drupal-canvas 0.3.2 → 0.4.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 +41 -0
- package/dist/{drupal-utils-DNru9pSM.d.ts → drupal-utils-C5s72hSd.d.ts} +10 -0
- package/dist/{drupal-utils-Dhu6eUg-.js → drupal-utils-CqS6lCsl.js} +8 -1
- package/dist/drupal-utils.d.ts +1 -1
- package/dist/drupal-utils.js +1 -1
- package/dist/index.d.ts +24 -2
- package/dist/index.js +18 -2
- package/dist/json-render-utils.d.ts +1 -0
- package/dist/json-render-utils.js +5 -0
- package/package.json +1 -1
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:
|
|
@@ -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;
|
|
@@ -55,7 +55,14 @@ const getSiteData = () => {
|
|
|
55
55
|
siteName: "",
|
|
56
56
|
siteSlogan: ""
|
|
57
57
|
},
|
|
58
|
-
baseUrl: window.drupalSettings?.canvasData?.v0?.baseUrl || "/"
|
|
58
|
+
baseUrl: window.drupalSettings?.canvasData?.v0?.baseUrl || "/",
|
|
59
|
+
themeAssets: window.drupalSettings?.canvasData?.v0?.themeAssets || {
|
|
60
|
+
logo: { url: "" },
|
|
61
|
+
favicon: {
|
|
62
|
+
url: "",
|
|
63
|
+
mimeType: ""
|
|
64
|
+
}
|
|
65
|
+
}
|
|
59
66
|
};
|
|
60
67
|
window.parent.postMessage({
|
|
61
68
|
type: "_canvas_useswr_data_fetch",
|
package/dist/drupal-utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-
|
|
1
|
+
import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-C5s72hSd.js";
|
|
2
2
|
export { getPageData, getSiteData, sortMenu };
|
package/dist/drupal-utils.js
CHANGED
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-
|
|
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
|
-
|
|
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-
|
|
1
|
+
import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-CqS6lCsl.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
|
-
|
|
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",
|