drupal-canvas 0.7.0 → 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 +33 -4
- package/dist/FormattedText.d.ts +1 -4
- package/dist/FormattedText.js +1 -2
- package/dist/context-DMp0nsTU.d.ts +94 -0
- package/dist/{drupal-utils-CUaK4jOk.d.ts → drupal-utils-BIiH7B6O.d.ts} +31 -5
- package/dist/drupal-utils.d.ts +1 -1
- package/dist/drupal-utils.js +2 -3
- package/dist/index.d.ts +18 -120
- package/dist/index.js +11 -153
- package/dist/json-render-utils.d.ts +13 -16
- package/dist/json-render-utils.js +2 -4
- package/dist/{jsonapi-client-BAQ3V5CC.d.ts → jsonapi-client-CKzxh1on.d.ts} +19 -11
- package/dist/jsonapi-client.d.ts +1 -1
- package/dist/jsonapi-client.js +617 -1
- package/dist/jsonapi-utils.d.ts +2 -5
- package/dist/jsonapi-utils.js +1 -2
- package/dist/{migration-CPBzW78_.js → migration-CxRMGzhm.js} +2 -4
- package/dist/next-image-standalone.d.ts +2 -5
- package/dist/next-image-standalone.js +1 -2
- package/dist/react.d.ts +54 -8
- package/dist/react.js +188 -10
- package/dist/utils.d.ts +1 -4
- package/dist/utils.js +1 -2
- package/package.json +2 -2
- package/dist/context-Cb4HbPbR.d.ts +0 -32
- package/dist/jsonapi-client-CejP62bM.js +0 -539
package/dist/index.js
CHANGED
|
@@ -1,155 +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 {
|
|
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
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Reads the Drupal-selected langcode from Canvas runtime settings when present,
|
|
13
|
-
* falling back to `drupalSettings.langcode` and then 'en'.
|
|
14
|
-
*
|
|
15
|
-
* Canvas attaches `canvasData.v0.langcode` for every code component that imports
|
|
16
|
-
* one of these utilities: the import adds `v0.langcode` to the component's
|
|
17
|
-
* `dataDependencies.drupalSettings`. Drupal core only sets
|
|
18
|
-
* `drupalSettings.langcode` on pages with a machine name form element, so that
|
|
19
|
-
* fallback is not a langcode source on rendered pages.
|
|
20
|
-
*
|
|
21
|
-
* @see ui/src/features/code-editor/utils/ast-utils.ts
|
|
22
|
-
*/
|
|
23
|
-
const getDrupalLangcode = () => globalThis.drupalSettings?.canvasData?.v0?.langcode ?? globalThis.drupalSettings?.langcode ?? "en";
|
|
24
|
-
/**
|
|
25
|
-
* Creates an `Intl.DateTimeFormat` instance, falling back to 'en' locale if
|
|
26
|
-
* the Drupal langcode string is not a valid BCP 47 tag.
|
|
27
|
-
*
|
|
28
|
-
* Drupal langcodes like `zh-hans` or `pt-br` use lowercase language tag
|
|
29
|
-
* components which may throw `RangeError` in strict BCP 47 environments.
|
|
30
|
-
* The try/catch ensures graceful degradation.
|
|
31
|
-
*
|
|
32
|
-
* All formatters use `timeZone: 'UTC'` because Canvas date/datetime props are
|
|
33
|
-
* stored without timezone offset. Formatting in the local browser timezone
|
|
34
|
-
* would silently shift dates — e.g. a UTC midnight date would appear as the
|
|
35
|
-
* previous day in negative-UTC-offset timezones (Americas).
|
|
36
|
-
*/
|
|
37
|
-
const createFormatter = (locale, options) => {
|
|
38
|
-
const utcOptions = {
|
|
39
|
-
timeZone: "UTC",
|
|
40
|
-
...options
|
|
41
|
-
};
|
|
42
|
-
try {
|
|
43
|
-
return new Intl.DateTimeFormat(locale, utcOptions);
|
|
44
|
-
} catch {
|
|
45
|
-
return new Intl.DateTimeFormat("en", utcOptions);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
/**
|
|
49
|
-
* Parses an ISO string to a Date object, returning null on failure.
|
|
50
|
-
*
|
|
51
|
-
* ECMAScript parses a date-time string without a UTC offset as local time,
|
|
52
|
-
* whereas date-only strings are parsed as UTC. Canvas treats every stored
|
|
53
|
-
* value as UTC (the PHP side appends `Z` before formatting), so a `Z` is
|
|
54
|
-
* appended to date-time strings that carry no offset. Without it, the UTC
|
|
55
|
-
* formatter would shift the value by the viewer's UTC offset.
|
|
56
|
-
*/
|
|
57
|
-
const parseIso = (iso) => {
|
|
58
|
-
if (!iso) return null;
|
|
59
|
-
const hasTimePart = /[T ]\d{2}:\d{2}/.test(iso);
|
|
60
|
-
const hasOffset = /(Z|[+-]\d{2}(:?\d{2})?)$/i.test(iso);
|
|
61
|
-
const d = new Date(hasTimePart && !hasOffset ? `${iso}Z` : iso);
|
|
62
|
-
return isNaN(d.getTime()) ? null : d;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Formats an ISO date string using the active Drupal locale's date format.
|
|
66
|
-
*
|
|
67
|
-
* Returns the original `iso` string unchanged if it cannot be parsed, and an
|
|
68
|
-
* empty string for `null` or `undefined` (an optional prop without a value).
|
|
69
|
-
*
|
|
70
|
-
* @param iso
|
|
71
|
-
* ISO date string, e.g. '2026-01-15'.
|
|
72
|
-
* @param options
|
|
73
|
-
* Optional format overrides. Defaults to `{ dateStyle: 'short' }`.
|
|
74
|
-
*
|
|
75
|
-
* @return
|
|
76
|
-
* Locale-formatted date string, e.g. '1/15/26' (en) or '15/01/2026' (fr).
|
|
77
|
-
*/
|
|
78
|
-
function canvasFormatDate(iso, options) {
|
|
79
|
-
if (iso == null) return "";
|
|
80
|
-
const date = parseIso(iso);
|
|
81
|
-
if (!date) return iso;
|
|
82
|
-
return createFormatter(getDrupalLangcode(), { dateStyle: options?.dateStyle ?? "short" }).format(date);
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* Formats an ISO datetime string using the active Drupal locale's format.
|
|
86
|
-
*
|
|
87
|
-
* Returns the original `iso` string unchanged if it cannot be parsed, and an
|
|
88
|
-
* empty string for `null` or `undefined` (an optional prop without a value).
|
|
89
|
-
*
|
|
90
|
-
* @param iso
|
|
91
|
-
* ISO datetime string, e.g. '2026-01-15T14:30:00Z'.
|
|
92
|
-
* @param options
|
|
93
|
-
* Optional format overrides. Defaults to
|
|
94
|
-
* `{ dateStyle: 'short', timeStyle: 'short' }`.
|
|
95
|
-
*
|
|
96
|
-
* @return
|
|
97
|
-
* Locale-formatted datetime string.
|
|
98
|
-
*/
|
|
99
|
-
function canvasFormatDateTime(iso, options) {
|
|
100
|
-
if (iso == null) return "";
|
|
101
|
-
const date = parseIso(iso);
|
|
102
|
-
if (!date) return iso;
|
|
103
|
-
return createFormatter(getDrupalLangcode(), {
|
|
104
|
-
dateStyle: options?.dateStyle ?? "short",
|
|
105
|
-
timeStyle: options?.timeStyle ?? "short"
|
|
106
|
-
}).format(date);
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Formats an ISO time/datetime string using the active Drupal locale's time format.
|
|
110
|
-
*
|
|
111
|
-
* Returns the original `iso` string unchanged if it cannot be parsed, and an
|
|
112
|
-
* empty string for `null` or `undefined` (an optional prop without a value).
|
|
113
|
-
*
|
|
114
|
-
* @param iso
|
|
115
|
-
* ISO time or datetime string, e.g. '14:30:00' or '2026-01-15T14:30:00Z'.
|
|
116
|
-
* @param options
|
|
117
|
-
* Optional format overrides. Defaults to `{ timeStyle: 'short' }`.
|
|
118
|
-
*
|
|
119
|
-
* @return
|
|
120
|
-
* Locale-formatted time string.
|
|
121
|
-
*/
|
|
122
|
-
function canvasFormatTime(iso, options) {
|
|
123
|
-
if (iso == null) return "";
|
|
124
|
-
const normalized = /^\d{2}:\d{2}/.test(iso) ? `1970-01-01T${iso}` : iso;
|
|
125
|
-
const date = parseIso(normalized);
|
|
126
|
-
if (!date) return iso;
|
|
127
|
-
return createFormatter(getDrupalLangcode(), { timeStyle: options?.timeStyle ?? "short" }).format(date);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Formats the `from` and `to` fields of a Canvas date-range prop.
|
|
131
|
-
*
|
|
132
|
-
* Returns `null` or `undefined` unchanged (an optional prop without a value).
|
|
133
|
-
*
|
|
134
|
-
* @param range
|
|
135
|
-
* Canvas date-range object, e.g. `{ from: '2026-01-15', to: '2026-03-20' }`.
|
|
136
|
-
* @param options
|
|
137
|
-
* Optional format overrides passed to each field. Defaults to
|
|
138
|
-
* `{ dateStyle: 'short' }`.
|
|
139
|
-
*
|
|
140
|
-
* @return
|
|
141
|
-
* A new object with the same keys; each string date value is replaced with a
|
|
142
|
-
* formatted string.
|
|
143
|
-
*/
|
|
144
|
-
function canvasFormatDateRange(range, options) {
|
|
145
|
-
if (range == null) return range;
|
|
146
|
-
const result = { ...range };
|
|
147
|
-
if (typeof result.from === "string") result.from = canvasFormatDate(result.from, options);
|
|
148
|
-
if (typeof result.to === "string") result.to = canvasFormatDate(result.to, options);
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
|
-
//#endregion
|
|
152
|
-
//#region src/drupal-settings.ts
|
|
10
|
+
// src/drupal-settings.ts
|
|
153
11
|
/** Reads `drupalSettings.canvasData.v0` from a settings object or the global. */
|
|
154
12
|
function readCanvasDataV0(settings = globalThis.drupalSettings) {
|
|
155
13
|
const v0 = settings?.canvasData?.v0;
|
|
@@ -167,7 +25,7 @@ const EMPTY_THEME_ASSETS = {
|
|
|
167
25
|
*
|
|
168
26
|
* Page context is available when Drupal attached any page-level key
|
|
169
27
|
* (`pageTitle`, `breadcrumbs`, or `mainEntity`); site context when it attached
|
|
170
|
-
* `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
|
|
171
29
|
* as the legacy getters.
|
|
172
30
|
*/
|
|
173
31
|
function drupalSettingsToCanvasContext(v0) {
|
|
@@ -176,7 +34,7 @@ function drupalSettingsToCanvasContext(v0) {
|
|
|
176
34
|
site: null
|
|
177
35
|
};
|
|
178
36
|
const hasPage = "pageTitle" in v0 || "breadcrumbs" in v0 || "mainEntity" in v0;
|
|
179
|
-
const hasSite = "branding" in v0;
|
|
37
|
+
const hasSite = "branding" in v0 || "langcode" in v0;
|
|
180
38
|
return {
|
|
181
39
|
page: hasPage ? {
|
|
182
40
|
pageTitle: v0.pageTitle || "",
|
|
@@ -190,8 +48,10 @@ function drupalSettingsToCanvasContext(v0) {
|
|
|
190
48
|
siteSlogan: ""
|
|
191
49
|
},
|
|
192
50
|
baseUrl: v0.baseUrl || "/",
|
|
193
|
-
themeAssets: v0.themeAssets || EMPTY_THEME_ASSETS
|
|
194
|
-
|
|
51
|
+
themeAssets: v0.themeAssets || EMPTY_THEME_ASSETS,
|
|
52
|
+
...v0.langcode && { langcode: v0.langcode }
|
|
53
|
+
} : null,
|
|
54
|
+
...v0.translations && { translations: v0.translations }
|
|
195
55
|
};
|
|
196
56
|
}
|
|
197
57
|
/**
|
|
@@ -211,8 +71,7 @@ function drupalSettingsToJsonApiRuntimeConfig(v0, options = {}) {
|
|
|
211
71
|
preview
|
|
212
72
|
};
|
|
213
73
|
}
|
|
214
|
-
|
|
215
|
-
//#region src/Region.tsx
|
|
74
|
+
// src/Region.tsx
|
|
216
75
|
const RegionsContext = createContext({});
|
|
217
76
|
/**
|
|
218
77
|
* Supplies the region node map read by `Region`.
|
|
@@ -236,5 +95,4 @@ function Region({ name, fallback = null }) {
|
|
|
236
95
|
const node = useContext(RegionsContext)[name];
|
|
237
96
|
return /* @__PURE__ */ jsx(Fragment, { children: node ?? fallback });
|
|
238
97
|
}
|
|
239
|
-
|
|
240
|
-
export { AGENT_MIGRATION_PROMPT, DraftSessionError, FormattedText, Image, LegacyJsonApiClient as JsonApiClient, LEGACY_API_GUIDANCE, Region, RegionsProvider, canvasFormatDate, canvasFormatDateRange, canvasFormatDateTime, canvasFormatTime, cn, createJsonApiClient, declareCanvasRuntime, drupalSettingsToCanvasContext, drupalSettingsToJsonApiRuntimeConfig, formatLegacyApiError, getCanvasRuntime, getNodePath, getPageData, getSiteData, isDraftSessionError, isLegacyRuntimeSupported, readCanvasDataV0, sortMenu as sortLinksetMenu, sortMenu$1 as sortMenu };
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
284
|
-
* a separate request, because Drupal returns
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
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 };
|
package/dist/jsonapi-client.d.ts
CHANGED
|
@@ -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-
|
|
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 };
|