@elementor/editor-global-classes 4.1.0-830 → 4.1.0-832
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 +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +279 -127
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +260 -111
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -20
- package/src/api.ts +32 -15
- package/src/components/global-styles-import-listener.tsx +8 -33
- package/src/components/populate-store.tsx +10 -24
- package/src/global-classes-styles-provider.ts +38 -12
- package/src/index.ts +5 -0
- package/src/load-document-classes.ts +76 -0
- package/src/load-existing-classes.ts +49 -0
- package/src/mcp-integration/classes-resource.ts +3 -1
- package/src/save-global-classes.tsx +17 -2
- package/src/store.ts +63 -4
- package/src/utils/create-labels-for-classes.ts +7 -0
- package/src/utils/tracking.ts +14 -6
package/dist/index.mjs
CHANGED
|
@@ -120,6 +120,7 @@ var SnapshotHistory = class _SnapshotHistory {
|
|
|
120
120
|
var localHistory = SnapshotHistory.get("global-classes");
|
|
121
121
|
var initialState = {
|
|
122
122
|
data: { items: {}, order: [] },
|
|
123
|
+
classLabels: {},
|
|
123
124
|
initialData: {
|
|
124
125
|
frontend: { items: {}, order: [] },
|
|
125
126
|
preview: { items: {}, order: [] }
|
|
@@ -132,17 +133,19 @@ var slice = createSlice({
|
|
|
132
133
|
initialState,
|
|
133
134
|
reducers: {
|
|
134
135
|
load(state, {
|
|
135
|
-
payload: { frontend, preview }
|
|
136
|
+
payload: { frontend, preview, classLabels }
|
|
136
137
|
}) {
|
|
137
138
|
state.initialData.frontend = frontend;
|
|
138
139
|
state.initialData.preview = preview;
|
|
139
140
|
state.data = preview;
|
|
141
|
+
state.classLabels = classLabels;
|
|
140
142
|
state.isDirty = false;
|
|
141
143
|
},
|
|
142
144
|
add(state, { payload }) {
|
|
143
145
|
localHistory.next(state.data);
|
|
144
146
|
state.data.items[payload.id] = payload;
|
|
145
147
|
state.data.order.unshift(payload.id);
|
|
148
|
+
state.classLabels[payload.id] = payload.label;
|
|
146
149
|
state.isDirty = true;
|
|
147
150
|
},
|
|
148
151
|
delete(state, { payload }) {
|
|
@@ -151,6 +154,7 @@ var slice = createSlice({
|
|
|
151
154
|
Object.entries(state.data.items).filter(([id2]) => id2 !== payload)
|
|
152
155
|
);
|
|
153
156
|
state.data.order = state.data.order.filter((id2) => id2 !== payload);
|
|
157
|
+
delete state.classLabels[payload];
|
|
154
158
|
state.isDirty = true;
|
|
155
159
|
},
|
|
156
160
|
setOrder(state, { payload }) {
|
|
@@ -172,6 +176,7 @@ var slice = createSlice({
|
|
|
172
176
|
localHistory.next(state.data);
|
|
173
177
|
Object.entries(payload).forEach(([id2, { modified }]) => {
|
|
174
178
|
state.data.items[id2].label = modified;
|
|
179
|
+
state.classLabels[id2] = modified;
|
|
175
180
|
});
|
|
176
181
|
state.isDirty = false;
|
|
177
182
|
},
|
|
@@ -236,6 +241,28 @@ var slice = createSlice({
|
|
|
236
241
|
state.data = data;
|
|
237
242
|
state.isDirty = true;
|
|
238
243
|
}
|
|
244
|
+
},
|
|
245
|
+
mergeExistingClasses(state, {
|
|
246
|
+
payload: { preview, frontend }
|
|
247
|
+
}) {
|
|
248
|
+
Object.entries(preview).forEach(([id2, previewClassData]) => {
|
|
249
|
+
const frontendClassData = frontend[id2];
|
|
250
|
+
if (previewClassData === null || previewClassData === void 0) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (!(id2 in state.data.items)) {
|
|
254
|
+
state.data.items[id2] = previewClassData;
|
|
255
|
+
}
|
|
256
|
+
if (!(id2 in state.initialData.frontend.items)) {
|
|
257
|
+
state.initialData.frontend.items[id2] = frontendClassData;
|
|
258
|
+
}
|
|
259
|
+
if (!(id2 in state.initialData.preview.items)) {
|
|
260
|
+
state.initialData.preview.items[id2] = previewClassData;
|
|
261
|
+
}
|
|
262
|
+
if (!(id2 in state.classLabels)) {
|
|
263
|
+
state.classLabels[id2] = previewClassData.label;
|
|
264
|
+
}
|
|
265
|
+
});
|
|
239
266
|
}
|
|
240
267
|
}
|
|
241
268
|
});
|
|
@@ -255,22 +282,37 @@ var getNonEmptyVariants = (style) => {
|
|
|
255
282
|
({ props, custom_css: customCss }) => Object.keys(props).length || customCss?.raw
|
|
256
283
|
);
|
|
257
284
|
};
|
|
285
|
+
var placeholderDefinition = (id2, label) => ({
|
|
286
|
+
id: id2,
|
|
287
|
+
type: "class",
|
|
288
|
+
label,
|
|
289
|
+
variants: []
|
|
290
|
+
});
|
|
258
291
|
var selectData = (state) => state[SLICE_NAME].data;
|
|
292
|
+
var selectClassLabels = (state) => state[SLICE_NAME].classLabels;
|
|
259
293
|
var selectFrontendInitialData = (state) => state[SLICE_NAME].initialData.frontend;
|
|
260
294
|
var selectPreviewInitialData = (state) => state[SLICE_NAME].initialData.preview;
|
|
261
295
|
var selectOrder = createSelector(selectData, ({ order }) => order);
|
|
262
296
|
var selectGlobalClasses = createSelector(selectData, ({ items }) => items);
|
|
263
297
|
var selectIsDirty = (state) => state[SLICE_NAME].isDirty;
|
|
264
298
|
var selectOrderedClasses = createSelector(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
(items, order) => order.map((id2) =>
|
|
299
|
+
selectData,
|
|
300
|
+
selectClassLabels,
|
|
301
|
+
({ items, order }, classLabels) => order.map((id2) => {
|
|
302
|
+
const loaded = items[id2];
|
|
303
|
+
if (loaded) {
|
|
304
|
+
return loaded;
|
|
305
|
+
}
|
|
306
|
+
const label = classLabels[id2];
|
|
307
|
+
return label !== void 0 ? placeholderDefinition(id2, label) : null;
|
|
308
|
+
}).filter((s) => s !== null)
|
|
268
309
|
);
|
|
269
310
|
var selectClass = (state, id2) => state[SLICE_NAME].data.items[id2] ?? null;
|
|
270
311
|
var selectEmptyCssClass = createSelector(
|
|
271
312
|
selectData,
|
|
272
313
|
({ items }) => Object.values(items).filter((cssClass) => cssClass.variants.length === 0)
|
|
273
314
|
);
|
|
315
|
+
var selectIsClassFetched = (state, id2) => !!state[SLICE_NAME].initialData.preview.items[id2] || !!state[SLICE_NAME].initialData.frontend.items[id2] || false;
|
|
274
316
|
|
|
275
317
|
// src/hooks/use-classes-order.ts
|
|
276
318
|
var useClassesOrder = () => {
|
|
@@ -356,21 +398,26 @@ import { httpService } from "@elementor/http-client";
|
|
|
356
398
|
var RESOURCE_URL = "/global-classes";
|
|
357
399
|
var BASE_URL = "elementor/v1";
|
|
358
400
|
var RESOURCE_USAGE_URL = `${RESOURCE_URL}/usage`;
|
|
401
|
+
var RESOURCE_POST_URL = `${RESOURCE_URL}/post`;
|
|
402
|
+
var RESOURCE_STYLES_URL = `${RESOURCE_URL}/styles`;
|
|
403
|
+
function saveGlobalClasses(context2, payload) {
|
|
404
|
+
return httpService().put(`${BASE_URL}${RESOURCE_URL}`, payload, {
|
|
405
|
+
params: { context: context2 }
|
|
406
|
+
});
|
|
407
|
+
}
|
|
359
408
|
var apiClient = {
|
|
360
409
|
usage: () => httpService().get(`${BASE_URL}${RESOURCE_USAGE_URL}`),
|
|
361
410
|
all: (context2 = "preview") => httpService().get(`${BASE_URL}${RESOURCE_URL}`, {
|
|
362
411
|
params: { context: context2 }
|
|
363
412
|
}),
|
|
364
|
-
|
|
365
|
-
params: {
|
|
366
|
-
context: "frontend"
|
|
367
|
-
}
|
|
413
|
+
getStylesForPost: (postId, context2 = "preview") => httpService().get(`${BASE_URL}${RESOURCE_POST_URL}`, {
|
|
414
|
+
params: { context: context2, post_id: postId }
|
|
368
415
|
}),
|
|
369
|
-
|
|
370
|
-
params: {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
416
|
+
getStylesByIds: (ids, context2 = "preview") => httpService().get(`${BASE_URL}${RESOURCE_STYLES_URL}`, {
|
|
417
|
+
params: { context: context2, ids: ids.join(",") }
|
|
418
|
+
}),
|
|
419
|
+
publish: (payload) => saveGlobalClasses("frontend", payload),
|
|
420
|
+
saveDraft: (payload) => saveGlobalClasses("preview", payload)
|
|
374
421
|
};
|
|
375
422
|
var API_ERROR_CODES = {
|
|
376
423
|
DUPLICATED_LABEL: "DUPLICATED_LABEL"
|
|
@@ -718,15 +765,20 @@ var extractCssClassData = (classId) => {
|
|
|
718
765
|
return { classTitle };
|
|
719
766
|
};
|
|
720
767
|
var getCssClass = (classId) => {
|
|
721
|
-
const
|
|
722
|
-
|
|
723
|
-
|
|
768
|
+
const state = getState();
|
|
769
|
+
const cssClass = selectClass(state, classId);
|
|
770
|
+
if (cssClass) {
|
|
771
|
+
return cssClass;
|
|
724
772
|
}
|
|
725
|
-
|
|
773
|
+
const label = selectClassLabels(state)[classId];
|
|
774
|
+
if (label !== void 0) {
|
|
775
|
+
return placeholderDefinition(classId, label);
|
|
776
|
+
}
|
|
777
|
+
throw new Error(`CSS class with ID ${classId} not found`);
|
|
726
778
|
};
|
|
727
779
|
var trackDeleteClass = async (classId) => {
|
|
728
|
-
const totalInstances = await getTotalInstancesByCssClassID(classId);
|
|
729
780
|
const classTitle = getCssClass(classId).label;
|
|
781
|
+
const totalInstances = await getTotalInstancesByCssClassID(classId);
|
|
730
782
|
return { totalInstances, classTitle };
|
|
731
783
|
};
|
|
732
784
|
var getTotalInstancesByCssClassID = async (classId) => {
|
|
@@ -746,14 +798,19 @@ var getRemovedInfo = (classId) => {
|
|
|
746
798
|
};
|
|
747
799
|
|
|
748
800
|
// src/save-global-classes.tsx
|
|
749
|
-
async function
|
|
801
|
+
async function saveGlobalClasses2({ context: context2, onApprove }) {
|
|
750
802
|
const state = selectData(getState2());
|
|
751
803
|
const apiAction = context2 === "preview" ? apiClient.saveDraft : apiClient.publish;
|
|
752
804
|
const currentContext = context2 === "preview" ? selectPreviewInitialData : selectFrontendInitialData;
|
|
805
|
+
const changes = calculateChanges(state, currentContext(getState2()));
|
|
806
|
+
const touchedIds = [...changes.added, ...changes.modified];
|
|
807
|
+
const touchedItems = Object.fromEntries(
|
|
808
|
+
touchedIds.map((id2) => [id2, state.items[id2]]).filter(([, v]) => v)
|
|
809
|
+
);
|
|
753
810
|
const response = await apiAction({
|
|
754
|
-
items:
|
|
811
|
+
items: touchedItems,
|
|
755
812
|
order: state.order,
|
|
756
|
-
changes
|
|
813
|
+
changes
|
|
757
814
|
});
|
|
758
815
|
dispatch(slice.actions.reset({ context: context2 }));
|
|
759
816
|
window.dispatchEvent(new CustomEvent("classes:updated", { detail: { context: context2 } }));
|
|
@@ -777,12 +834,16 @@ async function saveGlobalClasses({ context: context2, onApprove }) {
|
|
|
777
834
|
function calculateChanges(state, initialData) {
|
|
778
835
|
const stateIds = Object.keys(state.items);
|
|
779
836
|
const initialDataIds = Object.keys(initialData.items);
|
|
837
|
+
const { order: stateOrder } = state;
|
|
838
|
+
const { order: initialDataOrder } = initialData;
|
|
839
|
+
const order = stateOrder.join(";") !== initialDataOrder.join(";");
|
|
780
840
|
return {
|
|
781
841
|
added: stateIds.filter((id2) => !initialDataIds.includes(id2)),
|
|
782
842
|
deleted: initialDataIds.filter((id2) => !stateIds.includes(id2)),
|
|
783
843
|
modified: stateIds.filter((id2) => {
|
|
784
844
|
return id2 in initialData.items && hash(state.items[id2]) !== hash(initialData.items[id2]);
|
|
785
|
-
})
|
|
845
|
+
}),
|
|
846
|
+
order
|
|
786
847
|
};
|
|
787
848
|
}
|
|
788
849
|
|
|
@@ -1821,7 +1882,7 @@ var GlobalClassesList = ({
|
|
|
1821
1882
|
search: { debouncedValue: searchValue }
|
|
1822
1883
|
} = useSearchAndFilters();
|
|
1823
1884
|
const cssClasses = useOrderedClasses();
|
|
1824
|
-
const
|
|
1885
|
+
const dispatch7 = useDispatch();
|
|
1825
1886
|
const filters = useFilters();
|
|
1826
1887
|
const [draggedItemId, setDraggedItemId] = useState5(null);
|
|
1827
1888
|
const draggedItemLabel = cssClasses.find((cssClass) => cssClass.id === draggedItemId)?.label ?? "";
|
|
@@ -1853,17 +1914,17 @@ var GlobalClassesList = ({
|
|
|
1853
1914
|
event.stopImmediatePropagation();
|
|
1854
1915
|
event.preventDefault();
|
|
1855
1916
|
if (event.shiftKey) {
|
|
1856
|
-
|
|
1917
|
+
dispatch7(slice.actions.redo());
|
|
1857
1918
|
return;
|
|
1858
1919
|
}
|
|
1859
|
-
|
|
1920
|
+
dispatch7(slice.actions.undo());
|
|
1860
1921
|
}
|
|
1861
1922
|
};
|
|
1862
1923
|
window.addEventListener("keydown", handler2, {
|
|
1863
1924
|
capture: true
|
|
1864
1925
|
});
|
|
1865
1926
|
return () => window.removeEventListener("keydown", handler2);
|
|
1866
|
-
}, [
|
|
1927
|
+
}, [dispatch7]);
|
|
1867
1928
|
if (!cssClasses?.length) {
|
|
1868
1929
|
return /* @__PURE__ */ React17.createElement(EmptyState, null);
|
|
1869
1930
|
}
|
|
@@ -1920,7 +1981,7 @@ var GlobalClassesList = ({
|
|
|
1920
1981
|
newValue: newLabel,
|
|
1921
1982
|
source: "class-manager"
|
|
1922
1983
|
});
|
|
1923
|
-
|
|
1984
|
+
dispatch7(
|
|
1924
1985
|
slice.actions.update({
|
|
1925
1986
|
style: {
|
|
1926
1987
|
id: cssClass.id,
|
|
@@ -1943,7 +2004,7 @@ var GlobalClassesList = ({
|
|
|
1943
2004
|
} else if (newValue && onStartSyncRequest) {
|
|
1944
2005
|
onStartSyncRequest(id2);
|
|
1945
2006
|
} else {
|
|
1946
|
-
|
|
2007
|
+
dispatch7(
|
|
1947
2008
|
slice.actions.update({
|
|
1948
2009
|
style: {
|
|
1949
2010
|
id: id2,
|
|
@@ -1970,10 +2031,10 @@ var StyledHeader = styled6(Typography8)(({ theme, variant }) => ({
|
|
|
1970
2031
|
}
|
|
1971
2032
|
}));
|
|
1972
2033
|
var useReorder = (draggedItemId, setDraggedItemId, draggedItemLabel) => {
|
|
1973
|
-
const
|
|
2034
|
+
const dispatch7 = useDispatch();
|
|
1974
2035
|
const order = useClassesOrder();
|
|
1975
2036
|
const reorder = (newIds) => {
|
|
1976
|
-
|
|
2037
|
+
dispatch7(slice.actions.setOrder(newIds));
|
|
1977
2038
|
if (draggedItemId) {
|
|
1978
2039
|
trackGlobalClasses({
|
|
1979
2040
|
event: "classManagerReorder",
|
|
@@ -2340,7 +2401,7 @@ var usePreventUnload = () => {
|
|
|
2340
2401
|
};
|
|
2341
2402
|
var usePublish = () => {
|
|
2342
2403
|
return useMutation({
|
|
2343
|
-
mutationFn: () =>
|
|
2404
|
+
mutationFn: () => saveGlobalClasses2({ context: "frontend" }),
|
|
2344
2405
|
onSuccess: async () => {
|
|
2345
2406
|
setDocumentModifiedStatus(false);
|
|
2346
2407
|
if (hasDeletedItems()) {
|
|
@@ -2379,14 +2440,17 @@ var StopSyncConfirmationDialog = ({ open, onClose, onConfirm }) => {
|
|
|
2379
2440
|
));
|
|
2380
2441
|
};
|
|
2381
2442
|
|
|
2443
|
+
// src/mcp-integration/classes-resource.ts
|
|
2444
|
+
import { __getState as getState5 } from "@elementor/store";
|
|
2445
|
+
|
|
2382
2446
|
// src/global-classes-styles-provider.ts
|
|
2383
2447
|
import {
|
|
2384
2448
|
generateId
|
|
2385
2449
|
} from "@elementor/editor-styles";
|
|
2386
2450
|
import { createStylesProvider } from "@elementor/editor-styles-repository";
|
|
2387
2451
|
import {
|
|
2388
|
-
__dispatch as
|
|
2389
|
-
__getState as
|
|
2452
|
+
__dispatch as dispatch6,
|
|
2453
|
+
__getState as getState4,
|
|
2390
2454
|
__subscribeWithSelector as subscribeWithSelector
|
|
2391
2455
|
} from "@elementor/store";
|
|
2392
2456
|
import { __ as __15 } from "@wordpress/i18n";
|
|
@@ -2407,10 +2471,112 @@ var getCapabilities = () => {
|
|
|
2407
2471
|
}
|
|
2408
2472
|
};
|
|
2409
2473
|
|
|
2474
|
+
// src/load-existing-classes.ts
|
|
2475
|
+
import { __dispatch as dispatch5, __getState as getState3 } from "@elementor/store";
|
|
2476
|
+
|
|
2477
|
+
// src/load-document-classes.ts
|
|
2478
|
+
import { getCurrentDocument } from "@elementor/editor-documents";
|
|
2479
|
+
import { __dispatch as dispatch4 } from "@elementor/store";
|
|
2480
|
+
|
|
2481
|
+
// src/utils/create-labels-for-classes.ts
|
|
2482
|
+
function createLabelsForClasses(entries) {
|
|
2483
|
+
return Object.fromEntries(entries.map((e) => [e.id, e.label]));
|
|
2484
|
+
}
|
|
2485
|
+
|
|
2486
|
+
// src/load-document-classes.ts
|
|
2487
|
+
function styleDefinitionsMapWithoutNull(map) {
|
|
2488
|
+
return Object.fromEntries(
|
|
2489
|
+
Object.entries(map).filter(
|
|
2490
|
+
(entry) => entry[1] !== null
|
|
2491
|
+
)
|
|
2492
|
+
);
|
|
2493
|
+
}
|
|
2494
|
+
function resetGlobalClassesState(globalOrder, classLabels) {
|
|
2495
|
+
dispatch4(
|
|
2496
|
+
slice.actions.load({
|
|
2497
|
+
preview: { items: {}, order: globalOrder },
|
|
2498
|
+
frontend: { items: {}, order: globalOrder },
|
|
2499
|
+
classLabels
|
|
2500
|
+
})
|
|
2501
|
+
);
|
|
2502
|
+
}
|
|
2503
|
+
async function loadCurrentDocumentClasses() {
|
|
2504
|
+
const previewIndexRes = await apiClient.all("preview");
|
|
2505
|
+
const previewIndex = previewIndexRes.data.data;
|
|
2506
|
+
const classLabels = createLabelsForClasses(previewIndex);
|
|
2507
|
+
const globalOrder = previewIndex.map((e) => e.id);
|
|
2508
|
+
resetGlobalClassesState(globalOrder, classLabels);
|
|
2509
|
+
const postId = getCurrentDocument()?.id;
|
|
2510
|
+
if (!postId) {
|
|
2511
|
+
return;
|
|
2512
|
+
}
|
|
2513
|
+
const [previewPostRes, frontendPostRes] = await Promise.all([
|
|
2514
|
+
apiClient.getStylesForPost(postId, "preview"),
|
|
2515
|
+
apiClient.getStylesForPost(postId, "frontend")
|
|
2516
|
+
]);
|
|
2517
|
+
const previewItems = styleDefinitionsMapWithoutNull(previewPostRes.data.data);
|
|
2518
|
+
const frontendItems = styleDefinitionsMapWithoutNull(frontendPostRes.data.data);
|
|
2519
|
+
dispatch4(
|
|
2520
|
+
slice.actions.load({
|
|
2521
|
+
preview: { items: previewItems, order: globalOrder },
|
|
2522
|
+
frontend: { items: frontendItems, order: globalOrder },
|
|
2523
|
+
classLabels
|
|
2524
|
+
})
|
|
2525
|
+
);
|
|
2526
|
+
}
|
|
2527
|
+
async function addDocumentClasses(documentId) {
|
|
2528
|
+
const [previewPostRes, frontendPostRes] = await Promise.all([
|
|
2529
|
+
apiClient.getStylesForPost(documentId, "preview"),
|
|
2530
|
+
apiClient.getStylesForPost(documentId, "frontend")
|
|
2531
|
+
]);
|
|
2532
|
+
const previewItems = styleDefinitionsMapWithoutNull(previewPostRes.data.data);
|
|
2533
|
+
const frontendItems = styleDefinitionsMapWithoutNull(frontendPostRes.data.data);
|
|
2534
|
+
dispatch4(
|
|
2535
|
+
slice.actions.mergeExistingClasses({
|
|
2536
|
+
preview: previewItems,
|
|
2537
|
+
frontend: frontendItems
|
|
2538
|
+
})
|
|
2539
|
+
);
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
// src/load-existing-classes.ts
|
|
2543
|
+
var pendingLoad = null;
|
|
2544
|
+
var pendingIds = /* @__PURE__ */ new Set();
|
|
2545
|
+
async function loadExistingClasses(classIds) {
|
|
2546
|
+
const existingClasses = selectGlobalClasses(getState3());
|
|
2547
|
+
const missingIds = classIds.filter((id2) => !(id2 in existingClasses));
|
|
2548
|
+
if (missingIds.length === 0) {
|
|
2549
|
+
return;
|
|
2550
|
+
}
|
|
2551
|
+
missingIds.forEach((id2) => pendingIds.add(id2));
|
|
2552
|
+
if (pendingLoad) {
|
|
2553
|
+
await pendingLoad;
|
|
2554
|
+
return loadExistingClasses(classIds);
|
|
2555
|
+
}
|
|
2556
|
+
pendingLoad = fetchAndMergeClasses();
|
|
2557
|
+
try {
|
|
2558
|
+
await pendingLoad;
|
|
2559
|
+
} finally {
|
|
2560
|
+
pendingLoad = null;
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
async function fetchAndMergeClasses() {
|
|
2564
|
+
const idsToFetch = Array.from(pendingIds);
|
|
2565
|
+
pendingIds.clear();
|
|
2566
|
+
if (idsToFetch.length === 0) {
|
|
2567
|
+
return;
|
|
2568
|
+
}
|
|
2569
|
+
const previewResponse = await apiClient.getStylesByIds(idsToFetch, "preview");
|
|
2570
|
+
const frontendResponse = await apiClient.getStylesByIds(idsToFetch, "frontend");
|
|
2571
|
+
const previewItems = styleDefinitionsMapWithoutNull(previewResponse.data.data);
|
|
2572
|
+
const frontendItems = styleDefinitionsMapWithoutNull(frontendResponse.data.data);
|
|
2573
|
+
dispatch5(slice.actions.mergeExistingClasses({ preview: previewItems, frontend: frontendItems }));
|
|
2574
|
+
}
|
|
2575
|
+
|
|
2410
2576
|
// src/global-classes-styles-provider.ts
|
|
2411
|
-
var MAX_CLASSES =
|
|
2577
|
+
var MAX_CLASSES = 5e3;
|
|
2412
2578
|
var GLOBAL_CLASSES_PROVIDER_KEY = "global-classes";
|
|
2413
|
-
var PREGENERATED_LINK_PATTERN = /^global-(preview|frontend)-[a-zA-Z_-]+-css$/;
|
|
2579
|
+
var PREGENERATED_LINK_PATTERN = /^global-([0-9]+-)?(preview|frontend)-[a-zA-Z_-]+-css$/;
|
|
2414
2580
|
var globalClassesStylesProvider = createStylesProvider({
|
|
2415
2581
|
key: GLOBAL_CLASSES_PROVIDER_KEY,
|
|
2416
2582
|
priority: 30,
|
|
@@ -2423,21 +2589,38 @@ var globalClassesStylesProvider = createStylesProvider({
|
|
|
2423
2589
|
subscribe: (cb) => subscribeWithStates(cb),
|
|
2424
2590
|
capabilities: getCapabilities(),
|
|
2425
2591
|
actions: {
|
|
2426
|
-
all: () => selectOrderedClasses(
|
|
2427
|
-
get: (id2) =>
|
|
2592
|
+
all: () => selectOrderedClasses(getState4()),
|
|
2593
|
+
get: (id2) => {
|
|
2594
|
+
const state = getState4();
|
|
2595
|
+
const isFetched = selectIsClassFetched(state, id2);
|
|
2596
|
+
const style = selectClass(state, id2);
|
|
2597
|
+
if (isFetched || style) {
|
|
2598
|
+
return style;
|
|
2599
|
+
}
|
|
2600
|
+
loadExistingClasses([id2]);
|
|
2601
|
+
const label = selectClassLabels(state)[id2] ?? id2;
|
|
2602
|
+
return placeholderDefinition(id2, label);
|
|
2603
|
+
},
|
|
2428
2604
|
resolveCssName: (id2) => {
|
|
2429
|
-
|
|
2605
|
+
const state = getState4();
|
|
2606
|
+
const loaded = selectClass(state, id2);
|
|
2607
|
+
if (loaded) {
|
|
2608
|
+
return loaded.label;
|
|
2609
|
+
}
|
|
2610
|
+
const fromIndex = selectClassLabels(state)[id2];
|
|
2611
|
+
return fromIndex ?? id2;
|
|
2430
2612
|
},
|
|
2431
2613
|
create: (label, variants = [], id2) => {
|
|
2432
|
-
const
|
|
2433
|
-
const existingLabels =
|
|
2614
|
+
const existingClasses = Object.entries(selectClassLabels(getState4()));
|
|
2615
|
+
const existingLabels = existingClasses.map(([, classLabel]) => classLabel);
|
|
2434
2616
|
if (existingLabels.includes(label)) {
|
|
2435
2617
|
throw new GlobalClassLabelAlreadyExistsError({ context: { label } });
|
|
2436
2618
|
}
|
|
2619
|
+
const existingIds = existingClasses.map(([existingId]) => existingId);
|
|
2437
2620
|
if (!id2) {
|
|
2438
|
-
id2 = generateId("g-",
|
|
2621
|
+
id2 = generateId("g-", existingIds);
|
|
2439
2622
|
}
|
|
2440
|
-
|
|
2623
|
+
dispatch6(
|
|
2441
2624
|
slice.actions.add({
|
|
2442
2625
|
id: id2,
|
|
2443
2626
|
type: "class",
|
|
@@ -2448,17 +2631,17 @@ var globalClassesStylesProvider = createStylesProvider({
|
|
|
2448
2631
|
return id2;
|
|
2449
2632
|
},
|
|
2450
2633
|
update: (payload) => {
|
|
2451
|
-
|
|
2634
|
+
dispatch6(
|
|
2452
2635
|
slice.actions.update({
|
|
2453
2636
|
style: payload
|
|
2454
2637
|
})
|
|
2455
2638
|
);
|
|
2456
2639
|
},
|
|
2457
2640
|
delete: (id2) => {
|
|
2458
|
-
|
|
2641
|
+
dispatch6(slice.actions.delete(id2));
|
|
2459
2642
|
},
|
|
2460
2643
|
updateProps: (args) => {
|
|
2461
|
-
|
|
2644
|
+
dispatch6(
|
|
2462
2645
|
slice.actions.updateProps({
|
|
2463
2646
|
id: args.id,
|
|
2464
2647
|
meta: args.meta,
|
|
@@ -2468,7 +2651,7 @@ var globalClassesStylesProvider = createStylesProvider({
|
|
|
2468
2651
|
);
|
|
2469
2652
|
},
|
|
2470
2653
|
updateCustomCss: (args) => {
|
|
2471
|
-
|
|
2654
|
+
dispatch6(
|
|
2472
2655
|
slice.actions.updateProps({
|
|
2473
2656
|
id: args.id,
|
|
2474
2657
|
meta: args.meta,
|
|
@@ -2485,12 +2668,12 @@ var globalClassesStylesProvider = createStylesProvider({
|
|
|
2485
2668
|
}
|
|
2486
2669
|
});
|
|
2487
2670
|
var subscribeWithStates = (cb) => {
|
|
2488
|
-
let previousState = selectData(
|
|
2671
|
+
let previousState = selectData(getState4());
|
|
2489
2672
|
return subscribeWithSelector(
|
|
2490
|
-
(state) => state
|
|
2673
|
+
(state) => selectData(state),
|
|
2491
2674
|
(currentState) => {
|
|
2492
|
-
cb(previousState.items, currentState.
|
|
2493
|
-
previousState = currentState
|
|
2675
|
+
cb(previousState.items, currentState.items);
|
|
2676
|
+
previousState = currentState;
|
|
2494
2677
|
}
|
|
2495
2678
|
);
|
|
2496
2679
|
};
|
|
@@ -2499,7 +2682,7 @@ var subscribeWithStates = (cb) => {
|
|
|
2499
2682
|
var GLOBAL_CLASSES_URI = "elementor://global-classes";
|
|
2500
2683
|
var STORAGE_KEY = "elementor-global-classes";
|
|
2501
2684
|
var updateLocalStorageCache = () => {
|
|
2502
|
-
const classes =
|
|
2685
|
+
const classes = selectOrderedClasses(getState5());
|
|
2503
2686
|
localStorage.setItem(STORAGE_KEY, JSON.stringify(classes));
|
|
2504
2687
|
};
|
|
2505
2688
|
var initClassesResource = (classesMcpEntry, canvasMcpEntry) => {
|
|
@@ -2687,47 +2870,25 @@ import { useEffect as useEffect5 } from "react";
|
|
|
2687
2870
|
import { GLOBAL_STYLES_IMPORTED_EVENT } from "@elementor/editor-canvas";
|
|
2688
2871
|
import { __useDispatch as useDispatch2 } from "@elementor/store";
|
|
2689
2872
|
function GlobalStylesImportListener() {
|
|
2690
|
-
const
|
|
2873
|
+
const dispatch7 = useDispatch2();
|
|
2691
2874
|
useEffect5(() => {
|
|
2692
2875
|
const handleGlobalStylesImported = (event) => {
|
|
2693
2876
|
const importedClasses = event.detail?.global_classes;
|
|
2694
2877
|
if (importedClasses?.items && importedClasses?.order) {
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
},
|
|
2701
|
-
frontend: {
|
|
2702
|
-
items: importedClasses.items,
|
|
2703
|
-
order: importedClasses.order
|
|
2704
|
-
}
|
|
2878
|
+
const { items } = importedClasses;
|
|
2879
|
+
dispatch7(
|
|
2880
|
+
slice.actions.mergeExistingClasses({
|
|
2881
|
+
preview: items,
|
|
2882
|
+
frontend: items
|
|
2705
2883
|
})
|
|
2706
2884
|
);
|
|
2707
2885
|
}
|
|
2708
|
-
Promise.all([apiClient.all("preview"), apiClient.all("frontend")]).then(([previewRes, frontendRes]) => {
|
|
2709
|
-
const { data: previewData } = previewRes;
|
|
2710
|
-
const { data: frontendData } = frontendRes;
|
|
2711
|
-
dispatch5(
|
|
2712
|
-
slice.actions.load({
|
|
2713
|
-
preview: {
|
|
2714
|
-
items: previewData.data,
|
|
2715
|
-
order: previewData.meta.order
|
|
2716
|
-
},
|
|
2717
|
-
frontend: {
|
|
2718
|
-
items: frontendData.data,
|
|
2719
|
-
order: frontendData.meta.order
|
|
2720
|
-
}
|
|
2721
|
-
})
|
|
2722
|
-
);
|
|
2723
|
-
}).catch(() => {
|
|
2724
|
-
});
|
|
2725
2886
|
};
|
|
2726
2887
|
window.addEventListener(GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported);
|
|
2727
2888
|
return () => {
|
|
2728
2889
|
window.removeEventListener(GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported);
|
|
2729
2890
|
};
|
|
2730
|
-
}, [
|
|
2891
|
+
}, [dispatch7]);
|
|
2731
2892
|
return null;
|
|
2732
2893
|
}
|
|
2733
2894
|
|
|
@@ -2762,29 +2923,14 @@ function OpenPanelFromUrl() {
|
|
|
2762
2923
|
|
|
2763
2924
|
// src/components/populate-store.tsx
|
|
2764
2925
|
import { useEffect as useEffect7 } from "react";
|
|
2765
|
-
import {
|
|
2926
|
+
import { registerDataHook } from "@elementor/editor-v1-adapters";
|
|
2766
2927
|
function PopulateStore() {
|
|
2767
|
-
const dispatch5 = useDispatch3();
|
|
2768
2928
|
useEffect7(() => {
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
slice.actions.load({
|
|
2775
|
-
preview: {
|
|
2776
|
-
items: previewData.data,
|
|
2777
|
-
order: previewData.meta.order
|
|
2778
|
-
},
|
|
2779
|
-
frontend: {
|
|
2780
|
-
items: frontendData.data,
|
|
2781
|
-
order: frontendData.meta.order
|
|
2782
|
-
}
|
|
2783
|
-
})
|
|
2784
|
-
);
|
|
2785
|
-
}
|
|
2786
|
-
);
|
|
2787
|
-
}, [dispatch5]);
|
|
2929
|
+
loadCurrentDocumentClasses();
|
|
2930
|
+
registerDataHook("after", "editor/documents/attach-preview", async () => {
|
|
2931
|
+
await loadCurrentDocumentClasses();
|
|
2932
|
+
});
|
|
2933
|
+
}, []);
|
|
2788
2934
|
return null;
|
|
2789
2935
|
}
|
|
2790
2936
|
|
|
@@ -3153,7 +3299,7 @@ async function attemptCreate(opts) {
|
|
|
3153
3299
|
}
|
|
3154
3300
|
]);
|
|
3155
3301
|
try {
|
|
3156
|
-
await
|
|
3302
|
+
await saveGlobalClasses2({ context: "frontend" });
|
|
3157
3303
|
return newClassId;
|
|
3158
3304
|
} catch {
|
|
3159
3305
|
deleteClass2(newClassId);
|
|
@@ -3179,7 +3325,7 @@ async function attemptUpdate(opts) {
|
|
|
3179
3325
|
state
|
|
3180
3326
|
}
|
|
3181
3327
|
});
|
|
3182
|
-
await
|
|
3328
|
+
await saveGlobalClasses2({ context: "frontend" });
|
|
3183
3329
|
return true;
|
|
3184
3330
|
} catch {
|
|
3185
3331
|
snapshot.forEach((style) => {
|
|
@@ -3188,7 +3334,7 @@ async function attemptUpdate(opts) {
|
|
|
3188
3334
|
variants: style.variants
|
|
3189
3335
|
});
|
|
3190
3336
|
});
|
|
3191
|
-
await
|
|
3337
|
+
await saveGlobalClasses2({ context: "frontend" });
|
|
3192
3338
|
return false;
|
|
3193
3339
|
}
|
|
3194
3340
|
}
|
|
@@ -3208,7 +3354,7 @@ async function attemptDelete(opts) {
|
|
|
3208
3354
|
}
|
|
3209
3355
|
try {
|
|
3210
3356
|
deleteClass2(classId);
|
|
3211
|
-
await
|
|
3357
|
+
await saveGlobalClasses2({ context: "frontend" });
|
|
3212
3358
|
return true;
|
|
3213
3359
|
} catch {
|
|
3214
3360
|
return false;
|
|
@@ -3240,8 +3386,8 @@ import { __privateListenTo as listenTo2, isExperimentActive as isExperimentActiv
|
|
|
3240
3386
|
// src/sync-with-document-save.ts
|
|
3241
3387
|
import { getCurrentUser } from "@elementor/editor-current-user";
|
|
3242
3388
|
import { setDocumentModifiedStatus as setDocumentModifiedStatus2 } from "@elementor/editor-documents";
|
|
3243
|
-
import { registerDataHook } from "@elementor/editor-v1-adapters";
|
|
3244
|
-
import { __getState as
|
|
3389
|
+
import { registerDataHook as registerDataHook2 } from "@elementor/editor-v1-adapters";
|
|
3390
|
+
import { __getState as getState6, __subscribeWithSelector as subscribeWithSelector2 } from "@elementor/store";
|
|
3245
3391
|
var pendingSave = null;
|
|
3246
3392
|
function syncWithDocumentSave(panelActions) {
|
|
3247
3393
|
const unsubscribe = syncDirtyState();
|
|
@@ -3266,7 +3412,7 @@ function triggerSave(panelActions, context2 = "preview") {
|
|
|
3266
3412
|
if (pendingSave) {
|
|
3267
3413
|
return pendingSave;
|
|
3268
3414
|
}
|
|
3269
|
-
const promise =
|
|
3415
|
+
const promise = saveGlobalClasses2({
|
|
3270
3416
|
context: context2,
|
|
3271
3417
|
onApprove: panelActions?.open
|
|
3272
3418
|
});
|
|
@@ -3277,7 +3423,7 @@ function triggerSave(panelActions, context2 = "preview") {
|
|
|
3277
3423
|
return promise;
|
|
3278
3424
|
}
|
|
3279
3425
|
function bindSaveAction(panelActions) {
|
|
3280
|
-
|
|
3426
|
+
registerDataHook2("dependency", "document/save/save", (args) => {
|
|
3281
3427
|
triggerSave(panelActions, args.status === "publish" ? "frontend" : "preview");
|
|
3282
3428
|
return true;
|
|
3283
3429
|
});
|
|
@@ -3293,7 +3439,7 @@ function bindBeforeSaveTemplateAction() {
|
|
|
3293
3439
|
}));
|
|
3294
3440
|
}
|
|
3295
3441
|
function isDirty() {
|
|
3296
|
-
return selectIsDirty(
|
|
3442
|
+
return selectIsDirty(getState6());
|
|
3297
3443
|
}
|
|
3298
3444
|
|
|
3299
3445
|
// src/sync-with-document.tsx
|
|
@@ -3360,6 +3506,9 @@ function init() {
|
|
|
3360
3506
|
export {
|
|
3361
3507
|
ClassManagerPanelEmbedded,
|
|
3362
3508
|
GLOBAL_CLASSES_URI,
|
|
3363
|
-
|
|
3509
|
+
addDocumentClasses,
|
|
3510
|
+
createLabelsForClasses,
|
|
3511
|
+
init,
|
|
3512
|
+
loadExistingClasses
|
|
3364
3513
|
};
|
|
3365
3514
|
//# sourceMappingURL=index.mjs.map
|