@elementor/editor-components 4.2.0-934 → 4.2.0-936

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
@@ -7,7 +7,7 @@ import {
7
7
  import { getV1CurrentDocument } from "@elementor/editor-documents";
8
8
  import { registerEditingPanelReplacement } from "@elementor/editor-editing-panel";
9
9
  import { injectTab } from "@elementor/editor-elements-panel";
10
- import { stylesRepository } from "@elementor/editor-styles-repository";
10
+ import { embeddedDocumentsManager as embeddedDocumentsManager2 } from "@elementor/editor-embedded-documents-manager";
11
11
  import { registerDataHook as registerDataHook2 } from "@elementor/editor-v1-adapters";
12
12
  import { __registerSlice as registerSlice } from "@elementor/store";
13
13
  import { __ as __16 } from "@wordpress/i18n";
@@ -24,7 +24,6 @@ var initialState = {
24
24
  data: [],
25
25
  unpublishedData: [],
26
26
  loadStatus: "idle",
27
- styles: {},
28
27
  createdThisSession: [],
29
28
  archivedThisSession: [],
30
29
  path: [],
@@ -148,13 +147,6 @@ var baseSlice = createSlice({
148
147
  resetUnpublished: (state) => {
149
148
  state.unpublishedData = [];
150
149
  },
151
- removeStyles(state, { payload }) {
152
- const { [payload.id]: _, ...rest } = state.styles;
153
- state.styles = rest;
154
- },
155
- addStyles: (state, { payload }) => {
156
- state.styles = { ...state.styles, ...payload };
157
- },
158
150
  addCreatedThisSession: (state, { payload }) => {
159
151
  state.createdThisSession.push(payload);
160
152
  },
@@ -249,7 +241,6 @@ var slice = {
249
241
  var selectData = (state) => state[SLICE_NAME].data;
250
242
  var selectArchivedThisSession = (state) => state[SLICE_NAME].archivedThisSession;
251
243
  var selectLoadStatus = (state) => state[SLICE_NAME].loadStatus;
252
- var selectStylesDefinitions = (state) => state[SLICE_NAME].styles ?? {};
253
244
  var selectUnpublishedData = (state) => state[SLICE_NAME].unpublishedData;
254
245
  var getCreatedThisSession = (state) => state[SLICE_NAME].createdThisSession;
255
246
  var getPath = (state) => state[SLICE_NAME].path;
@@ -277,17 +268,6 @@ var selectUnpublishedComponents = createSelector(
277
268
  );
278
269
  var selectLoadIsPending = createSelector(selectLoadStatus, (status) => status === "pending");
279
270
  var selectLoadIsError = createSelector(selectLoadStatus, (status) => status === "error");
280
- var selectStyles = (state) => state[SLICE_NAME].styles ?? {};
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
- );
291
271
  var selectCreatedThisSession = createSelector(
292
272
  getCreatedThisSession,
293
273
  (createdThisSession) => createdThisSession
@@ -1682,12 +1662,6 @@ var componentsActions = {
1682
1662
  resetUnpublished() {
1683
1663
  dispatch2(slice.actions.resetUnpublished());
1684
1664
  },
1685
- removeStyles(id) {
1686
- dispatch2(slice.actions.removeStyles({ id }));
1687
- },
1688
- addStyles(styles) {
1689
- dispatch2(slice.actions.addStyles(styles));
1690
- },
1691
1665
  addCreatedThisSession(uid) {
1692
1666
  dispatch2(slice.actions.addCreatedThisSession(uid));
1693
1667
  },
@@ -2516,13 +2490,18 @@ import { isHandlingTemplateStyles, useLoadedTemplates } from "@elementor/editor-
2516
2490
 
2517
2491
  // src/store/actions/load-components-assets.ts
2518
2492
  import { isDocumentDirty, setDocumentModifiedStatus } from "@elementor/editor-documents";
2493
+ import { embeddedDocumentsManager } from "@elementor/editor-embedded-documents-manager";
2519
2494
 
2520
2495
  // src/utils/get-component-documents.ts
2521
- async function getComponentDocuments(elements, cache = /* @__PURE__ */ new Map()) {
2522
- const componentIds = await getComponentIds(elements, cache);
2496
+ async function getComponentDocuments({
2497
+ elements,
2498
+ cache = /* @__PURE__ */ new Map(),
2499
+ isRecursive = true
2500
+ }) {
2501
+ const componentIds = await getComponentIds(elements, cache, isRecursive);
2523
2502
  return getDocumentsMap(componentIds, cache);
2524
2503
  }
2525
- async function getComponentIds(elements, cache) {
2504
+ async function getComponentIds(elements, cache, isRecursive) {
2526
2505
  const results = await Promise.all(
2527
2506
  elements.map(async ({ widgetType, elType, elements: childElements, settings }) => {
2528
2507
  const ids = [];
@@ -2538,8 +2517,8 @@ async function getComponentIds(elements, cache) {
2538
2517
  const doc = await cache.get(componentId);
2539
2518
  childElements = doc?.elements;
2540
2519
  }
2541
- if (childElements?.length) {
2542
- const childIds = await getComponentIds(childElements, cache);
2520
+ if (isRecursive && childElements?.length) {
2521
+ const childIds = await getComponentIds(childElements, cache, isRecursive);
2543
2522
  ids.push(...childIds);
2544
2523
  }
2545
2524
  return ids;
@@ -2571,47 +2550,13 @@ async function loadComponentsOverridableProps(componentIds) {
2571
2550
  dispatch3(slice.actions.loadOverridableProps(data));
2572
2551
  }
2573
2552
 
2574
- // src/store/actions/load-components-styles.ts
2575
- import { addDocumentClasses } from "@elementor/editor-global-classes";
2576
- import { __dispatch as dispatch4, __getState as getState7 } from "@elementor/store";
2577
- function loadComponentsStyles(documents) {
2578
- if (!documents.size) {
2579
- return;
2580
- }
2581
- const knownComponents = selectStyles(getState7());
2582
- const unknownDocuments = new Map([...documents.entries()].filter(([id]) => !knownComponents[id]));
2583
- if (!unknownDocuments.size) {
2584
- return;
2585
- }
2586
- addStyles(unknownDocuments);
2587
- }
2588
- function addStyles(documents) {
2589
- const styles = Object.fromEntries(
2590
- [...documents.entries()].map(([id, document2]) => {
2591
- addDocumentClasses(id);
2592
- return [id, extractStylesFromDocument(document2)];
2593
- })
2594
- );
2595
- dispatch4(slice.actions.addStyles(styles));
2596
- }
2597
- function extractStylesFromDocument(document2) {
2598
- if (!document2.elements?.length) {
2599
- return [];
2600
- }
2601
- return document2.elements.flatMap(extractStylesFromElement);
2602
- }
2603
- function extractStylesFromElement(element) {
2604
- return [
2605
- ...Object.values(element.styles ?? {}),
2606
- ...(element.elements ?? []).flatMap(extractStylesFromElement)
2607
- ];
2608
- }
2609
-
2610
2553
  // src/store/actions/load-components-assets.ts
2611
2554
  async function loadComponentsAssets(elements) {
2612
- const documents = await getComponentDocuments(elements);
2555
+ const documents = await getComponentDocuments({ elements, isRecursive: false });
2613
2556
  updateDocumentState(documents);
2614
- loadComponentsStyles(documents);
2557
+ documents.forEach((document2, id) => {
2558
+ embeddedDocumentsManager.setDocument(id, document2);
2559
+ });
2615
2560
  await loadComponentsOverridableProps([...documents.keys()]);
2616
2561
  }
2617
2562
  function updateDocumentState(documents) {
@@ -2642,7 +2587,7 @@ import {
2642
2587
  } from "@elementor/editor-canvas";
2643
2588
  import { getCurrentDocument } from "@elementor/editor-documents";
2644
2589
  import { notify as notify2 } from "@elementor/editor-notifications";
2645
- import { __getState as getState8 } from "@elementor/store";
2590
+ import { __getState as getState7 } from "@elementor/store";
2646
2591
  import { hasProInstalled as hasProInstalled2 } from "@elementor/utils";
2647
2592
  import { __ as __13 } from "@wordpress/i18n";
2648
2593
 
@@ -3033,7 +2978,7 @@ function createComponentModel() {
3033
2978
  }
3034
2979
  const componentUid = editorSettings?.component_uid;
3035
2980
  if (componentUid) {
3036
- const component = selectComponentByUid(getState8(), componentUid);
2981
+ const component = selectComponentByUid(getState7(), componentUid);
3037
2982
  if (component?.name) {
3038
2983
  return component.name;
3039
2984
  }
@@ -3055,10 +3000,10 @@ function createComponentModel() {
3055
3000
 
3056
3001
  // src/populate-store.ts
3057
3002
  import { useEffect as useEffect2 } from "react";
3058
- import { __dispatch as dispatch5 } from "@elementor/store";
3003
+ import { __dispatch as dispatch4 } from "@elementor/store";
3059
3004
  function PopulateStore() {
3060
3005
  useEffect2(() => {
3061
- dispatch5(loadComponents());
3006
+ dispatch4(loadComponents());
3062
3007
  }, []);
3063
3008
  return null;
3064
3009
  }
@@ -3067,7 +3012,7 @@ function PopulateStore() {
3067
3012
  import { getAllDescendants } from "@elementor/editor-elements";
3068
3013
  import { notify as notify3 } from "@elementor/editor-notifications";
3069
3014
  import { blockCommand } from "@elementor/editor-v1-adapters";
3070
- import { __getState as getState9 } from "@elementor/store";
3015
+ import { __getState as getState8 } from "@elementor/store";
3071
3016
  import { __ as __14 } from "@wordpress/i18n";
3072
3017
  var COMPONENT_TYPE = "e-component";
3073
3018
  var COMPONENT_CIRCULAR_NESTING_ALERT = {
@@ -3093,7 +3038,7 @@ function wouldCreateCircularNesting(componentIdToAdd) {
3093
3038
  if (componentIdToAdd === void 0) {
3094
3039
  return false;
3095
3040
  }
3096
- const state = getState9();
3041
+ const state = getState8();
3097
3042
  const currentComponentId = selectCurrentComponentId(state);
3098
3043
  const path = selectPath(state);
3099
3044
  if (currentComponentId === null) {
@@ -3191,35 +3136,9 @@ function blockCircularPaste(args) {
3191
3136
  }
3192
3137
 
3193
3138
  // src/store/actions/remove-component-styles.ts
3194
- import { __dispatch as dispatch6 } from "@elementor/store";
3195
3139
  function removeComponentStyles(id) {
3196
3140
  apiClient.invalidateComponentConfigCache(id);
3197
- dispatch6(slice.actions.removeStyles({ id }));
3198
- }
3199
-
3200
- // src/store/components-styles-provider.ts
3201
- import { getCurrentDocumentId } from "@elementor/editor-elements";
3202
- import { createStylesProvider } from "@elementor/editor-styles-repository";
3203
- import { __getState as getState10, __subscribeWithSelector as subscribeWithSelector } from "@elementor/store";
3204
- var componentsStylesProvider = createStylesProvider({
3205
- key: "components-styles",
3206
- priority: 100,
3207
- subscribe: (cb) => subscribeWithSelector(
3208
- (state) => state[SLICE_NAME],
3209
- () => {
3210
- cb();
3211
- }
3212
- ),
3213
- actions: {
3214
- all: () => {
3215
- const currentDocumentId = getCurrentDocumentId();
3216
- return selectFlatStyles(getState10(), currentDocumentId);
3217
- },
3218
- get: (id) => {
3219
- return selectFlatStyles(getState10()).find((style) => style.id === id) ?? null;
3220
- }
3221
- }
3222
- });
3141
+ }
3223
3142
 
3224
3143
  // src/sync/publish-draft-components-in-page-before-save.ts
3225
3144
  import { invalidateDocumentData as invalidateDocumentData2, isDocumentDirty as isDocumentDirty2 } from "@elementor/editor-documents";
@@ -3233,7 +3152,7 @@ async function publishDraftComponentsInPageBeforeSave({ status, elements }) {
3233
3152
  if (status !== "publish") {
3234
3153
  return;
3235
3154
  }
3236
- const documents = await getComponentDocuments(elements);
3155
+ const documents = await getComponentDocuments({ elements });
3237
3156
  const draftIds = [...documents.values()].filter(isDocumentDirty2).map((document2) => document2.id);
3238
3157
  if (draftIds.length === 0) {
3239
3158
  return;
@@ -3296,7 +3215,6 @@ function load(result) {
3296
3215
 
3297
3216
  // src/init.ts
3298
3217
  function init() {
3299
- stylesRepository.register(componentsStylesProvider);
3300
3218
  registerSlice(slice);
3301
3219
  registerElementType(
3302
3220
  COMPONENT_WIDGET_TYPE2,
@@ -3317,12 +3235,16 @@ function init() {
3317
3235
  id: "components-populate-store",
3318
3236
  component: PopulateStore
3319
3237
  });
3320
- registerDataHook2("after", "editor/documents/attach-preview", async () => {
3321
- const { id, config } = getV1CurrentDocument();
3322
- if (id) {
3323
- removeComponentStyles(id);
3238
+ registerDataHook2("after", "editor/documents/attach-preview", () => {
3239
+ const { id, config } = getV1CurrentDocument() ?? {};
3240
+ if (!id) {
3241
+ return;
3324
3242
  }
3325
- await loadComponentsAssets(config?.elements ?? []);
3243
+ removeComponentStyles(id);
3244
+ void loadComponentsAssets(config?.elements ?? []);
3245
+ });
3246
+ embeddedDocumentsManager2.onDocumentLoad((_documentId, data) => {
3247
+ void loadComponentsAssets(data.elements ?? []);
3326
3248
  });
3327
3249
  injectIntoLogic({
3328
3250
  id: "templates",