@elementor/editor-global-classes 0.11.0 → 0.12.0

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.mjs CHANGED
@@ -9,7 +9,7 @@ import { __registerSlice as registerSlice } from "@elementor/store";
9
9
  // src/components/class-manager/class-manager-button.tsx
10
10
  import * as React8 from "react";
11
11
  import {
12
- __useActiveDocument as useActiveDocument,
12
+ __useActiveDocument as useActiveDocument2,
13
13
  __useActiveDocumentActions as useActiveDocumentActions
14
14
  } from "@elementor/editor-documents";
15
15
  import { IconButton as IconButton3, Tooltip as Tooltip2 } from "@elementor/ui";
@@ -17,7 +17,12 @@ import { __ as __6 } from "@wordpress/i18n";
17
17
 
18
18
  // src/components/class-manager/class-manager-panel.tsx
19
19
  import * as React7 from "react";
20
- import { useEffect } from "react";
20
+ import { useEffect, useState as useState4 } from "react";
21
+ import {
22
+ __useActiveDocument as useActiveDocument,
23
+ getDocumentModifiedStatus,
24
+ setDocumentModifiedStatus
25
+ } from "@elementor/editor-documents";
21
26
  import {
22
27
  __createPanel as createPanel,
23
28
  Panel,
@@ -28,6 +33,7 @@ import {
28
33
  } from "@elementor/editor-panels";
29
34
  import { changeEditMode } from "@elementor/editor-v1-adapters";
30
35
  import { XIcon } from "@elementor/icons";
36
+ import { useMutation } from "@elementor/query";
31
37
  import { Alert, Box as Box4, Button as Button3, ErrorBoundary, IconButton as IconButton2, Stack as Stack3 } from "@elementor/ui";
32
38
  import { __ as __5 } from "@wordpress/i18n";
33
39
 
@@ -129,32 +135,44 @@ var useDirtyState = () => {
129
135
  return useSelector(selectIsDirty);
130
136
  };
131
137
 
132
- // src/publish-global-classes.ts
138
+ // src/save-global-classes.ts
133
139
  import { __dispatch as dispatch, __getState as getState } from "@elementor/store";
134
140
 
135
141
  // src/api.ts
136
142
  import { httpService } from "@elementor/http";
137
143
  var RESOURCE_URL = "/global-classes";
138
144
  var apiClient = {
139
- all: () => httpService().get("elementor/v1" + RESOURCE_URL),
140
- update: (payload) => httpService().put("elementor/v1" + RESOURCE_URL, payload)
145
+ all: () => httpService().get("elementor/v1" + RESOURCE_URL, {
146
+ params: {
147
+ context: "preview"
148
+ }
149
+ }),
150
+ publish: (payload) => httpService().put("elementor/v1" + RESOURCE_URL, payload, {
151
+ params: {
152
+ context: "frontend"
153
+ }
154
+ }),
155
+ saveDraft: (payload) => httpService().put("elementor/v1" + RESOURCE_URL, payload, {
156
+ params: {
157
+ context: "preview"
158
+ }
159
+ })
141
160
  };
142
161
 
143
- // src/publish-global-classes.ts
144
- async function publishGlobalClasses() {
145
- if (!isDirty()) {
146
- return;
147
- }
162
+ // src/save-global-classes.ts
163
+ async function saveGlobalClasses({ context: context2 }) {
148
164
  const state = getState().globalClasses;
149
- await apiClient.update({
165
+ const data = {
150
166
  items: state.items,
151
167
  order: state.order
152
- });
168
+ };
169
+ if (context2 === "preview") {
170
+ await apiClient.saveDraft(data);
171
+ return;
172
+ }
173
+ await apiClient.publish(data);
153
174
  dispatch(slice.actions.setPristine());
154
175
  }
155
- function isDirty() {
156
- return selectIsDirty(getState());
157
- }
158
176
 
159
177
  // src/components/class-manager/class-manager-introduction.tsx
160
178
  import * as React from "react";
@@ -183,7 +201,14 @@ var ClassManagerIntroduction = () => {
183
201
  );
184
202
  };
185
203
  var IntroductionContent = () => {
186
- return /* @__PURE__ */ React.createElement(Stack, { gap: 1.5, padding: 3 }, /* @__PURE__ */ React.createElement(Image, { sx: { width: "100%", height: "312px" }, src: "", alt: "Introduction" }), /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Typography, { variant: "body2" }, __(
204
+ return /* @__PURE__ */ React.createElement(Stack, { gap: 1.5, padding: 3 }, /* @__PURE__ */ React.createElement(
205
+ Image,
206
+ {
207
+ sx: { width: "100%", height: "312px" },
208
+ src: "https://assets.elementor.com/packages/v1/images/class-manager-intro.svg",
209
+ alt: ""
210
+ }
211
+ ), /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(Typography, { variant: "body2" }, __(
187
212
  "The CSS Class Manager allows you to manage and organize your site's CSS classes efficiently. You can reorder classes to adjust their priority, rename them to maintain clarity in your design system, and delete unused classes to keep your CSS structured.",
188
213
  "elementor"
189
214
  )), /* @__PURE__ */ React.createElement("br", null), /* @__PURE__ */ React.createElement(Typography, { variant: "body2" }, __(
@@ -208,7 +233,6 @@ import {
208
233
  Box as Box3,
209
234
  IconButton,
210
235
  List,
211
- ListItem,
212
236
  ListItemButton,
213
237
  ListItemText,
214
238
  Menu,
@@ -345,13 +369,12 @@ import * as React4 from "react";
345
369
  import { GripVerticalIcon } from "@elementor/icons";
346
370
  import {
347
371
  Box as Box2,
348
- Paper,
349
372
  styled,
350
373
  UnstableSortableItem,
351
374
  UnstableSortableProvider
352
375
  } from "@elementor/ui";
353
376
  var SortableProvider = (props) => /* @__PURE__ */ React4.createElement(UnstableSortableProvider, { restrictAxis: true, variant: "static", dragPlaceholderStyle: { opacity: "1" }, ...props });
354
- var SortableTrigger = (props) => /* @__PURE__ */ React4.createElement("div", { ...props, role: "button", className: "class-item-sortable-trigger" }, /* @__PURE__ */ React4.createElement(GripVerticalIcon, { fontSize: "tiny" }));
377
+ var SortableTrigger = (props) => /* @__PURE__ */ React4.createElement(StyledSortableTrigger, { ...props, role: "button", className: "class-item-sortable-trigger" }, /* @__PURE__ */ React4.createElement(GripVerticalIcon, { fontSize: "tiny" }));
355
378
  var SortableItem = ({ children, id: id2, ...props }) => {
356
379
  return /* @__PURE__ */ React4.createElement(
357
380
  UnstableSortableItem,
@@ -370,55 +393,45 @@ var SortableItem = ({ children, id: id2, ...props }) => {
370
393
  isDragPlaceholder
371
394
  }) => {
372
395
  return /* @__PURE__ */ React4.createElement(
373
- StyledSortableItem,
396
+ Box2,
374
397
  {
375
398
  ...itemProps,
376
- sx: itemStyle,
399
+ style: itemStyle,
400
+ component: "li",
377
401
  role: "listitem",
378
- ...isDragOverlay ? { component: Paper, elevation: 0 } : {}
402
+ sx: {
403
+ backgroundColor: isDragOverlay ? "background.paper" : void 0
404
+ }
379
405
  },
380
- /* @__PURE__ */ React4.createElement(SortableTrigger, { ...triggerProps, style: triggerStyle }),
381
406
  children({
382
407
  itemProps,
383
408
  isDragged,
384
409
  triggerProps,
385
410
  itemStyle,
386
411
  triggerStyle,
387
- dropIndicationStyle,
388
- showDropIndication,
389
412
  isDragPlaceholder
390
- })
413
+ }),
414
+ showDropIndication && /* @__PURE__ */ React4.createElement(SortableItemIndicator, { style: dropIndicationStyle })
391
415
  );
392
416
  }
393
417
  }
394
418
  );
395
419
  };
396
- var StyledSortableItem = styled(Box2)`
397
- position: relative;
398
-
399
- &:hover {
400
- & .class-item-sortable-trigger {
401
- visibility: visible;
402
- }
403
- }
404
-
405
- & .class-item-sortable-trigger {
406
- visibility: hidden;
407
- position: absolute;
408
- left: 0;
409
- top: 50%;
410
- transform: translate( -75%, -50% );
411
- }
412
- `;
420
+ var StyledSortableTrigger = styled("div")(({ theme }) => ({
421
+ position: "absolute",
422
+ left: 0,
423
+ top: "50%",
424
+ transform: `translate( -${theme.spacing(1.5)}, -50% )`,
425
+ color: theme.palette.action.active
426
+ }));
413
427
  var SortableItemIndicator = styled(Box2)`
414
428
  width: 100%;
415
- height: 3px;
416
- border-radius: ${({ theme }) => theme.spacing(0.5)};
429
+ height: 1px;
417
430
  background-color: ${({ theme }) => theme.palette.text.primary};
418
431
  `;
419
432
 
420
433
  // src/components/class-manager/global-classes-list.tsx
421
- var GlobalClassesList = () => {
434
+ var GlobalClassesList = ({ disabled }) => {
422
435
  const cssClasses = useOrderedClasses();
423
436
  const [classesOrder, reorderClasses] = useReorder();
424
437
  if (!cssClasses?.length) {
@@ -428,16 +441,16 @@ var GlobalClassesList = () => {
428
441
  const renameClass = (newLabel) => {
429
442
  globalClassesStylesProvider.actions.update({ label: newLabel, id: id2 });
430
443
  };
431
- return /* @__PURE__ */ React5.createElement(SortableItem, { key: id2, id: id2 }, ({ isDragged, showDropIndication, dropIndicationStyle, isDragPlaceholder }) => /* @__PURE__ */ React5.createElement(
444
+ return /* @__PURE__ */ React5.createElement(SortableItem, { key: id2, id: id2 }, ({ isDragged, isDragPlaceholder, triggerProps, triggerStyle }) => /* @__PURE__ */ React5.createElement(
432
445
  ClassItem,
433
446
  {
434
447
  id: id2,
435
448
  label,
436
449
  renameClass,
437
450
  selected: isDragged,
438
- disabled: isDragPlaceholder
439
- },
440
- showDropIndication && /* @__PURE__ */ React5.createElement(SortableItemIndicator, { style: dropIndicationStyle })
451
+ disabled: disabled || isDragPlaceholder,
452
+ sortableTriggerProps: { ...triggerProps, style: triggerStyle }
453
+ }
441
454
  ));
442
455
  }))));
443
456
  };
@@ -448,14 +461,7 @@ var useReorder = () => {
448
461
  };
449
462
  return [order, reorder];
450
463
  };
451
- var ClassItem = ({
452
- id: id2,
453
- label,
454
- renameClass,
455
- selected,
456
- children,
457
- disabled
458
- }) => {
464
+ var ClassItem = ({ id: id2, label, renameClass, selected, disabled, sortableTriggerProps }) => {
459
465
  const {
460
466
  ref: editableRef,
461
467
  openEditMode,
@@ -472,99 +478,100 @@ var ClassItem = ({
472
478
  variant: "popover",
473
479
  disableAutoFocus: true
474
480
  });
475
- return /* @__PURE__ */ React5.createElement(Stack2, { direction: "row", alignItems: "center", gap: 1, flexGrow: 1, flexShrink: 0 }, /* @__PURE__ */ React5.createElement(
476
- StyledListItem,
481
+ const isSelected = (selected || popupState.isOpen) && !disabled;
482
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
483
+ StyledListItemButton,
477
484
  {
478
- component: "div",
479
- disablePadding: true,
485
+ dense: true,
480
486
  disableGutters: true,
481
- secondaryAction: /* @__PURE__ */ React5.createElement(
482
- Tooltip,
483
- {
484
- placement: "top",
485
- className: "class-item-more-actions",
486
- title: __4("More actions", "elementor")
487
- },
488
- /* @__PURE__ */ React5.createElement(IconButton, { size: "tiny", ...bindTrigger(popupState), "aria-label": "More actions" }, /* @__PURE__ */ React5.createElement(DotsVerticalIcon, { fontSize: "tiny" }))
489
- )
487
+ showActions: isSelected || isEditing,
488
+ shape: "rounded",
489
+ onDoubleClick: openEditMode,
490
+ selected: isSelected,
491
+ disabled,
492
+ focusVisibleClassName: "visible-class-item"
490
493
  },
494
+ /* @__PURE__ */ React5.createElement(SortableTrigger, { ...sortableTriggerProps }),
495
+ /* @__PURE__ */ React5.createElement(Indicator, { isActive: isEditing, isError: !!error }, isEditing ? /* @__PURE__ */ React5.createElement(
496
+ EditableField,
497
+ {
498
+ ref: editableRef,
499
+ error,
500
+ as: Typography3,
501
+ variant: "caption",
502
+ ...getEditableProps()
503
+ }
504
+ ) : /* @__PURE__ */ React5.createElement(EllipsisWithTooltip, { title: label, as: Typography3, variant: "caption" })),
491
505
  /* @__PURE__ */ React5.createElement(
492
- ListItemButton,
506
+ Tooltip,
493
507
  {
494
- dense: true,
495
- disableGutters: true,
496
- shape: "rounded",
497
- onDoubleClick: openEditMode,
498
- selected: selected || popupState.isOpen,
499
- disabled,
500
- focusVisibleClassName: "visible-class-item",
501
- sx: {
502
- minHeight: "36px",
503
- display: "flex",
504
- "&.visible-class-item": {
505
- boxShadow: "none !important"
506
- }
507
- }
508
+ placement: "top",
509
+ className: "class-item-more-actions",
510
+ title: __4("More actions", "elementor")
508
511
  },
509
- /* @__PURE__ */ React5.createElement(Indicator, { isActive: isEditing, isError: !!error }, isEditing ? /* @__PURE__ */ React5.createElement(
510
- EditableField,
511
- {
512
- ref: editableRef,
513
- error,
514
- as: Typography3,
515
- variant: "caption",
516
- ...getEditableProps()
512
+ /* @__PURE__ */ React5.createElement(IconButton, { size: "tiny", ...bindTrigger(popupState), "aria-label": "More actions" }, /* @__PURE__ */ React5.createElement(DotsVerticalIcon, { fontSize: "tiny" }))
513
+ )
514
+ ), /* @__PURE__ */ React5.createElement(
515
+ Menu,
516
+ {
517
+ ...bindMenu(popupState),
518
+ anchorOrigin: {
519
+ vertical: "bottom",
520
+ horizontal: "right"
521
+ },
522
+ transformOrigin: {
523
+ vertical: "top",
524
+ horizontal: "right"
525
+ }
526
+ },
527
+ /* @__PURE__ */ React5.createElement(
528
+ MenuItem,
529
+ {
530
+ sx: { minWidth: "160px" },
531
+ onClick: () => {
532
+ popupState.close();
533
+ openEditMode();
517
534
  }
518
- ) : /* @__PURE__ */ React5.createElement(EllipsisWithTooltip, { title: label, as: Typography3, variant: "caption" }))
535
+ },
536
+ /* @__PURE__ */ React5.createElement(ListItemText, { primary: __4("Rename", "elementor") })
519
537
  ),
520
- children,
521
538
  /* @__PURE__ */ React5.createElement(
522
- Menu,
539
+ MenuItem,
523
540
  {
524
- ...bindMenu(popupState),
525
- anchorOrigin: {
526
- vertical: "bottom",
527
- horizontal: "right"
528
- },
529
- transformOrigin: {
530
- vertical: "top",
531
- horizontal: "right"
541
+ onClick: () => {
542
+ popupState.close();
543
+ openDialog({ id: id2, label });
532
544
  }
533
545
  },
534
- /* @__PURE__ */ React5.createElement(
535
- MenuItem,
536
- {
537
- sx: { minWidth: "160px" },
538
- onClick: () => {
539
- popupState.close();
540
- openEditMode();
541
- }
542
- },
543
- /* @__PURE__ */ React5.createElement(ListItemText, { primary: __4("Rename", "elementor") })
544
- ),
545
- /* @__PURE__ */ React5.createElement(
546
- MenuItem,
547
- {
548
- onClick: () => {
549
- popupState.close();
550
- openDialog({ id: id2, label });
551
- }
552
- },
553
- /* @__PURE__ */ React5.createElement(ListItemText, { primary: __4("Delete", "elementor"), sx: { color: "error.light" } })
554
- )
546
+ /* @__PURE__ */ React5.createElement(ListItemText, { primary: __4("Delete", "elementor"), sx: { color: "error.light" } })
555
547
  )
556
548
  ));
557
549
  };
558
- var StyledListItem = styled2(ListItem)`
559
- .class-item-more-actions {
560
- visibility: hidden;
550
+ var StyledListItemButton = styled2(ListItemButton, {
551
+ shouldForwardProp: (prop) => !["showActions"].includes(prop)
552
+ })(
553
+ ({ showActions }) => `
554
+ min-height: 36px;
555
+
556
+ &.visible-class-item {
557
+ box-shadow: none !important;
558
+ }
559
+
560
+ .class-item-more-actions, .class-item-sortable-trigger {
561
+ visibility: ${showActions ? "visible" : "hidden"};
562
+ }
563
+
564
+ .class-item-sortable-trigger {
565
+ visibility: ${showActions ? "visible" : "hidden"};
561
566
  }
562
- &:hover {
563
- .class-item-more-actions {
567
+
568
+ &:hover&:not(:disabled) {
569
+ .class-item-more-actions, .class-item-sortable-trigger {
564
570
  visibility: visible;
565
571
  }
566
572
  }
567
- `;
573
+ `
574
+ );
568
575
  var EmptyState = () => /* @__PURE__ */ React5.createElement(Stack2, { alignItems: "center", gap: 1.5, pt: 10, px: 0.5, maxWidth: "260px", margin: "auto" }, /* @__PURE__ */ React5.createElement(FlippedColorSwatchIcon, { fontSize: "large" }), /* @__PURE__ */ React5.createElement(StyledHeader, { variant: "subtitle2", component: "h2", color: "text.secondary" }, __4("There are no global classes yet.", "elementor")), /* @__PURE__ */ React5.createElement(Typography3, { align: "center", variant: "caption", color: "text.secondary" }, __4(
569
576
  "CSS classes created in the editor panel will appear here. Once they are available, you can arrange their hierarchy, rename them, or delete them as needed.",
570
577
  "elementor"
@@ -583,7 +590,8 @@ var Indicator = styled2(Box3, {
583
590
  borderRadius: theme.spacing(0.5),
584
591
  border: getIndicatorBorder({ isActive, isError, theme }),
585
592
  padding: `0 ${theme.spacing(1)}`,
586
- marginLeft: isActive ? theme.spacing(1) : 0
593
+ marginLeft: isActive ? theme.spacing(1) : 0,
594
+ minWidth: 0
587
595
  }));
588
596
  var getIndicatorBorder = ({ isActive, isError, theme }) => {
589
597
  if (isError) {
@@ -647,36 +655,46 @@ var id = "global-classes-manager";
647
655
  var { panel, usePanelActions } = createPanel({
648
656
  id,
649
657
  component: ClassManagerPanel,
650
- onOpen: () => changeEditMode(id),
651
- onClose: () => changeEditMode("edit"),
652
- allowedEditModes: ["edit", id]
658
+ allowedEditModes: ["edit", id],
659
+ onOpen: () => {
660
+ changeEditMode(id);
661
+ return getDocumentModifiedStatus();
662
+ },
663
+ onClose: (documentModifiedState) => {
664
+ changeEditMode("edit");
665
+ if (getDocumentModifiedStatus() !== documentModifiedState) {
666
+ setDocumentModifiedStatus(documentModifiedState);
667
+ }
668
+ }
653
669
  });
654
670
  function ClassManagerPanel() {
655
- const isDirty3 = useDirtyState();
671
+ const isDirty2 = useDirtyState();
656
672
  const { close: closePanel } = usePanelActions();
657
673
  const { open: openSaveChangesDialog, close: closeSaveChangesDialog, isOpen: isSaveChangesDialogOpen } = useDialog();
674
+ const { mutateAsync: publish, isPending: isPublishing } = usePublish();
658
675
  usePreventUnload();
659
676
  return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(ErrorBoundary, { fallback: /* @__PURE__ */ React7.createElement(ErrorBoundaryFallback, null) }, /* @__PURE__ */ React7.createElement(Panel, null, /* @__PURE__ */ React7.createElement(PanelHeader, null, /* @__PURE__ */ React7.createElement(Stack3, { p: 1, pl: 2, width: "100%", direction: "row", alignItems: "center" }, /* @__PURE__ */ React7.createElement(PanelHeaderTitle, { sx: { display: "flex", alignItems: "center", gap: 0.5 } }, /* @__PURE__ */ React7.createElement(FlippedColorSwatchIcon, { fontSize: "inherit" }), __5("CSS Class manager", "elementor")), /* @__PURE__ */ React7.createElement(
660
677
  CloseButton,
661
678
  {
662
679
  sx: { marginLeft: "auto" },
663
680
  onClose: () => {
664
- if (isDirty3) {
681
+ if (isDirty2) {
665
682
  openSaveChangesDialog();
666
683
  return;
667
684
  }
668
685
  closePanel();
669
686
  }
670
687
  }
671
- ))), /* @__PURE__ */ React7.createElement(PanelBody, { px: 2 }, /* @__PURE__ */ React7.createElement(GlobalClassesList, null)), /* @__PURE__ */ React7.createElement(PanelFooter, null, /* @__PURE__ */ React7.createElement(
688
+ ))), /* @__PURE__ */ React7.createElement(PanelBody, { px: 2 }, /* @__PURE__ */ React7.createElement(GlobalClassesList, { disabled: isPublishing })), /* @__PURE__ */ React7.createElement(PanelFooter, null, /* @__PURE__ */ React7.createElement(
672
689
  Button3,
673
690
  {
674
691
  fullWidth: true,
675
692
  size: "small",
676
- variant: "contained",
677
693
  color: "global",
678
- disabled: !isDirty3,
679
- onClick: publishGlobalClasses
694
+ variant: "contained",
695
+ onClick: publish,
696
+ disabled: !isDirty2,
697
+ loading: isPublishing
680
698
  },
681
699
  __5("Save changes", "elementor")
682
700
  )))), /* @__PURE__ */ React7.createElement(ClassManagerIntroduction, null), isSaveChangesDialogOpen && /* @__PURE__ */ React7.createElement(SaveChangesDialog, null, /* @__PURE__ */ React7.createElement(SaveChangesDialog.Title, null, __5("You have unsaved changes", "elementor")), /* @__PURE__ */ React7.createElement(SaveChangesDialog.Content, null, /* @__PURE__ */ React7.createElement(SaveChangesDialog.ContentText, null, __5("You have unsaved changes in the Class Manager.", "elementor")), /* @__PURE__ */ React7.createElement(SaveChangesDialog.ContentText, null, __5("To avoid losing your updates, save your changes before leaving.", "elementor"))), /* @__PURE__ */ React7.createElement(
@@ -690,7 +708,7 @@ function ClassManagerPanel() {
690
708
  confirm: {
691
709
  label: __5("Save & Continue", "elementor"),
692
710
  action: async () => {
693
- await publishGlobalClasses();
711
+ await publish();
694
712
  closeSaveChangesDialog();
695
713
  closePanel();
696
714
  }
@@ -702,10 +720,10 @@ function ClassManagerPanel() {
702
720
  var CloseButton = ({ onClose, ...props }) => /* @__PURE__ */ React7.createElement(IconButton2, { size: "small", color: "secondary", onClick: onClose, "aria-label": "Close", ...props }, /* @__PURE__ */ React7.createElement(XIcon, { fontSize: "small" }));
703
721
  var ErrorBoundaryFallback = () => /* @__PURE__ */ React7.createElement(Box4, { role: "alert", sx: { minHeight: "100%", p: 2 } }, /* @__PURE__ */ React7.createElement(Alert, { severity: "error", sx: { mb: 2, maxWidth: 400, textAlign: "center" } }, /* @__PURE__ */ React7.createElement("strong", null, __5("Something went wrong", "elementor"))));
704
722
  var usePreventUnload = () => {
705
- const isDirty3 = useDirtyState();
723
+ const isDirty2 = useDirtyState();
706
724
  useEffect(() => {
707
725
  const handleBeforeUnload = (event) => {
708
- if (isDirty3) {
726
+ if (isDirty2) {
709
727
  event.preventDefault();
710
728
  }
711
729
  };
@@ -713,12 +731,24 @@ var usePreventUnload = () => {
713
731
  return () => {
714
732
  window.removeEventListener("beforeunload", handleBeforeUnload);
715
733
  };
716
- }, [isDirty3]);
734
+ }, [isDirty2]);
735
+ };
736
+ var usePublish = () => {
737
+ const document = useActiveDocument();
738
+ const [initialDocumentStatus] = useState4(document?.isDirty ?? false);
739
+ return useMutation({
740
+ mutationFn: () => saveGlobalClasses({ context: "frontend" }),
741
+ onSuccess: () => {
742
+ if (initialDocumentStatus !== document?.isDirty) {
743
+ setDocumentModifiedStatus(initialDocumentStatus);
744
+ }
745
+ }
746
+ });
717
747
  };
718
748
 
719
749
  // src/components/class-manager/class-manager-button.tsx
720
750
  var ClassManagerButton = () => {
721
- const document = useActiveDocument();
751
+ const document = useActiveDocument2();
722
752
  const { open: openPanel } = usePanelActions();
723
753
  const { save: saveDocument } = useActiveDocumentActions();
724
754
  const { open: openSaveChangesDialog, close: closeSaveChangesDialog, isOpen: isSaveChangesDialogOpen } = useDialog();
@@ -768,7 +798,8 @@ function PopulateStore() {
768
798
  }
769
799
 
770
800
  // src/sync-with-document-save.ts
771
- import { __privateRunCommandSync as runCommandSync, registerDataHook } from "@elementor/editor-v1-adapters";
801
+ import { setDocumentModifiedStatus as setDocumentModifiedStatus2 } from "@elementor/editor-documents";
802
+ import { registerDataHook } from "@elementor/editor-v1-adapters";
772
803
  import { __getState as getState3, __subscribeWithSelector as subscribeWithSelector2 } from "@elementor/store";
773
804
  function syncWithDocumentSave() {
774
805
  const unsubscribe = syncDirtyState();
@@ -777,16 +808,20 @@ function syncWithDocumentSave() {
777
808
  }
778
809
  function syncDirtyState() {
779
810
  return subscribeWithSelector2(selectIsDirty, () => {
780
- if (!isDirty2()) {
811
+ if (!isDirty()) {
781
812
  return;
782
813
  }
783
- runCommandSync("document/save/set-is-modified", { status: true }, { internal: true });
814
+ setDocumentModifiedStatus2(true);
784
815
  });
785
816
  }
786
817
  function bindSaveAction() {
787
- registerDataHook("after", "document/save/save", publishGlobalClasses);
818
+ registerDataHook("after", "document/save/save", (args) => {
819
+ return saveGlobalClasses({
820
+ context: args.status === "publish" ? "frontend" : "preview"
821
+ });
822
+ });
788
823
  }
789
- function isDirty2() {
824
+ function isDirty() {
790
825
  return selectIsDirty(getState3());
791
826
  }
792
827