@notectl/core 1.0.5 → 1.0.6

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 (63) hide show
  1. package/README.md +2 -1
  2. package/dist/chunks/{ToolbarPlugin-D5VqeBPT.mjs → ToolbarPlugin-sJTiZr-S.mjs} +2 -2
  3. package/dist/chunks/ToolbarPlugin-sJTiZr-S.mjs.map +1 -0
  4. package/dist/chunks/index-QvKiO9_4.mjs +538 -0
  5. package/dist/chunks/index-QvKiO9_4.mjs.map +1 -0
  6. package/dist/editor/EditorDOM.d.ts.map +1 -1
  7. package/dist/editor/NotectlEditor.d.ts +5 -1
  8. package/dist/editor/NotectlEditor.d.ts.map +1 -1
  9. package/dist/index.d.ts +2 -0
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/notectl-core.mjs +1846 -1712
  12. package/dist/notectl-core.mjs.map +1 -1
  13. package/dist/notectl-core.umd.js +1050 -966
  14. package/dist/notectl-core.umd.js.map +1 -1
  15. package/dist/plugins/PluginManager.d.ts +3 -1
  16. package/dist/plugins/PluginManager.d.ts.map +1 -1
  17. package/dist/plugins/code-block/CodeBlockCommands.d.ts +5 -0
  18. package/dist/plugins/code-block/CodeBlockCommands.d.ts.map +1 -0
  19. package/dist/plugins/code-block/CodeBlockKeyboardHandlers.d.ts +10 -0
  20. package/dist/plugins/code-block/CodeBlockKeyboardHandlers.d.ts.map +1 -0
  21. package/dist/plugins/code-block/CodeBlockNodeView.d.ts +1 -1
  22. package/dist/plugins/code-block/CodeBlockNodeView.d.ts.map +1 -1
  23. package/dist/plugins/code-block/CodeBlockPlugin.d.ts +3 -111
  24. package/dist/plugins/code-block/CodeBlockPlugin.d.ts.map +1 -1
  25. package/dist/plugins/code-block/CodeBlockService.d.ts +5 -0
  26. package/dist/plugins/code-block/CodeBlockService.d.ts.map +1 -0
  27. package/dist/plugins/code-block/CodeBlockTypes.d.ts +69 -0
  28. package/dist/plugins/code-block/CodeBlockTypes.d.ts.map +1 -0
  29. package/dist/plugins/code-block.mjs +1 -1
  30. package/dist/plugins/font-size/FontSizeOperations.d.ts +22 -0
  31. package/dist/plugins/font-size/FontSizeOperations.d.ts.map +1 -0
  32. package/dist/plugins/font-size/FontSizePlugin.d.ts +1 -10
  33. package/dist/plugins/font-size/FontSizePlugin.d.ts.map +1 -1
  34. package/dist/plugins/font-size/FontSizePopup.d.ts +9 -0
  35. package/dist/plugins/font-size/FontSizePopup.d.ts.map +1 -0
  36. package/dist/plugins/font-size.mjs +146 -162
  37. package/dist/plugins/font-size.mjs.map +1 -1
  38. package/dist/plugins/font.mjs +1 -1
  39. package/dist/plugins/heading.mjs +1 -1
  40. package/dist/plugins/image/ImageNodeView.d.ts.map +1 -1
  41. package/dist/plugins/image.mjs +1 -1
  42. package/dist/plugins/image.mjs.map +1 -1
  43. package/dist/plugins/print/PrintContentPreparer.d.ts +12 -0
  44. package/dist/plugins/print/PrintContentPreparer.d.ts.map +1 -0
  45. package/dist/plugins/print/PrintPlugin.d.ts +12 -0
  46. package/dist/plugins/print/PrintPlugin.d.ts.map +1 -0
  47. package/dist/plugins/print/PrintServiceImpl.d.ts +7 -0
  48. package/dist/plugins/print/PrintServiceImpl.d.ts.map +1 -0
  49. package/dist/plugins/print/PrintStyleCollector.d.ts +10 -0
  50. package/dist/plugins/print/PrintStyleCollector.d.ts.map +1 -0
  51. package/dist/plugins/print/PrintTypes.d.ts +56 -0
  52. package/dist/plugins/print/PrintTypes.d.ts.map +1 -0
  53. package/dist/plugins/table/TableControls.d.ts.map +1 -1
  54. package/dist/plugins/table/TableControlsDOM.d.ts.map +1 -1
  55. package/dist/plugins/table.mjs +13 -13
  56. package/dist/plugins/table.mjs.map +1 -1
  57. package/dist/plugins/toolbar/ToolbarPlugin.d.ts.map +1 -1
  58. package/dist/plugins/toolbar.mjs +1 -1
  59. package/dist/view/Reconciler.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/dist/chunks/ToolbarPlugin-D5VqeBPT.mjs.map +0 -1
  62. package/dist/chunks/index-CPPb-Jah.mjs +0 -569
  63. package/dist/chunks/index-CPPb-Jah.mjs.map +0 -1
