@perkyzz/emvb 1.0.0 → 1.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/README.md +9 -0
- package/THIRD_PARTY_NOTICES.md +1 -0
- package/package.json +10 -9
- package/src/admin/agents-api.ts +5 -1
- package/src/admin/bulk-api.ts +67 -0
- package/src/admin/content-api.ts +39 -6
- package/src/admin/copy-rich-text.ts +119 -0
- package/src/admin/dialog-tab-wrap.ts +78 -0
- package/src/admin/editor/A11yCopilot.tsx +2 -0
- package/src/admin/editor/Editor.tsx +24 -7
- package/src/admin/editor/ScheduleDialog.tsx +167 -0
- package/src/admin/editor/Timeline.tsx +6 -2
- package/src/admin/editor/TopBar.tsx +60 -8
- package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +22 -9
- package/src/admin/editor/canvas/canvas-scale.ts +3 -3
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/dnd/new-element.ts +68 -0
- package/src/admin/editor/editor-chrome.tsx +16 -5
- package/src/admin/editor/editor-commands.ts +10 -4
- package/src/admin/editor/editor-css.ts +2 -1
- package/src/admin/editor/element-chrome.ts +22 -0
- package/src/admin/editor/panels/ElementPanel.tsx +34 -17
- package/src/admin/editor/panels/SettingsPanel.tsx +2 -2
- package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
- package/src/admin/editor/panels/settings/EffectsControls.tsx +79 -1
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
- package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
- package/src/admin/editor/panels/settings/IconControls.tsx +11 -0
- package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +36 -2
- package/src/admin/editor/panels/settings/LengthRow.tsx +36 -3
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +18 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +7 -0
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- package/src/admin/editor/panels/settings/length-units.ts +15 -3
- package/src/admin/editor/panels/settings/style-sections.ts +1 -0
- package/src/admin/editor/panels/style-target.ts +17 -4
- package/src/admin/editor/section-templates.ts +26 -4
- package/src/admin/editor/store.ts +15 -3
- package/src/admin/editor/useEditorCommands.ts +7 -5
- package/src/admin/editor/useEditorData.ts +4 -0
- package/src/admin/editor/useNodeActions.ts +4 -2
- package/src/admin/editor/useSave.ts +47 -3
- package/src/admin/export-api.ts +238 -0
- package/src/admin/index.tsx +6 -1
- package/src/admin/menus-api.ts +113 -0
- package/src/admin/pages/ExportDialog.tsx +395 -0
- package/src/admin/pages/ImportElementorDialog.tsx +25 -1
- package/src/admin/pages/PageList.tsx +67 -2
- package/src/admin/pages/ThemePartList.tsx +37 -1
- package/src/admin/pages/bulk.tsx +303 -0
- package/src/admin/search.ts +20 -0
- package/src/admin/theme-api.ts +4 -0
- package/src/admin/ui.ts +11 -2
- package/src/admin/widgets/CanvasField.tsx +8 -0
- package/src/admin/widgets/ConvertToRichText.tsx +136 -0
- package/src/admin/widgets/ExportEntryHtml.tsx +92 -0
- package/src/admin/widgets/convert-body.ts +73 -2
- package/src/astro/EmVBPage.astro +3 -0
- package/src/astro/render.ts +47 -22
- package/src/astro/request-data.ts +3 -0
- package/src/astro/resolve-theme.ts +88 -51
- package/src/astro/tabs/runtime.ts +16 -6
- package/src/astro/visitor.ts +23 -4
- package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
- package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +19 -0
- package/src/astro/widgets/alerts.ts +37 -0
- package/src/astro/widgets/carousel.ts +167 -0
- package/src/astro/widgets/index.ts +1 -0
- package/src/astro/widgets/lightbox.ts +123 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +103 -3
- package/src/core/arrange.ts +57 -1
- package/src/core/bounded-array.ts +16 -13
- package/src/core/contract.ts +26 -3
- package/src/core/css/generate.ts +83 -21
- package/src/core/css/scope.ts +10 -2
- package/src/core/css/trace.ts +33 -8
- package/src/core/design/classes.ts +25 -5
- package/src/core/design/devices.ts +78 -2
- package/src/core/design/variables.ts +14 -1
- package/src/core/elements/icon-svg.ts +135 -0
- package/src/core/elements/index.ts +33 -127
- package/src/core/elements/widgets.ts +907 -0
- package/src/core/export/runtimes.generated.ts +12 -0
- package/src/core/export/site.ts +579 -0
- package/src/core/export/zip.ts +95 -0
- package/src/core/extensions/schema.ts +2 -1
- package/src/core/geo-trust.ts +18 -0
- package/src/core/history/diff.ts +25 -0
- package/src/core/icons/social.generated.ts +29 -0
- package/src/core/image-edit/schema.ts +2 -1
- package/src/core/import/elementor/atomic.ts +22 -9
- package/src/core/import/elementor/context.ts +18 -0
- package/src/core/import/elementor/index.ts +72 -11
- package/src/core/import/elementor/style.ts +21 -1
- package/src/core/import/elementor/widgets.ts +394 -133
- package/src/core/index.ts +14 -0
- package/src/core/issue-cap.ts +19 -0
- package/src/core/json-schema.ts +8 -1
- package/src/core/limits.ts +6 -0
- package/src/core/loop-collections.ts +33 -0
- package/src/core/perf/meter.ts +37 -19
- package/src/core/portable-text-export.ts +243 -0
- package/src/core/proposals.ts +8 -2
- package/src/core/public-attributes.ts +30 -0
- package/src/core/render/index.ts +115 -13
- package/src/core/render/tabs.ts +18 -11
- package/src/core/render/vnode.ts +44 -6
- package/src/core/sanitize/css.ts +26 -0
- package/src/core/sanitize/svg-upload.ts +276 -23
- package/src/core/sanitize/svg.ts +3 -3
- package/src/core/schema/descriptors.ts +4 -0
- package/src/core/schema/design.ts +8 -7
- package/src/core/schema/layout.ts +406 -18
- package/src/core/schema/style.ts +49 -1
- package/src/core/search-text.ts +70 -0
- package/src/core/shadowing-ids.ts +41 -0
- package/src/core/theme/conditions.ts +2 -1
- package/src/core/theme/float.ts +1 -0
- package/src/core/theme/parse-doc.ts +10 -5
- package/src/core/theme/popup-rules.ts +16 -0
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/validate.ts +3 -2
- package/src/index.ts +23 -2
- package/src/mcp/ports.ts +18 -7
- package/src/mcp/proposals.ts +36 -11
- package/src/mcp/read.ts +2 -3
- package/src/mcp/tools.ts +1 -1
- package/src/server/agent-settings.ts +12 -1
- package/src/server/hooks.ts +41 -6
- package/src/server/icon-routes.ts +52 -12
- package/src/server/mcp-routes.ts +11 -5
- package/src/server/plugin.ts +27 -2
- package/src/server/presence.ts +5 -1
- package/src/server/proposals.ts +16 -4
- package/src/server/requests.ts +60 -11
- package/src/server/site-origin.ts +13 -0
- package/src/server/targets.ts +26 -0
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
type LengthLiteral,
|
|
14
14
|
type LengthUnit,
|
|
15
15
|
type UnitChoice,
|
|
16
|
+
isViewportUnit,
|
|
16
17
|
} from "./length-units.ts";
|
|
17
18
|
import type { StyleKey } from "./style-sections.ts";
|
|
18
19
|
import { bindKind, boundRef, lengthRef, VariableButton, VariableChip } from "./VariableBinding.tsx";
|
|
@@ -45,6 +46,7 @@ export function LengthRow({
|
|
|
45
46
|
slider = false,
|
|
46
47
|
onPatch,
|
|
47
48
|
reset,
|
|
49
|
+
viewportUnits,
|
|
48
50
|
}: {
|
|
49
51
|
styleKey: StyleKey;
|
|
50
52
|
label: string;
|
|
@@ -57,14 +59,24 @@ export function LengthRow({
|
|
|
57
59
|
slider?: boolean;
|
|
58
60
|
onPatch: (patch: Partial<FlatStyleProps>) => void;
|
|
59
61
|
reset: React.ReactNode;
|
|
62
|
+
/** W-974: the record's dvh/svh marks; a marked `vh` length shows as that unit. */
|
|
63
|
+
viewportUnits?: FlatStyleProps["viewportUnits"];
|
|
60
64
|
}) {
|
|
61
65
|
const units = unitsFor(styleKey);
|
|
62
66
|
// W-213: a plain number is a unitless line height, shown with the `x` unit.
|
|
63
67
|
// W-603: memoized, so a plain number doesn't make a new object each render; the effect below
|
|
64
68
|
// would reset the draft on every keystroke and nothing typed over a unitless value would stick.
|
|
69
|
+
const marked = viewportUnits?.[styleKey as keyof NonNullable<typeof viewportUnits>];
|
|
65
70
|
const literal = React.useMemo<{ value: number; unit: NumericUnit } | undefined>(
|
|
66
|
-
() =>
|
|
67
|
-
|
|
71
|
+
() =>
|
|
72
|
+
isLiteral(value)
|
|
73
|
+
? value.unit === "vh" && marked
|
|
74
|
+
? { value: value.value, unit: marked }
|
|
75
|
+
: value
|
|
76
|
+
: typeof value === "number"
|
|
77
|
+
? { value, unit: "x" }
|
|
78
|
+
: undefined,
|
|
79
|
+
[value, marked],
|
|
68
80
|
);
|
|
69
81
|
// W-955: a fluid size shows as "32–56" in px.
|
|
70
82
|
const fluid = isFluid(value) ? value : undefined;
|
|
@@ -82,7 +94,28 @@ export function LengthRow({
|
|
|
82
94
|
}, [value, literal]);
|
|
83
95
|
|
|
84
96
|
const send = (next: LengthLiteral | FluidLiteral | "auto" | number | undefined) => {
|
|
85
|
-
|
|
97
|
+
// W-974: dvh and svh are stored as vh plus the record's mark, so 1.0 still draws vh.
|
|
98
|
+
const nextUnit = isLiteral(next) ? next.unit : undefined;
|
|
99
|
+
const stored =
|
|
100
|
+
isLiteral(next) && isViewportUnit(nextUnit)
|
|
101
|
+
? { value: next.value, unit: "vh" as const }
|
|
102
|
+
: next;
|
|
103
|
+
const marks = { ...viewportUnits } as Record<string, string>;
|
|
104
|
+
if (isViewportUnit(nextUnit)) marks[styleKey] = nextUnit;
|
|
105
|
+
else delete marks[styleKey];
|
|
106
|
+
const marksChanged = (marks[styleKey] ?? null) !== (marked ?? null);
|
|
107
|
+
if (same(stored, value) && !marksChanged) return;
|
|
108
|
+
onPatch({
|
|
109
|
+
[styleKey]: stored,
|
|
110
|
+
...(marksChanged
|
|
111
|
+
? {
|
|
112
|
+
viewportUnits:
|
|
113
|
+
Object.keys(marks).length > 0
|
|
114
|
+
? (marks as FlatStyleProps["viewportUnits"])
|
|
115
|
+
: undefined,
|
|
116
|
+
}
|
|
117
|
+
: {}),
|
|
118
|
+
});
|
|
86
119
|
};
|
|
87
120
|
|
|
88
121
|
const commit = () => {
|
|
@@ -56,6 +56,7 @@ export function LoopItemBindControl({
|
|
|
56
56
|
|
|
57
57
|
if (parts && parts.length > 0) {
|
|
58
58
|
const known = parts.some((part) => part.id === value);
|
|
59
|
+
const chosen = parts.find((part) => part.id === value);
|
|
59
60
|
const selectValue = value === "" ? NONE : known ? value : MANUAL;
|
|
60
61
|
return (
|
|
61
62
|
<div {...{ [`data-emvb-${marker}-bind`]: "list" }}>
|
|
@@ -98,6 +99,11 @@ export function LoopItemBindControl({
|
|
|
98
99
|
Optional published {label} theme part. Leave blank to use nested elements.
|
|
99
100
|
{adminLinks && <a href="/_emdash/admin/plugins/emvb/theme"> Open Theme Builder</a>}
|
|
100
101
|
</p>
|
|
102
|
+
{chosen && chosen.status !== "published" && (
|
|
103
|
+
<p className="emvb-helper" role="note" data-emvb-part-draft={chosen.status}>
|
|
104
|
+
{draftNote(chosen.status)}
|
|
105
|
+
</p>
|
|
106
|
+
)}
|
|
101
107
|
</div>
|
|
102
108
|
);
|
|
103
109
|
}
|
|
@@ -128,3 +134,15 @@ function labelFor(part: ThemePartSummary): string {
|
|
|
128
134
|
const status = part.status === "published" ? "" : ` (${part.status})`;
|
|
129
135
|
return `${part.title}${status}`;
|
|
130
136
|
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* W-970: the canvas draws a part's latest saved version, but visitors only see what is published.
|
|
140
|
+
* Say so when the chosen part has unpublished changes, or was never published.
|
|
141
|
+
*/
|
|
142
|
+
function draftNote(status: string): string {
|
|
143
|
+
if (status === "changed")
|
|
144
|
+
return "The canvas shows this part's unpublished changes. Visitors see the published version until you publish it in Theme Builder.";
|
|
145
|
+
if (status === "scheduled")
|
|
146
|
+
return "The canvas shows this part as scheduled. Visitors see it once it goes live.";
|
|
147
|
+
return "This part isn't published yet. The canvas shows its draft, but visitors see nothing here until you publish it in Theme Builder.";
|
|
148
|
+
}
|
|
@@ -539,6 +539,7 @@ export function StyleRow({
|
|
|
539
539
|
return (
|
|
540
540
|
<IconShadowControl
|
|
541
541
|
value={style?.iconShadow}
|
|
542
|
+
inherited={inherited?.iconShadow}
|
|
542
543
|
design={design}
|
|
543
544
|
onChange={(iconShadow) => onPatch({ iconShadow })}
|
|
544
545
|
onDesignChange={onDesignChange}
|
|
@@ -559,6 +560,7 @@ export function StyleRow({
|
|
|
559
560
|
return (
|
|
560
561
|
<ShadowControl
|
|
561
562
|
value={style?.boxShadow}
|
|
563
|
+
inherited={inherited?.boxShadow}
|
|
562
564
|
design={design}
|
|
563
565
|
onChange={(boxShadow) => onPatch({ boxShadow })}
|
|
564
566
|
onDesignChange={onDesignChange}
|
|
@@ -571,6 +573,7 @@ export function StyleRow({
|
|
|
571
573
|
return (
|
|
572
574
|
<EntranceControl
|
|
573
575
|
value={style?.entrance}
|
|
576
|
+
inherited={inherited?.entrance}
|
|
574
577
|
onChange={(entrance) => onPatch({ entrance })}
|
|
575
578
|
reset={reset}
|
|
576
579
|
/>
|
|
@@ -601,6 +604,7 @@ export function StyleRow({
|
|
|
601
604
|
return (
|
|
602
605
|
<TransitionControl
|
|
603
606
|
value={style?.transition}
|
|
607
|
+
inherited={inherited?.transition}
|
|
604
608
|
onChange={(transition) => onPatch({ transition })}
|
|
605
609
|
reset={reset}
|
|
606
610
|
/>
|
|
@@ -651,6 +655,7 @@ export function StyleRow({
|
|
|
651
655
|
slider={styleKey === "gap"}
|
|
652
656
|
onPatch={onPatch}
|
|
653
657
|
reset={reset}
|
|
658
|
+
viewportUnits={style?.viewportUnits}
|
|
654
659
|
/>
|
|
655
660
|
);
|
|
656
661
|
}
|
|
@@ -678,6 +683,8 @@ export const IMPLEMENTED_STYLE_KEYS: StyleKey[] = [
|
|
|
678
683
|
"entrance",
|
|
679
684
|
"scrollMotion",
|
|
680
685
|
"loopMotion",
|
|
686
|
+
// W-974: set by the Height rows' dvh/svh units (LengthRow), never a row of its own.
|
|
687
|
+
"viewportUnits",
|
|
681
688
|
"transition",
|
|
682
689
|
"iconRotate",
|
|
683
690
|
"iconFlip",
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isShadowingId } from "../../../../core/shadowing-ids.ts";
|
|
1
2
|
import type { Layout, LayoutNode } from "../../../../core/index.ts";
|
|
2
3
|
import { isReservedAttribute } from "../../../../core/render/extras.ts";
|
|
3
4
|
import { nodeChildren } from "../../../../core/tree-ops.ts";
|
|
@@ -29,6 +30,8 @@ export function htmlIdError(value: string, layout: Layout | null, nodeId: string
|
|
|
29
30
|
// W-418: EmVB names headings (emvb-h-…), form fields and tabs with emvb- ids; reusing one
|
|
30
31
|
// made two elements share an id, so a contents link or a label could point at the wrong one.
|
|
31
32
|
if (/^emvb-/i.test(value)) return "Ids starting with emvb- are reserved; choose another.";
|
|
33
|
+
if (isShadowingId(value))
|
|
34
|
+
return `"${value}" is the name of a browser built-in that scripts on the page use; choose another.`;
|
|
32
35
|
if (otherHtmlIds(layout, nodeId).has(value)) return "Another element already uses this CSS id.";
|
|
33
36
|
return null;
|
|
34
37
|
}
|
|
@@ -1,17 +1,29 @@
|
|
|
1
1
|
import { STYLE_LABELS, type StyleKey } from "./style-sections.ts";
|
|
2
2
|
|
|
3
|
-
export type LengthUnit = "px" | "rem" | "em" | "%" | "vw" | "vh" | "ch";
|
|
3
|
+
export type LengthUnit = "px" | "rem" | "em" | "%" | "vw" | "vh" | "ch" | ViewportUnit;
|
|
4
|
+
/**
|
|
5
|
+
* W-974: dynamic and small viewport height, for full-height sections on phones. Stored as `vh`
|
|
6
|
+
* plus the record's `viewportUnits`, so 1.0 still draws them as `vh`.
|
|
7
|
+
*/
|
|
8
|
+
export type ViewportUnit = "dvh" | "svh";
|
|
9
|
+
export const isViewportUnit = (unit: unknown): unit is ViewportUnit =>
|
|
10
|
+
unit === "dvh" || unit === "svh";
|
|
4
11
|
/** `x` is a unitless number, for Line height only (W-213). */
|
|
5
12
|
export type UnitChoice = LengthUnit | "auto" | "x";
|
|
6
13
|
export type LengthLiteral = { value: number; unit: LengthUnit };
|
|
7
14
|
|
|
8
15
|
const BOX: readonly UnitChoice[] = ["px", "%", "rem", "em", "vw", "vh", "ch"];
|
|
9
16
|
const BOX_AUTO: readonly UnitChoice[] = [...BOX, "auto"];
|
|
17
|
+
/** Heights also take dvh and svh (W-974). */
|
|
18
|
+
const HEIGHT: readonly UnitChoice[] = ["px", "%", "rem", "em", "vw", "vh", "dvh", "svh", "ch"];
|
|
19
|
+
const HEIGHT_AUTO: readonly UnitChoice[] = [...HEIGHT, "auto"];
|
|
10
20
|
|
|
11
21
|
/** Units each length property offers in its unit menu (DESIGN.md § Inputs). */
|
|
12
22
|
const UNITS: Partial<Record<StyleKey, readonly UnitChoice[]>> = {
|
|
13
23
|
width: BOX_AUTO,
|
|
14
|
-
height:
|
|
24
|
+
height: HEIGHT_AUTO,
|
|
25
|
+
minHeight: HEIGHT,
|
|
26
|
+
maxHeight: HEIGHT,
|
|
15
27
|
flexBasis: BOX_AUTO,
|
|
16
28
|
marginTop: BOX_AUTO,
|
|
17
29
|
marginRight: BOX_AUTO,
|
|
@@ -96,7 +108,7 @@ export type ParsedLength =
|
|
|
96
108
|
| { ok: true; value: LengthLiteral | FluidLiteral | "auto" | number | undefined }
|
|
97
109
|
| { ok: false; message: string };
|
|
98
110
|
|
|
99
|
-
const DRAFT = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*(px|rem|em|%|vw|vh|ch)?$/i;
|
|
111
|
+
const DRAFT = /^([+-]?(?:\d+(?:\.\d*)?|\.\d+))\s*(px|rem|em|%|vw|dvh|svh|vh|ch)?$/i;
|
|
100
112
|
/** A number with a unit EmVB doesn't take ("100dvh", "12pt"), or a comma decimal ("1,5") (W-262). */
|
|
101
113
|
const OTHER_UNIT = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)\s*[a-z%]+$/i;
|
|
102
114
|
const COMMA_DECIMAL = /^[+-]?\d*,\d+\s*[a-z%]*$/i;
|
|
@@ -2,12 +2,14 @@ import {
|
|
|
2
2
|
patchClassDevices,
|
|
3
3
|
patchClassState,
|
|
4
4
|
patchClassStyle,
|
|
5
|
+
patchClassWide,
|
|
5
6
|
patchDeviceStyle,
|
|
6
7
|
patchStates,
|
|
8
|
+
patchWideStyle,
|
|
7
9
|
type DesignSystem,
|
|
8
10
|
type DeviceStyles,
|
|
9
11
|
type LayoutNode,
|
|
10
|
-
type
|
|
12
|
+
type EditorDevice,
|
|
11
13
|
type FlatStyleProps,
|
|
12
14
|
type StyleProps,
|
|
13
15
|
patchNestedStyle,
|
|
@@ -19,7 +21,8 @@ import type { StyleStateChoice } from "./settings/StateSwitcher.tsx";
|
|
|
19
21
|
export type StyleSlot =
|
|
20
22
|
| { owner: "element" | "class"; slot: "style" }
|
|
21
23
|
| { owner: "element" | "class"; slot: "state"; state: StyleStateName }
|
|
22
|
-
| { owner: "element" | "class"; slot: "device"; device: "laptop" | "tablet" | "mobile" }
|
|
24
|
+
| { owner: "element" | "class"; slot: "device"; device: "laptop" | "tablet" | "mobile" }
|
|
25
|
+
| { owner: "element" | "class"; slot: "wide" };
|
|
23
26
|
|
|
24
27
|
/** Which style object a patch writes: the element's own, a class, a state, or a device. */
|
|
25
28
|
export function styleTarget({
|
|
@@ -28,10 +31,12 @@ export function styleTarget({
|
|
|
28
31
|
state,
|
|
29
32
|
}: {
|
|
30
33
|
classId: string | null;
|
|
31
|
-
device:
|
|
34
|
+
device: EditorDevice;
|
|
32
35
|
state: StyleStateChoice;
|
|
33
36
|
}): StyleSlot {
|
|
34
37
|
const owner = classId ? "class" : "element";
|
|
38
|
+
// W-959: Wide screen writes the own style's `wide` record.
|
|
39
|
+
if (device === "wide") return { owner, slot: "wide" };
|
|
35
40
|
if (device !== "desktop") return { owner, slot: "device", device };
|
|
36
41
|
if (state === "normal") return { owner, slot: "style" };
|
|
37
42
|
return { owner, slot: "state", state };
|
|
@@ -72,11 +77,19 @@ export function applyStylePatch({
|
|
|
72
77
|
node: LayoutNode;
|
|
73
78
|
design: DesignSystem;
|
|
74
79
|
classId: string | null;
|
|
75
|
-
device:
|
|
80
|
+
device: EditorDevice;
|
|
76
81
|
state: StyleStateChoice;
|
|
77
82
|
patch: Partial<FlatStyleProps>;
|
|
78
83
|
}): StyleWrite {
|
|
79
84
|
const target = styleTarget({ classId, device, state });
|
|
85
|
+
if (target.slot === "wide") {
|
|
86
|
+
if (!classId) {
|
|
87
|
+
const { style: _old, ...rest } = node;
|
|
88
|
+
const style = patchWideStyle(node.style, patch);
|
|
89
|
+
return { kind: "node", node: (style ? { ...rest, style } : rest) as LayoutNode };
|
|
90
|
+
}
|
|
91
|
+
return { kind: "design", design: patchClassWide(design, classId, patch) };
|
|
92
|
+
}
|
|
80
93
|
if (target.slot === "device") {
|
|
81
94
|
if (!classId) {
|
|
82
95
|
return {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
type ThemePartType,
|
|
7
7
|
} from "../../core/index.ts";
|
|
8
8
|
import type { Fetcher } from "../api.ts";
|
|
9
|
-
import { themePartLayout } from "../theme-api.ts";
|
|
9
|
+
import { listThemeParts, themePartLayout } from "../theme-api.ts";
|
|
10
10
|
|
|
11
11
|
const MAX_DEPTH = 8;
|
|
12
12
|
|
|
@@ -48,6 +48,8 @@ export async function loadSectionTemplates(
|
|
|
48
48
|
export interface PartTemplates {
|
|
49
49
|
sectionTemplates: Record<string, Layout>;
|
|
50
50
|
loopTemplates: Record<string, Layout>;
|
|
51
|
+
/** W-970: each loaded part's publish state ("published", "changed", "draft"…). */
|
|
52
|
+
partStatus?: Record<string, string>;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
const MAX_PARTS = 64;
|
|
@@ -124,9 +126,21 @@ export function usePartTemplates(layout: Layout | null, fetcher: Fetcher): PartT
|
|
|
124
126
|
return;
|
|
125
127
|
}
|
|
126
128
|
let cancelled = false;
|
|
127
|
-
void
|
|
128
|
-
(
|
|
129
|
-
|
|
129
|
+
void Promise.all([
|
|
130
|
+
loadPartTemplates(fetcher, current),
|
|
131
|
+
// W-970: the canvas draws parts' latest saved version; the list says which are published.
|
|
132
|
+
listThemeParts(fetcher).catch(() => []),
|
|
133
|
+
]).then(
|
|
134
|
+
([acc, parts]) => {
|
|
135
|
+
if (cancelled) return;
|
|
136
|
+
const loaded = new Set([
|
|
137
|
+
...Object.keys(acc.sectionTemplates),
|
|
138
|
+
...Object.keys(acc.loopTemplates),
|
|
139
|
+
]);
|
|
140
|
+
const partStatus = Object.fromEntries(
|
|
141
|
+
parts.filter((part) => loaded.has(part.id)).map((part) => [part.id, part.status]),
|
|
142
|
+
);
|
|
143
|
+
setTemplates({ ...acc, partStatus });
|
|
130
144
|
},
|
|
131
145
|
() => {
|
|
132
146
|
if (!cancelled) setTemplates(NO_PARTS);
|
|
@@ -139,3 +153,11 @@ export function usePartTemplates(layout: Layout | null, fetcher: Fetcher): PartT
|
|
|
139
153
|
|
|
140
154
|
return templates;
|
|
141
155
|
}
|
|
156
|
+
|
|
157
|
+
/** W-970: the canvas label's suffix for a part visitors don't see as drawn. */
|
|
158
|
+
export const partDraftLabel = (status: string): string =>
|
|
159
|
+
status === "changed"
|
|
160
|
+
? "unpublished changes"
|
|
161
|
+
: status === "scheduled"
|
|
162
|
+
? "scheduled"
|
|
163
|
+
: "not published";
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
LAYOUT_SCHEMA_VERSION,
|
|
16
16
|
withShiftedMarks,
|
|
17
17
|
} from "../../core/index.ts";
|
|
18
|
-
import { withPageHeadingLevel } from "./dnd/new-element.ts";
|
|
18
|
+
import { withLoopPostTitleLevel, withPageHeadingLevel } from "./dnd/new-element.ts";
|
|
19
19
|
import type { PageDraft } from "../content-api.ts";
|
|
20
20
|
|
|
21
21
|
/** Editor state (A-07): a pure reducer, so every edit is testable without a browser. */
|
|
@@ -23,6 +23,8 @@ export type EditorState = {
|
|
|
23
23
|
id: string;
|
|
24
24
|
page: PageDraft;
|
|
25
25
|
status: string;
|
|
26
|
+
/** W-1027: when EmDash will publish the saved draft by itself (ISO), or null. */
|
|
27
|
+
scheduledAt?: string | null;
|
|
26
28
|
rev: string | null;
|
|
27
29
|
design: DesignSystem;
|
|
28
30
|
designRevision: string | null;
|
|
@@ -59,6 +61,7 @@ export type EditorAction =
|
|
|
59
61
|
| { type: "apply-arranged"; layout: Layout; selected: string }
|
|
60
62
|
| { type: "saved"; rev: string; version: number }
|
|
61
63
|
| { type: "published"; rev: string }
|
|
64
|
+
| { type: "scheduled"; rev: string; status: string; at: string | null }
|
|
62
65
|
| { type: "set-design"; design: DesignSystem; revision: string | null }
|
|
63
66
|
/**
|
|
64
67
|
* W-536: a site styles edit shown before its save lands, so the next edit builds on it. The
|
|
@@ -216,7 +219,13 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
216
219
|
if (!state.page.layout) return state;
|
|
217
220
|
const place = { parentId: action.parentId, index: action.index };
|
|
218
221
|
const node = withPageHeadingLevel(action.node, state.page.layout, state.page.partType);
|
|
219
|
-
|
|
222
|
+
const added = addNode(state.page.layout, node, place);
|
|
223
|
+
return arranged(
|
|
224
|
+
state,
|
|
225
|
+
added.ok
|
|
226
|
+
? { ...added, layout: withLoopPostTitleLevel(added.layout, node.id, state.page.partType) }
|
|
227
|
+
: added,
|
|
228
|
+
);
|
|
220
229
|
}
|
|
221
230
|
case "move-node":
|
|
222
231
|
if (!state.page.layout) return state;
|
|
@@ -232,7 +241,10 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
232
241
|
status: state.status === "published" ? "changed" : state.status,
|
|
233
242
|
};
|
|
234
243
|
case "published":
|
|
235
|
-
return { ...state, rev: action.rev, status: "published" };
|
|
244
|
+
return { ...state, rev: action.rev, status: "published", scheduledAt: null };
|
|
245
|
+
case "scheduled":
|
|
246
|
+
// W-1027: scheduling (or cancelling it) keeps the draft; EmDash publishes it at `at`.
|
|
247
|
+
return { ...state, rev: action.rev, status: action.status, scheduledAt: action.at };
|
|
236
248
|
case "preview-design":
|
|
237
249
|
return { ...state, design: action.design };
|
|
238
250
|
case "set-design":
|
|
@@ -3,9 +3,10 @@ import type { createKumoToastManager } from "@cloudflare/kumo";
|
|
|
3
3
|
import { ArrowSquareOutIcon } from "@phosphor-icons/react";
|
|
4
4
|
import {
|
|
5
5
|
DEVICE_PREVIEW_PX,
|
|
6
|
+
WIDE_PREVIEW_PX,
|
|
6
7
|
mergeDesign,
|
|
7
8
|
type DesignSystem,
|
|
8
|
-
type
|
|
9
|
+
type EditorDevice,
|
|
9
10
|
} from "../../core/index.ts";
|
|
10
11
|
import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
11
12
|
import { ApiError, type Fetcher } from "../api.ts";
|
|
@@ -19,15 +20,16 @@ const publicPath = (pattern: string | null | undefined, slug: string) =>
|
|
|
19
20
|
(pattern || "/{slug}").replace("{slug}", encodeURIComponent(slug));
|
|
20
21
|
|
|
21
22
|
/** Window heights for the sized Tablet and Mobile previews (W-158); widths are the canvas's. */
|
|
22
|
-
const PREVIEW_HEIGHT = { laptop: 800, tablet: 1024, mobile: 844 } as const;
|
|
23
|
+
const PREVIEW_HEIGHT = { wide: 1440, laptop: 800, tablet: 1024, mobile: 844 } as const;
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
26
|
* `window.open` features for a device preview (W-158): Desktop is an ordinary tab; Tablet and
|
|
26
27
|
* Mobile open a window whose page area is the device width, so the page's own media queries apply.
|
|
27
28
|
*/
|
|
28
|
-
export function previewWindowFeatures(device:
|
|
29
|
+
export function previewWindowFeatures(device: EditorDevice): string | undefined {
|
|
29
30
|
if (device === "desktop") return undefined;
|
|
30
|
-
|
|
31
|
+
const width = device === "wide" ? WIDE_PREVIEW_PX : DEVICE_PREVIEW_PX[device];
|
|
32
|
+
return `popup,width=${width},height=${PREVIEW_HEIGHT[device]}`;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
/**
|
|
@@ -137,7 +139,7 @@ export function useEditorCommands({
|
|
|
137
139
|
});
|
|
138
140
|
};
|
|
139
141
|
|
|
140
|
-
const preview = (device:
|
|
142
|
+
const preview = (device: EditorDevice = "desktop") =>
|
|
141
143
|
void openInNewTab(
|
|
142
144
|
async () => {
|
|
143
145
|
if (isDirty(latest.current) && !(await save())) return null;
|
|
@@ -33,6 +33,8 @@ export type EditorEntry = {
|
|
|
33
33
|
seoNoIndex?: boolean;
|
|
34
34
|
seoImage?: string;
|
|
35
35
|
status: string;
|
|
36
|
+
/** W-1027: when EmDash publishes the entry by itself (ISO), or null. */
|
|
37
|
+
scheduledAt?: string | null;
|
|
36
38
|
rev: string | null;
|
|
37
39
|
layout: Layout | null;
|
|
38
40
|
partType?: ThemePartType;
|
|
@@ -64,6 +66,7 @@ type ContentResponse = {
|
|
|
64
66
|
slug?: string | null;
|
|
65
67
|
status?: string;
|
|
66
68
|
draftRevisionId?: string | null;
|
|
69
|
+
scheduledAt?: string | null;
|
|
67
70
|
data?: Record<string, unknown>;
|
|
68
71
|
seo?: {
|
|
69
72
|
title?: string | null;
|
|
@@ -100,6 +103,7 @@ export async function loadEntry(
|
|
|
100
103
|
seoNoIndex: body?.item?.seo?.noIndex === true,
|
|
101
104
|
seoImage: text(body?.item?.seo?.image),
|
|
102
105
|
status: entryStatus(body?.item),
|
|
106
|
+
scheduledAt: body?.item?.scheduledAt ?? null,
|
|
103
107
|
rev: body?.["_rev"] ?? null,
|
|
104
108
|
layout: readLayout(data["layout"]),
|
|
105
109
|
};
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
type LayoutNode,
|
|
26
26
|
} from "../../core/index.ts";
|
|
27
27
|
import { adminExtensionDefaults } from "./extension-manifests.ts";
|
|
28
|
-
import { newElement, withPageHeadingLevel } from "./dnd/new-element.ts";
|
|
28
|
+
import { newElement, withLoopPostTitleLevel, withPageHeadingLevel } from "./dnd/new-element.ts";
|
|
29
29
|
import { ELEMENT_NAMES } from "./element-chrome.ts";
|
|
30
30
|
import type { ItemActions } from "./panels/settings/ItemList.tsx";
|
|
31
31
|
import type { EditorAction, EditorState } from "./store.ts";
|
|
@@ -212,7 +212,9 @@ export function useNodeActions({
|
|
|
212
212
|
notice(result.reason);
|
|
213
213
|
return;
|
|
214
214
|
}
|
|
215
|
-
|
|
215
|
+
// W-968: a Post title placed inside a Loop starts as an H2.
|
|
216
|
+
const placed = withLoopPostTitleLevel(result.layout, node.id, latest.current.page.partType);
|
|
217
|
+
dispatch({ type: "apply-arranged", layout: placed, selected: result.selected });
|
|
216
218
|
const nameOf = (id: string) => ELEMENT_NAMES[findNode(layout, id)?.type ?? "container"];
|
|
217
219
|
if (result.fallback) {
|
|
218
220
|
// Added next to the nearest ancestor that takes it, rather than refused (W-175).
|
|
@@ -2,7 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import { byteLength, MAX_LAYOUT_BYTES, nodeIdAtPath, type Layout } from "../../core/index.ts";
|
|
3
3
|
import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
4
4
|
import { ApiError, type Fetcher } from "../api.ts";
|
|
5
|
-
import { publishPage, savePage } from "../content-api.ts";
|
|
5
|
+
import { publishPage, savePage, scheduleEntry } from "../content-api.ts";
|
|
6
6
|
import { publishThemePart, saveThemePart } from "../theme-api.ts";
|
|
7
7
|
import type { EditorAction, EditorState } from "./store.ts";
|
|
8
8
|
import { loadEntry } from "./useEditorData.ts";
|
|
@@ -214,7 +214,8 @@ export function useSave(
|
|
|
214
214
|
await run;
|
|
215
215
|
}, [fetcher, write, collection]);
|
|
216
216
|
|
|
217
|
-
|
|
217
|
+
/** The revision to publish or schedule: after the running save, and with unsaved edits saved. */
|
|
218
|
+
const flush = React.useCallback(async (): Promise<string | null | false> => {
|
|
218
219
|
let rev: string | null = latest.current.rev;
|
|
219
220
|
const pending = queued.current ?? inFlight.current;
|
|
220
221
|
if (pending) {
|
|
@@ -227,6 +228,12 @@ export function useSave(
|
|
|
227
228
|
rev = await start(rev);
|
|
228
229
|
if (!rev) return false;
|
|
229
230
|
}
|
|
231
|
+
return rev;
|
|
232
|
+
}, [start]);
|
|
233
|
+
|
|
234
|
+
const publish = React.useCallback(async (): Promise<boolean> => {
|
|
235
|
+
const rev = await flush();
|
|
236
|
+
if (rev === false) return false;
|
|
230
237
|
try {
|
|
231
238
|
const result =
|
|
232
239
|
collection === THEME_PARTS_COLLECTION
|
|
@@ -240,12 +247,49 @@ export function useSave(
|
|
|
240
247
|
setStatus({ kind: "error", message: publishFailureMessage(error), retry: false });
|
|
241
248
|
return false;
|
|
242
249
|
}
|
|
243
|
-
}, [fetcher, dispatch,
|
|
250
|
+
}, [fetcher, dispatch, flush, collection]);
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* W-1027: has EmDash publish the saved draft at `at` (unsaved edits are saved first), or with
|
|
254
|
+
* `at` null cancels the schedule. Returns the error message, or null when it worked.
|
|
255
|
+
*/
|
|
256
|
+
const schedule = React.useCallback(
|
|
257
|
+
async (at: Date | null): Promise<string | null> => {
|
|
258
|
+
const rev = at ? await flush() : latest.current.rev;
|
|
259
|
+
if (rev === false) return "Your changes couldn't be saved, so nothing was scheduled.";
|
|
260
|
+
try {
|
|
261
|
+
const result = await scheduleEntry(
|
|
262
|
+
fetcher,
|
|
263
|
+
`/_emdash/api/content/${collection}`,
|
|
264
|
+
latest.current.id,
|
|
265
|
+
at,
|
|
266
|
+
rev,
|
|
267
|
+
);
|
|
268
|
+
dispatch({
|
|
269
|
+
type: "scheduled",
|
|
270
|
+
rev: result.rev,
|
|
271
|
+
status: result.status,
|
|
272
|
+
at: result.scheduledAt,
|
|
273
|
+
});
|
|
274
|
+
setStatus({ kind: "saved" });
|
|
275
|
+
return null;
|
|
276
|
+
} catch (error) {
|
|
277
|
+
if (error instanceof ApiError && error.status === 409) {
|
|
278
|
+
setConflict(true);
|
|
279
|
+
return "This page was changed somewhere else. Reload or overwrite it, then schedule again.";
|
|
280
|
+
}
|
|
281
|
+
if (error instanceof ApiError && error.status === 400) return error.message;
|
|
282
|
+
return publishFailureMessage(error);
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
[fetcher, dispatch, flush, collection],
|
|
286
|
+
);
|
|
244
287
|
|
|
245
288
|
return {
|
|
246
289
|
status,
|
|
247
290
|
save,
|
|
248
291
|
publish,
|
|
292
|
+
schedule,
|
|
249
293
|
overwrite,
|
|
250
294
|
conflict,
|
|
251
295
|
closeConflict: () => setConflict(false),
|