@plaudit/gutenberg-api-extensions 2.8.0 → 2.10.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/build/blocks/common-native-property-implementations.d.ts +118 -0
- package/build/blocks/common-native-property-implementations.js +141 -20
- package/build/blocks/common-native-property-implementations.js.map +1 -1
- package/build/blocks/index.d.ts +5 -0
- package/build/blocks/layered-styles.d.ts +31 -0
- package/build/blocks/layered-styles.js +9 -7
- package/build/blocks/layered-styles.js.map +1 -1
- package/build/blocks/simple-block.d.ts +22 -0
- package/build/blocks/simple-block.js +10 -6
- package/build/blocks/simple-block.js.map +1 -1
- package/build/blocks/simple-native-property.d.ts +30 -0
- package/build/blocks/simple-native-property.js +106 -95
- package/build/blocks/simple-native-property.js.map +1 -1
- package/build/controls/AsynchronousFormTokenField.d.ts +20 -0
- package/build/controls/AsynchronousFormTokenField.js +23 -12
- package/build/controls/AsynchronousFormTokenField.js.map +1 -1
- package/build/controls/ExtendedPostPicker.d.ts +13 -0
- package/build/controls/ExtendedPostPicker.js +5 -10
- package/build/controls/ExtendedPostPicker.js.map +1 -1
- package/build/controls/InspectorPanel.d.ts +6 -0
- package/build/controls/InspectorPanel.js +3 -2
- package/build/controls/InspectorPanel.js.map +1 -1
- package/build/controls/LazySuggestionsComboboxControl.d.ts +7 -0
- package/build/controls/LazySuggestionsComboboxControl.js +70 -0
- package/build/controls/LazySuggestionsComboboxControl.js.map +1 -0
- package/build/controls/PickOne.d.ts +19 -0
- package/build/controls/PickOne.js +8 -7
- package/build/controls/PickOne.js.map +1 -1
- package/build/controls/SimpleToggle.d.ts +3 -0
- package/build/controls/SimpleToggle.js +2 -2
- package/build/controls/SimpleToggle.js.map +1 -1
- package/build/controls/SortableItemsControl.d.ts +11 -0
- package/build/controls/SortableItemsControl.js +154 -0
- package/build/controls/SortableItemsControl.js.map +1 -0
- package/{src/controls/index.ts → build/controls/index.d.ts} +1 -0
- package/build/controls/index.js +1 -0
- package/build/controls/index.js.map +1 -1
- package/build/controls/shared.d.ts +8 -0
- package/build/controls/shared.js +7 -0
- package/build/controls/shared.js.map +1 -0
- package/build/controls/types.d.ts +12 -0
- package/build/lib/plaudit-icons/column-1.d.ts +2 -0
- package/build/lib/plaudit-icons/column-1.js +3 -2
- package/build/lib/plaudit-icons/column-1.js.map +1 -1
- package/build/lib/plaudit-icons/column-2.d.ts +2 -0
- package/build/lib/plaudit-icons/column-2.js +3 -2
- package/build/lib/plaudit-icons/column-2.js.map +1 -1
- package/build/lib/plaudit-icons/column-3.d.ts +2 -0
- package/build/lib/plaudit-icons/column-3.js +3 -2
- package/build/lib/plaudit-icons/column-3.js.map +1 -1
- package/build/lib/plaudit-icons/placement-center.d.ts +2 -0
- package/build/lib/plaudit-icons/placement-center.js +3 -2
- package/build/lib/plaudit-icons/placement-center.js.map +1 -1
- package/build/lib/plaudit-icons/placement-end.d.ts +2 -0
- package/build/lib/plaudit-icons/placement-end.js +3 -2
- package/build/lib/plaudit-icons/placement-end.js.map +1 -1
- package/build/lib/plaudit-icons/placement-start.d.ts +2 -0
- package/build/lib/plaudit-icons/placement-start.js +3 -2
- package/build/lib/plaudit-icons/placement-start.js.map +1 -1
- package/build/lib/plaudit-icons/placement-stretch.d.ts +2 -0
- package/build/lib/plaudit-icons/placement-stretch.js +3 -2
- package/build/lib/plaudit-icons/placement-stretch.js.map +1 -1
- package/build/lib/plaudit-icons/plaudit-icon.d.ts +2 -0
- package/build/lib/plaudit-icons/plaudit-icon.js +3 -2
- package/build/lib/plaudit-icons/plaudit-icon.js.map +1 -1
- package/build/lib/plaudit-icons/reusable-block-marker.d.ts +2 -0
- package/build/lib/plaudit-icons/reusable-block-marker.js +3 -2
- package/build/lib/plaudit-icons/reusable-block-marker.js.map +1 -1
- package/{src/lib/plaudit-icons.ts → build/lib/plaudit-icons.d.ts} +0 -4
- package/package.json +14 -14
- package/src/blocks/common-native-property-implementations.tsx +0 -271
- package/src/blocks/index.ts +0 -12
- package/src/blocks/layered-styles.tsx +0 -108
- package/src/blocks/simple-block.tsx +0 -72
- package/src/blocks/simple-native-property.tsx +0 -200
- package/src/controls/AsynchronousFormTokenField.tsx +0 -151
- package/src/controls/ExtendedPostPicker.tsx +0 -50
- package/src/controls/InspectorPanel.tsx +0 -16
- package/src/controls/PickOne.tsx +0 -80
- package/src/controls/SimpleToggle.tsx +0 -9
- package/src/controls/types.ts +0 -11
- package/src/lib/plaudit-icons/column-1.tsx +0 -8
- package/src/lib/plaudit-icons/column-2.tsx +0 -8
- package/src/lib/plaudit-icons/column-3.tsx +0 -8
- package/src/lib/plaudit-icons/placement-center.tsx +0 -5
- package/src/lib/plaudit-icons/placement-end.tsx +0 -5
- package/src/lib/plaudit-icons/placement-start.tsx +0 -5
- package/src/lib/plaudit-icons/placement-stretch.tsx +0 -5
- package/src/lib/plaudit-icons/plaudit-icon.tsx +0 -6
- package/src/lib/plaudit-icons/reusable-block-marker.tsx +0 -5
- /package/{src/index.ts → build/index.d.ts} +0 -0
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import {Spinner, FormTokenField} from '@wordpress/components';
|
|
2
|
-
import type {TokenItem} from "@wordpress/components/build-types/form-token-field/types";
|
|
3
|
-
import {__} from "@wordpress/i18n";
|
|
4
|
-
import {useEffect, useState} from '@wordpress/element';
|
|
5
|
-
import debounce from "debounce";
|
|
6
|
-
|
|
7
|
-
// The strange values correspond to the literals that are expected by TokenItem.status, which allows the assignment code to be cleaner
|
|
8
|
-
export const enum ValidationState {
|
|
9
|
-
Valid = 'success',
|
|
10
|
-
Invalid = 'error',
|
|
11
|
-
Validating = 'validating'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface AsynchronousFormTokenFieldProps {
|
|
15
|
-
label: string;
|
|
16
|
-
value: string[];
|
|
17
|
-
onChange: (value: string[]) => void;
|
|
18
|
-
|
|
19
|
-
validationQuery(tokens: string[]): Promise<Array<TokenItem>>;
|
|
20
|
-
suggestionQuery(input: string): Promise<Array<string>>;
|
|
21
|
-
makeTokenFromSuggestion(suggestion: string): TokenItem;
|
|
22
|
-
validValues: Map<string, ValidationState>;
|
|
23
|
-
validator?: (value: string) => boolean;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function AsynchronousFormTokenField(props: AsynchronousFormTokenFieldProps) {
|
|
27
|
-
const [isInitializing, setIsInitializing] = useState(true);
|
|
28
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
29
|
-
const [isValidating, setIsValidating] = useState(false);
|
|
30
|
-
|
|
31
|
-
const [currentTokens, setCurrentTokens] = useState<Array<TokenItem>>([]);
|
|
32
|
-
const [suggestions, setSuggestions] = useState<Array<string>>([]);
|
|
33
|
-
|
|
34
|
-
const [myValidationRequestQueue] = useState<{queue: Promise<boolean>, currentRequest: number, trigger: (currentTokens: TokenItem[]) => void}>(() => ({
|
|
35
|
-
queue: Promise.resolve(true), currentRequest: 0,
|
|
36
|
-
trigger(currentTokens) {
|
|
37
|
-
const tokensInNeedOfValidation = currentTokens.filter(token => token.status === ValidationState.Validating);
|
|
38
|
-
if (tokensInNeedOfValidation.length > 0) {
|
|
39
|
-
setIsValidating(true);
|
|
40
|
-
const myNumber = ++myValidationRequestQueue.currentRequest;
|
|
41
|
-
myValidationRequestQueue.queue = myValidationRequestQueue.queue.then(async () => {
|
|
42
|
-
const tokensBeingValidatedList = tokensInNeedOfValidation.map(token => token.value).filter(value => !props.validValues.has(value));
|
|
43
|
-
if (tokensBeingValidatedList.length > 0) {
|
|
44
|
-
const tokensBeingValidated = new Set(tokensBeingValidatedList);
|
|
45
|
-
for (const value of tokensBeingValidatedList) {
|
|
46
|
-
props.validValues.set(value, ValidationState.Validating);
|
|
47
|
-
}
|
|
48
|
-
const validatedTokens = await props.validationQuery(tokensBeingValidatedList);
|
|
49
|
-
|
|
50
|
-
for (const validToken of validatedTokens) {
|
|
51
|
-
tokensBeingValidated.delete(validToken.value);
|
|
52
|
-
props.validValues.set(validToken.value, ValidationState.Valid);
|
|
53
|
-
}
|
|
54
|
-
for (const value of tokensBeingValidated) {
|
|
55
|
-
if (props.validValues.get(value) === ValidationState.Validating) {
|
|
56
|
-
props.validValues.set(value, ValidationState.Invalid);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (myNumber === myValidationRequestQueue.currentRequest) {
|
|
62
|
-
let changed = false;
|
|
63
|
-
for (const token of currentTokens) {
|
|
64
|
-
if (token.status === ValidationState.Validating) {
|
|
65
|
-
const status = props.validValues.get(token.value);
|
|
66
|
-
if (status !== undefined && token.status !== status) {
|
|
67
|
-
changed = true;
|
|
68
|
-
token.status = status;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (changed) {
|
|
73
|
-
setCurrentTokens(currentTokens);
|
|
74
|
-
}
|
|
75
|
-
setIsValidating(false);
|
|
76
|
-
}
|
|
77
|
-
return true;
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}));
|
|
82
|
-
|
|
83
|
-
const [mySuggestionRequestQueue] = useState<{
|
|
84
|
-
queue: Promise<boolean>, currentRequest: number, debouncer: (input: string) => void
|
|
85
|
-
}>(() => ({
|
|
86
|
-
queue: Promise.resolve(true),
|
|
87
|
-
currentRequest: 0,
|
|
88
|
-
debouncer: debounce(input => {
|
|
89
|
-
if (input.length < 2) {
|
|
90
|
-
setSuggestions([]);
|
|
91
|
-
} else {
|
|
92
|
-
setIsLoading(true);
|
|
93
|
-
const myNumber = ++mySuggestionRequestQueue.currentRequest;
|
|
94
|
-
mySuggestionRequestQueue.queue = mySuggestionRequestQueue.queue.then(async () => {
|
|
95
|
-
if (myNumber === mySuggestionRequestQueue.currentRequest) {
|
|
96
|
-
setSuggestions(await props.suggestionQuery(input));
|
|
97
|
-
setIsLoading(false);
|
|
98
|
-
}
|
|
99
|
-
return true;
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}, 500)
|
|
103
|
-
}));
|
|
104
|
-
|
|
105
|
-
useEffect(() => {
|
|
106
|
-
props.validationQuery(props.value).then(data => {
|
|
107
|
-
const tokenLabels = new Map<string, string|undefined>();
|
|
108
|
-
for (const rep of data) {
|
|
109
|
-
tokenLabels.set(rep.value, rep.title);
|
|
110
|
-
props.validValues.set(rep.value, ValidationState.Valid);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
for (const value of props.value) {
|
|
114
|
-
if (!props.validValues.has(value)) {
|
|
115
|
-
props.validValues.set(value, ValidationState.Invalid);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
setCurrentTokens(props.value.map(value => ({value, title: tokenLabels.get(value) ?? value, status: props.validValues.get(value)})));
|
|
119
|
-
setIsInitializing(false);
|
|
120
|
-
});
|
|
121
|
-
}, []);
|
|
122
|
-
|
|
123
|
-
useEffect(() => myValidationRequestQueue.trigger(currentTokens), [currentTokens]);
|
|
124
|
-
|
|
125
|
-
if (isInitializing) {
|
|
126
|
-
return <Spinner />;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const tokenTitleMappings = new Map(currentTokens.map(currentToken => [currentToken.value, currentToken.title]));
|
|
130
|
-
|
|
131
|
-
return <>
|
|
132
|
-
<FormTokenField
|
|
133
|
-
value={currentTokens}
|
|
134
|
-
label={props.label}
|
|
135
|
-
placeholder="Start typing to see suggestions"
|
|
136
|
-
suggestions={suggestions}
|
|
137
|
-
onChange={tokens => {
|
|
138
|
-
const tokenItems = tokens.map(token => typeof token === 'string' ? props.makeTokenFromSuggestion(token) : token);
|
|
139
|
-
|
|
140
|
-
props.onChange(tokenItems.map(token => token.value));
|
|
141
|
-
setCurrentTokens(tokenItems);
|
|
142
|
-
}}
|
|
143
|
-
__experimentalValidateInput={props.validator}
|
|
144
|
-
__experimentalAutoSelectFirstMatch={true}
|
|
145
|
-
displayTransform={token => tokenTitleMappings.get(token) ?? token}
|
|
146
|
-
onInputChange={mySuggestionRequestQueue.debouncer}
|
|
147
|
-
/>
|
|
148
|
-
{isLoading && <div><Spinner /><span className="components-form-token-field__help">{__("Updating Suggestions")}</span></div>}
|
|
149
|
-
{isValidating && <div><Spinner /><span className="components-form-token-field__help">{__("Validating")}</span></div>}
|
|
150
|
-
</>;
|
|
151
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import apiFetch from '@wordpress/api-fetch';
|
|
2
|
-
import {AsynchronousFormTokenField, ValidationState} from "./AsynchronousFormTokenField";
|
|
3
|
-
import {useState} from "@wordpress/element";
|
|
4
|
-
import {addQueryArgs} from "@wordpress/url";
|
|
5
|
-
|
|
6
|
-
type ExtendedPostPickerProps = {
|
|
7
|
-
onChange: (value: string[]) => void;
|
|
8
|
-
label: string;
|
|
9
|
-
postTypes: string[];
|
|
10
|
-
placeholder: string;
|
|
11
|
-
value: string[]
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export type ExtendedPostPickerConstructorProps = Partial<Omit<ExtendedPostPickerProps, 'onChange'|'value'|'label'>> & Pick<ExtendedPostPickerProps, 'onChange'|'value'|'label'>;
|
|
15
|
-
|
|
16
|
-
async function makeAPIRequest(data: {search?: string, ids?: string, postTypes?: string}) {
|
|
17
|
-
return (await apiFetch<Array<{ id: number, title: string }>>({path: addQueryArgs("/plaudit/common/v1/post-table-search", data)}))
|
|
18
|
-
.map(item => ({id: item.id.toString(), title: item.title}));
|
|
19
|
-
}
|
|
20
|
-
export function ExtendedPostPicker(props: ExtendedPostPickerConstructorProps) {
|
|
21
|
-
const [validPostIds, _] = useState(new Map<string, ValidationState>());
|
|
22
|
-
const value = props.value ?? [];
|
|
23
|
-
return <AsynchronousFormTokenField
|
|
24
|
-
{...props}
|
|
25
|
-
value={value}
|
|
26
|
-
makeTokenFromSuggestion={token => {
|
|
27
|
-
if (isNumeric(token)) {
|
|
28
|
-
return {value: token, status: validPostIds.get(token) ?? ValidationState.Validating, title: token};
|
|
29
|
-
} else {
|
|
30
|
-
const tokenId = /\(#([0-9]+)\)$/.exec(token)?.[1];
|
|
31
|
-
if (tokenId) {
|
|
32
|
-
return {value: tokenId, status: validPostIds.get(tokenId) ?? ValidationState.Validating, title: token};
|
|
33
|
-
}
|
|
34
|
-
return {value: token, status: ValidationState.Invalid, title: token};
|
|
35
|
-
}
|
|
36
|
-
}}
|
|
37
|
-
suggestionQuery={input => makeAPIRequest({search: input, postTypes: props.postTypes?.join(',')})
|
|
38
|
-
.then(posts => posts.map(post => `${post.title} (#${post.id})`))}
|
|
39
|
-
validationQuery={idsBeingValidated => makeAPIRequest({ids: idsBeingValidated.join(','), postTypes: props.postTypes?.join(',')})
|
|
40
|
-
.then(posts => posts.map(post => ({value: post.id, title: post.title, status: ValidationState.Valid})))}
|
|
41
|
-
validValues={validPostIds}
|
|
42
|
-
validator={token => /\(#([0-9]+)\)$/.exec(token)?.[1] !== undefined}
|
|
43
|
-
/>;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function isNumeric(str: string|number) {
|
|
47
|
-
if (typeof str !== "string") return true; // we only process strings!
|
|
48
|
-
return !isNaN(str as any) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
|
|
49
|
-
!isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
|
|
50
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type {PanelBodyProps} from "@wordpress/components/build-types/panel/types";
|
|
2
|
-
import {InspectorControls} from "@wordpress/block-editor";
|
|
3
|
-
import {PanelBody} from "@wordpress/components";
|
|
4
|
-
|
|
5
|
-
import React from "react";
|
|
6
|
-
|
|
7
|
-
type InspectorControlsType = {
|
|
8
|
-
// WordPress' types don't declare the group parameter, which is what we use to put the InspectorPanel in the correct spot
|
|
9
|
-
(props: InspectorControls.Props & { group?: string }): ReturnType<typeof InspectorControls>;
|
|
10
|
-
} & (typeof InspectorControls);
|
|
11
|
-
export function InspectorPanel(props: PanelBodyProps&{group?: string, condition?(): boolean}) {
|
|
12
|
-
const FullyTypedInspectorControls = InspectorControls as InspectorControlsType;
|
|
13
|
-
return <FullyTypedInspectorControls group={props.group}>
|
|
14
|
-
<PanelBody {...props} children={props.condition === undefined || props.condition() ? props.children : []} />
|
|
15
|
-
</FullyTypedInspectorControls>;
|
|
16
|
-
}
|
package/src/controls/PickOne.tsx
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__experimentalToggleGroupControl as ToggleGroupControl,
|
|
3
|
-
__experimentalToggleGroupControlOption as ToggleGroupControlOption,
|
|
4
|
-
__experimentalToggleGroupControlOptionIcon as ToggleGroupControlOptionIcon, BaseControl,
|
|
5
|
-
ColorPalette, RadioControl, SelectControl, useBaseControlProps
|
|
6
|
-
} from "@wordpress/components";
|
|
7
|
-
import type {ColorObject} from "@wordpress/components/build-types/color-palette/types";
|
|
8
|
-
|
|
9
|
-
import type {PickableOptions, SimpleBlockControlProps} from "./types";
|
|
10
|
-
|
|
11
|
-
import React, {type ReactElement} from "react";
|
|
12
|
-
|
|
13
|
-
function makeSharedRadioAndSelectProps<T extends string>(props: SimpleBlockControlProps<T, string>&{options: PickableOptions<string>}) {
|
|
14
|
-
return {
|
|
15
|
-
label: props.label,
|
|
16
|
-
onChange(value: string) {
|
|
17
|
-
props.setAttributes({[props.attribute]: value});
|
|
18
|
-
},
|
|
19
|
-
options: props.options.map(([value, label]) => ({
|
|
20
|
-
value, label: typeof label === 'string' ? label : label.text
|
|
21
|
-
}))
|
|
22
|
-
} as Pick<Parameters<(typeof SelectControl)|(typeof RadioControl)>[0], 'label'|'options'>&{onChange(value: string): void};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type PickOneFromToggleGroupProps<T extends string> = SimpleBlockControlProps<T, string|number>&{options: PickableOptions<string, {icon: ReactElement}>};
|
|
26
|
-
export function PickOneFromToggleGroup<T extends string>(props: PickOneFromToggleGroupProps<T>) {
|
|
27
|
-
return <ToggleGroupControl
|
|
28
|
-
label={props.label}
|
|
29
|
-
value={props.attributes[props.attribute]}
|
|
30
|
-
onChange={value => props.setAttributes({[props.attribute]: value})}
|
|
31
|
-
children={
|
|
32
|
-
props.options.map(([value, label]) => typeof label === 'string'
|
|
33
|
-
? <ToggleGroupControlOption key={value} value={value} label={label} />
|
|
34
|
-
: <ToggleGroupControlOptionIcon key={value} value={value} label={label.text} icon={label.icon} />)
|
|
35
|
-
}
|
|
36
|
-
/>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function PickOneFromSelect<T extends string>(props: SimpleBlockControlProps<T, string>& { options: PickableOptions<string> }) {
|
|
40
|
-
return <SelectControl
|
|
41
|
-
{...makeSharedRadioAndSelectProps(props)}
|
|
42
|
-
value={props.attributes[props.attribute]}
|
|
43
|
-
/>;
|
|
44
|
-
}
|
|
45
|
-
export function PickOneFromRadios<T extends string>(props: SimpleBlockControlProps<T, string>& { options: PickableOptions<string> }) {
|
|
46
|
-
return <RadioControl
|
|
47
|
-
{...makeSharedRadioAndSelectProps(props)}
|
|
48
|
-
selected={props.attributes[props.attribute]}
|
|
49
|
-
/>;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function PickOneFromColors<T extends string>(props: SimpleBlockControlProps<T, string>&{options: PickableOptions<string, {color?: string|undefined}>}) {
|
|
53
|
-
const valueToColorMap = new Map<string, string>();
|
|
54
|
-
const colorToValueMap = new Map<string, string>();
|
|
55
|
-
const colors: ColorObject[] = [];
|
|
56
|
-
for (const [value, display] of props.options) {
|
|
57
|
-
if (typeof display === 'string') {
|
|
58
|
-
colors.push({color: value, name: display});
|
|
59
|
-
} else if (display.color) {
|
|
60
|
-
valueToColorMap.set(value, display.color);
|
|
61
|
-
colorToValueMap.set(display.color, value);
|
|
62
|
-
colors.push({color: display.color, name: display.text});
|
|
63
|
-
} else {
|
|
64
|
-
colors.push({color: value, name: display.text});
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const currentColor = valueToColorMap.get(props.attributes[props.attribute]) ?? props.attributes[props.attribute];
|
|
69
|
-
const {baseControlProps, controlProps} = useBaseControlProps({label: props.label});
|
|
70
|
-
return <BaseControl {...baseControlProps}>
|
|
71
|
-
<ColorPalette
|
|
72
|
-
{...controlProps}
|
|
73
|
-
disableCustomColors={true}
|
|
74
|
-
onChange={color => props.setAttributes({[props.attribute]: colorToValueMap.get(color ?? currentColor) ?? color ?? currentColor})}
|
|
75
|
-
colors={colors}
|
|
76
|
-
value={currentColor}
|
|
77
|
-
clearable={false}
|
|
78
|
-
/>
|
|
79
|
-
</BaseControl>;
|
|
80
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import {ToggleControl} from "@wordpress/components";
|
|
2
|
-
|
|
3
|
-
import type {SimpleBlockControlProps} from "./types";
|
|
4
|
-
|
|
5
|
-
import React from "react";
|
|
6
|
-
|
|
7
|
-
export function SimpleToggle<T extends string>(props: SimpleBlockControlProps<T, boolean>) {
|
|
8
|
-
return <ToggleControl checked={props.attributes[props.attribute]} label={props.label} onChange={checked => props.setAttributes({[props.attribute]: checked})} />;
|
|
9
|
-
}
|
package/src/controls/types.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type {BlockEditProps} from "@wordpress/blocks";
|
|
2
|
-
|
|
3
|
-
export type SpecificValueBlockProps<T extends string, V> = {
|
|
4
|
-
attribute: T, attributes: BlockEditProps<Record<T, V>&Record<string, unknown>>['attributes'],
|
|
5
|
-
setAttributes: BlockEditProps<any>['setAttributes']
|
|
6
|
-
}
|
|
7
|
-
export type SimpleBlockControlProps<T extends string, V> = SpecificValueBlockProps<T, V>&{
|
|
8
|
-
label: string
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
export type PickableOptions<V extends string|number, T extends object = {}> = Array<[V, string|({text: string}&T)]>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
export const iconColumn2 = <svg width={34} height={24} viewBox="0 0 34 24">
|
|
4
|
-
<path
|
|
5
|
-
d="M32 0c1.1 0 2 .9 2 2v20c0 1.1-.9 2-2 2H2c-1.1 0-2-.9-2-2V2C0 .9.9 0 2 0h30zm0 22V2H18v20h14zm-16 0H2V2h14v20z"
|
|
6
|
-
fillRule="evenodd" clipRule="evenodd"
|
|
7
|
-
/>
|
|
8
|
-
</svg>;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
export const iconColumn3 = <svg width={34} height={24} viewBox="0 0 34 24">
|
|
4
|
-
<path
|
|
5
|
-
d="M34 2c0-1.1-.9-2-2-2H2C.9 0 0 .9 0 2v20c0 1.1.9 2 2 2h30c1.1 0 2-.9 2-2V2zM21.5 22h-9V2h9v20zm2 0V2H32v20h-8.5zm-13 0H2V2h8.5v20z"
|
|
6
|
-
fillRule="evenodd" clipRule="evenodd"
|
|
7
|
-
/>
|
|
8
|
-
</svg>;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
export const placementStretch = <svg version="1.1" x="0px" y="0px" focusable={false} viewBox="0 0 24 24" enableBackground="new 0 0 24 24" xmlSpace="preserve">
|
|
4
|
-
<path d="M8.8,6.5h6v11h-6V6.5z M4,18.5h16V20H4V18.5z M4,4h16v1.5H4V4z" />
|
|
5
|
-
</svg>;
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
export const plauditIcon = <svg width={24} height={24} viewBox="0 0 139 157.6">
|
|
4
|
-
<path fill="#d20000"
|
|
5
|
-
d="M83.3 39.1L101.6 9c2-3.2.9-7.1-2.4-8.5s-6.9.4-7.9 4l-9.7 33.9c-1.1 3.6-.3 4 1.7.7zm-43.9 19L9 40.5c-3.3-1.9-7.1-.7-8.5 2.6s.5 6.8 4.2 7.8l34.1 8.9c3.7 1 4 .2.6-1.7zm16.3-19c2 3.2 2.7 2.9 1.7-.7L47.6 4.5C46.5.8 43-1 39.7.5S35.3 5.8 37.3 9l18.4 30.1zm82.8 4c-1.4-3.3-5.2-4.5-8.5-2.6L99.5 58.1c-3.3 1.9-3 2.7.7 1.7l34.1-8.9c3.7-1 5.6-4.5 4.2-7.8zM88.8 57.7c-10.6-18.3-28-18.3-38.7 0l-38.7 66.6c-10.6 18.3-1.9 33.3 19.3 33.3h77.4c21.3 0 30-15 19.3-33.3L88.8 57.7zm-19.3 1c7.1 0 12.8 5.8 12.7 12.9s-5.8 12.8-12.9 12.7c-7 0-12.7-5.8-12.8-12.8.1-7.1 5.8-12.9 13-12.8zm32 91.2h-64c-17.6 0-24.8-8.1-16-18l32-35.9c8.8-9.9 23.2-9.9 32 0l32 35.9c8.8 9.9 1.6 17.9-16 18z" />
|
|
6
|
-
</svg>;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
|
|
3
|
-
export const reusableBlockMarker = <svg viewBox="0 0 24 24">
|
|
4
|
-
<path d="M21.3 10.8l-5.6-5.6c-.7-.7-1.8-.7-2.5 0l-5.6 5.6c-.7.7-.7 1.8 0 2.5l5.6 5.6c.3.3.8.5 1.2.5s.9-.2 1.2-.5l5.6-5.6c.8-.7.8-1.9.1-2.5zm-1 1.4l-5.6 5.6c-.1.1-.3.1-.4 0l-5.6-5.6c-.1-.1-.1-.3 0-.4l5.6-5.6s.1-.1.2-.1.1 0 .2.1l5.6 5.6c.1.1.1.3 0 .4zm-16.6-.4L10 5.5l-1-1-6.3 6.3c-.7.7-.7 1.8 0 2.5L9 19.5l1.1-1.1-6.3-6.3c-.2 0-.2-.2-.1-.3z" />
|
|
5
|
-
</svg>
|
|
File without changes
|