@sincpro/web-composer 1.2.0 → 1.3.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 +9 -0
- package/dist/domain/index.d.ts +3 -2
- package/dist/domain/index.js +3 -2
- package/dist/domain/layout.d.ts +3 -0
- package/dist/domain/layout.js +7 -0
- package/dist/domain/phone.d.ts +18 -0
- package/dist/domain/phone.js +22 -0
- package/dist/domain/registry.d.ts +6 -0
- package/dist/domain/workspace.d.ts +13 -1
- package/dist/domain/workspace.js +23 -9
- package/dist/shell/Composer.d.ts +4 -1
- package/dist/shell/Composer.js +48 -7
- package/dist/shell/Modal.d.ts +3 -2
- package/dist/shell/Modal.js +12 -6
- package/dist/shell/PanelHost.d.ts +3 -1
- package/dist/shell/PanelHost.js +6 -8
- package/dist/shell/copy.d.ts +3 -0
- package/dist/shell/copy.js +2 -0
- package/dist/shell/skin.d.ts +5 -0
- package/dist/shell/styles.js +15 -1
- package/dist/state/api.d.ts +4 -1
- package/dist/state/api.js +22 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -93,6 +93,7 @@ A view opens anything with one call and lets the workspace decide the rest:
|
|
|
93
93
|
api.open(ref); // the page — inside the peek, a step IN the drawer
|
|
94
94
|
api.open(ref, { to: "peek" }); // or "window", or "side"
|
|
95
95
|
api.open(ref, { to: "modal" }); // over THIS surface only; { blur: true } blurs what it covers
|
|
96
|
+
api.open(ref, { to: "window", size: { w: 720, h: 520 } }); // a window or a modal at that size
|
|
96
97
|
api.over; // in a modal: the record it was opened over — its context (null elsewhere)
|
|
97
98
|
api.replace(ref); // show it HERE without a step back: the record a form just created
|
|
98
99
|
api.setParams({ tenant }); // a filter that lives in the reference: survives reload and links
|
|
@@ -106,6 +107,7 @@ api.select(refs); // publish what this view has selected
|
|
|
106
107
|
api.context; // read what the user is on and what is selected — references only
|
|
107
108
|
api.pick(ref, onPick); // open a chooser (a many2one search); its view calls api.answer(ref)
|
|
108
109
|
api.pick(ref, onPick, { to: "modal" }); // the chooser as a modal over the form
|
|
110
|
+
api.pick(ref, onPick, { size: { w: 720, h: 520 } }); // a chooser window at that size (480×360 without it)
|
|
109
111
|
```
|
|
110
112
|
|
|
111
113
|
A **modal** belongs to the surface it covers — the page, a window, a side panel or the peek —
|
|
@@ -116,6 +118,13 @@ with it (asking first if something was typed). What it shares with whoever opene
|
|
|
116
118
|
its reference (`params`) and comes back with `api.answer`; `api.over` says what it covers. No
|
|
117
119
|
blur unless asked.
|
|
118
120
|
|
|
121
|
+
**On a phone** — when the workspace is narrower than 640 px (`<Composer phoneBelow>`, `0` never)
|
|
122
|
+
— it is one screen, and the views change nothing: the page takes it all; a window or a side
|
|
123
|
+
panel opens as the page, with its crumb to come back; a chooser opens as a sheet from the bottom,
|
|
124
|
+
so the form that asked stays to receive the answer; the peek is the screen's width. Panels that
|
|
125
|
+
were already open wait in «Also open», mounted, and one tap brings each to the page. Widen it and
|
|
126
|
+
the desk is back as it was.
|
|
127
|
+
|
|
119
128
|
From the app, around the workspace: `workspace.start(ref)` starts over from a menu (no
|
|
120
129
|
breadcrumb behind, no peek, the panels stay), and `useWorkspace({ hash: true })` puts the
|
|
121
130
|
workspace in the URL with the browser's Back working. Unsaved changes are asked with the
|
package/dist/domain/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
/** The model: no React, no CSS. Tested in Node; survives any change of skin. */
|
|
2
2
|
export type { Dock } from "./enums.js";
|
|
3
3
|
export { Axis, Destination, DOCKS, DragKind, HandleKind, Surface, Zone, } from "./enums.js";
|
|
4
|
-
export { type Box, type Handle, handles, KEYBOARD_STEP, layout, type Length, resolve, sizeAt, type Slot, stableOrder, STRIP, ZONE_LIMITS, } from "./layout.js";
|
|
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
|
+
export { chooserOnPhone, destinationOnPhone, PHONE_WIDTH, } from "./phone.js";
|
|
6
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
8
|
export { formatRef, isRef, parseRef, type ResourceRef, rootRef, sameRef, withParams, } from "./resource.js";
|
|
8
9
|
export { fromHash, restore, type SessionMemory, toHash, } from "./url.js";
|
|
9
|
-
export { back, closeModal, closePanel, closePeek, collapsePanel, cycleFocus, DEFAULT_ZONES, drillPeek, EMPTY, expandPanel, findPanel, floatPanel, focusedRef, focusPanel, goTo, hostOf, MAX_ZONE, maximize, MIN_SHARE, 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, start, type WindowBox, type Workspace, type Zones, } from "./workspace.js";
|
|
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";
|
package/dist/domain/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/** The model: no React, no CSS. Tested in Node; survives any change of skin. */
|
|
2
2
|
export { Axis, Destination, DOCKS, DragKind, HandleKind, Surface, Zone, } from "./enums.js";
|
|
3
|
-
export { handles, KEYBOARD_STEP, layout, resolve, sizeAt, stableOrder, STRIP, ZONE_LIMITS, } from "./layout.js";
|
|
3
|
+
export { handles, KEYBOARD_STEP, layout, phoneLayout, resolve, sizeAt, stableOrder, STRIP, ZONE_LIMITS, } from "./layout.js";
|
|
4
4
|
export { localEntries, matches, MIN_QUERY, PaletteSection, searchEntries, } from "./palette.js";
|
|
5
|
+
export { chooserOnPhone, destinationOnPhone, PHONE_WIDTH, } from "./phone.js";
|
|
5
6
|
export { createRegistry, loadView, } from "./registry.js";
|
|
6
7
|
export { formatRef, isRef, parseRef, rootRef, sameRef, withParams, } from "./resource.js";
|
|
7
8
|
export { fromHash, restore, toHash, } from "./url.js";
|
|
8
|
-
export { back, closeModal, closePanel, closePeek, collapsePanel, cycleFocus, DEFAULT_ZONES, drillPeek, EMPTY, expandPanel, findPanel, floatPanel, focusedRef, focusPanel, goTo, hostOf, MAX_ZONE, maximize, MIN_SHARE, MIN_ZONE, MODAL, modalId, modalOver, movePanel, nameOf, nameRef, navigatePanel, openModal, openPanel, PAGE, panelsIn, PEEK, peek, peekBack, peekGoTo, peekToPage, peekToSide, push, raisePanel, refOn, replace, replacePeek, resizePanel, resizeZone, select, selectionOf, settleModals, start, } from "./workspace.js";
|
|
9
|
+
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, modalId, modalOver, movePanel, nameOf, nameRef, navigatePanel, openModal, openPanel, PAGE, panelsIn, PEEK, peek, peekBack, peekGoTo, peekToPage, peekToSide, push, raisePanel, refOn, replace, replacePeek, resizePanel, resizeZone, select, selectionOf, settleModals, start, } from "./workspace.js";
|
package/dist/domain/layout.d.ts
CHANGED
|
@@ -50,6 +50,9 @@ export declare const resolve: (l: Length, size: number) => number;
|
|
|
50
50
|
/** What a minimized panel keeps: its title bar. It matches the frame's header. */
|
|
51
51
|
export declare const STRIP = 36;
|
|
52
52
|
export declare function layout(w: Workspace): readonly Slot[];
|
|
53
|
+
/** On a phone the page takes the whole workspace and every panel waits, mounted and hidden, to be
|
|
54
|
+
* brought to the page (see `phone.ts`). Hidden, not dropped: what was typed in it survives. */
|
|
55
|
+
export declare function phoneLayout(slots: readonly Slot[]): readonly Slot[];
|
|
53
56
|
/** Sorted by id so sibling order does not change when a panel changes zone — reordering
|
|
54
57
|
* siblings is what unmounts. */
|
|
55
58
|
export declare function stableOrder(slots: readonly Slot[]): readonly Slot[];
|
package/dist/domain/layout.js
CHANGED
|
@@ -134,6 +134,13 @@ export function layout(w) {
|
|
|
134
134
|
? { ...slot, box: FULL, floating: false, visible: true, collapsed: false, rail: false }
|
|
135
135
|
: { ...slot, visible: false });
|
|
136
136
|
}
|
|
137
|
+
/** On a phone the page takes the whole workspace and every panel waits, mounted and hidden, to be
|
|
138
|
+
* brought to the page (see `phone.ts`). Hidden, not dropped: what was typed in it survives. */
|
|
139
|
+
export function phoneLayout(slots) {
|
|
140
|
+
return slots.map((slot) => slot.id === PAGE
|
|
141
|
+
? { ...slot, box: FULL, floating: false, visible: true, collapsed: false, rail: false }
|
|
142
|
+
: { ...slot, visible: false });
|
|
143
|
+
}
|
|
137
144
|
/** Sorted by id so sibling order does not change when a panel changes zone — reordering
|
|
138
145
|
* siblings is what unmounts. */
|
|
139
146
|
export function stableOrder(slots) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Destination } from "./enums.js";
|
|
2
|
+
/**
|
|
3
|
+
* On a phone there is ONE screen. A side panel has no side to dock to and a window has nowhere
|
|
4
|
+
* to float, so they are not shrunk — they are translated into what a phone already has: the page,
|
|
5
|
+
* with its breadcrumb to come back. The peek and the modal stay: a drawer the width of the screen
|
|
6
|
+
* and a sheet from the bottom are what a phone does anyway.
|
|
7
|
+
*
|
|
8
|
+
* It is the WORKSPACE's width that decides, not the device's: a narrow embed on a wide screen is
|
|
9
|
+
* a phone too. Nothing in the model changes: the panels keep their zones, so widening the window
|
|
10
|
+
* brings the desk back as it was.
|
|
11
|
+
*/
|
|
12
|
+
/** Below this many pixels the workspace is a phone. */
|
|
13
|
+
export declare const PHONE_WIDTH = 640;
|
|
14
|
+
/** Where `open(ref, { to })` goes on a phone. */
|
|
15
|
+
export declare function destinationOnPhone(to: Destination): Destination;
|
|
16
|
+
/** Where a chooser opens on a phone. Not the page: it would push the form that asked into the
|
|
17
|
+
* breadcrumb — and the form has to stay where it is to receive the answer. */
|
|
18
|
+
export declare function chooserOnPhone(to: Destination): Destination;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Destination } from "./enums.js";
|
|
2
|
+
/**
|
|
3
|
+
* On a phone there is ONE screen. A side panel has no side to dock to and a window has nowhere
|
|
4
|
+
* to float, so they are not shrunk — they are translated into what a phone already has: the page,
|
|
5
|
+
* with its breadcrumb to come back. The peek and the modal stay: a drawer the width of the screen
|
|
6
|
+
* and a sheet from the bottom are what a phone does anyway.
|
|
7
|
+
*
|
|
8
|
+
* It is the WORKSPACE's width that decides, not the device's: a narrow embed on a wide screen is
|
|
9
|
+
* a phone too. Nothing in the model changes: the panels keep their zones, so widening the window
|
|
10
|
+
* brings the desk back as it was.
|
|
11
|
+
*/
|
|
12
|
+
/** Below this many pixels the workspace is a phone. */
|
|
13
|
+
export const PHONE_WIDTH = 640;
|
|
14
|
+
/** Where `open(ref, { to })` goes on a phone. */
|
|
15
|
+
export function destinationOnPhone(to) {
|
|
16
|
+
return to === Destination.Window || to === Destination.Side ? Destination.Page : to;
|
|
17
|
+
}
|
|
18
|
+
/** Where a chooser opens on a phone. Not the page: it would push the form that asked into the
|
|
19
|
+
* breadcrumb — and the form has to stay where it is to receive the answer. */
|
|
20
|
+
export function chooserOnPhone(to) {
|
|
21
|
+
return to === Destination.Window || to === Destination.Side ? Destination.Modal : to;
|
|
22
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Destination, Surface, Zone } from "./enums.js";
|
|
2
2
|
import type { ResourceRef } from "./resource.js";
|
|
3
|
+
import type { Size } from "./workspace.js";
|
|
3
4
|
import type { ComponentType } from "react";
|
|
4
5
|
export { Surface } from "./enums.js";
|
|
5
6
|
/**
|
|
@@ -12,12 +13,17 @@ export type OpenOptions = {
|
|
|
12
13
|
/** A modal only: blur what it covers. Off by default — the surface underneath is blocked,
|
|
13
14
|
* not hidden. */
|
|
14
15
|
blur?: boolean;
|
|
16
|
+
/** A window or a modal: the size it opens at, in pixels (a window: 480×360 without it). What
|
|
17
|
+
* does not fit is shrunk to what there is. On a phone there are no windows: it is ignored. */
|
|
18
|
+
size?: Size;
|
|
15
19
|
};
|
|
16
20
|
export type PickOptions = {
|
|
17
21
|
/** Where the chooser opens. A window unless said otherwise. */
|
|
18
22
|
to?: typeof Destination.Peek | typeof Destination.Window | typeof Destination.Side | typeof Destination.Modal;
|
|
19
23
|
/** A modal only: blur what it covers. */
|
|
20
24
|
blur?: boolean;
|
|
25
|
+
/** A window or a modal: the size the chooser opens at, in pixels. */
|
|
26
|
+
size?: Size;
|
|
21
27
|
};
|
|
22
28
|
/** One step of a breadcrumb, ready for `List.Crumbs` or `Record.Crumbs`. */
|
|
23
29
|
export type Crumb = {
|
|
@@ -51,6 +51,13 @@ export type Modal = {
|
|
|
51
51
|
view: ResourceRef;
|
|
52
52
|
/** Blur what it covers. Off unless asked: the host is blocked, not hidden. */
|
|
53
53
|
blur: boolean;
|
|
54
|
+
/** The size its view asked for; without it, the modal's own. */
|
|
55
|
+
size?: Size;
|
|
56
|
+
};
|
|
57
|
+
/** A size a view asks for, in pixels. What does not fit is shrunk to what there is. */
|
|
58
|
+
export type Size = {
|
|
59
|
+
w: number;
|
|
60
|
+
h: number;
|
|
54
61
|
};
|
|
55
62
|
/** What a selection belongs to, and the references selected. */
|
|
56
63
|
export type Selected = {
|
|
@@ -94,6 +101,8 @@ export declare const DEFAULT_ZONES: Zones;
|
|
|
94
101
|
export declare const MIN_ZONE = 0.12;
|
|
95
102
|
export declare const MAX_ZONE = 0.72;
|
|
96
103
|
export declare const MIN_SHARE = 0.12;
|
|
104
|
+
/** Below this a window's controls overlap; a size asked for is never smaller. */
|
|
105
|
+
export declare const MIN_WINDOW: Size;
|
|
97
106
|
export declare const EMPTY: Workspace;
|
|
98
107
|
export declare const findPanel: (w: Workspace, id: string) => Panel | null;
|
|
99
108
|
/** What a surface shows now — the page, the peek, a panel or a modal — or `null` if it is not
|
|
@@ -124,6 +133,8 @@ export type OpenPanelOptions = {
|
|
|
124
133
|
/** Deduplicating is the right default for a column and the wrong one for «the same table
|
|
125
134
|
* with two filters». */
|
|
126
135
|
allowDuplicate?: boolean;
|
|
136
|
+
/** A window only: the size it opens at — and the size an open one takes when asked again. */
|
|
137
|
+
size?: Size;
|
|
127
138
|
};
|
|
128
139
|
/** Opens a resource as a panel. If it is already open it moves it to the requested zone and
|
|
129
140
|
* focuses it, unless a duplicate is explicitly asked for. */
|
|
@@ -185,13 +196,14 @@ export declare function peekToPage(w: Workspace): Workspace;
|
|
|
185
196
|
export declare function peekToSide(w: Workspace, zone?: Zone): Workspace;
|
|
186
197
|
export type OpenModalOptions = {
|
|
187
198
|
blur?: boolean;
|
|
199
|
+
size?: Size;
|
|
188
200
|
};
|
|
189
201
|
/**
|
|
190
202
|
* `view` over `host`, which keeps its place and its state underneath. Asked from inside a
|
|
191
203
|
* modal, it replaces that one: same host, no stacking. It takes the focus, so the shortcuts and
|
|
192
204
|
* ⌘K talk to it.
|
|
193
205
|
*/
|
|
194
|
-
export declare function openModal(w: Workspace, host: string, view: ResourceRef, { blur }?: OpenModalOptions): Workspace;
|
|
206
|
+
export declare function openModal(w: Workspace, host: string, view: ResourceRef, { blur, size }?: OpenModalOptions): Workspace;
|
|
195
207
|
/** Closes the modal over `host` (or the modal itself, by its id). The focus goes back to the
|
|
196
208
|
* surface it covered. */
|
|
197
209
|
export declare function closeModal(w: Workspace, host: string): Workspace;
|
package/dist/domain/workspace.js
CHANGED
|
@@ -21,6 +21,8 @@ export const MIN_ZONE = 0.12;
|
|
|
21
21
|
export const MAX_ZONE = 0.72;
|
|
22
22
|
export const MIN_SHARE = 0.12;
|
|
23
23
|
const WINDOW_BOX = { x: 72, y: 56, w: 480, h: 360 };
|
|
24
|
+
/** Below this a window's controls overlap; a size asked for is never smaller. */
|
|
25
|
+
export const MIN_WINDOW = { w: 280, h: 160 };
|
|
24
26
|
const WINDOW_OFFSET = 28;
|
|
25
27
|
export const EMPTY = {
|
|
26
28
|
page: null,
|
|
@@ -90,7 +92,7 @@ const normalizeAll = (panels) => DOCKS.reduce((acc, zone) => normalize(acc, zone
|
|
|
90
92
|
function topZ(panels) {
|
|
91
93
|
return panels.reduce((max, p) => (p.placement.zone === Zone.Floating ? Math.max(max, p.placement.z) : max), 0);
|
|
92
94
|
}
|
|
93
|
-
function placementFor(zone, panels) {
|
|
95
|
+
function placementFor(zone, panels, size) {
|
|
94
96
|
if (zone !== Zone.Floating)
|
|
95
97
|
return { zone, share: 1 };
|
|
96
98
|
const floating = panels.filter((p) => p.placement.zone === Zone.Floating).length;
|
|
@@ -98,8 +100,8 @@ function placementFor(zone, panels) {
|
|
|
98
100
|
zone,
|
|
99
101
|
x: WINDOW_BOX.x + floating * WINDOW_OFFSET,
|
|
100
102
|
y: WINDOW_BOX.y + floating * WINDOW_OFFSET,
|
|
101
|
-
w: WINDOW_BOX.w,
|
|
102
|
-
h: WINDOW_BOX.h,
|
|
103
|
+
w: Math.max(MIN_WINDOW.w, size?.w ?? WINDOW_BOX.w),
|
|
104
|
+
h: Math.max(MIN_WINDOW.h, size?.h ?? WINDOW_BOX.h),
|
|
103
105
|
z: topZ(panels) + 1,
|
|
104
106
|
};
|
|
105
107
|
}
|
|
@@ -168,11 +170,19 @@ export function openPanel(w, view, options = {}) {
|
|
|
168
170
|
const zone = opts.zone ?? Zone.Right;
|
|
169
171
|
if (opts.allowDuplicate !== true) {
|
|
170
172
|
const existing = w.panels.find((p) => sameRef(p.view, view));
|
|
171
|
-
if (existing)
|
|
172
|
-
|
|
173
|
+
if (existing) {
|
|
174
|
+
const moved = movePanel(w, existing.id, zone);
|
|
175
|
+
const sized = opts.size === undefined || zone !== Zone.Floating
|
|
176
|
+
? moved
|
|
177
|
+
: floatPanel(moved, existing.id, {
|
|
178
|
+
w: Math.max(MIN_WINDOW.w, opts.size.w),
|
|
179
|
+
h: Math.max(MIN_WINDOW.h, opts.size.h),
|
|
180
|
+
});
|
|
181
|
+
return focusPanel(sized, existing.id);
|
|
182
|
+
}
|
|
173
183
|
}
|
|
174
184
|
const id = nextId(w.panels.map((p) => p.id));
|
|
175
|
-
const panel = { id, view, placement: placementFor(zone, w.panels) };
|
|
185
|
+
const panel = { id, view, placement: placementFor(zone, w.panels, opts.size) };
|
|
176
186
|
return focusPanel({ ...w, panels: normalizeAll([...w.panels, panel]) }, id);
|
|
177
187
|
}
|
|
178
188
|
export function movePanel(w, id, zone) {
|
|
@@ -361,18 +371,22 @@ export function peekToSide(w, zone = Zone.Right) {
|
|
|
361
371
|
* modal, it replaces that one: same host, no stacking. It takes the focus, so the shortcuts and
|
|
362
372
|
* ⌘K talk to it.
|
|
363
373
|
*/
|
|
364
|
-
export function openModal(w, host, view, { blur = false } = {}) {
|
|
374
|
+
export function openModal(w, host, view, { blur = false, size } = {}) {
|
|
365
375
|
const under = hostOf(host);
|
|
366
376
|
const over = refOn(w, under);
|
|
367
377
|
if (over === null)
|
|
368
378
|
return w;
|
|
369
379
|
const id = modalId(under);
|
|
370
380
|
const current = modalOver(w, under);
|
|
371
|
-
if (current !== null &&
|
|
381
|
+
if (current !== null &&
|
|
382
|
+
sameRef(current.view, view) &&
|
|
383
|
+
current.blur === blur &&
|
|
384
|
+
current.size?.w === size?.w &&
|
|
385
|
+
current.size?.h === size?.h)
|
|
372
386
|
return focusPanel(w, id);
|
|
373
387
|
const modals = [
|
|
374
388
|
...w.modals.filter((m) => m.host !== under && modalOver(w, m.host) !== null),
|
|
375
|
-
{ host: under, over, view, blur },
|
|
389
|
+
{ host: under, over, view, blur, ...(size === undefined ? {} : { size }) },
|
|
376
390
|
];
|
|
377
391
|
return { ...w, modals, focus: id, selected: dropSelection(w, id) };
|
|
378
392
|
}
|
package/dist/shell/Composer.d.ts
CHANGED
|
@@ -19,5 +19,8 @@ export type ComposerProps = {
|
|
|
19
19
|
/** Your design over the composer: icons, the peek drawer, the confirm dialog, the notice, or
|
|
20
20
|
* `styles: false` to drop the default sheet. What is not passed keeps the default. */
|
|
21
21
|
skin?: ComposerSkin;
|
|
22
|
+
/** Below this width (px) of the WORKSPACE it behaves as a phone: one screen, windows and side
|
|
23
|
+
* panels open as the page, choosers as a sheet (`domain/phone.ts`). `0` never does. */
|
|
24
|
+
phoneBelow?: number;
|
|
22
25
|
};
|
|
23
|
-
export declare function Composer({ workspace, registry, empty, keyboard, defaultOpen, palette: paletteProp, onPaletteChange, skin: skinProp, }: ComposerProps): import("react").JSX.Element;
|
|
26
|
+
export declare function Composer({ workspace, registry, empty, keyboard, defaultOpen, palette: paletteProp, onPaletteChange, skin: skinProp, phoneBelow, }: ComposerProps): import("react").JSX.Element;
|
package/dist/shell/Composer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
2
|
-
import { Destination, focusedRef, modalOver, PEEK, Surface, Zone, } from "../domain/index.js";
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Destination, destinationOnPhone, focusedRef, modalOver, PEEK, PHONE_WIDTH, Surface, Zone, } from "../domain/index.js";
|
|
3
3
|
import { composerCopy } from "./copy.js";
|
|
4
4
|
import { ModalLayer } from "./Modal.js";
|
|
5
5
|
import { WorkspacePalette } from "./Palette.js";
|
|
@@ -12,7 +12,7 @@ import { createApiFactory, targetOf } from "../state/api.js";
|
|
|
12
12
|
import { useDropMonitor } from "../state/drag.js";
|
|
13
13
|
import { useKeyboard } from "../state/useKeyboard.js";
|
|
14
14
|
import { useWorkspaceState } from "../state/useWorkspace.js";
|
|
15
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
15
|
+
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, } from "react";
|
|
16
16
|
/**
|
|
17
17
|
* The question before throwing away what someone typed, drawn with the design system. The store
|
|
18
18
|
* calls it; a `confirmDiscard` given to the store replaces it.
|
|
@@ -31,7 +31,36 @@ function useDiscardDialog(workspace, titleOf) {
|
|
|
31
31
|
}, [workspace, titleOf]);
|
|
32
32
|
return asking;
|
|
33
33
|
}
|
|
34
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Whether the workspace is a phone, measured BEFORE paint: measuring after it drew the desk for a
|
|
36
|
+
* frame and swapped it, and a click in that frame landed on a panel that was going away. A
|
|
37
|
+
* workspace with no width yet (hidden, or not laid out) is not a phone.
|
|
38
|
+
*/
|
|
39
|
+
function usePhone(root, below) {
|
|
40
|
+
const [phone, setPhone] = useState(false);
|
|
41
|
+
useLayoutEffect(() => {
|
|
42
|
+
const el = root.current;
|
|
43
|
+
if (el === null)
|
|
44
|
+
return;
|
|
45
|
+
const measure = (width) => setPhone(width > 0 && width < below);
|
|
46
|
+
measure(el.getBoundingClientRect().width);
|
|
47
|
+
if (typeof ResizeObserver === "undefined")
|
|
48
|
+
return;
|
|
49
|
+
const watch = new ResizeObserver(([entry]) => {
|
|
50
|
+
if (entry !== undefined)
|
|
51
|
+
measure(entry.contentRect.width);
|
|
52
|
+
});
|
|
53
|
+
watch.observe(el);
|
|
54
|
+
return () => watch.disconnect();
|
|
55
|
+
}, [root, below]);
|
|
56
|
+
return phone;
|
|
57
|
+
}
|
|
58
|
+
/** On a phone the panels that were open wait here: one tap brings each to the page. */
|
|
59
|
+
function PhoneDock({ panels, titleOf, onBring, }) {
|
|
60
|
+
const copy = composerCopy().phone;
|
|
61
|
+
return (_jsxs("nav", { "aria-label": copy.alsoOpen, className: "sc-dock", children: [_jsx("span", { className: "sc-dock-label", children: copy.alsoOpen }), panels.map((p) => (_jsx(ChromeButton, { onClick: () => onBring(p.id), children: titleOf(p.view) }, p.id)))] }));
|
|
62
|
+
}
|
|
63
|
+
export function Composer({ workspace, registry, empty, keyboard = true, defaultOpen = Destination.Page, palette: paletteProp, onPaletteChange, skin: skinProp, phoneBelow = PHONE_WIDTH, }) {
|
|
35
64
|
const skin = useMemo(() => resolveSkin(skinProp), [skinProp]);
|
|
36
65
|
const Drawer = skin.Peek ?? PeekDrawer;
|
|
37
66
|
const Confirm = skin.Confirm ?? ConfirmDialog;
|
|
@@ -43,7 +72,18 @@ export function Composer({ workspace, registry, empty, keyboard = true, defaultO
|
|
|
43
72
|
setPaletteState(open);
|
|
44
73
|
onPaletteChange?.(open);
|
|
45
74
|
}, [onPaletteChange]);
|
|
46
|
-
const
|
|
75
|
+
const root = useRef(null);
|
|
76
|
+
const phone = usePhone(root, phoneBelow);
|
|
77
|
+
/* The API reads it at call time: a view's API is not rebuilt when the window is resized. */
|
|
78
|
+
const phoneNow = useRef(phone);
|
|
79
|
+
useLayoutEffect(() => {
|
|
80
|
+
phoneNow.current = phone;
|
|
81
|
+
}, [phone]);
|
|
82
|
+
const api = useMemo(() => createApiFactory(workspace, {
|
|
83
|
+
registry,
|
|
84
|
+
defaultOpen,
|
|
85
|
+
isPhone: () => phoneNow.current,
|
|
86
|
+
}), [workspace, registry, defaultOpen]);
|
|
47
87
|
useEffect(() => api.dispose, [api]);
|
|
48
88
|
useKeyboard({
|
|
49
89
|
workspace,
|
|
@@ -57,7 +97,8 @@ export function Composer({ workspace, registry, empty, keyboard = true, defaultO
|
|
|
57
97
|
const asking = useDiscardDialog(workspace, api.titleOf);
|
|
58
98
|
/** Where a chosen search result opens. Without a page yet, the first one becomes it —
|
|
59
99
|
* whatever was asked: a peek or a window over nothing would be invisible. */
|
|
60
|
-
function open(ref,
|
|
100
|
+
function open(ref, asked) {
|
|
101
|
+
const destination = phone ? destinationOnPhone(asked) : asked;
|
|
61
102
|
if (workspace.get().page === null)
|
|
62
103
|
workspace.push(ref);
|
|
63
104
|
else if (destination === Destination.Peek)
|
|
@@ -82,5 +123,5 @@ export function Composer({ workspace, registry, empty, keyboard = true, defaultO
|
|
|
82
123
|
const peekModal = modalOver(state, PEEK);
|
|
83
124
|
const peekSpec = peeked === null ? null : registry.resolve(peeked);
|
|
84
125
|
const cameFrom = state.peekTrail.at(-1);
|
|
85
|
-
return (_jsx(SkinProvider, { value: skin, children: _jsxs("div", { className: "sc-root", children: [skin.styles ? _jsx(ComposerStyles, {}) : null, state.page === null ? (_jsx("div", { className: "sc-empty", children: empty })) : (_jsx(PanelHost, { workspace: state, registry: registry, store: workspace, api: api, overlay: peeked === null ? null : (_jsxs(_Fragment, { children: [_jsx("div", { style: { display: "contents" }, inert: peekModal !== null, onPointerDownCapture: () => workspace.focusPanel(PEEK), children: _jsx(Drawer, { title: api.titleOf(peeked), onClose: workspace.closePeek, actions: _jsxs(_Fragment, { children: [_jsx(ChromeButton, { onClick: () => workspace.peekToSide(peekSpec?.preferredZone ?? Zone.Right), children: copy.peek.openAsPanel }), cameFrom === undefined ? null : (_jsx(ChromeButton, { role: "ghost", icon: skin.icons.back, onClick: workspace.peekBack, children: copy.peek.back(api.titleOf(cameFrom)) })), _jsx(ChromeButton, { role: "ghost", onClick: workspace.peekToPage, children: copy.peek.openAsPage })] }), children: _jsx(ViewHost, { resource: peeked, registry: registry, api: api.for(peeked, { surface: Surface.Peek }) }) }) }), peekModal === null ? null : (_jsx(ModalLayer, { modal: peekModal, registry: registry, store: workspace, api: api }))] })) })), _jsx(Confirm, { open: asking !== null, title: copy.discard.title, detail: asking === null ? "" : copy.discard.detail(asking.names), keep: copy.discard.keep, discard: copy.discard.discard, onAnswer: (ok) => asking?.answer(ok) }), palette ? (_jsx(WorkspacePalette, { registry: registry, focused: focusedRef(state), onOpen: open, onAction: run, onClose: () => setPalette(false) })) : null] }) }));
|
|
126
|
+
return (_jsx(SkinProvider, { value: skin, children: _jsxs("div", { ref: root, className: "sc-root", ...(phone ? { "data-phone": "" } : {}), children: [skin.styles ? _jsx(ComposerStyles, {}) : null, state.page === null ? (_jsx("div", { className: "sc-empty", children: empty })) : (_jsx(PanelHost, { workspace: state, registry: registry, store: workspace, api: api, phone: phone, overlay: peeked === null ? null : (_jsxs(_Fragment, { children: [_jsx("div", { style: { display: "contents" }, inert: peekModal !== null, onPointerDownCapture: () => workspace.focusPanel(PEEK), children: _jsx(Drawer, { title: api.titleOf(peeked), onClose: workspace.closePeek, actions: _jsxs(_Fragment, { children: [phone ? null : (_jsx(ChromeButton, { onClick: () => workspace.peekToSide(peekSpec?.preferredZone ?? Zone.Right), children: copy.peek.openAsPanel })), cameFrom === undefined ? null : (_jsx(ChromeButton, { role: "ghost", icon: skin.icons.back, onClick: workspace.peekBack, children: copy.peek.back(api.titleOf(cameFrom)) })), _jsx(ChromeButton, { role: "ghost", onClick: workspace.peekToPage, children: copy.peek.openAsPage })] }), children: _jsx(ViewHost, { resource: peeked, registry: registry, api: api.for(peeked, { surface: Surface.Peek }) }) }) }), peekModal === null ? null : (_jsx(ModalLayer, { modal: peekModal, registry: registry, store: workspace, api: api, phone: phone }))] })) })), phone && state.page !== null && state.panels.length > 0 ? (_jsx(PhoneDock, { panels: state.panels, titleOf: api.titleOf, onBring: workspace.expandPanel })) : null, _jsx(Confirm, { open: asking !== null, title: copy.discard.title, detail: asking === null ? "" : copy.discard.detail(asking.names), keep: copy.discard.keep, discard: copy.discard.discard, onAnswer: (ok) => asking?.answer(ok) }), palette ? (_jsx(WorkspacePalette, { registry: registry, focused: focusedRef(state), onOpen: open, onAction: run, onClose: () => setPalette(false) })) : null] }) }));
|
|
86
127
|
}
|
package/dist/shell/Modal.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { type ModalProps } from "./skin.js";
|
|
|
3
3
|
import type { ApiFactory } from "../state/api.js";
|
|
4
4
|
import type { WorkspaceStore } from "../state/store.js";
|
|
5
5
|
import { type CSSProperties } from "react";
|
|
6
|
-
export declare function ModalWindow({ title, blur, onClose, children }: ModalProps): import("react").JSX.Element;
|
|
6
|
+
export declare function ModalWindow({ title, blur, size, phone, onClose, children }: ModalProps): import("react").JSX.Element;
|
|
7
7
|
export type ModalLayerProps = {
|
|
8
8
|
modal: Modal;
|
|
9
9
|
registry: Registry;
|
|
@@ -11,7 +11,8 @@ export type ModalLayerProps = {
|
|
|
11
11
|
api: ApiFactory;
|
|
12
12
|
/** Geometry only: where the host is, when the layer is not already inside it. */
|
|
13
13
|
style?: CSSProperties;
|
|
14
|
+
phone?: boolean;
|
|
14
15
|
};
|
|
15
16
|
/** Where a modal stands: over its host's box, taking the workspace focus when touched. The skin
|
|
16
17
|
* draws what is inside it. */
|
|
17
|
-
export declare function ModalLayer({ modal, registry, store, api, style }: ModalLayerProps): import("react").JSX.Element;
|
|
18
|
+
export declare function ModalLayer({ modal, registry, store, api, style, phone, }: ModalLayerProps): import("react").JSX.Element;
|
package/dist/shell/Modal.js
CHANGED
|
@@ -5,7 +5,8 @@ import { useSkin } from "./skin.js";
|
|
|
5
5
|
import { ViewHost } from "./ViewHost.js";
|
|
6
6
|
import { useEffect, useId, useRef, useState, } from "react";
|
|
7
7
|
/**
|
|
8
|
-
* The composer's own modal: a small window centred over the surface that asked for it
|
|
8
|
+
* The composer's own modal: a small window centred over the surface that asked for it — on a
|
|
9
|
+
* phone, a sheet from the bottom. It moves
|
|
9
10
|
* by its title — what is underneath may be what the person needs to read to answer — but never
|
|
10
11
|
* further than its surface: it belongs to it, and leaving it would cover a neighbour that is
|
|
11
12
|
* not blocked. It does not dim the rest of the workspace; that is the point of it.
|
|
@@ -45,7 +46,7 @@ function useMoveByTitle(box) {
|
|
|
45
46
|
}
|
|
46
47
|
return { offset, start };
|
|
47
48
|
}
|
|
48
|
-
export function ModalWindow({ title, blur, onClose, children }) {
|
|
49
|
+
export function ModalWindow({ title, blur, size, phone, onClose, children }) {
|
|
49
50
|
const copy = composerCopy().modal;
|
|
50
51
|
const { close: CloseIcon } = useSkin().icons;
|
|
51
52
|
const box = useRef(null);
|
|
@@ -59,17 +60,22 @@ export function ModalWindow({ title, blur, onClose, children }) {
|
|
|
59
60
|
opener.focus();
|
|
60
61
|
};
|
|
61
62
|
}, []);
|
|
62
|
-
return (_jsx("div", { className: "sc-modal-scrim", ...(blur ? { "data-blur": "" } : {}), children: _jsxs("section", { ref: box, role: "dialog", tabIndex: -1, "aria-labelledby": titleId, className: "sc-modal", style:
|
|
63
|
+
return (_jsx("div", { className: "sc-modal-scrim", ...(blur ? { "data-blur": "" } : {}), ...(phone ? { "data-phone": "" } : {}), children: _jsxs("section", { ref: box, role: "dialog", tabIndex: -1, "aria-labelledby": titleId, className: "sc-modal", style: phone
|
|
64
|
+
? undefined
|
|
65
|
+
: {
|
|
66
|
+
transform: `translate(${offset.x}px, ${offset.y}px)`,
|
|
67
|
+
...(size === undefined ? {} : { width: size.w, height: size.h }),
|
|
68
|
+
}, onKeyDown: (e) => {
|
|
63
69
|
if (e.key !== "Escape" || e.defaultPrevented)
|
|
64
70
|
return;
|
|
65
71
|
e.preventDefault();
|
|
66
72
|
onClose();
|
|
67
|
-
}, children: [_jsxs("header", { className: "sc-modal-head", onPointerDown: start, children: [_jsx("h2", { id: titleId, className: "sc-modal-title", children: title }), _jsx("button", { type: "button", className: "sc-control", "aria-label": copy.close, title: copy.close, onPointerDown: (e) => e.stopPropagation(), onClick: onClose, children: _jsx(CloseIcon, {}) })] }), _jsx("div", { className: "sc-modal-body", children: children })] }) }));
|
|
73
|
+
}, children: [_jsxs("header", { className: "sc-modal-head", onPointerDown: phone ? undefined : start, children: [_jsx("h2", { id: titleId, className: "sc-modal-title", children: title }), _jsx("button", { type: "button", className: "sc-control", "aria-label": copy.close, title: copy.close, onPointerDown: (e) => e.stopPropagation(), onClick: onClose, children: _jsx(CloseIcon, {}) })] }), _jsx("div", { className: "sc-modal-body", children: children })] }) }));
|
|
68
74
|
}
|
|
69
75
|
/** Where a modal stands: over its host's box, taking the workspace focus when touched. The skin
|
|
70
76
|
* draws what is inside it. */
|
|
71
|
-
export function ModalLayer({ modal, registry, store, api, style }) {
|
|
77
|
+
export function ModalLayer({ modal, registry, store, api, style, phone = false, }) {
|
|
72
78
|
const Window = useSkin().Modal ?? ModalWindow;
|
|
73
79
|
const { host, view } = modal;
|
|
74
|
-
return (_jsx("div", { className: "sc-modal-layer", ...(style === undefined ? {} : { style }), onPointerDownCapture: () => store.focusPanel(modalId(host)), children: _jsx(Window, { title: api.titleOf(view), blur: modal.blur, onClose: () => store.closeModal(host), children: _jsx(ViewHost, { resource: view, registry: registry, api: api.for(view, { surface: Surface.Modal, host }) }) }) }));
|
|
80
|
+
return (_jsx("div", { className: "sc-modal-layer", ...(style === undefined ? {} : { style }), onPointerDownCapture: () => store.focusPanel(modalId(host)), children: _jsx(Window, { title: api.titleOf(view), blur: modal.blur, ...(modal.size === undefined ? {} : { size: modal.size }), phone: phone, onClose: () => store.closeModal(host), children: _jsx(ViewHost, { resource: view, registry: registry, api: api.for(view, { surface: Surface.Modal, host }) }) }) }));
|
|
75
81
|
}
|
|
@@ -19,5 +19,7 @@ export type PanelHostProps = {
|
|
|
19
19
|
registry: Registry;
|
|
20
20
|
store: WorkspaceStore;
|
|
21
21
|
api: ApiFactory;
|
|
22
|
+
/** One screen: the page takes it all, the panels wait hidden, nothing resizes or docks. */
|
|
23
|
+
phone?: boolean;
|
|
22
24
|
};
|
|
23
|
-
export declare function PanelHost({ workspace, overlay, registry, store, api }: PanelHostProps): import("react").JSX.Element;
|
|
25
|
+
export declare function PanelHost({ workspace, overlay, registry, store, api, phone, }: PanelHostProps): import("react").JSX.Element;
|
package/dist/shell/PanelHost.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Axis, HandleKind, handles, KEYBOARD_STEP, layout, modalOver, PAGE, sizeAt, stableOrder, Surface, Zone, } from "../domain/index.js";
|
|
2
|
+
import { Axis, HandleKind, handles, KEYBOARD_STEP, layout, MIN_WINDOW, modalOver, PAGE, phoneLayout, sizeAt, stableOrder, Surface, Zone, } from "../domain/index.js";
|
|
3
3
|
import { composerCopy } from "./copy.js";
|
|
4
4
|
import { ModalLayer } from "./Modal.js";
|
|
5
5
|
import { PanelFrame } from "./PanelFrame.js";
|
|
@@ -7,8 +7,6 @@ import { ViewHost } from "./ViewHost.js";
|
|
|
7
7
|
import { useDropZone, usePanelDragArmed } from "../state/drag.js";
|
|
8
8
|
import { Fragment, useCallback, useRef, } from "react";
|
|
9
9
|
const HANDLE_THICKNESS = 9;
|
|
10
|
-
/** A window never gets smaller than this: below it the controls overlap. */
|
|
11
|
-
const MIN_WINDOW = { w: 280, h: 160 };
|
|
12
10
|
/** How much of a window must stay inside the host, so it can always be grabbed back. */
|
|
13
11
|
const KEEP_VISIBLE = 80;
|
|
14
12
|
/** A share of the host plus pixels, as CSS. `calc()` only when both are there. */
|
|
@@ -125,13 +123,13 @@ const DROP_ZONES = [
|
|
|
125
123
|
style: { left: "24%", right: "24%", bottom: 0, height: "30%" },
|
|
126
124
|
},
|
|
127
125
|
];
|
|
128
|
-
export function PanelHost({ workspace, overlay, registry, store, api }) {
|
|
126
|
+
export function PanelHost({ workspace, overlay, registry, store, api, phone = false, }) {
|
|
129
127
|
const hostRef = useRef(null);
|
|
130
128
|
const drag = useDrag(hostRef);
|
|
131
129
|
const dropArmed = usePanelDragArmed();
|
|
132
130
|
const copy = composerCopy().panel;
|
|
133
|
-
const slots = layout(workspace);
|
|
134
|
-
const resizeHandles = handles(workspace);
|
|
131
|
+
const slots = phone ? phoneLayout(layout(workspace)) : layout(workspace);
|
|
132
|
+
const resizeHandles = phone ? [] : handles(workspace);
|
|
135
133
|
const valueOf = (handle) => {
|
|
136
134
|
if (handle.kind === HandleKind.Zone)
|
|
137
135
|
return workspace.zones[handle.zone];
|
|
@@ -190,7 +188,7 @@ export function PanelHost({ workspace, overlay, registry, store, api }) {
|
|
|
190
188
|
/* The page has no frame to hold its modal: it stands beside it, over the same box, and
|
|
191
189
|
the page underneath is inert. */
|
|
192
190
|
if (isPage) {
|
|
193
|
-
return (_jsxs(Fragment, { children: [_jsx("div", { hidden: !slot.visible, inert: modal !== null, style: style, onPointerDownCapture: () => store.focusPanel(PAGE), className: "sc-slot", "data-page": "", children: _jsx(ViewHost, { resource: slot.view, registry: registry, api: api.for(slot.view, { surface: Surface.Page }) }) }), modal === null || !slot.visible ? null : (_jsx(ModalLayer, { modal: modal, registry: registry, store: store, api: api, style: boxStyle(slot.box) }))] }, slot.id));
|
|
191
|
+
return (_jsxs(Fragment, { children: [_jsx("div", { hidden: !slot.visible, inert: modal !== null, style: style, onPointerDownCapture: () => store.focusPanel(PAGE), className: "sc-slot", "data-page": "", children: _jsx(ViewHost, { resource: slot.view, registry: registry, api: api.for(slot.view, { surface: Surface.Page }) }) }), modal === null || !slot.visible ? null : (_jsx(ModalLayer, { modal: modal, registry: registry, store: store, api: api, phone: phone, style: boxStyle(slot.box) }))] }, slot.id));
|
|
194
192
|
}
|
|
195
193
|
const zone = slot.panel?.placement.zone ?? Zone.Right;
|
|
196
194
|
return (_jsxs("div", { hidden: !slot.visible, style: style, className: "sc-slot", "data-pad": slotPadding(slot), children: [_jsx(PanelFrame, { title: api.titleOf(slot.view), zone: zone, collapsed: slot.collapsed, rail: slot.rail, focused: workspace.focus === slot.id, maximized: workspace.maximized === slot.id, ...(slot.floating ? {} : { dragId: slot.id }), onMaximize: () => store.maximize(slot.id), onFocus: () => store.focusPanel(slot.id), onMoveStart: (e) => moveWindow(e, slot), modal: modal === null ? null : (_jsx(ModalLayer, { modal: modal, registry: registry, store: store, api: api })), actions: {
|
|
@@ -201,5 +199,5 @@ export function PanelHost({ workspace, overlay, registry, store, api }) {
|
|
|
201
199
|
}, children: _jsx(ViewHost, { resource: slot.view, registry: registry, api: api.for(slot.view, { surface: Surface.Panel, panelId: slot.id }) }) }), slot.floating && !slot.collapsed
|
|
202
200
|
? GRIPS.map((grip) => (_jsx("div", { "aria-hidden": true, onPointerDown: (e) => resizeWindow(e, slot, grip.dx, grip.dy), className: "sc-grip", "data-grip": grip.id }, grip.id)))
|
|
203
201
|
: null] }, slot.id));
|
|
204
|
-
}), overlay === undefined || overlay === null ? null : (_jsx("div", { style: boxStyle(slots.find((slot) => slot.id === PAGE && slot.visible)?.box ?? WHOLE), className: "sc-overlay", children: overlay })), _jsx("div", { className: "sc-drops", children: DROP_ZONES.map((b) => (_jsx(ZoneDropTarget, { zone: b.zone, label: copy[b.label], style: b.style, armed: dropArmed }, b.zone))) }), resizeHandles.map((handle) => (_jsx(ResizeHandle, { handle: handle, value: valueOf(handle), onDrag: moveHandle, onStep: (h, delta) => applyHandle(h, valueOf(h) + delta) }, handle.kind === HandleKind.Zone ? `z:${handle.zone}` : `p:${handle.panelId}`)))] }));
|
|
202
|
+
}), overlay === undefined || overlay === null ? null : (_jsx("div", { style: boxStyle(slots.find((slot) => slot.id === PAGE && slot.visible)?.box ?? WHOLE), className: "sc-overlay", children: overlay })), _jsx("div", { hidden: phone, className: "sc-drops", children: DROP_ZONES.map((b) => (_jsx(ZoneDropTarget, { zone: b.zone, label: copy[b.label], style: b.style, armed: dropArmed }, b.zone))) }), resizeHandles.map((handle) => (_jsx(ResizeHandle, { handle: handle, value: valueOf(handle), onDrag: moveHandle, onStep: (h, delta) => applyHandle(h, valueOf(h) + delta) }, handle.kind === HandleKind.Zone ? `z:${handle.zone}` : `p:${handle.panelId}`)))] }));
|
|
205
203
|
}
|
package/dist/shell/copy.d.ts
CHANGED
package/dist/shell/copy.js
CHANGED
|
@@ -33,6 +33,7 @@ export const ENGLISH_COMPOSER_COPY = {
|
|
|
33
33
|
back: (to) => `Back to ${to}`,
|
|
34
34
|
},
|
|
35
35
|
modal: { close: "Close" },
|
|
36
|
+
phone: { alsoOpen: "Also open" },
|
|
36
37
|
discard: {
|
|
37
38
|
title: "Discard the changes?",
|
|
38
39
|
detail: (names) => `What was typed in ${names.join(", ")} has not been saved.`,
|
|
@@ -93,6 +94,7 @@ export const SPANISH_COMPOSER_COPY = {
|
|
|
93
94
|
back: (to) => `Volver a ${to}`,
|
|
94
95
|
},
|
|
95
96
|
modal: { close: "Cerrar" },
|
|
97
|
+
phone: { alsoOpen: "También abiertos" },
|
|
96
98
|
discard: {
|
|
97
99
|
title: "¿Descartar los cambios?",
|
|
98
100
|
detail: (names) => `Lo escrito en ${names.join(", ")} no se guardó.`,
|
package/dist/shell/skin.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Size } from "../domain/index.js";
|
|
1
2
|
import { type IconProps } from "./icons.js";
|
|
2
3
|
import type { ComponentType, ReactNode } from "react";
|
|
3
4
|
/**
|
|
@@ -50,6 +51,10 @@ export type ModalProps = {
|
|
|
50
51
|
title: string;
|
|
51
52
|
/** Blur what it covers. Off unless the view that opened it asked. */
|
|
52
53
|
blur: boolean;
|
|
54
|
+
/** The size the view asked for, in pixels; what does not fit shrinks. */
|
|
55
|
+
size?: Size;
|
|
56
|
+
/** The workspace is a phone: draw it as a sheet from the bottom, not a window. */
|
|
57
|
+
phone: boolean;
|
|
53
58
|
onClose: () => void;
|
|
54
59
|
children: ReactNode;
|
|
55
60
|
};
|
package/dist/shell/styles.js
CHANGED
|
@@ -160,7 +160,7 @@ const CSS = `
|
|
|
160
160
|
}
|
|
161
161
|
.sc-modal-scrim[data-blur] { backdrop-filter: blur(var(--_modal-blur)); }
|
|
162
162
|
.sc-modal {
|
|
163
|
-
display: flex; flex-direction: column; width: min(28rem, 100%); max-height: 100%;
|
|
163
|
+
display: flex; flex-direction: column; width: min(28rem, 100%); max-width: 100%; max-height: 100%;
|
|
164
164
|
overflow: hidden; background: var(--_surface); border: 1px solid var(--_line-strong);
|
|
165
165
|
border-radius: var(--_radius); box-shadow: var(--_shadow); outline: 0;
|
|
166
166
|
}
|
|
@@ -175,6 +175,20 @@ const CSS = `
|
|
|
175
175
|
}
|
|
176
176
|
.sc-modal-body { flex: 1; min-height: 0; overflow: auto; container-type: inline-size; }
|
|
177
177
|
|
|
178
|
+
/* A phone: one screen. The drawer is the screen's width, the modal a sheet from the bottom. */
|
|
179
|
+
.sc-root[data-phone] .sc-peek { width: 100%; border-left: 0; border-radius: 0; }
|
|
180
|
+
.sc-modal-scrim[data-phone] { align-items: flex-end; padding: 0; }
|
|
181
|
+
.sc-modal-scrim[data-phone] .sc-modal {
|
|
182
|
+
width: 100%; max-height: 90%; border-bottom: 0;
|
|
183
|
+
border-radius: var(--_radius) var(--_radius) 0 0;
|
|
184
|
+
}
|
|
185
|
+
.sc-modal-scrim[data-phone] .sc-modal-head { cursor: default; }
|
|
186
|
+
.sc-dock {
|
|
187
|
+
display: flex; flex-shrink: 0; align-items: center; gap: 6px; padding: 6px 8px;
|
|
188
|
+
overflow-x: auto; background: var(--_ground); border-top: 1px solid var(--_line);
|
|
189
|
+
}
|
|
190
|
+
.sc-dock-label { flex-shrink: 0; color: var(--_muted); font-size: var(--_text-small); }
|
|
191
|
+
|
|
178
192
|
.sc-button {
|
|
179
193
|
display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 10px;
|
|
180
194
|
border: 1px solid var(--_line-strong); border-radius: var(--_radius-control);
|
package/dist/state/api.d.ts
CHANGED
|
@@ -37,5 +37,8 @@ export type ApiFactoryOptions = {
|
|
|
37
37
|
registry?: Registry;
|
|
38
38
|
/** Where `open(ref)` goes without a `to`. The page: what people expect of a click. */
|
|
39
39
|
defaultOpen?: Destination;
|
|
40
|
+
/** Whether the workspace is a phone right now — read at call time. On a phone a window or a
|
|
41
|
+
* side panel opens as the page, and a chooser as a modal (`domain/phone.ts`). */
|
|
42
|
+
isPhone?: () => boolean;
|
|
40
43
|
};
|
|
41
|
-
export declare function createApiFactory(store: WorkspaceStore, { registry, defaultOpen }?: ApiFactoryOptions): ApiFactory;
|
|
44
|
+
export declare function createApiFactory(store: WorkspaceStore, { registry, defaultOpen, isPhone }?: ApiFactoryOptions): ApiFactory;
|
package/dist/state/api.js
CHANGED
|
@@ -21,7 +21,7 @@ export function targetOf(id) {
|
|
|
21
21
|
/** A panel's or a modal's frame already says what it shows. One array, so it reads as
|
|
22
22
|
* «unchanged». */
|
|
23
23
|
const NO_CRUMBS = [];
|
|
24
|
-
export function createApiFactory(store, { registry, defaultOpen = Destination.Page } = {}) {
|
|
24
|
+
export function createApiFactory(store, { registry, defaultOpen = Destination.Page, isPhone = () => false } = {}) {
|
|
25
25
|
const cache = new Map();
|
|
26
26
|
const choosers = new Map();
|
|
27
27
|
const zoneFor = (spec) => spec?.preferredZone ?? Zone.Right;
|
|
@@ -51,11 +51,18 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
51
51
|
const now = model.refOn(store.get(), me);
|
|
52
52
|
return now !== null && model.sameRef(now, resource);
|
|
53
53
|
};
|
|
54
|
-
/** In a modal,
|
|
55
|
-
const
|
|
56
|
-
|
|
54
|
+
/** In a modal, what it was opened with stays when its view changes. */
|
|
55
|
+
const modalNow = () => {
|
|
56
|
+
const m = model.modalOver(store.get(), model.hostOf(me));
|
|
57
|
+
return { blur: m?.blur ?? false, ...(m?.size === undefined ? {} : { size: m.size }) };
|
|
58
|
+
};
|
|
59
|
+
function open(ref, asked, { blur, size } = {}) {
|
|
60
|
+
const to = isPhone() ? model.destinationOnPhone(asked) : asked;
|
|
57
61
|
if (to === Destination.Modal)
|
|
58
|
-
store.openModal(me, ref, {
|
|
62
|
+
store.openModal(me, ref, {
|
|
63
|
+
...(blur === undefined ? {} : { blur }),
|
|
64
|
+
...(size === undefined ? {} : { size }),
|
|
65
|
+
});
|
|
59
66
|
else if (to === Destination.Peek) {
|
|
60
67
|
if (inPeek)
|
|
61
68
|
store.drillPeek(ref);
|
|
@@ -63,7 +70,10 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
63
70
|
store.peek(ref);
|
|
64
71
|
}
|
|
65
72
|
else if (to === Destination.Window)
|
|
66
|
-
store.openPanel(ref,
|
|
73
|
+
store.openPanel(ref, {
|
|
74
|
+
zone: Zone.Floating,
|
|
75
|
+
...(size === undefined ? {} : { size }),
|
|
76
|
+
});
|
|
67
77
|
else if (to === Destination.Side)
|
|
68
78
|
store.openPanel(ref, zoneFor(registry?.resolve(ref) ?? null));
|
|
69
79
|
else
|
|
@@ -73,7 +83,7 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
73
83
|
if (target.surface === Surface.Panel)
|
|
74
84
|
store.navigatePanel(target.panelId, ref);
|
|
75
85
|
else if (inModal)
|
|
76
|
-
store.openModal(me, ref,
|
|
86
|
+
store.openModal(me, ref, modalNow());
|
|
77
87
|
else if (inPeek)
|
|
78
88
|
store.replacePeek(ref);
|
|
79
89
|
else
|
|
@@ -120,7 +130,7 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
120
130
|
over: inModal ? (model.modalOver(store.get(), target.host)?.over ?? null) : null,
|
|
121
131
|
context,
|
|
122
132
|
open: (ref, options) => open(ref, options?.to ??
|
|
123
|
-
(inPeek && defaultOpen === Destination.Page ? Destination.Peek : defaultOpen), options
|
|
133
|
+
(inPeek && defaultOpen === Destination.Page ? Destination.Peek : defaultOpen), options),
|
|
124
134
|
navigate: (to) => {
|
|
125
135
|
if (target.surface === Surface.Panel)
|
|
126
136
|
store.navigatePanel(target.panelId, to);
|
|
@@ -169,9 +179,10 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
169
179
|
setDirty: (dirty) => store.setDirty(me, resource, dirty),
|
|
170
180
|
select: (refs) => store.apply((w) => model.select(w, me, refs)),
|
|
171
181
|
pick: (ref, onPick, options) => {
|
|
172
|
-
const
|
|
182
|
+
const asked = options?.to ?? Destination.Window;
|
|
183
|
+
const to = isPhone() ? model.chooserOnPhone(asked) : asked;
|
|
173
184
|
if (to === Destination.Modal) {
|
|
174
|
-
open(ref, to, options
|
|
185
|
+
open(ref, to, options);
|
|
175
186
|
choosers.set(model.modalId(model.hostOf(me)), onPick);
|
|
176
187
|
return;
|
|
177
188
|
}
|
|
@@ -180,7 +191,7 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
180
191
|
choosers.set(PEEK, onPick);
|
|
181
192
|
return;
|
|
182
193
|
}
|
|
183
|
-
open(ref, to);
|
|
194
|
+
open(ref, to, options);
|
|
184
195
|
const id = store.get().focus;
|
|
185
196
|
if (id !== PAGE && id !== PEEK)
|
|
186
197
|
choosers.set(id, onPick);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sincpro/web-composer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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",
|