@gravity-ui/page-constructor 1.15.4 → 1.16.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/CHANGELOG.md +7 -0
- package/build/cjs/models/constructor-items/sub-blocks.d.ts +1 -0
- package/build/cjs/sub-blocks/HubspotForm/HubspotFormContainer.d.ts +1 -1
- package/build/cjs/sub-blocks/HubspotForm/HubspotFormContainer.js +26 -8
- package/build/cjs/sub-blocks/HubspotForm/index.js +2 -2
- package/build/esm/models/constructor-items/sub-blocks.d.ts +1 -0
- package/build/esm/sub-blocks/HubspotForm/HubspotFormContainer.d.ts +1 -1
- package/build/esm/sub-blocks/HubspotForm/HubspotFormContainer.js +26 -8
- package/build/esm/sub-blocks/HubspotForm/index.js +2 -2
- package/package.json +1 -1
- package/server/models/constructor-items/sub-blocks.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.16.0](https://github.com/gravity-ui/page-constructor/compare/v1.15.4...v1.16.0) (2023-02-14)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **HubspotForm:** add render outside virtual dom ([#138](https://github.com/gravity-ui/page-constructor/issues/138)) ([1b8694c](https://github.com/gravity-ui/page-constructor/commit/1b8694c6893df63ffabab84779febad57362804c))
|
|
9
|
+
|
|
3
10
|
## [1.15.4](https://github.com/gravity-ui/page-constructor/compare/v1.15.3...v1.15.4) (2023-02-13)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -65,6 +65,7 @@ export interface HubspotFormProps extends HubspotEventHandlers {
|
|
|
65
65
|
onLoad?: (arg: HubspotEventData) => void;
|
|
66
66
|
pixelEvents?: string | string[] | PixelEvent | PixelEvent[] | ButtonPixel;
|
|
67
67
|
hubspotEvents?: string[];
|
|
68
|
+
createDOMElement?: boolean;
|
|
68
69
|
}
|
|
69
70
|
export interface PartnerProps extends CardBaseProps {
|
|
70
71
|
text: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HubspotFormProps } from '../../models';
|
|
2
|
-
type HubspotFormContainerPropsKeys = 'className' | 'formId' | 'formInstanceId' | 'portalId' | 'region' | 'formClassName';
|
|
2
|
+
type HubspotFormContainerPropsKeys = 'className' | 'formId' | 'formInstanceId' | 'portalId' | 'region' | 'formClassName' | 'createDOMElement';
|
|
3
3
|
type HubspotFormContainerProps = Pick<HubspotFormProps, HubspotFormContainerPropsKeys>;
|
|
4
4
|
declare const HubspotFormContainer: (props: HubspotFormContainerProps) => JSX.Element;
|
|
5
5
|
export default HubspotFormContainer;
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const react_1 = tslib_1.
|
|
4
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
5
|
const loadHubspotScript_1 = tslib_1.__importDefault(require("./loadHubspotScript"));
|
|
6
6
|
const hooks_1 = require("../../hooks");
|
|
7
7
|
const HubspotFormContainer = (props) => {
|
|
8
|
-
const { className, formId, formInstanceId, portalId, region, formClassName, } = props;
|
|
8
|
+
const { className, formId, formInstanceId, portalId, region, formClassName, createDOMElement, } = props;
|
|
9
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
10
|
+
const hsContainerRef = (0, react_1.useRef)();
|
|
9
11
|
const containerId = formInstanceId
|
|
10
12
|
? `hubspot-form-${formId}-${formInstanceId}`
|
|
11
13
|
: `hubspot-form-${formId}`;
|
|
12
|
-
|
|
13
|
-
(
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const createForm = () => {
|
|
15
|
+
if (containerRef.current && !hsContainerRef.current && createDOMElement) {
|
|
16
|
+
hsContainerRef.current = document.createElement('div');
|
|
17
|
+
containerRef.current.id = '';
|
|
18
|
+
hsContainerRef.current.id = containerId;
|
|
19
|
+
containerRef.current.appendChild(hsContainerRef.current);
|
|
20
|
+
}
|
|
21
|
+
if (!createDOMElement || hsContainerRef.current) {
|
|
17
22
|
if (window.hbspt) {
|
|
18
23
|
window.hbspt.forms.create({
|
|
19
24
|
region,
|
|
@@ -24,8 +29,21 @@ const HubspotFormContainer = (props) => {
|
|
|
24
29
|
formInstanceId,
|
|
25
30
|
});
|
|
26
31
|
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
(0, hooks_1.useMount)(() => {
|
|
35
|
+
(async () => {
|
|
36
|
+
if (!window.hbspt) {
|
|
37
|
+
await (0, loadHubspotScript_1.default)();
|
|
38
|
+
}
|
|
39
|
+
createForm();
|
|
27
40
|
})();
|
|
41
|
+
return () => {
|
|
42
|
+
if (createDOMElement && containerRef.current && containerRef.current.lastChild) {
|
|
43
|
+
containerRef.current.removeChild(containerRef.current.lastChild);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
28
46
|
});
|
|
29
|
-
return react_1.default.createElement("div", { className: className, id: containerId });
|
|
47
|
+
return react_1.default.createElement("div", { className: className, id: containerId, ref: containerRef });
|
|
30
48
|
};
|
|
31
49
|
exports.default = HubspotFormContainer;
|
|
@@ -12,7 +12,7 @@ const b = (0, utils_1.block)('hubspot-form');
|
|
|
12
12
|
const HubspotForm = (props) => {
|
|
13
13
|
const { className, theme: themeProp, isMobile: isMobileProp, formId, formInstanceId, portalId, region, formClassName, pixelEvents,
|
|
14
14
|
// hubspotEvents, // TODO: decide how to handle them
|
|
15
|
-
onBeforeSubmit, onSubmit, onBeforeLoad, onLoad, onSubmitError, } = props;
|
|
15
|
+
onBeforeSubmit, onSubmit, onBeforeLoad, onLoad, createDOMElement, onSubmitError, } = props;
|
|
16
16
|
const handleMetrika = (0, useMetrika_1.useMetrika)();
|
|
17
17
|
const { themeValue } = (0, react_1.useContext)(ThemeValueContext_1.ThemeValueContext);
|
|
18
18
|
const isMobileValue = (0, react_1.useContext)(mobileContext_1.MobileContext);
|
|
@@ -29,6 +29,6 @@ const HubspotForm = (props) => {
|
|
|
29
29
|
},
|
|
30
30
|
}), [onBeforeLoad, onBeforeSubmit, onLoad, handleMetrika, pixelEvents, onSubmit, onSubmitError]);
|
|
31
31
|
(0, hooks_1.useHandleHubspotEvents)(handlers, formId);
|
|
32
|
-
return (react_1.default.createElement(HubspotFormContainer_1.default, { key: [formClassName, formId, formInstanceId, portalId, region].join(), className: b({ theme, mobile }, className), formClassName: formClassName, formId: formId, portalId: portalId, formInstanceId: formInstanceId, region: region }));
|
|
32
|
+
return (react_1.default.createElement(HubspotFormContainer_1.default, { createDOMElement: createDOMElement, key: [formClassName, formId, formInstanceId, portalId, region].join(), className: b({ theme, mobile }, className), formClassName: formClassName, formId: formId, portalId: portalId, formInstanceId: formInstanceId, region: region }));
|
|
33
33
|
};
|
|
34
34
|
exports.default = HubspotForm;
|
|
@@ -65,6 +65,7 @@ export interface HubspotFormProps extends HubspotEventHandlers {
|
|
|
65
65
|
onLoad?: (arg: HubspotEventData) => void;
|
|
66
66
|
pixelEvents?: string | string[] | PixelEvent | PixelEvent[] | ButtonPixel;
|
|
67
67
|
hubspotEvents?: string[];
|
|
68
|
+
createDOMElement?: boolean;
|
|
68
69
|
}
|
|
69
70
|
export interface PartnerProps extends CardBaseProps {
|
|
70
71
|
text: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HubspotFormProps } from '../../models';
|
|
2
|
-
type HubspotFormContainerPropsKeys = 'className' | 'formId' | 'formInstanceId' | 'portalId' | 'region' | 'formClassName';
|
|
2
|
+
type HubspotFormContainerPropsKeys = 'className' | 'formId' | 'formInstanceId' | 'portalId' | 'region' | 'formClassName' | 'createDOMElement';
|
|
3
3
|
type HubspotFormContainerProps = Pick<HubspotFormProps, HubspotFormContainerPropsKeys>;
|
|
4
4
|
declare const HubspotFormContainer: (props: HubspotFormContainerProps) => JSX.Element;
|
|
5
5
|
export default HubspotFormContainer;
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { useRef } from 'react';
|
|
2
2
|
import loadHubspotScript from './loadHubspotScript';
|
|
3
3
|
import { useMount } from '../../hooks';
|
|
4
4
|
const HubspotFormContainer = (props) => {
|
|
5
|
-
const { className, formId, formInstanceId, portalId, region, formClassName, } = props;
|
|
5
|
+
const { className, formId, formInstanceId, portalId, region, formClassName, createDOMElement, } = props;
|
|
6
|
+
const containerRef = useRef(null);
|
|
7
|
+
const hsContainerRef = useRef();
|
|
6
8
|
const containerId = formInstanceId
|
|
7
9
|
? `hubspot-form-${formId}-${formInstanceId}`
|
|
8
10
|
: `hubspot-form-${formId}`;
|
|
9
|
-
|
|
10
|
-
(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
const createForm = () => {
|
|
12
|
+
if (containerRef.current && !hsContainerRef.current && createDOMElement) {
|
|
13
|
+
hsContainerRef.current = document.createElement('div');
|
|
14
|
+
containerRef.current.id = '';
|
|
15
|
+
hsContainerRef.current.id = containerId;
|
|
16
|
+
containerRef.current.appendChild(hsContainerRef.current);
|
|
17
|
+
}
|
|
18
|
+
if (!createDOMElement || hsContainerRef.current) {
|
|
14
19
|
if (window.hbspt) {
|
|
15
20
|
window.hbspt.forms.create({
|
|
16
21
|
region,
|
|
@@ -21,8 +26,21 @@ const HubspotFormContainer = (props) => {
|
|
|
21
26
|
formInstanceId,
|
|
22
27
|
});
|
|
23
28
|
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
useMount(() => {
|
|
32
|
+
(async () => {
|
|
33
|
+
if (!window.hbspt) {
|
|
34
|
+
await loadHubspotScript();
|
|
35
|
+
}
|
|
36
|
+
createForm();
|
|
24
37
|
})();
|
|
38
|
+
return () => {
|
|
39
|
+
if (createDOMElement && containerRef.current && containerRef.current.lastChild) {
|
|
40
|
+
containerRef.current.removeChild(containerRef.current.lastChild);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
25
43
|
});
|
|
26
|
-
return React.createElement("div", { className: className, id: containerId });
|
|
44
|
+
return React.createElement("div", { className: className, id: containerId, ref: containerRef });
|
|
27
45
|
};
|
|
28
46
|
export default HubspotFormContainer;
|
|
@@ -10,7 +10,7 @@ const b = block('hubspot-form');
|
|
|
10
10
|
const HubspotForm = (props) => {
|
|
11
11
|
const { className, theme: themeProp, isMobile: isMobileProp, formId, formInstanceId, portalId, region, formClassName, pixelEvents,
|
|
12
12
|
// hubspotEvents, // TODO: decide how to handle them
|
|
13
|
-
onBeforeSubmit, onSubmit, onBeforeLoad, onLoad, onSubmitError, } = props;
|
|
13
|
+
onBeforeSubmit, onSubmit, onBeforeLoad, onLoad, createDOMElement, onSubmitError, } = props;
|
|
14
14
|
const handleMetrika = useMetrika();
|
|
15
15
|
const { themeValue } = useContext(ThemeValueContext);
|
|
16
16
|
const isMobileValue = useContext(MobileContext);
|
|
@@ -27,6 +27,6 @@ const HubspotForm = (props) => {
|
|
|
27
27
|
},
|
|
28
28
|
}), [onBeforeLoad, onBeforeSubmit, onLoad, handleMetrika, pixelEvents, onSubmit, onSubmitError]);
|
|
29
29
|
useHandleHubspotEvents(handlers, formId);
|
|
30
|
-
return (React.createElement(HubspotFormContainer, { key: [formClassName, formId, formInstanceId, portalId, region].join(), className: b({ theme, mobile }, className), formClassName: formClassName, formId: formId, portalId: portalId, formInstanceId: formInstanceId, region: region }));
|
|
30
|
+
return (React.createElement(HubspotFormContainer, { createDOMElement: createDOMElement, key: [formClassName, formId, formInstanceId, portalId, region].join(), className: b({ theme, mobile }, className), formClassName: formClassName, formId: formId, portalId: portalId, formInstanceId: formInstanceId, region: region }));
|
|
31
31
|
};
|
|
32
32
|
export default HubspotForm;
|
package/package.json
CHANGED
|
@@ -65,6 +65,7 @@ export interface HubspotFormProps extends HubspotEventHandlers {
|
|
|
65
65
|
onLoad?: (arg: HubspotEventData) => void;
|
|
66
66
|
pixelEvents?: string | string[] | PixelEvent | PixelEvent[] | ButtonPixel;
|
|
67
67
|
hubspotEvents?: string[];
|
|
68
|
+
createDOMElement?: boolean;
|
|
68
69
|
}
|
|
69
70
|
export interface PartnerProps extends CardBaseProps {
|
|
70
71
|
text: string;
|