@mistriwork/kit 1.0.0-rc.77 → 1.0.0-rc.79

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.
@@ -40,6 +40,11 @@
40
40
  like, on a bar with 4px to spare. */
41
41
  padding-block: var(--space-2);
42
42
  }
43
+ /* The App-wide choice's trigger is a tenant-control trigger; its word and pick take the bar's ink, not the page's
44
+ muted and body ink, which are dark on a dark ground. */
45
+ :root[data-look-bar='dark'] .app-mode .topbar .choice-control-trigger :is(bdi, .choice-control-word) {
46
+ color: inherit;
47
+ }
43
48
  :root[data-look-bar='dark'] .app-mode .topbar :is(.new-menu, .tenant-control-host) {
44
49
  align-self: center;
45
50
  }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The App's choosers, as a list can reach them. Below the width the bar holds one, a chooser leaves the bar and is an
3
+ * item of the account menu, which opens the same dialog; a list narrowed by a choice (`chosen.site`) opens it from a chip.
4
+ * Each mounted chooser says here what it shows and how to open it. Kept in the kit, which draws the chip, and read by
5
+ * the shell's account menu; the chooser itself is the shell's (ChoiceControl.tsx).
6
+ */
7
+ export interface ChoiceEntry {
8
+ /** The choice's name in `choose` (`site`), so a chip on a list it filters can open this chooser. */
9
+ readonly choice: string;
10
+ /** "Site:", the choice's name as the menu says it. */
11
+ readonly word: string;
12
+ /** The picked row's label, or the chooser's "Choose site" where nothing is picked. */
13
+ readonly name: string;
14
+ /** The picked row's label; absent where nothing is picked (or the pick is not yet read). */
15
+ readonly picked?: string;
16
+ readonly open: () => void;
17
+ }
18
+ /** Said by a chooser while it is mounted; undefined takes back the one it replaces, and only that one. */
19
+ export declare function setChoiceEntry(next: ChoiceEntry | undefined, replacing?: ChoiceEntry): void;
20
+ export declare const choiceEntries: () => readonly ChoiceEntry[];
21
+ export declare function subscribeChoiceEntries(listener: () => void): () => void;
@@ -0,0 +1,18 @@
1
+ let entries = [];
2
+ const entryListeners = new Set();
3
+ /** Said by a chooser while it is mounted; undefined takes back the one it replaces, and only that one. */
4
+ export function setChoiceEntry(next, replacing) {
5
+ const kept = replacing ? entries.filter((entry) => entry !== replacing) : entries;
6
+ if (next === undefined && kept.length === entries.length)
7
+ return;
8
+ entries = next ? [...kept, next] : kept;
9
+ for (const listener of [...entryListeners])
10
+ listener();
11
+ }
12
+ export const choiceEntries = () => entries;
13
+ export function subscribeChoiceEntries(listener) {
14
+ entryListeners.add(listener);
15
+ return () => {
16
+ entryListeners.delete(listener);
17
+ };
18
+ }
@@ -25,10 +25,13 @@ import { useMessageLanguage } from './useMessageLanguage.js';
25
25
  import { createPortal } from 'react-dom';
26
26
  import { listControlsRef, listHeadRef, useCrumbSlots } from './crumbSlot.js';
27
27
  import { FavoriteStar } from './FavoriteStar.js';
28
- import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
28
+ import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
29
29
  import { useMutation, useQueries, useQuery, useQueryClient } from '@tanstack/react-query';
30
30
  import { api, columnLabel, labelPath, pageSize, recordLabel, state as walk, toast } from '../core.js';
31
31
  import { say } from '../copy/lists/components/AppList.js';
32
+ import { choiceEntries, subscribeChoiceEntries } from '../choiceEntries.js';
33
+ import { choicesNamed } from '@mistriwork/engine/shared/queryOperands.js';
34
+ import { humanName } from '@mistriwork/engine/shared/model.js';
32
35
  import { LABEL_SEGMENT } from '@mistriwork/engine/shared/recordLabel.js';
33
36
  /* The walk's state, with the field core.js's JSDoc does not declare. */
34
37
  const state = walk;
@@ -38,7 +41,6 @@ import { splitConditions, splitQuery } from '../clauses.js';
38
41
  import { promptFor } from '../prompt.js';
39
42
  import { canonicalize, conditionTail, deriveFilterNames, mentionsColumn, ownedTails, squeeze, withCondition } from '../filterbar.js';
