eddev 2.0.0-beta.12 → 2.0.0-beta.121
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/css/editor-styles.css +4 -0
- package/dist/app/entry/HydrationOverlay.d.ts +1 -0
- package/dist/app/entry/HydrationOverlay.js +2 -0
- package/dist/app/entry/MetaTags.d.ts +7 -0
- package/dist/app/entry/MetaTags.js +17 -0
- package/dist/app/entry/boot-admin.js +9 -3
- package/dist/app/entry/hydration-script.d.ts +1 -0
- package/dist/app/entry/hydration-script.js +18 -0
- package/dist/app/entry/spa-root.js +3 -5
- package/dist/app/entry/ssr-root-client.d.ts +3 -1
- package/dist/app/entry/ssr-root-client.js +18 -6
- package/dist/app/entry/ssr-root.d.ts +3 -4
- package/dist/app/entry/ssr-root.js +19 -19
- package/dist/app/lib/admin/index.d.ts +2 -2
- package/dist/app/lib/admin/index.js +2 -2
- package/dist/app/lib/admin/installFieldTypes.js +3 -1
- package/dist/app/lib/admin/runWidgets.js +1 -1
- package/dist/app/lib/blocks/ContentBlocks.d.ts +1 -1
- package/dist/app/lib/blocks/ContentBlocks.js +5 -5
- package/dist/app/lib/blocks/EditableText.d.ts +15 -2
- package/dist/app/lib/blocks/EditableText.js +10 -4
- package/dist/app/lib/blocks/InnerBlocks.d.ts +21 -7
- package/dist/app/lib/blocks/InnerBlocks.js +75 -28
- package/dist/app/lib/blocks/block-utils.d.ts +2 -2
- package/dist/app/lib/blocks/block-utils.js +2 -2
- package/dist/app/lib/blocks/defineBlock.d.ts +3 -0
- package/dist/app/lib/blocks/defineBlock.js +7 -0
- package/dist/app/lib/blocks/editor/EditorHighlights.d.ts +7 -0
- package/dist/app/lib/blocks/editor/EditorHighlights.js +164 -0
- package/dist/app/lib/blocks/editor/EditorSupport.js +17 -12
- package/dist/app/lib/blocks/editor/ErrorBoundaryEditor.d.ts +1 -1
- package/dist/app/lib/blocks/editor/block-templates.d.ts +6 -0
- package/dist/app/lib/blocks/editor/block-templates.js +64 -0
- package/dist/app/lib/blocks/editor/create-block.d.ts +9 -0
- package/dist/app/lib/blocks/editor/create-block.js +13 -0
- package/dist/app/lib/blocks/editor/editor-config.d.ts +70 -7
- package/dist/app/lib/blocks/editor/editor-config.js +29 -62
- package/dist/app/lib/blocks/editor/installGutenbergHooks.d.ts +3 -0
- package/dist/app/lib/blocks/editor/installGutenbergHooks.js +105 -16
- package/dist/app/lib/blocks/editor/root-blocks.d.ts +6 -0
- package/dist/app/lib/blocks/editor/root-blocks.js +30 -0
- package/dist/app/lib/blocks/editor/usePostEditor.d.ts +1 -1
- package/dist/app/lib/blocks/index.d.ts +10 -9
- package/dist/app/lib/blocks/index.js +10 -9
- package/dist/app/lib/blocks/inline-editing.d.ts +9 -1
- package/dist/app/lib/blocks/inline-editing.js +7 -5
- package/dist/app/lib/devtools/components/BreakpointIndicator.js +1 -1
- package/dist/app/lib/devtools/components/DevUI.js +4 -3
- package/dist/app/lib/devtools/components/GridIndicator.d.ts +1 -0
- package/dist/app/lib/devtools/components/GridIndicator.js +29 -0
- package/dist/app/lib/devtools/hooks/usePersistState.d.ts +1 -1
- package/dist/app/lib/devtools/hooks/usePersistState.js +11 -2
- package/dist/app/lib/devtools/hooks/useTailwind.d.ts +2305 -1261
- package/dist/app/lib/devtools/hooks/useTailwind.js +1 -1
- package/dist/app/lib/devtools/index.d.ts +1 -1
- package/dist/app/lib/devtools/index.js +1 -1
- package/dist/app/lib/devtools/loader.js +8 -7
- package/dist/app/lib/devtools/useQueryDebug.d.ts +7 -1
- package/dist/app/lib/devtools/useQueryDebug.js +5 -8
- package/dist/app/lib/dynamic/dynamic.d.ts +1 -1
- package/dist/app/lib/dynamic/dynamic.js +5 -1
- package/dist/app/lib/dynamic/index.d.ts +1 -1
- package/dist/app/lib/dynamic/index.js +1 -1
- package/dist/app/lib/hooks/index.d.ts +4 -5
- package/dist/app/lib/hooks/index.js +4 -5
- package/dist/app/lib/hooks/queryUtils.d.ts +37 -3
- package/dist/app/lib/hooks/queryUtils.js +66 -26
- package/dist/app/lib/hooks/useAppData.js +12 -1
- package/dist/app/lib/hooks/useRPC.d.ts +0 -4
- package/dist/app/lib/hooks/useRPC.js +1 -8
- package/dist/app/lib/internal/finalize-rpc.d.ts +17 -0
- package/dist/app/lib/internal/finalize-rpc.js +3 -0
- package/dist/app/lib/internal/index.d.ts +5 -4
- package/dist/app/lib/internal/index.js +5 -4
- package/dist/app/lib/internal/read-admin-manifest.d.ts +1 -1
- package/dist/app/lib/legacy-stitches/createStitches.d.ts +21 -21
- package/dist/app/lib/legacy-stitches/createStitches.js +1 -1
- package/dist/app/lib/legacy-stitches/index.d.ts +1 -1
- package/dist/app/lib/legacy-stitches/index.js +1 -1
- package/dist/app/lib/routing/components/BackButton.d.ts +49 -0
- package/dist/app/lib/routing/components/BackButton.js +47 -0
- package/dist/app/lib/routing/components/BrowserRouter.d.ts +5 -1
- package/dist/app/lib/routing/components/BrowserRouter.js +98 -19
- package/dist/app/lib/routing/components/ClientOnly.d.ts +1 -1
- package/dist/app/lib/routing/components/ClientOnly.js +2 -2
- package/dist/app/lib/routing/components/Link.d.ts +1 -0
- package/dist/app/lib/routing/components/Link.js +11 -12
- package/dist/app/lib/routing/components/RouteRenderer.d.ts +1 -1
- package/dist/app/lib/routing/components/RouteRenderer.js +7 -6
- package/dist/app/lib/routing/components/SSRRouter.d.ts +2 -2
- package/dist/app/lib/routing/components/SSRRouter.js +5 -6
- package/dist/app/lib/routing/components/ScrollRestoration.js +5 -2
- package/dist/app/lib/routing/context.d.ts +8 -5
- package/dist/app/lib/routing/context.js +13 -96
- package/dist/app/lib/routing/hooks/useRestorableState.d.ts +2 -1
- package/dist/app/lib/routing/hooks/useRestorableState.js +2 -1
- package/dist/app/lib/routing/hooks/useRoute.d.ts +16 -1
- package/dist/app/lib/routing/hooks/useRoute.js +22 -1
- package/dist/app/lib/routing/hooks/useRouteMeta.d.ts +5 -0
- package/dist/app/lib/routing/hooks/useRouteMeta.js +9 -0
- package/dist/app/lib/routing/hooks/useRouteTransition.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouteTransition.js +1 -1
- package/dist/app/lib/routing/hooks/useRouter.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouter.js +1 -1
- package/dist/app/lib/routing/hooks/useRouterEvents.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouterEvents.js +1 -1
- package/dist/app/lib/routing/hooks/useRouterState.d.ts +1 -1
- package/dist/app/lib/routing/hooks/useRouterState.js +1 -1
- package/dist/app/lib/routing/hooks/useSearchParams.js +2 -2
- package/dist/app/lib/routing/index.d.ts +14 -13
- package/dist/app/lib/routing/index.js +14 -13
- package/dist/app/lib/routing/loader.d.ts +2 -2
- package/dist/app/lib/routing/loader.js +20 -11
- package/dist/app/lib/routing/types.d.ts +37 -10
- package/dist/app/lib/routing/utils.d.ts +5 -2
- package/dist/app/lib/routing/utils.js +37 -4
- package/dist/app/lib/{hooks → runtime}/apiConfig.d.ts +6 -2
- package/dist/app/lib/runtime/apiConfig.js +6 -0
- package/dist/app/lib/runtime/errorHandling.d.ts +39 -0
- package/dist/app/lib/runtime/errorHandling.js +6 -0
- package/dist/app/lib/runtime/index.d.ts +2 -0
- package/dist/app/lib/runtime/index.js +2 -0
- package/dist/app/lib/views/index.d.ts +1 -1
- package/dist/app/lib/views/index.js +1 -1
- package/dist/app/server/defineRouter.d.ts +2 -0
- package/dist/app/server/defineRouter.js +4 -0
- package/dist/app/server/index.d.ts +5 -3
- package/dist/app/server/index.js +5 -3
- package/dist/app/server/proxy-wp-admin.d.ts +1 -2
- package/dist/app/server/proxy-wp-admin.js +41 -14
- package/dist/app/server/render-ssr-page.d.ts +27 -2
- package/dist/app/server/render-ssr-page.js +192 -12
- package/dist/app/server/rpc.d.ts +56 -0
- package/dist/app/server/rpc.js +18 -0
- package/dist/app/server/server-context.d.ts +44 -4
- package/dist/app/server/server-context.js +305 -28
- package/dist/app/server/utils/replace-host.d.ts +1 -1
- package/dist/app/server/utils/replace-host.js +10 -2
- package/dist/app/server/utils/swr-cache.d.ts +4 -0
- package/dist/app/server/utils/swr-cache.js +31 -0
- package/dist/app/utils/APIProvider.d.ts +2 -0
- package/dist/app/utils/APIProvider.js +5 -0
- package/dist/app/utils/BlockErrorBoundary.d.ts +19 -0
- package/dist/app/utils/BlockErrorBoundary.js +38 -0
- package/dist/app/utils/ErrorMessage.d.ts +5 -0
- package/dist/app/utils/ErrorMessage.js +14 -0
- package/dist/app/utils/RouteErrorBoundary.d.ts +18 -0
- package/dist/app/utils/RouteErrorBoundary.js +38 -0
- package/dist/app/utils/asset-capture.d.ts +2 -0
- package/dist/app/utils/asset-capture.js +5 -0
- package/dist/app/utils/hydration-debugger.d.ts +13 -0
- package/dist/app/utils/hydration-debugger.js +11 -0
- package/dist/app/utils/query-client.d.ts +2 -0
- package/dist/app/utils/query-client.js +5 -1
- package/dist/app/utils/query-monitor.d.ts +26 -0
- package/dist/app/utils/query-monitor.js +7 -0
- package/dist/app/utils/trpc-client.d.ts +2 -0
- package/dist/app/utils/trpc-client.js +39 -0
- package/dist/node/cli/cli-worker.js +10 -5
- package/dist/node/cli/cli.js +81 -11
- package/dist/node/cli/display/CLIApp.js +3 -6
- package/dist/node/cli/display/boot-cli-app.js +1 -1
- package/dist/node/cli/display/tools/CreateBlock.d.ts +1 -1
- package/dist/node/cli/display/tools/cli-tools.d.ts +1 -11
- package/dist/node/cli/display/tools/cli-tools.js +9 -9
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/compiler/build-vinxi.js +2 -1
- package/dist/node/compiler/bundler.admin.d.ts +1 -1
- package/dist/node/compiler/bundler.admin.js +1 -1
- package/dist/node/compiler/bundler.frontend.js +1 -1
- package/dist/node/compiler/dev-server.js +10 -0
- package/dist/node/compiler/get-vite-config.d.ts +7 -1
- package/dist/node/compiler/get-vite-config.js +96 -16
- package/dist/node/compiler/vinxi-app.d.ts +12 -0
- package/dist/node/compiler/vinxi-app.js +139 -32
- package/dist/node/compiler/vinxi-codegen.js +345 -112
- package/dist/node/graphql/graphql-codegen.d.ts +11 -1
- package/dist/node/graphql/graphql-codegen.js +210 -33
- package/dist/node/graphql/graphql-schema-loader.d.ts +2 -1
- package/dist/node/graphql/graphql-schema-loader.js +5 -16
- package/dist/node/graphql/plugins/gql-plugin-queries.js +1 -1
- package/dist/node/graphql/query-files-loader.d.ts +3 -0
- package/dist/node/graphql/query-files-loader.js +5 -0
- package/dist/node/project/config.d.ts +159 -73
- package/dist/node/project/config.js +69 -20
- package/dist/node/project/env.d.ts +4 -0
- package/dist/node/project/env.js +1 -0
- package/dist/node/project/manifest/block-manifest.js +2 -1
- package/dist/node/project/manifest/manifest.d.ts +1 -0
- package/dist/node/project/manifest/manifest.js +14 -10
- package/dist/node/project/manifest/routes-manifest.d.ts +20 -0
- package/dist/node/project/manifest/routes-manifest.js +74 -0
- package/dist/node/project/manifest/view-manifest.js +1 -1
- package/dist/node/project/project.d.ts +11 -1
- package/dist/node/project/project.js +61 -7
- package/dist/node/project/wp-info.d.ts +1 -0
- package/dist/node/project/wp-info.js +13 -1
- package/dist/node/storybook/index.d.ts +2 -0
- package/dist/node/storybook/index.js +13 -0
- package/dist/node/types/block-type.d.ts +25 -20
- package/dist/node/types/block-type.js +1 -0
- package/dist/node/types/view-type.d.ts +7 -7
- package/dist/node/utils/fetch-wp.d.ts +1 -0
- package/dist/node/utils/fetch-wp.js +27 -0
- package/dist/node/utils/fs-codegen.d.ts +2 -0
- package/dist/node/utils/fs-codegen.js +2 -1
- package/dist/node/utils/is-deploying.js +1 -1
- package/dist/node/utils/report-builder.d.ts +6 -6
- package/dist/node/utils/self-signed-cert.d.ts +2 -0
- package/dist/node/utils/self-signed-cert.js +10 -2
- package/dist/node/utils/stateful-log.js +2 -0
- package/dist/node/utils/watch-file-tree.d.ts +17 -3
- package/dist/node/utils/watch-file-tree.js +12 -5
- package/package.json +21 -12
- package/types.app.d.ts +4 -2
- package/types.app.internal.d.ts +2 -2
- package/types.meta.d.ts +105 -0
- package/types.node.d.ts +3 -3
- package/dist/app/lib/blocks/ErrorBoundaryFrontend.d.ts +0 -15
- package/dist/app/lib/blocks/ErrorBoundaryFrontend.js +0 -35
- package/dist/app/lib/hooks/apiConfig.js +0 -4
- package/dist/app/lib/hooks/usePageLoad.d.ts +0 -6
- package/dist/app/lib/hooks/usePageLoad.js +0 -5
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
export function EditorHighlights(props) {
|
|
4
|
+
const [element, setElement] = useState(null);
|
|
5
|
+
const [controller, setController] = useState(null);
|
|
6
|
+
// wp.data.select('core/editor').isBlockSelected
|
|
7
|
+
// const isSelected = wp.data.useSelect(
|
|
8
|
+
// (select) => (select("core/editor") as any).isBlockSelected(props.clientId),
|
|
9
|
+
// [props.clientId]
|
|
10
|
+
// )
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!props.enabled || !element)
|
|
13
|
+
return;
|
|
14
|
+
const controller = new HighlightController(element);
|
|
15
|
+
setController(controller);
|
|
16
|
+
return () => controller.teardown();
|
|
17
|
+
}, [props.enabled, element]);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (controller) {
|
|
20
|
+
controller.isSelected = false;
|
|
21
|
+
controller.updateClasses();
|
|
22
|
+
controller.update();
|
|
23
|
+
}
|
|
24
|
+
}, [controller, false]);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
const element = document.getElementById(`block-${props.clientId}`);
|
|
27
|
+
if (element) {
|
|
28
|
+
setElement(element);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
setElement(null);
|
|
32
|
+
}
|
|
33
|
+
}, [props.clientId]);
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
if (controller && element) {
|
|
36
|
+
const onPointerEnter = () => controller.enable();
|
|
37
|
+
const onPointerLeave = () => controller.disable();
|
|
38
|
+
element.addEventListener("pointerenter", onPointerEnter);
|
|
39
|
+
element.addEventListener("pointerleave", onPointerLeave);
|
|
40
|
+
return () => {
|
|
41
|
+
element.removeEventListener("pointerenter", onPointerEnter);
|
|
42
|
+
element.removeEventListener("pointerleave", onPointerLeave);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}, [element, controller]);
|
|
46
|
+
return _jsx(_Fragment, { children: props.children });
|
|
47
|
+
// return (
|
|
48
|
+
// <div
|
|
49
|
+
// ref={ref}
|
|
50
|
+
// style={{ display: "contents" }}
|
|
51
|
+
// // onPointerEnter={() => controller?.enable()}
|
|
52
|
+
// // onPointerLeave={() => controller?.disable()}
|
|
53
|
+
// >
|
|
54
|
+
// {props.children}
|
|
55
|
+
// </div>
|
|
56
|
+
// )
|
|
57
|
+
}
|
|
58
|
+
class HighlightController {
|
|
59
|
+
root;
|
|
60
|
+
enabled = false;
|
|
61
|
+
disposers = [];
|
|
62
|
+
elements = new Map();
|
|
63
|
+
block = null;
|
|
64
|
+
isSelected = false;
|
|
65
|
+
constructor(root) {
|
|
66
|
+
this.root = root;
|
|
67
|
+
}
|
|
68
|
+
setup() {
|
|
69
|
+
this.teardown();
|
|
70
|
+
const updateElements = () => {
|
|
71
|
+
let editables = Array.from(this.root.querySelectorAll("[contenteditable=true], .editable-slot"));
|
|
72
|
+
let childBlocks = Array.from(this.root.querySelectorAll(".wp-block"));
|
|
73
|
+
const childIsSelected = this.root.querySelectorAll(".editor-highlighter-root-selected").length > 0;
|
|
74
|
+
this.block = this.root;
|
|
75
|
+
childBlocks = childBlocks.slice(1);
|
|
76
|
+
editables = childIsSelected
|
|
77
|
+
? []
|
|
78
|
+
: editables.filter((element) => !childBlocks.some((block) => block.contains(element)));
|
|
79
|
+
let changed = false;
|
|
80
|
+
for (const [el, item] of this.elements) {
|
|
81
|
+
if (!editables.includes(el)) {
|
|
82
|
+
item.observer.disconnect();
|
|
83
|
+
item.overlay.remove();
|
|
84
|
+
this.elements.delete(el);
|
|
85
|
+
changed = true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
for (let el of editables) {
|
|
89
|
+
if (!this.elements.has(el)) {
|
|
90
|
+
const observer = new ResizeObserver(() => this.update());
|
|
91
|
+
observer.observe(el);
|
|
92
|
+
this.elements.set(el, {
|
|
93
|
+
observer,
|
|
94
|
+
bounds: el.getBoundingClientRect(),
|
|
95
|
+
overlay: this.createOverlay(el),
|
|
96
|
+
});
|
|
97
|
+
changed = true;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
if (changed) {
|
|
101
|
+
this.update();
|
|
102
|
+
this.updateClasses();
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const mutationObserver = new MutationObserver(() => {
|
|
106
|
+
updateElements();
|
|
107
|
+
});
|
|
108
|
+
updateElements();
|
|
109
|
+
mutationObserver.observe(this.root, { childList: true, subtree: true });
|
|
110
|
+
this.disposers.push(() => {
|
|
111
|
+
mutationObserver.disconnect();
|
|
112
|
+
for (const item of this.elements.values()) {
|
|
113
|
+
item.observer.disconnect();
|
|
114
|
+
item.overlay.remove();
|
|
115
|
+
}
|
|
116
|
+
this.elements = new Map();
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
updateClasses() {
|
|
120
|
+
for (const item of this.elements.values()) {
|
|
121
|
+
item.overlay.classList.toggle("editor-highlight-selected", this.isSelected);
|
|
122
|
+
}
|
|
123
|
+
this.root.classList.toggle("editor-highlighter-root-selected", this.enabled);
|
|
124
|
+
}
|
|
125
|
+
createOverlay(target) {
|
|
126
|
+
const el = document.createElement("div");
|
|
127
|
+
el.style.position = "absolute";
|
|
128
|
+
el.style.pointerEvents = "none";
|
|
129
|
+
el.style.zIndex = "20";
|
|
130
|
+
el.classList.add("editor-highlight");
|
|
131
|
+
if (target.getAttribute("data-editor-higlight-class")) {
|
|
132
|
+
el.classList.add(target.getAttribute("data-editor-higlight-class"));
|
|
133
|
+
}
|
|
134
|
+
this.block.appendChild(el);
|
|
135
|
+
return el;
|
|
136
|
+
}
|
|
137
|
+
teardown() {
|
|
138
|
+
this.disposers.forEach((dispose) => dispose());
|
|
139
|
+
}
|
|
140
|
+
enable() {
|
|
141
|
+
this.enabled = true;
|
|
142
|
+
this.setup();
|
|
143
|
+
this.update();
|
|
144
|
+
this.updateClasses();
|
|
145
|
+
}
|
|
146
|
+
disable() {
|
|
147
|
+
this.enabled = false;
|
|
148
|
+
this.teardown();
|
|
149
|
+
this.update();
|
|
150
|
+
this.updateClasses();
|
|
151
|
+
}
|
|
152
|
+
update() {
|
|
153
|
+
if (!this.block)
|
|
154
|
+
return;
|
|
155
|
+
const rootBounds = this.block.getBoundingClientRect();
|
|
156
|
+
for (const [el, item] of this.elements) {
|
|
157
|
+
const bounds = el.getBoundingClientRect();
|
|
158
|
+
item.overlay.style.left = bounds.left - rootBounds.left + "px";
|
|
159
|
+
item.overlay.style.top = bounds.top - rootBounds.top + "px";
|
|
160
|
+
item.overlay.style.width = bounds.width + "px";
|
|
161
|
+
item.overlay.style.height = bounds.height + "px";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { ErrorBoundaryEditor } from "./ErrorBoundaryEditor";
|
|
2
|
+
import { createContext, Suspense, useContext, useEffect } from "react";
|
|
3
|
+
import { blockManifestReader } from "../../internal/read-block-manifest.js";
|
|
4
|
+
import { APIProvider } from "../../../utils/APIProvider.js";
|
|
5
|
+
import { ErrorBoundaryEditor } from "./ErrorBoundaryEditor.js";
|
|
7
6
|
export const BlockContext = createContext(undefined);
|
|
8
7
|
export function EditableBlock({ payload }) {
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
if (!env.admin)
|
|
9
|
+
throw new Error("`EditableBlock` can only be used in the admin environment");
|
|
10
|
+
const info = useContext(BlockContext);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const block = wp.data.select("core/block-editor").getBlock(info?.props.clientId);
|
|
13
|
+
if (block && block.attributes) {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
block.attributes.props = payload;
|
|
16
|
+
}
|
|
17
|
+
}, [payload, info?.props.clientId]);
|
|
18
|
+
if (!info)
|
|
11
19
|
return null;
|
|
12
|
-
const
|
|
13
|
-
return blockManifestReader.value[block.name];
|
|
14
|
-
};
|
|
15
|
-
const BlockComponent = getBlock();
|
|
20
|
+
const BlockComponent = blockManifestReader.value[info.name];
|
|
16
21
|
if (!BlockComponent)
|
|
17
22
|
return _jsx("div", { children: "Unable to load block component" });
|
|
18
|
-
return (_jsx(ErrorBoundaryEditor, { children: _jsx(
|
|
23
|
+
return (_jsx(ErrorBoundaryEditor, { children: _jsx(APIProvider, { children: _jsx(Suspense, { children: _jsx(BlockComponent, { ...payload }) }) }) }));
|
|
19
24
|
}
|
|
@@ -10,6 +10,6 @@ export declare class ErrorBoundaryEditor extends Component<Props, State> {
|
|
|
10
10
|
state: State;
|
|
11
11
|
static getDerivedStateFromError(err: Error): State;
|
|
12
12
|
componentDidCatch(error: Error, errorInfo: ErrorInfo): void;
|
|
13
|
-
render(): string | number | boolean | import("react/jsx-runtime").JSX.Element |
|
|
13
|
+
render(): string | number | boolean | Iterable<React.ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
14
14
|
}
|
|
15
15
|
export {};
|
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
export type BlockTemplate = [name: ChildBlockTypeName, props: any, children?: BlockTemplate][];
|
|
2
2
|
export declare function resolveAcfBlockName(name: string): string;
|
|
3
3
|
export declare function transformBlockTemplate(template: BlockTemplate): BlockTemplate;
|
|
4
|
+
export declare function applyTemplateBlocks(currentBlocks: any[], config: {
|
|
5
|
+
defaultBlocks?: BlockTemplate;
|
|
6
|
+
headerTemplate?: BlockTemplate;
|
|
7
|
+
footerTemplate?: BlockTemplate;
|
|
8
|
+
}): any[];
|
|
9
|
+
export declare function transformTemplateToBlocks(template: BlockTemplate, locked?: boolean, isFromTemplate?: boolean): any;
|
|
@@ -7,3 +7,67 @@ export function transformBlockTemplate(template) {
|
|
|
7
7
|
return [resolveAcfBlockName(name), props, children ? transformBlockTemplate(children) : undefined];
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
|
+
export function applyTemplateBlocks(currentBlocks, config) {
|
|
11
|
+
const templateBlocks = currentBlocks.filter((block) => block.attributes.isFromTemplate);
|
|
12
|
+
let header = config.headerTemplate ? syncBlocks(transformTemplateToBlocks(config.headerTemplate)) : [];
|
|
13
|
+
let footer = config.footerTemplate ? syncBlocks(transformTemplateToBlocks(config.footerTemplate)) : [];
|
|
14
|
+
let blocks = currentBlocks.filter((block) => !header.includes(block) && !footer.includes(block));
|
|
15
|
+
blocks.forEach((block) => {
|
|
16
|
+
delete block.attributes.lock;
|
|
17
|
+
delete block.isFromTemplate;
|
|
18
|
+
});
|
|
19
|
+
// const blocksToDelete = currentBlocks.filter((block: any) => {
|
|
20
|
+
// return !header.includes(block) && !footer.includes(block) && !blocks.includes(block)
|
|
21
|
+
// })
|
|
22
|
+
// blocksToDelete.forEach((block: any) => {
|
|
23
|
+
// delete block.attributes.lock
|
|
24
|
+
// delete block.isFromTemplate
|
|
25
|
+
// })
|
|
26
|
+
// blocks = [...blocks, ...blocksToDelete]
|
|
27
|
+
// console.log("blocks", blocks)
|
|
28
|
+
// console.log("blocksToDelete", blocksToDelete)
|
|
29
|
+
if (!blocks.length && config.defaultBlocks) {
|
|
30
|
+
blocks = transformTemplateToBlocks(config.defaultBlocks, false, false);
|
|
31
|
+
}
|
|
32
|
+
let newBlocks = [...header, ...blocks, ...footer];
|
|
33
|
+
function syncBlocks(blocks) {
|
|
34
|
+
return blocks.map((block) => {
|
|
35
|
+
const matched = templateBlocks.find((templateBlock) => templateBlock.name === block.name);
|
|
36
|
+
templateBlocks.splice(templateBlocks.indexOf(matched), 1);
|
|
37
|
+
if (matched) {
|
|
38
|
+
matched.attributes.lock = block.attributes.lock;
|
|
39
|
+
return matched;
|
|
40
|
+
}
|
|
41
|
+
return block;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return newBlocks;
|
|
45
|
+
}
|
|
46
|
+
export function transformTemplateToBlocks(template, locked = true, isFromTemplate = true) {
|
|
47
|
+
return template.map(([name, props, children]) => {
|
|
48
|
+
const attributes = {
|
|
49
|
+
data: {},
|
|
50
|
+
inline: {},
|
|
51
|
+
isFromTemplate: isFromTemplate,
|
|
52
|
+
lock: undefined,
|
|
53
|
+
};
|
|
54
|
+
if (props.locked === false) {
|
|
55
|
+
attributes.lock = { move: false, remove: false };
|
|
56
|
+
}
|
|
57
|
+
else if (locked || props.locked === true || props.locked === "all") {
|
|
58
|
+
attributes.lock = { move: true, remove: true };
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
attributes.lock = props.lock;
|
|
62
|
+
}
|
|
63
|
+
Object.assign(attributes, props);
|
|
64
|
+
return {
|
|
65
|
+
clientId: "block-" + Math.random().toString(36),
|
|
66
|
+
name: resolveAcfBlockName(name),
|
|
67
|
+
attributes: attributes,
|
|
68
|
+
innerBlocks: children ? transformTemplateToBlocks(children, false, isFromTemplate) : [],
|
|
69
|
+
isValid: true,
|
|
70
|
+
validationIssues: [],
|
|
71
|
+
};
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BlockInstance } from "../inline-editing";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a block instance for the editor. This doesn't add the block to the editor on it's own.
|
|
4
|
+
* @param name The name of the block
|
|
5
|
+
* @param attributes
|
|
6
|
+
* @param innerBlocks
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare function createBlock(name: ChildBlockTypeName, attributes?: Record<string, any>, innerBlocks?: BlockInstance[]): BlockInstance;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a block instance for the editor. This doesn't add the block to the editor on it's own.
|
|
3
|
+
* @param name The name of the block
|
|
4
|
+
* @param attributes
|
|
5
|
+
* @param innerBlocks
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export function createBlock(name, attributes = {}, innerBlocks = []) {
|
|
9
|
+
if (!env.admin) {
|
|
10
|
+
throw new Error("`createBlock` can only be used in the admin environment");
|
|
11
|
+
}
|
|
12
|
+
return wp.blocks.createBlock(name, attributes, innerBlocks);
|
|
13
|
+
}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
import { BlockTemplate } from "./block-templates";
|
|
1
|
+
import { BlockTemplate } from "./block-templates.js";
|
|
2
2
|
export type EditorConfigItem = {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Optionally indicate that the post title field should be hidden. Use then when your header template includes a post title editor already.
|
|
5
|
+
* @default false
|
|
6
|
+
**/
|
|
4
7
|
hideTitle?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Override the blocks which are allowed to be added to the root of this post-type/template combination.
|
|
10
|
+
*
|
|
11
|
+
* You can specify one or more block names, or block tags.
|
|
12
|
+
*
|
|
13
|
+
* The default is "root".
|
|
14
|
+
*
|
|
15
|
+
* @default ["root"]
|
|
16
|
+
**/
|
|
17
|
+
rootBlocks?: (ChildBlockTypeName | BlockTagName)[];
|
|
5
18
|
/** Allows you to add additional class names to blocks, depending on their type and state */
|
|
6
19
|
generateBlockClassName?: BlockWrapperClassGenerator;
|
|
7
20
|
/** The default blocks to insert when there are no (non-templated) blocks */
|
|
@@ -28,14 +41,28 @@ type BlockWrapperClassGenerator = (block: {
|
|
|
28
41
|
}, post: PostInfo) => string | void;
|
|
29
42
|
export declare const editorConfigStore: {
|
|
30
43
|
config: EditorConfig | null;
|
|
31
|
-
currentBlocksConfig: EditorConfigItem
|
|
44
|
+
currentBlocksConfig: EditorConfigItem;
|
|
32
45
|
};
|
|
33
46
|
export declare function configureEditorBlocks(config: EditorConfigItem): void;
|
|
34
|
-
export declare function transformTemplateToBlocks(template: BlockTemplate, locked?: boolean): any;
|
|
35
47
|
type PostInfo = {
|
|
36
|
-
template: TemplateName | "default";
|
|
37
48
|
type: PostTypeName;
|
|
49
|
+
isPattern: false;
|
|
50
|
+
isTemplatePart: false;
|
|
51
|
+
template: TemplateName | "default";
|
|
52
|
+
slug: string;
|
|
53
|
+
} | {
|
|
54
|
+
type: "wp_block";
|
|
55
|
+
isPattern: true;
|
|
56
|
+
isTemplatePart: false;
|
|
57
|
+
title: string;
|
|
58
|
+
} | {
|
|
59
|
+
type: "wp_template_part";
|
|
60
|
+
isPattern: false;
|
|
61
|
+
isTemplatePart: true;
|
|
62
|
+
area: string;
|
|
63
|
+
title: string;
|
|
38
64
|
slug: string;
|
|
65
|
+
wp_pattern_category?: number[];
|
|
39
66
|
};
|
|
40
67
|
type MatcherFunction = (post: PostInfo) => boolean | void;
|
|
41
68
|
type Matcher = {
|
|
@@ -44,9 +71,45 @@ type Matcher = {
|
|
|
44
71
|
/** Configuration for the editor, when the post type and template match */
|
|
45
72
|
config: EditorConfigItem | ((post: PostInfo) => EditorConfigItem);
|
|
46
73
|
};
|
|
74
|
+
export type BlockTransform = {
|
|
75
|
+
from: ChildBlockTypeName[];
|
|
76
|
+
to: ChildBlockTypeName;
|
|
77
|
+
};
|
|
78
|
+
export type CustomRichTextFormat = {
|
|
79
|
+
/** The ID of the format, eg. `"custom/fancy"` */
|
|
80
|
+
id: string;
|
|
81
|
+
/** The title of the format, shown on the tooltip */
|
|
82
|
+
title: string;
|
|
83
|
+
/**
|
|
84
|
+
* The HTML tag name to use.
|
|
85
|
+
* @default `"span"`
|
|
86
|
+
**/
|
|
87
|
+
tagName?: string;
|
|
88
|
+
/**
|
|
89
|
+
* The class name to apply to the element.
|
|
90
|
+
* @default `undefined`
|
|
91
|
+
**/
|
|
92
|
+
className?: string;
|
|
93
|
+
/**
|
|
94
|
+
* The icon to use in the toolbar.
|
|
95
|
+
*/
|
|
96
|
+
icon?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Whether format makes content interactive or not.
|
|
99
|
+
* @default `false`
|
|
100
|
+
*/
|
|
101
|
+
interactive?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Whether to disable this format by default. If `true`, you must pass the format ID to `allowedFormats` on a `EditableText` component.
|
|
104
|
+
*
|
|
105
|
+
* @default `false`
|
|
106
|
+
*/
|
|
107
|
+
disabledByDefault?: boolean;
|
|
108
|
+
};
|
|
47
109
|
type EditorConfig = {
|
|
48
|
-
|
|
49
|
-
matchers
|
|
110
|
+
customRichTextFormats?: CustomRichTextFormat[];
|
|
111
|
+
/** A list of template/post type matchers, and resulting editor config that they will apply */
|
|
112
|
+
matchers?: Matcher[];
|
|
50
113
|
};
|
|
51
114
|
/**
|
|
52
115
|
* This call should be placed in blocks/_editor.tsx
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { proxy } from "valtio";
|
|
2
|
-
import { resolveAcfBlockName, transformBlockTemplate } from "./block-templates";
|
|
2
|
+
import { applyTemplateBlocks, resolveAcfBlockName, transformBlockTemplate, transformTemplateToBlocks, } from "./block-templates.js";
|
|
3
3
|
export const editorConfigStore = proxy({
|
|
4
4
|
config: null,
|
|
5
|
-
currentBlocksConfig:
|
|
5
|
+
currentBlocksConfig: {},
|
|
6
6
|
});
|
|
7
7
|
export function configureEditorBlocks(config) {
|
|
8
8
|
const wp = window.wp;
|
|
@@ -21,60 +21,13 @@ export function configureEditorBlocks(config) {
|
|
|
21
21
|
if (config.template) {
|
|
22
22
|
setTemplate(config.template);
|
|
23
23
|
if (config.headerTemplate || config.footerTemplate) {
|
|
24
|
-
console.error("You cannot use both a template
|
|
24
|
+
console.error("You cannot use both a 'template' alongside 'headerBlock'/'footerBlock'. Did you mean to use 'defaultBlocks' instead?");
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
const currentBlocks = wp.data.select("core/block-editor").getBlocks();
|
|
29
|
-
const
|
|
30
|
-
let blocks = currentBlocks.filter((block) => !block.attributes.isFromTemplate);
|
|
31
|
-
let header = config.headerTemplate ? syncBlocks(transformTemplateToBlocks(config.headerTemplate)) : [];
|
|
32
|
-
let footer = config.footerTemplate ? syncBlocks(transformTemplateToBlocks(config.footerTemplate)) : [];
|
|
33
|
-
if (!blocks.length && config.defaultBlocks) {
|
|
34
|
-
blocks = transformTemplateToBlocks(config.defaultBlocks, false);
|
|
35
|
-
}
|
|
36
|
-
let newBlocks = [...header, ...blocks, ...footer];
|
|
37
|
-
// console.log("Configuring", newBlocks)
|
|
29
|
+
const newBlocks = applyTemplateBlocks(currentBlocks, config);
|
|
38
30
|
wp.data.dispatch("core/block-editor").resetBlocks(newBlocks);
|
|
39
|
-
function syncBlocks(blocks) {
|
|
40
|
-
return blocks.map((block) => {
|
|
41
|
-
const matched = templateBlocks.find((templateBlock) => templateBlock.name === block.name);
|
|
42
|
-
templateBlocks.splice(templateBlocks.indexOf(matched), 1);
|
|
43
|
-
if (matched) {
|
|
44
|
-
matched.attributes.lock = block.attributes.lock;
|
|
45
|
-
return matched;
|
|
46
|
-
}
|
|
47
|
-
return block;
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export function transformTemplateToBlocks(template, locked = true) {
|
|
52
|
-
return template.map(([name, props, children]) => {
|
|
53
|
-
const attributes = {
|
|
54
|
-
data: {},
|
|
55
|
-
inline: {},
|
|
56
|
-
isFromTemplate: true,
|
|
57
|
-
lock: undefined,
|
|
58
|
-
};
|
|
59
|
-
if (props.locked === false) {
|
|
60
|
-
attributes.lock = { move: false, remove: false };
|
|
61
|
-
}
|
|
62
|
-
else if (locked || props.locked === true || props.locked === "all") {
|
|
63
|
-
attributes.lock = { move: true, remove: true };
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
attributes.lock = props.lock;
|
|
67
|
-
}
|
|
68
|
-
Object.assign(attributes, props);
|
|
69
|
-
return {
|
|
70
|
-
clientId: "block-" + Math.random().toString(36),
|
|
71
|
-
name: resolveAcfBlockName(name),
|
|
72
|
-
attributes: attributes,
|
|
73
|
-
innerBlocks: children ? transformTemplateToBlocks(children, false) : [],
|
|
74
|
-
isValid: true,
|
|
75
|
-
validationIssues: [],
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
31
|
}
|
|
79
32
|
/**
|
|
80
33
|
* This call should be placed in blocks/_editor.tsx
|
|
@@ -92,10 +45,18 @@ export function getEditingPostInfo() {
|
|
|
92
45
|
const postInfo = {
|
|
93
46
|
...post,
|
|
94
47
|
...edits,
|
|
48
|
+
isTemplatePart: false,
|
|
49
|
+
isPattern: false,
|
|
95
50
|
};
|
|
96
51
|
if (!postInfo.template)
|
|
97
52
|
postInfo.template = "default";
|
|
98
53
|
postInfo.template = postInfo.template.replace(/(^views\/|\.tsx?$)/g, "");
|
|
54
|
+
if (postInfo.type === "wp_template_part") {
|
|
55
|
+
postInfo.isTemplatePart = true;
|
|
56
|
+
}
|
|
57
|
+
if (postInfo.type === "wp_block") {
|
|
58
|
+
postInfo.isPattern = true;
|
|
59
|
+
}
|
|
99
60
|
return postInfo;
|
|
100
61
|
}
|
|
101
62
|
export function updateTemplateConfig() {
|
|
@@ -104,7 +65,7 @@ export function updateTemplateConfig() {
|
|
|
104
65
|
const editorConfig = editorConfigStore.config;
|
|
105
66
|
if (!editorConfig)
|
|
106
67
|
return;
|
|
107
|
-
const matched = editorConfig.matchers
|
|
68
|
+
const matched = editorConfig.matchers?.find((matcher) => {
|
|
108
69
|
return matcher.match(postInfo);
|
|
109
70
|
});
|
|
110
71
|
if (matched) {
|
|
@@ -118,17 +79,24 @@ export function updateTemplateConfig() {
|
|
|
118
79
|
}
|
|
119
80
|
}
|
|
120
81
|
export function watchEditorTemplate() {
|
|
121
|
-
let
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
82
|
+
let lastKey = "unknown";
|
|
83
|
+
let timer = 0;
|
|
84
|
+
const update = () => {
|
|
85
|
+
const post = wp.data.select("core/editor").getCurrentPost();
|
|
86
|
+
const template = wp.data.select("core/editor").getPostEdits()?.template ?? post?.template ?? "";
|
|
87
|
+
const key = [post.type, template, post.slug, post.title].join(";");
|
|
88
|
+
if (key !== lastKey) {
|
|
89
|
+
lastKey = key;
|
|
90
|
+
clearTimeout(timer);
|
|
91
|
+
timer = setTimeout(() => {
|
|
128
92
|
updateTemplateConfig();
|
|
129
|
-
}
|
|
130
|
-
}
|
|
93
|
+
}, 20);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
wp.data.subscribe(() => {
|
|
97
|
+
update();
|
|
131
98
|
});
|
|
99
|
+
update();
|
|
132
100
|
}
|
|
133
101
|
function setWrapperBlock(blockName, blocks) {
|
|
134
102
|
const wp = window.wp;
|
|
@@ -174,7 +142,6 @@ function setWrapperBlock(blockName, blocks) {
|
|
|
174
142
|
}
|
|
175
143
|
function setTemplate(template) {
|
|
176
144
|
const wp = window.wp;
|
|
177
|
-
// console.log("Setting template", template)
|
|
178
145
|
let currentBlocks = wp.data.select("core/block-editor").getBlocks();
|
|
179
146
|
wp.data.dispatch("core/block-editor").updateSettings({
|
|
180
147
|
templateLock: "all",
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
export declare const blockMetaDescriptors: Map<string, BlockMeta> & {
|
|
2
|
+
$$valtioSnapshot: Omit<Map<string, BlockMeta>, "set" | "clear" | "delete">;
|
|
3
|
+
};
|
|
1
4
|
export declare function whenEditorIsReady(): Promise<void>;
|
|
2
5
|
export declare function installEDGutenbergHooks(): void;
|