@arbidocs/blocks 0.5.183 → 0.5.184
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/ConnectedCallDock-CF7KF5KM.cjs +1 -1
- package/dist/ConnectedCallRoom-NQOE2RYD.cjs +1 -1
- package/dist/{ConnectedNativeDocxComparison-3KTHPCMT.cjs → ConnectedNativeDocxComparison-2YMF257D.cjs} +6 -6
- package/dist/{ConnectedNativeDocxComparison-3KTHPCMT.cjs.map → ConnectedNativeDocxComparison-2YMF257D.cjs.map} +1 -1
- package/dist/{ConnectedStreamedWordArtifact-LUM6WE7F.cjs → ConnectedStreamedWordArtifact-3K5WTQMZ.cjs} +6 -6
- package/dist/{ConnectedStreamedWordArtifact-LUM6WE7F.cjs.map → ConnectedStreamedWordArtifact-3K5WTQMZ.cjs.map} +1 -1
- package/dist/{DocumentReviewCard-NKCKBY3P.cjs → DocumentReviewCard-3NNHDWG3.cjs} +14 -14
- package/dist/{DocumentReviewCard-NKCKBY3P.cjs.map → DocumentReviewCard-3NNHDWG3.cjs.map} +1 -1
- package/dist/{FilesViewerDialog-T4SOKUKO.cjs → FilesViewerDialog-OKLWGMIO.cjs} +17 -17
- package/dist/{FilesViewerDialog-T4SOKUKO.cjs.map → FilesViewerDialog-OKLWGMIO.cjs.map} +1 -1
- package/dist/{WorkspaceTableView-QT63XYII.cjs → WorkspaceTableView-LGDLG3TX.cjs} +7 -7
- package/dist/{WorkspaceTableView-QT63XYII.cjs.map → WorkspaceTableView-LGDLG3TX.cjs.map} +1 -1
- package/dist/agents/index.cjs +163 -163
- package/dist/calls/index.cjs +21 -21
- package/dist/chat/index.cjs +5 -5
- package/dist/{chunk-4TCOUQMC.cjs → chunk-3J4R2QFL.cjs} +3 -3
- package/dist/{chunk-4TCOUQMC.cjs.map → chunk-3J4R2QFL.cjs.map} +1 -1
- package/dist/{chunk-W5UGKUV7.cjs → chunk-66IOCKWS.cjs} +124 -31
- package/dist/chunk-66IOCKWS.cjs.map +1 -0
- package/dist/{chunk-L3MYUPSH.cjs → chunk-6AFAYGJW.cjs} +5 -5
- package/dist/{chunk-L3MYUPSH.cjs.map → chunk-6AFAYGJW.cjs.map} +1 -1
- package/dist/{chunk-SFAAOEQE.cjs → chunk-6RYDZ2PS.cjs} +3 -3
- package/dist/{chunk-SFAAOEQE.cjs.map → chunk-6RYDZ2PS.cjs.map} +1 -1
- package/dist/{chunk-7QZXHSQX.cjs → chunk-7YALMXGZ.cjs} +26 -6
- package/dist/chunk-7YALMXGZ.cjs.map +1 -0
- package/dist/{chunk-WIQDXRRB.cjs → chunk-E4CSBOXP.cjs} +28 -28
- package/dist/{chunk-WIQDXRRB.cjs.map → chunk-E4CSBOXP.cjs.map} +1 -1
- package/dist/{chunk-J4X3LYGC.cjs → chunk-EBRD3IUG.cjs} +4 -4
- package/dist/{chunk-J4X3LYGC.cjs.map → chunk-EBRD3IUG.cjs.map} +1 -1
- package/dist/{chunk-A4HOEGDI.cjs → chunk-ER55JOJV.cjs} +4 -4
- package/dist/{chunk-A4HOEGDI.cjs.map → chunk-ER55JOJV.cjs.map} +1 -1
- package/dist/{chunk-A7MGQMOV.cjs → chunk-H4N6BZNU.cjs} +3 -3
- package/dist/{chunk-A7MGQMOV.cjs.map → chunk-H4N6BZNU.cjs.map} +1 -1
- package/dist/{chunk-KHZEFLQC.cjs → chunk-HUAABZ2C.cjs} +51 -4
- package/dist/chunk-HUAABZ2C.cjs.map +1 -0
- package/dist/{chunk-YYMCN76N.cjs → chunk-IM6R7DRQ.cjs} +5 -5
- package/dist/{chunk-YYMCN76N.cjs.map → chunk-IM6R7DRQ.cjs.map} +1 -1
- package/dist/{chunk-LYDSETR7.cjs → chunk-JEHGTPS2.cjs} +3 -3
- package/dist/{chunk-LYDSETR7.cjs.map → chunk-JEHGTPS2.cjs.map} +1 -1
- package/dist/{chunk-3YPVXIFF.cjs → chunk-K2XLEOGQ.cjs} +4 -4
- package/dist/{chunk-3YPVXIFF.cjs.map → chunk-K2XLEOGQ.cjs.map} +1 -1
- package/dist/{chunk-DWUWPF2A.cjs → chunk-LQ5XVFLV.cjs} +58 -58
- package/dist/{chunk-DWUWPF2A.cjs.map → chunk-LQ5XVFLV.cjs.map} +1 -1
- package/dist/{chunk-I5LXJLO5.cjs → chunk-MZPBZSKS.cjs} +3 -3
- package/dist/{chunk-I5LXJLO5.cjs.map → chunk-MZPBZSKS.cjs.map} +1 -1
- package/dist/{chunk-ZTLPUUZB.cjs → chunk-OQWJXM4V.cjs} +6 -6
- package/dist/{chunk-ZTLPUUZB.cjs.map → chunk-OQWJXM4V.cjs.map} +1 -1
- package/dist/{chunk-UFDUDQYT.cjs → chunk-PUCYBYBY.cjs} +1712 -71
- package/dist/chunk-PUCYBYBY.cjs.map +1 -0
- package/dist/{chunk-4H5DPHZ2.cjs → chunk-Q6DU3DZC.cjs} +4 -4
- package/dist/{chunk-4H5DPHZ2.cjs.map → chunk-Q6DU3DZC.cjs.map} +1 -1
- package/dist/{chunk-H3C5BY2H.cjs → chunk-QCFX535U.cjs} +4 -4
- package/dist/{chunk-H3C5BY2H.cjs.map → chunk-QCFX535U.cjs.map} +1 -1
- package/dist/{chunk-AZP4ABNL.cjs → chunk-QTGWH6Z2.cjs} +4 -4
- package/dist/{chunk-AZP4ABNL.cjs.map → chunk-QTGWH6Z2.cjs.map} +1 -1
- package/dist/{chunk-HYULUR6E.cjs → chunk-QYPCNB7P.cjs} +29 -29
- package/dist/{chunk-HYULUR6E.cjs.map → chunk-QYPCNB7P.cjs.map} +1 -1
- package/dist/{chunk-6VIS6B3O.cjs → chunk-UVMOUOFD.cjs} +28 -28
- package/dist/{chunk-6VIS6B3O.cjs.map → chunk-UVMOUOFD.cjs.map} +1 -1
- package/dist/{chunk-7ARRFRQR.cjs → chunk-UXWPJ6I5.cjs} +36 -36
- package/dist/{chunk-7ARRFRQR.cjs.map → chunk-UXWPJ6I5.cjs.map} +1 -1
- package/dist/{chunk-NGT3P5ZG.cjs → chunk-VD3HI5RF.cjs} +6 -7
- package/dist/chunk-VD3HI5RF.cjs.map +1 -0
- package/dist/{chunk-LIAC6O7W.cjs → chunk-ZVTLEBFG.cjs} +4 -4
- package/dist/{chunk-LIAC6O7W.cjs.map → chunk-ZVTLEBFG.cjs.map} +1 -1
- package/dist/connect/docx.cjs +9 -9
- package/dist/connect/index.cjs +1396 -1190
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/viewer.cjs +14 -14
- package/dist/connection/databases/ConnectedSourcesEditor.d.ts +4 -0
- package/dist/connection/databases/ConnectedSourcesEditor.js +126 -0
- package/dist/connection/databases/ConnectedSourcesEditor.js.map +7 -0
- package/dist/connection/databases/sourceCells.d.ts +14 -0
- package/dist/connection/databases/sourceCells.js +40 -0
- package/dist/connection/databases/sourceCells.js.map +7 -0
- package/dist/connection/databases/useApiDatabaseSource.js +35 -11
- package/dist/connection/databases/useApiDatabaseSource.js.map +2 -2
- package/dist/connection/databases/useDatabaseCellSources.d.ts +8 -1
- package/dist/connection/databases/useDatabaseCellSources.js +40 -5
- package/dist/connection/databases/useDatabaseCellSources.js.map +2 -2
- package/dist/connection/databases/wireColumns.d.ts +17 -0
- package/dist/connection/databases/wireColumns.js +22 -0
- package/dist/connection/databases/wireColumns.js.map +7 -0
- package/dist/connection/facts/documentPickerGroups.d.ts +3 -0
- package/dist/connection/facts/documentPickerGroups.js +21 -0
- package/dist/connection/facts/documentPickerGroups.js.map +7 -0
- package/dist/connection/facts/factsSource.js +2 -17
- package/dist/connection/facts/factsSource.js.map +2 -2
- package/dist/connection/facts/useFactComposer.js +6 -60
- package/dist/connection/facts/useFactComposer.js.map +2 -2
- package/dist/connection/facts/usePassageCollection.d.ts +21 -0
- package/dist/connection/facts/usePassageCollection.js +72 -0
- package/dist/connection/facts/usePassageCollection.js.map +7 -0
- package/dist/connection/pages/TableViewBlock.js +2 -6
- package/dist/connection/pages/TableViewBlock.js.map +2 -2
- package/dist/connection/tags/ConnectedTagsPage.js +4 -1
- package/dist/connection/tags/ConnectedTagsPage.js.map +2 -2
- package/dist/databases/DatabaseFilterMenu.d.ts +1 -1
- package/dist/databases/DatabaseFilterMenu.js +4 -3
- package/dist/databases/DatabaseFilterMenu.js.map +2 -2
- package/dist/databases/DatabaseRowDetail.js +18 -2
- package/dist/databases/DatabaseRowDetail.js.map +2 -2
- package/dist/databases/databaseColumns.js +7 -2
- package/dist/databases/databaseColumns.js.map +2 -2
- package/dist/databases/index.cjs +128 -131
- package/dist/databases/index.d.ts +1 -1
- package/dist/databases/index.js.map +2 -2
- package/dist/databases/linkCells.d.ts +37 -1
- package/dist/databases/linkCells.js +17 -2
- package/dist/databases/linkCells.js.map +2 -2
- package/dist/embed/index.cjs +18 -18
- package/dist/facts/index.cjs +52 -54
- package/dist/facts/index.cjs.map +1 -1
- package/dist/files/index.cjs +220 -220
- package/dist/home/index.cjs +9 -9
- package/dist/index.cjs +785 -786
- package/dist/index.cjs.map +1 -1
- package/dist/pages/index.cjs +24 -25
- package/dist/pages/index.cjs.map +1 -1
- package/dist/settings/index.cjs +136 -136
- package/dist/site/index.cjs +10 -11
- package/dist/studio/index.cjs +4 -5
- package/dist/studio/index.cjs.map +1 -1
- package/dist/timeline/index.cjs +12 -13
- package/dist/workflow-canvas/index.cjs +26 -26
- package/dist/workspaces/index.cjs +5 -5
- package/node_modules/@arbidocs/coedit/package.json +1 -1
- package/package.json +5 -5
- package/dist/chunk-7QZXHSQX.cjs.map +0 -1
- package/dist/chunk-GXJW5EK5.cjs +0 -102
- package/dist/chunk-GXJW5EK5.cjs.map +0 -1
- package/dist/chunk-I24N4OSB.cjs +0 -57
- package/dist/chunk-I24N4OSB.cjs.map +0 -1
- package/dist/chunk-KHZEFLQC.cjs.map +0 -1
- package/dist/chunk-NGT3P5ZG.cjs.map +0 -1
- package/dist/chunk-UFDUDQYT.cjs.map +0 -1
- package/dist/chunk-VBD4RJOL.cjs +0 -1640
- package/dist/chunk-VBD4RJOL.cjs.map +0 -1
- package/dist/chunk-W5UGKUV7.cjs.map +0 -1
package/dist/chunk-VBD4RJOL.cjs
DELETED
|
@@ -1,1640 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
var chunkKHZEFLQC_cjs = require('./chunk-KHZEFLQC.cjs');
|
|
5
|
-
var chunkGISMY7J7_cjs = require('./chunk-GISMY7J7.cjs');
|
|
6
|
-
var chunkV5P5MRSR_cjs = require('./chunk-V5P5MRSR.cjs');
|
|
7
|
-
var chunkGXJW5EK5_cjs = require('./chunk-GXJW5EK5.cjs');
|
|
8
|
-
var chunkZVEW3JBT_cjs = require('./chunk-ZVEW3JBT.cjs');
|
|
9
|
-
var chunkPPCATBOY_cjs = require('./chunk-PPCATBOY.cjs');
|
|
10
|
-
var chunkPLIF5CUV_cjs = require('./chunk-PLIF5CUV.cjs');
|
|
11
|
-
var lucideReact = require('lucide-react');
|
|
12
|
-
var ui = require('@arbidocs/react/ui');
|
|
13
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
14
|
-
var react = require('react');
|
|
15
|
-
|
|
16
|
-
var isId = (v) => typeof v === "string" && v.trim() !== "";
|
|
17
|
-
var asList = (v) => Array.isArray(v) ? v : [];
|
|
18
|
-
var labelIds = (v) => asList(v).filter(isId);
|
|
19
|
-
var citations = (v) => asList(v).filter(
|
|
20
|
-
(c) => typeof c === "object" && c !== null && isId(c.doc_ext_id)
|
|
21
|
-
);
|
|
22
|
-
var nameOf = (id, row) => row.titles?.[id] ?? id;
|
|
23
|
-
var byText = (a, b) => a.localeCompare(b, void 0, { sensitivity: "base", numeric: true });
|
|
24
|
-
var emptiesLast = (ea, eb) => ea !== eb ? ea ? 1 : -1 : ea ? 0 : void 0;
|
|
25
|
-
var labelNames = (v, row) => labelIds(v).map((id) => nameOf(id, row)).join("; ");
|
|
26
|
-
var pagesOf = (c) => {
|
|
27
|
-
const pages = [];
|
|
28
|
-
for (const chunk of c.chunks ?? [])
|
|
29
|
-
if (typeof chunk.page === "number" && !pages.includes(chunk.page)) pages.push(chunk.page);
|
|
30
|
-
return pages;
|
|
31
|
-
};
|
|
32
|
-
var sameCitation = (a, b) => {
|
|
33
|
-
if (a.doc_ext_id !== b.doc_ext_id || (a.version ?? null) !== (b.version ?? null)) return false;
|
|
34
|
-
const ca = a.chunks ?? [];
|
|
35
|
-
const cb = b.chunks ?? [];
|
|
36
|
-
return ca.length === cb.length && ca.every((c, i) => c.chunk_id === cb[i].chunk_id && (c.page ?? null) === (cb[i].page ?? null));
|
|
37
|
-
};
|
|
38
|
-
var labelKit = {
|
|
39
|
-
icon: lucideReact.Tags,
|
|
40
|
-
width: 200,
|
|
41
|
-
labelKey: "label",
|
|
42
|
-
empty: (v) => labelIds(v).length === 0,
|
|
43
|
-
same: (a, b) => {
|
|
44
|
-
const sa = new Set(labelIds(a));
|
|
45
|
-
const sb = new Set(labelIds(b));
|
|
46
|
-
return sa.size === sb.size && [...sa].every((id) => sb.has(id));
|
|
47
|
-
},
|
|
48
|
-
format: (v, row) => labelNames(v, row),
|
|
49
|
-
toApi: (v) => {
|
|
50
|
-
const ids = [...new Set(labelIds(v))];
|
|
51
|
-
return ids.length > 0 ? ids : null;
|
|
52
|
-
},
|
|
53
|
-
compare: (a, b, ra, rb) => emptiesLast(labelKit.empty(a), labelKit.empty(b)) ?? byText(labelNames(a, ra), labelNames(b, rb)),
|
|
54
|
-
filterOps: ["contains", "neq", "empty", "not_empty"],
|
|
55
|
-
filterInput: "label",
|
|
56
|
-
canEditInGrid: (_c, s) => Boolean(s?.labels)
|
|
57
|
-
};
|
|
58
|
-
var sourceKit = {
|
|
59
|
-
icon: lucideReact.BookMarked,
|
|
60
|
-
width: 240,
|
|
61
|
-
labelKey: "source",
|
|
62
|
-
empty: (v) => citations(v).length === 0,
|
|
63
|
-
same: (a, b) => {
|
|
64
|
-
const la = citations(a);
|
|
65
|
-
const lb = citations(b);
|
|
66
|
-
return la.length === lb.length && la.every((c, i) => sameCitation(c, lb[i]));
|
|
67
|
-
},
|
|
68
|
-
format: (v, row) => citations(v).map((c) => {
|
|
69
|
-
const pages = pagesOf(c);
|
|
70
|
-
const name = nameOf(c.doc_ext_id, row);
|
|
71
|
-
return pages.length > 0 ? `${name} (${pages.map((p) => `p.${p}`).join(", ")})` : name;
|
|
72
|
-
}).join("; "),
|
|
73
|
-
toApi: (v) => {
|
|
74
|
-
const kept = citations(v);
|
|
75
|
-
return kept.length > 0 ? kept : null;
|
|
76
|
-
},
|
|
77
|
-
compare: (a, b, ra, rb) => {
|
|
78
|
-
const empty = emptiesLast(sourceKit.empty(a), sourceKit.empty(b));
|
|
79
|
-
if (empty !== void 0) return empty;
|
|
80
|
-
const ca = citations(a);
|
|
81
|
-
const cb = citations(b);
|
|
82
|
-
if (ca.length !== cb.length) return ca.length - cb.length;
|
|
83
|
-
return byText(nameOf(ca[0].doc_ext_id, ra), nameOf(cb[0].doc_ext_id, rb));
|
|
84
|
-
},
|
|
85
|
-
filterOps: ["contains", "empty", "not_empty"],
|
|
86
|
-
filterInput: "document",
|
|
87
|
-
canEditInGrid: () => false
|
|
88
|
-
};
|
|
89
|
-
var COLUMN_KITS = {
|
|
90
|
-
label: labelKit,
|
|
91
|
-
source: sourceKit
|
|
92
|
-
};
|
|
93
|
-
function kitOf(type) {
|
|
94
|
-
return type === "label" || type === "source" ? COLUMN_KITS[type] : void 0;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// src/databases/column-types.ts
|
|
98
|
-
var DATABASE_COLUMN_TYPES = [
|
|
99
|
-
"text",
|
|
100
|
-
"number",
|
|
101
|
-
"date",
|
|
102
|
-
"checkbox",
|
|
103
|
-
"select",
|
|
104
|
-
"person",
|
|
105
|
-
"document",
|
|
106
|
-
"relation",
|
|
107
|
-
"lookup",
|
|
108
|
-
"rollup"
|
|
109
|
-
];
|
|
110
|
-
var COMPUTED_COLUMN_TYPES = /* @__PURE__ */ new Set([
|
|
111
|
-
"lookup",
|
|
112
|
-
"rollup"
|
|
113
|
-
]);
|
|
114
|
-
var LINK_COLUMN_TYPES = /* @__PURE__ */ new Set([
|
|
115
|
-
"document",
|
|
116
|
-
"relation"
|
|
117
|
-
]);
|
|
118
|
-
var isComputedColumn = (column) => COMPUTED_COLUMN_TYPES.has(column.type);
|
|
119
|
-
var DATABASE_ROLLUP_OPS = ["count", "sum", "avg", "min", "max"];
|
|
120
|
-
var DEFAULT_DATABASE_COLUMN_TYPE_LABELS = {
|
|
121
|
-
text: "Text",
|
|
122
|
-
number: "Number",
|
|
123
|
-
date: "Date",
|
|
124
|
-
checkbox: "Checkbox",
|
|
125
|
-
select: "Select",
|
|
126
|
-
person: "Person",
|
|
127
|
-
// The same name as a `source` column: both hold a row's sources. A `document` column holds the
|
|
128
|
-
// documents; a `source` column also holds the passages cited in each.
|
|
129
|
-
document: "Sources",
|
|
130
|
-
relation: "Relation",
|
|
131
|
-
lookup: "Lookup",
|
|
132
|
-
rollup: "Rollup",
|
|
133
|
-
label: "Labels",
|
|
134
|
-
source: "Sources"
|
|
135
|
-
};
|
|
136
|
-
var OPTION_TONES = [
|
|
137
|
-
"bg-blue-bg text-blue-text",
|
|
138
|
-
"bg-green-bg text-green-text",
|
|
139
|
-
"bg-yellow-bg text-yellow-text",
|
|
140
|
-
"bg-purple-bg text-purple-text",
|
|
141
|
-
"bg-red-bg text-red-text",
|
|
142
|
-
"bg-gray-bg text-gray-text"
|
|
143
|
-
];
|
|
144
|
-
function optionTone(option) {
|
|
145
|
-
let hash = 0;
|
|
146
|
-
for (const ch of option.toLowerCase()) hash = hash * 31 + ch.charCodeAt(0) >>> 0;
|
|
147
|
-
return OPTION_TONES[hash % OPTION_TONES.length];
|
|
148
|
-
}
|
|
149
|
-
var isEmpty = (value) => value === null || value === void 0 || typeof value === "string" && value.trim() === "" || Array.isArray(value) && value.length === 0;
|
|
150
|
-
function cellList(value) {
|
|
151
|
-
if (isEmpty(value)) return [];
|
|
152
|
-
return Array.isArray(value) ? value.filter((v) => !isEmpty(v)) : [value];
|
|
153
|
-
}
|
|
154
|
-
function cellIds(value) {
|
|
155
|
-
return cellList(value).filter((v) => typeof v === "string");
|
|
156
|
-
}
|
|
157
|
-
function titleOf(id, titles) {
|
|
158
|
-
return titles?.[id] ?? id;
|
|
159
|
-
}
|
|
160
|
-
function sameCellValue(a, b, type) {
|
|
161
|
-
const kit = type ? kitOf(type) : void 0;
|
|
162
|
-
if (kit) return kit.same(a, b);
|
|
163
|
-
if (Array.isArray(a) || Array.isArray(b)) {
|
|
164
|
-
const la = cellList(a);
|
|
165
|
-
const lb = cellList(b);
|
|
166
|
-
return la.length === lb.length && la.every((v, i) => v === lb[i]);
|
|
167
|
-
}
|
|
168
|
-
return (a ?? null) === (b ?? null);
|
|
169
|
-
}
|
|
170
|
-
var kitRow = (titles) => ({
|
|
171
|
-
id: "",
|
|
172
|
-
values: {},
|
|
173
|
-
titles
|
|
174
|
-
});
|
|
175
|
-
var kitColumn = (type) => ({ id: "", name: "", type });
|
|
176
|
-
function formatDateValue(value, locale) {
|
|
177
|
-
const day = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
178
|
-
if (day) {
|
|
179
|
-
const [, y, m, d] = day;
|
|
180
|
-
return new Date(Date.UTC(+y, +m - 1, +d)).toLocaleDateString(locale, { timeZone: "UTC" });
|
|
181
|
-
}
|
|
182
|
-
const at = new Date(value);
|
|
183
|
-
return Number.isNaN(at.getTime()) ? value : at.toLocaleString(locale);
|
|
184
|
-
}
|
|
185
|
-
function formatNumberValue(value, locale) {
|
|
186
|
-
return value.toLocaleString(locale, { maximumFractionDigits: 6 });
|
|
187
|
-
}
|
|
188
|
-
var ISO_DATE = /^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
189
|
-
function formatLookupValue(value, titles, locale) {
|
|
190
|
-
if (isEmpty(value)) return "";
|
|
191
|
-
if (typeof value === "number") return formatNumberValue(value, locale);
|
|
192
|
-
if (typeof value === "boolean") return value ? "Yes" : "No";
|
|
193
|
-
if (typeof value === "string") {
|
|
194
|
-
if (titles?.[value] !== void 0) return titles[value];
|
|
195
|
-
if (ISO_DATE.test(value)) return formatDateValue(value, locale);
|
|
196
|
-
}
|
|
197
|
-
return String(value);
|
|
198
|
-
}
|
|
199
|
-
var NAMED_TYPES = /* @__PURE__ */ new Set([
|
|
200
|
-
"person",
|
|
201
|
-
"document",
|
|
202
|
-
"relation"
|
|
203
|
-
]);
|
|
204
|
-
function formatCell(value, type, locale, titles) {
|
|
205
|
-
if (isEmpty(value)) return "";
|
|
206
|
-
const kit = kitOf(type);
|
|
207
|
-
if (kit) return kit.format(value, kitRow(titles), kitColumn(type));
|
|
208
|
-
if ((type === "number" || type === "rollup") && typeof value === "number")
|
|
209
|
-
return formatNumberValue(value, locale);
|
|
210
|
-
if (type === "date" && typeof value === "string") return formatDateValue(value, locale);
|
|
211
|
-
if (type === "checkbox") return value ? "Yes" : "No";
|
|
212
|
-
if (NAMED_TYPES.has(type))
|
|
213
|
-
return cellIds(value).map((id) => titleOf(id, titles)).join(", ");
|
|
214
|
-
if (type === "lookup")
|
|
215
|
-
return cellList(value).map((v) => formatLookupValue(v, titles, locale)).join(", ");
|
|
216
|
-
return String(value);
|
|
217
|
-
}
|
|
218
|
-
function toApiValue(value, type) {
|
|
219
|
-
if (isEmpty(value)) return null;
|
|
220
|
-
const kit = kitOf(type);
|
|
221
|
-
if (kit) return kit.toApi(value);
|
|
222
|
-
if (LINK_COLUMN_TYPES.has(type)) return cellIds(value);
|
|
223
|
-
if (type === "checkbox") return Boolean(value);
|
|
224
|
-
if (type === "date" && value instanceof Date) {
|
|
225
|
-
const pad = (n) => String(n).padStart(2, "0");
|
|
226
|
-
return `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(value.getDate())}`;
|
|
227
|
-
}
|
|
228
|
-
if (type === "number" && typeof value === "string") {
|
|
229
|
-
const n = Number(value.replace(/,/g, ""));
|
|
230
|
-
return Number.isFinite(n) ? n : value;
|
|
231
|
-
}
|
|
232
|
-
return value;
|
|
233
|
-
}
|
|
234
|
-
function compareCells(a, b, type, titlesA, titlesB) {
|
|
235
|
-
const ea = isEmpty(a);
|
|
236
|
-
const eb = isEmpty(b);
|
|
237
|
-
if (ea || eb) return ea === eb ? 0 : ea ? 1 : -1;
|
|
238
|
-
const kit = kitOf(type);
|
|
239
|
-
if (kit) return kit.compare(a, b, kitRow(titlesA), kitRow(titlesB));
|
|
240
|
-
if (type === "number" || type === "checkbox" || type === "rollup") return Number(a) - Number(b);
|
|
241
|
-
const shown = NAMED_TYPES.has(type) || type === "lookup";
|
|
242
|
-
const ta = shown ? formatCell(a, type, void 0, titlesA) : String(a);
|
|
243
|
-
const tb = shown ? formatCell(b, type, void 0, titlesB) : String(b);
|
|
244
|
-
return ta.localeCompare(tb, void 0, { sensitivity: "base", numeric: true });
|
|
245
|
-
}
|
|
246
|
-
function rowTitle(row, columns, locale) {
|
|
247
|
-
const first = columns[0];
|
|
248
|
-
return first ? formatCell(row.values[first.id], first.type, locale, row.titles) : "";
|
|
249
|
-
}
|
|
250
|
-
var CHIP = "inline-flex h-[22px] min-w-0 max-w-[14rem] shrink-0 items-center gap-1 rounded-md border border-border bg-muted/50 px-1.5 text-xs text-foreground";
|
|
251
|
-
function initials(name) {
|
|
252
|
-
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
253
|
-
const letters = parts.length > 1 ? parts[0][0] + parts[parts.length - 1][0] : name.slice(0, 2);
|
|
254
|
-
return letters.toUpperCase();
|
|
255
|
-
}
|
|
256
|
-
function PersonChip({ name }) {
|
|
257
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex min-w-0 items-center gap-1.5 text-sm", children: [
|
|
258
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
259
|
-
"span",
|
|
260
|
-
{
|
|
261
|
-
"aria-hidden": true,
|
|
262
|
-
className: "flex size-5 shrink-0 items-center justify-center rounded-full bg-muted text-[10px] font-medium text-muted-foreground",
|
|
263
|
-
children: initials(name)
|
|
264
|
-
}
|
|
265
|
-
),
|
|
266
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: name })
|
|
267
|
-
] });
|
|
268
|
-
}
|
|
269
|
-
function LinkChip({
|
|
270
|
-
label,
|
|
271
|
-
kind,
|
|
272
|
-
onOpen,
|
|
273
|
-
testId,
|
|
274
|
-
openLabel,
|
|
275
|
-
className,
|
|
276
|
-
suffix
|
|
277
|
-
}) {
|
|
278
|
-
const Icon = kind === "document" ? lucideReact.FileText : lucideReact.ArrowUpRight;
|
|
279
|
-
const full = suffix ? `${label} ${suffix}` : label;
|
|
280
|
-
const body = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
281
|
-
/* @__PURE__ */ jsxRuntime.jsx(Icon, { className: "size-3 shrink-0 text-muted-foreground", "aria-hidden": true }),
|
|
282
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: label }),
|
|
283
|
-
suffix && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 tabular-nums text-muted-foreground", "data-slot": "chip-suffix", children: ` ${suffix}` })
|
|
284
|
-
] });
|
|
285
|
-
if (!onOpen) {
|
|
286
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", { className: ui.cn(CHIP, className), title: full, "data-testid": testId, children: body });
|
|
287
|
-
}
|
|
288
|
-
const stop = (e) => e.stopPropagation();
|
|
289
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
290
|
-
"button",
|
|
291
|
-
{
|
|
292
|
-
type: "button",
|
|
293
|
-
title: full,
|
|
294
|
-
"aria-label": openLabel,
|
|
295
|
-
"data-testid": testId,
|
|
296
|
-
onClick: (e) => {
|
|
297
|
-
e.stopPropagation();
|
|
298
|
-
onOpen();
|
|
299
|
-
},
|
|
300
|
-
onDoubleClick: stop,
|
|
301
|
-
onMouseDown: stop,
|
|
302
|
-
className: ui.cn(CHIP, "hover:bg-muted hover:underline", className),
|
|
303
|
-
children: body
|
|
304
|
-
}
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
function ChipRow({ children, wrap }) {
|
|
308
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
309
|
-
"span",
|
|
310
|
-
{
|
|
311
|
-
className: ui.cn(
|
|
312
|
-
"flex min-w-0 items-center gap-1",
|
|
313
|
-
wrap ? "flex-wrap py-0.5" : "h-full overflow-hidden"
|
|
314
|
-
),
|
|
315
|
-
children
|
|
316
|
-
}
|
|
317
|
-
);
|
|
318
|
-
}
|
|
319
|
-
function PersonCell({ value, titles }) {
|
|
320
|
-
const [id] = cellIds(value);
|
|
321
|
-
return id ? /* @__PURE__ */ jsxRuntime.jsx(PersonChip, { name: titleOf(id, titles) }) : null;
|
|
322
|
-
}
|
|
323
|
-
function LinkChipsCell({
|
|
324
|
-
value,
|
|
325
|
-
titles,
|
|
326
|
-
kind,
|
|
327
|
-
onOpenDocument,
|
|
328
|
-
wrap
|
|
329
|
-
}) {
|
|
330
|
-
const ids = cellIds(value);
|
|
331
|
-
if (ids.length === 0) return null;
|
|
332
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ChipRow, { wrap, children: ids.map((id) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
333
|
-
LinkChip,
|
|
334
|
-
{
|
|
335
|
-
label: titleOf(id, titles),
|
|
336
|
-
kind,
|
|
337
|
-
testId: `database-chip-${id}`,
|
|
338
|
-
onOpen: kind === "document" && onOpenDocument ? () => onOpenDocument(id) : void 0
|
|
339
|
-
},
|
|
340
|
-
id
|
|
341
|
-
)) });
|
|
342
|
-
}
|
|
343
|
-
function LookupCell({
|
|
344
|
-
value,
|
|
345
|
-
titles,
|
|
346
|
-
locale,
|
|
347
|
-
wrap
|
|
348
|
-
}) {
|
|
349
|
-
const values = cellList(value);
|
|
350
|
-
if (values.length === 0) return null;
|
|
351
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ChipRow, { wrap, children: values.map((v, i) => {
|
|
352
|
-
const text = formatLookupValue(v, titles, locale);
|
|
353
|
-
const key = `${i}-${text}`;
|
|
354
|
-
if (typeof v === "string" && /^doc-/.test(v))
|
|
355
|
-
return /* @__PURE__ */ jsxRuntime.jsx(LinkChip, { label: text, kind: "document" }, key);
|
|
356
|
-
if (typeof v === "string" && /^dbr-/.test(v))
|
|
357
|
-
return /* @__PURE__ */ jsxRuntime.jsx(LinkChip, { label: text, kind: "relation" }, key);
|
|
358
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
359
|
-
"span",
|
|
360
|
-
{
|
|
361
|
-
title: text,
|
|
362
|
-
className: "inline-flex h-[22px] min-w-0 max-w-[14rem] shrink-0 items-center truncate rounded-md bg-muted/60 px-1.5 text-xs text-foreground",
|
|
363
|
-
children: text
|
|
364
|
-
},
|
|
365
|
-
key
|
|
366
|
-
);
|
|
367
|
-
}) });
|
|
368
|
-
}
|
|
369
|
-
var MAX_SHOWN = 50;
|
|
370
|
-
var SEARCH_DEBOUNCE_MS = 200;
|
|
371
|
-
var DEFAULT_PICK_CELL_EDITOR_LABELS = {
|
|
372
|
-
searchPlaceholder: "Search\u2026",
|
|
373
|
-
noMatches: "No matches",
|
|
374
|
-
searching: "Searching\u2026",
|
|
375
|
-
clear: "Clear",
|
|
376
|
-
done: "Done",
|
|
377
|
-
remove: (label) => `Remove ${label}`
|
|
378
|
-
};
|
|
379
|
-
function useChoices(query, options, search) {
|
|
380
|
-
const [found, setFound] = react.useState([]);
|
|
381
|
-
const [loading, setLoading] = react.useState(Boolean(search));
|
|
382
|
-
react.useEffect(() => {
|
|
383
|
-
if (!search) return;
|
|
384
|
-
let live = true;
|
|
385
|
-
setLoading(true);
|
|
386
|
-
const t = setTimeout(
|
|
387
|
-
() => {
|
|
388
|
-
search(query.trim()).then((rows) => live && setFound(rows)).catch(() => live && setFound([])).finally(() => live && setLoading(false));
|
|
389
|
-
},
|
|
390
|
-
query ? SEARCH_DEBOUNCE_MS : 0
|
|
391
|
-
);
|
|
392
|
-
return () => {
|
|
393
|
-
live = false;
|
|
394
|
-
clearTimeout(t);
|
|
395
|
-
};
|
|
396
|
-
}, [query, search]);
|
|
397
|
-
const filtered = react.useMemo(() => {
|
|
398
|
-
if (search) return found.slice(0, MAX_SHOWN);
|
|
399
|
-
const q = query.trim().toLowerCase();
|
|
400
|
-
const all = options ?? [];
|
|
401
|
-
const hits = q ? all.filter(
|
|
402
|
-
(o) => o.label.toLowerCase().includes(q) || (o.description ?? "").toLowerCase().includes(q)
|
|
403
|
-
) : all;
|
|
404
|
-
return hits.slice(0, MAX_SHOWN);
|
|
405
|
-
}, [found, options, query, search]);
|
|
406
|
-
return { choices: filtered, loading: Boolean(search) && loading };
|
|
407
|
-
}
|
|
408
|
-
function PickCellEditor(props) {
|
|
409
|
-
const { value, onValueChange, stopEditing, data, kind, options, search } = props;
|
|
410
|
-
const l = { ...DEFAULT_PICK_CELL_EDITOR_LABELS, ...props.labels };
|
|
411
|
-
const multiple = kind !== "person";
|
|
412
|
-
const [chosen, setChosen] = react.useState(() => cellIds(value));
|
|
413
|
-
const [query, setQuery] = react.useState("");
|
|
414
|
-
const [active, setActive] = react.useState(0);
|
|
415
|
-
const input = react.useRef(null);
|
|
416
|
-
const { choices, loading } = useChoices(query, options, search);
|
|
417
|
-
const names = react.useRef({ ...data?.titles ?? {} });
|
|
418
|
-
for (const o of options ?? []) names.current[o.id] ??= o.label;
|
|
419
|
-
for (const o of choices) names.current[o.id] = o.label;
|
|
420
|
-
const nameOf2 = (id) => names.current[id] ?? id;
|
|
421
|
-
react.useEffect(() => input.current?.focus(), []);
|
|
422
|
-
react.useEffect(() => setActive(0), [query]);
|
|
423
|
-
const commit = (ids) => {
|
|
424
|
-
setChosen(ids);
|
|
425
|
-
if (data) {
|
|
426
|
-
const titles = { ...data.titles ?? {} };
|
|
427
|
-
for (const id of ids) titles[id] ??= nameOf2(id);
|
|
428
|
-
data.titles = titles;
|
|
429
|
-
}
|
|
430
|
-
onValueChange(multiple ? ids : ids[0] ?? null);
|
|
431
|
-
};
|
|
432
|
-
const close = () => setTimeout(() => stopEditing(), 0);
|
|
433
|
-
const toggle = (id) => {
|
|
434
|
-
if (!multiple) {
|
|
435
|
-
commit([id]);
|
|
436
|
-
close();
|
|
437
|
-
return;
|
|
438
|
-
}
|
|
439
|
-
commit(chosen.includes(id) ? chosen.filter((x) => x !== id) : [...chosen, id]);
|
|
440
|
-
};
|
|
441
|
-
const onKeyDown = (e) => {
|
|
442
|
-
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
443
|
-
e.preventDefault();
|
|
444
|
-
e.stopPropagation();
|
|
445
|
-
if (choices.length === 0) return;
|
|
446
|
-
const step = e.key === "ArrowDown" ? 1 : -1;
|
|
447
|
-
setActive((i) => (i + step + choices.length) % choices.length);
|
|
448
|
-
} else if (e.key === "Enter") {
|
|
449
|
-
e.preventDefault();
|
|
450
|
-
e.stopPropagation();
|
|
451
|
-
const pick = choices[active];
|
|
452
|
-
if (pick) toggle(pick.id);
|
|
453
|
-
else if (multiple) close();
|
|
454
|
-
} else if (e.key === "Backspace" && multiple && !query && chosen.length > 0) {
|
|
455
|
-
commit(chosen.slice(0, -1));
|
|
456
|
-
} else if (e.key === "ArrowLeft" || e.key === "ArrowRight" || e.key === "Home" || e.key === "End") {
|
|
457
|
-
e.stopPropagation();
|
|
458
|
-
}
|
|
459
|
-
};
|
|
460
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
461
|
-
"div",
|
|
462
|
-
{
|
|
463
|
-
"data-testid": "database-pick-editor",
|
|
464
|
-
className: "flex w-72 flex-col rounded-md border border-border bg-popover shadow-md",
|
|
465
|
-
children: [
|
|
466
|
-
multiple && chosen.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-1 border-b border-border p-1.5", children: chosen.map((id) => /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "inline-flex min-w-0 items-center", children: [
|
|
467
|
-
/* @__PURE__ */ jsxRuntime.jsx(LinkChip, { label: nameOf2(id), kind: kind === "document" ? "document" : "relation" }),
|
|
468
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
469
|
-
"button",
|
|
470
|
-
{
|
|
471
|
-
type: "button",
|
|
472
|
-
"aria-label": l.remove(nameOf2(id)),
|
|
473
|
-
onClick: () => commit(chosen.filter((x) => x !== id)),
|
|
474
|
-
"data-testid": `database-pick-remove-${id}`,
|
|
475
|
-
className: "rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground",
|
|
476
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "size-3" })
|
|
477
|
-
}
|
|
478
|
-
)
|
|
479
|
-
] }, id)) }),
|
|
480
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-1.5 border-b border-border px-2", children: [
|
|
481
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Search, { className: "size-3.5 shrink-0 text-muted-foreground", "aria-hidden": true }),
|
|
482
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
483
|
-
"input",
|
|
484
|
-
{
|
|
485
|
-
ref: input,
|
|
486
|
-
value: query,
|
|
487
|
-
placeholder: l.searchPlaceholder,
|
|
488
|
-
onChange: (e) => setQuery(e.target.value),
|
|
489
|
-
onKeyDown,
|
|
490
|
-
"data-testid": "database-pick-search",
|
|
491
|
-
className: "h-8 min-w-0 flex-1 bg-transparent text-sm outline-none placeholder:text-muted-foreground"
|
|
492
|
-
}
|
|
493
|
-
),
|
|
494
|
-
loading && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "size-3.5 animate-spin text-muted-foreground" })
|
|
495
|
-
] }),
|
|
496
|
-
/* @__PURE__ */ jsxRuntime.jsxs("div", { role: "listbox", "aria-multiselectable": multiple, className: "max-h-64 overflow-y-auto p-1", children: [
|
|
497
|
-
choices.map((o, i) => {
|
|
498
|
-
const isChosen = chosen.includes(o.id);
|
|
499
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
500
|
-
"button",
|
|
501
|
-
{
|
|
502
|
-
type: "button",
|
|
503
|
-
role: "option",
|
|
504
|
-
"aria-selected": isChosen,
|
|
505
|
-
onMouseEnter: () => setActive(i),
|
|
506
|
-
onClick: () => toggle(o.id),
|
|
507
|
-
"data-testid": `database-pick-option-${o.id}`,
|
|
508
|
-
className: ui.cn(
|
|
509
|
-
"flex w-full items-center gap-2 rounded px-2 py-1 text-left text-sm",
|
|
510
|
-
i === active && "bg-muted"
|
|
511
|
-
),
|
|
512
|
-
children: [
|
|
513
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex min-w-0 flex-1 flex-col", children: [
|
|
514
|
-
kind === "person" ? /* @__PURE__ */ jsxRuntime.jsx(PersonChip, { name: o.label }) : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: o.label }),
|
|
515
|
-
o.description && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-xs text-muted-foreground", children: o.description })
|
|
516
|
-
] }),
|
|
517
|
-
isChosen && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "size-3.5 shrink-0" })
|
|
518
|
-
]
|
|
519
|
-
},
|
|
520
|
-
o.id
|
|
521
|
-
);
|
|
522
|
-
}),
|
|
523
|
-
choices.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "px-2 py-1.5 text-sm text-muted-foreground", children: loading ? l.searching : l.noMatches })
|
|
524
|
-
] }),
|
|
525
|
-
(multiple || chosen.length > 0) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-end border-t border-border p-1", children: !multiple ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
526
|
-
"button",
|
|
527
|
-
{
|
|
528
|
-
type: "button",
|
|
529
|
-
onClick: () => {
|
|
530
|
-
commit([]);
|
|
531
|
-
close();
|
|
532
|
-
},
|
|
533
|
-
"data-testid": "database-pick-clear",
|
|
534
|
-
className: "rounded px-2 py-1 text-sm text-muted-foreground hover:bg-muted",
|
|
535
|
-
children: l.clear
|
|
536
|
-
}
|
|
537
|
-
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
538
|
-
"button",
|
|
539
|
-
{
|
|
540
|
-
type: "button",
|
|
541
|
-
onClick: close,
|
|
542
|
-
"data-testid": "database-pick-done",
|
|
543
|
-
className: "rounded px-2 py-1 text-sm font-medium hover:bg-muted",
|
|
544
|
-
children: l.done
|
|
545
|
-
}
|
|
546
|
-
) })
|
|
547
|
-
]
|
|
548
|
-
}
|
|
549
|
-
);
|
|
550
|
-
}
|
|
551
|
-
var optionTestId = (id) => `database-label-option-${id}`;
|
|
552
|
-
function LabelsCell({ value, titles, labels, onChange, rowHeight }) {
|
|
553
|
-
const ids = cellIds(value);
|
|
554
|
-
if (labels && onChange) {
|
|
555
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
556
|
-
chunkKHZEFLQC_cjs.FactLabelsCell,
|
|
557
|
-
{
|
|
558
|
-
options: labels.options,
|
|
559
|
-
selectedIds: ids,
|
|
560
|
-
onChange,
|
|
561
|
-
onCreate: labels.onCreate,
|
|
562
|
-
rowHeight,
|
|
563
|
-
compact: true,
|
|
564
|
-
testIds: { option: optionTestId }
|
|
565
|
-
}
|
|
566
|
-
);
|
|
567
|
-
}
|
|
568
|
-
if (ids.length === 0) return null;
|
|
569
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
570
|
-
"div",
|
|
571
|
-
{
|
|
572
|
-
className: rowHeight === void 0 ? "flex min-w-0 flex-wrap items-center gap-1" : "flex min-w-0 flex-wrap content-start gap-1 overflow-hidden",
|
|
573
|
-
style: rowHeight === void 0 ? void 0 : { maxHeight: chunkKHZEFLQC_cjs.labelChipsMaxHeight(rowHeight, true) },
|
|
574
|
-
title: rowHeight === void 0 ? void 0 : ids.map((id) => titleOf(id, titles)).join(", "),
|
|
575
|
-
children: ids.map((id) => /* @__PURE__ */ jsxRuntime.jsx(chunkKHZEFLQC_cjs.LabelChip, { name: titleOf(id, titles), color: ui.getEntityColor(id, "medium") }, id))
|
|
576
|
-
}
|
|
577
|
-
);
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
// src/databases/sourcesOverflow.ts
|
|
581
|
-
function hiddenAfterRows(tops, rows = 1) {
|
|
582
|
-
const shown = [...new Set(tops)].sort((a, b) => a - b)[rows - 1];
|
|
583
|
-
if (shown === void 0) return 0;
|
|
584
|
-
return tops.filter((top) => top > shown).length;
|
|
585
|
-
}
|
|
586
|
-
var CHIP_HEIGHT = 22;
|
|
587
|
-
var CHIP_GAP = 4;
|
|
588
|
-
var CELL_PAD_Y = 16;
|
|
589
|
-
var defaultMoreLabel = (count) => `${count} more: open the row`;
|
|
590
|
-
var citationKey = (cites, index) => {
|
|
591
|
-
const c = cites[index];
|
|
592
|
-
return `${c.doc_ext_id}:${c.version ?? ""}:${index}`;
|
|
593
|
-
};
|
|
594
|
-
var citationTestId = (cites, index) => {
|
|
595
|
-
const id = cites[index].doc_ext_id;
|
|
596
|
-
return cites.findIndex((c) => c.doc_ext_id === id) < index ? `${id}-${index}` : id;
|
|
597
|
-
};
|
|
598
|
-
function citationsOf(value) {
|
|
599
|
-
return cellList(value).filter(
|
|
600
|
-
(v) => typeof v === "object" && v !== null && typeof v.doc_ext_id === "string"
|
|
601
|
-
);
|
|
602
|
-
}
|
|
603
|
-
var MORE_CHIP = "inline-flex h-[22px] shrink-0 items-center rounded-md border border-border bg-muted/50 px-1.5 text-xs text-muted-foreground";
|
|
604
|
-
function SourcesCell({
|
|
605
|
-
value,
|
|
606
|
-
titles,
|
|
607
|
-
onOpen,
|
|
608
|
-
openLabel,
|
|
609
|
-
moreLabel = defaultMoreLabel,
|
|
610
|
-
rowHeight
|
|
611
|
-
}) {
|
|
612
|
-
const cites = citationsOf(value);
|
|
613
|
-
const chips = cites.map((c) => {
|
|
614
|
-
const count = c.chunks?.length ?? 0;
|
|
615
|
-
return { name: titleOf(c.doc_ext_id, titles), count: count > 0 ? `(${count})` : void 0 };
|
|
616
|
-
});
|
|
617
|
-
const names = chips.map((chip) => chip.count ? `${chip.name} ${chip.count}` : chip.name);
|
|
618
|
-
const rows = rowHeight === void 0 ? 1 : Math.max(1, Math.floor((rowHeight - CELL_PAD_Y + CHIP_GAP) / (CHIP_HEIGHT + CHIP_GAP)));
|
|
619
|
-
const row = react.useRef(null);
|
|
620
|
-
const [hidden, setHidden] = react.useState(0);
|
|
621
|
-
const signature = cites.map((c) => c.doc_ext_id).join("|");
|
|
622
|
-
react.useLayoutEffect(() => {
|
|
623
|
-
const el = row.current;
|
|
624
|
-
if (!el) return;
|
|
625
|
-
const measure = () => {
|
|
626
|
-
const next = hiddenAfterRows(
|
|
627
|
-
Array.from(el.children, (child) => child.offsetTop),
|
|
628
|
-
rows
|
|
629
|
-
);
|
|
630
|
-
setHidden((prev) => prev === next ? prev : next);
|
|
631
|
-
};
|
|
632
|
-
measure();
|
|
633
|
-
return chunkPPCATBOY_cjs.observeResize(el, measure);
|
|
634
|
-
}, [signature, titles, rows]);
|
|
635
|
-
if (cites.length === 0) return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: "\u2013" });
|
|
636
|
-
const more = hidden > 0 ? names.slice(-hidden).join("\n") : void 0;
|
|
637
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex w-full min-w-0 items-center gap-1", children: [
|
|
638
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
639
|
-
"div",
|
|
640
|
-
{
|
|
641
|
-
ref: row,
|
|
642
|
-
className: "flex min-w-0 flex-1 flex-wrap content-start gap-1 overflow-hidden",
|
|
643
|
-
style: { maxHeight: rows * CHIP_HEIGHT + (rows - 1) * CHIP_GAP },
|
|
644
|
-
children: cites.map((c, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
645
|
-
LinkChip,
|
|
646
|
-
{
|
|
647
|
-
kind: "document",
|
|
648
|
-
label: chips[i].name,
|
|
649
|
-
suffix: chips[i].count,
|
|
650
|
-
onOpen,
|
|
651
|
-
openLabel: onOpen && openLabel ? openLabel(names[i]) : void 0,
|
|
652
|
-
testId: `database-source-chip-${citationTestId(cites, i)}`,
|
|
653
|
-
className: "max-w-full"
|
|
654
|
-
},
|
|
655
|
-
citationKey(cites, i)
|
|
656
|
-
))
|
|
657
|
-
}
|
|
658
|
-
),
|
|
659
|
-
hidden > 0 && (onOpen ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
660
|
-
"button",
|
|
661
|
-
{
|
|
662
|
-
type: "button",
|
|
663
|
-
title: more,
|
|
664
|
-
"aria-label": moreLabel(hidden),
|
|
665
|
-
"data-testid": "database-source-more",
|
|
666
|
-
onClick: (e) => {
|
|
667
|
-
e.stopPropagation();
|
|
668
|
-
onOpen();
|
|
669
|
-
},
|
|
670
|
-
onDoubleClick: (e) => e.stopPropagation(),
|
|
671
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
672
|
-
className: `${MORE_CHIP} hover:bg-muted`,
|
|
673
|
-
children: `+${hidden}`
|
|
674
|
-
}
|
|
675
|
-
) : /* @__PURE__ */ jsxRuntime.jsx("span", { title: more, "data-testid": "database-source-more", className: MORE_CHIP, children: `+${hidden}` }))
|
|
676
|
-
] });
|
|
677
|
-
}
|
|
678
|
-
function DateSpanField({ value, onCommit, idPrefix }) {
|
|
679
|
-
const baseline = chunkGISMY7J7_cjs.factDateSpanToFields(value.start, value.end, value.timezone);
|
|
680
|
-
const [draft, setDraft] = react.useState(baseline);
|
|
681
|
-
react.useEffect(
|
|
682
|
-
() => setDraft(chunkGISMY7J7_cjs.factDateSpanToFields(value.start, value.end, value.timezone)),
|
|
683
|
-
[value.start, value.end, value.timezone]
|
|
684
|
-
);
|
|
685
|
-
const cancelled = react.useRef(false);
|
|
686
|
-
const commit = () => {
|
|
687
|
-
if (cancelled.current) {
|
|
688
|
-
cancelled.current = false;
|
|
689
|
-
setDraft(baseline);
|
|
690
|
-
return;
|
|
691
|
-
}
|
|
692
|
-
if (JSON.stringify(draft) === JSON.stringify(baseline)) return;
|
|
693
|
-
const span = chunkGISMY7J7_cjs.factDateFieldsToSpan(draft);
|
|
694
|
-
onCommit({ start: span.date, end: span.date_end, timezone: span.timezone });
|
|
695
|
-
};
|
|
696
|
-
return (
|
|
697
|
-
// The popover is drawn elsewhere on the page, but its keys still pass through here.
|
|
698
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
699
|
-
"div",
|
|
700
|
-
{
|
|
701
|
-
onKeyDownCapture: (e) => {
|
|
702
|
-
if (e.key === "Escape") cancelled.current = true;
|
|
703
|
-
},
|
|
704
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
705
|
-
chunkKHZEFLQC_cjs.FactDateInput,
|
|
706
|
-
{
|
|
707
|
-
value: draft,
|
|
708
|
-
onChange: setDraft,
|
|
709
|
-
idPrefix,
|
|
710
|
-
onOpenChange: (open) => {
|
|
711
|
-
if (open) cancelled.current = false;
|
|
712
|
-
else commit();
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
)
|
|
716
|
-
}
|
|
717
|
-
)
|
|
718
|
-
);
|
|
719
|
-
}
|
|
720
|
-
var TYPED_DATE = /^\d{4}(-\d{2})?(-\d{2})?$/;
|
|
721
|
-
var DEFAULT_DATE_SPAN_EDITOR_LABELS = {
|
|
722
|
-
edit: (name) => `Edit ${name}`,
|
|
723
|
-
invalid: "Enter a date as YYYY, YYYY-MM or YYYY-MM-DD.",
|
|
724
|
-
placeholder: "YYYY, YYYY-MM or YYYY-MM-DD"
|
|
725
|
-
};
|
|
726
|
-
var startText = (value, end, timezone) => {
|
|
727
|
-
const start = typeof value === "string" ? value : value?.start;
|
|
728
|
-
if (typeof start !== "string") return "";
|
|
729
|
-
return chunkGISMY7J7_cjs.factDateSpanToFields(start, end, timezone).date || start.slice(0, 10);
|
|
730
|
-
};
|
|
731
|
-
var typedTime = (typed) => Date.parse(`${typed}${"-01-01".slice(typed.length - 4)}`);
|
|
732
|
-
var textOf = (v) => typeof v === "string" && v ? v : null;
|
|
733
|
-
function DateSpanCellEditor({
|
|
734
|
-
value,
|
|
735
|
-
data,
|
|
736
|
-
endColumnId,
|
|
737
|
-
timezoneColumnId,
|
|
738
|
-
labels,
|
|
739
|
-
columnName = "",
|
|
740
|
-
onValueChange,
|
|
741
|
-
stopEditing
|
|
742
|
-
}) {
|
|
743
|
-
const l = { ...DEFAULT_DATE_SPAN_EDITOR_LABELS, ...labels };
|
|
744
|
-
const [original] = react.useState(value);
|
|
745
|
-
const [storedEnd] = react.useState(
|
|
746
|
-
() => textOf(endColumnId ? data?.values[endColumnId] : value?.end)
|
|
747
|
-
);
|
|
748
|
-
const [storedZone] = react.useState(
|
|
749
|
-
() => textOf(
|
|
750
|
-
timezoneColumnId ? data?.values[timezoneColumnId] : value?.timezone
|
|
751
|
-
)
|
|
752
|
-
);
|
|
753
|
-
const [opened] = react.useState(() => startText(value, storedEnd, storedZone));
|
|
754
|
-
const [text, setText] = react.useState(opened);
|
|
755
|
-
const [invalid, setInvalid] = react.useState(false);
|
|
756
|
-
const input = react.useRef(null);
|
|
757
|
-
react.useEffect(() => input.current?.focus(), []);
|
|
758
|
-
const spanFor = (typed) => {
|
|
759
|
-
if (!typed) return { start: null, end: null, timezone: null };
|
|
760
|
-
const keep = storedEnd !== null && typedTime(typed) <= Date.parse(storedEnd);
|
|
761
|
-
return { start: typed, end: keep ? storedEnd : null, timezone: keep ? storedZone : null };
|
|
762
|
-
};
|
|
763
|
-
const follow = (next) => {
|
|
764
|
-
const typed = next.trim();
|
|
765
|
-
if ((!typed || TYPED_DATE.test(typed)) && typed !== opened) {
|
|
766
|
-
onValueChange(spanFor(typed));
|
|
767
|
-
} else {
|
|
768
|
-
onValueChange(original);
|
|
769
|
-
}
|
|
770
|
-
};
|
|
771
|
-
const onKeyDown = (e) => {
|
|
772
|
-
if (e.key === "Escape") {
|
|
773
|
-
e.stopPropagation();
|
|
774
|
-
stopEditing(true);
|
|
775
|
-
} else if (e.key === "Enter") {
|
|
776
|
-
e.preventDefault();
|
|
777
|
-
e.stopPropagation();
|
|
778
|
-
const typed = text.trim();
|
|
779
|
-
if (typed && !TYPED_DATE.test(typed)) {
|
|
780
|
-
setInvalid(true);
|
|
781
|
-
return;
|
|
782
|
-
}
|
|
783
|
-
if (typed === opened) {
|
|
784
|
-
stopEditing(true);
|
|
785
|
-
return;
|
|
786
|
-
}
|
|
787
|
-
setTimeout(() => stopEditing(), 0);
|
|
788
|
-
}
|
|
789
|
-
};
|
|
790
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative h-full", children: [
|
|
791
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
792
|
-
ui.Input,
|
|
793
|
-
{
|
|
794
|
-
ref: input,
|
|
795
|
-
value: text,
|
|
796
|
-
"aria-label": l.edit(columnName),
|
|
797
|
-
"aria-invalid": invalid,
|
|
798
|
-
"aria-describedby": invalid ? "database-date-span-error" : void 0,
|
|
799
|
-
placeholder: l.placeholder,
|
|
800
|
-
onChange: (e) => {
|
|
801
|
-
setText(e.target.value);
|
|
802
|
-
follow(e.target.value);
|
|
803
|
-
setInvalid(false);
|
|
804
|
-
},
|
|
805
|
-
onKeyDown,
|
|
806
|
-
className: "h-full rounded-none",
|
|
807
|
-
"data-testid": "database-date-span-editor"
|
|
808
|
-
}
|
|
809
|
-
),
|
|
810
|
-
invalid && /* @__PURE__ */ jsxRuntime.jsx(
|
|
811
|
-
"p",
|
|
812
|
-
{
|
|
813
|
-
id: "database-date-span-error",
|
|
814
|
-
role: "alert",
|
|
815
|
-
className: "absolute left-0 top-full z-10 rounded-sm border bg-popover px-2 py-1 text-xs text-destructive shadow-md",
|
|
816
|
-
children: l.invalid
|
|
817
|
-
}
|
|
818
|
-
)
|
|
819
|
-
] });
|
|
820
|
-
}
|
|
821
|
-
function SelectChip({ value }) {
|
|
822
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
823
|
-
"span",
|
|
824
|
-
{
|
|
825
|
-
className: ui.cn(
|
|
826
|
-
"inline-flex max-w-full items-center truncate rounded-md px-2 py-0.5 text-xs font-medium",
|
|
827
|
-
optionTone(value)
|
|
828
|
-
),
|
|
829
|
-
children: value
|
|
830
|
-
}
|
|
831
|
-
);
|
|
832
|
-
}
|
|
833
|
-
function SelectCellEditor(props) {
|
|
834
|
-
const { value, onValueChange, stopEditing, options, clearLabel = "Clear" } = props;
|
|
835
|
-
const items = [...options, null];
|
|
836
|
-
const [active, setActive] = react.useState(() => Math.max(0, options.indexOf(String(value ?? ""))));
|
|
837
|
-
const list = react.useRef(null);
|
|
838
|
-
react.useEffect(() => list.current?.focus(), []);
|
|
839
|
-
const pick = (option) => {
|
|
840
|
-
onValueChange(option);
|
|
841
|
-
setTimeout(() => stopEditing(), 0);
|
|
842
|
-
};
|
|
843
|
-
const onKeyDown = (e) => {
|
|
844
|
-
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
|
845
|
-
e.preventDefault();
|
|
846
|
-
e.stopPropagation();
|
|
847
|
-
const step = e.key === "ArrowDown" ? 1 : -1;
|
|
848
|
-
setActive((i) => (i + step + items.length) % items.length);
|
|
849
|
-
} else if (e.key === "Enter") {
|
|
850
|
-
e.preventDefault();
|
|
851
|
-
e.stopPropagation();
|
|
852
|
-
pick(items[active]);
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
856
|
-
"div",
|
|
857
|
-
{
|
|
858
|
-
ref: list,
|
|
859
|
-
role: "listbox",
|
|
860
|
-
tabIndex: -1,
|
|
861
|
-
onKeyDown,
|
|
862
|
-
"data-testid": "database-select-editor",
|
|
863
|
-
className: "flex min-w-44 flex-col gap-0.5 rounded-md border border-border bg-popover p-1 shadow-md outline-none",
|
|
864
|
-
children: items.map((option, i) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
865
|
-
"button",
|
|
866
|
-
{
|
|
867
|
-
type: "button",
|
|
868
|
-
role: "option",
|
|
869
|
-
"aria-selected": option === value,
|
|
870
|
-
onMouseEnter: () => setActive(i),
|
|
871
|
-
onClick: () => pick(option),
|
|
872
|
-
"data-testid": option === null ? "database-select-clear" : `database-select-option-${option}`,
|
|
873
|
-
className: ui.cn(
|
|
874
|
-
"flex items-center gap-2 rounded px-2 py-1 text-left text-sm",
|
|
875
|
-
i === active && "bg-muted"
|
|
876
|
-
),
|
|
877
|
-
children: [
|
|
878
|
-
option === null ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground", children: clearLabel }) : /* @__PURE__ */ jsxRuntime.jsx(SelectChip, { value: option }),
|
|
879
|
-
option !== null && option === value && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { className: "ml-auto size-3.5" })
|
|
880
|
-
]
|
|
881
|
-
},
|
|
882
|
-
option ?? "__clear"
|
|
883
|
-
))
|
|
884
|
-
}
|
|
885
|
-
);
|
|
886
|
-
}
|
|
887
|
-
var DEFAULT_DATABASE_COLUMN_LABELS = {
|
|
888
|
-
addColumn: "Add a column",
|
|
889
|
-
columnSettings: (name) => `${name} column settings`,
|
|
890
|
-
computed: "Computed from a relation (read-only)",
|
|
891
|
-
openRow: "Open row",
|
|
892
|
-
dateSpanEditor: DEFAULT_DATE_SPAN_EDITOR_LABELS,
|
|
893
|
-
openRowFromSource: (title) => `${title}: open the row`
|
|
894
|
-
};
|
|
895
|
-
var ADD_COLUMN_COL_ID = "__add_column";
|
|
896
|
-
var OPEN_ROW_COL_ID = "__open_row";
|
|
897
|
-
var ROW_ACTIONS_COL_ID = "__row_actions";
|
|
898
|
-
var COLUMN_TYPE_ICONS = {
|
|
899
|
-
text: lucideReact.Type,
|
|
900
|
-
number: lucideReact.Hash,
|
|
901
|
-
date: lucideReact.CalendarDays,
|
|
902
|
-
checkbox: lucideReact.CheckSquare,
|
|
903
|
-
select: lucideReact.ChevronDown,
|
|
904
|
-
person: lucideReact.UserRound,
|
|
905
|
-
document: COLUMN_KITS.source.icon,
|
|
906
|
-
relation: lucideReact.ArrowUpRight,
|
|
907
|
-
lookup: lucideReact.Search,
|
|
908
|
-
rollup: lucideReact.Sigma,
|
|
909
|
-
label: COLUMN_KITS.label.icon,
|
|
910
|
-
source: COLUMN_KITS.source.icon
|
|
911
|
-
};
|
|
912
|
-
var WIDTHS = {
|
|
913
|
-
text: 220,
|
|
914
|
-
number: 130,
|
|
915
|
-
date: 140,
|
|
916
|
-
checkbox: 110,
|
|
917
|
-
select: 160,
|
|
918
|
-
person: 180,
|
|
919
|
-
document: 240,
|
|
920
|
-
relation: 240,
|
|
921
|
-
lookup: 200,
|
|
922
|
-
rollup: 130,
|
|
923
|
-
label: COLUMN_KITS.label.width,
|
|
924
|
-
source: COLUMN_KITS.source.width
|
|
925
|
-
};
|
|
926
|
-
function HeaderLabel({
|
|
927
|
-
dbColumn: column,
|
|
928
|
-
onEdit,
|
|
929
|
-
settingsLabel: label,
|
|
930
|
-
computedLabel
|
|
931
|
-
}) {
|
|
932
|
-
const Icon = COLUMN_TYPE_ICONS[column.type];
|
|
933
|
-
return /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "group/dbh flex min-w-0 items-center gap-1.5", children: [
|
|
934
|
-
/* @__PURE__ */ jsxRuntime.jsx(Icon, { className: "size-3.5 shrink-0 text-muted-foreground", "aria-hidden": true }),
|
|
935
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-[12.5px] font-medium", children: column.name }),
|
|
936
|
-
isComputedColumn(column) && /* @__PURE__ */ jsxRuntime.jsx("span", { title: computedLabel, "data-testid": `database-column-computed-${column.id}`, children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Lock, { className: "size-3 shrink-0 text-muted-foreground/70", "aria-label": computedLabel }) }),
|
|
937
|
-
onEdit && /* @__PURE__ */ jsxRuntime.jsx(
|
|
938
|
-
"button",
|
|
939
|
-
{
|
|
940
|
-
type: "button",
|
|
941
|
-
"aria-label": label,
|
|
942
|
-
title: label,
|
|
943
|
-
"data-testid": `database-column-settings-${column.id}`,
|
|
944
|
-
onClick: (e) => {
|
|
945
|
-
e.stopPropagation();
|
|
946
|
-
onEdit();
|
|
947
|
-
},
|
|
948
|
-
onMouseDown: (e) => e.stopPropagation(),
|
|
949
|
-
className: "ml-auto rounded p-0.5 text-muted-foreground opacity-0 hover:bg-muted hover:text-foreground focus-visible:opacity-100 group-hover/dbh:opacity-100",
|
|
950
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.MoreHorizontal, { className: "size-3.5" })
|
|
951
|
-
}
|
|
952
|
-
)
|
|
953
|
-
] });
|
|
954
|
-
}
|
|
955
|
-
function AddColumnHeader({ addLabel, onAddColumn }) {
|
|
956
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
957
|
-
"button",
|
|
958
|
-
{
|
|
959
|
-
type: "button",
|
|
960
|
-
"aria-label": addLabel,
|
|
961
|
-
title: addLabel,
|
|
962
|
-
"data-testid": "database-add-column",
|
|
963
|
-
onClick: onAddColumn,
|
|
964
|
-
className: "flex size-7 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground",
|
|
965
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { className: "size-4" })
|
|
966
|
-
}
|
|
967
|
-
);
|
|
968
|
-
}
|
|
969
|
-
function columnWidth(column) {
|
|
970
|
-
const header = Math.round(column.name.length * 8) + 76 + (isComputedColumn(column) ? 16 : 0);
|
|
971
|
-
return Math.min(320, Math.max(WIDTHS[column.type], header));
|
|
972
|
-
}
|
|
973
|
-
var positive = (n) => typeof n === "number" && Number.isFinite(n) && n > 0 ? n : void 0;
|
|
974
|
-
function sizing(column) {
|
|
975
|
-
const grow = positive(column.grow);
|
|
976
|
-
if (grow !== void 0) {
|
|
977
|
-
return { flex: grow, minWidth: positive(column.minWidth) ?? columnWidth(column) };
|
|
978
|
-
}
|
|
979
|
-
return {
|
|
980
|
-
width: positive(column.width) ?? columnWidth(column),
|
|
981
|
-
minWidth: positive(column.minWidth) ?? 90
|
|
982
|
-
};
|
|
983
|
-
}
|
|
984
|
-
function canEditColumn(column, sources) {
|
|
985
|
-
if (isComputedColumn(column) || column.locked) return false;
|
|
986
|
-
const kit = kitOf(column.type);
|
|
987
|
-
if (kit) return kit.canEditInGrid(column, sources);
|
|
988
|
-
if (column.type === "person") return Boolean(sources?.members);
|
|
989
|
-
if (column.type === "document") return Boolean(sources?.documents);
|
|
990
|
-
if (column.type === "relation") return Boolean(sources?.searchRows && column.relation);
|
|
991
|
-
return true;
|
|
992
|
-
}
|
|
993
|
-
function editorFor(column, sources, dateSpanLabels) {
|
|
994
|
-
if (kitOf(column.type)) return {};
|
|
995
|
-
const pick = (params) => ({
|
|
996
|
-
cellEditor: PickCellEditor,
|
|
997
|
-
cellEditorPopup: true,
|
|
998
|
-
cellEditorParams: params
|
|
999
|
-
});
|
|
1000
|
-
switch (column.type) {
|
|
1001
|
-
case "number":
|
|
1002
|
-
return { cellEditor: "agNumberCellEditor", cellEditorParams: { showStepperButtons: false } };
|
|
1003
|
-
case "date":
|
|
1004
|
-
return column.span ? {
|
|
1005
|
-
cellEditor: DateSpanCellEditor,
|
|
1006
|
-
cellEditorParams: {
|
|
1007
|
-
endColumnId: column.span.endColumnId,
|
|
1008
|
-
timezoneColumnId: column.span.timezoneColumnId,
|
|
1009
|
-
labels: dateSpanLabels,
|
|
1010
|
-
columnName: column.name
|
|
1011
|
-
}
|
|
1012
|
-
} : { cellEditor: "agDateStringCellEditor" };
|
|
1013
|
-
case "checkbox":
|
|
1014
|
-
return { cellEditor: "agCheckboxCellEditor" };
|
|
1015
|
-
case "select":
|
|
1016
|
-
return {
|
|
1017
|
-
cellEditor: SelectCellEditor,
|
|
1018
|
-
cellEditorPopup: true,
|
|
1019
|
-
cellEditorParams: { options: column.options ?? [] }
|
|
1020
|
-
};
|
|
1021
|
-
case "person":
|
|
1022
|
-
return pick({ kind: "person", options: sources?.members ?? [] });
|
|
1023
|
-
case "document":
|
|
1024
|
-
return pick({ kind: "document", options: sources?.documents ?? [] });
|
|
1025
|
-
case "relation": {
|
|
1026
|
-
const target = column.relation?.database_id;
|
|
1027
|
-
const searchRows = sources?.searchRows;
|
|
1028
|
-
return pick({
|
|
1029
|
-
kind: "relation",
|
|
1030
|
-
search: target && searchRows ? (q) => searchRows(target, q) : void 0
|
|
1031
|
-
});
|
|
1032
|
-
}
|
|
1033
|
-
case "lookup":
|
|
1034
|
-
case "rollup":
|
|
1035
|
-
return {};
|
|
1036
|
-
default:
|
|
1037
|
-
return { cellEditor: "agTextCellEditor" };
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
var EMPTY_ROW = { id: "", values: {} };
|
|
1041
|
-
var asText = (v) => typeof v === "string" && v ? v : null;
|
|
1042
|
-
function rendererFor(column, locale, sources, readOnly, isCellEditable, onOpenRow, l) {
|
|
1043
|
-
const kit = kitOf(column.type);
|
|
1044
|
-
if (kit) {
|
|
1045
|
-
const valueFormatter = (p) => kit.format(p.value, p.data ?? EMPTY_ROW, column);
|
|
1046
|
-
if (column.type === "label") {
|
|
1047
|
-
const editableFor = (row) => !readOnly && column.editIn !== "row" && canEditColumn(column, sources) && (!row || !isCellEditable || isCellEditable(row, column));
|
|
1048
|
-
return {
|
|
1049
|
-
valueFormatter,
|
|
1050
|
-
cellRenderer: (p) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1051
|
-
LabelsCell,
|
|
1052
|
-
{
|
|
1053
|
-
value: p.value,
|
|
1054
|
-
titles: p.data?.titles,
|
|
1055
|
-
labels: sources?.labels,
|
|
1056
|
-
onChange: editableFor(p.data) ? (ids) => p.node.setDataValue(column.id, ids) : void 0,
|
|
1057
|
-
rowHeight: p.node?.rowHeight ?? void 0
|
|
1058
|
-
}
|
|
1059
|
-
)
|
|
1060
|
-
};
|
|
1061
|
-
}
|
|
1062
|
-
return {
|
|
1063
|
-
valueFormatter,
|
|
1064
|
-
cellRenderer: (p) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1065
|
-
SourcesCell,
|
|
1066
|
-
{
|
|
1067
|
-
value: p.value,
|
|
1068
|
-
titles: p.data?.titles,
|
|
1069
|
-
openLabel: l.openRowFromSource,
|
|
1070
|
-
onOpen: onOpenRow && p.data ? () => onOpenRow(p.data, { focusColumn: column.id }) : void 0,
|
|
1071
|
-
rowHeight: p.node?.rowHeight ?? void 0
|
|
1072
|
-
}
|
|
1073
|
-
)
|
|
1074
|
-
};
|
|
1075
|
-
}
|
|
1076
|
-
switch (column.type) {
|
|
1077
|
-
case "checkbox":
|
|
1078
|
-
return {
|
|
1079
|
-
cellRenderer: "agCheckboxCellRenderer",
|
|
1080
|
-
cellClass: "flex items-center justify-center"
|
|
1081
|
-
};
|
|
1082
|
-
case "select":
|
|
1083
|
-
return {
|
|
1084
|
-
cellRenderer: (p) => typeof p.value === "string" && p.value ? /* @__PURE__ */ jsxRuntime.jsx(SelectChip, { value: p.value }) : null
|
|
1085
|
-
};
|
|
1086
|
-
case "number":
|
|
1087
|
-
return {
|
|
1088
|
-
cellClass: "cell-numeric",
|
|
1089
|
-
valueFormatter: (p) => formatCell(p.value, "number", locale)
|
|
1090
|
-
};
|
|
1091
|
-
case "rollup":
|
|
1092
|
-
return {
|
|
1093
|
-
cellClass: "cell-numeric text-muted-foreground",
|
|
1094
|
-
valueFormatter: (p) => formatCell(p.value, "rollup", locale)
|
|
1095
|
-
};
|
|
1096
|
-
case "date": {
|
|
1097
|
-
const span = column.span;
|
|
1098
|
-
if (span)
|
|
1099
|
-
return {
|
|
1100
|
-
valueFormatter: (p) => typeof p.value === "string" && p.value ? chunkGXJW5EK5_cjs.formatSpan(
|
|
1101
|
-
p.value,
|
|
1102
|
-
asText(p.data?.values[span.endColumnId]),
|
|
1103
|
-
span.timezoneColumnId ? asText(p.data?.values[span.timezoneColumnId]) : null
|
|
1104
|
-
) : ""
|
|
1105
|
-
};
|
|
1106
|
-
return {
|
|
1107
|
-
valueFormatter: (p) => formatCell(p.value, "date", locale)
|
|
1108
|
-
};
|
|
1109
|
-
}
|
|
1110
|
-
case "person":
|
|
1111
|
-
return {
|
|
1112
|
-
cellRenderer: (p) => /* @__PURE__ */ jsxRuntime.jsx(PersonCell, { value: p.value, titles: p.data?.titles })
|
|
1113
|
-
};
|
|
1114
|
-
case "document":
|
|
1115
|
-
case "relation":
|
|
1116
|
-
return {
|
|
1117
|
-
cellRenderer: (p) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
1118
|
-
LinkChipsCell,
|
|
1119
|
-
{
|
|
1120
|
-
value: p.value,
|
|
1121
|
-
titles: p.data?.titles,
|
|
1122
|
-
kind: column.type === "document" ? "document" : "relation",
|
|
1123
|
-
onOpenDocument: sources?.onOpenDocument
|
|
1124
|
-
}
|
|
1125
|
-
)
|
|
1126
|
-
};
|
|
1127
|
-
case "lookup":
|
|
1128
|
-
return {
|
|
1129
|
-
cellRenderer: (p) => /* @__PURE__ */ jsxRuntime.jsx(LookupCell, { value: p.value, titles: p.data?.titles, locale })
|
|
1130
|
-
};
|
|
1131
|
-
default:
|
|
1132
|
-
return { cellClass: "database-cell-text" };
|
|
1133
|
-
}
|
|
1134
|
-
}
|
|
1135
|
-
function setSpan(row, columnId, span, newValue) {
|
|
1136
|
-
if ((typeof newValue === "string" || newValue === null) && sameCellValue(asText(newValue), row.values[columnId] ?? null)) {
|
|
1137
|
-
return false;
|
|
1138
|
-
}
|
|
1139
|
-
const next = typeof newValue === "object" && newValue !== null ? newValue : { start: asText(newValue), end: null, timezone: null };
|
|
1140
|
-
const writes = [
|
|
1141
|
-
[columnId, next.start],
|
|
1142
|
-
[span.endColumnId, next.end],
|
|
1143
|
-
...span.timezoneColumnId ? [[span.timezoneColumnId, next.timezone]] : []
|
|
1144
|
-
];
|
|
1145
|
-
const changed = writes.filter(([id, v]) => !sameCellValue(v, row.values[id] ?? null));
|
|
1146
|
-
if (changed.length === 0) return false;
|
|
1147
|
-
row.values = { ...row.values, ...Object.fromEntries(writes) };
|
|
1148
|
-
return true;
|
|
1149
|
-
}
|
|
1150
|
-
function createDatabaseColumns(columns, options = {}) {
|
|
1151
|
-
const {
|
|
1152
|
-
readOnly,
|
|
1153
|
-
onEditColumn,
|
|
1154
|
-
onAddColumn,
|
|
1155
|
-
onOpenRow,
|
|
1156
|
-
locale,
|
|
1157
|
-
sources,
|
|
1158
|
-
isCellEditable,
|
|
1159
|
-
renderRowActions
|
|
1160
|
-
} = options;
|
|
1161
|
-
const l = { ...DEFAULT_DATABASE_COLUMN_LABELS, ...options.labels };
|
|
1162
|
-
const openRow = onOpenRow && columns.length > 0 ? [
|
|
1163
|
-
{
|
|
1164
|
-
colId: OPEN_ROW_COL_ID,
|
|
1165
|
-
headerName: "",
|
|
1166
|
-
width: 40,
|
|
1167
|
-
minWidth: 40,
|
|
1168
|
-
maxWidth: 40,
|
|
1169
|
-
resizable: false,
|
|
1170
|
-
sortable: false,
|
|
1171
|
-
editable: false,
|
|
1172
|
-
suppressMovable: true,
|
|
1173
|
-
// Pinned: the button stays in view however far the table scrolls.
|
|
1174
|
-
pinned: "left",
|
|
1175
|
-
lockPinned: true,
|
|
1176
|
-
lockPosition: "left",
|
|
1177
|
-
cellClass: "flex items-center justify-center !px-0",
|
|
1178
|
-
valueGetter: () => null,
|
|
1179
|
-
cellRenderer: (p) => p.data ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
1180
|
-
"button",
|
|
1181
|
-
{
|
|
1182
|
-
type: "button",
|
|
1183
|
-
"aria-label": l.openRow,
|
|
1184
|
-
title: l.openRow,
|
|
1185
|
-
"data-testid": `database-open-row-${p.data.id}`,
|
|
1186
|
-
onClick: (e) => {
|
|
1187
|
-
e.stopPropagation();
|
|
1188
|
-
if (p.data) onOpenRow(p.data);
|
|
1189
|
-
},
|
|
1190
|
-
onDoubleClick: (e) => e.stopPropagation(),
|
|
1191
|
-
className: "flex size-6 items-center justify-center rounded text-muted-foreground/70 hover:bg-muted hover:text-foreground",
|
|
1192
|
-
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Maximize2, { className: "size-3.5" })
|
|
1193
|
-
}
|
|
1194
|
-
) : null
|
|
1195
|
-
}
|
|
1196
|
-
] : [];
|
|
1197
|
-
const defs = columns.map((column) => {
|
|
1198
|
-
const gridEditable = !readOnly && !kitOf(column.type) && column.editIn !== "row" && canEditColumn(column, sources);
|
|
1199
|
-
return {
|
|
1200
|
-
colId: column.id,
|
|
1201
|
-
headerName: column.name,
|
|
1202
|
-
...sizing(column),
|
|
1203
|
-
resizable: true,
|
|
1204
|
-
sortable: true,
|
|
1205
|
-
editable: isCellEditable ? (p) => gridEditable && (!p.data || isCellEditable(p.data, column)) : gridEditable,
|
|
1206
|
-
// The grid's own type inference must not second-guess the database's column type.
|
|
1207
|
-
cellDataType: false,
|
|
1208
|
-
headerComponentParams: {
|
|
1209
|
-
innerHeaderComponent: HeaderLabel,
|
|
1210
|
-
innerHeaderComponentParams: {
|
|
1211
|
-
dbColumn: column,
|
|
1212
|
-
settingsLabel: l.columnSettings(column.name),
|
|
1213
|
-
computedLabel: l.computed,
|
|
1214
|
-
onEdit: !readOnly && onEditColumn ? () => onEditColumn(column) : void 0
|
|
1215
|
-
}
|
|
1216
|
-
},
|
|
1217
|
-
// An empty checkbox reads as unticked (not indeterminate).
|
|
1218
|
-
valueGetter: (p) => column.type === "checkbox" ? p.data?.values[column.id] === true : p.data?.values[column.id] ?? null,
|
|
1219
|
-
// Edits land in the row's values as the API would store them; the host saves them in
|
|
1220
|
-
// onCellValueChanged and puts the server's normalised row back.
|
|
1221
|
-
valueSetter: (p) => {
|
|
1222
|
-
if (!p.data) return false;
|
|
1223
|
-
const span = column.span;
|
|
1224
|
-
if (span) return setSpan(p.data, column.id, span, p.newValue);
|
|
1225
|
-
const next = toApiValue(p.newValue, column.type);
|
|
1226
|
-
if (sameCellValue(next, p.oldValue, column.type)) return false;
|
|
1227
|
-
p.data.values = { ...p.data.values, [column.id]: next };
|
|
1228
|
-
return true;
|
|
1229
|
-
},
|
|
1230
|
-
comparator: (a, b, nodeA, nodeB) => compareCells(a, b, column.type, nodeA?.data?.titles, nodeB?.data?.titles),
|
|
1231
|
-
getQuickFilterText: (p) => formatCell(p.value, column.type, locale, p.data?.titles),
|
|
1232
|
-
...editorFor(column, sources, l.dateSpanEditor),
|
|
1233
|
-
...rendererFor(column, locale, sources, readOnly, isCellEditable, onOpenRow, l)
|
|
1234
|
-
};
|
|
1235
|
-
});
|
|
1236
|
-
defs.unshift(...openRow);
|
|
1237
|
-
if (renderRowActions && columns.length > 0) {
|
|
1238
|
-
defs.push({
|
|
1239
|
-
colId: ROW_ACTIONS_COL_ID,
|
|
1240
|
-
headerName: "",
|
|
1241
|
-
width: 40,
|
|
1242
|
-
minWidth: 40,
|
|
1243
|
-
maxWidth: 40,
|
|
1244
|
-
resizable: false,
|
|
1245
|
-
sortable: false,
|
|
1246
|
-
editable: false,
|
|
1247
|
-
suppressMovable: true,
|
|
1248
|
-
pinned: "right",
|
|
1249
|
-
lockPinned: true,
|
|
1250
|
-
cellClass: "flex items-center justify-center !px-0",
|
|
1251
|
-
valueGetter: () => null,
|
|
1252
|
-
cellRenderer: (p) => p.data ? renderRowActions(p.data) : null
|
|
1253
|
-
});
|
|
1254
|
-
}
|
|
1255
|
-
if (!readOnly && onAddColumn) {
|
|
1256
|
-
defs.push({
|
|
1257
|
-
colId: ADD_COLUMN_COL_ID,
|
|
1258
|
-
width: 52,
|
|
1259
|
-
minWidth: 52,
|
|
1260
|
-
maxWidth: 52,
|
|
1261
|
-
resizable: false,
|
|
1262
|
-
sortable: false,
|
|
1263
|
-
editable: false,
|
|
1264
|
-
suppressMovable: true,
|
|
1265
|
-
// Pinned: on a wide table the add button stays in view instead of scrolling off the right.
|
|
1266
|
-
pinned: "right",
|
|
1267
|
-
lockPinned: true,
|
|
1268
|
-
headerComponent: AddColumnHeader,
|
|
1269
|
-
headerComponentParams: { addLabel: l.addColumn, onAddColumn },
|
|
1270
|
-
valueGetter: () => null
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
return defs;
|
|
1274
|
-
}
|
|
1275
|
-
var escapeHtml = (text) => text.replace(/[&<>"']/g, (ch) => `&#${ch.charCodeAt(0)};`);
|
|
1276
|
-
var DEFAULT_DATABASE_TABLE_LABELS = {
|
|
1277
|
-
newRow: "New row",
|
|
1278
|
-
emptyTitle: "No rows yet",
|
|
1279
|
-
emptyMessage: "Add a row, or import a spreadsheet.",
|
|
1280
|
-
noColumnsTitle: "No columns yet",
|
|
1281
|
-
noColumnsMessage: "Add a column to start.",
|
|
1282
|
-
noMatches: "No rows match your search or filters."
|
|
1283
|
-
};
|
|
1284
|
-
function regrowAfterDrag(event) {
|
|
1285
|
-
if (!event.finished || event.source !== "uiColumnResized") return;
|
|
1286
|
-
const grid = event.api;
|
|
1287
|
-
if (grid.isDestroyed()) return;
|
|
1288
|
-
const dragged = new Set((event.columns ?? []).map((column) => column.getColId()));
|
|
1289
|
-
const state = (grid.getColumns() ?? []).flatMap((column) => {
|
|
1290
|
-
const flex = dragged.has(column.getColId()) ? null : column.getFlex();
|
|
1291
|
-
return flex ? [{ colId: column.getColId(), flex }] : [];
|
|
1292
|
-
});
|
|
1293
|
-
if (state.length > 0) grid.applyColumnState({ state, applyOrder: false });
|
|
1294
|
-
}
|
|
1295
|
-
function DatabaseTable({
|
|
1296
|
-
columns,
|
|
1297
|
-
rows,
|
|
1298
|
-
onCellChange,
|
|
1299
|
-
onAddRow,
|
|
1300
|
-
onAddColumn,
|
|
1301
|
-
onEditColumn,
|
|
1302
|
-
onOpenRow,
|
|
1303
|
-
isCellEditable,
|
|
1304
|
-
renderRowActions,
|
|
1305
|
-
getRowTestId,
|
|
1306
|
-
getCellTestId,
|
|
1307
|
-
testIds,
|
|
1308
|
-
sources,
|
|
1309
|
-
onSelectionChange,
|
|
1310
|
-
selected,
|
|
1311
|
-
readOnly = false,
|
|
1312
|
-
isFiltered = false,
|
|
1313
|
-
isLoading,
|
|
1314
|
-
locale,
|
|
1315
|
-
gridId,
|
|
1316
|
-
rowHeight = 38,
|
|
1317
|
-
height = "100%",
|
|
1318
|
-
labels,
|
|
1319
|
-
columnLabels,
|
|
1320
|
-
gridProps,
|
|
1321
|
-
testId,
|
|
1322
|
-
revealRowId,
|
|
1323
|
-
onRevealed,
|
|
1324
|
-
openRowId = null
|
|
1325
|
-
}) {
|
|
1326
|
-
const l = { ...DEFAULT_DATABASE_TABLE_LABELS, ...labels };
|
|
1327
|
-
const latest = react.useRef({
|
|
1328
|
-
onEditColumn,
|
|
1329
|
-
onAddColumn,
|
|
1330
|
-
onOpenRow,
|
|
1331
|
-
isCellEditable,
|
|
1332
|
-
renderRowActions,
|
|
1333
|
-
getRowTestId,
|
|
1334
|
-
getCellTestId,
|
|
1335
|
-
columns,
|
|
1336
|
-
openRowId
|
|
1337
|
-
});
|
|
1338
|
-
latest.current = {
|
|
1339
|
-
onEditColumn,
|
|
1340
|
-
onAddColumn,
|
|
1341
|
-
onOpenRow,
|
|
1342
|
-
isCellEditable,
|
|
1343
|
-
renderRowActions,
|
|
1344
|
-
getRowTestId,
|
|
1345
|
-
getCellTestId,
|
|
1346
|
-
columns,
|
|
1347
|
-
openRowId
|
|
1348
|
-
};
|
|
1349
|
-
const hasCellEditable = !!isCellEditable;
|
|
1350
|
-
const hasRowActions = !!renderRowActions;
|
|
1351
|
-
const hasEditColumn = !!onEditColumn;
|
|
1352
|
-
const hasAddColumn = !!onAddColumn;
|
|
1353
|
-
const hasOpenRow = !!onOpenRow;
|
|
1354
|
-
const editColumn = react.useMemo(
|
|
1355
|
-
() => hasEditColumn ? (column) => latest.current.onEditColumn?.(column) : void 0,
|
|
1356
|
-
[hasEditColumn]
|
|
1357
|
-
);
|
|
1358
|
-
const addColumn = react.useMemo(
|
|
1359
|
-
() => hasAddColumn ? () => latest.current.onAddColumn?.() : void 0,
|
|
1360
|
-
[hasAddColumn]
|
|
1361
|
-
);
|
|
1362
|
-
const openRow = react.useMemo(
|
|
1363
|
-
() => hasOpenRow ? (row, options) => options ? latest.current.onOpenRow?.(row, options) : latest.current.onOpenRow?.(row) : void 0,
|
|
1364
|
-
[hasOpenRow]
|
|
1365
|
-
);
|
|
1366
|
-
const cellEditable = react.useMemo(
|
|
1367
|
-
() => hasCellEditable ? (row, column) => latest.current.isCellEditable?.(row, column) ?? true : void 0,
|
|
1368
|
-
[hasCellEditable]
|
|
1369
|
-
);
|
|
1370
|
-
const rowActions = react.useMemo(
|
|
1371
|
-
() => hasRowActions ? (row) => latest.current.renderRowActions?.(row) : void 0,
|
|
1372
|
-
[hasRowActions]
|
|
1373
|
-
);
|
|
1374
|
-
const rowTestId = react.useCallback(
|
|
1375
|
-
(row) => latest.current.getRowTestId?.(row) ?? `database-row-${row.id}`,
|
|
1376
|
-
[]
|
|
1377
|
-
);
|
|
1378
|
-
const cellTestId = react.useCallback(
|
|
1379
|
-
(columnId, row) => latest.current.getCellTestId?.(columnId, row) ?? `database-cell-${row.id}-${columnId}`,
|
|
1380
|
-
[]
|
|
1381
|
-
);
|
|
1382
|
-
const latestSources = react.useRef(sources);
|
|
1383
|
-
latestSources.current = sources;
|
|
1384
|
-
const hasSources = !!sources;
|
|
1385
|
-
const hasSearchRows = !!sources?.searchRows;
|
|
1386
|
-
const hasOpenDocument = !!sources?.onOpenDocument;
|
|
1387
|
-
const hasLabels = !!sources?.labels;
|
|
1388
|
-
const members = sources?.members;
|
|
1389
|
-
const documents = sources?.documents;
|
|
1390
|
-
const labelOptions = sources?.labels?.options;
|
|
1391
|
-
const contentKey = react.useMemo(
|
|
1392
|
-
() => JSON.stringify([columns, members, documents, labelOptions]),
|
|
1393
|
-
[columns, members, documents, labelOptions]
|
|
1394
|
-
);
|
|
1395
|
-
const multiline = rowHeight >= chunkV5P5MRSR_cjs.rowHeightForLines(2);
|
|
1396
|
-
const columnDefs = react.useMemo(
|
|
1397
|
-
() => createDatabaseColumns(columns, {
|
|
1398
|
-
readOnly,
|
|
1399
|
-
onEditColumn: editColumn,
|
|
1400
|
-
onAddColumn: addColumn,
|
|
1401
|
-
onOpenRow: openRow,
|
|
1402
|
-
isCellEditable: cellEditable,
|
|
1403
|
-
renderRowActions: rowActions,
|
|
1404
|
-
sources: sources && {
|
|
1405
|
-
members: sources.members,
|
|
1406
|
-
documents: sources.documents,
|
|
1407
|
-
labels: hasLabels ? {
|
|
1408
|
-
options: sources.labels.options,
|
|
1409
|
-
onCreate: (name) => latestSources.current.labels.onCreate(name)
|
|
1410
|
-
} : void 0,
|
|
1411
|
-
searchRows: hasSearchRows ? (databaseId, q) => latestSources.current.searchRows(databaseId, q) : void 0,
|
|
1412
|
-
onOpenDocument: hasOpenDocument ? (documentId) => latestSources.current?.onOpenDocument?.(documentId) : void 0
|
|
1413
|
-
},
|
|
1414
|
-
locale,
|
|
1415
|
-
labels: columnLabels
|
|
1416
|
-
}),
|
|
1417
|
-
// `columns` and `sources` are read through `contentKey` (and the latest callbacks).
|
|
1418
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1419
|
-
[
|
|
1420
|
-
contentKey,
|
|
1421
|
-
hasSources,
|
|
1422
|
-
hasSearchRows,
|
|
1423
|
-
hasOpenDocument,
|
|
1424
|
-
hasLabels,
|
|
1425
|
-
readOnly,
|
|
1426
|
-
editColumn,
|
|
1427
|
-
addColumn,
|
|
1428
|
-
openRow,
|
|
1429
|
-
cellEditable,
|
|
1430
|
-
rowActions,
|
|
1431
|
-
locale,
|
|
1432
|
-
columnLabels
|
|
1433
|
-
]
|
|
1434
|
-
);
|
|
1435
|
-
const noColumns = columns.length === 0;
|
|
1436
|
-
const emptyState = {
|
|
1437
|
-
icon: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Table2, { className: "size-8 text-muted-foreground" }),
|
|
1438
|
-
title: l.noColumnsTitle,
|
|
1439
|
-
message: readOnly ? void 0 : l.noColumnsMessage,
|
|
1440
|
-
action: !readOnly && onAddColumn ? /* @__PURE__ */ jsxRuntime.jsxs(ui.Button, { onClick: onAddColumn, "data-testid": "database-empty-add-column", className: "gap-1.5", children: [
|
|
1441
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { className: "size-4" }),
|
|
1442
|
-
columnLabels?.addColumn ?? DEFAULT_DATABASE_COLUMN_LABELS.addColumn
|
|
1443
|
-
] }) : void 0
|
|
1444
|
-
};
|
|
1445
|
-
const noRowsText = isFiltered ? l.noMatches : readOnly ? l.emptyTitle : `${l.emptyTitle}. ${l.emptyMessage}`;
|
|
1446
|
-
const api = react.useRef(null);
|
|
1447
|
-
const knownColumns = react.useRef(null);
|
|
1448
|
-
react.useEffect(() => {
|
|
1449
|
-
const ids = new Set(columns.map((c) => c.id));
|
|
1450
|
-
const added = knownColumns.current ? columns.filter((c) => !knownColumns.current.has(c.id)) : [];
|
|
1451
|
-
knownColumns.current = ids;
|
|
1452
|
-
const last = added[added.length - 1];
|
|
1453
|
-
if (last && api.current) {
|
|
1454
|
-
const grid = api.current;
|
|
1455
|
-
setTimeout(() => grid.ensureColumnVisible(last.id, "end"), 0);
|
|
1456
|
-
}
|
|
1457
|
-
}, [columns]);
|
|
1458
|
-
const onRevealedRef = react.useRef(onRevealed);
|
|
1459
|
-
onRevealedRef.current = onRevealed;
|
|
1460
|
-
react.useEffect(() => {
|
|
1461
|
-
if (!revealRowId) return;
|
|
1462
|
-
const flash = setTimeout(() => {
|
|
1463
|
-
const grid = api.current;
|
|
1464
|
-
const node = grid?.getRowNode?.(revealRowId);
|
|
1465
|
-
if (grid && node) {
|
|
1466
|
-
grid.ensureNodeVisible(node, "middle");
|
|
1467
|
-
grid.flashCells({ rowNodes: [node] });
|
|
1468
|
-
}
|
|
1469
|
-
}, 300);
|
|
1470
|
-
const done = setTimeout(() => onRevealedRef.current?.(), 3e3);
|
|
1471
|
-
return () => {
|
|
1472
|
-
clearTimeout(flash);
|
|
1473
|
-
clearTimeout(done);
|
|
1474
|
-
};
|
|
1475
|
-
}, [revealRowId, rows.length]);
|
|
1476
|
-
const openRowOf = (row, columnId) => {
|
|
1477
|
-
if (row && latest.current.columns.find((c) => c.id === columnId)?.editIn === "row")
|
|
1478
|
-
latest.current.onOpenRow?.(row, { focusColumn: columnId });
|
|
1479
|
-
};
|
|
1480
|
-
const clickRowOf = (row, columnId) => {
|
|
1481
|
-
if (!row) return;
|
|
1482
|
-
const column = latest.current.columns.find((c) => c.id === columnId);
|
|
1483
|
-
if (!column) return;
|
|
1484
|
-
if (column.editIn === "row") return latest.current.onOpenRow?.(row, { focusColumn: columnId });
|
|
1485
|
-
const open = latest.current.openRowId;
|
|
1486
|
-
const plain = column.type !== "checkbox" && column.type !== "label" && column.type !== "source";
|
|
1487
|
-
if (open && open !== row.id && plain) latest.current.onOpenRow?.(row);
|
|
1488
|
-
};
|
|
1489
|
-
const shownOpenRow = react.useRef(null);
|
|
1490
|
-
react.useEffect(() => {
|
|
1491
|
-
const grid = api.current;
|
|
1492
|
-
const before = shownOpenRow.current;
|
|
1493
|
-
shownOpenRow.current = openRowId;
|
|
1494
|
-
if (!grid || grid.isDestroyed() || before === openRowId) return;
|
|
1495
|
-
const rowNodes = [before, openRowId].map((id) => id ? grid.getRowNode(id) : void 0).filter((node) => !!node);
|
|
1496
|
-
if (rowNodes.length) grid.redrawRows({ rowNodes });
|
|
1497
|
-
}, [openRowId]);
|
|
1498
|
-
const shownRowHeight = react.useRef(rowHeight);
|
|
1499
|
-
react.useEffect(() => {
|
|
1500
|
-
const grid = api.current;
|
|
1501
|
-
const before = shownRowHeight.current;
|
|
1502
|
-
shownRowHeight.current = rowHeight;
|
|
1503
|
-
if (before === rowHeight || !grid || grid.isDestroyed()) return;
|
|
1504
|
-
const sized = latest.current.columns.filter((c) => c.type === "label" || c.type === "source").map((c) => c.id);
|
|
1505
|
-
if (sized.length > 0) grid.refreshCells({ columns: sized, force: true });
|
|
1506
|
-
}, [rowHeight]);
|
|
1507
|
-
const handleCellValueChanged = (event) => {
|
|
1508
|
-
const columnId = event.column.getColId();
|
|
1509
|
-
if (!event.data || !onCellChange) return;
|
|
1510
|
-
const value = event.data.values[columnId] ?? null;
|
|
1511
|
-
const span = columns.find((c) => c.id === columnId)?.span;
|
|
1512
|
-
if (!span) return onCellChange(event.data, columnId, value);
|
|
1513
|
-
const extra = {
|
|
1514
|
-
[span.endColumnId]: event.data.values[span.endColumnId] ?? null
|
|
1515
|
-
};
|
|
1516
|
-
if (span.timezoneColumnId) {
|
|
1517
|
-
extra[span.timezoneColumnId] = event.data.values[span.timezoneColumnId] ?? null;
|
|
1518
|
-
}
|
|
1519
|
-
onCellChange(event.data, columnId, value, extra);
|
|
1520
|
-
};
|
|
1521
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1522
|
-
"div",
|
|
1523
|
-
{
|
|
1524
|
-
className: ui.cn(
|
|
1525
|
-
"database-table flex h-full min-h-0 flex-col",
|
|
1526
|
-
multiline && "database-table--multiline"
|
|
1527
|
-
),
|
|
1528
|
-
"data-testid": chunkPLIF5CUV_cjs.testIdOr(testId, { testId: "database-table" }),
|
|
1529
|
-
children: [
|
|
1530
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "min-h-0 flex-1", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
1531
|
-
chunkZVEW3JBT_cjs.GridView,
|
|
1532
|
-
{
|
|
1533
|
-
testId: testIds?.grid ?? "database-grid",
|
|
1534
|
-
items: rows,
|
|
1535
|
-
columnDefs,
|
|
1536
|
-
getItemId: (row) => row.id,
|
|
1537
|
-
getRowTestId: rowTestId,
|
|
1538
|
-
getCellTestId: cellTestId,
|
|
1539
|
-
isLoading,
|
|
1540
|
-
emptyState,
|
|
1541
|
-
showEmpty: noColumns,
|
|
1542
|
-
gridId,
|
|
1543
|
-
height,
|
|
1544
|
-
rowHeight,
|
|
1545
|
-
selection: onSelectionChange ? { mode: "multiple", selected: selected ?? [], onSelectionChange, controlled: true } : void 0,
|
|
1546
|
-
onCellValueChanged: handleCellValueChanged,
|
|
1547
|
-
...gridProps,
|
|
1548
|
-
onGridReady: (params) => {
|
|
1549
|
-
api.current = params.api;
|
|
1550
|
-
gridProps?.onGridReady?.(params);
|
|
1551
|
-
},
|
|
1552
|
-
gridOptions: {
|
|
1553
|
-
overlayNoRowsTemplate: `<span class="text-sm text-muted-foreground">${escapeHtml(noRowsText)}</span>`,
|
|
1554
|
-
singleClickEdit: false,
|
|
1555
|
-
stopEditingWhenCellsLoseFocus: true,
|
|
1556
|
-
enterNavigatesVerticallyAfterEdit: true,
|
|
1557
|
-
undoRedoCellEditing: false,
|
|
1558
|
-
rowClassRules: {
|
|
1559
|
-
"database-row-open": (p) => !!p.data && p.data.id === latest.current.openRowId
|
|
1560
|
-
},
|
|
1561
|
-
onCellClicked: (event) => clickRowOf(event.data, event.column.getColId()),
|
|
1562
|
-
onCellDoubleClicked: (event) => openRowOf(event.data, event.column.getColId()),
|
|
1563
|
-
onCellKeyDown: (event) => {
|
|
1564
|
-
if ("column" in event && event.event instanceof KeyboardEvent && event.event.key === "Enter")
|
|
1565
|
-
openRowOf(event.data, event.column.getColId());
|
|
1566
|
-
},
|
|
1567
|
-
...gridProps?.gridOptions,
|
|
1568
|
-
onColumnResized: (event) => {
|
|
1569
|
-
gridProps?.gridOptions?.onColumnResized?.(event);
|
|
1570
|
-
regrowAfterDrag(event);
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
) }),
|
|
1575
|
-
!readOnly && onAddRow && columns.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "border-t border-border px-2 py-1", children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1576
|
-
ui.Button,
|
|
1577
|
-
{
|
|
1578
|
-
variant: "ghost",
|
|
1579
|
-
size: "sm",
|
|
1580
|
-
onClick: onAddRow,
|
|
1581
|
-
"data-testid": testIds?.addRow ?? "database-add-row",
|
|
1582
|
-
className: "gap-1.5 text-muted-foreground",
|
|
1583
|
-
children: [
|
|
1584
|
-
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { className: "size-4" }),
|
|
1585
|
-
l.newRow
|
|
1586
|
-
]
|
|
1587
|
-
}
|
|
1588
|
-
) })
|
|
1589
|
-
]
|
|
1590
|
-
}
|
|
1591
|
-
);
|
|
1592
|
-
}
|
|
1593
|
-
|
|
1594
|
-
exports.ADD_COLUMN_COL_ID = ADD_COLUMN_COL_ID;
|
|
1595
|
-
exports.COLUMN_TYPE_ICONS = COLUMN_TYPE_ICONS;
|
|
1596
|
-
exports.COMPUTED_COLUMN_TYPES = COMPUTED_COLUMN_TYPES;
|
|
1597
|
-
exports.DATABASE_COLUMN_TYPES = DATABASE_COLUMN_TYPES;
|
|
1598
|
-
exports.DATABASE_ROLLUP_OPS = DATABASE_ROLLUP_OPS;
|
|
1599
|
-
exports.DEFAULT_DATABASE_COLUMN_LABELS = DEFAULT_DATABASE_COLUMN_LABELS;
|
|
1600
|
-
exports.DEFAULT_DATABASE_COLUMN_TYPE_LABELS = DEFAULT_DATABASE_COLUMN_TYPE_LABELS;
|
|
1601
|
-
exports.DEFAULT_DATABASE_TABLE_LABELS = DEFAULT_DATABASE_TABLE_LABELS;
|
|
1602
|
-
exports.DEFAULT_PICK_CELL_EDITOR_LABELS = DEFAULT_PICK_CELL_EDITOR_LABELS;
|
|
1603
|
-
exports.DatabaseTable = DatabaseTable;
|
|
1604
|
-
exports.DateSpanCellEditor = DateSpanCellEditor;
|
|
1605
|
-
exports.DateSpanField = DateSpanField;
|
|
1606
|
-
exports.LINK_COLUMN_TYPES = LINK_COLUMN_TYPES;
|
|
1607
|
-
exports.LabelsCell = LabelsCell;
|
|
1608
|
-
exports.LinkChip = LinkChip;
|
|
1609
|
-
exports.LinkChipsCell = LinkChipsCell;
|
|
1610
|
-
exports.LookupCell = LookupCell;
|
|
1611
|
-
exports.OPEN_ROW_COL_ID = OPEN_ROW_COL_ID;
|
|
1612
|
-
exports.PersonCell = PersonCell;
|
|
1613
|
-
exports.PersonChip = PersonChip;
|
|
1614
|
-
exports.PickCellEditor = PickCellEditor;
|
|
1615
|
-
exports.ROW_ACTIONS_COL_ID = ROW_ACTIONS_COL_ID;
|
|
1616
|
-
exports.SelectCellEditor = SelectCellEditor;
|
|
1617
|
-
exports.SelectChip = SelectChip;
|
|
1618
|
-
exports.SourcesCell = SourcesCell;
|
|
1619
|
-
exports.canEditColumn = canEditColumn;
|
|
1620
|
-
exports.cellIds = cellIds;
|
|
1621
|
-
exports.cellList = cellList;
|
|
1622
|
-
exports.citationKey = citationKey;
|
|
1623
|
-
exports.citationTestId = citationTestId;
|
|
1624
|
-
exports.citationsOf = citationsOf;
|
|
1625
|
-
exports.columnWidth = columnWidth;
|
|
1626
|
-
exports.compareCells = compareCells;
|
|
1627
|
-
exports.createDatabaseColumns = createDatabaseColumns;
|
|
1628
|
-
exports.formatCell = formatCell;
|
|
1629
|
-
exports.formatDateValue = formatDateValue;
|
|
1630
|
-
exports.formatLookupValue = formatLookupValue;
|
|
1631
|
-
exports.formatNumberValue = formatNumberValue;
|
|
1632
|
-
exports.isComputedColumn = isComputedColumn;
|
|
1633
|
-
exports.kitOf = kitOf;
|
|
1634
|
-
exports.optionTone = optionTone;
|
|
1635
|
-
exports.rowTitle = rowTitle;
|
|
1636
|
-
exports.sameCellValue = sameCellValue;
|
|
1637
|
-
exports.titleOf = titleOf;
|
|
1638
|
-
exports.toApiValue = toApiValue;
|
|
1639
|
-
//# sourceMappingURL=chunk-VBD4RJOL.cjs.map
|
|
1640
|
-
//# sourceMappingURL=chunk-VBD4RJOL.cjs.map
|