@elementor/editor-responsive 0.10.5 → 0.11.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
@@ -1,269 +1,65 @@
1
- // src/store/index.ts
2
- import { __createSlice } from "@elementor/store";
3
- var initialState = {
4
- entities: {},
5
- activeId: null
6
- };
7
- var slice = __createSlice({
8
- name: "breakpoints",
9
- initialState,
10
- reducers: {
11
- init(state, action) {
12
- state.activeId = action.payload.activeId;
13
- state.entities = normalizeEntities(action.payload.entities);
14
- },
15
- activateBreakpoint(state, action) {
16
- if (state.entities[action.payload]) {
17
- state.activeId = action.payload;
18
- }
19
- }
20
- }
21
- });
22
- function normalizeEntities(entities) {
23
- return entities.reduce((acc, breakpoint) => {
24
- return {
25
- ...acc,
26
- [breakpoint.id]: breakpoint
27
- };
28
- }, {});
29
- }
30
-
31
- // src/sync/sync-store.ts
32
- import { __dispatch } from "@elementor/store";
33
- import { __privateListenTo as listenTo, v1ReadyEvent, windowEvent } from "@elementor/editor-v1-adapters";
1
+ // src/hooks/use-breakpoints.ts
34
2
  import { __ } from "@wordpress/i18n";
