drupal-canvas 0.7.1 → 0.8.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 CHANGED
@@ -69,9 +69,10 @@ export default function PageHeader() {
69
69
  (the primary Drupal entity, `null` on routes without one), including language
70
70
  and translation information. See
71
71
  [Main entity metadata](https://project.pages.drupalcode.org/canvas/code-components/data-fetching#main-entity-metadata).
72
- - Site context (`SiteContext`): `branding`, the Drupal `baseUrl`, and
73
- `themeAssets`. Headless frontends receive empty theme asset URLs; that is
74
- valid site context, so shared components must handle empty asset URLs.
72
+ - Site context (`SiteContext`): `branding`, the Drupal `baseUrl`, `themeAssets`,
73
+ and the interface `langcode`. Headless frontends receive empty theme asset
74
+ URLs; that is valid site context, so shared components must handle empty asset
75
+ URLs.
75
76
 
76
77
  Call the hooks unconditionally at the top level of a function component or
77
78
  custom hook (React's rules of hooks) and handle `null` results.
@@ -88,7 +89,35 @@ import { CanvasContextProvider } from 'drupal-canvas/react';
88
89
  ```
89
90
 
90
91
  The `CanvasContext` type describes the provider's value:
91
- `{ page: PageContext | null; site: SiteContext | null }`.
92
+ `{ page: PageContext | null; site: SiteContext | null; translations?: Translations | null }`.
93
+
94
+ ### `useTranslation`
95
+
96
+ Translate interface strings with `t()` and `formatPlural()`, which take the same
97
+ arguments as `Drupal.t()` and `Drupal.formatPlural()`. They work in every
98
+ frontend mode: they read the translations from the context. Without a
99
+ translation, they return the source string.
100
+
101
+ ```jsx
102
+ import { useTranslation } from 'drupal-canvas/react';
103
+
104
+ export default function Greeting({ name, count }) {
105
+ const { t, formatPlural } = useTranslation();
106
+ return (
107
+ <p>
108
+ {t('Hello @name', { '@name': name })}{' '}
109
+ {formatPlural(count, '1 new message', '@count new messages')}
110
+ </p>
111
+ );
112
+ }
113
+ ```
114
+
115
+ The code editor, the Canvas CLI, and the Headless SDK find the strings in the
116
+ component source, so pass string literals, and a string literal as the
117
+ `context`. Only `@` placeholders, such as `@name`, are replaced. Unlike Drupal's
118
+ functions, which return HTML, both return text: HTML in a string is shown as
119
+ text. See
120
+ [Interface translation](https://project.pages.drupalcode.org/canvas/code-components/interface-translation).
92
121
 
93
122
  ### `getPageData` and `getSiteData` (deprecated)
94
123
 
@@ -1,4 +1,3 @@
1
- //#region src/FormattedText.d.ts
2
1
  type FormattedTextProps = {
3
2
  children: string;
4
3
  as?: 'div' | 'span';
@@ -7,6 +6,4 @@ type FormattedTextProps = {
7
6
  style?: Record<string, string>;
8
7
  [key: string]: any;
9
8
  };
10
- declare function FormattedText({ children, as, ...props }: FormattedTextProps): import("react/jsx-runtime").JSX.Element;
11
- //#endregion
12
- export { FormattedText as default };
9
+ export default function FormattedText({ children, as, ...props }: FormattedTextProps): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +1,9 @@
1
1
  import { jsx } from "react/jsx-runtime";
2
- //#region src/FormattedText.tsx
2
+ // src/FormattedText.tsx
3
3
  function FormattedText({ children, as = "div", ...props }) {
4
4
  return /* @__PURE__ */ jsx(as, {
5
5
  dangerouslySetInnerHTML: { __html: children },
6
6
  ...props
7
7
  });
8
8
  }
9
- //#endregion
10
9
  export { FormattedText as default };
@@ -0,0 +1,94 @@
1
+ import { d as PageContext, f as SiteContext, p as Translations, u as CanvasContext } from "./drupal-utils-BIiH7B6O.js";
2
+ import { ReactNode } from "react";
3
+ /**
4
+ * Placeholder replacements, keyed by `@` placeholders, e.g.
5
+ * `{ '@name': name }`. Drupal's other placeholder prefixes (`%`, `:` and `!`)
6
+ * are not supported: such keys are ignored, so their placeholders stay in the
7
+ * text.
8
+ */
9
+ type TranslationArgs = Record<`@${string}`, string | number>;
10
+ interface TranslationOptions {
11
+ /** The string context, to tell apart identical source strings. */
12
+ context?: string;
13
+ }
14
+ /**
15
+ * Translates a string, with the same arguments as `Drupal.t()`.
16
+ *
17
+ * Unlike `Drupal.t()`, which returns HTML, the result is text: `@`
18
+ * placeholders insert their values as is, and HTML in the source string or its
19
+ * translation is not interpreted. React escapes the text when it renders it.
20
+ */
21
+ type TranslateFunction = (str: string, args?: TranslationArgs, options?: TranslationOptions) => string;
22
+ /**
23
+ * Formats a singular or plural string for a count, with the same arguments as
24
+ * `Drupal.formatPlural()`. `@count` is replaced with the count. The result is
25
+ * text, not HTML, as with `TranslateFunction`.
26
+ */
27
+ type FormatPluralFunction = (count: number, singular: string, plural: string, args?: TranslationArgs, options?: TranslationOptions) => string;
28
+ interface CanvasContextProviderProps {
29
+ context: CanvasContext;
30
+ children?: ReactNode;
31
+ }
32
+ /**
33
+ * Makes page and site context available to every React descendant. Adds no
34
+ * DOM wrapper. Rendering integrations use it internally; applications can use
35
+ * it to reach components outside the Canvas tree, such as a site header.
36
+ */
37
+ declare function CanvasContextProvider({ context, children }: CanvasContextProviderProps): import("react/jsx-runtime").JSX.Element;
38
+ interface TranslationsProviderProps {
39
+ /**
40
+ * The translations for every component below, e.g. the application's own
41
+ * dictionary. They replace the translations of the Canvas context instead
42
+ * of being merged with them; `null` means none, so components show their
43
+ * source strings.
44
+ */
45
+ translations: Translations | null;
46
+ children?: ReactNode;
47
+ }
48
+ /**
49
+ * Replaces the translations `useTranslation()` uses below it. The nearest
50
+ * provider takes precedence over the Canvas context's translations, also over
51
+ * a context that a rendering integration provides further down, such as the
52
+ * `context` of `CanvasComponentTree`. Without it, components use the
53
+ * translations of the Canvas context. Adds no DOM wrapper.
54
+ */
55
+ declare function TranslationsProvider({ translations, children }: TranslationsProviderProps): import("react/jsx-runtime").JSX.Element;
56
+ /**
57
+ * Returns the current page context, or `null` when no provider supplies one.
58
+ * Emits a deduplicated developer warning in that case; a provider that
59
+ * carries valid empty page data is not a missing-context condition.
60
+ */
61
+ declare function usePageContext(): PageContext | null;
62
+ /**
63
+ * Returns the current site context, or `null` when no provider supplies one.
64
+ * Emits a deduplicated developer warning in that case.
65
+ */
66
+ declare function useSiteContext(): SiteContext | null;
67
+ /**
68
+ * Returns `t()` and `formatPlural()`, which translate strings into the page's
69
+ * interface language. They take the arguments of `Drupal.t()` and
70
+ * `Drupal.formatPlural()`, with `@` placeholders only, but return text, not
71
+ * HTML, which React escapes when it renders it. The code editor, the Canvas
72
+ * CLI, and the Headless SDK find the strings to translate in the component
73
+ * source: pass string literals.
74
+ *
75
+ * The translations come from the nearest `TranslationsProvider`, otherwise
76
+ * from the Canvas context. Without a translation for a string, they return the
77
+ * source string. Without either provider they also warn once.
78
+ *
79
+ * @example
80
+ * const { t, formatPlural } = useTranslation();
81
+ * t('Hello @name', { '@name': name });
82
+ * formatPlural(count, '1 item', '@count items');
83
+ */
84
+ declare function useTranslation(): {
85
+ t: TranslateFunction;
86
+ formatPlural: FormatPluralFunction;
87
+ };
88
+ /**
89
+ * Whether a `CanvasContextProvider` is mounted above the calling component.
90
+ * Rendering integrations use it to decide whether to inherit an outer
91
+ * provider instead of adding their own.
92
+ */
93
+ declare function useHasCanvasContext(): boolean;
94
+ export { useHasCanvasContext as a, useTranslation as c, TranslationArgs as d, TranslationOptions as f, TranslationsProviderProps as i, FormatPluralFunction as l, CanvasContextProviderProps as n, usePageContext as o, TranslationsProvider as r, useSiteContext as s, CanvasContextProvider as t, TranslateFunction as u };
@@ -1,4 +1,3 @@
1
- //#region src/context-types.d.ts
2
1
  /**
3
2
  * The page context: the same shape `getPageData()` returns. The primary
4
3
  * entity can be `null` on routes without one.
@@ -10,13 +9,36 @@ type PageContext = PageData;
10
9
  * missing context.
11
10
  */
12
11
  type SiteContext = SiteData;
12
+ /**
13
+ * Interface translations for the strings Code Components pass to `t()` and
14
+ * `formatPlural()`, in the page's interface language. Same layout as Drupal's
15
+ * `drupalTranslations`.
16
+ */
17
+ interface Translations {
18
+ /**
19
+ * Translated strings keyed by context (`''` when none), then by source
20
+ * string. Plural strings join their forms with `\x03`, in source and
21
+ * translation alike. Untranslated strings can be omitted.
22
+ */
23
+ strings: Record<string, Record<string, string>>;
24
+ /**
25
+ * The plural form index for a count, with a `default` for counts not
26
+ * listed. As in Drupal, it covers counts up to 199: a larger count uses the
27
+ * index of 100 plus its remainder over 100. Without it, translated plurals
28
+ * use the first form for 1 and the second for other counts.
29
+ */
30
+ pluralFormula?: Record<string, number> | null;
31
+ }
13
32
  /** The context a rendering integration supplies to a component tree. */
14
33
  interface CanvasContext {
15
34
  page: PageContext | null;
16
35
  site: SiteContext | null;
36
+ /**
37
+ * Absent or `null` when there is nothing to translate: `t()` then returns
38
+ * source strings.
39
+ */
40
+ translations?: Translations | null;
17
41
  }
18
- //#endregion
19
- //#region src/drupal-utils.d.ts
20
42
  interface Linkset {
21
43
  linkset: LinksetItem[];
22
44
  }
@@ -90,6 +112,11 @@ interface SiteData {
90
112
  };
91
113
  baseUrl: string;
92
114
  themeAssets: ThemeAssets;
115
+ /**
116
+ * The interface language of the site, e.g. `fr`. `useDateFormatter()`
117
+ * formats dates in it. Absent when the integration did not supply it.
118
+ */
119
+ langcode?: string;
93
120
  }
94
121
  /**
95
122
  * Reads the current page data from `drupalSettings`.
@@ -113,5 +140,4 @@ declare const getPageData: () => PageData;
113
140
  * components.
114
141
  */
115
142
  declare const getSiteData: () => SiteData;
116
- //#endregion
117
- export { ThemeAssets as a, getSiteData as c, PageContext as d, SiteContext as f, SiteData as i, sortMenu as l, EntityMetadata as n, TranslationMetadata as o, PageData as r, getPageData as s, BreadcrumbLink as t, CanvasContext as u };
143
+ export { ThemeAssets as a, getSiteData as c, PageContext as d, SiteContext as f, SiteData as i, sortMenu as l, EntityMetadata as n, TranslationMetadata as o, Translations as p, PageData as r, getPageData as s, BreadcrumbLink as t, CanvasContext as u };
@@ -1,2 +1,2 @@
1
- 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";
1
+ 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-BIiH7B6O.js";
2
2
  export { BreadcrumbLink, type CanvasContext, EntityMetadata, type PageContext, PageData, type SiteContext, SiteData, ThemeAssets, TranslationMetadata, getPageData, getSiteData, sortMenu };
@@ -1,5 +1,5 @@
1
- import { r as assertLegacyRuntime } from "./migration-CPBzW78_.js";
2
- //#region src/drupal-utils.ts
1
+ import { r as assertLegacyRuntime } from "./migration-CxRMGzhm.js";
2
+ // src/drupal-utils.ts
3
3
  /**
4
4
  * Sort menu items from core's menu API into a tree with additional
5
5
  * _children and _hasSubmenu properties.
@@ -94,5 +94,4 @@ const getSiteData = () => {
94
94
  });
95
95
  return siteData;
96
96
  };
97
- //#endregion
98
97
  export { getPageData, getSiteData, sortMenu };
package/dist/index.d.ts CHANGED
@@ -1,12 +1,11 @@
1
+ import "./context-DMp0nsTU.js";
2
+ 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-CKzxh1on.js";
3
+ 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, p as Translations, r as PageData, s as getPageData, t as BreadcrumbLink, u as CanvasContext } from "./drupal-utils-BIiH7B6O.js";
1
4
  import FormattedText from "./FormattedText.js";
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";
5
5
  import { getNodePath, sortMenu as sortMenu$1 } from "./jsonapi-utils.js";
6
6
  import Image from "./next-image-standalone.js";
7
7
  import { cn } from "./utils.js";
8
8
  import { ReactNode } from "react";
9
- //#region src/drupal-settings.d.ts
10
9
  /** The subset of `drupalSettings.canvasData.v0` the context API reads. */
11
10
  interface CanvasDataV0 {
12
11
  pageTitle?: string | null;
@@ -16,10 +15,12 @@ interface CanvasDataV0 {
16
15
  mainEntity?: NonNullable<CanvasContext['page']>['mainEntity'];
17
16
  branding?: NonNullable<CanvasContext['site']>['branding'] | null;
18
17
  baseUrl?: string | null;
18
+ langcode?: string | null;
19
19
  themeAssets?: NonNullable<CanvasContext['site']>['themeAssets'] | null;
20
20
  jsonapiSettings?: {
21
21
  apiPrefix?: string;
22
22
  } | null;
23
+ translations?: Translations | null;
23
24
  }
24
25
  interface DrupalSettingsLike {
25
26
  canvasData?: {
@@ -27,27 +28,25 @@ interface DrupalSettingsLike {
27
28
  } | null;
28
29
  }
29
30
  /** Reads `drupalSettings.canvasData.v0` from a settings object or the global. */
30
- declare function readCanvasDataV0(settings?: DrupalSettingsLike | undefined): CanvasDataV0 | null;
31
+ export declare function readCanvasDataV0(settings?: DrupalSettingsLike | undefined): CanvasDataV0 | null;
31
32
  /**
32
33
  * Builds the page and site context from `drupalSettings.canvasData.v0`.
33
34
  *
34
35
  * Page context is available when Drupal attached any page-level key
35
36
  * (`pageTitle`, `breadcrumbs`, or `mainEntity`); site context when it attached
36
- * `branding`. Missing keys inside an available group take the same defaults
37
+ * `branding` or `langcode`. Missing keys inside an available group take the same defaults
37
38
  * as the legacy getters.
38
39
  */
39
- declare function drupalSettingsToCanvasContext(v0: CanvasDataV0 | null | undefined): CanvasContext;
40
+ export declare function drupalSettingsToCanvasContext(v0: CanvasDataV0 | null | undefined): CanvasContext;
40
41
  /**
41
42
  * Builds the JSON:API runtime configuration for a Drupal-rendered page from
42
43
  * `drupalSettings.canvasData.v0`, or `null` when the settings do not carry a
43
44
  * base URL or JSON:API is not installed. Previews read working copies through
44
45
  * the editor's Drupal session.
45
46
  */
46
- declare function drupalSettingsToJsonApiRuntimeConfig(v0: CanvasDataV0 | null | undefined, options?: {
47
+ export declare function drupalSettingsToJsonApiRuntimeConfig(v0: CanvasDataV0 | null | undefined, options?: {
47
48
  preview?: boolean;
48
49
  }): JsonApiRuntimeConfig | null;
49
- //#endregion
50
- //#region src/migration.d.ts
51
50
  /**
52
51
  * @file
53
52
  * Migration guidance shared by the legacy API errors, the hook warnings, and
@@ -57,9 +56,9 @@ declare function drupalSettingsToJsonApiRuntimeConfig(v0: CanvasDataV0 | null |
57
56
  * The AI-agent migration prompt included in legacy API errors and printed by
58
57
  * the Canvas CLI for components it could not migrate automatically.
59
58
  */
60
- declare const AGENT_MIGRATION_PROMPT: string;
59
+ export declare const AGENT_MIGRATION_PROMPT: string;
61
60
  /** Replacement guidance per legacy API. */
62
- declare const LEGACY_API_GUIDANCE: {
61
+ export declare const LEGACY_API_GUIDANCE: {
63
62
  readonly 'getPageData()': string;
64
63
  readonly 'getSiteData()': string;
65
64
  readonly 'new JsonApiClient()': string;
@@ -69,9 +68,7 @@ type LegacyApiName = keyof typeof LEGACY_API_GUIDANCE;
69
68
  * Builds the error message thrown when a legacy API is invoked outside Drupal
70
69
  * and Workbench.
71
70
  */
72
- declare function formatLegacyApiError(api: LegacyApiName): string;
73
- //#endregion
74
- //#region src/Region.d.ts
71
+ export declare function formatLegacyApiError(api: LegacyApiName): string;
75
72
  type RegionsMap = Record<string, ReactNode>;
76
73
  type RegionsProviderProps = {
77
74
  regions: RegionsMap;
@@ -83,7 +80,7 @@ type RegionsProviderProps = {
83
80
  * @deprecated Theme-global regions were replaced by page variants (ADR 19);
84
81
  * compose pages with the component tree instead. Kept for compatibility.
85
82
  */
86
- declare function RegionsProvider({ regions, children }: RegionsProviderProps): import("react/jsx-runtime").JSX.Element;
83
+ export declare function RegionsProvider({ regions, children }: RegionsProviderProps): import("react/jsx-runtime").JSX.Element;
87
84
  type RegionProps = {
88
85
  name: string;
89
86
  fallback?: ReactNode;
@@ -94,9 +91,7 @@ type RegionProps = {
94
91
  * @deprecated Theme-global regions were replaced by page variants (ADR 19);
95
92
  * compose pages with the component tree instead. Kept for compatibility.
96
93
  */
97
- declare function Region({ name, fallback }: RegionProps): import("react/jsx-runtime").JSX.Element;
98
- //#endregion
99
- //#region src/runtime.d.ts
94
+ export declare function Region({ name, fallback }: RegionProps): import("react/jsx-runtime").JSX.Element;
100
95
  /**
101
96
  * @file
102
97
  * The runtime marker that identifies the environments in which the legacy
@@ -117,15 +112,14 @@ type CanvasRuntimeEnvironment = 'drupal' | 'workbench';
117
112
  * Declares the current runtime environment. Called by Drupal and Workbench
118
113
  * integrations, never by Code Components or headless applications.
119
114
  */
120
- declare function declareCanvasRuntime(environment: CanvasRuntimeEnvironment): void;
115
+ export declare function declareCanvasRuntime(environment: CanvasRuntimeEnvironment): void;
121
116
  /**
122
117
  * Returns the declared runtime environment, or `null` outside Drupal and
123
118
  * Workbench.
124
119
  */
125
- declare function getCanvasRuntime(): CanvasRuntimeEnvironment | null;
120
+ export declare function getCanvasRuntime(): CanvasRuntimeEnvironment | null;
126
121
  /**
127
122
  * Whether the legacy runtime APIs are supported in the current environment.
128
123
  */
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 };
124
+ export declare function isLegacyRuntimeSupported(): boolean;
125
+ export { type BreadcrumbLink, type CanvasContext, type CanvasDataV0, type CanvasJsonApiClient, type CanvasRuntimeEnvironment, DraftSessionError, type EntityMetadata, FormattedText, Image, LegacyJsonApiClient as JsonApiClient, type JsonApiClientConfig, type JsonApiRuntimeConfig, type PageContext, type PageData, type SiteContext, type SiteData, type ThemeAssets, type TranslationMetadata, type Translations, cn, createJsonApiClient, getNodePath, getPageData, getSiteData, isDraftSessionError, sortMenu as sortLinksetMenu, sortMenu$1 as sortMenu };
package/dist/index.js CHANGED
@@ -1,13 +1,13 @@
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";
2
1
  import { getPageData, getSiteData, sortMenu } from "./drupal-utils.js";
3
2
  import FormattedText from "./FormattedText.js";
4
- import { a as isDraftSessionError, i as createJsonApiClient, n as DraftSessionError, r as LegacyJsonApiClient } from "./jsonapi-client-CejP62bM.js";
3
+ import { DraftSessionError, JsonApiClient as LegacyJsonApiClient, createJsonApiClient, isDraftSessionError } from "./jsonapi-client.js";
5
4
  import { getNodePath, sortMenu as sortMenu$1 } from "./jsonapi-utils.js";
5
+ 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-CxRMGzhm.js";
6
6
  import Image from "./next-image-standalone.js";
7
7
  import { cn } from "./utils.js";
8
8
  import { Fragment, jsx } from "react/jsx-runtime";
9
9
  import { createContext, useContext } from "react";
10
- //#region src/drupal-settings.ts
10
+ // src/drupal-settings.ts
11
11
  /** Reads `drupalSettings.canvasData.v0` from a settings object or the global. */
12
12
  function readCanvasDataV0(settings = globalThis.drupalSettings) {
13
13
  const v0 = settings?.canvasData?.v0;
@@ -25,7 +25,7 @@ const EMPTY_THEME_ASSETS = {
25
25
  *
26
26
  * Page context is available when Drupal attached any page-level key
27
27
  * (`pageTitle`, `breadcrumbs`, or `mainEntity`); site context when it attached
28
- * `branding`. Missing keys inside an available group take the same defaults
28
+ * `branding` or `langcode`. Missing keys inside an available group take the same defaults
29
29
  * as the legacy getters.
30
30
  */
31
31
  function drupalSettingsToCanvasContext(v0) {
@@ -34,7 +34,7 @@ function drupalSettingsToCanvasContext(v0) {
34
34
  site: null
35
35
  };
36
36
  const hasPage = "pageTitle" in v0 || "breadcrumbs" in v0 || "mainEntity" in v0;
37
- const hasSite = "branding" in v0;
37
+ const hasSite = "branding" in v0 || "langcode" in v0;
38
38
  return {
39
39
  page: hasPage ? {
40
40
  pageTitle: v0.pageTitle || "",
@@ -48,8 +48,10 @@ function drupalSettingsToCanvasContext(v0) {
48
48
  siteSlogan: ""
49
49
  },
50
50
  baseUrl: v0.baseUrl || "/",
51
- themeAssets: v0.themeAssets || EMPTY_THEME_ASSETS
52
- } : null
51
+ themeAssets: v0.themeAssets || EMPTY_THEME_ASSETS,
52
+ ...v0.langcode && { langcode: v0.langcode }
53
+ } : null,
54
+ ...v0.translations && { translations: v0.translations }
53
55
  };
54
56
  }
55
57
  /**
@@ -69,8 +71,7 @@ function drupalSettingsToJsonApiRuntimeConfig(v0, options = {}) {
69
71
  preview
70
72
  };
71
73
  }
72
- //#endregion
73
- //#region src/Region.tsx
74
+ // src/Region.tsx
74
75
  const RegionsContext = createContext({});
75
76
  /**
76
77
  * Supplies the region node map read by `Region`.
@@ -94,5 +95,4 @@ function Region({ name, fallback = null }) {
94
95
  const node = useContext(RegionsContext)[name];
95
96
  return /* @__PURE__ */ jsx(Fragment, { children: node ?? fallback });
96
97
  }
97
- //#endregion
98
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 };
@@ -2,12 +2,11 @@ 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";
5
- //#region src/json-render-utils.d.ts
6
5
  /**
7
6
  * Drupal Canvas component tree node.
8
7
  * @see canvas.component_tree_node in config/schema/canvas.schema.yml
9
8
  */
10
- interface CanvasComponentTreeNode {
9
+ export interface CanvasComponentTreeNode {
11
10
  parent_uuid: string | null;
12
11
  slot: string | null;
13
12
  uuid: string;
@@ -21,37 +20,37 @@ interface CanvasComponentTreeNode {
21
20
  * Drupal Canvas component tree. A flat sequence of component tree nodes linked by parent_uuid.
22
21
  * @see canvas.component_tree in config/schema/canvas.schema.yml
23
22
  */
24
- type CanvasComponentTree = CanvasComponentTreeNode[];
23
+ export type CanvasComponentTree = CanvasComponentTreeNode[];
25
24
  /**
26
25
  * Authored page spec element. The local file representation of a component
27
26
  * instance, as opposed to CanvasComponentTreeNode which is the API representation.
28
27
  */
29
- interface AuthoredSpecElement {
28
+ export interface AuthoredSpecElement {
30
29
  type: string;
31
30
  props?: unknown;
32
31
  slots?: AuthoredSpecSlots;
33
32
  _provenance?: Record<string, unknown>;
34
33
  }
35
- type AuthoredSpecElementMap = Record<string, AuthoredSpecElement>;
36
- type AuthoredSpecSlots = Record<string, string[]>;
34
+ export type AuthoredSpecElementMap = Record<string, AuthoredSpecElement>;
35
+ export type AuthoredSpecSlots = Record<string, string[]>;
37
36
  /**
38
37
  * Converts an array of Drupal Canvas components to json-render spec format.
39
38
  *
40
39
  * @param components - Flat array of Canvas component tree nodes
41
40
  * @returns json-render spec
42
41
  */
43
- declare function canvasTreeToSpec(components: CanvasComponentTree): Spec;
42
+ export declare function canvasTreeToSpec(components: CanvasComponentTree): Spec;
44
43
  /**
45
44
  * Converts a json-render spec to Drupal Canvas component tree format.
46
45
  *
47
46
  * @param jsonRenderSpec - json-render spec
48
47
  * @returns Flat array of Canvas component tree nodes
49
48
  */
50
- declare function specToCanvasTree(jsonRenderSpec: Spec): CanvasComponentTree;
49
+ export declare function specToCanvasTree(jsonRenderSpec: Spec): CanvasComponentTree;
51
50
  /**
52
51
  * Registry of components keyed by component_id.
53
52
  */
54
- type ComponentRegistry = Record<string, ComponentType<Record<string, unknown>>>;
53
+ export type ComponentRegistry = Record<string, ComponentType<Record<string, unknown>>>;
55
54
  /**
56
55
  * Renders a json-render spec using the given component registry.
57
56
  *
@@ -59,7 +58,7 @@ type ComponentRegistry = Record<string, ComponentType<Record<string, unknown>>>;
59
58
  * @param registry - Component registry to use for rendering.
60
59
  * @see {@link defineComponentRegistry}
61
60
  */
62
- declare function renderSpec(spec: Spec, registry: ComponentRegistry): ReactNode;
61
+ export declare function renderSpec(spec: Spec, registry: ComponentRegistry): ReactNode;
63
62
  /**
64
63
  * Renders a Drupal Canvas component tree.
65
64
  *
@@ -67,7 +66,7 @@ declare function renderSpec(spec: Spec, registry: ComponentRegistry): ReactNode;
67
66
  * @param registry - Component registry to use for rendering.
68
67
  * @see {@link defineComponentRegistry}
69
68
  */
70
- declare function renderCanvasTree(components: CanvasComponentTree, registry: ComponentRegistry): ReactNode;
69
+ export declare function renderCanvasTree(components: CanvasComponentTree, registry: ComponentRegistry): ReactNode;
71
70
  /**
72
71
  * Defines a component registry by dynamically importing each component's
73
72
  * JavaScript entry file from the discovery results.
@@ -78,7 +77,7 @@ declare function renderCanvasTree(components: CanvasComponentTree, registry: Com
78
77
  * @param components - Array of discovered components from `discoverCanvasProject()`
79
78
  * @returns A component registry that can be passed to `renderCanvasTree()`
80
79
  */
81
- declare function defineComponentRegistry(components: {
80
+ export declare function defineComponentRegistry(components: {
82
81
  name: string;
83
82
  jsEntryPath: string | null;
84
83
  }[]): Promise<ComponentRegistry>;
@@ -90,7 +89,7 @@ declare function defineComponentRegistry(components: {
90
89
  * @param metadata - Array of component metadata from `loadComponentsMetadata()`
91
90
  * @returns A json-render `Catalog` instance
92
91
  */
93
- declare function defineComponentCatalog(metadata: ComponentMetadata[]): import("@json-render/core").Catalog<{
92
+ export declare function defineComponentCatalog(metadata: ComponentMetadata[]): import("@json-render/core").Catalog<{
94
93
  spec: import("@json-render/core").SchemaType<"object", {
95
94
  root: import("@json-render/core").SchemaType<"string", unknown>;
96
95
  elements: import("@json-render/core").SchemaType<"record", import("@json-render/core").SchemaType<"object", {
@@ -149,6 +148,4 @@ declare function defineComponentCatalog(metadata: ComponentMetadata[]): import("
149
148
  }>;
150
149
  data?: undefined;
151
150
  };
152
- };
153
- //#endregion
154
- export { AuthoredSpecElement, AuthoredSpecElementMap, AuthoredSpecSlots, CanvasComponentTree, CanvasComponentTreeNode, ComponentRegistry, canvasTreeToSpec, defineComponentCatalog, defineComponentRegistry, renderCanvasTree, renderSpec, specToCanvasTree };
151
+ };
@@ -3,7 +3,7 @@ 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
- //#region ../../schema.json
6
+ // ../../schema.json
7
7
  var $defs = {
8
8
  "heading-element": {
9
9
  "title": "Heading element",
@@ -418,8 +418,7 @@ var $defs = {
418
418
  "pattern": "^[a-z0-9_\\.]+$"
419
419
  }
420
420
  };
421
- //#endregion
422
- //#region src/json-render-utils.tsx
421
+ // src/json-render-utils.tsx
423
422
  /**
424
423
  * Converts an array of Drupal Canvas components to json-render spec format.
425
424
  *
@@ -750,5 +749,4 @@ function defineComponentCatalog(metadata) {
750
749
  };
751
750
  } });
752
751
  }
753
- //#endregion
754
752
  export { canvasTreeToSpec, defineComponentCatalog, defineComponentRegistry, renderCanvasTree, renderSpec, specToCanvasTree };
@@ -1,5 +1,4 @@
1
1
  import { GetOptions, JsonApiClient, JsonApiClientOptions, RawApiResponseWithData } from "@drupal-api-client/json-api-client";
2
- //#region ../../node_modules/@drupal-api-client/api-client/dist/index.d.mts
3
2
  /**
4
3
  * The base URL for all API requests.
5
4
  */
@@ -13,8 +12,6 @@ interface Cache {
13
12
  get<T>(key: string, ...args: unknown[]): Promise<T>;
14
13
  set<T>(key: string, value: T, ...args: unknown[]): Promise<unknown>;
15
14
  }
16
- //#endregion
17
- //#region src/jsonapi-proxy.d.ts
18
15
  /**
19
16
  * @file
20
17
  * Framework-agnostic URL mapping between a Drupal backend's JSON:API
@@ -141,8 +138,6 @@ declare function mapProxyPathToUpstream(proxiedPath: string, options: {
141
138
  url: string;
142
139
  endpoint: JsonApiProxyEndpointName;
143
140
  } | null;
144
- //#endregion
145
- //#region src/jsonapi-client.d.ts
146
141
  type EndpointUrlSegments = Parameters<JsonApiClient['createURL']>[0];
147
142
  /**
148
143
  * Serializable JSON:API runtime configuration. Rendering integrations receive
@@ -257,6 +252,8 @@ declare class CanvasJsonApiClient extends JsonApiClient {
257
252
  readonly resourceVersion: string | null;
258
253
  /** Where JSON:API requests go (base URL, prefix, foreign site or not). */
259
254
  private readonly apiBase;
255
+ /** Resource types Drupal reads without revisions (see `getResource()`). */
256
+ private readonly unversionedTypes;
260
257
  constructor(config: JsonApiClientConfig);
261
258
  /**
262
259
  * Obtaining or renewing the configured credentials is part of the session
@@ -278,13 +275,25 @@ declare class CanvasJsonApiClient extends JsonApiClient {
278
275
  * one explicitly.
279
276
  */
280
277
  private withResourceVersion;
278
+ /**
279
+ * Resource reads apply the configured resource version. Drupal answers a
280
+ * versioned read of a resource type without revisions with 501 Not
281
+ * Implemented; the read is then repeated once without the version. When
282
+ * that returns the requested JSON:API resource without a `working-copy`
283
+ * link (which Drupal adds to every revisionable resource), the type is read
284
+ * without the version from then on. Any other response keeps the original
285
+ * one; a failed request throws as any read does. Raw responses and
286
+ * caller-selected versions bypass this.
287
+ */
281
288
  getResource<T>(type: string, resourceId: string, options?: GetOptions): Promise<T | RawApiResponseWithData<T>>;
282
289
  /**
283
- * Collection reads at a resource version fetch each item's working copy in
284
- * a separate request, because Drupal returns default revisions in
285
- * collections. Working copies are merged into the raw document before the
286
- * serializer runs. A failing ordinary item fetch keeps the original item;
287
- * draft-session errors propagate. Raw responses bypass this.
290
+ * Collection reads at a resource version fetch the working copy of each
291
+ * item that links to one in a separate request, because Drupal returns
292
+ * default revisions in collections. Items of types without revisions have
293
+ * no `working-copy` link and are kept. Working copies are merged into the
294
+ * raw document before the serializer runs. A failing ordinary item fetch
295
+ * keeps the original item; draft-session errors propagate. Raw responses
296
+ * bypass this.
288
297
  *
289
298
  * An omitted or false rawResponse returns the deserialized T. A literal
290
299
  * true returns the response wrapper; a dynamic flag retains both types.
@@ -325,5 +334,4 @@ declare function createJsonApiClient(config: JsonApiClientConfig): CanvasJsonApi
325
334
  declare class LegacyJsonApiClient extends CanvasJsonApiClient {
326
335
  constructor(baseUrl?: BaseUrl, options?: JsonApiClientOptions);
327
336
  }
328
- //#endregion
329
337
  export { trimSlashes as C, toBackendRelativePath as S, mapJsonApiRequestToProxy as _, LegacyJsonApiClient as a, resolveJsonApiBase as b, DEFAULT_JSONAPI_PREFIX as c, JSONAPI_PROXY_SESSION_EXPIRED as d, JSONAPI_PROXY_SESSION_HEADER as f, isSafeProxyPath as g, ResolvedJsonApiProxyPath as h, JsonApiRuntimeConfig as i, DEFAULT_ROUTER_PREFIX as l, JsonApiProxyEndpoints as m, DraftSessionError as n, createJsonApiClient as o, JsonApiProxyEndpointName as p, JsonApiClientConfig as r, isDraftSessionError as s, CanvasJsonApiClient as t, JSONAPI_DRAFT_SESSION_EXPIRED_ERROR as u, mapProxyPathToUpstream as v, resolveJsonApiProxyPath as x, normalizeBaseUrl as y };
@@ -1,3 +1,3 @@
1
- import { C as trimSlashes, S as toBackendRelativePath, _ as mapJsonApiRequestToProxy, a as LegacyJsonApiClient, b as resolveJsonApiBase, c as DEFAULT_JSONAPI_PREFIX, d as JSONAPI_PROXY_SESSION_EXPIRED, f as JSONAPI_PROXY_SESSION_HEADER, g as isSafeProxyPath, h as ResolvedJsonApiProxyPath, i as JsonApiRuntimeConfig, l as DEFAULT_ROUTER_PREFIX, m as JsonApiProxyEndpoints, n as DraftSessionError, o as createJsonApiClient, p as JsonApiProxyEndpointName, r as JsonApiClientConfig, s as isDraftSessionError, t as CanvasJsonApiClient, u as JSONAPI_DRAFT_SESSION_EXPIRED_ERROR, v as mapProxyPathToUpstream, x as resolveJsonApiProxyPath, y as normalizeBaseUrl } from "./jsonapi-client-BAQ3V5CC.js";
1
+ import { C as trimSlashes, S as toBackendRelativePath, _ as mapJsonApiRequestToProxy, a as LegacyJsonApiClient, b as resolveJsonApiBase, c as DEFAULT_JSONAPI_PREFIX, d as JSONAPI_PROXY_SESSION_EXPIRED, f as JSONAPI_PROXY_SESSION_HEADER, g as isSafeProxyPath, h as ResolvedJsonApiProxyPath, i as JsonApiRuntimeConfig, l as DEFAULT_ROUTER_PREFIX, m as JsonApiProxyEndpoints, n as DraftSessionError, o as createJsonApiClient, p as JsonApiProxyEndpointName, r as JsonApiClientConfig, s as isDraftSessionError, t as CanvasJsonApiClient, u as JSONAPI_DRAFT_SESSION_EXPIRED_ERROR, v as mapProxyPathToUpstream, x as resolveJsonApiProxyPath, y as normalizeBaseUrl } from "./jsonapi-client-CKzxh1on.js";
2
2
  export * from "@drupal-api-client/json-api-client";
3
3
  export { CanvasJsonApiClient, DEFAULT_JSONAPI_PREFIX, DEFAULT_ROUTER_PREFIX, DraftSessionError, JSONAPI_DRAFT_SESSION_EXPIRED_ERROR, JSONAPI_PROXY_SESSION_EXPIRED, JSONAPI_PROXY_SESSION_HEADER, LegacyJsonApiClient as JsonApiClient, JsonApiClientConfig, type JsonApiProxyEndpointName, type JsonApiProxyEndpoints, JsonApiRuntimeConfig, type ResolvedJsonApiProxyPath, createJsonApiClient, isDraftSessionError, isSafeProxyPath, mapJsonApiRequestToProxy, mapProxyPathToUpstream, normalizeBaseUrl, resolveJsonApiBase, resolveJsonApiProxyPath, toBackendRelativePath, trimSlashes };