@sincpro/web-composer 0.0.0-stage → 0.1.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.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +198 -2
  3. package/dist/domain/enums.d.ts +65 -0
  4. package/dist/domain/enums.js +56 -0
  5. package/dist/domain/index.d.ts +9 -0
  6. package/dist/domain/index.js +8 -0
  7. package/dist/domain/layout.d.ts +75 -0
  8. package/dist/domain/layout.js +180 -0
  9. package/dist/domain/palette.d.ts +42 -0
  10. package/dist/domain/palette.js +89 -0
  11. package/dist/domain/registry.d.ts +112 -0
  12. package/dist/domain/registry.js +37 -0
  13. package/dist/domain/resource.d.ts +21 -0
  14. package/dist/domain/resource.js +62 -0
  15. package/dist/domain/url.d.ts +3 -0
  16. package/dist/domain/url.js +107 -0
  17. package/dist/domain/workspace.d.ts +138 -0
  18. package/dist/domain/workspace.js +272 -0
  19. package/dist/index.d.ts +20 -0
  20. package/dist/index.js +19 -0
  21. package/dist/shell/Composer.d.ts +24 -0
  22. package/dist/shell/Composer.js +59 -0
  23. package/dist/shell/Palette.d.ts +9 -0
  24. package/dist/shell/Palette.js +123 -0
  25. package/dist/shell/PanelFrame.d.ts +31 -0
  26. package/dist/shell/PanelFrame.js +44 -0
  27. package/dist/shell/PanelHost.d.ts +23 -0
  28. package/dist/shell/PanelHost.js +188 -0
  29. package/dist/shell/RecordLink.d.ts +12 -0
  30. package/dist/shell/RecordLink.js +51 -0
  31. package/dist/shell/ViewHost.d.ts +11 -0
  32. package/dist/shell/ViewHost.js +42 -0
  33. package/dist/shell/copy.d.ts +64 -0
  34. package/dist/shell/copy.js +108 -0
  35. package/dist/state/api.d.ts +32 -0
  36. package/dist/state/api.js +140 -0
  37. package/dist/state/drag.d.ts +31 -0
  38. package/dist/state/drag.js +95 -0
  39. package/dist/state/store.d.ts +45 -0
  40. package/dist/state/store.js +76 -0
  41. package/dist/state/useKeyboard.d.ts +12 -0
  42. package/dist/state/useKeyboard.js +55 -0
  43. package/dist/state/useWorkspace.d.ts +23 -0
  44. package/dist/state/useWorkspace.js +34 -0
  45. package/package.json +82 -4
