@symbo.ls/utils 3.2.3 → 3.14.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/LICENSE +25 -12
- package/README.md +106 -0
- package/array.js +162 -0
- package/cache.js +7 -0
- package/cdn.js +83 -0
- package/component.js +25 -0
- package/cookie.js +71 -0
- package/{src/detectHeight.js → detectHeight.js} +3 -3
- package/dist/cjs/array.js +168 -0
- package/dist/cjs/browser.js +0 -2
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/cdn.js +85 -0
- package/dist/cjs/component.js +45 -0
- package/dist/cjs/cookie.js +75 -0
- package/dist/cjs/date.js +1 -3
- package/dist/cjs/detectHeight.js +4 -6
- package/dist/cjs/element.js +136 -0
- package/dist/cjs/env.js +43 -0
- package/dist/cjs/events.js +39 -0
- package/dist/cjs/extends.js +434 -0
- package/dist/cjs/fibonacci.js +1 -3
- package/dist/cjs/files.js +1 -3
- package/dist/cjs/function.js +114 -0
- package/dist/cjs/globals.js +30 -0
- package/dist/cjs/if.js +48 -0
- package/dist/cjs/index.js +38 -425
- package/dist/cjs/key.js +38 -0
- package/dist/cjs/keys.js +201 -0
- package/dist/cjs/load.js +5 -7
- package/dist/cjs/log.js +34 -0
- package/dist/cjs/metadata.js +310 -0
- package/dist/cjs/methods.js +599 -0
- package/dist/cjs/node.js +35 -0
- package/dist/cjs/object.js +634 -0
- package/dist/cjs/projectKeys.js +35 -0
- package/dist/cjs/props.js +282 -0
- package/dist/cjs/scaling.js +5 -169
- package/dist/cjs/scope.js +44 -0
- package/dist/cjs/sharedLibraries.js +146 -0
- package/dist/cjs/state.js +173 -0
- package/dist/cjs/string-extra.js +72 -0
- package/dist/cjs/string.js +183 -0
- package/dist/cjs/style.js +1 -3
- package/dist/cjs/tags.js +220 -0
- package/dist/cjs/triggerEvent.js +112 -0
- package/dist/cjs/types.js +74 -0
- package/dist/cjs/update.js +42 -0
- package/dist/esm/array.js +148 -0
- package/dist/esm/browser.js +14 -0
- package/dist/esm/cache.js +6 -0
- package/dist/esm/cdn.js +65 -0
- package/dist/esm/component.js +25 -0
- package/dist/esm/cookie.js +55 -0
- package/dist/esm/date.js +11 -0
- package/dist/esm/detectHeight.js +42 -0
- package/dist/esm/element.js +116 -0
- package/dist/esm/env.js +23 -0
- package/dist/esm/events.js +19 -0
- package/dist/esm/extends.js +414 -0
- package/dist/esm/fibonacci.js +10 -0
- package/dist/esm/files.js +4 -0
- package/dist/esm/function.js +94 -0
- package/dist/esm/globals.js +10 -0
- package/dist/esm/if.js +28 -0
- package/dist/esm/index.js +37 -0
- package/dist/esm/key.js +18 -0
- package/dist/esm/keys.js +181 -0
- package/dist/esm/load.js +151 -0
- package/dist/esm/log.js +14 -0
- package/dist/esm/metadata.js +290 -0
- package/dist/esm/methods.js +569 -0
- package/dist/esm/node.js +15 -0
- package/dist/esm/object.js +621 -0
- package/dist/esm/projectKeys.js +16 -0
- package/dist/esm/props.js +262 -0
- package/dist/esm/scaling.js +15 -0
- package/dist/esm/scope.js +24 -0
- package/dist/esm/sharedLibraries.js +126 -0
- package/dist/esm/state.js +163 -0
- package/dist/esm/string-extra.js +52 -0
- package/dist/esm/string.js +163 -0
- package/dist/esm/style.js +20 -0
- package/dist/esm/tags.js +200 -0
- package/dist/esm/triggerEvent.js +92 -0
- package/dist/esm/types.js +54 -0
- package/dist/esm/update.js +22 -0
- package/dist/iife/index.js +5818 -0
- package/element.js +148 -0
- package/env.js +15 -0
- package/events.js +19 -0
- package/extends.js +519 -0
- package/function.js +145 -0
- package/globals.js +8 -0
- package/if.js +30 -0
- package/index.js +41 -0
- package/key.js +20 -0
- package/keys.js +176 -0
- package/log.js +12 -0
- package/metadata.js +392 -0
- package/methods.js +636 -0
- package/node.js +37 -0
- package/object.js +803 -0
- package/package.json +38 -22
- package/projectKeys.js +30 -0
- package/props.js +327 -0
- package/{src/scaling.js → scaling.js} +1 -1
- package/scope.js +32 -0
- package/sharedLibraries.js +184 -0
- package/state.js +203 -0
- package/{src/index.js → string-extra.js} +11 -17
- package/string.js +206 -0
- package/tags.js +176 -0
- package/triggerEvent.js +102 -0
- package/types.js +55 -0
- package/update.js +27 -0
- package/dist/cjs/package.json +0 -4
- /package/{src/browser.js → browser.js} +0 -0
- /package/{src/date.js → date.js} +0 -0
- /package/{src/fibonacci.js → fibonacci.js} +0 -0
- /package/{src/files.js → files.js} +0 -0
- /package/{src/load.js → load.js} +0 -0
- /package/{src/style.js → style.js} +0 -0
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var methods_exports = {};
|
|
30
|
+
__export(methods_exports, {
|
|
31
|
+
call: () => call,
|
|
32
|
+
defineSetter: () => defineSetter,
|
|
33
|
+
error: () => error,
|
|
34
|
+
get: () => get,
|
|
35
|
+
getChildren: () => getChildren,
|
|
36
|
+
getContext: () => getContext,
|
|
37
|
+
getDB: () => getDB,
|
|
38
|
+
getPath: () => getPath,
|
|
39
|
+
getQuery: () => getQuery,
|
|
40
|
+
getRef: () => getRef,
|
|
41
|
+
getRoot: () => getRoot,
|
|
42
|
+
getRootContext: () => getRootContext,
|
|
43
|
+
getRootData: () => getRootData,
|
|
44
|
+
getRootState: () => getRootState,
|
|
45
|
+
isMethod: () => isMethod,
|
|
46
|
+
keys: () => keys,
|
|
47
|
+
log: () => log,
|
|
48
|
+
lookdown: () => lookdown,
|
|
49
|
+
lookdownAll: () => lookdownAll,
|
|
50
|
+
lookup: () => lookup,
|
|
51
|
+
nextElement: () => nextElement,
|
|
52
|
+
parse: () => parse,
|
|
53
|
+
parseDeep: () => parseDeep,
|
|
54
|
+
previousElement: () => previousElement,
|
|
55
|
+
remove: () => remove,
|
|
56
|
+
setNodeStyles: () => setNodeStyles,
|
|
57
|
+
setProps: () => setProps,
|
|
58
|
+
spotByPath: () => spotByPath,
|
|
59
|
+
variables: () => variables,
|
|
60
|
+
verbose: () => verbose,
|
|
61
|
+
warn: () => warn
|
|
62
|
+
});
|
|
63
|
+
module.exports = __toCommonJS(methods_exports);
|
|
64
|
+
var import_triggerEvent = require("./triggerEvent.js");
|
|
65
|
+
var import_keys = require("./keys.js");
|
|
66
|
+
var import_types = require("./types.js");
|
|
67
|
+
var import_object = require("./object.js");
|
|
68
|
+
var import_env = require("./env.js");
|
|
69
|
+
var import_array = require("./array.js");
|
|
70
|
+
var import_cache = require("./cache.js");
|
|
71
|
+
const ENV = process.env.NODE_ENV;
|
|
72
|
+
function spotByPath(path) {
|
|
73
|
+
const element = this;
|
|
74
|
+
const { __ref: ref } = element;
|
|
75
|
+
const arr = [].concat(path);
|
|
76
|
+
let foundelement = ref.root[arr[0]];
|
|
77
|
+
if (!arr || !arr.length) {
|
|
78
|
+
return console.log(arr, "on", element.key, "is undefined");
|
|
79
|
+
}
|
|
80
|
+
while (foundelement.key === arr[0]) {
|
|
81
|
+
arr.shift();
|
|
82
|
+
if (!arr.length) break;
|
|
83
|
+
foundelement = foundelement[arr[0]];
|
|
84
|
+
if (!foundelement) return;
|
|
85
|
+
}
|
|
86
|
+
return foundelement;
|
|
87
|
+
}
|
|
88
|
+
function lookup(param) {
|
|
89
|
+
const el = this;
|
|
90
|
+
let { parent } = el;
|
|
91
|
+
if ((0, import_types.isFunction)(param)) {
|
|
92
|
+
if (parent.state && param(parent, parent.state, parent.context)) {
|
|
93
|
+
return parent;
|
|
94
|
+
} else if (parent.parent) return parent.lookup(param);
|
|
95
|
+
else return;
|
|
96
|
+
}
|
|
97
|
+
if (el[param]) return el[param];
|
|
98
|
+
while (parent.param !== param) {
|
|
99
|
+
if (parent[param]) return parent[param];
|
|
100
|
+
parent = parent.parent;
|
|
101
|
+
if (!parent) return;
|
|
102
|
+
}
|
|
103
|
+
return parent;
|
|
104
|
+
}
|
|
105
|
+
function lookdown(param) {
|
|
106
|
+
const el = this;
|
|
107
|
+
const { __ref: ref } = el;
|
|
108
|
+
const children = ref?.__children;
|
|
109
|
+
if (!children) return;
|
|
110
|
+
for (let i = 0; i < children.length; i++) {
|
|
111
|
+
const v = children[i];
|
|
112
|
+
const childElem = el[v];
|
|
113
|
+
if (v === param) return childElem;
|
|
114
|
+
else if ((0, import_types.isFunction)(param)) {
|
|
115
|
+
const exec = param(childElem, childElem.state, childElem.context);
|
|
116
|
+
if (childElem.state && exec) {
|
|
117
|
+
return childElem;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const lookdown2 = childElem?.lookdown?.(param);
|
|
121
|
+
if (lookdown2) return lookdown2;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
function lookdownAll(param, results = []) {
|
|
125
|
+
const el = this;
|
|
126
|
+
const { __ref: ref } = el;
|
|
127
|
+
const children = ref?.__children;
|
|
128
|
+
if (!children) return;
|
|
129
|
+
for (let i = 0; i < children.length; i++) {
|
|
130
|
+
const v = children[i];
|
|
131
|
+
const childElem = el[v];
|
|
132
|
+
if (v === param) results.push(childElem);
|
|
133
|
+
else if ((0, import_types.isFunction)(param)) {
|
|
134
|
+
const exec = param(childElem, childElem.state, childElem.context);
|
|
135
|
+
if (childElem.state && exec) results.push(childElem);
|
|
136
|
+
}
|
|
137
|
+
childElem?.lookdownAll?.(param, results);
|
|
138
|
+
}
|
|
139
|
+
return results.length ? results : void 0;
|
|
140
|
+
}
|
|
141
|
+
function setNodeStyles(params = {}) {
|
|
142
|
+
const el = this;
|
|
143
|
+
if (!el.node?.style) return;
|
|
144
|
+
for (const param in params) {
|
|
145
|
+
const value = params[param];
|
|
146
|
+
const childElem = el[param];
|
|
147
|
+
if ((0, import_types.isObject)(value) && childElem) setNodeStyles.call(childElem, value);
|
|
148
|
+
else el.node.style[param] = value;
|
|
149
|
+
}
|
|
150
|
+
return el;
|
|
151
|
+
}
|
|
152
|
+
function remove(opts) {
|
|
153
|
+
const element = this;
|
|
154
|
+
const beforeRemoveReturns = (0, import_triggerEvent.triggerEventOn)("beforeRemove", element, opts);
|
|
155
|
+
if (beforeRemoveReturns === false) return element;
|
|
156
|
+
if ((0, import_types.isFunction)(element.node.remove)) element.node.remove();
|
|
157
|
+
else if (!(0, import_env.isProduction)()) {
|
|
158
|
+
console.warn("This item cant be removed");
|
|
159
|
+
element.log();
|
|
160
|
+
}
|
|
161
|
+
delete element.parent[element.key];
|
|
162
|
+
if (element.parent.__ref) {
|
|
163
|
+
element.parent.__ref.__children = (0, import_array.removeValueFromArray)(
|
|
164
|
+
element.parent.__ref.__children,
|
|
165
|
+
element.key
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
(0, import_triggerEvent.triggerEventOn)("remove", element, opts);
|
|
169
|
+
}
|
|
170
|
+
function get(param) {
|
|
171
|
+
const element = this;
|
|
172
|
+
return element[param];
|
|
173
|
+
}
|
|
174
|
+
function setProps(param, options) {
|
|
175
|
+
const element = this;
|
|
176
|
+
if (!param) return;
|
|
177
|
+
element.update(param, options);
|
|
178
|
+
return element;
|
|
179
|
+
}
|
|
180
|
+
function getRef(key) {
|
|
181
|
+
if (key) return this.__ref && this.__ref[key];
|
|
182
|
+
return this.__ref;
|
|
183
|
+
}
|
|
184
|
+
function getChildren() {
|
|
185
|
+
const __children = this.getRef("__children");
|
|
186
|
+
return __children.map((k) => this[k]);
|
|
187
|
+
}
|
|
188
|
+
function getPath() {
|
|
189
|
+
return this.getRef().path;
|
|
190
|
+
}
|
|
191
|
+
function getRootState(param) {
|
|
192
|
+
let state = null;
|
|
193
|
+
const hasRootState = (obj) => obj.__element && obj.root?.isRootState;
|
|
194
|
+
if (!this) {
|
|
195
|
+
state = window.platformState || window.smblsApp?.state;
|
|
196
|
+
} else if (hasRootState(this)) {
|
|
197
|
+
state = this.root;
|
|
198
|
+
} else if (this.__ref && this.__ref.path) {
|
|
199
|
+
const hasPlatformState = this.state && hasRootState(this.state);
|
|
200
|
+
const hasPlatformStateOnParent = (0, import_types.isFunction)(this.state) && this.parent.state && hasRootState(this.parent.state);
|
|
201
|
+
if (hasPlatformState || hasPlatformStateOnParent) {
|
|
202
|
+
state = this.state.root || this.parent.state.root;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
if (!state) {
|
|
206
|
+
state = window.platformState || window.smblsApp?.state;
|
|
207
|
+
}
|
|
208
|
+
return param ? state?.[param] : state;
|
|
209
|
+
}
|
|
210
|
+
function getRoot(key) {
|
|
211
|
+
const rootElem = this.getRootState()?.__element;
|
|
212
|
+
return rootElem && Object.keys(rootElem).length > 0 && key ? rootElem[key] : rootElem;
|
|
213
|
+
}
|
|
214
|
+
function getRootData(key) {
|
|
215
|
+
return this.getRoot("data") && Object.keys(this.getRoot("data")).length > 0 && key ? this.getRoot("data")[key] : this.getRoot("data");
|
|
216
|
+
}
|
|
217
|
+
function getRootContext(key) {
|
|
218
|
+
const ctx = this.getRoot()?.context;
|
|
219
|
+
return key ? ctx[key] : ctx;
|
|
220
|
+
}
|
|
221
|
+
function getContext(key) {
|
|
222
|
+
const ctx = this.context;
|
|
223
|
+
return key ? ctx[key] : ctx;
|
|
224
|
+
}
|
|
225
|
+
const defineSetter = (element, key, get2, set) => Object.defineProperty(element, key, { get: get2, set });
|
|
226
|
+
function keys() {
|
|
227
|
+
const element = this;
|
|
228
|
+
const keys2 = [];
|
|
229
|
+
for (const param in element) {
|
|
230
|
+
if (
|
|
231
|
+
// (REGISTRY[param] && !DOMQ_PROPERTIES.has(param)) ||
|
|
232
|
+
!Object.prototype.hasOwnProperty.call(element, param) || import_keys.DOMQ_PROPERTIES.has(param) && !import_keys.PARSED_DOMQ_PROPERTIES.has(param)
|
|
233
|
+
) {
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
keys2.push(param);
|
|
237
|
+
}
|
|
238
|
+
return keys2;
|
|
239
|
+
}
|
|
240
|
+
function parse(excl = []) {
|
|
241
|
+
const element = this;
|
|
242
|
+
const obj = {};
|
|
243
|
+
const keyList = keys.call(element);
|
|
244
|
+
const hasChildren = keyList.includes("children");
|
|
245
|
+
const exclSet = excl.length ? new Set(excl) : null;
|
|
246
|
+
for (let i = 0; i < keyList.length; i++) {
|
|
247
|
+
const v = keyList[i];
|
|
248
|
+
if (exclSet && exclSet.has(v) || !Object.prototype.hasOwnProperty.call(element, v)) continue;
|
|
249
|
+
if (hasChildren && v === "content") continue;
|
|
250
|
+
const val = element[v];
|
|
251
|
+
if (v === "state") {
|
|
252
|
+
if (element.__ref && !element.__ref.__hasRootState) continue;
|
|
253
|
+
const parsedVal = (0, import_types.isFunction)(val && val.parse) ? val.parse() : val;
|
|
254
|
+
obj[v] = (0, import_types.isFunction)(parsedVal) ? parsedVal : JSON.parse(JSON.stringify(parsedVal || {}));
|
|
255
|
+
} else if (v === "scope") {
|
|
256
|
+
if (element.__ref && !element.__ref.__hasRootScope) continue;
|
|
257
|
+
obj[v] = JSON.parse(JSON.stringify(val || {}));
|
|
258
|
+
} else if (v === "props") {
|
|
259
|
+
const { __element, update, ...props } = element[v];
|
|
260
|
+
obj[v] = props;
|
|
261
|
+
} else if ((0, import_types.isDefined)(val) && Object.prototype.hasOwnProperty.call(element, v)) {
|
|
262
|
+
obj[v] = val;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return obj;
|
|
266
|
+
}
|
|
267
|
+
function parseDeep(excl = [], visited = /* @__PURE__ */ new WeakSet()) {
|
|
268
|
+
const element = this;
|
|
269
|
+
if (visited.has(element)) return void 0;
|
|
270
|
+
visited.add(element);
|
|
271
|
+
const obj = parse.call(element, excl);
|
|
272
|
+
const exclSet = excl.length ? new Set(excl) : null;
|
|
273
|
+
for (const v in obj) {
|
|
274
|
+
if (exclSet && exclSet.has(v) || !Object.prototype.hasOwnProperty.call(element, v)) continue;
|
|
275
|
+
const val = obj[v];
|
|
276
|
+
if (Array.isArray(val)) {
|
|
277
|
+
obj[v] = val.map(
|
|
278
|
+
(item) => (0, import_types.isObjectLike)(item) ? parseDeep.call(item, excl, visited) : item
|
|
279
|
+
);
|
|
280
|
+
} else if ((0, import_types.isObjectLike)(val)) {
|
|
281
|
+
obj[v] = parseDeep.call(val, excl, visited);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
return obj;
|
|
285
|
+
}
|
|
286
|
+
function verbose(...args) {
|
|
287
|
+
if (ENV !== "test" && ENV !== "development") return;
|
|
288
|
+
const element = this;
|
|
289
|
+
const { __ref: ref } = element;
|
|
290
|
+
console.groupCollapsed(element.key);
|
|
291
|
+
if (args.length) {
|
|
292
|
+
args.forEach((v) => console.log(`%c${v}:
|
|
293
|
+
`, "font-weight: bold", element[v]));
|
|
294
|
+
} else {
|
|
295
|
+
console.log(ref.path);
|
|
296
|
+
const keys2 = element.keys();
|
|
297
|
+
keys2.forEach((v) => console.log(`%c${v}:`, "font-weight: bold", element[v]));
|
|
298
|
+
}
|
|
299
|
+
console.log(element);
|
|
300
|
+
console.groupEnd(element.key);
|
|
301
|
+
return element;
|
|
302
|
+
}
|
|
303
|
+
function log(...params) {
|
|
304
|
+
if (ENV === "test" || ENV === "development") {
|
|
305
|
+
console.log(...params);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function warn(...params) {
|
|
309
|
+
if (ENV === "test" || ENV === "development") {
|
|
310
|
+
console.warn(...params);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
function error(...params) {
|
|
314
|
+
if (ENV === "test" || ENV === "development") {
|
|
315
|
+
if (params[params.length - 1]?.debugger) debugger;
|
|
316
|
+
if (params[params.length - 1]?.verbose) verbose.call(this);
|
|
317
|
+
throw new Error(...params);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
function nextElement() {
|
|
321
|
+
const element = this;
|
|
322
|
+
const { key, parent } = element;
|
|
323
|
+
const { __children } = parent.__ref;
|
|
324
|
+
const currentIndex = __children.indexOf(key);
|
|
325
|
+
const nextChild = __children[currentIndex + 1];
|
|
326
|
+
return parent[nextChild];
|
|
327
|
+
}
|
|
328
|
+
function previousElement(el) {
|
|
329
|
+
const element = el || this;
|
|
330
|
+
const { key, parent } = element;
|
|
331
|
+
const { __children } = parent.__ref;
|
|
332
|
+
if (!__children) return;
|
|
333
|
+
const currentIndex = __children.indexOf(key);
|
|
334
|
+
return parent[__children[currentIndex - 1]];
|
|
335
|
+
}
|
|
336
|
+
function variables(obj = {}) {
|
|
337
|
+
const element = this;
|
|
338
|
+
if (!element.data) element.data = {};
|
|
339
|
+
if (!element.data.varCaches) element.data.varCaches = {};
|
|
340
|
+
const varCaches = element.data.varCaches;
|
|
341
|
+
const changes = {};
|
|
342
|
+
let changed;
|
|
343
|
+
for (const key in obj) {
|
|
344
|
+
if (obj[key] !== varCaches[key]) {
|
|
345
|
+
changed = true;
|
|
346
|
+
changes[key] = obj[key];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
return {
|
|
350
|
+
changed: (cb) => {
|
|
351
|
+
if (!changed) return;
|
|
352
|
+
const returns = cb(changes, (0, import_object.deepClone)(varCaches));
|
|
353
|
+
for (const key in changes) {
|
|
354
|
+
varCaches[key] = changes[key];
|
|
355
|
+
}
|
|
356
|
+
return returns;
|
|
357
|
+
},
|
|
358
|
+
timeout: (cb, timeout) => {
|
|
359
|
+
if (!changed) return;
|
|
360
|
+
const t = setTimeout(() => {
|
|
361
|
+
cb(changes);
|
|
362
|
+
clearTimeout(t);
|
|
363
|
+
}, timeout);
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function call(fnKey, ...args) {
|
|
368
|
+
const context = this.context;
|
|
369
|
+
const fn = context.utils?.[fnKey] || context.functions?.[fnKey] || context.methods?.[fnKey] || context.snippets?.[fnKey];
|
|
370
|
+
if (!fn) return;
|
|
371
|
+
try {
|
|
372
|
+
const result = fn.call(this, ...args);
|
|
373
|
+
if (result && typeof result.then === "function") {
|
|
374
|
+
result.catch((err) => {
|
|
375
|
+
error.call(this, err);
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
return result;
|
|
379
|
+
} catch (err) {
|
|
380
|
+
error.call(this, err);
|
|
381
|
+
if (context?.strictMode) throw err;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
async function getDB() {
|
|
385
|
+
const element = this;
|
|
386
|
+
const db = element.context?.fetch;
|
|
387
|
+
if (!db) return null;
|
|
388
|
+
if (typeof db.select === "function") {
|
|
389
|
+
if (!db.__authInitialized && db.getSession) {
|
|
390
|
+
const { initAdapterAuth } = await import("@symbo.ls/fetch");
|
|
391
|
+
await initAdapterAuth(db, element.context);
|
|
392
|
+
}
|
|
393
|
+
return db;
|
|
394
|
+
}
|
|
395
|
+
if (db.__resolved) {
|
|
396
|
+
if (!db.__resolved.__authInitialized && db.__resolved.getSession) {
|
|
397
|
+
const { initAdapterAuth } = await import("@symbo.ls/fetch");
|
|
398
|
+
await initAdapterAuth(db.__resolved, element.context);
|
|
399
|
+
}
|
|
400
|
+
return db.__resolved;
|
|
401
|
+
}
|
|
402
|
+
if (db.__resolving) return db.__resolving;
|
|
403
|
+
const resolvePromise = import("@symbo.ls/fetch").then(({ resolveDb }) => resolveDb(db));
|
|
404
|
+
db.__resolving = resolvePromise;
|
|
405
|
+
const resolved = await resolvePromise;
|
|
406
|
+
db.__resolved = resolved;
|
|
407
|
+
element.context.fetch = resolved;
|
|
408
|
+
delete db.__resolving;
|
|
409
|
+
if (resolved.getSession) {
|
|
410
|
+
const { initAdapterAuth } = await import("@symbo.ls/fetch");
|
|
411
|
+
await initAdapterAuth(resolved, element.context);
|
|
412
|
+
}
|
|
413
|
+
return resolved;
|
|
414
|
+
}
|
|
415
|
+
function getQuery(format) {
|
|
416
|
+
const element = this;
|
|
417
|
+
const useStateQuery = format || import_cache.OPTIONS.useStateQuery || element.context?.useStateQuery;
|
|
418
|
+
if (!useStateQuery) return null;
|
|
419
|
+
const query = {};
|
|
420
|
+
buildQueryFromElement(element, query);
|
|
421
|
+
if (useStateQuery === true) return query;
|
|
422
|
+
const formatter = QUERY_FORMATTERS[useStateQuery];
|
|
423
|
+
return formatter ? formatter(query) : query;
|
|
424
|
+
}
|
|
425
|
+
const buildQueryFromElement = (element, query) => {
|
|
426
|
+
const ref = element.__ref;
|
|
427
|
+
if (!ref) return;
|
|
428
|
+
const stateKey = ref.__state;
|
|
429
|
+
if (stateKey && typeof stateKey === "string") {
|
|
430
|
+
setQueryPath(query, stateKey);
|
|
431
|
+
}
|
|
432
|
+
const children = ref.__children;
|
|
433
|
+
if (children) {
|
|
434
|
+
for (let i = 0; i < children.length; i++) {
|
|
435
|
+
const child = element[children[i]];
|
|
436
|
+
if (child && child.__ref) {
|
|
437
|
+
buildQueryFromElement(child, query);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
const contentKey = ref.contentElementKey || "content";
|
|
442
|
+
const content = element[contentKey];
|
|
443
|
+
if (content && content.__ref) {
|
|
444
|
+
buildQueryFromElement(content, query);
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
const setQueryPath = (query, path) => {
|
|
448
|
+
const clean = path.replaceAll("../", "").replaceAll("~/", "");
|
|
449
|
+
const parts = clean.split("/");
|
|
450
|
+
let current = query;
|
|
451
|
+
for (let i = 0; i < parts.length; i++) {
|
|
452
|
+
const part = parts[i];
|
|
453
|
+
if (i === parts.length - 1) {
|
|
454
|
+
if (!current[part]) current[part] = true;
|
|
455
|
+
} else {
|
|
456
|
+
if (current[part] === true) current[part] = {};
|
|
457
|
+
if (!current[part]) current[part] = {};
|
|
458
|
+
current = current[part];
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
const queryToGraphQL = (query, indent = 0) => {
|
|
463
|
+
const pad = " ".repeat(indent);
|
|
464
|
+
const entries = Object.entries(query);
|
|
465
|
+
if (!entries.length) return "";
|
|
466
|
+
const fields = entries.map(([key, value]) => {
|
|
467
|
+
if (value === true) return `${pad}${key}`;
|
|
468
|
+
return `${pad}${key} {
|
|
469
|
+
${queryToGraphQL(value, indent + 1)}
|
|
470
|
+
${pad}}`;
|
|
471
|
+
});
|
|
472
|
+
return fields.join("\n");
|
|
473
|
+
};
|
|
474
|
+
const formatGraphQL = (query) => {
|
|
475
|
+
return `{
|
|
476
|
+
${queryToGraphQL(query, 1)}
|
|
477
|
+
}`;
|
|
478
|
+
};
|
|
479
|
+
const formatJsonApi = (query) => {
|
|
480
|
+
const result = { fields: {}, include: [] };
|
|
481
|
+
const walk = (obj, prefix) => {
|
|
482
|
+
const fields = [];
|
|
483
|
+
for (const key in obj) {
|
|
484
|
+
if (obj[key] === true) {
|
|
485
|
+
fields.push(key);
|
|
486
|
+
} else {
|
|
487
|
+
const nested = prefix ? `${prefix}.${key}` : key;
|
|
488
|
+
result.include.push(nested);
|
|
489
|
+
walk(obj[key], nested);
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
if (fields.length) {
|
|
493
|
+
result.fields[prefix || "_root"] = fields;
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
walk(query, "");
|
|
497
|
+
return result;
|
|
498
|
+
};
|
|
499
|
+
const formatOData = (query) => {
|
|
500
|
+
const build = (obj) => {
|
|
501
|
+
const select2 = [];
|
|
502
|
+
const expand2 = [];
|
|
503
|
+
for (const key in obj) {
|
|
504
|
+
if (obj[key] === true) {
|
|
505
|
+
select2.push(key);
|
|
506
|
+
} else {
|
|
507
|
+
const nested = build(obj[key]);
|
|
508
|
+
const parts2 = [];
|
|
509
|
+
if (nested.select) parts2.push(`$select=${nested.select}`);
|
|
510
|
+
if (nested.expand) parts2.push(`$expand=${nested.expand}`);
|
|
511
|
+
expand2.push(parts2.length ? `${key}(${parts2.join(";")})` : key);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return {
|
|
515
|
+
select: select2.length ? select2.join(",") : "",
|
|
516
|
+
expand: expand2.length ? expand2.join(",") : ""
|
|
517
|
+
};
|
|
518
|
+
};
|
|
519
|
+
const { select, expand } = build(query);
|
|
520
|
+
const parts = [];
|
|
521
|
+
if (select) parts.push(`$select=${select}`);
|
|
522
|
+
if (expand) parts.push(`$expand=${expand}`);
|
|
523
|
+
return parts.join("&");
|
|
524
|
+
};
|
|
525
|
+
const formatSQL = (query, options) => {
|
|
526
|
+
const columns = [];
|
|
527
|
+
const joins = [];
|
|
528
|
+
const tables = /* @__PURE__ */ new Set();
|
|
529
|
+
const walk = (obj, table, parentTable) => {
|
|
530
|
+
tables.add(table);
|
|
531
|
+
if (parentTable) {
|
|
532
|
+
joins.push(
|
|
533
|
+
`LEFT JOIN ${table} ON ${table}.${parentTable}_id = ${parentTable}.id`
|
|
534
|
+
);
|
|
535
|
+
}
|
|
536
|
+
for (const key in obj) {
|
|
537
|
+
if (obj[key] === true) {
|
|
538
|
+
columns.push(`${table}.${key}`);
|
|
539
|
+
} else {
|
|
540
|
+
walk(obj[key], key, table);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
const roots = Object.keys(query);
|
|
545
|
+
if (roots.length === 1 && query[roots[0]] !== true) {
|
|
546
|
+
walk(query[roots[0]], roots[0], null);
|
|
547
|
+
} else {
|
|
548
|
+
walk(query, "_root", null);
|
|
549
|
+
}
|
|
550
|
+
const from = [...tables][0] || "_root";
|
|
551
|
+
const select = columns.length ? columns.join(", ") : "*";
|
|
552
|
+
const joinStr = joins.length ? "\n" + joins.join("\n") : "";
|
|
553
|
+
return `SELECT ${select}
|
|
554
|
+
FROM ${from}${joinStr}`;
|
|
555
|
+
};
|
|
556
|
+
const formatPaths = (query) => {
|
|
557
|
+
const paths = [];
|
|
558
|
+
const walk = (obj, prefix) => {
|
|
559
|
+
for (const key in obj) {
|
|
560
|
+
const path = prefix ? `${prefix}/${key}` : key;
|
|
561
|
+
if (obj[key] === true) {
|
|
562
|
+
paths.push(path);
|
|
563
|
+
} else {
|
|
564
|
+
walk(obj[key], path);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
walk(query, "");
|
|
569
|
+
return paths;
|
|
570
|
+
};
|
|
571
|
+
const formatSupabase = (query) => {
|
|
572
|
+
const build = (obj) => {
|
|
573
|
+
const parts = [];
|
|
574
|
+
for (const key in obj) {
|
|
575
|
+
if (obj[key] === true) {
|
|
576
|
+
parts.push(key);
|
|
577
|
+
} else {
|
|
578
|
+
parts.push(`${key}(${build(obj[key])})`);
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
return parts.join(", ");
|
|
582
|
+
};
|
|
583
|
+
const roots = Object.keys(query);
|
|
584
|
+
if (roots.length === 1 && query[roots[0]] !== true) {
|
|
585
|
+
return { from: roots[0], select: build(query[roots[0]]) };
|
|
586
|
+
}
|
|
587
|
+
return { from: null, select: build(query) };
|
|
588
|
+
};
|
|
589
|
+
const QUERY_FORMATTERS = {
|
|
590
|
+
graphql: formatGraphQL,
|
|
591
|
+
"json-api": formatJsonApi,
|
|
592
|
+
odata: formatOData,
|
|
593
|
+
sql: formatSQL,
|
|
594
|
+
supabase: formatSupabase,
|
|
595
|
+
paths: formatPaths
|
|
596
|
+
};
|
|
597
|
+
function isMethod(param, element) {
|
|
598
|
+
return Boolean(import_keys.METHODS.has(param) || element?.context?.methods?.[param]);
|
|
599
|
+
}
|
package/dist/cjs/node.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var node_exports = {};
|
|
20
|
+
__export(node_exports, {
|
|
21
|
+
isDOMNode: () => isDOMNode,
|
|
22
|
+
isHtmlElement: () => isHtmlElement,
|
|
23
|
+
isNode: () => isNode
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(node_exports);
|
|
26
|
+
var import_globals = require("./globals.js");
|
|
27
|
+
const isNode = (obj) => {
|
|
28
|
+
return (typeof Node === "object" ? obj instanceof import_globals.window.Node : obj && typeof obj === "object" && typeof obj.nodeType === "number" && typeof obj.nodeName === "string") || false;
|
|
29
|
+
};
|
|
30
|
+
const isHtmlElement = (obj) => {
|
|
31
|
+
return (typeof HTMLElement === "object" ? obj instanceof import_globals.window.HTMLElement : obj && typeof obj === "object" && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === "string") || false;
|
|
32
|
+
};
|
|
33
|
+
const isDOMNode = (obj) => {
|
|
34
|
+
return typeof import_globals.window !== "undefined" && (import_globals.window.Node && obj instanceof import_globals.window.Node || import_globals.window.Window && obj instanceof import_globals.window.Window || obj === import_globals.window || obj === document);
|
|
35
|
+
};
|