@elementor/editor-components 4.0.1 → 4.0.3

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/dist/index.mjs CHANGED
@@ -76,11 +76,12 @@ var apiClient = {
76
76
  unlockComponent: async (componentId) => await httpService().post(`${BASE_URL}/unlock`, {
77
77
  componentId
78
78
  }).then((res) => res.data),
79
- getOverridableProps: async (componentId) => await httpService().get(`${BASE_URL}/overridable-props`, {
80
- params: {
81
- componentId: componentId.toString()
79
+ getOverridableProps: async (componentIds) => await httpService().get(
80
+ `${BASE_URL}/overridable-props`,
81
+ {
82
+ params: { "componentIds[]": componentIds }
82
83
  }
83
- }).then((res) => res.data.data),
84
+ ).then((res) => res.data),
84
85
  updateArchivedComponents: async (componentIds, status) => await httpService().post(
85
86
  `${BASE_URL}/archive`,
86
87
  {
@@ -180,6 +181,18 @@ var baseSlice = createSlice({
180
181
  }
181
182
  component.overridableProps = payload.overridableProps;
182
183
  },
184
+ loadOverridableProps: (state, { payload }) => {
185
+ const componentIds = Object.keys(payload);
186
+ componentIds.forEach((id) => {
187
+ const componentId = Number(id);
188
+ const overridableProps = payload[componentId];
189
+ const component = state.data.find((comp) => comp.id === componentId);
190
+ if (!component || !overridableProps) {
191
+ return;
192
+ }
193
+ component.overridableProps = overridableProps;
194
+ });
195
+ },
183
196
  rename: (state, { payload }) => {
184
197
  const component = state.data.find((comp) => comp.uid === payload.componentUid);
185
198
  if (!component) {
@@ -265,7 +278,16 @@ var selectUnpublishedComponents = createSelector(
265
278
  var selectLoadIsPending = createSelector(selectLoadStatus, (status) => status === "pending");
266
279
  var selectLoadIsError = createSelector(selectLoadStatus, (status) => status === "error");
267
280
  var selectStyles = (state) => state[SLICE_NAME].styles ?? {};
268
- var selectFlatStyles = createSelector(selectStylesDefinitions, (data) => Object.values(data).flat());
281
+ var selectFlatStyles = createSelector(
282
+ selectStylesDefinitions,
283
+ (_state, excludeComponentId = null) => excludeComponentId,
284
+ (data, excludeComponentId) => {
285
+ if (excludeComponentId === null) {
286
+ return Object.values(data).flat();
287
+ }
288
+ return Object.entries(data).filter(([id]) => id !== String(excludeComponentId)).map(([, styles]) => styles).flat();
289
+ }
290
+ );
269
291
  var selectCreatedThisSession = createSelector(
270
292
  getCreatedThisSession,
271
293
  (createdThisSession) => createdThisSession
@@ -2365,27 +2387,13 @@ async function getDocumentsMap(ids, cache) {
2365
2387
 
2366
2388
  // src/store/actions/load-components-overridable-props.ts
2367
2389
  import { __dispatch as dispatch4, __getState as getState6 } from "@elementor/store";
2368
- function loadComponentsOverridableProps(componentIds) {
2369
- if (!componentIds.length) {
2370
- return;
2371
- }
2372
- return Promise.all(componentIds.map(loadComponentOverrides));
2373
- }
2374
- async function loadComponentOverrides(componentId) {
2375
- const isOverridablePropsLoaded = selectIsOverridablePropsLoaded(getState6(), componentId);
2376
- if (isOverridablePropsLoaded) {
2377
- return;
2378
- }
2379
- const overridableProps = await apiClient.getOverridableProps(componentId);
2380
- if (!overridableProps) {
2390
+ async function loadComponentsOverridableProps(componentIds) {
2391
+ const unloadedIds = componentIds.filter((id) => !selectIsOverridablePropsLoaded(getState6(), id));
2392
+ if (!unloadedIds.length) {
2381
2393
  return;
2382
2394
  }
2383
- dispatch4(
2384
- slice.actions.setOverridableProps({
2385
- componentId,
2386
- overridableProps
2387
- })
2388
- );
2395
+ const { data } = await apiClient.getOverridableProps(unloadedIds);
2396
+ dispatch4(slice.actions.loadOverridableProps(data));
2389
2397
  }
2390
2398
 
2391
2399
  // src/store/actions/load-components-styles.ts
@@ -2997,6 +3005,7 @@ function removeComponentStyles(id) {
2997
3005
  }
2998
3006
 
2999
3007
  // src/store/components-styles-provider.ts
3008
+ import { getCurrentDocumentId } from "@elementor/editor-elements";
3000
3009
  import { createStylesProvider } from "@elementor/editor-styles-repository";
3001
3010
  import { __getState as getState10, __subscribeWithSelector as subscribeWithSelector } from "@elementor/store";
3002
3011
  var componentsStylesProvider = createStylesProvider({
@@ -3010,7 +3019,8 @@ var componentsStylesProvider = createStylesProvider({
3010
3019
  ),
3011
3020
  actions: {
3012
3021
  all: () => {
3013
- return selectFlatStyles(getState10());
3022
+ const currentDocumentId = getCurrentDocumentId();
3023
+ return selectFlatStyles(getState10(), currentDocumentId);
3014
3024
  },
3015
3025
  get: (id) => {
3016
3026
  return selectFlatStyles(getState10()).find((style) => style.id === id) ?? null;