@perkyzz/emvb 1.3.0 → 1.4.1
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 +2 -2
- package/package.json +2 -2
- package/src/admin/bulk-api.ts +5 -1
- package/src/admin/content-item.ts +3 -0
- package/src/admin/copy-rich-text.ts +99 -9
- package/src/admin/editor/A11yCopilot.tsx +3 -1
- package/src/admin/editor/Editor.tsx +28 -3
- package/src/admin/editor/Timeline.tsx +1 -8
- package/src/admin/editor/canvas/DeviceBar.tsx +7 -2
- package/src/admin/editor/canvas/EmptyCanvas.tsx +11 -2
- package/src/admin/editor/canvas/use-canvas-dnd.ts +1 -20
- package/src/admin/editor/canvas/vnode-react.tsx +2 -0
- package/src/admin/editor/co-design.ts +36 -1
- package/src/admin/editor/collection-previews.ts +7 -8
- package/src/admin/editor/dnd/dragged-source.ts +22 -0
- package/src/admin/editor/dnd/layer-drop.ts +141 -0
- package/src/admin/editor/dnd/new-element.ts +16 -0
- package/src/admin/editor/editor-css.ts +9 -1
- package/src/admin/editor/element-chrome.ts +6 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +33 -1
- package/src/admin/editor/extensions-context.tsx +16 -1
- package/src/admin/editor/feature-css.ts +27 -0
- package/src/admin/editor/inert-links.ts +8 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ConditionsEditor.tsx +18 -0
- package/src/admin/editor/panels/ElementPanel.tsx +2 -2
- package/src/admin/editor/panels/FontFaces.tsx +342 -0
- package/src/admin/editor/panels/LayersPanel.tsx +56 -6
- package/src/admin/editor/panels/LeftPanel.tsx +153 -29
- package/src/admin/editor/panels/SettingsPanel.tsx +1 -0
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +5 -0
- package/src/admin/editor/panels/TemplatesPanel.tsx +205 -0
- package/src/admin/editor/panels/TokenScales.tsx +2 -0
- package/src/admin/editor/panels/TriggersEditor.tsx +203 -9
- package/src/admin/editor/panels/VariableSection.tsx +111 -7
- package/src/admin/editor/panels/color-space.ts +71 -6
- package/src/admin/editor/panels/settings/AudienceEditor.tsx +3 -0
- package/src/admin/editor/panels/settings/FieldControl.tsx +33 -0
- package/src/admin/editor/panels/settings/FormBindControl.tsx +27 -31
- package/src/admin/editor/panels/settings/ImageFieldControl.tsx +106 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +9 -3
- package/src/admin/editor/panels/settings/StickyControl.tsx +97 -0
- package/src/admin/editor/panels/settings/StyleRow.tsx +14 -0
- package/src/admin/editor/panels/settings/loop-context.ts +34 -3
- package/src/admin/editor/panels/settings/style-sections.ts +19 -2
- package/src/admin/editor/panels/url-rules.ts +43 -0
- package/src/admin/editor/panels/use-layers-drop.ts +232 -0
- package/src/admin/editor/store.ts +4 -2
- package/src/admin/editor/useExtensions.ts +3 -1
- package/src/admin/editor/useNodeActions.ts +74 -1
- package/src/admin/editor/useSave.ts +116 -85
- package/src/admin/export-api.ts +27 -2
- package/src/admin/extension-outputs.ts +236 -0
- package/src/admin/font-files-api.ts +38 -0
- package/src/admin/import-forms.ts +133 -0
- package/src/admin/pages/ImportButton.tsx +15 -4
- package/src/admin/pages/ImportElementorDialog.tsx +53 -187
- package/src/admin/pages/ImportForms.tsx +71 -0
- package/src/admin/pages/ImportHtmlDialog.tsx +209 -0
- package/src/admin/pages/ImportImageCopies.tsx +167 -0
- package/src/admin/pages/ImportReport.tsx +63 -0
- package/src/admin/pages/NewPageDialog.tsx +54 -32
- package/src/admin/pages/PageList.tsx +9 -0
- package/src/admin/pages/ThemePartList.tsx +9 -0
- package/src/admin/setup/plan.ts +2 -0
- package/src/admin/ui.ts +7 -0
- package/src/admin/widgets/ConvertToRichText.tsx +3 -2
- package/src/astro/EmVBPage.astro +5 -2
- package/src/astro/extension-styles.ts +35 -0
- package/src/astro/forms/EmVBFormsClient.astro +3 -0
- package/src/astro/forms/enhance.ts +107 -0
- package/src/astro/popups/runtime.ts +47 -2
- package/src/astro/render.ts +25 -4
- package/src/astro/resolve-theme.ts +11 -4
- package/src/astro/resolve.ts +2 -0
- package/src/astro/theme-posts.ts +17 -23
- package/src/astro/visitor.ts +14 -5
- package/src/astro/widgets/EmVBStickyRuntime.astro +9 -0
- package/src/astro/widgets/EmVBThemeRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +12 -0
- package/src/astro/widgets/alerts.ts +16 -2
- package/src/astro/widgets/carousel.ts +65 -24
- package/src/astro/widgets/countdown.ts +18 -7
- package/src/astro/widgets/extension-runtimes.ts +27 -0
- package/src/astro/widgets/headline.ts +14 -5
- package/src/astro/widgets/sticky.ts +87 -0
- package/src/astro/widgets/theme.ts +52 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +150 -2
- package/src/core/arrange.ts +19 -1
- package/src/core/css/font-face.ts +72 -0
- package/src/core/css/generate.ts +41 -2
- package/src/core/css/trace.ts +8 -0
- package/src/core/data/bindings.ts +7 -4
- package/src/core/elements/dynamic-elements.ts +1 -1
- package/src/core/elements/element-nouns.ts +48 -0
- package/src/core/elements/form-elements.ts +119 -9
- package/src/core/elements/icon-svg.ts +14 -0
- package/src/core/elements/index.ts +24 -4
- package/src/core/elements/input-limits.ts +44 -0
- package/src/core/elements/menu.ts +109 -47
- package/src/core/elements/site.ts +108 -0
- package/src/core/elements/widgets.ts +13 -3
- package/src/core/export/runtimes.generated.ts +7 -5
- package/src/core/export/site.ts +53 -4
- package/src/core/extensions/classes.ts +114 -0
- package/src/core/extensions/index.ts +19 -2
- package/src/core/extensions/normalize.ts +13 -0
- package/src/core/extensions/placeholder.ts +7 -2
- package/src/core/extensions/registry.ts +134 -10
- package/src/core/extensions/render-ext.ts +115 -36
- package/src/core/extensions/safe-nodes.ts +67 -11
- package/src/core/extensions/types.ts +48 -1
- package/src/core/fonts/files.ts +74 -0
- package/src/core/fonts/google.ts +112 -0
- package/src/core/fonts/test-font.ts +9 -0
- package/src/core/import/elementor/context.ts +42 -4
- package/src/core/import/elementor/index.ts +55 -23
- package/src/core/import/elementor/widgets.ts +242 -20
- package/src/core/import/html/blocks.ts +602 -0
- package/src/core/import/html/index.ts +155 -0
- package/src/core/import/html/map.ts +958 -0
- package/src/core/import/html/parse.ts +430 -0
- package/src/core/index.ts +54 -0
- package/src/core/migrate/v18.ts +3 -0
- package/src/core/public-attributes.ts +17 -0
- package/src/core/render/extras.ts +31 -7
- package/src/core/render/form.ts +103 -10
- package/src/core/render/index.ts +165 -16
- package/src/core/render/section.ts +31 -1
- package/src/core/render/spacer-basis.ts +102 -0
- package/src/core/render/theme-boot.ts +16 -0
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +68 -3
- package/src/core/sanitize/motion.ts +12 -0
- package/src/core/schema/design.ts +40 -0
- package/src/core/schema/layout.ts +118 -6
- package/src/core/schema/style.ts +28 -0
- package/src/core/templates/index.ts +218 -0
- package/src/core/templates/pages.ts +29 -0
- package/src/core/templates/sections.ts +794 -0
- package/src/core/templates/types.ts +9 -0
- package/src/core/theme/dynamic.ts +9 -6
- package/src/core/theme/media-value.ts +88 -0
- package/src/core/theme/popup-markup.ts +21 -2
- package/src/core/theme/popup-rules.ts +36 -0
- package/src/core/theme/triggers.ts +64 -5
- package/src/core/translatable.ts +5 -2
- package/src/core/visitor-cookie.ts +91 -0
- package/src/extension-build.ts +331 -0
- package/src/index.ts +53 -4
- package/src/mcp/agent-defaults.ts +40 -0
- package/src/mcp/brief.ts +191 -0
- package/src/mcp/extensions.ts +138 -0
- package/src/mcp/prompts.ts +33 -0
- package/src/mcp/read.ts +84 -20
- package/src/mcp/tools.ts +42 -3
- package/src/mcp/write.ts +124 -9
- package/src/server/extension-routes.ts +110 -0
- package/src/server/font-routes.ts +301 -0
- package/src/server/plugin.ts +15 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { Select } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { imageFieldsOf, type FieldDescriptor, type LayoutNode } from "../../../../core/index.ts";
|
|
4
|
+
import { requestJson, type Fetcher } from "../../../api.ts";
|
|
5
|
+
import { FIELD } from "../../../ui.ts";
|
|
6
|
+
import { DraftTextField } from "./DraftTextField.tsx";
|
|
7
|
+
import { propsOf, withProp } from "./node-props.ts";
|
|
8
|
+
|
|
9
|
+
const AUTO = "__auto__";
|
|
10
|
+
const CURRENT = "__current__";
|
|
11
|
+
|
|
12
|
+
type SchemaField = { slug: string; type: string; label?: string | null };
|
|
13
|
+
|
|
14
|
+
/** The collection's image fields from EmDash's schema API; null when it can't be read. */
|
|
15
|
+
async function loadImageFields(
|
|
16
|
+
fetcher: Fetcher,
|
|
17
|
+
collection: string,
|
|
18
|
+
): Promise<{ slug: string; label: string }[] | null> {
|
|
19
|
+
try {
|
|
20
|
+
const data = await requestJson<{ item?: { fields?: SchemaField[] } }>(
|
|
21
|
+
fetcher,
|
|
22
|
+
`/_emdash/api/schema/collections/${encodeURIComponent(collection)}?includeFields=true`,
|
|
23
|
+
);
|
|
24
|
+
return imageFieldsOf(data.item?.fields ?? []);
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* W-1090 (#32): a collection Loop's Image field, picked from the collection's image fields.
|
|
32
|
+
* Unset is Automatic: `featured_image`, else the collection's first image field, as published
|
|
33
|
+
* pages read it. A name not in the list (typed before, or a field since removed) stays chosen.
|
|
34
|
+
* Without a collection, or when the schema can't be read, it is the plain text field.
|
|
35
|
+
*/
|
|
36
|
+
export function ImageFieldControl({
|
|
37
|
+
field,
|
|
38
|
+
node,
|
|
39
|
+
collection,
|
|
40
|
+
fetcher,
|
|
41
|
+
onChange,
|
|
42
|
+
}: {
|
|
43
|
+
field: FieldDescriptor;
|
|
44
|
+
node: LayoutNode;
|
|
45
|
+
collection: string | undefined;
|
|
46
|
+
fetcher: Fetcher;
|
|
47
|
+
onChange: (node: LayoutNode) => void;
|
|
48
|
+
}) {
|
|
49
|
+
// Keyed by collection, so a changed Collection never shows the previous one's fields.
|
|
50
|
+
const [loaded, setLoaded] = React.useState<{
|
|
51
|
+
collection: string;
|
|
52
|
+
fields: { slug: string; label: string }[] | null;
|
|
53
|
+
} | null>(null);
|
|
54
|
+
|
|
55
|
+
React.useEffect(() => {
|
|
56
|
+
if (!collection) return;
|
|
57
|
+
let cancelled = false;
|
|
58
|
+
void loadImageFields(fetcher, collection).then((next) => {
|
|
59
|
+
if (!cancelled) setLoaded({ collection, fields: next });
|
|
60
|
+
});
|
|
61
|
+
return () => {
|
|
62
|
+
cancelled = true;
|
|
63
|
+
};
|
|
64
|
+
}, [fetcher, collection]);
|
|
65
|
+
|
|
66
|
+
const fields = loaded && loaded.collection === collection ? loaded.fields : null;
|
|
67
|
+
if (!collection || !fields || fields.length === 0) {
|
|
68
|
+
return <DraftTextField field={field} node={node} onChange={onChange} />;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const raw = propsOf(node)[field.key];
|
|
72
|
+
const value = typeof raw === "string" ? raw : "";
|
|
73
|
+
const known = fields.some((f) => f.slug === value);
|
|
74
|
+
const automatic = `Automatic (${fields[0]?.label ?? ""})`;
|
|
75
|
+
const labelOf = (current: string) => {
|
|
76
|
+
if (current === AUTO) return automatic;
|
|
77
|
+
if (current === CURRENT) return `${value} (not an image field here)`;
|
|
78
|
+
return fields.find((f) => f.slug === current)?.label ?? current;
|
|
79
|
+
};
|
|
80
|
+
return (
|
|
81
|
+
<div data-emvb-field={field.key} data-emvb-image-field="list">
|
|
82
|
+
<Select
|
|
83
|
+
label={field.label}
|
|
84
|
+
className={FIELD}
|
|
85
|
+
value={value === "" ? AUTO : known ? value : CURRENT}
|
|
86
|
+
renderValue={(current: unknown) => labelOf(String(current))}
|
|
87
|
+
onValueChange={(next) => {
|
|
88
|
+
if (!next || next === CURRENT) return;
|
|
89
|
+
onChange(withProp(node, field.key, next === AUTO ? undefined : String(next)));
|
|
90
|
+
}}
|
|
91
|
+
>
|
|
92
|
+
<Select.Option value={AUTO}>{automatic}</Select.Option>
|
|
93
|
+
{!known && value ? <Select.Option value={CURRENT}>{labelOf(CURRENT)}</Select.Option> : null}
|
|
94
|
+
{fields.map((f) => (
|
|
95
|
+
<Select.Option key={f.slug} value={f.slug}>
|
|
96
|
+
{f.label}
|
|
97
|
+
</Select.Option>
|
|
98
|
+
))}
|
|
99
|
+
</Select>
|
|
100
|
+
<p className="emvb-helper">
|
|
101
|
+
The image Post image shows. Automatic uses the featured image, or else the collection's
|
|
102
|
+
first image field.
|
|
103
|
+
</p>
|
|
104
|
+
</div>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
@@ -21,6 +21,8 @@ export function LoopItemBindControl({
|
|
|
21
21
|
label = "Loop item",
|
|
22
22
|
emptyLabel = "Use nested elements",
|
|
23
23
|
marker = "loop-item",
|
|
24
|
+
helper,
|
|
25
|
+
partName = label,
|
|
24
26
|
}: {
|
|
25
27
|
value: string;
|
|
26
28
|
fetcher: Fetcher;
|
|
@@ -30,6 +32,10 @@ export function LoopItemBindControl({
|
|
|
30
32
|
emptyLabel?: string;
|
|
31
33
|
/** `data-emvb-${marker}-bind` keeps the loop-item tests stable. */
|
|
32
34
|
marker?: string;
|
|
35
|
+
/** Replaces the helper line under the list. */
|
|
36
|
+
helper?: string;
|
|
37
|
+
/** The part type as the empty and failed notes name it; unset is `label`. */
|
|
38
|
+
partName?: string;
|
|
33
39
|
}) {
|
|
34
40
|
const [parts, setParts] = React.useState<ThemePartSummary[] | null>(null);
|
|
35
41
|
const [failed, setFailed] = React.useState(false);
|
|
@@ -96,7 +102,7 @@ export function LoopItemBindControl({
|
|
|
96
102
|
onChange={(event) => onChange(event.target.value.trim())}
|
|
97
103
|
/>
|
|
98
104
|
<p className="emvb-helper">
|
|
99
|
-
Optional published {label} theme part. Leave blank to use nested elements
|
|
105
|
+
{helper ?? `Optional published ${label} theme part. Leave blank to use nested elements.`}
|
|
100
106
|
{adminLinks && <a href="/_emdash/admin/plugins/emvb/theme"> Open Theme Builder</a>}
|
|
101
107
|
</p>
|
|
102
108
|
{chosen && chosen.status !== "published" && (
|
|
@@ -118,8 +124,8 @@ export function LoopItemBindControl({
|
|
|
118
124
|
/>
|
|
119
125
|
<p className="emvb-helper">
|
|
120
126
|
{failed
|
|
121
|
-
? `Could not load ${
|
|
122
|
-
: `No ${
|
|
127
|
+
? `Could not load ${partName} parts. Paste a theme-part id${adminLinks ? ", or " : "."}`
|
|
128
|
+
: `No ${partName} theme parts yet. Paste an id${adminLinks ? ", or " : "."}`}
|
|
123
129
|
{adminLinks && (
|
|
124
130
|
<>
|
|
125
131
|
<a href="/_emdash/admin/plugins/emvb/theme">create one in Theme Builder</a>.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type * as React from "react";
|
|
2
|
+
import type { DesignSystem, FlatStyleProps } from "../../../../core/index.ts";
|
|
3
|
+
import { ColorControl } from "../ColorControl.tsx";
|
|
4
|
+
import { HintedSwitch } from "./HintedSwitch.tsx";
|
|
5
|
+
import { NumberField, type NumberSpec } from "./NumberRow.tsx";
|
|
6
|
+
|
|
7
|
+
type Sticky = NonNullable<FlatStyleProps["stickyMotion"]>;
|
|
8
|
+
type Effects = Extract<Sticky, { hide?: unknown }>;
|
|
9
|
+
|
|
10
|
+
const DISTANCE: NumberSpec = { min: 10, max: 2000, integer: true, example: "120", suffix: "px" };
|
|
11
|
+
const PADDING: NumberSpec = { min: 0, max: 400, integer: true, example: "8", suffix: "px" };
|
|
12
|
+
|
|
13
|
+
/** The effects, or undefined when none is left (an empty record would be refused). */
|
|
14
|
+
function tidy(next: Effects): Sticky | undefined {
|
|
15
|
+
const { distance, background, shadow, padding, hide } = next;
|
|
16
|
+
const kept: Effects = {
|
|
17
|
+
...(distance !== undefined ? { distance } : {}),
|
|
18
|
+
...(background !== undefined ? { background } : {}),
|
|
19
|
+
...(shadow ? { shadow } : {}),
|
|
20
|
+
...(padding !== undefined ? { padding } : {}),
|
|
21
|
+
...(hide ? { hide } : {}),
|
|
22
|
+
};
|
|
23
|
+
const any =
|
|
24
|
+
kept.background !== undefined || kept.shadow || kept.padding !== undefined || kept.hide;
|
|
25
|
+
return any ? kept : undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* W-1070: "When the page scrolls" in Position: how a sticky header looks once the page has
|
|
30
|
+
* scrolled, and whether it slides away while scrolling down.
|
|
31
|
+
*/
|
|
32
|
+
export function StickyControl({
|
|
33
|
+
value,
|
|
34
|
+
design,
|
|
35
|
+
onChange,
|
|
36
|
+
onDesignChange,
|
|
37
|
+
reset,
|
|
38
|
+
}: {
|
|
39
|
+
value: Sticky | undefined;
|
|
40
|
+
design: DesignSystem;
|
|
41
|
+
onChange: (next: Sticky | undefined) => void;
|
|
42
|
+
onDesignChange: (design: DesignSystem) => Promise<void>;
|
|
43
|
+
reset: React.ReactNode;
|
|
44
|
+
}) {
|
|
45
|
+
const current: Effects = value && !("type" in value) ? value : {};
|
|
46
|
+
const set = (patch: Partial<Effects>) => onChange(tidy({ ...current, ...patch }));
|
|
47
|
+
const padding = current.padding;
|
|
48
|
+
const paddingPx =
|
|
49
|
+
padding && typeof padding === "object" && "unit" in padding && padding.unit === "px"
|
|
50
|
+
? padding.value
|
|
51
|
+
: undefined;
|
|
52
|
+
return (
|
|
53
|
+
<div className="emvb-style-row emvb-sticky-control" data-emvb-style="stickyMotion">
|
|
54
|
+
<p className="emvb-field-label">When the page scrolls</p>
|
|
55
|
+
<HintedSwitch
|
|
56
|
+
label="Hide while scrolling down"
|
|
57
|
+
checked={current.hide === true}
|
|
58
|
+
onCheckedChange={(hide) => set({ hide })}
|
|
59
|
+
hint="It slides back as soon as the visitor scrolls up, and stays while focus is in it."
|
|
60
|
+
/>
|
|
61
|
+
<ColorControl
|
|
62
|
+
label="Background once scrolled"
|
|
63
|
+
value={current.background}
|
|
64
|
+
design={design}
|
|
65
|
+
onChange={(background) => set({ background })}
|
|
66
|
+
onDesignChange={onDesignChange}
|
|
67
|
+
/>
|
|
68
|
+
<HintedSwitch
|
|
69
|
+
label="Shadow once scrolled"
|
|
70
|
+
checked={current.shadow === true}
|
|
71
|
+
onCheckedChange={(shadow) => set({ shadow })}
|
|
72
|
+
/>
|
|
73
|
+
<NumberField
|
|
74
|
+
fieldKey="stickyPadding"
|
|
75
|
+
label="Top and bottom padding once scrolled"
|
|
76
|
+
value={paddingPx}
|
|
77
|
+
spec={PADDING}
|
|
78
|
+
onCommit={(px) =>
|
|
79
|
+
set({ padding: px === undefined ? undefined : { value: px, unit: "px" } })
|
|
80
|
+
}
|
|
81
|
+
/>
|
|
82
|
+
<NumberField
|
|
83
|
+
fieldKey="stickyDistance"
|
|
84
|
+
label="Changes over the first"
|
|
85
|
+
value={current.distance}
|
|
86
|
+
spec={DISTANCE}
|
|
87
|
+
inherited={120}
|
|
88
|
+
onCommit={(distance) => set({ distance })}
|
|
89
|
+
/>
|
|
90
|
+
<p className="emvb-helper">
|
|
91
|
+
Browsers without scroll-driven animations, and visitors who prefer reduced motion, see it as
|
|
92
|
+
it is.
|
|
93
|
+
</p>
|
|
94
|
+
{reset}
|
|
95
|
+
</div>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Input, Select } from "@cloudflare/kumo";
|
|
2
2
|
import { MotionControl } from "./MotionControl.tsx";
|
|
3
3
|
import { LoopControl } from "./LoopControl.tsx";
|
|
4
|
+
import { StickyControl } from "./StickyControl.tsx";
|
|
4
5
|
import { isSafeFontStack, type DesignSystem, type FlatStyleProps } from "../../../../core/index.ts";
|
|
5
6
|
import type { Fetcher } from "../../../api.ts";
|
|
6
7
|
import { FIELD } from "../../../ui.ts";
|
|
@@ -590,6 +591,18 @@ export function StyleRow({
|
|
|
590
591
|
);
|
|
591
592
|
}
|
|
592
593
|
|
|
594
|
+
if (styleKey === "stickyMotion") {
|
|
595
|
+
return (
|
|
596
|
+
<StickyControl
|
|
597
|
+
value={style?.stickyMotion}
|
|
598
|
+
design={design}
|
|
599
|
+
onChange={(stickyMotion) => onPatch({ stickyMotion })}
|
|
600
|
+
onDesignChange={onDesignChange}
|
|
601
|
+
reset={reset}
|
|
602
|
+
/>
|
|
603
|
+
);
|
|
604
|
+
}
|
|
605
|
+
|
|
593
606
|
if (styleKey === "loopMotion") {
|
|
594
607
|
return (
|
|
595
608
|
<LoopControl
|
|
@@ -683,6 +696,7 @@ export const IMPLEMENTED_STYLE_KEYS: StyleKey[] = [
|
|
|
683
696
|
"entrance",
|
|
684
697
|
"scrollMotion",
|
|
685
698
|
"loopMotion",
|
|
699
|
+
"stickyMotion",
|
|
686
700
|
// W-974: set by the Height rows' dvh/svh units (LengthRow), never a row of its own.
|
|
687
701
|
"viewportUnits",
|
|
688
702
|
"transition",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { LayoutNode } from "../../../../core/index.ts";
|
|
1
|
+
import type { Layout, LayoutNode } from "../../../../core/index.ts";
|
|
2
2
|
import type { ThemePartType } from "../../../../core/theme/part-types.ts";
|
|
3
|
+
import { someNode } from "../../../../core/tree-ops.ts";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Parts where a Loop can get posts: archive templates, and synced sections (which an archive
|
|
@@ -7,17 +8,47 @@ import type { ThemePartType } from "../../../../core/theme/part-types.ts";
|
|
|
7
8
|
*/
|
|
8
9
|
const LOOP_PARTS: ReadonlySet<ThemePartType> = new Set(["archive", "section"]);
|
|
9
10
|
|
|
11
|
+
/** A Loop that lists a collection of its own (W-308) rather than the archive's posts. */
|
|
12
|
+
const collectionOf = (node: LayoutNode): string | undefined => {
|
|
13
|
+
const collection = node.type === "loop" ? node.props.collection : undefined;
|
|
14
|
+
return typeof collection === "string" && collection ? collection : undefined;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* W-1090 (#31): an archive's Pagination pages through the archive's posts, which only a Loop
|
|
19
|
+
* without a collection lists. True when the archive has Loops and all of them list a collection.
|
|
20
|
+
*/
|
|
21
|
+
const onlyCollectionLoops = (layout: Layout): boolean =>
|
|
22
|
+
someNode(layout.root, (n) => collectionOf(n) !== undefined) &&
|
|
23
|
+
!someNode(layout.root, (n) => n.type === "loop" && collectionOf(n) === undefined);
|
|
24
|
+
|
|
10
25
|
/**
|
|
11
26
|
* W-271: a Loop or Pagination outside an archive template previews sample posts on the canvas,
|
|
12
|
-
* but the live page gets no posts, so it renders nothing there.
|
|
27
|
+
* but the live page gets no posts, so it renders nothing there. W-1090 (#31): in an archive
|
|
28
|
+
* template, a Loop with a collection lists the same entries on every archive page. Undefined
|
|
29
|
+
* where it works as it looks.
|
|
13
30
|
*/
|
|
14
31
|
export function loopContextNote(
|
|
15
32
|
node: LayoutNode,
|
|
16
33
|
partType: ThemePartType | undefined,
|
|
34
|
+
layout?: Layout | null,
|
|
17
35
|
): string | undefined {
|
|
36
|
+
if (partType === "archive" && collectionOf(node)) {
|
|
37
|
+
return "This Loop lists its own collection, so it shows the same entries on every page of the archive and ignores the archive's category or tag. To list the archive's posts page by page, leave Collection empty.";
|
|
38
|
+
}
|
|
39
|
+
if (
|
|
40
|
+
partType === "archive" &&
|
|
41
|
+
node.type === "pagination" &&
|
|
42
|
+
layout &&
|
|
43
|
+
onlyCollectionLoops(layout)
|
|
44
|
+
) {
|
|
45
|
+
return "Pagination pages through the archive's posts, but the Loop here lists its own collection, so every page would show the same entries. To page through the archive, leave its Collection empty.";
|
|
46
|
+
}
|
|
18
47
|
if (partType && LOOP_PARTS.has(partType)) return undefined;
|
|
48
|
+
// W-308: a collection Loop lists its entries on any page.
|
|
49
|
+
if (collectionOf(node)) return undefined;
|
|
19
50
|
if (node.type === "loop") {
|
|
20
|
-
return "A Loop lists posts only in an Archive template. Here the editor shows sample posts, but the live page shows nothing. Build post lists in Theme Builder › Archive.";
|
|
51
|
+
return "A Loop lists posts only in an Archive template. Here the editor shows sample posts, but the live page shows nothing. Build post lists in Theme Builder › Archive, or pick a Collection to list its entries here.";
|
|
21
52
|
}
|
|
22
53
|
if (node.type === "pagination") {
|
|
23
54
|
return "Pagination shows only in an Archive template with more than one page. Here the live page shows nothing.";
|
|
@@ -179,7 +179,17 @@ const SECTION_KEYS: Record<StyleSectionId, StyleKey[]> = {
|
|
|
179
179
|
"flexShrink",
|
|
180
180
|
"flexBasis",
|
|
181
181
|
],
|
|
182
|
-
position: [
|
|
182
|
+
position: [
|
|
183
|
+
"position",
|
|
184
|
+
"top",
|
|
185
|
+
"right",
|
|
186
|
+
"bottom",
|
|
187
|
+
"left",
|
|
188
|
+
"zIndex",
|
|
189
|
+
"alignSelf",
|
|
190
|
+
"order",
|
|
191
|
+
"stickyMotion",
|
|
192
|
+
],
|
|
183
193
|
typography: [
|
|
184
194
|
"fontFamily",
|
|
185
195
|
"fontSize",
|
|
@@ -300,6 +310,10 @@ const TYPE_SECTION_KEYS: Record<string, Partial<Record<StyleSectionId, StyleKey[
|
|
|
300
310
|
|
|
301
311
|
const OFFSETS = new Set<StyleKey>(["top", "right", "bottom", "left"]);
|
|
302
312
|
|
|
313
|
+
/** W-1070: "When the page scrolls" is for elements that stay in view: sticky or fixed. */
|
|
314
|
+
const pinned = (position: FlatStyleProps["position"]) =>
|
|
315
|
+
position === "sticky" || position === "fixed";
|
|
316
|
+
|
|
303
317
|
/** Offsets only do anything once the element is positioned (W-088). */
|
|
304
318
|
export const offsetsApply = (position: FlatStyleProps["position"]) =>
|
|
305
319
|
position !== undefined && position !== "static";
|
|
@@ -319,7 +333,9 @@ export function keysFor(
|
|
|
319
333
|
(
|
|
320
334
|
TYPE_SECTION_KEYS[type]?.[section] ??
|
|
321
335
|
SECTION_KEYS[section].filter((key) => ONLY_FOR[key]?.includes(type) ?? true)
|
|
322
|
-
)
|
|
336
|
+
)
|
|
337
|
+
.filter((key) => !OFFSETS.has(key) || offsetsApply(position))
|
|
338
|
+
.filter((key) => key !== "stickyMotion" || pinned(position)),
|
|
323
339
|
);
|
|
324
340
|
const keys = SECTION_KEYS[section].filter(
|
|
325
341
|
(key) => offered.has(key) || style?.[key] !== undefined,
|
|
@@ -427,6 +443,7 @@ export const STYLE_LABELS: Record<StyleKey, string> = {
|
|
|
427
443
|
entrance: "Entrance",
|
|
428
444
|
scrollMotion: "Scroll motion",
|
|
429
445
|
loopMotion: "Loop",
|
|
446
|
+
stickyMotion: "When the page scrolls",
|
|
430
447
|
viewportUnits: "Viewport units",
|
|
431
448
|
iconRotate: "Rotate",
|
|
432
449
|
iconFlip: "Flip",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { MAX_URL_PARAM_RULES, URL_PARAM_NAME, type UrlParamRule } from "../../../core/index.ts";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* W-1081: a popup's URL rules as the editor writes them, one per line: `utm_source=newsletter`
|
|
5
|
+
* (that value), `coupon` (there at all), `!preview` or `!lang=fr` (not there).
|
|
6
|
+
*/
|
|
7
|
+
export function formatUrlRules(rules: readonly UrlParamRule[] | null | undefined): string {
|
|
8
|
+
return (rules ?? [])
|
|
9
|
+
.map((r) => `${r.absent ? "!" : ""}${r.name}${r.value === undefined ? "" : `=${r.value}`}`)
|
|
10
|
+
.join("\n");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type ParsedUrlRules = { ok: true; rules: UrlParamRule[] } | { ok: false; message: string };
|
|
14
|
+
|
|
15
|
+
export function parseUrlRules(text: string): ParsedUrlRules {
|
|
16
|
+
const lines = text
|
|
17
|
+
.split("\n")
|
|
18
|
+
.map((line) => line.trim())
|
|
19
|
+
.filter(Boolean);
|
|
20
|
+
if (lines.length > MAX_URL_PARAM_RULES)
|
|
21
|
+
return { ok: false, message: `Use at most ${MAX_URL_PARAM_RULES} rules.` };
|
|
22
|
+
const rules: UrlParamRule[] = [];
|
|
23
|
+
for (const line of lines) {
|
|
24
|
+
const absent = line.startsWith("!");
|
|
25
|
+
const body = absent ? line.slice(1).trim() : line;
|
|
26
|
+
const at = body.indexOf("=");
|
|
27
|
+
const name = (at === -1 ? body : body.slice(0, at)).trim();
|
|
28
|
+
if (!URL_PARAM_NAME.test(name))
|
|
29
|
+
return {
|
|
30
|
+
ok: false,
|
|
31
|
+
message: `"${line}" isn't a rule: write a name such as utm_source, then =value if you like.`,
|
|
32
|
+
};
|
|
33
|
+
const value = at === -1 ? undefined : body.slice(at + 1).trim();
|
|
34
|
+
if (value !== undefined && value.length > 200)
|
|
35
|
+
return { ok: false, message: "A value can be at most 200 characters." };
|
|
36
|
+
rules.push({
|
|
37
|
+
name,
|
|
38
|
+
...(value === undefined ? {} : { value }),
|
|
39
|
+
...(absent ? { absent: true } : {}),
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return { ok: true, rules };
|
|
43
|
+
}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { findNode, isParentNode, type Layout } from "../../../core/index.ts";
|
|
3
|
+
import { dragStash } from "../dnd/drag-stash.ts";
|
|
4
|
+
import { draggedSource } from "../dnd/dragged-source.ts";
|
|
5
|
+
import { EXISTING_ELEMENT_MIME, NEW_ELEMENT_MIME, transferKinds } from "../dnd/drop-target.ts";
|
|
6
|
+
import {
|
|
7
|
+
autoScrollStep,
|
|
8
|
+
depthAtX,
|
|
9
|
+
EXPAND_DELAY_MS,
|
|
10
|
+
layerZone,
|
|
11
|
+
resolveLayerDrop,
|
|
12
|
+
type LayerDrop,
|
|
13
|
+
} from "../dnd/layer-drop.ts";
|
|
14
|
+
|
|
15
|
+
/** What Layers shows during a drag (W-1080). */
|
|
16
|
+
type LayersDropShown = {
|
|
17
|
+
/** The row outlined: the container a drop goes inside, or the refused row. */
|
|
18
|
+
mark: { id: string; kind: "inside" | "invalid" } | null;
|
|
19
|
+
/** The insertion line, in list pixels; `start` is from the inline-start edge (right in RTL). */
|
|
20
|
+
line: { top: number; start: number } | null;
|
|
21
|
+
/** Why the drop is refused, next to the refused row. */
|
|
22
|
+
refusal: { top: number; start: number; reason: string } | null;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const sameShown = (a: LayersDropShown | null, b: LayersDropShown | null) =>
|
|
26
|
+
JSON.stringify(a) === JSON.stringify(b);
|
|
27
|
+
|
|
28
|
+
/** Layers reads right to left when the admin does; indents then grow from the right edge. */
|
|
29
|
+
const isRtl = (el: Element) =>
|
|
30
|
+
getComputedStyle(el).direction === "rtl" || el.closest("[dir]")?.getAttribute("dir") === "rtl";
|
|
31
|
+
|
|
32
|
+
export type LayersDropCallbacks = {
|
|
33
|
+
/** Adds a new element from the Add panel at the drop. */
|
|
34
|
+
onDropNew?: (type: string, parentId: string, index: number) => void;
|
|
35
|
+
/** Moves an element (dragged from Layers or the canvas) to the drop. */
|
|
36
|
+
onMoveTo?: (id: string, parentId: string, index: number) => void;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type Live = {
|
|
40
|
+
layout: Layout | null;
|
|
41
|
+
depths: Map<string, number>;
|
|
42
|
+
collapsed: Set<string>;
|
|
43
|
+
expand: (id: string) => void;
|
|
44
|
+
} & LayersDropCallbacks;
|
|
45
|
+
|
|
46
|
+
const rowOf = (target: EventTarget | null): HTMLElement | null =>
|
|
47
|
+
target instanceof Element ? target.closest<HTMLElement>("[data-emvb-layer]") : null;
|
|
48
|
+
|
|
49
|
+
/** The element that scrolls Layers: the left panel itself. */
|
|
50
|
+
const scrollerOf = (list: HTMLElement): HTMLElement | null =>
|
|
51
|
+
list.closest<HTMLElement>(".emvb-panel") ?? list.parentElement;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* W-1080: drag Add tiles, Layers rows or canvas elements onto the Layers list. Between rows draws a
|
|
55
|
+
* line at the new element's depth, the middle of a row that holds others outlines it, a refused
|
|
56
|
+
* drop outlines the row in danger with the canvas's reason. A collapsed row opens after
|
|
57
|
+
* `EXPAND_DELAY_MS`; the panel scrolls near its edges. The drop runs the canvas's own
|
|
58
|
+
* add and move (one undo step each).
|
|
59
|
+
*/
|
|
60
|
+
export function useLayersDrop(
|
|
61
|
+
live: Live,
|
|
62
|
+
indent: (depth: number) => number,
|
|
63
|
+
listRef: React.RefObject<HTMLUListElement | null>,
|
|
64
|
+
) {
|
|
65
|
+
const [shown, setShownState] = React.useState<LayersDropShown | null>(null);
|
|
66
|
+
// dragover fires every few milliseconds; only a changed line or outline re-renders Layers.
|
|
67
|
+
const setShown = React.useCallback(
|
|
68
|
+
(next: LayersDropShown | null) =>
|
|
69
|
+
setShownState((current) => (sameShown(current, next) ? current : next)),
|
|
70
|
+
[],
|
|
71
|
+
);
|
|
72
|
+
const latest = React.useRef(live);
|
|
73
|
+
React.useLayoutEffect(() => {
|
|
74
|
+
latest.current = live;
|
|
75
|
+
});
|
|
76
|
+
const expandTimer = React.useRef<{ id: string; timer: ReturnType<typeof setTimeout> } | null>(
|
|
77
|
+
null,
|
|
78
|
+
);
|
|
79
|
+
const scroll = React.useRef<{ step: number; frame: number | null }>({ step: 0, frame: null });
|
|
80
|
+
|
|
81
|
+
const stopTimers = React.useCallback(() => {
|
|
82
|
+
if (expandTimer.current) clearTimeout(expandTimer.current.timer);
|
|
83
|
+
expandTimer.current = null;
|
|
84
|
+
scroll.current.step = 0;
|
|
85
|
+
if (scroll.current.frame !== null) cancelAnimationFrame(scroll.current.frame);
|
|
86
|
+
scroll.current.frame = null;
|
|
87
|
+
}, []);
|
|
88
|
+
const clear = React.useCallback(() => {
|
|
89
|
+
stopTimers();
|
|
90
|
+
setShown(null);
|
|
91
|
+
}, [stopTimers, setShown]);
|
|
92
|
+
|
|
93
|
+
React.useEffect(() => stopTimers, [stopTimers]);
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
if (!shown) return;
|
|
96
|
+
// Entering anything outside Layers (the canvas, the Add tab) clears it. dragleave can't: it
|
|
97
|
+
// also fires moving between a row's own children.
|
|
98
|
+
const enter = (event: DragEvent) => {
|
|
99
|
+
const panel = listRef.current?.parentElement;
|
|
100
|
+
if (!(event.target instanceof Node) || !panel?.contains(event.target)) clear();
|
|
101
|
+
};
|
|
102
|
+
window.addEventListener("dragend", clear);
|
|
103
|
+
window.addEventListener("drop", clear);
|
|
104
|
+
document.addEventListener("dragenter", enter);
|
|
105
|
+
return () => {
|
|
106
|
+
window.removeEventListener("dragend", clear);
|
|
107
|
+
window.removeEventListener("drop", clear);
|
|
108
|
+
document.removeEventListener("dragenter", enter);
|
|
109
|
+
};
|
|
110
|
+
}, [shown, clear, listRef]);
|
|
111
|
+
|
|
112
|
+
const enabled = !!(live.onDropNew || live.onMoveTo);
|
|
113
|
+
|
|
114
|
+
const resolve = (
|
|
115
|
+
event: React.DragEvent,
|
|
116
|
+
): { drop: LayerDrop; row: HTMLElement; depth: number; existing: boolean } | null => {
|
|
117
|
+
const { layout, depths, collapsed } = latest.current;
|
|
118
|
+
const list = listRef.current;
|
|
119
|
+
if (!layout || !list) return null;
|
|
120
|
+
const kinds = transferKinds(event.dataTransfer);
|
|
121
|
+
if (!kinds.neu && !kinds.existing) return null;
|
|
122
|
+
const row =
|
|
123
|
+
rowOf(event.target) ??
|
|
124
|
+
list.querySelector<HTMLElement>(`[data-emvb-layer="${CSS.escape(layout.root.id)}"]`);
|
|
125
|
+
const id = row?.getAttribute("data-emvb-layer");
|
|
126
|
+
const node = id ? findNode(layout, id) : undefined;
|
|
127
|
+
if (!row || !id || !node) return null;
|
|
128
|
+
const depth = depths.get(id) ?? 0;
|
|
129
|
+
const holds = isParentNode(node);
|
|
130
|
+
const open = holds && !collapsed.has(id) && node.children.length > 0;
|
|
131
|
+
const rect = row.getBoundingClientRect();
|
|
132
|
+
const onRow = rowOf(event.target) !== null;
|
|
133
|
+
const zone = onRow
|
|
134
|
+
? layerZone(event.clientY - rect.top, rect.height, holds, id === layout.root.id)
|
|
135
|
+
: "inside";
|
|
136
|
+
// The pointer's distance from the row's inline-start edge, where the indent is.
|
|
137
|
+
const fromStart = isRtl(row) ? rect.right - event.clientX : event.clientX - rect.left;
|
|
138
|
+
const outdent = depth - depthAtX(fromStart, indent, depth);
|
|
139
|
+
const source = draggedSource(event.dataTransfer, kinds.existing);
|
|
140
|
+
const drop = resolveLayerDrop(layout, { id, depth, open }, zone, source, outdent);
|
|
141
|
+
return drop ? { drop, row, depth, existing: kinds.existing } : null;
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
const autoScroll = (clientY: number) => {
|
|
145
|
+
const list = listRef.current;
|
|
146
|
+
const scroller = list ? scrollerOf(list) : null;
|
|
147
|
+
if (!scroller) return;
|
|
148
|
+
const box = scroller.getBoundingClientRect();
|
|
149
|
+
scroll.current.step = autoScrollStep(clientY, box.top, box.bottom);
|
|
150
|
+
if (scroll.current.step === 0 || scroll.current.frame !== null) return;
|
|
151
|
+
const tick = () => {
|
|
152
|
+
if (scroll.current.step === 0) {
|
|
153
|
+
scroll.current.frame = null;
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
scroller.scrollTop += scroll.current.step;
|
|
157
|
+
scroll.current.frame = requestAnimationFrame(tick);
|
|
158
|
+
};
|
|
159
|
+
scroll.current.frame = requestAnimationFrame(tick);
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const autoExpand = (id: string) => {
|
|
163
|
+
const { layout, collapsed } = latest.current;
|
|
164
|
+
const node = layout ? findNode(layout, id) : undefined;
|
|
165
|
+
const closed = !!node && isParentNode(node) && node.children.length > 0 && collapsed.has(id);
|
|
166
|
+
if (expandTimer.current?.id === id && closed) return;
|
|
167
|
+
if (expandTimer.current) clearTimeout(expandTimer.current.timer);
|
|
168
|
+
expandTimer.current = closed
|
|
169
|
+
? {
|
|
170
|
+
id,
|
|
171
|
+
timer: setTimeout(() => {
|
|
172
|
+
expandTimer.current = null;
|
|
173
|
+
latest.current.expand(id);
|
|
174
|
+
}, EXPAND_DELAY_MS),
|
|
175
|
+
}
|
|
176
|
+
: null;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
const onDragOver = (event: React.DragEvent<HTMLElement>) => {
|
|
180
|
+
if (!enabled) return;
|
|
181
|
+
const found = resolve(event);
|
|
182
|
+
if (!found) return;
|
|
183
|
+
event.preventDefault();
|
|
184
|
+
autoScroll(event.clientY);
|
|
185
|
+
const { drop, row, depth, existing } = found;
|
|
186
|
+
autoExpand(row.getAttribute("data-emvb-layer") ?? "");
|
|
187
|
+
const top = row.offsetTop;
|
|
188
|
+
if (!drop.ok) {
|
|
189
|
+
event.dataTransfer.dropEffect = "none";
|
|
190
|
+
setShown({
|
|
191
|
+
mark: { id: row.getAttribute("data-emvb-layer") ?? "", kind: "invalid" },
|
|
192
|
+
line: null,
|
|
193
|
+
refusal: { top: top + row.offsetHeight + 2, start: indent(depth), reason: drop.reason },
|
|
194
|
+
});
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
event.dataTransfer.dropEffect = existing ? "move" : "copy";
|
|
198
|
+
const { place } = drop;
|
|
199
|
+
setShown({
|
|
200
|
+
mark: place.edge === null ? { id: place.parentId, kind: "inside" } : null,
|
|
201
|
+
line:
|
|
202
|
+
place.edge === null
|
|
203
|
+
? null
|
|
204
|
+
: {
|
|
205
|
+
top: place.edge === "top" ? top - 1 : top + row.offsetHeight - 1,
|
|
206
|
+
start: indent(place.depth),
|
|
207
|
+
},
|
|
208
|
+
refusal: null,
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const onDrop = (event: React.DragEvent<HTMLElement>) => {
|
|
213
|
+
if (!enabled) return;
|
|
214
|
+
const found = resolve(event);
|
|
215
|
+
if (!found) return;
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
const transfer = event.dataTransfer;
|
|
218
|
+
const id = transfer.getData(EXISTING_ELEMENT_MIME) || dragStash.id() || "";
|
|
219
|
+
const type = transfer.getData(NEW_ELEMENT_MIME) || dragStash.type() || "";
|
|
220
|
+
dragStash.clear();
|
|
221
|
+
clear();
|
|
222
|
+
if (!found.drop.ok) return;
|
|
223
|
+
const { parentId, index } = found.drop.place;
|
|
224
|
+
if (found.existing) {
|
|
225
|
+
if (id) latest.current.onMoveTo?.(id, parentId, index);
|
|
226
|
+
} else if (type) latest.current.onDropNew?.(type, parentId, index);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
// dragenter takes the same path: the spec makes a cancelled dragenter the drop target, and a
|
|
230
|
+
// browser may send only dragenter while the pointer crosses rows.
|
|
231
|
+
return { shown, handlers: enabled ? { onDragEnter: onDragOver, onDragOver, onDrop } : {} };
|
|
232
|
+
}
|
|
@@ -54,7 +54,8 @@ export type EditorAction =
|
|
|
54
54
|
| { type: "select"; id: string | null }
|
|
55
55
|
| { type: "update-node"; id: string; update: (node: LayoutNode) => LayoutNode }
|
|
56
56
|
| { type: "delete-node"; id: string }
|
|
57
|
-
|
|
57
|
+
/** Restores the deletion of `id`, only while it is still the last one (W-1053). */
|
|
58
|
+
| { type: "restore"; id: string }
|
|
58
59
|
| { type: "add-root-container" }
|
|
59
60
|
| { type: "add-node"; node: LayoutNode; parentId: string; index: number }
|
|
60
61
|
| { type: "move-node"; id: string; parentId: string; index: number }
|
|
@@ -205,7 +206,8 @@ export function editorReducer(state: EditorState, action: EditorAction): EditorS
|
|
|
205
206
|
}
|
|
206
207
|
case "restore": {
|
|
207
208
|
const removed = state.lastDeleted;
|
|
208
|
-
|
|
209
|
+
// W-1053: a Restore left over from a deletion that Undo already took back does nothing.
|
|
210
|
+
if (!removed || removed.node.id !== action.id || !state.page.layout) return state;
|
|
209
211
|
const layout = insertNode(state.page.layout, removed.parentId, removed.index, removed.node);
|
|
210
212
|
return withLayout(state, layout, removed.node.id, null);
|
|
211
213
|
}
|