PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | assets/js/packages/utils/utils.js +321 -653 4.2.0-dev24.3.0-beta3 View file →
@@ -1,675 +1,343 @@
1 -/******/ (function() { // webpackBootstrap
2 -/******/ "use strict";
3 -/******/ var __webpack_modules__ = ({
1 +(function(react) {
4 2
5 -/***/ "./packages/packages/libs/utils/src/debounce.ts":
6 -/*!******************************************************!*\
7 - !*** ./packages/packages/libs/utils/src/debounce.ts ***!
8 - \******************************************************/
9 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
3 +//#region \0rolldown/runtime.js
4 + var __defProp$1 = Object.defineProperty;
5 + var __name = (target, value) => __defProp$1(target, "name", {
6 + value,
7 + configurable: true
8 + });
9 + var __exportAll = (all, no_symbols) => {
10 + let target = {};
11 + for (var name in all) {
12 + __defProp$1(target, name, {
13 + get: all[name],
14 + enumerable: true
15 + });
16 + }
17 + if (!no_symbols) {
18 + __defProp$1(target, Symbol.toStringTag, { value: "Module" });
19 + }
20 + return target;
21 + };
10 22
11 -__webpack_require__.r(__webpack_exports__);
12 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
13 -/* harmony export */ debounce: function() { return /* binding */ debounce; }
14 -/* harmony export */ });
15 -// eslint-disable-next-line @typescript-eslint/no-explicit-any
16 -function debounce(fn, wait) {
17 - let timer = null;
18 - const cancel = () => {
19 - if (!timer) {
20 - return;
21 - }
22 - clearTimeout(timer);
23 - timer = null;
24 - };
25 - const flush = (...args) => {
26 - cancel();
27 - fn(...args);
28 - };
29 - const run = (...args) => {
30 - cancel();
31 - timer = setTimeout(() => {
32 - fn(...args);
33 - timer = null;
34 - }, wait);
35 - };
36 - const pending = () => !!timer;
37 - run.flush = flush;
38 - run.cancel = cancel;
39 - run.pending = pending;
40 - return run;
41 -}
23 +//#endregion
42 24
43 -/***/ }),
25 +//#region packages/packages/libs/utils/src/errors/elementor-error.ts
26 + var __defProp = Object.defineProperty;
27 + var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
28 + enumerable: true,
29 + configurable: true,
30 + writable: true,
31 + value
32 + }) : obj[key] = value;
33 + var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
34 + var ElementorError = class extends Error {
35 + constructor(message, { code, context = null, cause = null }) {
36 + super(message, { cause });
37 + __publicField(this, "context");
38 + __publicField(this, "code");
39 + this.context = context;
40 + this.code = code;
41 + }
42 + };
44 43
45 -/***/ "./packages/packages/libs/utils/src/encoding.ts":
46 -/*!******************************************************!*\
47 - !*** ./packages/packages/libs/utils/src/encoding.ts ***!
48 - \******************************************************/
49 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
44 +//#endregion
45 +//#region packages/packages/libs/utils/src/errors/create-error.ts
46 + var createError = ({ code, message }) => {
47 + return class extends ElementorError {
48 + constructor({ cause, context } = {}) {
49 + super(message, {
50 + cause,
51 + code,
52 + context
53 + });
54 + }
55 + };
56 + };
50 57
51 -__webpack_require__.r(__webpack_exports__);
52 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
53 -/* harmony export */ decodeString: function() { return /* binding */ decodeString; },
54 -/* harmony export */ encodeString: function() { return /* binding */ encodeString; }
55 -/* harmony export */ });
56 -const encodeString = value => {
57 - const binary = Array.from(new TextEncoder().encode(value), b => String.fromCharCode(b)).join('');
58 - return btoa(binary);
59 -};
60 -const decodeString = (value, fallback) => {
61 - try {
62 - const binary = atob(value);
63 - const bytes = new Uint8Array(Array.from(binary, char => char.charCodeAt(0)));
64 - return new TextDecoder().decode(bytes);
65 - } catch {
66 - return fallback !== undefined ? fallback : '';
67 - }
68 -};
58 +//#endregion
59 +//#region packages/packages/libs/utils/src/errors/ensure-error.ts
60 + var ensureError = (error) => {
61 + if (error instanceof Error) return error;
62 + let message;
63 + let cause = null;
64 + try {
65 + message = JSON.stringify(error);
66 + } catch (e) {
67 + cause = e;
68 + message = "Unable to stringify the thrown value";
69 + }
70 + return new Error(`Unexpected non-error thrown: ${message}`, { cause });
71 + };
69 72
70 -/***/ }),
73 +//#endregion
74 +//#region packages/packages/libs/utils/src/debounce.ts
75 + function debounce(fn, wait) {
76 + let timer = null;
77 + const cancel = () => {
78 + if (!timer) return;
79 + clearTimeout(timer);
80 + timer = null;
81 + };
82 + const flush = (...args) => {
83 + cancel();
84 + fn(...args);
85 + };
86 + const run = (...args) => {
87 + cancel();
88 + timer = setTimeout(() => {
89 + fn(...args);
90 + timer = null;
91 + }, wait);
92 + };
93 + const pending = () => !!timer;
94 + run.flush = flush;
95 + run.cancel = cancel;
96 + run.pending = pending;
97 + return run;
98 + }
71 99
72 -/***/ "./packages/packages/libs/utils/src/errors/create-error.ts":
73 -/*!*****************************************************************!*\
74 - !*** ./packages/packages/libs/utils/src/errors/create-error.ts ***!
75 - \*****************************************************************/
76 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
100 +//#endregion
101 +//#region packages/packages/libs/utils/src/use-debounce-state.ts
102 + function useDebounceState(options = {}) {
103 + const { delay = 300, initialValue = "" } = options;
104 + const [debouncedValue, setDebouncedValue] = (0, react.useState)(initialValue);
105 + const [inputValue, setInputValue] = (0, react.useState)(initialValue);
106 + const runRef = (0, react.useRef)(null);
107 + (0, react.useEffect)(() => {
108 + return () => {
109 + runRef.current?.cancel?.();
110 + };
111 + }, []);
112 + const debouncedSetValue = (0, react.useCallback)((val) => {
113 + runRef.current?.cancel?.();
114 + runRef.current = debounce(() => {
115 + setDebouncedValue(val);
116 + }, delay);
117 + runRef.current();
118 + }, [delay]);
119 + const handleChange = (val) => {
120 + setInputValue(val);
121 + debouncedSetValue(val);
122 + };
123 + return {
124 + debouncedValue,
125 + inputValue,
126 + handleChange,
127 + setInputValue
128 + };
129 + }
77 130
78 -__webpack_require__.r(__webpack_exports__);
79 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
80 -/* harmony export */ createError: function() { return /* binding */ createError; }
81 -/* harmony export */ });
82 -/* harmony import */ var _elementor_error__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./elementor-error */ "./packages/packages/libs/utils/src/errors/elementor-error.ts");
131 +//#endregion
132 +//#region packages/packages/libs/utils/src/use-debounced-callback.ts
133 + function useDebouncedCallback(callback, delay) {
134 + const callbackRef = (0, react.useRef)(callback);
135 + (0, react.useEffect)(() => {
136 + callbackRef.current = callback;
137 + }, [callback]);
138 + const debounced = (0, react.useMemo)(() => debounce((...args) => callbackRef.current(...args), delay), [delay]);
139 + (0, react.useEffect)(() => {
140 + return () => {
141 + debounced.cancel();
142 + };
143 + }, [debounced]);
144 + return debounced;
145 + }
83 146
84 -const createError = ({
85 - code,
86 - message
87 -}) => {
88 - return class extends _elementor_error__WEBPACK_IMPORTED_MODULE_0__.ElementorError {
89 - constructor({
90 - cause,
91 - context
92 - } = {}) {
93 - super(message, {
94 - cause,
95 - code,
96 - context
97 - });
98 - }
99 - };
100 -};
147 +//#endregion
148 +//#region packages/packages/libs/utils/src/throttle.ts
149 + function throttle(fn, wait, shouldExecuteIgnoredCalls = false) {
150 + let timer = null;
151 + let ignoredExecution = false;
152 + const cancel = () => {
153 + if (!timer) return;
154 + clearTimeout(timer);
155 + timer = null;
156 + };
157 + const flush = (...args) => {
158 + cancel();
159 + fn(...args);
160 + };
161 + const run = (...args) => {
162 + if (timer) {
163 + ignoredExecution = true;
164 + return;
165 + }
166 + fn(...args);
167 + timer = setTimeout(() => {
168 + timer = null;
169 + if (ignoredExecution && shouldExecuteIgnoredCalls) fn(...args);
170 + ignoredExecution = false;
171 + }, wait);
172 + };
173 + const pending = () => !!timer;
174 + run.flush = flush;
175 + run.cancel = cancel;
176 + run.pending = pending;
177 + return run;
178 + }
101 179
102 -/***/ }),
180 +//#endregion
181 +//#region packages/packages/libs/utils/src/encoding.ts
182 + var encodeString = (value) => {
183 + const binary = Array.from(new TextEncoder().encode(value), (b) => String.fromCharCode(b)).join("");
184 + return btoa(binary);
185 + };
186 + var decodeString = (value, fallback) => {
187 + try {
188 + const binary = atob(value);
189 + const bytes = new Uint8Array(Array.from(binary, (char) => char.charCodeAt(0)));
190 + return new TextDecoder().decode(bytes);
191 + } catch {
192 + return fallback !== void 0 ? fallback : "";
193 + }
194 + };
103 195
104 -/***/ "./packages/packages/libs/utils/src/errors/elementor-error.ts":
105 -/*!********************************************************************!*\
106 - !*** ./packages/packages/libs/utils/src/errors/elementor-error.ts ***!
107 - \********************************************************************/
108 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
196 +//#endregion
197 +//#region packages/packages/libs/utils/src/hash.ts
198 + function hash(obj) {
199 + return JSON.stringify(obj, (_, value) => isPlainObject(value) ? Object.keys(value).sort().reduce((result, key) => {
200 + result[key] = value[key];
201 + return result;
202 + }, {}) : value);
203 + }
204 + function isPlainObject(value) {
205 + return !!value && typeof value === "object" && !Array.isArray(value);
206 + }
207 + function hashString(str, length) {
208 + let hashBasis = 5381;
209 + let i = str.length;
210 + while (i) hashBasis = hashBasis * 33 ^ str.charCodeAt(--i);
211 + const result = (hashBasis >>> 0).toString(36);
212 + if (length === void 0) return result;
213 + return result.slice(-length).padStart(length, "0");
214 + }
109 215
110 -__webpack_require__.r(__webpack_exports__);
111 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
112 -/* harmony export */ ElementorError: function() { return /* binding */ ElementorError; }
113 -/* harmony export */ });
114 -class ElementorError extends Error {
115 - constructor(message, {
116 - code,
117 - context = null,
118 - cause = null
119 - }) {
120 - super(message, {
121 - cause
122 - });
123 - this.context = context;
124 - this.code = code;
125 - }
126 -}
216 +//#endregion
217 +//#region packages/packages/libs/utils/src/use-search-state.ts
218 + function useSearchState({ localStorageKey }) {
219 + const getInitialSearchValue = () => {
220 + if (localStorageKey) {
221 + const storedValue = localStorage.getItem(localStorageKey);
222 + if (storedValue) {
223 + localStorage.removeItem(localStorageKey);
224 + return storedValue;
225 + }
226 + }
227 + return "";
228 + };
229 + const { debouncedValue, inputValue, handleChange } = useDebounceState({
230 + delay: 300,
231 + initialValue: getInitialSearchValue()
232 + });
233 + return {
234 + debouncedValue,
235 + inputValue,
236 + handleChange
237 + };
238 + }
127 239
128 -/***/ }),
240 +//#endregion
241 +//#region packages/packages/libs/utils/src/generate-unique-id.ts
242 + function generateUniqueId(prefix = "") {
243 + return `${prefix ? `${prefix}-` : ""}${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
244 + }
129 245
130 -/***/ "./packages/packages/libs/utils/src/errors/ensure-error.ts":
131 -/*!*****************************************************************!*\
132 - !*** ./packages/packages/libs/utils/src/errors/ensure-error.ts ***!
133 - \*****************************************************************/
134 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
246 +//#endregion
247 +//#region packages/packages/libs/utils/src/string-helpers.ts
248 + var capitalize = (str) => {
249 + return str.charAt(0).toUpperCase() + str.slice(1);
250 + };
135 251
136 -__webpack_require__.r(__webpack_exports__);
137 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
138 -/* harmony export */ ensureError: function() { return /* binding */ ensureError; }
139 -/* harmony export */ });
140 -const ensureError = error => {
141 - if (error instanceof Error) {
142 - return error;
143 - }
144 - let message;
145 - let cause = null;
146 - try {
147 - message = JSON.stringify(error);
148 - } catch (e) {
149 - cause = e;
150 - message = 'Unable to stringify the thrown value';
151 - }
152 - return new Error(`Unexpected non-error thrown: ${message}`, {
153 - cause
154 - });
155 -};
252 +//#endregion
253 +//#region packages/packages/libs/utils/src/version.ts
254 + var compareVersions = (a, b) => {
255 + const aParts = String(a || "0.0.0").split(".").map(Number);
256 + const bParts = String(b || "0.0.0").split(".").map(Number);
257 + for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
258 + const aVal = aParts[i] || 0;
259 + const bVal = bParts[i] || 0;
260 + if (aVal !== bVal) return aVal - bVal;
261 + }
262 + return 0;
263 + };
264 + var isVersionLessThan = (a, b) => {
265 + return compareVersions(a, b) < 0;
266 + };
267 + var isVersionGreaterOrEqual = (a, b) => {
268 + return compareVersions(a, b) >= 0;
269 + };
156 270
157 -/***/ }),
271 +//#endregion
272 +//#region packages/packages/libs/utils/src/is-pro.ts
273 + function hasProInstalled() {
274 + return window.elementor?.helpers?.hasPro?.() ?? false;
275 + }
276 + function isProActive() {
277 + if (!hasProInstalled()) return false;
278 + return window.elementorPro?.config?.isActive ?? false;
279 + }
280 + function getProVersion() {
281 + return window.elementorPro?.config?.version ?? "0.0";
282 + }
283 + function isProAtLeast(targetVersion) {
284 + const version = getProVersion();
285 + if (!version) return false;
286 + const [major, minor] = version.split(".").map(Number);
287 + const [targetMajor, targetMinor] = targetVersion.split(".").map(Number);
288 + return major > targetMajor || major === targetMajor && minor >= targetMinor;
289 + }
158 290
159 -/***/ "./packages/packages/libs/utils/src/errors/index.ts":
160 -/*!**********************************************************!*\
161 - !*** ./packages/packages/libs/utils/src/errors/index.ts ***!
162 - \**********************************************************/
163 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
291 +//#endregion
292 +//#region packages/packages/libs/utils/src/translations.ts
293 + function createTranslate({ configKey, defaultStrings = {} }) {
294 + return (key, ...args) => {
295 + const appConfig = window.elementorAppConfig;
296 + const remoteStrings = Object.fromEntries(Object.entries(appConfig?.[configKey]?.translations ?? {}).filter(([, value]) => "string" === typeof value && "" !== value.trim()));
297 + let template = {
298 + ...defaultStrings,
299 + ...remoteStrings
300 + }[key];
301 + if (!template) return key;
302 + for (let i = 0; i < args.length; i++) {
303 + template = template.replace(`%${i + 1}$s`, args[i]);
304 + template = template.replace("%s", args[i]);
305 + }
306 + return template;
307 + };
308 + }
164 309
165 -__webpack_require__.r(__webpack_exports__);
166 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
167 -/* harmony export */ ElementorError: function() { return /* reexport safe */ _elementor_error__WEBPACK_IMPORTED_MODULE_0__.ElementorError; },
168 -/* harmony export */ createError: function() { return /* reexport safe */ _create_error__WEBPACK_IMPORTED_MODULE_1__.createError; },
169 -/* harmony export */ ensureError: function() { return /* reexport safe */ _ensure_error__WEBPACK_IMPORTED_MODULE_2__.ensureError; }
170 -/* harmony export */ });
171 -/* harmony import */ var _elementor_error__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./elementor-error */ "./packages/packages/libs/utils/src/errors/elementor-error.ts");
172 -/* harmony import */ var _create_error__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./create-error */ "./packages/packages/libs/utils/src/errors/create-error.ts");
173 -/* harmony import */ var _ensure_error__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./ensure-error */ "./packages/packages/libs/utils/src/errors/ensure-error.ts");
310 +//#endregion
311 +//#region packages/packages/libs/utils/src/index.ts
312 + var src_exports = /* @__PURE__ */ __exportAll({
313 + ElementorError: () => ElementorError,
314 + capitalize: () => capitalize,
315 + compareVersions: () => compareVersions,
316 + createError: () => createError,
317 + createTranslate: () => createTranslate,
318 + debounce: () => debounce,
319 + decodeString: () => decodeString,
320 + encodeString: () => encodeString,
321 + ensureError: () => ensureError,
322 + generateUniqueId: () => generateUniqueId,
323 + hasProInstalled: () => hasProInstalled,
324 + hash: () => hash,
325 + hashString: () => hashString,
326 + isProActive: () => isProActive,
327 + isProAtLeast: () => isProAtLeast,
328 + isVersionGreaterOrEqual: () => isVersionGreaterOrEqual,
329 + isVersionLessThan: () => isVersionLessThan,
330 + throttle: () => throttle,
331 + useDebounceState: () => useDebounceState,
332 + useDebouncedCallback: () => useDebouncedCallback,
333 + useSearchState: () => useSearchState
334 + });
174 335
336 +//#endregion
337 +//#region \0elementor-package-library-entry
338 + (window.elementorV2 = window.elementorV2 || {}).utils = src_exports;
175 339
176 -
177 -
178 -/***/ }),
179 -
180 -/***/ "./packages/packages/libs/utils/src/generate-unique-id.ts":
181 -/*!****************************************************************!*\
182 - !*** ./packages/packages/libs/utils/src/generate-unique-id.ts ***!
183 - \****************************************************************/
184 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
185 -
186 -__webpack_require__.r(__webpack_exports__);
187 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
188 -/* harmony export */ generateUniqueId: function() { return /* binding */ generateUniqueId; }
189 -/* harmony export */ });
190 -function generateUniqueId(prefix = '') {
191 - const prefixStr = prefix ? `${prefix}-` : '';
192 - return `${prefixStr}${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
193 -}
194 -
195 -/***/ }),
196 -
197 -/***/ "./packages/packages/libs/utils/src/hash.ts":
198 -/*!**************************************************!*\
199 - !*** ./packages/packages/libs/utils/src/hash.ts ***!
200 - \**************************************************/
201 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
202 -
203 -__webpack_require__.r(__webpack_exports__);
204 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
205 -/* harmony export */ hash: function() { return /* binding */ hash; },
206 -/* harmony export */ hashString: function() { return /* binding */ hashString; }
207 -/* harmony export */ });
208 -/* eslint-disable no-bitwise */
209 -
210 -// Inspired by:
211 -// https://github.com/TanStack/query/blob/66ea5f2fc/packages/query-core/src/utils.ts#L212
212 -function hash(obj) {
213 - return JSON.stringify(obj, (_, value) => isPlainObject(value) ? Object.keys(value).sort().reduce((result, key) => {
214 - result[key] = value[key];
215 - return result;
216 - }, {}) : value);
217 -}
218 -function isPlainObject(value) {
219 - return !!value && typeof value === 'object' && !Array.isArray(value);
220 -}
221 -
222 -// Inspired by:
223 -// https://github.com/darkskyapp/string-hash/blob/master/index.js
224 -function hashString(str, length) {
225 - let hashBasis = 5381;
226 - let i = str.length;
227 - while (i) {
228 - hashBasis = hashBasis * 33 ^ str.charCodeAt(--i);
229 - }
230 -
231 - /* JavaScript does bitwise operations (like XOR, above) on 32-bit signed
232 - * integers. Since we want the results to be always positive, convert the
233 - * signed int to an unsigned by doing an unsigned bitshift. */
234 - const result = (hashBasis >>> 0).toString(36);
235 - if (length === undefined) {
236 - return result;
237 - }
238 - const sliced = result.slice(-length);
239 - return sliced.padStart(length, '0');
240 -}
241 -
242 -/***/ }),
243 -
244 -/***/ "./packages/packages/libs/utils/src/is-pro.ts":
245 -/*!****************************************************!*\
246 - !*** ./packages/packages/libs/utils/src/is-pro.ts ***!
247 - \****************************************************/
248 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
249 -
250 -__webpack_require__.r(__webpack_exports__);
251 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
252 -/* harmony export */ hasProInstalled: function() { return /* binding */ hasProInstalled; },
253 -/* harmony export */ isProActive: function() { return /* binding */ isProActive; },
254 -/* harmony export */ isProAtLeast: function() { return /* binding */ isProAtLeast; }
255 -/* harmony export */ });
256 -function hasProInstalled() {
257 - return window.elementor?.helpers?.hasPro?.() ?? false;
258 -}
259 -function isProActive() {
260 - if (!hasProInstalled()) {
261 - return false;
262 - }
263 - return window.elementorPro?.config?.isActive ?? false;
264 -}
265 -function getProVersion() {
266 - return window.elementorPro?.config?.version ?? '0.0';
267 -}
268 -function isProAtLeast(targetVersion) {
269 - const version = getProVersion();
270 - if (!version) {
271 - return false;
272 - }
273 - const [major, minor] = version.split('.').map(Number);
274 - const [targetMajor, targetMinor] = targetVersion.split('.').map(Number);
275 - return major > targetMajor || major === targetMajor && minor >= targetMinor;
276 -}
277 -
278 -/***/ }),
279 -
280 -/***/ "./packages/packages/libs/utils/src/string-helpers.ts":
281 -/*!************************************************************!*\
282 - !*** ./packages/packages/libs/utils/src/string-helpers.ts ***!
283 - \************************************************************/
284 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
285 -
286 -__webpack_require__.r(__webpack_exports__);
287 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
288 -/* harmony export */ capitalize: function() { return /* binding */ capitalize; }
289 -/* harmony export */ });
290 -const capitalize = str => {
291 - return str.charAt(0).toUpperCase() + str.slice(1);
292 -};
293 -
294 -/***/ }),
295 -
296 -/***/ "./packages/packages/libs/utils/src/throttle.ts":
297 -/*!******************************************************!*\
298 - !*** ./packages/packages/libs/utils/src/throttle.ts ***!
299 - \******************************************************/
300 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
301 -
302 -__webpack_require__.r(__webpack_exports__);
303 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
304 -/* harmony export */ throttle: function() { return /* binding */ throttle; }
305 -/* harmony export */ });
306 -// eslint-disable-next-line @typescript-eslint/no-explicit-any
307 -function throttle(fn, wait, shouldExecuteIgnoredCalls = false) {
308 - let timer = null;
309 - let ignoredExecution = false;
310 - const cancel = () => {
311 - if (!timer) {
312 - return;
313 - }
314 - clearTimeout(timer);
315 - timer = null;
316 - };
317 - const flush = (...args) => {
318 - cancel();
319 - fn(...args);
320 - };
321 - const run = (...args) => {
322 - if (timer) {
323 - ignoredExecution = true;
324 - return;
325 - }
326 - fn(...args);
327 - timer = setTimeout(() => {
328 - timer = null;
329 - if (ignoredExecution && shouldExecuteIgnoredCalls) {
330 - fn(...args);
331 - }
332 - ignoredExecution = false;
333 - }, wait);
334 - };
335 - const pending = () => !!timer;
336 - run.flush = flush;
337 - run.cancel = cancel;
338 - run.pending = pending;
339 - return run;
340 -}
341 -
342 -/***/ }),
343 -
344 -/***/ "./packages/packages/libs/utils/src/translations.ts":
345 -/*!**********************************************************!*\
346 - !*** ./packages/packages/libs/utils/src/translations.ts ***!
347 - \**********************************************************/
348 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
349 -
350 -__webpack_require__.r(__webpack_exports__);
351 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
352 -/* harmony export */ createTranslate: function() { return /* binding */ createTranslate; }
353 -/* harmony export */ });
354 -function createTranslate({
355 - configKey,
356 - defaultStrings = {}
357 -}) {
358 - return (key, ...args) => {
359 - const appConfig = window.elementorAppConfig;
360 - const remoteStrings = appConfig?.[configKey]?.translations;
361 - const strings = {
362 - ...defaultStrings,
363 - ...remoteStrings
364 - };
365 - let template = strings[key];
366 - if (!template) {
367 - return key;
368 - }
369 - for (let i = 0; i < args.length; i++) {
370 - template = template.replace(`%${i + 1}$s`, args[i]);
371 - template = template.replace('%s', args[i]);
372 - }
373 - return template;
374 - };
375 -}
376 -
377 -/***/ }),
378 -
379 -/***/ "./packages/packages/libs/utils/src/use-debounce-state.ts":
380 -/*!****************************************************************!*\
381 - !*** ./packages/packages/libs/utils/src/use-debounce-state.ts ***!
382 - \****************************************************************/
383 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
384 -
385 -__webpack_require__.r(__webpack_exports__);
386 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
387 -/* harmony export */ useDebounceState: function() { return /* binding */ useDebounceState; }
388 -/* harmony export */ });
389 -/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
390 -/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
391 -/* harmony import */ var _debounce__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./debounce */ "./packages/packages/libs/utils/src/debounce.ts");
392 -
393 -
394 -function useDebounceState(options = {}) {
395 - const {
396 - delay = 300,
397 - initialValue = ''
398 - } = options;
399 - const [debouncedValue, setDebouncedValue] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(initialValue);
400 - const [inputValue, setInputValue] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)(initialValue);
401 - const runRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(null);
402 - (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
403 - return () => {
404 - runRef.current?.cancel?.();
405 - };
406 - }, []);
407 - const debouncedSetValue = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(val => {
408 - runRef.current?.cancel?.();
409 - runRef.current = (0,_debounce__WEBPACK_IMPORTED_MODULE_1__.debounce)(() => {
410 - setDebouncedValue(val);
411 - }, delay);
412 - runRef.current();
413 - }, [delay]);
414 - const handleChange = val => {
415 - setInputValue(val);
416 - debouncedSetValue(val);
417 - };
418 - return {
419 - debouncedValue,
420 - inputValue,
421 - handleChange,
422 - setInputValue
423 - };
424 -}
425 -
426 -/***/ }),
427 -
428 -/***/ "./packages/packages/libs/utils/src/use-debounced-callback.ts":
429 -/*!********************************************************************!*\
430 - !*** ./packages/packages/libs/utils/src/use-debounced-callback.ts ***!
431 - \********************************************************************/
432 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
433 -
434 -__webpack_require__.r(__webpack_exports__);
435 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
436 -/* harmony export */ useDebouncedCallback: function() { return /* binding */ useDebouncedCallback; }
437 -/* harmony export */ });
438 -/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
439 -/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
440 -/* harmony import */ var _debounce__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./debounce */ "./packages/packages/libs/utils/src/debounce.ts");
441 -
442 -
443 -
444 -// eslint-disable-next-line @typescript-eslint/no-explicit-any
445 -function useDebouncedCallback(callback, delay) {
446 - const callbackRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)(callback);
447 - (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
448 - callbackRef.current = callback;
449 - }, [callback]);
450 - const debounced = (0,react__WEBPACK_IMPORTED_MODULE_0__.useMemo)(() => (0,_debounce__WEBPACK_IMPORTED_MODULE_1__.debounce)((...args) => callbackRef.current(...args), delay), [delay]);
451 - (0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
452 - return () => {
453 - debounced.cancel();
454 - };
455 - }, [debounced]);
456 - return debounced;
457 -}
458 -
459 -/***/ }),
460 -
461 -/***/ "./packages/packages/libs/utils/src/use-search-state.ts":
462 -/*!**************************************************************!*\
463 - !*** ./packages/packages/libs/utils/src/use-search-state.ts ***!
464 - \**************************************************************/
465 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
466 -
467 -__webpack_require__.r(__webpack_exports__);
468 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
469 -/* harmony export */ useSearchState: function() { return /* binding */ useSearchState; }
470 -/* harmony export */ });
471 -/* harmony import */ var _use_debounce_state__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./use-debounce-state */ "./packages/packages/libs/utils/src/use-debounce-state.ts");
472 -
473 -function useSearchState({
474 - localStorageKey
475 -}) {
476 - const getInitialSearchValue = () => {
477 - if (localStorageKey) {
478 - const storedValue = localStorage.getItem(localStorageKey);
479 - if (storedValue) {
480 - localStorage.removeItem(localStorageKey);
481 - return storedValue;
482 - }
483 - }
484 - return '';
485 - };
486 - const {
487 - debouncedValue,
488 - inputValue,
489 - handleChange
490 - } = (0,_use_debounce_state__WEBPACK_IMPORTED_MODULE_0__.useDebounceState)({
491 - delay: 300,
492 - initialValue: getInitialSearchValue()
493 - });
494 - return {
495 - debouncedValue,
496 - inputValue,
497 - handleChange
498 - };
499 -}
500 -
501 -/***/ }),
502 -
503 -/***/ "./packages/packages/libs/utils/src/version.ts":
504 -/*!*****************************************************!*\
505 - !*** ./packages/packages/libs/utils/src/version.ts ***!
506 - \*****************************************************/
507 -/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
508 -
509 -__webpack_require__.r(__webpack_exports__);
510 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
511 -/* harmony export */ compareVersions: function() { return /* binding */ compareVersions; },
512 -/* harmony export */ isVersionGreaterOrEqual: function() { return /* binding */ isVersionGreaterOrEqual; },
513 -/* harmony export */ isVersionLessThan: function() { return /* binding */ isVersionLessThan; }
514 -/* harmony export */ });
515 -const compareVersions = (a, b) => {
516 - const aParts = String(a || '0.0.0').split('.').map(Number);
517 - const bParts = String(b || '0.0.0').split('.').map(Number);
518 - for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
519 - const aVal = aParts[i] || 0;
520 - const bVal = bParts[i] || 0;
521 - if (aVal !== bVal) {
522 - return aVal - bVal;
523 - }
524 - }
525 - return 0;
526 -};
527 -const isVersionLessThan = (a, b) => {
528 - return compareVersions(a, b) < 0;
529 -};
530 -const isVersionGreaterOrEqual = (a, b) => {
531 - return compareVersions(a, b) >= 0;
532 -};
533 -
534 -/***/ }),
535 -
536 -/***/ "react":
537 -/*!**************************!*\
538 - !*** external ["React"] ***!
539 - \**************************/
540 -/***/ (function(module) {
541 -
542 -module.exports = window["React"];
543 -
544 -/***/ })
545 -
546 -/******/ });
547 -/************************************************************************/
548 -/******/ // The module cache
549 -/******/ var __webpack_module_cache__ = {};
550 -/******/
551 -/******/ // The require function
552 -/******/ function __webpack_require__(moduleId) {
553 -/******/ // Check if module is in cache
554 -/******/ var cachedModule = __webpack_module_cache__[moduleId];
555 -/******/ if (cachedModule !== undefined) {
556 -/******/ return cachedModule.exports;
557 -/******/ }
558 -/******/ // Create a new module (and put it into the cache)
559 -/******/ var module = __webpack_module_cache__[moduleId] = {
560 -/******/ // no module.id needed
561 -/******/ // no module.loaded needed
562 -/******/ exports: {}
563 -/******/ };
564 -/******/
565 -/******/ // Execute the module function
566 -/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
567 -/******/
568 -/******/ // Return the exports of the module
569 -/******/ return module.exports;
570 -/******/ }
571 -/******/
572 -/************************************************************************/
573 -/******/ /* webpack/runtime/compat get default export */
574 -/******/ !function() {
575 -/******/ // getDefaultExport function for compatibility with non-harmony modules
576 -/******/ __webpack_require__.n = function(module) {
577 -/******/ var getter = module && module.__esModule ?
578 -/******/ function() { return module['default']; } :
579 -/******/ function() { return module; };
580 -/******/ __webpack_require__.d(getter, { a: getter });
581 -/******/ return getter;
582 -/******/ };
583 -/******/ }();
584 -/******/
585 -/******/ /* webpack/runtime/define property getters */
586 -/******/ !function() {
587 -/******/ // define getter functions for harmony exports
588 -/******/ __webpack_require__.d = function(exports, definition) {
589 -/******/ for(var key in definition) {
590 -/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
591 -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
592 -/******/ }
593 -/******/ }
594 -/******/ };
595 -/******/ }();
596 -/******/
597 -/******/ /* webpack/runtime/hasOwnProperty shorthand */
598 -/******/ !function() {
599 -/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
600 -/******/ }();
601 -/******/
602 -/******/ /* webpack/runtime/make namespace object */
603 -/******/ !function() {
604 -/******/ // define __esModule on exports
605 -/******/ __webpack_require__.r = function(exports) {
606 -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
607 -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
608 -/******/ }
609 -/******/ Object.defineProperty(exports, '__esModule', { value: true });
610 -/******/ };
611 -/******/ }();
612 -/******/
613 -/************************************************************************/
614 -var __webpack_exports__ = {};
615 -// This entry needs to be wrapped in an IIFE because it needs to be isolated against other modules in the chunk.
616 -!function() {
617 -/*!***************************************************!*\
618 - !*** ./packages/packages/libs/utils/src/index.ts ***!
619 - \***************************************************/
620 -__webpack_require__.r(__webpack_exports__);
621 -/* harmony export */ __webpack_require__.d(__webpack_exports__, {
622 -/* harmony export */ ElementorError: function() { return /* reexport safe */ _errors__WEBPACK_IMPORTED_MODULE_0__.ElementorError; },
623 -/* harmony export */ capitalize: function() { return /* reexport safe */ _string_helpers__WEBPACK_IMPORTED_MODULE_9__.capitalize; },
624 -/* harmony export */ compareVersions: function() { return /* reexport safe */ _version__WEBPACK_IMPORTED_MODULE_10__.compareVersions; },
625 -/* harmony export */ createError: function() { return /* reexport safe */ _errors__WEBPACK_IMPORTED_MODULE_0__.createError; },
626 -/* harmony export */ createTranslate: function() { return /* reexport safe */ _translations__WEBPACK_IMPORTED_MODULE_12__.createTranslate; },
627 -/* harmony export */ debounce: function() { return /* reexport safe */ _debounce__WEBPACK_IMPORTED_MODULE_3__.debounce; },
628 -/* harmony export */ decodeString: function() { return /* reexport safe */ _encoding__WEBPACK_IMPORTED_MODULE_5__.decodeString; },
629 -/* harmony export */ encodeString: function() { return /* reexport safe */ _encoding__WEBPACK_IMPORTED_MODULE_5__.encodeString; },
630 -/* harmony export */ ensureError: function() { return /* reexport safe */ _errors__WEBPACK_IMPORTED_MODULE_0__.ensureError; },
631 -/* harmony export */ generateUniqueId: function() { return /* reexport safe */ _generate_unique_id__WEBPACK_IMPORTED_MODULE_8__.generateUniqueId; },
632 -/* harmony export */ hasProInstalled: function() { return /* reexport safe */ _is_pro__WEBPACK_IMPORTED_MODULE_11__.hasProInstalled; },
633 -/* harmony export */ hash: function() { return /* reexport safe */ _hash__WEBPACK_IMPORTED_MODULE_6__.hash; },
634 -/* harmony export */ hashString: function() { return /* reexport safe */ _hash__WEBPACK_IMPORTED_MODULE_6__.hashString; },
635 -/* harmony export */ isProActive: function() { return /* reexport safe */ _is_pro__WEBPACK_IMPORTED_MODULE_11__.isProActive; },
636 -/* harmony export */ isProAtLeast: function() { return /* reexport safe */ _is_pro__WEBPACK_IMPORTED_MODULE_11__.isProAtLeast; },
637 -/* harmony export */ isVersionGreaterOrEqual: function() { return /* reexport safe */ _version__WEBPACK_IMPORTED_MODULE_10__.isVersionGreaterOrEqual; },
638 -/* harmony export */ isVersionLessThan: function() { return /* reexport safe */ _version__WEBPACK_IMPORTED_MODULE_10__.isVersionLessThan; },
639 -/* harmony export */ throttle: function() { return /* reexport safe */ _throttle__WEBPACK_IMPORTED_MODULE_4__.throttle; },
640 -/* harmony export */ useDebounceState: function() { return /* reexport safe */ _use_debounce_state__WEBPACK_IMPORTED_MODULE_1__.useDebounceState; },
641 -/* harmony export */ useDebouncedCallback: function() { return /* reexport safe */ _use_debounced_callback__WEBPACK_IMPORTED_MODULE_2__.useDebouncedCallback; },
642 -/* harmony export */ useSearchState: function() { return /* reexport safe */ _use_search_state__WEBPACK_IMPORTED_MODULE_7__.useSearchState; }
643 -/* harmony export */ });
644 -/* harmony import */ var _errors__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./errors */ "./packages/packages/libs/utils/src/errors/index.ts");
645 -/* harmony import */ var _use_debounce_state__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./use-debounce-state */ "./packages/packages/libs/utils/src/use-debounce-state.ts");
646 -/* harmony import */ var _use_debounced_callback__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./use-debounced-callback */ "./packages/packages/libs/utils/src/use-debounced-callback.ts");
647 -/* harmony import */ var _debounce__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./debounce */ "./packages/packages/libs/utils/src/debounce.ts");
648 -/* harmony import */ var _throttle__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./throttle */ "./packages/packages/libs/utils/src/throttle.ts");
649 -/* harmony import */ var _encoding__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./encoding */ "./packages/packages/libs/utils/src/encoding.ts");
650 -/* harmony import */ var _hash__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./hash */ "./packages/packages/libs/utils/src/hash.ts");
651 -/* harmony import */ var _use_search_state__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./use-search-state */ "./packages/packages/libs/utils/src/use-search-state.ts");
652 -/* harmony import */ var _generate_unique_id__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./generate-unique-id */ "./packages/packages/libs/utils/src/generate-unique-id.ts");
653 -/* harmony import */ var _string_helpers__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(/*! ./string-helpers */ "./packages/packages/libs/utils/src/string-helpers.ts");
654 -/* harmony import */ var _version__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(/*! ./version */ "./packages/packages/libs/utils/src/version.ts");
655 -/* harmony import */ var _is_pro__WEBPACK_IMPORTED_MODULE_11__ = __webpack_require__(/*! ./is-pro */ "./packages/packages/libs/utils/src/is-pro.ts");
656 -/* harmony import */ var _translations__WEBPACK_IMPORTED_MODULE_12__ = __webpack_require__(/*! ./translations */ "./packages/packages/libs/utils/src/translations.ts");
657 -
658 -
659 -
660 -
661 -
662 -
663 -
664 -
665 -
666 -
667 -
668 -
669 -
670 -}();
671 -(window.elementorV2 = window.elementorV2 || {}).utils = __webpack_exports__;
672 -/******/ })()
673 -;
340 +//#endregion
341 +})(React);
674 342 window.elementorV2.utils?.init?.();
675 343 //# sourceMappingURL=utils.js.map