@gantfdt/semiword 0.0.0-stage → 1.0.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.
Files changed (97) hide show
  1. package/LICENSE +6 -0
  2. package/README.md +258 -2
  3. package/dist-lib/FlowchartEditor-EFUVACVN.mjs +442 -0
  4. package/dist-lib/FlowchartEditor-EFUVACVN.mjs.map +1 -0
  5. package/dist-lib/MindmapEditor-CCJRPI4I.mjs +141 -0
  6. package/dist-lib/MindmapEditor-CCJRPI4I.mjs.map +1 -0
  7. package/dist-lib/WhiteboardEditor-STZ7W7XX.mjs +120 -0
  8. package/dist-lib/WhiteboardEditor-STZ7W7XX.mjs.map +1 -0
  9. package/dist-lib/ai.d.mts +33 -0
  10. package/dist-lib/ai.mjs +14 -0
  11. package/dist-lib/ai.mjs.map +1 -0
  12. package/dist-lib/chunk-347SCO7S.mjs +3 -0
  13. package/dist-lib/chunk-347SCO7S.mjs.map +1 -0
  14. package/dist-lib/chunk-4F4NEVHE.mjs +100 -0
  15. package/dist-lib/chunk-4F4NEVHE.mjs.map +1 -0
  16. package/dist-lib/chunk-4W6PPBHQ.mjs +474 -0
  17. package/dist-lib/chunk-4W6PPBHQ.mjs.map +1 -0
  18. package/dist-lib/chunk-7AAZUM6M.mjs +45 -0
  19. package/dist-lib/chunk-7AAZUM6M.mjs.map +1 -0
  20. package/dist-lib/chunk-BBZ5ZBEK.mjs +1510 -0
  21. package/dist-lib/chunk-BBZ5ZBEK.mjs.map +1 -0
  22. package/dist-lib/chunk-CREU4TZJ.mjs +24 -0
  23. package/dist-lib/chunk-CREU4TZJ.mjs.map +1 -0
  24. package/dist-lib/chunk-EEUFVA37.mjs +4024 -0
  25. package/dist-lib/chunk-EEUFVA37.mjs.map +1 -0
  26. package/dist-lib/chunk-EOIJPQZI.mjs +370 -0
  27. package/dist-lib/chunk-EOIJPQZI.mjs.map +1 -0
  28. package/dist-lib/chunk-EOUNN3NA.mjs +1517 -0
  29. package/dist-lib/chunk-EOUNN3NA.mjs.map +1 -0
  30. package/dist-lib/chunk-FOIP7DEC.mjs +12 -0
  31. package/dist-lib/chunk-FOIP7DEC.mjs.map +1 -0
  32. package/dist-lib/chunk-GGIOCI2I.mjs +2442 -0
  33. package/dist-lib/chunk-GGIOCI2I.mjs.map +1 -0
  34. package/dist-lib/chunk-IICCIMZU.mjs +5272 -0
  35. package/dist-lib/chunk-IICCIMZU.mjs.map +1 -0
  36. package/dist-lib/chunk-JC5ZZPSL.mjs +600 -0
  37. package/dist-lib/chunk-JC5ZZPSL.mjs.map +1 -0
  38. package/dist-lib/chunk-K7Z56Q4M.mjs +6327 -0
  39. package/dist-lib/chunk-K7Z56Q4M.mjs.map +1 -0
  40. package/dist-lib/chunk-NPPS63UI.mjs +285 -0
  41. package/dist-lib/chunk-NPPS63UI.mjs.map +1 -0
  42. package/dist-lib/chunk-PFA3XERW.mjs +19 -0
  43. package/dist-lib/chunk-PFA3XERW.mjs.map +1 -0
  44. package/dist-lib/chunk-QWDJU3H7.mjs +18 -0
  45. package/dist-lib/chunk-QWDJU3H7.mjs.map +1 -0
  46. package/dist-lib/chunk-TOA6CRSJ.mjs +3917 -0
  47. package/dist-lib/chunk-TOA6CRSJ.mjs.map +1 -0
  48. package/dist-lib/chunk-W627LLF4.mjs +16 -0
  49. package/dist-lib/chunk-W627LLF4.mjs.map +1 -0
  50. package/dist-lib/chunk-XAEALEVP.mjs +547 -0
  51. package/dist-lib/chunk-XAEALEVP.mjs.map +1 -0
  52. package/dist-lib/chunk-ZM3WULHX.mjs +910 -0
  53. package/dist-lib/chunk-ZM3WULHX.mjs.map +1 -0
  54. package/dist-lib/context-DKwyjx1q.d.mts +37 -0
  55. package/dist-lib/designer.d.mts +215 -0
  56. package/dist-lib/designer.mjs +15 -0
  57. package/dist-lib/designer.mjs.map +1 -0
  58. package/dist-lib/document.d.mts +12 -0
  59. package/dist-lib/document.mjs +4 -0
  60. package/dist-lib/document.mjs.map +1 -0
  61. package/dist-lib/editor.d.mts +408 -0
  62. package/dist-lib/editor.mjs +19 -0
  63. package/dist-lib/editor.mjs.map +1 -0
  64. package/dist-lib/gant-ai.d.mts +40 -0
  65. package/dist-lib/gant-ai.mjs +217 -0
  66. package/dist-lib/gant-ai.mjs.map +1 -0
  67. package/dist-lib/index.d.mts +22 -0
  68. package/dist-lib/index.mjs +19 -0
  69. package/dist-lib/index.mjs.map +1 -0
  70. package/dist-lib/interface-RYndHNLS.d.mts +91 -0
  71. package/dist-lib/io.d.mts +75 -0
  72. package/dist-lib/io.mjs +9 -0
  73. package/dist-lib/io.mjs.map +1 -0
  74. package/dist-lib/memoryHistoryStore-DY47xjO_.d.mts +280 -0
  75. package/dist-lib/mindmapConstants-X75XUXV3.mjs +4 -0
  76. package/dist-lib/mindmapConstants-X75XUXV3.mjs.map +1 -0
  77. package/dist-lib/resolve-BMcwblyP.d.mts +114 -0
  78. package/dist-lib/sdk.d.mts +60 -0
  79. package/dist-lib/sdk.mjs +137 -0
  80. package/dist-lib/sdk.mjs.map +1 -0
  81. package/dist-lib/shapes-5SMSF6ML.mjs +4 -0
  82. package/dist-lib/shapes-5SMSF6ML.mjs.map +1 -0
  83. package/dist-lib/storage.d.mts +91 -0
  84. package/dist-lib/storage.mjs +5 -0
  85. package/dist-lib/storage.mjs.map +1 -0
  86. package/dist-lib/template.d.mts +155 -0
  87. package/dist-lib/template.mjs +6 -0
  88. package/dist-lib/template.mjs.map +1 -0
  89. package/dist-lib/types-CO6ppyIY.d.mts +18 -0
  90. package/dist-lib/types-CUsV1hUm.d.mts +49 -0
  91. package/dist-lib/types-ClQ38-C_.d.mts +256 -0
  92. package/dist-lib/types-D1D2miCr.d.mts +117 -0
  93. package/dist-lib/types-DiyyKlc1.d.mts +355 -0
  94. package/dist-lib/types-s1JYaGtG.d.mts +56 -0
  95. package/dist-lib/types-vl8k8NDK.d.mts +562 -0
  96. package/dist-lib/useDocumentPersistence-DOpnQsZQ.d.mts +228 -0
  97. package/package.json +282 -4
