@sitecore-content-sdk/react 0.2.0-beta.4 → 0.2.0-canary.10

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.
@@ -38,7 +38,6 @@ const react_1 = __importStar(require("react"));
38
38
  const Placeholder_1 = require("./Placeholder");
39
39
  const layout_1 = require("@sitecore-content-sdk/core/layout");
40
40
  const editing_1 = require("@sitecore-content-sdk/core/editing");
41
- const EditingScripts_1 = require("./EditingScripts");
42
41
  const DesignLibrary = (layoutData) => {
43
42
  const { route } = layoutData.sitecore;
44
43
  const [renderKey, setRenderKey] = (0, react_1.useState)(0);
@@ -73,7 +72,6 @@ const DesignLibrary = (layoutData) => {
73
72
  window.top.postMessage((0, editing_1.getDesignLibraryStatusEvent)(editing_1.DesignLibraryStatus.RENDERED, rootComponent.uid), '*');
74
73
  }, [renderKey, rootComponent.uid]);
75
74
  return (react_1.default.createElement(react_1.default.Fragment, null,
76
- react_1.default.createElement(EditingScripts_1.EditingScripts, null),
77
75
  react_1.default.createElement("main", null,
78
76
  react_1.default.createElement("div", { id: layout_1.EDITING_COMPONENT_ID }, route && (react_1.default.createElement(Placeholder_1.Placeholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, rendering: route, key: renderKey }))))));
79
77
  };
@@ -33,10 +33,21 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Form = void 0;
36
+ exports.Form = exports.mockFormModule = void 0;
37
37
  const react_1 = __importStar(require("react"));
38
- const form_1 = require("@sitecore-content-sdk/core/form");
38
+ const core_1 = require("@sitecore-content-sdk/core");
39
39
  const withSitecoreContext_1 = require("../enhancers/withSitecoreContext");
