@plaudit/gutenberg-api-extensions 2.95.0 → 2.97.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.
Files changed (113) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/blocks/basic-custom-block-bindings-support.js +1 -1
  3. package/dist/blocks/basic-custom-block-bindings-support.js.map +1 -1
  4. package/dist/blocks/conditions.js.map +1 -1
  5. package/dist/blocks/problematic-blocks-blocker.js.map +1 -1
  6. package/dist/blocks/simple-block.d.ts +4 -4
  7. package/dist/blocks/simple-block.js +2 -2
  8. package/dist/blocks/simple-block.js.map +1 -1
  9. package/dist/lib/useful-types.d.ts +6 -7
  10. package/package.json +13 -15
  11. package/dist/lib/compat-types.d.ts +0 -34
  12. package/dist/lib/compat-types.js +0 -3
  13. package/dist/lib/compat-types.js.map +0 -1
  14. package/src/blocks/MoveError.ts +0 -7
  15. package/src/blocks/PathError.ts +0 -18
  16. package/src/blocks/SNPFlexibleItemsListComponent.tsx +0 -30
  17. package/src/blocks/SNPGroupComponent.tsx +0 -38
  18. package/src/blocks/SNPListComponent.tsx +0 -25
  19. package/src/blocks/SNPTreeContext.tsx +0 -13
  20. package/src/blocks/basic-custom-block-bindings-support.tsx +0 -248
  21. package/src/blocks/common-native-property-constructors.tsx +0 -927
  22. package/src/blocks/conditions.ts +0 -261
  23. package/src/blocks/csnp-api.ts +0 -221
  24. package/src/blocks/data-controller/actions.ts +0 -20
  25. package/src/blocks/data-controller/reducer.ts +0 -146
  26. package/src/blocks/data-controller/trigger-handlers.ts +0 -150
  27. package/src/blocks/data-controller/utils.ts +0 -415
  28. package/src/blocks/data-controller-manager.ts +0 -50
  29. package/src/blocks/data-controller.ts +0 -165
  30. package/src/blocks/hooks/built-in-suspendable-option-protocols/select.ts +0 -51
  31. package/src/blocks/hooks/built-in-suspendable-option-protocols/settings.ts +0 -70
  32. package/src/blocks/hooks/useSuspendableOptions.ts +0 -122
  33. package/src/blocks/index.ts +0 -23
  34. package/src/blocks/layered-styles-api.ts +0 -142
  35. package/src/blocks/layered-styles-impl.ts +0 -95
  36. package/src/blocks/layout/LaidOutProperty.tsx +0 -72
  37. package/src/blocks/layout/LaidOutPropertyRow.tsx +0 -28
  38. package/src/blocks/layout/NodeContext.tsx +0 -54
  39. package/src/blocks/layout/PanelRoot.tsx +0 -30
  40. package/src/blocks/layout/TabsRoot.tsx +0 -56
  41. package/src/blocks/layout/ToolsPanelContext.tsx +0 -22
  42. package/src/blocks/problematic-blocks-blocker.ts +0 -24
  43. package/src/blocks/problematic-variations-blocker.ts +0 -32
  44. package/src/blocks/shared-exportable-types.ts +0 -6
  45. package/src/blocks/shared-internal-types.ts +0 -18
  46. package/src/blocks/simple-block.tsx +0 -74
  47. package/src/blocks/simple-native-property-api.ts +0 -173
  48. package/src/blocks/simple-native-property-impl.tsx +0 -335
  49. package/src/blocks/simple-native-property-internal-shared.ts +0 -19
  50. package/src/blocks/snp-api.ts +0 -5
  51. package/src/blocks/snp-data-store.ts +0 -72
  52. package/src/blocks/utilities.ts +0 -66
  53. package/src/controls/AsynchronousFormTokenField.tsx +0 -86
  54. package/src/controls/BaseSortableItemsControl.tsx +0 -84
  55. package/src/controls/ExtendedFormTokenField.tsx +0 -144
  56. package/src/controls/ExtendedPostPicker.ts +0 -57
  57. package/src/controls/ExtendedRadioControl.tsx +0 -107
  58. package/src/controls/ExtendedTaxonomyPicker.tsx +0 -100
  59. package/src/controls/ExtendedTermPicker.tsx +0 -61
  60. package/src/controls/ExtendedTextareaControl.tsx +0 -65
  61. package/src/controls/ExtendedUserPicker.ts +0 -56
  62. package/src/controls/FileControl.tsx +0 -48
  63. package/src/controls/FullSizeToggleControl.tsx +0 -95
  64. package/src/controls/ImageControl.tsx +0 -143
  65. package/src/controls/InspectorPanel.tsx +0 -37
  66. package/src/controls/LazySuggestionsComboboxControl.tsx +0 -64
  67. package/src/controls/MultiSelectControl.tsx +0 -59
  68. package/src/controls/PickOne.tsx +0 -88
  69. package/src/controls/PromisableComponent.tsx +0 -56
  70. package/src/controls/ProperLinkControl.tsx +0 -98
  71. package/src/controls/SimpleToggle.tsx +0 -9
  72. package/src/controls/SortableFlexibleItemsControl.tsx +0 -37
  73. package/src/controls/SortableItemsControl.tsx +0 -22
  74. package/src/controls/basicNumericallyIdedItemPicker.tsx +0 -75
  75. package/src/controls/hooks/useImprovedTokenManager.ts +0 -163
  76. package/src/controls/hooks/useMultiSingleConversionLayer.ts +0 -17
  77. package/src/controls/hooks/useNonRenderingCounter.ts +0 -6
  78. package/src/controls/hooks/useOutputMemoizingFilter.ts +0 -16
  79. package/src/controls/hooks/useSortableItemsModel.ts +0 -196
  80. package/src/controls/hooks/useSuggestions.ts +0 -91
  81. package/src/controls/hooks/useTokenManager.ts +0 -177
  82. package/src/controls/index.ts +0 -24
  83. package/src/controls/shared.ts +0 -50
  84. package/src/controls/types.ts +0 -18
  85. package/src/editor/insert-sibling-or-child-block-shortcut.tsx +0 -60
  86. package/src/editor/install-insert-sole-allowed-block-shortcut-support.tsx +0 -51
  87. package/src/editor/simple-gutenberg-endpoints-api.ts +0 -31
  88. package/src/editor/simple-gutenberg-endpoints-impl.ts +0 -126
  89. package/src/index.ts +0 -30
  90. package/src/lib/compat-types.ts +0 -21
  91. package/src/lib/gutenberg-api-extensions-state/custom-block-bindings-support-logic.ts +0 -35
  92. package/src/lib/gutenberg-api-extensions-state/general-logic.ts +0 -41
  93. package/src/lib/gutenberg-api-extensions-state/layered-block-styles-logic.ts +0 -43
  94. package/src/lib/gutenberg-api-extensions-state/snp-logic.ts +0 -240
  95. package/src/lib/gutenberg-api-extensions-state.ts +0 -69
  96. package/src/lib/helpers.ts +0 -115
  97. package/src/lib/modified-fast-deep-equals.ts +0 -91
  98. package/src/lib/plaudit-icons/column-1.tsx +0 -6
  99. package/src/lib/plaudit-icons/column-2.tsx +0 -6
  100. package/src/lib/plaudit-icons/column-3.tsx +0 -6
  101. package/src/lib/plaudit-icons/placement-center.tsx +0 -3
  102. package/src/lib/plaudit-icons/placement-end.tsx +0 -3
  103. package/src/lib/plaudit-icons/placement-start.tsx +0 -3
  104. package/src/lib/plaudit-icons/placement-stretch.tsx +0 -3
  105. package/src/lib/plaudit-icons/plaudit-icon.tsx +0 -4
  106. package/src/lib/plaudit-icons/reusable-block-marker.tsx +0 -3
  107. package/src/lib/plaudit-icons.ts +0 -13
  108. package/src/lib/sectioned-cache-store.ts +0 -120
  109. package/src/lib/suspense/promise-handlers.ts +0 -72
  110. package/src/lib/suspense.tsx +0 -18
  111. package/src/lib/useful-types.ts +0 -82
  112. package/src/schemas/README.md +0 -1
  113. package/src/schemas/plaudit-block-schema.json +0 -818