40
43
  import { exportOffered } from '@mistriwork/engine/shared/listPresentations.js';
41
- import { humanName } from '@mistriwork/engine/shared/model.js';
42
44
  import { pluralOf, recordNoun } from '@mistriwork/engine/shared/appNoun.js';
43
45
  import { primaryKey } from '@mistriwork/engine/shared/schema.js';
44
46
  import { findTable } from '../core.js';
@@ -333,7 +335,26 @@ export function AppList({ entry, spec, navigate, embedded = false, newButton, in
333
335
  }
334
336
  if (residueChip)
335
337
  chips.push(residueChip);
336
- const chipList = chips.map((c) => (_jsxs("span", { className: "applist-chip", title: c.text, children: [_jsx("span", { className: "applist-chip-text", children: c.text }), _jsx("button", { type: "button", className: "applist-chip-x", "aria-label": say('common.remove2', { text: c.text }), onClick: c.remove, children: "\u00D7" })] }, c.text)));
338
+ /* A choice that narrows this list (`chosen.site` in its query) is said beside what the reader applied, so a link
339
+ shared with someone who has picked another site reads as different. It has no x: the way out is another pick,
340
+ which the chip opens. Drawn from the App's declaration, so the row does not wait on the chooser mounting. */
341
+ const choosers = useSyncExternalStore(subscribeChoiceEntries, choiceEntries, () => []);
342
+ const declaredChoices = shell().app()?.choose;
343
+ const chosenChips = declaredChoices
344
+ ? choicesNamed(entry.query, appListQuery(spec, 0), ...tabs.map((_, i) => appListQuery(spec, i)))
345
+ .filter((name) => declaredChoices[name])
346
+ .map((name) => {
347
+ const chooser = choosers.find((c) => c.choice === name);
348
+ const thing = humanName(name);
349
+ const value = chooser?.picked ?? (chooser ? say('chosenNone') : '');
350
+ const text = say('chosen', { thing, value });
351
+ return (_jsx("span", { className: "applist-chip applist-chip-chosen", "data-choice": name, title: text, children: _jsxs("button", { type: "button", className: "applist-chip-text applist-chip-open", "aria-haspopup": "dialog", "aria-label": `${text}. ${say('chosenChange', { thing: thing.toLowerCase() })}`, disabled: !chooser, onClick: chooser?.open, children: [_jsx("span", { className: "applist-chip-label", children: `${thing}: ` }), _jsx("span", { className: "applist-chip-value", children: value })] }) }, `chosen-${name}`));
352
+ })
353
+ : [];
354
+ const chipList = [
355
+ ...chosenChips,
356
+ ...chips.map((c) => (_jsxs("span", { className: "applist-chip", title: c.text, children: [_jsx("span", { className: "applist-chip-text", children: c.text }), _jsx("button", { type: "button", className: "applist-chip-x", "aria-label": say('common.remove2', { text: c.text }), onClick: c.remove, children: "\u00D7" })] }, c.text))),
357
+ ];
337
358
  const isDefault = canonicalize(entry.query) === canonicalize(appListQuery(spec, 0));
338
359
  const exactTab = litTab >= 0 && canonicalize(refinement) === canonicalize(tabs[litTab].query ?? '');
339
360
  const offerSave = savable && !(isDefault || exactTab || yourLit >= 0 || !refinement);
@@ -759,7 +780,7 @@ export function AppList({ entry, spec, navigate, embedded = false, newButton, in
759
780
  [searchBox.column]: { raw },
760
781
  };
761
782
  setEdits(editsNow.current);
762
- }, onSearch: () => form.current?.requestSubmit(), apply: apply, current: currentText, residue: residueChip, listLabel: caption, phone: phone, onSheet: () => setSheet(true) })), spec.sorts?.length && !beside ? (_jsx(SortMenu, { sorts: spec.sorts, sort: spec.sort, query: entry.query, onPick: (query) => {
783
+ }, onSearch: () => form.current?.requestSubmit(), apply: apply, current: currentText, residue: residueChip, chosen: chosenChips, listLabel: caption, phone: phone, onSheet: () => setSheet(true) })), spec.sorts?.length && !beside ? (_jsx(SortMenu, { sorts: spec.sorts, sort: spec.sort, query: entry.query, onPick: (query) => {
763
784
  walk.page = 0;
764
785
  navigate(query);
765
786
  } })) : null, _jsxs("div", { className: "applist-actions", children: [boardable && _jsx(LayoutSwitch, { layout: layout, onChange: setLayout, label: say('layout', { caption }) }), railed && railNarrow && railProps && boxes.length > 0 && (_jsx("button", { type: "button", className: "applist-toggle", "aria-haspopup": "dialog", onClick: () => setSheet(true), children: narrowed ? say('common.filters', { narrowed }) : say('common.filtersButton') })), spec.advancedFilters === true && boxes.length > 0 && (_jsx("button", { type: "button", className: "applist-toggle", "aria-expanded": showAdvanced, onClick: () => {
@@ -67,6 +67,9 @@
67
67
  border: 0; border-radius: var(--radius); background: none; color: inherit; font: inherit; cursor: pointer;
68
68
  }
69
69
  .applist-chip-open:hover { color: var(--accent-ink); }
70
+ /* A choice's chip has no x: its words are the whole of it, and open the chooser. */
71
+ .applist-fields .applist-chip-chosen { padding-right: 0; }
72
+ .applist-chip-chosen .applist-chip-open:disabled { cursor: default; }
70
73
  .applist-fields .applist-chip-x { min-width: 24px; min-height: 24px; font-size: var(--text-md); }
71
74
  .applist-bar-chips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2h); flex-basis: 100%; }
72
75
  .applist-bar-chips:empty { display: none; }
@@ -1,3 +1,27 @@
1
+ /**
2
+ * An App list's filters as controls, not a form: the bar a list draws above
3
+ * its rows unless its view says `filterBar: 'rail'` or `'none'`.
4
+ *
5
+ * The bar was a form — an empty box or Select per filter, then Filter, then
6
+ * Advanced — the heaviest thing above a quiet table, and on a phone more than
7
+ * half the first screen. So the list's name column keeps one search box, a
8
+ * real field with the 3:1 edge; every other filter the view declares is a
9
+ * quiet "Status ▾" that opens, in a popover, the picker the rail draws for it
10
+ * (a checklist, Min/Max, date presets; a reference is the typeahead its box
11
+ * was); and what is applied is said in the same row as chips, each in its
12
+ * filter's place and under its filter's label ("Status: Open +1"): a chip
13
+ * opens its picker again, its × (or Backspace) takes it out, and two or more
14
+ * earn one Clear all. On a phone the pickers are the
15
+ * rail's sheet, behind one Filters button that says how many apply.
16
+ *
17
+ * No picker writes a new kind of question. Each hands a condition tail to
18
+ * withCondition, as the boxes and the rail do, so a chip, the address
19
+ * (publicAddress.ts), a saved view and the crumb read it as they always did.
20
+ * A picker edits a draft and applies it with one button: every navigation
21
+ * redraws the list, and a popover that applied each tick would close under
22
+ * the reader's second one.
23
+ */
24
+ import { type ReactNode } from 'react';
1
25
  import { type TableMeta } from '@mistriwork/engine/shared/schema.js';
2
26
  import { type Box } from './FilterBoxes.js';
3
27
  import { type FacetUnit } from './FilterRail.js';
@@ -28,6 +52,8 @@ interface ListFilterBarProps {
28
52
  text: string;
29
53
  remove: () => void;
30
54
  };
55
+ /** The choices that narrow the list (`chosen.site`): standing chips with no x, which open the chooser. */
56
+ chosen?: ReactNode;
31
57
  /** The list's own name, for the search box's words: "Search issues…". */
32
58
  listLabel: string;
33
59
  phone: boolean;
@@ -117,13 +117,13 @@ export function ListFilterBar(props) {
117
117
  if (phone) {
118
118
  /* The search stays in reach; the pickers are one button, and the chips
119
119
  wrap under the box rather than pushing it off the row. */
120
- return (_jsxs(_Fragment, { children: [searchBox, pickers.length > 0 && (_jsx("button", { type: "button", className: "applist-add applist-sheet-open", "aria-haspopup": "dialog", onClick: onSheet, children: narrowed ? say('common.filters', { narrowed }) : say('common.filtersButton') })), _jsxs("div", { className: "applist-bar-chips", children: [search && _jsx(FilterSlot, { ...props, box: search, chipOnly: true }), pickers.map((box) => (_jsx(FilterSlot, { ...props, box: box, chipOnly: true }, box.column))), residueChip, clearAll] })] }));
120
+ return (_jsxs(_Fragment, { children: [searchBox, pickers.length > 0 && (_jsx("button", { type: "button", className: "applist-add applist-sheet-open", "aria-haspopup": "dialog", onClick: onSheet, children: narrowed ? say('common.filters', { narrowed }) : say('common.filtersButton') })), _jsxs("div", { className: "applist-bar-chips", children: [search && _jsx(FilterSlot, { ...props, box: search, chipOnly: true }), pickers.map((box) => (_jsx(FilterSlot, { ...props, box: box, chipOnly: true }, box.column))), props.chosen, residueChip, clearAll] })] }));
121
121
  }
122
122
  const rest = idle.filter((box) => hidden.has(box.column));
123
123
  const heldSet = rest.filter((box) => facetActive(refinement, box.column, tabQuery)).length;
124
124
  return (_jsxs(_Fragment, { children: [_jsx("span", { ref: mark, hidden: true }), searchBox, search && _jsx(FilterSlot, { ...props, box: search }), pickers
125
125
  .filter((box) => !hidden.has(box.column))
126
- .map((box) => (_jsx(FilterSlot, { ...props, box: box }, box.column))), rest.length > 0 && (_jsx("span", { className: "applist-slot applist-slot-more", children: _jsxs("button", { type: "button", className: "applist-add", "aria-haspopup": "dialog", "aria-label": say('moreFilters', { filter: say('moreFiltersButton'), map: rest.map((box) => box.label).join(', ') }), onClick: onSheet, children: [say('moreFiltersButton'), heldSet > 0 && _jsx("span", { className: "applist-add-count", children: heldSet }), _jsx("span", { className: "applist-add-mark", "aria-hidden": "true", children: "\u25BE" })] }) })), residueChip, clearAll] }));
126
+ .map((box) => (_jsx(FilterSlot, { ...props, box: box }, box.column))), rest.length > 0 && (_jsx("span", { className: "applist-slot applist-slot-more", children: _jsxs("button", { type: "button", className: "applist-add", "aria-haspopup": "dialog", "aria-label": say('moreFilters', { filter: say('moreFiltersButton'), map: rest.map((box) => box.label).join(', ') }), onClick: onSheet, children: [say('moreFiltersButton'), heldSet > 0 && _jsx("span", { className: "applist-add-count", children: heldSet }), _jsx("span", { className: "applist-add-mark", "aria-hidden": "true", children: "\u25BE" })] }) })), props.chosen, residueChip, clearAll] }));
127
127
  }
