@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 +1 @@
1
- {"version":3,"file":"config-edit.d.ts","sourceRoot":"","sources":["../src/config-edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAqBjD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAkBrD,CAAA;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAGlD,CAAA"}
1
+ {"version":3,"file":"config-edit.d.ts","sourceRoot":"","sources":["../src/config-edit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAsBlD,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAmBrD,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAyC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAoBjD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAYlD,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAkBjD,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAG9C,CAAA"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAqBlD,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAYlD,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAmBjD,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,CAAqC,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import { SerializedEditorState } from 'lexical';
2
2
  import { ReactNode } from 'react';
3
- export type RenderEditorStateFn = (state: SerializedEditorState) => ReactNode;
3
+ import { RichEditorVariant } from '../types';
4
+ export type RenderEditorStateFn = (state: SerializedEditorState, variant?: RichEditorVariant) => ReactNode;
4
5
  export declare const NestedContentRendererProvider: import('react').Provider<RenderEditorStateFn | null>;
5
6
  export declare function useOptionalNestedContentRenderer(): RenderEditorStateFn | null;
6
7
  export declare function useNestedContentRenderer(): RenderEditorStateFn;
@@ -1 +1 @@
1
- {"version":3,"file":"NestedContentRendererContext.d.ts","sourceRoot":"","sources":["../../src/context/NestedContentRendererContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGtC,MAAM,MAAM,mBAAmB,GAAG,CAAC,KAAK,EAAE,qBAAqB,KAAK,SAAS,CAAA;AAM7E,eAAO,MAAM,6BAA6B,sDACH,CAAA;AAEvC,wBAAgB,gCAAgC,IAAI,mBAAmB,GAAG,IAAI,CAE7E;AAED,wBAAgB,wBAAwB,IAAI,mBAAmB,CAQ9D"}
1
+ {"version":3,"file":"NestedContentRendererContext.d.ts","sourceRoot":"","sources":["../../src/context/NestedContentRendererContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAElD,MAAM,MAAM,mBAAmB,GAAG,CAChC,KAAK,EAAE,qBAAqB,EAC5B,OAAO,CAAC,EAAE,iBAAiB,KACxB,SAAS,CAAC;AAIf,eAAO,MAAM,6BAA6B,sDAAwC,CAAC;AAEnF,wBAAgB,gCAAgC,IAAI,mBAAmB,GAAG,IAAI,CAE7E;AAED,wBAAgB,wBAAwB,IAAI,mBAAmB,CAM9D"}
@@ -0,0 +1,43 @@
1
+ const FAVICON_VARIANTS = [
2
+ "/favicon.ico",
3
+ "/favicon.png",
4
+ "/favicon.svg",
5
+ "/apple-touch-icon.png",
6
+ "/apple-touch-icon-precomposed.png"
7
+ ];
8
+ const faviconCache = /* @__PURE__ */ new Map();
9
+ function getHostname(href) {
10
+ try {
11
+ const url = new URL(href);
12
+ if (url.protocol !== "http:" && url.protocol !== "https:") return null;
13
+ return url.hostname;
14
+ } catch {
15
+ return null;
16
+ }
17
+ }
18
+ function probeImage(url) {
19
+ return new Promise((resolve) => {
20
+ const img = new Image();
21
+ img.onload = () => resolve(url);
22
+ img.onerror = () => resolve(null);
23
+ img.src = url;
24
+ });
25
+ }
26
+ async function probeFavicon(hostname) {
27
+ const cached = faviconCache.get(hostname);
28
+ if (cached !== void 0) return cached;
29
+ for (const variant of FAVICON_VARIANTS) {
30
+ const url = `https://${hostname}${variant}`;
31
+ const result = await probeImage(url);
32
+ if (result) {
33
+ faviconCache.set(hostname, result);
34
+ return result;
35
+ }
36
+ }
37
+ faviconCache.set(hostname, null);
38
+ return null;
39
+ }
40
+ export {
41
+ getHostname as g,
42
+ probeFavicon as p
43
+ };
package/dist/index.mjs CHANGED
@@ -1,285 +1,309 @@
1
- import { a as AutoFocusPlugin, c as defaultImageUpload, d as ImageUploadProvider, i as EditorRefPlugin, l as BlockIdPlugin, n as OnChangePlugin, o as LinkFaviconPlugin, p as CorePlugins, r as FootnotePlugin, s as ImageUploadPlugin, t as SubmitShortcutPlugin, u as blockIdState } from "./SubmitShortcutPlugin-6IvsbZD-.js";
2
- import { n as setResolvedEditNodes, r as allEditNodes } from "./node-registry-CeVi2y9f.js";
3
- import { F as useOptionalNestedContentRenderer, N as NestedContentRendererProvider, P as useNestedContentRenderer, t as editorTheme } from "./theme-DHOUKKSr.js";
4
- import { a as FootnoteDefinitionsProvider, c as useFootnoteDisplayNumber, d as RendererConfigProvider, f as useRendererConfig, m as useVariant, o as useFootnoteContent, p as useRendererMode, s as useFootnoteDefinitions } from "./KaTeXRenderer-BsyRH5_t.js";
5
- import { C as useColorScheme, S as ColorSchemeProvider } from "./config-tfg1FWhG.js";
6
- import "./LinkCardRenderer-OEMBDUhD.js";
7
- import "./AlertQuoteEditNode-BDoonB4u.js";
8
- import { n as usePresentDialog, r as LinkFavicon, t as PresentDialogProvider } from "./PresentDialogContext-DQw6MrNh.js";
9
- import { a as KaTeXPlugin, c as AlertPlugin, n as MermaidPlugin, s as ImagePlugin } from "./MermaidPlugin-Df2Cm2yX.js";
10
- /* empty css */
11
- import { a as commentVariant, i as noteVariant, n as clsx, o as articleVariant, r as getVariantClass, t as richContent } from "./shared.css-wgGgtK_e.js";
12
- import { $getRoot, $getSelection, $getState, $isElementNode, $isLineBreakNode, $isRangeSelection, $isTextNode } from "lexical";
1
+ import { F as FootnotePlugin, O as OnChangePlugin, S as SubmitShortcutPlugin, E as EditorRefPlugin, a as AutoFocusPlugin, d as ImageUploadProvider, g as defaultImageUpload, C as CorePlugins, I as ImageUploadPlugin, L as LinkFaviconPlugin, c as BlockIdPlugin, f as blockIdState } from "./SubmitShortcutPlugin-o2y6b-8f.js";
2
+ import { L, P, u } from "./PresentDialogContext-D5dHWtzD.js";
13
3
  import { jsx, jsxs } from "react/jsx-runtime";
14
- import { ContentEditable } from "@lexical/react/LexicalContentEditable";
15
- import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
16
- import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
4
+ import { s as setResolvedEditNodes, a as allEditNodes } from "./node-registry-Dzp7X3R4.js";
5
+ import { I as ImagePlugin, K as KaTeXPlugin, A as AlertPlugin, M as MermaidPlugin } from "./MermaidPlugin-BEtIhQHn.js";
17
6
  import { PortalThemeProvider } from "@haklex/rich-style-token";
18
7
  import { LexicalComposer } from "@lexical/react/LexicalComposer";
8
+ import { LexicalErrorBoundary } from "@lexical/react/LexicalErrorBoundary";
19
9
  import { HistoryPlugin } from "@lexical/react/LexicalHistoryPlugin";
10
+ import { RichTextPlugin } from "@lexical/react/LexicalRichTextPlugin";
11
+ import { n as ColorSchemeProvider } from "./config-BP_kyJbW.js";
12
+ import { u as u2 } from "./config-BP_kyJbW.js";
13
+ import { R as RendererConfigProvider } from "./KaTeXRenderer-BFryJSIS.js";
14
+ import { F, u as u3, b, d, e, f, g } from "./KaTeXRenderer-BFryJSIS.js";
15
+ import { n as editorTheme } from "./theme-Cg8JUW_j.js";
16
+ import { N, u as u4, p } from "./theme-Cg8JUW_j.js";
17
+ import { ContentEditable as ContentEditable$1 } from "@lexical/react/LexicalContentEditable";
18
+ import { d as clsx, g as getVariantClass } from "./utils-gy2c_HWc.js";
19
+ import { a, c, n, r } from "./utils-gy2c_HWc.js";
20
20
  import { articleTheme, commentTheme, noteTheme, vars } from "@haklex/rich-style-token/styles";
21
- //#region src/components/ContentEditable.css.ts
21
+ import { $getRoot, $getSelection, $isRangeSelection, $getState, $isElementNode, $isTextNode, $isLineBreakNode } from "lexical";
22
22
  var contentWrapper = "b94s950";
23
23
  var content = "b94s951";
24
24
  var placeholder = "b94s952";
25
- //#endregion
26
- //#region src/components/ContentEditable.tsx
27
- function ContentEditable$1({ className, placeholder: placeholder$1, hasHeader }) {
28
- const paddingTop = hasHeader ? 40 : 12;
29
- return /* @__PURE__ */ jsx("div", {
30
- className: clsx("rich-editor__content-wrapper", contentWrapper),
31
- style: { "--ce-padding-top": `${paddingTop}px` },
32
- children: /* @__PURE__ */ jsx(ContentEditable, {
33
- "aria-placeholder": placeholder$1 ?? "",
34
- className: clsx("rich-editor__content", content, className),
35
- placeholder: /* @__PURE__ */ jsx("div", {
36
- className: clsx("rich-editor__placeholder", placeholder),
37
- style: { display: placeholder$1 ? void 0 : "none" },
38
- children: placeholder$1
39
- })
40
- })
41
- });
25
+ function ContentEditable({ className, placeholder: placeholder$1, hasHeader }) {
26
+ const paddingTop = hasHeader ? 40 : 12;
27
+ return /* @__PURE__ */ jsx(
28
+ "div",
29
+ {
30
+ className: clsx("rich-editor__content-wrapper", contentWrapper),
31
+ style: { "--ce-padding-top": `${paddingTop}px` },
32
+ children: /* @__PURE__ */ jsx(
33
+ ContentEditable$1,
34
+ {
35
+ "aria-placeholder": placeholder$1 ?? "",
36
+ className: clsx("rich-editor__content", content, className),
37
+ placeholder: /* @__PURE__ */ jsx(
38
+ "div",
39
+ {
40
+ className: clsx("rich-editor__placeholder", placeholder),
41
+ style: { display: placeholder$1 ? void 0 : "none" },
42
+ children: placeholder$1
43
+ }
44
+ )
45
+ }
46
+ )
47
+ }
48
+ );
42
49
  }
43
- //#endregion
44
- //#region src/components/RichEditorShell.tsx
45
- function RichEditorShell({ nodes, initialValue, onChange, variant = "article", theme = "light", placeholder = "Write something...", onSubmit, autoFocus = false, className, contentClassName, style, actions, header, onEditorReady, rendererConfig, debounceMs, children }) {
46
- setResolvedEditNodes(nodes);
47
- const initialConfig = {
48
- namespace: "RichEditor",
49
- theme: editorTheme,
50
- nodes,
51
- editable: true,
52
- onError: (error) => {
53
- console.error("[RichEditor]", error);
54
- },
55
- ...initialValue ? { editorState: JSON.stringify(initialValue) } : {}
56
- };
57
- const variantClass = getVariantClass(variant);
58
- return /* @__PURE__ */ jsx(PortalThemeProvider, {
59
- className: variantClass,
60
- theme,
61
- children: /* @__PURE__ */ jsx(ColorSchemeProvider, {
62
- colorScheme: theme,
63
- children: /* @__PURE__ */ jsx(RendererConfigProvider, {
64
- config: rendererConfig,
65
- mode: "editor",
66
- variant,
67
- children: /* @__PURE__ */ jsx(LexicalComposer, {
68
- initialConfig,
69
- children: /* @__PURE__ */ jsx(FootnotePlugin, { children: /* @__PURE__ */ jsxs("div", {
70
- suppressHydrationWarning: true,
71
- className: clsx("rich-editor", variantClass, className),
72
- "data-theme": theme,
73
- style: {
74
- ...style,
75
- maxWidth: "none"
76
- },
77
- children: [
78
- header,
79
- /* @__PURE__ */ jsx(RichTextPlugin, {
80
- ErrorBoundary: LexicalErrorBoundary,
81
- contentEditable: /* @__PURE__ */ jsx(ContentEditable$1, {
82
- className: contentClassName,
83
- hasHeader: !!header,
84
- placeholder
85
- })
86
- }),
87
- /* @__PURE__ */ jsx(HistoryPlugin, {}),
88
- /* @__PURE__ */ jsx(OnChangePlugin, {
89
- debounceMs,
90
- onChange
91
- }),
92
- /* @__PURE__ */ jsx(SubmitShortcutPlugin, { onSubmit }),
93
- /* @__PURE__ */ jsx(EditorRefPlugin, { onEditorReady }),
94
- autoFocus && /* @__PURE__ */ jsx(AutoFocusPlugin, {}),
95
- children,
96
- actions && /* @__PURE__ */ jsx("div", {
97
- className: "rich-editor__actions",
98
- children: actions
99
- })
100
- ]
101
- }) })
102
- })
103
- })
104
- })
105
- });
50
+ function RichEditorShell({
51
+ nodes,
52
+ initialValue,
53
+ onChange,
54
+ variant = "article",
55
+ theme = "light",
56
+ placeholder: placeholder2 = "Write something...",
57
+ onSubmit,
58
+ autoFocus = false,
59
+ className,
60
+ contentClassName,
61
+ style,
62
+ actions,
63
+ header,
64
+ onEditorReady,
65
+ rendererConfig,
66
+ debounceMs,
67
+ children
68
+ }) {
69
+ setResolvedEditNodes(nodes);
70
+ const initialConfig = {
71
+ namespace: "RichEditor",
72
+ theme: editorTheme,
73
+ nodes,
74
+ editable: true,
75
+ onError: (error) => {
76
+ console.error("[RichEditor]", error);
77
+ },
78
+ ...initialValue ? { editorState: JSON.stringify(initialValue) } : {}
79
+ };
80
+ const variantClass = getVariantClass(variant);
81
+ return /* @__PURE__ */ jsx(PortalThemeProvider, { className: variantClass, theme, children: /* @__PURE__ */ jsx(ColorSchemeProvider, { colorScheme: theme, children: /* @__PURE__ */ jsx(RendererConfigProvider, { config: rendererConfig, mode: "editor", variant, children: /* @__PURE__ */ jsx(LexicalComposer, { initialConfig, children: /* @__PURE__ */ jsx(FootnotePlugin, { children: /* @__PURE__ */ jsxs(
82
+ "div",
83
+ {
84
+ suppressHydrationWarning: true,
85
+ className: clsx("rich-editor", variantClass, className),
86
+ "data-theme": theme,
87
+ style: { ...style, maxWidth: "none" },
88
+ children: [
89
+ header,
90
+ /* @__PURE__ */ jsx(
91
+ RichTextPlugin,
92
+ {
93
+ ErrorBoundary: LexicalErrorBoundary,
94
+ contentEditable: /* @__PURE__ */ jsx(
95
+ ContentEditable,
96
+ {
97
+ className: contentClassName,
98
+ hasHeader: !!header,
99
+ placeholder: placeholder2
100
+ }
101
+ )
102
+ }
103
+ ),
104
+ /* @__PURE__ */ jsx(HistoryPlugin, {}),
105
+ /* @__PURE__ */ jsx(OnChangePlugin, { debounceMs, onChange }),
106
+ /* @__PURE__ */ jsx(SubmitShortcutPlugin, { onSubmit }),
107
+ /* @__PURE__ */ jsx(EditorRefPlugin, { onEditorReady }),
108
+ autoFocus && /* @__PURE__ */ jsx(AutoFocusPlugin, {}),
109
+ children,
110
+ actions && /* @__PURE__ */ jsx("div", { className: "rich-editor__actions", children: actions })
111
+ ]
112
+ }
113
+ ) }) }) }) }) });
106
114
  }
107
- //#endregion
108
- //#region src/components/RichEditor.tsx
109
115
  function RichEditor({ extraNodes, imageUpload, children, ...shellProps }) {
110
- const nodes = extraNodes ? [...allEditNodes, ...extraNodes] : allEditNodes;
111
- const resolvedImageUpload = imageUpload ?? defaultImageUpload;
112
- return /* @__PURE__ */ jsx(ImageUploadProvider, {
113
- upload: resolvedImageUpload,
114
- children: /* @__PURE__ */ jsxs(RichEditorShell, {
115
- nodes,
116
- ...shellProps,
117
- children: [
118
- /* @__PURE__ */ jsx(CorePlugins, {}),
119
- /* @__PURE__ */ jsx(ImagePlugin, {}),
120
- /* @__PURE__ */ jsx(ImageUploadPlugin, { onUpload: resolvedImageUpload }),
121
- /* @__PURE__ */ jsx(KaTeXPlugin, {}),
122
- /* @__PURE__ */ jsx(AlertPlugin, {}),
123
- /* @__PURE__ */ jsx(MermaidPlugin, {}),
124
- /* @__PURE__ */ jsx(LinkFaviconPlugin, {}),
125
- /* @__PURE__ */ jsx(BlockIdPlugin, {}),
126
- children
127
- ]
128
- })
129
- });
116
+ const nodes = extraNodes ? [...allEditNodes, ...extraNodes] : allEditNodes;
117
+ const resolvedImageUpload = imageUpload ?? defaultImageUpload;
118
+ return /* @__PURE__ */ jsx(ImageUploadProvider, { upload: resolvedImageUpload, children: /* @__PURE__ */ jsxs(RichEditorShell, { nodes, ...shellProps, children: [
119
+ /* @__PURE__ */ jsx(CorePlugins, {}),
120
+ /* @__PURE__ */ jsx(ImagePlugin, {}),
121
+ /* @__PURE__ */ jsx(ImageUploadPlugin, { onUpload: resolvedImageUpload }),
122
+ /* @__PURE__ */ jsx(KaTeXPlugin, {}),
123
+ /* @__PURE__ */ jsx(AlertPlugin, {}),
124
+ /* @__PURE__ */ jsx(MermaidPlugin, {}),
125
+ /* @__PURE__ */ jsx(LinkFaviconPlugin, {}),
126
+ /* @__PURE__ */ jsx(BlockIdPlugin, {}),
127
+ children
128
+ ] }) });
130
129
  }
131
- //#endregion
132
- //#region src/utils/comment-anchor.ts
133
130
  function computeBlockFingerprint(block) {
134
- const text = block.getTextContent();
135
- const input = text.slice(0, 200) + String(text.length);
136
- let hash = 5381;
137
- for (let i = 0; i < input.length; i++) hash = (hash << 5) + hash + (input.codePointAt(i) ?? 0) | 0;
138
- return (hash >>> 0).toString(16);
131
+ const text = block.getTextContent();
132
+ const input = text.slice(0, 200) + String(text.length);
133
+ let hash = 5381;
134
+ for (let i = 0; i < input.length; i++) {
135
+ hash = (hash << 5) + hash + (input.codePointAt(i) ?? 0) | 0;
136
+ }
137
+ return (hash >>> 0).toString(16);
139
138
  }
140
139
  function $getRootBlock(node) {
141
- const root = $getRoot();
142
- let current = node;
143
- while (current) {
144
- const parent = current.getParent();
145
- if (parent === root && "getChildren" in current) return current;
146
- current = parent;
147
- }
148
- return null;
140
+ const root = $getRoot();
141
+ let current = node;
142
+ while (current) {
143
+ const parent = current.getParent();
144
+ if (parent === root && "getChildren" in current) {
145
+ return current;
146
+ }
147
+ current = parent;
148
+ }
149
+ return null;
149
150
  }
150
151
  function $resolveSelectionPoint(selection, which) {
151
- const point = selection[which];
152
- const node = point.getNode();
153
- if ($isElementNode(node)) {
154
- const children = node.getChildren();
155
- if (point.offset < children.length) return {
156
- node: children[point.offset],
157
- offset: 0
158
- };
159
- const last = children.at(-1);
160
- if (last && $isTextNode(last)) return {
161
- node: last,
162
- offset: last.getTextContentSize()
163
- };
164
- return {
165
- node,
166
- offset: 0
167
- };
168
- }
169
- return {
170
- node,
171
- offset: point.offset
172
- };
152
+ const point = selection[which];
153
+ const node = point.getNode();
154
+ if ($isElementNode(node)) {
155
+ const children = node.getChildren();
156
+ if (point.offset < children.length) {
157
+ return { node: children[point.offset], offset: 0 };
158
+ }
159
+ const last = children.at(-1);
160
+ if (last && $isTextNode(last)) {
161
+ return { node: last, offset: last.getTextContentSize() };
162
+ }
163
+ return { node, offset: 0 };
164
+ }
165
+ return { node, offset: point.offset };
173
166
  }
174
167
  function $getTextOffsetInBlock(block, targetNode, targetOffset) {
175
- let offset = 0;
176
- function walk(node) {
177
- if (node.is(targetNode)) {
178
- offset += targetOffset;
179
- return true;
180
- }
181
- if ($isTextNode(node)) offset += node.getTextContentSize();
182
- else if ($isLineBreakNode(node)) offset += 1;
183
- else if ($isElementNode(node)) {
184
- for (const child of node.getChildren()) if (walk(child)) return true;
185
- }
186
- return false;
187
- }
188
- for (const child of block.getChildren()) if (walk(child)) break;
189
- return offset;
168
+ let offset = 0;
169
+ function walk(node) {
170
+ if (node.is(targetNode)) {
171
+ offset += targetOffset;
172
+ return true;
173
+ }
174
+ if ($isTextNode(node)) {
175
+ offset += node.getTextContentSize();
176
+ } else if ($isLineBreakNode(node)) {
177
+ offset += 1;
178
+ } else if ($isElementNode(node)) {
179
+ for (const child of node.getChildren()) {
180
+ if (walk(child)) return true;
181
+ }
182
+ }
183
+ return false;
184
+ }
185
+ for (const child of block.getChildren()) {
186
+ if (walk(child)) break;
187
+ }
188
+ return offset;
190
189
  }
191
190
  function $buildBlockAnchorData(block) {
192
- const blockId = $getState(block, blockIdState);
193
- if (!blockId) return {
194
- ok: false,
195
- error: "no-block-id"
196
- };
197
- return {
198
- ok: true,
199
- anchor: {
200
- mode: "block",
201
- blockId,
202
- blockType: block.getType(),
203
- blockFingerprint: computeBlockFingerprint(block),
204
- snapshotText: block.getTextContent().slice(0, 300)
205
- }
206
- };
191
+ const blockId = $getState(block, blockIdState);
192
+ if (!blockId) {
193
+ return { ok: false, error: "no-block-id" };
194
+ }
195
+ return {
196
+ ok: true,
197
+ anchor: {
198
+ mode: "block",
199
+ blockId,
200
+ blockType: block.getType(),
201
+ blockFingerprint: computeBlockFingerprint(block),
202
+ snapshotText: block.getTextContent().slice(0, 300)
203
+ }
204
+ };
207
205
  }
208
206
  function buildBlockAnchor(editor, blockKey) {
209
- return editor.read(() => {
210
- if (blockKey) {
211
- const node = $getRoot().getChildren().find((c) => c.getKey() === blockKey);
212
- if (!node || !("getChildren" in node)) return {
213
- ok: false,
214
- error: "not-root-block"
215
- };
216
- return $buildBlockAnchorData(node);
217
- }
218
- const selection = $getSelection();
219
- if (!$isRangeSelection(selection)) return {
220
- ok: false,
221
- error: "no-selection"
222
- };
223
- const block = $getRootBlock(selection.anchor.getNode());
224
- if (!block) return {
225
- ok: false,
226
- error: "not-root-block"
227
- };
228
- return $buildBlockAnchorData(block);
229
- });
207
+ return editor.read(() => {
208
+ if (blockKey) {
209
+ const node = $getRoot().getChildren().find((c2) => c2.getKey() === blockKey);
210
+ if (!node || !("getChildren" in node)) {
211
+ return { ok: false, error: "not-root-block" };
212
+ }
213
+ return $buildBlockAnchorData(node);
214
+ }
215
+ const selection = $getSelection();
216
+ if (!$isRangeSelection(selection)) {
217
+ return { ok: false, error: "no-selection" };
218
+ }
219
+ const anchorNode = selection.anchor.getNode();
220
+ const block = $getRootBlock(anchorNode);
221
+ if (!block) {
222
+ return { ok: false, error: "not-root-block" };
223
+ }
224
+ return $buildBlockAnchorData(block);
225
+ });
230
226
  }
231
227
  function buildRangeAnchor(editor) {
232
- return editor.read(() => {
233
- const selection = $getSelection();
234
- if (!$isRangeSelection(selection)) return {
235
- ok: false,
236
- error: "no-selection"
237
- };
238
- if (selection.isCollapsed()) return {
239
- ok: false,
240
- error: "collapsed"
241
- };
242
- const anchorBlock = $getRootBlock(selection.anchor.getNode());
243
- const focusBlock = $getRootBlock(selection.focus.getNode());
244
- if (!anchorBlock || !focusBlock) return {
245
- ok: false,
246
- error: "not-root-block"
247
- };
248
- if (anchorBlock !== focusBlock) return {
249
- ok: false,
250
- error: "cross-block"
251
- };
252
- const block = anchorBlock;
253
- const blockId = $getState(block, blockIdState);
254
- if (!blockId) return {
255
- ok: false,
256
- error: "no-block-id"
257
- };
258
- const anchorPoint = $resolveSelectionPoint(selection, "anchor");
259
- const focusPoint = $resolveSelectionPoint(selection, "focus");
260
- let startOffset = $getTextOffsetInBlock(block, anchorPoint.node, anchorPoint.offset);
261
- let endOffset = $getTextOffsetInBlock(block, focusPoint.node, focusPoint.offset);
262
- if (startOffset > endOffset) [startOffset, endOffset] = [endOffset, startOffset];
263
- const text = block.getTextContent();
264
- const quote = text.slice(startOffset, endOffset);
265
- const prefix = text.slice(Math.max(0, startOffset - 50), startOffset);
266
- const suffix = text.slice(endOffset, endOffset + 50);
267
- return {
268
- ok: true,
269
- anchor: {
270
- mode: "range",
271
- blockId,
272
- blockType: block.getType(),
273
- blockFingerprint: computeBlockFingerprint(block),
274
- snapshotText: text.slice(0, 300),
275
- quote,
276
- prefix,
277
- suffix,
278
- startOffset,
279
- endOffset
280
- }
281
- };
282
- });
228
+ return editor.read(() => {
229
+ const selection = $getSelection();
230
+ if (!$isRangeSelection(selection)) {
231
+ return { ok: false, error: "no-selection" };
232
+ }
233
+ if (selection.isCollapsed()) {
234
+ return { ok: false, error: "collapsed" };
235
+ }
236
+ const anchorBlock = $getRootBlock(selection.anchor.getNode());
237
+ const focusBlock = $getRootBlock(selection.focus.getNode());
238
+ if (!anchorBlock || !focusBlock) {
239
+ return { ok: false, error: "not-root-block" };
240
+ }
241
+ if (anchorBlock !== focusBlock) {
242
+ return { ok: false, error: "cross-block" };
243
+ }
244
+ const block = anchorBlock;
245
+ const blockId = $getState(block, blockIdState);
246
+ if (!blockId) {
247
+ return { ok: false, error: "no-block-id" };
248
+ }
249
+ const anchorPoint = $resolveSelectionPoint(selection, "anchor");
250
+ const focusPoint = $resolveSelectionPoint(selection, "focus");
251
+ let startOffset = $getTextOffsetInBlock(block, anchorPoint.node, anchorPoint.offset);
252
+ let endOffset = $getTextOffsetInBlock(block, focusPoint.node, focusPoint.offset);
253
+ if (startOffset > endOffset) {
254
+ [startOffset, endOffset] = [endOffset, startOffset];
255
+ }
256
+ const text = block.getTextContent();
257
+ const quote = text.slice(startOffset, endOffset);
258
+ const prefix = text.slice(Math.max(0, startOffset - 50), startOffset);
259
+ const suffix = text.slice(endOffset, endOffset + 50);
260
+ return {
261
+ ok: true,
262
+ anchor: {
263
+ mode: "range",
264
+ blockId,
265
+ blockType: block.getType(),
266
+ blockFingerprint: computeBlockFingerprint(block),
267
+ snapshotText: text.slice(0, 300),
268
+ quote,
269
+ prefix,
270
+ suffix,
271
+ startOffset,
272
+ endOffset
273
+ }
274
+ };
275
+ });
283
276
  }
284
- //#endregion
285
- export { ColorSchemeProvider, CorePlugins, FootnoteDefinitionsProvider, LinkFavicon, NestedContentRendererProvider, PresentDialogProvider, RendererConfigProvider, RichEditor, RichEditorShell, articleTheme, articleVariant, buildBlockAnchor, buildRangeAnchor, commentTheme, commentVariant, editorTheme, getVariantClass, noteTheme, noteVariant, richContent, useColorScheme, useFootnoteContent, useFootnoteDefinitions, useFootnoteDisplayNumber, useNestedContentRenderer, useOptionalNestedContentRenderer, usePresentDialog, useRendererConfig, useRendererMode, useVariant, vars };
277
+ export {
278
+ ColorSchemeProvider,
279
+ CorePlugins,
280
+ F as FootnoteDefinitionsProvider,
281
+ L as LinkFavicon,
282
+ N as NestedContentRendererProvider,
283
+ P as PresentDialogProvider,
284
+ RendererConfigProvider,
285
+ RichEditor,
286
+ RichEditorShell,
287
+ articleTheme,
288
+ a as articleVariant,
289
+ buildBlockAnchor,
290
+ buildRangeAnchor,
291
+ commentTheme,
292
+ c as commentVariant,
293
+ editorTheme,
294
+ getVariantClass,
295
+ noteTheme,
296
+ n as noteVariant,
297
+ r as richContent,
298
+ u2 as useColorScheme,
299
+ u3 as useFootnoteContent,
300
+ b as useFootnoteDefinitions,
301
+ d as useFootnoteDisplayNumber,
302
+ u4 as useNestedContentRenderer,
303
+ p as useOptionalNestedContentRenderer,
304
+ u as usePresentDialog,
305
+ e as useRendererConfig,
306
+ f as useRendererMode,
307
+ g as useVariant,
308
+ vars
309
+ };