@secretstache/wordpress-gutenberg 0.3.0 → 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.
- package/README.md +4 -0
- package/build/index.js +8 -2
- package/build/index.js.map +1 -1
- package/package.json +5 -3
- package/src/components/ColorPaletteControl.js +24 -0
- package/src/components/DataQueryControls.js +51 -0
- package/src/components/DividersControl.js +74 -0
- package/src/components/IconPicker.js +73 -0
- package/src/components/ImageActions.js +59 -0
- package/src/components/LinkControl.js +30 -0
- package/src/components/MediaPicker.js +179 -0
- package/src/components/MediaTypeControl.js +54 -0
- package/src/components/ResourcesWrapper.js +46 -0
- package/src/components/ResponsiveSpacingControl.js +74 -0
- package/src/components/SortableSelect.js +60 -0
- package/src/components/SpacingControl.js +119 -0
- package/src/components/index.js +12 -0
- package/src/hooks/index.js +11 -0
- package/src/hooks/useAccordionItem.js +51 -0
- package/src/hooks/useAllowedBlocks.js +25 -0
- package/src/hooks/useBlockTabsData.js +90 -0
- package/src/hooks/useChildBlockPosition.js +31 -0
- package/src/hooks/useColorChange.js +12 -0
- package/src/hooks/useDataQuery.js +45 -0
- package/src/hooks/useParentBlock.js +57 -0
- package/src/hooks/usePreviewToggle.js +32 -0
- package/src/hooks/useSlider.js +24 -0
- package/src/hooks/useThemeColors.js +19 -0
- package/src/hooks/useUpdateAttribute.js +4 -0
- package/src/index.js +6 -0
- package/src/styles/_animation-file-renderer.scss +11 -0
- package/src/styles/_editor-base.scss +56 -0
- package/src/styles/_icon-picker.scss +4 -0
- package/src/styles/_image-wrapper.scss +59 -0
- package/src/styles/_link-control.scss +6 -0
- package/src/styles/_media-picker.scss +20 -0
- package/src/styles/_new-child-btn.scss +15 -0
- package/src/styles/_responsive-spacing.scss +30 -0
- package/src/styles/_root-block-appender.scss +40 -0
- package/src/styles/_sortable-select.scss +5 -0
- package/src/styles/styles.scss +12 -0
- package/src/utils/attributes.js +224 -0
- package/src/utils/constants.js +17 -0
- package/src/utils/helpers.js +175 -0
- package/src/utils/index.js +6 -0
- package/src/utils/rootBlock/README.md +71 -0
- package/src/utils/rootBlock/hideRootBlockForInlineInserter.js +13 -0
- package/src/utils/rootBlock/hideRootBlockForOtherBlocks.js +32 -0
- package/src/utils/rootBlock/index.js +4 -0
- package/src/utils/rootBlock/initRootBlockAppender.js +45 -0
- package/src/utils/rootBlock/setRootBlock.js +32 -0
- package/src/utils/waitForContainer/README.md +40 -0
- package/src/utils/waitForContainer/index.js +25 -0
- /package/build/{index.css → styles.css} +0 -0
package/src/index.js
ADDED
@@ -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,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,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,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
|
+
};
|
@@ -0,0 +1,175 @@
|
|
1
|
+
import apiFetch from '@wordpress/api-fetch';
|
2
|
+
import slugify from 'slugify';
|
3
|
+
import classNames from 'classnames';
|
4
|
+
|
5
|
+
export const loadSelectOptions = async (inputValue, postType, mapper = null) => {
|
6
|
+
const response = await apiFetch({
|
7
|
+
path: `/wp/v2/${postType}?search=${encodeURIComponent(inputValue)}`,
|
8
|
+
});
|
9
|
+
|
10
|
+
if (mapper) {
|
11
|
+
return response?.map(mapper);
|
12
|
+
} else {
|
13
|
+
return response?.map((post) => {
|
14
|
+
// Create a temporary DOM element to decode HTML entities
|
15
|
+
const tempElement = document.createElement('div');
|
16
|
+
tempElement.innerHTML = post?.title?.rendered;
|
17
|
+
|
18
|
+
return {
|
19
|
+
value: post.id,
|
20
|
+
label: tempElement.textContent || tempElement.innerText || '',
|
21
|
+
};
|
22
|
+
});
|
23
|
+
}
|
24
|
+
};
|
25
|
+
|
26
|
+
export const getSlug = (name) => slugify(name, {
|
27
|
+
replacement: '-',
|
28
|
+
lower: true,
|
29
|
+
strict: true,
|
30
|
+
});
|
31
|
+
|
32
|
+
export const cleanSvgString = (svgString) => {
|
33
|
+
if (svgString.startsWith('<?xml')) {
|
34
|
+
const endOfXml = svgString.indexOf('?>');
|
35
|
+
|
36
|
+
if (endOfXml !== -1) {
|
37
|
+
svgString = svgString.substring(endOfXml + 2);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
svgString = svgString.trim();
|
42
|
+
|
43
|
+
return svgString;
|
44
|
+
};
|
45
|
+
|
46
|
+
|
47
|
+
const SVG_MIME_TYPE = 'image/svg+xml';
|
48
|
+
|
49
|
+
export const getImage = async (mediaData) => {
|
50
|
+
const isSvg = mediaData?.mime === SVG_MIME_TYPE || mediaData?.mime_type === SVG_MIME_TYPE;
|
51
|
+
const imagePayload = {
|
52
|
+
isSvg,
|
53
|
+
imageUrl: null,
|
54
|
+
svgCode: null,
|
55
|
+
width: mediaData?.width,
|
56
|
+
height: mediaData?.height,
|
57
|
+
};
|
58
|
+
|
59
|
+
if (isSvg) {
|
60
|
+
imagePayload.svgCode = await fetch(mediaData.url).then(response => response.text()).then(cleanSvgString);
|
61
|
+
} else {
|
62
|
+
imagePayload.imageUrl = mediaData?.url;
|
63
|
+
}
|
64
|
+
|
65
|
+
return imagePayload;
|
66
|
+
};
|
67
|
+
|
68
|
+
export const getPhoneNumber = (phone) => {
|
69
|
+
if (!phone) return '';
|
70
|
+
|
71
|
+
let formatted = phone;
|
72
|
+
|
73
|
+
const pattern = /^\+\d(\d{3})(\d{3})(\d{4})$/;
|
74
|
+
const match = phone.match(pattern);
|
75
|
+
|
76
|
+
if (match) {
|
77
|
+
formatted = `${match[1]}-${match[2]}-${match[3]}`;
|
78
|
+
}
|
79
|
+
|
80
|
+
return formatted;
|
81
|
+
};
|
82
|
+
|
83
|
+
export const getLocationAddress = (location) => {
|
84
|
+
const {
|
85
|
+
street_number = '',
|
86
|
+
street_name = '',
|
87
|
+
city = '',
|
88
|
+
state_short = '',
|
89
|
+
post_code = '',
|
90
|
+
} = location;
|
91
|
+
|
92
|
+
// Start with the street number and name, trimming to remove extra spaces if one is missing
|
93
|
+
let addressParts = [`${street_number} ${street_name}`.trim()];
|
94
|
+
|
95
|
+
// Add the city with a line break, but only if there is a city name.
|
96
|
+
if (city) {
|
97
|
+
addressParts.push(`<br>${city}`);
|
98
|
+
}
|
99
|
+
|
100
|
+
// Combine state and postal code intelligently, adding only if they exist
|
101
|
+
let statePostalParts = [];
|
102
|
+
if (state_short) statePostalParts.push(state_short);
|
103
|
+
if (post_code) statePostalParts.push(post_code);
|
104
|
+
let statePostal = statePostalParts.join(' ');
|
105
|
+
|
106
|
+
if (statePostal) {
|
107
|
+
// Add a comma only if there's something before this part
|
108
|
+
addressParts.push(`${addressParts.length > 0 ? ', ' : ''}${statePostal}`);
|
109
|
+
}
|
110
|
+
|
111
|
+
return addressParts.join('');
|
112
|
+
};
|
113
|
+
|
114
|
+
export const decodeHtmlEntities = (text) => {
|
115
|
+
const tempElement = document.createElement('div');
|
116
|
+
tempElement.innerHTML = text;
|
117
|
+
|
118
|
+
return tempElement.textContent || tempElement.innerText || '';
|
119
|
+
};
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Generates a string of class names for spacing based on the provided spacing object.
|
123
|
+
*
|
124
|
+
* @param {Object} spacing - The spacing object containing margin and padding values.
|
125
|
+
* @param {Object} [desktopPrefixes] - Optional prefixes for desktop spacing classes.
|
126
|
+
* @param {string} [desktopPrefixes.marginTop='mt-'] - Prefix for desktop margin-top class.
|
127
|
+
* @param {string} [desktopPrefixes.marginBottom='mb-'] - Prefix for desktop margin-bottom class.
|
128
|
+
* @param {string} [desktopPrefixes.paddingTop='pt-'] - Prefix for desktop padding-top class.
|
129
|
+
* @param {string} [desktopPrefixes.paddingBottom='pb-'] - Prefix for desktop padding-bottom class.
|
130
|
+
* @param {Object} [mobilePrefixes] - Optional prefixes for mobile spacing classes.
|
131
|
+
* @param {string} [mobilePrefixes.marginTop='sm:mt-'] - Prefix for mobile margin-top class.
|
132
|
+
* @param {string} [mobilePrefixes.marginBottom='sm:mb-'] - Prefix for mobile margin-bottom class.
|
133
|
+
* @param {string} [mobilePrefixes.paddingTop='sm:pt-'] - Prefix for mobile padding-top class.
|
134
|
+
* @param {string} [mobilePrefixes.paddingBottom='sm:pb-'] - Prefix for mobile padding-bottom class.
|
135
|
+
* @returns {string} - A string of class names for the specified spacing.
|
136
|
+
*/
|
137
|
+
export const getSpacingClasses = (
|
138
|
+
spacing,
|
139
|
+
desktopPrefixes = {
|
140
|
+
marginTop: 'mt-',
|
141
|
+
marginBottom: 'mb-',
|
142
|
+
paddingTop: 'pt-',
|
143
|
+
paddingBottom: 'pb-',
|
144
|
+
},
|
145
|
+
mobilePrefixes = {
|
146
|
+
marginTop: 'sm:mt-',
|
147
|
+
marginBottom: 'sm:mb-',
|
148
|
+
paddingTop: 'sm:pt-',
|
149
|
+
paddingBottom: 'sm:pb-',
|
150
|
+
}
|
151
|
+
) => {
|
152
|
+
if (spacing?.desktop || spacing?.mobile) {
|
153
|
+
return classNames({
|
154
|
+
[`${desktopPrefixes.marginTop}${spacing.desktop.margin.top}`]: spacing.desktop.margin.top !== -1,
|
155
|
+
[`${desktopPrefixes.marginBottom}${spacing.desktop.margin.bottom}`]: spacing.desktop.margin.bottom !== -1,
|
156
|
+
|
157
|
+
[`${desktopPrefixes.paddingTop}${spacing.desktop.padding.top}`]: spacing.desktop.padding.top !== -1,
|
158
|
+
[`${desktopPrefixes.paddingBottom}${spacing.desktop.padding.bottom}`]: spacing.desktop.padding.bottom !== -1,
|
159
|
+
|
160
|
+
[`${mobilePrefixes.marginTop}${spacing.mobile.margin.top}`]: spacing.mobile.margin.top !== -1,
|
161
|
+
[`${mobilePrefixes.marginBottom}${spacing.mobile.margin.bottom}`]: spacing.mobile.margin.bottom !== -1,
|
162
|
+
|
163
|
+
[`${mobilePrefixes.paddingTop}${spacing.mobile.padding.top}`]: spacing.mobile.padding.top !== -1,
|
164
|
+
[`${mobilePrefixes.paddingBottom}${spacing.mobile.padding.bottom}`]: spacing.mobile.padding.bottom !== -1,
|
165
|
+
});
|
166
|
+
} else {
|
167
|
+
return classNames({
|
168
|
+
[`${desktopPrefixes.marginTop}${spacing.margin.top}`]: spacing.margin.top !== -1,
|
169
|
+
[`${desktopPrefixes.marginBottom}${spacing.margin.bottom}`]: spacing.margin.bottom !== -1,
|
170
|
+
|
171
|
+
[`${desktopPrefixes.paddingTop}${spacing.padding.top}`]: spacing.padding.top !== -1,
|
172
|
+
[`${desktopPrefixes.paddingBottom}${spacing.padding.bottom}`]: spacing.padding.bottom !== -1,
|
173
|
+
});
|
174
|
+
}
|
175
|
+
};
|