2 * @param {Editor} editor
4 function defineTaskListCustomElement(editor) {
5 const doc = editor.getDoc();
6 const win = doc.defaultView;
8 class TaskListElement extends win.HTMLElement {
11 // this.attachShadow({mode: 'open'});
13 // const input = doc.createElement('input');
14 // input.setAttribute('type', 'checkbox');
15 // input.setAttribute('disabled', 'disabled');
17 // if (this.hasAttribute('selected')) {
18 // input.setAttribute('selected', 'selected');
21 // this.shadowRoot.append(input);
22 // this.shadowRoot.close();
26 win.customElements.define('task-list-item', TaskListElement);
30 * @param {Editor} editor
33 function register(editor, url) {
35 // editor.on('NewBlock', ({ newBlock}) => {
36 // ensureElementHasCheckbox(newBlock);
39 editor.on('PreInit', () => {
41 defineTaskListCustomElement(editor);
43 editor.parser.addNodeFilter('li', function(elms) {
44 for (const elem of elms) {
45 if (elem.attributes.map.class === 'task-list-item') {
46 replaceTaskListNode(elem);
51 // editor.serializer.addNodeFilter('li', function(elms) {
52 // for (const elem of elms) {
53 // if (elem.attributes.map.class === 'task-list-item') {
54 // ensureNodeHasCheckbox(elem);
64 * @param {AstNode} node
66 function replaceTaskListNode(node) {
68 const taskListItem = new tinymce.html.Node.create('task-list-item', {
71 for (const child of node.children()) {
72 if (node.name !== 'input') {
73 taskListItem.append(child);
77 node.replace(taskListItem);
81 // * @param {Element} elem
83 // function ensureElementHasCheckbox(elem) {
84 // const hasCheckbox = elem.querySelector(':scope > input[type="checkbox"]') !== null;
89 // const input = elem.ownerDocument.createElement('input');
90 // input.setAttribute('type', 'checkbox');
91 // input.setAttribute('disabled', 'disabled');
92 // elem.prepend(input);
96 * @param {AstNode} elem
98 function ensureNodeHasCheckbox(elem) {
99 // Stop if there's already an input
100 if (elem.firstChild && elem.firstChild.name === 'input') {
104 const input = new tinymce.html.Node.create('input', {
106 disabled: 'disabled',
109 if (elem.firstChild) {
110 elem.insert(input, elem.firstChild, true);
118 * @param {WysiwygConfigOptions} options
121 export function getPlugin(options) {