@pepperi-addons/ngx-composite-lib-react 0.5.7 → 0.5.9

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/index.d.ts CHANGED
@@ -15,3 +15,4 @@ export { PepManageParameters } from './pep-manage-parameters.js';
15
15
  export { PepMappingParameters } from './pep-mapping-parameters.js';
16
16
  export { PepGenericFieldsBuilder } from './pep-generic-fields-builder.js';
17
17
  export { PepAssetPickerButton } from './pep-asset-picker-button.js';
18
+ export { PepLayoutBuilder } from './pep-layout-builder.js';
package/index.js CHANGED
@@ -15,4 +15,5 @@ export { PepManageParameters } from './pep-manage-parameters.js';
15
15
  export { PepMappingParameters } from './pep-mapping-parameters.js';
16
16
  export { PepGenericFieldsBuilder } from './pep-generic-fields-builder.js';
17
17
  export { PepAssetPickerButton } from './pep-asset-picker-button.js';
18
+ export { PepLayoutBuilder } from './pep-layout-builder.js';
18
19
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pepperi-addons/ngx-composite-lib-react",
3
- "version": "0.5.7",
3
+ "version": "0.5.9",
4
4
  "description": "React wrappers for Pepperi ngx-composite-lib Angular Elements.",
5
5
  "license": "MIT",
6
6
  "author": "Pepperi",
