@eightshift/frontend-libs-tailwind 1.0.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/.gitattributes +37 -0
- package/.github/CODEOWNERS +1 -0
- package/.github/CONTRIBUTING.md +17 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +10 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +10 -0
- package/.github/ISSUE_TEMPLATE/question.md +10 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +11 -0
- package/.github/workflows/ci.yml +31 -0
- package/.husky/pre-commit +1 -0
- package/.prettierrc +14 -0
- package/.stylelintrc +4 -0
- package/CHANGELOG.md +13 -0
- package/CODE_OF_CONDUCT.md +76 -0
- package/LICENSE +21 -0
- package/README.md +24 -0
- package/blocks/init/assets/application-admin.js +10 -0
- package/blocks/init/assets/application.js +13 -0
- package/blocks/init/assets/images/index.js +5 -0
- package/blocks/init/assets/scripts/application-admin.js +7 -0
- package/blocks/init/assets/scripts/application.js +3 -0
- package/blocks/init/assets/scripts/theme-colors.js +39 -0
- package/blocks/init/assets/styles/application-admin.css +6 -0
- package/blocks/init/assets/styles/application.css +3 -0
- package/blocks/init/src/Blocks/assets/application-blocks-editor.js +14 -0
- package/blocks/init/src/Blocks/assets/application-blocks-frontend.js +13 -0
- package/blocks/init/src/Blocks/assets/application-blocks.js +9 -0
- package/blocks/init/src/Blocks/assets/scripts/application-blocks-editor.js +65 -0
- package/blocks/init/src/Blocks/assets/scripts/application-blocks-frontend.js +24 -0
- package/blocks/init/src/Blocks/assets/scripts/link-section-editor.js +258 -0
- package/blocks/init/src/Blocks/assets/scripts/shared.js +25 -0
- package/blocks/init/src/Blocks/assets/styles/application-blocks-editor.css +15 -0
- package/blocks/init/src/Blocks/assets/styles/application-blocks-frontend.css +12 -0
- package/blocks/init/src/Blocks/assets/styles/application-blocks.css +0 -0
- package/blocks/init/src/Blocks/assets/styles/editor/editor-overrides.css +15 -0
- package/blocks/init/src/Blocks/assets/styles/tailwind.css +34 -0
- package/blocks/init/src/Blocks/components/admin-theme-options/admin-theme-options.php +20 -0
- package/blocks/init/src/Blocks/components/admin-theme-options/assets-admin/index.js +36 -0
- package/blocks/init/src/Blocks/components/admin-theme-options/assets-admin/pages/parts.js +55 -0
- package/blocks/init/src/Blocks/components/admin-theme-options/manifest.json +5 -0
- package/blocks/init/src/Blocks/components/button/assets/index.js +22 -0
- package/blocks/init/src/Blocks/components/button/button.php +77 -0
- package/blocks/init/src/Blocks/components/button/components/button-editor.js +40 -0
- package/blocks/init/src/Blocks/components/button/components/button-options.js +135 -0
- package/blocks/init/src/Blocks/components/button/manifest.json +299 -0
- package/blocks/init/src/Blocks/components/card/card.php +42 -0
- package/blocks/init/src/Blocks/components/card/components/card-editor.js +39 -0
- package/blocks/init/src/Blocks/components/card/components/card-options.js +56 -0
- package/blocks/init/src/Blocks/components/card/manifest.json +111 -0
- package/blocks/init/src/Blocks/components/head/head.php +52 -0
- package/blocks/init/src/Blocks/components/head/manifest.json +17 -0
- package/blocks/init/src/Blocks/components/heading/components/heading-editor.js +30 -0
- package/blocks/init/src/Blocks/components/heading/components/heading-options.js +62 -0
- package/blocks/init/src/Blocks/components/heading/heading.php +45 -0
- package/blocks/init/src/Blocks/components/heading/manifest.json +76 -0
- package/blocks/init/src/Blocks/components/hero/components/hero-editor.js +42 -0
- package/blocks/init/src/Blocks/components/hero/components/hero-options.js +100 -0
- package/blocks/init/src/Blocks/components/hero/hero.php +45 -0
- package/blocks/init/src/Blocks/components/hero/manifest.json +96 -0
- package/blocks/init/src/Blocks/components/icon/components/icon-editor.js +23 -0
- package/blocks/init/src/Blocks/components/icon/components/icon-options.js +65 -0
- package/blocks/init/src/Blocks/components/icon/icon.php +34 -0
- package/blocks/init/src/Blocks/components/icon/manifest.json +1234 -0
- package/blocks/init/src/Blocks/components/image/components/image-editor.js +65 -0
- package/blocks/init/src/Blocks/components/image/components/image-options.js +111 -0
- package/blocks/init/src/Blocks/components/image/image.php +62 -0
- package/blocks/init/src/Blocks/components/image/manifest.json +125 -0
- package/blocks/init/src/Blocks/components/list/components/list-editor.js +30 -0
- package/blocks/init/src/Blocks/components/list/components/list-options.js +62 -0
- package/blocks/init/src/Blocks/components/list/list.php +32 -0
- package/blocks/init/src/Blocks/components/list/manifest.json +127 -0
- package/blocks/init/src/Blocks/components/load-more/assets/index.js +19 -0
- package/blocks/init/src/Blocks/components/load-more/assets/load-more.js +147 -0
- package/blocks/init/src/Blocks/components/load-more/components/load-more-editor.js +14 -0
- package/blocks/init/src/Blocks/components/load-more/components/load-more-options.js +18 -0
- package/blocks/init/src/Blocks/components/load-more/load-more.php +47 -0
- package/blocks/init/src/Blocks/components/load-more/manifest.json +39 -0
- package/blocks/init/src/Blocks/components/modal/assets/index.js +27 -0
- package/blocks/init/src/Blocks/components/modal/manifest.json +48 -0
- package/blocks/init/src/Blocks/components/modal/modal.php +46 -0
- package/blocks/init/src/Blocks/components/paragraph/components/paragraph-editor.js +40 -0
- package/blocks/init/src/Blocks/components/paragraph/components/paragraph-options.js +48 -0
- package/blocks/init/src/Blocks/components/paragraph/manifest.json +83 -0
- package/blocks/init/src/Blocks/components/paragraph/paragraph.php +33 -0
- package/blocks/init/src/Blocks/components/post-header/manifest.json +5 -0
- package/blocks/init/src/Blocks/components/post-header/post-header.php +24 -0
- package/blocks/init/src/Blocks/components/quote/components/quote-editor.js +53 -0
- package/blocks/init/src/Blocks/components/quote/components/quote-options.js +29 -0
- package/blocks/init/src/Blocks/components/quote/manifest.json +47 -0
- package/blocks/init/src/Blocks/components/quote/quote.php +49 -0
- package/blocks/init/src/Blocks/components/share/assets/index.js +39 -0
- package/blocks/init/src/Blocks/components/share/components/share-editor.js +25 -0
- package/blocks/init/src/Blocks/components/share/components/share-options.js +112 -0
- package/blocks/init/src/Blocks/components/share/manifest.json +72 -0
- package/blocks/init/src/Blocks/components/share/share.php +66 -0
- package/blocks/init/src/Blocks/components/tracking-before-body-end/manifest.json +5 -0
- package/blocks/init/src/Blocks/components/tracking-before-body-end/tracking-before-body-end.php +9 -0
- package/blocks/init/src/Blocks/components/tracking-head/manifest.json +5 -0
- package/blocks/init/src/Blocks/components/tracking-head/tracking-head.php +9 -0
- package/blocks/init/src/Blocks/components/video/components/video-editor.js +74 -0
- package/blocks/init/src/Blocks/components/video/components/video-options.js +280 -0
- package/blocks/init/src/Blocks/components/video/manifest.json +116 -0
- package/blocks/init/src/Blocks/components/video/video.php +72 -0
- package/blocks/init/src/Blocks/custom/accordion/accordion-block.js +15 -0
- package/blocks/init/src/Blocks/custom/accordion/accordion.php +28 -0
- package/blocks/init/src/Blocks/custom/accordion/assets/index.js +37 -0
- package/blocks/init/src/Blocks/custom/accordion/components/accordion-editor.js +17 -0
- package/blocks/init/src/Blocks/custom/accordion/components/accordion-options.js +18 -0
- package/blocks/init/src/Blocks/custom/accordion/manifest.json +32 -0
- package/blocks/init/src/Blocks/custom/accordion-item/accordion-item-block.js +19 -0
- package/blocks/init/src/Blocks/custom/accordion-item/accordion-item.php +46 -0
- package/blocks/init/src/Blocks/custom/accordion-item/components/accordion-item-editor.js +60 -0
- package/blocks/init/src/Blocks/custom/accordion-item/manifest.json +69 -0
- package/blocks/init/src/Blocks/custom/button/button-block.js +13 -0
- package/blocks/init/src/Blocks/custom/button/button.php +11 -0
- package/blocks/init/src/Blocks/custom/button/components/button-editor.js +12 -0
- package/blocks/init/src/Blocks/custom/button/components/button-options.js +12 -0
- package/blocks/init/src/Blocks/custom/button/manifest.json +18 -0
- package/blocks/init/src/Blocks/custom/card/card-block.js +13 -0
- package/blocks/init/src/Blocks/custom/card/card.php +11 -0
- package/blocks/init/src/Blocks/custom/card/components/card-editor.js +12 -0
- package/blocks/init/src/Blocks/custom/card/components/card-options.js +15 -0
- package/blocks/init/src/Blocks/custom/card/manifest.json +18 -0
- package/blocks/init/src/Blocks/custom/carousel/assets/index.js +46 -0
- package/blocks/init/src/Blocks/custom/carousel/assets/navigation.js +31 -0
- package/blocks/init/src/Blocks/custom/carousel/assets/pagination.js +39 -0
- package/blocks/init/src/Blocks/custom/carousel/carousel-block.js +21 -0
- package/blocks/init/src/Blocks/custom/carousel/carousel.php +61 -0
- package/blocks/init/src/Blocks/custom/carousel/components/carousel-editor.js +25 -0
- package/blocks/init/src/Blocks/custom/carousel/components/carousel-options.js +47 -0
- package/blocks/init/src/Blocks/custom/carousel/manifest.json +130 -0
- package/blocks/init/src/Blocks/custom/column/column-block.js +21 -0
- package/blocks/init/src/Blocks/custom/column/column-hooks.js +32 -0
- package/blocks/init/src/Blocks/custom/column/column.php +21 -0
- package/blocks/init/src/Blocks/custom/column/components/column-editor.js +19 -0
- package/blocks/init/src/Blocks/custom/column/components/column-options.js +579 -0
- package/blocks/init/src/Blocks/custom/column/manifest.json +625 -0
- package/blocks/init/src/Blocks/custom/columns/columns-block.js +20 -0
- package/blocks/init/src/Blocks/custom/columns/columns.php +21 -0
- package/blocks/init/src/Blocks/custom/columns/components/columns-editor.js +81 -0
- package/blocks/init/src/Blocks/custom/columns/components/columns-options.js +104 -0
- package/blocks/init/src/Blocks/custom/columns/manifest.json +555 -0
- package/blocks/init/src/Blocks/custom/featured-content/components/featured-content-editor.js +28 -0
- package/blocks/init/src/Blocks/custom/featured-content/components/featured-content-options.js +239 -0
- package/blocks/init/src/Blocks/custom/featured-content/featured-content-block.js +13 -0
- package/blocks/init/src/Blocks/custom/featured-content/featured-content.php +139 -0
- package/blocks/init/src/Blocks/custom/featured-content/manifest.json +131 -0
- package/blocks/init/src/Blocks/custom/featured-content/partials/cards.php +39 -0
- package/blocks/init/src/Blocks/custom/group/components/group-editor.js +8 -0
- package/blocks/init/src/Blocks/custom/group/group-block.js +14 -0
- package/blocks/init/src/Blocks/custom/group/group.php +10 -0
- package/blocks/init/src/Blocks/custom/group/manifest.json +32 -0
- package/blocks/init/src/Blocks/custom/heading/components/heading-editor.js +15 -0
- package/blocks/init/src/Blocks/custom/heading/components/heading-options.js +38 -0
- package/blocks/init/src/Blocks/custom/heading/heading-block.js +13 -0
- package/blocks/init/src/Blocks/custom/heading/heading-transforms.js +25 -0
- package/blocks/init/src/Blocks/custom/heading/heading.php +15 -0
- package/blocks/init/src/Blocks/custom/heading/manifest.json +79 -0
- package/blocks/init/src/Blocks/custom/hero/components/hero-editor.js +12 -0
- package/blocks/init/src/Blocks/custom/hero/components/hero-options.js +14 -0
- package/blocks/init/src/Blocks/custom/hero/hero-block.js +13 -0
- package/blocks/init/src/Blocks/custom/hero/hero.php +11 -0
- package/blocks/init/src/Blocks/custom/hero/manifest.json +17 -0
- package/blocks/init/src/Blocks/custom/image/components/image-editor.js +12 -0
- package/blocks/init/src/Blocks/custom/image/components/image-options.js +14 -0
- package/blocks/init/src/Blocks/custom/image/image-block.js +13 -0
- package/blocks/init/src/Blocks/custom/image/image.php +11 -0
- package/blocks/init/src/Blocks/custom/image/manifest.json +105 -0
- package/blocks/init/src/Blocks/custom/list/components/list-editor.js +14 -0
- package/blocks/init/src/Blocks/custom/list/components/list-options.js +39 -0
- package/blocks/init/src/Blocks/custom/list/list-block.js +13 -0
- package/blocks/init/src/Blocks/custom/list/list.php +15 -0
- package/blocks/init/src/Blocks/custom/list/manifest.json +58 -0
- package/blocks/init/src/Blocks/custom/map/assets/index.js +20 -0
- package/blocks/init/src/Blocks/custom/map/assets/map-controller.js +42 -0
- package/blocks/init/src/Blocks/custom/map/assets/utils.js +161 -0
- package/blocks/init/src/Blocks/custom/map/components/map-components.js +403 -0
- package/blocks/init/src/Blocks/custom/map/components/map-editor.js +56 -0
- package/blocks/init/src/Blocks/custom/map/components/map-options.js +557 -0
- package/blocks/init/src/Blocks/custom/map/manifest.json +79 -0
- package/blocks/init/src/Blocks/custom/map/map-block.js +13 -0
- package/blocks/init/src/Blocks/custom/map/map.php +52 -0
- package/blocks/init/src/Blocks/custom/map/styles.css +2 -0
- package/blocks/init/src/Blocks/custom/modal/components/modal-editor.js +90 -0
- package/blocks/init/src/Blocks/custom/modal/manifest.json +51 -0
- package/blocks/init/src/Blocks/custom/modal/modal-block.js +14 -0
- package/blocks/init/src/Blocks/custom/modal/modal.php +20 -0
- package/blocks/init/src/Blocks/custom/paragraph/components/paragraph-editor.js +41 -0
- package/blocks/init/src/Blocks/custom/paragraph/components/paragraph-options.js +38 -0
- package/blocks/init/src/Blocks/custom/paragraph/manifest.json +79 -0
- package/blocks/init/src/Blocks/custom/paragraph/paragraph-block.js +13 -0
- package/blocks/init/src/Blocks/custom/paragraph/paragraph-transforms.js +45 -0
- package/blocks/init/src/Blocks/custom/paragraph/paragraph.php +15 -0
- package/blocks/init/src/Blocks/custom/quote/components/quote-editor.js +12 -0
- package/blocks/init/src/Blocks/custom/quote/components/quote-options.js +14 -0
- package/blocks/init/src/Blocks/custom/quote/manifest.json +17 -0
- package/blocks/init/src/Blocks/custom/quote/quote-block.js +13 -0
- package/blocks/init/src/Blocks/custom/quote/quote.php +13 -0
- package/blocks/init/src/Blocks/custom/share/components/share-editor.js +6 -0
- package/blocks/init/src/Blocks/custom/share/components/share-options.js +12 -0
- package/blocks/init/src/Blocks/custom/share/manifest.json +19 -0
- package/blocks/init/src/Blocks/custom/share/share-block.js +13 -0
- package/blocks/init/src/Blocks/custom/share/share.php +11 -0
- package/blocks/init/src/Blocks/custom/site-footer/components/site-footer-editor.js +57 -0
- package/blocks/init/src/Blocks/custom/site-footer/components/site-footer-options.js +106 -0
- package/blocks/init/src/Blocks/custom/site-footer/manifest.json +73 -0
- package/blocks/init/src/Blocks/custom/site-footer/site-footer-block.js +13 -0
- package/blocks/init/src/Blocks/custom/site-footer/site-footer.php +72 -0
- package/blocks/init/src/Blocks/custom/site-navigation/assets/index.js +9 -0
- package/blocks/init/src/Blocks/custom/site-navigation/components/site-navigation-editor.js +42 -0
- package/blocks/init/src/Blocks/custom/site-navigation/components/site-navigation-options.js +73 -0
- package/blocks/init/src/Blocks/custom/site-navigation/manifest.json +77 -0
- package/blocks/init/src/Blocks/custom/site-navigation/site-navigation-block.js +13 -0
- package/blocks/init/src/Blocks/custom/site-navigation/site-navigation.php +99 -0
- package/blocks/init/src/Blocks/custom/table-of-contents/assets/index.js +58 -0
- package/blocks/init/src/Blocks/custom/table-of-contents/components/table-of-contents-editor.js +38 -0
- package/blocks/init/src/Blocks/custom/table-of-contents/components/table-of-contents-options.js +32 -0
- package/blocks/init/src/Blocks/custom/table-of-contents/manifest.json +48 -0
- package/blocks/init/src/Blocks/custom/table-of-contents/table-of-contents-block.js +13 -0
- package/blocks/init/src/Blocks/custom/table-of-contents/table-of-contents.php +31 -0
- package/blocks/init/src/Blocks/custom/video/components/video-editor.js +6 -0
- package/blocks/init/src/Blocks/custom/video/components/video-options.js +12 -0
- package/blocks/init/src/Blocks/custom/video/manifest.json +105 -0
- package/blocks/init/src/Blocks/custom/video/video-block.js +13 -0
- package/blocks/init/src/Blocks/custom/video/video.php +22 -0
- package/blocks/init/src/Blocks/manifest.json +14 -0
- package/blocks/init/src/Blocks/variations/card-simple/manifest.json +17 -0
- package/blocks/init/src/Blocks/wrapper/components/wrapper-editor.js +12 -0
- package/blocks/init/src/Blocks/wrapper/components/wrapper-options.js +348 -0
- package/blocks/init/src/Blocks/wrapper/manifest.json +450 -0
- package/blocks/init/src/Blocks/wrapper/styles-editor.css +13 -0
- package/blocks/init/src/Blocks/wrapper/styles.css +19 -0
- package/blocks/init/src/Blocks/wrapper/wrapper.js +30 -0
- package/blocks/init/src/Blocks/wrapper/wrapper.php +34 -0
- package/eslint.config.mjs +3 -0
- package/linters/base.config.mjs +81 -0
- package/linters/eslint.config.mjs +4 -0
- package/linters/ignore-gitignored.mjs +9 -0
- package/linters/stylelint.config.js +146 -0
- package/package.json +93 -0
- package/readme/packages.md +74 -0
- package/schemas/block.json +302 -0
- package/schemas/component.json +240 -0
- package/schemas/globalManifest.json +73 -0
- package/schemas/variation.json +83 -0
- package/scripts/components/block-inserter.js +70 -0
- package/scripts/components/file-picker.js +243 -0
- package/scripts/components/index.js +6 -0
- package/scripts/components/link-section-editor.js +319 -0
- package/scripts/components/media-picker.js +86 -0
- package/scripts/components/server-side-render.js +37 -0
- package/scripts/components/settings/settings.js +48 -0
- package/scripts/components/settings/use-theme-options.js +52 -0
- package/scripts/editor/attributes.js +304 -0
- package/scripts/editor/colors.js +64 -0
- package/scripts/editor/editor.js +139 -0
- package/scripts/editor/fetch.js +102 -0
- package/scripts/editor/hooks.js +44 -0
- package/scripts/editor/index.js +11 -0
- package/scripts/editor/options.js +152 -0
- package/scripts/editor/registration.js +901 -0
- package/scripts/editor/store.js +213 -0
- package/scripts/editor/tailwindcss.js +224 -0
- package/scripts/editor/utility.js +47 -0
- package/scripts/helpers/breakpoints.js +48 -0
- package/scripts/helpers/cookies.js +65 -0
- package/scripts/helpers/dynamic-import.js +19 -0
- package/scripts/helpers/index.js +11 -0
- package/scripts/index.js +22 -0
- package/scripts/plugins/index.js +3 -0
- package/scripts/plugins/yoast-seo.js +70 -0
- package/webpack/base.mjs +138 -0
- package/webpack/helpers.mjs +67 -0
- package/webpack/index.mjs +52 -0
- package/webpack/production.mjs +60 -0
- package/webpack/project.mjs +55 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { createHigherOrderComponent } from '@wordpress/compose';
|
|
3
|
+
import { select } from '@wordpress/data';
|
|
4
|
+
import { STORE_NAME } from './store';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Filter callback for setting up the correct data to the blocks.
|
|
8
|
+
*
|
|
9
|
+
* @abstract private
|
|
10
|
+
*/
|
|
11
|
+
export const blocksFilterHook = createHigherOrderComponent((BlockListBlock) => {
|
|
12
|
+
return (innerProps) => {
|
|
13
|
+
const { name, clientId } = innerProps;
|
|
14
|
+
|
|
15
|
+
let updatedProps = innerProps;
|
|
16
|
+
|
|
17
|
+
// Update only our blocks.
|
|
18
|
+
if (name.split('/')[0] === select(STORE_NAME).getSettingsNamespace()) {
|
|
19
|
+
updatedProps = {
|
|
20
|
+
...innerProps,
|
|
21
|
+
...{
|
|
22
|
+
// Assign clientId to our internal attribute used for inline css variables.
|
|
23
|
+
attributes: {
|
|
24
|
+
...innerProps?.attributes,
|
|
25
|
+
blockClientId: clientId,
|
|
26
|
+
},
|
|
27
|
+
block: {
|
|
28
|
+
...innerProps?.block,
|
|
29
|
+
...{
|
|
30
|
+
attributes: {
|
|
31
|
+
...innerProps?.block?.attributes,
|
|
32
|
+
blockClientId: clientId,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
// Add className to block defined by our project.
|
|
38
|
+
className: select(STORE_NAME).getSettingsGlobalVariablesCustomBlockName(),
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return <BlockListBlock {...updatedProps} />;
|
|
43
|
+
};
|
|
44
|
+
}, 'blocksFilterHook');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// All exports are sorted in alphabetical order.
|
|
2
|
+
|
|
3
|
+
export * from './attributes';
|
|
4
|
+
export * from './colors';
|
|
5
|
+
export * from './editor';
|
|
6
|
+
export * from './fetch';
|
|
7
|
+
export * from './options';
|
|
8
|
+
export * from './utility';
|
|
9
|
+
export * from './tailwindcss';
|
|
10
|
+
export { getAttributes, getExample, getFullBlockName, getFullBlockNameVariation, registerBlocks, registerVariations } from './registration';
|
|
11
|
+
export { STORE_NAME, BUILD_VERSION, setStore, setStoreGlobalWindow, setConfigFlags } from './store';
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { getPaletteColors } from './colors';
|
|
2
|
+
import { getAttrKey } from './attributes';
|
|
3
|
+
import { lowerFirst, camelCase } from '@eightshift/ui-components/utilities';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Provides the ability to override component options from the parent block/component.
|
|
7
|
+
* The components must have the same options name as attribute standard with componentName prefix.
|
|
8
|
+
*
|
|
9
|
+
* @param {string} key - Key to check.
|
|
10
|
+
* @param {array} attributes - Array of attributes.
|
|
11
|
+
* @param {object} manifest - Components/blocks manifest.json
|
|
12
|
+
* @param {boolean} [isColor=false] - If option is color return colors.
|
|
13
|
+
*
|
|
14
|
+
* @access public
|
|
15
|
+
*
|
|
16
|
+
* @returns {object}
|
|
17
|
+
*
|
|
18
|
+
* Usage:
|
|
19
|
+
* ```js
|
|
20
|
+
* // General.
|
|
21
|
+
* <SelectControl
|
|
22
|
+
* label={__('Type', 'eightshift-frontend-libs')}
|
|
23
|
+
* value={buttonType}
|
|
24
|
+
* options={getOption('buttonType', attributes, manifest)}
|
|
25
|
+
* onChange={(value) => setAttributes({ [getAttrKey('buttonType', attributes, manifest)]: value })}
|
|
26
|
+
* />
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* // Color palette.
|
|
30
|
+
* <ColorPaletteCustom
|
|
31
|
+
* label={__('Color', 'eightshift-frontend-libs')}
|
|
32
|
+
* value={buttonColor}
|
|
33
|
+
* options={getOption('buttonColor', attributes, manifest, true)}
|
|
34
|
+
* onChange={(value) => setAttributes({ [getAttrKey('buttonColor', attributes, manifest)]: value })}
|
|
35
|
+
* />
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const getOption = (key, attributes, manifest, isColor = false) => {
|
|
39
|
+
|
|
40
|
+
// Check if there is prefix in the attributes object.
|
|
41
|
+
const options = attributes?.['options'] || {};
|
|
42
|
+
|
|
43
|
+
// Get the correct key for the check in the attributes object.
|
|
44
|
+
const newKey = getAttrKey(key, attributes, manifest);
|
|
45
|
+
|
|
46
|
+
// Determine if manifest options key exists.
|
|
47
|
+
const componentOptions = manifest?.options;
|
|
48
|
+
|
|
49
|
+
// Determine if this is component or block and provide the name, not used for anything important but only to output the error msg.
|
|
50
|
+
const name = Object.prototype.hasOwnProperty.call(manifest, 'blockName') ? manifest.blockName : manifest.componentName;
|
|
51
|
+
|
|
52
|
+
// Bailout if componentOptions is missing.
|
|
53
|
+
if (typeof componentOptions === 'undefined') {
|
|
54
|
+
throw Error(`It looks like you are missing options key in your ${name} manifest.`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Bailout if key is missing in manifest options or skip if option is color type.
|
|
58
|
+
if (!Object.prototype.hasOwnProperty.call(manifest.options, key) && !isColor) {
|
|
59
|
+
throw Error(`It looks like you are missing ${key} options key in your ${name} manifest.`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Check the provided options overrides.
|
|
63
|
+
if (Object.prototype.hasOwnProperty.call(options, newKey)) {
|
|
64
|
+
|
|
65
|
+
// If color type use color output.
|
|
66
|
+
if (isColor) {
|
|
67
|
+
return getOptionColors(options[newKey]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Used for array of objects (selectControl options). If so check override by value key.
|
|
71
|
+
if (typeof componentOptions[key][0] === 'object') {
|
|
72
|
+
return componentOptions[key].filter((item) => options[newKey].includes((item.value)));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// If array only user array value for check.
|
|
76
|
+
return manifest.options[key].filter((item) => options[newKey].includes(item));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// If color type use color output. Used for current component of no parent overrides are provided.
|
|
80
|
+
if (isColor) {
|
|
81
|
+
return getOptionColors(componentOptions[key]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// If you have default name for component.
|
|
85
|
+
return manifest.options[key];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Use this hook to filter the global colors out of the component or block manifest.
|
|
90
|
+
* _This function is deprecated._
|
|
91
|
+
*
|
|
92
|
+
* @deprecated Use `getOption` instead.
|
|
93
|
+
*
|
|
94
|
+
* Requires WP => 5.3
|
|
95
|
+
*
|
|
96
|
+
* @param {array} colors Array of colors to filter.
|
|
97
|
+
*
|
|
98
|
+
* @access public
|
|
99
|
+
*
|
|
100
|
+
* @return {object}
|
|
101
|
+
*
|
|
102
|
+
* Usage:
|
|
103
|
+
* ```js
|
|
104
|
+
* <ColorPaletteCustom
|
|
105
|
+
* label={__('Color', 'eightshift-frontend-libs')}
|
|
106
|
+
* value={buttonColor}
|
|
107
|
+
* options={getOptionColors(options.colors)}
|
|
108
|
+
* onChange={(value) => setAttributes({ [getAttrKey('buttonColor', attributes, manifest)]: value })}
|
|
109
|
+
* />
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
export const getOptionColors = (colors) => {
|
|
113
|
+
const coreColors = getPaletteColors();
|
|
114
|
+
|
|
115
|
+
if (!Array.isArray(colors) || !colors.length) {
|
|
116
|
+
return Object.values(coreColors);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return colors.map((colorName) => coreColors[colorName]);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Combines two objects of options, one from current component and the other from the parent component.
|
|
124
|
+
*
|
|
125
|
+
* @param {array} [attributes={}] - Array of attributes.
|
|
126
|
+
* @param {object} [manifest={}] - Components/blocks manifest.json
|
|
127
|
+
*
|
|
128
|
+
* @access public
|
|
129
|
+
*
|
|
130
|
+
* @returns {object}
|
|
131
|
+
*
|
|
132
|
+
* Usage:
|
|
133
|
+
* ```js
|
|
134
|
+
* getOptions(attributes, manifest)
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export const getOptions = (attributes = {}, manifest = {}) => {
|
|
138
|
+
const optionsManifest = manifest?.['options'] ?? {};
|
|
139
|
+
const optionsAttributes = attributes?.['options'] ?? {};
|
|
140
|
+
const componentName = manifest['componentName'];
|
|
141
|
+
|
|
142
|
+
const output = {};
|
|
143
|
+
const prefix = (typeof attributes['prefix'] === 'undefined') ? '' : attributes['prefix'];
|
|
144
|
+
|
|
145
|
+
for (const [key, value] of Object.entries(optionsManifest)) {
|
|
146
|
+
const newKey = key.replace(`${lowerFirst(camelCase(componentName))}`, '');
|
|
147
|
+
|
|
148
|
+
output[`${prefix}${newKey}`] = value;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return Object.assign(output, optionsAttributes);
|
|
152
|
+
};
|