35
- function syncStore() {
36
- syncInitialization();
37
- syncOnChange();
38
- }
39
- function syncInitialization() {
40
- const { init: init2 } = slice.actions;
41
- listenTo(
42
- v1ReadyEvent(),
43
- () => {
44
- __dispatch(init2({
45
- entities: getBreakpoints(),
46
- activeId: getActiveBreakpoint()
47
- }));
48
- }
49
- );
50
- }
51
- function syncOnChange() {
52
- const { activateBreakpoint } = slice.actions;
53
- listenTo(
54
- deviceModeChangeEvent(),
55
- () => {
56
- const activeBreakpoint = getActiveBreakpoint();
57
- __dispatch(activateBreakpoint(activeBreakpoint));
58
- }
59
- );
3
+ import { v1ReadyEvent, __privateUseListenTo as useListenTo } from "@elementor/editor-v1-adapters";
4
+ function useBreakpoints() {
5
+ return useListenTo(v1ReadyEvent(), getBreakpoints);
60
6
  }
61
7
  function getBreakpoints() {
62
8
  const { breakpoints } = window.elementor?.config?.responsive || {};
63
- if (!breakpoints) {
9
+ if (!breakpoints || Object.entries(breakpoints).length === 0) {
64
10
  return [];
65
11
  }
66
- const entities = Object.entries(breakpoints).filter(([, breakpoint]) => breakpoint.is_enabled).map(([id, { value, direction, label }]) => {
67
- return {
12
+ const minWidth = [];
13
+ const maxWidth = [];
14
+ const defaults = [
15
+ // Desktop breakpoint is not included in V1 config.
16
+ { id: "desktop", label: __("Desktop", "elementor") }
17
+ ];
18
+ Object.entries(breakpoints).forEach(([id, v1Breakpoint]) => {
19
+ if (!v1Breakpoint.is_enabled) {
20
+ return;
21
+ }
22
+ const breakpoint = {
68
23
  id,
69
- label,
70
- width: value,
71
- type: direction === "min" ? "min-width" : "max-width"
24
+ label: v1Breakpoint.label,
25
+ width: v1Breakpoint.value,
26
+ type: v1Breakpoint.direction === "min" ? "min-width" : "max-width"
72
27
  };
28
+ if (!breakpoint.width) {
29
+ defaults.push(breakpoint);
30
+ } else if (breakpoint.type === "min-width") {
31
+ minWidth.push(breakpoint);
32
+ } else if (breakpoint.type === "max-width") {
33
+ maxWidth.push(breakpoint);
34
+ }
73
35
  });
74
- entities.push({
75
- id: "desktop",
76
- label: __("Desktop", "elementor")
77
- });
78
- return entities;
36
+ const byWidth = (a, b) => {
37
+ return a.width && b.width ? b.width - a.width : 0;
38
+ };
39
+ return [...minWidth.sort(byWidth), ...defaults, ...maxWidth.sort(byWidth)];
40
+ }
41
+
42
+ // src/hooks/use-active-breakpoint.ts
43
+ import { __privateUseListenTo as useListenTo2, windowEvent } from "@elementor/editor-v1-adapters";
44
+ function useActiveBreakpoint() {
45
+ return useListenTo2(windowEvent("elementor/device-mode/change"), getActiveBreakpoint);
79
46
  }
80
47
  function getActiveBreakpoint() {
81
48
  const extendedWindow = window;
82
49
  return extendedWindow.elementor?.channels?.deviceMode?.request?.("currentMode") || null;
83
50
  }
84
- function deviceModeChangeEvent() {
85
- return windowEvent("elementor/device-mode/change");
86
- }
87
-
88
- // src/init.ts
89
- import { injectIntoResponsive } from "@elementor/editor-app-bar";
90
-
91
- // src/components/breakpoints-switcher.tsx
92
- import * as React from "react";
93
- import { __ as __2 } from "@wordpress/i18n";
94
-
95
- // src/hooks/use-breakpoints.ts
96
- import { __useSelector as useSelector } from "@elementor/store";
97
-
98
- // src/store/selectors.ts
99
- import { __createSelector } from "@elementor/store";
100
- var selectEntities = (state) => state.breakpoints.entities;
101
- var selectActiveId = (state) => state.breakpoints.activeId;
102
- var selectActiveBreakpoint = __createSelector(
103
- selectEntities,
104
- selectActiveId,
105
- (entities, activeId) => activeId && entities[activeId] ? entities[activeId] : null
106
- );
107
- var selectSortedBreakpoints = __createSelector(
108
- selectEntities,
109
- (entities) => {
110
- const byWidth = (a, b) => {
111
- return a.width && b.width ? b.width - a.width : 0;
112
- };
113
- const all = Object.values(entities);
114
- const defaults = all.filter((breakpoint) => !breakpoint.width);
115
- const minWidth = all.filter((breakpoint) => breakpoint.type === "min-width");
116
- const maxWidth = all.filter((breakpoint) => breakpoint.type === "max-width");
117
- return [
118
- ...minWidth.sort(byWidth),
119
- ...defaults,
120
- ...maxWidth.sort(byWidth)
121
- ];
122
- }
123
- );
124
-
125
- // src/hooks/use-breakpoints.ts
126
- function useBreakpoints() {
127
- const all = useSelector(selectSortedBreakpoints);
128
- const active = useSelector(selectActiveBreakpoint);
129
- return {
130
- all,
131
- active
132
- };
133
- }
134
-
135
- // src/components/breakpoints-switcher.tsx
136
- import { Tab, Tabs, Tooltip as BaseTooltip } from "@elementor/ui";
137
- import {
138
- DesktopIcon,
139
- TabletPortraitIcon,
140
- MobilePortraitIcon,
141
- WidescreenIcon,
142
- LaptopIcon,
143
- TabletLandscapeIcon,
144
- MobileLandscapeIcon
145
- } from "@elementor/icons";
146
51
 
147
- // src/hooks/use-breakpoints-actions.ts
52
+ // src/hooks/use-activate-breakpoint.ts
148
53
  import { useCallback } from "react";
149
54
  import { __privateRunCommand as runCommand } from "@elementor/editor-v1-adapters";
150
- function useBreakpointsActions() {
151
- const activate = useCallback((device) => {
152
- return runCommand("panel/change-device-mode", { device });
55
+ function useActivateBreakpoint() {
56
+ return useCallback((breakpoint) => {
57
+ return runCommand("panel/change-device-mode", { device: breakpoint });
153
58
  }, []);
154
- return {
155
- activate
156
- };
157
- }
158
-
159
- // src/components/breakpoints-switcher.tsx
160
- function BreakpointsSwitcher() {
161
- const { all, active } = useBreakpoints();
162
- const { activate } = useBreakpointsActions();
163
- if (!all.length || !active) {
164
- return null;
165
- }
166
- const onChange = (_, value) => {
167
- const extendedWindow = window;
168
- const config = extendedWindow?.elementor?.editorEvents?.config;
169
- if (config) {
170
- extendedWindow.elementor.editorEvents.dispatchEvent(
171
- config.names.topBar.responsiveControls,
172
- {
173
- location: config.locations.topBar,
174
- secondaryLocation: config.secondaryLocations.responsiveControls,
175
- trigger: config.triggers.click,
176
- element: config.elements.buttonIcon,
177
- mode: value
178
- }
179
- );
180
- }
181
- activate(value);
182
- };
183
- return /* @__PURE__ */ React.createElement(
184
- Tabs,
185
- {
186
- textColor: "inherit",
187
- indicatorColor: "secondary",
188
- value: active.id,
189
- onChange,
190
- "aria-label": __2("Switch Device", "elementor"),
191
- sx: {
192
- "& .MuiTabs-indicator": {
193
- backgroundColor: "text.primary"
194
- }
195
- }
196
- },
197
- all.map(({ id, label, type, width }) => {
198
- const Icon = iconsMap[id];
199
- const title = labelsMap[type || "default"].replace("%s", label).replace("%d", width?.toString() || "");
200
- return /* @__PURE__ */ React.createElement(
201
- Tab,
202
- {
203
- value: id,
204
- key: id,
205
- "aria-label": title,
206
- icon: /* @__PURE__ */ React.createElement(Tooltip, { title }, /* @__PURE__ */ React.createElement(Icon, null)),
207
- sx: { minWidth: "auto" },
208
- "data-testid": `switch-device-to-${id}`
209
- }
210
- );
211
- })
212
- );
213
- }
214
- function Tooltip(props) {
215
- return /* @__PURE__ */ React.createElement(
216
- BaseTooltip,
217
- {
218
- PopperProps: {
219
- sx: {
220
- "&.MuiTooltip-popper .MuiTooltip-tooltip.MuiTooltip-tooltipPlacementBottom": {
221
- mt: 2.5
222
- }
223
- }
224
- },
225
- ...props
226
- }
227
- );
228
59
  }
229
- var iconsMap = {
230
- widescreen: WidescreenIcon,
231
- desktop: DesktopIcon,
232
- laptop: LaptopIcon,
233
- tablet_extra: TabletLandscapeIcon,
234
- tablet: TabletPortraitIcon,
235
- mobile_extra: MobileLandscapeIcon,
236
- mobile: MobilePortraitIcon
237
- };
238
- var labelsMap = {
239
- default: "%s",
240
- // translators: %s: Breakpoint label, %d: Breakpoint size.
241
- "min-width": __2("%s (%dpx and up)", "elementor"),
242
- // translators: %s: Breakpoint label, %d: Breakpoint size.
243
- "max-width": __2("%s (up to %dpx)", "elementor")
60
+ export {
61
+ useActivateBreakpoint,
62
+ useActiveBreakpoint,
63
+ useBreakpoints
244
64
  };
245
-
246
- // src/init.ts
247
- import { __registerSlice } from "@elementor/store";
248
- function init() {
249
- initStore();
250
- registerAppBarUI();
251
- }
252
- function initStore() {
253
- __registerSlice(slice);
254
- syncStore();
255
- }
256
- function registerAppBarUI() {
257
- injectIntoResponsive({
258
- id: "responsive-breakpoints-switcher",
259
- component: BreakpointsSwitcher,
260
- options: {
261
- priority: 20
262
- // After document indication.
263
- }
264
- });
265
- }
266
-
267
- // src/index.ts
268
- init();
269
65
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/store/index.ts","../src/sync/sync-store.ts","../src/init.ts","../src/components/breakpoints-switcher.tsx","../src/hooks/use-breakpoints.ts","../src/store/selectors.ts","../src/hooks/use-breakpoints-actions.ts","../src/index.ts"],"sourcesContent":["import { __createSlice, PayloadAction } from '@elementor/store';\nimport { Breakpoint, BreakpointId } from '../types';\n\nexport type State = {\n\tentities: Record<BreakpointId, Breakpoint>,\n\tactiveId: BreakpointId | null,\n}\nconst initialState: State = {\n\tentities: {} as State['entities'],\n\tactiveId: null,\n};\n\nexport const slice = __createSlice( {\n\tname: 'breakpoints',\n\tinitialState,\n\treducers: {\n\t\tinit( state, action: PayloadAction<{\n\t\t\tentities: Breakpoint[],\n\t\t\tactiveId: State['activeId'],\n\t\t}> ) {\n\t\t\tstate.activeId = action.payload.activeId;\n\t\t\tstate.entities = normalizeEntities( action.payload.entities );\n\t\t},\n\n\t\tactivateBreakpoint( state, action: PayloadAction<BreakpointId> ) {\n\t\t\tif ( state.entities[ action.payload ] ) {\n\t\t\t\tstate.activeId = action.payload;\n\t\t\t}\n\t\t},\n\t},\n} );\n\nfunction normalizeEntities( entities: Breakpoint[] ) {\n\treturn entities.reduce( ( acc, breakpoint ) => {\n\t\treturn {\n\t\t\t...acc,\n\t\t\t[ breakpoint.id ]: breakpoint,\n\t\t};\n\t}, {} as State['entities'] );\n}\n","import { slice } from '../store';\nimport { __dispatch } from '@elementor/store';\nimport { Breakpoint, ExtendedWindow } from '../types';\nimport { __privateListenTo as listenTo, v1ReadyEvent, windowEvent } from '@elementor/editor-v1-adapters';\nimport { __ } from '@wordpress/i18n';\n\nexport default function syncStore() {\n\tsyncInitialization();\n\tsyncOnChange();\n}\n\nfunction syncInitialization() {\n\tconst { init } = slice.actions;\n\n\tlistenTo(\n\t\tv1ReadyEvent(),\n\t\t() => {\n\t\t\t__dispatch( init( {\n\t\t\t\tentities: getBreakpoints(),\n\t\t\t\tactiveId: getActiveBreakpoint(),\n\t\t\t} ) );\n\t\t}\n\t);\n}\n\nfunction syncOnChange() {\n\tconst { activateBreakpoint } = slice.actions;\n\n\tlistenTo(\n\t\tdeviceModeChangeEvent(),\n\t\t() => {\n\t\t\tconst activeBreakpoint = getActiveBreakpoint();\n\n\t\t\t__dispatch( activateBreakpoint( activeBreakpoint ) );\n\t\t},\n\t);\n}\n\nfunction getBreakpoints() {\n\tconst { breakpoints } = ( window as unknown as ExtendedWindow ).elementor?.config?.responsive || {};\n\n\tif ( ! breakpoints ) {\n\t\treturn [];\n\t}\n\n\tconst entities = Object\n\t\t.entries( breakpoints )\n\t\t.filter( ( [ , breakpoint ] ) => breakpoint.is_enabled )\n\t\t.map( ( [ id, { value, direction, label } ] ) => {\n\t\t\treturn {\n\t\t\t\tid,\n\t\t\t\tlabel,\n\t\t\t\twidth: value,\n\t\t\t\ttype: direction === 'min' ? 'min-width' : 'max-width',\n\t\t\t} as Breakpoint;\n\t\t} );\n\n\t// Desktop breakpoint is not included in V1 config.\n\tentities.push( {\n\t\tid: 'desktop',\n\t\tlabel: __( 'Desktop', 'elementor' ),\n\t} );\n\n\treturn entities;\n}\n\nfunction getActiveBreakpoint() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor?.channels?.deviceMode?.request?.( 'currentMode' ) || null;\n}\n\nfunction deviceModeChangeEvent() {\n\treturn windowEvent( 'elementor/device-mode/change' );\n}\n","import { slice } from './store';\nimport syncStore from './sync/sync-store';\nimport { injectIntoResponsive } from '@elementor/editor-app-bar';\nimport BreakpointsSwitcher from './components/breakpoints-switcher';\nimport { __registerSlice } from '@elementor/store';\n\nexport default function init() {\n\tinitStore();\n\n\tregisterAppBarUI();\n}\n\nfunction initStore() {\n\t__registerSlice( slice );\n\n\tsyncStore();\n}\n\nfunction registerAppBarUI() {\n\tinjectIntoResponsive( {\n\t\tid: 'responsive-breakpoints-switcher',\n\t\tcomponent: BreakpointsSwitcher,\n\t\toptions: {\n\t\t\tpriority: 20, // After document indication.\n\t\t},\n\t} );\n}\n","import * as React from 'react';\nimport { __ } from '@wordpress/i18n';\nimport { BreakpointId, ExtendedWindow } from '../types';\nimport useBreakpoints from '../hooks/use-breakpoints';\nimport { Tab, Tabs, Tooltip as BaseTooltip, TooltipProps } from '@elementor/ui';\nimport {\n\tDesktopIcon,\n\tTabletPortraitIcon,\n\tMobilePortraitIcon,\n\tWidescreenIcon,\n\tLaptopIcon,\n\tTabletLandscapeIcon,\n\tMobileLandscapeIcon,\n} from '@elementor/icons';\nimport useBreakpointsActions from '../hooks/use-breakpoints-actions';\n\nexport default function BreakpointsSwitcher() {\n\tconst { all, active } = useBreakpoints();\n\tconst { activate } = useBreakpointsActions();\n\n\tif ( ! all.length || ! active ) {\n\t\treturn null;\n\t}\n\n\tconst onChange = ( _: unknown, value: BreakpointId ) => {\n\t\tconst extendedWindow = window as unknown as ExtendedWindow;\n\t\tconst config = extendedWindow?.elementor?.editorEvents?.config;\n\n\t\tif ( config ) {\n\t\t\textendedWindow.elementor.editorEvents.dispatchEvent(\n\t\t\t\tconfig.names.topBar.responsiveControls,\n\t\t\t\t{\n\t\t\t\t\tlocation: config.locations.topBar,\n\t\t\t\t\tsecondaryLocation: config.secondaryLocations.responsiveControls,\n\t\t\t\t\ttrigger: config.triggers.click,\n\t\t\t\t\telement: config.elements.buttonIcon,\n\t\t\t\t\tmode: value,\n\t\t\t\t},\n\t\t\t);\n\t\t}\n\n\t\tactivate( value );\n\t};\n\n\treturn (\n\t\t<Tabs\n\t\t\ttextColor=\"inherit\"\n\t\t\tindicatorColor=\"secondary\"\n\t\t\tvalue={ active.id }\n\t\t\tonChange={ onChange }\n\t\t\taria-label={ __( 'Switch Device', 'elementor' ) }\n\t\t\tsx={ {\n\t\t\t\t'& .MuiTabs-indicator': {\n\t\t\t\t\tbackgroundColor: 'text.primary',\n\t\t\t\t},\n\t\t\t} }\n\t\t>\n\t\t\t{\n\t\t\t\tall.map( ( { id, label, type, width } ) => {\n\t\t\t\t\tconst Icon = iconsMap[ id ];\n\n\t\t\t\t\tconst title = labelsMap[ type || 'default' ]\n\t\t\t\t\t\t.replace( '%s', label )\n\t\t\t\t\t\t.replace( '%d', width?.toString() || '' );\n\n\t\t\t\t\treturn (\n\t\t\t\t\t\t<Tab value={ id }\n\t\t\t\t\t\t\tkey={ id }\n\t\t\t\t\t\t\taria-label={ title }\n\t\t\t\t\t\t\ticon={ <Tooltip title={ title }><Icon /></Tooltip> }\n\t\t\t\t\t\t\tsx={ { minWidth: 'auto' } }\n\t\t\t\t\t\t\tdata-testid={ `switch-device-to-${ id }` }\n\t\t\t\t\t\t/>\n\t\t\t\t\t);\n\t\t\t\t} )\n\t\t\t}\n\t\t</Tabs>\n\n\t);\n}\n\nfunction Tooltip( props: TooltipProps ) {\n\treturn <BaseTooltip\n\t\tPopperProps={ {\n\t\t\tsx: {\n\t\t\t\t'&.MuiTooltip-popper .MuiTooltip-tooltip.MuiTooltip-tooltipPlacementBottom': {\n\t\t\t\t\tmt: 2.5,\n\t\t\t\t},\n\t\t\t},\n\t\t} }\n\t\t{ ...props }\n\t/>;\n}\n\nconst iconsMap = {\n\twidescreen: WidescreenIcon,\n\tdesktop: DesktopIcon,\n\tlaptop: LaptopIcon,\n\ttablet_extra: TabletLandscapeIcon,\n\ttablet: TabletPortraitIcon,\n\tmobile_extra: MobileLandscapeIcon,\n\tmobile: MobilePortraitIcon,\n};\n\nconst labelsMap = {\n\tdefault: '%s',\n\t// translators: %s: Breakpoint label, %d: Breakpoint size.\n\t'min-width': __( '%s (%dpx and up)', 'elementor' ),\n\n\t// translators: %s: Breakpoint label, %d: Breakpoint size.\n\t'max-width': __( '%s (up to %dpx)', 'elementor' ),\n} as const;\n","import { __useSelector as useSelector } from '@elementor/store';\nimport { selectActiveBreakpoint, selectSortedBreakpoints } from '../store/selectors';\n\nexport default function useBreakpoints() {\n\tconst all = useSelector( selectSortedBreakpoints );\n\tconst active = useSelector( selectActiveBreakpoint );\n\n\treturn {\n\t\tall,\n\t\tactive,\n\t};\n}\n","import { slice } from './index';\nimport { Breakpoint } from '../types';\nimport { __createSelector, SliceState } from '@elementor/store';\n\ntype State = SliceState<typeof slice>;\n\nexport const selectEntities = ( state: State ) => state.breakpoints.entities;\nexport const selectActiveId = ( state: State ) => state.breakpoints.activeId;\n\nexport const selectActiveBreakpoint = __createSelector(\n\tselectEntities,\n\tselectActiveId,\n\t( entities, activeId ) => activeId && entities[ activeId ]\n\t\t? entities[ activeId ]\n\t\t: null,\n);\n\nexport const selectSortedBreakpoints = __createSelector(\n\tselectEntities,\n\t( entities ) => {\n\t\tconst byWidth = ( a: Breakpoint, b: Breakpoint ) => {\n\t\t\treturn ( a.width && b.width ) ? b.width - a.width : 0;\n\t\t};\n\n\t\tconst all = Object.values( entities );\n\n\t\tconst defaults = all.filter( ( breakpoint ) => ! breakpoint.width ); // AKA Desktop.\n\t\tconst minWidth = all.filter( ( breakpoint ) => breakpoint.type === 'min-width' );\n\t\tconst maxWidth = all.filter( ( breakpoint ) => breakpoint.type === 'max-width' );\n\n\t\t// Sort by size, big to small.\n\t\treturn [\n\t\t\t...minWidth.sort( byWidth ),\n\t\t\t...defaults,\n\t\t\t...maxWidth.sort( byWidth ),\n\t\t];\n\t},\n);\n","import { useCallback } from 'react';\nimport { BreakpointId } from '../types';\nimport { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\n\nexport default function useBreakpointsActions() {\n\tconst activate = useCallback( ( device: BreakpointId ) => {\n\t\treturn runCommand( 'panel/change-device-mode', { device } );\n\t}, [] );\n\n\treturn {\n\t\tactivate,\n\t};\n}\n","import init from './init';\n\ninit();\n"],"mappings":";AAAA,SAAS,qBAAoC;AAO7C,IAAM,eAAsB;AAAA,EAC3B,UAAU,CAAC;AAAA,EACX,UAAU;AACX;AAEO,IAAM,QAAQ,cAAe;AAAA,EACnC,MAAM;AAAA,EACN;AAAA,EACA,UAAU;AAAA,IACT,KAAM,OAAO,QAGR;AACJ,YAAM,WAAW,OAAO,QAAQ;AAChC,YAAM,WAAW,kBAAmB,OAAO,QAAQ,QAAS;AAAA,IAC7D;AAAA,IAEA,mBAAoB,OAAO,QAAsC;AAChE,UAAK,MAAM,SAAU,OAAO,OAAQ,GAAI;AACvC,cAAM,WAAW,OAAO;AAAA,MACzB;AAAA,IACD;AAAA,EACD;AACD,CAAE;AAEF,SAAS,kBAAmB,UAAyB;AACpD,SAAO,SAAS,OAAQ,CAAE,KAAK,eAAgB;AAC9C,WAAO;AAAA,MACN,GAAG;AAAA,MACH,CAAE,WAAW,EAAG,GAAG;AAAA,IACpB;AAAA,EACD,GAAG,CAAC,CAAuB;AAC5B;;;ACtCA,SAAS,kB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,UAAK,CAAE;AAAA,UACxC,IAAK,EAAE,UAAU,OAAO;AAAA,UACxB,eAAc,oBAAqB,EAAG;AAAA;AAAA,MACvC;AAAA,IAEF,CAAE;AAAA,EAEJ;AAGF;AAEA,SAAS,QAAS,OAAsB;AACvC,SAAO;AAAA,IAAC;AAAA;AAAA,MACP,aAAc;AAAA,QACb,IAAI;AAAA,UACH,6EAA6E;AAAA,YAC5E,IAAI;AAAA,UACL;AAAA,QACD;AAAA,MACD;AAAA,MACE,GAAG;AAAA;AAAA,EACN;AACD;AAEA,IAAM,WAAW;AAAA,EAChB,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,QAAQ;AACT;AAEA,IAAM,YAAY;AAAA,EACjB,SAAS;AAAA;AAAA,EAET,aAAaA,IAAI,oBAAoB,WAAY;AAAA;AAAA,EAGjD,aAAaA,IAAI,mBAAmB,WAAY;AACjD;;;AD3GA,SAAS,uBAAuB;AAEjB,SAAR,OAAwB;AAC9B,YAAU;AAEV,mBAAiB;AAClB;AAEA,SAAS,YAAY;AACpB,kBAAiB,KAAM;AAEvB,YAAU;AACX;AAEA,SAAS,mBAAmB;AAC3B,uBAAsB;AAAA,IACrB,IAAI;AAAA,IACJ,WAAW;AAAA,IACX,SAAS;AAAA,MACR,UAAU;AAAA;AAAA,IACX;AAAA,EACD,CAAE;AACH;;;AKxBA,KAAK;","names":["init","__","__"]}
1
+ {"version":3,"sources":["../src/hooks/use-breakpoints.ts","../src/hooks/use-active-breakpoint.ts","../src/hooks/use-activate-breakpoint.ts"],"sourcesContent":["import { __ } from '@wordpress/i18n';\nimport { Breakpoint, BreakpointId, ExtendedWindow } from '../types';\nimport { v1ReadyEvent, __privateUseListenTo as useListenTo } from '@elementor/editor-v1-adapters';\n\nexport function useBreakpoints() {\n\treturn useListenTo( v1ReadyEvent(), getBreakpoints );\n}\n\nfunction getBreakpoints() {\n\tconst { breakpoints } = ( window as unknown as ExtendedWindow ).elementor?.config?.responsive || {};\n\n\tif ( ! breakpoints || Object.entries( breakpoints ).length === 0 ) {\n\t\treturn [];\n\t}\n\n\tconst minWidth: Breakpoint[] = [];\n\tconst maxWidth: Breakpoint[] = [];\n\n\tconst defaults: Breakpoint[] = [\n\t\t// Desktop breakpoint is not included in V1 config.\n\t\t{ id: 'desktop', label: __( 'Desktop', 'elementor' ) },\n\t];\n\n\tObject.entries( breakpoints ).forEach( ( [ id, v1Breakpoint ] ) => {\n\t\tif ( ! v1Breakpoint.is_enabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst breakpoint: Breakpoint = {\n\t\t\tid: id as BreakpointId,\n\t\t\tlabel: v1Breakpoint.label,\n\t\t\twidth: v1Breakpoint.value,\n\t\t\ttype: v1Breakpoint.direction === 'min' ? 'min-width' : 'max-width',\n\t\t};\n\n\t\tif ( ! breakpoint.width ) {\n\t\t\tdefaults.push( breakpoint );\n\t\t} else if ( breakpoint.type === 'min-width' ) {\n\t\t\tminWidth.push( breakpoint );\n\t\t} else if ( breakpoint.type === 'max-width' ) {\n\t\t\tmaxWidth.push( breakpoint );\n\t\t}\n\t} );\n\n\tconst byWidth = ( a: Breakpoint, b: Breakpoint ) => {\n\t\treturn a.width && b.width ? b.width - a.width : 0;\n\t};\n\n\treturn [ ...minWidth.sort( byWidth ), ...defaults, ...maxWidth.sort( byWidth ) ];\n}\n","import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';\nimport { BreakpointId, ExtendedWindow } from '../types';\n\nexport function useActiveBreakpoint(): BreakpointId | null {\n\treturn useListenTo( windowEvent( 'elementor/device-mode/change' ), getActiveBreakpoint );\n}\n\nfunction getActiveBreakpoint() {\n\tconst extendedWindow = window as unknown as ExtendedWindow;\n\n\treturn extendedWindow.elementor?.channels?.deviceMode?.request?.( 'currentMode' ) || null;\n}\n","import { useCallback } from 'react';\nimport { BreakpointId } from '../types';\nimport { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\n\nexport function useActivateBreakpoint() {\n\treturn useCallback( ( breakpoint: BreakpointId ) => {\n\t\treturn runCommand( 'panel/change-device-mode', { device: breakpoint } );\n\t}, [] );\n}\n"],"mappings":";AAAA,SAAS,UAAU;AAEnB,SAAS,cAAc,wBAAwB,mBAAmB;AAE3D,SAAS,iBAAiB;AAChC,SAAO,YAAa,aAAa,GAAG,cAAe;AACpD;AAEA,SAAS,iBAAiB;AACzB,QAAM,EAAE,YAAY,IAAM,OAAsC,WAAW,QAAQ,cAAc,CAAC;AAElG,MAAK,CAAE,eAAe,OAAO,QAAS,WAAY,EAAE,WAAW,GAAI;AAClE,WAAO,CAAC;AAAA,EACT;AAEA,QAAM,WAAyB,CAAC;AAChC,QAAM,WAAyB,CAAC;AAEhC,QAAM,WAAyB;AAAA;AAAA,IAE9B,EAAE,IAAI,WAAW,OAAO,GAAI,WAAW,WAAY,EAAE;AAAA,EACtD;AAEA,SAAO,QAAS,WAAY,EAAE,QAAS,CAAE,CAAE,IAAI,YAAa,MAAO;AAClE,QAAK,CAAE,aAAa,YAAa;AAChC;AAAA,IACD;AAEA,UAAM,aAAyB;AAAA,MAC9B;AAAA,MACA,OAAO,aAAa;AAAA,MACpB,OAAO,aAAa;AAAA,MACpB,MAAM,aAAa,cAAc,QAAQ,cAAc;AAAA,IACxD;AAEA,QAAK,CAAE,WAAW,OAAQ;AACzB,eAAS,KAAM,UAAW;AAAA,IAC3B,WAAY,WAAW,SAAS,aAAc;AAC7C,eAAS,KAAM,UAAW;AAAA,IAC3B,WAAY,WAAW,SAAS,aAAc;AAC7C,eAAS,KAAM,UAAW;AAAA,IAC3B;AAAA,EACD,CAAE;AAEF,QAAM,UAAU,CAAE,GAAe,MAAmB;AACnD,WAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ;AAAA,EACjD;AAEA,SAAO,CAAE,GAAG,SAAS,KAAM,OAAQ,GAAG,GAAG,UAAU,GAAG,SAAS,KAAM,OAAQ,CAAE;AAChF;;;ACjDA,SAAS,wBAAwBA,cAAa,mBAAmB;AAG1D,SAAS,sBAA2C;AAC1D,SAAOA,aAAa,YAAa,8BAA+B,GAAG,mBAAoB;AACxF;AAEA,SAAS,sBAAsB;AAC9B,QAAM,iBAAiB;AAEvB,SAAO,eAAe,WAAW,UAAU,YAAY,UAAW,aAAc,KAAK;AACtF;;;ACXA,SAAS,mBAAmB;AAE5B,SAAS,uBAAuB,kBAAkB;AAE3C,SAAS,wBAAwB;AACvC,SAAO,YAAa,CAAE,eAA8B;AACnD,WAAO,WAAY,4BAA4B,EAAE,QAAQ,WAAW,CAAE;AAAA,EACvE,GAAG,CAAC,CAAE;AACP;","names":["useListenTo"]}
package/package.json CHANGED
@@ -1,46 +1,42 @@
1
1
  {
2
- "name": "@elementor/editor-responsive",
3
- "version": "0.10.5",
4
- "private": false,
5
- "author": "Elementor Team",
6
- "homepage": "https://elementor.com/",
7
- "license": "GPL-3.0-or-later",
8
- "main": "dist/index.js",
9
- "module": "dist/index.mjs",
10
- "types": "dist/index.d.ts",
11
- "exports": {
12
- ".": {
13
- "import": "./dist/index.mjs",
14
- "require": "./dist/index.js",
15
- "types": "./dist/index.d.ts"
16
- },
17
- "./package.json": "./package.json"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/elementor/elementor-packages.git",
22
- "directory": "packages/core/editor-responsive"
23
- },
24
- "bugs": {
25
- "url": "https://github.com/elementor/elementor-packages/issues"
26
- },
27
- "publishConfig": {
28
- "access": "public"
29
- },
30
- "scripts": {
31
- "build": "tsup --config=../../tsup.build.ts",
32
- "dev": "tsup --config=../../tsup.dev.ts"
33
- },
34
- "dependencies": {
35
- "@elementor/editor-app-bar": "^0.14.5",
36
- "@elementor/editor-v1-adapters": "^0.7.0",
37
- "@elementor/icons": "^0.8.1",
38
- "@elementor/store": "^0.8.3",
39
- "@elementor/ui": "^1.4.61",
40
- "@wordpress/i18n": "^4.45.0"
41
- },
42
- "peerDependencies": {
43
- "react": "^18.3.1"
44
- },
45
- "gitHead": "ea48212f4a9084fa323c3e70af093c5c0f6aa2d1"
2
+ "name": "@elementor/editor-responsive",
3
+ "version": "0.11.0",
4
+ "private": false,
5
+ "author": "Elementor Team",
6
+ "homepage": "https://elementor.com/",
7
+ "license": "GPL-3.0-or-later",
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.mjs",
10
+ "types": "dist/index.d.ts",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
+ },
17
+ "./package.json": "./package.json"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "https://github.com/elementor/elementor-packages.git",
22
+ "directory": "packages/libs/editor-responsive"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/elementor/elementor-packages/issues"
26
+ },
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "scripts": {
31
+ "build": "tsup --config=../../tsup.build.ts",
32
+ "dev": "tsup --config=../../tsup.dev.ts"
33
+ },
34
+ "dependencies": {
35
+ "@elementor/editor-v1-adapters": "^0.8.0",
36
+ "@wordpress/i18n": "^4.45.0"
37
+ },
38
+ "peerDependencies": {
39
+ "react": "^18.3.1"
40
+ },
41
+ "gitHead": "7d626115b07f3425b679f7508230f7776f3fe17b"
46
42
  }
@@ -1,23 +1,20 @@
1
- import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
2
1
  import { renderHook } from '@testing-library/react';
3
- import useBreakpointsActions from '../use-breakpoints-actions';
2
+ import { useActivateBreakpoint } from '../use-activate-breakpoint';
3
+ import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
4
4
 
5
5
  jest.mock( '@elementor/editor-v1-adapters', () => ( {
6
6
  __privateRunCommand: jest.fn(),
7
7
  } ) );
8
8
 
9
- describe( '@elementor/editor-responsive - useBreakpointsActions', () => {
9
+ describe( 'useActivateBreakpoints', () => {
10
10
  it( 'should activate a breakpoint', () => {
11
11
  // Act.
12
- const { result } = renderHook( () => useBreakpointsActions() );
12
+ const { result } = renderHook( useActivateBreakpoint );
13
13
 
14
- result.current.activate( 'tablet' );
14
+ result.current( 'tablet' );
15
15
 
16
16
  // Assert.
17
17
  expect( jest.mocked( runCommand ) ).toHaveBeenCalledTimes( 1 );
18
- expect( jest.mocked( runCommand ) ).toHaveBeenCalledWith(
19
- 'panel/change-device-mode',
20
- { device: 'tablet' }
21
- );
18
+ expect( jest.mocked( runCommand ) ).toHaveBeenCalledWith( 'panel/change-device-mode', { device: 'tablet' } );
22
19
  } );
23
20
  } );
@@ -0,0 +1,50 @@
1
+ import { act, renderHook } from '@testing-library/react';
2
+ import { useActiveBreakpoint } from '../use-active-breakpoint';
3
+ import { BreakpointId, ExtendedWindow } from '../../types';
4
+ import { dispatchWindowEvent } from 'test-utils';
5
+
6
+ describe( 'useActiveBreakpoint', () => {
7
+ function setActiveBreakpoint( active: BreakpointId ) {
8
+ const extendedWindow = window as unknown as ExtendedWindow;
9
+
10
+ extendedWindow.elementor = {
11
+ channels: {
12
+ deviceMode: {
13
+ request: () => {
14
+ return active;
15
+ },
16
+ },
17
+ },
18
+ };
19
+
20
+ dispatchWindowEvent( 'elementor/device-mode/change' );
21
+ }
22
+
23
+ it( 'should return null when no breakpoint is active', () => {
24
+ // Arrange.
25
+ setActiveBreakpoint( undefined as never );
26
+
27
+ // Act.
28
+ const { result } = renderHook( useActiveBreakpoint );
29
+
30
+ // Assert.
31
+ expect( result.current ).toEqual( null );
32
+ } );
33
+
34
+ it( 'should return the active breakpoint', () => {
35
+ // Arrange.
36
+ setActiveBreakpoint( 'mobile' );
37
+
38
+ // Act.
39
+ const { result } = renderHook( useActiveBreakpoint );
40
+
41
+ // Assert.
42
+ expect( result.current ).toEqual( 'mobile' );
43
+
44
+ // Act.
45
+ act( () => setActiveBreakpoint( 'tablet' ) );
46
+
47
+ // Assert.
48
+ expect( result.current ).toEqual( 'tablet' );
49
+ } );
50
+ } );
@@ -0,0 +1,90 @@
1
+ import { useBreakpoints } from '../use-breakpoints';
2
+ import { renderHook } from '@testing-library/react';
3
+ import { ExtendedWindow, V1Breakpoints } from '../../types';
4
+
5
+ describe( 'useBreakpoints', () => {
6
+ function setBreakpoints( breakpoints: Partial< V1Breakpoints > ) {
7
+ const extendedWindow = window as unknown as ExtendedWindow;
8
+
9
+ extendedWindow.elementor = {
10
+ config: {
11
+ responsive: {
12
+ breakpoints: breakpoints as V1Breakpoints,
13
+ },
14
+ },
15
+ };
16
+ }
17
+
18
+ it( 'should return an empty array if no breakpoints are available', () => {
19
+ // Arrange.
20
+ setBreakpoints( {} as never );
21
+
22
+ // Act.
23
+ const { result } = renderHook( useBreakpoints );
24
+
25
+ // Assert.
26
+ expect( result.current ).toEqual( [] );
27
+ } );
28
+
29
+ it( 'should filter out inactive breakpoints', () => {
30
+ // Arrange.
31
+ setBreakpoints( {
32
+ tablet: {
33
+ is_enabled: false,
34
+ value: 1024,
35
+ label: 'Tablet Portrait',
36
+ direction: 'max',
37
+ },
38
+ mobile: {
39
+ is_enabled: true,
40
+ value: 767,
41
+ label: 'Mobile Portrait',
42
+ direction: 'max',
43
+ },
44
+ } );
45
+
46
+ // Act.
47
+ const { result } = renderHook( useBreakpoints );
48
+
49
+ // Assert.
50
+ expect( result.current ).toEqual( [
51
+ { id: 'desktop', label: 'Desktop' },
52
+ { id: 'mobile', label: 'Mobile Portrait', width: 767, type: 'max-width' },
53
+ ] );
54
+ } );
55
+
56
+ it( 'should return all breakpoints sorted by size', () => {
57
+ // Arrange.
58
+ setBreakpoints( {
59
+ tablet: {
60
+ is_enabled: true,
61
+ value: 1024,
62
+ label: 'Tablet Portrait',
63
+ direction: 'max',
64
+ },
65
+ mobile: {
66
+ is_enabled: true,
67
+ value: 767,
68
+ label: 'Mobile Portrait',
69
+ direction: 'max',
70
+ },
71
+ widescreen: {
72
+ is_enabled: true,
73
+ value: 2400,
74
+ label: 'Widescreen',
75
+ direction: 'min',
76
+ },
77
+ } );
78
+
79
+ // Act.
80
+ const { result } = renderHook( useBreakpoints );
81
+
82
+ // Assert.
83
+ expect( result.current ).toEqual( [
84
+ { id: 'widescreen', label: 'Widescreen', width: 2400, type: 'min-width' },
85
+ { id: 'desktop', label: 'Desktop' },
86
+ { id: 'tablet', label: 'Tablet Portrait', width: 1024, type: 'max-width' },
87
+ { id: 'mobile', label: 'Mobile Portrait', width: 767, type: 'max-width' },
88
+ ] );
89
+ } );
90
+ } );
@@ -0,0 +1,9 @@
1
+ import { useCallback } from 'react';
2
+ import { BreakpointId } from '../types';
3
+ import { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';
4
+
5
+ export function useActivateBreakpoint() {
6
+ return useCallback( ( breakpoint: BreakpointId ) => {
7
+ return runCommand( 'panel/change-device-mode', { device: breakpoint } );
8
+ }, [] );
9
+ }
@@ -0,0 +1,12 @@
1
+ import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';
2
+ import { BreakpointId, ExtendedWindow } from '../types';
3
+
4
+ export function useActiveBreakpoint(): BreakpointId | null {
5
+ return useListenTo( windowEvent( 'elementor/device-mode/change' ), getActiveBreakpoint );
6
+ }
7
+
8
+ function getActiveBreakpoint() {
9
+ const extendedWindow = window as unknown as ExtendedWindow;
10
+
11
+ return extendedWindow.elementor?.channels?.deviceMode?.request?.( 'currentMode' ) || null;
12
+ }