drupal-canvas 0.4.2 → 0.4.3
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 +6 -3
- package/dist/FormattedText.d.ts +11 -1
- package/dist/FormattedText.js +10 -3
- package/dist/drupal-utils.d.ts +78 -1
- package/dist/drupal-utils.js +75 -3
- package/dist/index.d.ts +8 -16
- package/dist/index.js +7 -9
- package/dist/json-render-utils.d.ts +18 -21
- package/dist/json-render-utils.js +2 -6
- package/dist/{jsonapi-client-UDKOwuXX.d.ts → jsonapi-client-Q84JvzCD.d.ts} +6 -2
- package/dist/jsonapi-client.d.ts +1 -1
- package/dist/jsonapi-client.js +18 -5
- package/dist/jsonapi-utils.d.ts +32 -1
- package/dist/jsonapi-utils.js +42 -3
- package/dist/next-image-standalone.d.ts +6 -1
- package/dist/next-image-standalone.js +42 -3
- package/dist/utils.d.ts +4 -1
- package/dist/utils.js +8 -3
- package/package.json +18 -10
- package/dist/FormattedText-C1aZH-9n.js +0 -12
- package/dist/FormattedText-yaSCYPpK.d.ts +0 -18
- package/dist/drupal-utils-BIEn-IiB.js +0 -76
- package/dist/drupal-utils-C5s72hSd.d.ts +0 -60
- package/dist/jsonapi-client-VgGykg8d.js +0 -19
- package/dist/jsonapi-utils-BA2DcHP4.js +0 -43
- package/dist/jsonapi-utils-DUAnKdKa.d.ts +0 -33
- package/dist/next-image-standalone-Cp3o4ile.js +0 -41
- package/dist/next-image-standalone-wADMJCIZ.d.ts +0 -9
- package/dist/utils-DuVWmMX9.js +0 -10
- package/dist/utils-DyhCn7lR.d.ts +0 -6
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ Access information about the current page.
|
|
|
41
41
|
import { getPageData } from 'drupal-canvas';
|
|
42
42
|
|
|
43
43
|
const { pageTitle, breadcrumbs, mainEntity } = getPageData();
|
|
44
|
-
const { bundle, entityTypeId, uuid } = mainEntity;
|
|
44
|
+
const { bundle, entityTypeId, uuid, translations } = mainEntity;
|
|
45
45
|
```
|
|
46
46
|
|
|
47
47
|
#### Main entity metadata
|
|
@@ -49,7 +49,10 @@ const { bundle, entityTypeId, uuid } = mainEntity;
|
|
|
49
49
|
The main entity is the primary Drupal entity (e.g. article, canvas_page, blog)
|
|
50
50
|
associated with the current page. Access main entity metadata of the page you
|
|
51
51
|
are on with `getPageData`. This can be used to construct JSON:API parameters for
|
|
52
|
-
requests.
|
|
52
|
+
requests. `mainEntity.translations` lists every enabled site language
|
|
53
|
+
(`langcode`, `name`, `nativeName`, `url`, `translationAvailable`, `current`) for
|
|
54
|
+
building a language switcher, alongside `requestedLanguage` and
|
|
55
|
+
`renderedLanguage`.
|
|
53
56
|
[View documentation and example here.](https://project.pages.drupalcode.org/canvas/code-components/data-fetching#main-entity-metadata)
|
|
54
57
|
|
|
55
58
|
### `getSiteData`
|
|
@@ -200,7 +203,7 @@ const components = [
|
|
|
200
203
|
parent_uuid: '872cde09-809a-4f48-8bf5-88f37127cb55',
|
|
201
204
|
slot: 'body',
|
|
202
205
|
component_id: 'js.text',
|
|
203
|
-
component_version: '
|
|
206
|
+
component_version: 'd34b93534777207a',
|
|
204
207
|
inputs: { content: 'World' },
|
|
205
208
|
label: 'Text',
|
|
206
209
|
},
|
package/dist/FormattedText.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/FormattedText.d.ts
|
|
2
|
+
type FormattedTextProps = {
|
|
3
|
+
children: string;
|
|
4
|
+
as?: 'div' | 'span';
|
|
5
|
+
className?: string;
|
|
6
|
+
id?: string;
|
|
7
|
+
style?: Record<string, string>;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
};
|
|
10
|
+
declare function FormattedText({ children, as, ...props }: FormattedTextProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
//#endregion
|
|
2
12
|
export { FormattedText as default };
|
package/dist/FormattedText.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
//#region src/FormattedText.tsx
|
|
3
|
+
function FormattedText({ children, as = "div", ...props }) {
|
|
4
|
+
return /* @__PURE__ */ jsx(as, {
|
|
5
|
+
dangerouslySetInnerHTML: { __html: children },
|
|
6
|
+
...props
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { FormattedText as default };
|
package/dist/drupal-utils.d.ts
CHANGED
|
@@ -1,2 +1,79 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/drupal-utils.d.ts
|
|
2
|
+
interface Linkset {
|
|
3
|
+
linkset: LinksetItem[];
|
|
4
|
+
}
|
|
5
|
+
interface LinksetItem {
|
|
6
|
+
anchor: string;
|
|
7
|
+
item: LinksetMenuItem[];
|
|
8
|
+
}
|
|
9
|
+
interface LinksetMenuItem {
|
|
10
|
+
href: string;
|
|
11
|
+
hierarchy: string[];
|
|
12
|
+
_children?: LinksetMenuItem[];
|
|
13
|
+
_hasSubmenu: boolean;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Sort menu items from core's menu API into a tree with additional
|
|
17
|
+
* _children and _hasSubmenu properties.
|
|
18
|
+
*
|
|
19
|
+
* @param linkset
|
|
20
|
+
*
|
|
21
|
+
* @return menuItems
|
|
22
|
+
*/
|
|
23
|
+
declare function sortMenu(linkset: Linkset): LinksetMenuItem[];
|
|
24
|
+
interface BreadcrumbLink {
|
|
25
|
+
key: string;
|
|
26
|
+
text: string;
|
|
27
|
+
url: string;
|
|
28
|
+
}
|
|
29
|
+
interface EntityMetadata {
|
|
30
|
+
bundle: string;
|
|
31
|
+
entityTypeId: string;
|
|
32
|
+
uuid: string;
|
|
33
|
+
requestedLanguage: string;
|
|
34
|
+
renderedLanguage: string;
|
|
35
|
+
/**
|
|
36
|
+
* All enabled site languages for building a language switcher.
|
|
37
|
+
*
|
|
38
|
+
* Includes default and untranslated languages
|
|
39
|
+
* (`translationAvailable: false`). Untranslated entries still include a URL
|
|
40
|
+
* that resolves to the fallback translation. Empty when the entity type does
|
|
41
|
+
* not support translation or the site is monolingual.
|
|
42
|
+
*/
|
|
43
|
+
translations: TranslationMetadata[];
|
|
44
|
+
}
|
|
45
|
+
interface TranslationMetadata {
|
|
46
|
+
langcode: string;
|
|
47
|
+
name: string;
|
|
48
|
+
nativeName: string;
|
|
49
|
+
url: string;
|
|
50
|
+
translationAvailable: boolean;
|
|
51
|
+
current: boolean;
|
|
52
|
+
}
|
|
53
|
+
interface PageData {
|
|
54
|
+
pageTitle: string;
|
|
55
|
+
breadcrumbs: Array<BreadcrumbLink>;
|
|
56
|
+
mainEntity: EntityMetadata | null;
|
|
57
|
+
}
|
|
58
|
+
interface ThemeAssets {
|
|
59
|
+
logo: {
|
|
60
|
+
url: string;
|
|
61
|
+
};
|
|
62
|
+
favicon: {
|
|
63
|
+
url: string;
|
|
64
|
+
mimeType: string;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
interface SiteData {
|
|
68
|
+
branding: {
|
|
69
|
+
homeUrl: string;
|
|
70
|
+
siteName: string;
|
|
71
|
+
siteSlogan: string;
|
|
72
|
+
};
|
|
73
|
+
baseUrl: string;
|
|
74
|
+
themeAssets: ThemeAssets;
|
|
75
|
+
}
|
|
76
|
+
declare const getPageData: () => PageData;
|
|
77
|
+
declare const getSiteData: () => SiteData;
|
|
78
|
+
//#endregion
|
|
2
79
|
export { getPageData, getSiteData, sortMenu };
|
package/dist/drupal-utils.js
CHANGED
|
@@ -1,3 +1,75 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/drupal-utils.ts
|
|
2
|
+
/**
|
|
3
|
+
* Sort menu items from core's menu API into a tree with additional
|
|
4
|
+
* _children and _hasSubmenu properties.
|
|
5
|
+
*
|
|
6
|
+
* @param linkset
|
|
7
|
+
*
|
|
8
|
+
* @return menuItems
|
|
9
|
+
*/
|
|
10
|
+
function sortMenu(linkset) {
|
|
11
|
+
const menuItemsMap = /* @__PURE__ */ new Map();
|
|
12
|
+
const menu = [];
|
|
13
|
+
if (!linkset.linkset?.length) return [];
|
|
14
|
+
linkset.linkset[0].item.forEach((item) => {
|
|
15
|
+
const hierarchyKey = item.hierarchy.join("|");
|
|
16
|
+
menuItemsMap.set(hierarchyKey, {
|
|
17
|
+
...item,
|
|
18
|
+
id: hierarchyKey,
|
|
19
|
+
_children: [],
|
|
20
|
+
_hasSubmenu: false
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
linkset.linkset[0].item.forEach((item) => {
|
|
24
|
+
const hierarchyKey = item.hierarchy.join("|");
|
|
25
|
+
const currentItem = menuItemsMap.get(hierarchyKey);
|
|
26
|
+
if (item.hierarchy.length === 1) menu.push(currentItem);
|
|
27
|
+
else {
|
|
28
|
+
const parentKey = item.hierarchy.slice(0, -1).join("|");
|
|
29
|
+
const parent = menuItemsMap.get(parentKey);
|
|
30
|
+
if (parent) {
|
|
31
|
+
parent._children.push(currentItem);
|
|
32
|
+
parent._hasSubmenu = true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return menu;
|
|
37
|
+
}
|
|
38
|
+
const getPageData = () => {
|
|
39
|
+
const pageData = {
|
|
40
|
+
pageTitle: globalThis?.drupalSettings?.canvasData?.v0?.pageTitle || "",
|
|
41
|
+
breadcrumbs: globalThis?.drupalSettings?.canvasData?.v0?.breadcrumbs || [],
|
|
42
|
+
mainEntity: globalThis?.drupalSettings?.canvasData?.v0?.mainEntity || null
|
|
43
|
+
};
|
|
44
|
+
globalThis?.window?.parent.postMessage({
|
|
45
|
+
type: "_canvas_useswr_data_fetch",
|
|
46
|
+
id: "getPageData()",
|
|
47
|
+
data: pageData
|
|
48
|
+
});
|
|
49
|
+
return pageData;
|
|
50
|
+
};
|
|
51
|
+
const getSiteData = () => {
|
|
52
|
+
const siteData = {
|
|
53
|
+
branding: globalThis?.drupalSettings?.canvasData?.v0?.branding || {
|
|
54
|
+
homeUrl: "",
|
|
55
|
+
siteName: "",
|
|
56
|
+
siteSlogan: ""
|
|
57
|
+
},
|
|
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
|
+
}
|
|
66
|
+
};
|
|
67
|
+
globalThis?.window?.parent.postMessage({
|
|
68
|
+
type: "_canvas_useswr_data_fetch",
|
|
69
|
+
id: "getSiteData()",
|
|
70
|
+
data: siteData
|
|
71
|
+
});
|
|
72
|
+
return siteData;
|
|
73
|
+
};
|
|
74
|
+
//#endregion
|
|
75
|
+
export { getPageData, getSiteData, sortMenu };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,29 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { t as CanvasJsonApiClient } from "./jsonapi-client-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import * as react_jsx_runtime1 from "react/jsx-runtime";
|
|
1
|
+
import FormattedText from "./FormattedText.js";
|
|
2
|
+
import { getPageData, getSiteData, sortMenu } from "./drupal-utils.js";
|
|
3
|
+
import { t as CanvasJsonApiClient } from "./jsonapi-client-Q84JvzCD.js";
|
|
4
|
+
import { getNodePath, sortMenu as sortMenu$1 } from "./jsonapi-utils.js";
|
|
5
|
+
import Image from "./next-image-standalone.js";
|
|
6
|
+
import { cn } from "./utils.js";
|
|
8
7
|
import { ReactNode } from "react";
|
|
9
|
-
|
|
10
8
|
//#region src/Region.d.ts
|
|
11
9
|
type RegionsMap = Record<string, ReactNode>;
|
|
12
10
|
type RegionsProviderProps = {
|
|
13
11
|
regions: RegionsMap;
|
|
14
12
|
children: ReactNode;
|
|
15
13
|
};
|
|
16
|
-
declare function RegionsProvider({
|
|
17
|
-
regions,
|
|
18
|
-
children
|
|
19
|
-
}: RegionsProviderProps): react_jsx_runtime1.JSX.Element;
|
|
14
|
+
declare function RegionsProvider({ regions, children }: RegionsProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
20
15
|
type RegionProps = {
|
|
21
16
|
name: string;
|
|
22
17
|
fallback?: ReactNode;
|
|
23
18
|
};
|
|
24
|
-
declare function Region({
|
|
25
|
-
name,
|
|
26
|
-
fallback
|
|
27
|
-
}: RegionProps): react_jsx_runtime1.JSX.Element;
|
|
19
|
+
declare function Region({ name, fallback }: RegionProps): import("react/jsx-runtime").JSX.Element;
|
|
28
20
|
//#endregion
|
|
29
21
|
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,12 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
1
|
+
import { getPageData, getSiteData, sortMenu } from "./drupal-utils.js";
|
|
2
|
+
import FormattedText from "./FormattedText.js";
|
|
3
|
+
import { JsonApiClient as CanvasJsonApiClient } from "./jsonapi-client.js";
|
|
4
|
+
import { getNodePath, sortMenu as sortMenu$1 } from "./jsonapi-utils.js";
|
|
5
|
+
import Image from "./next-image-standalone.js";
|
|
6
|
+
import { cn } from "./utils.js";
|
|
7
7
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
8
8
|
import { createContext, useContext } from "react";
|
|
9
|
-
|
|
10
9
|
//#region src/Region.tsx
|
|
11
10
|
const RegionsContext = createContext({});
|
|
12
11
|
function RegionsProvider({ regions, children }) {
|
|
@@ -19,6 +18,5 @@ function Region({ name, fallback = null }) {
|
|
|
19
18
|
const node = useContext(RegionsContext)[name];
|
|
20
19
|
return /* @__PURE__ */ jsx(Fragment, { children: node ?? fallback });
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
//#endregion
|
|
24
|
-
export { FormattedText, Image, CanvasJsonApiClient as JsonApiClient, Region, RegionsProvider, cn, getNodePath, getPageData, getSiteData, sortMenu as sortLinksetMenu, sortMenu$1 as sortMenu };
|
|
22
|
+
export { FormattedText, Image, CanvasJsonApiClient as JsonApiClient, Region, RegionsProvider, cn, getNodePath, getPageData, getSiteData, sortMenu as sortLinksetMenu, sortMenu$1 as sortMenu };
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { ComponentType } from "react";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import * as _json_render_core0 from "@json-render/core";
|
|
4
3
|
import { Spec } from "@json-render/core";
|
|
5
4
|
import { ComponentMetadata } from "@drupal-canvas/discovery";
|
|
6
|
-
|
|
7
5
|
//#region src/json-render-utils.d.ts
|
|
8
|
-
|
|
9
6
|
/**
|
|
10
7
|
* Drupal Canvas component tree node.
|
|
11
8
|
* @see canvas.component_tree_node in config/schema/canvas.schema.yml
|
|
@@ -93,27 +90,27 @@ declare function defineComponentRegistry(components: {
|
|
|
93
90
|
* @param metadata - Array of component metadata from `loadComponentsMetadata()`
|
|
94
91
|
* @returns A json-render `Catalog` instance
|
|
95
92
|
*/
|
|
96
|
-
declare function defineComponentCatalog(metadata: ComponentMetadata[]):
|
|
97
|
-
spec:
|
|
98
|
-
root:
|
|
99
|
-
elements:
|
|
100
|
-
type:
|
|
101
|
-
props:
|
|
102
|
-
children:
|
|
103
|
-
slots:
|
|
104
|
-
visible:
|
|
93
|
+
declare function defineComponentCatalog(metadata: ComponentMetadata[]): import("@json-render/core").Catalog<{
|
|
94
|
+
spec: import("@json-render/core").SchemaType<"object", {
|
|
95
|
+
root: import("@json-render/core").SchemaType<"string", unknown>;
|
|
96
|
+
elements: import("@json-render/core").SchemaType<"record", import("@json-render/core").SchemaType<"object", {
|
|
97
|
+
type: import("@json-render/core").SchemaType<"ref", string>;
|
|
98
|
+
props: import("@json-render/core").SchemaType<"propsOf", string>;
|
|
99
|
+
children: import("@json-render/core").SchemaType<"array", import("@json-render/core").SchemaType<"string", unknown>>;
|
|
100
|
+
slots: import("@json-render/core").SchemaType<"record", import("@json-render/core").SchemaType<"array", import("@json-render/core").SchemaType<"string", unknown>>>;
|
|
101
|
+
visible: import("@json-render/core").SchemaType<"any", unknown>;
|
|
105
102
|
}>>;
|
|
106
103
|
}>;
|
|
107
|
-
catalog:
|
|
108
|
-
components:
|
|
109
|
-
props:
|
|
110
|
-
slots:
|
|
111
|
-
description:
|
|
112
|
-
example:
|
|
104
|
+
catalog: import("@json-render/core").SchemaType<"object", {
|
|
105
|
+
components: import("@json-render/core").SchemaType<"map", {
|
|
106
|
+
props: import("@json-render/core").SchemaType<"zod", unknown>;
|
|
107
|
+
slots: import("@json-render/core").SchemaType<"array", import("@json-render/core").SchemaType<"string", unknown>>;
|
|
108
|
+
description: import("@json-render/core").SchemaType<"string", unknown>;
|
|
109
|
+
example: import("@json-render/core").SchemaType<"any", unknown>;
|
|
113
110
|
}>;
|
|
114
|
-
actions:
|
|
115
|
-
params:
|
|
116
|
-
description:
|
|
111
|
+
actions: import("@json-render/core").SchemaType<"map", {
|
|
112
|
+
params: import("@json-render/core").SchemaType<"zod", unknown>;
|
|
113
|
+
description: import("@json-render/core").SchemaType<"string", unknown>;
|
|
117
114
|
}>;
|
|
118
115
|
}>;
|
|
119
116
|
}, {
|
|
@@ -3,7 +3,6 @@ import { cloneElement, createElement, isValidElement } from "react";
|
|
|
3
3
|
import { fromJSONSchema, z } from "zod";
|
|
4
4
|
import { defineCatalog, resolveElementProps } from "@json-render/core";
|
|
5
5
|
import { schema } from "@json-render/react/schema";
|
|
6
|
-
|
|
7
6
|
//#region ../../schema.json
|
|
8
7
|
var $defs = {
|
|
9
8
|
"heading-element": {
|
|
@@ -356,7 +355,6 @@ var $defs = {
|
|
|
356
355
|
"pattern": "^[a-z0-9_\\.]+$"
|
|
357
356
|
}
|
|
358
357
|
};
|
|
359
|
-
|
|
360
358
|
//#endregion
|
|
361
359
|
//#region src/json-render-utils.tsx
|
|
362
360
|
/**
|
|
@@ -465,8 +463,7 @@ function specToCanvasTree(jsonRenderSpec) {
|
|
|
465
463
|
*/
|
|
466
464
|
function normalizeCanvasProps(value) {
|
|
467
465
|
if (!value || typeof value !== "object" || Array.isArray(value)) return value;
|
|
468
|
-
|
|
469
|
-
return Object.fromEntries(Object.entries(record).map(([key, item]) => {
|
|
466
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => {
|
|
470
467
|
if (!item || typeof item !== "object" || Array.isArray(item)) return [key, item];
|
|
471
468
|
const nestedRecord = item;
|
|
472
469
|
const nestedKeys = Object.keys(nestedRecord);
|
|
@@ -677,6 +674,5 @@ function defineComponentCatalog(metadata) {
|
|
|
677
674
|
};
|
|
678
675
|
} });
|
|
679
676
|
}
|
|
680
|
-
|
|
681
677
|
//#endregion
|
|
682
|
-
export { canvasTreeToSpec, defineComponentCatalog, defineComponentRegistry, renderCanvasTree, renderSpec, specToCanvasTree };
|
|
678
|
+
export { canvasTreeToSpec, defineComponentCatalog, defineComponentRegistry, renderCanvasTree, renderSpec, specToCanvasTree };
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { JsonApiClient, JsonApiClientOptions } from "@drupal-api-client/json-api-client";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
//#region ../../node_modules/@drupal-api-client/api-client/dist/index.d.mts
|
|
3
|
+
/**
|
|
4
|
+
* The base URL for all API requests.
|
|
5
|
+
*/
|
|
6
|
+
type BaseUrl = string;
|
|
7
|
+
//#endregion
|
|
4
8
|
//#region src/jsonapi-client.d.ts
|
|
5
9
|
declare class CanvasJsonApiClient extends JsonApiClient {
|
|
6
10
|
constructor(baseUrl?: BaseUrl, options?: JsonApiClientOptions);
|
package/dist/jsonapi-client.d.ts
CHANGED
package/dist/jsonapi-client.js
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { DefaultSerializer, JsonApiClient } from "@drupal-api-client/json-api-client";
|
|
2
|
+
export * from "@drupal-api-client/json-api-client";
|
|
3
|
+
//#region src/jsonapi-client.ts
|
|
4
|
+
var CanvasJsonApiClient = class extends JsonApiClient {
|
|
5
|
+
constructor(baseUrl, options) {
|
|
6
|
+
if (globalThis?.drupalSettings?.canvasData?.v0?.jsonapiSettings === null) throw new Error("The JSON:API module is not installed. Please install it to use JsonApiClient.");
|
|
7
|
+
const clientBaseUrl = baseUrl || globalThis?.drupalSettings?.canvasData?.v0?.baseUrl;
|
|
8
|
+
if (!baseUrl && !clientBaseUrl) throw new Error("Could not determine your site's base URL for the JSON:API client. If working outside of Drupal Canvas, you can use the @drupal-canvas/vite-plugin to automatically configure it for you. Otherwise you must explicitly provide a base URL, i.e. `const client = new JsonApiClient(\"https://...\")`");
|
|
9
|
+
const clientOptions = {
|
|
10
|
+
apiPrefix: globalThis?.drupalSettings?.canvasData?.v0?.jsonapiSettings?.apiPrefix,
|
|
11
|
+
serializer: new DefaultSerializer(),
|
|
12
|
+
...options
|
|
13
|
+
};
|
|
14
|
+
super(clientBaseUrl, clientOptions);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { CanvasJsonApiClient as JsonApiClient };
|
package/dist/jsonapi-utils.d.ts
CHANGED
|
@@ -1,2 +1,33 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/jsonapi-utils.d.ts
|
|
2
|
+
interface Node {
|
|
3
|
+
path?: {
|
|
4
|
+
alias?: string;
|
|
5
|
+
};
|
|
6
|
+
drupal_internal__nid?: number;
|
|
7
|
+
}
|
|
8
|
+
interface MenuItem {
|
|
9
|
+
id: string | number;
|
|
10
|
+
parent?: string | number;
|
|
11
|
+
_children?: MenuItem[];
|
|
12
|
+
_hasSubmenu: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Given a node returned from JSON:API, return either the path alias or fall back
|
|
16
|
+
* to /node/x path.
|
|
17
|
+
*
|
|
18
|
+
* @param node
|
|
19
|
+
*
|
|
20
|
+
* @return string
|
|
21
|
+
*/
|
|
22
|
+
declare function getNodePath(node: Node): string;
|
|
23
|
+
/**
|
|
24
|
+
* Sort menu items from jsonapi_menu_items module into a tree with additional
|
|
25
|
+
* _children and _hasSubmenu properties.
|
|
26
|
+
*
|
|
27
|
+
* @param menuItems
|
|
28
|
+
*
|
|
29
|
+
* @return menuItems
|
|
30
|
+
*/
|
|
31
|
+
declare function sortMenu(menuItems: MenuItem[]): MenuItem[];
|
|
32
|
+
//#endregion
|
|
2
33
|
export { getNodePath, sortMenu };
|
package/dist/jsonapi-utils.js
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/jsonapi-utils.ts
|
|
2
|
+
/**
|
|
3
|
+
* Given a node returned from JSON:API, return either the path alias or fall back
|
|
4
|
+
* to /node/x path.
|
|
5
|
+
*
|
|
6
|
+
* @param node
|
|
7
|
+
*
|
|
8
|
+
* @return string
|
|
9
|
+
*/
|
|
10
|
+
function getNodePath(node) {
|
|
11
|
+
return node.path?.alias || (node.drupal_internal__nid ? `/node/${node.drupal_internal__nid}` : "#");
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Sort menu items from jsonapi_menu_items module into a tree with additional
|
|
15
|
+
* _children and _hasSubmenu properties.
|
|
16
|
+
*
|
|
17
|
+
* @param menuItems
|
|
18
|
+
*
|
|
19
|
+
* @return menuItems
|
|
20
|
+
*/
|
|
21
|
+
function sortMenu(menuItems) {
|
|
22
|
+
const menuItemsMap = /* @__PURE__ */ new Map();
|
|
23
|
+
const menu = [];
|
|
24
|
+
menuItems.forEach((menuItem) => {
|
|
25
|
+
menuItemsMap.set(menuItem.id, {
|
|
26
|
+
...menuItem,
|
|
27
|
+
_children: [],
|
|
28
|
+
_hasSubmenu: false
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
menuItems.forEach((menuItem) => {
|
|
32
|
+
const node = menuItemsMap.get(menuItem.id);
|
|
33
|
+
if (menuItem.parent && menuItemsMap.has(menuItem.parent)) {
|
|
34
|
+
const parent = menuItemsMap.get(menuItem.parent);
|
|
35
|
+
parent._children.push(node);
|
|
36
|
+
parent._hasSubmenu = true;
|
|
37
|
+
} else menu.push(node);
|
|
38
|
+
});
|
|
39
|
+
return menu;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { getNodePath, sortMenu };
|
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ImageLoaderParams, ImageProps } from "next-image-standalone";
|
|
2
|
+
//#region src/next-image-standalone.d.ts
|
|
3
|
+
declare function Image(props: Omit<ImageProps, 'loader'> & {
|
|
4
|
+
loader?: (params: ImageLoaderParams) => string;
|
|
5
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
//#endregion
|
|
2
7
|
export { Image as default };
|
|
@@ -1,3 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import NextImage from "next-image-standalone";
|
|
3
|
+
//#region src/next-image-standalone.tsx
|
|
4
|
+
function Image(props) {
|
|
5
|
+
const { src, loader } = props;
|
|
6
|
+
const srcString = typeof src === "string" ? src : "default" in src ? src.default.src : src.src;
|
|
7
|
+
if (!loader) {
|
|
8
|
+
const defaultLoader = ({ width, imageProps }) => {
|
|
9
|
+
try {
|
|
10
|
+
let result = new URL(srcString, "https://example.com").searchParams.get("alternateWidths");
|
|
11
|
+
if (!result) throw new Error("Responsive image generation requires an `alternateWidths` query parameter in the image URL.");
|
|
12
|
+
result = result.replace("{width}", width.toString());
|
|
13
|
+
if (result.includes("{height}")) {
|
|
14
|
+
const intrinsicWidth = Number(imageProps.width);
|
|
15
|
+
const intrinsicHeight = Number(imageProps.height);
|
|
16
|
+
if (!intrinsicWidth || !intrinsicHeight) throw new Error("Height calculation requires intrinsic image dimensions.");
|
|
17
|
+
const height = Math.round(width / (intrinsicWidth / intrinsicHeight));
|
|
18
|
+
result = result.replace("{height}", height.toString());
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
console.error("Responsive image generation failed. To fix this:\n1. Provide a custom `loader` function, or\n2. Ensure your image `src` includes an `alternateWidths` query parameter\n Example: ?alternateWidths=/path/to/responsive/{width}/image.jpg", {
|
|
23
|
+
src,
|
|
24
|
+
error
|
|
25
|
+
});
|
|
26
|
+
return srcString;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
return /* @__PURE__ */ jsx(NextImage, {
|
|
30
|
+
...props,
|
|
31
|
+
loader: defaultLoader,
|
|
32
|
+
sizes: props.sizes || "auto 100vw"
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return /* @__PURE__ */ jsx(NextImage, {
|
|
36
|
+
...props,
|
|
37
|
+
loader,
|
|
38
|
+
sizes: props.sizes || "auto 100vw"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { Image as default };
|
package/dist/utils.d.ts
CHANGED
package/dist/utils.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { clsx } from "clsx";
|
|
2
|
+
import { twMerge } from "tailwind-merge";
|
|
3
|
+
//#region src/utils.ts
|
|
4
|
+
function cn(...inputs) {
|
|
5
|
+
return twMerge(clsx(inputs));
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { cn };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drupal-canvas",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "Utilities and base components for building Drupal Canvas Code Components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -13,35 +13,43 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
".": {
|
|
15
15
|
"import": "./dist/index.js",
|
|
16
|
-
"types": "./dist/index.d.ts"
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
17
18
|
},
|
|
18
19
|
"./json-render-utils": {
|
|
19
20
|
"import": "./dist/json-render-utils.js",
|
|
20
|
-
"types": "./dist/json-render-utils.d.ts"
|
|
21
|
+
"types": "./dist/json-render-utils.d.ts",
|
|
22
|
+
"default": "./dist/json-render-utils.js"
|
|
21
23
|
},
|
|
22
24
|
"./FormattedText": {
|
|
23
25
|
"import": "./dist/FormattedText.js",
|
|
24
|
-
"types": "./dist/FormattedText.d.ts"
|
|
26
|
+
"types": "./dist/FormattedText.d.ts",
|
|
27
|
+
"default": "./dist/FormattedText.js"
|
|
25
28
|
},
|
|
26
29
|
"./drupal-utils": {
|
|
27
30
|
"import": "./dist/drupal-utils.js",
|
|
28
|
-
"types": "./dist/drupal-utils.d.ts"
|
|
31
|
+
"types": "./dist/drupal-utils.d.ts",
|
|
32
|
+
"default": "./dist/drupal-utils.js"
|
|
29
33
|
},
|
|
30
34
|
"./jsonapi-client": {
|
|
31
35
|
"import": "./dist/jsonapi-client.js",
|
|
32
|
-
"types": "./dist/jsonapi-client.d.ts"
|
|
36
|
+
"types": "./dist/jsonapi-client.d.ts",
|
|
37
|
+
"default": "./dist/jsonapi-client.js"
|
|
33
38
|
},
|
|
34
39
|
"./jsonapi-utils": {
|
|
35
40
|
"import": "./dist/jsonapi-utils.js",
|
|
36
|
-
"types": "./dist/jsonapi-utils.d.ts"
|
|
41
|
+
"types": "./dist/jsonapi-utils.d.ts",
|
|
42
|
+
"default": "./dist/jsonapi-utils.js"
|
|
37
43
|
},
|
|
38
44
|
"./next-image-standalone": {
|
|
39
45
|
"import": "./dist/next-image-standalone.js",
|
|
40
|
-
"types": "./dist/next-image-standalone.d.ts"
|
|
46
|
+
"types": "./dist/next-image-standalone.d.ts",
|
|
47
|
+
"default": "./dist/next-image-standalone.js"
|
|
41
48
|
},
|
|
42
49
|
"./utils": {
|
|
43
50
|
"import": "./dist/utils.js",
|
|
44
|
-
"types": "./dist/utils.d.ts"
|
|
51
|
+
"types": "./dist/utils.d.ts",
|
|
52
|
+
"default": "./dist/utils.js"
|
|
45
53
|
}
|
|
46
54
|
},
|
|
47
55
|
"type": "module",
|
|
@@ -64,7 +72,7 @@
|
|
|
64
72
|
"zod": "^4.2.0"
|
|
65
73
|
},
|
|
66
74
|
"devDependencies": {
|
|
67
|
-
"tsdown": "^0.
|
|
75
|
+
"tsdown": "^0.22.12",
|
|
68
76
|
"typescript": "^5.9.3",
|
|
69
77
|
"vitest": "^4.1.8"
|
|
70
78
|
},
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
//#region src/FormattedText.tsx
|
|
4
|
-
function FormattedText({ children, as = "div", ...props }) {
|
|
5
|
-
return /* @__PURE__ */ jsx(as, {
|
|
6
|
-
dangerouslySetInnerHTML: { __html: children },
|
|
7
|
-
...props
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
export { FormattedText as t };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
-
|
|
3
|
-
//#region src/FormattedText.d.ts
|
|
4
|
-
type FormattedTextProps = {
|
|
5
|
-
children: string;
|
|
6
|
-
as?: 'div' | 'span';
|
|
7
|
-
className?: string;
|
|
8
|
-
id?: string;
|
|
9
|
-
style?: Record<string, string>;
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
};
|
|
12
|
-
declare function FormattedText({
|
|
13
|
-
children,
|
|
14
|
-
as,
|
|
15
|
-
...props
|
|
16
|
-
}: FormattedTextProps): react_jsx_runtime0.JSX.Element;
|
|
17
|
-
//#endregion
|
|
18
|
-
export { FormattedText as t };
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
//#region src/drupal-utils.ts
|
|
2
|
-
/**
|
|
3
|
-
* Sort menu items from core's menu API into a tree with additional
|
|
4
|
-
* _children and _hasSubmenu properties.
|
|
5
|
-
*
|
|
6
|
-
* @param linkset
|
|
7
|
-
*
|
|
8
|
-
* @return menuItems
|
|
9
|
-
*/
|
|
10
|
-
function sortMenu(linkset) {
|
|
11
|
-
const menuItemsMap = /* @__PURE__ */ new Map();
|
|
12
|
-
const menu = [];
|
|
13
|
-
if (!linkset.linkset?.length) return [];
|
|
14
|
-
linkset.linkset[0].item.forEach((item) => {
|
|
15
|
-
const hierarchyKey = item.hierarchy.join("|");
|
|
16
|
-
menuItemsMap.set(hierarchyKey, {
|
|
17
|
-
...item,
|
|
18
|
-
id: hierarchyKey,
|
|
19
|
-
_children: [],
|
|
20
|
-
_hasSubmenu: false
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
linkset.linkset[0].item.forEach((item) => {
|
|
24
|
-
const hierarchyKey = item.hierarchy.join("|");
|
|
25
|
-
const currentItem = menuItemsMap.get(hierarchyKey);
|
|
26
|
-
if (item.hierarchy.length === 1) menu.push(currentItem);
|
|
27
|
-
else {
|
|
28
|
-
const parentKey = item.hierarchy.slice(0, -1).join("|");
|
|
29
|
-
const parent = menuItemsMap.get(parentKey);
|
|
30
|
-
if (parent) {
|
|
31
|
-
parent._children.push(currentItem);
|
|
32
|
-
parent._hasSubmenu = true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
return menu;
|
|
37
|
-
}
|
|
38
|
-
const getPageData = () => {
|
|
39
|
-
const pageData = {
|
|
40
|
-
pageTitle: globalThis?.drupalSettings?.canvasData?.v0?.pageTitle || "",
|
|
41
|
-
breadcrumbs: globalThis?.drupalSettings?.canvasData?.v0?.breadcrumbs || [],
|
|
42
|
-
mainEntity: globalThis?.drupalSettings?.canvasData?.v0?.mainEntity || null
|
|
43
|
-
};
|
|
44
|
-
globalThis?.window?.parent.postMessage({
|
|
45
|
-
type: "_canvas_useswr_data_fetch",
|
|
46
|
-
id: "getPageData()",
|
|
47
|
-
data: pageData
|
|
48
|
-
});
|
|
49
|
-
return pageData;
|
|
50
|
-
};
|
|
51
|
-
const getSiteData = () => {
|
|
52
|
-
const siteData = {
|
|
53
|
-
branding: globalThis?.drupalSettings?.canvasData?.v0?.branding || {
|
|
54
|
-
homeUrl: "",
|
|
55
|
-
siteName: "",
|
|
56
|
-
siteSlogan: ""
|
|
57
|
-
},
|
|
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
|
-
}
|
|
66
|
-
};
|
|
67
|
-
globalThis?.window?.parent.postMessage({
|
|
68
|
-
type: "_canvas_useswr_data_fetch",
|
|
69
|
-
id: "getSiteData()",
|
|
70
|
-
data: siteData
|
|
71
|
-
});
|
|
72
|
-
return siteData;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
//#endregion
|
|
76
|
-
export { getSiteData as n, sortMenu as r, getPageData as t };
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
//#region src/drupal-utils.d.ts
|
|
2
|
-
interface Linkset {
|
|
3
|
-
linkset: LinksetItem[];
|
|
4
|
-
}
|
|
5
|
-
interface LinksetItem {
|
|
6
|
-
anchor: string;
|
|
7
|
-
item: LinksetMenuItem[];
|
|
8
|
-
}
|
|
9
|
-
interface LinksetMenuItem {
|
|
10
|
-
href: string;
|
|
11
|
-
hierarchy: string[];
|
|
12
|
-
_children?: LinksetMenuItem[];
|
|
13
|
-
_hasSubmenu: boolean;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Sort menu items from core's menu API into a tree with additional
|
|
17
|
-
* _children and _hasSubmenu properties.
|
|
18
|
-
*
|
|
19
|
-
* @param linkset
|
|
20
|
-
*
|
|
21
|
-
* @return menuItems
|
|
22
|
-
*/
|
|
23
|
-
declare function sortMenu(linkset: Linkset): LinksetMenuItem[];
|
|
24
|
-
interface BreadcrumbLink {
|
|
25
|
-
key: string;
|
|
26
|
-
text: string;
|
|
27
|
-
url: string;
|
|
28
|
-
}
|
|
29
|
-
interface EntityMetadata {
|
|
30
|
-
bundle: string;
|
|
31
|
-
entityTypeId: string;
|
|
32
|
-
uuid: string;
|
|
33
|
-
}
|
|
34
|
-
interface PageData {
|
|
35
|
-
pageTitle: string;
|
|
36
|
-
breadcrumbs: Array<BreadcrumbLink>;
|
|
37
|
-
mainEntity: EntityMetadata | null;
|
|
38
|
-
}
|
|
39
|
-
interface ThemeAssets {
|
|
40
|
-
logo: {
|
|
41
|
-
url: string;
|
|
42
|
-
};
|
|
43
|
-
favicon: {
|
|
44
|
-
url: string;
|
|
45
|
-
mimeType: string;
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
interface SiteData {
|
|
49
|
-
branding: {
|
|
50
|
-
homeUrl: string;
|
|
51
|
-
siteName: string;
|
|
52
|
-
siteSlogan: string;
|
|
53
|
-
};
|
|
54
|
-
baseUrl: string;
|
|
55
|
-
themeAssets: ThemeAssets;
|
|
56
|
-
}
|
|
57
|
-
declare const getPageData: () => PageData;
|
|
58
|
-
declare const getSiteData: () => SiteData;
|
|
59
|
-
//#endregion
|
|
60
|
-
export { getSiteData as n, sortMenu as r, getPageData as t };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { DefaultSerializer, JsonApiClient } from "@drupal-api-client/json-api-client";
|
|
2
|
-
|
|
3
|
-
//#region src/jsonapi-client.ts
|
|
4
|
-
var CanvasJsonApiClient = class extends JsonApiClient {
|
|
5
|
-
constructor(baseUrl, options) {
|
|
6
|
-
if (globalThis?.drupalSettings?.canvasData?.v0?.jsonapiSettings === null) throw new Error("The JSON:API module is not installed. Please install it to use JsonApiClient.");
|
|
7
|
-
const clientBaseUrl = baseUrl || globalThis?.drupalSettings?.canvasData?.v0?.baseUrl;
|
|
8
|
-
if (!baseUrl && !clientBaseUrl) throw new Error("Could not determine your site's base URL for the JSON:API client. If working outside of Drupal Canvas, you can use the @drupal-canvas/vite-plugin to automatically configure it for you. Otherwise you must explicitly provide a base URL, i.e. `const client = new JsonApiClient(\"https://...\")`");
|
|
9
|
-
const clientOptions = {
|
|
10
|
-
apiPrefix: globalThis?.drupalSettings?.canvasData?.v0?.jsonapiSettings?.apiPrefix,
|
|
11
|
-
serializer: new DefaultSerializer(),
|
|
12
|
-
...options
|
|
13
|
-
};
|
|
14
|
-
super(clientBaseUrl, clientOptions);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
//#endregion
|
|
19
|
-
export { CanvasJsonApiClient as t };
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
//#region src/jsonapi-utils.ts
|
|
2
|
-
/**
|
|
3
|
-
* Given a node returned from JSON:API, return either the path alias or fall back
|
|
4
|
-
* to /node/x path.
|
|
5
|
-
*
|
|
6
|
-
* @param node
|
|
7
|
-
*
|
|
8
|
-
* @return string
|
|
9
|
-
*/
|
|
10
|
-
function getNodePath(node) {
|
|
11
|
-
return node.path?.alias || (node.drupal_internal__nid ? `/node/${node.drupal_internal__nid}` : "#");
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* Sort menu items from jsonapi_menu_items module into a tree with additional
|
|
15
|
-
* _children and _hasSubmenu properties.
|
|
16
|
-
*
|
|
17
|
-
* @param menuItems
|
|
18
|
-
*
|
|
19
|
-
* @return menuItems
|
|
20
|
-
*/
|
|
21
|
-
function sortMenu(menuItems) {
|
|
22
|
-
const menuItemsMap = /* @__PURE__ */ new Map();
|
|
23
|
-
const menu = [];
|
|
24
|
-
menuItems.forEach((menuItem) => {
|
|
25
|
-
menuItemsMap.set(menuItem.id, {
|
|
26
|
-
...menuItem,
|
|
27
|
-
_children: [],
|
|
28
|
-
_hasSubmenu: false
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
menuItems.forEach((menuItem) => {
|
|
32
|
-
const node = menuItemsMap.get(menuItem.id);
|
|
33
|
-
if (menuItem.parent && menuItemsMap.has(menuItem.parent)) {
|
|
34
|
-
const parent = menuItemsMap.get(menuItem.parent);
|
|
35
|
-
parent._children.push(node);
|
|
36
|
-
parent._hasSubmenu = true;
|
|
37
|
-
} else menu.push(node);
|
|
38
|
-
});
|
|
39
|
-
return menu;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
|
-
export { sortMenu as n, getNodePath as t };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
//#region src/jsonapi-utils.d.ts
|
|
2
|
-
interface Node {
|
|
3
|
-
path?: {
|
|
4
|
-
alias?: string;
|
|
5
|
-
};
|
|
6
|
-
drupal_internal__nid?: number;
|
|
7
|
-
}
|
|
8
|
-
interface MenuItem {
|
|
9
|
-
id: string | number;
|
|
10
|
-
parent?: string | number;
|
|
11
|
-
_children?: MenuItem[];
|
|
12
|
-
_hasSubmenu: boolean;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Given a node returned from JSON:API, return either the path alias or fall back
|
|
16
|
-
* to /node/x path.
|
|
17
|
-
*
|
|
18
|
-
* @param node
|
|
19
|
-
*
|
|
20
|
-
* @return string
|
|
21
|
-
*/
|
|
22
|
-
declare function getNodePath(node: Node): string;
|
|
23
|
-
/**
|
|
24
|
-
* Sort menu items from jsonapi_menu_items module into a tree with additional
|
|
25
|
-
* _children and _hasSubmenu properties.
|
|
26
|
-
*
|
|
27
|
-
* @param menuItems
|
|
28
|
-
*
|
|
29
|
-
* @return menuItems
|
|
30
|
-
*/
|
|
31
|
-
declare function sortMenu(menuItems: MenuItem[]): MenuItem[];
|
|
32
|
-
//#endregion
|
|
33
|
-
export { sortMenu as n, getNodePath as t };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import NextImage from "next-image-standalone";
|
|
3
|
-
|
|
4
|
-
//#region src/next-image-standalone.tsx
|
|
5
|
-
function Image(props) {
|
|
6
|
-
const { src, loader } = props;
|
|
7
|
-
if (!loader) {
|
|
8
|
-
const defaultLoader = ({ width, imageProps }) => {
|
|
9
|
-
try {
|
|
10
|
-
let result = new URL(src, "https://example.com").searchParams.get("alternateWidths");
|
|
11
|
-
if (!result) throw new Error("Responsive image generation requires an `alternateWidths` query parameter in the image URL.");
|
|
12
|
-
result = result.replace("{width}", width.toString());
|
|
13
|
-
if (result.includes("{height}")) {
|
|
14
|
-
const { width: intrinsicWidth, height: intrinsicHeight } = imageProps;
|
|
15
|
-
const height = Math.round(width / (intrinsicWidth / intrinsicHeight));
|
|
16
|
-
result = result.replace("{height}", height.toString());
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
console.error("Responsive image generation failed. To fix this:\n1. Provide a custom `loader` function, or\n2. Ensure your image `src` includes an `alternateWidths` query parameter\n Example: ?alternateWidths=/path/to/responsive/{width}/image.jpg", {
|
|
21
|
-
src,
|
|
22
|
-
error
|
|
23
|
-
});
|
|
24
|
-
return src;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
return /* @__PURE__ */ jsx(NextImage, {
|
|
28
|
-
...props,
|
|
29
|
-
loader: defaultLoader,
|
|
30
|
-
sizes: props.sizes || "auto 100vw"
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return /* @__PURE__ */ jsx(NextImage, {
|
|
34
|
-
...props,
|
|
35
|
-
loader,
|
|
36
|
-
sizes: props.sizes || "auto 100vw"
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
export { Image as t };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
2
|
-
import { ImageLoaderParams, ImageProps } from "next-image-standalone";
|
|
3
|
-
|
|
4
|
-
//#region src/next-image-standalone.d.ts
|
|
5
|
-
declare function Image(props: Omit<ImageProps, 'loader'> & {
|
|
6
|
-
loader?: (params: ImageLoaderParams) => string;
|
|
7
|
-
}): react_jsx_runtime0.JSX.Element;
|
|
8
|
-
//#endregion
|
|
9
|
-
export { Image as t };
|
package/dist/utils-DuVWmMX9.js
DELETED