@elementor/editor-responsive 0.12.6 → 0.13.1
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/CHANGELOG.md +20 -0
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +44 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
- package/src/index.ts +2 -1
- package/src/sync/get-breakpoints-tree.ts +34 -0
- package/src/sync/get-breakpoints.ts +5 -44
- package/src/sync/utils/get-breakpoints-by-widths.ts +54 -0
- package/src/types.ts +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 0.13.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @elementor/editor-v1-adapters@0.10.1
|
|
8
|
+
|
|
9
|
+
## 0.13.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- d99471a: Added tree representation for responsive breakdowns
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- da38fa9: Remove unused exports and add missing dependencies.
|
|
18
|
+
- Updated dependencies [da38fa9]
|
|
19
|
+
- Updated dependencies [ad6fde0]
|
|
20
|
+
- Updated dependencies [b8e2a85]
|
|
21
|
+
- @elementor/editor-v1-adapters@0.10.0
|
|
22
|
+
|
|
3
23
|
## 0.12.6
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -10,6 +10,9 @@ type Breakpoint = {
|
|
|
10
10
|
type?: 'min-width' | 'max-width';
|
|
11
11
|
};
|
|
12
12
|
type BreakpointsMap = Record<BreakpointId, Breakpoint>;
|
|
13
|
+
type BreakpointNode = Breakpoint & {
|
|
14
|
+
children: BreakpointNode[];
|
|
15
|
+
};
|
|
13
16
|
|
|
14
17
|
declare function useActiveBreakpoint(): BreakpointId | null;
|
|
15
18
|
|
|
@@ -17,6 +20,8 @@ declare function useActivateBreakpoint(): (breakpoint: BreakpointId) => Promise<
|
|
|
17
20
|
|
|
18
21
|
declare function getBreakpoints(): Breakpoint[];
|
|
19
22
|
|
|
23
|
+
declare function getBreakpointsTree(): BreakpointNode;
|
|
24
|
+
|
|
20
25
|
declare function getBreakpointsMap(): BreakpointsMap;
|
|
21
26
|
|
|
22
|
-
export { type Breakpoint, type BreakpointId, type BreakpointSize, type BreakpointsMap, getBreakpoints, getBreakpointsMap, useActivateBreakpoint, useActiveBreakpoint, useBreakpoints };
|
|
27
|
+
export { type Breakpoint, type BreakpointId, type BreakpointNode, type BreakpointSize, type BreakpointsMap, getBreakpoints, getBreakpointsMap, getBreakpointsTree, useActivateBreakpoint, useActiveBreakpoint, useBreakpoints };
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,9 @@ type Breakpoint = {
|
|
|
10
10
|
type?: 'min-width' | 'max-width';
|
|
11
11
|
};
|
|
12
12
|
type BreakpointsMap = Record<BreakpointId, Breakpoint>;
|
|
13
|
+
type BreakpointNode = Breakpoint & {
|
|
14
|
+
children: BreakpointNode[];
|
|
15
|
+
};
|
|
13
16
|
|
|
14
17
|
declare function useActiveBreakpoint(): BreakpointId | null;
|
|
15
18
|
|
|
@@ -17,6 +20,8 @@ declare function useActivateBreakpoint(): (breakpoint: BreakpointId) => Promise<
|
|
|
17
20
|
|
|
18
21
|
declare function getBreakpoints(): Breakpoint[];
|
|
19
22
|
|
|
23
|
+
declare function getBreakpointsTree(): BreakpointNode;
|
|
24
|
+
|
|
20
25
|
declare function getBreakpointsMap(): BreakpointsMap;
|
|
21
26
|
|
|
22
|
-
export { type Breakpoint, type BreakpointId, type BreakpointSize, type BreakpointsMap, getBreakpoints, getBreakpointsMap, useActivateBreakpoint, useActiveBreakpoint, useBreakpoints };
|
|
27
|
+
export { type Breakpoint, type BreakpointId, type BreakpointNode, type BreakpointSize, type BreakpointsMap, getBreakpoints, getBreakpointsMap, getBreakpointsTree, useActivateBreakpoint, useActiveBreakpoint, useBreakpoints };
|
package/dist/index.js
CHANGED
|
@@ -22,6 +22,7 @@ var index_exports = {};
|
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
getBreakpoints: () => getBreakpoints,
|
|
24
24
|
getBreakpointsMap: () => getBreakpointsMap,
|
|
25
|
+
getBreakpointsTree: () => getBreakpointsTree,
|
|
25
26
|
useActivateBreakpoint: () => useActivateBreakpoint,
|
|
26
27
|
useActiveBreakpoint: () => useActiveBreakpoint,
|
|
27
28
|
useBreakpoints: () => useBreakpoints
|
|
@@ -31,12 +32,16 @@ module.exports = __toCommonJS(index_exports);
|
|
|
31
32
|
// src/hooks/use-breakpoints.ts
|
|
32
33
|
var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
|
|
33
34
|
|
|
34
|
-
// src/sync/get-breakpoints.ts
|
|
35
|
+
// src/sync/utils/get-breakpoints-by-widths.ts
|
|
35
36
|
var import_i18n = require("@wordpress/i18n");
|
|
36
|
-
function
|
|
37
|
+
function getBreakpointsByWidths() {
|
|
37
38
|
const { breakpoints } = window.elementor?.config?.responsive || {};
|
|
38
39
|
if (!breakpoints || Object.entries(breakpoints).length === 0) {
|
|
39
|
-
return
|
|
40
|
+
return {
|
|
41
|
+
minWidth: [],
|
|
42
|
+
defaults: [],
|
|
43
|
+
maxWidth: []
|
|
44
|
+
};
|
|
40
45
|
}
|
|
41
46
|
const minWidth = [];
|
|
42
47
|
const maxWidth = [];
|
|
@@ -65,7 +70,17 @@ function getBreakpoints() {
|
|
|
65
70
|
const byWidth = (a, b) => {
|
|
66
71
|
return a.width && b.width ? b.width - a.width : 0;
|
|
67
72
|
};
|
|
68
|
-
return
|
|
73
|
+
return {
|
|
74
|
+
minWidth: minWidth.sort(byWidth),
|
|
75
|
+
defaults,
|
|
76
|
+
maxWidth: maxWidth.sort(byWidth)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// src/sync/get-breakpoints.ts
|
|
81
|
+
function getBreakpoints() {
|
|
82
|
+
const { minWidth, defaults, maxWidth } = getBreakpointsByWidths();
|
|
83
|
+
return [...minWidth, ...defaults, ...maxWidth];
|
|
69
84
|
}
|
|
70
85
|
|
|
71
86
|
// src/hooks/use-breakpoints.ts
|
|
@@ -92,6 +107,30 @@ function useActivateBreakpoint() {
|
|
|
92
107
|
}, []);
|
|
93
108
|
}
|
|
94
109
|
|
|
110
|
+
// src/sync/get-breakpoints-tree.ts
|
|
111
|
+
function getBreakpointsTree() {
|
|
112
|
+
const { minWidth, defaults, maxWidth } = getBreakpointsByWidths();
|
|
113
|
+
const [rootBreakpoint] = defaults;
|
|
114
|
+
const rootNode = {
|
|
115
|
+
...rootBreakpoint,
|
|
116
|
+
children: []
|
|
117
|
+
};
|
|
118
|
+
const buildBranch = (breakpoints) => {
|
|
119
|
+
let last = rootNode;
|
|
120
|
+
breakpoints.forEach((breakpoint) => {
|
|
121
|
+
const newNode = {
|
|
122
|
+
...breakpoint,
|
|
123
|
+
children: []
|
|
124
|
+
};
|
|
125
|
+
last.children.push(newNode);
|
|
126
|
+
last = newNode;
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
buildBranch(minWidth);
|
|
130
|
+
buildBranch(maxWidth);
|
|
131
|
+
return rootNode;
|
|
132
|
+
}
|
|
133
|
+
|
|
95
134
|
// src/sync/get-breakpoints-map.ts
|
|
96
135
|
function getBreakpointsMap() {
|
|
97
136
|
const breakpoints = getBreakpoints();
|
|
@@ -102,6 +141,7 @@ function getBreakpointsMap() {
|
|
|
102
141
|
0 && (module.exports = {
|
|
103
142
|
getBreakpoints,
|
|
104
143
|
getBreakpointsMap,
|
|
144
|
+
getBreakpointsTree,
|
|
105
145
|
useActivateBreakpoint,
|
|
106
146
|
useActiveBreakpoint,
|
|
107
147
|
useBreakpoints
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/hooks/use-breakpoints.ts","../src/sync/get-breakpoints.ts","../src/hooks/use-active-breakpoint.ts","../src/hooks/use-activate-breakpoint.ts","../src/sync/get-breakpoints-map.ts"],"sourcesContent":["export { useBreakpoints } from './hooks/use-breakpoints';\nexport { useActiveBreakpoint } from './hooks/use-active-breakpoint';\nexport { useActivateBreakpoint } from './hooks/use-activate-breakpoint';\nexport { getBreakpoints } from './sync/get-breakpoints';\nexport { getBreakpointsMap } from './sync/get-breakpoints-map';\n\nexport type { BreakpointId, BreakpointSize, Breakpoint, BreakpointsMap } from './types';\n","import { __privateUseListenTo as useListenTo, v1ReadyEvent } from '@elementor/editor-v1-adapters';\n\nimport { getBreakpoints } from '../sync/get-breakpoints';\n\nexport function useBreakpoints() {\n\treturn useListenTo( v1ReadyEvent(), getBreakpoints );\n}\n","import { __ } from '@wordpress/i18n';\n\nimport { type Breakpoint, type BreakpointId, type ExtendedWindow } from '
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/hooks/use-breakpoints.ts","../src/sync/utils/get-breakpoints-by-widths.ts","../src/sync/get-breakpoints.ts","../src/hooks/use-active-breakpoint.ts","../src/hooks/use-activate-breakpoint.ts","../src/sync/get-breakpoints-tree.ts","../src/sync/get-breakpoints-map.ts"],"sourcesContent":["export { useBreakpoints } from './hooks/use-breakpoints';\nexport { useActiveBreakpoint } from './hooks/use-active-breakpoint';\nexport { useActivateBreakpoint } from './hooks/use-activate-breakpoint';\nexport { getBreakpoints } from './sync/get-breakpoints';\nexport { getBreakpointsTree } from './sync/get-breakpoints-tree';\nexport { getBreakpointsMap } from './sync/get-breakpoints-map';\n\nexport type { BreakpointId, BreakpointSize, Breakpoint, BreakpointsMap, BreakpointNode } from './types';\n","import { __privateUseListenTo as useListenTo, v1ReadyEvent } from '@elementor/editor-v1-adapters';\n\nimport { getBreakpoints } from '../sync/get-breakpoints';\n\nexport function useBreakpoints() {\n\treturn useListenTo( v1ReadyEvent(), getBreakpoints );\n}\n","import { __ } from '@wordpress/i18n';\n\nimport { type Breakpoint, type BreakpointId, type ExtendedWindow } from '../../types';\n\nexport function getBreakpointsByWidths(): { minWidth: Breakpoint[]; defaults: Breakpoint[]; maxWidth: Breakpoint[] } {\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\t\tminWidth: [],\n\t\t\tdefaults: [],\n\t\t\tmaxWidth: [],\n\t\t};\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 {\n\t\tminWidth: minWidth.sort( byWidth ),\n\t\tdefaults,\n\t\tmaxWidth: maxWidth.sort( byWidth ),\n\t};\n}\n","import { type Breakpoint } from '../types';\nimport { getBreakpointsByWidths } from './utils/get-breakpoints-by-widths';\n\nexport function getBreakpoints(): Breakpoint[] {\n\tconst { minWidth, defaults, maxWidth } = getBreakpointsByWidths();\n\treturn [ ...minWidth, ...defaults, ...maxWidth ];\n}\n","import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';\n\nimport { type BreakpointId, type 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 { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\n\nimport { type BreakpointId } from '../types';\n\nexport function useActivateBreakpoint() {\n\treturn useCallback( ( breakpoint: BreakpointId ) => {\n\t\treturn runCommand( 'panel/change-device-mode', { device: breakpoint } );\n\t}, [] );\n}\n","import { type Breakpoint, type BreakpointNode } from '../types';\nimport { getBreakpointsByWidths } from './utils/get-breakpoints-by-widths';\n\nexport function getBreakpointsTree(): BreakpointNode {\n\tconst { minWidth, defaults, maxWidth } = getBreakpointsByWidths();\n\n\tconst [ rootBreakpoint ] = defaults;\n\n\tconst rootNode: BreakpointNode = {\n\t\t...rootBreakpoint,\n\t\tchildren: [],\n\t};\n\n\t// gets an array of breakpoints and nest one in the prior breakpoint\n\tconst buildBranch = ( breakpoints: Breakpoint[] ) => {\n\t\tlet last: BreakpointNode = rootNode;\n\n\t\tbreakpoints.forEach( ( breakpoint ) => {\n\t\t\tconst newNode = {\n\t\t\t\t...breakpoint,\n\t\t\t\tchildren: [],\n\t\t\t};\n\n\t\t\tlast.children.push( newNode );\n\n\t\t\tlast = newNode;\n\t\t} );\n\t};\n\n\tbuildBranch( minWidth );\n\tbuildBranch( maxWidth );\n\n\treturn rootNode;\n}\n","import { type BreakpointsMap } from '../types';\nimport { getBreakpoints } from './get-breakpoints';\n\nexport function getBreakpointsMap(): BreakpointsMap {\n\tconst breakpoints = getBreakpoints();\n\n\tconst entries = breakpoints.map( ( breakpoint ) => [ breakpoint.id, breakpoint ] );\n\n\treturn Object.fromEntries( entries );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,gCAAkE;;;ACAlE,kBAAmB;AAIZ,SAAS,yBAAqG;AACpH,QAAM,EAAE,YAAY,IAAM,OAAsC,WAAW,QAAQ,cAAc,CAAC;AAElG,MAAK,CAAE,eAAe,OAAO,QAAS,WAAY,EAAE,WAAW,GAAI;AAClE,WAAO;AAAA,MACN,UAAU,CAAC;AAAA,MACX,UAAU,CAAC;AAAA,MACX,UAAU,CAAC;AAAA,IACZ;AAAA,EACD;AAEA,QAAM,WAAyB,CAAC;AAChC,QAAM,WAAyB,CAAC;AAEhC,QAAM,WAAyB;AAAA;AAAA,IAE9B,EAAE,IAAI,WAAW,WAAO,gBAAI,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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AEnC,QAAM,UAAU,YAAY,IAAK,CAAE,eAAgB,CAAE,WAAW,IAAI,UAAW,CAAE;AAEjF,SAAO,OAAO,YAAa,OAAQ;AACpC;","names":["useListenTo","import_editor_v1_adapters","useListenTo","import_editor_v1_adapters","runCommand"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
// src/hooks/use-breakpoints.ts
|
|
2
2
|
import { __privateUseListenTo as useListenTo, v1ReadyEvent } from "@elementor/editor-v1-adapters";
|
|
3
3
|
|
|
4
|
-
// src/sync/get-breakpoints.ts
|
|
4
|
+
// src/sync/utils/get-breakpoints-by-widths.ts
|
|
5
5
|
import { __ } from "@wordpress/i18n";
|
|
6
|
-
function
|
|
6
|
+
function getBreakpointsByWidths() {
|
|
7
7
|
const { breakpoints } = window.elementor?.config?.responsive || {};
|
|
8
8
|
if (!breakpoints || Object.entries(breakpoints).length === 0) {
|
|
9
|
-
return
|
|
9
|
+
return {
|
|
10
|
+
minWidth: [],
|
|
11
|
+
defaults: [],
|
|
12
|
+
maxWidth: []
|
|
13
|
+
};
|
|
10
14
|
}
|
|
11
15
|
const minWidth = [];
|
|
12
16
|
const maxWidth = [];
|
|
@@ -35,7 +39,17 @@ function getBreakpoints() {
|
|
|
35
39
|
const byWidth = (a, b) => {
|
|
36
40
|
return a.width && b.width ? b.width - a.width : 0;
|
|
37
41
|
};
|
|
38
|
-
return
|
|
42
|
+
return {
|
|
43
|
+
minWidth: minWidth.sort(byWidth),
|
|
44
|
+
defaults,
|
|
45
|
+
maxWidth: maxWidth.sort(byWidth)
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// src/sync/get-breakpoints.ts
|
|
50
|
+
function getBreakpoints() {
|
|
51
|
+
const { minWidth, defaults, maxWidth } = getBreakpointsByWidths();
|
|
52
|
+
return [...minWidth, ...defaults, ...maxWidth];
|
|
39
53
|
}
|
|
40
54
|
|
|
41
55
|
// src/hooks/use-breakpoints.ts
|
|
@@ -62,6 +76,30 @@ function useActivateBreakpoint() {
|
|
|
62
76
|
}, []);
|
|
63
77
|
}
|
|
64
78
|
|
|
79
|
+
// src/sync/get-breakpoints-tree.ts
|
|
80
|
+
function getBreakpointsTree() {
|
|
81
|
+
const { minWidth, defaults, maxWidth } = getBreakpointsByWidths();
|
|
82
|
+
const [rootBreakpoint] = defaults;
|
|
83
|
+
const rootNode = {
|
|
84
|
+
...rootBreakpoint,
|
|
85
|
+
children: []
|
|
86
|
+
};
|
|
87
|
+
const buildBranch = (breakpoints) => {
|
|
88
|
+
let last = rootNode;
|
|
89
|
+
breakpoints.forEach((breakpoint) => {
|
|
90
|
+
const newNode = {
|
|
91
|
+
...breakpoint,
|
|
92
|
+
children: []
|
|
93
|
+
};
|
|
94
|
+
last.children.push(newNode);
|
|
95
|
+
last = newNode;
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
buildBranch(minWidth);
|
|
99
|
+
buildBranch(maxWidth);
|
|
100
|
+
return rootNode;
|
|
101
|
+
}
|
|
102
|
+
|
|
65
103
|
// src/sync/get-breakpoints-map.ts
|
|
66
104
|
function getBreakpointsMap() {
|
|
67
105
|
const breakpoints = getBreakpoints();
|
|
@@ -71,6 +109,7 @@ function getBreakpointsMap() {
|
|
|
71
109
|
export {
|
|
72
110
|
getBreakpoints,
|
|
73
111
|
getBreakpointsMap,
|
|
112
|
+
getBreakpointsTree,
|
|
74
113
|
useActivateBreakpoint,
|
|
75
114
|
useActiveBreakpoint,
|
|
76
115
|
useBreakpoints
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/use-breakpoints.ts","../src/sync/get-breakpoints.ts","../src/hooks/use-active-breakpoint.ts","../src/hooks/use-activate-breakpoint.ts","../src/sync/get-breakpoints-map.ts"],"sourcesContent":["import { __privateUseListenTo as useListenTo, v1ReadyEvent } from '@elementor/editor-v1-adapters';\n\nimport { getBreakpoints } from '../sync/get-breakpoints';\n\nexport function useBreakpoints() {\n\treturn useListenTo( v1ReadyEvent(), getBreakpoints );\n}\n","import { __ } from '@wordpress/i18n';\n\nimport { type Breakpoint, type BreakpointId, type ExtendedWindow } from '
|
|
1
|
+
{"version":3,"sources":["../src/hooks/use-breakpoints.ts","../src/sync/utils/get-breakpoints-by-widths.ts","../src/sync/get-breakpoints.ts","../src/hooks/use-active-breakpoint.ts","../src/hooks/use-activate-breakpoint.ts","../src/sync/get-breakpoints-tree.ts","../src/sync/get-breakpoints-map.ts"],"sourcesContent":["import { __privateUseListenTo as useListenTo, v1ReadyEvent } from '@elementor/editor-v1-adapters';\n\nimport { getBreakpoints } from '../sync/get-breakpoints';\n\nexport function useBreakpoints() {\n\treturn useListenTo( v1ReadyEvent(), getBreakpoints );\n}\n","import { __ } from '@wordpress/i18n';\n\nimport { type Breakpoint, type BreakpointId, type ExtendedWindow } from '../../types';\n\nexport function getBreakpointsByWidths(): { minWidth: Breakpoint[]; defaults: Breakpoint[]; maxWidth: Breakpoint[] } {\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\t\tminWidth: [],\n\t\t\tdefaults: [],\n\t\t\tmaxWidth: [],\n\t\t};\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 {\n\t\tminWidth: minWidth.sort( byWidth ),\n\t\tdefaults,\n\t\tmaxWidth: maxWidth.sort( byWidth ),\n\t};\n}\n","import { type Breakpoint } from '../types';\nimport { getBreakpointsByWidths } from './utils/get-breakpoints-by-widths';\n\nexport function getBreakpoints(): Breakpoint[] {\n\tconst { minWidth, defaults, maxWidth } = getBreakpointsByWidths();\n\treturn [ ...minWidth, ...defaults, ...maxWidth ];\n}\n","import { __privateUseListenTo as useListenTo, windowEvent } from '@elementor/editor-v1-adapters';\n\nimport { type BreakpointId, type 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 { __privateRunCommand as runCommand } from '@elementor/editor-v1-adapters';\n\nimport { type BreakpointId } from '../types';\n\nexport function useActivateBreakpoint() {\n\treturn useCallback( ( breakpoint: BreakpointId ) => {\n\t\treturn runCommand( 'panel/change-device-mode', { device: breakpoint } );\n\t}, [] );\n}\n","import { type Breakpoint, type BreakpointNode } from '../types';\nimport { getBreakpointsByWidths } from './utils/get-breakpoints-by-widths';\n\nexport function getBreakpointsTree(): BreakpointNode {\n\tconst { minWidth, defaults, maxWidth } = getBreakpointsByWidths();\n\n\tconst [ rootBreakpoint ] = defaults;\n\n\tconst rootNode: BreakpointNode = {\n\t\t...rootBreakpoint,\n\t\tchildren: [],\n\t};\n\n\t// gets an array of breakpoints and nest one in the prior breakpoint\n\tconst buildBranch = ( breakpoints: Breakpoint[] ) => {\n\t\tlet last: BreakpointNode = rootNode;\n\n\t\tbreakpoints.forEach( ( breakpoint ) => {\n\t\t\tconst newNode = {\n\t\t\t\t...breakpoint,\n\t\t\t\tchildren: [],\n\t\t\t};\n\n\t\t\tlast.children.push( newNode );\n\n\t\t\tlast = newNode;\n\t\t} );\n\t};\n\n\tbuildBranch( minWidth );\n\tbuildBranch( maxWidth );\n\n\treturn rootNode;\n}\n","import { type BreakpointsMap } from '../types';\nimport { getBreakpoints } from './get-breakpoints';\n\nexport function getBreakpointsMap(): BreakpointsMap {\n\tconst breakpoints = getBreakpoints();\n\n\tconst entries = breakpoints.map( ( breakpoint ) => [ breakpoint.id, breakpoint ] );\n\n\treturn Object.fromEntries( entries );\n}\n"],"mappings":";AAAA,SAAS,wBAAwB,aAAa,oBAAoB;;;ACAlE,SAAS,UAAU;AAIZ,SAAS,yBAAqG;AACpH,QAAM,EAAE,YAAY,IAAM,OAAsC,WAAW,QAAQ,cAAc,CAAC;AAElG,MAAK,CAAE,eAAe,OAAO,QAAS,WAAY,EAAE,WAAW,GAAI;AAClE,WAAO;AAAA,MACN,UAAU,CAAC;AAAA,MACX,UAAU,CAAC;AAAA,MACX,UAAU,CAAC;AAAA,IACZ;AAAA,EACD;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;AAA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3B,QAAM,WAA2B;AAAA,IAChC,GAAG;AAAA,IACH,UAAU,CAAC;AAAA,EACZ;AAGA,QAAM,cAAc,CAAE,gBAA+B;AACpD,QAAI,OAAuB;AAE3B,gBAAY,QAAS,CAAE,eAAgB;AACtC,YAAM,UAAU;AAAA,QACf,GAAG;AAAA,QACH,UAAU,CAAC;AAAA,MACZ;AAEA,WAAK,SAAS,KAAM,OAAQ;AAE5B,aAAO;AAAA,IACR,CAAE;AAAA,EACH;AAEA,cAAa,QAAS;AACtB,cAAa,QAAS;AAEtB,SAAO;AACR;;;AC9BO,SAAS,oBAAoC;AACnD,QAAM,cAAc,eAAe;AAEnC,QAAM,UAAU,YAAY,IAAK,CAAE,eAAgB,CAAE,WAAW,IAAI,UAAW,CAAE;AAEjF,SAAO,OAAO,YAAa,OAAQ;AACpC;","names":["useListenTo"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-responsive",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "Elementor Team",
|
|
6
6
|
"homepage": "https://elementor.com/",
|
|
@@ -39,10 +39,13 @@
|
|
|
39
39
|
"dev": "tsup --config=../../tsup.dev.ts"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@elementor/editor-v1-adapters": "0.
|
|
42
|
+
"@elementor/editor-v1-adapters": "0.10.1",
|
|
43
43
|
"@wordpress/i18n": "^5.13.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": "^18.3.1"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"tsup": "^8.3.5"
|
|
47
50
|
}
|
|
48
51
|
}
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ export { useBreakpoints } from './hooks/use-breakpoints';
|
|
|
2
2
|
export { useActiveBreakpoint } from './hooks/use-active-breakpoint';
|
|
3
3
|
export { useActivateBreakpoint } from './hooks/use-activate-breakpoint';
|
|
4
4
|
export { getBreakpoints } from './sync/get-breakpoints';
|
|
5
|
+
export { getBreakpointsTree } from './sync/get-breakpoints-tree';
|
|
5
6
|
export { getBreakpointsMap } from './sync/get-breakpoints-map';
|
|
6
7
|
|
|
7
|
-
export type { BreakpointId, BreakpointSize, Breakpoint, BreakpointsMap } from './types';
|
|
8
|
+
export type { BreakpointId, BreakpointSize, Breakpoint, BreakpointsMap, BreakpointNode } from './types';
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type Breakpoint, type BreakpointNode } from '../types';
|
|
2
|
+
import { getBreakpointsByWidths } from './utils/get-breakpoints-by-widths';
|
|
3
|
+
|
|
4
|
+
export function getBreakpointsTree(): BreakpointNode {
|
|
5
|
+
const { minWidth, defaults, maxWidth } = getBreakpointsByWidths();
|
|
6
|
+
|
|
7
|
+
const [ rootBreakpoint ] = defaults;
|
|
8
|
+
|
|
9
|
+
const rootNode: BreakpointNode = {
|
|
10
|
+
...rootBreakpoint,
|
|
11
|
+
children: [],
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// gets an array of breakpoints and nest one in the prior breakpoint
|
|
15
|
+
const buildBranch = ( breakpoints: Breakpoint[] ) => {
|
|
16
|
+
let last: BreakpointNode = rootNode;
|
|
17
|
+
|
|
18
|
+
breakpoints.forEach( ( breakpoint ) => {
|
|
19
|
+
const newNode = {
|
|
20
|
+
...breakpoint,
|
|
21
|
+
children: [],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
last.children.push( newNode );
|
|
25
|
+
|
|
26
|
+
last = newNode;
|
|
27
|
+
} );
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
buildBranch( minWidth );
|
|
31
|
+
buildBranch( maxWidth );
|
|
32
|
+
|
|
33
|
+
return rootNode;
|
|
34
|
+
}
|
|
@@ -1,46 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Breakpoint } from '../types';
|
|
2
|
+
import { getBreakpointsByWidths } from './utils/get-breakpoints-by-widths';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { breakpoints } = ( window as unknown as ExtendedWindow ).elementor?.config?.responsive || {};
|
|
7
|
-
|
|
8
|
-
if ( ! breakpoints || Object.entries( breakpoints ).length === 0 ) {
|
|
9
|
-
return [];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const minWidth: Breakpoint[] = [];
|
|
13
|
-
const maxWidth: Breakpoint[] = [];
|
|
14
|
-
|
|
15
|
-
const defaults: Breakpoint[] = [
|
|
16
|
-
// Desktop breakpoint is not included in V1 config.
|
|
17
|
-
{ id: 'desktop', label: __( 'Desktop', 'elementor' ) },
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
Object.entries( breakpoints ).forEach( ( [ id, v1Breakpoint ] ) => {
|
|
21
|
-
if ( ! v1Breakpoint.is_enabled ) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const breakpoint: Breakpoint = {
|
|
26
|
-
id: id as BreakpointId,
|
|
27
|
-
label: v1Breakpoint.label,
|
|
28
|
-
width: v1Breakpoint.value,
|
|
29
|
-
type: v1Breakpoint.direction === 'min' ? 'min-width' : 'max-width',
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
if ( ! breakpoint.width ) {
|
|
33
|
-
defaults.push( breakpoint );
|
|
34
|
-
} else if ( breakpoint.type === 'min-width' ) {
|
|
35
|
-
minWidth.push( breakpoint );
|
|
36
|
-
} else if ( breakpoint.type === 'max-width' ) {
|
|
37
|
-
maxWidth.push( breakpoint );
|
|
38
|
-
}
|
|
39
|
-
} );
|
|
40
|
-
|
|
41
|
-
const byWidth = ( a: Breakpoint, b: Breakpoint ) => {
|
|
42
|
-
return a.width && b.width ? b.width - a.width : 0;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
return [ ...minWidth.sort( byWidth ), ...defaults, ...maxWidth.sort( byWidth ) ];
|
|
4
|
+
export function getBreakpoints(): Breakpoint[] {
|
|
5
|
+
const { minWidth, defaults, maxWidth } = getBreakpointsByWidths();
|
|
6
|
+
return [ ...minWidth, ...defaults, ...maxWidth ];
|
|
46
7
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { __ } from '@wordpress/i18n';
|
|
2
|
+
|
|
3
|
+
import { type Breakpoint, type BreakpointId, type ExtendedWindow } from '../../types';
|
|
4
|
+
|
|
5
|
+
export function getBreakpointsByWidths(): { minWidth: Breakpoint[]; defaults: Breakpoint[]; maxWidth: Breakpoint[] } {
|
|
6
|
+
const { breakpoints } = ( window as unknown as ExtendedWindow ).elementor?.config?.responsive || {};
|
|
7
|
+
|
|
8
|
+
if ( ! breakpoints || Object.entries( breakpoints ).length === 0 ) {
|
|
9
|
+
return {
|
|
10
|
+
minWidth: [],
|
|
11
|
+
defaults: [],
|
|
12
|
+
maxWidth: [],
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const minWidth: Breakpoint[] = [];
|
|
17
|
+
const maxWidth: Breakpoint[] = [];
|
|
18
|
+
|
|
19
|
+
const defaults: Breakpoint[] = [
|
|
20
|
+
// Desktop breakpoint is not included in V1 config.
|
|
21
|
+
{ id: 'desktop', label: __( 'Desktop', 'elementor' ) },
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
Object.entries( breakpoints ).forEach( ( [ id, v1Breakpoint ] ) => {
|
|
25
|
+
if ( ! v1Breakpoint.is_enabled ) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const breakpoint: Breakpoint = {
|
|
30
|
+
id: id as BreakpointId,
|
|
31
|
+
label: v1Breakpoint.label,
|
|
32
|
+
width: v1Breakpoint.value,
|
|
33
|
+
type: v1Breakpoint.direction === 'min' ? 'min-width' : 'max-width',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
if ( ! breakpoint.width ) {
|
|
37
|
+
defaults.push( breakpoint );
|
|
38
|
+
} else if ( breakpoint.type === 'min-width' ) {
|
|
39
|
+
minWidth.push( breakpoint );
|
|
40
|
+
} else if ( breakpoint.type === 'max-width' ) {
|
|
41
|
+
maxWidth.push( breakpoint );
|
|
42
|
+
}
|
|
43
|
+
} );
|
|
44
|
+
|
|
45
|
+
const byWidth = ( a: Breakpoint, b: Breakpoint ) => {
|
|
46
|
+
return a.width && b.width ? b.width - a.width : 0;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
minWidth: minWidth.sort( byWidth ),
|
|
51
|
+
defaults,
|
|
52
|
+
maxWidth: maxWidth.sort( byWidth ),
|
|
53
|
+
};
|
|
54
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -2,7 +2,7 @@ export type BreakpointId = 'widescreen' | 'desktop' | 'laptop' | 'tablet_extra'
|
|
|
2
2
|
|
|
3
3
|
export type BreakpointSize = number;
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
type BreakpointLabel = string;
|
|
6
6
|
|
|
7
7
|
export type Breakpoint = {
|
|
8
8
|
id: BreakpointId;
|
|
@@ -13,7 +13,11 @@ export type Breakpoint = {
|
|
|
13
13
|
|
|
14
14
|
export type BreakpointsMap = Record< BreakpointId, Breakpoint >;
|
|
15
15
|
|
|
16
|
-
export type
|
|
16
|
+
export type BreakpointNode = Breakpoint & {
|
|
17
|
+
children: BreakpointNode[];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type V1Breakpoint = {
|
|
17
21
|
direction: 'min' | 'max';
|
|
18
22
|
is_enabled: boolean;
|
|
19
23
|
value: BreakpointSize;
|