@elementor/editor-components 4.0.0-633 → 4.0.0-635

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.
Files changed (34) hide show
  1. package/dist/index.d.mts +1516 -1
  2. package/dist/index.d.ts +1516 -1
  3. package/dist/index.js +372 -232
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +280 -210
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +23 -23
  8. package/src/extended/components/create-component-form/create-component-form.tsx +2 -3
  9. package/src/extended/init.ts +5 -1
  10. package/src/extended/store/actions/add-overridable-group.ts +14 -20
  11. package/src/extended/store/actions/archive-component.ts +2 -3
  12. package/src/extended/store/actions/create-unpublished-component.ts +9 -12
  13. package/src/extended/store/actions/delete-overridable-group.ts +7 -13
  14. package/src/extended/store/actions/delete-overridable-prop.ts +9 -15
  15. package/src/extended/store/actions/rename-component.ts +2 -3
  16. package/src/extended/store/actions/rename-overridable-group.ts +7 -13
  17. package/src/extended/store/actions/reorder-group-props.ts +14 -20
  18. package/src/extended/store/actions/reorder-overridable-groups.ts +10 -16
  19. package/src/extended/store/actions/reset-sanitized-components.ts +2 -4
  20. package/src/extended/store/actions/set-overridable-prop.ts +5 -13
  21. package/src/extended/store/actions/update-component-sanitized-attribute.ts +3 -4
  22. package/src/extended/store/actions/update-current-component.ts +5 -14
  23. package/src/extended/store/actions/update-overridable-prop-params.ts +11 -17
  24. package/src/extended/sync/cleanup-overridable-props-on-delete.ts +3 -10
  25. package/src/extended/sync/create-components-before-save.ts +12 -14
  26. package/src/extended/sync/set-component-overridable-props-settings-before-save.ts +2 -3
  27. package/src/extended/sync/update-archived-component-before-save.ts +2 -3
  28. package/src/extended/sync/update-component-title-before-save.ts +4 -5
  29. package/src/extended/utils/component-name-validation.ts +2 -4
  30. package/src/extended/utils/is-editing-component.ts +2 -10
  31. package/src/index.ts +120 -0
  32. package/src/store/actions/update-overridable-prop.ts +4 -10
  33. package/src/store/dispatchers.ts +63 -0
  34. package/src/store/selectors.ts +49 -0
@@ -1,9 +1,9 @@
1
1
  import { updateElementSettings, type V1ElementData } from '@elementor/editor-elements';
2
- import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
3
2
 
4
3
  import { apiClient } from '../../api';
5
4
  import { type ComponentInstanceProp } from '../../prop-types/component-instance-prop-type';
6
- import { selectUnpublishedComponents, slice } from '../../store/store';
5
+ import { componentsActions } from '../../store/dispatchers';
6
+ import { componentsSelectors } from '../../store/selectors';
7
7
  import { type DocumentSaveStatus, type UnpublishedComponent } from '../../types';
8
8
 
