@marktiderman/genesis-core 1.16.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -4
- package/dist/{chunk-Y452U45I.js → chunk-2VVZ2KX3.js} +3 -3
- package/dist/{chunk-Y452U45I.js.map → chunk-2VVZ2KX3.js.map} +1 -1
- package/dist/{chunk-E4777JKI.js → chunk-3FFBW4XC.js} +21 -8
- package/dist/chunk-3FFBW4XC.js.map +1 -0
- package/dist/{chunk-OYIUIW7C.js → chunk-7PUFVNPB.js} +2 -2
- package/dist/chunk-7PUFVNPB.js.map +1 -0
- package/dist/{chunk-VMRLCTZR.js → chunk-CC37H7O2.js} +4 -4
- package/dist/{chunk-VMRLCTZR.js.map → chunk-CC37H7O2.js.map} +1 -1
- package/dist/{chunk-CZOFWG54.js → chunk-GWQHP3RC.js} +3 -3
- package/dist/{chunk-CZOFWG54.js.map → chunk-GWQHP3RC.js.map} +1 -1
- package/dist/{chunk-K7WEY5WR.js → chunk-OSFG3GFY.js} +3 -3
- package/dist/{chunk-K7WEY5WR.js.map → chunk-OSFG3GFY.js.map} +1 -1
- package/dist/{chunk-J2EIM7FC.js → chunk-QPD4FKPC.js} +4 -4
- package/dist/{chunk-J2EIM7FC.js.map → chunk-QPD4FKPC.js.map} +1 -1
- package/dist/chunk-XMC4EJUE.js +131 -0
- package/dist/chunk-XMC4EJUE.js.map +1 -0
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +9 -8
- package/dist/hooks/mutation-mode.js +2 -2
- package/dist/hooks/use-infinite-resource.js +2 -2
- package/dist/hooks/use-one.js +2 -2
- package/dist/hooks/use-relation-label.d.ts +25 -0
- package/dist/hooks/use-relation-label.js +5 -0
- package/dist/hooks/use-relation-label.js.map +1 -0
- package/dist/hooks/use-resource-form.js +4 -4
- package/dist/hooks/use-resource.js +3 -3
- package/dist/index.d.ts +5 -4
- package/dist/index.js +9 -8
- package/dist/resource-view/index.d.ts +128 -7
- package/dist/resource-view/index.js +148 -1
- package/dist/resource-view/index.js.map +1 -1
- package/dist/{viewer-scope-77MqxvmZ.d.ts → viewer-scope-bthEYSOB.d.ts} +24 -6
- package/package.json +1 -1
- package/dist/chunk-E4777JKI.js.map +0 -1
- package/dist/chunk-OYIUIW7C.js.map +0 -1
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { useDataProvider } from './chunk-VDEW4AOS.js';
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
|
|
4
|
+
var CHUNK = 100;
|
|
5
|
+
var IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
6
|
+
var NAMING = /^(name|title|label|full_name|display_name)$/;
|
|
7
|
+
var batches = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
var namers = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
var SETTLE_MS = 1e4;
|
|
10
|
+
function within(work, fallback) {
|
|
11
|
+
return new Promise((resolve) => {
|
|
12
|
+
const timer = setTimeout(() => resolve(fallback), SETTLE_MS);
|
|
13
|
+
const done = (value) => {
|
|
14
|
+
clearTimeout(timer);
|
|
15
|
+
resolve(value);
|
|
16
|
+
};
|
|
17
|
+
try {
|
|
18
|
+
work().then(done, () => done(fallback));
|
|
19
|
+
} catch {
|
|
20
|
+
done(fallback);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function namingField(provider, resource) {
|
|
25
|
+
let known = namers.get(provider);
|
|
26
|
+
if (!known) namers.set(provider, known = /* @__PURE__ */ new Map());
|
|
27
|
+
let found = known.get(resource);
|
|
28
|
+
if (!found) {
|
|
29
|
+
const describe = provider.describe?.bind(provider);
|
|
30
|
+
const table = known;
|
|
31
|
+
found = describe ? within(
|
|
32
|
+
() => describe(resource).then((schema) => schema.labelField ?? schema.fields.find((f) => NAMING.test(f.name))?.name ?? null),
|
|
33
|
+
void 0
|
|
34
|
+
).then((field) => {
|
|
35
|
+
if (field === void 0) table.delete(resource);
|
|
36
|
+
return field ?? void 0;
|
|
37
|
+
}) : Promise.resolve(void 0);
|
|
38
|
+
known.set(resource, found);
|
|
39
|
+
}
|
|
40
|
+
return found;
|
|
41
|
+
}
|
|
42
|
+
async function chunkSize(provider, resource) {
|
|
43
|
+
const capabilities = provider.capabilities?.bind(provider);
|
|
44
|
+
const max = capabilities ? await within(() => capabilities(resource).then((c) => c.maxPerPage), void 0) : void 0;
|
|
45
|
+
return typeof max === "number" && max >= 1 ? Math.min(CHUNK, Math.floor(max)) : CHUNK;
|
|
46
|
+
}
|
|
47
|
+
function words(value) {
|
|
48
|
+
if (typeof value === "number" && Number.isFinite(value)) return String(value);
|
|
49
|
+
if (typeof value !== "string") return null;
|
|
50
|
+
return value.trim() || null;
|
|
51
|
+
}
|
|
52
|
+
async function flush(provider, batch) {
|
|
53
|
+
const { reference, ids } = batch;
|
|
54
|
+
const fail = (keys, error) => keys.forEach((k) => ids.get(k)?.waiters.forEach((w) => w.reject(error)));
|
|
55
|
+
const all = [...ids.keys()];
|
|
56
|
+
let labelField;
|
|
57
|
+
let size;
|
|
58
|
+
try {
|
|
59
|
+
labelField = batch.labelField ?? await namingField(provider, reference.resource);
|
|
60
|
+
if (labelField !== void 0 && !IDENTIFIER.test(labelField)) labelField = void 0;
|
|
61
|
+
size = await chunkSize(provider, reference.resource);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
fail(all, error);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const select = labelField && IDENTIFIER.test(reference.field) ? `${reference.field},${labelField}` : void 0;
|
|
67
|
+
for (let i = 0; i < all.length; i += size) {
|
|
68
|
+
const chunk = all.slice(i, i + size);
|
|
69
|
+
try {
|
|
70
|
+
const { data } = await provider.getList(reference.resource, {
|
|
71
|
+
// The whole page: a link to a field that isn't unique can match more rows than ids.
|
|
72
|
+
pagination: { page: 1, perPage: size },
|
|
73
|
+
filters: [{ field: reference.field, operator: "in", value: chunk.map((k) => ids.get(k).id) }],
|
|
74
|
+
count: "none",
|
|
75
|
+
...select ? { select } : {}
|
|
76
|
+
});
|
|
77
|
+
const found = /* @__PURE__ */ new Map();
|
|
78
|
+
for (const row of data) {
|
|
79
|
+
const key = String(row[reference.field]);
|
|
80
|
+
if (found.get(key)) continue;
|
|
81
|
+
const name = labelField ? row[labelField] : row[Object.keys(row).find((k) => NAMING.test(k)) ?? ""];
|
|
82
|
+
found.set(key, words(name));
|
|
83
|
+
}
|
|
84
|
+
for (const k of chunk) {
|
|
85
|
+
const asked = ids.get(k);
|
|
86
|
+
asked?.waiters.forEach((w) => w.resolve(found.get(String(asked.id)) ?? null));
|
|
87
|
+
}
|
|
88
|
+
} catch (error) {
|
|
89
|
+
fail(chunk, error);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function loadRelationLabel(provider, reference, id, labelField) {
|
|
94
|
+
let pending = batches.get(provider);
|
|
95
|
+
if (!pending) batches.set(provider, pending = /* @__PURE__ */ new Map());
|
|
96
|
+
const key = `${reference.resource}\0${reference.field}\0${labelField ?? ""}`;
|
|
97
|
+
let batch = pending.get(key);
|
|
98
|
+
if (!batch) {
|
|
99
|
+
const created = { reference, labelField, ids: /* @__PURE__ */ new Map() };
|
|
100
|
+
pending.set(key, batch = created);
|
|
101
|
+
setTimeout(() => {
|
|
102
|
+
pending.delete(key);
|
|
103
|
+
void flush(provider, created);
|
|
104
|
+
}, 0);
|
|
105
|
+
}
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
const idKey = `${typeof id}:${String(id)}`;
|
|
108
|
+
const asked = batch.ids.get(idKey) ?? { id, waiters: [] };
|
|
109
|
+
asked.waiters.push({ resolve, reject });
|
|
110
|
+
batch.ids.set(idKey, asked);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
function useRelationLabel(reference, id, options = {}) {
|
|
114
|
+
const provider = useDataProvider();
|
|
115
|
+
const { labelField, enabled = true } = options;
|
|
116
|
+
const linked = typeof id === "string" || typeof id === "number" && Number.isFinite(id) ? id : null;
|
|
117
|
+
const key = linked === null ? null : `${typeof linked}:${String(linked)}`;
|
|
118
|
+
const query = useQuery({
|
|
119
|
+
queryKey: [reference?.resource, "relation-label", { field: reference?.field, labelField: labelField ?? null, id: key }],
|
|
120
|
+
enabled: enabled && Boolean(reference && key),
|
|
121
|
+
staleTime: 6e4,
|
|
122
|
+
retry: false,
|
|
123
|
+
queryFn: () => loadRelationLabel(provider, reference, linked, labelField)
|
|
124
|
+
});
|
|
125
|
+
if (query.isError) return null;
|
|
126
|
+
return query.data;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export { loadRelationLabel, useRelationLabel };
|
|
130
|
+
//# sourceMappingURL=chunk-XMC4EJUE.js.map
|
|
131
|
+
//# sourceMappingURL=chunk-XMC4EJUE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-relation-label.ts"],"names":[],"mappings":";;;AAiBA,IAAM,KAAA,GAAQ,GAAA;AAEd,IAAM,UAAA,GAAa,0BAAA;AAEnB,IAAM,MAAA,GAAS,6CAAA;AAUf,IAAM,OAAA,uBAAc,OAAA,EAA0C;AAC9D,IAAM,MAAA,uBAAa,OAAA,EAAgE;AAEnF,IAAM,SAAA,GAAY,GAAA;AAGlB,SAAS,MAAA,CAAU,MAAwB,QAAA,EAAyB;AAClE,EAAA,OAAO,IAAI,OAAA,CAAW,CAAC,OAAA,KAAY;AACjC,IAAA,MAAM,QAAQ,UAAA,CAAW,MAAM,OAAA,CAAQ,QAAQ,GAAG,SAAS,CAAA;AAC3D,IAAA,MAAM,IAAA,GAAO,CAAC,KAAA,KAAa;AACzB,MAAA,YAAA,CAAa,KAAK,CAAA;AAClB,MAAA,OAAA,CAAQ,KAAK,CAAA;AAAA,IACf,CAAA;AACA,IAAA,IAAI;AACF,MAAA,IAAA,GAAO,IAAA,CAAK,IAAA,EAAM,MAAM,IAAA,CAAK,QAAQ,CAAC,CAAA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AAM,QAAQ,QAAA,CAAS;AAAA,IACrB,QAAA,EAAU,CAAC,SAAA,EAAW,QAAA,EAAU,kBAAkB,EAAE,KAAA,EAAO,SAAA,EAAW,KAAA,EAAO,UAAA,EAAY,UAAA,IAAc,IAAA,EAAM,EAAA,EAAI,KAAK,CAAA;AAAA,IACtH,OAAA,EAAS,OAAA,IAAW,OAAA,CAAQ,SAAA,IAAa,GAAG,CAAA;AAAA,IAC5C,SAAA,EAAW,GAAA;AAAA,IACX,KAAA,EAAO,KAAA;AAAA,IACP,SAAS,MAAM,iBAAA,CAAkB,QAAA,EAAU,SAAA,EAAY,QAAS,UAAU;AAAA,GAC3E,CAAA;AACD,EAAA,IAAI,KAAA,CAAM,SAAS,OAAO,IAAA;AAC1B,EAAA,OAAO,KAAA,CAAM,IAAA;AACf","file":"chunk-XMC4EJUE.js","sourcesContent":["// A link's words: the linked row's name in place of its id (docs/RESOURCE-VIEW.md, \"Relation\n// labels\"). Every cell asks for its own id, and the ids asked for in the same moment go out as\n// one `in` query per linked resource, so a page of 50 rows costs one request, never 50.\n\nimport { useQuery } from \"@tanstack/react-query\";\nimport { useDataProvider } from \"../provider/context\";\nimport type { DataProvider, Identifier } from \"../provider/types\";\nimport type { FieldReference } from \"../schema/types\";\n\nexport interface UseRelationLabelOptions {\n /** The linked row's field that names it. Default: the linked resource's `labelField` (`describe`). */\n labelField?: string;\n /** Default `true`. */\n enabled?: boolean;\n}\n\n// Ids per request: an `in` list stays well inside a URL.\nconst CHUNK = 100;\n// Field names only go into `select`, so nothing else rides along in the request.\nconst IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;\n// What names a row when nothing says (as `defineView` guesses a contract's labelField).\nconst NAMING = /^(name|title|label|full_name|display_name)$/;\n\ntype Waiter = { resolve: (label: string | null) => void; reject: (error: unknown) => void };\n// Keyed by the id's type and text, so 1 and \"1\" are both sent as given: a provider that compares\n// strictly (the mock's `in`) must get a number as a number. Rows match by text either way, since\n// a database may hand back 1 for \"1\".\ntype Asked = { id: Identifier; waiters: Waiter[] };\ntype Batch = { reference: FieldReference; labelField: string | undefined; ids: Map<string, Asked> };\n\n// Per provider, so two providers (two apps, a test each) never share a batch or a guess.\nconst batches = new WeakMap<DataProvider, Map<string, Batch>>();\nconst namers = new WeakMap<DataProvider, Map<string, Promise<string | undefined>>>();\n// How long a label waits on `describe` or `capabilities` before going on without them.\nconst SETTLE_MS = 10_000;\n\n/** A promise's value, or `fallback` when it fails, throws or takes longer than SETTLE_MS. */\nfunction within<T>(work: () => Promise<T>, fallback: T): Promise<T> {\n return new Promise<T>((resolve) => {\n const timer = setTimeout(() => resolve(fallback), SETTLE_MS);\n const done = (value: T) => {\n clearTimeout(timer);\n resolve(value);\n };\n try {\n work().then(done, () => done(fallback));\n } catch {\n done(fallback);\n }\n });\n}\n\n/**\n * The linked resource's naming field, from `describe` once per resource; undefined when it can't\n * say. A failed `describe` isn't remembered, so the next page asks again.\n */\nfunction namingField(provider: DataProvider, resource: string): Promise<string | undefined> {\n let known = namers.get(provider);\n if (!known) namers.set(provider, (known = new Map()));\n let found = known.get(resource);\n if (!found) {\n const describe = provider.describe?.bind(provider);\n const table = known;\n found = describe\n ? within(\n () =>\n describe(resource).then((schema) => schema.labelField ?? schema.fields.find((f) => NAMING.test(f.name))?.name ?? null),\n undefined as string | null | undefined,\n ).then((field) => {\n // undefined: describe failed. null: it answered, with no naming field.\n if (field === undefined) table.delete(resource);\n return field ?? undefined;\n })\n : Promise.resolve(undefined);\n known.set(resource, found);\n }\n return found;\n}\n\n/** Ids per request: the provider's page limit, at most CHUNK. */\nasync function chunkSize(provider: DataProvider, resource: string): Promise<number> {\n const capabilities = provider.capabilities?.bind(provider);\n const max = capabilities ? await within(() => capabilities(resource).then((c) => c.maxPerPage), undefined) : undefined;\n return typeof max === \"number\" && max >= 1 ? Math.min(CHUNK, Math.floor(max)) : CHUNK;\n}\n\n/** A value as words, or null when it has none. */\nfunction words(value: unknown): string | null {\n if (typeof value === \"number\" && Number.isFinite(value)) return String(value);\n if (typeof value !== \"string\") return null;\n return value.trim() || null;\n}\n\nasync function flush(provider: DataProvider, batch: Batch): Promise<void> {\n const { reference, ids } = batch;\n const fail = (keys: readonly string[], error: unknown) => keys.forEach((k) => ids.get(k)?.waiters.forEach((w) => w.reject(error)));\n const all = [...ids.keys()];\n let labelField: string | undefined;\n let size: number;\n try {\n labelField = batch.labelField ?? (await namingField(provider, reference.resource));\n if (labelField !== undefined && !IDENTIFIER.test(labelField)) labelField = undefined;\n size = await chunkSize(provider, reference.resource);\n } catch (error) {\n // Every waiter settles, whatever went wrong.\n fail(all, error);\n return;\n }\n const select = labelField && IDENTIFIER.test(reference.field) ? `${reference.field},${labelField}` : undefined;\n for (let i = 0; i < all.length; i += size) {\n const chunk = all.slice(i, i + size);\n try {\n const { data } = await provider.getList(reference.resource, {\n // The whole page: a link to a field that isn't unique can match more rows than ids.\n pagination: { page: 1, perPage: size },\n filters: [{ field: reference.field, operator: \"in\", value: chunk.map((k) => ids.get(k)!.id) as string[] | number[] }],\n count: \"none\",\n ...(select ? { select } : {}),\n });\n const found = new Map<string, string | null>();\n for (const row of data as Record<string, unknown>[]) {\n const key = String(row[reference.field]);\n if (found.get(key)) continue;\n const name = labelField ? row[labelField] : row[Object.keys(row).find((k) => NAMING.test(k)) ?? \"\"];\n found.set(key, words(name));\n }\n // An id the viewer can't see, or one that's gone, has no words.\n for (const k of chunk) {\n const asked = ids.get(k);\n asked?.waiters.forEach((w) => w.resolve(found.get(String(asked.id)) ?? null));\n }\n } catch (error) {\n fail(chunk, error);\n }\n }\n}\n\n/**\n * The words for one linked id, batched with every other id asked for in the same tick: one\n * `getList(resource, { filters: [{ field, operator: \"in\" }] })` per linked resource and naming\n * field. Resolves null when the row has no words or isn't visible to this viewer.\n */\nexport function loadRelationLabel(\n provider: DataProvider,\n reference: FieldReference,\n id: Identifier,\n labelField?: string,\n): Promise<string | null> {\n let pending = batches.get(provider);\n if (!pending) batches.set(provider, (pending = new Map()));\n const key = `${reference.resource}\\u0000${reference.field}\\u0000${labelField ?? \"\"}`;\n let batch = pending.get(key);\n if (!batch) {\n const created: Batch = { reference, labelField, ids: new Map() };\n pending.set(key, (batch = created));\n // A macrotask, not a microtask: every cell's effect in a commit has asked by then.\n setTimeout(() => {\n pending!.delete(key);\n void flush(provider, created);\n }, 0);\n }\n return new Promise((resolve, reject) => {\n const idKey = `${typeof id}:${String(id)}`;\n const asked = batch!.ids.get(idKey) ?? { id, waiters: [] };\n asked.waiters.push({ resolve, reject });\n batch!.ids.set(idKey, asked);\n });\n}\n\n/**\n * A linked row's words for a `relation` cell: `undefined` while they load, `null` when there are\n * none (the row is hidden from this viewer, gone, unnamed, or the read failed), so a screen shows\n * its own words then, never the raw id. Cached per id for a minute and refreshed when the linked\n * resource changes (its writes invalidate `[resource]`).\n */\nexport function useRelationLabel(\n reference: FieldReference | undefined,\n id: unknown,\n options: UseRelationLabelOptions = {},\n): string | null | undefined {\n const provider = useDataProvider();\n const { labelField, enabled = true } = options;\n const linked: Identifier | null = typeof id === \"string\" || (typeof id === \"number\" && Number.isFinite(id)) ? id : null;\n const key = linked === null ? null : `${typeof linked}:${String(linked)}`;\n const query = useQuery({\n queryKey: [reference?.resource, \"relation-label\", { field: reference?.field, labelField: labelField ?? null, id: key }],\n enabled: enabled && Boolean(reference && key),\n staleTime: 60_000,\n retry: false,\n queryFn: () => loadRelationLabel(provider, reference!, linked!, labelField),\n });\n if (query.isError) return null;\n return query.data;\n}\n"]}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export { UseResourceOptions, UseResourceReturn, useResource } from './use-resource.js';
|
|
2
2
|
export { UseOneOptions, useOne } from './use-one.js';
|
|
3
|
+
export { UseRelationLabelOptions, loadRelationLabel, useRelationLabel } from './use-relation-label.js';
|
|
3
4
|
export { InfinitePageParam, UseInfiniteResourceOptions, UseInfiniteResourceReturn, useInfiniteResource } from './use-infinite-resource.js';
|
|
4
5
|
export { useCapabilities } from './use-capabilities.js';
|
|
5
6
|
export { UseWriteOptions, UseWriteReturn, WRITE_FAILED, useWrite } from './use-write.js';
|
|
6
7
|
export { UseDraftReturn, useDraft } from './use-draft.js';
|
|
7
8
|
export { DEFAULT_DRAFT_DELAY_MS, DRAFT_NOT_SAVED, DraftAdoption, DraftController, DraftOptions, DraftSeed, DraftState, DraftStatus, DraftValue, isNetworkFailure, stableJson } from './draft-controller.js';
|
|
8
|
-
export { G as GenesisViewerRoles, N as NO_VIEWER, R as ResourceScope, V as Viewer, a as ViewerContext, b as ViewerScope, c as ViewerScopeProps, d as clearViewerCache, u as useOptionalViewerScope, e as useViewer, f as useViewerScope } from '../viewer-scope-
|
|
9
|
+
export { G as GenesisViewerRoles, N as NO_VIEWER, R as ResourceScope, V as Viewer, a as ViewerContext, b as ViewerScope, c as ViewerScopeProps, d as clearViewerCache, s as scopeClock, u as useOptionalViewerScope, e as useViewer, f as useViewerScope } from '../viewer-scope-bthEYSOB.js';
|
|
9
10
|
export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS, LiveOptions } from './use-live.js';
|
|
10
11
|
export { UseResourceFormOptions, UseResourceFormReturn, buildArrayItemDefaults, useResourceForm } from './use-resource-form.js';
|
|
11
12
|
export { UseWizardReturn, WizardStep, useWizard } from './use-wizard.js';
|
package/dist/hooks/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
export { ViewerScope, clearViewerCache, useOptionalViewerScope, useViewer, useViewerScope } from '../chunk-
|
|
1
|
+
export { ViewerScope, clearViewerCache, scopeClock, useOptionalViewerScope, useViewer, useViewerScope } from '../chunk-3FFBW4XC.js';
|
|
2
|
+
export { WRITE_FAILED, useWrite } from '../chunk-52T2EYXH.js';
|
|
2
3
|
export { NO_VIEWER } from '../chunk-OZYF55E3.js';
|
|
3
|
-
export { useInfiniteResource } from '../chunk-
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
4
|
+
export { useInfiniteResource } from '../chunk-2VVZ2KX3.js';
|
|
5
|
+
export { loadRelationLabel, useRelationLabel } from '../chunk-XMC4EJUE.js';
|
|
6
|
+
export { buildArrayItemDefaults, useResourceForm } from '../chunk-QPD4FKPC.js';
|
|
7
|
+
export { useOne } from '../chunk-GWQHP3RC.js';
|
|
8
|
+
export { useResource } from '../chunk-CC37H7O2.js';
|
|
7
9
|
export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS } from '../chunk-K4ZNAF3G.js';
|
|
8
10
|
export { DEFAULT_UNSAVED_CHANGES_MESSAGE, useUnsavedChangesGuard } from '../chunk-XQO4OH2N.js';
|
|
9
11
|
export { useWizard } from '../chunk-7KOLYF27.js';
|
|
10
|
-
export { WRITE_FAILED, useWrite } from '../chunk-52T2EYXH.js';
|
|
11
12
|
import '../chunk-AUVKRXRC.js';
|
|
12
|
-
export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from '../chunk-
|
|
13
|
-
import '../chunk-
|
|
13
|
+
export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from '../chunk-OSFG3GFY.js';
|
|
14
|
+
import '../chunk-7PUFVNPB.js';
|
|
14
15
|
import '../chunk-7NUL32W7.js';
|
|
15
16
|
export { useCapabilities } from '../chunk-LGTXQTHA.js';
|
|
16
17
|
import '../chunk-VDEW4AOS.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { DEFAULT_UNDO_DELAY_MS, DROPPED_WRITE_MESSAGE, cachedRecord, dropPendingWrites, executeWrite, flushPendingWrites, invalidateResource, pendingWriteCount, providerServesUndo, sameValue } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { DEFAULT_UNDO_DELAY_MS, DROPPED_WRITE_MESSAGE, cachedRecord, dropPendingWrites, executeWrite, flushPendingWrites, invalidateResource, pendingWriteCount, providerServesUndo, sameValue } from '../chunk-OSFG3GFY.js';
|
|
2
|
+
import '../chunk-7PUFVNPB.js';
|
|
3
3
|
import '../chunk-LGTXQTHA.js';
|
|
4
4
|
import '../chunk-VDEW4AOS.js';
|
|
5
5
|
import '../chunk-ZYJUEJ4Z.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { useInfiniteResource } from '../chunk-
|
|
1
|
+
export { useInfiniteResource } from '../chunk-2VVZ2KX3.js';
|
|
2
2
|
import '../chunk-K4ZNAF3G.js';
|
|
3
3
|
import '../chunk-AUVKRXRC.js';
|
|
4
|
-
import '../chunk-
|
|
4
|
+
import '../chunk-7PUFVNPB.js';
|
|
5
5
|
import '../chunk-VDEW4AOS.js';
|
|
6
6
|
import '../chunk-ZYJUEJ4Z.js';
|
|
7
7
|
//# sourceMappingURL=use-infinite-resource.js.map
|
package/dist/hooks/use-one.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { useOne } from '../chunk-
|
|
1
|
+
export { useOne } from '../chunk-GWQHP3RC.js';
|
|
2
2
|
import '../chunk-K4ZNAF3G.js';
|
|
3
3
|
import '../chunk-AUVKRXRC.js';
|
|
4
|
-
import '../chunk-
|
|
4
|
+
import '../chunk-7PUFVNPB.js';
|
|
5
5
|
import '../chunk-VDEW4AOS.js';
|
|
6
6
|
import '../chunk-ZYJUEJ4Z.js';
|
|
7
7
|
//# sourceMappingURL=use-one.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { D as DataProvider, a as Identifier } from '../types-CXhqXPN1.js';
|
|
2
|
+
import { b as FieldReference } from '../types-o8j7g6O6.js';
|
|
3
|
+
import '../form-types.js';
|
|
4
|
+
|
|
5
|
+
interface UseRelationLabelOptions {
|
|
6
|
+
/** The linked row's field that names it. Default: the linked resource's `labelField` (`describe`). */
|
|
7
|
+
labelField?: string;
|
|
8
|
+
/** Default `true`. */
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* The words for one linked id, batched with every other id asked for in the same tick: one
|
|
13
|
+
* `getList(resource, { filters: [{ field, operator: "in" }] })` per linked resource and naming
|
|
14
|
+
* field. Resolves null when the row has no words or isn't visible to this viewer.
|
|
15
|
+
*/
|
|
16
|
+
declare function loadRelationLabel(provider: DataProvider, reference: FieldReference, id: Identifier, labelField?: string): Promise<string | null>;
|
|
17
|
+
/**
|
|
18
|
+
* A linked row's words for a `relation` cell: `undefined` while they load, `null` when there are
|
|
19
|
+
* none (the row is hidden from this viewer, gone, unnamed, or the read failed), so a screen shows
|
|
20
|
+
* its own words then, never the raw id. Cached per id for a minute and refreshed when the linked
|
|
21
|
+
* resource changes (its writes invalidate `[resource]`).
|
|
22
|
+
*/
|
|
23
|
+
declare function useRelationLabel(reference: FieldReference | undefined, id: unknown, options?: UseRelationLabelOptions): string | null | undefined;
|
|
24
|
+
|
|
25
|
+
export { type UseRelationLabelOptions, loadRelationLabel, useRelationLabel };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"use-relation-label.js"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export { buildArrayItemDefaults, useResourceForm } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { buildArrayItemDefaults, useResourceForm } from '../chunk-QPD4FKPC.js';
|
|
2
|
+
import '../chunk-GWQHP3RC.js';
|
|
3
3
|
import '../chunk-K4ZNAF3G.js';
|
|
4
4
|
import '../chunk-XQO4OH2N.js';
|
|
5
5
|
import '../chunk-AUVKRXRC.js';
|
|
6
|
-
import '../chunk-
|
|
7
|
-
import '../chunk-
|
|
6
|
+
import '../chunk-OSFG3GFY.js';
|
|
7
|
+
import '../chunk-7PUFVNPB.js';
|
|
8
8
|
import '../chunk-7NUL32W7.js';
|
|
9
9
|
import '../chunk-LGTXQTHA.js';
|
|
10
10
|
import '../chunk-VDEW4AOS.js';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { useResource } from '../chunk-
|
|
1
|
+
export { useResource } from '../chunk-CC37H7O2.js';
|
|
2
2
|
import '../chunk-K4ZNAF3G.js';
|
|
3
3
|
import '../chunk-AUVKRXRC.js';
|
|
4
|
-
import '../chunk-
|
|
5
|
-
import '../chunk-
|
|
4
|
+
import '../chunk-OSFG3GFY.js';
|
|
5
|
+
import '../chunk-7PUFVNPB.js';
|
|
6
6
|
import '../chunk-7NUL32W7.js';
|
|
7
7
|
import '../chunk-LGTXQTHA.js';
|
|
8
8
|
import '../chunk-VDEW4AOS.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -7,12 +7,13 @@ export { S as StorageAdapter } from './types-DKcxHXxq.js';
|
|
|
7
7
|
export { createLocalStorageAdapter, createMemoryStorageAdapter, createNoopStorageAdapter } from './storage/index.js';
|
|
8
8
|
export { UseResourceOptions, UseResourceReturn, useResource } from './hooks/use-resource.js';
|
|
9
9
|
export { UseOneOptions, useOne } from './hooks/use-one.js';
|
|
10
|
+
export { UseRelationLabelOptions, loadRelationLabel, useRelationLabel } from './hooks/use-relation-label.js';
|
|
10
11
|
export { InfinitePageParam, UseInfiniteResourceOptions, UseInfiniteResourceReturn, useInfiniteResource } from './hooks/use-infinite-resource.js';
|
|
11
12
|
export { useCapabilities } from './hooks/use-capabilities.js';
|
|
12
13
|
export { UseWriteOptions, UseWriteReturn, WRITE_FAILED, useWrite } from './hooks/use-write.js';
|
|
13
14
|
export { UseDraftReturn, useDraft } from './hooks/use-draft.js';
|
|
14
15
|
export { DEFAULT_DRAFT_DELAY_MS, DRAFT_NOT_SAVED, DraftAdoption, DraftController, DraftOptions, DraftSeed, DraftState, DraftStatus, DraftValue, isNetworkFailure, stableJson } from './hooks/draft-controller.js';
|
|
15
|
-
export { G as GenesisViewerRoles, N as NO_VIEWER, R as ResourceScope, V as Viewer, a as ViewerContext, b as ViewerScope, c as ViewerScopeProps, d as clearViewerCache, u as useOptionalViewerScope, e as useViewer, f as useViewerScope } from './viewer-scope-
|
|
16
|
+
export { G as GenesisViewerRoles, N as NO_VIEWER, R as ResourceScope, V as Viewer, a as ViewerContext, b as ViewerScope, c as ViewerScopeProps, d as clearViewerCache, s as scopeClock, u as useOptionalViewerScope, e as useViewer, f as useViewerScope } from './viewer-scope-bthEYSOB.js';
|
|
16
17
|
export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS, LiveOptions } from './hooks/use-live.js';
|
|
17
18
|
export { UseResourceFormOptions, UseResourceFormReturn, buildArrayItemDefaults, useResourceForm } from './hooks/use-resource-form.js';
|
|
18
19
|
export { UseWizardReturn, WizardStep, useWizard } from './hooks/use-wizard.js';
|
|
@@ -32,13 +33,13 @@ import 'react-hook-form';
|
|
|
32
33
|
/** Who and when a key is for. `viewer` is required; null means signed out. */
|
|
33
34
|
interface KeyScope {
|
|
34
35
|
viewer: string | null;
|
|
35
|
-
/** The group,
|
|
36
|
+
/** The group, organization or space the screen is filtered to. */
|
|
36
37
|
group?: string | null;
|
|
37
38
|
/** The person-day (YYYY-MM-DD) a "today" read is for. */
|
|
38
39
|
day?: string | null;
|
|
39
40
|
/**
|
|
40
|
-
* Where the viewer is working (ViewerScope's `scope`:
|
|
41
|
-
* key, so the same query for two
|
|
41
|
+
* Where the viewer is working (ViewerScope's `scope`: an org, a league, a person…). Part of
|
|
42
|
+
* every key, so the same query for two scopes never shares a cache entry.
|
|
42
43
|
*/
|
|
43
44
|
scope?: Readonly<Record<string, unknown>>;
|
|
44
45
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,19 +2,20 @@ export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabas
|
|
|
2
2
|
export { defineResource } from './chunk-7FVTGKTX.js';
|
|
3
3
|
export { decodeRecordKey, encodeRecordKey, keyFields } from './chunk-KV2HW4G4.js';
|
|
4
4
|
import './chunk-XCX2TRBL.js';
|
|
5
|
-
export { ViewerScope, clearViewerCache, useOptionalViewerScope, useViewer, useViewerScope } from './chunk-
|
|
5
|
+
export { ViewerScope, clearViewerCache, scopeClock, useOptionalViewerScope, useViewer, useViewerScope } from './chunk-3FFBW4XC.js';
|
|
6
|
+
export { WRITE_FAILED, useWrite } from './chunk-52T2EYXH.js';
|
|
6
7
|
export { NO_VIEWER } from './chunk-OZYF55E3.js';
|
|
7
|
-
export { useInfiniteResource } from './chunk-
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
8
|
+
export { useInfiniteResource } from './chunk-2VVZ2KX3.js';
|
|
9
|
+
export { loadRelationLabel, useRelationLabel } from './chunk-XMC4EJUE.js';
|
|
10
|
+
export { buildArrayItemDefaults, useResourceForm } from './chunk-QPD4FKPC.js';
|
|
11
|
+
export { useOne } from './chunk-GWQHP3RC.js';
|
|
12
|
+
export { useResource } from './chunk-CC37H7O2.js';
|
|
11
13
|
export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS } from './chunk-K4ZNAF3G.js';
|
|
12
14
|
export { DEFAULT_UNSAVED_CHANGES_MESSAGE, useUnsavedChangesGuard } from './chunk-XQO4OH2N.js';
|
|
13
15
|
export { useWizard } from './chunk-7KOLYF27.js';
|
|
14
|
-
export { WRITE_FAILED, useWrite } from './chunk-52T2EYXH.js';
|
|
15
16
|
import './chunk-AUVKRXRC.js';
|
|
16
|
-
export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from './chunk-
|
|
17
|
-
export { defineQueryKeys, resourceKeys } from './chunk-
|
|
17
|
+
export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from './chunk-OSFG3GFY.js';
|
|
18
|
+
export { defineQueryKeys, resourceKeys } from './chunk-7PUFVNPB.js';
|
|
18
19
|
import './chunk-7NUL32W7.js';
|
|
19
20
|
export { useCapabilities } from './chunk-LGTXQTHA.js';
|
|
20
21
|
export { DataProviderRoot, GenesisProvider, createMockProvider, useDataProvider, useStorage } from './chunk-VDEW4AOS.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { D as DataRow, e as ResourceContract, F as FieldSchema, i as RowAction, j as RowOf } from '../types-o8j7g6O6.js';
|
|
2
2
|
import { C as ChipTone, R as Readiness } from '../status-BXRokZD9.js';
|
|
3
|
-
import { V as Viewer, R as ResourceScope } from '../viewer-scope-
|
|
4
|
-
export { G as GenesisViewerRoles, N as NO_VIEWER } from '../viewer-scope-
|
|
3
|
+
import { V as Viewer, R as ResourceScope } from '../viewer-scope-bthEYSOB.js';
|
|
4
|
+
export { G as GenesisViewerRoles, N as NO_VIEWER } from '../viewer-scope-bthEYSOB.js';
|
|
5
5
|
import { a as Identifier } from '../types-CXhqXPN1.js';
|
|
6
6
|
import '../form-types.js';
|
|
7
7
|
import 'react';
|
|
@@ -29,6 +29,16 @@ interface ViewField<Row extends DataRow = DataRow> {
|
|
|
29
29
|
* A value without one shows in title case. Keys must be the field's enum values, if it has any.
|
|
30
30
|
*/
|
|
31
31
|
labels?: Readonly<Record<string, string>>;
|
|
32
|
+
/**
|
|
33
|
+
* For a link (`relation`): the linked row's field that names it, e.g. `"full_name"`. Default:
|
|
34
|
+
* the linked resource's `labelField` (`provider.describe`), else a `name`/`title`-like field.
|
|
35
|
+
*/
|
|
36
|
+
labelField?: string;
|
|
37
|
+
/**
|
|
38
|
+
* For a link: the words when the linked row is hidden from this viewer or gone, e.g.
|
|
39
|
+
* `"Someone you can't see"`. Default: the catalogue's `common.hiddenLink`. Never the raw id.
|
|
40
|
+
*/
|
|
41
|
+
missingLabel?: string;
|
|
32
42
|
/** Longest text a form accepts. Feeds the derived validation. */
|
|
33
43
|
max?: number;
|
|
34
44
|
/** Shown read-only even where the server would accept a write. Never widens. */
|
|
@@ -42,9 +52,21 @@ interface ViewField<Row extends DataRow = DataRow> {
|
|
|
42
52
|
when?: (row: Row, viewer: Viewer) => boolean;
|
|
43
53
|
/** In a form: show the field only while this holds for the form's values. A hidden field isn't saved. */
|
|
44
54
|
visible?: (values: Readonly<Record<string, unknown>>) => boolean;
|
|
45
|
-
/**
|
|
46
|
-
|
|
55
|
+
/**
|
|
56
|
+
* A timestamp's clock: the viewer's (default), the scope's (the zone of whatever the screen is
|
|
57
|
+
* scoped to: ViewerScope's `scopeTimeZone`, or NativeResourceView's prop), or a fixed IANA zone.
|
|
58
|
+
* Closed: any other word (the removed `"practice"`) is a type error, and `defineView` refuses a
|
|
59
|
+
* zone the runtime doesn't know.
|
|
60
|
+
*/
|
|
61
|
+
timeZone?: ViewTimeZone;
|
|
47
62
|
}
|
|
63
|
+
/**
|
|
64
|
+
* An IANA zone name as written: `"UTC"`, `"GMT"` or `Area/Location` (`"Europe/Berlin"`). The
|
|
65
|
+
* type keeps a bare word out; `defineView` checks the runtime knows the zone.
|
|
66
|
+
*/
|
|
67
|
+
type TimeZoneName = "UTC" | "GMT" | `${string}/${string}`;
|
|
68
|
+
/** A view field's clock: the viewer's, the scope's, or a fixed zone. */
|
|
69
|
+
type ViewTimeZone = "viewer" | "scope" | TimeZoneName;
|
|
48
70
|
/** A column computed from the row, never stored or sent. */
|
|
49
71
|
interface ComputedColumn<Row extends DataRow = DataRow> {
|
|
50
72
|
/** The column's key; must not clash with a field name. */
|
|
@@ -172,7 +194,7 @@ interface ViewDefinition<C extends ResourceContract, Row extends DataRow = RowOf
|
|
|
172
194
|
/** Named operations on one row, in the order a menu shows them. Names are unique. */
|
|
173
195
|
actions?: readonly ViewAction<Row>[];
|
|
174
196
|
summary?: (row: Row) => RowSummary;
|
|
175
|
-
/** The scope keys this view needs above it (`["
|
|
197
|
+
/** The scope keys this view needs above it (`["org_id"]`). They stay out of forms. */
|
|
176
198
|
scope?: readonly FieldNameOf<C>[];
|
|
177
199
|
/** Group rows under headers by this field. */
|
|
178
200
|
groupBy?: FieldNameOf<C>;
|
|
@@ -196,6 +218,10 @@ interface ResolvedColumn<Row extends DataRow = DataRow> {
|
|
|
196
218
|
tones?: Readonly<Record<string, ViewTone>>;
|
|
197
219
|
/** The words for a value (`ViewField.labels`); `valueText` reads them. */
|
|
198
220
|
labels?: Readonly<Record<string, string>>;
|
|
221
|
+
/** For a link: the linked row's field that names it (`ViewField.labelField`). */
|
|
222
|
+
labelField?: string;
|
|
223
|
+
/** For a link: the words when its row is hidden or gone (`ViewField.missingLabel`). */
|
|
224
|
+
missingLabel?: string;
|
|
199
225
|
/** Whether to show the cell. Without a viewer it answers for no one (fail closed). */
|
|
200
226
|
when?: (row: Row, viewer?: Viewer) => boolean;
|
|
201
227
|
timeZone?: ViewField["timeZone"];
|
|
@@ -208,6 +234,10 @@ interface ResolvedFormField {
|
|
|
208
234
|
required: boolean;
|
|
209
235
|
readOnly: boolean;
|
|
210
236
|
max?: number;
|
|
237
|
+
/** For a link: the linked row's field that names it (`ViewField.labelField`). */
|
|
238
|
+
labelField?: string;
|
|
239
|
+
/** For a link: the words when its row is hidden or gone (`ViewField.missingLabel`). */
|
|
240
|
+
missingLabel?: string;
|
|
211
241
|
/** An enum field's choices, in the contract's order, with the view's words. */
|
|
212
242
|
options?: readonly {
|
|
213
243
|
value: string;
|
|
@@ -307,7 +337,7 @@ declare function rowPicture(summary: RowSummary): RowPicture | null;
|
|
|
307
337
|
type ScopeValue = string | number | boolean | null;
|
|
308
338
|
/**
|
|
309
339
|
* The view's declared scope keys with their values from the viewer's scope, ready to pass as a
|
|
310
|
-
* screen's `filter`: `scope: ["
|
|
340
|
+
* screen's `filter`: `scope: ["league_id"]` reads `scope.league_id`, then `scope.leagueId`.
|
|
311
341
|
*
|
|
312
342
|
* ```tsx
|
|
313
343
|
* <ResourceView view={brandsView} filter={scopeValues(brandsView, useViewerScope().scope)} />
|
|
@@ -319,6 +349,97 @@ type ScopeValue = string | number | boolean | null;
|
|
|
319
349
|
*/
|
|
320
350
|
declare function scopeValues(view: Pick<ResourceView<any, any>, "resource" | "definition">, scope: ResourceScope | null | undefined): Readonly<Record<string, ScopeValue>>;
|
|
321
351
|
|
|
352
|
+
/**
|
|
353
|
+
* A screen's `tree` (`<ResourceView tree={{ getParentId }} />`): rows nest under the row
|
|
354
|
+
* `getParentId` names. Client-side data only: every row is loaded, and children are never
|
|
355
|
+
* fetched on expand.
|
|
356
|
+
*/
|
|
357
|
+
interface ResourceTree<T> {
|
|
358
|
+
/** The parent row's key (the same text as the row key), or `null` / `undefined` / `""` for a root. */
|
|
359
|
+
getParentId: (row: T) => string | null | undefined;
|
|
360
|
+
/**
|
|
361
|
+
* Which rows start open (uncontrolled): `true` every parent, a number the parents shallower
|
|
362
|
+
* than that depth (`1` opens the roots), `false` none. Default `false`.
|
|
363
|
+
*/
|
|
364
|
+
defaultExpanded?: boolean | number;
|
|
365
|
+
/** The open rows by key, controlled. Leave unset and the screen keeps its own. */
|
|
366
|
+
expanded?: ReadonlySet<string>;
|
|
367
|
+
/** Called with the next open set whenever a row opens or closes. */
|
|
368
|
+
onExpandedChange?: (expanded: Set<string>) => void;
|
|
369
|
+
/** Selecting a row selects its descendants too, and clearing it clears them. Default `false`. */
|
|
370
|
+
cascadeSelect?: boolean;
|
|
371
|
+
}
|
|
372
|
+
/** How to read the tree out of flat rows. */
|
|
373
|
+
interface TreeOptions<T> {
|
|
374
|
+
/** A row's own id. */
|
|
375
|
+
getId: (row: T) => string;
|
|
376
|
+
/** The parent's id; `null`, `undefined` or `""` for a root. A parent that isn't loaded makes a root too. */
|
|
377
|
+
getParentId: (row: T) => string | null | undefined;
|
|
378
|
+
/**
|
|
379
|
+
* Which nodes are open: their ids, or `"all"`. A closed node's descendants aren't returned.
|
|
380
|
+
* While `match` is set, every ancestor of a match is open regardless, so each match shows.
|
|
381
|
+
*/
|
|
382
|
+
expanded: ReadonlySet<string> | "all";
|
|
383
|
+
/**
|
|
384
|
+
* The filter, when one is active: rows that match it, and their ancestors (so a match keeps its
|
|
385
|
+
* context), are kept; everything else is left out. Undefined: no filter, every row is kept.
|
|
386
|
+
*/
|
|
387
|
+
match?: (row: T) => boolean;
|
|
388
|
+
/**
|
|
389
|
+
* The sort, applied within each set of siblings (stable: ties keep the rows' order). Without it,
|
|
390
|
+
* siblings keep the rows' order, so a list sorted beforehand is sorted within siblings too.
|
|
391
|
+
*/
|
|
392
|
+
compare?: (a: T, b: T) => number;
|
|
393
|
+
}
|
|
394
|
+
/** One visible row of the tree, in display order. */
|
|
395
|
+
interface TreeNode<T> {
|
|
396
|
+
row: T;
|
|
397
|
+
id: string;
|
|
398
|
+
/** The parent's id as drawn: `null` for a root (a missing parent, or a broken cycle, counts as none). */
|
|
399
|
+
parentId: string | null;
|
|
400
|
+
/** 0 for a root. */
|
|
401
|
+
depth: number;
|
|
402
|
+
/** Whether it has children among the kept rows (so a toggle makes sense). */
|
|
403
|
+
hasChildren: boolean;
|
|
404
|
+
/** Whether it is open. Always false without children. */
|
|
405
|
+
expanded: boolean;
|
|
406
|
+
/** False for an ancestor kept only as a match's context; true otherwise, and always true without a filter. */
|
|
407
|
+
matched: boolean;
|
|
408
|
+
/** 1-based position among its kept siblings, and how many there are (`aria-posinset`, `aria-setsize`). */
|
|
409
|
+
position: number;
|
|
410
|
+
siblings: number;
|
|
411
|
+
}
|
|
412
|
+
/** What {@link treeRows} returns. */
|
|
413
|
+
interface TreeResult<T> {
|
|
414
|
+
/** The rows to draw, in order: each parent before its children, siblings in input order. */
|
|
415
|
+
visible: TreeNode<T>[];
|
|
416
|
+
/** Every kept row's node by id, collapsed ones included. */
|
|
417
|
+
nodes: ReadonlyMap<string, TreeNode<T>>;
|
|
418
|
+
/** Every descendant of a node among the kept rows, depth-first, collapsed or not. */
|
|
419
|
+
descendants: (id: string) => string[];
|
|
420
|
+
/** The ids of every kept node that has children: "expand all". */
|
|
421
|
+
parents: () => string[];
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Build the tree from flat rows. Siblings are sorted by `compare`, else keep the rows' order, so
|
|
425
|
+
* either way the sort applies within each set of siblings. A row whose parent isn't among `rows` is a root,
|
|
426
|
+
* and so is a row whose parent would close a cycle (each cycle loses one link). Duplicate ids keep
|
|
427
|
+
* the first row.
|
|
428
|
+
*/
|
|
429
|
+
declare function treeRows<T>(rows: readonly T[], options: TreeOptions<T>): TreeResult<T>;
|
|
430
|
+
/**
|
|
431
|
+
* The open ids a tree starts with: `true` opens every parent, a number opens parents shallower
|
|
432
|
+
* than that depth (`1` opens the roots), `false` or nothing opens none.
|
|
433
|
+
*/
|
|
434
|
+
declare function initialExpanded<T>(rows: readonly T[], options: Omit<TreeOptions<T>, "expanded" | "match">, open: boolean | number | undefined): Set<string>;
|
|
435
|
+
/** The open set with `id` opened or closed: a new set, or the same one when nothing changes. */
|
|
436
|
+
declare function setExpanded(expanded: ReadonlySet<string>, id: string, open: boolean): ReadonlySet<string>;
|
|
437
|
+
/**
|
|
438
|
+
* The selection after toggling `id` with cascade: the node and every descendant take the node's
|
|
439
|
+
* new state. Without cascade, use a plain toggle; selection never cascades by default.
|
|
440
|
+
*/
|
|
441
|
+
declare function cascadeSelection(selected: ReadonlySet<string>, id: string, descendants: readonly string[]): Set<string>;
|
|
442
|
+
|
|
322
443
|
type AnyView = ResourceView<ResourceContract<any>, any>;
|
|
323
444
|
/** Equality filters for a child list, sent to the server: `{ brand_id: brand.id }`. `null` is "is empty". */
|
|
324
445
|
type WorkspaceFilter = Readonly<Record<string, string | number | boolean | null>>;
|
|
@@ -481,4 +602,4 @@ declare function isWorkspace(value: unknown): value is ResourceWorkspace;
|
|
|
481
602
|
*/
|
|
482
603
|
declare function defineWorkspace<C extends ResourceContract, Row extends DataRow = RowOf<C>>(view: ResourceView<C, Row>, definition: WorkspaceDefinition<C, Row>): ResourceWorkspace<C, Row>;
|
|
483
604
|
|
|
484
|
-
export { type Allowed, type ComputedColumn, type DisplayHint, type FieldNameOf, type ResolvedColumn, type ResolvedFormField, type ResolvedReadinessItem, type ResolvedViewAction, type ResolvedWorkspaceSection, type ResourceView, type ResourceWorkspace, type RowImage, RowOf, type RowPicture, type RowSummary, type ViewAction, type ViewColumn, type ViewCopy, type ViewDefinition, ViewDefinitionError, type ViewField, type ViewFormItem, type ViewGuards, type ViewPreset, type ViewTone, Viewer, type WorkspaceDefinition, type WorkspaceFilter, type WorkspaceHeader, type WorkspaceHeaderAction, type WorkspaceHeaderOptions, type WorkspaceListSection, type WorkspaceReadinessItem, type WorkspaceSection, type WorkspaceSettingsSection, type WorkspaceSlotSection, defineView, defineWorkspace, deriveDisplay, initialsOf, isWorkspace, rowPicture, scopeValues, valueText };
|
|
605
|
+
export { type Allowed, type ComputedColumn, type DisplayHint, type FieldNameOf, type ResolvedColumn, type ResolvedFormField, type ResolvedReadinessItem, type ResolvedViewAction, type ResolvedWorkspaceSection, type ResourceTree, type ResourceView, type ResourceWorkspace, type RowImage, RowOf, type RowPicture, type RowSummary, type TimeZoneName, type TreeNode, type TreeOptions, type TreeResult, type ViewAction, type ViewColumn, type ViewCopy, type ViewDefinition, ViewDefinitionError, type ViewField, type ViewFormItem, type ViewGuards, type ViewPreset, type ViewTimeZone, type ViewTone, Viewer, type WorkspaceDefinition, type WorkspaceFilter, type WorkspaceHeader, type WorkspaceHeaderAction, type WorkspaceHeaderOptions, type WorkspaceListSection, type WorkspaceReadinessItem, type WorkspaceSection, type WorkspaceSettingsSection, type WorkspaceSlotSection, cascadeSelection, defineView, defineWorkspace, deriveDisplay, initialExpanded, initialsOf, isWorkspace, rowPicture, scopeValues, setExpanded, treeRows, valueText };
|