@elementor/editor-components 4.0.0-675 → 4.0.0-676

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@elementor/editor-components",
3
3
  "description": "Elementor editor components",
4
- "version": "4.0.0-675",
4
+ "version": "4.0.0-676",
5
5
  "private": false,
6
6
  "author": "Elementor Team",
7
7
  "homepage": "https://elementor.com/",
@@ -40,31 +40,31 @@
40
40
  "dev": "tsup --config=../../tsup.dev.ts"
41
41
  },
42
42
  "dependencies": {
43
- "@elementor/editor": "4.0.0-675",
44
- "@elementor/editor-canvas": "4.0.0-675",
45
- "@elementor/editor-controls": "4.0.0-675",
46
- "@elementor/editor-documents": "4.0.0-675",
47
- "@elementor/editor-editing-panel": "4.0.0-675",
48
- "@elementor/editor-elements": "4.0.0-675",
49
- "@elementor/editor-elements-panel": "4.0.0-675",
50
- "@elementor/editor-mcp": "4.0.0-675",
51
- "@elementor/editor-templates": "4.0.0-675",
52
- "@elementor/editor-panels": "4.0.0-675",
53
- "@elementor/editor-props": "4.0.0-675",
54
- "@elementor/editor-styles-repository": "4.0.0-675",
55
- "@elementor/editor-ui": "4.0.0-675",
56
- "@elementor/editor-v1-adapters": "4.0.0-675",
57
- "@elementor/http-client": "4.0.0-675",
43
+ "@elementor/editor": "4.0.0-676",
44
+ "@elementor/editor-canvas": "4.0.0-676",
45
+ "@elementor/editor-controls": "4.0.0-676",
46
+ "@elementor/editor-documents": "4.0.0-676",
47
+ "@elementor/editor-editing-panel": "4.0.0-676",
48
+ "@elementor/editor-elements": "4.0.0-676",
49
+ "@elementor/editor-elements-panel": "4.0.0-676",
50
+ "@elementor/editor-mcp": "4.0.0-676",
51
+ "@elementor/editor-templates": "4.0.0-676",
52
+ "@elementor/editor-panels": "4.0.0-676",
53
+ "@elementor/editor-props": "4.0.0-676",
54
+ "@elementor/editor-styles-repository": "4.0.0-676",
55
+ "@elementor/editor-ui": "4.0.0-676",
56
+ "@elementor/editor-v1-adapters": "4.0.0-676",
57
+ "@elementor/http-client": "4.0.0-676",
58
58
  "@elementor/icons": "^1.68.0",
59
- "@elementor/events": "4.0.0-675",
60
- "@elementor/query": "4.0.0-675",
61
- "@elementor/schema": "4.0.0-675",
62
- "@elementor/store": "4.0.0-675",
59
+ "@elementor/events": "4.0.0-676",
60
+ "@elementor/query": "4.0.0-676",
61
+ "@elementor/schema": "4.0.0-676",
62
+ "@elementor/store": "4.0.0-676",
63
63
  "@elementor/ui": "1.36.17",
64
- "@elementor/utils": "4.0.0-675",
64
+ "@elementor/utils": "4.0.0-676",
65
65
  "@wordpress/i18n": "^5.13.0",
66
- "@elementor/editor-notifications": "4.0.0-675",
67
- "@elementor/editor-current-user": "4.0.0-675"
66
+ "@elementor/editor-notifications": "4.0.0-676",
67
+ "@elementor/editor-current-user": "4.0.0-676"
68
68
  },
