@designos/editor 0.0.0-stage → 0.2.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/dist/index.js ADDED
@@ -0,0 +1,3316 @@
1
+ // src/components/Editor.tsx
2
+ import { useState as useState14 } from "react";
3
+
4
+ // src/hooks/useEditorAppearance.ts
5
+ import { useCallback, useEffect, useState } from "react";
6
+ var STORAGE_KEY = "designos:editor-appearance:v1";
7
+ function readAppearance() {
8
+ if (typeof window === "undefined") return "dark";
9
+ try {
10
+ return window.localStorage.getItem(STORAGE_KEY) === "light" ? "light" : "dark";
11
+ } catch {
12
+ return "dark";
13
+ }
14
+ }
15
+ function useEditorAppearance() {
16
+ const [appearance, setAppearance] = useState(readAppearance);
17
+ useEffect(() => {
18
+ try {
19
+ window.localStorage.setItem(STORAGE_KEY, appearance);
20
+ } catch {
21
+ }
22
+ }, [appearance]);
23
+ const toggleAppearance = useCallback(() => {
24
+ setAppearance((current) => current === "dark" ? "light" : "dark");
25
+ }, []);
26
+ return { appearance, toggleAppearance };
27
+ }
28
+
29
+ // src/components/Editor.tsx
30
+ import { createNodeFromManifest as createNodeFromManifest2, findNode as findNode4 } from "@designos/core";
31
+
32
+ // src/components/EditorStyleBoundary.tsx
33
+ import { useCallback as useCallback2, useState as useState2 } from "react";
34
+ import { createPortal } from "react-dom";
35
+ import { jsx } from "react/jsx-runtime";
36
+ var EDITOR_BASE_STYLES = `
37
+ :host {
38
+ all: initial !important;
39
+ --dos-bg-0: #09090b;
40
+ --dos-bg-1: #0f0f12;
41
+ --dos-bg-2: #18181b;
42
+ --dos-bg-3: #1e1e23;
43
+ --dos-bg-4: #27272a;
44
+ --dos-border: #2a2a2f;
45
+ --dos-border-hover: #3a3a3f;
46
+ --dos-text-0: #fafafa;
47
+ --dos-text-1: #a1a1aa;
48
+ --dos-text-2: #71717a;
49
+ --dos-green: #22c55e;
50
+ --dos-green-glow: rgba(34, 197, 94, 0.12);
51
+ display: block !important;
52
+ width: 100% !important;
53
+ min-height: 100vh !important;
54
+ color: var(--dos-text-0) !important;
55
+ background: var(--dos-bg-0) !important;
56
+ color-scheme: dark;
57
+ font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
58
+ font-size: 14px !important;
59
+ line-height: 1.45 !important;
60
+ position: relative !important;
61
+ overflow-x: clip !important;
62
+ -webkit-font-smoothing: antialiased;
63
+ -moz-osx-font-smoothing: grayscale;
64
+ }
65
+ :host *, :host *::before, :host *::after { box-sizing: border-box; }
66
+ :host * { font-family: inherit; border-color: var(--dos-border) !important; }
67
+ :host header {
68
+ position: relative; z-index: 2; min-height: 56px; height: 56px !important;
69
+ padding: 0 16px !important; gap: 16px !important; color: var(--dos-text-0) !important;
70
+ background: rgba(15, 15, 18, 0.96) !important; border-bottom: 1px solid var(--dos-border) !important;
71
+ box-shadow: 0 1px 0 rgba(255, 255, 255, 0.02);
72
+ }
73
+ :host header > strong { color: var(--dos-text-0); font-size: 14px; font-weight: 650; letter-spacing: -0.02em; white-space: nowrap; }
74
+ :host aside { color: var(--dos-text-0) !important; background: var(--dos-bg-1) !important; }
75
+ :host main { min-width: 0; color: var(--dos-text-0) !important; background: var(--dos-bg-0) !important; }
76
+ :host h3 { color: var(--dos-text-0) !important; font-size: 13px !important; font-weight: 650 !important; letter-spacing: 0.01em; }
77
+ :host h4 { color: var(--dos-text-0) !important; font-size: 12px; font-weight: 650; }
78
+ :host small, :host [data-muted="true"] { color: var(--dos-text-2) !important; }
79
+ :host label { color: var(--dos-text-1) !important; }
80
+ :host button {
81
+ min-height: 30px; padding: 6px 10px !important; border: 1px solid var(--dos-border) !important;
82
+ border-radius: 8px !important; color: var(--dos-text-1) !important; background: var(--dos-bg-2) !important;
83
+ font-size: 12px !important; font-weight: 550; line-height: 1.2; cursor: pointer;
84
+ transition: color 140ms ease, background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
85
+ }
86
+ :host button:hover:not(:disabled) { color: var(--dos-text-0) !important; background: var(--dos-bg-4) !important; border-color: var(--dos-border-hover) !important; }
87
+ :host button:active:not(:disabled) { transform: translateY(1px); }
88
+ :host button:disabled { cursor: not-allowed; opacity: 0.45; }
89
+ :host button[aria-pressed="true"] { color: #d9fbe5 !important; background: var(--dos-green-glow) !important; border-color: rgba(34, 197, 94, 0.42) !important; }
90
+ :host button.dos-primary-button { color: #06130a !important; background: var(--dos-green) !important; border-color: var(--dos-green) !important; font-weight: 700; }
91
+ :host button.dos-primary-button:hover:not(:disabled) { color: #041008 !important; background: #4ade80 !important; border-color: #4ade80 !important; box-shadow: 0 0 16px rgba(34, 197, 94, 0.16); }
92
+ :host button.dos-component-item { display: block; min-height: 0; padding: 11px 12px !important; color: var(--dos-text-0) !important; background: var(--dos-bg-1) !important; text-align: left !important; }
93
+ :host button.dos-component-item > div { font-size: 12px; font-weight: 600; }
94
+ :host button.dos-component-item > small { display: block; margin-top: 3px; font-size: 10px; }
95
+ :host .dos-layer-row { color: var(--dos-text-1); transition: background-color 140ms ease, color 140ms ease; }
96
+ :host .dos-layer-row:hover { background: var(--dos-bg-2) !important; }
97
+ :host .dos-layer-row.is-selected { color: #d9fbe5 !important; background: var(--dos-green-glow) !important; box-shadow: inset 2px 0 var(--dos-green); }
98
+ :host input:not([type="checkbox"]):not([type="radio"]):not([type="color"]), :host select, :host textarea {
99
+ width: 100%; min-width: 0; padding: 8px 10px !important; color: var(--dos-text-0) !important;
100
+ background: var(--dos-bg-0) !important; border: 1px solid var(--dos-border) !important;
101
+ border-radius: 8px !important; font-size: 12px !important; line-height: 1.45;
102
+ box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.18);
103
+ }
104
+ :host input::placeholder, :host textarea::placeholder { color: var(--dos-text-2) !important; }
105
+ :host input:focus, :host select:focus, :host textarea:focus { outline: 2px solid rgba(34, 197, 94, 0.72) !important; outline-offset: 1px; border-color: var(--dos-green) !important; }
106
+ :host input[type="checkbox"], :host input[type="radio"] { accent-color: var(--dos-green); }
107
+ :host input[type="color"] { width: 40px; height: 32px; padding: 3px; border: 1px solid var(--dos-border) !important; border-radius: 8px; background: var(--dos-bg-0); }
108
+ :host a { color: var(--dos-green) !important; text-underline-offset: 3px; }
109
+ :host a:hover { color: #4ade80 !important; }
110
+ :host [role="alert"] { color: #fecaca !important; background: rgba(127, 29, 29, 0.28) !important; border-color: rgba(239, 68, 68, 0.32) !important; }
111
+ :host .dos-editor-layout { min-width: 0; }
112
+ :host .dos-sidebar { flex: 0 0 280px; min-width: 0; }
113
+ :host .dos-sidebar-tabs { flex: 0 0 auto; border-bottom: 1px solid var(--dos-border) !important; }
114
+ :host .dos-sidebar-tabs button { min-height: 42px; border: 0 !important; border-radius: 0 !important; background: transparent !important; }
115
+ :host .dos-sidebar-tabs button[aria-pressed="true"] { color: var(--dos-green) !important; background: rgba(34, 197, 94, 0.06) !important; box-shadow: inset 0 -2px var(--dos-green); }
116
+ :host .dos-sidebar-content { min-height: 0; }
117
+ :host .dos-inspector { flex: 0 0 320px; min-width: 0; }
118
+ :host .dos-toolbar-actions { min-width: 0; flex-wrap: wrap; align-items: center; }
119
+ :host .dos-toolbar { position: sticky; top: 0; z-index: 8; height: 58px !important; min-height: 58px !important; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 16px !important; color: var(--dos-text-0) !important; background: rgba(15, 15, 18, 0.94) !important; border-bottom: 1px solid var(--dos-border) !important; backdrop-filter: blur(16px); }
120
+ :host .dos-toolbar-brand { display: flex; align-items: center; gap: 9px; flex: 0 0 auto; }
121
+ :host .dos-toolbar-brand strong { color: var(--dos-text-0); font-size: 13px; font-weight: 700; letter-spacing: -0.02em; }
122
+ :host .dos-brand-mark { display: grid; width: 29px; height: 29px; place-items: center; color: #07130a; background: linear-gradient(145deg, #4ade80, #22c55e); border: 1px solid rgba(134, 239, 172, 0.45); border-radius: 9px; box-shadow: 0 4px 14px rgba(34, 197, 94, 0.16); }
123
+ :host .dos-toolbar-actions { display: flex; flex: 1 1 auto; justify-content: flex-end; gap: 8px; }
124
+ :host .dos-toolbar-group { display: inline-flex; align-items: center; gap: 3px; padding: 3px; border: 1px solid rgba(63, 63, 70, 0.72); border-radius: 10px; background: rgba(24, 24, 27, 0.86); }
125
+ :host .dos-toolbar-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-width: 34px; height: 32px; padding: 0 9px !important; border-color: transparent !important; border-radius: 7px !important; color: var(--dos-text-1) !important; background: transparent !important; white-space: nowrap; }
126
+ :host .dos-toolbar-button:hover:not(:disabled) { color: var(--dos-text-0) !important; background: var(--dos-bg-3) !important; }
127
+ :host .dos-toolbar-button[aria-pressed="true"] { color: #d9fbe5 !important; background: rgba(34, 197, 94, 0.14) !important; border-color: rgba(34, 197, 94, 0.2) !important; }
128
+ :host .dos-toolbar-button svg, :host .dos-brand-mark svg { flex: 0 0 auto; }
129
+ :host .dos-toolbar-label { display: inline; }
130
+ :host .dos-viewport-group { gap: 1px; }
131
+ :host .dos-publish-wrap { display: flex; align-items: center; gap: 8px; min-width: 0; }
132
+ :host .dos-publish-button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 36px; padding: 0 13px !important; border-radius: 9px !important; white-space: nowrap; }
133
+ :host .dos-publish-feedback { max-width: 190px; overflow: hidden; color: var(--dos-text-2); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
134
+ :host .dos-publish-feedback.is-success { color: #86efac !important; }
135
+ :host .dos-publish-feedback.is-error { color: #fca5a5 !important; }
136
+ :host .dos-publish-link { font-size: 11px; white-space: nowrap; }
137
+ :host .dos-mobile-nav { display: none; }
138
+ :host .dos-editor-layout { display: flex; height: calc(100dvh - 58px); min-height: 360px; overflow: hidden; }
139
+ :host .dos-sidebar { width: 280px; height: 100%; display: flex; flex-direction: column; flex: 0 0 280px; min-width: 0; background: linear-gradient(180deg, #111114, #0f0f12) !important; border-right: 1px solid var(--dos-border) !important; }
140
+ :host .dos-sidebar-tabs { display: flex; flex: 0 0 auto; padding: 7px; gap: 4px; border-bottom: 1px solid var(--dos-border) !important; background: rgba(15, 15, 18, 0.74); }
141
+ :host .dos-sidebar-tabs button { display: flex; flex: 1; align-items: center; justify-content: center; gap: 7px; min-height: 36px; padding: 0 8px !important; border: 1px solid transparent !important; border-radius: 8px !important; color: var(--dos-text-2) !important; background: transparent !important; }
142
+ :host .dos-sidebar-tabs button[aria-selected="true"] { color: var(--dos-text-0) !important; background: var(--dos-bg-3) !important; border-color: var(--dos-border) !important; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.24); }
143
+ :host .dos-sidebar-content { flex: 1; overflow: auto; padding: 8px; }
144
+ :host .dos-component-header { padding: 12px !important; border-bottom: 1px solid var(--dos-border) !important; }
145
+ :host .dos-component-header h3 { margin: 0 0 10px !important; }
146
+ :host .dos-component-category { color: var(--dos-text-2) !important; font-size: 10px !important; letter-spacing: 0.09em; }
147
+ :host .dos-component-item { margin-bottom: 6px; border: 1px solid var(--dos-border) !important; border-radius: 9px !important; transition: background 140ms ease, border-color 140ms ease, transform 140ms ease; }
148
+ :host .dos-component-item:hover { transform: translateY(-1px); }
149
+ :host .dos-layer-row { border-color: var(--dos-border) !important; background: var(--dos-bg-1) !important; }
150
+ :host .dos-layer-row:not(.is-selected):hover { color: var(--dos-text-0) !important; background: var(--dos-bg-2) !important; }
151
+ :host .dos-layer-row > button { min-width: 28px; min-height: 28px; padding: 3px !important; }
152
+ :host .dos-inspector { display: flex; flex: 0 0 320px; flex-direction: column; min-width: 0; overflow: auto; background: linear-gradient(180deg, #111114, #0f0f12) !important; border-left: 1px solid var(--dos-border) !important; }
153
+ :host .dos-inspector-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; padding: 14px 16px; background: rgba(15, 15, 18, 0.96); border-bottom: 1px solid var(--dos-border) !important; backdrop-filter: blur(12px); }
154
+ :host .dos-inspector-head strong { color: var(--dos-text-0); font-size: 12px; font-weight: 700; }
155
+ :host .dos-inspector-head span { color: var(--dos-text-2); font-size: 10px; }
156
+ :host .dos-inspector-content { min-height: 0; }
157
+ :host .dos-inspector-content > div { padding: 14px !important; }
158
+ :host .dos-inspector-content label { font-size: 11px !important; font-weight: 550 !important; }
159
+ :host .dos-inspector-content h3 { margin-bottom: 12px !important; font-size: 14px !important; }
160
+ :host .dos-inspector-content h4 { margin-bottom: 9px !important; color: var(--dos-text-1) !important; font-size: 10px !important; letter-spacing: 0.07em; text-transform: uppercase; }
161
+ :host .dos-inspector-content section { border-color: var(--dos-border) !important; }
162
+ :host .dos-inspector-content select { min-width: 0; }
163
+ :host .dos-main { flex: 1 1 auto; min-width: 0; overflow: auto; background: radial-gradient(ellipse at 50% 0%, rgba(39, 39, 42, 0.58), transparent 68%), #09090b !important; }
164
+ :host .dos-canvas-viewport { display: flex; min-height: 100%; justify-content: center; padding: 24px; }
165
+ :host .dos-canvas-page { flex: 0 0 auto; max-width: 100%; transition: width 180ms ease; }
166
+ :host .dos-mobile-nav { position: fixed; inset: auto 0 0; z-index: 4; height: calc(66px + env(safe-area-inset-bottom)); padding: 5px 12px env(safe-area-inset-bottom); align-items: center; justify-content: space-around; background: rgba(15, 15, 18, 0.96); border-top: 1px solid var(--dos-border) !important; backdrop-filter: blur(18px); }
167
+ :host .dos-mobile-nav button { display: flex; flex: 1; height: 54px; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 4px 6px !important; border: 1px solid transparent !important; border-radius: 10px !important; color: var(--dos-text-2) !important; background: transparent !important; font-size: 10px !important; }
168
+ :host .dos-mobile-nav button[aria-pressed="true"] { color: #d9fbe5 !important; background: rgba(34, 197, 94, 0.12) !important; border-color: rgba(34, 197, 94, 0.18) !important; }
169
+ :host .dos-property-section { border-color: var(--dos-border) !important; }
170
+ :host .dos-json-overlay { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; background: rgba(0, 0, 0, 0.44); }
171
+ :host .dos-json-drawer { width: 100%; height: min(56vh, 540px); min-height: 240px; display: flex; flex-direction: column; overflow: hidden; color: var(--dos-text-0) !important; background: var(--dos-bg-1) !important; border: 1px solid var(--dos-border) !important; border-bottom: 0 !important; border-radius: 14px 14px 0 0; box-shadow: 0 -16px 50px rgba(0, 0, 0, 0.42); }
172
+ :host .dos-json-header { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; background: var(--dos-bg-1) !important; border-bottom: 1px solid var(--dos-border) !important; }
173
+ :host .dos-json-title { display: flex; flex-direction: column; gap: 2px; min-width: max-content; }
174
+ :host .dos-json-title strong { color: var(--dos-text-0); font-size: 13px; }
175
+ :host .dos-json-title span { color: var(--dos-text-2); font-size: 10px; }
176
+ :host .dos-json-actions { display: flex; align-items: center; justify-content: flex-end; flex-wrap: wrap; gap: 6px; }
177
+ :host .dos-json-close { min-width: 30px; padding: 2px 8px !important; font-size: 19px !important; line-height: 1; }
178
+ :host .dos-json-error { flex: 0 0 auto; max-height: 72px; overflow: auto; padding: 8px 14px; color: #fecaca; background: rgba(127, 29, 29, 0.28); border-bottom: 1px solid rgba(239, 68, 68, 0.32); font-size: 11px; white-space: pre-wrap; }
179
+ :host .dos-json-body { flex: 1; min-height: 0; overflow: hidden; }
180
+ :host .dos-json-body textarea, :host .dos-json-body pre { display: block; width: 100%; height: 100%; min-height: 0; margin: 0; padding: 14px 16px !important; overflow: auto; resize: none; border: 0 !important; border-radius: 0 !important; color: #d4d4d8 !important; background: #09090b !important; font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace !important; font-size: 11px !important; line-height: 1.6; white-space: pre; }
181
+ @media (max-width: 760px) {
182
+ :host .dos-json-overlay { z-index: 20; }
183
+ :host .dos-json-drawer { height: min(68vh, 620px); }
184
+ :host .dos-json-header { align-items: flex-start; flex-direction: column; gap: 8px; padding: 10px; }
185
+ :host .dos-json-title { flex-direction: row; align-items: baseline; gap: 8px; }
186
+ :host .dos-json-actions { width: 100%; justify-content: flex-start; }
187
+ :host .dos-json-body textarea, :host .dos-json-body pre { padding: 10px !important; }
188
+ }
189
+ :host .dos-assistant-drawer { position: absolute; top: 56px; right: 0; bottom: 0; z-index: 6; width: min(380px, 100%); display: flex; flex-direction: column; color: var(--dos-text-0) !important; background: var(--dos-bg-1) !important; border-left: 1px solid var(--dos-border) !important; box-shadow: -10px 0 30px rgba(0, 0, 0, 0.24); transform: translateX(100%); transition: transform 180ms ease; pointer-events: none; }
190
+ :host .dos-assistant-drawer.is-open { transform: translateX(0); pointer-events: auto; }
191
+ :host .dos-assistant-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--dos-border) !important; }
192
+ :host .dos-assistant-header > div { display: flex; flex-direction: column; gap: 2px; }
193
+ :host .dos-assistant-header strong { font-size: 13px; }
194
+ :host .dos-assistant-header span { color: var(--dos-text-2); font-size: 10px; }
195
+ :host .dos-assistant-header button { min-height: 28px; width: 28px; padding: 0 !important; font-size: 18px !important; line-height: 1; }
196
+ :host .dos-assistant-messages { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
197
+ :host .dos-assistant-empty { margin: auto 8px; color: var(--dos-text-2); font-size: 12px; line-height: 1.6; text-align: center; }
198
+ :host .dos-assistant-message { max-width: 92%; padding: 9px 10px; border-radius: 9px; white-space: pre-wrap; font-size: 12px; line-height: 1.5; }
199
+ :host .dos-assistant-message.user { align-self: flex-end; background: var(--dos-bg-3); color: var(--dos-text-0); }
200
+ :host .dos-assistant-message.agent { align-self: flex-start; background: var(--dos-green-glow); color: var(--dos-text-0); border: 1px solid rgba(34, 197, 94, 0.14); }
201
+ :host .dos-assistant-input { padding: 10px; border-top: 1px solid var(--dos-border) !important; display: flex; flex-direction: column; gap: 8px; }
202
+ :host .dos-assistant-input textarea { min-height: 72px; resize: vertical; }
203
+ :host .dos-design-drawer { position: absolute; top: 56px; right: 0; bottom: 0; z-index: 7; width: min(360px, 100%); display: flex; flex-direction: column; color: var(--dos-text-0) !important; background: var(--dos-bg-1) !important; border-left: 1px solid var(--dos-border) !important; box-shadow: -10px 0 30px rgba(0, 0, 0, 0.24); transform: translateX(100%); transition: transform 180ms ease; pointer-events: none; }
204
+ :host .dos-design-drawer.is-open { transform: translateX(0); pointer-events: auto; }
205
+ :host .dos-design-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--dos-border) !important; }
206
+ :host .dos-design-header > div { display: flex; flex-direction: column; gap: 2px; }
207
+ :host .dos-design-header strong { font-size: 13px; }
208
+ :host .dos-design-header span { color: var(--dos-text-2); font-size: 10px; }
209
+ :host .dos-design-header button { min-height: 28px; width: 28px; padding: 0 !important; font-size: 18px !important; line-height: 1; }
210
+ :host .dos-design-content { flex: 1; overflow: auto; padding: 16px; }
211
+ :host .dos-design-footer { padding: 12px 16px; border-top: 1px solid var(--dos-border) !important; display: flex; flex-direction: column; gap: 8px; }
212
+ :host .dos-design-footer [role="status"] { color: var(--dos-text-1) !important; font-size: 11px; }
213
+ :host .dos-kit-design-panel { display: flex; flex-direction: column; gap: 16px; }
214
+ :host .dos-kit-design-panel h3 { margin: 0 0 8px; color: var(--dos-text-1); font-size: 10px; letter-spacing: 0.07em; text-transform: uppercase; }
215
+ :host .dos-kit-design-presets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
216
+ :host .dos-kit-design-presets button { min-height: 34px; padding: 7px 9px !important; text-align: left; }
217
+ :host .dos-kit-design-group { min-width: 0; margin: 0; padding: 10px; border: 1px solid var(--dos-border) !important; border-radius: 9px; }
218
+ :host .dos-kit-design-group legend { padding: 0 5px; color: var(--dos-text-1); font-size: 10px; font-weight: 700; }
219
+ :host .dos-kit-design-token { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 7px 0; color: var(--dos-text-1); }
220
+ :host .dos-kit-design-token > span { min-width: 0; flex: 1 1 auto; }
221
+ :host .dos-kit-design-token small { display: block; margin-top: 3px; color: var(--dos-text-2); font-size: 10px; line-height: 1.4; }
222
+ :host .dos-kit-design-token select, :host .dos-kit-design-number-control { width: 52%; flex: 0 0 52%; }
223
+ :host .dos-kit-design-color-control { width: 52%; display: flex; flex: 0 0 52%; align-items: center; gap: 6px; }
224
+ :host .dos-kit-design-color-control input[type="color"] { flex: 0 0 38px; }
225
+ :host .dos-kit-design-color-control input[type="text"] { min-width: 0; }
226
+ :host .dos-kit-design-number-control { display: flex; align-items: center; gap: 6px; }
227
+ :host .dos-kit-design-number-control input { min-width: 0; }
228
+ :host .dos-kit-design-number-control > span { color: var(--dos-text-2); font-size: 10px; }
229
+ :host .dos-history-drawer { position: absolute; top: 56px; right: 0; bottom: 0; z-index: 5; width: min(340px, 100%); display: flex; flex-direction: column; color: var(--dos-text-0) !important; background: var(--dos-bg-1) !important; border-left: 1px solid var(--dos-border) !important; box-shadow: -10px 0 30px rgba(0, 0, 0, 0.22); transform: translateX(100%); transition: transform 180ms ease; pointer-events: none; }
230
+ :host .dos-history-drawer.is-open { transform: translateX(0); pointer-events: auto; }
231
+ :host .dos-history-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--dos-border) !important; }
232
+ :host .dos-history-header > div { display: flex; align-items: baseline; gap: 8px; }
233
+ :host .dos-history-header strong { font-size: 13px; }
234
+ :host .dos-history-header span { color: var(--dos-text-2); font-size: 10px; }
235
+ :host .dos-history-header button { min-height: 28px; width: 28px; padding: 0 !important; font-size: 18px !important; line-height: 1; }
236
+ :host .dos-history-list { flex: 1; overflow: auto; padding: 8px; }
237
+ :host .dos-history-entry { display: block; width: 100%; margin-bottom: 3px; padding: 11px 12px !important; text-align: left; border: 1px solid transparent !important; border-radius: 8px !important; color: var(--dos-text-1) !important; background: transparent !important; }
238
+ :host .dos-history-entry:hover:not(:disabled) { background: var(--dos-bg-3) !important; border-color: var(--dos-border) !important; }
239
+ :host .dos-history-current { color: var(--dos-text-0) !important; background: var(--dos-green-glow) !important; }
240
+ :host .dos-history-entry-meta, :host .dos-history-current > div:first-child { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; color: var(--dos-text-2); font-size: 10px; }
241
+ :host .dos-history-entry-meta + span, :host .dos-history-current > div:last-child { font-size: 12px; }
242
+ :host .dos-history-badge { display: inline-flex; padding: 2px 6px; border-radius: 999px; color: var(--dos-green) !important; background: rgba(34, 197, 94, 0.1) !important; font-size: 9px !important; font-weight: 700; }
243
+ :host .dos-history-empty { padding: 18px 8px; color: var(--dos-text-2); text-align: center; font-size: 11px; }
244
+ :host ::-webkit-scrollbar { width: 6px; height: 6px; }
245
+ :host ::-webkit-scrollbar-track { background: transparent; }
246
+ :host ::-webkit-scrollbar-thumb { background: #27272a; border-radius: 4px; }
247
+ :host ::-webkit-scrollbar-thumb:hover { background: #3a3a3f; }
248
+ :host button:focus-visible, :host a:focus-visible, :host input:focus-visible, :host select:focus-visible, :host textarea:focus-visible { outline: 2px solid var(--dos-green) !important; outline-offset: 2px; }
249
+ /* The light palette is scoped to editor chrome. The authored page remains inside CanvasFrame's separate iframe. */
250
+ :host([data-designos-appearance="light"]) .dos-toolbar,
251
+ :host([data-designos-appearance="light"]) .dos-sidebar,
252
+ :host([data-designos-appearance="light"]) .dos-inspector,
253
+ :host([data-designos-appearance="light"]) .dos-mobile-nav,
254
+ :host([data-designos-appearance="light"]) .dos-json-drawer,
255
+ :host([data-designos-appearance="light"]) .dos-assistant-drawer,
256
+ :host([data-designos-appearance="light"]) .dos-design-drawer,
257
+ :host([data-designos-appearance="light"]) .dos-history-drawer {
258
+ --dos-bg-0: #f8fafc;
259
+ --dos-bg-1: #ffffff;
260
+ --dos-bg-2: #f8fafc;
261
+ --dos-bg-3: #f1f5f9;
262
+ --dos-bg-4: #e2e8f0;
263
+ --dos-border: #d7dee8;
264
+ --dos-border-hover: #b9c5d6;
265
+ --dos-text-0: #111827;
266
+ --dos-text-1: #475569;
267
+ --dos-text-2: #64748b;
268
+ --dos-green: #15803d;
269
+ --dos-green-glow: rgba(21, 128, 61, 0.12);
270
+ color-scheme: light;
271
+ }
272
+ :host([data-designos-appearance="light"]) .dos-toolbar {
273
+ color: #111827 !important;
274
+ background: #ffffff !important;
275
+ border-color: #d7dee8 !important;
276
+ box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
277
+ }
278
+ :host([data-designos-appearance="light"]) .dos-toolbar-group {
279
+ background: #f8fafc !important;
280
+ border-color: #d7dee8 !important;
281
+ }
282
+ :host([data-designos-appearance="light"]) .dos-sidebar,
283
+ :host([data-designos-appearance="light"]) .dos-inspector {
284
+ background: #ffffff !important;
285
+ }
286
+ :host([data-designos-appearance="light"]) .dos-sidebar-tabs,
287
+ :host([data-designos-appearance="light"]) .dos-inspector-head,
288
+ :host([data-designos-appearance="light"]) .dos-mobile-nav {
289
+ background: #ffffff !important;
290
+ }
291
+ :host([data-designos-appearance="light"]) .dos-canvas-page {
292
+ background: radial-gradient(ellipse at 50% 0%, rgba(39, 39, 42, 0.58), transparent 68%), #09090b;
293
+ }
294
+ :host([data-designos-appearance="light"]) .dos-main {
295
+ background: radial-gradient(ellipse at 50% 0%, rgba(226, 232, 240, 0.9), transparent 68%), #f1f5f9 !important;
296
+ }
297
+ :host([data-designos-appearance="light"]) .dos-toolbar button[aria-pressed="true"],
298
+ :host([data-designos-appearance="light"]) .dos-mobile-nav button[aria-pressed="true"],
299
+ :host([data-designos-appearance="light"]) .dos-sidebar .dos-layer-row.is-selected {
300
+ color: #14532d !important;
301
+ }
302
+ :host([data-designos-appearance="light"]) .dos-json-body textarea,
303
+ :host([data-designos-appearance="light"]) .dos-json-body pre {
304
+ color: #111827 !important;
305
+ background: #f8fafc !important;
306
+ }
307
+ :host([data-designos-appearance="light"]) .dos-json-error,
308
+ :host([data-designos-appearance="light"]) [role="alert"] {
309
+ color: #991b1b !important;
310
+ background: #fef2f2 !important;
311
+ border-color: #fecaca !important;
312
+ }
313
+ :host([data-designos-appearance="light"]) .dos-publish-feedback.is-success { color: #166534 !important; }
314
+ :host([data-designos-appearance="light"]) .dos-publish-feedback.is-error { color: #b91c1c !important; }
315
+ :host([data-designos-appearance="light"]) .dos-sidebar::-webkit-scrollbar-thumb,
316
+ :host([data-designos-appearance="light"]) .dos-inspector::-webkit-scrollbar-thumb,
317
+ :host([data-designos-appearance="light"]) .dos-sidebar-content::-webkit-scrollbar-thumb,
318
+ :host([data-designos-appearance="light"]) .dos-history-list::-webkit-scrollbar-thumb,
319
+ :host([data-designos-appearance="light"]) .dos-json-body textarea::-webkit-scrollbar-thumb { background: #cbd5e1; }
320
+ @media (max-width: 1180px) {
321
+ :host .dos-toolbar { gap: 10px; padding: 0 10px !important; }
322
+ :host .dos-toolbar-actions { gap: 5px; }
323
+ :host .dos-toolbar-button { padding: 0 7px !important; }
324
+ :host .dos-toolbar-label { display: none; }
325
+ :host .dos-sidebar { flex-basis: 240px; }
326
+ :host .dos-inspector { flex-basis: 285px; }
327
+ }
328
+ @media (max-width: 900px) {
329
+ :host .dos-toolbar { position: sticky; height: auto !important; min-height: 108px !important; flex-direction: column; align-items: stretch; justify-content: center; gap: 5px; padding: 7px 10px !important; }
330
+ :host .dos-toolbar-brand { min-height: 28px; }
331
+ :host .dos-toolbar-actions { width: 100%; min-width: 0; flex: 0 0 auto; justify-content: flex-start; gap: 6px; margin-left: 0 !important; overflow-x: auto; overflow-y: hidden; flex-wrap: nowrap; scrollbar-width: none; }
332
+ :host .dos-toolbar-actions::-webkit-scrollbar { display: none; }
333
+ :host .dos-toolbar-group { flex: 0 0 auto; }
334
+ :host .dos-toolbar-button { width: 40px; min-width: 40px; height: 40px; min-height: 40px; padding: 0 !important; }
335
+ :host .dos-publish-wrap { flex: 0 0 auto; }
336
+ :host .dos-publish-button { width: 40px; min-width: 40px; height: 40px; min-height: 40px; padding: 0 !important; }
337
+ :host .dos-publish-feedback, :host .dos-publish-link { display: none; }
338
+ :host .dos-editor-layout { height: calc(100dvh - 172px - env(safe-area-inset-bottom)) !important; min-height: min(240px, calc(100dvh - 172px - env(safe-area-inset-bottom))); overflow: hidden; }
339
+ :host .dos-sidebar, :host .dos-inspector, :host main.dos-main { display: none; width: 100% !important; height: 100% !important; min-height: 0 !important; max-height: none !important; flex: 1 1 100% !important; border: 0 !important; }
340
+ :host .dos-editor-layout[data-mobile-panel="structure"] .dos-sidebar { display: flex; }
341
+ :host .dos-editor-layout[data-mobile-panel="canvas"] main.dos-main { display: block; }
342
+ :host .dos-editor-layout[data-mobile-panel="properties"] .dos-inspector { display: flex; }
343
+ :host .dos-mobile-nav { display: flex; }
344
+ :host .dos-canvas-viewport { min-height: 100%; padding: 12px; }
345
+ :host .dos-assistant-drawer, :host .dos-design-drawer, :host .dos-history-drawer { top: 108px; bottom: calc(66px + env(safe-area-inset-bottom)); width: 100%; border-left: 0 !important; border-radius: 16px 16px 0 0; }
346
+ }
347
+ @media (max-width: 480px) {
348
+ :host .dos-toolbar-brand strong { font-size: 12px; }
349
+ :host .dos-toolbar-actions { gap: 4px; }
350
+ :host .dos-toolbar-group { padding: 2px; }
351
+ :host .dos-toolbar-button { width: 40px; min-width: 40px; }
352
+ :host .dos-mobile-nav { padding-left: 6px; padding-right: 6px; }
353
+ :host .dos-sidebar-tabs button { min-height: 42px; }
354
+ }
355
+ `;
356
+ function EditorStyleBoundary({ children, appearance = "dark" }) {
357
+ const [shadowRoot, setShadowRoot] = useState2(null);
358
+ const attachShadowRoot = useCallback2((host) => {
359
+ if (!host) return;
360
+ const root = host.shadowRoot ?? host.attachShadow({ mode: "open" });
361
+ if (!root.querySelector("style[data-designos-editor-baseline]")) {
362
+ const style = host.ownerDocument.createElement("style");
363
+ style.dataset.designosEditorBaseline = "true";
364
+ style.textContent = EDITOR_BASE_STYLES;
365
+ root.appendChild(style);
366
+ }
367
+ setShadowRoot(root);
368
+ }, []);
369
+ return /* @__PURE__ */ jsx("div", { ref: attachShadowRoot, "data-designos-editor-host": "true", "data-designos-appearance": appearance, children: shadowRoot ? createPortal(children, shadowRoot) : null });
370
+ }
371
+
372
+ // src/store/editor-store.ts
373
+ import { create } from "zustand";
374
+ import {
375
+ createPage,
376
+ addNode,
377
+ removeNode,
378
+ updateNode,
379
+ moveNode,
380
+ reorderNode,
381
+ duplicateNode,
382
+ findNode,
383
+ cloneNode
384
+ } from "@designos/core";
385
+ var createEmptyPage = () => createPage("Untitled Page");
386
+ var clonePage = (page) => structuredClone(page);
387
+ function createHistoryEntry(page, label, source = "manual") {
388
+ const random = typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
389
+ return { id: `history-${random}`, page: clonePage(page), label, source, timestamp: Date.now() };
390
+ }
391
+ function previousState(state, label, source = "manual") {
392
+ return {
393
+ past: [...state.past, createHistoryEntry(state.page, label, source)],
394
+ future: [],
395
+ canUndo: true,
396
+ canRedo: false
397
+ };
398
+ }
399
+ var useEditorStore = create((set) => ({
400
+ page: createEmptyPage(),
401
+ selectedNodeId: void 0,
402
+ viewport: "desktop",
403
+ jsonDrawerOpen: false,
404
+ historyOpen: false,
405
+ assistantOpen: false,
406
+ designOpen: false,
407
+ previewMode: false,
408
+ past: [],
409
+ future: [],
410
+ canUndo: false,
411
+ canRedo: false,
412
+ copiedNode: null,
413
+ setPage: (page, options = {}) => set((state) => options.recordHistory === false ? { page } : { page, ...previousState(state, options.label ?? "Set page") }),
414
+ applyPageState: (page, options = {}) => {
415
+ const label = options.label ?? "Agent: Updated page";
416
+ const random = typeof crypto !== "undefined" && typeof crypto.randomUUID === "function" ? crypto.randomUUID() : `${Date.now()}-${Math.random().toString(36).slice(2)}`;
417
+ const versionId = `history-${random}`;
418
+ set((state) => ({
419
+ page: clonePage(page),
420
+ past: [...state.past, { id: versionId, page: clonePage(state.page), label, source: options.source ?? "agent", timestamp: Date.now() }],
421
+ future: [],
422
+ canUndo: true,
423
+ canRedo: false
424
+ }));
425
+ return {
426
+ status: "applied",
427
+ versionId,
428
+ summary: label,
429
+ changes: options.changes ?? [],
430
+ diagnostics: []
431
+ };
432
+ },
433
+ setViewport: (viewport) => set({ viewport }),
434
+ toggleJsonDrawer: () => set((state) => ({ jsonDrawerOpen: !state.jsonDrawerOpen, historyOpen: false, assistantOpen: false, designOpen: false })),
435
+ toggleHistory: () => set((state) => ({ historyOpen: !state.historyOpen, jsonDrawerOpen: false, assistantOpen: false, designOpen: false })),
436
+ toggleAssistant: () => set((state) => ({ assistantOpen: !state.assistantOpen, jsonDrawerOpen: false, historyOpen: false, designOpen: false })),
437
+ toggleDesign: () => set((state) => ({ designOpen: !state.designOpen, jsonDrawerOpen: false, historyOpen: false, assistantOpen: false })),
438
+ togglePreview: () => set((state) => ({ previewMode: !state.previewMode, selectedNodeId: void 0, jsonDrawerOpen: false, historyOpen: false, assistantOpen: false, designOpen: false })),
439
+ replaceHistory: (entries) => set({ past: entries, future: [], canUndo: entries.length > 0, canRedo: false }),
440
+ jumpToHistory: (entryId) => set((state) => {
441
+ const index = state.past.findIndex((entry) => entry.id === entryId);
442
+ if (index < 0) return state;
443
+ const selected = state.past[index];
444
+ return {
445
+ page: clonePage(selected.page),
446
+ past: state.past.slice(0, index),
447
+ future: [createHistoryEntry(state.page, "Restored current state", "restore"), ...state.future],
448
+ canUndo: index > 0,
449
+ canRedo: true
450
+ };
451
+ }),
452
+ selectNode: (nodeId) => set({ selectedNodeId: nodeId }),
453
+ addNode: (parentId, node, slotName) => set((state) => ({
454
+ page: { ...state.page, root: addNode(state.page.root, parentId, node, slotName) },
455
+ ...previousState(state, "Added component")
456
+ })),
457
+ removeNode: (nodeId) => set((state) => ({
458
+ page: { ...state.page, root: removeNode(state.page.root, nodeId) },
459
+ selectedNodeId: state.selectedNodeId === nodeId ? void 0 : state.selectedNodeId,
460
+ ...previousState(state, "Removed component")
461
+ })),
462
+ updateNodeProps: (nodeId, props) => set((state) => ({
463
+ page: {
464
+ ...state.page,
465
+ root: updateNode(state.page.root, nodeId, (node) => ({ ...node, props: { ...node.props, ...props } }))
466
+ },
467
+ ...previousState(state, "Updated properties")
468
+ })),
469
+ moveNode: (nodeId, destinationId, slotName) => set((state) => ({
470
+ page: { ...state.page, root: moveNode(state.page.root, nodeId, destinationId, slotName) },
471
+ ...previousState(state, "Moved component")
472
+ })),
473
+ reorderNode: (parentId, sourceIndex, targetIndex, slotName) => set((state) => ({
474
+ page: { ...state.page, root: reorderNode(state.page.root, parentId, sourceIndex, targetIndex, slotName) },
475
+ ...previousState(state, "Reordered component")
476
+ })),
477
+ duplicateNode: (nodeId) => set((state) => ({
478
+ page: { ...state.page, root: duplicateNode(state.page.root, nodeId) },
479
+ ...previousState(state, "Duplicated component")
480
+ })),
481
+ copySelectedNode: () => set((state) => {
482
+ if (!state.selectedNodeId) return state;
483
+ const found = findNode(state.page.root, state.selectedNodeId);
484
+ return found ? { copiedNode: cloneNode(found.node) } : state;
485
+ }),
486
+ pasteNode: () => set((state) => {
487
+ if (!state.copiedNode) return state;
488
+ const pasted = cloneNode(state.copiedNode);
489
+ return {
490
+ page: { ...state.page, root: addNode(state.page.root, "root", pasted) },
491
+ ...previousState(state, "Pasted component")
492
+ };
493
+ }),
494
+ undo: () => set((state) => {
495
+ if (state.past.length === 0) return state;
496
+ const previous = state.past[state.past.length - 1];
497
+ return {
498
+ page: clonePage(previous.page),
499
+ past: state.past.slice(0, -1),
500
+ future: [createHistoryEntry(state.page, previous.label, "restore"), ...state.future],
501
+ canUndo: state.past.length > 1,
502
+ canRedo: true
503
+ };
504
+ }),
505
+ redo: () => set((state) => {
506
+ if (state.future.length === 0) return state;
507
+ const next = state.future[0];
508
+ return {
509
+ page: clonePage(next.page),
510
+ future: state.future.slice(1),
511
+ past: [...state.past, createHistoryEntry(state.page, next.label, "restore")],
512
+ canUndo: true,
513
+ canRedo: state.future.length > 1
514
+ };
515
+ }),
516
+ reset: () => set({
517
+ page: createEmptyPage(),
518
+ selectedNodeId: void 0,
519
+ viewport: "desktop",
520
+ jsonDrawerOpen: false,
521
+ historyOpen: false,
522
+ assistantOpen: false,
523
+ designOpen: false,
524
+ previewMode: false,
525
+ past: [],
526
+ future: [],
527
+ canUndo: false,
528
+ canRedo: false
529
+ })
530
+ }));
531
+
532
+ // src/hooks/useKeyboardShortcuts.ts
533
+ import { useEffect as useEffect2 } from "react";
534
+
535
+ // src/utils/preview-frame-registry.ts
536
+ var previewDocuments = /* @__PURE__ */ new Set();
537
+ var listeners = /* @__PURE__ */ new Set();
538
+ function registerPreviewFrameDocument(document2) {
539
+ if (previewDocuments.has(document2)) return () => void 0;
540
+ previewDocuments.add(document2);
541
+ listeners.forEach((listener) => listener(document2, true));
542
+ return () => {
543
+ if (!previewDocuments.delete(document2)) return;
544
+ listeners.forEach((listener) => listener(document2, false));
545
+ };
546
+ }
547
+ function subscribeToPreviewFrameDocuments(listener) {
548
+ listeners.add(listener);
549
+ previewDocuments.forEach((document2) => listener(document2, true));
550
+ return () => listeners.delete(listener);
551
+ }
552
+
553
+ // src/hooks/useKeyboardShortcuts.ts
554
+ function useKeyboardShortcuts(enabled = true) {
555
+ const undo = useEditorStore((state) => state.undo);
556
+ const redo = useEditorStore((state) => state.redo);
557
+ const selectedNodeId = useEditorStore((state) => state.selectedNodeId);
558
+ const removeNode2 = useEditorStore((state) => state.removeNode);
559
+ const selectNode = useEditorStore((state) => state.selectNode);
560
+ const toggleJsonDrawer = useEditorStore((state) => state.toggleJsonDrawer);
561
+ const copySelectedNode = useEditorStore((state) => state.copySelectedNode);
562
+ const pasteNode = useEditorStore((state) => state.pasteNode);
563
+ useEffect2(() => {
564
+ if (!enabled) return;
565
+ const handleKeyDown = (event) => {
566
+ const target = event.target;
567
+ const tagName = target?.tagName?.toLowerCase();
568
+ const editingText = tagName === "input" || tagName === "textarea" || Boolean(target?.isContentEditable);
569
+ if (editingText) return;
570
+ const mod = event.ctrlKey || event.metaKey;
571
+ const key = event.key.toLowerCase();
572
+ const isUndo = mod && key === "z" && !event.shiftKey;
573
+ const isRedo = mod && key === "z" && event.shiftKey || event.ctrlKey && key === "y";
574
+ if (isUndo) {
575
+ event.preventDefault();
576
+ undo();
577
+ return;
578
+ }
579
+ if (isRedo) {
580
+ event.preventDefault();
581
+ redo();
582
+ return;
583
+ }
584
+ if (mod && key === "c") {
585
+ event.preventDefault();
586
+ copySelectedNode();
587
+ return;
588
+ }
589
+ if (mod && key === "v") {
590
+ event.preventDefault();
591
+ pasteNode();
592
+ return;
593
+ }
594
+ if (event.key === "Delete" && selectedNodeId) {
595
+ event.preventDefault();
596
+ removeNode2(selectedNodeId);
597
+ return;
598
+ }
599
+ if (event.key === "Escape") {
600
+ selectNode(void 0);
601
+ return;
602
+ }
603
+ if (mod && key === "j") {
604
+ event.preventDefault();
605
+ toggleJsonDrawer();
606
+ }
607
+ };
608
+ const attachedWindows = /* @__PURE__ */ new Set();
609
+ const attach = (targetWindow, active) => {
610
+ if (active && !attachedWindows.has(targetWindow)) {
611
+ targetWindow.addEventListener("keydown", handleKeyDown);
612
+ attachedWindows.add(targetWindow);
613
+ } else if (!active && attachedWindows.delete(targetWindow)) {
614
+ targetWindow.removeEventListener("keydown", handleKeyDown);
615
+ }
616
+ };
617
+ attach(window, true);
618
+ const unsubscribe = subscribeToPreviewFrameDocuments((previewDocument, active) => {
619
+ const previewWindow = previewDocument.defaultView;
620
+ if (previewWindow) attach(previewWindow, active);
621
+ });
622
+ return () => {
623
+ unsubscribe();
624
+ attachedWindows.forEach((targetWindow) => targetWindow.removeEventListener("keydown", handleKeyDown));
625
+ attachedWindows.clear();
626
+ };
627
+ }, [
628
+ enabled,
629
+ undo,
630
+ redo,
631
+ removeNode2,
632
+ selectedNodeId,
633
+ selectNode,
634
+ toggleJsonDrawer,
635
+ copySelectedNode,
636
+ pasteNode
637
+ ]);
638
+ }
639
+
640
+ // src/hooks/useAutosave.ts
641
+ import { useEffect as useEffect3, useRef } from "react";
642
+
643
+ // src/utils/storage.ts
644
+ import { PAGE_SCHEMA_VERSION, validatePage, validatePageAgainstRegistry } from "@designos/core";
645
+ var STORAGE_KEY2 = "designos-page";
646
+ function savePage(page, registry, storageKey = STORAGE_KEY2) {
647
+ if (page.version !== PAGE_SCHEMA_VERSION) {
648
+ console.error(`Refusing to save page schema ${page.version}; expected current schema ${PAGE_SCHEMA_VERSION}`);
649
+ return false;
650
+ }
651
+ const validation = validatePage(page);
652
+ const registryIssues = registry ? validatePageAgainstRegistry(page.root, registry) : [];
653
+ if (!validation.valid || registryIssues.length) {
654
+ console.error("Refusing to save an invalid page; existing stored data was preserved", [...validation.issues, ...registryIssues]);
655
+ return false;
656
+ }
657
+ try {
658
+ localStorage.setItem(storageKey, JSON.stringify(page));
659
+ return true;
660
+ } catch (error) {
661
+ console.error("Failed to save page", error);
662
+ return false;
663
+ }
664
+ }
665
+ function loadPage(storageKey = STORAGE_KEY2) {
666
+ let raw;
667
+ try {
668
+ raw = localStorage.getItem(storageKey);
669
+ } catch (error) {
670
+ throw new Error("Unable to read saved page storage", { cause: error });
671
+ }
672
+ if (!raw) return null;
673
+ let value;
674
+ try {
675
+ value = JSON.parse(raw);
676
+ } catch (error) {
677
+ throw new Error("Saved page contains invalid JSON; original content was preserved", { cause: error });
678
+ }
679
+ const validation = validatePage(value);
680
+ if (!validation.valid) {
681
+ const details = validation.issues.map((issue) => `${issue.path || "page"}: ${issue.message}`).join("; ");
682
+ throw new Error(`Saved page failed structural validation; original content was preserved: ${details}`);
683
+ }
684
+ return value;
685
+ }
686
+ function downloadSavedPage(storageKey = STORAGE_KEY2) {
687
+ const raw = localStorage.getItem(storageKey);
688
+ if (!raw) return false;
689
+ const blob = new Blob([raw], { type: "application/json" });
690
+ const url = URL.createObjectURL(blob);
691
+ const anchor = document.createElement("a");
692
+ anchor.href = url;
693
+ anchor.download = "designos-saved-page-recovery.json";
694
+ anchor.click();
695
+ URL.revokeObjectURL(url);
696
+ return true;
697
+ }
698
+ function clearPage(storageKey = STORAGE_KEY2) {
699
+ try {
700
+ localStorage.removeItem(storageKey);
701
+ } catch (error) {
702
+ console.error("Failed to clear page", error);
703
+ }
704
+ }
705
+
706
+ // src/hooks/useAutosave.ts
707
+ function useAutosave(enabled = true, registry, storageKey) {
708
+ const page = useEditorStore((state) => state.page);
709
+ const skipInitialWrite = useRef(true);
710
+ useEffect3(() => {
711
+ if (!enabled) return;
712
+ if (skipInitialWrite.current) {
713
+ skipInitialWrite.current = false;
714
+ return;
715
+ }
716
+ savePage(page, registry, storageKey);
717
+ }, [enabled, page, registry, storageKey]);
718
+ }
719
+
720
+ // src/hooks/useRestorePage.ts
721
+ import { useCallback as useCallback3, useEffect as useEffect4, useState as useState3 } from "react";
722
+ import { migratePageDocument, validatePageAgainstRegistry as validatePageAgainstRegistry2 } from "@designos/core";
723
+ function useRestorePage(registry, storageKey) {
724
+ const setPage = useEditorStore((state) => state.setPage);
725
+ const reset = useEditorStore((state) => state.reset);
726
+ const [status, setStatus] = useState3("loading");
727
+ useEffect4(() => {
728
+ try {
729
+ const stored = loadPage(storageKey);
730
+ if (!stored) {
731
+ setStatus("ready");
732
+ return;
733
+ }
734
+ const migrated = migratePageDocument(stored, registry);
735
+ const registryIssues = validatePageAgainstRegistry2(migrated.root, registry);
736
+ if (registryIssues.length) {
737
+ const details = registryIssues.map((issue) => `${issue.path || "page"}: ${issue.message}`).join("; ");
738
+ throw new Error(`Saved page is incompatible with the active component registry: ${details}`);
739
+ }
740
+ if (migrated.version !== stored.version && !savePage(migrated, registry, storageKey)) {
741
+ throw new Error("Migrated page passed validation but could not be persisted; autosave remains disabled to preserve the original document");
742
+ }
743
+ setPage(migrated, { recordHistory: false });
744
+ setStatus("ready");
745
+ } catch (error) {
746
+ console.error("Failed to restore saved page; preserving the original stored data and disabling autosave", error);
747
+ setStatus("blocked");
748
+ }
749
+ }, [registry, setPage, storageKey]);
750
+ const startFreshAfterDiscardingSavedData = useCallback3(() => {
751
+ clearPage(storageKey);
752
+ reset();
753
+ setStatus("ready");
754
+ }, [reset, storageKey]);
755
+ return { status, startFreshAfterDiscardingSavedData };
756
+ }
757
+
758
+ // src/components/dnd/DndProvider.tsx
759
+ import { createContext, useCallback as useCallback4, useContext, useRef as useRef2, useState as useState4 } from "react";
760
+ import {
761
+ DndContext,
762
+ KeyboardSensor,
763
+ PointerSensor,
764
+ rectIntersection,
765
+ useSensor,
766
+ useSensors
767
+ } from "@dnd-kit/core";
768
+ import { jsx as jsx2 } from "react/jsx-runtime";
769
+ var PreviewPointerEventsContext = createContext(false);
770
+ function useDisablePreviewPointerEvents() {
771
+ return useContext(PreviewPointerEventsContext);
772
+ }
773
+ function EditorDndProvider({ children, onDragEnd }) {
774
+ const sensors = useSensors(
775
+ useSensor(PointerSensor, { activationConstraint: { distance: 6 } }),
776
+ useSensor(KeyboardSensor)
777
+ );
778
+ const [disablePreviewPointerEvents, setDisablePreviewPointerEvents] = useState4(false);
779
+ const dragOriginDocument = useRef2(null);
780
+ const collisionDetection = useCallback4((args) => {
781
+ const originDocument = dragOriginDocument.current;
782
+ const hostDocument = originDocument?.defaultView?.frameElement?.ownerDocument ?? originDocument;
783
+ const startedInHost = Boolean(originDocument && hostDocument === originDocument);
784
+ if (!startedInHost) return rectIntersection(args);
785
+ const droppableRects = new Map(args.droppableRects);
786
+ for (const container of args.droppableContainers) {
787
+ const element = container.node.current;
788
+ const rect = droppableRects.get(container.id);
789
+ if (!element || !rect || element.ownerDocument === hostDocument) continue;
790
+ const frame = element.ownerDocument.defaultView?.frameElement;
791
+ if (!frame) continue;
792
+ const frameRect = frame.getBoundingClientRect();
793
+ droppableRects.set(container.id, {
794
+ ...rect,
795
+ top: rect.top + frameRect.top,
796
+ bottom: rect.bottom + frameRect.top,
797
+ left: rect.left + frameRect.left,
798
+ right: rect.right + frameRect.left
799
+ });
800
+ }
801
+ return rectIntersection({ ...args, droppableRects });
802
+ }, []);
803
+ const handleDragStart = (event) => {
804
+ const eventTarget = event.activatorEvent.target;
805
+ const originDocument = eventTarget?.ownerDocument ?? document;
806
+ dragOriginDocument.current = originDocument;
807
+ setDisablePreviewPointerEvents(!originDocument.defaultView?.frameElement);
808
+ };
809
+ const handleDragEnd = (event) => {
810
+ dragOriginDocument.current = null;
811
+ setDisablePreviewPointerEvents(false);
812
+ onDragEnd(event);
813
+ };
814
+ const handleDragCancel = () => {
815
+ dragOriginDocument.current = null;
816
+ setDisablePreviewPointerEvents(false);
817
+ };
818
+ return /* @__PURE__ */ jsx2(
819
+ DndContext,
820
+ {
821
+ sensors,
822
+ collisionDetection,
823
+ onDragStart: handleDragStart,
824
+ onDragEnd: handleDragEnd,
825
+ onDragCancel: handleDragCancel,
826
+ children: /* @__PURE__ */ jsx2(PreviewPointerEventsContext.Provider, { value: disablePreviewPointerEvents, children })
827
+ }
828
+ );
829
+ }
830
+
831
+ // src/components/dnd/validate-slot-drop.ts
832
+ import { findNode as findNode2 } from "@designos/core";
833
+ function getSlotDropError(root, registry, parentId, slotName, childType, source) {
834
+ const parent = findNode2(root, parentId)?.node;
835
+ const slot = parent && registry.get(parent.type)?.slots?.find((item) => item.name === slotName);
836
+ if (!parent) return "The drop target no longer exists.";
837
+ if (!slot) return `Region '${slotName}' is not declared by '${parent.type}'.`;
838
+ if (slot.allowedComponents && !slot.allowedComponents.includes(childType)) return `'${childType}' is not allowed in ${slot.label}.`;
839
+ if (slot.disallowedComponents?.includes(childType)) return `'${childType}' is disallowed in ${slot.label}.`;
840
+ const sameSlot = source?.parentId === parentId && source.slotName === slotName;
841
+ const targetCount = (parent.slots?.[slotName] ?? []).length - (sameSlot ? 1 : 0);
842
+ if (slot.maxChildren !== void 0 && targetCount + 1 > slot.maxChildren) return `${slot.label} allows at most ${slot.maxChildren} child(ren).`;
843
+ if (source?.slotName && !sameSlot) {
844
+ const sourceParent = findNode2(root, source.parentId)?.node;
845
+ const sourceSlot = sourceParent && registry.get(sourceParent.type)?.slots?.find((item) => item.name === source.slotName);
846
+ const sourceCount = sourceParent?.slots?.[source.slotName]?.length ?? 0;
847
+ if (sourceSlot?.minChildren !== void 0 && sourceCount - 1 < sourceSlot.minChildren) {
848
+ return `${sourceSlot.label} requires at least ${sourceSlot.minChildren} child(ren).`;
849
+ }
850
+ }
851
+ return void 0;
852
+ }
853
+ function getSourceSlotRemovalError(root, registry, source) {
854
+ if (!source.slotName) return void 0;
855
+ const parent = findNode2(root, source.parentId)?.node;
856
+ const slot = parent && registry.get(parent.type)?.slots?.find((item) => item.name === source.slotName);
857
+ const count = parent?.slots?.[source.slotName]?.length ?? 0;
858
+ return slot?.minChildren !== void 0 && count - 1 < slot.minChildren ? `${slot.label} requires at least ${slot.minChildren} child(ren).` : void 0;
859
+ }
860
+
861
+ // src/components/EditorIcon.tsx
862
+ import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
863
+ var shapes = {
864
+ layers: /* @__PURE__ */ jsxs(Fragment, { children: [
865
+ /* @__PURE__ */ jsx3("path", { d: "m12 3 9 5-9 5-9-5 9-5Z" }),
866
+ /* @__PURE__ */ jsx3("path", { d: "m3 12 9 5 9-5M3 16l9 5 9-5" })
867
+ ] }),
868
+ blocks: /* @__PURE__ */ jsxs(Fragment, { children: [
869
+ /* @__PURE__ */ jsx3("rect", { x: "3", y: "3", width: "8", height: "8", rx: "1.5" }),
870
+ /* @__PURE__ */ jsx3("rect", { x: "13", y: "3", width: "8", height: "5", rx: "1.5" }),
871
+ /* @__PURE__ */ jsx3("rect", { x: "13", y: "10", width: "8", height: "11", rx: "1.5" }),
872
+ /* @__PURE__ */ jsx3("rect", { x: "3", y: "13", width: "8", height: "8", rx: "1.5" })
873
+ ] }),
874
+ canvas: /* @__PURE__ */ jsxs(Fragment, { children: [
875
+ /* @__PURE__ */ jsx3("rect", { x: "3", y: "4", width: "18", height: "14", rx: "2" }),
876
+ /* @__PURE__ */ jsx3("path", { d: "M8 21h8m-4-3v3M7 8h10M7 11h6" })
877
+ ] }),
878
+ properties: /* @__PURE__ */ jsxs(Fragment, { children: [
879
+ /* @__PURE__ */ jsx3("path", { d: "M4 7h9m4 0h3M4 17h3m4 0h9" }),
880
+ /* @__PURE__ */ jsx3("circle", { cx: "15", cy: "7", r: "2" }),
881
+ /* @__PURE__ */ jsx3("circle", { cx: "9", cy: "17", r: "2" })
882
+ ] }),
883
+ preview: /* @__PURE__ */ jsxs(Fragment, { children: [
884
+ /* @__PURE__ */ jsx3("path", { d: "M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12Z" }),
885
+ /* @__PURE__ */ jsx3("circle", { cx: "12", cy: "12", r: "3" })
886
+ ] }),
887
+ exitPreview: /* @__PURE__ */ jsxs(Fragment, { children: [
888
+ /* @__PURE__ */ jsx3("path", { d: "m3 3 18 18M10.6 5.2A10.8 10.8 0 0 1 12 5c6.5 0 10 7 10 7a16 16 0 0 1-3.2 3.9M6.2 6.2C3.5 8 2 12 2 12s3.5 7 10 7a10 10 0 0 0 4-.8" }),
889
+ /* @__PURE__ */ jsx3("path", { d: "M9.9 9.9a3 3 0 0 0 4.2 4.2" })
890
+ ] }),
891
+ design: /* @__PURE__ */ jsxs(Fragment, { children: [
892
+ /* @__PURE__ */ jsx3("path", { d: "M12 3a9 9 0 1 0 0 18h1.2a2 2 0 0 0 1.4-3.4 1.8 1.8 0 0 1 1.3-3.1H18a3 3 0 0 0 3-3c0-4.7-4-8.5-9-8.5Z" }),
893
+ /* @__PURE__ */ jsx3("circle", { cx: "7.5", cy: "11", r: "1" }),
894
+ /* @__PURE__ */ jsx3("circle", { cx: "10", cy: "7.5", r: "1" }),
895
+ /* @__PURE__ */ jsx3("circle", { cx: "15", cy: "8", r: "1" })
896
+ ] }),
897
+ desktop: /* @__PURE__ */ jsxs(Fragment, { children: [
898
+ /* @__PURE__ */ jsx3("rect", { x: "3", y: "4", width: "18", height: "13", rx: "2" }),
899
+ /* @__PURE__ */ jsx3("path", { d: "M8 21h8m-4-4v4" })
900
+ ] }),
901
+ tablet: /* @__PURE__ */ jsxs(Fragment, { children: [
902
+ /* @__PURE__ */ jsx3("rect", { x: "5", y: "2", width: "14", height: "20", rx: "2" }),
903
+ /* @__PURE__ */ jsx3("path", { d: "M11 18h2" })
904
+ ] }),
905
+ mobile: /* @__PURE__ */ jsxs(Fragment, { children: [
906
+ /* @__PURE__ */ jsx3("rect", { x: "7", y: "2", width: "10", height: "20", rx: "2" }),
907
+ /* @__PURE__ */ jsx3("path", { d: "M11 18h2" })
908
+ ] }),
909
+ undo: /* @__PURE__ */ jsxs(Fragment, { children: [
910
+ /* @__PURE__ */ jsx3("path", { d: "M9 14 4 9l5-5" }),
911
+ /* @__PURE__ */ jsx3("path", { d: "M4 9h10a6 6 0 0 1 0 12h-2" })
912
+ ] }),
913
+ redo: /* @__PURE__ */ jsxs(Fragment, { children: [
914
+ /* @__PURE__ */ jsx3("path", { d: "m15 14 5-5-5-5" }),
915
+ /* @__PURE__ */ jsx3("path", { d: "M20 9H10a6 6 0 0 0 0 12h2" })
916
+ ] }),
917
+ json: /* @__PURE__ */ jsx3(Fragment, { children: /* @__PURE__ */ jsx3("path", { d: "M8 4H6a2 2 0 0 0-2 2v3a3 3 0 0 1-2 3 3 3 0 0 1 2 3v3a2 2 0 0 0 2 2h2M16 4h2a2 2 0 0 1 2 2v3a3 3 0 0 0 2 3 3 3 0 0 0-2 3v3a2 2 0 0 1-2 2h-2M13 7l-2 10" }) }),
918
+ assistant: /* @__PURE__ */ jsxs(Fragment, { children: [
919
+ /* @__PURE__ */ jsx3("path", { d: "m12 3 1.7 5.3L19 10l-5.3 1.7L12 17l-1.7-5.3L5 10l5.3-1.7L12 3Z" }),
920
+ /* @__PURE__ */ jsx3("path", { d: "m19 14 .9 2.1L22 17l-2.1.9L19 20l-.9-2.1L16 17l2.1-.9L19 14ZM5 3l.7 1.3L7 5l-1.3.7L5 7l-.7-1.3L3 5l1.3-.7L5 3Z" })
921
+ ] }),
922
+ history: /* @__PURE__ */ jsxs(Fragment, { children: [
923
+ /* @__PURE__ */ jsx3("path", { d: "M3 12a9 9 0 1 0 2.6-6.4L3 8" }),
924
+ /* @__PURE__ */ jsx3("path", { d: "M3 3v5h5m4-1v5l3 2" })
925
+ ] }),
926
+ publish: /* @__PURE__ */ jsxs(Fragment, { children: [
927
+ /* @__PURE__ */ jsx3("path", { d: "M12 16V4m-5 5 5-5 5 5" }),
928
+ /* @__PURE__ */ jsx3("path", { d: "M4 15v4a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-4" })
929
+ ] }),
930
+ sun: /* @__PURE__ */ jsxs(Fragment, { children: [
931
+ /* @__PURE__ */ jsx3("circle", { cx: "12", cy: "12", r: "4" }),
932
+ /* @__PURE__ */ jsx3("path", { d: "M12 2v2m0 16v2M4.93 4.93l1.42 1.42m11.3 11.3 1.42 1.42M2 12h2m16 0h2M4.93 19.07l1.42-1.42m11.3-11.3 1.42-1.42" })
933
+ ] }),
934
+ moon: /* @__PURE__ */ jsx3("path", { d: "M20.8 14.2A8.6 8.6 0 0 1 9.8 3.2 8.9 8.9 0 1 0 20.8 14.2Z" })
935
+ };
936
+ function EditorIcon({ name, size = 16 }) {
937
+ return /* @__PURE__ */ jsx3("svg", { "aria-hidden": "true", width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round", children: shapes[name] });
938
+ }
939
+
940
+ // src/components/toolbar/PublishButton.tsx
941
+ import { useEffect as useEffect5, useRef as useRef3, useState as useState5 } from "react";
942
+ import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
943
+ function safePublishedUrl(url) {
944
+ if (!url || typeof window === "undefined") return void 0;
945
+ try {
946
+ const parsed = new URL(url, window.location.href);
947
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return void 0;
948
+ if (url.startsWith("//")) return void 0;
949
+ return url;
950
+ } catch {
951
+ return void 0;
952
+ }
953
+ }
954
+ function PublishButton({ publisher, pageId, expectedRevision }) {
955
+ const [isPublishing, setIsPublishing] = useState5(false);
956
+ const [revision, setRevision] = useState5(expectedRevision);
957
+ const [feedback, setFeedback] = useState5(null);
958
+ const sequence = useRef3(0);
959
+ const activeRequest = useRef3(null);
960
+ const pageIdRef = useRef3(pageId);
961
+ pageIdRef.current = pageId;
962
+ useEffect5(() => {
963
+ sequence.current += 1;
964
+ activeRequest.current = null;
965
+ setIsPublishing(false);
966
+ setRevision(expectedRevision);
967
+ setFeedback(null);
968
+ }, [pageId, expectedRevision]);
969
+ async function handlePublish() {
970
+ if (activeRequest.current !== null) return;
971
+ const requestId = ++sequence.current;
972
+ const requestPageId = pageId;
973
+ activeRequest.current = requestId;
974
+ setIsPublishing(true);
975
+ setFeedback(null);
976
+ const page = structuredClone(useEditorStore.getState().page);
977
+ const pageSnapshot = JSON.stringify(page);
978
+ try {
979
+ const result = await publisher.publish({
980
+ page,
981
+ pageId: requestPageId,
982
+ expectedRevision: revision
983
+ });
984
+ if (activeRequest.current !== requestId || pageIdRef.current !== requestPageId) return;
985
+ if (!result || typeof result.revision !== "string" || !result.revision.trim()) {
986
+ throw new Error("The publisher did not return a valid revision.");
987
+ }
988
+ setRevision(result.revision);
989
+ const pageChangedDuringPublish = JSON.stringify(useEditorStore.getState().page) !== pageSnapshot;
990
+ setFeedback({
991
+ kind: "success",
992
+ message: pageChangedDuringPublish ? "Page published; newer edits remain unpublished." : "Page published.",
993
+ url: safePublishedUrl(result.url)
994
+ });
995
+ } catch (cause) {
996
+ if (activeRequest.current !== requestId || pageIdRef.current !== requestPageId) return;
997
+ setFeedback({
998
+ kind: "error",
999
+ message: `Page publish failed: ${cause instanceof Error ? cause.message : String(cause)}`
1000
+ });
1001
+ } finally {
1002
+ if (activeRequest.current === requestId) {
1003
+ activeRequest.current = null;
1004
+ setIsPublishing(false);
1005
+ }
1006
+ }
1007
+ }
1008
+ return /* @__PURE__ */ jsxs2("div", { className: "dos-publish-wrap", children: [
1009
+ /* @__PURE__ */ jsxs2(
1010
+ "button",
1011
+ {
1012
+ type: "button",
1013
+ className: "dos-primary-button dos-publish-button",
1014
+ onClick: () => void handlePublish(),
1015
+ disabled: isPublishing,
1016
+ "aria-busy": isPublishing,
1017
+ "aria-label": isPublishing ? "Publishing page\u2026" : "Publish Page",
1018
+ children: [
1019
+ /* @__PURE__ */ jsx4(EditorIcon, { name: "publish" }),
1020
+ /* @__PURE__ */ jsx4("span", { className: "dos-toolbar-label", children: isPublishing ? "Publishing page\u2026" : "Publish Page" })
1021
+ ]
1022
+ }
1023
+ ),
1024
+ feedback && /* @__PURE__ */ jsx4(
1025
+ "span",
1026
+ {
1027
+ role: feedback.kind === "error" ? "alert" : "status",
1028
+ "aria-live": feedback.kind === "error" ? "assertive" : "polite",
1029
+ title: feedback.message,
1030
+ className: `dos-publish-feedback is-${feedback.kind}`,
1031
+ children: feedback.message
1032
+ }
1033
+ ),
1034
+ feedback?.url && /* @__PURE__ */ jsx4("a", { className: "dos-publish-link", href: feedback.url, target: "_blank", rel: "noopener noreferrer", children: "View page" })
1035
+ ] });
1036
+ }
1037
+
1038
+ // src/components/toolbar/Toolbar.tsx
1039
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
1040
+ function Toolbar({ title = "DesignOS", publisher, pageId, expectedRevision, agent, hasDesign = false, appearance = "dark", onToggleAppearance = () => {
1041
+ } }) {
1042
+ const viewport = useEditorStore((state) => state.viewport);
1043
+ const setViewport = useEditorStore((state) => state.setViewport);
1044
+ const toggleJsonDrawer = useEditorStore((state) => state.toggleJsonDrawer);
1045
+ const jsonDrawerOpen = useEditorStore((state) => state.jsonDrawerOpen);
1046
+ const toggleHistory = useEditorStore((state) => state.toggleHistory);
1047
+ const historyOpen = useEditorStore((state) => state.historyOpen);
1048
+ const toggleAssistant = useEditorStore((state) => state.toggleAssistant);
1049
+ const assistantOpen = useEditorStore((state) => state.assistantOpen);
1050
+ const previewMode = useEditorStore((state) => state.previewMode);
1051
+ const togglePreview = useEditorStore((state) => state.togglePreview);
1052
+ const designOpen = useEditorStore((state) => state.designOpen);
1053
+ const toggleDesign = useEditorStore((state) => state.toggleDesign);
1054
+ const undo = useEditorStore((state) => state.undo);
1055
+ const redo = useEditorStore((state) => state.redo);
1056
+ const canUndo = useEditorStore((state) => state.canUndo);
1057
+ const canRedo = useEditorStore((state) => state.canRedo);
1058
+ const buttonClass = (active = false) => `dos-toolbar-button${active ? " is-active" : ""}`;
1059
+ return /* @__PURE__ */ jsxs3("header", { className: "dos-toolbar", children: [
1060
+ /* @__PURE__ */ jsxs3("div", { className: "dos-toolbar-brand", children: [
1061
+ /* @__PURE__ */ jsx5("span", { className: "dos-brand-mark", children: /* @__PURE__ */ jsx5(EditorIcon, { name: "design", size: 17 }) }),
1062
+ /* @__PURE__ */ jsx5("strong", { children: title })
1063
+ ] }),
1064
+ /* @__PURE__ */ jsxs3("div", { className: "dos-toolbar-actions", "aria-label": "Editor actions", children: [
1065
+ /* @__PURE__ */ jsxs3("div", { className: "dos-toolbar-group", children: [
1066
+ /* @__PURE__ */ jsxs3("button", { type: "button", className: buttonClass(previewMode), "aria-pressed": previewMode, "aria-label": previewMode ? "Exit preview" : "Preview page", title: previewMode ? "Exit preview" : "Preview page", onClick: togglePreview, children: [
1067
+ /* @__PURE__ */ jsx5(EditorIcon, { name: previewMode ? "exitPreview" : "preview" }),
1068
+ /* @__PURE__ */ jsx5("span", { className: "dos-toolbar-label", children: previewMode ? "Exit preview" : "Preview" })
1069
+ ] }),
1070
+ /* @__PURE__ */ jsxs3("button", { type: "button", className: buttonClass(appearance === "light"), "aria-pressed": appearance === "light", "aria-label": appearance === "dark" ? "Switch to light mode" : "Switch to dark mode", title: appearance === "dark" ? "Light editor" : "Dark editor", onClick: onToggleAppearance, children: [
1071
+ /* @__PURE__ */ jsx5(EditorIcon, { name: appearance === "dark" ? "sun" : "moon" }),
1072
+ /* @__PURE__ */ jsx5("span", { className: "dos-toolbar-label", children: appearance === "dark" ? "Light" : "Dark" })
1073
+ ] }),
1074
+ !previewMode && hasDesign && /* @__PURE__ */ jsxs3("button", { type: "button", className: buttonClass(designOpen), "aria-label": "Design", "aria-pressed": designOpen, title: "Site design", onClick: toggleDesign, children: [
1075
+ /* @__PURE__ */ jsx5(EditorIcon, { name: "design" }),
1076
+ /* @__PURE__ */ jsx5("span", { className: "dos-toolbar-label", children: "Design" })
1077
+ ] })
1078
+ ] }),
1079
+ !previewMode && /* @__PURE__ */ jsxs3(Fragment2, { children: [
1080
+ /* @__PURE__ */ jsxs3("div", { className: "dos-toolbar-group dos-viewport-group", role: "group", "aria-label": "Preview viewport", children: [
1081
+ /* @__PURE__ */ jsxs3("button", { type: "button", className: buttonClass(viewport === "desktop"), "aria-pressed": viewport === "desktop", "aria-label": "Desktop viewport", title: "Desktop viewport", onClick: () => setViewport("desktop"), children: [
1082
+ /* @__PURE__ */ jsx5(EditorIcon, { name: "desktop" }),
1083
+ /* @__PURE__ */ jsx5("span", { className: "dos-toolbar-label", children: "Desktop" })
1084
+ ] }),
1085
+ /* @__PURE__ */ jsxs3("button", { type: "button", className: buttonClass(viewport === "tablet"), "aria-pressed": viewport === "tablet", "aria-label": "Tablet viewport", title: "Tablet viewport", onClick: () => setViewport("tablet"), children: [
1086
+ /* @__PURE__ */ jsx5(EditorIcon, { name: "tablet" }),
1087
+ /* @__PURE__ */ jsx5("span", { className: "dos-toolbar-label", children: "Tablet" })
1088
+ ] }),
1089
+ /* @__PURE__ */ jsxs3("button", { type: "button", className: buttonClass(viewport === "mobile"), "aria-pressed": viewport === "mobile", "aria-label": "Mobile viewport", title: "Mobile viewport", onClick: () => setViewport("mobile"), children: [
1090
+ /* @__PURE__ */ jsx5(EditorIcon, { name: "mobile" }),
1091
+ /* @__PURE__ */ jsx5("span", { className: "dos-toolbar-label", children: "Mobile" })
1092
+ ] })
1093
+ ] }),
1094
+ /* @__PURE__ */ jsxs3("div", { className: "dos-toolbar-group", children: [
1095
+ /* @__PURE__ */ jsxs3("button", { type: "button", className: buttonClass(), "aria-label": "Undo", title: "Undo", onClick: undo, disabled: !canUndo, children: [
1096
+ /* @__PURE__ */ jsx5(EditorIcon, { name: "undo" }),
1097
+ /* @__PURE__ */ jsx5("span", { className: "dos-toolbar-label", children: "Undo" })
1098
+ ] }),
1099
+ /* @__PURE__ */ jsxs3("button", { type: "button", className: buttonClass(), "aria-label": "Redo", title: "Redo", onClick: redo, disabled: !canRedo, children: [
1100
+ /* @__PURE__ */ jsx5(EditorIcon, { name: "redo" }),
1101
+ /* @__PURE__ */ jsx5("span", { className: "dos-toolbar-label", children: "Redo" })
1102
+ ] })
1103
+ ] }),
1104
+ /* @__PURE__ */ jsxs3("div", { className: "dos-toolbar-group", children: [
1105
+ /* @__PURE__ */ jsxs3("button", { type: "button", className: buttonClass(jsonDrawerOpen), "aria-label": "Page JSON", "aria-pressed": jsonDrawerOpen, title: "Page JSON", onClick: toggleJsonDrawer, children: [
1106
+ /* @__PURE__ */ jsx5(EditorIcon, { name: "json" }),
1107
+ /* @__PURE__ */ jsx5("span", { className: "dos-toolbar-label", children: "JSON" })
1108
+ ] }),
1109
+ agent && /* @__PURE__ */ jsxs3("button", { type: "button", className: buttonClass(assistantOpen), "aria-label": "Assistant", "aria-pressed": assistantOpen, title: "Assistant", onClick: toggleAssistant, children: [
1110
+ /* @__PURE__ */ jsx5(EditorIcon, { name: "assistant" }),
1111
+ /* @__PURE__ */ jsx5("span", { className: "dos-toolbar-label", children: "Assistant" })
1112
+ ] }),
1113
+ /* @__PURE__ */ jsxs3("button", { type: "button", className: buttonClass(historyOpen), "aria-label": "Version history", "aria-pressed": historyOpen, title: "Version history", onClick: toggleHistory, children: [
1114
+ /* @__PURE__ */ jsx5(EditorIcon, { name: "history" }),
1115
+ /* @__PURE__ */ jsx5("span", { className: "dos-toolbar-label", children: "History" })
1116
+ ] })
1117
+ ] }),
1118
+ publisher && pageId && /* @__PURE__ */ jsx5(PublishButton, { publisher, pageId, expectedRevision })
1119
+ ] })
1120
+ ] })
1121
+ ] });
1122
+ }
1123
+
1124
+ // src/components/layout/Sidebar.tsx
1125
+ import { useState as useState6 } from "react";
1126
+ import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
1127
+ function Sidebar({ components, layers }) {
1128
+ const [tab, setTab] = useState6("layers");
1129
+ return /* @__PURE__ */ jsxs4("aside", { className: "dos-sidebar", "aria-label": "Structure panel", children: [
1130
+ /* @__PURE__ */ jsxs4("div", { className: "dos-sidebar-tabs", role: "tablist", "aria-label": "Structure tools", children: [
1131
+ /* @__PURE__ */ jsxs4("button", { type: "button", role: "tab", "aria-selected": tab === "layers", "aria-pressed": tab === "layers", onClick: () => setTab("layers"), children: [
1132
+ /* @__PURE__ */ jsx6(EditorIcon, { name: "layers" }),
1133
+ /* @__PURE__ */ jsx6("span", { children: "Layers" })
1134
+ ] }),
1135
+ /* @__PURE__ */ jsxs4("button", { type: "button", role: "tab", "aria-selected": tab === "components", "aria-pressed": tab === "components", onClick: () => setTab("components"), children: [
1136
+ /* @__PURE__ */ jsx6(EditorIcon, { name: "blocks" }),
1137
+ /* @__PURE__ */ jsx6("span", { children: "Components" })
1138
+ ] })
1139
+ ] }),
1140
+ /* @__PURE__ */ jsx6("div", { className: "dos-sidebar-content", children: tab === "layers" ? layers : components })
1141
+ ] });
1142
+ }
1143
+
1144
+ // src/components/layout/MainPanel.tsx
1145
+ import { jsx as jsx7 } from "react/jsx-runtime";
1146
+ function MainPanel({ children }) {
1147
+ return /* @__PURE__ */ jsx7("main", { className: "dos-main", children });
1148
+ }
1149
+
1150
+ // src/components/layout/InspectorPanel.tsx
1151
+ import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
1152
+ function InspectorPanel({ children }) {
1153
+ return /* @__PURE__ */ jsxs5("aside", { className: "dos-inspector", "aria-label": "Properties panel", children: [
1154
+ /* @__PURE__ */ jsxs5("div", { className: "dos-inspector-head", children: [
1155
+ /* @__PURE__ */ jsx8("strong", { children: "Properties" }),
1156
+ /* @__PURE__ */ jsx8("span", { children: "Selected element" })
1157
+ ] }),
1158
+ /* @__PURE__ */ jsx8("div", { className: "dos-inspector-content", children })
1159
+ ] });
1160
+ }
1161
+
1162
+ // src/components/layout/EditorLayout.tsx
1163
+ import { jsxs as jsxs6 } from "react/jsx-runtime";
1164
+ function EditorLayout({ sidebar, canvas, inspector, mobilePanel }) {
1165
+ return /* @__PURE__ */ jsxs6("div", { className: "dos-editor-layout", "data-mobile-panel": mobilePanel, children: [
1166
+ sidebar,
1167
+ canvas,
1168
+ inspector
1169
+ ] });
1170
+ }
1171
+
1172
+ // src/components/sidebar/ComponentLibrary.tsx
1173
+ import { useMemo, useState as useState7 } from "react";
1174
+
1175
+ // src/components/sidebar/ComponentItem.tsx
1176
+ import { useDraggable } from "@dnd-kit/core";
1177
+ import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
1178
+ function ComponentItem({ manifest, onAdd }) {
1179
+ const { attributes, listeners: listeners2, setNodeRef, transform, isDragging } = useDraggable({
1180
+ id: `component:${manifest.type}`,
1181
+ data: { kind: "component", componentType: manifest.type }
1182
+ });
1183
+ return /* @__PURE__ */ jsxs7(
1184
+ "button",
1185
+ {
1186
+ ref: setNodeRef,
1187
+ className: "dos-component-item",
1188
+ ...attributes,
1189
+ ...listeners2,
1190
+ onClick: onAdd,
1191
+ style: {
1192
+ width: "100%",
1193
+ textAlign: "left",
1194
+ padding: 12,
1195
+ marginBottom: 8,
1196
+ border: "1px solid #e5e7eb",
1197
+ borderRadius: 6,
1198
+ background: "#ffffff",
1199
+ cursor: isDragging ? "grabbing" : "grab",
1200
+ transform: transform ? `translate3d(${transform.x}px, ${transform.y}px, 0)` : void 0,
1201
+ opacity: isDragging ? 0.6 : 1
1202
+ },
1203
+ children: [
1204
+ /* @__PURE__ */ jsx9("div", { children: manifest.displayName }),
1205
+ manifest.category && /* @__PURE__ */ jsx9("small", { children: manifest.category })
1206
+ ]
1207
+ }
1208
+ );
1209
+ }
1210
+
1211
+ // src/components/sidebar/ComponentLibrary.tsx
1212
+ import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
1213
+ function ComponentLibrary({
1214
+ registry,
1215
+ onAdd
1216
+ }) {
1217
+ const [search, setSearch] = useState7("");
1218
+ const manifests = registry.getAll();
1219
+ const filtered = useMemo(
1220
+ () => manifests.filter(
1221
+ (manifest) => manifest.displayName.toLowerCase().includes(
1222
+ search.toLowerCase()
1223
+ ) || manifest.category?.toLowerCase().includes(
1224
+ search.toLowerCase()
1225
+ )
1226
+ ),
1227
+ [
1228
+ manifests,
1229
+ search
1230
+ ]
1231
+ );
1232
+ const grouped = useMemo(
1233
+ () => filtered.reduce(
1234
+ (groups, manifest) => {
1235
+ const category = manifest.category ?? "General";
1236
+ if (!groups[category]) {
1237
+ groups[category] = [];
1238
+ }
1239
+ groups[category].push(
1240
+ manifest
1241
+ );
1242
+ return groups;
1243
+ },
1244
+ {}
1245
+ ),
1246
+ [filtered]
1247
+ );
1248
+ return /* @__PURE__ */ jsxs8(
1249
+ "div",
1250
+ {
1251
+ className: "dos-component-library",
1252
+ style: {
1253
+ display: "flex",
1254
+ flexDirection: "column",
1255
+ height: "100%"
1256
+ },
1257
+ children: [
1258
+ /* @__PURE__ */ jsxs8(
1259
+ "div",
1260
+ {
1261
+ className: "dos-component-header",
1262
+ style: {
1263
+ padding: 16,
1264
+ borderBottom: "1px solid #e5e7eb"
1265
+ },
1266
+ children: [
1267
+ /* @__PURE__ */ jsx10(
1268
+ "h3",
1269
+ {
1270
+ style: {
1271
+ marginTop: 0,
1272
+ marginBottom: 12
1273
+ },
1274
+ children: "Components"
1275
+ }
1276
+ ),
1277
+ /* @__PURE__ */ jsx10(
1278
+ "input",
1279
+ {
1280
+ className: "dos-component-search",
1281
+ type: "text",
1282
+ placeholder: "Search components...",
1283
+ value: search,
1284
+ onChange: (e) => setSearch(
1285
+ e.target.value
1286
+ ),
1287
+ style: {
1288
+ width: "100%",
1289
+ padding: "8px 12px",
1290
+ border: "1px solid #d1d5db",
1291
+ borderRadius: 6
1292
+ }
1293
+ }
1294
+ )
1295
+ ]
1296
+ }
1297
+ ),
1298
+ /* @__PURE__ */ jsxs8(
1299
+ "div",
1300
+ {
1301
+ style: {
1302
+ flex: 1,
1303
+ overflow: "auto",
1304
+ padding: 16
1305
+ },
1306
+ children: [
1307
+ Object.entries(
1308
+ grouped
1309
+ ).map(
1310
+ ([
1311
+ category,
1312
+ items
1313
+ ]) => /* @__PURE__ */ jsxs8(
1314
+ "div",
1315
+ {
1316
+ style: {
1317
+ marginBottom: 24
1318
+ },
1319
+ children: [
1320
+ /* @__PURE__ */ jsx10(
1321
+ "div",
1322
+ {
1323
+ className: "dos-component-category",
1324
+ style: {
1325
+ fontSize: 12,
1326
+ fontWeight: 700,
1327
+ textTransform: "uppercase",
1328
+ color: "#6b7280",
1329
+ marginBottom: 8
1330
+ },
1331
+ children: category
1332
+ }
1333
+ ),
1334
+ items.map(
1335
+ (manifest) => /* @__PURE__ */ jsx10(
1336
+ ComponentItem,
1337
+ {
1338
+ manifest,
1339
+ onAdd: () => onAdd(
1340
+ manifest.type
1341
+ )
1342
+ },
1343
+ manifest.type
1344
+ )
1345
+ )
1346
+ ]
1347
+ },
1348
+ category
1349
+ )
1350
+ ),
1351
+ filtered.length === 0 && /* @__PURE__ */ jsx10(
1352
+ "div",
1353
+ {
1354
+ style: {
1355
+ color: "#6b7280",
1356
+ fontSize: 14
1357
+ },
1358
+ children: "No matching components"
1359
+ }
1360
+ )
1361
+ ]
1362
+ }
1363
+ )
1364
+ ]
1365
+ }
1366
+ );
1367
+ }
1368
+
1369
+ // src/components/sidebar/LayersPanel.tsx
1370
+ import { SortableContext, verticalListSortingStrategy } from "@dnd-kit/sortable";
1371
+
1372
+ // src/components/sidebar/SortableLayerNode.tsx
1373
+ import { CSS } from "@dnd-kit/utilities";
1374
+ import { useSortable } from "@dnd-kit/sortable";
1375
+
1376
+ // src/components/dnd/SlotDropTarget.tsx
1377
+ import { useDroppable } from "@dnd-kit/core";
1378
+ import { jsxs as jsxs9 } from "react/jsx-runtime";
1379
+ function slotDropId(parentId, slotName) {
1380
+ return `slot:${encodeURIComponent(parentId)}:${encodeURIComponent(slotName)}`;
1381
+ }
1382
+ function SlotDropTarget({ parentId, slotName, label, count, compact = false }) {
1383
+ const { setNodeRef, isOver } = useDroppable({
1384
+ id: slotDropId(parentId, slotName),
1385
+ data: { kind: "slot", parentId, slotName }
1386
+ });
1387
+ return /* @__PURE__ */ jsxs9(
1388
+ "div",
1389
+ {
1390
+ ref: setNodeRef,
1391
+ "aria-label": `Drop into ${label}`,
1392
+ "data-designos-slot": slotName,
1393
+ style: {
1394
+ margin: compact ? "4px 0" : "8px 0 12px",
1395
+ padding: compact ? "5px 8px" : "9px 12px",
1396
+ border: `1px dashed ${isOver ? "#4f46e5" : "#cbd5e1"}`,
1397
+ borderRadius: 6,
1398
+ background: isOver ? "#eef2ff" : "#f8fafc",
1399
+ color: "#64748b",
1400
+ fontSize: compact ? 11 : 12
1401
+ },
1402
+ children: [
1403
+ label,
1404
+ " \xB7 ",
1405
+ count,
1406
+ " ",
1407
+ count === 1 ? "item" : "items",
1408
+ " \xB7 drop here"
1409
+ ]
1410
+ }
1411
+ );
1412
+ }
1413
+
1414
+ // src/components/sidebar/LayerTreeNode.tsx
1415
+ import { useDraggable as useDraggable2 } from "@dnd-kit/core";
1416
+ import { Fragment as Fragment3, jsx as jsx11, jsxs as jsxs10 } from "react/jsx-runtime";
1417
+ function LayerTreeNode({ node, registry, depth = 0, parentId, slotName, index, siblingCount }) {
1418
+ const { attributes, listeners: listeners2, setNodeRef } = useDraggable2({
1419
+ id: `layer:${node.id}`,
1420
+ data: { kind: "node", nodeId: node.id, parentId, slotName, index }
1421
+ });
1422
+ const page = useEditorStore((state) => state.page);
1423
+ const selectedNodeId = useEditorStore((state) => state.selectedNodeId);
1424
+ const selectNode = useEditorStore((state) => state.selectNode);
1425
+ const duplicateNode2 = useEditorStore((state) => state.duplicateNode);
1426
+ const removeNode2 = useEditorStore((state) => state.removeNode);
1427
+ const reorderNode2 = useEditorStore((state) => state.reorderNode);
1428
+ const parent = parentId ? findNodeById(page.root, parentId) : void 0;
1429
+ const slot = parent && slotName ? registry.get(parent.type)?.slots?.find((item) => item.name === slotName) : void 0;
1430
+ const atSlotCapacity = slot?.maxChildren !== void 0 && (parent?.slots?.[slotName] ?? []).length >= slot.maxChildren;
1431
+ const atSlotMinimum = slot?.minChildren !== void 0 && (parent?.slots?.[slotName] ?? []).length <= slot.minChildren;
1432
+ const selected = selectedNodeId === node.id;
1433
+ return /* @__PURE__ */ jsxs10("div", { children: [
1434
+ /* @__PURE__ */ jsxs10(
1435
+ "div",
1436
+ {
1437
+ ref: setNodeRef,
1438
+ className: `dos-layer-row${selected ? " is-selected" : ""}`,
1439
+ onClick: () => selectNode(node.id),
1440
+ style: { display: "flex", alignItems: "center", gap: 6, padding: "6px 8px", paddingLeft: 12 + depth * 18, marginBottom: 2, borderRadius: 6, cursor: "grab", background: selected ? "#eef2ff" : "transparent" },
1441
+ children: [
1442
+ /* @__PURE__ */ jsx11("button", { type: "button", "aria-label": `Drag ${node.type}`, ...attributes, ...listeners2, onClick: (event) => event.stopPropagation(), children: "\u22EE\u22EE" }),
1443
+ /* @__PURE__ */ jsx11("span", { style: { flex: 1, fontSize: 13, overflow: "hidden", textOverflow: "ellipsis" }, children: node.meta?.label ?? node.type }),
1444
+ parentId && index !== void 0 && /* @__PURE__ */ jsxs10(Fragment3, { children: [
1445
+ /* @__PURE__ */ jsx11("button", { type: "button", "aria-label": `Move ${node.type} up`, disabled: index === 0, onClick: (event) => {
1446
+ event.stopPropagation();
1447
+ reorderNode2(parentId, index, index - 1, slotName);
1448
+ }, children: "\u2191" }),
1449
+ /* @__PURE__ */ jsx11("button", { type: "button", "aria-label": `Move ${node.type} down`, disabled: index === (siblingCount ?? 0) - 1, onClick: (event) => {
1450
+ event.stopPropagation();
1451
+ reorderNode2(parentId, index, index + 1, slotName);
1452
+ }, children: "\u2193" })
1453
+ ] }),
1454
+ /* @__PURE__ */ jsx11("button", { type: "button", title: "Duplicate", "aria-label": `Duplicate ${node.type}`, disabled: atSlotCapacity, onClick: (event) => {
1455
+ event.stopPropagation();
1456
+ duplicateNode2(node.id);
1457
+ }, children: "+" }),
1458
+ /* @__PURE__ */ jsx11("button", { type: "button", title: "Delete", "aria-label": `Delete ${node.type}`, disabled: atSlotMinimum, onClick: (event) => {
1459
+ event.stopPropagation();
1460
+ removeNode2(node.id);
1461
+ }, children: "\xD7" })
1462
+ ]
1463
+ }
1464
+ ),
1465
+ node.children.map((child, childIndex) => /* @__PURE__ */ jsx11(LayerTreeNode, { node: child, registry, depth: depth + 1, parentId: node.id, index: childIndex, siblingCount: node.children.length }, child.id)),
1466
+ [.../* @__PURE__ */ new Set([
1467
+ ...(registry.get(node.type)?.slots ?? []).map((item) => item.name),
1468
+ ...Object.keys(node.slots ?? {})
1469
+ ])].map((name) => {
1470
+ const children = node.slots?.[name] ?? [];
1471
+ const descriptor = registry.get(node.type)?.slots?.find((item) => item.name === name);
1472
+ const label = descriptor?.label ?? name;
1473
+ return /* @__PURE__ */ jsxs10("div", { children: [
1474
+ /* @__PURE__ */ jsx11(SlotDropTarget, { parentId: node.id, slotName: name, label, count: children.length, compact: true }),
1475
+ children.map((child, childIndex) => /* @__PURE__ */ jsx11(LayerTreeNode, { node: child, registry, depth: depth + 1, parentId: node.id, slotName: name, index: childIndex, siblingCount: children.length }, child.id))
1476
+ ] }, name);
1477
+ })
1478
+ ] });
1479
+ }
1480
+ function findNodeById(root, id) {
1481
+ if (root.id === id) return root;
1482
+ for (const child of root.children) {
1483
+ const found = findNodeById(child, id);
1484
+ if (found) return found;
1485
+ }
1486
+ for (const children of Object.values(root.slots ?? {})) {
1487
+ for (const child of children) {
1488
+ const found = findNodeById(child, id);
1489
+ if (found) return found;
1490
+ }
1491
+ }
1492
+ return void 0;
1493
+ }
1494
+
1495
+ // src/components/sidebar/SortableLayerNode.tsx
1496
+ import { jsx as jsx12, jsxs as jsxs11 } from "react/jsx-runtime";
1497
+ function SortableLayerNode({ node, registry, parentId, index }) {
1498
+ const { attributes, listeners: listeners2, setNodeRef, transform, transition } = useSortable({
1499
+ id: node.id,
1500
+ data: { kind: "node", nodeId: node.id, parentId, index }
1501
+ });
1502
+ const selectedNodeId = useEditorStore((state) => state.selectedNodeId);
1503
+ const selectNode = useEditorStore((state) => state.selectNode);
1504
+ const duplicateNode2 = useEditorStore((state) => state.duplicateNode);
1505
+ const removeNode2 = useEditorStore((state) => state.removeNode);
1506
+ return /* @__PURE__ */ jsxs11("div", { children: [
1507
+ /* @__PURE__ */ jsxs11(
1508
+ "div",
1509
+ {
1510
+ ref: setNodeRef,
1511
+ className: `dos-layer-row${selectedNodeId === node.id ? " is-selected" : ""}`,
1512
+ onClick: () => selectNode(node.id),
1513
+ style: { transform: CSS.Transform.toString(transform), transition, display: "flex", alignItems: "center", gap: 8, padding: 8, marginBottom: 4, borderRadius: 6, cursor: "grab", background: selectedNodeId === node.id ? "#eef2ff" : "#ffffff", border: "1px solid #e5e7eb" },
1514
+ children: [
1515
+ /* @__PURE__ */ jsx12("button", { type: "button", "aria-label": `Drag ${node.type}`, ...attributes, ...listeners2, onClick: (event) => event.stopPropagation(), children: "\u22EE\u22EE" }),
1516
+ /* @__PURE__ */ jsx12("div", { style: { flex: 1 }, children: node.meta?.label ?? node.type }),
1517
+ /* @__PURE__ */ jsx12("button", { type: "button", "aria-label": `Duplicate ${node.type}`, onClick: (event) => {
1518
+ event.stopPropagation();
1519
+ duplicateNode2(node.id);
1520
+ }, children: "+" }),
1521
+ /* @__PURE__ */ jsx12("button", { type: "button", "aria-label": `Delete ${node.type}`, onClick: (event) => {
1522
+ event.stopPropagation();
1523
+ removeNode2(node.id);
1524
+ }, children: "\xD7" })
1525
+ ]
1526
+ }
1527
+ ),
1528
+ node.children.map((child, childIndex) => /* @__PURE__ */ jsx12(LayerTreeNode, { node: child, registry, depth: 1, parentId: node.id, index: childIndex, siblingCount: node.children.length }, child.id)),
1529
+ [.../* @__PURE__ */ new Set([
1530
+ ...(registry.get(node.type)?.slots ?? []).map((slot) => slot.name),
1531
+ ...Object.keys(node.slots ?? {})
1532
+ ])].map((name) => {
1533
+ const children = node.slots?.[name] ?? [];
1534
+ const label = registry.get(node.type)?.slots?.find((slot) => slot.name === name)?.label ?? name;
1535
+ return /* @__PURE__ */ jsxs11("div", { children: [
1536
+ /* @__PURE__ */ jsx12(SlotDropTarget, { parentId: node.id, slotName: name, label, count: children.length, compact: true }),
1537
+ children.map((child, childIndex) => /* @__PURE__ */ jsx12(LayerTreeNode, { node: child, registry, depth: 1, parentId: node.id, slotName: name, index: childIndex, siblingCount: children.length }, child.id))
1538
+ ] }, name);
1539
+ })
1540
+ ] });
1541
+ }
1542
+
1543
+ // src/components/sidebar/LayersPanel.tsx
1544
+ import { jsx as jsx13, jsxs as jsxs12 } from "react/jsx-runtime";
1545
+ function LayersPanel({ registry }) {
1546
+ const page = useEditorStore((state) => state.page);
1547
+ const nodes = page.root.children;
1548
+ return /* @__PURE__ */ jsxs12("div", { className: "dos-layers-panel", style: { padding: 12 }, children: [
1549
+ /* @__PURE__ */ jsx13("h3", { children: "Layers" }),
1550
+ /* @__PURE__ */ jsx13(SortableContext, { items: nodes.map((node) => node.id), strategy: verticalListSortingStrategy, children: nodes.map((node, index) => /* @__PURE__ */ jsx13(SortableLayerNode, { node, registry, parentId: page.root.id, index }, node.id)) }),
1551
+ nodes.length === 0 && /* @__PURE__ */ jsx13("div", { children: "No layers" })
1552
+ ] });
1553
+ }
1554
+
1555
+ // src/components/canvas/CanvasDropZone.tsx
1556
+ import { useDroppable as useDroppable2 } from "@dnd-kit/core";
1557
+ import { jsx as jsx14 } from "react/jsx-runtime";
1558
+ function CanvasDropZone({ parentId, children, enabled = true }) {
1559
+ const { setNodeRef, isOver } = useDroppable2({
1560
+ id: `children:${encodeURIComponent(parentId)}`,
1561
+ data: { kind: "children", parentId },
1562
+ disabled: !enabled
1563
+ });
1564
+ return /* @__PURE__ */ jsx14(
1565
+ "div",
1566
+ {
1567
+ ref: setNodeRef,
1568
+ "aria-label": enabled ? "Drop into page" : void 0,
1569
+ style: { minHeight: 500, background: enabled && isOver ? "#eef2ff" : "transparent", transition: "background 120ms ease" },
1570
+ children
1571
+ }
1572
+ );
1573
+ }
1574
+
1575
+ // src/components/canvas/CanvasRoot.tsx
1576
+ import { jsx as jsx15 } from "react/jsx-runtime";
1577
+ function CanvasRoot({
1578
+ children
1579
+ }) {
1580
+ return /* @__PURE__ */ jsx15(
1581
+ "div",
1582
+ {
1583
+ style: {
1584
+ padding: 24,
1585
+ minHeight: "100%",
1586
+ background: "transparent"
1587
+ },
1588
+ children
1589
+ }
1590
+ );
1591
+ }
1592
+
1593
+ // src/components/canvas/SelectableNode.tsx
1594
+ import { Fragment as Fragment4, jsx as jsx16, jsxs as jsxs13 } from "react/jsx-runtime";
1595
+ function SelectableNode({
1596
+ selected,
1597
+ label,
1598
+ onSelect,
1599
+ children,
1600
+ preview = false
1601
+ }) {
1602
+ if (preview) return /* @__PURE__ */ jsx16(Fragment4, { children });
1603
+ return /* @__PURE__ */ jsxs13(
1604
+ "div",
1605
+ {
1606
+ onClick: (event) => {
1607
+ event.stopPropagation();
1608
+ onSelect();
1609
+ },
1610
+ style: {
1611
+ position: "relative",
1612
+ outline: selected ? "2px solid #3b82f6" : "2px solid transparent",
1613
+ borderRadius: 4,
1614
+ transition: "all 0.15s ease",
1615
+ cursor: "pointer"
1616
+ },
1617
+ children: [
1618
+ selected && /* @__PURE__ */ jsx16(
1619
+ "div",
1620
+ {
1621
+ style: {
1622
+ position: "absolute",
1623
+ top: -24,
1624
+ left: 0,
1625
+ zIndex: 100,
1626
+ padding: "2px 8px",
1627
+ background: "#2563eb",
1628
+ color: "#ffffff",
1629
+ fontSize: 11,
1630
+ fontWeight: 500,
1631
+ borderRadius: 4,
1632
+ whiteSpace: "nowrap",
1633
+ pointerEvents: "none"
1634
+ },
1635
+ children: label || "Selected"
1636
+ }
1637
+ ),
1638
+ children
1639
+ ]
1640
+ }
1641
+ );
1642
+ }
1643
+
1644
+ // src/components/canvas/CanvasNode.tsx
1645
+ import { jsx as jsx17, jsxs as jsxs14 } from "react/jsx-runtime";
1646
+ function CanvasNode({ node, registry, components, selectedNodeId, onSelect, preview = false }) {
1647
+ const Component = components[node.type];
1648
+ if (!Component) {
1649
+ return /* @__PURE__ */ jsxs14("div", { style: { padding: 12, border: "1px solid red", color: "red" }, children: [
1650
+ "Missing Component: ",
1651
+ node.type
1652
+ ] });
1653
+ }
1654
+ const declaredSlots = registry.get(node.type)?.slots ?? [];
1655
+ const slotNames = /* @__PURE__ */ new Set([...declaredSlots.map((slot) => slot.name), ...Object.keys(node.slots ?? {})]);
1656
+ const renderChildren = (nodes) => nodes.map((child) => /* @__PURE__ */ jsx17(
1657
+ CanvasNode,
1658
+ {
1659
+ node: child,
1660
+ registry,
1661
+ components,
1662
+ selectedNodeId,
1663
+ onSelect,
1664
+ preview
1665
+ },
1666
+ child.id
1667
+ ));
1668
+ const children = renderChildren(node.children);
1669
+ const slots = slotNames.size > 0 ? Object.fromEntries([...slotNames].map((name) => [name, renderChildren(node.slots?.[name] ?? [])])) : void 0;
1670
+ return /* @__PURE__ */ jsxs14(SelectableNode, { selected: selectedNodeId === node.id, label: node.type, onSelect: () => onSelect(node.id), preview, children: [
1671
+ /* @__PURE__ */ jsx17(Component, { ...node.props, ...slots ? { slots } : {}, children }),
1672
+ !preview && declaredSlots.map((slot) => /* @__PURE__ */ jsx17(
1673
+ SlotDropTarget,
1674
+ {
1675
+ parentId: node.id,
1676
+ slotName: slot.name,
1677
+ label: slot.label,
1678
+ count: node.slots?.[slot.name]?.length ?? 0
1679
+ },
1680
+ slot.name
1681
+ ))
1682
+ ] });
1683
+ }
1684
+
1685
+ // src/components/canvas/CanvasFrame.tsx
1686
+ import { useCallback as useCallback5, useEffect as useEffect6, useMemo as useMemo2, useRef as useRef4, useState as useState8 } from "react";
1687
+ import { createPortal as createPortal2 } from "react-dom";
1688
+ import { jsx as jsx18 } from "react/jsx-runtime";
1689
+ var FRAME_DOCUMENT = `<!doctype html><html><head><meta charset="utf-8"><style id="designos-frame-base">html,body{margin:0;min-width:0;min-height:100%;background:transparent;}#designos-canvas-root{min-height:100%;background:transparent;}</style><style id="designos-frame-scroll">html{height:100%!important;overflow-y:auto!important;}body{height:auto!important;min-height:100%!important;overflow:visible!important;}</style></head><body><div id="designos-canvas-root"></div></body></html>`;
1690
+ function copyDocumentAttributes(source, target) {
1691
+ for (const attribute of Array.from(target.attributes)) target.removeAttribute(attribute.name);
1692
+ for (const attribute of Array.from(source.attributes)) {
1693
+ if (/^on/i.test(attribute.name)) continue;
1694
+ target.setAttribute(attribute.name, attribute.value);
1695
+ }
1696
+ }
1697
+ function clearDocumentAttributes(target) {
1698
+ for (const attribute of Array.from(target.attributes)) target.removeAttribute(attribute.name);
1699
+ }
1700
+ function copyStylesheets(source, target, stylesheets, syncHostStyles) {
1701
+ const baseStyle = target.getElementById("designos-frame-base");
1702
+ if (!baseStyle || !target.head) return;
1703
+ target.head.querySelectorAll("[data-designos-host-style], [data-designos-preview-style]").forEach((element) => element.remove());
1704
+ const mirrored = syncHostStyles ? Array.from(source.querySelectorAll("style, link[rel~='stylesheet']")) : [];
1705
+ const copied = mirrored.map((element) => {
1706
+ const clone = target.importNode(element, true);
1707
+ clone.setAttribute("data-designos-host-style", "true");
1708
+ if (clone.tagName === "LINK") {
1709
+ clone.href = element.href;
1710
+ }
1711
+ return clone;
1712
+ });
1713
+ const explicit = stylesheets.map((href) => {
1714
+ const link = target.createElement("link");
1715
+ link.rel = "stylesheet";
1716
+ link.href = new URL(href, source.baseURI).href;
1717
+ link.setAttribute("data-designos-preview-style", "true");
1718
+ return link;
1719
+ });
1720
+ baseStyle.after(...copied, ...explicit);
1721
+ const scrollStyle = target.getElementById("designos-frame-scroll");
1722
+ if (scrollStyle) target.head.appendChild(scrollStyle);
1723
+ }
1724
+ function CanvasFrame({ children, syncHostStyles, stylesheets, previewStyles = "" }) {
1725
+ const frameRef = useRef4(null);
1726
+ const disablePointerEvents = useDisablePreviewPointerEvents();
1727
+ const [mountNode, setMountNode] = useState8(null);
1728
+ const handleLoad = useCallback5(() => {
1729
+ const document2 = frameRef.current?.contentDocument;
1730
+ const root = document2?.getElementById("designos-canvas-root");
1731
+ if (root) setMountNode(root);
1732
+ }, []);
1733
+ const stylesheetKey = stylesheets.join("\0");
1734
+ const stableStylesheets = useMemo2(() => stylesheetKey ? stylesheetKey.split("\0") : [], [stylesheetKey]);
1735
+ useEffect6(() => {
1736
+ if (!mountNode) return;
1737
+ return registerPreviewFrameDocument(mountNode.ownerDocument);
1738
+ }, [mountNode]);
1739
+ useEffect6(() => {
1740
+ if (!mountNode) return;
1741
+ const frameDocument = mountNode.ownerDocument;
1742
+ const hostDocument = document;
1743
+ const sync = () => {
1744
+ if (syncHostStyles) {
1745
+ copyDocumentAttributes(hostDocument.documentElement, frameDocument.documentElement);
1746
+ copyDocumentAttributes(hostDocument.body, frameDocument.body);
1747
+ } else {
1748
+ clearDocumentAttributes(frameDocument.documentElement);
1749
+ clearDocumentAttributes(frameDocument.body);
1750
+ }
1751
+ copyStylesheets(hostDocument, frameDocument, stableStylesheets, syncHostStyles);
1752
+ frameDocument.getElementById("designos-live-design")?.remove();
1753
+ if (previewStyles) {
1754
+ const style = frameDocument.createElement("style");
1755
+ style.id = "designos-live-design";
1756
+ style.dataset.designosPreviewStyle = "true";
1757
+ style.textContent = previewStyles;
1758
+ frameDocument.head.appendChild(style);
1759
+ }
1760
+ };
1761
+ sync();
1762
+ if (!syncHostStyles) return;
1763
+ const observer = new MutationObserver(sync);
1764
+ observer.observe(hostDocument.head, { childList: true, subtree: true, attributes: true, characterData: true });
1765
+ observer.observe(hostDocument.documentElement, { attributes: true });
1766
+ observer.observe(hostDocument.body, { attributes: true });
1767
+ return () => observer.disconnect();
1768
+ }, [mountNode, syncHostStyles, stableStylesheets, previewStyles]);
1769
+ return /* @__PURE__ */ jsx18(
1770
+ "iframe",
1771
+ {
1772
+ ref: frameRef,
1773
+ title: "DesignOS page preview",
1774
+ "aria-label": "DesignOS page preview",
1775
+ "data-designos-preview-frame": "true",
1776
+ srcDoc: FRAME_DOCUMENT,
1777
+ onLoad: handleLoad,
1778
+ style: {
1779
+ display: "block",
1780
+ width: "100%",
1781
+ height: "calc(100vh - 104px)",
1782
+ minHeight: 500,
1783
+ border: 0,
1784
+ background: "transparent",
1785
+ pointerEvents: disablePointerEvents ? "none" : "auto"
1786
+ },
1787
+ children: mountNode ? createPortal2(children, mountNode) : null
1788
+ }
1789
+ );
1790
+ }
1791
+
1792
+ // src/components/canvas/EmptyCanvas.tsx
1793
+ import { jsx as jsx19 } from "react/jsx-runtime";
1794
+ function EmptyCanvas() {
1795
+ return /* @__PURE__ */ jsx19(
1796
+ "div",
1797
+ {
1798
+ style: {
1799
+ display: "flex",
1800
+ alignItems: "center",
1801
+ justifyContent: "center",
1802
+ height: "100%",
1803
+ minHeight: 500,
1804
+ color: "#6b7280",
1805
+ fontSize: 14
1806
+ },
1807
+ children: "Drag a component here"
1808
+ }
1809
+ );
1810
+ }
1811
+
1812
+ // src/components/canvas/Canvas.tsx
1813
+ import { jsx as jsx20, jsxs as jsxs15 } from "react/jsx-runtime";
1814
+ var EMPTY_STYLESHEETS = [];
1815
+ function Canvas({ page, registry, components, preview, previewMode = false, previewStyles }) {
1816
+ const selectedNodeId = useEditorStore((state) => state.selectedNodeId);
1817
+ const viewport = useEditorStore((state) => state.viewport);
1818
+ const selectNode = useEditorStore((state) => state.selectNode);
1819
+ const rootChildren = page.root.children;
1820
+ const hasChildren = rootChildren.length > 0 || Object.values(page.root.slots ?? {}).some((children) => children.length > 0);
1821
+ const width = viewport === "desktop" ? "100%" : viewport === "tablet" ? "768px" : "375px";
1822
+ const canvasContent = /* @__PURE__ */ jsx20(CanvasDropZone, { parentId: page.root.id, enabled: !previewMode, children: /* @__PURE__ */ jsxs15(CanvasRoot, { children: [
1823
+ !hasChildren && /* @__PURE__ */ jsx20(EmptyCanvas, {}),
1824
+ rootChildren.map((node) => /* @__PURE__ */ jsx20(
1825
+ CanvasNode,
1826
+ {
1827
+ node,
1828
+ registry,
1829
+ components,
1830
+ selectedNodeId,
1831
+ onSelect: selectNode,
1832
+ preview: previewMode
1833
+ },
1834
+ node.id
1835
+ ))
1836
+ ] }) });
1837
+ return /* @__PURE__ */ jsx20("div", { className: "dos-canvas-viewport", children: /* @__PURE__ */ jsx20("div", { className: "dos-canvas-page", style: { width }, children: preview?.mode === "inline" ? canvasContent : /* @__PURE__ */ jsx20(
1838
+ CanvasFrame,
1839
+ {
1840
+ syncHostStyles: preview?.syncHostStyles ?? true,
1841
+ stylesheets: preview?.stylesheets ?? EMPTY_STYLESHEETS,
1842
+ previewStyles,
1843
+ children: canvasContent
1844
+ }
1845
+ ) }) });
1846
+ }
1847
+
1848
+ // src/components/json/JsonDrawer.tsx
1849
+ import { useEffect as useEffect7, useRef as useRef5, useState as useState9 } from "react";
1850
+ import { migratePageDocument as migratePageDocument2, validatePageAgainstRegistry as validatePageAgainstRegistry3 } from "@designos/core";
1851
+ import { Fragment as Fragment5, jsx as jsx21, jsxs as jsxs16 } from "react/jsx-runtime";
1852
+ function JsonDrawer({ registry }) {
1853
+ const page = useEditorStore((state) => state.page);
1854
+ const setPage = useEditorStore((state) => state.setPage);
1855
+ const toggleJsonDrawer = useEditorStore((state) => state.toggleJsonDrawer);
1856
+ const inputRef = useRef5(null);
1857
+ const [editing, setEditing] = useState9(false);
1858
+ const [value, setValue] = useState9("");
1859
+ const [error, setError] = useState9(null);
1860
+ const [copyStatus, setCopyStatus] = useState9("idle");
1861
+ useEffect7(() => {
1862
+ const handleKeyDown = (event) => {
1863
+ if (event.key === "Escape") {
1864
+ event.preventDefault();
1865
+ toggleJsonDrawer();
1866
+ }
1867
+ };
1868
+ window.addEventListener("keydown", handleKeyDown);
1869
+ return () => window.removeEventListener("keydown", handleKeyDown);
1870
+ }, [toggleJsonDrawer]);
1871
+ function startEditing() {
1872
+ setError(null);
1873
+ setCopyStatus("idle");
1874
+ setValue(JSON.stringify(page, null, 2));
1875
+ setEditing(true);
1876
+ }
1877
+ async function copyJson() {
1878
+ try {
1879
+ await navigator.clipboard.writeText(JSON.stringify(page, null, 2));
1880
+ setCopyStatus("copied");
1881
+ setError(null);
1882
+ window.setTimeout(() => setCopyStatus("idle"), 1800);
1883
+ } catch (cause) {
1884
+ setCopyStatus("idle");
1885
+ setError(cause instanceof Error ? `Unable to copy page JSON: ${cause.message}` : "Unable to copy page JSON");
1886
+ }
1887
+ }
1888
+ function exportJson() {
1889
+ const blob = new Blob([JSON.stringify(page, null, 2)], { type: "application/json" });
1890
+ const url = URL.createObjectURL(blob);
1891
+ const anchor = document.createElement("a");
1892
+ const baseName = page.meta.title?.trim().toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "designos-page";
1893
+ anchor.href = url;
1894
+ anchor.download = `${baseName}.json`;
1895
+ anchor.click();
1896
+ URL.revokeObjectURL(url);
1897
+ }
1898
+ function applyValue(source) {
1899
+ try {
1900
+ const parsed = JSON.parse(source);
1901
+ const migrated = migratePageDocument2(parsed, registry);
1902
+ const issues = validatePageAgainstRegistry3(migrated.root, registry);
1903
+ if (issues.length) {
1904
+ setError(issues.map((issue) => `${issue.path || "page"}: ${issue.message}`).join("\n"));
1905
+ return false;
1906
+ }
1907
+ setPage(migrated);
1908
+ setError(null);
1909
+ setEditing(false);
1910
+ return true;
1911
+ } catch (cause) {
1912
+ setError(cause instanceof Error ? cause.message : "Invalid page JSON");
1913
+ return false;
1914
+ }
1915
+ }
1916
+ async function importFile(file) {
1917
+ if (!file) return;
1918
+ try {
1919
+ const source = await file.text();
1920
+ setValue(source);
1921
+ applyValue(source);
1922
+ } catch (cause) {
1923
+ setError(cause instanceof Error ? `Unable to read JSON file: ${cause.message}` : "Unable to read JSON file");
1924
+ } finally {
1925
+ if (inputRef.current) inputRef.current.value = "";
1926
+ }
1927
+ }
1928
+ return /* @__PURE__ */ jsx21(
1929
+ "div",
1930
+ {
1931
+ className: "dos-json-overlay",
1932
+ style: { position: "fixed", inset: 0, zIndex: 1e3, display: "flex", alignItems: "flex-end", justifyContent: "center", background: "rgba(0, 0, 0, 0.44)" },
1933
+ onMouseDown: (event) => {
1934
+ if (event.target === event.currentTarget) toggleJsonDrawer();
1935
+ },
1936
+ children: /* @__PURE__ */ jsxs16("section", { className: "dos-json-drawer", style: { width: "100%", height: "min(56vh, 540px)", minHeight: 240, display: "flex", flexDirection: "column", overflow: "hidden", color: "#fafafa", background: "#0f0f12", border: "1px solid #2a2a2f", borderBottom: 0, borderRadius: "14px 14px 0 0", boxShadow: "0 -16px 50px rgba(0, 0, 0, 0.42)" }, role: "dialog", "aria-modal": "true", "aria-label": "Page JSON", children: [
1937
+ /* @__PURE__ */ jsxs16("div", { className: "dos-json-header", children: [
1938
+ /* @__PURE__ */ jsxs16("div", { className: "dos-json-title", children: [
1939
+ /* @__PURE__ */ jsx21("strong", { children: "Page JSON" }),
1940
+ /* @__PURE__ */ jsx21("span", { children: editing ? "Edit the current page data" : "Inspect, import, or export page data" })
1941
+ ] }),
1942
+ /* @__PURE__ */ jsxs16("div", { className: "dos-json-actions", children: [
1943
+ /* @__PURE__ */ jsx21("input", { ref: inputRef, type: "file", accept: "application/json,.json", "aria-label": "Import page JSON file", style: { display: "none" }, onChange: (event) => void importFile(event.target.files?.[0]) }),
1944
+ /* @__PURE__ */ jsx21("button", { type: "button", onClick: () => inputRef.current?.click(), children: "Import JSON" }),
1945
+ /* @__PURE__ */ jsx21("button", { type: "button", onClick: exportJson, children: "Export JSON" }),
1946
+ !editing && /* @__PURE__ */ jsx21("button", { type: "button", onClick: () => void copyJson(), children: copyStatus === "copied" ? "Copied" : "Copy JSON" }),
1947
+ editing ? /* @__PURE__ */ jsxs16(Fragment5, { children: [
1948
+ /* @__PURE__ */ jsx21("button", { type: "button", className: "dos-primary-button", onClick: () => applyValue(value), children: "Apply" }),
1949
+ /* @__PURE__ */ jsx21("button", { type: "button", onClick: () => {
1950
+ setEditing(false);
1951
+ setError(null);
1952
+ }, children: "Cancel" })
1953
+ ] }) : /* @__PURE__ */ jsx21("button", { type: "button", onClick: startEditing, children: "Edit" }),
1954
+ /* @__PURE__ */ jsx21("button", { type: "button", className: "dos-json-close", "aria-label": "Close Page JSON", onClick: toggleJsonDrawer, children: "\xD7" })
1955
+ ] })
1956
+ ] }),
1957
+ error && /* @__PURE__ */ jsx21("div", { role: "alert", className: "dos-json-error", children: error }),
1958
+ /* @__PURE__ */ jsx21("div", { className: "dos-json-body", children: editing ? /* @__PURE__ */ jsx21("textarea", { "aria-label": "Page JSON editor", value, onChange: (event) => setValue(event.target.value), spellCheck: false }) : /* @__PURE__ */ jsx21("pre", { children: JSON.stringify(page, null, 2) }) })
1959
+ ] })
1960
+ }
1961
+ );
1962
+ }
1963
+
1964
+ // src/components/inspector/PropertyPanel.tsx
1965
+ import { useState as useState10 } from "react";
1966
+ import {
1967
+ createNodeFromManifest,
1968
+ groupFields
1969
+ } from "@designos/core";
1970
+
1971
+ // src/hooks/useSelectedNode.ts
1972
+ import {
1973
+ findNode as findNode3
1974
+ } from "@designos/core";
1975
+ function useSelectedNode() {
1976
+ const page = useEditorStore(
1977
+ (state) => state.page
1978
+ );
1979
+ const selectedNodeId = useEditorStore(
1980
+ (state) => state.selectedNodeId
1981
+ );
1982
+ if (!selectedNodeId) {
1983
+ return void 0;
1984
+ }
1985
+ return findNode3(
1986
+ page.root,
1987
+ selectedNodeId
1988
+ )?.node;
1989
+ }
1990
+
1991
+ // src/components/inspector/FieldGroup.tsx
1992
+ import { jsx as jsx22, jsxs as jsxs17 } from "react/jsx-runtime";
1993
+ function FieldGroup({
1994
+ title,
1995
+ children
1996
+ }) {
1997
+ return /* @__PURE__ */ jsxs17(
1998
+ "div",
1999
+ {
2000
+ style: {
2001
+ marginBottom: 24
2002
+ },
2003
+ children: [
2004
+ /* @__PURE__ */ jsx22(
2005
+ "div",
2006
+ {
2007
+ style: {
2008
+ fontSize: 12,
2009
+ fontWeight: 700,
2010
+ textTransform: "uppercase",
2011
+ color: "#6b7280",
2012
+ marginBottom: 12,
2013
+ paddingBottom: 8,
2014
+ borderBottom: "1px solid #e5e7eb"
2015
+ },
2016
+ children: title
2017
+ }
2018
+ ),
2019
+ children
2020
+ ]
2021
+ }
2022
+ );
2023
+ }
2024
+
2025
+ // src/components/inspector/ObjectFieldRenderer.tsx
2026
+ import { jsx as jsx23, jsxs as jsxs18 } from "react/jsx-runtime";
2027
+ function ObjectFieldRenderer({
2028
+ field,
2029
+ value,
2030
+ onChange
2031
+ }) {
2032
+ const currentValue = value ?? {};
2033
+ return /* @__PURE__ */ jsx23(
2034
+ "div",
2035
+ {
2036
+ style: {
2037
+ padding: 12,
2038
+ border: "1px solid #e5e7eb",
2039
+ borderRadius: 6
2040
+ },
2041
+ children: field.fields.map(
2042
+ (subField) => {
2043
+ const fieldValue = currentValue[subField.name];
2044
+ return /* @__PURE__ */ jsxs18(
2045
+ "div",
2046
+ {
2047
+ style: {
2048
+ marginBottom: 12
2049
+ },
2050
+ children: [
2051
+ /* @__PURE__ */ jsx23(
2052
+ "label",
2053
+ {
2054
+ style: {
2055
+ display: "block",
2056
+ marginBottom: 6,
2057
+ fontWeight: 600
2058
+ },
2059
+ children: subField.label
2060
+ }
2061
+ ),
2062
+ /* @__PURE__ */ jsx23(
2063
+ FieldRenderer,
2064
+ {
2065
+ field: subField,
2066
+ value: fieldValue,
2067
+ onChange: (newValue) => onChange(
2068
+ {
2069
+ ...currentValue,
2070
+ [subField.name]: newValue
2071
+ }
2072
+ )
2073
+ }
2074
+ )
2075
+ ]
2076
+ },
2077
+ subField.name
2078
+ );
2079
+ }
2080
+ )
2081
+ }
2082
+ );
2083
+ }
2084
+
2085
+ // src/components/inspector/ArrayFieldRenderer.tsx
2086
+ import { createArrayItemDefaultValue } from "@designos/core";
2087
+ import { jsx as jsx24, jsxs as jsxs19 } from "react/jsx-runtime";
2088
+ function ArrayFieldRenderer({ field, value, onChange }) {
2089
+ const items = Array.isArray(value) ? value : [];
2090
+ const canAdd = field.maxItems === void 0 || items.length < field.maxItems;
2091
+ const canRemove = field.minItems === void 0 || items.length > field.minItems;
2092
+ return /* @__PURE__ */ jsxs19("div", { children: [
2093
+ items.map((item, index) => /* @__PURE__ */ jsxs19(
2094
+ "div",
2095
+ {
2096
+ style: { padding: 12, border: "1px solid #e5e7eb", marginBottom: 8, borderRadius: 6 },
2097
+ children: [
2098
+ /* @__PURE__ */ jsxs19("div", { style: { marginBottom: 8, fontWeight: 600 }, children: [
2099
+ field.item.label,
2100
+ " ",
2101
+ index + 1
2102
+ ] }),
2103
+ /* @__PURE__ */ jsx24(
2104
+ FieldRenderer,
2105
+ {
2106
+ field: field.item,
2107
+ value: item,
2108
+ onChange: (newValue) => onChange(items.map((current, currentIndex) => currentIndex === index ? newValue : current))
2109
+ }
2110
+ ),
2111
+ /* @__PURE__ */ jsx24(
2112
+ "button",
2113
+ {
2114
+ type: "button",
2115
+ "aria-label": `Remove ${field.item.label} ${index + 1}`,
2116
+ disabled: !canRemove,
2117
+ onClick: () => onChange(items.filter((_, currentIndex) => currentIndex !== index)),
2118
+ children: "Remove"
2119
+ }
2120
+ )
2121
+ ]
2122
+ },
2123
+ index
2124
+ )),
2125
+ /* @__PURE__ */ jsxs19(
2126
+ "button",
2127
+ {
2128
+ type: "button",
2129
+ "aria-label": `Add ${field.item.label}`,
2130
+ disabled: !canAdd,
2131
+ onClick: () => onChange([...items, createArrayItemDefaultValue(field)]),
2132
+ children: [
2133
+ "Add ",
2134
+ field.item.label
2135
+ ]
2136
+ }
2137
+ )
2138
+ ] });
2139
+ }
2140
+
2141
+ // src/components/inspector/SlotFieldRenderer.tsx
2142
+ import { jsx as jsx25 } from "react/jsx-runtime";
2143
+ function SlotFieldRenderer(_props) {
2144
+ return /* @__PURE__ */ jsx25(
2145
+ "div",
2146
+ {
2147
+ style: {
2148
+ padding: 12,
2149
+ border: "1px dashed #ccc",
2150
+ borderRadius: 6,
2151
+ background: "#f8fafc"
2152
+ },
2153
+ children: "Slot content is managed from the canvas."
2154
+ }
2155
+ );
2156
+ }
2157
+
2158
+ // src/components/inspector/FieldRenderer.tsx
2159
+ import { jsx as jsx26, jsxs as jsxs20 } from "react/jsx-runtime";
2160
+ function FieldRenderer({
2161
+ field,
2162
+ value,
2163
+ onChange
2164
+ }) {
2165
+ switch (field.type) {
2166
+ case "text":
2167
+ return /* @__PURE__ */ jsx26(
2168
+ "input",
2169
+ {
2170
+ type: "text",
2171
+ value: String(value ?? ""),
2172
+ placeholder: field.placeholder,
2173
+ onChange: (e) => onChange(
2174
+ e.target.value
2175
+ )
2176
+ }
2177
+ );
2178
+ case "textarea":
2179
+ return /* @__PURE__ */ jsx26(
2180
+ "textarea",
2181
+ {
2182
+ value: String(value ?? ""),
2183
+ placeholder: field.placeholder,
2184
+ onChange: (e) => onChange(
2185
+ e.target.value
2186
+ )
2187
+ }
2188
+ );
2189
+ case "number":
2190
+ return /* @__PURE__ */ jsx26(
2191
+ "input",
2192
+ {
2193
+ type: "number",
2194
+ value: typeof value === "number" ? value : 0,
2195
+ min: field.min,
2196
+ max: field.max,
2197
+ step: field.step,
2198
+ onChange: (e) => onChange(
2199
+ Number(
2200
+ e.target.value
2201
+ )
2202
+ )
2203
+ }
2204
+ );
2205
+ case "boolean":
2206
+ return /* @__PURE__ */ jsx26(
2207
+ "input",
2208
+ {
2209
+ type: "checkbox",
2210
+ checked: Boolean(
2211
+ value
2212
+ ),
2213
+ onChange: (e) => onChange(
2214
+ e.target.checked
2215
+ )
2216
+ }
2217
+ );
2218
+ case "color":
2219
+ return /* @__PURE__ */ jsx26(
2220
+ "input",
2221
+ {
2222
+ type: "color",
2223
+ value: String(
2224
+ value ?? "#000000"
2225
+ ),
2226
+ onChange: (e) => onChange(
2227
+ e.target.value
2228
+ )
2229
+ }
2230
+ );
2231
+ case "select":
2232
+ return /* @__PURE__ */ jsx26(
2233
+ "select",
2234
+ {
2235
+ value: String(
2236
+ value ?? ""
2237
+ ),
2238
+ onChange: (e) => onChange(
2239
+ e.target.value
2240
+ ),
2241
+ children: field.options.map(
2242
+ (option) => /* @__PURE__ */ jsx26(
2243
+ "option",
2244
+ {
2245
+ value: String(
2246
+ option.value
2247
+ ),
2248
+ children: option.label
2249
+ },
2250
+ String(
2251
+ option.value
2252
+ )
2253
+ )
2254
+ )
2255
+ }
2256
+ );
2257
+ case "radio":
2258
+ return /* @__PURE__ */ jsx26("div", { children: field.options.map(
2259
+ (option) => /* @__PURE__ */ jsxs20(
2260
+ "label",
2261
+ {
2262
+ style: {
2263
+ display: "block"
2264
+ },
2265
+ children: [
2266
+ /* @__PURE__ */ jsx26(
2267
+ "input",
2268
+ {
2269
+ type: "radio",
2270
+ checked: value === option.value,
2271
+ onChange: () => onChange(
2272
+ option.value
2273
+ )
2274
+ }
2275
+ ),
2276
+ " ",
2277
+ option.label
2278
+ ]
2279
+ },
2280
+ String(
2281
+ option.value
2282
+ )
2283
+ )
2284
+ ) });
2285
+ case "checkbox":
2286
+ return /* @__PURE__ */ jsx26("div", { children: field.options.map(
2287
+ (option) => {
2288
+ const values = Array.isArray(
2289
+ value
2290
+ ) ? value : [];
2291
+ const checked = values.includes(
2292
+ option.value
2293
+ );
2294
+ return /* @__PURE__ */ jsxs20(
2295
+ "label",
2296
+ {
2297
+ style: {
2298
+ display: "block"
2299
+ },
2300
+ children: [
2301
+ /* @__PURE__ */ jsx26(
2302
+ "input",
2303
+ {
2304
+ type: "checkbox",
2305
+ checked,
2306
+ onChange: (e) => {
2307
+ if (e.target.checked) {
2308
+ onChange([
2309
+ ...values,
2310
+ option.value
2311
+ ]);
2312
+ } else {
2313
+ onChange(
2314
+ values.filter(
2315
+ (item) => item !== option.value
2316
+ )
2317
+ );
2318
+ }
2319
+ }
2320
+ }
2321
+ ),
2322
+ " ",
2323
+ option.label
2324
+ ]
2325
+ },
2326
+ String(
2327
+ option.value
2328
+ )
2329
+ );
2330
+ }
2331
+ ) });
2332
+ case "image":
2333
+ return /* @__PURE__ */ jsx26(
2334
+ "input",
2335
+ {
2336
+ type: "text",
2337
+ placeholder: "Image URL",
2338
+ value: String(
2339
+ value ?? ""
2340
+ ),
2341
+ onChange: (e) => onChange(
2342
+ e.target.value
2343
+ )
2344
+ }
2345
+ );
2346
+ case "richText":
2347
+ return /* @__PURE__ */ jsx26(
2348
+ "textarea",
2349
+ {
2350
+ rows: 8,
2351
+ value: String(
2352
+ value ?? ""
2353
+ ),
2354
+ onChange: (e) => onChange(
2355
+ e.target.value
2356
+ )
2357
+ }
2358
+ );
2359
+ case "object":
2360
+ return /* @__PURE__ */ jsx26(
2361
+ ObjectFieldRenderer,
2362
+ {
2363
+ field,
2364
+ value: value ?? {},
2365
+ onChange
2366
+ }
2367
+ );
2368
+ case "array":
2369
+ return /* @__PURE__ */ jsx26(
2370
+ ArrayFieldRenderer,
2371
+ {
2372
+ field,
2373
+ value: Array.isArray(
2374
+ value
2375
+ ) ? value : [],
2376
+ onChange
2377
+ }
2378
+ );
2379
+ case "slot":
2380
+ return /* @__PURE__ */ jsx26(
2381
+ SlotFieldRenderer,
2382
+ {
2383
+ field
2384
+ }
2385
+ );
2386
+ case "custom":
2387
+ return /* @__PURE__ */ jsx26(
2388
+ "div",
2389
+ {
2390
+ style: {
2391
+ padding: 8,
2392
+ border: "1px dashed #ccc"
2393
+ },
2394
+ children: "Custom renderer required"
2395
+ }
2396
+ );
2397
+ default:
2398
+ return null;
2399
+ }
2400
+ }
2401
+
2402
+ // src/components/inspector/PropertyPanel.tsx
2403
+ import { jsx as jsx27, jsxs as jsxs21 } from "react/jsx-runtime";
2404
+ function PropertyPanel({ registry }) {
2405
+ const node = useSelectedNode();
2406
+ const [selectedSlotTypes, setSelectedSlotTypes] = useState10({});
2407
+ const updateNodeProps = useEditorStore((state) => state.updateNodeProps);
2408
+ const addNode2 = useEditorStore((state) => state.addNode);
2409
+ const removeNode2 = useEditorStore((state) => state.removeNode);
2410
+ const reorderNode2 = useEditorStore((state) => state.reorderNode);
2411
+ if (!node) {
2412
+ return /* @__PURE__ */ jsx27("div", { style: { padding: 16 }, children: "Select a component" });
2413
+ }
2414
+ const manifest = registry.get(node.type);
2415
+ if (!manifest) {
2416
+ return /* @__PURE__ */ jsxs21("div", { style: { padding: 16 }, children: [
2417
+ "Component not registered: ",
2418
+ node.type
2419
+ ] });
2420
+ }
2421
+ const visibleFields = manifest.fields.filter((field) => field.visible !== false);
2422
+ const groupedFields = groupFields(visibleFields);
2423
+ return /* @__PURE__ */ jsxs21("div", { style: { padding: 16 }, children: [
2424
+ /* @__PURE__ */ jsx27("h3", { style: { marginTop: 0, marginBottom: 16 }, children: manifest.displayName }),
2425
+ Object.entries(groupedFields).map(([group, fields]) => /* @__PURE__ */ jsx27(FieldGroup, { title: group, children: fields.map((field) => /* @__PURE__ */ jsxs21("div", { style: { marginBottom: 16, display: "flex", flexDirection: "column", gap: 6 }, children: [
2426
+ /* @__PURE__ */ jsx27("label", { style: { fontSize: 14, fontWeight: 600 }, children: field.label }),
2427
+ /* @__PURE__ */ jsx27(
2428
+ FieldRenderer,
2429
+ {
2430
+ field,
2431
+ value: node.props[field.name],
2432
+ onChange: (newValue) => updateNodeProps(node.id, { [field.name]: newValue })
2433
+ }
2434
+ ),
2435
+ field.description && /* @__PURE__ */ jsx27("small", { style: { color: "#6b7280" }, children: field.description })
2436
+ ] }, field.name)) }, group)),
2437
+ (manifest.slots ?? []).length > 0 && /* @__PURE__ */ jsxs21("section", { "aria-label": "Named content slots", style: { marginTop: 20, borderTop: "1px solid #e5e7eb", paddingTop: 16 }, children: [
2438
+ /* @__PURE__ */ jsx27("h4", { style: { margin: "0 0 12px" }, children: "Content regions" }),
2439
+ (manifest.slots ?? []).map((slot) => {
2440
+ const children = node.slots?.[slot.name] ?? [];
2441
+ const candidates = registry.getAll().filter(
2442
+ (candidate) => (!slot.allowedComponents || slot.allowedComponents.includes(candidate.type)) && !slot.disallowedComponents?.includes(candidate.type)
2443
+ );
2444
+ const requestedType = selectedSlotTypes[slot.name];
2445
+ const selectedType = candidates.some((candidate) => candidate.type === requestedType) ? requestedType : candidates[0]?.type ?? "";
2446
+ const atCapacity = slot.maxChildren !== void 0 && children.length >= slot.maxChildren;
2447
+ return /* @__PURE__ */ jsxs21("div", { style: { marginBottom: 16, padding: 10, border: "1px solid #e5e7eb", borderRadius: 6 }, children: [
2448
+ /* @__PURE__ */ jsxs21("div", { style: { display: "flex", justifyContent: "space-between", gap: 8, marginBottom: 8 }, children: [
2449
+ /* @__PURE__ */ jsx27("strong", { children: slot.label }),
2450
+ /* @__PURE__ */ jsxs21("small", { "aria-label": `${slot.label} child count`, style: { color: "#6b7280" }, children: [
2451
+ children.length,
2452
+ slot.minChildren !== void 0 ? ` / min ${slot.minChildren}` : "",
2453
+ slot.maxChildren !== void 0 ? ` / max ${slot.maxChildren}` : ""
2454
+ ] })
2455
+ ] }),
2456
+ children.length === 0 && /* @__PURE__ */ jsx27("small", { style: { display: "block", color: "#6b7280", marginBottom: 8 }, children: "Empty region" }),
2457
+ children.map((child, index) => /* @__PURE__ */ jsxs21("div", { style: { display: "flex", alignItems: "center", gap: 6, marginBottom: 6 }, children: [
2458
+ /* @__PURE__ */ jsx27("span", { style: { flex: 1, fontSize: 13 }, children: child.meta?.label ?? child.type }),
2459
+ /* @__PURE__ */ jsx27(
2460
+ "button",
2461
+ {
2462
+ type: "button",
2463
+ "aria-label": `Move ${slot.label} item ${index + 1} up`,
2464
+ disabled: index === 0,
2465
+ onClick: () => reorderNode2(node.id, index, index - 1, slot.name),
2466
+ children: "\u2191"
2467
+ }
2468
+ ),
2469
+ /* @__PURE__ */ jsx27(
2470
+ "button",
2471
+ {
2472
+ type: "button",
2473
+ "aria-label": `Move ${slot.label} item ${index + 1} down`,
2474
+ disabled: index === children.length - 1,
2475
+ onClick: () => reorderNode2(node.id, index, index + 1, slot.name),
2476
+ children: "\u2193"
2477
+ }
2478
+ ),
2479
+ /* @__PURE__ */ jsx27("button", { type: "button", "aria-label": `Remove ${slot.label} item ${index + 1}`, disabled: slot.minChildren !== void 0 && children.length <= slot.minChildren, onClick: () => removeNode2(child.id), children: "Remove" })
2480
+ ] }, child.id)),
2481
+ /* @__PURE__ */ jsxs21("div", { style: { display: "flex", gap: 6, marginTop: 8 }, children: [
2482
+ /* @__PURE__ */ jsx27(
2483
+ "select",
2484
+ {
2485
+ "aria-label": `Component for ${slot.label}`,
2486
+ value: selectedType,
2487
+ disabled: candidates.length === 0,
2488
+ onChange: (event) => setSelectedSlotTypes((current) => ({ ...current, [slot.name]: event.target.value })),
2489
+ children: candidates.map((candidate) => /* @__PURE__ */ jsx27("option", { value: candidate.type, children: candidate.displayName }, candidate.type))
2490
+ }
2491
+ ),
2492
+ /* @__PURE__ */ jsx27(
2493
+ "button",
2494
+ {
2495
+ type: "button",
2496
+ "aria-label": `Add to ${slot.label}`,
2497
+ disabled: !selectedType || atCapacity,
2498
+ onClick: () => addNode2(node.id, createNodeFromManifest(registry.getOrThrow(selectedType)), slot.name),
2499
+ children: "Add"
2500
+ }
2501
+ )
2502
+ ] })
2503
+ ] }, slot.name);
2504
+ })
2505
+ ] })
2506
+ ] });
2507
+ }
2508
+
2509
+ // src/hooks/useHistoryPersistence.ts
2510
+ import { useEffect as useEffect8, useRef as useRef6 } from "react";
2511
+ function useHistoryPersistence({ pageId, history, enabled = true }) {
2512
+ const past = useEditorStore((state) => state.past);
2513
+ const replaceHistory = useEditorStore((state) => state.replaceHistory);
2514
+ const hydrated = useRef6(false);
2515
+ const lastSaved = useRef6(void 0);
2516
+ useEffect8(() => {
2517
+ let cancelled = false;
2518
+ hydrated.current = false;
2519
+ lastSaved.current = void 0;
2520
+ if (!enabled || !history || !pageId) return () => void 0;
2521
+ void history.load({ pageId }).then((entries) => {
2522
+ if (cancelled) return;
2523
+ replaceHistory(entries);
2524
+ hydrated.current = true;
2525
+ }).catch((error) => {
2526
+ console.error("Failed to load page history; continuing with in-memory history", error);
2527
+ if (!cancelled) hydrated.current = true;
2528
+ });
2529
+ return () => {
2530
+ cancelled = true;
2531
+ };
2532
+ }, [enabled, history, pageId, replaceHistory]);
2533
+ useEffect8(() => {
2534
+ if (!enabled || !history || !pageId || !hydrated.current) return;
2535
+ const serialized = JSON.stringify(past);
2536
+ if (serialized === lastSaved.current) return;
2537
+ lastSaved.current = serialized;
2538
+ void history.save({ pageId, entries: past }).catch((error) => {
2539
+ console.error("Failed to save page history; current editor history remains available", error);
2540
+ });
2541
+ }, [enabled, history, pageId, past]);
2542
+ }
2543
+
2544
+ // src/components/history/HistoryDrawer.tsx
2545
+ import { useEffect as useEffect9, useRef as useRef7 } from "react";
2546
+ import { jsx as jsx28, jsxs as jsxs22 } from "react/jsx-runtime";
2547
+ function formatTime(timestamp) {
2548
+ const seconds = Math.max(0, Math.floor((Date.now() - timestamp) / 1e3));
2549
+ if (seconds < 10) return "Just now";
2550
+ if (seconds < 60) return `${seconds}s ago`;
2551
+ const minutes = Math.floor(seconds / 60);
2552
+ if (minutes < 60) return `${minutes}m ago`;
2553
+ const hours = Math.floor(minutes / 60);
2554
+ return `${hours}h ago`;
2555
+ }
2556
+ function HistoryDrawer() {
2557
+ const historyOpen = useEditorStore((state) => state.historyOpen);
2558
+ const toggleHistory = useEditorStore((state) => state.toggleHistory);
2559
+ const past = useEditorStore((state) => state.past);
2560
+ const jumpToHistory = useEditorStore((state) => state.jumpToHistory);
2561
+ const panelRef = useRef7(null);
2562
+ const entries = [...past].reverse();
2563
+ useEffect9(() => {
2564
+ if (!historyOpen) return;
2565
+ const handleKeyDown = (event) => {
2566
+ if (event.key === "Escape") {
2567
+ event.preventDefault();
2568
+ toggleHistory();
2569
+ }
2570
+ };
2571
+ const handleMouseDown = (event) => {
2572
+ if (panelRef.current && !panelRef.current.contains(event.target)) toggleHistory();
2573
+ };
2574
+ window.addEventListener("keydown", handleKeyDown);
2575
+ const timeout = window.setTimeout(() => window.addEventListener("mousedown", handleMouseDown), 0);
2576
+ return () => {
2577
+ window.removeEventListener("keydown", handleKeyDown);
2578
+ window.clearTimeout(timeout);
2579
+ window.removeEventListener("mousedown", handleMouseDown);
2580
+ };
2581
+ }, [historyOpen, toggleHistory]);
2582
+ return /* @__PURE__ */ jsxs22(
2583
+ "aside",
2584
+ {
2585
+ ref: panelRef,
2586
+ "aria-label": "Version history",
2587
+ className: `dos-history-drawer ${historyOpen ? "is-open" : ""}`,
2588
+ "aria-hidden": !historyOpen,
2589
+ children: [
2590
+ /* @__PURE__ */ jsxs22("div", { className: "dos-history-header", children: [
2591
+ /* @__PURE__ */ jsxs22("div", { children: [
2592
+ /* @__PURE__ */ jsx28("strong", { children: "Version History" }),
2593
+ /* @__PURE__ */ jsxs22("span", { children: [
2594
+ entries.length,
2595
+ " changes"
2596
+ ] })
2597
+ ] }),
2598
+ /* @__PURE__ */ jsx28("button", { type: "button", onClick: toggleHistory, "aria-label": "Close version history", children: "\xD7" })
2599
+ ] }),
2600
+ /* @__PURE__ */ jsxs22("div", { className: "dos-history-list", children: [
2601
+ /* @__PURE__ */ jsxs22("div", { className: "dos-history-entry dos-history-current", children: [
2602
+ /* @__PURE__ */ jsxs22("div", { children: [
2603
+ /* @__PURE__ */ jsx28("span", { children: "Current" }),
2604
+ /* @__PURE__ */ jsx28("span", { className: "dos-history-badge", children: "latest" })
2605
+ ] }),
2606
+ /* @__PURE__ */ jsx28("div", { children: "Current state" })
2607
+ ] }),
2608
+ entries.map((entry) => /* @__PURE__ */ jsxs22(
2609
+ "button",
2610
+ {
2611
+ type: "button",
2612
+ className: "dos-history-entry dos-history-snapshot",
2613
+ onClick: () => jumpToHistory(entry.id),
2614
+ children: [
2615
+ /* @__PURE__ */ jsxs22("span", { className: "dos-history-entry-meta", children: [
2616
+ /* @__PURE__ */ jsx28("span", { children: formatTime(entry.timestamp) }),
2617
+ /* @__PURE__ */ jsx28("span", { className: "dos-history-badge", children: entry.source ?? "manual" })
2618
+ ] }),
2619
+ /* @__PURE__ */ jsx28("span", { children: entry.label })
2620
+ ]
2621
+ },
2622
+ entry.id
2623
+ )),
2624
+ entries.length === 0 && /* @__PURE__ */ jsx28("div", { className: "dos-history-empty", children: "No history yet. Make a change to see it here." })
2625
+ ] })
2626
+ ]
2627
+ }
2628
+ );
2629
+ }
2630
+
2631
+ // src/components/assistant/PageAssistant.tsx
2632
+ import { useState as useState11 } from "react";
2633
+
2634
+ // src/types/page-agent.ts
2635
+ function projectField(field) {
2636
+ const result = {
2637
+ name: field.name,
2638
+ label: field.label,
2639
+ type: field.type,
2640
+ required: field.required,
2641
+ description: field.description,
2642
+ defaultValue: field.defaultValue
2643
+ };
2644
+ if ("options" in field) result.options = field.options;
2645
+ if (field.type === "object") result.fields = field.fields.map(projectField);
2646
+ if (field.type === "array") result.item = projectField(field.item);
2647
+ return result;
2648
+ }
2649
+ function projectPublicComponents(registry, permissions = {}) {
2650
+ const allowed = permissions.allowedComponentTypes;
2651
+ return registry.getAll().filter((manifest) => !allowed || allowed.includes(manifest.type)).map((manifest) => ({
2652
+ type: manifest.type,
2653
+ displayName: manifest.displayName,
2654
+ category: manifest.category,
2655
+ fields: manifest.fields.filter((field) => field.visible !== false).map(projectField),
2656
+ slots: (manifest.slots ?? []).map((slot) => ({
2657
+ name: slot.name,
2658
+ label: slot.label,
2659
+ allowedComponents: slot.allowedComponents
2660
+ })),
2661
+ canHaveChildren: Boolean(manifest.capabilities?.canHaveChildren)
2662
+ }));
2663
+ }
2664
+
2665
+ // src/page-agent-validation.ts
2666
+ import { validatePage as validatePage2, validatePageAgainstRegistry as validatePageAgainstRegistry4 } from "@designos/core";
2667
+ function walk(node, visit, path = "root") {
2668
+ visit(node, path);
2669
+ node.children.forEach((child, index) => walk(child, visit, `${path}.children[${index}]`));
2670
+ Object.entries(node.slots ?? {}).forEach(([name, children]) => {
2671
+ children.forEach((child, index) => walk(child, visit, `${path}.slots.${name}[${index}]`));
2672
+ });
2673
+ }
2674
+ function countNodes(root) {
2675
+ let count = 0;
2676
+ walk(root, () => {
2677
+ count += 1;
2678
+ });
2679
+ return count;
2680
+ }
2681
+ function sameValue(a, b) {
2682
+ return JSON.stringify(a) === JSON.stringify(b);
2683
+ }
2684
+ function summarizeNodeChanges(before, after, path, changes) {
2685
+ if (!before && after) {
2686
+ changes.push({ path, after: after.type, kind: "added" });
2687
+ return;
2688
+ }
2689
+ if (before && !after) {
2690
+ changes.push({ path, before: before.type, kind: "removed" });
2691
+ return;
2692
+ }
2693
+ if (!before || !after) return;
2694
+ if (before.type !== after.type) changes.push({ path: `${path}.type`, before: before.type, after: after.type, kind: "changed" });
2695
+ const propNames = /* @__PURE__ */ new Set([...Object.keys(before.props), ...Object.keys(after.props)]);
2696
+ for (const name of propNames) {
2697
+ if (!sameValue(before.props[name], after.props[name])) {
2698
+ changes.push({ path: `${path}.props.${name}`, before: before.props[name], after: after.props[name], kind: before.props[name] === void 0 ? "added" : after.props[name] === void 0 ? "removed" : "changed" });
2699
+ }
2700
+ }
2701
+ }
2702
+ function summarizePageChanges(before, after) {
2703
+ const beforeNodes = /* @__PURE__ */ new Map();
2704
+ const afterNodes = /* @__PURE__ */ new Map();
2705
+ walk(before.root, (node, path) => beforeNodes.set(node.id, { node, path }));
2706
+ walk(after.root, (node, path) => afterNodes.set(node.id, { node, path }));
2707
+ const ids = /* @__PURE__ */ new Set([...beforeNodes.keys(), ...afterNodes.keys()]);
2708
+ const changes = [];
2709
+ for (const id of ids) {
2710
+ const oldEntry = beforeNodes.get(id);
2711
+ const newEntry = afterNodes.get(id);
2712
+ summarizeNodeChanges(oldEntry?.node, newEntry?.node, newEntry?.path ?? oldEntry?.path ?? `root.${id}`, changes);
2713
+ }
2714
+ return changes;
2715
+ }
2716
+ function validatePageAgentState(current, candidate, registry, permissions = {}) {
2717
+ const diagnostics = [];
2718
+ const structural = validatePage2(candidate);
2719
+ const registryIssues = structural.valid ? registry.has(candidate.root.type) ? validatePageAgainstRegistry4(candidate.root, registry) : candidate.root.children.flatMap((child) => validatePageAgainstRegistry4(child, registry)) : [];
2720
+ for (const issue of [...structural.issues, ...registryIssues]) {
2721
+ diagnostics.push({ path: issue.path, message: issue.message, severity: "error" });
2722
+ }
2723
+ const allowed = permissions.allowedComponentTypes;
2724
+ const locked = new Set(permissions.lockedNodeIds ?? []);
2725
+ const beforeNodes = /* @__PURE__ */ new Map();
2726
+ walk(current.root, (node) => beforeNodes.set(node.id, node));
2727
+ walk(candidate.root, (node, path) => {
2728
+ if (allowed && !allowed.includes(node.type)) diagnostics.push({ path, message: `Component '${node.type}' is not available to this user`, severity: "error" });
2729
+ if (locked.has(node.id) && !sameValue(beforeNodes.get(node.id), node)) diagnostics.push({ path, message: `Node '${node.id}' is locked`, severity: "error" });
2730
+ });
2731
+ if (permissions.maxNodes !== void 0 && countNodes(candidate.root) > permissions.maxNodes) {
2732
+ diagnostics.push({ path: "root", message: `Page exceeds the maximum of ${permissions.maxNodes} components`, severity: "error" });
2733
+ }
2734
+ const changes = summarizePageChanges(current, candidate);
2735
+ if (permissions.canAddComponents === false && changes.some((change) => change.kind === "added")) diagnostics.push({ path: "root", message: "Adding components is not permitted", severity: "error" });
2736
+ if (permissions.canRemoveComponents === false && changes.some((change) => change.kind === "removed")) diagnostics.push({ path: "root", message: "Removing components is not permitted", severity: "error" });
2737
+ if (permissions.canEditContent === false && changes.some((change) => change.path.includes(".props."))) diagnostics.push({ path: "root", message: "Editing component properties is not permitted", severity: "error" });
2738
+ if (permissions.canChangeVariants === false && changes.some((change) => change.path.endsWith(".props.variant"))) diagnostics.push({ path: "root", message: "Changing component variants is not permitted", severity: "error" });
2739
+ if (permissions.canEditImages === false && changes.some((change) => /\.props\.(image|imageUrl|src|images)(\.|$)/.test(change.path))) diagnostics.push({ path: "root", message: "Editing images is not permitted", severity: "error" });
2740
+ if (permissions.canEditLinks === false && changes.some((change) => /\.props\.(href|url|link|links|primaryCta|secondaryCta)(\.|$)/.test(change.path))) diagnostics.push({ path: "root", message: "Editing links is not permitted", severity: "error" });
2741
+ if (permissions.canReorderComponents === false && changes.some((change) => change.path.includes("children") || change.path.includes("slots"))) diagnostics.push({ path: "root", message: "Reordering components is not permitted", severity: "error" });
2742
+ return { valid: diagnostics.every((diagnostic) => diagnostic.severity !== "error"), diagnostics, changes };
2743
+ }
2744
+
2745
+ // src/components/assistant/PageAssistant.tsx
2746
+ import { jsx as jsx29, jsxs as jsxs23 } from "react/jsx-runtime";
2747
+ function PageAssistant({ agent, registry, pageId, permissions = {}, baseRevision }) {
2748
+ const open = useEditorStore((state) => state.assistantOpen);
2749
+ const toggle = useEditorStore((state) => state.toggleAssistant);
2750
+ const page = useEditorStore((state) => state.page);
2751
+ const selectedNodeId = useEditorStore((state) => state.selectedNodeId);
2752
+ const history = useEditorStore((state) => state.past);
2753
+ const applyPageState = useEditorStore((state) => state.applyPageState);
2754
+ const [request, setRequest] = useState11("");
2755
+ const [messages, setMessages] = useState11([]);
2756
+ const [busy, setBusy] = useState11(false);
2757
+ async function send() {
2758
+ const text = request.trim();
2759
+ if (!text || busy) return;
2760
+ setRequest("");
2761
+ setMessages((current) => [...current, { role: "user", text }]);
2762
+ setBusy(true);
2763
+ try {
2764
+ let result;
2765
+ result = await agent.chat({
2766
+ request: text,
2767
+ pageId,
2768
+ page,
2769
+ selectedNodeId,
2770
+ components: projectPublicComponents(registry, permissions),
2771
+ permissions,
2772
+ history,
2773
+ baseRevision,
2774
+ applyPageState: ({ page: candidate, summary, baseRevision: candidateRevision }) => {
2775
+ if (candidateRevision && baseRevision && candidateRevision !== baseRevision) {
2776
+ return { status: "rejected", changes: [], diagnostics: [{ path: "baseRevision", message: "The page changed while the assistant was working.", severity: "error" }] };
2777
+ }
2778
+ const validation = validatePageAgentState(useEditorStore.getState().page, candidate, registry, permissions);
2779
+ if (!validation.valid) {
2780
+ return { status: "rejected", changes: validation.changes, diagnostics: validation.diagnostics };
2781
+ }
2782
+ return applyPageState(candidate, { label: `Agent: ${summary}`, source: "agent", changes: validation.changes });
2783
+ }
2784
+ });
2785
+ const appliedText = result.applied?.status === "applied" ? `${result.message}
2786
+
2787
+ Version created: ${result.applied.summary}` : result.message;
2788
+ setMessages((current) => [...current, { role: "agent", text: appliedText }]);
2789
+ } catch (error) {
2790
+ setMessages((current) => [...current, { role: "agent", text: error instanceof Error ? error.message : "The assistant could not complete that request." }]);
2791
+ } finally {
2792
+ setBusy(false);
2793
+ }
2794
+ }
2795
+ return /* @__PURE__ */ jsxs23("aside", { className: `dos-assistant-drawer ${open ? "is-open" : ""}`, "aria-label": "Page Assistant", "aria-hidden": !open, children: [
2796
+ /* @__PURE__ */ jsxs23("div", { className: "dos-assistant-header", children: [
2797
+ /* @__PURE__ */ jsxs23("div", { children: [
2798
+ /* @__PURE__ */ jsx29("strong", { children: "Page Assistant" }),
2799
+ /* @__PURE__ */ jsx29("span", { children: "Page data only" })
2800
+ ] }),
2801
+ /* @__PURE__ */ jsx29("button", { type: "button", onClick: toggle, "aria-label": "Close Page Assistant", children: "\xD7" })
2802
+ ] }),
2803
+ /* @__PURE__ */ jsxs23("div", { className: "dos-assistant-messages", "aria-live": "polite", children: [
2804
+ messages.length === 0 && /* @__PURE__ */ jsx29("p", { className: "dos-assistant-empty", children: "Ask me to update the page using the components and fields available to you." }),
2805
+ messages.map((message, index) => /* @__PURE__ */ jsx29("div", { className: `dos-assistant-message ${message.role}`, children: message.text }, `${message.role}-${index}`)),
2806
+ busy && /* @__PURE__ */ jsx29("div", { className: "dos-assistant-message agent", children: "Working with the current page JSON\u2026" })
2807
+ ] }),
2808
+ /* @__PURE__ */ jsxs23("div", { className: "dos-assistant-input", children: [
2809
+ /* @__PURE__ */ jsx29("textarea", { value: request, onChange: (event) => setRequest(event.target.value), onKeyDown: (event) => {
2810
+ if (event.key === "Enter" && !event.shiftKey) {
2811
+ event.preventDefault();
2812
+ void send();
2813
+ }
2814
+ }, placeholder: "Describe a page change\u2026", "aria-label": "Page Assistant request" }),
2815
+ /* @__PURE__ */ jsx29("button", { type: "button", className: "dos-primary-button", disabled: busy || !request.trim(), onClick: () => void send(), children: "Send" })
2816
+ ] })
2817
+ ] });
2818
+ }
2819
+
2820
+ // src/components/design/DesignDrawer.tsx
2821
+ import { useEffect as useEffect11, useRef as useRef8, useState as useState13 } from "react";
2822
+
2823
+ // src/components/design/KitDesignPanel.tsx
2824
+ import { useEffect as useEffect10, useState as useState12 } from "react";
2825
+
2826
+ // src/components/design/kit-design-utils.ts
2827
+ var COLOR_VALUE = /^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$/;
2828
+ var OPTION_VALUE = /^[A-Za-z0-9][A-Za-z0-9 _.,'-]*$/;
2829
+ var CSS_VARIABLE = /^--[A-Za-z_][A-Za-z0-9_-]*$/;
2830
+ var CSS_UNITS = /* @__PURE__ */ new Set(["", "px", "rem", "em", "%"]);
2831
+ function isStepAligned(value, min, step) {
2832
+ const steps = (value - min) / step;
2833
+ return Math.abs(steps - Math.round(steps)) < 1e-9;
2834
+ }
2835
+ function isValidKitDesignValue(token, value) {
2836
+ switch (token.type) {
2837
+ case "color":
2838
+ return typeof value === "string" && COLOR_VALUE.test(value);
2839
+ case "font-family":
2840
+ case "select":
2841
+ return typeof value === "string" && OPTION_VALUE.test(value) && token.options.some((option) => option.value === value);
2842
+ case "number":
2843
+ return typeof value === "number" && Number.isFinite(value) && Number.isFinite(token.min) && Number.isFinite(token.max) && Number.isFinite(token.step) && token.min <= token.max && token.step > 0 && value >= token.min && value <= token.max && isStepAligned(value, token.min, token.step);
2844
+ }
2845
+ }
2846
+ function resolveKitDesignValues(manifest, values) {
2847
+ const resolved = {};
2848
+ for (const token of manifest.tokens) {
2849
+ const value = values?.[token.id];
2850
+ resolved[token.id] = isValidKitDesignValue(token, value) ? value : token.default;
2851
+ }
2852
+ return resolved;
2853
+ }
2854
+ function applyKitDesignPreset(manifest, presetId) {
2855
+ const preset = manifest.presets.find((candidate) => candidate.id === presetId);
2856
+ if (!preset) return void 0;
2857
+ return resolveKitDesignValues(manifest, preset.values);
2858
+ }
2859
+ function projectKitDesignStyles(manifest, kitId, design) {
2860
+ const values = resolveKitDesignValues(manifest, design.tokens[kitId]);
2861
+ const declarations = [];
2862
+ for (const token of manifest.tokens) {
2863
+ if (!CSS_VARIABLE.test(token.cssVariable)) continue;
2864
+ const value = values[token.id];
2865
+ if (!isValidKitDesignValue(token, value)) continue;
2866
+ if (token.type === "number" && !CSS_UNITS.has(token.unit ?? "")) continue;
2867
+ const cssValue = token.type === "font-family" ? `"${value}"` : token.type === "number" ? `${value}${token.unit ?? ""}` : value;
2868
+ declarations.push(` ${token.cssVariable}: ${cssValue};`);
2869
+ }
2870
+ return declarations.length > 0 ? `:root {
2871
+ ${declarations.join("\n")}
2872
+ }` : "";
2873
+ }
2874
+ function getKitDesignValues(manifest, kitId, design) {
2875
+ return resolveKitDesignValues(manifest, design.tokens[kitId]);
2876
+ }
2877
+
2878
+ // src/components/design/KitDesignPanel.tsx
2879
+ import { jsx as jsx30, jsxs as jsxs24 } from "react/jsx-runtime";
2880
+ function toPickerHex(value) {
2881
+ if (/^#[\da-f]{6}$/i.test(value)) return value;
2882
+ if (/^#[\da-f]{3}$/i.test(value)) {
2883
+ return `#${value[1]}${value[1]}${value[2]}${value[2]}${value[3]}${value[3]}`;
2884
+ }
2885
+ if (/^#[\da-f]{4}$/i.test(value)) {
2886
+ return `#${value[1]}${value[1]}${value[2]}${value[2]}${value[3]}${value[3]}`;
2887
+ }
2888
+ if (/^#[\da-f]{8}$/i.test(value)) return value.slice(0, 7);
2889
+ return "#000000";
2890
+ }
2891
+ function ColorTokenControl({
2892
+ id,
2893
+ token,
2894
+ value,
2895
+ onChange
2896
+ }) {
2897
+ const [draft, setDraft] = useState12(value);
2898
+ useEffect10(() => setDraft(value), [value]);
2899
+ const commit = () => {
2900
+ if (isValidKitDesignValue(token, draft)) onChange(draft);
2901
+ else setDraft(value);
2902
+ };
2903
+ return /* @__PURE__ */ jsxs24("div", { className: "dos-kit-design-color-control", children: [
2904
+ /* @__PURE__ */ jsx30(
2905
+ "input",
2906
+ {
2907
+ type: "color",
2908
+ "aria-label": `${token.label} color picker`,
2909
+ value: toPickerHex(value),
2910
+ onChange: (event) => onChange(event.currentTarget.value)
2911
+ }
2912
+ ),
2913
+ /* @__PURE__ */ jsx30(
2914
+ "input",
2915
+ {
2916
+ id,
2917
+ type: "text",
2918
+ "aria-label": token.label,
2919
+ value: draft,
2920
+ pattern: "^#(?:[A-Fa-f0-9]{3}|[A-Fa-f0-9]{4}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{8})$",
2921
+ onChange: (event) => setDraft(event.currentTarget.value),
2922
+ onBlur: commit,
2923
+ onKeyDown: (event) => {
2924
+ if (event.key === "Enter") {
2925
+ event.preventDefault();
2926
+ event.currentTarget.blur();
2927
+ }
2928
+ }
2929
+ }
2930
+ )
2931
+ ] });
2932
+ }
2933
+ function NumberTokenControl({
2934
+ id,
2935
+ token,
2936
+ value,
2937
+ onChange
2938
+ }) {
2939
+ const [draft, setDraft] = useState12(String(value));
2940
+ useEffect10(() => setDraft(String(value)), [value]);
2941
+ const commit = () => {
2942
+ const nextValue = Number(draft);
2943
+ if (draft.trim() && isValidKitDesignValue(token, nextValue)) onChange(nextValue);
2944
+ else setDraft(String(value));
2945
+ };
2946
+ return /* @__PURE__ */ jsxs24("div", { className: "dos-kit-design-number-control", children: [
2947
+ /* @__PURE__ */ jsx30(
2948
+ "input",
2949
+ {
2950
+ id,
2951
+ type: "number",
2952
+ "aria-label": token.label,
2953
+ min: token.min,
2954
+ max: token.max,
2955
+ step: token.step,
2956
+ value: draft,
2957
+ onChange: (event) => setDraft(event.currentTarget.value),
2958
+ onBlur: commit,
2959
+ onKeyDown: (event) => {
2960
+ if (event.key === "Enter") {
2961
+ event.preventDefault();
2962
+ event.currentTarget.blur();
2963
+ }
2964
+ }
2965
+ }
2966
+ ),
2967
+ token.unit && /* @__PURE__ */ jsx30("span", { "aria-hidden": "true", children: token.unit })
2968
+ ] });
2969
+ }
2970
+ function groupTokens(tokens) {
2971
+ const groups = /* @__PURE__ */ new Map();
2972
+ for (const token of tokens) {
2973
+ const group = token.group?.trim() || "Design";
2974
+ groups.set(group, [...groups.get(group) ?? [], token]);
2975
+ }
2976
+ return [...groups.entries()];
2977
+ }
2978
+ function KitDesignPanel({ manifest, kitId, value, onChange }) {
2979
+ const currentValues = getKitDesignValues(manifest, kitId, value);
2980
+ const storedValues = value.tokens[kitId] ?? {};
2981
+ const activePreset = manifest.presets.find(
2982
+ (preset) => manifest.tokens.every(
2983
+ (token) => currentValues[token.id] === preset.values[token.id]
2984
+ )
2985
+ );
2986
+ const saveValues = (nextValues) => {
2987
+ onChange({
2988
+ ...value,
2989
+ tokens: {
2990
+ ...value.tokens,
2991
+ [kitId]: nextValues
2992
+ }
2993
+ });
2994
+ };
2995
+ const updateToken = (token, nextValue) => {
2996
+ if (!isValidKitDesignValue(token, nextValue)) return;
2997
+ saveValues({
2998
+ ...storedValues,
2999
+ ...resolveKitDesignValues(manifest, storedValues),
3000
+ [token.id]: nextValue
3001
+ });
3002
+ };
3003
+ const renderControl = (token) => {
3004
+ const id = `kit-design-${kitId}-${token.id}`;
3005
+ const tokenValue = currentValues[token.id];
3006
+ if (token.type === "color") {
3007
+ return /* @__PURE__ */ jsx30(
3008
+ ColorTokenControl,
3009
+ {
3010
+ id,
3011
+ token,
3012
+ value: tokenValue,
3013
+ onChange: (nextValue) => updateToken(token, nextValue)
3014
+ }
3015
+ );
3016
+ }
3017
+ if (token.type === "number") {
3018
+ return /* @__PURE__ */ jsx30(
3019
+ NumberTokenControl,
3020
+ {
3021
+ id,
3022
+ token,
3023
+ value: tokenValue,
3024
+ onChange: (nextValue) => updateToken(token, nextValue)
3025
+ }
3026
+ );
3027
+ }
3028
+ return /* @__PURE__ */ jsx30(
3029
+ "select",
3030
+ {
3031
+ id,
3032
+ "aria-label": token.label,
3033
+ value: tokenValue,
3034
+ onChange: (event) => updateToken(token, event.currentTarget.value),
3035
+ style: token.type === "font-family" ? { fontFamily: `"${tokenValue}", sans-serif` } : void 0,
3036
+ children: token.options.map((option) => /* @__PURE__ */ jsx30("option", { value: option.value, children: option.label }, option.value))
3037
+ }
3038
+ );
3039
+ };
3040
+ return /* @__PURE__ */ jsxs24("div", { className: "dos-kit-design-panel", "aria-label": manifest.name, children: [
3041
+ /* @__PURE__ */ jsxs24("section", { "aria-label": "Design presets", children: [
3042
+ /* @__PURE__ */ jsxs24("h3", { children: [
3043
+ manifest.name,
3044
+ " presets"
3045
+ ] }),
3046
+ /* @__PURE__ */ jsx30("div", { className: "dos-kit-design-presets", children: manifest.presets.map((preset) => /* @__PURE__ */ jsx30(
3047
+ "button",
3048
+ {
3049
+ type: "button",
3050
+ "aria-label": `Apply ${preset.name} preset`,
3051
+ "aria-pressed": activePreset?.id === preset.id,
3052
+ onClick: () => {
3053
+ const presetValues = applyKitDesignPreset(manifest, preset.id);
3054
+ if (presetValues) saveValues(presetValues);
3055
+ },
3056
+ children: preset.name
3057
+ },
3058
+ preset.id
3059
+ )) })
3060
+ ] }),
3061
+ groupTokens(manifest.tokens).map(([group, tokens]) => /* @__PURE__ */ jsxs24("fieldset", { className: "dos-kit-design-group", children: [
3062
+ /* @__PURE__ */ jsx30("legend", { children: group }),
3063
+ tokens.map((token) => /* @__PURE__ */ jsxs24("label", { className: "dos-kit-design-token", htmlFor: `kit-design-${kitId}-${token.id}`, children: [
3064
+ /* @__PURE__ */ jsxs24("span", { children: [
3065
+ token.label,
3066
+ token.description && /* @__PURE__ */ jsx30("small", { children: token.description })
3067
+ ] }),
3068
+ renderControl(token)
3069
+ ] }, token.id))
3070
+ ] }, group))
3071
+ ] });
3072
+ }
3073
+
3074
+ // src/components/design/DesignDrawer.tsx
3075
+ import { jsx as jsx31, jsxs as jsxs25 } from "react/jsx-runtime";
3076
+ function DesignDrawer({ design, value, onChange, open, onClose }) {
3077
+ const panelRef = useRef8(null);
3078
+ const [revision, setRevision] = useState13(design.expectedRevision);
3079
+ const [publishing, setPublishing] = useState13(false);
3080
+ const [status, setStatus] = useState13("");
3081
+ useEffect11(() => {
3082
+ if (!open) return;
3083
+ const onKeyDown = (event) => {
3084
+ if (event.key === "Escape") {
3085
+ event.preventDefault();
3086
+ onClose();
3087
+ }
3088
+ };
3089
+ const onMouseDown = (event) => {
3090
+ if (panelRef.current && !event.composedPath().includes(panelRef.current)) onClose();
3091
+ };
3092
+ window.addEventListener("keydown", onKeyDown);
3093
+ const timeout = window.setTimeout(() => window.addEventListener("mousedown", onMouseDown), 0);
3094
+ return () => {
3095
+ window.removeEventListener("keydown", onKeyDown);
3096
+ window.clearTimeout(timeout);
3097
+ window.removeEventListener("mousedown", onMouseDown);
3098
+ };
3099
+ }, [open, onClose]);
3100
+ async function publish() {
3101
+ if (publishing) return;
3102
+ setPublishing(true);
3103
+ setStatus("");
3104
+ try {
3105
+ const result = await design.publisher.publish({
3106
+ design: structuredClone(value),
3107
+ siteId: design.siteId,
3108
+ expectedRevision: revision
3109
+ });
3110
+ if (!result || typeof result.revision !== "string" || result.revision.length === 0) {
3111
+ throw new Error("The design publisher did not return a valid revision.");
3112
+ }
3113
+ setRevision(result.revision);
3114
+ setStatus("Design published.");
3115
+ } catch (error) {
3116
+ setStatus(`Publish failed: ${error instanceof Error ? error.message : String(error)}`);
3117
+ } finally {
3118
+ setPublishing(false);
3119
+ }
3120
+ }
3121
+ return /* @__PURE__ */ jsxs25(
3122
+ "aside",
3123
+ {
3124
+ ref: panelRef,
3125
+ "aria-label": "Site design",
3126
+ "aria-hidden": !open,
3127
+ className: `dos-design-drawer ${open ? "is-open" : ""}`,
3128
+ children: [
3129
+ /* @__PURE__ */ jsxs25("div", { className: "dos-design-header", children: [
3130
+ /* @__PURE__ */ jsxs25("div", { children: [
3131
+ /* @__PURE__ */ jsx31("strong", { children: "Site Design" }),
3132
+ /* @__PURE__ */ jsx31("span", { children: "Shared design settings" })
3133
+ ] }),
3134
+ /* @__PURE__ */ jsx31("button", { type: "button", onClick: onClose, "aria-label": "Close site design", children: "\xD7" })
3135
+ ] }),
3136
+ /* @__PURE__ */ jsx31("div", { className: "dos-design-content", children: design.manifest !== void 0 ? /* @__PURE__ */ jsx31(
3137
+ KitDesignPanel,
3138
+ {
3139
+ manifest: design.manifest,
3140
+ kitId: design.kitId,
3141
+ value,
3142
+ onChange: (next) => {
3143
+ onChange(next);
3144
+ setStatus("");
3145
+ }
3146
+ }
3147
+ ) : /* @__PURE__ */ jsx31(
3148
+ design.Panel,
3149
+ {
3150
+ value,
3151
+ onChange: (next) => {
3152
+ onChange(next);
3153
+ setStatus("");
3154
+ }
3155
+ }
3156
+ ) }),
3157
+ /* @__PURE__ */ jsxs25("div", { className: "dos-design-footer", children: [
3158
+ /* @__PURE__ */ jsx31("small", { children: "Changes update the preview immediately. They are not saved until you publish design." }),
3159
+ status && /* @__PURE__ */ jsx31("div", { role: "status", "aria-live": "polite", children: status }),
3160
+ /* @__PURE__ */ jsx31("button", { type: "button", className: "dos-primary-button", onClick: () => void publish(), disabled: publishing, "aria-busy": publishing, children: publishing ? "Publishing design\u2026" : "Publish Design" })
3161
+ ] })
3162
+ ]
3163
+ }
3164
+ );
3165
+ }
3166
+
3167
+ // src/components/Editor.tsx
3168
+ import { Fragment as Fragment6, jsx as jsx32, jsxs as jsxs26 } from "react/jsx-runtime";
3169
+ function canHaveGenericChildren(root, registry, parentId) {
3170
+ if (parentId === root.id) return true;
3171
+ const parent = findNode4(root, parentId)?.node;
3172
+ return Boolean(parent && registry.get(parent.type)?.capabilities?.canHaveChildren);
3173
+ }
3174
+ function EditorContent({ registry, components, preview, draftStorageKey, publisher, pageId, expectedRevision, history, agent, agentPermissions, design, appearance, onToggleAppearance }) {
3175
+ const previewMode = useEditorStore((state) => state.previewMode);
3176
+ const designOpen = useEditorStore((state) => state.designOpen);
3177
+ const toggleDesign = useEditorStore((state) => state.toggleDesign);
3178
+ const [designValue, setDesignValue] = useState14(() => design ? structuredClone(design.initialValue) : void 0);
3179
+ const [mobilePanel, setMobilePanel] = useState14("canvas");
3180
+ const designPreviewStyles = design && designValue ? design.getPreviewStyles?.(designValue) ?? (design.manifest !== void 0 ? projectKitDesignStyles(design.manifest, design.kitId, designValue) : void 0) : void 0;
3181
+ useKeyboardShortcuts(!previewMode);
3182
+ const restore = useRestorePage(registry, draftStorageKey);
3183
+ const restoreStatus = restore.status;
3184
+ useAutosave(restoreStatus === "ready", registry, draftStorageKey);
3185
+ useHistoryPersistence({ pageId, history, enabled: restoreStatus === "ready" });
3186
+ const page = useEditorStore((state) => state.page);
3187
+ const addNode2 = useEditorStore((state) => state.addNode);
3188
+ const jsonDrawerOpen = useEditorStore((state) => state.jsonDrawerOpen);
3189
+ const [dragMessage, setDragMessage] = useState14("");
3190
+ const handleAdd = (componentType) => {
3191
+ const node = createNodeFromManifest2(registry.getOrThrow(componentType));
3192
+ addNode2(page.root.id, node);
3193
+ };
3194
+ const handleDragEnd = (event) => {
3195
+ if (!event.over) return;
3196
+ const source = event.active.data.current;
3197
+ const target = event.over.data.current;
3198
+ if (!source || !target) return;
3199
+ const root = useEditorStore.getState().page.root;
3200
+ const state = useEditorStore.getState();
3201
+ const addToTarget = (node, parentId, slotName) => {
3202
+ if (slotName) {
3203
+ const error = getSlotDropError(root, registry, parentId, slotName, node.type);
3204
+ if (error) setDragMessage(error);
3205
+ else state.addNode(parentId, node, slotName);
3206
+ } else if (canHaveGenericChildren(root, registry, parentId)) {
3207
+ state.addNode(parentId, node);
3208
+ } else {
3209
+ setDragMessage("This component does not accept generic children.");
3210
+ }
3211
+ };
3212
+ if (source.kind === "component") {
3213
+ const node = createNodeFromManifest2(registry.getOrThrow(source.componentType));
3214
+ if (target.kind === "children") addToTarget(node, target.parentId);
3215
+ else if (target.kind === "slot") addToTarget(node, target.parentId, target.slotName);
3216
+ else if (target.kind === "node") addToTarget(node, target.parentId, target.slotName);
3217
+ return;
3218
+ }
3219
+ if (source.kind !== "node") return;
3220
+ if (target.kind === "node" && source.nodeId === target.nodeId) return;
3221
+ if (target.kind === "children") {
3222
+ const sourceError = getSourceSlotRemovalError(root, registry, source);
3223
+ if (sourceError) setDragMessage(sourceError);
3224
+ else if (!canHaveGenericChildren(root, registry, target.parentId)) setDragMessage("This component does not accept generic children.");
3225
+ else state.moveNode(source.nodeId, target.parentId);
3226
+ return;
3227
+ }
3228
+ if (target.kind === "slot") {
3229
+ const moving = findNode4(root, source.nodeId)?.node;
3230
+ if (!moving) return;
3231
+ const error = getSlotDropError(root, registry, target.parentId, target.slotName, moving.type, source);
3232
+ if (error) setDragMessage(error);
3233
+ else state.moveNode(source.nodeId, target.parentId, target.slotName);
3234
+ return;
3235
+ }
3236
+ if (target.kind === "node") {
3237
+ if (source.parentId === target.parentId && source.slotName === target.slotName) {
3238
+ state.reorderNode(target.parentId, source.index, target.index, target.slotName);
3239
+ return;
3240
+ }
3241
+ const moving = findNode4(root, source.nodeId)?.node;
3242
+ if (!moving) return;
3243
+ if (target.slotName) {
3244
+ const error = getSlotDropError(root, registry, target.parentId, target.slotName, moving.type, source);
3245
+ if (error) setDragMessage(error);
3246
+ else state.moveNode(source.nodeId, target.parentId, target.slotName);
3247
+ } else {
3248
+ const sourceError = getSourceSlotRemovalError(root, registry, source);
3249
+ if (sourceError) setDragMessage(sourceError);
3250
+ else if (!canHaveGenericChildren(root, registry, target.parentId)) setDragMessage("This component does not accept generic children.");
3251
+ else state.moveNode(source.nodeId, target.parentId);
3252
+ }
3253
+ }
3254
+ };
3255
+ return /* @__PURE__ */ jsxs26(Fragment6, { children: [
3256
+ /* @__PURE__ */ jsx32(Toolbar, { publisher, pageId, expectedRevision, agent, hasDesign: Boolean(design), appearance, onToggleAppearance }),
3257
+ restoreStatus === "blocked" && /* @__PURE__ */ jsxs26("div", { role: "alert", style: { padding: "10px 16px", background: "#fff7ed", color: "#7c2d12", borderBottom: "1px solid #fdba74" }, children: [
3258
+ "Saved page could not be safely restored. The original data is preserved and autosave is disabled.",
3259
+ /* @__PURE__ */ jsx32("button", { type: "button", onClick: () => downloadSavedPage(draftStorageKey), style: { marginLeft: 12 }, children: "Download saved data" }),
3260
+ /* @__PURE__ */ jsx32("button", { type: "button", onClick: () => {
3261
+ if (window.confirm("Discard the preserved saved page and start with a blank page? This cannot be undone.")) {
3262
+ restore.startFreshAfterDiscardingSavedData();
3263
+ }
3264
+ }, style: { marginLeft: 8 }, children: "Discard saved data and start fresh" })
3265
+ ] }),
3266
+ /* @__PURE__ */ jsxs26(EditorDndProvider, { onDragEnd: handleDragEnd, children: [
3267
+ dragMessage && /* @__PURE__ */ jsx32("div", { role: "status", "aria-live": "polite", style: { position: "fixed", top: 64, left: "50%", transform: "translateX(-50%)", zIndex: 1e3, padding: "8px 12px", borderRadius: 6, background: "#7f1d1d", color: "white" }, children: dragMessage }),
3268
+ /* @__PURE__ */ jsx32(
3269
+ EditorLayout,
3270
+ {
3271
+ mobilePanel,
3272
+ sidebar: !previewMode && /* @__PURE__ */ jsx32(
3273
+ Sidebar,
3274
+ {
3275
+ components: /* @__PURE__ */ jsx32(ComponentLibrary, { registry, onAdd: handleAdd }),
3276
+ layers: /* @__PURE__ */ jsx32(LayersPanel, { registry })
3277
+ }
3278
+ ),
3279
+ canvas: /* @__PURE__ */ jsx32(MainPanel, { children: /* @__PURE__ */ jsx32(Canvas, { page, registry, components, preview, previewMode, previewStyles: designPreviewStyles }) }),
3280
+ inspector: !previewMode && /* @__PURE__ */ jsx32(InspectorPanel, { children: /* @__PURE__ */ jsx32(PropertyPanel, { registry }) })
3281
+ }
3282
+ ),
3283
+ !previewMode && /* @__PURE__ */ jsx32("nav", { className: "dos-mobile-nav", "aria-label": "Workspace panels", children: ["structure", "canvas", "properties"].map((panel) => /* @__PURE__ */ jsxs26("button", { type: "button", "aria-pressed": mobilePanel === panel, onClick: () => setMobilePanel(panel), children: [
3284
+ /* @__PURE__ */ jsx32(EditorIcon, { name: panel === "structure" ? "layers" : panel === "canvas" ? "canvas" : "properties", size: 19 }),
3285
+ /* @__PURE__ */ jsx32("span", { children: panel === "structure" ? "Structure" : panel === "canvas" ? "Canvas" : "Properties" })
3286
+ ] }, panel)) })
3287
+ ] }),
3288
+ !previewMode && jsonDrawerOpen && /* @__PURE__ */ jsx32(JsonDrawer, { registry }),
3289
+ /* @__PURE__ */ jsx32(HistoryDrawer, {}),
3290
+ agent && /* @__PURE__ */ jsx32(PageAssistant, { agent, registry, pageId, permissions: agentPermissions, baseRevision: expectedRevision }),
3291
+ design && designValue && /* @__PURE__ */ jsx32(DesignDrawer, { design, value: designValue, onChange: setDesignValue, open: designOpen, onClose: toggleDesign })
3292
+ ] });
3293
+ }
3294
+ function Editor({ isolateStyles = true, ...props }) {
3295
+ const { appearance, toggleAppearance } = useEditorAppearance();
3296
+ const content = /* @__PURE__ */ jsx32(EditorContent, { ...props, appearance, onToggleAppearance: toggleAppearance });
3297
+ return isolateStyles ? /* @__PURE__ */ jsx32(EditorStyleBoundary, { appearance, children: content }) : content;
3298
+ }
3299
+
3300
+ // src/hooks/useEditor.ts
3301
+ var useEditor = useEditorStore;
3302
+ export {
3303
+ Editor,
3304
+ PageAssistant,
3305
+ projectPublicComponents,
3306
+ summarizePageChanges,
3307
+ useAutosave,
3308
+ useEditor,
3309
+ useEditorStore,
3310
+ useHistoryPersistence,
3311
+ useKeyboardShortcuts,
3312
+ useRestorePage,
3313
+ useSelectedNode,
3314
+ validatePageAgentState
3315
+ };
3316
+ //# sourceMappingURL=index.js.map