ckeditor5-elements-schema 0.0.0-stage → 49.0.0-alpha.4
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/LICENSE +21 -0
- package/README.md +70 -2
- package/dist/augmentation.d.ts +25 -0
- package/dist/augmentation.d.ts.map +1 -0
- package/dist/augmentation.js +2 -0
- package/dist/augmentation.js.map +1 -0
- package/dist/commands/elementBlockCommand.d.ts +46 -0
- package/dist/commands/elementBlockCommand.d.ts.map +1 -0
- package/dist/commands/elementBlockCommand.js +71 -0
- package/dist/commands/elementBlockCommand.js.map +1 -0
- package/dist/commands/elementContainerCommand.d.ts +36 -0
- package/dist/commands/elementContainerCommand.d.ts.map +1 -0
- package/dist/commands/elementContainerCommand.js +67 -0
- package/dist/commands/elementContainerCommand.js.map +1 -0
- package/dist/commands/elementInlineCommand.d.ts +87 -0
- package/dist/commands/elementInlineCommand.d.ts.map +1 -0
- package/dist/commands/elementInlineCommand.js +253 -0
- package/dist/commands/elementInlineCommand.js.map +1 -0
- package/dist/commands/elementInsertCommand.d.ts +33 -0
- package/dist/commands/elementInsertCommand.d.ts.map +1 -0
- package/dist/commands/elementInsertCommand.js +61 -0
- package/dist/commands/elementInsertCommand.js.map +1 -0
- package/dist/commands/elementSchemaCommand.d.ts +62 -0
- package/dist/commands/elementSchemaCommand.d.ts.map +1 -0
- package/dist/commands/elementSchemaCommand.js +107 -0
- package/dist/commands/elementSchemaCommand.js.map +1 -0
- package/dist/conversion/convertElementSchema.d.ts +17 -0
- package/dist/conversion/convertElementSchema.d.ts.map +1 -0
- package/dist/conversion/convertElementSchema.js +55 -0
- package/dist/conversion/convertElementSchema.js.map +1 -0
- package/dist/conversion/inlineTextElement.d.ts +24 -0
- package/dist/conversion/inlineTextElement.d.ts.map +1 -0
- package/dist/conversion/inlineTextElement.js +28 -0
- package/dist/conversion/inlineTextElement.js.map +1 -0
- package/dist/definition/canHold.d.ts +10 -0
- package/dist/definition/canHold.d.ts.map +1 -0
- package/dist/definition/canHold.js +22 -0
- package/dist/definition/canHold.js.map +1 -0
- package/dist/definition/compileElementSchema.d.ts +41 -0
- package/dist/definition/compileElementSchema.d.ts.map +1 -0
- package/dist/definition/compileElementSchema.js +60 -0
- package/dist/definition/compileElementSchema.js.map +1 -0
- package/dist/definition/elementSchemaError.d.ts +12 -0
- package/dist/definition/elementSchemaError.d.ts.map +1 -0
- package/dist/definition/elementSchemaError.js +16 -0
- package/dist/definition/elementSchemaError.js.map +1 -0
- package/dist/definition/readDefinition.d.ts +18 -0
- package/dist/definition/readDefinition.d.ts.map +1 -0
- package/dist/definition/readDefinition.js +60 -0
- package/dist/definition/readDefinition.js.map +1 -0
- package/dist/definition/suggest.d.ts +5 -0
- package/dist/definition/suggest.d.ts.map +1 -0
- package/dist/definition/suggest.js +27 -0
- package/dist/definition/suggest.js.map +1 -0
- package/dist/definition/types.d.ts +105 -0
- package/dist/definition/types.d.ts.map +1 -0
- package/dist/definition/types.js +2 -0
- package/dist/definition/types.js.map +1 -0
- package/dist/definition/validateElementSchema.d.ts +26 -0
- package/dist/definition/validateElementSchema.d.ts.map +1 -0
- package/dist/definition/validateElementSchema.js +145 -0
- package/dist/definition/validateElementSchema.js.map +1 -0
- package/dist/elementSchema.d.ts +47 -0
- package/dist/elementSchema.d.ts.map +1 -0
- package/dist/elementSchema.js +108 -0
- package/dist/elementSchema.js.map +1 -0
- package/dist/elementSchemaCommands.d.ts +83 -0
- package/dist/elementSchemaCommands.d.ts.map +1 -0
- package/dist/elementSchemaCommands.js +137 -0
- package/dist/elementSchemaCommands.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/typing/twoStepCaretMovement.d.ts +11 -0
- package/dist/typing/twoStepCaretMovement.d.ts.map +1 -0
- package/dist/typing/twoStepCaretMovement.js +76 -0
- package/dist/typing/twoStepCaretMovement.js.map +1 -0
- package/dist/validate.d.ts +12 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +11 -0
- package/dist/validate.js.map +1 -0
- package/package.json +49 -3
- package/src/augmentation.ts +28 -0
- package/src/commands/elementBlockCommand.ts +87 -0
- package/src/commands/elementContainerCommand.ts +83 -0
- package/src/commands/elementInlineCommand.ts +311 -0
- package/src/commands/elementInsertCommand.ts +74 -0
- package/src/commands/elementSchemaCommand.ts +140 -0
- package/src/conversion/convertElementSchema.ts +65 -0
- package/src/conversion/inlineTextElement.ts +31 -0
- package/src/definition/canHold.ts +29 -0
- package/src/definition/compileElementSchema.ts +88 -0
- package/src/definition/elementSchemaError.ts +21 -0
- package/src/definition/readDefinition.ts +98 -0
- package/src/definition/suggest.ts +38 -0
- package/src/definition/types.ts +123 -0
- package/src/definition/validateElementSchema.ts +238 -0
- package/src/elementSchema.ts +133 -0
- package/src/elementSchemaCommands.ts +202 -0
- package/src/index.ts +30 -0
- package/src/typing/twoStepCaretMovement.ts +119 -0
- package/src/validate.ts +20 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { ModelLivePosition, ModelLiveRange } from 'ckeditor5';
|
|
2
|
+
import ElementSchemaCommand from './elementSchemaCommand.js';
|
|
3
|
+
/**
|
|
4
|
+
* Toggles an inline element with text, as CKEditor's `bold` toggles an attribute of text, but with an element, e.g. a
|
|
5
|
+
* `bold` that is an inline `block` of the element schema.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* editor.execute('bold'); // The selection.
|
|
9
|
+
* editor.commands.get('bold').executeFor(element); // An element, e.g. of a context menu.
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* * On selected text, it wraps the text with the element, in each block, and merges it with the elements next to it.
|
|
13
|
+
* When all the text is in the element already, it unwraps the elements: the whole ones, not only the selected part.
|
|
14
|
+
* * On the cursor, it inserts an empty element with the cursor in it. In the element, it moves the cursor out of it, at
|
|
15
|
+
* its start or end, or it unwraps it.
|
|
16
|
+
* * On an element (selected, or given), it unwraps the element it is in, or wraps it.
|
|
17
|
+
*
|
|
18
|
+
* It is "on" ({@link isOn}) when the target is in the element: for selected text, when all of it is.
|
|
19
|
+
*/
|
|
20
|
+
export default class ElementInlineCommand extends ElementSchemaCommand {
|
|
21
|
+
isToggleable = true;
|
|
22
|
+
/**
|
|
23
|
+
* Puts the target in the element, or out of it: by default, the selection, also selected text.
|
|
24
|
+
*/
|
|
25
|
+
execute(elementOrPosition) {
|
|
26
|
+
const ranges = this._getSelectedRanges(elementOrPosition);
|
|
27
|
+
const target = this._getElementOrPosition(elementOrPosition);
|
|
28
|
+
this.editor.model.change(writer => {
|
|
29
|
+
if (ranges) {
|
|
30
|
+
if (this._isOnRanges(ranges)) {
|
|
31
|
+
this._unwrapRanges(writer, ranges);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this._wrapRanges(writer, ranges);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (target) {
|
|
38
|
+
const element = this._findElement(target);
|
|
39
|
+
if (element) {
|
|
40
|
+
this._leave(writer, element, target);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
this._insert(writer, target);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Enabled when the target can be edited, and is in the element, or the element can be there.
|
|
50
|
+
*/
|
|
51
|
+
_isEnabledFor(elementOrPosition) {
|
|
52
|
+
const ranges = this._getSelectedRanges(elementOrPosition);
|
|
53
|
+
const target = this._getElementOrPosition(elementOrPosition);
|
|
54
|
+
if (!target || !super._isEnabledFor(target)) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
if (ranges) {
|
|
58
|
+
return this._isOnRanges(ranges) || this._getWrapRanges(ranges).length > 0;
|
|
59
|
+
}
|
|
60
|
+
if (this._findElement(target)) {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
return target.is('position')
|
|
64
|
+
? this.editor.model.schema.checkChild(target, this.elementName)
|
|
65
|
+
: this._canHold(this.editor.model.createPositionBefore(target), [target]);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* "On" when the target is in the element: for selected text, when all of it is.
|
|
69
|
+
*/
|
|
70
|
+
_isOnFor(elementOrPosition) {
|
|
71
|
+
const ranges = this._getSelectedRanges(elementOrPosition);
|
|
72
|
+
const target = this._getElementOrPosition(elementOrPosition);
|
|
73
|
+
return ranges ? this._isOnRanges(ranges) : !!target && !!this._findElement(target);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Whether all the text of the ranges is in the element: there are elements, and nothing to wrap.
|
|
77
|
+
*/
|
|
78
|
+
_isOnRanges(ranges) {
|
|
79
|
+
return this._getElementsIn(ranges).length > 0 && !this._getWrapRanges(ranges).length;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Returns the elements of the command that a node is, or is in, in its line of text: the node and its ancestors, up to
|
|
83
|
+
* the first that is not inline, e.g. the paragraph. The inner first.
|
|
84
|
+
*/
|
|
85
|
+
_getElementsAround(node) {
|
|
86
|
+
const schema = this.editor.model.schema;
|
|
87
|
+
const elements = [];
|
|
88
|
+
for (let element = node; element?.is('element') && schema.isInline(element); element = element.parent) {
|
|
89
|
+
if (this.isElement(element)) {
|
|
90
|
+
elements.push(element);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return elements;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Returns the closest element of the command that the target is, or is in, in its line of text.
|
|
97
|
+
*/
|
|
98
|
+
_findElement(elementOrPosition) {
|
|
99
|
+
const target = this._getElementOrPosition(elementOrPosition);
|
|
100
|
+
return target ? (this._getElementsAround(target.is('position') ? target.parent : target)[0] ?? null) : null;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Returns the elements of the command in ranges, and around their ends.
|
|
104
|
+
*/
|
|
105
|
+
_getElementsIn(ranges) {
|
|
106
|
+
const elements = new Set();
|
|
107
|
+
for (const range of ranges) {
|
|
108
|
+
for (const element of [
|
|
109
|
+
...this._getElementsAround(range.start.parent),
|
|
110
|
+
...this._getElementsAround(range.end.parent)
|
|
111
|
+
]) {
|
|
112
|
+
elements.add(element);
|
|
113
|
+
}
|
|
114
|
+
for (const item of range.getItems()) {
|
|
115
|
+
if (this.isElement(item)) {
|
|
116
|
+
elements.add(item);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return Array.from(elements);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Returns the ranges to wrap with the element to put the text of ranges in it: in each parent the element is allowed
|
|
124
|
+
* in, the runs of nodes it can hold, which are not in the element already. The other elements are looked into, e.g.
|
|
125
|
+
* the paragraphs of a selection across blocks.
|
|
126
|
+
*/
|
|
127
|
+
_getWrapRanges(ranges) {
|
|
128
|
+
const model = this.editor.model;
|
|
129
|
+
const wrapRanges = [];
|
|
130
|
+
const collect = (flatRange) => {
|
|
131
|
+
const parent = flatRange.start.parent;
|
|
132
|
+
if (this._getElementsAround(parent).length) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
let run = null;
|
|
136
|
+
const close = () => {
|
|
137
|
+
if (run) {
|
|
138
|
+
wrapRanges.push(run);
|
|
139
|
+
run = null;
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
for (const item of flatRange.getItems({ shallow: true })) {
|
|
143
|
+
if (this.isElement(item)) {
|
|
144
|
+
close();
|
|
145
|
+
}
|
|
146
|
+
else if (this._canHold(flatRange.start, [item])) {
|
|
147
|
+
run = model.createRange(run?.start ?? model.createPositionBefore(item), model.createPositionAfter(item));
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
close();
|
|
151
|
+
if (item.is('element')) {
|
|
152
|
+
collect(model.createRangeIn(item));
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
close();
|
|
157
|
+
};
|
|
158
|
+
for (const range of ranges) {
|
|
159
|
+
range.getMinimalFlatRanges().forEach(collect);
|
|
160
|
+
}
|
|
161
|
+
return wrapRanges;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Wraps the text of ranges with new elements, merged with the ones next to them, and keeps the selection on the text.
|
|
165
|
+
*/
|
|
166
|
+
_wrapRanges(writer, ranges) {
|
|
167
|
+
// The last first: wrapping one does not move the ones before it.
|
|
168
|
+
const wrapRanges = this._getWrapRanges(ranges).reverse();
|
|
169
|
+
this._keepSelection(writer, ranges, () => {
|
|
170
|
+
for (const range of wrapRanges) {
|
|
171
|
+
const element = writer.createElement(this.elementName);
|
|
172
|
+
writer.wrap(range, element);
|
|
173
|
+
this._mergeWithSiblings(writer, element);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Unwraps the elements in ranges and around their ends, and keeps the selection on the text.
|
|
179
|
+
*/
|
|
180
|
+
_unwrapRanges(writer, ranges) {
|
|
181
|
+
const elements = this._getElementsIn(ranges);
|
|
182
|
+
this._keepSelection(writer, ranges, () => {
|
|
183
|
+
for (const element of elements) {
|
|
184
|
+
writer.unwrap(element);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Changes the content of the selected ranges, and selects the same text then: the ends of the ranges stick to the
|
|
190
|
+
* text, so they follow it into the elements and out of them.
|
|
191
|
+
*/
|
|
192
|
+
_keepSelection(writer, ranges, change) {
|
|
193
|
+
const backward = this.editor.model.document.selection.isBackward;
|
|
194
|
+
const ends = ranges.map(range => ({
|
|
195
|
+
start: ModelLivePosition.fromPosition(range.start, 'toNext'),
|
|
196
|
+
end: ModelLivePosition.fromPosition(range.end, 'toPrevious')
|
|
197
|
+
}));
|
|
198
|
+
change();
|
|
199
|
+
writer.setSelection(ends.map(({ start, end }) => writer.createRange(start, end)), { backward });
|
|
200
|
+
for (const { start, end } of ends) {
|
|
201
|
+
start.detach();
|
|
202
|
+
end.detach();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Merges a new element with the elements of the command next to it that have no attributes, as it has none.
|
|
207
|
+
*/
|
|
208
|
+
_mergeWithSiblings(writer, element) {
|
|
209
|
+
const isPlain = (node) => this.isElement(node) && node.getAttributeKeys().next().done === true;
|
|
210
|
+
if (isPlain(element.nextSibling)) {
|
|
211
|
+
writer.merge(writer.createPositionAfter(element));
|
|
212
|
+
}
|
|
213
|
+
if (isPlain(element.previousSibling)) {
|
|
214
|
+
writer.merge(writer.createPositionBefore(element));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Puts the target out of the element it is in: a cursor at the start or the end of the element goes before or after
|
|
219
|
+
* it, so that what is typed next is out of it; otherwise the element is unwrapped. A selected element that is
|
|
220
|
+
* unwrapped leaves its content selected.
|
|
221
|
+
*/
|
|
222
|
+
_leave(writer, element, target) {
|
|
223
|
+
if (target.is('position') && target.parent === element && !element.isEmpty) {
|
|
224
|
+
if (target.isAtEnd || target.isAtStart) {
|
|
225
|
+
writer.setSelection(element, target.isAtEnd ? 'after' : 'before');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const isSelected = this.editor.model.document.selection.getSelectedElement() === element;
|
|
230
|
+
const content = ModelLiveRange.fromRange(writer.createRangeIn(element));
|
|
231
|
+
writer.unwrap(element);
|
|
232
|
+
if (isSelected) {
|
|
233
|
+
writer.setSelection(content.toRange());
|
|
234
|
+
}
|
|
235
|
+
content.detach();
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Puts the target in a new element: at a position, an empty element with the cursor in it; an element, e.g. a
|
|
239
|
+
* selected inline object, is wrapped, and selected.
|
|
240
|
+
*/
|
|
241
|
+
_insert(writer, target) {
|
|
242
|
+
if (target.is('position')) {
|
|
243
|
+
const element = writer.createElement(this.elementName);
|
|
244
|
+
writer.insert(element, target);
|
|
245
|
+
writer.setSelection(element, 0);
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
writer.wrap(writer.createRangeOn(target), this.elementName);
|
|
249
|
+
writer.setSelection(target, 'on');
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=elementInlineCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementInlineCommand.js","sourceRoot":"","sources":["../../src/commands/elementInlineCommand.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,iBAAiB,EACjB,cAAc,EAMd,MAAM,WAAW,CAAC;AAEnB,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAE7D;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,oBAAoB;IACrD,YAAY,GAAG,IAAI,CAAC;IAEpC;;OAEG;IACa,OAAO,CAAC,iBAAqC;QAC5D,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;QAE7D,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YACjC,IAAI,MAAM,EAAE,CAAC;gBACZ,IAAI,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC9B,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBACpC,CAAC;qBAAM,CAAC;oBACP,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAClC,CAAC;YACF,CAAC;iBAAM,IAAI,MAAM,EAAE,CAAC;gBACnB,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;gBAE1C,IAAI,OAAO,EAAE,CAAC;oBACb,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,OAA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AAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;QAExE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAEvB,IAAI,UAAU,EAAE,CAAC;YAChB,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;QACxC,CAAC;QAED,OAAO,CAAC,MAAM,EAAE,CAAC;IAClB,CAAC;IAED;;;OAGG;IACK,OAAO,CAAC,MAAmB,EAAE,MAAyB;QAC7D,IAAI,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;YAC3B,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAEvD,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC/B,MAAM,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACP,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;YAC5D,MAAM,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ElementOrPosition } from 'ckeditor5-elements-core';
|
|
2
|
+
import ElementSchemaCommand from './elementSchemaCommand.js';
|
|
3
|
+
/**
|
|
4
|
+
* Inserts the element, as CKEditor's horizontal line and image commands do: an element that is not typed around text,
|
|
5
|
+
* e.g. an `empty` element of the element schema (a `divider`, or an inline `badge`), or an inline `container` (a `card`).
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* editor.execute('divider'); // In place of the selection.
|
|
9
|
+
* editor.commands.get('divider').executeFor(element); // After the element.
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* For the selection, it replaces the selected content, as typing does; at a position, it is inserted there; for an
|
|
13
|
+
* element, after it. Where the element cannot be, the blocks are split up to where it can, e.g. a block-level one in the
|
|
14
|
+
* middle of a paragraph. Then it is selected, as `selectNewElement()` does: an `empty` element as a whole, and an inline
|
|
15
|
+
* container gets a paragraph, with the cursor in it.
|
|
16
|
+
*
|
|
17
|
+
* It does not toggle: it is never "on".
|
|
18
|
+
*/
|
|
19
|
+
export default class ElementInsertCommand extends ElementSchemaCommand {
|
|
20
|
+
/**
|
|
21
|
+
* Inserts a new element at the target, and selects it.
|
|
22
|
+
*/
|
|
23
|
+
execute(elementOrPosition?: ElementOrPosition): void;
|
|
24
|
+
/**
|
|
25
|
+
* Enabled when the target can be edited, and the element can be there, or in one of its ancestors.
|
|
26
|
+
*/
|
|
27
|
+
protected _isEnabledFor(elementOrPosition?: ElementOrPosition): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Returns where the element goes: the selection, or the given position, or the position after the given element.
|
|
30
|
+
*/
|
|
31
|
+
private _getSelectable;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=elementInsertCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementInsertCommand.d.ts","sourceRoot":"","sources":["../../src/commands/elementInsertCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACnF,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAE7D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,oBAAoB;IACrE;;OAEG;IACa,OAAO,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI;IAmBpE;;OAEG;cACgB,aAAa,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,OAAO;IAUhF;;OAEG;IACH,OAAO,CAAC,cAAc;CActB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { selectNewElement } from 'ckeditor5-elements-core';
|
|
2
|
+
import ElementSchemaCommand from './elementSchemaCommand.js';
|
|
3
|
+
/**
|
|
4
|
+
* Inserts the element, as CKEditor's horizontal line and image commands do: an element that is not typed around text,
|
|
5
|
+
* e.g. an `empty` element of the element schema (a `divider`, or an inline `badge`), or an inline `container` (a `card`).
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* editor.execute('divider'); // In place of the selection.
|
|
9
|
+
* editor.commands.get('divider').executeFor(element); // After the element.
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* For the selection, it replaces the selected content, as typing does; at a position, it is inserted there; for an
|
|
13
|
+
* element, after it. Where the element cannot be, the blocks are split up to where it can, e.g. a block-level one in the
|
|
14
|
+
* middle of a paragraph. Then it is selected, as `selectNewElement()` does: an `empty` element as a whole, and an inline
|
|
15
|
+
* container gets a paragraph, with the cursor in it.
|
|
16
|
+
*
|
|
17
|
+
* It does not toggle: it is never "on".
|
|
18
|
+
*/
|
|
19
|
+
export default class ElementInsertCommand extends ElementSchemaCommand {
|
|
20
|
+
/**
|
|
21
|
+
* Inserts a new element at the target, and selects it.
|
|
22
|
+
*/
|
|
23
|
+
execute(elementOrPosition) {
|
|
24
|
+
const model = this.editor.model;
|
|
25
|
+
const selectable = this._getSelectable(elementOrPosition);
|
|
26
|
+
if (!selectable) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
model.change(writer => {
|
|
30
|
+
const element = writer.createElement(this.elementName);
|
|
31
|
+
model.insertContent(element, selectable);
|
|
32
|
+
if (element.parent) {
|
|
33
|
+
selectNewElement(writer, element);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Enabled when the target can be edited, and the element can be there, or in one of its ancestors.
|
|
39
|
+
*/
|
|
40
|
+
_isEnabledFor(elementOrPosition) {
|
|
41
|
+
const position = this._getSelectable(elementOrPosition)?.getFirstPosition();
|
|
42
|
+
return (!!position &&
|
|
43
|
+
super._isEnabledFor(elementOrPosition) &&
|
|
44
|
+
!!this.editor.model.schema.findAllowedParent(position, this.elementName));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns where the element goes: the selection, or the given position, or the position after the given element.
|
|
48
|
+
*/
|
|
49
|
+
_getSelectable(elementOrPosition) {
|
|
50
|
+
const model = this.editor.model;
|
|
51
|
+
const target = this._getElementOrPosition(elementOrPosition);
|
|
52
|
+
if (!target) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
if (!elementOrPosition) {
|
|
56
|
+
return model.document.selection;
|
|
57
|
+
}
|
|
58
|
+
return model.createSelection(target.is('position') ? target : model.createPositionAfter(target));
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=elementInsertCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementInsertCommand.js","sourceRoot":"","sources":["../../src/commands/elementInsertCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAA0B,MAAM,yBAAyB,CAAC;AACnF,OAAO,oBAAoB,MAAM,2BAA2B,CAAC;AAE7D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,oBAAoB;IACrE;;OAEG;IACa,OAAO,CAAC,iBAAqC;QAC5D,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,CAAC;QAE1D,IAAI,CAAC,UAAU,EAAE,CAAC;YACjB,OAAO;QACR,CAAC;QAED,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YACrB,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YAEvD,KAAK,CAAC,aAAa,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;YAEzC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;gBACpB,gBAAgB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;YACnC,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACgB,aAAa,CAAC,iBAAqC;QACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;QAE5E,OAAO,CACN,CAAC,CAAC,QAAQ;YACV,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC;YACtC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC,WAAW,CAAC,CACxE,CAAC;IACH,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,iBAAqC;QAC3D,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;QAE7D,IAAI,CAAC,MAAM,EAAE,CAAC;YACb,OAAO,IAAI,CAAC;QACb,CAAC;QAED,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACxB,OAAO,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC;QACjC,CAAC;QAED,OAAO,KAAK,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC;IAClG,CAAC;CACD"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Editor, ModelElement, ModelDocumentFragment, ModelItem, ModelPosition, ModelRange } from 'ckeditor5';
|
|
2
|
+
import { ElementOrPositionCommand, type ElementOrPosition } from 'ckeditor5-elements-core';
|
|
3
|
+
/**
|
|
4
|
+
* The base of the commands of the elements of a schema, one for each kind of element: what they share is the element,
|
|
5
|
+
* the state, and how they find their targets and check the schema.
|
|
6
|
+
*
|
|
7
|
+
* * {@link ElementInlineCommand}: an inline element with text, as bold (an inline `block`);
|
|
8
|
+
* * {@link ElementBlockCommand}: a block, as a heading (a `block`);
|
|
9
|
+
* * {@link ElementContainerCommand}: a container of blocks, as a block quote (a `container`);
|
|
10
|
+
* * {@link ElementInsertCommand}: an element that is inserted, as a horizontal line, an inline image, or a card (an
|
|
11
|
+
* `empty` element, and an inline `container`).
|
|
12
|
+
*
|
|
13
|
+
* As every {@link ElementOrPositionCommand}, it is for the selection, or for a given position or element, e.g. of a
|
|
14
|
+
* context menu.
|
|
15
|
+
*/
|
|
16
|
+
export default class ElementSchemaCommand extends ElementOrPositionCommand {
|
|
17
|
+
/**
|
|
18
|
+
* Whether the target is in the element, or is one, for the commands that toggle it.
|
|
19
|
+
*
|
|
20
|
+
* @observable
|
|
21
|
+
*/
|
|
22
|
+
isOn: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The name of the model element of the command.
|
|
25
|
+
*/
|
|
26
|
+
readonly elementName: string;
|
|
27
|
+
constructor(editor: Editor, elementName: string);
|
|
28
|
+
refresh(elementOrPosition?: ElementOrPosition): void;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a node is an element of the command.
|
|
31
|
+
*/
|
|
32
|
+
isElement(node: ModelItem | ModelDocumentFragment | null): node is ModelElement;
|
|
33
|
+
/**
|
|
34
|
+
* Returns the closest element of the command that the target is, or is in: by default, the selection. Never a root.
|
|
35
|
+
*/
|
|
36
|
+
protected _findElement(elementOrPosition?: ElementOrPosition): ModelElement | null;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the elements the target is, or is in (by default, the selection), the inner first: an element and its
|
|
39
|
+
* ancestors, or the parent of a position and its ancestors. Not the root.
|
|
40
|
+
*/
|
|
41
|
+
protected _getAncestors(elementOrPosition?: ElementOrPosition): ModelElement[];
|
|
42
|
+
/**
|
|
43
|
+
* Returns the ranges of the selected content, when the command is for the selection, and the selection is content,
|
|
44
|
+
* not a cursor nor an element.
|
|
45
|
+
*/
|
|
46
|
+
protected _getSelectedRanges(elementOrPosition?: ElementOrPosition): ModelRange[] | null;
|
|
47
|
+
/**
|
|
48
|
+
* Returns the blocks of the target, by default of the selection: the selected blocks, or the block-level element the
|
|
49
|
+
* target is, or is in (e.g. the paragraph with the cursor, a selected horizontal line, or a block quote).
|
|
50
|
+
*/
|
|
51
|
+
protected _getBlocks(elementOrPosition?: ElementOrPosition): ModelElement[];
|
|
52
|
+
/**
|
|
53
|
+
* Whether an element (by default, the one of the command) can be at a position, and hold the items there: the check
|
|
54
|
+
* for wrapping them, or for renaming their parent.
|
|
55
|
+
*/
|
|
56
|
+
protected _canHold(position: ModelPosition, items: Iterable<ModelItem>, name?: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Whether the children of an element can be in its place: the check for unwrapping it.
|
|
59
|
+
*/
|
|
60
|
+
protected _canUnwrap(element: ModelElement): boolean;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=elementSchemaCommand.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementSchemaCommand.d.ts","sourceRoot":"","sources":["../../src/commands/elementSchemaCommand.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,qBAAqB,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACnH,OAAO,EAAE,wBAAwB,EAAE,KAAK,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAE3F;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,wBAAwB;IACzE;;;;OAIG;IACY,IAAI,EAAE,OAAO,CAAC;IAE7B;;OAEG;IACH,SAAgB,WAAW,EAAE,MAAM,CAAC;gBAExB,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAO/B,OAAO,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,IAAI;IAKpE;;OAEG;IACI,SAAS,CAAC,IAAI,EAAE,SAAS,GAAG,qBAAqB,GAAG,IAAI,GAAG,IAAI,IAAI,YAAY;IAItF;;OAEG;IACH,SAAS,CAAC,YAAY,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,YAAY,GAAG,IAAI;IAIlF;;;OAGG;IACH,SAAS,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,YAAY,EAAE;IAW9E;;;OAGG;IACH,SAAS,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,UAAU,EAAE,GAAG,IAAI;IAQxF;;;OAGG;IACH,SAAS,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,YAAY,EAAE;IAgB3E;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,aAAa,EAAE,KAAK,EAAE,QAAQ,CAAC,SAAS,CAAC,EAAE,IAAI,SAAmB,GAAG,OAAO;IAmBzG;;OAEG;IACH,SAAS,CAAC,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO;CAWpD"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { ElementOrPositionCommand } from 'ckeditor5-elements-core';
|
|
2
|
+
/**
|
|
3
|
+
* The base of the commands of the elements of a schema, one for each kind of element: what they share is the element,
|
|
4
|
+
* the state, and how they find their targets and check the schema.
|
|
5
|
+
*
|
|
6
|
+
* * {@link ElementInlineCommand}: an inline element with text, as bold (an inline `block`);
|
|
7
|
+
* * {@link ElementBlockCommand}: a block, as a heading (a `block`);
|
|
8
|
+
* * {@link ElementContainerCommand}: a container of blocks, as a block quote (a `container`);
|
|
9
|
+
* * {@link ElementInsertCommand}: an element that is inserted, as a horizontal line, an inline image, or a card (an
|
|
10
|
+
* `empty` element, and an inline `container`).
|
|
11
|
+
*
|
|
12
|
+
* As every {@link ElementOrPositionCommand}, it is for the selection, or for a given position or element, e.g. of a
|
|
13
|
+
* context menu.
|
|
14
|
+
*/
|
|
15
|
+
export default class ElementSchemaCommand extends ElementOrPositionCommand {
|
|
16
|
+
/**
|
|
17
|
+
* The name of the model element of the command.
|
|
18
|
+
*/
|
|
19
|
+
elementName;
|
|
20
|
+
constructor(editor, elementName) {
|
|
21
|
+
super(editor);
|
|
22
|
+
this.elementName = elementName;
|
|
23
|
+
this.set('isOn', false);
|
|
24
|
+
}
|
|
25
|
+
refresh(elementOrPosition) {
|
|
26
|
+
this.isOn = this._isOnFor(elementOrPosition);
|
|
27
|
+
super.refresh(elementOrPosition);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Whether a node is an element of the command.
|
|
31
|
+
*/
|
|
32
|
+
isElement(node) {
|
|
33
|
+
return !!node?.is('element', this.elementName);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Returns the closest element of the command that the target is, or is in: by default, the selection. Never a root.
|
|
37
|
+
*/
|
|
38
|
+
_findElement(elementOrPosition) {
|
|
39
|
+
return this._getAncestors(elementOrPosition).find(element => this.isElement(element)) ?? null;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Returns the elements the target is, or is in (by default, the selection), the inner first: an element and its
|
|
43
|
+
* ancestors, or the parent of a position and its ancestors. Not the root.
|
|
44
|
+
*/
|
|
45
|
+
_getAncestors(elementOrPosition) {
|
|
46
|
+
const target = this._getElementOrPosition(elementOrPosition);
|
|
47
|
+
const element = target && (target.is('position') ? target.parent : target);
|
|
48
|
+
return element?.is('element')
|
|
49
|
+
? element
|
|
50
|
+
.getAncestors({ includeSelf: true, parentFirst: true })
|
|
51
|
+
.filter((node) => node.is('element') && !node.is('rootElement'))
|
|
52
|
+
: [];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the ranges of the selected content, when the command is for the selection, and the selection is content,
|
|
56
|
+
* not a cursor nor an element.
|
|
57
|
+
*/
|
|
58
|
+
_getSelectedRanges(elementOrPosition) {
|
|
59
|
+
const selection = this.editor.model.document.selection;
|
|
60
|
+
return !elementOrPosition && !selection.isCollapsed && !selection.getSelectedElement()
|
|
61
|
+
? Array.from(selection.getRanges())
|
|
62
|
+
: null;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Returns the blocks of the target, by default of the selection: the selected blocks, or the block-level element the
|
|
66
|
+
* target is, or is in (e.g. the paragraph with the cursor, a selected horizontal line, or a block quote).
|
|
67
|
+
*/
|
|
68
|
+
_getBlocks(elementOrPosition) {
|
|
69
|
+
const selection = this.editor.model.document.selection;
|
|
70
|
+
const blocks = elementOrPosition || selection.getSelectedElement() ? [] : Array.from(selection.getSelectedBlocks());
|
|
71
|
+
if (blocks.length) {
|
|
72
|
+
return blocks;
|
|
73
|
+
}
|
|
74
|
+
const block = this._getAncestors(elementOrPosition).find(element => !this.editor.model.schema.isInline(element));
|
|
75
|
+
return block ? [block] : [];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Whether an element (by default, the one of the command) can be at a position, and hold the items there: the check
|
|
79
|
+
* for wrapping them, or for renaming their parent.
|
|
80
|
+
*/
|
|
81
|
+
_canHold(position, items, name = this.elementName) {
|
|
82
|
+
const schema = this.editor.model.schema;
|
|
83
|
+
if (!schema.checkChild(position, name)) {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
const parent = position.parent;
|
|
87
|
+
const context = [...parent.getAncestors({ includeSelf: true }).filter(node => node.is('element')), name];
|
|
88
|
+
for (const item of items) {
|
|
89
|
+
if (!schema.checkChild(context, item.is('$textProxy') ? '$text' : item)) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Whether the children of an element can be in its place: the check for unwrapping it.
|
|
97
|
+
*/
|
|
98
|
+
_canUnwrap(element) {
|
|
99
|
+
const model = this.editor.model;
|
|
100
|
+
if (!element.parent) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const position = model.createPositionBefore(element);
|
|
104
|
+
return Array.from(element.getChildren()).every(child => model.schema.checkChild(position, child));
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=elementSchemaCommand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementSchemaCommand.js","sourceRoot":"","sources":["../../src/commands/elementSchemaCommand.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAA0B,MAAM,yBAAyB,CAAC;AAE3F;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,OAAO,OAAO,oBAAqB,SAAQ,wBAAwB;IAQzE;;OAEG;IACa,WAAW,CAAS;IAEpC,YAAY,MAAc,EAAE,WAAmB;QAC9C,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACzB,CAAC;IAEe,OAAO,CAAC,iBAAqC;QAC5D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QAC7C,KAAK,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,IAA8C;QAC9D,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACO,YAAY,CAAC,iBAAqC;QAC3D,OAAO,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,IAAI,CAAC;IAC/F,CAAC;IAED;;;OAGG;IACO,aAAa,CAAC,iBAAqC;QAC5D,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;QAC7D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C;QACd,CAAC;QAED,MAAM,QAAQ,GAAG,KAAK,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;QAErD,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;IACnG,CAAC;CACD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Editor } from 'ckeditor5';
|
|
2
|
+
import type { ElementSchemaElement, ElementSchemaInput } from '../definition/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Returns the tag of an element in the data: a `span` for what is in a line of text (an inline element that is empty or
|
|
5
|
+
* has text), a `div` for the rest. An inline container is a `div`: it holds blocks, which a `span` cannot hold.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getViewTag({ type, isInline }: Pick<ElementSchemaElement, 'type' | 'isInline'>): 'div' | 'span';
|
|
8
|
+
/**
|
|
9
|
+
* Declares the converters of the elements of a schema, one to one: an element is a `div` or a `span` in the data (see
|
|
10
|
+
* {@link getViewTag}), with its name as the class. Its attributes are `data-*` attributes. The data is loaded as it is
|
|
11
|
+
* saved. The editing view is the same, except for the tag, when the element has an `editingTag`.
|
|
12
|
+
*
|
|
13
|
+
* The `empty` elements are empty in the data too: `<div class="divider"></div>`, with no filler. The inline elements with
|
|
14
|
+
* text have no block filler, so the cursor can go in an empty one (see `withoutBlockFiller()`).
|
|
15
|
+
*/
|
|
16
|
+
export declare function convertElementSchema(editor: Editor, input: ElementSchemaInput): void;
|
|
17
|
+
//# sourceMappingURL=convertElementSchema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertElementSchema.d.ts","sourceRoot":"","sources":["../../src/conversion/convertElementSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAGvF;;;GAGG;AACH,wBAAgB,UAAU,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,IAAI,CAAC,oBAAoB,EAAE,MAAM,GAAG,UAAU,CAAC,GAAG,KAAK,GAAG,MAAM,CAE9G;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,IAAI,CA4CpF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createInlineTextElement } from './inlineTextElement.js';
|
|
2
|
+
/**
|
|
3
|
+
* Returns the tag of an element in the data: a `span` for what is in a line of text (an inline element that is empty or
|
|
4
|
+
* has text), a `div` for the rest. An inline container is a `div`: it holds blocks, which a `span` cannot hold.
|
|
5
|
+
*/
|
|
6
|
+
export function getViewTag({ type, isInline }) {
|
|
7
|
+
return isInline && type !== 'container' ? 'span' : 'div';
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Declares the converters of the elements of a schema, one to one: an element is a `div` or a `span` in the data (see
|
|
11
|
+
* {@link getViewTag}), with its name as the class. Its attributes are `data-*` attributes. The data is loaded as it is
|
|
12
|
+
* saved. The editing view is the same, except for the tag, when the element has an `editingTag`.
|
|
13
|
+
*
|
|
14
|
+
* The `empty` elements are empty in the data too: `<div class="divider"></div>`, with no filler. The inline elements with
|
|
15
|
+
* text have no block filler, so the cursor can go in an empty one (see `withoutBlockFiller()`).
|
|
16
|
+
*/
|
|
17
|
+
export function convertElementSchema(editor, input) {
|
|
18
|
+
const { conversion } = editor;
|
|
19
|
+
for (const [name, element] of Object.entries(input)) {
|
|
20
|
+
const { type, isInline, editingTag, allowAttributes } = element;
|
|
21
|
+
const tag = getViewTag(element);
|
|
22
|
+
const view = { name: tag, classes: name };
|
|
23
|
+
const isInlineText = type === 'block' && !!isInline;
|
|
24
|
+
for (const key of allowAttributes ?? []) {
|
|
25
|
+
// The names of HTML attributes are lowercase, so the data has them in lowercase; the model keeps the key as it is.
|
|
26
|
+
conversion.attributeToAttribute({ model: { name, key }, view: `data-${key.toLowerCase()}` });
|
|
27
|
+
}
|
|
28
|
+
// Upcast, data downcast and editing downcast at once; what differs is declared with a higher priority.
|
|
29
|
+
conversion.elementToElement({ model: name, view });
|
|
30
|
+
if (type === 'empty') {
|
|
31
|
+
conversion.for('dataDowncast').elementToElement({
|
|
32
|
+
model: name,
|
|
33
|
+
view: (_element, { writer }) => writer.createEmptyElement(tag, { class: name }),
|
|
34
|
+
converterPriority: 'high'
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (isInlineText) {
|
|
38
|
+
conversion.for('dataDowncast').elementToElement({
|
|
39
|
+
model: name,
|
|
40
|
+
view: (_element, { writer }) => createInlineTextElement(writer, tag, name),
|
|
41
|
+
converterPriority: 'high'
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (editingTag || isInlineText) {
|
|
45
|
+
conversion.for('editingDowncast').elementToElement({
|
|
46
|
+
model: name,
|
|
47
|
+
view: (_element, { writer }) => isInlineText
|
|
48
|
+
? createInlineTextElement(writer, editingTag ?? tag, name)
|
|
49
|
+
: writer.createContainerElement(editingTag ?? tag, { class: name }),
|
|
50
|
+
converterPriority: 'high'
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=convertElementSchema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertElementSchema.js","sourceRoot":"","sources":["../../src/conversion/convertElementSchema.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAmD;IAC7F,OAAO,QAAQ,IAAI,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,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