@@ -1,41 +0,0 @@
1
- import {produce} from "immer";
2
-
3
- import {clone} from "../helpers";
4
- import type {BlockName, RegisterBlockAttrs} from "../useful-types";
5
-
6
- export type GeneralLogicActions = {type: 'RECORD_BASELINE_BLOCK_ATTRS', attrs: RegisterBlockAttrs<Record<string, any>>}|{type: "SET_FEATURE_PROP", feature: string, prop: string, value: any};
7
- export type GeneralLogicState = {
8
- baselineBlockAttrs: {[blockName in BlockName]?: RegisterBlockAttrs<Record<string, any>>},
9
- features: {[name in string]?: {[prop in string]: any}}
10
- };
11
- export function generalLogic(state: GeneralLogicState, action: GeneralLogicActions): typeof state {
12
- if (action.type === "RECORD_BASELINE_BLOCK_ATTRS") {
13
- return produce(state, (draft: typeof state) => {
14
- if (!(action.attrs.name in draft.baselineBlockAttrs)) {
15
- draft.baselineBlockAttrs[action.attrs.name] = clone(action.attrs);
16
- }
17
- });
18
- } else if (action.type === "SET_FEATURE_PROP") {
19
- return produce(state, (draft: typeof state) => {
20
- (draft.features[action.feature] ?? (draft.features[action.feature] = {}))[action.prop] = action.value;
21
- });
22
- }
23
- return state;
24
- }
25
-
26
- export const generalLogicActions = {
27
- recordBaselineBlockAttrs(attrs: RegisterBlockAttrs<Record<string, any>>): GeneralLogicActions {
28
- return {type: "RECORD_BASELINE_BLOCK_ATTRS", attrs};
29
- },
30
- setFeatureProp(feature: string, prop: string, value: any): GeneralLogicActions {
31
- return {type: "SET_FEATURE_PROP", feature, prop, value};
32
- }
33
- };
34
- export const generalLogicSelectors = {
35
- baselineBlockAttrs(state: GeneralLogicState, blockName: BlockName) {
36
- return state.baselineBlockAttrs[blockName];
37
- },
38
- featureProp(state: GeneralLogicState, feature: string, prop: string) {
39
- return state.features[feature]?.[prop];
40
- }
41
- };
@@ -1,43 +0,0 @@
1
- import {produce} from "immer";
2
-
3
- import type {PDSimpleNativeProperty} from "../../blocks";
4
- import type {NamedBlockAction} from "../gutenberg-api-extensions-state";
5
- import type {BlockName, WorkableUnknownAction} from "../useful-types";
6
-
7
- export type LayeredBlockStylesLogicActions =
8
- NamedBlockAction<'ADD_LAYERED_BLOCK_STYLES', {properties: PDSimpleNativeProperty[]}>|
9
- NamedBlockAction<'SET_LAYERED_BLOCK_STYLES', {properties: {[name in string]: PDSimpleNativeProperty}}>;
10
- export type LayeredBlockStylesLogicState = {
11
- layeredBlockStyles: {[blockName in BlockName]?: {[name in string]: PDSimpleNativeProperty}}
12
- };
13
-
14
- export const layeredBlockStylesLogicActions = {
15
- addLayeredBlockStyles(blockName: BlockName, properties: PDSimpleNativeProperty[]) {
16
- return {type: 'ADD_LAYERED_BLOCK_STYLES', blockName, properties};
17
- }
18
- };
19
- export const layeredBlockStylesLogicSelectors = {
20
- blockStylesLayer(state: LayeredBlockStylesLogicState, blockName: BlockName, layerName: string) {
21
- return state.layeredBlockStyles[blockName]?.[layerName];
22
- },
23
- blockStylesLayers(state: LayeredBlockStylesLogicState, blockName: BlockName) {
24
- return state.layeredBlockStyles[blockName];
25
- }
26
- };
27
-
28
- export function layeredBlockStylesLogic(state: LayeredBlockStylesLogicState, action: LayeredBlockStylesLogicActions|WorkableUnknownAction): typeof state {
29
- switch (action.type) {
30
- case "ADD_LAYERED_BLOCK_STYLES":
31
- return produce(state, (draft: typeof state) => {
32
- const blockLayeredStyles = draft.layeredBlockStyles[action.blockName] ?? (draft.layeredBlockStyles[action.blockName] = {});
33
- for (const layer of action.properties) {
34
- blockLayeredStyles[layer.name] = layer;
35
- }
36
- });
37
- case "SET_LAYERED_BLOCK_STYLES":
38
- return produce(state, (draft: typeof state) => {
39
- draft.layeredBlockStyles[action.blockName] = action.properties;
40
- });
41
- }
42
- return state;
43
- }
@@ -1,240 +0,0 @@
1
- import {getBlockType} from "@wordpress/blocks";
2
- import {dispatch} from "@wordpress/data";
3
-
4
- import {produce} from "immer";
5
-
6
- import type {LaidOutProperties, PropertiesParameter, SimpleNativePanel, SimpleNativeTab} from "../../blocks";
7
- import {hydrateSimpleNativeProperty, OutsideHydrationInfo} from "../../blocks/common-native-property-constructors";
8
- import type {
9
- ExtraPropTransformsConfig,
10
- HydratedInspectorPanelGroupedTabs,
11
- HydratedSimpleNativePanel,
12
- HydratedSimpleNativeTabItem, PerBlockExtraPropTransforms,
13
- PreppedSimpleNativePanelsAndTabs
14
- } from "../../blocks/simple-native-property-internal-shared";
15
- import {BareProperties, NamedBlockAction, store} from "../gutenberg-api-extensions-state";
16
- import {BlockName, isBlockJsonNativePropsConfig, RegisterBlockAttrs, WorkableUnknownAction} from "../useful-types";
17
-
18
- export type SNPLogicState = {
19
- desiccatedProperties: {[blockName in BlockName]?: Array<SimpleNativePanel|SimpleNativeTab>},
20
- preppedProperties: {[blockName in BlockName]?: PreppedSimpleNativePanelsAndTabs|false},
21
- extraPropTransforms: {[blockName in BlockName]?: ExtraPropTransformsConfig},
22
- computedExtraPropTransforms: {[blockName in BlockName]?: PerBlockExtraPropTransforms|false},
23
- };
24
-
25
- export type SNPLogicActions = {type: 'ADD_PROPERTIES', blockName: BlockName|BlockName[], properties: BareProperties}|
26
- NamedBlockAction<'SET_PREPPED_PROPERTIES', {properties: PreppedSimpleNativePanelsAndTabs|false}>|
27
- NamedBlockAction<'ADD_OR_UPDATE_EXTRA_PROP_TRANSFORM', {propPath: string, extraPropTransform: ExtraPropTransformsConfig[string]}>|
28
- NamedBlockAction<'SET_EXTRA_PROP_TRANSFORMS', {extraPropTransforms: ExtraPropTransformsConfig}>|
29
- NamedBlockAction<'SET_COMPUTED_EXTRA_PROP_TRANSFORMS', {computedExtraPropTransforms: PerBlockExtraPropTransforms|false|undefined}>;
30
-
31
- export const snpLogicActions = {
32
- addProperties(blockName: BlockName|BlockName[], properties: BareProperties): SNPLogicActions {
33
- return {type: 'ADD_PROPERTIES', blockName, properties};
34
- },
35
- addOrUpdateExtraPropTransform(blockName: BlockName, propPath: string, extraPropTransform: ExtraPropTransformsConfig[string]): SNPLogicActions {
36
- return {type: 'ADD_OR_UPDATE_EXTRA_PROP_TRANSFORM', blockName, propPath, extraPropTransform};
37
- },
38
- setComputedExtraPropTransforms(blockName: BlockName, computedExtraPropTransforms: PerBlockExtraPropTransforms|false): SNPLogicActions {
39
- return {type: 'SET_COMPUTED_EXTRA_PROP_TRANSFORMS', blockName, computedExtraPropTransforms};
40
- },
41
- setPreppedProperties(blockName: BlockName, properties: PreppedSimpleNativePanelsAndTabs|false): SNPLogicActions {
42
- return {type: 'SET_PREPPED_PROPERTIES', blockName, properties};
43
- }
44
- };
45
- export const snpLogicSelectors = {
46
- desiccatedProperties(state: SNPLogicState, blockName: BlockName) {
47
- return state.desiccatedProperties[blockName];
48
- },
49
- preppedProperties(state: SNPLogicState, blockName: BlockName) {
50
- let res = state.preppedProperties[blockName];
51
- if (res === undefined) {
52
- res = prepSimpleNativePanelsAndTabs(blockName, state.desiccatedProperties[blockName]);
53
- dispatch(store).setPreppedProperties(blockName, res);
54
- }
55
- return res;
56
- },
57
- extraPropTransforms(state: SNPLogicState, blockName: BlockName) {
58
- return state.extraPropTransforms[blockName];
59
- },
60
- computedExtraPropTransforms(state: SNPLogicState, blockName: BlockName) {
61
- let res = state.computedExtraPropTransforms[blockName];
62
- if (res === undefined) {
63
- res = computeExtraPropTransforms(getBlockType(blockName) as RegisterBlockAttrs, state.extraPropTransforms[blockName]);
64
- dispatch(store).setComputedExtraPropTransforms(blockName, res);
65
- }
66
- return res;
67
- }
68
- };
69
-
70
- export function snpLogic(state: SNPLogicState, action: SNPLogicActions|WorkableUnknownAction) {
71
- switch (action.type) {
72
- case "ADD_PROPERTIES":
73
- return produce(state, (draft: typeof state) => {
74
- for (const bn of Array.isArray(action.blockName) ? action.blockName : [action.blockName]) {
75
- addProperties(bn, action.properties, draft.desiccatedProperties);
76
- draft.preppedProperties[bn] = undefined;
77
- draft.extraPropTransforms[bn] = undefined;
78
- draft.computedExtraPropTransforms[bn] = undefined;
79
- }
80
- });
81
- case "ADD_OR_UPDATE_EXTRA_PROP_TRANSFORM":
82
- return produce(state, (draft: typeof state) => {
83
- const blockTransforms = (draft.extraPropTransforms[action.blockName] ??= {});
84
- if (blockTransforms[action.propPath]) {
85
- blockTransforms[action.propPath]!.styleProperty = action.extraPropTransform.styleProperty;
86
- } else {
87
- blockTransforms[action.propPath] = action.extraPropTransform;
88
- }
89
- draft.computedExtraPropTransforms[action.blockName] = undefined;
90
- });
91
- case "SET_PREPPED_PROPERTIES":
92
- return produce(state, (draft: typeof state) => {
93
- draft.preppedProperties[action.blockName] = action.properties;
94
- });
95
- case "SET_EXTRA_PROP_TRANSFORMS":
96
- return produce(state, (draft: typeof state) => {
97
- draft.extraPropTransforms[action.blockName] = action.extraPropTransforms;
98
- });
99
- case "SET_COMPUTED_EXTRA_PROP_TRANSFORMS":
100
- return produce(state, (draft: typeof state) => {
101
- draft.computedExtraPropTransforms[action.blockName] = action.computedExtraPropTransforms;
102
- });
103
- default:
104
- return state;
105
- }
106
- }
107
-
108
- export function addProperties(block: BlockName, properties: PropertiesParameter, simpleNativePanelsAndTabs: SNPLogicState['desiccatedProperties']) {
109
- const panels = (simpleNativePanelsAndTabs[block] ??= []);
110
- if ('title' in properties) {
111
- panels.push(properties);
112
- return;
113
- }
114
- let rawProperties: LaidOutProperties = [];
115
- for (const prop of properties) {
116
- if ('title' in prop) {
117
- if (rawProperties.length) {
118
- panels.push({
119
- title: "",
120
- properties: rawProperties
121
- });
122
- rawProperties = [];
123
- }
124
- panels.push(prop);
125
- } else {
126
- rawProperties.push(prop);
127
- }
128
- }
129
- if (rawProperties.length) {
130
- panels.push({
131
- title: "",
132
- properties: rawProperties
133
- });
134
- }
135
- }
136
-
137
- function normalizeTabItems(
138
- items: SimpleNativeTab['items'], outsideHydrationInfo: OutsideHydrationInfo
139
- ): HydratedSimpleNativeTabItem[] {
140
- let bareProperties: HydratedSimpleNativePanel['properties'] = [];
141
- const normalizedItems: HydratedSimpleNativeTabItem[] = [];
142
- for (const item of items) {
143
- if (Array.isArray(item)) {
144
- bareProperties.push(item.map(prp => hydrateSimpleNativeProperty(prp, "", outsideHydrationInfo, [])));
145
- } else if ('title' in item && 'properties' in item) {
146
- if (bareProperties.length) {
147
- normalizedItems.push({title: "", properties: bareProperties, initialOpen: true});
148
- bareProperties = [];
149
- }
150
- normalizedItems.push(hydrateSimpleNativePanel(item, outsideHydrationInfo));
151
- } else {
152
- bareProperties.push(hydrateSimpleNativeProperty(item, "", outsideHydrationInfo, []));
153
- }
154
- }
155
- if (bareProperties.length) {
156
- normalizedItems.push({title: "", properties: bareProperties, initialOpen: true});
157
- }
158
- return normalizedItems;
159
- }
160
- function hydrateSimpleNativePanel(panel: SimpleNativePanel, outsideHydrationInfo: OutsideHydrationInfo): HydratedSimpleNativePanel {
161
- return {
162
- ...panel, properties: panel.properties.map(prop => Array.isArray(prop)
163
- ? prop.map(prp => hydrateSimpleNativeProperty(prp, "", outsideHydrationInfo, []))
164
- : hydrateSimpleNativeProperty(prop, "", outsideHydrationInfo, []))
165
- }
166
- }
167
-
168
- /**
169
- * This performs the one-time prep for rendering the registered SNP panels and tabs for a Block.
170
- *
171
- * @param block the name of the block to prep
172
- * @param items the properties sourced from the datastore
173
- * @returns either false or an object with at least one declared panel or tab.
174
- * This guarantee is made in order to avoid having to perform more convoluted checks in the render methods
175
- */
176
- export function prepSimpleNativePanelsAndTabs(block: BlockName, items: Array<SimpleNativePanel|SimpleNativeTab>|undefined): PreppedSimpleNativePanelsAndTabs|false {
177
- if (items === undefined) {
178
- return false;
179
- }
180
-
181
- const ungroupedTabs: SimpleNativeTab[] = [];
182
- const panels: SimpleNativePanel[] = [];
183
- for (const item of items) {
184
- const isTab = 'items' in item;
185
- if (item.group === 'layered-styles' || (!isTab && item.dataStoreTypeOverride === 'layered-styles')) {
186
- const props = (isTab
187
- ? item.items.flatMap(propsOrPanel => 'title' in propsOrPanel ? propsOrPanel.properties : propsOrPanel)
188
- : item.properties).flat();
189
-
190
- dispatch(store).addLayeredBlockStyles(block, props);
191
- }
192
- if (isTab) {
193
- ungroupedTabs.push(item);
194
- } else {
195
- panels.push(item);
196
- }
197
- }
198
-
199
- if (!panels.length && !ungroupedTabs.length) {
200
- return false;
201
- }
202
-
203
- let panelOrTabKeyIndex = 0;
204
- const groupedTabs: HydratedInspectorPanelGroupedTabs = {};
205
- for (const tab of ungroupedTabs) {
206
- const tabGroupName = tab.group ?? 'default';
207
- const groupedTabsForName = (groupedTabs[tabGroupName] ?? (groupedTabs[tabGroupName] = [`${block}-${panelOrTabKeyIndex++}`, {}]))[1];
208
- // If a tab with that title already exists, we append its properties to the existing ones
209
- const existingGroupedTabsForName = groupedTabsForName[tab.title];
210
- groupedTabsForName[tab.title] = {
211
- title: tab.title, group: tabGroupName,
212
- items: existingGroupedTabsForName
213
- ? [...existingGroupedTabsForName.items, ...normalizeTabItems(tab.items, {forLayeredStyles: tab.group === "layered-styles", blockName: block})]
214
- : normalizeTabItems(tab.items, {forLayeredStyles: tab.group === "layered-styles", blockName: block})
215
- };
216
- }
217
-
218
- return {
219
- // Because JavaScript's Array sorting methods are stable, we can just sort once at the end
220
- panels: panels
221
- .map(panel => hydrateSimpleNativePanel(panel, {forLayeredStyles: panel.group === "layered-styles", blockName: block}))
222
- .sort(({position: aPosition = 10}, {position: bPosition = 10}) => aPosition - bPosition)
223
- .map(panel => [`${block}-${panelOrTabKeyIndex++}`, panel]),
224
- // We sort tab groups by name in order to force SNP styles to be added after layered-styles
225
- // We don't need to check for equality in the group comparator because Object-keys are guaranteed to be distinct
226
- tabs: Object.fromEntries(Object.entries(groupedTabs)
227
- .sort(([aName], [bName]) => aName > bName ? 1 : -1))
228
- };
229
- }
230
-
231
- export function computeExtraPropTransforms(blockType: RegisterBlockAttrs, extraPropTransforms: ExtraPropTransformsConfig|undefined): PerBlockExtraPropTransforms|false {
232
- if (extraPropTransforms === undefined) {
233
- return false;
234
- }
235
- const rawTransforms = Object.entries(extraPropTransforms);
236
- const transforms = rawTransforms.length
237
- ? rawTransforms.map<PerBlockExtraPropTransforms['transforms'][number]>(transform => [transform[0].split(".") as [string, ...string[]], transform[1]])
238
- : false;
239
- return transforms ? {transforms, appliesInEditor: !isBlockJsonNativePropsConfig(blockType.plaudit)} : false;
240
- }
@@ -1,69 +0,0 @@
1
- import {combineReducers, createReduxStore, register} from "@wordpress/data";
2
-
3
- import type {LaidOutProperties, SimpleNativePanel, SimpleNativeTab} from "../blocks";
4
- import {
5
- customBlockBindingsSupportLogic, customBlockBindingsSupportLogicActions, CustomBlockBindingsSupportLogicActions, customBlockBindingsSupportLogicSelectors,
6
- CustomBlockBindingsSupportLogicState
7
- } from "./gutenberg-api-extensions-state/custom-block-bindings-support-logic";
8
- import {generalLogic, generalLogicActions, GeneralLogicActions, generalLogicSelectors, GeneralLogicState} from "./gutenberg-api-extensions-state/general-logic";
9
- import {
10
- layeredBlockStylesLogic, layeredBlockStylesLogicActions, LayeredBlockStylesLogicActions, layeredBlockStylesLogicSelectors, LayeredBlockStylesLogicState
11
- } from "./gutenberg-api-extensions-state/layered-block-styles-logic";
12
- import {snpLogic, snpLogicActions, SNPLogicActions, snpLogicSelectors, SNPLogicState} from "./gutenberg-api-extensions-state/snp-logic";
13
- import {combineSelectors} from "./helpers";
14
- import type {BlockName} from "./useful-types";
15
-
16
- export type State = {
17
- customBlockBindingsSupportLogic: CustomBlockBindingsSupportLogicState,
18
- layeredBlockStylesLogic: LayeredBlockStylesLogicState,
19
- snpLogic: SNPLogicState,
20
- generalLogic: GeneralLogicState
21
- };
22
- export type BareProperties = SimpleNativePanel|SimpleNativeTab|Array<LaidOutProperties[number]|SimpleNativePanel|SimpleNativeTab>;
23
- export type NamedBlockAction<A extends string, P = {}> = {type: A, blockName: BlockName}&P;
24
-
25
- const DEFAULT_STATE: State = {
26
- customBlockBindingsSupportLogic: {
27
- customBlockBindingsSupport: {}
28
- },
29
- layeredBlockStylesLogic: {
30
- layeredBlockStyles: {}
31
- },
32
- snpLogic: {
33
- desiccatedProperties: {},
34
- preppedProperties: {},
35
- extraPropTransforms: {},
36
- computedExtraPropTransforms: {}
37
- },
38
- generalLogic: {
39
- baselineBlockAttrs: {}, features: {}
40
- }
41
- };
42
-
43
- type ReducerActions = CustomBlockBindingsSupportLogicActions|LayeredBlockStylesLogicActions|SNPLogicActions|GeneralLogicActions;
44
-
45
- export const store = createReduxStore('plaudit/gutenberg-api-extensions', {
46
- initialState: DEFAULT_STATE,
47
- reducer: combineReducers({
48
- customBlockBindingsSupportLogic,
49
- layeredBlockStylesLogic,
50
- snpLogic,
51
- generalLogic
52
- }),
53
- actions: {
54
- ...customBlockBindingsSupportLogicActions,
55
- ...layeredBlockStylesLogicActions,
56
- ...snpLogicActions,
57
- ...generalLogicActions
58
- },
59
- selectors: combineSelectors({
60
- customBlockBindingsSupportLogic: customBlockBindingsSupportLogicSelectors,
61
- layeredBlockStylesLogic: layeredBlockStylesLogicSelectors,
62
- snpLogic: snpLogicSelectors,
63
- generalLogic: generalLogicSelectors
64
- })
65
- });
66
-
67
- export function registerStore() {
68
- register(store);
69
- }
@@ -1,115 +0,0 @@
1
- import {useEffect, useRef} from "@wordpress/element";
2
-
3
- import {is_wp_error, SubsequentArgsOfFunc} from "./useful-types";
4
-
5
- export function clone<T>(value: T): T {
6
- if (value === null || value === undefined) {
7
- return value;
8
- } else if (Array.isArray(value)) {
9
- return value.map(v => clone(v)) as T;
10
- }
11
- return typeof value === 'object' ? Object.fromEntries(Object.entries(value).map(([k, v]) => [k, clone(v)])) as T : value;
12
- }
13
-
14
- // This is madness. I do not know why it works, only that it does.
15
- type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never;
16
-
17
- // This forcibly overwrites the selectors' expected states to be the root state
18
- type SelectorsForT<S, ST> = S extends {[SELECTOR in string]: (state: any, ...args: any[]) => any}
19
- ? {[SL in keyof S]: (state: ST, ...args: SubsequentArgsOfFunc<S[SL]>) => ReturnType<S[SL]>}
20
- : never;
21
-
22
- // This unifies the partial states declared via SelectorArgs into the full state
23
- type StateFromSelectorsArg<S extends SelectorsArg<any>> = {[K in keyof S]: Parameters<S[K][keyof S[K]]>[0]};
24
-
25
- // This handles the, "normalize state and flatten" step
26
- type CombinedSelectors<S extends SelectorsArg<any>> = UnionToIntersection<{[K in keyof S]: SelectorsForT<S[K], StateFromSelectorsArg<S>>}[keyof S]>;
27
-
28
- // Defines the shape of the argument in such a way that its shape can be derived from the state and vice versa
29
- type SelectorsArg<S extends {}> = {[K in keyof S]: {[SELECTOR in string]: (state: S[K], ...args: any[]) => any}};
30
-
31
- export function combineSelectors<S extends SelectorsArg<any>>(selectors: S) {
32
- return Object.fromEntries((Object.entries(selectors) as [keyof S, S[keyof S]][]).flatMap(sel => {
33
- const key = sel[0];
34
- return (Object.entries(sel[1])).map(nestedSel => {
35
- return [nestedSel[0], (state: StateFromSelectorsArg<S>, ...args: SubsequentArgsOfFunc<typeof nestedSel[1]>) => {
36
- return nestedSel[1](state[key], ...args);
37
- }];
38
- });
39
- })) as CombinedSelectors<typeof selectors>;
40
- }
41
-
42
- export function useAdoptedStyleSheet() {
43
- const sheet = useRef<CSSStyleSheet>();
44
- if (sheet.current === undefined) {
45
- sheet.current = new CSSStyleSheet();
46
- }
47
- useEffect(() => {
48
- if (sheet.current !== undefined && !document.adoptedStyleSheets.includes(sheet.current)) {
49
- document.adoptedStyleSheets.push(sheet.current);
50
- }
51
- return () => {
52
- if (sheet.current !== undefined) {
53
- document.adoptedStyleSheets.splice(document.adoptedStyleSheets.indexOf(sheet.current), 1);
54
- }
55
- }
56
- });
57
- return sheet.current;
58
- }
59
-
60
- export class TemporalLRUCache<K, V extends NonNullable<any>|undefined> {
61
- private readonly cache: Map<K, [V, number]> = new Map();
62
- private timeout?: ReturnType<typeof setTimeout>;
63
-
64
- public constructor(
65
- private readonly capacity: number,
66
- private readonly minDroppableAccessTime = 10_000
67
- ) {}
68
-
69
- get(key: K) {
70
- const val = this.cache.get(key);
71
- if (val !== undefined) {
72
- val[1] = Date.now();
73
- return val[0];
74
- }
75
- return null;
76
- }
77
-
78
- set(key: K, value: V) {
79
- this.cache.set(key, [value, Date.now()]);
80
- if (this.cache.size >= this.capacity && this.timeout === undefined) {
81
- this.beginTimeout();
82
- }
83
- }
84
-
85
- has(key: K) {
86
- return this.cache.has(key);
87
- }
88
-
89
- cancelTimeout() {
90
- if (this.timeout !== undefined) {
91
- clearTimeout(this.timeout);
92
- this.timeout = undefined;
93
- }
94
- }
95
- private beginTimeout() {
96
- this.timeout = setTimeout(() => {
97
- const now = Date.now();
98
- const droppableItems = [...this.cache.entries()]
99
- .filter(([_, v]) => now - v[1] >= this.minDroppableAccessTime)
100
- .sort(([_a, [_a0, mraA]], [_b, [_b0, mraB]]) => mraA - mraB)
101
- .slice(0, this.cache.size - this.capacity);
102
- for (const [key] of droppableItems) {
103
- this.cache.delete(key);
104
- }
105
- this.timeout = undefined;
106
- if (this.cache.size > this.capacity) {
107
- this.beginTimeout();
108
- }
109
- }, this.minDroppableAccessTime);
110
- }
111
- }
112
-
113
- export function potentialWpErrorToString(e: unknown): string|undefined {
114
- return is_wp_error(e) ? e.message ?? e.code?.toString() : (e?.toString() as string|undefined)
115
- }
@@ -1,91 +0,0 @@
1
- /**
2
- * This is a modified copy of https://github.com/epoberezkin/fast-deep-equal that treats "not present" and "present but undefined" as equivalent
3
- */
4
- export function fastDeepEquals(a: unknown, b: unknown) {
5
- if (a === b) return true;
6
-
7
- if (a && b && typeof a === 'object' && typeof b === 'object') {
8
- if (a.constructor !== b.constructor) return false;
9
-
10
- if (Array.isArray(a)) {
11
- if (!Array.isArray(b)) {
12
- return false;
13
- }
14
-
15
- const length = a.length;
16
- if (length !== b.length) return false;
17
- for (let i = length - 1; i >= 0; i--) {
18
- if (!fastDeepEquals(a[i], b[i])) return false;
19
- }
20
- return true;
21
- }
22
-
23
-
24
- if (a instanceof Map) {
25
- if (!(b instanceof Map)) {
26
- return false;
27
- }
28
-
29
- for (const [key, value] of b.entries()) {
30
- if (value !== undefined && !a.has(key)) {
31
- return false;
32
- }
33
- }
34
- for (const [key, value] of a.entries()) {
35
- if (value !== undefined && !b.has(key)) {
36
- return false;
37
- }
38
- if (!fastDeepEquals(value, b.get(key))) {
39
- return false;
40
- }
41
- }
42
- return true;
43
- }
44
-
45
- if (a instanceof Set) {
46
- if (!(b instanceof Set)) {
47
- return false;
48
- }
49
- if (a.size !== b.size) {
50
- return false;
51
- }
52
- for (const key of a.keys()) {
53
- if (!b.has(key)) return false;
54
- }
55
- return true;
56
- }
57
-
58
- if (a instanceof RegExp) {
59
- return b instanceof RegExp && a.source === b.source && a.flags === b.flags;
60
- }
61
-
62
- if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
63
- if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
64
-
65
- for (const [key, value] of Object.entries(b)) {
66
- if (value !== undefined && !(key in a)) {
67
- return false;
68
- }
69
- }
70
- for (const [key, value] of Object.entries(a)) {
71
- if (key === '_owner' && "$$typeof" in a) {
72
- // React-specific: avoid traversing React elements' _owner.
73
- // _owner contains circular references
74
- // and is not needed when comparing the actual elements (and not their owners)
75
- continue;
76
- }
77
- if (value !== undefined) {
78
- if (!fastDeepEquals(value, b[key as keyof typeof b])) {
79
- return false;
80
- }
81
- } else if (key in b && b[key as keyof typeof b] !== undefined) {
82
- return false;
83
- }
84
- }
85
-
86
- return true;
87
- }
88
-
89
- // true if both NaN, false otherwise
90
- return a!==a && b!==b;
91
- }
@@ -1,6 +0,0 @@
1
- export const iconColumn1 = <svg width={34} height={24} viewBox="0 0 34 24">
2
- <path
3
- d="M32 2H2v20h30V2zM2 0C.9 0 0 .9 0 2v20c0 1.1.9 2 2 2h30c1.1 0 2-.9 2-2V2c0-1.1-.9-2-2-2H2z"
4
- fillRule="evenodd" clipRule="evenodd"
5
- />
6
- </svg>;
@@ -1,6 +0,0 @@
1
- export const iconColumn2 = <svg width={34} height={24} viewBox="0 0 34 24">
2
- <path
3
- 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"
4
- fillRule="evenodd" clipRule="evenodd"
5
- />
6
- </svg>;
@@ -1,6 +0,0 @@
1
- export const iconColumn3 = <svg width={34} height={24} viewBox="0 0 34 24">
2
- <path
3
- 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"
4
- fillRule="evenodd" clipRule="evenodd"
5
- />
6
- </svg>;
@@ -1,3 +0,0 @@
1
- export const placementCenter = <svg version="1.1" x="0px" y="0px" focusable={false} viewBox="0 0 24 24" enableBackground="new 0 0 24 24" xmlSpace="preserve">
2
- <path d="M20,11h-5V4H9v7H4v1.5h5V20h6v-7.5h5V11z" />
3
- </svg>;
@@ -1,3 +0,0 @@
1
- export const placementEnd = <svg version="1.1" x="0px" y="0px" focusable={false} viewBox="0 0 24 24" enableBackground="new 0 0 24 24" xmlSpace="preserve">
2
- <path d="M15,4H9v11h6V4z M4,18.5V20h16v-1.5H4z" />
3
- </svg>;
@@ -1,3 +0,0 @@
1
- export const placementStart = <svg version="1.1" x="0px" y="0px" focusable={false} viewBox="0 0 24 24" enableBackground="new 0 0 24 24" xmlSpace="preserve">
2
- <path d="M9,20h6V9H9V20z M4,4v1.5h16V4H4z" />
3
- </svg>;
@@ -1,3 +0,0 @@
1
- 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">
2
- <path d="M8.8,6.5h6v11h-6V6.5z M4,18.5h16V20H4V18.5z M4,4h16v1.5H4V4z" />
3
- </svg>;
@@ -1,4 +0,0 @@
1
- export const plauditIcon = <svg width={24} height={24} viewBox="0 0 139 157.6">
2
- <path fill="#d20000"
3
- 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" />
4
- </svg>;
@@ -1,3 +0,0 @@
1
- export const reusableBlockMarker = <svg viewBox="0 0 24 24">
2
- <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" />
3
- </svg>
@@ -1,13 +0,0 @@
1
- // =============================================
2
- // Allows sharing of assets in block configurations
3
- // =============================================
4
-
5
- export * from './plaudit-icons/column-1';
6
- export * from './plaudit-icons/column-2';
7
- export * from './plaudit-icons/column-3';
8
- export * from './plaudit-icons/placement-start';
9
- export * from './plaudit-icons/placement-center';
10
- export * from './plaudit-icons/placement-end';
11
- export * from './plaudit-icons/placement-stretch';
12
- export * from './plaudit-icons/plaudit-icon';
13
- export * from './plaudit-icons/reusable-block-marker';