@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.js CHANGED
@@ -32,7 +32,10 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  ClassManagerPanelEmbedded: () => ClassManagerPanelEmbedded,
34
34
  GLOBAL_CLASSES_URI: () => GLOBAL_CLASSES_URI,
35
- init: () => init
35
+ addDocumentClasses: () => addDocumentClasses,
36
+ createLabelsForClasses: () => createLabelsForClasses,
37
+ init: () => init,
38
+ loadExistingClasses: () => loadExistingClasses
36
39
  });
37
40
  module.exports = __toCommonJS(index_exports);
38
41
 
@@ -136,6 +139,7 @@ var SnapshotHistory = class _SnapshotHistory {
136
139
  var localHistory = SnapshotHistory.get("global-classes");
137
140
  var initialState = {
138
141
  data: { items: {}, order: [] },
142
+ classLabels: {},
139
143
  initialData: {
140
144
  frontend: { items: {}, order: [] },
141
145
  preview: { items: {}, order: [] }
@@ -148,17 +152,19 @@ var slice = (0, import_store.__createSlice)({
148
152
  initialState,
149
153
  reducers: {
150
154
  load(state, {
151
- payload: { frontend, preview }
155
+ payload: { frontend, preview, classLabels }
152
156
  }) {
153
157
  state.initialData.frontend = frontend;
154
158
  state.initialData.preview = preview;
155
159
  state.data = preview;
160
+ state.classLabels = classLabels;
156
161
  state.isDirty = false;
157
162
  },
158
163
  add(state, { payload }) {
159
164
  localHistory.next(state.data);
160
165
  state.data.items[payload.id] = payload;
161
166
  state.data.order.unshift(payload.id);
167
+ state.classLabels[payload.id] = payload.label;
162
168
  state.isDirty = true;
163
169
  },
164
170
  delete(state, { payload }) {
@@ -167,6 +173,7 @@ var slice = (0, import_store.__createSlice)({
167
173
  Object.entries(state.data.items).filter(([id2]) => id2 !== payload)
168
174
  );
169
175
  state.data.order = state.data.order.filter((id2) => id2 !== payload);
176
+ delete state.classLabels[payload];
170
177
  state.isDirty = true;
171
178
  },
172
179
  setOrder(state, { payload }) {
@@ -188,6 +195,7 @@ var slice = (0, import_store.__createSlice)({
188
195
  localHistory.next(state.data);
189
196
  Object.entries(payload).forEach(([id2, { modified }]) => {
190
197
  state.data.items[id2].label = modified;
198
+ state.classLabels[id2] = modified;
191
199
  });
192
200
  state.isDirty = false;
193
201
  },
@@ -252,6 +260,28 @@ var slice = (0, import_store.__createSlice)({
252
260
  state.data = data;
253
261
  state.isDirty = true;
254
262
  }
263
+ },
264
+ mergeExistingClasses(state, {
265
+ payload: { preview, frontend }
266
+ }) {
267
+ Object.entries(preview).forEach(([id2, previewClassData]) => {
268
+ const frontendClassData = frontend[id2];
269
+ if (previewClassData === null || previewClassData === void 0) {
270
+ return;
271
+ }
272
+ if (!(id2 in state.data.items)) {
273
+ state.data.items[id2] = previewClassData;
274
+ }
275
+ if (!(id2 in state.initialData.frontend.items)) {
276
+ state.initialData.frontend.items[id2] = frontendClassData;
277
+ }
278
+ if (!(id2 in state.initialData.preview.items)) {
279
+ state.initialData.preview.items[id2] = previewClassData;
280
+ }
281
+ if (!(id2 in state.classLabels)) {
282
+ state.classLabels[id2] = previewClassData.label;
283
+ }
284
+ });
255
285
  }
256
286
  }
257
287
  });
@@ -271,22 +301,37 @@ var getNonEmptyVariants = (style) => {
271
301
  ({ props, custom_css: customCss }) => Object.keys(props).length || customCss?.raw
272
302
  );
273
303
  };
304
+ var placeholderDefinition = (id2, label) => ({
305
+ id: id2,
306
+ type: "class",
307
+ label,
308
+ variants: []
309
+ });
274
310
  var selectData = (state) => state[SLICE_NAME].data;
311
+ var selectClassLabels = (state) => state[SLICE_NAME].classLabels;
275
312
  var selectFrontendInitialData = (state) => state[SLICE_NAME].initialData.frontend;
276
313
  var selectPreviewInitialData = (state) => state[SLICE_NAME].initialData.preview;
277
314
  var selectOrder = (0, import_store.__createSelector)(selectData, ({ order }) => order);
278
315
  var selectGlobalClasses = (0, import_store.__createSelector)(selectData, ({ items }) => items);
279
316
  var selectIsDirty = (state) => state[SLICE_NAME].isDirty;
280
317
  var selectOrderedClasses = (0, import_store.__createSelector)(
281
- selectGlobalClasses,
282
- selectOrder,
283
- (items, order) => order.map((id2) => items[id2])
318
+ selectData,
319
+ selectClassLabels,
320
+ ({ items, order }, classLabels) => order.map((id2) => {
321
+ const loaded = items[id2];
322
+ if (loaded) {
323
+ return loaded;
324
+ }
325
+ const label = classLabels[id2];
326
+ return label !== void 0 ? placeholderDefinition(id2, label) : null;
327
+ }).filter((s) => s !== null)
284
328
  );
285
329
  var selectClass = (state, id2) => state[SLICE_NAME].data.items[id2] ?? null;
286
330
  var selectEmptyCssClass = (0, import_store.__createSelector)(
287
331
  selectData,
288
332
  ({ items }) => Object.values(items).filter((cssClass) => cssClass.variants.length === 0)
289
333
  );
334
+ var selectIsClassFetched = (state, id2) => !!state[SLICE_NAME].initialData.preview.items[id2] || !!state[SLICE_NAME].initialData.frontend.items[id2] || false;
290
335
 
291
336
  // src/hooks/use-classes-order.ts
292
337
  var useClassesOrder = () => {
@@ -372,21 +417,26 @@ var import_http_client = require("@elementor/http-client");
372
417
  var RESOURCE_URL = "/global-classes";
373
418
  var BASE_URL = "elementor/v1";
374
419
  var RESOURCE_USAGE_URL = `${RESOURCE_URL}/usage`;
420
+ var RESOURCE_POST_URL = `${RESOURCE_URL}/post`;
421
+ var RESOURCE_STYLES_URL = `${RESOURCE_URL}/styles`;
422
+ function saveGlobalClasses(context2, payload) {
423
+ return (0, import_http_client.httpService)().put(`${BASE_URL}${RESOURCE_URL}`, payload, {
424
+ params: { context: context2 }
425
+ });
426
+ }
375
427
  var apiClient = {
376
428
  usage: () => (0, import_http_client.httpService)().get(`${BASE_URL}${RESOURCE_USAGE_URL}`),
377
429
  all: (context2 = "preview") => (0, import_http_client.httpService)().get(`${BASE_URL}${RESOURCE_URL}`, {
378
430
  params: { context: context2 }
379
431
  }),
380
- publish: (payload) => (0, import_http_client.httpService)().put("elementor/v1" + RESOURCE_URL, payload, {
381
- params: {
382
- context: "frontend"
383
- }
432
+ getStylesForPost: (postId, context2 = "preview") => (0, import_http_client.httpService)().get(`${BASE_URL}${RESOURCE_POST_URL}`, {
433
+ params: { context: context2, post_id: postId }
384
434
  }),
385
- saveDraft: (payload) => (0, import_http_client.httpService)().put("elementor/v1" + RESOURCE_URL, payload, {
386
- params: {
387
- context: "preview"
388
- }
389
- })
435
+ getStylesByIds: (ids, context2 = "preview") => (0, import_http_client.httpService)().get(`${BASE_URL}${RESOURCE_STYLES_URL}`, {
436
+ params: { context: context2, ids: ids.join(",") }
437
+ }),
438
+ publish: (payload) => saveGlobalClasses("frontend", payload),
439
+ saveDraft: (payload) => saveGlobalClasses("preview", payload)
390
440
  };
391
441
  var API_ERROR_CODES = {
392
442
  DUPLICATED_LABEL: "DUPLICATED_LABEL"
@@ -723,15 +773,20 @@ var extractCssClassData = (classId) => {
723
773
  return { classTitle };
724
774
  };
725
775
  var getCssClass = (classId) => {
726
- const cssClass = selectClass((0, import_store8.__getState)(), classId);
727
- if (!cssClass) {
728
- throw new Error(`CSS class with ID ${classId} not found`);
776
+ const state = (0, import_store8.__getState)();
777
+ const cssClass = selectClass(state, classId);
778
+ if (cssClass) {
779
+ return cssClass;
780
+ }
781
+ const label = selectClassLabels(state)[classId];
782
+ if (label !== void 0) {
783
+ return placeholderDefinition(classId, label);
729
784
  }
730
- return cssClass;
785
+ throw new Error(`CSS class with ID ${classId} not found`);
731
786
  };
732
787
  var trackDeleteClass = async (classId) => {
733
- const totalInstances = await getTotalInstancesByCssClassID(classId);
734
788
  const classTitle = getCssClass(classId).label;
789
+ const totalInstances = await getTotalInstancesByCssClassID(classId);
735
790
  return { totalInstances, classTitle };
736
791
  };
737
792
  var getTotalInstancesByCssClassID = async (classId) => {
@@ -751,14 +806,19 @@ var getRemovedInfo = (classId) => {
751
806
  };
752
807
 
753
808
  // src/save-global-classes.tsx
754
- async function saveGlobalClasses({ context: context2, onApprove }) {
809
+ async function saveGlobalClasses2({ context: context2, onApprove }) {
755
810
  const state = selectData((0, import_store10.__getState)());
756
811
  const apiAction = context2 === "preview" ? apiClient.saveDraft : apiClient.publish;
757
812
  const currentContext = context2 === "preview" ? selectPreviewInitialData : selectFrontendInitialData;
813
+ const changes = calculateChanges(state, currentContext((0, import_store10.__getState)()));
814
+ const touchedIds = [...changes.added, ...changes.modified];
815
+ const touchedItems = Object.fromEntries(
816
+ touchedIds.map((id2) => [id2, state.items[id2]]).filter(([, v]) => v)
817
+ );
758
818
  const response = await apiAction({
759
- items: state.items,
819
+ items: touchedItems,
760
820
  order: state.order,
761
- changes: calculateChanges(state, currentContext((0, import_store10.__getState)()))
821
+ changes
762
822
  });
763
823
  (0, import_store10.__dispatch)(slice.actions.reset({ context: context2 }));
764
824
  window.dispatchEvent(new CustomEvent("classes:updated", { detail: { context: context2 } }));
@@ -782,12 +842,16 @@ async function saveGlobalClasses({ context: context2, onApprove }) {
782
842
  function calculateChanges(state, initialData) {
783
843
  const stateIds = Object.keys(state.items);
784
844
  const initialDataIds = Object.keys(initialData.items);
845
+ const { order: stateOrder } = state;
846
+ const { order: initialDataOrder } = initialData;
847
+ const order = stateOrder.join(";") !== initialDataOrder.join(";");
785
848
  return {
786
849
  added: stateIds.filter((id2) => !initialDataIds.includes(id2)),
787
850
  deleted: initialDataIds.filter((id2) => !stateIds.includes(id2)),
788
851
  modified: stateIds.filter((id2) => {
789
852
  return id2 in initialData.items && (0, import_utils4.hash)(state.items[id2]) !== (0, import_utils4.hash)(initialData.items[id2]);
790
- })
853
+ }),
854
+ order
791
855
  };
792
856
  }
793
857
 
@@ -1786,7 +1850,7 @@ var GlobalClassesList = ({
1786
1850
  search: { debouncedValue: searchValue }
1787
1851
  } = useSearchAndFilters();
1788
1852
  const cssClasses = useOrderedClasses();
1789
- const dispatch5 = (0, import_store16.__useDispatch)();
1853
+ const dispatch7 = (0, import_store16.__useDispatch)();
1790
1854
  const filters = useFilters();
1791
1855
  const [draggedItemId, setDraggedItemId] = (0, import_react8.useState)(null);
1792
1856
  const draggedItemLabel = cssClasses.find((cssClass) => cssClass.id === draggedItemId)?.label ?? "";
@@ -1818,17 +1882,17 @@ var GlobalClassesList = ({
1818
1882
  event.stopImmediatePropagation();
1819
1883
  event.preventDefault();
1820
1884
  if (event.shiftKey) {
1821
- dispatch5(slice.actions.redo());
1885
+ dispatch7(slice.actions.redo());
1822
1886
  return;
1823
1887
  }
1824
- dispatch5(slice.actions.undo());
1888
+ dispatch7(slice.actions.undo());
1825
1889
  }
1826
1890
  };
1827
1891
  window.addEventListener("keydown", handler2, {
1828
1892
  capture: true
1829
1893
  });
1830
1894
  return () => window.removeEventListener("keydown", handler2);
1831
- }, [dispatch5]);
1895
+ }, [dispatch7]);
1832
1896
  if (!cssClasses?.length) {
1833
1897
  return /* @__PURE__ */ React17.createElement(EmptyState, null);
1834
1898
  }
@@ -1885,7 +1949,7 @@ var GlobalClassesList = ({
1885
1949
  newValue: newLabel,
1886
1950
  source: "class-manager"
1887
1951
  });
1888
- dispatch5(
1952
+ dispatch7(
1889
1953
  slice.actions.update({
1890
1954
  style: {
1891
1955
  id: cssClass.id,
@@ -1908,7 +1972,7 @@ var GlobalClassesList = ({
1908
1972
  } else if (newValue && onStartSyncRequest) {
1909
1973
  onStartSyncRequest(id2);
1910
1974
  } else {
1911
- dispatch5(
1975
+ dispatch7(
1912
1976
  slice.actions.update({
1913
1977
  style: {
1914
1978
  id: id2,
@@ -1935,10 +1999,10 @@ var StyledHeader = (0, import_ui14.styled)(import_ui14.Typography)(({ theme, var
1935
1999
  }
1936
2000
  }));
1937
2001
  var useReorder = (draggedItemId, setDraggedItemId, draggedItemLabel) => {
1938
- const dispatch5 = (0, import_store16.__useDispatch)();
2002
+ const dispatch7 = (0, import_store16.__useDispatch)();
1939
2003
  const order = useClassesOrder();
1940
2004
  const reorder = (newIds) => {
1941
- dispatch5(slice.actions.setOrder(newIds));
2005
+ dispatch7(slice.actions.setOrder(newIds));
1942
2006
  if (draggedItemId) {
1943
2007
  trackGlobalClasses({
1944
2008
  event: "classManagerReorder",
@@ -2296,7 +2360,7 @@ var usePreventUnload = () => {
2296
2360
  };
2297
2361
  var usePublish = () => {
2298
2362
  return (0, import_query2.useMutation)({
2299
- mutationFn: () => saveGlobalClasses({ context: "frontend" }),
2363
+ mutationFn: () => saveGlobalClasses2({ context: "frontend" }),
2300
2364
  onSuccess: async () => {
2301
2365
  (0, import_editor_documents3.setDocumentModifiedStatus)(false);
2302
2366
  if (hasDeletedItems()) {
@@ -2335,10 +2399,13 @@ var StopSyncConfirmationDialog = ({ open, onClose, onConfirm }) => {
2335
2399
  ));
2336
2400
  };
2337
2401
 
2402
+ // src/mcp-integration/classes-resource.ts
2403
+ var import_store26 = require("@elementor/store");
2404
+
2338
2405
  // src/global-classes-styles-provider.ts
2339
2406
  var import_editor_styles2 = require("@elementor/editor-styles");
2340
2407
  var import_editor_styles_repository2 = require("@elementor/editor-styles-repository");
2341
- var import_store20 = require("@elementor/store");
2408
+ var import_store24 = require("@elementor/store");
2342
2409
  var import_i18n15 = require("@wordpress/i18n");
2343
2410
 
2344
2411
  // src/capabilities.ts
@@ -2357,10 +2424,112 @@ var getCapabilities = () => {
2357
2424
  }
2358
2425
  };
2359
2426
 
2427
+ // src/load-existing-classes.ts
2428
+ var import_store22 = require("@elementor/store");
2429
+
2430
+ // src/load-document-classes.ts
2431
+ var import_editor_documents4 = require("@elementor/editor-documents");
2432
+ var import_store20 = require("@elementor/store");
2433
+
2434
+ // src/utils/create-labels-for-classes.ts
2435
+ function createLabelsForClasses(entries) {
2436
+ return Object.fromEntries(entries.map((e) => [e.id, e.label]));
2437
+ }
2438
+
2439
+ // src/load-document-classes.ts
2440
+ function styleDefinitionsMapWithoutNull(map) {
2441
+ return Object.fromEntries(
2442
+ Object.entries(map).filter(
2443
+ (entry) => entry[1] !== null
2444
+ )
2445
+ );
2446
+ }
2447
+ function resetGlobalClassesState(globalOrder, classLabels) {
2448
+ (0, import_store20.__dispatch)(
2449
+ slice.actions.load({
2450
+ preview: { items: {}, order: globalOrder },
2451
+ frontend: { items: {}, order: globalOrder },
2452
+ classLabels
2453
+ })
2454
+ );
2455
+ }
2456
+ async function loadCurrentDocumentClasses() {
2457
+ const previewIndexRes = await apiClient.all("preview");
2458
+ const previewIndex = previewIndexRes.data.data;
2459
+ const classLabels = createLabelsForClasses(previewIndex);
2460
+ const globalOrder = previewIndex.map((e) => e.id);
2461
+ resetGlobalClassesState(globalOrder, classLabels);
2462
+ const postId = (0, import_editor_documents4.getCurrentDocument)()?.id;
2463
+ if (!postId) {
2464
+ return;
2465
+ }
2466
+ const [previewPostRes, frontendPostRes] = await Promise.all([
2467
+ apiClient.getStylesForPost(postId, "preview"),
2468
+ apiClient.getStylesForPost(postId, "frontend")
2469
+ ]);
2470
+ const previewItems = styleDefinitionsMapWithoutNull(previewPostRes.data.data);
2471
+ const frontendItems = styleDefinitionsMapWithoutNull(frontendPostRes.data.data);
2472
+ (0, import_store20.__dispatch)(
2473
+ slice.actions.load({
2474
+ preview: { items: previewItems, order: globalOrder },
2475
+ frontend: { items: frontendItems, order: globalOrder },
2476
+ classLabels
2477
+ })
2478
+ );
2479
+ }
2480
+ async function addDocumentClasses(documentId) {
2481
+ const [previewPostRes, frontendPostRes] = await Promise.all([
2482
+ apiClient.getStylesForPost(documentId, "preview"),
2483
+ apiClient.getStylesForPost(documentId, "frontend")
2484
+ ]);
2485
+ const previewItems = styleDefinitionsMapWithoutNull(previewPostRes.data.data);
2486
+ const frontendItems = styleDefinitionsMapWithoutNull(frontendPostRes.data.data);
2487
+ (0, import_store20.__dispatch)(
2488
+ slice.actions.mergeExistingClasses({
2489
+ preview: previewItems,
2490
+ frontend: frontendItems
2491
+ })
2492
+ );
2493
+ }
2494
+
2495
+ // src/load-existing-classes.ts
2496
+ var pendingLoad = null;
2497
+ var pendingIds = /* @__PURE__ */ new Set();
2498
+ async function loadExistingClasses(classIds) {
2499
+ const existingClasses = selectGlobalClasses((0, import_store22.__getState)());
2500
+ const missingIds = classIds.filter((id2) => !(id2 in existingClasses));
2501
+ if (missingIds.length === 0) {
2502
+ return;
2503
+ }
2504
+ missingIds.forEach((id2) => pendingIds.add(id2));
2505
+ if (pendingLoad) {
2506
+ await pendingLoad;
2507
+ return loadExistingClasses(classIds);
2508
+ }
2509
+ pendingLoad = fetchAndMergeClasses();
2510
+ try {
2511
+ await pendingLoad;
2512
+ } finally {
2513
+ pendingLoad = null;
2514
+ }
2515
+ }
2516
+ async function fetchAndMergeClasses() {
2517
+ const idsToFetch = Array.from(pendingIds);
2518
+ pendingIds.clear();
2519
+ if (idsToFetch.length === 0) {
2520
+ return;
2521
+ }
2522
+ const previewResponse = await apiClient.getStylesByIds(idsToFetch, "preview");
2523
+ const frontendResponse = await apiClient.getStylesByIds(idsToFetch, "frontend");
2524
+ const previewItems = styleDefinitionsMapWithoutNull(previewResponse.data.data);
2525
+ const frontendItems = styleDefinitionsMapWithoutNull(frontendResponse.data.data);
2526
+ (0, import_store22.__dispatch)(slice.actions.mergeExistingClasses({ preview: previewItems, frontend: frontendItems }));
2527
+ }
2528
+
2360
2529
  // src/global-classes-styles-provider.ts
2361
- var MAX_CLASSES = 100;
2530
+ var MAX_CLASSES = 5e3;
2362
2531
  var GLOBAL_CLASSES_PROVIDER_KEY = "global-classes";
2363
- var PREGENERATED_LINK_PATTERN = /^global-(preview|frontend)-[a-zA-Z_-]+-css$/;
2532
+ var PREGENERATED_LINK_PATTERN = /^global-([0-9]+-)?(preview|frontend)-[a-zA-Z_-]+-css$/;
2364
2533
  var globalClassesStylesProvider = (0, import_editor_styles_repository2.createStylesProvider)({
2365
2534
  key: GLOBAL_CLASSES_PROVIDER_KEY,
2366
2535
  priority: 30,
@@ -2373,21 +2542,38 @@ var globalClassesStylesProvider = (0, import_editor_styles_repository2.createSty
2373
2542
  subscribe: (cb) => subscribeWithStates(cb),
2374
2543
  capabilities: getCapabilities(),
2375
2544
  actions: {
2376
- all: () => selectOrderedClasses((0, import_store20.__getState)()),
2377
- get: (id2) => selectClass((0, import_store20.__getState)(), id2),
2545
+ all: () => selectOrderedClasses((0, import_store24.__getState)()),
2546
+ get: (id2) => {
2547
+ const state = (0, import_store24.__getState)();
2548
+ const isFetched = selectIsClassFetched(state, id2);
2549
+ const style = selectClass(state, id2);
2550
+ if (isFetched || style) {
2551
+ return style;
2552
+ }
2553
+ loadExistingClasses([id2]);
2554
+ const label = selectClassLabels(state)[id2] ?? id2;
2555
+ return placeholderDefinition(id2, label);
2556
+ },
2378
2557
  resolveCssName: (id2) => {
2379
- return selectClass((0, import_store20.__getState)(), id2)?.label ?? id2;
2558
+ const state = (0, import_store24.__getState)();
2559
+ const loaded = selectClass(state, id2);
2560
+ if (loaded) {
2561
+ return loaded.label;
2562
+ }
2563
+ const fromIndex = selectClassLabels(state)[id2];
2564
+ return fromIndex ?? id2;
2380
2565
  },
2381
2566
  create: (label, variants = [], id2) => {
2382
- const classes = selectGlobalClasses((0, import_store20.__getState)());
2383
- const existingLabels = Object.values(classes).map((style) => style.label);
2567
+ const existingClasses = Object.entries(selectClassLabels((0, import_store24.__getState)()));
2568
+ const existingLabels = existingClasses.map(([, classLabel]) => classLabel);
2384
2569
  if (existingLabels.includes(label)) {
2385
2570
  throw new GlobalClassLabelAlreadyExistsError({ context: { label } });
2386
2571
  }
2572
+ const existingIds = existingClasses.map(([existingId]) => existingId);
2387
2573
  if (!id2) {
2388
- id2 = (0, import_editor_styles2.generateId)("g-", Object.keys(classes));
2574
+ id2 = (0, import_editor_styles2.generateId)("g-", existingIds);
2389
2575
  }
2390
- (0, import_store20.__dispatch)(
2576
+ (0, import_store24.__dispatch)(
2391
2577
  slice.actions.add({
2392
2578
  id: id2,
2393
2579
  type: "class",
@@ -2398,17 +2584,17 @@ var globalClassesStylesProvider = (0, import_editor_styles_repository2.createSty
2398
2584
  return id2;
2399
2585
  },
2400
2586
  update: (payload) => {
2401
- (0, import_store20.__dispatch)(
2587
+ (0, import_store24.__dispatch)(
2402
2588
  slice.actions.update({
2403
2589
  style: payload
2404
2590
  })
2405
2591
  );
2406
2592
  },
2407
2593
  delete: (id2) => {
2408
- (0, import_store20.__dispatch)(slice.actions.delete(id2));
2594
+ (0, import_store24.__dispatch)(slice.actions.delete(id2));
2409
2595
  },
2410
2596
  updateProps: (args) => {
2411
- (0, import_store20.__dispatch)(
2597
+ (0, import_store24.__dispatch)(
2412
2598
  slice.actions.updateProps({
2413
2599
  id: args.id,
2414
2600
  meta: args.meta,
@@ -2418,7 +2604,7 @@ var globalClassesStylesProvider = (0, import_editor_styles_repository2.createSty
2418
2604
  );
2419
2605
  },
2420
2606
  updateCustomCss: (args) => {
2421
- (0, import_store20.__dispatch)(
2607
+ (0, import_store24.__dispatch)(
2422
2608
  slice.actions.updateProps({
2423
2609
  id: args.id,
2424
2610
  meta: args.meta,
@@ -2435,12 +2621,12 @@ var globalClassesStylesProvider = (0, import_editor_styles_repository2.createSty
2435
2621
  }
2436
2622
  });
2437
2623
  var subscribeWithStates = (cb) => {
2438
- let previousState = selectData((0, import_store20.__getState)());
2439
- return (0, import_store20.__subscribeWithSelector)(
2440
- (state) => state.globalClasses,
2624
+ let previousState = selectData((0, import_store24.__getState)());
2625
+ return (0, import_store24.__subscribeWithSelector)(
2626
+ (state) => selectData(state),
2441
2627
  (currentState) => {
2442
- cb(previousState.items, currentState.data.items);
2443
- previousState = currentState.data;
2628
+ cb(previousState.items, currentState.items);
2629
+ previousState = currentState;
2444
2630
  }
2445
2631
  );
2446
2632
  };
@@ -2449,7 +2635,7 @@ var subscribeWithStates = (cb) => {
2449
2635
  var GLOBAL_CLASSES_URI = "elementor://global-classes";
2450
2636
  var STORAGE_KEY = "elementor-global-classes";
2451
2637
  var updateLocalStorageCache = () => {
2452
- const classes = globalClassesStylesProvider.actions.all();
2638
+ const classes = selectOrderedClasses((0, import_store26.__getState)());
2453
2639
  localStorage.setItem(STORAGE_KEY, JSON.stringify(classes));
2454
2640
  };
2455
2641
  var initClassesResource = (classesMcpEntry, canvasMcpEntry) => {
@@ -2483,12 +2669,12 @@ var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
2483
2669
  var import_editor_mcp = require("@elementor/editor-mcp");
2484
2670
  var import_editor_panels2 = require("@elementor/editor-panels");
2485
2671
  var import_editor_styles_repository5 = require("@elementor/editor-styles-repository");
2486
- var import_editor_v1_adapters7 = require("@elementor/editor-v1-adapters");
2487
- var import_store28 = require("@elementor/store");
2672
+ var import_editor_v1_adapters8 = require("@elementor/editor-v1-adapters");
2673
+ var import_store32 = require("@elementor/store");
2488
2674
 
2489
2675
  // src/components/class-manager/class-manager-button.tsx
2490
2676
  var React20 = __toESM(require("react"));
2491
- var import_editor_documents4 = require("@elementor/editor-documents");
2677
+ var import_editor_documents5 = require("@elementor/editor-documents");
2492
2678
  var import_editor_styles_repository3 = require("@elementor/editor-styles-repository");
2493
2679
  var import_editor_ui10 = require("@elementor/editor-ui");
2494
2680
  var import_editor_v1_adapters3 = require("@elementor/editor-v1-adapters");
@@ -2519,9 +2705,9 @@ var trackGlobalClassesButton = () => {
2519
2705
  });
2520
2706
  };
2521
2707
  var ClassManagerButton = () => {
2522
- const document = (0, import_editor_documents4.__useActiveDocument)();
2708
+ const document = (0, import_editor_documents5.__useActiveDocument)();
2523
2709
  const { open: openPanel } = usePanelActions();
2524
- const { save: saveDocument } = (0, import_editor_documents4.__useActiveDocumentActions)();
2710
+ const { save: saveDocument } = (0, import_editor_documents5.__useActiveDocumentActions)();
2525
2711
  const { open: openSaveChangesDialog, close: closeSaveChangesDialog, isOpen: isSaveChangesDialogOpen } = (0, import_editor_ui10.useDialog)();
2526
2712
  const { prefetchClassesUsage } = usePrefetchCssClassUsage();
2527
2713
  const { userCan } = (0, import_editor_styles_repository3.useUserStylesCapability)();
@@ -2628,49 +2814,27 @@ function createClassName(prefix) {
2628
2814
  // src/components/global-styles-import-listener.tsx
2629
2815
  var import_react11 = require("react");
2630
2816
  var import_editor_canvas = require("@elementor/editor-canvas");
2631
- var import_store22 = require("@elementor/store");
2817
+ var import_store28 = require("@elementor/store");
2632
2818
  function GlobalStylesImportListener() {
2633
- const dispatch5 = (0, import_store22.__useDispatch)();
2819
+ const dispatch7 = (0, import_store28.__useDispatch)();
2634
2820
  (0, import_react11.useEffect)(() => {
2635
2821
  const handleGlobalStylesImported = (event) => {
2636
2822
  const importedClasses = event.detail?.global_classes;
2637
2823
  if (importedClasses?.items && importedClasses?.order) {
2638
- dispatch5(
2639
- slice.actions.load({
2640
- preview: {
2641
- items: importedClasses.items,
2642
- order: importedClasses.order
2643
- },
2644
- frontend: {
2645
- items: importedClasses.items,
2646
- order: importedClasses.order
2647
- }
2824
+ const { items } = importedClasses;
2825
+ dispatch7(
2826
+ slice.actions.mergeExistingClasses({
2827
+ preview: items,
2828
+ frontend: items
2648
2829
  })
2649
2830
  );
2650
2831
  }
2651
- Promise.all([apiClient.all("preview"), apiClient.all("frontend")]).then(([previewRes, frontendRes]) => {
2652
- const { data: previewData } = previewRes;
2653
- const { data: frontendData } = frontendRes;
2654
- dispatch5(
2655
- slice.actions.load({
2656
- preview: {
2657
- items: previewData.data,
2658
- order: previewData.meta.order
2659
- },
2660
- frontend: {
2661
- items: frontendData.data,
2662
- order: frontendData.meta.order
2663
- }
2664
- })
2665
- );
2666
- }).catch(() => {
2667
- });
2668
2832
  };
2669
2833
  window.addEventListener(import_editor_canvas.GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported);
2670
2834
  return () => {
2671
2835
  window.removeEventListener(import_editor_canvas.GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported);
2672
2836
  };
2673
- }, [dispatch5]);
2837
+ }, [dispatch7]);
2674
2838
  return null;
2675
2839
  }
2676
2840
 
@@ -2705,29 +2869,14 @@ function OpenPanelFromUrl() {
2705
2869
 
2706
2870
  // src/components/populate-store.tsx
2707
2871
  var import_react13 = require("react");
2708
- var import_store24 = require("@elementor/store");
2872
+ var import_editor_v1_adapters5 = require("@elementor/editor-v1-adapters");
2709
2873
  function PopulateStore() {
2710
- const dispatch5 = (0, import_store24.__useDispatch)();
2711
2874
  (0, import_react13.useEffect)(() => {
2712
- Promise.all([apiClient.all("preview"), apiClient.all("frontend")]).then(
2713
- ([previewRes, frontendRes]) => {
2714
- const { data: previewData } = previewRes;
2715
- const { data: frontendData } = frontendRes;
2716
- dispatch5(
2717
- slice.actions.load({
2718
- preview: {
2719
- items: previewData.data,
2720
- order: previewData.meta.order
2721
- },
2722
- frontend: {
2723
- items: frontendData.data,
2724
- order: frontendData.meta.order
2725
- }
2726
- })
2727
- );
2728
- }
2729
- );
2730
- }, [dispatch5]);
2875
+ loadCurrentDocumentClasses();
2876
+ (0, import_editor_v1_adapters5.registerDataHook)("after", "editor/documents/attach-preview", async () => {
2877
+ await loadCurrentDocumentClasses();
2878
+ });
2879
+ }, []);
2731
2880
  return null;
2732
2881
  }
2733
2882
 
@@ -3096,7 +3245,7 @@ async function attemptCreate(opts) {
3096
3245
  }
3097
3246
  ]);
3098
3247
  try {
3099
- await saveGlobalClasses({ context: "frontend" });
3248
+ await saveGlobalClasses2({ context: "frontend" });
3100
3249
  return newClassId;
3101
3250
  } catch {
3102
3251
  deleteClass2(newClassId);
@@ -3122,7 +3271,7 @@ async function attemptUpdate(opts) {
3122
3271
  state
3123
3272
  }
3124
3273
  });
3125
- await saveGlobalClasses({ context: "frontend" });
3274
+ await saveGlobalClasses2({ context: "frontend" });
3126
3275
  return true;
3127
3276
  } catch {
3128
3277
  snapshot.forEach((style) => {
@@ -3131,7 +3280,7 @@ async function attemptUpdate(opts) {
3131
3280
  variants: style.variants
3132
3281
  });
3133
3282
  });
3134
- await saveGlobalClasses({ context: "frontend" });
3283
+ await saveGlobalClasses2({ context: "frontend" });
3135
3284
  return false;
3136
3285
  }
3137
3286
  }
@@ -3151,7 +3300,7 @@ async function attemptDelete(opts) {
3151
3300
  }
3152
3301
  try {
3153
3302
  deleteClass2(classId);
3154
- await saveGlobalClasses({ context: "frontend" });
3303
+ await saveGlobalClasses2({ context: "frontend" });
3155
3304
  return true;
3156
3305
  } catch {
3157
3306
  return false;
@@ -3178,13 +3327,13 @@ var initMcpIntegration = (reg, canvasMcpEntry) => {
3178
3327
 
3179
3328
  // src/sync-with-document.tsx
3180
3329
  var import_react14 = require("react");
3181
- var import_editor_v1_adapters6 = require("@elementor/editor-v1-adapters");
3330
+ var import_editor_v1_adapters7 = require("@elementor/editor-v1-adapters");
3182
3331
 
3183
3332
  // src/sync-with-document-save.ts
3184
3333
  var import_editor_current_user3 = require("@elementor/editor-current-user");
3185
- var import_editor_documents5 = require("@elementor/editor-documents");
3186
- var import_editor_v1_adapters5 = require("@elementor/editor-v1-adapters");
3187
- var import_store26 = require("@elementor/store");
3334
+ var import_editor_documents6 = require("@elementor/editor-documents");
3335
+ var import_editor_v1_adapters6 = require("@elementor/editor-v1-adapters");
3336
+ var import_store30 = require("@elementor/store");
3188
3337
  var pendingSave = null;
3189
3338
  function syncWithDocumentSave(panelActions) {
3190
3339
  const unsubscribe = syncDirtyState();
@@ -3193,11 +3342,11 @@ function syncWithDocumentSave(panelActions) {
3193
3342
  return unsubscribe;
3194
3343
  }
3195
3344
  function syncDirtyState() {
3196
- return (0, import_store26.__subscribeWithSelector)(selectIsDirty, () => {
3345
+ return (0, import_store30.__subscribeWithSelector)(selectIsDirty, () => {
3197
3346
  if (!isDirty()) {
3198
3347
  return;
3199
3348
  }
3200
- (0, import_editor_documents5.setDocumentModifiedStatus)(true);
3349
+ (0, import_editor_documents6.setDocumentModifiedStatus)(true);
3201
3350
  });
3202
3351
  }
3203
3352
  function triggerSave(panelActions, context2 = "preview") {
@@ -3209,7 +3358,7 @@ function triggerSave(panelActions, context2 = "preview") {
3209
3358
  if (pendingSave) {
3210
3359
  return pendingSave;
3211
3360
  }
3212
- const promise = saveGlobalClasses({
3361
+ const promise = saveGlobalClasses2({
3213
3362
  context: context2,
3214
3363
  onApprove: panelActions?.open
3215
3364
  });
@@ -3220,7 +3369,7 @@ function triggerSave(panelActions, context2 = "preview") {
3220
3369
  return promise;
3221
3370
  }
3222
3371
  function bindSaveAction(panelActions) {
3223
- (0, import_editor_v1_adapters5.registerDataHook)("dependency", "document/save/save", (args) => {
3372
+ (0, import_editor_v1_adapters6.registerDataHook)("dependency", "document/save/save", (args) => {
3224
3373
  triggerSave(panelActions, args.status === "publish" ? "frontend" : "preview");
3225
3374
  return true;
3226
3375
  });
@@ -3236,15 +3385,15 @@ function bindBeforeSaveTemplateAction() {
3236
3385
  }));
3237
3386
  }
3238
3387
  function isDirty() {
3239
- return selectIsDirty((0, import_store26.__getState)());
3388
+ return selectIsDirty((0, import_store30.__getState)());
3240
3389
  }
3241
3390
 
3242
3391
  // src/sync-with-document.tsx
3243
3392
  function SyncWithDocumentSave() {
3244
3393
  const { open: openClassPanel } = usePanelActions();
3245
3394
  (0, import_react14.useEffect)(() => {
3246
- const unsubscribe = (0, import_editor_v1_adapters6.__privateListenTo)((0, import_editor_v1_adapters6.v1ReadyEvent)(), () => {
3247
- const open = (0, import_editor_v1_adapters6.isExperimentActive)("e_editor_design_system_panel") ? () => {
3395
+ const unsubscribe = (0, import_editor_v1_adapters7.__privateListenTo)((0, import_editor_v1_adapters7.v1ReadyEvent)(), () => {
3396
+ const open = (0, import_editor_v1_adapters7.isExperimentActive)("e_editor_design_system_panel") ? () => {
3248
3397
  window.dispatchEvent(new CustomEvent("elementor/open-global-classes-manager"));
3249
3398
  } : openClassPanel;
3250
3399
  syncWithDocumentSave({ open });
@@ -3256,8 +3405,8 @@ function SyncWithDocumentSave() {
3256
3405
 
3257
3406
  // src/init.ts
3258
3407
  function init() {
3259
- (0, import_store28.__registerSlice)(slice);
3260
- if (!(0, import_editor_v1_adapters7.isExperimentActive)("e_editor_design_system_panel")) {
3408
+ (0, import_store32.__registerSlice)(slice);
3409
+ if (!(0, import_editor_v1_adapters8.isExperimentActive)("e_editor_design_system_panel")) {
3261
3410
  (0, import_editor_panels2.__registerPanel)(panel);
3262
3411
  }
3263
3412
  import_editor_styles_repository5.stylesRepository.register(globalClassesStylesProvider);
@@ -3277,7 +3426,7 @@ function init() {
3277
3426
  id: "global-classes-prefetch-css-class-usage",
3278
3427
  component: PrefetchCssClassUsage
3279
3428
  });
3280
- if (!(0, import_editor_v1_adapters7.isExperimentActive)("e_editor_design_system_panel")) {
3429
+ if (!(0, import_editor_v1_adapters8.isExperimentActive)("e_editor_design_system_panel")) {
3281
3430
  (0, import_editor.injectIntoLogic)({
3282
3431
  id: "global-classes-open-panel-from-url",
3283
3432
  component: OpenPanelFromUrl
@@ -3304,6 +3453,9 @@ function init() {
3304
3453
  0 && (module.exports = {
3305
3454
  ClassManagerPanelEmbedded,
3306
3455
  GLOBAL_CLASSES_URI,
3307
- init
3456
+ addDocumentClasses,
3457
+ createLabelsForClasses,
3458
+ init,
3459
+ loadExistingClasses
3308
3460
  });
3309
3461
  //# sourceMappingURL=index.js.map