69
69
  "peerDependencies": {
70
70
  "react": "^18.3.1",
package/src/index.ts CHANGED
@@ -51,6 +51,8 @@ export { componentsActions } from './store/dispatchers';
51
51
  export { componentsSelectors } from './store/selectors';
52
52
  export {
53
53
  SLICE_NAME,
54
+ createComponentsAction,
55
+ registerComponentsReducer,
54
56
  selectOverridableProps,
55
57
  selectPath,
56
58
  slice,
@@ -59,7 +61,7 @@ export {
59
61
  useIsSanitizedComponent,
60
62
  useOverridableProps,
61
63
  } from './store/store';
62
- export type { ComponentsPathItem, ComponentsSlice, SanitizeAttributes } from './store/store';
64
+ export type { ComponentsPathItem, ComponentsSlice, ComponentsState, SanitizeAttributes } from './store/store';
63
65
 
64
66
  export { publishDraftComponentsInPageBeforeSave } from './sync/publish-draft-components-in-page-before-save';
65
67
 
@@ -0,0 +1,168 @@
1
+ import type { V1Document } from '@elementor/editor-documents';
2
+ import {
3
+ __createAction as createAction,
4
+ __createSlice as createSlice,
5
+ __dispatch as dispatch,
6
+ type AnyAction,
7
+ type PayloadAction,
8
+ } from '@elementor/store';
9
+
10
+ import type { ComponentId, OverridableProps, PublishedComponent, UnpublishedComponent } from '../types';
11
+ import { type ComponentsState, initialState, type SanitizeAttributes, SLICE_NAME } from './store-types';
12
+ import { loadComponents } from './thunks';
13
+
14
+ type GetComponentResponse = PublishedComponent[];
15
+
16
+ type ComponentsReducer< P > = ( state: ComponentsState, action: PayloadAction< P > ) => void;
17
+
18
+ const extraReducersMap = new Map< string, ComponentsReducer< unknown > >();
19
+
20
+ export function registerComponentsReducer< P >( name: string, reducer: ComponentsReducer< P > ) {
21
+ extraReducersMap.set( `${ SLICE_NAME }/${ name }`, reducer as ComponentsReducer< unknown > );
22
+ }
23
+
24
+ export function createComponentsAction< P >( name: string ) {
25
+ const action = createAction< P >( `${ SLICE_NAME }/${ name }` );
26
+
27
+ return {
28
+ action,
29
+ register( reducer: ComponentsReducer< P > ) {
30
+ registerComponentsReducer( name, reducer );
31
+ },
32
+ dispatch( payload: P ) {
33
+ dispatch( action( payload ) );
34
+ },
35
+ };
36
+ }
37
+
38
+ export function __resetExtraReducers() {
39
+ extraReducersMap.clear();
40
+ }
41
+
42
+ const baseSlice = createSlice( {
43
+ name: SLICE_NAME,
44
+ initialState,
45
+ reducers: {
46
+ add: ( state, { payload }: PayloadAction< PublishedComponent | PublishedComponent[] > ) => {
47
+ if ( Array.isArray( payload ) ) {
48
+ state.data = [ ...payload, ...state.data ];
49
+ } else {
50
+ state.data.unshift( payload );
51
+ }
52
+ },
53
+ load: ( state, { payload }: PayloadAction< PublishedComponent[] > ) => {
54
+ state.data = payload;
55
+ },
56
+ addUnpublished: ( state, { payload }: PayloadAction< UnpublishedComponent > ) => {
57
+ state.unpublishedData.unshift( payload );
58
+ },
59
+ removeUnpublished: ( state, { payload }: PayloadAction< string | string[] > ) => {
60
+ const uidsToRemove = Array.isArray( payload ) ? payload : [ payload ];
61
+ state.unpublishedData = state.unpublishedData.filter(
62
+ ( component ) => ! uidsToRemove.includes( component.uid )
63
+ );
64
+ },
65
+ resetUnpublished: ( state ) => {
66
+ state.unpublishedData = [];
67
+ },
68
+ removeStyles( state, { payload }: PayloadAction< { id: ComponentId } > ) {
69
+ const { [ payload.id ]: _, ...rest } = state.styles;
70
+
71
+ state.styles = rest;
72
+ },
73
+ addStyles: ( state, { payload } ) => {
74
+ state.styles = { ...state.styles, ...payload };
75
+ },
76
+ addCreatedThisSession: ( state, { payload }: PayloadAction< string > ) => {
77
+ state.createdThisSession.push( payload );
78
+ },
79
+ removeCreatedThisSession: ( state, { payload }: PayloadAction< string > ) => {
80
+ state.createdThisSession = state.createdThisSession.filter( ( uid ) => uid !== payload );
81
+ },
82
+ archive: ( state, { payload }: PayloadAction< number > ) => {
83
+ const component = state.data.find( ( comp ) => comp.id === payload );
84
+
85
+ if ( component ) {
86
+ component.isArchived = true;
87
+ state.archivedThisSession.push( payload );
88
+ }
89
+ },
90
+ setCurrentComponentId: ( state, { payload }: PayloadAction< V1Document[ 'id' ] | null > ) => {
91
+ state.currentComponentId = payload;
92
+ },
93
+ setPath: ( state, { payload }: PayloadAction< ComponentsState[ 'path' ] > ) => {
94
+ state.path = payload;
95
+ },
96
+ setOverridableProps: (
97
+ state,
98
+ { payload }: PayloadAction< { componentId: ComponentId; overridableProps: OverridableProps } >
99
+ ) => {
100
+ const component = state.data.find( ( comp ) => comp.id === payload.componentId );
101
+
102
+ if ( ! component ) {
103
+ return;
104
+ }
105
+
106
+ component.overridableProps = payload.overridableProps;
107
+ },
108
+ rename: ( state, { payload }: PayloadAction< { componentUid: string; name: string } > ) => {
109
+ const component = state.data.find( ( comp ) => comp.uid === payload.componentUid );
110
+
111
+ if ( ! component ) {
112
+ return;
113
+ }
114
+ if ( component.id ) {
115
+ state.updatedComponentNames[ component.id ] = payload.name;
116
+ }
117
+ component.name = payload.name;
118
+ },
119
+ cleanUpdatedComponentNames: ( state ) => {
120
+ state.updatedComponentNames = {};
121
+ },
122
+ updateComponentSanitizedAttribute: (
123
+ state,
124
+ {
125
+ payload: { componentId, attribute },
126
+ }: PayloadAction< { componentId: ComponentId; attribute: SanitizeAttributes } >
127
+ ) => {
128
+ if ( ! state.sanitized[ componentId ] ) {
129
+ state.sanitized[ componentId ] = {};
130
+ }
131
+
132
+ state.sanitized[ componentId ][ attribute ] = true;
133
+ },
134
+ resetSanitizedComponents: ( state ) => {
135
+ state.sanitized = {};
136
+ },
137
+ },
138
+ extraReducers: ( builder ) => {
139
+ builder.addCase( loadComponents.fulfilled, ( state, { payload }: PayloadAction< GetComponentResponse > ) => {
140
+ state.data = payload;
141
+ state.loadStatus = 'idle';
142
+ } );
143
+ builder.addCase( loadComponents.pending, ( state ) => {
144
+ state.loadStatus = 'pending';
145
+ } );
146
+ builder.addCase( loadComponents.rejected, ( state ) => {
147
+ state.loadStatus = 'error';
148
+ } );
149
+ },
150
+ } );
151
+
152
+ export const slice: typeof baseSlice = {
153
+ ...baseSlice,
154
+ reducer( state: ComponentsState | undefined, action: AnyAction ) {
155
+ const nextState = baseSlice.reducer( state, action );
156
+
157
+ const extraReducer = extraReducersMap.get( action.type );
158
+
159
+ if ( ! extraReducer || ! nextState ) {
160
+ return nextState;
161
+ }
162
+
163
+ const clonedState = structuredClone( nextState );
164
+ extraReducer( clonedState, action as PayloadAction< unknown > );
165
+
166
+ return clonedState;
167
+ },
168
+ };
@@ -6,6 +6,7 @@ import {
6
6
  selectArchivedThisSession,
7
7
  selectComponentByUid,
8
8
  selectComponents,
9
+ selectCreatedThisSession,
9
10
  selectCurrentComponent,
10
11
  selectCurrentComponentId,
11
12
  selectOverridableProps,
@@ -40,6 +41,9 @@ export const componentsSelectors = {
40
41
  getArchivedThisSession() {
41
42
  return selectArchivedThisSession( getState() );
42
43
  },
44
+ getCreatedThisSession() {
45
+ return selectCreatedThisSession( getState() );
46
+ },
43
47
  getComponents() {
44
48
  return selectComponents( getState() );
45
49
  },
@@ -0,0 +1,48 @@
1
+ import { type V1Document } from '@elementor/editor-documents';
2
+
3
+ import {
4
+ type Component,
5
+ type ComponentId,
6
+ type PublishedComponent,
7
+ type StylesDefinition,
8
+ type UnpublishedComponent,
9
+ } from '../types';
10
+
11
+ export type SanitizeAttributes = 'overridableProps';
12
+
13
+ export type ComponentsState = {
14
+ data: PublishedComponent[];
15
+ unpublishedData: UnpublishedComponent[];
16
+ loadStatus: 'idle' | 'pending' | 'error';
17
+ styles: StylesDefinition;
18
+ createdThisSession: Component[ 'uid' ][];
19
+ archivedThisSession: ComponentId[];
20
+ path: ComponentsPathItem[];
21
+ currentComponentId: V1Document[ 'id' ] | null;
22
+ updatedComponentNames: Record< number, string >;
23
+
24
+ // We use this map to flag any sanitized attribute of a given component
25
+ // This map currently resets in response to the `editor/documents/open` command
26
+ sanitized: Record< ComponentId, Partial< Record< SanitizeAttributes, boolean > > >;
27
+ };
28
+
29
+ export type ComponentsPathItem = {
30
+ instanceId?: string;
31
+ instanceTitle?: string;
32
+ componentId: V1Document[ 'id' ];
33
+ };
34
+
35
+ export const initialState: ComponentsState = {
36
+ data: [],
37
+ unpublishedData: [],
38
+ loadStatus: 'idle',
39
+ styles: {},
40
+ createdThisSession: [],
41
+ archivedThisSession: [],
42
+ path: [],
43
+ currentComponentId: null,
44
+ updatedComponentNames: {},
45
+ sanitized: {},
46
+ };
47
+
48
+ export const SLICE_NAME = 'components';
@@ -1,176 +1,14 @@
1
- import { type V1Document } from '@elementor/editor-documents';
2
- import {
3
- __createSelector as createSelector,
4
- __createSlice as createSlice,
5
- __useSelector as useSelector,
6
- type PayloadAction,
7
- type SliceState,
8
- } from '@elementor/store';
1
+ import { __createSelector as createSelector, __useSelector as useSelector, type SliceState } from '@elementor/store';
9
2
 
10
- import {
11
- type Component,
12
- type ComponentId,
13
- type OverridableProps,
14
- type PublishedComponent,
15
- type StylesDefinition,
16
- type UnpublishedComponent,
17
- } from '../types';
18
- import { loadComponents } from './thunks';
19
-
20
- type GetComponentResponse = PublishedComponent[];
21
-
22
- type Status = 'idle' | 'pending' | 'error';
23
-
24
- export type SanitizeAttributes = 'overridableProps';
25
-
26
- type ComponentsState = {
27
- data: PublishedComponent[];
28
- unpublishedData: UnpublishedComponent[];
29
- loadStatus: Status;
30
- styles: StylesDefinition;
31
- createdThisSession: Component[ 'uid' ][];
32
- archivedThisSession: ComponentId[];
33
- path: ComponentsPathItem[];
34
- currentComponentId: V1Document[ 'id' ] | null;
35
- updatedComponentNames: Record< number, string >;
36
-
37
- // We use this map to flag any sanitized attribute of a given component
38
- // This map currently resets in response to the `editor/documents/open` command
39
- sanitized: Record< ComponentId, Partial< Record< SanitizeAttributes, boolean > > >;
40
- };
3
+ import type { ComponentId, OverridableProps, PublishedComponent, UnpublishedComponent } from '../types';
4
+ import { type slice } from './extensible-slice';
5
+ import { type SanitizeAttributes, SLICE_NAME } from './store-types';
41
6
 
42
7
  export type ComponentsSlice = SliceState< typeof slice >;
43
8
 
44
- export type ComponentsPathItem = {
45
- instanceId?: string;
46
- instanceTitle?: string;
47
- componentId: V1Document[ 'id' ];
48
- };
49
-
50
- export const initialState: ComponentsState = {
51
- data: [],
52
- unpublishedData: [],
53
- loadStatus: 'idle',
54
- styles: {},
55
- createdThisSession: [],
56
- archivedThisSession: [],
57
- path: [],
58
- currentComponentId: null,
59
- updatedComponentNames: {},
60
- sanitized: {},
61
- };
62
-
63
- export const SLICE_NAME = 'components';
64
-
65
- export const slice = createSlice( {
66
- name: SLICE_NAME,
67
- initialState,
68
- reducers: {
69
- add: ( state, { payload }: PayloadAction< PublishedComponent | PublishedComponent[] > ) => {
70
- if ( Array.isArray( payload ) ) {
71
- state.data = [ ...payload, ...state.data ];
72
- } else {
73
- state.data.unshift( payload );
74
- }
75
- },
76
- load: ( state, { payload }: PayloadAction< PublishedComponent[] > ) => {
77
- state.data = payload;
78
- },
79
- addUnpublished: ( state, { payload }: PayloadAction< UnpublishedComponent > ) => {
80
- state.unpublishedData.unshift( payload );
81
- },
82
- removeUnpublished: ( state, { payload }: PayloadAction< string | string[] > ) => {
83
- const uidsToRemove = Array.isArray( payload ) ? payload : [ payload ];
84
- state.unpublishedData = state.unpublishedData.filter(
85
- ( component ) => ! uidsToRemove.includes( component.uid )
86
- );
87
- },
88
- resetUnpublished: ( state ) => {
89
- state.unpublishedData = [];
90
- },
91
- removeStyles( state, { payload }: PayloadAction< { id: ComponentId } > ) {
92
- const { [ payload.id ]: _, ...rest } = state.styles;
93
-
94
- state.styles = rest;
95
- },
96
- addStyles: ( state, { payload } ) => {
97
- state.styles = { ...state.styles, ...payload };
98
- },
99
- addCreatedThisSession: ( state, { payload }: PayloadAction< string > ) => {
100
- state.createdThisSession.push( payload );
101
- },
102
- removeCreatedThisSession: ( state, { payload }: PayloadAction< string > ) => {
103
- state.createdThisSession = state.createdThisSession.filter( ( uid ) => uid !== payload );
104
- },
105
- archive: ( state, { payload }: PayloadAction< number > ) => {
106
- const component = state.data.find( ( comp ) => comp.id === payload );
107
-
108
- if ( component ) {
109
- component.isArchived = true;
110
- state.archivedThisSession.push( payload );
111
- }
112
- },
113
- setCurrentComponentId: ( state, { payload }: PayloadAction< V1Document[ 'id' ] | null > ) => {
114
- state.currentComponentId = payload;
115
- },
116
- setPath: ( state, { payload }: PayloadAction< ComponentsPathItem[] > ) => {
117
- state.path = payload;
118
- },
119
- setOverridableProps: (
120
- state,
121
- { payload }: PayloadAction< { componentId: ComponentId; overridableProps: OverridableProps } >
122
- ) => {
123
- const component = state.data.find( ( comp ) => comp.id === payload.componentId );
124
-
125
- if ( ! component ) {
126
- return;
127
- }
128
-
129
- component.overridableProps = payload.overridableProps;
130
- },
131
- rename: ( state, { payload }: PayloadAction< { componentUid: string; name: string } > ) => {
132
- const component = state.data.find( ( comp ) => comp.uid === payload.componentUid );
133
-
134
- if ( ! component ) {
135
- return;
136
- }
137
- if ( component.id ) {
138
- state.updatedComponentNames[ component.id ] = payload.name;
139
- }
140
- component.name = payload.name;
141
- },
142
- cleanUpdatedComponentNames: ( state ) => {
143
- state.updatedComponentNames = {};
144
- },
145
- updateComponentSanitizedAttribute: (
146
- state,
147
- {
148
- payload: { componentId, attribute },
149
- }: PayloadAction< { componentId: ComponentId; attribute: SanitizeAttributes } >
150
- ) => {
151
- if ( ! state.sanitized[ componentId ] ) {
152
- state.sanitized[ componentId ] = {};
153
- }
154
-
155
- state.sanitized[ componentId ][ attribute ] = true;
156
- },
157
- resetSanitizedComponents: ( state ) => {
158
- state.sanitized = {};
159
- },
160
- },
161
- extraReducers: ( builder ) => {
162
- builder.addCase( loadComponents.fulfilled, ( state, { payload }: PayloadAction< GetComponentResponse > ) => {
163
- state.data = payload;
164
- state.loadStatus = 'idle';
165
- } );
166
- builder.addCase( loadComponents.pending, ( state ) => {
167
- state.loadStatus = 'pending';
168
- } );
169
- builder.addCase( loadComponents.rejected, ( state ) => {
170
- state.loadStatus = 'error';
171
- } );
172
- },
173
- } );
9
+ export { slice, registerComponentsReducer, createComponentsAction, __resetExtraReducers } from './extensible-slice';
10
+ export type { ComponentsState, ComponentsPathItem, SanitizeAttributes } from './store-types';
11
+ export { initialState, SLICE_NAME } from './store-types';
174
12
 
175
13
  export const selectData = ( state: ComponentsSlice ) => state[ SLICE_NAME ].data;
176
14
  export const selectArchivedThisSession = ( state: ComponentsSlice ) => state[ SLICE_NAME ].archivedThisSession;