@seyamali/aurelia-editor 0.1.1 → 0.1.3
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/aurelia-editor.js +1 -1
- package/dist/aurelia-editor.umd.cjs +184 -151
- package/dist/code-block-popover-ui-u3iuYqYp.js +79 -0
- package/dist/core/engine.d.ts +5 -0
- package/dist/{horizontal-rule-plugin-DdpCd1us.js → horizontal-rule-plugin-Ct8iq55t.js} +1 -1
- package/dist/{index-C9G087KG.js → index-BrE44rnx.js} +8427 -8199
- package/dist/plugins/advanced/raw-html-node.d.ts +20 -0
- package/dist/state-logic-DmJ5y08x.js +103 -0
- package/dist/table-popover-ui-BoxmjrtM.js +161 -0
- package/package.json +1 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { DecoratorNode, NodeKey, SerializedLexicalNode, Spread, DOMConversionMap, DOMExportOutput } from 'lexical';
|
|
2
|
+
export type SerializedRawHtmlNode = Spread<{
|
|
3
|
+
html: string;
|
|
4
|
+
tag: string;
|
|
5
|
+
}, SerializedLexicalNode>;
|
|
6
|
+
export declare class RawHtmlNode extends DecoratorNode<HTMLElement> {
|
|
7
|
+
__html: string;
|
|
8
|
+
__tag: string;
|
|
9
|
+
static getType(): string;
|
|
10
|
+
static clone(node: RawHtmlNode): RawHtmlNode;
|
|
11
|
+
constructor(html: string, tag: string, key?: NodeKey);
|
|
12
|
+
static importJSON(serializedNode: SerializedRawHtmlNode): RawHtmlNode;
|
|
13
|
+
exportJSON(): SerializedRawHtmlNode;
|
|
14
|
+
createDOM(): HTMLElement;
|
|
15
|
+
updateDOM(): false;
|
|
16
|
+
decorate(): HTMLElement;
|
|
17
|
+
static importDOM(): DOMConversionMap | null;
|
|
18
|
+
exportDOM(): DOMExportOutput;
|
|
19
|
+
}
|
|
20
|
+
export declare function $createRawHtmlNode(html: string, tag: string): RawHtmlNode;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { CAN_UNDO_COMMAND as h, COMMAND_PRIORITY_CRITICAL as r, CAN_REDO_COMMAND as y, UNDO_COMMAND as L, REDO_COMMAND as T, SELECTION_CHANGE_COMMAND as C, $getSelection as B, $isRangeSelection as I, $isNodeSelection as E } from "lexical";
|
|
2
|
+
import { $getNearestNodeOfType as b } from "@lexical/utils";
|
|
3
|
+
import { $isHeadingNode as O, $isQuoteNode as M } from "@lexical/rich-text";
|
|
4
|
+
import { ListNode as f } from "@lexical/list";
|
|
5
|
+
import { LinkNode as k } from "@lexical/link";
|
|
6
|
+
import { I as A, $ as _ } from "./index-BrE44rnx.js";
|
|
7
|
+
import { $isTableNode as v } from "@lexical/table";
|
|
8
|
+
function U(s) {
|
|
9
|
+
const p = () => {
|
|
10
|
+
s.getEditorState().read(() => {
|
|
11
|
+
const e = B();
|
|
12
|
+
let t = !1;
|
|
13
|
+
if (I(e)) {
|
|
14
|
+
const o = {
|
|
15
|
+
bold: "bold-btn",
|
|
16
|
+
italic: "italic-btn",
|
|
17
|
+
underline: "underline-btn",
|
|
18
|
+
strikethrough: "strikethrough-btn",
|
|
19
|
+
subscript: "subscript-btn",
|
|
20
|
+
superscript: "superscript-btn",
|
|
21
|
+
code: "code-btn"
|
|
22
|
+
};
|
|
23
|
+
for (const [d, u] of Object.entries(o))
|
|
24
|
+
document.getElementById(u)?.classList.toggle("active", e.hasFormat(d));
|
|
25
|
+
const n = e.anchor.getNode();
|
|
26
|
+
let i = n.getKey() === "root" ? n : n.getTopLevelElementOrThrow(), l = "paragraph";
|
|
27
|
+
O(i) ? l = i.getTag() : M(i) && (l = "blockquote");
|
|
28
|
+
const c = document.querySelector('button[data-item-id="heading-dropdown"]');
|
|
29
|
+
if (c) {
|
|
30
|
+
const u = {
|
|
31
|
+
h1: "Heading 1",
|
|
32
|
+
h2: "Heading 2",
|
|
33
|
+
h3: "Heading 3",
|
|
34
|
+
h4: "Heading 4",
|
|
35
|
+
h5: "Heading 5",
|
|
36
|
+
h6: "Heading 6",
|
|
37
|
+
paragraph: "Normal",
|
|
38
|
+
blockquote: "Quote"
|
|
39
|
+
}[l] || "Normal";
|
|
40
|
+
c.innerHTML = `${A.HEADING} ${u} <span style="font-size: 0.8em; opacity: 0.6; margin-left: 4px;">▼</span>`;
|
|
41
|
+
}
|
|
42
|
+
document.getElementById("blockquote-btn")?.classList.toggle("active", l === "blockquote");
|
|
43
|
+
const a = b(n, f);
|
|
44
|
+
if (a) {
|
|
45
|
+
const d = a.getListType();
|
|
46
|
+
document.getElementById("bullet-list-btn")?.classList.toggle("active", d === "bullet"), document.getElementById("numbered-list-btn")?.classList.toggle("active", d === "number");
|
|
47
|
+
} else
|
|
48
|
+
document.getElementById("bullet-list-btn")?.classList.remove("active"), document.getElementById("numbered-list-btn")?.classList.remove("active");
|
|
49
|
+
t = b(n, k) !== null;
|
|
50
|
+
} else if (E(e)) {
|
|
51
|
+
const o = e.getNodes();
|
|
52
|
+
o.length === 1 && _(o[0]) && (t = !!o[0].__linkUrl);
|
|
53
|
+
}
|
|
54
|
+
document.getElementById("insert-link-btn")?.classList.toggle("active", t);
|
|
55
|
+
const m = document.getElementById("indent-btn"), g = document.getElementById("outdent-btn");
|
|
56
|
+
if (m && g)
|
|
57
|
+
if (I(e)) {
|
|
58
|
+
const o = e.anchor.getNode(), n = o.getTopLevelElement(), i = b(o, f), l = n !== null && !v(n);
|
|
59
|
+
m.disabled = !l;
|
|
60
|
+
const c = n?.getIndent?.() || 0, a = i !== null && i.getParent() instanceof f;
|
|
61
|
+
g.disabled = !(c > 0 || a);
|
|
62
|
+
} else
|
|
63
|
+
m.disabled = !0, g.disabled = !0;
|
|
64
|
+
});
|
|
65
|
+
}, N = (e) => {
|
|
66
|
+
const t = document.getElementById("announcer");
|
|
67
|
+
t && (t.innerText = e, setTimeout(() => {
|
|
68
|
+
t.innerText === e && (t.innerText = "");
|
|
69
|
+
}, 3e3));
|
|
70
|
+
};
|
|
71
|
+
s.registerCommand(
|
|
72
|
+
h,
|
|
73
|
+
(e) => {
|
|
74
|
+
const t = document.getElementById("undo-btn");
|
|
75
|
+
return t && (t.disabled = !e), !1;
|
|
76
|
+
},
|
|
77
|
+
r
|
|
78
|
+
), s.registerCommand(
|
|
79
|
+
y,
|
|
80
|
+
(e) => {
|
|
81
|
+
const t = document.getElementById("redo-btn");
|
|
82
|
+
return t && (t.disabled = !e), !1;
|
|
83
|
+
},
|
|
84
|
+
r
|
|
85
|
+
), s.registerCommand(
|
|
86
|
+
L,
|
|
87
|
+
() => (N("Undo performed"), !1),
|
|
88
|
+
r
|
|
89
|
+
), s.registerCommand(
|
|
90
|
+
T,
|
|
91
|
+
() => (N("Redo performed"), !1),
|
|
92
|
+
r
|
|
93
|
+
), s.registerUpdateListener(() => {
|
|
94
|
+
p();
|
|
95
|
+
}), s.registerCommand(
|
|
96
|
+
C,
|
|
97
|
+
() => (p(), !1),
|
|
98
|
+
r
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
U as setupToolbarState
|
|
103
|
+
};
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { $getSelection as v, $isRangeSelection as f, SELECTION_CHANGE_COMMAND as R, COMMAND_PRIORITY_LOW as B } from "lexical";
|
|
2
|
+
import { $isTableSelection as m, $unmergeCell as T, $isTableCellNode as C, $mergeCells as _, $isTableNode as y, $deleteTableColumn__EXPERIMENTAL as h, $deleteTableRow__EXPERIMENTAL as $, $insertTableColumn__EXPERIMENTAL as I, $insertTableRow__EXPERIMENTAL as L } from "@lexical/table";
|
|
3
|
+
import { I as r } from "./index-BrE44rnx.js";
|
|
4
|
+
const l = {
|
|
5
|
+
insertRowAbove: (e) => {
|
|
6
|
+
e.getInternalEditor().update(() => {
|
|
7
|
+
L(!1);
|
|
8
|
+
});
|
|
9
|
+
},
|
|
10
|
+
insertRowBelow: (e) => {
|
|
11
|
+
e.getInternalEditor().update(() => {
|
|
12
|
+
L(!0);
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
insertColumnLeft: (e) => {
|
|
16
|
+
e.getInternalEditor().update(() => {
|
|
17
|
+
I(!1);
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
insertColumnRight: (e) => {
|
|
21
|
+
e.getInternalEditor().update(() => {
|
|
22
|
+
I(!0);
|
|
23
|
+
});
|
|
24
|
+
},
|
|
25
|
+
deleteRow: (e) => {
|
|
26
|
+
e.getInternalEditor().update(() => {
|
|
27
|
+
$();
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
deleteColumn: (e) => {
|
|
31
|
+
e.getInternalEditor().update(() => {
|
|
32
|
+
h();
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
deleteTable: (e) => {
|
|
36
|
+
e.getInternalEditor().update(() => {
|
|
37
|
+
const t = v();
|
|
38
|
+
if (f(t) || m(t)) {
|
|
39
|
+
const p = t.getNodes();
|
|
40
|
+
for (const s of p) {
|
|
41
|
+
let n = s;
|
|
42
|
+
for (; n !== null; ) {
|
|
43
|
+
if (y(n)) {
|
|
44
|
+
n.remove();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
n = typeof n.getParent == "function" ? n.getParent() : null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
// Aliases for backward compatibility
|
|
54
|
+
insertRow: (e) => l.insertRowBelow(e),
|
|
55
|
+
insertColumn: (e) => l.insertColumnRight(e),
|
|
56
|
+
mergeCells: (e) => {
|
|
57
|
+
e.getInternalEditor().update(() => {
|
|
58
|
+
const t = v();
|
|
59
|
+
if (m(t)) {
|
|
60
|
+
const s = t.getNodes().filter((n) => C(n));
|
|
61
|
+
s.length > 1 && _(s);
|
|
62
|
+
} else
|
|
63
|
+
console.warn("Please select multiple cells (drag across cells) to merge");
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
splitCell: (e) => {
|
|
67
|
+
e.getInternalEditor().update(() => {
|
|
68
|
+
const t = v();
|
|
69
|
+
(f(t) || m(t)) && T();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
function O(e) {
|
|
74
|
+
let t = document.getElementById("table-popover");
|
|
75
|
+
t || (t = document.createElement("div"), t.id = "table-popover", t.className = "table-popover hidden", t.innerHTML = `
|
|
76
|
+
<div class="table-popover-group">
|
|
77
|
+
<button id="table-row-above" title="Insert Row Above">${r.TABLE_ROW_ABOVE}</button>
|
|
78
|
+
<button id="table-row-below" title="Insert Row Below">${r.TABLE_ROW_BELOW}</button>
|
|
79
|
+
<button id="table-row-delete" title="Delete Row" class="danger">${r.TABLE_ROW_DELETE}</button>
|
|
80
|
+
</div>
|
|
81
|
+
<div class="divider-v"></div>
|
|
82
|
+
<div class="table-popover-group">
|
|
83
|
+
<button id="table-col-left" title="Insert Column Left">${r.TABLE_COL_LEFT}</button>
|
|
84
|
+
<button id="table-col-right" title="Insert Column Right">${r.TABLE_COL_RIGHT}</button>
|
|
85
|
+
<button id="table-col-delete" title="Delete Column" class="danger">${r.TABLE_COL_DELETE}</button>
|
|
86
|
+
</div>
|
|
87
|
+
<div class="divider-v" id="table-merge-divider"></div>
|
|
88
|
+
<div class="table-popover-group">
|
|
89
|
+
<button id="table-merge" title="Merge Cells">${r.TABLE_MERGE}</button>
|
|
90
|
+
<button id="table-split" title="Split Cell">${r.TABLE_SPLIT}</button>
|
|
91
|
+
</div>
|
|
92
|
+
<div class="divider-v"></div>
|
|
93
|
+
<div class="table-popover-group">
|
|
94
|
+
<button id="table-delete" title="Delete Table" class="danger">${r.TABLE_DELETE}</button>
|
|
95
|
+
</div>
|
|
96
|
+
`, document.getElementById("editor-wrapper")?.appendChild(t));
|
|
97
|
+
const p = (o) => {
|
|
98
|
+
const b = document.getElementById("editor-wrapper");
|
|
99
|
+
if (!b || !t) return;
|
|
100
|
+
const d = b.getBoundingClientRect(), a = o.getBoundingClientRect(), c = t.getBoundingClientRect();
|
|
101
|
+
let E = a.top - d.top - c.height - 10, u = a.left - d.left + a.width / 2 - c.width / 2;
|
|
102
|
+
u < 10 && (u = 10), u + c.width > d.width - 10 && (u = d.width - c.width - 10), E < 10 && (E = a.bottom - d.top + 10), t.style.top = `${E}px`, t.style.left = `${u}px`;
|
|
103
|
+
}, s = () => {
|
|
104
|
+
t?.classList.add("hidden");
|
|
105
|
+
}, n = (o) => {
|
|
106
|
+
t?.classList.remove("hidden"), requestAnimationFrame(() => p(o));
|
|
107
|
+
};
|
|
108
|
+
e.registerCommand(
|
|
109
|
+
R,
|
|
110
|
+
() => {
|
|
111
|
+
const o = v();
|
|
112
|
+
if (f(o) || m(o)) {
|
|
113
|
+
const b = o.getNodes();
|
|
114
|
+
let d = !1;
|
|
115
|
+
const a = document.getElementById("table-merge"), c = document.getElementById("table-merge-divider"), E = m(o);
|
|
116
|
+
a && (a.style.display = E ? "flex" : "none"), c && (c.style.display = E ? "block" : "none");
|
|
117
|
+
for (const u of b) {
|
|
118
|
+
let g = u;
|
|
119
|
+
for (; g !== null; ) {
|
|
120
|
+
if (C(g)) {
|
|
121
|
+
const w = e.getElementByKey(g.getKey());
|
|
122
|
+
if (w) {
|
|
123
|
+
n(w), d = !0;
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
g = typeof g.getParent == "function" ? g.getParent() : null;
|
|
128
|
+
}
|
|
129
|
+
if (d) break;
|
|
130
|
+
}
|
|
131
|
+
d || s();
|
|
132
|
+
} else
|
|
133
|
+
s();
|
|
134
|
+
return !1;
|
|
135
|
+
},
|
|
136
|
+
B
|
|
137
|
+
);
|
|
138
|
+
const i = { update: (o) => e.update(o), getInternalEditor: () => e };
|
|
139
|
+
document.getElementById("table-row-above")?.addEventListener("click", () => {
|
|
140
|
+
l.insertRowAbove(i);
|
|
141
|
+
}), document.getElementById("table-row-below")?.addEventListener("click", () => {
|
|
142
|
+
l.insertRowBelow(i);
|
|
143
|
+
}), document.getElementById("table-row-delete")?.addEventListener("click", () => {
|
|
144
|
+
l.deleteRow(i);
|
|
145
|
+
}), document.getElementById("table-col-left")?.addEventListener("click", () => {
|
|
146
|
+
l.insertColumnLeft(i);
|
|
147
|
+
}), document.getElementById("table-col-right")?.addEventListener("click", () => {
|
|
148
|
+
l.insertColumnRight(i);
|
|
149
|
+
}), document.getElementById("table-col-delete")?.addEventListener("click", () => {
|
|
150
|
+
l.deleteColumn(i);
|
|
151
|
+
}), document.getElementById("table-merge")?.addEventListener("click", () => {
|
|
152
|
+
l.mergeCells(i);
|
|
153
|
+
}), document.getElementById("table-split")?.addEventListener("click", () => {
|
|
154
|
+
l.splitCell(i);
|
|
155
|
+
}), document.getElementById("table-delete")?.addEventListener("click", () => {
|
|
156
|
+
s(), l.deleteTable(i);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
export {
|
|
160
|
+
O as setupTablePopover
|
|
161
|
+
};
|