@eightshift/frontend-libs-tailwind 1.0.0 → 1.1.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 +15 -1
- package/blocks/init/assets/fonts/fraunces-italic-latin-extended.woff2 +0 -0
- package/blocks/init/assets/fonts/fraunces-italic-latin.woff2 +0 -0
- package/blocks/init/assets/fonts/fraunces-latin-extended.woff2 +0 -0
- package/blocks/init/assets/fonts/fraunces-latin.woff2 +0 -0
- package/blocks/init/assets/fonts/noto-sans-italic-latin-extended.woff2 +0 -0
- package/blocks/init/assets/fonts/noto-sans-italic-latin.woff2 +0 -0
- package/blocks/init/assets/fonts/noto-sans-latin-extended.woff2 +0 -0
- package/blocks/init/assets/fonts/noto-sans-latin.woff2 +0 -0
- package/blocks/init/src/Blocks/assets/scripts/shared.js +1 -3
- package/blocks/init/src/Blocks/assets/styles/editor/editor-overrides.css +1 -1
- package/blocks/init/src/Blocks/assets/styles/fonts.css +90 -0
- package/blocks/init/src/Blocks/assets/styles/tailwind.css +1 -5
- package/blocks/init/src/Blocks/components/admin-theme-options/assets-admin/pages/parts.js +1 -0
- package/blocks/init/src/Blocks/components/button/components/button-editor.js +1 -5
- package/blocks/init/src/Blocks/components/button/components/button-options.js +2 -21
- package/blocks/init/src/Blocks/components/button/manifest.json +8 -8
- package/blocks/init/src/Blocks/components/card/components/card-editor.js +1 -2
- package/blocks/init/src/Blocks/components/card/components/card-options.js +0 -1
- package/blocks/init/src/Blocks/components/heading/components/heading-editor.js +1 -5
- package/blocks/init/src/Blocks/components/image/components/image-editor.js +1 -7
- package/blocks/init/src/Blocks/components/image/components/image-options.js +3 -17
- package/blocks/init/src/Blocks/components/list/components/list-options.js +1 -3
- package/blocks/init/src/Blocks/components/load-more/assets/load-more.js +1 -2
- package/blocks/init/src/Blocks/components/load-more/components/load-more-options.js +1 -0
- package/blocks/init/src/Blocks/components/modal/assets/index.js +7 -9
- package/blocks/init/src/Blocks/components/paragraph/components/paragraph-options.js +1 -3
- package/blocks/init/src/Blocks/components/paragraph/manifest.json +14 -16
- package/blocks/init/src/Blocks/components/post-header/post-header.php +1 -1
- package/blocks/init/src/Blocks/components/share/assets/index.js +1 -5
- package/blocks/init/src/Blocks/components/share/components/share-editor.js +7 -4
- package/blocks/init/src/Blocks/components/share/components/share-options.js +2 -11
- package/blocks/init/src/Blocks/components/video/components/video-editor.js +2 -4
- package/blocks/init/src/Blocks/components/video/components/video-options.js +5 -27
- package/blocks/init/src/Blocks/custom/accordion/assets/index.js +1 -1
- package/blocks/init/src/Blocks/custom/accordion/components/accordion-editor.js +6 -1
- package/blocks/init/src/Blocks/custom/carousel/assets/pagination.js +3 -8
- package/blocks/init/src/Blocks/custom/column/components/column-editor.js +4 -1
- package/blocks/init/src/Blocks/custom/column/components/column-options.js +5 -12
- package/blocks/init/src/Blocks/custom/columns/components/columns-editor.js +2 -6
- package/blocks/init/src/Blocks/custom/featured-content/components/featured-content-options.js +18 -30
- package/blocks/init/src/Blocks/custom/featured-content/partials/cards.php +5 -5
- package/blocks/init/src/Blocks/custom/group/components/group-editor.js +1 -3
- package/blocks/init/src/Blocks/custom/heading/heading-transforms.js +1 -0
- package/blocks/init/src/Blocks/custom/map/assets/map-controller.js +0 -1
- package/blocks/init/src/Blocks/custom/map/components/map-components.js +3 -3
- package/blocks/init/src/Blocks/custom/map/components/map-editor.js +2 -12
- package/blocks/init/src/Blocks/custom/map/components/map-options.js +10 -46
- package/blocks/init/src/Blocks/custom/paragraph/paragraph-transforms.js +1 -0
- package/blocks/init/src/Blocks/custom/site-footer/components/site-footer-options.js +1 -3
- package/blocks/init/src/Blocks/custom/table-of-contents/components/table-of-contents-editor.js +1 -1
- package/blocks/init/src/Blocks/wrapper/components/wrapper-options.js +4 -19
- package/blocks/init/src/Blocks/wrapper/wrapper.js +1 -4
- package/linters/base.config.mjs +1 -1
- package/linters/eslint.config.mjs +1 -2
- package/linters/stylelint.config.js +9 -13
- package/package.json +92 -92
- package/schemas/block.json +4 -0
- package/schemas/component.json +4 -0
- package/scripts/components/block-inserter.js +8 -14
- package/scripts/components/file-picker.js +42 -39
- package/scripts/components/index.js +1 -0
- package/scripts/components/link-section-editor.js +6 -2
- package/scripts/components/picker-placeholder.js +109 -0
- package/scripts/components/server-side-render.js +2 -4
- package/scripts/components/settings/settings.js +3 -14
- package/scripts/components/settings/use-theme-options.js +2 -2
- package/scripts/editor/attributes.js +3 -9
- package/scripts/editor/colors.js +43 -41
- package/scripts/editor/editor.js +9 -16
- package/scripts/editor/fetch.js +26 -19
- package/scripts/editor/hooks.js +1 -0
- package/scripts/editor/options.js +2 -4
- package/scripts/editor/registration.js +51 -128
- package/scripts/editor/tailwindcss.js +118 -37
- package/scripts/helpers/breakpoints.js +3 -8
- package/scripts/helpers/cookies.js +2 -1
- package/scripts/helpers/index.js +1 -7
- package/scripts/index.js +2 -0
- package/scripts/plugins/yoast-seo.js +2 -3
- package/linters/ignore-gitignored.mjs +0 -9
|
@@ -57,7 +57,6 @@ export const registerBlocks = (
|
|
|
57
57
|
deprecationsComponentPath = null,
|
|
58
58
|
overridesComponentPath = null,
|
|
59
59
|
) => {
|
|
60
|
-
|
|
61
60
|
const componentsManifest = componentsManifestPath.keys().map(componentsManifestPath);
|
|
62
61
|
const blocksManifests = blocksManifestPath.keys().map(blocksManifestPath);
|
|
63
62
|
|
|
@@ -76,9 +75,7 @@ export const registerBlocks = (
|
|
|
76
75
|
|
|
77
76
|
// Iterate blocks to register.
|
|
78
77
|
blocksManifests.map((blockManifest) => {
|
|
79
|
-
const {
|
|
80
|
-
active = true,
|
|
81
|
-
} = blockManifest;
|
|
78
|
+
const { active = true } = blockManifest;
|
|
82
79
|
|
|
83
80
|
// If block has active key set to false the block will not show in the block editor.
|
|
84
81
|
if (active) {
|
|
@@ -117,19 +114,12 @@ export const registerBlocks = (
|
|
|
117
114
|
const blockOverridesComponent = getBlockGenericComponent(blockManifest.blockName, overridesComponentPath, 'overrides');
|
|
118
115
|
|
|
119
116
|
if (blockOverridesComponent !== null) {
|
|
120
|
-
blockManifest = Object.assign(blockManifest, blockOverridesComponent);
|
|
117
|
+
blockManifest = Object.assign(blockManifest, blockOverridesComponent);
|
|
121
118
|
}
|
|
122
119
|
}
|
|
123
120
|
|
|
124
121
|
// Pass data to registerBlock helper to get final output for registerBlockType.
|
|
125
|
-
const blockDetails = registerBlock(
|
|
126
|
-
globalManifest,
|
|
127
|
-
wrapperManifest,
|
|
128
|
-
componentsManifest,
|
|
129
|
-
blockManifest,
|
|
130
|
-
wrapperComponent,
|
|
131
|
-
blockComponent
|
|
132
|
-
);
|
|
122
|
+
const blockDetails = registerBlock(globalManifest, wrapperManifest, componentsManifest, blockManifest, wrapperComponent, blockComponent);
|
|
133
123
|
|
|
134
124
|
// Format the 'deprecated' attribute details to match the format Gutenberg wants.
|
|
135
125
|
if (blockDetails?.options?.deprecated) {
|
|
@@ -154,7 +144,7 @@ export const registerBlocks = (
|
|
|
154
144
|
...deprecation.newAttributes(attributes),
|
|
155
145
|
};
|
|
156
146
|
},
|
|
157
|
-
|
|
147
|
+
|
|
158
148
|
isEligible: deprecation?.isEligible ?? ((attributes) => Object.keys(deprecation.oldAttributes).every((v) => Object.keys(attributes).includes(v))),
|
|
159
149
|
save: blockDetails.options.save,
|
|
160
150
|
};
|
|
@@ -169,10 +159,7 @@ export const registerBlocks = (
|
|
|
169
159
|
});
|
|
170
160
|
|
|
171
161
|
// Add icon foreground and background colors as CSS variables for later use.
|
|
172
|
-
const {
|
|
173
|
-
background: backgroundGlobal,
|
|
174
|
-
foreground: foregroundGlobal,
|
|
175
|
-
} = globalManifest;
|
|
162
|
+
const { background: backgroundGlobal, foreground: foregroundGlobal } = globalManifest;
|
|
176
163
|
|
|
177
164
|
document.documentElement.style.setProperty('--es-admin-block-icon-foreground', foregroundGlobal);
|
|
178
165
|
document.documentElement.style.setProperty('--es-admin-block-icon-background', backgroundGlobal);
|
|
@@ -209,13 +196,7 @@ export const registerBlocks = (
|
|
|
209
196
|
* );
|
|
210
197
|
* ```
|
|
211
198
|
*/
|
|
212
|
-
export const registerVariations = (
|
|
213
|
-
globalManifest = {},
|
|
214
|
-
variationsManifestPath,
|
|
215
|
-
blocksManifestPath = null,
|
|
216
|
-
overridesComponentPath = null,
|
|
217
|
-
) => {
|
|
218
|
-
|
|
199
|
+
export const registerVariations = (globalManifest = {}, variationsManifestPath, blocksManifestPath = null, overridesComponentPath = null) => {
|
|
219
200
|
const variationsManifests = variationsManifestPath.keys().map(variationsManifestPath);
|
|
220
201
|
|
|
221
202
|
// Set all store values.
|
|
@@ -223,9 +204,7 @@ export const registerVariations = (
|
|
|
223
204
|
|
|
224
205
|
// Iterate blocks to register.
|
|
225
206
|
variationsManifests.map((variationManifest) => {
|
|
226
|
-
const {
|
|
227
|
-
active = true,
|
|
228
|
-
} = variationManifest;
|
|
207
|
+
const { active = true } = variationManifest;
|
|
229
208
|
|
|
230
209
|
// If variation has active key set to false the variation will not show in the block editor.
|
|
231
210
|
if (active) {
|
|
@@ -234,16 +213,12 @@ export const registerVariations = (
|
|
|
234
213
|
const blockOverridesComponent = getBlockGenericComponent(variationManifest.name, overridesComponentPath, 'overrides');
|
|
235
214
|
|
|
236
215
|
if (blockOverridesComponent !== null) {
|
|
237
|
-
variationManifest = Object.assign(variationManifest, blockOverridesComponent)
|
|
216
|
+
variationManifest = Object.assign(variationManifest, blockOverridesComponent);
|
|
238
217
|
}
|
|
239
218
|
}
|
|
240
219
|
|
|
241
220
|
// Pass data to registerVariation helper to get final output for registerBlockVariation.
|
|
242
|
-
const blockDetails = registerVariation(
|
|
243
|
-
globalManifest,
|
|
244
|
-
variationManifest,
|
|
245
|
-
(blocksManifestPath !== null) ? blocksManifestPath.keys().map(blocksManifestPath) : []
|
|
246
|
-
);
|
|
221
|
+
const blockDetails = registerVariation(globalManifest, variationManifest, blocksManifestPath !== null ? blocksManifestPath.keys().map(blocksManifestPath) : []);
|
|
247
222
|
|
|
248
223
|
// Native WP method for block registration.
|
|
249
224
|
registerBlockVariation(blockDetails.blockName, blockDetails.options);
|
|
@@ -269,7 +244,6 @@ export const registerVariations = (
|
|
|
269
244
|
*
|
|
270
245
|
*/
|
|
271
246
|
export const getBlockEditComponent = (blockName, paths, fileName) => {
|
|
272
|
-
|
|
273
247
|
// Create an array of all blocks file paths.
|
|
274
248
|
const pathsKeys = paths.keys();
|
|
275
249
|
|
|
@@ -278,7 +252,6 @@ export const getBlockEditComponent = (blockName, paths, fileName) => {
|
|
|
278
252
|
|
|
279
253
|
// If edit component is missing throw and error.
|
|
280
254
|
if (typeof editComponent === 'undefined') {
|
|
281
|
-
// eslint-disable-next-line max-len
|
|
282
255
|
throw Error(`It looks like you are missing block edit component for block: ${blockName}, please check if you have ${blockName}-block.js file in your block folder.`);
|
|
283
256
|
}
|
|
284
257
|
|
|
@@ -287,7 +260,6 @@ export const getBlockEditComponent = (blockName, paths, fileName) => {
|
|
|
287
260
|
|
|
288
261
|
// If edit component callback is missing throw and error.
|
|
289
262
|
if (typeof editCallback === 'undefined') {
|
|
290
|
-
// eslint-disable-next-line max-len
|
|
291
263
|
throw Error(`It looks like you are missing block edit component for block: ${blockName}, please check if you have ${blockName}-block.js file in your block folder.`);
|
|
292
264
|
}
|
|
293
265
|
|
|
@@ -307,7 +279,6 @@ export const getBlockEditComponent = (blockName, paths, fileName) => {
|
|
|
307
279
|
*
|
|
308
280
|
*/
|
|
309
281
|
export const getBlockGenericComponent = (blockName, paths, fileName) => {
|
|
310
|
-
|
|
311
282
|
// Create an array of all blocks file paths.
|
|
312
283
|
const pathsKeys = paths.keys();
|
|
313
284
|
|
|
@@ -334,7 +305,7 @@ export const getBlockGenericComponent = (blockName, paths, fileName) => {
|
|
|
334
305
|
* @returns {string?}
|
|
335
306
|
*/
|
|
336
307
|
export const getNamespace = (globalManifest, blockManifest) => {
|
|
337
|
-
return
|
|
308
|
+
return typeof blockManifest.namespace === 'undefined' ? globalManifest.namespace : blockManifest.namespace;
|
|
338
309
|
};
|
|
339
310
|
|
|
340
311
|
/**
|
|
@@ -375,9 +346,7 @@ export const getFullBlockNameVariation = (globalManifest, blockManifest) => {
|
|
|
375
346
|
* @returns {function} Save callback.
|
|
376
347
|
*/
|
|
377
348
|
export const getSaveCallback = (blockManifest) => {
|
|
378
|
-
const {
|
|
379
|
-
hasInnerBlocks,
|
|
380
|
-
} = blockManifest;
|
|
349
|
+
const { hasInnerBlocks } = blockManifest;
|
|
381
350
|
|
|
382
351
|
if (hasInnerBlocks && typeof InnerBlocks !== 'undefined') {
|
|
383
352
|
return () => createElement(InnerBlocks.Content);
|
|
@@ -394,9 +363,7 @@ export const getSaveCallback = (blockManifest) => {
|
|
|
394
363
|
* @param {object} blockManifest - Block manifest.
|
|
395
364
|
*/
|
|
396
365
|
export const getMergeCallback = (blockManifest) => {
|
|
397
|
-
const {
|
|
398
|
-
mergeableAttributes,
|
|
399
|
-
} = blockManifest;
|
|
366
|
+
const { mergeableAttributes } = blockManifest;
|
|
400
367
|
|
|
401
368
|
if (mergeableAttributes) {
|
|
402
369
|
return (receiver, merger) => {
|
|
@@ -408,24 +375,24 @@ export const getMergeCallback = (blockManifest) => {
|
|
|
408
375
|
});
|
|
409
376
|
|
|
410
377
|
switch (mergeStrategy) {
|
|
411
|
-
case
|
|
378
|
+
case 'append': {
|
|
412
379
|
outputObject[attribute] = `${receiver[attribute] ?? ''}${merger[attribute] ?? ''}`;
|
|
413
380
|
break;
|
|
414
381
|
}
|
|
415
|
-
case
|
|
382
|
+
case 'useDestinationAttribute': {
|
|
416
383
|
outputObject[attribute] = merger[attribute] ?? '';
|
|
417
384
|
break;
|
|
418
385
|
}
|
|
419
|
-
case
|
|
386
|
+
case 'addNumericIntValue': {
|
|
420
387
|
outputObject[attribute] = parseInt(receiver[attribute] ?? '0') + parseInt(merger[attribute] ?? '0');
|
|
421
388
|
break;
|
|
422
389
|
}
|
|
423
|
-
case
|
|
390
|
+
case 'addNumericFloatValue': {
|
|
424
391
|
outputObject[attribute] = parseFloat(receiver[attribute] ?? '0') + parseFloat(merger[attribute] ?? '0');
|
|
425
392
|
break;
|
|
426
393
|
}
|
|
427
|
-
|
|
428
|
-
case
|
|
394
|
+
|
|
395
|
+
case 'addNumericPixelValue': {
|
|
429
396
|
// Remove numbers
|
|
430
397
|
const receiverUnit = (receiver[attribute] ?? '0px').replace(/\d/g, '');
|
|
431
398
|
|
|
@@ -437,7 +404,7 @@ export const getMergeCallback = (blockManifest) => {
|
|
|
437
404
|
outputObject[attribute] = `${calculatedValue}${receiverUnit}`;
|
|
438
405
|
break;
|
|
439
406
|
}
|
|
440
|
-
|
|
407
|
+
|
|
441
408
|
default: {
|
|
442
409
|
// "useSourceAttribute" is default
|
|
443
410
|
outputObject[attribute] = receiver[attribute] ?? '';
|
|
@@ -466,12 +433,12 @@ export const getMergeCallback = (blockManifest) => {
|
|
|
466
433
|
export const getEditCallback = (Component, Wrapper) => (props) => {
|
|
467
434
|
const useWrapper = select(STORE_NAME).getConfigUseWrapper();
|
|
468
435
|
|
|
469
|
-
return (
|
|
470
|
-
|
|
471
|
-
<Wrapper props={props}>
|
|
472
|
-
<Component {...props} />
|
|
473
|
-
</Wrapper> :
|
|
436
|
+
return useWrapper ? (
|
|
437
|
+
<Wrapper props={props}>
|
|
474
438
|
<Component {...props} />
|
|
439
|
+
</Wrapper>
|
|
440
|
+
) : (
|
|
441
|
+
<Component {...props} />
|
|
475
442
|
);
|
|
476
443
|
};
|
|
477
444
|
|
|
@@ -485,19 +452,10 @@ export const getEditCallback = (Component, Wrapper) => (props) => {
|
|
|
485
452
|
*
|
|
486
453
|
* @returns {object}
|
|
487
454
|
*/
|
|
488
|
-
export const getIconOptions = (
|
|
489
|
-
globalManifest
|
|
490
|
-
blockManifest
|
|
491
|
-
) => {
|
|
455
|
+
export const getIconOptions = (globalManifest, blockManifest) => {
|
|
456
|
+
const { background: backgroundGlobal, foreground: foregroundGlobal } = globalManifest;
|
|
492
457
|
|
|
493
|
-
const {
|
|
494
|
-
background: backgroundGlobal,
|
|
495
|
-
foreground: foregroundGlobal,
|
|
496
|
-
} = globalManifest;
|
|
497
|
-
|
|
498
|
-
const {
|
|
499
|
-
icon,
|
|
500
|
-
} = blockManifest;
|
|
458
|
+
const { icon } = blockManifest;
|
|
501
459
|
|
|
502
460
|
if (typeof icon === 'undefined') {
|
|
503
461
|
return {};
|
|
@@ -507,15 +465,15 @@ export const getIconOptions = (
|
|
|
507
465
|
// icon exists in the library
|
|
508
466
|
if (icon.src !== undefined && blockIcons[icon.src] !== undefined) {
|
|
509
467
|
return {
|
|
510
|
-
background:
|
|
511
|
-
foreground:
|
|
468
|
+
background: typeof icon.background === 'undefined' ? backgroundGlobal : icon.background,
|
|
469
|
+
foreground: typeof icon.foreground === 'undefined' ? foregroundGlobal : icon.foreground,
|
|
512
470
|
src: <span dangerouslySetInnerHTML={{ __html: blockIcons[icon.src] }} />,
|
|
513
471
|
};
|
|
514
472
|
}
|
|
515
473
|
|
|
516
474
|
return {
|
|
517
|
-
background:
|
|
518
|
-
foreground:
|
|
475
|
+
background: typeof icon.background === 'undefined' ? backgroundGlobal : icon.background,
|
|
476
|
+
foreground: typeof icon.foreground === 'undefined' ? foregroundGlobal : icon.foreground,
|
|
519
477
|
src: icon.src.includes('<svg') ? <span dangerouslySetInnerHTML={{ __html: icon.src }} /> : icon.src,
|
|
520
478
|
};
|
|
521
479
|
};
|
|
@@ -550,7 +508,6 @@ export const prepareComponentAttribute = (manifest, newName, realName, isExample
|
|
|
550
508
|
|
|
551
509
|
// Iterate each attribute and attach parent prefixes.
|
|
552
510
|
for (const [componentAttribute] of Object.entries(componentAttributes)) {
|
|
553
|
-
|
|
554
511
|
let attribute = componentAttribute;
|
|
555
512
|
|
|
556
513
|
// If there is a attribute name switch use the new one.
|
|
@@ -589,32 +546,23 @@ export const prepareComponentAttribute = (manifest, newName, realName, isExample
|
|
|
589
546
|
*
|
|
590
547
|
* @returns {object}
|
|
591
548
|
*/
|
|
592
|
-
export const prepareComponentAttributes = (
|
|
593
|
-
componentsManifest,
|
|
594
|
-
manifest,
|
|
595
|
-
isExample = false,
|
|
596
|
-
parent = ''
|
|
597
|
-
) => {
|
|
549
|
+
export const prepareComponentAttributes = (componentsManifest, manifest, isExample = false, parent = '') => {
|
|
598
550
|
const output = {};
|
|
599
551
|
|
|
600
|
-
const {
|
|
601
|
-
components = {},
|
|
602
|
-
} = manifest;
|
|
552
|
+
const { components = {} } = manifest;
|
|
603
553
|
|
|
604
554
|
// Determine if this is component or block and provide the name, not used for anything important but only to output the error msg.
|
|
605
555
|
const name = manifest?.blockName ? manifest.blockName : manifest.componentName;
|
|
606
556
|
|
|
607
|
-
const newParent =
|
|
557
|
+
const newParent = parent === '' ? name : parent;
|
|
608
558
|
|
|
609
559
|
// Iterate over components key in manifest recursively and check component names.
|
|
610
560
|
for (let [newComponentName, realComponentName] of Object.entries(components)) {
|
|
611
|
-
|
|
612
561
|
// Filter components real name.
|
|
613
562
|
const [component] = componentsManifest.filter((item) => item.componentName === kebabCase(realComponentName));
|
|
614
563
|
|
|
615
564
|
// Bailout if component doesn't exist.
|
|
616
565
|
if (!component) {
|
|
617
|
-
// eslint-disable-next-line max-len
|
|
618
566
|
throw Error(`Component specified in "${name}" manifest doesn't exist in your components list. Please check if you project has "${realComponentName}" component.`);
|
|
619
567
|
}
|
|
620
568
|
|
|
@@ -622,7 +570,6 @@ export const prepareComponentAttributes = (
|
|
|
622
570
|
|
|
623
571
|
// If component has more components do recursive loop.
|
|
624
572
|
if (component?.components) {
|
|
625
|
-
// eslint-disable-next-line max-len
|
|
626
573
|
outputAttributes = prepareComponentAttributes(componentsManifest, component, isExample, `${newParent}${upperFirst(camelCase(newComponentName))}`);
|
|
627
574
|
} else {
|
|
628
575
|
// Output the component attributes if there is no nesting left, and append the parent prefixes.
|
|
@@ -630,13 +577,10 @@ export const prepareComponentAttributes = (
|
|
|
630
577
|
}
|
|
631
578
|
|
|
632
579
|
// Populate the output recursively.
|
|
633
|
-
Object.assign(
|
|
634
|
-
output,
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
...outputAttributes,
|
|
638
|
-
}
|
|
639
|
-
);
|
|
580
|
+
Object.assign(output, {
|
|
581
|
+
...output,
|
|
582
|
+
...outputAttributes,
|
|
583
|
+
});
|
|
640
584
|
}
|
|
641
585
|
|
|
642
586
|
// Add the current block/component attributes to the output.
|
|
@@ -662,20 +606,10 @@ export const prepareComponentAttributes = (
|
|
|
662
606
|
* getAttributes(globalManifest, wrapperManifest, componentManifests, manifest)
|
|
663
607
|
* ```
|
|
664
608
|
*/
|
|
665
|
-
export const getAttributes = (
|
|
666
|
-
|
|
667
|
-
wrapperManifest,
|
|
668
|
-
componentsManifest,
|
|
669
|
-
parentManifest
|
|
670
|
-
) => {
|
|
671
|
-
const {
|
|
672
|
-
blockName,
|
|
673
|
-
} = parentManifest;
|
|
609
|
+
export const getAttributes = (globalManifest, wrapperManifest, componentsManifest, parentManifest) => {
|
|
610
|
+
const { blockName } = parentManifest;
|
|
674
611
|
|
|
675
|
-
const {
|
|
676
|
-
attributes: attributesGlobal,
|
|
677
|
-
blockClassPrefix = 'block',
|
|
678
|
-
} = globalManifest;
|
|
612
|
+
const { attributes: attributesGlobal, blockClassPrefix = 'block' } = globalManifest;
|
|
679
613
|
|
|
680
614
|
const output = {
|
|
681
615
|
blockName: {
|
|
@@ -683,9 +617,10 @@ export const getAttributes = (
|
|
|
683
617
|
default: blockName,
|
|
684
618
|
},
|
|
685
619
|
blockClientId: {
|
|
686
|
-
type: 'string'
|
|
620
|
+
type: 'string',
|
|
687
621
|
},
|
|
688
|
-
blockTopLevelId: {
|
|
622
|
+
blockTopLevelId: {
|
|
623
|
+
// Used to pass reference to all components.
|
|
689
624
|
type: 'string',
|
|
690
625
|
default: Math.random().toString(36).slice(-6),
|
|
691
626
|
},
|
|
@@ -701,7 +636,7 @@ export const getAttributes = (
|
|
|
701
636
|
type: 'string',
|
|
702
637
|
default: `js-${blockClassPrefix}-${blockName}`,
|
|
703
638
|
},
|
|
704
|
-
...(
|
|
639
|
+
...(typeof attributesGlobal === 'undefined' ? {} : attributesGlobal),
|
|
705
640
|
...(wrapperManifest?.attributes ?? {}),
|
|
706
641
|
...prepareComponentAttributes(componentsManifest, parentManifest),
|
|
707
642
|
};
|
|
@@ -752,10 +687,7 @@ export const getAttributes = (
|
|
|
752
687
|
* }
|
|
753
688
|
* ```
|
|
754
689
|
*/
|
|
755
|
-
export const getExample = (
|
|
756
|
-
parent = '',
|
|
757
|
-
manifest = {}
|
|
758
|
-
) => {
|
|
690
|
+
export const getExample = (parent = '', manifest = {}) => {
|
|
759
691
|
return prepareComponentAttributes(select(STORE_NAME).getComponents(), manifest, true, parent);
|
|
760
692
|
};
|
|
761
693
|
|
|
@@ -770,10 +702,7 @@ export const getExample = (
|
|
|
770
702
|
*
|
|
771
703
|
* @returns {object}
|
|
772
704
|
*/
|
|
773
|
-
export const registerVariation = (
|
|
774
|
-
globalManifest = {},
|
|
775
|
-
variationManifest = {}
|
|
776
|
-
) => {
|
|
705
|
+
export const registerVariation = (globalManifest = {}, variationManifest = {}) => {
|
|
777
706
|
const parentBlockManifest = select(STORE_NAME).getBlock(variationManifest.parentName);
|
|
778
707
|
|
|
779
708
|
// Append globalManifest data in to output.
|
|
@@ -823,15 +752,7 @@ export const registerVariation = (
|
|
|
823
752
|
*
|
|
824
753
|
* @returns {object}
|
|
825
754
|
*/
|
|
826
|
-
export const registerBlock = (
|
|
827
|
-
globalManifest = {},
|
|
828
|
-
wrapperManifest = {},
|
|
829
|
-
componentsManifest = {},
|
|
830
|
-
blockManifest = {},
|
|
831
|
-
wrapperComponent,
|
|
832
|
-
blockComponent
|
|
833
|
-
) => {
|
|
834
|
-
|
|
755
|
+
export const registerBlock = (globalManifest = {}, wrapperManifest = {}, componentsManifest = {}, blockManifest = {}, wrapperComponent, blockComponent) => {
|
|
835
756
|
// Block Icon option.
|
|
836
757
|
blockManifest['icon'] = getIconOptions(globalManifest, blockManifest);
|
|
837
758
|
|
|
@@ -843,7 +764,7 @@ export const registerBlock = (
|
|
|
843
764
|
|
|
844
765
|
blockManifest['attributes'] = {
|
|
845
766
|
metadata: {
|
|
846
|
-
type: 'object'
|
|
767
|
+
type: 'object',
|
|
847
768
|
},
|
|
848
769
|
...attributes,
|
|
849
770
|
};
|
|
@@ -855,6 +776,7 @@ export const registerBlock = (
|
|
|
855
776
|
|
|
856
777
|
// Find all attributes that have default value and output that to example.
|
|
857
778
|
const exampleAttributes = {};
|
|
779
|
+
|
|
858
780
|
for (const [key, value] of Object.entries(attributes)) {
|
|
859
781
|
if (value?.default) {
|
|
860
782
|
exampleAttributes[key] = value.default;
|
|
@@ -888,6 +810,7 @@ export const registerBlock = (
|
|
|
888
810
|
|
|
889
811
|
if (context === 'accessibility') {
|
|
890
812
|
const { content } = attributes;
|
|
813
|
+
|
|
891
814
|
return !content || content?.length === 0 ? __('Empty', 'eightshift-frontend-libs') : content;
|
|
892
815
|
}
|
|
893
816
|
|
|
@@ -6,9 +6,9 @@ import { clsx } from '@eightshift/ui-components/utilities';
|
|
|
6
6
|
*
|
|
7
7
|
* The part needs to be defined within the manifest, in the `tailwind` object.
|
|
8
8
|
*
|
|
9
|
-
* @param {string}
|
|
9
|
+
* @param {string} part - Part name.
|
|
10
10
|
* @param {Object<string, mixed>} manifest - Component/block manifest.
|
|
11
|
-
* @param {...string?} custom - Custom classes to include in the
|
|
11
|
+
* @param {...string?} custom - Custom classes to include in the output.
|
|
12
12
|
*
|
|
13
13
|
* @returns {string} Output classes.
|
|
14
14
|
*
|
|
@@ -29,12 +29,77 @@ export const getTwPart = (part, manifest, ...custom) => {
|
|
|
29
29
|
return clsx(partClasses, ...custom);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Gets Tailwind classes for the provided dynamic part.
|
|
34
|
+
*
|
|
35
|
+
* The part needs to be defined within the manifest, in the `tailwind` object.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} part - Part name.
|
|
38
|
+
* @param {Object<string, mixed>} attributes - Current attribute value.
|
|
39
|
+
* @param {Object<string, mixed>} manifest - Component/block manifest.
|
|
40
|
+
* @param {...string?} custom - Custom classes to include in the output.
|
|
41
|
+
*
|
|
42
|
+
* @returns {string} Output classes.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* const classes = getTwPart('intro', manifest);
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* const classes = getTwPart('intro', manifest, 'p-4 bg-gray-100');
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
export const getTwDynamicPart = (part, attributes, manifest, ...custom) => {
|
|
52
|
+
if (!part || !manifest || !manifest?.tailwind || Object.keys(manifest?.tailwind ?? {}).length === 0) {
|
|
53
|
+
return '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const baseClasses = manifest?.tailwind?.parts?.[part]?.twClassesEditor ?? manifest?.tailwind?.parts?.[part]?.twClasses ?? '';
|
|
57
|
+
|
|
58
|
+
const mainClasses = Object.entries(manifest?.tailwind?.options ?? {}).reduce((current, [attributeName, { responsive, twClasses, twClassesEditor, part: partName }]) => {
|
|
59
|
+
if (partName !== part) {
|
|
60
|
+
return current;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const value = checkAttr(attributeName, attributes, manifest, true);
|
|
64
|
+
|
|
65
|
+
if (!value) {
|
|
66
|
+
return current;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!responsive) {
|
|
70
|
+
return [...current, twClassesEditor?.[value] ?? twClasses?.[value]];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const responsiveClasses = Object.keys(value).reduce((curr, breakpoint) => {
|
|
74
|
+
if (breakpoint === '_desktopFirst') {
|
|
75
|
+
return curr;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const currentClasses = twClassesEditor?.[value[breakpoint]] ?? twClasses?.[value[breakpoint]];
|
|
79
|
+
|
|
80
|
+
if (breakpoint === '_default') {
|
|
81
|
+
return [...curr, currentClasses];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (Array.isArray(currentClasses)) {
|
|
85
|
+
return [...curr, ...currentClasses.split(' ').map((currentClass) => `${breakpoint}:${currentClass}`)];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return [...curr, `${breakpoint}:${currentClasses}`];
|
|
89
|
+
}, []);
|
|
90
|
+
|
|
91
|
+
return [...current, ...responsiveClasses];
|
|
92
|
+
}, []);
|
|
93
|
+
|
|
94
|
+
return clsx(baseClasses, ...mainClasses, ...custom);
|
|
95
|
+
};
|
|
96
|
+
|
|
32
97
|
/**
|
|
33
98
|
* Get Tailwind classes from attributes and manifest.
|
|
34
99
|
*
|
|
35
100
|
* @param {Object<string, mixed>} attributes - Current attribute value.
|
|
36
101
|
* @param {Object<string, mixed>} manifest - Component/block manifest.
|
|
37
|
-
* @param {...string?} custom - Custom classes to include in the
|
|
102
|
+
* @param {...string?} custom - Custom classes to include in the output.
|
|
38
103
|
*
|
|
39
104
|
* @returns {string} Output classes
|
|
40
105
|
*
|
|
@@ -52,7 +117,11 @@ export const getTwClasses = (attributes, manifest, ...custom) => {
|
|
|
52
117
|
|
|
53
118
|
const baseClasses = manifest?.tailwind?.base?.twClassesEditor ?? manifest?.tailwind?.base?.twClasses ?? '';
|
|
54
119
|
|
|
55
|
-
const mainClasses = Object.entries(manifest?.tailwind?.options ?? {}).reduce((current, [attributeName, { responsive, twClasses, twClassesEditor }]) => {
|
|
120
|
+
const mainClasses = Object.entries(manifest?.tailwind?.options ?? {}).reduce((current, [attributeName, { responsive, twClasses, twClassesEditor, part: partName }]) => {
|
|
121
|
+
if (partName) {
|
|
122
|
+
return current;
|
|
123
|
+
}
|
|
124
|
+
|
|
56
125
|
const value = checkAttr(attributeName, attributes, manifest, true);
|
|
57
126
|
|
|
58
127
|
if (!value) {
|
|
@@ -84,25 +153,26 @@ export const getTwClasses = (attributes, manifest, ...custom) => {
|
|
|
84
153
|
return [...current, ...responsiveClasses];
|
|
85
154
|
}, []);
|
|
86
155
|
|
|
87
|
-
const combinationClasses =
|
|
88
|
-
|
|
156
|
+
const combinationClasses =
|
|
157
|
+
manifest?.tailwind?.combinations?.reduce((current, { attributes: conditions, twClasses, twClassesEditor }) => {
|
|
158
|
+
const conditionKeys = Object.keys(conditions);
|
|
89
159
|
|
|
90
|
-
|
|
91
|
-
|
|
160
|
+
for (const key of conditionKeys) {
|
|
161
|
+
const value = checkAttr(key, attributes, manifest, true);
|
|
92
162
|
|
|
93
|
-
|
|
163
|
+
const isArrayCondition = Array.isArray(conditions[key]);
|
|
94
164
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
165
|
+
if (!value) {
|
|
166
|
+
return current;
|
|
167
|
+
} else if (isArrayCondition && !conditions[key].includes(value)) {
|
|
168
|
+
return current;
|
|
169
|
+
} else if (!isArrayCondition && value !== conditions[key]) {
|
|
170
|
+
return current;
|
|
171
|
+
}
|
|
101
172
|
}
|
|
102
|
-
}
|
|
103
173
|
|
|
104
|
-
|
|
105
|
-
|
|
174
|
+
return [...current, twClassesEditor ?? twClasses];
|
|
175
|
+
}, []) ?? [];
|
|
106
176
|
|
|
107
177
|
return clsx(baseClasses, ...mainClasses, ...combinationClasses, ...custom);
|
|
108
178
|
};
|
|
@@ -137,7 +207,7 @@ export const getTwClasses = (attributes, manifest, ...custom) => {
|
|
|
137
207
|
export const processEightshiftClasses = (breakpoints) => ({
|
|
138
208
|
// Make sure to include all the custom ES classes from JSON manifests.
|
|
139
209
|
json: (rawContent) => {
|
|
140
|
-
if (!
|
|
210
|
+
if (!rawContent.includes('tailwind')) {
|
|
141
211
|
return rawContent;
|
|
142
212
|
}
|
|
143
213
|
|
|
@@ -153,14 +223,18 @@ export const processEightshiftClasses = (breakpoints) => ({
|
|
|
153
223
|
combinedResults[key] = combined.join(' ');
|
|
154
224
|
}
|
|
155
225
|
|
|
156
|
-
const responsiveVars =
|
|
157
|
-
|
|
158
|
-
|
|
226
|
+
const responsiveVars =
|
|
227
|
+
combinedResults?.responsive
|
|
228
|
+
?.split(' ')
|
|
229
|
+
?.map((cls) => {
|
|
230
|
+
return breakpoints.reduce((curr, breakpoint) => `${curr} ${breakpoint}:${cls} max-${breakpoint}:${cls}`, cls);
|
|
231
|
+
})
|
|
232
|
+
?.join(' ') ?? '';
|
|
159
233
|
|
|
160
234
|
const nonResponsiveVars = combinedResults?.regular ?? '';
|
|
161
235
|
|
|
162
236
|
return `${nonResponsiveVars} ${responsiveVars}`.trim();
|
|
163
|
-
}
|
|
237
|
+
},
|
|
164
238
|
});
|
|
165
239
|
|
|
166
240
|
/**
|
|
@@ -182,43 +256,50 @@ export const processEightshiftClasses = (breakpoints) => ({
|
|
|
182
256
|
*
|
|
183
257
|
*/
|
|
184
258
|
export const getScreens = (breakpointData, unit = 'rem') => {
|
|
185
|
-
return Object.entries(breakpointData ?? []).reduce(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
259
|
+
return Object.entries(breakpointData ?? []).reduce(
|
|
260
|
+
(acc, [key, value]) => ({
|
|
261
|
+
...acc,
|
|
262
|
+
[key]: `${value}${unit}`,
|
|
263
|
+
}),
|
|
264
|
+
{},
|
|
265
|
+
);
|
|
189
266
|
};
|
|
190
267
|
|
|
191
268
|
export const generateOptionsFromValue = (value, getLabel = (v) => v) => {
|
|
192
|
-
return Object.entries(value)
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
269
|
+
return Object.entries(value)
|
|
270
|
+
.filter(([breakpoint]) => breakpoint !== '_desktopFirst')
|
|
271
|
+
.map(([breakpoint, innerValue]) => ({
|
|
272
|
+
value: innerValue,
|
|
273
|
+
label: getLabel(innerValue, breakpoint),
|
|
274
|
+
}));
|
|
275
|
+
};
|
|
197
276
|
|
|
198
277
|
// Utilities
|
|
199
278
|
function* extractKeys(obj, parentKey = '', isResponsive = false) {
|
|
200
279
|
isResponsive = obj['responsive'] === true ? true : isResponsive;
|
|
201
|
-
let resultKey = isResponsive ?
|
|
280
|
+
let resultKey = isResponsive ? 'responsive' : 'regular';
|
|
202
281
|
|
|
203
282
|
for (let key in obj) {
|
|
204
283
|
let newKey = parentKey ? `${parentKey}.${key}` : key;
|
|
284
|
+
|
|
205
285
|
if (typeof obj[key] === 'object' && obj[key] !== null) {
|
|
206
286
|
yield* extractKeys(obj[key], newKey, isResponsive);
|
|
207
287
|
} else if (newKey.includes('twClasses')) {
|
|
208
288
|
if (typeof obj[key] === 'object') {
|
|
209
289
|
for (let subKey in obj[key]) {
|
|
210
|
-
yield {key: `${newKey}.${subKey}`, value: obj[key][subKey], responsive: resultKey};
|
|
290
|
+
yield { key: `${newKey}.${subKey}`, value: obj[key][subKey], responsive: resultKey };
|
|
211
291
|
}
|
|
212
292
|
} else {
|
|
213
|
-
yield {key: newKey, value: obj[key], responsive: resultKey};
|
|
293
|
+
yield { key: newKey, value: obj[key], responsive: resultKey };
|
|
214
294
|
}
|
|
215
295
|
}
|
|
216
296
|
}
|
|
217
297
|
}
|
|
218
298
|
|
|
219
299
|
const combineAndRemoveDuplicates = (results) => {
|
|
220
|
-
return results.reduce((acc, {key, value, responsive}) => {
|
|
300
|
+
return results.reduce((acc, { key, value, responsive }) => {
|
|
221
301
|
acc[responsive] = acc[responsive] ? `${acc[responsive]} ${value}` : value;
|
|
302
|
+
|
|
222
303
|
return acc;
|
|
223
304
|
}, {});
|
|
224
|
-
}
|
|
305
|
+
};
|