1 |
efrain |
1 |
/**
|
|
|
2 |
* TinyMCE version 6.8.3 (2024-02-08)
|
|
|
3 |
*/
|
|
|
4 |
|
|
|
5 |
(function () {
|
|
|
6 |
'use strict';
|
|
|
7 |
|
|
|
8 |
var global$1 = tinymce.util.Tools.resolve('tinymce.PluginManager');
|
|
|
9 |
|
|
|
10 |
const applyListFormat = (editor, listName, styleValue) => {
|
|
|
11 |
const cmd = listName === 'UL' ? 'InsertUnorderedList' : 'InsertOrderedList';
|
|
|
12 |
editor.execCommand(cmd, false, styleValue === false ? null : { 'list-style-type': styleValue });
|
|
|
13 |
};
|
|
|
14 |
|
|
|
15 |
const register$2 = editor => {
|
|
|
16 |
editor.addCommand('ApplyUnorderedListStyle', (ui, value) => {
|
|
|
17 |
applyListFormat(editor, 'UL', value['list-style-type']);
|
|
|
18 |
});
|
|
|
19 |
editor.addCommand('ApplyOrderedListStyle', (ui, value) => {
|
|
|
20 |
applyListFormat(editor, 'OL', value['list-style-type']);
|
|
|
21 |
});
|
|
|
22 |
};
|
|
|
23 |
|
|
|
24 |
const option = name => editor => editor.options.get(name);
|
|
|
25 |
const register$1 = editor => {
|
|
|
26 |
const registerOption = editor.options.register;
|
|
|
27 |
registerOption('advlist_number_styles', {
|
|
|
28 |
processor: 'string[]',
|
|
|
29 |
default: 'default,lower-alpha,lower-greek,lower-roman,upper-alpha,upper-roman'.split(',')
|
|
|
30 |
});
|
|
|
31 |
registerOption('advlist_bullet_styles', {
|
|
|
32 |
processor: 'string[]',
|
|
|
33 |
default: 'default,circle,square'.split(',')
|
|
|
34 |
});
|
|
|
35 |
};
|
|
|
36 |
const getNumberStyles = option('advlist_number_styles');
|
|
|
37 |
const getBulletStyles = option('advlist_bullet_styles');
|
|
|
38 |
|
|
|
39 |
const isNullable = a => a === null || a === undefined;
|
|
|
40 |
const isNonNullable = a => !isNullable(a);
|
|
|
41 |
|
|
|
42 |
var global = tinymce.util.Tools.resolve('tinymce.util.Tools');
|
|
|
43 |
|
|
|
44 |
class Optional {
|
|
|
45 |
constructor(tag, value) {
|
|
|
46 |
this.tag = tag;
|
|
|
47 |
this.value = value;
|
|
|
48 |
}
|
|
|
49 |
static some(value) {
|
|
|
50 |
return new Optional(true, value);
|
|
|
51 |
}
|
|
|
52 |
static none() {
|
|
|
53 |
return Optional.singletonNone;
|
|
|
54 |
}
|
|
|
55 |
fold(onNone, onSome) {
|
|
|
56 |
if (this.tag) {
|
|
|
57 |
return onSome(this.value);
|
|
|
58 |
} else {
|
|
|
59 |
return onNone();
|
|
|
60 |
}
|
|
|
61 |
}
|
|
|
62 |
isSome() {
|
|
|
63 |
return this.tag;
|
|
|
64 |
}
|
|
|
65 |
isNone() {
|
|
|
66 |
return !this.tag;
|
|
|
67 |
}
|
|
|
68 |
map(mapper) {
|
|
|
69 |
if (this.tag) {
|
|
|
70 |
return Optional.some(mapper(this.value));
|
|
|
71 |
} else {
|
|
|
72 |
return Optional.none();
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
bind(binder) {
|
|
|
76 |
if (this.tag) {
|
|
|
77 |
return binder(this.value);
|
|
|
78 |
} else {
|
|
|
79 |
return Optional.none();
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
exists(predicate) {
|
|
|
83 |
return this.tag && predicate(this.value);
|
|
|
84 |
}
|
|
|
85 |
forall(predicate) {
|
|
|
86 |
return !this.tag || predicate(this.value);
|
|
|
87 |
}
|
|
|
88 |
filter(predicate) {
|
|
|
89 |
if (!this.tag || predicate(this.value)) {
|
|
|
90 |
return this;
|
|
|
91 |
} else {
|
|
|
92 |
return Optional.none();
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
getOr(replacement) {
|
|
|
96 |
return this.tag ? this.value : replacement;
|
|
|
97 |
}
|
|
|
98 |
or(replacement) {
|
|
|
99 |
return this.tag ? this : replacement;
|
|
|
100 |
}
|
|
|
101 |
getOrThunk(thunk) {
|
|
|
102 |
return this.tag ? this.value : thunk();
|
|
|
103 |
}
|
|
|
104 |
orThunk(thunk) {
|
|
|
105 |
return this.tag ? this : thunk();
|
|
|
106 |
}
|
|
|
107 |
getOrDie(message) {
|
|
|
108 |
if (!this.tag) {
|
|
|
109 |
throw new Error(message !== null && message !== void 0 ? message : 'Called getOrDie on None');
|
|
|
110 |
} else {
|
|
|
111 |
return this.value;
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
static from(value) {
|
|
|
115 |
return isNonNullable(value) ? Optional.some(value) : Optional.none();
|
|
|
116 |
}
|
|
|
117 |
getOrNull() {
|
|
|
118 |
return this.tag ? this.value : null;
|
|
|
119 |
}
|
|
|
120 |
getOrUndefined() {
|
|
|
121 |
return this.value;
|
|
|
122 |
}
|
|
|
123 |
each(worker) {
|
|
|
124 |
if (this.tag) {
|
|
|
125 |
worker(this.value);
|
|
|
126 |
}
|
|
|
127 |
}
|
|
|
128 |
toArray() {
|
|
|
129 |
return this.tag ? [this.value] : [];
|
|
|
130 |
}
|
|
|
131 |
toString() {
|
|
|
132 |
return this.tag ? `some(${ this.value })` : 'none()';
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
Optional.singletonNone = new Optional(false);
|
|
|
136 |
|
|
|
137 |
const findUntil = (xs, pred, until) => {
|
|
|
138 |
for (let i = 0, len = xs.length; i < len; i++) {
|
|
|
139 |
const x = xs[i];
|
|
|
140 |
if (pred(x, i)) {
|
|
|
141 |
return Optional.some(x);
|
|
|
142 |
} else if (until(x, i)) {
|
|
|
143 |
break;
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
return Optional.none();
|
|
|
147 |
};
|
|
|
148 |
|
|
|
149 |
const isCustomList = list => /\btox\-/.test(list.className);
|
|
|
150 |
const isChildOfBody = (editor, elm) => {
|
|
|
151 |
return editor.dom.isChildOf(elm, editor.getBody());
|
|
|
152 |
};
|
|
|
153 |
const matchNodeNames = regex => node => isNonNullable(node) && regex.test(node.nodeName);
|
|
|
154 |
const isListNode = matchNodeNames(/^(OL|UL|DL)$/);
|
|
|
155 |
const isTableCellNode = matchNodeNames(/^(TH|TD)$/);
|
|
|
156 |
const inList = (editor, parents, nodeName) => findUntil(parents, parent => isListNode(parent) && !isCustomList(parent), isTableCellNode).exists(list => list.nodeName === nodeName && isChildOfBody(editor, list));
|
|
|
157 |
const getSelectedStyleType = editor => {
|
|
|
158 |
const listElm = editor.dom.getParent(editor.selection.getNode(), 'ol,ul');
|
|
|
159 |
const style = editor.dom.getStyle(listElm, 'listStyleType');
|
|
|
160 |
return Optional.from(style);
|
|
|
161 |
};
|
|
|
162 |
const isWithinNonEditable = (editor, element) => element !== null && !editor.dom.isEditable(element);
|
|
|
163 |
const isWithinNonEditableList = (editor, element) => {
|
|
|
164 |
const parentList = editor.dom.getParent(element, 'ol,ul,dl');
|
|
|
165 |
return isWithinNonEditable(editor, parentList) && editor.selection.isEditable();
|
|
|
166 |
};
|
|
|
167 |
const setNodeChangeHandler = (editor, nodeChangeHandler) => {
|
|
|
168 |
const initialNode = editor.selection.getNode();
|
|
|
169 |
nodeChangeHandler({
|
|
|
170 |
parents: editor.dom.getParents(initialNode),
|
|
|
171 |
element: initialNode
|
|
|
172 |
});
|
|
|
173 |
editor.on('NodeChange', nodeChangeHandler);
|
|
|
174 |
return () => editor.off('NodeChange', nodeChangeHandler);
|
|
|
175 |
};
|
|
|
176 |
|
|
|
177 |
const styleValueToText = styleValue => {
|
|
|
178 |
return styleValue.replace(/\-/g, ' ').replace(/\b\w/g, chr => {
|
|
|
179 |
return chr.toUpperCase();
|
|
|
180 |
});
|
|
|
181 |
};
|
|
|
182 |
const normalizeStyleValue = styleValue => isNullable(styleValue) || styleValue === 'default' ? '' : styleValue;
|
|
|
183 |
const makeSetupHandler = (editor, nodeName) => api => {
|
|
|
184 |
const updateButtonState = (editor, parents) => {
|
|
|
185 |
const element = editor.selection.getStart(true);
|
|
|
186 |
api.setActive(inList(editor, parents, nodeName));
|
|
|
187 |
api.setEnabled(!isWithinNonEditableList(editor, element) && editor.selection.isEditable());
|
|
|
188 |
};
|
|
|
189 |
const nodeChangeHandler = e => updateButtonState(editor, e.parents);
|
|
|
190 |
return setNodeChangeHandler(editor, nodeChangeHandler);
|
|
|
191 |
};
|
|
|
192 |
const addSplitButton = (editor, id, tooltip, cmd, nodeName, styles) => {
|
|
|
193 |
editor.ui.registry.addSplitButton(id, {
|
|
|
194 |
tooltip,
|
|
|
195 |
icon: nodeName === 'OL' ? 'ordered-list' : 'unordered-list',
|
|
|
196 |
presets: 'listpreview',
|
|
|
197 |
columns: 3,
|
|
|
198 |
fetch: callback => {
|
|
|
199 |
const items = global.map(styles, styleValue => {
|
|
|
200 |
const iconStyle = nodeName === 'OL' ? 'num' : 'bull';
|
|
|
201 |
const iconName = styleValue === 'disc' || styleValue === 'decimal' ? 'default' : styleValue;
|
|
|
202 |
const itemValue = normalizeStyleValue(styleValue);
|
|
|
203 |
const displayText = styleValueToText(styleValue);
|
|
|
204 |
return {
|
|
|
205 |
type: 'choiceitem',
|
|
|
206 |
value: itemValue,
|
|
|
207 |
icon: 'list-' + iconStyle + '-' + iconName,
|
|
|
208 |
text: displayText
|
|
|
209 |
};
|
|
|
210 |
});
|
|
|
211 |
callback(items);
|
|
|
212 |
},
|
|
|
213 |
onAction: () => editor.execCommand(cmd),
|
|
|
214 |
onItemAction: (_splitButtonApi, value) => {
|
|
|
215 |
applyListFormat(editor, nodeName, value);
|
|
|
216 |
},
|
|
|
217 |
select: value => {
|
|
|
218 |
const listStyleType = getSelectedStyleType(editor);
|
|
|
219 |
return listStyleType.map(listStyle => value === listStyle).getOr(false);
|
|
|
220 |
},
|
|
|
221 |
onSetup: makeSetupHandler(editor, nodeName)
|
|
|
222 |
});
|
|
|
223 |
};
|
|
|
224 |
const addButton = (editor, id, tooltip, cmd, nodeName, styleValue) => {
|
|
|
225 |
editor.ui.registry.addToggleButton(id, {
|
|
|
226 |
active: false,
|
|
|
227 |
tooltip,
|
|
|
228 |
icon: nodeName === 'OL' ? 'ordered-list' : 'unordered-list',
|
|
|
229 |
onSetup: makeSetupHandler(editor, nodeName),
|
|
|
230 |
onAction: () => editor.queryCommandState(cmd) || styleValue === '' ? editor.execCommand(cmd) : applyListFormat(editor, nodeName, styleValue)
|
|
|
231 |
});
|
|
|
232 |
};
|
|
|
233 |
const addControl = (editor, id, tooltip, cmd, nodeName, styles) => {
|
|
|
234 |
if (styles.length > 1) {
|
|
|
235 |
addSplitButton(editor, id, tooltip, cmd, nodeName, styles);
|
|
|
236 |
} else {
|
|
|
237 |
addButton(editor, id, tooltip, cmd, nodeName, normalizeStyleValue(styles[0]));
|
|
|
238 |
}
|
|
|
239 |
};
|
|
|
240 |
const register = editor => {
|
|
|
241 |
addControl(editor, 'numlist', 'Numbered list', 'InsertOrderedList', 'OL', getNumberStyles(editor));
|
|
|
242 |
addControl(editor, 'bullist', 'Bullet list', 'InsertUnorderedList', 'UL', getBulletStyles(editor));
|
|
|
243 |
};
|
|
|
244 |
|
|
|
245 |
var Plugin = () => {
|
|
|
246 |
global$1.add('advlist', editor => {
|
|
|
247 |
if (editor.hasPlugin('lists')) {
|
|
|
248 |
register$1(editor);
|
|
|
249 |
register(editor);
|
|
|
250 |
register$2(editor);
|
|
|
251 |
} else {
|
|
|
252 |
console.error('Please use the Lists plugin together with the Advanced List plugin.');
|
|
|
253 |
}
|
|
|
254 |
});
|
|
|
255 |
};
|
|
|
256 |
|
|
|
257 |
Plugin();
|
|
|
258 |
|
|
|
259 |
})();
|