@elementor/editor-variables 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 +20 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +143 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +106 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -0
- package/src/components/variables-selection.tsx +27 -0
- package/src/controls/variables-selection-control.tsx +47 -0
- package/src/hooks/use-prop-variable-action.tsx +20 -0
- package/src/index.ts +1 -0
- package/src/init.ts +24 -0
- package/src/prop-types/color-variable-prop-type.ts +4 -0
- package/src/transformers/variable-transformer.ts +9 -0
- package/src/utils.ts +11 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# @elementor/editor-variables
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 97e4d7d: create `editor-variables` package
|
|
8
|
+
- 9eb90c2: styled variable replaces control component
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- Updated dependencies [093b7ca]
|
|
13
|
+
- Updated dependencies [5f348b8]
|
|
14
|
+
- Updated dependencies [10cbbe9]
|
|
15
|
+
- Updated dependencies [ce1852b]
|
|
16
|
+
- Updated dependencies [baa9d17]
|
|
17
|
+
- Updated dependencies [97e4d7d]
|
|
18
|
+
- @elementor/editor-controls@0.27.0
|
|
19
|
+
- @elementor/editor-editing-panel@1.30.0
|
|
20
|
+
- @elementor/editor-canvas@0.19.0
|
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
init: () => init
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
|
+
|
|
37
|
+
// src/init.ts
|
|
38
|
+
var import_editor_canvas2 = require("@elementor/editor-canvas");
|
|
39
|
+
var import_editor_editing_panel2 = require("@elementor/editor-editing-panel");
|
|
40
|
+
|
|
41
|
+
// src/controls/variables-selection-control.tsx
|
|
42
|
+
var React = __toESM(require("react"));
|
|
43
|
+
var import_editor_controls = require("@elementor/editor-controls");
|
|
44
|
+
var import_icons = require("@elementor/icons");
|
|
45
|
+
var import_ui = require("@elementor/ui");
|
|
46
|
+
var import_i18n = require("@wordpress/i18n");
|
|
47
|
+
var VariablesSelectionControl = () => {
|
|
48
|
+
const { setValue } = (0, import_editor_controls.useBoundProp)();
|
|
49
|
+
const value = "#FF7BE5";
|
|
50
|
+
const label = "Light Fuchsia Pink";
|
|
51
|
+
const unlinkVariable = () => {
|
|
52
|
+
setValue(null);
|
|
53
|
+
};
|
|
54
|
+
return /* @__PURE__ */ React.createElement(import_ui.Box, null, /* @__PURE__ */ React.createElement(
|
|
55
|
+
import_ui.UnstableTag,
|
|
56
|
+
{
|
|
57
|
+
fullWidth: true,
|
|
58
|
+
showActionsOnHover: true,
|
|
59
|
+
startIcon: /* @__PURE__ */ React.createElement(import_ui.Stack, { spacing: 1, direction: "row", alignItems: "center" }, /* @__PURE__ */ React.createElement(StyledUnstableColorIndicator, { size: "inherit", component: "span", value }), /* @__PURE__ */ React.createElement(import_icons.ColorFilterIcon, { fontSize: "inherit", sx: { mr: 1 } })),
|
|
60
|
+
label: /* @__PURE__ */ React.createElement(import_ui.Box, { sx: { display: "inline-grid" } }, /* @__PURE__ */ React.createElement(import_ui.Typography, { sx: { textOverflow: "ellipsis", overflowX: "hidden" }, variant: "subtitle2" }, label)),
|
|
61
|
+
actions: /* @__PURE__ */ React.createElement(import_ui.IconButton, { size: "tiny", onClick: unlinkVariable, "aria-label": (0, import_i18n.__)("Unlink", "elementor") }, /* @__PURE__ */ React.createElement(import_icons.DetachIcon, { fontSize: "tiny" }))
|
|
62
|
+
}
|
|
63
|
+
));
|
|
64
|
+
};
|
|
65
|
+
var StyledUnstableColorIndicator = (0, import_ui.styled)(import_ui.UnstableColorIndicator)(({ theme }) => ({
|
|
66
|
+
borderRadius: `${theme.shape.borderRadius / 2}px`
|
|
67
|
+
}));
|
|
68
|
+
|
|
69
|
+
// src/hooks/use-prop-variable-action.tsx
|
|
70
|
+
var React3 = __toESM(require("react"));
|
|
71
|
+
var import_editor_editing_panel = require("@elementor/editor-editing-panel");
|
|
72
|
+
var import_icons2 = require("@elementor/icons");
|
|
73
|
+
var import_i18n3 = require("@wordpress/i18n");
|
|
74
|
+
|
|
75
|
+
// src/components/variables-selection.tsx
|
|
76
|
+
var React2 = __toESM(require("react"));
|
|
77
|
+
var import_editor_controls2 = require("@elementor/editor-controls");
|
|
78
|
+
var import_ui2 = require("@elementor/ui");
|
|
79
|
+
var import_i18n2 = require("@wordpress/i18n");
|
|
80
|
+
|
|
81
|
+
// src/prop-types/color-variable-prop-type.ts
|
|
82
|
+
var import_editor_props = require("@elementor/editor-props");
|
|
83
|
+
var import_schema = require("@elementor/schema");
|
|
84
|
+
var colorVariablePropTypeUtil = (0, import_editor_props.createPropUtils)("global-color-variable", import_schema.z.string());
|
|
85
|
+
|
|
86
|
+
// src/components/variables-selection.tsx
|
|
87
|
+
var VariablesSelection = ({ onSelect }) => {
|
|
88
|
+
const { setValue: setVariable } = (0, import_editor_controls2.useBoundProp)(colorVariablePropTypeUtil);
|
|
89
|
+
const handleSetVariable = () => {
|
|
90
|
+
const value = colorVariablePropTypeUtil.create("");
|
|
91
|
+
setVariable(value.value);
|
|
92
|
+
onSelect?.();
|
|
93
|
+
};
|
|
94
|
+
return /* @__PURE__ */ React2.createElement(import_ui2.Box, { sx: { overflowY: "auto", height: 260, width: 220 } }, /* @__PURE__ */ React2.createElement(import_ui2.MenuItem, { onClick: handleSetVariable }, (0, import_i18n2.__)("Variables", "elementor")));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// src/utils.ts
|
|
98
|
+
var hasAssignedVariable = (propValue) => {
|
|
99
|
+
return !!colorVariablePropTypeUtil.isValid(propValue);
|
|
100
|
+
};
|
|
101
|
+
var supportsVariables = (propType) => {
|
|
102
|
+
return propType.kind === "union" && colorVariablePropTypeUtil.key in propType.prop_types;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// src/hooks/use-prop-variable-action.tsx
|
|
106
|
+
var usePropVariableAction = () => {
|
|
107
|
+
const { propType } = (0, import_editor_editing_panel.useBoundProp)();
|
|
108
|
+
const visible = !!propType && supportsVariables(propType);
|
|
109
|
+
return {
|
|
110
|
+
visible,
|
|
111
|
+
icon: import_icons2.ColorFilterIcon,
|
|
112
|
+
title: (0, import_i18n3.__)("Variables", "elementor"),
|
|
113
|
+
popoverContent: ({ closePopover }) => /* @__PURE__ */ React3.createElement(VariablesSelection, { onSelect: closePopover })
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// src/transformers/variable-transformer.ts
|
|
118
|
+
var import_editor_canvas = require("@elementor/editor-canvas");
|
|
119
|
+
var variableTransformer = (0, import_editor_canvas.createTransformer)((value) => {
|
|
120
|
+
if (!value.trim()) {
|
|
121
|
+
return null;
|
|
122
|
+
}
|
|
123
|
+
return `var(--${value})`;
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
// src/init.ts
|
|
127
|
+
var { registerPopoverAction } = import_editor_editing_panel2.controlActionsMenu;
|
|
128
|
+
function init() {
|
|
129
|
+
(0, import_editor_editing_panel2.registerControlReplacement)({
|
|
130
|
+
component: VariablesSelectionControl,
|
|
131
|
+
condition: ({ value }) => hasAssignedVariable(value)
|
|
132
|
+
});
|
|
133
|
+
registerPopoverAction({
|
|
134
|
+
id: "variables",
|
|
135
|
+
useProps: usePropVariableAction
|
|
136
|
+
});
|
|
137
|
+
import_editor_canvas2.styleTransformersRegistry.register(colorVariablePropTypeUtil.key, variableTransformer);
|
|
138
|
+
}
|
|
139
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
140
|
+
0 && (module.exports = {
|
|
141
|
+
init
|
|
142
|
+
});
|
|
143
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/init.ts","../src/controls/variables-selection-control.tsx","../src/hooks/use-prop-variable-action.tsx","../src/components/variables-selection.tsx","../src/prop-types/color-variable-prop-type.ts","../src/utils.ts","../src/transformers/variable-transformer.ts"],"sourcesContent":["export { init } from './init';\n","import { styleTransformersRegistry } from '@elementor/editor-canvas';\nimport { controlActionsMenu, registerControlReplacement } from '@elementor/editor-editing-panel';\n\nimport { VariablesSelectionControl } from './controls/variables-selection-control';\nimport { usePropVariableAction } from './hooks/use-prop-variable-action';\nimport { colorVariablePropTypeUtil } from './prop-types/color-variable-prop-type';\nimport { variableTransformer } from './transformers/variable-transformer';\nimport { hasAssignedVariable } from './utils';\n\nconst { registerPopoverAction } = controlActionsMenu;\n\nexport function init() {\n\tregisterControlReplacement( {\n\t\tcomponent: VariablesSelectionControl,\n\t\tcondition: ( { value } ) => hasAssignedVariable( value ),\n\t} );\n\n\tregisterPopoverAction( {\n\t\tid: 'variables',\n\t\tuseProps: usePropVariableAction,\n\t} );\n\n\tstyleTransformersRegistry.register( colorVariablePropTypeUtil.key, variableTransformer );\n}\n","import * as React from 'react';\nimport { useBoundProp } from '@elementor/editor-controls';\nimport { ColorFilterIcon, DetachIcon } from '@elementor/icons';\nimport { Box, IconButton, Stack, styled, Typography, UnstableColorIndicator, UnstableTag as Tag } from '@elementor/ui';\nimport { __ } from '@wordpress/i18n';\n\nexport const VariablesSelectionControl = () => {\n\tconst { setValue } = useBoundProp();\n\n\tconst value = '#FF7BE5';\n\tconst label = 'Light Fuchsia Pink';\n\n\tconst unlinkVariable = () => {\n\t\tsetValue( null );\n\t};\n\n\treturn (\n\t\t<Box>\n\t\t\t<Tag\n\t\t\t\tfullWidth\n\t\t\t\tshowActionsOnHover\n\t\t\t\tstartIcon={\n\t\t\t\t\t<Stack spacing={ 1 } direction=\"row\" alignItems=\"center\">\n\t\t\t\t\t\t<StyledUnstableColorIndicator size=\"inherit\" component=\"span\" value={ value } />\n\t\t\t\t\t\t<ColorFilterIcon fontSize={ 'inherit' } sx={ { mr: 1 } } />\n\t\t\t\t\t</Stack>\n\t\t\t\t}\n\t\t\t\tlabel={\n\t\t\t\t\t<Box sx={ { display: 'inline-grid' } }>\n\t\t\t\t\t\t<Typography sx={ { textOverflow: 'ellipsis', overflowX: 'hidden' } } variant=\"subtitle2\">\n\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t</Typography>\n\t\t\t\t\t</Box>\n\t\t\t\t}\n\t\t\t\tactions={\n\t\t\t\t\t<IconButton size={ 'tiny' } onClick={ unlinkVariable } aria-label={ __( 'Unlink', 'elementor' ) }>\n\t\t\t\t\t\t<DetachIcon fontSize={ 'tiny' } />\n\t\t\t\t\t</IconButton>\n\t\t\t\t}\n\t\t\t/>\n\t\t</Box>\n\t);\n};\n\nconst StyledUnstableColorIndicator = styled( UnstableColorIndicator )( ( { theme } ) => ( {\n\tborderRadius: `${ theme.shape.borderRadius / 2 }px`,\n} ) );\n","import * as React from 'react';\nimport { type PopoverActionProps, useBoundProp } from '@elementor/editor-editing-panel';\nimport { ColorFilterIcon } from '@elementor/icons';\nimport { __ } from '@wordpress/i18n';\n\nimport { VariablesSelection } from '../components/variables-selection';\nimport { supportsVariables } from '../utils';\n\nexport const usePropVariableAction = (): PopoverActionProps => {\n\tconst { propType } = useBoundProp();\n\n\tconst visible = !! propType && supportsVariables( propType );\n\n\treturn {\n\t\tvisible,\n\t\ticon: ColorFilterIcon,\n\t\ttitle: __( 'Variables', 'elementor' ),\n\t\tpopoverContent: ( { closePopover } ) => <VariablesSelection onSelect={ closePopover } />,\n\t};\n};\n","import * as React from 'react';\nimport { useBoundProp } from '@elementor/editor-controls';\nimport { Box, MenuItem } from '@elementor/ui';\nimport { __ } from '@wordpress/i18n';\n\nimport { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';\n\ntype Props = {\n\tonSelect?: () => void;\n};\n\nexport const VariablesSelection = ( { onSelect }: Props ) => {\n\tconst { setValue: setVariable } = useBoundProp( colorVariablePropTypeUtil );\n\n\tconst handleSetVariable = () => {\n\t\tconst value = colorVariablePropTypeUtil.create( '' );\n\n\t\tsetVariable( value.value );\n\t\tonSelect?.();\n\t};\n\n\treturn (\n\t\t<Box sx={ { overflowY: 'auto', height: 260, width: 220 } }>\n\t\t\t<MenuItem onClick={ handleSetVariable }>{ __( 'Variables', 'elementor' ) }</MenuItem>\n\t\t</Box>\n\t);\n};\n","import { createPropUtils } from '@elementor/editor-props';\nimport { z } from '@elementor/schema';\n\nexport const colorVariablePropTypeUtil = createPropUtils( 'global-color-variable', z.string() );\n","import { type PropType, type PropValue } from '@elementor/editor-props';\n\nimport { colorVariablePropTypeUtil } from './prop-types/color-variable-prop-type';\n\nexport const hasAssignedVariable = ( propValue: PropValue ): boolean => {\n\treturn !! colorVariablePropTypeUtil.isValid( propValue );\n};\n\nexport const supportsVariables = ( propType: PropType ): boolean => {\n\treturn propType.kind === 'union' && colorVariablePropTypeUtil.key in propType.prop_types;\n};\n","import { createTransformer } from '@elementor/editor-canvas';\n\nexport const variableTransformer = createTransformer( ( value: string ) => {\n\tif ( ! value.trim() ) {\n\t\treturn null;\n\t}\n\n\treturn `var(--${ value })`;\n} );\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,wBAA0C;AAC1C,IAAAC,+BAA+D;;;ACD/D,YAAuB;AACvB,6BAA6B;AAC7B,mBAA4C;AAC5C,gBAAuG;AACvG,kBAAmB;AAEZ,IAAM,4BAA4B,MAAM;AAC9C,QAAM,EAAE,SAAS,QAAI,qCAAa;AAElC,QAAM,QAAQ;AACd,QAAM,QAAQ;AAEd,QAAM,iBAAiB,MAAM;AAC5B,aAAU,IAAK;AAAA,EAChB;AAEA,SACC,oCAAC,qBACA;AAAA,IAAC,UAAAC;AAAA,IAAA;AAAA,MACA,WAAS;AAAA,MACT,oBAAkB;AAAA,MAClB,WACC,oCAAC,mBAAM,SAAU,GAAI,WAAU,OAAM,YAAW,YAC/C,oCAAC,gCAA6B,MAAK,WAAU,WAAU,QAAO,OAAgB,GAC9E,oCAAC,gCAAgB,UAAW,WAAY,IAAK,EAAE,IAAI,EAAE,GAAI,CAC1D;AAAA,MAED,OACC,oCAAC,iBAAI,IAAK,EAAE,SAAS,cAAc,KAClC,oCAAC,wBAAW,IAAK,EAAE,cAAc,YAAY,WAAW,SAAS,GAAI,SAAQ,eAC1E,KACH,CACD;AAAA,MAED,SACC,oCAAC,wBAAW,MAAO,QAAS,SAAU,gBAAiB,kBAAa,gBAAI,UAAU,WAAY,KAC7F,oCAAC,2BAAW,UAAW,QAAS,CACjC;AAAA;AAAA,EAEF,CACD;AAEF;AAEA,IAAM,mCAA+B,kBAAQ,gCAAuB,EAAG,CAAE,EAAE,MAAM,OAAS;AAAA,EACzF,cAAc,GAAI,MAAM,MAAM,eAAe,CAAE;AAChD,EAAI;;;AC9CJ,IAAAC,SAAuB;AACvB,kCAAsD;AACtD,IAAAC,gBAAgC;AAChC,IAAAC,eAAmB;;;ACHnB,IAAAC,SAAuB;AACvB,IAAAC,0BAA6B;AAC7B,IAAAC,aAA8B;AAC9B,IAAAC,eAAmB;;;ACHnB,0BAAgC;AAChC,oBAAkB;AAEX,IAAM,gCAA4B,qCAAiB,yBAAyB,gBAAE,OAAO,CAAE;;;ADQvF,IAAM,qBAAqB,CAAE,EAAE,SAAS,MAAc;AAC5D,QAAM,EAAE,UAAU,YAAY,QAAI,sCAAc,yBAA0B;AAE1E,QAAM,oBAAoB,MAAM;AAC/B,UAAM,QAAQ,0BAA0B,OAAQ,EAAG;AAEnD,gBAAa,MAAM,KAAM;AACzB,eAAW;AAAA,EACZ;AAEA,SACC,qCAAC,kBAAI,IAAK,EAAE,WAAW,QAAQ,QAAQ,KAAK,OAAO,IAAI,KACtD,qCAAC,uBAAS,SAAU,yBAAsB,iBAAI,aAAa,WAAY,CAAG,CAC3E;AAEF;;;AEtBO,IAAM,sBAAsB,CAAE,cAAmC;AACvE,SAAO,CAAC,CAAE,0BAA0B,QAAS,SAAU;AACxD;AAEO,IAAM,oBAAoB,CAAE,aAAiC;AACnE,SAAO,SAAS,SAAS,WAAW,0BAA0B,OAAO,SAAS;AAC/E;;;AHFO,IAAM,wBAAwB,MAA0B;AAC9D,QAAM,EAAE,SAAS,QAAI,0CAAa;AAElC,QAAM,UAAU,CAAC,CAAE,YAAY,kBAAmB,QAAS;AAE3D,SAAO;AAAA,IACN;AAAA,IACA,MAAM;AAAA,IACN,WAAO,iBAAI,aAAa,WAAY;AAAA,IACpC,gBAAgB,CAAE,EAAE,aAAa,MAAO,qCAAC,sBAAmB,UAAW,cAAe;AAAA,EACvF;AACD;;;AInBA,2BAAkC;AAE3B,IAAM,0BAAsB,wCAAmB,CAAE,UAAmB;AAC1E,MAAK,CAAE,MAAM,KAAK,GAAI;AACrB,WAAO;AAAA,EACR;AAEA,SAAO,SAAU,KAAM;AACxB,CAAE;;;ANCF,IAAM,EAAE,sBAAsB,IAAI;AAE3B,SAAS,OAAO;AACtB,+DAA4B;AAAA,IAC3B,WAAW;AAAA,IACX,WAAW,CAAE,EAAE,MAAM,MAAO,oBAAqB,KAAM;AAAA,EACxD,CAAE;AAEF,wBAAuB;AAAA,IACtB,IAAI;AAAA,IACJ,UAAU;AAAA,EACX,CAAE;AAEF,kDAA0B,SAAU,0BAA0B,KAAK,mBAAoB;AACxF;","names":["import_editor_canvas","import_editor_editing_panel","Tag","React","import_icons","import_i18n","React","import_editor_controls","import_ui","import_i18n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// src/init.ts
|
|
2
|
+
import { styleTransformersRegistry } from "@elementor/editor-canvas";
|
|
3
|
+
import { controlActionsMenu, registerControlReplacement } from "@elementor/editor-editing-panel";
|
|
4
|
+
|
|
5
|
+
// src/controls/variables-selection-control.tsx
|
|
6
|
+
import * as React from "react";
|
|
7
|
+
import { useBoundProp } from "@elementor/editor-controls";
|
|
8
|
+
import { ColorFilterIcon, DetachIcon } from "@elementor/icons";
|
|
9
|
+
import { Box, IconButton, Stack, styled, Typography, UnstableColorIndicator, UnstableTag as Tag } from "@elementor/ui";
|
|
10
|
+
import { __ } from "@wordpress/i18n";
|
|
11
|
+
var VariablesSelectionControl = () => {
|
|
12
|
+
const { setValue } = useBoundProp();
|
|
13
|
+
const value = "#FF7BE5";
|
|
14
|
+
const label = "Light Fuchsia Pink";
|
|
15
|
+
const unlinkVariable = () => {
|
|
16
|
+
setValue(null);
|
|
17
|
+
};
|
|
18
|
+
return /* @__PURE__ */ React.createElement(Box, null, /* @__PURE__ */ React.createElement(
|
|
19
|
+
Tag,
|
|
20
|
+
{
|
|
21
|
+
fullWidth: true,
|
|
22
|
+
showActionsOnHover: true,
|
|
23
|
+
startIcon: /* @__PURE__ */ React.createElement(Stack, { spacing: 1, direction: "row", alignItems: "center" }, /* @__PURE__ */ React.createElement(StyledUnstableColorIndicator, { size: "inherit", component: "span", value }), /* @__PURE__ */ React.createElement(ColorFilterIcon, { fontSize: "inherit", sx: { mr: 1 } })),
|
|
24
|
+
label: /* @__PURE__ */ React.createElement(Box, { sx: { display: "inline-grid" } }, /* @__PURE__ */ React.createElement(Typography, { sx: { textOverflow: "ellipsis", overflowX: "hidden" }, variant: "subtitle2" }, label)),
|
|
25
|
+
actions: /* @__PURE__ */ React.createElement(IconButton, { size: "tiny", onClick: unlinkVariable, "aria-label": __("Unlink", "elementor") }, /* @__PURE__ */ React.createElement(DetachIcon, { fontSize: "tiny" }))
|
|
26
|
+
}
|
|
27
|
+
));
|
|
28
|
+
};
|
|
29
|
+
var StyledUnstableColorIndicator = styled(UnstableColorIndicator)(({ theme }) => ({
|
|
30
|
+
borderRadius: `${theme.shape.borderRadius / 2}px`
|
|
31
|
+
}));
|
|
32
|
+
|
|
33
|
+
// src/hooks/use-prop-variable-action.tsx
|
|
34
|
+
import * as React3 from "react";
|
|
35
|
+
import { useBoundProp as useBoundProp3 } from "@elementor/editor-editing-panel";
|
|
36
|
+
import { ColorFilterIcon as ColorFilterIcon2 } from "@elementor/icons";
|
|
37
|
+
import { __ as __3 } from "@wordpress/i18n";
|
|
38
|
+
|
|
39
|
+
// src/components/variables-selection.tsx
|
|
40
|
+
import * as React2 from "react";
|
|
41
|
+
import { useBoundProp as useBoundProp2 } from "@elementor/editor-controls";
|
|
42
|
+
import { Box as Box2, MenuItem } from "@elementor/ui";
|
|
43
|
+
import { __ as __2 } from "@wordpress/i18n";
|
|
44
|
+
|
|
45
|
+
// src/prop-types/color-variable-prop-type.ts
|
|
46
|
+
import { createPropUtils } from "@elementor/editor-props";
|
|
47
|
+
import { z } from "@elementor/schema";
|
|
48
|
+
var colorVariablePropTypeUtil = createPropUtils("global-color-variable", z.string());
|
|
49
|
+
|
|
50
|
+
// src/components/variables-selection.tsx
|
|
51
|
+
var VariablesSelection = ({ onSelect }) => {
|
|
52
|
+
const { setValue: setVariable } = useBoundProp2(colorVariablePropTypeUtil);
|
|
53
|
+
const handleSetVariable = () => {
|
|
54
|
+
const value = colorVariablePropTypeUtil.create("");
|
|
55
|
+
setVariable(value.value);
|
|
56
|
+
onSelect?.();
|
|
57
|
+
};
|
|
58
|
+
return /* @__PURE__ */ React2.createElement(Box2, { sx: { overflowY: "auto", height: 260, width: 220 } }, /* @__PURE__ */ React2.createElement(MenuItem, { onClick: handleSetVariable }, __2("Variables", "elementor")));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/utils.ts
|
|
62
|
+
var hasAssignedVariable = (propValue) => {
|
|
63
|
+
return !!colorVariablePropTypeUtil.isValid(propValue);
|
|
64
|
+
};
|
|
65
|
+
var supportsVariables = (propType) => {
|
|
66
|
+
return propType.kind === "union" && colorVariablePropTypeUtil.key in propType.prop_types;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/hooks/use-prop-variable-action.tsx
|
|
70
|
+
var usePropVariableAction = () => {
|
|
71
|
+
const { propType } = useBoundProp3();
|
|
72
|
+
const visible = !!propType && supportsVariables(propType);
|
|
73
|
+
return {
|
|
74
|
+
visible,
|
|
75
|
+
icon: ColorFilterIcon2,
|
|
76
|
+
title: __3("Variables", "elementor"),
|
|
77
|
+
popoverContent: ({ closePopover }) => /* @__PURE__ */ React3.createElement(VariablesSelection, { onSelect: closePopover })
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/transformers/variable-transformer.ts
|
|
82
|
+
import { createTransformer } from "@elementor/editor-canvas";
|
|
83
|
+
var variableTransformer = createTransformer((value) => {
|
|
84
|
+
if (!value.trim()) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
return `var(--${value})`;
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// src/init.ts
|
|
91
|
+
var { registerPopoverAction } = controlActionsMenu;
|
|
92
|
+
function init() {
|
|
93
|
+
registerControlReplacement({
|
|
94
|
+
component: VariablesSelectionControl,
|
|
95
|
+
condition: ({ value }) => hasAssignedVariable(value)
|
|
96
|
+
});
|
|
97
|
+
registerPopoverAction({
|
|
98
|
+
id: "variables",
|
|
99
|
+
useProps: usePropVariableAction
|
|
100
|
+
});
|
|
101
|
+
styleTransformersRegistry.register(colorVariablePropTypeUtil.key, variableTransformer);
|
|
102
|
+
}
|
|
103
|
+
export {
|
|
104
|
+
init
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/init.ts","../src/controls/variables-selection-control.tsx","../src/hooks/use-prop-variable-action.tsx","../src/components/variables-selection.tsx","../src/prop-types/color-variable-prop-type.ts","../src/utils.ts","../src/transformers/variable-transformer.ts"],"sourcesContent":["import { styleTransformersRegistry } from '@elementor/editor-canvas';\nimport { controlActionsMenu, registerControlReplacement } from '@elementor/editor-editing-panel';\n\nimport { VariablesSelectionControl } from './controls/variables-selection-control';\nimport { usePropVariableAction } from './hooks/use-prop-variable-action';\nimport { colorVariablePropTypeUtil } from './prop-types/color-variable-prop-type';\nimport { variableTransformer } from './transformers/variable-transformer';\nimport { hasAssignedVariable } from './utils';\n\nconst { registerPopoverAction } = controlActionsMenu;\n\nexport function init() {\n\tregisterControlReplacement( {\n\t\tcomponent: VariablesSelectionControl,\n\t\tcondition: ( { value } ) => hasAssignedVariable( value ),\n\t} );\n\n\tregisterPopoverAction( {\n\t\tid: 'variables',\n\t\tuseProps: usePropVariableAction,\n\t} );\n\n\tstyleTransformersRegistry.register( colorVariablePropTypeUtil.key, variableTransformer );\n}\n","import * as React from 'react';\nimport { useBoundProp } from '@elementor/editor-controls';\nimport { ColorFilterIcon, DetachIcon } from '@elementor/icons';\nimport { Box, IconButton, Stack, styled, Typography, UnstableColorIndicator, UnstableTag as Tag } from '@elementor/ui';\nimport { __ } from '@wordpress/i18n';\n\nexport const VariablesSelectionControl = () => {\n\tconst { setValue } = useBoundProp();\n\n\tconst value = '#FF7BE5';\n\tconst label = 'Light Fuchsia Pink';\n\n\tconst unlinkVariable = () => {\n\t\tsetValue( null );\n\t};\n\n\treturn (\n\t\t<Box>\n\t\t\t<Tag\n\t\t\t\tfullWidth\n\t\t\t\tshowActionsOnHover\n\t\t\t\tstartIcon={\n\t\t\t\t\t<Stack spacing={ 1 } direction=\"row\" alignItems=\"center\">\n\t\t\t\t\t\t<StyledUnstableColorIndicator size=\"inherit\" component=\"span\" value={ value } />\n\t\t\t\t\t\t<ColorFilterIcon fontSize={ 'inherit' } sx={ { mr: 1 } } />\n\t\t\t\t\t</Stack>\n\t\t\t\t}\n\t\t\t\tlabel={\n\t\t\t\t\t<Box sx={ { display: 'inline-grid' } }>\n\t\t\t\t\t\t<Typography sx={ { textOverflow: 'ellipsis', overflowX: 'hidden' } } variant=\"subtitle2\">\n\t\t\t\t\t\t\t{ label }\n\t\t\t\t\t\t</Typography>\n\t\t\t\t\t</Box>\n\t\t\t\t}\n\t\t\t\tactions={\n\t\t\t\t\t<IconButton size={ 'tiny' } onClick={ unlinkVariable } aria-label={ __( 'Unlink', 'elementor' ) }>\n\t\t\t\t\t\t<DetachIcon fontSize={ 'tiny' } />\n\t\t\t\t\t</IconButton>\n\t\t\t\t}\n\t\t\t/>\n\t\t</Box>\n\t);\n};\n\nconst StyledUnstableColorIndicator = styled( UnstableColorIndicator )( ( { theme } ) => ( {\n\tborderRadius: `${ theme.shape.borderRadius / 2 }px`,\n} ) );\n","import * as React from 'react';\nimport { type PopoverActionProps, useBoundProp } from '@elementor/editor-editing-panel';\nimport { ColorFilterIcon } from '@elementor/icons';\nimport { __ } from '@wordpress/i18n';\n\nimport { VariablesSelection } from '../components/variables-selection';\nimport { supportsVariables } from '../utils';\n\nexport const usePropVariableAction = (): PopoverActionProps => {\n\tconst { propType } = useBoundProp();\n\n\tconst visible = !! propType && supportsVariables( propType );\n\n\treturn {\n\t\tvisible,\n\t\ticon: ColorFilterIcon,\n\t\ttitle: __( 'Variables', 'elementor' ),\n\t\tpopoverContent: ( { closePopover } ) => <VariablesSelection onSelect={ closePopover } />,\n\t};\n};\n","import * as React from 'react';\nimport { useBoundProp } from '@elementor/editor-controls';\nimport { Box, MenuItem } from '@elementor/ui';\nimport { __ } from '@wordpress/i18n';\n\nimport { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';\n\ntype Props = {\n\tonSelect?: () => void;\n};\n\nexport const VariablesSelection = ( { onSelect }: Props ) => {\n\tconst { setValue: setVariable } = useBoundProp( colorVariablePropTypeUtil );\n\n\tconst handleSetVariable = () => {\n\t\tconst value = colorVariablePropTypeUtil.create( '' );\n\n\t\tsetVariable( value.value );\n\t\tonSelect?.();\n\t};\n\n\treturn (\n\t\t<Box sx={ { overflowY: 'auto', height: 260, width: 220 } }>\n\t\t\t<MenuItem onClick={ handleSetVariable }>{ __( 'Variables', 'elementor' ) }</MenuItem>\n\t\t</Box>\n\t);\n};\n","import { createPropUtils } from '@elementor/editor-props';\nimport { z } from '@elementor/schema';\n\nexport const colorVariablePropTypeUtil = createPropUtils( 'global-color-variable', z.string() );\n","import { type PropType, type PropValue } from '@elementor/editor-props';\n\nimport { colorVariablePropTypeUtil } from './prop-types/color-variable-prop-type';\n\nexport const hasAssignedVariable = ( propValue: PropValue ): boolean => {\n\treturn !! colorVariablePropTypeUtil.isValid( propValue );\n};\n\nexport const supportsVariables = ( propType: PropType ): boolean => {\n\treturn propType.kind === 'union' && colorVariablePropTypeUtil.key in propType.prop_types;\n};\n","import { createTransformer } from '@elementor/editor-canvas';\n\nexport const variableTransformer = createTransformer( ( value: string ) => {\n\tif ( ! value.trim() ) {\n\t\treturn null;\n\t}\n\n\treturn `var(--${ value })`;\n} );\n"],"mappings":"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","names":["React","useBoundProp","ColorFilterIcon","__","React","useBoundProp","Box","__","useBoundProp","Box","__","useBoundProp","ColorFilterIcon","__"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@elementor/editor-variables",
|
|
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-variables"
|
|
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/editor-editing-panel": "1.30.0",
|
|
43
|
+
"@elementor/editor-canvas": "0.19.0",
|
|
44
|
+
"@elementor/editor-props": "0.12.0",
|
|
45
|
+
"@elementor/schema": "0.1.2",
|
|
46
|
+
"@elementor/editor-controls": "0.27.0",
|
|
47
|
+
"@elementor/icons": "1.37.0",
|
|
48
|
+
"@wordpress/i18n": "^5.13.0",
|
|
49
|
+
"@elementor/ui": "1.33.2"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"react": "^18.3.1"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"tsup": "^8.3.5"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useBoundProp } from '@elementor/editor-controls';
|
|
3
|
+
import { Box, MenuItem } from '@elementor/ui';
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
|
|
6
|
+
import { colorVariablePropTypeUtil } from '../prop-types/color-variable-prop-type';
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
onSelect?: () => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const VariablesSelection = ( { onSelect }: Props ) => {
|
|
13
|
+
const { setValue: setVariable } = useBoundProp( colorVariablePropTypeUtil );
|
|
14
|
+
|
|
15
|
+
const handleSetVariable = () => {
|
|
16
|
+
const value = colorVariablePropTypeUtil.create( '' );
|
|
17
|
+
|
|
18
|
+
setVariable( value.value );
|
|
19
|
+
onSelect?.();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Box sx={ { overflowY: 'auto', height: 260, width: 220 } }>
|
|
24
|
+
<MenuItem onClick={ handleSetVariable }>{ __( 'Variables', 'elementor' ) }</MenuItem>
|
|
25
|
+
</Box>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useBoundProp } from '@elementor/editor-controls';
|
|
3
|
+
import { ColorFilterIcon, DetachIcon } from '@elementor/icons';
|
|
4
|
+
import { Box, IconButton, Stack, styled, Typography, UnstableColorIndicator, UnstableTag as Tag } from '@elementor/ui';
|
|
5
|
+
import { __ } from '@wordpress/i18n';
|
|
6
|
+
|
|
7
|
+
export const VariablesSelectionControl = () => {
|
|
8
|
+
const { setValue } = useBoundProp();
|
|
9
|
+
|
|
10
|
+
const value = '#FF7BE5';
|
|
11
|
+
const label = 'Light Fuchsia Pink';
|
|
12
|
+
|
|
13
|
+
const unlinkVariable = () => {
|
|
14
|
+
setValue( null );
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<Box>
|
|
19
|
+
<Tag
|
|
20
|
+
fullWidth
|
|
21
|
+
showActionsOnHover
|
|
22
|
+
startIcon={
|
|
23
|
+
<Stack spacing={ 1 } direction="row" alignItems="center">
|
|
24
|
+
<StyledUnstableColorIndicator size="inherit" component="span" value={ value } />
|
|
25
|
+
<ColorFilterIcon fontSize={ 'inherit' } sx={ { mr: 1 } } />
|
|
26
|
+
</Stack>
|
|
27
|
+
}
|
|
28
|
+
label={
|
|
29
|
+
<Box sx={ { display: 'inline-grid' } }>
|
|
30
|
+
<Typography sx={ { textOverflow: 'ellipsis', overflowX: 'hidden' } } variant="subtitle2">
|
|
31
|
+
{ label }
|
|
32
|
+
</Typography>
|
|
33
|
+
</Box>
|
|
34
|
+
}
|
|
35
|
+
actions={
|
|
36
|
+
<IconButton size={ 'tiny' } onClick={ unlinkVariable } aria-label={ __( 'Unlink', 'elementor' ) }>
|
|
37
|
+
<DetachIcon fontSize={ 'tiny' } />
|
|
38
|
+
</IconButton>
|
|
39
|
+
}
|
|
40
|
+
/>
|
|
41
|
+
</Box>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const StyledUnstableColorIndicator = styled( UnstableColorIndicator )( ( { theme } ) => ( {
|
|
46
|
+
borderRadius: `${ theme.shape.borderRadius / 2 }px`,
|
|
47
|
+
} ) );
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type PopoverActionProps, useBoundProp } from '@elementor/editor-editing-panel';
|
|
3
|
+
import { ColorFilterIcon } from '@elementor/icons';
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
|
|
6
|
+
import { VariablesSelection } from '../components/variables-selection';
|
|
7
|
+
import { supportsVariables } from '../utils';
|
|
8
|
+
|
|
9
|
+
export const usePropVariableAction = (): PopoverActionProps => {
|
|
10
|
+
const { propType } = useBoundProp();
|
|
11
|
+
|
|
12
|
+
const visible = !! propType && supportsVariables( propType );
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
visible,
|
|
16
|
+
icon: ColorFilterIcon,
|
|
17
|
+
title: __( 'Variables', 'elementor' ),
|
|
18
|
+
popoverContent: ( { closePopover } ) => <VariablesSelection onSelect={ closePopover } />,
|
|
19
|
+
};
|
|
20
|
+
};
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { init } from './init';
|
package/src/init.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { styleTransformersRegistry } from '@elementor/editor-canvas';
|
|
2
|
+
import { controlActionsMenu, registerControlReplacement } from '@elementor/editor-editing-panel';
|
|
3
|
+
|
|
4
|
+
import { VariablesSelectionControl } from './controls/variables-selection-control';
|
|
5
|
+
import { usePropVariableAction } from './hooks/use-prop-variable-action';
|
|
6
|
+
import { colorVariablePropTypeUtil } from './prop-types/color-variable-prop-type';
|
|
7
|
+
import { variableTransformer } from './transformers/variable-transformer';
|
|
8
|
+
import { hasAssignedVariable } from './utils';
|
|
9
|
+
|
|
10
|
+
const { registerPopoverAction } = controlActionsMenu;
|
|
11
|
+
|
|
12
|
+
export function init() {
|
|
13
|
+
registerControlReplacement( {
|
|
14
|
+
component: VariablesSelectionControl,
|
|
15
|
+
condition: ( { value } ) => hasAssignedVariable( value ),
|
|
16
|
+
} );
|
|
17
|
+
|
|
18
|
+
registerPopoverAction( {
|
|
19
|
+
id: 'variables',
|
|
20
|
+
useProps: usePropVariableAction,
|
|
21
|
+
} );
|
|
22
|
+
|
|
23
|
+
styleTransformersRegistry.register( colorVariablePropTypeUtil.key, variableTransformer );
|
|
24
|
+
}
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type PropType, type PropValue } from '@elementor/editor-props';
|
|
2
|
+
|
|
3
|
+
import { colorVariablePropTypeUtil } from './prop-types/color-variable-prop-type';
|
|
4
|
+
|
|
5
|
+
export const hasAssignedVariable = ( propValue: PropValue ): boolean => {
|
|
6
|
+
return !! colorVariablePropTypeUtil.isValid( propValue );
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export const supportsVariables = ( propType: PropType ): boolean => {
|
|
10
|
+
return propType.kind === 'union' && colorVariablePropTypeUtil.key in propType.prop_types;
|
|
11
|
+
};
|