@@ -0,0 +1,89 @@
1
+ import { formatRef } from "./resource.js";
2
+ /**
3
+ * ⌘K in three layers: GO TO a screen, DO something with what I am on, and
4
+ * what each domain FOUND for the query. Pure on purpose — what the palette
5
+ * offers and how a query matches are tested without drawing it.
6
+ */
7
+ export const PaletteSection = {
8
+ Goto: "goto",
9
+ Actions: "actions",
10
+ Found: "found",
11
+ };
12
+ /** Shorter than this, every domain answers with half its table. */
13
+ export const MIN_QUERY = 2;
14
+ const fold = (text) => text
15
+ .normalize("NFD")
16
+ .replace(/\p{Diacritic}/gu, "")
17
+ .toLowerCase();
18
+ /** Every word of the query, in any order, ignoring accents and case:
19
+ * «facturacion» finds «Facturación», «nueva fac» finds «Nueva factura». */
20
+ export function matches(entry, query) {
21
+ const words = fold(query).split(/\s+/).filter(Boolean);
22
+ if (words.length === 0)
23
+ return true;
24
+ const keywords = entry.section === PaletteSection.Actions ? (entry.keywords ?? []) : [];
25
+ const detail = entry.section === PaletteSection.Actions ? "" : (entry.detail ?? "");
26
+ const haystack = fold([entry.label, detail, ...keywords].join(" "));
27
+ return words.every((word) => haystack.includes(word));
28
+ }
29
+ /** What is known without asking anyone: the screens, and the actions of the
30
+ * resource the user is on. */
31
+ export function localEntries(registry, focused) {
32
+ const goto = registry
33
+ .all()
34
+ .filter((spec) => spec.goto === true)
35
+ .map((spec) => {
36
+ const ref = { domain: spec.domain, kind: spec.kind };
37
+ return {
38
+ section: PaletteSection.Goto,
39
+ id: `goto:${formatRef(ref)}`,
40
+ label: spec.title(ref),
41
+ ...(spec.icon === undefined ? {} : { icon: spec.icon }),
42
+ ref,
43
+ };
44
+ });
45
+ const spec = focused === null ? null : registry.resolve(focused);
46
+ const actions = (focused === null ? [] : (spec?.actions?.(focused) ?? [])).map((action) => ({
47
+ section: PaletteSection.Actions,
48
+ id: `action:${action.id}`,
49
+ label: action.label,
50
+ ...(action.icon === undefined ? {} : { icon: action.icon }),
51
+ ...(action.shortcut === undefined ? {} : { shortcut: action.shortcut }),
52
+ ...(action.keywords === undefined ? {} : { keywords: action.keywords }),
53
+ action,
54
+ }));
55
+ return [...actions, ...goto];
56
+ }
57
+ /** Asks every domain that searches. A domain that fails is logged and left
58
+ * out; the others still answer. */
59
+ export async function searchEntries(registry, query) {
60
+ const text = query.trim();
61
+ if (text.length < MIN_QUERY)
62
+ return [];
63
+ const specs = registry.all().filter((spec) => spec.search !== undefined);
64
+ const answers = await Promise.allSettled(specs.map((spec) => spec.search(text)));
65
+ const seen = new Set();
66
+ const found = [];
67
+ answers.forEach((answer, i) => {
68
+ if (answer.status === "rejected") {
69
+ console.warn(`[composer] search failed in «${specs[i]?.domain}»`, answer.reason);
70
+ return;
71
+ }
72
+ for (const hit of answer.value) {
73
+ const id = `found:${formatRef(hit.ref)}`;
74
+ if (seen.has(id))
75
+ continue;
76
+ seen.add(id);
77
+ const icon = registry.resolve(hit.ref)?.icon;
78
+ found.push({
79
+ section: PaletteSection.Found,
80
+ id,
81
+ label: hit.label,
82
+ ...(hit.detail === undefined ? {} : { detail: hit.detail }),
83
+ ...(icon === undefined ? {} : { icon }),
84
+ ref: hit.ref,
85
+ });
86
+ }
87
+ });
88
+ return found;
89
+ }
@@ -0,0 +1,112 @@
1
+ import type { Destination, Surface, Zone } from "./enums.js";
2
+ import type { ResourceRef } from "./resource.js";
3
+ import type { ComponentType } from "react";
4
+ export { Surface } from "./enums.js";
5
+ /**
6
+ * Each domain declares itself. A `switch (ref.domain)` would force the host to import every
7
+ * domain, and one bundle would drag the others in.
8
+ */
9
+ export type OpenOptions = {
10
+ /** Where it opens. Without it, the workspace's default: the page. */
11
+ to?: Destination;
12
+ };
13
+ export type PickOptions = {
14
+ /** Where the chooser opens. A window unless said otherwise. */
15
+ to?: typeof Destination.Peek | typeof Destination.Window | typeof Destination.Side;
16
+ };
17
+ /** One step of a breadcrumb, ready for `List.Crumbs` or `Record.Crumbs`. */
18
+ export type Crumb = {
19
+ label: string;
20
+ onClick?: () => void;
21
+ };
22
+ /**
23
+ * What the workspace lends a view. It can open things and navigate; it cannot read the
24
+ * workspace — if it could, two domains would couple through it instead of through a reference.
25
+ */
26
+ export type WorkspaceApi = {
27
+ self: ResourceRef;
28
+ surface: Surface;
29
+ /** The one way to open a resource: `open(ref)` goes to the page, `open(ref, { to })` where
30
+ * the caller says. From a peek or a window, opening the page leaves it where it is. */
31
+ open: (ref: ResourceRef, options?: OpenOptions) => void;
32
+ /** Change what THIS surface shows, without opening anything. */
33
+ navigate: (ref: ResourceRef) => void;
34
+ /** One page back in the breadcrumb. */
35
+ back: () => void;
36
+ /** A window, a side panel or the peek grows into the page. Nothing on the page itself. */
37
+ expand: () => void;
38
+ /** Close the container: its panel or the peek drawer. */
39
+ close: () => void;
40
+ /** Request workspace focus so shortcuts talk to this view. */
41
+ focus: () => void;
42
+ /** The way here, ready to draw: the pages before this one, each a link, and this one. Empty
43
+ * outside the page: a panel's frame already says what it shows. */
44
+ crumbs: () => readonly Crumb[];
45
+ /** Publish what THIS surface has selected, so a detail panel or an assistant can follow it.
46
+ * An empty list clears it. */
47
+ select: (refs: readonly ResourceRef[]) => void;
48
+ /** What the user is working on — references only. Read-only on purpose. */
49
+ context: {
50
+ focused: () => ResourceRef | null;
51
+ selection: () => readonly ResourceRef[];
52
+ subscribe: (listener: () => void) => () => void;
53
+ };
54
+ /** Open `ref` as a chooser: when its view calls `answer`, `onPick` receives the value and
55
+ * the chooser closes. */
56
+ pick: (ref: ResourceRef, onPick: (value: ResourceRef) => void, options?: PickOptions) => void;
57
+ /** From a chooser: deliver the value to whoever asked, and close this surface. */
58
+ answer: (value: ResourceRef) => void;
59
+ };
60
+ /** Named `resource` rather than `ref` because `ref` is a reserved React prop. */
61
+ export type ViewProps = {
62
+ resource: ResourceRef;
63
+ api: WorkspaceApi;
64
+ };
65
+ type Icon = ComponentType<{
66
+ className?: string;
67
+ strokeWidth?: number;
68
+ }>;
69
+ /** Something a domain lets the user do with one of its resources: «Audit», «Reconcile».
70
+ * ⌘K offers the actions of the resource the user is on. */
71
+ export type Action = {
72
+ id: string;
73
+ label: string;
74
+ icon?: Icon;
75
+ /** Drawn, not bound: the palette is where the shortcut gets learned. */
76
+ shortcut?: string;
77
+ keywords?: readonly string[];
78
+ /** Receives the API of the surface the resource is on. */
79
+ run: (api: WorkspaceApi) => void;
80
+ };
81
+ /** A record a domain found for a ⌘K query. */
82
+ export type SearchHit = {
83
+ ref: ResourceRef;
84
+ label: string;
85
+ /** What tells two hits with the same label apart: the customer, the date. */
86
+ detail?: string;
87
+ };
88
+ export type ViewSpec = {
89
+ domain: string;
90
+ kind: string;
91
+ title: (ref: ResourceRef) => string;
92
+ icon?: Icon;
93
+ /** Where to open when asked beside the page with no zone. */
94
+ preferredZone?: Zone;
95
+ /** Listed under «Go to» in ⌘K, opened as `domain:kind` with no id. */
96
+ goto?: boolean;
97
+ actions?: (ref: ResourceRef) => readonly Action[];
98
+ /** ⌘K asks every domain that declares it; one that fails does not take the others'
99
+ * results with it. */
100
+ search?: (query: string) => Promise<readonly SearchHit[]>;
101
+ /** Lazy: the point where a remote module enters without changing anything else. */
102
+ load: () => Promise<ComponentType<ViewProps>>;
103
+ };
104
+ export type Registry = {
105
+ resolve: (ref: ResourceRef) => ViewSpec | null;
106
+ domains: () => readonly string[];
107
+ all: () => readonly ViewSpec[];
108
+ };
109
+ /** A function, not a singleton, so two workspaces with different domains can
110
+ * mount on the same page. */
111
+ export declare function createRegistry(specs: readonly ViewSpec[]): Registry;
112
+ export declare function loadView(spec: ViewSpec): Promise<ComponentType<ViewProps>>;
@@ -0,0 +1,37 @@
1
+ export { Surface } from "./enums.js";
2
+ const specKey = (spec) => `${spec.domain}:${spec.kind}`;
3
+ /** A function, not a singleton, so two workspaces with different domains can
4
+ * mount on the same page. */
5
+ export function createRegistry(specs) {
6
+ const byKey = new Map();
7
+ for (const spec of specs) {
8
+ const key = specKey(spec);
9
+ if (byKey.has(key)) {
10
+ console.warn(`[composer] ${key} is already registered; ignoring the duplicate`);
11
+ continue;
12
+ }
13
+ byKey.set(key, spec);
14
+ }
15
+ return {
16
+ resolve: (ref) => byKey.get(specKey(ref)) ?? null,
17
+ domains: () => [...new Set(specs.map((s) => s.domain))],
18
+ all: () => [...byKey.values()],
19
+ };
20
+ }
21
+ /**
22
+ * Cache against the `ViewSpec` object, not `domain:kind`. With a string key,
23
+ * two registries declaring the same pair — which `createRegistry` promises to
24
+ * allow — shared an entry and the second received the first's component.
25
+ *
26
+ * A failing module is not cached, so retry can work.
27
+ */
28
+ const modules = new WeakMap();
29
+ export function loadView(spec) {
30
+ const cached = modules.get(spec);
31
+ if (cached !== undefined)
32
+ return cached;
33
+ const loading = spec.load();
34
+ modules.set(spec, loading);
35
+ loading.catch(() => modules.delete(spec));
36
+ return loading;
37
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The workspace stores references, not data — that way one domain can carry a resource
3
+ * belonging to another without knowing its shape.
4
+ *
5
+ * Format: `domain:kind/id?param=value`
6
+ */
7
+ export type ResourceRef = {
8
+ domain: string;
9
+ kind: string;
10
+ id?: string;
11
+ params?: Readonly<Record<string, string>>;
12
+ };
13
+ export declare function isRef(value: unknown): value is ResourceRef;
14
+ /** Params are sorted so that two equivalent refs produce the same text and `sameRef` works. */
15
+ export declare function formatRef(ref: ResourceRef): string;
16
+ export declare function parseRef(text: string): ResourceRef | null;
17
+ export declare function sameRef(a: ResourceRef, b: ResourceRef): boolean;
18
+ /** Merges instead of replacing; almost always one param changes and the rest are kept. */
19
+ export declare function withParams(ref: ResourceRef, params: Record<string, string>): ResourceRef;
20
+ /** The resource with no params: tells whether two panels look at the same thing. */
21
+ export declare function rootRef(ref: ResourceRef): ResourceRef;
@@ -0,0 +1,62 @@
1
+ const SEGMENT = /^[A-Za-z0-9_.~-]+$/;
2
+ const REF = /^([^:]+):([^/?]+)(?:\/([^?]*))?(?:\?(.*))?$/;
3
+ function parseParams(query) {
4
+ const params = {};
5
+ for (const pair of query.split("&")) {
6
+ const eq = pair.indexOf("=");
7
+ if (eq > 0)
8
+ params[decodeURIComponent(pair.slice(0, eq))] = decodeURIComponent(pair.slice(eq + 1));
9
+ }
10
+ return params;
11
+ }
12
+ export function isRef(value) {
13
+ if (typeof value !== "object" || value === null)
14
+ return false;
15
+ const ref = value;
16
+ return (typeof ref.domain === "string" &&
17
+ SEGMENT.test(ref.domain) &&
18
+ typeof ref.kind === "string" &&
19
+ SEGMENT.test(ref.kind));
20
+ }
21
+ /** Params are sorted so that two equivalent refs produce the same text and `sameRef` works. */
22
+ export function formatRef(ref) {
23
+ const id = ref.id ? `/${encodeURIComponent(ref.id)}` : "";
24
+ const entries = Object.entries(ref.params ?? {})
25
+ .filter(([, v]) => v !== "")
26
+ .sort(([a], [b]) => a.localeCompare(b));
27
+ const query = entries.length
28
+ ? `?${entries.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join("&")}`
29
+ : "";
30
+ return `${ref.domain}:${ref.kind}${id}${query}`;
31
+ }
32
+ export function parseRef(text) {
33
+ const match = REF.exec(text);
34
+ if (!match)
35
+ return null;
36
+ const [, domain, kind, id, query] = match;
37
+ if (!domain || !kind || !SEGMENT.test(domain) || !SEGMENT.test(kind))
38
+ return null;
39
+ const params = query ? parseParams(query) : {};
40
+ return {
41
+ domain,
42
+ kind,
43
+ ...(id ? { id: decodeURIComponent(id) } : {}),
44
+ ...(Object.keys(params).length ? { params } : {}),
45
+ };
46
+ }
47
+ export function sameRef(a, b) {
48
+ return formatRef(a) === formatRef(b);
49
+ }
50
+ /** Merges instead of replacing; almost always one param changes and the rest are kept. */
51
+ export function withParams(ref, params) {
52
+ const merged = { ...(ref.params ?? {}), ...params };
53
+ for (const [key, value] of Object.entries(merged))
54
+ if (value === "")
55
+ delete merged[key];
56
+ const { params: _, ...rest } = ref;
57
+ return Object.keys(merged).length ? { ...rest, params: merged } : rest;
58
+ }
59
+ /** The resource with no params: tells whether two panels look at the same thing. */
60
+ export function rootRef(ref) {
61
+ return { domain: ref.domain, kind: ref.kind, ...(ref.id ? { id: ref.id } : {}) };
62
+ }
@@ -0,0 +1,3 @@
1
+ import { type Workspace } from "./workspace.js";
2
+ export declare function toHash(w: Workspace): string;
3
+ export declare function fromHash(hash: string): Workspace;
@@ -0,0 +1,107 @@
1
+ import { DOCKS, Zone } from "./enums.js";
2
+ import { formatRef, parseRef } from "./resource.js";
3
+ import { DEFAULT_ZONES, EMPTY, PAGE, } from "./workspace.js";
4
+ /**
5
+ * The URL carries what is worth sending a colleague so they see the same workspace — the page,
6
+ * the panels, the sizes — not the trail, the selection or what was typed.
7
+ *
8
+ * Separators are characters a reference cannot contain, because `formatRef` percent-encodes
9
+ * them: `;` between panels, `!` between a panel's fields, `,` inside a placement. The panel
10
+ * separator cannot be `+`: `URLSearchParams` decodes it as a space.
11
+ */
12
+ const FLAG = {
13
+ [Zone.Left]: "l",
14
+ [Zone.Right]: "r",
15
+ [Zone.Bottom]: "b",
16
+ };
17
+ const ZONE = { l: Zone.Left, r: Zone.Right, b: Zone.Bottom };
18
+ const n2 = (n) => n.toFixed(2);
19
+ function packPlacement(placement) {
20
+ const collapsed = placement.collapsed === true ? ",c" : "";
21
+ if (placement.zone === Zone.Floating) {
22
+ const { x, y, w, h, z } = placement;
23
+ return `f,${Math.round(x)},${Math.round(y)},${Math.round(w)},${Math.round(h)},${z}${collapsed}`;
24
+ }
25
+ return `${FLAG[placement.zone]},${n2(placement.share)}${collapsed}`;
26
+ }
27
+ function unpackPlacement(text) {
28
+ const [flag, ...rest] = text.split(",");
29
+ if (flag === "f") {
30
+ const [x, y, w, h, z] = rest.map(Number);
31
+ if ([x, y, w, h].some((v) => v === undefined || Number.isNaN(v)))
32
+ return null;
33
+ return {
34
+ zone: Zone.Floating,
35
+ x: x,
36
+ y: y,
37
+ w: w,
38
+ h: h,
39
+ z: z === undefined || Number.isNaN(z) ? 1 : z,
40
+ ...(rest.includes("c") ? { collapsed: true } : {}),
41
+ };
42
+ }
43
+ const zone = flag === undefined ? undefined : ZONE[flag];
44
+ const share = Number(rest[0]);
45
+ if (zone === undefined || rest[0] === undefined || Number.isNaN(share))
46
+ return null;
47
+ return rest.includes("c") ? { zone, share, collapsed: true } : { zone, share };
48
+ }
49
+ const packPanels = (panels) => panels.map((p) => `${p.id}!${formatRef(p.view)}!${packPlacement(p.placement)}`).join(";");
50
+ function unpackPanels(text) {
51
+ const panels = [];
52
+ for (const chunk of text.split(";")) {
53
+ const [id, refText, placementText] = chunk.split("!");
54
+ const view = refText === undefined ? null : parseRef(refText);
55
+ const placement = placementText === undefined ? null : unpackPlacement(placementText);
56
+ if (id !== undefined && id !== "" && view !== null && placement !== null)
57
+ panels.push({ id, view, placement });
58
+ }
59
+ return panels;
60
+ }
61
+ const packZones = (zones) => DOCKS.map((z) => n2(zones[z])).join(",");
62
+ function unpackZones(text) {
63
+ const values = text.split(",").map(Number);
64
+ const next = { ...DEFAULT_ZONES };
65
+ DOCKS.forEach((zone, i) => {
66
+ const v = values[i];
67
+ if (v !== undefined && !Number.isNaN(v))
68
+ next[zone] = v;
69
+ });
70
+ return next;
71
+ }
72
+ export function toHash(w) {
73
+ const parts = [];
74
+ if (w.page !== null)
75
+ parts.push(`p=${formatRef(w.page)}`);
76
+ if (w.panels.length > 0)
77
+ parts.push(`s=${packPanels(w.panels)}`);
78
+ parts.push(`z=${packZones(w.zones)}`);
79
+ if (w.peek !== null)
80
+ parts.push(`k=${formatRef(w.peek)}`);
81
+ if (w.focus !== PAGE)
82
+ parts.push(`f=${w.focus}`);
83
+ if (w.maximized !== null)
84
+ parts.push(`m=${w.maximized}`);
85
+ return `#/w?${parts.join("&")}`;
86
+ }
87
+ export function fromHash(hash) {
88
+ if (!hash.startsWith("#/w"))
89
+ return EMPTY;
90
+ const query = new URLSearchParams(hash.slice(hash.indexOf("?") + 1));
91
+ const page = query.get("p");
92
+ const peek = query.get("k");
93
+ const panels = unpackPanels(query.get("s") ?? "");
94
+ const focus = query.get("f");
95
+ const maximized = query.get("m");
96
+ const zones = query.get("z");
97
+ const has = (id) => id !== null && panels.some((p) => p.id === id);
98
+ return {
99
+ ...EMPTY,
100
+ page: page === null ? null : parseRef(page),
101
+ panels,
102
+ zones: zones === null ? DEFAULT_ZONES : unpackZones(zones),
103
+ peek: peek === null ? null : parseRef(peek),
104
+ focus: has(focus) ? focus : PAGE,
105
+ maximized: maximized === PAGE || has(maximized) ? maximized : null,
106
+ };
107
+ }
@@ -0,0 +1,138 @@
1
+ import { type Dock, DOCKS, Zone } from "./enums.js";
2
+ import { type ResourceRef } from "./resource.js";
3
+ export { DOCKS, Zone };
4
+ export type { Dock };
5
+ /**
6
+ * One page, and what is open around it.
7
+ *
8
+ * The PAGE is what I am working on — a list, a record — and its `trail` is the way I came, so a
9
+ * breadcrumb can take me back. Around it, any number of PANELS: docked beside it (`Side`) or
10
+ * floating over it (`Window`). A peek is a drawer to read without leaving.
11
+ *
12
+ * The space share lives in TWO places on purpose: `zones` is how much of the container each
13
+ * docked zone takes; `Placement.share` is how much of ITS zone a panel takes. Keeping it all
14
+ * in the panel made the size of the first one mean «the width of the zone» and the size of the
15
+ * rest mean nothing.
16
+ */
17
+ export type Placement = {
18
+ zone: Dock;
19
+ share: number;
20
+ collapsed?: boolean;
21
+ } | {
22
+ zone: typeof Zone.Floating;
23
+ x: number;
24
+ y: number;
25
+ w: number;
26
+ h: number;
27
+ z: number;
28
+ collapsed?: boolean;
29
+ };
30
+ export type Panel = {
31
+ id: string;
32
+ view: ResourceRef;
33
+ placement: Placement;
34
+ };
35
+ /** How much of the container each docked zone takes. */
36
+ export type Zones = Record<Dock, number>;
37
+ /** What a selection belongs to, and the references selected. */
38
+ export type Selected = {
39
+ by: string;
40
+ refs: readonly ResourceRef[];
41
+ };
42
+ export type Workspace = {
43
+ page: ResourceRef | null;
44
+ /** The pages I came through to reach `page`, oldest first. Session memory. */
45
+ trail: readonly ResourceRef[];
46
+ panels: readonly Panel[];
47
+ zones: Zones;
48
+ peek: ResourceRef | null;
49
+ /** `PAGE` or a panel id: who the shortcuts talk to. Not the browser's focus, which lives
50
+ * inside the view, almost always in a field. */
51
+ focus: string;
52
+ /** A panel id, or `PAGE`. It takes the whole workspace while it lasts. */
53
+ maximized: string | null;
54
+ /** The last selection any surface published. A chat or a detail panel follows THIS, not the
55
+ * focus: clicking into the chat must not make it lose what it was following. */
56
+ selected: Selected | null;
57
+ };
58
+ /** The page is not a panel and has no id; it needs one so it can be focused and maximized. */
59
+ export declare const PAGE = "page";
60
+ export declare const DEFAULT_ZONES: Zones;
61
+ /** Outside these limits one of the two sides stops being usable. */
62
+ export declare const MIN_ZONE = 0.12;
63
+ export declare const MAX_ZONE = 0.72;
64
+ export declare const MIN_SHARE = 0.12;
65
+ export declare const EMPTY: Workspace;
66
+ export declare const findPanel: (w: Workspace, id: string) => Panel | null;
67
+ export declare const panelsIn: (w: Workspace, zone: Zone) => readonly Panel[];
68
+ /**
69
+ * Opens `view` as the page and keeps where I was, so the breadcrumb can take me back. The first
70
+ * page has nothing behind it. When there is nothing to change it returns THE SAME object —
71
+ * every reducer here does, and that is what makes it possible to subscribe to a part of the
72
+ * workspace: if every call returned a new one, any action would redraw everything.
73
+ */
74
+ export declare function push(w: Workspace, view: ResourceRef): Workspace;
75
+ /** Back to the page at `index` of the trail; the pages after it are dropped. A crumb is this. */
76
+ export declare function goTo(w: Workspace, index: number): Workspace;
77
+ /** One page back. Nothing to go back to is not an error: it changes nothing. */
78
+ export declare const back: (w: Workspace) => Workspace;
79
+ export type OpenPanelOptions = {
80
+ zone?: Zone;
81
+ /** Deduplicating is the right default for a column and the wrong one for «the same table
82
+ * with two filters». */
83
+ allowDuplicate?: boolean;
84
+ };
85
+ /** Opens a resource as a panel. If it is already open it moves it to the requested zone and
86
+ * focuses it, unless a duplicate is explicitly asked for. */
87
+ export declare function openPanel(w: Workspace, view: ResourceRef, options?: Zone | OpenPanelOptions): Workspace;
88
+ export declare function movePanel(w: Workspace, id: string, zone: Zone): Workspace;
89
+ /** Closing the maximized or the focused one has to give the rest back, or the workspace ends
90
+ * up empty with panels inside it. */
91
+ export declare function closePanel(w: Workspace, id: string): Workspace;
92
+ /** Changes what a panel looks at without moving or closing it. */
93
+ export declare function navigatePanel(w: Workspace, id: string, view: ResourceRef): Workspace;
94
+ /** How much of the container a docked zone takes. */
95
+ export declare function resizeZone(w: Workspace, zone: Dock, size: number): Workspace;
96
+ /**
97
+ * How much of ITS zone a panel takes. What it gains it takes from the neighbour below, like
98
+ * any divider between two panels: moving a handle has to affect both sides and nobody else.
99
+ */
100
+ export declare function resizePanel(w: Workspace, id: string, share: number): Workspace;
101
+ export type WindowBox = Partial<{
102
+ x: number;
103
+ y: number;
104
+ w: number;
105
+ h: number;
106
+ }>;
107
+ /** Moves or resizes a window. */
108
+ export declare function floatPanel(w: Workspace, id: string, box: WindowBox): Workspace;
109
+ /** Bring to front. Without this, two overlapping windows cannot be pulled apart. */
110
+ export declare function raisePanel(w: Workspace, id: string): Workspace;
111
+ /** Collapse to its header without closing it: still there, still mounted, taking no room. */
112
+ export declare function collapsePanel(w: Workspace, id: string): Workspace;
113
+ /** Take the whole workspace. Calling it on what is already maximized gives it back. */
114
+ export declare function maximize(w: Workspace, target: string | null): Workspace;
115
+ /** The WORKSPACE focus, which is who the shortcuts talk to. Opening a panel focuses it. */
116
+ export declare function focusPanel(w: Workspace, target: string): Workspace;
117
+ /** The next one in reading order: the page, then each panel. */
118
+ export declare function cycleFocus(w: Workspace, delta: number): Workspace;
119
+ /**
120
+ * A panel grows into the page: its resource becomes the page, with the previous page in the
121
+ * breadcrumb, and the panel is gone. «Enlarge» that keeps where you came from.
122
+ */
123
+ export declare function expandPanel(w: Workspace, id: string): Workspace;
124
+ export declare function peek(w: Workspace, view: ResourceRef): Workspace;
125
+ export declare const closePeek: (w: Workspace) => Workspace;
126
+ /** The peek becomes the page. */
127
+ export declare function peekToPage(w: Workspace): Workspace;
128
+ /** It docks to the right because the drawer was already there and the piece does not move. */
129
+ export declare function peekToSide(w: Workspace, zone?: Zone): Workspace;
130
+ /**
131
+ * What a surface has selected — the rows of a list. The workspace keeps only references, so a
132
+ * chat in another domain can read them without knowing what they are. Selecting nothing clears
133
+ * it only if that surface owned it.
134
+ */
135
+ export declare function select(w: Workspace, by: string, refs: readonly ResourceRef[]): Workspace;
136
+ /** What the user is working on: the page, or the panel that has the focus. */
137
+ export declare function focusedRef(w: Workspace): ResourceRef | null;
138
+ export declare const selectionOf: (w: Workspace) => readonly ResourceRef[];