drupal-canvas 0.3.2 → 0.4.1

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 CHANGED
@@ -376,6 +376,47 @@ export default function MyComponent({ photo }) {
376
376
  }
377
377
  ```
378
378
 
379
+ ### Region / RegionsProvider
380
+
381
+ Render Drupal Canvas global regions inside a layout component.
382
+ `<Region name="..." />` slots in the region whose machine name matches `name`,
383
+ and `<RegionsProvider regions={...}>` supplies the region node map. On the
384
+ Drupal side, region placement is handled by the active theme; these components
385
+ are used by standalone renderers (such as
386
+ [Workbench](https://project.pages.drupalcode.org/canvas/code-components/workbench/regions))
387
+ that compose a page with its surrounding regions on their own.
388
+
389
+ ```jsx
390
+ import { Region } from 'drupal-canvas';
391
+
392
+ export default function Layout({ children }) {
393
+ return (
394
+ <>
395
+ <Region name="header" />
396
+ <main>{children}</main>
397
+ <Region name="footer" />
398
+ </>
399
+ );
400
+ }
401
+ ```
402
+
403
+ Pass a `fallback` to render placeholder content when a region is not provided:
404
+
405
+ ```jsx
406
+ <Region name="sidebar" fallback={<aside>No sidebar configured</aside>} />
407
+ ```
408
+
409
+ When composing a renderer outside of Drupal or Workbench, wrap the tree in
410
+ `RegionsProvider` with a map of region machine names to React nodes:
411
+
412
+ ```jsx
413
+ import { RegionsProvider } from 'drupal-canvas';
414
+
415
+ <RegionsProvider regions={{ header: <SiteHeader />, footer: <SiteFooter /> }}>
416
+ <Layout>{pageContent}</Layout>
417
+ </RegionsProvider>;
418
+ ```
419
+
379
420
  ## Development
380
421
 
381
422
  The following scripts are available for developing this package:
@@ -37,11 +37,11 @@ function sortMenu(linkset) {
37
37
  }
38
38
  const getPageData = () => {
39
39
  const pageData = {
40
- pageTitle: window.drupalSettings?.canvasData?.v0?.pageTitle || "",
41
- breadcrumbs: window.drupalSettings?.canvasData?.v0?.breadcrumbs || [],
42
- mainEntity: window.drupalSettings?.canvasData?.v0?.mainEntity || null
40
+ pageTitle: globalThis?.drupalSettings?.canvasData?.v0?.pageTitle || "",
41
+ breadcrumbs: globalThis?.drupalSettings?.canvasData?.v0?.breadcrumbs || [],
42
+ mainEntity: globalThis?.drupalSettings?.canvasData?.v0?.mainEntity || null
43
43
  };
44
- window.parent.postMessage({
44
+ window?.parent.postMessage({
45
45
  type: "_canvas_useswr_data_fetch",
46
46
  id: "getPageData()",
47
47
  data: pageData
@@ -50,14 +50,21 @@ const getPageData = () => {
50
50
  };
51
51
  const getSiteData = () => {
52
52
  const siteData = {
53
- branding: window.drupalSettings?.canvasData?.v0?.branding || {
53
+ branding: globalThis?.drupalSettings?.canvasData?.v0?.branding || {
54
54
  homeUrl: "",
55
55
  siteName: "",
56
56
  siteSlogan: ""
57
57
  },
58
- baseUrl: window.drupalSettings?.canvasData?.v0?.baseUrl || "/"
58
+ baseUrl: globalThis?.drupalSettings?.canvasData?.v0?.baseUrl || "/",
59
+ themeAssets: globalThis?.drupalSettings?.canvasData?.v0?.themeAssets || {
60
+ logo: { url: "" },
61
+ favicon: {
62
+ url: "",
63
+ mimeType: ""
64
+ }
65
+ }
59
66
  };
60
- window.parent.postMessage({
67
+ window?.parent.postMessage({
61
68
  type: "_canvas_useswr_data_fetch",
62
69
  id: "getSiteData()",
63
70
  data: siteData
@@ -36,6 +36,15 @@ interface PageData {
36
36
  breadcrumbs: Array<BreadcrumbLink>;
37
37
  mainEntity: EntityMetadata | null;
38
38
  }
39
+ interface ThemeAssets {
40
+ logo: {
41
+ url: string;
42
+ };
43
+ favicon: {
44
+ url: string;
45
+ mimeType: string;
46
+ };
47
+ }
39
48
  interface SiteData {
40
49
  branding: {
41
50
  homeUrl: string;
@@ -43,6 +52,7 @@ interface SiteData {
43
52
  siteSlogan: string;
44
53
  };
45
54
  baseUrl: string;
55
+ themeAssets: ThemeAssets;
46
56
  }
47
57
  declare const getPageData: () => PageData;
48
58
  declare const getSiteData: () => SiteData;
@@ -1,2 +1,2 @@
1
- import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-DNru9pSM.js";
1
+ import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-C5s72hSd.js";
2
2
  export { getPageData, getSiteData, sortMenu };
@@ -1,3 +1,3 @@
1
- import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-Dhu6eUg-.js";
1
+ import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-BxSGMAw9.js";
2
2
 
3
3
  export { getPageData, getSiteData, sortMenu };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,29 @@
1
1
  import { t as FormattedText } from "./FormattedText-yaSCYPpK.js";
2
- import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-DNru9pSM.js";
2
+ import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-C5s72hSd.js";
3
3
  import { t as CanvasJsonApiClient } from "./jsonapi-client-UDKOwuXX.js";
4
4
  import { n as sortMenu$1, t as getNodePath } from "./jsonapi-utils-DUAnKdKa.js";
5
5
  import { t as Image } from "./next-image-standalone-wADMJCIZ.js";
6
6
  import { t as cn } from "./utils-DyhCn7lR.js";
7
- export { FormattedText, Image, CanvasJsonApiClient as JsonApiClient, cn, getNodePath, getPageData, getSiteData, sortMenu as sortLinksetMenu, sortMenu$1 as sortMenu };
7
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
8
+ import { ReactNode } from "react";
9
+
10
+ //#region src/Region.d.ts
11
+ type RegionsMap = Record<string, ReactNode>;
12
+ type RegionsProviderProps = {
13
+ regions: RegionsMap;
14
+ children: ReactNode;
15
+ };
16
+ declare function RegionsProvider({
17
+ regions,
18
+ children
19
+ }: RegionsProviderProps): react_jsx_runtime1.JSX.Element;
20
+ type RegionProps = {
21
+ name: string;
22
+ fallback?: ReactNode;
23
+ };
24
+ declare function Region({
25
+ name,
26
+ fallback
27
+ }: RegionProps): react_jsx_runtime1.JSX.Element;
28
+ //#endregion
29
+ export { FormattedText, Image, CanvasJsonApiClient as JsonApiClient, Region, RegionsProvider, cn, getNodePath, getPageData, getSiteData, sortMenu as sortLinksetMenu, sortMenu$1 as sortMenu };
package/dist/index.js CHANGED
@@ -1,8 +1,24 @@
1
- import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-Dhu6eUg-.js";
1
+ import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-BxSGMAw9.js";
2
2
  import { t as FormattedText } from "./FormattedText-C1aZH-9n.js";
3
3
  import { t as CanvasJsonApiClient } from "./jsonapi-client-Wpf6rG0C.js";
4
4
  import { n as sortMenu$1, t as getNodePath } from "./jsonapi-utils-BA2DcHP4.js";
5
5
  import { t as Image } from "./next-image-standalone-Cp3o4ile.js";
6
6
  import { t as cn } from "./utils-DuVWmMX9.js";
7
+ import { Fragment, jsx } from "react/jsx-runtime";
8
+ import { createContext, useContext } from "react";
7
9
 
8
- export { FormattedText, Image, CanvasJsonApiClient as JsonApiClient, cn, getNodePath, getPageData, getSiteData, sortMenu as sortLinksetMenu, sortMenu$1 as sortMenu };
10
+ //#region src/Region.tsx
11
+ const RegionsContext = createContext({});
12
+ function RegionsProvider({ regions, children }) {
13
+ return /* @__PURE__ */ jsx(RegionsContext.Provider, {
14
+ value: regions,
15
+ children
16
+ });
17
+ }
18
+ function Region({ name, fallback = null }) {
19
+ const node = useContext(RegionsContext)[name];
20
+ return /* @__PURE__ */ jsx(Fragment, { children: node ?? fallback });
21
+ }
22
+
23
+ //#endregion
24
+ export { FormattedText, Image, CanvasJsonApiClient as JsonApiClient, Region, RegionsProvider, cn, getNodePath, getPageData, getSiteData, sortMenu as sortLinksetMenu, sortMenu$1 as sortMenu };
@@ -33,6 +33,7 @@ interface AuthoredSpecElement {
33
33
  type: string;
34
34
  props?: unknown;
35
35
  slots?: AuthoredSpecSlots;
36
+ _provenance?: Record<string, unknown>;
36
37
  }
37
38
  type AuthoredSpecElementMap = Record<string, AuthoredSpecElement>;
38
39
  type AuthoredSpecSlots = Record<string, string[]>;
@@ -345,6 +345,11 @@ var $defs = {
345
345
  }
346
346
  }
347
347
  },
348
+ "content-entity-reference": {
349
+ "title": "Content entity reference",
350
+ "type": "object",
351
+ "x-allowed-entity-type-id": null
352
+ },
348
353
  "config-entity-id": {
349
354
  "title": "config entity id",
350
355
  "type": "string",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drupal-canvas",
3
- "version": "0.3.2",
3
+ "version": "0.4.1",
4
4
  "description": "Utilities and base components for building Drupal Canvas Code Components",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -66,7 +66,7 @@
66
66
  "devDependencies": {
67
67
  "tsdown": "^0.17.0-beta.5",
68
68
  "typescript": "^5.9.3",
69
- "vitest": "^3.2.3"
69
+ "vitest": "^4.1.8"
70
70
  },
71
71
  "scripts": {
72
72
  "build": "NODE_ENV=production tsdown",