@elementor/editor-components 4.3.0-998 → 4.4.0-1064
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 +110 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +23 -23
- package/src/create-component-type.ts +6 -1
- package/src/utils/component-document-data.ts +25 -8
- package/src/utils/reconcile-component-instance-elements.ts +107 -0
package/dist/index.js
CHANGED
|
@@ -91,11 +91,11 @@ module.exports = __toCommonJS(index_exports);
|
|
|
91
91
|
// src/init.ts
|
|
92
92
|
var import_editor = require("@elementor/editor");
|
|
93
93
|
var import_editor_canvas6 = require("@elementor/editor-canvas");
|
|
94
|
-
var
|
|
94
|
+
var import_editor_documents5 = require("@elementor/editor-documents");
|
|
95
95
|
var import_editor_editing_panel7 = require("@elementor/editor-editing-panel");
|
|
96
96
|
var import_editor_elements_panel = require("@elementor/editor-elements-panel");
|
|
97
97
|
var import_editor_embedded_documents_manager2 = require("@elementor/editor-embedded-documents-manager");
|
|
98
|
-
var
|
|
98
|
+
var import_editor_v1_adapters7 = require("@elementor/editor-v1-adapters");
|
|
99
99
|
var import_store28 = require("@elementor/store");
|
|
100
100
|
var import_i18n16 = require("@wordpress/i18n");
|
|
101
101
|
|
|
@@ -417,14 +417,21 @@ var useIsSanitizedComponent = (componentId, key) => {
|
|
|
417
417
|
};
|
|
418
418
|
|
|
419
419
|
// src/utils/component-document-data.ts
|
|
420
|
-
var
|
|
421
|
-
var
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
420
|
+
var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
|
|
421
|
+
var getComponentDocumentParams = (id) => ({
|
|
422
|
+
action: "get_document_config",
|
|
423
|
+
unique_id: `document-${id}`,
|
|
424
|
+
data: { id }
|
|
425
|
+
});
|
|
426
|
+
var pendingRequests = /* @__PURE__ */ new Map();
|
|
427
|
+
var getComponentDocumentData = (id) => {
|
|
428
|
+
const pendingRequest = pendingRequests.get(id);
|
|
429
|
+
if (pendingRequest) {
|
|
430
|
+
return pendingRequest;
|
|
431
|
+
}
|
|
432
|
+
const request = import_editor_v1_adapters2.ajax.load(getComponentDocumentParams(id)).catch(() => null).finally(() => pendingRequests.delete(id));
|
|
433
|
+
pendingRequests.set(id, request);
|
|
434
|
+
return request;
|
|
428
435
|
};
|
|
429
436
|
|
|
430
437
|
// src/component-instance-transformer.ts
|
|
@@ -1126,7 +1133,7 @@ var import_i18n10 = require("@wordpress/i18n");
|
|
|
1126
1133
|
// src/utils/detach-component-instance/detach-component-instance.ts
|
|
1127
1134
|
var import_editor_canvas4 = require("@elementor/editor-canvas");
|
|
1128
1135
|
var import_editor_elements3 = require("@elementor/editor-elements");
|
|
1129
|
-
var
|
|
1136
|
+
var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
|
|
1130
1137
|
var import_store10 = require("@elementor/store");
|
|
1131
1138
|
var import_i18n9 = require("@wordpress/i18n");
|
|
1132
1139
|
|
|
@@ -1406,7 +1413,7 @@ async function detachComponentInstance({
|
|
|
1406
1413
|
if (!rootElement) {
|
|
1407
1414
|
throw new Error(`Component with ID "${componentId}" has no root element.`);
|
|
1408
1415
|
}
|
|
1409
|
-
const undoableDetach = (0,
|
|
1416
|
+
const undoableDetach = (0, import_editor_v1_adapters3.undoable)(
|
|
1410
1417
|
{
|
|
1411
1418
|
do: () => {
|
|
1412
1419
|
const overrides = extractInstanceOverrides(instanceContainer);
|
|
@@ -2548,7 +2555,7 @@ var import_react10 = require("react");
|
|
|
2548
2555
|
var import_editor_templates = require("@elementor/editor-templates");
|
|
2549
2556
|
|
|
2550
2557
|
// src/store/actions/load-components-assets.ts
|
|
2551
|
-
var
|
|
2558
|
+
var import_editor_documents = require("@elementor/editor-documents");
|
|
2552
2559
|
var import_editor_embedded_documents_manager = require("@elementor/editor-embedded-documents-manager");
|
|
2553
2560
|
|
|
2554
2561
|
// src/utils/get-component-documents.ts
|
|
@@ -2624,9 +2631,9 @@ async function loadComponentsAssets(elements) {
|
|
|
2624
2631
|
await loadComponentsOverridableProps([...documents.keys()]);
|
|
2625
2632
|
}
|
|
2626
2633
|
function updateDocumentState(documents) {
|
|
2627
|
-
const isDrafted = [...documents.values()].some(
|
|
2634
|
+
const isDrafted = [...documents.values()].some(import_editor_documents.isDocumentDirty);
|
|
2628
2635
|
if (isDrafted) {
|
|
2629
|
-
(0,
|
|
2636
|
+
(0, import_editor_documents.setDocumentModifiedStatus)(true);
|
|
2630
2637
|
}
|
|
2631
2638
|
}
|
|
2632
2639
|
|
|
@@ -2647,10 +2654,10 @@ function LoadTemplateComponentsInternal() {
|
|
|
2647
2654
|
|
|
2648
2655
|
// src/create-component-type.ts
|
|
2649
2656
|
var import_editor_canvas5 = require("@elementor/editor-canvas");
|
|
2650
|
-
var
|
|
2657
|
+
var import_editor_documents3 = require("@elementor/editor-documents");
|
|
2651
2658
|
var import_editor_notifications2 = require("@elementor/editor-notifications");
|
|
2652
2659
|
var import_store23 = require("@elementor/store");
|
|
2653
|
-
var
|
|
2660
|
+
var import_utils6 = require("@elementor/utils");
|
|
2654
2661
|
var import_i18n13 = require("@wordpress/i18n");
|
|
2655
2662
|
|
|
2656
2663
|
// src/utils/format-component-elements-id.ts
|
|
@@ -2669,29 +2676,85 @@ function formatComponentElementsId(elements, path) {
|
|
|
2669
2676
|
});
|
|
2670
2677
|
}
|
|
2671
2678
|
|
|
2672
|
-
// src/utils/
|
|
2673
|
-
var import_editor_documents3 = require("@elementor/editor-documents");
|
|
2679
|
+
// src/utils/reconcile-component-instance-elements.ts
|
|
2674
2680
|
var import_editor_elements8 = require("@elementor/editor-elements");
|
|
2675
|
-
var
|
|
2681
|
+
var import_utils5 = require("@elementor/utils");
|
|
2682
|
+
var ELEMENT_ID_LENGTH2 = 7;
|
|
2683
|
+
function overridesRecordToMapping(overrides) {
|
|
2684
|
+
const mapping = {};
|
|
2685
|
+
for (const [key, value] of Object.entries(overrides)) {
|
|
2686
|
+
mapping[key] = { value };
|
|
2687
|
+
}
|
|
2688
|
+
return mapping;
|
|
2689
|
+
}
|
|
2690
|
+
function getElementConfig(element) {
|
|
2691
|
+
const type = element.elType === "widget" ? element.widgetType : element.elType;
|
|
2692
|
+
if (!type) {
|
|
2693
|
+
return void 0;
|
|
2694
|
+
}
|
|
2695
|
+
return (0, import_editor_elements8.getWidgetsCache)()?.[type];
|
|
2696
|
+
}
|
|
2697
|
+
function deriveIds(element, seed) {
|
|
2698
|
+
const id = (0, import_utils5.hashString)(seed, ELEMENT_ID_LENGTH2);
|
|
2699
|
+
return {
|
|
2700
|
+
...element,
|
|
2701
|
+
id,
|
|
2702
|
+
elements: (element.elements ?? []).map((child, index) => deriveIds(child, `${id}_${index}`))
|
|
2703
|
+
};
|
|
2704
|
+
}
|
|
2705
|
+
function reconcileElementTree(element, overridesMapping) {
|
|
2706
|
+
const elementConfig = getElementConfig(element);
|
|
2707
|
+
const withOverrides = applyOverridesToSettings(element.settings ?? {}, overridesMapping);
|
|
2708
|
+
const effectiveSettings = unwrapOverridableSettings(withOverrides);
|
|
2709
|
+
const originalChildren = element.elements ?? [];
|
|
2710
|
+
const originalChildIds = new Set(originalChildren.map((child) => child.id));
|
|
2711
|
+
const attributes = {
|
|
2712
|
+
elements: [...originalChildren],
|
|
2713
|
+
settings: effectiveSettings
|
|
2714
|
+
};
|
|
2715
|
+
if (elementConfig?.children_dependencies?.length) {
|
|
2716
|
+
(0, import_editor_elements8.reconcileInitialChildren)({
|
|
2717
|
+
elementId: element.id,
|
|
2718
|
+
elementConfig,
|
|
2719
|
+
attributes
|
|
2720
|
+
});
|
|
2721
|
+
}
|
|
2722
|
+
const reconciledChildren = (attributes.elements ?? []).map(
|
|
2723
|
+
(child) => originalChildIds.has(child.id) ? child : deriveIds(child, `${element.id}_${child.elType}`)
|
|
2724
|
+
).map((child) => reconcileElementTree(child, overridesMapping));
|
|
2725
|
+
return {
|
|
2726
|
+
...element,
|
|
2727
|
+
elements: reconciledChildren
|
|
2728
|
+
};
|
|
2729
|
+
}
|
|
2730
|
+
function reconcileComponentInstanceElements(elements, overrides = {}) {
|
|
2731
|
+
const overridesMapping = overridesRecordToMapping(overrides);
|
|
2732
|
+
return elements.map((element) => reconcileElementTree(element, overridesMapping));
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
// src/utils/switch-to-component.ts
|
|
2736
|
+
var import_editor_documents2 = require("@elementor/editor-documents");
|
|
2737
|
+
var import_editor_elements9 = require("@elementor/editor-elements");
|
|
2738
|
+
var import_editor_v1_adapters4 = require("@elementor/editor-v1-adapters");
|
|
2676
2739
|
async function switchToComponent(componentId, componentInstanceId, element) {
|
|
2677
2740
|
const selector = getSelector(element, componentInstanceId);
|
|
2678
|
-
(0,
|
|
2679
|
-
await (0,
|
|
2741
|
+
(0, import_editor_documents2.invalidateDocumentData)(componentId);
|
|
2742
|
+
await (0, import_editor_documents2.switchToDocument)(componentId, {
|
|
2680
2743
|
selector,
|
|
2681
2744
|
mode: "autosave",
|
|
2682
2745
|
setAsInitial: false,
|
|
2683
2746
|
shouldScroll: false
|
|
2684
2747
|
});
|
|
2685
2748
|
await loadComponentsOverridableProps([componentId], { force: true });
|
|
2686
|
-
const currentDocumentContainer = (0,
|
|
2749
|
+
const currentDocumentContainer = (0, import_editor_elements9.getCurrentDocumentContainer)();
|
|
2687
2750
|
const topLevelElement = currentDocumentContainer?.children?.[0];
|
|
2688
2751
|
if (topLevelElement) {
|
|
2689
|
-
(0,
|
|
2752
|
+
(0, import_editor_elements9.selectElement)(topLevelElement.id);
|
|
2690
2753
|
expandNavigator();
|
|
2691
2754
|
}
|
|
2692
2755
|
}
|
|
2693
2756
|
async function expandNavigator() {
|
|
2694
|
-
await (0,
|
|
2757
|
+
await (0, import_editor_v1_adapters4.__privateRunCommand)("navigator/expand-all");
|
|
2695
2758
|
}
|
|
2696
2759
|
function getSelector(element, componentInstanceId) {
|
|
2697
2760
|
if (element) {
|
|
@@ -2802,7 +2865,7 @@ function createComponentView(options) {
|
|
|
2802
2865
|
eventsManagerConfig = legacyWindow.elementorCommon.eventsManager.config;
|
|
2803
2866
|
#componentRenderContext;
|
|
2804
2867
|
isComponentCurrentlyEdited() {
|
|
2805
|
-
const currentDocument = (0,
|
|
2868
|
+
const currentDocument = (0, import_editor_documents3.getCurrentDocument)();
|
|
2806
2869
|
return currentDocument?.id === this.getComponentId();
|
|
2807
2870
|
}
|
|
2808
2871
|
getRenderContext() {
|
|
@@ -2845,7 +2908,11 @@ function createComponentView(options) {
|
|
|
2845
2908
|
};
|
|
2846
2909
|
const instanceId = this.model.get("id");
|
|
2847
2910
|
const elements = componentInstance.elements ?? [];
|
|
2848
|
-
const
|
|
2911
|
+
const reconciledElements = reconcileComponentInstanceElements(
|
|
2912
|
+
elements,
|
|
2913
|
+
componentInstance.overrides ?? {}
|
|
2914
|
+
);
|
|
2915
|
+
const formattedElements = formatComponentElementsId(reconciledElements, [instanceId]);
|
|
2849
2916
|
this.collection = legacyWindow.elementor.createBackboneElementsCollection(formattedElements);
|
|
2850
2917
|
this.collection.models.forEach(setInactiveRecursively);
|
|
2851
2918
|
settings.component_instance = "<template data-children-placeholder></template>";
|
|
@@ -2881,7 +2948,7 @@ function createComponentView(options) {
|
|
|
2881
2948
|
}
|
|
2882
2949
|
_getContextMenuConfig() {
|
|
2883
2950
|
const isAdministrator = isUserAdministrator();
|
|
2884
|
-
const hasPro = (0,
|
|
2951
|
+
const hasPro = (0, import_utils6.hasProInstalled)();
|
|
2885
2952
|
const isOutdated = isProOutdatedForComponents();
|
|
2886
2953
|
const showPromoBadge = !hasPro && !isOutdated;
|
|
2887
2954
|
const badgeClass = "elementor-context-menu-list__item__shortcut__promotion-badge";
|
|
@@ -2975,7 +3042,7 @@ function createComponentView(options) {
|
|
|
2975
3042
|
notifyComponentEditUpdate();
|
|
2976
3043
|
return;
|
|
2977
3044
|
}
|
|
2978
|
-
if (!(0,
|
|
3045
|
+
if (!(0, import_utils6.hasProInstalled)()) {
|
|
2979
3046
|
notifyComponentEditUpgrade();
|
|
2980
3047
|
return;
|
|
2981
3048
|
}
|
|
@@ -3072,9 +3139,9 @@ function PopulateStore() {
|
|
|
3072
3139
|
}
|
|
3073
3140
|
|
|
3074
3141
|
// src/prevent-circular-nesting.ts
|
|
3075
|
-
var
|
|
3142
|
+
var import_editor_elements10 = require("@elementor/editor-elements");
|
|
3076
3143
|
var import_editor_notifications3 = require("@elementor/editor-notifications");
|
|
3077
|
-
var
|
|
3144
|
+
var import_editor_v1_adapters5 = require("@elementor/editor-v1-adapters");
|
|
3078
3145
|
var import_store26 = require("@elementor/store");
|
|
3079
3146
|
var import_i18n14 = require("@wordpress/i18n");
|
|
3080
3147
|
var COMPONENT_TYPE = "e-component";
|
|
@@ -3084,15 +3151,15 @@ var COMPONENT_CIRCULAR_NESTING_ALERT = {
|
|
|
3084
3151
|
id: "circular-component-nesting-blocked"
|
|
3085
3152
|
};
|
|
3086
3153
|
function initCircularNestingPrevention() {
|
|
3087
|
-
(0,
|
|
3154
|
+
(0, import_editor_v1_adapters5.blockCommand)({
|
|
3088
3155
|
command: "document/elements/create",
|
|
3089
3156
|
condition: blockCircularCreate
|
|
3090
3157
|
});
|
|
3091
|
-
(0,
|
|
3158
|
+
(0, import_editor_v1_adapters5.blockCommand)({
|
|
3092
3159
|
command: "document/elements/move",
|
|
3093
3160
|
condition: blockCircularMove
|
|
3094
3161
|
});
|
|
3095
|
-
(0,
|
|
3162
|
+
(0, import_editor_v1_adapters5.blockCommand)({
|
|
3096
3163
|
command: "document/elements/paste",
|
|
3097
3164
|
condition: blockCircularPaste
|
|
3098
3165
|
});
|
|
@@ -3167,7 +3234,7 @@ function blockCircularMove(args) {
|
|
|
3167
3234
|
if (!container) {
|
|
3168
3235
|
return false;
|
|
3169
3236
|
}
|
|
3170
|
-
const allElements = (0,
|
|
3237
|
+
const allElements = (0, import_editor_elements10.getAllDescendants)(container);
|
|
3171
3238
|
return allElements.some((element) => {
|
|
3172
3239
|
const componentId = extractComponentIdFromContainer(element);
|
|
3173
3240
|
if (componentId === null) {
|
|
@@ -3204,7 +3271,7 @@ function removeComponentStyles(id) {
|
|
|
3204
3271
|
}
|
|
3205
3272
|
|
|
3206
3273
|
// src/sync/publish-draft-components-in-page-before-save.ts
|
|
3207
|
-
var
|
|
3274
|
+
var import_editor_documents4 = require("@elementor/editor-documents");
|
|
3208
3275
|
var import_editor_notifications4 = require("@elementor/editor-notifications");
|
|
3209
3276
|
var import_http_client2 = require("@elementor/http-client");
|
|
3210
3277
|
var import_i18n15 = require("@wordpress/i18n");
|
|
@@ -3216,7 +3283,7 @@ async function publishDraftComponentsInPageBeforeSave({ status, elements }) {
|
|
|
3216
3283
|
return;
|
|
3217
3284
|
}
|
|
3218
3285
|
const documents = await getComponentDocuments({ elements });
|
|
3219
|
-
const draftIds = [...documents.values()].filter(
|
|
3286
|
+
const draftIds = [...documents.values()].filter(import_editor_documents4.isDocumentDirty).map((document2) => document2.id);
|
|
3220
3287
|
if (draftIds.length === 0) {
|
|
3221
3288
|
return;
|
|
3222
3289
|
}
|
|
@@ -3229,7 +3296,7 @@ async function publishDraftComponentsInPageBeforeSave({ status, elements }) {
|
|
|
3229
3296
|
}
|
|
3230
3297
|
throw error;
|
|
3231
3298
|
}
|
|
3232
|
-
draftIds.forEach((id) => (0,
|
|
3299
|
+
draftIds.forEach((id) => (0, import_editor_documents4.invalidateDocumentData)(id));
|
|
3233
3300
|
}
|
|
3234
3301
|
function isInsufficientPermissionsError(error) {
|
|
3235
3302
|
return error instanceof import_http_client2.AxiosError && error.response?.data?.code === INSUFFICIENT_PERMISSIONS_ERROR_CODE;
|
|
@@ -3262,12 +3329,12 @@ var beforeSave = ({ container, status }) => {
|
|
|
3262
3329
|
};
|
|
3263
3330
|
|
|
3264
3331
|
// src/sync/load-component-data-after-instance-added.ts
|
|
3265
|
-
var
|
|
3332
|
+
var import_editor_v1_adapters6 = require("@elementor/editor-v1-adapters");
|
|
3266
3333
|
function initLoadComponentDataAfterInstanceAdded() {
|
|
3267
|
-
(0,
|
|
3334
|
+
(0, import_editor_v1_adapters6.registerDataHook)("after", "document/elements/paste", (_args, result) => {
|
|
3268
3335
|
load(result);
|
|
3269
3336
|
});
|
|
3270
|
-
(0,
|
|
3337
|
+
(0, import_editor_v1_adapters6.registerDataHook)("after", "document/elements/import", (_args, result) => {
|
|
3271
3338
|
load(result);
|
|
3272
3339
|
});
|
|
3273
3340
|
}
|
|
@@ -3302,8 +3369,8 @@ function init() {
|
|
|
3302
3369
|
id: "components-populate-store",
|
|
3303
3370
|
component: PopulateStore
|
|
3304
3371
|
});
|
|
3305
|
-
(0,
|
|
3306
|
-
const { id, config } = (0,
|
|
3372
|
+
(0, import_editor_v1_adapters7.registerDataHook)("after", "editor/documents/attach-preview", () => {
|
|
3373
|
+
const { id, config } = (0, import_editor_documents5.getV1CurrentDocument)() ?? {};
|
|
3307
3374
|
if (!id) {
|
|
3308
3375
|
return;
|
|
3309
3376
|
}
|