@marktiderman/genesis-core 2.9.0 → 2.11.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 +164 -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-X6EVE7W4.js → chunk-3B5O36DU.js} +112 -19
- 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-AKF2RAGX.js} +8 -5
- package/dist/chunk-AKF2RAGX.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-IQVIHN7C.js → chunk-VJGU6E4U.js} +19 -13
- package/dist/chunk-VJGU6E4U.js.map +1 -0
- 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 +5 -4
- package/dist/hooks/index.js +18 -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 +10 -2
- 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-relation-label.d.ts +1 -1
- package/dist/hooks/use-relation-label.js +2 -2
- package/dist/hooks/use-resource-form.d.ts +20 -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 +8 -6
- package/dist/index.js +21 -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 +113 -4
- package/dist/resource-view/index.js +183 -25
- 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-r_Rlw7BB.d.ts → types-BzLv8yOm.d.ts} +22 -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-BWV34wh5.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-IQVIHN7C.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/chunk-X6EVE7W4.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';
|
|
@@ -104,6 +105,17 @@ interface ViewLink {
|
|
|
104
105
|
filter?: LinkFilter | ((values: Readonly<Record<string, unknown>>) => LinkFilter);
|
|
105
106
|
/** The linked fields a search matches. Default: the naming field (`labelField`). */
|
|
106
107
|
searchFields?: readonly string[];
|
|
108
|
+
/**
|
|
109
|
+
* The order the picker lists rows in. Default: by the naming field, then the key. `"view"`
|
|
110
|
+
* uses the linked view's own `orderBy` (a `position` its list is sorted by) and needs `view`;
|
|
111
|
+
* a linked view without one keeps the default. `{ field, direction }` names a linked field.
|
|
112
|
+
*/
|
|
113
|
+
orderBy?: "view" | LinkOrder;
|
|
114
|
+
}
|
|
115
|
+
/** A picker's order: a field of the linked resource, ascending unless it says so. */
|
|
116
|
+
interface LinkOrder {
|
|
117
|
+
field: string;
|
|
118
|
+
direction?: "asc" | "desc";
|
|
107
119
|
}
|
|
108
120
|
/** A link's picker, resolved: what to list, what names a row, and the filters to send. */
|
|
109
121
|
interface ResolvedLink {
|
|
@@ -115,6 +127,14 @@ interface ResolvedLink {
|
|
|
115
127
|
readonly labelField: string | undefined;
|
|
116
128
|
/** The linked fields a search matches. Unset: the naming field. */
|
|
117
129
|
searchFields?: readonly string[];
|
|
130
|
+
/**
|
|
131
|
+
* The order the picker lists rows in (`link.orderBy`, or the linked view's `orderBy` for
|
|
132
|
+
* `"view"`), then the key. Undefined: by the naming field, then the key.
|
|
133
|
+
*/
|
|
134
|
+
readonly orderBy?: {
|
|
135
|
+
readonly field: string;
|
|
136
|
+
readonly direction: "asc" | "desc";
|
|
137
|
+
} | undefined;
|
|
118
138
|
/**
|
|
119
139
|
* The filters a picker sends: the linked view's scope keys from `scope` (as its own lists apply
|
|
120
140
|
* them), its preset's filter, then the link's own `filter` for these form values.
|
|
@@ -266,6 +286,8 @@ interface ViewCopy {
|
|
|
266
286
|
}
|
|
267
287
|
/** How a calendar lays out its window: a month grid, 1–4 weeks, a day-by-day agenda, or a row per lane. */
|
|
268
288
|
type ViewCalendarLayout = "month" | "weeks" | "agenda" | "lanes";
|
|
289
|
+
/** What a calendar's `durationField` counts. */
|
|
290
|
+
type ViewCalendarDurationUnit = "minutes" | "hours" | "days";
|
|
269
291
|
/**
|
|
270
292
|
* How the view's rows show as a calendar: ResourceView's `mode="calendar"` on the web,
|
|
271
293
|
* NativeResourceView's later. Plain values only, so every platform reads the same block; a screen
|
|
@@ -276,17 +298,69 @@ interface ViewCalendar<Name extends string = string> {
|
|
|
276
298
|
field: Name;
|
|
277
299
|
/** Where a row ends: its last day for a date field, its end instant for a timestamp. */
|
|
278
300
|
endField?: Name;
|
|
301
|
+
/**
|
|
302
|
+
* A number field holding how long a row runs, for a row with no end column: its end is the
|
|
303
|
+
* start plus this many `durationUnit`s. A row whose `endField` has a value keeps that end.
|
|
304
|
+
*/
|
|
305
|
+
durationField?: Name;
|
|
306
|
+
/** What `durationField` counts. Default `minutes`. */
|
|
307
|
+
durationUnit?: ViewCalendarDurationUnit;
|
|
279
308
|
/** A yes/no field: the row is all day, its timestamp shown without a time. */
|
|
280
309
|
allDayField?: Name;
|
|
281
310
|
/** The field whose value (or list of values) names a row's lanes: a dot each, a lane each. */
|
|
282
311
|
laneBy?: Name;
|
|
283
312
|
/** Default `month`. */
|
|
284
313
|
layout?: ViewCalendarLayout;
|
|
314
|
+
/**
|
|
315
|
+
* The layout on a phone (below 768px), until the person picks one from the layout switch:
|
|
316
|
+
* `"agenda"` turns a month grid too narrow to read into a day-by-day list. Unset, a phone shows
|
|
317
|
+
* `layout`, as before.
|
|
318
|
+
*/
|
|
319
|
+
phoneLayout?: ViewCalendarLayout;
|
|
285
320
|
/** For `weeks`, `agenda` and `lanes`: 1 to 4. Default 2. */
|
|
286
321
|
weeks?: 1 | 2 | 3 | 4;
|
|
287
322
|
/** 0 Sunday or 1 Monday (default). */
|
|
288
323
|
weekStartsOn?: 0 | 1;
|
|
289
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
|
+
}
|
|
290
364
|
/** What `defineView` accepts. */
|
|
291
365
|
interface ViewDefinition<C extends ResourceContract, Row extends DataRow = RowOf<C>> {
|
|
292
366
|
copy?: ViewCopy;
|
|
@@ -319,6 +393,10 @@ interface ViewDefinition<C extends ResourceContract, Row extends DataRow = RowOf
|
|
|
319
393
|
scope?: readonly FieldNameOf<C>[];
|
|
320
394
|
/** How the rows show as a calendar (`mode="calendar"`). */
|
|
321
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>>;
|
|
322
400
|
/** Group rows under headers by this field. */
|
|
323
401
|
groupBy?: FieldNameOf<C>;
|
|
324
402
|
/** Default order; `manual: true` turns on drag to reorder, writing this field. */
|
|
@@ -398,6 +476,11 @@ interface ResourceView<C extends ResourceContract = ResourceContract, Row extend
|
|
|
398
476
|
/** A value in words: the field's `labels`, else title case. For badges, choices and group titles. */
|
|
399
477
|
valueLabel(name: string, value: unknown): string;
|
|
400
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;
|
|
401
484
|
form(mode: "create" | "edit"): readonly ResolvedFormField[];
|
|
402
485
|
/** Fields a writer may send: the form's, never generated, read-only, key or scope fields. */
|
|
403
486
|
writable(mode: "create" | "edit"): readonly string[];
|
|
@@ -415,6 +498,13 @@ interface ResourceView<C extends ResourceContract = ResourceContract, Row extend
|
|
|
415
498
|
*/
|
|
416
499
|
canAction(name: string, row: Row, viewer?: Viewer): Allowed;
|
|
417
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;
|
|
418
508
|
}
|
|
419
509
|
|
|
420
510
|
/** A view that names a field, preset or section its contract doesn't have. */
|
|
@@ -439,6 +529,25 @@ declare function valueText(labels: Readonly<Record<string, string>> | undefined,
|
|
|
439
529
|
* @stability Beta
|
|
440
530
|
*/
|
|
441
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[];
|
|
442
551
|
/**
|
|
443
552
|
* Describe what a resource means to people. The result is frozen and platform-neutral:
|
|
444
553
|
*
|
|
@@ -782,4 +891,4 @@ type WorkspaceSection<Row extends DataRow = DataRow, Name extends string = strin
|
|
|
782
891
|
/** @deprecated Renamed `RecordViewHeaderAction`. */
|
|
783
892
|
type WorkspaceHeaderAction = RecordViewHeaderAction;
|
|
784
893
|
|
|
785
|
-
export { type Allowed, type ComputedColumn, type DisplayHint, type FieldNameOf, type LinkFilter, 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 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';
|
|
@@ -50,6 +49,7 @@ function scopeFilter(view, scope) {
|
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
// src/resource-view/link.ts
|
|
52
|
+
var IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
53
53
|
function filterParams(filter) {
|
|
54
54
|
return Object.entries(filter ?? {}).map(
|
|
55
55
|
([field, value]) => value === null ? { field, operator: "is_null" } : Array.isArray(value) ? { field, operator: "in", value: [...value] } : { field, operator: "eq", value }
|
|
@@ -68,9 +68,19 @@ function linkProblems(name, link, reference) {
|
|
|
68
68
|
if (l.filter !== void 0 && typeof l.filter !== "function" && (!l.filter || typeof l.filter !== "object" || Array.isArray(l.filter))) {
|
|
69
69
|
problems.push(`${where}.filter isn't a filter or a function`);
|
|
70
70
|
}
|
|
71
|
-
if (l.searchFields !== void 0 && (!Array.isArray(l.searchFields) || l.searchFields.some((f) => typeof f !== "string" ||
|
|
71
|
+
if (l.searchFields !== void 0 && (!Array.isArray(l.searchFields) || l.searchFields.some((f) => typeof f !== "string" || !IDENTIFIER.test(f)))) {
|
|
72
72
|
problems.push(`${where}.searchFields isn't a list of field names`);
|
|
73
73
|
}
|
|
74
|
+
if (l.orderBy === "view") {
|
|
75
|
+
if (l.view === void 0) problems.push(`${where}.orderBy "view" needs a view`);
|
|
76
|
+
} else if (l.orderBy !== void 0) {
|
|
77
|
+
const o = l.orderBy;
|
|
78
|
+
if (!o || typeof o !== "object" || typeof o.field !== "string" || !IDENTIFIER.test(o.field)) {
|
|
79
|
+
problems.push(`${where}.orderBy isn't "view" or { field, direction }`);
|
|
80
|
+
} else if (o.direction !== void 0 && o.direction !== "asc" && o.direction !== "desc") {
|
|
81
|
+
problems.push(`${where}.orderBy.direction is "asc" or "desc", not ${String(o.direction)}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
74
84
|
return problems;
|
|
75
85
|
}
|
|
76
86
|
function linkedViewProblems(where, view, reference, preset) {
|
|
@@ -108,6 +118,12 @@ function resolveLink(owner, name, reference, link, labelField) {
|
|
|
108
118
|
return labelField ?? linkedView()?.labelField;
|
|
109
119
|
},
|
|
110
120
|
...link?.searchFields ? { searchFields: Object.freeze([...link.searchFields]) } : {},
|
|
121
|
+
// Read when asked, like the naming field: `"view"` reads a view given as a function.
|
|
122
|
+
get orderBy() {
|
|
123
|
+
const order = link?.orderBy === "view" ? linkedView()?.definition.orderBy : link?.orderBy;
|
|
124
|
+
if (!order || typeof order.field !== "string" || !IDENTIFIER.test(order.field)) return void 0;
|
|
125
|
+
return Object.freeze({ field: order.field, direction: order.direction === "desc" ? "desc" : "asc" });
|
|
126
|
+
},
|
|
111
127
|
filters(scope, values = {}) {
|
|
112
128
|
const view = linkedView();
|
|
113
129
|
const preset = view ? view.definition.presets?.[link?.preset ?? "default"]?.filter : void 0;
|
|
@@ -186,6 +202,20 @@ function valueText(labels, value) {
|
|
|
186
202
|
const key = String(value);
|
|
187
203
|
return own(labels, key) ?? titleCase(key);
|
|
188
204
|
}
|
|
205
|
+
var KIND = { datetime: "date or timestamp", boolean: "yes/no", number: "number" };
|
|
206
|
+
var LAYOUTS = ["month", "weeks", "agenda", "lanes"];
|
|
207
|
+
var CALENDAR_KEYS = [
|
|
208
|
+
"field",
|
|
209
|
+
"endField",
|
|
210
|
+
"durationField",
|
|
211
|
+
"durationUnit",
|
|
212
|
+
"allDayField",
|
|
213
|
+
"laneBy",
|
|
214
|
+
"layout",
|
|
215
|
+
"phoneLayout",
|
|
216
|
+
"weeks",
|
|
217
|
+
"weekStartsOn"
|
|
218
|
+
];
|
|
189
219
|
function calendarProblems(fields, calendar) {
|
|
190
220
|
const problems = [];
|
|
191
221
|
const byName = new Map(fields.map((f) => [f.name, f]));
|
|
@@ -193,14 +223,20 @@ function calendarProblems(fields, calendar) {
|
|
|
193
223
|
if (name === void 0) return;
|
|
194
224
|
const f = byName.get(name);
|
|
195
225
|
if (!f) problems.push(`${where} names "${name}", which isn't a field`);
|
|
196
|
-
else if (f.type !== type || f.array) problems.push(`${where} "${name}" isn't a ${type
|
|
226
|
+
else if (f.type !== type || f.array) problems.push(`${where} "${name}" isn't a ${KIND[type]} field`);
|
|
197
227
|
};
|
|
198
228
|
typed(calendar.field, "calendar.field", "datetime");
|
|
199
229
|
typed(calendar.endField, "calendar.endField", "datetime");
|
|
230
|
+
typed(calendar.durationField, "calendar.durationField", "number");
|
|
200
231
|
typed(calendar.allDayField, "calendar.allDayField", "boolean");
|
|
232
|
+
if (calendar.durationUnit !== void 0 && !["minutes", "hours", "days"].includes(calendar.durationUnit)) {
|
|
233
|
+
problems.push(`calendar.durationUnit "${String(calendar.durationUnit)}" isn't minutes, hours or days`);
|
|
234
|
+
}
|
|
235
|
+
if (calendar.durationUnit !== void 0 && calendar.durationField === void 0) problems.push("calendar.durationUnit needs a durationField");
|
|
201
236
|
if (calendar.laneBy !== void 0 && !byName.has(calendar.laneBy)) problems.push(`calendar.laneBy names "${calendar.laneBy}", which isn't a field`);
|
|
202
|
-
|
|
203
|
-
|
|
237
|
+
for (const key of ["layout", "phoneLayout"]) {
|
|
238
|
+
const value = calendar[key];
|
|
239
|
+
if (value !== void 0 && !LAYOUTS.includes(value)) problems.push(`calendar.${key} "${String(value)}" isn't month, weeks, agenda or lanes`);
|
|
204
240
|
}
|
|
205
241
|
if (calendar.weeks !== void 0 && ![1, 2, 3, 4].includes(calendar.weeks)) problems.push(`calendar.weeks is 1 to 4, not ${String(calendar.weeks)}`);
|
|
206
242
|
if (calendar.weekStartsOn !== void 0 && calendar.weekStartsOn !== 0 && calendar.weekStartsOn !== 1) {
|
|
@@ -208,6 +244,62 @@ function calendarProblems(fields, calendar) {
|
|
|
208
244
|
}
|
|
209
245
|
return problems;
|
|
210
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
|
+
}
|
|
211
303
|
function defineView(contract, definition = {}) {
|
|
212
304
|
const facts = contract;
|
|
213
305
|
const fields = contract.fields;
|
|
@@ -316,13 +408,42 @@ function defineView(contract, definition = {}) {
|
|
|
316
408
|
if (!rawCalendar || typeof rawCalendar !== "object" || Array.isArray(rawCalendar)) {
|
|
317
409
|
problems.push("calendar isn't an object");
|
|
318
410
|
} else {
|
|
319
|
-
const
|
|
320
|
-
for (const key of Object.keys(rawCalendar)) if (!known2.includes(key)) problems.push(`calendar.${key} isn't a calendar setting`);
|
|
411
|
+
for (const key of Object.keys(rawCalendar)) if (!CALENDAR_KEYS.includes(key)) problems.push(`calendar.${key} isn't a calendar setting`);
|
|
321
412
|
if (rawCalendar.field === void 0) problems.push("calendar.field is required");
|
|
322
413
|
calendar = Object.freeze({ ...rawCalendar });
|
|
323
414
|
problems.push(...calendarProblems(fields, calendar));
|
|
324
415
|
}
|
|
325
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
|
+
}
|
|
326
447
|
if (definition.orderBy) known(definition.orderBy.field, "orderBy");
|
|
327
448
|
for (const [name, preset] of Object.entries(presets)) {
|
|
328
449
|
if (preset.columns && preset.columns !== "default" && !own(columnLists, preset.columns)) {
|
|
@@ -375,6 +496,27 @@ function defineView(contract, definition = {}) {
|
|
|
375
496
|
const neededLink = (f) => linkEditable(f) && !f.nullable && !f.optional && !f.hasDefault && !scope.has(f.name);
|
|
376
497
|
const defaultColumns = own(columnLists, "default") ?? fields.filter((f) => !quiet(f)).map((f) => f.name);
|
|
377
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
|
+
};
|
|
378
520
|
const resolvedColumns = /* @__PURE__ */ new Map();
|
|
379
521
|
const columns = (preset = "default") => {
|
|
380
522
|
const cached = resolvedColumns.get(preset);
|
|
@@ -386,20 +528,7 @@ function defineView(contract, definition = {}) {
|
|
|
386
528
|
if (typeof column !== "string") {
|
|
387
529
|
return Object.freeze({ key: column.key, label: column.label, display: column.display ?? "text", value: column.value });
|
|
388
530
|
}
|
|
389
|
-
|
|
390
|
-
return Object.freeze({
|
|
391
|
-
key: column,
|
|
392
|
-
label: label(column),
|
|
393
|
-
display: display(column),
|
|
394
|
-
field: byName.get(column),
|
|
395
|
-
value: (row) => row[column],
|
|
396
|
-
...v?.tones ? { tones: v.tones } : {},
|
|
397
|
-
...v?.labels ? { labels: v.labels } : {},
|
|
398
|
-
...v?.labelField ? { labelField: v.labelField } : {},
|
|
399
|
-
...v?.missingLabel ? { missingLabel: v.missingLabel } : {},
|
|
400
|
-
...v?.when ? { when: (row, viewer = NO_VIEWER) => v.when(row, viewer) } : {},
|
|
401
|
-
...v?.timeZone ? { timeZone: v.timeZone } : {}
|
|
402
|
-
});
|
|
531
|
+
return fieldColumn(column);
|
|
403
532
|
})
|
|
404
533
|
);
|
|
405
534
|
resolvedColumns.set(preset, out);
|
|
@@ -478,6 +607,31 @@ function defineView(contract, definition = {}) {
|
|
|
478
607
|
const value = labelField ? row[labelField] : void 0;
|
|
479
608
|
return { title: value === null || value === void 0 || value === "" ? titleCase(noun) : String(value) };
|
|
480
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
|
+
};
|
|
481
635
|
return Object.freeze({
|
|
482
636
|
contract,
|
|
483
637
|
definition: Object.freeze({
|
|
@@ -488,7 +642,9 @@ function defineView(contract, definition = {}) {
|
|
|
488
642
|
...definition.form ? { form: formItems } : {},
|
|
489
643
|
...definition.scope ? { scope: Object.freeze([...definition.scope]) } : {},
|
|
490
644
|
...definition.actions ? { actions: actionList } : {},
|
|
491
|
-
...calendar ? { calendar } : {}
|
|
645
|
+
...calendar ? { calendar } : {},
|
|
646
|
+
...board ? { board } : {},
|
|
647
|
+
...gallery ? { gallery } : {}
|
|
492
648
|
}),
|
|
493
649
|
resource: contract.name,
|
|
494
650
|
noun,
|
|
@@ -497,6 +653,7 @@ function defineView(contract, definition = {}) {
|
|
|
497
653
|
labelField,
|
|
498
654
|
presets: presetNames,
|
|
499
655
|
field: (name) => byName.get(name),
|
|
656
|
+
column: (name) => byName.has(name) && readable(name) ? fieldColumn(name) : void 0,
|
|
500
657
|
label,
|
|
501
658
|
display,
|
|
502
659
|
valueLabel,
|
|
@@ -506,7 +663,8 @@ function defineView(contract, definition = {}) {
|
|
|
506
663
|
can,
|
|
507
664
|
actions: () => resolvedActions,
|
|
508
665
|
canAction,
|
|
509
|
-
summary
|
|
666
|
+
summary,
|
|
667
|
+
galleryItem
|
|
510
668
|
});
|
|
511
669
|
}
|
|
512
670
|
|
|
@@ -876,6 +1034,6 @@ function defineRecordView(view, definition) {
|
|
|
876
1034
|
var defineWorkspace = defineRecordView;
|
|
877
1035
|
var isWorkspace = isRecordView;
|
|
878
1036
|
|
|
879
|
-
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 };
|
|
880
1038
|
//# sourceMappingURL=index.js.map
|
|
881
1039
|
//# sourceMappingURL=index.js.map
|