@haklex/rich-editor 0.0.81 → 0.0.83

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 (66) hide show
  1. package/dist/AlertQuoteEditNode-B2q-1u6S.js +293 -0
  2. package/dist/KaTeXRenderer-BFryJSIS.js +218 -0
  3. package/dist/LinkCardRenderer-QmkOlyXb.js +36 -0
  4. package/dist/MermaidPlugin-BEtIhQHn.js +97 -0
  5. package/dist/PresentDialogContext-D5dHWtzD.js +58 -0
  6. package/dist/RubyRenderer-cm5eDc9q.js +14 -0
  7. package/dist/SubmitShortcutPlugin-o2y6b-8f.js +1650 -0
  8. package/dist/commands-entry.mjs +23 -14
  9. package/dist/components/LinkFavicon.d.ts.map +1 -1
  10. package/dist/components/renderers/FootnoteRenderer.d.ts.map +1 -1
  11. package/dist/components/renderers/FootnoteSectionEditRenderer.d.ts.map +1 -1
  12. package/dist/components/renderers/FootnoteSectionRenderer.d.ts.map +1 -1
  13. package/dist/components/renderers/FootnoteStaticRenderer.d.ts.map +1 -1
  14. package/dist/components/renderers/RubyRenderer.d.ts.map +1 -1
  15. package/dist/components/renderers/TagRenderer.d.ts.map +1 -1
  16. package/dist/config-BP_kyJbW.js +1363 -0
  17. package/dist/config-edit.d.ts.map +1 -1
  18. package/dist/config.d.ts.map +1 -1
  19. package/dist/context/NestedContentRendererContext.d.ts +2 -1
  20. package/dist/context/NestedContentRendererContext.d.ts.map +1 -1
  21. package/dist/favicon-BQgbXF_a.js +43 -0
  22. package/dist/index.mjs +283 -259
  23. package/dist/node-registry-Dzp7X3R4.js +811 -0
  24. package/dist/nodes/AlertQuoteNode.d.ts.map +1 -1
  25. package/dist/nodes/CommentNode.d.ts +21 -0
  26. package/dist/nodes/CommentNode.d.ts.map +1 -0
  27. package/dist/nodes/FootnoteNode.d.ts.map +1 -1
  28. package/dist/nodes/FootnoteSectionNode.d.ts.map +1 -1
  29. package/dist/nodes/RubyNode.d.ts.map +1 -1
  30. package/dist/nodes/SpoilerNode.d.ts.map +1 -1
  31. package/dist/nodes/TagNode.d.ts.map +1 -1
  32. package/dist/nodes-entry.d.ts +2 -0
  33. package/dist/nodes-entry.d.ts.map +1 -1
  34. package/dist/nodes-entry.mjs +50 -7
  35. package/dist/plugins/MarkdownPastePlugin.d.ts.map +1 -1
  36. package/dist/plugins-entry.mjs +27 -10
  37. package/dist/renderers-entry.mjs +61 -40
  38. package/dist/rich-editor.css +1 -2
  39. package/dist/static-entry.d.ts +1 -1
  40. package/dist/static-entry.d.ts.map +1 -1
  41. package/dist/static-entry.mjs +55 -16
  42. package/dist/styles/shared.css.d.ts +164 -0
  43. package/dist/styles/shared.css.d.ts.map +1 -1
  44. package/dist/styles/theme.d.ts.map +1 -1
  45. package/dist/styles-entry.d.ts +2 -2
  46. package/dist/styles-entry.d.ts.map +1 -1
  47. package/dist/styles-entry.mjs +14 -3
  48. package/dist/theme-Cg8JUW_j.js +1034 -0
  49. package/dist/transformers/comment.d.ts +4 -0
  50. package/dist/transformers/comment.d.ts.map +1 -0
  51. package/dist/transformers/index.d.ts +1 -0
  52. package/dist/transformers/index.d.ts.map +1 -1
  53. package/dist/utils-gy2c_HWc.js +24 -0
  54. package/package.json +4 -4
  55. package/dist/AlertQuoteEditNode-BDoonB4u.js +0 -267
  56. package/dist/KaTeXRenderer-BsyRH5_t.js +0 -214
  57. package/dist/LinkCardRenderer-OEMBDUhD.js +0 -45
  58. package/dist/MermaidPlugin-Df2Cm2yX.js +0 -67
  59. package/dist/PresentDialogContext-DQw6MrNh.js +0 -59
  60. package/dist/RubyRenderer-BpDb_amz.js +0 -14
  61. package/dist/SubmitShortcutPlugin-6IvsbZD-.js +0 -1463
  62. package/dist/config-tfg1FWhG.js +0 -1149
  63. package/dist/favicon-DIWusrrw.js +0 -41
  64. package/dist/node-registry-CeVi2y9f.js +0 -666
  65. package/dist/shared.css-wgGgtK_e.js +0 -23
  66. package/dist/theme-DHOUKKSr.js +0 -1034
