ckeditor5-elements-schema 0.0.0-stage → 49.0.0-alpha.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +44 -2
  3. package/dist/augmentation.d.ts +19 -0
  4. package/dist/augmentation.d.ts.map +1 -0
  5. package/dist/augmentation.js +2 -0
  6. package/dist/augmentation.js.map +1 -0
  7. package/dist/canHold.d.ts +10 -0
  8. package/dist/canHold.d.ts.map +1 -0
  9. package/dist/canHold.js +22 -0
  10. package/dist/canHold.js.map +1 -0
  11. package/dist/compileElementSchema.d.ts +41 -0
  12. package/dist/compileElementSchema.d.ts.map +1 -0
  13. package/dist/compileElementSchema.js +60 -0
  14. package/dist/compileElementSchema.js.map +1 -0
  15. package/dist/convertElementSchema.d.ts +16 -0
  16. package/dist/convertElementSchema.d.ts.map +1 -0
  17. package/dist/convertElementSchema.js +43 -0
  18. package/dist/convertElementSchema.js.map +1 -0
  19. package/dist/elementSchema.d.ts +47 -0
  20. package/dist/elementSchema.d.ts.map +1 -0
  21. package/dist/elementSchema.js +108 -0
  22. package/dist/elementSchema.js.map +1 -0
  23. package/dist/elementSchemaError.d.ts +12 -0
  24. package/dist/elementSchemaError.d.ts.map +1 -0
  25. package/dist/elementSchemaError.js +16 -0
  26. package/dist/elementSchemaError.js.map +1 -0
  27. package/dist/index.d.ts +10 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +12 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/readDefinition.d.ts +18 -0
  32. package/dist/readDefinition.d.ts.map +1 -0
  33. package/dist/readDefinition.js +60 -0
  34. package/dist/readDefinition.js.map +1 -0
  35. package/dist/suggest.d.ts +5 -0
  36. package/dist/suggest.d.ts.map +1 -0
  37. package/dist/suggest.js +27 -0
  38. package/dist/suggest.js.map +1 -0
  39. package/dist/types.d.ts +105 -0
  40. package/dist/types.d.ts.map +1 -0
  41. package/dist/types.js +2 -0
  42. package/dist/types.js.map +1 -0
  43. package/dist/validate.d.ts +12 -0
  44. package/dist/validate.d.ts.map +1 -0
  45. package/dist/validate.js +11 -0
  46. package/dist/validate.js.map +1 -0
  47. package/dist/validateElementSchema.d.ts +26 -0
  48. package/dist/validateElementSchema.d.ts.map +1 -0
  49. package/dist/validateElementSchema.js +145 -0
  50. package/dist/validateElementSchema.js.map +1 -0
  51. package/package.json +49 -3
  52. package/src/augmentation.ts +21 -0
  53. package/src/canHold.ts +29 -0
  54. package/src/compileElementSchema.ts +88 -0
  55. package/src/convertElementSchema.ts +51 -0
  56. package/src/elementSchema.ts +133 -0
  57. package/src/elementSchemaError.ts +21 -0
  58. package/src/index.ts +14 -0
  59. package/src/readDefinition.ts +98 -0
  60. package/src/suggest.ts +38 -0
  61. package/src/types.ts +123 -0
  62. package/src/validate.ts +20 -0
  63. package/src/validateElementSchema.ts +238 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ivan Kildyushov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,45 @@
