@elytracms/studio 0.0.63 → 0.0.64
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/dist/components/builder/canvas-chrome-css.d.ts +54 -0
- package/dist/components/builder/canvas-chrome-css.js +164 -0
- package/dist/components/builder/canvas-chrome-css.js.map +1 -0
- package/dist/components/builder/canvas-chrome.d.ts +122 -18
- package/dist/components/builder/canvas-chrome.js +148 -82
- package/dist/components/builder/canvas-chrome.js.map +1 -1
- package/dist/components/builder/canvas-render-context.d.ts +13 -0
- package/dist/components/builder/canvas-render-context.js +7 -5
- package/dist/components/builder/canvas-render-context.js.map +1 -1
- package/dist/components/builder/canvas-stylesheet.d.ts +1 -1
- package/dist/components/builder/canvas-stylesheet.js +16 -9
- package/dist/components/builder/canvas-stylesheet.js.map +1 -1
- package/dist/components/builder/canvas-theme-notice.d.ts +6 -0
- package/dist/components/builder/canvas-theme-notice.js +46 -0
- package/dist/components/builder/canvas-theme-notice.js.map +1 -0
- package/dist/components/builder/canvas.js +17 -10
- package/dist/components/builder/canvas.js.map +1 -1
- package/dist/components/builder/rich-text-toolbar.d.ts +23 -0
- package/dist/components/builder/rich-text-toolbar.js +24 -17
- package/dist/components/builder/rich-text-toolbar.js.map +1 -1
- package/dist/components/builder/spacing-handles.d.ts +31 -0
- package/dist/components/builder/spacing-handles.js +49 -37
- package/dist/components/builder/spacing-handles.js.map +1 -1
- package/dist/components/components/component-preview.d.ts +2 -1
- package/dist/components/components/component-preview.js +24 -25
- package/dist/components/components/component-preview.js.map +1 -1
- package/dist/lib/i18n/messages.de.js +4 -0
- package/dist/lib/i18n/messages.de.js.map +1 -1
- package/dist/lib/i18n/messages.en.d.ts +4 -0
- package/dist/lib/i18n/messages.en.js +5 -0
- package/dist/lib/i18n/messages.en.js.map +1 -1
- package/dist/lib/persistence/backend-mode.d.ts +7 -0
- package/dist/lib/persistence/backend-mode.js +9 -0
- package/dist/lib/persistence/backend-mode.js.map +1 -1
- package/dist/lib/persistence/index.d.ts +1 -1
- package/dist/lib/persistence/index.js +1 -1
- package/dist/lib/persistence/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canvas-theme-notice.js","sourceRoot":"","sources":["../../../src/components/builder/canvas-theme-notice.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChC,OAAO,EAAE,aAAa,EAAE,CAAC,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,mCAAmC,CAAA;AAChE,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAGhD;;;;;;;;;;;;;;GAcG;AAEH,MAAM,cAAc,GAAG,IAAI,GAAG,EAA6B,CAAA;AAE3D,sDAAsD;AACtD,MAAM,UAAU,8BAA8B;IAC5C,cAAc,CAAC,KAAK,EAAE,CAAA;AACxB,CAAC;AAED,MAAM,WAAW,GAAuD;IACtE,MAAM,EAAE,kCAAkC;IAC1C,kBAAkB,EAAE,2CAA2C;IAC/D,iBAAiB,EAAE,yCAAyC;IAC5D,eAAe,EAAE,wCAAwC;CAC1D,CAAA;AAED,MAAM,UAAU,iBAAiB,CAAC,EAAE,MAAM,EAAwC;IAChF,+EAA+E;IAC/E,MAAM,CAAC,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;IACtC,IAAI,CAAC,MAAM,IAAI,CAAC,YAAY,EAAE;QAAE,OAAO,IAAI,CAAA;IAC3C,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC3C,IAAI,CAAC,UAAU,IAAI,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAA;IAE/D,OAAO,CACL,6BACc,qBAAqB,sBACf,MAAM,CAAC,IAAI,EAC7B,SAAS,EAAC,4EAA4E,YAEtF,cAAK,SAAS,EAAC,kFAAkF,YAC/F,MAAC,GAAG,IAAC,GAAG,EAAC,GAAG,EAAC,KAAK,EAAC,OAAO,aACxB,KAAC,aAAa,IAAC,SAAS,EAAC,uCAAuC,wBAAe,EAC/E,KAAC,IAAI,IAAC,IAAI,EAAC,IAAI,EAAC,SAAS,EAAC,gBAAgB,YACvC,SAAS,CAAC,UAAU,CAAC,GACjB,EACP,iBACE,IAAI,EAAC,QAAQ,gBACD,SAAS,CAAC,gBAAgB,CAAC,EACvC,OAAO,EAAE,GAAG,EAAE;4BACZ,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;4BAC/B,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;wBAC5B,CAAC,EACD,SAAS,EAAC,mFAAmF,YAE7F,KAAC,CAAC,IAAC,SAAS,EAAC,UAAU,GAAG,GACnB,IACL,GACF,GACF,CACP,CAAA;AACH,CAAC","sourcesContent":["import { useState } from 'react'\nimport { AlertTriangle, X } from 'lucide-react'\nimport { translate } from '@elytracms/studio/lib/i18n'\nimport { isDevRuntime } from '@elytracms/studio/lib/persistence'\nimport { Row, Text } from '@elytracms/studio/ui'\nimport type { CanvasThemeStatus } from './canvas-chrome'\n\n/**\n * EC-414 AD-D item 2 — the canvas-theme runtime notice, in the established\n * validation-surface style (the `ClipboardNoticeOverlay` shape: a dismissible,\n * NEVER-blocking overlay above the canvas, in the STUDIO document — studio UI\n * primitives are fine here, this is not in-frame chrome). Dev builds only:\n *\n * - `legacy`: the probe found the merged pre-EC-414 canvas.css — a one-time\n * notice naming the migration (the canvas keeps working exactly as before).\n * - `stylesheet-error` / `no-theme-tokens` / `no-stylesheet`: the canvas\n * stylesheet is broken or missing — the invalid state is named explicitly\n * instead of silently rendering unstyled blocks.\n *\n * \"One-time\": dismissing a kind suppresses it for the rest of the studio\n * session (module state survives canvas remounts/navigation).\n */\n\nconst dismissedKinds = new Set<CanvasThemeStatus['kind']>()\n\n/** Test hook: reset the session-sticky dismissals. */\nexport function resetCanvasThemeNoticeForTests(): void {\n dismissedKinds.clear()\n}\n\nconst NOTICE_KEYS: Partial<Record<CanvasThemeStatus['kind'], string>> = {\n legacy: 'builder.canvasTheme.legacyNotice',\n 'stylesheet-error': 'builder.canvasTheme.stylesheetErrorNotice',\n 'no-theme-tokens': 'builder.canvasTheme.noThemeTokensNotice',\n 'no-stylesheet': 'builder.canvasTheme.noStylesheetNotice',\n}\n\nexport function CanvasThemeNotice({ status }: { status: CanvasThemeStatus | null }) {\n // Local state only forces the re-render on dismiss; the truth is module-level.\n const [, setDismissedAt] = useState(0)\n if (!status || !isDevRuntime()) return null\n const messageKey = NOTICE_KEYS[status.kind]\n if (!messageKey || dismissedKinds.has(status.kind)) return null\n\n return (\n <div\n data-testid=\"canvas-theme-notice\"\n data-notice-kind={status.kind}\n className=\"absolute top-4 left-1/2 z-20 w-max max-w-[min(460px,90%)] -translate-x-1/2\"\n >\n <div className=\"rounded-lg border border-border bg-popover p-2 text-popover-foreground shadow-lg\">\n <Row gap=\"2\" align=\"start\">\n <AlertTriangle className=\"mt-0.5 size-3.5 shrink-0 text-warning\" aria-hidden />\n <Text size=\"xs\" className=\"min-w-0 flex-1\">\n {translate(messageKey)}\n </Text>\n <button\n type=\"button\"\n aria-label={translate('common.dismiss')}\n onClick={() => {\n dismissedKinds.add(status.kind)\n setDismissedAt(Date.now())\n }}\n className=\"shrink-0 rounded p-0.5 text-muted-foreground hover:bg-muted hover:text-foreground\"\n >\n <X className=\"size-3.5\" />\n </button>\n </Row>\n </div>\n </div>\n )\n}\n"]}
|
|
@@ -7,7 +7,8 @@ import { getStudioRegistry } from '@elytracms/studio/lib/registry';
|
|
|
7
7
|
import { translate } from '@elytracms/studio/lib/i18n';
|
|
8
8
|
import { getInstantiatedKit } from '@elytracms/studio/lib/starters/kit-session';
|
|
9
9
|
import { resolveDeploymentCanvasTheme } from '@elytracms/studio/lib/workspace';
|
|
10
|
-
import {
|
|
10
|
+
import { wireCanvasChrome } from './canvas-chrome.js';
|
|
11
|
+
import { CanvasThemeNotice } from './canvas-theme-notice.js';
|
|
11
12
|
import { getCanvasStylesheetUrl } from './canvas-stylesheet.js';
|
|
12
13
|
import { useBuilder } from './builder-store.js';
|
|
13
14
|
import { useCanvasViewports, viewportWidth } from './canvas-breakpoints.js';
|
|
@@ -48,6 +49,9 @@ export function BuilderCanvas({ perspective = 'draft', } = {}) {
|
|
|
48
49
|
// (EC-117) — injected after app.css so the kit's overrides win in the cascade.
|
|
49
50
|
const params = useParams({ strict: false });
|
|
50
51
|
const kitTokensCss = params.projectId ? getInstantiatedKit(params.projectId)?.tokensCss : undefined;
|
|
52
|
+
// EC-414 AD-D: the settled canvas-theme classification (legacy merged shape /
|
|
53
|
+
// broken stylesheet) drives the dev-only, never-blocking notice overlay.
|
|
54
|
+
const [themeStatus, setThemeStatus] = useState(null);
|
|
51
55
|
const wireUp = useCallback(() => {
|
|
52
56
|
const d = iframeRef.current?.contentDocument;
|
|
53
57
|
if (!d || !d.body)
|
|
@@ -57,18 +61,21 @@ export function BuilderCanvas({ perspective = 'draft', } = {}) {
|
|
|
57
61
|
// as a light, site-like page — never the studio chrome's current theme (a
|
|
58
62
|
// black canvas is exactly what leaks through when the studio is
|
|
59
63
|
// dark-themed and the iframe root inherits that class). The injected
|
|
60
|
-
// canvas stylesheet
|
|
61
|
-
//
|
|
62
|
-
//
|
|
64
|
+
// canvas stylesheet (new world: the chrome's neutral backdrop; legacy
|
|
65
|
+
// world: the studio `:root` tokens) supplies that backdrop once `.dark` is
|
|
66
|
+
// never added here (mirrors the components-preview surface, which wires
|
|
67
|
+
// through the same chrome). The editing chrome (selection/hover outlines,
|
|
63
68
|
// drop indicators, the rich-text toolbar, locale-fallback chips) uses
|
|
64
|
-
// hardcoded colors rather than
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
//
|
|
68
|
-
applyCanvasChrome
|
|
69
|
+
// hardcoded colors rather than tokens, so it stays visible against a light
|
|
70
|
+
// page regardless. The full injection — stylesheet link, editing chrome,
|
|
71
|
+
// kit tokens, the consumer's `defineStudio({ canvas })` theme (EC-389,
|
|
72
|
+
// injected LAST so it wins), and the EC-414 world probe — lives in
|
|
73
|
+
// `wireCanvasChrome`/`applyCanvasChrome`.
|
|
74
|
+
wireCanvasChrome(d, {
|
|
69
75
|
stylesheetUrl: getCanvasStylesheetUrl(),
|
|
70
76
|
kitTokensCss,
|
|
71
77
|
theme: resolveDeploymentCanvasTheme(),
|
|
78
|
+
onStatus: (status) => setThemeStatus((prev) => (prev?.kind === status.kind ? prev : status)),
|
|
72
79
|
});
|
|
73
80
|
setDoc(d);
|
|
74
81
|
}, [kitTokensCss]);
|
|
@@ -146,7 +153,7 @@ export function BuilderCanvas({ perspective = 'draft', } = {}) {
|
|
|
146
153
|
// (Tailwind defaults when unconfigured), the same resolved set the toolbar
|
|
147
154
|
// switcher offers.
|
|
148
155
|
const { viewports } = useCanvasViewports();
|
|
149
|
-
return (_jsxs("div", { className: "canvas-grid relative flex min-h-0 flex-1 items-stretch justify-center overflow-auto p-6", children: [_jsx(ClipboardNoticeOverlay, {}), _jsxs("div", { style: { width: viewportWidth(viewports, builder.viewport), maxWidth: '100%' }, className: "flex", children: [_jsx("iframe", { ref: iframeRef, onLoad: wireUp, title: translate('builder.canvas.pagePreview'), className: "min-h-[480px] w-full rounded-lg border border-border bg-background shadow-md", srcDoc: "<!doctype html><html><head></head><body></body></html>" }), doc
|
|
156
|
+
return (_jsxs("div", { className: "canvas-grid relative flex min-h-0 flex-1 items-stretch justify-center overflow-auto p-6", children: [_jsx(ClipboardNoticeOverlay, {}), _jsx(CanvasThemeNotice, { status: themeStatus }), _jsxs("div", { style: { width: viewportWidth(viewports, builder.viewport), maxWidth: '100%' }, className: "flex", children: [_jsx("iframe", { ref: iframeRef, onLoad: wireUp, title: translate('builder.canvas.pagePreview'), className: "min-h-[480px] w-full rounded-lg border border-border bg-background shadow-md", srcDoc: "<!doctype html><html><head></head><body></body></html>" }), doc
|
|
150
157
|
? createPortal(
|
|
151
158
|
// Render the composition root directly (EC-287: no layout
|
|
152
159
|
// indirection — a page renders its blocks).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../../src/components/builder/canvas.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAA;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAChE,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,qBAAqB,CAAA;AAC5B,OAAO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AE,SAAS,EACd,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,SAAS,CAAC,4BAA4B,CAAC,EAC9C,SAAS,EAAC,8EAA8E,EACxF,MAAM,EAAC,wDAAwD,GAC/D,EACD,GAAG;wBACF,CAAC,CAAC,YAAY;wBACV,0DAA0D;wBAC1D,4CAA4C;wBAC5C,qBAAqB,CAAC,UAAU,EAAE,GAAG,CAAC,EACtC,GAAG,CAAC,IAAI,CACT;wBACH,CAAC,CAAC,IAAI,EACP,aAAa,IAAI,GAAG,CAAC,CAAC,CAAC,CACtB,KAAC,cAAc,IAAwB,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,IAA/C,aAAa,CAAC,EAAE,CAAmC,CACzE,CAAC,CAAC,CAAC,IAAI,EAEP,YAAY,IAAI,GAAG,CAAC,CAAC,CAAC,KAAC,eAAe,IAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,GAAI,CAAC,CAAC,CAAC,IAAI,IAC3E,IACF,CACP,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\nimport { renderPageComposition } from '@elytracms/core/runtime-renderer'\nimport type { ComponentNode } from '@elytracms/core/project-graph'\nimport { useParams } from '@elytracms/studio/router'\nimport { getStudioRegistry } from '@elytracms/studio/lib/registry'\nimport { translate } from '@elytracms/studio/lib/i18n'\nimport type { CanvasPerspective } from '@elytracms/studio/lib/data'\nimport { getInstantiatedKit } from '@elytracms/studio/lib/starters/kit-session'\nimport { resolveDeploymentCanvasTheme } from '@elytracms/studio/lib/workspace'\nimport { applyCanvasChrome } from './canvas-chrome'\nimport { getCanvasStylesheetUrl } from './canvas-stylesheet'\nimport { useBuilder } from './builder-store'\nimport { useCanvasViewports, viewportWidth } from './canvas-breakpoints'\nimport { nodeIdAt } from './canvas-dom'\nimport { useCanvasDnd } from './canvas-dnd'\nimport { useCanvasInlineEditing } from './canvas-inline-editing'\nimport { useCanvasRenderContext } from './canvas-render-context'\nimport {\n ClipboardNoticeOverlay,\n attachClipboardListeners,\n useStudioClipboard,\n} from './clipboard-actions'\nimport { RichTextToolbar } from './rich-text-toolbar'\nimport { SpacingHandles, hasSpacingHandles } from './spacing-handles'\n\n\n/**\n * Iframe-isolated page preview (brief §8.2, EC-061, EC-064). The graph renders\n * into a same-origin iframe via a React portal — true style isolation + true\n * responsive widths. Each node is wrapped with an editable marker so clicks\n * select and hover/selection draw outlines. Native listeners bridge the iframe\n * boundary (React's synthetic events don't cross frames); the two big gesture\n * state machines live in their own tested modules (EC-330): drag & drop in\n * `canvas-dnd`, inline text/rich-text editing in `canvas-inline-editing`, and\n * the render-context assembly in `canvas-render-context`.\n */\nexport function BuilderCanvas({\n perspective = 'draft',\n}: {\n /** Resolve references against this perspective (EC-300/AD-16). The editable Draft\n * view passes `'draft'` (a just-made reusable shows immediately); the read-only\n * Published view passes `'published'` (honest preview of what delivery serves). */\n perspective?: CanvasPerspective\n} = {}) {\n const builder = useBuilder()\n const { dispatch } = builder\n const studio = getStudioRegistry()\n\n // The edited composition root, composed for preview. EC-287 retired the project\n // graph and its published-graph preview; the canvas always renders the live,\n // editable draft (content publishing is per document).\n const activeRoot: ComponentNode = builder.present\n const iframeRef = useRef<HTMLIFrameElement>(null)\n const [doc, setDoc] = useState<Document | null>(null)\n\n // Graph/selection refs let the native iframe listeners read the *current*\n // state without re-subscribing on every edit.\n const presentRef = useRef(builder.present)\n presentRef.current = builder.present\n const selectedIdRef = useRef(builder.selectedId)\n selectedIdRef.current = builder.selectedId\n\n // When the project was created from a starter kit, its brand token palette drives the canvas UI\n // (EC-117) — injected after app.css so the kit's overrides win in the cascade.\n const params = useParams({ strict: false }) as { projectId?: string }\n const kitTokensCss = params.projectId ? getInstantiatedKit(params.projectId)?.tokensCss : undefined\n\n const wireUp = useCallback(() => {\n const d = iframeRef.current?.contentDocument\n if (!d || !d.body) return\n // Deliberately no `.dark` here: this iframe renders the REAL page (plus\n // studio editing chrome portaled alongside it), and its backdrop must read\n // as a light, site-like page — never the studio chrome's current theme (a\n // black canvas is exactly what leaks through when the studio is\n // dark-themed and the iframe root inherits that class). The injected\n // canvas stylesheet's `:root` (light) tokens supply that backdrop for free\n // once `.dark` is never added here (mirrors the components-preview fix,\n // `component-preview.tsx`). The editing chrome (selection/hover outlines,\n // drop indicators, the rich-text toolbar, locale-fallback chips) uses\n // hardcoded colors rather than these tokens, so it stays visible against a\n // light page regardless. The full injection — stylesheet link, editing\n // chrome, kit tokens, and the consumer's `defineStudio({ canvas })` theme\n // (EC-389, injected LAST so it wins) — lives in `applyCanvasChrome`.\n applyCanvasChrome(d, {\n stylesheetUrl: getCanvasStylesheetUrl(),\n kitTokensCss,\n theme: resolveDeploymentCanvasTheme(),\n })\n setDoc(d)\n }, [kitTokensCss])\n\n // Handle the already-loaded case (srcDoc may load before onLoad attaches).\n useEffect(() => {\n if (iframeRef.current?.contentDocument?.readyState === 'complete') wireUp()\n }, [wireUp])\n\n // Inline editing (EC-158/EC-159): the dblclick-to-edit state machine, the\n // live session ref other listeners consult, the rich-text host (mark\n // toolbar), and the per-node remount epochs (decorate keys).\n const inline = useCanvasInlineEditing(doc, { presentRef, dispatch, studio })\n const { editingRef, richEditHost, richEditEpochs } = inline\n\n // Native selection/hover listeners inside the iframe document.\n useEffect(() => {\n if (!doc) return\n const onClick = (e: Event) => {\n // Clicks inside the active inline editor are caret moves, not selection.\n if (editingRef.current?.host.contains(e.target as Node)) return\n const id = nodeIdAt(e.target)\n if (id) {\n e.preventDefault()\n dispatch({ type: 'select', id })\n }\n }\n const onOver = (e: Event) => dispatch({ type: 'hover', id: nodeIdAt(e.target) })\n const onLeave = () => dispatch({ type: 'hover', id: null })\n doc.addEventListener('click', onClick, true)\n doc.addEventListener('mouseover', onOver)\n doc.addEventListener('mouseleave', onLeave, true)\n return () => {\n doc.removeEventListener('click', onClick, true)\n doc.removeEventListener('mouseover', onOver)\n doc.removeEventListener('mouseleave', onLeave, true)\n }\n }, [doc, dispatch, editingRef])\n\n // Drag & drop on the canvas (EC-160/EC-162) — see `canvas-dnd`.\n useCanvasDnd(doc, { presentRef, dispatch, studio, editingRef })\n\n // Copy/cut/paste on the canvas (EC-175): the same studio clipboard the page\n // tree and blocks panel use, wired to the *iframe* document (events never\n // cross frames). Shortcuts stay inert while an inline editor is live and in\n // form fields; the iframe's own navigator.clipboard does the async I/O\n // (Chromium scopes clipboard access to the focused document).\n const clipboard = useStudioClipboard()\n useEffect(() => {\n if (!doc) return\n return attachClipboardListeners(doc, {\n clipboard,\n getSelectedId: () => selectedIdRef.current,\n isBlocked: () => editingRef.current !== null,\n asyncClipboard: doc.defaultView?.navigator.clipboard,\n getSelection: () => doc.getSelection(),\n })\n }, [doc, clipboard, editingRef])\n\n // The render context: the seven delivery-parity resolvers + the editable-\n // wrapper decorator (selection/hover, locale chips, remount epochs) — see\n // `canvas-render-context`.\n const { ctx, pageNodeIds } = useCanvasRenderContext({\n present: builder.present,\n selectedId: builder.selectedId,\n hoveredId: builder.hoveredId,\n studio,\n perspective,\n richEditEpochs,\n })\n\n // Tokenized spacing handles (EC-163): a selected Stack/Grid with 2+ children\n // gets draggable gap handles between them, portaled into the iframe.\n const spacingTarget =\n doc && hasSpacingHandles(builder.selectedNode) && pageNodeIds.has(builder.selectedNode.id)\n ? builder.selectedNode\n : null\n\n // EC-250: the preview frame width derives from the config-sourced breakpoints\n // (Tailwind defaults when unconfigured), the same resolved set the toolbar\n // switcher offers.\n const { viewports } = useCanvasViewports()\n\n return (\n <div className=\"canvas-grid relative flex min-h-0 flex-1 items-stretch justify-center overflow-auto p-6\">\n {/* Copy/cut/paste outcomes (EC-175): non-blocking, with issue deep links. */}\n <ClipboardNoticeOverlay />\n <div style={{ width: viewportWidth(viewports, builder.viewport), maxWidth: '100%' }} className=\"flex\">\n <iframe\n ref={iframeRef}\n onLoad={wireUp}\n title={translate('builder.canvas.pagePreview')}\n className=\"min-h-[480px] w-full rounded-lg border border-border bg-background shadow-md\"\n srcDoc=\"<!doctype html><html><head></head><body></body></html>\"\n />\n {doc\n ? createPortal(\n // Render the composition root directly (EC-287: no layout\n // indirection — a page renders its blocks).\n renderPageComposition(activeRoot, ctx),\n doc.body,\n )\n : null}\n {spacingTarget && doc ? (\n <SpacingHandles key={spacingTarget.id} doc={doc} node={spacingTarget} />\n ) : null}\n {/* Floating mark toolbar for the live rich-text session (EC-159). */}\n {richEditHost && doc ? <RichTextToolbar doc={doc} host={richEditHost} /> : null}\n </div>\n </div>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"canvas.js","sourceRoot":"","sources":["../../../src/components/builder/canvas.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAExE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AAEtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAC/E,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAA;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAElD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACxE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C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ent":["import { useCallback, useEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\nimport { renderPageComposition } from '@elytracms/core/runtime-renderer'\nimport type { ComponentNode } from '@elytracms/core/project-graph'\nimport { useParams } from '@elytracms/studio/router'\nimport { getStudioRegistry } from '@elytracms/studio/lib/registry'\nimport { translate } from '@elytracms/studio/lib/i18n'\nimport type { CanvasPerspective } from '@elytracms/studio/lib/data'\nimport { getInstantiatedKit } from '@elytracms/studio/lib/starters/kit-session'\nimport { resolveDeploymentCanvasTheme } from '@elytracms/studio/lib/workspace'\nimport { wireCanvasChrome } from './canvas-chrome'\nimport type { CanvasThemeStatus } from './canvas-chrome'\nimport { CanvasThemeNotice } from './canvas-theme-notice'\nimport { getCanvasStylesheetUrl } from './canvas-stylesheet'\nimport { useBuilder } from './builder-store'\nimport { useCanvasViewports, viewportWidth } from './canvas-breakpoints'\nimport { nodeIdAt } from './canvas-dom'\nimport { useCanvasDnd } from './canvas-dnd'\nimport { useCanvasInlineEditing } from './canvas-inline-editing'\nimport { useCanvasRenderContext } from './canvas-render-context'\nimport {\n ClipboardNoticeOverlay,\n attachClipboardListeners,\n useStudioClipboard,\n} from './clipboard-actions'\nimport { RichTextToolbar } from './rich-text-toolbar'\nimport { SpacingHandles, hasSpacingHandles } from './spacing-handles'\n\n\n/**\n * Iframe-isolated page preview (brief §8.2, EC-061, EC-064). The graph renders\n * into a same-origin iframe via a React portal — true style isolation + true\n * responsive widths. Each node is wrapped with an editable marker so clicks\n * select and hover/selection draw outlines. Native listeners bridge the iframe\n * boundary (React's synthetic events don't cross frames); the two big gesture\n * state machines live in their own tested modules (EC-330): drag & drop in\n * `canvas-dnd`, inline text/rich-text editing in `canvas-inline-editing`, and\n * the render-context assembly in `canvas-render-context`.\n */\nexport function BuilderCanvas({\n perspective = 'draft',\n}: {\n /** Resolve references against this perspective (EC-300/AD-16). The editable Draft\n * view passes `'draft'` (a just-made reusable shows immediately); the read-only\n * Published view passes `'published'` (honest preview of what delivery serves). */\n perspective?: CanvasPerspective\n} = {}) {\n const builder = useBuilder()\n const { dispatch } = builder\n const studio = getStudioRegistry()\n\n // The edited composition root, composed for preview. EC-287 retired the project\n // graph and its published-graph preview; the canvas always renders the live,\n // editable draft (content publishing is per document).\n const activeRoot: ComponentNode = builder.present\n const iframeRef = useRef<HTMLIFrameElement>(null)\n const [doc, setDoc] = useState<Document | null>(null)\n\n // Graph/selection refs let the native iframe listeners read the *current*\n // state without re-subscribing on every edit.\n const presentRef = useRef(builder.present)\n presentRef.current = builder.present\n const selectedIdRef = useRef(builder.selectedId)\n selectedIdRef.current = builder.selectedId\n\n // When the project was created from a starter kit, its brand token palette drives the canvas UI\n // (EC-117) — injected after app.css so the kit's overrides win in the cascade.\n const params = useParams({ strict: false }) as { projectId?: string }\n const kitTokensCss = params.projectId ? getInstantiatedKit(params.projectId)?.tokensCss : undefined\n\n // EC-414 AD-D: the settled canvas-theme classification (legacy merged shape /\n // broken stylesheet) drives the dev-only, never-blocking notice overlay.\n const [themeStatus, setThemeStatus] = useState<CanvasThemeStatus | null>(null)\n\n const wireUp = useCallback(() => {\n const d = iframeRef.current?.contentDocument\n if (!d || !d.body) return\n // Deliberately no `.dark` here: this iframe renders the REAL page (plus\n // studio editing chrome portaled alongside it), and its backdrop must read\n // as a light, site-like page — never the studio chrome's current theme (a\n // black canvas is exactly what leaks through when the studio is\n // dark-themed and the iframe root inherits that class). The injected\n // canvas stylesheet (new world: the chrome's neutral backdrop; legacy\n // world: the studio `:root` tokens) supplies that backdrop once `.dark` is\n // never added here (mirrors the components-preview surface, which wires\n // through the same chrome). The editing chrome (selection/hover outlines,\n // drop indicators, the rich-text toolbar, locale-fallback chips) uses\n // hardcoded colors rather than tokens, so it stays visible against a light\n // page regardless. The full injection — stylesheet link, editing chrome,\n // kit tokens, the consumer's `defineStudio({ canvas })` theme (EC-389,\n // injected LAST so it wins), and the EC-414 world probe — lives in\n // `wireCanvasChrome`/`applyCanvasChrome`.\n wireCanvasChrome(d, {\n stylesheetUrl: getCanvasStylesheetUrl(),\n kitTokensCss,\n theme: resolveDeploymentCanvasTheme(),\n onStatus: (status) =>\n setThemeStatus((prev) => (prev?.kind === status.kind ? prev : status)),\n })\n setDoc(d)\n }, [kitTokensCss])\n\n // Handle the already-loaded case (srcDoc may load before onLoad attaches).\n useEffect(() => {\n if (iframeRef.current?.contentDocument?.readyState === 'complete') wireUp()\n }, [wireUp])\n\n // Inline editing (EC-158/EC-159): the dblclick-to-edit state machine, the\n // live session ref other listeners consult, the rich-text host (mark\n // toolbar), and the per-node remount epochs (decorate keys).\n const inline = useCanvasInlineEditing(doc, { presentRef, dispatch, studio })\n const { editingRef, richEditHost, richEditEpochs } = inline\n\n // Native selection/hover listeners inside the iframe document.\n useEffect(() => {\n if (!doc) return\n const onClick = (e: Event) => {\n // Clicks inside the active inline editor are caret moves, not selection.\n if (editingRef.current?.host.contains(e.target as Node)) return\n const id = nodeIdAt(e.target)\n if (id) {\n e.preventDefault()\n dispatch({ type: 'select', id })\n }\n }\n const onOver = (e: Event) => dispatch({ type: 'hover', id: nodeIdAt(e.target) })\n const onLeave = () => dispatch({ type: 'hover', id: null })\n doc.addEventListener('click', onClick, true)\n doc.addEventListener('mouseover', onOver)\n doc.addEventListener('mouseleave', onLeave, true)\n return () => {\n doc.removeEventListener('click', onClick, true)\n doc.removeEventListener('mouseover', onOver)\n doc.removeEventListener('mouseleave', onLeave, true)\n }\n }, [doc, dispatch, editingRef])\n\n // Drag & drop on the canvas (EC-160/EC-162) — see `canvas-dnd`.\n useCanvasDnd(doc, { presentRef, dispatch, studio, editingRef })\n\n // Copy/cut/paste on the canvas (EC-175): the same studio clipboard the page\n // tree and blocks panel use, wired to the *iframe* document (events never\n // cross frames). Shortcuts stay inert while an inline editor is live and in\n // form fields; the iframe's own navigator.clipboard does the async I/O\n // (Chromium scopes clipboard access to the focused document).\n const clipboard = useStudioClipboard()\n useEffect(() => {\n if (!doc) return\n return attachClipboardListeners(doc, {\n clipboard,\n getSelectedId: () => selectedIdRef.current,\n isBlocked: () => editingRef.current !== null,\n asyncClipboard: doc.defaultView?.navigator.clipboard,\n getSelection: () => doc.getSelection(),\n })\n }, [doc, clipboard, editingRef])\n\n // The render context: the seven delivery-parity resolvers + the editable-\n // wrapper decorator (selection/hover, locale chips, remount epochs) — see\n // `canvas-render-context`.\n const { ctx, pageNodeIds } = useCanvasRenderContext({\n present: builder.present,\n selectedId: builder.selectedId,\n hoveredId: builder.hoveredId,\n studio,\n perspective,\n richEditEpochs,\n })\n\n // Tokenized spacing handles (EC-163): a selected Stack/Grid with 2+ children\n // gets draggable gap handles between them, portaled into the iframe.\n const spacingTarget =\n doc && hasSpacingHandles(builder.selectedNode) && pageNodeIds.has(builder.selectedNode.id)\n ? builder.selectedNode\n : null\n\n // EC-250: the preview frame width derives from the config-sourced breakpoints\n // (Tailwind defaults when unconfigured), the same resolved set the toolbar\n // switcher offers.\n const { viewports } = useCanvasViewports()\n\n return (\n <div className=\"canvas-grid relative flex min-h-0 flex-1 items-stretch justify-center overflow-auto p-6\">\n {/* Copy/cut/paste outcomes (EC-175): non-blocking, with issue deep links. */}\n <ClipboardNoticeOverlay />\n {/* Canvas-theme classification notice (EC-414 AD-D): dev-only, never blocks. */}\n <CanvasThemeNotice status={themeStatus} />\n <div style={{ width: viewportWidth(viewports, builder.viewport), maxWidth: '100%' }} className=\"flex\">\n <iframe\n ref={iframeRef}\n onLoad={wireUp}\n title={translate('builder.canvas.pagePreview')}\n className=\"min-h-[480px] w-full rounded-lg border border-border bg-background shadow-md\"\n srcDoc=\"<!doctype html><html><head></head><body></body></html>\"\n />\n {doc\n ? createPortal(\n // Render the composition root directly (EC-287: no layout\n // indirection — a page renders its blocks).\n renderPageComposition(activeRoot, ctx),\n doc.body,\n )\n : null}\n {spacingTarget && doc ? (\n <SpacingHandles key={spacingTarget.id} doc={doc} node={spacingTarget} />\n ) : null}\n {/* Floating mark toolbar for the live rich-text session (EC-159). */}\n {richEditHost && doc ? <RichTextToolbar doc={doc} host={richEditHost} /> : null}\n </div>\n </div>\n )\n}\n"]}
|
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
/** Everything the portal-free toolbar markup needs (chrome contract surface). */
|
|
2
|
+
export interface RichTextToolbarViewProps {
|
|
3
|
+
left: number;
|
|
4
|
+
top: number;
|
|
5
|
+
bold: boolean;
|
|
6
|
+
italic: boolean;
|
|
7
|
+
hasLink: boolean;
|
|
8
|
+
/** Non-null → the link editor row is open with this draft value. */
|
|
9
|
+
linkDraft: string | null;
|
|
10
|
+
onToolbarMouseDown: (e: React.MouseEvent<HTMLDivElement>) => void;
|
|
11
|
+
onBold: () => void;
|
|
12
|
+
onItalic: () => void;
|
|
13
|
+
onOpenLink: () => void;
|
|
14
|
+
onUnlink: () => void;
|
|
15
|
+
onLinkDraftChange: (value: string) => void;
|
|
16
|
+
onLinkSubmit: () => void;
|
|
17
|
+
onLinkCancel: () => void;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The toolbar's rendered markup, portal-free so the AD-D chrome contract test
|
|
21
|
+
* can walk it with `renderToStaticMarkup`: every class here MUST be `ec-*`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function RichTextToolbarView(props: RichTextToolbarViewProps): import("react").JSX.Element;
|
|
1
24
|
export declare function RichTextToolbar({ doc, host }: {
|
|
2
25
|
doc: Document;
|
|
3
26
|
host: HTMLElement;
|
|
@@ -23,6 +23,28 @@ function selectionState(doc, host) {
|
|
|
23
23
|
linkHref: link?.getAttribute('href') ?? null,
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* The toolbar's rendered markup, portal-free so the AD-D chrome contract test
|
|
28
|
+
* can walk it with `renderToStaticMarkup`: every class here MUST be `ec-*`.
|
|
29
|
+
*/
|
|
30
|
+
export function RichTextToolbarView(props) {
|
|
31
|
+
return (_jsx("div", { "data-ec-rt-toolbar": "", role: "toolbar", "aria-label": translate('builder.richText.toolbarLabel'), className: "ec-chrome ec-rt-toolbar", style: {
|
|
32
|
+
position: 'fixed',
|
|
33
|
+
left: Math.max(8, props.left),
|
|
34
|
+
top: Math.max(8, props.top - TOOLBAR_OFFSET_PX),
|
|
35
|
+
transform: 'translate(-50%, -100%)',
|
|
36
|
+
zIndex: 50,
|
|
37
|
+
}, onMouseDown: props.onToolbarMouseDown, children: props.linkDraft !== null ? (_jsxs("form", { className: "ec-rt-toolbar-row", onSubmit: (e) => {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
props.onLinkSubmit();
|
|
40
|
+
}, children: [_jsx("input", { autoFocus: true, type: "text", value: props.linkDraft, placeholder: translate('builder.richText.linkPlaceholder'), "aria-label": translate('builder.richText.linkUrl'), onChange: (e) => props.onLinkDraftChange(e.target.value), onKeyDown: (e) => {
|
|
41
|
+
if (e.key === 'Escape') {
|
|
42
|
+
e.preventDefault();
|
|
43
|
+
e.stopPropagation();
|
|
44
|
+
props.onLinkCancel();
|
|
45
|
+
}
|
|
46
|
+
}, className: "ec-rt-toolbar-input" }), _jsx("button", { type: "submit", className: "ec-rt-toolbar-btn", "aria-label": translate('builder.richText.applyLink'), children: translate('builder.richText.set') })] })) : (_jsxs("div", { className: "ec-rt-toolbar-row", children: [_jsx(MarkButton, { label: translate('builder.richText.bold'), active: props.bold, onClick: props.onBold, children: "B" }), _jsx(MarkButton, { label: translate('builder.richText.italic'), active: props.italic, onClick: props.onItalic, children: "I" }), _jsx(MarkButton, { label: translate('builder.richText.link'), active: props.hasLink, onClick: props.onOpenLink, children: translate('builder.richText.link') }), props.hasLink ? (_jsx(MarkButton, { label: translate('builder.richText.removeLink'), active: false, onClick: props.onUnlink, children: translate('builder.richText.unlink') })) : null] })) }));
|
|
47
|
+
}
|
|
26
48
|
export function RichTextToolbar({ doc, host }) {
|
|
27
49
|
const [state, setState] = useState(null);
|
|
28
50
|
const [linkOpen, setLinkOpen] = useState(false);
|
|
@@ -78,26 +100,11 @@ export function RichTextToolbar({ doc, host }) {
|
|
|
78
100
|
return null;
|
|
79
101
|
const left = state?.left ?? savedRangeRef.current?.getBoundingClientRect().left ?? 0;
|
|
80
102
|
const top = state?.top ?? savedRangeRef.current?.getBoundingClientRect().top ?? 0;
|
|
81
|
-
return createPortal(_jsx(
|
|
82
|
-
position: 'fixed',
|
|
83
|
-
left: Math.max(8, left),
|
|
84
|
-
top: Math.max(8, top - TOOLBAR_OFFSET_PX),
|
|
85
|
-
transform: 'translate(-50%, -100%)',
|
|
86
|
-
zIndex: 50,
|
|
87
|
-
}, onMouseDown: (e) => {
|
|
103
|
+
return createPortal(_jsx(RichTextToolbarView, { left: left, top: top, bold: state?.bold ?? false, italic: state?.italic ?? false, hasLink: state !== null && state.linkHref !== null, linkDraft: linkOpen ? linkDraft : null, onToolbarMouseDown: (e) => {
|
|
88
104
|
// Keep the host's selection/focus — except for the link input.
|
|
89
105
|
if (!e.target.closest('input'))
|
|
90
106
|
e.preventDefault();
|
|
91
|
-
},
|
|
92
|
-
e.preventDefault();
|
|
93
|
-
applyLink(linkDraft);
|
|
94
|
-
}, children: [_jsx("input", { autoFocus: true, type: "text", value: linkDraft, placeholder: translate('builder.richText.linkPlaceholder'), "aria-label": translate('builder.richText.linkUrl'), onChange: (e) => setLinkDraft(e.target.value), onKeyDown: (e) => {
|
|
95
|
-
if (e.key === 'Escape') {
|
|
96
|
-
e.preventDefault();
|
|
97
|
-
e.stopPropagation();
|
|
98
|
-
closeLinkEditor();
|
|
99
|
-
}
|
|
100
|
-
}, className: "ec-rt-toolbar-input" }), _jsx("button", { type: "submit", className: "ec-rt-toolbar-btn", "aria-label": translate('builder.richText.applyLink'), children: translate('builder.richText.set') })] })) : (_jsxs("div", { className: "ec-rt-toolbar-row", children: [_jsx(MarkButton, { label: translate('builder.richText.bold'), active: state?.bold ?? false, onClick: () => exec('bold'), children: "B" }), _jsx(MarkButton, { label: translate('builder.richText.italic'), active: state?.italic ?? false, onClick: () => exec('italic'), children: "I" }), _jsx(MarkButton, { label: translate('builder.richText.link'), active: state !== null && state.linkHref !== null, onClick: openLinkEditor, children: translate('builder.richText.link') }), state !== null && state.linkHref !== null ? (_jsx(MarkButton, { label: translate('builder.richText.removeLink'), active: false, onClick: () => exec('unlink'), children: translate('builder.richText.unlink') })) : null] })) }), doc.body);
|
|
107
|
+
}, onBold: () => exec('bold'), onItalic: () => exec('italic'), onOpenLink: openLinkEditor, onUnlink: () => exec('unlink'), onLinkDraftChange: setLinkDraft, onLinkSubmit: () => applyLink(linkDraft), onLinkCancel: closeLinkEditor }), doc.body);
|
|
101
108
|
}
|
|
102
109
|
function MarkButton({ label, active, onClick, children, }) {
|
|
103
110
|
return (_jsx("button", { type: "button", "aria-label": label, "aria-pressed": active, title: label, onClick: onClick, className: "ec-rt-toolbar-btn", "data-active": active || undefined, children: children }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rich-text-toolbar.js","sourceRoot":"","sources":["../../../src/components/builder/rich-text-toolbar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAA;AA0BtD,MAAM,iBAAiB,GAAG,CAAC,CAAA;AAE3B,SAAS,cAAc,CAAC,GAAa,EAAE,IAAiB;IACtD,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,EAAE,CAAA;IACpC,IAAI,CAAC,SAAS,IAAI,SAAS,CAAC,UAAU,KAAK,CAAC,IAAI,SAAS,CAAC,WAAW;QAAE,OAAO,IAAI,CAAA;IAClF,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAA;IAC5F,MAAM,IAAI,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,C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AAS,YAE/B,QAAQ,GACF,CACV,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\nimport { translate } from '@elytracms/studio/lib/i18n'\n\n/**\n * Floating mark toolbar for inline rich-text editing (EC-159): anchored to the\n * live text selection inside the canvas iframe, offering bold, italic, and\n * link (set + remove). Portaled into the *iframe* document — selection\n * rectangles are iframe-viewport coordinates, so the toolbar positions\n * `fixed` in that viewport and never needs cross-frame math.\n *\n * Mark application uses the document's native editing commands on the live\n * selection (`bold`/`italic`/`createLink`/`unlink`), which produce exactly the\n * tags the `@elytracms/core/rich-text` DOM parser inverts (`b/strong`, `i/em`,\n * `a[href]`). Pointer-down on the toolbar is swallowed so the host keeps its\n * selection; the link input is the one exception (it needs focus), and the\n * canvas blur handler ignores blurs into `[data-ec-rt-toolbar]`.\n */\n\ninterface ToolbarState {\n left: number\n top: number\n bold: boolean\n italic: boolean\n /** The href of the link the selection sits inside, if any. */\n linkHref: string | null\n}\n\nconst TOOLBAR_OFFSET_PX = 8\n\nfunction selectionState(doc: Document, host: HTMLElement): ToolbarState | null {\n const selection = doc.getSelection()\n if (!selection || selection.rangeCount === 0 || selection.isCollapsed) return null\n if (!host.contains(selection.anchorNode) || !host.contains(selection.focusNode)) return null\n const rect = selection.getRangeAt(0).getBoundingClientRect()\n if (rect.width === 0 && rect.height === 0) return null\n const anchor = selection.anchorNode\n const anchorElement = anchor instanceof Element ? anchor : anchor?.parentElement\n const link = anchorElement?.closest('a') ?? null\n return {\n left: rect.left + rect.width / 2,\n top: rect.top,\n bold: doc.queryCommandState('bold'),\n italic: doc.queryCommandState('italic'),\n linkHref: link?.getAttribute('href') ?? null,\n }\n}\n\nexport function RichTextToolbar({ doc, host }: { doc: Document; host: HTMLElement }) {\n const [state, setState] = useState<ToolbarState | null>(null)\n const [linkOpen, setLinkOpen] = useState(false)\n const [linkDraft, setLinkDraft] = useState('')\n const savedRangeRef = useRef<Range | null>(null)\n\n const refresh = useCallback(() => {\n setState(selectionState(doc, host))\n }, [doc, host])\n\n useEffect(() => {\n refresh()\n doc.addEventListener('selectionchange', refresh)\n return () => doc.removeEventListener('selectionchange', refresh)\n }, [doc, refresh])\n\n // Close a stale link editor when the selection leaves the host entirely.\n useEffect(() => {\n if (!state && !linkOpen) setLinkDraft('')\n }, [state, linkOpen])\n\n const exec = useCallback(\n (command: string, value?: string) => {\n doc.execCommand(command, false, value)\n refresh()\n },\n [doc, refresh],\n )\n\n const openLinkEditor = useCallback(() => {\n const selection = doc.getSelection()\n if (selection && selection.rangeCount > 0) {\n savedRangeRef.current = selection.getRangeAt(0).cloneRange()\n }\n setLinkDraft(state?.linkHref ?? '')\n setLinkOpen(true)\n }, [doc, state])\n\n const applyLink = useCallback(\n (href: string) => {\n const selection = doc.getSelection()\n const saved = savedRangeRef.current\n if (saved && selection) {\n selection.removeAllRanges()\n selection.addRange(saved)\n }\n const trimmed = href.trim()\n if (trimmed.length > 0) exec('createLink', trimmed)\n else exec('unlink')\n setLinkOpen(false)\n savedRangeRef.current = null\n host.focus({ preventScroll: true })\n },\n [doc, exec, host],\n )\n\n const closeLinkEditor = useCallback(() => {\n setLinkOpen(false)\n savedRangeRef.current = null\n host.focus({ preventScroll: true })\n }, [host])\n\n if (!state && !linkOpen) return null\n const left = state?.left ?? savedRangeRef.current?.getBoundingClientRect().left ?? 0\n const top = state?.top ?? savedRangeRef.current?.getBoundingClientRect().top ?? 0\n\n return createPortal(\n <div\n data-ec-rt-toolbar=\"\"\n role=\"toolbar\"\n aria-label={translate('builder.richText.toolbarLabel')}\n className=\"ec-rt-toolbar\"\n style={{\n position: 'fixed',\n left: Math.max(8, left),\n top: Math.max(8, top - TOOLBAR_OFFSET_PX),\n transform: 'translate(-50%, -100%)',\n zIndex: 50,\n }}\n onMouseDown={(e) => {\n // Keep the host's selection/focus — except for the link input.\n if (!(e.target as HTMLElement).closest('input')) e.preventDefault()\n }}\n >\n {linkOpen ? (\n <form\n className=\"ec-rt-toolbar-row\"\n onSubmit={(e) => {\n e.preventDefault()\n applyLink(linkDraft)\n }}\n >\n <input\n autoFocus\n type=\"text\"\n value={linkDraft}\n placeholder={translate('builder.richText.linkPlaceholder')}\n aria-label={translate('builder.richText.linkUrl')}\n onChange={(e) => setLinkDraft(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault()\n e.stopPropagation()\n closeLinkEditor()\n }\n }}\n className=\"ec-rt-toolbar-input\"\n />\n <button type=\"submit\" className=\"ec-rt-toolbar-btn\" aria-label={translate('builder.richText.applyLink')}>\n {translate('builder.richText.set')}\n </button>\n </form>\n ) : (\n <div className=\"ec-rt-toolbar-row\">\n <MarkButton label={translate('builder.richText.bold')} active={state?.bold ?? false} onClick={() => exec('bold')}>\n B\n </MarkButton>\n <MarkButton label={translate('builder.richText.italic')} active={state?.italic ?? false} onClick={() => exec('italic')}>\n I\n </MarkButton>\n <MarkButton\n label={translate('builder.richText.link')}\n active={state !== null && state.linkHref !== null}\n onClick={openLinkEditor}\n >\n {translate('builder.richText.link')}\n </MarkButton>\n {state !== null && state.linkHref !== null ? (\n <MarkButton label={translate('builder.richText.removeLink')} active={false} onClick={() => exec('unlink')}>\n {translate('builder.richText.unlink')}\n </MarkButton>\n ) : null}\n </div>\n )}\n </div>,\n doc.body,\n )\n}\n\nfunction MarkButton({\n label,\n active,\n onClick,\n children,\n}: {\n label: string\n active: boolean\n onClick: () => void\n children: React.ReactNode\n}) {\n return (\n <button\n type=\"button\"\n aria-label={label}\n aria-pressed={active}\n title={label}\n onClick={onClick}\n className=\"ec-rt-toolbar-btn\"\n data-active={active || undefined}\n >\n {children}\n </button>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"rich-text-toolbar.js","sourceRoot":"","sources":["../../../src/components/builder/rich-text-toolbar.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AA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mB,iBAChB,MAAM,IAAI,SAAS,YAE/B,QAAQ,GACF,CACV,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\nimport { translate } from '@elytracms/studio/lib/i18n'\n\n/**\n * Floating mark toolbar for inline rich-text editing (EC-159): anchored to the\n * live text selection inside the canvas iframe, offering bold, italic, and\n * link (set + remove). Portaled into the *iframe* document — selection\n * rectangles are iframe-viewport coordinates, so the toolbar positions\n * `fixed` in that viewport and never needs cross-frame math.\n *\n * In-frame chrome contract (EC-414 AD-B): the toolbar is styled EXCLUSIVELY by\n * the chrome stylesheet's `ec-rt-*` rules plus inline positioning — no studio\n * utilities, no studio UI primitives — and its root carries the `.ec-chrome`\n * containment recipe. The portal-free {@link RichTextToolbarView} is the\n * contract-testable markup surface.\n *\n * Mark application uses the document's native editing commands on the live\n * selection (`bold`/`italic`/`createLink`/`unlink`), which produce exactly the\n * tags the `@elytracms/core/rich-text` DOM parser inverts (`b/strong`, `i/em`,\n * `a[href]`). Pointer-down on the toolbar is swallowed so the host keeps its\n * selection; the link input is the one exception (it needs focus), and the\n * canvas blur handler ignores blurs into `[data-ec-rt-toolbar]`.\n */\n\ninterface ToolbarState {\n left: number\n top: number\n bold: boolean\n italic: boolean\n /** The href of the link the selection sits inside, if any. */\n linkHref: string | null\n}\n\nconst TOOLBAR_OFFSET_PX = 8\n\nfunction selectionState(doc: Document, host: HTMLElement): ToolbarState | null {\n const selection = doc.getSelection()\n if (!selection || selection.rangeCount === 0 || selection.isCollapsed) return null\n if (!host.contains(selection.anchorNode) || !host.contains(selection.focusNode)) return null\n const rect = selection.getRangeAt(0).getBoundingClientRect()\n if (rect.width === 0 && rect.height === 0) return null\n const anchor = selection.anchorNode\n const anchorElement = anchor instanceof Element ? anchor : anchor?.parentElement\n const link = anchorElement?.closest('a') ?? null\n return {\n left: rect.left + rect.width / 2,\n top: rect.top,\n bold: doc.queryCommandState('bold'),\n italic: doc.queryCommandState('italic'),\n linkHref: link?.getAttribute('href') ?? null,\n }\n}\n\n/** Everything the portal-free toolbar markup needs (chrome contract surface). */\nexport interface RichTextToolbarViewProps {\n left: number\n top: number\n bold: boolean\n italic: boolean\n hasLink: boolean\n /** Non-null → the link editor row is open with this draft value. */\n linkDraft: string | null\n onToolbarMouseDown: (e: React.MouseEvent<HTMLDivElement>) => void\n onBold: () => void\n onItalic: () => void\n onOpenLink: () => void\n onUnlink: () => void\n onLinkDraftChange: (value: string) => void\n onLinkSubmit: () => void\n onLinkCancel: () => void\n}\n\n/**\n * The toolbar's rendered markup, portal-free so the AD-D chrome contract test\n * can walk it with `renderToStaticMarkup`: every class here MUST be `ec-*`.\n */\nexport function RichTextToolbarView(props: RichTextToolbarViewProps) {\n return (\n <div\n data-ec-rt-toolbar=\"\"\n role=\"toolbar\"\n aria-label={translate('builder.richText.toolbarLabel')}\n className=\"ec-chrome ec-rt-toolbar\"\n style={{\n position: 'fixed',\n left: Math.max(8, props.left),\n top: Math.max(8, props.top - TOOLBAR_OFFSET_PX),\n transform: 'translate(-50%, -100%)',\n zIndex: 50,\n }}\n onMouseDown={props.onToolbarMouseDown}\n >\n {props.linkDraft !== null ? (\n <form\n className=\"ec-rt-toolbar-row\"\n onSubmit={(e) => {\n e.preventDefault()\n props.onLinkSubmit()\n }}\n >\n <input\n autoFocus\n type=\"text\"\n value={props.linkDraft}\n placeholder={translate('builder.richText.linkPlaceholder')}\n aria-label={translate('builder.richText.linkUrl')}\n onChange={(e) => props.onLinkDraftChange(e.target.value)}\n onKeyDown={(e) => {\n if (e.key === 'Escape') {\n e.preventDefault()\n e.stopPropagation()\n props.onLinkCancel()\n }\n }}\n className=\"ec-rt-toolbar-input\"\n />\n <button type=\"submit\" className=\"ec-rt-toolbar-btn\" aria-label={translate('builder.richText.applyLink')}>\n {translate('builder.richText.set')}\n </button>\n </form>\n ) : (\n <div className=\"ec-rt-toolbar-row\">\n <MarkButton label={translate('builder.richText.bold')} active={props.bold} onClick={props.onBold}>\n B\n </MarkButton>\n <MarkButton label={translate('builder.richText.italic')} active={props.italic} onClick={props.onItalic}>\n I\n </MarkButton>\n <MarkButton label={translate('builder.richText.link')} active={props.hasLink} onClick={props.onOpenLink}>\n {translate('builder.richText.link')}\n </MarkButton>\n {props.hasLink ? (\n <MarkButton label={translate('builder.richText.removeLink')} active={false} onClick={props.onUnlink}>\n {translate('builder.richText.unlink')}\n </MarkButton>\n ) : null}\n </div>\n )}\n </div>\n )\n}\n\nexport function RichTextToolbar({ doc, host }: { doc: Document; host: HTMLElement }) {\n const [state, setState] = useState<ToolbarState | null>(null)\n const [linkOpen, setLinkOpen] = useState(false)\n const [linkDraft, setLinkDraft] = useState('')\n const savedRangeRef = useRef<Range | null>(null)\n\n const refresh = useCallback(() => {\n setState(selectionState(doc, host))\n }, [doc, host])\n\n useEffect(() => {\n refresh()\n doc.addEventListener('selectionchange', refresh)\n return () => doc.removeEventListener('selectionchange', refresh)\n }, [doc, refresh])\n\n // Close a stale link editor when the selection leaves the host entirely.\n useEffect(() => {\n if (!state && !linkOpen) setLinkDraft('')\n }, [state, linkOpen])\n\n const exec = useCallback(\n (command: string, value?: string) => {\n doc.execCommand(command, false, value)\n refresh()\n },\n [doc, refresh],\n )\n\n const openLinkEditor = useCallback(() => {\n const selection = doc.getSelection()\n if (selection && selection.rangeCount > 0) {\n savedRangeRef.current = selection.getRangeAt(0).cloneRange()\n }\n setLinkDraft(state?.linkHref ?? '')\n setLinkOpen(true)\n }, [doc, state])\n\n const applyLink = useCallback(\n (href: string) => {\n const selection = doc.getSelection()\n const saved = savedRangeRef.current\n if (saved && selection) {\n selection.removeAllRanges()\n selection.addRange(saved)\n }\n const trimmed = href.trim()\n if (trimmed.length > 0) exec('createLink', trimmed)\n else exec('unlink')\n setLinkOpen(false)\n savedRangeRef.current = null\n host.focus({ preventScroll: true })\n },\n [doc, exec, host],\n )\n\n const closeLinkEditor = useCallback(() => {\n setLinkOpen(false)\n savedRangeRef.current = null\n host.focus({ preventScroll: true })\n }, [host])\n\n if (!state && !linkOpen) return null\n const left = state?.left ?? savedRangeRef.current?.getBoundingClientRect().left ?? 0\n const top = state?.top ?? savedRangeRef.current?.getBoundingClientRect().top ?? 0\n\n return createPortal(\n <RichTextToolbarView\n left={left}\n top={top}\n bold={state?.bold ?? false}\n italic={state?.italic ?? false}\n hasLink={state !== null && state.linkHref !== null}\n linkDraft={linkOpen ? linkDraft : null}\n onToolbarMouseDown={(e) => {\n // Keep the host's selection/focus — except for the link input.\n if (!(e.target as HTMLElement).closest('input')) e.preventDefault()\n }}\n onBold={() => exec('bold')}\n onItalic={() => exec('italic')}\n onOpenLink={openLinkEditor}\n onUnlink={() => exec('unlink')}\n onLinkDraftChange={setLinkDraft}\n onLinkSubmit={() => applyLink(linkDraft)}\n onLinkCancel={closeLinkEditor}\n />,\n doc.body,\n )\n}\n\nfunction MarkButton({\n label,\n active,\n onClick,\n children,\n}: {\n label: string\n active: boolean\n onClick: () => void\n children: React.ReactNode\n}) {\n return (\n <button\n type=\"button\"\n aria-label={label}\n aria-pressed={active}\n title={label}\n onClick={onClick}\n className=\"ec-rt-toolbar-btn\"\n data-active={active || undefined}\n >\n {children}\n </button>\n )\n}\n"]}
|
|
@@ -14,8 +14,39 @@ import type { GapStep } from '@elytracms/studio/lib/dnd/gap-drag';
|
|
|
14
14
|
*/
|
|
15
15
|
/** Plain-language label for a gap step — the inspector's vocabulary. */
|
|
16
16
|
export declare function gapStepLabel(step: GapStep): string;
|
|
17
|
+
export interface HandleSpotView {
|
|
18
|
+
index: number;
|
|
19
|
+
/** Document-coordinate position of the handle's center. */
|
|
20
|
+
x: number;
|
|
21
|
+
y: number;
|
|
22
|
+
crossStart: number;
|
|
23
|
+
crossLength: number;
|
|
24
|
+
}
|
|
17
25
|
/** True when the node is a container with at least two children to space. */
|
|
18
26
|
export declare function hasSpacingHandles(node: ComponentNode | null): node is ComponentNode;
|
|
27
|
+
/** Everything the portal-free handle markup needs (chrome contract surface). */
|
|
28
|
+
export interface SpacingHandlesViewProps {
|
|
29
|
+
spots: HandleSpotView[];
|
|
30
|
+
horizontal: boolean;
|
|
31
|
+
/** The live drag, for the active-handle tint and the floating label. */
|
|
32
|
+
drag: {
|
|
33
|
+
index: number;
|
|
34
|
+
labelX: number;
|
|
35
|
+
labelY: number;
|
|
36
|
+
label: string;
|
|
37
|
+
} | null;
|
|
38
|
+
onPointerDown: (spot: HandleSpotView) => (e: React.PointerEvent<HTMLDivElement>) => void;
|
|
39
|
+
onPointerMove: (e: React.PointerEvent<HTMLDivElement>) => void;
|
|
40
|
+
onPointerUp: () => void;
|
|
41
|
+
onPointerCancel: () => void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The spacing handles' rendered markup, portal-free so the AD-D chrome
|
|
45
|
+
* contract test can walk it with `renderToStaticMarkup`. In-frame chrome
|
|
46
|
+
* contract (EC-414 AD-B): `ec-*`/`data-ec-*` plus inline styles only; the root
|
|
47
|
+
* carries the `.ec-chrome` containment recipe.
|
|
48
|
+
*/
|
|
49
|
+
export declare function SpacingHandlesView(props: SpacingHandlesViewProps): import("react").JSX.Element;
|
|
19
50
|
export declare function SpacingHandles({ doc, node }: {
|
|
20
51
|
doc: Document;
|
|
21
52
|
node: ComponentNode;
|
|
@@ -63,6 +63,52 @@ export function hasSpacingHandles(node) {
|
|
|
63
63
|
const HANDLE_THICKNESS = 14;
|
|
64
64
|
const HANDLE_BAR = 4;
|
|
65
65
|
const HANDLE_MAX_LENGTH = 48;
|
|
66
|
+
/**
|
|
67
|
+
* The spacing handles' rendered markup, portal-free so the AD-D chrome
|
|
68
|
+
* contract test can walk it with `renderToStaticMarkup`. In-frame chrome
|
|
69
|
+
* contract (EC-414 AD-B): `ec-*`/`data-ec-*` plus inline styles only; the root
|
|
70
|
+
* carries the `.ec-chrome` containment recipe.
|
|
71
|
+
*/
|
|
72
|
+
export function SpacingHandlesView(props) {
|
|
73
|
+
const { spots, horizontal, drag } = props;
|
|
74
|
+
return (_jsxs("div", { "data-ec-spacing-handles": "", className: "ec-chrome", children: [spots.map((spot) => {
|
|
75
|
+
const length = Math.min(spot.crossLength, HANDLE_MAX_LENGTH);
|
|
76
|
+
const active = drag?.index === spot.index;
|
|
77
|
+
return (_jsx("div", { "data-ec-gap-handle": spot.index, role: "separator", "aria-label": translate('builder.spacing.gapAfterChild', { index: spot.index + 1 }), "aria-orientation": horizontal ? 'vertical' : 'horizontal', onPointerDown: props.onPointerDown(spot), onPointerMove: props.onPointerMove, onPointerUp: props.onPointerUp, onPointerCancel: props.onPointerCancel, style: {
|
|
78
|
+
position: 'absolute',
|
|
79
|
+
left: spot.x - (horizontal ? HANDLE_THICKNESS / 2 : length / 2),
|
|
80
|
+
top: spot.y - (horizontal ? length / 2 : HANDLE_THICKNESS / 2),
|
|
81
|
+
width: horizontal ? HANDLE_THICKNESS : length,
|
|
82
|
+
height: horizontal ? length : HANDLE_THICKNESS,
|
|
83
|
+
display: 'flex',
|
|
84
|
+
alignItems: 'center',
|
|
85
|
+
justifyContent: 'center',
|
|
86
|
+
cursor: horizontal ? 'col-resize' : 'row-resize',
|
|
87
|
+
zIndex: 40,
|
|
88
|
+
touchAction: 'none',
|
|
89
|
+
}, children: _jsx("div", { style: {
|
|
90
|
+
width: horizontal ? HANDLE_BAR : '100%',
|
|
91
|
+
height: horizontal ? '100%' : HANDLE_BAR,
|
|
92
|
+
borderRadius: 999,
|
|
93
|
+
backgroundColor: active ? '#5b8cff' : 'rgba(91, 140, 255, 0.65)',
|
|
94
|
+
boxShadow: '0 0 0 1px rgba(8, 12, 24, 0.55)',
|
|
95
|
+
} }) }, spot.index));
|
|
96
|
+
}), drag ? (_jsx("div", { "data-ec-gap-label": "", style: {
|
|
97
|
+
position: 'absolute',
|
|
98
|
+
left: drag.labelX + 12,
|
|
99
|
+
top: drag.labelY + 12,
|
|
100
|
+
zIndex: 50,
|
|
101
|
+
pointerEvents: 'none',
|
|
102
|
+
padding: '2px 8px',
|
|
103
|
+
borderRadius: 6,
|
|
104
|
+
fontSize: 11,
|
|
105
|
+
fontWeight: 600,
|
|
106
|
+
whiteSpace: 'nowrap',
|
|
107
|
+
color: '#fff',
|
|
108
|
+
backgroundColor: '#5b8cff',
|
|
109
|
+
boxShadow: '0 2px 8px rgba(8, 12, 24, 0.4)',
|
|
110
|
+
}, children: drag.label })) : null] }));
|
|
111
|
+
}
|
|
66
112
|
export function SpacingHandles({ doc, node }) {
|
|
67
113
|
const builder = useBuilder();
|
|
68
114
|
const { dispatch } = builder;
|
|
@@ -173,42 +219,8 @@ export function SpacingHandles({ doc, node }) {
|
|
|
173
219
|
applyPreview(step);
|
|
174
220
|
};
|
|
175
221
|
const horizontal = axis === 'horizontal';
|
|
176
|
-
return createPortal(
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
return (_jsx("div", { "data-ec-gap-handle": spot.index, role: "separator", "aria-label": translate('builder.spacing.gapAfterChild', { index: spot.index + 1 }), "aria-orientation": horizontal ? 'vertical' : 'horizontal', onPointerDown: onPointerDown(spot), onPointerMove: onPointerMove, onPointerUp: () => finish('commit'), onPointerCancel: () => finish('cancel'), style: {
|
|
180
|
-
position: 'absolute',
|
|
181
|
-
left: spot.x - (horizontal ? HANDLE_THICKNESS / 2 : length / 2),
|
|
182
|
-
top: spot.y - (horizontal ? length / 2 : HANDLE_THICKNESS / 2),
|
|
183
|
-
width: horizontal ? HANDLE_THICKNESS : length,
|
|
184
|
-
height: horizontal ? length : HANDLE_THICKNESS,
|
|
185
|
-
display: 'flex',
|
|
186
|
-
alignItems: 'center',
|
|
187
|
-
justifyContent: 'center',
|
|
188
|
-
cursor: horizontal ? 'col-resize' : 'row-resize',
|
|
189
|
-
zIndex: 40,
|
|
190
|
-
touchAction: 'none',
|
|
191
|
-
}, children: _jsx("div", { style: {
|
|
192
|
-
width: horizontal ? HANDLE_BAR : '100%',
|
|
193
|
-
height: horizontal ? '100%' : HANDLE_BAR,
|
|
194
|
-
borderRadius: 999,
|
|
195
|
-
backgroundColor: active ? '#5b8cff' : 'rgba(91, 140, 255, 0.65)',
|
|
196
|
-
boxShadow: '0 0 0 1px rgba(8, 12, 24, 0.55)',
|
|
197
|
-
} }) }, spot.index));
|
|
198
|
-
}), drag ? (_jsx("div", { "data-ec-gap-label": "", style: {
|
|
199
|
-
position: 'absolute',
|
|
200
|
-
left: drag.labelX + 12,
|
|
201
|
-
top: drag.labelY + 12,
|
|
202
|
-
zIndex: 50,
|
|
203
|
-
pointerEvents: 'none',
|
|
204
|
-
padding: '2px 8px',
|
|
205
|
-
borderRadius: 6,
|
|
206
|
-
fontSize: 11,
|
|
207
|
-
fontWeight: 600,
|
|
208
|
-
whiteSpace: 'nowrap',
|
|
209
|
-
color: '#fff',
|
|
210
|
-
backgroundColor: '#5b8cff',
|
|
211
|
-
boxShadow: '0 2px 8px rgba(8, 12, 24, 0.4)',
|
|
212
|
-
}, children: gapStepLabel(drag.step) })) : null] }), doc.body);
|
|
222
|
+
return createPortal(_jsx(SpacingHandlesView, { spots: spots, horizontal: horizontal, drag: drag
|
|
223
|
+
? { index: drag.index, labelX: drag.labelX, labelY: drag.labelY, label: gapStepLabel(drag.step) }
|
|
224
|
+
: null, onPointerDown: onPointerDown, onPointerMove: onPointerMove, onPointerUp: () => finish('commit'), onPointerCancel: () => finish('cancel') }), doc.body);
|
|
213
225
|
}
|
|
214
226
|
//# sourceMappingURL=spacing-handles.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spacing-handles.js","sourceRoot":"","sources":["../../../src/components/builder/spacing-handles.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAE/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,sC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C,YAEA,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,GACpB,CACP,CAAC,CAAC,CAAC,IAAI,IACJ,EACN,GAAG,CAAC,IAAI,CACT,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\nimport { DEFAULT_SLOT, isLayoutContainerNode, staticProp } from '@elytracms/core/project-graph'\nimport type { ComponentNode } from '@elytracms/core/project-graph'\nimport { containerFlowAxis } from '@elytracms/studio/lib/dnd/drop-rules'\nimport type { FlowAxis } from '@elytracms/studio/lib/dnd/drop-rules'\nimport {\n containerGapStep,\n gapHandleSpots,\n gapStepCss,\n gapStepFromDrag,\n} from '@elytracms/studio/lib/dnd/gap-drag'\nimport type { GapStep } from '@elytracms/studio/lib/dnd/gap-drag'\nimport { translate } from '@elytracms/studio/lib/i18n'\nimport { useBuilder } from './builder-store'\nimport { GAP_LABEL_KEYS, GAP_NONE_LABEL_KEY } from './layout-inspector'\n\n/**\n * Tokenized spacing handles (EC-163, vision §3.1 / AD-10): when a Stack/Grid\n * container is selected on the canvas, draggable gap handles appear between\n * its children, axis-aware via the shared `containerFlowAxis`. Dragging snaps\n * through the EC-161 spacing-token scale (`lib/dnd/gap-drag` — pure math, no\n * pixel value can escape it) with a live plain-language label (the layout\n * inspector's vocabulary). The drag previews imperatively on the rendered\n * element; releasing commits exactly ONE builder dispatch — `setProp` with the\n * token, or `removeProp` for \"no gap\", the identical values the inspector's\n * gap select writes — so one undo restores, and the graph stays the single\n * source of truth. Esc mid-drag cancels: preview reverts, nothing dispatches.\n */\n\n/** Plain-language label for a gap step — the inspector's vocabulary. */\nexport function gapStepLabel(step: GapStep): string {\n return step === null ? translate(GAP_NONE_LABEL_KEY) : translate(GAP_LABEL_KEYS[step])\n}\n\ninterface HandleSpotView {\n index: number\n /** Document-coordinate position of the handle's center. */\n x: number\n y: number\n crossStart: number\n crossLength: number\n}\n\ninterface ActiveDrag {\n index: number\n startStep: GapStep\n step: GapStep\n /** Pointer start along the flow axis (client coords). */\n startCoord: number\n /** Live pointer position (document coords) for the floating label. */\n labelX: number\n labelY: number\n}\n\n/** The container's rendered element (the Stack/Grid div carrying the gap style). */\nfunction containerElementFor(doc: Document, nodeId: string): HTMLElement | null {\n const wrapper = doc.querySelector(`[data-ec-node-id=\"${nodeId}\"]`)\n return (wrapper?.querySelector(':scope > [data-ec-primitive]') as HTMLElement | null) ?? null\n}\n\ninterface Measured {\n spots: HandleSpotView[]\n /** The axis the children are *rendered* along (drag direction follows it). */\n axis: FlowAxis\n}\n\n/**\n * Measure the handle spots between the container's rendered children. The\n * graph-level flow axis (`containerFlowAxis`) is tried first; when the\n * rendered layout disagrees — a stacking Grid below the mobile breakpoint\n * lays its \"columns\" out vertically — the cross axis is measured instead, so\n * handles always sit in the gaps the editor actually sees.\n */\nfunction measureSpots(doc: Document, nodeId: string, flowAxis: FlowAxis): Measured {\n const container = containerElementFor(doc, nodeId)\n const win = doc.defaultView\n if (!container || !win) return { spots: [], axis: flowAxis }\n const children = Array.from(\n container.querySelectorAll(':scope > [data-ec-node-id]'),\n ) as HTMLElement[]\n if (children.length < 2) return { spots: [], axis: flowAxis }\n const rects = children.map((el) => {\n const r = el.getBoundingClientRect()\n return { left: r.left + win.scrollX, top: r.top + win.scrollY, width: r.width, height: r.height }\n })\n const along = gapHandleSpots(rects, flowAxis)\n if (along.length > 0) return { spots: along, axis: flowAxis }\n const cross: FlowAxis = flowAxis === 'horizontal' ? 'vertical' : 'horizontal'\n const across = gapHandleSpots(rects, cross)\n return across.length > 0 ? { spots: across, axis: cross } : { spots: [], axis: flowAxis }\n}\n\n/** True when the node is a container with at least two children to space. */\nexport function hasSpacingHandles(node: ComponentNode | null): node is ComponentNode {\n return (\n node !== null &&\n isLayoutContainerNode(node) &&\n (node.slots?.[DEFAULT_SLOT]?.length ?? 0) >= 2\n )\n}\n\nconst HANDLE_THICKNESS = 14\nconst HANDLE_BAR = 4\nconst HANDLE_MAX_LENGTH = 48\n\nexport function SpacingHandles({ doc, node }: { doc: Document; node: ComponentNode }) {\n const builder = useBuilder()\n const { dispatch } = builder\n const flowAxis = containerFlowAxis(node)\n const [measured, setMeasured] = useState<Measured>({ spots: [], axis: flowAxis })\n const [drag, setDrag] = useState<ActiveDrag | null>(null)\n const dragRef = useRef<ActiveDrag | null>(null)\n // The container's pre-drag inline gap, restored on cancel/commit (the graph\n // re-render owns the committed value; the preview is imperative-only).\n const inlineGapRef = useRef<string>('')\n\n // Re-measure when the graph, selection, drag preview, or iframe size change.\n useLayoutEffect(() => {\n const measure = () => setMeasured(measureSpots(doc, node.id, flowAxis))\n measure()\n const win = doc.defaultView\n win?.addEventListener('resize', measure)\n return () => win?.removeEventListener('resize', measure)\n }, [doc, node, flowAxis, builder.present, builder.viewport, drag?.step])\n const { spots, axis } = measured\n\n const applyPreview = useCallback(\n (step: GapStep) => {\n const container = containerElementFor(doc, node.id)\n if (container) container.style.gap = gapStepCss(step)\n },\n [doc, node.id],\n )\n\n const finish = useCallback(\n (mode: 'commit' | 'cancel') => {\n const active = dragRef.current\n if (!active) return\n dragRef.current = null\n setDrag(null)\n // Drop the imperative preview; the rendered graph value takes over.\n const container = containerElementFor(doc, node.id)\n if (container) container.style.gap = inlineGapRef.current\n if (mode === 'commit' && active.step !== active.startStep) {\n // Exactly one dispatch — one operations command, one undo step — and\n // the identical prop value the inspector's gap select produces.\n if (active.step === null) {\n dispatch({ type: 'removeProp', id: node.id, name: 'gap' })\n } else {\n dispatch({ type: 'setProp', id: node.id, name: 'gap', value: staticProp(active.step) })\n }\n }\n },\n [doc, node.id, dispatch],\n )\n\n // Esc cancels mid-drag — listen on both documents (focus may sit either side\n // of the iframe boundary while the pointer is captured).\n useEffect(() => {\n if (!drag) return\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.preventDefault()\n e.stopPropagation()\n finish('cancel')\n }\n }\n doc.addEventListener('keydown', onKeyDown, true)\n document.addEventListener('keydown', onKeyDown, true)\n return () => {\n doc.removeEventListener('keydown', onKeyDown, true)\n document.removeEventListener('keydown', onKeyDown, true)\n }\n }, [drag, doc, finish])\n\n // Cleanup on unmount/selection change mid-drag: revert, never dispatch.\n useEffect(() => () => finish('cancel'), [finish])\n\n const onPointerDown = (spot: HandleSpotView) => (e: React.PointerEvent<HTMLDivElement>) => {\n if (e.button !== 0) return\n e.preventDefault()\n e.stopPropagation()\n const startStep = containerGapStep(node)\n const container = containerElementFor(doc, node.id)\n inlineGapRef.current = container?.style.gap ?? ''\n try {\n e.currentTarget.setPointerCapture(e.pointerId)\n } catch {\n // Synthetic pointer events (tests, automation) have no active pointer\n // to capture; move/up still arrive via the handle's own listeners.\n }\n const next: ActiveDrag = {\n index: spot.index,\n startStep,\n step: startStep,\n startCoord: axis === 'horizontal' ? e.clientX : e.clientY,\n labelX: spot.x,\n labelY: spot.y,\n }\n dragRef.current = next\n setDrag(next)\n }\n\n const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n const active = dragRef.current\n if (!active) return\n const win = doc.defaultView\n const coord = axis === 'horizontal' ? e.clientX : e.clientY\n const step = gapStepFromDrag(active.startStep, coord - active.startCoord)\n const next: ActiveDrag = {\n ...active,\n step,\n labelX: e.clientX + (win?.scrollX ?? 0),\n labelY: e.clientY + (win?.scrollY ?? 0),\n }\n dragRef.current = next\n setDrag(next)\n applyPreview(step)\n }\n\n const horizontal = axis === 'horizontal'\n\n return createPortal(\n <div data-ec-spacing-handles=\"\">\n {spots.map((spot) => {\n const length = Math.min(spot.crossLength, HANDLE_MAX_LENGTH)\n const active = drag?.index === spot.index\n return (\n <div\n key={spot.index}\n data-ec-gap-handle={spot.index}\n role=\"separator\"\n aria-label={translate('builder.spacing.gapAfterChild', { index: spot.index + 1 })}\n aria-orientation={horizontal ? 'vertical' : 'horizontal'}\n onPointerDown={onPointerDown(spot)}\n onPointerMove={onPointerMove}\n onPointerUp={() => finish('commit')}\n onPointerCancel={() => finish('cancel')}\n style={{\n position: 'absolute',\n left: spot.x - (horizontal ? HANDLE_THICKNESS / 2 : length / 2),\n top: spot.y - (horizontal ? length / 2 : HANDLE_THICKNESS / 2),\n width: horizontal ? HANDLE_THICKNESS : length,\n height: horizontal ? length : HANDLE_THICKNESS,\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n cursor: horizontal ? 'col-resize' : 'row-resize',\n zIndex: 40,\n touchAction: 'none',\n }}\n >\n <div\n style={{\n width: horizontal ? HANDLE_BAR : '100%',\n height: horizontal ? '100%' : HANDLE_BAR,\n borderRadius: 999,\n backgroundColor: active ? '#5b8cff' : 'rgba(91, 140, 255, 0.65)',\n boxShadow: '0 0 0 1px rgba(8, 12, 24, 0.55)',\n }}\n />\n </div>\n )\n })}\n {drag ? (\n <div\n data-ec-gap-label=\"\"\n style={{\n position: 'absolute',\n left: drag.labelX + 12,\n top: drag.labelY + 12,\n zIndex: 50,\n pointerEvents: 'none',\n padding: '2px 8px',\n borderRadius: 6,\n fontSize: 11,\n fontWeight: 600,\n whiteSpace: 'nowrap',\n color: '#fff',\n backgroundColor: '#5b8cff',\n boxShadow: '0 2px 8px rgba(8, 12, 24, 0.4)',\n }}\n >\n {gapStepLabel(drag.step)}\n </div>\n ) : null}\n </div>,\n doc.body,\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"spacing-handles.js","sourceRoot":"","sources":["../../../src/components/builder/spacing-handles.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAE/F,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAA;AAExE,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,eAAe,GAChB,MAAM,o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C,IAAI,CAAC,CAAA;QACb,YAAY,CAAC,IAAI,CAAC,CAAA;IACpB,CAAC,CAAA;IAED,MAAM,UAAU,GAAG,IAAI,KAAK,YAAY,CAAA;IAExC,OAAO,YAAY,CACjB,KAAC,kBAAkB,IACjB,KAAK,EAAE,KAAK,EACZ,UAAU,EAAE,UAAU,EACtB,IAAI,EACF,IAAI;YACF,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACjG,CAAC,CAAC,IAAI,EAEV,aAAa,EAAE,aAAa,EAC5B,aAAa,EAAE,aAAa,EAC5B,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EACnC,eAAe,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,GACvC,EACF,GAAG,CAAC,IAAI,CACT,CAAA;AACH,CAAC","sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\nimport { DEFAULT_SLOT, isLayoutContainerNode, staticProp } from '@elytracms/core/project-graph'\nimport type { ComponentNode } from '@elytracms/core/project-graph'\nimport { containerFlowAxis } from '@elytracms/studio/lib/dnd/drop-rules'\nimport type { FlowAxis } from '@elytracms/studio/lib/dnd/drop-rules'\nimport {\n containerGapStep,\n gapHandleSpots,\n gapStepCss,\n gapStepFromDrag,\n} from '@elytracms/studio/lib/dnd/gap-drag'\nimport type { GapStep } from '@elytracms/studio/lib/dnd/gap-drag'\nimport { translate } from '@elytracms/studio/lib/i18n'\nimport { useBuilder } from './builder-store'\nimport { GAP_LABEL_KEYS, GAP_NONE_LABEL_KEY } from './layout-inspector'\n\n/**\n * Tokenized spacing handles (EC-163, vision §3.1 / AD-10): when a Stack/Grid\n * container is selected on the canvas, draggable gap handles appear between\n * its children, axis-aware via the shared `containerFlowAxis`. Dragging snaps\n * through the EC-161 spacing-token scale (`lib/dnd/gap-drag` — pure math, no\n * pixel value can escape it) with a live plain-language label (the layout\n * inspector's vocabulary). The drag previews imperatively on the rendered\n * element; releasing commits exactly ONE builder dispatch — `setProp` with the\n * token, or `removeProp` for \"no gap\", the identical values the inspector's\n * gap select writes — so one undo restores, and the graph stays the single\n * source of truth. Esc mid-drag cancels: preview reverts, nothing dispatches.\n */\n\n/** Plain-language label for a gap step — the inspector's vocabulary. */\nexport function gapStepLabel(step: GapStep): string {\n return step === null ? translate(GAP_NONE_LABEL_KEY) : translate(GAP_LABEL_KEYS[step])\n}\n\nexport interface HandleSpotView {\n index: number\n /** Document-coordinate position of the handle's center. */\n x: number\n y: number\n crossStart: number\n crossLength: number\n}\n\ninterface ActiveDrag {\n index: number\n startStep: GapStep\n step: GapStep\n /** Pointer start along the flow axis (client coords). */\n startCoord: number\n /** Live pointer position (document coords) for the floating label. */\n labelX: number\n labelY: number\n}\n\n/** The container's rendered element (the Stack/Grid div carrying the gap style). */\nfunction containerElementFor(doc: Document, nodeId: string): HTMLElement | null {\n const wrapper = doc.querySelector(`[data-ec-node-id=\"${nodeId}\"]`)\n return (wrapper?.querySelector(':scope > [data-ec-primitive]') as HTMLElement | null) ?? null\n}\n\ninterface Measured {\n spots: HandleSpotView[]\n /** The axis the children are *rendered* along (drag direction follows it). */\n axis: FlowAxis\n}\n\n/**\n * Measure the handle spots between the container's rendered children. The\n * graph-level flow axis (`containerFlowAxis`) is tried first; when the\n * rendered layout disagrees — a stacking Grid below the mobile breakpoint\n * lays its \"columns\" out vertically — the cross axis is measured instead, so\n * handles always sit in the gaps the editor actually sees.\n */\nfunction measureSpots(doc: Document, nodeId: string, flowAxis: FlowAxis): Measured {\n const container = containerElementFor(doc, nodeId)\n const win = doc.defaultView\n if (!container || !win) return { spots: [], axis: flowAxis }\n const children = Array.from(\n container.querySelectorAll(':scope > [data-ec-node-id]'),\n ) as HTMLElement[]\n if (children.length < 2) return { spots: [], axis: flowAxis }\n const rects = children.map((el) => {\n const r = el.getBoundingClientRect()\n return { left: r.left + win.scrollX, top: r.top + win.scrollY, width: r.width, height: r.height }\n })\n const along = gapHandleSpots(rects, flowAxis)\n if (along.length > 0) return { spots: along, axis: flowAxis }\n const cross: FlowAxis = flowAxis === 'horizontal' ? 'vertical' : 'horizontal'\n const across = gapHandleSpots(rects, cross)\n return across.length > 0 ? { spots: across, axis: cross } : { spots: [], axis: flowAxis }\n}\n\n/** True when the node is a container with at least two children to space. */\nexport function hasSpacingHandles(node: ComponentNode | null): node is ComponentNode {\n return (\n node !== null &&\n isLayoutContainerNode(node) &&\n (node.slots?.[DEFAULT_SLOT]?.length ?? 0) >= 2\n )\n}\n\nconst HANDLE_THICKNESS = 14\nconst HANDLE_BAR = 4\nconst HANDLE_MAX_LENGTH = 48\n\n/** Everything the portal-free handle markup needs (chrome contract surface). */\nexport interface SpacingHandlesViewProps {\n spots: HandleSpotView[]\n horizontal: boolean\n /** The live drag, for the active-handle tint and the floating label. */\n drag: { index: number; labelX: number; labelY: number; label: string } | null\n onPointerDown: (spot: HandleSpotView) => (e: React.PointerEvent<HTMLDivElement>) => void\n onPointerMove: (e: React.PointerEvent<HTMLDivElement>) => void\n onPointerUp: () => void\n onPointerCancel: () => void\n}\n\n/**\n * The spacing handles' rendered markup, portal-free so the AD-D chrome\n * contract test can walk it with `renderToStaticMarkup`. In-frame chrome\n * contract (EC-414 AD-B): `ec-*`/`data-ec-*` plus inline styles only; the root\n * carries the `.ec-chrome` containment recipe.\n */\nexport function SpacingHandlesView(props: SpacingHandlesViewProps) {\n const { spots, horizontal, drag } = props\n return (\n <div data-ec-spacing-handles=\"\" className=\"ec-chrome\">\n {spots.map((spot) => {\n const length = Math.min(spot.crossLength, HANDLE_MAX_LENGTH)\n const active = drag?.index === spot.index\n return (\n <div\n key={spot.index}\n data-ec-gap-handle={spot.index}\n role=\"separator\"\n aria-label={translate('builder.spacing.gapAfterChild', { index: spot.index + 1 })}\n aria-orientation={horizontal ? 'vertical' : 'horizontal'}\n onPointerDown={props.onPointerDown(spot)}\n onPointerMove={props.onPointerMove}\n onPointerUp={props.onPointerUp}\n onPointerCancel={props.onPointerCancel}\n style={{\n position: 'absolute',\n left: spot.x - (horizontal ? HANDLE_THICKNESS / 2 : length / 2),\n top: spot.y - (horizontal ? length / 2 : HANDLE_THICKNESS / 2),\n width: horizontal ? HANDLE_THICKNESS : length,\n height: horizontal ? length : HANDLE_THICKNESS,\n display: 'flex',\n alignItems: 'center',\n justifyContent: 'center',\n cursor: horizontal ? 'col-resize' : 'row-resize',\n zIndex: 40,\n touchAction: 'none',\n }}\n >\n <div\n style={{\n width: horizontal ? HANDLE_BAR : '100%',\n height: horizontal ? '100%' : HANDLE_BAR,\n borderRadius: 999,\n backgroundColor: active ? '#5b8cff' : 'rgba(91, 140, 255, 0.65)',\n boxShadow: '0 0 0 1px rgba(8, 12, 24, 0.55)',\n }}\n />\n </div>\n )\n })}\n {drag ? (\n <div\n data-ec-gap-label=\"\"\n style={{\n position: 'absolute',\n left: drag.labelX + 12,\n top: drag.labelY + 12,\n zIndex: 50,\n pointerEvents: 'none',\n padding: '2px 8px',\n borderRadius: 6,\n fontSize: 11,\n fontWeight: 600,\n whiteSpace: 'nowrap',\n color: '#fff',\n backgroundColor: '#5b8cff',\n boxShadow: '0 2px 8px rgba(8, 12, 24, 0.4)',\n }}\n >\n {drag.label}\n </div>\n ) : null}\n </div>\n )\n}\n\nexport function SpacingHandles({ doc, node }: { doc: Document; node: ComponentNode }) {\n const builder = useBuilder()\n const { dispatch } = builder\n const flowAxis = containerFlowAxis(node)\n const [measured, setMeasured] = useState<Measured>({ spots: [], axis: flowAxis })\n const [drag, setDrag] = useState<ActiveDrag | null>(null)\n const dragRef = useRef<ActiveDrag | null>(null)\n // The container's pre-drag inline gap, restored on cancel/commit (the graph\n // re-render owns the committed value; the preview is imperative-only).\n const inlineGapRef = useRef<string>('')\n\n // Re-measure when the graph, selection, drag preview, or iframe size change.\n useLayoutEffect(() => {\n const measure = () => setMeasured(measureSpots(doc, node.id, flowAxis))\n measure()\n const win = doc.defaultView\n win?.addEventListener('resize', measure)\n return () => win?.removeEventListener('resize', measure)\n }, [doc, node, flowAxis, builder.present, builder.viewport, drag?.step])\n const { spots, axis } = measured\n\n const applyPreview = useCallback(\n (step: GapStep) => {\n const container = containerElementFor(doc, node.id)\n if (container) container.style.gap = gapStepCss(step)\n },\n [doc, node.id],\n )\n\n const finish = useCallback(\n (mode: 'commit' | 'cancel') => {\n const active = dragRef.current\n if (!active) return\n dragRef.current = null\n setDrag(null)\n // Drop the imperative preview; the rendered graph value takes over.\n const container = containerElementFor(doc, node.id)\n if (container) container.style.gap = inlineGapRef.current\n if (mode === 'commit' && active.step !== active.startStep) {\n // Exactly one dispatch — one operations command, one undo step — and\n // the identical prop value the inspector's gap select produces.\n if (active.step === null) {\n dispatch({ type: 'removeProp', id: node.id, name: 'gap' })\n } else {\n dispatch({ type: 'setProp', id: node.id, name: 'gap', value: staticProp(active.step) })\n }\n }\n },\n [doc, node.id, dispatch],\n )\n\n // Esc cancels mid-drag — listen on both documents (focus may sit either side\n // of the iframe boundary while the pointer is captured).\n useEffect(() => {\n if (!drag) return\n const onKeyDown = (e: KeyboardEvent) => {\n if (e.key === 'Escape') {\n e.preventDefault()\n e.stopPropagation()\n finish('cancel')\n }\n }\n doc.addEventListener('keydown', onKeyDown, true)\n document.addEventListener('keydown', onKeyDown, true)\n return () => {\n doc.removeEventListener('keydown', onKeyDown, true)\n document.removeEventListener('keydown', onKeyDown, true)\n }\n }, [drag, doc, finish])\n\n // Cleanup on unmount/selection change mid-drag: revert, never dispatch.\n useEffect(() => () => finish('cancel'), [finish])\n\n const onPointerDown = (spot: HandleSpotView) => (e: React.PointerEvent<HTMLDivElement>) => {\n if (e.button !== 0) return\n e.preventDefault()\n e.stopPropagation()\n const startStep = containerGapStep(node)\n const container = containerElementFor(doc, node.id)\n inlineGapRef.current = container?.style.gap ?? ''\n try {\n e.currentTarget.setPointerCapture(e.pointerId)\n } catch {\n // Synthetic pointer events (tests, automation) have no active pointer\n // to capture; move/up still arrive via the handle's own listeners.\n }\n const next: ActiveDrag = {\n index: spot.index,\n startStep,\n step: startStep,\n startCoord: axis === 'horizontal' ? e.clientX : e.clientY,\n labelX: spot.x,\n labelY: spot.y,\n }\n dragRef.current = next\n setDrag(next)\n }\n\n const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n const active = dragRef.current\n if (!active) return\n const win = doc.defaultView\n const coord = axis === 'horizontal' ? e.clientX : e.clientY\n const step = gapStepFromDrag(active.startStep, coord - active.startCoord)\n const next: ActiveDrag = {\n ...active,\n step,\n labelX: e.clientX + (win?.scrollX ?? 0),\n labelY: e.clientY + (win?.scrollY ?? 0),\n }\n dragRef.current = next\n setDrag(next)\n applyPreview(step)\n }\n\n const horizontal = axis === 'horizontal'\n\n return createPortal(\n <SpacingHandlesView\n spots={spots}\n horizontal={horizontal}\n drag={\n drag\n ? { index: drag.index, labelX: drag.labelX, labelY: drag.labelY, label: gapStepLabel(drag.step) }\n : null\n }\n onPointerDown={onPointerDown}\n onPointerMove={onPointerMove}\n onPointerUp={() => finish('commit')}\n onPointerCancel={() => finish('cancel')}\n />,\n doc.body,\n )\n}\n"]}
|
|
@@ -69,7 +69,8 @@ export declare class PreviewErrorBoundary extends Component<{
|
|
|
69
69
|
* The EC-191 fallback panel — component name + "preview unavailable" + the error.
|
|
70
70
|
* Rendered INTO the preview iframe (which carries only the project stylesheet, and
|
|
71
71
|
* may carry none in tests), so it uses inline styles rather than studio UI classes
|
|
72
|
-
* —
|
|
72
|
+
* — the EC-414 AD-B chrome contract, with the `.ec-chrome` containment recipe on
|
|
73
|
+
* its root (walked by the chrome contract test).
|
|
73
74
|
*/
|
|
74
75
|
export declare function PreviewUnavailable({ displayName, error }: {
|
|
75
76
|
displayName: string;
|