eddev 2.0.0-beta.50 → 2.0.0-beta.51

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.
@@ -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
- installEDGutenbergHooks();
6
- installFieldTypes();
7
- runWidgets();
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
- /** Optionally indicate that the post title field should be hidden. Use then when your header template includes a post title editor already. */
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 | null;
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: null,
5
+ currentBlocksConfig: {},
6
6
  });
7
7
  export function configureEditorBlocks(config) {
8
8
  const wp = window.wp;
@@ -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 { useSnapshot } from "valtio";
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,6 @@
1
+ export declare const rootBlocks: {
2
+ listen(): void;
3
+ update(): void;
4
+ getRootBlocks(): Set<string>;
5
+ isRootBlock(blockName: string, tags?: string[]): boolean | undefined;
6
+ };
@@ -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
- * Update aspects of the API client
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
- body = body.replace("<!---VITE_HEADER--->", () => assets.map((asset) => renderAsset(asset)).join("\n"));
56
- body = body.replace("<!---VITE_FOOTER--->", () => renderAsset({
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.50";
1
+ export declare const VERSION = "2.0.0-beta.51";
@@ -1 +1 @@
1
- export const VERSION = "2.0.0-beta.50";
1
+ export const VERSION = "2.0.0-beta.51";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eddev",
3
- "version": "2.0.0-beta.50",
3
+ "version": "2.0.0-beta.51",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "type": "module",