128
128
  /**
129
129
  * One declared filter in its place in the row: its chip when it narrows the
@@ -55,7 +55,7 @@ import { defaultCurrency } from '../locale.js';
55
55
  import { wordFor } from './valueModel.js';
56
56
  import { majorText, minorToMajor, rowCurrency } from '@mistriwork/engine/shared/money.js';
57
57
  import { MinorMoneyInput, minorProblem } from './MinorMoneyInput.js';
58
- import { clockDefault, fieldInput, inferredNarrowing, flagStart, formColumns, formFrame, formGroups, hasFormChanges, insertValues, isFormFieldVisible, missingFields, narrowingCondition, presetValue, SEGMENTED_WORDS, withDisplayChoices, } from './newRecordModel.js';
58
+ import { clockDefault, fieldInput, inferredNarrowing, flagStart, formColumns, formFrame, formGroups, hasFormChanges, insertValues, isFormFieldVisible, missingFields, narrowingCondition, presetValue, chosenDefaults, SEGMENTED_WORDS, withDisplayChoices, } from './newRecordModel.js';
59
59
  import { derivedValue, formWords, resolvedForm, useMeDefaults } from './formDefaults.js';
60
60
  import { useRecordInsert } from './useRecordInsert.js';
61
61
  import { say } from '../copy/forms/components/NewRecord.js';
@@ -122,6 +122,9 @@ function NewRecordFormBody({ table, form, app, label: columnLabel, target, inser
122
122
  return start === undefined ? [] : [[column.name, start]];
123
123
  })
124
124
  : [];
125
+ /* A reference to the App's chosen row (`choose`: the site the person works at) starts at it, read once as the form
126
+ opens: a pick changed while it is open never replaces what the form holds (newRecordModel.ts chosenDefaults). */
127
+ const [chosen] = useState(() => (app ? chosenDefaults(columns, shell().app()?.choose, shell().chosen(), target) : {}));
125
128
  /* A vocabulary opens on the choice the database would write (`default 'booked'`), unless the form says another. */
