@elementor/editor-global-classes 0.1.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/CHANGELOG.md +12 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +98 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +99 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +49 -0
- package/src/components/logic-hooks.tsx +46 -0
- package/src/global-classes-styles-provider.ts +11 -0
- package/src/index.ts +3 -0
- package/src/init.ts +18 -0
- package/src/store.ts +39 -0
package/CHANGELOG.md
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// src/init.ts
|
|
4
|
+
var import_editor = require("@elementor/editor");
|
|
5
|
+
var import_editor_styles_repository = require("@elementor/editor-styles-repository");
|
|
6
|
+
var import_store6 = require("@elementor/store");
|
|
7
|
+
|
|
8
|
+
// src/components/logic-hooks.tsx
|
|
9
|
+
var import_react = require("react");
|
|
10
|
+
var import_store2 = require("@elementor/store");
|
|
11
|
+
|
|
12
|
+
// src/store.ts
|
|
13
|
+
var import_store = require("@elementor/store");
|
|
14
|
+
var initialState = {
|
|
15
|
+
items: {},
|
|
16
|
+
order: []
|
|
17
|
+
};
|
|
18
|
+
var SLICE_NAME = "globalClasses";
|
|
19
|
+
var slice = (0, import_store.__createSlice)({
|
|
20
|
+
name: SLICE_NAME,
|
|
21
|
+
initialState,
|
|
22
|
+
reducers: {
|
|
23
|
+
init(state, { payload }) {
|
|
24
|
+
state.items = payload.items;
|
|
25
|
+
state.order = payload.order;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
var selectItems = (state) => state[SLICE_NAME].items;
|
|
30
|
+
var selectOrder = (state) => state[SLICE_NAME].order;
|
|
31
|
+
var selectOrderedGlobalClasses = (0, import_store.__createSelector)(
|
|
32
|
+
selectItems,
|
|
33
|
+
selectOrder,
|
|
34
|
+
(items, order) => order.map((id) => items[id])
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// src/components/logic-hooks.tsx
|
|
38
|
+
function LogicHooks() {
|
|
39
|
+
const dispatch = (0, import_store2.__useDispatch)();
|
|
40
|
+
(0, import_react.useEffect)(() => {
|
|
41
|
+
dispatch(
|
|
42
|
+
slice.actions.init({
|
|
43
|
+
items: {
|
|
44
|
+
"global-class-1": {
|
|
45
|
+
id: "global-class-1",
|
|
46
|
+
label: "Global Class 1",
|
|
47
|
+
type: "class",
|
|
48
|
+
variants: [
|
|
49
|
+
{
|
|
50
|
+
meta: {
|
|
51
|
+
state: null,
|
|
52
|
+
breakpoint: null
|
|
53
|
+
},
|
|
54
|
+
props: {
|
|
55
|
+
color: {
|
|
56
|
+
$$type: "color",
|
|
57
|
+
value: "#aaaaaa"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
"global-class-2": {
|
|
64
|
+
id: "global-class-2",
|
|
65
|
+
label: "Global Class 2",
|
|
66
|
+
type: "class",
|
|
67
|
+
variants: []
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
order: ["global-class-1", "global-class-2"]
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
}, [dispatch]);
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/global-classes-styles-provider.ts
|
|
78
|
+
var import_store4 = require("@elementor/store");
|
|
79
|
+
var globalClassesStylesProvider = {
|
|
80
|
+
key: "global-classes",
|
|
81
|
+
priority: 30,
|
|
82
|
+
get: () => selectOrderedGlobalClasses((0, import_store4.__getState)()),
|
|
83
|
+
subscribe: (cb) => (0, import_store4.__subscribe)(cb)
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// src/init.ts
|
|
87
|
+
function init() {
|
|
88
|
+
(0, import_store6.__registerSlice)(slice);
|
|
89
|
+
import_editor_styles_repository.stylesRepository.register(globalClassesStylesProvider);
|
|
90
|
+
(0, import_editor.injectIntoLogic)({
|
|
91
|
+
id: "global-classes-hooks",
|
|
92
|
+
component: LogicHooks
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// src/index.ts
|
|
97
|
+
init();
|
|
98
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/init.ts","../src/components/logic-hooks.tsx","../src/store.ts","../src/global-classes-styles-provider.ts","../src/index.ts"],"sourcesContent":["import { injectIntoLogic } from '@elementor/editor';\nimport { stylesRepository } from '@elementor/editor-styles-repository';\nimport { __registerSlice as registerSlice } from '@elementor/store';\n\nimport { LogicHooks } from './components/logic-hooks';\nimport { globalClassesStylesProvider } from './global-classes-styles-provider';\nimport { slice } from './store';\n\nexport function init() {\n\tregisterSlice( slice );\n\n\tstylesRepository.register( globalClassesStylesProvider );\n\n\tinjectIntoLogic( {\n\t\tid: 'global-classes-hooks',\n\t\tcomponent: LogicHooks,\n\t} );\n}\n","import { useEffect } from 'react';\nimport { __useDispatch as useDispatch } from '@elementor/store';\n\nimport { slice } from '../store';\n\nexport function LogicHooks() {\n\tconst dispatch = useDispatch();\n\n\tuseEffect( () => {\n\t\t// TODO: Replace with loading from the server.\n\t\tdispatch(\n\t\t\tslice.actions.init( {\n\t\t\t\titems: {\n\t\t\t\t\t'global-class-1': {\n\t\t\t\t\t\tid: 'global-class-1',\n\t\t\t\t\t\tlabel: 'Global Class 1',\n\t\t\t\t\t\ttype: 'class',\n\t\t\t\t\t\tvariants: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t\tstate: null,\n\t\t\t\t\t\t\t\t\tbreakpoint: null,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tprops: {\n\t\t\t\t\t\t\t\t\tcolor: {\n\t\t\t\t\t\t\t\t\t\t$$type: 'color',\n\t\t\t\t\t\t\t\t\t\tvalue: '#aaaaaa',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\t'global-class-2': {\n\t\t\t\t\t\tid: 'global-class-2',\n\t\t\t\t\t\tlabel: 'Global Class 2',\n\t\t\t\t\t\ttype: 'class',\n\t\t\t\t\t\tvariants: [],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\torder: [ 'global-class-1', 'global-class-2' ],\n\t\t\t} )\n\t\t);\n\t}, [ dispatch ] );\n\n\treturn null;\n}\n","import { type StyleDefinition, type StyleDefinitionID } from '@elementor/editor-styles';\nimport {\n\t__createSelector as createSelector,\n\t__createSlice as createSlice,\n\ttype PayloadAction,\n\ttype SliceState,\n} from '@elementor/store';\n\ntype State = {\n\titems: Record< StyleDefinitionID, StyleDefinition >;\n\torder: StyleDefinitionID[];\n};\n\nconst initialState: State = {\n\titems: {},\n\torder: [],\n};\n\n// Slice\nexport const SLICE_NAME = 'globalClasses';\n\nexport const slice = createSlice( {\n\tname: SLICE_NAME,\n\tinitialState,\n\treducers: {\n\t\tinit( state, { payload }: PayloadAction< State > ) {\n\t\t\tstate.items = payload.items;\n\t\t\tstate.order = payload.order;\n\t\t},\n\t},\n} );\n\n// Selectors\nconst selectItems = ( state: SliceState< typeof slice > ) => state[ SLICE_NAME ].items;\nconst selectOrder = ( state: SliceState< typeof slice > ) => state[ SLICE_NAME ].order;\n\nexport const selectOrderedGlobalClasses = createSelector( selectItems, selectOrder, ( items, order ) =>\n\torder.map( ( id ) => items[ id ] )\n);\n","import type { StylesProvider } from '@elementor/editor-styles-repository';\nimport { __getState as getState, __subscribe as subscribe } from '@elementor/store';\n\nimport { selectOrderedGlobalClasses } from './store';\n\nexport const globalClassesStylesProvider: StylesProvider = {\n\tkey: 'global-classes',\n\tpriority: 30,\n\tget: () => selectOrderedGlobalClasses( getState() ),\n\tsubscribe: ( cb ) => subscribe( cb ),\n};\n","import { init } from './init';\n\ninit();\n"],"mappings":";;;AAAA,oBAAgC;AAChC,sCAAiC;AACjC,IAAAA,gBAAiD;;;ACFjD,mBAA0B;AAC1B,IAAAC,gBAA6C;;;ACA7C,mBAKO;AAOP,IAAM,eAAsB;AAAA,EAC3B,OAAO,CAAC;AAAA,EACR,OAAO,CAAC;AACT;AAGO,IAAM,aAAa;AAEnB,IAAM,YAAQ,aAAAC,eAAa;AAAA,EACjC,MAAM;AAAA,EACN;AAAA,EACA,UAAU;AAAA,IACT,KAAM,OAAO,EAAE,QAAQ,GAA4B;AAClD,YAAM,QAAQ,QAAQ;AACtB,YAAM,QAAQ,QAAQ;AAAA,IACvB;AAAA,EACD;AACD,CAAE;AAGF,IAAM,cAAc,CAAE,UAAuC,MAAO,UAAW,EAAE;AACjF,IAAM,cAAc,CAAE,UAAuC,MAAO,UAAW,EAAE;AAE1E,IAAM,iCAA6B,aAAAC;AAAA,EAAgB;AAAA,EAAa;AAAA,EAAa,CAAE,OAAO,UAC5F,MAAM,IAAK,CAAE,OAAQ,MAAO,EAAG,CAAE;AAClC;;;ADjCO,SAAS,aAAa;AAC5B,QAAM,eAAW,cAAAC,eAAY;AAE7B,8BAAW,MAAM;AAEhB;AAAA,MACC,MAAM,QAAQ,KAAM;AAAA,QACnB,OAAO;AAAA,UACN,kBAAkB;AAAA,YACjB,IAAI;AAAA,YACJ,OAAO;AAAA,YACP,MAAM;AAAA,YACN,UAAU;AAAA,cACT;AAAA,gBACC,MAAM;AAAA,kBACL,OAAO;AAAA,kBACP,YAAY;AAAA,gBACb;AAAA,gBACA,OAAO;AAAA,kBACN,OAAO;AAAA,oBACN,QAAQ;AAAA,oBACR,OAAO;AAAA,kBACR;AAAA,gBACD;AAAA,cACD;AAAA,YACD;AAAA,UACD;AAAA,UACA,kBAAkB;AAAA,YACjB,IAAI;AAAA,YACJ,OAAO;AAAA,YACP,MAAM;AAAA,YACN,UAAU,CAAC;AAAA,UACZ;AAAA,QACD;AAAA,QACA,OAAO,CAAE,kBAAkB,gBAAiB;AAAA,MAC7C,CAAE;AAAA,IACH;AAAA,EACD,GAAG,CAAE,QAAS,CAAE;AAEhB,SAAO;AACR;;;AE5CA,IAAAC,gBAAiE;AAI1D,IAAM,8BAA8C;AAAA,EAC1D,KAAK;AAAA,EACL,UAAU;AAAA,EACV,KAAK,MAAM,+BAA4B,cAAAC,YAAS,CAAE;AAAA,EAClD,WAAW,CAAE,WAAQ,cAAAC,aAAW,EAAG;AACpC;;;AHFO,SAAS,OAAO;AACtB,oBAAAC,iBAAe,KAAM;AAErB,mDAAiB,SAAU,2BAA4B;AAEvD,qCAAiB;AAAA,IAChB,IAAI;AAAA,IACJ,WAAW;AAAA,EACZ,CAAE;AACH;;;AIfA,KAAK;","names":["import_store","import_store","createSlice","createSelector","useDispatch","import_store","getState","subscribe","registerSlice"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// src/init.ts
|
|
2
|
+
import { injectIntoLogic } from "@elementor/editor";
|
|
3
|
+
import { stylesRepository } from "@elementor/editor-styles-repository";
|
|
4
|
+
import { __registerSlice as registerSlice } from "@elementor/store";
|
|
5
|
+
|
|
6
|
+
// src/components/logic-hooks.tsx
|
|
7
|
+
import { useEffect } from "react";
|
|
8
|
+
import { __useDispatch as useDispatch } from "@elementor/store";
|
|
9
|
+
|
|
10
|
+
// src/store.ts
|
|
11
|
+
import {
|
|
12
|
+
__createSelector as createSelector,
|
|
13
|
+
__createSlice as createSlice
|
|
14
|
+
} from "@elementor/store";
|
|
15
|
+
var initialState = {
|
|
16
|
+
items: {},
|
|
17
|
+
order: []
|
|
18
|
+
};
|
|
19
|
+
var SLICE_NAME = "globalClasses";
|
|
20
|
+
var slice = createSlice({
|
|
21
|
+
name: SLICE_NAME,
|
|
22
|
+
initialState,
|
|
23
|
+
reducers: {
|
|
24
|
+
init(state, { payload }) {
|
|
25
|
+
state.items = payload.items;
|
|
26
|
+
state.order = payload.order;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
var selectItems = (state) => state[SLICE_NAME].items;
|
|
31
|
+
var selectOrder = (state) => state[SLICE_NAME].order;
|
|
32
|
+
var selectOrderedGlobalClasses = createSelector(
|
|
33
|
+
selectItems,
|
|
34
|
+
selectOrder,
|
|
35
|
+
(items, order) => order.map((id) => items[id])
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// src/components/logic-hooks.tsx
|
|
39
|
+
function LogicHooks() {
|
|
40
|
+
const dispatch = useDispatch();
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
dispatch(
|
|
43
|
+
slice.actions.init({
|
|
44
|
+
items: {
|
|
45
|
+
"global-class-1": {
|
|
46
|
+
id: "global-class-1",
|
|
47
|
+
label: "Global Class 1",
|
|
48
|
+
type: "class",
|
|
49
|
+
variants: [
|
|
50
|
+
{
|
|
51
|
+
meta: {
|
|
52
|
+
state: null,
|
|
53
|
+
breakpoint: null
|
|
54
|
+
},
|
|
55
|
+
props: {
|
|
56
|
+
color: {
|
|
57
|
+
$$type: "color",
|
|
58
|
+
value: "#aaaaaa"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
"global-class-2": {
|
|
65
|
+
id: "global-class-2",
|
|
66
|
+
label: "Global Class 2",
|
|
67
|
+
type: "class",
|
|
68
|
+
variants: []
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
order: ["global-class-1", "global-class-2"]
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
}, [dispatch]);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// src/global-classes-styles-provider.ts
|
|
79
|
+
import { __getState as getState, __subscribe as subscribe } from "@elementor/store";
|
|
80
|
+
var globalClassesStylesProvider = {
|
|
81
|
+
key: "global-classes",
|
|
82
|
+
priority: 30,
|
|
83
|
+
get: () => selectOrderedGlobalClasses(getState()),
|
|
84
|
+
subscribe: (cb) => subscribe(cb)
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
// src/init.ts
|
|
88
|
+
function init() {
|
|
89
|
+
registerSlice(slice);
|
|
90
|
+
stylesRepository.register(globalClassesStylesProvider);
|
|
91
|
+
injectIntoLogic({
|
|
92
|
+
id: "global-classes-hooks",
|
|
93
|
+
component: LogicHooks
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// src/index.ts
|
|
98
|
+
init();
|
|
99
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/init.ts","../src/components/logic-hooks.tsx","../src/store.ts","../src/global-classes-styles-provider.ts","../src/index.ts"],"sourcesContent":["import { injectIntoLogic } from '@elementor/editor';\nimport { stylesRepository } from '@elementor/editor-styles-repository';\nimport { __registerSlice as registerSlice } from '@elementor/store';\n\nimport { LogicHooks } from './components/logic-hooks';\nimport { globalClassesStylesProvider } from './global-classes-styles-provider';\nimport { slice } from './store';\n\nexport function init() {\n\tregisterSlice( slice );\n\n\tstylesRepository.register( globalClassesStylesProvider );\n\n\tinjectIntoLogic( {\n\t\tid: 'global-classes-hooks',\n\t\tcomponent: LogicHooks,\n\t} );\n}\n","import { useEffect } from 'react';\nimport { __useDispatch as useDispatch } from '@elementor/store';\n\nimport { slice } from '../store';\n\nexport function LogicHooks() {\n\tconst dispatch = useDispatch();\n\n\tuseEffect( () => {\n\t\t// TODO: Replace with loading from the server.\n\t\tdispatch(\n\t\t\tslice.actions.init( {\n\t\t\t\titems: {\n\t\t\t\t\t'global-class-1': {\n\t\t\t\t\t\tid: 'global-class-1',\n\t\t\t\t\t\tlabel: 'Global Class 1',\n\t\t\t\t\t\ttype: 'class',\n\t\t\t\t\t\tvariants: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tmeta: {\n\t\t\t\t\t\t\t\t\tstate: null,\n\t\t\t\t\t\t\t\t\tbreakpoint: null,\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\tprops: {\n\t\t\t\t\t\t\t\t\tcolor: {\n\t\t\t\t\t\t\t\t\t\t$$type: 'color',\n\t\t\t\t\t\t\t\t\t\tvalue: '#aaaaaa',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t\t'global-class-2': {\n\t\t\t\t\t\tid: 'global-class-2',\n\t\t\t\t\t\tlabel: 'Global Class 2',\n\t\t\t\t\t\ttype: 'class',\n\t\t\t\t\t\tvariants: [],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\torder: [ 'global-class-1', 'global-class-2' ],\n\t\t\t} )\n\t\t);\n\t}, [ dispatch ] );\n\n\treturn null;\n}\n","import { type StyleDefinition, type StyleDefinitionID } from '@elementor/editor-styles';\nimport {\n\t__createSelector as createSelector,\n\t__createSlice as createSlice,\n\ttype PayloadAction,\n\ttype SliceState,\n} from '@elementor/store';\n\ntype State = {\n\titems: Record< StyleDefinitionID, StyleDefinition >;\n\torder: StyleDefinitionID[];\n};\n\nconst initialState: State = {\n\titems: {},\n\torder: [],\n};\n\n// Slice\nexport const SLICE_NAME = 'globalClasses';\n\nexport const slice = createSlice( {\n\tname: SLICE_NAME,\n\tinitialState,\n\treducers: {\n\t\tinit( state, { payload }: PayloadAction< State > ) {\n\t\t\tstate.items = payload.items;\n\t\t\tstate.order = payload.order;\n\t\t},\n\t},\n} );\n\n// Selectors\nconst selectItems = ( state: SliceState< typeof slice > ) => state[ SLICE_NAME ].items;\nconst selectOrder = ( state: SliceState< typeof slice > ) => state[ SLICE_NAME ].order;\n\nexport const selectOrderedGlobalClasses = createSelector( selectItems, selectOrder, ( items, order ) =>\n\torder.map( ( id ) => items[ id ] )\n);\n","import type { StylesProvider } from '@elementor/editor-styles-repository';\nimport { __getState as getState, __subscribe as subscribe } from '@elementor/store';\n\nimport { selectOrderedGlobalClasses } from './store';\n\nexport const globalClassesStylesProvider: StylesProvider = {\n\tkey: 'global-classes',\n\tpriority: 30,\n\tget: () => selectOrderedGlobalClasses( getState() ),\n\tsubscribe: ( cb ) => subscribe( cb ),\n};\n","import { init } from './init';\n\ninit();\n"],"mappings":";AAAA,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,mBAAmB,qBAAqB;;;ACFjD,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB,mBAAmB;;;ACA7C;AAAA,EACC,oBAAoB;AAAA,EACpB,iBAAiB;AAAA,OAGX;AAOP,IAAM,eAAsB;AAAA,EAC3B,OAAO,CAAC;AAAA,EACR,OAAO,CAAC;AACT;AAGO,IAAM,aAAa;AAEnB,IAAM,QAAQ,YAAa;AAAA,EACjC,MAAM;AAAA,EACN;AAAA,EACA,UAAU;AAAA,IACT,KAAM,OAAO,EAAE,QAAQ,GAA4B;AAClD,YAAM,QAAQ,QAAQ;AACtB,YAAM,QAAQ,QAAQ;AAAA,IACvB;AAAA,EACD;AACD,CAAE;AAGF,IAAM,cAAc,CAAE,UAAuC,MAAO,UAAW,EAAE;AACjF,IAAM,cAAc,CAAE,UAAuC,MAAO,UAAW,EAAE;AAE1E,IAAM,6BAA6B;AAAA,EAAgB;AAAA,EAAa;AAAA,EAAa,CAAE,OAAO,UAC5F,MAAM,IAAK,CAAE,OAAQ,MAAO,EAAG,CAAE;AAClC;;;ADjCO,SAAS,aAAa;AAC5B,QAAM,WAAW,YAAY;AAE7B,YAAW,MAAM;AAEhB;AAAA,MACC,MAAM,QAAQ,KAAM;AAAA,QACnB,OAAO;AAAA,UACN,kBAAkB;AAAA,YACjB,IAAI;AAAA,YACJ,OAAO;AAAA,YACP,MAAM;AAAA,YACN,UAAU;AAAA,cACT;AAAA,gBACC,MAAM;AAAA,kBACL,OAAO;AAAA,kBACP,YAAY;AAAA,gBACb;AAAA,gBACA,OAAO;AAAA,kBACN,OAAO;AAAA,oBACN,QAAQ;AAAA,oBACR,OAAO;AAAA,kBACR;AAAA,gBACD;AAAA,cACD;AAAA,YACD;AAAA,UACD;AAAA,UACA,kBAAkB;AAAA,YACjB,IAAI;AAAA,YACJ,OAAO;AAAA,YACP,MAAM;AAAA,YACN,UAAU,CAAC;AAAA,UACZ;AAAA,QACD;AAAA,QACA,OAAO,CAAE,kBAAkB,gBAAiB;AAAA,MAC7C,CAAE;AAAA,IACH;AAAA,EACD,GAAG,CAAE,QAAS,CAAE;AAEhB,SAAO;AACR;;;AE5CA,SAAS,cAAc,UAAU,eAAe,iBAAiB;AAI1D,IAAM,8BAA8C;AAAA,EAC1D,KAAK;AAAA,EACL,UAAU;AAAA,EACV,KAAK,MAAM,2BAA4B,SAAS,CAAE;AAAA,EAClD,WAAW,CAAE,OAAQ,UAAW,EAAG;AACpC;;;AHFO,SAAS,OAAO;AACtB,gBAAe,KAAM;AAErB,mBAAiB,SAAU,2BAA4B;AAEvD,kBAAiB;AAAA,IAChB,IAAI;AAAA,IACJ,WAAW;AAAA,EACZ,CAAE;AACH;;;AIfA,KAAK;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elementor/editor-global-classes",
|
|
3
|
+
"version": "0.1.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
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.mjs",
|
|
15
|
+
"require": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./package.json": "./package.json"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/elementor/elementor-packages.git",
|
|
22
|
+
"directory": "packages/core/editor-global-classes"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/elementor/elementor-packages/issues"
|
|
26
|
+
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"files": [
|
|
31
|
+
"README.md",
|
|
32
|
+
"CHANGELOG.md",
|
|
33
|
+
"/dist",
|
|
34
|
+
"/src",
|
|
35
|
+
"!**/__tests__"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "tsup --config=../../tsup.build.ts",
|
|
39
|
+
"dev": "tsup --config=../../tsup.dev.ts"
|
|
40
|
+
},
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"@elementor/store": "0.8.6",
|
|
43
|
+
"@elementor/editor-styles-repository": "0.3.0",
|
|
44
|
+
"@elementor/editor": "0.17.2"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": "^18.3.1"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { __useDispatch as useDispatch } from '@elementor/store';
|
|
3
|
+
|
|
4
|
+
import { slice } from '../store';
|
|
5
|
+
|
|
6
|
+
export function LogicHooks() {
|
|
7
|
+
const dispatch = useDispatch();
|
|
8
|
+
|
|
9
|
+
useEffect( () => {
|
|
10
|
+
// TODO: Replace with loading from the server.
|
|
11
|
+
dispatch(
|
|
12
|
+
slice.actions.init( {
|
|
13
|
+
items: {
|
|
14
|
+
'global-class-1': {
|
|
15
|
+
id: 'global-class-1',
|
|
16
|
+
label: 'Global Class 1',
|
|
17
|
+
type: 'class',
|
|
18
|
+
variants: [
|
|
19
|
+
{
|
|
20
|
+
meta: {
|
|
21
|
+
state: null,
|
|
22
|
+
breakpoint: null,
|
|
23
|
+
},
|
|
24
|
+
props: {
|
|
25
|
+
color: {
|
|
26
|
+
$$type: 'color',
|
|
27
|
+
value: '#aaaaaa',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
},
|
|
33
|
+
'global-class-2': {
|
|
34
|
+
id: 'global-class-2',
|
|
35
|
+
label: 'Global Class 2',
|
|
36
|
+
type: 'class',
|
|
37
|
+
variants: [],
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
order: [ 'global-class-1', 'global-class-2' ],
|
|
41
|
+
} )
|
|
42
|
+
);
|
|
43
|
+
}, [ dispatch ] );
|
|
44
|
+
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { StylesProvider } from '@elementor/editor-styles-repository';
|
|
2
|
+
import { __getState as getState, __subscribe as subscribe } from '@elementor/store';
|
|
3
|
+
|
|
4
|
+
import { selectOrderedGlobalClasses } from './store';
|
|
5
|
+
|
|
6
|
+
export const globalClassesStylesProvider: StylesProvider = {
|
|
7
|
+
key: 'global-classes',
|
|
8
|
+
priority: 30,
|
|
9
|
+
get: () => selectOrderedGlobalClasses( getState() ),
|
|
10
|
+
subscribe: ( cb ) => subscribe( cb ),
|
|
11
|
+
};
|
package/src/index.ts
ADDED
package/src/init.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { injectIntoLogic } from '@elementor/editor';
|
|
2
|
+
import { stylesRepository } from '@elementor/editor-styles-repository';
|
|
3
|
+
import { __registerSlice as registerSlice } from '@elementor/store';
|
|
4
|
+
|
|
5
|
+
import { LogicHooks } from './components/logic-hooks';
|
|
6
|
+
import { globalClassesStylesProvider } from './global-classes-styles-provider';
|
|
7
|
+
import { slice } from './store';
|
|
8
|
+
|
|
9
|
+
export function init() {
|
|
10
|
+
registerSlice( slice );
|
|
11
|
+
|
|
12
|
+
stylesRepository.register( globalClassesStylesProvider );
|
|
13
|
+
|
|
14
|
+
injectIntoLogic( {
|
|
15
|
+
id: 'global-classes-hooks',
|
|
16
|
+
component: LogicHooks,
|
|
17
|
+
} );
|
|
18
|
+
}
|
package/src/store.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type StyleDefinition, type StyleDefinitionID } from '@elementor/editor-styles';
|
|
2
|
+
import {
|
|
3
|
+
__createSelector as createSelector,
|
|
4
|
+
__createSlice as createSlice,
|
|
5
|
+
type PayloadAction,
|
|
6
|
+
type SliceState,
|
|
7
|
+
} from '@elementor/store';
|
|
8
|
+
|
|
9
|
+
type State = {
|
|
10
|
+
items: Record< StyleDefinitionID, StyleDefinition >;
|
|
11
|
+
order: StyleDefinitionID[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const initialState: State = {
|
|
15
|
+
items: {},
|
|
16
|
+
order: [],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// Slice
|
|
20
|
+
export const SLICE_NAME = 'globalClasses';
|
|
21
|
+
|
|
22
|
+
export const slice = createSlice( {
|
|
23
|
+
name: SLICE_NAME,
|
|
24
|
+
initialState,
|
|
25
|
+
reducers: {
|
|
26
|
+
init( state, { payload }: PayloadAction< State > ) {
|
|
27
|
+
state.items = payload.items;
|
|
28
|
+
state.order = payload.order;
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
} );
|
|
32
|
+
|
|
33
|
+
// Selectors
|
|
34
|
+
const selectItems = ( state: SliceState< typeof slice > ) => state[ SLICE_NAME ].items;
|
|
35
|
+
const selectOrder = ( state: SliceState< typeof slice > ) => state[ SLICE_NAME ].order;
|
|
36
|
+
|
|
37
|
+
export const selectOrderedGlobalClasses = createSelector( selectItems, selectOrder, ( items, order ) =>
|
|
38
|
+
order.map( ( id ) => items[ id ] )
|
|
39
|
+
);
|