@freelygive/canvas-utils 0.3.3-dev.770641bc → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@freelygive/canvas-utils",
3
- "version": "0.3.3-dev.770641bc",
3
+ "version": "0.3.3",
4
4
  "description": "Canvas utility components and test helpers for Drupal Canvas projects.",
5
5
  "type": "module",
6
6
  "files": [
@@ -5,23 +5,20 @@ import useSWR from 'swr';
5
5
  /**
6
6
  * Fetch the main entity for the current page using SWR.
7
7
  * Uses Canvas mainEntity (when available) with fallback to title-based lookup.
8
- *
9
- * @param {string} entityType - The JSON:API entity type (e.g., 'node--news_article').
10
- * @param {Object} [options] - Fetch options.
11
- * @param {string[]} [options.includes] - Relationships to include.
12
- * @param {Object} [options.fields] - Sparse fieldset map (e.g., { 'node--news_article': ['title'] }).
8
+ * @param {string} entityType - The JSON:API entity type (e.g., 'node--news_article')
9
+ * @param {object} options - Fetch options
10
+ * @param {string[]} options.includes - Relationships to include
11
+ * @param {object} options.fields - Sparse fieldset map (e.g., { 'node--news_article': ['title'] })
13
12
  * @returns {{ data: object|undefined, error: Error|undefined, isLoading: boolean }}
14
13
  */
15
14
  export const useMainEntity = (
16
15
  entityType,
17
16
  { includes = [], fields = {} } = {},
18
17
  ) => {
19
- // mainEntity will be available in future Canvas versions.
20
- const pageData =
21
- /** @type {{ pageTitle: string, mainEntity?: { uuid: string } }} */ (
22
- getPageData()
23
- );
24
- const { pageTitle, mainEntity } = pageData;
18
+ const pageData = getPageData();
19
+ const { pageTitle } = pageData;
20
+ // mainEntity will be available in future Canvas versions
21
+ const mainEntity = pageData.mainEntity;
25
22
  const entityId = mainEntity?.uuid || pageTitle || null;
26
23
 
27
24
  return useSWR(
@@ -11,9 +11,8 @@ const flattenChildren = (children) => {
11
11
  React.Children.forEach(children, (child) => {
12
12
  if (!child) return;
13
13
  // Check if it's a Fragment (type is Symbol(react.fragment))
14
- const el = /** @type {React.ReactElement} */ (child);
15
- if (el.type === React.Fragment) {
16
- result.push(...flattenChildren(el.props.children));
14
+ if (child?.type === React.Fragment) {
15
+ result.push(...flattenChildren(child.props.children));
17
16
  } else {
18
17
  result.push(child);
19
18
  }