@secretstache/wordpress-gutenberg 0.2.5 → 0.3.1

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.
Files changed (54) hide show
  1. package/README.md +4 -0
  2. package/build/index.js +8 -2
  3. package/build/index.js.map +1 -1
  4. package/build/{index.css → styles.css} +44 -10
  5. package/package.json +5 -3
  6. package/src/components/ColorPaletteControl.js +24 -0
  7. package/src/components/DataQueryControls.js +51 -0
  8. package/src/components/DividersControl.js +74 -0
  9. package/src/components/IconPicker.js +73 -0
  10. package/src/components/ImageActions.js +59 -0
  11. package/src/components/LinkControl.js +30 -0
  12. package/src/components/MediaPicker.js +179 -0
  13. package/src/components/MediaTypeControl.js +54 -0
  14. package/src/components/ResourcesWrapper.js +46 -0
  15. package/src/components/ResponsiveSpacingControl.js +74 -0
  16. package/src/components/SortableSelect.js +60 -0
  17. package/src/components/SpacingControl.js +119 -0
  18. package/src/components/index.js +12 -0
  19. package/src/hooks/index.js +11 -0
  20. package/src/hooks/useAccordionItem.js +51 -0
  21. package/src/hooks/useAllowedBlocks.js +25 -0
  22. package/src/hooks/useBlockTabsData.js +90 -0
  23. package/src/hooks/useChildBlockPosition.js +31 -0
  24. package/src/hooks/useColorChange.js +12 -0
  25. package/src/hooks/useDataQuery.js +45 -0
  26. package/src/hooks/useParentBlock.js +57 -0
  27. package/src/hooks/usePreviewToggle.js +32 -0
  28. package/src/hooks/useSlider.js +24 -0
  29. package/src/hooks/useThemeColors.js +19 -0
  30. package/src/hooks/useUpdateAttribute.js +4 -0
  31. package/src/index.js +6 -0
  32. package/src/styles/_animation-file-renderer.scss +11 -0
  33. package/src/styles/_editor-base.scss +56 -0
  34. package/src/styles/_icon-picker.scss +4 -0
  35. package/src/styles/_image-wrapper.scss +59 -0
  36. package/src/styles/_link-control.scss +6 -0
  37. package/src/styles/_media-picker.scss +20 -0
  38. package/src/styles/_new-child-btn.scss +15 -0
  39. package/src/styles/_responsive-spacing.scss +30 -0
  40. package/src/styles/_root-block-appender.scss +40 -0
  41. package/src/styles/_sortable-select.scss +5 -0
  42. package/src/styles/styles.scss +12 -0
  43. package/src/utils/attributes.js +224 -0
  44. package/src/utils/constants.js +17 -0
  45. package/src/utils/helpers.js +175 -0
  46. package/src/utils/index.js +6 -0
  47. package/src/utils/rootBlock/README.md +71 -0
  48. package/src/utils/rootBlock/hideRootBlockForInlineInserter.js +13 -0
  49. package/src/utils/rootBlock/hideRootBlockForOtherBlocks.js +32 -0
  50. package/src/utils/rootBlock/index.js +4 -0
  51. package/src/utils/rootBlock/initRootBlockAppender.js +45 -0
  52. package/src/utils/rootBlock/setRootBlock.js +32 -0
  53. package/src/utils/waitForContainer/README.md +40 -0
  54. package/src/utils/waitForContainer/index.js +25 -0
