@plaudit/gutenberg-api-extensions 2.3.0 → 2.5.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,6 +1,10 @@
1
+ import type { BlockIcon } from "@wordpress/blocks";
1
2
  import type { RangeControlProps } from "@wordpress/components/build-types/range-control/types";
2
3
  import type { TextControlProps } from "@wordpress/components/build-types/text-control/types";
3
4
  import type { TextareaControlProps } from "@wordpress/components/build-types/textarea-control/types";
5
+ import type { ToggleControlProps } from "@wordpress/components/build-types/toggle-control/types";
6
+ import type { ToggleGroupControlProps } from "@wordpress/components/build-types/toggle-group-control/types";
7
+ import type { PickableOptions } from "../controls/types";
4
8
  import type { SimpleNativeProperty } from "./simple-native-property";
5
9
  type CommonPropertyConfig<T, V> = {
6
10
  name: string;
@@ -8,6 +12,7 @@ type CommonPropertyConfig<T, V> = {
8
12
  default: T;
9
13
  enum?: T[];
10
14
  component?: V;
15
+ help?: string;
11
16
  };
12
17
  export declare function rangeProperty(config: CommonPropertyConfig<number, RangeControlProps> & {
13
18
  min: number;
@@ -15,6 +20,14 @@ export declare function rangeProperty(config: CommonPropertyConfig<number, Range
15
20
  step?: number;
16
21
  enum?: number[];
17
22
  }): SimpleNativeProperty;
23
+ export declare function toggleProperty(config: CommonPropertyConfig<boolean, ToggleControlProps>): SimpleNativeProperty;
24
+ type ToggleGroupPropertyConfigBase<T extends string | number> = CommonPropertyConfig<T, ToggleGroupControlProps> & {
25
+ options: PickableOptions<T, {
26
+ icon: BlockIcon;
27
+ }>;
28
+ };
29
+ export type ToggleGroupPropertyConfig = ToggleGroupPropertyConfigBase<string> | ToggleGroupPropertyConfigBase<number>;
30
+ export declare function toggleGroupProperty(config: ToggleGroupPropertyConfig): SimpleNativeProperty;
18
31
  export declare function textProperty(config: CommonPropertyConfig<string, TextControlProps>): SimpleNativeProperty;
19
32
  export declare function textareaProperty(config: CommonPropertyConfig<string, TextareaControlProps>): SimpleNativeProperty;
20
33
  export type ImagePropertyData = {
@@ -1,5 +1,5 @@
1
1
  import { MediaUpload, MediaUploadCheck } from "@wordpress/block-editor";
2
- import { Button, Card, CardBody, CardHeader, FocalPointPicker, RangeControl, ResponsiveWrapper, TextareaControl, TextControl, __experimentalHeading as Heading } from "@wordpress/components";
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";
3
3
  import { useSelect } from "@wordpress/data";
4
4
  import { __ } from "@wordpress/i18n";
5
5
  import React from "react";
@@ -10,17 +10,52 @@ export function rangeProperty(config) {
10
10
  enum: config.enum,
11
11
  default: config.default,
12
12
  renderer(value, onChange) {
13
- return React.createElement(RangeControl, Object.assign({ value: value, onChange: onChange, min: config.min, max: config.max, label: config.label, step: config.step }, config.component));
13
+ return React.createElement(RangeControl, Object.assign({ value: value, onChange: onChange, min: config.min, max: config.max, label: config.label, step: config.step, help: config.help }, config.component));
14
14
  }
15
15
  };
16
16
  }
17
+ export function toggleProperty(config) {
18
+ return {
19
+ name: config.name,
20
+ type: 'boolean',
21
+ default: config.default,
22
+ renderer(value, onChange) {
23
+ return React.createElement(ToggleControl, Object.assign({ checked: value, onChange: onChange, label: config.label, help: config.help }, config.component));
24
+ }
25
+ };
26
+ }
27
+ export function toggleGroupProperty(config) {
28
+ const children = config.options.map(([value, label]) => typeof label === 'string'
29
+ ? React.createElement(ToggleGroupControlOption, { key: value, value: value, label: label })
30
+ : React.createElement(ToggleGroupControlOptionIcon, { key: value, value: value, label: label.text, icon: label.icon }));
31
+ if (typeof config.default === 'string') {
32
+ return {
33
+ name: config.name,
34
+ type: 'string',
35
+ default: config.default,
36
+ renderer(value, onChange) {
37
+ return React.createElement(ToggleGroupControl, Object.assign({ value: value, onChange: v => onChange(v === null || v === void 0 ? void 0 : v.toString()), label: config.label, help: config.help }, config.component, { children: children }));
38
+ }
39
+ };
40
+ }
41
+ else {
42
+ return {
43
+ name: config.name,
44
+ type: 'number',
45
+ default: config.default,
46
+ renderer(value, onChange) {
47
+ return React.createElement(ToggleGroupControl, Object.assign({ value: value, label: config.label, help: config.help }, config.component, { onChange: v => onChange(v === undefined || typeof v === 'number' ? v : (v.includes('.') ? parseFloat(v) : parseInt(v))), children: children }));
48
+ }
49
+ };
50
+ }
51
+ }
17
52
  export function textProperty(config) {
18
53
  return {
19
54
  name: config.name,
20
55
  type: 'string',
21
56
  default: config.default,
22
57
  renderer(value, onChange) {
23
- return React.createElement(TextControl, Object.assign({ value: value, onChange: onChange }, config.component));
58
+ return React.createElement(TextControl, Object.assign({ value: value, onChange: onChange, label: config.label, help: config.help }, config.component));
24
59
  }
25
60
  };
26
61
  }
@@ -30,7 +65,7 @@ export function textareaProperty(config) {
30
65
  type: 'string',
31
66
  default: config.default,
32
67
  renderer(value, onChange) {
33
- return React.createElement(TextareaControl, Object.assign({ value: value, onChange: onChange }, config.component));
68
+ return React.createElement(TextareaControl, Object.assign({ value: value, onChange: onChange, label: config.label, help: config.help }, config.component));
34
69
  }
35
70
  };
36
71
  }
@@ -7,19 +7,19 @@ type BaseLayeredBlockStyleLayer = {
7
7
  };
8
8
  type LayeredBlockStyleColorLayer = BaseLayeredBlockStyleLayer & {
9
9
  picker: 'color';
10
- options: PickableOptions<{
10
+ options: PickableOptions<string, {
11
11
  color?: string;
12
12
  }>;
13
13
  };
14
14
  type LayeredBlockStyleToggleLayer = BaseLayeredBlockStyleLayer & {
15
15
  picker?: 'toggle-control';
16
- options: PickableOptions<{
16
+ options: PickableOptions<string, {
17
17
  icon: BlockIcon;
18
18
  }>;
19
19
  };
20
20
  type LayeredBlockStyleSelectOrRadioLayer = BaseLayeredBlockStyleLayer & {
21
21
  picker: 'select' | 'radio';
22
- options: PickableOptions;
22
+ options: PickableOptions<string>;
23
23
  };
24
24
  export type LayeredBlockStyleLayer = LayeredBlockStyleColorLayer | LayeredBlockStyleToggleLayer | LayeredBlockStyleSelectOrRadioLayer;
25
25
  export interface LayeredBlockStylesConfig {
@@ -1,18 +1,19 @@
1
1
  import type { PickableOptions, SimpleBlockControlProps } from "./types";
2
2
  import React, { type ReactElement } from "react";
3
- export declare function PickOneFromToggleGroup<T extends string>(props: SimpleBlockControlProps<T, string> & {
4
- options: PickableOptions<{
3
+ export type PickOneFromToggleGroupProps<T extends string> = SimpleBlockControlProps<T, string | number> & {
4
+ options: PickableOptions<string, {
5
5
  icon: ReactElement;
6
6
  }>;
7
- }): React.JSX.Element;
7
+ };
8
+ export declare function PickOneFromToggleGroup<T extends string>(props: PickOneFromToggleGroupProps<T>): React.JSX.Element;
8
9
  export declare function PickOneFromSelect<T extends string>(props: SimpleBlockControlProps<T, string> & {
9
- options: PickableOptions;
10
+ options: PickableOptions<string>;
10
11
  }): React.JSX.Element;
11
12
  export declare function PickOneFromRadios<T extends string>(props: SimpleBlockControlProps<T, string> & {
12
- options: PickableOptions;
13
+ options: PickableOptions<string>;
13
14
  }): React.JSX.Element;
14
15
  export declare function PickOneFromColors<T extends string>(props: SimpleBlockControlProps<T, string> & {
15
- options: PickableOptions<{
16
+ options: PickableOptions<string, {
16
17
  color?: string | undefined;
17
18
  }>;
18
19
  }): React.JSX.Element;
@@ -7,6 +7,6 @@ export type SpecificValueBlockProps<T extends string, V> = {
7
7
  export type SimpleBlockControlProps<T extends string, V> = SpecificValueBlockProps<T, V> & {
8
8
  label: string;
9
9
  };
10
- export type PickableOptions<T extends object = {}> = Array<[string, string | ({
10
+ export type PickableOptions<V extends string | number, T extends object = {}> = Array<[V, string | ({
11
11
  text: string;
12
12
  } & T)]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plaudit/gutenberg-api-extensions",
3
- "version": "2.3.0",
3
+ "version": "2.5.0",
4
4
  "scripts": {
5
5
  "prepublishOnly": "rm -rf build && mkdir build && tsc",
6
6
  "build": "tsc",