@@ -0,0 +1,72 @@
1
+ import React from 'react';
2
+ export interface PepLayoutBlockConfig {
3
+ navigateToEditorAfterBlockAdded?: boolean;
4
+ blocksLimitNumber?: number;
5
+ getBlockTitle?: (blockKey: string) => string;
6
+ }
7
+ export interface PepLayoutBlockAddedEvent {
8
+ BlockKey: string;
9
+ DraggableItem: unknown;
10
+ }
11
+ export declare type PepLayoutEditorType = 'layout-builder' | 'section' | 'block';
12
+ export interface PepLayoutEditor {
13
+ id: string;
14
+ title: string;
15
+ type: PepLayoutEditorType;
16
+ hostObject?: unknown;
17
+ }
18
+ export interface PepLayoutView {
19
+ Layout: {
20
+ MaxWidth?: number;
21
+ VerticalSpacing?: unknown;
22
+ HorizontalSpacing?: unknown;
23
+ SectionsGap?: unknown;
24
+ ColumnsGap?: unknown;
25
+ Sections: Array<{
26
+ Key: string;
27
+ Name?: string;
28
+ Split?: string;
29
+ Height?: number;
30
+ CollapseOnTablet?: boolean;
31
+ FillHeight?: boolean;
32
+ Hide?: unknown[];
33
+ Columns: Array<{
34
+ BlockContainer?: {
35
+ BlockKey: string;
36
+ Hide?: unknown[];
37
+ };
38
+ }>;
39
+ }>;
40
+ };
41
+ }
42
+ export interface PepLayoutBuilderProps {
43
+ availableBlocksForDrag?: unknown[];
44
+ blocksLayoutConfig?: PepLayoutBlockConfig;
45
+ layoutEditorTitle?: string;
46
+ lockScreen?: boolean;
47
+ updateShellRouterData?: boolean;
48
+ manageGlobalCursor?: boolean;
49
+ layoutView?: PepLayoutView;
50
+ onBackClick?: () => void;
51
+ onEditorChange?: (editor: PepLayoutEditor) => void;
52
+ onBlockAdded?: (event: PepLayoutBlockAddedEvent) => void;
53
+ onBlocksRemoved?: (blockKeys: string[]) => void;
54
+ onEditableStateChange?: (isEditable: boolean) => void;
55
+ layoutEditorTopContent?: React.ReactNode;
56
+ headerEndContent?: React.ReactNode;
57
+ blockEditorContent?: React.ReactNode;
58
+ layoutContent?: React.ReactNode;
59
+ className?: string;
60
+ style?: React.CSSProperties;
61
+ }
62
+ export declare class PepLayoutBuilder extends React.Component<PepLayoutBuilderProps> {
63
+ private readonly elementRef;
64
+ private unsubs;
65
+ componentDidMount(): void;
66
+ componentDidUpdate(prevProps: PepLayoutBuilderProps): void;
67
+ componentWillUnmount(): void;
68
+ private applyPropsToElement;
69
+ private bindEvents;
70
+ private unbindEvents;
71
+ render(): React.ReactNode;
72
+ }
@@ -0,0 +1,88 @@
1
+ import React from 'react';
2
+ export class PepLayoutBuilder extends React.Component {
3
+ constructor() {
4
+ super(...arguments);
5
+ this.elementRef = React.createRef();
6
+ this.unsubs = [];
7
+ }
8
+ componentDidMount() {
9
+ this.applyPropsToElement();
10
+ this.bindEvents();
11
+ }
12
+ componentDidUpdate(prevProps) {
13
+ this.applyPropsToElement();
14
+ const handlersChanged = prevProps.onBackClick !== this.props.onBackClick ||
15
+ prevProps.onEditorChange !== this.props.onEditorChange ||
16
+ prevProps.onBlockAdded !== this.props.onBlockAdded ||
17
+ prevProps.onBlocksRemoved !== this.props.onBlocksRemoved ||
18
+ prevProps.onEditableStateChange !== this.props.onEditableStateChange;
19
+ if (handlersChanged) {
20
+ this.unbindEvents();
21
+ this.bindEvents();
22
+ }
23
+ }
24
+ componentWillUnmount() {
25
+ this.unbindEvents();
26
+ }
27
+ applyPropsToElement() {
28
+ const el = this.elementRef.current;
29
+ if (!el)
30
+ return;
31
+ const { availableBlocksForDrag, blocksLayoutConfig, layoutEditorTitle, lockScreen, updateShellRouterData, manageGlobalCursor, layoutView, } = this.props;
32
+ if (availableBlocksForDrag !== undefined)
33
+ el.availableBlocksForDrag = availableBlocksForDrag;
34
+ if (blocksLayoutConfig !== undefined)
35
+ el.blocksLayoutConfig = blocksLayoutConfig;
36
+ if (layoutEditorTitle !== undefined)
37
+ el.layoutEditorTitle = layoutEditorTitle;
38
+ if (lockScreen !== undefined)
39
+ el.lockScreen = lockScreen;
40
+ if (updateShellRouterData !== undefined)
41
+ el.updateShellRouterData = updateShellRouterData;
42
+ if (manageGlobalCursor !== undefined)
43
+ el.manageGlobalCursor = manageGlobalCursor;
44
+ if (layoutView !== undefined)
45
+ el.layoutView = layoutView;
46
+ }
47
+ bindEvents() {
48
+ const el = this.elementRef.current;
49
+ if (!el)
50
+ return;
51
+ const bind = (name, cb) => {
52
+ if (!cb)
53
+ return () => { };
54
+ const handler = (e) => cb(e.detail);
55
+ el.addEventListener(name, handler);
56
+ return () => el.removeEventListener(name, handler);
57
+ };
58
+ this.unsubs = [
59
+ bind('backClick', this.props.onBackClick ? () => this.props.onBackClick?.() : undefined),
60
+ bind('editorChange', this.props.onEditorChange),
61
+ bind('blockAdded', this.props.onBlockAdded),
62
+ bind('blocksRemoved', this.props.onBlocksRemoved),
63
+ bind('editableStateChange', this.props.onEditableStateChange),
64
+ ];
65
+ }
66
+ unbindEvents() {
67
+ this.unsubs.forEach((u) => u());
68
+ this.unsubs = [];
69
+ }
70
+ render() {
71
+ const { layoutEditorTopContent, headerEndContent, blockEditorContent, layoutContent, className, style, } = this.props;
72
+ const children = [];
73
+ if (layoutEditorTopContent) {
74
+ children.push(React.createElement('div', { ['layout-editor-top-content']: '' }, layoutEditorTopContent));
75
+ }
76
+ if (headerEndContent) {
77
+ children.push(React.createElement('div', { ['header-end-content']: '' }, headerEndContent));
78
+ }
79
+ if (blockEditorContent) {
80
+ children.push(React.createElement('div', { ['block-editor-content']: '' }, blockEditorContent));
81
+ }
82
+ if (layoutContent) {
83
+ children.push(React.createElement('div', { ['layout-content']: '' }, layoutContent));
84
+ }
85
+ return React.createElement('pep-layout-builder-element', { ref: this.elementRef, class: className, style }, children.length > 0 ? children : undefined);
86
+ }
87
+ }
88
+ //# sourceMappingURL=pep-layout-builder.js.map