drupal-canvas 0.6.0 → 0.7.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 +177 -45
- package/dist/context-Cb4HbPbR.d.ts +32 -0
- package/dist/drupal-utils-CUaK4jOk.d.ts +117 -0
- package/dist/drupal-utils.d.ts +2 -79
- package/dist/drupal-utils.js +23 -0
- package/dist/index.d.ts +101 -87
- package/dist/index.js +68 -134
- package/dist/json-render-utils.d.ts +3 -3
- package/dist/jsonapi-client-BAQ3V5CC.d.ts +329 -0
- package/dist/jsonapi-client-CejP62bM.js +539 -0
- package/dist/jsonapi-client.d.ts +2 -2
- package/dist/jsonapi-client.js +2 -17
- package/dist/migration-CPBzW78_.js +63 -0
- package/dist/react.d.ts +25 -0
- package/dist/react.js +158 -0
- package/package.json +11 -1
- package/dist/jsonapi-client-Q84JvzCD.d.ts +0 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,105 +1,75 @@
|
|
|
1
1
|
import FormattedText from "./FormattedText.js";
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import { a as ThemeAssets, c as getSiteData, d as PageContext, f as SiteContext, i as SiteData, l as sortMenu, n as EntityMetadata, o as TranslationMetadata, r as PageData, s as getPageData, t as BreadcrumbLink, u as CanvasContext } from "./drupal-utils-CUaK4jOk.js";
|
|
3
|
+
import "./context-Cb4HbPbR.js";
|
|
4
|
+
import { a as LegacyJsonApiClient, i as JsonApiRuntimeConfig, n as DraftSessionError, o as createJsonApiClient, r as JsonApiClientConfig, s as isDraftSessionError, t as CanvasJsonApiClient } from "./jsonapi-client-BAQ3V5CC.js";
|
|
4
5
|
import { getNodePath, sortMenu as sortMenu$1 } from "./jsonapi-utils.js";
|
|
5
6
|
import Image from "./next-image-standalone.js";
|
|
6
7
|
import { cn } from "./utils.js";
|
|
7
8
|
import { ReactNode } from "react";
|
|
8
|
-
//#region src/
|
|
9
|
+
//#region src/drupal-settings.d.ts
|
|
10
|
+
/** The subset of `drupalSettings.canvasData.v0` the context API reads. */
|
|
11
|
+
interface CanvasDataV0 {
|
|
12
|
+
pageTitle?: string | null;
|
|
13
|
+
breadcrumbs?: CanvasContext['page'] extends (infer P) ? P extends {
|
|
14
|
+
breadcrumbs: infer B;
|
|
15
|
+
} ? B | null : never : never;
|
|
16
|
+
mainEntity?: NonNullable<CanvasContext['page']>['mainEntity'];
|
|
17
|
+
branding?: NonNullable<CanvasContext['site']>['branding'] | null;
|
|
18
|
+
baseUrl?: string | null;
|
|
19
|
+
themeAssets?: NonNullable<CanvasContext['site']>['themeAssets'] | null;
|
|
20
|
+
jsonapiSettings?: {
|
|
21
|
+
apiPrefix?: string;
|
|
22
|
+
} | null;
|
|
23
|
+
}
|
|
24
|
+
interface DrupalSettingsLike {
|
|
25
|
+
canvasData?: {
|
|
26
|
+
v0?: CanvasDataV0 | null;
|
|
27
|
+
} | null;
|
|
28
|
+
}
|
|
29
|
+
/** Reads `drupalSettings.canvasData.v0` from a settings object or the global. */
|
|
30
|
+
declare function readCanvasDataV0(settings?: DrupalSettingsLike | undefined): CanvasDataV0 | null;
|
|
9
31
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* These functions format ISO date/time strings using the Drupal-selected
|
|
13
|
-
* langcode from `drupalSettings.canvasData.v0.langcode`. They are opt-in: Canvas passes date
|
|
14
|
-
* props to templates as raw ISO strings by default. Use these utilities when
|
|
15
|
-
* you want to display a date in the user's locale.
|
|
32
|
+
* Builds the page and site context from `drupalSettings.canvasData.v0`.
|
|
16
33
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @example Twig: `{{ my_date_prop|canvasFormatDate }}`
|
|
22
|
-
* @example JSX: `canvasFormatDate(myDateProp)`
|
|
23
|
-
* @example JSX with options: `canvasFormatDate(myDateProp, { dateStyle: 'long' })`
|
|
34
|
+
* Page context is available when Drupal attached any page-level key
|
|
35
|
+
* (`pageTitle`, `breadcrumbs`, or `mainEntity`); site context when it attached
|
|
36
|
+
* `branding`. Missing keys inside an available group take the same defaults
|
|
37
|
+
* as the legacy getters.
|
|
24
38
|
*/
|
|
39
|
+
declare function drupalSettingsToCanvasContext(v0: CanvasDataV0 | null | undefined): CanvasContext;
|
|
25
40
|
/**
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
* guard.
|
|
41
|
+
* Builds the JSON:API runtime configuration for a Drupal-rendered page from
|
|
42
|
+
* `drupalSettings.canvasData.v0`, or `null` when the settings do not carry a
|
|
43
|
+
* base URL or JSON:API is not installed. Previews read working copies through
|
|
44
|
+
* the editor's Drupal session.
|
|
31
45
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
46
|
+
declare function drupalSettingsToJsonApiRuntimeConfig(v0: CanvasDataV0 | null | undefined, options?: {
|
|
47
|
+
preview?: boolean;
|
|
48
|
+
}): JsonApiRuntimeConfig | null;
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/migration.d.ts
|
|
38
51
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* empty string for `null` or `undefined` (an optional prop without a value).
|
|
43
|
-
*
|
|
44
|
-
* @param iso
|
|
45
|
-
* ISO date string, e.g. '2026-01-15'.
|
|
46
|
-
* @param options
|
|
47
|
-
* Optional format overrides. Defaults to `{ dateStyle: 'short' }`.
|
|
48
|
-
*
|
|
49
|
-
* @return
|
|
50
|
-
* Locale-formatted date string, e.g. '1/15/26' (en) or '15/01/2026' (fr).
|
|
52
|
+
* @file
|
|
53
|
+
* Migration guidance shared by the legacy API errors, the hook warnings, and
|
|
54
|
+
* the Canvas CLI's pull codemod report.
|
|
51
55
|
*/
|
|
52
|
-
declare function canvasFormatDate(iso: string | null | undefined, options?: Pick<CanvasDateFormatOptions, 'dateStyle'>): string;
|
|
53
56
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* Returns the original `iso` string unchanged if it cannot be parsed, and an
|
|
57
|
-
* empty string for `null` or `undefined` (an optional prop without a value).
|
|
58
|
-
*
|
|
59
|
-
* @param iso
|
|
60
|
-
* ISO datetime string, e.g. '2026-01-15T14:30:00Z'.
|
|
61
|
-
* @param options
|
|
62
|
-
* Optional format overrides. Defaults to
|
|
63
|
-
* `{ dateStyle: 'short', timeStyle: 'short' }`.
|
|
64
|
-
*
|
|
65
|
-
* @return
|
|
66
|
-
* Locale-formatted datetime string.
|
|
57
|
+
* The AI-agent migration prompt included in legacy API errors and printed by
|
|
58
|
+
* the Canvas CLI for components it could not migrate automatically.
|
|
67
59
|
*/
|
|
68
|
-
declare
|
|
60
|
+
declare const AGENT_MIGRATION_PROMPT: string;
|
|
61
|
+
/** Replacement guidance per legacy API. */
|
|
62
|
+
declare const LEGACY_API_GUIDANCE: {
|
|
63
|
+
readonly 'getPageData()': string;
|
|
64
|
+
readonly 'getSiteData()': string;
|
|
65
|
+
readonly 'new JsonApiClient()': string;
|
|
66
|
+
};
|
|
67
|
+
type LegacyApiName = keyof typeof LEGACY_API_GUIDANCE;
|
|
69
68
|
/**
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* Returns the original `iso` string unchanged if it cannot be parsed, and an
|
|
73
|
-
* empty string for `null` or `undefined` (an optional prop without a value).
|
|
74
|
-
*
|
|
75
|
-
* @param iso
|
|
76
|
-
* ISO time or datetime string, e.g. '14:30:00' or '2026-01-15T14:30:00Z'.
|
|
77
|
-
* @param options
|
|
78
|
-
* Optional format overrides. Defaults to `{ timeStyle: 'short' }`.
|
|
79
|
-
*
|
|
80
|
-
* @return
|
|
81
|
-
* Locale-formatted time string.
|
|
69
|
+
* Builds the error message thrown when a legacy API is invoked outside Drupal
|
|
70
|
+
* and Workbench.
|
|
82
71
|
*/
|
|
83
|
-
declare function
|
|
84
|
-
/**
|
|
85
|
-
* Formats the `from` and `to` fields of a Canvas date-range prop.
|
|
86
|
-
*
|
|
87
|
-
* Returns `null` or `undefined` unchanged (an optional prop without a value).
|
|
88
|
-
*
|
|
89
|
-
* @param range
|
|
90
|
-
* Canvas date-range object, e.g. `{ from: '2026-01-15', to: '2026-03-20' }`.
|
|
91
|
-
* @param options
|
|
92
|
-
* Optional format overrides passed to each field. Defaults to
|
|
93
|
-
* `{ dateStyle: 'short' }`.
|
|
94
|
-
*
|
|
95
|
-
* @return
|
|
96
|
-
* A new object with the same keys; each string date value is replaced with a
|
|
97
|
-
* formatted string.
|
|
98
|
-
*/
|
|
99
|
-
declare function canvasFormatDateRange<T extends {
|
|
100
|
-
from?: string | null;
|
|
101
|
-
to?: string | null;
|
|
102
|
-
} | null | undefined>(range: T, options?: Pick<CanvasDateFormatOptions, 'dateStyle'>): T;
|
|
72
|
+
declare function formatLegacyApiError(api: LegacyApiName): string;
|
|
103
73
|
//#endregion
|
|
104
74
|
//#region src/Region.d.ts
|
|
105
75
|
type RegionsMap = Record<string, ReactNode>;
|
|
@@ -107,11 +77,55 @@ type RegionsProviderProps = {
|
|
|
107
77
|
regions: RegionsMap;
|
|
108
78
|
children: ReactNode;
|
|
109
79
|
};
|
|
80
|
+
/**
|
|
81
|
+
* Supplies the region node map read by `Region`.
|
|
82
|
+
*
|
|
83
|
+
* @deprecated Theme-global regions were replaced by page variants (ADR 19);
|
|
84
|
+
* compose pages with the component tree instead. Kept for compatibility.
|
|
85
|
+
*/
|
|
110
86
|
declare function RegionsProvider({ regions, children }: RegionsProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
111
87
|
type RegionProps = {
|
|
112
88
|
name: string;
|
|
113
89
|
fallback?: ReactNode;
|
|
114
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* Renders the region whose machine name matches `name`.
|
|
93
|
+
*
|
|
94
|
+
* @deprecated Theme-global regions were replaced by page variants (ADR 19);
|
|
95
|
+
* compose pages with the component tree instead. Kept for compatibility.
|
|
96
|
+
*/
|
|
115
97
|
declare function Region({ name, fallback }: RegionProps): import("react/jsx-runtime").JSX.Element;
|
|
116
98
|
//#endregion
|
|
117
|
-
|
|
99
|
+
//#region src/runtime.d.ts
|
|
100
|
+
/**
|
|
101
|
+
* @file
|
|
102
|
+
* The runtime marker that identifies the environments in which the legacy
|
|
103
|
+
* `getPageData()`, `getSiteData()`, and `new JsonApiClient()` APIs keep
|
|
104
|
+
* working: Drupal-rendered Code Components and Canvas Workbench previews.
|
|
105
|
+
*
|
|
106
|
+
* The marker is established explicitly by those integrations before any Code
|
|
107
|
+
* Component module is evaluated. It is a compatibility check, not a security
|
|
108
|
+
* boundary: the presence of `window`, a backend URL, or a user-created
|
|
109
|
+
* `drupalSettings` object is deliberately not treated as proof of either
|
|
110
|
+
* environment.
|
|
111
|
+
*
|
|
112
|
+
* @see docs/adr/0021-code-component-runtime-compatibility-across-frontend-modes.md
|
|
113
|
+
*/
|
|
114
|
+
/** The environments that support the legacy runtime APIs. */
|
|
115
|
+
type CanvasRuntimeEnvironment = 'drupal' | 'workbench';
|
|
116
|
+
/**
|
|
117
|
+
* Declares the current runtime environment. Called by Drupal and Workbench
|
|
118
|
+
* integrations, never by Code Components or headless applications.
|
|
119
|
+
*/
|
|
120
|
+
declare function declareCanvasRuntime(environment: CanvasRuntimeEnvironment): void;
|
|
121
|
+
/**
|
|
122
|
+
* Returns the declared runtime environment, or `null` outside Drupal and
|
|
123
|
+
* Workbench.
|
|
124
|
+
*/
|
|
125
|
+
declare function getCanvasRuntime(): CanvasRuntimeEnvironment | null;
|
|
126
|
+
/**
|
|
127
|
+
* Whether the legacy runtime APIs are supported in the current environment.
|
|
128
|
+
*/
|
|
129
|
+
declare function isLegacyRuntimeSupported(): boolean;
|
|
130
|
+
//#endregion
|
|
131
|
+
export { AGENT_MIGRATION_PROMPT, type BreadcrumbLink, type CanvasContext, type CanvasDataV0, type CanvasJsonApiClient, type CanvasRuntimeEnvironment, DraftSessionError, type EntityMetadata, FormattedText, Image, LegacyJsonApiClient as JsonApiClient, type JsonApiClientConfig, type JsonApiRuntimeConfig, LEGACY_API_GUIDANCE, type PageContext, type PageData, Region, RegionsProvider, type SiteContext, type SiteData, type ThemeAssets, type TranslationMetadata, cn, createJsonApiClient, declareCanvasRuntime, drupalSettingsToCanvasContext, drupalSettingsToJsonApiRuntimeConfig, formatLegacyApiError, getCanvasRuntime, getNodePath, getPageData, getSiteData, isDraftSessionError, isLegacyRuntimeSupported, readCanvasDataV0, sortMenu as sortLinksetMenu, sortMenu$1 as sortMenu };
|
package/dist/index.js
CHANGED
|
@@ -1,164 +1,98 @@
|
|
|
1
|
+
import { a as declareCanvasRuntime, i as formatLegacyApiError, n as LEGACY_API_GUIDANCE, o as getCanvasRuntime, s as isLegacyRuntimeSupported, t as AGENT_MIGRATION_PROMPT } from "./migration-CPBzW78_.js";
|
|
1
2
|
import { getPageData, getSiteData, sortMenu } from "./drupal-utils.js";
|
|
2
3
|
import FormattedText from "./FormattedText.js";
|
|
3
|
-
import {
|
|
4
|
+
import { a as isDraftSessionError, i as createJsonApiClient, n as DraftSessionError, r as LegacyJsonApiClient } from "./jsonapi-client-CejP62bM.js";
|
|
4
5
|
import { getNodePath, sortMenu as sortMenu$1 } from "./jsonapi-utils.js";
|
|
5
6
|
import Image from "./next-image-standalone.js";
|
|
6
7
|
import { cn } from "./utils.js";
|
|
7
8
|
import { Fragment, jsx } from "react/jsx-runtime";
|
|
8
9
|
import { createContext, useContext } from "react";
|
|
9
|
-
//#region src/
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
* @see ui/src/features/code-editor/utils/ast-utils.ts
|
|
21
|
-
*/
|
|
22
|
-
const getDrupalLangcode = () => globalThis.drupalSettings?.canvasData?.v0?.langcode ?? globalThis.drupalSettings?.langcode ?? "en";
|
|
23
|
-
/**
|
|
24
|
-
* Creates an `Intl.DateTimeFormat` instance, falling back to 'en' locale if
|
|
25
|
-
* the Drupal langcode string is not a valid BCP 47 tag.
|
|
26
|
-
*
|
|
27
|
-
* Drupal langcodes like `zh-hans` or `pt-br` use lowercase language tag
|
|
28
|
-
* components which may throw `RangeError` in strict BCP 47 environments.
|
|
29
|
-
* The try/catch ensures graceful degradation.
|
|
30
|
-
*
|
|
31
|
-
* All formatters use `timeZone: 'UTC'` because Canvas date/datetime props are
|
|
32
|
-
* stored without timezone offset. Formatting in the local browser timezone
|
|
33
|
-
* would silently shift dates — e.g. a UTC midnight date would appear as the
|
|
34
|
-
* previous day in negative-UTC-offset timezones (Americas).
|
|
35
|
-
*/
|
|
36
|
-
const createFormatter = (locale, options) => {
|
|
37
|
-
const utcOptions = {
|
|
38
|
-
timeZone: "UTC",
|
|
39
|
-
...options
|
|
40
|
-
};
|
|
41
|
-
try {
|
|
42
|
-
return new Intl.DateTimeFormat(locale, utcOptions);
|
|
43
|
-
} catch {
|
|
44
|
-
return new Intl.DateTimeFormat("en", utcOptions);
|
|
10
|
+
//#region src/drupal-settings.ts
|
|
11
|
+
/** Reads `drupalSettings.canvasData.v0` from a settings object or the global. */
|
|
12
|
+
function readCanvasDataV0(settings = globalThis.drupalSettings) {
|
|
13
|
+
const v0 = settings?.canvasData?.v0;
|
|
14
|
+
return v0 && typeof v0 === "object" ? v0 : null;
|
|
15
|
+
}
|
|
16
|
+
const EMPTY_THEME_ASSETS = {
|
|
17
|
+
logo: { url: "" },
|
|
18
|
+
favicon: {
|
|
19
|
+
url: "",
|
|
20
|
+
mimeType: ""
|
|
45
21
|
}
|
|
46
22
|
};
|
|
47
23
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* ECMAScript parses a date-time string without a UTC offset as local time,
|
|
51
|
-
* whereas date-only strings are parsed as UTC. Canvas treats every stored
|
|
52
|
-
* value as UTC (the PHP side appends `Z` before formatting), so a `Z` is
|
|
53
|
-
* appended to date-time strings that carry no offset. Without it, the UTC
|
|
54
|
-
* formatter would shift the value by the viewer's UTC offset.
|
|
55
|
-
*/
|
|
56
|
-
const parseIso = (iso) => {
|
|
57
|
-
if (!iso) return null;
|
|
58
|
-
const hasTimePart = /[T ]\d{2}:\d{2}/.test(iso);
|
|
59
|
-
const hasOffset = /(Z|[+-]\d{2}(:?\d{2})?)$/i.test(iso);
|
|
60
|
-
const d = new Date(hasTimePart && !hasOffset ? `${iso}Z` : iso);
|
|
61
|
-
return isNaN(d.getTime()) ? null : d;
|
|
62
|
-
};
|
|
63
|
-
/**
|
|
64
|
-
* Formats an ISO date string using the active Drupal locale's date format.
|
|
65
|
-
*
|
|
66
|
-
* Returns the original `iso` string unchanged if it cannot be parsed, and an
|
|
67
|
-
* empty string for `null` or `undefined` (an optional prop without a value).
|
|
68
|
-
*
|
|
69
|
-
* @param iso
|
|
70
|
-
* ISO date string, e.g. '2026-01-15'.
|
|
71
|
-
* @param options
|
|
72
|
-
* Optional format overrides. Defaults to `{ dateStyle: 'short' }`.
|
|
73
|
-
*
|
|
74
|
-
* @return
|
|
75
|
-
* Locale-formatted date string, e.g. '1/15/26' (en) or '15/01/2026' (fr).
|
|
76
|
-
*/
|
|
77
|
-
function canvasFormatDate(iso, options) {
|
|
78
|
-
if (iso == null) return "";
|
|
79
|
-
const date = parseIso(iso);
|
|
80
|
-
if (!date) return iso;
|
|
81
|
-
return createFormatter(getDrupalLangcode(), { dateStyle: options?.dateStyle ?? "short" }).format(date);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Formats an ISO datetime string using the active Drupal locale's format.
|
|
24
|
+
* Builds the page and site context from `drupalSettings.canvasData.v0`.
|
|
85
25
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* ISO datetime string, e.g. '2026-01-15T14:30:00Z'.
|
|
91
|
-
* @param options
|
|
92
|
-
* Optional format overrides. Defaults to
|
|
93
|
-
* `{ dateStyle: 'short', timeStyle: 'short' }`.
|
|
94
|
-
*
|
|
95
|
-
* @return
|
|
96
|
-
* Locale-formatted datetime string.
|
|
97
|
-
*/
|
|
98
|
-
function canvasFormatDateTime(iso, options) {
|
|
99
|
-
if (iso == null) return "";
|
|
100
|
-
const date = parseIso(iso);
|
|
101
|
-
if (!date) return iso;
|
|
102
|
-
return createFormatter(getDrupalLangcode(), {
|
|
103
|
-
dateStyle: options?.dateStyle ?? "short",
|
|
104
|
-
timeStyle: options?.timeStyle ?? "short"
|
|
105
|
-
}).format(date);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Formats an ISO time/datetime string using the active Drupal locale's time format.
|
|
109
|
-
*
|
|
110
|
-
* Returns the original `iso` string unchanged if it cannot be parsed, and an
|
|
111
|
-
* empty string for `null` or `undefined` (an optional prop without a value).
|
|
112
|
-
*
|
|
113
|
-
* @param iso
|
|
114
|
-
* ISO time or datetime string, e.g. '14:30:00' or '2026-01-15T14:30:00Z'.
|
|
115
|
-
* @param options
|
|
116
|
-
* Optional format overrides. Defaults to `{ timeStyle: 'short' }`.
|
|
117
|
-
*
|
|
118
|
-
* @return
|
|
119
|
-
* Locale-formatted time string.
|
|
26
|
+
* Page context is available when Drupal attached any page-level key
|
|
27
|
+
* (`pageTitle`, `breadcrumbs`, or `mainEntity`); site context when it attached
|
|
28
|
+
* `branding`. Missing keys inside an available group take the same defaults
|
|
29
|
+
* as the legacy getters.
|
|
120
30
|
*/
|
|
121
|
-
function
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
31
|
+
function drupalSettingsToCanvasContext(v0) {
|
|
32
|
+
if (!v0) return {
|
|
33
|
+
page: null,
|
|
34
|
+
site: null
|
|
35
|
+
};
|
|
36
|
+
const hasPage = "pageTitle" in v0 || "breadcrumbs" in v0 || "mainEntity" in v0;
|
|
37
|
+
const hasSite = "branding" in v0;
|
|
38
|
+
return {
|
|
39
|
+
page: hasPage ? {
|
|
40
|
+
pageTitle: v0.pageTitle || "",
|
|
41
|
+
breadcrumbs: v0.breadcrumbs || [],
|
|
42
|
+
mainEntity: v0.mainEntity || null
|
|
43
|
+
} : null,
|
|
44
|
+
site: hasSite ? {
|
|
45
|
+
branding: v0.branding || {
|
|
46
|
+
homeUrl: "",
|
|
47
|
+
siteName: "",
|
|
48
|
+
siteSlogan: ""
|
|
49
|
+
},
|
|
50
|
+
baseUrl: v0.baseUrl || "/",
|
|
51
|
+
themeAssets: v0.themeAssets || EMPTY_THEME_ASSETS
|
|
52
|
+
} : null
|
|
53
|
+
};
|
|
127
54
|
}
|
|
128
55
|
/**
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
* @param range
|
|
134
|
-
* Canvas date-range object, e.g. `{ from: '2026-01-15', to: '2026-03-20' }`.
|
|
135
|
-
* @param options
|
|
136
|
-
* Optional format overrides passed to each field. Defaults to
|
|
137
|
-
* `{ dateStyle: 'short' }`.
|
|
138
|
-
*
|
|
139
|
-
* @return
|
|
140
|
-
* A new object with the same keys; each string date value is replaced with a
|
|
141
|
-
* formatted string.
|
|
56
|
+
* Builds the JSON:API runtime configuration for a Drupal-rendered page from
|
|
57
|
+
* `drupalSettings.canvasData.v0`, or `null` when the settings do not carry a
|
|
58
|
+
* base URL or JSON:API is not installed. Previews read working copies through
|
|
59
|
+
* the editor's Drupal session.
|
|
142
60
|
*/
|
|
143
|
-
function
|
|
144
|
-
if (
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
61
|
+
function drupalSettingsToJsonApiRuntimeConfig(v0, options = {}) {
|
|
62
|
+
if (!v0 || typeof v0.baseUrl !== "string" || v0.baseUrl === "") return null;
|
|
63
|
+
if (v0.jsonapiSettings === null) return null;
|
|
64
|
+
const preview = options.preview ?? false;
|
|
65
|
+
return {
|
|
66
|
+
baseUrl: v0.baseUrl,
|
|
67
|
+
...v0.jsonapiSettings?.apiPrefix && { apiPrefix: v0.jsonapiSettings.apiPrefix },
|
|
68
|
+
resourceVersion: preview ? "rel:working-copy" : null,
|
|
69
|
+
preview
|
|
70
|
+
};
|
|
149
71
|
}
|
|
150
72
|
//#endregion
|
|
151
73
|
//#region src/Region.tsx
|
|
152
74
|
const RegionsContext = createContext({});
|
|
75
|
+
/**
|
|
76
|
+
* Supplies the region node map read by `Region`.
|
|
77
|
+
*
|
|
78
|
+
* @deprecated Theme-global regions were replaced by page variants (ADR 19);
|
|
79
|
+
* compose pages with the component tree instead. Kept for compatibility.
|
|
80
|
+
*/
|
|
153
81
|
function RegionsProvider({ regions, children }) {
|
|
154
82
|
return /* @__PURE__ */ jsx(RegionsContext.Provider, {
|
|
155
83
|
value: regions,
|
|
156
84
|
children
|
|
157
85
|
});
|
|
158
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* Renders the region whose machine name matches `name`.
|
|
89
|
+
*
|
|
90
|
+
* @deprecated Theme-global regions were replaced by page variants (ADR 19);
|
|
91
|
+
* compose pages with the component tree instead. Kept for compatibility.
|
|
92
|
+
*/
|
|
159
93
|
function Region({ name, fallback = null }) {
|
|
160
94
|
const node = useContext(RegionsContext)[name];
|
|
161
95
|
return /* @__PURE__ */ jsx(Fragment, { children: node ?? fallback });
|
|
162
96
|
}
|
|
163
97
|
//#endregion
|
|
164
|
-
export { FormattedText, Image,
|
|
98
|
+
export { AGENT_MIGRATION_PROMPT, DraftSessionError, FormattedText, Image, LegacyJsonApiClient as JsonApiClient, LEGACY_API_GUIDANCE, Region, RegionsProvider, cn, createJsonApiClient, declareCanvasRuntime, drupalSettingsToCanvasContext, drupalSettingsToJsonApiRuntimeConfig, formatLegacyApiError, getCanvasRuntime, getNodePath, getPageData, getSiteData, isDraftSessionError, isLegacyRuntimeSupported, readCanvasDataV0, sortMenu as sortLinksetMenu, sortMenu$1 as sortMenu };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentType } from "react";
|
|
1
|
+
import { ComponentType, ReactNode } from "react";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { Spec } from "@json-render/core";
|
|
4
4
|
import { ComponentMetadata } from "@drupal-canvas/discovery";
|
|
@@ -59,7 +59,7 @@ type ComponentRegistry = Record<string, ComponentType<Record<string, unknown>>>;
|
|
|
59
59
|
* @param registry - Component registry to use for rendering.
|
|
60
60
|
* @see {@link defineComponentRegistry}
|
|
61
61
|
*/
|
|
62
|
-
declare function renderSpec(spec: Spec, registry: ComponentRegistry):
|
|
62
|
+
declare function renderSpec(spec: Spec, registry: ComponentRegistry): ReactNode;
|
|
63
63
|
/**
|
|
64
64
|
* Renders a Drupal Canvas component tree.
|
|
65
65
|
*
|
|
@@ -67,7 +67,7 @@ declare function renderSpec(spec: Spec, registry: ComponentRegistry): React.Reac
|
|
|
67
67
|
* @param registry - Component registry to use for rendering.
|
|
68
68
|
* @see {@link defineComponentRegistry}
|
|
69
69
|
*/
|
|
70
|
-
declare function renderCanvasTree(components: CanvasComponentTree, registry: ComponentRegistry):
|
|
70
|
+
declare function renderCanvasTree(components: CanvasComponentTree, registry: ComponentRegistry): ReactNode;
|
|
71
71
|
/**
|
|
72
72
|
* Defines a component registry by dynamically importing each component's
|
|
73
73
|
* JavaScript entry file from the discovery results.
|