@elementor/editor-default-styles 4.3.0-1049 → 4.3.0-1051

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
@@ -30,25 +30,45 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ DefaultStylesTabEmbedded: () => DefaultStylesTabEmbedded,
33
34
  init: () => init
34
35
  });
35
36
  module.exports = __toCommonJS(index_exports);
36
37
 
37
- // src/init.ts
38
- var import_editor = require("@elementor/editor");
39
- var import_editor_app_bar = require("@elementor/editor-app-bar");
40
- var import_editor_editing_panel3 = require("@elementor/editor-editing-panel");
41
- var import_editor_panels3 = require("@elementor/editor-panels");
42
- var import_editor_styles_repository2 = require("@elementor/editor-styles-repository");
43
- var import_store12 = require("@elementor/store");
44
-
45
- // src/components/populate-store.tsx
46
- var import_react = require("react");
47
- var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
38
+ // src/components/default-styles-tab-embedded.tsx
39
+ var React3 = __toESM(require("react"));
40
+ var import_react2 = require("react");
41
+ var import_editor_controls = require("@elementor/editor-controls");
42
+ var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
43
+ var import_editor_responsive = require("@elementor/editor-responsive");
44
+ var import_editor_ui = require("@elementor/editor-ui");
45
+ var import_menus = require("@elementor/menus");
46
+ var import_query = require("@elementor/query");
47
+ var import_session = require("@elementor/session");
48
48
  var import_store4 = require("@elementor/store");
49
+ var import_ui3 = require("@elementor/ui");
50
+ var import_i18n2 = require("@wordpress/i18n");
49
51
 
50
- // src/load-default-styles.ts
52
+ // src/allowed-tags.ts
53
+ var getElementorConfig = () => window.elementor?.config ?? {};
54
+ var getAllowedDefaultStyleTags = () => {
55
+ const tags = getElementorConfig().atomic?.default_styles?.allowed_tags;
56
+ if (!tags?.length) {
57
+ return [];
58
+ }
59
+ return tags;
60
+ };
61
+ var getDefaultActiveTag = (tags) => {
62
+ if (tags.includes("h1")) {
63
+ return "h1";
64
+ }
65
+ return tags[0] ?? "";
66
+ };
67
+ var isAllowedDefaultStyleTag = (tag, tags = getAllowedDefaultStyleTags()) => tags.includes(tag);
68
+
69
+ // src/save-default-styles.ts
51
70
  var import_store2 = require("@elementor/store");
71
+ var import_utils = require("@elementor/utils");
52
72
 
53
73
  // src/api.ts
54
74
  var import_http_client = require("@elementor/http-client");
