@elementor/editor-default-styles 4.3.0-1042

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 ADDED
@@ -0,0 +1,800 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ init: () => init
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+
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");
48
+ var import_store4 = require("@elementor/store");
49
+
50
+ // src/load-default-styles.ts
51
+ var import_store2 = require("@elementor/store");
52
+
53
+ // src/api.ts
54
+ var import_http_client = require("@elementor/http-client");
55
+ var RESOURCE_URL = "/default-styles";
56
+ var BASE_URL = "elementor/v1";
57
+ var apiClient = {
58
+ all: () => (0, import_http_client.httpService)().get(`${BASE_URL}${RESOURCE_URL}`),
59
+ put: (tag, variants) => (0, import_http_client.httpService)().put(`${BASE_URL}${RESOURCE_URL}/${tag}`, {
60
+ type: "class",
61
+ variants
62
+ }),
63
+ delete: (tag) => (0, import_http_client.httpService)().delete(`${BASE_URL}${RESOURCE_URL}/${tag}`)
64
+ };
65
+
66
+ // src/store.ts
67
+ var import_editor_styles = require("@elementor/editor-styles");
68
+ var import_store = require("@elementor/store");
69
+ var initialState = {
70
+ data: {},
71
+ initialData: {},
72
+ isDirty: false
73
+ };
74
+ var SLICE_NAME = "defaultStyles";
75
+ var slice = (0, import_store.__createSlice)({
76
+ name: SLICE_NAME,
77
+ initialState,
78
+ reducers: {
79
+ load(state, {
80
+ payload: { data }
81
+ }) {
82
+ state.initialData = structuredClone(data);
83
+ state.data = structuredClone(data);
84
+ state.isDirty = false;
85
+ },
86
+ update(state, { payload }) {
87
+ state.data[payload.style.id] = {
88
+ ...state.data[payload.style.id],
89
+ ...payload.style
90
+ };
91
+ state.isDirty = true;
92
+ },
93
+ updateProps(state, {
94
+ payload
95
+ }) {
96
+ const style = state.data[payload.id] ?? {
97
+ id: payload.id,
98
+ label: payload.id,
99
+ type: "class",
100
+ variants: []
101
+ };
102
+ const variant = (0, import_editor_styles.getVariantByMeta)(style, payload.meta);
103
+ let customCss = ("custom_css" in payload ? payload.custom_css : variant?.custom_css) ?? null;
104
+ customCss = customCss?.raw ? customCss : null;
105
+ if (variant) {
106
+ const payloadProps = JSON.parse(JSON.stringify(payload.props));
107
+ const mode = payload.mode ?? "merge";
108
+ if (mode === "replace") {
109
+ variant.props = payloadProps;
110
+ } else {
111
+ const variantProps = JSON.parse(JSON.stringify(variant.props));
112
+ variant.props = { ...variantProps, ...payloadProps };
113
+ }
114
+ variant.custom_css = customCss;
115
+ } else {
116
+ style.variants.push({
117
+ meta: payload.meta,
118
+ props: payload.props,
119
+ custom_css: customCss
120
+ });
121
+ }
122
+ state.data[payload.id] = style;
123
+ state.isDirty = true;
124
+ },
125
+ reset(state) {
126
+ state.data = structuredClone(state.initialData);
127
+ state.isDirty = false;
128
+ },
129
+ commit(state) {
130
+ state.initialData = structuredClone(state.data);
131
+ state.isDirty = false;
132
+ },
133
+ deleteTag(state, { payload }) {
134
+ delete state.data[payload];
135
+ state.isDirty = true;
136
+ }
137
+ }
138
+ });
139
+ var selectData = (0, import_store.__createSelector)(
140
+ (state) => state.defaultStyles.data,
141
+ (data) => data
142
+ );
143
+ var selectIsDirty = (0, import_store.__createSelector)(
144
+ (state) => state.defaultStyles.isDirty,
145
+ (isDirty) => isDirty
146
+ );
147
+ var selectInitialData = (0, import_store.__createSelector)(
148
+ (state) => state.defaultStyles.initialData,
149
+ (initialData) => initialData
150
+ );
151
+ var selectTagStyle = (0, import_store.__createSelector)(
152
+ [selectData, (_state, id) => id],
153
+ (data, id) => data[id]
154
+ );
155
+
156
+ // src/load-default-styles.ts
157
+ async function loadDefaultStyles() {
158
+ const response = await apiClient.all();
159
+ const items = response.data.data;
160
+ (0, import_store2.__dispatch)(
161
+ slice.actions.load({
162
+ data: items
163
+ })
164
+ );
165
+ }
166
+
167
+ // src/components/populate-store.tsx
168
+ var V2_PANEL_ROUTE = "panel/v2";
169
+ function PopulateStore() {
170
+ (0, import_react.useEffect)(() => {
171
+ void loadDefaultStyles();
172
+ (0, import_editor_v1_adapters.registerDataHook)("after", "editor/documents/attach-preview", async () => {
173
+ if (selectIsDirty((0, import_store4.__getState)())) {
174
+ return;
175
+ }
176
+ await loadDefaultStyles();
177
+ });
178
+ const unsubscribe = (0, import_editor_v1_adapters.__privateListenTo)((0, import_editor_v1_adapters.routeCloseEvent)(V2_PANEL_ROUTE), () => {
179
+ if (selectIsDirty((0, import_store4.__getState)())) {
180
+ return;
181
+ }
182
+ void loadDefaultStyles();
183
+ });
184
+ return unsubscribe;
185
+ }, []);
186
+ return null;
187
+ }
188
+
189
+ // src/default-styles-open-gate.tsx
190
+ var React5 = __toESM(require("react"));
191
+ var import_react4 = require("react");
192
+ var import_editor_documents = require("@elementor/editor-documents");
193
+ var import_editor_ui2 = require("@elementor/editor-ui");
194
+ var import_i18n3 = require("@wordpress/i18n");
195
+
196
+ // src/default-styles-panel.tsx
197
+ var React4 = __toESM(require("react"));
198
+ var import_editor_panels2 = require("@elementor/editor-panels");
199
+ var import_editor_v1_adapters2 = require("@elementor/editor-v1-adapters");
200
+
201
+ // src/components/default-styles-panel-content.tsx
202
+ var React3 = __toESM(require("react"));
203
+ var import_react3 = require("react");
204
+ var import_editor_controls = require("@elementor/editor-controls");
205
+ var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
206
+ var import_editor_panels = require("@elementor/editor-panels");
207
+ var import_editor_responsive = require("@elementor/editor-responsive");
208
+ var import_editor_ui = require("@elementor/editor-ui");
209
+ var import_menus = require("@elementor/menus");
210
+ var import_query = require("@elementor/query");
211
+ var import_session = require("@elementor/session");
212
+ var import_store8 = require("@elementor/store");
213
+ var import_ui3 = require("@elementor/ui");
214
+ var import_i18n2 = require("@wordpress/i18n");
215
+
216
+ // src/allowed-tags.ts
217
+ var getElementorConfig = () => window.elementor?.config ?? {};
218
+ var getAllowedDefaultStyleTags = () => {
219
+ const tags = getElementorConfig().atomic?.default_styles?.allowed_tags;
220
+ if (!tags?.length) {
221
+ return [];
222
+ }
223
+ return tags;
224
+ };
225
+ var getDefaultActiveTag = (tags) => {
226
+ if (tags.includes("h1")) {
227
+ return "h1";
228
+ }
229
+ return tags[0] ?? "";
230
+ };
231
+ var isAllowedDefaultStyleTag = (tag, tags = getAllowedDefaultStyleTags()) => tags.includes(tag);
232
+
233
+ // src/panel-interactions.ts
234
+ function blockPanelInteractions() {
235
+ const extendedWindow = window;
236
+ extendedWindow.$e?.components?.get?.("panel")?.blockUserInteractions?.();
237
+ }
238
+ function unblockPanelInteractions() {
239
+ const extendedWindow = window;
240
+ extendedWindow.$e?.components?.get?.("panel")?.unblockUserInteractions?.();
241
+ }
242
+
243
+ // src/save-default-styles.ts
244
+ var import_store6 = require("@elementor/store");
245
+ var import_utils = require("@elementor/utils");
246
+ function getChangedTags(state) {
247
+ const current = selectData(state);
248
+ const initial = selectInitialData(state);
249
+ const changed = [];
250
+ Object.keys(current).forEach((tag) => {
251
+ const currentStyle = current[tag];
252
+ const initialStyle = initial[tag];
253
+ if (!initialStyle || (0, import_utils.hash)(currentStyle) !== (0, import_utils.hash)(initialStyle)) {
254
+ changed.push(tag);
255
+ }
256
+ });
257
+ Object.keys(initial).forEach((tag) => {
258
+ if (!current[tag]) {
259
+ changed.push(tag);
260
+ }
261
+ });
262
+ return changed;
263
+ }
264
+ async function saveDefaultStyles() {
265
+ const state = (0, import_store6.__getState)();
266
+ if (!selectIsDirty(state)) {
267
+ return;
268
+ }
269
+ const data = selectData(state);
270
+ const changedTags = getChangedTags(state);
271
+ await Promise.all(
272
+ changedTags.map(async (tag) => {
273
+ const style = data[tag];
274
+ if (!style || style.variants.length === 0) {
275
+ await apiClient.delete(tag);
276
+ return;
277
+ }
278
+ await apiClient.put(tag, style.variants);
279
+ })
280
+ );
281
+ (0, import_store6.__dispatch)(slice.actions.commit());
282
+ }
283
+
284
+ // src/components/tag-chip.tsx
285
+ var React2 = __toESM(require("react"));
286
+ var import_react2 = require("react");
287
+ var import_icons = require("@elementor/icons");
288
+ var import_ui2 = require("@elementor/ui");
289
+ var import_i18n = require("@wordpress/i18n");
290
+
291
+ // src/components/tag-state-menu.tsx
292
+ var React = __toESM(require("react"));
293
+ var import_editor_editing_panel = require("@elementor/editor-editing-panel");
294
+ var import_ui = require("@elementor/ui");
295
+ function TagStateMenu({ popupState, anchorEl, activeState, onSelectState }) {
296
+ return /* @__PURE__ */ React.createElement(
297
+ import_ui.Menu,
298
+ {
299
+ MenuListProps: { dense: true, sx: { minWidth: "160px" } },
300
+ ...(0, import_ui.bindMenu)(popupState),
301
+ anchorEl,
302
+ anchorOrigin: { vertical: "bottom", horizontal: "left" },
303
+ transformOrigin: { horizontal: "left", vertical: -4 },
304
+ disableAutoFocusItem: true
305
+ },
306
+ /* @__PURE__ */ React.createElement(
307
+ import_editor_editing_panel.PseudoStateMenuItems,
308
+ {
309
+ states: import_editor_editing_panel.DEFAULT_PSEUDO_STATES,
310
+ activeState,
311
+ onSelectState,
312
+ onClose: popupState.close
313
+ }
314
+ )
315
+ );
316
+ }
317
+
318
+ // src/components/tag-chip.tsx
319
+ var CHIP_SIZE = "tiny";
320
+ function TagChip({ label, chipProps, activeState, onSelectState }) {
321
+ const popupState = (0, import_ui2.usePopupState)({
322
+ variant: "popover",
323
+ popupId: "tag-state-menu"
324
+ });
325
+ const [chipRef, setChipRef] = (0, import_react2.useState)(null);
326
+ const { onDelete: _onDelete, ...chipGroupProps } = chipProps;
327
+ const isShowingState = Boolean(activeState);
328
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
329
+ import_ui2.UnstableChipGroup,
330
+ {
331
+ ref: setChipRef,
332
+ ...chipGroupProps,
333
+ "aria-label": `Edit ${label}`,
334
+ role: "group",
335
+ sx: (theme) => ({
336
+ "&.MuiChipGroup-root.MuiAutocomplete-tag": {
337
+ margin: theme.spacing(0.125)
338
+ }
339
+ })
340
+ },
341
+ /* @__PURE__ */ React2.createElement(
342
+ import_ui2.Chip,
343
+ {
344
+ size: CHIP_SIZE,
345
+ label,
346
+ variant: isShowingState ? "standard" : "filled",
347
+ shape: "rounded",
348
+ color: "default",
349
+ onClick: () => {
350
+ if (isShowingState) {
351
+ onSelectState(null);
352
+ }
353
+ },
354
+ sx: (theme) => ({
355
+ lineHeight: 1,
356
+ borderRadius: `${theme.shape.borderRadius * 0.75}px`
357
+ })
358
+ }
359
+ ),
360
+ /* @__PURE__ */ React2.createElement(
361
+ import_ui2.Chip,
362
+ {
363
+ icon: isShowingState ? void 0 : /* @__PURE__ */ React2.createElement(import_icons.DotsVerticalIcon, { fontSize: "tiny" }),
364
+ size: CHIP_SIZE,
365
+ label: isShowingState ? /* @__PURE__ */ React2.createElement(import_ui2.Stack, { direction: "row", gap: 0.5, alignItems: "center" }, /* @__PURE__ */ React2.createElement(import_ui2.Typography, { variant: "inherit" }, activeState), /* @__PURE__ */ React2.createElement(import_icons.DotsVerticalIcon, { fontSize: "tiny" })) : void 0,
366
+ variant: "filled",
367
+ shape: "rounded",
368
+ color: "default",
369
+ ...(0, import_ui2.bindTrigger)(popupState),
370
+ "aria-label": (0, import_i18n.__)("Open tag state menu", "elementor"),
371
+ sx: (theme) => ({
372
+ borderRadius: `${theme.shape.borderRadius * 0.75}px`,
373
+ paddingRight: 0,
374
+ ...!isShowingState ? { paddingLeft: 0 } : {},
375
+ ".MuiChip-label": isShowingState ? { paddingRight: 0 } : { padding: 0 }
376
+ })
377
+ }
378
+ )
379
+ ), /* @__PURE__ */ React2.createElement(
380
+ TagStateMenu,
381
+ {
382
+ popupState,
383
+ anchorEl: chipRef,
384
+ activeState,
385
+ onSelectState
386
+ }
387
+ ));
388
+ }
389
+
390
+ // src/components/default-styles-panel-content.tsx
391
+ var { useMenuItems } = import_menus.controlActionsMenu;
392
+ var SHIM_ELEMENT_ID = "default-styles-editor-shim";
393
+ var SHIM_CLASSES_PROP = "__default_styles_classes__";
394
+ var TAG_SELECTOR_ID = "default-styles-tag-selector";
395
+ var LAST_ACTIVE_TAG_SESSION_PREFIX = "default-styles";
396
+ var LAST_ACTIVE_TAG_SESSION_KEY = "last-active-tag";
397
+ var LAST_ACTIVE_TAG_STORAGE_KEY = `${LAST_ACTIVE_TAG_SESSION_PREFIX}/${LAST_ACTIVE_TAG_SESSION_KEY}`;
398
+ function readStoredActiveTag(allowedTags) {
399
+ const storedTag = (0, import_session.getSessionStorageItem)(LAST_ACTIVE_TAG_STORAGE_KEY);
400
+ if (storedTag && isAllowedDefaultStyleTag(storedTag, allowedTags)) {
401
+ return storedTag;
402
+ }
403
+ return getDefaultActiveTag(allowedTags);
404
+ }
405
+ function toTagChip(tag) {
406
+ return { label: tag, value: tag, fixed: true };
407
+ }
408
+ var shimElement = {
409
+ id: SHIM_ELEMENT_ID,
410
+ type: "default-style"
411
+ };
412
+ var shimElementType = {
413
+ key: "default-style",
414
+ controls: [],
415
+ propsSchema: {},
416
+ title: (0, import_i18n2.__)("Default Style", "elementor")
417
+ };
418
+ function DefaultStylesPanelContent({ onRequestClose }) {
419
+ const allowedTags = (0, import_react3.useMemo)(() => getAllowedDefaultStyleTags(), []);
420
+ const tagOptions = (0, import_react3.useMemo)(
421
+ () => allowedTags.map((tag) => ({ label: tag, value: tag })),
422
+ [allowedTags]
423
+ );
424
+ const [selectedTag, setSelectedTagState] = (0, import_react3.useState)(() => readStoredActiveTag(allowedTags));
425
+ const [activeStyleState, setActiveStyleState] = (0, import_react3.useState)(null);
426
+ const breakpoint = (0, import_editor_responsive.useActiveBreakpoint)();
427
+ const menuItems = useMenuItems().default;
428
+ const controlReplacements = (0, import_editor_controls.getControlReplacements)();
429
+ const isDirty = (0, import_store8.__useSelector)(selectIsDirty);
430
+ const { mutateAsync: save, isPending: isSaving } = useSave();
431
+ const { open: openSaveChangesDialog, close: closeSaveChangesDialog, isOpen: isSaveChangesDialogOpen } = (0, import_editor_ui.useDialog)();
432
+ const setSelectedTag = (tag) => {
433
+ setSelectedTagState(tag);
434
+ (0, import_session.setSessionStorageItem)(LAST_ACTIVE_TAG_STORAGE_KEY, tag);
435
+ };
436
+ const handleClosePanel = (0, import_react3.useCallback)(() => {
437
+ if (isDirty) {
438
+ openSaveChangesDialog();
439
+ return;
440
+ }
441
+ onRequestClose();
442
+ }, [isDirty, onRequestClose, openSaveChangesDialog]);
443
+ (0, import_react3.useEffect)(() => {
444
+ blockPanelInteractions();
445
+ return () => {
446
+ unblockPanelInteractions();
447
+ };
448
+ }, []);
449
+ usePreventUnload(isDirty);
450
+ const handleTagSelect = (_selected, reason, option) => {
451
+ if (reason !== "selectOption" || !option.value) {
452
+ return;
453
+ }
454
+ setSelectedTag(option.value);
455
+ setActiveStyleState(null);
456
+ };
457
+ const resetAndClosePanel = () => {
458
+ (0, import_store8.__dispatch)(slice.actions.reset());
459
+ closeSaveChangesDialog();
460
+ onRequestClose();
461
+ };
462
+ const handleSaveAndContinue = async () => {
463
+ try {
464
+ await save();
465
+ } catch {
466
+ return;
467
+ }
468
+ closeSaveChangesDialog();
469
+ onRequestClose();
470
+ };
471
+ 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(
472
+ import_ui3.Stack,
473
+ {
474
+ p: 1,
475
+ pl: 2,
476
+ width: "100%",
477
+ direction: "row",
478
+ alignItems: "center",
479
+ justifyContent: "space-between",
480
+ spacing: 0.5
481
+ },
482
+ /* @__PURE__ */ React3.createElement(import_editor_panels.PanelHeaderTitle, { sx: { flex: 1, minWidth: 0 } }, (0, import_i18n2.__)("Default Styles", "elementor")),
483
+ /* @__PURE__ */ React3.createElement(
484
+ import_ui3.CloseButton,
485
+ {
486
+ "aria-label": (0, import_i18n2.__)("Close", "elementor"),
487
+ sx: { flexShrink: 0 },
488
+ onClick: handleClosePanel
489
+ }
490
+ )
491
+ )), /* @__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(
492
+ import_editor_editing_panel2.CreatableAutocomplete,
493
+ {
494
+ id: TAG_SELECTOR_ID,
495
+ size: "tiny",
496
+ placeholder: (0, import_i18n2.__)("Type tag name", "elementor"),
497
+ options: tagOptions,
498
+ selected: [toTagChip(selectedTag)],
499
+ onSelect: handleTagSelect,
500
+ renderTags: (values, getTagProps) => values.map((value, index) => /* @__PURE__ */ React3.createElement(
501
+ TagChip,
502
+ {
503
+ key: value.value ?? value.label,
504
+ label: value.label,
505
+ chipProps: getTagProps({ index }),
506
+ activeState: activeStyleState,
507
+ onSelectState: setActiveStyleState
508
+ }
509
+ ))
510
+ }
511
+ ))), /* @__PURE__ */ React3.createElement(
512
+ import_editor_editing_panel2.ElementProvider,
513
+ {
514
+ element: shimElement,
515
+ elementType: shimElementType,
516
+ settings: {}
517
+ },
518
+ /* @__PURE__ */ React3.createElement(import_editor_editing_panel2.ClassesPropProvider, { prop: SHIM_CLASSES_PROP }, /* @__PURE__ */ React3.createElement(
519
+ import_editor_editing_panel2.StyleProvider,
520
+ {
521
+ meta: {
522
+ breakpoint,
523
+ state: activeStyleState
524
+ },
525
+ id: selectedTag,
526
+ setId: () => {
527
+ },
528
+ setMetaState: setActiveStyleState
529
+ },
530
+ /* @__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(
531
+ import_ui3.Box,
532
+ {
533
+ sx: {
534
+ height: "150px"
535
+ }
536
+ }
537
+ )))
538
+ ))
539
+ )), /* @__PURE__ */ React3.createElement(import_editor_panels.PanelFooter, null, /* @__PURE__ */ React3.createElement(
540
+ import_ui3.Button,
541
+ {
542
+ fullWidth: true,
543
+ size: "small",
544
+ color: "global",
545
+ variant: "contained",
546
+ onClick: () => void save(),
547
+ disabled: !isDirty,
548
+ loading: isSaving
549
+ },
550
+ (0, import_i18n2.__)("Save changes", "elementor")
551
+ ))))), 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(
552
+ import_editor_ui.SaveChangesDialog.Actions,
553
+ {
554
+ actions: {
555
+ discard: {
556
+ label: (0, import_i18n2.__)("Discard", "elementor"),
557
+ action: resetAndClosePanel
558
+ },
559
+ confirm: {
560
+ label: (0, import_i18n2.__)("Save & Continue", "elementor"),
561
+ action: handleSaveAndContinue
562
+ }
563
+ }
564
+ }
565
+ ))));
566
+ }
567
+ function useSave() {
568
+ return (0, import_query.useMutation)({
569
+ mutationFn: () => saveDefaultStyles()
570
+ });
571
+ }
572
+ function usePreventUnload(isDirty) {
573
+ (0, import_react3.useEffect)(() => {
574
+ const handleBeforeUnload = (event) => {
575
+ if (isDirty) {
576
+ event.preventDefault();
577
+ }
578
+ };
579
+ window.addEventListener("beforeunload", handleBeforeUnload);
580
+ return () => {
581
+ window.removeEventListener("beforeunload", handleBeforeUnload);
582
+ };
583
+ }, [isDirty]);
584
+ }
585
+
586
+ // src/default-styles-panel.tsx
587
+ var DEFAULT_STYLES_PANEL_ID = "default-styles";
588
+ var { panel, usePanelStatus, usePanelActions } = (0, import_editor_panels2.__createPanel)({
589
+ id: DEFAULT_STYLES_PANEL_ID,
590
+ component: DefaultStylesPanelRoot,
591
+ allowedEditModes: ["edit", DEFAULT_STYLES_PANEL_ID],
592
+ onOpen: () => {
593
+ (0, import_editor_v1_adapters2.changeEditMode)(DEFAULT_STYLES_PANEL_ID);
594
+ },
595
+ onClose: async () => {
596
+ (0, import_editor_v1_adapters2.changeEditMode)("edit");
597
+ },
598
+ isOpenPreviousElement: true
599
+ });
600
+ function DefaultStylesPanelRoot() {
601
+ const { close } = usePanelActions();
602
+ return /* @__PURE__ */ React4.createElement(
603
+ DefaultStylesPanelContent,
604
+ {
605
+ onRequestClose: () => {
606
+ void close();
607
+ }
608
+ }
609
+ );
610
+ }
611
+
612
+ // src/default-styles-open-gate.tsx
613
+ var EVENT_REQUEST_OPEN_DEFAULT_STYLES = "elementor/default-styles/request-open";
614
+ function DefaultStylesOpenGate() {
615
+ const { open } = usePanelActions();
616
+ const document = (0, import_editor_documents.__useActiveDocument)();
617
+ const { save: saveDocument } = (0, import_editor_documents.__useActiveDocumentActions)();
618
+ const { open: openSaveDialog, close: closeSaveDialog, isOpen: isSaveDialogOpen } = (0, import_editor_ui2.useDialog)();
619
+ const documentRef = (0, import_react4.useRef)(document);
620
+ documentRef.current = document;
621
+ const pendingOpenRef = (0, import_react4.useRef)(null);
622
+ const gatedOpen = (0, import_react4.useCallback)(
623
+ (onClean) => {
624
+ if (documentRef.current?.isDirty) {
625
+ pendingOpenRef.current = onClean;
626
+ openSaveDialog();
627
+ return;
628
+ }
629
+ onClean();
630
+ },
631
+ [openSaveDialog]
632
+ );
633
+ const handleSaveAndContinue = (0, import_react4.useCallback)(async () => {
634
+ try {
635
+ await saveDocument();
636
+ closeSaveDialog();
637
+ pendingOpenRef.current?.();
638
+ pendingOpenRef.current = null;
639
+ } catch {
640
+ }
641
+ }, [saveDocument, closeSaveDialog]);
642
+ const handleStayHere = (0, import_react4.useCallback)(() => {
643
+ closeSaveDialog();
644
+ pendingOpenRef.current = null;
645
+ }, [closeSaveDialog]);
646
+ (0, import_react4.useEffect)(() => {
647
+ const handler = () => {
648
+ gatedOpen(() => {
649
+ void open();
650
+ });
651
+ };
652
+ window.addEventListener(EVENT_REQUEST_OPEN_DEFAULT_STYLES, handler);
653
+ return () => {
654
+ window.removeEventListener(EVENT_REQUEST_OPEN_DEFAULT_STYLES, handler);
655
+ };
656
+ }, [gatedOpen, open]);
657
+ if (!isSaveDialogOpen) {
658
+ return null;
659
+ }
660
+ 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.__)(
661
+ "To open Default Styles, save your page first. You can't continue without saving.",
662
+ "elementor"
663
+ ))), /* @__PURE__ */ React5.createElement(
664
+ import_editor_ui2.SaveChangesDialog.Actions,
665
+ {
666
+ actions: {
667
+ cancel: {
668
+ label: (0, import_i18n3.__)("Stay here", "elementor"),
669
+ action: handleStayHere
670
+ },
671
+ confirm: {
672
+ label: (0, import_i18n3.__)("Save & Continue", "elementor"),
673
+ action: handleSaveAndContinue
674
+ }
675
+ }
676
+ }
677
+ )));
678
+ }
679
+
680
+ // src/default-styles-provider.ts
681
+ var import_editor_styles_repository = require("@elementor/editor-styles-repository");
682
+ var import_store10 = require("@elementor/store");
683
+ var import_i18n4 = require("@wordpress/i18n");
684
+ var DEFAULT_STYLES_PROVIDER_KEY = "default-styles";
685
+ var DEFAULT_STYLES_CSS_NAME_PREFIX = "e-default-";
686
+ var resolveCssName = (id) => `${DEFAULT_STYLES_CSS_NAME_PREFIX}${id}`;
687
+ var placeholderDefinition = (id) => ({
688
+ id,
689
+ label: id,
690
+ type: "class",
691
+ variants: []
692
+ });
693
+ var asClassDefinition = (style) => ({
694
+ ...style,
695
+ type: "class"
696
+ });
697
+ var defaultStylesStylesProvider = (0, import_editor_styles_repository.createStylesProvider)({
698
+ key: DEFAULT_STYLES_PROVIDER_KEY,
699
+ priority: 15,
700
+ labels: {
701
+ singular: (0, import_i18n4.__)("tag", "elementor"),
702
+ plural: (0, import_i18n4.__)("tags", "elementor")
703
+ },
704
+ subscribe: (cb) => subscribeWithStates(cb),
705
+ actions: {
706
+ all: () => getAllowedDefaultStyleTags().map((tag) => {
707
+ const style = selectData((0, import_store10.__getState)())[tag];
708
+ return style ? asClassDefinition(style) : placeholderDefinition(tag);
709
+ }),
710
+ get: (id) => {
711
+ const style = selectData((0, import_store10.__getState)())[id];
712
+ return style ? asClassDefinition(style) : placeholderDefinition(id);
713
+ },
714
+ resolveCssName,
715
+ update: (payload) => {
716
+ (0, import_store10.__dispatch)(
717
+ slice.actions.update({
718
+ style: payload
719
+ })
720
+ );
721
+ },
722
+ delete: (id) => {
723
+ (0, import_store10.__dispatch)(slice.actions.deleteTag(id));
724
+ },
725
+ updateProps: (args) => {
726
+ (0, import_store10.__dispatch)(
727
+ slice.actions.updateProps({
728
+ id: args.id,
729
+ meta: args.meta,
730
+ props: args.props,
731
+ mode: args.mode
732
+ })
733
+ );
734
+ },
735
+ updateCustomCss: (args) => {
736
+ (0, import_store10.__dispatch)(
737
+ slice.actions.updateProps({
738
+ id: args.id,
739
+ meta: args.meta,
740
+ custom_css: args.custom_css,
741
+ props: {}
742
+ })
743
+ );
744
+ }
745
+ }
746
+ });
747
+ var subscribeWithStates = (cb) => {
748
+ let previousState = selectData((0, import_store10.__getState)());
749
+ return (0, import_store10.__subscribeWithSelector)(
750
+ (state) => selectData(state),
751
+ (currentState) => {
752
+ cb(previousState, currentState);
753
+ previousState = currentState;
754
+ }
755
+ );
756
+ };
757
+
758
+ // src/hooks/use-default-styles-action-props.ts
759
+ var import_icons2 = require("@elementor/icons");
760
+ var import_i18n5 = require("@wordpress/i18n");
761
+ function useDefaultStylesActionProps() {
762
+ return {
763
+ title: (0, import_i18n5.__)("Default Styles", "elementor"),
764
+ icon: import_icons2.TextIcon,
765
+ onClick: () => {
766
+ window.dispatchEvent(new CustomEvent(EVENT_REQUEST_OPEN_DEFAULT_STYLES));
767
+ }
768
+ };
769
+ }
770
+
771
+ // src/init.ts
772
+ function init() {
773
+ (0, import_store12.__registerSlice)(slice);
774
+ (0, import_editor_editing_panel3.registerElementPanelDefaults)("default-style", {
775
+ defaultTab: "style",
776
+ defaultSectionsExpanded: {
777
+ style: [...import_editor_editing_panel3.STYLE_SECTION_NAMES]
778
+ }
779
+ });
780
+ (0, import_editor_panels3.__registerPanel)(panel);
781
+ import_editor_styles_repository2.stylesRepository.register(defaultStylesStylesProvider);
782
+ import_editor_app_bar.toolsMenu.registerAction({
783
+ id: "default-styles-button",
784
+ priority: 4,
785
+ useProps: useDefaultStylesActionProps
786
+ });
787
+ (0, import_editor.injectIntoLogic)({
788
+ id: "default-styles-populate-store",
789
+ component: PopulateStore
790
+ });
791
+ (0, import_editor.injectIntoLogic)({
792
+ id: "default-styles-open-gate",
793
+ component: DefaultStylesOpenGate
794
+ });
795
+ }
796
+ // Annotate the CommonJS export names for ESM import in node:
797
+ 0 && (module.exports = {
798
+ init
799
+ });
800
+ //# sourceMappingURL=index.js.map