drupal-canvas 0.1.2 → 0.2.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
@@ -40,8 +40,13 @@ Access information about the current page.
40
40
  ```js
41
41
  import { getPageData } from 'drupal-canvas';
42
42
 
43
- const { pageTitle, breadcrumbs } = getPageData();
43
+ const { pageTitle, breadcrumbs, mainEntity } = getPageData();
44
+ const { bundle, entityTypeId, uuid } = mainEntity;
44
45
  ```
46
+ #### Main entity metadata
47
+ The main entity is the primary Drupal entity (e.g. article, canvas_page, blog) associated with the current page.
48
+ Access main entity metadata of the page you are on with `getPageData`. This can be used to construct JSON:API parameters for requests.
49
+ [View documentation and example here.](https://project.pages.drupalcode.org/canvas/code-components/data-fetching#main-entity-metadata)
45
50
 
46
51
  ### `getSiteData`
47
52
 
@@ -1,3 +1,5 @@
1
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
2
+
1
3
  //#region src/FormattedText.d.ts
2
4
  type FormattedTextProps = {
3
5
  children: string;
@@ -11,6 +13,6 @@ declare function FormattedText({
11
13
  children,
12
14
  as,
13
15
  ...props
14
- }: FormattedTextProps): any;
16
+ }: FormattedTextProps): react_jsx_runtime0.JSX.Element;
15
17
  //#endregion
16
18
  export { FormattedText as t };
@@ -1,2 +1,2 @@
1
- import { t as FormattedText } from "./FormattedText-CcQ03VEY.js";
1
+ import { t as FormattedText } from "./FormattedText-BjQdnNmH.js";
2
2
  export { FormattedText as default };
@@ -26,9 +26,15 @@ interface BreadcrumbLink {
26
26
  text: string;
27
27
  url: string;
28
28
  }
29
+ interface EntityMetadata {
30
+ bundle: string;
31
+ entityTypeId: string;
32
+ uuid: string;
33
+ }
29
34
  interface PageData {
30
35
  pageTitle: string;
31
36
  breadcrumbs: Array<BreadcrumbLink>;
37
+ mainEntity: EntityMetadata | null;
32
38
  }
