Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/bbcode dataprocessor data facade wo tests #169

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
121 commits
Select commit Hold shift + click to select a range
76ea4cf
feature(bbcode-dataprocessor): Add another editor to example app
Aug 8, 2023
fdf4246
feature(bbcode-dataprocessor): Add tabs to switch between editors
Aug 8, 2023
1c0be4a
feature(bbcode-dataprocessor): Introduce coremedia-bbcode plugin
Aug 15, 2023
f48a2c6
feature(bbcode-dataprocessor): Use coremedia-bbcode plugin in example…
Aug 15, 2023
480d3b4
feature(bbcode-dataprocessor): Remove logging + preview from bbcode e…
Aug 23, 2023
bb4a0c7
feature(bbcode-dataprocessor): Take child contents into account in HT…
Aug 23, 2023
87b3bb3
feature(bbcode-dataprocessor): Return undefined if rule is not applied
Aug 24, 2023
8a7b880
feature(bbcode-dataprocessor): Enable underline and link plugins in b…
Aug 24, 2023
862c237
feature(bbcode-dataprocessor): Cleanup
Aug 24, 2023
3272bf2
feature(bbcode-dataprocessor): Fix & enable Hyperlink Rule
Aug 24, 2023
c4a80ef
feature(bbcode-dataprocessor): Fix falsy EditorConfig types
Aug 24, 2023
353d836
chore: Fix Version After Rebase
mmichaelis Sep 12, 2023
0e85dc3
feat: Common Examples UI
mmichaelis Sep 26, 2023
c59b5ba
feat: Refactor to new Examples UI
mmichaelis Sep 26, 2023
a3d1f3c
chore: Update Copyright
mmichaelis Sep 26, 2023
f847bd3
refactor: Read-Only Toggle
mmichaelis Sep 26, 2023
7172b9e
refactor: Minor Adaptations
mmichaelis Sep 27, 2023
4066752
refactor: Introduce DataFormatter
mmichaelis Sep 27, 2023
8260e00
refactor: Make Preview Formatter Configurable
mmichaelis Sep 27, 2023
bd537cd
refactor: Refactor Preview Initialization
mmichaelis Sep 27, 2023
88c8aca
refactor: Refactor To Toggle By Data Type
mmichaelis Sep 27, 2023
11c8ab3
refactor: Refactor Read Only Toggle
mmichaelis Sep 28, 2023
df10a91
refactor: Convert to async function
mmichaelis Sep 28, 2023
b86aade
feat: Remember Read-Only State on Reload
mmichaelis Sep 28, 2023
661f2fc
refactor: Use SwitchButton for Preview
mmichaelis Sep 28, 2023
3865016
feat: Remember Preview State
mmichaelis Sep 28, 2023
f7c7056
refactor: Extract Content Link Data
mmichaelis Sep 29, 2023
2f76617
refactor: Extract Invalid Rich Text Data
mmichaelis Sep 29, 2023
d62f793
refactor: Extract Simple Rich Text Data
mmichaelis Sep 29, 2023
ad1d4a0
fix: Fix Possible "XSS" Attack Vector
mmichaelis Sep 29, 2023
99a44fd
refactor: Bundle Rich Text Data
mmichaelis Sep 29, 2023
1ca4507
refactor: Rename "data" folder
mmichaelis Sep 29, 2023
8bfbe60
feat: Introduce WithRequired Utility Type
mmichaelis Sep 29, 2023
06428b9
refactor: Use ExampleData Type for examples
mmichaelis Sep 29, 2023
a11251c
feat: Provide First BBCode Example Data
mmichaelis Sep 29, 2023
39b8be7
feat: Use BBCode Example Data
mmichaelis Sep 29, 2023
8fa8675
fix: Typings for BBob Parser
mmichaelis Sep 29, 2023
1b075e8
chore: Fix Package Versions After Rebase To Main
mmichaelis Sep 29, 2023
a35f27a
chore: Update pnpm-lock.yaml
mmichaelis Sep 29, 2023
08c34c6
chore: Fix Dependency Versions After Rebase
mmichaelis Sep 29, 2023
724ddc9
chore: Update pnpm-lock.yaml
mmichaelis Sep 29, 2023
a0ae032
fix: Broken example-data after Rebase
mmichaelis Sep 29, 2023
da1f45f
fix: Add Accidentally Dropped Challenging Data
mmichaelis Sep 29, 2023
b776872
fix: Adapt Rich Text Editor Config
mmichaelis Oct 2, 2023
f2d5d16
feat: Integrate Data Facade
mmichaelis Oct 2, 2023
529ca6e
chore: Update pnpm-lock.yaml
mmichaelis Oct 2, 2023
02c4f54
chore: Fix Lint Issues
mmichaelis Oct 2, 2023
44201a0
fix: Address Remote property injection
mmichaelis Oct 2, 2023
510b6cb
feat: Extend BBCode Example Data
mmichaelis Oct 2, 2023
31a9917
fix: No Jest, No Fail
mmichaelis Oct 2, 2023
b7767e9
refactor: Handle Paragraphs
mmichaelis Oct 2, 2023
cb38981
feat: Introduce Rules for Headings
mmichaelis Oct 2, 2023
467ff1b
chore: ESLint Fix
mmichaelis Oct 2, 2023
abe2eb4
test: Security Challenge Data
mmichaelis Oct 4, 2023
c48237f
feat: Add BBCode Security Layer
mmichaelis Oct 4, 2023
ca1d3bb
chore: Update pnpm-lock.yaml
mmichaelis Oct 4, 2023
5eac02a
doc: Documenting Supported BBCode Tags
mmichaelis Oct 4, 2023
7696b3c
refactor: Rename "tag" to "process"
mmichaelis Oct 4, 2023
17de0ce
fix: ESLint Fix
mmichaelis Oct 4, 2023
384fd0c
refactor: BBCode2Html Refactored
mmichaelis Oct 4, 2023
ba9e9d5
feat: Allow-List for BBCode Tags
mmichaelis Oct 5, 2023
97eda36
feat: toData: Support `[quote]`
mmichaelis Oct 5, 2023
8af5845
feat: toData: Support `[code]`
mmichaelis Oct 5, 2023
615e018
feat: toData: Support `[list]` and `[*]`
mmichaelis Oct 5, 2023
4db8da7
feat: toData: Support `[table]` et al.
mmichaelis Oct 5, 2023
cdf6419
fixup! feat: toData: Support `[table]` et al.
mmichaelis Oct 5, 2023
b0b71a3
feat: toData: Support language for `[code]`
mmichaelis Oct 5, 2023
b1a0882
docs: References added to README
mmichaelis Oct 5, 2023
beaee57
feat: Pimp BBCode Demo
mmichaelis Oct 5, 2023
8e64220
fixup! feat: toData: Support `[quote]`
mmichaelis Oct 5, 2023
78e823a
feat: Pimp BBCode Demo, List Feature
mmichaelis Oct 5, 2023
11072d4
feat: Add some Debug Logging
mmichaelis Oct 5, 2023
5434b3b
chore: Update pnpm-lock.yaml
mmichaelis Oct 5, 2023
33cd4c2
fix: Fix Minor Typo in Debugging Output
mmichaelis Oct 5, 2023
7d3bef2
refactor: Move bbcode2html
mmichaelis Oct 5, 2023
ce7ca87
feat: Define Public API for BBCode
mmichaelis Oct 5, 2023
29ee086
refactor: De-Duplicate RequireSelected
mmichaelis Oct 5, 2023
199ec07
refactor: Move MockBlocklistService
mmichaelis Oct 5, 2023
6b01436
refactor: Make MockBlocklistService Self-Contained
mmichaelis Oct 5, 2023
b3e38eb
test: First Tests for BBCode Processing
mmichaelis Oct 5, 2023
f79be82
chore: Update pnpm-lock.yaml
mmichaelis Oct 5, 2023
21e8e0b
fix: [list=1] denotes the `type` of an ordered list
mmichaelis Oct 5, 2023
df9d4ee
fix: Fix Bold by FontWeight (and Heading, possibly)
mmichaelis Oct 5, 2023
a1f6f73
fix: Test and Fix Heading Parsing
mmichaelis Oct 5, 2023
1ea00ed
fix: Enhance Whitespace Normalization
mmichaelis Oct 5, 2023
9d2730d
fix: ESLint
mmichaelis Oct 5, 2023
537c1af
test: Extend Integration Tests
mmichaelis Oct 6, 2023
5deb873
fix: Fix issues detected by integration test
mmichaelis Oct 6, 2023
052a631
refactor: Copy & Adapt BBob HTML5 Preset
mmichaelis Oct 9, 2023
f8e0557
chore: Update pnpm-lock.yaml
mmichaelis Oct 9, 2023
a66e799
feat: Minor Refactorings for ckeditor5Preset
mmichaelis Oct 9, 2023
b4b5d96
feat: Apply Required CKEditor 5 Code Block Structure
mmichaelis Oct 9, 2023
7f25577
feat: Prefer Extend Over Copy & Adapt
mmichaelis Oct 9, 2023
3f67e84
chore: Update pnpm-lock.yaml
mmichaelis Oct 9, 2023
fcf72b6
feat: Adapt Code-Mapping for CKEditor 5 Data View
mmichaelis Oct 9, 2023
f3e66ff
test: Adapted Code-Mapping for CKEditor 5 Data View
mmichaelis Oct 9, 2023
b5ee77b
refactor: Clean up BBob typings
mmichaelis Oct 9, 2023
9cbfb73
fix: Typing Issues (and ESLint Complaints)
mmichaelis Oct 9, 2023
d11aa7a
test: Adapt Integration Test
mmichaelis Oct 9, 2023
ad9ac77
feat: Add Support for [color] #html2bbcode
mmichaelis Oct 9, 2023
e6482a0
feat: Add Color Selection to BBCode Example App
mmichaelis Oct 9, 2023
01dd8aa
chore: Update pnpm-lock.yaml
mmichaelis Oct 9, 2023
8ce9cf0
docs: BBCodeBold
mmichaelis Oct 10, 2023
c54ed2a
feat: Customize Language Tokens
mmichaelis Oct 10, 2023
144b9e8
feat: Code Block Examples
mmichaelis Oct 10, 2023
6250e86
refactor: Defensive Language Matching (Code Block)
mmichaelis Oct 10, 2023
54f7c01
test: Code Block toData Transformation
mmichaelis Oct 10, 2023
85f9822
refactor: Rename ckeditor5-coremedia-bbcode to ckeditor5-bbcode (folder)
mmichaelis Oct 10, 2023
21e8e13
refactor: Rename ckeditor5-coremedia-bbcode to ckeditor5-bbcode (modu…
mmichaelis Oct 10, 2023
034d48b
chore: Update pnpm-lock.yaml
mmichaelis Oct 10, 2023
d8951ac
docs: Update BBCode README
mmichaelis Oct 10, 2023
14201b7
refactor: Pretty-Print Optimization for URL
mmichaelis Oct 10, 2023
bdf90b5
docs: Adapt README.md
mmichaelis Oct 10, 2023
ad0c501
test: BBCodeBold
mmichaelis Oct 10, 2023
726f086
test: BBCodeItalic
mmichaelis Oct 10, 2023
7312fc5
refactor: BBCodeItalic/BBCodeBold
mmichaelis Oct 10, 2023
a667990
test: Corner Cases for BBCodeItalic/BBCodeBold
mmichaelis Oct 10, 2023
ace1727
refactor: Simplify (and document) BBCodeColor
mmichaelis Oct 10, 2023
3f45954
test: BBCodeColor
mmichaelis Oct 10, 2023
11b9b70
chore(bbcode-dataprocessor): Apply prettier suggestion
JensDallmann Oct 11, 2023
87c260d
test-commit
JensDallmann Oct 16, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@ckeditor/ckeditor5-engine": "39.0.2",
"@ckeditor/ckeditor5-essentials": "39.0.2",
"@ckeditor/ckeditor5-find-and-replace": "39.0.2",
"@ckeditor/ckeditor5-font": "39.0.2",
"@ckeditor/ckeditor5-heading": "39.0.2",
"@ckeditor/ckeditor5-highlight": "39.0.2",
"@ckeditor/ckeditor5-image": "39.0.2",
Expand All @@ -37,6 +38,7 @@
"@ckeditor/ckeditor5-ui": "39.0.2",
"@ckeditor/ckeditor5-utils": "39.0.2",
"@coremedia-internal/ckeditor5-coremedia-example-data": "^1.0.0",
"@coremedia/ckeditor5-bbcode": "16.0.1-rc.2",
"@coremedia/ckeditor5-coremedia-blocklist": "16.0.1-rc.2",
"@coremedia/ckeditor5-coremedia-content-clipboard": "16.0.1-rc.2",
"@coremedia/ckeditor5-coremedia-differencing": "16.0.1-rc.2",
Expand All @@ -45,6 +47,7 @@
"@coremedia/ckeditor5-coremedia-richtext": "16.0.1-rc.2",
"@coremedia/ckeditor5-coremedia-studio-essentials": "16.0.1-rc.2",
"@coremedia/ckeditor5-coremedia-studio-integration-mock": "16.0.1-rc.2",
"@coremedia/ckeditor5-data-facade": "16.0.1-rc.2",
"@coremedia/ckeditor5-dataprocessor-support": "16.0.1-rc.2",
"@coremedia/ckeditor5-dom-converter": "16.0.1-rc.2",
"@coremedia/ckeditor5-font-mapper": "16.0.1-rc.2",
Expand Down
86 changes: 18 additions & 68 deletions app/sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,32 @@
<link rel="stylesheet" type="text/css" href="styles.css">
<link rel="stylesheet" type="text/css" href="coremedia.css">
<!--
Unfortunately it was not possible to simply import the CKEditorInspector in the ts file.
The CKEditorInspector was always undefined. This way it works, and it is fine for an example application.
Unfortunately, it was impossible to simply import the CKEditorInspector in
the ts file. The CKEditorInspector was always undefined. This way it works,
and it is fine for an example application.
-->
<script src="../node_modules/@ckeditor/ckeditor5-inspector/build/inspector.js"></script>
</head>
<body data-editor="ClassicEditor" data-collaboration="false">

<div id="notifications"></div>

<header>
<div id="notifications">
<!-- Place to render notifications like "open in tab" -->
</div>
<div class="centered">
<h1><a href="https://ckeditor.com/ckeditor-5/" target="_blank" rel="noopener noreferrer"><img
src="https://c.cksource.com/a/1/logos/ckeditor5.svg" alt="CKEditor 5 logo">CKEditor 5</a></h1>
src="https://c.cksource.com/a/1/logos/ckeditor5.svg" alt="CKEditor 5 logo">CKEditor 5</a></h1>
<nav>
<ul>
<li><a href="https://ckeditor.com/docs/ckeditor5/" target="_blank" rel="noopener noreferrer">Documentation</a>
</li>
<li><a href="https://ckeditor.com/" target="_blank" rel="noopener noreferrer">Website</a></li>
<li><a href=".?#ckdebug=verbose" rel="noopener noreferrer" id="debug">Debug Logging</a></li>
<li>Language: <a href="." rel="noopener noreferrer" id="lang" title="Switch language of editor UI."
style="font-weight: initial;"></a></li>
</ul>
</nav>
</div>
<div id="examples">
<label for="xmp-input">
Example Data:
</label>
<input id="xmp-input"
list="xmp-data"
placeholder="Start typing..."
autocomplete="on"
>
<datalist id="xmp-data">
<!-- Will be filled from example-data.ts -->
</datalist>
<button id="xmp-reload" title="Reload">🔄</button>
<button id="xmp-clear" title="Clear">🚮</button>
<!-- Place to render example selection combobox to. -->
</div>
</header>

Expand All @@ -56,70 +44,32 @@ <h2>CKEditor 5: CoreMedia Plugin Showcase</h2>
</div>
</div>
<div class="centered">
<div>
<button id="readOnlyMode" title="Delay Modifiers: Ctrl/Cmd: 10s, Shift: 60s, Ctrl/Cmd+Shift: 120s">Enable Read-Only-Mode</button>
<button id="previewButton">Show XML Preview</button>
<div id="applicationToolbar">
<button id="inputExampleContentButton">Show Input Example Content</button>
</div>

<div id="inputExampleContentDiv" hidden="hidden">
<!-- The Drag Examples will be generated here. -->
</div>
<div class="row">

<div id="defaultEditorRow" class="row editor-row">
<div class="row-editor">
<!-- RichText Editor Starts Here. Content is initial content to display on load. -->
<!-- The data inside are given in data-format of CKEditor, which is CoreMedia RichText 1.0. -->
<div id="editor"></div>
<div id="preview" class="preview hidden" hidden></div>
<div id="preview">
<!-- The preview displaying the "stored data" will be rendered here. -->
</div>
</div>
</div>
</div>
</main>

<footer>
<p>Copyright © 2020-2022,
<p>Copyright © 2020-2023,
<a href="https://www.coremedia.com/" target="_blank" rel="noopener">CoreMedia</a>
</p>
</footer>
<script>
const loadTranslations = (locale) => {
if (locale === "en") {
console.log("Default locale. No need to load further resources.");
} else {
const scriptEl = document.createElement("script");
scriptEl.src = "../dist/translations/" + locale + ".js";
document.body.appendChild(scriptEl);
}
};

const loadCKEditor = (locale) => {
const scriptEl = document.createElement("script");
scriptEl.src = "../dist/ckeditor.js";
scriptEl.dataset["lang"] = locale;
document.body.appendChild(scriptEl);
};

const initLanguage = () => {
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const languageFlag = 'lang';
const language = urlParams.get(languageFlag)?.toLowerCase() || 'en';
const languageToggle = document.getElementById(languageFlag);
let label, hrefLang;
if (language === "de") {
label = "EN | <strong>DE</strong>";
hrefLang = "en";
} else {
label = "<strong>EN</strong> | DE";
hrefLang = "de";
}
languageToggle.setAttribute("href", `.?lang=${hrefLang}`);
languageToggle.innerHTML = label;
return language;
};

const lang = initLanguage();
loadCKEditor(lang);
loadTranslations(lang);
</script>
<script src="../dist/translations/de.js"></script>
<script src="../dist/ckeditor.js"></script>
</body>
</html>
24 changes: 20 additions & 4 deletions app/sample/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ input.error {

/* --------- PREVIEW STYLES ---------------------------------------------------------------------------------------- */
.preview {
display: inline-block;
display: none;
vertical-align: top;
background-color: white;
padding: 2px 2em;
Expand All @@ -114,8 +114,8 @@ input.error {
min-height: calc(var(--ck-sample-editor-min-height) + 38.67px);
}

.preview.hidden {
display: none;
.with-preview .preview {
display: inline-block;
}

#input-examples.hidden {
Expand All @@ -140,6 +140,22 @@ input.error {
text-align: justify;
}

/* --------- CK List Styles (useAttribute: true) ------------------------------------------------------------------- */

.ck-content ol[type="1"] {
list-style-type: decimal;
}

/* Case-Insensitive Matching; see https://github.com/w3c/csswg-drafts/issues/2101 */
.ck-content ol[type="i"] {
list-style-type: lower-roman;
}

/* Case-Insensitive Matching; see https://github.com/w3c/csswg-drafts/issues/2101 */
.ck-content ol[type="a"] {
list-style-type: lower-alpha;
}

/* --------- EDITOR STYLES ---------------------------------------------------------------------------------------- */

#ckeditor {
Expand All @@ -159,7 +175,7 @@ main .ck-editor[role='application'] .ck.ck-content,
padding: 1.5em 2em;
}

.ck.ck-editor.with-preview {
.with-preview .ck.ck-editor {
display: inline-block;
vertical-align: top;
width: calc(50% - 8px) !important;
Expand Down
106 changes: 106 additions & 0 deletions app/src/ApplicationState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { setHashParam } from "./HashParams";

// Keeping the following values in line with corresponding switch-buttons helps
// to ease the integration. We may also refactor this to some more explicit
// reusable set of types to choose from.

export type InspectorState = "expanded" | "collapsed";
export type CompatibilityMode = "v10" | "latest";
export type DataType = "richtext" | "bbcode";
export type UiLanguage = "en" | "de";
export type ReadOnlyMode = "rw" | "ro";
export type PreviewState = "hidden" | "visible";

export class ApplicationState {
/**
* Language for CKEditor 5 UI.
*/
readonly #uiLanguage: UiLanguage;
/**
* Signals, if to open the inspector expanded or collapsed by default.
*/
readonly #inspector: InspectorState;
/**
* Plugin version compatibility mode to apply.
*
* * `v10`: Up to version 10 we provided different data-processing for
* CoreMedia Rich Text.
* * `latest`: Just assume the latest plugin version.
*/
readonly #compatibility: CompatibilityMode;
/**
* The data type to support.
*/
readonly #dataType: DataType;
#readOnlyMode: ReadOnlyMode;
#previewState: PreviewState;

constructor(config?: Map<string, string | boolean>) {
const uiLanguage = config?.get("uiLanguage") ?? "en";
const inspector = config?.get("inspector") ?? "collapsed";
const compatibility = config?.get("compatibility") ?? "latest";
const dataType = config?.get("dataType") ?? "richtext";
const readOnly = config?.get("readOnly") ?? false;
const showPreview = config?.get("showPreview") ?? false;

this.#uiLanguage = typeof uiLanguage === "string" && uiLanguage.toLowerCase() === "de" ? "de" : "en";
this.#inspector =
typeof inspector === "string" && inspector.toLowerCase() === "expanded" ? "expanded" : "collapsed";
this.#compatibility = typeof compatibility === "string" && compatibility.toLowerCase() === "v10" ? "v10" : "latest";
this.#dataType = typeof dataType === "string" && dataType.toLowerCase() === "bbcode" ? "bbcode" : "richtext";
this.#readOnlyMode = typeof readOnly === "boolean" && readOnly ? "ro" : "rw";
this.#previewState = typeof showPreview === "boolean" && showPreview ? "visible" : "hidden";
}

get uiLanguage(): UiLanguage {
return this.#uiLanguage;
}

set uiLanguage(language: UiLanguage) {
if (language !== this.#uiLanguage) {
setHashParam("uiLanguage", language, true);
}
}

get inspector(): InspectorState {
return this.#inspector;
}

get compatibility(): CompatibilityMode {
return this.#compatibility;
}

set compatibility(mode) {
if (this.#compatibility !== mode) {
setHashParam("compatibility", mode, true);
}
}

get dataType(): DataType {
return this.#dataType;
}

set dataType(dataType) {
if (this.#dataType !== dataType) {
setHashParam("dataType", dataType, true);
}
}

get readOnlyMode(): ReadOnlyMode {
return this.#readOnlyMode;
}

set readOnlyMode(mode) {
this.#readOnlyMode = mode;
setHashParam("readOnly", mode === "ro");
}

get previewState(): PreviewState {
return this.#previewState;
}

set previewState(state) {
this.#previewState = state;
setHashParam("showPreview", state === "visible");
}
}
20 changes: 20 additions & 0 deletions app/src/ApplicationToolbar.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const defaultApplicationToolbarId = "applicationToolbar";

export interface ApplicationToolbarConfig {
/**
* ID of toolbar button to add the preview button to.
* Defaults to: `applicationToolbar`.
*/
toolbarId?: string;
}

export const requireApplicationToolbar = (config?: ApplicationToolbarConfig): HTMLElement => {
const { toolbarId = defaultApplicationToolbarId } = config ?? {};
const toolbar = document.getElementById(toolbarId);

if (!toolbar) {
throw new Error(`Cannot find toolbar element having ID "${toolbarId}".`);
}

return toolbar;
};
4 changes: 4 additions & 0 deletions app/src/CKEditorInstanceFactory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ApplicationState } from "./ApplicationState";
import { ClassicEditor } from "@ckeditor/ckeditor5-editor-classic";

export type CKEditorInstanceFactory = (sourceElement: HTMLElement, state: ApplicationState) => Promise<ClassicEditor>;
18 changes: 18 additions & 0 deletions app/src/DataFormatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { default as formatXml } from "xml-formatter";

export type DataFormatter = (data: string, empty?: string) => string;

export const dataFormatter: {
xml: DataFormatter;
text: DataFormatter;
} = {
xml: (data, empty) =>
data
? formatXml(data, {
indentation: " ",
collapseContent: false,
whiteSpaceAtEndOfSelfclosingTag: true,
})
: empty ?? "",
text: (data, empty) => (data ? data : empty ?? ""),
};
16 changes: 16 additions & 0 deletions app/src/DataTypeSwitch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { SwitchButton, SwitchButtonConfig } from "./SwitchButton";

export const dataTypes = {
["richtext" as const]: "Rich Text",
["bbcode" as const]: "BBCode",
};

export const initDataTypeSwitch = (config: SwitchButtonConfig<keyof typeof dataTypes>): void => {
new SwitchButton({
id: "dataTypeSwitch",
default: "richtext",
states: dataTypes,
label: "Data Type",
...config,
}).init();
};
Loading