@sincpro/web-composer 1.1.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 +28 -4
- package/dist/domain/enums.d.ts +3 -0
- package/dist/domain/enums.js +3 -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 +28 -8
- package/dist/domain/url.d.ts +1 -1
- package/dist/domain/url.js +9 -6
- package/dist/domain/workspace.d.ts +58 -1
- package/dist/domain/workspace.js +87 -9
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/shell/Composer.d.ts +4 -1
- package/dist/shell/Composer.js +53 -14
- package/dist/shell/Modal.d.ts +18 -0
- package/dist/shell/Modal.js +81 -0
- package/dist/shell/PanelFrame.d.ts +4 -1
- package/dist/shell/PanelFrame.js +2 -2
- package/dist/shell/PanelHost.d.ts +3 -1
- package/dist/shell/PanelHost.js +12 -10
- package/dist/shell/copy.d.ts +6 -0
- package/dist/shell/copy.js +8 -4
- package/dist/shell/skin.d.ts +23 -0
- package/dist/shell/skin.js +1 -0
- package/dist/shell/styles.d.ts +1 -1
- package/dist/shell/styles.js +47 -1
- package/dist/state/api.d.ts +9 -1
- package/dist/state/api.js +55 -12
- package/dist/state/store.d.ts +5 -1
- package/dist/state/store.js +3 -1
- package/dist/state/useKeyboard.js +3 -1
- package/package.json +1 -1
package/dist/state/api.js
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
1
|
import * as model from "../domain/index.js";
|
|
2
2
|
import { Destination, formatRef, PAGE, PEEK, Surface, Zone, } from "../domain/index.js";
|
|
3
|
-
/** The id the workspace knows the surface by: `PAGE`, `PEEK
|
|
3
|
+
/** The id the workspace knows the surface by: `PAGE`, `PEEK`, the panel id or `modal:<host>`. */
|
|
4
4
|
const surfaceId = (target) => target.surface === Surface.Panel
|
|
5
5
|
? target.panelId
|
|
6
6
|
: target.surface === Surface.Peek
|
|
7
7
|
? PEEK
|
|
8
|
-
:
|
|
9
|
-
|
|
8
|
+
: target.surface === Surface.Modal
|
|
9
|
+
? model.modalId(target.host)
|
|
10
|
+
: PAGE;
|
|
11
|
+
/** The other way: the target of a surface the workspace knows by `id` — the focus, say. */
|
|
12
|
+
export function targetOf(id) {
|
|
13
|
+
if (id === PAGE)
|
|
14
|
+
return { surface: Surface.Page };
|
|
15
|
+
if (id === PEEK)
|
|
16
|
+
return { surface: Surface.Peek };
|
|
17
|
+
if (id.startsWith(model.MODAL))
|
|
18
|
+
return { surface: Surface.Modal, host: model.hostOf(id) };
|
|
19
|
+
return { surface: Surface.Panel, panelId: id };
|
|
20
|
+
}
|
|
21
|
+
/** A panel's or a modal's frame already says what it shows. One array, so it reads as
|
|
22
|
+
* «unchanged». */
|
|
10
23
|
const NO_CRUMBS = [];
|
|
11
|
-
export function createApiFactory(store, { registry, defaultOpen = Destination.Page } = {}) {
|
|
24
|
+
export function createApiFactory(store, { registry, defaultOpen = Destination.Page, isPhone = () => false } = {}) {
|
|
12
25
|
const cache = new Map();
|
|
13
26
|
const choosers = new Map();
|
|
14
27
|
const zoneFor = (spec) => spec?.preferredZone ?? Zone.Right;
|
|
@@ -32,20 +45,35 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
32
45
|
function build(resource, target) {
|
|
33
46
|
const me = surfaceId(target);
|
|
34
47
|
const inPeek = target.surface === Surface.Peek;
|
|
48
|
+
const inModal = target.surface === Surface.Modal;
|
|
35
49
|
/** Still showing what this API was lent for. */
|
|
36
50
|
const here = () => {
|
|
37
51
|
const now = model.refOn(store.get(), me);
|
|
38
52
|
return now !== null && model.sameRef(now, resource);
|
|
39
53
|
};
|
|
40
|
-
|
|
41
|
-
|
|
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;
|
|
61
|
+
if (to === Destination.Modal)
|
|
62
|
+
store.openModal(me, ref, {
|
|
63
|
+
...(blur === undefined ? {} : { blur }),
|
|
64
|
+
...(size === undefined ? {} : { size }),
|
|
65
|
+
});
|
|
66
|
+
else if (to === Destination.Peek) {
|
|
42
67
|
if (inPeek)
|
|
43
68
|
store.drillPeek(ref);
|
|
44
69
|
else
|
|
45
70
|
store.peek(ref);
|
|
46
71
|
}
|
|
47
72
|
else if (to === Destination.Window)
|
|
48
|
-
store.openPanel(ref,
|
|
73
|
+
store.openPanel(ref, {
|
|
74
|
+
zone: Zone.Floating,
|
|
75
|
+
...(size === undefined ? {} : { size }),
|
|
76
|
+
});
|
|
49
77
|
else if (to === Destination.Side)
|
|
50
78
|
store.openPanel(ref, zoneFor(registry?.resolve(ref) ?? null));
|
|
51
79
|
else
|
|
@@ -54,6 +82,8 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
54
82
|
function replace(ref) {
|
|
55
83
|
if (target.surface === Surface.Panel)
|
|
56
84
|
store.navigatePanel(target.panelId, ref);
|
|
85
|
+
else if (inModal)
|
|
86
|
+
store.openModal(me, ref, modalNow());
|
|
57
87
|
else if (inPeek)
|
|
58
88
|
store.replacePeek(ref);
|
|
59
89
|
else
|
|
@@ -85,7 +115,7 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
85
115
|
* equal labels on an equal trail are an equal breadcrumb. */
|
|
86
116
|
let last = null;
|
|
87
117
|
function crumbs() {
|
|
88
|
-
if (target.surface === Surface.Panel)
|
|
118
|
+
if (target.surface === Surface.Panel || inModal)
|
|
89
119
|
return NO_CRUMBS;
|
|
90
120
|
const next = freshCrumbs();
|
|
91
121
|
const key = `${store.get().trail.length}\u0000${next.map((c) => c.label).join("\u0000")}`;
|
|
@@ -97,12 +127,15 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
97
127
|
return {
|
|
98
128
|
self: resource,
|
|
99
129
|
surface: target.surface,
|
|
130
|
+
over: inModal ? (model.modalOver(store.get(), target.host)?.over ?? null) : null,
|
|
100
131
|
context,
|
|
101
132
|
open: (ref, options) => open(ref, options?.to ??
|
|
102
|
-
(inPeek && defaultOpen === Destination.Page ? Destination.Peek : defaultOpen)),
|
|
133
|
+
(inPeek && defaultOpen === Destination.Page ? Destination.Peek : defaultOpen), options),
|
|
103
134
|
navigate: (to) => {
|
|
104
135
|
if (target.surface === Surface.Panel)
|
|
105
136
|
store.navigatePanel(target.panelId, to);
|
|
137
|
+
else if (inModal)
|
|
138
|
+
replace(to);
|
|
106
139
|
else if (inPeek)
|
|
107
140
|
store.drillPeek(to);
|
|
108
141
|
else
|
|
@@ -130,6 +163,8 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
130
163
|
close: () => {
|
|
131
164
|
if (target.surface === Surface.Panel)
|
|
132
165
|
store.closePanel(target.panelId);
|
|
166
|
+
else if (inModal)
|
|
167
|
+
store.closeModal(me);
|
|
133
168
|
else if (inPeek)
|
|
134
169
|
store.closePeek();
|
|
135
170
|
else
|
|
@@ -144,13 +179,19 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
144
179
|
setDirty: (dirty) => store.setDirty(me, resource, dirty),
|
|
145
180
|
select: (refs) => store.apply((w) => model.select(w, me, refs)),
|
|
146
181
|
pick: (ref, onPick, options) => {
|
|
147
|
-
const
|
|
182
|
+
const asked = options?.to ?? Destination.Window;
|
|
183
|
+
const to = isPhone() ? model.chooserOnPhone(asked) : asked;
|
|
184
|
+
if (to === Destination.Modal) {
|
|
185
|
+
open(ref, to, options);
|
|
186
|
+
choosers.set(model.modalId(model.hostOf(me)), onPick);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
148
189
|
if (to === Destination.Peek) {
|
|
149
190
|
store.peek(ref);
|
|
150
191
|
choosers.set(PEEK, onPick);
|
|
151
192
|
return;
|
|
152
193
|
}
|
|
153
|
-
open(ref, to);
|
|
194
|
+
open(ref, to, options);
|
|
154
195
|
const id = store.get().focus;
|
|
155
196
|
if (id !== PAGE && id !== PEEK)
|
|
156
197
|
choosers.set(id, onPick);
|
|
@@ -162,7 +203,9 @@ export function createApiFactory(store, { registry, defaultOpen = Destination.Pa
|
|
|
162
203
|
/* Forget it BEFORE closing, so closing is not mistaken for anything else. */
|
|
163
204
|
choosers.delete(me);
|
|
164
205
|
onPick(value);
|
|
165
|
-
if (
|
|
206
|
+
if (inModal)
|
|
207
|
+
store.closeModal(me);
|
|
208
|
+
else if (inPeek)
|
|
166
209
|
store.closePeek();
|
|
167
210
|
else if (target.surface === Surface.Panel)
|
|
168
211
|
store.closePanel(target.panelId);
|
package/dist/state/store.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Dock, OpenPanelOptions, ResourceRef, WindowBox, Workspace, Zone } from "../domain/index.js";
|
|
1
|
+
import type { Dock, OpenModalOptions, OpenPanelOptions, ResourceRef, WindowBox, Workspace, Zone } from "../domain/index.js";
|
|
2
2
|
/**
|
|
3
3
|
* The pure reducers already are the state handling; this only binds them to the browser. An
|
|
4
4
|
* external store, not `useState`: with state in the component every action recreated the API
|
|
@@ -47,6 +47,10 @@ export type WorkspaceStore = {
|
|
|
47
47
|
closePeek: () => void;
|
|
48
48
|
peekToPage: () => void;
|
|
49
49
|
peekToSide: (zone?: Zone) => void;
|
|
50
|
+
/** `view` over `host` (`PAGE`, `PEEK`, a panel id — or a modal's id, to replace it), blocking
|
|
51
|
+
* only that surface. */
|
|
52
|
+
openModal: (host: string, view: ResourceRef, options?: OpenModalOptions) => void;
|
|
53
|
+
closeModal: (host: string) => void;
|
|
50
54
|
/** The name a view gives `ref` (see `api.setTitle`). */
|
|
51
55
|
setTitle: (ref: ResourceRef, title: string | null) => void;
|
|
52
56
|
/** `surface` (`PAGE`, `PEEK` or a panel id) has unsaved changes for `ref`. Ignored if it no
|
package/dist/state/store.js
CHANGED
|
@@ -87,7 +87,7 @@ export function createWorkspaceStore({ initial = model.EMPTY, hash = false, onCh
|
|
|
87
87
|
/** Runs `change`, asking first if it would throw away something unsaved. After a «yes» it
|
|
88
88
|
* runs again on the state of THEN — the answer may have taken a while. */
|
|
89
89
|
function run(change, mode) {
|
|
90
|
-
const next = change(state);
|
|
90
|
+
const next = model.settleModals(change(state));
|
|
91
91
|
if (next === state)
|
|
92
92
|
return;
|
|
93
93
|
const lost = lostIn(next);
|
|
@@ -182,6 +182,8 @@ export function createWorkspaceStore({ initial = model.EMPTY, hash = false, onCh
|
|
|
182
182
|
closePeek: () => go(model.closePeek),
|
|
183
183
|
peekToPage: () => go(model.peekToPage),
|
|
184
184
|
peekToSide: (zone) => go((w) => model.peekToSide(w, zone)),
|
|
185
|
+
openModal: (host, view, options) => go((w) => model.openModal(w, host, view, options), History.Replace),
|
|
186
|
+
closeModal: (host) => go((w) => model.closeModal(w, host), History.Replace),
|
|
185
187
|
setTitle: (ref, title) => go((w) => model.nameRef(w, ref, title), History.Replace),
|
|
186
188
|
setDirty: (surface, ref, on) => {
|
|
187
189
|
const shown = model.refOn(state, surface);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PAGE, PEEK } from "../domain/index.js";
|
|
1
|
+
import { MODAL, PAGE, PEEK } from "../domain/index.js";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
3
|
/** Inside a field only Escape survives. Stealing a key from someone who is typing is worse than
|
|
4
4
|
* having no shortcuts. */
|
|
@@ -52,6 +52,8 @@ export function useKeyboard({ workspace, enabled = true, onPalette }) {
|
|
|
52
52
|
else if (mod && e.shiftKey && e.code === "Backspace" && state.focus !== PAGE) {
|
|
53
53
|
if (state.focus === PEEK)
|
|
54
54
|
workspace.closePeek();
|
|
55
|
+
else if (state.focus.startsWith(MODAL))
|
|
56
|
+
workspace.closeModal(state.focus);
|
|
55
57
|
else
|
|
56
58
|
workspace.closePanel(state.focus);
|
|
57
59
|
e.preventDefault();
|
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",
|