@@ -0,0 +1,910 @@
1
+ import { sanitizeSvg } from './chunk-4W6PPBHQ.mjs';
2
+ import { tr } from './chunk-W627LLF4.mjs';
3
+ import { createContext, forwardRef, useMemo, lazy, memo, useState, useCallback, useContext, useRef, useEffect, Suspense } from 'react';
4
+ import { Input, ConfigProvider, theme, Tooltip as Tooltip$1, Tabs as Tabs$1, Modal as Modal$1, Drawer as Drawer$1, Empty, InputNumber as InputNumber$1, Select as Select$1, Radio as Radio$1, Button, Spin } from 'antd';
5
+ export { Alert, Button, Checkbox, DatePicker, Divider, Dropdown, Popover, Radio as Radio2, Select as Select2, Space, Spin, Switch, Tag } from 'antd';
6
+ import { keyframes, cx, css } from '@emotion/css';
7
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
8
+ import { Node, mergeAttributes } from '@tiptap/core';
9
+ import { NodeSelection } from '@tiptap/pm/state';
10
+ import { ReactNodeViewRenderer, NodeViewWrapper } from '@tiptap/react';
11
+ import { EditOutlined, DeleteOutlined } from '@ant-design/icons';
12
+
13
+ var EditorStyleContext = createContext({});
14
+ function EditorStyleProvider({ componentSize, glassEffect = false, children }) {
15
+ const value = useMemo(() => ({ componentSize, glassEffect }), [componentSize, glassEffect]);
16
+ const antdSize = componentSize === "compact" ? "small" : componentSize;
17
+ return /* @__PURE__ */ jsx(EditorStyleContext.Provider, { value, children: /* @__PURE__ */ jsx(ConfigProvider, { componentSize: antdSize, children }) });
18
+ }
19
+ function useEditorStyleConfig() {
20
+ return useContext(EditorStyleContext);
21
+ }
22
+
23
+ // src/editor/ui/createStyles.ts
24
+ function isSizeType(value) {
25
+ return value === "small" || value === "middle" || value === "large" || value === "compact";
26
+ }
27
+ function resolveSize(params, explicitSize, fallback) {
28
+ if (isSizeType(explicitSize)) return explicitSize;
29
+ if (isSizeType(params)) return params;
30
+ if (params && typeof params === "object" && "size" in params) {
31
+ const size = params.size;
32
+ if (isSizeType(size)) return size;
33
+ }
34
+ return fallback;
35
+ }
36
+ function parseColor(color) {
37
+ const hex = color.trim().match(/^#([\da-f]{3}|[\da-f]{6})(?:[\da-f]{2})?$/i)?.[1];
38
+ if (hex) {
39
+ const normalized = hex.length === 3 ? hex.split("").map((char) => char + char).join("") : hex;
40
+ return [
41
+ Number.parseInt(normalized.slice(0, 2), 16),
42
+ Number.parseInt(normalized.slice(2, 4), 16),
43
+ Number.parseInt(normalized.slice(4, 6), 16)
44
+ ];
45
+ }
46
+ const rgb = color.trim().match(/^rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/i);
47
+ return rgb ? [Number(rgb[1]), Number(rgb[2]), Number(rgb[3])] : null;
48
+ }
49
+ function getAlphaColor(baseColor, alpha) {
50
+ const rgb = parseColor(baseColor);
51
+ if (!rgb) return baseColor;
52
+ return `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, ${alpha})`;
53
+ }
54
+ function createSizeToken(token, size) {
55
+ switch (size) {
56
+ case "small":
57
+ return {
58
+ controlHeight: token.controlHeight,
59
+ paddingContentVertical: 8,
60
+ paddingContentHorizontal: token.paddingContentHorizontalSM,
61
+ borderRadius: token.borderRadiusSM,
62
+ fontSize: token.fontSize
63
+ };
64
+ case "large":
65
+ return {
66
+ controlHeight: token.controlHeightLG,
67
+ paddingContentVertical: token.paddingContentVerticalLG,
68
+ paddingContentHorizontal: token.paddingContentHorizontalLG,
69
+ borderRadius: token.borderRadiusLG,
70
+ fontSize: token.fontSizeSM
71
+ };
72
+ case "compact":
73
+ return {
74
+ controlHeight: token.controlHeightXS,
75
+ paddingContentVertical: token.paddingXXS,
76
+ paddingContentHorizontal: token.paddingXS,
77
+ borderRadius: token.borderRadiusXS,
78
+ fontSize: token.fontSize
79
+ };
80
+ default:
81
+ return {
82
+ controlHeight: token.controlHeight,
83
+ paddingContentVertical: token.paddingContentVertical,
84
+ paddingContentHorizontal: token.paddingContentHorizontal,
85
+ borderRadius: token.borderRadius,
86
+ fontSize: token.fontSize
87
+ };
88
+ }
89
+ }
90
+ function createStyles(callback) {
91
+ return (params, explicitSize) => {
92
+ const { token } = theme.useToken();
93
+ const { componentSize } = ConfigProvider.useConfig();
94
+ const config = useEditorStyleConfig();
95
+ const size = resolveSize(params, explicitSize, config.componentSize ?? componentSize ?? "middle");
96
+ const glassEffect = config.glassEffect === true;
97
+ const sizeToken = useMemo(() => createSizeToken(token, size), [token, size]);
98
+ const options = useMemo(
99
+ () => ({ token, sizeToken, size, css, cx, keyframes, getAlphaColor, glassEffect, params }),
100
+ [token, sizeToken, size, glassEffect, params]
101
+ );
102
+ const styles = useMemo(() => callback(options), [options]);
103
+ return { styles, cx, token, sizeToken, size, getAlphaColor, glassEffect, css };
104
+ };
105
+ }
106
+ var currentRegistrar;
107
+ var overlaySequence = 0;
108
+ function configureEditorOverlayRegistrar(registrar) {
109
+ currentRegistrar = registrar;
110
+ }
111
+ function useEditorOverlayRegistry({ open, type, title }) {
112
+ const idRef = useRef(null);
113
+ if (!idRef.current) {
114
+ overlaySequence += 1;
115
+ idRef.current = `semiword_${type}_${overlaySequence}`;
116
+ }
117
+ useEffect(() => {
118
+ if (!open || !currentRegistrar) return;
119
+ return currentRegistrar({ id: idRef.current, type, title });
120
+ }, [open, type, title]);
121
+ }
122
+ var useTooltipStyles = createStyles(({ css: css2, token }) => ({
123
+ wrapper: css2`
124
+ .ant-tooltip-inner {
125
+ color: ${token.colorTextHeading};
126
+ padding: ${token.controlPaddingHorizontal - 2}px ${token.controlPaddingHorizontal}px;
127
+ }
128
+ `,
129
+ autoWidth: css2`
130
+ max-width: 100% !important;
131
+ `,
132
+ fixedWidth: css2`
133
+ max-width: 360px !important;
134
+ `
135
+ }));
136
+ function Tooltip({ autoWidth = true, rootClassName, color, ...props }) {
137
+ const { styles, cx: cx2, token } = useTooltipStyles();
138
+ return /* @__PURE__ */ jsx(
139
+ Tooltip$1,
140
+ {
141
+ ...props,
142
+ color: color ?? token.colorBgContainer,
143
+ rootClassName: cx2(styles.wrapper, autoWidth ? styles.autoWidth : styles.fixedWidth, rootClassName)
144
+ }
145
+ );
146
+ }
147
+ var useTabsStyles = createStyles(({ css: css2, token, sizeToken }) => ({
148
+ wrapper: css2`
149
+ background-color: var(--colorBgAlphaColorContainer);
150
+ border-radius: ${token.borderRadius}px;
151
+
152
+ .tabs-content-padding .tabs-content-scroll {
153
+ padding: 2px ${sizeToken.paddingContentHorizontal}px ${sizeToken.paddingContentVertical}px;
154
+ }
155
+ .tabs-content-scroll {
156
+ padding-top: 2px;
157
+ }
158
+ `,
159
+ oneTabs: css2`
160
+ .ant-tabs-nav {
161
+ margin-bottom: 0;
162
+ background-color: transparent;
163
+ padding: 0 ${sizeToken.paddingContentHorizontal}px;
164
+ }
165
+ `,
166
+ divider: css2`
167
+ padding-bottom: ${sizeToken.paddingContentVertical}px;
168
+ `,
169
+ twoTabs: css2`
170
+ .ant-tabs-nav {
171
+ display: none;
172
+ }
173
+ `
174
+ }));
175
+ function Tabs({ items, contentPadding = true, className, style, ...props }) {
176
+ const { styles, cx: cx2 } = useTabsStyles();
177
+ const topItems = useMemo(
178
+ () => items?.map((item) => {
179
+ const next = { ...item };
180
+ delete next.children;
181
+ return next;
182
+ }),
183
+ [items]
184
+ );
185
+ return /* @__PURE__ */ jsxs("div", { className: cx2(styles.wrapper, "tabs-root", className), style, children: [
186
+ /* @__PURE__ */ jsxs("div", { children: [
187
+ /* @__PURE__ */ jsx(Tabs$1, { ...props, className: cx2(styles.oneTabs, "tabs-bar"), items: topItems }),
188
+ /* @__PURE__ */ jsx("div", { className: cx2(styles.divider, "ant-tab-divider") })
189
+ ] }),
190
+ /* @__PURE__ */ jsx("div", { className: cx2("tabs-content-wrapper", { "tabs-content-padding": contentPadding }), children: /* @__PURE__ */ jsx("div", { className: "tabs-content-scroll", style: { overflow: "visible" }, children: /* @__PURE__ */ jsx(
191
+ Tabs$1,
192
+ {
193
+ ...props,
194
+ className: cx2(styles.twoTabs, className, "tabs-content"),
195
+ animated: { inkBar: true, tabPane: true },
196
+ items
197
+ }
198
+ ) }) })
199
+ ] });
200
+ }
201
+ function Modal({
202
+ footer = true,
203
+ onClose,
204
+ onCancel,
205
+ destroyOnClose,
206
+ destroyOnHidden,
207
+ children,
208
+ ...props
209
+ }) {
210
+ useEditorOverlayRegistry({
211
+ open: !!props.open,
212
+ type: "modal",
213
+ title: typeof props.title === "string" ? props.title : void 0
214
+ });
215
+ return /* @__PURE__ */ jsx(
216
+ Modal$1,
217
+ {
218
+ centered: true,
219
+ ...props,
220
+ footer: typeof footer === "boolean" ? footer ? void 0 : null : footer,
221
+ destroyOnHidden: destroyOnHidden ?? destroyOnClose,
222
+ onCancel: onClose ?? onCancel,
223
+ children: /* @__PURE__ */ jsx("div", { className: "gant-modal-wrapper gant-modal-bg-wrapper", children: /* @__PURE__ */ jsx("div", { className: "gant-modal-content-scroll", children: /* @__PURE__ */ jsx("div", { className: "gant-modal-content", children }) }) })
224
+ }
225
+ );
226
+ }
227
+ function Drawer({ footer = true, children, ...props }) {
228
+ useEditorOverlayRegistry({
229
+ open: !!props.open,
230
+ type: "drawer",
231
+ title: typeof props.title === "string" ? props.title : void 0
232
+ });
233
+ return /* @__PURE__ */ jsx(Drawer$1, { destroyOnHidden: true, ...props, footer: typeof footer === "boolean" ? footer ? void 0 : null : footer, children: /* @__PURE__ */ jsx("div", { className: "drawer-body-wrapper", children: /* @__PURE__ */ jsx("div", { className: "drawer-body-content drawer-body-content-wrapper", children: /* @__PURE__ */ jsx("div", { className: "drawer-body-content-scroll", children }) }) }) });
234
+ }
235
+ var useStyles = createStyles(({ css: css2, token }) => ({
236
+ imageContainer: css2`
237
+ display: flex;
238
+ justify-content: center;
239
+ align-items: center;
240
+ `,
241
+ text: css2`
242
+ margin-top: ${token.paddingContentVertical}px;
243
+ font-size: ${token.fontSizeHeading4}px;
244
+ text-align: center;
245
+ `,
246
+ tips: css2`
247
+ margin-top: 4px;
248
+ color: ${token.colorTextQuaternary};
249
+ text-align: center;
250
+ `
251
+ }));
252
+ function CustomEmpty({ emptyText = tr("\u6682\u65E0\u6570\u636E"), emptyTips, emptyImage, className }) {
253
+ const { styles } = useStyles();
254
+ return /* @__PURE__ */ jsxs("div", { className, children: [
255
+ /* @__PURE__ */ jsx(
256
+ Empty,
257
+ {
258
+ className: styles.imageContainer,
259
+ image: emptyImage ?? Empty.PRESENTED_IMAGE_SIMPLE,
260
+ imageStyle: { height: 80, width: 80 },
261
+ description: null
262
+ }
263
+ ),
264
+ /* @__PURE__ */ jsxs("div", { style: { marginTop: -20 }, children: [
265
+ /* @__PURE__ */ jsx("h5", { className: styles.text, children: emptyText }),
266
+ emptyTips ? /* @__PURE__ */ jsx("p", { className: styles.tips, children: emptyTips }) : null
267
+ ] })
268
+ ] });
269
+ }
270
+ var TextArea = forwardRef(function TextArea2({ onChange, autoSize = { minRows: 2, maxRows: 6 }, ...props }, ref) {
271
+ return /* @__PURE__ */ jsx(
272
+ Input.TextArea,
273
+ {
274
+ ...props,
275
+ autoSize,
276
+ onChange: (event) => onChange?.(event.target.value),
277
+ ref
278
+ }
279
+ );
280
+ });
281
+ var InternalInput = forwardRef(function Input$1({ onChange, ...props }, ref) {
282
+ return /* @__PURE__ */ jsx(
283
+ Input,
284
+ {
285
+ allowClear: true,
286
+ ...props,
287
+ onChange: (event) => onChange?.(event.target.value),
288
+ ref
289
+ }
290
+ );
291
+ });
292
+ var Input2 = Object.assign(InternalInput, {
293
+ Group: Input.Group,
294
+ Search: Input.Search,
295
+ TextArea,
296
+ Password: Input.Password,
297
+ OTP: Input.OTP
298
+ });
299
+ function InputNumber({ step = 1, precision = 0, onChange, ...props }) {
300
+ const stepPrecision = String(step).split(".")[1]?.length ?? 0;
301
+ return /* @__PURE__ */ jsx(
302
+ InputNumber$1,
303
+ {
304
+ ...props,
305
+ step,
306
+ precision: Math.max(stepPrecision, precision),
307
+ onChange: (value) => onChange?.(value ?? void 0)
308
+ }
309
+ );
310
+ }
311
+ function Select({
312
+ dataSource = [],
313
+ labelProp = "label",
314
+ valueProp = "value",
315
+ optionDisabled,
316
+ ...props
317
+ }) {
318
+ const options = useMemo(
319
+ () => dataSource.map((item) => ({
320
+ label: item[labelProp],
321
+ value: item[valueProp],
322
+ disabled: optionDisabled ? optionDisabled(item) : item.disabled
323
+ })),
324
+ [dataSource, labelProp, valueProp, optionDisabled]
325
+ );
326
+ return /* @__PURE__ */ jsx(Select$1, { allowClear: true, showSearch: true, ...props, options });
327
+ }
328
+ function Radio({
329
+ dataSource = [],
330
+ labelProp = "label",
331
+ valueProp = "value",
332
+ optionDisabled,
333
+ onChange,
334
+ ...props
335
+ }) {
336
+ const options = useMemo(
337
+ () => dataSource.map((item) => ({
338
+ label: item[labelProp],
339
+ value: item[valueProp],
340
+ disabled: optionDisabled ? optionDisabled(item) : item.disabled
341
+ })),
342
+ [dataSource, labelProp, valueProp, optionDisabled]
343
+ );
344
+ return /* @__PURE__ */ jsx(Radio$1.Group, { ...props, options, onChange: (event) => onChange?.(event.target.value) });
345
+ }
346
+
347
+ // src/editor/plugins/builtin/shared/graphicblock/utils.ts
348
+ function svgToDataUri(svg) {
349
+ const safeSvg = sanitizeSvg(svg);
350
+ return safeSvg ? `data:image/svg+xml;charset=utf-8,${encodeURIComponent(safeSvg)}` : "";
351
+ }
352
+ function parseJsonAttr(raw) {
353
+ if (!raw || typeof raw !== "string") return null;
354
+ try {
355
+ const parsed = JSON.parse(raw);
356
+ return parsed && typeof parsed === "object" ? parsed : null;
357
+ } catch {
358
+ return null;
359
+ }
360
+ }
361
+ function finalizeSvgRoot(svgEl, { stripSelectors, forceAspectRatio } = {}) {
362
+ const selectors = stripSelectors?.filter(Boolean) ?? [];
363
+ if (selectors.length > 0) {
364
+ svgEl.querySelectorAll(selectors.join(", ")).forEach((el) => el.remove());
365
+ }
366
+ const width = Math.round(parseFloat(svgEl.getAttribute("width") || "0")) || 0;
367
+ const height = Math.round(parseFloat(svgEl.getAttribute("height") || "0")) || 0;
368
+ if (!svgEl.getAttribute("viewBox") && width > 0 && height > 0) {
369
+ svgEl.setAttribute("viewBox", `0 0 ${width} ${height}`);
370
+ svgEl.setAttribute("preserveAspectRatio", "xMidYMid meet");
371
+ }
372
+ if (forceAspectRatio) {
373
+ svgEl.setAttribute("preserveAspectRatio", "xMidYMid meet");
374
+ }
375
+ const svg = new XMLSerializer().serializeToString(svgEl);
376
+ return { svg, width, height };
377
+ }
378
+ function EditorActionBar({ onCancel, onSave }) {
379
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
380
+ /* @__PURE__ */ jsx(Button, { size: "small", onClick: onCancel, children: tr("\u53D6\u6D88") }),
381
+ /* @__PURE__ */ jsx(Button, { size: "small", type: "primary", onClick: onSave, children: tr("\u4FDD\u5B58") })
382
+ ] });
383
+ }
384
+ function createGraphicBlockNode(options) {
385
+ const { name, dataType, alt, commandName, view } = options;
386
+ return Node.create({
387
+ name,
388
+ group: "block",
389
+ atom: true,
390
+ draggable: true,
391
+ addAttributes() {
392
+ return {
393
+ // 图数据的 JSON 字符串(各块结构不同:x6 toJSON / Excalidraw scene / simple-mind-map getData)
394
+ data: { default: "" },
395
+ // SVG 快照,用于预览态与导出还原
396
+ svg: { default: "" },
397
+ // 预览块宽/高(像素):保存时取内容自然尺寸,之后可分别拖拽调节;null 表示自适应。
398
+ // 以 data-width/data-height 承载并显式转 number,避免落在 div 上被 parseHTML 读回成字符串
399
+ width: {
400
+ default: null,
401
+ parseHTML: (el) => {
402
+ const v = parseFloat(el.getAttribute("data-width") || "");
403
+ return Number.isFinite(v) && v > 0 ? v : null;
404
+ },
405
+ renderHTML: (attrs) => typeof attrs.width === "number" && attrs.width > 0 ? { "data-width": String(attrs.width) } : {}
406
+ },
407
+ height: {
408
+ default: null,
409
+ parseHTML: (el) => {
410
+ const v = parseFloat(el.getAttribute("data-height") || "");
411
+ return Number.isFinite(v) && v > 0 ? v : null;
412
+ },
413
+ renderHTML: (attrs) => typeof attrs.height === "number" && attrs.height > 0 ? { "data-height": String(attrs.height) } : {}
414
+ }
415
+ };
416
+ },
417
+ parseHTML() {
418
+ return [{ tag: `div[data-type="${dataType}"]` }];
419
+ },
420
+ /**
421
+ * 渲染为 HTML(getHTML() 导出场景)。
422
+ * 编辑器内由 NodeView 接管渲染。
423
+ * - div 保留 data/svg 属性,parseHTML 自动还原,确保导出→导入图数据不丢失。
424
+ * - svg 存在时追加 <img src=data-uri>,使导出的 HTML/PDF 能直接显示图形。
425
+ */
426
+ renderHTML({ HTMLAttributes }) {
427
+ const svg = HTMLAttributes.svg;
428
+ const width = parseFloat(HTMLAttributes["data-width"] ?? "");
429
+ const height = parseFloat(HTMLAttributes["data-height"] ?? "");
430
+ const attrs = mergeAttributes(HTMLAttributes, { "data-type": dataType });
431
+ const src = typeof svg === "string" ? svgToDataUri(svg) : "";
432
+ if (src) {
433
+ const parts = ["max-width:100%;"];
434
+ if (Number.isFinite(width) && width > 0) parts.push(`width:${width}px;`);
435
+ if (Number.isFinite(height) && height > 0) {
436
+ parts.push(`height:${height}px;object-fit:contain;`);
437
+ }
438
+ return ["div", attrs, ["img", { src, alt, style: parts.join("") }]];
439
+ }
440
+ return ["div", attrs];
441
+ },
442
+ addNodeView() {
443
+ return ReactNodeViewRenderer(view);
444
+ },
445
+ addCommands() {
446
+ return {
447
+ [commandName]: () => ({ editor, commands }) => {
448
+ const node = { type: this.name, attrs: { data: "", svg: "" } };
449
+ if (editor.state.selection instanceof NodeSelection) {
450
+ return commands.insertContentAt(editor.state.selection.to, node);
451
+ }
452
+ return commands.insertContent(node);
453
+ }
454
+ };
455
+ }
456
+ });
457
+ }
458
+
459
+ // src/editor/plugins/builtin/shared/blockStyle.ts
460
+ var useBlockStyles = createStyles(({ css: css2, token, sizeToken, glassEffect, getAlphaColor: getAlphaColor2 }) => {
461
+ const { borderRadius, paddingContentVertical } = sizeToken;
462
+ return {
463
+ wrapper: css2`
464
+ margin: 16px 0;
465
+ border-radius: ${borderRadius + 4}px;
466
+ border: 1px solid ${token.colorBorderSecondary};
467
+ overflow: hidden;
468
+ transition: border-color 0.2s;
469
+
470
+ &:hover {
471
+ border-color: ${token.colorPrimaryHover};
472
+ }
473
+ `,
474
+ wrapperSelected: css2`
475
+ border-color: ${token.colorPrimary};
476
+ box-shadow: 0 0 0 2px ${getAlphaColor2(token.colorPrimary, 0.1)};
477
+ `,
478
+ /**
479
+ * 预览态外壳:宽度收缩贴合内容(fit-content),使边框/背景随内容尺寸变化。
480
+ * min-width 保证内容极窄时右上角工具栏(编辑/删除)仍能完整显示。
481
+ * 仅预览态启用;编辑态 wrapper 保持块级撑满,保证编辑器有充足宽度。
482
+ */
483
+ wrapperPreview: css2`
484
+ width: fit-content;
485
+ min-width: 200px;
486
+ max-width: 100%;
487
+ `,
488
+ /**
489
+ * 预览容器:高度随内容自然撑开(不设 min-height),使边框在高度方向也贴合内容、
490
+ * 不产生底部留白;空块靠 placeholder 自身 padding 保证可点击区域。
491
+ */
492
+ preview: css2`
493
+ position: relative;
494
+ background: ${glassEffect ? getAlphaColor2(token.colorBgContainer, 0.3) : token.colorBgLayout};
495
+ `,
496
+ snapshot: css2`
497
+ padding: ${paddingContentVertical}px;
498
+ display: flex;
499
+ align-items: center;
500
+ justify-content: center;
501
+ cursor: pointer;
502
+
503
+ svg,
504
+ img {
505
+ max-width: 100%;
506
+ max-height: 500px;
507
+ }
508
+ `,
509
+ /**
510
+ * 可调节尺寸的快照容器(思维导图等:保存后按内容自然尺寸展示,可拖拽调节)。
511
+ * 设定了显式宽高时不再受 max-height:500px 截断,内部 SVG 等比填满容器
512
+ * (依赖导出 SVG 带 viewBox,preserveAspectRatio 默认保持比例并居中)。
513
+ */
514
+ snapshotResizable: css2`
515
+ box-sizing: border-box;
516
+ overflow: hidden;
517
+
518
+ svg,
519
+ img {
520
+ width: 100%;
521
+ height: 100%;
522
+ max-width: 100%;
523
+ max-height: 100%;
524
+ object-fit: contain;
525
+ }
526
+ `,
527
+ /**
528
+ * 可调节尺寸快照的定位容器:宽度收缩贴合内部快照(fit-content),
529
+ * 作为右下角手柄的定位参照,使手柄贴在快照右下角并随宽高拖拽同步移动。
530
+ */
531
+ resizableWrap: css2`
532
+ position: relative;
533
+ width: fit-content;
534
+ max-width: 100%;
535
+ `,
536
+ /** 右下角尺寸调节手柄 */
537
+ resizeHandle: css2`
538
+ position: absolute;
539
+ right: 2px;
540
+ bottom: 2px;
541
+ width: 16px;
542
+ height: 16px;
543
+ cursor: nwse-resize;
544
+ opacity: 0;
545
+ transition: opacity 0.2s;
546
+ z-index: 2;
547
+
548
+ &::after {
549
+ content: '';
550
+ position: absolute;
551
+ right: 3px;
552
+ bottom: 3px;
553
+ width: 8px;
554
+ height: 8px;
555
+ border-right: 2px solid ${token.colorPrimary};
556
+ border-bottom: 2px solid ${token.colorPrimary};
557
+ }
558
+
559
+ /* 悬停在 preview 父容器时显示手柄 */
560
+ div:hover > & {
561
+ opacity: 0.6;
562
+ }
563
+
564
+ &:hover {
565
+ opacity: 1;
566
+ }
567
+ `,
568
+ /** 选中态常显手柄 */
569
+ resizeHandleVisible: css2`
570
+ opacity: 0.8;
571
+ `,
572
+ placeholder: css2`
573
+ display: flex;
574
+ flex-direction: column;
575
+ align-items: center;
576
+ justify-content: center;
577
+ padding: 40px;
578
+ color: ${token.colorTextTertiary};
579
+ cursor: pointer;
580
+ gap: 12px;
581
+
582
+ svg {
583
+ opacity: 0.4;
584
+ }
585
+
586
+ &:hover {
587
+ color: ${token.colorPrimary};
588
+ svg {
589
+ opacity: 0.7;
590
+ }
591
+ }
592
+ `,
593
+ toolbar: css2`
594
+ position: absolute;
595
+ top: 8px;
596
+ right: 8px;
597
+ display: flex;
598
+ gap: 4px;
599
+ opacity: 0;
600
+ transition: opacity 0.2s;
601
+ background: ${glassEffect ? getAlphaColor2(token.colorBgElevated, 0.8) : token.colorBgElevated};
602
+ border-radius: ${borderRadius}px;
603
+ padding: 2px 4px;
604
+ box-shadow: ${token.boxShadowSecondary};
605
+
606
+ /* 悬停在 preview 父容器时显示工具栏(toolbar 是 preview 的直接子元素) */
607
+ div:hover > & {
608
+ opacity: 1;
609
+ }
610
+ `,
611
+ editorContainer: css2`
612
+ display: flex;
613
+ flex-direction: column;
614
+ height: 500px;
615
+ `
616
+ };
617
+ });
618
+
619
+ // src/editor/plugins/builtin/shared/graphicblock/style.ts
620
+ var useImgPreviewStyles = createStyles(({ css: css2, token }) => ({
621
+ // 预览外壳:相对定位承载右下角手柄与右上角工具栏。
622
+ // 用普通块级布局(非 flex),max-width:100% 把 box 约束进容器内。
623
+ preview: css2`
624
+ position: relative;
625
+ `,
626
+ // 快照盒子:宽高由内联 style 指定,max-width:100% 兜底约束进容器,img 在盒内等比 contain
627
+ snapshot: css2`
628
+ position: relative;
629
+ max-width: 100%;
630
+ box-sizing: border-box;
631
+ padding: ${token.paddingSM}px;
632
+ cursor: pointer;
633
+
634
+ img {
635
+ display: block;
636
+ width: 100%;
637
+ height: 100%;
638
+ object-fit: contain;
639
+ }
640
+ `
641
+ }));
642
+ var MIN_WIDTH = 120;
643
+ var MIN_HEIGHT = 80;
644
+ function useResizableSize({ width, height, updateAttributes }) {
645
+ const [dragSize, setDragSize] = useState(null);
646
+ const dragRef = useRef(null);
647
+ const snapshotRef = useRef(null);
648
+ const detachDragListenersRef = useRef(null);
649
+ useEffect(
650
+ () => () => {
651
+ detachDragListenersRef.current?.();
652
+ detachDragListenersRef.current = null;
653
+ },
654
+ []
655
+ );
656
+ const handleResizeStart = useCallback(
657
+ (e) => {
658
+ e.preventDefault();
659
+ e.stopPropagation();
660
+ const rect = snapshotRef.current?.getBoundingClientRect();
661
+ const startW = typeof width === "number" && width > 0 ? width : rect?.width ?? MIN_WIDTH;
662
+ const startH = typeof height === "number" && height > 0 ? height : rect?.height ?? MIN_HEIGHT;
663
+ dragRef.current = { startX: e.clientX, startY: e.clientY, startW, startH, width: startW, height: startH };
664
+ setDragSize({ width: startW, height: startH });
665
+ const onMove = (ev) => {
666
+ const d = dragRef.current;
667
+ if (!d) return;
668
+ const next = {
669
+ width: Math.max(MIN_WIDTH, d.startW + (ev.clientX - d.startX)),
670
+ height: Math.max(MIN_HEIGHT, d.startH + (ev.clientY - d.startY))
671
+ };
672
+ d.width = next.width;
673
+ d.height = next.height;
674
+ setDragSize(next);
675
+ };
676
+ const onUp = () => {
677
+ detachDragListenersRef.current?.();
678
+ detachDragListenersRef.current = null;
679
+ const d = dragRef.current;
680
+ dragRef.current = null;
681
+ if (d) {
682
+ updateAttributes({
683
+ width: Math.round(d.width),
684
+ height: Math.round(d.height)
685
+ });
686
+ }
687
+ setDragSize(null);
688
+ };
689
+ window.addEventListener("pointermove", onMove);
690
+ window.addEventListener("pointerup", onUp);
691
+ window.addEventListener("pointercancel", onUp);
692
+ detachDragListenersRef.current = () => {
693
+ window.removeEventListener("pointermove", onMove);
694
+ window.removeEventListener("pointerup", onUp);
695
+ window.removeEventListener("pointercancel", onUp);
696
+ };
697
+ },
698
+ [width, height, updateAttributes]
699
+ );
700
+ const snapshotStyle = useMemo(() => {
701
+ const w = dragSize?.width ?? (typeof width === "number" && width > 0 ? width : void 0);
702
+ const h = dragSize?.height ?? (typeof height === "number" && height > 0 ? height : void 0);
703
+ return { width: w, height: h };
704
+ }, [dragSize, width, height]);
705
+ return { snapshotRef, snapshotStyle, handleResizeStart };
706
+ }
707
+ function GraphicPreviewBody({
708
+ hasPreview,
709
+ snapshot,
710
+ onResizeStart,
711
+ selected,
712
+ placeholderIcon,
713
+ placeholderText,
714
+ editable,
715
+ onEdit,
716
+ onDelete
717
+ }) {
718
+ const { styles, cx: cx2 } = useBlockStyles();
719
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
720
+ hasPreview ? (
721
+ // 定位容器宽度贴合快照,手柄相对它定位,宽高拖拽时手柄同步跟随
722
+ /* @__PURE__ */ jsxs("div", { className: styles.resizableWrap, children: [
723
+ snapshot,
724
+ /* @__PURE__ */ jsx(
725
+ "div",
726
+ {
727
+ className: cx2(styles.resizeHandle, selected && styles.resizeHandleVisible),
728
+ onPointerDown: onResizeStart,
729
+ onClick: (e) => e.stopPropagation()
730
+ }
731
+ )
732
+ ] })
733
+ ) : /* @__PURE__ */ jsxs("div", { className: styles.placeholder, onClick: onEdit, children: [
734
+ placeholderIcon,
735
+ /* @__PURE__ */ jsx("span", { children: placeholderText() })
736
+ ] }),
737
+ /* @__PURE__ */ jsxs("div", { className: styles.toolbar, children: [
738
+ /* @__PURE__ */ jsx(Button, { type: "text", size: "small", icon: /* @__PURE__ */ jsx(EditOutlined, {}), onClick: onEdit, children: tr("\u7F16\u8F91") }),
739
+ editable && /* @__PURE__ */ jsx(Button, { type: "text", size: "small", icon: /* @__PURE__ */ jsx(DeleteOutlined, {}), onClick: onDelete, danger: true, children: tr("\u5220\u9664") })
740
+ ] })
741
+ ] });
742
+ }
743
+ function InlineSvgPreview(props) {
744
+ const { svg, width, height, updateAttributes } = props;
745
+ const { styles, cx: cx2 } = useBlockStyles();
746
+ const { snapshotRef, snapshotStyle, handleResizeStart } = useResizableSize({ width, height, updateAttributes });
747
+ const previewSvg = useMemo(() => svg ? sanitizeSvg(svg) : "", [svg]);
748
+ return /* @__PURE__ */ jsx("div", { className: styles.preview, children: /* @__PURE__ */ jsx(
749
+ GraphicPreviewBody,
750
+ {
751
+ hasPreview: !!previewSvg,
752
+ snapshot: /* @__PURE__ */ jsx(
753
+ "div",
754
+ {
755
+ ref: snapshotRef,
756
+ className: cx2(styles.snapshot, styles.snapshotResizable),
757
+ style: snapshotStyle,
758
+ dangerouslySetInnerHTML: { __html: previewSvg },
759
+ onClick: props.onEdit
760
+ }
761
+ ),
762
+ onResizeStart: handleResizeStart,
763
+ selected: props.selected,
764
+ placeholderIcon: props.placeholderIcon,
765
+ placeholderText: props.placeholderText,
766
+ editable: props.editable,
767
+ onEdit: props.onEdit,
768
+ onDelete: props.onDelete
769
+ }
770
+ ) });
771
+ }
772
+ function ImgDataUriPreview(props) {
773
+ const { svg, width, height, updateAttributes } = props;
774
+ const { styles } = useImgPreviewStyles();
775
+ const { snapshotRef, snapshotStyle, handleResizeStart } = useResizableSize({ width, height, updateAttributes });
776
+ const previewSrc = useMemo(() => svg ? svgToDataUri(svg) : "", [svg]);
777
+ return /* @__PURE__ */ jsx("div", { className: styles.preview, children: /* @__PURE__ */ jsx(
778
+ GraphicPreviewBody,
779
+ {
780
+ hasPreview: !!previewSrc,
781
+ snapshot: /* @__PURE__ */ jsx("div", { ref: snapshotRef, className: styles.snapshot, style: snapshotStyle, onClick: props.onEdit, children: /* @__PURE__ */ jsx("img", { src: previewSrc, alt: props.alt }) }),
782
+ onResizeStart: handleResizeStart,
783
+ selected: props.selected,
784
+ placeholderIcon: props.placeholderIcon,
785
+ placeholderText: props.placeholderText,
786
+ editable: props.editable,
787
+ onEdit: props.onEdit,
788
+ onDelete: props.onDelete
789
+ }
790
+ ) });
791
+ }
792
+ function GraphicPreview(props) {
793
+ return props.strategy === "imgDataUri" ? /* @__PURE__ */ jsx(ImgDataUriPreview, { ...props }) : /* @__PURE__ */ jsx(InlineSvgPreview, { ...props });
794
+ }
795
+ function GraphicEditorHost({
796
+ editor: Editor,
797
+ value,
798
+ onSave,
799
+ onCancel,
800
+ loadingText
801
+ }) {
802
+ const { styles } = useBlockStyles();
803
+ return /* @__PURE__ */ jsx("div", { className: styles.editorContainer, children: /* @__PURE__ */ jsx(
804
+ Suspense,
805
+ {
806
+ fallback: /* @__PURE__ */ jsx("div", { style: { display: "flex", alignItems: "center", justifyContent: "center", height: "100%" }, children: /* @__PURE__ */ jsx(Spin, { tip: loadingText() }) }),
807
+ children: /* @__PURE__ */ jsx(Editor, { value, onSave, onCancel })
808
+ }
809
+ ) });
810
+ }
811
+ function createGraphicBlockView(options) {
812
+ const { previewStrategy, placeholderIcon, placeholderText, loadingText, alt, editorLoader } = options;
813
+ const LazyEditor = lazy(editorLoader);
814
+ const GraphicBlockView = memo(({ node, updateAttributes, deleteNode, selected, editor }) => {
815
+ const { styles, cx: cx2 } = useBlockStyles();
816
+ const [mode, setMode] = useState("preview");
817
+ const { data, svg, width, height } = node.attrs;
818
+ const value = useMemo(() => parseJsonAttr(data), [data]);
819
+ const handleEdit = useCallback(() => {
820
+ if (!editor.isEditable) return;
821
+ setMode("editing");
822
+ }, [editor]);
823
+ const handleDelete = useCallback(() => {
824
+ if (!editor.isEditable) return;
825
+ deleteNode();
826
+ }, [deleteNode, editor]);
827
+ const handleSave = useCallback(
828
+ (result) => {
829
+ updateAttributes({
830
+ data: JSON.stringify(result.data),
831
+ svg: sanitizeSvg(result.svg),
832
+ // 保存时以内容自然尺寸为初始块尺寸,之后可拖拽调节
833
+ width: result.width > 0 ? result.width : null,
834
+ height: result.height > 0 ? result.height : null
835
+ });
836
+ setMode("preview");
837
+ },
838
+ [updateAttributes]
839
+ );
840
+ const handleCancel = useCallback(() => setMode("preview"), []);
841
+ return /* @__PURE__ */ jsx(
842
+ NodeViewWrapper,
843
+ {
844
+ className: cx2(styles.wrapper, selected && styles.wrapperSelected, mode === "preview" && styles.wrapperPreview),
845
+ children: mode === "preview" ? /* @__PURE__ */ jsx(
846
+ GraphicPreview,
847
+ {
848
+ strategy: previewStrategy,
849
+ svg,
850
+ width,
851
+ height,
852
+ updateAttributes,
853
+ selected,
854
+ placeholderIcon,
855
+ placeholderText,
856
+ alt,
857
+ editable: editor.isEditable,
858
+ onEdit: handleEdit,
859
+ onDelete: handleDelete
860
+ }
861
+ ) : /* @__PURE__ */ jsx(
862
+ GraphicEditorHost,
863
+ {
864
+ editor: LazyEditor,
865
+ value,
866
+ onSave: handleSave,
867
+ onCancel: handleCancel,
868
+ loadingText
869
+ }
870
+ )
871
+ }
872
+ );
873
+ });
874
+ return GraphicBlockView;
875
+ }
876
+
877
+ // src/editor/plugins/builtin/shared/graphicblock/shellStyle.ts
878
+ function createGraphicEditorShellStyles(options = {}) {
879
+ const { toolbarJustify = "flex-start", toolbarWrap = false } = options;
880
+ return createStyles(({ css: css2, token }) => ({
881
+ root: css2`
882
+ display: flex;
883
+ flex-direction: column;
884
+ height: 100%;
885
+ `,
886
+ toolbar: css2`
887
+ display: flex;
888
+ align-items: center;
889
+ justify-content: ${toolbarJustify};
890
+ gap: 8px;
891
+ padding: 6px 12px;
892
+ border-bottom: 1px solid ${token.colorBorderSecondary};
893
+ background: ${token.colorBgContainer};
894
+ flex-wrap: ${toolbarWrap ? "wrap" : "nowrap"};
895
+ `,
896
+ spacer: css2`
897
+ flex: 1;
898
+ `,
899
+ canvas: css2`
900
+ /* flex:1 + min-height:0 让画布拿到明确的剩余可用尺寸(simple-mind-map 等依赖) */
901
+ flex: 1;
902
+ min-height: 0;
903
+ position: relative;
904
+ `
905
+ }));
906
+ }
907
+
908
+ export { CustomEmpty, Drawer, EditorActionBar, EditorStyleProvider, Input2 as Input, InputNumber, Modal, Radio, Select, Tabs, Tooltip, configureEditorOverlayRegistrar, createGraphicBlockNode, createGraphicBlockView, createGraphicEditorShellStyles, createSizeToken, createStyles, finalizeSvgRoot, getAlphaColor, useBlockStyles };
909
+ //# sourceMappingURL=chunk-ZM3WULHX.mjs.map
910
+ //# sourceMappingURL=chunk-ZM3WULHX.mjs.map