@marktiderman/genesis-core 1.17.0 → 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-M4SPLFLL.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/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +7 -7
- 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-resource-form.js +4 -4
- package/dist/hooks/use-resource.js +3 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.js +7 -7
- package/dist/resource-view/index.d.ts +110 -7
- package/dist/resource-view/index.js +131 -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-M4SPLFLL.js.map +0 -1
- package/dist/chunk-OYIUIW7C.js.map +0 -1
package/dist/hooks/index.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
export { ViewerScope, clearViewerCache, useOptionalViewerScope, useViewer, useViewerScope } from '../chunk-
|
|
1
|
+
export { ViewerScope, clearViewerCache, scopeClock, useOptionalViewerScope, useViewer, useViewerScope } from '../chunk-3FFBW4XC.js';
|
|
2
2
|
export { WRITE_FAILED, useWrite } from '../chunk-52T2EYXH.js';
|
|
3
3
|
export { NO_VIEWER } from '../chunk-OZYF55E3.js';
|
|
4
|
-
export { useInfiniteResource } from '../chunk-
|
|
4
|
+
export { useInfiniteResource } from '../chunk-2VVZ2KX3.js';
|
|
5
5
|
export { loadRelationLabel, useRelationLabel } from '../chunk-XMC4EJUE.js';
|
|
6
|
-
export { buildArrayItemDefaults, useResourceForm } from '../chunk-
|
|
7
|
-
export { useOne } from '../chunk-
|
|
8
|
-
export { useResource } from '../chunk-
|
|
6
|
+
export { buildArrayItemDefaults, useResourceForm } from '../chunk-QPD4FKPC.js';
|
|
7
|
+
export { useOne } from '../chunk-GWQHP3RC.js';
|
|
8
|
+
export { useResource } from '../chunk-CC37H7O2.js';
|
|
9
9
|
export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS } from '../chunk-K4ZNAF3G.js';
|
|
10
10
|
export { DEFAULT_UNSAVED_CHANGES_MESSAGE, useUnsavedChangesGuard } from '../chunk-XQO4OH2N.js';
|
|
11
11
|
export { useWizard } from '../chunk-7KOLYF27.js';
|
|
12
12
|
import '../chunk-AUVKRXRC.js';
|
|
13
|
-
export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from '../chunk-
|
|
14
|
-
import '../chunk-
|
|
13
|
+
export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from '../chunk-OSFG3GFY.js';
|
|
14
|
+
import '../chunk-7PUFVNPB.js';
|
|
15
15
|
import '../chunk-7NUL32W7.js';
|
|
16
16
|
export { useCapabilities } from '../chunk-LGTXQTHA.js';
|
|
17
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
|
|
@@ -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
|
@@ -13,7 +13,7 @@ export { useCapabilities } from './hooks/use-capabilities.js';
|
|
|
13
13
|
export { UseWriteOptions, UseWriteReturn, WRITE_FAILED, useWrite } from './hooks/use-write.js';
|
|
14
14
|
export { UseDraftReturn, useDraft } from './hooks/use-draft.js';
|
|
15
15
|
export { DEFAULT_DRAFT_DELAY_MS, DRAFT_NOT_SAVED, DraftAdoption, DraftController, DraftOptions, DraftSeed, DraftState, DraftStatus, DraftValue, isNetworkFailure, stableJson } from './hooks/draft-controller.js';
|
|
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, 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';
|
|
17
17
|
export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS, LiveOptions } from './hooks/use-live.js';
|
|
18
18
|
export { UseResourceFormOptions, UseResourceFormReturn, buildArrayItemDefaults, useResourceForm } from './hooks/use-resource-form.js';
|
|
19
19
|
export { UseWizardReturn, WizardStep, useWizard } from './hooks/use-wizard.js';
|
|
@@ -33,13 +33,13 @@ import 'react-hook-form';
|
|
|
33
33
|
/** Who and when a key is for. `viewer` is required; null means signed out. */
|
|
34
34
|
interface KeyScope {
|
|
35
35
|
viewer: string | null;
|
|
36
|
-
/** The group,
|
|
36
|
+
/** The group, organization or space the screen is filtered to. */
|
|
37
37
|
group?: string | null;
|
|
38
38
|
/** The person-day (YYYY-MM-DD) a "today" read is for. */
|
|
39
39
|
day?: string | null;
|
|
40
40
|
/**
|
|
41
|
-
* Where the viewer is working (ViewerScope's `scope`:
|
|
42
|
-
* 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.
|
|
43
43
|
*/
|
|
44
44
|
scope?: Readonly<Record<string, unknown>>;
|
|
45
45
|
}
|
package/dist/index.js
CHANGED
|
@@ -2,20 +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
6
|
export { WRITE_FAILED, useWrite } from './chunk-52T2EYXH.js';
|
|
7
7
|
export { NO_VIEWER } from './chunk-OZYF55E3.js';
|
|
8
|
-
export { useInfiniteResource } from './chunk-
|
|
8
|
+
export { useInfiniteResource } from './chunk-2VVZ2KX3.js';
|
|
9
9
|
export { loadRelationLabel, useRelationLabel } from './chunk-XMC4EJUE.js';
|
|
10
|
-
export { buildArrayItemDefaults, useResourceForm } from './chunk-
|
|
11
|
-
export { useOne } from './chunk-
|
|
12
|
-
export { useResource } from './chunk-
|
|
10
|
+
export { buildArrayItemDefaults, useResourceForm } from './chunk-QPD4FKPC.js';
|
|
11
|
+
export { useOne } from './chunk-GWQHP3RC.js';
|
|
12
|
+
export { useResource } from './chunk-CC37H7O2.js';
|
|
13
13
|
export { DEFAULT_LIVE_DEBOUNCE_MS, DEFAULT_LIVE_RESYNC_MS } from './chunk-K4ZNAF3G.js';
|
|
14
14
|
export { DEFAULT_UNSAVED_CHANGES_MESSAGE, useUnsavedChangesGuard } from './chunk-XQO4OH2N.js';
|
|
15
15
|
export { useWizard } from './chunk-7KOLYF27.js';
|
|
16
16
|
import './chunk-AUVKRXRC.js';
|
|
17
|
-
export { DEFAULT_UNDO_DELAY_MS, dropPendingWrites, flushPendingWrites, pendingWriteCount } from './chunk-
|
|
18
|
-
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';
|
|
19
19
|
import './chunk-7NUL32W7.js';
|
|
20
20
|
export { useCapabilities } from './chunk-LGTXQTHA.js';
|
|
21
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';
|
|
@@ -52,9 +52,21 @@ interface ViewField<Row extends DataRow = DataRow> {
|
|
|
52
52
|
when?: (row: Row, viewer: Viewer) => boolean;
|
|
53
53
|
/** In a form: show the field only while this holds for the form's values. A hidden field isn't saved. */
|
|
54
54
|
visible?: (values: Readonly<Record<string, unknown>>) => boolean;
|
|
55
|
-
/**
|
|
56
|
-
|
|
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;
|
|
57
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;
|
|
58
70
|
/** A column computed from the row, never stored or sent. */
|
|
59
71
|
interface ComputedColumn<Row extends DataRow = DataRow> {
|
|
60
72
|
/** The column's key; must not clash with a field name. */
|
|
@@ -182,7 +194,7 @@ interface ViewDefinition<C extends ResourceContract, Row extends DataRow = RowOf
|
|
|
182
194
|
/** Named operations on one row, in the order a menu shows them. Names are unique. */
|
|
183
195
|
actions?: readonly ViewAction<Row>[];
|
|
184
196
|
summary?: (row: Row) => RowSummary;
|
|
185
|
-
/** The scope keys this view needs above it (`["
|
|
197
|
+
/** The scope keys this view needs above it (`["org_id"]`). They stay out of forms. */
|
|
186
198
|
scope?: readonly FieldNameOf<C>[];
|
|
187
199
|
/** Group rows under headers by this field. */
|
|
188
200
|
groupBy?: FieldNameOf<C>;
|
|
@@ -325,7 +337,7 @@ declare function rowPicture(summary: RowSummary): RowPicture | null;
|
|
|
325
337
|
type ScopeValue = string | number | boolean | null;
|
|
326
338
|
/**
|
|
327
339
|
* The view's declared scope keys with their values from the viewer's scope, ready to pass as a
|
|
328
|
-
* screen's `filter`: `scope: ["
|
|
340
|
+
* screen's `filter`: `scope: ["league_id"]` reads `scope.league_id`, then `scope.leagueId`.
|
|
329
341
|
*
|
|
330
342
|
* ```tsx
|
|
331
343
|
* <ResourceView view={brandsView} filter={scopeValues(brandsView, useViewerScope().scope)} />
|
|
@@ -337,6 +349,97 @@ type ScopeValue = string | number | boolean | null;
|
|
|
337
349
|
*/
|
|
338
350
|
declare function scopeValues(view: Pick<ResourceView<any, any>, "resource" | "definition">, scope: ResourceScope | null | undefined): Readonly<Record<string, ScopeValue>>;
|
|
339
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
|
+
|
|
340
443
|
type AnyView = ResourceView<ResourceContract<any>, any>;
|
|
341
444
|
/** Equality filters for a child list, sent to the server: `{ brand_id: brand.id }`. `null` is "is empty". */
|
|
342
445
|
type WorkspaceFilter = Readonly<Record<string, string | number | boolean | null>>;
|
|
@@ -499,4 +602,4 @@ declare function isWorkspace(value: unknown): value is ResourceWorkspace;
|
|
|
499
602
|
*/
|
|
500
603
|
declare function defineWorkspace<C extends ResourceContract, Row extends DataRow = RowOf<C>>(view: ResourceView<C, Row>, definition: WorkspaceDefinition<C, Row>): ResourceWorkspace<C, Row>;
|
|
501
604
|
|
|
502
|
-
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 };
|
|
@@ -2,6 +2,7 @@ import { readinessOf } from '../chunk-PP3XFFQM.js';
|
|
|
2
2
|
import { keyFields, encodeRecordKey } from '../chunk-KV2HW4G4.js';
|
|
3
3
|
import { NO_VIEWER } from '../chunk-OZYF55E3.js';
|
|
4
4
|
export { NO_VIEWER } from '../chunk-OZYF55E3.js';
|
|
5
|
+
import { isTimeZone } from '../chunk-3B4IFDMK.js';
|
|
5
6
|
import { titleCase } from '../chunk-RYEXWQFD.js';
|
|
6
7
|
import { isSafeUrl } from '../chunk-YDDPFSQ6.js';
|
|
7
8
|
|
|
@@ -125,6 +126,17 @@ function defineView(contract, definition = {}) {
|
|
|
125
126
|
if (values?.length && !values.includes(value)) problems.push(`fields.${name}.labels names "${value}", which isn't one of its values`);
|
|
126
127
|
}
|
|
127
128
|
}
|
|
129
|
+
for (const [name, v] of Object.entries(viewFields)) {
|
|
130
|
+
const zone = v?.timeZone;
|
|
131
|
+
if (zone === void 0 || zone === "viewer" || zone === "scope") continue;
|
|
132
|
+
if (zone === "practice") {
|
|
133
|
+
problems.push(
|
|
134
|
+
`fields.${name}.timeZone "practice" was renamed "scope" in genesis-core 2; run \`genesis codemod genesis-core-2-scope-names\``
|
|
135
|
+
);
|
|
136
|
+
} else if (!isTimeZone(zone)) {
|
|
137
|
+
problems.push(`fields.${name}.timeZone "${String(zone)}" isn't "viewer", "scope" or a time zone this runtime knows`);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
128
140
|
for (const [name, v] of Object.entries(viewFields)) {
|
|
129
141
|
if (v?.missingLabel === void 0) continue;
|
|
130
142
|
if (typeof v.missingLabel !== "string" || !v.missingLabel.trim()) problems.push(`fields.${name}.missingLabel isn't text`);
|
|
@@ -379,6 +391,124 @@ function scopeValues(view, scope) {
|
|
|
379
391
|
return Object.freeze(out);
|
|
380
392
|
}
|
|
381
393
|
|
|
394
|
+
// src/resource-view/tree.ts
|
|
395
|
+
var rootish = (parent) => parent == null || parent === "";
|
|
396
|
+
function treeRows(rows, options) {
|
|
397
|
+
const { getId, getParentId, expanded, match, compare } = options;
|
|
398
|
+
const byId = /* @__PURE__ */ new Map();
|
|
399
|
+
const order = [];
|
|
400
|
+
for (const row of rows) {
|
|
401
|
+
const id = getId(row);
|
|
402
|
+
if (byId.has(id)) continue;
|
|
403
|
+
byId.set(id, row);
|
|
404
|
+
order.push(id);
|
|
405
|
+
}
|
|
406
|
+
const parentOf = /* @__PURE__ */ new Map();
|
|
407
|
+
const resolving = /* @__PURE__ */ new Set();
|
|
408
|
+
const resolve = (id) => {
|
|
409
|
+
if (parentOf.has(id)) return parentOf.get(id);
|
|
410
|
+
const raw = getParentId(byId.get(id));
|
|
411
|
+
let parent = rootish(raw) || raw === id || !byId.has(raw) ? null : raw;
|
|
412
|
+
if (parent !== null) {
|
|
413
|
+
resolving.add(id);
|
|
414
|
+
if (resolving.has(parent)) parent = null;
|
|
415
|
+
else resolve(parent);
|
|
416
|
+
resolving.delete(id);
|
|
417
|
+
}
|
|
418
|
+
parentOf.set(id, parent);
|
|
419
|
+
return parent;
|
|
420
|
+
};
|
|
421
|
+
for (const id of order) resolve(id);
|
|
422
|
+
for (const id of order) {
|
|
423
|
+
const seen = /* @__PURE__ */ new Set([id]);
|
|
424
|
+
let at = parentOf.get(id) ?? null;
|
|
425
|
+
while (at !== null && !seen.has(at)) {
|
|
426
|
+
seen.add(at);
|
|
427
|
+
at = parentOf.get(at) ?? null;
|
|
428
|
+
}
|
|
429
|
+
if (at !== null) parentOf.set(id, null);
|
|
430
|
+
}
|
|
431
|
+
let kept = null;
|
|
432
|
+
const matched = /* @__PURE__ */ new Set();
|
|
433
|
+
if (match) {
|
|
434
|
+
kept = /* @__PURE__ */ new Set();
|
|
435
|
+
for (const id of order) {
|
|
436
|
+
if (!match(byId.get(id))) continue;
|
|
437
|
+
matched.add(id);
|
|
438
|
+
for (let at = id; at !== null && !kept.has(at); at = parentOf.get(at) ?? null) kept.add(at);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const children = /* @__PURE__ */ new Map();
|
|
442
|
+
for (const id of order) {
|
|
443
|
+
if (kept && !kept.has(id)) continue;
|
|
444
|
+
const parent = parentOf.get(id) ?? null;
|
|
445
|
+
const list = children.get(parent);
|
|
446
|
+
if (list) list.push(id);
|
|
447
|
+
else children.set(parent, [id]);
|
|
448
|
+
}
|
|
449
|
+
if (compare) for (const list of children.values()) list.sort((a, b) => compare(byId.get(a), byId.get(b)));
|
|
450
|
+
const isOpen = (id) => match ? true : expanded === "all" || expanded.has(id);
|
|
451
|
+
const nodes = /* @__PURE__ */ new Map();
|
|
452
|
+
const visible = [];
|
|
453
|
+
const visit = (parent, depth, shown) => {
|
|
454
|
+
const ids = children.get(parent) ?? [];
|
|
455
|
+
ids.forEach((id, index) => {
|
|
456
|
+
const hasChildren = (children.get(id)?.length ?? 0) > 0;
|
|
457
|
+
const open = hasChildren && isOpen(id);
|
|
458
|
+
const node = {
|
|
459
|
+
row: byId.get(id),
|
|
460
|
+
id,
|
|
461
|
+
parentId: parent,
|
|
462
|
+
depth,
|
|
463
|
+
hasChildren,
|
|
464
|
+
expanded: open,
|
|
465
|
+
matched: match ? matched.has(id) : true,
|
|
466
|
+
position: index + 1,
|
|
467
|
+
siblings: ids.length
|
|
468
|
+
};
|
|
469
|
+
nodes.set(id, node);
|
|
470
|
+
if (shown) visible.push(node);
|
|
471
|
+
visit(id, depth + 1, shown && open);
|
|
472
|
+
});
|
|
473
|
+
};
|
|
474
|
+
visit(null, 0, true);
|
|
475
|
+
const descendants = (id) => {
|
|
476
|
+
const out = [];
|
|
477
|
+
const walk = (at) => {
|
|
478
|
+
for (const child of children.get(at) ?? []) {
|
|
479
|
+
out.push(child);
|
|
480
|
+
walk(child);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
walk(id);
|
|
484
|
+
return out;
|
|
485
|
+
};
|
|
486
|
+
const parents = () => [...nodes.values()].filter((n) => n.hasChildren).map((n) => n.id);
|
|
487
|
+
return { visible, nodes, descendants, parents };
|
|
488
|
+
}
|
|
489
|
+
function initialExpanded(rows, options, open) {
|
|
490
|
+
if (!open) return /* @__PURE__ */ new Set();
|
|
491
|
+
const tree = treeRows(rows, { ...options, expanded: "all" });
|
|
492
|
+
const depth = open === true ? Infinity : open;
|
|
493
|
+
return new Set(tree.parents().filter((id) => tree.nodes.get(id).depth < depth));
|
|
494
|
+
}
|
|
495
|
+
function setExpanded(expanded, id, open) {
|
|
496
|
+
if (expanded.has(id) === open) return expanded;
|
|
497
|
+
const next = new Set(expanded);
|
|
498
|
+
if (open) next.add(id);
|
|
499
|
+
else next.delete(id);
|
|
500
|
+
return next;
|
|
501
|
+
}
|
|
502
|
+
function cascadeSelection(selected, id, descendants) {
|
|
503
|
+
const next = new Set(selected);
|
|
504
|
+
const on = !selected.has(id);
|
|
505
|
+
for (const at of [id, ...descendants]) {
|
|
506
|
+
if (on) next.add(at);
|
|
507
|
+
else next.delete(at);
|
|
508
|
+
}
|
|
509
|
+
return next;
|
|
510
|
+
}
|
|
511
|
+
|
|
382
512
|
// src/resource-view/workspace.ts
|
|
383
513
|
var WORKSPACE = /* @__PURE__ */ Symbol.for("genesis.resource-workspace");
|
|
384
514
|
var REFUSED = "This isn't allowed.";
|
|
@@ -582,6 +712,6 @@ function defineWorkspace(view, definition) {
|
|
|
582
712
|
});
|
|
583
713
|
}
|
|
584
714
|
|
|
585
|
-
export { ViewDefinitionError, defineView, defineWorkspace, deriveDisplay, initialsOf, isWorkspace, rowPicture, scopeValues, valueText };
|
|
715
|
+
export { ViewDefinitionError, cascadeSelection, defineView, defineWorkspace, deriveDisplay, initialExpanded, initialsOf, isWorkspace, rowPicture, scopeValues, setExpanded, treeRows, valueText };
|
|
586
716
|
//# sourceMappingURL=index.js.map
|
|
587
717
|
//# sourceMappingURL=index.js.map
|