@plaudit/gutenberg-api-extensions 2.6.0 → 2.7.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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { BlockIcon } from "@wordpress/blocks";
|
|
2
|
+
import type { RadioControlProps } from "@wordpress/components/build-types/radio-control/types";
|
|
2
3
|
import type { RangeControlProps } from "@wordpress/components/build-types/range-control/types";
|
|
3
4
|
import type { TextControlProps } from "@wordpress/components/build-types/text-control/types";
|
|
4
5
|
import type { TextareaControlProps } from "@wordpress/components/build-types/textarea-control/types";
|
|
@@ -27,6 +28,12 @@ export declare function rangeProperty(config: CommonPropertyConfig<number, Range
|
|
|
27
28
|
step?: number;
|
|
28
29
|
enum?: number[];
|
|
29
30
|
}): SimpleNativeProperty;
|
|
31
|
+
export declare function radioProperty(config: CommonPropertyConfig<string, RadioControlProps> & {
|
|
32
|
+
options: PickableOptions<string>;
|
|
33
|
+
}): SimpleNativeProperty;
|
|
34
|
+
export declare function selectProperty(config: CommonPropertyConfig<string, never> & {
|
|
35
|
+
options: PickableOptions<string>;
|
|
36
|
+
}): SimpleNativeProperty;
|
|
30
37
|
export declare function toggleProperty(config: CommonPropertyConfig<boolean, ToggleControlProps>): SimpleNativeProperty;
|
|
31
38
|
type ToggleGroupPropertyConfigBase<T extends string | number> = CommonPropertyConfig<T, ToggleGroupControlProps> & {
|
|
32
39
|
options: PickableOptions<T, {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MediaUpload, MediaUploadCheck } from "@wordpress/block-editor";
|
|
2
|
-
import { Button, Card, CardBody, CardHeader, FocalPointPicker, RangeControl, ResponsiveWrapper, TextareaControl, TextControl, ToggleControl, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalHeading as Heading, __experimentalToggleGroupControlOption as ToggleGroupControlOption, __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon } from "@wordpress/components";
|
|
2
|
+
import { Button, Card, CardBody, CardHeader, FocalPointPicker, RadioControl, RangeControl, SelectControl, ResponsiveWrapper, TextareaControl, TextControl, ToggleControl, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalHeading as Heading, __experimentalToggleGroupControlOption as ToggleGroupControlOption, __experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon } from "@wordpress/components";
|
|
3
3
|
import { useSelect } from "@wordpress/data";
|
|
4
4
|
import { __ } from "@wordpress/i18n";
|
|
5
5
|
import React from "react";
|
|
@@ -16,6 +16,32 @@ export function rangeProperty(config) {
|
|
|
16
16
|
}
|
|
17
17
|
};
|
|
18
18
|
}
|
|
19
|
+
export function radioProperty(config) {
|
|
20
|
+
return {
|
|
21
|
+
name: config.name,
|
|
22
|
+
type: 'string',
|
|
23
|
+
enum: config.enum,
|
|
24
|
+
default: config.default,
|
|
25
|
+
condition: config.condition,
|
|
26
|
+
alwaysStore: config.alwaysStore,
|
|
27
|
+
renderer(value, onChange) {
|
|
28
|
+
return React.createElement(RadioControl, Object.assign({ selected: value, onChange: onChange, options: asOptions(config.options), label: config.label, help: config.help }, config.component));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export function selectProperty(config) {
|
|
33
|
+
return {
|
|
34
|
+
name: config.name,
|
|
35
|
+
type: 'string',
|
|
36
|
+
enum: config.enum,
|
|
37
|
+
default: config.default,
|
|
38
|
+
condition: config.condition,
|
|
39
|
+
alwaysStore: config.alwaysStore,
|
|
40
|
+
renderer(value, onChange) {
|
|
41
|
+
return React.createElement(SelectControl, { value: value !== null && value !== void 0 ? value : '', onChange: onChange, options: asOptions(config.options, ''), label: config.label, help: config.help });
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
19
45
|
export function toggleProperty(config) {
|
|
20
46
|
return {
|
|
21
47
|
name: config.name,
|
|
@@ -129,3 +155,10 @@ export function imageProperty(config) {
|
|
|
129
155
|
}
|
|
130
156
|
};
|
|
131
157
|
}
|
|
158
|
+
function asOptions(options, noSelectionValue) {
|
|
159
|
+
const res = options.map(opt => ({ value: opt[0], label: typeof opt[1] === 'string' ? opt[1] : opt[1].text }));
|
|
160
|
+
if (noSelectionValue !== undefined && !res.some(opt => !opt.value)) {
|
|
161
|
+
res.splice(0, 0, { value: noSelectionValue, label: "-- No Selection --" });
|
|
162
|
+
}
|
|
163
|
+
return res;
|
|
164
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plaudit/gutenberg-api-extensions",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepublishOnly": "rm -rf build && mkdir build && tsc",
|
|
6
6
|
"build": "tsc",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"react-dom": "^18.2.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@types/react": "^18.2.
|
|
37
|
+
"@types/react": "^18.2.57",
|
|
38
38
|
"@types/wordpress__block-editor": "^11.5.10",
|
|
39
39
|
"@types/wordpress__blocks": "^12.5.13",
|
|
40
40
|
"typescript": "^5.3.3"
|