@marktiderman/genesis-core 2.10.0 → 2.12.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 +191 -1
- package/dist/{chunk-LGTXQTHA.js → chunk-2VJQVAJD.js} +3 -3
- package/dist/{chunk-LGTXQTHA.js.map → chunk-2VJQVAJD.js.map} +1 -1
- package/dist/chunk-2WS4LGYU.js +47 -0
- package/dist/chunk-2WS4LGYU.js.map +1 -0
- package/dist/{chunk-KXVDDDJY.js → chunk-3B5O36DU.js} +105 -13
- package/dist/chunk-3B5O36DU.js.map +1 -0
- package/dist/{chunk-EHFYSJJA.js → chunk-42QPCDQF.js} +3 -3
- package/dist/{chunk-EHFYSJJA.js.map → chunk-42QPCDQF.js.map} +1 -1
- package/dist/{chunk-RK365SO2.js → chunk-C62CMLWG.js} +8 -5
- package/dist/chunk-C62CMLWG.js.map +1 -0
- package/dist/chunk-HYYTAJBG.js +85 -0
- package/dist/chunk-HYYTAJBG.js.map +1 -0
- package/dist/{chunk-4ZR7472O.js → chunk-LOJGHR5O.js} +4 -4
- package/dist/{chunk-4ZR7472O.js.map → chunk-LOJGHR5O.js.map} +1 -1
- package/dist/{chunk-ON2V4RXX.js → chunk-OC4OGB2K.js} +19 -11
- package/dist/chunk-OC4OGB2K.js.map +1 -0
- package/dist/{chunk-HQAVDVIH.js → chunk-POMTRNAL.js} +4 -4
- package/dist/{chunk-HQAVDVIH.js.map → chunk-POMTRNAL.js.map} +1 -1
- package/dist/{chunk-VDEW4AOS.js → chunk-PSFKIG27.js} +55 -6
- package/dist/chunk-PSFKIG27.js.map +1 -0
- package/dist/{chunk-37RWGNIO.js → chunk-VFT6QKZW.js} +114 -5
- package/dist/chunk-VFT6QKZW.js.map +1 -0
- package/dist/{chunk-VDS6REM3.js → chunk-VJGU6E4U.js} +5 -5
- package/dist/{chunk-VDS6REM3.js.map → chunk-VJGU6E4U.js.map} +1 -1
- package/dist/{chunk-ZCE3CHPX.js → chunk-XVRIWP7B.js} +3 -3
- package/dist/{chunk-ZCE3CHPX.js.map → chunk-XVRIWP7B.js.map} +1 -1
- package/dist/{chunk-7FVTGKTX.js → chunk-YDMKMNDS.js} +2 -2
- package/dist/{chunk-7FVTGKTX.js.map → chunk-YDMKMNDS.js.map} +1 -1
- package/dist/{chunk-6WV6ST67.js → chunk-YNXLPOAB.js} +97 -10
- package/dist/chunk-YNXLPOAB.js.map +1 -0
- package/dist/{chunk-7GW3QR63.js → chunk-ZHC3MDCS.js} +101 -18
- package/dist/chunk-ZHC3MDCS.js.map +1 -0
- package/dist/conversation/index.d.ts +195 -0
- package/dist/conversation/index.js +110 -0
- package/dist/conversation/index.js.map +1 -0
- package/dist/csv.d.ts +1 -1
- package/dist/errors.js +1 -2
- package/dist/form-types.d.ts +1 -1
- package/dist/gallery/index.d.ts +79 -0
- package/dist/gallery/index.js +64 -0
- package/dist/gallery/index.js.map +1 -0
- package/dist/hooks/index.d.ts +6 -4
- package/dist/hooks/index.js +19 -18
- package/dist/hooks/mutation-mode.d.ts +29 -2
- package/dist/hooks/mutation-mode.js +9 -4
- package/dist/hooks/related-keys.d.ts +1 -1
- package/dist/hooks/use-capabilities.d.ts +1 -1
- package/dist/hooks/use-capabilities.js +2 -2
- package/dist/hooks/use-infinite-resource.d.ts +1 -1
- package/dist/hooks/use-infinite-resource.js +4 -4
- package/dist/hooks/use-link-options.d.ts +1 -1
- package/dist/hooks/use-link-options.js +6 -6
- package/dist/hooks/use-live.d.ts +1 -1
- package/dist/hooks/use-live.js +3 -3
- package/dist/hooks/use-one.d.ts +1 -1
- package/dist/hooks/use-one.js +4 -4
- package/dist/hooks/use-persisted-ui-state.d.ts +12 -0
- package/dist/hooks/use-persisted-ui-state.js +5 -0
- package/dist/hooks/use-persisted-ui-state.js.map +1 -0
- package/dist/hooks/use-relation-label.d.ts +1 -1
- package/dist/hooks/use-relation-label.js +2 -2
- package/dist/hooks/use-resource-form.d.ts +14 -1
- package/dist/hooks/use-resource-form.js +12 -9
- package/dist/hooks/use-resource.d.ts +17 -3
- package/dist/hooks/use-resource.js +12 -8
- package/dist/hooks/use-write.d.ts +1 -1
- package/dist/index.d.ts +9 -6
- package/dist/index.js +22 -21
- package/dist/offline/index.d.ts +84 -0
- package/dist/offline/index.js +413 -0
- package/dist/offline/index.js.map +1 -0
- package/dist/provider/index.d.ts +60 -7
- package/dist/provider/index.js +3 -3
- package/dist/resource-view/index.d.ts +79 -4
- package/dist/resource-view/index.js +141 -19
- package/dist/resource-view/index.js.map +1 -1
- package/dist/schema/index.d.ts +4 -3
- package/dist/schema/index.js +2 -1
- package/dist/testing/index.d.ts +2 -2
- package/dist/{types-9WnGxZhj.d.ts → types-BzLv8yOm.d.ts} +8 -0
- package/dist/types-CsKSAKqs.d.ts +143 -0
- package/dist/{viewer-scope-bthEYSOB.d.ts → viewer-scope-Dx0N9AYk.d.ts} +3 -2
- package/dist/workspaces.d.ts +1 -1
- package/dist/{write-outcome-ZWlhhzRW.d.ts → write-outcome-DC5hORz-.d.ts} +1 -1
- package/dist/write-state-DVC4Yq9T.d.ts +58 -0
- package/package.json +15 -2
- package/dist/chunk-37RWGNIO.js.map +0 -1
- package/dist/chunk-6WV6ST67.js.map +0 -1
- package/dist/chunk-7GW3QR63.js.map +0 -1
- package/dist/chunk-KXVDDDJY.js.map +0 -1
- package/dist/chunk-ON2V4RXX.js.map +0 -1
- package/dist/chunk-PA6WJE5E.js +0 -115
- package/dist/chunk-PA6WJE5E.js.map +0 -1
- package/dist/chunk-RK365SO2.js.map +0 -1
- package/dist/chunk-VDEW4AOS.js.map +0 -1
package/dist/provider/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { D as DataProvider, b as Identifier, B as BaseRecord, I as InvalidationKey, W as WriteEvent, C as CountMode, a as FilterParam } from '../types-
|
|
2
|
-
export { A as ArrayFilter, d as BulkChange, e as BulkResult, f as CreateParams, g as CreateResult, i as DeleteParams, j as DeleteResult, G as GetManyParams, o as GetManyResult, p as GetOneParams, q as GetOneResult, H as HistoryParams, r as ImportParams, L as ListParams, s as ListResult, N as NullFilter, P as PaginationParam, R as RangeFilter, w as ResourceChangeEvent, M as RowFailure, Q as ScalarFilter, S as SortParam, V as SubscribeParams, X as UpdateParams, Y as UpdateResult } from '../types-
|
|
3
|
-
import { D as DataWriteError, W as WriteOutcome } from '../write-outcome-
|
|
4
|
-
export { a as DataWriteErrorOptions, i as isDataWriteError } from '../write-outcome-
|
|
1
|
+
import { D as DataProvider, b as Identifier, B as BaseRecord, I as InvalidationKey, W as WriteEvent, C as CountMode, a as FilterParam } from '../types-BzLv8yOm.js';
|
|
2
|
+
export { A as ArrayFilter, d as BulkChange, e as BulkResult, f as CreateParams, g as CreateResult, i as DeleteParams, j as DeleteResult, G as GetManyParams, o as GetManyResult, p as GetOneParams, q as GetOneResult, H as HistoryParams, r as ImportParams, L as ListParams, s as ListResult, N as NullFilter, P as PaginationParam, R as RangeFilter, w as ResourceChangeEvent, M as RowFailure, Q as ScalarFilter, S as SortParam, V as SubscribeParams, X as UpdateParams, Y as UpdateResult } from '../types-BzLv8yOm.js';
|
|
3
|
+
import { D as DataWriteError, W as WriteOutcome } from '../write-outcome-DC5hORz-.js';
|
|
4
|
+
export { a as DataWriteErrorOptions, i as isDataWriteError } from '../write-outcome-DC5hORz-.js';
|
|
5
5
|
import { D as DataReadError, R as ReadOutcome } from '../read-outcome-BnboMYOV.js';
|
|
6
6
|
export { a as DataReadErrorOptions, i as isDataReadError, r as readFailureMessage } from '../read-outcome-BnboMYOV.js';
|
|
7
7
|
import * as react from 'react';
|
|
8
8
|
import { ReactNode } from 'react';
|
|
9
9
|
import { QueryClient } from '@tanstack/react-query';
|
|
10
10
|
import { S as StorageAdapter } from '../types-DKcxHXxq.js';
|
|
11
|
+
import { Q as QueryPersistence } from '../types-CsKSAKqs.js';
|
|
11
12
|
|
|
12
13
|
interface MockProviderOptions {
|
|
13
14
|
/** Simulated latency in ms (default 0). */
|
|
@@ -125,6 +126,17 @@ interface SupabaseWriteContext {
|
|
|
125
126
|
/** The row's id, for an update. */
|
|
126
127
|
id?: Identifier;
|
|
127
128
|
}
|
|
129
|
+
/** What an `update` override is told besides the row. */
|
|
130
|
+
interface SupabaseUpdateContext {
|
|
131
|
+
/**
|
|
132
|
+
* With a `version` rule and an `expectedVersion` from the caller: the
|
|
133
|
+
* version the row must still be at. The override must apply the change
|
|
134
|
+
* only at that version (e.g. `... where id = $1 and version = $2`) and
|
|
135
|
+
* return nothing when no row matched; the provider then tells a
|
|
136
|
+
* `conflict` from `forbidden` and `gone`.
|
|
137
|
+
*/
|
|
138
|
+
expectedVersion?: string;
|
|
139
|
+
}
|
|
128
140
|
/** Per-resource rules for `createSupabaseProvider`. Every field is optional. */
|
|
129
141
|
interface SupabaseResourceConfig {
|
|
130
142
|
/** Singular noun for failure messages, e.g. "project". Defaults to "record". */
|
|
@@ -174,7 +186,23 @@ interface SupabaseResourceConfig {
|
|
|
174
186
|
* row to say why (`forbidden` or `gone`), exactly as for a plain update,
|
|
175
187
|
* so a function that silently skips a row never reports a save.
|
|
176
188
|
*/
|
|
177
|
-
update?: (id: Identifier, row: Record<string, unknown
|
|
189
|
+
update?: (id: Identifier, row: Record<string, unknown>, context?: SupabaseUpdateContext) => Promise<BaseRecord | Identifier | boolean | null | undefined | void>;
|
|
190
|
+
/**
|
|
191
|
+
* The column every update and delete of this resource is checked against,
|
|
192
|
+
* so an edit made on a stale copy is refused as a `conflict` instead of
|
|
193
|
+
* overwriting someone else's (`UpdateParams.expectedVersion`).
|
|
194
|
+
*
|
|
195
|
+
* The database must advance it on every update, or it detects nothing:
|
|
196
|
+
* `integer` with genesis-supabase's `genesis_version_bump` trigger
|
|
197
|
+
* (migration 0019), or `timestamp` with a trigger that sets it to `now()`
|
|
198
|
+
* on update (`moddatetime`). The provider never writes it: a submitted
|
|
199
|
+
* value is dropped. Writes without an `expectedVersion` are not checked,
|
|
200
|
+
* so turning this on changes nothing for callers that don't send one.
|
|
201
|
+
*/
|
|
202
|
+
version?: {
|
|
203
|
+
field: string;
|
|
204
|
+
kind: "integer" | "timestamp";
|
|
205
|
+
};
|
|
178
206
|
/** Maps a stored row to edit-form values; see `DataProvider.toFormValues`. */
|
|
179
207
|
toFormValues?: (record: Record<string, unknown>) => Record<string, unknown>;
|
|
180
208
|
/**
|
|
@@ -445,6 +473,27 @@ type GenesisProviderProps = {
|
|
|
445
473
|
mock?: never;
|
|
446
474
|
/** Platform-specific storage adapter. Defaults to localStorage (SSR-safe). */
|
|
447
475
|
storage?: StorageAdapter;
|
|
476
|
+
/**
|
|
477
|
+
* Keep reads on the device and restore them on the next start, so lists and records open at
|
|
478
|
+
* once: `persistOffline({ cache: indexedDbLocalCache(), resources, buster })` from
|
|
479
|
+
* `@marktiderman/genesis-core/offline`. Needs `persistScope`. Give it from the first render:
|
|
480
|
+
* the provider keeps the first one it's given.
|
|
481
|
+
*/
|
|
482
|
+
persist?: (client: QueryClient) => QueryPersistence;
|
|
483
|
+
/**
|
|
484
|
+
* Whose cache this is: `cacheScope(user.id, workspaceKey)` once someone is signed in,
|
|
485
|
+
* `null` once nobody is, and `undefined` while that isn't known yet (the session loading).
|
|
486
|
+
* A device is one person's: restoring someone deletes everyone else's kept reads, and
|
|
487
|
+
* `null` deletes them all, so a session that ended outside the app (it expired, or was
|
|
488
|
+
* signed out elsewhere) leaves nothing on the device. Undefined does nothing. A change of
|
|
489
|
+
* scope restores the new one's reads. Clear the QueryClient yourself when the person
|
|
490
|
+
* changes, as a sign-out already does; a `ViewerScope` inside keeps the restored reads for
|
|
491
|
+
* this person. Restoring is client-only: in a server-rendered app, give it after hydration
|
|
492
|
+
* (undefined on the server and the first client render), and the screens restore in the
|
|
493
|
+
* background. Change it only once the provider's session has: a scope must never name a
|
|
494
|
+
* person before the data provider's requests are made as them.
|
|
495
|
+
*/
|
|
496
|
+
persistScope?: string | null;
|
|
448
497
|
/**
|
|
449
498
|
* The TanStack Query client to use. Without it, GenesisProvider creates
|
|
450
499
|
* its OWN client — a second cache beside any the app already has, so app
|
|
@@ -465,6 +514,10 @@ type GenesisProviderProps = {
|
|
|
465
514
|
storage?: StorageAdapter;
|
|
466
515
|
/** See the `provider` variant. */
|
|
467
516
|
queryClient?: QueryClient;
|
|
517
|
+
/** See the `provider` variant. */
|
|
518
|
+
persist?: (client: QueryClient) => QueryPersistence;
|
|
519
|
+
/** See the `provider` variant. */
|
|
520
|
+
persistScope?: string | null;
|
|
468
521
|
};
|
|
469
522
|
/**
|
|
470
523
|
* Convenience root: a `QueryClientProvider`, storage, and a data provider
|
|
@@ -472,6 +525,6 @@ type GenesisProviderProps = {
|
|
|
472
525
|
* unless you pass `queryClient`; an app that already has one should pass it,
|
|
473
526
|
* or mount `DataProviderRoot` inside its existing `QueryClientProvider`.
|
|
474
527
|
*/
|
|
475
|
-
declare function GenesisProvider({ children, provider, mock, storage, queryClient: queryClientProp, }: GenesisProviderProps): react.JSX.Element;
|
|
528
|
+
declare function GenesisProvider({ children, provider, mock, storage, queryClient: queryClientProp, persist, persistScope, }: GenesisProviderProps): react.JSX.Element;
|
|
476
529
|
|
|
477
|
-
export { BaseRecord, type CallRpcOptions, CountMode, type CreateOrAdoptOptions, type CreateOrAdoptResult, DEFAULT_RPC_MESSAGES, DataProvider, DataProviderRoot, type DataProviderRootProps, DataReadError, DataWriteError, FilterParam, GenesisProvider, type GenesisProviderProps, Identifier, InvalidationKey, type MockProviderOptions, type PostgrestFieldErrors, RPC_FAILED, ReadOutcome, type RpcClient, type SupabaseClient, type SupabaseClientInput, type SupabaseProviderOptions, type SupabaseRealtimeChannel, type SupabaseRealtimePayload, type SupabaseResourceConfig, type SupabaseWriteContext, WriteEvent, WriteOutcome, callRpc, createMockProvider, createOrAdopt, createSupabaseProvider, fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, useDataProvider, useStorage, writeOutcomeFromCode };
|
|
530
|
+
export { BaseRecord, type CallRpcOptions, CountMode, type CreateOrAdoptOptions, type CreateOrAdoptResult, DEFAULT_RPC_MESSAGES, DataProvider, DataProviderRoot, type DataProviderRootProps, DataReadError, DataWriteError, FilterParam, GenesisProvider, type GenesisProviderProps, Identifier, InvalidationKey, type MockProviderOptions, type PostgrestFieldErrors, RPC_FAILED, ReadOutcome, type RpcClient, type SupabaseClient, type SupabaseClientInput, type SupabaseProviderOptions, type SupabaseRealtimeChannel, type SupabaseRealtimePayload, type SupabaseResourceConfig, type SupabaseUpdateContext, type SupabaseWriteContext, WriteEvent, WriteOutcome, callRpc, createMockProvider, createOrAdopt, createSupabaseProvider, fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, useDataProvider, useStorage, writeOutcomeFromCode };
|
package/dist/provider/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from '../chunk-
|
|
2
|
-
export { DataProviderRoot, GenesisProvider, createMockProvider, useDataProvider, useStorage } from '../chunk-
|
|
1
|
+
export { DEFAULT_RPC_MESSAGES, RPC_FAILED, callRpc, createOrAdopt, createSupabaseProvider } from '../chunk-ZHC3MDCS.js';
|
|
2
|
+
export { DataProviderRoot, GenesisProvider, createMockProvider, useDataProvider, useStorage } from '../chunk-PSFKIG27.js';
|
|
3
3
|
import '../chunk-ZYJUEJ4Z.js';
|
|
4
|
-
export { fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, writeOutcomeFromCode } from '../chunk-
|
|
4
|
+
export { fieldErrorsFromPostgrest, readOutcomeFromCode, toDataWriteError, writeOutcomeFromCode } from '../chunk-VFT6QKZW.js';
|
|
5
5
|
export { DataReadError, isDataReadError, readFailureMessage } from '../chunk-HUNGCTRA.js';
|
|
6
6
|
import '../chunk-RYEXWQFD.js';
|
|
7
7
|
export { DataWriteError, isDataWriteError } from '../chunk-LG6TUBVM.js';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { h as DataRow, x as ResourceContract, O as RowOf, K as RowAction, F as FieldSchema, a as FilterParam, b as Identifier } from '../types-
|
|
1
|
+
import { h as DataRow, x as ResourceContract, O as RowOf, K as RowAction, F as FieldSchema, a as FilterParam, b as Identifier } from '../types-BzLv8yOm.js';
|
|
2
|
+
import { GalleryItem } from '../gallery/index.js';
|
|
2
3
|
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-
|
|
4
|
+
import { V as Viewer, R as ResourceScope } from '../viewer-scope-Dx0N9AYk.js';
|
|
5
|
+
export { G as GenesisViewerRoles, N as NO_VIEWER } from '../viewer-scope-Dx0N9AYk.js';
|
|
5
6
|
import 'react';
|
|
6
7
|
import '@tanstack/react-query';
|
|
7
8
|
import '../dates.js';
|
|
@@ -321,6 +322,45 @@ interface ViewCalendar<Name extends string = string> {
|
|
|
321
322
|
/** 0 Sunday or 1 Monday (default). */
|
|
322
323
|
weekStartsOn?: 0 | 1;
|
|
323
324
|
}
|
|
325
|
+
/**
|
|
326
|
+
* How the view's rows show as a board: a column per value of one field, a card per row.
|
|
327
|
+
* ResourceView's `mode="board"` draws it, and moving a card between columns writes the field
|
|
328
|
+
* through the provider. Plain values only, so every platform reads the same block.
|
|
329
|
+
*/
|
|
330
|
+
interface ViewBoard<Name extends string = string> {
|
|
331
|
+
/** The field whose value is a card's column: a field with choices (an enum) or a yes/no one. */
|
|
332
|
+
field: Name;
|
|
333
|
+
/**
|
|
334
|
+
* The columns, in order, as values of `field`. Default: its choices in the contract's order,
|
|
335
|
+
* then a "No value" column when it can be empty. Listing them shows only those.
|
|
336
|
+
*/
|
|
337
|
+
columns?: readonly string[];
|
|
338
|
+
/** The fields a card shows under its title, in order. Default none: the title alone. */
|
|
339
|
+
cardFields?: readonly Name[];
|
|
340
|
+
/**
|
|
341
|
+
* The most cards a column should hold, by value (`{ doing: 3 }`): a work-in-progress limit.
|
|
342
|
+
* A column over its limit says so; nothing stops a move into it.
|
|
343
|
+
*/
|
|
344
|
+
limits?: Readonly<Record<string, number>>;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* How the view's rows show as a gallery: ResourceView's `mode="grid"` draws a photo per row in
|
|
348
|
+
* justified rows (the layout `GalleryGrid` uses, from `@marktiderman/genesis-core/gallery`) in
|
|
349
|
+
* place of cards. Plain field names only, so every platform reads the same block.
|
|
350
|
+
*/
|
|
351
|
+
interface ViewGallery<Name extends string = string> {
|
|
352
|
+
/** The field holding the image's URL. */
|
|
353
|
+
image: Name;
|
|
354
|
+
/** The image's width and height in pixels, when the rows store them: rows pack by their ratio, 4:3 without. */
|
|
355
|
+
width?: Name;
|
|
356
|
+
height?: Name;
|
|
357
|
+
/** A short line under the photo in the viewer. Default none. */
|
|
358
|
+
caption?: Name;
|
|
359
|
+
/** The photo's text alternative. Default the row's label (the view's `labelField`). */
|
|
360
|
+
alt?: Name;
|
|
361
|
+
/** The target row height, px on the web and points on a phone. Default 180, as `GalleryGrid`. */
|
|
362
|
+
rowHeight?: number;
|
|
363
|
+
}
|
|
324
364
|
/** What `defineView` accepts. */
|
|
325
365
|
interface ViewDefinition<C extends ResourceContract, Row extends DataRow = RowOf<C>> {
|
|
326
366
|
copy?: ViewCopy;
|
|
@@ -353,6 +393,10 @@ interface ViewDefinition<C extends ResourceContract, Row extends DataRow = RowOf
|
|
|
353
393
|
scope?: readonly FieldNameOf<C>[];
|
|
354
394
|
/** How the rows show as a calendar (`mode="calendar"`). */
|
|
355
395
|
calendar?: ViewCalendar<FieldNameOf<C>>;
|
|
396
|
+
/** How the rows show as a board (`mode="board"`). */
|
|
397
|
+
board?: ViewBoard<FieldNameOf<C>>;
|
|
398
|
+
/** How the rows show as a gallery of photos (`mode="grid"`), in place of cards. */
|
|
399
|
+
gallery?: ViewGallery<FieldNameOf<C>>;
|
|
356
400
|
/** Group rows under headers by this field. */
|
|
357
401
|
groupBy?: FieldNameOf<C>;
|
|
358
402
|
/** Default order; `manual: true` turns on drag to reorder, writing this field. */
|
|
@@ -432,6 +476,11 @@ interface ResourceView<C extends ResourceContract = ResourceContract, Row extend
|
|
|
432
476
|
/** A value in words: the field's `labels`, else title case. For badges, choices and group titles. */
|
|
433
477
|
valueLabel(name: string, value: unknown): string;
|
|
434
478
|
columns(preset?: string): readonly ResolvedColumn<Row>[];
|
|
479
|
+
/**
|
|
480
|
+
* One field as a column, resolved as a preset lists it (a board card's fields, say). Undefined
|
|
481
|
+
* for a name that isn't a field or one the viewer can't read (`permissions.read: false`).
|
|
482
|
+
*/
|
|
483
|
+
column(name: string): ResolvedColumn<Row> | undefined;
|
|
435
484
|
form(mode: "create" | "edit"): readonly ResolvedFormField[];
|
|
436
485
|
/** Fields a writer may send: the form's, never generated, read-only, key or scope fields. */
|
|
437
486
|
writable(mode: "create" | "edit"): readonly string[];
|
|
@@ -449,6 +498,13 @@ interface ResourceView<C extends ResourceContract = ResourceContract, Row extend
|
|
|
449
498
|
*/
|
|
450
499
|
canAction(name: string, row: Row, viewer?: Viewer): Allowed;
|
|
451
500
|
summary(row: Row): RowSummary;
|
|
501
|
+
/**
|
|
502
|
+
* The row as a gallery photo, by the view's `gallery` block and any `override` a screen passes
|
|
503
|
+
* (ResourceView's `gallery`): undefined without a gallery block. Its `id` is the row's key, its
|
|
504
|
+
* `alt` the row's label unless the block names a field; a row without an image has an empty `src`,
|
|
505
|
+
* which GalleryGrid and NativeGalleryGrid draw as a placeholder tile; leave those out of a Lightbox.
|
|
506
|
+
*/
|
|
507
|
+
galleryItem(row: Row, override?: Partial<ViewGallery>): GalleryItem | undefined;
|
|
452
508
|
}
|
|
453
509
|
|
|
454
510
|
/** A view that names a field, preset or section its contract doesn't have. */
|
|
@@ -473,6 +529,25 @@ declare function valueText(labels: Readonly<Record<string, string>> | undefined,
|
|
|
473
529
|
* @stability Beta
|
|
474
530
|
*/
|
|
475
531
|
declare function calendarProblems(fields: readonly Pick<FieldSchema, "name" | "type" | "array">[], calendar: Partial<ViewCalendar>): string[];
|
|
532
|
+
/**
|
|
533
|
+
* The values a board's field can hold, in the contract's order: an enum's choices, or `true`
|
|
534
|
+
* and `false` for a yes/no field. Undefined when the field has no fixed set of values.
|
|
535
|
+
*
|
|
536
|
+
* @stability Beta
|
|
537
|
+
*/
|
|
538
|
+
declare function boardChoices(field: Pick<FieldSchema, "type" | "array" | "enumValues"> | undefined): readonly string[] | undefined;
|
|
539
|
+
/**
|
|
540
|
+
* What's wrong with a gallery block for these fields, one sentence each (empty when it's fine).
|
|
541
|
+
*
|
|
542
|
+
* @stability Beta
|
|
543
|
+
*/
|
|
544
|
+
declare function galleryProblems(fields: readonly Pick<FieldSchema, "name" | "type" | "array">[], gallery: Partial<ViewGallery>): string[];
|
|
545
|
+
/**
|
|
546
|
+
* What's wrong with a board block for these fields, one sentence each (empty when it's fine).
|
|
547
|
+
*
|
|
548
|
+
* @stability Beta
|
|
549
|
+
*/
|
|
550
|
+
declare function boardProblems(fields: readonly Pick<FieldSchema, "name" | "type" | "array" | "enumValues">[], board: Partial<ViewBoard>): string[];
|
|
476
551
|
/**
|
|
477
552
|
* Describe what a resource means to people. The result is frozen and platform-neutral:
|
|
478
553
|
*
|
|
@@ -816,4 +891,4 @@ type WorkspaceSection<Row extends DataRow = DataRow, Name extends string = strin
|
|
|
816
891
|
/** @deprecated Renamed `RecordViewHeaderAction`. */
|
|
817
892
|
type WorkspaceHeaderAction = RecordViewHeaderAction;
|
|
818
893
|
|
|
819
|
-
export { type Allowed, type ComputedColumn, type DisplayHint, type FieldNameOf, type LinkFilter, type LinkOrder, type LinkedView, type RecordView, type RecordViewDefinition, type RecordViewFilter, type RecordViewHeader, type RecordViewHeaderAction, type RecordViewHeaderOptions, type RecordViewListSection, type RecordViewReadinessItem, type RecordViewSection, type RecordViewSettingsSection, type RecordViewSlotSection, type ResolvedColumn, type ResolvedFormField, type ResolvedLink, type ResolvedReadinessItem, type ResolvedRecordViewSection, type ResolvedViewAction, type ResourceTree, type ResourceView, type ResourceWorkspace, type RowImage, RowOf, type RowPicture, type RowSummary, type TimeZoneName, type TreeNode, type TreeOptions, type TreeResult, type ViewAction, type ViewCalendar, type ViewCalendarDurationUnit, type ViewCalendarLayout, type ViewColumn, type ViewCopy, type ViewDefinition, ViewDefinitionError, type ViewField, type ViewFormItem, type ViewGuards, type ViewLink, type ViewPreset, type ViewTimeZone, type ViewTone, Viewer, type WorkspaceDefinition, type WorkspaceHeaderAction, type WorkspaceSection, calendarProblems, cascadeSelection, defineRecordView, defineView, defineWorkspace, deriveDisplay, filterParams, initialExpanded, initialsOf, isRecordView, isWorkspace, plural, rowPicture, sameFormValue, scopeFilter, scopeValues, setExpanded, singular, treeRows, valueText };
|
|
894
|
+
export { type Allowed, type ComputedColumn, type DisplayHint, type FieldNameOf, type LinkFilter, type LinkOrder, type LinkedView, type RecordView, type RecordViewDefinition, type RecordViewFilter, type RecordViewHeader, type RecordViewHeaderAction, type RecordViewHeaderOptions, type RecordViewListSection, type RecordViewReadinessItem, type RecordViewSection, type RecordViewSettingsSection, type RecordViewSlotSection, type ResolvedColumn, type ResolvedFormField, type ResolvedLink, type ResolvedReadinessItem, type ResolvedRecordViewSection, type ResolvedViewAction, type ResourceTree, type ResourceView, type ResourceWorkspace, type RowImage, RowOf, type RowPicture, type RowSummary, type TimeZoneName, type TreeNode, type TreeOptions, type TreeResult, type ViewAction, type ViewBoard, type ViewCalendar, type ViewCalendarDurationUnit, type ViewCalendarLayout, type ViewColumn, type ViewCopy, type ViewDefinition, ViewDefinitionError, type ViewField, type ViewFormItem, type ViewGallery, type ViewGuards, type ViewLink, type ViewPreset, type ViewTimeZone, type ViewTone, Viewer, type WorkspaceDefinition, type WorkspaceHeaderAction, type WorkspaceSection, boardChoices, boardProblems, calendarProblems, cascadeSelection, defineRecordView, defineView, defineWorkspace, deriveDisplay, filterParams, galleryProblems, initialExpanded, initialsOf, isRecordView, isWorkspace, plural, rowPicture, sameFormValue, scopeFilter, scopeValues, setExpanded, singular, treeRows, valueText };
|
|
@@ -3,8 +3,7 @@ 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
5
|
import { isTimeZone } from '../chunk-WXENWPWP.js';
|
|
6
|
-
import { isDevelopment, reportError } from '../chunk-
|
|
7
|
-
import '../chunk-PA6WJE5E.js';
|
|
6
|
+
import { isDevelopment, reportError } from '../chunk-VFT6QKZW.js';
|
|
8
7
|
import '../chunk-HUNGCTRA.js';
|
|
9
8
|
import { titleCase } from '../chunk-RYEXWQFD.js';
|
|
10
9
|
import '../chunk-LG6TUBVM.js';
|
|
@@ -245,6 +244,62 @@ function calendarProblems(fields, calendar) {
|
|
|
245
244
|
}
|
|
246
245
|
return problems;
|
|
247
246
|
}
|
|
247
|
+
var BOARD_KEYS = ["field", "columns", "cardFields", "limits"];
|
|
248
|
+
function boardChoices(field) {
|
|
249
|
+
if (!field || field.array) return void 0;
|
|
250
|
+
if (field.enumValues?.length) return field.enumValues;
|
|
251
|
+
if (field.type === "boolean") return ["true", "false"];
|
|
252
|
+
return void 0;
|
|
253
|
+
}
|
|
254
|
+
var GALLERY_KEYS = ["image", "width", "height", "caption", "alt", "rowHeight"];
|
|
255
|
+
function galleryProblems(fields, gallery) {
|
|
256
|
+
const problems = [];
|
|
257
|
+
const byName = new Map(fields.map((f) => [f.name, f]));
|
|
258
|
+
const named = (key, type) => {
|
|
259
|
+
const name = gallery[key];
|
|
260
|
+
if (name === void 0) return;
|
|
261
|
+
const field = byName.get(name);
|
|
262
|
+
if (!field) problems.push(`gallery.${key} names "${name}", which isn't a field`);
|
|
263
|
+
else if (type && (field.type !== type || field.array)) problems.push(`gallery.${key} "${name}" is a ${field.array ? "list" : field.type}, not a ${type === "string" ? "text" : "number"} field`);
|
|
264
|
+
};
|
|
265
|
+
named("image", "string");
|
|
266
|
+
named("width", "number");
|
|
267
|
+
named("height", "number");
|
|
268
|
+
named("caption");
|
|
269
|
+
named("alt");
|
|
270
|
+
if (gallery.width === void 0 !== (gallery.height === void 0)) problems.push("gallery.width and gallery.height go together: a ratio needs both");
|
|
271
|
+
const { rowHeight } = gallery;
|
|
272
|
+
if (rowHeight !== void 0 && !(typeof rowHeight === "number" && Number.isFinite(rowHeight) && rowHeight > 0)) problems.push(`gallery.rowHeight is a height above 0, not ${String(rowHeight)}`);
|
|
273
|
+
return problems;
|
|
274
|
+
}
|
|
275
|
+
function boardProblems(fields, board) {
|
|
276
|
+
const problems = [];
|
|
277
|
+
const byName = new Map(fields.map((f) => [f.name, f]));
|
|
278
|
+
const field = board.field === void 0 ? void 0 : byName.get(board.field);
|
|
279
|
+
if (board.field !== void 0 && !field) problems.push(`board.field names "${board.field}", which isn't a field`);
|
|
280
|
+
const choices = boardChoices(field);
|
|
281
|
+
if (field && !choices) problems.push(`board.field "${board.field}" has no fixed values: use an enum or a yes/no field`);
|
|
282
|
+
if (board.columns !== void 0) {
|
|
283
|
+
if (!Array.isArray(board.columns) || board.columns.length === 0) problems.push("board.columns isn't a list of values");
|
|
284
|
+
else {
|
|
285
|
+
const seen = /* @__PURE__ */ new Set();
|
|
286
|
+
for (const value of board.columns) {
|
|
287
|
+
if (choices && !choices.includes(value)) problems.push(`board.columns lists "${String(value)}", which isn't a value of ${board.field}`);
|
|
288
|
+
if (seen.has(value)) problems.push(`board.columns lists "${String(value)}" twice`);
|
|
289
|
+
seen.add(value);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
for (const name of board.cardFields ?? []) {
|
|
294
|
+
if (!byName.has(name)) problems.push(`board.cardFields names "${name}", which isn't a field`);
|
|
295
|
+
}
|
|
296
|
+
for (const [value, limit] of Object.entries(board.limits ?? {})) {
|
|
297
|
+
const columns = board.columns ?? choices;
|
|
298
|
+
if (columns && !columns.includes(value)) problems.push(`board.limits has "${value}", which isn't one of the board's columns`);
|
|
299
|
+
if (!Number.isInteger(limit) || limit < 1) problems.push(`board.limits.${value} is a whole number of cards, 1 or more, not ${String(limit)}`);
|
|
300
|
+
}
|
|
301
|
+
return problems;
|
|
302
|
+
}
|
|
248
303
|
function defineView(contract, definition = {}) {
|
|
249
304
|
const facts = contract;
|
|
250
305
|
const fields = contract.fields;
|
|
@@ -359,6 +414,36 @@ function defineView(contract, definition = {}) {
|
|
|
359
414
|
problems.push(...calendarProblems(fields, calendar));
|
|
360
415
|
}
|
|
361
416
|
}
|
|
417
|
+
const rawBoard = definition.board;
|
|
418
|
+
let board;
|
|
419
|
+
if (rawBoard !== void 0) {
|
|
420
|
+
if (!rawBoard || typeof rawBoard !== "object" || Array.isArray(rawBoard)) {
|
|
421
|
+
problems.push("board isn't an object");
|
|
422
|
+
} else {
|
|
423
|
+
for (const key of Object.keys(rawBoard)) if (!BOARD_KEYS.includes(key)) problems.push(`board.${key} isn't a board setting`);
|
|
424
|
+
if (rawBoard.field === void 0) problems.push("board.field is required");
|
|
425
|
+
const given = rawBoard;
|
|
426
|
+
board = Object.freeze({
|
|
427
|
+
...given,
|
|
428
|
+
...given.columns ? { columns: Object.freeze([...given.columns]) } : {},
|
|
429
|
+
...given.cardFields ? { cardFields: Object.freeze([...given.cardFields]) } : {},
|
|
430
|
+
...given.limits ? { limits: Object.freeze({ ...given.limits }) } : {}
|
|
431
|
+
});
|
|
432
|
+
problems.push(...boardProblems(fields, board));
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
const rawGallery = definition.gallery;
|
|
436
|
+
let gallery;
|
|
437
|
+
if (rawGallery !== void 0) {
|
|
438
|
+
if (!rawGallery || typeof rawGallery !== "object" || Array.isArray(rawGallery)) {
|
|
439
|
+
problems.push("gallery isn't an object");
|
|
440
|
+
} else {
|
|
441
|
+
for (const key of Object.keys(rawGallery)) if (!GALLERY_KEYS.includes(key)) problems.push(`gallery.${key} isn't a gallery setting`);
|
|
442
|
+
if (rawGallery.image === void 0) problems.push("gallery.image is required");
|
|
443
|
+
gallery = Object.freeze({ ...rawGallery });
|
|
444
|
+
problems.push(...galleryProblems(fields, gallery));
|
|
445
|
+
}
|
|
446
|
+
}
|
|
362
447
|
if (definition.orderBy) known(definition.orderBy.field, "orderBy");
|
|
363
448
|
for (const [name, preset] of Object.entries(presets)) {
|
|
364
449
|
if (preset.columns && preset.columns !== "default" && !own(columnLists, preset.columns)) {
|
|
@@ -411,6 +496,27 @@ function defineView(contract, definition = {}) {
|
|
|
411
496
|
const neededLink = (f) => linkEditable(f) && !f.nullable && !f.optional && !f.hasDefault && !scope.has(f.name);
|
|
412
497
|
const defaultColumns = own(columnLists, "default") ?? fields.filter((f) => !quiet(f)).map((f) => f.name);
|
|
413
498
|
const presetNames = Object.freeze(["default", ...Object.keys(columnLists).filter((p) => p !== "default")]);
|
|
499
|
+
const fieldColumns = /* @__PURE__ */ new Map();
|
|
500
|
+
const fieldColumn = (column) => {
|
|
501
|
+
const cached = fieldColumns.get(column);
|
|
502
|
+
if (cached) return cached;
|
|
503
|
+
const v = own(viewFields, column);
|
|
504
|
+
const resolved = Object.freeze({
|
|
505
|
+
key: column,
|
|
506
|
+
label: label(column),
|
|
507
|
+
display: display(column),
|
|
508
|
+
field: byName.get(column),
|
|
509
|
+
value: (row) => row[column],
|
|
510
|
+
...v?.tones ? { tones: v.tones } : {},
|
|
511
|
+
...v?.labels ? { labels: v.labels } : {},
|
|
512
|
+
...v?.labelField ? { labelField: v.labelField } : {},
|
|
513
|
+
...v?.missingLabel ? { missingLabel: v.missingLabel } : {},
|
|
514
|
+
...v?.when ? { when: (row, viewer = NO_VIEWER) => v.when(row, viewer) } : {},
|
|
515
|
+
...v?.timeZone ? { timeZone: v.timeZone } : {}
|
|
516
|
+
});
|
|
517
|
+
fieldColumns.set(column, resolved);
|
|
518
|
+
return resolved;
|
|
519
|
+
};
|
|
414
520
|
const resolvedColumns = /* @__PURE__ */ new Map();
|
|
415
521
|
const columns = (preset = "default") => {
|
|
416
522
|
const cached = resolvedColumns.get(preset);
|
|
@@ -422,20 +528,7 @@ function defineView(contract, definition = {}) {
|
|
|
422
528
|
if (typeof column !== "string") {
|
|
423
529
|
return Object.freeze({ key: column.key, label: column.label, display: column.display ?? "text", value: column.value });
|
|
424
530
|
}
|
|
425
|
-
|
|
426
|
-
return Object.freeze({
|
|
427
|
-
key: column,
|
|
428
|
-
label: label(column),
|
|
429
|
-
display: display(column),
|
|
430
|
-
field: byName.get(column),
|
|
431
|
-
value: (row) => row[column],
|
|
432
|
-
...v?.tones ? { tones: v.tones } : {},
|
|
433
|
-
...v?.labels ? { labels: v.labels } : {},
|
|
434
|
-
...v?.labelField ? { labelField: v.labelField } : {},
|
|
435
|
-
...v?.missingLabel ? { missingLabel: v.missingLabel } : {},
|
|
436
|
-
...v?.when ? { when: (row, viewer = NO_VIEWER) => v.when(row, viewer) } : {},
|
|
437
|
-
...v?.timeZone ? { timeZone: v.timeZone } : {}
|
|
438
|
-
});
|
|
531
|
+
return fieldColumn(column);
|
|
439
532
|
})
|
|
440
533
|
);
|
|
441
534
|
resolvedColumns.set(preset, out);
|
|
@@ -514,6 +607,31 @@ function defineView(contract, definition = {}) {
|
|
|
514
607
|
const value = labelField ? row[labelField] : void 0;
|
|
515
608
|
return { title: value === null || value === void 0 || value === "" ? titleCase(noun) : String(value) };
|
|
516
609
|
};
|
|
610
|
+
const galleryItem = (row, override) => {
|
|
611
|
+
const block = { ...gallery, ...override };
|
|
612
|
+
if (!block.image) return void 0;
|
|
613
|
+
const image = row[block.image];
|
|
614
|
+
const src = typeof image === "string" ? image : "";
|
|
615
|
+
const number = (name) => {
|
|
616
|
+
const value = name ? Number(row[name]) : NaN;
|
|
617
|
+
return Number.isFinite(value) && value > 0 ? value : void 0;
|
|
618
|
+
};
|
|
619
|
+
const text = (name) => {
|
|
620
|
+
const value = name ? row[name] : void 0;
|
|
621
|
+
return value === null || value === void 0 || value === "" ? void 0 : String(value);
|
|
622
|
+
};
|
|
623
|
+
const width = number(block.width);
|
|
624
|
+
const height = number(block.height);
|
|
625
|
+
const caption = text(block.caption);
|
|
626
|
+
const alt = text(block.alt) ?? summary(row).title;
|
|
627
|
+
return {
|
|
628
|
+
id: String(encodeRecordKey(contract, row)),
|
|
629
|
+
src,
|
|
630
|
+
alt,
|
|
631
|
+
...width !== void 0 && height !== void 0 ? { width, height } : {},
|
|
632
|
+
...caption !== void 0 ? { caption } : {}
|
|
633
|
+
};
|
|
634
|
+
};
|
|
517
635
|
return Object.freeze({
|
|
518
636
|
contract,
|
|
519
637
|
definition: Object.freeze({
|
|
@@ -524,7 +642,9 @@ function defineView(contract, definition = {}) {
|
|
|
524
642
|
...definition.form ? { form: formItems } : {},
|
|
525
643
|
...definition.scope ? { scope: Object.freeze([...definition.scope]) } : {},
|
|
526
644
|
...definition.actions ? { actions: actionList } : {},
|
|
527
|
-
...calendar ? { calendar } : {}
|
|
645
|
+
...calendar ? { calendar } : {},
|
|
646
|
+
...board ? { board } : {},
|
|
647
|
+
...gallery ? { gallery } : {}
|
|
528
648
|
}),
|
|
529
649
|
resource: contract.name,
|
|
530
650
|
noun,
|
|
@@ -533,6 +653,7 @@ function defineView(contract, definition = {}) {
|
|
|
533
653
|
labelField,
|
|
534
654
|
presets: presetNames,
|
|
535
655
|
field: (name) => byName.get(name),
|
|
656
|
+
column: (name) => byName.has(name) && readable(name) ? fieldColumn(name) : void 0,
|
|
536
657
|
label,
|
|
537
658
|
display,
|
|
538
659
|
valueLabel,
|
|
@@ -542,7 +663,8 @@ function defineView(contract, definition = {}) {
|
|
|
542
663
|
can,
|
|
543
664
|
actions: () => resolvedActions,
|
|
544
665
|
canAction,
|
|
545
|
-
summary
|
|
666
|
+
summary,
|
|
667
|
+
galleryItem
|
|
546
668
|
});
|
|
547
669
|
}
|
|
548
670
|
|
|
@@ -912,6 +1034,6 @@ function defineRecordView(view, definition) {
|
|
|
912
1034
|
var defineWorkspace = defineRecordView;
|
|
913
1035
|
var isWorkspace = isRecordView;
|
|
914
1036
|
|
|
915
|
-
export { ViewDefinitionError, calendarProblems, cascadeSelection, defineRecordView, defineView, defineWorkspace, deriveDisplay, filterParams, initialExpanded, initialsOf, isRecordView, isWorkspace, plural, rowPicture, sameFormValue, scopeFilter, scopeValues, setExpanded, singular, treeRows, valueText };
|
|
1037
|
+
export { ViewDefinitionError, boardChoices, boardProblems, calendarProblems, cascadeSelection, defineRecordView, defineView, defineWorkspace, deriveDisplay, filterParams, galleryProblems, initialExpanded, initialsOf, isRecordView, isWorkspace, plural, rowPicture, sameFormValue, scopeFilter, scopeValues, setExpanded, singular, treeRows, valueText };
|
|
916
1038
|
//# sourceMappingURL=index.js.map
|
|
917
1039
|
//# sourceMappingURL=index.js.map
|