@sincpro/web-composer 1.4.0 → 1.5.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 +11 -2
- package/dist/domain/index.d.ts +1 -1
- package/dist/domain/registry.d.ts +22 -2
- package/dist/index.d.ts +1 -1
- package/dist/shell/styles.js +3 -0
- package/dist/state/api.js +30 -6
- package/dist/state/testing.d.ts +5 -2
- package/dist/state/testing.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,14 +109,23 @@ api.pick(ref, onPick); // open a chooser (a many2one search); its view calls api
|
|
|
109
109
|
api.pick(ref, onPick, { to: "modal" }); // the chooser as a modal over the form
|
|
110
110
|
api.pick(ref, onPick, { size: { w: 720, h: 520 } }); // a chooser window at that size (480×360 without it)
|
|
111
111
|
api.pick<boolean>(confirmRef, (ok) => ok && post(), { to: "modal" }); // any value, not only a ref
|
|
112
|
+
api.pick(ref, onPick, { question: { chosen } }); // what the chooser is asked, in memory
|
|
113
|
+
api.choosing; // in the chooser: { question } while someone waits for its answer; null when opened to look
|
|
112
114
|
```
|
|
113
115
|
|
|
116
|
+
A **chooser** knows it is one: `api.choosing` says it was opened by `pick` and what it was asked,
|
|
117
|
+
so the same list draws a «Choose» per row or rows that open, with no flag in its reference. The
|
|
118
|
+
question lives exactly as long as the wait for the answer — in memory, like the answer — and so
|
|
119
|
+
does `choosing`: a link or a reload opens the view to look at it. What must survive those (a
|
|
120
|
+
filter, a company, a default) is not a question: it goes in `params`.
|
|
121
|
+
|
|
114
122
|
A **modal** belongs to the surface it covers — the page, a window, a side panel or the peek —
|
|
115
123
|
and blocks only that one: the rest of the workspace keeps answering, and a window keeps moving
|
|
116
124
|
and closing by its own title bar. One per surface: opening another one over the same surface,
|
|
117
125
|
or from inside it, replaces it. When its surface shows another record or closes, the modal goes
|
|
118
126
|
with it (asking first if something was typed). What it shares with whoever opened it travels in
|
|
119
|
-
its reference (`params`)
|
|
127
|
+
its reference (`params`) — or, for a chooser, in its `question` — and comes back with
|
|
128
|
+
`api.answer`; `api.over` says what it covers. No
|
|
120
129
|
blur unless asked.
|
|
121
130
|
|
|
122
131
|
**On a phone** — when the workspace is narrower than 640 px (`<Composer phoneBelow>`, `0` never)
|
|
@@ -251,7 +260,7 @@ store, no shell, no browser:
|
|
|
251
260
|
```ts
|
|
252
261
|
import { createTestApi } from "@sincpro/web-composer";
|
|
253
262
|
|
|
254
|
-
const t = createTestApi(invoiceRef("F-1")); // { surface, over, crumbs, selection } optional
|
|
263
|
+
const t = createTestApi(invoiceRef("F-1")); // { surface, over, crumbs, selection, choosing } optional
|
|
255
264
|
render(<Invoice resource={t.api.self} api={t.api} />);
|
|
256
265
|
// … click «Register payment»
|
|
257
266
|
expect(t.callsTo("open")[0].args).toEqual([paymentRef("F-1"), { to: "modal" }]);
|
package/dist/domain/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { Axis, Destination, DOCKS, DragKind, HandleKind, Surface, Zone, } from "
|
|
|
4
4
|
export { type Box, type Handle, handles, KEYBOARD_STEP, layout, type Length, phoneLayout, resolve, sizeAt, type Slot, stableOrder, STRIP, ZONE_LIMITS, } from "./layout.js";
|
|
5
5
|
export { localEntries, matches, MIN_QUERY, type PaletteEntry, PaletteSection, searchEntries, } from "./palette.js";
|
|
6
6
|
export { chooserOnPhone, destinationOnPhone, PHONE_WIDTH, } from "./phone.js";
|
|
7
|
-
export { type Action, createRegistry, type Crumb, loadView, type OpenOptions, type PickOptions, type Registry, type SearchHit, type ViewProps, type ViewSpec, type WorkspaceApi, } from "./registry.js";
|
|
7
|
+
export { type Action, type Choosing, createRegistry, type Crumb, loadView, type OpenOptions, type PickOptions, type Registry, type SearchHit, type ViewProps, type ViewSpec, type WorkspaceApi, } from "./registry.js";
|
|
8
8
|
export { formatRef, isRef, parseRef, type ResourceRef, rootRef, sameRef, withParams, } from "./resource.js";
|
|
9
9
|
export { fromHash, restore, type SessionMemory, toHash, } from "./url.js";
|
|
10
10
|
export { back, closeModal, closePanel, closePeek, collapsePanel, cycleFocus, DEFAULT_ZONES, drillPeek, EMPTY, expandPanel, findPanel, floatPanel, focusedRef, focusPanel, goTo, hostOf, MAX_ZONE, maximize, MIN_SHARE, MIN_WINDOW, MIN_ZONE, MODAL, type Modal, modalId, modalOver, movePanel, nameOf, nameRef, navigatePanel, openModal, type OpenModalOptions, openPanel, type OpenPanelOptions, PAGE, type Panel, panelsIn, PEEK, peek, peekBack, peekGoTo, peekToPage, peekToSide, type Placement, push, raisePanel, refOn, replace, replacePeek, resizePanel, resizeZone, select, type Selected, selectionOf, settleModals, type Size, start, type WindowBox, type Workspace, type Zones, } from "./workspace.js";
|
|
@@ -24,6 +24,16 @@ export type PickOptions = {
|
|
|
24
24
|
blur?: boolean;
|
|
25
25
|
/** A window or a modal: the size the chooser opens at, in pixels. */
|
|
26
26
|
size?: Size;
|
|
27
|
+
/**
|
|
28
|
+
* What the chooser is asked, beyond what it shows: the ids already chosen, the amount to
|
|
29
|
+
* suggest. Any value, in memory — it lives exactly as long as the wait for the answer, like the
|
|
30
|
+
* answer itself. What must survive a reload or a link (a filter, a company) goes in `params`.
|
|
31
|
+
*/
|
|
32
|
+
question?: unknown;
|
|
33
|
+
};
|
|
34
|
+
/** Why a view was opened when it was opened to answer: what `pick` asked it. */
|
|
35
|
+
export type Choosing = {
|
|
36
|
+
question: unknown;
|
|
27
37
|
};
|
|
28
38
|
/** One step of a breadcrumb, ready for `List.Crumbs` or `Record.Crumbs`. */
|
|
29
39
|
export type Crumb = {
|
|
@@ -101,13 +111,23 @@ export type WorkspaceApi = {
|
|
|
101
111
|
* Open `ref` as a chooser: when its view calls `answer`, `onPick` receives the value and the
|
|
102
112
|
* chooser closes. The value is a reference by default — a many2one — but it can be anything
|
|
103
113
|
* the chooser's view answers: `true` for a confirmation, a date range, an amount. Closed
|
|
104
|
-
* without an answer, `onPick` is never called.
|
|
114
|
+
* without an answer, `onPick` is never called. `question` reaches the chooser as
|
|
115
|
+
* `api.choosing.question`.
|
|
105
116
|
*
|
|
106
117
|
* api.pick<boolean>(confirmRef, (ok) => ok && post(), { to: Destination.Modal });
|
|
118
|
+
* api.pick(chooserRef, fill, { to: Destination.Modal, question: { chosen: ids } });
|
|
107
119
|
*/
|
|
108
120
|
pick: <T = ResourceRef>(ref: ResourceRef, onPick: (value: T) => void, options?: PickOptions) => void;
|
|
121
|
+
/**
|
|
122
|
+
* Opened by `pick`, waiting for an answer: what it was asked. `null` when it was opened to be
|
|
123
|
+
* looked at — `open`, a link, a reload: the wait does not survive one, so neither does this.
|
|
124
|
+
* The same view can draw itself to choose (a «Choose» per row) or to read (rows that open).
|
|
125
|
+
* It stays while the chooser filters or drills (`setParams`, `navigate`) and goes when it
|
|
126
|
+
* answers or closes.
|
|
127
|
+
*/
|
|
128
|
+
choosing: Choosing | null;
|
|
109
129
|
/** From a chooser: deliver the value to whoever asked, and close this surface. Nobody asked
|
|
110
|
-
* (
|
|
130
|
+
* (`choosing` is `null`): nothing happens. */
|
|
111
131
|
answer: (value: unknown) => void;
|
|
112
132
|
};
|
|
113
133
|
/** Named `resource` rather than `ref` because `ref` is a reserved React prop. */
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* Only the model TYPES that appear in these signatures are re-exported, so declaring a domain
|
|
7
7
|
* does not force a two-place import.
|
|
8
8
|
*/
|
|
9
|
-
export type { Action, Crumb, OpenOptions, PaletteEntry, PickOptions, Registry, ResourceRef, SearchHit, ViewProps, ViewSpec, Workspace, WorkspaceApi, } from "./domain/index.js";
|
|
9
|
+
export type { Action, Choosing, Crumb, OpenOptions, PaletteEntry, PickOptions, Registry, ResourceRef, SearchHit, ViewProps, ViewSpec, Workspace, WorkspaceApi, } from "./domain/index.js";
|
|
10
10
|
export { Destination, focusedRef, PAGE, PaletteSection, PEEK, selectionOf, Surface, Zone, } from "./domain/index.js";
|
|
11
11
|
export { Composer, type ComposerProps } from "./shell/Composer.js";
|
|
12
12
|
export { type ComposerCopy, composerCopy, ENGLISH_COMPOSER_COPY, installComposerCopy, SPANISH_COMPOSER_COPY, } from "./shell/copy.js";
|
package/dist/shell/styles.js
CHANGED
|
@@ -51,6 +51,9 @@ const CSS = `
|
|
|
51
51
|
}
|
|
52
52
|
.sc-root *, .sc-root *::before, .sc-root *::after { box-sizing: border-box; }
|
|
53
53
|
.sc-root :focus-visible { outline: 2px solid var(--_accent); outline-offset: 1px; }
|
|
54
|
+
/* A modal takes the focus when it opens so that it is announced, not to be pointed at: the
|
|
55
|
+
ring on the whole dialog read as a thick coloured border. The controls inside keep theirs. */
|
|
56
|
+
.sc-root .sc-modal:focus-visible { outline: 0; }
|
|
54
57
|
.sc-root :is(.sc-control, .sc-button, .sc-menu-item, .sc-palette-search, .sc-option-icon) svg {
|
|
55
58
|
flex-shrink: 0; width: var(--_icon); height: var(--_icon);
|
|
56
59
|
}
|
package/dist/state/api.js
CHANGED
|
@@ -37,6 +37,16 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
37
37
|
if (model.refOn(w, key) === null)
|
|
38
38
|
cache.delete(key);
|
|
39
39
|
});
|
|
40
|
+
/** `id` now waits for an answer, or no longer does. Its API is built again: `choosing` is a
|
|
41
|
+
* value read in render, and the surface may keep showing the same resource. */
|
|
42
|
+
function ask(id, pending) {
|
|
43
|
+
choosers.set(id, pending);
|
|
44
|
+
cache.delete(id);
|
|
45
|
+
}
|
|
46
|
+
function forget(id) {
|
|
47
|
+
if (choosers.delete(id))
|
|
48
|
+
cache.delete(id);
|
|
49
|
+
}
|
|
40
50
|
const context = {
|
|
41
51
|
focused: () => model.focusedRef(store.get()),
|
|
42
52
|
selection: () => model.selectionOf(store.get()),
|
|
@@ -56,8 +66,14 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
56
66
|
const m = model.modalOver(store.get(), model.hostOf(me));
|
|
57
67
|
return { blur: m?.blur ?? false, ...(m?.size === undefined ? {} : { size: m.size }) };
|
|
58
68
|
};
|
|
69
|
+
/** A fresh modal or peek opened from OUTSIDE it is not the chooser that was there: whoever
|
|
70
|
+
* waited for that one is not waiting for this. From inside, it is the chooser drilling. */
|
|
59
71
|
function open(ref, asked, { blur, size } = {}) {
|
|
60
72
|
const to = isPhone() ? model.destinationOnPhone(asked) : asked;
|
|
73
|
+
if (to === Destination.Modal && !inModal)
|
|
74
|
+
forget(model.modalId(model.hostOf(me)));
|
|
75
|
+
if (to === Destination.Peek && !inPeek)
|
|
76
|
+
forget(PEEK);
|
|
61
77
|
if (to === Destination.Modal)
|
|
62
78
|
store.openModal(me, ref, {
|
|
63
79
|
...(blur === undefined ? {} : { blur }),
|
|
@@ -129,6 +145,10 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
129
145
|
surface: target.surface,
|
|
130
146
|
over: inModal ? (model.modalOver(store.get(), target.host)?.over ?? null) : null,
|
|
131
147
|
context,
|
|
148
|
+
choosing: (() => {
|
|
149
|
+
const pending = choosers.get(me);
|
|
150
|
+
return pending === undefined ? null : { question: pending.question };
|
|
151
|
+
})(),
|
|
132
152
|
open: (ref, options) => open(ref, options?.to ??
|
|
133
153
|
(inPeek && defaultOpen === Destination.Page ? Destination.Peek : defaultOpen), options),
|
|
134
154
|
navigate: (to) => {
|
|
@@ -179,30 +199,34 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
179
199
|
setDirty: (dirty) => store.setDirty(me, resource, dirty),
|
|
180
200
|
select: (refs) => store.apply((w) => model.select(w, me, refs)),
|
|
181
201
|
pick: (ref, onPick, options) => {
|
|
202
|
+
const pending = {
|
|
203
|
+
onPick: onPick,
|
|
204
|
+
question: options?.question,
|
|
205
|
+
};
|
|
182
206
|
const asked = options?.to ?? Destination.Window;
|
|
183
207
|
const to = isPhone() ? model.chooserOnPhone(asked) : asked;
|
|
184
208
|
if (to === Destination.Modal) {
|
|
185
209
|
open(ref, to, options);
|
|
186
|
-
|
|
210
|
+
ask(model.modalId(model.hostOf(me)), pending);
|
|
187
211
|
return;
|
|
188
212
|
}
|
|
189
213
|
if (to === Destination.Peek) {
|
|
190
214
|
store.peek(ref);
|
|
191
|
-
|
|
215
|
+
ask(PEEK, pending);
|
|
192
216
|
return;
|
|
193
217
|
}
|
|
194
218
|
open(ref, to, options);
|
|
195
219
|
const id = store.get().focus;
|
|
196
220
|
if (id !== PAGE && id !== PEEK)
|
|
197
|
-
|
|
221
|
+
ask(id, pending);
|
|
198
222
|
},
|
|
199
223
|
answer: (value) => {
|
|
200
|
-
const
|
|
201
|
-
if (
|
|
224
|
+
const pending = choosers.get(me);
|
|
225
|
+
if (pending === undefined)
|
|
202
226
|
return;
|
|
203
227
|
/* Forget it BEFORE closing, so closing is not mistaken for anything else. */
|
|
204
228
|
choosers.delete(me);
|
|
205
|
-
onPick(value);
|
|
229
|
+
pending.onPick(value);
|
|
206
230
|
if (inModal)
|
|
207
231
|
store.closeModal(me);
|
|
208
232
|
else if (inPeek)
|
package/dist/state/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type Crumb, type ResourceRef, Surface, type WorkspaceApi } from "../domain/index.js";
|
|
1
|
+
import { type Choosing, type Crumb, type ResourceRef, Surface, type WorkspaceApi } from "../domain/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* An `api` for testing a view WITHOUT a workspace: it does nothing, and remembers every call. A
|
|
4
4
|
* view only talks to the workspace through its `api`, so what it asked for is what a test checks —
|
|
@@ -9,7 +9,8 @@ import { type Crumb, type ResourceRef, Surface, type WorkspaceApi } from "../dom
|
|
|
9
9
|
* // … click «Register payment»
|
|
10
10
|
* expect(t.calls).toContainEqual({ method: "open", args: [paymentRef("F-1"), { to: "modal" }] });
|
|
11
11
|
*
|
|
12
|
-
* A chooser it was asked to open answers with `respond(value)`, the way its view would.
|
|
12
|
+
* A chooser it was asked to open answers with `respond(value)`, the way its view would. A view
|
|
13
|
+
* tested AS a chooser gets `{ choosing: { question } }`, and its `answer` is recorded.
|
|
13
14
|
*/
|
|
14
15
|
/** One call the view made: the method and its arguments, as given. */
|
|
15
16
|
export type ApiCall = {
|
|
@@ -26,6 +27,8 @@ export type TestApiOptions = {
|
|
|
26
27
|
crumbs?: readonly Crumb[];
|
|
27
28
|
/** What `api.context.selection()` gives. */
|
|
28
29
|
selection?: readonly ResourceRef[];
|
|
30
|
+
/** Opened by `pick` with this question (`api.choosing`). `null` without it: opened to look. */
|
|
31
|
+
choosing?: Choosing | null;
|
|
29
32
|
};
|
|
30
33
|
export type TestApi = {
|
|
31
34
|
api: WorkspaceApi;
|
package/dist/state/testing.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-composer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "The Sincpro workspace for React: one page with its breadcrumb, a peek, side panels and windows, and ⌘K — all over references, never data.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|