@@ -109,8 +129,7 @@ var slice = (0, import_store.__createSlice)({
109
129
  if (mode === "replace") {
110
130
  variant.props = payloadProps;
111
131
  } else {
112
- const variantProps = JSON.parse(JSON.stringify(variant.props));
113
- variant.props = { ...variantProps, ...payloadProps };
132
+ variant.props = { ...variant.props, ...payloadProps };
114
133
  }
115
134
  variant.custom_css = customCss;
116
135
  } else {
@@ -124,11 +143,11 @@ var slice = (0, import_store.__createSlice)({
124
143
  state.isDirty = true;
125
144
  },
126
145
  reset(state) {
127
- state.data = structuredClone(state.initialData);
146
+ state.data = state.initialData;
128
147
  state.isDirty = false;
129
148
  },
130
149
  commit(state) {
131
- state.initialData = structuredClone(state.data);
150
+ state.initialData = state.data;
132
151
  state.isDirty = false;
133
152
  },
134
153
  deleteTag(state, { payload }) {
@@ -154,96 +173,7 @@ var selectTagStyle = (0, import_store.__createSelector)(
154
173
  (data, id) => data[id]
155
174
  );
156
175
 
157
- // src/load-default-styles.ts
158
- async function loadDefaultStyles() {
159
- const response = await apiClient.all();
160
- const items = response.data.data;
161
- (0, import_store2.__dispatch)(
162
- slice.actions.load({
163
- data: items
164
- })
165
- );
166
- }
167
-
168
- // src/components/populate-store.tsx
169
- var V2_PANEL_ROUTE = "panel/v2";
170
- function PopulateStore() {
171
- (0, import_react.useEffect)(() => {
172
- void loadDefaultStyles();
173
- (0, import_editor_v1_adapters.registerDataHook)("after", "editor/documents/attach-preview", async () => {
174
- if (selectIsDirty((0, import_store4.__getState)())) {
175
- return;
176
- }
177
- await loadDefaultStyles();
178
- });
179
- const unsubscribe = (0, import_editor_v1_adapters.__privateListenTo)((0, import_editor_v1_adapters.routeCloseEvent)(V2_PANEL_ROUTE), () => {
180
- if (selectIsDirty((0, import_store4.__getState)())) {
181
- return;
182
- }
183
- void loadDefaultStyles();
184
- });
185
- return unsubscribe;
186
- }, []);
187
- return null;
188
- }
189
-
190
- // src/default-styles-open-gate.tsx
191
- var React5 = __toESM(require("react"));
192
- var import_react4 = require("react");
193
- var import_editor_documents = require("@elementor/editor-documents");
194
- var import_editor_ui2 = require("@elementor/editor-ui");
195
- var import_i18n3 = require("@wordpress/i18n");
196
-
197
- // src/default-styles-panel.tsx
198
- var React4 = __toESM(require("react"));
199
- var import_editor_panels2 = require("@elementor/editor-panels");
200
- var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
201
-
202
- // src/components/default-styles-panel-content.tsx
203
- var React3 = __toESM(require("react"));
204
- var import_react3 = require("react");
205
- var import_editor_controls = require("@elementor/editor-controls");
206
- var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
207
- var import_editor_panels = require("@elementor/editor-panels");
208
- var import_editor_responsive = require("@elementor/editor-responsive");
209
- var import_editor_ui = require("@elementor/editor-ui");
210
- var import_menus = require("@elementor/menus");
211
- var import_query = require("@elementor/query");
212
- var import_session = require("@elementor/session");
213
- var import_store8 = require("@elementor/store");
214
- var import_ui3 = require("@elementor/ui");
215
- var import_i18n2 = require("@wordpress/i18n");
216
-
217
- // src/allowed-tags.ts
218
- var getElementorConfig = () => window.elementor?.config ?? {};
219
- var getAllowedDefaultStyleTags = () => {
220
- const tags = getElementorConfig().atomic?.default_styles?.allowed_tags;
221
- if (!tags?.length) {
222
- return [];
223
- }
224
- return tags;
225
- };
226
- var getDefaultActiveTag = (tags) => {
227
- if (tags.includes("h1")) {
228
- return "h1";
229
- }
230
- return tags[0] ?? "";
231
- };
232
- var isAllowedDefaultStyleTag = (tag, tags = getAllowedDefaultStyleTags()) => tags.includes(tag);
233
-
234
- // src/panel-interactions.ts
235
- function blockPanelInteractions() {
236
- const extendedWindow = window;
237
- extendedWindow.$e?.components?.get?.("panel")?.blockUserInteractions?.();
238
- }
239
- function unblockPanelInteractions() {
240
- const extendedWindow = window;
241
- extendedWindow.$e?.components?.get?.("panel")?.unblockUserInteractions?.();
242
- }
243
-
244
176
  // src/save-default-styles.ts
245
- var import_store6 = require("@elementor/store");
246
- var import_utils = require("@elementor/utils");
247
177
  function getChangedTags(state) {
248
178
  const current = selectData(state);
249
179
  const initial = selectInitialData(state);
@@ -263,7 +193,7 @@ function getChangedTags(state) {
263
193
  return changed;
264
194
  }
265
195
  async function saveDefaultStyles() {
266
- const state = (0, import_store6.__getState)();
196
+ const state = (0, import_store2.__getState)();
267
197
  if (!selectIsDirty(state)) {
268
198
  return;
269
199
  }
@@ -279,12 +209,12 @@ async function saveDefaultStyles() {
279
209
  await apiClient.put(tag, style.variants);
280
210
  })
281
211
  );
282
- (0, import_store6.__dispatch)(slice.actions.commit());
212
+ (0, import_store2.__dispatch)(slice.actions.commit());
283
213
  }
284
214
 
285
215
  // src/components/tag-chip.tsx
286
216
  var React2 = __toESM(require("react"));
287
- var import_react2 = require("react");
217
+ var import_react = require("react");
288
218
  var import_icons = require("@elementor/icons");
289
219
  var import_ui2 = require("@elementor/ui");
290
220
  var import_i18n = require("@wordpress/i18n");
@@ -323,7 +253,7 @@ function TagChip({ label, chipProps, activeState, onSelectState }) {
323
253
  variant: "popover",
324
254
  popupId: "tag-state-menu"
325
255
  });
326
- const [chipRef, setChipRef] = (0, import_react2.useState)(null);
256
+ const [chipRef, setChipRef] = (0, import_react.useState)(null);
327
257
  const { onDelete: _onDelete, ...chipGroupProps } = chipProps;
328
258
  const isShowingState = Boolean(activeState);
329
259
  return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
@@ -388,7 +318,7 @@ function TagChip({ label, chipProps, activeState, onSelectState }) {
388
318
  ));
389
319
  }
