@elementor/editor-variables 4.2.0-842 → 4.2.0-843

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elementor/editor-variables",
3
- "version": "4.2.0-842",
3
+ "version": "4.2.0-843",
4
4
  "private": false,
5
5
  "author": "Elementor Team",
6
6
  "homepage": "https://elementor.com/",
@@ -39,22 +39,22 @@
39
39
  "dev": "tsup --config=../../tsup.dev.ts"
40
40
  },
41
41
  "dependencies": {
42
- "@elementor/editor": "4.2.0-842",
43
- "@elementor/editor-canvas": "4.2.0-842",
44
- "@elementor/editor-controls": "4.2.0-842",
45
- "@elementor/editor-current-user": "4.2.0-842",
46
- "@elementor/editor-mcp": "4.2.0-842",
47
- "@elementor/editor-panels": "4.2.0-842",
48
- "@elementor/editor-props": "4.2.0-842",
49
- "@elementor/editor-ui": "4.2.0-842",
50
- "@elementor/editor-v1-adapters": "4.2.0-842",
51
- "@elementor/menus": "4.2.0-842",
52
- "@elementor/http-client": "4.2.0-842",
42
+ "@elementor/editor": "4.2.0-843",
43
+ "@elementor/editor-canvas": "4.2.0-843",
44
+ "@elementor/editor-controls": "4.2.0-843",
45
+ "@elementor/editor-current-user": "4.2.0-843",
46
+ "@elementor/editor-mcp": "4.2.0-843",
47
+ "@elementor/editor-panels": "4.2.0-843",
48
+ "@elementor/editor-props": "4.2.0-843",
49
+ "@elementor/editor-ui": "4.2.0-843",
50
+ "@elementor/editor-v1-adapters": "4.2.0-843",
51
+ "@elementor/menus": "4.2.0-843",
52
+ "@elementor/http-client": "4.2.0-843",
53
53
  "@elementor/icons": "~1.75.1",
54
- "@elementor/events": "4.2.0-842",
55
- "@elementor/schema": "4.2.0-842",
54
+ "@elementor/events": "4.2.0-843",
55
+ "@elementor/schema": "4.2.0-843",
56
56
  "@elementor/ui": "1.37.5",
57
- "@elementor/utils": "4.2.0-842",
57
+ "@elementor/utils": "4.2.0-843",
58
58
  "@wordpress/i18n": "^5.13.0"
59
59
  },
60
60
  "peerDependencies": {
@@ -2,28 +2,17 @@ import { useEffect } from 'react';
2
2
  import { GLOBAL_STYLES_IMPORTED_EVENT } from '@elementor/editor-canvas';
3
3
 
4
4
  import { service } from '../service';
5
- import { styleVariablesRepository } from '../style-variables-repository';
6
5
 
7
6
  export function GlobalStylesImportListener() {
8
7
  useEffect( () => {
9
- const handleGlobalStylesImported = ( event: CustomEvent ) => {
10
- const importedVars = event.detail?.global_variables;
11
-
12
- if ( ! importedVars ) {
13
- return;
14
- }
15
-
16
- if ( importedVars.data && typeof importedVars.data === 'object' ) {
17
- styleVariablesRepository.update( importedVars.data );
18
- }
19
-
8
+ const handleGlobalStylesImported = () => {
20
9
  service.load();
21
10
  };
22
11
 
23
- window.addEventListener( GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported as EventListener );
12
+ window.addEventListener( GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported );
24
13
 
25
14
  return () => {
26
- window.removeEventListener( GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported as EventListener );
15
+ window.removeEventListener( GLOBAL_STYLES_IMPORTED_EVENT, handleGlobalStylesImported );
27
16
  };
28
17
  }, [] );
29
18
 
@@ -1,9 +1,9 @@
1
- import { useCallback, useState } from 'react';
1
+ import { useCallback, useEffect, useState } from 'react';
2
2
 
3
3
  import { generateTempId } from '../../../batch-operations';
4
4
  import { getVariables } from '../../../hooks/use-prop-variables';
5
5
  import { service } from '../../../service';
6
- import { type TVariablesList } from '../../../storage';
6
+ import { STORAGE_UPDATED_EVENT, type TVariablesList } from '../../../storage';
7
7
  import { generateDuplicateLabel } from '../../../utils/duplicate-label';
8
8
  import { filterBySearch } from '../../../utils/filter-by-search';
9
9
  import { applySelectionFilters, variablesToList } from '../../../utils/variables-to-list';
@@ -17,6 +17,20 @@ export const useVariablesManagerState = () => {
17
17
  const [ isSaving, setIsSaving ] = useState( false );
18
18
  const [ searchValue, setSearchValue ] = useState( '' );
19
19
 
20
+ useEffect( () => {
21
+ const handleStorageUpdated = () => {
22
+ setVariables( getVariables( false ) );
23
+ setDeletedVariables( [] );
24
+ setIsDirty( false );
25
+ };
26
+
27
+ window.addEventListener( STORAGE_UPDATED_EVENT, handleStorageUpdated );
28
+
29
+ return () => {
30
+ window.removeEventListener( STORAGE_UPDATED_EVENT, handleStorageUpdated );
31
+ };
32
+ }, [] );
33
+
20
34
  const handleOnChange = useCallback(
21
35
  ( newVariables: TVariablesList ) => {
22
36
  setVariables( { ...variables, ...newVariables } );
@@ -2,7 +2,7 @@ import { type MCPRegistryEntry } from '@elementor/editor-mcp';
2
2
  import { __privateListenTo as listenTo, commandEndEvent } from '@elementor/editor-v1-adapters';
3
3
 
4
4
  import { service } from '../service';
5
- import { type TVariable } from '../storage';
5
+ import { STORAGE_UPDATED_EVENT, type TVariable } from '../storage';
6
6
 
7
7
  export const GLOBAL_VARIABLES_URI = 'elementor://global-variables';
8
8
 
@@ -47,7 +47,7 @@ export const initVariablesResource = ( variablesMcpEntry: MCPRegistryEntry, canv
47
47
  }
48
48
  );
49
49
 
50
- window.addEventListener( 'variables:updated', notifyGlobalVariablesUpdated );
50
+ window.addEventListener( STORAGE_UPDATED_EVENT, notifyGlobalVariablesUpdated );
51
51
 
52
52
  listenTo( commandEndEvent( 'document/save/update' ), notifyGlobalVariablesUpdated );
53
53
  } );
package/src/storage.ts CHANGED
@@ -13,6 +13,8 @@ export type TVariablesList = Record< string, TVariable >;
13
13
  const STORAGE_KEY = 'elementor-global-variables';
14
14
  const STORAGE_WATERMARK_KEY = 'elementor-global-variables-watermark';
15
15
 
16
+ export const STORAGE_UPDATED_EVENT = 'variables:updated';
17
+
16
18
  export const OP_RW = 'RW';
17
19
  const OP_RO = 'RO';
18
20
 
@@ -23,7 +25,7 @@ export class Storage {
23
25
  };
24
26
 
25
27
  notifyChange() {
26
- window.dispatchEvent( new Event( 'variables:updated' ) );
28
+ window.dispatchEvent( new Event( STORAGE_UPDATED_EVENT ) );
27
29
  }
28
30
 
29
31
  constructor() {