@designos/editor 0.1.0 → 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.d.ts +23 -13
- package/dist/index.js +333 -47
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { ComponentType } from 'react';
|
|
3
3
|
import * as _designos_core from '@designos/core';
|
|
4
|
-
import { PageDocument, ComponentRegistry, PageNode } from '@designos/core';
|
|
4
|
+
import { PageDocument, DesignDocument, KitDesignManifest, ComponentRegistry, PageNode } from '@designos/core';
|
|
5
5
|
import * as zustand from 'zustand';
|
|
6
6
|
|
|
7
7
|
interface EditorPreviewOptions {
|
|
@@ -33,8 +33,8 @@ interface PagePublisher {
|
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
interface DesignPublishInput {
|
|
36
|
-
/** JSON-serializable site-wide design
|
|
37
|
-
design:
|
|
36
|
+
/** Versioned, JSON-serializable site-wide design document supplied by the host. */
|
|
37
|
+
design: DesignDocument;
|
|
38
38
|
/** Stable host-owned identity for the site or design being published. */
|
|
39
39
|
siteId: string;
|
|
40
40
|
/** Optional optimistic-concurrency token returned by the host previously. */
|
|
@@ -50,23 +50,33 @@ interface DesignPublisher {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
interface DesignPanelProps {
|
|
53
|
-
/** Temporary
|
|
54
|
-
value:
|
|
55
|
-
onChange(value:
|
|
53
|
+
/** Temporary versioned design value. It is not page history or autosaved. */
|
|
54
|
+
value: DesignDocument;
|
|
55
|
+
onChange(value: DesignDocument): void;
|
|
56
56
|
}
|
|
57
|
-
interface
|
|
58
|
-
/** Initial design
|
|
59
|
-
initialValue:
|
|
57
|
+
interface EditorDesignBaseOptions {
|
|
58
|
+
/** Initial versioned design document for this editor session. */
|
|
59
|
+
initialValue: DesignDocument;
|
|
60
60
|
/** Stable host-owned site or design identifier. */
|
|
61
61
|
siteId: string;
|
|
62
|
-
/**
|
|
63
|
-
|
|
64
|
-
/** Convert the current design to CSS applied only inside the iframe preview. */
|
|
65
|
-
getPreviewStyles?: (value: unknown) => string;
|
|
62
|
+
/** Override the built-in kit-manifest CSS-variable projection. */
|
|
63
|
+
getPreviewStyles?: (value: DesignDocument) => string;
|
|
66
64
|
/** Host-owned persistence/publishing behavior. */
|
|
67
65
|
publisher: DesignPublisher;
|
|
68
66
|
expectedRevision?: string;
|
|
69
67
|
}
|
|
68
|
+
type EditorDesignOptions = EditorDesignBaseOptions & ({
|
|
69
|
+
/** Legacy or host-specific controls for a design schema. */
|
|
70
|
+
Panel: ComponentType<DesignPanelProps>;
|
|
71
|
+
manifest?: never;
|
|
72
|
+
kitId?: never;
|
|
73
|
+
} | {
|
|
74
|
+
/** Declarative kit schema rendered by the editor's standard controls. */
|
|
75
|
+
manifest: KitDesignManifest;
|
|
76
|
+
/** Stable package ID used as the design-document token group. */
|
|
77
|
+
kitId: string;
|
|
78
|
+
Panel?: never;
|
|
79
|
+
});
|
|
70
80
|
|
|
71
81
|
interface PageHistoryEntry {
|
|
72
82
|
/** Stable identity for this snapshot within the page history. */
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/components/Editor.tsx
|
|
2
|
-
import { useState as
|
|
2
|
+
import { useState as useState14 } from "react";
|
|
3
3
|
|
|
4
4
|
// src/hooks/useEditorAppearance.ts
|
|
5
5
|
import { useCallback, useEffect, useState } from "react";
|
|
@@ -210,6 +210,22 @@ var EDITOR_BASE_STYLES = `
|
|
|
210
210
|
:host .dos-design-content { flex: 1; overflow: auto; padding: 16px; }
|
|
211
211
|
:host .dos-design-footer { padding: 12px 16px; border-top: 1px solid var(--dos-border) !important; display: flex; flex-direction: column; gap: 8px; }
|
|
212
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; }
|
|
213
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; }
|
|
214
230
|
:host .dos-history-drawer.is-open { transform: translateX(0); pointer-events: auto; }
|
|
215
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; }
|
|
@@ -2802,14 +2818,267 @@ Version created: ${result.applied.summary}` : result.message;
|
|
|
2802
2818
|
}
|
|
2803
2819
|
|
|
2804
2820
|
// src/components/design/DesignDrawer.tsx
|
|
2805
|
-
import { useEffect as
|
|
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
|
|
2806
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";
|
|
2807
3076
|
function DesignDrawer({ design, value, onChange, open, onClose }) {
|
|
2808
3077
|
const panelRef = useRef8(null);
|
|
2809
|
-
const [revision, setRevision] =
|
|
2810
|
-
const [publishing, setPublishing] =
|
|
2811
|
-
const [status, setStatus] =
|
|
2812
|
-
|
|
3078
|
+
const [revision, setRevision] = useState13(design.expectedRevision);
|
|
3079
|
+
const [publishing, setPublishing] = useState13(false);
|
|
3080
|
+
const [status, setStatus] = useState13("");
|
|
3081
|
+
useEffect11(() => {
|
|
2813
3082
|
if (!open) return;
|
|
2814
3083
|
const onKeyDown = (event) => {
|
|
2815
3084
|
if (event.key === "Escape") {
|
|
@@ -2849,8 +3118,7 @@ function DesignDrawer({ design, value, onChange, open, onClose }) {
|
|
|
2849
3118
|
setPublishing(false);
|
|
2850
3119
|
}
|
|
2851
3120
|
}
|
|
2852
|
-
|
|
2853
|
-
return /* @__PURE__ */ jsxs24(
|
|
3121
|
+
return /* @__PURE__ */ jsxs25(
|
|
2854
3122
|
"aside",
|
|
2855
3123
|
{
|
|
2856
3124
|
ref: panelRef,
|
|
@@ -2858,21 +3126,38 @@ function DesignDrawer({ design, value, onChange, open, onClose }) {
|
|
|
2858
3126
|
"aria-hidden": !open,
|
|
2859
3127
|
className: `dos-design-drawer ${open ? "is-open" : ""}`,
|
|
2860
3128
|
children: [
|
|
2861
|
-
/* @__PURE__ */
|
|
2862
|
-
/* @__PURE__ */
|
|
2863
|
-
/* @__PURE__ */
|
|
2864
|
-
/* @__PURE__ */
|
|
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" })
|
|
2865
3133
|
] }),
|
|
2866
|
-
/* @__PURE__ */
|
|
3134
|
+
/* @__PURE__ */ jsx31("button", { type: "button", onClick: onClose, "aria-label": "Close site design", children: "\xD7" })
|
|
2867
3135
|
] }),
|
|
2868
|
-
/* @__PURE__ */
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
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" })
|
|
2876
3161
|
] })
|
|
2877
3162
|
]
|
|
2878
3163
|
}
|
|
@@ -2880,7 +3165,7 @@ function DesignDrawer({ design, value, onChange, open, onClose }) {
|
|
|
2880
3165
|
}
|
|
2881
3166
|
|
|
2882
3167
|
// src/components/Editor.tsx
|
|
2883
|
-
import { Fragment as Fragment6, jsx as
|
|
3168
|
+
import { Fragment as Fragment6, jsx as jsx32, jsxs as jsxs26 } from "react/jsx-runtime";
|
|
2884
3169
|
function canHaveGenericChildren(root, registry, parentId) {
|
|
2885
3170
|
if (parentId === root.id) return true;
|
|
2886
3171
|
const parent = findNode4(root, parentId)?.node;
|
|
@@ -2890,8 +3175,9 @@ function EditorContent({ registry, components, preview, draftStorageKey, publish
|
|
|
2890
3175
|
const previewMode = useEditorStore((state) => state.previewMode);
|
|
2891
3176
|
const designOpen = useEditorStore((state) => state.designOpen);
|
|
2892
3177
|
const toggleDesign = useEditorStore((state) => state.toggleDesign);
|
|
2893
|
-
const [designValue, setDesignValue] =
|
|
2894
|
-
const [mobilePanel, setMobilePanel] =
|
|
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;
|
|
2895
3181
|
useKeyboardShortcuts(!previewMode);
|
|
2896
3182
|
const restore = useRestorePage(registry, draftStorageKey);
|
|
2897
3183
|
const restoreStatus = restore.status;
|
|
@@ -2900,7 +3186,7 @@ function EditorContent({ registry, components, preview, draftStorageKey, publish
|
|
|
2900
3186
|
const page = useEditorStore((state) => state.page);
|
|
2901
3187
|
const addNode2 = useEditorStore((state) => state.addNode);
|
|
2902
3188
|
const jsonDrawerOpen = useEditorStore((state) => state.jsonDrawerOpen);
|
|
2903
|
-
const [dragMessage, setDragMessage] =
|
|
3189
|
+
const [dragMessage, setDragMessage] = useState14("");
|
|
2904
3190
|
const handleAdd = (componentType) => {
|
|
2905
3191
|
const node = createNodeFromManifest2(registry.getOrThrow(componentType));
|
|
2906
3192
|
addNode2(page.root.id, node);
|
|
@@ -2966,49 +3252,49 @@ function EditorContent({ registry, components, preview, draftStorageKey, publish
|
|
|
2966
3252
|
}
|
|
2967
3253
|
}
|
|
2968
3254
|
};
|
|
2969
|
-
return /* @__PURE__ */
|
|
2970
|
-
/* @__PURE__ */
|
|
2971
|
-
restoreStatus === "blocked" && /* @__PURE__ */
|
|
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: [
|
|
2972
3258
|
"Saved page could not be safely restored. The original data is preserved and autosave is disabled.",
|
|
2973
|
-
/* @__PURE__ */
|
|
2974
|
-
/* @__PURE__ */
|
|
3259
|
+
/* @__PURE__ */ jsx32("button", { type: "button", onClick: () => downloadSavedPage(draftStorageKey), style: { marginLeft: 12 }, children: "Download saved data" }),
|
|
3260
|
+
/* @__PURE__ */ jsx32("button", { type: "button", onClick: () => {
|
|
2975
3261
|
if (window.confirm("Discard the preserved saved page and start with a blank page? This cannot be undone.")) {
|
|
2976
3262
|
restore.startFreshAfterDiscardingSavedData();
|
|
2977
3263
|
}
|
|
2978
3264
|
}, style: { marginLeft: 8 }, children: "Discard saved data and start fresh" })
|
|
2979
3265
|
] }),
|
|
2980
|
-
/* @__PURE__ */
|
|
2981
|
-
dragMessage && /* @__PURE__ */
|
|
2982
|
-
/* @__PURE__ */
|
|
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(
|
|
2983
3269
|
EditorLayout,
|
|
2984
3270
|
{
|
|
2985
3271
|
mobilePanel,
|
|
2986
|
-
sidebar: !previewMode && /* @__PURE__ */
|
|
3272
|
+
sidebar: !previewMode && /* @__PURE__ */ jsx32(
|
|
2987
3273
|
Sidebar,
|
|
2988
3274
|
{
|
|
2989
|
-
components: /* @__PURE__ */
|
|
2990
|
-
layers: /* @__PURE__ */
|
|
3275
|
+
components: /* @__PURE__ */ jsx32(ComponentLibrary, { registry, onAdd: handleAdd }),
|
|
3276
|
+
layers: /* @__PURE__ */ jsx32(LayersPanel, { registry })
|
|
2991
3277
|
}
|
|
2992
3278
|
),
|
|
2993
|
-
canvas: /* @__PURE__ */
|
|
2994
|
-
inspector: !previewMode && /* @__PURE__ */
|
|
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 }) })
|
|
2995
3281
|
}
|
|
2996
3282
|
),
|
|
2997
|
-
!previewMode && /* @__PURE__ */
|
|
2998
|
-
/* @__PURE__ */
|
|
2999
|
-
/* @__PURE__ */
|
|
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" })
|
|
3000
3286
|
] }, panel)) })
|
|
3001
3287
|
] }),
|
|
3002
|
-
!previewMode && jsonDrawerOpen && /* @__PURE__ */
|
|
3003
|
-
/* @__PURE__ */
|
|
3004
|
-
agent && /* @__PURE__ */
|
|
3005
|
-
design && /* @__PURE__ */
|
|
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 })
|
|
3006
3292
|
] });
|
|
3007
3293
|
}
|
|
3008
3294
|
function Editor({ isolateStyles = true, ...props }) {
|
|
3009
3295
|
const { appearance, toggleAppearance } = useEditorAppearance();
|
|
3010
|
-
const content = /* @__PURE__ */
|
|
3011
|
-
return isolateStyles ? /* @__PURE__ */
|
|
3296
|
+
const content = /* @__PURE__ */ jsx32(EditorContent, { ...props, appearance, onToggleAppearance: toggleAppearance });
|
|
3297
|
+
return isolateStyles ? /* @__PURE__ */ jsx32(EditorStyleBoundary, { appearance, children: content }) : content;
|
|
3012
3298
|
}
|
|
3013
3299
|
|
|
3014
3300
|
// src/hooks/useEditor.ts
|