@sitecore-content-sdk/react 1.5.3-canary.7 → 1.5.3-canary.8

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.
@@ -56,13 +56,14 @@ exports.mockFormModule = mockFormModule;
56
56
  * @public
57
57
  */
58
58
  const Form = ({ params, rendering }) => {
59
- var _a;
59
+ var _a, _b, _c, _d, _e;
60
60
  const id = params === null || params === void 0 ? void 0 : params.RenderingIdentifier;
61
61
  const [error, setError] = (0, react_1.useState)(false);
62
62
  const [content, setContent] = (0, react_1.useState)('');
63
63
  const context = (0, withSitecore_1.useSitecore)();
64
64
  const formRef = (0, react_1.useRef)(null);
65
65
  const isEditing = context.page.mode.isEditing;
66
+ // fetch form content
66
67
  (0, react_1.useEffect)(() => {
67
68
  var _a, _b, _c, _d;
68
69
  if (!content) {
@@ -82,19 +83,27 @@ const Form = ({ params, rendering }) => {
82
83
  setError(true);
83
84
  });
84
85
  }
85
- else {
86
- if (!formRef.current)
87
- return;
88
- // If we are in editing mode, we don't want to send any events
89
- if (!isEditing) {
90
- subscribeToFormSubmitEvent(formRef.current, rendering.uid);
91
- }
92
- executeScriptElements(formRef.current);
86
+ }, [
87
+ content,
88
+ isEditing,
89
+ params.FormId,
90
+ (_b = (_a = context.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.clientContextId,
91
+ (_d = (_c = context.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.edgeUrl,
92
+ ]);
93
+ // Set innerHTML and execute scripts whenever form content changes
94
+ (0, react_1.useEffect)(() => {
95
+ if (!content || !formRef.current)
96
+ return;
97
+ formRef.current.innerHTML = content;
98
+ executeScriptElements(formRef.current);
99
+ // If we are in editing mode, we don't want to send any events
100
+ if (!isEditing) {
101
+ subscribeToFormSubmitEvent(formRef.current, rendering.uid);
93
102
  }
94
- }, [content]);
103
+ }, [content, isEditing, rendering.uid]);
95
104
  if (isEditing && error) {
96
105
  return react_1.default.createElement(ErrorBoundary_1.ErrorComponent, { message: "There was a problem loading this section" });
97
106
  }
98
- return (react_1.default.createElement("div", { ref: formRef, dangerouslySetInnerHTML: { __html: content }, className: (_a = params.styles) === null || _a === void 0 ? void 0 : _a.trimEnd(), id: id ? id : undefined }));
107
+ return react_1.default.createElement("div", { ref: formRef, className: (_e = params.styles) === null || _e === void 0 ? void 0 : _e.trimEnd(), id: id ? id : undefined });
99
108
  };
100
109
  exports.Form = Form;
@@ -19,13 +19,14 @@ export const mockFormModule = (formModule) => {
19
19
  * @public
20
20
  */
21
21
  export const Form = ({ params, rendering }) => {
22
- var _a;
22
+ var _a, _b, _c, _d, _e;
23
23
  const id = params === null || params === void 0 ? void 0 : params.RenderingIdentifier;
24
24
  const [error, setError] = useState(false);
25
25
  const [content, setContent] = useState('');
26
26
  const context = useSitecore();
27
27
  const formRef = useRef(null);
28
28
  const isEditing = context.page.mode.isEditing;
29
+ // fetch form content
29
30
  useEffect(() => {
30
31
  var _a, _b, _c, _d;
31
32
  if (!content) {
@@ -45,18 +46,26 @@ export const Form = ({ params, rendering }) => {
45
46
  setError(true);
46
47
  });
47
48
  }
48
- else {
49
- if (!formRef.current)
50
- return;
51
- // If we are in editing mode, we don't want to send any events
52
- if (!isEditing) {
53
- subscribeToFormSubmitEvent(formRef.current, rendering.uid);
54
- }
55
- executeScriptElements(formRef.current);
49
+ }, [
50
+ content,
51
+ isEditing,
52
+ params.FormId,
53
+ (_b = (_a = context.api) === null || _a === void 0 ? void 0 : _a.edge) === null || _b === void 0 ? void 0 : _b.clientContextId,
54
+ (_d = (_c = context.api) === null || _c === void 0 ? void 0 : _c.edge) === null || _d === void 0 ? void 0 : _d.edgeUrl,
55
+ ]);
56
+ // Set innerHTML and execute scripts whenever form content changes
57
+ useEffect(() => {
58
+ if (!content || !formRef.current)
59
+ return;
60
+ formRef.current.innerHTML = content;
61
+ executeScriptElements(formRef.current);
62
+ // If we are in editing mode, we don't want to send any events
63
+ if (!isEditing) {
64
+ subscribeToFormSubmitEvent(formRef.current, rendering.uid);
56
65
  }
57
- }, [content]);
66
+ }, [content, isEditing, rendering.uid]);
58
67
  if (isEditing && error) {
59
68
  return React.createElement(ErrorComponent, { message: "There was a problem loading this section" });
60
69
  }
61
- return (React.createElement("div", { ref: formRef, dangerouslySetInnerHTML: { __html: content }, className: (_a = params.styles) === null || _a === void 0 ? void 0 : _a.trimEnd(), id: id ? id : undefined }));
70
+ return React.createElement("div", { ref: formRef, className: (_e = params.styles) === null || _e === void 0 ? void 0 : _e.trimEnd(), id: id ? id : undefined });
62
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/react",
3
- "version": "1.5.3-canary.7",
3
+ "version": "1.5.3-canary.8",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -76,13 +76,13 @@
76
76
  "react-dom": "^19.2.1"
77
77
  },
78
78
  "dependencies": {
79
- "@sitecore-content-sdk/core": "1.5.3-canary.7",
80
- "@sitecore-content-sdk/search": "0.1.3-canary.7",
79
+ "@sitecore-content-sdk/core": "1.5.3-canary.8",
80
+ "@sitecore-content-sdk/search": "0.1.3-canary.8",
81
81
  "fast-deep-equal": "^3.1.3"
82
82
  },
83
83
  "description": "",
84
84
  "types": "types/index.d.ts",
85
- "gitHead": "61c59f504f85770507c96e6d3d2482fd7a838e8c",
85
+ "gitHead": "ad56417c8e38c3a17b0176d13eedd71071569432",
86
86
  "files": [
87
87
  "dist",
88
88
  "types",
@@ -1 +1 @@
1
- {"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../src/components/Form.tsx"],"names":[],"mappings":"AACA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAOvE;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,YAAY,GAAG,SAI7C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,MAAM,EAAE;QACN;;WAEG;QACH,MAAM,EAAE,MAAM,CAAC;QACf;;WAEG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB;;WAEG;QACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;CACH,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,IAAI,GAAI,uBAAuB,SAAS,sBAwDpD,CAAC"}
1
+ {"version":3,"file":"Form.d.ts","sourceRoot":"","sources":["../../src/components/Form.tsx"],"names":[],"mappings":"AACA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAOvE;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,YAAY,GAAG,SAI7C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,SAAS,EAAE,kBAAkB,CAAC;IAC9B,MAAM,EAAE;QACN;;WAEG;QACH,MAAM,EAAE,MAAM,CAAC;QACf;;WAEG;QACH,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB;;WAEG;QACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B,CAAC;CACH,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,IAAI,GAAI,uBAAuB,SAAS,sBA4DpD,CAAC"}