@elementor/editor-elements 4.5.0-1173 → 4.5.0-1175
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.d.mts +16 -1
- package/dist/index.d.ts +16 -1
- package/dist/index.js +72 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
- package/src/index.ts +2 -0
- package/src/sync/get-element-widget-markers.ts +33 -0
- package/src/sync/regenerate-local-style-ids.ts +55 -0
- package/src/sync/types.ts +8 -0
package/dist/index.mjs
CHANGED
|
@@ -888,6 +888,66 @@ var getElementStyles = (elementID) => {
|
|
|
888
888
|
return container?.model.get("styles") || null;
|
|
889
889
|
};
|
|
890
890
|
|
|
891
|
+
// src/sync/get-element-widget-markers.ts
|
|
892
|
+
import { z } from "@elementor/schema";
|
|
893
|
+
var WIDGET_ID_PATTERN = /^[a-z0-9-]+\/[a-z0-9-]+$/;
|
|
894
|
+
var PART_PATTERN = /^[a-z][a-z0-9_]*$/;
|
|
895
|
+
var MIN_VERSION = 1;
|
|
896
|
+
var widgetMarkerSchema = z.object({
|
|
897
|
+
id: z.string().regex(WIDGET_ID_PATTERN),
|
|
898
|
+
version: z.number().int().min(MIN_VERSION),
|
|
899
|
+
values: z.record(z.unknown()).optional()
|
|
900
|
+
});
|
|
901
|
+
var partSchema = z.string().regex(PART_PATTERN);
|
|
902
|
+
function getElementWidgetMarker(elementId) {
|
|
903
|
+
const result = widgetMarkerSchema.safeParse(getContainer(elementId)?.model.get("widget"));
|
|
904
|
+
if (!result.success) {
|
|
905
|
+
return null;
|
|
906
|
+
}
|
|
907
|
+
return { ...result.data, values: result.data.values ?? {} };
|
|
908
|
+
}
|
|
909
|
+
function getElementPart(elementId) {
|
|
910
|
+
const result = partSchema.safeParse(getContainer(elementId)?.model.get("part"));
|
|
911
|
+
return result.success ? result.data : null;
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// src/sync/regenerate-local-style-ids.ts
|
|
915
|
+
import { classesPropTypeUtil } from "@elementor/editor-props";
|
|
916
|
+
function regenerateLocalStyleIds(element) {
|
|
917
|
+
const originalStyles = element.styles;
|
|
918
|
+
if (!originalStyles || Object.keys(originalStyles).length === 0) {
|
|
919
|
+
return { styles: void 0, settings: void 0 };
|
|
920
|
+
}
|
|
921
|
+
const newStyles = {};
|
|
922
|
+
const styleIdMapping = {};
|
|
923
|
+
for (const [originalStyleId, style] of Object.entries(originalStyles)) {
|
|
924
|
+
const newStyleId = generateLocalStyleId(element.id);
|
|
925
|
+
newStyles[newStyleId] = { ...style, id: newStyleId };
|
|
926
|
+
styleIdMapping[originalStyleId] = newStyleId;
|
|
927
|
+
}
|
|
928
|
+
const settings = element.settings;
|
|
929
|
+
if (!settings || Object.keys(settings).length === 0) {
|
|
930
|
+
return { styles: newStyles, settings: void 0 };
|
|
931
|
+
}
|
|
932
|
+
const updatedSettings = { ...settings };
|
|
933
|
+
for (const [propKey, propValue] of Object.entries(updatedSettings)) {
|
|
934
|
+
if (isClassesProp(propValue) && propValue.value.length > 0) {
|
|
935
|
+
const updatedClasses = propValue.value.map((classId) => styleIdMapping[classId] ?? classId);
|
|
936
|
+
updatedSettings[propKey] = classesPropTypeUtil.create(updatedClasses);
|
|
937
|
+
}
|
|
938
|
+
}
|
|
939
|
+
return {
|
|
940
|
+
styles: newStyles,
|
|
941
|
+
settings: updatedSettings
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
function isClassesProp(prop) {
|
|
945
|
+
return classesPropTypeUtil.isValid(prop);
|
|
946
|
+
}
|
|
947
|
+
function generateLocalStyleId(elementId) {
|
|
948
|
+
return `e-${elementId}-${generateElementId()}`;
|
|
949
|
+
}
|
|
950
|
+
|
|
891
951
|
// src/sync/get-all-descendants.ts
|
|
892
952
|
function getAllDescendants(container) {
|
|
893
953
|
const children = (container.children ?? []).flatMap((child) => getAllDescendants(child));
|
|
@@ -1346,13 +1406,13 @@ var styleRerenderEvents = [
|
|
|
1346
1406
|
];
|
|
1347
1407
|
|
|
1348
1408
|
// src/styles/create-element-style.ts
|
|
1349
|
-
import { classesPropTypeUtil as
|
|
1409
|
+
import { classesPropTypeUtil as classesPropTypeUtil3 } from "@elementor/editor-props";
|
|
1350
1410
|
import {
|
|
1351
1411
|
generateId
|
|
1352
1412
|
} from "@elementor/editor-styles";
|
|
1353
1413
|
|
|
1354
1414
|
// src/styles/mutate-element-styles.ts
|
|
1355
|
-
import { classesPropTypeUtil } from "@elementor/editor-props";
|
|
1415
|
+
import { classesPropTypeUtil as classesPropTypeUtil2 } from "@elementor/editor-props";
|
|
1356
1416
|
import { __privateRunCommandSync as runCommandSync7 } from "@elementor/editor-v1-adapters";
|
|
1357
1417
|
function mutateElementStyles(elementId, mutator) {
|
|
1358
1418
|
const container = getContainer(elementId);
|
|
@@ -1407,7 +1467,7 @@ function clearRemovedClasses(container, { oldIds, newIds }) {
|
|
|
1407
1467
|
function getClassesProps(container) {
|
|
1408
1468
|
return Object.entries(container.settings.toJSON()).filter((prop) => {
|
|
1409
1469
|
const [, value] = prop;
|
|
1410
|
-
return
|
|
1470
|
+
return classesPropTypeUtil2.isValid(value);
|
|
1411
1471
|
});
|
|
1412
1472
|
}
|
|
1413
1473
|
function notifyChanges() {
|
|
@@ -1446,7 +1506,7 @@ function createElementStyle({
|
|
|
1446
1506
|
}
|
|
1447
1507
|
function addStyleToClassesProp(elementId, classesProp, styleId) {
|
|
1448
1508
|
const base = getElementSetting(elementId, classesProp);
|
|
1449
|
-
const classesPropValue =
|
|
1509
|
+
const classesPropValue = classesPropTypeUtil3.create(
|
|
1450
1510
|
(prev) => {
|
|
1451
1511
|
return [...prev ?? [], styleId];
|
|
1452
1512
|
},
|
|
@@ -1595,11 +1655,13 @@ export {
|
|
|
1595
1655
|
getElementIcon,
|
|
1596
1656
|
getElementInteractions,
|
|
1597
1657
|
getElementLabel,
|
|
1658
|
+
getElementPart,
|
|
1598
1659
|
getElementSetting,
|
|
1599
1660
|
getElementSettings,
|
|
1600
1661
|
getElementStyles,
|
|
1601
1662
|
getElementTitle,
|
|
1602
1663
|
getElementType,
|
|
1664
|
+
getElementWidgetMarker,
|
|
1603
1665
|
getElements,
|
|
1604
1666
|
getHostDocumentElements,
|
|
1605
1667
|
getHostDocumentId,
|
|
@@ -1613,6 +1675,7 @@ export {
|
|
|
1613
1675
|
parseDefaultStyleTagFromClassList,
|
|
1614
1676
|
playElementInteractions,
|
|
1615
1677
|
reconcileInitialChildren,
|
|
1678
|
+
regenerateLocalStyleIds,
|
|
1616
1679
|
removeElements,
|
|
1617
1680
|
removeModelFromParent,
|
|
1618
1681
|
replaceElement,
|