@@ -0,0 +1,24 @@
1
+ import { useEffect, useRef } from '@wordpress/element';
2
+
3
+ export const useSlider = ({ isEnabled, setupSlider, dependencies = [] }) => {
4
+ const sliderElRef = useRef(null);
5
+ const sliderInstance = useRef(null);
6
+
7
+ useEffect(() => {
8
+ if (isEnabled && sliderElRef?.current) {
9
+ sliderInstance.current = setupSlider(sliderElRef.current);
10
+ }
11
+
12
+ return () => {
13
+ if (sliderInstance.current) {
14
+ sliderInstance.current?.destroy();
15
+ sliderInstance.current = null;
16
+ }
17
+ };
18
+ }, [isEnabled, ...dependencies]);
19
+
20
+ return {
21
+ sliderElRef,
22
+ sliderInstance: sliderInstance.current,
23
+ };
24
+ };
@@ -0,0 +1,19 @@
1
+ import { useSelect } from '@wordpress/data';
2
+
3
+ export const useThemeColors = (allowedColors = []) => {
4
+ return useSelect((select) => {
5
+ const { getSettings } = select('core/block-editor');
6
+ const allColors = getSettings()?.colors || [];
7
+
8
+ if (allowedColors.length > 0) {
9
+ const colorMap = new Map(allColors.map(color => [color.slug, color]));
10
+
11
+ return allowedColors
12
+ .map(slug => colorMap.get(slug))
13
+ .filter(Boolean);
14
+ }
15
+
16
+ return allColors;
17
+ }, [allowedColors]);
18
+ };
19
+
@@ -0,0 +1,4 @@
1
+ export const useUpdateAttribute = (setAttributes) => (attributeName, value) => {
2
+ setAttributes({ [attributeName]: value });
3
+ };
4
+
package/src/index.js ADDED
@@ -0,0 +1,6 @@
1
+ export * from './components';
2
+ export * from './hooks';
3
+
4
+ export * from './utils';
5
+
6
+ import './styles/styles.scss';
@@ -0,0 +1,11 @@
1
+ .bc-animation-block-json-file {
2
+ display: flex;
3
+ align-items: center;
4
+ cursor: pointer;
5
+ }
6
+
7
+ .bc-remove-btn {
8
+ margin-top: 15px;
9
+ margin-bottom: 15px;
10
+ display: flex;
11
+ }
@@ -0,0 +1,56 @@
1
+ .editor-styles-wrapper {
2
+ .edit-post-visual-editor__post-title-wrapper {
3
+ margin-top: 10px !important;
4
+ margin-bottom: 10px !important;
5
+
6
+ h1.editor-post-title {
7
+ margin: 0;
8
+ border-bottom: 1px dashed #ddd;
9
+ padding-bottom: 10px;
10
+ font-weight: normal;
11
+ font-size: 30px !important;
12
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
13
+ text-align: center;
14
+ }
15
+ }
16
+
17
+ .block-editor-block-list__layout.is-root-container {
18
+ margin-bottom: 3rem;
19
+ padding-bottom: 100px;
20
+
21
+ &.has-background {
22
+ transition:
23
+ background 1s,
24
+ color 1s;
25
+ }
26
+
27
+ & > .block-list-appender.wp-block:only-child {
28
+ p {
29
+ margin-top: 0;
30
+ margin-bottom: 0;
31
+ }
32
+ }
33
+
34
+ & > .block-list-appender.wp-block:only-child,
35
+ & > p.wp-block:only-child {
36
+ margin: 2rem 0;
37
+ }
38
+
39
+ }
40
+ }
41
+
42
+ .block-editor-block-types-list>[role=presentation] {
43
+ justify-content: center;
44
+ }
45
+
46
+ .components-base-control {
47
+ .block-editor-url-input {
48
+ input.block-editor-url-input__input {
49
+ width: 100%;
50
+ }
51
+ }
52
+ }
53
+
54
+ .components-range-control__mark-label {
55
+ margin-top: 7px !important;
56
+ }
@@ -0,0 +1,4 @@
1
+ .svg-container {
2
+ width: 100%;
3
+ height: auto;
4
+ }
@@ -0,0 +1,59 @@
1
+ .bc-image-wrapper {
2
+ position: relative;
3
+ height: auto;
4
+ align-self: start;
5
+
6
+ &__actions {
7
+ display: none;
8
+ position: absolute;
9
+ top: 0;
10
+ left: 0;
11
+ right: 0;
12
+ bottom: 0;
13
+ flex-wrap: nowrap;
14
+ justify-content: center;
15
+ align-items: center;
16
+ gap: 20px;
17
+ padding: 5px 15px;
18
+ z-index: 20;
19
+
20
+ @media screen and (max-width: 768px) {
21
+ gap: 15px;
22
+ }
23
+ }
24
+
25
+ &__btn {
26
+ font-size: 14px !important;
27
+ backdrop-filter: blur(16px) saturate(180%);
28
+ background: hsla(0, 0%, 100%, 0.75);
29
+ flex-grow: 1;
30
+ justify-content: center;
31
+ max-width: 130px;
32
+
33
+ @media screen and (max-width: 768px) {
34
+ padding: 5px;
35
+ }
36
+ }
37
+
38
+ &__overlay {
39
+ display: none;
40
+ position: absolute;
41
+ top: 0;
42
+ left: 0;
43
+ right: 0;
44
+ bottom: 0;
45
+ z-index: 10;
46
+ background: rgba(255, 255, 255, 0.3);
47
+ backdrop-filter: blur(3px);
48
+ }
49
+
50
+ &:hover {
51
+ .bc-image-wrapper__actions {
52
+ display: flex;
53
+ }
54
+
55
+ .bc-image-wrapper__overlay {
56
+ display: block;
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,6 @@
1
+ .bc-url-input {
2
+ input {
3
+ width: 100%;
4
+ border: 1px solid #949494;
5
+ }
6
+ }
@@ -0,0 +1,20 @@
1
+ .bc-selected-media-wrapper {
2
+ max-width: 200px;
3
+ cursor: pointer;
4
+ background: rgba(0, 0, 0, 0.3);
5
+ }
6
+
7
+ .bc-selected-media {
8
+ width: 100%;
9
+
10
+ &--image {
11
+ max-height: 300px;
12
+ }
13
+ }
14
+
15
+ .bc-select-btn,
16
+ .bc-remove-btn {
17
+ margin-top: 15px;
18
+ margin-bottom: 15px;
19
+ display: flex;
20
+ }
@@ -0,0 +1,15 @@
1
+ .bc-add-new-child-btn {
2
+ display: flex;
3
+ margin: 20px auto !important;
4
+ align-items: center;
5
+ flex-direction: column;
6
+ height: 50px;
7
+ justify-content: center;
8
+ width: 100%;
9
+ user-select: text;
10
+ font-family: inherit;
11
+ font-size: 100%;
12
+ padding: 12px !important;
13
+ box-shadow: inset 0 0 0 1px #1e1e1e;
14
+ color: #1e1e1e;
15
+ }
@@ -0,0 +1,30 @@
1
+ .bc-responsive-spacing-tab {
2
+ &:last-child {
3
+ margin-bottom: 2rem;
4
+ }
5
+ }
6
+
7
+ .bc-spacing-control-wrapper {
8
+ margin-bottom: 35px;
9
+ }
10
+
11
+ .bc-spacing-range-control {
12
+ padding: 0 6px;
13
+
14
+ .components-base-control__label {
15
+ margin-left: -9px;
16
+ }
17
+
18
+ .components-range-control__root {
19
+ .components-range-control__wrapper {
20
+ margin-bottom: 0;
21
+
22
+ .components-range-control__marks {
23
+ .components-range-control__mark-label {
24
+ left: 8px !important;
25
+ margin-top: 7px !important;
26
+ }
27
+ }
28
+ }
29
+ }
30
+ }
@@ -0,0 +1,40 @@
1
+ .root-block-appender {
2
+ position: absolute;
3
+ bottom: 30px;
4
+ left: 50%;
5
+ transform: translateX(-50%);
6
+ width: calc(100% - var(--content-padding) * 2);
7
+
8
+ &::after {
9
+ content: attr(data-tooltip);
10
+ position: absolute;
11
+ left: 50%;
12
+ bottom: -30px;
13
+ transform: translateX(-50%);
14
+ z-index: 1;
15
+ visibility: hidden;
16
+ opacity: 0;
17
+ transition: opacity 0.3s;
18
+ width: max-content;
19
+ max-width: 200px;
20
+ white-space: nowrap;
21
+ background: #000;
22
+ border-radius: 2px;
23
+ color: #f0f0f0;
24
+ font-size: 12px;
25
+ line-height: 1.4;
26
+ padding: 4px 8px;
27
+ text-align: center;
28
+ font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen-Sans, Ubuntu, Cantarell, Helvetica Neue, sans-serif;
29
+ }
30
+
31
+ &:hover::after {
32
+ visibility: visible;
33
+ opacity: 1;
34
+ }
35
+
36
+ // hide the default appender
37
+ & ~ .block-list-appender.wp-block {
38
+ display: none;
39
+ }
40
+ }
@@ -0,0 +1,5 @@
1
+ .react-select {
2
+ &__input {
3
+ box-shadow: none !important;
4
+ }
5
+ }
@@ -0,0 +1,12 @@
1
+ .block-editor__container {
2
+ @import "editor-base";
3
+ @import "animation-file-renderer";
4
+ @import "icon-picker";
5
+ @import "image-wrapper";
6
+ @import "link-control";
7
+ @import "media-picker";
8
+ @import "sortable-select";
9
+ @import "responsive-spacing";
10
+ @import "new-child-btn";
11
+ @import "root-block-appender";
12
+ }
@@ -0,0 +1,224 @@
1
+ export const linkControlAttribute = {
2
+ linkLabel: {
3
+ type: 'string',
4
+ default: '',
5
+ },
6
+ linkSource: {
7
+ type: 'string',
8
+ default: '#',
9
+ },
10
+ linkIsOpenInNewTab: {
11
+ type: 'boolean',
12
+ default: false,
13
+ },
14
+ };
15
+
16
+ export const mediaAttribute = {
17
+ media: {
18
+ type: 'object',
19
+ default: {
20
+ id: null,
21
+ url: '',
22
+ alt: '',
23
+ filename: '',
24
+ },
25
+ },
26
+ };
27
+
28
+ export const contentAttribute = {
29
+ title: {
30
+ type: 'string',
31
+ default: 'Title',
32
+ },
33
+ description: {
34
+ type: 'string',
35
+ default: 'Description',
36
+ },
37
+ };
38
+
39
+ export const animationAttribute = {
40
+ animationFile: {
41
+ type: 'object',
42
+ default: {
43
+ id: null,
44
+ url: null,
45
+ name: null,
46
+ filename: null,
47
+ mime: null,
48
+ },
49
+ },
50
+ isAnimationLooped: {
51
+ type: 'boolean',
52
+ default: true,
53
+ },
54
+ };
55
+
56
+ export const curatedPostsAttribute = {
57
+ curatedPosts: {
58
+ type: 'array',
59
+ default: [],
60
+ items: {
61
+ type: 'object',
62
+ properties: {
63
+ value: {
64
+ type: 'number'
65
+ },
66
+ label: {
67
+ type: 'string'
68
+ }
69
+ }
70
+ }
71
+ }
72
+ };
73
+
74
+ export const curatedCategoriesAttribute = {
75
+ curatedCategories: {
76
+ type: 'array',
77
+ default: [],
78
+ items: {
79
+ type: 'object',
80
+ properties: {
81
+ value: {
82
+ type: 'number'
83
+ },
84
+ label: {
85
+ type: 'string'
86
+ }
87
+ }
88
+ }
89
+ }
90
+ };
91
+
92
+ export const numberOfPostsAttribute = {
93
+ numberOfPosts: {
94
+ type: 'number',
95
+ default: 5,
96
+ },
97
+ };
98
+
99
+ export const getDataQueryAttributes = (
100
+ sourcesList,
101
+ queriesList,
102
+ hasCuratedPosts = true,
103
+ hasCuratedCategories = false,
104
+ hasNumberOfPosts = false,
105
+ ) => {
106
+ let dataSourceConfig = {
107
+ type: 'string'
108
+ };
109
+
110
+ if (sourcesList && sourcesList?.length > 0) {
111
+ dataSourceConfig.enum = sourcesList;
112
+ dataSourceConfig.default = sourcesList[0].value;
113
+ }
114
+
115
+ let queryTypeConfig = {
116
+ type: 'string'
117
+ };
118
+
119
+ if (queriesList && queriesList?.length > 0) {
120
+ queryTypeConfig.enum = [
121
+ ...queriesList
122
+ ];
123
+ queryTypeConfig.default = queriesList[0].value;
124
+ }
125
+
126
+ return {
127
+ dataSource: dataSourceConfig,
128
+ queryType: queryTypeConfig,
129
+ ...(hasCuratedPosts ? curatedPostsAttribute : {}),
130
+ ...(hasCuratedCategories ? curatedCategoriesAttribute : {}),
131
+ ...(hasNumberOfPosts ? numberOfPostsAttribute : {}),
132
+ };
133
+ };
134
+
135
+ /**
136
+ * Returns the base background attribute object with configurable default background color and media type.
137
+ *
138
+ * @param {string} [defaultBackgroundMediaType=''] - The default background media type.
139
+ * @param {Object} defaultBackgroundColor - The background color configuration.
140
+ * @param {string} defaultBackgroundColor.value - The hex value of the background color.
141
+ * @param {string} defaultBackgroundColor.slug - The slug of the background color.
142
+ * @returns {Object} The base background attribute object.
143
+ */
144
+ export const getBaseBackgroundAttributes = (
145
+ defaultBackgroundMediaType = '',
146
+ defaultBackgroundColor = { value: '', slug: '' },
147
+ ) => {
148
+ return {
149
+ isIncludeBackgroundMedia: {
150
+ type: 'boolean',
151
+ default: false,
152
+ },
153
+ backgroundMediaType: {
154
+ type: 'string',
155
+ default: '',
156
+ },
157
+ backgroundColor: {
158
+ type: 'object',
159
+ default: defaultBackgroundColor,
160
+ },
161
+ backgroundImage: {
162
+ type: 'object',
163
+ default: {
164
+ id: null,
165
+ url: '',
166
+ },
167
+ },
168
+ backgroundVideo: {
169
+ type: 'object',
170
+ default: {
171
+ id: null,
172
+ url: '',
173
+ },
174
+ },
175
+ isIncludeOverlay: {
176
+ type: 'boolean',
177
+ default: false,
178
+ },
179
+ };
180
+ };
181
+
182
+ export const spacingAttribute = {
183
+ spacing: {
184
+ type: 'object',
185
+ default: {
186
+ margin: {
187
+ top: -1,
188
+ bottom: -1,
189
+ },
190
+ padding: {
191
+ top: -1,
192
+ bottom: -1,
193
+ }
194
+ },
195
+ },
196
+ }
197
+
198
+ export const responsiveSpacingAttribute = {
199
+ spacing: {
200
+ type: 'object',
201
+ default: {
202
+ desktop: {
203
+ margin: {
204
+ top: -1,
205
+ bottom: -1,
206
+ },
207
+ padding: {
208
+ top: -1,
209
+ bottom: -1,
210
+ }
211
+ },
212
+ mobile: {
213
+ margin: {
214
+ top: -1,
215
+ bottom: -1,
216
+ },
217
+ padding: {
218
+ top: -1,
219
+ bottom: -1,
220
+ }
221
+ }
222
+ }
223
+ }
224
+ }
@@ -0,0 +1,17 @@
1
+ export const QUERY_TYPES = {
2
+ LATEST: 'latest',
3
+ CURATED: 'curated',
4
+ BY_CATEGORY: 'by_category'
5
+ };
6
+
7
+ export const MEDIA_TYPES = {
8
+ IMAGE: 'image',
9
+ VIDEO: 'video',
10
+ ANIMATION: 'animation',
11
+ };
12
+
13
+ export const MEDIA_TYPE_LABELS = {
14
+ [MEDIA_TYPES.IMAGE]: 'Image',
15
+ [MEDIA_TYPES.VIDEO]: 'Video',
16
+ [MEDIA_TYPES.ANIMATION]: 'Animation',
17
+ };