@elementor/editor-components 3.35.0-473 → 3.35.0-475
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.js +66 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -51
- package/dist/index.mjs.map +1 -1
- package/package.json +22 -22
- package/src/store/actions/load-components-assets.ts +7 -12
- package/src/store/actions/load-components-styles.ts +22 -21
- package/src/sync/update-components-before-save.ts +4 -9
- package/src/utils/get-component-documents.ts +70 -0
- package/src/utils/get-component-ids.ts +0 -41
package/dist/index.mjs
CHANGED
|
@@ -2319,31 +2319,48 @@ var archiveComponent = (componentId, componentName) => {
|
|
|
2319
2319
|
// src/store/actions/load-components-assets.ts
|
|
2320
2320
|
import { isDocumentDirty, setDocumentModifiedStatus as setDocumentModifiedStatus5 } from "@elementor/editor-documents";
|
|
2321
2321
|
|
|
2322
|
-
// src/utils/get-component-
|
|
2323
|
-
|
|
2324
|
-
const
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
}
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2322
|
+
// src/utils/get-component-documents.ts
|
|
2323
|
+
async function getComponentDocuments(elements, cache = /* @__PURE__ */ new Map()) {
|
|
2324
|
+
const componentIds = await getComponentIds(elements, cache);
|
|
2325
|
+
return getDocumentsMap(componentIds, cache);
|
|
2326
|
+
}
|
|
2327
|
+
async function getComponentIds(elements, cache) {
|
|
2328
|
+
const results = await Promise.all(
|
|
2329
|
+
elements.map(async ({ widgetType, elType, elements: childElements, settings }) => {
|
|
2330
|
+
const ids = [];
|
|
2331
|
+
if (isComponentInstance({ widgetType, elType })) {
|
|
2332
|
+
const componentId = settings?.component_instance?.value?.component_id.value;
|
|
2333
|
+
if (!componentId) {
|
|
2334
|
+
return ids;
|
|
2335
|
+
}
|
|
2335
2336
|
ids.push(componentId);
|
|
2337
|
+
if (!cache.has(componentId)) {
|
|
2338
|
+
cache.set(componentId, getComponentDocumentData(componentId));
|
|
2339
|
+
}
|
|
2340
|
+
const doc = await cache.get(componentId);
|
|
2341
|
+
childElements = doc?.elements;
|
|
2336
2342
|
}
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2343
|
+
if (childElements?.length) {
|
|
2344
|
+
const childIds = await getComponentIds(childElements, cache);
|
|
2345
|
+
ids.push(...childIds);
|
|
2346
|
+
}
|
|
2347
|
+
return ids;
|
|
2348
|
+
})
|
|
2349
|
+
);
|
|
2350
|
+
return [...new Set(results.flat())];
|
|
2351
|
+
}
|
|
2352
|
+
async function getDocumentsMap(ids, cache) {
|
|
2353
|
+
const documents = await Promise.all(
|
|
2354
|
+
ids.map(async (id2) => {
|
|
2355
|
+
const document = await cache.get(id2);
|
|
2356
|
+
if (!document) {
|
|
2357
|
+
return null;
|
|
2358
|
+
}
|
|
2359
|
+
return [id2, document];
|
|
2360
|
+
})
|
|
2361
|
+
);
|
|
2362
|
+
return new Map(documents.filter((document) => document !== null));
|
|
2363
|
+
}
|
|
2347
2364
|
|
|
2348
2365
|
// src/store/actions/load-components-overridable-props.ts
|
|
2349
2366
|
import { __dispatch as dispatch10, __getState as getState12 } from "@elementor/store";
|
|
@@ -2372,48 +2389,47 @@ async function loadComponentOverrides(componentId) {
|
|
|
2372
2389
|
|
|
2373
2390
|
// src/store/actions/load-components-styles.ts
|
|
2374
2391
|
import { __dispatch as dispatch11, __getState as getState13 } from "@elementor/store";
|
|
2375
|
-
|
|
2376
|
-
if (!
|
|
2392
|
+
function loadComponentsStyles(documents) {
|
|
2393
|
+
if (!documents.size) {
|
|
2377
2394
|
return;
|
|
2378
2395
|
}
|
|
2379
2396
|
const knownComponents = selectStyles(getState13());
|
|
2380
|
-
const
|
|
2381
|
-
if (!
|
|
2397
|
+
const unknownDocuments = new Map([...documents.entries()].filter(([id2]) => !knownComponents[id2]));
|
|
2398
|
+
if (!unknownDocuments.size) {
|
|
2382
2399
|
return;
|
|
2383
2400
|
}
|
|
2384
|
-
|
|
2385
|
-
}
|
|
2386
|
-
async function addComponentStyles(ids) {
|
|
2387
|
-
const newComponents = await loadStyles(ids);
|
|
2388
|
-
addStyles(newComponents);
|
|
2389
|
-
}
|
|
2390
|
-
async function loadStyles(ids) {
|
|
2391
|
-
return Promise.all(ids.map(async (id2) => [id2, await apiClient.getComponentConfig(id2)]));
|
|
2401
|
+
addStyles(unknownDocuments);
|
|
2392
2402
|
}
|
|
2393
|
-
function addStyles(
|
|
2403
|
+
function addStyles(documents) {
|
|
2394
2404
|
const styles = Object.fromEntries(
|
|
2395
|
-
|
|
2405
|
+
[...documents.entries()].map(([id2, document]) => [id2, extractStylesFromDocument(document)])
|
|
2396
2406
|
);
|
|
2397
2407
|
dispatch11(slice.actions.addStyles(styles));
|
|
2398
2408
|
}
|
|
2399
|
-
function
|
|
2400
|
-
|
|
2409
|
+
function extractStylesFromDocument(document) {
|
|
2410
|
+
if (!document.elements?.length) {
|
|
2411
|
+
return [];
|
|
2412
|
+
}
|
|
2413
|
+
return document.elements.flatMap(extractStylesFromElement);
|
|
2414
|
+
}
|
|
2415
|
+
function extractStylesFromElement(element) {
|
|
2416
|
+
return [
|
|
2417
|
+
...Object.values(element.styles ?? {}),
|
|
2418
|
+
...(element.elements ?? []).flatMap(extractStylesFromElement)
|
|
2419
|
+
];
|
|
2401
2420
|
}
|
|
2402
2421
|
|
|
2403
2422
|
// src/store/actions/load-components-assets.ts
|
|
2404
2423
|
async function loadComponentsAssets(elements) {
|
|
2405
|
-
const
|
|
2424
|
+
const documents = await getComponentDocuments(elements);
|
|
2406
2425
|
return Promise.all([
|
|
2407
|
-
updateDocumentState(
|
|
2408
|
-
loadComponentsOverridableProps(
|
|
2409
|
-
loadComponentsStyles(
|
|
2426
|
+
updateDocumentState(documents),
|
|
2427
|
+
loadComponentsOverridableProps([...documents.keys()]),
|
|
2428
|
+
loadComponentsStyles(documents)
|
|
2410
2429
|
]);
|
|
2411
2430
|
}
|
|
2412
|
-
|
|
2413
|
-
const
|
|
2414
|
-
(document) => !!document
|
|
2415
|
-
);
|
|
2416
|
-
const isDrafted = components.some(isDocumentDirty);
|
|
2431
|
+
function updateDocumentState(documents) {
|
|
2432
|
+
const isDrafted = [...documents.values()].some(isDocumentDirty);
|
|
2417
2433
|
if (isDrafted) {
|
|
2418
2434
|
setDocumentModifiedStatus5(true);
|
|
2419
2435
|
}
|
|
@@ -5087,9 +5103,8 @@ async function updateComponentsBeforeSave({ status, elements }) {
|
|
|
5087
5103
|
if (status !== "publish") {
|
|
5088
5104
|
return;
|
|
5089
5105
|
}
|
|
5090
|
-
const
|
|
5091
|
-
const
|
|
5092
|
-
const draftIds = componentDocumentData.filter((document) => !!document).filter(isDocumentDirty2).map((document) => document.id);
|
|
5106
|
+
const documents = await getComponentDocuments(elements);
|
|
5107
|
+
const draftIds = [...documents.values()].filter(isDocumentDirty2).map((document) => document.id);
|
|
5093
5108
|
if (draftIds.length === 0) {
|
|
5094
5109
|
return;
|
|
5095
5110
|
}
|