@1agh/maude 2.0.4 → 2.0.8
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/apps/hub/src/project-transactions/kernel.mjs +10 -1
- package/apps/studio/access/closure.ts +156 -16
- package/apps/studio/access/filters.ts +39 -5
- package/apps/studio/access/known-canvases.ts +24 -1
- package/apps/studio/access/refused-inputs.ts +89 -0
- package/apps/studio/actions/agents.ts +59 -0
- package/apps/studio/actions/ctx.ts +3 -0
- package/apps/studio/actions/defs/app.ts +12 -0
- package/apps/studio/actions/defs/sync.ts +13 -0
- package/apps/studio/actions/defs/view.ts +59 -3
- package/apps/studio/actions/keymap.gen.ts +35 -0
- package/apps/studio/actions/menu.ts +2 -0
- package/apps/studio/actions/types.ts +3 -1
- package/apps/studio/actions.manifest.json +148 -1
- package/apps/studio/actions.parity.json +31 -1
- package/apps/studio/annotations/ui/ai-seen.tsx +4 -3
- package/apps/studio/annotations/ui/element-node.tsx +139 -54
- package/apps/studio/annotations/ui/lod.tsx +1 -1
- package/apps/studio/annotations/ui/ride.ts +2 -1
- package/apps/studio/annotations/ui/text-style.ts +1 -1
- package/apps/studio/annotations-context-toolbar.tsx +5 -4
- package/apps/studio/annotations-layer.tsx +4 -15
- package/apps/studio/api.ts +425 -128
- package/apps/studio/artboard-activity-overlay.tsx +4 -4
- package/apps/studio/artboard-ai-copies.tsx +4 -4
- package/apps/studio/artboard-freeze.ts +108 -0
- package/apps/studio/artboard-live-gate.tsx +636 -0
- package/apps/studio/artboard-live.ts +831 -0
- package/apps/studio/artboard-placeholder.ts +197 -0
- package/apps/studio/artboard-still-raster.ts +485 -0
- package/apps/studio/artboard-still-warmup.ts +221 -0
- package/apps/studio/artboard-still.ts +1188 -0
- package/apps/studio/artboard-webgl.ts +669 -0
- package/apps/studio/asset-placeholder.tsx +237 -132
- package/apps/studio/asset-upload-bars.tsx +4 -4
- package/apps/studio/bin/_agent-browser-bin.mjs +8 -0
- package/apps/studio/bin/_agent-browser-safe.mjs +2 -1
- package/apps/studio/bin/_canvas-reasons.mjs +34 -0
- package/apps/studio/bin/_ds-check-live.mjs +37 -0
- package/apps/studio/bin/_ds-check.mjs +4 -1
- package/apps/studio/bin/_ds-prove-judge.mjs +167 -0
- package/apps/studio/bin/_ds-prove-playwright.mjs +183 -105
- package/apps/studio/bin/_import-asset.mjs +2 -1
- package/apps/studio/bin/_perf-probe-open.mjs +364 -0
- package/apps/studio/bin/_perf-probe.mjs +2 -1
- package/apps/studio/bin/_perf-shared.mjs +12 -7
- package/apps/studio/bin/_pw-launch.mjs +26 -1
- package/apps/studio/bin/_studio-verb.mjs +24 -3
- package/apps/studio/bin/_thumb-blank.mjs +70 -0
- package/apps/studio/bin/_thumb-cover.mjs +35 -0
- package/apps/studio/bin/_thumbs-playwright.mjs +89 -12
- package/apps/studio/bin/ds-check.sh +5 -1
- package/apps/studio/bin/perf.sh +30 -1
- package/apps/studio/bin/server-up.sh +7 -2
- package/apps/studio/bin/smoke.sh +19 -0
- package/apps/studio/bridge/dgn-protocol.ts +35 -0
- package/apps/studio/canvas-build-sandbox.ts +69 -13
- package/apps/studio/canvas-camera.ts +90 -0
- package/apps/studio/canvas-comment-mount.tsx +9 -9
- package/apps/studio/canvas-lib.tsx +289 -44
- package/apps/studio/canvas-pages-view.tsx +465 -0
- package/apps/studio/canvas-pages.ts +305 -0
- package/apps/studio/canvas-rows.ts +62 -0
- package/apps/studio/canvas-shell.tsx +62 -16
- package/apps/studio/canvas-theme-icons.tsx +41 -0
- package/apps/studio/canvas-theme-pill.tsx +15 -6
- package/apps/studio/canvas-theme.ts +12 -11
- package/apps/studio/client/app.jsx +7 -0
- package/apps/studio/client/canvas-url.js +36 -1
- package/apps/studio/client/home/HomeAccounts.jsx +262 -0
- package/apps/studio/client/home/Shelves.jsx +4 -3
- package/apps/studio/client/home/home-accounts-model.js +121 -0
- package/apps/studio/client/home/home-api.js +6 -0
- package/apps/studio/client/home/home-app.jsx +141 -40
- package/apps/studio/client/home/home-model.js +172 -6
- package/apps/studio/client/home/home.css +169 -5
- package/apps/studio/client/home/shell-mode.js +8 -1
- package/apps/studio/client/hooks/canvas-origin-probe.js +34 -0
- package/apps/studio/client/hooks/use-action-keys.jsx +3 -1
- package/apps/studio/client/hooks/use-canvas-bridge.jsx +1 -1
- package/apps/studio/client/hooks/use-palette-and-panels.jsx +23 -6
- package/apps/studio/client/hooks/use-photo-and-timeline.jsx +16 -8
- package/apps/studio/client/hooks/use-project-data.jsx +13 -2
- package/apps/studio/client/hooks/use-shell-core.jsx +19 -9
- package/apps/studio/client/index-loader.ts +41 -21
- package/apps/studio/client/inspector/inspector-panel.jsx +35 -14
- package/apps/studio/client/panels/ChatPanel.jsx +27 -20
- package/apps/studio/client/panels/CreateProject.jsx +19 -5
- package/apps/studio/client/panels/caps-cache.js +46 -0
- package/apps/studio/client/shell/viewport.jsx +66 -22
- package/apps/studio/client/tree/tree.jsx +17 -0
- package/apps/studio/client/v2/access/access-client.js +2 -0
- package/apps/studio/client/v2/access/access-host.jsx +12 -1
- package/apps/studio/client/v2/access/trashed-banner.jsx +6 -3
- package/apps/studio/client/v2/ai/Advanced.jsx +12 -0
- package/apps/studio/client/v2/ai/Composer.jsx +27 -10
- package/apps/studio/client/v2/canvases/canvases-panel.jsx +24 -0
- package/apps/studio/client/v2/canvases/use-canvas-index.js +24 -1
- package/apps/studio/client/v2/code/canvas-error-card.jsx +14 -2
- package/apps/studio/client/v2/code/canvas-imports-card.jsx +19 -14
- package/apps/studio/client/v2/code/canvas-imports-words.js +60 -0
- package/apps/studio/client/v2/code/canvas-waiting-card.jsx +59 -5
- package/apps/studio/client/v2/code/canvas-waiting.js +18 -1
- package/apps/studio/client/v2/code/code-bus.js +5 -0
- package/apps/studio/client/v2/code/code-consent-sheet.jsx +87 -0
- package/apps/studio/client/v2/code/code-consent.js +67 -0
- package/apps/studio/client/v2/diagnostics/sync-details/sync-details-model.js +62 -10
- package/apps/studio/client/v2/diagnostics/sync-details/sync-details.jsx +314 -5
- package/apps/studio/client/v2/ds/advanced-host.jsx +11 -26
- package/apps/studio/client/v2/ds/ds-refresh.js +161 -0
- package/apps/studio/client/v2/ds/library-host.jsx +45 -45
- package/apps/studio/client/v2/ds/make-host.jsx +13 -15
- package/apps/studio/client/v2/ds/off-system-host.jsx +18 -19
- package/apps/studio/client/v2/ds/review-host.jsx +7 -1
- package/apps/studio/client/v2/ds/truth-host.jsx +15 -17
- package/apps/studio/client/v2/ds/upgrade-host.jsx +26 -10
- package/apps/studio/client/v2/history/branch-actions.js +13 -9
- package/apps/studio/client/v2/history/git-advanced.jsx +8 -1
- package/apps/studio/client/v2/history/git-model.js +3 -1
- package/apps/studio/client/v2/history/git-parts.jsx +16 -1
- package/apps/studio/client/v2/layers/artboard-layers.jsx +24 -5
- package/apps/studio/client/v2/layers/layers-request.js +49 -0
- package/apps/studio/client/v2/left-panel/canvases-pinned.jsx +93 -3
- package/apps/studio/client/v2/left-panel/ds-boards.js +39 -0
- package/apps/studio/client/v2/left-panel/left-panel-model.js +13 -0
- package/apps/studio/client/v2/left-panel/left-panel.css +24 -0
- package/apps/studio/client/v2/presence/faces.jsx +42 -14
- package/apps/studio/client/v2/shell/account-card.jsx +10 -4
- package/apps/studio/client/v2/shell/canvas-crash-guard.js +172 -0
- package/apps/studio/client/v2/shell/canvas-mode.js +17 -1
- package/apps/studio/client/v2/shell/floating-panels.css +37 -1
- package/apps/studio/client/v2/shell/github-signin-host.jsx +42 -0
- package/apps/studio/client/v2/shell/menu-runner.js +11 -0
- package/apps/studio/client/v2/shell/mode-switch.jsx +14 -3
- package/apps/studio/client/v2/shell/opening-skeleton.js +118 -0
- package/apps/studio/client/v2/shell/opening-skeleton.jsx +103 -0
- package/apps/studio/client/v2/shell/pages-pick.js +49 -0
- package/apps/studio/client/v2/shell/project-account-card.jsx +203 -0
- package/apps/studio/client/v2/shell/project-account-model.js +182 -0
- package/apps/studio/client/v2/shell/project-menu-model.js +3 -0
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +140 -11
- package/apps/studio/client/v2/shell/share-cluster.css +58 -0
- package/apps/studio/client/v2/shell/share-cluster.jsx +26 -7
- package/apps/studio/client/v2/shell/shell-parity.json +8 -0
- package/apps/studio/client/v2/shell/team-switch.js +94 -0
- package/apps/studio/client/v2/shell/too-heavy-card.jsx +38 -0
- package/apps/studio/client/v2/shell/use-account.js +8 -1
- package/apps/studio/client/v2/shell/use-canvas-mode-lane.js +30 -0
- package/apps/studio/collab/persistence.ts +9 -1
- package/apps/studio/collab/registry.ts +32 -0
- package/apps/studio/collab/room.ts +8 -0
- package/apps/studio/comments-overlay.tsx +12 -11
- package/apps/studio/config-reload-wire.ts +56 -0
- package/apps/studio/config.schema.json +6 -0
- package/apps/studio/context.ts +37 -1
- package/apps/studio/dist/client.bundle.js +1198 -1198
- package/apps/studio/dist/comment-mount.js +2 -2
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds/board/board.css +6 -0
- package/apps/studio/ds/board/ds-bar.tsx +21 -3
- package/apps/studio/ds/board/specimen.tsx +16 -2
- package/apps/studio/ds/board/template.ts +39 -19
- package/apps/studio/ds/canvas-cli.ts +58 -2
- package/apps/studio/ds/check.ts +26 -1
- package/apps/studio/ds/cli.ts +14 -4
- package/apps/studio/ds/component-list.ts +2 -1
- package/apps/studio/ds/convert.ts +34 -6
- package/apps/studio/ds/default.ts +6 -1
- package/apps/studio/ds/ds-resolver.ts +58 -8
- package/apps/studio/ds/ds-verb.ts +13 -0
- package/apps/studio/ds/engine.ts +3 -1
- package/apps/studio/ds/folder-systems.ts +199 -0
- package/apps/studio/ds/pairing-css.ts +2 -1
- package/apps/studio/ds/post-build.ts +38 -0
- package/apps/studio/ds/rename.ts +10 -3
- package/apps/studio/ds/shell-fallbacks.ts +2 -1
- package/apps/studio/ds/upgrade-apply.ts +27 -5
- package/apps/studio/ds/upgrade-cli.ts +22 -2
- package/apps/studio/ds/upgrade-prove.ts +198 -15
- package/apps/studio/ds/upgrade-stage.ts +10 -3
- package/apps/studio/editing/ai-point-ring.tsx +4 -4
- package/apps/studio/editing/ai-scope-outline.tsx +4 -4
- package/apps/studio/editing/align-bar.tsx +4 -4
- package/apps/studio/editing/anchor-report.ts +3 -2
- package/apps/studio/editing/artboard-handles.tsx +4 -4
- package/apps/studio/editing/corner-dots.tsx +4 -4
- package/apps/studio/editing/crop-mode.tsx +4 -4
- package/apps/studio/editing/drop-chip.tsx +4 -4
- package/apps/studio/editing/empty-report.ts +3 -2
- package/apps/studio/editing/focus-model.tsx +4 -4
- package/apps/studio/editing/gap-bands.tsx +3 -3
- package/apps/studio/editing/hold-rings.tsx +4 -4
- package/apps/studio/editing/lock-badge.tsx +3 -3
- package/apps/studio/editing/long-page.ts +23 -1
- package/apps/studio/editing/nudge.tsx +2 -2
- package/apps/studio/editing/page-activity.ts +4 -3
- package/apps/studio/editing/paste-bar.tsx +4 -4
- package/apps/studio/editing/pen/overlay.tsx +4 -3
- package/apps/studio/editing/place-freely.tsx +3 -3
- package/apps/studio/editing/reorder-slot.tsx +3 -3
- package/apps/studio/editing/selection.tsx +4 -4
- package/apps/studio/editing/size-ghost.tsx +4 -4
- package/apps/studio/editing/tab-order.tsx +4 -4
- package/apps/studio/editing/text-in-place.tsx +4 -4
- package/apps/studio/editing/undo-preview.tsx +3 -3
- package/apps/studio/equal-spacing-handles.tsx +3 -3
- package/apps/studio/frame-clock.ts +89 -0
- package/apps/studio/history/trash.ts +6 -0
- package/apps/studio/home/accounts.ts +87 -0
- package/apps/studio/home/index-reader.ts +24 -2
- package/apps/studio/home/routes.ts +19 -0
- package/apps/studio/http.ts +80 -34
- package/apps/studio/index/ds-usage.ts +4 -1
- package/apps/studio/index-cache.ts +272 -0
- package/apps/studio/inspect-overlay.tsx +4 -3
- package/apps/studio/inspect.ts +7 -2
- package/apps/studio/link-chip-overlay.tsx +4 -3
- package/apps/studio/measure-overlay.tsx +4 -3
- package/apps/studio/present/pointer-dot.tsx +3 -2
- package/apps/studio/present/present-media.ts +6 -2
- package/apps/studio/present/present-stage.tsx +3 -2
- package/apps/studio/preview/preview-camera.tsx +3 -2
- package/apps/studio/routes/ds-convert.ts +18 -0
- package/apps/studio/routes/sync.ts +176 -0
- package/apps/studio/routes/trash.ts +16 -1
- package/apps/studio/safe-zones-overlay.tsx +3 -2
- package/apps/studio/server.ts +8 -10
- package/apps/studio/skip-dirs.ts +103 -47
- package/apps/studio/studio-page-host.ts +70 -0
- package/apps/studio/sync/accepted-cold-start.ts +28 -13
- package/apps/studio/sync/asset-push.ts +146 -23
- package/apps/studio/sync/asset-state.ts +3 -2
- package/apps/studio/sync/code-module-consent.ts +86 -0
- package/apps/studio/sync/file-ledger.ts +24 -0
- package/apps/studio/sync/file-membership.ts +28 -3
- package/apps/studio/sync/file-plane.ts +497 -61
- package/apps/studio/sync/file-pull.ts +304 -33
- package/apps/studio/sync/held-deletes.ts +230 -0
- package/apps/studio/sync/hub-link.ts +1 -2
- package/apps/studio/sync/hubs-config.ts +59 -2
- package/apps/studio/sync/index.ts +405 -163
- package/apps/studio/sync/journal-client.ts +94 -5
- package/apps/studio/sync/pending-deletes.ts +100 -0
- package/apps/studio/sync/projection.ts +77 -12
- package/apps/studio/sync/seed-progress.ts +104 -3
- package/apps/studio/sync/settings.ts +36 -1
- package/apps/studio/sync/status.ts +17 -1
- package/apps/studio/sync/writer-registry.ts +5 -0
- package/apps/studio/text-caret.ts +5 -3
- package/apps/studio/thumbs/service.ts +12 -2
- package/apps/studio/thumbs/validate.ts +7 -0
- package/apps/studio/toolbars/toolbar-rect.ts +3 -2
- package/apps/studio/ui-prefs-migrate.ts +4 -0
- package/apps/studio/use-annotation-resize.tsx +4 -3
- package/apps/studio/use-artboard-drag.tsx +3 -2
- package/apps/studio/use-element-resize.tsx +7 -6
- package/apps/studio/use-grid-track-handles.tsx +5 -4
- package/apps/studio/use-selection-set.tsx +64 -4
- package/apps/studio/use-spacing-handles.tsx +7 -6
- package/apps/studio/video-comp.tsx +75 -39
- package/apps/studio/video-play-overlay.tsx +4 -3
- package/apps/studio/whats-new.json +99 -0
- package/cli/commands/design.mjs +5 -2
- package/cli/commands/hub.mjs +10 -1
- package/cli/lib/bash-guard.mjs +27 -1
- package/cli/lib/design-help.gen.mjs +1 -1
- package/cli/lib/design-hook.mjs +20 -0
- package/cli/lib/design-link.mjs +42 -17
- package/cli/lib/hub-purge.mjs +183 -0
- package/cli/lib/studio-locate.mjs +35 -10
- package/package.json +8 -8
- package/plugins/design/templates/_shell.html +164 -1
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
// The canvas half of Canvas | Pages (2.0.7 B2, decision `v2-207-pages-view`) — the store and the pure rules are in
|
|
2
|
+
// canvas-pages.ts.
|
|
3
|
+
//
|
|
4
|
+
// usePagesView mounted once by CanvasCore (canvas-shell.tsx): keeps the page order current, leaves the one
|
|
5
|
+
// page in sight (a CSS rule keyed on `html[data-maude-pages]`), puts the camera on it (again on
|
|
6
|
+
// a resize or when the shell's panels move), hears PageDown / PageUp (and → / ← with nothing
|
|
7
|
+
// selected) through the registry, and tells the shell `pages-view` — again on every `set-mode`
|
|
8
|
+
// seed, so a newly active canvas is never mistaken for the last one.
|
|
9
|
+
// CanvasPagesSwitch the pill's Canvas | Pages and, in Pages, ‹ n / N › — also on the Design system canvas's bar
|
|
10
|
+
// (ds/board/ds-bar.tsx, `variant="ds"`; decision `v2-207-pages-on-ds-canvas`).
|
|
11
|
+
// runPagesAction the shell's `run-action` lane: `view.pages`, `pages.next`, `pages.prev` — and, while Pages
|
|
12
|
+
// shows, `view.zoom-to-artboard` turns to that artboard's page (`turnToPage`).
|
|
13
|
+
//
|
|
14
|
+
// A pick in the left panel (or a selection made anywhere) of an artboard Pages has out of sight turns to its page
|
|
15
|
+
// (decision `v2-207-pages-pick-turns-page`): the jump selects the artboard and frames it, and before 2.0.7 polish
|
|
16
|
+
// the camera and the selection box went to a hidden artboard — an empty frame.
|
|
17
|
+
|
|
18
|
+
import { useEffect, useRef, useSyncExternalStore } from 'react';
|
|
19
|
+
import { canvasInsets, canvasModeStore } from './bridge/canvas-mode-store.ts';
|
|
20
|
+
import type { ArtboardRect, ViewportControllerHandle } from './canvas-lib.tsx';
|
|
21
|
+
import {
|
|
22
|
+
getCanvasView,
|
|
23
|
+
getPageChosen,
|
|
24
|
+
getPagesState,
|
|
25
|
+
PAGES_ATTR,
|
|
26
|
+
PAGES_STYLE_ID,
|
|
27
|
+
pageCamera,
|
|
28
|
+
pageCounter,
|
|
29
|
+
pagesApply,
|
|
30
|
+
pagesHideCss,
|
|
31
|
+
pagesOrder,
|
|
32
|
+
setCanvasView,
|
|
33
|
+
setPageAt,
|
|
34
|
+
setPagesOrder,
|
|
35
|
+
stepPage,
|
|
36
|
+
subscribeCanvasView,
|
|
37
|
+
useCanvasView,
|
|
38
|
+
usePagePosition,
|
|
39
|
+
} from './canvas-pages.ts';
|
|
40
|
+
import type { PresentMeta } from './present/order.ts';
|
|
41
|
+
import { useCanvasKeys } from './use-canvas-keys.ts';
|
|
42
|
+
|
|
43
|
+
type Camera = { x: number; y: number; zoom: number };
|
|
44
|
+
|
|
45
|
+
const modeStore = () => (typeof window === 'undefined' ? null : canvasModeStore(window));
|
|
46
|
+
const noSub = () => () => {};
|
|
47
|
+
|
|
48
|
+
/** The shell's mode for this canvas (null on a free canvas), live. */
|
|
49
|
+
function useShellMode(): string | null {
|
|
50
|
+
const s = modeStore();
|
|
51
|
+
return useSyncExternalStore(
|
|
52
|
+
s ? s.subscribe : noSub,
|
|
53
|
+
() => s?.get().mode ?? null,
|
|
54
|
+
() => null
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The occluded insets' sequence, live — the panels moved, the page refits. */
|
|
59
|
+
function useInsetsSeq(): number {
|
|
60
|
+
const s = modeStore();
|
|
61
|
+
return useSyncExternalStore(
|
|
62
|
+
s ? s.subscribe : noSub,
|
|
63
|
+
() => s?.get().insetsSeq ?? -1,
|
|
64
|
+
() => -1
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const pageAtNow = () => getPagesState().at;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* `pages-view` to the studio (bridge/dgn-protocol.ts — active canvas only): on, which page of how many, and the
|
|
72
|
+
* artboard on it (`id`, only while on — the left panel marks it). Nothing outside the studio window.
|
|
73
|
+
*/
|
|
74
|
+
function tellShell(r: { on: boolean; index: number; total: number; id: string | null }): void {
|
|
75
|
+
if (typeof window === 'undefined' || window.parent === window) return;
|
|
76
|
+
try {
|
|
77
|
+
window.parent.postMessage(
|
|
78
|
+
{
|
|
79
|
+
dgn: 'pages-view',
|
|
80
|
+
v: 1,
|
|
81
|
+
on: r.on,
|
|
82
|
+
index: r.index,
|
|
83
|
+
total: r.total,
|
|
84
|
+
...(r.on && r.id ? { id: r.id } : {}),
|
|
85
|
+
},
|
|
86
|
+
'*'
|
|
87
|
+
);
|
|
88
|
+
} catch {
|
|
89
|
+
/* detached */
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Is Pages showing on this canvas right now? (The pill and the rule both ask.) */
|
|
94
|
+
export function usePagesShowing(here: boolean): boolean {
|
|
95
|
+
const view = useCanvasView();
|
|
96
|
+
const mode = useShellMode();
|
|
97
|
+
return here && view === 'pages' && pagesApply(mode);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** May the switch be offered here? (Edit or Viewing in the studio window — not Preview, Present, a capture.) */
|
|
101
|
+
export function usePagesAvailable(): boolean {
|
|
102
|
+
return pagesApply(useShellMode());
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** What the mounted canvas's Pages is doing, for the shell's lanes (one canvas per frame). */
|
|
106
|
+
const live: { on: boolean; fit: (() => void) | null } = { on: false, fit: null };
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Turn to artboard `id`'s page when Pages shows and has it; already on it, put the camera back on the page.
|
|
110
|
+
* True when Pages took it (the caller then leaves the camera alone).
|
|
111
|
+
*/
|
|
112
|
+
export function turnToPage(id: unknown): boolean {
|
|
113
|
+
if (!live.on || typeof id !== 'string' || !id) return false;
|
|
114
|
+
const { order, at } = getPagesState();
|
|
115
|
+
if (!order.includes(id)) return false;
|
|
116
|
+
if (at === id) live.fit?.();
|
|
117
|
+
else setPageAt(id);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* A pick (`select-by-id`: Layers, the Canvases tab, the AI, a restore) of artboard `id` while Pages shows: turn to its
|
|
123
|
+
* page when another one is showing (decision `v2-207-pages-stale-selection` — keyed on the pick, never on a change
|
|
124
|
+
* of the selected artboard, so the artboard that was selected before a page step turns back too). True when the
|
|
125
|
+
* page turned (the page's own camera follows; the caller leaves the camera alone). On its page already → false, and
|
|
126
|
+
* the pick reveals inside the page as always.
|
|
127
|
+
*/
|
|
128
|
+
export function pickTurnsPage(id: unknown): boolean {
|
|
129
|
+
if (!live.on || typeof id !== 'string' || !id) return false;
|
|
130
|
+
const { order, at } = getPagesState();
|
|
131
|
+
if (at === id || !order.includes(id)) return false;
|
|
132
|
+
setPageAt(id);
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** Tests only: leave the selection behind on a page turn, so a pick can be shown to turn back on its own. */
|
|
137
|
+
let dropOff = false;
|
|
138
|
+
export function __pagesDropOff(off: boolean): void {
|
|
139
|
+
dropOff = off;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function presentMeta(): PresentMeta | undefined {
|
|
143
|
+
if (typeof window === 'undefined') return undefined;
|
|
144
|
+
return (window as unknown as { __canvas_meta__?: { present?: PresentMeta } }).__canvas_meta__
|
|
145
|
+
?.present;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function ensureStyle(css: string | null): void {
|
|
149
|
+
if (typeof document === 'undefined') return;
|
|
150
|
+
let el = document.getElementById(PAGES_STYLE_ID) as HTMLStyleElement | null;
|
|
151
|
+
if (css === null) {
|
|
152
|
+
el?.remove();
|
|
153
|
+
document.documentElement.removeAttribute(PAGES_ATTR);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (!el) {
|
|
157
|
+
el = document.createElement('style');
|
|
158
|
+
el.id = PAGES_STYLE_ID;
|
|
159
|
+
(document.head ?? document.documentElement).appendChild(el);
|
|
160
|
+
}
|
|
161
|
+
if (el.textContent !== css) el.textContent = css;
|
|
162
|
+
document.documentElement.setAttribute(PAGES_ATTR, '');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface UsePagesViewOptions {
|
|
166
|
+
controller: ViewportControllerHandle | null;
|
|
167
|
+
artboards: readonly ArtboardRect[];
|
|
168
|
+
/** The selected artboard (or the one the selection is in) — where Pages opens; else the first page. */
|
|
169
|
+
selectedArtboard: () => string | null;
|
|
170
|
+
hostRef: { current: HTMLElement | null };
|
|
171
|
+
/** May Pages show on this canvas at all? (Not on the Design system canvas, an embed, a follower.) */
|
|
172
|
+
here: boolean;
|
|
173
|
+
/** What the canvas has selected, for the → / ← aliases (a selection's arrows nudge it). */
|
|
174
|
+
selectionNone: () => boolean;
|
|
175
|
+
/**
|
|
176
|
+
* The page showing is now `page`: drop whatever is selected on another artboard (decision
|
|
177
|
+
* `v2-207-pages-stale-selection`). Called synchronously on every page turn while Pages shows — keys, ‹ ›, a
|
|
178
|
+
* script, run-action, a left-panel jump, a layout change — so it must read the selection as of now, not a render.
|
|
179
|
+
*/
|
|
180
|
+
dropOffPage?: (page: string) => void;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function usePagesView(opts: UsePagesViewOptions): boolean {
|
|
184
|
+
const { controller, artboards, hostRef, here } = opts;
|
|
185
|
+
const selArt = useRef(opts.selectedArtboard);
|
|
186
|
+
selArt.current = opts.selectedArtboard;
|
|
187
|
+
const on = usePagesShowing(here);
|
|
188
|
+
live.on = on;
|
|
189
|
+
useEffect(
|
|
190
|
+
() => () => {
|
|
191
|
+
live.on = false;
|
|
192
|
+
},
|
|
193
|
+
[]
|
|
194
|
+
);
|
|
195
|
+
const at = useSyncExternalStore(subscribeCanvasView, pageAtNow, pageAtNow);
|
|
196
|
+
const insetsSeq = useInsetsSeq();
|
|
197
|
+
const ctlRef = useRef(controller);
|
|
198
|
+
ctlRef.current = controller;
|
|
199
|
+
/** The camera Canvas had when Pages came on (in this session), put back when it goes off. */
|
|
200
|
+
const savedCam = useRef<Camera | null>(null);
|
|
201
|
+
|
|
202
|
+
// the order, from the live layout and the Present order
|
|
203
|
+
const orderKey = artboards.map((r) => `${r.id}:${r.x}:${r.y}:${r.w}:${r.h}`).join('|');
|
|
204
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: orderKey is the layout's identity
|
|
205
|
+
useEffect(() => {
|
|
206
|
+
setPagesOrder(pagesOrder(artboards, presentMeta()));
|
|
207
|
+
}, [orderKey]);
|
|
208
|
+
|
|
209
|
+
// Pages comes on: open on the selected artboard (else where this session left off, else the first page), and keep
|
|
210
|
+
// the Canvas camera to put back
|
|
211
|
+
const wasOn = useRef(false);
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
if (on && !wasOn.current) {
|
|
214
|
+
const { order } = getPagesState();
|
|
215
|
+
const picked = selArt.current();
|
|
216
|
+
if (picked && order.includes(picked)) setPageAt(picked);
|
|
217
|
+
else if (!order.includes(getPageChosen() ?? '')) setPageAt(null);
|
|
218
|
+
const c = ctlRef.current?.viewport;
|
|
219
|
+
savedCam.current = c ? { x: c.x, y: c.y, zoom: c.zoom } : null;
|
|
220
|
+
}
|
|
221
|
+
if (!on && wasOn.current) {
|
|
222
|
+
const ctl = ctlRef.current;
|
|
223
|
+
if (ctl) {
|
|
224
|
+
if (savedCam.current) ctl.setViewport(savedCam.current);
|
|
225
|
+
else ctl.fit();
|
|
226
|
+
}
|
|
227
|
+
savedCam.current = null;
|
|
228
|
+
}
|
|
229
|
+
wasOn.current = on;
|
|
230
|
+
}, [on]);
|
|
231
|
+
|
|
232
|
+
// a selection made on another artboard (a left-panel pick, Layers, the AI) turns to its page: Pages never leaves
|
|
233
|
+
// the selection — or the camera the jump moves — on an artboard it hides
|
|
234
|
+
const selNow = opts.selectedArtboard();
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
if (!on || !selNow) return;
|
|
237
|
+
const { order, at: showing } = getPagesState();
|
|
238
|
+
if (selNow !== showing && order.includes(selNow)) setPageAt(selNow);
|
|
239
|
+
}, [on, selNow]);
|
|
240
|
+
|
|
241
|
+
// …and the other way round (decision `v2-207-pages-stale-selection`): a page turn by ANY route drops what is
|
|
242
|
+
// selected on the artboard it leaves — no outline on empty canvas, no Inspector naming a hidden artboard. What a
|
|
243
|
+
// real mouse click on › already did (that click lands on the canvas and clears); keys, a script click, run-action
|
|
244
|
+
// and a left-panel jump did not. Synchronous, in the store's own listener, so a pick that turns the page (it
|
|
245
|
+
// selected first) is read as it is now and kept.
|
|
246
|
+
const dropRef = useRef(opts.dropOffPage);
|
|
247
|
+
dropRef.current = opts.dropOffPage;
|
|
248
|
+
useEffect(() => {
|
|
249
|
+
let last = getPagesState().at;
|
|
250
|
+
return subscribeCanvasView(() => {
|
|
251
|
+
const now = getPagesState().at;
|
|
252
|
+
if (now === last) return;
|
|
253
|
+
last = now;
|
|
254
|
+
if (live.on && now && !dropOff) dropRef.current?.(now);
|
|
255
|
+
});
|
|
256
|
+
}, []);
|
|
257
|
+
useEffect(() => {
|
|
258
|
+
// Pages coming on opens on the selected artboard; anything else selected (a multi-selection) is off the page
|
|
259
|
+
const showing = getPagesState().at;
|
|
260
|
+
if (on && showing && !dropOff) dropRef.current?.(showing);
|
|
261
|
+
}, [on]);
|
|
262
|
+
|
|
263
|
+
// the rule that leaves the one page
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
ensureStyle(on && at ? pagesHideCss(at) : null);
|
|
266
|
+
return () => ensureStyle(null);
|
|
267
|
+
}, [on, at]);
|
|
268
|
+
|
|
269
|
+
// the camera on the page — again when the host resizes or the shell's panels move
|
|
270
|
+
const rect = at ? artboards.find((r) => r.id === at) : undefined;
|
|
271
|
+
const rectKey = rect ? `${rect.x}:${rect.y}:${rect.w}:${rect.h}` : '';
|
|
272
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: rectKey + insetsSeq are the fit's inputs
|
|
273
|
+
useEffect(() => {
|
|
274
|
+
if (!on || !rect) return undefined;
|
|
275
|
+
const host = hostRef.current;
|
|
276
|
+
const fit = () => {
|
|
277
|
+
const ctl = ctlRef.current;
|
|
278
|
+
if (!ctl || !host) return;
|
|
279
|
+
ctl.setViewport(
|
|
280
|
+
pageCamera(rect, { w: host.clientWidth, h: host.clientHeight }, canvasInsets())
|
|
281
|
+
);
|
|
282
|
+
};
|
|
283
|
+
fit();
|
|
284
|
+
live.fit = fit;
|
|
285
|
+
const unfit = () => {
|
|
286
|
+
if (live.fit === fit) live.fit = null;
|
|
287
|
+
};
|
|
288
|
+
if (!host || typeof ResizeObserver === 'undefined') return unfit;
|
|
289
|
+
const ro = new ResizeObserver(() => fit());
|
|
290
|
+
ro.observe(host);
|
|
291
|
+
return () => {
|
|
292
|
+
ro.disconnect();
|
|
293
|
+
unfit();
|
|
294
|
+
};
|
|
295
|
+
}, [on, at, rectKey, insetsSeq]);
|
|
296
|
+
|
|
297
|
+
// tell the shell (Preview and Present are off while Pages is on) — and again when it seeds this canvas
|
|
298
|
+
const pos = usePagePosition();
|
|
299
|
+
const index = pos?.index ?? 0;
|
|
300
|
+
const total = pos?.total ?? 0;
|
|
301
|
+
const id = pos ? at : null;
|
|
302
|
+
const report = useRef({ on, index, total, id });
|
|
303
|
+
report.current = { on, index, total, id };
|
|
304
|
+
useEffect(() => {
|
|
305
|
+
tellShell({ on, index, total, id });
|
|
306
|
+
}, [on, index, total, id]);
|
|
307
|
+
useEffect(() => {
|
|
308
|
+
if (typeof window === 'undefined' || window.parent === window) return undefined;
|
|
309
|
+
const onMsg = (e: MessageEvent) => {
|
|
310
|
+
if (e.source !== window.parent) return;
|
|
311
|
+
if ((e.data as { dgn?: unknown } | null)?.dgn !== 'set-mode') return;
|
|
312
|
+
tellShell(report.current);
|
|
313
|
+
};
|
|
314
|
+
window.addEventListener('message', onMsg);
|
|
315
|
+
return () => window.removeEventListener('message', onMsg);
|
|
316
|
+
}, []);
|
|
317
|
+
|
|
318
|
+
// the paging keys, from the registry (PageDown / PageUp; → / ← with nothing selected)
|
|
319
|
+
const selNone = useRef(opts.selectionNone);
|
|
320
|
+
selNone.current = opts.selectionNone;
|
|
321
|
+
useCanvasKeys(
|
|
322
|
+
{
|
|
323
|
+
'pages.next': (e) => {
|
|
324
|
+
if (getCanvasView() !== 'pages') return;
|
|
325
|
+
e.preventDefault();
|
|
326
|
+
stepPage('next');
|
|
327
|
+
},
|
|
328
|
+
'pages.prev': (e) => {
|
|
329
|
+
if (getCanvasView() !== 'pages') return;
|
|
330
|
+
e.preventDefault();
|
|
331
|
+
stepPage('prev');
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
{ selection: () => (selNone.current() ? 'none' : 'object') }
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
return on;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* The shell's `run-action` for Pages. True when the id was one of these (handled, or ignored in Preview/Present).
|
|
342
|
+
* `view.zoom-to-artboard` is Pages' only while it shows and has the artboard (it turns the page); else false, and the
|
|
343
|
+
* caller frames the artboard as always.
|
|
344
|
+
*/
|
|
345
|
+
export function runPagesAction(id: unknown, params?: { id?: unknown }): boolean {
|
|
346
|
+
if (id === 'view.zoom-to-artboard') return turnToPage(params?.id);
|
|
347
|
+
if (id === 'view.pages') {
|
|
348
|
+
if (!pagesApply(modeStore()?.get().mode ?? null)) return true;
|
|
349
|
+
setCanvasView(getCanvasView() === 'pages' ? 'canvas' : 'pages');
|
|
350
|
+
return true;
|
|
351
|
+
}
|
|
352
|
+
if (id === 'pages.next' || id === 'pages.prev') {
|
|
353
|
+
stepPage(id === 'pages.next' ? 'next' : 'prev');
|
|
354
|
+
return true;
|
|
355
|
+
}
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const SEG_WORD = { canvas: 'Canvas', pages: 'Pages' } as const;
|
|
360
|
+
const SEG_TITLE = {
|
|
361
|
+
canvas: 'The whole canvas',
|
|
362
|
+
pages: 'One artboard at a time',
|
|
363
|
+
} as const;
|
|
364
|
+
|
|
365
|
+
/** The two homes of the switch: the canvas pill (canvas-theme-pill.tsx) and the Design system bar (ds-bar.tsx). */
|
|
366
|
+
const SEG_CLASS = {
|
|
367
|
+
pill: { seg: 'dc-theme-pill-seg', b: 'dc-theme-pill-b' },
|
|
368
|
+
ds: { seg: 'ds-bar-seg', b: 'ds-bar-b' },
|
|
369
|
+
} as const;
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Canvas | Pages, and in Pages ‹ n / N ›, drawn in its host's own classes: the canvas pill's, or the Design system
|
|
373
|
+
* bar's (`variant="ds"`, which also brings the pager's chrome and steps aside where Pages cannot show — the pill
|
|
374
|
+
* itself is gone there).
|
|
375
|
+
*/
|
|
376
|
+
export function CanvasPagesSwitch({ variant = 'pill' }: { variant?: 'pill' | 'ds' } = {}) {
|
|
377
|
+
const view = useCanvasView();
|
|
378
|
+
const pos = usePagePosition();
|
|
379
|
+
const available = usePagesAvailable();
|
|
380
|
+
const pages = view === 'pages';
|
|
381
|
+
const cls = SEG_CLASS[variant];
|
|
382
|
+
if (variant === 'ds' && !available) return null;
|
|
383
|
+
return (
|
|
384
|
+
<>
|
|
385
|
+
{variant === 'ds' ? <style data-dc-pages-css="">{PAGES_PILL_CSS}</style> : null}
|
|
386
|
+
<fieldset className={cls.seg} aria-label="Show the canvas as" data-testid="canvas-view">
|
|
387
|
+
{(['canvas', 'pages'] as const).map((v) => (
|
|
388
|
+
<button
|
|
389
|
+
key={v}
|
|
390
|
+
type="button"
|
|
391
|
+
className={cls.b}
|
|
392
|
+
data-testid={`canvas-view-${v}`}
|
|
393
|
+
aria-pressed={view === v}
|
|
394
|
+
title={SEG_TITLE[v]}
|
|
395
|
+
onClick={() => setCanvasView(v)}
|
|
396
|
+
>
|
|
397
|
+
{SEG_WORD[v]}
|
|
398
|
+
</button>
|
|
399
|
+
))}
|
|
400
|
+
</fieldset>
|
|
401
|
+
{pages && pos ? (
|
|
402
|
+
// biome-ignore lint/a11y/useSemanticElements: a pager group of buttons, not a form
|
|
403
|
+
<span
|
|
404
|
+
className="dc-pages-nav"
|
|
405
|
+
role="group"
|
|
406
|
+
aria-label="Pages"
|
|
407
|
+
data-testid="canvas-pages-nav"
|
|
408
|
+
>
|
|
409
|
+
<button
|
|
410
|
+
type="button"
|
|
411
|
+
className="dc-pages-b"
|
|
412
|
+
data-testid="canvas-pages-prev"
|
|
413
|
+
aria-label="Previous page"
|
|
414
|
+
title="Previous page (PageUp)"
|
|
415
|
+
aria-keyshortcuts="PageUp"
|
|
416
|
+
disabled={pos ? pos.index === 0 : true}
|
|
417
|
+
onClick={() => stepPage('prev')}
|
|
418
|
+
>
|
|
419
|
+
<Chevron dir="prev" />
|
|
420
|
+
</button>
|
|
421
|
+
<span className="dc-pages-count" data-testid="canvas-pages-count" aria-live="polite">
|
|
422
|
+
{pageCounter(pos.index, pos.total)}
|
|
423
|
+
</span>
|
|
424
|
+
<button
|
|
425
|
+
type="button"
|
|
426
|
+
className="dc-pages-b"
|
|
427
|
+
data-testid="canvas-pages-next"
|
|
428
|
+
aria-label="Next page"
|
|
429
|
+
title="Next page (PageDown)"
|
|
430
|
+
aria-keyshortcuts="PageDown"
|
|
431
|
+
disabled={pos ? pos.index >= pos.total - 1 : true}
|
|
432
|
+
onClick={() => stepPage('next')}
|
|
433
|
+
>
|
|
434
|
+
<Chevron dir="next" />
|
|
435
|
+
</button>
|
|
436
|
+
</span>
|
|
437
|
+
) : null}
|
|
438
|
+
</>
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
function Chevron({ dir }: { dir: 'prev' | 'next' }) {
|
|
443
|
+
return (
|
|
444
|
+
<svg width="12" height="12" viewBox="0 0 16 16" fill="none" aria-hidden="true">
|
|
445
|
+
<polyline
|
|
446
|
+
points={dir === 'prev' ? '10 3.5 5.5 8 10 12.5' : '6 3.5 10.5 8 6 12.5'}
|
|
447
|
+
stroke="currentColor"
|
|
448
|
+
strokeWidth="2"
|
|
449
|
+
strokeLinecap="round"
|
|
450
|
+
strokeLinejoin="round"
|
|
451
|
+
/>
|
|
452
|
+
</svg>
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/** The pager's chrome, beside the pill's own (canvas-theme-pill.tsx `PILL_CSS`). */
|
|
457
|
+
export const PAGES_PILL_CSS = `
|
|
458
|
+
.dc-pages-nav{display:inline-flex;align-items:center;gap:2px;margin-left:4px}
|
|
459
|
+
.dc-pages-b{appearance:none;display:grid;place-items:center;width:28px;height:28px;border:0;border-radius:var(--maude-hud-radius-md,10px);background:transparent;color:var(--maude-chrome-fg-1);cursor:pointer}
|
|
460
|
+
.dc-pages-b:hover:not(:disabled){background:var(--maude-chrome-bg-3);color:var(--maude-chrome-fg-0)}
|
|
461
|
+
.dc-pages-b:disabled{opacity:.4;cursor:default}
|
|
462
|
+
.dc-pages-b:focus-visible{outline:2px solid var(--maude-hud-focus-ring);outline-offset:1px}
|
|
463
|
+
@media (max-width:1399px){html[data-maude-pages] .dc-theme-pill-path{display:none}}
|
|
464
|
+
.dc-pages-count{min-width:44px;text-align:center;font-variant-numeric:tabular-nums;font-size:var(--maude-hud-type-xs,11px);color:var(--maude-chrome-fg-0)}
|
|
465
|
+
`;
|