126
129
  const defaults = {
127
130
  ...Object.fromEntries(flags),
@@ -133,6 +136,7 @@ function NewRecordFormBody({ table, form, app, label: columnLabel, target, inser
133
136
  clockDefault('now', column, new Date(), formatClockZone()),
134
137
  ]))
135
138
  : {}),
139
+ ...chosen,
136
140
  ...(form?.defaults ?? {}),
137
141
  };
138
142
  const switches = new Set(flags.map(([name]) => name));
@@ -5,7 +5,7 @@
5
5
  * and what is missing or changed before the values are written.
6
6
  */
7
7
  import { type ColumnMeta, type TableMeta } from '@mistriwork/engine/shared/schema.js';
8
- import type { AppForm } from '@mistriwork/engine/shared/servedApp.js';
8
+ import type { AppForm, ServedChoice } from '@mistriwork/engine/shared/servedApp.js';
9
9
  import { type FormScalar } from '@mistriwork/engine/shared/formValues.js';
10
10
  /** The client-side presentation subset of an authored App form. */
11
11
  export type FormCuration = Omit<AppForm<string>, 'defaults'> & {
@@ -74,6 +74,13 @@ export declare function fieldInput(column: ColumnMeta, options: {
74
74
  export declare function clockDefault(word: 'today' | 'now', column: ColumnMeta, now: Date, timeZone?: string): string;
75
75
  /** The choices a narrowed reference offers, in the query language: `project_id = 4`; undefined while a field it reads is empty. */
76
76
  export declare function narrowingCondition(where: Readonly<Record<string, string>> | undefined, values: Readonly<Record<string, unknown>>): string | undefined;
77
+ /**
78
+ * Where a New form's references start from the App's choices (`choose`): a reference to the chosen table, by its key,
79
+ * starts at the pick, so a visit booked at a site the person works at names that site without being asked. It is a
80
+ * start like any default, below the form's own (a parent's key, a declared default): the field is the person's to
81
+ * change, and the form reads this once, so a pick changed while the form is open never replaces what it holds.
82
+ */
83
+ export declare function chosenDefaults(columns: readonly ColumnMeta[], choose: Readonly<Record<string, ServedChoice>> | undefined, chosen: Readonly<Record<string, string>>, target: (tableId: string) => TableMeta | undefined): Record<string, string>;
77
84
  /**
78
85
  * The pickers a form narrows by an earlier pick where the App's form says nothing (`fields.<column>.where`): a
79
86
  * reference whose table points at the table of a required reference asked before it, by exactly one column, offers
@@ -4,7 +4,7 @@
4
4
  * start), the control each field gets, how an earlier pick narrows a later one, whether it opens as a drawer or a page,
5
5
  * and what is missing or changed before the values are written.
6
6
  */
7
- import { coerceForColumn, columnKind, isFlagColumn } from '@mistriwork/engine/shared/schema.js';
7
+ import { coerceForColumn, columnKind, isFlagColumn, primaryKey, } from '@mistriwork/engine/shared/schema.js';
8
8
  import { appNow } from '../locale.js';
9
9
  import { autoKey, formShownFields, isRequired } from '@mistriwork/engine/shared/form.js';
10
10
  import { evaluateFormCondition, typedValue } from '@mistriwork/engine/shared/formValues.js';
@@ -244,6 +244,28 @@ export function narrowingCondition(where, values) {
244
244
  }
245
245
  return clauses.join(' and ');
246
246
  }
247
+ /**
248
+ * Where a New form's references start from the App's choices (`choose`): a reference to the chosen table, by its key,
249
+ * starts at the pick, so a visit booked at a site the person works at names that site without being asked. It is a
250
+ * start like any default, below the form's own (a parent's key, a declared default): the field is the person's to
251
+ * change, and the form reads this once, so a pick changed while the form is open never replaces what it holds.
252
+ */
253
+ export function chosenDefaults(columns, choose, chosen, target) {
254
+ const out = {};
255
+ for (const [name, choice] of Object.entries(choose ?? {})) {
256
+ const value = chosen[name];
257
+ const into = value ? target(choice.table) : undefined;
258
+ const keys = into ? primaryKey(into) : [];
259
+ if (keys.length !== 1)
260
+ continue;
261
+ for (const column of columns) {
262
+ const ref = column.references;
263
+ if (ref?.table === choice.table && ref.column === keys[0] && !Object.hasOwn(out, column.name))
264
+ out[column.name] = value;
265
+ }
266
+ }
267
+ return out;
268
+ }
247
269
  /**
248
270
  * The pickers a form narrows by an earlier pick where the App's form says nothing (`fields.<column>.where`): a
249
271
  * reference whose table points at the table of a required reference asked before it, by exactly one column, offers
@@ -28,4 +28,7 @@ export declare const say: import("../../../messages.js").RoomMessage<{
28
28
  readonly captionFilters: "{caption} filters";
29
29
  readonly everything: "Everything";
30
30
  readonly layout: "Show {caption} as";
31
+ readonly chosen: "{thing}: {value}";
32
+ readonly chosenNone: "none";
33
+ readonly chosenChange: "Change {thing}";
31
34
  }>;
@@ -30,4 +30,7 @@ export const say = defineMessages({
30
30
  captionFilters: '{caption} filters',
31
31
  everything: 'Everything',
32
32
  layout: 'Show {caption} as',
33
+ chosen: '{thing}: {value}',
34
+ chosenNone: 'none',
35
+ chosenChange: 'Change {thing}',
33
36
  });
@@ -202,6 +202,8 @@ async function sent(path, body, headers) {
202
202
  composedReads()?.forget();
203
203
  }
204
204
  }
205
+ /* The header an App's picks are sent in (server/app/appChoices.ts). */
206
+ const CHOSEN_HEADER = 'x-mistri-chosen';
205
207
  /**
206
208
  * @param {string} path
207
209
  * @param {Record<string, unknown> | undefined} body
@@ -209,6 +211,11 @@ async function sent(path, body, headers) {
209
211
  * @returns {Promise<any>}
210
212
  */
211
213
  async function request(path, body, headers) {
214
+ /* The App-wide picks ride every request (an App's `choose`): the server reads each row again under the reader, so
215
+ the header is a wish and never a grant. A caller's own header of the same name wins. */
216
+ const chosen = new URLSearchParams(shell().chosen()).toString();
217
+ if (chosen)
218
+ headers = { [CHOSEN_HEADER]: chosen, ...headers };
212
219
  const parsedPath = new URL(path, window.location.href);
213
220
  if (!path.startsWith('/api/') || parsedPath.hash || parsedPath.pathname !== path.split('?')[0]) {
214
221
  throw Object.assign(new Error(say('useACanonicalApi')), { outcome: 'not_applied' });
@@ -11,6 +11,7 @@
11
11
  import { FIRST_PAINT_ELEMENT, itemKey, readKey, } from '@mistriwork/engine/shared/firstPaint.js';
12
12
  import { sessionIdentity } from './sessionIdentity.js';
13
13
  import { shellById } from './shellHost.js';
14
+ import { shell } from './shellMode.js';
14
15
  /* Long enough for the first room and what it asks as it draws, and no
15
16
  longer: past it every read is the reader's own again. */
16
17
  const LIFETIME = 15_000;
@@ -48,6 +49,14 @@ function held() {
48
49
  }
49
50
  if (!owner && identity.mode !== 'unknown')
50
51
  owner = identity;
52
+ /* The page was drawn for the pick the server holds for this person (an App's `choose`, read from their store as the
53
+ page's reads were asked), so a person with a stored pick keeps first paint: nothing waits on one. Only a tab that
54
+ differs from it, or one with no store to hold it, sends a pick of its own (`chosen()` is that difference), and
55
+ none of the page's answers is that tab's: every one is asked again. */
56
+ if (Object.keys(shell().chosen()).length) {
57
+ data = null;
58
+ return null;
59
+ }
51
60
  return data;
52
61
  }
53
62
  /** The answer the page carries for this request, once, or undefined. */
@@ -6,6 +6,7 @@
6
6
  * write.js re-exports both; the rules are these, once.
7
7
  */
8
8
  import { isAppendOnly } from '@mistriwork/engine/shared/schema.js';
9
+ import { rowMeetsCondition } from '@mistriwork/engine/shared/rowCondition.js';
9
10
  import { prefersPages, state, writeAllowed } from './core.js';
10
11
  import { planColumn } from './columns.js';
11
12
  import { pageBridge } from './uiBridge.js';
@@ -26,17 +27,21 @@ export function booleanChoices(column, row) {
26
27
  return /bool/i.test(column?.type ?? '') ? { yes: 'true', no: 'false' } : { yes: '1', no: '0' };
27
28
  }
28
29
  /**
29
- * Whether the row is in a state its machine freezes (`final: { freeze: true }`): the server refuses every write to it,
30
- * so no editor is offered. Judged from the row's own state, which a row that does not carry the column cannot say.
30
+ * Whether the row is frozen: in a state its machine freezes (`final: { freeze: true }`), or matching its resource's
31
+ * `frozen` condition. The server refuses every write to it, so no editor is offered. Judged from the row's own values,
32
+ * which a row that does not carry a column cannot say (the server's refusal then stands, a 409 `frozen`).
31
33
  */
32
34
  function frozenRow(tableId, row) {
33
35
  if (!row)
34
36
  return false;
35
37
  const app =
36
- /** @type {{ resources?: Record<string, { machine?: import('@mistriwork/engine/shared/servedApp.js').ServedMachine }> } | null} */ (pageBridge.activeApp());
37
- const machine = app?.resources?.[tableId]?.machine;
38
+ /** @type {{ resources?: Record<string, { frozen?: string, machine?: import('@mistriwork/engine/shared/servedApp.js').ServedMachine }> } | null} */ (pageBridge.activeApp());
39
+ const resource = app?.resources?.[tableId];
40
+ const machine = resource?.machine;
38
41
  const value = machine ? row[machine.column] : undefined;
39
- return (machine !== undefined && value !== undefined && value !== null && machine.states.some((s) => s.freeze && s.value === String(value)));
42
+ if (machine !== undefined && value !== undefined && value !== null && machine.states.some((s) => s.freeze && s.value === String(value)))
43
+ return true;
44
+ return typeof resource?.frozen === 'string' && rowMeetsCondition(state.schema, tableId, resource.frozen, row);
40
45
  }
41
46
  /** True when this row can be edited at all: write mode on, and a full key; a frozen row (`row`, where the caller has it) is not. */
42
47
  export function canEditRow(table, key, row) {
@@ -153,6 +153,9 @@ export interface ShellMode {
153
153
  unauthorized(info: unknown): void;
154
154
  /** Draw the App's sign-in in place, so a signed-out visitor comes back to this address (publicSurface.js); a no-op where none signs in. */
155
155
  signInHere(appId: string): void;
156
+ /** The App-wide rows this tab has picked (an App's `choose`), each name's key as text: sent with every request as
157
+ `x-mistri-chosen`, and believed only once the server has read the row again. None in the Workbench. */
158
+ chosen(): Readonly<Record<string, string>>;
156
159
  /** A tenant session's requests, or null where there is no tenant. */
157
160
  tenant: TenantRequests | null;
158
161
  tenantLinks: TenantLinks | null;
@@ -1,5 +1,6 @@
1
1
  const none = () => false;
2
2
  const NOTHING_REACHABLE = new Set();
3
+ const NOTHING_CHOSEN = Object.freeze({});
3
4
  const WORKBENCH = Object.freeze({
4
5
  app: () => null,
5
6
  inApp: none,
@@ -20,6 +21,7 @@ const WORKBENCH = Object.freeze({
20
21
  peekRecord: null,
21
22
  unauthorized: () => { },
22
23
  signInHere: () => { },
24
+ chosen: () => NOTHING_CHOSEN,
23
25
  tenant: null,
24
26
  tenantLinks: null,
25
27
  mutations: Object.freeze({ start: () => undefined, unknown: none, settle: none, hasUnresolved: none }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mistriwork/kit",
3
- "version": "1.0.0-rc.77",
3
+ "version": "1.0.0-rc.79",
4
4
  "description": "The shared React client both shells are drawn with: the walk and the address, Grid, Value, the record page, lists, filters and charts.",
5
5
  "homepage": "https://mistriwork.dev",
6
6
  "bugs": {
@@ -85,8 +85,8 @@
85
85
  "./package.json": "./package.json"
86
86
  },
87
87
  "dependencies": {
88
- "@mistriwork/engine": "1.0.0-rc.77",
89
- "@mistriwork/ui": "1.0.0-rc.77",
88
+ "@mistriwork/engine": "1.0.0-rc.79",
89
+ "@mistriwork/ui": "1.0.0-rc.79",
90
90
  "intl-messageformat": "12.1.2",
91
91
  "qrcode-generator": "^2.0.4"
92
92
  },