@@ -0,0 +1,538 @@
1
+ import { g as t, p as e, b as o, j as n, k as c } from "./Document-CI3iCwEP.mjs";
2
+ import { e as r } from "./HTMLUtils-0wvCRvJc.mjs";
3
+ import { c as s } from "./NodeSpec-NZVvcCuH.mjs";
4
+ import { i as l, a as i, c as a } from "./Selection-D5ZjXoB7.mjs";
5
+ import { n as d } from "./TypeBrands-C09nE2qO.mjs";
6
+ import { f as u } from "./ToolbarItem-ugDymuXi.mjs";
7
+ import { f } from "./NodeResolver-D68ZLXti.mjs";
8
+ import { S as g } from "./Plugin-B9OZ6Y4c.mjs";
9
+ function p(t2, e2) {
10
+ switch (t2.type) {
11
+ case "inline":
12
+ return (function(t3, e3) {
13
+ switch (e3.type) {
14
+ case "insertText":
15
+ return (function(t4, e4) {
16
+ if (t4.blockId !== e4.blockId) return t4;
17
+ const o2 = e4.text.length, n2 = t4.from > e4.offset ? t4.from + o2 : t4.from, c2 = t4.to >= e4.offset ? t4.to + o2 : t4.to;
18
+ return n2 === t4.from && c2 === t4.to ? t4 : { ...t4, from: n2, to: c2 };
19
+ })(t3, e3);
20
+ case "deleteText":
21
+ return (function(t4, e4) {
22
+ if (t4.blockId !== e4.blockId) return t4;
23
+ const o2 = e4.to - e4.from, n2 = b(t4.from, e4.from, e4.to, o2), c2 = b(t4.to, e4.from, e4.to, o2);
24
+ return n2 >= c2 ? null : n2 === t4.from && c2 === t4.to ? t4 : { ...t4, from: n2, to: c2 };
25
+ })(t3, e3);
26
+ case "splitBlock":
27
+ return (function(t4, e4) {
28
+ if (t4.blockId !== e4.blockId) return t4;
29
+ if (t4.to <= e4.offset) return t4;
30
+ if (t4.from >= e4.offset) return { ...t4, blockId: e4.newBlockId, from: t4.from - e4.offset, to: t4.to - e4.offset };
31
+ return [{ ...t4, to: e4.offset }, { ...t4, blockId: e4.newBlockId, from: 0, to: t4.to - e4.offset }];
32
+ })(t3, e3);
33
+ case "mergeBlocks":
34
+ return (function(t4, e4) {
35
+ return t4.blockId !== e4.sourceBlockId ? t4 : { ...t4, blockId: e4.targetBlockId, from: t4.from + e4.targetLengthBefore, to: t4.to + e4.targetLengthBefore };
36
+ })(t3, e3);
37
+ case "removeNode":
38
+ return k(t3, e3);
39
+ default:
40
+ return t3;
41
+ }
42
+ })(t2, e2);
43
+ case "widget":
44
+ return (function(t3, e3) {
45
+ switch (e3.type) {
46
+ case "insertText":
47
+ return (function(t4, e4) {
48
+ if (t4.blockId !== e4.blockId) return t4;
49
+ const o2 = e4.text.length;
50
+ return t4.offset > e4.offset || t4.offset === e4.offset && t4.side >= 1 ? { ...t4, offset: t4.offset + o2 } : t4;
51
+ })(t3, e3);
52
+ case "deleteText":
53
+ return (function(t4, e4) {
54
+ if (t4.blockId !== e4.blockId) return t4;
55
+ if (t4.offset > e4.from && t4.offset < e4.to) return null;
56
+ const o2 = e4.to - e4.from;
57
+ return t4.offset >= e4.to ? { ...t4, offset: t4.offset - o2 } : t4;
58
+ })(t3, e3);
59
+ case "splitBlock":
60
+ return (function(t4, e4) {
61
+ return t4.blockId !== e4.blockId || t4.offset < e4.offset ? t4 : t4.offset > e4.offset ? { ...t4, blockId: e4.newBlockId, offset: t4.offset - e4.offset } : t4.side >= 1 ? { ...t4, blockId: e4.newBlockId, offset: 0 } : t4;
62
+ })(t3, e3);
63
+ case "mergeBlocks":
64
+ return (function(t4, e4) {
65
+ return t4.blockId !== e4.sourceBlockId ? t4 : { ...t4, blockId: e4.targetBlockId, offset: t4.offset + e4.targetLengthBefore };
66
+ })(t3, e3);
67
+ case "removeNode":
68
+ return k(t3, e3);
69
+ default:
70
+ return t3;
71
+ }
72
+ })(t2, e2);
73
+ case "node":
74
+ return (function(t3, e3) {
75
+ switch (e3.type) {
76
+ case "mergeBlocks":
77
+ return (function(t4, e4) {
78
+ return t4.blockId === e4.sourceBlockId ? null : t4;
79
+ })(t3, e3);
80
+ case "removeNode":
81
+ return k(t3, e3);
82
+ default:
83
+ return t3;
84
+ }
85
+ })(t2, e2);
86
+ }
87
+ }
88
+ function k(t2, e2) {
89
+ return t2.blockId === e2.removedNode.id ? null : t2;
90
+ }
91
+ function b(t2, e2, o2, n2) {
92
+ return t2 <= e2 ? t2 : t2 >= o2 ? t2 - n2 : e2;
93
+ }
94
+ function h(t2, e2, o2, n2) {
95
+ return { type: "inline", blockId: t2, from: e2, to: o2, attrs: n2 };
96
+ }
97
+ function m(t2, e2) {
98
+ return { type: "node", blockId: t2, attrs: e2 };
99
+ }
100
+ function y(t2, e2, o2, n2) {
101
+ return { type: "widget", blockId: t2, offset: e2, toDOM: o2, side: n2?.side ?? -1, key: n2?.key };
102
+ }
103
+ class B {
104
+ constructor(t2) {
105
+ this.byBlock = t2;
106
+ }
107
+ static empty = new B(/* @__PURE__ */ new Map());
108
+ static create(t2) {
109
+ if (0 === t2.length) return B.empty;
110
+ const e2 = /* @__PURE__ */ new Map();
111
+ for (const o2 of t2) {
112
+ const t3 = e2.get(o2.blockId);
113
+ t3 ? t3.push(o2) : e2.set(o2.blockId, [o2]);
114
+ }
115
+ return new B(e2);
116
+ }
117
+ find(t2) {
118
+ return this.byBlock.get(t2) ?? [];
119
+ }
120
+ findInline(t2) {
121
+ const e2 = this.byBlock.get(t2);
122
+ return e2 ? e2.filter((t3) => "inline" === t3.type) : [];
123
+ }
124
+ findNode(t2) {
125
+ const e2 = this.byBlock.get(t2);
126
+ return e2 ? e2.filter((t3) => "node" === t3.type) : [];
127
+ }
128
+ findWidget(t2) {
129
+ const e2 = this.byBlock.get(t2);
130
+ return e2 ? e2.filter((t3) => "widget" === t3.type) : [];
131
+ }
132
+ add(t2) {
133
+ if (0 === t2.length) return this;
134
+ if (this.isEmpty) return B.create(t2);
135
+ const e2 = /* @__PURE__ */ new Map();
136
+ for (const [t3, o2] of this.byBlock) e2.set(t3, [...o2]);
137
+ for (const o2 of t2) {
138
+ const t3 = e2.get(o2.blockId);
139
+ t3 ? t3.push(o2) : e2.set(o2.blockId, [o2]);
140
+ }
141
+ return new B(e2);
142
+ }
143
+ remove(t2) {
144
+ const e2 = /* @__PURE__ */ new Map();
145
+ let o2 = false;
146
+ for (const [n2, c2] of this.byBlock) {
147
+ const r2 = c2.filter((e3) => !t2(e3));
148
+ r2.length !== c2.length && (o2 = true), r2.length > 0 && e2.set(n2, r2);
149
+ }
150
+ return o2 ? 0 === e2.size ? B.empty : new B(e2) : this;
151
+ }
152
+ merge(t2) {
153
+ if (t2.isEmpty) return this;
154
+ if (this.isEmpty) return t2;
155
+ const e2 = /* @__PURE__ */ new Map();
156
+ for (const [t3, o2] of this.byBlock) e2.set(t3, [...o2]);
157
+ for (const [o2, n2] of t2.byBlock) {
158
+ const t3 = e2.get(o2);
159
+ t3 ? t3.push(...n2) : e2.set(o2, [...n2]);
160
+ }
161
+ return new B(e2);
162
+ }
163
+ equals(t2) {
164
+ if (this === t2) return true;
165
+ if (this.byBlock.size !== t2.byBlock.size) return false;
166
+ for (const [e2, o2] of this.byBlock) {
167
+ const n2 = t2.byBlock.get(e2);
168
+ if (!n2) return false;
169
+ if (!I(o2, n2)) return false;
170
+ }
171
+ return true;
172
+ }
173
+ get isEmpty() {
174
+ return 0 === this.byBlock.size;
175
+ }
176
+ map(t2) {
177
+ if (this.isEmpty || 0 === t2.steps.length) return this;
178
+ let e2 = [];
179
+ for (const t3 of this.byBlock.values()) for (const o2 of t3) e2.push(o2);
180
+ for (const o2 of t2.steps) {
181
+ const t3 = [];
182
+ for (const n2 of e2) {
183
+ const e3 = p(n2, o2);
184
+ if (null !== e3) if (Array.isArray(e3)) for (const o3 of e3) t3.push(o3);
185
+ else t3.push(e3);
186
+ }
187
+ e2 = t3;
188
+ }
189
+ return 0 === e2.length ? B.empty : B.create(e2);
190
+ }
191
+ }
192
+ function I(t2, e2) {
193
+ if (t2 === e2) return true;
194
+ if (t2.length !== e2.length) return false;
195
+ for (let o2 = 0; o2 < t2.length; o2++) {
196
+ const n2 = t2[o2], c2 = e2[o2];
197
+ if (!n2 || !c2 || !x(n2, c2)) return false;
198
+ }
199
+ return true;
200
+ }
201
+ function x(t2, e2) {
202
+ if (t2.type !== e2.type) return false;
203
+ if (t2.blockId !== e2.blockId) return false;
204
+ switch (t2.type) {
205
+ case "inline": {
206
+ const o2 = e2;
207
+ return t2.from === o2.from && t2.to === o2.to && w(t2.attrs, o2.attrs);
208
+ }
209
+ case "node": {
210
+ const o2 = e2;
211
+ return w(t2.attrs, o2.attrs);
212
+ }
213
+ case "widget": {
214
+ const o2 = e2;
215
+ return t2.offset === o2.offset && t2.side === o2.side && t2.key === o2.key && t2.toDOM === o2.toDOM;
216
+ }
217
+ }
218
+ }
219
+ function w(t2, e2) {
220
+ if (t2 === e2) return true;
221
+ const o2 = Object.keys(t2), n2 = Object.keys(e2);
222
+ if (o2.length !== n2.length) return false;
223
+ for (const n3 of o2) if (t2[n3] !== e2[n3]) return false;
224
+ return true;
225
+ }
226
+ function C(t2, e2) {
227
+ const o2 = t2.getState();
228
+ if (l(o2.selection)) return false;
229
+ const n2 = o2.selection, c2 = o2.getBlock(n2.anchor.blockId);
230
+ return !(!c2 || "code_block" !== c2.type) && e2({ state: o2, block: c2, blockId: n2.anchor.blockId, offset: n2.anchor.offset });
231
+ }
232
+ function v(t2) {
233
+ return C(t2, ({ state: e2, blockId: o2 }) => {
234
+ const n2 = e2.getBlockOrder(), c2 = n2.indexOf(o2);
235
+ if (c2 < n2.length - 1) {
236
+ const o3 = n2[c2 + 1], r2 = e2.transaction("command").setSelection(a(o3, 0)).build();
237
+ t2.dispatch(r2);
238
+ } else _(t2, o2);
239
+ return true;
240
+ });
241
+ }
242
+ function _(e2, n2) {
243
+ const c2 = e2.getState(), r2 = c2.getBlock(n2);
244
+ if (!r2) return;
245
+ const s2 = t(r2), l2 = o(), i2 = c2.transaction("command").splitBlock(n2, s2, l2).setBlockType(l2, d("paragraph")).setSelection(a(l2, 0)).build();
246
+ e2.dispatch(i2);
247
+ }
248
+ function S(e2, o2) {
249
+ const r2 = e2.getState(), s2 = r2.selection;
250
+ if (l(s2)) return false;
251
+ const i2 = r2.getBlock(s2.anchor.blockId);
252
+ if (!i2 || "code_block" === i2.type) return false;
253
+ const u2 = { language: o2.defaultLanguage ?? "", backgroundColor: "" }, f2 = r2.transaction("command");
254
+ return (function(e3, o3) {
255
+ if (0 === t(o3)) return;
256
+ const r3 = n(o3);
257
+ let s3 = 0;
258
+ for (const t2 of r3) if (c(t2)) {
259
+ if (t2.text.length > 0) for (const n2 of t2.marks) e3.removeMark(o3.id, s3, s3 + t2.text.length, n2);
260
+ s3 += t2.text.length;
261
+ } else s3 += 1;
262
+ })(f2, i2), f2.setBlockType(s2.anchor.blockId, d("code_block"), u2).setSelection(a(s2.anchor.blockId, 0)), e2.dispatch(f2.build()), true;
263
+ }
264
+ const A = { insertAfter: "Mod-Enter", toggle: "Mod-Shift-M" }, T = { defaultLanguage: "", useSpaces: false, spaceCount: 2, showCopyButton: true }, M = new g("codeBlock");
265
+ function N(t2, e2, o2, n2) {
266
+ const c2 = t2.getState(), r2 = c2.getBlock(e2);
267
+ if (!r2 || "code_block" !== r2.type) return;
268
+ const s2 = f(c2.doc, e2);
269
+ if (!s2) return;
270
+ const l2 = { ...r2.attrs, [o2]: n2 }, i2 = c2.transaction("command").setNodeAttr(s2, l2).build();
271
+ t2.dispatch(i2);
272
+ }
273
+ class L {
274
+ id = "code-block";
275
+ name = "Code Block";
276
+ priority = 36;
277
+ config;
278
+ resolvedKeymap;
279
+ context = null;
280
+ constructor(t2) {
281
+ this.config = { ...T, ...t2 }, this.resolvedKeymap = { ...A, ...t2?.keymap };
282
+ }
283
+ init(n2) {
284
+ n2.registerStyleSheet("\n/* Code Block — uses theme custom properties */\n.notectl-code-block {\n position: relative;\n margin: 8px 0;\n border-radius: 6px;\n background: var(--notectl-code-block-bg);\n color: var(--notectl-code-block-color);\n font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;\n font-size: 14px;\n line-height: 1.5;\n overflow: hidden;\n}\n\n.notectl-code-block__header {\n display: flex;\n align-items: center;\n justify-content: space-between;\n padding: 6px 12px;\n background: var(--notectl-code-block-header-bg);\n border-bottom: 1px solid var(--notectl-code-block-header-border);\n font-size: 12px;\n color: var(--notectl-code-block-header-color);\n user-select: none;\n}\n\n.notectl-code-block__language {\n font-weight: 500;\n letter-spacing: 0.02em;\n}\n\n.notectl-code-block__copy {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n border: none;\n border-radius: 4px;\n background: transparent;\n color: var(--notectl-code-block-header-color);\n cursor: pointer;\n padding: 0;\n transition: background 0.15s, color 0.15s;\n}\n\n.notectl-code-block__copy:hover {\n background: rgba(128, 128, 128, 0.15);\n color: var(--notectl-code-block-color);\n}\n\n.notectl-code-block__copy svg {\n fill: currentColor;\n}\n\n.notectl-code-block__content {\n display: block;\n padding: 12px 16px;\n white-space: pre-wrap;\n word-wrap: break-word;\n tab-size: 4;\n -moz-tab-size: 4;\n outline: none;\n min-height: 1.5em;\n}\n\n.notectl-code-block--selected {\n outline: 2px solid var(--notectl-primary);\n outline-offset: 2px;\n}\n\n.notectl-code-block__esc-hint {\n display: none;\n position: absolute;\n bottom: 4px;\n right: 8px;\n font-size: 11px;\n color: var(--notectl-code-block-header-color);\n opacity: 0.5;\n pointer-events: none;\n user-select: none;\n font-family: system-ui, sans-serif;\n}\n\n.notectl-code-block--focused .notectl-code-block__esc-hint {\n display: block;\n}\n"), this.context = n2, this.registerNodeSpec(n2), this.registerNodeView(n2), (function(t2, e2) {
285
+ t2.registerCommand("toggleCodeBlock", () => (function(t3, e3) {
286
+ const o2 = t3.getState();
287
+ if (l(o2.selection)) return false;
288
+ const n3 = o2.getBlock(o2.selection.anchor.blockId);
289
+ if (!n3) return false;
290
+ if ("code_block" === n3.type) {
291
+ const e4 = o2.transaction("command").setBlockType(o2.selection.anchor.blockId, d("paragraph")).setSelection(o2.selection).build();
292
+ return t3.dispatch(e4), true;
293
+ }
294
+ return S(t3, e3);
295
+ })(t2, e2)), t2.registerCommand("insertCodeBlock", () => S(t2, e2)), t2.registerCommand("setCodeBlockLanguage", () => false), t2.registerCommand("setCodeBlockBackground", () => false), t2.registerCommand("exitCodeBlock", () => v(t2));
296
+ })(n2, this.config), (function(n3, c2, r2) {
297
+ const s2 = { Enter: () => (function(t2) {
298
+ return C(t2, ({ state: n4, block: c3, blockId: r3, offset: s3 }) => {
299
+ if (!i(n4.selection)) return false;
300
+ const l3 = e(c3);
301
+ if (l3.endsWith("\n") && s3 === l3.length) return (function(t3, e2, n5) {
302
+ const c4 = t3.getState(), r4 = n5.length - 1, s4 = o(), l4 = c4.transaction("input").deleteTextAt(e2, r4, n5.length).splitBlock(e2, r4, s4).setBlockType(s4, d("paragraph")).setSelection(a(s4, 0)).build();
303
+ return t3.dispatch(l4), true;
304
+ })(t2, r3, l3);
305
+ const u3 = n4.transaction("input").insertText(r3, s3, "\n", []).setSelection(a(r3, s3 + 1)).build();
306
+ return t2.dispatch(u3), true;
307
+ });
308
+ })(n3), Backspace: () => (function(t2) {
309
+ return C(t2, ({ state: e2, blockId: o2, offset: n4 }) => {
310
+ if (!i(e2.selection)) return false;
311
+ if (0 !== n4) return false;
312
+ const c3 = e2.transaction("input").setBlockType(o2, d("paragraph")).setSelection(e2.selection).build();
313
+ return t2.dispatch(c3), true;
314
+ });
315
+ })(n3), Tab: () => (function(t2, e2) {
316
+ return C(t2, ({ state: o2, blockId: n4, offset: c3 }) => {
317
+ const r3 = e2.useSpaces ? " ".repeat(e2.spaceCount ?? 2) : " ", s3 = o2.transaction("input").insertText(n4, c3, r3, []).setSelection(a(n4, c3 + r3.length)).build();
318
+ return t2.dispatch(s3), true;
319
+ });
320
+ })(n3, c2), "Shift-Tab": () => (function(t2, o2) {
321
+ return C(t2, ({ state: n4, block: c3, blockId: r3, offset: s3 }) => {
322
+ const l3 = e(c3), i2 = l3.lastIndexOf("\n", s3 - 1) + 1;
323
+ if (o2.useSpaces) {
324
+ const e2 = o2.spaceCount ?? 2;
325
+ if (l3.slice(i2, i2 + e2) === " ".repeat(e2)) {
326
+ const o3 = n4.transaction("input").deleteTextAt(r3, i2, i2 + e2).setSelection(a(r3, Math.max(i2, s3 - e2))).build();
327
+ return t2.dispatch(o3), true;
328
+ }
329
+ } else if (" " === l3[i2]) {
330
+ const e2 = n4.transaction("input").deleteTextAt(r3, i2, i2 + 1).setSelection(a(r3, Math.max(i2, s3 - 1))).build();
331
+ return t2.dispatch(e2), true;
332
+ }
333
+ return true;
334
+ });
335
+ })(n3, c2), Escape: () => v(n3), ArrowDown: () => (function(t2) {
336
+ return C(t2, ({ state: o2, block: n4, blockId: c3, offset: r3 }) => {
337
+ if (!i(o2.selection)) return false;
338
+ if (-1 !== e(n4).indexOf("\n", r3)) return false;
339
+ const s3 = o2.getBlockOrder(), l3 = s3.indexOf(c3);
340
+ if (l3 < s3.length - 1) {
341
+ const e2 = s3[l3 + 1], n5 = o2.transaction("command").setSelection(a(e2, 0)).build();
342
+ t2.dispatch(n5);
343
+ } else _(t2, c3);
344
+ return true;
345
+ });
346
+ })(n3), ArrowUp: () => (function(o2) {
347
+ return C(o2, ({ state: n4, block: c3, blockId: r3, offset: s3 }) => {
348
+ if (!i(n4.selection)) return false;
349
+ const l3 = e(c3).indexOf("\n");
350
+ if (-1 !== l3 && s3 > l3) return false;
351
+ const d2 = n4.getBlockOrder(), u3 = d2.indexOf(r3);
352
+ if (u3 > 0) {
353
+ const e2 = d2[u3 - 1], c4 = n4.getBlock(e2), r4 = c4 ? t(c4) : 0, s4 = n4.transaction("command").setSelection(a(e2, r4)).build();
354
+ return o2.dispatch(s4), true;
355
+ }
356
+ return false;
357
+ });
358
+ })(n3), ArrowRight: () => (function(t2) {
359
+ return C(t2, ({ state: o2, block: n4, blockId: c3, offset: r3 }) => {
360
+ if (!i(o2.selection)) return false;
361
+ if (r3 !== e(n4).length) return false;
362
+ const s3 = o2.getBlockOrder(), l3 = s3.indexOf(c3);
363
+ if (l3 < s3.length - 1) {
364
+ const e2 = s3[l3 + 1], n5 = o2.transaction("command").setSelection(a(e2, 0)).build();
365
+ t2.dispatch(n5);
366
+ } else _(t2, c3);
367
+ return true;
368
+ });
369
+ })(n3), ArrowLeft: () => (function(e2) {
370
+ return C(e2, ({ state: o2, blockId: n4, offset: c3 }) => {
371
+ if (!i(o2.selection)) return false;
372
+ if (0 !== c3) return false;
373
+ const r3 = o2.getBlockOrder(), s3 = r3.indexOf(n4);
374
+ if (s3 > 0) {
375
+ const n5 = r3[s3 - 1], c4 = o2.getBlock(n5), l3 = c4 ? t(c4) : 0, i2 = o2.transaction("command").setSelection(a(n5, l3)).build();
376
+ return e2.dispatch(i2), true;
377
+ }
378
+ return false;
379
+ });
380
+ })(n3) }, { insertAfter: l2, toggle: u2 } = r2;
381
+ l2 && (s2[l2] = () => (function(t2) {
382
+ return C(t2, ({ blockId: e2 }) => (_(t2, e2), true));
383
+ })(n3)), u2 && (s2[u2] = () => n3.executeCommand("toggleCodeBlock")), n3.registerKeymap(s2);
384
+ })(n2, this.config, this.resolvedKeymap), this.registerInputRule(n2), this.registerToolbarItem(n2), this.registerMiddleware(n2), (function(t2, e2, o2) {
385
+ t2.registerService(M, { setLanguage(e3, o3) {
386
+ N(t2, e3, "language", o3);
387
+ }, getLanguage(t3) {
388
+ const e3 = o2();
389
+ if (!e3) return "";
390
+ const n3 = e3.getState().getBlock(t3);
391
+ return n3 && "code_block" === n3.type ? n3.attrs?.language ?? "" : "";
392
+ }, setBackground(e3, o3) {
393
+ N(t2, e3, "backgroundColor", o3);
394
+ }, getBackground(t3) {
395
+ const e3 = o2();
396
+ if (!e3) return "";
397
+ const n3 = e3.getState().getBlock(t3);
398
+ return n3 && "code_block" === n3.type ? n3.attrs?.backgroundColor ?? "" : "";
399
+ }, isCodeBlock(t3) {
400
+ const e3 = o2();
401
+ if (!e3) return false;
402
+ const n3 = e3.getState().getBlock(t3);
403
+ return "code_block" === n3?.type;
404
+ }, getSupportedLanguages: () => e2.highlighter ? e2.highlighter.getSupportedLanguages() : [] });
405
+ })(n2, this.config, () => this.context), this.patchTableCellContent(n2);
406
+ }
407
+ destroy() {
408
+ this.context = null;
409
+ }
410
+ onStateChange(t2, e2, o2) {
411
+ if (!this.context) return;
412
+ const n2 = l(t2.selection) ? null : t2.selection.anchor.blockId, c2 = l(e2.selection) ? null : e2.selection.anchor.blockId, r2 = n2 ? t2.getBlock(n2) : void 0, s2 = c2 ? e2.getBlock(c2) : void 0, i2 = "code_block" === r2?.type, a2 = "code_block" === s2?.type;
413
+ i2 && n2 && this.setBlockFocused(n2, false), a2 && c2 && this.setBlockFocused(c2, true), !i2 && a2 ? this.context.announce("Entered code block. Press Escape to exit.") : i2 && !a2 && this.context.announce("Left code block.");
414
+ }
415
+ decorations(t2) {
416
+ if (!this.config.highlighter) return B.empty;
417
+ const o2 = [], n2 = this.config.highlighter;
418
+ for (const c2 of t2.getBlockOrder()) {
419
+ const r2 = t2.getBlock(c2);
420
+ if (!r2 || "code_block" !== r2.type) continue;
421
+ const s2 = r2.attrs?.language ?? "";
422
+ if (!s2) continue;
423
+ const l2 = e(r2);
424
+ if (!l2) continue;
425
+ const i2 = n2.tokenize(l2, s2);
426
+ for (const t3 of i2) o2.push(h(c2, t3.from, t3.to, { class: `notectl-token--${t3.type}` }));
427
+ }
428
+ return B.create(o2);
429
+ }
430
+ registerNodeSpec(t2) {
431
+ t2.registerNodeSpec({ type: "code_block", group: "block", content: { allow: ["text"] }, selectable: true, attrs: { language: { default: "" }, backgroundColor: { default: "" } }, toDOM(t3) {
432
+ const e2 = s("pre", t3.id);
433
+ e2.className = "notectl-code-block";
434
+ const o2 = document.createElement("code");
435
+ return o2.className = "notectl-code-block__content", e2.appendChild(o2), e2;
436
+ }, toHTML(t3, e2) {
437
+ const o2 = r(t3.attrs?.language ?? ""), n2 = r(t3.attrs?.backgroundColor ?? "");
438
+ return `<pre${n2 ? ` style="background-color: ${n2}"` : ""}><code${o2 ? ` data-language="${o2}"` : ""}>${e2 || ""}</code></pre>`;
439
+ }, parseHTML: [{ tag: "pre", getAttrs(t3) {
440
+ const e2 = t3.querySelector("code"), o2 = e2?.className.match(/language-(\S+)/)?.[1] ?? "";
441
+ return { language: (e2?.getAttribute("data-language") ?? "") || o2 };
442
+ } }], sanitize: { tags: ["pre", "code"], attrs: ["data-language", "class", "style"] } });
443
+ }
444
+ registerNodeView(t2) {
445
+ var o2;
446
+ t2.registerNodeView("code_block", (o2 = this.config, (t3, n2, c2) => {
447
+ const r2 = document.createElement("pre");
448
+ r2.className = "notectl-code-block", r2.setAttribute("data-block-id", t3.id), r2.setAttribute("role", "group"), r2.setAttribute("aria-roledescription", "code block");
449
+ const s2 = document.createElement("div");
450
+ s2.className = "notectl-code-block__header", s2.setAttribute("contenteditable", "false");
451
+ const l2 = document.createElement("span");
452
+ l2.className = "notectl-code-block__language";
453
+ let i2 = null;
454
+ false !== o2.showCopyButton && (i2 = document.createElement("button"), i2.className = "notectl-code-block__copy", i2.setAttribute("aria-label", "Copy code"), i2.setAttribute("data-notectl-no-print", ""), i2.type = "button", i2.innerHTML = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="14" height="14"><path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"/></svg>');
455
+ const a2 = document.createElement("span");
456
+ a2.className = "notectl-sr-only", a2.setAttribute("aria-live", "assertive"), a2.setAttribute("aria-atomic", "true"), s2.appendChild(l2), i2 && s2.appendChild(i2), s2.appendChild(a2);
457
+ const d2 = document.createElement("code");
458
+ d2.className = "notectl-code-block__content";
459
+ const u2 = document.createElement("div");
460
+ u2.className = "notectl-code-block__esc-hint", u2.setAttribute("contenteditable", "false"), u2.setAttribute("aria-hidden", "true"), u2.setAttribute("data-notectl-no-print", ""), u2.textContent = "Esc to exit", r2.appendChild(s2), r2.appendChild(d2), r2.appendChild(u2), o2.background && r2.style.setProperty("--notectl-code-block-bg", o2.background), o2.headerBackground && r2.style.setProperty("--notectl-code-block-header-bg", o2.headerBackground), o2.textColor && r2.style.setProperty("--notectl-code-block-color", o2.textColor), o2.headerColor && r2.style.setProperty("--notectl-code-block-header-color", o2.headerColor);
461
+ let f2 = t3.id;
462
+ function g2(t4) {
463
+ const e2 = t4.attrs?.language ?? "", o3 = e2 || "plain";
464
+ l2.textContent = o3, r2.setAttribute("aria-label", `${o3} code block. Press Escape to exit.`), e2 ? d2.setAttribute("data-language", e2) : d2.removeAttribute("data-language");
465
+ const n3 = t4.attrs?.backgroundColor ?? "";
466
+ r2.style.backgroundColor = n3 || "";
467
+ }
468
+ return g2(t3), i2 && i2.addEventListener("click", (t4) => {
469
+ t4.preventDefault(), t4.stopPropagation();
470
+ const o3 = n2().getBlock(f2);
471
+ if (!o3) return;
472
+ const c3 = e(o3);
473
+ navigator.clipboard.writeText(c3), a2.textContent = "Copied to clipboard", setTimeout(() => {
474
+ a2.textContent = "";
475
+ }, 1e3);
476
+ }), { dom: r2, contentDOM: d2, update: (t4) => "code_block" === t4.type && (f2 = t4.id, r2.setAttribute("data-block-id", t4.id), g2(t4), true), selectNode() {
477
+ r2.classList.add("notectl-code-block--selected");
478
+ }, deselectNode() {
479
+ r2.classList.remove("notectl-code-block--selected");
480
+ }, destroy() {
481
+ } };
482
+ }));
483
+ }
484
+ registerInputRule(t2) {
485
+ t2.registerInputRule({ pattern: /^```(\w*) $/, handler: (t3, e2, o2, n2) => {
486
+ const c2 = t3.selection;
487
+ if (l(c2)) return null;
488
+ if (!i(c2)) return null;
489
+ const r2 = t3.getBlock(c2.anchor.blockId);
490
+ if (!r2 || "paragraph" !== r2.type) return null;
491
+ const s2 = { language: e2[1] ?? "", backgroundColor: "" };
492
+ return t3.transaction("input").deleteTextAt(c2.anchor.blockId, o2, o2 + e2[0].length).setBlockType(c2.anchor.blockId, d("code_block"), s2).setSelection(a(c2.anchor.blockId, 0)).build();
493
+ } });
494
+ }
495
+ registerToolbarItem(t2) {
496
+ t2.registerToolbarItem({ id: "code_block", group: "block", icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.4 16.6L4.8 12l4.6-4.6L8 6l-6 6 6 6 1.4-1.4zm5.2 0l4.6-4.6-4.6-4.6L16 6l6 6-6 6-1.4-1.4z"/></svg>', label: "Code Block", tooltip: this.resolvedKeymap.toggle ? `Code Block (${u(this.resolvedKeymap.toggle)})` : "Code Block", command: "toggleCodeBlock", priority: 56, separatorAfter: this.config.separatorAfter, isActive: (t3) => {
497
+ if (l(t3.selection)) return false;
498
+ const e2 = t3.getBlock(t3.selection.anchor.blockId);
499
+ return "code_block" === e2?.type;
500
+ } });
501
+ }
502
+ registerMiddleware(t2) {
503
+ t2.registerMiddleware((t3, e2, o2) => {
504
+ if (!t3.steps.some((t4) => {
505
+ if ("addMark" !== t4.type) return false;
506
+ const o3 = e2.getBlock(t4.blockId);
507
+ return "code_block" === o3?.type;
508
+ })) return void o2(t3);
509
+ const n2 = t3.steps.filter((t4) => {
510
+ if ("addMark" !== t4.type) return true;
511
+ const o3 = e2.getBlock(t4.blockId);
512
+ return "code_block" !== o3?.type;
513
+ });
514
+ o2({ ...t3, steps: n2 });
515
+ }, 50);
516
+ }
517
+ patchTableCellContent(t2) {
518
+ const e2 = t2.getSchemaRegistry(), o2 = e2.getNodeSpec("table_cell");
519
+ if (!o2?.content) return;
520
+ const n2 = o2.content.allow ?? [];
521
+ n2.includes("code_block") || (e2.removeNodeSpec("table_cell"), e2.registerNodeSpec({ ...o2, content: { ...o2.content, allow: [...n2, "code_block"] } }));
522
+ }
523
+ setBlockFocused(t2, e2) {
524
+ if (!this.context) return;
525
+ const o2 = this.context.getContainer().querySelector(`[data-block-id="${t2}"]`);
526
+ o2 && o2.classList.toggle("notectl-code-block--focused", e2);
527
+ }
528
+ }
529
+ export {
530
+ M as C,
531
+ B as D,
532
+ L as a,
533
+ I as d,
534
+ h as i,
535
+ m as n,
536
+ y as w
537
+ };
538
+ //# sourceMappingURL=index-QvKiO9_4.mjs.map