33
39
  interface SiteData {
34
40
  branding: {
@@ -38,7 +38,8 @@ function sortMenu(linkset) {
38
38
  const getPageData = () => {
39
39
  const pageData = {
40
40
  pageTitle: window.drupalSettings?.canvasData?.v0?.pageTitle || "",
41
- breadcrumbs: window.drupalSettings?.canvasData?.v0?.breadcrumbs || []
41
+ breadcrumbs: window.drupalSettings?.canvasData?.v0?.breadcrumbs || [],
42
+ mainEntity: window.drupalSettings?.canvasData?.v0?.mainEntity || null
42
43
  };
43
44
  window.parent.postMessage({
44
45
  type: "_canvas_useswr_data_fetch",
@@ -1,2 +1,2 @@
1
- import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-CqLfxx9F.js";
1
+ import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-ByF92Aue.js";
2
2
  export { getPageData, getSiteData, sortMenu };
@@ -1,3 +1,3 @@
1
- import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-Dfvj3HlO.js";
1
+ import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-C41ZWu0D.js";
2
2
 
3
3
  export { getPageData, getSiteData, sortMenu };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { t as FormattedText } from "./FormattedText-CcQ03VEY.js";
2
- import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-CqLfxx9F.js";
1
+ import { t as FormattedText } from "./FormattedText-BjQdnNmH.js";
2
+ import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-ByF92Aue.js";
3
3
  import { t as CanvasJsonApiClient } from "./jsonapi-client-BamGkTjn.js";
4
4
  import { n as sortMenu$1, t as getNodePath } from "./jsonapi-utils-co82I5eL.js";
5
- import { t as Image } from "./next-image-standalone-CHJW9_qx.js";
5
+ import { t as Image } from "./next-image-standalone-BqTHJhzr.js";
6
6
  import { t as cn } from "./utils-Cn7jrjo0.js";
7
7
  export { FormattedText, Image, CanvasJsonApiClient as JsonApiClient, cn, getNodePath, getPageData, getSiteData, sortMenu as sortLinksetMenu, sortMenu$1 as sortMenu };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-Dfvj3HlO.js";
1
+ import { n as getSiteData, r as sortMenu, t as getPageData } from "./drupal-utils-C41ZWu0D.js";
2
2
  import { t as FormattedText } from "./FormattedText-B8Lu3ByU.js";
3
- import { t as CanvasJsonApiClient } from "./jsonapi-client-jLXdE88j.js";
3
+ import { t as CanvasJsonApiClient } from "./jsonapi-client-BydDHnEY.js";
4
4
  import { n as sortMenu$1, t as getNodePath } from "./jsonapi-utils-oywSkEdN.js";
5
5
  import { t as Image } from "./next-image-standalone-B4uHVOA8.js";
6
6
  import { t as cn } from "./utils-DG-hPO0N.js";
@@ -1,5 +1,4 @@
1
- import { Jsona } from "jsona";
2
- import { JsonApiClient } from "@drupal-api-client/json-api-client";
1
+ import { DefaultSerializer, JsonApiClient } from "@drupal-api-client/json-api-client";
3
2
 
4
3
  //#region src/jsonapi-client.ts
5
4
  var CanvasJsonApiClient = class extends JsonApiClient {
@@ -9,7 +8,7 @@ var CanvasJsonApiClient = class extends JsonApiClient {
9
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://...\")`");
10
9
  const clientOptions = {
11
10
  apiPrefix: window.drupalSettings?.canvasData?.v0?.jsonapiSettings?.apiPrefix,
12
- serializer: new Jsona(),
11
+ serializer: new DefaultSerializer(),
13
12
  ...options
14
13
  };
15
14
  super(clientBaseUrl, clientOptions);
@@ -1,4 +1,4 @@
1
- import { t as CanvasJsonApiClient } from "./jsonapi-client-jLXdE88j.js";
1
+ import { t as CanvasJsonApiClient } from "./jsonapi-client-BydDHnEY.js";
2
2
 
3
3
  export * from "@drupal-api-client/json-api-client"
4
4
 
@@ -1,8 +1,9 @@
1
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
1
2
  import { ImageLoaderParams, ImageProps } from "next-image-standalone";
2
3
 
3
4
  //#region src/next-image-standalone.d.ts
4
5
  declare function Image(props: Omit<ImageProps, 'loader'> & {
5
6
  loader?: (params: ImageLoaderParams) => string;
6
- }): any;
7
+ }): react_jsx_runtime0.JSX.Element;
7
8
  //#endregion
8
9
  export { Image as t };
@@ -1,2 +1,2 @@
1
- import { t as Image } from "./next-image-standalone-CHJW9_qx.js";
1
+ import { t as Image } from "./next-image-standalone-BqTHJhzr.js";
2
2
  export { Image as default };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "drupal-canvas",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Utilities and base components for building Drupal Canvas Code Components",
5
- "license": "GPL-2.0-or-later",
5
+ "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://git.drupalcode.org/project/canvas.git",
@@ -50,9 +50,8 @@
50
50
  "drupal"
51
51
  ],
52
52
  "dependencies": {
53
- "@drupal-api-client/json-api-client": "^1.3.0",
53
+ "@drupal-api-client/json-api-client": "^1.4.0",
54
54
  "clsx": "^2.1.1",
55
- "jsona": "^1.12.1",
56
55
  "next-image-standalone": "^0.1.3",
57
56
  "tailwind-merge": "^3.0.2"
58
57
  },
@@ -1,16 +0,0 @@
1
- {
2
- "configurations": [
3
- {
4
- "name": "Listen for Xdebug",
5
- "type": "php",
6
- "request": "launch",
7
- "hostname": "0.0.0.0",
8
- "port": 9003,
9
- "pathMappings": {
10
- "/var/www/html": "${workspaceFolder}"
11
- },
12
- "preLaunchTask": "DDEV: Enable Xdebug",
13
- "postDebugTask": "DDEV: Disable Xdebug"
14
- }
15
- ]
16
- }
@@ -1,3 +0,0 @@
1
- {
2
- "intelephense.environment.phpVersion": "8.3"
3
- }
@@ -1,23 +0,0 @@
1
- {
2
- "version": "2.0.0",
3
- "tasks": [
4
- {
5
- "label": "DDEV: Enable Xdebug",
6
- "type": "shell",
7
- "command": "ddev xdebug on",
8
- "presentation": {
9
- "reveal": "silent",
10
- "close": true
11
- }
12
- },
13
- {
14
- "label": "DDEV: Disable Xdebug",
15
- "type": "shell",
16
- "command": "ddev xdebug off",
17
- "presentation": {
18
- "reveal": "silent",
19
- "close": true
20
- }
21
- }
22
- ]
23
- }