@elementor/editor-ui 4.4.0-1141 → 4.4.0-1142
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.d.mts
CHANGED
|
@@ -36,8 +36,11 @@ type IntroductionModalProps = React$1.PropsWithChildren<{
|
|
|
36
36
|
}>;
|
|
37
37
|
declare const IntroductionModal: ({ open, handleClose, title, children }: IntroductionModalProps) => React$1.JSX.Element;
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
type ColorScheme = 'auto' | 'dark' | 'light';
|
|
40
|
+
|
|
41
|
+
declare function ThemeProvider({ children, colorScheme: staticColorScheme, }: {
|
|
40
42
|
children: React$1.ReactNode;
|
|
43
|
+
colorScheme?: ColorScheme;
|
|
41
44
|
}): React$1.JSX.Element;
|
|
42
45
|
|
|
43
46
|
type MenuListItemProps = MenuItemProps & {
|
package/dist/index.d.ts
CHANGED
|
@@ -36,8 +36,11 @@ type IntroductionModalProps = React$1.PropsWithChildren<{
|
|
|
36
36
|
}>;
|
|
37
37
|
declare const IntroductionModal: ({ open, handleClose, title, children }: IntroductionModalProps) => React$1.JSX.Element;
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
type ColorScheme = 'auto' | 'dark' | 'light';
|
|
40
|
+
|
|
41
|
+
declare function ThemeProvider({ children, colorScheme: staticColorScheme, }: {
|
|
40
42
|
children: React$1.ReactNode;
|
|
43
|
+
colorScheme?: ColorScheme;
|
|
41
44
|
}): React$1.JSX.Element;
|
|
42
45
|
|
|
43
46
|
type MenuListItemProps = MenuItemProps & {
|
package/dist/index.js
CHANGED
|
@@ -240,12 +240,18 @@ var import_ui6 = require("@elementor/ui");
|
|
|
240
240
|
// src/hooks/use-color-scheme.ts
|
|
241
241
|
var import_react5 = require("react");
|
|
242
242
|
var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
|
|
243
|
-
function useColorScheme() {
|
|
243
|
+
function useColorScheme(staticColorScheme) {
|
|
244
244
|
const [colorScheme, setColorScheme] = (0, import_react5.useState)(() => getV1ColorScheme());
|
|
245
245
|
(0, import_react5.useEffect)(() => {
|
|
246
|
+
if (staticColorScheme) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
246
249
|
return (0, import_editor_v1_adapters.__privateListenTo)((0, import_editor_v1_adapters.v1ReadyEvent)(), () => setColorScheme(getV1ColorScheme()));
|
|
247
|
-
}, []);
|
|
250
|
+
}, [staticColorScheme]);
|
|
248
251
|
(0, import_react5.useEffect)(() => {
|
|
252
|
+
if (staticColorScheme) {
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
249
255
|
return (0, import_editor_v1_adapters.__privateListenTo)((0, import_editor_v1_adapters.commandEndEvent)("document/elements/settings"), (e) => {
|
|
250
256
|
const event = e;
|
|
251
257
|
const isColorScheme = event.args?.settings && "ui_theme" in event.args.settings;
|
|
@@ -253,8 +259,8 @@ function useColorScheme() {
|
|
|
253
259
|
setColorScheme(getV1ColorScheme());
|
|
254
260
|
}
|
|
255
261
|
});
|
|
256
|
-
}, []);
|
|
257
|
-
return colorScheme;
|
|
262
|
+
}, [staticColorScheme]);
|
|
263
|
+
return staticColorScheme || colorScheme;
|
|
258
264
|
}
|
|
259
265
|
function getV1ColorScheme() {
|
|
260
266
|
return window.elementor?.getPreferences?.("ui_theme") || "auto";
|
|
@@ -262,8 +268,11 @@ function getV1ColorScheme() {
|
|
|
262
268
|
|
|
263
269
|
// src/components/theme-provider.tsx
|
|
264
270
|
var EDITOR_PALETTE = "unstable";
|
|
265
|
-
function ThemeProvider({
|
|
266
|
-
|
|
271
|
+
function ThemeProvider({
|
|
272
|
+
children,
|
|
273
|
+
colorScheme: staticColorScheme
|
|
274
|
+
}) {
|
|
275
|
+
const colorScheme = useColorScheme(staticColorScheme);
|
|
267
276
|
return /* @__PURE__ */ React5.createElement(import_ui6.ThemeProvider, { colorScheme, palette: EDITOR_PALETTE }, children);
|
|
268
277
|
}
|
|
269
278
|
|
package/dist/index.mjs
CHANGED
|
@@ -178,12 +178,18 @@ import {
|
|
|
178
178
|
commandEndEvent,
|
|
179
179
|
v1ReadyEvent
|
|
180
180
|
} from "@elementor/editor-v1-adapters";
|
|
181
|
-
function useColorScheme() {
|
|
181
|
+
function useColorScheme(staticColorScheme) {
|
|
182
182
|
const [colorScheme, setColorScheme] = useState4(() => getV1ColorScheme());
|
|
183
183
|
useEffect2(() => {
|
|
184
|
+
if (staticColorScheme) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
184
187
|
return listenTo(v1ReadyEvent(), () => setColorScheme(getV1ColorScheme()));
|
|
185
|
-
}, []);
|
|
188
|
+
}, [staticColorScheme]);
|
|
186
189
|
useEffect2(() => {
|
|
190
|
+
if (staticColorScheme) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
187
193
|
return listenTo(commandEndEvent("document/elements/settings"), (e) => {
|
|
188
194
|
const event = e;
|
|
189
195
|
const isColorScheme = event.args?.settings && "ui_theme" in event.args.settings;
|
|
@@ -191,8 +197,8 @@ function useColorScheme() {
|
|
|
191
197
|
setColorScheme(getV1ColorScheme());
|
|
192
198
|
}
|
|
193
199
|
});
|
|
194
|
-
}, []);
|
|
195
|
-
return colorScheme;
|
|
200
|
+
}, [staticColorScheme]);
|
|
201
|
+
return staticColorScheme || colorScheme;
|
|
196
202
|
}
|
|
197
203
|
function getV1ColorScheme() {
|
|
198
204
|
return window.elementor?.getPreferences?.("ui_theme") || "auto";
|
|
@@ -200,8 +206,11 @@ function getV1ColorScheme() {
|
|
|
200
206
|
|
|
201
207
|
// src/components/theme-provider.tsx
|
|
202
208
|
var EDITOR_PALETTE = "unstable";
|
|
203
|
-
function ThemeProvider({
|
|
204
|
-
|
|
209
|
+
function ThemeProvider({
|
|
210
|
+
children,
|
|
211
|
+
colorScheme: staticColorScheme
|
|
212
|
+
}) {
|
|
213
|
+
const colorScheme = useColorScheme(staticColorScheme);
|
|
205
214
|
return /* @__PURE__ */ React5.createElement(ThemeProviderBase, { colorScheme, palette: EDITOR_PALETTE }, children);
|
|
206
215
|
}
|
|
207
216
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elementor/editor-ui",
|
|
3
3
|
"description": "Elementor Editor UI",
|
|
4
|
-
"version": "4.4.0-
|
|
4
|
+
"version": "4.4.0-1142",
|
|
5
5
|
"private": false,
|
|
6
6
|
"author": "Elementor Team",
|
|
7
7
|
"homepage": "https://elementor.com/",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"react-dom": "^18.3.1"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@elementor/editor-v1-adapters": "4.4.0-
|
|
40
|
+
"@elementor/editor-v1-adapters": "4.4.0-1142",
|
|
41
41
|
"@elementor/icons": "~1.78.1",
|
|
42
|
-
"@elementor/ui": "1.41.
|
|
42
|
+
"@elementor/ui": "1.41.4",
|
|
43
43
|
"@tanstack/react-virtual": "^3.13.3",
|
|
44
44
|
"@wordpress/i18n": "^5.13.0"
|
|
45
45
|
},
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { ThemeProvider as ThemeProviderBase, type ThemeProviderProps } from '@elementor/ui';
|
|
3
3
|
|
|
4
|
-
import { useColorScheme } from '../hooks/use-color-scheme';
|
|
4
|
+
import { type ColorScheme, useColorScheme } from '../hooks/use-color-scheme';
|
|
5
5
|
|
|
6
6
|
const EDITOR_PALETTE: ThemeProviderProps[ 'palette' ] = 'unstable';
|
|
7
7
|
|
|
8
|
-
export default function ThemeProvider( {
|
|
9
|
-
|
|
8
|
+
export default function ThemeProvider( {
|
|
9
|
+
children,
|
|
10
|
+
colorScheme: staticColorScheme,
|
|
11
|
+
}: {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
colorScheme?: ColorScheme;
|
|
14
|
+
} ) {
|
|
15
|
+
const colorScheme = useColorScheme( staticColorScheme );
|
|
10
16
|
|
|
11
17
|
return (
|
|
12
18
|
<ThemeProviderBase colorScheme={ colorScheme } palette={ EDITOR_PALETTE }>
|
|
@@ -82,6 +82,101 @@ describe( '@elementor/editor - useColorScheme', () => {
|
|
|
82
82
|
// Assert.
|
|
83
83
|
expect( result.current ).toBe( 'auto' );
|
|
84
84
|
} );
|
|
85
|
+
|
|
86
|
+
describe( 'static color scheme', () => {
|
|
87
|
+
it( 'should use the static color scheme over the V1 preference', () => {
|
|
88
|
+
// Arrange.
|
|
89
|
+
mockV1ColorScheme( 'light' );
|
|
90
|
+
|
|
91
|
+
// Act.
|
|
92
|
+
const { result } = renderHook( () => useColorScheme( 'dark' ) );
|
|
93
|
+
|
|
94
|
+
// Assert.
|
|
95
|
+
expect( result.current ).toBe( 'dark' );
|
|
96
|
+
} );
|
|
97
|
+
|
|
98
|
+
it( 'should follow the V1 preference when no static color scheme is provided', () => {
|
|
99
|
+
// Arrange.
|
|
100
|
+
mockV1ColorScheme( 'light' );
|
|
101
|
+
|
|
102
|
+
// Act.
|
|
103
|
+
const { result } = renderHook( () => useColorScheme( undefined ) );
|
|
104
|
+
|
|
105
|
+
// Assert.
|
|
106
|
+
expect( result.current ).toBe( 'light' );
|
|
107
|
+
} );
|
|
108
|
+
|
|
109
|
+
it( 'should keep the static color scheme on V1 ready', () => {
|
|
110
|
+
// Arrange.
|
|
111
|
+
mockV1ColorScheme( 'light' );
|
|
112
|
+
|
|
113
|
+
const { result } = renderHook( () => useColorScheme( 'dark' ) );
|
|
114
|
+
|
|
115
|
+
// Act.
|
|
116
|
+
act( () => {
|
|
117
|
+
dispatchEvent( new CustomEvent( 'elementor/initialized' ) );
|
|
118
|
+
} );
|
|
119
|
+
|
|
120
|
+
// Assert.
|
|
121
|
+
expect( result.current ).toBe( 'dark' );
|
|
122
|
+
} );
|
|
123
|
+
|
|
124
|
+
it( 'should keep the static color scheme on V1 preference change', () => {
|
|
125
|
+
// Arrange.
|
|
126
|
+
mockV1ColorScheme( 'light' );
|
|
127
|
+
|
|
128
|
+
const { result } = renderHook( () => useColorScheme( 'dark' ) );
|
|
129
|
+
|
|
130
|
+
// Act.
|
|
131
|
+
act( () => {
|
|
132
|
+
mockV1ColorScheme( 'auto' );
|
|
133
|
+
|
|
134
|
+
dispatchEvent(
|
|
135
|
+
new CustomEvent( 'elementor/commands/run/after', {
|
|
136
|
+
detail: {
|
|
137
|
+
command: 'document/elements/settings',
|
|
138
|
+
args: {
|
|
139
|
+
container: {
|
|
140
|
+
id: 'editorPreferences_settings',
|
|
141
|
+
},
|
|
142
|
+
settings: {
|
|
143
|
+
ui_theme: 'auto',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
} )
|
|
148
|
+
);
|
|
149
|
+
} );
|
|
150
|
+
|
|
151
|
+
// Assert.
|
|
152
|
+
expect( result.current ).toBe( 'dark' );
|
|
153
|
+
} );
|
|
154
|
+
|
|
155
|
+
it( 'should update the result when the static color scheme changes', () => {
|
|
156
|
+
// Arrange.
|
|
157
|
+
mockV1ColorScheme( 'light' );
|
|
158
|
+
|
|
159
|
+
const { result, rerender } = renderHook(
|
|
160
|
+
( { staticColorScheme }: { staticColorScheme?: ColorScheme } ) => useColorScheme( staticColorScheme ),
|
|
161
|
+
{ initialProps: { staticColorScheme: 'dark' as ColorScheme | undefined } }
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// Assert - Before change.
|
|
165
|
+
expect( result.current ).toBe( 'dark' );
|
|
166
|
+
|
|
167
|
+
// Act - Change to another static value.
|
|
168
|
+
rerender( { staticColorScheme: 'auto' } );
|
|
169
|
+
|
|
170
|
+
// Assert.
|
|
171
|
+
expect( result.current ).toBe( 'auto' );
|
|
172
|
+
|
|
173
|
+
// Act - Remove the static value.
|
|
174
|
+
rerender( { staticColorScheme: undefined } );
|
|
175
|
+
|
|
176
|
+
// Assert.
|
|
177
|
+
expect( result.current ).toBe( 'light' );
|
|
178
|
+
} );
|
|
179
|
+
} );
|
|
85
180
|
} );
|
|
86
181
|
|
|
87
182
|
function mockV1ColorScheme( colorScheme: ColorScheme ) {
|
|
@@ -14,14 +14,22 @@ export type ExtendedWindow = Window & {
|
|
|
14
14
|
};
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
export function useColorScheme() {
|
|
17
|
+
export function useColorScheme( staticColorScheme?: ColorScheme ) {
|
|
18
18
|
const [ colorScheme, setColorScheme ] = useState< ColorScheme >( () => getV1ColorScheme() );
|
|
19
19
|
|
|
20
20
|
useEffect( () => {
|
|
21
|
+
if ( staticColorScheme ) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
21
25
|
return listenTo( v1ReadyEvent(), () => setColorScheme( getV1ColorScheme() ) );
|
|
22
|
-
}, [] );
|
|
26
|
+
}, [ staticColorScheme ] );
|
|
23
27
|
|
|
24
28
|
useEffect( () => {
|
|
29
|
+
if ( staticColorScheme ) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
return listenTo( commandEndEvent( 'document/elements/settings' ), ( e ) => {
|
|
26
34
|
const event = e as CommandEvent< {
|
|
27
35
|
settings: {
|
|
@@ -36,9 +44,9 @@ export function useColorScheme() {
|
|
|
36
44
|
setColorScheme( getV1ColorScheme() );
|
|
37
45
|
}
|
|
38
46
|
} );
|
|
39
|
-
}, [] );
|
|
47
|
+
}, [ staticColorScheme ] );
|
|
40
48
|
|
|
41
|
-
return colorScheme;
|
|
49
|
+
return staticColorScheme || colorScheme;
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
function getV1ColorScheme() {
|