@elementor/editor-global-classes 4.3.0-991 → 4.3.0-993
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 +124 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +122 -120
- package/dist/index.mjs.map +1 -1
- package/package.json +21 -21
- package/src/components/class-manager/class-manager-panel.tsx +7 -2
package/dist/index.mjs
CHANGED
|
@@ -526,10 +526,119 @@ var useFilters = () => {
|
|
|
526
526
|
}, [filters, allFilters]);
|
|
527
527
|
};
|
|
528
528
|
|
|
529
|
+
// src/load-existing-classes.ts
|
|
530
|
+
import { __dispatch as dispatch2, __getState as getState } from "@elementor/store";
|
|
531
|
+
|
|
532
|
+
// src/load-document-classes.ts
|
|
533
|
+
import { getCurrentDocument } from "@elementor/editor-documents";
|
|
534
|
+
import { __dispatch as dispatch } from "@elementor/store";
|
|
535
|
+
|
|
536
|
+
// src/utils/create-labels-for-classes.ts
|
|
537
|
+
function createLabelsForClasses(entries) {
|
|
538
|
+
return Object.fromEntries(entries.map((e) => [e.id, e.label]));
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// src/load-document-classes.ts
|
|
542
|
+
function styleDefinitionsMapWithoutNull(map) {
|
|
543
|
+
return Object.fromEntries(
|
|
544
|
+
Object.entries(map).filter(
|
|
545
|
+
(entry) => entry[1] !== null
|
|
546
|
+
)
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
function resetGlobalClassesState(globalOrder, classLabels) {
|
|
550
|
+
dispatch(
|
|
551
|
+
slice.actions.load({
|
|
552
|
+
preview: { items: {}, order: globalOrder },
|
|
553
|
+
frontend: { items: {}, order: globalOrder },
|
|
554
|
+
classLabels
|
|
555
|
+
})
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
async function loadCurrentDocumentClasses() {
|
|
559
|
+
const [previewIndexRes, frontendIndexRes] = await Promise.all([
|
|
560
|
+
apiClient.all("preview"),
|
|
561
|
+
apiClient.all("frontend")
|
|
562
|
+
]);
|
|
563
|
+
const previewIndex = previewIndexRes.data.data;
|
|
564
|
+
const frontendIndex = frontendIndexRes.data.data;
|
|
565
|
+
const classLabels = createLabelsForClasses(previewIndex);
|
|
566
|
+
const previewOrder = previewIndex.map((e) => e.id);
|
|
567
|
+
const frontendOrder = frontendIndex.map((e) => e.id);
|
|
568
|
+
resetGlobalClassesState(previewOrder, classLabels);
|
|
569
|
+
const postId = getCurrentDocument()?.id;
|
|
570
|
+
if (!postId) {
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
const [previewPostRes, frontendPostRes] = await Promise.all([
|
|
574
|
+
apiClient.getStylesForPost(postId, "preview"),
|
|
575
|
+
apiClient.getStylesForPost(postId, "frontend")
|
|
576
|
+
]);
|
|
577
|
+
const previewItems = styleDefinitionsMapWithoutNull(previewPostRes.data.data);
|
|
578
|
+
const frontendItems = styleDefinitionsMapWithoutNull(frontendPostRes.data.data);
|
|
579
|
+
dispatch(
|
|
580
|
+
slice.actions.load({
|
|
581
|
+
preview: { items: previewItems, order: previewOrder },
|
|
582
|
+
frontend: { items: frontendItems, order: frontendOrder },
|
|
583
|
+
classLabels
|
|
584
|
+
})
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
async function addDocumentClasses(documentId) {
|
|
588
|
+
const [previewPostRes, frontendPostRes] = await Promise.all([
|
|
589
|
+
apiClient.getStylesForPost(documentId, "preview"),
|
|
590
|
+
apiClient.getStylesForPost(documentId, "frontend")
|
|
591
|
+
]);
|
|
592
|
+
const previewItems = styleDefinitionsMapWithoutNull(previewPostRes.data.data);
|
|
593
|
+
const frontendItems = styleDefinitionsMapWithoutNull(frontendPostRes.data.data);
|
|
594
|
+
dispatch(
|
|
595
|
+
slice.actions.mergeExistingClasses({
|
|
596
|
+
preview: previewItems,
|
|
597
|
+
frontend: frontendItems
|
|
598
|
+
})
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// src/load-existing-classes.ts
|
|
603
|
+
var pendingLoad = null;
|
|
604
|
+
var pendingIds = /* @__PURE__ */ new Set();
|
|
605
|
+
async function loadExistingClasses(classIds) {
|
|
606
|
+
const existingClasses = selectGlobalClasses(getState());
|
|
607
|
+
const missingIds = classIds.filter((id) => !(id in existingClasses));
|
|
608
|
+
if (missingIds.length === 0) {
|
|
609
|
+
return;
|
|
610
|
+
}
|
|
611
|
+
missingIds.forEach((id) => pendingIds.add(id));
|
|
612
|
+
if (pendingLoad) {
|
|
613
|
+
await pendingLoad;
|
|
614
|
+
return loadExistingClasses(classIds);
|
|
615
|
+
}
|
|
616
|
+
pendingLoad = fetchAndMergeClasses();
|
|
617
|
+
try {
|
|
618
|
+
await pendingLoad;
|
|
619
|
+
} finally {
|
|
620
|
+
pendingLoad = null;
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
async function fetchAndMergeClasses() {
|
|
624
|
+
const idsToFetch = Array.from(pendingIds);
|
|
625
|
+
pendingIds.clear();
|
|
626
|
+
if (idsToFetch.length === 0) {
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
const [previewResponse, frontendResponse] = await Promise.all([
|
|
630
|
+
apiClient.getStylesByIds(idsToFetch, "preview"),
|
|
631
|
+
apiClient.getStylesByIds(idsToFetch, "frontend")
|
|
632
|
+
]);
|
|
633
|
+
const previewItems = styleDefinitionsMapWithoutNull(previewResponse.data.data);
|
|
634
|
+
const frontendItems = styleDefinitionsMapWithoutNull(frontendResponse.data.data);
|
|
635
|
+
dispatch2(slice.actions.mergeExistingClasses({ preview: previewItems, frontend: frontendItems }));
|
|
636
|
+
}
|
|
637
|
+
|
|
529
638
|
// src/save-global-classes.tsx
|
|
530
639
|
import * as React3 from "react";
|
|
531
640
|
import { openDialog } from "@elementor/editor-ui";
|
|
532
|
-
import { __dispatch as
|
|
641
|
+
import { __dispatch as dispatch3, __getState as getState3 } from "@elementor/store";
|
|
533
642
|
import { hash } from "@elementor/utils";
|
|
534
643
|
|
|
535
644
|
// src/components/class-manager/duplicate-label-dialog.tsx
|
|
@@ -645,7 +754,7 @@ var DuplicateLabelDialog = ({
|
|
|
645
754
|
|
|
646
755
|
// src/utils/tracking.ts
|
|
647
756
|
import { getMixpanel } from "@elementor/events";
|
|
648
|
-
import { __getState as
|
|
757
|
+
import { __getState as getState2 } from "@elementor/store";
|
|
649
758
|
var trackGlobalClasses = async (payload) => {
|
|
650
759
|
const { runAction } = payload;
|
|
651
760
|
const data = await getSanitizedData(payload);
|
|
@@ -760,7 +869,7 @@ var extractCssClassData = (classId) => {
|
|
|
760
869
|
return { classTitle };
|
|
761
870
|
};
|
|
762
871
|
var getCssClass = (classId) => {
|
|
763
|
-
const state =
|
|
872
|
+
const state = getState2();
|
|
764
873
|
const cssClass = selectClass(state, classId);
|
|
765
874
|
if (cssClass) {
|
|
766
875
|
return cssClass;
|
|
@@ -794,10 +903,10 @@ var getRemovedInfo = (classId) => {
|
|
|
794
903
|
|
|
795
904
|
// src/save-global-classes.tsx
|
|
796
905
|
async function saveGlobalClasses2({ context: context2, onApprove }) {
|
|
797
|
-
const state = selectData(
|
|
906
|
+
const state = selectData(getState3());
|
|
798
907
|
const apiAction = context2 === "preview" ? apiClient.saveDraft : apiClient.publish;
|
|
799
908
|
const currentContext = context2 === "preview" ? selectPreviewInitialData : selectFrontendInitialData;
|
|
800
|
-
const changes = calculateChanges(state, currentContext(
|
|
909
|
+
const changes = calculateChanges(state, currentContext(getState3()));
|
|
801
910
|
const touchedIds = [...changes.added, ...changes.modified];
|
|
802
911
|
const touchedItems = Object.fromEntries(
|
|
803
912
|
touchedIds.map((id) => [id, state.items[id]]).filter(([, v]) => v)
|
|
@@ -807,10 +916,10 @@ async function saveGlobalClasses2({ context: context2, onApprove }) {
|
|
|
807
916
|
order: state.order,
|
|
808
917
|
changes
|
|
809
918
|
});
|
|
810
|
-
|
|
919
|
+
dispatch3(slice.actions.reset({ context: context2 }));
|
|
811
920
|
window.dispatchEvent(new CustomEvent("classes:updated", { detail: { context: context2 } }));
|
|
812
921
|
if (response?.data?.data?.code === API_ERROR_CODES.DUPLICATED_LABEL) {
|
|
813
|
-
|
|
922
|
+
dispatch3(slice.actions.updateMultiple(response.data.data.modifiedLabels));
|
|
814
923
|
trackGlobalClasses({
|
|
815
924
|
event: "classPublishConflict",
|
|
816
925
|
numOfConflicts: Object.keys(response.data.data.modifiedLabels).length
|
|
@@ -1133,14 +1242,14 @@ var IntroductionContent = () => {
|
|
|
1133
1242
|
};
|
|
1134
1243
|
|
|
1135
1244
|
// src/components/class-manager/delete-class.ts
|
|
1136
|
-
import { __dispatch as
|
|
1245
|
+
import { __dispatch as dispatch4 } from "@elementor/store";
|
|
1137
1246
|
var isDeleted = false;
|
|
1138
1247
|
var deleteClass = (id) => {
|
|
1139
1248
|
trackGlobalClasses({
|
|
1140
1249
|
event: "classDeleted",
|
|
1141
1250
|
classId: id,
|
|
1142
1251
|
runAction: () => {
|
|
1143
|
-
|
|
1252
|
+
dispatch4(slice.actions.delete(id));
|
|
1144
1253
|
isDeleted = true;
|
|
1145
1254
|
}
|
|
1146
1255
|
});
|
|
@@ -1169,115 +1278,6 @@ var useOrderedClasses = () => {
|
|
|
1169
1278
|
return useSelector3(selectOrderedClasses);
|
|
1170
1279
|
};
|
|
1171
1280
|
|
|
1172
|
-
// src/load-existing-classes.ts
|
|
1173
|
-
import { __dispatch as dispatch4, __getState as getState3 } from "@elementor/store";
|
|
1174
|
-
|
|
1175
|
-
// src/load-document-classes.ts
|
|
1176
|
-
import { getCurrentDocument } from "@elementor/editor-documents";
|
|
1177
|
-
import { __dispatch as dispatch3 } from "@elementor/store";
|
|
1178
|
-
|
|
1179
|
-
// src/utils/create-labels-for-classes.ts
|
|
1180
|
-
function createLabelsForClasses(entries) {
|
|
1181
|
-
return Object.fromEntries(entries.map((e) => [e.id, e.label]));
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
// src/load-document-classes.ts
|
|
1185
|
-
function styleDefinitionsMapWithoutNull(map) {
|
|
1186
|
-
return Object.fromEntries(
|
|
1187
|
-
Object.entries(map).filter(
|
|
1188
|
-
(entry) => entry[1] !== null
|
|
1189
|
-
)
|
|
1190
|
-
);
|
|
1191
|
-
}
|
|
1192
|
-
function resetGlobalClassesState(globalOrder, classLabels) {
|
|
1193
|
-
dispatch3(
|
|
1194
|
-
slice.actions.load({
|
|
1195
|
-
preview: { items: {}, order: globalOrder },
|
|
1196
|
-
frontend: { items: {}, order: globalOrder },
|
|
1197
|
-
classLabels
|
|
1198
|
-
})
|
|
1199
|
-
);
|
|
1200
|
-
}
|
|
1201
|
-
async function loadCurrentDocumentClasses() {
|
|
1202
|
-
const [previewIndexRes, frontendIndexRes] = await Promise.all([
|
|
1203
|
-
apiClient.all("preview"),
|
|
1204
|
-
apiClient.all("frontend")
|
|
1205
|
-
]);
|
|
1206
|
-
const previewIndex = previewIndexRes.data.data;
|
|
1207
|
-
const frontendIndex = frontendIndexRes.data.data;
|
|
1208
|
-
const classLabels = createLabelsForClasses(previewIndex);
|
|
1209
|
-
const previewOrder = previewIndex.map((e) => e.id);
|
|
1210
|
-
const frontendOrder = frontendIndex.map((e) => e.id);
|
|
1211
|
-
resetGlobalClassesState(previewOrder, classLabels);
|
|
1212
|
-
const postId = getCurrentDocument()?.id;
|
|
1213
|
-
if (!postId) {
|
|
1214
|
-
return;
|
|
1215
|
-
}
|
|
1216
|
-
const [previewPostRes, frontendPostRes] = await Promise.all([
|
|
1217
|
-
apiClient.getStylesForPost(postId, "preview"),
|
|
1218
|
-
apiClient.getStylesForPost(postId, "frontend")
|
|
1219
|
-
]);
|
|
1220
|
-
const previewItems = styleDefinitionsMapWithoutNull(previewPostRes.data.data);
|
|
1221
|
-
const frontendItems = styleDefinitionsMapWithoutNull(frontendPostRes.data.data);
|
|
1222
|
-
dispatch3(
|
|
1223
|
-
slice.actions.load({
|
|
1224
|
-
preview: { items: previewItems, order: previewOrder },
|
|
1225
|
-
frontend: { items: frontendItems, order: frontendOrder },
|
|
1226
|
-
classLabels
|
|
1227
|
-
})
|
|
1228
|
-
);
|
|
1229
|
-
}
|
|
1230
|
-
async function addDocumentClasses(documentId) {
|
|
1231
|
-
const [previewPostRes, frontendPostRes] = await Promise.all([
|
|
1232
|
-
apiClient.getStylesForPost(documentId, "preview"),
|
|
1233
|
-
apiClient.getStylesForPost(documentId, "frontend")
|
|
1234
|
-
]);
|
|
1235
|
-
const previewItems = styleDefinitionsMapWithoutNull(previewPostRes.data.data);
|
|
1236
|
-
const frontendItems = styleDefinitionsMapWithoutNull(frontendPostRes.data.data);
|
|
1237
|
-
dispatch3(
|
|
1238
|
-
slice.actions.mergeExistingClasses({
|
|
1239
|
-
preview: previewItems,
|
|
1240
|
-
frontend: frontendItems
|
|
1241
|
-
})
|
|
1242
|
-
);
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
// src/load-existing-classes.ts
|
|
1246
|
-
var pendingLoad = null;
|
|
1247
|
-
var pendingIds = /* @__PURE__ */ new Set();
|
|
1248
|
-
async function loadExistingClasses(classIds) {
|
|
1249
|
-
const existingClasses = selectGlobalClasses(getState3());
|
|
1250
|
-
const missingIds = classIds.filter((id) => !(id in existingClasses));
|
|
1251
|
-
if (missingIds.length === 0) {
|
|
1252
|
-
return;
|
|
1253
|
-
}
|
|
1254
|
-
missingIds.forEach((id) => pendingIds.add(id));
|
|
1255
|
-
if (pendingLoad) {
|
|
1256
|
-
await pendingLoad;
|
|
1257
|
-
return loadExistingClasses(classIds);
|
|
1258
|
-
}
|
|
1259
|
-
pendingLoad = fetchAndMergeClasses();
|
|
1260
|
-
try {
|
|
1261
|
-
await pendingLoad;
|
|
1262
|
-
} finally {
|
|
1263
|
-
pendingLoad = null;
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
async function fetchAndMergeClasses() {
|
|
1267
|
-
const idsToFetch = Array.from(pendingIds);
|
|
1268
|
-
pendingIds.clear();
|
|
1269
|
-
if (idsToFetch.length === 0) {
|
|
1270
|
-
return;
|
|
1271
|
-
}
|
|
1272
|
-
const [previewResponse, frontendResponse] = await Promise.all([
|
|
1273
|
-
apiClient.getStylesByIds(idsToFetch, "preview"),
|
|
1274
|
-
apiClient.getStylesByIds(idsToFetch, "frontend")
|
|
1275
|
-
]);
|
|
1276
|
-
const previewItems = styleDefinitionsMapWithoutNull(previewResponse.data.data);
|
|
1277
|
-
const frontendItems = styleDefinitionsMapWithoutNull(frontendResponse.data.data);
|
|
1278
|
-
dispatch4(slice.actions.mergeExistingClasses({ preview: previewItems, frontend: frontendItems }));
|
|
1279
|
-
}
|
|
1280
|
-
|
|
1281
1281
|
// src/components/class-manager/class-item.tsx
|
|
1282
1282
|
import * as React15 from "react";
|
|
1283
1283
|
import { useRef, useState as useState4 } from "react";
|
|
@@ -2317,7 +2317,8 @@ function ClassManagerPanelContent({
|
|
|
2317
2317
|
unblockPanelInteractions();
|
|
2318
2318
|
};
|
|
2319
2319
|
}, []);
|
|
2320
|
-
const handleStopSync = useCallback((classId) => {
|
|
2320
|
+
const handleStopSync = useCallback(async (classId) => {
|
|
2321
|
+
await loadExistingClasses([classId]);
|
|
2321
2322
|
dispatch5(
|
|
2322
2323
|
slice.actions.update({
|
|
2323
2324
|
style: {
|
|
@@ -2329,7 +2330,8 @@ function ClassManagerPanelContent({
|
|
|
2329
2330
|
trackGlobalClasses({ event: "classSyncToV3", classId, action: "unsync" });
|
|
2330
2331
|
setStopSyncConfirmation(null);
|
|
2331
2332
|
}, []);
|
|
2332
|
-
const handleStartSync = useCallback((classId) => {
|
|
2333
|
+
const handleStartSync = useCallback(async (classId) => {
|
|
2334
|
+
await loadExistingClasses([classId]);
|
|
2333
2335
|
dispatch5(
|
|
2334
2336
|
slice.actions.update({
|
|
2335
2337
|
style: {
|