@coorax/core 0.0.0-canary.0 → 0.0.0-canary.2
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/classes/component.class.d.ts +23 -0
- package/dist/base/classes/container.class.d.ts +17 -0
- package/dist/base/classes/field.class.d.ts +15 -0
- package/dist/base/classes/tnode.class.d.ts +14 -0
- package/{src/base/index.ts → dist/base/index.d.ts} +0 -4
- package/dist/base/types/components/components.d.ts +13 -0
- package/dist/base/types/container/container.d.ts +27 -0
- package/dist/base/types/container/division.types.d.ts +3 -0
- package/{src/base/types/container/section.types.ts → dist/base/types/container/section.types.d.ts} +2 -2
- package/{src/base/types/container/ul-list.types.ts → dist/base/types/container/ul-list.types.d.ts} +2 -2
- package/dist/base/types/css.types.d.ts +23 -0
- package/dist/base/types/field/divider.types.d.ts +3 -0
- package/dist/base/types/field/field.blockquote.types.d.ts +4 -0
- package/dist/base/types/field/field.d.ts +50 -0
- package/dist/base/types/field/field.image.types.d.ts +3 -0
- package/{src/base/types/field/field.media.types.ts → dist/base/types/field/field.media.types.d.ts} +2 -3
- package/{src/base/types/field/field.text.types.ts → dist/base/types/field/field.text.types.d.ts} +4 -5
- 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/{src/base/types/field/heading.types.ts → dist/base/types/field/heading.types.d.ts} +2 -2
- package/{src/base/types/field/paragraph.types.ts → dist/base/types/field/paragraph.types.d.ts} +2 -2
- package/dist/base/types/global.types.d.ts +26 -0
- package/{src/base/types/node/span.types.ts → dist/base/types/node/link.types.d.ts} +2 -2
- package/{src/base/types/node/node.ts → dist/base/types/node/node.d.ts} +13 -17
- package/{src/base/types/node/link.types.ts → dist/base/types/node/span.types.d.ts} +2 -2
- package/dist/base/types/tree/tree.d.ts +24 -0
- package/dist/constants/field.constants.d.ts +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/{src/engine/engine.ts → dist/engine/engine.d.ts} +20 -24
- package/dist/engine/engine.test.d.ts +1 -0
- package/{src/index.ts → dist/index.d.ts} +1 -2
- package/dist/index.js +3252 -0
- 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/editor/editor.module.d.ts +44 -0
- package/dist/modules/focus/focus.module.d.ts +54 -0
- package/dist/modules/history/history.module.d.ts +41 -0
- package/dist/modules/hover/hover.module.d.ts +53 -0
- package/{src/modules/index.ts → dist/modules/index.d.ts} +3 -1
- package/dist/modules/insertion/insertion.module.d.ts +71 -0
- package/dist/modules/modules-manager.d.ts +43 -0
- package/{src/modules/modules.types.ts → dist/modules/modules.types.d.ts} +25 -30
- package/dist/modules/selection/selection.module.d.ts +60 -0
- package/dist/modules/selection/selection.test.d.ts +1 -0
- package/dist/modules/text-editing/text-editing.constants.d.ts +2 -0
- package/dist/modules/text-editing/text-editing.module.d.ts +82 -0
- package/dist/modules/text-editing/text-editing.utils.d.ts +6 -0
- package/dist/services/commandsbus/commandsbus.d.ts +53 -0
- package/dist/services/commandsbus/commandsbus.test.d.ts +17 -0
- package/dist/services/document/document.d.ts +44 -0
- package/dist/services/eventbus/eventbus.d.ts +86 -0
- package/dist/services/eventbus/eventbus.test.d.ts +8 -0
- package/dist/services/eventbus/subscriber.d.ts +18 -0
- package/dist/services/mutations/mutations.d.ts +43 -0
- package/dist/services/mutations/mutations.errors.d.ts +6 -0
- package/dist/services/mutations/mutations.test.d.ts +1 -0
- package/dist/services/shortcuts/shortcuts.d.ts +4 -0
- package/dist/services/state/state.d.ts +20 -0
- package/dist/services/state/state.errors.d.ts +6 -0
- package/dist/services/tasks/tasks.service.d.ts +106 -0
- package/dist/services/tasks/tasks.service.test.d.ts +7 -0
- package/dist/services/text-marks/index.d.ts +1 -0
- package/{src/services/text-marks/marks.types.ts → dist/services/text-marks/marks.types.d.ts} +20 -23
- package/dist/services/text-marks/text-marks.d.ts +45 -0
- package/dist/services/ui/contributions.types.d.ts +79 -0
- package/dist/services/ui/default-styles.d.ts +3 -0
- package/{src/services/ui/index.ts → dist/services/ui/index.d.ts} +0 -1
- package/dist/services/ui/ui.d.ts +23 -0
- package/dist/services/ui/ui.errors.d.ts +3 -0
- package/dist/services/ui/ui.types.d.ts +25 -0
- package/dist/styles.css +2 -0
- package/dist/utils/components.utils.d.ts +10 -0
- package/dist/utils/container.utils.d.ts +13 -0
- package/dist/utils/fields.utils.d.ts +27 -0
- package/dist/utils/global.utils.d.ts +47 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/modules.utils.d.ts +11 -0
- package/dist/utils/tnode.utils.d.ts +9 -0
- package/dist/utils/tree.utils.d.ts +11 -0
- package/package.json +23 -6
- package/styles.css +4 -4
- package/src/base/classes/component.class.ts +0 -68
- package/src/base/classes/container.class.ts +0 -57
- package/src/base/classes/field.class.ts +0 -42
- package/src/base/classes/tnode.class.ts +0 -38
- package/src/base/types/components/components.ts +0 -21
- package/src/base/types/container/container.ts +0 -37
- package/src/base/types/container/division.types.ts +0 -3
- package/src/base/types/css.types.ts +0 -33
- package/src/base/types/field/divider.types.ts +0 -3
- package/src/base/types/field/field.ts +0 -46
- package/src/base/types/global.types.ts +0 -45
- package/src/base/types/tree/tree.ts +0 -33
- package/src/engine/engine.test.ts +0 -27
- package/src/modules/editor/editor.module.ts +0 -119
- package/src/modules/focus/focus.module.ts +0 -185
- package/src/modules/history/history.module.ts +0 -60
- package/src/modules/hover/hover.module.ts +0 -121
- package/src/modules/insertion/insertion.module.ts +0 -140
- package/src/modules/modules-manager.ts +0 -132
- package/src/modules/selection/selection.module.ts +0 -174
- package/src/modules/selection/selection.test.ts +0 -1
- package/src/modules/text-editing/text-editing.constants.ts +0 -6
- package/src/modules/text-editing/text-editing.module.ts +0 -377
- package/src/modules/text-editing/text-editing.utils.ts +0 -27
- package/src/services/commandsbus/commandsbus.test.ts +0 -312
- package/src/services/commandsbus/commandsbus.ts +0 -360
- package/src/services/document/document.ts +0 -139
- package/src/services/eventbus/eventbus.test.ts +0 -144
- package/src/services/eventbus/eventbus.ts +0 -162
- package/src/services/eventbus/subscriber.ts +0 -46
- package/src/services/mutations/mutations.errors.ts +0 -12
- package/src/services/mutations/mutations.test.ts +0 -177
- package/src/services/mutations/mutations.ts +0 -457
- package/src/services/shortcuts/shortcuts.ts +0 -3
- package/src/services/state/state.errors.ts +0 -12
- package/src/services/state/state.ts +0 -64
- package/src/services/tasks/tasks.service.test.ts +0 -193
- package/src/services/tasks/tasks.service.ts +0 -288
- package/src/services/text-marks/index.ts +0 -2
- package/src/services/text-marks/text-marks.ts +0 -244
- package/src/services/ui/default-styles.ts +0 -93
- package/src/services/ui/ui.errors.ts +0 -6
- package/src/services/ui/ui.ts +0 -148
- package/src/services/ui/ui.types.ts +0 -197
- package/src/utils/components.utils.ts +0 -26
- package/src/utils/container.utils.ts +0 -59
- package/src/utils/fields.utils.ts +0 -118
- package/src/utils/global.utils.ts +0 -128
- package/src/utils/index.ts +0 -7
- package/src/utils/modules.utils.ts +0 -110
- package/src/utils/tnode.utils.ts +0 -48
- package/src/utils/tree.utils.ts +0 -120
- package/tsconfig.json +0 -9
- /package/{src/engine/index.ts → dist/engine/index.d.ts} +0 -0
- /package/{src/services/commandsbus/index.ts → dist/services/commandsbus/index.d.ts} +0 -0
- /package/{src/services/document/index.ts → dist/services/document/index.d.ts} +0 -0
- /package/{src/services/eventbus/index.ts → dist/services/eventbus/index.d.ts} +0 -0
- /package/{src/services/mutations/index.ts → dist/services/mutations/index.d.ts} +0 -0
- /package/{src/services/state/index.ts → dist/services/state/index.d.ts} +0 -0
- /package/{src/services/tasks/index.ts → dist/services/tasks/index.d.ts} +0 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3252 @@
|
|
|
1
|
+
// ../schema/dist/index.js
|
|
2
|
+
import _ from "lodash";
|
|
3
|
+
|
|
4
|
+
class ComponentClass {
|
|
5
|
+
id;
|
|
6
|
+
name;
|
|
7
|
+
tag;
|
|
8
|
+
type;
|
|
9
|
+
props;
|
|
10
|
+
variant = "component";
|
|
11
|
+
order;
|
|
12
|
+
instanceId;
|
|
13
|
+
count;
|
|
14
|
+
updatedAt;
|
|
15
|
+
createdAt;
|
|
16
|
+
constructor(component) {
|
|
17
|
+
this.id = component.id;
|
|
18
|
+
this.name = component.name;
|
|
19
|
+
this.tag = component.tag;
|
|
20
|
+
this.type = component.type;
|
|
21
|
+
this.variant = component.variant;
|
|
22
|
+
this.order = component.order;
|
|
23
|
+
this.props = component.props;
|
|
24
|
+
this.count = component.count;
|
|
25
|
+
this.updatedAt = component.updatedAt;
|
|
26
|
+
this.createdAt = component.createdAt;
|
|
27
|
+
this.instanceId = component.instanceId;
|
|
28
|
+
}
|
|
29
|
+
isInstance() {
|
|
30
|
+
return !!this.instanceId;
|
|
31
|
+
}
|
|
32
|
+
getChildren(_tree) {
|
|
33
|
+
return new Set;
|
|
34
|
+
}
|
|
35
|
+
appendChild(tree) {
|
|
36
|
+
return tree;
|
|
37
|
+
}
|
|
38
|
+
removeChild(tree) {
|
|
39
|
+
return tree;
|
|
40
|
+
}
|
|
41
|
+
getCurrentComponentObject() {
|
|
42
|
+
return {
|
|
43
|
+
id: this.id,
|
|
44
|
+
name: this.name,
|
|
45
|
+
tag: this.tag,
|
|
46
|
+
type: this.type,
|
|
47
|
+
variant: this.variant,
|
|
48
|
+
order: this.order,
|
|
49
|
+
props: this.props,
|
|
50
|
+
count: this.count,
|
|
51
|
+
instanceId: this.instanceId,
|
|
52
|
+
createdAt: this.createdAt,
|
|
53
|
+
updatedAt: this.updatedAt
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
class ContainerClass {
|
|
59
|
+
id;
|
|
60
|
+
name;
|
|
61
|
+
tag;
|
|
62
|
+
type;
|
|
63
|
+
props;
|
|
64
|
+
variant = "container";
|
|
65
|
+
order;
|
|
66
|
+
constructor(container) {
|
|
67
|
+
this.id = container.id;
|
|
68
|
+
this.name = container.name;
|
|
69
|
+
this.tag = container.tag;
|
|
70
|
+
this.type = container.type;
|
|
71
|
+
this.variant = container.variant;
|
|
72
|
+
this.order = container.order;
|
|
73
|
+
this.props = container.props;
|
|
74
|
+
}
|
|
75
|
+
getChildren(_tree) {
|
|
76
|
+
return new Set;
|
|
77
|
+
}
|
|
78
|
+
appendChild(tree) {
|
|
79
|
+
return tree;
|
|
80
|
+
}
|
|
81
|
+
removeChild(tree) {
|
|
82
|
+
return tree;
|
|
83
|
+
}
|
|
84
|
+
getCurrentContainerObject() {
|
|
85
|
+
return {
|
|
86
|
+
id: this.id,
|
|
87
|
+
name: this.name,
|
|
88
|
+
tag: this.tag,
|
|
89
|
+
type: this.type,
|
|
90
|
+
variant: this.variant,
|
|
91
|
+
order: this.order,
|
|
92
|
+
props: this.props
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
class FieldClass {
|
|
98
|
+
id;
|
|
99
|
+
name;
|
|
100
|
+
tag;
|
|
101
|
+
type;
|
|
102
|
+
variant = "field";
|
|
103
|
+
containerId;
|
|
104
|
+
props;
|
|
105
|
+
constructor(field) {
|
|
106
|
+
this.id = field.id;
|
|
107
|
+
this.name = field.name;
|
|
108
|
+
this.tag = field.tag;
|
|
109
|
+
this.containerId = field.containerId;
|
|
110
|
+
this.props = field.props;
|
|
111
|
+
this.variant = field.variant;
|
|
112
|
+
this.type = field.type;
|
|
113
|
+
}
|
|
114
|
+
isContainerized() {
|
|
115
|
+
return !!this.containerId;
|
|
116
|
+
}
|
|
117
|
+
getCurrentFieldObject() {
|
|
118
|
+
return {
|
|
119
|
+
id: this.id,
|
|
120
|
+
name: this.name,
|
|
121
|
+
tag: this.tag,
|
|
122
|
+
containerId: this.containerId,
|
|
123
|
+
props: this.props,
|
|
124
|
+
variant: this.variant,
|
|
125
|
+
type: this.type
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
class TNodeClass {
|
|
131
|
+
id;
|
|
132
|
+
tag;
|
|
133
|
+
type;
|
|
134
|
+
name;
|
|
135
|
+
variant;
|
|
136
|
+
fieldId;
|
|
137
|
+
props;
|
|
138
|
+
constructor(tnode) {
|
|
139
|
+
this.id = tnode.id;
|
|
140
|
+
this.name = tnode.name;
|
|
141
|
+
this.variant = tnode.variant;
|
|
142
|
+
this.tag = tnode.tag;
|
|
143
|
+
this.props = tnode.props;
|
|
144
|
+
this.type = tnode.type;
|
|
145
|
+
this.fieldId = tnode.fieldId;
|
|
146
|
+
}
|
|
147
|
+
getCurrentNodeObject() {
|
|
148
|
+
return {
|
|
149
|
+
id: this.id,
|
|
150
|
+
name: this.name,
|
|
151
|
+
variant: this.variant,
|
|
152
|
+
tag: this.tag,
|
|
153
|
+
type: this.type,
|
|
154
|
+
props: this.props,
|
|
155
|
+
fieldId: this.fieldId
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
var DEFAULT_IMAGE_PREVIEW = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEBLAEsAAD/4QBWRXhpZgAATU0AKgAAAAgABAEaAAUAAAABAAAAPgEbAAUAAAABAAAARgEoAAMAAAABAAIAAAITAAMAAAABAAEAAAAAAAAAAAEsAAAAAQAAASwAAAAB/+0ALFBob3Rvc2hvcCAzLjAAOEJJTQQEAAAAAAAPHAFaAAMbJUccAQAAAgAEAP/hDW9odHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvADw/eHBhY2tldCBiZWdpbj0n77u/JyBpZD0nVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkJz8+Cjx4OnhtcG1ldGEgeG1sbnM6eD0nYWRvYmU6bnM6bWV0YS8nIHg6eG1wdGs9J0ltYWdlOjpFeGlmVG9vbCAxMi40MCc+CjxyZGY6UkRGIHhtbG5zOnJkZj0naHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyc+CgogPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9JycKICB4bWxuczp0aWZmPSdodHRwOi8vbnMuYWRvYmUuY29tL3RpZmYvMS4wLyc+CiAgPHRpZmY6UmVzb2x1dGlvblVuaXQ+MjwvdGlmZjpSZXNvbHV0aW9uVW5pdD4KICA8dGlmZjpYUmVzb2x1dGlvbj4zMDAvMTwvdGlmZjpYUmVzb2x1dGlvbj4KICA8dGlmZjpZUmVzb2x1dGlvbj4zMDAvMTwvdGlmZjpZUmVzb2x1dGlvbj4KIDwvcmRmOkRlc2NyaXB0aW9uPgoKIDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PScnCiAgeG1sbnM6eG1wPSdodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvJz4KICA8eG1wOkNyZWF0b3JUb29sPkFkb2JlIFN0b2NrIFBsYXRmb3JtPC94bXA6Q3JlYXRvclRvb2w+CiA8L3JkZjpEZXNjcmlwdGlvbj4KCiA8cmRmOkRlc2NyaXB0aW9uIHJkZjphYm91dD0nJwogIHhtbG5zOnhtcE1NPSdodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvbW0vJz4KICA8eG1wTU06RG9jdW1lbnRJRD54bXAuaWlkOmUzMWNkNzdmLTgzMjgtNDdhYS04NWI0LTRlMDBkZGUwYzI4YjwveG1wTU06RG9jdW1lbnRJRD4KICA8eG1wTU06SW5zdGFuY2VJRD5hZG9iZTpkb2NpZDpzdG9jazo2M2Y2NTBiOC0zMjM3LTQyODktYTgwZS1lMzdjNDlhOWI2MjA8L3htcE1NOkluc3RhbmNlSUQ+CiAgPHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD5hZG9iZTpkb2NpZDpzdG9jazoxNjc5NDQyMTk2PC94bXBNTTpPcmlnaW5hbERvY3VtZW50SUQ+CiA8L3JkZjpEZXNjcmlwdGlvbj4KPC9yZGY6UkRGPgo8L3g6eG1wbWV0YT4KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAKPD94cGFja2V0IGVuZD0ndyc/Pv/bAEMA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";
|
|
160
|
+
function generateRandomId() {
|
|
161
|
+
return `${Date.now().toString(12)}:${crypto.randomUUID()}`;
|
|
162
|
+
}
|
|
163
|
+
function generateId(prefix) {
|
|
164
|
+
return `${prefix}:${crypto.randomUUID()}`;
|
|
165
|
+
}
|
|
166
|
+
function generateFieldId() {
|
|
167
|
+
return generateId("field");
|
|
168
|
+
}
|
|
169
|
+
function generateTNodeId() {
|
|
170
|
+
return generateId("tnode");
|
|
171
|
+
}
|
|
172
|
+
function generateContainerId() {
|
|
173
|
+
return generateId("container");
|
|
174
|
+
}
|
|
175
|
+
function generateComponentId() {
|
|
176
|
+
return generateId("component");
|
|
177
|
+
}
|
|
178
|
+
function generateTreeId() {
|
|
179
|
+
return generateId("tree");
|
|
180
|
+
}
|
|
181
|
+
function generateSubscriberId() {
|
|
182
|
+
return generateId("subscriber");
|
|
183
|
+
}
|
|
184
|
+
function Capitalize(value) {
|
|
185
|
+
return `${value[0].toUpperCase()}${value.slice(1)}`;
|
|
186
|
+
}
|
|
187
|
+
function ObjectEntries(obj) {
|
|
188
|
+
return Object.entries(obj);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
class CustomObject {
|
|
192
|
+
obj;
|
|
193
|
+
constructor(obj) {
|
|
194
|
+
this.obj = obj;
|
|
195
|
+
}
|
|
196
|
+
filter(predicate) {
|
|
197
|
+
const entries = Object.entries(this.obj);
|
|
198
|
+
const filtered = entries.filter(([key, value]) => predicate(value, key));
|
|
199
|
+
return new CustomObject(Object.fromEntries(filtered));
|
|
200
|
+
}
|
|
201
|
+
pick(...keys) {
|
|
202
|
+
const picked = keys.reduce((acc, key) => {
|
|
203
|
+
acc[key] = this.obj[key];
|
|
204
|
+
return acc;
|
|
205
|
+
}, {});
|
|
206
|
+
return new CustomObject(picked);
|
|
207
|
+
}
|
|
208
|
+
get size() {
|
|
209
|
+
return Object.keys(this.obj).length;
|
|
210
|
+
}
|
|
211
|
+
has(key) {
|
|
212
|
+
return key in this.obj;
|
|
213
|
+
}
|
|
214
|
+
get keys() {
|
|
215
|
+
return Object.keys(this.obj);
|
|
216
|
+
}
|
|
217
|
+
get(key) {
|
|
218
|
+
return this.obj[key];
|
|
219
|
+
}
|
|
220
|
+
baseObject() {
|
|
221
|
+
return this.obj;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
var isPlainObject = (v) => {
|
|
225
|
+
if (typeof v !== "object" || v === null)
|
|
226
|
+
return false;
|
|
227
|
+
const proto = Object.getPrototypeOf(v);
|
|
228
|
+
return proto === Object.prototype || proto === null;
|
|
229
|
+
};
|
|
230
|
+
function areObjectsTheSame(objA, objB) {
|
|
231
|
+
return _.isEqual(objA, objB);
|
|
232
|
+
}
|
|
233
|
+
var UTILS = {
|
|
234
|
+
generateRandomId,
|
|
235
|
+
generateId,
|
|
236
|
+
generateContainerId,
|
|
237
|
+
generateFieldId,
|
|
238
|
+
generateTreeId,
|
|
239
|
+
generateSubscriberId,
|
|
240
|
+
generateComponentId,
|
|
241
|
+
Capitalize,
|
|
242
|
+
generateTNodeId,
|
|
243
|
+
ObjectEntries,
|
|
244
|
+
isPlainObject
|
|
245
|
+
};
|
|
246
|
+
function NewComponent(container3, defaultValue) {
|
|
247
|
+
const now = Date.now();
|
|
248
|
+
return new ComponentClass({
|
|
249
|
+
...container3,
|
|
250
|
+
id: UTILS.generateComponentId(),
|
|
251
|
+
variant: "component",
|
|
252
|
+
count: defaultValue?.count ?? 0,
|
|
253
|
+
createdAt: defaultValue?.createdAt ?? now,
|
|
254
|
+
updatedAt: defaultValue?.updatedAt ?? now
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function DeserializeComponent(component2) {
|
|
258
|
+
return new ComponentClass(component2);
|
|
259
|
+
}
|
|
260
|
+
var ComponentsUtils = { NewComponent, DeserializeComponent };
|
|
261
|
+
function NewUlListContainer(defaultValue) {
|
|
262
|
+
return new ContainerClass({
|
|
263
|
+
id: UTILS.generateContainerId(),
|
|
264
|
+
name: "Ul list container",
|
|
265
|
+
type: "list",
|
|
266
|
+
tag: "ul",
|
|
267
|
+
variant: "container",
|
|
268
|
+
props: {},
|
|
269
|
+
order: new Set,
|
|
270
|
+
...defaultValue
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function NewSectionContainer(defaultValue) {
|
|
274
|
+
return new ContainerClass({
|
|
275
|
+
id: UTILS.generateContainerId(),
|
|
276
|
+
name: "Section container",
|
|
277
|
+
type: "section",
|
|
278
|
+
tag: "section",
|
|
279
|
+
variant: "container",
|
|
280
|
+
props: {},
|
|
281
|
+
order: new Set,
|
|
282
|
+
...defaultValue
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
function NewContainer(type, defaultValue) {
|
|
286
|
+
switch (type) {
|
|
287
|
+
case "section":
|
|
288
|
+
return NewSectionContainer(defaultValue);
|
|
289
|
+
default:
|
|
290
|
+
return NewUlListContainer(defaultValue);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function DeserializeContainer(container3) {
|
|
294
|
+
return new ContainerClass(container3);
|
|
295
|
+
}
|
|
296
|
+
var ContainersUtils = {
|
|
297
|
+
NewContainer,
|
|
298
|
+
DeserializeContainer,
|
|
299
|
+
NewUlListContainer,
|
|
300
|
+
NewSectionContainer
|
|
301
|
+
};
|
|
302
|
+
var Text = {
|
|
303
|
+
style: {
|
|
304
|
+
width: "100%",
|
|
305
|
+
color: "var(--foreground)",
|
|
306
|
+
fontSize: "18px",
|
|
307
|
+
minHeight: "32px",
|
|
308
|
+
whiteSpace: "pre-wrap",
|
|
309
|
+
fontWeight: 400,
|
|
310
|
+
lineHeight: 2,
|
|
311
|
+
display: "block",
|
|
312
|
+
alignItems: "center",
|
|
313
|
+
outline: "none",
|
|
314
|
+
border: "none",
|
|
315
|
+
fieldSizing: "content",
|
|
316
|
+
cursor: "default",
|
|
317
|
+
paddingInline: 4,
|
|
318
|
+
userSelect: "none"
|
|
319
|
+
},
|
|
320
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
321
|
+
};
|
|
322
|
+
var Heading = {
|
|
323
|
+
style: {
|
|
324
|
+
width: "100%",
|
|
325
|
+
maxWidth: "100%",
|
|
326
|
+
color: "var(--foreground)",
|
|
327
|
+
fontSize: "40px",
|
|
328
|
+
minHeight: "48px",
|
|
329
|
+
fontWeight: 400,
|
|
330
|
+
whiteSpace: "pre-wrap",
|
|
331
|
+
display: "block",
|
|
332
|
+
alignItems: "center",
|
|
333
|
+
outline: "none",
|
|
334
|
+
border: "none",
|
|
335
|
+
fieldSizing: "content",
|
|
336
|
+
cursor: "default",
|
|
337
|
+
paddingInline: 4,
|
|
338
|
+
userSelect: "none"
|
|
339
|
+
},
|
|
340
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
341
|
+
};
|
|
342
|
+
var Image = {
|
|
343
|
+
style: {
|
|
344
|
+
width: "100%",
|
|
345
|
+
objectFit: "cover",
|
|
346
|
+
display: "block",
|
|
347
|
+
alignItems: "center",
|
|
348
|
+
outline: "none",
|
|
349
|
+
border: "none",
|
|
350
|
+
fieldSizing: "content",
|
|
351
|
+
cursor: "default",
|
|
352
|
+
userSelect: "none"
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
var Video = {
|
|
356
|
+
style: {
|
|
357
|
+
width: "100%",
|
|
358
|
+
objectFit: "cover",
|
|
359
|
+
display: "block",
|
|
360
|
+
alignItems: "center",
|
|
361
|
+
outline: "none",
|
|
362
|
+
border: "none",
|
|
363
|
+
fieldSizing: "content",
|
|
364
|
+
cursor: "default",
|
|
365
|
+
userSelect: "none"
|
|
366
|
+
}
|
|
367
|
+
};
|
|
368
|
+
var IFrame = {
|
|
369
|
+
style: {
|
|
370
|
+
width: "100%",
|
|
371
|
+
aspectRatio: "5/3",
|
|
372
|
+
objectFit: "cover",
|
|
373
|
+
display: "block",
|
|
374
|
+
alignItems: "center",
|
|
375
|
+
outline: "none",
|
|
376
|
+
border: "none",
|
|
377
|
+
fieldSizing: "content",
|
|
378
|
+
cursor: "default",
|
|
379
|
+
userSelect: "none"
|
|
380
|
+
}
|
|
381
|
+
};
|
|
382
|
+
var Link = {
|
|
383
|
+
style: {
|
|
384
|
+
width: "100%",
|
|
385
|
+
color: "var(--primary)",
|
|
386
|
+
fontSize: "18px",
|
|
387
|
+
minHeight: "32px",
|
|
388
|
+
whiteSpace: "pre-wrap",
|
|
389
|
+
fontWeight: 400,
|
|
390
|
+
display: "inline-flex",
|
|
391
|
+
lineHeight: 2,
|
|
392
|
+
alignItems: "center",
|
|
393
|
+
outline: "none",
|
|
394
|
+
border: "none",
|
|
395
|
+
fieldSizing: "content",
|
|
396
|
+
cursor: "default",
|
|
397
|
+
paddingInline: 4,
|
|
398
|
+
userSelect: "none"
|
|
399
|
+
},
|
|
400
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
401
|
+
};
|
|
402
|
+
var Blockquote = {
|
|
403
|
+
style: {
|
|
404
|
+
width: "100%",
|
|
405
|
+
maxWidth: "100%",
|
|
406
|
+
color: "var(--muted-foreground)",
|
|
407
|
+
fontSize: "18px",
|
|
408
|
+
minHeight: "32px",
|
|
409
|
+
fontWeight: 400,
|
|
410
|
+
whiteSpace: "pre-wrap",
|
|
411
|
+
fontStyle: "italic",
|
|
412
|
+
display: "block",
|
|
413
|
+
alignItems: "center",
|
|
414
|
+
outline: "none",
|
|
415
|
+
border: "none",
|
|
416
|
+
fieldSizing: "content",
|
|
417
|
+
cursor: "default",
|
|
418
|
+
paddingInline: 4,
|
|
419
|
+
userSelect: "none"
|
|
420
|
+
},
|
|
421
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
422
|
+
};
|
|
423
|
+
var Divider = {
|
|
424
|
+
style: {
|
|
425
|
+
width: "100%",
|
|
426
|
+
borderTopWidth: 1,
|
|
427
|
+
borderTopStyle: "solid",
|
|
428
|
+
borderTopColor: "var(--color-muted-foreground)",
|
|
429
|
+
marginBlock: 8,
|
|
430
|
+
outline: "none",
|
|
431
|
+
height: 1,
|
|
432
|
+
position: "relative",
|
|
433
|
+
overflow: "visible"
|
|
434
|
+
},
|
|
435
|
+
pseudoStyle: {
|
|
436
|
+
":before": {
|
|
437
|
+
content: '""',
|
|
438
|
+
position: "absolute",
|
|
439
|
+
top: "-8px",
|
|
440
|
+
bottom: "-8px",
|
|
441
|
+
height: 16,
|
|
442
|
+
left: 0,
|
|
443
|
+
right: 0,
|
|
444
|
+
pointerEvents: "auto",
|
|
445
|
+
zIndex: 5
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
var Code = {
|
|
450
|
+
style: {
|
|
451
|
+
width: "100%",
|
|
452
|
+
maxWidth: "100%",
|
|
453
|
+
color: "var(--foreground)",
|
|
454
|
+
fontSize: "14px",
|
|
455
|
+
fontFamily: "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace",
|
|
456
|
+
minHeight: "40px",
|
|
457
|
+
fontWeight: 400,
|
|
458
|
+
lineHeight: 1.7,
|
|
459
|
+
whiteSpace: "pre-wrap",
|
|
460
|
+
display: "block",
|
|
461
|
+
outline: "none",
|
|
462
|
+
border: "1px solid var(--border)",
|
|
463
|
+
fieldSizing: "content",
|
|
464
|
+
cursor: "default",
|
|
465
|
+
padding: 12,
|
|
466
|
+
userSelect: "none"
|
|
467
|
+
},
|
|
468
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none bg-foreground dark:bg-transparent"
|
|
469
|
+
};
|
|
470
|
+
var Caption = {
|
|
471
|
+
style: {
|
|
472
|
+
width: "100%",
|
|
473
|
+
maxWidth: "100%",
|
|
474
|
+
color: "var(--muted-foreground)",
|
|
475
|
+
fontSize: "14px",
|
|
476
|
+
minHeight: "24px",
|
|
477
|
+
fontWeight: 400,
|
|
478
|
+
lineHeight: 1.5,
|
|
479
|
+
whiteSpace: "pre-wrap",
|
|
480
|
+
display: "block",
|
|
481
|
+
textAlign: "center",
|
|
482
|
+
outline: "none",
|
|
483
|
+
border: "none",
|
|
484
|
+
fieldSizing: "content",
|
|
485
|
+
cursor: "default",
|
|
486
|
+
paddingInline: 4,
|
|
487
|
+
paddingBottom: 4,
|
|
488
|
+
userSelect: "none"
|
|
489
|
+
},
|
|
490
|
+
className: "[&:empty:before]:content-[attr(data-placeholder)] [&:empty:before]:text-muted-foreground [&:empty:before]:pointer-events-none"
|
|
491
|
+
};
|
|
492
|
+
var DEFAULT_STYLES = {
|
|
493
|
+
text: Text,
|
|
494
|
+
heading: Heading,
|
|
495
|
+
image: Image,
|
|
496
|
+
divider: Divider,
|
|
497
|
+
video: Video,
|
|
498
|
+
iframe: IFrame,
|
|
499
|
+
blockquote: Blockquote,
|
|
500
|
+
link: Link,
|
|
501
|
+
code: Code,
|
|
502
|
+
caption: Caption
|
|
503
|
+
};
|
|
504
|
+
function isEditableField(block) {
|
|
505
|
+
return block.variant === "field" && isEditableType(block.type);
|
|
506
|
+
}
|
|
507
|
+
function isEditableType(type) {
|
|
508
|
+
return type === "heading" || type === "text" || type === "blockquote" || type === "link" || type === "code" || type === "caption";
|
|
509
|
+
}
|
|
510
|
+
function isMediaField(block) {
|
|
511
|
+
return block.variant === "field" && isMediaType(block.type);
|
|
512
|
+
}
|
|
513
|
+
function isMediaType(type) {
|
|
514
|
+
return type === "image" || type === "video" || type === "iframe";
|
|
515
|
+
}
|
|
516
|
+
function getIframeSrc(value) {
|
|
517
|
+
const input = value.trim();
|
|
518
|
+
const normalizedInput = input.startsWith("//") ? `https:${input}` : /^[a-z][\w+.-]*:\/\//i.test(input) ? input : `https://${input}`;
|
|
519
|
+
let url;
|
|
520
|
+
try {
|
|
521
|
+
url = new URL(normalizedInput);
|
|
522
|
+
} catch {
|
|
523
|
+
return value;
|
|
524
|
+
}
|
|
525
|
+
const hostname = url.hostname.toLowerCase().replace(/^www\./, "");
|
|
526
|
+
const isYouTube = ["youtube.com", "m.youtube.com", "music.youtube.com", "youtu.be"].includes(hostname);
|
|
527
|
+
if (!isYouTube)
|
|
528
|
+
return value;
|
|
529
|
+
const segments = url.pathname.split("/").filter(Boolean);
|
|
530
|
+
const videoId = hostname === "youtu.be" ? segments[0] : segments[0] === "watch" ? url.searchParams.get("v") : ["embed", "shorts", "live"].includes(segments[0] ?? "") ? segments[1] : undefined;
|
|
531
|
+
if (!videoId || !/^[\w-]{11}$/.test(videoId))
|
|
532
|
+
return null;
|
|
533
|
+
return `https://www.youtube.com/embed/${videoId}`;
|
|
534
|
+
}
|
|
535
|
+
function NewTextField(defaultValue) {
|
|
536
|
+
return new FieldClass({
|
|
537
|
+
id: UTILS.generateFieldId(),
|
|
538
|
+
name: "Text field",
|
|
539
|
+
type: "text",
|
|
540
|
+
tag: "p",
|
|
541
|
+
variant: "field",
|
|
542
|
+
props: {
|
|
543
|
+
children: { text: "", marks: [] },
|
|
544
|
+
"data-text-path": "props.children",
|
|
545
|
+
contentEditable: false,
|
|
546
|
+
...DEFAULT_STYLES["text"]
|
|
547
|
+
},
|
|
548
|
+
...defaultValue
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
function NewHeadingField(defaultValue) {
|
|
552
|
+
return new FieldClass({
|
|
553
|
+
id: UTILS.generateFieldId(),
|
|
554
|
+
name: "Heading field",
|
|
555
|
+
type: "heading",
|
|
556
|
+
tag: "h1",
|
|
557
|
+
variant: "field",
|
|
558
|
+
props: {
|
|
559
|
+
children: { text: "", marks: [] },
|
|
560
|
+
"data-text-path": "props.children",
|
|
561
|
+
contentEditable: false,
|
|
562
|
+
...DEFAULT_STYLES["heading"]
|
|
563
|
+
},
|
|
564
|
+
...defaultValue
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
function NewImageField(defaultValue) {
|
|
568
|
+
return new FieldClass({
|
|
569
|
+
id: UTILS.generateFieldId(),
|
|
570
|
+
name: "Image field",
|
|
571
|
+
type: "image",
|
|
572
|
+
tag: "img",
|
|
573
|
+
variant: "field",
|
|
574
|
+
props: {
|
|
575
|
+
src: "",
|
|
576
|
+
alt: "image",
|
|
577
|
+
...DEFAULT_STYLES["image"]
|
|
578
|
+
},
|
|
579
|
+
...defaultValue
|
|
580
|
+
});
|
|
581
|
+
}
|
|
582
|
+
function NewVideoField(defaultValue) {
|
|
583
|
+
return new FieldClass({
|
|
584
|
+
id: UTILS.generateFieldId(),
|
|
585
|
+
name: "Video field",
|
|
586
|
+
type: "video",
|
|
587
|
+
tag: "video",
|
|
588
|
+
variant: "field",
|
|
589
|
+
props: {
|
|
590
|
+
src: "",
|
|
591
|
+
alt: "video",
|
|
592
|
+
controlsList: "nodownload nofullscreen noremoteplayback noplaybackrate",
|
|
593
|
+
preload: "metadata",
|
|
594
|
+
controls: true,
|
|
595
|
+
...DEFAULT_STYLES["video"]
|
|
596
|
+
},
|
|
597
|
+
...defaultValue
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
function NewIFrameField(defaultValue) {
|
|
601
|
+
return new FieldClass({
|
|
602
|
+
id: UTILS.generateFieldId(),
|
|
603
|
+
name: "IFrame field",
|
|
604
|
+
type: "iframe",
|
|
605
|
+
tag: "iframe",
|
|
606
|
+
variant: "field",
|
|
607
|
+
props: {
|
|
608
|
+
src: "",
|
|
609
|
+
alt: "image",
|
|
610
|
+
allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",
|
|
611
|
+
referrerPolicy: "strict-origin-when-cross-origin",
|
|
612
|
+
allowFullScreen: false,
|
|
613
|
+
frameBorder: 0,
|
|
614
|
+
...DEFAULT_STYLES["iframe"]
|
|
615
|
+
},
|
|
616
|
+
...defaultValue
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
function NewLinkField(defaultValue) {
|
|
620
|
+
return new FieldClass({
|
|
621
|
+
id: UTILS.generateFieldId(),
|
|
622
|
+
name: "Link field",
|
|
623
|
+
type: "link",
|
|
624
|
+
tag: "a",
|
|
625
|
+
variant: "field",
|
|
626
|
+
props: {
|
|
627
|
+
href: "#",
|
|
628
|
+
alt: "Preview new link",
|
|
629
|
+
"data-text-path": "props.children",
|
|
630
|
+
children: { text: "Preview new link", marks: [] },
|
|
631
|
+
...DEFAULT_STYLES["link"]
|
|
632
|
+
},
|
|
633
|
+
...defaultValue
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
function NewBlockquoteField(defaultValue) {
|
|
637
|
+
return new FieldClass({
|
|
638
|
+
id: UTILS.generateFieldId(),
|
|
639
|
+
name: "Blockquote field",
|
|
640
|
+
type: "blockquote",
|
|
641
|
+
tag: "blockquote",
|
|
642
|
+
variant: "field",
|
|
643
|
+
props: {
|
|
644
|
+
"data-text-path": "props.children",
|
|
645
|
+
children: { text: "", marks: [] },
|
|
646
|
+
...DEFAULT_STYLES["blockquote"]
|
|
647
|
+
},
|
|
648
|
+
...defaultValue
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
function NewDividerField(defaultValue) {
|
|
652
|
+
return new FieldClass({
|
|
653
|
+
id: UTILS.generateFieldId(),
|
|
654
|
+
name: "Divider field",
|
|
655
|
+
type: "divider",
|
|
656
|
+
tag: "hr",
|
|
657
|
+
variant: "field",
|
|
658
|
+
props: {
|
|
659
|
+
...DEFAULT_STYLES["divider"]
|
|
660
|
+
},
|
|
661
|
+
...defaultValue
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
function NewCodeField(defaultValue) {
|
|
665
|
+
return new FieldClass({
|
|
666
|
+
id: UTILS.generateFieldId(),
|
|
667
|
+
name: "Code field",
|
|
668
|
+
type: "code",
|
|
669
|
+
tag: "pre",
|
|
670
|
+
variant: "field",
|
|
671
|
+
props: {
|
|
672
|
+
"data-text-path": "props.children",
|
|
673
|
+
children: { text: "", marks: [] },
|
|
674
|
+
theme: "dark",
|
|
675
|
+
contentEditable: false,
|
|
676
|
+
...DEFAULT_STYLES["code"]
|
|
677
|
+
},
|
|
678
|
+
...defaultValue
|
|
679
|
+
});
|
|
680
|
+
}
|
|
681
|
+
function NewCaptionField(defaultValue) {
|
|
682
|
+
return new FieldClass({
|
|
683
|
+
id: UTILS.generateFieldId(),
|
|
684
|
+
name: "Caption field",
|
|
685
|
+
type: "caption",
|
|
686
|
+
tag: "figcaption",
|
|
687
|
+
variant: "field",
|
|
688
|
+
props: {
|
|
689
|
+
"data-text-path": "props.children",
|
|
690
|
+
children: { text: "", marks: [] },
|
|
691
|
+
contentEditable: false,
|
|
692
|
+
...DEFAULT_STYLES["caption"]
|
|
693
|
+
},
|
|
694
|
+
...defaultValue
|
|
695
|
+
});
|
|
696
|
+
}
|
|
697
|
+
function NewField(type, defaultValue) {
|
|
698
|
+
switch (type) {
|
|
699
|
+
case "text":
|
|
700
|
+
return NewTextField(defaultValue);
|
|
701
|
+
case "heading":
|
|
702
|
+
return NewHeadingField(defaultValue);
|
|
703
|
+
case "image":
|
|
704
|
+
return NewImageField(defaultValue);
|
|
705
|
+
case "video":
|
|
706
|
+
return NewVideoField(defaultValue);
|
|
707
|
+
case "link":
|
|
708
|
+
return NewLinkField(defaultValue);
|
|
709
|
+
case "divider":
|
|
710
|
+
return NewDividerField(defaultValue);
|
|
711
|
+
case "iframe":
|
|
712
|
+
return NewIFrameField(defaultValue);
|
|
713
|
+
case "blockquote":
|
|
714
|
+
return NewBlockquoteField(defaultValue);
|
|
715
|
+
case "code":
|
|
716
|
+
return NewCodeField(defaultValue);
|
|
717
|
+
case "caption":
|
|
718
|
+
return NewCaptionField(defaultValue);
|
|
719
|
+
default:
|
|
720
|
+
return NewTextField(defaultValue);
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
function DeserializeField(field4) {
|
|
724
|
+
return new FieldClass(field4);
|
|
725
|
+
}
|
|
726
|
+
var FieldsUtils = {
|
|
727
|
+
NewField,
|
|
728
|
+
DeserializeField,
|
|
729
|
+
NewTextField,
|
|
730
|
+
NewHeadingField,
|
|
731
|
+
NewLinkField,
|
|
732
|
+
NewImageField,
|
|
733
|
+
NewDividerField,
|
|
734
|
+
NewIFrameField,
|
|
735
|
+
NewBlockquoteField,
|
|
736
|
+
NewCodeField,
|
|
737
|
+
NewCaptionField
|
|
738
|
+
};
|
|
739
|
+
function NewLinkTNode(defaultValue) {
|
|
740
|
+
return new TNodeClass({
|
|
741
|
+
id: UTILS.generateTNodeId(),
|
|
742
|
+
name: "Link tnode",
|
|
743
|
+
type: "link",
|
|
744
|
+
tag: "a",
|
|
745
|
+
variant: "tnode",
|
|
746
|
+
props: { style: {}, text: "" },
|
|
747
|
+
...defaultValue
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
function NewSpanTNode(defaultValue) {
|
|
751
|
+
return new TNodeClass({
|
|
752
|
+
id: UTILS.generateTNodeId(),
|
|
753
|
+
name: "Sub-field tnode",
|
|
754
|
+
type: "sub-field",
|
|
755
|
+
tag: "span",
|
|
756
|
+
variant: "tnode",
|
|
757
|
+
props: { style: {}, text: "" },
|
|
758
|
+
...defaultValue
|
|
759
|
+
});
|
|
760
|
+
}
|
|
761
|
+
function NewTNode(type, defaultValue) {
|
|
762
|
+
switch (type) {
|
|
763
|
+
case "link":
|
|
764
|
+
return NewLinkTNode(defaultValue);
|
|
765
|
+
default:
|
|
766
|
+
return NewSpanTNode(defaultValue);
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
function DeserializeTNode(tnode2) {
|
|
770
|
+
return new TNodeClass(tnode2);
|
|
771
|
+
}
|
|
772
|
+
var TNodesUtils = { NewTNode, DeserializeTNode };
|
|
773
|
+
function SerializeTree(tree2) {
|
|
774
|
+
const newFields = Array.from(tree2.fields.entries()).reduce((prev, [id, currentField]) => {
|
|
775
|
+
prev[id] = currentField.getCurrentFieldObject();
|
|
776
|
+
return prev;
|
|
777
|
+
}, {});
|
|
778
|
+
const newContainers = Array.from(tree2.containers.entries()).reduce((prev, [id, currentContainer]) => {
|
|
779
|
+
prev[id] = currentContainer.getCurrentContainerObject();
|
|
780
|
+
return prev;
|
|
781
|
+
}, {});
|
|
782
|
+
const newComponents = Array.from(tree2.components.entries()).reduce((prev, [id, currentComponent]) => {
|
|
783
|
+
prev[id] = currentComponent.getCurrentComponentObject();
|
|
784
|
+
return prev;
|
|
785
|
+
}, {});
|
|
786
|
+
return {
|
|
787
|
+
id: tree2.id,
|
|
788
|
+
version: tree2.version,
|
|
789
|
+
order: [...tree2.order],
|
|
790
|
+
fields: newFields,
|
|
791
|
+
containers: newContainers,
|
|
792
|
+
components: newComponents
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
function DeserializeTree(tree2) {
|
|
796
|
+
const newFields = UTILS.ObjectEntries(tree2.fields).reduce((prev, [id, currentField]) => {
|
|
797
|
+
prev.set(id, FieldsUtils.DeserializeField(currentField));
|
|
798
|
+
return prev;
|
|
799
|
+
}, new Map);
|
|
800
|
+
const newContainers = UTILS.ObjectEntries(tree2.containers).reduce((prev, [id, currentContainer]) => {
|
|
801
|
+
prev.set(id, ContainersUtils.DeserializeContainer(currentContainer));
|
|
802
|
+
return prev;
|
|
803
|
+
}, new Map);
|
|
804
|
+
const newComponents = UTILS.ObjectEntries(tree2.components).reduce((prev, [id, currentComponent]) => {
|
|
805
|
+
prev.set(id, ComponentsUtils.DeserializeComponent(currentComponent));
|
|
806
|
+
return prev;
|
|
807
|
+
}, new Map);
|
|
808
|
+
return {
|
|
809
|
+
id: tree2.id,
|
|
810
|
+
version: tree2.version,
|
|
811
|
+
order: new Set(tree2.order),
|
|
812
|
+
fields: newFields,
|
|
813
|
+
containers: newContainers,
|
|
814
|
+
components: newComponents
|
|
815
|
+
};
|
|
816
|
+
}
|
|
817
|
+
function GetDefaultTree() {
|
|
818
|
+
return {
|
|
819
|
+
id: "root",
|
|
820
|
+
version: "0.0.0",
|
|
821
|
+
order: new Set,
|
|
822
|
+
fields: new Map,
|
|
823
|
+
containers: new Map,
|
|
824
|
+
components: new Map
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
var KINDS = ["fields", "containers", "components"];
|
|
828
|
+
function coraxTreeDiffing(prev, next) {
|
|
829
|
+
const added = new Set, removed = new Set, changed = new Set;
|
|
830
|
+
for (const kind of KINDS) {
|
|
831
|
+
const a = prev[kind];
|
|
832
|
+
const b = next[kind];
|
|
833
|
+
if (a === b)
|
|
834
|
+
continue;
|
|
835
|
+
const bKeys = b.keys();
|
|
836
|
+
for (const id of bKeys) {
|
|
837
|
+
if (!a.has(id))
|
|
838
|
+
added.add(id);
|
|
839
|
+
else if (a.get(id) !== b.get(id))
|
|
840
|
+
changed.add(id);
|
|
841
|
+
}
|
|
842
|
+
const aKeys = a.keys();
|
|
843
|
+
for (const id of aKeys)
|
|
844
|
+
if (!b.has(id))
|
|
845
|
+
removed.add(id);
|
|
846
|
+
}
|
|
847
|
+
return { added, removed, changed, orderChanged: prev.order !== next.order };
|
|
848
|
+
}
|
|
849
|
+
function segments({ text, marks }) {
|
|
850
|
+
if (!text)
|
|
851
|
+
return [];
|
|
852
|
+
const cuts = new Set([0, text.length]);
|
|
853
|
+
for (const m of marks) {
|
|
854
|
+
cuts.add(m.start);
|
|
855
|
+
cuts.add(m.end);
|
|
856
|
+
}
|
|
857
|
+
const points = [...cuts].sort((a, b) => a - b);
|
|
858
|
+
const out = [];
|
|
859
|
+
for (let i = 0;i < points.length - 1; i++) {
|
|
860
|
+
const [s, e] = [points[i], points[i + 1]];
|
|
861
|
+
out.push({
|
|
862
|
+
text: text.slice(s, e),
|
|
863
|
+
marks: marks.filter((m) => m.start <= s && m.end >= e)
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
return out;
|
|
867
|
+
}
|
|
868
|
+
var UNITLESS = new Set([
|
|
869
|
+
"animationIterationCount",
|
|
870
|
+
"aspectRatio",
|
|
871
|
+
"borderImageOutset",
|
|
872
|
+
"borderImageSlice",
|
|
873
|
+
"borderImageWidth",
|
|
874
|
+
"boxFlex",
|
|
875
|
+
"boxFlexGroup",
|
|
876
|
+
"boxOrdinalGroup",
|
|
877
|
+
"columnCount",
|
|
878
|
+
"columns",
|
|
879
|
+
"flex",
|
|
880
|
+
"flexGrow",
|
|
881
|
+
"flexPositive",
|
|
882
|
+
"flexShrink",
|
|
883
|
+
"flexNegative",
|
|
884
|
+
"flexOrder",
|
|
885
|
+
"gridArea",
|
|
886
|
+
"gridRow",
|
|
887
|
+
"gridRowEnd",
|
|
888
|
+
"gridRowSpan",
|
|
889
|
+
"gridRowStart",
|
|
890
|
+
"gridColumn",
|
|
891
|
+
"gridColumnEnd",
|
|
892
|
+
"gridColumnSpan",
|
|
893
|
+
"gridColumnStart",
|
|
894
|
+
"fontWeight",
|
|
895
|
+
"lineClamp",
|
|
896
|
+
"lineHeight",
|
|
897
|
+
"opacity",
|
|
898
|
+
"order",
|
|
899
|
+
"orphans",
|
|
900
|
+
"scale",
|
|
901
|
+
"tabSize",
|
|
902
|
+
"widows",
|
|
903
|
+
"zIndex",
|
|
904
|
+
"zoom",
|
|
905
|
+
"fillOpacity",
|
|
906
|
+
"floodOpacity",
|
|
907
|
+
"stopOpacity",
|
|
908
|
+
"strokeDasharray",
|
|
909
|
+
"strokeDashoffset",
|
|
910
|
+
"strokeMiterlimit",
|
|
911
|
+
"strokeOpacity",
|
|
912
|
+
"strokeWidth"
|
|
913
|
+
]);
|
|
914
|
+
function toKebab(property) {
|
|
915
|
+
return property.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`);
|
|
916
|
+
}
|
|
917
|
+
function toCssValue(property, value) {
|
|
918
|
+
if (Array.isArray(value))
|
|
919
|
+
return value.map((v) => String(v)).join(",");
|
|
920
|
+
if (typeof value === "number" && value !== 0 && !UNITLESS.has(property))
|
|
921
|
+
return `${value}px`;
|
|
922
|
+
return String(value);
|
|
923
|
+
}
|
|
924
|
+
function declarations(style) {
|
|
925
|
+
return Object.entries(style).map(([property, value]) => `${toKebab(property)}:${toCssValue(property, value)}`).join(";");
|
|
926
|
+
}
|
|
927
|
+
function serializeRules(style, selector) {
|
|
928
|
+
const rules = [];
|
|
929
|
+
const own = {};
|
|
930
|
+
for (const [key, value] of Object.entries(style)) {
|
|
931
|
+
if (value && typeof value === "object") {
|
|
932
|
+
rules.push(...serializeRules(value, `${selector}${key}`));
|
|
933
|
+
} else {
|
|
934
|
+
own[key] = value;
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
if (Object.keys(own).length > 0)
|
|
938
|
+
rules.push(`${selector}{${declarations(own)}}`);
|
|
939
|
+
return rules;
|
|
940
|
+
}
|
|
941
|
+
function stableStringify(value) {
|
|
942
|
+
if (value === null || typeof value !== "object")
|
|
943
|
+
return JSON.stringify(value) ?? "null";
|
|
944
|
+
if (Array.isArray(value))
|
|
945
|
+
return `[${value.map(stableStringify).join(",")}]`;
|
|
946
|
+
const entries = Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([k, v]) => `${JSON.stringify(k)}:${stableStringify(v)}`);
|
|
947
|
+
return `{${entries.join(",")}}`;
|
|
948
|
+
}
|
|
949
|
+
function hash(input) {
|
|
950
|
+
let h = 2166136261;
|
|
951
|
+
for (let i = 0;i < input.length; i++) {
|
|
952
|
+
h ^= input.charCodeAt(i);
|
|
953
|
+
h = Math.imul(h, 16777619);
|
|
954
|
+
}
|
|
955
|
+
return (h >>> 0).toString(36);
|
|
956
|
+
}
|
|
957
|
+
var collected = new Map;
|
|
958
|
+
var sink = null;
|
|
959
|
+
function collectCoraxPseudoStyle(style) {
|
|
960
|
+
if (!style || Object.keys(style).length === 0)
|
|
961
|
+
return;
|
|
962
|
+
const className = `corax-p-${hash(stableStringify(style))}`;
|
|
963
|
+
if (collected.has(className))
|
|
964
|
+
return className;
|
|
965
|
+
collected.set(className, serializeRules(style, `.${className}`).join(""));
|
|
966
|
+
sink?.();
|
|
967
|
+
return className;
|
|
968
|
+
}
|
|
969
|
+
function getCollectedStyles() {
|
|
970
|
+
return Array.from(collected.values()).join("");
|
|
971
|
+
}
|
|
972
|
+
function clearCollectedStyles() {
|
|
973
|
+
collected.clear();
|
|
974
|
+
}
|
|
975
|
+
function setCoraxStyleSink(fn) {
|
|
976
|
+
sink = fn;
|
|
977
|
+
fn();
|
|
978
|
+
return () => {
|
|
979
|
+
if (sink === fn)
|
|
980
|
+
sink = null;
|
|
981
|
+
};
|
|
982
|
+
}
|
|
983
|
+
var CODE_THEMES = {
|
|
984
|
+
dark: {
|
|
985
|
+
plain: "#e6edf3",
|
|
986
|
+
keyword: "#ff7b72",
|
|
987
|
+
string: "#a5d6ff",
|
|
988
|
+
number: "#79c0ff",
|
|
989
|
+
comment: "#8b949e",
|
|
990
|
+
function: "#d2a8ff",
|
|
991
|
+
punctuation: "#e6edf3",
|
|
992
|
+
operator: "#ff7b72"
|
|
993
|
+
},
|
|
994
|
+
light: {
|
|
995
|
+
plain: "#24292f",
|
|
996
|
+
keyword: "#cf222e",
|
|
997
|
+
string: "#0a3069",
|
|
998
|
+
number: "#0550ae",
|
|
999
|
+
comment: "#6e7781",
|
|
1000
|
+
function: "#8250df",
|
|
1001
|
+
punctuation: "#24292f",
|
|
1002
|
+
operator: "#cf222e"
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
var CODE_THEME_NAMES = Object.keys(CODE_THEMES);
|
|
1006
|
+
var KEYWORDS = new Set([
|
|
1007
|
+
"const",
|
|
1008
|
+
"let",
|
|
1009
|
+
"var",
|
|
1010
|
+
"function",
|
|
1011
|
+
"class",
|
|
1012
|
+
"extends",
|
|
1013
|
+
"return",
|
|
1014
|
+
"if",
|
|
1015
|
+
"else",
|
|
1016
|
+
"for",
|
|
1017
|
+
"while",
|
|
1018
|
+
"do",
|
|
1019
|
+
"switch",
|
|
1020
|
+
"case",
|
|
1021
|
+
"break",
|
|
1022
|
+
"continue",
|
|
1023
|
+
"new",
|
|
1024
|
+
"typeof",
|
|
1025
|
+
"instanceof",
|
|
1026
|
+
"in",
|
|
1027
|
+
"of",
|
|
1028
|
+
"this",
|
|
1029
|
+
"super",
|
|
1030
|
+
"import",
|
|
1031
|
+
"export",
|
|
1032
|
+
"from",
|
|
1033
|
+
"default",
|
|
1034
|
+
"as",
|
|
1035
|
+
"async",
|
|
1036
|
+
"await",
|
|
1037
|
+
"yield",
|
|
1038
|
+
"try",
|
|
1039
|
+
"catch",
|
|
1040
|
+
"finally",
|
|
1041
|
+
"throw",
|
|
1042
|
+
"delete",
|
|
1043
|
+
"void",
|
|
1044
|
+
"null",
|
|
1045
|
+
"undefined",
|
|
1046
|
+
"true",
|
|
1047
|
+
"false",
|
|
1048
|
+
"interface",
|
|
1049
|
+
"type",
|
|
1050
|
+
"enum",
|
|
1051
|
+
"implements",
|
|
1052
|
+
"public",
|
|
1053
|
+
"private",
|
|
1054
|
+
"protected",
|
|
1055
|
+
"readonly",
|
|
1056
|
+
"static",
|
|
1057
|
+
"get",
|
|
1058
|
+
"set",
|
|
1059
|
+
"declare",
|
|
1060
|
+
"namespace",
|
|
1061
|
+
"abstract",
|
|
1062
|
+
"satisfies",
|
|
1063
|
+
"keyof",
|
|
1064
|
+
"infer",
|
|
1065
|
+
"is",
|
|
1066
|
+
"any",
|
|
1067
|
+
"string",
|
|
1068
|
+
"number",
|
|
1069
|
+
"boolean",
|
|
1070
|
+
"never",
|
|
1071
|
+
"unknown",
|
|
1072
|
+
"object",
|
|
1073
|
+
"symbol",
|
|
1074
|
+
"bigint"
|
|
1075
|
+
]);
|
|
1076
|
+
var isIdentStart = (c) => /[A-Za-z_$]/.test(c);
|
|
1077
|
+
var isIdentPart = (c) => /[A-Za-z0-9_$]/.test(c);
|
|
1078
|
+
var isDigit = (c) => c >= "0" && c <= "9";
|
|
1079
|
+
function tokenizeCode(input) {
|
|
1080
|
+
const tokens = [];
|
|
1081
|
+
const push = (type, value) => {
|
|
1082
|
+
if (!value)
|
|
1083
|
+
return;
|
|
1084
|
+
const last = tokens[tokens.length - 1];
|
|
1085
|
+
if (last && last.type === type)
|
|
1086
|
+
last.value += value;
|
|
1087
|
+
else
|
|
1088
|
+
tokens.push({ type, value });
|
|
1089
|
+
};
|
|
1090
|
+
let i = 0;
|
|
1091
|
+
const n = input.length;
|
|
1092
|
+
while (i < n) {
|
|
1093
|
+
const c = input[i];
|
|
1094
|
+
const next = input[i + 1];
|
|
1095
|
+
if (/\s/.test(c)) {
|
|
1096
|
+
let j = i + 1;
|
|
1097
|
+
while (j < n && /\s/.test(input[j]))
|
|
1098
|
+
j++;
|
|
1099
|
+
push("plain", input.slice(i, j));
|
|
1100
|
+
i = j;
|
|
1101
|
+
continue;
|
|
1102
|
+
}
|
|
1103
|
+
if (c === "/" && next === "/") {
|
|
1104
|
+
let j = i + 2;
|
|
1105
|
+
while (j < n && input[j] !== `
|
|
1106
|
+
`)
|
|
1107
|
+
j++;
|
|
1108
|
+
push("comment", input.slice(i, j));
|
|
1109
|
+
i = j;
|
|
1110
|
+
continue;
|
|
1111
|
+
}
|
|
1112
|
+
if (c === "/" && next === "*") {
|
|
1113
|
+
let j = i + 2;
|
|
1114
|
+
while (j < n && !(input[j] === "*" && input[j + 1] === "/"))
|
|
1115
|
+
j++;
|
|
1116
|
+
j = Math.min(n, j + 2);
|
|
1117
|
+
push("comment", input.slice(i, j));
|
|
1118
|
+
i = j;
|
|
1119
|
+
continue;
|
|
1120
|
+
}
|
|
1121
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
1122
|
+
let j = i + 1;
|
|
1123
|
+
while (j < n) {
|
|
1124
|
+
if (input[j] === "\\") {
|
|
1125
|
+
j += 2;
|
|
1126
|
+
continue;
|
|
1127
|
+
}
|
|
1128
|
+
if (input[j] === c) {
|
|
1129
|
+
j++;
|
|
1130
|
+
break;
|
|
1131
|
+
}
|
|
1132
|
+
if (c !== "`" && input[j] === `
|
|
1133
|
+
`)
|
|
1134
|
+
break;
|
|
1135
|
+
j++;
|
|
1136
|
+
}
|
|
1137
|
+
push("string", input.slice(i, j));
|
|
1138
|
+
i = j;
|
|
1139
|
+
continue;
|
|
1140
|
+
}
|
|
1141
|
+
if (isDigit(c)) {
|
|
1142
|
+
let j = i;
|
|
1143
|
+
while (j < n && /[0-9a-fA-FxXoObBeE._]/.test(input[j]))
|
|
1144
|
+
j++;
|
|
1145
|
+
if (j < n && (input[j] === "+" || input[j] === "-") && /[eE]/.test(input[j - 1]))
|
|
1146
|
+
j++;
|
|
1147
|
+
while (j < n && isDigit(input[j]))
|
|
1148
|
+
j++;
|
|
1149
|
+
push("number", input.slice(i, j));
|
|
1150
|
+
i = j;
|
|
1151
|
+
continue;
|
|
1152
|
+
}
|
|
1153
|
+
if (isIdentStart(c)) {
|
|
1154
|
+
let j = i + 1;
|
|
1155
|
+
while (j < n && isIdentPart(input[j]))
|
|
1156
|
+
j++;
|
|
1157
|
+
const word = input.slice(i, j);
|
|
1158
|
+
let k = j;
|
|
1159
|
+
while (k < n && /\s/.test(input[k]))
|
|
1160
|
+
k++;
|
|
1161
|
+
if (KEYWORDS.has(word))
|
|
1162
|
+
push("keyword", word);
|
|
1163
|
+
else if (input[k] === "(")
|
|
1164
|
+
push("function", word);
|
|
1165
|
+
else
|
|
1166
|
+
push("plain", word);
|
|
1167
|
+
i = j;
|
|
1168
|
+
continue;
|
|
1169
|
+
}
|
|
1170
|
+
if (/[{}()[\];,.]/.test(c)) {
|
|
1171
|
+
push("punctuation", c);
|
|
1172
|
+
i++;
|
|
1173
|
+
continue;
|
|
1174
|
+
}
|
|
1175
|
+
if (/[=+\-*/%<>!&|^~?:]/.test(c)) {
|
|
1176
|
+
push("operator", c);
|
|
1177
|
+
i++;
|
|
1178
|
+
continue;
|
|
1179
|
+
}
|
|
1180
|
+
push("plain", c);
|
|
1181
|
+
i++;
|
|
1182
|
+
}
|
|
1183
|
+
return tokens;
|
|
1184
|
+
}
|
|
1185
|
+
// src/utils/modules.utils.ts
|
|
1186
|
+
function createScopedTCtx(engine, moduleName) {
|
|
1187
|
+
const disposers = [];
|
|
1188
|
+
function trackFn(disposer) {
|
|
1189
|
+
let done = false;
|
|
1190
|
+
const safe = () => {
|
|
1191
|
+
if (!done) {
|
|
1192
|
+
done = true;
|
|
1193
|
+
disposer();
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
disposers.push(safe);
|
|
1197
|
+
return disposer;
|
|
1198
|
+
}
|
|
1199
|
+
const ctx = {
|
|
1200
|
+
events: {
|
|
1201
|
+
on: (ev, handler) => trackFn(engine.events.on(ev, handler)),
|
|
1202
|
+
emit: (ev, props) => engine.events.emit(ev, props),
|
|
1203
|
+
batch: (evs) => engine.events.batch(evs)
|
|
1204
|
+
},
|
|
1205
|
+
commands: {
|
|
1206
|
+
register: (cmd, handler) => trackFn(engine.commands.register(cmd, handler)),
|
|
1207
|
+
registerAsync: (cmd, handler) => trackFn(engine.commands.registerAsync(cmd, handler)),
|
|
1208
|
+
tryExecute: (cmd, payload) => engine.commands.tryExecute(cmd, payload),
|
|
1209
|
+
tryExecuteAsync: (cmd, payload) => engine.commands.tryExecuteAsync(cmd, payload),
|
|
1210
|
+
execute: (cmd, payload) => engine.commands.execute(cmd, payload),
|
|
1211
|
+
executeAsync: (cmd, payload) => engine.commands.executeAsync(cmd, payload),
|
|
1212
|
+
before: (cmd, next) => trackFn(engine.commands.before(cmd, next)),
|
|
1213
|
+
beforeAsync: (cmd, next) => trackFn(engine.commands.beforeAsync(cmd, next)),
|
|
1214
|
+
after: (cmd, callback) => trackFn(engine.commands.after(cmd, callback)),
|
|
1215
|
+
afterAsync: (cmd, callback) => trackFn(engine.commands.afterAsync(cmd, callback)),
|
|
1216
|
+
has: (cmd) => engine.commands.has(cmd)
|
|
1217
|
+
},
|
|
1218
|
+
state: {
|
|
1219
|
+
defineSlice: (name2, initial) => {
|
|
1220
|
+
return trackFn(engine.state.defineSlice(name2, initial));
|
|
1221
|
+
},
|
|
1222
|
+
get: (name2) => engine.state.get(name2),
|
|
1223
|
+
set: (name2, next) => {
|
|
1224
|
+
engine.state.set(name2, next);
|
|
1225
|
+
},
|
|
1226
|
+
subscribe: (name2, fn) => trackFn(engine.state.subscribe(name2, fn))
|
|
1227
|
+
},
|
|
1228
|
+
document: engine.document,
|
|
1229
|
+
mutations: engine.mutations,
|
|
1230
|
+
shortcuts: engine.shortcuts,
|
|
1231
|
+
text: {
|
|
1232
|
+
registerMark: (type, behavior) => trackFn(engine.text.registerMark(type, behavior)),
|
|
1233
|
+
toggleMark: (c, o) => engine.text.toggleMark(c, o),
|
|
1234
|
+
insertText: (c, at, t, o) => engine.text.insertText(c, at, t, o),
|
|
1235
|
+
deleteRange: (c, s, e) => engine.text.deleteRange(c, s, e),
|
|
1236
|
+
replaceRange: (c, s, e, t, o) => engine.text.replaceRange(c, s, e, t, o),
|
|
1237
|
+
isInclusive: (t) => engine.text.isInclusive(t)
|
|
1238
|
+
},
|
|
1239
|
+
ui: {
|
|
1240
|
+
contribute: (c) => trackFn(engine.ui.contribute({
|
|
1241
|
+
...c,
|
|
1242
|
+
id: `${moduleName}.${c.id}`,
|
|
1243
|
+
when: c.when
|
|
1244
|
+
})),
|
|
1245
|
+
subscribe: (slotName, fn) => trackFn(engine.ui.subscribe(slotName, fn)),
|
|
1246
|
+
getSlots: (slotName) => engine.ui.getSlots(slotName),
|
|
1247
|
+
registerStyle: (styleName, css) => trackFn(engine.ui.registerStyle(styleName, css)),
|
|
1248
|
+
patchStyle: (styleName, patch) => trackFn(engine.ui.patchStyle(styleName, patch)),
|
|
1249
|
+
getStyle: (styleName) => engine.ui.getStyle(styleName),
|
|
1250
|
+
interceptPayload: (id, fn) => trackFn(engine.ui.interceptPayload(id, fn)),
|
|
1251
|
+
runContribution: (c, ui) => engine.ui.runContribution(c, ui)
|
|
1252
|
+
},
|
|
1253
|
+
tasks: {
|
|
1254
|
+
schedule: (name2, delay, fn) => trackFn(engine.tasks.schedule(name2, delay, fn)),
|
|
1255
|
+
cancel: (name2) => engine.tasks.cancel(name2),
|
|
1256
|
+
isPending: (name2) => engine.tasks.isPending(name2),
|
|
1257
|
+
isRunning: (name2) => engine.tasks.isRunning(name2),
|
|
1258
|
+
getStatus: (name2) => engine.tasks.getStatus(name2),
|
|
1259
|
+
getState: (name2) => engine.tasks.getState(name2),
|
|
1260
|
+
subscribe: (name2, fn) => trackFn(engine.tasks.subscribe(name2, fn)),
|
|
1261
|
+
flush: (name2) => engine.tasks.flush(name2),
|
|
1262
|
+
cancelAll: () => engine.tasks.cancelAll(),
|
|
1263
|
+
dispose: () => engine.tasks.dispose()
|
|
1264
|
+
}
|
|
1265
|
+
};
|
|
1266
|
+
return {
|
|
1267
|
+
ctx,
|
|
1268
|
+
dispose: () => disposers.splice(0).reverse().forEach((dp) => dp())
|
|
1269
|
+
};
|
|
1270
|
+
}
|
|
1271
|
+
var ModuleUtils = { createScopedTCtx };
|
|
1272
|
+
// src/modules/modules-manager.ts
|
|
1273
|
+
class ModuleManager {
|
|
1274
|
+
registry = new Map;
|
|
1275
|
+
active = new Map;
|
|
1276
|
+
engine;
|
|
1277
|
+
constructor(engine) {
|
|
1278
|
+
this.engine = engine;
|
|
1279
|
+
}
|
|
1280
|
+
register(modules2) {
|
|
1281
|
+
for (const module of modules2) {
|
|
1282
|
+
if (this.registry.has(module.name)) {
|
|
1283
|
+
throw new Error(`Module "${module.name}" is already registered`);
|
|
1284
|
+
}
|
|
1285
|
+
this.registry.set(module.name, module);
|
|
1286
|
+
}
|
|
1287
|
+
}
|
|
1288
|
+
isEnabled(name2) {
|
|
1289
|
+
return this.active.has(name2);
|
|
1290
|
+
}
|
|
1291
|
+
isRegistered(name2) {
|
|
1292
|
+
return this.registry.has(name2);
|
|
1293
|
+
}
|
|
1294
|
+
enable(name2) {
|
|
1295
|
+
this.enableRec(name2, []);
|
|
1296
|
+
}
|
|
1297
|
+
enableAll() {
|
|
1298
|
+
for (const name2 of this.registry.keys())
|
|
1299
|
+
this.enable(name2);
|
|
1300
|
+
}
|
|
1301
|
+
disabledAll() {
|
|
1302
|
+
for (const name2 of this.registry.keys())
|
|
1303
|
+
this.disable(name2, { cascade: true });
|
|
1304
|
+
}
|
|
1305
|
+
disable(name2, opts = {}) {
|
|
1306
|
+
const cleanup = this.active.get(name2);
|
|
1307
|
+
if (!cleanup)
|
|
1308
|
+
return;
|
|
1309
|
+
const dependents = this.activeDependentsOf(name2);
|
|
1310
|
+
if (dependents.length > 0) {
|
|
1311
|
+
if (!opts.cascade) {
|
|
1312
|
+
throw new Error(`Cannot disable "${name2}": required by ${dependents.join(", ")}`);
|
|
1313
|
+
}
|
|
1314
|
+
dependents.forEach((d) => this.disable(d, { cascade: true }));
|
|
1315
|
+
}
|
|
1316
|
+
this.active.delete(name2);
|
|
1317
|
+
cleanup();
|
|
1318
|
+
}
|
|
1319
|
+
unregister(name2) {
|
|
1320
|
+
this.disable(name2, { cascade: true });
|
|
1321
|
+
this.registry.delete(name2);
|
|
1322
|
+
}
|
|
1323
|
+
enableRec(name2, stack) {
|
|
1324
|
+
if (this.active.has(name2))
|
|
1325
|
+
return;
|
|
1326
|
+
if (stack.includes(name2)) {
|
|
1327
|
+
throw new Error(`Circular dependency: ${[...stack, name2].join(" -> ")}`);
|
|
1328
|
+
}
|
|
1329
|
+
const module = this.registry.get(name2);
|
|
1330
|
+
if (!module) {
|
|
1331
|
+
const needer = stack[stack.length - 1];
|
|
1332
|
+
throw new Error(`Module "${name2}" is not registered` + (needer ? ` (required by "${needer}")` : ""));
|
|
1333
|
+
}
|
|
1334
|
+
for (const dep of module.requires ?? []) {
|
|
1335
|
+
this.enableRec(dep, [...stack, name2]);
|
|
1336
|
+
}
|
|
1337
|
+
this.activate(module);
|
|
1338
|
+
}
|
|
1339
|
+
activate(module) {
|
|
1340
|
+
const { ctx, dispose } = ModuleUtils.createScopedTCtx(this.engine, module.name);
|
|
1341
|
+
try {
|
|
1342
|
+
const custom = module.install(ctx);
|
|
1343
|
+
this.active.set(module.name, () => {
|
|
1344
|
+
try {
|
|
1345
|
+
if (!custom)
|
|
1346
|
+
return;
|
|
1347
|
+
custom?.();
|
|
1348
|
+
} finally {
|
|
1349
|
+
dispose();
|
|
1350
|
+
}
|
|
1351
|
+
});
|
|
1352
|
+
} catch (error) {
|
|
1353
|
+
dispose();
|
|
1354
|
+
throw error;
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
activeDependentsOf(name2) {
|
|
1358
|
+
return [...this.active.keys()].filter((n) => this.registry.get(n)?.requires.includes(name2));
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
// src/services/commandsbus/commandsbus.ts
|
|
1363
|
+
class CmdNotFoundError extends Error {
|
|
1364
|
+
constructor(cmd) {
|
|
1365
|
+
super(`Command ${cmd} is not registered (module disabled?)`);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
class CommandsBusService {
|
|
1370
|
+
handlers = new Map;
|
|
1371
|
+
asyncHandlers = new Map;
|
|
1372
|
+
afterHooks = new Map;
|
|
1373
|
+
asyncAfterHooks = new Map;
|
|
1374
|
+
nextFunctions = new Map;
|
|
1375
|
+
asyncNextFunctions = new Map;
|
|
1376
|
+
tryExecute(cmd, payload) {
|
|
1377
|
+
try {
|
|
1378
|
+
return this.execute(cmd, payload);
|
|
1379
|
+
} catch (er) {
|
|
1380
|
+
if (!(er instanceof CmdNotFoundError))
|
|
1381
|
+
throw er;
|
|
1382
|
+
console.error(er.message);
|
|
1383
|
+
return null;
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
async tryExecuteAsync(cmd, payload) {
|
|
1387
|
+
try {
|
|
1388
|
+
return await this.executeAsync(cmd, payload);
|
|
1389
|
+
} catch (er) {
|
|
1390
|
+
if (!(er instanceof CmdNotFoundError))
|
|
1391
|
+
throw er;
|
|
1392
|
+
console.error(er.message);
|
|
1393
|
+
return null;
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
execute(cmd, payload) {
|
|
1397
|
+
const handler = this.handlers.get(cmd);
|
|
1398
|
+
if (!handler) {
|
|
1399
|
+
if (this.asyncHandlers.has(cmd)) {
|
|
1400
|
+
throw new Error(`Command "${String(cmd)}" is asynchronous, use executeAsync instead`);
|
|
1401
|
+
}
|
|
1402
|
+
throw new CmdNotFoundError(cmd);
|
|
1403
|
+
}
|
|
1404
|
+
if (this.asyncNextFunctions.has(cmd) || this.asyncAfterHooks.has(cmd)) {
|
|
1405
|
+
throw new Error(`Command "${String(cmd)}" has asynchronous hooks, use executeAsync instead`);
|
|
1406
|
+
}
|
|
1407
|
+
const nextFunctions = this.nextFunctions.get(cmd);
|
|
1408
|
+
let transformedPayload = payload;
|
|
1409
|
+
if (nextFunctions) {
|
|
1410
|
+
for (const nextFn of nextFunctions) {
|
|
1411
|
+
const result2 = nextFn(transformedPayload);
|
|
1412
|
+
if (result2 === null) {
|
|
1413
|
+
return null;
|
|
1414
|
+
}
|
|
1415
|
+
transformedPayload = result2;
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
const result = handler(transformedPayload);
|
|
1419
|
+
const afterHooks = this.afterHooks.get(cmd);
|
|
1420
|
+
if (afterHooks) {
|
|
1421
|
+
for (const hook of afterHooks) {
|
|
1422
|
+
hook(transformedPayload, result);
|
|
1423
|
+
}
|
|
1424
|
+
}
|
|
1425
|
+
return result;
|
|
1426
|
+
}
|
|
1427
|
+
async executeAsync(cmd, payload) {
|
|
1428
|
+
const asyncHandler = this.asyncHandlers.get(cmd);
|
|
1429
|
+
const syncHandler = this.handlers.get(cmd);
|
|
1430
|
+
const handler = asyncHandler ?? syncHandler;
|
|
1431
|
+
if (!handler) {
|
|
1432
|
+
throw new CmdNotFoundError(cmd);
|
|
1433
|
+
}
|
|
1434
|
+
const nextFunctions = this.nextFunctions.get(cmd);
|
|
1435
|
+
let transformedPayload = payload;
|
|
1436
|
+
if (nextFunctions) {
|
|
1437
|
+
for (const nextFn of nextFunctions) {
|
|
1438
|
+
const result2 = nextFn(transformedPayload);
|
|
1439
|
+
if (result2 === null) {
|
|
1440
|
+
return null;
|
|
1441
|
+
}
|
|
1442
|
+
transformedPayload = result2;
|
|
1443
|
+
}
|
|
1444
|
+
}
|
|
1445
|
+
const asyncNextFunctions = this.asyncNextFunctions.get(cmd);
|
|
1446
|
+
if (asyncNextFunctions) {
|
|
1447
|
+
for (const nextFn of asyncNextFunctions) {
|
|
1448
|
+
const result2 = await nextFn(transformedPayload);
|
|
1449
|
+
if (result2 === null) {
|
|
1450
|
+
return null;
|
|
1451
|
+
}
|
|
1452
|
+
transformedPayload = result2;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
const result = await handler(transformedPayload);
|
|
1456
|
+
const afterHooks = this.afterHooks.get(cmd);
|
|
1457
|
+
if (afterHooks) {
|
|
1458
|
+
for (const hook of afterHooks) {
|
|
1459
|
+
hook(transformedPayload, result);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
const asyncAfterHooks = this.asyncAfterHooks.get(cmd);
|
|
1463
|
+
if (asyncAfterHooks) {
|
|
1464
|
+
for (const hook of asyncAfterHooks) {
|
|
1465
|
+
await hook(transformedPayload, result);
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
return result;
|
|
1469
|
+
}
|
|
1470
|
+
register(cmd, handler) {
|
|
1471
|
+
if (this.handlers.has(cmd) || this.asyncHandlers.has(cmd)) {
|
|
1472
|
+
throw new Error(`Command ${cmd} already registered`);
|
|
1473
|
+
}
|
|
1474
|
+
this.handlers.set(cmd, handler);
|
|
1475
|
+
return () => {
|
|
1476
|
+
if (this.handlers.get(cmd) === handler)
|
|
1477
|
+
this.handlers.delete(cmd);
|
|
1478
|
+
};
|
|
1479
|
+
}
|
|
1480
|
+
registerAsync(cmd, handler) {
|
|
1481
|
+
if (this.handlers.has(cmd) || this.asyncHandlers.has(cmd)) {
|
|
1482
|
+
throw new Error(`Command ${cmd} already registered`);
|
|
1483
|
+
}
|
|
1484
|
+
this.asyncHandlers.set(cmd, handler);
|
|
1485
|
+
return () => {
|
|
1486
|
+
if (this.asyncHandlers.get(cmd) === handler)
|
|
1487
|
+
this.asyncHandlers.delete(cmd);
|
|
1488
|
+
};
|
|
1489
|
+
}
|
|
1490
|
+
before(cmd, next) {
|
|
1491
|
+
const nextFunctions = this.nextFunctions.get(cmd) ?? [];
|
|
1492
|
+
nextFunctions.push(next);
|
|
1493
|
+
this.nextFunctions.set(cmd, nextFunctions);
|
|
1494
|
+
return () => {
|
|
1495
|
+
const currentNextFunctions = this.nextFunctions.get(cmd);
|
|
1496
|
+
if (currentNextFunctions) {
|
|
1497
|
+
const index = currentNextFunctions.indexOf(next);
|
|
1498
|
+
if (index !== -1) {
|
|
1499
|
+
currentNextFunctions.splice(index, 1);
|
|
1500
|
+
}
|
|
1501
|
+
if (currentNextFunctions.length === 0) {
|
|
1502
|
+
this.nextFunctions.delete(cmd);
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
};
|
|
1506
|
+
}
|
|
1507
|
+
beforeAsync(cmd, next) {
|
|
1508
|
+
const asyncNextFunctions = this.asyncNextFunctions.get(cmd) ?? [];
|
|
1509
|
+
asyncNextFunctions.push(next);
|
|
1510
|
+
this.asyncNextFunctions.set(cmd, asyncNextFunctions);
|
|
1511
|
+
return () => {
|
|
1512
|
+
const currentAsyncNextFunctions = this.asyncNextFunctions.get(cmd);
|
|
1513
|
+
if (currentAsyncNextFunctions) {
|
|
1514
|
+
const index = currentAsyncNextFunctions.indexOf(next);
|
|
1515
|
+
if (index !== -1) {
|
|
1516
|
+
currentAsyncNextFunctions.splice(index, 1);
|
|
1517
|
+
}
|
|
1518
|
+
if (currentAsyncNextFunctions.length === 0) {
|
|
1519
|
+
this.asyncNextFunctions.delete(cmd);
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
}
|
|
1524
|
+
after(cmd, callback) {
|
|
1525
|
+
const hooks = this.afterHooks.get(cmd) ?? [];
|
|
1526
|
+
hooks.push(callback);
|
|
1527
|
+
this.afterHooks.set(cmd, hooks);
|
|
1528
|
+
return () => {
|
|
1529
|
+
const currentHooks = this.afterHooks.get(cmd);
|
|
1530
|
+
if (!currentHooks)
|
|
1531
|
+
return;
|
|
1532
|
+
const index = currentHooks.indexOf(callback);
|
|
1533
|
+
if (index !== -1) {
|
|
1534
|
+
currentHooks.splice(index, 1);
|
|
1535
|
+
}
|
|
1536
|
+
if (currentHooks.length === 0) {
|
|
1537
|
+
this.afterHooks.delete(cmd);
|
|
1538
|
+
}
|
|
1539
|
+
};
|
|
1540
|
+
}
|
|
1541
|
+
afterAsync(cmd, callback) {
|
|
1542
|
+
const hooks = this.asyncAfterHooks.get(cmd) ?? [];
|
|
1543
|
+
hooks.push(callback);
|
|
1544
|
+
this.asyncAfterHooks.set(cmd, hooks);
|
|
1545
|
+
return () => {
|
|
1546
|
+
const currentHooks = this.asyncAfterHooks.get(cmd);
|
|
1547
|
+
if (!currentHooks)
|
|
1548
|
+
return;
|
|
1549
|
+
const index = currentHooks.indexOf(callback);
|
|
1550
|
+
if (index !== -1) {
|
|
1551
|
+
currentHooks.splice(index, 1);
|
|
1552
|
+
}
|
|
1553
|
+
if (currentHooks.length === 0) {
|
|
1554
|
+
this.asyncAfterHooks.delete(cmd);
|
|
1555
|
+
}
|
|
1556
|
+
};
|
|
1557
|
+
}
|
|
1558
|
+
has(cmd) {
|
|
1559
|
+
return this.handlers.has(cmd) || this.asyncHandlers.has(cmd);
|
|
1560
|
+
}
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
// src/services/document/document.ts
|
|
1564
|
+
class DocumentService {
|
|
1565
|
+
state;
|
|
1566
|
+
events;
|
|
1567
|
+
blockListeners = new Map;
|
|
1568
|
+
constructor(state, events) {
|
|
1569
|
+
this.state = state;
|
|
1570
|
+
this.events = events;
|
|
1571
|
+
this.state.defineSlice("document", GetDefaultTree());
|
|
1572
|
+
}
|
|
1573
|
+
subscribeBlock(id, fn) {
|
|
1574
|
+
const set = this.blockListeners.get(id) ?? new Set;
|
|
1575
|
+
set.add(fn);
|
|
1576
|
+
this.blockListeners.set(id, set);
|
|
1577
|
+
return () => {
|
|
1578
|
+
set.delete(fn);
|
|
1579
|
+
if (!set.size)
|
|
1580
|
+
this.blockListeners.delete(id);
|
|
1581
|
+
};
|
|
1582
|
+
}
|
|
1583
|
+
bumpDocumentVersion(version) {
|
|
1584
|
+
const parts = version.split(".").map((n) => parseInt(n, 10));
|
|
1585
|
+
if (parts.length !== 3 || parts.some((n) => isNaN(n))) {
|
|
1586
|
+
throw new Error(`Invalid document version format: ${version}`);
|
|
1587
|
+
}
|
|
1588
|
+
let [major, minor, patch] = parts;
|
|
1589
|
+
patch++;
|
|
1590
|
+
if (patch >= 100) {
|
|
1591
|
+
patch = 0;
|
|
1592
|
+
minor++;
|
|
1593
|
+
}
|
|
1594
|
+
if (minor >= 100) {
|
|
1595
|
+
minor = 0;
|
|
1596
|
+
major++;
|
|
1597
|
+
}
|
|
1598
|
+
const newVersion = `${major}.${minor}.${patch}`;
|
|
1599
|
+
return newVersion;
|
|
1600
|
+
}
|
|
1601
|
+
get() {
|
|
1602
|
+
return this.state.get("document");
|
|
1603
|
+
}
|
|
1604
|
+
apply(predicate, { shouldEmitEvent, origin } = {
|
|
1605
|
+
shouldEmitEvent: true,
|
|
1606
|
+
origin: "user"
|
|
1607
|
+
}) {
|
|
1608
|
+
const prev = this.get();
|
|
1609
|
+
const next = predicate(prev);
|
|
1610
|
+
if (next === prev)
|
|
1611
|
+
return;
|
|
1612
|
+
const diff = coraxTreeDiffing(prev, next);
|
|
1613
|
+
if (!shouldEmitEvent) {
|
|
1614
|
+
this.state.set("document", next);
|
|
1615
|
+
for (const id of [...diff.changed, ...diff.added, ...diff.removed]) {
|
|
1616
|
+
this.blockListeners.get(id)?.forEach((fn) => fn());
|
|
1617
|
+
}
|
|
1618
|
+
} else {
|
|
1619
|
+
const versionnedTree = { ...next, version: this.bumpDocumentVersion(next.version) };
|
|
1620
|
+
this.state.set("document", versionnedTree);
|
|
1621
|
+
for (const id of [...diff.changed, ...diff.added, ...diff.removed]) {
|
|
1622
|
+
this.blockListeners.get(id)?.forEach((fn) => fn());
|
|
1623
|
+
}
|
|
1624
|
+
this.events.emit("document:changed", {
|
|
1625
|
+
prev,
|
|
1626
|
+
next: versionnedTree,
|
|
1627
|
+
origin: origin ?? "user",
|
|
1628
|
+
diff
|
|
1629
|
+
});
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
getBlock(id) {
|
|
1633
|
+
const t = this.get();
|
|
1634
|
+
return t.fields.get(id) ?? t.containers.get(id) ?? t.components.get(id);
|
|
1635
|
+
}
|
|
1636
|
+
has(id) {
|
|
1637
|
+
return this.getBlock(id) !== undefined;
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
// src/services/eventbus/subscriber.ts
|
|
1642
|
+
class Subscriber {
|
|
1643
|
+
target;
|
|
1644
|
+
event;
|
|
1645
|
+
value = {};
|
|
1646
|
+
constructor(target, event) {
|
|
1647
|
+
this.target = target;
|
|
1648
|
+
this.event = event;
|
|
1649
|
+
}
|
|
1650
|
+
with(props) {
|
|
1651
|
+
const { event = "", ...restProps } = props;
|
|
1652
|
+
return Object.assign(Object.create(Object.getPrototypeOf(this)), this, {
|
|
1653
|
+
...event.trim() ? { event } : null,
|
|
1654
|
+
..."value" in restProps ? restProps : { value: restProps }
|
|
1655
|
+
});
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
// src/services/eventbus/eventbus.ts
|
|
1660
|
+
class EventBusService {
|
|
1661
|
+
handlers = new Map;
|
|
1662
|
+
isRerenderEventActive = false;
|
|
1663
|
+
cleanUpCallback(ev, blogHandler) {
|
|
1664
|
+
const newHandlers = (this.handlers.get(ev) ?? []).filter((handler) => handler.id !== blogHandler.id);
|
|
1665
|
+
this.handlers.set(ev, newHandlers);
|
|
1666
|
+
}
|
|
1667
|
+
on(ev, callback) {
|
|
1668
|
+
const prevHandlers = this.handlers.get(ev) ?? [];
|
|
1669
|
+
const newId = UTILS.generateSubscriberId();
|
|
1670
|
+
const newTEvent = {
|
|
1671
|
+
id: newId,
|
|
1672
|
+
callback,
|
|
1673
|
+
subscriber: new Subscriber(newId, ev)
|
|
1674
|
+
};
|
|
1675
|
+
this.handlers.set(ev, [...prevHandlers, newTEvent]);
|
|
1676
|
+
return this.cleanUpCallback.bind(this, ev, newTEvent);
|
|
1677
|
+
}
|
|
1678
|
+
async emit(ev, props, toAwaited = true) {
|
|
1679
|
+
if (ev === "re-render") {
|
|
1680
|
+
this.isRerenderEventActive = true;
|
|
1681
|
+
}
|
|
1682
|
+
const eventHandlers = this.handlers.get(ev) ?? [];
|
|
1683
|
+
const eventsPromises = Promise.all(eventHandlers.map((handler) => {
|
|
1684
|
+
const subscriber = props ? handler.subscriber.with(props) : handler.subscriber;
|
|
1685
|
+
return handler.callback(subscriber);
|
|
1686
|
+
}));
|
|
1687
|
+
if (toAwaited) {
|
|
1688
|
+
await eventsPromises.catch((err) => console.error("Error in event handlers:", err));
|
|
1689
|
+
} else {
|
|
1690
|
+
eventsPromises.then(() => console.log("All handlers resolved")).catch((err) => console.error("Error in event handlers:", err));
|
|
1691
|
+
}
|
|
1692
|
+
if (this.isRerenderEventActive) {
|
|
1693
|
+
this.isRerenderEventActive = false;
|
|
1694
|
+
}
|
|
1695
|
+
if (ev !== "changes") {
|
|
1696
|
+
await this.emit("changes", { ...props, event: ev });
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
batch(evs) {
|
|
1700
|
+
return evs.map(([ev, props]) => this.emit(ev, props));
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
|
|
1704
|
+
// src/services/mutations/mutations.errors.ts
|
|
1705
|
+
class MutationError extends Error {
|
|
1706
|
+
constructor(message) {
|
|
1707
|
+
super(`MutationError: ${message}`);
|
|
1708
|
+
this.name = "MutationError";
|
|
1709
|
+
}
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
class MutationPrototypeError extends MutationError {
|
|
1713
|
+
constructor(name2) {
|
|
1714
|
+
super(`Trying to mutate '${name2}' who has lost his prototype`);
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
// src/services/mutations/mutations.ts
|
|
1719
|
+
var FORBIDDEN = new Set(["__proto__", "constructor", "prototype"]);
|
|
1720
|
+
|
|
1721
|
+
class MutationsService {
|
|
1722
|
+
insertField(tree, _field, index) {
|
|
1723
|
+
const hasField = tree.order.has(_field.id);
|
|
1724
|
+
if (hasField) {
|
|
1725
|
+
throw new MutationError(`Field ${_field.name} with ID (${_field.id}) already exists`);
|
|
1726
|
+
}
|
|
1727
|
+
const field = _field instanceof FieldClass ? _field : new FieldClass(_field);
|
|
1728
|
+
if (!(field instanceof FieldClass)) {
|
|
1729
|
+
throw new MutationPrototypeError(field.name);
|
|
1730
|
+
}
|
|
1731
|
+
if (index === 0) {
|
|
1732
|
+
throw new MutationError(`Cannot delete the first field!`);
|
|
1733
|
+
}
|
|
1734
|
+
if (field.containerId) {
|
|
1735
|
+
const hasContainer = tree.containers.has(field.containerId);
|
|
1736
|
+
const hasContainerInOrder = tree.order.has(field.containerId);
|
|
1737
|
+
if (!hasContainer || !hasContainerInOrder) {
|
|
1738
|
+
throw new MutationError(`Insert of Field ${field.name} with ID (${field.id}) failed. Container ${field.containerId} does not exist`);
|
|
1739
|
+
}
|
|
1740
|
+
tree = this.mutateContainer(tree, {
|
|
1741
|
+
id: field.containerId,
|
|
1742
|
+
keyValuePairs: {
|
|
1743
|
+
order: new Set([field.id])
|
|
1744
|
+
}
|
|
1745
|
+
});
|
|
1746
|
+
}
|
|
1747
|
+
let order;
|
|
1748
|
+
if (index !== undefined) {
|
|
1749
|
+
if (index < 0) {
|
|
1750
|
+
console.warn(`Mutation: negative index detected '${index}'`);
|
|
1751
|
+
}
|
|
1752
|
+
const orderArray = Array.from(tree.order);
|
|
1753
|
+
let targetIndex = index;
|
|
1754
|
+
while (targetIndex > 0 && targetIndex < orderArray.length) {
|
|
1755
|
+
const previous = tree.fields.get(orderArray[targetIndex - 1]);
|
|
1756
|
+
const current = tree.fields.get(orderArray[targetIndex]);
|
|
1757
|
+
const isAttachedCaption = !!previous && isMediaType(previous.type) && !!current && current.type === "caption" && current.props.mediaId === previous.id;
|
|
1758
|
+
if (!isAttachedCaption)
|
|
1759
|
+
break;
|
|
1760
|
+
targetIndex++;
|
|
1761
|
+
}
|
|
1762
|
+
orderArray.splice(targetIndex, 0, field.id);
|
|
1763
|
+
order = new Set(orderArray);
|
|
1764
|
+
} else {
|
|
1765
|
+
order = new Set(tree.order);
|
|
1766
|
+
order.add(field.id);
|
|
1767
|
+
}
|
|
1768
|
+
const fields = new Map(tree.fields);
|
|
1769
|
+
fields.set(field.id, field);
|
|
1770
|
+
return {
|
|
1771
|
+
...tree,
|
|
1772
|
+
order,
|
|
1773
|
+
fields
|
|
1774
|
+
};
|
|
1775
|
+
}
|
|
1776
|
+
deleteField(tree, fieldId) {
|
|
1777
|
+
const hasField = tree.order.has(fieldId);
|
|
1778
|
+
if (!hasField) {
|
|
1779
|
+
throw new MutationError(`Field with ID (${fieldId}) not found`);
|
|
1780
|
+
}
|
|
1781
|
+
const field = tree.fields.get(fieldId);
|
|
1782
|
+
const order = new Set(tree.order);
|
|
1783
|
+
order.delete(fieldId);
|
|
1784
|
+
const fields = new Map(tree.fields);
|
|
1785
|
+
fields.delete(fieldId);
|
|
1786
|
+
let updatedTree = {
|
|
1787
|
+
...tree,
|
|
1788
|
+
order,
|
|
1789
|
+
fields
|
|
1790
|
+
};
|
|
1791
|
+
const hasContainer = field?.containerId && updatedTree.containers.has(field.containerId);
|
|
1792
|
+
if (hasContainer) {
|
|
1793
|
+
const container = updatedTree.containers.get(field.containerId);
|
|
1794
|
+
const containerHasField = container?.order.has(fieldId);
|
|
1795
|
+
if (container && containerHasField) {
|
|
1796
|
+
const containerOrder = new Set(container.order);
|
|
1797
|
+
containerOrder.delete(fieldId);
|
|
1798
|
+
updatedTree = this.mutateContainer(updatedTree, {
|
|
1799
|
+
id: field.containerId,
|
|
1800
|
+
keyValuePairs: {
|
|
1801
|
+
order: containerOrder
|
|
1802
|
+
},
|
|
1803
|
+
autoMerge: false
|
|
1804
|
+
});
|
|
1805
|
+
}
|
|
1806
|
+
}
|
|
1807
|
+
const attachedCaptions = [];
|
|
1808
|
+
for (const [id, f] of updatedTree.fields) {
|
|
1809
|
+
if (f.type === "caption" && f.props.mediaId === fieldId) {
|
|
1810
|
+
attachedCaptions.push(id);
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
for (const captionId of attachedCaptions) {
|
|
1814
|
+
updatedTree = this.deleteField(updatedTree, captionId);
|
|
1815
|
+
}
|
|
1816
|
+
return updatedTree;
|
|
1817
|
+
}
|
|
1818
|
+
changeField(tree, { fieldId, type }) {
|
|
1819
|
+
const hasField = tree.order.has(fieldId) && tree.fields.has(fieldId);
|
|
1820
|
+
if (!hasField) {
|
|
1821
|
+
throw new MutationError(`Field with ID (${fieldId}) not found`);
|
|
1822
|
+
}
|
|
1823
|
+
const _field = tree.fields.get(fieldId);
|
|
1824
|
+
const field = _field instanceof FieldClass ? _field : new FieldClass(_field);
|
|
1825
|
+
if (!(field instanceof FieldClass)) {
|
|
1826
|
+
throw new MutationPrototypeError(field.name);
|
|
1827
|
+
}
|
|
1828
|
+
if (!isEditableField(field) || field.type === type) {
|
|
1829
|
+
return tree;
|
|
1830
|
+
}
|
|
1831
|
+
const hasContent = !!field.props.children.text.length;
|
|
1832
|
+
if (hasContent) {
|
|
1833
|
+
return tree;
|
|
1834
|
+
}
|
|
1835
|
+
const order = new Set(tree.order);
|
|
1836
|
+
const pos = [...order].indexOf(fieldId);
|
|
1837
|
+
return this.insertField(this.deleteField(tree, fieldId), FieldsUtils.NewField(type, { id: field.id }), pos);
|
|
1838
|
+
}
|
|
1839
|
+
mutateField(tree, { id, keyValuePairs, autoMerge }) {
|
|
1840
|
+
const hasFieldInOrder = tree.order.has(id);
|
|
1841
|
+
if (!hasFieldInOrder) {
|
|
1842
|
+
throw new MutationError(`Field ${id} doesn't exist on the tree`);
|
|
1843
|
+
}
|
|
1844
|
+
const existingField = tree.fields.get(id);
|
|
1845
|
+
if (!existingField || !(existingField instanceof FieldClass)) {
|
|
1846
|
+
throw new MutationPrototypeError(existingField?.name ?? id);
|
|
1847
|
+
}
|
|
1848
|
+
const currentField = existingField.getCurrentFieldObject();
|
|
1849
|
+
const updatedField = this.deepObjectUpdate(currentField, {
|
|
1850
|
+
keyValuePairs,
|
|
1851
|
+
autoMerge,
|
|
1852
|
+
id
|
|
1853
|
+
});
|
|
1854
|
+
if (updatedField === currentField)
|
|
1855
|
+
return tree;
|
|
1856
|
+
const fields = new Map(tree.fields);
|
|
1857
|
+
fields.set(id, new FieldClass(updatedField));
|
|
1858
|
+
return {
|
|
1859
|
+
...tree,
|
|
1860
|
+
fields
|
|
1861
|
+
};
|
|
1862
|
+
}
|
|
1863
|
+
canMerge(autoMerge, value, current) {
|
|
1864
|
+
if (!autoMerge)
|
|
1865
|
+
return false;
|
|
1866
|
+
if (current === undefined || current === null)
|
|
1867
|
+
return false;
|
|
1868
|
+
if (Array.isArray(value))
|
|
1869
|
+
return Array.isArray(current);
|
|
1870
|
+
if (UTILS.isPlainObject(value))
|
|
1871
|
+
return UTILS.isPlainObject(current);
|
|
1872
|
+
return false;
|
|
1873
|
+
}
|
|
1874
|
+
mergeValues(current, value) {
|
|
1875
|
+
if (Array.isArray(current)) {
|
|
1876
|
+
const incoming = value;
|
|
1877
|
+
return incoming.length === 0 ? current : [...current, ...incoming];
|
|
1878
|
+
}
|
|
1879
|
+
const cur = current;
|
|
1880
|
+
const inc = value;
|
|
1881
|
+
const unchanged = Object.keys(inc).every((k) => Object.is(cur[k], inc[k]));
|
|
1882
|
+
return unchanged ? current : { ...cur, ...inc };
|
|
1883
|
+
}
|
|
1884
|
+
setIn(obj, path, value, autoMerge) {
|
|
1885
|
+
const [head, ...rest] = path;
|
|
1886
|
+
const current = obj?.[head];
|
|
1887
|
+
let next;
|
|
1888
|
+
if (rest.length === 0) {
|
|
1889
|
+
next = this.canMerge(autoMerge, value, current) ? this.mergeValues(current, value) : value;
|
|
1890
|
+
} else {
|
|
1891
|
+
next = this.setIn(UTILS.isPlainObject(current) ? current : {}, rest, value, autoMerge);
|
|
1892
|
+
}
|
|
1893
|
+
if (Object.is(next, current))
|
|
1894
|
+
return obj;
|
|
1895
|
+
return Array.isArray(obj) ? Object.assign([...obj], { [head]: next }) : { ...obj, [head]: next };
|
|
1896
|
+
}
|
|
1897
|
+
deepObjectUpdate(obj, { keyValuePairs, autoMerge = true }) {
|
|
1898
|
+
let result = obj;
|
|
1899
|
+
for (const [key, value] of UTILS.ObjectEntries(keyValuePairs)) {
|
|
1900
|
+
const path = key.split(".");
|
|
1901
|
+
if (path.some((p) => FORBIDDEN.has(p))) {
|
|
1902
|
+
throw new MutationError(`Forbidden key "${key}"`);
|
|
1903
|
+
}
|
|
1904
|
+
result = this.setIn(result, path, value, autoMerge);
|
|
1905
|
+
}
|
|
1906
|
+
return result;
|
|
1907
|
+
}
|
|
1908
|
+
mutateContainer(tree, { keyValuePairs, id, autoMerge = true }) {
|
|
1909
|
+
if (!tree.order.has(id)) {
|
|
1910
|
+
throw new MutationError(`Container ${id} doesn't exist on the tree`);
|
|
1911
|
+
}
|
|
1912
|
+
const existingContainer = tree.containers.get(id);
|
|
1913
|
+
if (!existingContainer || !(existingContainer instanceof ContainerClass)) {
|
|
1914
|
+
throw new MutationPrototypeError(existingContainer?.name ?? "ContainerNotFound");
|
|
1915
|
+
}
|
|
1916
|
+
const currentContainer = existingContainer.getCurrentContainerObject();
|
|
1917
|
+
const updatedContainer = this.deepObjectUpdate(currentContainer, {
|
|
1918
|
+
keyValuePairs,
|
|
1919
|
+
autoMerge,
|
|
1920
|
+
id
|
|
1921
|
+
});
|
|
1922
|
+
if (currentContainer === updatedContainer)
|
|
1923
|
+
return tree;
|
|
1924
|
+
const containers = new Map(tree.containers);
|
|
1925
|
+
containers.set(id, new ContainerClass(updatedContainer));
|
|
1926
|
+
return {
|
|
1927
|
+
...tree,
|
|
1928
|
+
containers
|
|
1929
|
+
};
|
|
1930
|
+
}
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
// src/services/shortcuts/shortcuts.ts
|
|
1934
|
+
class ShortcutsService {
|
|
1935
|
+
}
|
|
1936
|
+
|
|
1937
|
+
// src/services/state/state.errors.ts
|
|
1938
|
+
class StateError extends Error {
|
|
1939
|
+
constructor(msg) {
|
|
1940
|
+
super(`StateError: ${msg}`);
|
|
1941
|
+
this.name = "StateError";
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
class StateNotFoundError extends StateError {
|
|
1946
|
+
constructor(name2) {
|
|
1947
|
+
super(`State ${name2} not found`);
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
// src/services/state/state.ts
|
|
1952
|
+
class StateService {
|
|
1953
|
+
slices = new Map;
|
|
1954
|
+
listeners = new Map;
|
|
1955
|
+
defineSlice(name2, initialValue) {
|
|
1956
|
+
if (this.slices.has(name2)) {
|
|
1957
|
+
throw new StateError(`${name2} slice already defined`);
|
|
1958
|
+
}
|
|
1959
|
+
this.slices.set(name2, initialValue);
|
|
1960
|
+
return () => {
|
|
1961
|
+
this.slices.delete(name2);
|
|
1962
|
+
this.listeners.delete(name2);
|
|
1963
|
+
};
|
|
1964
|
+
}
|
|
1965
|
+
get(name2) {
|
|
1966
|
+
const state = this.slices.get(name2);
|
|
1967
|
+
if (!state)
|
|
1968
|
+
return;
|
|
1969
|
+
return state;
|
|
1970
|
+
}
|
|
1971
|
+
set(name2, value) {
|
|
1972
|
+
if (!this.slices.has(name2))
|
|
1973
|
+
throw new StateError(`Slice "${String(name2)}" is not defined`);
|
|
1974
|
+
if (value === this.slices.get(name2))
|
|
1975
|
+
return;
|
|
1976
|
+
this.slices.set(name2, value);
|
|
1977
|
+
this.listeners.get(name2)?.forEach((fn) => fn(value));
|
|
1978
|
+
}
|
|
1979
|
+
subscribe(name2, fn) {
|
|
1980
|
+
const set = this.listeners.get(name2) ?? new Set;
|
|
1981
|
+
set.add(fn);
|
|
1982
|
+
this.listeners.set(name2, set);
|
|
1983
|
+
return () => set.delete(fn);
|
|
1984
|
+
}
|
|
1985
|
+
}
|
|
1986
|
+
|
|
1987
|
+
// src/services/text-marks/text-marks.ts
|
|
1988
|
+
class TextMarksService {
|
|
1989
|
+
behaviors = new Map([
|
|
1990
|
+
["bold", { inclusive: true }],
|
|
1991
|
+
["italic", { inclusive: true }],
|
|
1992
|
+
["underline", { inclusive: true }],
|
|
1993
|
+
["code", { inclusive: true }],
|
|
1994
|
+
["link", { inclusive: false }],
|
|
1995
|
+
["initial", { inclusive: false }]
|
|
1996
|
+
]);
|
|
1997
|
+
registerMark(type, behavior = { inclusive: true }) {
|
|
1998
|
+
if (this.behaviors.has(type))
|
|
1999
|
+
throw new Error(`Mark "${type}" is already registered`);
|
|
2000
|
+
this.behaviors.set(type, behavior);
|
|
2001
|
+
return () => {
|
|
2002
|
+
if (this.behaviors.get(type) === behavior)
|
|
2003
|
+
this.behaviors.delete(type);
|
|
2004
|
+
};
|
|
2005
|
+
}
|
|
2006
|
+
isInclusive(type) {
|
|
2007
|
+
return this.behaviors.get(type)?.inclusive ?? true;
|
|
2008
|
+
}
|
|
2009
|
+
attrsKey(attrs) {
|
|
2010
|
+
if (!attrs)
|
|
2011
|
+
return "";
|
|
2012
|
+
const keys = Object.keys(attrs).sort();
|
|
2013
|
+
return keys.length ? JSON.stringify(keys.map((k) => [k, attrs[k]])) : "";
|
|
2014
|
+
}
|
|
2015
|
+
sameMarks(a, b) {
|
|
2016
|
+
return a.length === b.length && a.every((mark, i) => mark.type === b[i].type && mark.start === b[i].start && mark.end === b[i].end && this.attrsKey(mark.attrs) === this.attrsKey(b[i].attrs));
|
|
2017
|
+
}
|
|
2018
|
+
normalizeMarks(marks, textLength) {
|
|
2019
|
+
const groups = new Map;
|
|
2020
|
+
for (const mark of marks) {
|
|
2021
|
+
const start = Math.max(0, Math.min(mark.start, textLength));
|
|
2022
|
+
const end = Math.max(0, Math.min(mark.end, textLength));
|
|
2023
|
+
if (!(start < end))
|
|
2024
|
+
continue;
|
|
2025
|
+
const key = `${mark.type}|${this.attrsKey(mark.attrs)}`;
|
|
2026
|
+
const list = groups.get(key) ?? [];
|
|
2027
|
+
list.push({ ...mark, start, end });
|
|
2028
|
+
groups.set(key, list);
|
|
2029
|
+
}
|
|
2030
|
+
const merged = [];
|
|
2031
|
+
for (const list of groups.values()) {
|
|
2032
|
+
list.sort((a, b) => a.start - b.start);
|
|
2033
|
+
let cur = list[0];
|
|
2034
|
+
for (let i = 1;i < list.length; i++) {
|
|
2035
|
+
const next = list[i];
|
|
2036
|
+
if (next.start <= cur.end) {
|
|
2037
|
+
if (next.end > cur.end)
|
|
2038
|
+
cur = { ...cur, end: next.end };
|
|
2039
|
+
} else {
|
|
2040
|
+
merged.push(cur);
|
|
2041
|
+
cur = next;
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
merged.push(cur);
|
|
2045
|
+
}
|
|
2046
|
+
merged.sort((a, b) => a.start - b.start || a.type.localeCompare(b.type) || a.end - b.end);
|
|
2047
|
+
return this.sameMarks(marks, merged) ? marks : merged;
|
|
2048
|
+
}
|
|
2049
|
+
isFullyMarked(marks, start, end, spec) {
|
|
2050
|
+
const relevant = marks.filter((m) => m.type === spec.type).sort((a, b) => a.start - b.start);
|
|
2051
|
+
let covered = start;
|
|
2052
|
+
for (const mark of relevant) {
|
|
2053
|
+
if (mark.end <= covered)
|
|
2054
|
+
continue;
|
|
2055
|
+
if (mark.start > covered)
|
|
2056
|
+
return false;
|
|
2057
|
+
covered = mark.end;
|
|
2058
|
+
if (covered >= end)
|
|
2059
|
+
return true;
|
|
2060
|
+
}
|
|
2061
|
+
return covered >= end;
|
|
2062
|
+
}
|
|
2063
|
+
removeMark(marks, start, end, type) {
|
|
2064
|
+
const out = [];
|
|
2065
|
+
for (const mark of marks) {
|
|
2066
|
+
if (mark.type !== type || mark.end <= start || mark.start >= end) {
|
|
2067
|
+
out.push(mark);
|
|
2068
|
+
continue;
|
|
2069
|
+
}
|
|
2070
|
+
if (mark.start < start)
|
|
2071
|
+
out.push({ ...mark, end: start });
|
|
2072
|
+
if (mark.end > end)
|
|
2073
|
+
out.push({ ...mark, start: end });
|
|
2074
|
+
}
|
|
2075
|
+
return out;
|
|
2076
|
+
}
|
|
2077
|
+
toggleMark(content, { start, end, spec }) {
|
|
2078
|
+
const len = content.text.length;
|
|
2079
|
+
const s = Math.max(0, Math.min(start, end, len));
|
|
2080
|
+
const e = Math.min(len, Math.max(start, end));
|
|
2081
|
+
if (s >= e)
|
|
2082
|
+
return content;
|
|
2083
|
+
const next = this.isFullyMarked(content.marks, s, e, spec) ? this.removeMark(content.marks, s, e, spec.type) : [
|
|
2084
|
+
...spec.type === "link" ? this.removeMark(content.marks, s, e, "link") : content.marks,
|
|
2085
|
+
{ type: spec.type, start: s, end: e, ...spec.attrs && { attrs: spec.attrs } }
|
|
2086
|
+
];
|
|
2087
|
+
const marks = this.normalizeMarks(next, len);
|
|
2088
|
+
return marks === content.marks ? content : { text: content.text, marks };
|
|
2089
|
+
}
|
|
2090
|
+
deleteRange(content, start, end) {
|
|
2091
|
+
const len = content.text.length;
|
|
2092
|
+
const _start = Math.max(0, Math.min(start, end, len));
|
|
2093
|
+
const _end = Math.min(len, Math.max(start, end));
|
|
2094
|
+
if (_start >= _end)
|
|
2095
|
+
return content;
|
|
2096
|
+
const diff = _end - _start;
|
|
2097
|
+
const map = (p) => p <= _start ? p : p >= _end ? p - diff : _end;
|
|
2098
|
+
const newText = content.text.slice(0, _start) + content.text.slice(_end);
|
|
2099
|
+
const marks = content.marks.map((mark) => ({
|
|
2100
|
+
...mark,
|
|
2101
|
+
start: map(mark.start),
|
|
2102
|
+
end: map(mark.end)
|
|
2103
|
+
}));
|
|
2104
|
+
return { text: newText, marks: this.normalizeMarks(marks, newText.length) };
|
|
2105
|
+
}
|
|
2106
|
+
insertText(content, at, text, opts = {}) {
|
|
2107
|
+
if (text.length === 0)
|
|
2108
|
+
return content;
|
|
2109
|
+
const len = content.text.length;
|
|
2110
|
+
const pos = Math.max(0, Math.min(at, len));
|
|
2111
|
+
const n = text.length;
|
|
2112
|
+
let marks = content.marks.map((mark) => {
|
|
2113
|
+
if (mark.start >= pos)
|
|
2114
|
+
return { ...mark, start: mark.start + n, end: mark.end + n };
|
|
2115
|
+
if (mark.end > pos)
|
|
2116
|
+
return { ...mark, end: mark.end + n };
|
|
2117
|
+
if (mark.end === pos && this.isInclusive(mark.type))
|
|
2118
|
+
return { ...mark, end: mark.end + n };
|
|
2119
|
+
return mark;
|
|
2120
|
+
});
|
|
2121
|
+
if (opts.marks) {
|
|
2122
|
+
const types = new Set([
|
|
2123
|
+
...marks.map((mark) => mark.type),
|
|
2124
|
+
...opts.marks.map((spec) => spec.type)
|
|
2125
|
+
]);
|
|
2126
|
+
for (const type of types)
|
|
2127
|
+
marks = this.removeMark(marks, pos, pos + n, type);
|
|
2128
|
+
for (const spec of opts.marks) {
|
|
2129
|
+
marks.push({
|
|
2130
|
+
type: spec.type,
|
|
2131
|
+
start: pos,
|
|
2132
|
+
end: pos + n,
|
|
2133
|
+
...spec.attrs && { attrs: spec.attrs }
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
const newText = content.text.slice(0, pos) + text + content.text.slice(pos);
|
|
2138
|
+
return { text: newText, marks: this.normalizeMarks(marks, newText.length) };
|
|
2139
|
+
}
|
|
2140
|
+
replaceRange(content, start, end, text, opts) {
|
|
2141
|
+
const s = Math.min(start, end);
|
|
2142
|
+
return this.insertText(this.deleteRange(content, start, end), s, text, opts);
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
// src/services/ui/ui.errors.ts
|
|
2147
|
+
class UiError extends Error {
|
|
2148
|
+
constructor(message) {
|
|
2149
|
+
super(`UIError: ${message}`);
|
|
2150
|
+
this.name = "UIError";
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
2153
|
+
|
|
2154
|
+
// src/services/ui/ui.ts
|
|
2155
|
+
import { cn } from "cn";
|
|
2156
|
+
|
|
2157
|
+
// src/services/ui/contributions.types.ts
|
|
2158
|
+
var defineButton = (c) => c;
|
|
2159
|
+
var defineComponent = (c) => c;
|
|
2160
|
+
// src/services/ui/ui.ts
|
|
2161
|
+
class UiService {
|
|
2162
|
+
commands;
|
|
2163
|
+
styles = new Map;
|
|
2164
|
+
outdatedStyles = new Map;
|
|
2165
|
+
bySlot = new Map;
|
|
2166
|
+
listeners = new Map;
|
|
2167
|
+
interceptors = new Map;
|
|
2168
|
+
constructor(commands) {
|
|
2169
|
+
this.commands = commands;
|
|
2170
|
+
for (const [key, value] of UTILS.ObjectEntries(DEFAULT_STYLES)) {
|
|
2171
|
+
this.styles.set(key, value);
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
interceptPayload(contributionId, fn) {
|
|
2175
|
+
const list = this.interceptors.get(contributionId) ?? [];
|
|
2176
|
+
this.interceptors.set(contributionId, [...list, fn]);
|
|
2177
|
+
return () => this.interceptors.set(contributionId, (this.interceptors.get(contributionId) ?? []).filter((i) => i !== fn));
|
|
2178
|
+
}
|
|
2179
|
+
async runContribution(c, ui2) {
|
|
2180
|
+
let payload = c.getPayload(ui2);
|
|
2181
|
+
for (const intercept of this.interceptors.get(c.id) ?? []) {
|
|
2182
|
+
const next = await intercept(payload, ui2);
|
|
2183
|
+
if (next === null)
|
|
2184
|
+
return;
|
|
2185
|
+
payload = next;
|
|
2186
|
+
}
|
|
2187
|
+
this.commands.execute(c.command, payload);
|
|
2188
|
+
}
|
|
2189
|
+
contribute(c) {
|
|
2190
|
+
const slotName = c.slot;
|
|
2191
|
+
const prevContribution = this.bySlot.get(slotName) ?? [];
|
|
2192
|
+
if (prevContribution.some((x) => x.id === c.id)) {
|
|
2193
|
+
throw new UiError(`Contribution with id ${c.id} already exists`);
|
|
2194
|
+
}
|
|
2195
|
+
this.bySlot.set(slotName, [...prevContribution, c]);
|
|
2196
|
+
return () => {
|
|
2197
|
+
const current = this.bySlot.get(slotName) ?? [];
|
|
2198
|
+
this.bySlot.set(slotName, current.filter((x) => x.id !== c.id));
|
|
2199
|
+
this.notify(c.slot);
|
|
2200
|
+
};
|
|
2201
|
+
}
|
|
2202
|
+
getSlots(slot) {
|
|
2203
|
+
return this.bySlot.get(slot) ?? EMPTY;
|
|
2204
|
+
}
|
|
2205
|
+
subscribe(slot, fn) {
|
|
2206
|
+
const set = this.listeners.get(slot) ?? new Set;
|
|
2207
|
+
set.add(fn);
|
|
2208
|
+
this.listeners.set(slot, set);
|
|
2209
|
+
return () => set.delete(fn);
|
|
2210
|
+
}
|
|
2211
|
+
notify(slot) {
|
|
2212
|
+
this.listeners.get(slot)?.forEach((fn) => fn());
|
|
2213
|
+
}
|
|
2214
|
+
registerStyle(styleName, style) {
|
|
2215
|
+
const prevStyle = this.styles.get(styleName);
|
|
2216
|
+
if (prevStyle) {
|
|
2217
|
+
console.log(`[WARN]: Overwritting ${name} styles`);
|
|
2218
|
+
this.outdatedStyles.set(styleName, prevStyle);
|
|
2219
|
+
}
|
|
2220
|
+
this.styles.set(styleName, style);
|
|
2221
|
+
return () => {
|
|
2222
|
+
this.styles.set(styleName, this.outdatedStyles.get(styleName) ?? DEFAULT_STYLES[styleName]);
|
|
2223
|
+
this.outdatedStyles.delete(styleName);
|
|
2224
|
+
};
|
|
2225
|
+
}
|
|
2226
|
+
patchStyle(styleName, style) {
|
|
2227
|
+
const prevStyle = this.styles.get(styleName) ?? { style: {}, pseudoStyle: {} };
|
|
2228
|
+
this.outdatedStyles.set(styleName, prevStyle);
|
|
2229
|
+
this.styles.set(styleName, {
|
|
2230
|
+
style: {
|
|
2231
|
+
...prevStyle.style,
|
|
2232
|
+
...style.style
|
|
2233
|
+
},
|
|
2234
|
+
pseudoStyle: {
|
|
2235
|
+
...prevStyle.pseudoStyle,
|
|
2236
|
+
...style.pseudoStyle
|
|
2237
|
+
},
|
|
2238
|
+
className: cn(prevStyle.className, style.className)
|
|
2239
|
+
});
|
|
2240
|
+
return () => {
|
|
2241
|
+
this.styles.set(styleName, this.outdatedStyles.get(styleName) ?? DEFAULT_STYLES[styleName]);
|
|
2242
|
+
this.outdatedStyles.delete(styleName);
|
|
2243
|
+
};
|
|
2244
|
+
}
|
|
2245
|
+
getStyle(styleName) {
|
|
2246
|
+
return this.styles.get(styleName);
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
var EMPTY = [];
|
|
2250
|
+
|
|
2251
|
+
// src/services/tasks/tasks.service.ts
|
|
2252
|
+
var DEFAULT_TASK_STATE = Object.freeze({
|
|
2253
|
+
status: "idle",
|
|
2254
|
+
isPending: false,
|
|
2255
|
+
isRunning: false,
|
|
2256
|
+
isIdle: true,
|
|
2257
|
+
lastExecutedAt: undefined,
|
|
2258
|
+
error: null,
|
|
2259
|
+
taskId: "default"
|
|
2260
|
+
});
|
|
2261
|
+
|
|
2262
|
+
class TasksService {
|
|
2263
|
+
pendingTasks = new Map;
|
|
2264
|
+
states = new Map;
|
|
2265
|
+
listeners = new Map;
|
|
2266
|
+
setState(name2, partial) {
|
|
2267
|
+
const key = name2;
|
|
2268
|
+
const prev = this.states.get(key) || DEFAULT_TASK_STATE;
|
|
2269
|
+
const status = partial.status ?? prev.status;
|
|
2270
|
+
const next = Object.freeze({
|
|
2271
|
+
...prev,
|
|
2272
|
+
...partial,
|
|
2273
|
+
status,
|
|
2274
|
+
isPending: status === "pending",
|
|
2275
|
+
isRunning: status === "running",
|
|
2276
|
+
isIdle: status === "idle"
|
|
2277
|
+
});
|
|
2278
|
+
this.states.set(key, next);
|
|
2279
|
+
this.notify(name2, next);
|
|
2280
|
+
}
|
|
2281
|
+
notify(name2, state) {
|
|
2282
|
+
const key = name2;
|
|
2283
|
+
const set = this.listeners.get(key);
|
|
2284
|
+
if (set) {
|
|
2285
|
+
for (const listener of set) {
|
|
2286
|
+
try {
|
|
2287
|
+
listener(state);
|
|
2288
|
+
} catch (err) {
|
|
2289
|
+
console.error(`[TasksService] Listener error for task "${key}":`, err);
|
|
2290
|
+
}
|
|
2291
|
+
}
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
getState(name2) {
|
|
2295
|
+
const key = name2;
|
|
2296
|
+
return this.states.get(key) || DEFAULT_TASK_STATE;
|
|
2297
|
+
}
|
|
2298
|
+
getStatus(name2) {
|
|
2299
|
+
return this.getState(name2).status;
|
|
2300
|
+
}
|
|
2301
|
+
isPending(name2) {
|
|
2302
|
+
return this.getState(name2).isPending;
|
|
2303
|
+
}
|
|
2304
|
+
isRunning(name2) {
|
|
2305
|
+
return this.getState(name2).isRunning;
|
|
2306
|
+
}
|
|
2307
|
+
subscribe(name2, fn) {
|
|
2308
|
+
const key = name2;
|
|
2309
|
+
let set = this.listeners.get(key);
|
|
2310
|
+
if (!set) {
|
|
2311
|
+
set = new Set;
|
|
2312
|
+
this.listeners.set(key, set);
|
|
2313
|
+
}
|
|
2314
|
+
set.add(fn);
|
|
2315
|
+
return () => {
|
|
2316
|
+
const currentSet = this.listeners.get(key);
|
|
2317
|
+
if (currentSet) {
|
|
2318
|
+
currentSet.delete(fn);
|
|
2319
|
+
if (currentSet.size === 0) {
|
|
2320
|
+
this.listeners.delete(key);
|
|
2321
|
+
}
|
|
2322
|
+
}
|
|
2323
|
+
};
|
|
2324
|
+
}
|
|
2325
|
+
schedule(name2, delay, fn, taskId) {
|
|
2326
|
+
const key = name2;
|
|
2327
|
+
const existing = this.pendingTasks.get(key);
|
|
2328
|
+
if (existing) {
|
|
2329
|
+
clearTimeout(existing.timerId);
|
|
2330
|
+
this.pendingTasks.delete(key);
|
|
2331
|
+
}
|
|
2332
|
+
this.setState(name2, {
|
|
2333
|
+
status: "pending",
|
|
2334
|
+
error: null
|
|
2335
|
+
});
|
|
2336
|
+
const timerId = setTimeout(async () => {
|
|
2337
|
+
this.pendingTasks.delete(key);
|
|
2338
|
+
await this.executeTask(name2, fn);
|
|
2339
|
+
}, delay);
|
|
2340
|
+
this.pendingTasks.set(key, {
|
|
2341
|
+
name: name2,
|
|
2342
|
+
fn,
|
|
2343
|
+
delay,
|
|
2344
|
+
timerId,
|
|
2345
|
+
taskId: taskId ?? UTILS.generateId("task")
|
|
2346
|
+
});
|
|
2347
|
+
return () => {
|
|
2348
|
+
const current = this.pendingTasks.get(key);
|
|
2349
|
+
if (current && current.timerId === timerId) {
|
|
2350
|
+
clearTimeout(timerId);
|
|
2351
|
+
this.pendingTasks.delete(key);
|
|
2352
|
+
this.setState(name2, { status: "idle" });
|
|
2353
|
+
}
|
|
2354
|
+
};
|
|
2355
|
+
}
|
|
2356
|
+
async executeTask(name2, fn) {
|
|
2357
|
+
this.setState(name2, {
|
|
2358
|
+
status: "running"
|
|
2359
|
+
});
|
|
2360
|
+
let executionError = null;
|
|
2361
|
+
try {
|
|
2362
|
+
await fn();
|
|
2363
|
+
} catch (err) {
|
|
2364
|
+
executionError = err instanceof Error ? err : new Error(String(err));
|
|
2365
|
+
console.error(`[TasksService] Error executing task "${String(name2)}":`, err);
|
|
2366
|
+
} finally {
|
|
2367
|
+
this.setState(name2, {
|
|
2368
|
+
status: "idle",
|
|
2369
|
+
lastExecutedAt: Date.now(),
|
|
2370
|
+
error: executionError
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2373
|
+
}
|
|
2374
|
+
cancel(name2) {
|
|
2375
|
+
const key = name2;
|
|
2376
|
+
const existing = this.pendingTasks.get(key);
|
|
2377
|
+
if (!existing)
|
|
2378
|
+
return false;
|
|
2379
|
+
clearTimeout(existing.timerId);
|
|
2380
|
+
this.pendingTasks.delete(key);
|
|
2381
|
+
this.setState(name2, { status: "idle" });
|
|
2382
|
+
return true;
|
|
2383
|
+
}
|
|
2384
|
+
async flush(name2) {
|
|
2385
|
+
const key = name2;
|
|
2386
|
+
const existing = this.pendingTasks.get(key);
|
|
2387
|
+
if (!existing)
|
|
2388
|
+
return;
|
|
2389
|
+
clearTimeout(existing.timerId);
|
|
2390
|
+
this.pendingTasks.delete(key);
|
|
2391
|
+
await this.executeTask(name2, existing.fn);
|
|
2392
|
+
}
|
|
2393
|
+
cancelAll() {
|
|
2394
|
+
for (const record of this.pendingTasks.values()) {
|
|
2395
|
+
clearTimeout(record.timerId);
|
|
2396
|
+
this.setState(record.name, { status: "idle" });
|
|
2397
|
+
}
|
|
2398
|
+
this.pendingTasks.clear();
|
|
2399
|
+
}
|
|
2400
|
+
dispose() {
|
|
2401
|
+
this.cancelAll();
|
|
2402
|
+
this.listeners.clear();
|
|
2403
|
+
this.states.clear();
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2406
|
+
|
|
2407
|
+
// src/engine/engine.ts
|
|
2408
|
+
class Engine {
|
|
2409
|
+
events = new EventBusService;
|
|
2410
|
+
state = new StateService;
|
|
2411
|
+
document = new DocumentService(this.state, this.events);
|
|
2412
|
+
commands = new CommandsBusService;
|
|
2413
|
+
shortcuts = new ShortcutsService;
|
|
2414
|
+
mutations = new MutationsService;
|
|
2415
|
+
ui = new UiService(this.commands);
|
|
2416
|
+
text = new TextMarksService;
|
|
2417
|
+
tasks = new TasksService;
|
|
2418
|
+
modules = new ModuleManager(this);
|
|
2419
|
+
}
|
|
2420
|
+
// src/modules/insertion/insertion.module.ts
|
|
2421
|
+
var ActionsOpenerContribution = {
|
|
2422
|
+
id: "insert-field",
|
|
2423
|
+
slot: "block-actions",
|
|
2424
|
+
order: 0,
|
|
2425
|
+
kind: "button",
|
|
2426
|
+
command: "actions.toggle",
|
|
2427
|
+
icon: "PlusIcon",
|
|
2428
|
+
getPayload: () => true,
|
|
2429
|
+
name: "BlockActionButton",
|
|
2430
|
+
getProps() {
|
|
2431
|
+
return { variant: "secondary", size: "icon-lg", isBaseButton: true };
|
|
2432
|
+
},
|
|
2433
|
+
when() {
|
|
2434
|
+
return true;
|
|
2435
|
+
}
|
|
2436
|
+
};
|
|
2437
|
+
var InsertionModule = {
|
|
2438
|
+
name: "insertion",
|
|
2439
|
+
version: "1.0.0",
|
|
2440
|
+
requires: [],
|
|
2441
|
+
install(ctx) {
|
|
2442
|
+
ctx.state.defineSlice("insertion", false);
|
|
2443
|
+
ctx.commands.register("actions.toggle", (isOpen) => {
|
|
2444
|
+
ctx.state.set("insertion", isOpen);
|
|
2445
|
+
ctx.events.emit("actions:toggle", isOpen);
|
|
2446
|
+
});
|
|
2447
|
+
ctx.commands.register("fields.change", ({ fieldId, type }) => {
|
|
2448
|
+
ctx.document.apply((tree) => ctx.mutations.changeField(tree, { fieldId, type }), { origin: isMediaType(type) ? "history" : "user" });
|
|
2449
|
+
ctx.state.set("insertion", false);
|
|
2450
|
+
ctx.events.emit("fields:change", { fieldId, type });
|
|
2451
|
+
});
|
|
2452
|
+
ctx.commands.register("blocks.insert", ({ block, pos }) => {
|
|
2453
|
+
const isNotMedia = block.type !== "image" && block.type !== "video";
|
|
2454
|
+
const hasSrcInProps = "src" in block.props && !!block.props.src.trim();
|
|
2455
|
+
const shouldEmitEvent = isNotMedia || hasSrcInProps;
|
|
2456
|
+
ctx.document.apply((tree) => {
|
|
2457
|
+
if (block.variant === "field") {
|
|
2458
|
+
return ctx.mutations.insertField(tree, block, pos);
|
|
2459
|
+
}
|
|
2460
|
+
return tree;
|
|
2461
|
+
}, { shouldEmitEvent });
|
|
2462
|
+
ctx.state.set("insertion", false);
|
|
2463
|
+
ctx.events.emit("blocks:insert", { block, pos });
|
|
2464
|
+
});
|
|
2465
|
+
ctx.commands.register("blocks.delete", ({ blockId }) => {
|
|
2466
|
+
const isFieldBlock = blockId.startsWith("field:");
|
|
2467
|
+
if (!isFieldBlock)
|
|
2468
|
+
return;
|
|
2469
|
+
ctx.document.apply((tree) => ctx.mutations.deleteField(tree, blockId));
|
|
2470
|
+
ctx.events.emit("blocks:delete", { blockId });
|
|
2471
|
+
});
|
|
2472
|
+
function actionButton(id, type, icon, order) {
|
|
2473
|
+
ctx.ui.contribute(defineButton({
|
|
2474
|
+
id,
|
|
2475
|
+
order,
|
|
2476
|
+
icon,
|
|
2477
|
+
kind: "button",
|
|
2478
|
+
slot: "block-actions",
|
|
2479
|
+
command: "fields.change",
|
|
2480
|
+
name: "BlockActionButton",
|
|
2481
|
+
getProps() {
|
|
2482
|
+
return { variant: "secondary", size: "icon-sm" };
|
|
2483
|
+
},
|
|
2484
|
+
getPayload: () => {
|
|
2485
|
+
const focus = ctx.state.get("focus_memory")?.blocks?.[0];
|
|
2486
|
+
if (!focus) {
|
|
2487
|
+
throw new Error("Empty focus memory...");
|
|
2488
|
+
}
|
|
2489
|
+
return { fieldId: focus.id, type };
|
|
2490
|
+
},
|
|
2491
|
+
when() {
|
|
2492
|
+
return true;
|
|
2493
|
+
}
|
|
2494
|
+
}));
|
|
2495
|
+
}
|
|
2496
|
+
ctx.ui.contribute({
|
|
2497
|
+
...ActionsOpenerContribution,
|
|
2498
|
+
getPayload: () => !ctx.state.get("insertion")
|
|
2499
|
+
});
|
|
2500
|
+
actionButton("insert-heading", "heading", "HeadingIcon", 1);
|
|
2501
|
+
actionButton("insert-text", "text", "TextIcon", 2);
|
|
2502
|
+
actionButton("insert-image", "image", "ImagePlus", 3);
|
|
2503
|
+
actionButton("insert-video", "video", "TvMinimalPlayIcon", 4);
|
|
2504
|
+
actionButton("insert-iframe", "iframe", "YoutubeIcon", 5);
|
|
2505
|
+
actionButton("insert-doc", "link", "FileTextIcon", 6);
|
|
2506
|
+
actionButton("insert-blockquote", "blockquote", "QuoteIcon", 7);
|
|
2507
|
+
actionButton("insert-code", "code", "CodeIcon", 8);
|
|
2508
|
+
actionButton("insert-divider", "divider", "DividerIcon", 9);
|
|
2509
|
+
}
|
|
2510
|
+
};
|
|
2511
|
+
// src/modules/editor/editor.module.ts
|
|
2512
|
+
var MIN_SIZE = 16;
|
|
2513
|
+
function overlayPositionFromBlockRects(rects, editorRect) {
|
|
2514
|
+
if (!editorRect || rects.length === 0)
|
|
2515
|
+
return null;
|
|
2516
|
+
const top = Math.min(...rects.map((rect) => rect.top));
|
|
2517
|
+
const left = Math.min(...rects.map((rect) => rect.left));
|
|
2518
|
+
const bottom = Math.max(...rects.map((rect) => rect.bottom));
|
|
2519
|
+
const right = Math.max(...rects.map((rect) => rect.right));
|
|
2520
|
+
const scrollTop = rects[0].parentScrollTop;
|
|
2521
|
+
const scrollLeft = rects[0].parentScrollLeft;
|
|
2522
|
+
const width = right - left;
|
|
2523
|
+
const height = bottom - top;
|
|
2524
|
+
return {
|
|
2525
|
+
top: top - editorRect.top - editorRect.clientTop + scrollTop - (height < MIN_SIZE ? MIN_SIZE / 2 : 0),
|
|
2526
|
+
left: left - editorRect.left - editorRect.clientLeft + scrollLeft - (width < MIN_SIZE ? MIN_SIZE / 2 : 0),
|
|
2527
|
+
width: width < MIN_SIZE ? MIN_SIZE : width,
|
|
2528
|
+
height: height < MIN_SIZE ? MIN_SIZE : height
|
|
2529
|
+
};
|
|
2530
|
+
}
|
|
2531
|
+
var EditorModule = {
|
|
2532
|
+
name: "editor",
|
|
2533
|
+
version: "1.0.0",
|
|
2534
|
+
requires: [],
|
|
2535
|
+
install(ctx) {
|
|
2536
|
+
ctx.state.defineSlice("editor", { editorRect: null });
|
|
2537
|
+
ctx.commands.register("editor.rect", ({ editorRect }) => {
|
|
2538
|
+
const prevState = ctx.state.get("editor");
|
|
2539
|
+
if (editorRect === null) {
|
|
2540
|
+
if (prevState?.editorRect === null)
|
|
2541
|
+
return;
|
|
2542
|
+
ctx.state.set("editor", { editorRect });
|
|
2543
|
+
ctx.events.emit("editor:rect", { editorRect });
|
|
2544
|
+
return;
|
|
2545
|
+
}
|
|
2546
|
+
if (!prevState) {
|
|
2547
|
+
return;
|
|
2548
|
+
}
|
|
2549
|
+
if (prevState.editorRect === null) {
|
|
2550
|
+
ctx.state.set("editor", { editorRect });
|
|
2551
|
+
ctx.events.emit("editor:rect", { editorRect });
|
|
2552
|
+
return;
|
|
2553
|
+
}
|
|
2554
|
+
const areSame = areObjectsTheSame(prevState.editorRect, editorRect);
|
|
2555
|
+
if (!areSame) {
|
|
2556
|
+
ctx.state.set("editor", { editorRect });
|
|
2557
|
+
ctx.events.emit("editor:rect", { editorRect });
|
|
2558
|
+
}
|
|
2559
|
+
});
|
|
2560
|
+
}
|
|
2561
|
+
};
|
|
2562
|
+
|
|
2563
|
+
// src/modules/selection/selection.module.ts
|
|
2564
|
+
function compute(prev, incoming, mode) {
|
|
2565
|
+
switch (mode) {
|
|
2566
|
+
case "replace":
|
|
2567
|
+
return new Map(incoming);
|
|
2568
|
+
case "add":
|
|
2569
|
+
return new Map([...prev, ...incoming]);
|
|
2570
|
+
case "remove": {
|
|
2571
|
+
const result = new Map(prev);
|
|
2572
|
+
for (const id of incoming.keys()) {
|
|
2573
|
+
result.delete(id);
|
|
2574
|
+
}
|
|
2575
|
+
return result;
|
|
2576
|
+
}
|
|
2577
|
+
case "toggle": {
|
|
2578
|
+
const result = new Map(prev);
|
|
2579
|
+
for (const [id, rect] of incoming) {
|
|
2580
|
+
if (result.has(id)) {
|
|
2581
|
+
result.delete(id);
|
|
2582
|
+
} else {
|
|
2583
|
+
result.set(id, rect);
|
|
2584
|
+
}
|
|
2585
|
+
}
|
|
2586
|
+
return result;
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2590
|
+
function sameBlocks(a, b) {
|
|
2591
|
+
if (a.size !== b.size)
|
|
2592
|
+
return false;
|
|
2593
|
+
for (const [id, rectA] of a.entries()) {
|
|
2594
|
+
const rectB = b.get(id);
|
|
2595
|
+
if (!rectB)
|
|
2596
|
+
return false;
|
|
2597
|
+
for (const key in rectA) {
|
|
2598
|
+
if (Object.prototype.hasOwnProperty.call(rectA, key)) {
|
|
2599
|
+
if (rectA[key] !== rectB[key]) {
|
|
2600
|
+
return false;
|
|
2601
|
+
}
|
|
2602
|
+
}
|
|
2603
|
+
}
|
|
2604
|
+
}
|
|
2605
|
+
return true;
|
|
2606
|
+
}
|
|
2607
|
+
function selectionOverlayPropsFromUICtx(ui4, editorRect, order) {
|
|
2608
|
+
const rects = Array.from(ui4?.selection?.blocks?.entries() ?? []).map(([id, rect]) => order.has(id) ? rect : null).filter(Boolean);
|
|
2609
|
+
return overlayPositionFromBlockRects(rects, editorRect);
|
|
2610
|
+
}
|
|
2611
|
+
var SelectionModule = {
|
|
2612
|
+
name: "selection",
|
|
2613
|
+
version: "1.0.0",
|
|
2614
|
+
requires: [],
|
|
2615
|
+
install(ctx) {
|
|
2616
|
+
ctx.state.defineSlice("selection", { blocks: new Map });
|
|
2617
|
+
ctx.ui.contribute(defineComponent({
|
|
2618
|
+
id: "selection-overlay",
|
|
2619
|
+
slot: "overlay",
|
|
2620
|
+
order: 1000,
|
|
2621
|
+
kind: "component",
|
|
2622
|
+
name: "SelectionOverlay",
|
|
2623
|
+
when: (ui4) => ui4.selection.blocks.size > 0,
|
|
2624
|
+
getProps: (ui4) => {
|
|
2625
|
+
const editorState = ctx.state.get("editor") ?? { editorRect: null };
|
|
2626
|
+
const position = selectionOverlayPropsFromUICtx(ui4, editorState?.editorRect, ctx.document.get().order);
|
|
2627
|
+
return {
|
|
2628
|
+
position,
|
|
2629
|
+
hidden: !Array.from(ui4.selection.blocks.keys()).length || !position
|
|
2630
|
+
};
|
|
2631
|
+
}
|
|
2632
|
+
}));
|
|
2633
|
+
const apply = (next) => {
|
|
2634
|
+
const previous = ctx.state.get("selection").blocks;
|
|
2635
|
+
if (sameBlocks(previous, next))
|
|
2636
|
+
return;
|
|
2637
|
+
ctx.state.set("selection", { blocks: next });
|
|
2638
|
+
ctx.events.emit("selection:changed", { blocks: next, previous });
|
|
2639
|
+
};
|
|
2640
|
+
ctx.commands.register("blocks.select", ({ blocks, mode = "replace" }) => {
|
|
2641
|
+
const validBlocks = new Map;
|
|
2642
|
+
for (const [id, rect] of blocks) {
|
|
2643
|
+
if (ctx.document.has(id)) {
|
|
2644
|
+
validBlocks.set(id, rect);
|
|
2645
|
+
}
|
|
2646
|
+
}
|
|
2647
|
+
const prev = ctx.state.get("selection").blocks;
|
|
2648
|
+
apply(compute(prev, validBlocks, mode));
|
|
2649
|
+
});
|
|
2650
|
+
ctx.commands.register("blocks.clearSelection", () => apply(new Map));
|
|
2651
|
+
}
|
|
2652
|
+
};
|
|
2653
|
+
// src/modules/focus/focus.module.ts
|
|
2654
|
+
import _2 from "lodash";
|
|
2655
|
+
function focusOverlayPropsFromUICtx(ui4, editorRect) {
|
|
2656
|
+
const rect = ui4.focus?.rect;
|
|
2657
|
+
if (!rect)
|
|
2658
|
+
return null;
|
|
2659
|
+
return overlayPositionFromBlockRects([rect], editorRect);
|
|
2660
|
+
}
|
|
2661
|
+
var FocusModule = {
|
|
2662
|
+
name: "focus",
|
|
2663
|
+
version: "1.0.0",
|
|
2664
|
+
requires: ["selection"],
|
|
2665
|
+
install(ctx) {
|
|
2666
|
+
ctx.state.defineSlice("focus", null);
|
|
2667
|
+
ctx.state.defineSlice("focus_memory", { blocks: [], count: 3 });
|
|
2668
|
+
ctx.ui.contribute(defineComponent({
|
|
2669
|
+
id: "focus-overlay",
|
|
2670
|
+
slot: "overlay",
|
|
2671
|
+
order: 1001,
|
|
2672
|
+
kind: "component",
|
|
2673
|
+
name: "FocusOverlay",
|
|
2674
|
+
when: (ui4) => !!ui4.focus?.id,
|
|
2675
|
+
getProps: (ui4) => {
|
|
2676
|
+
const editorState = ctx.state.get("editor") ?? { editorRect: null };
|
|
2677
|
+
const position = focusOverlayPropsFromUICtx(ui4, editorState?.editorRect);
|
|
2678
|
+
const document = ctx.state.get("document");
|
|
2679
|
+
return {
|
|
2680
|
+
position,
|
|
2681
|
+
hidden: !ui4.focus?.id || !position || !document?.order.has(ui4?.focus?.id)
|
|
2682
|
+
};
|
|
2683
|
+
}
|
|
2684
|
+
}));
|
|
2685
|
+
ctx.commands.register("blocks.focus", (payload) => {
|
|
2686
|
+
const { id: focusedId = null, rect = null } = payload ?? {};
|
|
2687
|
+
const prev = ctx.state.get("focus");
|
|
2688
|
+
if (focusedId !== null && !ctx.document.has(focusedId))
|
|
2689
|
+
return;
|
|
2690
|
+
if (focusedId === prev?.id && _2.isEqual(rect, prev.rect))
|
|
2691
|
+
return;
|
|
2692
|
+
const prevFocusedId = prev?.id;
|
|
2693
|
+
const shouldUnfocusPrev = Boolean(prevFocusedId && prevFocusedId !== focusedId && (() => {
|
|
2694
|
+
const b = ctx.document.getBlock(prevFocusedId);
|
|
2695
|
+
return b && isEditableField(b);
|
|
2696
|
+
})());
|
|
2697
|
+
const shouldFocusCurrent = Boolean(focusedId && (() => {
|
|
2698
|
+
const b = ctx.document.getBlock(focusedId);
|
|
2699
|
+
return b && isEditableField(b);
|
|
2700
|
+
})());
|
|
2701
|
+
if (shouldUnfocusPrev || shouldFocusCurrent) {
|
|
2702
|
+
ctx.document.apply((tree) => {
|
|
2703
|
+
let nextTree = tree;
|
|
2704
|
+
if (shouldUnfocusPrev && prevFocusedId) {
|
|
2705
|
+
nextTree = ctx.mutations.mutateField(nextTree, {
|
|
2706
|
+
keyValuePairs: {
|
|
2707
|
+
"props.contentEditable": false
|
|
2708
|
+
},
|
|
2709
|
+
id: prevFocusedId
|
|
2710
|
+
});
|
|
2711
|
+
}
|
|
2712
|
+
if (shouldFocusCurrent && focusedId) {
|
|
2713
|
+
nextTree = ctx.mutations.mutateField(nextTree, {
|
|
2714
|
+
keyValuePairs: {
|
|
2715
|
+
"props.contentEditable": true
|
|
2716
|
+
},
|
|
2717
|
+
id: focusedId
|
|
2718
|
+
});
|
|
2719
|
+
}
|
|
2720
|
+
return nextTree;
|
|
2721
|
+
}, { shouldEmitEvent: false });
|
|
2722
|
+
}
|
|
2723
|
+
ctx.state.set("focus", payload);
|
|
2724
|
+
const selectedBlocks = ctx.state.get("selection");
|
|
2725
|
+
if (payload && !selectedBlocks?.blocks?.has(payload.id)) {
|
|
2726
|
+
ctx.commands.execute("blocks.select", {
|
|
2727
|
+
blocks: new Map().set(payload.id, payload.rect),
|
|
2728
|
+
mode: "replace"
|
|
2729
|
+
});
|
|
2730
|
+
} else if (!payload) {
|
|
2731
|
+
ctx.commands.execute("blocks.select", {
|
|
2732
|
+
blocks: new Map,
|
|
2733
|
+
mode: "replace"
|
|
2734
|
+
});
|
|
2735
|
+
}
|
|
2736
|
+
const { blocks: _memoBlocks, count } = ctx.state.get("focus_memory");
|
|
2737
|
+
if (focusedId && rect) {
|
|
2738
|
+
ctx.state.set("focus_memory", {
|
|
2739
|
+
blocks: [{ id: focusedId, rect }, ...[..._memoBlocks].reverse()].slice(0, count),
|
|
2740
|
+
count
|
|
2741
|
+
});
|
|
2742
|
+
}
|
|
2743
|
+
ctx.events.emit("blocks:focus", payload);
|
|
2744
|
+
});
|
|
2745
|
+
}
|
|
2746
|
+
};
|
|
2747
|
+
// src/modules/hover/hover.module.ts
|
|
2748
|
+
function hoverOverlayPropsFromUICtx(ui4, editorRect) {
|
|
2749
|
+
const rect = ui4.hover?.rect;
|
|
2750
|
+
if (!rect)
|
|
2751
|
+
return null;
|
|
2752
|
+
return overlayPositionFromBlockRects([rect], editorRect);
|
|
2753
|
+
}
|
|
2754
|
+
var HoverModule = {
|
|
2755
|
+
name: "hover",
|
|
2756
|
+
version: "1.0.0",
|
|
2757
|
+
requires: [],
|
|
2758
|
+
install(ctx) {
|
|
2759
|
+
ctx.state.defineSlice("hover", null);
|
|
2760
|
+
ctx.state.defineSlice("hover_memory", { blocks: [], count: 3 });
|
|
2761
|
+
ctx.ui.contribute(defineComponent({
|
|
2762
|
+
id: "hover-overlay",
|
|
2763
|
+
slot: "overlay",
|
|
2764
|
+
order: 999,
|
|
2765
|
+
kind: "component",
|
|
2766
|
+
name: "HoverOverlay",
|
|
2767
|
+
when: (ui4) => !!ui4.hover?.id,
|
|
2768
|
+
getProps: (ui4) => {
|
|
2769
|
+
const editorState = ctx.state.get("editor") ?? { editorRect: null };
|
|
2770
|
+
const selection = ctx.state.get("selection");
|
|
2771
|
+
const document = ctx.state.get("document");
|
|
2772
|
+
const position = hoverOverlayPropsFromUICtx(ui4, editorState?.editorRect);
|
|
2773
|
+
return {
|
|
2774
|
+
position,
|
|
2775
|
+
hidden: !ui4.hover?.id || !position || !!selection && selection.blocks.has(ui4.hover?.id) || !document?.order.has(ui4.hover?.id)
|
|
2776
|
+
};
|
|
2777
|
+
}
|
|
2778
|
+
}));
|
|
2779
|
+
ctx.commands.register("blocks.hover", (payload) => {
|
|
2780
|
+
if (!payload) {
|
|
2781
|
+
ctx.state.set("hover", null);
|
|
2782
|
+
ctx.events.emit("blocks:hover", null);
|
|
2783
|
+
return;
|
|
2784
|
+
}
|
|
2785
|
+
const { id, rect } = payload;
|
|
2786
|
+
const prev = ctx.state.get("hover");
|
|
2787
|
+
if (id !== null && !ctx.document.has(id))
|
|
2788
|
+
return;
|
|
2789
|
+
if (id === prev?.id)
|
|
2790
|
+
return;
|
|
2791
|
+
ctx.state.set("hover", payload);
|
|
2792
|
+
const { blocks: _memoBlocks, count } = ctx.state.get("hover_memory");
|
|
2793
|
+
if (id && rect) {
|
|
2794
|
+
ctx.state.set("hover_memory", {
|
|
2795
|
+
blocks: [..._memoBlocks, { id, rect }].slice(-count),
|
|
2796
|
+
count
|
|
2797
|
+
});
|
|
2798
|
+
}
|
|
2799
|
+
ctx.events.emit("blocks:hover", payload);
|
|
2800
|
+
});
|
|
2801
|
+
}
|
|
2802
|
+
};
|
|
2803
|
+
// src/modules/history/history.module.ts
|
|
2804
|
+
var HistoryModule = {
|
|
2805
|
+
name: "history",
|
|
2806
|
+
version: "1.0.0",
|
|
2807
|
+
requires: ["focus"],
|
|
2808
|
+
install(ctx) {
|
|
2809
|
+
const MAX = 100;
|
|
2810
|
+
let stack = [ctx.document.get()];
|
|
2811
|
+
let cursor = 0;
|
|
2812
|
+
ctx.state.defineSlice("history", { canUndo: false, canRedo: false });
|
|
2813
|
+
ctx.state.defineSlice("history:stack", { size: 0, cursor: 0 });
|
|
2814
|
+
const sync = () => {
|
|
2815
|
+
ctx.state.set("history", {
|
|
2816
|
+
canUndo: cursor > 0,
|
|
2817
|
+
canRedo: cursor < stack.length - 1
|
|
2818
|
+
});
|
|
2819
|
+
ctx.state.set("history:stack", {
|
|
2820
|
+
size: stack.length,
|
|
2821
|
+
cursor
|
|
2822
|
+
});
|
|
2823
|
+
};
|
|
2824
|
+
ctx.events.on("document:changed", ({ value }) => {
|
|
2825
|
+
if (value.origin === "history")
|
|
2826
|
+
return;
|
|
2827
|
+
stack = [...stack.slice(0, cursor + 1), value.next].slice(-MAX);
|
|
2828
|
+
cursor = stack.length - 1;
|
|
2829
|
+
sync();
|
|
2830
|
+
});
|
|
2831
|
+
const go = (to) => {
|
|
2832
|
+
if (to < 0 || to >= stack.length)
|
|
2833
|
+
return;
|
|
2834
|
+
cursor = to;
|
|
2835
|
+
ctx.document.apply(() => stack[cursor], { origin: "history" });
|
|
2836
|
+
sync();
|
|
2837
|
+
if (ctx.state.get("focus"))
|
|
2838
|
+
ctx.commands.tryExecute("blocks.focus", null);
|
|
2839
|
+
};
|
|
2840
|
+
ctx.commands.register("history.undo", () => go(cursor - 1));
|
|
2841
|
+
ctx.commands.register("history.redo", () => go(cursor + 1));
|
|
2842
|
+
ctx.commands.register("history.move", ({ cursor: cursor2 }) => go(cursor2));
|
|
2843
|
+
ctx.commands.register("history.cleanup", () => {
|
|
2844
|
+
stack = [stack[cursor]];
|
|
2845
|
+
cursor = 0;
|
|
2846
|
+
ctx.state.set("history:stack", {
|
|
2847
|
+
size: 1,
|
|
2848
|
+
cursor: 0
|
|
2849
|
+
});
|
|
2850
|
+
});
|
|
2851
|
+
}
|
|
2852
|
+
};
|
|
2853
|
+
// src/modules/text-editing/text-editing.constants.ts
|
|
2854
|
+
var MARK_DEFAULT_ATTRS = {
|
|
2855
|
+
link: { href: "#" },
|
|
2856
|
+
initial: { style: { fontSize: 54 } }
|
|
2857
|
+
};
|
|
2858
|
+
|
|
2859
|
+
// src/modules/text-editing/text-editing.module.ts
|
|
2860
|
+
var isTextContent = (v) => typeof v === "object" && v !== null && typeof v.text === "string" && Array.isArray(v.marks);
|
|
2861
|
+
function splitString(str, delimiter) {
|
|
2862
|
+
return str.split(delimiter);
|
|
2863
|
+
}
|
|
2864
|
+
var getIn = (obj, path) => {
|
|
2865
|
+
if (!path)
|
|
2866
|
+
return null;
|
|
2867
|
+
return splitString(path, ".").reduce((o, k) => o?.[k], obj);
|
|
2868
|
+
};
|
|
2869
|
+
var TextEditingModule = {
|
|
2870
|
+
name: "text-editing",
|
|
2871
|
+
version: "1.0.0",
|
|
2872
|
+
requires: [],
|
|
2873
|
+
install(ctx) {
|
|
2874
|
+
ctx.state.defineSlice("textSelection", null);
|
|
2875
|
+
ctx.state.defineSlice("currentMarks", []);
|
|
2876
|
+
const currentMarks = (marks, sel) => {
|
|
2877
|
+
return marks.filter((mark) => mark.start === sel.start && mark.end === sel.end);
|
|
2878
|
+
};
|
|
2879
|
+
const current = () => {
|
|
2880
|
+
const sel = ctx.state.get("textSelection");
|
|
2881
|
+
if (!sel)
|
|
2882
|
+
return null;
|
|
2883
|
+
const block = ctx.document.getBlock(sel.blockId);
|
|
2884
|
+
if (!block || !isEditableField(block))
|
|
2885
|
+
return null;
|
|
2886
|
+
const content = getIn(block, sel.path);
|
|
2887
|
+
if (!isTextContent(content))
|
|
2888
|
+
return null;
|
|
2889
|
+
return { sel, content };
|
|
2890
|
+
};
|
|
2891
|
+
const write = (sel, next) => {
|
|
2892
|
+
ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
|
|
2893
|
+
id: sel.blockId,
|
|
2894
|
+
keyValuePairs: { [sel.path]: next },
|
|
2895
|
+
autoMerge: false
|
|
2896
|
+
}));
|
|
2897
|
+
const curBlock = ctx.document.getBlock(sel.blockId);
|
|
2898
|
+
if (!curBlock || !isEditableField(curBlock))
|
|
2899
|
+
return;
|
|
2900
|
+
ctx.state.set("currentMarks", currentMarks([...curBlock.props.children.marks], sel));
|
|
2901
|
+
};
|
|
2902
|
+
const setCaret = (sel, pos) => ctx.state.set("textSelection", {
|
|
2903
|
+
...sel,
|
|
2904
|
+
start: pos,
|
|
2905
|
+
end: pos,
|
|
2906
|
+
pendingMarks: null
|
|
2907
|
+
});
|
|
2908
|
+
const activeAt = (content, pos) => content.marks.filter((m) => m.start < pos && m.end > pos || m.end === pos && m.start < pos && ctx.text.isInclusive(m.type)).map((m) => ({ type: m.type, ...m.attrs && { attrs: m.attrs } }));
|
|
2909
|
+
ctx.commands.register("text.setSelection", (next) => {
|
|
2910
|
+
if (!next) {
|
|
2911
|
+
ctx.state.set("textSelection", null);
|
|
2912
|
+
ctx.state.set("currentMarks", []);
|
|
2913
|
+
return;
|
|
2914
|
+
}
|
|
2915
|
+
const prev = ctx.state.get("textSelection");
|
|
2916
|
+
const samePlace = prev && prev.blockId === next.blockId && prev.path === next.path && prev.start === next.start && prev.end === next.end;
|
|
2917
|
+
if (samePlace)
|
|
2918
|
+
return;
|
|
2919
|
+
const curBlock = ctx.document.getBlock(next.blockId);
|
|
2920
|
+
if (!curBlock || !isEditableField(curBlock))
|
|
2921
|
+
return;
|
|
2922
|
+
ctx.state.set("textSelection", { ...next, pendingMarks: null });
|
|
2923
|
+
ctx.state.set("currentMarks", currentMarks([...curBlock.props.children.marks], next));
|
|
2924
|
+
});
|
|
2925
|
+
ctx.commands.register("text.format", ({ format, attrs }) => {
|
|
2926
|
+
const cur = current();
|
|
2927
|
+
if (!cur)
|
|
2928
|
+
return;
|
|
2929
|
+
const { sel, content } = cur;
|
|
2930
|
+
if (sel.start === sel.end) {
|
|
2931
|
+
if (format === "initial") {
|
|
2932
|
+
const next2 = ctx.text.toggleMark(content, {
|
|
2933
|
+
start: 0,
|
|
2934
|
+
end: 1,
|
|
2935
|
+
spec: { type: format, ...attrs && { attrs } }
|
|
2936
|
+
});
|
|
2937
|
+
write(sel, next2);
|
|
2938
|
+
ctx.events.emit("text:format", { format, attrs });
|
|
2939
|
+
return;
|
|
2940
|
+
}
|
|
2941
|
+
const base = sel.pendingMarks ?? activeAt(content, sel.start);
|
|
2942
|
+
const pendingMarks = base.some((s) => s.type === format) ? base.filter((s) => s.type !== format) : [...base, { type: format, ...attrs && { attrs } }];
|
|
2943
|
+
ctx.state.set("textSelection", { ...sel, pendingMarks });
|
|
2944
|
+
ctx.events.emit("text:format", { format, attrs });
|
|
2945
|
+
return;
|
|
2946
|
+
}
|
|
2947
|
+
const next = ctx.text.toggleMark(content, {
|
|
2948
|
+
start: sel.start,
|
|
2949
|
+
end: sel.end,
|
|
2950
|
+
spec: { type: format, ...attrs && { attrs } }
|
|
2951
|
+
});
|
|
2952
|
+
if (next === content)
|
|
2953
|
+
return;
|
|
2954
|
+
write(sel, next);
|
|
2955
|
+
ctx.events.emit("text:format", { format, attrs });
|
|
2956
|
+
});
|
|
2957
|
+
ctx.commands.register("text.insert", ({ text }) => {
|
|
2958
|
+
const cur = current();
|
|
2959
|
+
if (!cur || text.length === 0)
|
|
2960
|
+
return;
|
|
2961
|
+
const { sel, content } = cur;
|
|
2962
|
+
const start = Math.min(sel.start, sel.end);
|
|
2963
|
+
const next = ctx.text.replaceRange(content, sel.start, sel.end, text, {
|
|
2964
|
+
marks: sel.pendingMarks ?? undefined
|
|
2965
|
+
});
|
|
2966
|
+
write(sel, next);
|
|
2967
|
+
setCaret(sel, start + text.length);
|
|
2968
|
+
});
|
|
2969
|
+
ctx.commands.register("text.delete", ({ direction = "backward", type = "character" }) => {
|
|
2970
|
+
const cur = current();
|
|
2971
|
+
if (!cur)
|
|
2972
|
+
return;
|
|
2973
|
+
const { sel, content } = cur;
|
|
2974
|
+
let start = Math.min(sel.start, sel.end);
|
|
2975
|
+
let end = Math.max(sel.start, sel.end);
|
|
2976
|
+
if (start === end) {
|
|
2977
|
+
if (direction === "backward")
|
|
2978
|
+
start -= 1;
|
|
2979
|
+
else
|
|
2980
|
+
end += 1;
|
|
2981
|
+
if (start < 0 || end > content.text.length)
|
|
2982
|
+
return;
|
|
2983
|
+
if (type === "word") {
|
|
2984
|
+
let chars = content.text.split("");
|
|
2985
|
+
chars = direction === "backward" ? chars.slice(0, sel.start) : chars.slice(sel.start);
|
|
2986
|
+
const sideWhiteSpacePos = direction === "backward" && chars[chars.length - 1] === " " ? "end" : direction === "forward" && chars[0] === " " ? "start" : "none";
|
|
2987
|
+
if (sideWhiteSpacePos === "start") {
|
|
2988
|
+
const position = chars.findIndex((char) => char !== " ");
|
|
2989
|
+
chars = chars.slice(position);
|
|
2990
|
+
} else if (sideWhiteSpacePos === "end") {
|
|
2991
|
+
let count = 0;
|
|
2992
|
+
for (let i = chars.length - 1;i >= 0; i--) {
|
|
2993
|
+
if (chars[i] !== " ") {
|
|
2994
|
+
break;
|
|
2995
|
+
}
|
|
2996
|
+
count++;
|
|
2997
|
+
}
|
|
2998
|
+
chars = chars.slice(0, -count);
|
|
2999
|
+
}
|
|
3000
|
+
const firstWhiteSpaceIndex = chars.findIndex((char) => char === " ");
|
|
3001
|
+
const lastWhiteSpaceIndex = chars.findLastIndex((char) => char === " ");
|
|
3002
|
+
if (direction === "backward") {
|
|
3003
|
+
start = lastWhiteSpaceIndex !== -1 ? lastWhiteSpaceIndex + 1 : 0;
|
|
3004
|
+
} else if (direction === "forward") {
|
|
3005
|
+
end = firstWhiteSpaceIndex !== -1 ? firstWhiteSpaceIndex + (content.text.length - chars.length) : content.text.length;
|
|
3006
|
+
}
|
|
3007
|
+
}
|
|
3008
|
+
}
|
|
3009
|
+
const next = ctx.text.deleteRange(content, start, end);
|
|
3010
|
+
if (next === content)
|
|
3011
|
+
return;
|
|
3012
|
+
write(sel, next);
|
|
3013
|
+
setCaret(sel, Math.max(0, start));
|
|
3014
|
+
});
|
|
3015
|
+
const formatButton = (format, icon, order) => ctx.ui.contribute(defineButton({
|
|
3016
|
+
id: `format-${format}`,
|
|
3017
|
+
slot: "toolbar",
|
|
3018
|
+
order,
|
|
3019
|
+
kind: "button",
|
|
3020
|
+
icon,
|
|
3021
|
+
command: "text.format",
|
|
3022
|
+
name: "ToolBarButton",
|
|
3023
|
+
getPayload: () => ({ format, attrs: MARK_DEFAULT_ATTRS[format] ?? {} }),
|
|
3024
|
+
getProps(ui4) {
|
|
3025
|
+
const focusedBlock = ui4.focus;
|
|
3026
|
+
if (!focusedBlock?.id)
|
|
3027
|
+
return { isActive: false };
|
|
3028
|
+
const block = ctx.document.getBlock(focusedBlock.id);
|
|
3029
|
+
if (!block || !isEditableField(block))
|
|
3030
|
+
return { isActive: false };
|
|
3031
|
+
const children = block.props.children;
|
|
3032
|
+
const curSel = ctx.state.get("textSelection");
|
|
3033
|
+
if (!curSel)
|
|
3034
|
+
return { isActive: false };
|
|
3035
|
+
const correspondingMark = children.marks?.find((mark) => mark.type === format);
|
|
3036
|
+
if (!correspondingMark)
|
|
3037
|
+
return { isActive: false };
|
|
3038
|
+
return {
|
|
3039
|
+
isActive: correspondingMark.start === curSel.start && correspondingMark.end === curSel.end
|
|
3040
|
+
};
|
|
3041
|
+
},
|
|
3042
|
+
when: (ui4) => {
|
|
3043
|
+
if (!ui4.focus?.id)
|
|
3044
|
+
return false;
|
|
3045
|
+
const block = ctx.document.getBlock(ui4.focus.id);
|
|
3046
|
+
if (!block)
|
|
3047
|
+
return false;
|
|
3048
|
+
const sel = ctx.state.get("textSelection");
|
|
3049
|
+
return isEditableField(block) && !!sel && sel.start !== sel.end && block.type !== "code";
|
|
3050
|
+
}
|
|
3051
|
+
}));
|
|
3052
|
+
formatButton("bold", "BoldIcon", 10);
|
|
3053
|
+
formatButton("italic", "ItalicIcon", 20);
|
|
3054
|
+
formatButton("link", "LinkIcon", 30);
|
|
3055
|
+
formatButton("underline", "UnderlineIcon", 40);
|
|
3056
|
+
}
|
|
3057
|
+
};
|
|
3058
|
+
// src/modules/code/code.module.ts
|
|
3059
|
+
var CodeModule = {
|
|
3060
|
+
name: "code",
|
|
3061
|
+
version: "1.0.0",
|
|
3062
|
+
requires: [],
|
|
3063
|
+
install(ctx) {
|
|
3064
|
+
ctx.commands.register("code.toggleTheme", ({ fieldId }) => {
|
|
3065
|
+
const block = ctx.document.getBlock(fieldId);
|
|
3066
|
+
if (!block || block.type !== "code")
|
|
3067
|
+
return;
|
|
3068
|
+
const current = block.props.theme ?? "dark";
|
|
3069
|
+
const index = CODE_THEME_NAMES.indexOf(current);
|
|
3070
|
+
const next = CODE_THEME_NAMES[(index + 1) % CODE_THEME_NAMES.length];
|
|
3071
|
+
ctx.document.apply((tree) => ctx.mutations.mutateField(tree, {
|
|
3072
|
+
id: fieldId,
|
|
3073
|
+
keyValuePairs: { "props.theme": next }
|
|
3074
|
+
}));
|
|
3075
|
+
ctx.events.emit("code:toggleTheme", { fieldId });
|
|
3076
|
+
});
|
|
3077
|
+
}
|
|
3078
|
+
};
|
|
3079
|
+
// src/modules/caption/caption.module.ts
|
|
3080
|
+
var hasCaptionFor = (fields, mediaId) => {
|
|
3081
|
+
for (const field of fields) {
|
|
3082
|
+
if (field.type !== "caption")
|
|
3083
|
+
continue;
|
|
3084
|
+
if (field.props.mediaId === mediaId)
|
|
3085
|
+
return true;
|
|
3086
|
+
}
|
|
3087
|
+
return false;
|
|
3088
|
+
};
|
|
3089
|
+
var CaptionModule = {
|
|
3090
|
+
name: "caption",
|
|
3091
|
+
version: "1.0.0",
|
|
3092
|
+
requires: [],
|
|
3093
|
+
install(ctx) {
|
|
3094
|
+
const addCaption = (mediaId) => {
|
|
3095
|
+
const media = ctx.document.getBlock(mediaId);
|
|
3096
|
+
if (!media || !isMediaField(media))
|
|
3097
|
+
return;
|
|
3098
|
+
if (hasCaptionFor(ctx.document.get().fields.values(), mediaId))
|
|
3099
|
+
return;
|
|
3100
|
+
const pos = [...ctx.document.get().order].indexOf(mediaId);
|
|
3101
|
+
if (pos === -1)
|
|
3102
|
+
return;
|
|
3103
|
+
const caption = FieldsUtils.NewCaptionField();
|
|
3104
|
+
if (caption.props?.mediaId) {
|
|
3105
|
+
caption.props.mediaId = mediaId;
|
|
3106
|
+
}
|
|
3107
|
+
ctx.document.apply((tree) => ctx.mutations.insertField(tree, caption, pos + 1));
|
|
3108
|
+
ctx.events.emit("caption:add", { mediaId });
|
|
3109
|
+
};
|
|
3110
|
+
ctx.commands.register("caption.add", ({ mediaId }) => addCaption(mediaId));
|
|
3111
|
+
ctx.events.on("fields:change", ({ value }) => {
|
|
3112
|
+
if (!isMediaType(value.type))
|
|
3113
|
+
return;
|
|
3114
|
+
addCaption(value.fieldId);
|
|
3115
|
+
});
|
|
3116
|
+
ctx.events.on("blocks:insert", ({ value }) => {
|
|
3117
|
+
const block = value.block;
|
|
3118
|
+
if (block.variant !== "field" || !isMediaType(block.type))
|
|
3119
|
+
return;
|
|
3120
|
+
addCaption(block.id);
|
|
3121
|
+
});
|
|
3122
|
+
ctx.ui.contribute(defineButton({
|
|
3123
|
+
id: "insert-caption",
|
|
3124
|
+
slot: "toolbar",
|
|
3125
|
+
order: 100,
|
|
3126
|
+
kind: "button",
|
|
3127
|
+
icon: "CaptionsIcon",
|
|
3128
|
+
command: "caption.add",
|
|
3129
|
+
name: "CaptionButton",
|
|
3130
|
+
label: "Add caption",
|
|
3131
|
+
getPayload: (ui4) => {
|
|
3132
|
+
const mediaId = [...ui4.selection?.blocks?.keys() ?? []][0];
|
|
3133
|
+
if (!mediaId)
|
|
3134
|
+
throw new Error("Empty selection...");
|
|
3135
|
+
return { mediaId };
|
|
3136
|
+
},
|
|
3137
|
+
getProps: () => ({}),
|
|
3138
|
+
when: (ui4) => {
|
|
3139
|
+
const blocks = ui4.selection?.blocks;
|
|
3140
|
+
if (!blocks || blocks.size !== 1)
|
|
3141
|
+
return false;
|
|
3142
|
+
const mediaId = [...blocks.keys()][0];
|
|
3143
|
+
const media = ctx.document.getBlock(mediaId);
|
|
3144
|
+
if (!media || !isMediaField(media))
|
|
3145
|
+
return false;
|
|
3146
|
+
return !hasCaptionFor(ctx.document.get().fields.values(), mediaId);
|
|
3147
|
+
}
|
|
3148
|
+
}));
|
|
3149
|
+
}
|
|
3150
|
+
};
|
|
3151
|
+
// src/modules/deletion/deletion.module.ts
|
|
3152
|
+
var DeletionModule = {
|
|
3153
|
+
name: "deletion",
|
|
3154
|
+
version: "1.0.0",
|
|
3155
|
+
requires: [],
|
|
3156
|
+
install(ctx) {
|
|
3157
|
+
ctx.commands.register("blocks.deleteSelection", () => {
|
|
3158
|
+
const blocks = ctx.state.get("selection")?.blocks ?? new Map;
|
|
3159
|
+
const ids = [...blocks.keys()].filter((id) => id.startsWith("field:"));
|
|
3160
|
+
if (!ids.length)
|
|
3161
|
+
return;
|
|
3162
|
+
ctx.document.apply((tree) => {
|
|
3163
|
+
let next = tree;
|
|
3164
|
+
for (const id of ids) {
|
|
3165
|
+
if (next.fields.has(id))
|
|
3166
|
+
next = ctx.mutations.deleteField(next, id);
|
|
3167
|
+
}
|
|
3168
|
+
return next;
|
|
3169
|
+
});
|
|
3170
|
+
ctx.commands.execute("blocks.clearSelection", undefined);
|
|
3171
|
+
});
|
|
3172
|
+
ctx.ui.contribute(defineButton({
|
|
3173
|
+
id: "delete-blocks",
|
|
3174
|
+
slot: "toolbar",
|
|
3175
|
+
order: 200,
|
|
3176
|
+
kind: "button",
|
|
3177
|
+
icon: "TrashIcon",
|
|
3178
|
+
command: "blocks.deleteSelection",
|
|
3179
|
+
name: "DeleteButton",
|
|
3180
|
+
label: "Delete",
|
|
3181
|
+
getPayload: () => {
|
|
3182
|
+
return;
|
|
3183
|
+
},
|
|
3184
|
+
getProps: () => ({}),
|
|
3185
|
+
when: (ui4) => (ui4.selection?.blocks?.size ?? 0) > 0
|
|
3186
|
+
}));
|
|
3187
|
+
}
|
|
3188
|
+
};
|
|
3189
|
+
export {
|
|
3190
|
+
tokenizeCode,
|
|
3191
|
+
setCoraxStyleSink,
|
|
3192
|
+
segments,
|
|
3193
|
+
overlayPositionFromBlockRects,
|
|
3194
|
+
isMediaType,
|
|
3195
|
+
isMediaField,
|
|
3196
|
+
isEditableType,
|
|
3197
|
+
isEditableField,
|
|
3198
|
+
getIframeSrc,
|
|
3199
|
+
getCollectedStyles,
|
|
3200
|
+
defineComponent,
|
|
3201
|
+
defineButton,
|
|
3202
|
+
coraxTreeDiffing,
|
|
3203
|
+
hash as coraxStyleHash,
|
|
3204
|
+
collectCoraxPseudoStyle,
|
|
3205
|
+
clearCollectedStyles,
|
|
3206
|
+
areObjectsTheSame,
|
|
3207
|
+
UiService,
|
|
3208
|
+
UiError,
|
|
3209
|
+
UTILS,
|
|
3210
|
+
TextMarksService,
|
|
3211
|
+
TextEditingModule,
|
|
3212
|
+
TasksService,
|
|
3213
|
+
TNodesUtils,
|
|
3214
|
+
TNodeClass,
|
|
3215
|
+
Subscriber,
|
|
3216
|
+
StateService,
|
|
3217
|
+
StateNotFoundError,
|
|
3218
|
+
StateError,
|
|
3219
|
+
SerializeTree,
|
|
3220
|
+
SelectionModule,
|
|
3221
|
+
MutationsService,
|
|
3222
|
+
MutationPrototypeError,
|
|
3223
|
+
MutationError,
|
|
3224
|
+
ModuleUtils,
|
|
3225
|
+
ModuleManager,
|
|
3226
|
+
InsertionModule,
|
|
3227
|
+
HoverModule,
|
|
3228
|
+
HistoryModule,
|
|
3229
|
+
GetDefaultTree,
|
|
3230
|
+
FocusModule,
|
|
3231
|
+
FieldsUtils,
|
|
3232
|
+
FieldClass,
|
|
3233
|
+
EventBusService,
|
|
3234
|
+
Engine,
|
|
3235
|
+
EditorModule,
|
|
3236
|
+
DocumentService,
|
|
3237
|
+
DeserializeTree,
|
|
3238
|
+
DeletionModule,
|
|
3239
|
+
DEFAULT_STYLES,
|
|
3240
|
+
DEFAULT_IMAGE_PREVIEW,
|
|
3241
|
+
CustomObject,
|
|
3242
|
+
ContainersUtils,
|
|
3243
|
+
ContainerClass,
|
|
3244
|
+
ComponentsUtils,
|
|
3245
|
+
ComponentClass,
|
|
3246
|
+
CommandsBusService,
|
|
3247
|
+
CodeModule,
|
|
3248
|
+
CmdNotFoundError,
|
|
3249
|
+
CaptionModule,
|
|
3250
|
+
CODE_THEME_NAMES,
|
|
3251
|
+
CODE_THEMES
|
|
3252
|
+
};
|