@ai-matrx/records-ui 0.107.5 → 0.108.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/first-page.cjs +487 -0
- package/dist/first-page.cjs.map +1 -0
- package/dist/first-page.d.cts +35 -0
- package/dist/first-page.d.ts +35 -0
- package/dist/first-page.js +474 -0
- package/dist/first-page.js.map +1 -0
- package/dist/index.d.cts +98 -595
- package/dist/index.d.ts +98 -595
- package/dist/views-VPwb3QQk.d.cts +505 -0
- package/dist/views-VPwb3QQk.d.ts +505 -0
- package/package.json +15 -5
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/parity.ts
|
|
4
|
+
import {
|
|
5
|
+
KERNEL_TABLES,
|
|
6
|
+
PARITY_FIELD_TYPES,
|
|
7
|
+
fieldKindFor,
|
|
8
|
+
newerKindOf
|
|
9
|
+
} from "@ai-matrx/records";
|
|
10
|
+
import { humanizeIdentifier } from "@ai-matrx/kit/text-case";
|
|
11
|
+
var kernelId = (name) => KERNEL_TABLES.find((t) => t.name === name)?.id ?? "";
|
|
12
|
+
var KERNEL_FILE_TABLE = kernelId("File");
|
|
13
|
+
var KERNEL_PERSON_TABLE = kernelId("Person");
|
|
14
|
+
var PARITY_MADE_OF = Object.fromEntries(
|
|
15
|
+
PARITY_FIELD_TYPES.map((p) => [p.parity_type, p.made_of])
|
|
16
|
+
);
|
|
17
|
+
var KERNEL = { file: KERNEL_FILE_TABLE, person: KERNEL_PERSON_TABLE };
|
|
18
|
+
function editorKindFor(field) {
|
|
19
|
+
return fieldKindFor(field, KERNEL);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/gridLook.ts
|
|
23
|
+
function defaultSortOf(table, fields) {
|
|
24
|
+
const raw = table?.default_sort ?? null;
|
|
25
|
+
const first = Array.isArray(raw) ? raw[0] : raw;
|
|
26
|
+
let name = null;
|
|
27
|
+
let direction = "asc";
|
|
28
|
+
if (typeof first === "string") {
|
|
29
|
+
const trimmed = first.trim();
|
|
30
|
+
if (trimmed === "") return null;
|
|
31
|
+
if (trimmed.startsWith("-")) {
|
|
32
|
+
name = trimmed.slice(1).trim();
|
|
33
|
+
direction = "desc";
|
|
34
|
+
} else {
|
|
35
|
+
const [head, tail] = trimmed.split(/\s+/);
|
|
36
|
+
name = head ?? null;
|
|
37
|
+
if (tail && tail.toLowerCase() === "desc") direction = "desc";
|
|
38
|
+
}
|
|
39
|
+
} else if (first && typeof first === "object") {
|
|
40
|
+
const entry = first;
|
|
41
|
+
const named = entry["field"] ?? entry["key"] ?? entry["id"];
|
|
42
|
+
name = typeof named === "string" ? named : null;
|
|
43
|
+
if (String(entry["direction"] ?? "").toLowerCase() === "desc") direction = "desc";
|
|
44
|
+
}
|
|
45
|
+
if (!name) return null;
|
|
46
|
+
const field = fields.find((f) => f.key === name) ?? fields.find((f) => f.id === name);
|
|
47
|
+
return field ? { id: field.key, direction } : null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/gridPage.ts
|
|
51
|
+
import { isRuleFilter } from "@ai-matrx/records";
|
|
52
|
+
import { dateFilterBounds, dateFilterDayBounds } from "@ai-matrx/design-system/data-table";
|
|
53
|
+
function holdsNumbers(field) {
|
|
54
|
+
const kind = String(editorKindFor(field));
|
|
55
|
+
if (kind === "number" || kind === "currency" || kind === "percent") return true;
|
|
56
|
+
return String((field.config ?? {})["system"] ?? "") === "autonumber";
|
|
57
|
+
}
|
|
58
|
+
function sortAsFor(field) {
|
|
59
|
+
const kind = String(editorKindFor(field));
|
|
60
|
+
if (holdsNumbers(field)) return "number";
|
|
61
|
+
if (kind === "datetime") return "date";
|
|
62
|
+
return "text";
|
|
63
|
+
}
|
|
64
|
+
function pageSortFor(fields, sort) {
|
|
65
|
+
if (!sort) return [];
|
|
66
|
+
const field = fields.find((f) => f.key === sort.id);
|
|
67
|
+
if (!field) return [];
|
|
68
|
+
return [{ field: field.key, direction: sort.direction === "desc" ? "desc" : "asc", as: sortAsFor(field) }];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/presentation.ts
|
|
72
|
+
import {
|
|
73
|
+
COLOR_ROTATION,
|
|
74
|
+
parseTableStyle,
|
|
75
|
+
tableStyleIsEmpty
|
|
76
|
+
} from "@ai-matrx/design-system/data-table";
|
|
77
|
+
import { getFieldFormat } from "@ai-matrx/design-system/field-formats";
|
|
78
|
+
import { newerKindOf as newerKindOf2, ratingMaxOf } from "@ai-matrx/records";
|
|
79
|
+
var MIN_ROW_HEIGHT = 24;
|
|
80
|
+
var MAX_ROW_HEIGHT = 96;
|
|
81
|
+
var AGGREGATE_KINDS = [
|
|
82
|
+
"count",
|
|
83
|
+
"sum",
|
|
84
|
+
"average",
|
|
85
|
+
"min",
|
|
86
|
+
"max",
|
|
87
|
+
"empty",
|
|
88
|
+
"filled",
|
|
89
|
+
"unique",
|
|
90
|
+
"checked",
|
|
91
|
+
"unchecked",
|
|
92
|
+
"percentFilled"
|
|
93
|
+
];
|
|
94
|
+
var GROUP_ORDERS = [
|
|
95
|
+
"value-asc",
|
|
96
|
+
"value-desc",
|
|
97
|
+
"count-desc",
|
|
98
|
+
"first-seen"
|
|
99
|
+
];
|
|
100
|
+
function isRecord(v) {
|
|
101
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
102
|
+
}
|
|
103
|
+
function parseGridPresentation(raw) {
|
|
104
|
+
let value = raw;
|
|
105
|
+
if (typeof value === "string") {
|
|
106
|
+
const trimmed = value.trim();
|
|
107
|
+
if (trimmed === "") return {};
|
|
108
|
+
try {
|
|
109
|
+
value = JSON.parse(trimmed);
|
|
110
|
+
} catch {
|
|
111
|
+
return {};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!isRecord(value)) return {};
|
|
115
|
+
const out = {};
|
|
116
|
+
const style = parseTableStyle(value["style"]);
|
|
117
|
+
if (!tableStyleIsEmpty(style)) out.style = style;
|
|
118
|
+
if (isRecord(value["formats"])) {
|
|
119
|
+
const formats = {};
|
|
120
|
+
for (const [key, cfg] of Object.entries(value["formats"])) {
|
|
121
|
+
if (!isRecord(cfg)) continue;
|
|
122
|
+
const id = cfg["id"];
|
|
123
|
+
if (typeof id !== "string") continue;
|
|
124
|
+
const options = cfg["options"];
|
|
125
|
+
formats[key] = isRecord(options) ? {
|
|
126
|
+
id,
|
|
127
|
+
options
|
|
128
|
+
} : { id };
|
|
129
|
+
}
|
|
130
|
+
if (Object.keys(formats).length > 0) out.formats = formats;
|
|
131
|
+
}
|
|
132
|
+
if (Array.isArray(value["frozen"])) {
|
|
133
|
+
const frozen = value["frozen"].filter((k) => typeof k === "string");
|
|
134
|
+
if (frozen.length > 0) out.frozen = frozen;
|
|
135
|
+
}
|
|
136
|
+
const grouping = parseGrouping(value["grouping"]);
|
|
137
|
+
if (grouping) out.grouping = grouping;
|
|
138
|
+
if (isRecord(value["widths"])) {
|
|
139
|
+
const widths = {};
|
|
140
|
+
for (const [key, raw2] of Object.entries(value["widths"])) {
|
|
141
|
+
if (typeof raw2 !== "number" || !Number.isFinite(raw2) || raw2 <= 0) continue;
|
|
142
|
+
widths[key] = Math.round(raw2);
|
|
143
|
+
}
|
|
144
|
+
if (Object.keys(widths).length > 0) out.widths = widths;
|
|
145
|
+
}
|
|
146
|
+
const rowHeight = value["rowHeight"];
|
|
147
|
+
if (typeof rowHeight === "number" && Number.isFinite(rowHeight) && rowHeight >= MIN_ROW_HEIGHT && rowHeight <= MAX_ROW_HEIGHT) {
|
|
148
|
+
out.rowHeight = Math.round(rowHeight);
|
|
149
|
+
}
|
|
150
|
+
if (Array.isArray(value["hiddenFields"])) {
|
|
151
|
+
const hiddenFields = value["hiddenFields"].filter((k) => typeof k === "string");
|
|
152
|
+
if (hiddenFields.length > 0) out.hiddenFields = hiddenFields;
|
|
153
|
+
}
|
|
154
|
+
if (Array.isArray(value["cardHidden"])) {
|
|
155
|
+
out.cardHidden = value["cardHidden"].filter((k) => typeof k === "string");
|
|
156
|
+
}
|
|
157
|
+
if (Array.isArray(value["columnOrder"])) {
|
|
158
|
+
const columnOrder = value["columnOrder"].filter((k) => typeof k === "string");
|
|
159
|
+
if (columnOrder.length > 0) out.columnOrder = columnOrder;
|
|
160
|
+
}
|
|
161
|
+
const gallerySize = value["gallerySize"];
|
|
162
|
+
if (gallerySize === "small" || gallerySize === "medium" || gallerySize === "large") {
|
|
163
|
+
out.gallerySize = gallerySize;
|
|
164
|
+
}
|
|
165
|
+
if (typeof value["wrap"] === "boolean") out.wrap = value["wrap"];
|
|
166
|
+
if (Array.isArray(value["wrapColumns"])) {
|
|
167
|
+
const wrapColumns = value["wrapColumns"].filter((k) => typeof k === "string");
|
|
168
|
+
if (wrapColumns.length > 0) out.wrapColumns = wrapColumns;
|
|
169
|
+
}
|
|
170
|
+
const fit = value["fit"];
|
|
171
|
+
if (fit === "auto" || fit === "fit" || fit === "scroll") out.fit = fit;
|
|
172
|
+
if (typeof value["freezeFirst"] === "boolean") out.freezeFirst = value["freezeFirst"];
|
|
173
|
+
const footer = value["footer"];
|
|
174
|
+
if (footer === "sticky" || footer === "inline") out.footer = footer;
|
|
175
|
+
if (isRecord(value["summaries"])) {
|
|
176
|
+
const summaries = {};
|
|
177
|
+
for (const [key, op] of Object.entries(value["summaries"])) {
|
|
178
|
+
if (typeof op === "string" && op.trim() !== "") summaries[key] = op;
|
|
179
|
+
}
|
|
180
|
+
if (Object.keys(summaries).length > 0) out.summaries = summaries;
|
|
181
|
+
}
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
function parseGrouping(raw) {
|
|
185
|
+
if (!isRecord(raw)) return void 0;
|
|
186
|
+
const field = raw["field"];
|
|
187
|
+
if (typeof field !== "string" || field.trim() === "") return void 0;
|
|
188
|
+
const out = { field };
|
|
189
|
+
if (isRecord(raw["aggregates"])) {
|
|
190
|
+
const aggregates = {};
|
|
191
|
+
for (const [key, spec] of Object.entries(raw["aggregates"])) {
|
|
192
|
+
if (!isRecord(spec)) continue;
|
|
193
|
+
const kind = spec["kind"];
|
|
194
|
+
if (typeof kind !== "string") continue;
|
|
195
|
+
if (!AGGREGATE_KINDS.includes(kind)) continue;
|
|
196
|
+
const label = spec["label"];
|
|
197
|
+
aggregates[key] = typeof label === "string" ? { kind, label } : { kind };
|
|
198
|
+
}
|
|
199
|
+
if (Object.keys(aggregates).length > 0) out.aggregates = aggregates;
|
|
200
|
+
}
|
|
201
|
+
const order = raw["order"];
|
|
202
|
+
if (typeof order === "string" && GROUP_ORDERS.includes(order)) {
|
|
203
|
+
out.order = order;
|
|
204
|
+
}
|
|
205
|
+
if (Array.isArray(raw["collapsed"])) {
|
|
206
|
+
const collapsed = raw["collapsed"].filter((k) => typeof k === "string");
|
|
207
|
+
if (collapsed.length > 0) out.collapsed = collapsed;
|
|
208
|
+
}
|
|
209
|
+
if (raw["showColumn"] === true) out.showColumn = true;
|
|
210
|
+
if (Array.isArray(raw["then"])) {
|
|
211
|
+
const then = [];
|
|
212
|
+
for (const level of raw["then"]) {
|
|
213
|
+
if (!isRecord(level)) continue;
|
|
214
|
+
const sub = level["field"];
|
|
215
|
+
if (typeof sub !== "string" || sub.trim() === "") continue;
|
|
216
|
+
const subOrder = level["order"];
|
|
217
|
+
const subGrain = level["grain"];
|
|
218
|
+
then.push({
|
|
219
|
+
field: sub,
|
|
220
|
+
...typeof subOrder === "string" && GROUP_ORDERS.includes(subOrder) ? { order: subOrder } : {},
|
|
221
|
+
...typeof subGrain === "string" && subGrain !== "" ? { grain: subGrain } : {}
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
if (then.length > 0) out.then = then.slice(0, 2);
|
|
225
|
+
}
|
|
226
|
+
const grain = raw["grain"];
|
|
227
|
+
if (typeof grain === "string" && grain !== "") out.grain = grain;
|
|
228
|
+
const across = raw["across"];
|
|
229
|
+
if (typeof across === "string" && across.trim() !== "") out.across = across;
|
|
230
|
+
if (Array.isArray(raw["show"])) {
|
|
231
|
+
const show = raw["show"].filter((k) => typeof k === "string" && k !== "");
|
|
232
|
+
if (show.length > 0) out.show = show;
|
|
233
|
+
}
|
|
234
|
+
if (Array.isArray(raw["trail"])) {
|
|
235
|
+
const trail = [];
|
|
236
|
+
for (const step of raw["trail"]) {
|
|
237
|
+
if (!isRecord(step) || typeof step["dim"] !== "string" || step["dim"] === "") continue;
|
|
238
|
+
const value = step["value"];
|
|
239
|
+
if (value !== null && typeof value !== "string") continue;
|
|
240
|
+
trail.push({ dim: step["dim"], value });
|
|
241
|
+
}
|
|
242
|
+
if (trail.length > 0) out.trail = trail;
|
|
243
|
+
}
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// src/viewKeys.ts
|
|
248
|
+
var STORE_KEEPS_TIMELINE = true;
|
|
249
|
+
var ALL = ["grid", "kanban", "calendar", "gallery", ...STORE_KEEPS_TIMELINE ? ["timeline"] : [], "list"];
|
|
250
|
+
var HIDES = ["grid", "gallery", "kanban", "calendar", ...STORE_KEEPS_TIMELINE ? ["timeline"] : [], "list"];
|
|
251
|
+
var GRIDS = ["grid"];
|
|
252
|
+
var VIEW_KEYS = [
|
|
253
|
+
{ path: "layout", shape: "kind", layouts: ALL, writer: "caller" },
|
|
254
|
+
{ path: "filters", shape: "filter", layouts: ALL, writer: "caller" },
|
|
255
|
+
{ path: "where", shape: "rule", layouts: ALL, writer: "caller" },
|
|
256
|
+
{ path: "group_field", shape: "field", layouts: ["kanban", ...STORE_KEEPS_TIMELINE ? ["timeline"] : []], writer: "caller" },
|
|
257
|
+
{ path: "swimlane_field", shape: "field:lane", layouts: ["kanban"], writer: "caller" },
|
|
258
|
+
{ path: "collapsed_columns", shape: "values", layouts: ["kanban"], writer: "caller" },
|
|
259
|
+
{ path: "measure", shape: "field:number", layouts: ["kanban"], writer: "caller" },
|
|
260
|
+
{ path: "date_field", shape: "field:date", layouts: ["calendar"], writer: "caller" },
|
|
261
|
+
...STORE_KEEPS_TIMELINE ? [
|
|
262
|
+
{ path: "start_field", shape: "field:date", layouts: ["timeline"], writer: "caller" },
|
|
263
|
+
{ path: "end_field", shape: "field:date", layouts: ["calendar", "timeline"], writer: "caller" }
|
|
264
|
+
] : [],
|
|
265
|
+
{ path: "image_field", shape: "field", layouts: ["gallery"], writer: "caller" },
|
|
266
|
+
{ path: "sorts", shape: "sorts", layouts: ALL, writer: "caller" },
|
|
267
|
+
{ path: "rule_id", shape: "uuid", layouts: ALL, writer: "caller" },
|
|
268
|
+
{ path: "is_default", shape: "boolean", layouts: ALL, writer: "caller" },
|
|
269
|
+
{ path: "presentation", shape: "presentation", layouts: ALL, writer: "caller" },
|
|
270
|
+
{ path: "presentation.style", shape: "style", layouts: ALL, writer: "caller" },
|
|
271
|
+
{ path: "presentation.formats", shape: "object", layouts: GRIDS, writer: "caller" },
|
|
272
|
+
{ path: "presentation.frozen", shape: "fields", layouts: GRIDS, writer: "caller" },
|
|
273
|
+
{ path: "presentation.grouping", shape: "grouping", layouts: ["grid", "gallery", "list"], writer: "caller" },
|
|
274
|
+
{ path: "presentation.widths", shape: "widths", layouts: GRIDS, writer: "caller" },
|
|
275
|
+
{ path: "presentation.rowHeight", shape: "row_height", layouts: GRIDS, writer: "caller" },
|
|
276
|
+
{ path: "presentation.hiddenFields", shape: "fields", layouts: HIDES, writer: "caller" },
|
|
277
|
+
{ path: "presentation.cardHidden", shape: "fields", layouts: ["kanban", "calendar", ...STORE_KEEPS_TIMELINE ? ["timeline"] : [], "list", "gallery"], writer: "caller" },
|
|
278
|
+
{ path: "presentation.columnOrder", shape: "fields", layouts: GRIDS, writer: "caller" },
|
|
279
|
+
{ path: "presentation.gallerySize", shape: "gallery_size", layouts: ["gallery"], writer: "caller" },
|
|
280
|
+
{ path: "presentation.wrap", shape: "boolean", layouts: GRIDS, writer: "caller" },
|
|
281
|
+
{ path: "presentation.wrapColumns", shape: "fields", layouts: GRIDS, writer: "caller" },
|
|
282
|
+
{ path: "presentation.fit", shape: "fit", layouts: GRIDS, writer: "caller" },
|
|
283
|
+
{ path: "presentation.freezeFirst", shape: "boolean", layouts: GRIDS, writer: "caller" },
|
|
284
|
+
{ path: "presentation.footer", shape: "footer", layouts: GRIDS, writer: "caller" },
|
|
285
|
+
{ path: "presentation.summaries", shape: "summaries", layouts: GRIDS, writer: "caller" },
|
|
286
|
+
{ path: "grid", shape: "grid", layouts: GRIDS, writer: "caller" },
|
|
287
|
+
{ path: "hidden_fields", shape: "input", layouts: HIDES, writer: "input" },
|
|
288
|
+
{ path: "table_id", shape: "server", layouts: ALL, writer: "server" },
|
|
289
|
+
{ path: "order", shape: "server", layouts: GRIDS, writer: "server" },
|
|
290
|
+
{ path: "moved_from", shape: "server", layouts: ALL, writer: "server" }
|
|
291
|
+
];
|
|
292
|
+
var STORE_KEPT_LAYOUTS = ["grid", "kanban", "calendar", "gallery", ...STORE_KEEPS_TIMELINE ? ["timeline"] : [], "list"];
|
|
293
|
+
var KINDS = STORE_KEPT_LAYOUTS;
|
|
294
|
+
function viewSettings(definition, rowFilters) {
|
|
295
|
+
const data = definition ?? {};
|
|
296
|
+
const text = (key) => {
|
|
297
|
+
const v = data[key];
|
|
298
|
+
return typeof v === "string" && v !== "" ? v : null;
|
|
299
|
+
};
|
|
300
|
+
const layout = String(data["layout"] ?? "grid");
|
|
301
|
+
const flat = rowFilters ?? (isObject(data["filters"]) ? data["filters"] : null);
|
|
302
|
+
const moved = data["moved_from"];
|
|
303
|
+
return {
|
|
304
|
+
layout: KINDS.includes(layout) ? layout : "grid",
|
|
305
|
+
filters: flat && Object.keys(flat).length > 0 ? flat : null,
|
|
306
|
+
where: isRule(data["where"]) ? data["where"] : null,
|
|
307
|
+
groupField: text("group_field"),
|
|
308
|
+
swimlaneField: text("swimlane_field"),
|
|
309
|
+
collapsedColumns: Array.isArray(data["collapsed_columns"]) ? data["collapsed_columns"].filter((v) => ["string", "number", "boolean"].includes(typeof v)).map(String) : [],
|
|
310
|
+
measure: text("measure"),
|
|
311
|
+
dateField: text("date_field"),
|
|
312
|
+
startField: text("start_field"),
|
|
313
|
+
endField: text("end_field"),
|
|
314
|
+
imageField: text("image_field"),
|
|
315
|
+
sorts: parseSorts(data["sorts"]),
|
|
316
|
+
ruleId: text("rule_id"),
|
|
317
|
+
isDefault: data["is_default"] === true || data["is_default"] === "true",
|
|
318
|
+
presentation: parseGridPresentation(data["presentation"]),
|
|
319
|
+
movedFrom: isObject(moved) ? moved : null
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
function isObject(raw) {
|
|
323
|
+
return Boolean(raw) && typeof raw === "object" && !Array.isArray(raw);
|
|
324
|
+
}
|
|
325
|
+
function isRule(raw) {
|
|
326
|
+
if (!isObject(raw)) return false;
|
|
327
|
+
const node = raw;
|
|
328
|
+
return typeof node.op === "string" && Array.isArray(node.args);
|
|
329
|
+
}
|
|
330
|
+
function parseSorts(raw) {
|
|
331
|
+
let list = raw;
|
|
332
|
+
if (typeof raw === "string") {
|
|
333
|
+
try {
|
|
334
|
+
list = raw.trim() === "" ? [] : JSON.parse(raw);
|
|
335
|
+
} catch {
|
|
336
|
+
return [];
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
if (!Array.isArray(list)) return [];
|
|
340
|
+
return list.filter((s) => isObject(s) && typeof s.field === "string").map((s) => ({ field: s.field, direction: s.direction === "desc" ? "desc" : "asc" }));
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// src/views.ts
|
|
344
|
+
var VIEW_LAYOUTS = ["grid", "kanban", "calendar", "gallery", "timeline", "list"];
|
|
345
|
+
var LAYOUT_LABEL = {
|
|
346
|
+
grid: "Grid",
|
|
347
|
+
kanban: "Kanban",
|
|
348
|
+
calendar: "Calendar",
|
|
349
|
+
gallery: "Gallery",
|
|
350
|
+
timeline: "Timeline",
|
|
351
|
+
list: "List"
|
|
352
|
+
};
|
|
353
|
+
function viewOrderOf(definition) {
|
|
354
|
+
const raw = definition?.["order"];
|
|
355
|
+
return raw === "manual" ? "manual" : raw === "sorted" ? "sorted" : null;
|
|
356
|
+
}
|
|
357
|
+
function defaultViewOf(views) {
|
|
358
|
+
return views.find((v) => v.isDefault);
|
|
359
|
+
}
|
|
360
|
+
var PAGE_VIEWS = [...VIEW_LAYOUTS, "dashboards", "archived"];
|
|
361
|
+
var PAGE_VIEW_LABEL = {
|
|
362
|
+
...LAYOUT_LABEL,
|
|
363
|
+
dashboards: "Dashboards",
|
|
364
|
+
archived: "Archived"
|
|
365
|
+
};
|
|
366
|
+
function viewFromRow(row) {
|
|
367
|
+
const data = row.definition ?? {};
|
|
368
|
+
const k = viewSettings(data, row.filters && Object.keys(row.filters).length > 0 ? row.filters : null);
|
|
369
|
+
const tableFromDefinition = typeof data["table_id"] === "string" && data["table_id"] !== "" ? data["table_id"] : null;
|
|
370
|
+
return {
|
|
371
|
+
id: row.view_id,
|
|
372
|
+
name: row.name || "Untitled view",
|
|
373
|
+
subject: row.table_id ?? tableFromDefinition ?? "",
|
|
374
|
+
layout: k.layout,
|
|
375
|
+
groupField: k.groupField,
|
|
376
|
+
swimlaneField: k.swimlaneField,
|
|
377
|
+
collapsedColumns: k.collapsedColumns,
|
|
378
|
+
measure: k.measure,
|
|
379
|
+
dateField: k.dateField,
|
|
380
|
+
startField: k.startField,
|
|
381
|
+
endField: k.endField,
|
|
382
|
+
imageField: k.imageField,
|
|
383
|
+
sorts: k.sorts,
|
|
384
|
+
order: viewOrderOf(data),
|
|
385
|
+
ruleId: k.ruleId,
|
|
386
|
+
...k.filters ? { filters: k.filters } : {},
|
|
387
|
+
where: k.where,
|
|
388
|
+
// The older table's own default view, carried in by the mover, IS this table's default —
|
|
389
|
+
// the mover wrote the row's column, which `custom.views` does not return. Read as anything
|
|
390
|
+
// else, the page would seed a second "All records" beside it and open on that.
|
|
391
|
+
isDefault: k.isDefault || k.movedFrom?.["kind"] === "default_view",
|
|
392
|
+
presentation: k.presentation,
|
|
393
|
+
movedFrom: k.movedFrom
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// src/viewLook.ts
|
|
398
|
+
function lookFromDocument(doc) {
|
|
399
|
+
const data = doc ?? {};
|
|
400
|
+
const read = viewSettings(data);
|
|
401
|
+
const out = {};
|
|
402
|
+
const has = (key) => Object.prototype.hasOwnProperty.call(data, key);
|
|
403
|
+
if (has("layout") && VIEW_LAYOUTS.includes(String(data["layout"]))) {
|
|
404
|
+
out.layout = data["layout"];
|
|
405
|
+
}
|
|
406
|
+
if (has("group_field")) out.groupField = read.groupField;
|
|
407
|
+
if (has("swimlane_field")) out.swimlaneField = read.swimlaneField;
|
|
408
|
+
if (has("collapsed_columns")) out.collapsedColumns = read.collapsedColumns;
|
|
409
|
+
if (has("measure")) out.measure = read.measure;
|
|
410
|
+
if (has("date_field")) out.dateField = read.dateField;
|
|
411
|
+
if (has("start_field")) out.startField = read.startField;
|
|
412
|
+
if (has("end_field")) out.endField = read.endField;
|
|
413
|
+
if (has("image_field")) out.imageField = read.imageField;
|
|
414
|
+
if (has("sorts")) out.sorts = read.sorts;
|
|
415
|
+
if (has("where")) out.where = read.where;
|
|
416
|
+
if (has("presentation")) out.presentation = parseGridPresentation(data["presentation"]);
|
|
417
|
+
return out;
|
|
418
|
+
}
|
|
419
|
+
function applyLook(view, look) {
|
|
420
|
+
if (!look) return view;
|
|
421
|
+
return { ...view, ...look };
|
|
422
|
+
}
|
|
423
|
+
async function readLooks(client, tableId) {
|
|
424
|
+
const answered = await client.viewLookRead({ table_id: tableId });
|
|
425
|
+
if (!answered.ok) return answered;
|
|
426
|
+
const out = {};
|
|
427
|
+
for (const [viewId, row] of Object.entries(answered.data ?? {})) {
|
|
428
|
+
out[viewId] = lookFromDocument(row?.look ?? null);
|
|
429
|
+
}
|
|
430
|
+
return { ok: true, data: out };
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/firstPage.ts
|
|
434
|
+
var TABLE_PAGE_SIZE = 100;
|
|
435
|
+
function firstGridPageArgs(input) {
|
|
436
|
+
const { shown, fields } = input;
|
|
437
|
+
if (!shown) return null;
|
|
438
|
+
if ((shown.layout ?? "grid") !== "grid") return null;
|
|
439
|
+
if (shown.ruleId) return null;
|
|
440
|
+
if (shown.order === "manual") return null;
|
|
441
|
+
if (shown.filters && Object.keys(shown.filters).length > 0) return null;
|
|
442
|
+
if (shown.presentation?.grouping) return null;
|
|
443
|
+
const first = (shown.sorts ?? [])[0];
|
|
444
|
+
const viewSort = first && fields.some((f) => f.key === first.field) ? { id: first.field, direction: first.direction } : null;
|
|
445
|
+
const opening = viewSort ?? defaultSortOf(input.table, fields);
|
|
446
|
+
return {
|
|
447
|
+
p_table_id: input.tableId,
|
|
448
|
+
p_filter: {},
|
|
449
|
+
p_search: null,
|
|
450
|
+
p_sort: pageSortFor(fields, opening),
|
|
451
|
+
p_view_id: null,
|
|
452
|
+
p_limit: input.pageSize ?? TABLE_PAGE_SIZE,
|
|
453
|
+
p_offset: 0
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
async function firstGridPageRequest(client, tableId, options = {}) {
|
|
457
|
+
const [table, fields, views, looks] = await Promise.all([
|
|
458
|
+
client.tableRead({ table_id: tableId }),
|
|
459
|
+
client.fields({ table_id: tableId }),
|
|
460
|
+
client.views({ table_id: tableId }),
|
|
461
|
+
readLooks(client, tableId)
|
|
462
|
+
]);
|
|
463
|
+
if (!table.ok || !fields.ok || !views.ok || !looks.ok) return null;
|
|
464
|
+
const mine = views.data.map(viewFromRow).filter((v) => v.subject === tableId);
|
|
465
|
+
const view = defaultViewOf(mine) ?? mine[0] ?? null;
|
|
466
|
+
const shown = view ? applyLook(view, looks.data[view.id]) : null;
|
|
467
|
+
return firstGridPageArgs({ tableId, table: table.data, fields: fields.data, shown, ...options.pageSize ? { pageSize: options.pageSize } : {} });
|
|
468
|
+
}
|
|
469
|
+
export {
|
|
470
|
+
TABLE_PAGE_SIZE,
|
|
471
|
+
firstGridPageArgs,
|
|
472
|
+
firstGridPageRequest
|
|
473
|
+
};
|
|
474
|
+
//# sourceMappingURL=first-page.js.map
|