-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample-data.ts
More file actions
68 lines (66 loc) · 1.88 KB
/
example-data.ts
File metadata and controls
68 lines (66 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// noinspection HttpUrlsUsage
import { PREDEFINED_MOCK_LINK_DATA } from "@coremedia/ckeditor5-coremedia-studio-integration-mock";
import type { ExampleData } from "@coremedia-internal/ckeditor5-coremedia-example-data";
import { bbCodeData, initExamples, richTextData } from "@coremedia-internal/ckeditor5-coremedia-example-data";
import type { Editor } from "ckeditor5";
import { EditingView } from "ckeditor5";
import { DataFacade } from "@coremedia/ckeditor5-data-facade";
const exampleData: {
richtext: ExampleData;
bbcode: ExampleData;
} = {
richtext: {
...richTextData,
"Various Links": PREDEFINED_MOCK_LINK_DATA,
},
bbcode: bbCodeData,
};
export type ExampleDataType = keyof typeof exampleData;
const dumpEditingViewOnRender = (editor: Editor): void => {
const {
editing: { view },
} = editor;
// noinspection InnerHTMLJS
view.once(
"render",
(event) => {
const { source } = event;
if (source instanceof EditingView) {
console.log("CKEditor's Editing-Controller rendered data.", {
source,
innerHtml: source.getDomRoot()?.innerHTML,
});
}
},
{
priority: "lowest",
},
);
};
const dumpDataViewOnRender = (editor: Editor): void => {
const { data } = editor;
data.once(
"set",
(event, details) =>
console.log("CKEditor's Data-Controller received data via 'set'.", {
event,
// eslint-disable-next-line
data: details[0]
}),
{
priority: "lowest",
},
);
};
export const initExamplesAndBindTo = (editor: Editor, examplesType: ExampleDataType = "richtext"): void => {
initExamples({
id: "examples",
examples: exampleData[examplesType],
default: "Welcome",
onChange: (data: string): void => {
dumpEditingViewOnRender(editor);
dumpDataViewOnRender(editor);
editor.plugins.get(DataFacade).setData(data);
},
});
};