eddev 2.0.0-beta.50 → 2.0.0-beta.52
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/dist/app/entry/boot-admin.js +9 -3
- package/dist/app/lib/blocks/editor/editor-config.d.ts +15 -2
- package/dist/app/lib/blocks/editor/editor-config.js +1 -3
- package/dist/app/lib/blocks/editor/installGutenbergHooks.js +7 -6
- 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/hooks/apiConfig.d.ts +2 -2
- package/dist/app/lib/hooks/queryUtils.js +2 -2
- package/dist/app/server/proxy-wp-admin.js +8 -3
- package/dist/node/cli/version.d.ts +1 -1
- package/dist/node/cli/version.js +1 -1
- package/dist/node/project/manifest/block-manifest.js +1 -0
- package/dist/node/types/block-type.d.ts +5 -0
- package/dist/node/types/block-type.js +1 -0
- package/package.json +1 -1
|
@@ -2,7 +2,13 @@ import { installFieldTypes } from "../lib/admin/installFieldTypes.js";
|
|
|
2
2
|
import { runWidgets } from "../lib/admin/runWidgets.js";
|
|
3
3
|
import { installEDGutenbergHooks } from "../lib/blocks/editor/installGutenbergHooks.js";
|
|
4
4
|
export default function bootAdmin() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
console.log("Booting admin");
|
|
6
|
+
if (window.name === "editor-canvas") {
|
|
7
|
+
console.log("In canvas");
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
installEDGutenbergHooks();
|
|
11
|
+
installFieldTypes();
|
|
12
|
+
runWidgets();
|
|
13
|
+
}
|
|
8
14
|
}
|
|
@@ -1,7 +1,20 @@
|
|
|
1
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,7 +41,7 @@ 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
47
|
export declare function transformTemplateToBlocks(template: BlockTemplate, locked?: boolean): any;
|
|
@@ -2,7 +2,7 @@ import { proxy } from "valtio";
|
|
|
2
2
|
import { resolveAcfBlockName, transformBlockTemplate } 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;
|
|
@@ -34,7 +34,6 @@ export function configureEditorBlocks(config) {
|
|
|
34
34
|
blocks = transformTemplateToBlocks(config.defaultBlocks, false);
|
|
35
35
|
}
|
|
36
36
|
let newBlocks = [...header, ...blocks, ...footer];
|
|
37
|
-
// console.log("Configuring", newBlocks)
|
|
38
37
|
wp.data.dispatch("core/block-editor").resetBlocks(newBlocks);
|
|
39
38
|
function syncBlocks(blocks) {
|
|
40
39
|
return blocks.map((block) => {
|
|
@@ -174,7 +173,6 @@ function setWrapperBlock(blockName, blocks) {
|
|
|
174
173
|
}
|
|
175
174
|
function setTemplate(template) {
|
|
176
175
|
const wp = window.wp;
|
|
177
|
-
// console.log("Setting template", template)
|
|
178
176
|
let currentBlocks = wp.data.select("core/block-editor").getBlocks();
|
|
179
177
|
wp.data.dispatch("core/block-editor").updateSettings({
|
|
180
178
|
templateLock: "all",
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
|
+
import { useSnapshot } from "valtio";
|
|
4
|
+
import { getBlockMetadata } from "../block-utils.js";
|
|
3
5
|
import { InlineEditingContextProvider } from "../inline-editing.js";
|
|
4
6
|
import { BlockContext, EditableBlock } from "./EditorSupport.js";
|
|
5
7
|
import { blocksByTag } from "./blocks-by-tag.js";
|
|
6
8
|
import { editorConfigStore, getEditingPostInfo, watchEditorTemplate } from "./editor-config.js";
|
|
7
|
-
import {
|
|
8
|
-
import { getBlockMetadata } from "../block-utils.js";
|
|
9
|
+
import { rootBlocks } from "./root-blocks.js";
|
|
9
10
|
function listenForHandleResize() {
|
|
10
11
|
let interval = setInterval(() => {
|
|
11
12
|
let viewportTarget = document.querySelector(".interface-interface-skeleton__content");
|
|
@@ -53,6 +54,8 @@ export function installEDGutenbergHooks() {
|
|
|
53
54
|
wp.richText.unregisterFormatType("core/keyboard");
|
|
54
55
|
wp.richText.unregisterFormatType("core/text-color");
|
|
55
56
|
whenEditorIsReady().then(() => watchEditorTemplate());
|
|
57
|
+
// Recalculate registered blocks when rootBlocks change
|
|
58
|
+
rootBlocks.listen();
|
|
56
59
|
wp.hooks.addFilter("blocks.registerBlockType", "ed", (item, name) => {
|
|
57
60
|
// Hook into ACF blocks, customising the edit mode.
|
|
58
61
|
if (name.startsWith("acf/")) {
|
|
@@ -99,13 +102,11 @@ export function installEDGutenbergHooks() {
|
|
|
99
102
|
item.tags = [];
|
|
100
103
|
}
|
|
101
104
|
blocksByTag.add(item.name, item.tags);
|
|
105
|
+
const isRootBlock = rootBlocks.isRootBlock(name, item.tags);
|
|
102
106
|
return {
|
|
103
107
|
...item,
|
|
104
108
|
get parent() {
|
|
105
|
-
return blocksByTag.expand([
|
|
106
|
-
...(item.parent ?? []),
|
|
107
|
-
...(item.tags.includes("root") ? ["core/post-content"] : []),
|
|
108
|
-
]);
|
|
109
|
+
return blocksByTag.expand([...(item.parent ?? []), ...(isRootBlock ? ["core/post-content"] : [])]);
|
|
109
110
|
},
|
|
110
111
|
get ancestor() {
|
|
111
112
|
return item.ancestor ? blocksByTag.expand(item.ancestor) : undefined;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { hash } from "object-code";
|
|
2
|
+
import { subscribe, snapshot } from "valtio";
|
|
3
|
+
import { editorConfigStore } from "./editor-config";
|
|
4
|
+
import { blocksByTag } from "./blocks-by-tag";
|
|
5
|
+
let constraint = ["root"];
|
|
6
|
+
let rootBlockList = new Set(["root"]);
|
|
7
|
+
export const rootBlocks = {
|
|
8
|
+
listen() {
|
|
9
|
+
let key = hash(rootBlocks);
|
|
10
|
+
subscribe(editorConfigStore, () => {
|
|
11
|
+
constraint = snapshot(editorConfigStore.currentBlocksConfig).rootBlocks ?? ["root"];
|
|
12
|
+
let newKey = hash(constraint);
|
|
13
|
+
if (key === newKey)
|
|
14
|
+
return;
|
|
15
|
+
// The root blocks config have changed, so we need to recalculate the registered blocks
|
|
16
|
+
key = newKey;
|
|
17
|
+
rootBlocks.update();
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
update() {
|
|
21
|
+
rootBlockList = new Set(blocksByTag.expand(constraint));
|
|
22
|
+
wp.data.dispatch("core/blocks").reapplyBlockTypeFilters();
|
|
23
|
+
},
|
|
24
|
+
getRootBlocks() {
|
|
25
|
+
return rootBlockList;
|
|
26
|
+
},
|
|
27
|
+
isRootBlock(blockName, tags) {
|
|
28
|
+
return rootBlockList.has(blockName) || (tags && tags.some((tag) => rootBlockList.has(tag)));
|
|
29
|
+
},
|
|
30
|
+
};
|
|
@@ -11,9 +11,9 @@ export type APIConfigStore = {
|
|
|
11
11
|
*/
|
|
12
12
|
customQueryFetchOptions?: (type: "query" | "mutation", queryName: string, queryArgs: any, url: string, opts: RequestInit) => RequestInit | Promise<RequestInit>;
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* Allows you to hook into the response of a query or mutation.
|
|
15
15
|
*/
|
|
16
|
-
onResponse?: (response: Response) => void;
|
|
16
|
+
onResponse?: (response: Response, type: "query" | "mutation", queryName: string, queryArgs: any, url: string, opts: RequestInit) => void;
|
|
17
17
|
set: (config: Partial<APIConfigStore>) => void;
|
|
18
18
|
};
|
|
19
19
|
export declare const apiConfig: APIConfigStore;
|
|
@@ -31,7 +31,7 @@ const fetchGETQuery = async (name, params, opts) => {
|
|
|
31
31
|
}
|
|
32
32
|
const response = await fetch(url, options);
|
|
33
33
|
if (apiConfig.onResponse)
|
|
34
|
-
apiConfig.onResponse(response);
|
|
34
|
+
apiConfig.onResponse(response, "query", name, params, url, options);
|
|
35
35
|
const payload = await response.json();
|
|
36
36
|
if (payload.errors?.length > 0) {
|
|
37
37
|
throw createQueryError(payload.errors.map((e) => e.message), response.status);
|
|
@@ -156,7 +156,7 @@ const fetchMutation = async (name, params, opts) => {
|
|
|
156
156
|
}
|
|
157
157
|
const response = await fetch(url, options);
|
|
158
158
|
if (apiConfig.onResponse)
|
|
159
|
-
apiConfig.onResponse(response);
|
|
159
|
+
apiConfig.onResponse(response, "mutation", name, params, url, options);
|
|
160
160
|
const payload = await response.json();
|
|
161
161
|
if (payload.errors?.length > 0) {
|
|
162
162
|
throw createQueryError(payload.errors.map((e) => e.message), response.status);
|
|
@@ -52,15 +52,20 @@ export async function proxyWpAdmin(event, serverContext) {
|
|
|
52
52
|
if (contentType.startsWith("text/html")) {
|
|
53
53
|
const clientManifest = serverContext.runtime.getManifest("admin");
|
|
54
54
|
const assets = await clientManifest.inputs[clientManifest.handler].assets();
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const getViteHeader = () => assets.map((asset) => renderAsset(asset)).join("\n");
|
|
56
|
+
const getViteFooter = () => renderAsset({
|
|
57
57
|
tag: "script",
|
|
58
58
|
attrs: {
|
|
59
59
|
type: "module",
|
|
60
60
|
src: clientManifest.inputs[clientManifest.handler].output.path,
|
|
61
61
|
},
|
|
62
62
|
children: "",
|
|
63
|
-
})
|
|
63
|
+
});
|
|
64
|
+
const encodeForJSON = (str) => JSON.stringify(str).slice(1, -1).replace(/\"/g, "'");
|
|
65
|
+
body = body.replace(/<!---VITE_HEADER--->/g, getViteHeader);
|
|
66
|
+
body = body.replace(/<!---VITE_FOOTER--->/g, getViteFooter);
|
|
67
|
+
body = body.replace(/<!---VITE_HEADER_ENCODED--->/g, encodeForJSON(getViteHeader()));
|
|
68
|
+
body = body.replace(/<!---VITE_FOOTER_ENCODED--->/g, encodeForJSON(getViteFooter()));
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
else {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "2.0.0-beta.
|
|
1
|
+
export declare const VERSION = "2.0.0-beta.52";
|
package/dist/node/cli/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = "2.0.0-beta.
|
|
1
|
+
export const VERSION = "2.0.0-beta.52";
|
|
@@ -134,6 +134,7 @@ function readBlockDataAsJSONExport(file, contents) {
|
|
|
134
134
|
result.frontendMode = userData.frontendMode;
|
|
135
135
|
if (userData.postMetaBlock) {
|
|
136
136
|
result.postMetaBlock = {
|
|
137
|
+
postTypes: userData.postMetaBlock.postTypes,
|
|
137
138
|
fieldName: userData.postMetaBlock.fieldName,
|
|
138
139
|
};
|
|
139
140
|
result.types = userData.postMetaBlock.postTypes;
|
|
@@ -23,10 +23,13 @@ export declare const BlockMetaSchema: z.ZodObject<{
|
|
|
23
23
|
cache: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
24
24
|
allowMultiple: z.ZodDefault<z.ZodBoolean>;
|
|
25
25
|
postMetaBlock: z.ZodOptional<z.ZodObject<{
|
|
26
|
+
postTypes: z.ZodArray<z.ZodString, "many">;
|
|
26
27
|
fieldName: z.ZodString;
|
|
27
28
|
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
postTypes: string[];
|
|
28
30
|
fieldName: string;
|
|
29
31
|
}, {
|
|
32
|
+
postTypes: string[];
|
|
30
33
|
fieldName: string;
|
|
31
34
|
}>>;
|
|
32
35
|
frontendMode: z.ZodDefault<z.ZodEnum<["hidden", "childrenOnly", "default"]>>;
|
|
@@ -56,6 +59,7 @@ export declare const BlockMetaSchema: z.ZodObject<{
|
|
|
56
59
|
keywords?: string[] | undefined;
|
|
57
60
|
templates?: string[] | null | undefined;
|
|
58
61
|
postMetaBlock?: {
|
|
62
|
+
postTypes: string[];
|
|
59
63
|
fieldName: string;
|
|
60
64
|
} | undefined;
|
|
61
65
|
}, {
|
|
@@ -81,6 +85,7 @@ export declare const BlockMetaSchema: z.ZodObject<{
|
|
|
81
85
|
dynamic?: boolean | undefined;
|
|
82
86
|
allowMultiple?: boolean | undefined;
|
|
83
87
|
postMetaBlock?: {
|
|
88
|
+
postTypes: string[];
|
|
84
89
|
fieldName: string;
|
|
85
90
|
} | undefined;
|
|
86
91
|
frontendMode?: "hidden" | "childrenOnly" | "default" | undefined;
|