@elementor/editor-styles-repository 0.8.3 → 0.8.4
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/.turbo/turbo-build.log +10 -10
- package/CHANGELOG.md +14 -0
- package/dist/index.d.mts +45 -17
- package/dist/index.d.ts +45 -17
- package/dist/index.js +109 -51
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -49
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -5
- package/src/__tests__/{elements-styles-provider.test.ts → document-elements-styles-provider.test.ts} +33 -21
- package/src/__tests__/element-base-styles-provider.test.ts +3 -3
- package/src/errors.ts +5 -0
- package/src/hooks/use-create-actions-by-provider.ts +1 -1
- package/src/index.ts +10 -11
- package/src/init.ts +3 -3
- package/src/{elements-styles-provider.ts → providers/document-elements-styles-provider.ts} +29 -16
- package/src/{element-base-styles-provider.ts → providers/element-base-styles-provider.ts} +6 -10
- package/src/types.ts +33 -0
- package/src/utils/__tests__/create-styles-repository.test.ts +17 -93
- package/src/utils/__tests__/validate-style-label.test.ts +37 -0
- package/src/utils/create-styles-provider.ts +51 -0
- package/src/utils/create-styles-repository.ts +3 -58
- package/src/utils/is-elements-styles-provider.ts +5 -0
- package/src/utils/validate-style-label.ts +38 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @elementor/editor-styles-repository@0.8.
|
|
2
|
+
> @elementor/editor-styles-repository@0.8.4 build
|
|
3
3
|
> tsup --config=../../tsup.build.ts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -10,13 +10,13 @@
|
|
|
10
10
|
[34mCLI[39m Cleaning output folder
|
|
11
11
|
[34mESM[39m Build start
|
|
12
12
|
[34mCJS[39m Build start
|
|
13
|
-
[
|
|
14
|
-
[
|
|
15
|
-
[
|
|
16
|
-
[
|
|
17
|
-
[
|
|
18
|
-
[
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m6.33 KB[39m
|
|
14
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m12.77 KB[39m
|
|
15
|
+
[32mESM[39m ⚡️ Build success in 120ms
|
|
16
|
+
[32mCJS[39m [1mdist/index.js [22m[32m8.15 KB[39m
|
|
17
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m13.61 KB[39m
|
|
18
|
+
[32mCJS[39m ⚡️ Build success in 124ms
|
|
19
19
|
[34mDTS[39m Build start
|
|
20
|
-
[32mDTS[39m ⚡️ Build success in
|
|
21
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[
|
|
22
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
20
|
+
[32mDTS[39m ⚡️ Build success in 8869ms
|
|
21
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.19 KB[39m
|
|
22
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.19 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @elementor/editor-styles-repository
|
|
2
2
|
|
|
3
|
+
## 0.8.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 42c42ee: Remove side-effects
|
|
8
|
+
- 5fa575c: Fix when switching documents it removes all the previous document styles
|
|
9
|
+
- 64574e3: Refactor styles provider as a preparation for header/footer styles not being rendered
|
|
10
|
+
- Updated dependencies [5fa575c]
|
|
11
|
+
- Updated dependencies [fe0ab45]
|
|
12
|
+
- Updated dependencies [fd5251c]
|
|
13
|
+
- @elementor/editor-elements@0.8.1
|
|
14
|
+
- @elementor/editor-props@0.12.0
|
|
15
|
+
- @elementor/editor-styles@0.6.6
|
|
16
|
+
|
|
3
17
|
## 0.8.3
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -3,32 +3,30 @@ import * as _elementor_editor_styles from '@elementor/editor-styles';
|
|
|
3
3
|
import { StyleDefinition, StyleDefinitionID, StyleDefinitionVariant } from '@elementor/editor-styles';
|
|
4
4
|
|
|
5
5
|
type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
6
|
+
type Meta = Record<string, unknown>;
|
|
6
7
|
type UpdateActionPayload = MakeOptional<StyleDefinition, 'label' | 'variants' | 'type'>;
|
|
7
8
|
type UpdatePropsActionPayload = {
|
|
8
9
|
id: StyleDefinitionID;
|
|
9
10
|
meta: StyleDefinitionVariant['meta'];
|
|
10
11
|
props: Props;
|
|
11
12
|
};
|
|
12
|
-
type Meta = Record<string, unknown>;
|
|
13
13
|
type StylesProvider = {
|
|
14
|
-
|
|
14
|
+
getKey: () => string;
|
|
15
15
|
priority: number;
|
|
16
|
+
limit: number;
|
|
17
|
+
subscribe: (callback: () => void) => () => void;
|
|
18
|
+
labels: {
|
|
19
|
+
singular: string | null;
|
|
20
|
+
plural: string | null;
|
|
21
|
+
};
|
|
16
22
|
actions: {
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
all: (meta?: Meta) => StyleDefinition[];
|
|
24
|
+
get: (id: StyleDefinitionID, meta?: Meta) => StyleDefinition | null;
|
|
19
25
|
create?: (label: StyleDefinition['label']) => StyleDefinitionID;
|
|
20
26
|
delete?: (id: StyleDefinitionID) => void;
|
|
21
|
-
setOrder?: (order: StyleDefinitionID[]) => void;
|
|
22
27
|
update?: (data: UpdateActionPayload) => void;
|
|
23
28
|
updateProps?: (args: UpdatePropsActionPayload, meta?: Meta) => void;
|
|
24
29
|
};
|
|
25
|
-
subscribe: (callback: () => void) => () => void;
|
|
26
|
-
labels?: {
|
|
27
|
-
singular: string;
|
|
28
|
-
plural: string;
|
|
29
|
-
};
|
|
30
|
-
reservedLabel?: string;
|
|
31
|
-
limit?: number;
|
|
32
30
|
};
|
|
33
31
|
|
|
34
32
|
declare const stylesRepository: {
|
|
@@ -37,8 +35,6 @@ declare const stylesRepository: {
|
|
|
37
35
|
subscribe: (cb: () => void) => () => void;
|
|
38
36
|
getProviders: () => StylesProvider[];
|
|
39
37
|
getProviderByKey: (key: string) => StylesProvider | undefined;
|
|
40
|
-
isLabelExist: (newLabel: string) => boolean;
|
|
41
|
-
isLabelValid: (newLabel: string) => boolean;
|
|
42
38
|
};
|
|
43
39
|
|
|
44
40
|
declare function useProviders(): StylesProvider[];
|
|
@@ -47,9 +43,41 @@ type CreateAction = Required<StylesProvider['actions']>['create'];
|
|
|
47
43
|
type CreateTuple = [StylesProvider, CreateAction];
|
|
48
44
|
declare function useCreateActionsByProvider(): CreateTuple[];
|
|
49
45
|
|
|
50
|
-
declare
|
|
51
|
-
|
|
46
|
+
declare function validateStyleLabel(label: string): {
|
|
47
|
+
isValid: boolean;
|
|
48
|
+
error: null;
|
|
49
|
+
} | {
|
|
50
|
+
isValid: boolean;
|
|
51
|
+
error: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type CreateStylesProviderOptions = {
|
|
55
|
+
key: string | (() => string);
|
|
56
|
+
priority?: number;
|
|
57
|
+
limit?: number;
|
|
58
|
+
subscribe?: (callback: () => void) => () => void;
|
|
59
|
+
labels?: {
|
|
60
|
+
singular: string;
|
|
61
|
+
plural: string;
|
|
62
|
+
};
|
|
63
|
+
actions: {
|
|
64
|
+
all: StylesProvider['actions']['all'];
|
|
65
|
+
get: StylesProvider['actions']['get'];
|
|
66
|
+
create?: StylesProvider['actions']['create'];
|
|
67
|
+
delete?: StylesProvider['actions']['delete'];
|
|
68
|
+
update?: StylesProvider['actions']['update'];
|
|
69
|
+
updateProps?: StylesProvider['actions']['updateProps'];
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
declare function createStylesProvider({ key, priority, limit, subscribe, labels, actions, }: CreateStylesProviderOptions): StylesProvider;
|
|
73
|
+
|
|
74
|
+
declare function isElementsStylesProvider(key: string): boolean;
|
|
52
75
|
|
|
53
76
|
declare const ELEMENTS_BASE_STYLES_PROVIDER_KEY = "element-base-styles";
|
|
54
77
|
|
|
55
|
-
|
|
78
|
+
declare const ELEMENTS_STYLES_PROVIDER_KEY_PREFIX = "document-elements-";
|
|
79
|
+
declare const ELEMENTS_STYLES_RESERVED_LABEL = "local";
|
|
80
|
+
|
|
81
|
+
declare function init(): void;
|
|
82
|
+
|
|
83
|
+
export { type CreateStylesProviderOptions, ELEMENTS_BASE_STYLES_PROVIDER_KEY, ELEMENTS_STYLES_PROVIDER_KEY_PREFIX, ELEMENTS_STYLES_RESERVED_LABEL, type Meta, type StylesProvider, type UpdateActionPayload, type UpdatePropsActionPayload, createStylesProvider, init, isElementsStylesProvider, stylesRepository, useCreateActionsByProvider, useProviders, validateStyleLabel };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,32 +3,30 @@ import * as _elementor_editor_styles from '@elementor/editor-styles';
|
|
|
3
3
|
import { StyleDefinition, StyleDefinitionID, StyleDefinitionVariant } from '@elementor/editor-styles';
|
|
4
4
|
|
|
5
5
|
type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<T>;
|
|
6
|
+
type Meta = Record<string, unknown>;
|
|
6
7
|
type UpdateActionPayload = MakeOptional<StyleDefinition, 'label' | 'variants' | 'type'>;
|
|
7
8
|
type UpdatePropsActionPayload = {
|
|
8
9
|
id: StyleDefinitionID;
|
|
9
10
|
meta: StyleDefinitionVariant['meta'];
|
|
10
11
|
props: Props;
|
|
11
12
|
};
|
|
12
|
-
type Meta = Record<string, unknown>;
|
|
13
13
|
type StylesProvider = {
|
|
14
|
-
|
|
14
|
+
getKey: () => string;
|
|
15
15
|
priority: number;
|
|
16
|
+
limit: number;
|
|
17
|
+
subscribe: (callback: () => void) => () => void;
|
|
18
|
+
labels: {
|
|
19
|
+
singular: string | null;
|
|
20
|
+
plural: string | null;
|
|
21
|
+
};
|
|
16
22
|
actions: {
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
all: (meta?: Meta) => StyleDefinition[];
|
|
24
|
+
get: (id: StyleDefinitionID, meta?: Meta) => StyleDefinition | null;
|
|
19
25
|
create?: (label: StyleDefinition['label']) => StyleDefinitionID;
|
|
20
26
|
delete?: (id: StyleDefinitionID) => void;
|
|
21
|
-
setOrder?: (order: StyleDefinitionID[]) => void;
|
|
22
27
|
update?: (data: UpdateActionPayload) => void;
|
|
23
28
|
updateProps?: (args: UpdatePropsActionPayload, meta?: Meta) => void;
|
|
24
29
|
};
|
|
25
|
-
subscribe: (callback: () => void) => () => void;
|
|
26
|
-
labels?: {
|
|
27
|
-
singular: string;
|
|
28
|
-
plural: string;
|
|
29
|
-
};
|
|
30
|
-
reservedLabel?: string;
|
|
31
|
-
limit?: number;
|
|
32
30
|
};
|
|
33
31
|
|
|
34
32
|
declare const stylesRepository: {
|
|
@@ -37,8 +35,6 @@ declare const stylesRepository: {
|
|
|
37
35
|
subscribe: (cb: () => void) => () => void;
|
|
38
36
|
getProviders: () => StylesProvider[];
|
|
39
37
|
getProviderByKey: (key: string) => StylesProvider | undefined;
|
|
40
|
-
isLabelExist: (newLabel: string) => boolean;
|
|
41
|
-
isLabelValid: (newLabel: string) => boolean;
|
|
42
38
|
};
|
|
43
39
|
|
|
44
40
|
declare function useProviders(): StylesProvider[];
|
|
@@ -47,9 +43,41 @@ type CreateAction = Required<StylesProvider['actions']>['create'];
|
|
|
47
43
|
type CreateTuple = [StylesProvider, CreateAction];
|
|
48
44
|
declare function useCreateActionsByProvider(): CreateTuple[];
|
|
49
45
|
|
|
50
|
-
declare
|
|
51
|
-
|
|
46
|
+
declare function validateStyleLabel(label: string): {
|
|
47
|
+
isValid: boolean;
|
|
48
|
+
error: null;
|
|
49
|
+
} | {
|
|
50
|
+
isValid: boolean;
|
|
51
|
+
error: string;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type CreateStylesProviderOptions = {
|
|
55
|
+
key: string | (() => string);
|
|
56
|
+
priority?: number;
|
|
57
|
+
limit?: number;
|
|
58
|
+
subscribe?: (callback: () => void) => () => void;
|
|
59
|
+
labels?: {
|
|
60
|
+
singular: string;
|
|
61
|
+
plural: string;
|
|
62
|
+
};
|
|
63
|
+
actions: {
|
|
64
|
+
all: StylesProvider['actions']['all'];
|
|
65
|
+
get: StylesProvider['actions']['get'];
|
|
66
|
+
create?: StylesProvider['actions']['create'];
|
|
67
|
+
delete?: StylesProvider['actions']['delete'];
|
|
68
|
+
update?: StylesProvider['actions']['update'];
|
|
69
|
+
updateProps?: StylesProvider['actions']['updateProps'];
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
declare function createStylesProvider({ key, priority, limit, subscribe, labels, actions, }: CreateStylesProviderOptions): StylesProvider;
|
|
73
|
+
|
|
74
|
+
declare function isElementsStylesProvider(key: string): boolean;
|
|
52
75
|
|
|
53
76
|
declare const ELEMENTS_BASE_STYLES_PROVIDER_KEY = "element-base-styles";
|
|
54
77
|
|
|
55
|
-
|
|
78
|
+
declare const ELEMENTS_STYLES_PROVIDER_KEY_PREFIX = "document-elements-";
|
|
79
|
+
declare const ELEMENTS_STYLES_RESERVED_LABEL = "local";
|
|
80
|
+
|
|
81
|
+
declare function init(): void;
|
|
82
|
+
|
|
83
|
+
export { type CreateStylesProviderOptions, ELEMENTS_BASE_STYLES_PROVIDER_KEY, ELEMENTS_STYLES_PROVIDER_KEY_PREFIX, ELEMENTS_STYLES_RESERVED_LABEL, type Meta, type StylesProvider, type UpdateActionPayload, type UpdatePropsActionPayload, createStylesProvider, init, isElementsStylesProvider, stylesRepository, useCreateActionsByProvider, useProviders, validateStyleLabel };
|
package/dist/index.js
CHANGED
|
@@ -21,16 +21,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
ELEMENTS_BASE_STYLES_PROVIDER_KEY: () => ELEMENTS_BASE_STYLES_PROVIDER_KEY,
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
ELEMENTS_STYLES_PROVIDER_KEY_PREFIX: () => ELEMENTS_STYLES_PROVIDER_KEY_PREFIX,
|
|
25
|
+
ELEMENTS_STYLES_RESERVED_LABEL: () => ELEMENTS_STYLES_RESERVED_LABEL,
|
|
26
|
+
createStylesProvider: () => createStylesProvider,
|
|
27
|
+
init: () => init,
|
|
28
|
+
isElementsStylesProvider: () => isElementsStylesProvider,
|
|
26
29
|
stylesRepository: () => stylesRepository,
|
|
27
30
|
useCreateActionsByProvider: () => useCreateActionsByProvider,
|
|
28
|
-
useProviders: () => useProviders
|
|
31
|
+
useProviders: () => useProviders,
|
|
32
|
+
validateStyleLabel: () => validateStyleLabel
|
|
29
33
|
});
|
|
30
34
|
module.exports = __toCommonJS(index_exports);
|
|
31
35
|
|
|
32
36
|
// src/utils/create-styles-repository.ts
|
|
33
|
-
var VALID_SELECTOR_REGEX = /^[a-zA-Z0-9_-]+$/;
|
|
34
37
|
var createStylesRepository = () => {
|
|
35
38
|
const providers = [];
|
|
36
39
|
const getProviders = () => {
|
|
@@ -40,7 +43,7 @@ var createStylesRepository = () => {
|
|
|
40
43
|
providers.push(provider);
|
|
41
44
|
};
|
|
42
45
|
const all = (meta = {}) => {
|
|
43
|
-
return getProviders().flatMap((provider) => provider.actions.
|
|
46
|
+
return getProviders().flatMap((provider) => provider.actions.all(meta));
|
|
44
47
|
};
|
|
45
48
|
const subscribe = (cb) => {
|
|
46
49
|
const unsubscribes = providers.map((provider) => {
|
|
@@ -51,28 +54,14 @@ var createStylesRepository = () => {
|
|
|
51
54
|
};
|
|
52
55
|
};
|
|
53
56
|
const getProviderByKey = (key) => {
|
|
54
|
-
return providers.find((provider) => provider.
|
|
57
|
+
return providers.find((provider) => provider.getKey() === key);
|
|
55
58
|
};
|
|
56
|
-
const isLabelExist = (newLabel) => {
|
|
57
|
-
const classes = all();
|
|
58
|
-
const reservedLabels = providers.map(({ reservedLabel }) => reservedLabel).filter(Boolean);
|
|
59
|
-
if (reservedLabels.includes(newLabel)) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
if (!classes?.length) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return classes.some(({ label }) => label.toLowerCase() === newLabel.toLowerCase());
|
|
66
|
-
};
|
|
67
|
-
const isLabelValid = (newLabel) => VALID_SELECTOR_REGEX.test(newLabel);
|
|
68
59
|
return {
|
|
69
60
|
all,
|
|
70
61
|
register,
|
|
71
62
|
subscribe,
|
|
72
63
|
getProviders,
|
|
73
|
-
getProviderByKey
|
|
74
|
-
isLabelExist,
|
|
75
|
-
isLabelValid
|
|
64
|
+
getProviderByKey
|
|
76
65
|
};
|
|
77
66
|
};
|
|
78
67
|
|
|
@@ -100,7 +89,11 @@ function useCreateActionsByProvider() {
|
|
|
100
89
|
}, []);
|
|
101
90
|
}
|
|
102
91
|
|
|
103
|
-
// src/
|
|
92
|
+
// src/utils/validate-style-label.ts
|
|
93
|
+
var import_schema = require("@elementor/schema");
|
|
94
|
+
var import_i18n = require("@wordpress/i18n");
|
|
95
|
+
|
|
96
|
+
// src/providers/document-elements-styles-provider.ts
|
|
104
97
|
var import_editor_elements = require("@elementor/editor-elements");
|
|
105
98
|
var import_editor_v1_adapters = require("@elementor/editor-v1-adapters");
|
|
106
99
|
|
|
@@ -110,22 +103,65 @@ var InvalidElementsStyleProviderMetaError = (0, import_utils.createError)({
|
|
|
110
103
|
code: "invalid_elements_style_provider_meta",
|
|
111
104
|
message: "Invalid elements style provider meta."
|
|
112
105
|
});
|
|
106
|
+
var ActiveDocumentMustExistError = (0, import_utils.createError)({
|
|
107
|
+
code: "active_document_must_exist",
|
|
108
|
+
message: "Active document must exist."
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
// src/utils/create-styles-provider.ts
|
|
112
|
+
var DEFAULT_LIMIT = 1e4;
|
|
113
|
+
var DEFAULT_PRIORITY = 10;
|
|
114
|
+
function createStylesProvider({
|
|
115
|
+
key,
|
|
116
|
+
priority = DEFAULT_PRIORITY,
|
|
117
|
+
limit = DEFAULT_LIMIT,
|
|
118
|
+
subscribe = () => () => {
|
|
119
|
+
},
|
|
120
|
+
labels,
|
|
121
|
+
actions
|
|
122
|
+
}) {
|
|
123
|
+
return {
|
|
124
|
+
getKey: typeof key === "string" ? () => key : key,
|
|
125
|
+
priority,
|
|
126
|
+
limit,
|
|
127
|
+
subscribe,
|
|
128
|
+
labels: {
|
|
129
|
+
singular: labels?.singular ?? null,
|
|
130
|
+
plural: labels?.plural ?? null
|
|
131
|
+
},
|
|
132
|
+
actions: {
|
|
133
|
+
all: actions.all,
|
|
134
|
+
get: actions.get,
|
|
135
|
+
create: actions.create,
|
|
136
|
+
delete: actions.delete,
|
|
137
|
+
update: actions.update,
|
|
138
|
+
updateProps: actions.updateProps
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
113
142
|
|
|
114
|
-
// src/elements-styles-provider.ts
|
|
115
|
-
var
|
|
116
|
-
var
|
|
117
|
-
var
|
|
118
|
-
key:
|
|
143
|
+
// src/providers/document-elements-styles-provider.ts
|
|
144
|
+
var ELEMENTS_STYLES_PROVIDER_KEY_PREFIX = "document-elements-";
|
|
145
|
+
var ELEMENTS_STYLES_RESERVED_LABEL = "local";
|
|
146
|
+
var documentElementsStylesProvider = createStylesProvider({
|
|
147
|
+
key: () => {
|
|
148
|
+
const documentId = (0, import_editor_elements.getCurrentDocumentId)();
|
|
149
|
+
if (!documentId) {
|
|
150
|
+
throw new ActiveDocumentMustExistError();
|
|
151
|
+
}
|
|
152
|
+
return `${ELEMENTS_STYLES_PROVIDER_KEY_PREFIX}${documentId}`;
|
|
153
|
+
},
|
|
119
154
|
priority: 50,
|
|
155
|
+
subscribe: (cb) => (0, import_editor_v1_adapters.__privateListenTo)(import_editor_elements.styleRerenderEvents, cb),
|
|
120
156
|
actions: {
|
|
121
|
-
|
|
157
|
+
all: (meta = {}) => {
|
|
122
158
|
let elements = (0, import_editor_elements.getElements)();
|
|
123
159
|
if (isValidElementsMeta(meta)) {
|
|
124
160
|
elements = elements.filter((element) => element.id === meta.elementId);
|
|
125
161
|
}
|
|
126
162
|
return elements.flatMap((element) => Object.values(element.model.get("styles") ?? {}));
|
|
127
163
|
},
|
|
128
|
-
|
|
164
|
+
get: (id, meta = {}) => {
|
|
129
165
|
if (!isValidElementsMeta(meta)) {
|
|
130
166
|
throw new InvalidElementsStyleProviderMetaError({ context: { meta } });
|
|
131
167
|
}
|
|
@@ -143,52 +179,74 @@ var elementsStylesProvider = {
|
|
|
143
179
|
props: args.props
|
|
144
180
|
});
|
|
145
181
|
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
reservedLabel: LOCAL_STYLES_RESERVED_LABEL
|
|
149
|
-
};
|
|
182
|
+
}
|
|
183
|
+
});
|
|
150
184
|
function isValidElementsMeta(meta) {
|
|
151
185
|
return "elementId" in meta && typeof meta.elementId === "string" && !!meta.elementId;
|
|
152
186
|
}
|
|
153
187
|
|
|
154
|
-
// src/
|
|
188
|
+
// src/utils/validate-style-label.ts
|
|
189
|
+
var VALID_LABEL_REGEX = /^[a-zA-Z0-9_-]+$/;
|
|
190
|
+
var schema = import_schema.z.string().min(1, (0, import_i18n.__)("Cannot be empty", "elementor")).max(50, (0, import_i18n.__)("Cannot be longer than 50 characters", "elementor")).regex(VALID_LABEL_REGEX, (0, import_i18n.__)("Invalid format", "elementor"));
|
|
191
|
+
function validateStyleLabel(label) {
|
|
192
|
+
const existingLabels = /* @__PURE__ */ new Set([
|
|
193
|
+
ELEMENTS_STYLES_RESERVED_LABEL,
|
|
194
|
+
...stylesRepository.all().map((styleDef) => styleDef.label.toLowerCase())
|
|
195
|
+
]);
|
|
196
|
+
const result = schema.refine((value) => !existingLabels.has(value), {
|
|
197
|
+
message: (0, import_i18n.__)("Name exists", "elementor")
|
|
198
|
+
}).safeParse(label.toLowerCase());
|
|
199
|
+
if (result.success) {
|
|
200
|
+
return {
|
|
201
|
+
isValid: true,
|
|
202
|
+
error: null
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
isValid: false,
|
|
207
|
+
error: result.error.format()._errors[0]
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/utils/is-elements-styles-provider.ts
|
|
212
|
+
function isElementsStylesProvider(key) {
|
|
213
|
+
return new RegExp(`^${ELEMENTS_STYLES_PROVIDER_KEY_PREFIX}\\d+$`).test(key);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/providers/element-base-styles-provider.ts
|
|
155
217
|
var import_editor_elements2 = require("@elementor/editor-elements");
|
|
156
218
|
var ELEMENTS_BASE_STYLES_PROVIDER_KEY = "element-base-styles";
|
|
157
|
-
var elementBaseStylesProvider = {
|
|
219
|
+
var elementBaseStylesProvider = createStylesProvider({
|
|
158
220
|
key: ELEMENTS_BASE_STYLES_PROVIDER_KEY,
|
|
159
|
-
priority: 10,
|
|
160
221
|
actions: {
|
|
161
|
-
|
|
222
|
+
all() {
|
|
162
223
|
const widgetsCache = (0, import_editor_elements2.getWidgetsCache)();
|
|
163
224
|
return Object.values(widgetsCache ?? {}).flatMap(
|
|
164
225
|
(widget) => Object.values(widget.base_styles ?? {})
|
|
165
226
|
);
|
|
166
227
|
},
|
|
167
|
-
|
|
168
|
-
return this.
|
|
228
|
+
get(id) {
|
|
229
|
+
return this.all().find((style) => style.id === id) ?? null;
|
|
169
230
|
}
|
|
170
|
-
},
|
|
171
|
-
subscribe: () => {
|
|
172
|
-
return () => {
|
|
173
|
-
};
|
|
174
231
|
}
|
|
175
|
-
};
|
|
232
|
+
});
|
|
176
233
|
|
|
177
234
|
// src/init.ts
|
|
178
235
|
function init() {
|
|
179
|
-
stylesRepository.register(
|
|
236
|
+
stylesRepository.register(documentElementsStylesProvider);
|
|
180
237
|
stylesRepository.register(elementBaseStylesProvider);
|
|
181
238
|
}
|
|
182
|
-
|
|
183
|
-
// src/index.ts
|
|
184
|
-
init();
|
|
185
239
|
// Annotate the CommonJS export names for ESM import in node:
|
|
186
240
|
0 && (module.exports = {
|
|
187
241
|
ELEMENTS_BASE_STYLES_PROVIDER_KEY,
|
|
188
|
-
|
|
189
|
-
|
|
242
|
+
ELEMENTS_STYLES_PROVIDER_KEY_PREFIX,
|
|
243
|
+
ELEMENTS_STYLES_RESERVED_LABEL,
|
|
244
|
+
createStylesProvider,
|
|
245
|
+
init,
|
|
246
|
+
isElementsStylesProvider,
|
|
190
247
|
stylesRepository,
|
|
191
248
|
useCreateActionsByProvider,
|
|
192
|
-
useProviders
|
|
249
|
+
useProviders,
|
|
250
|
+
validateStyleLabel
|
|
193
251
|
});
|
|
194
252
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils/create-styles-repository.ts","../src/styles-repository.ts","../src/hooks/use-providers.ts","../src/hooks/use-create-actions-by-provider.ts","../src/elements-styles-provider.ts","../src/errors.ts","../src/element-base-styles-provider.ts","../src/init.ts"],"sourcesContent":["export {\n\ttype StylesProvider,\n\ttype UpdateActionPayload,\n\ttype Meta,\n\ttype UpdatePropsActionPayload,\n} from './utils/create-styles-repository';\n\nexport { stylesRepository } from './styles-repository';\nexport { useProviders } from './hooks/use-providers';\nexport { useCreateActionsByProvider } from './hooks/use-create-actions-by-provider';\n\nexport { ELEMENTS_STYLES_PROVIDER_KEY, LOCAL_STYLES_RESERVED_LABEL } from './elements-styles-provider';\nexport { ELEMENTS_BASE_STYLES_PROVIDER_KEY } from './element-base-styles-provider';\n\nimport { init } from './init';\n\ninit();\n","import { type Props } from '@elementor/editor-props';\nimport { type StyleDefinition, type StyleDefinitionID, type StyleDefinitionVariant } from '@elementor/editor-styles';\n\ntype MakeOptional< T, K extends keyof T > = Omit< T, K > & Partial< T >;\n\nexport type UpdateActionPayload = MakeOptional< StyleDefinition, 'label' | 'variants' | 'type' >;\n\nexport type UpdatePropsActionPayload = {\n\tid: StyleDefinitionID;\n\tmeta: StyleDefinitionVariant[ 'meta' ];\n\tprops: Props;\n};\n\nexport type Meta = Record< string, unknown >;\n\nexport type StylesProvider = {\n\tkey: string;\n\tpriority: number;\n\tactions: {\n\t\tget: ( meta?: Meta ) => StyleDefinition[];\n\t\tgetById: ( id: StyleDefinitionID, meta?: Meta ) => StyleDefinition | null;\n\t\tcreate?: ( label: StyleDefinition[ 'label' ] ) => StyleDefinitionID;\n\t\tdelete?: ( id: StyleDefinitionID ) => void;\n\t\tsetOrder?: ( order: StyleDefinitionID[] ) => void;\n\t\tupdate?: ( data: UpdateActionPayload ) => void;\n\t\tupdateProps?: ( args: UpdatePropsActionPayload, meta?: Meta ) => void;\n\t};\n\tsubscribe: ( callback: () => void ) => () => void;\n\tlabels?: {\n\t\tsingular: string;\n\t\tplural: string;\n\t};\n\treservedLabel?: string;\n\tlimit?: number;\n};\n\nconst VALID_SELECTOR_REGEX = /^[a-zA-Z0-9_-]+$/;\n\nexport const createStylesRepository = () => {\n\tconst providers: StylesProvider[] = [];\n\n\tconst getProviders = () => {\n\t\treturn providers.slice( 0 ).sort( ( a, b ) => ( a.priority > b.priority ? -1 : 1 ) );\n\t};\n\n\tconst register = ( provider: StylesProvider ) => {\n\t\tproviders.push( provider );\n\t};\n\n\tconst all = ( meta: Meta = {} ) => {\n\t\treturn getProviders().flatMap( ( provider ) => provider.actions.get( meta ) );\n\t};\n\n\tconst subscribe = ( cb: () => void ) => {\n\t\tconst unsubscribes = providers.map( ( provider ) => {\n\t\t\treturn provider.subscribe( cb );\n\t\t} );\n\n\t\treturn () => {\n\t\t\tunsubscribes.forEach( ( unsubscribe ) => unsubscribe() );\n\t\t};\n\t};\n\n\tconst getProviderByKey = ( key: string ) => {\n\t\treturn providers.find( ( provider ) => provider.key === key );\n\t};\n\n\tconst isLabelExist = ( newLabel: string ) => {\n\t\tconst classes = all();\n\t\tconst reservedLabels = providers.map( ( { reservedLabel } ) => reservedLabel ).filter( Boolean );\n\n\t\tif ( reservedLabels.includes( newLabel ) ) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif ( ! classes?.length ) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn classes.some( ( { label } ) => label.toLowerCase() === newLabel.toLowerCase() );\n\t};\n\n\tconst isLabelValid = ( newLabel: string ) => VALID_SELECTOR_REGEX.test( newLabel );\n\n\treturn {\n\t\tall,\n\t\tregister,\n\t\tsubscribe,\n\t\tgetProviders,\n\t\tgetProviderByKey,\n\t\tisLabelExist,\n\t\tisLabelValid,\n\t};\n};\n","import { createStylesRepository } from './utils/create-styles-repository';\n\nexport const stylesRepository = createStylesRepository();\n","import { useEffect, useReducer } from 'react';\n\nimport { stylesRepository } from '../styles-repository';\n\nexport function useProviders() {\n\tconst [ , rerender ] = useReducer( ( prev ) => ! prev, false );\n\n\tuseEffect( () => stylesRepository.subscribe( rerender ), [] );\n\n\treturn stylesRepository.getProviders();\n}\n","import { useMemo } from 'react';\n\nimport { stylesRepository } from '../styles-repository';\nimport { type StylesProvider } from '../utils/create-styles-repository';\n\ntype CreateAction = Required< StylesProvider[ 'actions' ] >[ 'create' ];\ntype CreateTuple = [ StylesProvider, CreateAction ];\n\nexport function useCreateActionsByProvider() {\n\treturn useMemo( () => {\n\t\treturn stylesRepository\n\t\t\t.getProviders()\n\t\t\t.map< CreateTuple | null >( ( provider ) => {\n\t\t\t\tif ( ! provider.actions.create ) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn [ provider, provider.actions.create ];\n\t\t\t} )\n\t\t\t.filter( ( item ) => !! item );\n\t}, [] );\n}\n","import { getElements, getElementStyles, styleRerenderEvents, updateElementStyle } from '@elementor/editor-elements';\nimport { __privateListenTo as listenTo } from '@elementor/editor-v1-adapters';\n\nimport { InvalidElementsStyleProviderMetaError } from './errors';\nimport { type StylesProvider } from './utils/create-styles-repository';\n\nexport const ELEMENTS_STYLES_PROVIDER_KEY = 'elements';\nexport const LOCAL_STYLES_RESERVED_LABEL = 'local';\n\nexport const elementsStylesProvider = {\n\tkey: ELEMENTS_STYLES_PROVIDER_KEY,\n\tpriority: 50,\n\tactions: {\n\t\tget: ( meta = {} ) => {\n\t\t\tlet elements = getElements();\n\n\t\t\tif ( isValidElementsMeta( meta ) ) {\n\t\t\t\telements = elements.filter( ( element ) => element.id === meta.elementId );\n\t\t\t}\n\n\t\t\treturn elements.flatMap( ( element ) => Object.values( element.model.get( 'styles' ) ?? {} ) );\n\t\t},\n\n\t\tgetById: ( id, meta = {} ) => {\n\t\t\tif ( ! isValidElementsMeta( meta ) ) {\n\t\t\t\tthrow new InvalidElementsStyleProviderMetaError( { context: { meta } } );\n\t\t\t}\n\n\t\t\tconst styles = getElementStyles( meta.elementId ) ?? {};\n\n\t\t\treturn styles[ id ] ?? null;\n\t\t},\n\n\t\tupdateProps: ( args, meta = {} ) => {\n\t\t\tif ( ! isValidElementsMeta( meta ) ) {\n\t\t\t\tthrow new InvalidElementsStyleProviderMetaError( { context: { meta } } );\n\t\t\t}\n\n\t\t\tupdateElementStyle( {\n\t\t\t\telementId: meta.elementId,\n\t\t\t\tstyleId: args.id,\n\t\t\t\tmeta: args.meta,\n\t\t\t\tprops: args.props,\n\t\t\t} );\n\t\t},\n\t},\n\tsubscribe: ( cb ) => listenTo( styleRerenderEvents, cb ),\n\treservedLabel: LOCAL_STYLES_RESERVED_LABEL,\n} satisfies StylesProvider;\n\ntype ElementsMeta = {\n\telementId: string;\n};\n\nfunction isValidElementsMeta( meta: Record< string, unknown > ): meta is ElementsMeta {\n\treturn 'elementId' in meta && typeof meta.elementId === 'string' && !! meta.elementId;\n}\n","import { createError } from '@elementor/utils';\n\nexport const InvalidElementsStyleProviderMetaError = createError< { meta: Record< string, unknown > } >( {\n\tcode: 'invalid_elements_style_provider_meta',\n\tmessage: 'Invalid elements style provider meta.',\n} );\n","import { getWidgetsCache } from '@elementor/editor-elements';\n\nimport { type StylesProvider } from './utils/create-styles-repository';\n\nexport const ELEMENTS_BASE_STYLES_PROVIDER_KEY = 'element-base-styles';\n\nexport const elementBaseStylesProvider: StylesProvider = {\n\tkey: ELEMENTS_BASE_STYLES_PROVIDER_KEY,\n\tpriority: 10,\n\tactions: {\n\t\tget() {\n\t\t\tconst widgetsCache = getWidgetsCache();\n\n\t\t\treturn Object.values( widgetsCache ?? {} ).flatMap( ( widget ) =>\n\t\t\t\tObject.values( widget.base_styles ?? {} )\n\t\t\t);\n\t\t},\n\n\t\tgetById( id ) {\n\t\t\treturn this.get().find( ( style ) => style.id === id ) ?? null;\n\t\t},\n\t},\n\tsubscribe: () => {\n\t\treturn () => {};\n\t},\n};\n","import { elementBaseStylesProvider } from './element-base-styles-provider';\nimport { elementsStylesProvider } from './elements-styles-provider';\nimport { stylesRepository } from './styles-repository';\n\nexport function init() {\n\tstylesRepository.register( elementsStylesProvider );\n\tstylesRepository.register( elementBaseStylesProvider );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACoCA,IAAM,uBAAuB;AAEtB,IAAM,yBAAyB,MAAM;AAC3C,QAAM,YAA8B,CAAC;AAErC,QAAM,eAAe,MAAM;AAC1B,WAAO,UAAU,MAAO,CAAE,EAAE,KAAM,CAAE,GAAG,MAAS,EAAE,WAAW,EAAE,WAAW,KAAK,CAAI;AAAA,EACpF;AAEA,QAAM,WAAW,CAAE,aAA8B;AAChD,cAAU,KAAM,QAAS;AAAA,EAC1B;AAEA,QAAM,MAAM,CAAE,OAAa,CAAC,MAAO;AAClC,WAAO,aAAa,EAAE,QAAS,CAAE,aAAc,SAAS,QAAQ,IAAK,IAAK,CAAE;AAAA,EAC7E;AAEA,QAAM,YAAY,CAAE,OAAoB;AACvC,UAAM,eAAe,UAAU,IAAK,CAAE,aAAc;AACnD,aAAO,SAAS,UAAW,EAAG;AAAA,IAC/B,CAAE;AAEF,WAAO,MAAM;AACZ,mBAAa,QAAS,CAAE,gBAAiB,YAAY,CAAE;AAAA,IACxD;AAAA,EACD;AAEA,QAAM,mBAAmB,CAAE,QAAiB;AAC3C,WAAO,UAAU,KAAM,CAAE,aAAc,SAAS,QAAQ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ACL,UAAU;AAAA,EACV,SAAS;AAAA,IACR,MAAM;AACL,YAAM,mBAAe,yCAAgB;AAErC,aAAO,OAAO,OAAQ,gBAAgB,CAAC,CAAE,EAAE;AAAA,QAAS,CAAE,WACrD,OAAO,OAAQ,OAAO,eAAe,CAAC,CAAE;AAAA,MACzC;AAAA,IACD;AAAA,IAEA,QAAS,IAAK;AACb,aAAO,KAAK,IAAI,EAAE,KAAM,CAAE,UAAW,MAAM,OAAO,EAAG,KAAK;AAAA,IAC3D;AAAA,EACD;AAAA,EACA,WAAW,MAAM;AAChB,WAAO,MAAM;AAAA,IAAC;AAAA,EACf;AACD;;;ACrBO,SAAS,OAAO;AACtB,mBAAiB,SAAU,sBAAuB;AAClD,mBAAiB,SAAU,yBAA0B;AACtD;;;ARSA,KAAK;","names":["import_react","listenTo","import_editor_elements"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/utils/create-styles-repository.ts","../src/styles-repository.ts","../src/hooks/use-providers.ts","../src/hooks/use-create-actions-by-provider.ts","../src/utils/validate-style-label.ts","../src/providers/document-elements-styles-provider.ts","../src/errors.ts","../src/utils/create-styles-provider.ts","../src/utils/is-elements-styles-provider.ts","../src/providers/element-base-styles-provider.ts","../src/init.ts"],"sourcesContent":["export * from './types';\n\nexport { stylesRepository } from './styles-repository';\nexport { useProviders } from './hooks/use-providers';\nexport { useCreateActionsByProvider } from './hooks/use-create-actions-by-provider';\nexport { validateStyleLabel } from './utils/validate-style-label';\nexport { createStylesProvider, type CreateStylesProviderOptions } from './utils/create-styles-provider';\nexport { isElementsStylesProvider } from './utils/is-elements-styles-provider';\n\nexport { ELEMENTS_BASE_STYLES_PROVIDER_KEY } from './providers/element-base-styles-provider';\nexport {\n\tELEMENTS_STYLES_PROVIDER_KEY_PREFIX,\n\tELEMENTS_STYLES_RESERVED_LABEL,\n} from './providers/document-elements-styles-provider';\n\nexport { init } from './init';\n","import { type Meta, type StylesProvider } from '../types';\n\nexport const createStylesRepository = () => {\n\tconst providers: StylesProvider[] = [];\n\n\tconst getProviders = () => {\n\t\treturn providers.slice( 0 ).sort( ( a, b ) => ( a.priority > b.priority ? -1 : 1 ) );\n\t};\n\n\tconst register = ( provider: StylesProvider ) => {\n\t\tproviders.push( provider );\n\t};\n\n\tconst all = ( meta: Meta = {} ) => {\n\t\treturn getProviders().flatMap( ( provider ) => provider.actions.all( meta ) );\n\t};\n\n\tconst subscribe = ( cb: () => void ) => {\n\t\tconst unsubscribes = providers.map( ( provider ) => {\n\t\t\treturn provider.subscribe( cb );\n\t\t} );\n\n\t\treturn () => {\n\t\t\tunsubscribes.forEach( ( unsubscribe ) => unsubscribe() );\n\t\t};\n\t};\n\n\tconst getProviderByKey = ( key: string ) => {\n\t\treturn providers.find( ( provider ) => provider.getKey() === key );\n\t};\n\n\treturn {\n\t\tall,\n\t\tregister,\n\t\tsubscribe,\n\t\tgetProviders,\n\t\tgetProviderByKey,\n\t};\n};\n","import { createStylesRepository } from './utils/create-styles-repository';\n\nexport const stylesRepository = createStylesRepository();\n","import { useEffect, useReducer } from 'react';\n\nimport { stylesRepository } from '../styles-repository';\n\nexport function useProviders() {\n\tconst [ , rerender ] = useReducer( ( prev ) => ! prev, false );\n\n\tuseEffect( () => stylesRepository.subscribe( rerender ), [] );\n\n\treturn stylesRepository.getProviders();\n}\n","import { useMemo } from 'react';\n\nimport { stylesRepository } from '../styles-repository';\nimport { type StylesProvider } from '../types';\n\ntype CreateAction = Required< StylesProvider[ 'actions' ] >[ 'create' ];\ntype CreateTuple = [ StylesProvider, CreateAction ];\n\nexport function useCreateActionsByProvider() {\n\treturn useMemo( () => {\n\t\treturn stylesRepository\n\t\t\t.getProviders()\n\t\t\t.map< CreateTuple | null >( ( provider ) => {\n\t\t\t\tif ( ! provider.actions.create ) {\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\n\t\t\t\treturn [ provider, provider.actions.create ];\n\t\t\t} )\n\t\t\t.filter( ( item ) => !! item );\n\t}, [] );\n}\n","import { z } from '@elementor/schema';\nimport { __ } from '@wordpress/i18n';\n\nimport { ELEMENTS_STYLES_RESERVED_LABEL } from '../providers/document-elements-styles-provider';\nimport { stylesRepository } from '../styles-repository';\n\nconst VALID_LABEL_REGEX = /^[a-zA-Z0-9_-]+$/;\n\nconst schema = z\n\t.string()\n\t.min( 1, __( 'Cannot be empty', 'elementor' ) )\n\t.max( 50, __( 'Cannot be longer than 50 characters', 'elementor' ) )\n\t.regex( VALID_LABEL_REGEX, __( 'Invalid format', 'elementor' ) );\n\nexport function validateStyleLabel( label: string ) {\n\tconst existingLabels = new Set( [\n\t\tELEMENTS_STYLES_RESERVED_LABEL,\n\t\t...stylesRepository.all().map( ( styleDef ) => styleDef.label.toLowerCase() ),\n\t] );\n\n\tconst result = schema\n\t\t.refine( ( value ) => ! existingLabels.has( value ), {\n\t\t\tmessage: __( 'Name exists', 'elementor' ),\n\t\t} )\n\t\t.safeParse( label.toLowerCase() );\n\n\tif ( result.success ) {\n\t\treturn {\n\t\t\tisValid: true,\n\t\t\terror: null,\n\t\t};\n\t}\n\n\treturn {\n\t\tisValid: false,\n\t\terror: result.error.format()._errors[ 0 ],\n\t};\n}\n","import {\n\tgetCurrentDocumentId,\n\tgetElements,\n\tgetElementStyles,\n\tstyleRerenderEvents,\n\tupdateElementStyle,\n} from '@elementor/editor-elements';\nimport { __privateListenTo as listenTo } from '@elementor/editor-v1-adapters';\n\nimport { ActiveDocumentMustExistError, InvalidElementsStyleProviderMetaError } from '../errors';\nimport { createStylesProvider } from '../utils/create-styles-provider';\n\nexport const ELEMENTS_STYLES_PROVIDER_KEY_PREFIX = 'document-elements-';\nexport const ELEMENTS_STYLES_RESERVED_LABEL = 'local';\n\ntype ElementsMeta = {\n\telementId: string;\n};\n\nexport const documentElementsStylesProvider = createStylesProvider( {\n\tkey: () => {\n\t\tconst documentId = getCurrentDocumentId();\n\n\t\tif ( ! documentId ) {\n\t\t\tthrow new ActiveDocumentMustExistError();\n\t\t}\n\n\t\treturn `${ ELEMENTS_STYLES_PROVIDER_KEY_PREFIX }${ documentId }`;\n\t},\n\tpriority: 50,\n\tsubscribe: ( cb ) => listenTo( styleRerenderEvents, cb ),\n\tactions: {\n\t\tall: ( meta = {} ) => {\n\t\t\tlet elements = getElements();\n\n\t\t\tif ( isValidElementsMeta( meta ) ) {\n\t\t\t\telements = elements.filter( ( element ) => element.id === meta.elementId );\n\t\t\t}\n\n\t\t\treturn elements.flatMap( ( element ) => Object.values( element.model.get( 'styles' ) ?? {} ) );\n\t\t},\n\n\t\tget: ( id, meta = {} ) => {\n\t\t\tif ( ! isValidElementsMeta( meta ) ) {\n\t\t\t\tthrow new InvalidElementsStyleProviderMetaError( { context: { meta } } );\n\t\t\t}\n\n\t\t\tconst styles = getElementStyles( meta.elementId ) ?? {};\n\n\t\t\treturn styles[ id ] ?? null;\n\t\t},\n\n\t\tupdateProps: ( args, meta = {} ) => {\n\t\t\tif ( ! isValidElementsMeta( meta ) ) {\n\t\t\t\tthrow new InvalidElementsStyleProviderMetaError( { context: { meta } } );\n\t\t\t}\n\n\t\t\tupdateElementStyle( {\n\t\t\t\telementId: meta.elementId,\n\t\t\t\tstyleId: args.id,\n\t\t\t\tmeta: args.meta,\n\t\t\t\tprops: args.props,\n\t\t\t} );\n\t\t},\n\t},\n} );\n\nfunction isValidElementsMeta( meta: Record< string, unknown > ): meta is ElementsMeta {\n\treturn 'elementId' in meta && typeof meta.elementId === 'string' && !! meta.elementId;\n}\n","import { createError } from '@elementor/utils';\n\nexport const InvalidElementsStyleProviderMetaError = createError< { meta: Record< string, unknown > } >( {\n\tcode: 'invalid_elements_style_provider_meta',\n\tmessage: 'Invalid elements style provider meta.',\n} );\n\nexport const ActiveDocumentMustExistError = createError( {\n\tcode: 'active_document_must_exist',\n\tmessage: 'Active document must exist.',\n} );\n","import { type StylesProvider } from '../types';\n\nexport type CreateStylesProviderOptions = {\n\tkey: string | ( () => string );\n\tpriority?: number;\n\tlimit?: number;\n\tsubscribe?: ( callback: () => void ) => () => void;\n\tlabels?: {\n\t\tsingular: string;\n\t\tplural: string;\n\t};\n\tactions: {\n\t\tall: StylesProvider[ 'actions' ][ 'all' ];\n\t\tget: StylesProvider[ 'actions' ][ 'get' ];\n\t\tcreate?: StylesProvider[ 'actions' ][ 'create' ];\n\t\tdelete?: StylesProvider[ 'actions' ][ 'delete' ];\n\t\tupdate?: StylesProvider[ 'actions' ][ 'update' ];\n\t\tupdateProps?: StylesProvider[ 'actions' ][ 'updateProps' ];\n\t};\n};\n\nconst DEFAULT_LIMIT = 10000;\nconst DEFAULT_PRIORITY = 10;\n\nexport function createStylesProvider( {\n\tkey,\n\tpriority = DEFAULT_PRIORITY,\n\tlimit = DEFAULT_LIMIT,\n\tsubscribe = () => () => {},\n\tlabels,\n\tactions,\n}: CreateStylesProviderOptions ): StylesProvider {\n\treturn {\n\t\tgetKey: typeof key === 'string' ? () => key : key,\n\t\tpriority,\n\t\tlimit,\n\t\tsubscribe,\n\t\tlabels: {\n\t\t\tsingular: labels?.singular ?? null,\n\t\t\tplural: labels?.plural ?? null,\n\t\t},\n\t\tactions: {\n\t\t\tall: actions.all,\n\t\t\tget: actions.get,\n\t\t\tcreate: actions.create,\n\t\t\tdelete: actions.delete,\n\t\t\tupdate: actions.update,\n\t\t\tupdateProps: actions.updateProps,\n\t\t},\n\t};\n}\n","import { ELEMENTS_STYLES_PROVIDER_KEY_PREFIX } from '../providers/document-elements-styles-provider';\n\nexport function isElementsStylesProvider( key: string ) {\n\treturn new RegExp( `^${ ELEMENTS_STYLES_PROVIDER_KEY_PREFIX }\\\\d+$` ).test( key );\n}\n","import { getWidgetsCache } from '@elementor/editor-elements';\n\nimport { createStylesProvider } from '../utils/create-styles-provider';\n\nexport const ELEMENTS_BASE_STYLES_PROVIDER_KEY = 'element-base-styles';\n\nexport const elementBaseStylesProvider = createStylesProvider( {\n\tkey: ELEMENTS_BASE_STYLES_PROVIDER_KEY,\n\tactions: {\n\t\tall() {\n\t\t\tconst widgetsCache = getWidgetsCache();\n\n\t\t\treturn Object.values( widgetsCache ?? {} ).flatMap( ( widget ) =>\n\t\t\t\tObject.values( widget.base_styles ?? {} )\n\t\t\t);\n\t\t},\n\n\t\tget( id ) {\n\t\t\treturn this.all().find( ( style ) => style.id === id ) ?? null;\n\t\t},\n\t},\n} );\n","import { documentElementsStylesProvider } from './providers/document-elements-styles-provider';\nimport { elementBaseStylesProvider } from './providers/element-base-styles-provider';\nimport { stylesRepository } from './styles-repository';\n\nexport function init() {\n\tstylesRepository.register( documentElementsStylesProvider );\n\tstylesRepository.register( elementBaseStylesProvider );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEO,IAAM,yBAAyB,MAAM;AAC3C,QAAM,YAA8B,CAAC;AAErC,QAAM,eAAe,MAAM;AAC1B,WAAO,UAAU,MAAO,CAAE,EAAE,KAAM,CAAE,GAAG,MAAS,EAAE,WAAW,EAAE,WAAW,KAAK,CAAI;AAAA,EACpF;AAEA,QAAM,WAAW,CAAE,aAA8B;AAChD,cAAU,KAAM,QAAS;AAAA,EAC1B;AAEA,QAAM,MAAM,CAAE,OAAa,CAAC,MAAO;AAClC,WAAO,aAAa,EAAE,QAAS,CAAE,aAAc,SAAS,QAAQ,IAAK,IAAK,CAAE;AAAA,EAC7E;AAEA,QAAM,YAAY,CAAE,OAAoB;AACvC,UAAM,eAAe,UAAU,IAAK,CAAE,aAAc;AACnD,aAAO,SAAS,UAAW,EAAG;AAAA,IAC/B,CAAE;AAEF,WAAO,MAAM;AACZ,mBAAa,QAAS,CAAE,gBAAiB,YAAY,CAAE;AAAA,IACxD;AAAA,EACD;AAEA,QAAM,mBAAmB,CAAE,QAAiB;AAC3C,WAAO,UAAU,KAAM,CAAE,aAAc,SAAS,OAAO,MAAM,GAAI;AAAA,EAClE;AAEA,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA;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