@webikon/webentor-core 0.9.12
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/.husky/pre-commit +40 -0
- package/.prettierrc.js +5 -0
- package/CHANGELOG.md +88 -0
- package/LICENCE.md +7 -0
- package/README.md +26 -0
- package/core-js/_alpine.ts +20 -0
- package/core-js/_slider.ts +232 -0
- package/core-js/_utils.ts +126 -0
- package/core-js/blocks-components/block-appender.tsx +36 -0
- package/core-js/blocks-components/button.tsx +424 -0
- package/core-js/blocks-components/custom-image-sizes-panel.tsx +197 -0
- package/core-js/blocks-components/index.ts +4 -0
- package/core-js/blocks-components/typography-picker-select.tsx +31 -0
- package/core-js/blocks-filters/_filter-core-typography.tsx +108 -0
- package/core-js/blocks-filters/_slider-settings.tsx +283 -0
- package/core-js/blocks-filters/index.ts +3 -0
- package/core-js/blocks-filters/responsive-settings/components/DisabledSliderInfo.tsx +10 -0
- package/core-js/blocks-filters/responsive-settings/constants.ts +11 -0
- package/core-js/blocks-filters/responsive-settings/index.tsx +196 -0
- package/core-js/blocks-filters/responsive-settings/settings/block-link/index.ts +1 -0
- package/core-js/blocks-filters/responsive-settings/settings/block-link/panel.tsx +47 -0
- package/core-js/blocks-filters/responsive-settings/settings/border/border/index.tsx +1 -0
- package/core-js/blocks-filters/responsive-settings/settings/border/border/properties.ts +27 -0
- package/core-js/blocks-filters/responsive-settings/settings/border/border/settings.tsx +310 -0
- package/core-js/blocks-filters/responsive-settings/settings/border/border-radius/index.tsx +1 -0
- package/core-js/blocks-filters/responsive-settings/settings/border/border-radius/properties.ts +31 -0
- package/core-js/blocks-filters/responsive-settings/settings/border/border-radius/settings.tsx +211 -0
- package/core-js/blocks-filters/responsive-settings/settings/border/index.ts +1 -0
- package/core-js/blocks-filters/responsive-settings/settings/border/panel.tsx +54 -0
- package/core-js/blocks-filters/responsive-settings/settings/container/display/index.ts +2 -0
- package/core-js/blocks-filters/responsive-settings/settings/container/display/properties.ts +167 -0
- package/core-js/blocks-filters/responsive-settings/settings/container/display/settings.tsx +73 -0
- package/core-js/blocks-filters/responsive-settings/settings/container/flexbox/index.ts +2 -0
- package/core-js/blocks-filters/responsive-settings/settings/container/flexbox/properties.ts +187 -0
- package/core-js/blocks-filters/responsive-settings/settings/container/flexbox/settings.tsx +131 -0
- package/core-js/blocks-filters/responsive-settings/settings/container/grid/index.ts +2 -0
- package/core-js/blocks-filters/responsive-settings/settings/container/grid/properties.ts +187 -0
- package/core-js/blocks-filters/responsive-settings/settings/container/grid/settings.tsx +132 -0
- package/core-js/blocks-filters/responsive-settings/settings/container/index.ts +4 -0
- package/core-js/blocks-filters/responsive-settings/settings/container/panel.tsx +92 -0
- package/core-js/blocks-filters/responsive-settings/settings/spacing/index.ts +3 -0
- package/core-js/blocks-filters/responsive-settings/settings/spacing/panel.tsx +45 -0
- package/core-js/blocks-filters/responsive-settings/settings/spacing/properties.ts +74 -0
- package/core-js/blocks-filters/responsive-settings/settings/spacing/settings.tsx +85 -0
- package/core-js/blocks-filters/responsive-settings/types/index.ts +68 -0
- package/core-js/blocks-filters/responsive-settings/utils.ts +321 -0
- package/core-js/blocks-utils/_use-block-parent.ts +27 -0
- package/core-js/blocks-utils/_use-post-types.ts +43 -0
- package/core-js/blocks-utils/_use-taxonomies.ts +29 -0
- package/core-js/blocks-utils/index.ts +3 -0
- package/core-js/config/webentor-config.ts +718 -0
- package/core-js/index.ts +14 -0
- package/core-js/types/_block-components.ts +7 -0
- package/core-js/types/_webentor-config.ts +182 -0
- package/package.json +98 -0
- package/resources/blocks/e-accordion/block.json +34 -0
- package/resources/blocks/e-accordion/e-accordion.block.tsx +125 -0
- package/resources/blocks/e-accordion/script.ts +1 -0
- package/resources/blocks/e-accordion/style.css +8 -0
- package/resources/blocks/e-accordion-group/block.json +56 -0
- package/resources/blocks/e-accordion-group/e-accordion-group.block.tsx +99 -0
- package/resources/blocks/e-breadcrumbs/block.json +41 -0
- package/resources/blocks/e-breadcrumbs/e-breadcrumbs.block.tsx +53 -0
- package/resources/blocks/e-button/block.json +32 -0
- package/resources/blocks/e-button/e-button.block.tsx +55 -0
- package/resources/blocks/e-gallery/block.json +90 -0
- package/resources/blocks/e-gallery/e-gallery.block.tsx +316 -0
- package/resources/blocks/e-icon-picker/block.json +37 -0
- package/resources/blocks/e-icon-picker/e-icon-picker.block.tsx +230 -0
- package/resources/blocks/e-icon-picker/style.css +17 -0
- package/resources/blocks/e-image/block.json +78 -0
- package/resources/blocks/e-image/e-image.block.tsx +331 -0
- package/resources/blocks/e-picker-query-loop/block.json +25 -0
- package/resources/blocks/e-picker-query-loop/e-picker-query-loop.block.tsx +189 -0
- package/resources/blocks/e-post-template/block.json +25 -0
- package/resources/blocks/e-post-template/e-post-template.block.tsx +100 -0
- package/resources/blocks/e-query-loop/block.json +36 -0
- package/resources/blocks/e-query-loop/constants.tsx +8 -0
- package/resources/blocks/e-query-loop/e-query-loop.block.tsx +270 -0
- package/resources/blocks/e-query-loop/taxonomy-controls.tsx +184 -0
- package/resources/blocks/e-slider/block.json +42 -0
- package/resources/blocks/e-slider/e-slider.block.tsx +100 -0
- package/resources/blocks/e-svg/block.json +37 -0
- package/resources/blocks/e-svg/e-svg.block.tsx +156 -0
- package/resources/blocks/e-tab-container/block.json +49 -0
- package/resources/blocks/e-tab-container/e-tab-container.block.tsx +123 -0
- package/resources/blocks/e-table/block.json +30 -0
- package/resources/blocks/e-table/e-table.block.tsx +120 -0
- package/resources/blocks/e-table/script.ts +48 -0
- package/resources/blocks/e-table-cell/block.json +40 -0
- package/resources/blocks/e-table-cell/e-table-cell.block.tsx +180 -0
- package/resources/blocks/e-table-row/block.json +28 -0
- package/resources/blocks/e-table-row/e-table-row.block.tsx +118 -0
- package/resources/blocks/e-tabs/block.json +27 -0
- package/resources/blocks/e-tabs/e-tabs.block.tsx +90 -0
- package/resources/blocks/l-404/block.json +51 -0
- package/resources/blocks/l-404/l-404.block.tsx +75 -0
- package/resources/blocks/l-flexible-container/block.json +34 -0
- package/resources/blocks/l-flexible-container/l-flexible-container.block.tsx +97 -0
- package/resources/blocks/l-footer/block.json +23 -0
- package/resources/blocks/l-footer/l-footer.block.tsx +51 -0
- package/resources/blocks/l-formatted-content/block.json +28 -0
- package/resources/blocks/l-formatted-content/l-formatted-content.block.tsx +97 -0
- package/resources/blocks/l-header/block.json +26 -0
- package/resources/blocks/l-header/l-header.block.tsx +100 -0
- package/resources/blocks/l-mobile-nav/block.json +15 -0
- package/resources/blocks/l-mobile-nav/l-mobile-nav.block.tsx +56 -0
- package/resources/blocks/l-mobile-nav/style.css +54 -0
- package/resources/blocks/l-nav-menu/block.json +27 -0
- package/resources/blocks/l-nav-menu/l-nav-menu.block.tsx +109 -0
- package/resources/blocks/l-nav-menu/style.css +134 -0
- package/resources/blocks/l-post-card/block.json +13 -0
- package/resources/blocks/l-post-card/l-post-card.block.tsx +52 -0
- package/resources/blocks/l-section/block.json +89 -0
- package/resources/blocks/l-section/l-section.block.tsx +316 -0
- package/resources/blocks/l-site-logo/block.json +15 -0
- package/resources/blocks/l-site-logo/l-site-logo.block.tsx +54 -0
- package/resources/core-components/slider/slider.script.ts +11 -0
- package/resources/core-components/slider/slider.style.css +134 -0
- package/resources/scripts/editor.ts +29 -0
- package/resources/styles/app.css +21 -0
- package/resources/styles/common/_editor.css +86 -0
- package/resources/styles/common/_form.css +83 -0
- package/resources/styles/common/_global.css +73 -0
- package/resources/styles/common/_theme.css +75 -0
- package/resources/styles/common/_utilities.css +33 -0
- package/resources/styles/common/_wordpress.css +110 -0
- package/resources/styles/components/_table.css +102 -0
- package/resources/styles/editor.css +16 -0
- package/resources/styles/partials/.gitkeep +0 -0
- package/resources/styles/partials/_header.css +21 -0
- package/resources/styles/partials/_pagination.css +35 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { useBlockProps } from '@wordpress/block-editor';
|
|
2
|
+
import { getBlockType } from '@wordpress/blocks';
|
|
3
|
+
|
|
4
|
+
import { useBlockParent } from '@webentorCore/blocks-utils/_use-block-parent';
|
|
5
|
+
|
|
6
|
+
export const getPixelFromRemValue = (value: string): string => {
|
|
7
|
+
if (value.includes('rem')) {
|
|
8
|
+
const remValue = value.replace('rem', '');
|
|
9
|
+
return `${Number(remValue) * 16}px`;
|
|
10
|
+
}
|
|
11
|
+
return value;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const hasSpacingSettingsForBreakpoint = (
|
|
15
|
+
attributes: any,
|
|
16
|
+
breakpoint: string,
|
|
17
|
+
): boolean => {
|
|
18
|
+
return (
|
|
19
|
+
attributes?.spacing?.['margin-top']?.value?.[breakpoint] ||
|
|
20
|
+
attributes?.spacing?.['margin-bottom']?.value?.[breakpoint] ||
|
|
21
|
+
attributes?.spacing?.['margin-left']?.value?.[breakpoint] ||
|
|
22
|
+
attributes?.spacing?.['margin-right']?.value?.[breakpoint] ||
|
|
23
|
+
attributes?.spacing?.['padding-top']?.value?.[breakpoint] ||
|
|
24
|
+
attributes?.spacing?.['padding-bottom']?.value?.[breakpoint] ||
|
|
25
|
+
attributes?.spacing?.['padding-left']?.value?.[breakpoint] ||
|
|
26
|
+
attributes?.spacing?.['padding-right']?.value?.[breakpoint]
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const isSliderEnabledForBreakpoint = (
|
|
31
|
+
blockName: string,
|
|
32
|
+
attributes: any,
|
|
33
|
+
breakpoint: string,
|
|
34
|
+
): boolean => {
|
|
35
|
+
return (
|
|
36
|
+
blockName === 'webentor/e-slider' &&
|
|
37
|
+
attributes?.slider?.enabled?.value?.[breakpoint]
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const prepareTailwindClassesFromSettings = (
|
|
42
|
+
settings: any,
|
|
43
|
+
type: string,
|
|
44
|
+
): string[] => {
|
|
45
|
+
const classes: string[] = [];
|
|
46
|
+
|
|
47
|
+
const parentBlock = useBlockParent();
|
|
48
|
+
const parentBlockAttributes = parentBlock?.attributes;
|
|
49
|
+
|
|
50
|
+
if (settings[type]) {
|
|
51
|
+
Object.entries(settings[type]).forEach(([, prop]: [string, any]) => {
|
|
52
|
+
if (prop?.value) {
|
|
53
|
+
Object.entries(prop?.value).forEach(
|
|
54
|
+
([bpName, bpPropValue]: [string, any]) => {
|
|
55
|
+
// Skip flex related settings when display is not flex
|
|
56
|
+
if (type === 'flex') {
|
|
57
|
+
if (settings?.display?.display?.value?.[bpName] !== 'flex') {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Skip flex item related settings when parent display is not flex
|
|
63
|
+
if (type === 'flexItem') {
|
|
64
|
+
if (
|
|
65
|
+
parentBlockAttributes?.display?.display?.value?.[bpName] !==
|
|
66
|
+
'flex'
|
|
67
|
+
) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Skip grid related settings when display is not grid
|
|
73
|
+
if (type === 'grid') {
|
|
74
|
+
if (settings?.display?.display?.value?.[bpName] !== 'grid') {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Skip grid item related settings when parent display is not grid
|
|
80
|
+
if (type === 'gridItem') {
|
|
81
|
+
if (
|
|
82
|
+
parentBlockAttributes?.display?.display?.value?.[bpName] !=
|
|
83
|
+
'grid'
|
|
84
|
+
) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Skip when slider is enabled
|
|
90
|
+
if (settings?.slider?.enabled?.value?.[bpName]) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (bpPropValue) {
|
|
95
|
+
const twBreakpoint = bpName === 'basic' ? '' : `${bpName}:`;
|
|
96
|
+
|
|
97
|
+
if (bpPropValue === 'hidden') {
|
|
98
|
+
// Hidden items should be semi-transparent to indicate that they are hidden but still present
|
|
99
|
+
classes.push(`${twBreakpoint}opacity-30`);
|
|
100
|
+
} else {
|
|
101
|
+
classes.push(`${twBreakpoint}${bpPropValue}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return classes;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
export const prepareTailwindBorderClassesFromSettings = (
|
|
114
|
+
settings: any,
|
|
115
|
+
type: string,
|
|
116
|
+
side: string | string[],
|
|
117
|
+
): string[] => {
|
|
118
|
+
const classes: string[] = [];
|
|
119
|
+
if (settings[type]) {
|
|
120
|
+
Object.entries(settings[type]).forEach(
|
|
121
|
+
([propName, prop]: [string, any]) => {
|
|
122
|
+
if (prop?.value) {
|
|
123
|
+
Object.entries(prop?.value).forEach(
|
|
124
|
+
([bpName, bpPropValue]: [string, object]) => {
|
|
125
|
+
if (bpPropValue) {
|
|
126
|
+
const twBreakpoint = bpName === 'basic' ? '' : `${bpName}:`;
|
|
127
|
+
|
|
128
|
+
Object.entries(bpPropValue).forEach(
|
|
129
|
+
([valueSide, value]: [string, any]) => {
|
|
130
|
+
if (valueSide === 'linked') {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (propName === 'border') {
|
|
135
|
+
// Check if side classes should be processed as we can in some cases get only one side of the border
|
|
136
|
+
if (Array.isArray(side) && !side.includes(valueSide)) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (typeof side === 'string' && side !== valueSide) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
classes.push(
|
|
145
|
+
...prepareTailwindBorderClassesForSide(
|
|
146
|
+
value,
|
|
147
|
+
valueSide,
|
|
148
|
+
twBreakpoint,
|
|
149
|
+
),
|
|
150
|
+
);
|
|
151
|
+
} else if (propName === 'borderRadius') {
|
|
152
|
+
classes.push(
|
|
153
|
+
...prepareTailwindBorderRadiusClassesForCorner(
|
|
154
|
+
value,
|
|
155
|
+
valueSide,
|
|
156
|
+
twBreakpoint,
|
|
157
|
+
),
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return classes;
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const prepareTailwindBorderRadiusClassesForCorner = (
|
|
174
|
+
value: any,
|
|
175
|
+
corner: string,
|
|
176
|
+
twBreakpoint: string,
|
|
177
|
+
): string[] => {
|
|
178
|
+
const classes: string[] = [];
|
|
179
|
+
|
|
180
|
+
const radiusMapping = {
|
|
181
|
+
topLeft: 'rounded-tl',
|
|
182
|
+
topRight: 'rounded-tr',
|
|
183
|
+
bottomRight: 'rounded-br',
|
|
184
|
+
bottomLeft: 'rounded-bl',
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
if (value) {
|
|
188
|
+
classes.push(`${twBreakpoint}${radiusMapping[corner]}-${value}`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return classes;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
export const prepareTailwindBorderClassesForSide = (
|
|
195
|
+
value: any,
|
|
196
|
+
side: string,
|
|
197
|
+
twBreakpoint: string,
|
|
198
|
+
): string[] => {
|
|
199
|
+
const classes: string[] = [];
|
|
200
|
+
|
|
201
|
+
const borderMapping = {
|
|
202
|
+
top: 'border-t',
|
|
203
|
+
right: 'border-r',
|
|
204
|
+
bottom: 'border-b',
|
|
205
|
+
left: 'border-l',
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
if (value) {
|
|
209
|
+
if (value?.width) {
|
|
210
|
+
classes.push(`${twBreakpoint}${borderMapping[side]}-${value.width}`);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (value?.style) {
|
|
214
|
+
classes.push(`${twBreakpoint}${borderMapping[side]}-${value.style}`);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (value?.color) {
|
|
218
|
+
classes.push(`${twBreakpoint}${borderMapping[side]}-${value.color}`);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return classes;
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
export const applyResponsiveSettings = (attributes: any): boolean => {
|
|
226
|
+
if (
|
|
227
|
+
!attributes?.blockLink &&
|
|
228
|
+
!attributes?.spacing &&
|
|
229
|
+
!attributes?.display &&
|
|
230
|
+
!attributes?.grid &&
|
|
231
|
+
!attributes?.gridItem &&
|
|
232
|
+
!attributes?.flexbox &&
|
|
233
|
+
!attributes?.flexboxItem
|
|
234
|
+
) {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return true;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Automatically generates the class names for the block based on the attributes if they are supported.
|
|
243
|
+
*
|
|
244
|
+
* @param attributes - The attributes of the block
|
|
245
|
+
* @returns The class names of the block
|
|
246
|
+
*/
|
|
247
|
+
export const generateClassNames = (attributes: any): string => {
|
|
248
|
+
if (!applyResponsiveSettings(attributes)) {
|
|
249
|
+
return '';
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const blockProps = useBlockProps();
|
|
253
|
+
// const settings = useSettings();
|
|
254
|
+
const blockName = blockProps['data-type'];
|
|
255
|
+
|
|
256
|
+
const blockSettings = getBlockType(blockName);
|
|
257
|
+
const supports = blockSettings?.supports;
|
|
258
|
+
|
|
259
|
+
const classes: string[] = [];
|
|
260
|
+
|
|
261
|
+
// Prepare all Tailwind classes
|
|
262
|
+
if (supports?.webentor?.spacing) {
|
|
263
|
+
const spacingClasses = prepareTailwindClassesFromSettings(
|
|
264
|
+
attributes,
|
|
265
|
+
'spacing',
|
|
266
|
+
);
|
|
267
|
+
classes.push(...spacingClasses);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (supports?.webentor?.display) {
|
|
271
|
+
const displayClasses = prepareTailwindClassesFromSettings(
|
|
272
|
+
attributes,
|
|
273
|
+
'display',
|
|
274
|
+
);
|
|
275
|
+
classes.push(...displayClasses);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (supports?.webentor?.flexbox) {
|
|
279
|
+
const flexboxClasses = prepareTailwindClassesFromSettings(
|
|
280
|
+
attributes,
|
|
281
|
+
'flexbox',
|
|
282
|
+
);
|
|
283
|
+
classes.push(...flexboxClasses);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (supports?.webentor?.flexboxItem) {
|
|
287
|
+
const flexboxItemClasses = prepareTailwindClassesFromSettings(
|
|
288
|
+
attributes,
|
|
289
|
+
'flexboxItem',
|
|
290
|
+
);
|
|
291
|
+
classes.push(...flexboxItemClasses);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (supports?.webentor?.grid) {
|
|
295
|
+
const gridClasses = prepareTailwindClassesFromSettings(attributes, 'grid');
|
|
296
|
+
classes.push(...gridClasses);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (supports?.webentor?.gridItem) {
|
|
300
|
+
const gridItemClasses = prepareTailwindClassesFromSettings(
|
|
301
|
+
attributes,
|
|
302
|
+
'gridItem',
|
|
303
|
+
);
|
|
304
|
+
classes.push(...gridItemClasses);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (supports?.webentor?.border || supports?.webentor?.borderRadius) {
|
|
308
|
+
const borderClasses = prepareTailwindBorderClassesFromSettings(
|
|
309
|
+
attributes,
|
|
310
|
+
'border',
|
|
311
|
+
['top', 'right', 'bottom', 'left'],
|
|
312
|
+
);
|
|
313
|
+
classes.push(...borderClasses);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return classes.join(' ') ?? '';
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
export const inlineStyleGenerator = (): Record<string, any> => {
|
|
320
|
+
return {};
|
|
321
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
store as blockEditorStore,
|
|
3
|
+
useBlockProps,
|
|
4
|
+
} from '@wordpress/block-editor';
|
|
5
|
+
import { useSelect } from '@wordpress/data';
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Allows you to easily interface with the direct
|
|
9
|
+
* parent of the current block
|
|
10
|
+
*/
|
|
11
|
+
export const useBlockParent = () => {
|
|
12
|
+
// Get the client id from the block props, because the useBlockEditContext is for some reason not returning correct client id in various cases
|
|
13
|
+
const { id } = useBlockProps();
|
|
14
|
+
const clientId = id.replace('block-', '');
|
|
15
|
+
|
|
16
|
+
const parentClientId = useSelect(
|
|
17
|
+
(select) => select(blockEditorStore).getBlockRootClientId(clientId),
|
|
18
|
+
[clientId],
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const parentBlock = useSelect(
|
|
22
|
+
(select) => select(blockEditorStore).getBlock(parentClientId),
|
|
23
|
+
[parentClientId],
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
return parentBlock;
|
|
27
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useSelect } from '@wordpress/data';
|
|
2
|
+
import { useMemo } from '@wordpress/element';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns a helper object that contains:
|
|
6
|
+
* 1. An `options` object from the available post types, to be passed to a `SelectControl`.
|
|
7
|
+
* 2. A helper map with available taxonomies per post type.
|
|
8
|
+
*
|
|
9
|
+
* Source: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/query/utils.js
|
|
10
|
+
*
|
|
11
|
+
* @return {Object} The helper object related to post types.
|
|
12
|
+
*/
|
|
13
|
+
export const usePostTypes = () => {
|
|
14
|
+
const postTypes = useSelect((select) => {
|
|
15
|
+
const { getPostTypes } = select('core');
|
|
16
|
+
|
|
17
|
+
const excludedPostTypes = ['attachment'];
|
|
18
|
+
// @ts-expect-error We don't have the type for this function
|
|
19
|
+
const filteredPostTypes = getPostTypes({ per_page: -1 })?.filter(
|
|
20
|
+
({ viewable, slug }) => viewable && !excludedPostTypes.includes(slug),
|
|
21
|
+
);
|
|
22
|
+
return filteredPostTypes;
|
|
23
|
+
}, []);
|
|
24
|
+
|
|
25
|
+
const postTypesTaxonomiesMap = useMemo(() => {
|
|
26
|
+
if (!postTypes?.length) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
return postTypes.reduce((accumulator, type) => {
|
|
30
|
+
accumulator[type.slug] = type.taxonomies;
|
|
31
|
+
return accumulator;
|
|
32
|
+
}, {});
|
|
33
|
+
}, [postTypes]);
|
|
34
|
+
const postTypesSelectOptions = useMemo(
|
|
35
|
+
() =>
|
|
36
|
+
(postTypes || []).map(({ labels, slug }) => ({
|
|
37
|
+
label: labels.singular_name,
|
|
38
|
+
value: slug,
|
|
39
|
+
})),
|
|
40
|
+
[postTypes],
|
|
41
|
+
);
|
|
42
|
+
return { postTypesTaxonomiesMap, postTypesSelectOptions };
|
|
43
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useSelect } from '@wordpress/data';
|
|
2
|
+
import { useMemo } from '@wordpress/element';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Hook that returns the taxonomies associated with a specific post type.
|
|
6
|
+
*
|
|
7
|
+
* Source: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/query/utils.js
|
|
8
|
+
*
|
|
9
|
+
* @param {string} postType The post type from which to retrieve the associated taxonomies.
|
|
10
|
+
* @return {Object[]} An array of the associated taxonomies.
|
|
11
|
+
*/
|
|
12
|
+
export const useTaxonomies = (postType) => {
|
|
13
|
+
const taxonomies = useSelect(
|
|
14
|
+
(select) => {
|
|
15
|
+
const { getTaxonomies } = select('core');
|
|
16
|
+
// @ts-expect-error We don't have the type for this function
|
|
17
|
+
return getTaxonomies({
|
|
18
|
+
type: postType,
|
|
19
|
+
per_page: -1,
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
[postType],
|
|
23
|
+
);
|
|
24
|
+
return useMemo(() => {
|
|
25
|
+
return taxonomies?.filter(
|
|
26
|
+
({ visibility }) => !!visibility?.publicly_queryable,
|
|
27
|
+
);
|
|
28
|
+
}, [taxonomies]);
|
|
29
|
+
};
|