@plaudit/gutenberg-api-extensions 2.9.0 → 2.11.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 +59 -16
- 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/simple-block.d.ts +22 -0
- package/build/blocks/simple-native-property.d.ts +30 -0
- package/build/blocks/simple-native-property.js +122 -86
- package/build/blocks/simple-native-property.js.map +1 -1
- package/build/controls/AsynchronousFormTokenField.d.ts +20 -0
- package/build/controls/ExtendedPostPicker.d.ts +13 -0
- package/build/controls/InspectorPanel.d.ts +6 -0
- package/build/controls/LazySuggestionsComboboxControl.d.ts +7 -0
- package/build/controls/PickOne.d.ts +19 -0
- package/build/controls/SimpleToggle.d.ts +3 -0
- package/build/controls/SortableItemsControl.d.ts +11 -0
- package/build/controls/SortableItemsControl.js +142 -31
- package/build/controls/SortableItemsControl.js.map +1 -1
- package/build/controls/shared.d.ts +8 -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-2.d.ts +2 -0
- package/build/lib/plaudit-icons/column-3.d.ts +2 -0
- package/build/lib/plaudit-icons/placement-center.d.ts +2 -0
- package/build/lib/plaudit-icons/placement-end.d.ts +2 -0
- package/build/lib/plaudit-icons/placement-start.d.ts +2 -0
- package/build/lib/plaudit-icons/placement-stretch.d.ts +2 -0
- package/build/lib/plaudit-icons/plaudit-icon.d.ts +2 -0
- package/build/lib/plaudit-icons/reusable-block-marker.d.ts +2 -0
- package/{src/lib/plaudit-icons.ts → build/lib/plaudit-icons.d.ts} +0 -4
- package/package.json +5 -5
- package/src/blocks/common-native-property-implementations.tsx +0 -361
- 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 -204
- package/src/controls/AsynchronousFormTokenField.tsx +0 -158
- package/src/controls/ExtendedPostPicker.tsx +0 -50
- package/src/controls/InspectorPanel.tsx +0 -16
- package/src/controls/LazySuggestionsComboboxControl.tsx +0 -84
- package/src/controls/PickOne.tsx +0 -80
- package/src/controls/SimpleToggle.tsx +0 -9
- package/src/controls/SortableItemsControl.tsx +0 -70
- package/src/controls/shared.ts +0 -7
- 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/controls/index.ts → build/controls/index.d.ts} +0 -0
- /package/{src/index.ts → build/index.d.ts} +0 -0
|
@@ -28,37 +28,47 @@ export function installSimpleNativePropertiesSupport() {
|
|
|
28
28
|
}
|
|
29
29
|
window.plauditSimpleNativePropertiesSupportInstalled = true;
|
|
30
30
|
const simpleNativePanels = window.plauditSimpleNativePanels ?? (window.plauditSimpleNativePanels = {});
|
|
31
|
+
function attachSNP(property, injectableProperties) {
|
|
32
|
+
const attrPath = property.name.split('.');
|
|
33
|
+
if (attrPath.length === 1) {
|
|
34
|
+
injectableProperties[property.name] = { type: property.type, default: property.alwaysStore ? undefined : property.default };
|
|
35
|
+
if ('enum' in property) {
|
|
36
|
+
injectableProperties[property.name].enum = property.enum;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
let actualProp = injectableProperties[attrPath[0]];
|
|
41
|
+
if (actualProp === undefined) {
|
|
42
|
+
injectableProperties[attrPath[0]] = actualProp = { type: "object" };
|
|
43
|
+
}
|
|
44
|
+
else if (actualProp.type !== "object") {
|
|
45
|
+
throw new Error(`Property type collision on ${property.name}. Attempted treat the property as an object when it was already a ${actualProp.type}`);
|
|
46
|
+
}
|
|
47
|
+
if (property.default !== undefined) {
|
|
48
|
+
if (actualProp.default === undefined) {
|
|
49
|
+
actualProp.default = {};
|
|
50
|
+
}
|
|
51
|
+
let target = actualProp.default;
|
|
52
|
+
for (let i = 1; i < attrPath.length - 1; i++) {
|
|
53
|
+
target = target[attrPath[i]] = {};
|
|
54
|
+
}
|
|
55
|
+
target[attrPath[attrPath.length - 1]] = property.default;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
31
59
|
addFilter('blocks.registerBlockType', 'plaudit/gutenberg-api-extensions/attach-simple-native-properties', (atts) => {
|
|
32
60
|
const blockSimpleNativePanels = simpleNativePanels[atts.name];
|
|
33
61
|
if (blockSimpleNativePanels) {
|
|
34
62
|
const injectableProperties = {};
|
|
35
63
|
for (const blockSimpleNativePanel of blockSimpleNativePanels) {
|
|
36
64
|
for (const property of blockSimpleNativePanel.properties) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if ('enum' in property) {
|
|
41
|
-
injectableProperties[property.name].enum = property.enum;
|
|
65
|
+
if (Array.isArray(property)) {
|
|
66
|
+
for (const prop of property) {
|
|
67
|
+
attachSNP(prop, injectableProperties);
|
|
42
68
|
}
|
|
43
69
|
}
|
|
44
70
|
else {
|
|
45
|
-
|
|
46
|
-
if (actualProp === undefined) {
|
|
47
|
-
injectableProperties[attrPath[0]] = actualProp = { type: "object" };
|
|
48
|
-
}
|
|
49
|
-
else if (actualProp.type !== "object") {
|
|
50
|
-
throw new Error(`Property type collision on ${property.name}. Attempted treat the property as an object when it was already a ${actualProp.type}`);
|
|
51
|
-
}
|
|
52
|
-
if (property.default !== undefined) {
|
|
53
|
-
if (actualProp.default === undefined) {
|
|
54
|
-
actualProp.default = {};
|
|
55
|
-
}
|
|
56
|
-
let target = actualProp.default;
|
|
57
|
-
for (let i = 1; i < attrPath.length - 1; i++) {
|
|
58
|
-
target = target[attrPath[i]] = {};
|
|
59
|
-
}
|
|
60
|
-
target[attrPath[attrPath.length - 1]] = property.default;
|
|
61
|
-
}
|
|
71
|
+
attachSNP(property, injectableProperties);
|
|
62
72
|
}
|
|
63
73
|
}
|
|
64
74
|
}
|
|
@@ -82,6 +92,77 @@ export function installSimpleNativePropertiesSupport() {
|
|
|
82
92
|
currentLayer[attrPath[attrPath.length - 1]] = value;
|
|
83
93
|
blockEditProps.setAttributes({ [attrPath[0]]: payload });
|
|
84
94
|
}
|
|
95
|
+
function getExistingValue(blockEditProps, prop) {
|
|
96
|
+
const propPath = prop.name.split('.');
|
|
97
|
+
if (propPath.length === 1) {
|
|
98
|
+
let existingValue = blockEditProps.attributes[prop.name];
|
|
99
|
+
if (existingValue === undefined && prop.default !== undefined) {
|
|
100
|
+
existingValue = prop.default;
|
|
101
|
+
blockEditProps.setAttributes({ [prop.name]: prop.default });
|
|
102
|
+
}
|
|
103
|
+
return existingValue;
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
let graphExistingValue = blockEditProps.attributes[propPath[0]];
|
|
107
|
+
if (graphExistingValue === undefined) {
|
|
108
|
+
blockEditProps.attributes[propPath[0]] = graphExistingValue = {};
|
|
109
|
+
}
|
|
110
|
+
for (let i = 1; i < propPath.length; i++) {
|
|
111
|
+
if (graphExistingValue[propPath[i]] === undefined) {
|
|
112
|
+
for (; i < propPath.length - 1; i++) {
|
|
113
|
+
graphExistingValue = graphExistingValue[propPath[i]] = {};
|
|
114
|
+
}
|
|
115
|
+
graphExistingValue[propPath[propPath.length - 1]] = prop.default;
|
|
116
|
+
if (prop.default !== undefined) {
|
|
117
|
+
blockEditProps.setAttributes({ [propPath[0]]: blockEditProps.attributes[propPath[0]] });
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
graphExistingValue = graphExistingValue[propPath[i]];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return graphExistingValue ?? prop.default;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function renderPropertyComponent(blockEditProps, prop) {
|
|
129
|
+
if (Array.isArray(prop)) {
|
|
130
|
+
return React.createElement(React.Fragment, null, ...prop.map(p => renderPropertyComponent(blockEditProps, p)));
|
|
131
|
+
}
|
|
132
|
+
let existingValue = getExistingValue(blockEditProps, prop);
|
|
133
|
+
let ele;
|
|
134
|
+
if (prop.type === "array") { // If the value is not an array or is a sparse array, then it will cause unrecoverable errors upon conversion to PHP
|
|
135
|
+
if (existingValue !== undefined && (!Array.isArray(existingValue) || existingValue.length > existingValue.filter(() => true).length)) {
|
|
136
|
+
throw new Error(`Invalid value passed to an array-type property: ${existingValue}`);
|
|
137
|
+
}
|
|
138
|
+
ele = prop.renderer(existingValue, value => setDottedAttribute(blockEditProps, prop.name, value));
|
|
139
|
+
}
|
|
140
|
+
else if (prop.type === "object") {
|
|
141
|
+
if (existingValue !== undefined && (Array.isArray(existingValue) || typeof existingValue !== 'object')) {
|
|
142
|
+
throw new Error(`Invalid value passed to an object-type property: ${existingValue}`);
|
|
143
|
+
}
|
|
144
|
+
ele = prop.renderer(existingValue, value => setDottedAttribute(blockEditProps, prop.name, value));
|
|
145
|
+
}
|
|
146
|
+
else if (prop.type === "boolean") {
|
|
147
|
+
if (typeof existingValue !== 'boolean' && existingValue !== undefined) {
|
|
148
|
+
existingValue = !!existingValue;
|
|
149
|
+
}
|
|
150
|
+
ele = prop.renderer(existingValue, value => setDottedAttribute(blockEditProps, prop.name, value));
|
|
151
|
+
}
|
|
152
|
+
else if (prop.type === "string") {
|
|
153
|
+
if (typeof existingValue !== 'string' && existingValue !== undefined) {
|
|
154
|
+
existingValue = existingValue.toString();
|
|
155
|
+
}
|
|
156
|
+
ele = prop.renderer(existingValue, value => setDottedAttribute(blockEditProps, prop.name, value));
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
if (typeof existingValue !== 'number' && existingValue !== undefined) {
|
|
160
|
+
existingValue = parseFloat(existingValue);
|
|
161
|
+
}
|
|
162
|
+
ele = prop.renderer(existingValue, value => setDottedAttribute(blockEditProps, prop.name, value));
|
|
163
|
+
}
|
|
164
|
+
return prop.condition === undefined || prop.condition(blockEditProps) ? ele : undefined;
|
|
165
|
+
}
|
|
85
166
|
addFilter('editor.BlockEdit', 'plaudit/gutenberg-api-extensions/simple-native-properties', createHigherOrderComponent(BlockEdit => (blockEditProps) => {
|
|
86
167
|
const blockSimpleNativePanels = simpleNativePanels[blockEditProps.name];
|
|
87
168
|
if (!blockSimpleNativePanels) {
|
|
@@ -91,75 +172,30 @@ export function installSimpleNativePropertiesSupport() {
|
|
|
91
172
|
return React.createElement(React.Fragment, null,
|
|
92
173
|
React.createElement(BlockEdit, { ...blockEditProps }),
|
|
93
174
|
...blockSimpleNativePanels.map(p => {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
175
|
+
const cellsPerRow = p.properties.map(prop => Array.isArray(prop) ? prop.length : 1)
|
|
176
|
+
.reduce((a, b) => b > a || a % b !== 0 ? a * b : a);
|
|
177
|
+
let grid = "";
|
|
178
|
+
let row = 0;
|
|
179
|
+
for (const prop of p.properties) {
|
|
180
|
+
row++;
|
|
181
|
+
let gridRow = "";
|
|
182
|
+
if (Array.isArray(prop)) {
|
|
183
|
+
if (prop.length === 0) {
|
|
184
|
+
continue;
|
|
104
185
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
if (graphExistingValue === undefined) {
|
|
108
|
-
blockEditProps.attributes[propPath[0]] = graphExistingValue = {};
|
|
109
|
-
}
|
|
110
|
-
for (let i = 1; i < propPath.length; i++) {
|
|
111
|
-
if (graphExistingValue[propPath[i]] === undefined) {
|
|
112
|
-
for (; i < propPath.length - 1; i++) {
|
|
113
|
-
graphExistingValue = graphExistingValue[propPath[i]] = {};
|
|
114
|
-
}
|
|
115
|
-
graphExistingValue[propPath[propPath.length - 1]] = existingValue = prop.default;
|
|
116
|
-
blockEditProps.setAttributes({ [propPath[0]]: blockEditProps.attributes[propPath[0]] });
|
|
117
|
-
break;
|
|
118
|
-
}
|
|
119
|
-
else {
|
|
120
|
-
graphExistingValue = graphExistingValue[propPath[i]];
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
existingValue = graphExistingValue ?? prop.default;
|
|
186
|
+
for (let i = 0; i < prop.length; i++) {
|
|
187
|
+
gridRow += ` R${row}C${i}`.repeat(cellsPerRow / prop.length);
|
|
124
188
|
}
|
|
125
189
|
}
|
|
126
190
|
else {
|
|
127
|
-
|
|
191
|
+
gridRow += ` R${row}C1`.repeat(cellsPerRow);
|
|
128
192
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
else if (prop.type === "object") {
|
|
137
|
-
if (existingValue !== undefined && (Array.isArray(existingValue) || typeof existingValue !== 'object')) {
|
|
138
|
-
throw new Error(`Invalid value passed to an object-type property: ${existingValue}`);
|
|
139
|
-
}
|
|
140
|
-
ele = prop.renderer(existingValue, value => setDottedAttribute(blockEditProps, prop.name, value));
|
|
141
|
-
}
|
|
142
|
-
else if (prop.type === "boolean") {
|
|
143
|
-
if (typeof existingValue !== 'boolean' && existingValue !== undefined) {
|
|
144
|
-
existingValue = !!existingValue;
|
|
145
|
-
}
|
|
146
|
-
ele = prop.renderer(existingValue, value => setDottedAttribute(blockEditProps, prop.name, value));
|
|
147
|
-
}
|
|
148
|
-
else if (prop.type === "string") {
|
|
149
|
-
if (typeof existingValue !== 'string' && existingValue !== undefined) {
|
|
150
|
-
existingValue = existingValue.toString();
|
|
151
|
-
}
|
|
152
|
-
ele = prop.renderer(existingValue, value => setDottedAttribute(blockEditProps, prop.name, value));
|
|
153
|
-
}
|
|
154
|
-
else {
|
|
155
|
-
if (typeof existingValue !== 'number' && existingValue !== undefined) {
|
|
156
|
-
existingValue = parseFloat(existingValue);
|
|
157
|
-
}
|
|
158
|
-
ele = prop.renderer(existingValue, value => setDottedAttribute(blockEditProps, prop.name, value));
|
|
159
|
-
}
|
|
160
|
-
return prop.condition === undefined || prop.condition(blockEditProps) ? ele : undefined;
|
|
161
|
-
}).filter((ele) => ele !== undefined);
|
|
162
|
-
return React.createElement(InspectorPanel, { ...p, condition: () => items.length > 0 && (p.condition === undefined || p.condition(blockEditProps)), key: `plaudit-simple-native-property-${keyIndex++}` }, ...items);
|
|
193
|
+
grid += ` "${gridRow.substring(1)}"`;
|
|
194
|
+
}
|
|
195
|
+
const items = p.properties.map(prop => renderPropertyComponent(blockEditProps, prop))
|
|
196
|
+
.filter((ele) => ele !== undefined);
|
|
197
|
+
return React.createElement(InspectorPanel, { ...p, condition: () => items.length > 0 && (p.condition === undefined || p.condition(blockEditProps)), key: `plaudit-simple-native-property-${keyIndex++}` },
|
|
198
|
+
React.createElement("div", { style: { display: "grid", gridTemplateAreas: grid.substring(1), columnGap: "8px" } }, ...items));
|
|
163
199
|
}));
|
|
164
200
|
}, 'plauditGutenbergApiExtensionsSimpleNativeProperties'));
|
|
165
201
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-native-property.js","sourceRoot":"","sources":["../../src/blocks/simple-native-property.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,0BAA0B,EAAC,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAG3C,OAAO,EAAC,cAAc,EAAC,MAAM,aAAa,CAAC;AAE3C,OAAO,
|
|
1
|
+
{"version":3,"file":"simple-native-property.js","sourceRoot":"","sources":["../../src/blocks/simple-native-property.tsx"],"names":[],"mappings":"AAA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from "react";
|
|
3
|
+
export declare const enum ValidationState {
|
|
4
|
+
Valid = "success",
|
|
5
|
+
Invalid = "error",
|
|
6
|
+
Validating = "validating"
|
|
7
|
+
}
|
|
8
|
+
export interface AsynchronousFormTokenFieldProps {
|
|
9
|
+
label: string;
|
|
10
|
+
help?: string;
|
|
11
|
+
value?: string[];
|
|
12
|
+
onChange: (value: string[]) => void;
|
|
13
|
+
validationQuery(tokens: string[]): Promise<Array<TokenItem>>;
|
|
14
|
+
suggestionQuery(input: string): Promise<Array<string>>;
|
|
15
|
+
makeTokenFromSuggestion(suggestion: string): TokenItem;
|
|
16
|
+
validValues: Map<string, ValidationState>;
|
|
17
|
+
validator?: (value: string) => boolean;
|
|
18
|
+
multiple?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function AsynchronousFormTokenField(props: AsynchronousFormTokenFieldProps): React.JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
type ExtendedPostPickerProps = {
|
|
3
|
+
onChange: (value: string[]) => void;
|
|
4
|
+
label: string;
|
|
5
|
+
help?: string;
|
|
6
|
+
postTypes: string[];
|
|
7
|
+
placeholder: string;
|
|
8
|
+
value?: string[];
|
|
9
|
+
multiple?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type ExtendedPostPickerConstructorProps = Partial<Omit<ExtendedPostPickerProps, 'onChange' | 'value' | 'label'>> & Pick<ExtendedPostPickerProps, 'onChange' | 'value' | 'label'>;
|
|
12
|
+
export declare function ExtendedPostPicker(props: ExtendedPostPickerConstructorProps): React.JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ComboboxControlOption, ComboboxControlProps } from "@wordpress/components/build-types/combobox-control/types";
|
|
2
|
+
import React from "react";
|
|
3
|
+
export type LazySuggestionsComboboxControlProps = Omit<ComboboxControlProps, 'options'> & {
|
|
4
|
+
getOption(value?: string): Promise<ComboboxControlOption | undefined>;
|
|
5
|
+
getSuggestions(filterValue: string): Promise<ComboboxControlOption[]>;
|
|
6
|
+
};
|
|
7
|
+
export declare function LazySuggestionsComboboxControl(props: LazySuggestionsComboboxControlProps): React.JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PickableOptions, SimpleBlockControlProps } from "./types";
|
|
2
|
+
import React, { type ReactElement } from "react";
|
|
3
|
+
export type PickOneFromToggleGroupProps<T extends string> = SimpleBlockControlProps<T, string | number> & {
|
|
4
|
+
options: PickableOptions<string, {
|
|
5
|
+
icon: ReactElement;
|
|
6
|
+
}>;
|
|
7
|
+
};
|
|
8
|
+
export declare function PickOneFromToggleGroup<T extends string>(props: PickOneFromToggleGroupProps<T>): React.JSX.Element;
|
|
9
|
+
export declare function PickOneFromSelect<T extends string>(props: SimpleBlockControlProps<T, string> & {
|
|
10
|
+
options: PickableOptions<string>;
|
|
11
|
+
}): React.JSX.Element;
|
|
12
|
+
export declare function PickOneFromRadios<T extends string>(props: SimpleBlockControlProps<T, string> & {
|
|
13
|
+
options: PickableOptions<string>;
|
|
14
|
+
}): React.JSX.Element;
|
|
15
|
+
export declare function PickOneFromColors<T extends string>(props: SimpleBlockControlProps<T, string> & {
|
|
16
|
+
options: PickableOptions<string, {
|
|
17
|
+
color?: string | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BaseControlProps } from "@wordpress/components/build-types/base-control/types";
|
|
2
|
+
import React, { type ReactNode } from "react";
|
|
3
|
+
export type SortableItemsControlProps<D> = Omit<BaseControlProps, 'children'> & {
|
|
4
|
+
value: D[] | undefined;
|
|
5
|
+
onChange: (value: D[]) => void;
|
|
6
|
+
children: (datum: D, onDatumChange: (datum: D) => void) => ReactNode;
|
|
7
|
+
emptyValue: D;
|
|
8
|
+
min?: number;
|
|
9
|
+
max?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare function SortableItemsControl<D>({ value: propValue, onChange, children: makeChild, emptyValue, min, max, id, ...baseControlProps }: SortableItemsControlProps<D>): React.JSX.Element;
|
|
@@ -1,43 +1,154 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseControl, Button, Icon } from "@wordpress/components";
|
|
2
|
+
import { useEffect, useId, useRef, useState } from "@wordpress/element";
|
|
2
3
|
import React from "react";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
export function SortableItemsControl({ value: propValue, onChange, children: makeChild, emptyValue, min, max, id, ...baseControlProps }) {
|
|
5
|
+
if (!window.plauditGutenbergApiExtensionSortableItemsControlCSSLoaded) {
|
|
6
|
+
const styles = document.createElement("style");
|
|
7
|
+
//TODO: Add CSS for the drop handler stuff here
|
|
8
|
+
styles.appendChild(document.createTextNode(`
|
|
9
|
+
.plaudit-sortable-items-container .drop-zone {
|
|
10
|
+
background-color: #ccc;
|
|
11
|
+
transition-property: height, padding;
|
|
12
|
+
transition-duration: 250ms;
|
|
13
|
+
transition-timing-function: cubic-bezier(0.075, 0.82, 0.165, 1);
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
height: 20px;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.plaudit-sortable-items-container .drop-zone.plaudit-sortable-items-hidden {
|
|
19
|
+
height: 0;
|
|
20
|
+
padding: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.plaudit-sortable-items-container .dragging {
|
|
24
|
+
display: none !important;
|
|
25
|
+
}
|
|
26
|
+
.plaudit-sortable-items-container .floating {
|
|
27
|
+
position: fixed;
|
|
28
|
+
box-shadow: 5px 5px 10px rgba(0,0,0,0.5);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.plaudit-sortable-items-container .plaudit-sortable-items-row {
|
|
32
|
+
display: grid;
|
|
33
|
+
grid-template-areas: "HANDLE FIELD CONTROL";
|
|
34
|
+
grid-template-columns: auto 1fr auto;
|
|
35
|
+
border: 1px solid #ccc;
|
|
36
|
+
padding-block-start: 8px;
|
|
37
|
+
}
|
|
38
|
+
.plaudit-sortable-items-container .plaudit-sortable-items-drag-handle {
|
|
39
|
+
padding: 0 6px;
|
|
40
|
+
display: grid;
|
|
41
|
+
place-content: center;
|
|
42
|
+
line-height: 1;
|
|
43
|
+
margin-bottom: 8px;
|
|
44
|
+
}
|
|
45
|
+
.plaudit-sortable-items-container .plaudit-sortable-items-controls {
|
|
46
|
+
margin-top: -4px;
|
|
47
|
+
}
|
|
48
|
+
`));
|
|
49
|
+
document.head.appendChild(styles);
|
|
50
|
+
window.plauditGutenbergApiExtensionSortableItemsControlCSSLoaded = true;
|
|
51
|
+
}
|
|
52
|
+
const controlId = id ?? useId();
|
|
6
53
|
const containerRef = useRef(null);
|
|
54
|
+
const [value, setValue] = useState(propValue ?? []);
|
|
55
|
+
const [dragging, setDragging] = useState(null);
|
|
56
|
+
const [dropZone, setDropZone] = useState(null);
|
|
57
|
+
const [mouse, setMouse] = useState([0, 0]);
|
|
7
58
|
useEffect(() => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
59
|
+
if (dragging !== null) {
|
|
60
|
+
const handler = (event) => setMouse([event.x, event.y]);
|
|
61
|
+
document.addEventListener('mousemove', handler);
|
|
62
|
+
return () => document.removeEventListener('mousemove', handler);
|
|
63
|
+
}
|
|
64
|
+
return () => { };
|
|
65
|
+
}, [dragging]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (dragging !== null && containerRef.current) {
|
|
68
|
+
const result = Array.from(containerRef.current.querySelectorAll(".drop-zone"))
|
|
69
|
+
.map(e => [parseInt(e.getAttribute("data-position")), Math.abs(e.getBoundingClientRect().y - mouse[1]), e])
|
|
70
|
+
.reduce((a, b) => {
|
|
71
|
+
if (a[2].classList.contains("dragging")) {
|
|
72
|
+
return b;
|
|
73
|
+
}
|
|
74
|
+
else if (b[2].classList.contains("dragging")) {
|
|
75
|
+
return a;
|
|
76
|
+
}
|
|
77
|
+
else if (b[1] < a[1]) {
|
|
78
|
+
return b;
|
|
79
|
+
}
|
|
80
|
+
return a;
|
|
81
|
+
})[0];
|
|
82
|
+
setDropZone(result);
|
|
83
|
+
}
|
|
84
|
+
}, [dragging, mouse]);
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (dragging === null) {
|
|
87
|
+
return () => { };
|
|
88
|
+
}
|
|
89
|
+
const handler = (e) => {
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
onDragEnd(dragging);
|
|
92
|
+
};
|
|
93
|
+
document.addEventListener('mouseup', handler);
|
|
94
|
+
return () => document.removeEventListener('mouseup', handler);
|
|
95
|
+
}, [dragging, dropZone]);
|
|
11
96
|
const onChangeByIndex = (datum, index) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
97
|
+
const newValue = [...value];
|
|
98
|
+
newValue[index] = datum;
|
|
99
|
+
onChange(newValue);
|
|
100
|
+
setValue(newValue);
|
|
15
101
|
};
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
102
|
+
const removeByIndex = (index) => {
|
|
103
|
+
const newValue = value.filter((_, i) => i !== index);
|
|
104
|
+
onChange(newValue);
|
|
105
|
+
setValue(newValue);
|
|
20
106
|
};
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
107
|
+
const onDragEnd = (oldIndex) => {
|
|
108
|
+
if (dropZone !== null) {
|
|
109
|
+
transferByIndex(oldIndex, dropZone);
|
|
110
|
+
}
|
|
111
|
+
setDragging(null);
|
|
112
|
+
setDropZone(null);
|
|
25
113
|
};
|
|
26
|
-
|
|
27
|
-
|
|
114
|
+
const transferByIndex = (oldIndex, newIndex) => {
|
|
115
|
+
if (newIndex !== oldIndex) {
|
|
116
|
+
const newValue = [...value];
|
|
117
|
+
if (newIndex > oldIndex) {
|
|
118
|
+
newValue.splice(newIndex, 0, value[oldIndex]);
|
|
119
|
+
newValue.splice(oldIndex, 1);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
newValue.splice(newIndex, 0, ...newValue.splice(oldIndex, 1));
|
|
123
|
+
}
|
|
124
|
+
onChange(newValue);
|
|
125
|
+
setValue(newValue);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const removeDisabled = min !== undefined && value.length <= min;
|
|
129
|
+
return React.createElement(BaseControl, { ...baseControlProps, id: controlId },
|
|
130
|
+
React.createElement("div", { className: "plaudit-sortable-items-container", ref: containerRef },
|
|
131
|
+
...value.map((datum, index) => React.createElement(React.Fragment, null,
|
|
132
|
+
React.createElement(SortableItemsDropZone, { position: index, dragging: dragging, dropZone: dropZone }),
|
|
133
|
+
React.createElement("div", { className: `plaudit-sortable-items-row${dragging === index ? " floating" : ""}`, "data-index": index, style: dragging === index ? { top: `${mouse[1]}px`, left: `${mouse[0]}px` } : {} },
|
|
134
|
+
React.createElement("div", { className: "plaudit-sortable-items-drag-handle", onMouseDown: e => {
|
|
135
|
+
e.preventDefault();
|
|
136
|
+
setDragging(index);
|
|
137
|
+
setMouse([e.nativeEvent.x, e.nativeEvent.y]);
|
|
138
|
+
} },
|
|
139
|
+
React.createElement(Icon, { icon: "move" })),
|
|
140
|
+
React.createElement("div", null, makeChild(datum, datum => onChangeByIndex(datum, index))),
|
|
141
|
+
React.createElement("div", { className: "plaudit-sortable-items-controls" },
|
|
142
|
+
React.createElement(Button, { icon: "remove", disabled: removeDisabled, onClick: () => removeByIndex(index), "aria-label": "Remove" }))))),
|
|
143
|
+
React.createElement(SortableItemsDropZone, { position: value.length, dragging: dragging, dropZone: dropZone })),
|
|
28
144
|
React.createElement("div", null,
|
|
29
|
-
React.createElement(Button, { onClick: () => {
|
|
30
|
-
value
|
|
31
|
-
|
|
145
|
+
React.createElement(Button, { icon: "insert", disabled: max !== undefined && value.length >= max, onClick: () => {
|
|
146
|
+
const newValue = [...value, emptyValue];
|
|
147
|
+
onChange(newValue);
|
|
148
|
+
setValue(newValue);
|
|
32
149
|
} }, "Add Row")));
|
|
33
150
|
}
|
|
34
|
-
function
|
|
35
|
-
return
|
|
36
|
-
}
|
|
37
|
-
function SortableItem(props) {
|
|
38
|
-
return React.createElement("div", { "data-index": props.index },
|
|
39
|
-
React.createElement("div", { className: "plaudit-sortable-items-drag-handler" }, "//TODO: Make this look pretty"),
|
|
40
|
-
React.createElement("div", null, props.children),
|
|
41
|
-
React.createElement("div", null, "//TODO: Add a removal button"));
|
|
151
|
+
function SortableItemsDropZone(props) {
|
|
152
|
+
return React.createElement("div", { "data-position": props.position, className: `drop-zone${props.dragging === null || props.position !== props.dropZone ? " plaudit-sortable-items-hidden" : ""}${props.position - 1 === props.dragging ? " dragging" : ""}` });
|
|
42
153
|
}
|
|
43
154
|
//# sourceMappingURL=SortableItemsControl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortableItemsControl.js","sourceRoot":"","sources":["../../src/controls/SortableItemsControl.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"SortableItemsControl.js","sourceRoot":"","sources":["../../src/controls/SortableItemsControl.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAC,MAAM,uBAAuB,CAAC;AAEhE,OAAO,EAAC,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,oBAAoB,CAAC;AAEtE,OAAO,KAAuB,MAAM,OAAO,CAAC;AAW5C,MAAM,UAAU,oBAAoB,CAAI,EAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,gBAAgB,EAA+B;IACrK,IAAI,CAAE,MAAc,CAAC,yDAAyD,EAAE,CAAC;QAChF,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC/C,+CAA+C;QAC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CAAC,QAAQ,GAAG,CAAC,KAAK,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,EAAE,GACvL,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { BlockEditProps } from "@wordpress/blocks";
|
|
2
|
+
export type SpecificValueBlockProps<T extends string, V> = {
|
|
3
|
+
attribute: T;
|
|
4
|
+
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
|
+
export type PickableOptions<V extends string | number, T extends object = {}> = Array<[V, string | ({
|
|
11
|
+
text: string;
|
|
12
|
+
} & T)]>;
|