@ebl-vue/editor-full 1.0.8

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 (101) hide show
  1. package/.postcssrc.yml +33 -0
  2. package/LICENSE +21 -0
  3. package/README.md +1 -0
  4. package/dist/index.d.ts +5 -0
  5. package/dist/index.mjs +2565 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/package.json +55 -0
  8. package/postcss.config.js +15 -0
  9. package/src/components/Editor/Editor.vue +209 -0
  10. package/src/components/index.ts +27 -0
  11. package/src/constants/index.ts +1 -0
  12. package/src/i18n/zh-cn.ts +151 -0
  13. package/src/icons/index.ts +78 -0
  14. package/src/index.ts +11 -0
  15. package/src/installer.ts +22 -0
  16. package/src/plugins/alert/index.css +150 -0
  17. package/src/plugins/alert/index.ts +463 -0
  18. package/src/plugins/block-alignment/index.css +9 -0
  19. package/src/plugins/block-alignment/index.ts +116 -0
  20. package/src/plugins/block-alignment/readme.md +1 -0
  21. package/src/plugins/code/LICENSE +21 -0
  22. package/src/plugins/code/index.css +120 -0
  23. package/src/plugins/code/index.ts +530 -0
  24. package/src/plugins/code/utils/string.ts +34 -0
  25. package/src/plugins/color-picker/index.ts +138 -0
  26. package/src/plugins/color-picker/styles.css +27 -0
  27. package/src/plugins/delimiter/index.css +14 -0
  28. package/src/plugins/delimiter/index.ts +122 -0
  29. package/src/plugins/drag-drop/index.css +19 -0
  30. package/src/plugins/drag-drop/index.ts +151 -0
  31. package/src/plugins/drag-drop/readme.md +1 -0
  32. package/src/plugins/header/H1.ts +405 -0
  33. package/src/plugins/header/H2.ts +403 -0
  34. package/src/plugins/header/H3.ts +404 -0
  35. package/src/plugins/header/H4.ts +405 -0
  36. package/src/plugins/header/H5.ts +405 -0
  37. package/src/plugins/header/H6.ts +406 -0
  38. package/src/plugins/header/index.css +20 -0
  39. package/src/plugins/header/index.ts +15 -0
  40. package/src/plugins/header/types.d.ts +46 -0
  41. package/src/plugins/indent/index.css +86 -0
  42. package/src/plugins/indent/index.ts +697 -0
  43. package/src/plugins/inline-code/index.css +11 -0
  44. package/src/plugins/inline-code/index.ts +205 -0
  45. package/src/plugins/list/ListRenderer/ChecklistRenderer.ts +211 -0
  46. package/src/plugins/list/ListRenderer/ListRenderer.ts +73 -0
  47. package/src/plugins/list/ListRenderer/OrderedListRenderer.ts +123 -0
  48. package/src/plugins/list/ListRenderer/UnorderedListRenderer.ts +123 -0
  49. package/src/plugins/list/ListRenderer/index.ts +6 -0
  50. package/src/plugins/list/ListTabulator/index.ts +1179 -0
  51. package/src/plugins/list/index.ts +502 -0
  52. package/src/plugins/list/styles/CssPrefix.ts +4 -0
  53. package/src/plugins/list/styles/icons/index.ts +10 -0
  54. package/src/plugins/list/styles/input.css +36 -0
  55. package/src/plugins/list/styles/list.css +165 -0
  56. package/src/plugins/list/types/Elements.ts +14 -0
  57. package/src/plugins/list/types/ItemMeta.ts +40 -0
  58. package/src/plugins/list/types/ListParams.ts +102 -0
  59. package/src/plugins/list/types/ListRenderer.ts +6 -0
  60. package/src/plugins/list/types/OlCounterType.ts +63 -0
  61. package/src/plugins/list/types/index.ts +14 -0
  62. package/src/plugins/list/utils/focusItem.ts +18 -0
  63. package/src/plugins/list/utils/getChildItems.ts +40 -0
  64. package/src/plugins/list/utils/getItemChildWrapper.ts +10 -0
  65. package/src/plugins/list/utils/getItemContentElement.ts +10 -0
  66. package/src/plugins/list/utils/getSiblings.ts +52 -0
  67. package/src/plugins/list/utils/isLastItem.ts +9 -0
  68. package/src/plugins/list/utils/itemHasSublist.ts +10 -0
  69. package/src/plugins/list/utils/normalizeData.ts +84 -0
  70. package/src/plugins/list/utils/removeChildWrapperIfEmpty.ts +31 -0
  71. package/src/plugins/list/utils/renderToolboxInput.ts +105 -0
  72. package/src/plugins/list/utils/stripNumbers.ts +7 -0
  73. package/src/plugins/list/utils/type-guards.ts +8 -0
  74. package/src/plugins/list.md +15 -0
  75. package/src/plugins/marker/index.css +4 -0
  76. package/src/plugins/marker/index.ts +187 -0
  77. package/src/plugins/paragraph/index.css +23 -0
  78. package/src/plugins/paragraph/index.ts +380 -0
  79. package/src/plugins/paragraph/types/icons.d.ts +4 -0
  80. package/src/plugins/paragraph/utils/makeFragment.ts +17 -0
  81. package/src/plugins/quote/index.css +26 -0
  82. package/src/plugins/quote/index.ts +206 -0
  83. package/src/plugins/table/index.ts +4 -0
  84. package/src/plugins/table/plugin.ts +254 -0
  85. package/src/plugins/table/style.css +388 -0
  86. package/src/plugins/table/table.ts +1192 -0
  87. package/src/plugins/table/toolbox.ts +165 -0
  88. package/src/plugins/table/utils/dom.ts +128 -0
  89. package/src/plugins/table/utils/popover.ts +172 -0
  90. package/src/plugins/table/utils/throttled.ts +22 -0
  91. package/src/plugins/underline/index.css +3 -0
  92. package/src/plugins/underline/index.ts +216 -0
  93. package/src/plugins/undo/index.ts +509 -0
  94. package/src/plugins/undo/observer.ts +101 -0
  95. package/src/style.css +89 -0
  96. package/src/utils/index.ts +15 -0
  97. package/src/utils/install.ts +19 -0
  98. package/tsconfig.json +37 -0
  99. package/types/index.d.ts +13 -0
  100. package/types/plugins/index.d.ts +0 -0
  101. package/vite.config.ts +79 -0