40
+ let { executeScriptElements, loadForm, subscribeToFormSubmitEvent } = core_1.form;
41
+ /**
42
+ * Mock function to replace the form module functions for `testing` purposes.
43
+ * @param {any} formModule - The form module to mock
44
+ */
45
+ const mockFormModule = (formModule) => {
46
+ executeScriptElements = formModule.executeScriptElements;
47
+ loadForm = formModule.loadForm;
48
+ subscribeToFormSubmitEvent = formModule.subscribeToFormSubmitEvent;
49
+ };
50
+ exports.mockFormModule = mockFormModule;
40
51
  const Form = ({ params, rendering }) => {
41
52
  var _a;
42
53
  const id = params === null || params === void 0 ? void 0 : params.RenderingIdentifier;
@@ -48,7 +59,7 @@ const Form = ({ params, rendering }) => {
48
59
  (0, react_1.useEffect)(() => {
49
60
  var _a, _b, _c, _d;
50
61
  if (!content) {
51
- (0, form_1.loadForm)((_b = (_a = context.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId, params.FormId, (_d = (_c = context.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.edgeUrl)
62
+ loadForm((_b = (_a = context.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.contextId, params.FormId, (_d = (_c = context.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.edgeUrl)
52
63
  .then(setContent)
53
64
  .catch(() => {
54
65
  if (isEditing) {
@@ -60,9 +71,9 @@ const Form = ({ params, rendering }) => {
60
71
  else {
61
72
  // If we are in editing mode, we don't want to send any events
62
73
  if (!isEditing) {
63
- (0, form_1.subscribeToFormSubmitEvent)(formRef.current, rendering.uid);
74
+ subscribeToFormSubmitEvent(formRef.current, rendering.uid);
64
75
  }
65
- (0, form_1.executeScriptElements)(formRef.current);
76
+ executeScriptElements(formRef.current);
66
77
  }
67
78
  }, [content]);
68
79
  if (isEditing) {
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.DefaultEditingError = void 0;
7
7
  exports.withDatasourceCheck = withDatasourceCheck;
8
8
  const react_1 = __importDefault(require("react"));
9
+ const layout_1 = require("@sitecore-content-sdk/core/layout");
9
10
  const withSitecoreContext_1 = require("./withSitecoreContext");
10
11
  const DefaultEditingError = () => (react_1.default.createElement("div", { className: "sc-jss-editing-error", role: "alert" }, "Datasource is required. Please choose a content item for this component."));
11
12
  exports.DefaultEditingError = DefaultEditingError;
@@ -22,7 +23,9 @@ function withDatasourceCheck(options) {
22
23
  var _a, _b;
23
24
  const { sitecoreContext } = (0, withSitecoreContext_1.useSitecoreContext)();
24
25
  const EditingError = (_a = options === null || options === void 0 ? void 0 : options.editingErrorComponent) !== null && _a !== void 0 ? _a : exports.DefaultEditingError;
25
- return ((_b = props.rendering) === null || _b === void 0 ? void 0 : _b.dataSource) ? (react_1.default.createElement(Component, Object.assign({}, props))) : sitecoreContext.pageEditing ? (react_1.default.createElement(EditingError, null)) : null;
26
+ // If the component is rendered in DesignLibrary, we don't need to check for datasource
27
+ const isDesignLibrary = (sitecoreContext === null || sitecoreContext === void 0 ? void 0 : sitecoreContext.renderingType) === layout_1.RenderingType.Component;
28
+ return isDesignLibrary || ((_b = props.rendering) === null || _b === void 0 ? void 0 : _b.dataSource) ? (react_1.default.createElement(Component, Object.assign({}, props))) : sitecoreContext.pageEditing ? (react_1.default.createElement(EditingError, null)) : null;
26
29
  };
27
30
  };
28
31
  }
@@ -2,7 +2,6 @@ import React, { useEffect, useMemo, useState } from 'react';
2
2
  import { Placeholder } from './Placeholder';
3
3
  import { EDITING_COMPONENT_ID, EDITING_COMPONENT_PLACEHOLDER, } from '@sitecore-content-sdk/core/layout';
4
4
  import { DesignLibraryStatus, getDesignLibraryStatusEvent, addComponentUpdateHandler, } from '@sitecore-content-sdk/core/editing';
5
- import { EditingScripts } from './EditingScripts';
6
5
  export const DesignLibrary = (layoutData) => {
7
6
  const { route } = layoutData.sitecore;
8
7
  const [renderKey, setRenderKey] = useState(0);
@@ -37,7 +36,6 @@ export const DesignLibrary = (layoutData) => {
37
36
  window.top.postMessage(getDesignLibraryStatusEvent(DesignLibraryStatus.RENDERED, rootComponent.uid), '*');
38
37
  }, [renderKey, rootComponent.uid]);
39
38
  return (React.createElement(React.Fragment, null,
40
- React.createElement(EditingScripts, null),
41
39
  React.createElement("main", null,
42
40
  React.createElement("div", { id: EDITING_COMPONENT_ID }, route && (React.createElement(Placeholder, { name: EDITING_COMPONENT_PLACEHOLDER, rendering: route, key: renderKey }))))));
43
41
  };
@@ -1,6 +1,16 @@
1
1
  import React, { useEffect, useRef, useState } from 'react';
2
- import { executeScriptElements, loadForm, subscribeToFormSubmitEvent, } from '@sitecore-content-sdk/core/form';
2
+ import { form } from '@sitecore-content-sdk/core';
3
3
  import { useSitecoreContext } from '../enhancers/withSitecoreContext';
4
+ let { executeScriptElements, loadForm, subscribeToFormSubmitEvent } = form;
5
+ /**
6
+ * Mock function to replace the form module functions for `testing` purposes.
7
+ * @param {any} formModule - The form module to mock
8
+ */
9
+ export const mockFormModule = (formModule) => {
10
+ executeScriptElements = formModule.executeScriptElements;
11
+ loadForm = formModule.loadForm;
12
+ subscribeToFormSubmitEvent = formModule.subscribeToFormSubmitEvent;
13
+ };
4
14
  export const Form = ({ params, rendering }) => {
5
15
  var _a;
6
16
  const id = params === null || params === void 0 ? void 0 : params.RenderingIdentifier;
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { RenderingType } from '@sitecore-content-sdk/core/layout';
2
3
  import { useSitecoreContext } from './withSitecoreContext';
3
4
  export const DefaultEditingError = () => (React.createElement("div", { className: "sc-jss-editing-error", role: "alert" }, "Datasource is required. Please choose a content item for this component."));
4
5
  /**
@@ -14,7 +15,9 @@ export function withDatasourceCheck(options) {
14
15
  var _a, _b;
15
16
  const { sitecoreContext } = useSitecoreContext();
16
17
  const EditingError = (_a = options === null || options === void 0 ? void 0 : options.editingErrorComponent) !== null && _a !== void 0 ? _a : DefaultEditingError;
17
- return ((_b = props.rendering) === null || _b === void 0 ? void 0 : _b.dataSource) ? (React.createElement(Component, Object.assign({}, props))) : sitecoreContext.pageEditing ? (React.createElement(EditingError, null)) : null;
18
+ // If the component is rendered in DesignLibrary, we don't need to check for datasource
19
+ const isDesignLibrary = (sitecoreContext === null || sitecoreContext === void 0 ? void 0 : sitecoreContext.renderingType) === RenderingType.Component;
20
+ return isDesignLibrary || ((_b = props.rendering) === null || _b === void 0 ? void 0 : _b.dataSource) ? (React.createElement(Component, Object.assign({}, props))) : sitecoreContext.pageEditing ? (React.createElement(EditingError, null)) : null;
18
21
  };
19
22
  };
20
23
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/react",
3
- "version": "0.2.0-beta.4",
3
+ "version": "0.2.0-canary.10",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -39,7 +39,6 @@
39
39
  "@types/mocha": "^10.0.10",
40
40
  "@types/node": "22.12.0",
41
41
  "@types/prop-types": "^15.7.14",
42
- "@types/proxyquire": "^1.3.31",
43
42
  "@types/react": "^18.2.45",
44
43
  "@types/react-dom": "^18.0.10",
45
44
  "@types/sinon": "^17.0.3",
@@ -52,7 +51,6 @@
52
51
  "jsdom": "^26.0.0",
53
52
  "mocha": "^11.1.0",
54
53
  "nyc": "^17.1.0",
55
- "proxyquire": "^2.1.3",
56
54
  "react": "^18.2.0",
57
55
  "react-dom": "^18.2.0",
58
56
  "sinon": "^19.0.2",
@@ -67,13 +65,13 @@
67
65
  "react-dom": "^18.2.0"
68
66
  },
69
67
  "dependencies": {
70
- "@sitecore-content-sdk/core": "0.2.0-beta.4",
68
+ "@sitecore-content-sdk/core": "0.2.0-canary.10",
71
69
  "fast-deep-equal": "^3.1.3",
72
70
  "prop-types": "^15.8.1"
73
71
  },
74
72
  "description": "",
75
73
  "types": "types/index.d.ts",
76
- "gitHead": "750ea744c6ba45e5480c921acf549ec48c53b303",
74
+ "gitHead": "2e80b0d181a1f979c7d9ab554409768e35314c8b",
77
75
  "files": [
78
76
  "dist",
79
77
  "types"
@@ -1,5 +1,10 @@
1
1
  import React from 'react';
2
2
  import { ComponentRendering } from '@sitecore-content-sdk/core/layout';
3
+ /**
4
+ * Mock function to replace the form module functions for `testing` purposes.
5
+ * @param {any} formModule - The form module to mock
6
+ */
7
+ export declare const mockFormModule: (formModule: any) => void;
3
8
  /**
4
9
  * Shape of the Form component rendering data.
5
10
  * FormId is the rendering parameter that specifies the ID of the Sitecore Form to render.