@pepperi-addons/ngx-composite-lib-react 0.5.13 → 0.5.16
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/elements/main.js +1 -1
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/package.json +2 -2
- package/pep-group-buttons-settings.js +117 -36
- package/pep-layout-builder2.d.ts +31 -0
- package/pep-layout-builder2.js +405 -27
- package/pep-layout.js +5 -3
- package/pep-layout2.d.ts +57 -0
- package/pep-layout2.js +145 -0
package/pep-layout2.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom';
|
|
4
|
+
export class PepLayout2 extends React.Component {
|
|
5
|
+
constructor() {
|
|
6
|
+
super(...arguments);
|
|
7
|
+
this.elementRef = React.createRef();
|
|
8
|
+
this.unsubs = [];
|
|
9
|
+
this.rootFactoryPromise = null;
|
|
10
|
+
this.portalRoots = new Map();
|
|
11
|
+
}
|
|
12
|
+
componentDidMount() {
|
|
13
|
+
this.applyPropsToElement();
|
|
14
|
+
this.bindEvents();
|
|
15
|
+
}
|
|
16
|
+
componentDidUpdate(prevProps) {
|
|
17
|
+
this.applyPropsToElement();
|
|
18
|
+
const handlersChanged = prevProps.onLayoutViewChange !== this.props.onLayoutViewChange ||
|
|
19
|
+
prevProps.onScreenTypeChange !== this.props.onScreenTypeChange;
|
|
20
|
+
if (handlersChanged) {
|
|
21
|
+
this.unbindEvents();
|
|
22
|
+
this.bindEvents();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
componentWillUnmount() {
|
|
26
|
+
this.unbindEvents();
|
|
27
|
+
this.unmountAllPortals();
|
|
28
|
+
}
|
|
29
|
+
getRootFactory() {
|
|
30
|
+
if (this.rootFactoryPromise) {
|
|
31
|
+
return this.rootFactoryPromise;
|
|
32
|
+
}
|
|
33
|
+
this.rootFactoryPromise = Promise.resolve().then(() => {
|
|
34
|
+
const win = window;
|
|
35
|
+
const createRoot = win.ReactDOMClient?.createRoot;
|
|
36
|
+
if (typeof createRoot === 'function') {
|
|
37
|
+
return (container) => {
|
|
38
|
+
const root = createRoot(container);
|
|
39
|
+
return {
|
|
40
|
+
render: (node) => root.render(node),
|
|
41
|
+
unmount: () => root.unmount(),
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return (container) => {
|
|
46
|
+
return {
|
|
47
|
+
render: (node) => ReactDOM.render(_jsx(_Fragment, { children: node }), container),
|
|
48
|
+
unmount: () => ReactDOM.unmountComponentAtNode(container),
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
return this.rootFactoryPromise;
|
|
53
|
+
}
|
|
54
|
+
async ensurePortalRoot(host) {
|
|
55
|
+
const existing = this.portalRoots.get(host);
|
|
56
|
+
if (existing) {
|
|
57
|
+
return existing;
|
|
58
|
+
}
|
|
59
|
+
const createRoot = await this.getRootFactory();
|
|
60
|
+
const root = createRoot(host);
|
|
61
|
+
this.portalRoots.set(host, root);
|
|
62
|
+
return root;
|
|
63
|
+
}
|
|
64
|
+
unmountPortal(host) {
|
|
65
|
+
const existing = this.portalRoots.get(host);
|
|
66
|
+
if (existing) {
|
|
67
|
+
existing.unmount();
|
|
68
|
+
this.portalRoots.delete(host);
|
|
69
|
+
}
|
|
70
|
+
while (host.firstChild) {
|
|
71
|
+
host.removeChild(host.firstChild);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
unmountAllPortals() {
|
|
75
|
+
this.portalRoots.forEach((root, host) => {
|
|
76
|
+
root.unmount();
|
|
77
|
+
while (host.firstChild) {
|
|
78
|
+
host.removeChild(host.firstChild);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
this.portalRoots.clear();
|
|
82
|
+
}
|
|
83
|
+
applyPropsToElement() {
|
|
84
|
+
const el = this.elementRef.current;
|
|
85
|
+
if (!el) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const { editorMode, layoutView, renderSkeleton, showSkeleton, blockTemplateRenderer } = this.props;
|
|
89
|
+
if (editorMode !== undefined)
|
|
90
|
+
el.editorMode = editorMode;
|
|
91
|
+
if (layoutView !== undefined)
|
|
92
|
+
el.layoutView = layoutView;
|
|
93
|
+
if (renderSkeleton !== undefined)
|
|
94
|
+
el.renderSkeleton = renderSkeleton;
|
|
95
|
+
if (showSkeleton !== undefined)
|
|
96
|
+
el.showSkeleton = showSkeleton;
|
|
97
|
+
if (blockTemplateRenderer) {
|
|
98
|
+
el.blockTemplateRenderer = (host, blockKey) => {
|
|
99
|
+
void this.ensurePortalRoot(host).then((root) => {
|
|
100
|
+
root.render(blockTemplateRenderer(blockKey));
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
el.blockTemplateUnmount = (host) => {
|
|
104
|
+
this.unmountPortal(host);
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
el.blockTemplateRenderer = null;
|
|
109
|
+
el.blockTemplateUnmount = null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
bindEvents() {
|
|
113
|
+
const el = this.elementRef.current;
|
|
114
|
+
if (!el) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const bind = (name, cb) => {
|
|
118
|
+
if (!cb)
|
|
119
|
+
return () => { };
|
|
120
|
+
const handler = (e) => cb(e.detail);
|
|
121
|
+
el.addEventListener(name, handler);
|
|
122
|
+
return () => el.removeEventListener(name, handler);
|
|
123
|
+
};
|
|
124
|
+
this.unsubs = [
|
|
125
|
+
bind('layoutViewChange', this.props.onLayoutViewChange),
|
|
126
|
+
bind('screenTypeChange', this.props.onScreenTypeChange),
|
|
127
|
+
];
|
|
128
|
+
}
|
|
129
|
+
unbindEvents() {
|
|
130
|
+
this.unsubs.forEach((u) => u());
|
|
131
|
+
this.unsubs = [];
|
|
132
|
+
}
|
|
133
|
+
render() {
|
|
134
|
+
const { blockTemplate, children, className, style } = this.props;
|
|
135
|
+
const childElements = [];
|
|
136
|
+
if (blockTemplate) {
|
|
137
|
+
childElements.push(React.createElement('div', { key: 'block-template', slot: 'blockTemplate' }, blockTemplate));
|
|
138
|
+
}
|
|
139
|
+
if (children) {
|
|
140
|
+
childElements.push(children);
|
|
141
|
+
}
|
|
142
|
+
return React.createElement('pep-layout2-element', { ref: this.elementRef, class: className, style }, childElements.length > 0 ? childElements : undefined);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=pep-layout2.js.map
|