-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinputExampleContents.ts
More file actions
339 lines (337 loc) · 9.92 KB
/
inputExampleContents.ts
File metadata and controls
339 lines (337 loc) · 9.92 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
import type { InputExampleElement } from "@coremedia/ckeditor5-coremedia-studio-integration-mock";
import { MockContentPlugin, MockInputExamplePlugin } from "@coremedia/ckeditor5-coremedia-studio-integration-mock";
import type { ClassicEditor } from "ckeditor5";
const INPUT_EXAMPLE_CONTENT_DIV_CLASS = "inputExampleContentDiv";
const initInputExampleContent = (editor: ClassicEditor) => {
const mockContentPlugin = editor.plugins.get(MockContentPlugin);
const mockInputExamplePlugin = editor.plugins.get(MockInputExamplePlugin);
// Just ensure, that the default content provided by MockContentPlugin
// still fulfills our expectations.
const requireExplicitContent = mockContentPlugin.requireExplicitContent;
// Add some content of not insertable type. (By default only contents of type 'document'
// are considered insertable.
mockContentPlugin.addContents({
id: 40,
type: "notinsertable",
name: "Not insertable Content Type",
linkable: false,
});
const singleInputDocuments: InputExampleElement[] = [
{
label: "Document 1",
tooltip: "Some Document",
classes: ["linkable", "type-document"],
items: [30],
},
{
label: "Document 2",
tooltip: "Some Other Document",
classes: ["linkable", "type-document"],
items: [32],
},
{
label: "Short Name",
tooltip: "Document with short name (1-unicode char)",
classes: ["linkable", "type-document"],
items: [114],
},
{
label: "Document (edit)",
tooltip: "Document which is actively edited",
classes: ["linkable", "type-document"],
items: [requireExplicitContent(112)],
},
{
label: "Entities",
tooltip: "Entities in name",
classes: ["linkable", "type-document"],
items: [requireExplicitContent(600)],
},
{
label: "Characters",
tooltip: "Various characters in name",
classes: ["linkable", "type-document"],
items: [requireExplicitContent(602)],
},
{
label: "RTL",
tooltip: "Left-to-Right name",
classes: ["linkable", "type-document"],
items: [requireExplicitContent(604)],
},
{
label: "XSS",
tooltip: "Some possible Cross-Site-Scripting Attack",
classes: ["linkable", "type-document"],
items: [requireExplicitContent(606)],
},
{
label: "Long",
tooltip: "Very long name",
classes: ["linkable", "type-document"],
items: [requireExplicitContent(608)],
},
{
label: "Image",
tooltip: "Content with some red image blob.",
classes: ["linkable", "embeddable", "type-document"],
items: [requireExplicitContent(900)],
},
{
label: "Only Embeddable",
tooltip: "An image document which may only be embedded but not linked.",
classes: ["embeddable", "type-document"],
items: [requireExplicitContent(922)],
},
{
label: "Image (edit)",
tooltip: "An image, whose blob frequently changes.",
classes: ["linkable", "embeddable", "type-document"],
items: [requireExplicitContent(906)],
},
];
const singleInputs = [
{
label: "Root",
tooltip: "Root Folder; insertable for test-scenarios with empty name",
classes: ["linkable", "type-folder"],
// id is an extra option, which overrides any ID calculation.
items: [requireExplicitContent(1)],
},
...singleInputDocuments,
];
const unreadables = [
{
label: "Unreadable",
tooltip: "Document cannot be read.",
classes: ["linkable", "type-document"],
items: [requireExplicitContent(104)],
},
{
label: "Sometimes Unreadable",
tooltip: "Document cannot be read sometimes.",
classes: ["linkable", "type-document"],
items: [requireExplicitContent(106)],
},
{
label: "Some Unreadable",
tooltip: "One document can be read, the other cannot be read.",
classes: ["linkable", "type-collection"],
items: [30, requireExplicitContent(104), 32],
},
{
label: "Image (unreadable)",
tooltip: "Image document cannot be read.",
classes: ["linkable", "embeddable", "type-document"],
items: [requireExplicitContent(914)],
},
];
const singleInputsNotInsertable = [
{
label: "Folder",
tooltip: "Some Folder",
classes: ["non-linkable", "type-folder"],
items: [31],
},
{
label: "Not Insertable",
tooltip: "Content of not insertable type.",
classes: ["non-linkable", "type-folder"],
items: [requireExplicitContent(40)],
},
];
const slowDocuments: InputExampleElement[] = [
{
label: "Slow",
tooltip: "Slowed down access to content",
classes: ["linkable", "type-document"],
items: [requireExplicitContent(800)],
},
{
label: "Very Slow",
tooltip: "Content takes more than just minutes to load.",
classes: ["linkable", "type-document"],
items: [requireExplicitContent(802)],
},
{
label: "Image (slow)",
tooltip: "An image, which takes some time to load.",
classes: ["linkable", "embeddable", "type-document"],
items: [requireExplicitContent(908)],
},
];
const pairedExamples = [
{
label: "Two",
tooltip: "Two documents, which are valid to insert.",
classes: ["linkable", "type-collection"],
items: [30, 32],
},
{
label: "Slow/Fast",
tooltip: "Two documents, the first one slow to load, the other fast to load.",
classes: ["linkable", "type-collection"],
items: [requireExplicitContent(800), 32],
},
{
label: "Fast/Slow",
tooltip: "Two documents, the first one fast to load, the other slow to load.",
classes: ["linkable", "type-collection"],
items: [32, requireExplicitContent(800)],
},
{
label: "Slow/Fast/Slow",
tooltip: "Slow/Fast/Slow for testing insert order after lazy loading",
classes: ["linkable", "type-collection"],
items: [requireExplicitContent(800), 32, requireExplicitContent(804)],
},
{
label: "Insertable/Not Insertable",
tooltip: "Two contents, one of them is not allowed to be inserted.",
classes: ["non-linkable", "type-collection"],
items: [31, 32],
},
{
label: "Three Images",
tooltip: "Three images, which are valid to insert.",
classes: ["linkable", "embeddable", "type-collection"],
items: [requireExplicitContent(900), requireExplicitContent(902), requireExplicitContent(904)],
},
];
const allInputs = [
{
label: `Several Inputs`,
tooltip: `${singleInputs.length} contents which are allowed to be inserted.`,
classes: ["linkable", "type-collection"],
items: singleInputs.flatMap((item) => item.items),
},
{
label: `Several Input Documents`,
tooltip: `${singleInputDocuments.length} documents which are allowed to be inserted.`,
classes: ["linkable", "type-collection"],
items: singleInputDocuments.flatMap((item) => item.items),
},
{
label: `Insertable Documents (incl. Slow)`,
tooltip: `${singleInputDocuments.length + slowDocuments.length} including ${slowDocuments.length} documents at the start which load slowly.`,
classes: ["linkable", "type-collection"],
items: slowDocuments.concat(singleInputDocuments).flatMap((item) => item.items),
},
];
const externalContents: InputExampleElement[] = [
{
label: "Insertable external content",
tooltip: "Insertable External Content",
classes: ["linkable"],
items: [
{
externalId: 2000,
},
],
},
{
label: "Already imported external content",
tooltip: "Already imported external Content",
classes: ["linkable"],
items: [
{
externalId: 2002,
},
],
},
{
label: "Not insertable external content",
tooltip: "Not droppable external content (Unknown type)",
classes: ["non-linkable"],
items: [
{
externalId: 2004,
},
],
},
{
label: "Multiple insertable external contents",
tooltip: "Multiple insertable external contents",
classes: ["linkable"],
items: [
{
externalId: 2000,
},
{
externalId: 2002,
},
],
},
{
label: "Multiple external contents (including not insertable)",
tooltip: "Multiple external contents (including not insertable)",
classes: ["non-linkable"],
items: [
{
externalId: 2000,
},
{
externalId: 2002,
},
{
externalId: 2004,
},
],
},
{
label: "External content - error",
tooltip: "External content - error",
classes: ["linkable"],
items: [
{
externalId: 2006,
},
],
},
];
const allData: InputExampleElement[] = [
...singleInputs,
...singleInputsNotInsertable,
...slowDocuments,
...pairedExamples,
...allInputs,
...unreadables,
...createBulkOf50Contents(),
...externalContents,
];
const main = () => {
const examplesEl = document.getElementById(INPUT_EXAMPLE_CONTENT_DIV_CLASS);
if (!examplesEl) {
console.error(`Required element missing: ${INPUT_EXAMPLE_CONTENT_DIV_CLASS}`);
return;
}
allData.forEach((data) => {
const insertDiv: HTMLDivElement = mockInputExamplePlugin.createInsertElement(data);
examplesEl.appendChild(insertDiv);
});
console.log(`Initialized ${allData.length} insert examples.`);
};
main();
};
const createBulkOf50Contents = (): [
{
classes: string[];
tooltip: string;
label: string;
items: number[];
},
] => {
const ids = [];
for (let i = 13000; i < 13100; i = i + 2) {
ids.push(i);
}
return [
{
label: "50 contents",
tooltip: "50 contents: ",
classes: ["linkable", "type-document"],
items: ids,
},
];
};
export { initInputExampleContent };