@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
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { Input } from "@cloudflare/kumo";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { sanitizeHref } from "../../core/index.ts";
|
|
4
|
+
import type { PageSummary } from "../content-api.ts";
|
|
5
|
+
import { FIELD } from "../ui.ts";
|
|
6
|
+
|
|
7
|
+
/** Where WordPress page ids went in earlier imports, so a site imports page by page (W-958). */
|
|
8
|
+
const STORAGE_KEY = "emvb-elementor-page-links";
|
|
9
|
+
|
|
10
|
+
export type PageLinks = Readonly<Record<number, string>>;
|
|
11
|
+
|
|
12
|
+
export function readPageLinks(): PageLinks {
|
|
13
|
+
try {
|
|
14
|
+
const parsed = JSON.parse(localStorage.getItem(STORAGE_KEY) ?? "{}") as unknown;
|
|
15
|
+
if (typeof parsed !== "object" || parsed === null) return {};
|
|
16
|
+
const out: Record<number, string> = {};
|
|
17
|
+
for (const [key, value] of Object.entries(parsed)) {
|
|
18
|
+
const id = Number(key);
|
|
19
|
+
if (Number.isInteger(id) && id > 0 && typeof value === "string" && value.length <= 2000)
|
|
20
|
+
out[id] = value;
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
} catch {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function writePageLinks(links: PageLinks): void {
|
|
29
|
+
try {
|
|
30
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify({ ...readPageLinks(), ...links }));
|
|
31
|
+
} catch {
|
|
32
|
+
// Storage is off or full: the next import asks again.
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Page links (W-958): an Elementor 4 export links to WordPress pages by id only. Each gets an
|
|
38
|
+
* address on this site (one of your pages, or typed); left empty, its links are left out.
|
|
39
|
+
*/
|
|
40
|
+
export function ImportPageLinks({
|
|
41
|
+
ids,
|
|
42
|
+
links,
|
|
43
|
+
pages,
|
|
44
|
+
onChange,
|
|
45
|
+
}: {
|
|
46
|
+
ids: readonly number[];
|
|
47
|
+
links: PageLinks;
|
|
48
|
+
pages: readonly PageSummary[] | undefined;
|
|
49
|
+
onChange: (id: number, address: string) => void;
|
|
50
|
+
}) {
|
|
51
|
+
const listId = React.useId();
|
|
52
|
+
if (ids.length === 0) return null;
|
|
53
|
+
return (
|
|
54
|
+
<fieldset className="emvb-import-links" data-emvb-import-links="">
|
|
55
|
+
<legend className="emvb-import-label">Page links</legend>
|
|
56
|
+
<p className="emvb-helper">
|
|
57
|
+
This export links to WordPress pages by their number. Enter where each goes on this site,
|
|
58
|
+
such as /contact, or pick one of your pages. Leave one empty to leave its links out.
|
|
59
|
+
</p>
|
|
60
|
+
<datalist id={listId}>
|
|
61
|
+
{(pages ?? []).map((page) => (
|
|
62
|
+
<option key={page.id} value={`/${page.slug}`}>
|
|
63
|
+
{page.title}
|
|
64
|
+
</option>
|
|
65
|
+
))}
|
|
66
|
+
</datalist>
|
|
67
|
+
{ids.map((id) => {
|
|
68
|
+
const value = links[id] ?? "";
|
|
69
|
+
const invalid = value.trim() !== "" && sanitizeHref(value.trim()) === undefined;
|
|
70
|
+
return (
|
|
71
|
+
<Input
|
|
72
|
+
key={id}
|
|
73
|
+
label={`WordPress page ${id}`}
|
|
74
|
+
className={`${FIELD} emvb-mono`}
|
|
75
|
+
list={listId}
|
|
76
|
+
placeholder="/address"
|
|
77
|
+
value={value}
|
|
78
|
+
aria-invalid={invalid || undefined}
|
|
79
|
+
error={invalid ? "Enter an address such as /contact." : undefined}
|
|
80
|
+
onChange={(event) => onChange(id, event.target.value)}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
})}
|
|
84
|
+
</fieldset>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
@@ -4,7 +4,9 @@ import * as React from "react";
|
|
|
4
4
|
import type { Fetcher } from "../api.ts";
|
|
5
5
|
import { listPages } from "../content-api.ts";
|
|
6
6
|
import { editorUrl } from "../editor/exit.ts";
|
|
7
|
-
import { matchesSearch } from "../search.ts";
|
|
7
|
+
import { contentSnippet, matchesSearch } from "../search.ts";
|
|
8
|
+
import { PAGES_COLLECTION } from "../../constants.ts";
|
|
9
|
+
import { BulkBar, SelectAll, SelectRow, useSelection } from "./bulk.tsx";
|
|
8
10
|
import {
|
|
9
11
|
EditedTime,
|
|
10
12
|
ListError,
|
|
@@ -15,20 +17,57 @@ import {
|
|
|
15
17
|
StatusBadge,
|
|
16
18
|
useList,
|
|
17
19
|
} from "./list-kit.tsx";
|
|
20
|
+
import { ImportElementorDialog } from "./ImportElementorDialog.tsx";
|
|
21
|
+
import { ImportButton } from "./ImportButton.tsx";
|
|
22
|
+
import { ExportButton, ExportDialog } from "./ExportDialog.tsx";
|
|
18
23
|
import { NewPageDialog } from "./NewPageDialog.tsx";
|
|
19
24
|
|
|
25
|
+
/** W-978: why a row matches when only its content does. */
|
|
26
|
+
export function FoundIn({
|
|
27
|
+
query,
|
|
28
|
+
text,
|
|
29
|
+
fields,
|
|
30
|
+
}: {
|
|
31
|
+
query: string;
|
|
32
|
+
text: string | undefined;
|
|
33
|
+
fields: string[];
|
|
34
|
+
}) {
|
|
35
|
+
const snippet = contentSnippet(query, text, ...fields);
|
|
36
|
+
return snippet ? (
|
|
37
|
+
<div className="emvb-row-found" data-emvb-found-in="">
|
|
38
|
+
Found in content: {snippet}
|
|
39
|
+
</div>
|
|
40
|
+
) : null;
|
|
41
|
+
}
|
|
42
|
+
|
|
20
43
|
/** The Visual pages list (IA): title and slug, status, last edited; New page. */
|
|
21
44
|
export function PageList({ fetcher }: { fetcher: Fetcher }) {
|
|
22
45
|
const list = useList(fetcher, listPages);
|
|
23
46
|
const [creating, setCreating] = React.useState(false);
|
|
47
|
+
const [importing, setImporting] = React.useState(false);
|
|
48
|
+
const [exporting, setExporting] = React.useState(false);
|
|
24
49
|
const [query, setQuery] = React.useState("");
|
|
25
50
|
const searchRef = React.useRef<HTMLInputElement>(null);
|
|
26
51
|
const shown =
|
|
27
52
|
list.state === "ready"
|
|
28
|
-
? list.items.filter((page) =>
|
|
53
|
+
? list.items.filter((page) =>
|
|
54
|
+
// W-978: titles, addresses and the words on the page.
|
|
55
|
+
matchesSearch(query, page.title, `/${page.slug}`, page.text ?? ""),
|
|
56
|
+
)
|
|
29
57
|
: [];
|
|
58
|
+
const selection = useSelection(list.state === "ready" ? list.items.map((p) => p.id) : []);
|
|
59
|
+
const [exportIds, setExportIds] = React.useState<string[]>([]);
|
|
60
|
+
const titles = new Map(list.state === "ready" ? list.items.map((p) => [p.id, p.title]) : []);
|
|
30
61
|
|
|
31
|
-
const newPage =
|
|
62
|
+
const newPage = (
|
|
63
|
+
<div className="emvb-list-actions">
|
|
64
|
+
{list.state === "ready" && list.items.length > 0 && (
|
|
65
|
+
<ExportButton onClick={() => setExporting(true)} />
|
|
66
|
+
)}
|
|
67
|
+
<ImportButton onClick={() => setImporting(true)} />
|
|
68
|
+
<NewButton label="New page" onClick={() => setCreating(true)} />
|
|
69
|
+
</div>
|
|
70
|
+
);
|
|
32
71
|
|
|
33
72
|
return (
|
|
34
73
|
<>
|
|
@@ -53,6 +92,19 @@ export function PageList({ fetcher }: { fetcher: Fetcher }) {
|
|
|
53
92
|
{list.state === "ready" && list.items.length > 0 && (
|
|
54
93
|
<ListSearch value={query} onChange={setQuery} label="Search pages" inputRef={searchRef} />
|
|
55
94
|
)}
|
|
95
|
+
<BulkBar
|
|
96
|
+
fetcher={fetcher}
|
|
97
|
+
collection={PAGES_COLLECTION}
|
|
98
|
+
selection={selection}
|
|
99
|
+
titles={titles}
|
|
100
|
+
noun="page"
|
|
101
|
+
nouns="pages"
|
|
102
|
+
onChanged={list.retry}
|
|
103
|
+
onExport={(ids) => {
|
|
104
|
+
setExportIds(ids);
|
|
105
|
+
setExporting(true);
|
|
106
|
+
}}
|
|
107
|
+
/>
|
|
56
108
|
{list.state === "ready" && list.items.length > 0 && shown.length === 0 && (
|
|
57
109
|
<NoMatches
|
|
58
110
|
query={query}
|
|
@@ -67,6 +119,9 @@ export function PageList({ fetcher }: { fetcher: Fetcher }) {
|
|
|
67
119
|
<Table data-emvb-list="pages">
|
|
68
120
|
<Table.Header>
|
|
69
121
|
<Table.Row>
|
|
122
|
+
<Table.Head className="emvb-row-select">
|
|
123
|
+
<SelectAll shown={shown.map((p) => p.id)} selection={selection} noun="pages" />
|
|
124
|
+
</Table.Head>
|
|
70
125
|
<Table.Head>Title</Table.Head>
|
|
71
126
|
<Table.Head>Status</Table.Head>
|
|
72
127
|
<Table.Head>Last edited</Table.Head>
|
|
@@ -75,11 +130,19 @@ export function PageList({ fetcher }: { fetcher: Fetcher }) {
|
|
|
75
130
|
<Table.Body>
|
|
76
131
|
{shown.map((page) => (
|
|
77
132
|
<Table.Row key={page.id} data-emvb-row={page.id}>
|
|
133
|
+
<Table.Cell className="emvb-row-select">
|
|
134
|
+
<SelectRow id={page.id} title={page.title} selection={selection} />
|
|
135
|
+
</Table.Cell>
|
|
78
136
|
<Table.Cell>
|
|
79
137
|
<a className="emvb-row-title" href={editorUrl(page.id)}>
|
|
80
138
|
{page.title}
|
|
81
139
|
</a>
|
|
82
140
|
<div className="emvb-row-slug">/{page.slug}</div>
|
|
141
|
+
<FoundIn
|
|
142
|
+
query={query}
|
|
143
|
+
text={page.text}
|
|
144
|
+
fields={[page.title, `/${page.slug}`]}
|
|
145
|
+
/>
|
|
83
146
|
</Table.Cell>
|
|
84
147
|
<Table.Cell>
|
|
85
148
|
<StatusBadge status={page.status} />
|
|
@@ -94,6 +157,22 @@ export function PageList({ fetcher }: { fetcher: Fetcher }) {
|
|
|
94
157
|
</div>
|
|
95
158
|
)}
|
|
96
159
|
<NewPageDialog fetcher={fetcher} open={creating} onOpenChange={setCreating} />
|
|
160
|
+
<ExportDialog
|
|
161
|
+
fetcher={fetcher}
|
|
162
|
+
open={exporting}
|
|
163
|
+
onOpenChange={(open) => {
|
|
164
|
+
setExporting(open);
|
|
165
|
+
if (!open) setExportIds([]);
|
|
166
|
+
}}
|
|
167
|
+
pages={list.state === "ready" ? list.items : []}
|
|
168
|
+
selectedIds={exportIds}
|
|
169
|
+
/>
|
|
170
|
+
<ImportElementorDialog
|
|
171
|
+
fetcher={fetcher}
|
|
172
|
+
open={importing}
|
|
173
|
+
onOpenChange={setImporting}
|
|
174
|
+
target="page"
|
|
175
|
+
/>
|
|
97
176
|
</>
|
|
98
177
|
);
|
|
99
178
|
}
|
|
@@ -7,6 +7,9 @@ import type { Fetcher } from "../api.ts";
|
|
|
7
7
|
import { listThemeParts, partTypeLabel } from "../theme-api.ts";
|
|
8
8
|
import { editorUrl } from "../editor/exit.ts";
|
|
9
9
|
import { matchesSearch } from "../search.ts";
|
|
10
|
+
import { BulkBar, SelectAll, SelectRow, useSelection } from "./bulk.tsx";
|
|
11
|
+
import { partsInUse } from "../bulk-api.ts";
|
|
12
|
+
import { FoundIn } from "./PageList.tsx";
|
|
10
13
|
import {
|
|
11
14
|
EditedTime,
|
|
12
15
|
ListError,
|
|
@@ -17,6 +20,8 @@ import {
|
|
|
17
20
|
StatusBadge,
|
|
18
21
|
useList,
|
|
19
22
|
} from "./list-kit.tsx";
|
|
23
|
+
import { ImportButton } from "./ImportButton.tsx";
|
|
24
|
+
import { ImportElementorDialog } from "./ImportElementorDialog.tsx";
|
|
20
25
|
import { NewThemePartDialog } from "./NewThemePartDialog.tsx";
|
|
21
26
|
|
|
22
27
|
type Filter = "all" | ThemePartType;
|
|
@@ -122,11 +127,17 @@ function FilterTabs({
|
|
|
122
127
|
export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
|
|
123
128
|
const list = useList(fetcher, listThemeParts);
|
|
124
129
|
const [creating, setCreating] = React.useState(false);
|
|
130
|
+
const [importing, setImporting] = React.useState(false);
|
|
125
131
|
const [filter, setFilter] = React.useState<Filter>("all");
|
|
126
132
|
const [query, setQuery] = React.useState("");
|
|
127
133
|
const searchRef = React.useRef<HTMLInputElement>(null);
|
|
128
134
|
|
|
129
|
-
const newPart =
|
|
135
|
+
const newPart = (
|
|
136
|
+
<div className="emvb-list-actions">
|
|
137
|
+
<ImportButton onClick={() => setImporting(true)} />
|
|
138
|
+
<NewButton label="New theme part" onClick={() => setCreating(true)} />
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
130
141
|
|
|
131
142
|
const visible =
|
|
132
143
|
list.state === "ready"
|
|
@@ -135,8 +146,11 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
|
|
|
135
146
|
: list.items.filter((p) => p.partType === filter)
|
|
136
147
|
: [];
|
|
137
148
|
const shown = visible.filter((p) =>
|
|
138
|
-
|
|
149
|
+
// W-978: and the words in the part.
|
|
150
|
+
matchesSearch(query, p.title, partTypeLabel(p.partType), p.conditionsSummary, p.text ?? ""),
|
|
139
151
|
);
|
|
152
|
+
const selection = useSelection(list.state === "ready" ? list.items.map((p) => p.id) : []);
|
|
153
|
+
const titles = new Map(list.state === "ready" ? list.items.map((p) => [p.id, p.title]) : []);
|
|
140
154
|
|
|
141
155
|
const emptyFilterLabel =
|
|
142
156
|
filter === "all" ? "theme parts" : FILTERS.find((f) => f.value === filter)?.label.toLowerCase();
|
|
@@ -158,6 +172,17 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
|
|
|
158
172
|
/>
|
|
159
173
|
</>
|
|
160
174
|
)}
|
|
175
|
+
<BulkBar
|
|
176
|
+
fetcher={fetcher}
|
|
177
|
+
collection={THEME_PARTS_COLLECTION}
|
|
178
|
+
selection={selection}
|
|
179
|
+
titles={titles}
|
|
180
|
+
noun="theme part"
|
|
181
|
+
nouns="theme parts"
|
|
182
|
+
onChanged={list.retry}
|
|
183
|
+
deleteNote="Pages that use a deleted synced section or loop item show nothing in its place until you restore it."
|
|
184
|
+
usage={(ids) => partsInUse(fetcher, ids)}
|
|
185
|
+
/>
|
|
161
186
|
{list.state === "loading" && <ListLoading label="Loading theme parts…" />}
|
|
162
187
|
{list.state === "error" && (
|
|
163
188
|
<ListError title="Couldn't load theme parts" message={list.message} onRetry={list.retry} />
|
|
@@ -196,6 +221,13 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
|
|
|
196
221
|
<Table data-emvb-list="theme-parts">
|
|
197
222
|
<Table.Header>
|
|
198
223
|
<Table.Row>
|
|
224
|
+
<Table.Head className="emvb-row-select">
|
|
225
|
+
<SelectAll
|
|
226
|
+
shown={shown.map((p) => p.id)}
|
|
227
|
+
selection={selection}
|
|
228
|
+
noun="theme parts"
|
|
229
|
+
/>
|
|
230
|
+
</Table.Head>
|
|
199
231
|
<Table.Head>Title</Table.Head>
|
|
200
232
|
<Table.Head>Type</Table.Head>
|
|
201
233
|
<Table.Head>Conditions</Table.Head>
|
|
@@ -206,6 +238,9 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
|
|
|
206
238
|
<Table.Body>
|
|
207
239
|
{shown.map((part) => (
|
|
208
240
|
<Table.Row key={part.id} data-emvb-row={part.id}>
|
|
241
|
+
<Table.Cell className="emvb-row-select">
|
|
242
|
+
<SelectRow id={part.id} title={part.title} selection={selection} />
|
|
243
|
+
</Table.Cell>
|
|
209
244
|
<Table.Cell>
|
|
210
245
|
<a
|
|
211
246
|
className="emvb-row-title"
|
|
@@ -213,6 +248,15 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
|
|
|
213
248
|
>
|
|
214
249
|
{part.title}
|
|
215
250
|
</a>
|
|
251
|
+
<FoundIn
|
|
252
|
+
query={query}
|
|
253
|
+
text={part.text}
|
|
254
|
+
fields={[
|
|
255
|
+
part.title,
|
|
256
|
+
partTypeLabel(part.partType),
|
|
257
|
+
part.conditionsSummary,
|
|
258
|
+
]}
|
|
259
|
+
/>
|
|
216
260
|
</Table.Cell>
|
|
217
261
|
<Table.Cell>{partTypeLabel(part.partType)}</Table.Cell>
|
|
218
262
|
<Table.Cell>
|
|
@@ -232,6 +276,12 @@ export function ThemePartList({ fetcher }: { fetcher: Fetcher }) {
|
|
|
232
276
|
)}
|
|
233
277
|
</div>
|
|
234
278
|
)}
|
|
279
|
+
<ImportElementorDialog
|
|
280
|
+
fetcher={fetcher}
|
|
281
|
+
open={importing}
|
|
282
|
+
onOpenChange={setImporting}
|
|
283
|
+
target="part"
|
|
284
|
+
/>
|
|
235
285
|
<NewThemePartDialog
|
|
236
286
|
fetcher={fetcher}
|
|
237
287
|
open={creating}
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { Button, Checkbox, Dialog, Loader } from "@cloudflare/kumo";
|
|
2
|
+
import {
|
|
3
|
+
ArrowCounterClockwiseIcon,
|
|
4
|
+
DownloadSimpleIcon,
|
|
5
|
+
TrashIcon,
|
|
6
|
+
UploadSimpleIcon,
|
|
7
|
+
} from "@phosphor-icons/react";
|
|
8
|
+
import * as React from "react";
|
|
9
|
+
import type { Fetcher } from "../api.ts";
|
|
10
|
+
import { publishMany, restoreMany, trashMany, type BulkResult } from "../bulk-api.ts";
|
|
11
|
+
import { DialogCloseButton } from "../editor/DialogCloseButton.tsx";
|
|
12
|
+
import { BUTTON, SOLID_DESTRUCTIVE, UI_CSS } from "../ui.ts";
|
|
13
|
+
|
|
14
|
+
const plural = (n: number, one: string, many: string) => `${n} ${n === 1 ? one : many}`;
|
|
15
|
+
|
|
16
|
+
/** W-978: which rows are ticked, kept to the rows that still exist. */
|
|
17
|
+
export function useSelection(ids: readonly string[]) {
|
|
18
|
+
const [selected, setSelected] = React.useState<ReadonlySet<string>>(new Set());
|
|
19
|
+
const key = ids.join(" ");
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
setSelected((current) => {
|
|
22
|
+
const kept = new Set([...current].filter((id) => ids.includes(id)));
|
|
23
|
+
return kept.size === current.size ? current : kept;
|
|
24
|
+
});
|
|
25
|
+
// `key` stands for `ids`, which is a new array on every render.
|
|
26
|
+
// oxlint-disable-next-line react-hooks/exhaustive-deps
|
|
27
|
+
}, [key]);
|
|
28
|
+
const toggle = (id: string, on: boolean) =>
|
|
29
|
+
setSelected((current) => {
|
|
30
|
+
const next = new Set(current);
|
|
31
|
+
if (on) next.add(id);
|
|
32
|
+
else next.delete(id);
|
|
33
|
+
return next;
|
|
34
|
+
});
|
|
35
|
+
const setAll = (shown: readonly string[], on: boolean) =>
|
|
36
|
+
setSelected((current) => {
|
|
37
|
+
const next = new Set(current);
|
|
38
|
+
for (const id of shown)
|
|
39
|
+
if (on) next.add(id);
|
|
40
|
+
else next.delete(id);
|
|
41
|
+
return next;
|
|
42
|
+
});
|
|
43
|
+
return { selected, toggle, setAll, clear: () => setSelected(new Set()) };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The header cell that ticks every row shown. */
|
|
47
|
+
export function SelectAll({
|
|
48
|
+
shown,
|
|
49
|
+
selection,
|
|
50
|
+
noun,
|
|
51
|
+
}: {
|
|
52
|
+
shown: readonly string[];
|
|
53
|
+
selection: ReturnType<typeof useSelection>;
|
|
54
|
+
noun: string;
|
|
55
|
+
}) {
|
|
56
|
+
const ticked = shown.filter((id) => selection.selected.has(id)).length;
|
|
57
|
+
return (
|
|
58
|
+
<Checkbox
|
|
59
|
+
aria-label={`Select all ${noun} shown`}
|
|
60
|
+
checked={shown.length > 0 && ticked === shown.length}
|
|
61
|
+
indeterminate={ticked > 0 && ticked < shown.length}
|
|
62
|
+
onCheckedChange={(on: boolean) => selection.setAll(shown, on)}
|
|
63
|
+
data-emvb-select-all=""
|
|
64
|
+
/>
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** A row's tick box, named after the row. */
|
|
69
|
+
export function SelectRow({
|
|
70
|
+
id,
|
|
71
|
+
title,
|
|
72
|
+
selection,
|
|
73
|
+
}: {
|
|
74
|
+
id: string;
|
|
75
|
+
title: string;
|
|
76
|
+
selection: ReturnType<typeof useSelection>;
|
|
77
|
+
}) {
|
|
78
|
+
return (
|
|
79
|
+
<Checkbox
|
|
80
|
+
aria-label={`Select ${title}`}
|
|
81
|
+
checked={selection.selected.has(id)}
|
|
82
|
+
onCheckedChange={(on: boolean) => selection.toggle(id, on)}
|
|
83
|
+
data-emvb-select-row={id}
|
|
84
|
+
/>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
type BulkState =
|
|
89
|
+
| { kind: "idle" }
|
|
90
|
+
| { kind: "busy"; what: "publish" | "delete" | "restore" }
|
|
91
|
+
| { kind: "done"; text: string; restorable?: string[]; error?: boolean };
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* W-978: Publish, Delete (to EmDash's trash, with Restore) and, on Pages, Export for the ticked
|
|
95
|
+
* rows. Each item is its own request; one that fails is named and the rest go on.
|
|
96
|
+
*/
|
|
97
|
+
export function BulkBar({
|
|
98
|
+
fetcher,
|
|
99
|
+
collection,
|
|
100
|
+
selection,
|
|
101
|
+
titles,
|
|
102
|
+
noun,
|
|
103
|
+
nouns,
|
|
104
|
+
onChanged,
|
|
105
|
+
onExport,
|
|
106
|
+
deleteNote,
|
|
107
|
+
usage,
|
|
108
|
+
}: {
|
|
109
|
+
fetcher: Fetcher;
|
|
110
|
+
collection: string;
|
|
111
|
+
selection: ReturnType<typeof useSelection>;
|
|
112
|
+
/** Titles by id, for the confirm and the result. */
|
|
113
|
+
titles: ReadonlyMap<string, string>;
|
|
114
|
+
noun: string;
|
|
115
|
+
nouns: string;
|
|
116
|
+
/** Reloads the list after a change. */
|
|
117
|
+
onChanged: () => void;
|
|
118
|
+
onExport?: (ids: string[]) => void;
|
|
119
|
+
/** What else the delete confirm should say. */
|
|
120
|
+
deleteNote?: string;
|
|
121
|
+
/** W-980: where the chosen items are still used, by id, for the delete confirm. */
|
|
122
|
+
usage?: (ids: string[]) => Promise<Map<string, string[]>>;
|
|
123
|
+
}) {
|
|
124
|
+
const [inUse, setInUse] = React.useState<Map<string, string[]> | null>(null);
|
|
125
|
+
const [state, setState] = React.useState<BulkState>({ kind: "idle" });
|
|
126
|
+
const [confirming, setConfirming] = React.useState(false);
|
|
127
|
+
const ids = [...selection.selected];
|
|
128
|
+
const busy = state.kind === "busy";
|
|
129
|
+
const failures = (result: BulkResult) =>
|
|
130
|
+
result.failed.map((f) => `${titles.get(f.id) ?? f.id} (${f.message})`).join("; ");
|
|
131
|
+
|
|
132
|
+
const run = async (what: "publish" | "delete") => {
|
|
133
|
+
setConfirming(false);
|
|
134
|
+
setState({ kind: "busy", what });
|
|
135
|
+
const result = await (what === "publish" ? publishMany : trashMany)(fetcher, collection, ids);
|
|
136
|
+
const verb = what === "publish" ? "Published" : "Moved to the trash:";
|
|
137
|
+
const parts = [
|
|
138
|
+
result.done.length > 0 ? `${verb} ${plural(result.done.length, noun, nouns)}.` : "",
|
|
139
|
+
result.failed.length > 0
|
|
140
|
+
? `Not ${what === "publish" ? "published" : "deleted"}: ${failures(result)}.`
|
|
141
|
+
: "",
|
|
142
|
+
].filter(Boolean);
|
|
143
|
+
setState({
|
|
144
|
+
kind: "done",
|
|
145
|
+
text: parts.join(" "),
|
|
146
|
+
...(what === "delete" && result.done.length > 0 ? { restorable: result.done } : {}),
|
|
147
|
+
...(result.failed.length > 0 ? { error: true } : {}),
|
|
148
|
+
});
|
|
149
|
+
selection.clear();
|
|
150
|
+
if (result.done.length > 0) onChanged();
|
|
151
|
+
};
|
|
152
|
+
const restore = async (restorable: string[]) => {
|
|
153
|
+
setState({ kind: "busy", what: "restore" });
|
|
154
|
+
const result = await restoreMany(fetcher, collection, restorable);
|
|
155
|
+
setState({
|
|
156
|
+
kind: "done",
|
|
157
|
+
text: [
|
|
158
|
+
result.done.length > 0 ? `Restored ${plural(result.done.length, noun, nouns)}.` : "",
|
|
159
|
+
result.failed.length > 0 ? `Not restored: ${failures(result)}.` : "",
|
|
160
|
+
]
|
|
161
|
+
.filter(Boolean)
|
|
162
|
+
.join(" "),
|
|
163
|
+
...(result.failed.length > 0 ? { error: true } : {}),
|
|
164
|
+
});
|
|
165
|
+
if (result.done.length > 0) onChanged();
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
if (ids.length === 0 && state.kind === "idle") return null;
|
|
169
|
+
return (
|
|
170
|
+
<div
|
|
171
|
+
className="emvb-bulk-bar"
|
|
172
|
+
role="region"
|
|
173
|
+
aria-label={`Selected ${nouns}`}
|
|
174
|
+
data-emvb-bulk-bar=""
|
|
175
|
+
>
|
|
176
|
+
{ids.length > 0 && (
|
|
177
|
+
<>
|
|
178
|
+
<span className="emvb-bulk-count" aria-live="polite">
|
|
179
|
+
{plural(ids.length, noun, nouns)} selected
|
|
180
|
+
</span>
|
|
181
|
+
<Button
|
|
182
|
+
variant="secondary"
|
|
183
|
+
className={BUTTON}
|
|
184
|
+
icon={
|
|
185
|
+
state.kind === "busy" && state.what === "publish" ? (
|
|
186
|
+
<Loader size={14} />
|
|
187
|
+
) : (
|
|
188
|
+
<UploadSimpleIcon aria-hidden="true" />
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
aria-disabled={busy}
|
|
192
|
+
onClick={() => !busy && void run("publish")}
|
|
193
|
+
data-emvb-bulk="publish"
|
|
194
|
+
>
|
|
195
|
+
Publish
|
|
196
|
+
</Button>
|
|
197
|
+
{onExport && (
|
|
198
|
+
<Button
|
|
199
|
+
variant="secondary"
|
|
200
|
+
className={BUTTON}
|
|
201
|
+
icon={<DownloadSimpleIcon aria-hidden="true" />}
|
|
202
|
+
aria-disabled={busy}
|
|
203
|
+
onClick={() => !busy && onExport(ids)}
|
|
204
|
+
data-emvb-bulk="export"
|
|
205
|
+
>
|
|
206
|
+
Export
|
|
207
|
+
</Button>
|
|
208
|
+
)}
|
|
209
|
+
<Button
|
|
210
|
+
variant="secondary"
|
|
211
|
+
className={BUTTON}
|
|
212
|
+
icon={
|
|
213
|
+
state.kind === "busy" && state.what === "delete" ? (
|
|
214
|
+
<Loader size={14} />
|
|
215
|
+
) : (
|
|
216
|
+
<TrashIcon aria-hidden="true" />
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
aria-disabled={busy}
|
|
220
|
+
onClick={() => {
|
|
221
|
+
if (busy) return;
|
|
222
|
+
setInUse(null);
|
|
223
|
+
setConfirming(true);
|
|
224
|
+
usage?.(ids).then(setInUse, () => setInUse(new Map()));
|
|
225
|
+
}}
|
|
226
|
+
data-emvb-bulk="delete"
|
|
227
|
+
>
|
|
228
|
+
Delete
|
|
229
|
+
</Button>
|
|
230
|
+
<Button variant="ghost" className={BUTTON} onClick={selection.clear} aria-disabled={busy}>
|
|
231
|
+
Clear selection
|
|
232
|
+
</Button>
|
|
233
|
+
</>
|
|
234
|
+
)}
|
|
235
|
+
{state.kind !== "idle" && (
|
|
236
|
+
<p
|
|
237
|
+
className={
|
|
238
|
+
state.kind === "done" && state.error ? "emvb-helper emvb-danger-text" : "emvb-helper"
|
|
239
|
+
}
|
|
240
|
+
role="status"
|
|
241
|
+
data-emvb-bulk-status=""
|
|
242
|
+
>
|
|
243
|
+
{state.kind === "busy"
|
|
244
|
+
? state.what === "publish"
|
|
245
|
+
? "Publishing…"
|
|
246
|
+
: state.what === "delete"
|
|
247
|
+
? "Moving to the trash…"
|
|
248
|
+
: "Restoring…"
|
|
249
|
+
: state.text}
|
|
250
|
+
{state.kind === "done" && state.restorable && (
|
|
251
|
+
<Button
|
|
252
|
+
variant="ghost"
|
|
253
|
+
className={BUTTON}
|
|
254
|
+
icon={<ArrowCounterClockwiseIcon aria-hidden="true" />}
|
|
255
|
+
onClick={() => state.restorable && void restore(state.restorable)}
|
|
256
|
+
data-emvb-bulk="restore"
|
|
257
|
+
>
|
|
258
|
+
Restore
|
|
259
|
+
</Button>
|
|
260
|
+
)}
|
|
261
|
+
</p>
|
|
262
|
+
)}
|
|
263
|
+
<Dialog.Root open={confirming} onOpenChange={setConfirming}>
|
|
264
|
+
<Dialog size="base" className="p-6">
|
|
265
|
+
<style>{UI_CSS}</style>
|
|
266
|
+
<div className="emvb-dialog" data-emvb-dialog="bulk-delete">
|
|
267
|
+
<Dialog.Title>Delete {plural(ids.length, noun, nouns)}?</Dialog.Title>
|
|
268
|
+
<Dialog.Description>
|
|
269
|
+
{ids.length <= 5
|
|
270
|
+
? `${ids.map((id) => titles.get(id) ?? id).join(", ")} ${ids.length === 1 ? "goes" : "go"} to EmDash's trash and ${ids.length === 1 ? "leaves" : "leave"} the site.`
|
|
271
|
+
: `They go to EmDash's trash and leave the site.`}{" "}
|
|
272
|
+
You can restore them right after, or later from the trash.
|
|
273
|
+
</Dialog.Description>
|
|
274
|
+
{inUse && inUse.size > 0 && (
|
|
275
|
+
<ul className="emvb-helper emvb-danger-text" data-emvb-bulk-in-use="">
|
|
276
|
+
{[...inUse].map(([id, where]) => (
|
|
277
|
+
<li key={id}>
|
|
278
|
+
{titles.get(id) ?? id} is used on {where.slice(0, 3).join(", ")}
|
|
279
|
+
{where.length > 3 ? ` and ${where.length - 3} more` : ""}; it will show nothing
|
|
280
|
+
there.
|
|
281
|
+
</li>
|
|
282
|
+
))}
|
|
283
|
+
</ul>
|
|
284
|
+
)}
|
|
285
|
+
{deleteNote && <p className="emvb-helper">{deleteNote}</p>}
|
|
286
|
+
<div className="emvb-dialog-actions">
|
|
287
|
+
<DialogCloseButton>Cancel</DialogCloseButton>
|
|
288
|
+
<Button
|
|
289
|
+
variant="destructive"
|
|
290
|
+
className={BUTTON}
|
|
291
|
+
style={SOLID_DESTRUCTIVE}
|
|
292
|
+
onClick={() => void run("delete")}
|
|
293
|
+
data-emvb-bulk-confirm=""
|
|
294
|
+
>
|
|
295
|
+
Delete {plural(ids.length, noun, nouns)}
|
|
296
|
+
</Button>
|
|
297
|
+
</div>
|
|
298
|
+
</div>
|
|
299
|
+
</Dialog>
|
|
300
|
+
</Dialog.Root>
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Icon } from "@phosphor-icons/react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
/** A card's heading row: an icon tile, the title and one line on what the card is for (W-477). */
|
|
5
|
+
export function SectionHead({
|
|
6
|
+
id,
|
|
7
|
+
icon: SectionIcon,
|
|
8
|
+
title,
|
|
9
|
+
children,
|
|
10
|
+
}: {
|
|
11
|
+
id: string;
|
|
12
|
+
icon: Icon;
|
|
13
|
+
title: string;
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}) {
|
|
16
|
+
return (
|
|
17
|
+
<div className="emvb-agents-head">
|
|
18
|
+
<span className="emvb-agents-icon" aria-hidden="true">
|
|
19
|
+
<SectionIcon size={18} />
|
|
20
|
+
</span>
|
|
21
|
+
<div>
|
|
22
|
+
<h2 id={id}>{title}</h2>
|
|
23
|
+
<p>{children}</p>
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
}
|