@@ -1,1034 +0,0 @@
1
- import { i as FootnoteStaticRenderer, l as RendererWrapper, r as decodeThumbHash, t as KaTeXRenderer, u as createRendererDecoration } from "./KaTeXRenderer-BsyRH5_t.js";
2
- import { createContext, createElement, use, useCallback, useEffect, useMemo, useState } from "react";
3
- import { $getNodeByKey, $getSelection, $insertNodes, $isRangeSelection, DecoratorNode, ElementNode, TextNode, createCommand } from "lexical";
4
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
- import { ImageIcon, Info, Lightbulb, MessageSquareWarning, OctagonAlert, Sigma, Tag, TriangleAlert, Workflow } from "lucide-react";
6
- //#region src/context/NestedContentRendererContext.tsx
7
- var NestedContentRendererContext = createContext(null);
8
- var NestedContentRendererProvider = NestedContentRendererContext.Provider;
9
- function useOptionalNestedContentRenderer() {
10
- return use(NestedContentRendererContext);
11
- }
12
- function useNestedContentRenderer() {
13
- const fn = use(NestedContentRendererContext);
14
- if (!fn) throw new Error("useNestedContentRenderer must be used within a NestedContentRendererProvider");
15
- return fn;
16
- }
17
- //#endregion
18
- //#region src/components/renderers/AlertRenderer.tsx
19
- var InfoIcon = () => /* @__PURE__ */ jsx(Info, { size: 16 });
20
- var LightbulbIcon = () => /* @__PURE__ */ jsx(Lightbulb, { size: 16 });
21
- var MessageWarningIcon = () => /* @__PURE__ */ jsx(MessageSquareWarning, { size: 16 });
22
- var TriangleAlertIcon = () => /* @__PURE__ */ jsx(TriangleAlert, { size: 16 });
23
- var OctagonAlertIcon = () => /* @__PURE__ */ jsx(OctagonAlert, { size: 16 });
24
- var ALERT_ICONS = {
25
- note: InfoIcon,
26
- tip: LightbulbIcon,
27
- important: MessageWarningIcon,
28
- warning: TriangleAlertIcon,
29
- caution: OctagonAlertIcon
30
- };
31
- var AlertRenderer = ({ type }) => {
32
- const Icon = ALERT_ICONS[type];
33
- return /* @__PURE__ */ jsxs("div", {
34
- className: `rich-alert-header rich-alert-header-${type}`,
35
- children: [/* @__PURE__ */ jsx("span", {
36
- className: "rich-alert-icon",
37
- children: /* @__PURE__ */ jsx(Icon, {})
38
- }), /* @__PURE__ */ jsx("span", {
39
- className: "rich-alert-label",
40
- children: ALERT_LABELS[type]
41
- })]
42
- });
43
- };
44
- //#endregion
45
- //#region src/components/renderers/AlertStaticDecorator.tsx
46
- function AlertStaticDecorator({ alertType, contentState }) {
47
- const renderContent = useNestedContentRenderer();
48
- return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(RendererWrapper, {
49
- defaultRenderer: AlertRenderer,
50
- props: { type: alertType },
51
- rendererKey: "Alert"
52
- }), /* @__PURE__ */ jsx("div", {
53
- className: "rich-alert-content",
54
- children: renderContent(contentState)
55
- })] });
56
- }
57
- //#endregion
58
- //#region src/utils/extractTextContent.ts
59
- function extractTextContent(state) {
60
- function walk(node) {
61
- if (node.text) return node.text;
62
- if (node.children) return node.children.map(walk).join("");
63
- if (node.root) return walk(node.root);
64
- return "";
65
- }
66
- return walk(state);
67
- }
68
- //#endregion
69
- //#region \0@oxc-project+runtime@0.115.0/helpers/typeof.js
70
- function _typeof(o) {
71
- "@babel/helpers - typeof";
72
- return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
73
- return typeof o;
74
- } : function(o) {
75
- return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
76
- }, _typeof(o);
77
- }
78
- //#endregion
79
- //#region \0@oxc-project+runtime@0.115.0/helpers/toPrimitive.js
80
- function toPrimitive(t, r) {
81
- if ("object" != _typeof(t) || !t) return t;
82
- var e = t[Symbol.toPrimitive];
83
- if (void 0 !== e) {
84
- var i = e.call(t, r || "default");
85
- if ("object" != _typeof(i)) return i;
86
- throw new TypeError("@@toPrimitive must return a primitive value.");
87
- }
88
- return ("string" === r ? String : Number)(t);
89
- }
90
- //#endregion
91
- //#region \0@oxc-project+runtime@0.115.0/helpers/toPropertyKey.js
92
- function toPropertyKey(t) {
93
- var i = toPrimitive(t, "string");
94
- return "symbol" == _typeof(i) ? i : i + "";
95
- }
96
- //#endregion
97
- //#region \0@oxc-project+runtime@0.115.0/helpers/defineProperty.js
98
- function _defineProperty(e, r, t) {
99
- return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
100
- value: t,
101
- enumerable: !0,
102
- configurable: !0,
103
- writable: !0
104
- }) : e[r] = t, e;
105
- }
106
- //#endregion
107
- //#region src/nodes/AlertQuoteNode.ts
108
- var ALERT_TYPES = [
109
- "note",
110
- "tip",
111
- "important",
112
- "warning",
113
- "caution"
114
- ];
115
- var ALERT_LABELS = {
116
- note: "Note",
117
- tip: "Tip",
118
- important: "Important",
119
- warning: "Warning",
120
- caution: "Caution"
121
- };
122
- var AlertQuoteNode = class AlertQuoteNode extends DecoratorNode {
123
- static getType() {
124
- return "alert-quote";
125
- }
126
- static clone(node) {
127
- return new AlertQuoteNode(node.__alertType, node.__contentState, node.__key);
128
- }
129
- constructor(alertType, contentState, key) {
130
- super(key);
131
- _defineProperty(this, "__alertType", void 0);
132
- _defineProperty(this, "__contentState", void 0);
133
- this.__alertType = alertType;
134
- this.__contentState = contentState || { root: {
135
- children: [{
136
- type: "paragraph",
137
- children: [],
138
- direction: null,
139
- format: "",
140
- indent: 0,
141
- textFormat: 0,
142
- textStyle: "",
143
- version: 1
144
- }],
145
- direction: null,
146
- format: "",
147
- indent: 0,
148
- type: "root",
149
- version: 1
150
- } };
151
- }
152
- createDOM(_config) {
153
- const div = document.createElement("div");
154
- div.className = `rich-alert rich-alert-${this.__alertType}`;
155
- return div;
156
- }
157
- updateDOM(prevNode, dom) {
158
- if (prevNode.__alertType !== this.__alertType) dom.className = `rich-alert rich-alert-${this.__alertType}`;
159
- return false;
160
- }
161
- isInline() {
162
- return false;
163
- }
164
- getAlertType() {
165
- return this.__alertType;
166
- }
167
- setAlertType(alertType) {
168
- const writable = this.getWritable();
169
- writable.__alertType = alertType;
170
- }
171
- getContentState() {
172
- return this.getLatest().__contentState;
173
- }
174
- setContentState(state) {
175
- const writable = this.getWritable();
176
- writable.__contentState = state;
177
- }
178
- getTextContent() {
179
- return extractTextContent(this.__contentState);
180
- }
181
- static importJSON(serializedNode) {
182
- return new AlertQuoteNode(serializedNode.alertType, serializedNode.content);
183
- }
184
- exportJSON() {
185
- return {
186
- ...super.exportJSON(),
187
- type: "alert-quote",
188
- alertType: this.__alertType,
189
- content: this.__contentState,
190
- version: 1
191
- };
192
- }
193
- decorate(_editor, _config) {
194
- return createElement(AlertStaticDecorator, {
195
- alertType: this.__alertType,
196
- contentState: this.__contentState
197
- });
198
- }
199
- };
200
- function $isAlertQuoteNode(node) {
201
- return node instanceof AlertQuoteNode;
202
- }
203
- //#endregion
204
- //#region src/nodes/FootnoteNode.ts
205
- var FootnoteNode = class FootnoteNode extends DecoratorNode {
206
- static getType() {
207
- return "footnote";
208
- }
209
- static clone(node) {
210
- return new FootnoteNode(node.__identifier, node.__key);
211
- }
212
- constructor(identifier, key) {
213
- super(key);
214
- _defineProperty(this, "__identifier", void 0);
215
- this.__identifier = identifier;
216
- }
217
- createDOM(_config) {
218
- const sup = document.createElement("sup");
219
- sup.className = "rich-footnote";
220
- return sup;
221
- }
222
- updateDOM() {
223
- return false;
224
- }
225
- isInline() {
226
- return true;
227
- }
228
- static importJSON(serializedNode) {
229
- return $createFootnoteNode(serializedNode.identifier);
230
- }
231
- exportJSON() {
232
- return {
233
- ...super.exportJSON(),
234
- type: "footnote",
235
- identifier: this.__identifier,
236
- version: 1
237
- };
238
- }
239
- getIdentifier() {
240
- return this.getLatest().__identifier;
241
- }
242
- setIdentifier(identifier) {
243
- const writable = this.getWritable();
244
- writable.__identifier = identifier;
245
- }
246
- decorate(_editor, _config) {
247
- return createRendererDecoration("Footnote", FootnoteStaticRenderer, { identifier: this.__identifier });
248
- }
249
- };
250
- function $createFootnoteNode(identifier) {
251
- return new FootnoteNode(identifier);
252
- }
253
- //#endregion
254
- //#region src/components/renderers/ImageRenderer.tsx
255
- function ImageRenderer({ src, altText, width, height, caption, thumbhash, accent }) {
256
- const [loaded, setLoaded] = useState(false);
257
- const [zoomed, setZoomed] = useState(false);
258
- const handleLoad = useCallback(() => setLoaded(true), []);
259
- const handleZoomOpen = useCallback(() => {
260
- if (!loaded) return;
261
- setZoomed(true);
262
- }, [loaded]);
263
- const handleZoomClose = useCallback(() => setZoomed(false), []);
264
- useEffect(() => {
265
- if (!zoomed) return;
266
- const onKeyDown = (e) => {
267
- if (e.key === "Escape") setZoomed(false);
268
- };
269
- document.addEventListener("keydown", onKeyDown);
270
- return () => document.removeEventListener("keydown", onKeyDown);
271
- }, [zoomed]);
272
- useEffect(() => {
273
- if (!zoomed) return;
274
- const prev = document.body.style.overflow;
275
- document.body.style.overflow = "hidden";
276
- return () => {
277
- document.body.style.overflow = prev;
278
- };
279
- }, [zoomed]);
280
- const handleContainerKeyDown = useCallback((e) => {
281
- if ((e.key === "Enter" || e.key === " ") && loaded) {
282
- e.preventDefault();
283
- setZoomed(true);
284
- }
285
- }, [loaded]);
286
- const placeholderUrl = useMemo(() => thumbhash ? decodeThumbHash(thumbhash) : void 0, [thumbhash]);
287
- const aspectStyle = width && height ? {
288
- aspectRatio: `${width} / ${height}`,
289
- maxWidth: "100%",
290
- width
291
- } : { maxWidth: "100%" };
292
- return /* @__PURE__ */ jsxs("figure", {
293
- className: "rich-image",
294
- children: [
295
- /* @__PURE__ */ jsx("div", {
296
- "aria-label": loaded ? `Zoom image: ${altText}` : void 0,
297
- className: `rich-image-container${loaded ? " rich-image-loaded" : ""}`,
298
- role: "button",
299
- tabIndex: loaded ? 0 : -1,
300
- style: {
301
- ...aspectStyle,
302
- backgroundColor: !loaded && !placeholderUrl ? accent : void 0,
303
- backgroundImage: !loaded && placeholderUrl ? `url(${placeholderUrl})` : void 0,
304
- backgroundSize: "cover",
305
- cursor: loaded ? "zoom-in" : void 0
306
- },
307
- onClick: handleZoomOpen,
308
- onKeyDown: handleContainerKeyDown,
309
- children: /* @__PURE__ */ jsx("img", {
310
- alt: altText,
311
- className: loaded ? "rich-image-visible" : "rich-image-hidden",
312
- height,
313
- loading: "lazy",
314
- src,
315
- style: {
316
- maxWidth: "100%",
317
- height: "auto"
318
- },
319
- width,
320
- onLoad: handleLoad
321
- })
322
- }),
323
- caption && /* @__PURE__ */ jsx("figcaption", { children: caption }),
324
- zoomed && /* @__PURE__ */ jsx("div", {
325
- "aria-label": `Zoomed image: ${altText}`,
326
- "aria-modal": "true",
327
- className: "rich-image-zoom-overlay",
328
- role: "dialog",
329
- tabIndex: 0,
330
- onClick: handleZoomClose,
331
- children: /* @__PURE__ */ jsx("img", {
332
- alt: altText,
333
- className: "rich-image-zoom-img",
334
- src
335
- })
336
- })
337
- ]
338
- });
339
- }
340
- //#endregion
341
- //#region src/plugins/image-upload-command.ts
342
- var OPEN_IMAGE_UPLOAD_DIALOG_COMMAND = createCommand("OPEN_IMAGE_UPLOAD_DIALOG_COMMAND");
343
- //#endregion
344
- //#region src/nodes/ImageNode.ts
345
- function sanitizeImageSrc(src) {
346
- const trimmed = src.trim();
347
- if (/^(?:javascript\s*:|vbscript\s*:|data\s*:(?!image\/))/i.test(trimmed)) return "";
348
- return trimmed;
349
- }
350
- function sanitizeColor(value) {
351
- if (!value) return void 0;
352
- const trimmed = value.trim();
353
- if (/^#[\da-f]{3,8}$/i.test(trimmed)) return trimmed;
354
- if (/^(?:rgb|hsl)a?\([^)]+\)$/i.test(trimmed)) return trimmed;
355
- if (/^[a-z]{3,20}$/i.test(trimmed)) return trimmed;
356
- }
357
- var ImageNode = class ImageNode extends DecoratorNode {
358
- static getType() {
359
- return "image";
360
- }
361
- static clone(node) {
362
- return new ImageNode({
363
- src: node.__src,
364
- altText: node.__altText,
365
- width: node.__width,
366
- height: node.__height,
367
- caption: node.__caption,
368
- thumbhash: node.__thumbhash,
369
- accent: node.__accent
370
- }, node.__key);
371
- }
372
- constructor(payload, key) {
373
- super(key);
374
- _defineProperty(this, "__src", void 0);
375
- _defineProperty(this, "__altText", void 0);
376
- _defineProperty(this, "__width", void 0);
377
- _defineProperty(this, "__height", void 0);
378
- _defineProperty(this, "__caption", void 0);
379
- _defineProperty(this, "__thumbhash", void 0);
380
- _defineProperty(this, "__accent", void 0);
381
- this.__src = sanitizeImageSrc(payload.src);
382
- this.__altText = payload.altText;
383
- this.__width = payload.width;
384
- this.__height = payload.height;
385
- this.__caption = payload.caption;
386
- this.__thumbhash = payload.thumbhash;
387
- this.__accent = sanitizeColor(payload.accent);
388
- }
389
- createDOM(_config) {
390
- const div = document.createElement("div");
391
- div.className = "rich-image-wrapper";
392
- return div;
393
- }
394
- updateDOM() {
395
- return false;
396
- }
397
- isInline() {
398
- return false;
399
- }
400
- static importJSON(serializedNode) {
401
- return $createImageNode({
402
- src: serializedNode.src,
403
- altText: serializedNode.altText,
404
- width: serializedNode.width,
405
- height: serializedNode.height,
406
- caption: serializedNode.caption,
407
- thumbhash: serializedNode.thumbhash,
408
- accent: serializedNode.accent
409
- });
410
- }
411
- exportJSON() {
412
- return {
413
- ...super.exportJSON(),
414
- type: "image",
415
- src: this.__src,
416
- altText: this.__altText,
417
- width: this.__width,
418
- height: this.__height,
419
- caption: this.__caption,
420
- thumbhash: this.__thumbhash,
421
- accent: this.__accent,
422
- version: 1
423
- };
424
- }
425
- setSrc(src) {
426
- const writable = this.getWritable();
427
- writable.__src = sanitizeImageSrc(src);
428
- }
429
- setAltText(altText) {
430
- const writable = this.getWritable();
431
- writable.__altText = altText;
432
- }
433
- setCaption(caption) {
434
- const writable = this.getWritable();
435
- writable.__caption = caption;
436
- }
437
- setDimensions(width, height) {
438
- const writable = this.getWritable();
439
- writable.__width = width;
440
- writable.__height = height;
441
- }
442
- setThumbhash(thumbhash) {
443
- const writable = this.getWritable();
444
- writable.__thumbhash = thumbhash;
445
- }
446
- setAccent(accent) {
447
- const writable = this.getWritable();
448
- writable.__accent = sanitizeColor(accent);
449
- }
450
- getSrc() {
451
- return this.__src;
452
- }
453
- getAltText() {
454
- return this.__altText;
455
- }
456
- getCaption() {
457
- return this.__caption;
458
- }
459
- getWidth() {
460
- return this.__width;
461
- }
462
- getHeight() {
463
- return this.__height;
464
- }
465
- getThumbhash() {
466
- return this.__thumbhash;
467
- }
468
- getAccent() {
469
- return this.__accent;
470
- }
471
- decorate(_editor, _config) {
472
- return createRendererDecoration("Image", ImageRenderer, {
473
- src: this.__src,
474
- altText: this.__altText,
475
- width: this.__width,
476
- height: this.__height,
477
- caption: this.__caption,
478
- thumbhash: this.__thumbhash,
479
- accent: this.__accent
480
- });
481
- }
482
- };
483
- _defineProperty(ImageNode, "commandItems", [{
484
- title: "Image",
485
- icon: createElement(ImageIcon, { size: 20 }),
486
- description: "Upload or embed an image",
487
- keywords: [
488
- "image",
489
- "picture",
490
- "photo"
491
- ],
492
- section: "MEDIA",
493
- placement: ["slash", "toolbar"],
494
- group: "insert",
495
- onSelect: (editor) => {
496
- if (editor.dispatchCommand(OPEN_IMAGE_UPLOAD_DIALOG_COMMAND, void 0)) return;
497
- editor.update(() => {
498
- $insertNodes([$createImageNode({
499
- src: "",
500
- altText: ""
501
- })]);
502
- });
503
- }
504
- }]);
505
- function $createImageNode(payload) {
506
- return new ImageNode(payload);
507
- }
508
- function $isImageNode(node) {
509
- return node instanceof ImageNode;
510
- }
511
- //#endregion
512
- //#region src/nodes/KaTeXBlockNode.ts
513
- var KaTeXBlockNode = class KaTeXBlockNode extends DecoratorNode {
514
- static getType() {
515
- return "katex-block";
516
- }
517
- static clone(node) {
518
- return new KaTeXBlockNode(node.__equation, node.__key);
519
- }
520
- constructor(equation, key) {
521
- super(key);
522
- _defineProperty(this, "__equation", void 0);
523
- this.__equation = equation;
524
- }
525
- createDOM(_config) {
526
- const div = document.createElement("div");
527
- div.className = "rich-katex-block-wrapper";
528
- return div;
529
- }
530
- updateDOM() {
531
- return false;
532
- }
533
- isInline() {
534
- return false;
535
- }
536
- static importJSON(serializedNode) {
537
- return $createKaTeXBlockNode(serializedNode.equation);
538
- }
539
- exportJSON() {
540
- return {
541
- ...super.exportJSON(),
542
- type: "katex-block",
543
- equation: this.__equation,
544
- version: 1
545
- };
546
- }
547
- getEquation() {
548
- return this.__equation;
549
- }
550
- setEquation(equation) {
551
- const writable = this.getWritable();
552
- writable.__equation = equation;
553
- }
554
- decorate(_editor, _config) {
555
- return createRendererDecoration("KaTeX", KaTeXRenderer, {
556
- equation: this.__equation,
557
- displayMode: true
558
- });
559
- }
560
- };
561
- _defineProperty(KaTeXBlockNode, "slashMenuItems", [{
562
- title: "Math Equation",
563
- icon: createElement(Sigma, { size: 20 }),
564
- description: "KaTeX block formula",
565
- keywords: [
566
- "math",
567
- "equation",
568
- "latex",
569
- "katex"
570
- ],
571
- section: "ADVANCED",
572
- onSelect: (editor) => {
573
- editor.update(() => {
574
- $insertNodes([$createKaTeXBlockNode("")]);
575
- });
576
- }
577
- }]);
578
- function $createKaTeXBlockNode(equation) {
579
- return new KaTeXBlockNode(equation);
580
- }
581
- function $isKaTeXBlockNode(node) {
582
- return node instanceof KaTeXBlockNode;
583
- }
584
- //#endregion
585
- //#region src/nodes/KaTeXInlineNode.ts
586
- var KaTeXInlineNode = class KaTeXInlineNode extends DecoratorNode {
587
- static getType() {
588
- return "katex-inline";
589
- }
590
- static clone(node) {
591
- return new KaTeXInlineNode(node.__equation, node.__key);
592
- }
593
- constructor(equation, key) {
594
- super(key);
595
- _defineProperty(this, "__equation", void 0);
596
- this.__equation = equation;
597
- }
598
- createDOM(_config) {
599
- return document.createElement("span");
600
- }
601
- updateDOM() {
602
- return false;
603
- }
604
- isInline() {
605
- return true;
606
- }
607
- static importJSON(serializedNode) {
608
- return $createKaTeXInlineNode(serializedNode.equation);
609
- }
610
- exportJSON() {
611
- return {
612
- ...super.exportJSON(),
613
- type: "katex-inline",
614
- equation: this.__equation,
615
- version: 1
616
- };
617
- }
618
- getEquation() {
619
- return this.__equation;
620
- }
621
- setEquation(equation) {
622
- const writable = this.getWritable();
623
- writable.__equation = equation;
624
- }
625
- decorate(_editor, _config) {
626
- return createRendererDecoration("KaTeX", KaTeXRenderer, {
627
- equation: this.__equation,
628
- displayMode: false
629
- });
630
- }
631
- };
632
- function $createKaTeXInlineNode(equation) {
633
- return new KaTeXInlineNode(equation);
634
- }
635
- function $isKaTeXInlineNode(node) {
636
- return node instanceof KaTeXInlineNode;
637
- }
638
- //#endregion
639
- //#region src/components/renderers/MentionRenderer.tsx
640
- function MentionRenderer({ handle, displayName }) {
641
- const normalizedHandle = handle.replace(/^@+/, "");
642
- return /* @__PURE__ */ jsx("span", {
643
- className: "rich-mention rich-mention-plain",
644
- children: /* @__PURE__ */ jsxs("span", {
645
- className: "rich-mention-handle",
646
- children: ["@", displayName || normalizedHandle]
647
- })
648
- });
649
- }
650
- //#endregion
651
- //#region src/nodes/MentionNode.ts
652
- var MentionNode = class MentionNode extends DecoratorNode {
653
- static getType() {
654
- return "mention";
655
- }
656
- static clone(node) {
657
- return new MentionNode(node.__platform, node.__handle, node.__displayName, node.__key);
658
- }
659
- constructor(platform, handle, displayName, key) {
660
- super(key);
661
- _defineProperty(this, "__platform", void 0);
662
- _defineProperty(this, "__handle", void 0);
663
- _defineProperty(this, "__displayName", void 0);
664
- this.__platform = platform;
665
- this.__handle = handle;
666
- this.__displayName = displayName;
667
- }
668
- createDOM(_config) {
669
- const el = document.createElement("span");
670
- el.style.display = "inline-flex";
671
- el.style.alignItems = "center";
672
- el.style.height = "1lh";
673
- return el;
674
- }
675
- updateDOM() {
676
- return false;
677
- }
678
- isInline() {
679
- return true;
680
- }
681
- getPlatform() {
682
- return this.getLatest().__platform;
683
- }
684
- getHandle() {
685
- return this.getLatest().__handle;
686
- }
687
- getDisplayName() {
688
- return this.getLatest().__displayName;
689
- }
690
- static importJSON(serializedNode) {
691
- return $createMentionNode(serializedNode.platform, serializedNode.handle, serializedNode.displayName);
692
- }
693
- exportJSON() {
694
- return {
695
- ...super.exportJSON(),
696
- type: "mention",
697
- platform: this.__platform,
698
- handle: this.__handle,
699
- ...this.__displayName ? { displayName: this.__displayName } : {},
700
- version: 1
701
- };
702
- }
703
- decorate(_editor, _config) {
704
- return createRendererDecoration("Mention", MentionRenderer, {
705
- platform: this.__platform,
706
- handle: this.__handle,
707
- displayName: this.__displayName
708
- });
709
- }
710
- };
711
- _defineProperty(MentionNode, "slashMenuItems", [{
712
- title: "Mention",
713
- icon: createElement("span", { style: {
714
- fontSize: 16,
715
- fontWeight: 700
716
- } }, "@"),
717
- description: "Mention a social account",
718
- keywords: [
719
- "mention",
720
- "at",
721
- "@",
722
- "github",
723
- "twitter"
724
- ],
725
- section: "INLINE",
726
- onSelect: (editor) => {
727
- editor.update(() => {
728
- const selection = $getSelection();
729
- if ($isRangeSelection(selection)) selection.insertText("@");
730
- });
731
- }
732
- }]);
733
- function $createMentionNode(platform, handle, displayName) {
734
- return new MentionNode(platform, handle, displayName);
735
- }
736
- function $isMentionNode(node) {
737
- return node instanceof MentionNode;
738
- }
739
- //#endregion
740
- //#region src/components/renderers/MermaidRenderer.tsx
741
- function MermaidRenderer({ content }) {
742
- return /* @__PURE__ */ jsx("div", {
743
- className: "rich-mermaid-block",
744
- children: /* @__PURE__ */ jsx("pre", { children: /* @__PURE__ */ jsx("code", { children: content }) })
745
- });
746
- }
747
- //#endregion
748
- //#region src/nodes/MermaidNode.ts
749
- var MermaidNode = class MermaidNode extends DecoratorNode {
750
- static getType() {
751
- return "mermaid";
752
- }
753
- static clone(node) {
754
- return new MermaidNode(node.__diagram, node.__key);
755
- }
756
- constructor(diagram, key) {
757
- super(key);
758
- _defineProperty(this, "__diagram", void 0);
759
- this.__diagram = diagram;
760
- }
761
- createDOM(_config) {
762
- const div = document.createElement("div");
763
- div.className = "rich-mermaid-wrapper";
764
- return div;
765
- }
766
- updateDOM() {
767
- return false;
768
- }
769
- isInline() {
770
- return false;
771
- }
772
- static importJSON(serializedNode) {
773
- return $createMermaidNode(serializedNode.diagram);
774
- }
775
- exportJSON() {
776
- return {
777
- ...super.exportJSON(),
778
- type: "mermaid",
779
- diagram: this.__diagram,
780
- version: 1
781
- };
782
- }
783
- getDiagram() {
784
- return this.__diagram;
785
- }
786
- setDiagram(diagram) {
787
- const writable = this.getWritable();
788
- writable.__diagram = diagram;
789
- }
790
- decorate(editor, _config) {
791
- const nodeKey = this.__key;
792
- return createRendererDecoration("Mermaid", MermaidRenderer, {
793
- content: this.__diagram,
794
- onContentChange: (newDiagram) => {
795
- editor.update(() => {
796
- const node = $getNodeByKey(nodeKey);
797
- if (node) node.setDiagram(newDiagram);
798
- });
799
- }
800
- });
801
- }
802
- };
803
- _defineProperty(MermaidNode, "commandItems", [{
804
- title: "Mermaid Diagram",
805
- icon: createElement(Workflow, { size: 20 }),
806
- description: "Flowchart, sequence diagram",
807
- keywords: [
808
- "mermaid",
809
- "diagram",
810
- "chart",
811
- "flowchart"
812
- ],
813
- section: "MEDIA",
814
- placement: ["slash", "toolbar"],
815
- group: "insert",
816
- onSelect: (editor) => {
817
- editor.update(() => {
818
- $insertNodes([$createMermaidNode("graph TD\n A[Start] --> B[End]")]);
819
- });
820
- }
821
- }]);
822
- function $createMermaidNode(diagram) {
823
- return new MermaidNode(diagram);
824
- }
825
- function $isMermaidNode(node) {
826
- return node instanceof MermaidNode;
827
- }
828
- //#endregion
829
- //#region src/nodes/SpoilerNode.ts
830
- var SpoilerNode = class SpoilerNode extends ElementNode {
831
- static getType() {
832
- return "spoiler";
833
- }
834
- static clone(node) {
835
- return new SpoilerNode(node.__key);
836
- }
837
- constructor(key) {
838
- super(key);
839
- }
840
- createDOM(_config) {
841
- const span = document.createElement("span");
842
- span.className = "rich-spoiler";
843
- span.setAttribute("role", "button");
844
- span.setAttribute("tabindex", "0");
845
- span.setAttribute("aria-label", "Spoiler (click to reveal)");
846
- const toggle = () => {
847
- if (span.isContentEditable) return;
848
- const revealed = span.classList.toggle("rich-spoiler-revealed");
849
- span.setAttribute("aria-label", revealed ? "Spoiler (revealed)" : "Spoiler (click to reveal)");
850
- };
851
- span.addEventListener("click", toggle);
852
- span.addEventListener("keydown", (e) => {
853
- if (e.key === "Enter" || e.key === " ") {
854
- e.preventDefault();
855
- toggle();
856
- }
857
- });
858
- return span;
859
- }
860
- updateDOM() {
861
- return false;
862
- }
863
- static importJSON(_serializedNode) {
864
- return $createSpoilerNode();
865
- }
866
- exportJSON() {
867
- return {
868
- ...super.exportJSON(),
869
- type: "spoiler",
870
- version: 1
871
- };
872
- }
873
- canInsertTextBefore() {
874
- return true;
875
- }
876
- canInsertTextAfter() {
877
- return true;
878
- }
879
- isInline() {
880
- return true;
881
- }
882
- };
883
- function $createSpoilerNode() {
884
- return new SpoilerNode();
885
- }
886
- //#endregion
887
- //#region src/utils/tag-color.ts
888
- function stringToHue(str) {
889
- let hash = 0;
890
- for (let i = 0; i < str.length; i++) hash = str.charCodeAt(i) + ((hash << 5) - hash);
891
- const hue = hash % 360;
892
- return hue < 0 ? hue + 360 : hue;
893
- }
894
- function getTagBgColor(text) {
895
- const hue = stringToHue(text);
896
- const sat = 70 + hue % 21;
897
- const light = 40 + hue % 31;
898
- return `hsla(${hue}, ${sat > 30 ? sat - 30 : 0}%, ${light < 80 ? light + 20 : 100}%, 0.7)`;
899
- }
900
- //#endregion
901
- //#region src/nodes/TagNode.ts
902
- var TagNode = class TagNode extends TextNode {
903
- static getType() {
904
- return "tag";
905
- }
906
- static clone(node) {
907
- return new TagNode(node.__text, node.__key);
908
- }
909
- static importDOM() {
910
- return { span: () => ({
911
- conversion: (domNode) => {
912
- if (!(domNode instanceof HTMLElement)) return null;
913
- if (!domNode.classList.contains("rich-tag")) return null;
914
- return { node: $createTagNode(domNode.textContent ?? "") };
915
- },
916
- priority: 2
917
- }) };
918
- }
919
- constructor(text, key) {
920
- super(text, key);
921
- }
922
- createDOM(config) {
923
- const element = super.createDOM(config);
924
- element.classList.add("rich-tag");
925
- element.style.backgroundColor = getTagBgColor(this.getTextContent());
926
- return element;
927
- }
928
- updateDOM(prevNode, dom, config) {
929
- const updated = super.updateDOM(prevNode, dom, config);
930
- dom.classList.add("rich-tag");
931
- if (prevNode.__text !== this.__text) dom.style.backgroundColor = getTagBgColor(this.__text);
932
- return updated;
933
- }
934
- exportDOM(_editor) {
935
- const element = document.createElement("span");
936
- element.className = "rich-tag";
937
- element.style.backgroundColor = getTagBgColor(this.getTextContent());
938
- element.textContent = this.getTextContent();
939
- return { element };
940
- }
941
- getText() {
942
- return this.getTextContent();
943
- }
944
- canInsertTextBefore() {
945
- return false;
946
- }
947
- canInsertTextAfter() {
948
- return false;
949
- }
950
- isTextEntity() {
951
- return true;
952
- }
953
- static importJSON(serializedNode) {
954
- const node = $createTagNode(serializedNode.text ?? "");
955
- node.setFormat(serializedNode.format ?? 0);
956
- node.setDetail(serializedNode.detail ?? 0);
957
- node.setMode(serializedNode.mode ?? "normal");
958
- node.setStyle(serializedNode.style ?? "");
959
- return node;
960
- }
961
- exportJSON() {
962
- return {
963
- ...super.exportJSON(),
964
- type: "tag",
965
- version: 1
966
- };
967
- }
968
- };
969
- _defineProperty(TagNode, "commandItems", [{
970
- title: "Tag",
971
- icon: createElement(Tag, { size: 20 }),
972
- description: "Insert a tag",
973
- keywords: [
974
- "tag",
975
- "label",
976
- "badge"
977
- ],
978
- section: "INLINE",
979
- placement: ["slash", "toolbar"],
980
- group: "insert",
981
- onSelect: (editor, queryString) => {
982
- editor.update(() => {
983
- $insertNodes([$createTagNode(queryString || "tag")]);
984
- });
985
- }
986
- }]);
987
- function $createTagNode(text) {
988
- return new TagNode(text);
989
- }
990
- function $isTagNode(node) {
991
- return node instanceof TagNode;
992
- }
993
- //#endregion
994
- //#region src/styles/theme.ts
995
- var editorTheme = {
996
- text: {
997
- bold: "rich-text-bold",
998
- italic: "rich-text-italic",
999
- underline: "rich-text-underline",
1000
- strikethrough: "rich-text-strikethrough",
1001
- superscript: "rich-text-superscript",
1002
- subscript: "rich-text-subscript",
1003
- code: "rich-text-code",
1004
- highlight: "rich-text-highlight"
1005
- },
1006
- heading: {
1007
- h1: "rich-heading-h1",
1008
- h2: "rich-heading-h2",
1009
- h3: "rich-heading-h3",
1010
- h4: "rich-heading-h4",
1011
- h5: "rich-heading-h5",
1012
- h6: "rich-heading-h6"
1013
- },
1014
- list: {
1015
- ol: "rich-list-ol",
1016
- ul: "rich-list-ul",
1017
- listitem: "rich-list-item",
1018
- listitemChecked: "rich-list-item-checked",
1019
- listitemUnchecked: "rich-list-item-unchecked",
1020
- checklist: "rich-checklist",
1021
- nested: { listitem: "rich-list-nested-item" }
1022
- },
1023
- quote: "rich-quote",
1024
- link: "rich-link",
1025
- paragraph: "rich-paragraph",
1026
- code: "rich-code-block",
1027
- table: "rich-table",
1028
- tableCell: "rich-table-cell",
1029
- tableCellHeader: "rich-table-cell-header",
1030
- tableScrollableWrapper: "rich-table-scrollable-wrapper",
1031
- hr: "rich-hr"
1032
- };
1033
- //#endregion
1034
- export { _defineProperty as A, OPEN_IMAGE_UPLOAD_DIALOG_COMMAND as C, ALERT_LABELS as D, $isAlertQuoteNode as E, useOptionalNestedContentRenderer as F, AlertRenderer as M, NestedContentRendererProvider as N, ALERT_TYPES as O, useNestedContentRenderer as P, ImageNode as S, FootnoteNode as T, $createKaTeXBlockNode as _, getTagBgColor as a, $createImageNode as b, $createMermaidNode as c, $createMentionNode as d, $isMentionNode as f, KaTeXInlineNode as g, $isKaTeXInlineNode as h, TagNode as i, extractTextContent as j, AlertQuoteNode as k, $isMermaidNode as l, $createKaTeXInlineNode as m, $createTagNode as n, $createSpoilerNode as o, MentionNode as p, $isTagNode as r, SpoilerNode as s, editorTheme as t, MermaidNode as u, $isKaTeXBlockNode as v, $createFootnoteNode as w, $isImageNode as x, KaTeXBlockNode as y };