@haklex/rich-ext-nested-doc 0.1.0 → 0.2.0

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.
@@ -1,249 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { extractTextContent as extractTextContent$1 } from "@haklex/rich-editor/commands";
5
- import { useOptionalNestedContentRenderer, useColorScheme, useRendererConfig, usePresentDialog, useVariant, ColorSchemeProvider, NestedContentRendererProvider, extractTextContent } from "@haklex/rich-editor/static";
6
- import { DecoratorNode } from "lexical";
7
- import { useMemo, useCallback, createElement } from "react";
8
- import { jsx, Fragment, jsxs } from "react/jsx-runtime";
9
- import { usePortalTheme } from "@haklex/rich-style-token";
10
- import { Maximize2 } from "lucide-react";
11
- import { RichRenderer } from "@haklex/rich-static-renderer";
12
- var editOverlayRoot = "_1an6v8d0";
13
- var editOverlay = "_1an6v8d1";
14
- var rendererContent = "_1an6v8d2";
15
- var dialogPopup = "_1an6v8d3";
16
- var dialogShell = "_1an6v8d4";
17
- var dialogHeader = "_1an6v8d5";
18
- var dialogHeaderLeft = "_1an6v8d6";
19
- var dialogTitle = "_1an6v8d7";
20
- var dialogHeaderRight = "_1an6v8d8";
21
- var dialogHeaderCloseBtn = "_1an6v8d9";
22
- var editorArea = "_1an6v8dc";
23
- var dialogFooter = "_1an6v8dg";
24
- var staticOverlayRoot = "_1an6v8dh";
25
- var staticOverlay = "_1an6v8di";
26
- var staticGradientMask = "_1an6v8dj";
27
- var staticDialogPopup = "_1an6v8dk";
28
- var staticDialogBody = "_1an6v8dl";
29
- var previewSurface = "_1an6v8dm";
30
- var previewEmpty = "_1an6v8dn";
31
- function NestedDocRenderer({
32
- value,
33
- variant = "comment"
34
- }) {
35
- const renderNestedContent = useOptionalNestedContentRenderer();
36
- const theme = useColorScheme();
37
- const rendererConfig = useRendererConfig();
38
- if (renderNestedContent) {
39
- return /* @__PURE__ */ jsx(Fragment, { children: renderNestedContent(value, variant) });
40
- }
41
- return /* @__PURE__ */ jsx(RichRenderer, { rendererConfig, theme, value, variant });
42
- }
43
- function truncateEditorState(state, maxNodes) {
44
- const root = state.root;
45
- if (!root?.children || root.children.length <= maxNodes) return state;
46
- return {
47
- ...state,
48
- root: {
49
- ...root,
50
- children: root.children.slice(0, maxNodes)
51
- }
52
- };
53
- }
54
- function hasRenderableEditorState(state) {
55
- const children = state.root?.children ?? [];
56
- if (children.length === 0) return false;
57
- if (children.length > 1) return true;
58
- const first = children[0];
59
- if (!first) return false;
60
- if (first.type !== "paragraph") return true;
61
- return first.children?.some((child) => {
62
- if (child.type !== "text") return true;
63
- return Boolean(child.text?.trim());
64
- }) ?? false;
65
- }
66
- const PREVIEW_NODE_LIMIT = 6;
67
- function NestedDocStaticDecorator({ contentState }) {
68
- const colorScheme = useColorScheme();
69
- const { className: portalClassName } = usePortalTheme();
70
- const presentDialogFromCtx = usePresentDialog();
71
- const renderNestedContent = useOptionalNestedContentRenderer();
72
- const children = contentState.root?.children ?? [];
73
- const needsTruncation = children.length > PREVIEW_NODE_LIMIT;
74
- const previewState = useMemo(
75
- () => truncateEditorState(contentState, PREVIEW_NODE_LIMIT),
76
- [contentState]
77
- );
78
- const hasPreview = hasRenderableEditorState(contentState);
79
- const title = useMemo(() => {
80
- const firstChild = children[0];
81
- if (!firstChild) return "";
82
- const walk = (node) => {
83
- if (node.text) return node.text;
84
- if (node.children) return node.children.map(walk).join("");
85
- return "";
86
- };
87
- return walk(firstChild).slice(0, 80);
88
- }, [children]);
89
- const contextVariant = useVariant();
90
- const handleOpen = useCallback(async () => {
91
- const present = presentDialogFromCtx ?? (await import("@haklex/rich-editor-ui")).presentDialog;
92
- present({
93
- title: title || void 0,
94
- content: () => /* @__PURE__ */ jsx(ColorSchemeProvider, { colorScheme, children: /* @__PURE__ */ jsx(NestedContentRendererProvider, { value: renderNestedContent, children: /* @__PURE__ */ jsx("div", { className: staticDialogBody, children: /* @__PURE__ */ jsx(NestedDocRenderer, { value: contentState, variant: contextVariant }) }) }) }),
95
- className: staticDialogPopup,
96
- portalClassName,
97
- theme: colorScheme,
98
- showCloseButton: true,
99
- clickOutsideToDismiss: true,
100
- sheet: "auto"
101
- });
102
- }, [
103
- colorScheme,
104
- contentState,
105
- portalClassName,
106
- presentDialogFromCtx,
107
- renderNestedContent,
108
- title,
109
- contextVariant
110
- ]);
111
- if (!hasPreview) {
112
- return null;
113
- }
114
- return /* @__PURE__ */ jsxs(
115
- "div",
116
- {
117
- className: staticOverlayRoot,
118
- role: "button",
119
- tabIndex: 0,
120
- onClick: handleOpen,
121
- onKeyDown: (e) => {
122
- if (e.key === "Enter" || e.key === " ") {
123
- e.preventDefault();
124
- handleOpen();
125
- }
126
- },
127
- children: [
128
- /* @__PURE__ */ jsx("div", { className: `${rendererContent} rich-nested-doc-content`, children: /* @__PURE__ */ jsx("div", { className: previewSurface, children: /* @__PURE__ */ jsx(NestedDocRenderer, { value: previewState }) }) }),
129
- needsTruncation && /* @__PURE__ */ jsx("div", { "aria-hidden": true, className: staticGradientMask }),
130
- /* @__PURE__ */ jsx("div", { "aria-hidden": true, className: staticOverlay, children: /* @__PURE__ */ jsx(Maximize2, { size: 24 }) })
131
- ]
132
- }
133
- );
134
- }
135
- class NestedDocNode extends DecoratorNode {
136
- constructor(contentState, key) {
137
- super(key);
138
- __publicField(this, "__contentState");
139
- this.__contentState = contentState || {
140
- root: {
141
- children: [
142
- {
143
- type: "paragraph",
144
- children: [],
145
- direction: null,
146
- format: "",
147
- indent: 0,
148
- textFormat: 0,
149
- textStyle: "",
150
- version: 1
151
- }
152
- ],
153
- direction: null,
154
- format: "",
155
- indent: 0,
156
- type: "root",
157
- version: 1
158
- }
159
- };
160
- }
161
- static getType() {
162
- return "nested-doc";
163
- }
164
- static clone(node) {
165
- return new NestedDocNode(node.__contentState, node.__key);
166
- }
167
- createDOM(_config) {
168
- const div = document.createElement("div");
169
- div.className = "rich-nested-doc";
170
- return div;
171
- }
172
- updateDOM() {
173
- return false;
174
- }
175
- isInline() {
176
- return false;
177
- }
178
- getContentState() {
179
- return this.getLatest().__contentState;
180
- }
181
- setContentState(state) {
182
- const writable = this.getWritable();
183
- writable.__contentState = state;
184
- }
185
- getTextContent() {
186
- return extractTextContent(this.__contentState);
187
- }
188
- static importJSON(serializedNode) {
189
- return new NestedDocNode(serializedNode.content);
190
- }
191
- exportJSON() {
192
- return {
193
- ...super.exportJSON(),
194
- type: "nested-doc",
195
- content: this.__contentState,
196
- version: 1
197
- };
198
- }
199
- decorate(_editor, _config) {
200
- return createElement(NestedDocStaticDecorator, {
201
- contentState: this.__contentState
202
- });
203
- }
204
- }
205
- function $createNestedDocNode(contentState) {
206
- return new NestedDocNode(contentState);
207
- }
208
- function $isNestedDocNode(node) {
209
- return node instanceof NestedDocNode;
210
- }
211
- const NESTED_DOC_BLOCK_TRANSFORMER = {
212
- dependencies: [],
213
- export: (node) => {
214
- if (!$isNestedDocNode(node)) return null;
215
- const text = extractTextContent$1(node.getContentState());
216
- return `<nested-doc>
217
- ${text}
218
- </nested-doc>`;
219
- },
220
- // eslint-disable-next-line regexp/no-useless-assertions -- intentionally never-matching regex for export-only transformer
221
- regExp: /a^/,
222
- replace: () => {
223
- },
224
- type: "element"
225
- };
226
- export {
227
- $isNestedDocNode as $,
228
- NestedDocRenderer as N,
229
- previewEmpty as a,
230
- editOverlay as b,
231
- dialogShell as c,
232
- dialogPopup as d,
233
- editOverlayRoot as e,
234
- dialogHeader as f,
235
- dialogHeaderLeft as g,
236
- hasRenderableEditorState as h,
237
- dialogTitle as i,
238
- dialogHeaderRight as j,
239
- dialogHeaderCloseBtn as k,
240
- editorArea as l,
241
- dialogFooter as m,
242
- NestedDocNode as n,
243
- $createNestedDocNode as o,
244
- previewSurface as p,
245
- NESTED_DOC_BLOCK_TRANSFORMER as q,
246
- rendererContent as r,
247
- NestedDocStaticDecorator as s,
248
- truncateEditorState as t
249
- };