@coorax/core 0.0.0-canary.1 → 0.0.0-canary.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base/types/field/field.blockquote.types.d.ts +4 -0
- package/dist/base/types/field/field.d.ts +14 -3
- package/dist/base/types/field/field.image.types.d.ts +3 -0
- package/dist/base/types/field/field.video.types.d.ts +8 -0
- package/dist/base/types/field/fields.iframe.types.d.ts +7 -0
- package/dist/base/types/global.types.d.ts +2 -0
- package/dist/base/types/tree/tree.d.ts +2 -1
- package/dist/constants/field.constants.d.ts +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1511 -361
- package/dist/modules/caption/caption.module.d.ts +35 -0
- package/dist/modules/caption/caption.test.d.ts +1 -0
- package/dist/modules/code/code.module.d.ts +37 -0
- package/dist/modules/deletion/deletion.module.d.ts +26 -0
- package/dist/modules/divider/divider.module.d.ts +58 -0
- package/dist/modules/focus/focus.module.d.ts +1 -1
- package/dist/modules/history/history.module.d.ts +14 -0
- package/dist/modules/hover/hover.module.d.ts +1 -1
- package/dist/modules/index.d.ts +6 -1
- package/dist/modules/insertion/insertion.module.d.ts +20 -1
- package/dist/modules/media/media.module.d.ts +52 -0
- package/dist/modules/modules-manager.d.ts +2 -0
- package/dist/modules/paragraph-theme/paragraph-theme.module.d.ts +49 -0
- package/dist/modules/selection/selection.module.d.ts +1 -1
- package/dist/modules/text-editing/text-editing.constants.d.ts +1 -1
- package/dist/modules/text-editing/text-editing.module.d.ts +1 -2
- package/dist/modules/text-editing/text-editing.utils.d.ts +1 -1
- package/dist/services/document/document.d.ts +1 -2
- package/dist/services/eventbus/eventbus.d.ts +4 -4
- package/dist/services/eventbus/eventbus.test.d.ts +1 -1
- package/dist/services/eventbus/subscriber.d.ts +4 -4
- package/dist/services/mutations/mutations.d.ts +10 -5
- package/dist/services/tasks/tasks.service.d.ts +1 -1
- package/dist/services/text-marks/index.d.ts +0 -1
- package/dist/services/text-marks/text-marks.d.ts +1 -1
- package/dist/services/ui/contributions.types.d.ts +79 -0
- package/dist/services/ui/default-styles.d.ts +1 -1
- package/dist/services/ui/index.d.ts +0 -1
- package/dist/services/ui/ui.d.ts +7 -6
- package/dist/services/ui/ui.types.d.ts +7 -95
- package/dist/styles.css +1 -536
- package/dist/utils/fields.utils.d.ts +10 -2
- package/dist/utils/index.d.ts +0 -6
- package/package.json +12 -8
- package/styles.css +4 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
//
|
|
1
|
+
// ../schema/dist/index.js
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
|
|
2
4
|
class ComponentClass {
|
|
3
5
|
id;
|
|
4
6
|
name;
|
|
@@ -52,7 +54,7 @@ class ComponentClass {
|
|
|
52
54
|
};
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
|
-
|
|
57
|
+
|
|
56
58
|
class ContainerClass {
|
|
57
59
|
id;
|
|
58
60
|
name;
|
|
@@ -91,7 +93,7 @@ class ContainerClass {
|
|
|
91
93
|
};
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
|
-
|
|
96
|
+
|
|
95
97
|
class FieldClass {
|
|
96
98
|
id;
|
|
97
99
|
name;
|
|
@@ -124,7 +126,7 @@ class FieldClass {
|
|
|
124
126
|
};
|
|
125
127
|
}
|
|
126
128
|
}
|
|
127
|
-
|
|
129
|
+
|
|
128
130
|
class TNodeClass {
|
|
129
131
|
id;
|
|
130
132
|
tag;
|
|
@@ -154,7 +156,7 @@ class TNodeClass {
|
|
|
154
156
|
};
|
|
155
157
|
}
|
|
156
158
|
}
|
|
157
|
-
// src/utils/global.utils.ts
|
|
159
|
+
var DEFAULT_IMAGE_PREVIEW = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEBLAEsAAD/4QBWRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAITAAMAA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NzdmLTgzMjgtNDdhYS04NWI0LTRlMDBkZGUwYzI4YjwveG1wTU06RG9jdW1lbnRJRD4KICA8eG1wTU06SW5zdGFuY2VJRD5hZG9iZTpkb2NpZDpzdG9jazo2M2Y2NTBiOC0zMjM3LTQyODktYTgwZS1lMzdjNDlhOWI2MjA8L3htcE1NOkluc3RhbmNlSUQ+CiAgPHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD5hZG9iZTpkb2NpZDpzdG9jazoxNjc5NDQyMTk2PC94bXBNTTpPcmlnaW5hbERvY3VtZW50SUQ+CiA8L3JkZjpEZXNjcmlwdGlvbj4KPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKPD94cGFja2V0IGVuZD0ndyc/Pv/bAEMAAwICAwICAwMDAwQDAwQFCAUFBAQFCgcHBggMCgwMCwoLCw0OEhANDhEOCwsQFhARExQVFRUMDxcYFhQYEhQVFP/bAEMBAwQEBQQFCQUFCRQNCw0UFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFP/AABEIAPACbwMBEQACEQEDEQH/xAAdAAEBAAICAwEAAAAAAAAAAAAACAYHAQUCAwQJ/8QARBABAAEDAgIDCwoFAwMF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NOYeCpsHzXP8AfazTmHgqbB81z/fazTmHgqbB81z/AH2s05h4KmwfNc/32s05h4KmwfNc/wB9rNOYeCpsHzXP99rNOYeCpsHzXP8AfazTmHgqbB81z/fazTmHgqbB81z/AH2s05h4KmwfNc/32s05h4KmwfNc/wB9rNOYeCpsHzXP99rNOYeCpsHzXP8AfazTmHgqbB81z/fazTmHgqbB81z/AH2s05h4KmwfNc/32s05h4KmwfNc/wB9rNOY92L3LmwMa9FdWn5WREfcvZlyaZ9vKYNOY2PoG2dK2tg04WkYGPp+NH/Tx7cUxM+WfLPrlxUmOzHQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH//Z";
|
|
158
160
|
function generateRandomId() {
|
|
159
161
|
return `${Date.now().toString(12)}:${crypto.randomUUID()}`;
|
|
160
162
|
}
|
|
@@ -226,14 +228,19 @@ var isPlainObject = (v) => {
|
|
|
226
228
|
return proto === Object.prototype || proto === null;
|
|
227
229
|
};
|
|
228
230
|
function areObjectsTheSame(objA, objB) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
231
|
+
return _.isEqual(objA, objB);
|
|
232
|
+
}
|
|
233
|
+
function compareDocumentVersion(...versions) {
|
|
234
|
+
return versions.map((version) => {
|
|
235
|
+
const [major, minor, patch] = version.split(".").map(Number);
|
|
236
|
+
return { major, minor, patch };
|
|
237
|
+
}).sort((a, b) => {
|
|
238
|
+
if (a.major !== b.major)
|
|
239
|
+
return a.major - b.major;
|
|
240
|
+
if (a.minor !== b.minor)
|
|
241
|
+
return a.minor - b.minor;
|
|
242
|
+
return a.patch - b.patch;
|
|
243
|
+
}).map(({ major, minor, patch }) => `${major}.${minor}.${patch}`);
|
|
237
244
|
}
|
|
238
245
|
var UTILS = {
|
|
239
246
|
generateRandomId,
|
|
@@ -248,8 +255,6 @@ var UTILS = {
|
|
|
248
255
|
ObjectEntries,
|
|
249
256
|
isPlainObject
|
|
250
257
|
};
|
|
251
|
-
|
|
252
|
-
// src/utils/components.utils.ts
|
|
253
258
|
function NewComponent(container3, defaultValue) {
|
|
254
259
|
const now = Date.now();
|
|
255
260
|
return new ComponentClass({
|
|
@@ -265,7 +270,6 @@ function DeserializeComponent(component2) {
|
|
|
265
270
|
return new ComponentClass(component2);
|
|
266
271
|
}
|
|
267
272
|
var ComponentsUtils = { NewComponent, DeserializeComponent };
|
|
268
|
-
// src/utils/container.utils.ts
|
|
269
273
|
function NewUlListContainer(defaultValue) {
|
|
270
274
|
return new ContainerClass({
|
|
271
275
|
id: UTILS.generateContainerId(),
|
|
@@ -307,9 +311,260 @@ var ContainersUtils = {
|
|
|
307
311
|
NewUlListContainer,
|
|
308
312
|
NewSectionContainer
|
|
309
313
|
};
|
|
310
|
-
|
|
314
|
+
var Text = {
|
|
315
|
+
style: {
|
|
316
|
+
width: "100%",
|
|
317
|
+
color: "var(--foreground)",
|
|
318
|
+
fontSize: "18px",
|
|
319
|
+
minHeight: "32px",
|
|
320
|
+
whiteSpace: "pre-wrap",
|
|
321
|
+
fontWeight: 400,
|
|
322
|
+
lineHeight: 1.5,
|
|
323
|
+
display: "block",
|
|
324
|
+
alignItems: "center",
|
|
325
|
+
outline: "none",
|
|
326
|
+
border: "none",
|
|
327
|
+
fieldSizing: "content",
|
|
328
|
+
cursor: "default",
|
|
329
|
+
paddingInline: 4,
|
|
330
|
+
userSelect: "none"
|
|
331
|
+
},
|
|
332
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
333
|
+
};
|
|
334
|
+
var Heading = {
|
|
335
|
+
style: {
|
|
336
|
+
width: "100%",
|
|
337
|
+
maxWidth: "100%",
|
|
338
|
+
color: "var(--foreground)",
|
|
339
|
+
fontSize: "40px",
|
|
340
|
+
minHeight: "48px",
|
|
341
|
+
fontWeight: 400,
|
|
342
|
+
whiteSpace: "pre-wrap",
|
|
343
|
+
display: "block",
|
|
344
|
+
alignItems: "center",
|
|
345
|
+
outline: "none",
|
|
346
|
+
border: "none",
|
|
347
|
+
fieldSizing: "content",
|
|
348
|
+
cursor: "default",
|
|
349
|
+
paddingInline: 4,
|
|
350
|
+
userSelect: "none"
|
|
351
|
+
},
|
|
352
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
353
|
+
};
|
|
354
|
+
var SubHeading = {
|
|
355
|
+
style: {
|
|
356
|
+
width: "100%",
|
|
357
|
+
maxWidth: "100%",
|
|
358
|
+
color: "var(--foreground)",
|
|
359
|
+
fontSize: "28px",
|
|
360
|
+
minHeight: "40px",
|
|
361
|
+
fontWeight: 400,
|
|
362
|
+
whiteSpace: "pre-wrap",
|
|
363
|
+
display: "block",
|
|
364
|
+
alignItems: "center",
|
|
365
|
+
outline: "none",
|
|
366
|
+
border: "none",
|
|
367
|
+
fieldSizing: "content",
|
|
368
|
+
cursor: "default",
|
|
369
|
+
paddingInline: 4,
|
|
370
|
+
userSelect: "none"
|
|
371
|
+
},
|
|
372
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
373
|
+
};
|
|
374
|
+
var Image = {
|
|
375
|
+
style: {
|
|
376
|
+
width: "100%",
|
|
377
|
+
alignSelf: "center",
|
|
378
|
+
objectFit: "cover",
|
|
379
|
+
display: "block",
|
|
380
|
+
alignItems: "center",
|
|
381
|
+
outline: "none",
|
|
382
|
+
border: "none",
|
|
383
|
+
fieldSizing: "content",
|
|
384
|
+
cursor: "default",
|
|
385
|
+
userSelect: "none"
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
var Video = {
|
|
389
|
+
style: {
|
|
390
|
+
width: "100%",
|
|
391
|
+
objectFit: "cover",
|
|
392
|
+
display: "block",
|
|
393
|
+
alignItems: "center",
|
|
394
|
+
outline: "none",
|
|
395
|
+
border: "none",
|
|
396
|
+
fieldSizing: "content",
|
|
397
|
+
cursor: "default",
|
|
398
|
+
userSelect: "none"
|
|
399
|
+
}
|
|
400
|
+
};
|
|
401
|
+
var IFrame = {
|
|
402
|
+
style: {
|
|
403
|
+
width: "100%",
|
|
404
|
+
aspectRatio: "5/3",
|
|
405
|
+
objectFit: "cover",
|
|
406
|
+
display: "block",
|
|
407
|
+
alignItems: "center",
|
|
408
|
+
outline: "none",
|
|
409
|
+
border: "none",
|
|
410
|
+
fieldSizing: "content",
|
|
411
|
+
cursor: "default",
|
|
412
|
+
userSelect: "none"
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
var Link = {
|
|
416
|
+
style: {
|
|
417
|
+
width: "100%",
|
|
418
|
+
color: "var(--primary)",
|
|
419
|
+
fontSize: "18px",
|
|
420
|
+
minHeight: "32px",
|
|
421
|
+
whiteSpace: "pre-wrap",
|
|
422
|
+
fontWeight: 400,
|
|
423
|
+
display: "inline-flex",
|
|
424
|
+
lineHeight: 2,
|
|
425
|
+
alignItems: "center",
|
|
426
|
+
outline: "none",
|
|
427
|
+
border: "none",
|
|
428
|
+
fieldSizing: "content",
|
|
429
|
+
cursor: "default",
|
|
430
|
+
paddingInline: 4,
|
|
431
|
+
userSelect: "none"
|
|
432
|
+
},
|
|
433
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
434
|
+
};
|
|
435
|
+
var Blockquote = {
|
|
436
|
+
style: {
|
|
437
|
+
width: "100%",
|
|
438
|
+
maxWidth: "100%",
|
|
439
|
+
color: "var(--muted-foreground)",
|
|
440
|
+
fontSize: "18px",
|
|
441
|
+
minHeight: "32px",
|
|
442
|
+
fontWeight: 400,
|
|
443
|
+
whiteSpace: "pre-wrap",
|
|
444
|
+
fontStyle: "italic",
|
|
445
|
+
display: "block",
|
|
446
|
+
alignItems: "center",
|
|
447
|
+
outline: "none",
|
|
448
|
+
border: "none",
|
|
449
|
+
fieldSizing: "content",
|
|
450
|
+
cursor: "default",
|
|
451
|
+
paddingInline: 4,
|
|
452
|
+
userSelect: "none"
|
|
453
|
+
},
|
|
454
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
455
|
+
};
|
|
456
|
+
var Divider = {
|
|
457
|
+
style: {
|
|
458
|
+
width: "100%",
|
|
459
|
+
borderTopWidth: 1,
|
|
460
|
+
borderTopStyle: "solid",
|
|
461
|
+
borderTopColor: "var(--color-muted-foreground)",
|
|
462
|
+
marginBlock: 8,
|
|
463
|
+
outline: "none",
|
|
464
|
+
height: 1,
|
|
465
|
+
position: "relative",
|
|
466
|
+
overflow: "visible"
|
|
467
|
+
},
|
|
468
|
+
pseudoStyle: {
|
|
469
|
+
":before": {
|
|
470
|
+
content: '""',
|
|
471
|
+
position: "absolute",
|
|
472
|
+
top: "-8px",
|
|
473
|
+
bottom: "-8px",
|
|
474
|
+
height: 16,
|
|
475
|
+
left: 0,
|
|
476
|
+
right: 0,
|
|
477
|
+
pointerEvents: "auto",
|
|
478
|
+
zIndex: 5
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
};
|
|
482
|
+
var Code = {
|
|
483
|
+
style: {
|
|
484
|
+
width: "100%",
|
|
485
|
+
maxWidth: "100%",
|
|
486
|
+
color: "var(--foreground)",
|
|
487
|
+
fontSize: "14px",
|
|
488
|
+
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace",
|
|
489
|
+
minHeight: "40px",
|
|
490
|
+
fontWeight: 400,
|
|
491
|
+
lineHeight: 1.7,
|
|
492
|
+
whiteSpace: "pre-wrap",
|
|
493
|
+
display: "block",
|
|
494
|
+
outline: "none",
|
|
495
|
+
border: "1px solid var(--border)",
|
|
496
|
+
fieldSizing: "content",
|
|
497
|
+
cursor: "default",
|
|
498
|
+
padding: 12,
|
|
499
|
+
userSelect: "none"
|
|
500
|
+
},
|
|
501
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none bg-foreground dark:bg-transparent"
|
|
502
|
+
};
|
|
503
|
+
var Caption = {
|
|
504
|
+
style: {
|
|
505
|
+
width: "100%",
|
|
506
|
+
maxWidth: "100%",
|
|
507
|
+
color: "var(--muted-foreground)",
|
|
508
|
+
fontSize: "14px",
|
|
509
|
+
minHeight: "24px",
|
|
510
|
+
fontWeight: 400,
|
|
511
|
+
lineHeight: 1.5,
|
|
512
|
+
whiteSpace: "pre-wrap",
|
|
513
|
+
display: "block",
|
|
514
|
+
textAlign: "center",
|
|
515
|
+
outline: "none",
|
|
516
|
+
border: "none",
|
|
517
|
+
fieldSizing: "content",
|
|
518
|
+
cursor: "default",
|
|
519
|
+
paddingInline: 4,
|
|
520
|
+
paddingBottom: 4,
|
|
521
|
+
userSelect: "none"
|
|
522
|
+
},
|
|
523
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
524
|
+
};
|
|
525
|
+
var DEFAULT_STYLES = {
|
|
526
|
+
text: Text,
|
|
527
|
+
heading: Heading,
|
|
528
|
+
"sub-heading": SubHeading,
|
|
529
|
+
image: Image,
|
|
530
|
+
divider: Divider,
|
|
531
|
+
video: Video,
|
|
532
|
+
iframe: IFrame,
|
|
533
|
+
blockquote: Blockquote,
|
|
534
|
+
link: Link,
|
|
535
|
+
code: Code,
|
|
536
|
+
caption: Caption
|
|
537
|
+
};
|
|
311
538
|
function isEditableField(block) {
|
|
312
|
-
return block.variant === "field" && (block.type
|
|
539
|
+
return block.variant === "field" && isEditableType(block.type);
|
|
540
|
+
}
|
|
541
|
+
function isEditableType(type) {
|
|
542
|
+
return type === "heading" || type === "sub-heading" || type === "text" || type === "blockquote" || type === "link" || type === "code" || type === "caption";
|
|
543
|
+
}
|
|
544
|
+
function isMediaField(block) {
|
|
545
|
+
return block.variant === "field" && isMediaType(block.type);
|
|
546
|
+
}
|
|
547
|
+
function isMediaType(type) {
|
|
548
|
+
return type === "image" || type === "video" || type === "iframe";
|
|
549
|
+
}
|
|
550
|
+
function getIframeSrc(value) {
|
|
551
|
+
const input = value.trim();
|
|
552
|
+
const normalizedInput = input.startsWith("//") ? `https:${input}` : /^[a-z][\w+.-]*:\/\//i.test(input) ? input : `https://${input}`;
|
|
553
|
+
let url;
|
|
554
|
+
try {
|
|
555
|
+
url = new URL(normalizedInput);
|
|
556
|
+
} catch {
|
|
557
|
+
return value;
|
|
558
|
+
}
|
|
559
|
+
const hostname = url.hostname.toLowerCase().replace(/^www\./, "");
|
|
560
|
+
const isYouTube = ["youtube.com", "m.youtube.com", "music.youtube.com", "youtu.be"].includes(hostname);
|
|
561
|
+
if (!isYouTube)
|
|
562
|
+
return value;
|
|
563
|
+
const segments = url.pathname.split("/").filter(Boolean);
|
|
564
|
+
const videoId = hostname === "youtu.be" ? segments[0] : segments[0] === "watch" ? url.searchParams.get("v") : ["embed", "shorts", "live"].includes(segments[0] ?? "") ? segments[1] : undefined;
|
|
565
|
+
if (!videoId || !/^[\w-]{11}$/.test(videoId))
|
|
566
|
+
return null;
|
|
567
|
+
return `https://www.youtube.com/embed/${videoId}?enablejsapi=1`;
|
|
313
568
|
}
|
|
314
569
|
function NewTextField(defaultValue) {
|
|
315
570
|
return new FieldClass({
|
|
@@ -321,7 +576,8 @@ function NewTextField(defaultValue) {
|
|
|
321
576
|
props: {
|
|
322
577
|
children: { text: "", marks: [] },
|
|
323
578
|
"data-text-path": "props.children",
|
|
324
|
-
contentEditable: false
|
|
579
|
+
contentEditable: false,
|
|
580
|
+
...DEFAULT_STYLES["text"]
|
|
325
581
|
},
|
|
326
582
|
...defaultValue
|
|
327
583
|
});
|
|
@@ -336,7 +592,24 @@ function NewHeadingField(defaultValue) {
|
|
|
336
592
|
props: {
|
|
337
593
|
children: { text: "", marks: [] },
|
|
338
594
|
"data-text-path": "props.children",
|
|
339
|
-
contentEditable: false
|
|
595
|
+
contentEditable: false,
|
|
596
|
+
...DEFAULT_STYLES["heading"]
|
|
597
|
+
},
|
|
598
|
+
...defaultValue
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
function NewSubHeadingField(defaultValue) {
|
|
602
|
+
return new FieldClass({
|
|
603
|
+
id: UTILS.generateFieldId(),
|
|
604
|
+
name: "Sub-heading field",
|
|
605
|
+
type: "sub-heading",
|
|
606
|
+
tag: "h2",
|
|
607
|
+
variant: "field",
|
|
608
|
+
props: {
|
|
609
|
+
children: { text: "", marks: [] },
|
|
610
|
+
"data-text-path": "props.children",
|
|
611
|
+
contentEditable: false,
|
|
612
|
+
...DEFAULT_STYLES["sub-heading"]
|
|
340
613
|
},
|
|
341
614
|
...defaultValue
|
|
342
615
|
});
|
|
@@ -348,7 +621,11 @@ function NewImageField(defaultValue) {
|
|
|
348
621
|
type: "image",
|
|
349
622
|
tag: "img",
|
|
350
623
|
variant: "field",
|
|
351
|
-
props: {
|
|
624
|
+
props: {
|
|
625
|
+
src: "",
|
|
626
|
+
alt: "image",
|
|
627
|
+
...DEFAULT_STYLES["image"]
|
|
628
|
+
},
|
|
352
629
|
...defaultValue
|
|
353
630
|
});
|
|
354
631
|
}
|
|
@@ -359,18 +636,111 @@ function NewVideoField(defaultValue) {
|
|
|
359
636
|
type: "video",
|
|
360
637
|
tag: "video",
|
|
361
638
|
variant: "field",
|
|
362
|
-
props: {
|
|
639
|
+
props: {
|
|
640
|
+
src: "",
|
|
641
|
+
alt: "video",
|
|
642
|
+
controlsList: "nodownload nofullscreen noremoteplayback noplaybackrate",
|
|
643
|
+
preload: "metadata",
|
|
644
|
+
controls: true,
|
|
645
|
+
...DEFAULT_STYLES["video"]
|
|
646
|
+
},
|
|
647
|
+
...defaultValue
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
function NewIFrameField(defaultValue) {
|
|
651
|
+
return new FieldClass({
|
|
652
|
+
id: UTILS.generateFieldId(),
|
|
653
|
+
name: "IFrame field",
|
|
654
|
+
type: "iframe",
|
|
655
|
+
tag: "iframe",
|
|
656
|
+
variant: "field",
|
|
657
|
+
props: {
|
|
658
|
+
src: "",
|
|
659
|
+
alt: "image",
|
|
660
|
+
allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",
|
|
661
|
+
referrerPolicy: "strict-origin-when-cross-origin",
|
|
662
|
+
allowFullScreen: false,
|
|
663
|
+
frameBorder: 0,
|
|
664
|
+
...DEFAULT_STYLES["iframe"]
|
|
665
|
+
},
|
|
666
|
+
...defaultValue
|
|
667
|
+
});
|
|
668
|
+
}
|
|
669
|
+
function NewLinkField(defaultValue) {
|
|
670
|
+
return new FieldClass({
|
|
671
|
+
id: UTILS.generateFieldId(),
|
|
672
|
+
name: "Link field",
|
|
673
|
+
type: "link",
|
|
674
|
+
tag: "a",
|
|
675
|
+
variant: "field",
|
|
676
|
+
props: {
|
|
677
|
+
href: "#",
|
|
678
|
+
alt: "Preview new link",
|
|
679
|
+
"data-text-path": "props.children",
|
|
680
|
+
children: { text: "Preview new link", marks: [] },
|
|
681
|
+
...DEFAULT_STYLES["link"]
|
|
682
|
+
},
|
|
683
|
+
...defaultValue
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
function NewBlockquoteField(defaultValue) {
|
|
687
|
+
return new FieldClass({
|
|
688
|
+
id: UTILS.generateFieldId(),
|
|
689
|
+
name: "Blockquote field",
|
|
690
|
+
type: "blockquote",
|
|
691
|
+
tag: "blockquote",
|
|
692
|
+
variant: "field",
|
|
693
|
+
props: {
|
|
694
|
+
"data-text-path": "props.children",
|
|
695
|
+
children: { text: "", marks: [] },
|
|
696
|
+
...DEFAULT_STYLES["blockquote"]
|
|
697
|
+
},
|
|
363
698
|
...defaultValue
|
|
364
699
|
});
|
|
365
700
|
}
|
|
366
701
|
function NewDividerField(defaultValue) {
|
|
367
702
|
return new FieldClass({
|
|
368
703
|
id: UTILS.generateFieldId(),
|
|
369
|
-
name: "
|
|
704
|
+
name: "Divider field",
|
|
370
705
|
type: "divider",
|
|
371
706
|
tag: "hr",
|
|
372
707
|
variant: "field",
|
|
373
|
-
props: {
|
|
708
|
+
props: {
|
|
709
|
+
...DEFAULT_STYLES["divider"]
|
|
710
|
+
},
|
|
711
|
+
...defaultValue
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
function NewCodeField(defaultValue) {
|
|
715
|
+
return new FieldClass({
|
|
716
|
+
id: UTILS.generateFieldId(),
|
|
717
|
+
name: "Code field",
|
|
718
|
+
type: "code",
|
|
719
|
+
tag: "pre",
|
|
720
|
+
variant: "field",
|
|
721
|
+
props: {
|
|
722
|
+
"data-text-path": "props.children",
|
|
723
|
+
children: { text: "", marks: [] },
|
|
724
|
+
theme: "dark",
|
|
725
|
+
contentEditable: false,
|
|
726
|
+
...DEFAULT_STYLES["code"]
|
|
727
|
+
},
|
|
728
|
+
...defaultValue
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
function NewCaptionField(defaultValue) {
|
|
732
|
+
return new FieldClass({
|
|
733
|
+
id: UTILS.generateFieldId(),
|
|
734
|
+
name: "Caption field",
|
|
735
|
+
type: "caption",
|
|
736
|
+
tag: "figcaption",
|
|
737
|
+
variant: "field",
|
|
738
|
+
props: {
|
|
739
|
+
"data-text-path": "props.children",
|
|
740
|
+
children: { text: "", marks: [] },
|
|
741
|
+
contentEditable: false,
|
|
742
|
+
...DEFAULT_STYLES["caption"]
|
|
743
|
+
},
|
|
374
744
|
...defaultValue
|
|
375
745
|
});
|
|
376
746
|
}
|
|
@@ -380,115 +750,45 @@ function NewField(type, defaultValue) {
|
|
|
380
750
|
return NewTextField(defaultValue);
|
|
381
751
|
case "heading":
|
|
382
752
|
return NewHeadingField(defaultValue);
|
|
753
|
+
case "sub-heading":
|
|
754
|
+
return NewSubHeadingField(defaultValue);
|
|
383
755
|
case "image":
|
|
384
756
|
return NewImageField(defaultValue);
|
|
385
757
|
case "video":
|
|
386
758
|
return NewVideoField(defaultValue);
|
|
759
|
+
case "link":
|
|
760
|
+
return NewLinkField(defaultValue);
|
|
387
761
|
case "divider":
|
|
388
762
|
return NewDividerField(defaultValue);
|
|
763
|
+
case "iframe":
|
|
764
|
+
return NewIFrameField(defaultValue);
|
|
765
|
+
case "blockquote":
|
|
766
|
+
return NewBlockquoteField(defaultValue);
|
|
767
|
+
case "code":
|
|
768
|
+
return NewCodeField(defaultValue);
|
|
769
|
+
case "caption":
|
|
770
|
+
return NewCaptionField(defaultValue);
|
|
389
771
|
default:
|
|
390
772
|
return NewTextField(defaultValue);
|
|
391
773
|
}
|
|
392
774
|
}
|
|
393
|
-
function DeserializeField(
|
|
394
|
-
return new FieldClass(
|
|
775
|
+
function DeserializeField(field4) {
|
|
776
|
+
return new FieldClass(field4);
|
|
395
777
|
}
|
|
396
778
|
var FieldsUtils = {
|
|
397
779
|
NewField,
|
|
398
780
|
DeserializeField,
|
|
399
781
|
NewTextField,
|
|
400
782
|
NewHeadingField,
|
|
783
|
+
NewSubHeadingField,
|
|
784
|
+
NewLinkField,
|
|
401
785
|
NewImageField,
|
|
402
|
-
NewDividerField
|
|
786
|
+
NewDividerField,
|
|
787
|
+
NewIFrameField,
|
|
788
|
+
NewBlockquoteField,
|
|
789
|
+
NewCodeField,
|
|
790
|
+
NewCaptionField
|
|
403
791
|
};
|
|
404
|
-
// src/utils/modules.utils.ts
|
|
405
|
-
function createScopedTCtx(engine, moduleName) {
|
|
406
|
-
const disposers = [];
|
|
407
|
-
function trackFn(disposer) {
|
|
408
|
-
let done = false;
|
|
409
|
-
const safe = () => {
|
|
410
|
-
if (!done) {
|
|
411
|
-
done = true;
|
|
412
|
-
disposer();
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
disposers.push(safe);
|
|
416
|
-
return disposer;
|
|
417
|
-
}
|
|
418
|
-
const ctx = {
|
|
419
|
-
events: {
|
|
420
|
-
on: (ev, handler) => trackFn(engine.events.on(ev, handler)),
|
|
421
|
-
emit: (ev, props) => engine.events.emit(ev, props),
|
|
422
|
-
batch: (evs) => engine.events.batch(evs)
|
|
423
|
-
},
|
|
424
|
-
commands: {
|
|
425
|
-
register: (cmd, handler) => trackFn(engine.commands.register(cmd, handler)),
|
|
426
|
-
registerAsync: (cmd, handler) => trackFn(engine.commands.registerAsync(cmd, handler)),
|
|
427
|
-
tryExecute: (cmd, payload) => engine.commands.tryExecute(cmd, payload),
|
|
428
|
-
tryExecuteAsync: (cmd, payload) => engine.commands.tryExecuteAsync(cmd, payload),
|
|
429
|
-
execute: (cmd, payload) => engine.commands.execute(cmd, payload),
|
|
430
|
-
executeAsync: (cmd, payload) => engine.commands.executeAsync(cmd, payload),
|
|
431
|
-
before: (cmd, next) => trackFn(engine.commands.before(cmd, next)),
|
|
432
|
-
beforeAsync: (cmd, next) => trackFn(engine.commands.beforeAsync(cmd, next)),
|
|
433
|
-
after: (cmd, callback) => trackFn(engine.commands.after(cmd, callback)),
|
|
434
|
-
afterAsync: (cmd, callback) => trackFn(engine.commands.afterAsync(cmd, callback)),
|
|
435
|
-
has: (cmd) => engine.commands.has(cmd)
|
|
436
|
-
},
|
|
437
|
-
state: {
|
|
438
|
-
defineSlice: (name2, initial) => {
|
|
439
|
-
return trackFn(engine.state.defineSlice(name2, initial));
|
|
440
|
-
},
|
|
441
|
-
get: (name2) => engine.state.get(name2),
|
|
442
|
-
set: (name2, next) => {
|
|
443
|
-
engine.state.set(name2, next);
|
|
444
|
-
},
|
|
445
|
-
subscribe: (name2, fn) => trackFn(engine.state.subscribe(name2, fn))
|
|
446
|
-
},
|
|
447
|
-
document: engine.document,
|
|
448
|
-
mutations: engine.mutations,
|
|
449
|
-
shortcuts: engine.shortcuts,
|
|
450
|
-
text: {
|
|
451
|
-
registerMark: (type, behavior) => trackFn(engine.text.registerMark(type, behavior)),
|
|
452
|
-
toggleMark: (c, o) => engine.text.toggleMark(c, o),
|
|
453
|
-
insertText: (c, at, t, o) => engine.text.insertText(c, at, t, o),
|
|
454
|
-
deleteRange: (c, s, e) => engine.text.deleteRange(c, s, e),
|
|
455
|
-
replaceRange: (c, s, e, t, o) => engine.text.replaceRange(c, s, e, t, o),
|
|
456
|
-
isInclusive: (t) => engine.text.isInclusive(t)
|
|
457
|
-
},
|
|
458
|
-
ui: {
|
|
459
|
-
contribute: (slotName, c) => trackFn(engine.ui.contribute(slotName, {
|
|
460
|
-
...c,
|
|
461
|
-
id: `${moduleName}.${c.id}`,
|
|
462
|
-
when: c.when
|
|
463
|
-
})),
|
|
464
|
-
subscribe: (slotName, fn) => trackFn(engine.ui.subscribe(slotName, fn)),
|
|
465
|
-
getSlots: (slotName) => engine.ui.getSlots(slotName),
|
|
466
|
-
registerStyle: (styleName, css2) => trackFn(engine.ui.registerStyle(styleName, css2)),
|
|
467
|
-
patchStyle: (styleName, patch) => trackFn(engine.ui.patchStyle(styleName, patch)),
|
|
468
|
-
getStyle: (styleName) => engine.ui.getStyle(styleName),
|
|
469
|
-
interceptPayload: (id, fn) => trackFn(engine.ui.interceptPayload(id, fn)),
|
|
470
|
-
runContribution: (c, ui) => engine.ui.runContribution(c, ui)
|
|
471
|
-
},
|
|
472
|
-
tasks: {
|
|
473
|
-
schedule: (name2, delay, fn) => trackFn(engine.tasks.schedule(name2, delay, fn)),
|
|
474
|
-
cancel: (name2) => engine.tasks.cancel(name2),
|
|
475
|
-
isPending: (name2) => engine.tasks.isPending(name2),
|
|
476
|
-
isRunning: (name2) => engine.tasks.isRunning(name2),
|
|
477
|
-
getStatus: (name2) => engine.tasks.getStatus(name2),
|
|
478
|
-
getState: (name2) => engine.tasks.getState(name2),
|
|
479
|
-
subscribe: (name2, fn) => trackFn(engine.tasks.subscribe(name2, fn)),
|
|
480
|
-
flush: (name2) => engine.tasks.flush(name2),
|
|
481
|
-
cancelAll: () => engine.tasks.cancelAll(),
|
|
482
|
-
dispose: () => engine.tasks.dispose()
|
|
483
|
-
}
|
|
484
|
-
};
|
|
485
|
-
return {
|
|
486
|
-
ctx,
|
|
487
|
-
dispose: () => disposers.splice(0).reverse().forEach((dp) => dp())
|
|
488
|
-
};
|
|
489
|
-
}
|
|
490
|
-
var ModuleUtils = { createScopedTCtx };
|
|
491
|
-
// src/utils/tnode.utils.ts
|
|
492
792
|
function NewLinkTNode(defaultValue) {
|
|
493
793
|
return new TNodeClass({
|
|
494
794
|
id: UTILS.generateTNodeId(),
|
|
@@ -523,7 +823,6 @@ function DeserializeTNode(tnode2) {
|
|
|
523
823
|
return new TNodeClass(tnode2);
|
|
524
824
|
}
|
|
525
825
|
var TNodesUtils = { NewTNode, DeserializeTNode };
|
|
526
|
-
// src/utils/tree.utils.ts
|
|
527
826
|
function SerializeTree(tree2) {
|
|
528
827
|
const newFields = Array.from(tree2.fields.entries()).reduce((prev, [id, currentField]) => {
|
|
529
828
|
prev[id] = currentField.getCurrentFieldObject();
|
|
@@ -540,7 +839,7 @@ function SerializeTree(tree2) {
|
|
|
540
839
|
return {
|
|
541
840
|
id: tree2.id,
|
|
542
841
|
version: tree2.version,
|
|
543
|
-
order: tree2.order,
|
|
842
|
+
order: [...tree2.order],
|
|
544
843
|
fields: newFields,
|
|
545
844
|
containers: newContainers,
|
|
546
845
|
components: newComponents
|
|
@@ -550,19 +849,19 @@ function DeserializeTree(tree2) {
|
|
|
550
849
|
const newFields = UTILS.ObjectEntries(tree2.fields).reduce((prev, [id, currentField]) => {
|
|
551
850
|
prev.set(id, FieldsUtils.DeserializeField(currentField));
|
|
552
851
|
return prev;
|
|
553
|
-
},
|
|
852
|
+
}, new Map);
|
|
554
853
|
const newContainers = UTILS.ObjectEntries(tree2.containers).reduce((prev, [id, currentContainer]) => {
|
|
555
854
|
prev.set(id, ContainersUtils.DeserializeContainer(currentContainer));
|
|
556
855
|
return prev;
|
|
557
|
-
},
|
|
856
|
+
}, new Map);
|
|
558
857
|
const newComponents = UTILS.ObjectEntries(tree2.components).reduce((prev, [id, currentComponent]) => {
|
|
559
858
|
prev.set(id, ComponentsUtils.DeserializeComponent(currentComponent));
|
|
560
859
|
return prev;
|
|
561
|
-
},
|
|
860
|
+
}, new Map);
|
|
562
861
|
return {
|
|
563
862
|
id: tree2.id,
|
|
564
863
|
version: tree2.version,
|
|
565
|
-
order: tree2.order,
|
|
864
|
+
order: new Set(tree2.order),
|
|
566
865
|
fields: newFields,
|
|
567
866
|
containers: newContainers,
|
|
568
867
|
components: newComponents
|
|
@@ -600,6 +899,429 @@ function coraxTreeDiffing(prev, next) {
|
|
|
600
899
|
}
|
|
601
900
|
return { added, removed, changed, orderChanged: prev.order !== next.order };
|
|
602
901
|
}
|
|
902
|
+
function segments({ text, marks }) {
|
|
903
|
+
if (!text)
|
|
904
|
+
return [];
|
|
905
|
+
const cuts = new Set([0, text.length]);
|
|
906
|
+
for (const m of marks) {
|
|
907
|
+
cuts.add(m.start);
|
|
908
|
+
cuts.add(m.end);
|
|
909
|
+
}
|
|
910
|
+
const points = [...cuts].sort((a, b) => a - b);
|
|
911
|
+
const out = [];
|
|
912
|
+
for (let i = 0;i < points.length - 1; i++) {
|
|
913
|
+
const [s, e] = [points[i], points[i + 1]];
|
|
914
|
+
out.push({
|
|
915
|
+
text: text.slice(s, e),
|
|
916
|
+
marks: marks.filter((m) => m.start <= s && m.end >= e)
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
return out;
|
|
920
|
+
}
|
|
921
|
+
var UNITLESS = new Set([
|
|
922
|
+
"animationIterationCount",
|
|
923
|
+
"aspectRatio",
|
|
924
|
+
"borderImageOutset",
|
|
925
|
+
"borderImageSlice",
|
|
926
|
+
"borderImageWidth",
|
|
927
|
+
"boxFlex",
|
|
928
|
+
"boxFlexGroup",
|
|
929
|
+
"boxOrdinalGroup",
|
|
930
|
+
"columnCount",
|
|
931
|
+
"columns",
|
|
932
|
+
"flex",
|
|
933
|
+
"flexGrow",
|
|
934
|
+
"flexPositive",
|
|
935
|
+
"flexShrink",
|
|
936
|
+
"flexNegative",
|
|
937
|
+
"flexOrder",
|
|
938
|
+
"gridArea",
|
|
939
|
+
"gridRow",
|
|
940
|
+
"gridRowEnd",
|
|
941
|
+
"gridRowSpan",
|
|
942
|
+
"gridRowStart",
|
|
943
|
+
"gridColumn",
|
|
944
|
+
"gridColumnEnd",
|
|
945
|
+
"gridColumnSpan",
|
|
946
|
+
"gridColumnStart",
|
|
947
|
+
"fontWeight",
|
|
948
|
+
"lineClamp",
|
|
949
|
+
"lineHeight",
|
|
950
|
+
"opacity",
|
|
951
|
+
"order",
|
|
952
|
+
"orphans",
|
|
953
|
+
"scale",
|
|
954
|
+
"tabSize",
|
|
955
|
+
"widows",
|
|
956
|
+
"zIndex",
|
|
957
|
+
"zoom",
|
|
958
|
+
"fillOpacity",
|
|
959
|
+
"floodOpacity",
|
|
960
|
+
"stopOpacity",
|
|
961
|
+
"strokeDasharray",
|
|
962
|
+
"strokeDashoffset",
|
|
963
|
+
"strokeMiterlimit",
|
|
964
|
+
"strokeOpacity",
|
|
965
|
+
"strokeWidth"
|
|
966
|
+
]);
|
|
967
|
+
function toKebab(property) {
|
|
968
|
+
return property.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
969
|
+
}
|
|
970
|
+
function toCssValue(property, value) {
|
|
971
|
+
if (Array.isArray(value))
|
|
972
|
+
return value.map((v) => String(v)).join(",");
|
|
973
|
+
if (typeof value === "number" && value !== 0 && !UNITLESS.has(property))
|
|
974
|
+
return `${value}px`;
|
|
975
|
+
return String(value);
|
|
976
|
+
}
|
|
977
|
+
function declarations(style) {
|
|
978
|
+
return Object.entries(style).map(([property, value]) => `${toKebab(property)}:${toCssValue(property, value)}`).join(";");
|
|
979
|
+
}
|
|
980
|
+
function serializeRules(style, selector) {
|
|
981
|
+
const rules = [];
|
|
982
|
+
const own = {};
|
|
983
|
+
for (const [key, value] of Object.entries(style)) {
|
|
984
|
+
if (value && typeof value === "object") {
|
|
985
|
+
rules.push(...serializeRules(value, `${selector}${key}`));
|
|
986
|
+
} else {
|
|
987
|
+
own[key] = value;
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
if (Object.keys(own).length > 0)
|
|
991
|
+
rules.push(`${selector}{${declarations(own)}}`);
|
|
992
|
+
return rules;
|
|
993
|
+
}
|
|
994
|
+
function stableStringify(value) {
|
|
995
|
+
if (value === null || typeof value !== "object")
|
|
996
|
+
return JSON.stringify(value) ?? "null";
|
|
997
|
+
if (Array.isArray(value))
|
|
998
|
+
return `[${value.map(stableStringify).join(",")}]`;
|
|
999
|
+
const entries = Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`);
|
|
1000
|
+
return `{${entries.join(",")}}`;
|
|
1001
|
+
}
|
|
1002
|
+
function hash(input) {
|
|
1003
|
+
let h = 2166136261;
|
|
1004
|
+
for (let i = 0;i < input.length; i++) {
|
|
1005
|
+
h ^= input.charCodeAt(i);
|
|
1006
|
+
h = Math.imul(h, 16777619);
|
|
1007
|
+
}
|
|
1008
|
+
return (h >>> 0).toString(36);
|
|
1009
|
+
}
|
|
1010
|
+
var collected = new Map;
|
|
1011
|
+
var sink = null;
|
|
1012
|
+
function collectCoraxPseudoStyle(style) {
|
|
1013
|
+
if (!style || Object.keys(style).length === 0)
|
|
1014
|
+
return;
|
|
1015
|
+
const className = `corax-p-${hash(stableStringify(style))}`;
|
|
1016
|
+
if (collected.has(className))
|
|
1017
|
+
return className;
|
|
1018
|
+
collected.set(className, serializeRules(style, `.${className}`).join(""));
|
|
1019
|
+
sink?.();
|
|
1020
|
+
return className;
|
|
1021
|
+
}
|
|
1022
|
+
function getCollectedStyles() {
|
|
1023
|
+
return Array.from(collected.values()).join("");
|
|
1024
|
+
}
|
|
1025
|
+
function clearCollectedStyles() {
|
|
1026
|
+
collected.clear();
|
|
1027
|
+
}
|
|
1028
|
+
function setCoraxStyleSink(fn) {
|
|
1029
|
+
sink = fn;
|
|
1030
|
+
fn();
|
|
1031
|
+
return () => {
|
|
1032
|
+
if (sink === fn)
|
|
1033
|
+
sink = null;
|
|
1034
|
+
};
|
|
1035
|
+
}
|
|
1036
|
+
var CODE_THEMES = {
|
|
1037
|
+
dark: {
|
|
1038
|
+
plain: "#e6edf3",
|
|
1039
|
+
keyword: "#ff7b72",
|
|
1040
|
+
string: "#a5d6ff",
|
|
1041
|
+
number: "#79c0ff",
|
|
1042
|
+
comment: "#8b949e",
|
|
1043
|
+
function: "#d2a8ff",
|
|
1044
|
+
punctuation: "#e6edf3",
|
|
1045
|
+
operator: "#ff7b72"
|
|
1046
|
+
},
|
|
1047
|
+
light: {
|
|
1048
|
+
plain: "#24292f",
|
|
1049
|
+
keyword: "#cf222e",
|
|
1050
|
+
string: "#0a3069",
|
|
1051
|
+
number: "#0550ae",
|
|
1052
|
+
comment: "#6e7781",
|
|
1053
|
+
function: "#8250df",
|
|
1054
|
+
punctuation: "#24292f",
|
|
1055
|
+
operator: "#cf222e"
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
var CODE_THEME_NAMES = Object.keys(CODE_THEMES);
|
|
1059
|
+
var KEYWORDS = new Set([
|
|
1060
|
+
"const",
|
|
1061
|
+
"let",
|
|
1062
|
+
"var",
|
|
1063
|
+
"function",
|
|
1064
|
+
"class",
|
|
1065
|
+
"extends",
|
|
1066
|
+
"return",
|
|
1067
|
+
"if",
|
|
1068
|
+
"else",
|
|
1069
|
+
"for",
|
|
1070
|
+
"while",
|
|
1071
|
+
"do",
|
|
1072
|
+
"switch",
|
|
1073
|
+
"case",
|
|
1074
|
+
"break",
|
|
1075
|
+
"continue",
|
|
1076
|
+
"new",
|
|
1077
|
+
"typeof",
|
|
1078
|
+
"instanceof",
|
|
1079
|
+
"in",
|
|
1080
|
+
"of",
|
|
1081
|
+
"this",
|
|
1082
|
+
"super",
|
|
1083
|
+
"import",
|
|
1084
|
+
"export",
|
|
1085
|
+
"from",
|
|
1086
|
+
"default",
|
|
1087
|
+
"as",
|
|
1088
|
+
"async",
|
|
1089
|
+
"await",
|
|
1090
|
+
"yield",
|
|
1091
|
+
"try",
|
|
1092
|
+
"catch",
|
|
1093
|
+
"finally",
|
|
1094
|
+
"throw",
|
|
1095
|
+
"delete",
|
|
1096
|
+
"void",
|
|
1097
|
+
"null",
|
|
1098
|
+
"undefined",
|
|
1099
|
+
"true",
|
|
1100
|
+
"false",
|
|
1101
|
+
"interface",
|
|
1102
|
+
"type",
|
|
1103
|
+
"enum",
|
|
1104
|
+
"implements",
|
|
1105
|
+
"public",
|
|
1106
|
+
"private",
|
|
1107
|
+
"protected",
|
|
1108
|
+
"readonly",
|
|
1109
|
+
"static",
|
|
1110
|
+
"get",
|
|
1111
|
+
"set",
|
|
1112
|
+
"declare",
|
|
1113
|
+
"namespace",
|
|
1114
|
+
"abstract",
|
|
1115
|
+
"satisfies",
|
|
1116
|
+
"keyof",
|
|
1117
|
+
"infer",
|
|
1118
|
+
"is",
|
|
1119
|
+
"any",
|
|
1120
|
+
"string",
|
|
1121
|
+
"number",
|
|
1122
|
+
"boolean",
|
|
1123
|
+
"never",
|
|
1124
|
+
"unknown",
|
|
1125
|
+
"object",
|
|
1126
|
+
"symbol",
|
|
1127
|
+
"bigint"
|
|
1128
|
+
]);
|
|
1129
|
+
var isIdentStart = (c) => /[A-Za-z_$]/.test(c);
|
|
1130
|
+
var isIdentPart = (c) => /[A-Za-z0-9_$]/.test(c);
|
|
1131
|
+
var isDigit = (c) => c >= "0" && c <= "9";
|
|
1132
|
+
function tokenizeCode(input) {
|
|
1133
|
+
const tokens = [];
|
|
1134
|
+
const push = (type, value) => {
|
|
1135
|
+
if (!value)
|
|
1136
|
+
return;
|
|
1137
|
+
const last = tokens[tokens.length - 1];
|
|
1138
|
+
if (last && last.type === type)
|
|
1139
|
+
last.value += value;
|
|
1140
|
+
else
|
|
1141
|
+
tokens.push({ type, value });
|
|
1142
|
+
};
|
|
1143
|
+
let i = 0;
|
|
1144
|
+
const n = input.length;
|
|
1145
|
+
while (i < n) {
|
|
1146
|
+
const c = input[i];
|
|
1147
|
+
const next = input[i + 1];
|
|
1148
|
+
if (/\s/.test(c)) {
|
|
1149
|
+
let j = i + 1;
|
|
1150
|
+
while (j < n && /\s/.test(input[j]))
|
|
1151
|
+
j++;
|
|
1152
|
+
push("plain", input.slice(i, j));
|
|
1153
|
+
i = j;
|
|
1154
|
+
continue;
|
|
1155
|
+
}
|
|
1156
|
+
if (c === "/" && next === "/") {
|
|
1157
|
+
let j = i + 2;
|
|
1158
|
+
while (j < n && input[j] !== `
|
|
1159
|
+
`)
|
|
1160
|
+
j++;
|
|
1161
|
+
push("comment", input.slice(i, j));
|
|
1162
|
+
i = j;
|
|
1163
|
+
continue;
|
|
1164
|
+
}
|
|
1165
|
+
if (c === "/" && next === "*") {
|
|
1166
|
+
let j = i + 2;
|
|
1167
|
+
while (j < n && !(input[j] === "*" && input[j + 1] === "/"))
|
|
1168
|
+
j++;
|
|
1169
|
+
j = Math.min(n, j + 2);
|
|
1170
|
+
push("comment", input.slice(i, j));
|
|
1171
|
+
i = j;
|
|
1172
|
+
continue;
|
|
1173
|
+
}
|
|
1174
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
1175
|
+
let j = i + 1;
|
|
1176
|
+
while (j < n) {
|
|
1177
|
+
if (input[j] === "\\") {
|
|
1178
|
+
j += 2;
|
|
1179
|
+
continue;
|
|
1180
|
+
}
|
|
1181
|
+
if (input[j] === c) {
|
|
1182
|
+
j++;
|
|
1183
|
+
break;
|
|
1184
|
+
}
|
|
1185
|
+
if (c !== "`" && input[j] === `
|
|
1186
|
+
`)
|
|
1187
|
+
break;
|
|
1188
|
+
j++;
|
|
1189
|
+
}
|
|
1190
|
+
push("string", input.slice(i, j));
|
|
1191
|
+
i = j;
|
|
1192
|
+
continue;
|
|
1193
|
+
}
|
|
1194
|
+
if (isDigit(c)) {
|
|
1195
|
+
let j = i;
|
|
1196
|
+
while (j < n && /[0-9a-fA-FxXoObBeE._]/.test(input[j]))
|
|
1197
|
+
j++;
|
|
1198
|
+
if (j < n && (input[j] === "+" || input[j] === "-") && /[eE]/.test(input[j - 1]))
|
|
1199
|
+
j++;
|
|
1200
|
+
while (j < n && isDigit(input[j]))
|
|
1201
|
+
j++;
|
|
1202
|
+
push("number", input.slice(i, j));
|
|
1203
|
+
i = j;
|
|
1204
|
+
continue;
|
|
1205
|
+
}
|
|
1206
|
+
if (isIdentStart(c)) {
|
|
1207
|
+
let j = i + 1;
|
|
1208
|
+
while (j < n && isIdentPart(input[j]))
|
|
1209
|
+
j++;
|
|
1210
|
+
const word = input.slice(i, j);
|
|
1211
|
+
let k = j;
|
|
1212
|
+
while (k < n && /\s/.test(input[k]))
|
|
1213
|
+
k++;
|
|
1214
|
+
if (KEYWORDS.has(word))
|
|
1215
|
+
push("keyword", word);
|
|
1216
|
+
else if (input[k] === "(")
|
|
1217
|
+
push("function", word);
|
|
1218
|
+
else
|
|
1219
|
+
push("plain", word);
|
|
1220
|
+
i = j;
|
|
1221
|
+
continue;
|
|
1222
|
+
}
|
|
1223
|
+
if (/[{}()[\];,.]/.test(c)) {
|
|
1224
|
+
push("punctuation", c);
|
|
1225
|
+
i++;
|
|
1226
|
+
continue;
|
|
1227
|
+
}
|
|
1228
|
+
if (/[=+\-*/%<>!&|^~?:]/.test(c)) {
|
|
1229
|
+
push("operator", c);
|
|
1230
|
+
i++;
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
push("plain", c);
|
|
1234
|
+
i++;
|
|
1235
|
+
}
|
|
1236
|
+
return tokens;
|
|
1237
|
+
}
|
|
1238
|
+
// src/utils/modules.utils.ts
|
|
1239
|
+
function createScopedTCtx(engine, moduleName) {
|
|
1240
|
+
const disposers = [];
|
|
1241
|
+
function trackFn(disposer) {
|
|
1242
|
+
let done = false;
|
|
1243
|
+
const safe = () => {
|
|
1244
|
+
if (!done) {
|
|
1245
|
+
done = true;
|
|
1246
|
+
disposer();
|
|
1247
|
+
}
|
|
1248
|
+
};
|
|
1249
|
+
disposers.push(safe);
|
|
1250
|
+
return disposer;
|
|
1251
|
+
}
|
|
1252
|
+
const ctx = {
|
|
1253
|
+
events: {
|
|
1254
|
+
on: (ev, handler) => trackFn(engine.events.on(ev, handler)),
|
|
1255
|
+
emit: (ev, props) => engine.events.emit(ev, props),
|
|
1256
|
+
batch: (evs) => engine.events.batch(evs)
|
|
1257
|
+
},
|
|
1258
|
+
commands: {
|
|
1259
|
+
register: (cmd, handler) => trackFn(engine.commands.register(cmd, handler)),
|
|
1260
|
+
registerAsync: (cmd, handler) => trackFn(engine.commands.registerAsync(cmd, handler)),
|
|
1261
|
+
tryExecute: (cmd, payload) => engine.commands.tryExecute(cmd, payload),
|
|
1262
|
+
tryExecuteAsync: (cmd, payload) => engine.commands.tryExecuteAsync(cmd, payload),
|
|
1263
|
+
execute: (cmd, payload) => engine.commands.execute(cmd, payload),
|
|
1264
|
+
executeAsync: (cmd, payload) => engine.commands.executeAsync(cmd, payload),
|
|
1265
|
+
before: (cmd, next) => trackFn(engine.commands.before(cmd, next)),
|
|
1266
|
+
beforeAsync: (cmd, next) => trackFn(engine.commands.beforeAsync(cmd, next)),
|
|
1267
|
+
after: (cmd, callback) => trackFn(engine.commands.after(cmd, callback)),
|
|
1268
|
+
afterAsync: (cmd, callback) => trackFn(engine.commands.afterAsync(cmd, callback)),
|
|
1269
|
+
has: (cmd) => engine.commands.has(cmd)
|
|
1270
|
+
},
|
|
1271
|
+
state: {
|
|
1272
|
+
defineSlice: (name2, initial) => {
|
|
1273
|
+
return trackFn(engine.state.defineSlice(name2, initial));
|
|
1274
|
+
},
|
|
1275
|
+
get: (name2) => engine.state.get(name2),
|
|
1276
|
+
set: (name2, next) => {
|
|
1277
|
+
engine.state.set(name2, next);
|
|
1278
|
+
},
|
|
1279
|
+
subscribe: (name2, fn) => trackFn(engine.state.subscribe(name2, fn))
|
|
1280
|
+
},
|
|
1281
|
+
document: engine.document,
|
|
1282
|
+
mutations: engine.mutations,
|
|
1283
|
+
shortcuts: engine.shortcuts,
|
|
1284
|
+
text: {
|
|
1285
|
+
registerMark: (type, behavior) => trackFn(engine.text.registerMark(type, behavior)),
|
|
1286
|
+
toggleMark: (c, o) => engine.text.toggleMark(c, o),
|
|
1287
|
+
insertText: (c, at, t, o) => engine.text.insertText(c, at, t, o),
|
|
1288
|
+
deleteRange: (c, s, e) => engine.text.deleteRange(c, s, e),
|
|
1289
|
+
replaceRange: (c, s, e, t, o) => engine.text.replaceRange(c, s, e, t, o),
|
|
1290
|
+
isInclusive: (t) => engine.text.isInclusive(t)
|
|
1291
|
+
},
|
|
1292
|
+
ui: {
|
|
1293
|
+
contribute: (c) => trackFn(engine.ui.contribute({
|
|
1294
|
+
...c,
|
|
1295
|
+
id: `${moduleName}.${c.id}`,
|
|
1296
|
+
when: c.when
|
|
1297
|
+
})),
|
|
1298
|
+
subscribe: (slotName, fn) => trackFn(engine.ui.subscribe(slotName, fn)),
|
|
1299
|
+
getSlots: (slotName) => engine.ui.getSlots(slotName),
|
|
1300
|
+
registerStyle: (styleName, css) => trackFn(engine.ui.registerStyle(styleName, css)),
|
|
1301
|
+
patchStyle: (styleName, patch) => trackFn(engine.ui.patchStyle(styleName, patch)),
|
|
1302
|
+
getStyle: (styleName) => engine.ui.getStyle(styleName),
|
|
1303
|
+
interceptPayload: (id, fn) => trackFn(engine.ui.interceptPayload(id, fn)),
|
|
1304
|
+
runContribution: (c, ui) => engine.ui.runContribution(c, ui)
|
|
1305
|
+
},
|
|
1306
|
+
tasks: {
|
|
1307
|
+
schedule: (name2, delay, fn) => trackFn(engine.tasks.schedule(name2, delay, fn)),
|
|
1308
|
+
cancel: (name2) => engine.tasks.cancel(name2),
|
|
1309
|
+
isPending: (name2) => engine.tasks.isPending(name2),
|
|
1310
|
+
isRunning: (name2) => engine.tasks.isRunning(name2),
|
|
1311
|
+
getStatus: (name2) => engine.tasks.getStatus(name2),
|
|
1312
|
+
getState: (name2) => engine.tasks.getState(name2),
|
|
1313
|
+
subscribe: (name2, fn) => trackFn(engine.tasks.subscribe(name2, fn)),
|
|
1314
|
+
flush: (name2) => engine.tasks.flush(name2),
|
|
1315
|
+
cancelAll: () => engine.tasks.cancelAll(),
|
|
1316
|
+
dispose: () => engine.tasks.dispose()
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
return {
|
|
1320
|
+
ctx,
|
|
1321
|
+
dispose: () => disposers.splice(0).reverse().forEach((dp) => dp())
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
var ModuleUtils = { createScopedTCtx };
|
|
603
1325
|
// src/modules/modules-manager.ts
|
|
604
1326
|
class ModuleManager {
|
|
605
1327
|
registry = new Map;
|
|
@@ -619,6 +1341,9 @@ class ModuleManager {
|
|
|
619
1341
|
isEnabled(name2) {
|
|
620
1342
|
return this.active.has(name2);
|
|
621
1343
|
}
|
|
1344
|
+
isRegistered(name2) {
|
|
1345
|
+
return this.registry.has(name2);
|
|
1346
|
+
}
|
|
622
1347
|
enable(name2) {
|
|
623
1348
|
this.enableRec(name2, []);
|
|
624
1349
|
}
|
|
@@ -1047,28 +1772,28 @@ class MutationPrototypeError extends MutationError {
|
|
|
1047
1772
|
var FORBIDDEN = new Set(["__proto__", "constructor", "prototype"]);
|
|
1048
1773
|
|
|
1049
1774
|
class MutationsService {
|
|
1050
|
-
insertField(
|
|
1051
|
-
const hasField =
|
|
1775
|
+
insertField(tree, _field, index) {
|
|
1776
|
+
const hasField = tree.order.has(_field.id);
|
|
1052
1777
|
if (hasField) {
|
|
1053
1778
|
throw new MutationError(`Field ${_field.name} with ID (${_field.id}) already exists`);
|
|
1054
1779
|
}
|
|
1055
|
-
const
|
|
1056
|
-
if (!(
|
|
1057
|
-
throw new MutationPrototypeError(
|
|
1780
|
+
const field = _field instanceof FieldClass ? _field : new FieldClass(_field);
|
|
1781
|
+
if (!(field instanceof FieldClass)) {
|
|
1782
|
+
throw new MutationPrototypeError(field.name);
|
|
1058
1783
|
}
|
|
1059
1784
|
if (index === 0) {
|
|
1060
1785
|
throw new MutationError(`Cannot delete the first field!`);
|
|
1061
1786
|
}
|
|
1062
|
-
if (
|
|
1063
|
-
const hasContainer =
|
|
1064
|
-
const hasContainerInOrder =
|
|
1787
|
+
if (field.containerId) {
|
|
1788
|
+
const hasContainer = tree.containers.has(field.containerId);
|
|
1789
|
+
const hasContainerInOrder = tree.order.has(field.containerId);
|
|
1065
1790
|
if (!hasContainer || !hasContainerInOrder) {
|
|
1066
|
-
throw new MutationError(`Insert of Field ${
|
|
1791
|
+
throw new MutationError(`Insert of Field ${field.name} with ID (${field.id}) failed. Container ${field.containerId} does not exist`);
|
|
1067
1792
|
}
|
|
1068
|
-
|
|
1069
|
-
id:
|
|
1793
|
+
tree = this.mutateContainer(tree, {
|
|
1794
|
+
id: field.containerId,
|
|
1070
1795
|
keyValuePairs: {
|
|
1071
|
-
order: new Set([
|
|
1796
|
+
order: new Set([field.id])
|
|
1072
1797
|
}
|
|
1073
1798
|
});
|
|
1074
1799
|
}
|
|
@@ -1077,45 +1802,51 @@ class MutationsService {
|
|
|
1077
1802
|
if (index < 0) {
|
|
1078
1803
|
console.warn(`Mutation: negative index detected '${index}'`);
|
|
1079
1804
|
}
|
|
1080
|
-
const orderArray = Array.from(
|
|
1081
|
-
|
|
1805
|
+
const orderArray = Array.from(tree.order);
|
|
1806
|
+
let targetIndex = index;
|
|
1807
|
+
const previous = tree.fields.get(orderArray[targetIndex - 1]);
|
|
1808
|
+
const current = tree.fields.get(orderArray[targetIndex]);
|
|
1809
|
+
const isAttachedCaption = !!previous && isMediaType(previous.type) && !!current && current.type === "caption" && current.props.mediaId === previous.id;
|
|
1810
|
+
if (isAttachedCaption)
|
|
1811
|
+
targetIndex++;
|
|
1812
|
+
orderArray.splice(targetIndex, 0, field.id);
|
|
1082
1813
|
order = new Set(orderArray);
|
|
1083
1814
|
} else {
|
|
1084
|
-
order = new Set(
|
|
1085
|
-
order.add(
|
|
1815
|
+
order = new Set(tree.order);
|
|
1816
|
+
order.add(field.id);
|
|
1086
1817
|
}
|
|
1087
|
-
const
|
|
1088
|
-
|
|
1818
|
+
const fields = new Map(tree.fields);
|
|
1819
|
+
fields.set(field.id, field);
|
|
1089
1820
|
return {
|
|
1090
|
-
...
|
|
1821
|
+
...tree,
|
|
1091
1822
|
order,
|
|
1092
|
-
fields
|
|
1823
|
+
fields
|
|
1093
1824
|
};
|
|
1094
1825
|
}
|
|
1095
|
-
deleteField(
|
|
1096
|
-
const hasField =
|
|
1826
|
+
deleteField(tree, fieldId) {
|
|
1827
|
+
const hasField = tree.order.has(fieldId);
|
|
1097
1828
|
if (!hasField) {
|
|
1098
1829
|
throw new MutationError(`Field with ID (${fieldId}) not found`);
|
|
1099
1830
|
}
|
|
1100
|
-
const
|
|
1101
|
-
const order = new Set(
|
|
1831
|
+
const field = tree.fields.get(fieldId);
|
|
1832
|
+
const order = new Set(tree.order);
|
|
1102
1833
|
order.delete(fieldId);
|
|
1103
|
-
const
|
|
1104
|
-
|
|
1834
|
+
const fields = new Map(tree.fields);
|
|
1835
|
+
fields.delete(fieldId);
|
|
1105
1836
|
let updatedTree = {
|
|
1106
|
-
...
|
|
1837
|
+
...tree,
|
|
1107
1838
|
order,
|
|
1108
|
-
fields
|
|
1839
|
+
fields
|
|
1109
1840
|
};
|
|
1110
|
-
const hasContainer =
|
|
1841
|
+
const hasContainer = field?.containerId && updatedTree.containers.has(field.containerId);
|
|
1111
1842
|
if (hasContainer) {
|
|
1112
|
-
const
|
|
1113
|
-
const containerHasField =
|
|
1114
|
-
if (
|
|
1115
|
-
const containerOrder = new Set(
|
|
1843
|
+
const container = updatedTree.containers.get(field.containerId);
|
|
1844
|
+
const containerHasField = container?.order.has(fieldId);
|
|
1845
|
+
if (container && containerHasField) {
|
|
1846
|
+
const containerOrder = new Set(container.order);
|
|
1116
1847
|
containerOrder.delete(fieldId);
|
|
1117
1848
|
updatedTree = this.mutateContainer(updatedTree, {
|
|
1118
|
-
id:
|
|
1849
|
+
id: field.containerId,
|
|
1119
1850
|
keyValuePairs: {
|
|
1120
1851
|
order: containerOrder
|
|
1121
1852
|
},
|
|
@@ -1123,14 +1854,44 @@ class MutationsService {
|
|
|
1123
1854
|
});
|
|
1124
1855
|
}
|
|
1125
1856
|
}
|
|
1126
|
-
|
|
1857
|
+
const attachedCaptions = [];
|
|
1858
|
+
for (const [id, f] of updatedTree.fields) {
|
|
1859
|
+
if (f.type === "caption" && f.props.mediaId === fieldId) {
|
|
1860
|
+
attachedCaptions.push(id);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
for (const captionId of attachedCaptions) {
|
|
1864
|
+
updatedTree = this.deleteField(updatedTree, captionId);
|
|
1865
|
+
}
|
|
1866
|
+
return updatedTree;
|
|
1867
|
+
}
|
|
1868
|
+
changeField(tree, { fieldId, type }) {
|
|
1869
|
+
const hasField = tree.order.has(fieldId) && tree.fields.has(fieldId);
|
|
1870
|
+
if (!hasField) {
|
|
1871
|
+
throw new MutationError(`Field with ID (${fieldId}) not found`);
|
|
1872
|
+
}
|
|
1873
|
+
const _field = tree.fields.get(fieldId);
|
|
1874
|
+
const field = _field instanceof FieldClass ? _field : new FieldClass(_field);
|
|
1875
|
+
if (!(field instanceof FieldClass)) {
|
|
1876
|
+
throw new MutationPrototypeError(field.name);
|
|
1877
|
+
}
|
|
1878
|
+
if (!isEditableField(field) || field.type === type) {
|
|
1879
|
+
return tree;
|
|
1880
|
+
}
|
|
1881
|
+
const hasContent = !!field.props.children.text.length;
|
|
1882
|
+
if (hasContent) {
|
|
1883
|
+
return tree;
|
|
1884
|
+
}
|
|
1885
|
+
const order = new Set(tree.order);
|
|
1886
|
+
const pos = [...order].indexOf(fieldId);
|
|
1887
|
+
return this.insertField(this.deleteField(tree, fieldId), FieldsUtils.NewField(type, { id: field.id }), pos);
|
|
1127
1888
|
}
|
|
1128
|
-
mutateField(
|
|
1129
|
-
const hasFieldInOrder =
|
|
1889
|
+
mutateField(tree, { id, keyValuePairs, autoMerge }) {
|
|
1890
|
+
const hasFieldInOrder = tree.order.has(id);
|
|
1130
1891
|
if (!hasFieldInOrder) {
|
|
1131
1892
|
throw new MutationError(`Field ${id} doesn't exist on the tree`);
|
|
1132
1893
|
}
|
|
1133
|
-
const existingField =
|
|
1894
|
+
const existingField = tree.fields.get(id);
|
|
1134
1895
|
if (!existingField || !(existingField instanceof FieldClass)) {
|
|
1135
1896
|
throw new MutationPrototypeError(existingField?.name ?? id);
|
|
1136
1897
|
}
|
|
@@ -1141,12 +1902,12 @@ class MutationsService {
|
|
|
1141
1902
|
id
|
|
1142
1903
|
});
|
|
1143
1904
|
if (updatedField === currentField)
|
|
1144
|
-
return
|
|
1145
|
-
const
|
|
1146
|
-
|
|
1905
|
+
return tree;
|
|
1906
|
+
const fields = new Map(tree.fields);
|
|
1907
|
+
fields.set(id, new FieldClass(updatedField));
|
|
1147
1908
|
return {
|
|
1148
|
-
...
|
|
1149
|
-
fields
|
|
1909
|
+
...tree,
|
|
1910
|
+
fields
|
|
1150
1911
|
};
|
|
1151
1912
|
}
|
|
1152
1913
|
canMerge(autoMerge, value, current) {
|
|
@@ -1194,11 +1955,11 @@ class MutationsService {
|
|
|
1194
1955
|
}
|
|
1195
1956
|
return result;
|
|
1196
1957
|
}
|
|
1197
|
-
mutateContainer(
|
|
1198
|
-
if (!
|
|
1958
|
+
mutateContainer(tree, { keyValuePairs, id, autoMerge = true }) {
|
|
1959
|
+
if (!tree.order.has(id)) {
|
|
1199
1960
|
throw new MutationError(`Container ${id} doesn't exist on the tree`);
|
|
1200
1961
|
}
|
|
1201
|
-
const existingContainer =
|
|
1962
|
+
const existingContainer = tree.containers.get(id);
|
|
1202
1963
|
if (!existingContainer || !(existingContainer instanceof ContainerClass)) {
|
|
1203
1964
|
throw new MutationPrototypeError(existingContainer?.name ?? "ContainerNotFound");
|
|
1204
1965
|
}
|
|
@@ -1209,11 +1970,11 @@ class MutationsService {
|
|
|
1209
1970
|
id
|
|
1210
1971
|
});
|
|
1211
1972
|
if (currentContainer === updatedContainer)
|
|
1212
|
-
return
|
|
1213
|
-
const containers = new Map(
|
|
1973
|
+
return tree;
|
|
1974
|
+
const containers = new Map(tree.containers);
|
|
1214
1975
|
containers.set(id, new ContainerClass(updatedContainer));
|
|
1215
1976
|
return {
|
|
1216
|
-
...
|
|
1977
|
+
...tree,
|
|
1217
1978
|
containers
|
|
1218
1979
|
};
|
|
1219
1980
|
}
|
|
@@ -1432,91 +2193,6 @@ class TextMarksService {
|
|
|
1432
2193
|
}
|
|
1433
2194
|
}
|
|
1434
2195
|
|
|
1435
|
-
// src/services/ui/default-styles.ts
|
|
1436
|
-
var Text = {
|
|
1437
|
-
style: {
|
|
1438
|
-
width: "100%",
|
|
1439
|
-
color: "var(--text-foreground)",
|
|
1440
|
-
fontSize: "18px",
|
|
1441
|
-
minHeight: "32px",
|
|
1442
|
-
whiteSpace: "pre",
|
|
1443
|
-
fontWeight: 400,
|
|
1444
|
-
display: "block",
|
|
1445
|
-
alignItems: "center",
|
|
1446
|
-
outline: "none",
|
|
1447
|
-
border: "none",
|
|
1448
|
-
fieldSizing: "content",
|
|
1449
|
-
cursor: "default",
|
|
1450
|
-
paddingInline: 4,
|
|
1451
|
-
userSelect: "none"
|
|
1452
|
-
},
|
|
1453
|
-
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
1454
|
-
};
|
|
1455
|
-
var Heading = {
|
|
1456
|
-
style: {
|
|
1457
|
-
width: "100%",
|
|
1458
|
-
maxWidth: "100%",
|
|
1459
|
-
color: "var(--text-foreground)",
|
|
1460
|
-
fontSize: "40px",
|
|
1461
|
-
minHeight: "48px",
|
|
1462
|
-
fontWeight: 400,
|
|
1463
|
-
whiteSpace: "pre",
|
|
1464
|
-
display: "block",
|
|
1465
|
-
alignItems: "center",
|
|
1466
|
-
outline: "none",
|
|
1467
|
-
border: "none",
|
|
1468
|
-
fieldSizing: "content",
|
|
1469
|
-
cursor: "default",
|
|
1470
|
-
paddingInline: 4,
|
|
1471
|
-
userSelect: "none"
|
|
1472
|
-
},
|
|
1473
|
-
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
1474
|
-
};
|
|
1475
|
-
var Image = {
|
|
1476
|
-
style: {
|
|
1477
|
-
width: "100%",
|
|
1478
|
-
objectFit: "cover",
|
|
1479
|
-
display: "block",
|
|
1480
|
-
alignItems: "center",
|
|
1481
|
-
outline: "none",
|
|
1482
|
-
border: "none",
|
|
1483
|
-
fieldSizing: "content",
|
|
1484
|
-
cursor: "default",
|
|
1485
|
-
userSelect: "none"
|
|
1486
|
-
}
|
|
1487
|
-
};
|
|
1488
|
-
var Divider = {
|
|
1489
|
-
style: {
|
|
1490
|
-
width: "100%",
|
|
1491
|
-
borderTopWidth: 1,
|
|
1492
|
-
borderTopStyle: "solid",
|
|
1493
|
-
borderTopColor: "var(--color-muted-foreground)",
|
|
1494
|
-
marginBlock: 8,
|
|
1495
|
-
height: 1,
|
|
1496
|
-
position: "relative",
|
|
1497
|
-
overflow: "visible"
|
|
1498
|
-
},
|
|
1499
|
-
pseudoStyle: {
|
|
1500
|
-
":before": {
|
|
1501
|
-
content: '""',
|
|
1502
|
-
position: "absolute",
|
|
1503
|
-
top: "-8px",
|
|
1504
|
-
bottom: "-8px",
|
|
1505
|
-
height: 16,
|
|
1506
|
-
left: 0,
|
|
1507
|
-
right: 0,
|
|
1508
|
-
pointerEvents: "auto",
|
|
1509
|
-
zIndex: 5
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
};
|
|
1513
|
-
var STYLES = {
|
|
1514
|
-
text: Text,
|
|
1515
|
-
heading: Heading,
|
|
1516
|
-
image: Image,
|
|
1517
|
-
divider: Divider
|
|
1518
|
-
};
|
|
1519
|
-
|
|
1520
2196
|
// src/services/ui/ui.errors.ts
|
|
1521
2197
|
class UiError extends Error {
|
|
1522
2198
|
constructor(message) {
|
|
@@ -1528,11 +2204,9 @@ class UiError extends Error {
|
|
|
1528
2204
|
// src/services/ui/ui.ts
|
|
1529
2205
|
import { cn } from "cn";
|
|
1530
2206
|
|
|
1531
|
-
// src/services/ui/
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
}
|
|
1535
|
-
|
|
2207
|
+
// src/services/ui/contributions.types.ts
|
|
2208
|
+
var defineButton = (c) => c;
|
|
2209
|
+
var defineComponent = (c) => c;
|
|
1536
2210
|
// src/services/ui/ui.ts
|
|
1537
2211
|
class UiService {
|
|
1538
2212
|
commands;
|
|
@@ -1543,7 +2217,7 @@ class UiService {
|
|
|
1543
2217
|
interceptors = new Map;
|
|
1544
2218
|
constructor(commands) {
|
|
1545
2219
|
this.commands = commands;
|
|
1546
|
-
for (const [key, value] of UTILS.ObjectEntries(
|
|
2220
|
+
for (const [key, value] of UTILS.ObjectEntries(DEFAULT_STYLES)) {
|
|
1547
2221
|
this.styles.set(key, value);
|
|
1548
2222
|
}
|
|
1549
2223
|
}
|
|
@@ -1562,7 +2236,8 @@ class UiService {
|
|
|
1562
2236
|
}
|
|
1563
2237
|
this.commands.execute(c.command, payload);
|
|
1564
2238
|
}
|
|
1565
|
-
contribute(
|
|
2239
|
+
contribute(c) {
|
|
2240
|
+
const slotName = c.slot;
|
|
1566
2241
|
const prevContribution = this.bySlot.get(slotName) ?? [];
|
|
1567
2242
|
if (prevContribution.some((x) => x.id === c.id)) {
|
|
1568
2243
|
throw new UiError(`Contribution with id ${c.id} already exists`);
|
|
@@ -1594,7 +2269,7 @@ class UiService {
|
|
|
1594
2269
|
}
|
|
1595
2270
|
this.styles.set(styleName, style);
|
|
1596
2271
|
return () => {
|
|
1597
|
-
this.styles.set(styleName, this.outdatedStyles.get(styleName) ??
|
|
2272
|
+
this.styles.set(styleName, this.outdatedStyles.get(styleName) ?? DEFAULT_STYLES[styleName]);
|
|
1598
2273
|
this.outdatedStyles.delete(styleName);
|
|
1599
2274
|
};
|
|
1600
2275
|
}
|
|
@@ -1613,7 +2288,7 @@ class UiService {
|
|
|
1613
2288
|
className: cn(prevStyle.className, style.className)
|
|
1614
2289
|
});
|
|
1615
2290
|
return () => {
|
|
1616
|
-
this.styles.set(styleName, this.outdatedStyles.get(styleName) ??
|
|
2291
|
+
this.styles.set(styleName, this.outdatedStyles.get(styleName) ?? DEFAULT_STYLES[styleName]);
|
|
1617
2292
|
this.outdatedStyles.delete(styleName);
|
|
1618
2293
|
};
|
|
1619
2294
|
}
|
|
@@ -1819,15 +2494,24 @@ var InsertionModule = {
|
|
|
1819
2494
|
ctx.state.set("insertion", isOpen);
|
|
1820
2495
|
ctx.events.emit("actions:toggle", isOpen);
|
|
1821
2496
|
});
|
|
2497
|
+
ctx.commands.register("fields.change", ({ fieldId, type }) => {
|
|
2498
|
+
const block = ctx.document.getBlock(fieldId);
|
|
2499
|
+
if (block && block.type === "caption") {
|
|
2500
|
+
return;
|
|
2501
|
+
}
|
|
2502
|
+
ctx.document.apply((tree) => ctx.mutations.changeField(tree, { fieldId, type }), { origin: isMediaType(type) || type === "link" ? "history" : "user" });
|
|
2503
|
+
ctx.state.set("insertion", false);
|
|
2504
|
+
ctx.events.emit("fields:change", { fieldId, type });
|
|
2505
|
+
});
|
|
1822
2506
|
ctx.commands.register("blocks.insert", ({ block, pos }) => {
|
|
1823
2507
|
const isNotMedia = block.type !== "image" && block.type !== "video";
|
|
1824
2508
|
const hasSrcInProps = "src" in block.props && !!block.props.src.trim();
|
|
1825
2509
|
const shouldEmitEvent = isNotMedia || hasSrcInProps;
|
|
1826
|
-
ctx.document.apply((
|
|
2510
|
+
ctx.document.apply((tree) => {
|
|
1827
2511
|
if (block.variant === "field") {
|
|
1828
|
-
return ctx.mutations.insertField(
|
|
2512
|
+
return ctx.mutations.insertField(tree, block, pos);
|
|
1829
2513
|
}
|
|
1830
|
-
return
|
|
2514
|
+
return tree;
|
|
1831
2515
|
}, { shouldEmitEvent });
|
|
1832
2516
|
ctx.state.set("insertion", false);
|
|
1833
2517
|
ctx.events.emit("blocks:insert", { block, pos });
|
|
@@ -1836,35 +2520,47 @@ var InsertionModule = {
|
|
|
1836
2520
|
const isFieldBlock = blockId.startsWith("field:");
|
|
1837
2521
|
if (!isFieldBlock)
|
|
1838
2522
|
return;
|
|
1839
|
-
ctx.document.apply((
|
|
2523
|
+
ctx.document.apply((tree) => ctx.mutations.deleteField(tree, blockId));
|
|
1840
2524
|
ctx.events.emit("blocks:delete", { blockId });
|
|
1841
2525
|
});
|
|
1842
|
-
function actionButton(id,
|
|
1843
|
-
ctx.ui.contribute(
|
|
2526
|
+
function actionButton(id, type, icon, order) {
|
|
2527
|
+
ctx.ui.contribute(defineButton({
|
|
1844
2528
|
id,
|
|
1845
2529
|
order,
|
|
1846
2530
|
icon,
|
|
1847
2531
|
kind: "button",
|
|
1848
2532
|
slot: "block-actions",
|
|
1849
|
-
command: "
|
|
2533
|
+
command: "fields.change",
|
|
1850
2534
|
name: "BlockActionButton",
|
|
1851
2535
|
getProps() {
|
|
1852
|
-
return { variant: "
|
|
2536
|
+
return { variant: "secondary", size: "icon-sm" };
|
|
2537
|
+
},
|
|
2538
|
+
getPayload: () => {
|
|
2539
|
+
const focus = ctx.state.get("focus_memory")?.blocks?.[0];
|
|
2540
|
+
if (!focus) {
|
|
2541
|
+
throw new Error("Empty focus memory...");
|
|
2542
|
+
}
|
|
2543
|
+
return { fieldId: focus.id, type };
|
|
1853
2544
|
},
|
|
1854
|
-
getPayload: () => ({ block }),
|
|
1855
2545
|
when() {
|
|
1856
2546
|
return true;
|
|
1857
2547
|
}
|
|
1858
|
-
});
|
|
2548
|
+
}));
|
|
1859
2549
|
}
|
|
1860
|
-
ctx.ui.contribute(
|
|
2550
|
+
ctx.ui.contribute({
|
|
1861
2551
|
...ActionsOpenerContribution,
|
|
1862
2552
|
getPayload: () => !ctx.state.get("insertion")
|
|
1863
2553
|
});
|
|
1864
|
-
actionButton("insert-heading",
|
|
1865
|
-
actionButton("insert-
|
|
1866
|
-
actionButton("insert-
|
|
1867
|
-
actionButton("insert-
|
|
2554
|
+
actionButton("insert-heading", "heading", "HeadingIcon", 1);
|
|
2555
|
+
actionButton("insert-sub-heading", "sub-heading", "Heading2Icon", 2);
|
|
2556
|
+
actionButton("insert-text", "text", "TextIcon", 3);
|
|
2557
|
+
actionButton("insert-image", "image", "ImagePlus", 4);
|
|
2558
|
+
actionButton("insert-video", "video", "TvMinimalPlayIcon", 5);
|
|
2559
|
+
actionButton("insert-iframe", "iframe", "YoutubeIcon", 6);
|
|
2560
|
+
actionButton("insert-doc", "link", "FileTextIcon", 7);
|
|
2561
|
+
actionButton("insert-blockquote", "blockquote", "QuoteIcon", 8);
|
|
2562
|
+
actionButton("insert-code", "code", "CodeIcon", 9);
|
|
2563
|
+
actionButton("insert-divider", "divider", "DividerIcon", 10);
|
|
1868
2564
|
}
|
|
1869
2565
|
};
|
|
1870
2566
|
// src/modules/editor/editor.module.ts
|
|
@@ -1963,8 +2659,8 @@ function sameBlocks(a, b) {
|
|
|
1963
2659
|
}
|
|
1964
2660
|
return true;
|
|
1965
2661
|
}
|
|
1966
|
-
function selectionOverlayPropsFromUICtx(
|
|
1967
|
-
const rects = Array.from(
|
|
2662
|
+
function selectionOverlayPropsFromUICtx(ui4, editorRect, order) {
|
|
2663
|
+
const rects = Array.from(ui4?.selection?.blocks?.entries() ?? []).map(([id, rect]) => order.has(id) ? rect : null).filter(Boolean);
|
|
1968
2664
|
return overlayPositionFromBlockRects(rects, editorRect);
|
|
1969
2665
|
}
|
|
1970
2666
|
var SelectionModule = {
|
|
@@ -1973,22 +2669,22 @@ var SelectionModule = {
|
|
|
1973
2669
|
requires: [],
|
|
1974
2670
|
install(ctx) {
|
|
1975
2671
|
ctx.state.defineSlice("selection", { blocks: new Map });
|
|
1976
|
-
ctx.ui.contribute(
|
|
2672
|
+
ctx.ui.contribute(defineComponent({
|
|
1977
2673
|
id: "selection-overlay",
|
|
1978
2674
|
slot: "overlay",
|
|
1979
2675
|
order: 1000,
|
|
1980
2676
|
kind: "component",
|
|
1981
2677
|
name: "SelectionOverlay",
|
|
1982
|
-
when: (
|
|
1983
|
-
getProps: (
|
|
2678
|
+
when: (ui4) => ui4.selection.blocks.size > 0,
|
|
2679
|
+
getProps: (ui4) => {
|
|
1984
2680
|
const editorState = ctx.state.get("editor") ?? { editorRect: null };
|
|
1985
|
-
const position = selectionOverlayPropsFromUICtx(
|
|
2681
|
+
const position = selectionOverlayPropsFromUICtx(ui4, editorState?.editorRect, ctx.document.get().order);
|
|
1986
2682
|
return {
|
|
1987
2683
|
position,
|
|
1988
|
-
hidden: !Array.from(
|
|
2684
|
+
hidden: !Array.from(ui4.selection.blocks.keys()).length || !position
|
|
1989
2685
|
};
|
|
1990
2686
|
}
|
|
1991
|
-
});
|
|
2687
|
+
}));
|
|
1992
2688
|
const apply = (next) => {
|
|
1993
2689
|
const previous = ctx.state.get("selection").blocks;
|
|
1994
2690
|
if (sameBlocks(previous, next))
|
|
@@ -2010,9 +2706,9 @@ var SelectionModule = {
|
|
|
2010
2706
|
}
|
|
2011
2707
|
};
|
|
2012
2708
|
// src/modules/focus/focus.module.ts
|
|
2013
|
-
import
|
|
2014
|
-
function focusOverlayPropsFromUICtx(
|
|
2015
|
-
const rect =
|
|
2709
|
+
import _2 from "lodash";
|
|
2710
|
+
function focusOverlayPropsFromUICtx(ui4, editorRect) {
|
|
2711
|
+
const rect = ui4.focus?.rect;
|
|
2016
2712
|
if (!rect)
|
|
2017
2713
|
return null;
|
|
2018
2714
|
return overlayPositionFromBlockRects([rect], editorRect);
|
|
@@ -2024,36 +2720,29 @@ var FocusModule = {
|
|
|
2024
2720
|
install(ctx) {
|
|
2025
2721
|
ctx.state.defineSlice("focus", null);
|
|
2026
2722
|
ctx.state.defineSlice("focus_memory", { blocks: [], count: 3 });
|
|
2027
|
-
ctx.ui.contribute(
|
|
2723
|
+
ctx.ui.contribute(defineComponent({
|
|
2028
2724
|
id: "focus-overlay",
|
|
2029
2725
|
slot: "overlay",
|
|
2030
2726
|
order: 1001,
|
|
2031
2727
|
kind: "component",
|
|
2032
2728
|
name: "FocusOverlay",
|
|
2033
|
-
when: (
|
|
2034
|
-
getProps: (
|
|
2729
|
+
when: (ui4) => !!ui4.focus?.id,
|
|
2730
|
+
getProps: (ui4) => {
|
|
2035
2731
|
const editorState = ctx.state.get("editor") ?? { editorRect: null };
|
|
2036
|
-
const position = focusOverlayPropsFromUICtx(
|
|
2037
|
-
const
|
|
2732
|
+
const position = focusOverlayPropsFromUICtx(ui4, editorState?.editorRect);
|
|
2733
|
+
const document2 = ctx.state.get("document");
|
|
2038
2734
|
return {
|
|
2039
2735
|
position,
|
|
2040
|
-
hidden: !
|
|
2736
|
+
hidden: !ui4.focus?.id || !position || !document2?.order.has(ui4?.focus?.id)
|
|
2041
2737
|
};
|
|
2042
2738
|
}
|
|
2043
|
-
});
|
|
2739
|
+
}));
|
|
2044
2740
|
ctx.commands.register("blocks.focus", (payload) => {
|
|
2045
|
-
if (payload && !isEditableField(ctx.document.getBlock(payload.id))) {
|
|
2046
|
-
ctx.commands.execute("blocks.select", {
|
|
2047
|
-
blocks: new Map().set(payload.id, payload.rect),
|
|
2048
|
-
mode: "replace"
|
|
2049
|
-
});
|
|
2050
|
-
return;
|
|
2051
|
-
}
|
|
2052
2741
|
const { id: focusedId = null, rect = null } = payload ?? {};
|
|
2053
2742
|
const prev = ctx.state.get("focus");
|
|
2054
2743
|
if (focusedId !== null && !ctx.document.has(focusedId))
|
|
2055
2744
|
return;
|
|
2056
|
-
if (focusedId === prev?.id &&
|
|
2745
|
+
if (focusedId === prev?.id && _2.isEqual(rect, prev.rect))
|
|
2057
2746
|
return;
|
|
2058
2747
|
const prevFocusedId = prev?.id;
|
|
2059
2748
|
const shouldUnfocusPrev = Boolean(prevFocusedId && prevFocusedId !== focusedId && (() => {
|
|
@@ -2065,8 +2754,8 @@ var FocusModule = {
|
|
|
2065
2754
|
return b && isEditableField(b);
|
|
2066
2755
|
})());
|
|
2067
2756
|
if (shouldUnfocusPrev || shouldFocusCurrent) {
|
|
2068
|
-
ctx.document.apply((
|
|
2069
|
-
let nextTree =
|
|
2757
|
+
ctx.document.apply((tree) => {
|
|
2758
|
+
let nextTree = tree;
|
|
2070
2759
|
if (shouldUnfocusPrev && prevFocusedId) {
|
|
2071
2760
|
nextTree = ctx.mutations.mutateField(nextTree, {
|
|
2072
2761
|
keyValuePairs: {
|
|
@@ -2102,7 +2791,7 @@ var FocusModule = {
|
|
|
2102
2791
|
const { blocks: _memoBlocks, count } = ctx.state.get("focus_memory");
|
|
2103
2792
|
if (focusedId && rect) {
|
|
2104
2793
|
ctx.state.set("focus_memory", {
|
|
2105
|
-
blocks: [
|
|
2794
|
+
blocks: [{ id: focusedId, rect }, ...[..._memoBlocks].reverse()].slice(0, count),
|
|
2106
2795
|
count
|
|
2107
2796
|
});
|
|
2108
2797
|
}
|
|
@@ -2111,8 +2800,8 @@ var FocusModule = {
|
|
|
2111
2800
|
}
|
|
2112
2801
|
};
|
|
2113
2802
|
// src/modules/hover/hover.module.ts
|
|
2114
|
-
function hoverOverlayPropsFromUICtx(
|
|
2115
|
-
const rect =
|
|
2803
|
+
function hoverOverlayPropsFromUICtx(ui4, editorRect) {
|
|
2804
|
+
const rect = ui4.hover?.rect;
|
|
2116
2805
|
if (!rect)
|
|
2117
2806
|
return null;
|
|
2118
2807
|
return overlayPositionFromBlockRects([rect], editorRect);
|
|
@@ -2124,24 +2813,24 @@ var HoverModule = {
|
|
|
2124
2813
|
install(ctx) {
|
|
2125
2814
|
ctx.state.defineSlice("hover", null);
|
|
2126
2815
|
ctx.state.defineSlice("hover_memory", { blocks: [], count: 3 });
|
|
2127
|
-
ctx.ui.contribute(
|
|
2816
|
+
ctx.ui.contribute(defineComponent({
|
|
2128
2817
|
id: "hover-overlay",
|
|
2129
2818
|
slot: "overlay",
|
|
2130
2819
|
order: 999,
|
|
2131
2820
|
kind: "component",
|
|
2132
2821
|
name: "HoverOverlay",
|
|
2133
|
-
when: (
|
|
2134
|
-
getProps: (
|
|
2822
|
+
when: (ui4) => !!ui4.hover?.id,
|
|
2823
|
+
getProps: (ui4) => {
|
|
2135
2824
|
const editorState = ctx.state.get("editor") ?? { editorRect: null };
|
|
2136
2825
|
const selection = ctx.state.get("selection");
|
|
2137
|
-
const
|
|
2138
|
-
const position = hoverOverlayPropsFromUICtx(
|
|
2826
|
+
const document2 = ctx.state.get("document");
|
|
2827
|
+
const position = hoverOverlayPropsFromUICtx(ui4, editorState?.editorRect);
|
|
2139
2828
|
return {
|
|
2140
2829
|
position,
|
|
2141
|
-
hidden: !
|
|
2830
|
+
hidden: !ui4.hover?.id || !position || !!selection && selection.blocks.has(ui4.hover?.id) || !document2?.order.has(ui4.hover?.id)
|
|
2142
2831
|
};
|
|
2143
2832
|
}
|
|
2144
|
-
});
|
|
2833
|
+
}));
|
|
2145
2834
|
ctx.commands.register("blocks.hover", (payload) => {
|
|
2146
2835
|
if (!payload) {
|
|
2147
2836
|
ctx.state.set("hover", null);
|
|
@@ -2176,10 +2865,17 @@ var HistoryModule = {
|
|
|
2176
2865
|
let stack = [ctx.document.get()];
|
|
2177
2866
|
let cursor = 0;
|
|
2178
2867
|
ctx.state.defineSlice("history", { canUndo: false, canRedo: false });
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2868
|
+
ctx.state.defineSlice("history:stack", { size: 0, cursor: 0 });
|
|
2869
|
+
const sync = () => {
|
|
2870
|
+
ctx.state.set("history", {
|
|
2871
|
+
canUndo: cursor > 0,
|
|
2872
|
+
canRedo: cursor < stack.length - 1
|
|
2873
|
+
});
|
|
2874
|
+
ctx.state.set("history:stack", {
|
|
2875
|
+
size: stack.length,
|
|
2876
|
+
cursor
|
|
2877
|
+
});
|
|
2878
|
+
};
|
|
2183
2879
|
ctx.events.on("document:changed", ({ value }) => {
|
|
2184
2880
|
if (value.origin === "history")
|
|
2185
2881
|
return;
|
|
@@ -2193,11 +2889,20 @@ var HistoryModule = {
|
|
|
2193
2889
|
cursor = to;
|
|
2194
2890
|
ctx.document.apply(() => stack[cursor], { origin: "history" });
|
|
2195
2891
|
sync();
|
|
2196
|
-
if (
|
|
2892
|
+
if (ctx.state.get("focus"))
|
|
2197
2893
|
ctx.commands.tryExecute("blocks.focus", null);
|
|
2198
2894
|
};
|
|
2199
2895
|
ctx.commands.register("history.undo", () => go(cursor - 1));
|
|
2200
2896
|
ctx.commands.register("history.redo", () => go(cursor + 1));
|
|
2897
|
+
ctx.commands.register("history.move", ({ cursor: cursor2 }) => go(cursor2));
|
|
2898
|
+
ctx.commands.register("history.cleanup", () => {
|
|
2899
|
+
stack = [stack[cursor]];
|
|
2900
|
+
cursor = 0;
|
|
2901
|
+
ctx.state.set("history:stack", {
|
|
2902
|
+
size: 1,
|
|
2903
|
+
cursor: 0
|
|
2904
|
+
});
|
|
2905
|
+
});
|
|
2201
2906
|
}
|
|
2202
2907
|
};
|
|
2203
2908
|
// src/modules/text-editing/text-editing.constants.ts
|
|
@@ -2231,7 +2936,7 @@ var TextEditingModule = {
|
|
|
2231
2936
|
if (!sel)
|
|
2232
2937
|
return null;
|
|
2233
2938
|
const block = ctx.document.getBlock(sel.blockId);
|
|
2234
|
-
if (!block ||
|
|
2939
|
+
if (!block || !isEditableField(block))
|
|
2235
2940
|
return null;
|
|
2236
2941
|
const content = getIn(block, sel.path);
|
|
2237
2942
|
if (!isTextContent(content))
|
|
@@ -2239,13 +2944,13 @@ var TextEditingModule = {
|
|
|
2239
2944
|
return { sel, content };
|
|
2240
2945
|
};
|
|
2241
2946
|
const write = (sel, next) => {
|
|
2242
|
-
ctx.document.apply((
|
|
2947
|
+
ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
|
|
2243
2948
|
id: sel.blockId,
|
|
2244
2949
|
keyValuePairs: { [sel.path]: next },
|
|
2245
2950
|
autoMerge: false
|
|
2246
2951
|
}));
|
|
2247
2952
|
const curBlock = ctx.document.getBlock(sel.blockId);
|
|
2248
|
-
if (!curBlock || !
|
|
2953
|
+
if (!curBlock || !isEditableField(curBlock))
|
|
2249
2954
|
return;
|
|
2250
2955
|
ctx.state.set("currentMarks", currentMarks([...curBlock.props.children.marks], sel));
|
|
2251
2956
|
};
|
|
@@ -2267,7 +2972,7 @@ var TextEditingModule = {
|
|
|
2267
2972
|
if (samePlace)
|
|
2268
2973
|
return;
|
|
2269
2974
|
const curBlock = ctx.document.getBlock(next.blockId);
|
|
2270
|
-
if (!curBlock || !
|
|
2975
|
+
if (!curBlock || !isEditableField(curBlock))
|
|
2271
2976
|
return;
|
|
2272
2977
|
ctx.state.set("textSelection", { ...next, pendingMarks: null });
|
|
2273
2978
|
ctx.state.set("currentMarks", currentMarks([...curBlock.props.children.marks], next));
|
|
@@ -2335,16 +3040,24 @@ var TextEditingModule = {
|
|
|
2335
3040
|
chars = direction === "backward" ? chars.slice(0, sel.start) : chars.slice(sel.start);
|
|
2336
3041
|
const sideWhiteSpacePos = direction === "backward" && chars[chars.length - 1] === " " ? "end" : direction === "forward" && chars[0] === " " ? "start" : "none";
|
|
2337
3042
|
if (sideWhiteSpacePos === "start") {
|
|
2338
|
-
|
|
3043
|
+
const position = chars.findIndex((char) => char !== " ");
|
|
3044
|
+
chars = chars.slice(position);
|
|
2339
3045
|
} else if (sideWhiteSpacePos === "end") {
|
|
2340
|
-
|
|
3046
|
+
let count = 0;
|
|
3047
|
+
for (let i = chars.length - 1;i >= 0; i--) {
|
|
3048
|
+
if (chars[i] !== " ") {
|
|
3049
|
+
break;
|
|
3050
|
+
}
|
|
3051
|
+
count++;
|
|
3052
|
+
}
|
|
3053
|
+
chars = chars.slice(0, -count);
|
|
2341
3054
|
}
|
|
2342
3055
|
const firstWhiteSpaceIndex = chars.findIndex((char) => char === " ");
|
|
2343
3056
|
const lastWhiteSpaceIndex = chars.findLastIndex((char) => char === " ");
|
|
2344
|
-
if (direction === "backward"
|
|
2345
|
-
start = lastWhiteSpaceIndex + 1;
|
|
2346
|
-
} else if (direction === "forward"
|
|
2347
|
-
end = firstWhiteSpaceIndex + (content.text.length - chars.length);
|
|
3057
|
+
if (direction === "backward") {
|
|
3058
|
+
start = lastWhiteSpaceIndex !== -1 ? lastWhiteSpaceIndex + 1 : 0;
|
|
3059
|
+
} else if (direction === "forward") {
|
|
3060
|
+
end = firstWhiteSpaceIndex !== -1 ? firstWhiteSpaceIndex + (content.text.length - chars.length) : content.text.length;
|
|
2348
3061
|
}
|
|
2349
3062
|
}
|
|
2350
3063
|
}
|
|
@@ -2354,7 +3067,7 @@ var TextEditingModule = {
|
|
|
2354
3067
|
write(sel, next);
|
|
2355
3068
|
setCaret(sel, Math.max(0, start));
|
|
2356
3069
|
});
|
|
2357
|
-
const formatButton = (format, icon, order) => ctx.ui.contribute(
|
|
3070
|
+
const formatButton = (format, icon, order) => ctx.ui.contribute(defineButton({
|
|
2358
3071
|
id: `format-${format}`,
|
|
2359
3072
|
slot: "toolbar",
|
|
2360
3073
|
order,
|
|
@@ -2363,12 +3076,12 @@ var TextEditingModule = {
|
|
|
2363
3076
|
command: "text.format",
|
|
2364
3077
|
name: "ToolBarButton",
|
|
2365
3078
|
getPayload: () => ({ format, attrs: MARK_DEFAULT_ATTRS[format] ?? {} }),
|
|
2366
|
-
getProps(
|
|
2367
|
-
const focusedBlock =
|
|
3079
|
+
getProps(ui4) {
|
|
3080
|
+
const focusedBlock = ui4.focus;
|
|
2368
3081
|
if (!focusedBlock?.id)
|
|
2369
3082
|
return { isActive: false };
|
|
2370
3083
|
const block = ctx.document.getBlock(focusedBlock.id);
|
|
2371
|
-
if (!block || !
|
|
3084
|
+
if (!block || !isEditableField(block))
|
|
2372
3085
|
return { isActive: false };
|
|
2373
3086
|
const children = block.props.children;
|
|
2374
3087
|
const curSel = ctx.state.get("textSelection");
|
|
@@ -2381,48 +3094,475 @@ var TextEditingModule = {
|
|
|
2381
3094
|
isActive: correspondingMark.start === curSel.start && correspondingMark.end === curSel.end
|
|
2382
3095
|
};
|
|
2383
3096
|
},
|
|
2384
|
-
when: (
|
|
2385
|
-
if (!
|
|
3097
|
+
when: (ui4) => {
|
|
3098
|
+
if (!ui4.focus?.id)
|
|
2386
3099
|
return false;
|
|
2387
|
-
const block = ctx.document.getBlock(
|
|
3100
|
+
const block = ctx.document.getBlock(ui4.focus.id);
|
|
2388
3101
|
if (!block)
|
|
2389
3102
|
return false;
|
|
2390
3103
|
const sel = ctx.state.get("textSelection");
|
|
2391
|
-
return isEditableField(block) && !!sel && sel.start !== sel.end;
|
|
3104
|
+
return isEditableField(block) && !!sel && sel.start !== sel.end && block.type !== "code";
|
|
2392
3105
|
}
|
|
2393
|
-
});
|
|
3106
|
+
}));
|
|
2394
3107
|
formatButton("bold", "BoldIcon", 10);
|
|
2395
3108
|
formatButton("italic", "ItalicIcon", 20);
|
|
2396
3109
|
formatButton("link", "LinkIcon", 30);
|
|
2397
3110
|
formatButton("underline", "UnderlineIcon", 40);
|
|
2398
3111
|
}
|
|
2399
3112
|
};
|
|
2400
|
-
// src/modules/
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2407
|
-
|
|
3113
|
+
// src/modules/code/code.module.ts
|
|
3114
|
+
var CodeModule = {
|
|
3115
|
+
name: "code",
|
|
3116
|
+
version: "1.0.0",
|
|
3117
|
+
requires: [],
|
|
3118
|
+
install(ctx) {
|
|
3119
|
+
ctx.commands.register("code.toggleTheme", ({ fieldId }) => {
|
|
3120
|
+
const block = ctx.document.getBlock(fieldId);
|
|
3121
|
+
if (!block || block.type !== "code")
|
|
3122
|
+
return;
|
|
3123
|
+
const current = block.props.theme ?? "dark";
|
|
3124
|
+
const index = CODE_THEME_NAMES.indexOf(current);
|
|
3125
|
+
const next = CODE_THEME_NAMES[(index + 1) % CODE_THEME_NAMES.length];
|
|
3126
|
+
ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
|
|
3127
|
+
id: fieldId,
|
|
3128
|
+
keyValuePairs: { "props.theme": next }
|
|
3129
|
+
}));
|
|
3130
|
+
ctx.events.emit("code:toggleTheme", { fieldId });
|
|
3131
|
+
});
|
|
2408
3132
|
}
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
3133
|
+
};
|
|
3134
|
+
// src/modules/caption/caption.module.ts
|
|
3135
|
+
var hasCaptionFor = (tree, mediaId) => {
|
|
3136
|
+
const order = [...tree.order];
|
|
3137
|
+
const pos = order.indexOf(mediaId);
|
|
3138
|
+
if (pos === -1)
|
|
3139
|
+
return false;
|
|
3140
|
+
const next = tree.fields.get(order[pos + 1]);
|
|
3141
|
+
return next?.type === "caption" && next.props.mediaId === mediaId;
|
|
3142
|
+
};
|
|
3143
|
+
var CaptionModule = {
|
|
3144
|
+
name: "caption",
|
|
3145
|
+
version: "1.0.0",
|
|
3146
|
+
requires: [],
|
|
3147
|
+
install(ctx) {
|
|
3148
|
+
const addCaption = (mediaId) => {
|
|
3149
|
+
const media = ctx.document.getBlock(mediaId);
|
|
3150
|
+
if (!media || !isMediaField(media))
|
|
3151
|
+
return;
|
|
3152
|
+
if (hasCaptionFor(ctx.document.get(), mediaId))
|
|
3153
|
+
return;
|
|
3154
|
+
const pos = [...ctx.document.get().order].indexOf(mediaId);
|
|
3155
|
+
if (pos === -1)
|
|
3156
|
+
return;
|
|
3157
|
+
const caption = FieldsUtils.NewCaptionField();
|
|
3158
|
+
ctx.document.apply((tree) => {
|
|
3159
|
+
const newTree = ctx.mutations.insertField(tree, caption, pos + 1);
|
|
3160
|
+
return ctx.mutations.mutateField(newTree, {
|
|
3161
|
+
id: caption.id,
|
|
3162
|
+
keyValuePairs: {
|
|
3163
|
+
"props.mediaId": mediaId
|
|
3164
|
+
}
|
|
3165
|
+
});
|
|
3166
|
+
});
|
|
3167
|
+
ctx.events.emit("caption:add", { mediaId });
|
|
3168
|
+
};
|
|
3169
|
+
ctx.commands.register("caption.add", ({ mediaId }) => addCaption(mediaId));
|
|
3170
|
+
ctx.ui.contribute(defineButton({
|
|
3171
|
+
id: "insert-caption",
|
|
3172
|
+
slot: "toolbar",
|
|
3173
|
+
order: 100,
|
|
3174
|
+
kind: "button",
|
|
3175
|
+
icon: "CaptionsIcon",
|
|
3176
|
+
command: "caption.add",
|
|
3177
|
+
name: "CaptionButton",
|
|
3178
|
+
label: "Add caption",
|
|
3179
|
+
getPayload: (ui4) => {
|
|
3180
|
+
const mediaId = [...ui4.selection?.blocks?.keys() ?? []][0];
|
|
3181
|
+
if (!mediaId)
|
|
3182
|
+
throw new Error("Empty selection...");
|
|
3183
|
+
return { mediaId };
|
|
3184
|
+
},
|
|
3185
|
+
getProps: () => ({}),
|
|
3186
|
+
when: (ui4) => {
|
|
3187
|
+
const blocks = ui4.selection?.blocks;
|
|
3188
|
+
if (!blocks || blocks.size !== 1)
|
|
3189
|
+
return false;
|
|
3190
|
+
const mediaId = [...blocks.keys()][0];
|
|
3191
|
+
const media = ctx.document.getBlock(mediaId);
|
|
3192
|
+
if (!media || !isMediaField(media))
|
|
3193
|
+
return false;
|
|
3194
|
+
const doc = ctx.document.get();
|
|
3195
|
+
const mediaIdx = [...doc.order].indexOf(mediaId);
|
|
3196
|
+
const caption = ctx.document.getBlock([...doc.order][mediaIdx + 1]);
|
|
3197
|
+
if (caption && caption.props.mediaId === media.id)
|
|
3198
|
+
return false;
|
|
3199
|
+
return true;
|
|
3200
|
+
}
|
|
3201
|
+
}));
|
|
3202
|
+
}
|
|
3203
|
+
};
|
|
3204
|
+
// src/modules/media/media.module.ts
|
|
3205
|
+
var IMAGE_WIDTHS = {
|
|
3206
|
+
sm: "calc(100% + 100px)",
|
|
3207
|
+
lg: "calc(100% + 300px)"
|
|
3208
|
+
};
|
|
3209
|
+
var selectedId = (ui4) => {
|
|
3210
|
+
const blocks = ui4.selection?.blocks;
|
|
3211
|
+
if (!blocks || blocks.size !== 1)
|
|
3212
|
+
return null;
|
|
3213
|
+
return [...blocks.keys()][0];
|
|
3214
|
+
};
|
|
3215
|
+
var isYouTubeIframe = (block) => {
|
|
3216
|
+
const field = block;
|
|
3217
|
+
if (!field || field.type !== "iframe")
|
|
3218
|
+
return false;
|
|
3219
|
+
return !!field.props?.src && !!getIframeSrc(field.props.src)?.startsWith("https://www.youtube.com/embed/");
|
|
3220
|
+
};
|
|
3221
|
+
var MediaModule = {
|
|
3222
|
+
name: "media",
|
|
3223
|
+
version: "1.0.0",
|
|
3224
|
+
requires: [],
|
|
3225
|
+
install(ctx) {
|
|
3226
|
+
ctx.commands.register("iframe.playback", ({ fieldId, action }) => {
|
|
3227
|
+
const block = ctx.document.getBlock(fieldId);
|
|
3228
|
+
if (!block || block.type !== "iframe")
|
|
3229
|
+
return;
|
|
3230
|
+
const iframe = document.getElementById(fieldId);
|
|
3231
|
+
iframe?.contentWindow?.postMessage(JSON.stringify({
|
|
3232
|
+
event: "command",
|
|
3233
|
+
func: action === "play" ? "playVideo" : "pauseVideo",
|
|
3234
|
+
args: []
|
|
3235
|
+
}), "*");
|
|
3236
|
+
ctx.events.emit("iframe:playback", { fieldId, action });
|
|
2416
3237
|
});
|
|
3238
|
+
ctx.commands.register("image.setWidth", ({ fieldId, width }) => {
|
|
3239
|
+
const block = ctx.document.getBlock(fieldId);
|
|
3240
|
+
if (!block || block.type !== "image")
|
|
3241
|
+
return;
|
|
3242
|
+
const next = block.props.style?.width === width ? "100%" : width;
|
|
3243
|
+
ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
|
|
3244
|
+
id: fieldId,
|
|
3245
|
+
keyValuePairs: { "props.style": { width: next, maxWidth: "none" } }
|
|
3246
|
+
}));
|
|
3247
|
+
ctx.events.emit("image:setWidth", { fieldId, width: next });
|
|
3248
|
+
});
|
|
3249
|
+
ctx.ui.contribute(defineButton({
|
|
3250
|
+
id: "iframe-playback",
|
|
3251
|
+
slot: "toolbar",
|
|
3252
|
+
order: 70,
|
|
3253
|
+
kind: "button",
|
|
3254
|
+
icon: "PlayIcon",
|
|
3255
|
+
command: "iframe.playback",
|
|
3256
|
+
name: "IframePlaybackButton",
|
|
3257
|
+
label: "Play/Pause",
|
|
3258
|
+
getPayload: (ui4) => {
|
|
3259
|
+
const fieldId = selectedId(ui4);
|
|
3260
|
+
if (!fieldId)
|
|
3261
|
+
throw new Error("Empty selection...");
|
|
3262
|
+
return { fieldId, action: "play" };
|
|
3263
|
+
},
|
|
3264
|
+
getProps: () => ({}),
|
|
3265
|
+
when: (ui4) => {
|
|
3266
|
+
const fieldId = selectedId(ui4);
|
|
3267
|
+
if (!fieldId)
|
|
3268
|
+
return false;
|
|
3269
|
+
return isYouTubeIframe(ctx.document.getBlock(fieldId));
|
|
3270
|
+
}
|
|
3271
|
+
}));
|
|
3272
|
+
const widthButton = (id, icon, order, width) => ctx.ui.contribute(defineButton({
|
|
3273
|
+
id,
|
|
3274
|
+
slot: "toolbar",
|
|
3275
|
+
order,
|
|
3276
|
+
kind: "button",
|
|
3277
|
+
icon,
|
|
3278
|
+
command: "image.setWidth",
|
|
3279
|
+
name: "ImageWidthButton",
|
|
3280
|
+
label: `Width ${width}`,
|
|
3281
|
+
getPayload: (ui4) => {
|
|
3282
|
+
const fieldId = selectedId(ui4);
|
|
3283
|
+
if (!fieldId)
|
|
3284
|
+
throw new Error("Empty selection...");
|
|
3285
|
+
return { fieldId, width };
|
|
3286
|
+
},
|
|
3287
|
+
getProps: (ui4) => {
|
|
3288
|
+
const fieldId = selectedId(ui4);
|
|
3289
|
+
const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
|
|
3290
|
+
return { isActive: block?.props.style?.width === width };
|
|
3291
|
+
},
|
|
3292
|
+
when: (ui4) => {
|
|
3293
|
+
const fieldId = selectedId(ui4);
|
|
3294
|
+
if (!fieldId)
|
|
3295
|
+
return false;
|
|
3296
|
+
return ctx.document.getBlock(fieldId)?.type === "image";
|
|
3297
|
+
}
|
|
3298
|
+
}));
|
|
3299
|
+
widthButton("image-width-sm", "MoveHorizontalIcon", 80, IMAGE_WIDTHS.sm);
|
|
3300
|
+
widthButton("image-width-lg", "ExpandIcon", 81, IMAGE_WIDTHS.lg);
|
|
2417
3301
|
}
|
|
2418
|
-
|
|
2419
|
-
|
|
3302
|
+
};
|
|
3303
|
+
// src/modules/divider/divider.module.ts
|
|
3304
|
+
var DIVIDER_STYLES = ["solid", "dashed", "dotted"];
|
|
3305
|
+
var DIVIDER_WIDTHS = {
|
|
3306
|
+
sm: "calc(100% - 100px)",
|
|
3307
|
+
lg: "calc(100% - 300px)"
|
|
3308
|
+
};
|
|
3309
|
+
var selectedId2 = (ui4) => {
|
|
3310
|
+
const blocks = ui4.selection?.blocks;
|
|
3311
|
+
if (!blocks || blocks.size !== 1)
|
|
3312
|
+
return null;
|
|
3313
|
+
return [...blocks.keys()][0];
|
|
3314
|
+
};
|
|
3315
|
+
var DividerModule = {
|
|
3316
|
+
name: "divider",
|
|
3317
|
+
version: "1.0.0",
|
|
3318
|
+
requires: [],
|
|
3319
|
+
install(ctx) {
|
|
3320
|
+
ctx.commands.register("divider.setWidth", ({ fieldId, width }) => {
|
|
3321
|
+
const block = ctx.document.getBlock(fieldId);
|
|
3322
|
+
if (!block || block.type !== "divider")
|
|
3323
|
+
return;
|
|
3324
|
+
const next = block.props.style?.width === width ? "100%" : width;
|
|
3325
|
+
ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
|
|
3326
|
+
id: fieldId,
|
|
3327
|
+
keyValuePairs: { "props.style": { width: next } }
|
|
3328
|
+
}));
|
|
3329
|
+
ctx.events.emit("divider:setWidth", { fieldId, width: next });
|
|
3330
|
+
});
|
|
3331
|
+
ctx.commands.register("divider.setStyle", ({ fieldId, style }) => {
|
|
3332
|
+
const block = ctx.document.getBlock(fieldId);
|
|
3333
|
+
if (!block || block.type !== "divider")
|
|
3334
|
+
return;
|
|
3335
|
+
ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
|
|
3336
|
+
id: fieldId,
|
|
3337
|
+
keyValuePairs: { "props.style": { borderTopStyle: style } }
|
|
3338
|
+
}));
|
|
3339
|
+
ctx.events.emit("divider:setStyle", { fieldId, style });
|
|
3340
|
+
});
|
|
3341
|
+
const widthButton = (id, icon, order, width) => ctx.ui.contribute(defineButton({
|
|
3342
|
+
id,
|
|
3343
|
+
slot: "toolbar",
|
|
3344
|
+
order,
|
|
3345
|
+
kind: "button",
|
|
3346
|
+
icon,
|
|
3347
|
+
command: "divider.setWidth",
|
|
3348
|
+
name: "DividerWidthButton",
|
|
3349
|
+
label: `Width ${width}`,
|
|
3350
|
+
getPayload: (ui4) => {
|
|
3351
|
+
const fieldId = selectedId2(ui4);
|
|
3352
|
+
if (!fieldId)
|
|
3353
|
+
throw new Error("Empty selection...");
|
|
3354
|
+
return { fieldId, width };
|
|
3355
|
+
},
|
|
3356
|
+
getProps: (ui4) => {
|
|
3357
|
+
const fieldId = selectedId2(ui4);
|
|
3358
|
+
const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
|
|
3359
|
+
return { isActive: block?.props.style?.width === width };
|
|
3360
|
+
},
|
|
3361
|
+
when: (ui4) => {
|
|
3362
|
+
const fieldId = selectedId2(ui4);
|
|
3363
|
+
if (!fieldId)
|
|
3364
|
+
return false;
|
|
3365
|
+
return ctx.document.getBlock(fieldId)?.type === "divider";
|
|
3366
|
+
}
|
|
3367
|
+
}));
|
|
3368
|
+
widthButton("divider-width-sm", "MoveHorizontalIcon", 90, DIVIDER_WIDTHS.sm);
|
|
3369
|
+
widthButton("divider-width-lg", "ExpandIcon", 91, DIVIDER_WIDTHS.lg);
|
|
3370
|
+
const styleButton = (id, order, borderStyle) => ctx.ui.contribute(defineButton({
|
|
3371
|
+
id,
|
|
3372
|
+
slot: "toolbar",
|
|
3373
|
+
order,
|
|
3374
|
+
kind: "button",
|
|
3375
|
+
icon: "LineStyleIcon",
|
|
3376
|
+
command: "divider.setStyle",
|
|
3377
|
+
name: "DividerStyleButton",
|
|
3378
|
+
label: `Style ${borderStyle}`,
|
|
3379
|
+
getPayload: (ui4) => {
|
|
3380
|
+
const fieldId = selectedId2(ui4);
|
|
3381
|
+
if (!fieldId)
|
|
3382
|
+
throw new Error("Empty selection...");
|
|
3383
|
+
return { fieldId, style: borderStyle };
|
|
3384
|
+
},
|
|
3385
|
+
getProps: (ui4) => {
|
|
3386
|
+
const fieldId = selectedId2(ui4);
|
|
3387
|
+
const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
|
|
3388
|
+
const current = block?.props.style?.borderTopStyle ?? "solid";
|
|
3389
|
+
return { isActive: current === borderStyle, borderStyle };
|
|
3390
|
+
},
|
|
3391
|
+
when: (ui4) => {
|
|
3392
|
+
const fieldId = selectedId2(ui4);
|
|
3393
|
+
if (!fieldId)
|
|
3394
|
+
return false;
|
|
3395
|
+
return ctx.document.getBlock(fieldId)?.type === "divider";
|
|
3396
|
+
}
|
|
3397
|
+
}));
|
|
3398
|
+
DIVIDER_STYLES.forEach((borderStyle, index) => {
|
|
3399
|
+
styleButton(`divider-style-${borderStyle}`, 92 + index, borderStyle);
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
};
|
|
3403
|
+
// src/modules/paragraph-theme/paragraph-theme.module.ts
|
|
3404
|
+
var PARAGRAPH_THEMES = [
|
|
3405
|
+
"neutral",
|
|
3406
|
+
"warning",
|
|
3407
|
+
"error",
|
|
3408
|
+
"info"
|
|
3409
|
+
];
|
|
3410
|
+
var THEME_ICONS = {
|
|
3411
|
+
neutral: "ThemeNeutralIcon",
|
|
3412
|
+
warning: "ThemeWarningIcon",
|
|
3413
|
+
error: "ThemeErrorIcon",
|
|
3414
|
+
info: "ThemeInfoIcon"
|
|
3415
|
+
};
|
|
3416
|
+
var PARAGRAPH_THEME_STYLES = {
|
|
3417
|
+
neutral: { backgroundColor: "var(--card)", color: "var(--muted-foreground)" },
|
|
3418
|
+
warning: { backgroundColor: "rgba(245, 158, 11, 0.05)", color: "rgb(180, 83, 9)" },
|
|
3419
|
+
error: { backgroundColor: "rgba(244, 63, 94, 0.05)", color: "rgb(190, 18, 60)" },
|
|
3420
|
+
info: { backgroundColor: "rgba(59, 130, 246, 0.05)", color: "rgb(29, 78, 216)" }
|
|
3421
|
+
};
|
|
3422
|
+
var getParagraphTheme = (content) => {
|
|
3423
|
+
const len = content.text.length;
|
|
3424
|
+
const mark = content.marks.find((m) => m.type === "theme" && m.start === 0 && m.end === len);
|
|
3425
|
+
if (!mark)
|
|
3426
|
+
return null;
|
|
3427
|
+
return mark.attrs?.["data-theme"] ?? null;
|
|
3428
|
+
};
|
|
3429
|
+
var ParagraphThemeModule = {
|
|
3430
|
+
name: "paragraph-theme",
|
|
3431
|
+
version: "1.0.0",
|
|
3432
|
+
requires: [],
|
|
3433
|
+
install(ctx) {
|
|
3434
|
+
ctx.text.registerMark("theme", { inclusive: true });
|
|
3435
|
+
const selectedId3 = (ui4) => {
|
|
3436
|
+
const blocks = ui4.selection?.blocks;
|
|
3437
|
+
if (!blocks || blocks.size !== 1)
|
|
3438
|
+
return null;
|
|
3439
|
+
const id = [...blocks.keys()][0];
|
|
3440
|
+
const type = ctx.document.getBlock(id)?.type;
|
|
3441
|
+
return type === "text" || type === "sub-heading" ? id : null;
|
|
3442
|
+
};
|
|
3443
|
+
ctx.commands.register("paragraph.setTheme", ({ fieldId, theme }) => {
|
|
3444
|
+
const block = ctx.document.getBlock(fieldId);
|
|
3445
|
+
if (!block || block.type !== "text" && block.type !== "sub-heading")
|
|
3446
|
+
return;
|
|
3447
|
+
const content = block.props.children;
|
|
3448
|
+
const len = content.text.length;
|
|
3449
|
+
if (len === 0)
|
|
3450
|
+
return;
|
|
3451
|
+
const isToggleOff = getParagraphTheme(content) === theme;
|
|
3452
|
+
const others = content.marks.filter((m) => m.type !== "theme");
|
|
3453
|
+
const marks = isToggleOff ? others : [
|
|
3454
|
+
...others,
|
|
3455
|
+
{
|
|
3456
|
+
type: "theme",
|
|
3457
|
+
start: 0,
|
|
3458
|
+
end: len,
|
|
3459
|
+
attrs: {
|
|
3460
|
+
"data-theme": theme,
|
|
3461
|
+
style: {
|
|
3462
|
+
...PARAGRAPH_THEME_STYLES[theme],
|
|
3463
|
+
height: "100%",
|
|
3464
|
+
display: "block",
|
|
3465
|
+
borderRadius: 12,
|
|
3466
|
+
paddingInline: 16,
|
|
3467
|
+
paddingBlock: 12,
|
|
3468
|
+
whiteSpace: "pre-wrap",
|
|
3469
|
+
lineHeight: 1.5
|
|
3470
|
+
}
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
];
|
|
3474
|
+
ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
|
|
3475
|
+
id: fieldId,
|
|
3476
|
+
keyValuePairs: { ["props.children"]: { text: content.text, marks } },
|
|
3477
|
+
autoMerge: false
|
|
3478
|
+
}));
|
|
3479
|
+
ctx.events.emit("paragraph:setTheme", { fieldId, theme });
|
|
3480
|
+
});
|
|
3481
|
+
const themeButton = (id, order, theme) => ctx.ui.contribute(defineButton({
|
|
3482
|
+
id,
|
|
3483
|
+
slot: "toolbar",
|
|
3484
|
+
order,
|
|
3485
|
+
kind: "button",
|
|
3486
|
+
icon: THEME_ICONS[theme],
|
|
3487
|
+
command: "paragraph.setTheme",
|
|
3488
|
+
name: "ParagraphThemeButton",
|
|
3489
|
+
label: `Theme ${theme}`,
|
|
3490
|
+
getPayload: (ui4) => {
|
|
3491
|
+
const fieldId = selectedId3(ui4);
|
|
3492
|
+
if (!fieldId)
|
|
3493
|
+
throw new Error("Empty selection...");
|
|
3494
|
+
return { fieldId, theme };
|
|
3495
|
+
},
|
|
3496
|
+
getProps: (ui4) => {
|
|
3497
|
+
const fieldId = selectedId3(ui4);
|
|
3498
|
+
const block = fieldId ? ctx.document.getBlock(fieldId) : undefined;
|
|
3499
|
+
const isActive = !!block && getParagraphTheme(block.props.children) === theme;
|
|
3500
|
+
return { isActive, theme };
|
|
3501
|
+
},
|
|
3502
|
+
when: (ui4) => selectedId3(ui4) !== null
|
|
3503
|
+
}));
|
|
3504
|
+
PARAGRAPH_THEMES.forEach((theme, index) => {
|
|
3505
|
+
themeButton(`paragraph-theme-${theme}`, 60 + index, theme);
|
|
3506
|
+
});
|
|
3507
|
+
}
|
|
3508
|
+
};
|
|
3509
|
+
// src/modules/deletion/deletion.module.ts
|
|
3510
|
+
var DeletionModule = {
|
|
3511
|
+
name: "deletion",
|
|
3512
|
+
version: "1.0.0",
|
|
3513
|
+
requires: [],
|
|
3514
|
+
install(ctx) {
|
|
3515
|
+
ctx.commands.register("blocks.deleteSelection", () => {
|
|
3516
|
+
const blocks = ctx.state.get("selection")?.blocks ?? new Map;
|
|
3517
|
+
const ids = [...blocks.keys()].filter((id) => id.startsWith("field:"));
|
|
3518
|
+
if (!ids.length)
|
|
3519
|
+
return;
|
|
3520
|
+
ctx.document.apply((tree) => {
|
|
3521
|
+
let next = tree;
|
|
3522
|
+
for (const id of ids) {
|
|
3523
|
+
if (next.fields.has(id))
|
|
3524
|
+
next = ctx.mutations.deleteField(next, id);
|
|
3525
|
+
}
|
|
3526
|
+
return next;
|
|
3527
|
+
});
|
|
3528
|
+
ctx.commands.execute("blocks.clearSelection", undefined);
|
|
3529
|
+
});
|
|
3530
|
+
ctx.ui.contribute(defineButton({
|
|
3531
|
+
id: "delete-blocks",
|
|
3532
|
+
slot: "toolbar",
|
|
3533
|
+
order: 200,
|
|
3534
|
+
kind: "button",
|
|
3535
|
+
icon: "TrashIcon",
|
|
3536
|
+
command: "blocks.deleteSelection",
|
|
3537
|
+
name: "DeleteButton",
|
|
3538
|
+
label: "Delete",
|
|
3539
|
+
getPayload: () => {
|
|
3540
|
+
return;
|
|
3541
|
+
},
|
|
3542
|
+
getProps: () => ({}),
|
|
3543
|
+
when: (ui4) => (ui4.selection?.blocks?.size ?? 0) > 0
|
|
3544
|
+
}));
|
|
3545
|
+
}
|
|
3546
|
+
};
|
|
2420
3547
|
export {
|
|
3548
|
+
tokenizeCode,
|
|
3549
|
+
setCoraxStyleSink,
|
|
2421
3550
|
segments,
|
|
2422
3551
|
overlayPositionFromBlockRects,
|
|
3552
|
+
isMediaType,
|
|
3553
|
+
isMediaField,
|
|
3554
|
+
isEditableType,
|
|
2423
3555
|
isEditableField,
|
|
2424
|
-
|
|
3556
|
+
getParagraphTheme,
|
|
3557
|
+
getIframeSrc,
|
|
3558
|
+
getCollectedStyles,
|
|
3559
|
+
defineComponent,
|
|
3560
|
+
defineButton,
|
|
2425
3561
|
coraxTreeDiffing,
|
|
3562
|
+
hash as coraxStyleHash,
|
|
3563
|
+
compareDocumentVersion,
|
|
3564
|
+
collectCoraxPseudoStyle,
|
|
3565
|
+
clearCollectedStyles,
|
|
2426
3566
|
areObjectsTheSame,
|
|
2427
3567
|
UiService,
|
|
2428
3568
|
UiError,
|
|
@@ -2438,12 +3578,14 @@ export {
|
|
|
2438
3578
|
StateError,
|
|
2439
3579
|
SerializeTree,
|
|
2440
3580
|
SelectionModule,
|
|
2441
|
-
|
|
3581
|
+
ParagraphThemeModule,
|
|
3582
|
+
PARAGRAPH_THEME_STYLES,
|
|
2442
3583
|
MutationsService,
|
|
2443
3584
|
MutationPrototypeError,
|
|
2444
3585
|
MutationError,
|
|
2445
3586
|
ModuleUtils,
|
|
2446
3587
|
ModuleManager,
|
|
3588
|
+
MediaModule,
|
|
2447
3589
|
InsertionModule,
|
|
2448
3590
|
HoverModule,
|
|
2449
3591
|
HistoryModule,
|
|
@@ -2455,12 +3597,20 @@ export {
|
|
|
2455
3597
|
Engine,
|
|
2456
3598
|
EditorModule,
|
|
2457
3599
|
DocumentService,
|
|
3600
|
+
DividerModule,
|
|
2458
3601
|
DeserializeTree,
|
|
3602
|
+
DeletionModule,
|
|
3603
|
+
DEFAULT_STYLES,
|
|
3604
|
+
DEFAULT_IMAGE_PREVIEW,
|
|
2459
3605
|
CustomObject,
|
|
2460
3606
|
ContainersUtils,
|
|
2461
3607
|
ContainerClass,
|
|
2462
3608
|
ComponentsUtils,
|
|
2463
3609
|
ComponentClass,
|
|
2464
3610
|
CommandsBusService,
|
|
2465
|
-
|
|
3611
|
+
CodeModule,
|
|
3612
|
+
CmdNotFoundError,
|
|
3613
|
+
CaptionModule,
|
|
3614
|
+
CODE_THEME_NAMES,
|
|
3615
|
+
CODE_THEMES
|
|
2466
3616
|
};
|