@bettercms-ai/kit 4.0.0 → 4.1.1
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/dist/adapters/lossy.d.ts +4 -0
- package/dist/adapters/lossy.js +4 -0
- package/dist/adapters/lossy.js.map +1 -1
- package/dist/adapters/prod-types.d.ts +4 -0
- package/dist/adapters/prod-types.js +4 -1
- package/dist/adapters/prod-types.js.map +1 -1
- package/dist/adapters/schema.js +7 -0
- package/dist/adapters/schema.js.map +1 -1
- package/dist/context.d.ts +83 -0
- package/dist/context.js +58 -1
- package/dist/context.js.map +1 -1
- package/dist/controls/choice.d.ts +1 -1
- package/dist/controls/choice.js +21 -2
- package/dist/controls/choice.js.map +1 -1
- package/dist/controls/index.d.ts +1 -0
- package/dist/controls/index.js +3 -2
- package/dist/controls/index.js.map +1 -1
- package/dist/controls/link.d.ts +23 -2
- package/dist/controls/link.js +456 -4
- package/dist/controls/link.js.map +1 -1
- package/dist/controls/media-v16.d.ts +27 -0
- package/dist/controls/media-v16.js +261 -0
- package/dist/controls/media-v16.js.map +1 -0
- package/dist/controls/media.js +63 -1
- package/dist/controls/media.js.map +1 -1
- package/dist/controls/reference-services.d.ts +8 -0
- package/dist/controls/reference.js +78 -2
- package/dist/controls/reference.js.map +1 -1
- package/dist/controls/rich-text/ai-runs.d.ts +13 -0
- package/dist/controls/rich-text/ai-runs.js +71 -0
- package/dist/controls/rich-text/ai-runs.js.map +1 -0
- package/dist/controls/rich-text/block-tool.d.ts +31 -0
- package/dist/controls/rich-text/block-tool.js +62 -0
- package/dist/controls/rich-text/block-tool.js.map +1 -0
- package/dist/controls/rich-text/blocks.d.ts +6 -1
- package/dist/controls/rich-text/blocks.js +404 -24
- package/dist/controls/rich-text/blocks.js.map +1 -1
- package/dist/controls/rich-text/catalog.d.ts +21 -6
- package/dist/controls/rich-text/catalog.js +312 -23
- package/dist/controls/rich-text/catalog.js.map +1 -1
- package/dist/controls/rich-text/code-head.d.ts +30 -0
- package/dist/controls/rich-text/code-head.js +230 -0
- package/dist/controls/rich-text/code-head.js.map +1 -0
- package/dist/controls/rich-text/codec.d.ts +1 -1
- package/dist/controls/rich-text/codec.js +3 -1
- package/dist/controls/rich-text/codec.js.map +1 -1
- package/dist/controls/rich-text/dom.d.ts +27 -0
- package/dist/controls/rich-text/dom.js +69 -4
- package/dist/controls/rich-text/dom.js.map +1 -1
- package/dist/controls/rich-text/editor.js +212 -50
- package/dist/controls/rich-text/editor.js.map +1 -1
- package/dist/controls/rich-text/ops.js +1 -0
- package/dist/controls/rich-text/ops.js.map +1 -1
- package/dist/controls/rich-text/slash-preview.d.ts +8 -0
- package/dist/controls/rich-text/slash-preview.js +287 -0
- package/dist/controls/rich-text/slash-preview.js.map +1 -0
- package/dist/controls/rich-text/table-grid.d.ts +22 -0
- package/dist/controls/rich-text/table-grid.js +1052 -0
- package/dist/controls/rich-text/table-grid.js.map +1 -0
- package/dist/controls/rich-text/toolbar.js +60 -18
- package/dist/controls/rich-text/toolbar.js.map +1 -1
- package/dist/controls/text.d.ts +6 -0
- package/dist/controls/text.js +95 -5
- package/dist/controls/text.js.map +1 -1
- package/dist/core/facets.d.ts +1 -0
- package/dist/core/facets.js +1 -0
- package/dist/core/facets.js.map +1 -1
- package/dist/engine/array.d.ts +7 -0
- package/dist/engine/array.js +164 -45
- package/dist/engine/array.js.map +1 -1
- package/dist/engine/field-shell.d.ts +12 -0
- package/dist/engine/field-shell.js +217 -63
- package/dist/engine/field-shell.js.map +1 -1
- package/dist/engine/frame.js +39 -2
- package/dist/engine/frame.js.map +1 -1
- package/dist/engine/grouping.d.ts +71 -10
- package/dist/engine/grouping.js +223 -26
- package/dist/engine/grouping.js.map +1 -1
- package/dist/engine/kit-field.js +38 -4
- package/dist/engine/kit-field.js.map +1 -1
- package/dist/engine/schema-form.js +7 -2
- package/dist/engine/schema-form.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/kit.css +85 -0
- package/dist/schema/table.d.ts +2 -1
- package/dist/schema/table.js +5 -0
- package/dist/schema/table.js.map +1 -1
- package/dist/schema/types.d.ts +6 -0
- package/dist/schema/types.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/theme.css +115 -0
- package/dist/tokens.css +268 -0
- package/dist/ui/block-icon-picker.d.ts +38 -0
- package/dist/ui/block-icon-picker.js +141 -0
- package/dist/ui/block-icon-picker.js.map +1 -0
- package/dist/ui/button.js +1 -0
- package/dist/ui/button.js.map +1 -1
- package/dist/ui/code-language-menu.d.ts +24 -0
- package/dist/ui/code-language-menu.js +123 -0
- package/dist/ui/code-language-menu.js.map +1 -0
- package/dist/ui/content-fields.d.ts +47 -0
- package/dist/ui/content-fields.js +278 -0
- package/dist/ui/content-fields.js.map +1 -0
- package/dist/ui/foundations.d.ts +118 -0
- package/dist/ui/foundations.js +564 -0
- package/dist/ui/foundations.js.map +1 -0
- package/dist/ui/index.d.ts +6 -0
- package/dist/ui/index.js +7 -1
- package/dist/ui/inspector.d.ts +394 -0
- package/dist/ui/inspector.js +1173 -0
- package/dist/ui/inspector.js.map +1 -0
- package/dist/ui/overlay.d.ts +7 -2
- package/dist/ui/overlay.js +55 -20
- package/dist/ui/overlay.js.map +1 -1
- package/dist/ui/shortcut-hint.js +1 -1
- package/dist/ui/shortcut-hint.js.map +1 -1
- package/dist/ui/toast.d.ts +5 -3
- package/dist/ui/toast.js +83 -11
- package/dist/ui/toast.js.map +1 -1
- package/dist/ui/tooltip-card.d.ts +45 -0
- package/dist/ui/tooltip-card.js +135 -0
- package/dist/ui/tooltip-card.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1052 @@
|
|
|
1
|
+
import { cellNote, cellText, cellType, cellValue, isObjLike, orderedRows, tkey, withValue } from "../../schema/table.js";
|
|
2
|
+
import { cn } from "../../lib/cn.js";
|
|
3
|
+
import { Menu, MenuContent, MenuItem, MenuLabel, MenuSeparator, MenuTrigger, Modal, ModalBody, ModalContent, ModalHeader } from "../../ui/overlay.js";
|
|
4
|
+
import { Textarea } from "../../ui/input.js";
|
|
5
|
+
import { TableEditor, moveRowTo, typedCell } from "../table/table-editor.js";
|
|
6
|
+
import { placeCaret } from "./dom.js";
|
|
7
|
+
import * as React from "react";
|
|
8
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { IconAdjustmentsHorizontal, IconTrash, IconX } from "@tabler/icons-react";
|
|
10
|
+
import { AnimatePresence, motion } from "framer-motion";
|
|
11
|
+
//#region src/controls/rich-text/table-grid.tsx
|
|
12
|
+
/**
|
|
13
|
+
* The table block of prototype editor-v16, drawn in place (look "v16"; content.jsx:1051-1195 BlockOverlay,
|
|
14
|
+
* content.css:344-347, 387-397, 441-444, 651-653, 675-684, 817-824).
|
|
15
|
+
*
|
|
16
|
+
* The island still holds the kit's table value (`TableValue`, schema/table.ts): this file only changes how it is
|
|
17
|
+
* edited. Nothing is added to the stored shape. What the grid does not draw (caption, note, footnotes, row group
|
|
18
|
+
* headings, column types and their settings, highlights, the JSON-LD and phone settings) stays in the value untouched.
|
|
19
|
+
*
|
|
20
|
+
* - the table: cells 9 / 12, hairline borders, header cells grey 13 / 500, min 80 wide, at least 60% of the body
|
|
21
|
+
* - hover: "Add column" dots above each inner column border and "Add row" dots left of each inner row border
|
|
22
|
+
* (18 round, a 5 dot that turns into a + on a white disc), with a 2 violet guide that draws from the edge and glides
|
|
23
|
+
* between dots; a "Column actions" chip above the hovered column and a "Row actions" chip left of the hovered row
|
|
24
|
+
* (drag 4 or more to move with a drop line and a tinted source, click for the menu)
|
|
25
|
+
* - caret in a cell: the 36 high toolbar 52 above the table: Header row · Add row below · Add column right ·
|
|
26
|
+
* Center text · Delete table
|
|
27
|
+
*
|
|
28
|
+
* Editing the grid does not draw (kept from the kit's table editor, so the v16 look hides nothing that works today):
|
|
29
|
+
* the caption above the table and the note under it are edited in place; the footnotes are listed under the note
|
|
30
|
+
* (text edited in place, ✕ removes one and the cell marks naming it); "Table settings" (cell toolbar, and the
|
|
31
|
+
* column / row menus as "Column type and settings…" / "Row group and settings…") opens the full table editor in a
|
|
32
|
+
* dialog for column types and their settings, row groups, totals, highlights, footnote marks, search and phones.
|
|
33
|
+
*
|
|
34
|
+
* "Fit to width" stores `design.fit` (REQ-KIT-3, written `data-fit="true"`): the table spans the column.
|
|
35
|
+
*/
|
|
36
|
+
/** Rows as the table shows them (ungrouped, then each row group, then the totals): the grid's row order. */
|
|
37
|
+
function gridRows(t) {
|
|
38
|
+
const { bodies, foot } = orderedRows(t);
|
|
39
|
+
return [...bodies.flatMap((b) => b.rows), ...foot];
|
|
40
|
+
}
|
|
41
|
+
/** Footnotes no cell names any more go with the row or column that named them. */
|
|
42
|
+
function pruneNotes(t) {
|
|
43
|
+
if (!t.footnotes?.length) return t;
|
|
44
|
+
const used = /* @__PURE__ */ new Set();
|
|
45
|
+
for (const r of t.rows) for (const c of Object.values(r.cells)) {
|
|
46
|
+
const n = cellNote(c);
|
|
47
|
+
if (n) used.add(n);
|
|
48
|
+
}
|
|
49
|
+
const footnotes = t.footnotes.filter((f) => used.has(f._key));
|
|
50
|
+
return footnotes.length === t.footnotes.length ? t : {
|
|
51
|
+
...t,
|
|
52
|
+
footnotes
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/** Remove footnote `key` and every cell mark that names it. */
|
|
56
|
+
function gridDeleteFootnote(t, key) {
|
|
57
|
+
return {
|
|
58
|
+
...t,
|
|
59
|
+
footnotes: (t.footnotes ?? []).filter((f) => f._key !== key),
|
|
60
|
+
rows: t.rows.map((r) => {
|
|
61
|
+
let hit = false;
|
|
62
|
+
const cells = Object.fromEntries(Object.entries(r.cells).map(([k, c]) => {
|
|
63
|
+
if (!c || !isObjLike(c) || cellNote(c) !== key) return [k, c];
|
|
64
|
+
hit = true;
|
|
65
|
+
const { note: _note, ...rest } = c;
|
|
66
|
+
return [k, rest];
|
|
67
|
+
}));
|
|
68
|
+
return hit ? {
|
|
69
|
+
...r,
|
|
70
|
+
cells
|
|
71
|
+
} : r;
|
|
72
|
+
})
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/** Write one footnote's text. */
|
|
76
|
+
var gridFootnoteText = (t, key, text) => ({
|
|
77
|
+
...t,
|
|
78
|
+
footnotes: (t.footnotes ?? []).map((f) => f._key === key ? {
|
|
79
|
+
...f,
|
|
80
|
+
text
|
|
81
|
+
} : f)
|
|
82
|
+
});
|
|
83
|
+
/** A new column at `at`; with the header row on its header says "Column" (content.jsx:1093). */
|
|
84
|
+
function gridInsertColumn(t, at) {
|
|
85
|
+
const col = {
|
|
86
|
+
_key: tkey("c"),
|
|
87
|
+
label: t.headerRow ? "Column" : "",
|
|
88
|
+
type: "text"
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
...t,
|
|
92
|
+
columns: [
|
|
93
|
+
...t.columns.slice(0, at),
|
|
94
|
+
col,
|
|
95
|
+
...t.columns.slice(at)
|
|
96
|
+
]
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function gridMoveColumn(t, from, to) {
|
|
100
|
+
if (from === to || from < 0 || to < 0 || from >= t.columns.length || to >= t.columns.length) return t;
|
|
101
|
+
const columns = t.columns.slice();
|
|
102
|
+
const [c] = columns.splice(from, 1);
|
|
103
|
+
columns.splice(to, 0, c);
|
|
104
|
+
return {
|
|
105
|
+
...t,
|
|
106
|
+
columns
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function gridDeleteColumn(t, at) {
|
|
110
|
+
const key = t.columns[at]?._key;
|
|
111
|
+
if (!key) return t;
|
|
112
|
+
return pruneNotes({
|
|
113
|
+
...t,
|
|
114
|
+
columns: t.columns.filter((c) => c._key !== key),
|
|
115
|
+
rows: t.rows.map((r) => key in r.cells ? {
|
|
116
|
+
...r,
|
|
117
|
+
cells: Object.fromEntries(Object.entries(r.cells).filter(([k]) => k !== key))
|
|
118
|
+
} : r)
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
/** An empty row at shown position `at`; it joins the row group (or the totals) of the row it is added next to. */
|
|
122
|
+
function gridInsertRow(t, at, above = false) {
|
|
123
|
+
const order = gridRows(t);
|
|
124
|
+
const near = above ? order[at] : order[at - 1] ?? order[at];
|
|
125
|
+
const row = {
|
|
126
|
+
_key: tkey("r"),
|
|
127
|
+
cells: {},
|
|
128
|
+
...near?.group ? { group: near.group } : {},
|
|
129
|
+
...near?.footer ? { footer: true } : {}
|
|
130
|
+
};
|
|
131
|
+
return {
|
|
132
|
+
...t,
|
|
133
|
+
rows: [
|
|
134
|
+
...order.slice(0, at),
|
|
135
|
+
row,
|
|
136
|
+
...order.slice(at)
|
|
137
|
+
]
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function gridDeleteRow(t, at) {
|
|
141
|
+
const order = gridRows(t);
|
|
142
|
+
return pruneNotes({
|
|
143
|
+
...t,
|
|
144
|
+
rows: order.filter((_, i) => i !== at)
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
/** "Center text": every column centred, or back to each column's own default. */
|
|
148
|
+
var gridCentered = (t) => t.columns.length > 0 && t.columns.every((c) => c.align === "center");
|
|
149
|
+
function gridToggleCenter(t) {
|
|
150
|
+
const on = gridCentered(t);
|
|
151
|
+
return {
|
|
152
|
+
...t,
|
|
153
|
+
columns: t.columns.map((c) => {
|
|
154
|
+
if (!on) return {
|
|
155
|
+
...c,
|
|
156
|
+
align: "center"
|
|
157
|
+
};
|
|
158
|
+
const { align: _align, ...rest } = c;
|
|
159
|
+
return rest;
|
|
160
|
+
})
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
var TI = {
|
|
164
|
+
header: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("rect", {
|
|
165
|
+
x: "3",
|
|
166
|
+
y: "3",
|
|
167
|
+
width: "18",
|
|
168
|
+
height: "18",
|
|
169
|
+
rx: "2"
|
|
170
|
+
}), /* @__PURE__ */ jsx("path", { d: "M3 9h18" })] }),
|
|
171
|
+
row: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
172
|
+
/* @__PURE__ */ jsx("rect", {
|
|
173
|
+
x: "3",
|
|
174
|
+
y: "3",
|
|
175
|
+
width: "13",
|
|
176
|
+
height: "7",
|
|
177
|
+
rx: "1"
|
|
178
|
+
}),
|
|
179
|
+
/* @__PURE__ */ jsx("path", { d: "m22 15-3-3 3-3" }),
|
|
180
|
+
/* @__PURE__ */ jsx("rect", {
|
|
181
|
+
x: "3",
|
|
182
|
+
y: "14",
|
|
183
|
+
width: "13",
|
|
184
|
+
height: "7",
|
|
185
|
+
rx: "1"
|
|
186
|
+
})
|
|
187
|
+
] }),
|
|
188
|
+
col: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
189
|
+
/* @__PURE__ */ jsx("rect", {
|
|
190
|
+
x: "3",
|
|
191
|
+
y: "3",
|
|
192
|
+
width: "7",
|
|
193
|
+
height: "13",
|
|
194
|
+
rx: "1"
|
|
195
|
+
}),
|
|
196
|
+
/* @__PURE__ */ jsx("path", { d: "m9 22 3-3 3 3" }),
|
|
197
|
+
/* @__PURE__ */ jsx("rect", {
|
|
198
|
+
x: "14",
|
|
199
|
+
y: "3",
|
|
200
|
+
width: "7",
|
|
201
|
+
height: "13",
|
|
202
|
+
rx: "1"
|
|
203
|
+
})
|
|
204
|
+
] }),
|
|
205
|
+
center: /* @__PURE__ */ jsx("path", { d: "M15 12H3M17 18H3M21 6H3" }),
|
|
206
|
+
fit: /* @__PURE__ */ jsx("path", { d: "m18 8 4 4-4 4M2 12h20m-16-4-4 4 4 4" }),
|
|
207
|
+
more: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
208
|
+
/* @__PURE__ */ jsx("circle", {
|
|
209
|
+
cx: "5",
|
|
210
|
+
cy: "12",
|
|
211
|
+
r: "1"
|
|
212
|
+
}),
|
|
213
|
+
/* @__PURE__ */ jsx("circle", {
|
|
214
|
+
cx: "12",
|
|
215
|
+
cy: "12",
|
|
216
|
+
r: "1"
|
|
217
|
+
}),
|
|
218
|
+
/* @__PURE__ */ jsx("circle", {
|
|
219
|
+
cx: "19",
|
|
220
|
+
cy: "12",
|
|
221
|
+
r: "1"
|
|
222
|
+
})
|
|
223
|
+
] }),
|
|
224
|
+
plus: /* @__PURE__ */ jsx("path", { d: "M5 12h14M12 5v14" }),
|
|
225
|
+
insL: /* @__PURE__ */ jsx("path", { d: "M3 19V5M13 6l-6 6 6 6M7 12h14" }),
|
|
226
|
+
insR: /* @__PURE__ */ jsx("path", { d: "M17 12H3M11 18l6-6-6-6M21 5v14" }),
|
|
227
|
+
insA: /* @__PURE__ */ jsx("path", { d: "M5 3h14M18 13l-6-6-6 6M12 7v14" }),
|
|
228
|
+
insB: /* @__PURE__ */ jsx("path", { d: "M19 21H5M6 11l6 6 6-6M12 17V3" }),
|
|
229
|
+
up: /* @__PURE__ */ jsx("path", { d: "M12 19V5M5 12l7-7 7 7" }),
|
|
230
|
+
down: /* @__PURE__ */ jsx("path", { d: "M12 5v14M19 12l-7 7-7-7" }),
|
|
231
|
+
mvL: /* @__PURE__ */ jsx("path", { d: "M19 12H5M12 19l-7-7 7-7" }),
|
|
232
|
+
mvR: /* @__PURE__ */ jsx("path", { d: "M5 12h14M12 5l7 7-7 7" })
|
|
233
|
+
};
|
|
234
|
+
var Ti = ({ n, className }) => /* @__PURE__ */ jsx("svg", {
|
|
235
|
+
width: "14",
|
|
236
|
+
height: "14",
|
|
237
|
+
viewBox: "0 0 24 24",
|
|
238
|
+
fill: "none",
|
|
239
|
+
stroke: "currentColor",
|
|
240
|
+
strokeWidth: "2",
|
|
241
|
+
strokeLinecap: "round",
|
|
242
|
+
strokeLinejoin: "round",
|
|
243
|
+
"aria-hidden": true,
|
|
244
|
+
className,
|
|
245
|
+
children: TI[n]
|
|
246
|
+
});
|
|
247
|
+
/**
|
|
248
|
+
* One cell as a plain text box. `shown` is what it says at rest (a number with its unit), `raw` what it says while
|
|
249
|
+
* edited. `live` writes on every keystroke (words); otherwise the cell is read once, on blur (a number, a yes / no).
|
|
250
|
+
*/
|
|
251
|
+
function GridText({ shown, raw = shown, live, readOnly, label, onCommit, onEnter, at, className }) {
|
|
252
|
+
const ref = React.useRef(null);
|
|
253
|
+
const focused = React.useRef(false);
|
|
254
|
+
/** what the box holds: its own typing, or the last text written into it */
|
|
255
|
+
const held = React.useRef(null);
|
|
256
|
+
React.useLayoutEffect(() => {
|
|
257
|
+
const el = ref.current;
|
|
258
|
+
if (!el) return;
|
|
259
|
+
const want = focused.current ? raw : shown;
|
|
260
|
+
if (focused.current && want === held.current) return;
|
|
261
|
+
held.current = want;
|
|
262
|
+
if (el.textContent === want) return;
|
|
263
|
+
el.textContent = want;
|
|
264
|
+
if (focused.current) placeCaret(el);
|
|
265
|
+
}, [shown, raw]);
|
|
266
|
+
const text = (el) => (el.textContent ?? "").replace(//g, "");
|
|
267
|
+
return /* @__PURE__ */ jsx("div", {
|
|
268
|
+
ref,
|
|
269
|
+
role: "textbox",
|
|
270
|
+
"aria-label": label,
|
|
271
|
+
"aria-readonly": readOnly || void 0,
|
|
272
|
+
tabIndex: readOnly ? -1 : 0,
|
|
273
|
+
"data-tg-cell": at,
|
|
274
|
+
contentEditable: readOnly ? false : "plaintext-only",
|
|
275
|
+
suppressContentEditableWarning: true,
|
|
276
|
+
spellCheck: true,
|
|
277
|
+
onFocus: (e) => {
|
|
278
|
+
focused.current = true;
|
|
279
|
+
if (raw !== shown && text(e.currentTarget) !== raw) {
|
|
280
|
+
e.currentTarget.textContent = raw;
|
|
281
|
+
placeCaret(e.currentTarget);
|
|
282
|
+
}
|
|
283
|
+
held.current = text(e.currentTarget);
|
|
284
|
+
},
|
|
285
|
+
onBlur: (e) => {
|
|
286
|
+
focused.current = false;
|
|
287
|
+
if (live || readOnly) return;
|
|
288
|
+
const typed = text(e.currentTarget);
|
|
289
|
+
e.currentTarget.textContent = shown;
|
|
290
|
+
held.current = shown;
|
|
291
|
+
if (typed !== raw) onCommit(typed);
|
|
292
|
+
},
|
|
293
|
+
onInput: (e) => {
|
|
294
|
+
held.current = text(e.currentTarget);
|
|
295
|
+
if (live) onCommit(held.current);
|
|
296
|
+
},
|
|
297
|
+
onPaste: (e) => {
|
|
298
|
+
e.preventDefault();
|
|
299
|
+
document.execCommand("insertText", false, e.clipboardData.getData("text/plain").replace(/\s*\n\s*/g, " "));
|
|
300
|
+
},
|
|
301
|
+
onKeyDown: (e) => {
|
|
302
|
+
if (e.key !== "Enter" || e.nativeEvent.isComposing) return;
|
|
303
|
+
e.preventDefault();
|
|
304
|
+
onEnter();
|
|
305
|
+
},
|
|
306
|
+
className: cn("min-h-5 min-w-0 cursor-text whitespace-pre-wrap break-words outline-none focus-visible:shadow-none", className)
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
/** What a body cell says at rest and while edited, and whether its words are written as typed. */
|
|
310
|
+
function cellEdit(col, row, cell) {
|
|
311
|
+
const v = cellValue(cell);
|
|
312
|
+
const type = cellType(col, row, cell);
|
|
313
|
+
const said = cellText(col, row, cell);
|
|
314
|
+
if (type === "reference" || type === "richtext-inline" && typeof v === "string" && /<[a-z!/]/i.test(v)) return {
|
|
315
|
+
shown: said,
|
|
316
|
+
raw: said,
|
|
317
|
+
live: false,
|
|
318
|
+
locked: true
|
|
319
|
+
};
|
|
320
|
+
const columnType = row.type ?? col.type;
|
|
321
|
+
if ((type === "text" || type === "richtext-inline") && type === columnType) {
|
|
322
|
+
const s = typeof v === "string" ? v : said;
|
|
323
|
+
return {
|
|
324
|
+
shown: s,
|
|
325
|
+
raw: s,
|
|
326
|
+
live: true,
|
|
327
|
+
locked: false
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
if (type === "number" || type === "money" || type === "rating") return {
|
|
331
|
+
shown: said,
|
|
332
|
+
raw: typeof v === "number" ? String(v) : said,
|
|
333
|
+
live: false,
|
|
334
|
+
locked: false
|
|
335
|
+
};
|
|
336
|
+
if (type === "link") return {
|
|
337
|
+
shown: said,
|
|
338
|
+
raw: isObjLike(v) ? String(v.label ?? "") : said,
|
|
339
|
+
live: false,
|
|
340
|
+
locked: false
|
|
341
|
+
};
|
|
342
|
+
return {
|
|
343
|
+
shown: said,
|
|
344
|
+
raw: said,
|
|
345
|
+
live: false,
|
|
346
|
+
locked: false
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
function measure(t) {
|
|
350
|
+
const box = t.getBoundingClientRect();
|
|
351
|
+
const rows = Array.from(t.rows);
|
|
352
|
+
const first = rows[0] ? Array.from(rows[0].cells) : [];
|
|
353
|
+
return {
|
|
354
|
+
cols: first.slice(0, -1).map((c) => c.getBoundingClientRect().right - box.left),
|
|
355
|
+
mids: first.map((c) => {
|
|
356
|
+
const b = c.getBoundingClientRect();
|
|
357
|
+
return b.left - box.left + b.width / 2;
|
|
358
|
+
}),
|
|
359
|
+
rows: rows.slice(0, -1).map((r) => r.getBoundingClientRect().bottom - box.top),
|
|
360
|
+
rmids: rows.map((r) => {
|
|
361
|
+
const b = r.getBoundingClientRect();
|
|
362
|
+
return b.top - box.top + b.height / 2;
|
|
363
|
+
})
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
var sameGeo = (a, b) => !!a && [
|
|
367
|
+
"cols",
|
|
368
|
+
"mids",
|
|
369
|
+
"rows",
|
|
370
|
+
"rmids"
|
|
371
|
+
].every((k) => a[k].length === b[k].length && a[k].every((x, i) => Math.abs(x - b[k][i]) < .5));
|
|
372
|
+
var CELL = "min-w-20 border border-kit-insp-line px-3 py-[9px] align-top";
|
|
373
|
+
var HEAD_CELL = "bg-[var(--kit-insp-table-head)] text-[13px] font-medium text-[var(--kit-insp-table-head-fg)]";
|
|
374
|
+
var POP = "opacity_160ms_cubic-bezier(.22,1,.36,1),transform_260ms_cubic-bezier(.34,1.56,.64,1),filter_160ms_cubic-bezier(.22,1,.36,1)";
|
|
375
|
+
var DOT = cn("group/dt pointer-events-auto absolute grid size-[18px] place-items-center rounded-full text-kit-insp-btool-icon outline-none", "before:absolute before:z-[1] before:size-[5px] before:rounded-full before:bg-kit-insp-faint before:[transition:opacity_120ms_cubic-bezier(.22,1,.36,1),transform_120ms_cubic-bezier(.22,1,.36,1)]", "hover:before:scale-[.4] hover:before:opacity-0 focus-visible:before:scale-[.4] focus-visible:before:opacity-0", `after:absolute after:inset-0 after:scale-[.6] after:rounded-full after:bg-kit-insp-btool-bg after:opacity-0 after:blur-[4px] after:shadow-[inset_0_0_0_1px_var(--kit-insp-btool-line),0_1px_3px_rgb(0_0_0/0.1)] after:[transition:${POP}]`, "hover:after:scale-100 hover:after:opacity-100 hover:after:blur-none focus-visible:after:scale-100 focus-visible:after:opacity-100 focus-visible:after:blur-none");
|
|
376
|
+
var DOT_ICON = `relative z-[2] size-3 scale-[.6] opacity-0 blur-[4px] [transition:${POP}] group-hover/dt:scale-100 group-hover/dt:opacity-100 group-hover/dt:blur-none group-focus-visible/dt:scale-100 group-focus-visible/dt:opacity-100 group-focus-visible/dt:blur-none`;
|
|
377
|
+
var HANDLE = "pointer-events-auto absolute grid cursor-grab touch-none place-items-center rounded-[4px] bg-kit-insp-btool-bg text-kit-insp-btool-icon shadow-[inset_0_0_0_1px_var(--kit-insp-btool-line),0_1px_2px_rgb(0_0_0/0.06)] outline-none hover:bg-kit-insp-btool-hover focus-visible:shadow-[inset_0_0_0_1px_var(--kit-insp-btool-line),0_0_0_2px_var(--kit-focus-ring)] active:cursor-grabbing data-[popup-open]:bg-kit-insp-btool-hover";
|
|
378
|
+
var GUIDE = "pointer-events-none absolute bg-[var(--kit-insp-table-guide)]";
|
|
379
|
+
var TOOL_BTN = "grid size-7 shrink-0 place-items-center rounded-[6px] text-kit-insp-btool-icon outline-none transition-colors duration-100 hover:bg-kit-insp-btool-hover focus-visible:shadow-[0_0_0_2px_var(--kit-focus-ring)] aria-pressed:bg-kit-insp-btool-hover";
|
|
380
|
+
var MENU = "w-[220px] min-w-[220px]";
|
|
381
|
+
/** The v16 table block. `m` is the island's table value; every edit goes through `set` (one undo history). */
|
|
382
|
+
function TableGridV16({ m, set, el, ctx, autoFocus, options }) {
|
|
383
|
+
const ro = !!ctx.readOnly;
|
|
384
|
+
/** the full table editor in a dialog: the settings the grid does not draw */
|
|
385
|
+
const [settings, setSettings] = React.useState(false);
|
|
386
|
+
const wrap = React.useRef(null);
|
|
387
|
+
const table = React.useRef(null);
|
|
388
|
+
const rows = React.useMemo(() => gridRows(m), [m]);
|
|
389
|
+
/** drawn rows before the body: the header row */
|
|
390
|
+
const h = m.headerRow ? 1 : 0;
|
|
391
|
+
const drawn = rows.length + h;
|
|
392
|
+
const [geo, setGeo] = React.useState(null);
|
|
393
|
+
const [over, setOver] = React.useState(false);
|
|
394
|
+
const [hcol, setHcol] = React.useState(null);
|
|
395
|
+
const [hrow, setHrow] = React.useState(null);
|
|
396
|
+
const [dot, setDot] = React.useState(null);
|
|
397
|
+
const [menu, setMenu] = React.useState(null);
|
|
398
|
+
const [drag, setDrag] = React.useState(null);
|
|
399
|
+
const [drop, setDrop] = React.useState(null);
|
|
400
|
+
/** the cell holding the caret, as drawn [row, column] */
|
|
401
|
+
const [sel, setSel] = React.useState(null);
|
|
402
|
+
const leaveT = React.useRef(void 0);
|
|
403
|
+
const dotT = React.useRef(void 0);
|
|
404
|
+
/** a menu is open or a drag runs: the chips stay where they are while the pointer is away */
|
|
405
|
+
const busy = React.useRef(false);
|
|
406
|
+
busy.current = !!menu || !!drag;
|
|
407
|
+
React.useLayoutEffect(() => {
|
|
408
|
+
const t = table.current;
|
|
409
|
+
if (!t) return;
|
|
410
|
+
const run = () => {
|
|
411
|
+
const g = measure(t);
|
|
412
|
+
setGeo((p) => sameGeo(p, g) ? p : g);
|
|
413
|
+
};
|
|
414
|
+
run();
|
|
415
|
+
if (typeof ResizeObserver === "undefined") return;
|
|
416
|
+
const obs = new ResizeObserver(run);
|
|
417
|
+
obs.observe(t);
|
|
418
|
+
return () => obs.disconnect();
|
|
419
|
+
}, [m]);
|
|
420
|
+
React.useEffect(() => () => {
|
|
421
|
+
clearTimeout(leaveT.current);
|
|
422
|
+
clearTimeout(dotT.current);
|
|
423
|
+
}, []);
|
|
424
|
+
const focusCell = React.useCallback((r, c) => {
|
|
425
|
+
const cell = wrap.current?.querySelector(`[data-tg-cell="${r}:${c}"]`);
|
|
426
|
+
if (!cell) return false;
|
|
427
|
+
cell.focus();
|
|
428
|
+
placeCaret(cell);
|
|
429
|
+
return true;
|
|
430
|
+
}, []);
|
|
431
|
+
React.useEffect(() => {
|
|
432
|
+
if (autoFocus && !ro) focusCell(0, 0);
|
|
433
|
+
}, []);
|
|
434
|
+
const removeTable = () => ctx.remove(el, "Table deleted");
|
|
435
|
+
const addCol = (at) => set((t) => gridInsertColumn(t, at), "Add column");
|
|
436
|
+
const addRow = (at, above = false) => set((t) => gridInsertRow(t, at, above), "Add row");
|
|
437
|
+
const moveCol = (i, to) => {
|
|
438
|
+
set((t) => gridMoveColumn(t, i, to), "Move column");
|
|
439
|
+
setHcol(to);
|
|
440
|
+
};
|
|
441
|
+
/** `i` and `to` are drawn rows; the header row stays on top */
|
|
442
|
+
const moveRow = (i, to) => {
|
|
443
|
+
if (i < h || to < h || to >= drawn) return;
|
|
444
|
+
set((t) => moveRowTo(t, i - h, to - h), "Move row");
|
|
445
|
+
setHrow(to);
|
|
446
|
+
};
|
|
447
|
+
const delCol = (i) => {
|
|
448
|
+
if (m.columns.length <= 1) return removeTable();
|
|
449
|
+
set((t) => gridDeleteColumn(t, i), "Delete column");
|
|
450
|
+
setHcol(null);
|
|
451
|
+
};
|
|
452
|
+
const delRow = (i) => {
|
|
453
|
+
if (drawn <= 1) return removeTable();
|
|
454
|
+
if (i < h) set({ headerRow: false }, "Delete header row");
|
|
455
|
+
else set((t) => gridDeleteRow(t, i - h), "Delete row");
|
|
456
|
+
setHrow(null);
|
|
457
|
+
setSel(null);
|
|
458
|
+
};
|
|
459
|
+
const writeLabel = (key, label) => set({ columns: m.columns.map((c) => c._key === key ? {
|
|
460
|
+
...c,
|
|
461
|
+
label
|
|
462
|
+
} : c) }, "Edit table");
|
|
463
|
+
const writeCell = (row, col, text, live) => {
|
|
464
|
+
const prev = row.cells[col._key];
|
|
465
|
+
const next = live ? withValue(prev, text) : typedCell(prev, col, row, text);
|
|
466
|
+
set({ rows: m.rows.map((r) => r._key === row._key ? {
|
|
467
|
+
...r,
|
|
468
|
+
cells: {
|
|
469
|
+
...r.cells,
|
|
470
|
+
[col._key]: next
|
|
471
|
+
}
|
|
472
|
+
} : r) }, "Edit table");
|
|
473
|
+
};
|
|
474
|
+
const onMove = (e) => {
|
|
475
|
+
clearTimeout(leaveT.current);
|
|
476
|
+
if (!over) setOver(true);
|
|
477
|
+
if (menu || drag) return;
|
|
478
|
+
const c = e.target.closest?.("td, th");
|
|
479
|
+
if (!c || !table.current?.contains(c)) return;
|
|
480
|
+
const r = c.parentElement.rowIndex;
|
|
481
|
+
if (c.cellIndex !== hcol) setHcol(c.cellIndex);
|
|
482
|
+
if (r !== hrow) setHrow(r);
|
|
483
|
+
};
|
|
484
|
+
const onLeave = () => {
|
|
485
|
+
clearTimeout(leaveT.current);
|
|
486
|
+
leaveT.current = setTimeout(() => {
|
|
487
|
+
setOver(false);
|
|
488
|
+
if (busy.current) return;
|
|
489
|
+
setDot(null);
|
|
490
|
+
setHcol(null);
|
|
491
|
+
setHrow(null);
|
|
492
|
+
}, 240);
|
|
493
|
+
};
|
|
494
|
+
const dotOn = (d) => {
|
|
495
|
+
clearTimeout(dotT.current);
|
|
496
|
+
setDot(d);
|
|
497
|
+
};
|
|
498
|
+
const dotOff = () => {
|
|
499
|
+
clearTimeout(dotT.current);
|
|
500
|
+
dotT.current = setTimeout(() => setDot(null), 140);
|
|
501
|
+
};
|
|
502
|
+
const grab = (e, kind, i) => {
|
|
503
|
+
const t = table.current;
|
|
504
|
+
if (e.button !== 0 || !t) return;
|
|
505
|
+
e.preventDefault();
|
|
506
|
+
const min = kind === "row" ? h : 0;
|
|
507
|
+
const fixed = kind === "row" && i < min;
|
|
508
|
+
const x0 = e.clientX;
|
|
509
|
+
const y0 = e.clientY;
|
|
510
|
+
const n = kind === "row" ? t.rows.length : t.rows[0]?.cells.length ?? 0;
|
|
511
|
+
const st = {
|
|
512
|
+
on: false,
|
|
513
|
+
to: i
|
|
514
|
+
};
|
|
515
|
+
const edge = (k) => (kind === "row" ? t.rows[k] : t.rows[0].cells[k]).getBoundingClientRect();
|
|
516
|
+
const move = (ev) => {
|
|
517
|
+
if (fixed) return;
|
|
518
|
+
const d = kind === "row" ? ev.clientY - y0 : ev.clientX - x0;
|
|
519
|
+
if (!st.on && Math.abs(d) < 4) return;
|
|
520
|
+
if (!st.on) {
|
|
521
|
+
st.on = true;
|
|
522
|
+
setDrag({
|
|
523
|
+
kind,
|
|
524
|
+
i
|
|
525
|
+
});
|
|
526
|
+
setDot(null);
|
|
527
|
+
document.body.style.cursor = "grabbing";
|
|
528
|
+
document.body.style.userSelect = "none";
|
|
529
|
+
}
|
|
530
|
+
const box = t.getBoundingClientRect();
|
|
531
|
+
const p = kind === "row" ? ev.clientY : ev.clientX;
|
|
532
|
+
let to = i;
|
|
533
|
+
for (let k = min; k < n; k++) {
|
|
534
|
+
const r = edge(k);
|
|
535
|
+
if (p > (kind === "row" ? (r.top + r.bottom) / 2 : (r.left + r.right) / 2)) to = k;
|
|
536
|
+
}
|
|
537
|
+
if (p < (kind === "row" ? edge(min).bottom : edge(0).right)) to = min;
|
|
538
|
+
st.to = Math.max(min, Math.min(n - 1, to));
|
|
539
|
+
const tr = edge(st.to);
|
|
540
|
+
setDrop(kind === "row" ? { y: (st.to > i ? tr.bottom : tr.top) - box.top } : { x: (st.to > i ? tr.right : tr.left) - box.left });
|
|
541
|
+
};
|
|
542
|
+
const up = () => {
|
|
543
|
+
window.removeEventListener("pointermove", move);
|
|
544
|
+
window.removeEventListener("pointerup", up);
|
|
545
|
+
window.removeEventListener("pointercancel", up);
|
|
546
|
+
if (!st.on) {
|
|
547
|
+
setMenu({
|
|
548
|
+
kind,
|
|
549
|
+
i
|
|
550
|
+
});
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
document.body.style.cursor = "";
|
|
554
|
+
document.body.style.userSelect = "";
|
|
555
|
+
setDrag(null);
|
|
556
|
+
setDrop(null);
|
|
557
|
+
if (st.to === i) return;
|
|
558
|
+
if (kind === "row") moveRow(i, st.to);
|
|
559
|
+
else moveCol(i, st.to);
|
|
560
|
+
ctx.notify(kind === "row" ? "Row moved" : "Column moved");
|
|
561
|
+
};
|
|
562
|
+
window.addEventListener("pointermove", move);
|
|
563
|
+
window.addEventListener("pointerup", up);
|
|
564
|
+
window.addEventListener("pointercancel", up);
|
|
565
|
+
};
|
|
566
|
+
const chipKey = (e, kind, i) => {
|
|
567
|
+
if (e.key !== "Enter" && e.key !== " ") return;
|
|
568
|
+
e.preventDefault();
|
|
569
|
+
setMenu({
|
|
570
|
+
kind,
|
|
571
|
+
i
|
|
572
|
+
});
|
|
573
|
+
};
|
|
574
|
+
const centered = gridCentered(m);
|
|
575
|
+
const fit = !!m.design?.fit;
|
|
576
|
+
const act = (k) => {
|
|
577
|
+
const [r, c] = sel ?? [0, 0];
|
|
578
|
+
if (k === "row") addRow(Math.max(0, r - h + 1));
|
|
579
|
+
else if (k === "col") addCol(c + 1);
|
|
580
|
+
else if (k === "header") {
|
|
581
|
+
set({ headerRow: !m.headerRow }, m.headerRow ? "Turn off header row" : "Turn on header row");
|
|
582
|
+
setSel(null);
|
|
583
|
+
} else if (k === "center") set((t) => gridToggleCenter(t), "Center text");
|
|
584
|
+
else if (k === "fit") set((t) => {
|
|
585
|
+
const { fit: _fit, ...design } = t.design ?? {};
|
|
586
|
+
return {
|
|
587
|
+
...t,
|
|
588
|
+
design: fit ? Object.keys(design).length ? design : void 0 : {
|
|
589
|
+
...design,
|
|
590
|
+
fit: true
|
|
591
|
+
}
|
|
592
|
+
};
|
|
593
|
+
}, fit ? "Table to its own width" : "Fit table to width");
|
|
594
|
+
else removeTable();
|
|
595
|
+
};
|
|
596
|
+
const alignOf = (c) => c.align === "center" ? "text-center" : c.align === "end" || !c.align && (c.type === "number" || c.type === "money" || c.type === "rating") ? "text-right" : "text-left";
|
|
597
|
+
const tint = (r, c) => drag && (drag.kind === "row" ? drag.i === r : drag.i === c) ? "!bg-kit-insp-zone-over" : "";
|
|
598
|
+
const show = !ro && (over || !!menu || !!drag);
|
|
599
|
+
const last = drawn - 1;
|
|
600
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
601
|
+
className: "group/blk relative my-5",
|
|
602
|
+
"data-rt-isolate": "",
|
|
603
|
+
children: [
|
|
604
|
+
ro && !m.caption ? null : /* @__PURE__ */ jsx("input", {
|
|
605
|
+
value: m.caption ?? "",
|
|
606
|
+
readOnly: ro,
|
|
607
|
+
"aria-label": "Table caption",
|
|
608
|
+
placeholder: "Add a caption",
|
|
609
|
+
onChange: (e) => set({ caption: e.target.value }, "Edit table caption"),
|
|
610
|
+
className: "mb-2 block w-full rounded-[4px] border-0 bg-transparent px-0 text-[13px] font-medium leading-[18px] text-kit-insp-tip-title outline-none placeholder:text-kit-insp-faint focus:bg-kit-insp-card-focus"
|
|
611
|
+
}),
|
|
612
|
+
/* @__PURE__ */ jsxs("div", {
|
|
613
|
+
ref: wrap,
|
|
614
|
+
className: cn("relative inline-block min-w-[60%] max-w-full align-top", fit && "block w-full"),
|
|
615
|
+
onMouseMove: ro ? void 0 : onMove,
|
|
616
|
+
onMouseLeave: ro ? void 0 : onLeave,
|
|
617
|
+
onFocus: (e) => {
|
|
618
|
+
const at = e.target.getAttribute?.("data-tg-cell");
|
|
619
|
+
if (!at) return;
|
|
620
|
+
const [r, c] = at.split(":").map(Number);
|
|
621
|
+
setSel([r, c]);
|
|
622
|
+
},
|
|
623
|
+
onBlur: (e) => {
|
|
624
|
+
if (!wrap.current?.contains(e.relatedTarget)) setSel(null);
|
|
625
|
+
},
|
|
626
|
+
children: [
|
|
627
|
+
/* @__PURE__ */ jsx("table", {
|
|
628
|
+
ref: table,
|
|
629
|
+
className: "w-full border-collapse text-[14px] leading-5 text-kit-fg",
|
|
630
|
+
children: /* @__PURE__ */ jsxs("tbody", { children: [m.headerRow ? /* @__PURE__ */ jsx("tr", { children: m.columns.map((col, c) => /* @__PURE__ */ jsx("th", {
|
|
631
|
+
scope: "col",
|
|
632
|
+
className: cn(CELL, HEAD_CELL, alignOf(col), tint(0, c)),
|
|
633
|
+
children: /* @__PURE__ */ jsx(GridText, {
|
|
634
|
+
at: `0:${c}`,
|
|
635
|
+
shown: col.label,
|
|
636
|
+
live: true,
|
|
637
|
+
readOnly: ro,
|
|
638
|
+
label: `Column ${c + 1} name`,
|
|
639
|
+
onCommit: (text) => writeLabel(col._key, text),
|
|
640
|
+
onEnter: () => focusCell(1, c) || ctx.exit(el)
|
|
641
|
+
})
|
|
642
|
+
}, col._key)) }) : null, rows.map((row, i) => {
|
|
643
|
+
const r = i + h;
|
|
644
|
+
return /* @__PURE__ */ jsx("tr", {
|
|
645
|
+
className: row.footer ? "font-medium" : void 0,
|
|
646
|
+
children: m.columns.map((col, c) => {
|
|
647
|
+
const ed = cellEdit(col, row, row.cells[col._key]);
|
|
648
|
+
const head = m.headerColumn && c === 0;
|
|
649
|
+
return /* @__PURE__ */ jsx("td", {
|
|
650
|
+
className: cn(CELL, head && HEAD_CELL, alignOf(col), tint(r, c)),
|
|
651
|
+
children: /* @__PURE__ */ jsx(GridText, {
|
|
652
|
+
at: `${r}:${c}`,
|
|
653
|
+
shown: ed.shown,
|
|
654
|
+
raw: ed.raw,
|
|
655
|
+
live: ed.live,
|
|
656
|
+
readOnly: ro || ed.locked,
|
|
657
|
+
label: `${col.label.trim() || `Column ${c + 1}`}, row ${i + 1}`,
|
|
658
|
+
onCommit: (text) => writeCell(row, col, text, ed.live),
|
|
659
|
+
onEnter: () => focusCell(r + 1, c) || ctx.exit(el)
|
|
660
|
+
})
|
|
661
|
+
}, col._key);
|
|
662
|
+
})
|
|
663
|
+
}, row._key);
|
|
664
|
+
})] })
|
|
665
|
+
}),
|
|
666
|
+
show && geo ? /* @__PURE__ */ jsxs("div", {
|
|
667
|
+
className: "pointer-events-none absolute inset-0 z-[5]",
|
|
668
|
+
contentEditable: false,
|
|
669
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
670
|
+
children: [
|
|
671
|
+
drag ? null : geo.cols.map((x, i) => /* @__PURE__ */ jsx("button", {
|
|
672
|
+
type: "button",
|
|
673
|
+
tabIndex: -1,
|
|
674
|
+
title: "Add column",
|
|
675
|
+
"aria-label": "Add column",
|
|
676
|
+
className: cn(DOT, "-top-[21px] -ml-[9px]"),
|
|
677
|
+
style: { left: x },
|
|
678
|
+
onMouseEnter: () => dotOn({
|
|
679
|
+
c: i,
|
|
680
|
+
x
|
|
681
|
+
}),
|
|
682
|
+
onMouseLeave: dotOff,
|
|
683
|
+
onClick: () => addCol(i + 1),
|
|
684
|
+
children: /* @__PURE__ */ jsx(Ti, {
|
|
685
|
+
n: "plus",
|
|
686
|
+
className: DOT_ICON
|
|
687
|
+
})
|
|
688
|
+
}, `c${i}`)),
|
|
689
|
+
drag ? null : geo.rows.map((y, i) => /* @__PURE__ */ jsx("button", {
|
|
690
|
+
type: "button",
|
|
691
|
+
tabIndex: -1,
|
|
692
|
+
title: "Add row",
|
|
693
|
+
"aria-label": "Add row",
|
|
694
|
+
className: cn(DOT, "-left-[21px] -mt-[9px]"),
|
|
695
|
+
style: { top: y },
|
|
696
|
+
onMouseEnter: () => dotOn({
|
|
697
|
+
r: i,
|
|
698
|
+
y
|
|
699
|
+
}),
|
|
700
|
+
onMouseLeave: dotOff,
|
|
701
|
+
onClick: () => addRow(i + 1 - h),
|
|
702
|
+
children: /* @__PURE__ */ jsx(Ti, {
|
|
703
|
+
n: "plus",
|
|
704
|
+
className: DOT_ICON
|
|
705
|
+
})
|
|
706
|
+
}, `r${i}`)),
|
|
707
|
+
hcol != null && geo.mids[hcol] != null ? /* @__PURE__ */ jsxs(Menu, {
|
|
708
|
+
open: menu?.kind === "col",
|
|
709
|
+
onOpenChange: (o) => setMenu(o ? {
|
|
710
|
+
kind: "col",
|
|
711
|
+
i: hcol
|
|
712
|
+
} : null),
|
|
713
|
+
children: [/* @__PURE__ */ jsx(MenuTrigger, {
|
|
714
|
+
title: "Drag to move · click for menu",
|
|
715
|
+
"aria-label": "Column actions",
|
|
716
|
+
className: cn(HANDLE, "-top-[9px] h-[18px] -translate-x-1/2 px-1"),
|
|
717
|
+
style: { left: geo.mids[hcol] },
|
|
718
|
+
onPointerDown: (e) => grab(e, "col", hcol),
|
|
719
|
+
onKeyDown: (e) => chipKey(e, "col", hcol),
|
|
720
|
+
children: /* @__PURE__ */ jsx(Ti, { n: "more" })
|
|
721
|
+
}), /* @__PURE__ */ jsxs(MenuContent, {
|
|
722
|
+
align: "start",
|
|
723
|
+
className: MENU,
|
|
724
|
+
finalFocus: false,
|
|
725
|
+
children: [
|
|
726
|
+
/* @__PURE__ */ jsx(MenuLabel, { children: "Column" }),
|
|
727
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
728
|
+
icon: /* @__PURE__ */ jsx(Ti, { n: "insL" }),
|
|
729
|
+
onClick: () => addCol(hcol),
|
|
730
|
+
children: "Insert left"
|
|
731
|
+
}),
|
|
732
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
733
|
+
icon: /* @__PURE__ */ jsx(Ti, { n: "insR" }),
|
|
734
|
+
onClick: () => addCol(hcol + 1),
|
|
735
|
+
children: "Insert right"
|
|
736
|
+
}),
|
|
737
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
738
|
+
icon: /* @__PURE__ */ jsx(Ti, { n: "mvL" }),
|
|
739
|
+
disabled: hcol === 0,
|
|
740
|
+
onClick: () => moveCol(hcol, hcol - 1),
|
|
741
|
+
children: "Move left"
|
|
742
|
+
}),
|
|
743
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
744
|
+
icon: /* @__PURE__ */ jsx(Ti, { n: "mvR" }),
|
|
745
|
+
disabled: hcol >= m.columns.length - 1,
|
|
746
|
+
onClick: () => moveCol(hcol, hcol + 1),
|
|
747
|
+
children: "Move right"
|
|
748
|
+
}),
|
|
749
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
750
|
+
icon: /* @__PURE__ */ jsx(IconAdjustmentsHorizontal, { stroke: 1.75 }),
|
|
751
|
+
onClick: () => setSettings(true),
|
|
752
|
+
children: "Column type and settings…"
|
|
753
|
+
}),
|
|
754
|
+
/* @__PURE__ */ jsx(MenuSeparator, {}),
|
|
755
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
756
|
+
danger: true,
|
|
757
|
+
icon: /* @__PURE__ */ jsx(IconTrash, { stroke: 1.75 }),
|
|
758
|
+
onClick: () => delCol(hcol),
|
|
759
|
+
children: "Delete column"
|
|
760
|
+
})
|
|
761
|
+
]
|
|
762
|
+
})]
|
|
763
|
+
}) : null,
|
|
764
|
+
hrow != null && geo.rmids[hrow] != null ? /* @__PURE__ */ jsxs(Menu, {
|
|
765
|
+
open: menu?.kind === "row",
|
|
766
|
+
onOpenChange: (o) => setMenu(o ? {
|
|
767
|
+
kind: "row",
|
|
768
|
+
i: hrow
|
|
769
|
+
} : null),
|
|
770
|
+
children: [/* @__PURE__ */ jsx(MenuTrigger, {
|
|
771
|
+
title: "Drag to move · click for menu",
|
|
772
|
+
"aria-label": "Row actions",
|
|
773
|
+
className: cn(HANDLE, "-left-[9px] w-[18px] -translate-y-1/2 py-1"),
|
|
774
|
+
style: { top: geo.rmids[hrow] },
|
|
775
|
+
onPointerDown: (e) => grab(e, "row", hrow),
|
|
776
|
+
onKeyDown: (e) => chipKey(e, "row", hrow),
|
|
777
|
+
children: /* @__PURE__ */ jsx(Ti, {
|
|
778
|
+
n: "more",
|
|
779
|
+
className: "rotate-90"
|
|
780
|
+
})
|
|
781
|
+
}), /* @__PURE__ */ jsxs(MenuContent, {
|
|
782
|
+
align: "start",
|
|
783
|
+
className: MENU,
|
|
784
|
+
finalFocus: false,
|
|
785
|
+
children: [
|
|
786
|
+
/* @__PURE__ */ jsx(MenuLabel, { children: hrow < h ? "Header row" : "Row" }),
|
|
787
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
788
|
+
icon: /* @__PURE__ */ jsx(Ti, { n: "insA" }),
|
|
789
|
+
disabled: hrow < h,
|
|
790
|
+
onClick: () => addRow(hrow - h, true),
|
|
791
|
+
children: "Insert above"
|
|
792
|
+
}),
|
|
793
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
794
|
+
icon: /* @__PURE__ */ jsx(Ti, { n: "insB" }),
|
|
795
|
+
onClick: () => addRow(hrow - h + 1),
|
|
796
|
+
children: "Insert below"
|
|
797
|
+
}),
|
|
798
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
799
|
+
icon: /* @__PURE__ */ jsx(Ti, { n: "up" }),
|
|
800
|
+
disabled: hrow <= h,
|
|
801
|
+
onClick: () => moveRow(hrow, hrow - 1),
|
|
802
|
+
children: "Move up"
|
|
803
|
+
}),
|
|
804
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
805
|
+
icon: /* @__PURE__ */ jsx(Ti, { n: "down" }),
|
|
806
|
+
disabled: hrow < h || hrow >= last,
|
|
807
|
+
onClick: () => moveRow(hrow, hrow + 1),
|
|
808
|
+
children: "Move down"
|
|
809
|
+
}),
|
|
810
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
811
|
+
icon: /* @__PURE__ */ jsx(IconAdjustmentsHorizontal, { stroke: 1.75 }),
|
|
812
|
+
onClick: () => setSettings(true),
|
|
813
|
+
children: "Row group and settings…"
|
|
814
|
+
}),
|
|
815
|
+
/* @__PURE__ */ jsx(MenuSeparator, {}),
|
|
816
|
+
/* @__PURE__ */ jsx(MenuItem, {
|
|
817
|
+
danger: true,
|
|
818
|
+
icon: /* @__PURE__ */ jsx(IconTrash, { stroke: 1.75 }),
|
|
819
|
+
onClick: () => delRow(hrow),
|
|
820
|
+
children: "Delete row"
|
|
821
|
+
})
|
|
822
|
+
]
|
|
823
|
+
})]
|
|
824
|
+
}) : null,
|
|
825
|
+
drop ? "y" in drop ? /* @__PURE__ */ jsx("i", {
|
|
826
|
+
className: cn(GUIDE, "inset-x-0 z-[2] -mt-px block h-[2px]"),
|
|
827
|
+
style: { top: drop.y }
|
|
828
|
+
}) : /* @__PURE__ */ jsx("i", {
|
|
829
|
+
className: cn(GUIDE, "inset-y-0 z-[2] -ml-px block w-[2px]"),
|
|
830
|
+
style: { left: drop.x }
|
|
831
|
+
}) : null,
|
|
832
|
+
/* @__PURE__ */ jsx(AnimatePresence, { children: dot && !drag ? "x" in dot ? /* @__PURE__ */ jsx(motion.i, {
|
|
833
|
+
className: cn(GUIDE, "inset-y-0 -ml-px block w-[2px] origin-top"),
|
|
834
|
+
initial: {
|
|
835
|
+
scaleY: 0,
|
|
836
|
+
opacity: 1,
|
|
837
|
+
left: dot.x
|
|
838
|
+
},
|
|
839
|
+
animate: {
|
|
840
|
+
scaleY: 1,
|
|
841
|
+
opacity: 1,
|
|
842
|
+
left: dot.x
|
|
843
|
+
},
|
|
844
|
+
exit: {
|
|
845
|
+
opacity: 0,
|
|
846
|
+
transition: { duration: .12 }
|
|
847
|
+
},
|
|
848
|
+
transition: {
|
|
849
|
+
scaleY: {
|
|
850
|
+
duration: .22,
|
|
851
|
+
ease: [
|
|
852
|
+
.22,
|
|
853
|
+
1,
|
|
854
|
+
.36,
|
|
855
|
+
1
|
|
856
|
+
]
|
|
857
|
+
},
|
|
858
|
+
left: {
|
|
859
|
+
type: "spring",
|
|
860
|
+
stiffness: 420,
|
|
861
|
+
damping: 34
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}, "gv") : /* @__PURE__ */ jsx(motion.i, {
|
|
865
|
+
className: cn(GUIDE, "inset-x-0 -mt-px block h-[2px] origin-left"),
|
|
866
|
+
initial: {
|
|
867
|
+
scaleX: 0,
|
|
868
|
+
opacity: 1,
|
|
869
|
+
top: dot.y
|
|
870
|
+
},
|
|
871
|
+
animate: {
|
|
872
|
+
scaleX: 1,
|
|
873
|
+
opacity: 1,
|
|
874
|
+
top: dot.y
|
|
875
|
+
},
|
|
876
|
+
exit: {
|
|
877
|
+
opacity: 0,
|
|
878
|
+
transition: { duration: .12 }
|
|
879
|
+
},
|
|
880
|
+
transition: {
|
|
881
|
+
scaleX: {
|
|
882
|
+
duration: .22,
|
|
883
|
+
ease: [
|
|
884
|
+
.22,
|
|
885
|
+
1,
|
|
886
|
+
.36,
|
|
887
|
+
1
|
|
888
|
+
]
|
|
889
|
+
},
|
|
890
|
+
top: {
|
|
891
|
+
type: "spring",
|
|
892
|
+
stiffness: 420,
|
|
893
|
+
damping: 34
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
}, "gh") : null })
|
|
897
|
+
]
|
|
898
|
+
}) : null,
|
|
899
|
+
sel && !ro ? /* @__PURE__ */ jsxs("div", {
|
|
900
|
+
role: "toolbar",
|
|
901
|
+
"aria-label": "Table",
|
|
902
|
+
contentEditable: false,
|
|
903
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
904
|
+
className: "absolute -top-[52px] left-0 z-[6] flex w-max origin-bottom-left items-center gap-0.5 rounded-[10px] bg-kit-insp-btool-bg p-1 shadow-[0_0_0_1px_var(--kit-insp-btool-line),0_1px_2px_rgb(0_0_0/0.05),0_8px_24px_-4px_rgb(0_0_0/0.1)] motion-safe:animate-[kit-insp-appear_160ms_cubic-bezier(0.22,1,0.36,1)_both]",
|
|
905
|
+
children: [
|
|
906
|
+
/* @__PURE__ */ jsx("button", {
|
|
907
|
+
type: "button",
|
|
908
|
+
title: "Header row",
|
|
909
|
+
"aria-label": "Header row",
|
|
910
|
+
"aria-pressed": m.headerRow,
|
|
911
|
+
className: TOOL_BTN,
|
|
912
|
+
onClick: () => act("header"),
|
|
913
|
+
children: /* @__PURE__ */ jsx(Ti, { n: "header" })
|
|
914
|
+
}),
|
|
915
|
+
/* @__PURE__ */ jsx("i", {
|
|
916
|
+
"aria-hidden": true,
|
|
917
|
+
className: "mx-0.5 h-4 w-px shrink-0 bg-kit-insp-btool-sep"
|
|
918
|
+
}),
|
|
919
|
+
/* @__PURE__ */ jsx("button", {
|
|
920
|
+
type: "button",
|
|
921
|
+
title: "Add row below",
|
|
922
|
+
"aria-label": "Add row below",
|
|
923
|
+
className: TOOL_BTN,
|
|
924
|
+
onClick: () => act("row"),
|
|
925
|
+
children: /* @__PURE__ */ jsx(Ti, { n: "row" })
|
|
926
|
+
}),
|
|
927
|
+
/* @__PURE__ */ jsx("button", {
|
|
928
|
+
type: "button",
|
|
929
|
+
title: "Add column right",
|
|
930
|
+
"aria-label": "Add column right",
|
|
931
|
+
className: TOOL_BTN,
|
|
932
|
+
onClick: () => act("col"),
|
|
933
|
+
children: /* @__PURE__ */ jsx(Ti, { n: "col" })
|
|
934
|
+
}),
|
|
935
|
+
/* @__PURE__ */ jsx("i", {
|
|
936
|
+
"aria-hidden": true,
|
|
937
|
+
className: "mx-0.5 h-4 w-px shrink-0 bg-kit-insp-btool-sep"
|
|
938
|
+
}),
|
|
939
|
+
/* @__PURE__ */ jsx("button", {
|
|
940
|
+
type: "button",
|
|
941
|
+
title: "Center text",
|
|
942
|
+
"aria-label": "Center text",
|
|
943
|
+
"aria-pressed": centered,
|
|
944
|
+
className: TOOL_BTN,
|
|
945
|
+
onClick: () => act("center"),
|
|
946
|
+
children: /* @__PURE__ */ jsx(Ti, { n: "center" })
|
|
947
|
+
}),
|
|
948
|
+
/* @__PURE__ */ jsx("button", {
|
|
949
|
+
type: "button",
|
|
950
|
+
title: "Fit to width",
|
|
951
|
+
"aria-label": "Fit to width",
|
|
952
|
+
"aria-pressed": fit,
|
|
953
|
+
className: TOOL_BTN,
|
|
954
|
+
onClick: () => act("fit"),
|
|
955
|
+
children: /* @__PURE__ */ jsx(Ti, { n: "fit" })
|
|
956
|
+
}),
|
|
957
|
+
/* @__PURE__ */ jsx("button", {
|
|
958
|
+
type: "button",
|
|
959
|
+
title: "Table settings",
|
|
960
|
+
"aria-label": "Table settings",
|
|
961
|
+
className: TOOL_BTN,
|
|
962
|
+
onClick: () => setSettings(true),
|
|
963
|
+
children: /* @__PURE__ */ jsx(IconAdjustmentsHorizontal, {
|
|
964
|
+
className: "size-3.5",
|
|
965
|
+
stroke: 1.75,
|
|
966
|
+
"aria-hidden": true
|
|
967
|
+
})
|
|
968
|
+
}),
|
|
969
|
+
/* @__PURE__ */ jsx("i", {
|
|
970
|
+
"aria-hidden": true,
|
|
971
|
+
className: "mx-0.5 h-4 w-px shrink-0 bg-kit-insp-btool-sep"
|
|
972
|
+
}),
|
|
973
|
+
/* @__PURE__ */ jsx("button", {
|
|
974
|
+
type: "button",
|
|
975
|
+
title: "Delete table",
|
|
976
|
+
"aria-label": "Delete table",
|
|
977
|
+
className: cn(TOOL_BTN, "text-kit-insp-btool-danger"),
|
|
978
|
+
onClick: () => act("del"),
|
|
979
|
+
children: /* @__PURE__ */ jsx(IconTrash, {
|
|
980
|
+
className: "size-3.5",
|
|
981
|
+
stroke: 1.75,
|
|
982
|
+
"aria-hidden": true
|
|
983
|
+
})
|
|
984
|
+
})
|
|
985
|
+
]
|
|
986
|
+
}) : null
|
|
987
|
+
]
|
|
988
|
+
}),
|
|
989
|
+
ro && !m.notes ? null : /* @__PURE__ */ jsx(Textarea, {
|
|
990
|
+
value: m.notes ?? "",
|
|
991
|
+
readOnly: ro,
|
|
992
|
+
rows: 1,
|
|
993
|
+
"aria-label": "Note under the table",
|
|
994
|
+
placeholder: "Add a note: source, method or date",
|
|
995
|
+
onChange: (e) => set({ notes: e.target.value }, "Edit table note"),
|
|
996
|
+
className: "mt-2 min-h-0 resize-none rounded-[4px] border-0 bg-transparent px-0 py-0 text-[12px] leading-[18px] text-kit-group-sub shadow-none outline-none placeholder:text-kit-insp-faint hover:bg-transparent focus:bg-kit-insp-card-focus focus:shadow-none"
|
|
997
|
+
}),
|
|
998
|
+
m.footnotes?.length ? /* @__PURE__ */ jsx("ol", {
|
|
999
|
+
"aria-label": "Footnotes",
|
|
1000
|
+
className: "mt-2 flex list-none flex-col gap-1 p-0 text-[12px] leading-[18px] text-kit-group-sub",
|
|
1001
|
+
children: m.footnotes.map((f, n) => /* @__PURE__ */ jsxs("li", {
|
|
1002
|
+
className: "group/fn flex items-center gap-1.5",
|
|
1003
|
+
children: [
|
|
1004
|
+
/* @__PURE__ */ jsx("sup", {
|
|
1005
|
+
className: "shrink-0 font-semibold text-kit-insp-accent-fg",
|
|
1006
|
+
children: n + 1
|
|
1007
|
+
}),
|
|
1008
|
+
/* @__PURE__ */ jsx("input", {
|
|
1009
|
+
value: f.text,
|
|
1010
|
+
readOnly: ro,
|
|
1011
|
+
"aria-label": `Footnote ${n + 1}`,
|
|
1012
|
+
onChange: (e) => set((v) => gridFootnoteText(v, f._key, e.target.value), "Edit footnote"),
|
|
1013
|
+
className: "min-w-0 flex-1 rounded-[4px] border-0 bg-transparent px-0 text-inherit outline-none focus:bg-kit-insp-card-focus"
|
|
1014
|
+
}),
|
|
1015
|
+
ro ? null : /* @__PURE__ */ jsx("button", {
|
|
1016
|
+
type: "button",
|
|
1017
|
+
"aria-label": `Remove footnote ${n + 1}`,
|
|
1018
|
+
onClick: () => set((v) => gridDeleteFootnote(v, f._key), "Remove footnote"),
|
|
1019
|
+
className: "grid size-5 shrink-0 place-items-center rounded-[4px] text-kit-insp-desc opacity-0 transition-opacity hover:bg-kit-insp-row-press focus-visible:opacity-100 group-hover/fn:opacity-100 pointer-coarse:opacity-100",
|
|
1020
|
+
children: /* @__PURE__ */ jsx(IconX, {
|
|
1021
|
+
className: "size-3",
|
|
1022
|
+
stroke: 1.75,
|
|
1023
|
+
"aria-hidden": true
|
|
1024
|
+
})
|
|
1025
|
+
})
|
|
1026
|
+
]
|
|
1027
|
+
}, f._key))
|
|
1028
|
+
}) : null,
|
|
1029
|
+
settings ? /* @__PURE__ */ jsx(Modal, {
|
|
1030
|
+
open: true,
|
|
1031
|
+
onOpenChange: (o) => !o && setSettings(false),
|
|
1032
|
+
children: /* @__PURE__ */ jsxs(ModalContent, {
|
|
1033
|
+
size: "xl",
|
|
1034
|
+
children: [/* @__PURE__ */ jsx(ModalHeader, {
|
|
1035
|
+
title: "Table settings",
|
|
1036
|
+
description: "Column types, row groups, totals, footnotes and how the table reads on the site."
|
|
1037
|
+
}), /* @__PURE__ */ jsx(ModalBody, { children: /* @__PURE__ */ jsx(TableEditor, {
|
|
1038
|
+
value: m,
|
|
1039
|
+
onChange: (next) => set(() => next, "Edit table"),
|
|
1040
|
+
readOnly: ro,
|
|
1041
|
+
options,
|
|
1042
|
+
label: "Table"
|
|
1043
|
+
}) })]
|
|
1044
|
+
})
|
|
1045
|
+
}) : null
|
|
1046
|
+
]
|
|
1047
|
+
});
|
|
1048
|
+
}
|
|
1049
|
+
//#endregion
|
|
1050
|
+
export { TableGridV16, gridCentered, gridDeleteColumn, gridDeleteFootnote, gridDeleteRow, gridFootnoteText, gridInsertColumn, gridInsertRow, gridMoveColumn, gridRows, gridToggleCenter };
|
|
1051
|
+
|
|
1052
|
+
//# sourceMappingURL=table-grid.js.map
|