@@ -0,0 +1,11 @@
1
+ .inline-code {
2
+ background: rgba(250, 239, 240, 0.78);
3
+ color: #b44437;
4
+ padding: 3px 4px;
5
+ border-radius: 5px;
6
+ margin: 0 1px;
7
+ font-family: inherit;
8
+ font-size: 0.86em;
9
+ font-weight: 500;
10
+ letter-spacing: 0.3px;
11
+ }
@@ -0,0 +1,205 @@
1
+ /**
2
+ * Build styles
3
+ */
4
+ import './index.css';
5
+ const IconBrackets = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
6
+ <path d="M9 8L5 12L9 16" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
7
+ <path d="M15 8L19 12L15 16" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
8
+ </svg>
9
+ `;
10
+ import { API, InlineTool, InlineToolConstructorOptions, SanitizerConfig } from "@editorjs/editorjs";
11
+
12
+ interface IconClasses {
13
+ base: string;
14
+ active: string;
15
+ }
16
+
17
+ /**
18
+ * Inline Code Tool for the Editor.js
19
+ *
20
+ * Allows to wrap inline fragment and style it somehow.
21
+ */
22
+ export default class InlineCode implements InlineTool {
23
+ /**
24
+ * Editor.js API
25
+ */
26
+ private api: API;
27
+ /**
28
+ * Button element for the toolbar
29
+ */
30
+ private button: HTMLButtonElement | null;
31
+ /**
32
+ * Tag representing the term
33
+ */
34
+ private tag: string = 'CODE';
35
+ /**
36
+ * CSS classes for the icon
37
+ */
38
+ private iconClasses: IconClasses;
39
+
40
+ /**
41
+ * Class name for term-tag
42
+ *
43
+ * @type {string}
44
+ */
45
+ static get CSS(): string {
46
+ return 'inline-code';
47
+ }
48
+
49
+ constructor({ api }: InlineToolConstructorOptions) {
50
+ this.api = api;
51
+
52
+ this.button = null;
53
+
54
+ this.iconClasses = {
55
+ base: this.api.styles.inlineToolButton,
56
+ active: this.api.styles.inlineToolButtonActive,
57
+ };
58
+ }
59
+
60
+ /**
61
+ * Specifies Tool as Inline Toolbar Tool
62
+ *
63
+ * @return {boolean}
64
+ */
65
+ static get isInline(): boolean {
66
+ return true;
67
+ }
68
+
69
+ /**
70
+ * Create button element for Toolbar
71
+ *
72
+ * @return {HTMLElement}
73
+ */
74
+ render(): HTMLElement {
75
+ this.button = document.createElement('button');
76
+ this.button.type = 'button';
77
+ this.button.classList.add(this.iconClasses.base);
78
+ this.button.innerHTML = this.toolboxIcon;
79
+
80
+ return this.button;
81
+ }
82
+
83
+ /**
84
+ * Wrap/Unwrap selected fragment
85
+ *
86
+ * @param {Range} range - selected fragment
87
+ */
88
+ surround(range: Range): void {
89
+ if (!range) {
90
+ return;
91
+ }
92
+
93
+ let termWrapper = this.api.selection.findParentTag(this.tag, InlineCode.CSS) as HTMLElement;
94
+
95
+ /**
96
+ * If the start or end of the selection range is within a highlighted block
97
+ */
98
+ if (termWrapper) {
99
+ this.unwrap(termWrapper);
100
+ } else {
101
+ const existingCodeTag = range.commonAncestorContainer.parentElement?.querySelector(this.tag);
102
+ if (!existingCodeTag) {
103
+ this.wrap(range);
104
+ }
105
+ }
106
+ }
107
+
108
+ /**
109
+ * Wrap selection with term-tag
110
+ *
111
+ * @param {Range} range - selected fragment
112
+ */
113
+ wrap(range: Range): void {
114
+ /**
115
+ * Create a wrapper for highlighting
116
+ */
117
+ let span = document.createElement(this.tag);
118
+
119
+ span.classList.add(InlineCode.CSS);
120
+
121
+ /**
122
+ * SurroundContent throws an error if the Range splits a non-Text node with only one of its boundary points
123
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Range/surroundContents}
124
+ *
125
+ * // range.surroundContents(span);
126
+ */
127
+ span.appendChild(range.extractContents());
128
+ range.insertNode(span);
129
+
130
+ /**
131
+ * Expand (add) selection to highlighted block
132
+ */
133
+ this.api.selection.expandToTag(span);
134
+ }
135
+
136
+ /**
137
+ * Unwrap term-tag
138
+ *
139
+ * @param {HTMLElement} termWrapper - term wrapper tag
140
+ */
141
+ unwrap(termWrapper: HTMLElement): void {
142
+ /**
143
+ * Expand selection to all term-tag
144
+ */
145
+ this.api.selection.expandToTag(termWrapper);
146
+
147
+ const sel = window.getSelection();
148
+ if (!sel) return;
149
+
150
+ const range = sel.getRangeAt(0);
151
+ const unwrappedContent = range.extractContents();
152
+
153
+ /**
154
+ * Remove empty term-tag
155
+ */
156
+ termWrapper.parentNode?.removeChild(termWrapper);
157
+
158
+ /**
159
+ * Insert extracted content
160
+ */
161
+ range.insertNode(unwrappedContent);
162
+
163
+ /**
164
+ * Restore selection
165
+ */
166
+ sel.removeAllRanges();
167
+ sel.addRange(range);
168
+ }
169
+
170
+ /**
171
+ * Check and change Term's state for current selection
172
+ *
173
+ * @return {boolean}
174
+ */
175
+ checkState(): boolean {
176
+ const termTag = this.api.selection.findParentTag(this.tag, InlineCode.CSS);
177
+
178
+ if (this.button) {
179
+ this.button.classList.toggle(this.iconClasses.active, !!termTag);
180
+ }
181
+
182
+ return !!termTag;
183
+ }
184
+
185
+
186
+ /**
187
+ * Get Tool icon's SVG
188
+ * @return {string}
189
+ */
190
+ get toolboxIcon(): string {
191
+ return IconBrackets;
192
+ }
193
+
194
+ /**
195
+ * Sanitizer rule
196
+ * @return {SanitizerConfig}
197
+ */
198
+ static get sanitize(): SanitizerConfig {
199
+ return {
200
+ code: {
201
+ class: InlineCode.CSS,
202
+ },
203
+ };
204
+ }
205
+ }
@@ -0,0 +1,211 @@
1
+ import type { ChecklistItemMeta } from '../types/ItemMeta';
2
+ import type { ListConfig } from '../types/ListParams';
3
+ import { isEmpty, make } from '@editorjs/dom';
4
+ import { DefaultListCssClasses } from './ListRenderer';
5
+ import type { ListCssClasses, ListRendererInterface } from './ListRenderer';
6
+ import { CssPrefix } from '../styles/CssPrefix';
7
+ const IconCheck = `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
8
+ <path d="M7 12L10.4884 15.8372C10.5677 15.9245 10.705 15.9245 10.7844 15.8372L17 9" stroke="black" stroke-width="2" stroke-linecap="round"/>
9
+ </svg>
10
+ `;
11
+
12
+ /**
13
+ * Interface that represents all list used only in unordered list rendering
14
+ */
15
+ interface ChecklistCssClasses extends ListCssClasses {
16
+ /**
17
+ * CSS class of the checklist
18
+ */
19
+ checklist: string;
20
+
21
+ /**
22
+ * CSS class of the checked checkbox
23
+ */
24
+ itemChecked: string;
25
+
26
+ /**
27
+ * CSS class for the special hover behavior of the checkboc
28
+ */
29
+ noHover: string;
30
+
31
+ /**
32
+ * CSS class of the checkbox
33
+ */
34
+ checkbox: string;
35
+
36
+ /**
37
+ * CSS class of the checkbox container
38
+ */
39
+ checkboxContainer: string;
40
+
41
+ /**
42
+ * CSS class for disabled checkbox check
43
+ */
44
+ checkboxCheckDisabled: string;
45
+ }
46
+
47
+ /**
48
+ * Class that is responsible for checklist rendering
49
+ */
50
+ export class CheckListRenderer implements ListRendererInterface<ChecklistItemMeta> {
51
+ /**
52
+ * Tool's configuration
53
+ */
54
+ protected config?: ListConfig;
55
+
56
+ /**
57
+ * Is Editorjs List Tool read-only option
58
+ */
59
+ private readOnly: boolean;
60
+
61
+ /**
62
+ * Getter for all CSS classes used in unordered list rendering
63
+ */
64
+ private static get CSS(): ChecklistCssClasses {
65
+ return {
66
+ ...DefaultListCssClasses,
67
+ checklist: `${CssPrefix}-checklist`,
68
+ itemChecked: `${CssPrefix}__checkbox--checked`,
69
+ noHover: `${CssPrefix}__checkbox--no-hover`,
70
+ checkbox: `${CssPrefix}__checkbox-check`,
71
+ checkboxContainer: `${CssPrefix}__checkbox`,
72
+ checkboxCheckDisabled: `${CssPrefix}__checkbox-check--disabled`,
73
+ };
74
+ }
75
+
76
+ /**
77
+ * Assign passed readonly mode and config to relevant class properties
78
+ * @param readonly - read-only mode flag
79
+ * @param config - user config for Tool
80
+ */
81
+ constructor(readonly: boolean, config?: ListConfig) {
82
+ this.config = config;
83
+ this.readOnly = readonly;
84
+ }
85
+
86
+ /**
87
+ * Renders ul wrapper for list
88
+ * @param isRoot - boolean variable that represents level of the wrappre (root or childList)
89
+ * @returns - created html ul element
90
+ */
91
+ public renderWrapper(isRoot: boolean): HTMLUListElement {
92
+ let wrapperElement: HTMLUListElement;
93
+
94
+ /**
95
+ * Check if it's root level
96
+ */
97
+ if (isRoot === true) {
98
+ wrapperElement = make('ul', [CheckListRenderer.CSS.wrapper, CheckListRenderer.CSS.checklist]) as HTMLUListElement;
99
+
100
+ /**
101
+ * Delegate clicks from wrapper to items
102
+ */
103
+ wrapperElement.addEventListener('click', (event) => {
104
+ const target = event.target as Element | null;
105
+
106
+ if (target) {
107
+ const checkbox = target.closest(`.${CheckListRenderer.CSS.checkboxContainer}`);
108
+
109
+ if (checkbox && checkbox.contains(target)) {
110
+ this.toggleCheckbox(checkbox);
111
+ }
112
+ }
113
+ });
114
+ } else {
115
+ wrapperElement = make('ul', [CheckListRenderer.CSS.checklist, CheckListRenderer.CSS.itemChildren]) as HTMLUListElement;
116
+ }
117
+
118
+ return wrapperElement;
119
+ }
120
+
121
+ /**
122
+ * Redners list item element
123
+ * @param content - content used in list item rendering
124
+ * @param meta - meta of the list item used in rendering of the checklist
125
+ * @returns - created html list item element
126
+ */
127
+ public renderItem(content: string, meta: ChecklistItemMeta): HTMLLIElement {
128
+ const itemWrapper = make('li', [CheckListRenderer.CSS.item, CheckListRenderer.CSS.item]);
129
+ const itemContent = make('div', CheckListRenderer.CSS.itemContent, {
130
+ innerHTML: content,
131
+ contentEditable: (!this.readOnly).toString(),
132
+ });
133
+
134
+ const checkbox = make('span', CheckListRenderer.CSS.checkbox);
135
+ const checkboxContainer = make('div', CheckListRenderer.CSS.checkboxContainer);
136
+
137
+ if (meta.checked === true) {
138
+ checkboxContainer.classList.add(CheckListRenderer.CSS.itemChecked);
139
+ }
140
+
141
+ // Disable checkbox interaction in read-only mode
142
+ if (this.readOnly) {
143
+ checkboxContainer.classList.add(CheckListRenderer.CSS.checkboxCheckDisabled);
144
+ }
145
+
146
+ checkbox.innerHTML = IconCheck;
147
+ checkboxContainer.appendChild(checkbox);
148
+
149
+ itemWrapper.appendChild(checkboxContainer);
150
+ itemWrapper.appendChild(itemContent);
151
+
152
+ return itemWrapper as HTMLLIElement;
153
+ }
154
+
155
+ /**
156
+ * Return the item content
157
+ * @param item - item wrapper (<li>)
158
+ * @returns - item content string
159
+ */
160
+ public getItemContent(item: Element): string {
161
+ const contentNode = item.querySelector(`.${CheckListRenderer.CSS.itemContent}`);
162
+
163
+ if (!contentNode) {
164
+ return '';
165
+ }
166
+
167
+ if (isEmpty(contentNode)) {
168
+ return '';
169
+ }
170
+
171
+ return contentNode.innerHTML;
172
+ }
173
+
174
+ /**
175
+ * Return meta object of certain element
176
+ * @param item - will be returned meta information of this item
177
+ * @returns Item meta object
178
+ */
179
+ public getItemMeta(item: Element): ChecklistItemMeta {
180
+ const checkbox = item.querySelector(`.${CheckListRenderer.CSS.checkboxContainer}`);
181
+
182
+ return {
183
+ checked: checkbox ? checkbox.classList.contains(CheckListRenderer.CSS.itemChecked) : false,
184
+ };
185
+ }
186
+
187
+ /**
188
+ * Returns default item meta used on creation of the new item
189
+ */
190
+ public composeDefaultMeta(): ChecklistItemMeta {
191
+ return { checked: false };
192
+ }
193
+
194
+ /**
195
+ * Toggle checklist item state
196
+ * @param checkbox - checkbox element to be toggled
197
+ */
198
+ private toggleCheckbox(checkbox: Element): void {
199
+ checkbox.classList.toggle(CheckListRenderer.CSS.itemChecked);
200
+ checkbox.classList.add(CheckListRenderer.CSS.noHover);
201
+ checkbox.addEventListener('mouseleave', () => this.removeSpecialHoverBehavior(checkbox), { once: true });
202
+ }
203
+
204
+ /**
205
+ * Removes class responsible for special hover behavior on an item
206
+ * @param el - item wrapper
207
+ */
208
+ private removeSpecialHoverBehavior(el: Element): void {
209
+ el.classList.remove(CheckListRenderer.CSS.noHover);
210
+ }
211
+ }
@@ -0,0 +1,73 @@
1
+ import { CssPrefix } from '../styles/CssPrefix';
2
+ /**
3
+ * CSS classes for the List Tool
4
+ */
5
+ export const DefaultListCssClasses = {
6
+ wrapper: CssPrefix,
7
+ item: `${CssPrefix}__item`,
8
+ itemContent: `${CssPrefix}__item-content`,
9
+ itemChildren: `${CssPrefix}__item-children`,
10
+ };
11
+
12
+ /**
13
+ * Interface that represents default list css classes
14
+ */
15
+ export interface ListCssClasses {
16
+ /**
17
+ * CSS class of the whole list wrapper
18
+ */
19
+ wrapper: string;
20
+
21
+ /**
22
+ * CSS class of the list item
23
+ */
24
+ item: string;
25
+
26
+ /**
27
+ * CSS class of the list item content element
28
+ */
29
+ itemContent: string;
30
+
31
+ /**
32
+ * CSS class of the children item wrapper
33
+ */
34
+ itemChildren: string;
35
+ }
36
+
37
+ /**
38
+ * Interface that represents all list renderer classes
39
+ */
40
+ export interface ListRendererInterface<ItemMeta> {
41
+ /**
42
+ * Renders wrapper for list
43
+ * @param isRoot - boolean variable that represents level of the wrappre (root or childList)
44
+ * @returns - created html ul element
45
+ */
46
+ renderWrapper: (isRoot: boolean) => HTMLElement;
47
+
48
+ /**
49
+ * Redners list item element
50
+ * @param content - content of the list item
51
+ * @returns - created html list item element
52
+ */
53
+ renderItem: (content: string, meta: ItemMeta) => HTMLElement;
54
+
55
+ /**
56
+ * Return the item content
57
+ * @param {Element} item - item wrapper (<li>)
58
+ * @returns {string}
59
+ */
60
+ getItemContent: (item: Element) => string;
61
+
62
+ /**
63
+ * Return meta object of certain element
64
+ * @param {Element} item - item of the list to get meta from
65
+ * @returns {ItemMeta} Item meta object
66
+ */
67
+ getItemMeta: (item: Element) => ItemMeta;
68
+
69
+ /**
70
+ * Returns default item meta used on creation of the new item
71
+ */
72
+ composeDefaultMeta: () => ItemMeta;
73
+ };
@@ -0,0 +1,123 @@
1
+ import type { OrderedListItemMeta } from '../types/ItemMeta';
2
+ import type { ListConfig } from '../types/ListParams';
3
+ import { isEmpty, make } from '@editorjs/dom';
4
+ import { DefaultListCssClasses } from './ListRenderer';
5
+ import type { ListCssClasses, ListRendererInterface } from './ListRenderer';
6
+ import { CssPrefix } from '../styles/CssPrefix';
7
+
8
+ /**
9
+ * Interface that represents all list used only in unordered list rendering
10
+ */
11
+ interface OrderedListCssClasses extends ListCssClasses {
12
+ /**
13
+ * CSS class of the ordered list
14
+ */
15
+ orderedList: string;
16
+ }
17
+
18
+ /**
19
+ * Class that is responsible for ordered list rendering
20
+ */
21
+ export class OrderedListRenderer implements ListRendererInterface<OrderedListItemMeta> {
22
+ /**
23
+ * Tool's configuration
24
+ */
25
+ protected config?: ListConfig;
26
+
27
+ /**
28
+ * Is Editorjs List Tool read-only option
29
+ */
30
+ private readOnly: boolean;
31
+
32
+ /**
33
+ * Getter for all CSS classes used in unordered list rendering
34
+ */
35
+ private static get CSS(): OrderedListCssClasses {
36
+ return {
37
+ ...DefaultListCssClasses,
38
+ orderedList: `${CssPrefix}-ordered`,
39
+ };
40
+ }
41
+
42
+ /**
43
+ * Assign passed readonly mode and config to relevant class properties
44
+ * @param readonly - read-only mode flag
45
+ * @param config - user config for Tool
46
+ */
47
+ constructor(readonly: boolean, config?: ListConfig) {
48
+ this.config = config;
49
+ this.readOnly = readonly;
50
+ }
51
+
52
+ /**
53
+ * Renders ol wrapper for list
54
+ * @param isRoot - boolean variable that represents level of the wrappre (root or childList)
55
+ * @returns - created html ol element
56
+ */
57
+ public renderWrapper(isRoot: boolean): HTMLOListElement {
58
+ let wrapperElement: HTMLOListElement;
59
+
60
+ /**
61
+ * Check if it's root level
62
+ */
63
+ if (isRoot === true) {
64
+ wrapperElement = make('ol', [OrderedListRenderer.CSS.wrapper, OrderedListRenderer.CSS.orderedList]) as HTMLOListElement;
65
+ } else {
66
+ wrapperElement = make('ol', [OrderedListRenderer.CSS.orderedList, OrderedListRenderer.CSS.itemChildren]) as HTMLOListElement;
67
+ }
68
+
69
+ return wrapperElement;
70
+ }
71
+
72
+ /**
73
+ * Redners list item element
74
+ * @param content - content used in list item rendering
75
+ * @param _meta - meta of the list item unused in rendering of the ordered list
76
+ * @returns - created html list item element
77
+ */
78
+ public renderItem(content: string, _meta: OrderedListItemMeta): HTMLLIElement {
79
+ const itemWrapper = make('li', OrderedListRenderer.CSS.item);
80
+ const itemContent = make('div', OrderedListRenderer.CSS.itemContent, {
81
+ innerHTML: content,
82
+ contentEditable: (!this.readOnly).toString(),
83
+ });
84
+
85
+ itemWrapper.appendChild(itemContent);
86
+
87
+ return itemWrapper as HTMLLIElement;
88
+ }
89
+
90
+ /**
91
+ * Return the item content
92
+ * @param item - item wrapper (<li>)
93
+ * @returns - item content string
94
+ */
95
+ public getItemContent(item: Element): string {
96
+ const contentNode = item.querySelector(`.${OrderedListRenderer.CSS.itemContent}`);
97
+
98
+ if (!contentNode) {
99
+ return '';
100
+ }
101
+
102
+ if (isEmpty(contentNode)) {
103
+ return '';
104
+ }
105
+
106
+ return contentNode.innerHTML;
107
+ }
108
+
109
+ /**
110
+ * Returns item meta, for ordered list
111
+ * @returns item meta object
112
+ */
113
+ public getItemMeta(): OrderedListItemMeta {
114
+ return {};
115
+ }
116
+
117
+ /**
118
+ * Returns default item meta used on creation of the new item
119
+ */
120
+ public composeDefaultMeta(): OrderedListItemMeta {
121
+ return {};
122
+ }
123
+ }