@ebl-vue/editor-full 2.31.11 → 2.31.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +360 -319
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/components/Editor/Editor.vue +22 -6
- package/src/plugins/list/ListRenderer/ChecklistRenderer.ts +1 -1
- package/src/plugins/list/ListTabulator/index.ts +1 -1
- package/src/plugins/list/index.ts +118 -123
- package/src/plugins/list/styles/.cdx-list .css +168 -0
- package/src/plugins/list/utils/normalizeData.ts +0 -1
- package/src/plugins/list-bak/ListRenderer/ChecklistRenderer.ts +208 -0
- package/src/plugins/list-bak/ListRenderer/ListRenderer.ts +73 -0
- package/src/plugins/list-bak/ListRenderer/OrderedListRenderer.ts +123 -0
- package/src/plugins/list-bak/ListRenderer/UnorderedListRenderer.ts +123 -0
- package/src/plugins/list-bak/ListRenderer/index.ts +6 -0
- package/src/plugins/list-bak/ListTabulator/index.ts +1179 -0
- package/src/plugins/list-bak/index.ts +485 -0
- package/src/plugins/list-bak/styles/CssPrefix.ts +4 -0
- package/src/plugins/list-bak/styles/input.css +36 -0
- package/src/plugins/list-bak/styles/list.css +165 -0
- package/src/plugins/list-bak/types/Elements.ts +14 -0
- package/src/plugins/list-bak/types/ItemMeta.ts +40 -0
- package/src/plugins/list-bak/types/ListParams.ts +102 -0
- package/src/plugins/list-bak/types/ListRenderer.ts +6 -0
- package/src/plugins/list-bak/types/OlCounterType.ts +63 -0
- package/src/plugins/list-bak/types/index.ts +14 -0
- package/src/plugins/list-bak/utils/focusItem.ts +18 -0
- package/src/plugins/list-bak/utils/getChildItems.ts +40 -0
- package/src/plugins/list-bak/utils/getItemChildWrapper.ts +10 -0
- package/src/plugins/list-bak/utils/getItemContentElement.ts +10 -0
- package/src/plugins/list-bak/utils/getSiblings.ts +52 -0
- package/src/plugins/list-bak/utils/isLastItem.ts +9 -0
- package/src/plugins/list-bak/utils/itemHasSublist.ts +10 -0
- package/src/plugins/list-bak/utils/normalizeData.ts +84 -0
- package/src/plugins/list-bak/utils/removeChildWrapperIfEmpty.ts +31 -0
- package/src/plugins/list-bak/utils/renderToolboxInput.ts +105 -0
- package/src/plugins/list-bak/utils/stripNumbers.ts +7 -0
- package/src/plugins/list-bak/utils/type-guards.ts +8 -0
|
@@ -0,0 +1,208 @@
|
|
|
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
|
+
import { IconCheck } from "../../../icons";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Interface that represents all list used only in unordered list rendering
|
|
11
|
+
*/
|
|
12
|
+
interface ChecklistCssClasses extends ListCssClasses {
|
|
13
|
+
/**
|
|
14
|
+
* CSS class of the checklist
|
|
15
|
+
*/
|
|
16
|
+
checklist: string;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* CSS class of the checked checkbox
|
|
20
|
+
*/
|
|
21
|
+
itemChecked: string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* CSS class for the special hover behavior of the checkboc
|
|
25
|
+
*/
|
|
26
|
+
noHover: string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* CSS class of the checkbox
|
|
30
|
+
*/
|
|
31
|
+
checkbox: string;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* CSS class of the checkbox container
|
|
35
|
+
*/
|
|
36
|
+
checkboxContainer: string;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* CSS class for disabled checkbox check
|
|
40
|
+
*/
|
|
41
|
+
checkboxCheckDisabled: string;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Class that is responsible for checklist rendering
|
|
46
|
+
*/
|
|
47
|
+
export class CheckListRenderer implements ListRendererInterface<ChecklistItemMeta> {
|
|
48
|
+
/**
|
|
49
|
+
* Tool's configuration
|
|
50
|
+
*/
|
|
51
|
+
protected config?: ListConfig;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Is Editorjs List Tool read-only option
|
|
55
|
+
*/
|
|
56
|
+
private readOnly: boolean;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Getter for all CSS classes used in unordered list rendering
|
|
60
|
+
*/
|
|
61
|
+
private static get CSS(): ChecklistCssClasses {
|
|
62
|
+
return {
|
|
63
|
+
...DefaultListCssClasses,
|
|
64
|
+
checklist: `${CssPrefix}-checklist`,
|
|
65
|
+
itemChecked: `${CssPrefix}__checkbox--checked`,
|
|
66
|
+
noHover: `${CssPrefix}__checkbox--no-hover`,
|
|
67
|
+
checkbox: `${CssPrefix}__checkbox-check`,
|
|
68
|
+
checkboxContainer: `${CssPrefix}__checkbox`,
|
|
69
|
+
checkboxCheckDisabled: `${CssPrefix}__checkbox-check--disabled`,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Assign passed readonly mode and config to relevant class properties
|
|
75
|
+
* @param readonly - read-only mode flag
|
|
76
|
+
* @param config - user config for Tool
|
|
77
|
+
*/
|
|
78
|
+
constructor(readonly: boolean, config?: ListConfig) {
|
|
79
|
+
this.config = config;
|
|
80
|
+
this.readOnly = readonly;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Renders ul wrapper for list
|
|
85
|
+
* @param isRoot - boolean variable that represents level of the wrappre (root or childList)
|
|
86
|
+
* @returns - created html ul element
|
|
87
|
+
*/
|
|
88
|
+
public renderWrapper(isRoot: boolean): HTMLUListElement {
|
|
89
|
+
let wrapperElement: HTMLUListElement;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Check if it's root level
|
|
93
|
+
*/
|
|
94
|
+
if (isRoot === true) {
|
|
95
|
+
wrapperElement = make('ul', [CheckListRenderer.CSS.wrapper, CheckListRenderer.CSS.checklist]) as HTMLUListElement;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Delegate clicks from wrapper to items
|
|
99
|
+
*/
|
|
100
|
+
wrapperElement.addEventListener('click', (event) => {
|
|
101
|
+
const target = event.target as Element | null;
|
|
102
|
+
|
|
103
|
+
if (target) {
|
|
104
|
+
const checkbox = target.closest(`.${CheckListRenderer.CSS.checkboxContainer}`);
|
|
105
|
+
|
|
106
|
+
if (checkbox && checkbox.contains(target)) {
|
|
107
|
+
this.toggleCheckbox(checkbox);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
wrapperElement = make('ul', [CheckListRenderer.CSS.checklist, CheckListRenderer.CSS.itemChildren]) as HTMLUListElement;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
return wrapperElement;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Redners list item element
|
|
120
|
+
* @param content - content used in list item rendering
|
|
121
|
+
* @param meta - meta of the list item used in rendering of the checklist
|
|
122
|
+
* @returns - created html list item element
|
|
123
|
+
*/
|
|
124
|
+
public renderItem(content: string, meta: ChecklistItemMeta): HTMLLIElement {
|
|
125
|
+
const itemWrapper = make('li', [CheckListRenderer.CSS.item, CheckListRenderer.CSS.item]);
|
|
126
|
+
const itemContent = make('div', CheckListRenderer.CSS.itemContent, {
|
|
127
|
+
innerHTML: content,
|
|
128
|
+
contentEditable: (!this.readOnly).toString(),
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const checkbox = make('span', CheckListRenderer.CSS.checkbox);
|
|
132
|
+
const checkboxContainer = make('div', CheckListRenderer.CSS.checkboxContainer);
|
|
133
|
+
|
|
134
|
+
if (meta.checked === true) {
|
|
135
|
+
checkboxContainer.classList.add(CheckListRenderer.CSS.itemChecked);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Disable checkbox interaction in read-only mode
|
|
139
|
+
if (this.readOnly) {
|
|
140
|
+
checkboxContainer.classList.add(CheckListRenderer.CSS.checkboxCheckDisabled);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
checkbox.innerHTML = IconCheck;
|
|
144
|
+
checkboxContainer.appendChild(checkbox);
|
|
145
|
+
|
|
146
|
+
itemWrapper.appendChild(checkboxContainer);
|
|
147
|
+
itemWrapper.appendChild(itemContent);
|
|
148
|
+
|
|
149
|
+
return itemWrapper as HTMLLIElement;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Return the item content
|
|
154
|
+
* @param item - item wrapper (<li>)
|
|
155
|
+
* @returns - item content string
|
|
156
|
+
*/
|
|
157
|
+
public getItemContent(item: Element): string {
|
|
158
|
+
const contentNode = item.querySelector(`.${CheckListRenderer.CSS.itemContent}`);
|
|
159
|
+
|
|
160
|
+
if (!contentNode) {
|
|
161
|
+
return '';
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (isEmpty(contentNode)) {
|
|
165
|
+
return '';
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return contentNode.innerHTML;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Return meta object of certain element
|
|
173
|
+
* @param item - will be returned meta information of this item
|
|
174
|
+
* @returns Item meta object
|
|
175
|
+
*/
|
|
176
|
+
public getItemMeta(item: Element): ChecklistItemMeta {
|
|
177
|
+
const checkbox = item.querySelector(`.${CheckListRenderer.CSS.checkboxContainer}`);
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
checked: checkbox ? checkbox.classList.contains(CheckListRenderer.CSS.itemChecked) : false,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Returns default item meta used on creation of the new item
|
|
186
|
+
*/
|
|
187
|
+
public composeDefaultMeta(): ChecklistItemMeta {
|
|
188
|
+
return { checked: false };
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Toggle checklist item state
|
|
193
|
+
* @param checkbox - checkbox element to be toggled
|
|
194
|
+
*/
|
|
195
|
+
private toggleCheckbox(checkbox: Element): void {
|
|
196
|
+
checkbox.classList.toggle(CheckListRenderer.CSS.itemChecked);
|
|
197
|
+
checkbox.classList.add(CheckListRenderer.CSS.noHover);
|
|
198
|
+
checkbox.addEventListener('mouseleave', () => this.removeSpecialHoverBehavior(checkbox), { once: true });
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Removes class responsible for special hover behavior on an item
|
|
203
|
+
* @param el - item wrapper
|
|
204
|
+
*/
|
|
205
|
+
private removeSpecialHoverBehavior(el: Element): void {
|
|
206
|
+
el.classList.remove(CheckListRenderer.CSS.noHover);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import type { UnorderedListItemMeta } from '../types/ItemMeta';
|
|
2
|
+
import type { ListConfig } from '../types/ListParams';
|
|
3
|
+
import { make, isEmpty } 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 UnoderedListCssClasses extends ListCssClasses {
|
|
12
|
+
/**
|
|
13
|
+
* CSS class of the unordered list
|
|
14
|
+
*/
|
|
15
|
+
unorderedList: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Class that is responsible for unordered list rendering
|
|
20
|
+
*/
|
|
21
|
+
export class UnorderedListRenderer implements ListRendererInterface<UnorderedListItemMeta> {
|
|
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(): UnoderedListCssClasses {
|
|
36
|
+
return {
|
|
37
|
+
...DefaultListCssClasses,
|
|
38
|
+
unorderedList: `${CssPrefix}-unordered`,
|
|
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 ul element
|
|
56
|
+
*/
|
|
57
|
+
public renderWrapper(isRoot: boolean): HTMLUListElement {
|
|
58
|
+
let wrapperElement: HTMLUListElement;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Check if it's root level
|
|
62
|
+
*/
|
|
63
|
+
if (isRoot === true) {
|
|
64
|
+
wrapperElement = make('ul', [UnorderedListRenderer.CSS.wrapper, UnorderedListRenderer.CSS.unorderedList]) as HTMLUListElement;
|
|
65
|
+
} else {
|
|
66
|
+
wrapperElement = make('ul', [UnorderedListRenderer.CSS.unorderedList, UnorderedListRenderer.CSS.itemChildren]) as HTMLUListElement;
|
|
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 unordered list
|
|
76
|
+
* @returns - created html list item element
|
|
77
|
+
*/
|
|
78
|
+
public renderItem(content: string, _meta: UnorderedListItemMeta): HTMLLIElement {
|
|
79
|
+
const itemWrapper = make('li', UnorderedListRenderer.CSS.item);
|
|
80
|
+
const itemContent = make('div', UnorderedListRenderer.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(`.${UnorderedListRenderer.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 unordered list
|
|
111
|
+
* @returns Item meta object
|
|
112
|
+
*/
|
|
113
|
+
public getItemMeta(): UnorderedListItemMeta {
|
|
114
|
+
return {};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Returns default item meta used on creation of the new item
|
|
119
|
+
*/
|
|
120
|
+
public composeDefaultMeta(): UnorderedListItemMeta {
|
|
121
|
+
return {};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { CheckListRenderer } from './ChecklistRenderer';
|
|
2
|
+
import { OrderedListRenderer } from './OrderedListRenderer';
|
|
3
|
+
import { UnorderedListRenderer } from './UnorderedListRenderer';
|
|
4
|
+
import { DefaultListCssClasses } from './ListRenderer';
|
|
5
|
+
|
|
6
|
+
export { CheckListRenderer, OrderedListRenderer, UnorderedListRenderer, DefaultListCssClasses };
|