1
- # Temporary Holding Version
1
+ # ckeditor5-elements-schema
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Element schema for CKEditor 5 Elements: `ElementSchema` declares elements in the model schema from a simple definition,
4
+ e.g. a JSON file, with three types of elements (`empty`, `block`, `container`), and rejects definitions that are
5
+ contradictory.
6
+
7
+ ## Installation
8
+
9
+ This package is part of `ckeditor5-elements`. Install the whole package to use it:
10
+
11
+ ```sh
12
+ npm install ckeditor5 ckeditor5-elements
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```json
18
+ {
19
+ "note": { "type": "container", "allowAttributes": ["type"] },
20
+ "title": { "type": "block", "allowIn": ["note"] },
21
+ "badge": { "type": "empty", "isInline": true, "allowAttributes": ["color"] }
22
+ }
23
+ ```
24
+
25
+ ```ts
26
+ import { ElementSchema } from 'ckeditor5-elements';
27
+ import schema from './schema.json';
28
+
29
+ // In the editor config:
30
+ plugins: [..., ElementSchema],
31
+ elementSchema: schema,
32
+ elementSchemaConverters: true // Optional: converts the elements one to one, as `div` and `span`
33
+ ```
34
+
35
+ The `empty` and `container` elements can be selected as a whole, by a click and by the arrow keys, when `ElementSelectable`
36
+ (from `ckeditor5-elements-selectable`) is loaded too.
37
+
38
+ `validateElementSchema(schema)` checks a definition without an editor, e.g. in a test or in CI. In Node.js, import it from
39
+ `ckeditor5-elements/validate-schema`: the main entry loads CKEditor, which needs a browser.
40
+
41
+ See the [Element schema guide](https://ivankild.github.io/ckeditor5-elements/guide/schema) of the documentation.
42
+
43
+ ## License
44
+
45
+ MIT
@@ -0,0 +1,19 @@
1
+ import type { ElementSchema, ElementSchemaInput } from './index.js';
2
+ declare module 'ckeditor5' {
3
+ interface PluginsMap {
4
+ [ElementSchema.pluginName]: ElementSchema;
5
+ }
6
+ interface EditorConfig {
7
+ /**
8
+ * The elements to declare in the model schema: an object, e.g. a JSON file. See {@link ElementSchema}.
9
+ */
10
+ elementSchema?: ElementSchemaInput;
11
+ /**
12
+ * Whether to declare the converters of the elements of `elementSchema`, one to one: `div` or `span` with the name as
13
+ * the class, and the attributes as `data-*` attributes, in the data and in the editing view; `editingTag` of an
14
+ * element sets another tag for the editing view. See {@link ElementSchema}. Default: `false`.
15
+ */
16
+ elementSchemaConverters?: boolean;
17
+ }
18
+ }
19
+ //# sourceMappingURL=augmentation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augmentation.d.ts","sourceRoot":"","sources":["../src/augmentation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEpE,OAAO,QAAQ,WAAW,CAAC;IAC1B,UAAU,UAAU;QACnB,CAAC,aAAa,CAAC,UAAU,CAAC,EAAE,aAAa,CAAC;KAC1C;IAED,UAAU,YAAY;QACrB;;WAEG;QACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;QAEnC;;;;WAIG;QACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;KAClC;CACD"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=augmentation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"augmentation.js","sourceRoot":"","sources":["../src/augmentation.ts"],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import type { ElementSchemaKind } from './types.js';
2
+ /**
3
+ * The root can hold blocks, containers and block-level empty elements, like a container.
4
+ */
5
+ export declare const ROOT: ElementSchemaKind;
6
+ /**
7
+ * Returns why `parent` cannot contain `child` (an element, or `'$text'`), or `null` when it can.
8
+ */
9
+ export declare function whyNot(parent: ElementSchemaKind, child: ElementSchemaKind | '$text'): string | null;
10
+ //# sourceMappingURL=canHold.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canHold.d.ts","sourceRoot":"","sources":["../src/canHold.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;GAEG;AACH,eAAO,MAAM,IAAI,EAAE,iBAA0D,CAAC;AAE9E;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,iBAAiB,EAAE,KAAK,EAAE,iBAAiB,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAkBnG"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The root can hold blocks, containers and block-level empty elements, like a container.
3
+ */
4
+ export const ROOT = { type: 'container', isInline: false };
5
+ /**
6
+ * Returns why `parent` cannot contain `child` (an element, or `'$text'`), or `null` when it can.
7
+ */
8
+ export function whyNot(parent, child) {
9
+ const isText = child === '$text';
10
+ if (parent.type === 'empty') {
11
+ return 'an empty element cannot contain anything';
12
+ }
13
+ if (parent.type === 'block') {
14
+ const what = parent.isInline ? 'an inline text element' : 'a block';
15
+ return isText || child.isInline ? null : `${what} can contain only text and inline elements`;
16
+ }
17
+ if (isText) {
18
+ return 'a container cannot contain text: put the text in a block';
19
+ }
20
+ return child.isInline ? 'a container cannot contain inline elements: put them in a block' : null;
21
+ }
22
+ //# sourceMappingURL=canHold.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canHold.js","sourceRoot":"","sources":["../src/canHold.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,MAAM,IAAI,GAAsB,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC;AAE9E;;GAEG;AACH,MAAM,UAAU,MAAM,CAAC,MAAyB,EAAE,KAAkC;IACnF,MAAM,MAAM,GAAG,KAAK,KAAK,OAAO,CAAC;IAEjC,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC7B,OAAO,0CAA0C,CAAC;IACnD,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC7B,MAAM,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,SAAS,CAAC;QAEpE,OAAO,MAAM,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,4CAA4C,CAAC;IAC9F,CAAC;IAED,IAAI,MAAM,EAAE,CAAC;QACZ,OAAO,0DAA0D,CAAC;IACnE,CAAC;IAED,OAAO,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,iEAAiE,CAAC,CAAC,CAAC,IAAI,CAAC;AAClG,CAAC"}
@@ -0,0 +1,41 @@
1
+ import type { ModelSchemaItemDefinition } from 'ckeditor5';
2
+ import type { ElementSchemaInput } from './types.js';
3
+ /**
4
+ * The result of {@link compileElementSchema}.
5
+ */
6
+ export interface CompiledElementSchema {
7
+ /**
8
+ * The items to register in CKEditor's schema, by name.
9
+ */
10
+ items: [name: string, definition: ModelSchemaItemDefinition][];
11
+ /**
12
+ * The `allowChildren` of the elements, as the places to add to the children: `schema.extend(child, { allowIn: parent })`.
13
+ * The child can be an element of another plugin, which is extended, not registered.
14
+ */
15
+ children: {
16
+ parent: string;
17
+ child: string;
18
+ }[];
19
+ }
20
+ /**
21
+ * Translates a valid element schema to the definitions of CKEditor's schema. Each type is made like a generic item of
22
+ * CKEditor:
23
+ *
24
+ * * `container`: like `$container`: allowed in the root and in containers; holds what is allowed in a container: blocks,
25
+ * containers and block objects, not text.
26
+ * * `block`: like `$block`: a block, allowed in the root and in containers; holds text and inline objects.
27
+ * * `empty` and not inline: like `$blockObject`: an object, allowed where blocks are.
28
+ * * `empty` and inline: like `$inlineObject`: an object, allowed where text is, with the attributes of text.
29
+ * * `block` and inline: an inline element that holds text and inline elements, allowed where text is, with the attributes
30
+ * of text: like `$text`, but an element, so it can have attributes of its own.
31
+ * * `container` and inline: a container laid out in a line, e.g. with others in a block: allowed where text is, like every
32
+ * inline element, and holds the same as a container: blocks, not text.
33
+ *
34
+ * `isInline` is about the layout and the position of an element, so it is set for every type, and CKEditor's features and
35
+ * the converters can use it.
36
+ *
37
+ * `allowAttributes` is passed as it is. `allowIn` replaces the default places of the type. `allowChildren` adds to what
38
+ * the type holds, as in CKEditor.
39
+ */
40
+ export declare function compileElementSchema(input: ElementSchemaInput): CompiledElementSchema;
41
+ //# sourceMappingURL=compileElementSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileElementSchema.d.ts","sourceRoot":"","sources":["../src/compileElementSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,KAAK,EAAwB,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACrC;;OAEG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,yBAAyB,CAAC,EAAE,CAAC;IAE/D;;;OAGG;IACH,QAAQ,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC9C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,kBAAkB,GAAG,qBAAqB,CAarF"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Translates a valid element schema to the definitions of CKEditor's schema. Each type is made like a generic item of
3
+ * CKEditor:
4
+ *
5
+ * * `container`: like `$container`: allowed in the root and in containers; holds what is allowed in a container: blocks,
6
+ * containers and block objects, not text.
7
+ * * `block`: like `$block`: a block, allowed in the root and in containers; holds text and inline objects.
8
+ * * `empty` and not inline: like `$blockObject`: an object, allowed where blocks are.
9
+ * * `empty` and inline: like `$inlineObject`: an object, allowed where text is, with the attributes of text.
10
+ * * `block` and inline: an inline element that holds text and inline elements, allowed where text is, with the attributes
11
+ * of text: like `$text`, but an element, so it can have attributes of its own.
12
+ * * `container` and inline: a container laid out in a line, e.g. with others in a block: allowed where text is, like every
13
+ * inline element, and holds the same as a container: blocks, not text.
14
+ *
15
+ * `isInline` is about the layout and the position of an element, so it is set for every type, and CKEditor's features and
16
+ * the converters can use it.
17
+ *
18
+ * `allowAttributes` is passed as it is. `allowIn` replaces the default places of the type. `allowChildren` adds to what
19
+ * the type holds, as in CKEditor.
20
+ */
21
+ export function compileElementSchema(input) {
22
+ const items = [];
23
+ const children = [];
24
+ for (const [name, element] of Object.entries(input)) {
25
+ items.push([name, compileElement(element)]);
26
+ for (const child of element.allowChildren ?? []) {
27
+ children.push({ parent: name, child });
28
+ }
29
+ }
30
+ return { items, children };
31
+ }
32
+ function compileElement({ type, isInline, allowIn, allowAttributes }) {
33
+ // Where the element is allowed: the places of its type, or the given ones.
34
+ const places = (defaultPlaces) => allowIn ? { allowIn } : { allowWhere: defaultPlaces };
35
+ const attributes = allowAttributes ? { allowAttributes } : {};
36
+ if (type === 'empty' && isInline) {
37
+ return { inheritTypesFrom: '$inlineObject', allowAttributesOf: '$text', ...places('$text'), ...attributes };
38
+ }
39
+ if (type === 'empty') {
40
+ return { inheritTypesFrom: '$blockObject', ...places('$block'), ...attributes };
41
+ }
42
+ if (type === 'block' && isInline) {
43
+ return {
44
+ isInline: true,
45
+ allowContentOf: '$block',
46
+ allowAttributesOf: '$text',
47
+ ...places('$text'),
48
+ ...attributes
49
+ };
50
+ }
51
+ if (type === 'block') {
52
+ return { inheritTypesFrom: '$block', allowContentOf: '$block', ...places('$block'), ...attributes };
53
+ }
54
+ return {
55
+ allowContentOf: '$container',
56
+ ...(isInline ? { isInline: true, ...places('$text') } : places('$block')),
57
+ ...attributes
58
+ };
59
+ }
60
+ //# sourceMappingURL=compileElementSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileElementSchema.js","sourceRoot":"","sources":["../src/compileElementSchema.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAyB;IAC7D,MAAM,KAAK,GAAmC,EAAE,CAAC;IACjD,MAAM,QAAQ,GAAsC,EAAE,CAAC;IAEvD,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACrD,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,cAAc,CAAC,OAA+B,CAAC,CAAC,CAAC,CAAC;QAEpE,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,aAAa,IAAI,EAAE,EAAE,CAAC;YACjD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;QACxC,CAAC;IACF,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC5B,CAAC;AAED,SAAS,cAAc,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAwB;IACzF,2EAA2E;IAC3E,MAAM,MAAM,GAAG,CAAC,aAAqB,EAA6D,EAAE,CACnG,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;IACvD,MAAM,UAAU,GAAG,eAAe,CAAC,CAAC,CAAC,EAAE,eAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAE9D,IAAI,IAAI,KAAK,OAAO,IAAI,QAAQ,EAAE,CAAC;QAClC,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,GAAG,UAAU,EAAE,CAAC;IAC7G,CAAC;IAED,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACtB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,UAAU,EAAE,CAAC;IACjF,CAAC;IAED,IAAI,IAAI,KAAK,OAAO,IAAI,QAAQ,EAAE,CAAC;QAClC,OAAO;YACN,QAAQ,EAAE,IAAI;YACd,cAAc,EAAE,QAAQ;YACxB,iBAAiB,EAAE,OAAO;YAC1B,GAAG,MAAM,CAAC,OAAO,CAAC;YAClB,GAAG,UAAU;SACb,CAAC;IACH,CAAC;IAED,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;QACtB,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,cAAc,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,UAAU,EAAE,CAAC;IACrG,CAAC;IAED,OAAO;QACN,cAAc,EAAE,YAAY;QAC5B,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACzE,GAAG,UAAU;KACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { Editor } from 'ckeditor5';
2
+ import type { ElementSchemaElement, ElementSchemaInput } from './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.
14
+ */
15
+ export declare function convertElementSchema(editor: Editor, input: ElementSchemaInput): void;
16
+ //# sourceMappingURL=convertElementSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertElementSchema.d.ts","sourceRoot":"","sources":["../src/convertElementSchema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAE3E;;;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;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAgCpF"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * 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
3
+ * has text), a `div` for the rest. An inline container is a `div`: it holds blocks, which a `span` cannot hold.
4
+ */
5
+ export function getViewTag({ type, isInline }) {
6
+ return isInline && type !== 'container' ? 'span' : 'div';
7
+ }
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.
14
+ */
15
+ export function convertElementSchema(editor, input) {
16
+ const { conversion } = editor;
17
+ for (const [name, element] of Object.entries(input)) {
18
+ const { type, editingTag, allowAttributes } = element;
19
+ const tag = getViewTag(element);
20
+ const view = { name: tag, classes: name };
21
+ for (const key of allowAttributes ?? []) {
22
+ // The names of HTML attributes are lowercase, so the data has them in lowercase; the model keeps the key as it is.
23
+ conversion.attributeToAttribute({ model: { name, key }, view: `data-${key.toLowerCase()}` });
24
+ }
25
+ // Upcast, data downcast and editing downcast at once; what differs is declared with a higher priority.
26
+ conversion.elementToElement({ model: name, view });
27
+ if (type === 'empty') {
28
+ conversion.for('dataDowncast').elementToElement({
29
+ model: name,
30
+ view: (_element, { writer }) => writer.createEmptyElement(tag, { class: name }),
31
+ converterPriority: 'high'
32
+ });
33
+ }
34
+ if (editingTag) {
35
+ conversion.for('editingDowncast').elementToElement({
36
+ model: name,
37
+ view: { name: editingTag, classes: name },
38
+ converterPriority: 'high'
39
+ });
40
+ }
41
+ }
42
+ }
43
+ //# sourceMappingURL=convertElementSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertElementSchema.js","sourceRoot":"","sources":["../src/convertElementSchema.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAmD;IAC7F,OAAO,QAAQ,IAAI,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;AAC1D,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAAC,MAAc,EAAE,KAAyB;IAC7E,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAE9B,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACrD,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,OAA+B,CAAC;QAC9E,MAAM,GAAG,GAAG,UAAU,CAAC,OAA+B,CAAC,CAAC;QACxD,MAAM,IAAI,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QAE1C,KAAK,MAAM,GAAG,IAAI,eAAe,IAAI,EAAE,EAAE,CAAC;YACzC,mHAAmH;YACnH,UAAU,CAAC,oBAAoB,CAAC,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,QAAQ,GAAG,CAAC,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;QAC9F,CAAC;QAED,uGAAuG;QACvG,UAAU,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAEnD,IAAI,IAAI,KAAK,OAAO,EAAE,CAAC;YACtB,UAAU,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,gBAAgB,CAAC;gBAC/C,KAAK,EAAE,IAAI;gBACX,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;gBAC/E,iBAAiB,EAAE,MAAM;aACzB,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,UAAU,EAAE,CAAC;YAChB,UAAU,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,gBAAgB,CAAC;gBAClD,KAAK,EAAE,IAAI;gBACX,IAAI,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,IAAI,EAAE;gBACzC,iBAAiB,EAAE,MAAM;aACzB,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;AACF,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { Plugin } from 'ckeditor5';
2
+ /**
3
+ * Declares elements in the model schema of the editor from a simple definition, the `elementSchema` editor option: a
4
+ * plain object, e.g. a JSON file.
5
+ *
6
+ * ```json
7
+ * {
8
+ * "note": { "type": "container", "allowAttributes": ["type"] },
9
+ * "title": { "type": "block", "allowIn": ["note"] },
10
+ * "badge": { "type": "empty", "isInline": true, "allowAttributes": ["color"] }
11
+ * }
12
+ * ```
13
+ *
14
+ * Every element has one of three types, instead of CKEditor's many `is*` flags and generic items:
15
+ *
16
+ * * `empty`: has no content, like an image. It is an object, selected as a whole. With `isInline`, it is in a line of text.
17
+ * * `block`: can contain text and inline elements, like a paragraph. With `isInline`, it is an inline element with text,
18
+ * like a bold that is an element with attributes.
19
+ * * `container`: cannot contain text, but blocks, containers and empty elements, like a block quote.
20
+ *
21
+ * `allowAttributes` and `allowChildren` work as in CKEditor's schema. `allowIn` too, but it replaces the default places.
22
+ * See {@link ElementSchemaElement}.
23
+ *
24
+ * The schema is validated first, and a schema that is contradictory or refers to unknown elements is not accepted: the
25
+ * editor is not created, and the {@link ElementSchemaError} lists all the problems (see {@link validateElementSchema}).
26
+ *
27
+ * The elements are registered after the plugins are initialized (in `afterInit()`), so they can refer to the elements
28
+ * of other plugins, e.g. `paragraph`. Plugins that extend or convert the elements must do it in `afterInit()` too, or
29
+ * later; the converters can be declared at any time.
30
+ *
31
+ * The `empty` and `container` elements can be selected as a whole, by a click on them and by the arrow keys, when
32
+ * the `ElementSelectable` plugin is loaded too: the element schema does not depend on it, and uses it when it is there
33
+ * (with `elementSchemaConverters`, it warns when it is not).
34
+ *
35
+ * The plugin declares the schema only: how the elements look in the editor and in the data is declared with
36
+ * converters, or by the plugin when the `elementSchemaConverters` option is `true`: one to one, as `div` and `span`.
37
+ */
38
+ export default class ElementSchema extends Plugin {
39
+ static get pluginName(): 'ElementSchema';
40
+ afterInit(): void;
41
+ /**
42
+ * Makes the `empty` elements and the containers selectable as a whole, by a click on them and by the arrow keys, with
43
+ * `ElementSelectable`. Not the blocks: a click in a block puts the cursor in its text.
44
+ */
45
+ private _makeSelectable;
46
+ }
47
+ //# sourceMappingURL=elementSchema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementSchema.d.ts","sourceRoot":"","sources":["../src/elementSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAoB,MAAM,WAAW,CAAC;AAQrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,MAAM;IAChD,WAAkB,UAAU,IAAI,eAAe,CAE9C;IAEM,SAAS,IAAI,IAAI;IA+BxB;;;OAGG;IACH,OAAO,CAAC,eAAe;CAiBvB"}
@@ -0,0 +1,108 @@
1
+ import { Plugin } from 'ckeditor5';
2
+ import { findPlugin } from 'ckeditor5-elements-core';
3
+ import { compileElementSchema } from './compileElementSchema.js';
4
+ import { convertElementSchema } from './convertElementSchema.js';
5
+ import ElementSchemaError from './elementSchemaError.js';
6
+ import { validateElementSchema } from './validateElementSchema.js';
7
+ /**
8
+ * Declares elements in the model schema of the editor from a simple definition, the `elementSchema` editor option: a
9
+ * plain object, e.g. a JSON file.
10
+ *
11
+ * ```json
12
+ * {
13
+ * "note": { "type": "container", "allowAttributes": ["type"] },
14
+ * "title": { "type": "block", "allowIn": ["note"] },
15
+ * "badge": { "type": "empty", "isInline": true, "allowAttributes": ["color"] }
16
+ * }
17
+ * ```
18
+ *
19
+ * Every element has one of three types, instead of CKEditor's many `is*` flags and generic items:
20
+ *
21
+ * * `empty`: has no content, like an image. It is an object, selected as a whole. With `isInline`, it is in a line of text.
22
+ * * `block`: can contain text and inline elements, like a paragraph. With `isInline`, it is an inline element with text,
23
+ * like a bold that is an element with attributes.
24
+ * * `container`: cannot contain text, but blocks, containers and empty elements, like a block quote.
25
+ *
26
+ * `allowAttributes` and `allowChildren` work as in CKEditor's schema. `allowIn` too, but it replaces the default places.
27
+ * See {@link ElementSchemaElement}.
28
+ *
29
+ * The schema is validated first, and a schema that is contradictory or refers to unknown elements is not accepted: the
30
+ * editor is not created, and the {@link ElementSchemaError} lists all the problems (see {@link validateElementSchema}).
31
+ *
32
+ * The elements are registered after the plugins are initialized (in `afterInit()`), so they can refer to the elements
33
+ * of other plugins, e.g. `paragraph`. Plugins that extend or convert the elements must do it in `afterInit()` too, or
34
+ * later; the converters can be declared at any time.
35
+ *
36
+ * The `empty` and `container` elements can be selected as a whole, by a click on them and by the arrow keys, when
37
+ * the `ElementSelectable` plugin is loaded too: the element schema does not depend on it, and uses it when it is there
38
+ * (with `elementSchemaConverters`, it warns when it is not).
39
+ *
40
+ * The plugin declares the schema only: how the elements look in the editor and in the data is declared with
41
+ * converters, or by the plugin when the `elementSchemaConverters` option is `true`: one to one, as `div` and `span`.
42
+ */
43
+ export default class ElementSchema extends Plugin {
44
+ static get pluginName() {
45
+ return 'ElementSchema';
46
+ }
47
+ afterInit() {
48
+ const input = this.editor.config.get('elementSchema');
49
+ if (input === undefined) {
50
+ return;
51
+ }
52
+ const schema = this.editor.model.schema;
53
+ const issues = validateElementSchema(input, { external: getExternalKinds(schema) });
54
+ if (issues.length) {
55
+ throw new ElementSchemaError(issues);
56
+ }
57
+ const { items, children } = compileElementSchema(input);
58
+ for (const [name, definition] of items) {
59
+ schema.register(name, definition);
60
+ }
61
+ for (const { parent, child } of children) {
62
+ schema.extend(child, { allowIn: parent });
63
+ }
64
+ this._makeSelectable(input);
65
+ if (this.editor.config.get('elementSchemaConverters')) {
66
+ convertElementSchema(this.editor, input);
67
+ }
68
+ }
69
+ /**
70
+ * Makes the `empty` elements and the containers selectable as a whole, by a click on them and by the arrow keys, with
71
+ * `ElementSelectable`. Not the blocks: a click in a block puts the cursor in its text.
72
+ */
73
+ _makeSelectable(input) {
74
+ const names = Object.entries(input)
75
+ .filter(([, element]) => element.type === 'empty' || element.type === 'container')
76
+ .map(([name]) => name);
77
+ const selectable = findPlugin(this.editor, 'ElementSelectable', isSelectablePlugin);
78
+ if (selectable) {
79
+ selectable.add(...names);
80
+ }
81
+ else if (names.length && this.editor.config.get('elementSchemaConverters')) {
82
+ // The converters make the elements, and nothing selects them: say it, as it is a silent loss. Not CKEditor's
83
+ // `logWarning()`: it links to CKEditor's list of errors, which does not have this one.
84
+ // eslint-disable-next-line no-console -- A warning for the developer, once, when the editor is created.
85
+ console.warn(`ElementSchema: load ElementSelectable to select the elements of the schema as a whole: ${names.join(', ')}.`);
86
+ }
87
+ }
88
+ }
89
+ function isSelectablePlugin(plugin) {
90
+ return 'add' in plugin && typeof plugin.add === 'function';
91
+ }
92
+ /**
93
+ * Returns the kinds of the elements of other plugins: inline or not, and `empty` for objects, `block` for what can
94
+ * contain text, `container` for the rest. The generic items (`$block`, …) are not elements.
95
+ */
96
+ function getExternalKinds(schema) {
97
+ const kinds = {};
98
+ for (const name of Object.keys(schema.getDefinitions())) {
99
+ if (!name.startsWith('$')) {
100
+ kinds[name] = {
101
+ isInline: schema.isInline(name),
102
+ type: schema.isObject(name) ? 'empty' : schema.checkChild(name, '$text') ? 'block' : 'container'
103
+ };
104
+ }
105
+ }
106
+ return kinds;
107
+ }
108
+ //# sourceMappingURL=elementSchema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementSchema.js","sourceRoot":"","sources":["../src/elementSchema.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,12 @@
1
+ import type { ElementSchemaIssue } from './types.js';
2
+ /**
3
+ * Thrown when the element schema is not valid. It lists all the problems, and has them in {@link issues}.
4
+ */
5
+ export default class ElementSchemaError extends Error {
6
+ /**
7
+ * The problems of the schema.
8
+ */
9
+ readonly issues: readonly ElementSchemaIssue[];
10
+ constructor(issues: readonly ElementSchemaIssue[]);
11
+ }
12
+ //# sourceMappingURL=elementSchemaError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementSchemaError.d.ts","sourceRoot":"","sources":["../src/elementSchemaError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAErD;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,KAAK;IACpD;;OAEG;IACH,SAAgB,MAAM,EAAE,SAAS,kBAAkB,EAAE,CAAC;gBAE1C,MAAM,EAAE,SAAS,kBAAkB,EAAE;CASjD"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Thrown when the element schema is not valid. It lists all the problems, and has them in {@link issues}.
3
+ */
4
+ export default class ElementSchemaError extends Error {
5
+ /**
6
+ * The problems of the schema.
7
+ */
8
+ issues;
9
+ constructor(issues) {
10
+ super(`The element schema is not valid (${String(issues.length)} ${issues.length === 1 ? 'problem' : 'problems'}):\n` +
11
+ issues.map(({ path, message }) => `- ${path ? `${path}: ` : ''}${message}`).join('\n'));
12
+ this.name = 'ElementSchemaError';
13
+ this.issues = issues;
14
+ }
15
+ }
16
+ //# sourceMappingURL=elementSchemaError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"elementSchemaError.js","sourceRoot":"","sources":["../src/elementSchemaError.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,kBAAmB,SAAQ,KAAK;IACpD;;OAEG;IACa,MAAM,CAAgC;IAEtD,YAAY,MAAqC;QAChD,KAAK,CACJ,oCAAoC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,MAAM;YAC9G,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CACvF,CAAC;QAEF,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;CACD"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Element schema: declare elements in the model schema from a simple definition, e.g. a JSON file, with three types of
3
+ * elements (`empty`, `block`, `container`), and a validation that rejects contradictory definitions.
4
+ *
5
+ * @module ckeditor5-elements-schema
6
+ */
7
+ export { default as ElementSchema } from './elementSchema.js';
8
+ export * from './validate.js';
9
+ import './augmentation.js';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAG9D,cAAc,eAAe,CAAC;AAE9B,OAAO,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Element schema: declare elements in the model schema from a simple definition, e.g. a JSON file, with three types of
3
+ * elements (`empty`, `block`, `container`), and a validation that rejects contradictory definitions.
4
+ *
5
+ * @module ckeditor5-elements-schema
6
+ */
7
+ // Plugins.
8
+ export { default as ElementSchema } from './elementSchema.js';
9
+ // Validation and compiling, which do not need an editor (also in `validate.ts`, for Node.js).
10
+ export * from './validate.js';
11
+ import './augmentation.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,WAAW;AACX,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAE9D,8FAA8F;AAC9F,cAAc,eAAe,CAAC;AAE9B,OAAO,mBAAmB,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { ElementSchemaKind } from './types.js';
2
+ /**
3
+ * Reports a problem of the schema, at the path.
4
+ */
5
+ export type Report = (path: string, message: string) => void;
6
+ export declare const ELEMENT_KEYS: string[];
7
+ export declare const ELEMENT_NAME: RegExp;
8
+ export declare const ATTRIBUTE_NAME: RegExp;
9
+ export declare const TAG_NAME: RegExp;
10
+ export declare function readKind(definition: Record<string, unknown>, path: string, report: Report): ElementSchemaKind | null;
11
+ /**
12
+ * Reads a list of names, and reports what is not a list of unique, non-empty strings. Returns the list, or
13
+ * `undefined` when it is missing.
14
+ */
15
+ export declare function readNames(definition: Record<string, unknown>, key: string, path: string, report: Report): string[] | undefined;
16
+ export declare function checkKeys(object: Record<string, unknown>, allowed: readonly string[], path: string, report: Report): void;
17
+ export declare function isRecord(value: unknown): value is Record<string, unknown>;
18
+ //# sourceMappingURL=readDefinition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readDefinition.d.ts","sourceRoot":"","sources":["../src/readDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGpD;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;AAG7D,eAAO,MAAM,YAAY,UAAoF,CAAC;AAE9G,eAAO,MAAM,YAAY,QAAwB,CAAC;AAClD,eAAO,MAAM,cAAc,QAAuB,CAAC;AACnD,eAAO,MAAM,QAAQ,QAAkC,CAAC;AAExD,wBAAgB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAuBpH;AAED;;;GAGG;AACH,wBAAgB,SAAS,CACxB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACnC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACZ,MAAM,EAAE,GAAG,SAAS,CA4BtB;AAED,wBAAgB,SAAS,CACxB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GACZ,IAAI,CASN;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAEzE"}