@crystallize/design-system 1.6.1 → 1.8.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.
- package/CHANGELOG.md +13 -0
- package/dist/index.css +53 -332
- package/dist/index.d.ts +15 -8
- package/dist/index.js +1736 -4555
- package/dist/index.mjs +1655 -2339
- package/package.json +1 -1
- package/src/action-menu/action-item-separator.tsx +14 -0
- package/src/action-menu/action-item.tsx +2 -2
- package/src/action-menu/action-menu.css +8 -0
- package/src/action-menu/action-menu.tsx +2 -1
- package/src/dropdown-menu/dropdown-menu-root.tsx +3 -1
- package/src/dropdown-menu/index.ts +5 -2
- package/src/iconography/subscription-contracts.tsx +4 -4
- package/src/iconography/subscription-plans.tsx +5 -5
- package/src/rich-text-editor/model/crystallize-to-lexical.ts +12 -1
- package/src/rich-text-editor/model/lexical-to-crystallize.ts +38 -38
- package/src/rich-text-editor/nodes/BaseNodes.ts +0 -7
- package/src/rich-text-editor/nodes/TableCellNodes.ts +0 -7
- package/src/rich-text-editor/plugins/ActionsPlugin/index.tsx +13 -2
- package/src/rich-text-editor/plugins/CodeActionMenuPlugin/components/CopyButton/index.tsx +3 -2
- package/src/rich-text-editor/plugins/CodeActionMenuPlugin/components/PrettierButton/index.tsx +0 -1
- package/src/rich-text-editor/plugins/FloatingTextFormatToolbarPlugin/index.css +17 -17
- package/src/rich-text-editor/plugins/FloatingTextFormatToolbarPlugin/index.tsx +1 -1
- package/src/rich-text-editor/plugins/MaxLengthPlugin/index.tsx +2 -7
- package/src/rich-text-editor/plugins/TableActionMenuPlugin/index.tsx +80 -149
- package/src/rich-text-editor/plugins/ToolbarPlugin/index.tsx +2 -2
- package/src/rich-text-editor/plugins/ToolbarPlugin/insert-table.tsx +55 -0
- package/src/rich-text-editor/rich-text-editor.css +10 -322
- package/src/rich-text-editor/rich-text-editor.stories.tsx +35 -5
- package/src/rich-text-editor/rich-text-editor.tsx +6 -39
- package/src/rich-text-editor/tests/rich-text-editor-code.test.tsx +10 -6
- package/src/rich-text-editor/tests/rich-text-editor-model-conversions.test.tsx +19 -7
- package/src/rich-text-editor/themes/CrystallizeRTEditorTheme.css +3 -11
- package/dist/TableComponent-I2YOOYOU.css +0 -281
- package/dist/TableComponent-QINOO453.mjs +0 -1377
- package/dist/chevron-down-3FRWSIKS.svg +0 -1
- package/dist/chunk-VUXQZRSP.mjs +0 -737
- package/dist/markdown-4BGQNLLT.svg +0 -1
- package/src/rich-text-editor/nodes/KeywordNode.ts +0 -73
- package/src/rich-text-editor/nodes/TableComponent.tsx +0 -1547
- package/src/rich-text-editor/nodes/TableNode.tsx +0 -398
- package/src/rich-text-editor/plugins/ComponentPickerPlugin/index.tsx +0 -320
- package/src/rich-text-editor/plugins/DragDropPastePlugin/index.ts +0 -40
- package/src/rich-text-editor/plugins/MarkdownShortcutPlugin/index.tsx +0 -16
- package/src/rich-text-editor/plugins/MarkdownTransformers/index.ts +0 -195
- package/src/rich-text-editor/plugins/SpeechToTextPlugin/index.ts +0 -113
- package/src/rich-text-editor/plugins/TableCellResizer/index.css +0 -12
- package/src/rich-text-editor/plugins/TableCellResizer/index.tsx +0 -386
- package/src/rich-text-editor/plugins/TablePlugin.tsx +0 -190
- package/src/rich-text-editor/plugins/TreeViewPlugin/index.tsx +0 -25
- package/src/rich-text-editor/plugins/TypingPerfPlugin/index.ts +0 -117
package/dist/chunk-VUXQZRSP.mjs
DELETED
|
@@ -1,737 +0,0 @@
|
|
|
1
|
-
// src/spinner/index.tsx
|
|
2
|
-
import { cx } from "class-variance-authority";
|
|
3
|
-
import { forwardRef } from "react";
|
|
4
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
var realSize = 40;
|
|
6
|
-
var Spinner = forwardRef(
|
|
7
|
-
({ children, className, color = "currentColor", size = 30, strokeSize, ...delegated }, ref) => {
|
|
8
|
-
const viewSize = size || realSize;
|
|
9
|
-
const sizeHalf = realSize / 2;
|
|
10
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
11
|
-
ref,
|
|
12
|
-
className: cx("c-spinner", className),
|
|
13
|
-
"data-testid": "loading-spinner",
|
|
14
|
-
...delegated,
|
|
15
|
-
children: [
|
|
16
|
-
/* @__PURE__ */ jsx("svg", {
|
|
17
|
-
viewBox: `0 0 ${realSize} ${realSize}`,
|
|
18
|
-
x: "0px",
|
|
19
|
-
y: "0px",
|
|
20
|
-
style: { width: viewSize, height: viewSize },
|
|
21
|
-
children: /* @__PURE__ */ jsx("circle", {
|
|
22
|
-
cx: "20",
|
|
23
|
-
cy: "20",
|
|
24
|
-
r: "18",
|
|
25
|
-
style: {
|
|
26
|
-
stroke: color,
|
|
27
|
-
strokeWidth: strokeSize ? strokeSize : viewSize / 10,
|
|
28
|
-
strokeLinecap: "round",
|
|
29
|
-
strokeDasharray: size < 16 ? size * 6 : size * 3.5,
|
|
30
|
-
transformOrigin: `${sizeHalf}px ${sizeHalf}px 0`
|
|
31
|
-
},
|
|
32
|
-
className: "c-spinner-artifact"
|
|
33
|
-
})
|
|
34
|
-
}),
|
|
35
|
-
children && /* @__PURE__ */ jsx("span", {
|
|
36
|
-
className: "c-spinner-children",
|
|
37
|
-
style: { fontSize: size ? `${size * 0.75}px` : "1em" },
|
|
38
|
-
children
|
|
39
|
-
})
|
|
40
|
-
]
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
);
|
|
44
|
-
Spinner.displayName = "Spinner";
|
|
45
|
-
|
|
46
|
-
// src/button/button.tsx
|
|
47
|
-
import { forwardRef as forwardRef2 } from "react";
|
|
48
|
-
import { cva } from "class-variance-authority";
|
|
49
|
-
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
50
|
-
var buttonTokens = {
|
|
51
|
-
variant: {
|
|
52
|
-
default: "c-btn",
|
|
53
|
-
elevate: "c-btn-elevate"
|
|
54
|
-
},
|
|
55
|
-
intent: {
|
|
56
|
-
default: "c-btn",
|
|
57
|
-
action: "c-btn-action",
|
|
58
|
-
danger: "c-btn-danger"
|
|
59
|
-
},
|
|
60
|
-
size: {
|
|
61
|
-
xs: "c-btn-xs",
|
|
62
|
-
sm: "c-btn-sm",
|
|
63
|
-
md: "c-btn-md",
|
|
64
|
-
lg: "c-btn-lg"
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var buttonStyles = cva("c-btn", {
|
|
68
|
-
variants: {
|
|
69
|
-
intent: {
|
|
70
|
-
default: "",
|
|
71
|
-
action: "",
|
|
72
|
-
danger: ""
|
|
73
|
-
},
|
|
74
|
-
variant: {
|
|
75
|
-
default: "",
|
|
76
|
-
elevate: ""
|
|
77
|
-
},
|
|
78
|
-
status: {
|
|
79
|
-
loading: "c-btn-loading"
|
|
80
|
-
},
|
|
81
|
-
size: {
|
|
82
|
-
xs: "c-btn-xs",
|
|
83
|
-
sm: "c-btn-sm",
|
|
84
|
-
md: "c-btn-md",
|
|
85
|
-
lg: "c-btn-lg"
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
compoundVariants: [
|
|
89
|
-
{
|
|
90
|
-
intent: "default",
|
|
91
|
-
variant: "elevate",
|
|
92
|
-
class: "c-btn-elevate"
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
intent: "action",
|
|
96
|
-
variant: "default",
|
|
97
|
-
class: "c-btn-action"
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
intent: "danger",
|
|
101
|
-
variant: "default",
|
|
102
|
-
class: "c-btn-danger"
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
intent: "danger",
|
|
106
|
-
variant: "elevate",
|
|
107
|
-
class: "c-btn-danger c-btn-elevate"
|
|
108
|
-
}
|
|
109
|
-
],
|
|
110
|
-
defaultVariants: {
|
|
111
|
-
intent: "default",
|
|
112
|
-
variant: "default",
|
|
113
|
-
size: "sm"
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
var spinnerSizeMap = {
|
|
117
|
-
xs: 10,
|
|
118
|
-
sm: 12,
|
|
119
|
-
md: 14,
|
|
120
|
-
lg: 16
|
|
121
|
-
};
|
|
122
|
-
var Button = forwardRef2(
|
|
123
|
-
({
|
|
124
|
-
children,
|
|
125
|
-
className,
|
|
126
|
-
type = "button",
|
|
127
|
-
as: El = "button",
|
|
128
|
-
size,
|
|
129
|
-
variant,
|
|
130
|
-
intent,
|
|
131
|
-
prepend,
|
|
132
|
-
append,
|
|
133
|
-
status,
|
|
134
|
-
...delegated
|
|
135
|
-
}, ref) => {
|
|
136
|
-
let isAnchor = false;
|
|
137
|
-
if ("to" in delegated || "href" in delegated) {
|
|
138
|
-
isAnchor = true;
|
|
139
|
-
}
|
|
140
|
-
return /* @__PURE__ */ jsxs2(El, {
|
|
141
|
-
ref,
|
|
142
|
-
type: isAnchor ? void 0 : type,
|
|
143
|
-
className: buttonStyles({ size, variant, intent, status, className }),
|
|
144
|
-
...delegated,
|
|
145
|
-
children: [
|
|
146
|
-
!prepend ? null : /* @__PURE__ */ jsx2("span", {
|
|
147
|
-
className: "c-btn__prepend",
|
|
148
|
-
children: prepend
|
|
149
|
-
}),
|
|
150
|
-
children,
|
|
151
|
-
status !== "loading" ? null : /* @__PURE__ */ jsx2("span", {
|
|
152
|
-
className: "c-btn__loading-spinner",
|
|
153
|
-
children: /* @__PURE__ */ jsx2(Spinner, {
|
|
154
|
-
size: size ? spinnerSizeMap[size] : spinnerSizeMap.md
|
|
155
|
-
})
|
|
156
|
-
}),
|
|
157
|
-
!append ? null : /* @__PURE__ */ jsx2("span", {
|
|
158
|
-
className: "c-btn__append",
|
|
159
|
-
children: append
|
|
160
|
-
})
|
|
161
|
-
]
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
);
|
|
165
|
-
Button.displayName = "Button";
|
|
166
|
-
|
|
167
|
-
// src/input/input.tsx
|
|
168
|
-
import { cva as cva2 } from "class-variance-authority";
|
|
169
|
-
import { forwardRef as forwardRef3 } from "react";
|
|
170
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
171
|
-
var inputStyles = cva2(["c-input"], {
|
|
172
|
-
variants: {},
|
|
173
|
-
defaultVariants: {}
|
|
174
|
-
});
|
|
175
|
-
var Input = forwardRef3(({ className, ...delegated }, ref) => {
|
|
176
|
-
return /* @__PURE__ */ jsx3("input", {
|
|
177
|
-
ref,
|
|
178
|
-
className: inputStyles({ className }),
|
|
179
|
-
type: "text",
|
|
180
|
-
...delegated
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
Input.displayName = "Input";
|
|
184
|
-
|
|
185
|
-
// src/label/label.tsx
|
|
186
|
-
import { forwardRef as forwardRef4 } from "react";
|
|
187
|
-
import { cx as cx2 } from "class-variance-authority";
|
|
188
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
189
|
-
var Label = forwardRef4(({ className, ...delegated }, ref) => {
|
|
190
|
-
return /* @__PURE__ */ jsx4("label", {
|
|
191
|
-
ref,
|
|
192
|
-
className: cx2("c-label", className),
|
|
193
|
-
...delegated
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
Label.displayName = "Label";
|
|
197
|
-
|
|
198
|
-
// src/input-with-label/input-with-label.tsx
|
|
199
|
-
import { forwardRef as forwardRef6 } from "react";
|
|
200
|
-
import { cva as cva3, cx as cx3 } from "class-variance-authority";
|
|
201
|
-
|
|
202
|
-
// src/iconography/triangle.tsx
|
|
203
|
-
import { forwardRef as forwardRef5 } from "react";
|
|
204
|
-
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
205
|
-
var Triangle = forwardRef5((delegated, ref) => {
|
|
206
|
-
const { width = 20, height = 20, ...rest } = delegated;
|
|
207
|
-
return /* @__PURE__ */ jsx5("svg", {
|
|
208
|
-
viewBox: "0 0 17 15",
|
|
209
|
-
width,
|
|
210
|
-
height,
|
|
211
|
-
ref,
|
|
212
|
-
fill: "none",
|
|
213
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
214
|
-
...rest,
|
|
215
|
-
children: /* @__PURE__ */ jsx5("path", {
|
|
216
|
-
d: "M15.463 1.2L8.5 12.685 1.537 1.2h13.925zM1.353.896s0 0 0 0h0z",
|
|
217
|
-
stroke: "currentColor",
|
|
218
|
-
strokeWidth: 2.4
|
|
219
|
-
})
|
|
220
|
-
});
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
// src/input-with-label/input-with-label.tsx
|
|
224
|
-
import { Fragment, jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
225
|
-
var inputWithLabelStyles = cva3(["c-input-with-label"], {
|
|
226
|
-
variants: {
|
|
227
|
-
variant: {
|
|
228
|
-
default: "",
|
|
229
|
-
elevated: "c-input-with-label-elevated",
|
|
230
|
-
outlined: "c-input-with-label-outlined"
|
|
231
|
-
},
|
|
232
|
-
status: {
|
|
233
|
-
error: "c-input-with-label--error"
|
|
234
|
-
}
|
|
235
|
-
},
|
|
236
|
-
defaultVariants: {}
|
|
237
|
-
});
|
|
238
|
-
var InputWithLabel = forwardRef6(
|
|
239
|
-
({ className, label, append, errorMessage, status, variant, id, labelProps, ...delegated }, ref) => {
|
|
240
|
-
const { className: labelClassName, ...labelPropsRest } = labelProps ?? {};
|
|
241
|
-
return /* @__PURE__ */ jsx6(Fragment, {
|
|
242
|
-
children: /* @__PURE__ */ jsxs3(Label, {
|
|
243
|
-
className: inputWithLabelStyles({ status, variant, className: labelClassName }),
|
|
244
|
-
htmlFor: id,
|
|
245
|
-
...labelPropsRest,
|
|
246
|
-
children: [
|
|
247
|
-
label,
|
|
248
|
-
/* @__PURE__ */ jsxs3("span", {
|
|
249
|
-
className: "c-input-with-label-input-wrap",
|
|
250
|
-
children: [
|
|
251
|
-
/* @__PURE__ */ jsx6(Input, {
|
|
252
|
-
className: cx3("c-input-with-label-input", className),
|
|
253
|
-
ref,
|
|
254
|
-
id,
|
|
255
|
-
...delegated
|
|
256
|
-
}),
|
|
257
|
-
!append && !errorMessage ? null : /* @__PURE__ */ jsx6("div", {
|
|
258
|
-
className: "c-input-with-label-append",
|
|
259
|
-
title: errorMessage,
|
|
260
|
-
children: errorMessage ? /* @__PURE__ */ jsx6(Triangle, {}) : append
|
|
261
|
-
})
|
|
262
|
-
]
|
|
263
|
-
})
|
|
264
|
-
]
|
|
265
|
-
})
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
);
|
|
269
|
-
InputWithLabel.displayName = "InputWithLabel";
|
|
270
|
-
|
|
271
|
-
// src/rich-text-editor/plugins/TablePlugin.tsx
|
|
272
|
-
import { createContext, useContext, useEffect, useMemo, useState } from "react";
|
|
273
|
-
import "react";
|
|
274
|
-
import {
|
|
275
|
-
$createNodeSelection,
|
|
276
|
-
$createParagraphNode,
|
|
277
|
-
$getSelection,
|
|
278
|
-
$isRangeSelection,
|
|
279
|
-
$isRootOrShadowRoot,
|
|
280
|
-
$setSelection,
|
|
281
|
-
COMMAND_PRIORITY_EDITOR,
|
|
282
|
-
createCommand
|
|
283
|
-
} from "lexical";
|
|
284
|
-
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
285
|
-
|
|
286
|
-
// src/rich-text-editor/nodes/TableNode.tsx
|
|
287
|
-
import * as React from "react";
|
|
288
|
-
import { Suspense } from "react";
|
|
289
|
-
import {
|
|
290
|
-
DecoratorNode
|
|
291
|
-
} from "lexical";
|
|
292
|
-
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
293
|
-
var cellHTMLCache = /* @__PURE__ */ new Map();
|
|
294
|
-
var cellTextContentCache = /* @__PURE__ */ new Map();
|
|
295
|
-
var emptyEditorJSON = '{"root":{"children":[{"children":[],"direction":null,"format":"","indent":0,"type":"paragraph","version":1}],"direction":null,"format":"","indent":0,"type":"root","version":1}}';
|
|
296
|
-
var plainTextEditorJSON = (text) => text === "" ? emptyEditorJSON : `{"root":{"children":[{"children":[{"detail":0,"format":0,"mode":"normal","style":"","text":${text},"type":"text","version":1}],"direction":"ltr","format":"","indent":0,"type":"paragraph","version":1}],"direction":"ltr","format":"","indent":0,"type":"root","version":1}}`;
|
|
297
|
-
var TableComponent = React.lazy(
|
|
298
|
-
() => import("./TableComponent-QINOO453.mjs")
|
|
299
|
-
);
|
|
300
|
-
function createUID() {
|
|
301
|
-
return Math.random().toString(36).replace(/[^a-z]+/g, "").substr(0, 5);
|
|
302
|
-
}
|
|
303
|
-
function createCell(type) {
|
|
304
|
-
return {
|
|
305
|
-
colSpan: 1,
|
|
306
|
-
id: createUID(),
|
|
307
|
-
json: emptyEditorJSON,
|
|
308
|
-
type,
|
|
309
|
-
width: null
|
|
310
|
-
};
|
|
311
|
-
}
|
|
312
|
-
function createRow() {
|
|
313
|
-
return {
|
|
314
|
-
cells: [],
|
|
315
|
-
height: null,
|
|
316
|
-
id: createUID()
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
function extractRowsFromHTML(tableElem) {
|
|
320
|
-
const rowElems = tableElem.querySelectorAll("tr");
|
|
321
|
-
const rows = [];
|
|
322
|
-
for (let y = 0; y < rowElems.length; y++) {
|
|
323
|
-
const rowElem = rowElems[y];
|
|
324
|
-
const cellElems = rowElem.querySelectorAll("td,th");
|
|
325
|
-
if (!cellElems || cellElems.length === 0) {
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
const cells = [];
|
|
329
|
-
for (let x = 0; x < cellElems.length; x++) {
|
|
330
|
-
const cellElem = cellElems[x];
|
|
331
|
-
const isHeader = cellElem.nodeName === "TH";
|
|
332
|
-
const cell = createCell(isHeader ? "header" : "normal");
|
|
333
|
-
cell.json = plainTextEditorJSON(JSON.stringify(cellElem.innerText.replace(/\n/g, " ")));
|
|
334
|
-
cells.push(cell);
|
|
335
|
-
}
|
|
336
|
-
const row = createRow();
|
|
337
|
-
row.cells = cells;
|
|
338
|
-
rows.push(row);
|
|
339
|
-
}
|
|
340
|
-
return rows;
|
|
341
|
-
}
|
|
342
|
-
function convertTableElement(domNode) {
|
|
343
|
-
const rowElems = domNode.querySelectorAll("tr");
|
|
344
|
-
if (!rowElems || rowElems.length === 0) {
|
|
345
|
-
return null;
|
|
346
|
-
}
|
|
347
|
-
const rows = [];
|
|
348
|
-
for (let y = 0; y < rowElems.length; y++) {
|
|
349
|
-
const rowElem = rowElems[y];
|
|
350
|
-
const cellElems = rowElem.querySelectorAll("td,th");
|
|
351
|
-
if (!cellElems || cellElems.length === 0) {
|
|
352
|
-
continue;
|
|
353
|
-
}
|
|
354
|
-
const cells = [];
|
|
355
|
-
for (let x = 0; x < cellElems.length; x++) {
|
|
356
|
-
const cellElem = cellElems[x];
|
|
357
|
-
const isHeader = cellElem.nodeName === "TH";
|
|
358
|
-
const cell = createCell(isHeader ? "header" : "normal");
|
|
359
|
-
cell.json = plainTextEditorJSON(JSON.stringify(cellElem.innerText.replace(/\n/g, " ")));
|
|
360
|
-
cells.push(cell);
|
|
361
|
-
}
|
|
362
|
-
const row = createRow();
|
|
363
|
-
row.cells = cells;
|
|
364
|
-
rows.push(row);
|
|
365
|
-
}
|
|
366
|
-
return { node: $createTableNode(rows) };
|
|
367
|
-
}
|
|
368
|
-
function exportTableCellsToHTML(rows, rect) {
|
|
369
|
-
const table = document.createElement("table");
|
|
370
|
-
const colGroup = document.createElement("colgroup");
|
|
371
|
-
const tBody = document.createElement("tbody");
|
|
372
|
-
const firstRow = rows[0];
|
|
373
|
-
for (let x = rect != null ? rect.startX : 0; x < (rect != null ? rect.endX + 1 : firstRow.cells.length); x++) {
|
|
374
|
-
const col = document.createElement("col");
|
|
375
|
-
colGroup.append(col);
|
|
376
|
-
}
|
|
377
|
-
for (let y = rect != null ? rect.startY : 0; y < (rect != null ? rect.endY + 1 : rows.length); y++) {
|
|
378
|
-
const row = rows[y];
|
|
379
|
-
const cells = row.cells;
|
|
380
|
-
const rowElem = document.createElement("tr");
|
|
381
|
-
for (let x = rect != null ? rect.startX : 0; x < (rect != null ? rect.endX + 1 : cells.length); x++) {
|
|
382
|
-
const cell = cells[x];
|
|
383
|
-
const cellElem = document.createElement(cell.type === "header" ? "th" : "td");
|
|
384
|
-
cellElem.innerHTML = cellHTMLCache.get(cell.json) || "";
|
|
385
|
-
rowElem.appendChild(cellElem);
|
|
386
|
-
}
|
|
387
|
-
tBody.appendChild(rowElem);
|
|
388
|
-
}
|
|
389
|
-
table.appendChild(colGroup);
|
|
390
|
-
table.appendChild(tBody);
|
|
391
|
-
return table;
|
|
392
|
-
}
|
|
393
|
-
var TableNode = class extends DecoratorNode {
|
|
394
|
-
constructor(rows, key) {
|
|
395
|
-
super(key);
|
|
396
|
-
this.__rows = rows || [];
|
|
397
|
-
}
|
|
398
|
-
static getType() {
|
|
399
|
-
return "tablesheet";
|
|
400
|
-
}
|
|
401
|
-
static clone(node) {
|
|
402
|
-
return new TableNode(Array.from(node.__rows), node.__key);
|
|
403
|
-
}
|
|
404
|
-
static importJSON(serializedNode) {
|
|
405
|
-
return $createTableNode(serializedNode.rows);
|
|
406
|
-
}
|
|
407
|
-
exportJSON() {
|
|
408
|
-
return {
|
|
409
|
-
rows: this.__rows,
|
|
410
|
-
type: "tablesheet",
|
|
411
|
-
version: 1
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
static importDOM() {
|
|
415
|
-
return {
|
|
416
|
-
table: (_node) => ({
|
|
417
|
-
conversion: convertTableElement,
|
|
418
|
-
priority: 0
|
|
419
|
-
})
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
exportDOM() {
|
|
423
|
-
return { element: exportTableCellsToHTML(this.__rows) };
|
|
424
|
-
}
|
|
425
|
-
createDOM() {
|
|
426
|
-
return document.createElement("div");
|
|
427
|
-
}
|
|
428
|
-
updateDOM() {
|
|
429
|
-
return false;
|
|
430
|
-
}
|
|
431
|
-
mergeRows(startX, startY, mergeRows) {
|
|
432
|
-
const self = this.getWritable();
|
|
433
|
-
const rows = self.__rows;
|
|
434
|
-
const endY = Math.min(rows.length, startY + mergeRows.length);
|
|
435
|
-
for (let y = startY; y < endY; y++) {
|
|
436
|
-
const row = rows[y];
|
|
437
|
-
const mergeRow = mergeRows[y - startY];
|
|
438
|
-
const cells = row.cells;
|
|
439
|
-
const cellsClone = Array.from(cells);
|
|
440
|
-
const rowClone = { ...row, cells: cellsClone };
|
|
441
|
-
const mergeCells = mergeRow.cells;
|
|
442
|
-
const endX = Math.min(cells.length, startX + mergeCells.length);
|
|
443
|
-
for (let x = startX; x < endX; x++) {
|
|
444
|
-
const cell = cells[x];
|
|
445
|
-
const mergeCell = mergeCells[x - startX];
|
|
446
|
-
const cellClone = { ...cell, json: mergeCell.json, type: mergeCell.type };
|
|
447
|
-
cellsClone[x] = cellClone;
|
|
448
|
-
}
|
|
449
|
-
rows[y] = rowClone;
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
updateCellJSON(x, y, json) {
|
|
453
|
-
const self = this.getWritable();
|
|
454
|
-
const rows = self.__rows;
|
|
455
|
-
const row = rows[y];
|
|
456
|
-
const cells = row.cells;
|
|
457
|
-
const cell = cells[x];
|
|
458
|
-
const cellsClone = Array.from(cells);
|
|
459
|
-
const cellClone = { ...cell, json };
|
|
460
|
-
const rowClone = { ...row, cells: cellsClone };
|
|
461
|
-
cellsClone[x] = cellClone;
|
|
462
|
-
rows[y] = rowClone;
|
|
463
|
-
}
|
|
464
|
-
updateCellType(x, y, type) {
|
|
465
|
-
const self = this.getWritable();
|
|
466
|
-
const rows = self.__rows;
|
|
467
|
-
const row = rows[y];
|
|
468
|
-
const cells = row.cells;
|
|
469
|
-
const cell = cells[x];
|
|
470
|
-
const cellsClone = Array.from(cells);
|
|
471
|
-
const cellClone = { ...cell, type };
|
|
472
|
-
const rowClone = { ...row, cells: cellsClone };
|
|
473
|
-
cellsClone[x] = cellClone;
|
|
474
|
-
rows[y] = rowClone;
|
|
475
|
-
}
|
|
476
|
-
insertColumnAt(x) {
|
|
477
|
-
const self = this.getWritable();
|
|
478
|
-
const rows = self.__rows;
|
|
479
|
-
for (let y = 0; y < rows.length; y++) {
|
|
480
|
-
const row = rows[y];
|
|
481
|
-
const cells = row.cells;
|
|
482
|
-
const cellsClone = Array.from(cells);
|
|
483
|
-
const rowClone = { ...row, cells: cellsClone };
|
|
484
|
-
const type = (cells[x] || cells[x - 1]).type;
|
|
485
|
-
cellsClone.splice(x, 0, createCell(type));
|
|
486
|
-
rows[y] = rowClone;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
deleteColumnAt(x) {
|
|
490
|
-
const self = this.getWritable();
|
|
491
|
-
const rows = self.__rows;
|
|
492
|
-
for (let y = 0; y < rows.length; y++) {
|
|
493
|
-
const row = rows[y];
|
|
494
|
-
const cells = row.cells;
|
|
495
|
-
const cellsClone = Array.from(cells);
|
|
496
|
-
const rowClone = { ...row, cells: cellsClone };
|
|
497
|
-
cellsClone.splice(x, 1);
|
|
498
|
-
rows[y] = rowClone;
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
addColumns(count) {
|
|
502
|
-
const self = this.getWritable();
|
|
503
|
-
const rows = self.__rows;
|
|
504
|
-
for (let y = 0; y < rows.length; y++) {
|
|
505
|
-
const row = rows[y];
|
|
506
|
-
const cells = row.cells;
|
|
507
|
-
const cellsClone = Array.from(cells);
|
|
508
|
-
const rowClone = { ...row, cells: cellsClone };
|
|
509
|
-
const type = cells[cells.length - 1].type;
|
|
510
|
-
for (let x = 0; x < count; x++) {
|
|
511
|
-
cellsClone.push(createCell(type));
|
|
512
|
-
}
|
|
513
|
-
rows[y] = rowClone;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
insertRowAt(y) {
|
|
517
|
-
const self = this.getWritable();
|
|
518
|
-
const rows = self.__rows;
|
|
519
|
-
const prevRow = rows[y] || rows[y - 1];
|
|
520
|
-
const cellCount = prevRow.cells.length;
|
|
521
|
-
const row = createRow();
|
|
522
|
-
for (let x = 0; x < cellCount; x++) {
|
|
523
|
-
const cell = createCell(prevRow.cells[x].type);
|
|
524
|
-
row.cells.push(cell);
|
|
525
|
-
}
|
|
526
|
-
rows.splice(y, 0, row);
|
|
527
|
-
}
|
|
528
|
-
deleteRowAt(y) {
|
|
529
|
-
const self = this.getWritable();
|
|
530
|
-
const rows = self.__rows;
|
|
531
|
-
rows.splice(y, 1);
|
|
532
|
-
}
|
|
533
|
-
addRows(count) {
|
|
534
|
-
const self = this.getWritable();
|
|
535
|
-
const rows = self.__rows;
|
|
536
|
-
const prevRow = rows[rows.length - 1];
|
|
537
|
-
const cellCount = prevRow.cells.length;
|
|
538
|
-
for (let y = 0; y < count; y++) {
|
|
539
|
-
const row = createRow();
|
|
540
|
-
for (let x = 0; x < cellCount; x++) {
|
|
541
|
-
const cell = createCell(prevRow.cells[x].type);
|
|
542
|
-
row.cells.push(cell);
|
|
543
|
-
}
|
|
544
|
-
rows.push(row);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
updateColumnWidth(x, width) {
|
|
548
|
-
const self = this.getWritable();
|
|
549
|
-
const rows = self.__rows;
|
|
550
|
-
for (let y = 0; y < rows.length; y++) {
|
|
551
|
-
const row = rows[y];
|
|
552
|
-
const cells = row.cells;
|
|
553
|
-
const cellsClone = Array.from(cells);
|
|
554
|
-
const rowClone = { ...row, cells: cellsClone };
|
|
555
|
-
cellsClone[x].width = width;
|
|
556
|
-
rows[y] = rowClone;
|
|
557
|
-
}
|
|
558
|
-
}
|
|
559
|
-
decorate(_, config) {
|
|
560
|
-
return /* @__PURE__ */ jsx7(Suspense, {
|
|
561
|
-
fallback: "...",
|
|
562
|
-
children: /* @__PURE__ */ jsx7(TableComponent, {
|
|
563
|
-
nodeKey: this.__key,
|
|
564
|
-
theme: config.theme,
|
|
565
|
-
rows: this.__rows
|
|
566
|
-
})
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
isInline() {
|
|
570
|
-
return false;
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
function $isTableNode(node) {
|
|
574
|
-
return node instanceof TableNode;
|
|
575
|
-
}
|
|
576
|
-
function $createTableNode(rows) {
|
|
577
|
-
return new TableNode(rows);
|
|
578
|
-
}
|
|
579
|
-
function $createTableNodeWithDimensions(rowCount, columnCount, includeHeaders = true) {
|
|
580
|
-
const rows = [];
|
|
581
|
-
for (let y = 0; y < columnCount; y++) {
|
|
582
|
-
const row = createRow();
|
|
583
|
-
rows.push(row);
|
|
584
|
-
for (let x = 0; x < rowCount; x++) {
|
|
585
|
-
row.cells.push(createCell(includeHeaders === true && (y === 0 || x === 0) ? "header" : "normal"));
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
return new TableNode(rows);
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
// src/rich-text-editor/plugins/TablePlugin.tsx
|
|
592
|
-
import { Fragment as Fragment2, jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
593
|
-
var INSERT_NEW_TABLE_COMMAND = createCommand("INSERT_NEW_TABLE_COMMAND");
|
|
594
|
-
var CellContext = createContext({
|
|
595
|
-
cellEditorConfig: null,
|
|
596
|
-
cellEditorPlugins: null,
|
|
597
|
-
set: () => {
|
|
598
|
-
}
|
|
599
|
-
});
|
|
600
|
-
function TableContext({ children }) {
|
|
601
|
-
const [contextValue, setContextValue] = useState({
|
|
602
|
-
cellEditorConfig: null,
|
|
603
|
-
cellEditorPlugins: null
|
|
604
|
-
});
|
|
605
|
-
return /* @__PURE__ */ jsx8(CellContext.Provider, {
|
|
606
|
-
value: useMemo(
|
|
607
|
-
() => ({
|
|
608
|
-
cellEditorConfig: contextValue.cellEditorConfig,
|
|
609
|
-
cellEditorPlugins: contextValue.cellEditorPlugins,
|
|
610
|
-
set: (cellEditorConfig, cellEditorPlugins) => {
|
|
611
|
-
setContextValue({ cellEditorConfig, cellEditorPlugins });
|
|
612
|
-
}
|
|
613
|
-
}),
|
|
614
|
-
[contextValue.cellEditorConfig, contextValue.cellEditorPlugins]
|
|
615
|
-
),
|
|
616
|
-
children
|
|
617
|
-
});
|
|
618
|
-
}
|
|
619
|
-
function InsertNewTableDialog({ activeEditor }) {
|
|
620
|
-
const [rows, setRows] = useState("5");
|
|
621
|
-
const [columns, setColumns] = useState("5");
|
|
622
|
-
const onClick = () => {
|
|
623
|
-
if (parseInt(rows) < 1 || parseInt(columns) < 1) {
|
|
624
|
-
return;
|
|
625
|
-
}
|
|
626
|
-
activeEditor.dispatchCommand(INSERT_NEW_TABLE_COMMAND, { columns, rows });
|
|
627
|
-
};
|
|
628
|
-
return /* @__PURE__ */ jsxs4(Fragment2, {
|
|
629
|
-
children: [
|
|
630
|
-
/* @__PURE__ */ jsxs4("div", {
|
|
631
|
-
className: "grid grid-cols-[1fr_1px_1fr] border border-gray-100-800 border-solid shadow-sm rounded-md ",
|
|
632
|
-
children: [
|
|
633
|
-
/* @__PURE__ */ jsx8(InputWithLabel, {
|
|
634
|
-
label: "Rows",
|
|
635
|
-
value: rows,
|
|
636
|
-
placeholder: "0",
|
|
637
|
-
type: "text",
|
|
638
|
-
inputMode: "numeric",
|
|
639
|
-
onChange: (e) => setRows(e.target.value)
|
|
640
|
-
}),
|
|
641
|
-
/* @__PURE__ */ jsx8("span", {
|
|
642
|
-
className: "h-full bg-gray-100-800"
|
|
643
|
-
}),
|
|
644
|
-
/* @__PURE__ */ jsx8(InputWithLabel, {
|
|
645
|
-
type: "text",
|
|
646
|
-
label: "Columns",
|
|
647
|
-
placeholder: "0",
|
|
648
|
-
value: columns,
|
|
649
|
-
inputMode: "numeric",
|
|
650
|
-
onChange: (e) => setColumns(e.target.value)
|
|
651
|
-
})
|
|
652
|
-
]
|
|
653
|
-
}),
|
|
654
|
-
/* @__PURE__ */ jsx8("div", {
|
|
655
|
-
className: "flex justify-end mt-3",
|
|
656
|
-
children: /* @__PURE__ */ jsx8(Button, {
|
|
657
|
-
size: "sm",
|
|
658
|
-
intent: "action",
|
|
659
|
-
"aria-label": "Confirm",
|
|
660
|
-
onClick,
|
|
661
|
-
children: "Confirm"
|
|
662
|
-
})
|
|
663
|
-
})
|
|
664
|
-
]
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
function TablePlugin({
|
|
668
|
-
cellEditorConfig,
|
|
669
|
-
children
|
|
670
|
-
}) {
|
|
671
|
-
const [editor] = useLexicalComposerContext();
|
|
672
|
-
const cellContext = useContext(CellContext);
|
|
673
|
-
useEffect(() => {
|
|
674
|
-
if (!editor.hasNodes([TableNode])) {
|
|
675
|
-
throw new Error("TablePlugin: TableNode is not registered on editor");
|
|
676
|
-
}
|
|
677
|
-
cellContext.set(cellEditorConfig, children);
|
|
678
|
-
return editor.registerCommand(
|
|
679
|
-
INSERT_NEW_TABLE_COMMAND,
|
|
680
|
-
({ columns, rows, includeHeaders }) => {
|
|
681
|
-
const selection = $getSelection();
|
|
682
|
-
if (!$isRangeSelection(selection)) {
|
|
683
|
-
return true;
|
|
684
|
-
}
|
|
685
|
-
const focus = selection.focus;
|
|
686
|
-
const focusNode = focus.getNode();
|
|
687
|
-
if (focusNode !== null) {
|
|
688
|
-
const tableNode = $createTableNodeWithDimensions(Number(rows), Number(columns), includeHeaders);
|
|
689
|
-
if ($isRootOrShadowRoot(focusNode)) {
|
|
690
|
-
const target = focusNode.getChildAtIndex(focus.offset);
|
|
691
|
-
if (target !== null) {
|
|
692
|
-
target.insertBefore(tableNode);
|
|
693
|
-
} else {
|
|
694
|
-
focusNode.append(tableNode);
|
|
695
|
-
}
|
|
696
|
-
tableNode.insertBefore($createParagraphNode());
|
|
697
|
-
} else {
|
|
698
|
-
const topLevelNode = focusNode.getTopLevelElementOrThrow();
|
|
699
|
-
topLevelNode.insertAfter(tableNode);
|
|
700
|
-
}
|
|
701
|
-
tableNode.insertAfter($createParagraphNode());
|
|
702
|
-
const nodeSelection = $createNodeSelection();
|
|
703
|
-
nodeSelection.add(tableNode.getKey());
|
|
704
|
-
$setSelection(nodeSelection);
|
|
705
|
-
}
|
|
706
|
-
return true;
|
|
707
|
-
},
|
|
708
|
-
COMMAND_PRIORITY_EDITOR
|
|
709
|
-
);
|
|
710
|
-
}, [cellContext, cellEditorConfig, children, editor]);
|
|
711
|
-
return null;
|
|
712
|
-
}
|
|
713
|
-
|
|
714
|
-
// src/rich-text-editor/utils/environment.ts
|
|
715
|
-
var IS_APPLE = typeof navigator !== "undefined" && /Mac|iPod|iPhone|iPad/.test(navigator.platform);
|
|
716
|
-
|
|
717
|
-
export {
|
|
718
|
-
Spinner,
|
|
719
|
-
buttonTokens,
|
|
720
|
-
Button,
|
|
721
|
-
Input,
|
|
722
|
-
Label,
|
|
723
|
-
InputWithLabel,
|
|
724
|
-
CellContext,
|
|
725
|
-
TableContext,
|
|
726
|
-
InsertNewTableDialog,
|
|
727
|
-
TablePlugin,
|
|
728
|
-
IS_APPLE,
|
|
729
|
-
cellHTMLCache,
|
|
730
|
-
cellTextContentCache,
|
|
731
|
-
createUID,
|
|
732
|
-
createRow,
|
|
733
|
-
extractRowsFromHTML,
|
|
734
|
-
exportTableCellsToHTML,
|
|
735
|
-
TableNode,
|
|
736
|
-
$isTableNode
|
|
737
|
-
};
|