9
9
  export async function createComponentsBeforeSave( {
@@ -13,7 +13,7 @@ export async function createComponentsBeforeSave( {
13
13
  elements: V1ElementData[];
14
14
  status: DocumentSaveStatus;
15
15
  } ) {
16
- const unpublishedComponents = selectUnpublishedComponents( getState() );
16
+ const unpublishedComponents = componentsSelectors.getUnpublishedComponents();
17
17
 
18
18
  if ( ! unpublishedComponents.length ) {
19
19
  return;
@@ -24,20 +24,18 @@ export async function createComponentsBeforeSave( {
24
24
 
25
25
  updateComponentInstances( elements, uidToComponentId );
26
26
 
27
- dispatch(
28
- slice.actions.add(
29
- unpublishedComponents.map( ( component ) => ( {
30
- id: uidToComponentId.get( component.uid ) as number,
31
- name: component.name,
32
- uid: component.uid,
33
- overridableProps: component.overridableProps ? component.overridableProps : undefined,
34
- } ) )
35
- )
27
+ componentsActions.add(
28
+ unpublishedComponents.map( ( component ) => ( {
29
+ id: uidToComponentId.get( component.uid ) as number,
30
+ name: component.name,
31
+ uid: component.uid,
32
+ overridableProps: component.overridableProps ? component.overridableProps : undefined,
33
+ } ) )
36
34
  );
37
- dispatch( slice.actions.resetUnpublished() );
35
+ componentsActions.resetUnpublished();
38
36
  } catch ( error ) {
39
37
  const failedUids = unpublishedComponents.map( ( component ) => component.uid );
40
- dispatch( slice.actions.removeUnpublished( failedUids ) );
38
+ componentsActions.removeUnpublished( failedUids );
41
39
 
42
40
  throw new Error( `Failed to publish components: ${ error }` );
43
41
  }
@@ -1,8 +1,7 @@
1
1
  import { type V1Document } from '@elementor/editor-documents';
2
2
  import { type V1Element } from '@elementor/editor-elements';
3
- import { __getState as getState } from '@elementor/store';
4
3
 
5
- import { selectOverridableProps } from '../../store/store';
4
+ import { componentsSelectors } from '../../store/selectors';
6
5
  import { COMPONENT_DOCUMENT_TYPE } from '../consts';
7
6
 
8
7
  export const setComponentOverridablePropsSettingsBeforeSave = ( {
@@ -16,7 +15,7 @@ export const setComponentOverridablePropsSettingsBeforeSave = ( {
16
15
  return;
17
16
  }
18
17
 
19
- const overridableProps = selectOverridableProps( getState(), currentDocument.id );
18
+ const overridableProps = componentsSelectors.getOverridableProps( currentDocument.id );
20
19
  if ( overridableProps ) {
21
20
  container.settings.set( 'overridable_props', overridableProps );
22
21
  }
@@ -1,8 +1,7 @@
1
1
  import { type NotificationData, notify } from '@elementor/editor-notifications';
2
- import { __getState as getState } from '@elementor/store';
3
2
 
4
3
  import { apiClient } from '../../api';
5
- import { selectArchivedThisSession } from '../../store/store';
4
+ import { componentsSelectors } from '../../store/selectors';
6
5
  import { type DocumentSaveStatus } from '../../types';
7
6
 
8
7
  const failedNotification = ( message: string ): NotificationData => ( {
@@ -13,7 +12,7 @@ const failedNotification = ( message: string ): NotificationData => ( {
13
12
 
14
13
  export const updateArchivedComponentBeforeSave = async ( status: DocumentSaveStatus ) => {
15
14
  try {
16
- const archivedComponents = selectArchivedThisSession( getState() );
15
+ const archivedComponents = componentsSelectors.getArchivedThisSession();
17
16
 
18
17
  if ( ! archivedComponents.length ) {
19
18
  return;
@@ -1,11 +1,10 @@
1
- import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
2
-
3
1
  import { apiClient } from '../../api';
4
- import { selectUpdatedComponentNames, slice } from '../../store/store';
2
+ import { componentsActions } from '../../store/dispatchers';
3
+ import { componentsSelectors } from '../../store/selectors';
5
4
  import { type DocumentSaveStatus } from '../../types';
6
5
 
7
6
  export const updateComponentTitleBeforeSave = async ( status: DocumentSaveStatus ) => {
8
- const updatedComponentNames = selectUpdatedComponentNames( getState() );
7
+ const updatedComponentNames = componentsSelectors.getUpdatedComponentNames();
9
8
 
10
9
  if ( ! updatedComponentNames.length ) {
11
10
  return;
@@ -14,6 +13,6 @@ export const updateComponentTitleBeforeSave = async ( status: DocumentSaveStatus
14
13
  const result = await apiClient.updateComponentTitle( updatedComponentNames, status );
15
14
 
16
15
  if ( result.failedIds.length === 0 ) {
17
- dispatch( slice.actions.cleanUpdatedComponentNames() );
16
+ componentsActions.cleanUpdatedComponentNames();
18
17
  }
19
18
  };
@@ -1,12 +1,10 @@
1
- import { __getState as getState } from '@elementor/store';
2
-
3
- import { selectComponents } from '../../store/store';
1
+ import { componentsSelectors } from '../../store/selectors';
4
2
  import { createSubmitComponentSchema } from './component-form-schema';
5
3
 
6
4
  type ValidationResult = { isValid: true; errorMessage: null } | { isValid: false; errorMessage: string };
7
5
 
8
6
  export function validateComponentName( label: string ): ValidationResult {
9
- const existingComponentTitles = selectComponents( getState() )?.map( ( { name } ) => name ) ?? [];
7
+ const existingComponentTitles = componentsSelectors.getComponents()?.map( ( { name } ) => name ) ?? [];
10
8
  const schema = createSubmitComponentSchema( existingComponentTitles );
11
9
  const result = schema.safeParse( { componentName: label.toLowerCase() } );
12
10
 
@@ -1,13 +1,5 @@
1
- import { __getStore as getStore } from '@elementor/store';
2
-
3
- import { type ComponentsSlice, selectCurrentComponentId } from '../../store/store';
1
+ import { componentsSelectors } from '../../store/selectors';
4
2
 
5
3
  export function isEditingComponent(): boolean {
6
- const state = getStore()?.getState() as ComponentsSlice | undefined;
7
-
8
- if ( ! state ) {
9
- return false;
10
- }
11
-
12
- return selectCurrentComponentId( state ) !== null;
4
+ return componentsSelectors.getCurrentComponentId() !== null;
13
5
  }
package/src/index.ts CHANGED
@@ -1 +1,121 @@
1
1
  export { init } from './init';
2
+
3
+ export { apiClient } from './api';
4
+ export type { ComponentItems, CreateComponentPayload, CreateComponentResponse } from './api';
5
+
6
+ export { ComponentSearch } from './components/components-tab/component-search';
7
+ export { ComponentItem, ComponentName } from './components/components-tab/components-item';
8
+ export type { ComponentItemProps, ComponentNameProps } from './components/components-tab/components-item';
9
+ export {
10
+ ComponentsList,
11
+ EmptySearchResult,
12
+ EmptyState as ComponentsEmptyState,
13
+ useFilteredComponents,
14
+ } from './components/components-tab/components-list';
15
+ export { LoadingComponents } from './components/components-tab/loading-components';
16
+ export { SearchProvider, useSearch } from './components/components-tab/search-provider';
17
+ export { EmptyState as InstanceEmptyState } from './components/instance-editing-panel/empty-state';
18
+ export { InstancePanelBody } from './components/instance-editing-panel/instance-panel-body';
19
+ export { EditComponentAction, InstancePanelHeader } from './components/instance-editing-panel/instance-panel-header';
20
+ export { useInstancePanelData } from './components/instance-editing-panel/use-instance-panel-data';
21
+
22
+ export { COMPONENT_WIDGET_TYPE } from './create-component-type';
23
+
24
+ export { useComponents } from './hooks/use-components';
25
+ export { useComponentsPermissions } from './hooks/use-components-permissions';
26
+ export { useSanitizeOverridableProps } from './hooks/use-sanitize-overridable-props';
27
+
28
+ export { componentInstanceOverridePropTypeUtil } from './prop-types/component-instance-override-prop-type';
29
+ export type {
30
+ ComponentInstanceOverrideProp,
31
+ ComponentInstanceOverridePropValue,
32
+ } from './prop-types/component-instance-override-prop-type';
33
+ export { componentInstanceOverridesPropTypeUtil } from './prop-types/component-instance-overrides-prop-type';
34
+ export type {
35
+ ComponentInstanceOverride,
36
+ ComponentInstanceOverridesPropValue,
37
+ } from './prop-types/component-instance-overrides-prop-type';
38
+ export { componentInstancePropTypeUtil } from './prop-types/component-instance-prop-type';
39
+ export type { ComponentInstanceProp, ComponentInstancePropValue } from './prop-types/component-instance-prop-type';
40
+ export { componentOverridablePropTypeUtil } from './prop-types/component-overridable-prop-type';
41
+ export type {
42
+ ComponentOverridableProp,
43
+ ComponentOverridablePropValue,
44
+ } from './prop-types/component-overridable-prop-type';
45
+
46
+ export {
47
+ ComponentInstanceProvider,
48
+ useComponentId,
49
+ useComponentInstanceOverrides,
50
+ useComponentOverridableProps,
51
+ } from './provider/component-instance-context';
52
+ export {
53
+ OverridablePropProvider,
54
+ useComponentInstanceElement,
55
+ useOverridablePropValue,
56
+ } from './provider/overridable-prop-context';
57
+
58
+ export { loadComponentsAssets } from './store/actions/load-components-assets';
59
+ export { updateOverridableProp } from './store/actions/update-overridable-prop';
60
+ export { componentsActions } from './store/dispatchers';
61
+ export { componentsSelectors } from './store/selectors';
62
+ export {
63
+ SLICE_NAME,
64
+ selectArchivedThisSession,
65
+ selectComponent,
66
+ selectComponentByUid,
67
+ selectComponents,
68
+ selectCreatedThisSession,
69
+ selectCurrentComponent,
70
+ selectCurrentComponentId,
71
+ selectData,
72
+ selectFlatStyles,
73
+ selectIsOverridablePropsLoaded,
74
+ selectLoadIsError,
75
+ selectLoadIsPending,
76
+ selectOverridableProps,
77
+ selectPath,
78
+ selectStyles,
79
+ selectUnpublishedComponents,
80
+ selectUpdatedComponentNames,
81
+ slice,
82
+ useComponent,
83
+ useCurrentComponent,
84
+ useCurrentComponentId,
85
+ useIsSanitizedComponent,
86
+ useOverridableProps,
87
+ } from './store/store';
88
+ export type { ComponentsPathItem, ComponentsSlice, SanitizeAttributes } from './store/store';
89
+
90
+ export { publishDraftComponentsInPageBeforeSave } from './sync/publish-draft-components-in-page-before-save';
91
+
92
+ export type {
93
+ Component,
94
+ ComponentFormValues,
95
+ ComponentId,
96
+ ComponentOverridable,
97
+ ComponentRenderContext,
98
+ DocumentSaveStatus,
99
+ DocumentStatus,
100
+ ElementorStorage,
101
+ ExtendedWindow,
102
+ OriginalElementData,
103
+ OriginPropFields,
104
+ OverridableProp,
105
+ OverridableProps,
106
+ OverridablePropsGroup,
107
+ PublishedComponent,
108
+ StylesDefinition,
109
+ UnpublishedComponent,
110
+ UpdatedComponentName,
111
+ } from './types';
112
+
113
+ export { filterValidOverridableProps, isExposedPropValid } from './utils/filter-valid-overridable-props';
114
+ export { getContainerByOriginId } from './utils/get-container-by-origin-id';
115
+ export { getOverridableProp } from './utils/get-overridable-prop';
116
+ export { getPropTypeForComponentOverride } from './utils/get-prop-type-for-component-override';
117
+ export { isComponentInstance } from './utils/is-component-instance';
118
+ export { resolveOverridePropValue } from './utils/resolve-override-prop-value';
119
+ export { switchToComponent } from './utils/switch-to-component';
120
+ export { onElementDrop, trackComponentEvent } from './utils/tracking';
121
+ export type { Source } from './utils/tracking';
@@ -1,16 +1,15 @@
1
- import { __dispatch as dispatch, __getState as getState } from '@elementor/store';
2
-
3
1
  import { type ComponentOverridablePropValue } from '../../prop-types/component-overridable-prop-type';
4
2
  import { type OriginPropFields, type OverridableProps } from '../../types';
5
3
  import { resolveOverridePropValue } from '../../utils/resolve-override-prop-value';
6
- import { selectOverridableProps, slice } from '../store';
4
+ import { componentsActions } from '../dispatchers';
5
+ import { componentsSelectors } from '../selectors';
7
6
 
8
7
  export function updateOverridableProp(
9
8
  componentId: number,
10
9
  propValue: ComponentOverridablePropValue,
11
10
  originPropFields?: OriginPropFields
12
11
  ) {
13
- const overridableProps = selectOverridableProps( getState(), componentId );
12
+ const overridableProps = componentsSelectors.getOverridableProps( componentId );
14
13
 
15
14
  if ( ! overridableProps ) {
16
15
  return;
@@ -44,10 +43,5 @@ export function updateOverridableProp(
44
43
  },
45
44
  } satisfies OverridableProps;
46
45
 
47
- dispatch(
48
- slice.actions.setOverridableProps( {
49
- componentId,
50
- overridableProps: newOverridableProps,
51
- } )
52
- );
46
+ componentsActions.setOverridableProps( componentId, newOverridableProps );
53
47
  }
@@ -0,0 +1,63 @@
1
+ import { type V1Document } from '@elementor/editor-documents';
2
+ import { __dispatch as dispatch, __getStore as getStore } from '@elementor/store';
3
+
4
+ import { type ComponentId, type OverridableProps, type PublishedComponent, type UnpublishedComponent } from '../types';
5
+ import { type ComponentsPathItem, type SanitizeAttributes, slice } from './store';
6
+
7
+ function safeDispatch() {
8
+ return getStore()?.dispatch;
9
+ }
10
+
11
+ export const componentsActions = {
12
+ add( components: PublishedComponent | PublishedComponent[] ) {
13
+ dispatch( slice.actions.add( components ) );
14
+ },
15
+ load( components: PublishedComponent[] ) {
16
+ dispatch( slice.actions.load( components ) );
17
+ },
18
+ addUnpublished( component: UnpublishedComponent ) {
19
+ dispatch( slice.actions.addUnpublished( component ) );
20
+ },
21
+ removeUnpublished( uids: string | string[] ) {
22
+ dispatch( slice.actions.removeUnpublished( uids ) );
23
+ },
24
+ resetUnpublished() {
25
+ dispatch( slice.actions.resetUnpublished() );
26
+ },
27
+ removeStyles( id: ComponentId ) {
28
+ dispatch( slice.actions.removeStyles( { id } ) );
29
+ },
30
+ addStyles( styles: Record< string, unknown > ) {
31
+ dispatch( slice.actions.addStyles( styles ) );
32
+ },
33
+ addCreatedThisSession( uid: string ) {
34
+ dispatch( slice.actions.addCreatedThisSession( uid ) );
35
+ },
36
+ removeCreatedThisSession( uid: string ) {
37
+ dispatch( slice.actions.removeCreatedThisSession( uid ) );
38
+ },
39
+ archive( componentId: ComponentId ) {
40
+ dispatch( slice.actions.archive( componentId ) );
41
+ },
42
+ setCurrentComponentId( id: V1Document[ 'id' ] | null ) {
43
+ safeDispatch()?.( slice.actions.setCurrentComponentId( id ) );
44
+ },
45
+ setPath( path: ComponentsPathItem[] ) {
46
+ safeDispatch()?.( slice.actions.setPath( path ) );
47
+ },
48
+ setOverridableProps( componentId: ComponentId, overridableProps: OverridableProps ) {
49
+ dispatch( slice.actions.setOverridableProps( { componentId, overridableProps } ) );
50
+ },
51
+ rename( componentUid: string, name: string ) {
52
+ dispatch( slice.actions.rename( { componentUid, name } ) );
53
+ },
54
+ cleanUpdatedComponentNames() {
55
+ dispatch( slice.actions.cleanUpdatedComponentNames() );
56
+ },
57
+ updateComponentSanitizedAttribute( componentId: ComponentId, attribute: SanitizeAttributes ) {
58
+ dispatch( slice.actions.updateComponentSanitizedAttribute( { componentId, attribute } ) );
59
+ },
60
+ resetSanitizedComponents() {
61
+ dispatch( slice.actions.resetSanitizedComponents() );
62
+ },
63
+ };
@@ -0,0 +1,49 @@
1
+ import { __getState as getState, __getStore as getStore } from '@elementor/store';
2
+
3
+ import { type ComponentId } from '../types';
4
+ import {
5
+ type ComponentsSlice,
6
+ selectArchivedThisSession,
7
+ selectComponentByUid,
8
+ selectComponents,
9
+ selectCurrentComponent,
10
+ selectCurrentComponentId,
11
+ selectOverridableProps,
12
+ selectUnpublishedComponents,
13
+ selectUpdatedComponentNames,
14
+ } from './store';
15
+
16
+ function safeGetState(): ComponentsSlice | undefined {
17
+ return getStore()?.getState() as ComponentsSlice | undefined;
18
+ }
19
+
20
+ export const componentsSelectors = {
21
+ getOverridableProps( componentId: ComponentId ) {
22
+ return selectOverridableProps( getState(), componentId );
23
+ },
24
+ getCurrentComponent() {
25
+ return selectCurrentComponent( getState() );
26
+ },
27
+ getCurrentComponentId() {
28
+ const state = safeGetState();
29
+ if ( ! state ) {
30
+ return null;
31
+ }
32
+ return selectCurrentComponentId( state );
33
+ },
34
+ getUnpublishedComponents() {
35
+ return selectUnpublishedComponents( getState() );
36
+ },
37
+ getUpdatedComponentNames() {
38
+ return selectUpdatedComponentNames( getState() );
39
+ },
40
+ getArchivedThisSession() {
41
+ return selectArchivedThisSession( getState() );
42
+ },
43
+ getComponents() {
44
+ return selectComponents( getState() );
45
+ },
46
+ getComponentByUid( componentUid: string ) {
47
+ return selectComponentByUid( getState(), componentUid );
48
+ },
49
+ };