@total_onion/onion-library 1.1.7 → 1.1.8
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.
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* eslint-disable no-restricted-syntax */
|
|
2
|
+
import lazyloader from '@total_onion/onion-loader/onion-loader';
|
|
3
|
+
import(
|
|
4
|
+
'../fields-core-wordpress-block-editor-preview-v3/core-wordpress-block-editor-preview-v3.scss'
|
|
5
|
+
);
|
|
6
|
+
|
|
5
7
|
import jQuery from 'jquery';
|
|
6
8
|
const $ = jQuery;
|
|
7
9
|
|
|
@@ -40,21 +42,11 @@ $(document).ready(function ($) {
|
|
|
40
42
|
// return;
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
const ctaSelectNames = [
|
|
44
|
-
'cta_style',
|
|
45
|
-
'load_more_button_style',
|
|
46
|
-
'category_button_style',
|
|
47
|
-
'active_category_button_style',
|
|
48
|
-
'top_level_category_button_style',
|
|
49
|
-
'show_all_button_style',
|
|
50
|
-
'toggle_filter_button_style'
|
|
51
|
-
];
|
|
52
45
|
const themeSelectNames = ['page_theme'];
|
|
53
46
|
const colourData = globalThis.colourconfig;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
wppreview({lazyloaderFilepath: 'js/blocks/'});
|
|
47
|
+
colourSetup(colourData);
|
|
48
|
+
coreEditorThemeSelect(themeSelectNames);
|
|
49
|
+
wordpressPreviewJs({lazyloaderFilepath: 'js/blocks/'});
|
|
58
50
|
|
|
59
51
|
document.documentElement.insertAdjacentHTML('afterbegin', previewvars[0]);
|
|
60
52
|
document.documentElement.insertAdjacentHTML(
|
|
@@ -118,3 +110,165 @@ $(document).ready(function ($) {
|
|
|
118
110
|
});
|
|
119
111
|
}, 2000);
|
|
120
112
|
});
|
|
113
|
+
|
|
114
|
+
function wordpressPreviewJs(
|
|
115
|
+
options = {lazyloaderFilepath: '', enableLazyloading: true}
|
|
116
|
+
) {
|
|
117
|
+
function launchLazyloader(elements) {
|
|
118
|
+
lazyloader.options.assetArray = [];
|
|
119
|
+
elements.forEach((el) => {
|
|
120
|
+
lazyloader.options.assetArray.push({
|
|
121
|
+
assetKey: el.dataset.assetkey ?? ''
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
lazyloader.options.ignoreCss = true; // the css for the preview is all in the preview.scss file
|
|
125
|
+
lazyloader.options.lazy = options.enableLazyloading;
|
|
126
|
+
if (options.lazyloaderFilepath) {
|
|
127
|
+
lazyloader.options.filePath = options.lazyloaderFilepath;
|
|
128
|
+
}
|
|
129
|
+
lazyloader.options.debugLogMessages = false;
|
|
130
|
+
lazyloader.lazyloaderInit();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function observeContainer(element) {
|
|
134
|
+
const targetNode = element;
|
|
135
|
+
const config = {
|
|
136
|
+
childList: true,
|
|
137
|
+
subtree: true
|
|
138
|
+
};
|
|
139
|
+
let notLoaded = targetNode.querySelectorAll('section:not(.loaded)');
|
|
140
|
+
launchLazyloader(notLoaded);
|
|
141
|
+
|
|
142
|
+
const observer = new MutationObserver(() => {
|
|
143
|
+
notLoaded = targetNode.querySelectorAll('section:not(.loaded)');
|
|
144
|
+
if (notLoaded && notLoaded.length > 0) {
|
|
145
|
+
launchLazyloader(notLoaded);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
observer.observe(targetNode, config);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function waitForContainer() {
|
|
152
|
+
const containerCheck = setInterval(() => {
|
|
153
|
+
const container = document.querySelector(
|
|
154
|
+
'.block-editor-block-list__layout.is-root-container'
|
|
155
|
+
);
|
|
156
|
+
if (container) {
|
|
157
|
+
observeContainer(container);
|
|
158
|
+
clearInterval(containerCheck);
|
|
159
|
+
}
|
|
160
|
+
}, 300);
|
|
161
|
+
}
|
|
162
|
+
waitForContainer();
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function coreEditorThemeSelect(selectNames) {
|
|
166
|
+
if (typeof acf != 'undefined') {
|
|
167
|
+
acf.addAction(
|
|
168
|
+
'select2_init',
|
|
169
|
+
function ($select, args, settings, field) {
|
|
170
|
+
if (selectNames.find((name) => name === field.data.name)) {
|
|
171
|
+
const selected = $select.find(':selected').val()
|
|
172
|
+
? $select.find(':selected').val().replace('__', '')
|
|
173
|
+
: null;
|
|
174
|
+
$select.val(selected);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function colourSetup(colourData) {
|
|
182
|
+
try {
|
|
183
|
+
let paletteSelect = getPaletteSelect(['page_theme']);
|
|
184
|
+
let colourPalette = getColourPalette(paletteSelect, colourData);
|
|
185
|
+
if (!colourPalette) return;
|
|
186
|
+
let acfPaletteFields = [];
|
|
187
|
+
|
|
188
|
+
if (typeof acf != 'undefined') {
|
|
189
|
+
import('./colour-picker-styles.scss');
|
|
190
|
+
// This runs only once when the colour pickers initialize
|
|
191
|
+
acf.add_filter('color_picker_args', function (args, field) {
|
|
192
|
+
acfPaletteFields.push(field);
|
|
193
|
+
args.palettes = colourPalette.colours;
|
|
194
|
+
return args;
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Listener for when you change palette in the admin
|
|
199
|
+
if (paletteSelect) {
|
|
200
|
+
jQuery(paletteSelect).on('select2:select', function (event) {
|
|
201
|
+
let colourPalette = getColourPalette(paletteSelect, colourData);
|
|
202
|
+
updatePickerInputs(colourPalette, acfPaletteFields);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
} catch (error) {
|
|
206
|
+
console.log(error);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* getPaletteSelect
|
|
211
|
+
*
|
|
212
|
+
* @param {array} selectFieldNames An array containing the names of the acf pickers
|
|
213
|
+
* @returns {HTMLElement} The current picker to listen for changes
|
|
214
|
+
*/
|
|
215
|
+
function getPaletteSelect(selectFieldNames) {
|
|
216
|
+
let selectElement;
|
|
217
|
+
selectFieldNames.forEach((name) => {
|
|
218
|
+
document.querySelector(`[data-name=${name}] select`)
|
|
219
|
+
? (selectElement = document.querySelector(
|
|
220
|
+
`[data-name=${name}] select`
|
|
221
|
+
))
|
|
222
|
+
: false;
|
|
223
|
+
});
|
|
224
|
+
return selectElement;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* getColourPalette
|
|
229
|
+
*
|
|
230
|
+
* @param {HTMLElement} select
|
|
231
|
+
* @param {object} paletteData
|
|
232
|
+
* @returns {array} An array of colours as hex strings.
|
|
233
|
+
*/
|
|
234
|
+
function getColourPalette(select, paletteData) {
|
|
235
|
+
let coloursArray = [];
|
|
236
|
+
const defaultTheme = paletteData['default-theme'];
|
|
237
|
+
if (
|
|
238
|
+
select &&
|
|
239
|
+
select.value &&
|
|
240
|
+
Number(paletteData['enable-custom-theme'] > 0)
|
|
241
|
+
) {
|
|
242
|
+
document.querySelector(
|
|
243
|
+
'html'
|
|
244
|
+
).dataset.currentcolourpalette = `theme-${select.value.replace(
|
|
245
|
+
'__',
|
|
246
|
+
''
|
|
247
|
+
)}`;
|
|
248
|
+
coloursArray =
|
|
249
|
+
paletteData[`theme-${select.value.replace('__', '')}`];
|
|
250
|
+
} else {
|
|
251
|
+
coloursArray = paletteData[`theme-${defaultTheme}`];
|
|
252
|
+
document.querySelector(
|
|
253
|
+
'html'
|
|
254
|
+
).dataset.currentcolourpalette = `theme-${defaultTheme}`;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return coloursArray;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* updatePickerInputs
|
|
262
|
+
*
|
|
263
|
+
* @param {array} colourData The current colour palette to apply to the acf pickers.
|
|
264
|
+
* @param {array} fields The acf picker elements to apply the palettes to.
|
|
265
|
+
*/
|
|
266
|
+
function updatePickerInputs(colourData = [], fields = []) {
|
|
267
|
+
fields.forEach((field) => {
|
|
268
|
+
jQuery(field).find('input.wp-color-picker').iris({
|
|
269
|
+
palettes: colourData.colours
|
|
270
|
+
});
|
|
271
|
+
jQuery(field).find('input.wp-picker-clear').trigger('click');
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -29,6 +29,24 @@ html :where([style*='border-width'][data-assetkey]) {
|
|
|
29
29
|
border-style: initial;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
.iris-square {
|
|
33
|
+
display: none;
|
|
34
|
+
}
|
|
35
|
+
.iris-slider {
|
|
36
|
+
display: none;
|
|
37
|
+
}
|
|
38
|
+
.iris-picker {
|
|
39
|
+
max-height: 15px;
|
|
40
|
+
transform: translate(0px, -210%);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.block-editor-block-list__block {
|
|
44
|
+
background-color: var(--palette-default-1);
|
|
45
|
+
.edit-post-visual-editor__post-title-wrapper & {
|
|
46
|
+
background-color: transparent;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
32
50
|
.acf-block-component.acf-block-body .acf-block-preview {
|
|
33
51
|
.swiper {
|
|
34
52
|
&::before {
|