@rien7/seji 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/design-surface.mjs +6 -0
- package/bin/postinstall.mjs +19 -0
- package/bin/seji.mjs +573 -0
- package/dist/agent/host.d.mts +34 -0
- package/dist/agent/host.mjs +387 -0
- package/dist/agent/messages.d.mts +9 -0
- package/dist/agent/messages.mjs +70 -0
- package/dist/agent/runtimes.mjs +157 -0
- package/dist/cli/app.mjs +321 -0
- package/dist/cli/appScan.mjs +284 -0
- package/dist/cli/catalog.mjs +78 -0
- package/dist/cli/component.mjs +165 -0
- package/dist/cli/consolidate.mjs +159 -0
- package/dist/cli/cssImport.mjs +68 -0
- package/dist/cli/dev.mjs +335 -0
- package/dist/cli/doctor.mjs +306 -0
- package/dist/cli/init.mjs +338 -0
- package/dist/cli/legacyNames.mjs +266 -0
- package/dist/cli/migrate.mjs +163 -0
- package/dist/cli/prompt.mjs +34 -0
- package/dist/cli/propose.mjs +208 -0
- package/dist/cli/providers.mjs +344 -0
- package/dist/cli/reviewOps.mjs +110 -0
- package/dist/cli/semver.mjs +45 -0
- package/dist/cli/setup.mjs +357 -0
- package/dist/cli/sketches.mjs +47 -0
- package/dist/cli/skills.mjs +150 -0
- package/dist/cli/snapshot.mjs +107 -0
- package/dist/cli/tokenOps.mjs +120 -0
- package/dist/cli/types.mjs +191 -0
- package/dist/cli/updater.mjs +274 -0
- package/dist/components/astIndex.mjs +992 -0
- package/dist/components/ops.mjs +1069 -0
- package/dist/editor/AgentProposalCard.d.ts +10 -0
- package/dist/editor/AgentProposalCard.d.ts.map +1 -0
- package/dist/editor/AgentProposalCard.js +31 -0
- package/dist/editor/AgentProposalCard.js.map +1 -0
- package/dist/editor/App.d.ts +2 -0
- package/dist/editor/App.d.ts.map +1 -0
- package/dist/editor/App.js +2832 -0
- package/dist/editor/App.js.map +1 -0
- package/dist/editor/CanvasHud.d.ts +12 -0
- package/dist/editor/CanvasHud.d.ts.map +1 -0
- package/dist/editor/CanvasHud.js +13 -0
- package/dist/editor/CanvasHud.js.map +1 -0
- package/dist/editor/CanvasSurface.d.ts +31 -0
- package/dist/editor/CanvasSurface.d.ts.map +1 -0
- package/dist/editor/CanvasSurface.js +270 -0
- package/dist/editor/CanvasSurface.js.map +1 -0
- package/dist/editor/CommentPopover.d.ts +17 -0
- package/dist/editor/CommentPopover.d.ts.map +1 -0
- package/dist/editor/CommentPopover.js +62 -0
- package/dist/editor/CommentPopover.js.map +1 -0
- package/dist/editor/Comments.d.ts +13 -0
- package/dist/editor/Comments.d.ts.map +1 -0
- package/dist/editor/Comments.js +41 -0
- package/dist/editor/Comments.js.map +1 -0
- package/dist/editor/ComponentPage.d.ts +28 -0
- package/dist/editor/ComponentPage.d.ts.map +1 -0
- package/dist/editor/ComponentPage.js +55 -0
- package/dist/editor/ComponentPage.js.map +1 -0
- package/dist/editor/ComponentPanel.d.ts +38 -0
- package/dist/editor/ComponentPanel.d.ts.map +1 -0
- package/dist/editor/ComponentPanel.js +275 -0
- package/dist/editor/ComponentPanel.js.map +1 -0
- package/dist/editor/Glyph.d.ts +51 -0
- package/dist/editor/Glyph.d.ts.map +1 -0
- package/dist/editor/Glyph.js +50 -0
- package/dist/editor/Glyph.js.map +1 -0
- package/dist/editor/History.d.ts +7 -0
- package/dist/editor/History.d.ts.map +1 -0
- package/dist/editor/History.js +51 -0
- package/dist/editor/History.js.map +1 -0
- package/dist/editor/Inspector.d.ts +56 -0
- package/dist/editor/Inspector.d.ts.map +1 -0
- package/dist/editor/Inspector.js +510 -0
- package/dist/editor/Inspector.js.map +1 -0
- package/dist/editor/LazyMount.d.ts +10 -0
- package/dist/editor/LazyMount.d.ts.map +1 -0
- package/dist/editor/LazyMount.js +29 -0
- package/dist/editor/LazyMount.js.map +1 -0
- package/dist/editor/LocaleSwitch.d.ts +3 -0
- package/dist/editor/LocaleSwitch.d.ts.map +1 -0
- package/dist/editor/LocaleSwitch.js +9 -0
- package/dist/editor/LocaleSwitch.js.map +1 -0
- package/dist/editor/PreviewFrame.d.ts +10 -0
- package/dist/editor/PreviewFrame.d.ts.map +1 -0
- package/dist/editor/PreviewFrame.js +22 -0
- package/dist/editor/PreviewFrame.js.map +1 -0
- package/dist/editor/ProjectIndex.d.ts +12 -0
- package/dist/editor/ProjectIndex.d.ts.map +1 -0
- package/dist/editor/ProjectIndex.js +43 -0
- package/dist/editor/ProjectIndex.js.map +1 -0
- package/dist/editor/PromoteComponent.d.ts +28 -0
- package/dist/editor/PromoteComponent.d.ts.map +1 -0
- package/dist/editor/PromoteComponent.js +33 -0
- package/dist/editor/PromoteComponent.js.map +1 -0
- package/dist/editor/PromoteForm.d.ts +18 -0
- package/dist/editor/PromoteForm.d.ts.map +1 -0
- package/dist/editor/PromoteForm.js +35 -0
- package/dist/editor/PromoteForm.js.map +1 -0
- package/dist/editor/PromoteToken.d.ts +31 -0
- package/dist/editor/PromoteToken.d.ts.map +1 -0
- package/dist/editor/PromoteToken.js +94 -0
- package/dist/editor/PromoteToken.js.map +1 -0
- package/dist/editor/StatePreviews.d.ts +28 -0
- package/dist/editor/StatePreviews.d.ts.map +1 -0
- package/dist/editor/StatePreviews.js +113 -0
- package/dist/editor/StatePreviews.js.map +1 -0
- package/dist/editor/ValueCombo.d.ts +51 -0
- package/dist/editor/ValueCombo.d.ts.map +1 -0
- package/dist/editor/ValueCombo.js +260 -0
- package/dist/editor/ValueCombo.js.map +1 -0
- package/dist/editor/agent/AgentPanel.d.ts +19 -0
- package/dist/editor/agent/AgentPanel.d.ts.map +1 -0
- package/dist/editor/agent/AgentPanel.js +271 -0
- package/dist/editor/agent/AgentPanel.js.map +1 -0
- package/dist/editor/agent/Markdown.d.ts +5 -0
- package/dist/editor/agent/Markdown.d.ts.map +1 -0
- package/dist/editor/agent/Markdown.js +28 -0
- package/dist/editor/agent/Markdown.js.map +1 -0
- package/dist/editor/agent/agentApi.d.ts +106 -0
- package/dist/editor/agent/agentApi.d.ts.map +1 -0
- package/dist/editor/agent/agentApi.js +66 -0
- package/dist/editor/agent/agentApi.js.map +1 -0
- package/dist/editor/agent/toolLines.d.ts +38 -0
- package/dist/editor/agent/toolLines.d.ts.map +1 -0
- package/dist/editor/agent/toolLines.js +159 -0
- package/dist/editor/agent/toolLines.js.map +1 -0
- package/dist/editor/agent/useAgent.d.ts +15 -0
- package/dist/editor/agent/useAgent.d.ts.map +1 -0
- package/dist/editor/agent/useAgent.js +65 -0
- package/dist/editor/agent/useAgent.js.map +1 -0
- package/dist/editor/api.d.ts +378 -0
- package/dist/editor/api.d.ts.map +1 -0
- package/dist/editor/api.js +247 -0
- package/dist/editor/api.js.map +1 -0
- package/dist/editor/camera.d.ts +18 -0
- package/dist/editor/camera.d.ts.map +1 -0
- package/dist/editor/camera.js +40 -0
- package/dist/editor/camera.js.map +1 -0
- package/dist/editor/canvas.d.ts +25 -0
- package/dist/editor/canvas.d.ts.map +1 -0
- package/dist/editor/canvas.js +35 -0
- package/dist/editor/canvas.js.map +1 -0
- package/dist/editor/changes/ChangesPage.d.ts +25 -0
- package/dist/editor/changes/ChangesPage.d.ts.map +1 -0
- package/dist/editor/changes/ChangesPage.js +132 -0
- package/dist/editor/changes/ChangesPage.js.map +1 -0
- package/dist/editor/changes/changeModel.d.ts +25 -0
- package/dist/editor/changes/changeModel.d.ts.map +1 -0
- package/dist/editor/changes/changeModel.js +81 -0
- package/dist/editor/changes/changeModel.js.map +1 -0
- package/dist/editor/changes/changeState.d.mts +29 -0
- package/dist/editor/changes/changeState.mjs +187 -0
- package/dist/editor/chrome/EditorChrome.d.ts +49 -0
- package/dist/editor/chrome/EditorChrome.d.ts.map +1 -0
- package/dist/editor/chrome/EditorChrome.js +21 -0
- package/dist/editor/chrome/EditorChrome.js.map +1 -0
- package/dist/editor/drafts.d.ts +46 -0
- package/dist/editor/drafts.d.ts.map +1 -0
- package/dist/editor/drafts.js +38 -0
- package/dist/editor/drafts.js.map +1 -0
- package/dist/editor/i18n.d.ts +29 -0
- package/dist/editor/i18n.d.ts.map +1 -0
- package/dist/editor/i18n.js +2320 -0
- package/dist/editor/i18n.js.map +1 -0
- package/dist/editor/iconStroke.d.ts +6 -0
- package/dist/editor/iconStroke.d.ts.map +1 -0
- package/dist/editor/iconStroke.js +6 -0
- package/dist/editor/iconStroke.js.map +1 -0
- package/dist/editor/main.d.ts +2 -0
- package/dist/editor/main.d.ts.map +1 -0
- package/dist/editor/main.js +14 -0
- package/dist/editor/main.js.map +1 -0
- package/dist/editor/model.d.ts +16 -0
- package/dist/editor/model.d.ts.map +1 -0
- package/dist/editor/model.js +11 -0
- package/dist/editor/model.js.map +1 -0
- package/dist/editor/reasons.d.ts +44 -0
- package/dist/editor/reasons.d.ts.map +1 -0
- package/dist/editor/reasons.js +131 -0
- package/dist/editor/reasons.js.map +1 -0
- package/dist/editor/reviewLifecycle.d.ts +8 -0
- package/dist/editor/reviewLifecycle.d.ts.map +1 -0
- package/dist/editor/reviewLifecycle.js +21 -0
- package/dist/editor/reviewLifecycle.js.map +1 -0
- package/dist/editor/styles.css +8737 -0
- package/dist/editor/tokenMatch.d.ts +59 -0
- package/dist/editor/tokenMatch.d.ts.map +1 -0
- package/dist/editor/tokenMatch.js +198 -0
- package/dist/editor/tokenMatch.js.map +1 -0
- package/dist/editor/tokens/ConsolidatePage.d.ts +16 -0
- package/dist/editor/tokens/ConsolidatePage.d.ts.map +1 -0
- package/dist/editor/tokens/ConsolidatePage.js +244 -0
- package/dist/editor/tokens/ConsolidatePage.js.map +1 -0
- package/dist/editor/tokens/TokenActivity.d.ts +18 -0
- package/dist/editor/tokens/TokenActivity.d.ts.map +1 -0
- package/dist/editor/tokens/TokenActivity.js +18 -0
- package/dist/editor/tokens/TokenActivity.js.map +1 -0
- package/dist/editor/tokens/TokenDialogs.d.ts +26 -0
- package/dist/editor/tokens/TokenDialogs.d.ts.map +1 -0
- package/dist/editor/tokens/TokenDialogs.js +119 -0
- package/dist/editor/tokens/TokenDialogs.js.map +1 -0
- package/dist/editor/tokens/TokenList.d.ts +21 -0
- package/dist/editor/tokens/TokenList.d.ts.map +1 -0
- package/dist/editor/tokens/TokenList.js +98 -0
- package/dist/editor/tokens/TokenList.js.map +1 -0
- package/dist/editor/tokens/TokenPage.d.ts +25 -0
- package/dist/editor/tokens/TokenPage.d.ts.map +1 -0
- package/dist/editor/tokens/TokenPage.js +108 -0
- package/dist/editor/tokens/TokenPage.js.map +1 -0
- package/dist/editor/tokens/tokenModel.d.ts +35 -0
- package/dist/editor/tokens/tokenModel.d.ts.map +1 -0
- package/dist/editor/tokens/tokenModel.js +72 -0
- package/dist/editor/tokens/tokenModel.js.map +1 -0
- package/dist/editor/ui/Button.d.ts +3 -0
- package/dist/editor/ui/Button.d.ts.map +1 -0
- package/dist/editor/ui/Button.js +6 -0
- package/dist/editor/ui/Button.js.map +1 -0
- package/dist/editor/ui/CommentBox.d.ts +23 -0
- package/dist/editor/ui/CommentBox.d.ts.map +1 -0
- package/dist/editor/ui/CommentBox.js +41 -0
- package/dist/editor/ui/CommentBox.js.map +1 -0
- package/dist/editor/ui/Icon.d.ts +8 -0
- package/dist/editor/ui/Icon.d.ts.map +1 -0
- package/dist/editor/ui/Icon.js +6 -0
- package/dist/editor/ui/Icon.js.map +1 -0
- package/dist/editor/ui/IconButton.d.ts +11 -0
- package/dist/editor/ui/IconButton.d.ts.map +1 -0
- package/dist/editor/ui/IconButton.js +6 -0
- package/dist/editor/ui/IconButton.js.map +1 -0
- package/dist/editor/ui/NumberInput.d.ts +14 -0
- package/dist/editor/ui/NumberInput.d.ts.map +1 -0
- package/dist/editor/ui/NumberInput.js +6 -0
- package/dist/editor/ui/NumberInput.js.map +1 -0
- package/dist/editor/ui/PageLine.d.ts +14 -0
- package/dist/editor/ui/PageLine.d.ts.map +1 -0
- package/dist/editor/ui/PageLine.js +7 -0
- package/dist/editor/ui/PageLine.js.map +1 -0
- package/dist/editor/ui/SearchPicker.d.ts +41 -0
- package/dist/editor/ui/SearchPicker.d.ts.map +1 -0
- package/dist/editor/ui/SearchPicker.js +82 -0
- package/dist/editor/ui/SearchPicker.js.map +1 -0
- package/dist/editor/ui/Select.d.ts +19 -0
- package/dist/editor/ui/Select.d.ts.map +1 -0
- package/dist/editor/ui/Select.js +12 -0
- package/dist/editor/ui/Select.js.map +1 -0
- package/dist/editor/ui/TokenField.d.ts +14 -0
- package/dist/editor/ui/TokenField.d.ts.map +1 -0
- package/dist/editor/ui/TokenField.js +41 -0
- package/dist/editor/ui/TokenField.js.map +1 -0
- package/dist/editor/ui/TokenPicker.d.ts +31 -0
- package/dist/editor/ui/TokenPicker.d.ts.map +1 -0
- package/dist/editor/ui/TokenPicker.js +26 -0
- package/dist/editor/ui/TokenPicker.js.map +1 -0
- package/dist/editor/useBuildError.d.ts +7 -0
- package/dist/editor/useBuildError.d.ts.map +1 -0
- package/dist/editor/useBuildError.js +30 -0
- package/dist/editor/useBuildError.js.map +1 -0
- package/dist/editor/useLatestRequest.d.ts +22 -0
- package/dist/editor/useLatestRequest.d.ts.map +1 -0
- package/dist/editor/useLatestRequest.js +49 -0
- package/dist/editor/useLatestRequest.js.map +1 -0
- package/dist/editor-bundle/editor.css +2 -0
- package/dist/editor-bundle/editor.js +83 -0
- package/dist/editor-ui.d.ts +15 -0
- package/dist/editor-ui.d.ts.map +1 -0
- package/dist/editor-ui.js +14 -0
- package/dist/editor-ui.js.map +1 -0
- package/dist/inspector/runtime.d.ts +18 -0
- package/dist/inspector/runtime.d.ts.map +1 -0
- package/dist/inspector/runtime.js +1280 -0
- package/dist/inspector/runtime.js.map +1 -0
- package/dist/preview/main.d.ts +3 -0
- package/dist/preview/main.d.ts.map +1 -0
- package/dist/preview/main.js +320 -0
- package/dist/preview/main.js.map +1 -0
- package/dist/preview/preview.css +40 -0
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +2 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/shared/buildError.d.mts +27 -0
- package/dist/shared/buildError.mjs +141 -0
- package/dist/shared/cameraFit.d.mts +16 -0
- package/dist/shared/cameraFit.mjs +47 -0
- package/dist/shared/canvasLayout.d.mts +13 -0
- package/dist/shared/canvasLayout.mjs +171 -0
- package/dist/shared/commentShots.d.mts +12 -0
- package/dist/shared/commentShots.mjs +53 -0
- package/dist/shared/componentExtract.d.mts +43 -0
- package/dist/shared/componentExtract.mjs +136 -0
- package/dist/shared/componentMeta.d.mts +26 -0
- package/dist/shared/componentMeta.mjs +87 -0
- package/dist/shared/componentOps.d.mts +70 -0
- package/dist/shared/componentOps.mjs +407 -0
- package/dist/shared/componentTarget.d.mts +15 -0
- package/dist/shared/componentTarget.mjs +58 -0
- package/dist/shared/components.d.mts +30 -0
- package/dist/shared/components.mjs +106 -0
- package/dist/shared/consolidateCategories.d.mts +2 -0
- package/dist/shared/consolidateCategories.mjs +6 -0
- package/dist/shared/env.d.mts +4 -0
- package/dist/shared/env.mjs +18 -0
- package/dist/shared/gitChanges.d.mts +2 -0
- package/dist/shared/gitChanges.mjs +30 -0
- package/dist/shared/oklab.d.mts +6 -0
- package/dist/shared/oklab.mjs +56 -0
- package/dist/shared/optimizeEntries.d.mts +5 -0
- package/dist/shared/optimizeEntries.mjs +24 -0
- package/dist/shared/packages.d.mts +11 -0
- package/dist/shared/packages.mjs +96 -0
- package/dist/shared/projectFiles.d.mts +23 -0
- package/dist/shared/projectFiles.mjs +72 -0
- package/dist/shared/prompt.d.mts +20 -0
- package/dist/shared/prompt.mjs +201 -0
- package/dist/shared/proposals.d.mts +11 -0
- package/dist/shared/proposals.mjs +42 -0
- package/dist/shared/protocol.d.ts +122 -0
- package/dist/shared/protocol.d.ts.map +1 -0
- package/dist/shared/protocol.js +7 -0
- package/dist/shared/protocol.js.map +1 -0
- package/dist/shared/reviewArchive.d.mts +4 -0
- package/dist/shared/reviewArchive.mjs +19 -0
- package/dist/shared/reviewStore.d.mts +30 -0
- package/dist/shared/reviewStore.mjs +218 -0
- package/dist/shared/reviewVerify.d.mts +21 -0
- package/dist/shared/reviewVerify.mjs +158 -0
- package/dist/shared/sizeModes.d.mts +15 -0
- package/dist/shared/sizeModes.mjs +53 -0
- package/dist/shared/sketches.d.mts +10 -0
- package/dist/shared/sketches.mjs +64 -0
- package/dist/shared/snapshotCheck.d.mts +13 -0
- package/dist/shared/snapshotCheck.mjs +81 -0
- package/dist/shared/timeout.d.mts +1 -0
- package/dist/shared/timeout.mjs +15 -0
- package/dist/shared/tokens.d.ts +2 -0
- package/dist/shared/tokens.d.ts.map +1 -0
- package/dist/shared/tokens.js +2 -0
- package/dist/shared/tokens.js.map +1 -0
- package/dist/shared/types.d.ts +689 -0
- package/dist/shared/types.d.ts.map +1 -0
- package/dist/shared/types.js +13 -0
- package/dist/shared/types.js.map +1 -0
- package/dist/shared/wheelRouting.d.mts +9 -0
- package/dist/shared/wheelRouting.mjs +31 -0
- package/dist/shared/writeScope.mjs +96 -0
- package/dist/snapshots/diff.d.mts +28 -0
- package/dist/snapshots/diff.mjs +263 -0
- package/dist/snapshots/index.d.mts +110 -0
- package/dist/snapshots/index.mjs +638 -0
- package/dist/snapshots/render.d.mts +24 -0
- package/dist/snapshots/render.mjs +250 -0
- package/dist/snapshots/toolOps.d.mts +25 -0
- package/dist/snapshots/toolOps.mjs +69 -0
- package/dist/tokens/adapters/css.mjs +51 -0
- package/dist/tokens/adapters/cssInCode.mjs +314 -0
- package/dist/tokens/adapters/oxcShared.mjs +80 -0
- package/dist/tokens/adapters/preprocessor.mjs +63 -0
- package/dist/tokens/adapters/registry.mjs +53 -0
- package/dist/tokens/adapters/tailwindcss.mjs +424 -0
- package/dist/tokens/adapters/types.mjs +117 -0
- package/dist/tokens/consolidate/index.d.mts +42 -0
- package/dist/tokens/consolidate/index.mjs +111 -0
- package/dist/tokens/consolidate/normalize.mjs +479 -0
- package/dist/tokens/consolidate/plan.mjs +726 -0
- package/dist/tokens/consolidate/scan.mjs +928 -0
- package/dist/tokens/extract.mjs +441 -0
- package/dist/tokens/moduleData.d.mts +14 -0
- package/dist/tokens/moduleData.mjs +32 -0
- package/dist/tokens/opLock.d.mts +4 -0
- package/dist/tokens/opLock.mjs +108 -0
- package/dist/tokens/ops.d.mts +71 -0
- package/dist/tokens/ops.mjs +1511 -0
- package/dist/tokens/pipeline.mjs +813 -0
- package/dist/tokens/report.d.mts +47 -0
- package/dist/tokens/report.mjs +257 -0
- package/dist/tokens/rewrite/code.mjs +172 -0
- package/dist/tokens/rewrite/css.mjs +154 -0
- package/dist/tokens/rewrite/index.mjs +244 -0
- package/dist/tokens/rewrite/tailwind.mjs +288 -0
- package/dist/tokens/rewrite/text.mjs +116 -0
- package/dist/tokens/rewrite/value.mjs +115 -0
- package/dist/tokens/usage.d.mts +97 -0
- package/dist/tokens/usage.mjs +680 -0
- package/dist/vite/agent.d.ts +21 -0
- package/dist/vite/agent.d.ts.map +1 -0
- package/dist/vite/agent.js +165 -0
- package/dist/vite/agent.js.map +1 -0
- package/dist/vite/events.d.ts +27 -0
- package/dist/vite/events.d.ts.map +1 -0
- package/dist/vite/events.js +156 -0
- package/dist/vite/events.js.map +1 -0
- package/dist/vite/layout.d.ts +2 -0
- package/dist/vite/layout.d.ts.map +1 -0
- package/dist/vite/layout.js +4 -0
- package/dist/vite/layout.js.map +1 -0
- package/dist/vite/plugin.d.ts +40 -0
- package/dist/vite/plugin.d.ts.map +1 -0
- package/dist/vite/plugin.js +1255 -0
- package/dist/vite/plugin.js.map +1 -0
- package/dist/vite/requestGuard.d.mts +3 -0
- package/dist/vite/requestGuard.mjs +43 -0
- package/dist/vite/review.d.ts +11 -0
- package/dist/vite/review.d.ts.map +1 -0
- package/dist/vite/review.js +283 -0
- package/dist/vite/review.js.map +1 -0
- package/package.json +104 -4
- package/skills/seji/SKILL.md +395 -0
- package/skills/seji-authoring/SKILL.md +397 -0
- package/skills/seji-tokens/SKILL.md +432 -0
- package/README.md +0 -3
|
@@ -0,0 +1,2832 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react';
|
|
3
|
+
import { Dialog } from '@base-ui/react/dialog';
|
|
4
|
+
import { Field } from '@base-ui/react/field';
|
|
5
|
+
import { Tabs } from '@base-ui/react/tabs';
|
|
6
|
+
import { BotIcon, CheckIcon, ChevronLeftIcon, ChevronRightIcon, ComponentIcon, CopyIcon, FileIcon, LayoutTemplateIcon, ListChecksIcon, MessageSquarePlusIcon, SearchIcon, SlidersHorizontalIcon, XIcon, } from 'lucide-react';
|
|
7
|
+
import { designPages, } from '@rien7/design-surface-runtime';
|
|
8
|
+
import { createPageFit } from '../shared/cameraFit.mjs';
|
|
9
|
+
import { sourceKind } from '../shared/sketches.mjs';
|
|
10
|
+
import { buildAgentPrompt, isCopyableReviewItem, missingComponentPages } from '../shared/prompt.mjs';
|
|
11
|
+
import { isAwaitingVerification, tokenVerificationGap } from '../shared/reviewVerify.mjs';
|
|
12
|
+
import * as manifestModule from 'virtual:design/manifest';
|
|
13
|
+
import * as componentsModule from 'virtual:design/components';
|
|
14
|
+
import * as tokensModule from 'virtual:design/tokens';
|
|
15
|
+
import { version } from 'virtual:design/config';
|
|
16
|
+
import { ApiError, captureFrameShot, decideProposal, loadComponent, loadComponents, loadLayout, loadReview, loadTokenData, loadTokenUsage, loadUsageSummary, planComponentAction, postComponentAction, postTokenOp, revertComponentBatch, saveCamera, saveCommentShot, saveLayout, saveReviewOps, subscribeReview, } from './api';
|
|
17
|
+
import { ChangesPage } from './changes/ChangesPage';
|
|
18
|
+
import { changeEntries, isChangeItem } from './changes/changeModel';
|
|
19
|
+
import { AgentPanel } from './agent/AgentPanel';
|
|
20
|
+
import { agentSend } from './agent/agentApi';
|
|
21
|
+
import { useAgent } from './agent/useAgent';
|
|
22
|
+
import { ComponentPanel } from './ComponentPanel';
|
|
23
|
+
import { extractItem, extractSourceOf, takenComponentNames } from '../shared/componentExtract.mjs';
|
|
24
|
+
import { ComponentPageAfter, ComponentPageHead } from './ComponentPage';
|
|
25
|
+
import { EditorRightPanel, EditorSidePanel, EditorStatusBar, EditorTopbar } from './chrome/EditorChrome';
|
|
26
|
+
import { History } from './History';
|
|
27
|
+
import { CommentPopover } from './CommentPopover';
|
|
28
|
+
import { Comments } from './Comments';
|
|
29
|
+
import { Inspector } from './Inspector';
|
|
30
|
+
import { StatePreviews } from './StatePreviews';
|
|
31
|
+
import { VARIANT_LIMIT, baseFrameKey, draftKey, entriesWithin, isVariantKey, loadDrafts, saveDrafts, variantSeparator, } from './drafts';
|
|
32
|
+
import { LazyMount } from './LazyMount';
|
|
33
|
+
import { PreviewFrame } from './PreviewFrame';
|
|
34
|
+
import { LocaleSwitch } from './LocaleSwitch';
|
|
35
|
+
import { CanvasSurface, applyCanvasWheel } from './CanvasSurface';
|
|
36
|
+
import { framePointToViewport, wheelPixels } from '../shared/wheelRouting.mjs';
|
|
37
|
+
import { createCameraStore, clampZoom } from './camera';
|
|
38
|
+
import { defaultCanvasPositions, mergeCanvasPositions, nodeDefinitions, } from './canvas';
|
|
39
|
+
import { ProjectIndex } from './ProjectIndex';
|
|
40
|
+
import { ConsolidatePage } from './tokens/ConsolidatePage';
|
|
41
|
+
import { TokenActivity } from './tokens/TokenActivity';
|
|
42
|
+
import { TokenList } from './tokens/TokenList';
|
|
43
|
+
import { TokenPage } from './tokens/TokenPage';
|
|
44
|
+
import { tokenLabel } from './tokens/tokenModel';
|
|
45
|
+
import { createFrameState, valueOf } from './model';
|
|
46
|
+
import { Button } from './ui/Button';
|
|
47
|
+
import { Glyph } from './Glyph';
|
|
48
|
+
import { PageLine } from './ui/PageLine';
|
|
49
|
+
import { Icon } from './ui/Icon';
|
|
50
|
+
import { IconButton } from './ui/IconButton';
|
|
51
|
+
import { useI18n } from './i18n';
|
|
52
|
+
import { useBuildError } from './useBuildError';
|
|
53
|
+
import { errorWhere } from '../shared/buildError.mjs';
|
|
54
|
+
import { errorText } from './reasons';
|
|
55
|
+
import { dueForArchive, isOpenComment, mergeReviewItems, nowIso, reviewId, } from './reviewLifecycle';
|
|
56
|
+
let DESIGNS = manifestModule.designs;
|
|
57
|
+
let { componentCatalog, componentDirs, componentGroups, componentPages, componentSources } = componentsModule;
|
|
58
|
+
let { tokenAliases, tokenGroups, tokenHealth, tokenSourceHash, tokenValues: sourceTokenValues } = tokensModule;
|
|
59
|
+
let health = tokenHealth;
|
|
60
|
+
const sourceLabel = (file) => file.replace(/^(?:\.\.\/)+/, '');
|
|
61
|
+
const normalizeFilePath = (file) => file.replaceAll('\\', '/').replace(/^\.\//, '');
|
|
62
|
+
/** Files that still hard-code `value`, per the last token build. */
|
|
63
|
+
const literalFilesOf = (value) => {
|
|
64
|
+
const needle = value.toLowerCase();
|
|
65
|
+
return (health?.clusters?.find((entry) => entry.value.toLowerCase() === needle)?.files ??
|
|
66
|
+
(health?.hardcoded ?? [])
|
|
67
|
+
.filter((entry) => entry.values?.some((item) => item.value.toLowerCase() === needle))
|
|
68
|
+
.map((entry) => entry.file));
|
|
69
|
+
};
|
|
70
|
+
/** Component names that have a component page (token pages link to them). */
|
|
71
|
+
let componentPageNames = new Set(Object.keys(componentPages));
|
|
72
|
+
let liveVersion = 0;
|
|
73
|
+
const liveListeners = new Set();
|
|
74
|
+
const subscribeLive = (listener) => {
|
|
75
|
+
liveListeners.add(listener);
|
|
76
|
+
return () => {
|
|
77
|
+
liveListeners.delete(listener);
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const liveSnapshot = () => liveVersion;
|
|
81
|
+
const bumpLive = () => {
|
|
82
|
+
liveVersion += 1;
|
|
83
|
+
for (const listener of liveListeners)
|
|
84
|
+
listener();
|
|
85
|
+
};
|
|
86
|
+
const onHot = (name, apply) => window.addEventListener(`design-surface:${name}`, (event) => {
|
|
87
|
+
apply(event.detail);
|
|
88
|
+
bumpLive();
|
|
89
|
+
});
|
|
90
|
+
onHot('manifest', (mod) => {
|
|
91
|
+
DESIGNS = mod.designs;
|
|
92
|
+
});
|
|
93
|
+
onHot('components', (mod) => {
|
|
94
|
+
;
|
|
95
|
+
({ componentCatalog, componentDirs, componentGroups, componentPages, componentSources } = mod);
|
|
96
|
+
componentPageNames = new Set(Object.keys(componentPages));
|
|
97
|
+
});
|
|
98
|
+
// Token data has one owner, the bindings above: seeded by virtual:design/tokens, replaced by a
|
|
99
|
+
// hot update of that module or, after a token build, by GET /__seji/api/tokens (the dev
|
|
100
|
+
// server's `design-surface:tokens-data` event, relayed by the virtual module).
|
|
101
|
+
const applyTokenData = (mod) => {
|
|
102
|
+
;
|
|
103
|
+
({ tokenAliases, tokenGroups, tokenHealth, tokenSourceHash, tokenValues: sourceTokenValues } = mod);
|
|
104
|
+
health = tokenHealth;
|
|
105
|
+
};
|
|
106
|
+
onHot('tokens', applyTokenData);
|
|
107
|
+
let tokenDataRequest = 0;
|
|
108
|
+
window.addEventListener('design-surface:tokens-data', () => {
|
|
109
|
+
const request = ++tokenDataRequest;
|
|
110
|
+
void loadTokenData().then((data) => {
|
|
111
|
+
if (!data || request !== tokenDataRequest)
|
|
112
|
+
return;
|
|
113
|
+
applyTokenData(data);
|
|
114
|
+
bumpLive();
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
const componentNameForPage = (designId, pageId) => Object.entries(componentPages).find(([, page]) => page.design === designId && page.page === pageId)?.[0];
|
|
118
|
+
const frameKeyOf = (pageId, frameId) => `${pageId}__${frameId}`;
|
|
119
|
+
// Variant artboards use `<frame key>~<letter>`; they belong to their base frame.
|
|
120
|
+
const pageIdOfFrameKey = (key) => baseFrameKey(key).split('__')[0] ?? '';
|
|
121
|
+
const frameIdOfFrameKey = (key) => baseFrameKey(key).split('__')[1] ?? '';
|
|
122
|
+
const EMPTY_DRAFTS = { entries: [], variants: [] };
|
|
123
|
+
const VARIANT_LETTERS = ['A', 'B', 'C', 'D'];
|
|
124
|
+
const isOpenItem = (item) => item.status === 'open' || item.status === 'in_progress';
|
|
125
|
+
const stateOf = (item) => item.state ?? 'default';
|
|
126
|
+
/** Value a property had before any draft: a bound token, the width, or the computed style. */
|
|
127
|
+
const originalValue = (node, property) => {
|
|
128
|
+
if (!node)
|
|
129
|
+
return '';
|
|
130
|
+
const variable = node.variables?.find((item) => item.property === property);
|
|
131
|
+
if (variable)
|
|
132
|
+
return `var(${variable.token})`;
|
|
133
|
+
if (property === 'width' && node.layout)
|
|
134
|
+
return `${Math.round(node.layout.width)}px`;
|
|
135
|
+
const key = property.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
136
|
+
return node.styles?.[key] ?? '';
|
|
137
|
+
};
|
|
138
|
+
const RESOURCE_PAGES = new Set(['overview', 'tokens', 'consolidate', 'changes']);
|
|
139
|
+
const isResourcePage = (id) => Boolean(id && RESOURCE_PAGES.has(id));
|
|
140
|
+
const navTabOfResource = (page) => page === 'overview' ? 'components' : page === 'changes' ? 'pages' : 'tokens';
|
|
141
|
+
const RESOURCE_PARAMS = ['token', 'plan', 'item'];
|
|
142
|
+
/**
|
|
143
|
+
* Writes `?design=&page=&…`. `push` (moving to another page or resource) adds a history entry,
|
|
144
|
+
* so Back returns (the popstate handler restores it); otherwise the current entry is replaced
|
|
145
|
+
* (frame selection on the canvas, parameter normalisation).
|
|
146
|
+
*/
|
|
147
|
+
const replaceUrl = (design, page, extra, push = false) => {
|
|
148
|
+
const params = new URLSearchParams(window.location.search);
|
|
149
|
+
params.set('design', design);
|
|
150
|
+
params.set('page', page);
|
|
151
|
+
for (const key of ['frame', ...RESOURCE_PARAMS])
|
|
152
|
+
params.delete(key);
|
|
153
|
+
for (const [key, value] of Object.entries(extra))
|
|
154
|
+
if (value)
|
|
155
|
+
params.set(key, value);
|
|
156
|
+
const next = `?${params.toString()}`;
|
|
157
|
+
if (push && next !== window.location.search)
|
|
158
|
+
window.history.pushState(null, '', next);
|
|
159
|
+
else
|
|
160
|
+
window.history.replaceState(null, '', next);
|
|
161
|
+
};
|
|
162
|
+
/** `?design=&page=&frame=` for a canvas frame; leaving a resource page for the canvas is navigation. */
|
|
163
|
+
const replaceCanvasUrl = (design, page, frame) => replaceUrl(design, page, { frame }, isResourcePage(new URLSearchParams(window.location.search).get('page')));
|
|
164
|
+
const toNodeRef = (node) => ({
|
|
165
|
+
id: node.id,
|
|
166
|
+
anchor: node.ownAnchor ?? node.anchor,
|
|
167
|
+
tag: node.tag,
|
|
168
|
+
name: node.name,
|
|
169
|
+
component: node.component ?? null,
|
|
170
|
+
...(node.components?.length ? { components: node.components } : {}),
|
|
171
|
+
source: node.source ?? null,
|
|
172
|
+
path: node.path,
|
|
173
|
+
html: node.html ?? '',
|
|
174
|
+
rect: node.rect,
|
|
175
|
+
freeRect: node.freeRect,
|
|
176
|
+
});
|
|
177
|
+
const useMediaQuery = (query) => {
|
|
178
|
+
const [matches, setMatches] = useState(() => window.matchMedia(query).matches);
|
|
179
|
+
useEffect(() => {
|
|
180
|
+
const media = window.matchMedia(query);
|
|
181
|
+
const onChange = () => setMatches(media.matches);
|
|
182
|
+
onChange();
|
|
183
|
+
media.addEventListener('change', onChange);
|
|
184
|
+
return () => media.removeEventListener('change', onChange);
|
|
185
|
+
}, [query]);
|
|
186
|
+
return matches;
|
|
187
|
+
};
|
|
188
|
+
function DefaultPageBoard({ frames, renderFrame }) {
|
|
189
|
+
return (_jsx("div", { className: "default-page-board", children: frames.map(renderFrame) }));
|
|
190
|
+
}
|
|
191
|
+
export function App() {
|
|
192
|
+
const { locale, t } = useI18n();
|
|
193
|
+
const buildError = useBuildError();
|
|
194
|
+
const live = useSyncExternalStore(subscribeLive, liveSnapshot);
|
|
195
|
+
const isMobile = useMediaQuery('(max-width: 900px)');
|
|
196
|
+
const isMobileRef = useRef(isMobile);
|
|
197
|
+
isMobileRef.current = isMobile;
|
|
198
|
+
const initialId = useRef(new URLSearchParams(window.location.search).get('design')).current;
|
|
199
|
+
const [designId, setDesignId] = useState(initialId && DESIGNS[initialId] ? initialId : '');
|
|
200
|
+
const design = designId ? DESIGNS[designId] : undefined;
|
|
201
|
+
const pages = useMemo(() => (design ? designPages(design) : []), [design]);
|
|
202
|
+
const componentPageIds = useMemo(() => new Set(Object.values(componentPages).map((entry) => entry.page)), [live]);
|
|
203
|
+
const pageList = useMemo(() => pages.filter((page) => !componentPageIds.has(page.id)), [componentPageIds, pages]);
|
|
204
|
+
const frames = pages;
|
|
205
|
+
const frameDefs = useMemo(() => pages.flatMap((page) => page.frames.map((frame) => ({
|
|
206
|
+
page,
|
|
207
|
+
frame,
|
|
208
|
+
key: `${page.id}__${frame.id}`,
|
|
209
|
+
}))), [pages]);
|
|
210
|
+
const frameByKey = useMemo(() => Object.fromEntries(frameDefs.map((entry) => [entry.key, entry])), [frameDefs]);
|
|
211
|
+
const [frameStates, setFrameStates] = useState({});
|
|
212
|
+
const [reviewItems, setReviewItems] = useState([]);
|
|
213
|
+
const reviewRef = useRef([]);
|
|
214
|
+
reviewRef.current = reviewItems;
|
|
215
|
+
const [activeFrameId, setActiveFrameId] = useState('');
|
|
216
|
+
const [activePageId, setActivePageId] = useState('');
|
|
217
|
+
const activePageRef = useRef('');
|
|
218
|
+
activePageRef.current = activePageId;
|
|
219
|
+
const [play, setPlay] = useState(new Set());
|
|
220
|
+
const playRef = useRef(new Set());
|
|
221
|
+
playRef.current = play;
|
|
222
|
+
const [positions, setPositions] = useState({});
|
|
223
|
+
const cameraRef = useRef(null);
|
|
224
|
+
if (!cameraRef.current) {
|
|
225
|
+
cameraRef.current = createCameraStore({ x: 60, y: 60, zoom: 0.55 });
|
|
226
|
+
}
|
|
227
|
+
const camera = cameraRef.current;
|
|
228
|
+
// Saved cameras by page id (this design): a page opens where it was left.
|
|
229
|
+
const pageCamerasRef = useRef({});
|
|
230
|
+
const [mobilePanel, setMobilePanel] = useState(null);
|
|
231
|
+
const [navTab, setNavTab] = useState('pages');
|
|
232
|
+
const [navQuery, setNavQuery] = useState('');
|
|
233
|
+
const [rightTab, setRightTab] = useState('inspect');
|
|
234
|
+
// The editor's agent (0.5.0): the dev server runs it; this is its stream and state.
|
|
235
|
+
const agent = useAgent();
|
|
236
|
+
// What the resource pages show (from `?token=`, `?plan=`, `?item=`).
|
|
237
|
+
const [activeToken, setActiveToken] = useState(null);
|
|
238
|
+
const [activePlan, setActivePlan] = useState(null);
|
|
239
|
+
const [activeChange, setActiveChange] = useState(null);
|
|
240
|
+
// `seji usage` for every token (token list counts and filters).
|
|
241
|
+
const [usageSummary, setUsageSummary] = useState(null);
|
|
242
|
+
const [leftCollapsed, setLeftCollapsed] = useState(() => {
|
|
243
|
+
try {
|
|
244
|
+
return localStorage.getItem('design-surface:left-collapsed') === '1';
|
|
245
|
+
}
|
|
246
|
+
catch {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
const leftCollapsedRef = useRef(leftCollapsed);
|
|
251
|
+
leftCollapsedRef.current = leftCollapsed;
|
|
252
|
+
const setLeftPanelCollapsed = (collapsed) => {
|
|
253
|
+
setLeftCollapsed(collapsed);
|
|
254
|
+
try {
|
|
255
|
+
localStorage.setItem('design-surface:left-collapsed', collapsed ? '1' : '0');
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
/* storage unavailable */
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
const [rightCollapsed, setRightCollapsed] = useState(() => {
|
|
262
|
+
try {
|
|
263
|
+
return localStorage.getItem('design-surface:right-collapsed') === '1';
|
|
264
|
+
}
|
|
265
|
+
catch {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
const rightCollapsedRef = useRef(rightCollapsed);
|
|
270
|
+
rightCollapsedRef.current = rightCollapsed;
|
|
271
|
+
const setRightPanelCollapsed = (collapsed) => {
|
|
272
|
+
setRightCollapsed(collapsed);
|
|
273
|
+
try {
|
|
274
|
+
localStorage.setItem('design-surface:right-collapsed', collapsed ? '1' : '0');
|
|
275
|
+
}
|
|
276
|
+
catch {
|
|
277
|
+
/* storage unavailable */
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
const [commentMode, setCommentMode] = useState(false);
|
|
281
|
+
const commentModeRef = useRef(commentMode);
|
|
282
|
+
commentModeRef.current = commentMode;
|
|
283
|
+
const commentRestorePlayRef = useRef(false);
|
|
284
|
+
const [commentTarget, setCommentTarget] = useState(null);
|
|
285
|
+
const [commentDraft, setCommentDraft] = useState('');
|
|
286
|
+
const [activeCommentId, setActiveCommentId] = useState(null);
|
|
287
|
+
const [copied, setCopied] = useState(false);
|
|
288
|
+
const [error, setError] = useState(null);
|
|
289
|
+
// Component pages: list (left rail) and the open component's report (right panel).
|
|
290
|
+
const [componentList, setComponentList] = useState(null);
|
|
291
|
+
const [componentReport, setComponentReport] = useState(null);
|
|
292
|
+
const [componentLoading, setComponentLoading] = useState(false);
|
|
293
|
+
const [componentError, setComponentError] = useState(null);
|
|
294
|
+
const [componentFilter, setComponentFilter] = useState('all');
|
|
295
|
+
const [componentRefresh, setComponentRefresh] = useState(0);
|
|
296
|
+
const currentComponent = designId ? componentNameForPage(designId, activePageId) ?? null : null;
|
|
297
|
+
const [tidyOpen, setTidyOpen] = useState(false);
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
setTidyOpen(false);
|
|
300
|
+
}, [currentComponent]);
|
|
301
|
+
// Inspector drafts: local to this browser, never written to review.json.
|
|
302
|
+
const [drafts, setDrafts] = useState(EMPTY_DRAFTS);
|
|
303
|
+
const draftsRef = useRef(EMPTY_DRAFTS);
|
|
304
|
+
const draftsOwner = useRef('');
|
|
305
|
+
const [draftMessage, setDraftMessage] = useState(null);
|
|
306
|
+
// Shift-click adds nodes (from any artboard) next to the primary selection.
|
|
307
|
+
const [extraSelection, setExtraSelection] = useState([]);
|
|
308
|
+
const extraRef = useRef(extraSelection);
|
|
309
|
+
extraRef.current = extraSelection;
|
|
310
|
+
// Pseudo state being edited on the primary selection.
|
|
311
|
+
const [editState, setEditState] = useState('default');
|
|
312
|
+
const editStateRef = useRef(editState);
|
|
313
|
+
editStateRef.current = editState;
|
|
314
|
+
// A click on a component page's state preview: the frame is asked to select that
|
|
315
|
+
// component (`select-component`, sent once the frame is ready) and the picked state is
|
|
316
|
+
// applied when its `design:select` answers. `componentTargets` remembers, per frame, the
|
|
317
|
+
// path of the component root that was selected that way.
|
|
318
|
+
const pendingComponentPickRef = useRef(null);
|
|
319
|
+
const [componentTargets, setComponentTargets] = useState({});
|
|
320
|
+
const previewRef = useRef(null);
|
|
321
|
+
const inspectorTargetsRef = useRef([]);
|
|
322
|
+
const activeFrameRef = useRef(activeFrameId);
|
|
323
|
+
activeFrameRef.current = activeFrameId;
|
|
324
|
+
const frameStatesRef = useRef(frameStates);
|
|
325
|
+
frameStatesRef.current = frameStates;
|
|
326
|
+
const iframes = useRef({});
|
|
327
|
+
const pendingReviewOps = useRef([]);
|
|
328
|
+
const reviewSaveInFlight = useRef(0);
|
|
329
|
+
const deferredReviewSync = useRef(false);
|
|
330
|
+
const reviewSaveTimer = useRef(null);
|
|
331
|
+
const reviewSaveChain = useRef(Promise.resolve());
|
|
332
|
+
const canvasRef = useRef(null);
|
|
333
|
+
const positionsRef = useRef({});
|
|
334
|
+
const send = useCallback((frameId, command) => {
|
|
335
|
+
iframes.current[frameId]?.contentWindow?.postMessage({ type: 'design:command', ...command }, '*');
|
|
336
|
+
}, []);
|
|
337
|
+
const applyFramePendingChanges = useCallback((frameId, items) => {
|
|
338
|
+
for (const item of items) {
|
|
339
|
+
if (item.frame !== baseFrameKey(frameId))
|
|
340
|
+
continue;
|
|
341
|
+
if (item.status === 'archived' || item.status === 'resolved')
|
|
342
|
+
continue;
|
|
343
|
+
if (item.target.type !== 'node')
|
|
344
|
+
continue;
|
|
345
|
+
if (item.kind === 'free' && item.to) {
|
|
346
|
+
send(frameId, {
|
|
347
|
+
action: 'set-free-rect',
|
|
348
|
+
anchor: item.target.node.anchor,
|
|
349
|
+
path: item.target.node.path,
|
|
350
|
+
rect: item.to,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
else if (item.kind === 'style' && item.to !== undefined) {
|
|
354
|
+
send(frameId, {
|
|
355
|
+
action: 'set-style',
|
|
356
|
+
anchor: item.target.node.anchor,
|
|
357
|
+
path: item.target.node.path,
|
|
358
|
+
property: item.property ?? '',
|
|
359
|
+
value: String(item.to),
|
|
360
|
+
...(item.state ? { state: item.state } : {}),
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
else if (item.kind === 'suggestion') {
|
|
364
|
+
const token = item.token ?? (typeof item.to === 'string' ? item.to : '');
|
|
365
|
+
if (token.startsWith('--') && item.property) {
|
|
366
|
+
send(frameId, {
|
|
367
|
+
action: 'set-style',
|
|
368
|
+
anchor: item.target.node.anchor,
|
|
369
|
+
path: item.target.node.path,
|
|
370
|
+
property: item.property,
|
|
371
|
+
value: `var(${token})`,
|
|
372
|
+
...(item.state ? { state: item.state } : {}),
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}, [send]);
|
|
378
|
+
const writeDrafts = useCallback((next) => {
|
|
379
|
+
draftsRef.current = next;
|
|
380
|
+
setDrafts(next);
|
|
381
|
+
if (draftsOwner.current)
|
|
382
|
+
saveDrafts(draftsOwner.current, next);
|
|
383
|
+
}, []);
|
|
384
|
+
const draftCommand = (entry, id) => ({
|
|
385
|
+
action: 'set-style',
|
|
386
|
+
...(id !== undefined ? { id } : {}),
|
|
387
|
+
anchor: entry.node.anchor,
|
|
388
|
+
path: entry.node.path,
|
|
389
|
+
property: entry.property,
|
|
390
|
+
value: entry.value,
|
|
391
|
+
...(entry.state !== 'default' ? { state: entry.state } : {}),
|
|
392
|
+
});
|
|
393
|
+
const applyFrameDrafts = useCallback((frameId) => {
|
|
394
|
+
for (const entry of draftsRef.current.entries) {
|
|
395
|
+
if (entry.frame === frameId)
|
|
396
|
+
send(frameId, draftCommand(entry));
|
|
397
|
+
}
|
|
398
|
+
}, [send]);
|
|
399
|
+
// Value a property shows without its draft: a saved (pending) change, or nothing.
|
|
400
|
+
const savedStyleValue = useCallback((frameId, path, property, state) => {
|
|
401
|
+
const item = reviewRef.current.find((entry) => (entry.kind === 'style' || entry.kind === 'suggestion') &&
|
|
402
|
+
entry.frame === baseFrameKey(frameId) &&
|
|
403
|
+
entry.status !== 'archived' &&
|
|
404
|
+
entry.status !== 'resolved' &&
|
|
405
|
+
entry.target.type === 'node' &&
|
|
406
|
+
entry.target.node.path === path &&
|
|
407
|
+
entry.property === property &&
|
|
408
|
+
stateOf(entry) === state);
|
|
409
|
+
if (!item)
|
|
410
|
+
return null;
|
|
411
|
+
if (item.kind === 'suggestion') {
|
|
412
|
+
const token = item.token ?? String(item.to ?? '');
|
|
413
|
+
return token.startsWith('--') ? `var(${token})` : null;
|
|
414
|
+
}
|
|
415
|
+
return item.to === undefined ? null : String(item.to);
|
|
416
|
+
}, []);
|
|
417
|
+
// Put a property back to what it shows without the current draft or preview.
|
|
418
|
+
const restoreStyle = useCallback((frameId, node, property, state) => {
|
|
419
|
+
const draft = draftsRef.current.entries.find((entry) => entry.frame === frameId &&
|
|
420
|
+
entry.node.path === node.path &&
|
|
421
|
+
entry.property === property &&
|
|
422
|
+
entry.state === state);
|
|
423
|
+
const value = draft?.value ?? savedStyleValue(frameId, node.path, property, state);
|
|
424
|
+
const stateField = state !== 'default' ? { state } : {};
|
|
425
|
+
if (value !== null) {
|
|
426
|
+
send(frameId, { action: 'set-style', anchor: node.anchor, path: node.path, property, value, ...stateField });
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
send(frameId, { action: 'reset-style', anchor: node.anchor, path: node.path, property, ...stateField });
|
|
430
|
+
}
|
|
431
|
+
}, [savedStyleValue, send]);
|
|
432
|
+
const titleOf = useCallback((item) => locale === 'zh-CN' ? item.titleZh ?? item.title ?? '' : item.title ?? '', [locale]);
|
|
433
|
+
// Component pages carry editor chrome above and below the project's board (header,
|
|
434
|
+
// tidy proposal, a real usage frame); its measured height is part of the page node.
|
|
435
|
+
const [chromeExtra, setChromeExtra] = useState({});
|
|
436
|
+
const nodeDefs = useMemo(() => nodeDefinitions(frames, (frame) => frame.title ?? frame.id).map((node) => chromeExtra[node.id] ? { ...node, height: node.height + chromeExtra[node.id] } : node), [chromeExtra, frames]);
|
|
437
|
+
const defaults = useMemo(() => defaultCanvasPositions(frames), [frames]);
|
|
438
|
+
// Extra room a page needs while it shows state previews or alternatives. The page grows
|
|
439
|
+
// by that much and the pages to its right / below shift over, so nothing overlaps.
|
|
440
|
+
const [growth, setGrowth] = useState({});
|
|
441
|
+
const offsetsRef = useRef({});
|
|
442
|
+
const canvasNodes = useMemo(() => {
|
|
443
|
+
const base = nodeDefs.map((node) => ({
|
|
444
|
+
...node,
|
|
445
|
+
...(positions[node.id] ?? defaults[node.id] ?? { x: 0, y: 0 }),
|
|
446
|
+
}));
|
|
447
|
+
const offsets = {};
|
|
448
|
+
const nodes = base.map((node) => {
|
|
449
|
+
let dx = 0;
|
|
450
|
+
let dy = 0;
|
|
451
|
+
for (const other of base) {
|
|
452
|
+
const grow = growth[other.id];
|
|
453
|
+
if (other.id === node.id || !grow)
|
|
454
|
+
continue;
|
|
455
|
+
const overlapsY = other.y < node.y + node.height && node.y < other.y + other.height + grow.h;
|
|
456
|
+
const overlapsX = other.x < node.x + node.width && node.x < other.x + other.width + grow.w;
|
|
457
|
+
if (grow.w && overlapsY && other.x + other.width <= node.x + 1)
|
|
458
|
+
dx += grow.w;
|
|
459
|
+
if (grow.h && overlapsX && other.y + other.height <= node.y + 1)
|
|
460
|
+
dy += grow.h;
|
|
461
|
+
}
|
|
462
|
+
offsets[node.id] = { x: dx, y: dy };
|
|
463
|
+
const grow = growth[node.id];
|
|
464
|
+
return {
|
|
465
|
+
...node,
|
|
466
|
+
x: node.x + dx,
|
|
467
|
+
y: node.y + dy,
|
|
468
|
+
width: node.width + (grow?.w ?? 0),
|
|
469
|
+
height: node.height + (grow?.h ?? 0),
|
|
470
|
+
};
|
|
471
|
+
});
|
|
472
|
+
offsetsRef.current = offsets;
|
|
473
|
+
return nodes;
|
|
474
|
+
}, [nodeDefs, defaults, growth, positions]);
|
|
475
|
+
// When a component page is fitted into view, and which camera moves are the user's
|
|
476
|
+
// (shared/cameraFit.mjs). Camera moves the editor makes itself go through it.
|
|
477
|
+
const pageFitRef = useRef(null);
|
|
478
|
+
if (!pageFitRef.current)
|
|
479
|
+
pageFitRef.current = createPageFit();
|
|
480
|
+
const pageFit = pageFitRef.current;
|
|
481
|
+
const focusNodeAt = useCallback((id, map) => {
|
|
482
|
+
const viewport = canvasRef.current;
|
|
483
|
+
const node = nodeDefs.find((item) => item.id === id);
|
|
484
|
+
const position = map[id] ?? defaults[id];
|
|
485
|
+
if (!viewport || !node || !position)
|
|
486
|
+
return;
|
|
487
|
+
const rect = viewport.getBoundingClientRect();
|
|
488
|
+
if (!rect.width || !rect.height)
|
|
489
|
+
return;
|
|
490
|
+
const compact = isMobileRef.current;
|
|
491
|
+
const padding = compact ? 24 : 96;
|
|
492
|
+
const leftWidth = compact || leftCollapsedRef.current
|
|
493
|
+
? 0
|
|
494
|
+
: Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--ds-side-width')) || 324;
|
|
495
|
+
const rightWidth = compact || rightCollapsedRef.current
|
|
496
|
+
? 0
|
|
497
|
+
: Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue('--ds-right-width')) || 324;
|
|
498
|
+
const availableWidth = Math.max(0, rect.width - (compact ? 0 : leftWidth + rightWidth + 32));
|
|
499
|
+
const zoom = clampZoom(Math.min(1, (availableWidth - padding * 2) / node.width, (rect.height - padding * 2) / node.height));
|
|
500
|
+
pageFit.programmatic(() => camera.set({
|
|
501
|
+
zoom,
|
|
502
|
+
x: (compact ? 0 : leftWidth) + availableWidth / 2 - (position.x + node.width / 2) * zoom,
|
|
503
|
+
y: rect.height / 2 - (position.y + node.height / 2) * zoom,
|
|
504
|
+
}));
|
|
505
|
+
}, [camera, defaults, nodeDefs, pageFit]);
|
|
506
|
+
// Pan/zoom so every listed artboard (e.g. a base and its new alternative) is in view
|
|
507
|
+
// between the side panels.
|
|
508
|
+
const focusBoards = useCallback((keys) => {
|
|
509
|
+
const viewport = canvasRef.current;
|
|
510
|
+
if (!viewport)
|
|
511
|
+
return;
|
|
512
|
+
const view = viewport.getBoundingClientRect();
|
|
513
|
+
const boxes = keys.flatMap((key) => {
|
|
514
|
+
const element = viewport.querySelector(`[data-board-frame="${CSS.escape(key)}"]`);
|
|
515
|
+
const box = element?.getBoundingClientRect();
|
|
516
|
+
return box && box.width ? [box] : [];
|
|
517
|
+
});
|
|
518
|
+
if (!boxes.length || !view.width || !view.height)
|
|
519
|
+
return;
|
|
520
|
+
const current = camera.get();
|
|
521
|
+
const toWorld = (x, y) => ({
|
|
522
|
+
x: (x - view.left - current.x) / current.zoom,
|
|
523
|
+
y: (y - view.top - current.y) / current.zoom,
|
|
524
|
+
});
|
|
525
|
+
const topLeft = toWorld(Math.min(...boxes.map((box) => box.left)), Math.min(...boxes.map((box) => box.top)));
|
|
526
|
+
const bottomRight = toWorld(Math.max(...boxes.map((box) => box.right)), Math.max(...boxes.map((box) => box.bottom)));
|
|
527
|
+
const width = bottomRight.x - topLeft.x;
|
|
528
|
+
const height = bottomRight.y - topLeft.y;
|
|
529
|
+
const compact = isMobileRef.current;
|
|
530
|
+
const padding = compact ? 24 : 72;
|
|
531
|
+
const cssWidth = (name) => Number.parseFloat(getComputedStyle(document.documentElement).getPropertyValue(name)) || 324;
|
|
532
|
+
const leftWidth = compact || leftCollapsedRef.current ? 0 : cssWidth('--ds-side-width');
|
|
533
|
+
const rightWidth = compact || rightCollapsedRef.current ? 0 : cssWidth('--ds-right-width');
|
|
534
|
+
const availableWidth = Math.max(0, view.width - (compact ? 0 : leftWidth + rightWidth + 32));
|
|
535
|
+
const zoom = clampZoom(Math.min(1, (availableWidth - padding * 2) / width, (view.height - padding * 2) / height));
|
|
536
|
+
pageFit.programmatic(() => camera.set({
|
|
537
|
+
zoom,
|
|
538
|
+
x: (compact ? 0 : leftWidth) + availableWidth / 2 - (topLeft.x + width / 2) * zoom,
|
|
539
|
+
y: view.height / 2 - (topLeft.y + height / 2) * zoom,
|
|
540
|
+
}));
|
|
541
|
+
}, [camera, pageFit]);
|
|
542
|
+
// Measure how much each page board outgrew its declared size: the state strip and
|
|
543
|
+
// variant actions under an artboard, and alternatives beside it.
|
|
544
|
+
useEffect(() => {
|
|
545
|
+
const viewport = canvasRef.current;
|
|
546
|
+
if (!viewport || typeof ResizeObserver === 'undefined')
|
|
547
|
+
return;
|
|
548
|
+
let raf = 0;
|
|
549
|
+
const measure = () => {
|
|
550
|
+
raf = 0;
|
|
551
|
+
const next = {};
|
|
552
|
+
const chrome = {};
|
|
553
|
+
for (const page of Array.from(viewport.querySelectorAll('[data-board-page]'))) {
|
|
554
|
+
let w = 0;
|
|
555
|
+
let h = 0;
|
|
556
|
+
for (const group of Array.from(page.querySelectorAll('.board-group'))) {
|
|
557
|
+
const frame = group.querySelector('.board-slot > .board-frame');
|
|
558
|
+
if (frame)
|
|
559
|
+
w = Math.max(w, group.offsetWidth - frame.offsetWidth);
|
|
560
|
+
}
|
|
561
|
+
// Strips under artboards on the same row share that row's extra height; a board that
|
|
562
|
+
// wraps its artboards (component pages draw a strip under every style frame) adds
|
|
563
|
+
// each row's extra.
|
|
564
|
+
const rows = new Map();
|
|
565
|
+
for (const slot of Array.from(page.querySelectorAll('.board-slot'))) {
|
|
566
|
+
const frame = slot.querySelector(':scope > .board-frame');
|
|
567
|
+
if (!frame)
|
|
568
|
+
continue;
|
|
569
|
+
const extra = slot.offsetHeight - frame.offsetHeight;
|
|
570
|
+
if (extra <= 0)
|
|
571
|
+
continue;
|
|
572
|
+
rows.set(slot.offsetTop, Math.max(rows.get(slot.offsetTop) ?? 0, extra));
|
|
573
|
+
}
|
|
574
|
+
for (const extra of rows.values())
|
|
575
|
+
h += extra;
|
|
576
|
+
if (w || h)
|
|
577
|
+
next[page.dataset.boardPage ?? ''] = { w: Math.round(w), h: Math.round(h) };
|
|
578
|
+
let extra = 0;
|
|
579
|
+
for (const part of Array.from(page.querySelectorAll(':scope > .component-page-chrome'))) {
|
|
580
|
+
extra += part.offsetHeight;
|
|
581
|
+
}
|
|
582
|
+
if (extra)
|
|
583
|
+
chrome[page.dataset.boardPage ?? ''] = Math.round(extra);
|
|
584
|
+
}
|
|
585
|
+
setGrowth((current) => (JSON.stringify(current) === JSON.stringify(next) ? current : next));
|
|
586
|
+
// Keep pages that are not mounted right now, so revisiting one fits it at once.
|
|
587
|
+
setChromeExtra((current) => {
|
|
588
|
+
const merged = { ...current, ...chrome };
|
|
589
|
+
return JSON.stringify(current) === JSON.stringify(merged) ? current : merged;
|
|
590
|
+
});
|
|
591
|
+
};
|
|
592
|
+
const schedule = () => {
|
|
593
|
+
if (!raf)
|
|
594
|
+
raf = window.requestAnimationFrame(measure);
|
|
595
|
+
};
|
|
596
|
+
const resize = new ResizeObserver(schedule);
|
|
597
|
+
const observeAll = () => {
|
|
598
|
+
for (const element of Array.from(viewport.querySelectorAll('.board-slot, .board-group, .component-page-chrome'))) {
|
|
599
|
+
resize.observe(element);
|
|
600
|
+
}
|
|
601
|
+
schedule();
|
|
602
|
+
};
|
|
603
|
+
const mutations = new MutationObserver(observeAll);
|
|
604
|
+
mutations.observe(viewport, { childList: true, subtree: true });
|
|
605
|
+
observeAll();
|
|
606
|
+
return () => {
|
|
607
|
+
if (raf)
|
|
608
|
+
window.cancelAnimationFrame(raf);
|
|
609
|
+
resize.disconnect();
|
|
610
|
+
mutations.disconnect();
|
|
611
|
+
};
|
|
612
|
+
}, [designId, nodeDefs]);
|
|
613
|
+
const moveNode = useCallback((id, rawPosition) => {
|
|
614
|
+
// Store the position without the temporary push from a neighbour's growth.
|
|
615
|
+
const offset = offsetsRef.current[id] ?? { x: 0, y: 0 };
|
|
616
|
+
const position = { x: rawPosition.x - offset.x, y: rawPosition.y - offset.y };
|
|
617
|
+
const next = { ...positionsRef.current, [id]: position };
|
|
618
|
+
positionsRef.current = next;
|
|
619
|
+
setPositions(next);
|
|
620
|
+
void saveLayout(designId, next).catch(() => setError(t('error.save')));
|
|
621
|
+
}, [camera, designId, t]);
|
|
622
|
+
useEffect(() => {
|
|
623
|
+
if (!designId)
|
|
624
|
+
return;
|
|
625
|
+
let timer = null;
|
|
626
|
+
const unsubscribe = camera.subscribe(() => {
|
|
627
|
+
if (timer)
|
|
628
|
+
window.clearTimeout(timer);
|
|
629
|
+
timer = window.setTimeout(() => {
|
|
630
|
+
const page = activePageRef.current;
|
|
631
|
+
const current = camera.get();
|
|
632
|
+
if (page)
|
|
633
|
+
pageCamerasRef.current = { ...pageCamerasRef.current, [page]: current };
|
|
634
|
+
void saveCamera(designId, current, page || undefined).catch(() => { });
|
|
635
|
+
}, 200);
|
|
636
|
+
});
|
|
637
|
+
return () => {
|
|
638
|
+
unsubscribe();
|
|
639
|
+
if (timer)
|
|
640
|
+
window.clearTimeout(timer);
|
|
641
|
+
};
|
|
642
|
+
}, [camera, designId]);
|
|
643
|
+
const focusNode = useCallback((id) => focusNodeAt(id, positions), [focusNodeAt, positions]);
|
|
644
|
+
// Opening a page: its saved camera, else fit the page into view.
|
|
645
|
+
const showPage = (id) => {
|
|
646
|
+
const saved = pageCamerasRef.current[id];
|
|
647
|
+
if (saved)
|
|
648
|
+
pageFit.programmatic(() => camera.set(saved));
|
|
649
|
+
else
|
|
650
|
+
focusNode(id);
|
|
651
|
+
};
|
|
652
|
+
const showPageRef = useRef(showPage);
|
|
653
|
+
showPageRef.current = showPage;
|
|
654
|
+
const focusNodeRef = useRef(focusNodeAt);
|
|
655
|
+
focusNodeRef.current = focusNodeAt;
|
|
656
|
+
// A component page is fitted into view once its chrome (header, tidy card, usage frame)
|
|
657
|
+
// has been measured with its own report loaded: the ResizeObserver above updates
|
|
658
|
+
// `chromeExtra`, and every part has explicit sizes, so the measured height is final once
|
|
659
|
+
// the report for this component is in. It refits when that height changes, until the
|
|
660
|
+
// user pans or zooms on the page (pageFit decides; see shared/cameraFit.mjs).
|
|
661
|
+
useEffect(() => camera.subscribe(() => pageFit.cameraChanged()), [camera, pageFit]);
|
|
662
|
+
const chromeHeight = chromeExtra[activePageId] ?? 0;
|
|
663
|
+
const componentPageReady = Boolean(currentComponent && componentReport?.name === currentComponent);
|
|
664
|
+
useEffect(() => {
|
|
665
|
+
if (!pageFit.shouldFit({ page: activePageId, chromeHeight, ready: componentPageReady }))
|
|
666
|
+
return;
|
|
667
|
+
focusNodeRef.current(activePageId, positionsRef.current);
|
|
668
|
+
}, [activePageId, chromeHeight, componentPageReady, pageFit]);
|
|
669
|
+
const persistReviewOps = useCallback((ops, keepalive = true) => {
|
|
670
|
+
if (!ops.length)
|
|
671
|
+
return reviewSaveChain.current;
|
|
672
|
+
reviewSaveInFlight.current += 1;
|
|
673
|
+
reviewSaveChain.current = reviewSaveChain.current
|
|
674
|
+
.catch(() => { })
|
|
675
|
+
.then(() => saveReviewOps(designId, ops, { keepalive }))
|
|
676
|
+
.then((saved) => {
|
|
677
|
+
reviewSaveInFlight.current = Math.max(0, reviewSaveInFlight.current - 1);
|
|
678
|
+
if (deferredReviewSync.current &&
|
|
679
|
+
pendingReviewOps.current.length === 0 &&
|
|
680
|
+
reviewSaveInFlight.current === 0) {
|
|
681
|
+
deferredReviewSync.current = false;
|
|
682
|
+
setReviewItems((previous) => {
|
|
683
|
+
const merged = mergeReviewItems(previous, saved.items);
|
|
684
|
+
reviewRef.current = merged;
|
|
685
|
+
return merged;
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
})
|
|
689
|
+
.catch(() => {
|
|
690
|
+
reviewSaveInFlight.current = Math.max(0, reviewSaveInFlight.current - 1);
|
|
691
|
+
setError(t('error.save'));
|
|
692
|
+
});
|
|
693
|
+
return reviewSaveChain.current;
|
|
694
|
+
}, [designId, t]);
|
|
695
|
+
const flushReviewOps = useCallback(() => {
|
|
696
|
+
if (reviewSaveTimer.current) {
|
|
697
|
+
window.clearTimeout(reviewSaveTimer.current);
|
|
698
|
+
reviewSaveTimer.current = null;
|
|
699
|
+
}
|
|
700
|
+
const ops = pendingReviewOps.current;
|
|
701
|
+
pendingReviewOps.current = [];
|
|
702
|
+
return persistReviewOps(ops);
|
|
703
|
+
}, [persistReviewOps]);
|
|
704
|
+
const queueReviewOps = useCallback((ops) => {
|
|
705
|
+
if (!ops.length)
|
|
706
|
+
return;
|
|
707
|
+
pendingReviewOps.current.push(...ops);
|
|
708
|
+
if (reviewSaveTimer.current)
|
|
709
|
+
window.clearTimeout(reviewSaveTimer.current);
|
|
710
|
+
reviewSaveTimer.current = window.setTimeout(() => {
|
|
711
|
+
reviewSaveTimer.current = null;
|
|
712
|
+
const pending = pendingReviewOps.current;
|
|
713
|
+
pendingReviewOps.current = [];
|
|
714
|
+
persistReviewOps(pending);
|
|
715
|
+
}, 250);
|
|
716
|
+
}, [persistReviewOps]);
|
|
717
|
+
const upsertReviewItem = useCallback((item, ops = []) => {
|
|
718
|
+
const next = { ...item, updatedAt: nowIso() };
|
|
719
|
+
setReviewItems((previous) => {
|
|
720
|
+
const index = previous.findIndex((entry) => entry.id === next.id);
|
|
721
|
+
const items = index === -1
|
|
722
|
+
? [...previous, next]
|
|
723
|
+
: previous.map((entry) => (entry.id === next.id ? next : entry));
|
|
724
|
+
reviewRef.current = items;
|
|
725
|
+
return items;
|
|
726
|
+
});
|
|
727
|
+
queueReviewOps([{ type: 'upsert', item: next }, ...ops]);
|
|
728
|
+
return next;
|
|
729
|
+
}, [queueReviewOps]);
|
|
730
|
+
const removeReviewItems = useCallback((ids) => {
|
|
731
|
+
if (!ids.length)
|
|
732
|
+
return;
|
|
733
|
+
const set = new Set(ids);
|
|
734
|
+
setReviewItems((previous) => {
|
|
735
|
+
const items = previous.filter((item) => !set.has(item.id));
|
|
736
|
+
reviewRef.current = items;
|
|
737
|
+
return items;
|
|
738
|
+
});
|
|
739
|
+
queueReviewOps(ids.map((id) => ({ type: 'remove', id })));
|
|
740
|
+
}, [queueReviewOps]);
|
|
741
|
+
// Same zoom / pan as the empty canvas, at the pointer's place in the canvas viewport. Any frame
|
|
742
|
+
// on the canvas may forward wheels (page frames; state thumbnails take
|
|
743
|
+
// no pointer events today, the fallback below covers them if that changes).
|
|
744
|
+
const forwardFrameWheel = useCallback((iframe, data) => {
|
|
745
|
+
const viewport = canvasRef.current;
|
|
746
|
+
if (!iframe || !viewport || !viewport.contains(iframe))
|
|
747
|
+
return;
|
|
748
|
+
const point = framePointToViewport(data, iframe.getBoundingClientRect(), iframe.offsetWidth, viewport.getBoundingClientRect());
|
|
749
|
+
applyCanvasWheel(camera, { route: data.route, ...point, ...wheelPixels(data) });
|
|
750
|
+
}, [camera]);
|
|
751
|
+
const handlePreview = useCallback((frameId, data) => {
|
|
752
|
+
switch (data.type) {
|
|
753
|
+
case 'design:wheel': {
|
|
754
|
+
forwardFrameWheel(iframes.current[frameId], data);
|
|
755
|
+
return;
|
|
756
|
+
}
|
|
757
|
+
case 'design:hello': {
|
|
758
|
+
setFrameStates((previous) => ({
|
|
759
|
+
...previous,
|
|
760
|
+
[frameId]: {
|
|
761
|
+
...(previous[frameId] ?? createFrameState()),
|
|
762
|
+
ready: false,
|
|
763
|
+
selected: null,
|
|
764
|
+
hover: null,
|
|
765
|
+
},
|
|
766
|
+
}));
|
|
767
|
+
setActiveFrameId((current) => current || frameId);
|
|
768
|
+
// Saved changes and drafts survive reloads, including in play mode.
|
|
769
|
+
applyFramePendingChanges(frameId, reviewRef.current);
|
|
770
|
+
applyFrameDrafts(frameId);
|
|
771
|
+
if (!playRef.current.has(frameId)) {
|
|
772
|
+
window.setTimeout(() => send(frameId, { action: 'enable' }), 0);
|
|
773
|
+
}
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
case 'design:ready': {
|
|
777
|
+
setFrameStates((previous) => ({
|
|
778
|
+
...previous,
|
|
779
|
+
[frameId]: {
|
|
780
|
+
...(previous[frameId] ?? createFrameState()),
|
|
781
|
+
ready: true,
|
|
782
|
+
tokens: data.tokens,
|
|
783
|
+
baseline: data.baseline ?? data.tokens,
|
|
784
|
+
},
|
|
785
|
+
}));
|
|
786
|
+
for (const item of reviewRef.current) {
|
|
787
|
+
if (item.kind !== 'token' ||
|
|
788
|
+
item.target.type !== 'token' ||
|
|
789
|
+
item.to === undefined ||
|
|
790
|
+
item.verifiedAt ||
|
|
791
|
+
item.status === 'archived' ||
|
|
792
|
+
item.proposalDecision === 'rejected') {
|
|
793
|
+
continue;
|
|
794
|
+
}
|
|
795
|
+
send(frameId, {
|
|
796
|
+
action: 'set-token',
|
|
797
|
+
name: item.target.token,
|
|
798
|
+
value: String(item.to),
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
applyFramePendingChanges(frameId, reviewRef.current);
|
|
802
|
+
applyFrameDrafts(frameId);
|
|
803
|
+
if (pendingComponentPickRef.current?.frame === frameId) {
|
|
804
|
+
const { component, aliases } = pendingComponentPickRef.current;
|
|
805
|
+
send(frameId, { action: 'select-component', component, aliases });
|
|
806
|
+
}
|
|
807
|
+
return;
|
|
808
|
+
}
|
|
809
|
+
case 'design:tree': {
|
|
810
|
+
setFrameStates((previous) => {
|
|
811
|
+
const current = previous[frameId] ?? createFrameState();
|
|
812
|
+
const ids = new Set(data.nodes.map((node) => node.id));
|
|
813
|
+
return {
|
|
814
|
+
...previous,
|
|
815
|
+
[frameId]: {
|
|
816
|
+
...current,
|
|
817
|
+
tree: data.nodes,
|
|
818
|
+
truncated: data.truncated,
|
|
819
|
+
selected: current.selected && ids.has(current.selected.id) ? current.selected : null,
|
|
820
|
+
},
|
|
821
|
+
};
|
|
822
|
+
});
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
case 'design:select': {
|
|
826
|
+
const primaryFrame = activeFrameRef.current;
|
|
827
|
+
const primary = frameStatesRef.current[primaryFrame]?.selected ?? null;
|
|
828
|
+
if (data.additive && data.node && primary) {
|
|
829
|
+
const node = data.node;
|
|
830
|
+
if (frameId === primaryFrame && node.path === primary.path)
|
|
831
|
+
return;
|
|
832
|
+
setExtraSelection((current) => {
|
|
833
|
+
const exists = current.some((item) => item.frame === frameId && item.node.path === node.path);
|
|
834
|
+
const next = exists
|
|
835
|
+
? current.filter((item) => !(item.frame === frameId && item.node.path === node.path))
|
|
836
|
+
: [...current, { frame: frameId, node }];
|
|
837
|
+
extraRef.current = next;
|
|
838
|
+
return next;
|
|
839
|
+
});
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
const refresh = Boolean(data.refresh && data.node);
|
|
843
|
+
if (refresh && data.node) {
|
|
844
|
+
// A hover preview restyles the canvas only; the fields keep the real value.
|
|
845
|
+
if (previewRef.current)
|
|
846
|
+
return;
|
|
847
|
+
const node = data.node;
|
|
848
|
+
setExtraSelection((current) => current.some((item) => item.frame === frameId && item.node.path === node.path)
|
|
849
|
+
? current.map((item) => item.frame === frameId && item.node.path === node.path ? { frame: frameId, node } : item)
|
|
850
|
+
: current);
|
|
851
|
+
if (frameId !== primaryFrame) {
|
|
852
|
+
// A restyle in another artboard refreshes its node without moving focus.
|
|
853
|
+
setFrameStates((states) => ({
|
|
854
|
+
...states,
|
|
855
|
+
[frameId]: { ...(states[frameId] ?? createFrameState()), selected: node },
|
|
856
|
+
}));
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
else {
|
|
861
|
+
if (extraRef.current.length) {
|
|
862
|
+
extraRef.current = [];
|
|
863
|
+
setExtraSelection([]);
|
|
864
|
+
}
|
|
865
|
+
if (editStateRef.current !== 'default') {
|
|
866
|
+
send(primaryFrame, { action: 'force-state', state: null });
|
|
867
|
+
editStateRef.current = 'default';
|
|
868
|
+
setEditState('default');
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
setFrameStates((previous) => ({
|
|
872
|
+
...previous,
|
|
873
|
+
[frameId]: { ...(previous[frameId] ?? createFrameState()), selected: data.node },
|
|
874
|
+
}));
|
|
875
|
+
const pick = refresh ? null : pendingComponentPickRef.current;
|
|
876
|
+
if (pick) {
|
|
877
|
+
pendingComponentPickRef.current = null;
|
|
878
|
+
if (pick.frame === frameId && data.node) {
|
|
879
|
+
const node = data.node;
|
|
880
|
+
setComponentTargets((current) => ({ ...current, [frameId]: node.path }));
|
|
881
|
+
if (pick.state !== 'default') {
|
|
882
|
+
editStateRef.current = pick.state;
|
|
883
|
+
setEditState(pick.state);
|
|
884
|
+
send(frameId, {
|
|
885
|
+
action: 'force-state',
|
|
886
|
+
id: node.id,
|
|
887
|
+
anchor: node.ownAnchor ?? node.anchor,
|
|
888
|
+
path: node.path,
|
|
889
|
+
state: pick.state,
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
if (data.node && !refresh) {
|
|
895
|
+
const nextPageId = pageIdOfFrameKey(frameId);
|
|
896
|
+
const nextStateFrameId = frameIdOfFrameKey(frameId);
|
|
897
|
+
setActiveFrameId(frameId);
|
|
898
|
+
setActivePageId(nextPageId);
|
|
899
|
+
if (commentModeRef.current) {
|
|
900
|
+
setCommentTarget(data.node);
|
|
901
|
+
setCommentDraft('');
|
|
902
|
+
setActiveCommentId(null);
|
|
903
|
+
setRightTab('comments');
|
|
904
|
+
}
|
|
905
|
+
else {
|
|
906
|
+
setCommentTarget(null);
|
|
907
|
+
setRightTab('inspect');
|
|
908
|
+
}
|
|
909
|
+
if (isMobileRef.current)
|
|
910
|
+
setMobilePanel('right');
|
|
911
|
+
replaceCanvasUrl(designId, nextPageId, nextStateFrameId);
|
|
912
|
+
}
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
case 'design:node': {
|
|
916
|
+
const node = data.node;
|
|
917
|
+
setExtraSelection((current) => current.some((item) => item.frame === frameId && item.node.path === node.path)
|
|
918
|
+
? current.map((item) => item.frame === frameId && item.node.path === node.path ? { frame: frameId, node } : item)
|
|
919
|
+
: current);
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
case 'design:hover': {
|
|
923
|
+
setFrameStates((previous) => ({
|
|
924
|
+
...previous,
|
|
925
|
+
[frameId]: {
|
|
926
|
+
...(previous[frameId] ?? createFrameState()),
|
|
927
|
+
hover: { id: data.id, rect: data.rect },
|
|
928
|
+
},
|
|
929
|
+
}));
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
case 'design:free': {
|
|
933
|
+
const node = data.node;
|
|
934
|
+
const ref = toNodeRef(node);
|
|
935
|
+
const key = ref.anchor ?? String(ref.id);
|
|
936
|
+
const to = node.freeRect ?? data.rect;
|
|
937
|
+
const existing = reviewRef.current.find((item) => item.kind === 'free' &&
|
|
938
|
+
item.frame === frameId &&
|
|
939
|
+
item.target.type === 'node' &&
|
|
940
|
+
(item.target.node.anchor ?? String(item.target.node.id)) === key);
|
|
941
|
+
const from = existing?.from ?? data.from ?? to;
|
|
942
|
+
const timestamp = nowIso();
|
|
943
|
+
upsertReviewItem({
|
|
944
|
+
id: existing?.id ?? `free-${frameId}-${key}`,
|
|
945
|
+
design: designId,
|
|
946
|
+
kind: 'free',
|
|
947
|
+
scope: 'frame',
|
|
948
|
+
page: pageIdOfFrameKey(frameId),
|
|
949
|
+
frame: frameId,
|
|
950
|
+
target: { type: 'node', node: ref },
|
|
951
|
+
from,
|
|
952
|
+
to,
|
|
953
|
+
status: 'open',
|
|
954
|
+
createdAt: existing?.createdAt ?? timestamp,
|
|
955
|
+
updatedAt: timestamp,
|
|
956
|
+
});
|
|
957
|
+
setFrameStates((previous) => ({
|
|
958
|
+
...previous,
|
|
959
|
+
[frameId]: {
|
|
960
|
+
...(previous[frameId] ?? createFrameState()),
|
|
961
|
+
selected: node,
|
|
962
|
+
},
|
|
963
|
+
}));
|
|
964
|
+
const freePageId = pageIdOfFrameKey(frameId);
|
|
965
|
+
const freeFrameId = frameIdOfFrameKey(frameId);
|
|
966
|
+
setActiveFrameId(frameId);
|
|
967
|
+
setActivePageId(freePageId);
|
|
968
|
+
setRightTab('inspect');
|
|
969
|
+
if (isMobileRef.current)
|
|
970
|
+
setMobilePanel('right');
|
|
971
|
+
replaceCanvasUrl(designId, freePageId, freeFrameId);
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}, [applyFrameDrafts, applyFramePendingChanges, camera, designId, forwardFrameWheel, send, upsertReviewItem]);
|
|
976
|
+
useEffect(() => {
|
|
977
|
+
const onMessage = (event) => {
|
|
978
|
+
const data = event.data;
|
|
979
|
+
if (!data || typeof data.type !== 'string' || !data.type.startsWith('design:'))
|
|
980
|
+
return;
|
|
981
|
+
const frameId = Object.keys(iframes.current).find((id) => iframes.current[id]?.contentWindow === event.source);
|
|
982
|
+
if (frameId) {
|
|
983
|
+
handlePreview(frameId, data);
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
// Frames the editor does not drive (state thumbnails) only wheel.
|
|
987
|
+
if (data.type !== 'design:wheel' || !event.source)
|
|
988
|
+
return;
|
|
989
|
+
const iframe = Array.from(canvasRef.current?.querySelectorAll('iframe') ?? []).find((element) => element.contentWindow === event.source);
|
|
990
|
+
forwardFrameWheel(iframe, data);
|
|
991
|
+
};
|
|
992
|
+
window.addEventListener('message', onMessage);
|
|
993
|
+
return () => window.removeEventListener('message', onMessage);
|
|
994
|
+
}, [forwardFrameWheel, handlePreview]);
|
|
995
|
+
useEffect(() => {
|
|
996
|
+
const onPopState = () => {
|
|
997
|
+
const params = new URLSearchParams(window.location.search);
|
|
998
|
+
const nextId = params.get('design') ?? '';
|
|
999
|
+
const nextDesign = nextId ? DESIGNS[nextId] : undefined;
|
|
1000
|
+
setDesignId(nextDesign ? nextId : '');
|
|
1001
|
+
if (!nextDesign)
|
|
1002
|
+
return;
|
|
1003
|
+
const nextPages = designPages(nextDesign);
|
|
1004
|
+
const requestedPage = params.get('page');
|
|
1005
|
+
const requestedFrame = params.get('frame');
|
|
1006
|
+
const resource = isResourcePage(requestedPage) ? requestedPage : null;
|
|
1007
|
+
const page = nextPages.find((item) => item.id === requestedPage) ?? nextPages[0];
|
|
1008
|
+
const frame = page?.frames.find((item) => item.id === requestedFrame) ?? page?.frames[0];
|
|
1009
|
+
if (!resource && (!page || !frame))
|
|
1010
|
+
return;
|
|
1011
|
+
setActivePageId(resource ?? page.id);
|
|
1012
|
+
setActiveToken(params.get('token'));
|
|
1013
|
+
setActivePlan(params.get('plan'));
|
|
1014
|
+
setActiveChange(params.get('item'));
|
|
1015
|
+
setActiveFrameId(resource
|
|
1016
|
+
? nextPages[0]?.frames[0]
|
|
1017
|
+
? frameKeyOf(nextPages[0].id, nextPages[0].frames[0].id)
|
|
1018
|
+
: ''
|
|
1019
|
+
: frameKeyOf(page.id, frame.id));
|
|
1020
|
+
setCommentMode(false);
|
|
1021
|
+
commentRestorePlayRef.current = false;
|
|
1022
|
+
setCommentTarget(null);
|
|
1023
|
+
setCommentDraft('');
|
|
1024
|
+
setActiveCommentId(null);
|
|
1025
|
+
setNavTab(resource
|
|
1026
|
+
? navTabOfResource(resource)
|
|
1027
|
+
: page && componentPageIds.has(page.id)
|
|
1028
|
+
? 'components'
|
|
1029
|
+
: 'pages');
|
|
1030
|
+
setRightTab('inspect');
|
|
1031
|
+
if (!resource)
|
|
1032
|
+
requestAnimationFrame(() => showPageRef.current(page.id));
|
|
1033
|
+
};
|
|
1034
|
+
window.addEventListener('popstate', onPopState);
|
|
1035
|
+
return () => window.removeEventListener('popstate', onPopState);
|
|
1036
|
+
}, [focusNode]);
|
|
1037
|
+
useEffect(() => {
|
|
1038
|
+
if (!design)
|
|
1039
|
+
return;
|
|
1040
|
+
const nextStates = {};
|
|
1041
|
+
for (const entry of frameDefs)
|
|
1042
|
+
nextStates[entry.key] = createFrameState();
|
|
1043
|
+
setFrameStates(nextStates);
|
|
1044
|
+
setReviewItems([]);
|
|
1045
|
+
reviewRef.current = [];
|
|
1046
|
+
draftsOwner.current = designId;
|
|
1047
|
+
const storedDrafts = loadDrafts(designId);
|
|
1048
|
+
draftsRef.current = storedDrafts;
|
|
1049
|
+
setDrafts(storedDrafts);
|
|
1050
|
+
extraRef.current = [];
|
|
1051
|
+
setExtraSelection([]);
|
|
1052
|
+
editStateRef.current = 'default';
|
|
1053
|
+
setEditState('default');
|
|
1054
|
+
const params = new URLSearchParams(window.location.search);
|
|
1055
|
+
const requestedPage = params.get('page');
|
|
1056
|
+
const requestedFrame = params.get('frame');
|
|
1057
|
+
const resource = isResourcePage(requestedPage) ? requestedPage : null;
|
|
1058
|
+
const mobilePage = pages.find((page) => page.frames.some((frame) => frame.size[0] <= 500));
|
|
1059
|
+
const page = pages.find((item) => item.id === requestedPage) ??
|
|
1060
|
+
(isMobileRef.current ? mobilePage : undefined) ??
|
|
1061
|
+
pages[0];
|
|
1062
|
+
const frame = page?.frames.find((item) => item.id === requestedFrame) ??
|
|
1063
|
+
(isMobileRef.current
|
|
1064
|
+
? page?.frames.find((item) => item.size[0] <= 500)
|
|
1065
|
+
: undefined) ??
|
|
1066
|
+
page?.frames[0];
|
|
1067
|
+
const hidden = pages[0]?.frames[0];
|
|
1068
|
+
const hiddenKey = hidden ? frameKeyOf(pages[0].id, hidden.id) : '';
|
|
1069
|
+
const nextPageId = resource ?? page?.id ?? '';
|
|
1070
|
+
const nextFrameKey = resource || !page || !frame ? hiddenKey : frameKeyOf(page.id, frame.id);
|
|
1071
|
+
setActivePageId(nextPageId);
|
|
1072
|
+
setActiveFrameId(nextFrameKey);
|
|
1073
|
+
setActiveToken(params.get('token'));
|
|
1074
|
+
setActivePlan(params.get('plan'));
|
|
1075
|
+
setActiveChange(params.get('item'));
|
|
1076
|
+
setNavTab(resource
|
|
1077
|
+
? navTabOfResource(resource)
|
|
1078
|
+
: page && componentPageIds.has(page.id)
|
|
1079
|
+
? 'components'
|
|
1080
|
+
: 'pages');
|
|
1081
|
+
setNavQuery('');
|
|
1082
|
+
setRightTab('inspect');
|
|
1083
|
+
const nextPlay = new Set();
|
|
1084
|
+
setPlay(nextPlay);
|
|
1085
|
+
playRef.current = nextPlay;
|
|
1086
|
+
setCommentMode(false);
|
|
1087
|
+
commentRestorePlayRef.current = false;
|
|
1088
|
+
setCommentTarget(null);
|
|
1089
|
+
setCommentDraft('');
|
|
1090
|
+
setActiveCommentId(null);
|
|
1091
|
+
setMobilePanel(null);
|
|
1092
|
+
setError(null);
|
|
1093
|
+
const nextDefaults = defaultCanvasPositions(pages);
|
|
1094
|
+
positionsRef.current = nextDefaults;
|
|
1095
|
+
setPositions(nextDefaults);
|
|
1096
|
+
let cancelled = false;
|
|
1097
|
+
const focusTarget = nextPageId;
|
|
1098
|
+
let focusFrame = requestAnimationFrame(() => focusNodeRef.current(focusTarget, nextDefaults));
|
|
1099
|
+
const applyLayout = (map, layoutCamera) => {
|
|
1100
|
+
if (cancelled)
|
|
1101
|
+
return;
|
|
1102
|
+
positionsRef.current = map;
|
|
1103
|
+
setPositions(map);
|
|
1104
|
+
cancelAnimationFrame(focusFrame);
|
|
1105
|
+
if (layoutCamera) {
|
|
1106
|
+
pageFit.programmatic(() => camera.set(layoutCamera));
|
|
1107
|
+
return;
|
|
1108
|
+
}
|
|
1109
|
+
focusFrame = requestAnimationFrame(() => focusNodeRef.current(focusTarget, map));
|
|
1110
|
+
};
|
|
1111
|
+
pageCamerasRef.current = {};
|
|
1112
|
+
void loadLayout(designId)
|
|
1113
|
+
.then((layout) => {
|
|
1114
|
+
pageCamerasRef.current = layout?.cameras ?? {};
|
|
1115
|
+
// Only this page's camera; a 0.4.3 cache (one camera, no page cameras) still applies.
|
|
1116
|
+
const pageCamera = layout?.cameras ? layout.cameras[focusTarget] : layout?.camera;
|
|
1117
|
+
applyLayout(mergeCanvasPositions(nextDefaults, layout?.positions), pageCamera);
|
|
1118
|
+
})
|
|
1119
|
+
.catch(() => applyLayout(nextDefaults));
|
|
1120
|
+
void loadReview(designId)
|
|
1121
|
+
.then((review) => {
|
|
1122
|
+
if (cancelled)
|
|
1123
|
+
return;
|
|
1124
|
+
setReviewItems(review.items);
|
|
1125
|
+
reviewRef.current = review.items;
|
|
1126
|
+
const tokenValues = Object.fromEntries(review.items.flatMap((item) => item.kind === 'token' &&
|
|
1127
|
+
item.target.type === 'token' &&
|
|
1128
|
+
item.to !== undefined &&
|
|
1129
|
+
!item.verifiedAt &&
|
|
1130
|
+
item.status !== 'archived' &&
|
|
1131
|
+
item.proposalDecision !== 'rejected'
|
|
1132
|
+
? [[item.target.token, String(item.to)]]
|
|
1133
|
+
: []));
|
|
1134
|
+
setFrameStates((previous) => {
|
|
1135
|
+
const next = { ...previous };
|
|
1136
|
+
for (const entry of frameDefs) {
|
|
1137
|
+
const state = next[entry.key] ?? createFrameState();
|
|
1138
|
+
let tokens = state.tokens;
|
|
1139
|
+
for (const [name, value] of Object.entries(tokenValues)) {
|
|
1140
|
+
tokens = tokens.filter((item) => item.name !== name);
|
|
1141
|
+
tokens = [...tokens, { name, value }];
|
|
1142
|
+
}
|
|
1143
|
+
next[entry.key] = { ...state, tokens };
|
|
1144
|
+
}
|
|
1145
|
+
return next;
|
|
1146
|
+
});
|
|
1147
|
+
for (const entry of frameDefs) {
|
|
1148
|
+
for (const [name, value] of Object.entries(tokenValues)) {
|
|
1149
|
+
send(entry.key, { action: 'set-token', name, value });
|
|
1150
|
+
}
|
|
1151
|
+
applyFramePendingChanges(entry.key, review.items);
|
|
1152
|
+
}
|
|
1153
|
+
})
|
|
1154
|
+
.catch(() => setError(t('error.load')));
|
|
1155
|
+
const nextParams = new URLSearchParams();
|
|
1156
|
+
nextParams.set('design', designId);
|
|
1157
|
+
if (nextPageId)
|
|
1158
|
+
nextParams.set('page', nextPageId);
|
|
1159
|
+
// `?locale=` is read by the i18n provider (links, screenshots); keep it.
|
|
1160
|
+
const localeParam = params.get('locale');
|
|
1161
|
+
if (localeParam)
|
|
1162
|
+
nextParams.set('locale', localeParam);
|
|
1163
|
+
if (resource) {
|
|
1164
|
+
for (const key of ['token', 'plan', 'item']) {
|
|
1165
|
+
const value = params.get(key);
|
|
1166
|
+
if (value)
|
|
1167
|
+
nextParams.set(key, value);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
else if (page && frame) {
|
|
1171
|
+
nextParams.set('frame', frame.id);
|
|
1172
|
+
}
|
|
1173
|
+
window.history.replaceState(null, '', `?${nextParams.toString()}`);
|
|
1174
|
+
return () => {
|
|
1175
|
+
cancelled = true;
|
|
1176
|
+
cancelAnimationFrame(focusFrame);
|
|
1177
|
+
flushReviewOps();
|
|
1178
|
+
};
|
|
1179
|
+
}, [applyFramePendingChanges, design, designId, flushReviewOps, frameDefs, pages, send, t]);
|
|
1180
|
+
// Pick up agent-side status/reply edits and proposals in real time via SSE,
|
|
1181
|
+
// with low-frequency polling fallback if EventSource is unavailable or drops.
|
|
1182
|
+
useEffect(() => {
|
|
1183
|
+
if (!design)
|
|
1184
|
+
return;
|
|
1185
|
+
let cancelled = false;
|
|
1186
|
+
let fallbackTimer = null;
|
|
1187
|
+
const mergeRemote = (remote) => {
|
|
1188
|
+
if (cancelled)
|
|
1189
|
+
return;
|
|
1190
|
+
if (pendingReviewOps.current.length > 0 || reviewSaveInFlight.current > 0) {
|
|
1191
|
+
deferredReviewSync.current = true;
|
|
1192
|
+
return;
|
|
1193
|
+
}
|
|
1194
|
+
setReviewItems((previous) => {
|
|
1195
|
+
const merged = mergeReviewItems(previous, remote.items);
|
|
1196
|
+
reviewRef.current = merged;
|
|
1197
|
+
return merged;
|
|
1198
|
+
});
|
|
1199
|
+
};
|
|
1200
|
+
const stopFallback = () => {
|
|
1201
|
+
if (fallbackTimer !== null) {
|
|
1202
|
+
window.clearInterval(fallbackTimer);
|
|
1203
|
+
fallbackTimer = null;
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
const startFallback = () => {
|
|
1207
|
+
if (cancelled || fallbackTimer !== null)
|
|
1208
|
+
return;
|
|
1209
|
+
fallbackTimer = window.setInterval(() => {
|
|
1210
|
+
void loadReview(designId)
|
|
1211
|
+
.then((remote) => {
|
|
1212
|
+
if (!cancelled)
|
|
1213
|
+
mergeRemote(remote);
|
|
1214
|
+
})
|
|
1215
|
+
.catch(() => { });
|
|
1216
|
+
}, 15_000);
|
|
1217
|
+
};
|
|
1218
|
+
const unsubscribe = subscribeReview(designId, (remote) => {
|
|
1219
|
+
stopFallback();
|
|
1220
|
+
mergeRemote(remote);
|
|
1221
|
+
}, {
|
|
1222
|
+
onOpen: stopFallback,
|
|
1223
|
+
onError: startFallback,
|
|
1224
|
+
onComponents: () => {
|
|
1225
|
+
if (!cancelled)
|
|
1226
|
+
setComponentRefresh((value) => value + 1);
|
|
1227
|
+
},
|
|
1228
|
+
});
|
|
1229
|
+
return () => {
|
|
1230
|
+
cancelled = true;
|
|
1231
|
+
stopFallback();
|
|
1232
|
+
unsubscribe();
|
|
1233
|
+
};
|
|
1234
|
+
}, [design, designId]);
|
|
1235
|
+
// Component pages read the headless report (/__seji/api/components, same as
|
|
1236
|
+
// `seji component list|show`). Refetch when component items change.
|
|
1237
|
+
const componentItemsKey = reviewItems
|
|
1238
|
+
.filter((item) => item.kind === 'component')
|
|
1239
|
+
.map((item) => `${item.id}:${item.status}:${item.proposalDecision ?? ''}:${item.updatedAt}`)
|
|
1240
|
+
.join('|');
|
|
1241
|
+
useEffect(() => {
|
|
1242
|
+
if (!designId)
|
|
1243
|
+
return;
|
|
1244
|
+
let cancelled = false;
|
|
1245
|
+
loadComponents()
|
|
1246
|
+
.then((list) => {
|
|
1247
|
+
if (!cancelled)
|
|
1248
|
+
setComponentList(list);
|
|
1249
|
+
})
|
|
1250
|
+
.catch(() => {
|
|
1251
|
+
if (!cancelled)
|
|
1252
|
+
setComponentList(null);
|
|
1253
|
+
});
|
|
1254
|
+
return () => {
|
|
1255
|
+
cancelled = true;
|
|
1256
|
+
};
|
|
1257
|
+
}, [componentItemsKey, componentRefresh, designId]);
|
|
1258
|
+
useEffect(() => {
|
|
1259
|
+
if (!currentComponent) {
|
|
1260
|
+
setComponentReport(null);
|
|
1261
|
+
setComponentError(null);
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
let cancelled = false;
|
|
1265
|
+
setComponentLoading(true);
|
|
1266
|
+
setComponentError(null);
|
|
1267
|
+
loadComponent(currentComponent)
|
|
1268
|
+
.then((report) => {
|
|
1269
|
+
if (!cancelled)
|
|
1270
|
+
setComponentReport(report);
|
|
1271
|
+
})
|
|
1272
|
+
.catch((reason) => {
|
|
1273
|
+
if (cancelled)
|
|
1274
|
+
return;
|
|
1275
|
+
setComponentReport(null);
|
|
1276
|
+
setComponentError(reason instanceof Error ? reason.message : String(reason));
|
|
1277
|
+
})
|
|
1278
|
+
.finally(() => {
|
|
1279
|
+
if (!cancelled)
|
|
1280
|
+
setComponentLoading(false);
|
|
1281
|
+
});
|
|
1282
|
+
return () => {
|
|
1283
|
+
cancelled = true;
|
|
1284
|
+
};
|
|
1285
|
+
}, [componentItemsKey, componentRefresh, currentComponent]);
|
|
1286
|
+
const runComponentAction = useCallback(async (input) => {
|
|
1287
|
+
const result = await postComponentAction({ ...input, design: designId });
|
|
1288
|
+
const item = result.item;
|
|
1289
|
+
if (item && item.design === designId) {
|
|
1290
|
+
setReviewItems((previous) => {
|
|
1291
|
+
const merged = [...previous.filter((entry) => entry.id !== item.id), item];
|
|
1292
|
+
reviewRef.current = merged;
|
|
1293
|
+
return merged;
|
|
1294
|
+
});
|
|
1295
|
+
}
|
|
1296
|
+
setComponentRefresh((value) => value + 1);
|
|
1297
|
+
return result;
|
|
1298
|
+
}, [designId]);
|
|
1299
|
+
const refetchComponents = useCallback(() => setComponentRefresh((value) => value + 1), []);
|
|
1300
|
+
// Undo a tool-executed rename / merge / replace (same as `seji component revert`).
|
|
1301
|
+
const revertComponentItem = useCallback(async (item) => {
|
|
1302
|
+
if (!item.componentOp)
|
|
1303
|
+
return;
|
|
1304
|
+
await revertComponentBatch(item.componentOp.batchId, item.design);
|
|
1305
|
+
setComponentRefresh((value) => value + 1);
|
|
1306
|
+
}, []);
|
|
1307
|
+
// Component tidy proposals are decided on the server (same as `seji proposal`),
|
|
1308
|
+
// which owns the ledger the proposal lives in; the report refetches afterwards.
|
|
1309
|
+
const decideComponentProposal = useCallback(async (item, decision, note = '') => {
|
|
1310
|
+
const { item: updated } = await decideProposal({ design: item.design, id: item.id, decision, note });
|
|
1311
|
+
if (updated.design === designId) {
|
|
1312
|
+
setReviewItems((previous) => {
|
|
1313
|
+
const merged = previous.map((entry) => (entry.id === updated.id ? updated : entry));
|
|
1314
|
+
reviewRef.current = merged;
|
|
1315
|
+
return merged;
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1318
|
+
setComponentRefresh((value) => value + 1);
|
|
1319
|
+
}, [designId]);
|
|
1320
|
+
const archiveBusy = useRef(false);
|
|
1321
|
+
const archiveTick = useCallback(() => {
|
|
1322
|
+
if (archiveBusy.current)
|
|
1323
|
+
return;
|
|
1324
|
+
archiveBusy.current = true;
|
|
1325
|
+
try {
|
|
1326
|
+
const due = dueForArchive(reviewRef.current);
|
|
1327
|
+
if (!due.length)
|
|
1328
|
+
return;
|
|
1329
|
+
const ids = due.map((item) => item.id);
|
|
1330
|
+
const archivedAt = nowIso();
|
|
1331
|
+
setReviewItems((previous) => {
|
|
1332
|
+
const set = new Set(ids);
|
|
1333
|
+
const items = previous.map((item) => set.has(item.id)
|
|
1334
|
+
? { ...item, status: 'archived', archivedAt, updatedAt: archivedAt }
|
|
1335
|
+
: item);
|
|
1336
|
+
reviewRef.current = items;
|
|
1337
|
+
return items;
|
|
1338
|
+
});
|
|
1339
|
+
queueReviewOps([{ type: 'archive', ids, archivedAt }]);
|
|
1340
|
+
}
|
|
1341
|
+
finally {
|
|
1342
|
+
archiveBusy.current = false;
|
|
1343
|
+
}
|
|
1344
|
+
}, [queueReviewOps]);
|
|
1345
|
+
useEffect(() => {
|
|
1346
|
+
if (!design)
|
|
1347
|
+
return;
|
|
1348
|
+
const timer = window.setInterval(() => archiveTick(), 30000);
|
|
1349
|
+
return () => window.clearInterval(timer);
|
|
1350
|
+
}, [archiveTick, design]);
|
|
1351
|
+
useEffect(() => {
|
|
1352
|
+
setMobilePanel(null);
|
|
1353
|
+
requestAnimationFrame(() => focusNodeRef.current(activePageId, positions));
|
|
1354
|
+
}, [isMobile]);
|
|
1355
|
+
useEffect(() => {
|
|
1356
|
+
const flush = () => flushReviewOps();
|
|
1357
|
+
const onVisibility = () => {
|
|
1358
|
+
if (document.visibilityState === 'hidden')
|
|
1359
|
+
flush();
|
|
1360
|
+
};
|
|
1361
|
+
window.addEventListener('pagehide', flush);
|
|
1362
|
+
document.addEventListener('visibilitychange', onVisibility);
|
|
1363
|
+
return () => {
|
|
1364
|
+
window.removeEventListener('pagehide', flush);
|
|
1365
|
+
document.removeEventListener('visibilitychange', onVisibility);
|
|
1366
|
+
};
|
|
1367
|
+
}, [flushReviewOps]);
|
|
1368
|
+
const activeState = frameStates[activeFrameId] ?? createFrameState();
|
|
1369
|
+
const selected = activeState.selected;
|
|
1370
|
+
const allTokens = useMemo(() => tokenGroups.flatMap((group) => group.tokens), [live]);
|
|
1371
|
+
const hardcodedByFile = useMemo(() => {
|
|
1372
|
+
const map = new Map();
|
|
1373
|
+
for (const entry of tokenHealth?.hardcoded ?? []) {
|
|
1374
|
+
map.set(normalizeFilePath(entry.file), {
|
|
1375
|
+
count: entry.count,
|
|
1376
|
+
values: entry.values ?? [],
|
|
1377
|
+
});
|
|
1378
|
+
}
|
|
1379
|
+
return map;
|
|
1380
|
+
}, [live]);
|
|
1381
|
+
const tokenUsesByFile = useMemo(() => {
|
|
1382
|
+
const map = new Map();
|
|
1383
|
+
for (const token of allTokens) {
|
|
1384
|
+
for (const file of token.usedIn ?? []) {
|
|
1385
|
+
const key = normalizeFilePath(file);
|
|
1386
|
+
map.set(key, (map.get(key) ?? 0) + 1);
|
|
1387
|
+
}
|
|
1388
|
+
}
|
|
1389
|
+
return map;
|
|
1390
|
+
}, [allTokens]);
|
|
1391
|
+
const tokenValues = useMemo(() => {
|
|
1392
|
+
const values = {};
|
|
1393
|
+
for (const token of allTokens) {
|
|
1394
|
+
values[token.name] =
|
|
1395
|
+
valueOf(activeState.tokens, token.name) ||
|
|
1396
|
+
sourceTokenValues[token.name] ||
|
|
1397
|
+
token.value ||
|
|
1398
|
+
valueOf(activeState.baseline, token.name);
|
|
1399
|
+
}
|
|
1400
|
+
return values;
|
|
1401
|
+
}, [allTokens, activeState.tokens, activeState.baseline, live]);
|
|
1402
|
+
useEffect(() => {
|
|
1403
|
+
const root = document.documentElement;
|
|
1404
|
+
for (const token of allTokens) {
|
|
1405
|
+
const value = tokenValues[token.name];
|
|
1406
|
+
if (value)
|
|
1407
|
+
root.style.setProperty(token.name, value);
|
|
1408
|
+
else
|
|
1409
|
+
root.style.removeProperty(token.name);
|
|
1410
|
+
}
|
|
1411
|
+
}, [allTokens, tokenValues]);
|
|
1412
|
+
// A token review is resolved only when the generated source actually contains
|
|
1413
|
+
// the requested value. Until then the inline preview stays in place.
|
|
1414
|
+
// Same check as the headless `seji verify`.
|
|
1415
|
+
useEffect(() => {
|
|
1416
|
+
const context = {
|
|
1417
|
+
values: sourceTokenValues,
|
|
1418
|
+
aliases: tokenAliases,
|
|
1419
|
+
literalFiles: literalFilesOf,
|
|
1420
|
+
};
|
|
1421
|
+
const matched = reviewItems.filter((item) => isAwaitingVerification(item) && !tokenVerificationGap(item, context));
|
|
1422
|
+
if (!matched.length)
|
|
1423
|
+
return;
|
|
1424
|
+
const timestamp = nowIso();
|
|
1425
|
+
queueReviewOps(matched.map((item) => ({
|
|
1426
|
+
type: 'patch',
|
|
1427
|
+
id: item.id,
|
|
1428
|
+
patch: { verifiedAt: timestamp, updatedAt: timestamp },
|
|
1429
|
+
})));
|
|
1430
|
+
}, [queueReviewOps, reviewItems, sourceTokenValues, tokenAliases]);
|
|
1431
|
+
const activeReviewItems = useMemo(() => reviewItems.filter((item) => item.status !== 'archived' &&
|
|
1432
|
+
(item.frame === activeFrameId || item.scope === 'design' || item.kind === 'component')), [reviewItems, activeFrameId]);
|
|
1433
|
+
const activeComments = activeReviewItems.filter((item) => item.kind === 'comment');
|
|
1434
|
+
const archivedItems = reviewItems.filter((item) => item.status === 'archived');
|
|
1435
|
+
const tokenOverrides = useMemo(() => reviewItems.flatMap((item) => item.kind === 'token' &&
|
|
1436
|
+
item.scope === 'design' &&
|
|
1437
|
+
item.status !== 'archived' &&
|
|
1438
|
+
!item.verifiedAt &&
|
|
1439
|
+
item.proposalDecision !== 'rejected' &&
|
|
1440
|
+
item.target.type === 'token'
|
|
1441
|
+
? [
|
|
1442
|
+
{
|
|
1443
|
+
name: item.target.token,
|
|
1444
|
+
from: String(item.from ?? ''),
|
|
1445
|
+
value: String(item.to ?? ''),
|
|
1446
|
+
status: item.status,
|
|
1447
|
+
},
|
|
1448
|
+
]
|
|
1449
|
+
: []), [reviewItems]);
|
|
1450
|
+
useEffect(() => {
|
|
1451
|
+
for (const override of tokenOverrides) {
|
|
1452
|
+
if (!override.value)
|
|
1453
|
+
continue;
|
|
1454
|
+
document.documentElement.style.setProperty(override.name, override.value);
|
|
1455
|
+
for (const entry of frameDefs) {
|
|
1456
|
+
send(entry.key, { action: 'set-token', name: override.name, value: override.value });
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
}, [frameDefs, send, tokenOverrides]);
|
|
1460
|
+
const activeComment = activeComments.find((comment) => comment.id === activeCommentId) ?? null;
|
|
1461
|
+
const openCommentsForActive = activeComments.filter(isOpenComment).length;
|
|
1462
|
+
const copyCount = reviewItems.filter(isCopyableReviewItem).length;
|
|
1463
|
+
const commentCount = reviewItems.filter(isOpenComment).length;
|
|
1464
|
+
const addComment = useCallback(() => {
|
|
1465
|
+
if (!commentTarget || !commentDraft.trim() || !activeFrameId)
|
|
1466
|
+
return;
|
|
1467
|
+
const timestamp = nowIso();
|
|
1468
|
+
const item = {
|
|
1469
|
+
id: reviewId(),
|
|
1470
|
+
design: designId,
|
|
1471
|
+
kind: 'comment',
|
|
1472
|
+
scope: 'frame',
|
|
1473
|
+
page: pageIdOfFrameKey(activeFrameId),
|
|
1474
|
+
frame: activeFrameId,
|
|
1475
|
+
target: { type: 'node', node: toNodeRef(commentTarget) },
|
|
1476
|
+
// Product vs sketch at creation time: resolving a product comment with only design/
|
|
1477
|
+
// changes prints a reminder (shared/sketches.mjs).
|
|
1478
|
+
...(sourceKind(commentTarget.source) ? { targetKind: sourceKind(commentTarget.source) ?? undefined } : {}),
|
|
1479
|
+
body: commentDraft.trim(),
|
|
1480
|
+
thread: [],
|
|
1481
|
+
status: 'open',
|
|
1482
|
+
createdAt: timestamp,
|
|
1483
|
+
updatedAt: timestamp,
|
|
1484
|
+
};
|
|
1485
|
+
upsertReviewItem(item);
|
|
1486
|
+
setCommentDraft('');
|
|
1487
|
+
setCommentTarget(null);
|
|
1488
|
+
setActiveCommentId(item.id);
|
|
1489
|
+
// Screenshot of the frame as it looks now (live DOM, current tab/state). The item is saved
|
|
1490
|
+
// first so the server can attach `shot`; a failed capture leaves the comment without one.
|
|
1491
|
+
const captured = captureFrameShot(iframes.current[activeFrameId]);
|
|
1492
|
+
void Promise.all([captured, flushReviewOps()]).then(([png]) => {
|
|
1493
|
+
if (png)
|
|
1494
|
+
void saveCommentShot(designId, item.id, png);
|
|
1495
|
+
});
|
|
1496
|
+
}, [activeFrameId, commentDraft, commentTarget, designId, flushReviewOps, upsertReviewItem]);
|
|
1497
|
+
const resolveComment = useCallback((id) => {
|
|
1498
|
+
const item = reviewRef.current.find((entry) => entry.id === id);
|
|
1499
|
+
if (!item)
|
|
1500
|
+
return;
|
|
1501
|
+
const resolved = item.status !== 'resolved' && item.status !== 'archived';
|
|
1502
|
+
const timestamp = nowIso();
|
|
1503
|
+
upsertReviewItem({
|
|
1504
|
+
...item,
|
|
1505
|
+
status: resolved ? 'resolved' : 'open',
|
|
1506
|
+
resolvedAt: resolved ? timestamp : undefined,
|
|
1507
|
+
updatedAt: timestamp,
|
|
1508
|
+
});
|
|
1509
|
+
}, [upsertReviewItem]);
|
|
1510
|
+
const editComment = useCallback((id, body) => {
|
|
1511
|
+
const item = reviewRef.current.find((entry) => entry.id === id);
|
|
1512
|
+
if (!item || !body.trim())
|
|
1513
|
+
return;
|
|
1514
|
+
upsertReviewItem({ ...item, body: body.trim(), updatedAt: nowIso() });
|
|
1515
|
+
}, [upsertReviewItem]);
|
|
1516
|
+
const deleteComment = useCallback((id) => {
|
|
1517
|
+
removeReviewItems([id]);
|
|
1518
|
+
if (activeCommentId === id)
|
|
1519
|
+
setActiveCommentId(null);
|
|
1520
|
+
}, [activeCommentId, removeReviewItems]);
|
|
1521
|
+
const toggleCommentMode = useCallback(() => {
|
|
1522
|
+
const next = !commentMode;
|
|
1523
|
+
setCommentMode(next);
|
|
1524
|
+
if (next) {
|
|
1525
|
+
setRightTab('comments');
|
|
1526
|
+
setActiveCommentId(null);
|
|
1527
|
+
if (isMobileRef.current)
|
|
1528
|
+
setMobilePanel('right');
|
|
1529
|
+
if (activeFrameId && playRef.current.has(activeFrameId)) {
|
|
1530
|
+
commentRestorePlayRef.current = true;
|
|
1531
|
+
const nextPlay = new Set(playRef.current);
|
|
1532
|
+
nextPlay.delete(activeFrameId);
|
|
1533
|
+
playRef.current = nextPlay;
|
|
1534
|
+
setPlay(nextPlay);
|
|
1535
|
+
send(activeFrameId, { action: 'enable' });
|
|
1536
|
+
}
|
|
1537
|
+
else {
|
|
1538
|
+
commentRestorePlayRef.current = false;
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
else {
|
|
1542
|
+
if (commentRestorePlayRef.current && activeFrameId) {
|
|
1543
|
+
const nextPlay = new Set(playRef.current);
|
|
1544
|
+
nextPlay.add(activeFrameId);
|
|
1545
|
+
playRef.current = nextPlay;
|
|
1546
|
+
setPlay(nextPlay);
|
|
1547
|
+
send(activeFrameId, { action: 'disable' });
|
|
1548
|
+
}
|
|
1549
|
+
commentRestorePlayRef.current = false;
|
|
1550
|
+
setCommentTarget(null);
|
|
1551
|
+
setCommentDraft('');
|
|
1552
|
+
setActiveCommentId(null);
|
|
1553
|
+
}
|
|
1554
|
+
}, [activeFrameId, commentMode, send]);
|
|
1555
|
+
const focusComment = useCallback((id) => {
|
|
1556
|
+
setActiveCommentId(id);
|
|
1557
|
+
setCommentTarget(null);
|
|
1558
|
+
setCommentDraft('');
|
|
1559
|
+
setRightTab('comments');
|
|
1560
|
+
if (isMobileRef.current)
|
|
1561
|
+
setMobilePanel('right');
|
|
1562
|
+
}, []);
|
|
1563
|
+
const syncTokenPreview = useCallback((name, value) => {
|
|
1564
|
+
const baseline = sourceTokenValues[name] ?? '';
|
|
1565
|
+
const nextValue = value ?? baseline;
|
|
1566
|
+
for (const entry of frameDefs) {
|
|
1567
|
+
send(entry.key, { action: 'set-token', name, value: nextValue });
|
|
1568
|
+
}
|
|
1569
|
+
if (nextValue) {
|
|
1570
|
+
document.documentElement.style.setProperty(name, nextValue);
|
|
1571
|
+
}
|
|
1572
|
+
else {
|
|
1573
|
+
document.documentElement.style.removeProperty(name);
|
|
1574
|
+
}
|
|
1575
|
+
setFrameStates((previous) => {
|
|
1576
|
+
const next = { ...previous };
|
|
1577
|
+
for (const entry of frameDefs) {
|
|
1578
|
+
const state = next[entry.key];
|
|
1579
|
+
if (!state)
|
|
1580
|
+
continue;
|
|
1581
|
+
const tokens = state.tokens.filter((item) => item.name !== name);
|
|
1582
|
+
if (value !== null && value !== baseline)
|
|
1583
|
+
tokens.push({ name, value });
|
|
1584
|
+
next[entry.key] = { ...state, tokens };
|
|
1585
|
+
}
|
|
1586
|
+
return next;
|
|
1587
|
+
});
|
|
1588
|
+
}, [frameDefs, send]);
|
|
1589
|
+
const updateProposalValue = useCallback((id, value) => {
|
|
1590
|
+
const item = reviewRef.current.find((entry) => entry.id === id);
|
|
1591
|
+
if (!item || item.target.type !== 'token')
|
|
1592
|
+
return;
|
|
1593
|
+
upsertReviewItem({ ...item, to: value, updatedAt: nowIso() });
|
|
1594
|
+
if (item.proposalDecision !== 'rejected') {
|
|
1595
|
+
syncTokenPreview(item.target.token, value);
|
|
1596
|
+
}
|
|
1597
|
+
}, [syncTokenPreview, upsertReviewItem]);
|
|
1598
|
+
const approveProposal = useCallback((id, value, note) => {
|
|
1599
|
+
const item = reviewRef.current.find((entry) => entry.id === id);
|
|
1600
|
+
if (!item)
|
|
1601
|
+
return;
|
|
1602
|
+
const trimmedNote = note.trim();
|
|
1603
|
+
if (item.target.type !== 'token') {
|
|
1604
|
+
// Component proposals (tidy) are decided where the component page decides them.
|
|
1605
|
+
void decideComponentProposal(item, 'approve', trimmedNote).catch(refetchComponents);
|
|
1606
|
+
return;
|
|
1607
|
+
}
|
|
1608
|
+
upsertReviewItem({
|
|
1609
|
+
...item,
|
|
1610
|
+
to: value,
|
|
1611
|
+
proposalDecision: 'approved',
|
|
1612
|
+
decisionNote: trimmedNote || undefined,
|
|
1613
|
+
updatedAt: nowIso(),
|
|
1614
|
+
});
|
|
1615
|
+
syncTokenPreview(item.target.token, value);
|
|
1616
|
+
}, [decideComponentProposal, refetchComponents, syncTokenPreview, upsertReviewItem]);
|
|
1617
|
+
const rejectProposal = useCallback((id, note) => {
|
|
1618
|
+
const item = reviewRef.current.find((entry) => entry.id === id);
|
|
1619
|
+
if (!item)
|
|
1620
|
+
return;
|
|
1621
|
+
const trimmedNote = note.trim();
|
|
1622
|
+
if (item.target.type !== 'token') {
|
|
1623
|
+
void decideComponentProposal(item, 'reject', trimmedNote).catch(refetchComponents);
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
upsertReviewItem({
|
|
1627
|
+
...item,
|
|
1628
|
+
proposalDecision: 'rejected',
|
|
1629
|
+
decisionNote: trimmedNote || undefined,
|
|
1630
|
+
updatedAt: nowIso(),
|
|
1631
|
+
});
|
|
1632
|
+
syncTokenPreview(item.target.token, null);
|
|
1633
|
+
}, [decideComponentProposal, refetchComponents, syncTokenPreview, upsertReviewItem]);
|
|
1634
|
+
const resetProposalDecision = useCallback((id) => {
|
|
1635
|
+
const item = reviewRef.current.find((entry) => entry.id === id);
|
|
1636
|
+
if (!item)
|
|
1637
|
+
return;
|
|
1638
|
+
if (item.target.type !== 'token') {
|
|
1639
|
+
void decideComponentProposal(item, 'reset').catch(refetchComponents);
|
|
1640
|
+
return;
|
|
1641
|
+
}
|
|
1642
|
+
upsertReviewItem({
|
|
1643
|
+
...item,
|
|
1644
|
+
proposalDecision: undefined,
|
|
1645
|
+
decisionNote: undefined,
|
|
1646
|
+
updatedAt: nowIso(),
|
|
1647
|
+
});
|
|
1648
|
+
if (item.to !== undefined)
|
|
1649
|
+
syncTokenPreview(item.target.token, String(item.to));
|
|
1650
|
+
}, [decideComponentProposal, refetchComponents, syncTokenPreview, upsertReviewItem]);
|
|
1651
|
+
const changeFreeRect = useCallback((rect) => {
|
|
1652
|
+
const state = frameStates[activeFrameId];
|
|
1653
|
+
const node = state?.selected;
|
|
1654
|
+
if (!node?.free)
|
|
1655
|
+
return;
|
|
1656
|
+
const key = node.ownAnchor ?? node.anchor ?? String(node.id);
|
|
1657
|
+
const existing = reviewRef.current.find((item) => item.kind === 'free' &&
|
|
1658
|
+
item.frame === activeFrameId &&
|
|
1659
|
+
item.target.type === 'node' &&
|
|
1660
|
+
(item.target.node.anchor ?? String(item.target.node.id)) === key);
|
|
1661
|
+
const from = existing?.from ?? node.freeRect ?? node.rect ?? rect;
|
|
1662
|
+
const timestamp = nowIso();
|
|
1663
|
+
send(activeFrameId, { action: 'set-free-rect', id: node.id, rect });
|
|
1664
|
+
upsertReviewItem({
|
|
1665
|
+
id: existing?.id ?? `free-${activeFrameId}-${key}`,
|
|
1666
|
+
design: designId,
|
|
1667
|
+
kind: 'free',
|
|
1668
|
+
scope: 'frame',
|
|
1669
|
+
page: pageIdOfFrameKey(activeFrameId),
|
|
1670
|
+
frame: activeFrameId,
|
|
1671
|
+
target: { type: 'node', node: toNodeRef({ ...node, rect, freeRect: rect }) },
|
|
1672
|
+
from,
|
|
1673
|
+
to: rect,
|
|
1674
|
+
status: 'open',
|
|
1675
|
+
createdAt: existing?.createdAt ?? timestamp,
|
|
1676
|
+
updatedAt: timestamp,
|
|
1677
|
+
});
|
|
1678
|
+
setFrameStates((previous) => {
|
|
1679
|
+
const current = previous[activeFrameId] ?? createFrameState();
|
|
1680
|
+
return {
|
|
1681
|
+
...previous,
|
|
1682
|
+
[activeFrameId]: { ...current, selected: { ...node, rect, freeRect: rect } },
|
|
1683
|
+
};
|
|
1684
|
+
});
|
|
1685
|
+
}, [activeFrameId, designId, frameStates, send, upsertReviewItem]);
|
|
1686
|
+
const flashDraftMessage = useCallback((message) => {
|
|
1687
|
+
setDraftMessage(message);
|
|
1688
|
+
window.setTimeout(() => setDraftMessage((current) => (current === message ? null : current)), 3200);
|
|
1689
|
+
}, []);
|
|
1690
|
+
const nodeForTarget = (target) => inspectorTargetsRef.current.find((item) => item.frame === target.frame && item.node.path === target.node.path)?.node;
|
|
1691
|
+
// Inspector edits become drafts: the preview restyles at once, nothing is saved.
|
|
1692
|
+
const editDrafts = useCallback((edits, targets) => {
|
|
1693
|
+
const list = targets ?? inspectorTargetsRef.current.map((item) => ({ frame: item.frame, node: item.ref }));
|
|
1694
|
+
if (!list.length || !edits.length)
|
|
1695
|
+
return;
|
|
1696
|
+
const state = editStateRef.current;
|
|
1697
|
+
const entries = [...draftsRef.current.entries];
|
|
1698
|
+
for (const target of list) {
|
|
1699
|
+
if (playRef.current.has(target.frame))
|
|
1700
|
+
continue;
|
|
1701
|
+
const node = nodeForTarget(target);
|
|
1702
|
+
for (const edit of edits) {
|
|
1703
|
+
const key = draftKey({ frame: target.frame, node: target.node, state, property: edit.property });
|
|
1704
|
+
const index = entries.findIndex((entry) => draftKey(entry) === key);
|
|
1705
|
+
const from = index >= 0 ? entries[index].from : edit.from ?? originalValue(node, edit.property);
|
|
1706
|
+
const entry = {
|
|
1707
|
+
frame: target.frame,
|
|
1708
|
+
node: target.node,
|
|
1709
|
+
property: edit.property,
|
|
1710
|
+
state,
|
|
1711
|
+
from,
|
|
1712
|
+
value: edit.value,
|
|
1713
|
+
...(edit.token ? { token: edit.token } : {}),
|
|
1714
|
+
};
|
|
1715
|
+
if (!edit.token && edit.value === from) {
|
|
1716
|
+
if (index >= 0)
|
|
1717
|
+
entries.splice(index, 1);
|
|
1718
|
+
}
|
|
1719
|
+
else if (index >= 0) {
|
|
1720
|
+
entries[index] = entry;
|
|
1721
|
+
}
|
|
1722
|
+
else {
|
|
1723
|
+
entries.push(entry);
|
|
1724
|
+
}
|
|
1725
|
+
send(target.frame, draftCommand(entry, node?.id));
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
previewRef.current = null;
|
|
1729
|
+
writeDrafts({ ...draftsRef.current, entries });
|
|
1730
|
+
}, [send, writeDrafts]);
|
|
1731
|
+
// Hovering a token or scrubbing shows a value without making it a draft.
|
|
1732
|
+
const previewDrafts = useCallback((edits) => {
|
|
1733
|
+
const last = previewRef.current;
|
|
1734
|
+
if (!edits) {
|
|
1735
|
+
if (!last)
|
|
1736
|
+
return;
|
|
1737
|
+
previewRef.current = null;
|
|
1738
|
+
for (const target of last.targets) {
|
|
1739
|
+
for (const property of last.properties)
|
|
1740
|
+
restoreStyle(target.frame, target.node, property, last.state);
|
|
1741
|
+
}
|
|
1742
|
+
return;
|
|
1743
|
+
}
|
|
1744
|
+
const state = editStateRef.current;
|
|
1745
|
+
const targets = inspectorTargetsRef.current.map((item) => ({ frame: item.frame, node: item.ref }));
|
|
1746
|
+
for (const target of targets) {
|
|
1747
|
+
const id = nodeForTarget(target)?.id;
|
|
1748
|
+
for (const edit of edits) {
|
|
1749
|
+
send(target.frame, {
|
|
1750
|
+
action: 'set-style',
|
|
1751
|
+
...(id !== undefined ? { id } : {}),
|
|
1752
|
+
anchor: target.node.anchor,
|
|
1753
|
+
path: target.node.path,
|
|
1754
|
+
property: edit.property,
|
|
1755
|
+
value: edit.value,
|
|
1756
|
+
...(state !== 'default' ? { state } : {}),
|
|
1757
|
+
});
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
previewRef.current = {
|
|
1761
|
+
targets,
|
|
1762
|
+
properties: [...new Set([...(last?.properties ?? []), ...edits.map((edit) => edit.property)])],
|
|
1763
|
+
state,
|
|
1764
|
+
};
|
|
1765
|
+
}, [restoreStyle, send]);
|
|
1766
|
+
const dropDrafts = useCallback((removed) => {
|
|
1767
|
+
if (!removed.length)
|
|
1768
|
+
return;
|
|
1769
|
+
const keys = new Set(removed.map(draftKey));
|
|
1770
|
+
writeDrafts({
|
|
1771
|
+
...draftsRef.current,
|
|
1772
|
+
entries: draftsRef.current.entries.filter((entry) => !keys.has(draftKey(entry))),
|
|
1773
|
+
});
|
|
1774
|
+
for (const entry of removed)
|
|
1775
|
+
restoreStyle(entry.frame, entry.node, entry.property, entry.state);
|
|
1776
|
+
}, [restoreStyle, writeDrafts]);
|
|
1777
|
+
const revertDrafts = useCallback((properties) => {
|
|
1778
|
+
const state = editStateRef.current;
|
|
1779
|
+
const targets = inspectorTargetsRef.current;
|
|
1780
|
+
dropDrafts(draftsRef.current.entries.filter((entry) => entry.state === state &&
|
|
1781
|
+
properties.includes(entry.property) &&
|
|
1782
|
+
targets.some((item) => item.frame === entry.frame && item.node.path === entry.node.path)));
|
|
1783
|
+
}, [dropDrafts]);
|
|
1784
|
+
const revertNode = useCallback(() => {
|
|
1785
|
+
const primary = inspectorTargetsRef.current[0];
|
|
1786
|
+
if (!primary)
|
|
1787
|
+
return;
|
|
1788
|
+
dropDrafts(entriesWithin(draftsRef.current.entries, primary.frame, primary.node.path));
|
|
1789
|
+
}, [dropDrafts]);
|
|
1790
|
+
// "Save as changes": drafts become pending review items for the agent.
|
|
1791
|
+
const saveDraftChanges = useCallback((scope) => {
|
|
1792
|
+
const frameId = activeFrameRef.current;
|
|
1793
|
+
const primary = inspectorTargetsRef.current[0];
|
|
1794
|
+
if (!frameId || isVariantKey(frameId))
|
|
1795
|
+
return;
|
|
1796
|
+
const chosen = scope === 'component'
|
|
1797
|
+
? primary && primary.frame === frameId
|
|
1798
|
+
? entriesWithin(draftsRef.current.entries, frameId, primary.node.path)
|
|
1799
|
+
: []
|
|
1800
|
+
: draftsRef.current.entries.filter((entry) => entry.frame === frameId);
|
|
1801
|
+
if (!chosen.length)
|
|
1802
|
+
return;
|
|
1803
|
+
const component = scope === 'component' ? primary?.node.component ?? null : null;
|
|
1804
|
+
const timestamp = nowIso();
|
|
1805
|
+
const superseded = [];
|
|
1806
|
+
for (const entry of chosen) {
|
|
1807
|
+
const suffix = entry.state !== 'default' ? `:${entry.state}` : '';
|
|
1808
|
+
const base = scope === 'component' ? `component-${component ?? 'node'}` : frameId;
|
|
1809
|
+
const id = `${entry.token ? 'suggestion' : 'style'}-${base}-${entry.node.path}-${entry.property}${suffix}`;
|
|
1810
|
+
const existing = reviewRef.current.find((item) => item.id === id);
|
|
1811
|
+
for (const item of reviewRef.current) {
|
|
1812
|
+
if (item.id !== id &&
|
|
1813
|
+
(item.kind === 'style' || item.kind === 'suggestion') &&
|
|
1814
|
+
isOpenItem(item) &&
|
|
1815
|
+
item.scope === scope &&
|
|
1816
|
+
item.frame === frameId &&
|
|
1817
|
+
item.target.type === 'node' &&
|
|
1818
|
+
item.target.node.path === entry.node.path &&
|
|
1819
|
+
item.property === entry.property &&
|
|
1820
|
+
stateOf(item) === entry.state) {
|
|
1821
|
+
superseded.push(item.id);
|
|
1822
|
+
}
|
|
1823
|
+
}
|
|
1824
|
+
const token = entry.token ? allTokens.find((item) => item.name === entry.token) : undefined;
|
|
1825
|
+
upsertReviewItem({
|
|
1826
|
+
id,
|
|
1827
|
+
design: designId,
|
|
1828
|
+
kind: entry.token ? 'suggestion' : 'style',
|
|
1829
|
+
scope,
|
|
1830
|
+
page: pageIdOfFrameKey(frameId),
|
|
1831
|
+
frame: frameId,
|
|
1832
|
+
target: { type: 'node', node: entry.node },
|
|
1833
|
+
property: entry.property,
|
|
1834
|
+
...(entry.state !== 'default' ? { state: entry.state } : {}),
|
|
1835
|
+
from: existing?.from ?? entry.from,
|
|
1836
|
+
to: entry.token ?? entry.value,
|
|
1837
|
+
...(entry.token ? { token: entry.token, source: token?.source } : {}),
|
|
1838
|
+
status: 'open',
|
|
1839
|
+
createdAt: existing?.createdAt ?? timestamp,
|
|
1840
|
+
updatedAt: timestamp,
|
|
1841
|
+
});
|
|
1842
|
+
}
|
|
1843
|
+
removeReviewItems([...new Set(superseded)]);
|
|
1844
|
+
const keys = new Set(chosen.map(draftKey));
|
|
1845
|
+
writeDrafts({
|
|
1846
|
+
...draftsRef.current,
|
|
1847
|
+
entries: draftsRef.current.entries.filter((entry) => !keys.has(draftKey(entry))),
|
|
1848
|
+
});
|
|
1849
|
+
flashDraftMessage(scope === 'component'
|
|
1850
|
+
? t('inspect.savedToComponent', { count: chosen.length, name: component ?? '' })
|
|
1851
|
+
: t('inspect.saved', { count: chosen.length }));
|
|
1852
|
+
}, [allTokens, designId, flashDraftMessage, removeReviewItems, t, upsertReviewItem, writeDrafts]);
|
|
1853
|
+
// "Promote to token" is an explicit dialog, so the new token is a change right
|
|
1854
|
+
// away; binding the field to it stays a draft like any other edit.
|
|
1855
|
+
const createPromotedToken = useCallback((target, draft) => {
|
|
1856
|
+
if (!designId)
|
|
1857
|
+
return;
|
|
1858
|
+
const timestamp = nowIso();
|
|
1859
|
+
const source = allTokens.find((item) => item.tier === draft.tier)?.source ??
|
|
1860
|
+
`design/tokens/${draft.tier}.tokens.json`;
|
|
1861
|
+
const id = `token-create-${draft.name}`;
|
|
1862
|
+
const existing = reviewRef.current.find((item) => item.id === id);
|
|
1863
|
+
upsertReviewItem({
|
|
1864
|
+
id,
|
|
1865
|
+
design: designId,
|
|
1866
|
+
kind: 'token',
|
|
1867
|
+
scope: 'design',
|
|
1868
|
+
target: { type: 'token', token: draft.name },
|
|
1869
|
+
from: '',
|
|
1870
|
+
to: draft.value,
|
|
1871
|
+
source,
|
|
1872
|
+
sourceHash: tokenSourceHash,
|
|
1873
|
+
tokenType: draft.type,
|
|
1874
|
+
tokenAction: 'create',
|
|
1875
|
+
tokenTier: draft.tier,
|
|
1876
|
+
...(draft.alias ? { tokenAlias: draft.alias } : {}),
|
|
1877
|
+
tokenDescription: draft.description,
|
|
1878
|
+
status: 'open',
|
|
1879
|
+
createdAt: existing?.createdAt ?? timestamp,
|
|
1880
|
+
updatedAt: timestamp,
|
|
1881
|
+
});
|
|
1882
|
+
for (const entry of frameDefs)
|
|
1883
|
+
send(entry.key, { action: 'set-token', name: draft.name, value: draft.value });
|
|
1884
|
+
for (const variant of draftsRef.current.variants) {
|
|
1885
|
+
send(variant.key, { action: 'set-token', name: draft.name, value: draft.value });
|
|
1886
|
+
}
|
|
1887
|
+
document.documentElement.style.setProperty(draft.name, draft.value);
|
|
1888
|
+
editDrafts([{ property: target.property, value: `var(${draft.name})`, token: draft.name, from: target.value }], [{ frame: target.frame, node: target.node }]);
|
|
1889
|
+
}, [allTokens, designId, editDrafts, frameDefs, send, upsertReviewItem]);
|
|
1890
|
+
const chooseEditState = useCallback((state) => {
|
|
1891
|
+
const primary = inspectorTargetsRef.current[0];
|
|
1892
|
+
if (!primary)
|
|
1893
|
+
return;
|
|
1894
|
+
previewDrafts(null);
|
|
1895
|
+
editStateRef.current = state;
|
|
1896
|
+
setEditState(state);
|
|
1897
|
+
send(primary.frame, {
|
|
1898
|
+
action: 'force-state',
|
|
1899
|
+
id: primary.node.id,
|
|
1900
|
+
anchor: primary.ref.anchor,
|
|
1901
|
+
path: primary.node.path,
|
|
1902
|
+
state: state === 'default' ? null : state,
|
|
1903
|
+
});
|
|
1904
|
+
}, [previewDrafts, send]);
|
|
1905
|
+
// "Save as alternative": copy the artboard (and its drafts) next to it.
|
|
1906
|
+
const saveVariant = useCallback(() => {
|
|
1907
|
+
const base = baseFrameKey(activeFrameRef.current);
|
|
1908
|
+
if (!base || !frameByKey[base])
|
|
1909
|
+
return;
|
|
1910
|
+
const store = draftsRef.current;
|
|
1911
|
+
const siblings = store.variants.filter((variant) => variant.base === base);
|
|
1912
|
+
if (siblings.length >= VARIANT_LIMIT) {
|
|
1913
|
+
flashDraftMessage(t('inspect.variantLimit', { count: VARIANT_LIMIT }));
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1916
|
+
const letter = VARIANT_LETTERS.find((item) => !siblings.some((variant) => variant.name === item));
|
|
1917
|
+
if (!letter)
|
|
1918
|
+
return;
|
|
1919
|
+
const key = `${base}${variantSeparator}${letter.toLowerCase()}`;
|
|
1920
|
+
const copies = store.entries
|
|
1921
|
+
.filter((entry) => entry.frame === base)
|
|
1922
|
+
.map((entry) => ({ ...entry, frame: key }));
|
|
1923
|
+
writeDrafts({
|
|
1924
|
+
entries: [...store.entries, ...copies],
|
|
1925
|
+
variants: [...store.variants, { key, base, name: letter }],
|
|
1926
|
+
});
|
|
1927
|
+
// Once the copy is on the canvas, bring the base and all its alternatives into view.
|
|
1928
|
+
const keys = [base, ...siblings.map((variant) => variant.key), key];
|
|
1929
|
+
window.requestAnimationFrame(() => window.requestAnimationFrame(() => focusBoards(keys)));
|
|
1930
|
+
}, [flashDraftMessage, focusBoards, frameByKey, t, writeDrafts]);
|
|
1931
|
+
const deleteVariant = useCallback((key) => {
|
|
1932
|
+
const store = draftsRef.current;
|
|
1933
|
+
writeDrafts({
|
|
1934
|
+
entries: store.entries.filter((entry) => entry.frame !== key),
|
|
1935
|
+
variants: store.variants.filter((variant) => variant.key !== key),
|
|
1936
|
+
});
|
|
1937
|
+
delete iframes.current[key];
|
|
1938
|
+
setExtraSelection((current) => current.filter((item) => item.frame !== key));
|
|
1939
|
+
if (activeFrameRef.current === key)
|
|
1940
|
+
setActiveFrameId(baseFrameKey(key));
|
|
1941
|
+
}, [writeDrafts]);
|
|
1942
|
+
// "Use this": the alternative's drafts replace the base artboard's drafts.
|
|
1943
|
+
const useVariant = useCallback((key) => {
|
|
1944
|
+
const variant = draftsRef.current.variants.find((item) => item.key === key);
|
|
1945
|
+
if (!variant)
|
|
1946
|
+
return;
|
|
1947
|
+
const base = variant.base;
|
|
1948
|
+
const store = draftsRef.current;
|
|
1949
|
+
const previous = store.entries.filter((entry) => entry.frame === base);
|
|
1950
|
+
const copies = store.entries
|
|
1951
|
+
.filter((entry) => entry.frame === key)
|
|
1952
|
+
.map((entry) => ({ ...entry, frame: base }));
|
|
1953
|
+
writeDrafts({
|
|
1954
|
+
...store,
|
|
1955
|
+
entries: [...store.entries.filter((entry) => entry.frame !== base), ...copies],
|
|
1956
|
+
});
|
|
1957
|
+
for (const entry of previous)
|
|
1958
|
+
restoreStyle(base, entry.node, entry.property, entry.state);
|
|
1959
|
+
for (const entry of copies)
|
|
1960
|
+
send(base, draftCommand(entry));
|
|
1961
|
+
deleteVariant(key);
|
|
1962
|
+
setActiveFrameId(base);
|
|
1963
|
+
flashDraftMessage(t('inspect.variantUsed', { name: t('inspect.variantName', { name: variant.name }) }));
|
|
1964
|
+
}, [deleteVariant, flashDraftMessage, restoreStyle, send, t, writeDrafts]);
|
|
1965
|
+
// Promote a hard-coded literal: one create item that names the token (explicit tier and
|
|
1966
|
+
// usage note) and lists every file that still hard-codes the value, so the agent rewires
|
|
1967
|
+
// those references and verification checks they are gone.
|
|
1968
|
+
const promoteLiteral = useCallback((draft, only) => {
|
|
1969
|
+
if (!designId)
|
|
1970
|
+
return;
|
|
1971
|
+
const timestamp = nowIso();
|
|
1972
|
+
// A component token replaces the literal in that component only.
|
|
1973
|
+
const files = only?.length ? only : literalFilesOf(draft.value);
|
|
1974
|
+
const existing = reviewRef.current.find((item) => item.kind === 'token' &&
|
|
1975
|
+
item.tokenAction === 'create' &&
|
|
1976
|
+
item.target.type === 'token' &&
|
|
1977
|
+
item.target.token === draft.name &&
|
|
1978
|
+
item.status !== 'archived');
|
|
1979
|
+
upsertReviewItem({
|
|
1980
|
+
id: existing?.id ?? `token-create-${draft.name}`,
|
|
1981
|
+
design: designId,
|
|
1982
|
+
kind: 'token',
|
|
1983
|
+
scope: 'design',
|
|
1984
|
+
target: { type: 'token', token: draft.name },
|
|
1985
|
+
from: '',
|
|
1986
|
+
to: draft.value,
|
|
1987
|
+
source: allTokens.find((item) => item.tier === draft.tier)?.source ??
|
|
1988
|
+
`design/tokens/${draft.tier}.tokens.json`,
|
|
1989
|
+
sourceHash: tokenSourceHash,
|
|
1990
|
+
tokenType: /^(#|rgb|hsl|oklch|oklab|color)/i.test(draft.value) ? 'color' : 'text',
|
|
1991
|
+
tokenAction: 'create',
|
|
1992
|
+
tokenTier: draft.tier,
|
|
1993
|
+
...(draft.alias ? { tokenAlias: draft.alias } : {}),
|
|
1994
|
+
tokenDescription: draft.description,
|
|
1995
|
+
replaces: { value: draft.value, files },
|
|
1996
|
+
status: 'open',
|
|
1997
|
+
createdAt: existing?.createdAt ?? timestamp,
|
|
1998
|
+
updatedAt: timestamp,
|
|
1999
|
+
});
|
|
2000
|
+
}, [allTokens, designId, upsertReviewItem]);
|
|
2001
|
+
const copyPrompt = useCallback(() => {
|
|
2002
|
+
if (!design)
|
|
2003
|
+
return;
|
|
2004
|
+
const pending = reviewRef.current.filter(isCopyableReviewItem);
|
|
2005
|
+
if (!pending.length)
|
|
2006
|
+
return;
|
|
2007
|
+
const batch = {
|
|
2008
|
+
id: reviewId(),
|
|
2009
|
+
design: designId,
|
|
2010
|
+
createdAt: nowIso(),
|
|
2011
|
+
itemIds: pending.map((item) => item.id),
|
|
2012
|
+
};
|
|
2013
|
+
queueReviewOps([{ type: 'batch', batch }]);
|
|
2014
|
+
const missing = missingComponentPages(componentCatalog, (name) => Boolean(componentPages[name]));
|
|
2015
|
+
const text = buildAgentPrompt({
|
|
2016
|
+
design: designId,
|
|
2017
|
+
items: pending,
|
|
2018
|
+
batchId: batch.id,
|
|
2019
|
+
missingComponents: missing,
|
|
2020
|
+
});
|
|
2021
|
+
const task = navigator.clipboard?.writeText(text) ??
|
|
2022
|
+
Promise.reject(new Error('Clipboard unavailable'));
|
|
2023
|
+
void task
|
|
2024
|
+
.then(() => {
|
|
2025
|
+
setCopied(true);
|
|
2026
|
+
window.setTimeout(() => setCopied(false), 1500);
|
|
2027
|
+
})
|
|
2028
|
+
.catch(() => setError(t('error.clipboard')));
|
|
2029
|
+
}, [componentCatalog, componentPages, design, designId, flushReviewOps, queueReviewOps, t]);
|
|
2030
|
+
/** The Agent tab in front (not on the changes page, which has no right panel). */
|
|
2031
|
+
const showAgentPanel = useCallback(() => {
|
|
2032
|
+
setRightTab('agent');
|
|
2033
|
+
setRightPanelCollapsed(false);
|
|
2034
|
+
if (isMobileRef.current)
|
|
2035
|
+
setMobilePanel('right');
|
|
2036
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2037
|
+
}, []);
|
|
2038
|
+
/**
|
|
2039
|
+
* "Hand to agent" with an agent on this machine: the same batch as the copy, saved first (the
|
|
2040
|
+
* agent reads the ledger), then the same prompt text as the copy goes to the agent; the panel
|
|
2041
|
+
* shows it as a card of the items. Without an agent it copies the prompt as before.
|
|
2042
|
+
*/
|
|
2043
|
+
const handToAgent = useCallback(async (options) => {
|
|
2044
|
+
if (!design)
|
|
2045
|
+
return;
|
|
2046
|
+
if (!agent.available) {
|
|
2047
|
+
copyPrompt();
|
|
2048
|
+
return;
|
|
2049
|
+
}
|
|
2050
|
+
const pending = reviewRef.current.filter(isCopyableReviewItem);
|
|
2051
|
+
if (!pending.length)
|
|
2052
|
+
return;
|
|
2053
|
+
const batch = {
|
|
2054
|
+
id: reviewId(),
|
|
2055
|
+
design: designId,
|
|
2056
|
+
createdAt: nowIso(),
|
|
2057
|
+
itemIds: pending.map((item) => item.id),
|
|
2058
|
+
};
|
|
2059
|
+
queueReviewOps([{ type: 'batch', batch }]);
|
|
2060
|
+
flushReviewOps();
|
|
2061
|
+
await reviewSaveChain.current.catch(() => { });
|
|
2062
|
+
if (!options?.stay)
|
|
2063
|
+
showAgentPanel();
|
|
2064
|
+
try {
|
|
2065
|
+
await agentSend({
|
|
2066
|
+
text: buildAgentPrompt({
|
|
2067
|
+
design: designId,
|
|
2068
|
+
items: pending,
|
|
2069
|
+
batchId: batch.id,
|
|
2070
|
+
missingComponents: missingComponentPages(componentCatalog, (name) => Boolean(componentPages[name])),
|
|
2071
|
+
}),
|
|
2072
|
+
handoff: { design: designId, itemIds: batch.itemIds, batchId: batch.id },
|
|
2073
|
+
context: agentContextRef.current,
|
|
2074
|
+
});
|
|
2075
|
+
}
|
|
2076
|
+
catch (sendError) {
|
|
2077
|
+
setError(sendError instanceof Error ? sendError.message : String(sendError));
|
|
2078
|
+
}
|
|
2079
|
+
}, [agent.available, componentCatalog, componentPages, copyPrompt, design, designId, flushReviewOps, queueReviewOps, showAgentPanel]);
|
|
2080
|
+
const activateFrame = useCallback((pageId, frameId) => {
|
|
2081
|
+
const page = pages.find((item) => item.id === pageId);
|
|
2082
|
+
const frame = page?.frames.find((item) => item.id === frameId);
|
|
2083
|
+
if (!page || !frame)
|
|
2084
|
+
return;
|
|
2085
|
+
const key = frameKeyOf(page.id, frame.id);
|
|
2086
|
+
setActivePageId(page.id);
|
|
2087
|
+
setActiveFrameId(key);
|
|
2088
|
+
setNavTab(componentPageIds.has(page.id) ? 'components' : 'pages');
|
|
2089
|
+
setRightTab('inspect');
|
|
2090
|
+
setMobilePanel(null);
|
|
2091
|
+
setCommentMode(false);
|
|
2092
|
+
commentRestorePlayRef.current = false;
|
|
2093
|
+
setCommentTarget(null);
|
|
2094
|
+
setCommentDraft('');
|
|
2095
|
+
setActiveCommentId(null);
|
|
2096
|
+
if (!playRef.current.has(key))
|
|
2097
|
+
send(key, { action: 'enable' });
|
|
2098
|
+
replaceCanvasUrl(designId, page.id, frame.id);
|
|
2099
|
+
}, [componentPageIds, designId, pages, send]);
|
|
2100
|
+
const togglePlay = (frameKey) => {
|
|
2101
|
+
const entry = frameByKey[baseFrameKey(frameKey)];
|
|
2102
|
+
if (!entry)
|
|
2103
|
+
return;
|
|
2104
|
+
if (editStateRef.current !== 'default') {
|
|
2105
|
+
send(activeFrameRef.current, { action: 'force-state', state: null });
|
|
2106
|
+
editStateRef.current = 'default';
|
|
2107
|
+
setEditState('default');
|
|
2108
|
+
}
|
|
2109
|
+
previewDrafts(null);
|
|
2110
|
+
setActivePageId(entry.page.id);
|
|
2111
|
+
setActiveFrameId(frameKey);
|
|
2112
|
+
replaceCanvasUrl(designId, entry.page.id, entry.frame.id);
|
|
2113
|
+
setPlay((previous) => {
|
|
2114
|
+
const next = new Set(previous);
|
|
2115
|
+
if (next.has(frameKey)) {
|
|
2116
|
+
next.delete(frameKey);
|
|
2117
|
+
send(frameKey, { action: 'enable' });
|
|
2118
|
+
}
|
|
2119
|
+
else {
|
|
2120
|
+
next.add(frameKey);
|
|
2121
|
+
send(frameKey, { action: 'disable' });
|
|
2122
|
+
setCommentMode(false);
|
|
2123
|
+
commentRestorePlayRef.current = false;
|
|
2124
|
+
setCommentTarget(null);
|
|
2125
|
+
setCommentDraft('');
|
|
2126
|
+
setActiveCommentId(null);
|
|
2127
|
+
}
|
|
2128
|
+
playRef.current = next;
|
|
2129
|
+
return next;
|
|
2130
|
+
});
|
|
2131
|
+
};
|
|
2132
|
+
const selectPage = (pageId, frameId) => {
|
|
2133
|
+
const page = pages.find((item) => item.id === pageId);
|
|
2134
|
+
if (!page)
|
|
2135
|
+
return;
|
|
2136
|
+
if (!frameId && pageId === activePageId && frameByKey[activeFrameId])
|
|
2137
|
+
return;
|
|
2138
|
+
const frame = page.frames.find((item) => item.id === frameId) ?? page.frames[0];
|
|
2139
|
+
if (!frame)
|
|
2140
|
+
return;
|
|
2141
|
+
activateFrame(page.id, frame.id);
|
|
2142
|
+
requestAnimationFrame(() => showPage(page.id));
|
|
2143
|
+
};
|
|
2144
|
+
const openComponentPage = useCallback((name) => {
|
|
2145
|
+
const page = componentPages[name];
|
|
2146
|
+
if (!page || page.design !== designId)
|
|
2147
|
+
return;
|
|
2148
|
+
if (!pages.some((item) => item.id === page.page))
|
|
2149
|
+
return;
|
|
2150
|
+
selectPage(page.page);
|
|
2151
|
+
}, [componentPages, designId, pages, selectPage]);
|
|
2152
|
+
// The last canvas or token page, so the changes page can hand the screen back.
|
|
2153
|
+
const returnPageRef = useRef(null);
|
|
2154
|
+
const resourceRef = useRef({ page: activePageId, token: activeToken, plan: activePlan });
|
|
2155
|
+
resourceRef.current = { page: activePageId, token: activeToken, plan: activePlan };
|
|
2156
|
+
// One place that switches to a resource page and writes its URL.
|
|
2157
|
+
const openResourcePage = useCallback((page, params = {}) => {
|
|
2158
|
+
if (page === 'changes' && resourceRef.current.page !== 'changes')
|
|
2159
|
+
returnPageRef.current = resourceRef.current;
|
|
2160
|
+
setActivePageId(page);
|
|
2161
|
+
if (page !== 'changes')
|
|
2162
|
+
setNavTab(navTabOfResource(page));
|
|
2163
|
+
if (params.token !== undefined)
|
|
2164
|
+
setActiveToken(params.token);
|
|
2165
|
+
if (params.plan !== undefined)
|
|
2166
|
+
setActivePlan(params.plan);
|
|
2167
|
+
if (params.item !== undefined)
|
|
2168
|
+
setActiveChange(params.item);
|
|
2169
|
+
setRightTab('inspect');
|
|
2170
|
+
setMobilePanel(null);
|
|
2171
|
+
replaceUrl(designId, page, params, true);
|
|
2172
|
+
}, [designId]);
|
|
2173
|
+
const selectOverview = useCallback(() => openResourcePage('overview'), [openResourcePage]);
|
|
2174
|
+
/** Token page for a token (its DTCG path or CSS name); null shows the list only. */
|
|
2175
|
+
const openTokenPage = useCallback((token) => {
|
|
2176
|
+
const def = token ? allTokens.find((item) => item.name === token || item.path === token) : undefined;
|
|
2177
|
+
openResourcePage('tokens', { token: def ? tokenLabel(def) : token });
|
|
2178
|
+
}, [allTokens, openResourcePage]);
|
|
2179
|
+
const openConsolidate = useCallback((plan) => openResourcePage('consolidate', { plan }), [openResourcePage]);
|
|
2180
|
+
const openChangesPage = useCallback((item) => openResourcePage('changes', { item }), [openResourcePage]);
|
|
2181
|
+
const leaveChangesPage = useCallback(() => {
|
|
2182
|
+
const back = returnPageRef.current;
|
|
2183
|
+
if (back && isResourcePage(back.page) && back.page !== 'changes') {
|
|
2184
|
+
openResourcePage(back.page, { token: back.token, plan: back.plan });
|
|
2185
|
+
return;
|
|
2186
|
+
}
|
|
2187
|
+
const page = back ? pages.find((item) => item.id === back.page) : undefined;
|
|
2188
|
+
const target = page ?? pageList[0] ?? pages[0];
|
|
2189
|
+
if (target)
|
|
2190
|
+
selectPage(target.id);
|
|
2191
|
+
}, [openResourcePage, pageList, pages, selectPage]);
|
|
2192
|
+
const refreshUsage = useCallback(() => {
|
|
2193
|
+
loadUsageSummary().then((list) => setUsageSummary(new Map(list.map((entry) => [entry.token, entry]))), () => setError(t('error.load')));
|
|
2194
|
+
}, [t]);
|
|
2195
|
+
const wantsUsage = navTab === 'tokens';
|
|
2196
|
+
useEffect(() => {
|
|
2197
|
+
if (wantsUsage && !usageSummary)
|
|
2198
|
+
refreshUsage();
|
|
2199
|
+
}, [refreshUsage, usageSummary, wantsUsage]);
|
|
2200
|
+
// `seji usage <token>` for the token page. App is the one owner: it refetches after
|
|
2201
|
+
// every operation, after an undo, and when the review ledger reports a tool write (CLI or UI).
|
|
2202
|
+
const activeTokenName = useMemo(() => {
|
|
2203
|
+
if (activePageId !== 'tokens' || !activeToken)
|
|
2204
|
+
return null;
|
|
2205
|
+
return allTokens.find((token) => tokenLabel(token) === activeToken || token.name === activeToken)?.name ?? null;
|
|
2206
|
+
}, [activePageId, activeToken, allTokens]);
|
|
2207
|
+
const [tokenUsage, setTokenUsage] = useState(null);
|
|
2208
|
+
const tokenUsageName = useRef(null);
|
|
2209
|
+
const tokenUsageSeq = useRef(0);
|
|
2210
|
+
const refreshTokenUsage = useCallback(() => {
|
|
2211
|
+
const name = tokenUsageName.current;
|
|
2212
|
+
if (!name)
|
|
2213
|
+
return;
|
|
2214
|
+
const seq = ++tokenUsageSeq.current;
|
|
2215
|
+
loadTokenUsage(name).then((report) => {
|
|
2216
|
+
if (tokenUsageSeq.current === seq)
|
|
2217
|
+
setTokenUsage({ token: name, report });
|
|
2218
|
+
}, (error) => {
|
|
2219
|
+
if (tokenUsageSeq.current === seq)
|
|
2220
|
+
setTokenUsage({ token: name, error: errorText(t, error) });
|
|
2221
|
+
});
|
|
2222
|
+
}, [t]);
|
|
2223
|
+
useEffect(() => {
|
|
2224
|
+
tokenUsageName.current = activeTokenName;
|
|
2225
|
+
setTokenUsage((current) => (current?.token === activeTokenName ? current : null));
|
|
2226
|
+
refreshTokenUsage();
|
|
2227
|
+
}, [activeTokenName, refreshTokenUsage]);
|
|
2228
|
+
const refreshAllUsage = useCallback(() => {
|
|
2229
|
+
refreshUsage();
|
|
2230
|
+
refreshTokenUsage();
|
|
2231
|
+
}, [refreshTokenUsage, refreshUsage]);
|
|
2232
|
+
// Tool writes (and token items the agent finished) change who uses what.
|
|
2233
|
+
const tokenWritesKey = useMemo(() => reviewItems
|
|
2234
|
+
.flatMap((item) => item.tokenOp
|
|
2235
|
+
? [`${item.id}@${item.updatedAt}@${item.tokenOp.revertedAt ?? ''}`]
|
|
2236
|
+
: item.kind === 'token'
|
|
2237
|
+
? [`${item.id}@${item.status}`]
|
|
2238
|
+
: [])
|
|
2239
|
+
.join('|'), [reviewItems]);
|
|
2240
|
+
const lastTokenWrites = useRef(null);
|
|
2241
|
+
useEffect(() => {
|
|
2242
|
+
const previous = lastTokenWrites.current;
|
|
2243
|
+
lastTokenWrites.current = tokenWritesKey;
|
|
2244
|
+
if (previous === null || previous === tokenWritesKey)
|
|
2245
|
+
return;
|
|
2246
|
+
refreshAllUsage();
|
|
2247
|
+
// Only the key matters; the refresh callbacks read the current token themselves.
|
|
2248
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2249
|
+
}, [tokenWritesKey]);
|
|
2250
|
+
// Token operations run by the tool (`seji tokens <op>`). A dry run resolves with
|
|
2251
|
+
// its report (refusals included); a real run throws a refusal. With snapshots, the change
|
|
2252
|
+
// opens in Changes (before/after of the affected screens); otherwise the page follows a
|
|
2253
|
+
// renamed or merged token to its new name.
|
|
2254
|
+
const runTokenOp = useCallback(async (op, args) => {
|
|
2255
|
+
const report = await postTokenOp(op, { ...args, design: designId });
|
|
2256
|
+
if (args.dryRun)
|
|
2257
|
+
return report;
|
|
2258
|
+
if (report.refused)
|
|
2259
|
+
throw new ApiError(report.refused, 409, { why: report.why });
|
|
2260
|
+
const follow = op === 'rename' && args.to
|
|
2261
|
+
? args.to
|
|
2262
|
+
: op === 'merge' && args.into && args.alias === false
|
|
2263
|
+
? args.into
|
|
2264
|
+
: op === 'delete'
|
|
2265
|
+
? null
|
|
2266
|
+
: undefined;
|
|
2267
|
+
if (args.snapshots && report.itemId) {
|
|
2268
|
+
// "Back" from Changes returns to the token under its new name.
|
|
2269
|
+
if (follow !== undefined)
|
|
2270
|
+
resourceRef.current = { ...resourceRef.current, page: 'tokens', token: follow };
|
|
2271
|
+
openChangesPage(report.itemId);
|
|
2272
|
+
}
|
|
2273
|
+
else if (follow !== undefined) {
|
|
2274
|
+
openTokenPage(follow);
|
|
2275
|
+
}
|
|
2276
|
+
refreshAllUsage();
|
|
2277
|
+
return report;
|
|
2278
|
+
}, [designId, openChangesPage, openTokenPage, refreshAllUsage]);
|
|
2279
|
+
const openArtboard = useCallback((id) => {
|
|
2280
|
+
setDesignId(id);
|
|
2281
|
+
setMobilePanel(null);
|
|
2282
|
+
window.history.pushState(null, '', `?design=${encodeURIComponent(id)}`);
|
|
2283
|
+
}, []);
|
|
2284
|
+
const goProjects = useCallback(() => {
|
|
2285
|
+
setDesignId('');
|
|
2286
|
+
setMobilePanel(null);
|
|
2287
|
+
window.history.pushState(null, '', window.location.pathname);
|
|
2288
|
+
}, []);
|
|
2289
|
+
if (!design) {
|
|
2290
|
+
return (_jsx(ProjectIndex, { designs: Object.values(DESIGNS), titleOf: titleOf, onOpen: openArtboard }));
|
|
2291
|
+
}
|
|
2292
|
+
const previewSrc = (page, frame) => `/__seji/preview?design=${encodeURIComponent(designId)}&page=${encodeURIComponent(page.id)}&frame=${encodeURIComponent(frame.id)}`;
|
|
2293
|
+
const activePage = pages.find((page) => page.id === activePageId);
|
|
2294
|
+
const activeFrameEntry = frameByKey[baseFrameKey(activeFrameId)];
|
|
2295
|
+
const activeNode = nodeDefs.find((node) => node.id === activePageId);
|
|
2296
|
+
const isOverviewPage = activePageId === 'overview';
|
|
2297
|
+
const isTokensPage = activePageId === 'tokens';
|
|
2298
|
+
const isConsolidatePage = activePageId === 'consolidate';
|
|
2299
|
+
const isChangesPage = activePageId === 'changes';
|
|
2300
|
+
// Resource pages replace the canvas with a scrolling page. The changes page brings its own
|
|
2301
|
+
// list and side column; consolidation is one wide table.
|
|
2302
|
+
const isPagedPage = isResourcePage(activePageId);
|
|
2303
|
+
const hasLeftPanel = !isChangesPage;
|
|
2304
|
+
const hasRightPanel = !isChangesPage && !isConsolidatePage;
|
|
2305
|
+
const confirmCount = changeEntries(reviewItems).filter((entry) => entry.tab === 'confirm').length;
|
|
2306
|
+
const changesPageTitle = (page) => {
|
|
2307
|
+
const entry = page ? pages.find((item) => item.id === page) : undefined;
|
|
2308
|
+
return entry ? titleOf(entry) : page ?? t('changes.comment');
|
|
2309
|
+
};
|
|
2310
|
+
const snapshotFrameTitle = (frame) => {
|
|
2311
|
+
const page = pages.find((item) => item.id === frame.page);
|
|
2312
|
+
const config = page?.frames.find((item) => item.id === frame.frame);
|
|
2313
|
+
return page ? `${titleOf(page)} / ${config ? titleOf(config) : frame.frame}` : frame.title ?? frame.key;
|
|
2314
|
+
};
|
|
2315
|
+
const isDesignPage = activeNode?.kind === 'page';
|
|
2316
|
+
const activeTokenDef = activeToken
|
|
2317
|
+
? allTokens.find((token) => tokenLabel(token) === activeToken || token.name === activeToken)
|
|
2318
|
+
: undefined;
|
|
2319
|
+
const pageLabel = isOverviewPage
|
|
2320
|
+
? t('components.overviewTitle')
|
|
2321
|
+
: isTokensPage
|
|
2322
|
+
? activeTokenDef
|
|
2323
|
+
? tokenLabel(activeTokenDef)
|
|
2324
|
+
: t('tokens.title')
|
|
2325
|
+
: isConsolidatePage
|
|
2326
|
+
? t('consolidate.title')
|
|
2327
|
+
: isChangesPage
|
|
2328
|
+
? t('changesPage.title')
|
|
2329
|
+
: activePage
|
|
2330
|
+
? titleOf(activePage)
|
|
2331
|
+
: t('left.pages');
|
|
2332
|
+
// What the agent is told the user is looking at (an "[Editor]" line when it changes).
|
|
2333
|
+
const agentContext = useMemo(() => {
|
|
2334
|
+
if (!designId)
|
|
2335
|
+
return null;
|
|
2336
|
+
const frameKey = activeFrameId && pageIdOfFrameKey(activeFrameId) === activePageId ? activeFrameId : '';
|
|
2337
|
+
const node = frameKey ? selected : null;
|
|
2338
|
+
return {
|
|
2339
|
+
design: designId,
|
|
2340
|
+
page: activePageId || null,
|
|
2341
|
+
frame: frameKey ? frameIdOfFrameKey(frameKey) || null : null,
|
|
2342
|
+
element: node
|
|
2343
|
+
? { name: node.name, source: node.source ?? null, anchor: node.ownAnchor ?? node.anchor ?? null, text: node.text ?? null }
|
|
2344
|
+
: null,
|
|
2345
|
+
};
|
|
2346
|
+
}, [activeFrameId, activePageId, designId, selected]);
|
|
2347
|
+
const agentContextRef = useRef(agentContext);
|
|
2348
|
+
agentContextRef.current = agentContext;
|
|
2349
|
+
const activeCanvasNode = canvasNodes.find((node) => node.id === activePageId);
|
|
2350
|
+
const activeComponentName = componentNameForPage(designId, activePageId) ?? null;
|
|
2351
|
+
const navQueryText = navQuery.trim().toLowerCase();
|
|
2352
|
+
const filteredPages = pageList.filter((page) => {
|
|
2353
|
+
const label = `${titleOf(page)} ${page.size[0]}×${page.size[1]}`.toLowerCase();
|
|
2354
|
+
return !navQueryText || label.includes(navQueryText);
|
|
2355
|
+
});
|
|
2356
|
+
const sourceLabels = Object.fromEntries(Object.entries(componentSources).map(([name, file]) => [name, sourceLabel(file)]));
|
|
2357
|
+
const missingComponents = componentCatalog.filter((component) => !componentPages[component.name]);
|
|
2358
|
+
const registeredComponents = componentCatalog.filter((component) => Boolean(componentPages[component.name]));
|
|
2359
|
+
const filteredComponentGroups = componentGroups
|
|
2360
|
+
.map((group) => ({
|
|
2361
|
+
...group,
|
|
2362
|
+
components: group.components.filter((component) => {
|
|
2363
|
+
if (!componentPages[component.name])
|
|
2364
|
+
return false;
|
|
2365
|
+
return `${component.name} ${component.file}`
|
|
2366
|
+
.toLowerCase()
|
|
2367
|
+
.includes(navQueryText);
|
|
2368
|
+
}),
|
|
2369
|
+
}))
|
|
2370
|
+
.filter((group) => group.components.length > 0);
|
|
2371
|
+
const filteredMissingComponents = missingComponents.filter((component) => `${component.name} ${component.file}`.toLowerCase().includes(navQueryText));
|
|
2372
|
+
// --- component pages -----------------------------------------------------------------
|
|
2373
|
+
const componentSummaries = componentList?.components ?? [];
|
|
2374
|
+
// Pending component items come from the server report (every design ledger), the
|
|
2375
|
+
// proposal flag from the list: one source for both.
|
|
2376
|
+
const activeReport = componentReport && componentReport.name === activeComponentName ? componentReport : null;
|
|
2377
|
+
const tidyProposalOf = (name) => name === activeReport?.name
|
|
2378
|
+
? activeReport.items.find((item) => item.componentAction === 'tidy' && (item.status === 'open' || item.status === 'in_progress')) ?? null
|
|
2379
|
+
: null;
|
|
2380
|
+
const catalogNames = new Set(componentCatalog.map((component) => component.name));
|
|
2381
|
+
const listedComponents = componentSummaries.filter((summary) => summary.deprecated || (catalogNames.has(summary.name) && componentPages[summary.name]));
|
|
2382
|
+
// "Issues": hard-coded values, or base-layer (primitive) tokens used directly.
|
|
2383
|
+
const hasIssues = (summary) => summary.hardcoded > 0 || summary.primitive > 0;
|
|
2384
|
+
const componentFilterCounts = {
|
|
2385
|
+
all: listedComponents.length,
|
|
2386
|
+
issues: listedComponents.filter(hasIssues).length,
|
|
2387
|
+
proposed: listedComponents.filter((summary) => summary.proposed).length,
|
|
2388
|
+
deprecated: listedComponents.filter((summary) => summary.deprecated).length,
|
|
2389
|
+
};
|
|
2390
|
+
const visibleComponents = listedComponents.filter((summary) => {
|
|
2391
|
+
if (navQueryText && !`${summary.name} ${summary.file}`.toLowerCase().includes(navQueryText))
|
|
2392
|
+
return false;
|
|
2393
|
+
if (componentFilter === 'issues')
|
|
2394
|
+
return hasIssues(summary);
|
|
2395
|
+
if (componentFilter === 'proposed')
|
|
2396
|
+
return summary.proposed;
|
|
2397
|
+
if (componentFilter === 'deprecated')
|
|
2398
|
+
return Boolean(summary.deprecated);
|
|
2399
|
+
return true;
|
|
2400
|
+
});
|
|
2401
|
+
const layeredGroups = componentList
|
|
2402
|
+
? (componentList.layers
|
|
2403
|
+
? [
|
|
2404
|
+
{
|
|
2405
|
+
id: 'base',
|
|
2406
|
+
label: t('components.group.base'),
|
|
2407
|
+
components: visibleComponents.filter((item) => !item.deprecated && item.layer === 'base'),
|
|
2408
|
+
},
|
|
2409
|
+
{
|
|
2410
|
+
id: 'composite',
|
|
2411
|
+
label: t('components.group.composite'),
|
|
2412
|
+
components: visibleComponents.filter((item) => !item.deprecated && item.layer !== 'base'),
|
|
2413
|
+
},
|
|
2414
|
+
]
|
|
2415
|
+
: [
|
|
2416
|
+
{
|
|
2417
|
+
id: 'all',
|
|
2418
|
+
label: t('components.group.all'),
|
|
2419
|
+
components: visibleComponents.filter((item) => !item.deprecated),
|
|
2420
|
+
},
|
|
2421
|
+
])
|
|
2422
|
+
.concat([
|
|
2423
|
+
{
|
|
2424
|
+
id: 'deprecated',
|
|
2425
|
+
label: t('components.group.deprecated'),
|
|
2426
|
+
components: visibleComponents.filter((item) => item.deprecated),
|
|
2427
|
+
},
|
|
2428
|
+
])
|
|
2429
|
+
.filter((group) => group.components.length > 0)
|
|
2430
|
+
: [];
|
|
2431
|
+
const navTabs = [
|
|
2432
|
+
{ id: 'pages', label: t('left.pages'), count: pageList.length, hint: t('left.pagesHint') },
|
|
2433
|
+
{
|
|
2434
|
+
id: 'components',
|
|
2435
|
+
label: t('components.title'),
|
|
2436
|
+
count: registeredComponents.length,
|
|
2437
|
+
hint: t('left.componentsHint'),
|
|
2438
|
+
},
|
|
2439
|
+
{ id: 'tokens', label: t('tokens.title'), count: allTokens.length, hint: t('left.tokensHint') },
|
|
2440
|
+
];
|
|
2441
|
+
const activateCard = (page, frame, key) => {
|
|
2442
|
+
if (!isVariantKey(key)) {
|
|
2443
|
+
activateFrame(page.id, frame.id);
|
|
2444
|
+
return;
|
|
2445
|
+
}
|
|
2446
|
+
setActivePageId(page.id);
|
|
2447
|
+
setActiveFrameId(key);
|
|
2448
|
+
setRightTab('inspect');
|
|
2449
|
+
if (!playRef.current.has(key))
|
|
2450
|
+
send(key, { action: 'enable' });
|
|
2451
|
+
};
|
|
2452
|
+
// Frames an open tidy proposal would move off the component page.
|
|
2453
|
+
const activeTidy = activeComponentName ? tidyProposalOf(activeComponentName) : null;
|
|
2454
|
+
const proposedMoves = new Set(tidyOpen && activeTidy ? (activeTidy.frames ?? []).map((id) => frameKeyOf(activePageId, id)) : []);
|
|
2455
|
+
const renderFrameCard = (page, frame, key, variant) => {
|
|
2456
|
+
const state = frameStates[key] ?? createFrameState();
|
|
2457
|
+
const draftCount = drafts.entries.filter((entry) => entry.frame === key).length;
|
|
2458
|
+
const extras = extraSelection.filter((item) => item.frame === key);
|
|
2459
|
+
const playing = play.has(key);
|
|
2460
|
+
const isActive = activeFrameId === key;
|
|
2461
|
+
const frameComments = reviewItems.filter((item) => item.kind === 'comment' && item.frame === key && item.status !== 'archived');
|
|
2462
|
+
const popoverNode = isActive
|
|
2463
|
+
? commentTarget ??
|
|
2464
|
+
(activeComment?.target.type === 'node' ? activeComment.target.node : null)
|
|
2465
|
+
: null;
|
|
2466
|
+
const iframeElement = iframes.current[key];
|
|
2467
|
+
const iframeRect = iframeElement?.getBoundingClientRect();
|
|
2468
|
+
const iframeScale = iframeRect ? iframeRect.width / frame.size[0] : 1;
|
|
2469
|
+
const commentAnchor = popoverNode?.rect && iframeRect
|
|
2470
|
+
? {
|
|
2471
|
+
x: iframeRect.left + popoverNode.rect.x * iframeScale,
|
|
2472
|
+
y: iframeRect.top + popoverNode.rect.y * iframeScale,
|
|
2473
|
+
width: popoverNode.rect.width * iframeScale,
|
|
2474
|
+
height: popoverNode.rect.height * iframeScale,
|
|
2475
|
+
}
|
|
2476
|
+
: null;
|
|
2477
|
+
const frameWidth = frame.size[0];
|
|
2478
|
+
const frameHeight = frame.size[1];
|
|
2479
|
+
const viewportHeight = Math.max(0, frameHeight - 34);
|
|
2480
|
+
return (_jsxs("div", { className: [
|
|
2481
|
+
'board-frame',
|
|
2482
|
+
isActive ? 'is-active' : '',
|
|
2483
|
+
playing ? 'is-playing' : '',
|
|
2484
|
+
proposedMoves.has(key) ? 'is-proposed-move' : '',
|
|
2485
|
+
]
|
|
2486
|
+
.filter(Boolean)
|
|
2487
|
+
.join(' '), "data-board-frame": key, style: { width: frameWidth, height: frameHeight }, children: [_jsxs("div", { className: "board-frame-chrome", "data-canvas-drag": true, onClick: () => activateCard(page, frame, key), children: [_jsxs("span", { className: "board-frame-title", children: [variant ? t('inspect.variantName', { name: variant.name }) : titleOf(frame), frame.category ? (_jsx("span", { className: `frame-category is-${frame.category}`, children: t(`components.category.${frame.category}`) })) : null] }), _jsxs("span", { className: "board-frame-meta", children: [draftCount ? (_jsx("span", { className: "board-frame-drafts", children: t('inspect.draftShort', { count: draftCount }) })) : null, _jsx("span", { className: "board-frame-state", children: variant ? t('inspect.variantCopy') : frame.id }), _jsxs("span", { className: "board-frame-size", children: [frameWidth, "\u00D7", frameHeight] }), _jsx("button", { "aria-pressed": playing, className: playing ? 'board-mode is-play' : 'board-mode', title: playing ? t('frame.inspectTitle') : t('frame.playTitle'), type: "button", onPointerDown: (event) => event.stopPropagation(), onClick: (event) => {
|
|
2488
|
+
event.stopPropagation();
|
|
2489
|
+
togglePlay(key);
|
|
2490
|
+
}, children: _jsx(Glyph, { name: playing ? 'play' : 'eye', size: 12 }) })] })] }), _jsxs("div", { className: "board-frame-viewport", style: { height: viewportHeight }, children: [_jsx(LazyMount, { active: isActive || playing || Boolean(variant), placeholder: _jsxs("div", { className: "preview-skeleton is-static", children: [_jsx("span", { className: "preview-skeleton-mark" }), _jsx("span", { children: t('preview.loading') })] }), children: _jsx(PreviewFrame, { frameId: key, iframeRef: (element) => {
|
|
2491
|
+
iframes.current[key] = element;
|
|
2492
|
+
}, src: `/__seji/preview?design=${encodeURIComponent(designId)}&page=${encodeURIComponent(page.id)}&frame=${encodeURIComponent(frame.id)}`, title: `${titleOf(page)} / ${titleOf(frame)}`, onLoad: () => {
|
|
2493
|
+
if (!playRef.current.has(key)) {
|
|
2494
|
+
window.setTimeout(() => send(key, { action: 'enable' }), 30);
|
|
2495
|
+
}
|
|
2496
|
+
} }) }), isActive && !playing && state.selected?.rect && (_jsx("div", { className: "selection-outline", style: {
|
|
2497
|
+
left: state.selected.rect.x,
|
|
2498
|
+
top: state.selected.rect.y,
|
|
2499
|
+
width: state.selected.rect.width,
|
|
2500
|
+
height: state.selected.rect.height,
|
|
2501
|
+
}, children: _jsx("span", { className: "selection-label", children: state.selected.ownAnchor ?? state.selected.name }) })), !playing &&
|
|
2502
|
+
extras.map((item) => item.node.rect ? (_jsx("div", { className: "selection-outline is-extra", style: {
|
|
2503
|
+
left: item.node.rect.x,
|
|
2504
|
+
top: item.node.rect.y,
|
|
2505
|
+
width: item.node.rect.width,
|
|
2506
|
+
height: item.node.rect.height,
|
|
2507
|
+
} }, item.node.path)) : null), isActive && !playing && state.hover?.rect && (_jsx("div", { className: "hover-outline", style: {
|
|
2508
|
+
left: state.hover.rect.x,
|
|
2509
|
+
top: state.hover.rect.y,
|
|
2510
|
+
width: state.hover.rect.width,
|
|
2511
|
+
height: state.hover.rect.height,
|
|
2512
|
+
} })), !playing &&
|
|
2513
|
+
frameComments.map((comment, index) => {
|
|
2514
|
+
const node = comment.target.type === 'node' ? comment.target.node : null;
|
|
2515
|
+
if (!node?.rect || comment.status === 'resolved')
|
|
2516
|
+
return null;
|
|
2517
|
+
return (_jsx("button", { "aria-label": comment.body, className: isActive && activeCommentId === comment.id
|
|
2518
|
+
? 'comment-pin is-active'
|
|
2519
|
+
: 'comment-pin', style: {
|
|
2520
|
+
left: (node.rect?.x ?? 0) + (node.rect?.width ?? 0) - 9,
|
|
2521
|
+
top: (node.rect?.y ?? 0) - 9,
|
|
2522
|
+
}, title: comment.body, type: "button", onClick: () => {
|
|
2523
|
+
activateFrame(page.id, frame.id);
|
|
2524
|
+
setActiveCommentId(comment.id);
|
|
2525
|
+
setCommentTarget(null);
|
|
2526
|
+
setCommentDraft('');
|
|
2527
|
+
setRightTab('comments');
|
|
2528
|
+
if (isMobileRef.current)
|
|
2529
|
+
setMobilePanel('right');
|
|
2530
|
+
}, onPointerDown: (event) => event.stopPropagation(), children: index + 1 }, comment.id));
|
|
2531
|
+
}), isActive && (_jsx(CommentPopover, { anchor: commentAnchor, comment: activeComment, draft: commentDraft, target: commentTarget, onAdd: addComment, onCancel: () => {
|
|
2532
|
+
setCommentTarget(null);
|
|
2533
|
+
setCommentDraft('');
|
|
2534
|
+
}, onClose: () => setActiveCommentId(null), onDelete: deleteComment, onDraft: setCommentDraft, onEdit: editComment, onResolve: resolveComment }))] })] }, key));
|
|
2535
|
+
};
|
|
2536
|
+
// Saved-but-unapplied changes plus drafts, for previews that load the frame fresh.
|
|
2537
|
+
const thumbStylesOf = (key) => {
|
|
2538
|
+
const saved = reviewItems.flatMap((item) => {
|
|
2539
|
+
if ((item.kind !== 'style' && item.kind !== 'suggestion') ||
|
|
2540
|
+
item.frame !== baseFrameKey(key) ||
|
|
2541
|
+
item.status === 'archived' ||
|
|
2542
|
+
item.status === 'resolved' ||
|
|
2543
|
+
item.target.type !== 'node' ||
|
|
2544
|
+
!item.property) {
|
|
2545
|
+
return [];
|
|
2546
|
+
}
|
|
2547
|
+
const token = item.kind === 'suggestion' ? item.token ?? String(item.to ?? '') : '';
|
|
2548
|
+
const value = item.kind === 'suggestion' ? (token.startsWith('--') ? `var(${token})` : '') : String(item.to ?? '');
|
|
2549
|
+
if (!value)
|
|
2550
|
+
return [];
|
|
2551
|
+
return [{
|
|
2552
|
+
anchor: item.target.node.anchor ?? null,
|
|
2553
|
+
path: item.target.node.path,
|
|
2554
|
+
property: item.property,
|
|
2555
|
+
value,
|
|
2556
|
+
...(item.state ? { state: item.state } : {}),
|
|
2557
|
+
}];
|
|
2558
|
+
});
|
|
2559
|
+
const draft = drafts.entries
|
|
2560
|
+
.filter((entry) => entry.frame === key)
|
|
2561
|
+
.map((entry) => ({
|
|
2562
|
+
anchor: entry.node.anchor ?? null,
|
|
2563
|
+
path: entry.node.path,
|
|
2564
|
+
property: entry.property,
|
|
2565
|
+
value: entry.value,
|
|
2566
|
+
...(entry.state !== 'default' ? { state: entry.state } : {}),
|
|
2567
|
+
}));
|
|
2568
|
+
return [...saved, ...draft];
|
|
2569
|
+
};
|
|
2570
|
+
// One artboard plus its alternatives side by side, and the selected element's state
|
|
2571
|
+
// previews under the active frame.
|
|
2572
|
+
const renderBoardFrame = (page, frame) => {
|
|
2573
|
+
const key = frameKeyOf(page.id, frame.id);
|
|
2574
|
+
const variants = drafts.variants.filter((variant) => variant.base === key);
|
|
2575
|
+
const statesFor = (cardKey) => {
|
|
2576
|
+
if (play.has(cardKey))
|
|
2577
|
+
return null;
|
|
2578
|
+
const node = activeFrameId === cardKey ? frameStates[cardKey]?.selected ?? null : null;
|
|
2579
|
+
return (_jsx(_Fragment, { children: node?.states ? (_jsx(StatePreviews, { editing: editState, node: node, size: [frame.size[0], Math.max(0, frame.size[1] - 34)], src: previewSrc(page, frame), styles: thumbStylesOf(cardKey), onPick: chooseEditState })) : null }));
|
|
2580
|
+
};
|
|
2581
|
+
return (_jsxs("div", { className: "board-group", children: [_jsxs("div", { className: "board-slot", style: { minWidth: frame.size[0] }, children: [renderFrameCard(page, frame, key), statesFor(key)] }), variants.map((variant) => (_jsxs("div", { className: "board-slot is-variant", style: { minWidth: frame.size[0] }, children: [renderFrameCard(page, frame, variant.key, variant), _jsxs("div", { className: "board-variant-actions", children: [_jsx(Button, { className: "primary-button", type: "button", onClick: () => useVariant(variant.key), children: t('inspect.useVariant') }), _jsx(Button, { className: "button", type: "button", onClick: () => deleteVariant(variant.key), children: t('inspect.deleteVariant') })] }), statesFor(variant.key)] }, variant.key)))] }, key));
|
|
2582
|
+
};
|
|
2583
|
+
const renderCanvasNode = (node) => {
|
|
2584
|
+
if (node.kind !== 'page')
|
|
2585
|
+
return null;
|
|
2586
|
+
const page = pages.find((item) => item.id === node.id);
|
|
2587
|
+
if (!page)
|
|
2588
|
+
return null;
|
|
2589
|
+
const Board = page.board ?? DefaultPageBoard;
|
|
2590
|
+
const pageActiveFrameId = activeFrameEntry?.page.id === page.id ? activeFrameEntry.frame.id : '';
|
|
2591
|
+
const board = (_jsx(Board, { activeFrameId: pageActiveFrameId, frames: page.frames, onActivateFrame: (frameId) => activateFrame(page.id, frameId), page: page, playing: play, renderFrame: (frame) => renderBoardFrame(page, frame) }));
|
|
2592
|
+
const componentName = componentNameForPage(designId, page.id);
|
|
2593
|
+
if (!componentName) {
|
|
2594
|
+
return (_jsx("div", { className: "page-node is-board", "data-board-page": page.id, children: board }));
|
|
2595
|
+
}
|
|
2596
|
+
const summary = componentSummaries.find((item) => item.name === componentName) ?? null;
|
|
2597
|
+
const isCurrent = componentName === activeComponentName;
|
|
2598
|
+
return (_jsxs("div", { className: "page-node is-board is-component-page", "data-board-page": page.id, children: [_jsx(ComponentPageHead, { deprecated: summary?.deprecated ?? null, frames: page.frames, layer: summary?.layer ?? null, name: componentName }), _jsx("div", { className: "component-page-board", children: board }), _jsx(ComponentPageAfter, { frames: page.frames, open: isCurrent && tidyOpen, proposal: tidyProposalOf(componentName), titleOf: titleOf, onDecide: (proposal, decision, note) => decideComponentProposal(proposal, decision, note).then(() => {
|
|
2599
|
+
if (decision !== 'reset')
|
|
2600
|
+
setTidyOpen(false);
|
|
2601
|
+
}), onOpenChange: (open) => {
|
|
2602
|
+
if (!isCurrent)
|
|
2603
|
+
openComponentPage(componentName);
|
|
2604
|
+
setTidyOpen(open);
|
|
2605
|
+
} })] }));
|
|
2606
|
+
};
|
|
2607
|
+
const navPanel = (_jsxs(EditorSidePanel, { ariaLabel: t('left.pages'), side: "left", tabs: navTabs.map((tab) => ({
|
|
2608
|
+
value: tab.id,
|
|
2609
|
+
label: tab.label,
|
|
2610
|
+
count: tab.count,
|
|
2611
|
+
hint: tab.hint,
|
|
2612
|
+
})), value: navTab, onValueChange: (value) => {
|
|
2613
|
+
setNavTab(value);
|
|
2614
|
+
setNavQuery('');
|
|
2615
|
+
}, onClose: isMobile ? () => setMobilePanel(null) : undefined, closeLabel: t('mobile.close'), onCollapse: isMobile ? undefined : () => setLeftPanelCollapsed(true), collapseLabel: t('right.collapse'), children: [_jsxs(Field.Root, { className: "nav-search", children: [_jsx(Icon, { icon: SearchIcon, size: 12 }), _jsx(Field.Control, { "aria-label": t('left.filter'), className: "nav-search-input", placeholder: t('left.filter'), value: navQuery, onChange: (event) => setNavQuery(event.target.value) }), navQuery && (_jsx(IconButton, { className: "icon-button nav-search-clear", label: t('common.clear'), onClick: () => setNavQuery(''), children: _jsx(Icon, { icon: XIcon, size: 10 }) }))] }), _jsx(Tabs.Panel, { className: "nav-body", value: "pages", children: pageList.length === 0 ? (_jsx("div", { className: "panel-empty", children: t('project.noPages') })) : filteredPages.length === 0 ? (_jsx("div", { className: "panel-empty", children: t('left.noMatches') })) : (_jsx("div", { className: "page-list", children: filteredPages.map((page) => (_jsxs(Button, { "aria-current": page.id === activePageId ? 'page' : undefined, className: page.id === activePageId ? 'page-item is-active' : 'page-item', type: "button", onClick: () => selectPage(page.id), children: [_jsx("span", { className: "page-glyph", children: _jsx(Icon, { icon: FileIcon, size: 12 }) }), _jsxs("span", { className: "page-text", children: [_jsx("strong", { children: titleOf(page) }), _jsx("small", { children: t('components.states', { count: page.frames.length }) })] })] }, page.id))) })) }), _jsx(Tabs.Panel, { className: "nav-body", value: "components", children: componentCatalog.length === 0 ? (_jsx("div", { className: "panel-empty", children: t('components.empty') })) : (_jsxs(_Fragment, { children: [_jsxs(Button, { "aria-current": isOverviewPage ? 'page' : undefined, className: isOverviewPage ? 'page-item is-active' : 'page-item', type: "button", onClick: selectOverview, children: [_jsx("span", { className: "page-glyph", children: _jsx(Icon, { icon: ComponentIcon, size: 12 }) }), _jsxs("span", { className: "page-text", children: [_jsx("strong", { children: t('components.overviewTitle') }), _jsx("small", { children: t('components.overviewHint') })] })] }), filteredMissingComponents.length > 0 && (_jsxs("div", { className: "component-missing", children: [_jsxs("div", { className: "component-missing-head", children: [_jsx("strong", { children: t('components.missing') }), _jsx("em", { children: filteredMissingComponents.length })] }), _jsx("p", { children: t('components.missingHint') }), _jsx("div", { className: "component-missing-list", children: filteredMissingComponents.map((component) => (_jsxs("div", { className: "component-missing-row", children: [_jsx("span", { children: component.name }), _jsx("code", { children: sourceLabel(component.file) })] }, component.name))) })] })), componentList ? (_jsxs(_Fragment, { children: [_jsx("div", { className: "component-filters", role: "group", "aria-label": t('left.filter'), children: ['all', 'issues', 'proposed', 'deprecated'].map((filter) => (_jsxs("button", { "aria-pressed": componentFilter === filter, className: componentFilter === filter ? 'component-filter is-on' : 'component-filter', type: "button", onClick: () => setComponentFilter(filter), children: [t(`components.filter.${filter}`), filter !== 'all' ? _jsx("em", { children: componentFilterCounts[filter] }) : null] }, filter))) }), layeredGroups.length > 0 ? (_jsx("div", { className: "component-groups", children: layeredGroups.map((group) => (_jsxs("section", { className: `component-group is-${group.id}`, children: [_jsxs("div", { className: "component-group-head", children: [_jsx("span", { children: group.label }), _jsx("em", { children: group.components.length })] }), group.components.map((summary) => {
|
|
2616
|
+
const hasPage = Boolean(componentPages[summary.name]);
|
|
2617
|
+
const proposed = summary.proposed;
|
|
2618
|
+
return (_jsx(PageLine, { active: summary.name === activeComponentName, icon: ComponentIcon, meta: hasPage ? undefined : t('components.flag.noPage'), name: summary.name, title: summary.description ?? sourceLabel(summary.file), trailing: _jsxs("span", { className: "component-row-flags", children: [summary.deprecated ? (_jsx("span", { className: "component-row-replacement", children: summary.deprecated.replacement
|
|
2619
|
+
? t('components.replacedBy', { name: summary.deprecated.replacement })
|
|
2620
|
+
: t('components.status.deprecated') })) : null, proposed ? (_jsx("span", { className: "component-flag is-proposed", children: t('components.flag.proposed') })) : null, summary.hardcoded > 0 ? (_jsx("span", { className: "component-flag is-warning", children: t('components.flag.hardcoded', { count: summary.hardcoded }) })) : null, summary.primitive > 0 ? (_jsx("span", { className: "component-flag is-warning", children: t('components.flag.primitive', { count: summary.primitive }) })) : null] }), onClick: () => openComponentPage(summary.name) }, summary.name));
|
|
2621
|
+
})] }, group.id))) })) : (_jsx("div", { className: "panel-empty", children: navQueryText ? t('left.noMatches') : t('components.filter.empty') }))] })) : filteredComponentGroups.length > 0 ? (_jsx("div", { className: "component-groups", children: filteredComponentGroups.map((group) => (_jsxs("section", { className: "component-group", children: [_jsxs("div", { className: "component-group-head", children: [_jsx("span", { children: locale === 'zh-CN' ? group.labelZh ?? group.label : group.label }), _jsx("em", { children: group.components.length })] }), group.components.map((component) => {
|
|
2622
|
+
const page = componentPages[component.name];
|
|
2623
|
+
if (!page)
|
|
2624
|
+
return null;
|
|
2625
|
+
const isActive = component.name === activeComponentName;
|
|
2626
|
+
return (_jsx(PageLine, { active: isActive, icon: ComponentIcon, name: component.name, title: `${page.design} / ${page.page}`, onClick: () => openComponentPage(component.name) }, component.name));
|
|
2627
|
+
})] }, group.id))) })) : filteredMissingComponents.length === 0 ? (_jsx("div", { className: "panel-empty", children: t('left.noMatches') })) : null] })) }), _jsx(Tabs.Panel, { className: "nav-body token-nav", value: "tokens", children: _jsx(TokenList, { activeToken: isTokensPage ? activeTokenDef?.name ?? null : null, consolidateActive: isConsolidatePage, health: health, query: navQuery, tokens: allTokens, usage: usageSummary, values: tokenValues, onConsolidate: () => openConsolidate(null), onSelect: openTokenPage }) })] }));
|
|
2628
|
+
const componentGallery = (_jsxs("div", { className: "component-gallery", children: [_jsxs("div", { className: "component-gallery-head", children: [_jsxs("div", { children: [_jsx("p", { className: "panel-kicker", children: t('components.overviewKicker') }), _jsx("h1", { children: t('components.overviewTitle') }), _jsx("p", { children: t('components.overviewHint') })] }), _jsx("span", { className: "component-gallery-count", children: registeredComponents.length })] }), _jsx("div", { className: "component-overview-grid", children: registeredComponents.map((component) => {
|
|
2629
|
+
const pageId = componentPages[component.name]?.page;
|
|
2630
|
+
const page = pageId ? pages.find((item) => item.id === pageId) : undefined;
|
|
2631
|
+
const frame = page?.frames[0];
|
|
2632
|
+
if (!page || !frame)
|
|
2633
|
+
return null;
|
|
2634
|
+
const scale = Math.min(320 / frame.size[0], 176 / frame.size[1]);
|
|
2635
|
+
const normalizedFile = normalizeFilePath(component.file);
|
|
2636
|
+
const hardcoded = hardcodedByFile.get(normalizedFile);
|
|
2637
|
+
const tokenCount = tokenUsesByFile.get(normalizedFile) ?? 0;
|
|
2638
|
+
const badge = hardcoded && hardcoded.count > 0
|
|
2639
|
+
? {
|
|
2640
|
+
tone: 'is-warning',
|
|
2641
|
+
label: t('components.tokenStatus.literals', { count: hardcoded.count }),
|
|
2642
|
+
title: hardcoded.values.length
|
|
2643
|
+
? hardcoded.values.map((entry) => `${entry.value} ×${entry.count}`).join(', ')
|
|
2644
|
+
: t('components.tokenStatus.literals', { count: hardcoded.count }),
|
|
2645
|
+
}
|
|
2646
|
+
: tokenCount > 0
|
|
2647
|
+
? {
|
|
2648
|
+
tone: 'is-tokenized',
|
|
2649
|
+
label: t('components.tokenStatus.tokenized'),
|
|
2650
|
+
title: t('components.tokenStatus.tokenizedHint', { count: tokenCount }),
|
|
2651
|
+
}
|
|
2652
|
+
: {
|
|
2653
|
+
tone: 'is-neutral',
|
|
2654
|
+
label: t('components.tokenStatus.clean'),
|
|
2655
|
+
title: sourceLabel(component.file),
|
|
2656
|
+
};
|
|
2657
|
+
return (_jsxs("div", { "aria-current": activePageId === page.id ? 'page' : undefined, className: activePageId === page.id
|
|
2658
|
+
? 'component-overview-card is-active'
|
|
2659
|
+
: 'component-overview-card', role: "button", tabIndex: 0, onClick: () => selectPage(page.id), onKeyDown: (event) => {
|
|
2660
|
+
if (event.key === 'Enter' || event.key === ' ') {
|
|
2661
|
+
event.preventDefault();
|
|
2662
|
+
selectPage(page.id);
|
|
2663
|
+
}
|
|
2664
|
+
}, children: [_jsx("span", { className: "component-overview-preview", children: _jsx("iframe", { "aria-hidden": "true", loading: "lazy", src: `/__seji/preview?design=${encodeURIComponent(designId)}&page=${encodeURIComponent(page.id)}&frame=${encodeURIComponent(frame.id)}`, style: {
|
|
2665
|
+
width: frame.size[0],
|
|
2666
|
+
height: frame.size[1],
|
|
2667
|
+
transform: `scale(${scale})`,
|
|
2668
|
+
transformOrigin: 'top left',
|
|
2669
|
+
}, tabIndex: -1, title: titleOf(page) }) }), _jsxs("span", { className: "component-overview-info", children: [_jsxs("span", { className: "component-overview-head", children: [_jsx("strong", { children: titleOf(page) }), _jsx("span", { className: `component-token-badge ${badge.tone}`, title: badge.title, children: badge.label })] }), page.description && (_jsx("span", { className: "component-overview-description", children: page.description })), _jsxs("span", { className: "component-overview-meta", children: [page.id, " \u00B7 ", t('components.states', { count: page.frames.length })] })] })] }, component.name));
|
|
2670
|
+
}) }), missingComponents.length > 0 && (_jsxs("div", { className: "component-gallery-missing", children: [_jsx("h2", { children: t('components.missing') }), _jsx("p", { children: t('components.missingHint') }), _jsx("div", { className: "component-gallery-grid", children: missingComponents.map((component) => (_jsx(PageLine, { active: false, icon: ComponentIcon, meta: t('components.missing'), name: component.name, title: sourceLabel(component.file), onClick: () => openComponentPage(component.name) }, component.name))) })] }))] }));
|
|
2671
|
+
const primaryTarget = selected && activeFrameId ? { frame: activeFrameId, node: selected, ref: toNodeRef(selected) } : null;
|
|
2672
|
+
const inspectorTargets = primaryTarget
|
|
2673
|
+
? [
|
|
2674
|
+
primaryTarget,
|
|
2675
|
+
...extraSelection
|
|
2676
|
+
.filter((item) => !(item.frame === activeFrameId && item.node.path === primaryTarget.node.path))
|
|
2677
|
+
.map((item) => ({ frame: item.frame, node: item.node, ref: toNodeRef(item.node) })),
|
|
2678
|
+
]
|
|
2679
|
+
: [];
|
|
2680
|
+
inspectorTargetsRef.current = inspectorTargets;
|
|
2681
|
+
const activeBase = baseFrameKey(activeFrameId);
|
|
2682
|
+
const variantSummaries = drafts.variants
|
|
2683
|
+
.filter((variant) => variant.base === activeBase)
|
|
2684
|
+
.map((variant) => ({
|
|
2685
|
+
key: variant.key,
|
|
2686
|
+
name: t('inspect.variantName', { name: variant.name }),
|
|
2687
|
+
changes: drafts.entries.filter((entry) => entry.frame === variant.key).length,
|
|
2688
|
+
}));
|
|
2689
|
+
// Promote to component: a review item for the agent, written like any other item (the review
|
|
2690
|
+
// endpoint captures its "before" screens).
|
|
2691
|
+
const promoteToComponent = (target, draft) => {
|
|
2692
|
+
if (!designId)
|
|
2693
|
+
return;
|
|
2694
|
+
const node = { ...target.ref, source: target.node.source ?? target.ref.source ?? null };
|
|
2695
|
+
const origin = extractSourceOf(node, catalogNames);
|
|
2696
|
+
upsertReviewItem(extractItem({
|
|
2697
|
+
design: designId,
|
|
2698
|
+
node,
|
|
2699
|
+
page: pageIdOfFrameKey(target.frame),
|
|
2700
|
+
frame: baseFrameKey(target.frame),
|
|
2701
|
+
name: draft.name,
|
|
2702
|
+
description: draft.description,
|
|
2703
|
+
dir: draft.dir,
|
|
2704
|
+
from: origin.from,
|
|
2705
|
+
parent: origin.parent,
|
|
2706
|
+
parentFile: origin.parent ? componentSources[origin.parent] ?? null : null,
|
|
2707
|
+
}));
|
|
2708
|
+
};
|
|
2709
|
+
// Suggest promoting to token: a `create` token item with the name and tier left to the agent
|
|
2710
|
+
// (`target.token` empty, no `tokenTier`), `replaces` the literal like the promote form does,
|
|
2711
|
+
// so the existing verification (token exists, literal gone) applies once the agent names it.
|
|
2712
|
+
const suggestKey = (frame, path, property) => `${baseFrameKey(frame)}|${path}|${property}`;
|
|
2713
|
+
const suggestedTokens = new Set(reviewItems
|
|
2714
|
+
.filter((item) => item.kind === 'token' && item.tokenSuggested && item.status !== 'archived' && item.node)
|
|
2715
|
+
.map((item) => suggestKey(item.frame ?? '', item.node?.path ?? '', item.property ?? '')));
|
|
2716
|
+
const suggestToken = (target, property, value) => {
|
|
2717
|
+
if (!designId)
|
|
2718
|
+
return;
|
|
2719
|
+
const frame = baseFrameKey(target.frame);
|
|
2720
|
+
const key = suggestKey(frame, target.ref.path, property);
|
|
2721
|
+
const existing = reviewRef.current.find((item) => item.tokenSuggested && item.status !== 'archived' && suggestKey(item.frame ?? '', item.node?.path ?? '', item.property ?? '') === key);
|
|
2722
|
+
const timestamp = nowIso();
|
|
2723
|
+
upsertReviewItem({
|
|
2724
|
+
id: existing?.id ?? `token-suggest-${reviewId()}`,
|
|
2725
|
+
design: designId,
|
|
2726
|
+
kind: 'token',
|
|
2727
|
+
scope: 'design',
|
|
2728
|
+
page: pageIdOfFrameKey(frame),
|
|
2729
|
+
frame,
|
|
2730
|
+
target: { type: 'token', token: '' },
|
|
2731
|
+
node: { ...target.ref, source: target.node.source ?? target.ref.source ?? null },
|
|
2732
|
+
property,
|
|
2733
|
+
from: '',
|
|
2734
|
+
to: value,
|
|
2735
|
+
tokenType: /^(#|rgb|hsl|oklch|oklab|color)/i.test(value) ? 'color' : 'length',
|
|
2736
|
+
tokenAction: 'create',
|
|
2737
|
+
tokenSuggested: true,
|
|
2738
|
+
replaces: { value, files: literalFilesOf(value) },
|
|
2739
|
+
status: 'open',
|
|
2740
|
+
createdAt: existing?.createdAt ?? timestamp,
|
|
2741
|
+
updatedAt: timestamp,
|
|
2742
|
+
});
|
|
2743
|
+
};
|
|
2744
|
+
const inspectorProps = {
|
|
2745
|
+
drafts: drafts.entries,
|
|
2746
|
+
editState,
|
|
2747
|
+
running: Boolean(activeFrameId && play.has(activeFrameId)),
|
|
2748
|
+
variant: isVariantKey(activeFrameId),
|
|
2749
|
+
variants: variantSummaries,
|
|
2750
|
+
frameDraftCount: drafts.entries.filter((entry) => entry.frame === activeFrameId).length,
|
|
2751
|
+
boardCount: new Set(inspectorTargets.map((item) => item.frame)).size,
|
|
2752
|
+
message: draftMessage,
|
|
2753
|
+
tokens: allTokens,
|
|
2754
|
+
tokenValues,
|
|
2755
|
+
componentPages,
|
|
2756
|
+
componentSources: sourceLabels,
|
|
2757
|
+
onOpenComponent: openComponentPage,
|
|
2758
|
+
onStopRunning: () => activeFrameId && togglePlay(activeFrameId),
|
|
2759
|
+
onEdit: editDrafts,
|
|
2760
|
+
onPreview: previewDrafts,
|
|
2761
|
+
onRevert: revertDrafts,
|
|
2762
|
+
onRevertNode: revertNode,
|
|
2763
|
+
onSaveChanges: () => saveDraftChanges('frame'),
|
|
2764
|
+
onSaveToComponent: () => saveDraftChanges('component'),
|
|
2765
|
+
onSaveVariant: saveVariant,
|
|
2766
|
+
onUseVariant: useVariant,
|
|
2767
|
+
onCreateToken: createPromotedToken,
|
|
2768
|
+
onFreeRect: changeFreeRect,
|
|
2769
|
+
componentNames: catalogNames,
|
|
2770
|
+
takenComponentNames: takenComponentNames({
|
|
2771
|
+
catalog: catalogNames,
|
|
2772
|
+
pages: Object.keys(componentPages),
|
|
2773
|
+
items: reviewItems,
|
|
2774
|
+
}),
|
|
2775
|
+
componentDirs,
|
|
2776
|
+
onPromoteComponent: promoteToComponent,
|
|
2777
|
+
onSuggestToken: suggestToken,
|
|
2778
|
+
suggestedTokens,
|
|
2779
|
+
};
|
|
2780
|
+
const rightPanel = (_jsxs(EditorRightPanel, { tabs: [
|
|
2781
|
+
{ value: 'inspect', label: t('right.inspect'), hint: t('right.inspectHint') },
|
|
2782
|
+
{
|
|
2783
|
+
value: 'comments',
|
|
2784
|
+
label: t('right.comments'),
|
|
2785
|
+
count: openCommentsForActive,
|
|
2786
|
+
hint: t('right.commentsHint'),
|
|
2787
|
+
},
|
|
2788
|
+
{ value: 'history', label: t('right.history'), hint: t('right.historyHint') },
|
|
2789
|
+
{ value: 'agent', label: t('right.agent') },
|
|
2790
|
+
], value: rightTab, onValueChange: (value) => setRightTab(value), onClose: () => setMobilePanel(null), closeLabel: t('mobile.close'), onCollapse: () => setRightPanelCollapsed(true), collapseLabel: t('right.collapse'), children: [_jsx(Tabs.Panel, { className: "right-body", value: "inspect", children: isDesignPage && activeComponentName && inspectorTargets.length === 0 ? (_jsx(ComponentPanel, { components: componentSummaries, error: componentError, items: activeReport?.items ?? [], loading: componentLoading, name: activeComponentName, report: activeReport, tokens: allTokens, onAction: (input) => runComponentAction({ ...input, name: activeComponentName }), onDescribe: (description) => runComponentAction({ name: activeComponentName, action: 'describe', description }), onPlan: (input, signal) => planComponentAction({ ...input, name: activeComponentName, design: designId }, signal), onRevert: (item) => revertComponentItem(item), onOpenComponent: openComponentPage, onPromote: (draft, files) => promoteLiteral(draft, files) })) : isDesignPage ? (_jsx(Inspector, { ...inspectorProps, targets: inspectorTargets })) : isTokensPage ? (activeTokenDef ? (_jsx(TokenActivity, { health: health, summary: usageSummary?.get(activeTokenDef.name), items: reviewItems.filter(isChangeItem), token: activeTokenDef, onApproveProposal: approveProposal, onOpenChange: openChangesPage, onRejectProposal: rejectProposal, onUpdateProposalValue: updateProposalValue })) : (_jsx("p", { className: "panel-empty", children: t('tokens.activity.pick') }))) : (_jsx(Inspector, { ...inspectorProps, targets: [] })) }), _jsx(Tabs.Panel, { className: "right-body comments-panel-body", value: "comments", children: _jsx(Comments, { activeId: activeCommentId, comments: activeComments, mode: commentMode, onDelete: deleteComment, onFocus: focusComment, onResolve: resolveComment, onToggleMode: toggleCommentMode }) }), _jsx(Tabs.Panel, { className: "right-body history-panel", value: "history", children: _jsx(History, { items: archivedItems }) }), _jsx(Tabs.Panel, { className: "right-body agent-panel-body", keepMounted: true, value: "agent", children: _jsx(AgentPanel, { agent: agent, copied: copied, design: designId ? { id: designId, title: design ? titleOf(design) : designId } : null, context: agentContext, pendingCount: copyCount, onCopy: copyPrompt, onHandoff: () => void handToAgent() }) })] }));
|
|
2791
|
+
return (_jsxs("div", { className: isPagedPage ? 'app is-paged editor-app' : 'app editor-app', children: [_jsx(EditorTopbar, { project: t('project.title'), design: titleOf(design), onProjectClick: goProjects, nav: _jsx("span", { className: "breadcrumb-page", children: pageLabel }), actions: _jsxs(_Fragment, { children: [_jsxs(Button, { "aria-pressed": isChangesPage, className: isChangesPage ? 'topbar-changes is-active' : 'topbar-changes', "data-open-changes": true, title: t('changesPage.openHint'), type: "button", onClick: isChangesPage ? leaveChangesPage : () => openChangesPage(null), children: [_jsx(Icon, { icon: ListChecksIcon, size: 12 }), _jsx("span", { className: "topbar-changes-label", children: t('changesPage.title') }), confirmCount > 0 && _jsx("em", { children: confirmCount })] }), _jsxs(Button, { "aria-pressed": commentMode, className: commentMode ? 'comment-mode is-active' : 'comment-mode', type: "button", onClick: toggleCommentMode, children: [_jsx(Icon, { icon: MessageSquarePlusIcon, size: 12 }), _jsx("span", { className: "topbar-comment-label", children: t('comments.mode') }), commentCount > 0 && _jsx("em", { children: commentCount })] }), _jsxs(Button, { "aria-label": t('topbar.copyPrompt'), className: "primary-button", "data-handoff": agent.available ? 'agent' : 'copy', disabled: copyCount === 0, title: agent.available ? t('agent.handoffHint') : undefined, type: "button", onClick: agent.available ? () => void handToAgent({ stay: isChangesPage }) : copyPrompt, children: [_jsx(Icon, { icon: agent.available ? BotIcon : copied ? CheckIcon : CopyIcon, size: 12 }), _jsx("span", { className: "topbar-copy-label", children: copied && !agent.available
|
|
2792
|
+
? t('topbar.copied')
|
|
2793
|
+
: `${t('topbar.copyPrompt')}${copyCount ? ` (${copyCount})` : ''}` })] }), agent.available ? (_jsx(IconButton, { className: "icon-button topbar-copy-alt", disabled: copyCount === 0, label: copied ? t('topbar.copied') : t('agent.copyInstead'), onClick: copyPrompt, children: _jsx(Icon, { icon: copied ? CheckIcon : CopyIcon, size: 12 }) })) : null, _jsx(LocaleSwitch, {})] }) }), _jsxs("div", { className: [
|
|
2794
|
+
isPagedPage ? 'workspace is-paged' : 'workspace is-floating',
|
|
2795
|
+
isChangesPage ? 'is-full' : '',
|
|
2796
|
+
!isMobile && (leftCollapsed || !hasLeftPanel) ? 'is-left-collapsed' : '',
|
|
2797
|
+
!isMobile && (rightCollapsed || !hasRightPanel) ? 'is-right-collapsed' : '',
|
|
2798
|
+
].filter(Boolean).join(' '), children: [!isMobile && hasLeftPanel && !leftCollapsed && navPanel, !isMobile && hasLeftPanel && leftCollapsed && (_jsx(IconButton, { className: "icon-button left-panel-reopen", label: t('right.expand'), onClick: () => setLeftPanelCollapsed(false), children: _jsx(Icon, { icon: ChevronRightIcon, size: 12 }) })), _jsx("main", { className: "center", children: isTokensPage ? (_jsx("div", { className: "resource-page token-page-wrap", children: activeTokenDef ? (_jsx(TokenPage, { componentPages: componentPageNames, token: activeTokenDef, tokens: allTokens, usage: tokenUsage, values: tokenValues, onOpenComponent: openComponentPage, onRun: runTokenOp, onSelectToken: openTokenPage }, activeTokenDef.name)) : (_jsxs("div", { className: "token-page-empty", children: [_jsx("h1", { children: activeToken ?? t('tokens.title') }), _jsx("p", { children: activeToken
|
|
2799
|
+
? t('tokens.page.missing', { name: activeToken })
|
|
2800
|
+
: t('tokens.page.pick', { count: allTokens.length }) })] })) })) : isConsolidatePage ? (_jsx("div", { className: "resource-page", children: _jsx(ConsolidatePage, { components: componentSummaries, design: designId, planId: activePlan, tokens: allTokens, values: tokenValues, onOpenChange: (item) => {
|
|
2801
|
+
refreshAllUsage();
|
|
2802
|
+
openChangesPage(item);
|
|
2803
|
+
}, onOpenPlan: openConsolidate }) })) : isChangesPage ? (_jsx(ChangesPage, { activeId: activeChange, copied: copied, copyCount: copyCount, design: designId, frameTitle: snapshotFrameTitle, items: reviewItems.filter(isChangeItem), pageTitle: changesPageTitle, onApproveProposal: approveProposal, onCopy: copyPrompt, onRejectProposal: rejectProposal, onRemove: (id) => removeReviewItems([id]), onReverted: refreshAllUsage, onSelect: (id) => openChangesPage(id), onUpdateProposalValue: updateProposalValue })) : isOverviewPage ? (componentGallery) : (_jsx(CanvasSurface, { activeId: activePageId, camera: camera, hint: t('canvas.hint'), nodes: activeCanvasNode ? [activeCanvasNode] : [], onMove: moveNode, onSelect: selectPage, renderNode: renderCanvasNode, viewportRef: canvasRef })) }), !isMobile && hasRightPanel && !rightCollapsed && rightPanel, !isMobile && hasRightPanel && rightCollapsed && (_jsx(IconButton, { className: "icon-button right-panel-reopen", label: t('right.expand'), onClick: () => setRightPanelCollapsed(false), children: _jsx(Icon, { icon: ChevronLeftIcon, size: 12 }) }))] }), isMobile && (_jsxs(_Fragment, { children: [_jsx(Dialog.Root, { open: mobilePanel === 'pages', onOpenChange: (open) => {
|
|
2804
|
+
if (!open)
|
|
2805
|
+
setMobilePanel(null);
|
|
2806
|
+
}, children: _jsxs(Dialog.Portal, { children: [_jsx(Dialog.Backdrop, { className: "mobile-backdrop" }), _jsx(Dialog.Popup, { "aria-label": t('left.pages'), "aria-modal": "true", className: "left-panel mobile-dialog", onKeyDown: (event) => {
|
|
2807
|
+
if (event.key === 'Escape')
|
|
2808
|
+
setMobilePanel(null);
|
|
2809
|
+
}, children: navPanel })] }) }), _jsx(Dialog.Root, { open: mobilePanel === 'right', onOpenChange: (open) => {
|
|
2810
|
+
if (!open)
|
|
2811
|
+
setMobilePanel(null);
|
|
2812
|
+
}, children: _jsxs(Dialog.Portal, { children: [_jsx(Dialog.Backdrop, { className: "mobile-backdrop" }), _jsx(Dialog.Popup, { "aria-label": t('right.inspect'), "aria-modal": "true", className: "right-panel mobile-dialog", onKeyDown: (event) => {
|
|
2813
|
+
if (event.key === 'Escape')
|
|
2814
|
+
setMobilePanel(null);
|
|
2815
|
+
}, children: rightPanel })] }) })] })), _jsxs("nav", { "aria-label": t('mobile.tools'), className: "mobile-toolbar", children: [_jsxs(Button, { className: mobilePanel === 'pages' ? 'mobile-tool is-active' : 'mobile-tool', type: "button", onClick: () => setMobilePanel((current) => (current === 'pages' ? null : 'pages')), children: [_jsx(Icon, { icon: LayoutTemplateIcon, size: 18 }), _jsx("span", { children: t('left.pages') })] }), _jsxs(Button, { className: mobilePanel === 'right' && rightTab === 'inspect'
|
|
2816
|
+
? 'mobile-tool is-active'
|
|
2817
|
+
: 'mobile-tool', type: "button", onClick: () => {
|
|
2818
|
+
setRightTab('inspect');
|
|
2819
|
+
setMobilePanel((current) => current === 'right' && rightTab === 'inspect' ? null : 'right');
|
|
2820
|
+
}, children: [_jsx(Icon, { icon: SlidersHorizontalIcon, size: 18 }), _jsx("span", { children: t('right.inspect') })] }), _jsxs(Button, { className: mobilePanel === 'right' && rightTab === 'comments'
|
|
2821
|
+
? 'mobile-tool is-active'
|
|
2822
|
+
: 'mobile-tool', type: "button", onClick: () => {
|
|
2823
|
+
setRightTab('comments');
|
|
2824
|
+
setMobilePanel((current) => current === 'right' && rightTab === 'comments' ? null : 'right');
|
|
2825
|
+
}, children: [_jsx(Icon, { icon: MessageSquarePlusIcon, size: 18 }), _jsx("span", { children: t('right.comments') }), openCommentsForActive > 0 && _jsx("em", { children: openCommentsForActive })] }), _jsxs(Button, { className: isChangesPage ? 'mobile-tool is-active' : 'mobile-tool', type: "button", onClick: isChangesPage ? leaveChangesPage : () => openChangesPage(null), children: [_jsx(Icon, { icon: ListChecksIcon, size: 18 }), _jsx("span", { children: t('changesPage.title') }), confirmCount > 0 && _jsx("em", { children: confirmCount })] })] }), _jsx(EditorStatusBar, { preview: t('status.preview'), version: version, designLabel: t('status.design'), design: designId, page: pageLabel || activePageId, pathLabel: t('status.review'), path: `design/${designId}/review.json`, error: error, buildError: buildError
|
|
2826
|
+
? {
|
|
2827
|
+
label: t('status.buildError', { file: errorWhere(buildError) || buildError.message }),
|
|
2828
|
+
detail: buildError.detail,
|
|
2829
|
+
}
|
|
2830
|
+
: null })] }));
|
|
2831
|
+
}
|
|
2832
|
+
//# sourceMappingURL=App.js.map
|