@wordpress-gcb/fields 0.2.1 → 0.2.2
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/dist/conditional-logic.js +83 -0
- package/{src → dist}/control-context.js +3 -2
- package/{src → dist}/controls/MediaCapabilityGate.js +12 -8
- package/dist/controls/MediaPicker.js +149 -0
- package/dist/controls/MediaTriggerBadges.js +35 -0
- package/{src → dist}/controls/PopoverOrModal.js +49 -43
- package/dist/controls/SortableItem.js +126 -0
- package/dist/controls/button-group.js +46 -0
- package/dist/controls/checkbox-group.js +65 -0
- package/dist/controls/checkbox.js +15 -0
- package/dist/controls/code.js +24 -0
- package/dist/controls/color.js +241 -0
- package/dist/controls/date.js +55 -0
- package/dist/controls/datetime.js +61 -0
- package/dist/controls/email.js +17 -0
- package/dist/controls/file.js +163 -0
- package/dist/controls/gallery.js +371 -0
- package/dist/controls/google-map.js +143 -0
- package/dist/controls/heading-level.js +93 -0
- package/dist/controls/icon.js +292 -0
- package/dist/controls/image.js +360 -0
- package/dist/controls/index.js +88 -0
- package/dist/controls/message.js +86 -0
- package/dist/controls/number.js +19 -0
- package/dist/controls/oembed.js +42 -0
- package/{src → dist}/controls/page-link.js +1 -2
- package/dist/controls/post-object.js +913 -0
- package/dist/controls/radio.js +19 -0
- package/dist/controls/range.js +108 -0
- package/{src → dist}/controls/relationship.js +12 -7
- package/dist/controls/repeater.js +277 -0
- package/dist/controls/richtext.js +494 -0
- package/dist/controls/select.js +144 -0
- package/dist/controls/size.js +59 -0
- package/dist/controls/spacing.js +141 -0
- package/dist/controls/taxonomy.js +569 -0
- package/dist/controls/text.js +16 -0
- package/dist/controls/textarea.js +17 -0
- package/dist/controls/toggle-group.js +28 -0
- package/dist/controls/toggle.js +15 -0
- package/dist/controls/url.js +235 -0
- package/dist/controls/user.js +383 -0
- package/{src → dist}/controls/wysiwyg.js +1 -1
- package/{src → dist}/hooks/useTokens.js +25 -21
- package/{src → dist}/index.js +2 -8
- package/dist/inspector.js +163 -0
- package/{src → dist}/provider.js +18 -17
- package/dist/utils/map-utils.js +54 -0
- package/dist/utils/token-helper.js +396 -0
- package/{src → dist}/validation-context.js +4 -4
- package/package.json +20 -13
- package/src/conditional-logic.js +0 -77
- package/src/controls/MediaPicker.js +0 -139
- package/src/controls/MediaTriggerBadges.js +0 -31
- package/src/controls/SortableItem.js +0 -110
- package/src/controls/button-group.js +0 -49
- package/src/controls/checkbox-group.js +0 -55
- package/src/controls/checkbox.js +0 -13
- package/src/controls/code.js +0 -21
- package/src/controls/color.js +0 -235
- package/src/controls/date.js +0 -37
- package/src/controls/datetime.js +0 -54
- package/src/controls/email.js +0 -15
- package/src/controls/file.js +0 -134
- package/src/controls/gallery.js +0 -338
- package/src/controls/google-map.js +0 -117
- package/src/controls/heading-level.js +0 -99
- package/src/controls/icon.js +0 -301
- package/src/controls/image.js +0 -334
- package/src/controls/index.js +0 -95
- package/src/controls/message.js +0 -56
- package/src/controls/number.js +0 -17
- package/src/controls/oembed.js +0 -32
- package/src/controls/post-object.js +0 -788
- package/src/controls/radio.js +0 -18
- package/src/controls/range.js +0 -110
- package/src/controls/repeater.js +0 -290
- package/src/controls/richtext.js +0 -505
- package/src/controls/select.js +0 -141
- package/src/controls/size.js +0 -49
- package/src/controls/spacing.js +0 -141
- package/src/controls/taxonomy.js +0 -488
- package/src/controls/text.js +0 -14
- package/src/controls/textarea.js +0 -15
- package/src/controls/toggle-group.js +0 -34
- package/src/controls/toggle.js +0 -13
- package/src/controls/url.js +0 -164
- package/src/controls/user.js +0 -343
- package/src/inspector.js +0 -174
- package/src/utils/map-utils.js +0 -51
- package/src/utils/token-helper.js +0 -243
package/src/utils/map-utils.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Map utilities for fields that translate user-friendly keys to backend tokens.
|
|
3
|
-
*
|
|
4
|
-
* simple: { sm: 'spacing-sm', md: 'spacing-md' }
|
|
5
|
-
* labelled:{ sm: { label: 'Small (16px)', token: 'spacing-sm' } }
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
export const parseMap = (map) => {
|
|
9
|
-
if (!map || typeof map !== 'object') return null;
|
|
10
|
-
const out = {};
|
|
11
|
-
Object.entries(map).forEach(([key, value]) => {
|
|
12
|
-
if (typeof value === 'string') {
|
|
13
|
-
out[key] = { label: key, token: value };
|
|
14
|
-
} else if (typeof value === 'object' && value.token) {
|
|
15
|
-
out[key] = { label: value.label || key, token: value.token };
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
return Object.keys(out).length > 0 ? out : null;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const getTokenFromKey = (m, key) => (m && key ? m[key]?.token || null : null);
|
|
22
|
-
|
|
23
|
-
export const getKeyFromToken = (m, token) => {
|
|
24
|
-
if (!m || !token) return null;
|
|
25
|
-
const entry = Object.entries(m).find(([, v]) => v.token === token);
|
|
26
|
-
return entry ? entry[0] : null;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const mapToOptions = (m) => {
|
|
30
|
-
if (!m) return [];
|
|
31
|
-
return Object.entries(m).map(([key, v]) => ({ label: v.label, value: key }));
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const getMapKeys = (m) => {
|
|
35
|
-
if (!m) return [];
|
|
36
|
-
return Object.keys(m)
|
|
37
|
-
.map((k) => Number(k))
|
|
38
|
-
.filter((k) => !Number.isNaN(k))
|
|
39
|
-
.sort((a, b) => a - b);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
export const mapToRangeMarks = (m) => {
|
|
43
|
-
if (!m) return null;
|
|
44
|
-
return Object.entries(m).map(([key, v]) => ({ value: Number(key), label: v.label }));
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const isValidMapValue = (m, value) => {
|
|
48
|
-
if (!m || value === null || value === undefined) return false;
|
|
49
|
-
if (m[value]) return true;
|
|
50
|
-
return Object.values(m).some((e) => e.token === value);
|
|
51
|
-
};
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Token helpers — ported from the original GCB.
|
|
3
|
-
*
|
|
4
|
-
* Two layers of tokens:
|
|
5
|
-
* - Built-in groups (this file): hard-coded design system tokens that ship
|
|
6
|
-
* with the plugin. Useful as a fallback when a theme has no theme.json.
|
|
7
|
-
* - Theme groups (window.gcbLite.tokens): parsed from theme.json by PHP.
|
|
8
|
-
* Always merged in by getTokenGroupTokens() below — theme tokens win on
|
|
9
|
-
* a path collision.
|
|
10
|
-
*
|
|
11
|
-
* Token path syntax: "category:subKey" or "category:subKey:tokenKey".
|
|
12
|
-
* "spacing:scale" — the group of tokens
|
|
13
|
-
* "spacing:scale:30" — a specific token
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
const builtInTokenGroups = {
|
|
17
|
-
color: {
|
|
18
|
-
label: 'Color',
|
|
19
|
-
children: {
|
|
20
|
-
palette: {
|
|
21
|
-
label: 'Palette',
|
|
22
|
-
tokens: [
|
|
23
|
-
{ key: 'primary', value: 'color-primary', label: 'Primary' },
|
|
24
|
-
{ key: 'secondary', value: 'color-secondary', label: 'Secondary' },
|
|
25
|
-
{ key: 'accent', value: 'color-accent', label: 'Accent' },
|
|
26
|
-
{ key: 'neutral', value: 'color-neutral', label: 'Neutral' },
|
|
27
|
-
{ key: 'dark', value: 'color-dark', label: 'Dark' },
|
|
28
|
-
{ key: 'light', value: 'color-light', label: 'Light' },
|
|
29
|
-
],
|
|
30
|
-
},
|
|
31
|
-
duotone: {
|
|
32
|
-
label: 'Duotone',
|
|
33
|
-
tokens: [
|
|
34
|
-
{ key: 'blue', value: 'duotone-blue', label: 'Blue Duotone' },
|
|
35
|
-
{ key: 'purple', value: 'duotone-purple', label: 'Purple Duotone' },
|
|
36
|
-
{ key: 'green', value: 'duotone-green', label: 'Green Duotone' },
|
|
37
|
-
],
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
spacing: {
|
|
42
|
-
label: 'Spacing',
|
|
43
|
-
children: {
|
|
44
|
-
scale: {
|
|
45
|
-
label: 'Scale',
|
|
46
|
-
tokens: [
|
|
47
|
-
{ key: '0', value: 'spacing-none', label: 'None (0)', size: '0' },
|
|
48
|
-
{ key: '10', value: 'spacing-10', label: 'Step 1 (0.25rem)', size: '0.25rem' },
|
|
49
|
-
{ key: '20', value: 'spacing-20', label: 'Step 2 (0.5rem)', size: '0.5rem' },
|
|
50
|
-
{ key: '30', value: 'spacing-30', label: 'Step 3 (1rem)', size: '1rem' },
|
|
51
|
-
{ key: '40', value: 'spacing-40', label: 'Step 4 (1.5rem)', size: '1.5rem' },
|
|
52
|
-
{ key: '50', value: 'spacing-50', label: 'Step 5 (2rem)', size: '2rem' },
|
|
53
|
-
{ key: '60', value: 'spacing-60', label: 'Step 6 (3rem)', size: '3rem' },
|
|
54
|
-
{ key: '70', value: 'spacing-70', label: 'Step 7 (4rem)', size: '4rem' },
|
|
55
|
-
{ key: '80', value: 'spacing-80', label: 'Step 8 (6rem)', size: '6rem' },
|
|
56
|
-
],
|
|
57
|
-
},
|
|
58
|
-
presets: {
|
|
59
|
-
label: 'Presets',
|
|
60
|
-
tokens: [
|
|
61
|
-
{ key: 'xs', value: 'spacing-xs', label: 'Extra Small (0.5rem)', size: '0.5rem' },
|
|
62
|
-
{ key: 'sm', value: 'spacing-sm', label: 'Small (1rem)', size: '1rem' },
|
|
63
|
-
{ key: 'md', value: 'spacing-md', label: 'Medium (1.5rem)', size: '1.5rem' },
|
|
64
|
-
{ key: 'lg', value: 'spacing-lg', label: 'Large (2rem)', size: '2rem' },
|
|
65
|
-
{ key: 'xl', value: 'spacing-xl', label: 'Extra Large (3rem)', size: '3rem' },
|
|
66
|
-
{ key: '2xl', value: 'spacing-2xl', label: '2X Large (4rem)', size: '4rem' },
|
|
67
|
-
{ key: '3xl', value: 'spacing-3xl', label: '3X Large (6rem)', size: '6rem' },
|
|
68
|
-
],
|
|
69
|
-
},
|
|
70
|
-
semantic: {
|
|
71
|
-
label: 'Semantic',
|
|
72
|
-
tokens: [
|
|
73
|
-
{ key: 'content', value: 'spacing-content', label: 'Content', size: 'var(--wp--style--block-gap, 1.5rem)' },
|
|
74
|
-
{ key: 'section', value: 'spacing-section', label: 'Section', size: 'clamp(2rem, 5vw, 4rem)' },
|
|
75
|
-
{ key: 'container', value: 'spacing-container', label: 'Container', size: 'clamp(1rem, 3vw, 2rem)' },
|
|
76
|
-
],
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
typography: {
|
|
81
|
-
label: 'Typography',
|
|
82
|
-
children: {
|
|
83
|
-
fontSize: {
|
|
84
|
-
label: 'Font Sizes',
|
|
85
|
-
tokens: [
|
|
86
|
-
{ key: 'xs', value: 'text-xs', label: 'Extra Small (12px)' },
|
|
87
|
-
{ key: 'sm', value: 'text-sm', label: 'Small (14px)' },
|
|
88
|
-
{ key: 'base', value: 'text-base', label: 'Base (16px)' },
|
|
89
|
-
{ key: 'lg', value: 'text-lg', label: 'Large (18px)' },
|
|
90
|
-
{ key: 'xl', value: 'text-xl', label: 'Extra Large (20px)' },
|
|
91
|
-
{ key: '2xl', value: 'text-2xl', label: '2X Large (24px)' },
|
|
92
|
-
],
|
|
93
|
-
},
|
|
94
|
-
fontWeight: {
|
|
95
|
-
label: 'Font Weights',
|
|
96
|
-
tokens: [
|
|
97
|
-
{ key: 'light', value: 'font-light', label: 'Light (300)' },
|
|
98
|
-
{ key: 'normal', value: 'font-normal', label: 'Normal (400)' },
|
|
99
|
-
{ key: 'medium', value: 'font-medium', label: 'Medium (500)' },
|
|
100
|
-
{ key: 'semibold', value: 'font-semibold', label: 'Semibold (600)' },
|
|
101
|
-
{ key: 'bold', value: 'font-bold', label: 'Bold (700)' },
|
|
102
|
-
],
|
|
103
|
-
},
|
|
104
|
-
},
|
|
105
|
-
},
|
|
106
|
-
sizing: {
|
|
107
|
-
label: 'Sizing',
|
|
108
|
-
children: {
|
|
109
|
-
containers: {
|
|
110
|
-
label: 'Container Widths',
|
|
111
|
-
tokens: [
|
|
112
|
-
{ key: 'narrow', value: 'container-narrow', label: 'Narrow (600px)' },
|
|
113
|
-
{ key: 'normal', value: 'container-normal', label: 'Normal (1200px)' },
|
|
114
|
-
{ key: 'wide', value: 'container-wide', label: 'Wide (1600px)' },
|
|
115
|
-
{ key: 'full', value: 'container-full', label: 'Full Width' },
|
|
116
|
-
],
|
|
117
|
-
},
|
|
118
|
-
borderRadius: {
|
|
119
|
-
label: 'Border Radius',
|
|
120
|
-
tokens: [
|
|
121
|
-
{ key: 'none', value: 'radius-none', label: 'None' },
|
|
122
|
-
{ key: 'sm', value: 'radius-sm', label: 'Small' },
|
|
123
|
-
{ key: 'md', value: 'radius-md', label: 'Medium' },
|
|
124
|
-
{ key: 'lg', value: 'radius-lg', label: 'Large' },
|
|
125
|
-
{ key: 'full', value: 'radius-full', label: 'Full (Pill)' },
|
|
126
|
-
],
|
|
127
|
-
},
|
|
128
|
-
},
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Get all token groups, merging built-ins with theme.json tokens.
|
|
134
|
-
* Theme tokens override built-ins on a path collision.
|
|
135
|
-
*
|
|
136
|
-
* @param {object} [themeTokens] Theme token tree. Defaults to the legacy
|
|
137
|
-
* `window.gcbLite.tokens` global so non-React callers (and the unmigrated
|
|
138
|
-
* plugin) keep working; the SDK's useTokens() hook passes the value from
|
|
139
|
-
* GcbFieldsProvider instead.
|
|
140
|
-
*/
|
|
141
|
-
export function getAllTokenGroups(themeTokens) {
|
|
142
|
-
if (themeTokens === undefined) {
|
|
143
|
-
themeTokens = (typeof window !== 'undefined' && window.gcbLite?.tokens) || {};
|
|
144
|
-
}
|
|
145
|
-
const merged = { ...builtInTokenGroups };
|
|
146
|
-
|
|
147
|
-
Object.keys(themeTokens).forEach((category) => {
|
|
148
|
-
if (merged[category]) {
|
|
149
|
-
merged[category] = {
|
|
150
|
-
...merged[category],
|
|
151
|
-
children: {
|
|
152
|
-
...(merged[category].children || {}),
|
|
153
|
-
...(themeTokens[category].children || {}),
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
} else {
|
|
157
|
-
merged[category] = themeTokens[category];
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
return merged;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Resolve a token group path to its token list.
|
|
166
|
-
*
|
|
167
|
-
* @param {string} tokenGroup e.g. "spacing:scale", "custom:gap"
|
|
168
|
-
* @returns {Array|null}
|
|
169
|
-
*/
|
|
170
|
-
export function getTokenGroupTokens(tokenGroup) {
|
|
171
|
-
if (!tokenGroup || typeof tokenGroup !== 'string') return null;
|
|
172
|
-
const [categoryKey, subKey] = tokenGroup.split(':');
|
|
173
|
-
if (!categoryKey || !subKey) return null;
|
|
174
|
-
|
|
175
|
-
const all = getAllTokenGroups();
|
|
176
|
-
const category = all[categoryKey];
|
|
177
|
-
if (!category?.children) return null;
|
|
178
|
-
|
|
179
|
-
return category.children[subKey]?.tokens || null;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
/**
|
|
183
|
-
* Convert a token list to {label, value} options for a select/radio control.
|
|
184
|
-
*/
|
|
185
|
-
export function tokensToOptions(tokens) {
|
|
186
|
-
if (!Array.isArray(tokens)) return [];
|
|
187
|
-
return tokens.map((t) => ({ label: t.label, value: t.key }));
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* For spacing tokens: resolve the raw size value (e.g. "1rem").
|
|
192
|
-
* Accepts a full path ("spacing:scale:30"), a partial ("scale:30"),
|
|
193
|
-
* or just a key ("30") — searches in priority order.
|
|
194
|
-
*/
|
|
195
|
-
export function getSpacingSize(tokenKey) {
|
|
196
|
-
if (!tokenKey) return null;
|
|
197
|
-
const parts = tokenKey.split(':');
|
|
198
|
-
let categoryKey, subKey, key;
|
|
199
|
-
|
|
200
|
-
if (parts.length === 3) {
|
|
201
|
-
[categoryKey, subKey, key] = parts;
|
|
202
|
-
} else if (parts.length === 2) {
|
|
203
|
-
categoryKey = 'spacing';
|
|
204
|
-
[subKey, key] = parts;
|
|
205
|
-
} else {
|
|
206
|
-
// Bare key — search every spacing subcategory.
|
|
207
|
-
const spacing = getAllTokenGroups().spacing;
|
|
208
|
-
if (spacing?.children) {
|
|
209
|
-
for (const subCat of Object.values(spacing.children)) {
|
|
210
|
-
const t = subCat.tokens?.find((tok) => tok.key === tokenKey);
|
|
211
|
-
if (t?.size) return t.size;
|
|
212
|
-
if (t?.value) return t.value; // theme.json tokens use `value`
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return null;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
const cat = getAllTokenGroups()[categoryKey];
|
|
219
|
-
const tok = cat?.children?.[subKey]?.tokens?.find((t) => t.key === key);
|
|
220
|
-
return tok?.size || tok?.value || null;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Convert a spacing token to the WP CSS custom property.
|
|
225
|
-
* Falls back to var(--wp--preset--spacing--{key}) for unknown tokens.
|
|
226
|
-
*/
|
|
227
|
-
export function spacingTokenToCSSVar(tokenKey) {
|
|
228
|
-
if (!tokenKey) return null;
|
|
229
|
-
const parts = tokenKey.split(':');
|
|
230
|
-
const key = parts.length > 1 ? parts[parts.length - 1] : tokenKey;
|
|
231
|
-
return `var(--wp--preset--spacing--${key})`;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Resolve a token to its cssVar, preferring an explicit cssVar property
|
|
236
|
-
* (theme.json tokens have one), falling back to the spacing convention.
|
|
237
|
-
*/
|
|
238
|
-
export function tokenToCSSVar(token) {
|
|
239
|
-
if (!token) return null;
|
|
240
|
-
if (token.cssVar) return token.cssVar;
|
|
241
|
-
if (token.slug) return `var(--wp--preset--spacing--${token.slug})`;
|
|
242
|
-
return null;
|
|
243
|
-
}
|