@eightshift/frontend-libs-tailwind 1.3.3 → 1.4.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/.husky/pre-commit +0 -0
- package/CHANGELOG.md +12 -0
- package/blocks/init/src/Blocks/components/button/button.php +1 -1
- package/blocks/init/src/Blocks/components/button/components/button-editor.js +2 -2
- package/blocks/init/src/Blocks/components/card/card.php +7 -7
- package/blocks/init/src/Blocks/components/card/components/card-editor.js +12 -8
- package/blocks/init/src/Blocks/components/heading/components/heading-editor.js +2 -2
- package/blocks/init/src/Blocks/components/heading/components/heading-options.js +1 -1
- package/blocks/init/src/Blocks/components/heading/heading.php +1 -1
- package/blocks/init/src/Blocks/components/hero/components/hero-editor.js +3 -3
- package/blocks/init/src/Blocks/components/hero/hero.php +2 -2
- package/blocks/init/src/Blocks/components/icon/components/icon-editor.js +2 -2
- package/blocks/init/src/Blocks/components/icon/icon.php +1 -1
- package/blocks/init/src/Blocks/components/image/components/image-editor.js +2 -3
- package/blocks/init/src/Blocks/components/image/image.php +1 -1
- package/blocks/init/src/Blocks/components/list/components/list-editor.js +2 -2
- package/blocks/init/src/Blocks/components/list/list.php +1 -1
- package/blocks/init/src/Blocks/components/list/manifest.json +2 -2
- package/blocks/init/src/Blocks/components/modal/modal.php +5 -5
- package/blocks/init/src/Blocks/components/paragraph/components/paragraph-editor.js +2 -2
- package/blocks/init/src/Blocks/components/paragraph/paragraph.php +1 -1
- package/blocks/init/src/Blocks/components/quote/components/quote-editor.js +5 -5
- package/blocks/init/src/Blocks/components/quote/manifest.json +1 -1
- package/blocks/init/src/Blocks/components/quote/quote.php +4 -4
- package/blocks/init/src/Blocks/components/share/components/share-editor.js +3 -3
- package/blocks/init/src/Blocks/components/share/manifest.json +1 -1
- package/blocks/init/src/Blocks/components/share/share.php +3 -3
- package/blocks/init/src/Blocks/components/video/components/video-editor.js +2 -2
- package/blocks/init/src/Blocks/components/video/video.php +1 -1
- package/blocks/init/src/Blocks/custom/accordion-item/accordion-item.php +2 -2
- package/blocks/init/src/Blocks/custom/accordion-item/components/accordion-item-editor.js +5 -5
- package/blocks/init/src/Blocks/custom/accordion-item/manifest.json +4 -4
- package/blocks/init/src/Blocks/custom/carousel/carousel.php +2 -2
- package/blocks/init/src/Blocks/custom/carousel/components/carousel-editor.js +3 -3
- package/blocks/init/src/Blocks/custom/carousel/manifest.json +2 -2
- package/blocks/init/src/Blocks/custom/column/column-hooks.js +2 -2
- package/blocks/init/src/Blocks/custom/column/column.php +1 -1
- package/blocks/init/src/Blocks/custom/column/manifest.json +1 -1
- package/blocks/init/src/Blocks/custom/columns/columns.php +1 -1
- package/blocks/init/src/Blocks/custom/columns/components/columns-editor.js +2 -2
- package/blocks/init/src/Blocks/custom/featured-content/components/featured-content-editor.js +2 -2
- package/blocks/init/src/Blocks/custom/featured-content/featured-content.php +2 -2
- package/blocks/init/src/Blocks/custom/heading/components/heading-editor.js +2 -2
- package/blocks/init/src/Blocks/custom/heading/heading.php +1 -1
- package/blocks/init/src/Blocks/custom/list/components/list-editor.js +2 -2
- package/blocks/init/src/Blocks/custom/list/list.php +1 -1
- package/blocks/init/src/Blocks/custom/map/components/map-components.js +2 -2
- package/blocks/init/src/Blocks/custom/map/map.php +1 -1
- package/blocks/init/src/Blocks/custom/paragraph/components/paragraph-editor.js +2 -2
- package/blocks/init/src/Blocks/custom/paragraph/paragraph.php +1 -1
- package/blocks/init/src/Blocks/custom/site-footer/components/site-footer-editor.js +10 -10
- package/blocks/init/src/Blocks/custom/site-footer/manifest.json +2 -2
- package/blocks/init/src/Blocks/custom/site-footer/site-footer.php +9 -9
- package/blocks/init/src/Blocks/custom/site-navigation/components/site-navigation-editor.js +5 -5
- package/blocks/init/src/Blocks/custom/site-navigation/manifest.json +3 -3
- package/blocks/init/src/Blocks/custom/site-navigation/site-navigation.php +11 -11
- package/blocks/init/src/Blocks/custom/table-of-contents/components/table-of-contents-editor.js +3 -3
- package/blocks/init/src/Blocks/custom/table-of-contents/table-of-contents.php +2 -2
- package/blocks/init/src/Blocks/wrapper/components/wrapper-editor.js +2 -2
- package/blocks/init/src/Blocks/wrapper/manifest.json +2 -2
- package/blocks/init/src/Blocks/wrapper/wrapper.php +1 -1
- package/linters/stylelint.config.js +7 -0
- package/package.json +91 -92
- package/schemas/block.json +129 -20
- package/schemas/component.json +129 -20
- package/schemas/globalManifest.json +1 -1
- package/scripts/editor/tailwindcss.js +209 -0
package/schemas/component.json
CHANGED
|
@@ -101,7 +101,7 @@
|
|
|
101
101
|
"properties": {
|
|
102
102
|
"attributes": {
|
|
103
103
|
"type": "object",
|
|
104
|
-
"description": "Set the
|
|
104
|
+
"description": "Set the attributes for the block example"
|
|
105
105
|
},
|
|
106
106
|
"innerBlocks": {
|
|
107
107
|
"type": "array",
|
|
@@ -119,18 +119,32 @@
|
|
|
119
119
|
},
|
|
120
120
|
"tailwind": {
|
|
121
121
|
"type": "object",
|
|
122
|
-
"description": "Defines shared Tailwind configs for the component.
|
|
122
|
+
"description": "Defines shared Tailwind configs for the component. Allows defining flexible parts, option-based classes, and combinations to add various styles.",
|
|
123
123
|
"properties": {
|
|
124
124
|
"base": {
|
|
125
|
+
"deprecated": true,
|
|
125
126
|
"type": "object",
|
|
126
|
-
"description": "Base classes for the main part of the component.",
|
|
127
|
+
"description": "DEPRECATED - move into parts (part should be named 'base')! Base classes for the main part of the component.",
|
|
127
128
|
"properties": {
|
|
128
129
|
"twClasses": {
|
|
129
|
-
"type": [
|
|
130
|
+
"type": [
|
|
131
|
+
"string",
|
|
132
|
+
"array"
|
|
133
|
+
],
|
|
130
134
|
"description": "Classnames to apply. An array of classnames (strings) can also be provided for improved manifest readability."
|
|
131
135
|
},
|
|
132
136
|
"twClassesEditor": {
|
|
133
|
-
"type": [
|
|
137
|
+
"type": [
|
|
138
|
+
"string",
|
|
139
|
+
"array"
|
|
140
|
+
],
|
|
141
|
+
"description": "Editor-specific classnames to apply. These classes are added to 'twClassesEditorOnly'/'twClasses'. An array of classnames (strings) can also be provided for improved manifest readability."
|
|
142
|
+
},
|
|
143
|
+
"twClassesEditorOnly": {
|
|
144
|
+
"type": [
|
|
145
|
+
"string",
|
|
146
|
+
"array"
|
|
147
|
+
],
|
|
134
148
|
"description": "Editor-specific classnames to apply. Overrides 'twClasses'. An array of classnames (strings) can also be provided for improved manifest readability."
|
|
135
149
|
}
|
|
136
150
|
},
|
|
@@ -138,7 +152,7 @@
|
|
|
138
152
|
},
|
|
139
153
|
"options": {
|
|
140
154
|
"type": "object",
|
|
141
|
-
"description": "Per-attribute classes, added to
|
|
155
|
+
"description": "Per-attribute classes, added to one or more parts, or different classes per part. Key represents the attribute name.",
|
|
142
156
|
"additionalProperties": {
|
|
143
157
|
"$ref": "#/$defs/twOptionsEntry"
|
|
144
158
|
},
|
|
@@ -146,7 +160,7 @@
|
|
|
146
160
|
},
|
|
147
161
|
"parts": {
|
|
148
162
|
"type": "object",
|
|
149
|
-
"description": "
|
|
163
|
+
"description": "Parts of the component. Key represents the part name.",
|
|
150
164
|
"additionalProperties": {
|
|
151
165
|
"$ref": "#/$defs/twPartEntry"
|
|
152
166
|
},
|
|
@@ -154,7 +168,7 @@
|
|
|
154
168
|
},
|
|
155
169
|
"combinations": {
|
|
156
170
|
"type": "array",
|
|
157
|
-
"description": "Conditionally applied classes, depending on the set attribute values. Added to the
|
|
171
|
+
"description": "Conditionally applied classes, depending on the set attribute values. Added to the chosen part, or different classes per part.",
|
|
158
172
|
"items": {
|
|
159
173
|
"type": "object",
|
|
160
174
|
"properties": {
|
|
@@ -165,13 +179,21 @@
|
|
|
165
179
|
"[a-zA-Z]": {
|
|
166
180
|
"anyOf": [
|
|
167
181
|
{
|
|
168
|
-
"type": [
|
|
182
|
+
"type": [
|
|
183
|
+
"string",
|
|
184
|
+
"number",
|
|
185
|
+
"boolean"
|
|
186
|
+
],
|
|
169
187
|
"minLength": 1
|
|
170
188
|
},
|
|
171
189
|
{
|
|
172
190
|
"type": "array",
|
|
173
191
|
"items": {
|
|
174
|
-
"type": [
|
|
192
|
+
"type": [
|
|
193
|
+
"string",
|
|
194
|
+
"number",
|
|
195
|
+
"boolean"
|
|
196
|
+
],
|
|
175
197
|
"minLength": 1
|
|
176
198
|
}
|
|
177
199
|
}
|
|
@@ -180,17 +202,36 @@
|
|
|
180
202
|
}
|
|
181
203
|
},
|
|
182
204
|
"twClasses": {
|
|
183
|
-
"type": [
|
|
205
|
+
"type": [
|
|
206
|
+
"string",
|
|
207
|
+
"array"
|
|
208
|
+
],
|
|
184
209
|
"description": "Classnames to apply if all conditions match. Key is the attribute value, value is the classnames to apply. An array of classnames (strings) can also be provided for improved manifest readability."
|
|
185
210
|
},
|
|
186
211
|
"twClassesEditor": {
|
|
187
|
-
"type": [
|
|
212
|
+
"type": [
|
|
213
|
+
"string",
|
|
214
|
+
"array"
|
|
215
|
+
],
|
|
216
|
+
"description": "Editor-specific classnames to apply if all conditions match. These classes are added to 'twClassesEditorOnly'/'twClasses'. Key is the attribute value, value is the classnames to apply. An array of classnames (strings) can also be provided for improved manifest readability."
|
|
217
|
+
},
|
|
218
|
+
"twClassesEditorOnly": {
|
|
219
|
+
"type": [
|
|
220
|
+
"string",
|
|
221
|
+
"array"
|
|
222
|
+
],
|
|
188
223
|
"description": "Editor-specific classnames to apply if all conditions match. Overrides 'twClasses'. Key is the attribute value, value is the classnames to apply. An array of classnames (strings) can also be provided for improved manifest readability."
|
|
224
|
+
},
|
|
225
|
+
"output": {
|
|
226
|
+
"type": "object",
|
|
227
|
+
"description": "Allows outputting different classes per part for this combination. Key is the part name, value is an object with class definitions ('twClasses'/'twClassesEditor'/'twClassesEditorOnly'). Overrides 'twClasses'/'twClassesEditor'/'twClassesEditorOnly' if set.",
|
|
228
|
+
"additionalProperties": {
|
|
229
|
+
"$ref": "#/$defs/twPartEntry"
|
|
230
|
+
}
|
|
189
231
|
}
|
|
190
232
|
},
|
|
191
233
|
"required": [
|
|
192
|
-
"attributes"
|
|
193
|
-
"twClasses"
|
|
234
|
+
"attributes"
|
|
194
235
|
]
|
|
195
236
|
},
|
|
196
237
|
"minLength": 1
|
|
@@ -208,11 +249,24 @@
|
|
|
208
249
|
"type": "object",
|
|
209
250
|
"properties": {
|
|
210
251
|
"twClasses": {
|
|
211
|
-
"type": [
|
|
252
|
+
"type": [
|
|
253
|
+
"string",
|
|
254
|
+
"array"
|
|
255
|
+
],
|
|
212
256
|
"description": "Classnames to apply. An array of classnames (strings) can also be provided for improved manifest readability."
|
|
213
257
|
},
|
|
214
258
|
"twClassesEditor": {
|
|
215
|
-
"type": [
|
|
259
|
+
"type": [
|
|
260
|
+
"string",
|
|
261
|
+
"array"
|
|
262
|
+
],
|
|
263
|
+
"description": "Editor-specific classnames to apply. These classes are added to 'twClassesEditorOnly'/'twClasses'. An array of classnames (strings) can also be provided for improved manifest readability."
|
|
264
|
+
},
|
|
265
|
+
"twClassesEditorOnly": {
|
|
266
|
+
"type": [
|
|
267
|
+
"string",
|
|
268
|
+
"array"
|
|
269
|
+
],
|
|
216
270
|
"description": "Editor-specific classnames to apply. Overrides 'twClasses'. An array of classnames (strings) can also be provided for improved manifest readability."
|
|
217
271
|
}
|
|
218
272
|
}
|
|
@@ -224,19 +278,74 @@
|
|
|
224
278
|
"type": "object",
|
|
225
279
|
"description": "Classnames to apply. Key is the attribute value, value is the classnames to apply. An array of classnames (strings) can also be provided for improved manifest readability.",
|
|
226
280
|
"additionalProperties": {
|
|
227
|
-
"type": [
|
|
281
|
+
"type": [
|
|
282
|
+
"string",
|
|
283
|
+
"array"
|
|
284
|
+
]
|
|
228
285
|
}
|
|
229
286
|
},
|
|
230
287
|
"twClassesEditor": {
|
|
288
|
+
"type": "object",
|
|
289
|
+
"description": "Editor-specific classnames to apply. These classes are added to 'twClassesEditorOnly'/'twClasses'. Key is the attribute value, value is the classnames to apply. An array of classnames (strings) can also be provided for improved manifest readability.",
|
|
290
|
+
"additionalProperties": {
|
|
291
|
+
"type": [
|
|
292
|
+
"string",
|
|
293
|
+
"array"
|
|
294
|
+
]
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
"twClassesEditorOnly": {
|
|
231
298
|
"type": "object",
|
|
232
299
|
"description": "Editor-specific classnames to apply. Overrides 'twClasses'. Key is the attribute value, value is the classnames to apply. An array of classnames (strings) can also be provided for improved manifest readability.",
|
|
233
300
|
"additionalProperties": {
|
|
234
|
-
"type": [
|
|
301
|
+
"type": [
|
|
302
|
+
"string",
|
|
303
|
+
"array"
|
|
304
|
+
]
|
|
235
305
|
}
|
|
236
306
|
},
|
|
237
307
|
"part": {
|
|
238
|
-
"type":
|
|
239
|
-
"description": "Part to assign the class output to. If not specified, the classes are added to the base class.
|
|
308
|
+
"type": "string",
|
|
309
|
+
"description": "Part to assign the class output to. If not specified, the classes are added to the base class. Specify multiple parts by separating their names with commas. NOTE: if classes are specified per-part, this list will be ignored!"
|
|
310
|
+
},
|
|
311
|
+
"responsive": {
|
|
312
|
+
"type": "boolean",
|
|
313
|
+
"description": "Set to 'true' if the option has the ability to have per-breakpoint values."
|
|
314
|
+
}
|
|
315
|
+
},
|
|
316
|
+
"additionalProperties": {
|
|
317
|
+
"type": "object",
|
|
318
|
+
"properties": {
|
|
319
|
+
"twClasses": {
|
|
320
|
+
"type": "object",
|
|
321
|
+
"description": "Classnames to apply. Key is the attribute value, value is the classnames to apply. An array of classnames (strings) can also be provided for improved manifest readability.",
|
|
322
|
+
"additionalProperties": {
|
|
323
|
+
"type": [
|
|
324
|
+
"string",
|
|
325
|
+
"array"
|
|
326
|
+
]
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
"twClassesEditor": {
|
|
330
|
+
"type": "object",
|
|
331
|
+
"description": "Editor-specific classnames to apply. These classes are added to 'twClassesEditorOnly'/'twClasses'. Key is the attribute value, value is the classnames to apply. An array of classnames (strings) can also be provided for improved manifest readability.",
|
|
332
|
+
"additionalProperties": {
|
|
333
|
+
"type": [
|
|
334
|
+
"string",
|
|
335
|
+
"array"
|
|
336
|
+
]
|
|
337
|
+
}
|
|
338
|
+
},
|
|
339
|
+
"twClassesEditorOnly": {
|
|
340
|
+
"type": "object",
|
|
341
|
+
"description": "Editor-specific classnames to apply. Overrides 'twClasses'. Key is the attribute value, value is the classnames to apply. An array of classnames (strings) can also be provided for improved manifest readability.",
|
|
342
|
+
"additionalProperties": {
|
|
343
|
+
"type": [
|
|
344
|
+
"string",
|
|
345
|
+
"array"
|
|
346
|
+
]
|
|
347
|
+
}
|
|
348
|
+
}
|
|
240
349
|
}
|
|
241
350
|
}
|
|
242
351
|
}
|
|
@@ -12,6 +12,8 @@ import { clsx } from '@eightshift/ui-components/utilities';
|
|
|
12
12
|
*
|
|
13
13
|
* @returns {string} Output classes.
|
|
14
14
|
*
|
|
15
|
+
* @deprecated Since 1.4.0. Use `tailwindClasses` instead.
|
|
16
|
+
*
|
|
15
17
|
* @example
|
|
16
18
|
* const classes = getTwPart('intro', manifest);
|
|
17
19
|
*
|
|
@@ -46,6 +48,8 @@ export const getTwPart = (part, manifest, ...custom) => {
|
|
|
46
48
|
*
|
|
47
49
|
* @returns {string} Output classes.
|
|
48
50
|
*
|
|
51
|
+
* @deprecated Since 1.4.0. Use `tailwindClasses` instead.
|
|
52
|
+
*
|
|
49
53
|
* @example
|
|
50
54
|
* const classes = getTwPart('intro', manifest);
|
|
51
55
|
*
|
|
@@ -118,6 +122,8 @@ export const getTwDynamicPart = (part, attributes, manifest, ...custom) => {
|
|
|
118
122
|
*
|
|
119
123
|
* @returns {string} Output classes
|
|
120
124
|
*
|
|
125
|
+
* @deprecated Since 1.4.0. Use `tailwindClasses` instead.
|
|
126
|
+
*
|
|
121
127
|
* @example
|
|
122
128
|
* const classes = getTwClasses(attributes, manifest);
|
|
123
129
|
*
|
|
@@ -341,3 +347,206 @@ const combineAndRemoveDuplicates = (results) => {
|
|
|
341
347
|
return acc;
|
|
342
348
|
}, {});
|
|
343
349
|
};
|
|
350
|
+
|
|
351
|
+
const unifyClasses = (classes) => {
|
|
352
|
+
if (Array.isArray(classes)) {
|
|
353
|
+
return clsx(...classes);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
return classes.trim();
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
const processOption = (partName, optionValue, defs) => {
|
|
360
|
+
let optionClasses = [];
|
|
361
|
+
|
|
362
|
+
const isResponsive = defs?.responsive === true;
|
|
363
|
+
const itemPartName = defs?.part ?? 'base';
|
|
364
|
+
const isSingleValue = 'twClasses' in defs || 'twClassesEditor' in defs || 'twClassesEditorOnly' in defs;
|
|
365
|
+
|
|
366
|
+
// Part checks.
|
|
367
|
+
if (!isSingleValue && typeof defs?.[partName] === 'undefined') {
|
|
368
|
+
return '';
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (isSingleValue && !itemPartName.includes(partName)) {
|
|
372
|
+
return '';
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Non-responsive options.
|
|
376
|
+
if (!isResponsive) {
|
|
377
|
+
const rawValueBase =
|
|
378
|
+
defs?.twClassesEditorOnly?.[optionValue] ??
|
|
379
|
+
defs?.twClasses?.[optionValue] ??
|
|
380
|
+
defs?.[partName]?.twClassesEditorOnly?.[optionValue] ??
|
|
381
|
+
defs?.[partName]?.twClasses?.[optionValue] ??
|
|
382
|
+
'';
|
|
383
|
+
|
|
384
|
+
const rawValueEditor =
|
|
385
|
+
defs?.twClassesEditor?.[optionValue] ?? defs?.[partName]?.twClassesEditor?.[optionValue] ?? '';
|
|
386
|
+
|
|
387
|
+
return clsx(unifyClasses(rawValueBase), unifyClasses(rawValueEditor));
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Responsive options.
|
|
391
|
+
const breakpoints = Object.keys(optionValue).filter((key) => key !== '_desktopFirst');
|
|
392
|
+
|
|
393
|
+
for (const breakpoint of breakpoints) {
|
|
394
|
+
const breakpointValue = optionValue?.[breakpoint];
|
|
395
|
+
|
|
396
|
+
if (typeof breakpointValue === 'undefined') {
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const rawValueBase =
|
|
401
|
+
defs?.twClassesEditorOnly?.[breakpointValue] ??
|
|
402
|
+
defs?.twClasses?.[breakpointValue] ??
|
|
403
|
+
defs?.[partName]?.twClassesEditorOnly?.[breakpointValue] ??
|
|
404
|
+
defs?.[partName]?.twClasses?.[breakpointValue] ??
|
|
405
|
+
'';
|
|
406
|
+
|
|
407
|
+
const rawValueEditor =
|
|
408
|
+
defs?.twClassesEditor?.[breakpointValue] ?? defs?.[partName]?.twClassesEditor?.[breakpointValue] ?? '';
|
|
409
|
+
|
|
410
|
+
if (breakpoint === '_default') {
|
|
411
|
+
optionClasses = [...optionClasses, unifyClasses(rawValueBase), unifyClasses(rawValueEditor)];
|
|
412
|
+
|
|
413
|
+
continue;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
const splitClassesBase = unifyClasses(rawValueBase)
|
|
417
|
+
.split(' ')
|
|
418
|
+
.filter(Boolean)
|
|
419
|
+
.map((currentClass) => `${breakpoint}:${currentClass}`);
|
|
420
|
+
|
|
421
|
+
const splitClassesEditor = unifyClasses(rawValueEditor)
|
|
422
|
+
.split(' ')
|
|
423
|
+
.filter(Boolean)
|
|
424
|
+
.map((currentClass) => `${breakpoint}:${currentClass}`);
|
|
425
|
+
|
|
426
|
+
optionClasses = [...optionClasses, unifyClasses(splitClassesBase), unifyClasses(splitClassesEditor)];
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return unifyClasses(optionClasses);
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
const processCombination = (partName, combo, attributes, manifest) => {
|
|
433
|
+
let matches = true;
|
|
434
|
+
|
|
435
|
+
for (const [attributeName, allowedValue] of Object.entries(combo?.attributes ?? {})) {
|
|
436
|
+
const optionValue = checkAttr(attributeName, attributes, manifest, true);
|
|
437
|
+
|
|
438
|
+
if (Array.isArray(allowedValue) && !allowedValue.includes(optionValue)) {
|
|
439
|
+
matches = false;
|
|
440
|
+
break;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
if (optionValue !== allowedValue) {
|
|
444
|
+
matches = false;
|
|
445
|
+
break;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
if (!matches) {
|
|
450
|
+
return '';
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const itemPartName = combo?.part ?? 'base';
|
|
454
|
+
const isSingleValue = 'twClasses' in combo || 'twClassesEditor' in combo || 'twClassesEditorOnly' in combo;
|
|
455
|
+
|
|
456
|
+
if (isSingleValue && !partName.includes(itemPartName)) {
|
|
457
|
+
return '';
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
const rawValueBase =
|
|
461
|
+
combo?.output?.[partName]?.twClassesEditorOnly ??
|
|
462
|
+
combo?.output?.[partName]?.twClasses ??
|
|
463
|
+
combo?.twClassesEditorOnly ??
|
|
464
|
+
combo?.twClasses ??
|
|
465
|
+
'';
|
|
466
|
+
|
|
467
|
+
const rawValueEditor = combo?.output?.[partName]?.twClassesEditor ?? combo?.twClassesEditor ?? '';
|
|
468
|
+
|
|
469
|
+
if (!Array.isArray(rawValueBase) && typeof rawValueBase !== 'string') {
|
|
470
|
+
throw new Error(
|
|
471
|
+
'Combination classes/editor-only classes were not defined correctly. Please check the combination definition in the manifest.',
|
|
472
|
+
);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if (!Array.isArray(rawValueEditor) && typeof rawValueEditor !== 'string') {
|
|
476
|
+
throw new Error(
|
|
477
|
+
'Combination editor classes were not defined correctly. Please check the combination definition in the manifest.',
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
return clsx(unifyClasses(rawValueBase), unifyClasses(rawValueEditor));
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* Get Tailwind classes from attributes and manifest.
|
|
486
|
+
*
|
|
487
|
+
* @param {string} part - Part to get classes for.
|
|
488
|
+
* @param {Object<string, mixed>} attributes - Component/block attributes.
|
|
489
|
+
* @param {Object<string, mixed>} manifest - Component/block manifest data.
|
|
490
|
+
* @param {...string?} custom - Custom classes to include in the output.
|
|
491
|
+
*
|
|
492
|
+
* @returns {string} Output classes
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* const classes = tailwindClasses(attributes, manifest);
|
|
496
|
+
*
|
|
497
|
+
* @example
|
|
498
|
+
* const classes = tailwindClasses(attributes, manifest, 'p-4 bg-gray-100');
|
|
499
|
+
*
|
|
500
|
+
*/
|
|
501
|
+
export const tailwindClasses = (part, attributes, manifest, ...custom) => {
|
|
502
|
+
// If nothing is set, return custom classes as a fallback.
|
|
503
|
+
if (!attributes || !manifest || !manifest?.tailwind || Object.keys(manifest?.tailwind ?? {}).length === 0) {
|
|
504
|
+
return clsx(...custom);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
const allParts = ['base', ...Object.keys(manifest?.tailwind?.parts ?? {})];
|
|
508
|
+
|
|
509
|
+
let partName = 'base';
|
|
510
|
+
|
|
511
|
+
if (part?.length > 0 && typeof manifest.tailwind.parts[part] !== 'undefined' && allParts.includes(part)) {
|
|
512
|
+
partName = part;
|
|
513
|
+
} else if (part !== 'base') {
|
|
514
|
+
throw new Error(`Part '${part}' is not defined in the manifest.`);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// Base classes.
|
|
518
|
+
const baseBaseClasses = manifest?.tailwind?.parts?.[partName]?.twClassesEditorOnly ??
|
|
519
|
+
manifest?.tailwind?.parts?.[partName]?.twClasses ??
|
|
520
|
+
manifest?.tailwind?.base?.twClassesEditorOnly ??
|
|
521
|
+
manifest?.tailwind?.base?.twClasses ?? [''];
|
|
522
|
+
const baseEditorClasses = manifest?.tailwind?.parts?.[partName]?.twClassesEditor ??
|
|
523
|
+
manifest?.tailwind?.base?.twClassesEditor ?? [''];
|
|
524
|
+
|
|
525
|
+
// Option classes.
|
|
526
|
+
const options = manifest?.tailwind?.options ?? {};
|
|
527
|
+
|
|
528
|
+
let optionClasses = [];
|
|
529
|
+
|
|
530
|
+
for (const [attributeName, defs] of Object.entries(options)) {
|
|
531
|
+
const optionValue = checkAttr(attributeName, attributes, manifest, true);
|
|
532
|
+
|
|
533
|
+
optionClasses = [...optionClasses, processOption(partName, optionValue, defs)];
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// Combinations.
|
|
537
|
+
const combinations = manifest?.tailwind?.combinations ?? [];
|
|
538
|
+
|
|
539
|
+
let combinationClasses = [];
|
|
540
|
+
|
|
541
|
+
for (const combo of combinations) {
|
|
542
|
+
combinationClasses = [...combinationClasses, processCombination(partName, combo, attributes, manifest)];
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
return clsx(
|
|
546
|
+
unifyClasses(baseBaseClasses),
|
|
547
|
+
unifyClasses(baseEditorClasses),
|
|
548
|
+
...optionClasses,
|
|
549
|
+
...combinationClasses,
|
|
550
|
+
...custom,
|
|
551
|
+
);
|
|
552
|
+
};
|