@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.js
CHANGED
|
@@ -2301,31 +2301,48 @@ var archiveComponent = (componentId, componentName) => {
|
|
|
2301
2301
|
// src/store/actions/load-components-assets.ts
|
|
2302
2302
|
var import_editor_documents9 = require("@elementor/editor-documents");
|
|
2303
2303
|
|
|
2304
|
-
// src/utils/get-component-
|
|
2305
|
-
|
|
2306
|
-
const
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
}
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2304
|
+
// src/utils/get-component-documents.ts
|
|
2305
|
+
async function getComponentDocuments(elements, cache = /* @__PURE__ */ new Map()) {
|
|
2306
|
+
const componentIds = await getComponentIds(elements, cache);
|
|
2307
|
+
return getDocumentsMap(componentIds, cache);
|
|
2308
|
+
}
|
|
2309
|
+
async function getComponentIds(elements, cache) {
|
|
2310
|
+
const results = await Promise.all(
|
|
2311
|
+
elements.map(async ({ widgetType, elType, elements: childElements, settings }) => {
|
|
2312
|
+
const ids = [];
|
|
2313
|
+
if (isComponentInstance({ widgetType, elType })) {
|
|
2314
|
+
const componentId = settings?.component_instance?.value?.component_id.value;
|
|
2315
|
+
if (!componentId) {
|
|
2316
|
+
return ids;
|
|
2317
|
+
}
|
|
2317
2318
|
ids.push(componentId);
|
|
2319
|
+
if (!cache.has(componentId)) {
|
|
2320
|
+
cache.set(componentId, getComponentDocumentData(componentId));
|
|
2321
|
+
}
|
|
2322
|
+
const doc = await cache.get(componentId);
|
|
2323
|
+
childElements = doc?.elements;
|
|
2318
2324
|
}
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2325
|
+
if (childElements?.length) {
|
|
2326
|
+
const childIds = await getComponentIds(childElements, cache);
|
|
2327
|
+
ids.push(...childIds);
|
|
2328
|
+
}
|
|
2329
|
+
return ids;
|
|
2330
|
+
})
|
|
2331
|
+
);
|
|
2332
|
+
return [...new Set(results.flat())];
|
|
2333
|
+
}
|
|
2334
|
+
async function getDocumentsMap(ids, cache) {
|
|
2335
|
+
const documents = await Promise.all(
|
|
2336
|
+
ids.map(async (id2) => {
|
|
2337
|
+
const document = await cache.get(id2);
|
|
2338
|
+
if (!document) {
|
|
2339
|
+
return null;
|
|
2340
|
+
}
|
|
2341
|
+
return [id2, document];
|
|
2342
|
+
})
|
|
2343
|
+
);
|
|
2344
|
+
return new Map(documents.filter((document) => document !== null));
|
|
2345
|
+
}
|
|
2329
2346
|
|
|
2330
2347
|
// src/store/actions/load-components-overridable-props.ts
|
|
2331
2348
|
var import_store37 = require("@elementor/store");
|
|
@@ -2354,48 +2371,47 @@ async function loadComponentOverrides(componentId) {
|
|
|
2354
2371
|
|
|
2355
2372
|
// src/store/actions/load-components-styles.ts
|
|
2356
2373
|
var import_store39 = require("@elementor/store");
|
|
2357
|
-
|
|
2358
|
-
if (!
|
|
2374
|
+
function loadComponentsStyles(documents) {
|
|
2375
|
+
if (!documents.size) {
|
|
2359
2376
|
return;
|
|
2360
2377
|
}
|
|
2361
2378
|
const knownComponents = selectStyles((0, import_store39.__getState)());
|
|
2362
|
-
const
|
|
2363
|
-
if (!
|
|
2379
|
+
const unknownDocuments = new Map([...documents.entries()].filter(([id2]) => !knownComponents[id2]));
|
|
2380
|
+
if (!unknownDocuments.size) {
|
|
2364
2381
|
return;
|
|
2365
2382
|
}
|
|
2366
|
-
|
|
2367
|
-
}
|
|
2368
|
-
async function addComponentStyles(ids) {
|
|
2369
|
-
const newComponents = await loadStyles(ids);
|
|
2370
|
-
addStyles(newComponents);
|
|
2371
|
-
}
|
|
2372
|
-
async function loadStyles(ids) {
|
|
2373
|
-
return Promise.all(ids.map(async (id2) => [id2, await apiClient.getComponentConfig(id2)]));
|
|
2383
|
+
addStyles(unknownDocuments);
|
|
2374
2384
|
}
|
|
2375
|
-
function addStyles(
|
|
2385
|
+
function addStyles(documents) {
|
|
2376
2386
|
const styles = Object.fromEntries(
|
|
2377
|
-
|
|
2387
|
+
[...documents.entries()].map(([id2, document]) => [id2, extractStylesFromDocument(document)])
|
|
2378
2388
|
);
|
|
2379
2389
|
(0, import_store39.__dispatch)(slice.actions.addStyles(styles));
|
|
2380
2390
|
}
|
|
2381
|
-
function
|
|
2382
|
-
|
|
2391
|
+
function extractStylesFromDocument(document) {
|
|
2392
|
+
if (!document.elements?.length) {
|
|
2393
|
+
return [];
|
|
2394
|
+
}
|
|
2395
|
+
return document.elements.flatMap(extractStylesFromElement);
|
|
2396
|
+
}
|
|
2397
|
+
function extractStylesFromElement(element) {
|
|
2398
|
+
return [
|
|
2399
|
+
...Object.values(element.styles ?? {}),
|
|
2400
|
+
...(element.elements ?? []).flatMap(extractStylesFromElement)
|
|
2401
|
+
];
|
|
2383
2402
|
}
|
|
2384
2403
|
|
|
2385
2404
|
// src/store/actions/load-components-assets.ts
|
|
2386
2405
|
async function loadComponentsAssets(elements) {
|
|
2387
|
-
const
|
|
2406
|
+
const documents = await getComponentDocuments(elements);
|
|
2388
2407
|
return Promise.all([
|
|
2389
|
-
updateDocumentState(
|
|
2390
|
-
loadComponentsOverridableProps(
|
|
2391
|
-
loadComponentsStyles(
|
|
2408
|
+
updateDocumentState(documents),
|
|
2409
|
+
loadComponentsOverridableProps([...documents.keys()]),
|
|
2410
|
+
loadComponentsStyles(documents)
|
|
2392
2411
|
]);
|
|
2393
2412
|
}
|
|
2394
|
-
|
|
2395
|
-
const
|
|
2396
|
-
(document) => !!document
|
|
2397
|
-
);
|
|
2398
|
-
const isDrafted = components.some(import_editor_documents9.isDocumentDirty);
|
|
2413
|
+
function updateDocumentState(documents) {
|
|
2414
|
+
const isDrafted = [...documents.values()].some(import_editor_documents9.isDocumentDirty);
|
|
2399
2415
|
if (isDrafted) {
|
|
2400
2416
|
(0, import_editor_documents9.setDocumentModifiedStatus)(true);
|
|
2401
2417
|
}
|
|
@@ -5047,9 +5063,8 @@ async function updateComponentsBeforeSave({ status, elements }) {
|
|
|
5047
5063
|
if (status !== "publish") {
|
|
5048
5064
|
return;
|
|
5049
5065
|
}
|
|
5050
|
-
const
|
|
5051
|
-
const
|
|
5052
|
-
const draftIds = componentDocumentData.filter((document) => !!document).filter(import_editor_documents12.isDocumentDirty).map((document) => document.id);
|
|
5066
|
+
const documents = await getComponentDocuments(elements);
|
|
5067
|
+
const draftIds = [...documents.values()].filter(import_editor_documents12.isDocumentDirty).map((document) => document.id);
|
|
5053
5068
|
if (draftIds.length === 0) {
|
|
5054
5069
|
return;
|
|
5055
5070
|
}
|