@perkyzz/emvb 0.9.0 → 1.1.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 +10 -1
- package/package.json +2 -2
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/bulk-api.ts +67 -0
- package/src/admin/content-api.ts +10 -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 +3 -1
- package/src/admin/editor/Editor.tsx +311 -250
- package/src/admin/editor/Timeline.tsx +8 -3
- package/src/admin/editor/TopBar.tsx +29 -7
- package/src/admin/editor/canvas/CanvasFrame.tsx +7 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +31 -10
- 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/co-design.ts +190 -0
- package/src/admin/editor/dnd/new-element.ts +48 -4
- package/src/admin/editor/editor-chrome.tsx +8 -6
- package/src/admin/editor/editor-commands.ts +15 -4
- package/src/admin/editor/editor-css.ts +2 -1
- package/src/admin/editor/element-chrome.ts +3 -1
- package/src/admin/editor/extension-manifests.ts +20 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
- package/src/admin/editor/extensions-context.tsx +27 -0
- package/src/admin/editor/feature-css.ts +17 -0
- package/src/admin/editor/palette-items.ts +2 -2
- package/src/admin/editor/panels/AddPanel.tsx +31 -1
- package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
- package/src/admin/editor/panels/ClassesSection.tsx +9 -6
- package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ElementPanel.tsx +68 -20
- package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
- package/src/admin/editor/panels/LayersPanel.tsx +10 -6
- package/src/admin/editor/panels/LeftPanel.tsx +33 -5
- package/src/admin/editor/panels/PageSettings.tsx +4 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +72 -15
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
- package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
- package/src/admin/editor/panels/settings/EffectsControls.tsx +183 -10
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +25 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +63 -19
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +19 -1
- package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
- package/src/admin/editor/panels/settings/StyleRow.tsx +120 -13
- package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
- package/src/admin/editor/panels/settings/background-mode.ts +14 -11
- package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
- package/src/admin/editor/panels/settings/box-sides.ts +22 -14
- package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
- package/src/admin/editor/panels/settings/length-units.ts +68 -4
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +52 -10
- package/src/admin/editor/panels/style-target.ts +22 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/section-templates.ts +26 -4
- package/src/admin/editor/store.ts +14 -4
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +7 -5
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +18 -7
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/export-api.ts +221 -0
- package/src/admin/index.tsx +6 -1
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +9 -26
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ExportDialog.tsx +395 -0
- package/src/admin/pages/ImportButton.tsx +18 -0
- package/src/admin/pages/ImportElementorDialog.tsx +669 -0
- package/src/admin/pages/ImportPageLinks.tsx +86 -0
- package/src/admin/pages/PageList.tsx +82 -3
- package/src/admin/pages/ThemePartList.tsx +52 -2
- package/src/admin/pages/bulk.tsx +303 -0
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/search.ts +20 -0
- package/src/admin/theme-api.ts +4 -0
- package/src/admin/ui.ts +50 -4
- 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/content-port.ts +14 -1
- package/src/astro/render.ts +6 -6
- package/src/astro/resolve-theme.ts +25 -8
- package/src/astro/resolve.ts +89 -2
- package/src/astro/tabs/runtime.ts +16 -6
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +45 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +305 -0
- package/src/core/css/generate.ts +151 -20
- package/src/core/css/scope.ts +10 -2
- package/src/core/css/trace.ts +47 -13
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +28 -9
- package/src/core/design/devices.ts +89 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +31 -5
- package/src/core/elements/dynamic-elements.ts +3 -3
- package/src/core/elements/index.ts +73 -9
- package/src/core/export/runtimes.generated.ts +9 -0
- package/src/core/export/site.ts +562 -0
- package/src/core/export/zip.ts +95 -0
- package/src/core/extensions/define.ts +13 -0
- package/src/core/extensions/index.ts +41 -0
- package/src/core/extensions/namespace.ts +82 -0
- package/src/core/extensions/normalize.ts +141 -0
- package/src/core/extensions/placeholder.ts +41 -0
- package/src/core/extensions/registry.ts +94 -0
- package/src/core/extensions/render-ext.ts +118 -0
- package/src/core/extensions/safe-nodes.ts +93 -0
- package/src/core/extensions/schema.ts +112 -0
- package/src/core/extensions/types.ts +159 -0
- package/src/core/forms/binding.ts +1 -1
- package/src/core/history/diff.ts +26 -1
- package/src/core/import/elementor/atomic.ts +1608 -0
- package/src/core/import/elementor/classes.ts +127 -0
- package/src/core/import/elementor/context.ts +429 -0
- package/src/core/import/elementor/counter-steps.ts +72 -0
- package/src/core/import/elementor/css.ts +445 -0
- package/src/core/import/elementor/html.ts +500 -0
- package/src/core/import/elementor/index.ts +967 -0
- package/src/core/import/elementor/inline-marks.ts +81 -0
- package/src/core/import/elementor/snapshots.ts +48 -0
- package/src/core/import/elementor/style.ts +429 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +96 -0
- package/src/core/json-schema.ts +114 -0
- package/src/core/limits.ts +19 -0
- package/src/core/migrate/index.ts +6 -1
- package/src/core/migrate/v18.ts +222 -0
- package/src/core/perf/meter.ts +42 -24
- package/src/core/portable-text-export.ts +243 -0
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/public-attributes.ts +30 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +222 -23
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/tabs.ts +18 -11
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +151 -10
- package/src/core/sanitize/motion.ts +116 -0
- package/src/core/saved-sections.ts +6 -0
- package/src/core/schema/descriptors.ts +3 -1
- package/src/core/schema/design.ts +4 -3
- package/src/core/schema/layout.ts +92 -16
- package/src/core/schema/style.ts +296 -112
- package/src/core/search-text.ts +70 -0
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +2 -0
- package/src/core/theme/popup-rules.ts +33 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +24 -0
- package/src/mcp/errors.ts +3 -1
- package/src/mcp/ports.ts +67 -0
- package/src/mcp/prompts.ts +1 -11
- package/src/mcp/proposals.ts +281 -0
- package/src/mcp/read.ts +10 -10
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +5 -1
- package/src/server/icon-routes.ts +52 -12
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +35 -2
- package/src/server/presence.ts +78 -0
- package/src/server/proposals.ts +261 -0
- package/src/server/requests.ts +196 -0
- package/src/server/tools-served.ts +45 -0
|
@@ -36,7 +36,8 @@ import {
|
|
|
36
36
|
type Arranged,
|
|
37
37
|
inheritedStyle,
|
|
38
38
|
type LayoutNode,
|
|
39
|
-
type
|
|
39
|
+
type Device,
|
|
40
|
+
type EditorDevice,
|
|
40
41
|
type ResponsiveDevice,
|
|
41
42
|
classStylesInListOrder,
|
|
42
43
|
iconHasAdjustableStroke,
|
|
@@ -44,7 +45,8 @@ import {
|
|
|
44
45
|
resolveCascade,
|
|
45
46
|
SAMPLE_POST,
|
|
46
47
|
STYLE_STATES,
|
|
47
|
-
type
|
|
48
|
+
type FlatStyleProps,
|
|
49
|
+
flattenMotion,
|
|
48
50
|
type StyleStates,
|
|
49
51
|
boxLinkHeldBack,
|
|
50
52
|
} from "../../../core/index.ts";
|
|
@@ -65,6 +67,7 @@ import {
|
|
|
65
67
|
HtmlIdField,
|
|
66
68
|
} from "./settings/AdvancedFields.tsx";
|
|
67
69
|
import { ClassChipInput } from "./settings/ClassChipInput.tsx";
|
|
70
|
+
import { useExtensionElement } from "../extensions-context.tsx";
|
|
68
71
|
import { StateDot, StateSwitcher, type StyleStateChoice } from "./settings/StateSwitcher.tsx";
|
|
69
72
|
import {
|
|
70
73
|
DEFAULT_UI,
|
|
@@ -131,7 +134,7 @@ const writeSections = (type: string, open: Set<StyleSectionId>) => {
|
|
|
131
134
|
}
|
|
132
135
|
};
|
|
133
136
|
|
|
134
|
-
const countSet = (type: string, style:
|
|
137
|
+
const countSet = (type: string, style: FlatStyleProps | undefined, section: StyleSectionId) =>
|
|
135
138
|
keysFor(type, section, style).filter((key) => style?.[key] !== undefined).length;
|
|
136
139
|
|
|
137
140
|
/** Whether any state sets a key of this section (the section header's dot in Normal). */
|
|
@@ -149,6 +152,14 @@ const NORMAL_ONLY_KEYS = new Set<StyleKey>([
|
|
|
149
152
|
"scrollMotion",
|
|
150
153
|
]);
|
|
151
154
|
|
|
155
|
+
/** UX-063: which device is being edited and what it overrides (W-956 Laptop, W-959 Wide screen). */
|
|
156
|
+
const DEVICE_NOTE: Record<Exclude<EditorDevice, "desktop">, string> = {
|
|
157
|
+
wide: "Editing Wide screen (2400 px and up). These styles override Desktop.",
|
|
158
|
+
laptop: "Editing Laptop. These styles override Desktop.",
|
|
159
|
+
tablet: "Editing Tablet. These styles override Laptop and Desktop.",
|
|
160
|
+
mobile: "Editing Mobile. These styles override Tablet, Laptop and Desktop.",
|
|
161
|
+
};
|
|
162
|
+
|
|
152
163
|
const JUMP_HELP: Record<Exclude<StyleStateChoice, "normal">, string> = {
|
|
153
164
|
hover: "Changing size or position on hover can make the page jump.",
|
|
154
165
|
focus: "Changing size or position on focus can make the page jump.",
|
|
@@ -159,7 +170,7 @@ const JUMP_HELP: Record<Exclude<StyleStateChoice, "normal">, string> = {
|
|
|
159
170
|
const positionInEffect = (
|
|
160
171
|
node: LayoutNode,
|
|
161
172
|
design: DesignSystem,
|
|
162
|
-
cls: { style?:
|
|
173
|
+
cls: { style?: FlatStyleProps } | undefined,
|
|
163
174
|
) =>
|
|
164
175
|
cls
|
|
165
176
|
? cls.style?.position
|
|
@@ -218,7 +229,7 @@ type Props = {
|
|
|
218
229
|
/** The chosen style state, for the canvas preview (W-089). */
|
|
219
230
|
onStyleState?: (nodeId: string, state: StyleStateChoice) => void;
|
|
220
231
|
/** Tablet and mobile edit overrides. Desktop edits `style` (W-096). */
|
|
221
|
-
device?:
|
|
232
|
+
device?: EditorDevice;
|
|
222
233
|
/** Add, move and delete for Accordion items and Tabs panels (W-130). */
|
|
223
234
|
items?: ItemActions;
|
|
224
235
|
/** The theme part being edited, if any, for the H1 warning (W-208). */
|
|
@@ -321,7 +332,7 @@ function pairFields<F extends { key: string }>(fields: readonly F[]): F[][] {
|
|
|
321
332
|
|
|
322
333
|
/** UX-071: fields that only apply to some values of another field on the same element. */
|
|
323
334
|
const SHOWN_WHEN: Readonly<
|
|
324
|
-
Record<string, (props: Record<string, unknown>, device:
|
|
335
|
+
Record<string, (props: Record<string, unknown>, device: Device) => boolean>
|
|
325
336
|
> = {
|
|
326
337
|
"loop.columns": (props) => props["display"] === "grid" || props["display"] === "cards",
|
|
327
338
|
"pagination.countText": (props) => props["showCount"] === true,
|
|
@@ -335,7 +346,7 @@ const SHOWN_WHEN: Readonly<
|
|
|
335
346
|
"grid.columnTracksMobile": (_props, device) => device === "mobile",
|
|
336
347
|
};
|
|
337
348
|
|
|
338
|
-
function fieldShown(key: string, node: LayoutNode, device:
|
|
349
|
+
function fieldShown(key: string, node: LayoutNode, device: Device = "desktop"): boolean {
|
|
339
350
|
const props = node.props as Record<string, unknown>;
|
|
340
351
|
// A stored value always shows, so it can be seen and reset.
|
|
341
352
|
if (props[key] !== undefined) return true;
|
|
@@ -349,7 +360,19 @@ function fieldShown(key: string, node: LayoutNode, device: PopupDevice = "deskto
|
|
|
349
360
|
|
|
350
361
|
/** Right panel with an element selected (IA / W-021): descriptor Content + Style sections. */
|
|
351
362
|
export function ElementPanel(props: Props) {
|
|
352
|
-
const
|
|
363
|
+
const builtIn = ELEMENT_DESCRIPTORS.find((d) => d.type === props.node.type);
|
|
364
|
+
const extension = useExtensionElement(props.node.type);
|
|
365
|
+
const descriptor: ElementDescriptor | undefined = builtIn
|
|
366
|
+
? builtIn
|
|
367
|
+
: extension
|
|
368
|
+
? {
|
|
369
|
+
type: extension.type,
|
|
370
|
+
name: extension.label,
|
|
371
|
+
group: extension.group,
|
|
372
|
+
defaultTab: "content",
|
|
373
|
+
fields: [...extension.fields],
|
|
374
|
+
}
|
|
375
|
+
: undefined;
|
|
353
376
|
if (!descriptor) {
|
|
354
377
|
return (
|
|
355
378
|
<div
|
|
@@ -357,9 +380,21 @@ export function ElementPanel(props: Props) {
|
|
|
357
380
|
data-emvb-panel="element"
|
|
358
381
|
data-emvb-element={props.node.type}
|
|
359
382
|
>
|
|
360
|
-
<h2 className="emvb-panel-title">
|
|
383
|
+
<h2 className="emvb-panel-title">
|
|
384
|
+
{props.node.type.startsWith("ext:") ? "Missing extension" : "Unknown element"}
|
|
385
|
+
</h2>
|
|
361
386
|
<p className="emvb-helper">
|
|
362
|
-
|
|
387
|
+
{props.node.type.startsWith("ext:") ? (
|
|
388
|
+
<>
|
|
389
|
+
This block needs the extension for "{props.node.type}". It can be moved or
|
|
390
|
+
deleted; install the extension to edit it.
|
|
391
|
+
</>
|
|
392
|
+
) : (
|
|
393
|
+
<>
|
|
394
|
+
Unknown element "{props.node.type}". It can be moved or deleted, but not
|
|
395
|
+
edited.
|
|
396
|
+
</>
|
|
397
|
+
)}
|
|
363
398
|
</p>
|
|
364
399
|
{props.rejection && <Alert>{props.rejection}</Alert>}
|
|
365
400
|
</div>
|
|
@@ -413,10 +448,20 @@ function KnownElementPanel({
|
|
|
413
448
|
React.useEffect(() => {
|
|
414
449
|
onStyleState?.(node.id, tab === "style" ? styleState : "normal");
|
|
415
450
|
}, [node.id, styleState, tab, onStyleState]);
|
|
416
|
-
|
|
451
|
+
// W-925: the rows read the flat motion keys; applyStylePatch nests them again.
|
|
452
|
+
// W-959: the own style's `wide` record is Wide screen's, not a Desktop value.
|
|
453
|
+
const { wide: storedWide, ...ownDesktop } = (cls ? cls.style : node.style) ?? {};
|
|
454
|
+
const normal = flattenMotion(cls || node.style ? ownDesktop : undefined);
|
|
417
455
|
const states = cls ? cls.states : node.states;
|
|
418
|
-
const responsive: ResponsiveDevice | null = device === "desktop" ? null : device;
|
|
419
|
-
const
|
|
456
|
+
const responsive: ResponsiveDevice | "wide" | null = device === "desktop" ? null : device;
|
|
457
|
+
const storedDevices = cls ? cls.devices : node.devices;
|
|
458
|
+
const { hidden: _wideHidden, ...wideValues } = storedWide ?? {};
|
|
459
|
+
const ownerDevices = (storedDevices || storedWide) && {
|
|
460
|
+
wide: flattenMotion(storedWide ? wideValues : undefined),
|
|
461
|
+
laptop: flattenMotion(storedDevices?.laptop),
|
|
462
|
+
tablet: flattenMotion(storedDevices?.tablet),
|
|
463
|
+
mobile: flattenMotion(storedDevices?.mobile),
|
|
464
|
+
};
|
|
420
465
|
const style = responsive
|
|
421
466
|
? ownerDevices?.[responsive]
|
|
422
467
|
: styleState === "normal"
|
|
@@ -425,6 +470,9 @@ function KnownElementPanel({
|
|
|
425
470
|
const ownInherited = responsive
|
|
426
471
|
? {
|
|
427
472
|
...normal,
|
|
473
|
+
// W-956: each device inherits the wider ones: Laptop, then Tablet. W-959: Wide screen
|
|
474
|
+
// builds on Desktop only.
|
|
475
|
+
...(responsive !== "laptop" && responsive !== "wide" ? ownerDevices?.laptop : undefined),
|
|
428
476
|
...(responsive === "mobile" ? ownerDevices?.tablet : undefined),
|
|
429
477
|
}
|
|
430
478
|
: styleState === "normal"
|
|
@@ -463,7 +511,9 @@ function KnownElementPanel({
|
|
|
463
511
|
!singleColorOffered &&
|
|
464
512
|
node.props.singleColor !== true &&
|
|
465
513
|
ownColors;
|
|
466
|
-
|
|
514
|
+
// Field values have no laptop or wide screen setting: those devices edit Desktop's.
|
|
515
|
+
const fieldDevice: Device = device === "laptop" || device === "wide" ? "desktop" : device;
|
|
516
|
+
const patchStyle = (patch: Partial<FlatStyleProps>) => {
|
|
467
517
|
const written = applyStylePatch({
|
|
468
518
|
node,
|
|
469
519
|
design,
|
|
@@ -568,7 +618,7 @@ function KnownElementPanel({
|
|
|
568
618
|
</p>
|
|
569
619
|
) : (
|
|
570
620
|
pairFields(
|
|
571
|
-
descriptor.fields.filter((field) => fieldShown(field.key, node,
|
|
621
|
+
descriptor.fields.filter((field) => fieldShown(field.key, node, fieldDevice)),
|
|
572
622
|
).map((row) => {
|
|
573
623
|
const controls = row.map((field) => (
|
|
574
624
|
<React.Fragment key={field.key}>
|
|
@@ -581,7 +631,7 @@ function KnownElementPanel({
|
|
|
581
631
|
duplicateName={
|
|
582
632
|
field.key === "field" && layout ? duplicateFieldName(layout, node.id) : false
|
|
583
633
|
}
|
|
584
|
-
device={
|
|
634
|
+
device={fieldDevice}
|
|
585
635
|
/>
|
|
586
636
|
</React.Fragment>
|
|
587
637
|
));
|
|
@@ -674,10 +724,8 @@ function KnownElementPanel({
|
|
|
674
724
|
) : (
|
|
675
725
|
// UX-063: say which device is being edited, as states say "Editing Hover".
|
|
676
726
|
<p className="emvb-helper" data-emvb-device-note={device}>
|
|
677
|
-
{device
|
|
678
|
-
|
|
679
|
-
: "Editing Tablet. These styles override Desktop."}{" "}
|
|
680
|
-
Hover, Focus and Active are set on Desktop and apply on every device.
|
|
727
|
+
{DEVICE_NOTE[device]} Hover, Focus and Active are set on Desktop and apply on every
|
|
728
|
+
device.
|
|
681
729
|
</p>
|
|
682
730
|
)}
|
|
683
731
|
{!cls && <StyleSources node={node} design={design} device={device} state={styleState} />}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Badge, Button, Checkbox } from "@cloudflare/kumo";
|
|
2
|
+
import { TranslateIcon } from "@phosphor-icons/react";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import type { Layout } from "../../../core/schema/layout.ts";
|
|
5
|
+
import { translatableStrings } from "../../../core/translatable.ts";
|
|
6
|
+
import type { Fetcher } from "../../api.ts";
|
|
7
|
+
import { ApiError } from "../../api.ts";
|
|
8
|
+
import {
|
|
9
|
+
createTranslation,
|
|
10
|
+
listTranslations,
|
|
11
|
+
siteLocales,
|
|
12
|
+
type Translation,
|
|
13
|
+
} from "../../languages-api.ts";
|
|
14
|
+
import { createRequest } from "../../proposals-api.ts";
|
|
15
|
+
import { editorUrl } from "../exit.ts";
|
|
16
|
+
|
|
17
|
+
const nameOf = (locale: string) => {
|
|
18
|
+
try {
|
|
19
|
+
return new Intl.DisplayNames(undefined, { type: "language" }).of(locale) ?? locale;
|
|
20
|
+
} catch {
|
|
21
|
+
return locale;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* W-936 Translate this page (D-068): each language is its own entry. A missing one is created as
|
|
27
|
+
* a draft copy of this layout (EmDash's `translationOf`) and opened; optionally the person's agent
|
|
28
|
+
* is asked to translate it, and its proposal is reviewed in the new page's Agent tab.
|
|
29
|
+
*/
|
|
30
|
+
export function LanguagesSection({
|
|
31
|
+
fetcher,
|
|
32
|
+
collection,
|
|
33
|
+
entryId,
|
|
34
|
+
title,
|
|
35
|
+
slug,
|
|
36
|
+
layout,
|
|
37
|
+
navigate = (url) => window.location.assign(url),
|
|
38
|
+
}: {
|
|
39
|
+
fetcher: Fetcher;
|
|
40
|
+
collection: string;
|
|
41
|
+
entryId: string;
|
|
42
|
+
title: string;
|
|
43
|
+
slug: string;
|
|
44
|
+
layout: Layout | null;
|
|
45
|
+
navigate?: (url: string) => void;
|
|
46
|
+
}) {
|
|
47
|
+
const [site, setSite] = React.useState<{ defaultLocale: string; locales: string[] } | null>(null);
|
|
48
|
+
const [translations, setTranslations] = React.useState<Translation[]>([]);
|
|
49
|
+
const [askAgent, setAskAgent] = React.useState(true);
|
|
50
|
+
const [busy, setBusy] = React.useState<string | null>(null);
|
|
51
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
52
|
+
React.useEffect(() => {
|
|
53
|
+
let cancelled = false;
|
|
54
|
+
siteLocales(fetcher)
|
|
55
|
+
.then(async (locales) => {
|
|
56
|
+
if (cancelled || !locales) return;
|
|
57
|
+
setSite(locales);
|
|
58
|
+
const list = await listTranslations(fetcher, collection, entryId);
|
|
59
|
+
if (!cancelled) setTranslations(list);
|
|
60
|
+
})
|
|
61
|
+
.catch(() => undefined);
|
|
62
|
+
return () => {
|
|
63
|
+
cancelled = true;
|
|
64
|
+
};
|
|
65
|
+
}, [fetcher, collection, entryId]);
|
|
66
|
+
if (!site) return null;
|
|
67
|
+
const current = translations.find((t) => t.id === entryId)?.locale ?? site.defaultLocale;
|
|
68
|
+
const texts = layout ? translatableStrings(layout).length : 0;
|
|
69
|
+
|
|
70
|
+
const translate = async (locale: string) => {
|
|
71
|
+
if (!layout || busy) return;
|
|
72
|
+
setBusy(locale);
|
|
73
|
+
setError(null);
|
|
74
|
+
try {
|
|
75
|
+
const id = await createTranslation(fetcher, {
|
|
76
|
+
collection,
|
|
77
|
+
sourceId: entryId,
|
|
78
|
+
locale,
|
|
79
|
+
title,
|
|
80
|
+
slug,
|
|
81
|
+
layout,
|
|
82
|
+
});
|
|
83
|
+
if (askAgent) {
|
|
84
|
+
await createRequest(
|
|
85
|
+
fetcher,
|
|
86
|
+
collection,
|
|
87
|
+
id,
|
|
88
|
+
`Translate this page from ${nameOf(current)} (${current}) into ${nameOf(locale)} (${locale}). Change only the words (${texts} texts: headings, text, buttons, alt text, labels); keep the layout, links, images and styles.`,
|
|
89
|
+
).catch(() => undefined);
|
|
90
|
+
}
|
|
91
|
+
navigate(editorUrl(id, collection));
|
|
92
|
+
} catch (e) {
|
|
93
|
+
setError(e instanceof ApiError ? e.message : "Couldn't create the translation. Try again.");
|
|
94
|
+
setBusy(null);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<section className="emvb-field-group" aria-label="Languages" data-emvb-languages="">
|
|
100
|
+
<span className="emvb-field-label">Languages</span>
|
|
101
|
+
<ul className="emvb-codesign-ops">
|
|
102
|
+
{site.locales.map((locale) => {
|
|
103
|
+
const found = translations.find((t) => t.locale === locale);
|
|
104
|
+
return (
|
|
105
|
+
<li key={locale} className="emvb-codesign-op" data-emvb-language={locale}>
|
|
106
|
+
<span className="emvb-codesign-op-text">
|
|
107
|
+
{nameOf(locale)} <span className="emvb-helper">({locale})</span>
|
|
108
|
+
</span>
|
|
109
|
+
<span className="emvb-codesign-op-actions">
|
|
110
|
+
{locale === current ? (
|
|
111
|
+
<Badge variant="blue">This page</Badge>
|
|
112
|
+
) : found ? (
|
|
113
|
+
<Button
|
|
114
|
+
size="sm"
|
|
115
|
+
variant="ghost"
|
|
116
|
+
data-emvb-language-open=""
|
|
117
|
+
onClick={() => navigate(editorUrl(found.id, collection))}
|
|
118
|
+
>
|
|
119
|
+
Open
|
|
120
|
+
</Button>
|
|
121
|
+
) : (
|
|
122
|
+
<Button
|
|
123
|
+
size="sm"
|
|
124
|
+
variant="secondary"
|
|
125
|
+
icon={<TranslateIcon aria-hidden="true" />}
|
|
126
|
+
aria-busy={busy === locale || undefined}
|
|
127
|
+
disabled={!layout || (busy !== null && busy !== locale)}
|
|
128
|
+
data-emvb-language-translate=""
|
|
129
|
+
onClick={() => void translate(locale)}
|
|
130
|
+
>
|
|
131
|
+
Translate
|
|
132
|
+
</Button>
|
|
133
|
+
)}
|
|
134
|
+
</span>
|
|
135
|
+
</li>
|
|
136
|
+
);
|
|
137
|
+
})}
|
|
138
|
+
</ul>
|
|
139
|
+
{site.locales.some((l) => l !== current && !translations.some((t) => t.locale === l)) && (
|
|
140
|
+
<Checkbox
|
|
141
|
+
label="Ask my agent to translate the new page"
|
|
142
|
+
checked={askAgent}
|
|
143
|
+
onCheckedChange={(checked: boolean) => setAskAgent(checked)}
|
|
144
|
+
/>
|
|
145
|
+
)}
|
|
146
|
+
<p className="emvb-helper" role={error ? "alert" : undefined}>
|
|
147
|
+
{error ??
|
|
148
|
+
`Translate copies this page's layout into a draft in that language (${texts} texts to translate), then opens it.`}
|
|
149
|
+
</p>
|
|
150
|
+
</section>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
@@ -365,10 +365,10 @@ const LayerRow = React.memo(function LayerRow({
|
|
|
365
365
|
const preview = layerPreview(node);
|
|
366
366
|
const typeName = ELEMENT_NAMES[node.type] ?? node.type;
|
|
367
367
|
// A label names the row in place of the type (W-157); the type stays in the tooltip.
|
|
368
|
-
const name = node.
|
|
368
|
+
const name = node.editorLabel ?? typeName;
|
|
369
369
|
// Names and previews truncate, so the tooltip carries them in full (DESIGN.md, W-168).
|
|
370
|
-
const tooltip = node.
|
|
371
|
-
? `${node.
|
|
370
|
+
const tooltip = node.editorLabel
|
|
371
|
+
? `${node.editorLabel} (${typeName})`
|
|
372
372
|
: preview
|
|
373
373
|
? `${typeName}: ${preview}`
|
|
374
374
|
: typeName;
|
|
@@ -439,7 +439,7 @@ const LayerRow = React.memo(function LayerRow({
|
|
|
439
439
|
setRenaming(false);
|
|
440
440
|
if (text === null || !actions.onRename) return;
|
|
441
441
|
const next = clipText(text.trim(), 80).trim() || undefined;
|
|
442
|
-
if (next !== node.
|
|
442
|
+
if (next !== node.editorLabel) actions.onRename(node.id, next);
|
|
443
443
|
};
|
|
444
444
|
return (
|
|
445
445
|
<li role="treeitem" aria-expanded={hasChildren ? !collapsed : undefined}>
|
|
@@ -477,7 +477,11 @@ const LayerRow = React.memo(function LayerRow({
|
|
|
477
477
|
<span className="emvb-layer-caret" />
|
|
478
478
|
)}
|
|
479
479
|
{renaming ? (
|
|
480
|
-
<RenameInput
|
|
480
|
+
<RenameInput
|
|
481
|
+
initial={node.editorLabel ?? ""}
|
|
482
|
+
placeholder={typeName}
|
|
483
|
+
onDone={finishRename}
|
|
484
|
+
/>
|
|
481
485
|
) : (
|
|
482
486
|
<button
|
|
483
487
|
ref={selectButton}
|
|
@@ -485,7 +489,7 @@ const LayerRow = React.memo(function LayerRow({
|
|
|
485
489
|
className="emvb-layer-select"
|
|
486
490
|
aria-current={selected ? "true" : undefined}
|
|
487
491
|
title={tooltip}
|
|
488
|
-
data-emvb-layer-label={node.
|
|
492
|
+
data-emvb-layer-label={node.editorLabel ? "" : undefined}
|
|
489
493
|
onDoubleClick={startRename}
|
|
490
494
|
onKeyDown={(event) => {
|
|
491
495
|
if (event.key === "F2") {
|
|
@@ -3,12 +3,15 @@ import * as React from "react";
|
|
|
3
3
|
import type { ElementType, Layout } from "../../../core/index.ts";
|
|
4
4
|
import { AddPanel } from "./AddPanel.tsx";
|
|
5
5
|
import { LayersPanel } from "./LayersPanel.tsx";
|
|
6
|
+
import { CoDesignPanel } from "./CoDesignPanel.tsx";
|
|
7
|
+
import type { CoDesign } from "../useCoDesign.ts";
|
|
8
|
+
import { ExtensionPanels } from "../extensions/ExtensionPanels.tsx";
|
|
6
9
|
import type { ClipboardActions } from "../useClipboardActions.ts";
|
|
7
10
|
import type { SavedSectionActions } from "../useSavedSections.ts";
|
|
8
11
|
|
|
9
12
|
const SESSION_KEY = "emvb-left-tab";
|
|
10
13
|
|
|
11
|
-
/** Add | Layers left panel (W-018). Remembers the last tab for the session. */
|
|
14
|
+
/** Add | Layers | Agent left panel (W-018, W-930). Remembers the last tab for the session. */
|
|
12
15
|
export function LeftPanel({
|
|
13
16
|
layout,
|
|
14
17
|
selectedId,
|
|
@@ -24,11 +27,12 @@ export function LeftPanel({
|
|
|
24
27
|
onRename,
|
|
25
28
|
onSaveSection,
|
|
26
29
|
formsAvailable = true,
|
|
30
|
+
coDesign,
|
|
27
31
|
}: {
|
|
28
32
|
layout: Layout | null;
|
|
29
33
|
selectedId: string | null;
|
|
30
34
|
onSelect: (id: string) => void;
|
|
31
|
-
onAdd: (type: ElementType) => void;
|
|
35
|
+
onAdd: (type: ElementType | string) => void;
|
|
32
36
|
/** Adds a section recipe (W-320). */
|
|
33
37
|
onRecipe?: (id: string) => void;
|
|
34
38
|
/** My sections (W-876). */
|
|
@@ -43,10 +47,13 @@ export function LeftPanel({
|
|
|
43
47
|
/** Save as section in the row menu (W-876). */
|
|
44
48
|
onSaveSection?: (id: string) => void;
|
|
45
49
|
formsAvailable?: boolean;
|
|
50
|
+
/** W-930: agent proposals to review; the Agent tab shows only with it. */
|
|
51
|
+
coDesign?: CoDesign;
|
|
46
52
|
}) {
|
|
47
53
|
const [tab, setTab] = React.useState(() => {
|
|
48
54
|
try {
|
|
49
|
-
|
|
55
|
+
const last = sessionStorage.getItem(SESSION_KEY);
|
|
56
|
+
return last === "layers" || (last === "agent" && coDesign) ? last : "add";
|
|
50
57
|
} catch {
|
|
51
58
|
return "add";
|
|
52
59
|
}
|
|
@@ -67,12 +74,33 @@ export function LeftPanel({
|
|
|
67
74
|
tabs={[
|
|
68
75
|
{ value: "add", label: "Add" },
|
|
69
76
|
{ value: "layers", label: "Layers" },
|
|
77
|
+
...(coDesign
|
|
78
|
+
? [
|
|
79
|
+
{
|
|
80
|
+
value: "agent",
|
|
81
|
+
label:
|
|
82
|
+
coDesign.proposals.items.length > 0
|
|
83
|
+
? `Agent (${coDesign.proposals.items.length})`
|
|
84
|
+
: "Agent",
|
|
85
|
+
},
|
|
86
|
+
]
|
|
87
|
+
: []),
|
|
70
88
|
]}
|
|
71
89
|
value={tab}
|
|
72
90
|
onValueChange={changeTab}
|
|
73
91
|
/>
|
|
74
|
-
{tab === "
|
|
75
|
-
<
|
|
92
|
+
{tab === "agent" && coDesign ? (
|
|
93
|
+
<CoDesignPanel co={coDesign} layout={layout} />
|
|
94
|
+
) : tab === "add" ? (
|
|
95
|
+
<>
|
|
96
|
+
<AddPanel
|
|
97
|
+
onAdd={onAdd}
|
|
98
|
+
onRecipe={onRecipe}
|
|
99
|
+
saved={saved}
|
|
100
|
+
formsAvailable={formsAvailable}
|
|
101
|
+
/>
|
|
102
|
+
<ExtensionPanels />
|
|
103
|
+
</>
|
|
76
104
|
) : (
|
|
77
105
|
<LayersPanel
|
|
78
106
|
layout={layout}
|
|
@@ -40,6 +40,7 @@ export function PageSettings({
|
|
|
40
40
|
onChange,
|
|
41
41
|
kind = "page",
|
|
42
42
|
fetcher,
|
|
43
|
+
languages,
|
|
43
44
|
}: {
|
|
44
45
|
page: PageDraft;
|
|
45
46
|
slugError: string | null;
|
|
@@ -47,6 +48,8 @@ export function PageSettings({
|
|
|
47
48
|
kind?: "page" | "theme-part";
|
|
48
49
|
/** For the Social image picker (W-287); without it the field isn't offered. */
|
|
49
50
|
fetcher?: Fetcher;
|
|
51
|
+
/** W-936: the Languages section, when the site has more than one. */
|
|
52
|
+
languages?: React.ReactNode;
|
|
50
53
|
}) {
|
|
51
54
|
// Hooks run before the theme-part branch, so switching `kind` keeps the hook order (W-092).
|
|
52
55
|
const descriptionId = React.useId();
|
|
@@ -234,6 +237,7 @@ export function PageSettings({
|
|
|
234
237
|
/>
|
|
235
238
|
</Collapsible.Panel>
|
|
236
239
|
</Collapsible.Root>
|
|
240
|
+
{languages}
|
|
237
241
|
</div>
|
|
238
242
|
);
|
|
239
243
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type * as React from "react";
|
|
2
2
|
import type { Deletion } from "../restore-deleted.ts";
|
|
3
|
-
import type { DesignSystem, LayoutNode,
|
|
3
|
+
import type { DesignSystem, LayoutNode, EditorDevice } from "../../../core/index.ts";
|
|
4
4
|
import type { Fetcher } from "../../api.ts";
|
|
5
5
|
import type { EditorAction, EditorState } from "../store.ts";
|
|
6
6
|
import { ElementPanel } from "./ElementPanel.tsx";
|
|
7
7
|
import type { ItemActions } from "./settings/ItemList.tsx";
|
|
8
8
|
import type { StyleStateChoice } from "./settings/StateSwitcher.tsx";
|
|
9
9
|
import { PageSettings } from "./PageSettings.tsx";
|
|
10
|
+
import { LanguagesSection } from "./LanguagesSection.tsx";
|
|
11
|
+
import { PAGES_COLLECTION } from "../../../constants.ts";
|
|
10
12
|
import { SiteStylesDrawer } from "./SiteStylesDrawer.tsx";
|
|
11
13
|
|
|
12
14
|
/** The right panel: Site styles when open, else the selected element's settings, else page settings. */
|
|
@@ -26,6 +28,7 @@ export function SettingsPanel({
|
|
|
26
28
|
slugError,
|
|
27
29
|
onSlugEdit,
|
|
28
30
|
kind,
|
|
31
|
+
translatable = false,
|
|
29
32
|
onStyleState,
|
|
30
33
|
device = "desktop",
|
|
31
34
|
items,
|
|
@@ -46,10 +49,12 @@ export function SettingsPanel({
|
|
|
46
49
|
slugError: string | null;
|
|
47
50
|
onSlugEdit: () => void;
|
|
48
51
|
kind: "page" | "theme-part";
|
|
52
|
+
/** W-936: an EmVB page (not field mode) offers its other languages. */
|
|
53
|
+
translatable?: boolean;
|
|
49
54
|
/** The Style tab's chosen state, for the canvas preview (W-089). */
|
|
50
55
|
onStyleState?: (nodeId: string, state: StyleStateChoice) => void;
|
|
51
56
|
/** Which device's styles the Style tab edits (W-096). */
|
|
52
|
-
device?:
|
|
57
|
+
device?: EditorDevice;
|
|
53
58
|
/** Accordion and Tabs item actions (W-130). */
|
|
54
59
|
items?: ItemActions;
|
|
55
60
|
}) {
|
|
@@ -115,6 +120,20 @@ export function SettingsPanel({
|
|
|
115
120
|
slugError={slugError}
|
|
116
121
|
kind={kind}
|
|
117
122
|
fetcher={fetcher}
|
|
123
|
+
{...(translatable && kind === "page"
|
|
124
|
+
? {
|
|
125
|
+
languages: (
|
|
126
|
+
<LanguagesSection
|
|
127
|
+
fetcher={fetcher}
|
|
128
|
+
collection={PAGES_COLLECTION}
|
|
129
|
+
entryId={state.id}
|
|
130
|
+
title={state.page.title}
|
|
131
|
+
slug={state.page.slug}
|
|
132
|
+
layout={state.page.layout}
|
|
133
|
+
/>
|
|
134
|
+
),
|
|
135
|
+
}
|
|
136
|
+
: {})}
|
|
118
137
|
onChange={(patch) => {
|
|
119
138
|
if (patch.slug !== undefined) onSlugEdit();
|
|
120
139
|
dispatch({ type: "set-page", patch });
|
|
@@ -20,7 +20,9 @@ import {
|
|
|
20
20
|
type DefaultStyleTag,
|
|
21
21
|
type DesignSystem,
|
|
22
22
|
type Layout,
|
|
23
|
-
type
|
|
23
|
+
type FlatStyleProps,
|
|
24
|
+
flattenMotion,
|
|
25
|
+
patchNestedStyle,
|
|
24
26
|
type VariableKind,
|
|
25
27
|
} from "../../../core/index.ts";
|
|
26
28
|
import { BUTTON, SOLID_DESTRUCTIVE } from "../../ui.ts";
|
|
@@ -566,12 +568,10 @@ function DefaultsSection({
|
|
|
566
568
|
onSave: (design: DesignSystem) => Promise<boolean | void>;
|
|
567
569
|
}) {
|
|
568
570
|
const [tag, setTag] = React.useState<DefaultStyleTag>("p");
|
|
569
|
-
const
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
if (partial[key] === undefined) delete next[key];
|
|
574
|
-
}
|
|
571
|
+
const stored = design.defaults?.[tag];
|
|
572
|
+
const style = flattenMotion(stored);
|
|
573
|
+
const patch = (partial: Partial<FlatStyleProps>) => {
|
|
574
|
+
const next = patchNestedStyle(stored, partial);
|
|
575
575
|
const defaults = {
|
|
576
576
|
...design.defaults,
|
|
577
577
|
[tag]: Object.keys(next).length > 0 ? next : undefined,
|