390
320
 
391
- // src/components/default-styles-panel-content.tsx
321
+ // src/components/default-styles-tab-embedded.tsx
392
322
  var { useMenuItems } = import_menus.controlActionsMenu;
393
323
  var SHIM_ELEMENT_ID = "default-styles-editor-shim";
394
324
  var SHIM_CLASSES_PROP = "__default_styles_classes__";
@@ -416,37 +346,38 @@ var shimElementType = {
416
346
  propsSchema: {},
417
347
  title: (0, import_i18n2.__)("Default Style", "elementor")
418
348
  };
419
- function DefaultStylesPanelContent({ onRequestClose }) {
420
- const allowedTags = (0, import_react3.useMemo)(() => getAllowedDefaultStyleTags(), []);
421
- const tagOptions = (0, import_react3.useMemo)(
349
+ function DefaultStylesTabEmbedded({ onRequestClose, onExposeCloseAttempt }) {
350
+ const allowedTags = (0, import_react2.useMemo)(() => getAllowedDefaultStyleTags(), []);
351
+ const tagOptions = (0, import_react2.useMemo)(
422
352
  () => allowedTags.map((tag) => ({ label: tag, value: tag })),
423
353
  [allowedTags]
424
354
  );
425
- const [selectedTag, setSelectedTagState] = (0, import_react3.useState)(() => readStoredActiveTag(allowedTags));
426
- const [activeStyleState, setActiveStyleState] = (0, import_react3.useState)(null);
355
+ const [selectedTag, setSelectedTagState] = (0, import_react2.useState)(() => readStoredActiveTag(allowedTags));
356
+ const [activeStyleState, setActiveStyleState] = (0, import_react2.useState)(null);
427
357
  const breakpoint = (0, import_editor_responsive.useActiveBreakpoint)();
428
358
  const menuItems = useMenuItems().default;
429
359
  const controlReplacements = (0, import_editor_controls.getControlReplacements)();
430
- const isDirty = (0, import_store8.__useSelector)(selectIsDirty);
360
+ const isDirty = (0, import_store4.__useSelector)(selectIsDirty);
431
361
  const { mutateAsync: save, isPending: isSaving } = useSave();
432
362
  const { open: openSaveChangesDialog, close: closeSaveChangesDialog, isOpen: isSaveChangesDialogOpen } = (0, import_editor_ui.useDialog)();
433
363
  const setSelectedTag = (tag) => {
434
364
  setSelectedTagState(tag);
435
365
  (0, import_session.setSessionStorageItem)(LAST_ACTIVE_TAG_STORAGE_KEY, tag);
436
366
  };
437
- const handleClosePanel = (0, import_react3.useCallback)(() => {
367
+ const handleClosePanel = (0, import_react2.useCallback)(() => {
438
368
  if (isDirty) {
439
369
  openSaveChangesDialog();
440
370
  return;
441
371
  }
442
- onRequestClose();
372
+ void onRequestClose();
443
373
  }, [isDirty, onRequestClose, openSaveChangesDialog]);
444
- (0, import_react3.useEffect)(() => {
445
- blockPanelInteractions();
446
- return () => {
447
- unblockPanelInteractions();
448
- };
449
- }, []);
374
+ (0, import_react2.useEffect)(() => {
375
+ if (!onExposeCloseAttempt) {
376
+ return;
377
+ }
378
+ onExposeCloseAttempt(() => handleClosePanel());
379
+ return () => onExposeCloseAttempt(null);
380
+ }, [onExposeCloseAttempt, handleClosePanel]);
450
381
  usePreventUnload(isDirty);
451
382
  const handleTagSelect = (_selected, reason, option) => {
452
383
  if (reason !== "selectOption" || !option.value) {
@@ -456,9 +387,9 @@ function DefaultStylesPanelContent({ onRequestClose }) {
456
387
  setActiveStyleState(null);
457
388
  };
458
389
  const resetAndClosePanel = () => {
459
- (0, import_store8.__dispatch)(slice.actions.reset());
390
+ (0, import_store4.__dispatch)(slice.actions.reset());
460
391
  closeSaveChangesDialog();
461
- onRequestClose();
392
+ void onRequestClose();
462
393
  };
463
394
  const handleSaveAndContinue = async () => {
464
395
  try {
@@ -467,89 +398,82 @@ function DefaultStylesPanelContent({ onRequestClose }) {
467
398
  return;
468
399
  }
469
400
  closeSaveChangesDialog();
470
- onRequestClose();
401
+ void onRequestClose();
471
402
  };
472
- return /* @__PURE__ */ React3.createElement(import_ui3.ErrorBoundary, { fallback: null }, /* @__PURE__ */ React3.createElement(import_editor_ui.ThemeProvider, null, /* @__PURE__ */ React3.createElement(import_editor_controls.ControlActionsProvider, { items: menuItems }, /* @__PURE__ */ React3.createElement(import_editor_controls.ControlReplacementsProvider, { replacements: controlReplacements }, /* @__PURE__ */ React3.createElement(import_editor_panels.Panel, null, /* @__PURE__ */ React3.createElement(import_editor_panels.PanelHeader, null, /* @__PURE__ */ React3.createElement(
403
+ return /* @__PURE__ */ React3.createElement(import_ui3.ErrorBoundary, { fallback: null }, /* @__PURE__ */ React3.createElement(import_editor_ui.ThemeProvider, null, /* @__PURE__ */ React3.createElement(import_editor_controls.ControlActionsProvider, { items: menuItems }, /* @__PURE__ */ React3.createElement(import_editor_controls.ControlReplacementsProvider, { replacements: controlReplacements }, /* @__PURE__ */ React3.createElement(
473
404
  import_ui3.Stack,
474
405
  {
475
- p: 1,
476
- pl: 2,
477
- width: "100%",
478
- direction: "row",
479
- alignItems: "center",
480
- justifyContent: "space-between",
481
- spacing: 0.5
406
+ sx: {
407
+ flex: 1,
408
+ minHeight: 0,
409
+ overflow: "hidden",
410
+ display: "flex",
411
+ flexDirection: "column"
412
+ }
482
413
  },
483
- /* @__PURE__ */ React3.createElement(import_editor_panels.PanelHeaderTitle, { sx: { flex: 1, minWidth: 0 } }, (0, import_i18n2.__)("Default Styles", "elementor")),
484
- /* @__PURE__ */ React3.createElement(
485
- import_ui3.CloseButton,
414
+ /* @__PURE__ */ React3.createElement(import_ui3.Box, { sx: { flex: 1, minHeight: 0, overflow: "auto" } }, /* @__PURE__ */ React3.createElement(import_ui3.Stack, { sx: { px: 2, pt: 1, gap: 1 } }, /* @__PURE__ */ React3.createElement(import_ui3.FormControl, { fullWidth: true, size: "small" }, /* @__PURE__ */ React3.createElement(import_ui3.FormLabel, { htmlFor: TAG_SELECTOR_ID, size: "small", sx: { mb: 1 } }, (0, import_i18n2.__)("Tag", "elementor")), /* @__PURE__ */ React3.createElement(
415
+ import_editor_editing_panel2.CreatableAutocomplete,
486
416
  {
487
- "aria-label": (0, import_i18n2.__)("Close", "elementor"),
488
- sx: { flexShrink: 0 },
489
- onClick: handleClosePanel
417
+ id: TAG_SELECTOR_ID,
418
+ size: "tiny",
419
+ placeholder: (0, import_i18n2.__)("Type tag name", "elementor"),
420
+ options: tagOptions,
421
+ selected: [toTagChip(selectedTag)],
422
+ onSelect: handleTagSelect,
423
+ renderTags: (values, getTagProps) => values.map((value, index) => /* @__PURE__ */ React3.createElement(
424
+ TagChip,
425
+ {
426
+ key: value.value ?? value.label,
427
+ label: value.label,
428
+ chipProps: getTagProps({ index }),
429
+ activeState: activeStyleState,
430
+ onSelectState: setActiveStyleState
431
+ }
432
+ ))
490
433
  }
491
- )
492
- )), /* @__PURE__ */ React3.createElement(import_editor_panels.PanelBody, null, /* @__PURE__ */ React3.createElement(import_ui3.Stack, { sx: { px: 2, pt: 1, gap: 1 } }, /* @__PURE__ */ React3.createElement(import_ui3.FormControl, { fullWidth: true, size: "small" }, /* @__PURE__ */ React3.createElement(import_ui3.FormLabel, { htmlFor: TAG_SELECTOR_ID, size: "small", sx: { mb: 1 } }, (0, import_i18n2.__)("Tag", "elementor")), /* @__PURE__ */ React3.createElement(
493
- import_editor_editing_panel2.CreatableAutocomplete,
494
- {
495
- id: TAG_SELECTOR_ID,
496
- size: "tiny",
497
- placeholder: (0, import_i18n2.__)("Type tag name", "elementor"),
498
- options: tagOptions,
499
- selected: [toTagChip(selectedTag)],
500
- onSelect: handleTagSelect,
501
- renderTags: (values, getTagProps) => values.map((value, index) => /* @__PURE__ */ React3.createElement(
502
- TagChip,
503
- {
504
- key: value.value ?? value.label,
505
- label: value.label,
506
- chipProps: getTagProps({ index }),
507
- activeState: activeStyleState,
508
- onSelectState: setActiveStyleState
509
- }
510
- ))
511
- }
512
- ))), /* @__PURE__ */ React3.createElement(
513
- import_editor_editing_panel2.ElementProvider,
514
- {
515
- element: shimElement,
516
- elementType: shimElementType,
517
- settings: {}
518
- },
519
- /* @__PURE__ */ React3.createElement(import_editor_editing_panel2.ClassesPropProvider, { prop: SHIM_CLASSES_PROP }, /* @__PURE__ */ React3.createElement(
520
- import_editor_editing_panel2.StyleProvider,
434
+ ))), /* @__PURE__ */ React3.createElement(
435
+ import_editor_editing_panel2.ElementProvider,
521
436
  {
522
- meta: {
523
- breakpoint,
524
- state: activeStyleState
525
- },
526
- id: selectedTag,
527
- setId: () => {
528
- },
529
- setMetaState: setActiveStyleState
437
+ element: shimElement,
438
+ elementType: shimElementType,
439
+ settings: {}
530
440
  },
531
- /* @__PURE__ */ React3.createElement(import_session.SessionStorageProvider, { prefix: selectedTag }, /* @__PURE__ */ React3.createElement(import_editor_editing_panel2.StyleInheritanceProvider, null, /* @__PURE__ */ React3.createElement(import_editor_editing_panel2.SectionsList, null, /* @__PURE__ */ React3.createElement(import_editor_editing_panel2.StyleSections, null)), /* @__PURE__ */ React3.createElement(
532
- import_ui3.Box,
441
+ /* @__PURE__ */ React3.createElement(import_editor_editing_panel2.ClassesPropProvider, { prop: SHIM_CLASSES_PROP }, /* @__PURE__ */ React3.createElement(
442
+ import_editor_editing_panel2.StyleProvider,
533
443
  {
534
- sx: {
535
- height: "150px"
444
+ meta: {
445
+ breakpoint,
446
+ state: activeStyleState
447
+ },
448
+ id: selectedTag,
449
+ setId: () => {
450
+ },
451
+ setMetaState: setActiveStyleState
452
+ },
453
+ /* @__PURE__ */ React3.createElement(import_session.SessionStorageProvider, { prefix: selectedTag }, /* @__PURE__ */ React3.createElement(import_editor_editing_panel2.StyleInheritanceProvider, null, /* @__PURE__ */ React3.createElement(import_editor_editing_panel2.SectionsList, null, /* @__PURE__ */ React3.createElement(import_editor_editing_panel2.StyleSections, null)), /* @__PURE__ */ React3.createElement(
454
+ import_ui3.Box,
455
+ {
456
+ sx: {
457
+ height: "150px"
458
+ }
536
459
  }
537
- }
538
- )))
460
+ )))
461
+ ))
462
+ )),
463
+ /* @__PURE__ */ React3.createElement(import_ui3.Box, { sx: { flexShrink: 0, px: 2, py: 1.5 } }, /* @__PURE__ */ React3.createElement(
464
+ import_ui3.Button,
465
+ {
466
+ fullWidth: true,
467
+ size: "small",
468
+ color: "global",
469
+ variant: "contained",
470
+ onClick: () => void save(),
471
+ disabled: !isDirty,
472
+ loading: isSaving
473
+ },
474
+ (0, import_i18n2.__)("Save changes", "elementor")
539
475
  ))
540
- )), /* @__PURE__ */ React3.createElement(import_editor_panels.PanelFooter, null, /* @__PURE__ */ React3.createElement(
541
- import_ui3.Button,
542
- {
543
- fullWidth: true,
544
- size: "small",
545
- color: "global",
546
- variant: "contained",
547
- onClick: () => void save(),
548
- disabled: !isDirty,
549
- loading: isSaving
550
- },
551
- (0, import_i18n2.__)("Save changes", "elementor")
552
- ))))), isSaveChangesDialogOpen && /* @__PURE__ */ React3.createElement(import_editor_ui.SaveChangesDialog, null, /* @__PURE__ */ React3.createElement(import_editor_ui.SaveChangesDialog.Title, { onClose: closeSaveChangesDialog }, (0, import_i18n2.__)("You have unsaved changes", "elementor")), /* @__PURE__ */ React3.createElement(import_editor_ui.SaveChangesDialog.Content, null, /* @__PURE__ */ React3.createElement(import_editor_ui.SaveChangesDialog.ContentText, null, (0, import_i18n2.__)("You have unsaved changes in Default Styles.", "elementor")), /* @__PURE__ */ React3.createElement(import_editor_ui.SaveChangesDialog.ContentText, null, (0, import_i18n2.__)("To avoid losing your updates, save your changes before leaving.", "elementor"))), /* @__PURE__ */ React3.createElement(
476
+ ))), isSaveChangesDialogOpen && /* @__PURE__ */ React3.createElement(import_editor_ui.SaveChangesDialog, null, /* @__PURE__ */ React3.createElement(import_editor_ui.SaveChangesDialog.Title, { onClose: closeSaveChangesDialog }, (0, import_i18n2.__)("You have unsaved changes", "elementor")), /* @__PURE__ */ React3.createElement(import_editor_ui.SaveChangesDialog.Content, null, /* @__PURE__ */ React3.createElement(import_editor_ui.SaveChangesDialog.ContentText, null, (0, import_i18n2.__)("You have unsaved changes in Default Styles.", "elementor")), /* @__PURE__ */ React3.createElement(import_editor_ui.SaveChangesDialog.ContentText, null, (0, import_i18n2.__)("To avoid losing your updates, save your changes before leaving.", "elementor"))), /* @__PURE__ */ React3.createElement(
553
477
  import_editor_ui.SaveChangesDialog.Actions,
554
478
  {
555
479
  actions: {
@@ -571,7 +495,7 @@ function useSave() {
571
495
  });
572
496
  }
573
497
  function usePreventUnload(isDirty) {
574
- (0, import_react3.useEffect)(() => {
498
+ (0, import_react2.useEffect)(() => {
575
499
  const handleBeforeUnload = (event) => {
576
500
  if (isDirty) {
577
501
  event.preventDefault();
@@ -584,104 +508,56 @@ function usePreventUnload(isDirty) {
584
508
  }, [isDirty]);
585
509
  }
586
510
 
587
- // src/default-styles-panel.tsx
588
- var DEFAULT_STYLES_PANEL_ID = "default-styles";
589
- var { panel, usePanelStatus, usePanelActions } = (0, import_editor_panels2.__createPanel)({
590
- id: DEFAULT_STYLES_PANEL_ID,
591
- component: DefaultStylesPanelRoot,
592
- allowedEditModes: ["edit", DEFAULT_STYLES_PANEL_ID],
593
- onOpen: () => {
594
- (0, import_editor_v1_adapters2.changeEditMode)(DEFAULT_STYLES_PANEL_ID);
595
- },
596
- onClose: async () => {
597
- (0, import_editor_v1_adapters2.changeEditMode)("edit");
598
- },
599
- isOpenPreviousElement: true
600
- });
601
- function DefaultStylesPanelRoot() {
602
- const { close } = usePanelActions();
603
- return /* @__PURE__ */ React4.createElement(
604
- DefaultStylesPanelContent,
605
- {
606
- onRequestClose: () => {
607
- void close();
608
- }
609
- }
511
+ // src/init.ts
512
+ var import_editor = require("@elementor/editor");
513
+ var import_editor_editing_panel3 = require("@elementor/editor-editing-panel");
514
+ var import_editor_styles_repository2 = require("@elementor/editor-styles-repository");
515
+ var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
516
+ var import_store12 = require("@elementor/store");
517
+
518
+ // src/components/populate-store.tsx
519
+ var import_react3 = require("react");
520
+ var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
521
+ var import_store8 = require("@elementor/store");
522
+
523
+ // src/load-default-styles.ts
524
+ var import_store6 = require("@elementor/store");
525
+ async function loadDefaultStyles() {
526
+ const response = await apiClient.all();
527
+ const items = response.data.data;
528
+ (0, import_store6.__dispatch)(
529
+ slice.actions.load({
530
+ data: items
531
+ })
610
532
  );
611
533
  }
612
534
 
613
- // src/default-styles-open-gate.tsx
614
- var EVENT_REQUEST_OPEN_DEFAULT_STYLES = "elementor/default-styles/request-open";
615
- function DefaultStylesOpenGate() {
616
- const { open } = usePanelActions();
617
- const document = (0, import_editor_documents.__useActiveDocument)();
618
- const { save: saveDocument } = (0, import_editor_documents.__useActiveDocumentActions)();
619
- const { open: openSaveDialog, close: closeSaveDialog, isOpen: isSaveDialogOpen } = (0, import_editor_ui2.useDialog)();
620
- const documentRef = (0, import_react4.useRef)(document);
621
- documentRef.current = document;
622
- const pendingOpenRef = (0, import_react4.useRef)(null);
623
- const gatedOpen = (0, import_react4.useCallback)(
624
- (onClean) => {
625
- if (documentRef.current?.isDirty) {
626
- pendingOpenRef.current = onClean;
627
- openSaveDialog();
535
+ // src/components/populate-store.tsx
536
+ var V2_PANEL_ROUTE = "panel/v2";
537
+ function PopulateStore() {
538
+ (0, import_react3.useEffect)(() => {
539
+ void loadDefaultStyles();
540
+ (0, import_editor_v1_adapters.registerDataHook)("after", "editor/documents/attach-preview", async () => {
541
+ if (selectIsDirty((0, import_store8.__getState)())) {
628
542
  return;
629
543
  }
630
- onClean();
631
- },
632
- [openSaveDialog]
633
- );
634
- const handleSaveAndContinue = (0, import_react4.useCallback)(async () => {
635
- try {
636
- await saveDocument();
637
- closeSaveDialog();
638
- pendingOpenRef.current?.();
639
- pendingOpenRef.current = null;
640
- } catch {
641
- }
642
- }, [saveDocument, closeSaveDialog]);
643
- const handleStayHere = (0, import_react4.useCallback)(() => {
644
- closeSaveDialog();
645
- pendingOpenRef.current = null;
646
- }, [closeSaveDialog]);
647
- (0, import_react4.useEffect)(() => {
648
- const handler = () => {
649
- gatedOpen(() => {
650
- void open();
651
- });
652
- };
653
- window.addEventListener(EVENT_REQUEST_OPEN_DEFAULT_STYLES, handler);
654
- return () => {
655
- window.removeEventListener(EVENT_REQUEST_OPEN_DEFAULT_STYLES, handler);
656
- };
657
- }, [gatedOpen, open]);
658
- if (!isSaveDialogOpen) {
659
- return null;
660
- }
661
- return /* @__PURE__ */ React5.createElement(import_editor_ui2.ThemeProvider, null, /* @__PURE__ */ React5.createElement(import_editor_ui2.SaveChangesDialog, null, /* @__PURE__ */ React5.createElement(import_editor_ui2.SaveChangesDialog.Title, null, (0, import_i18n3.__)("You have unsaved changes", "elementor")), /* @__PURE__ */ React5.createElement(import_editor_ui2.SaveChangesDialog.Content, null, /* @__PURE__ */ React5.createElement(import_editor_ui2.SaveChangesDialog.ContentText, { sx: { mb: 2 } }, (0, import_i18n3.__)(
662
- "To open Default Styles, save your page first. You can't continue without saving.",
663
- "elementor"
664
- ))), /* @__PURE__ */ React5.createElement(
665
- import_editor_ui2.SaveChangesDialog.Actions,
666
- {
667
- actions: {
668
- cancel: {
669
- label: (0, import_i18n3.__)("Stay here", "elementor"),
670
- action: handleStayHere
671
- },
672
- confirm: {
673
- label: (0, import_i18n3.__)("Save & Continue", "elementor"),
674
- action: handleSaveAndContinue
675
- }
544
+ await loadDefaultStyles();
545
+ });
546
+ const unsubscribe = (0, import_editor_v1_adapters.__privateListenTo)((0, import_editor_v1_adapters.routeCloseEvent)(V2_PANEL_ROUTE), () => {
547
+ if (selectIsDirty((0, import_store8.__getState)())) {
548
+ return;
676
549
  }
677
- }
678
- )));
550
+ void loadDefaultStyles();
551
+ });
552
+ return unsubscribe;
553
+ }, []);
554
+ return null;
679
555
  }
680
556
 
681
557
  // src/default-styles-provider.ts
682
558
  var import_editor_styles_repository = require("@elementor/editor-styles-repository");
683
559
  var import_store10 = require("@elementor/store");
684
- var import_i18n4 = require("@wordpress/i18n");
560
+ var import_i18n3 = require("@wordpress/i18n");
685
561
  var DEFAULT_STYLES_PROVIDER_KEY = "default-styles";
686
562
  var DEFAULT_STYLES_CSS_NAME_PREFIX = "e-default-";
687
563
  var resolveCssName = (id) => `${DEFAULT_STYLES_CSS_NAME_PREFIX}${id}`;
@@ -699,8 +575,8 @@ var defaultStylesStylesProvider = (0, import_editor_styles_repository.createStyl
699
575
  key: DEFAULT_STYLES_PROVIDER_KEY,
700
576
  priority: 15,
701
577
  labels: {
702
- singular: (0, import_i18n4.__)("tag", "elementor"),
703
- plural: (0, import_i18n4.__)("tags", "elementor")
578
+ singular: (0, import_i18n3.__)("tag", "elementor"),
579
+ plural: (0, import_i18n3.__)("tags", "elementor")
704
580
  },
705
581
  subscribe: (cb) => subscribeWithStates(cb),
706
582
  actions: {
@@ -756,21 +632,12 @@ var subscribeWithStates = (cb) => {
756
632
  );
757
633
  };
758
634
 
759
- // src/hooks/use-default-styles-action-props.ts
760
- var import_icons2 = require("@elementor/icons");
761
- var import_i18n5 = require("@wordpress/i18n");
762
- function useDefaultStylesActionProps() {
763
- return {
764
- title: (0, import_i18n5.__)("Default Styles", "elementor"),
765
- icon: import_icons2.TextIcon,
766
- onClick: () => {
767
- window.dispatchEvent(new CustomEvent(EVENT_REQUEST_OPEN_DEFAULT_STYLES));
768
- }
769
- };
770
- }
771
-
772
635
  // src/init.ts
636
+ var DEFAULT_STYLES_EXPERIMENT = "e_default_styles";
773
637
  function init() {
638
+ if (!(0, import_editor_v1_adapters2.isExperimentActive)(DEFAULT_STYLES_EXPERIMENT)) {
639
+ return;
640
+ }
774
641
  (0, import_store12.__registerSlice)(slice);
775
642
  (0, import_editor_editing_panel3.registerElementPanelDefaults)("default-style", {
776
643
  defaultTab: "style",
@@ -778,24 +645,15 @@ function init() {
778
645
  style: [...import_editor_editing_panel3.STYLE_SECTION_NAMES]
779
646
  }
780
647
  });
781
- (0, import_editor_panels3.__registerPanel)(panel);
782
648
  import_editor_styles_repository2.stylesRepository.register(defaultStylesStylesProvider);
783
- import_editor_app_bar.toolsMenu.registerAction({
784
- id: "default-styles-button",
785
- priority: 4,
786
- useProps: useDefaultStylesActionProps
787
- });
788
649
  (0, import_editor.injectIntoLogic)({
789
650
  id: "default-styles-populate-store",
790
651
  component: PopulateStore
791
652
  });
792
- (0, import_editor.injectIntoLogic)({
793
- id: "default-styles-open-gate",
794
- component: DefaultStylesOpenGate
795
- });
796
653
  }
797
654
  // Annotate the CommonJS export names for ESM import in node:
798
655
  0 && (module.exports = {
656
+ DefaultStylesTabEmbedded,
799
657
  init
800
658
  });
801
659
  //# sourceMappingURL=index.js.map