domql 3.6.8 → 3.7.3
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/dist/iife/index.js +100 -41
- package/package.json +4 -4
package/dist/iife/index.js
CHANGED
|
@@ -631,8 +631,38 @@ var Domql = (() => {
|
|
|
631
631
|
});
|
|
632
632
|
|
|
633
633
|
// ../utils/dist/esm/function.js
|
|
634
|
+
var hasHandlerPlugin, resolveHandler, runPluginHook;
|
|
634
635
|
var init_function = __esm({
|
|
635
636
|
"../utils/dist/esm/function.js"() {
|
|
637
|
+
hasHandlerPlugin = (ctx) => {
|
|
638
|
+
const plugins = ctx?.plugins;
|
|
639
|
+
if (!plugins || !plugins.length) return false;
|
|
640
|
+
for (const plugin of plugins) {
|
|
641
|
+
if (plugin.resolveHandler) return true;
|
|
642
|
+
}
|
|
643
|
+
return false;
|
|
644
|
+
};
|
|
645
|
+
resolveHandler = (handler, element) => {
|
|
646
|
+
if (typeof handler === "function") return handler;
|
|
647
|
+
const plugins = element?.context?.plugins;
|
|
648
|
+
if (!plugins) return handler;
|
|
649
|
+
for (const plugin of plugins) {
|
|
650
|
+
if (plugin.resolveHandler) {
|
|
651
|
+
const resolved = plugin.resolveHandler(handler, element);
|
|
652
|
+
if (typeof resolved === "function") return resolved;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
return handler;
|
|
656
|
+
};
|
|
657
|
+
runPluginHook = (hookName, element, ...args) => {
|
|
658
|
+
const plugins = element?.context?.plugins;
|
|
659
|
+
if (!plugins) return;
|
|
660
|
+
for (const plugin of plugins) {
|
|
661
|
+
if (typeof plugin[hookName] === "function") {
|
|
662
|
+
plugin[hookName](element, ...args);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
};
|
|
636
666
|
}
|
|
637
667
|
});
|
|
638
668
|
|
|
@@ -1255,7 +1285,9 @@ var Domql = (() => {
|
|
|
1255
1285
|
if (isFunction(origEvent)) {
|
|
1256
1286
|
on[eventName] = (...args) => {
|
|
1257
1287
|
const originalEventRetunrs = origEvent(...args);
|
|
1258
|
-
if (originalEventRetunrs !== false)
|
|
1288
|
+
if (originalEventRetunrs !== false) {
|
|
1289
|
+
if (isFunction(funcFromProps)) return funcFromProps(...args);
|
|
1290
|
+
}
|
|
1259
1291
|
};
|
|
1260
1292
|
} else on[eventName] = funcFromProps;
|
|
1261
1293
|
}
|
|
@@ -1271,7 +1303,8 @@ var Domql = (() => {
|
|
|
1271
1303
|
const cachedKeys = opts.cachedKeys || [];
|
|
1272
1304
|
for (const key in obj) {
|
|
1273
1305
|
const value = obj[key];
|
|
1274
|
-
const
|
|
1306
|
+
const isOnKey = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key[2] === key[2].toUpperCase();
|
|
1307
|
+
const isEventHandler = isOnKey && (isFunction(value) || value != null && hasHandlerPlugin(this.context));
|
|
1275
1308
|
if (isEventHandler) {
|
|
1276
1309
|
const eventName = lowercaseFirstLetter(key.slice(2));
|
|
1277
1310
|
if (obj.on) obj.on[eventName] = value;
|
|
@@ -1311,8 +1344,8 @@ var Domql = (() => {
|
|
|
1311
1344
|
for (const key in obj.props) {
|
|
1312
1345
|
const value = obj.props[key];
|
|
1313
1346
|
const isEvent = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110;
|
|
1314
|
-
const
|
|
1315
|
-
if (isEvent &&
|
|
1347
|
+
const isHandler = isFunction(value) || value != null && hasHandlerPlugin(this.context);
|
|
1348
|
+
if (isEvent && isHandler) {
|
|
1316
1349
|
addEventFromProps(key, obj);
|
|
1317
1350
|
delete obj.props[key];
|
|
1318
1351
|
continue;
|
|
@@ -1363,6 +1396,7 @@ var Domql = (() => {
|
|
|
1363
1396
|
init_object();
|
|
1364
1397
|
init_types();
|
|
1365
1398
|
init_string();
|
|
1399
|
+
init_function();
|
|
1366
1400
|
RE_UPPER = /^[A-Z]/;
|
|
1367
1401
|
RE_DIGITS = /^\d+$/;
|
|
1368
1402
|
CSS_SELECTOR_PREFIXES = /* @__PURE__ */ new Set([":", "@", "[", "*", "+", "~", "&", ">", "$", "-", ".", "!"]);
|
|
@@ -1786,6 +1820,7 @@ var Domql = (() => {
|
|
|
1786
1820
|
var init_triggerEvent = __esm({
|
|
1787
1821
|
"../utils/dist/esm/triggerEvent.js"() {
|
|
1788
1822
|
init_types();
|
|
1823
|
+
init_function();
|
|
1789
1824
|
getOnOrPropsEvent = (param, element) => {
|
|
1790
1825
|
const onEvent = element.on?.[param];
|
|
1791
1826
|
if (onEvent) return onEvent;
|
|
@@ -1795,6 +1830,7 @@ var Domql = (() => {
|
|
|
1795
1830
|
return props[propKey];
|
|
1796
1831
|
};
|
|
1797
1832
|
applyEvent = (param, element, state2, context, options) => {
|
|
1833
|
+
param = resolveHandler(param, element);
|
|
1798
1834
|
if (!isFunction(param)) return;
|
|
1799
1835
|
try {
|
|
1800
1836
|
const result = param.call(
|
|
@@ -1821,6 +1857,7 @@ var Domql = (() => {
|
|
|
1821
1857
|
if (!element) {
|
|
1822
1858
|
throw new Error("Element is required");
|
|
1823
1859
|
}
|
|
1860
|
+
runPluginHook(param, element, options);
|
|
1824
1861
|
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
1825
1862
|
if (appliedFunction) {
|
|
1826
1863
|
const { state: state2, context } = element;
|
|
@@ -1828,6 +1865,7 @@ var Domql = (() => {
|
|
|
1828
1865
|
}
|
|
1829
1866
|
};
|
|
1830
1867
|
applyEventUpdate = (param, updatedObj, element, state2, context, options) => {
|
|
1868
|
+
param = resolveHandler(param, element);
|
|
1831
1869
|
if (!isFunction(param)) return;
|
|
1832
1870
|
try {
|
|
1833
1871
|
const result = param.call(
|
|
@@ -1852,6 +1890,7 @@ var Domql = (() => {
|
|
|
1852
1890
|
}
|
|
1853
1891
|
};
|
|
1854
1892
|
triggerEventOnUpdate = (param, updatedObj, element, options) => {
|
|
1893
|
+
runPluginHook(param, element, updatedObj, options);
|
|
1855
1894
|
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
1856
1895
|
if (appliedFunction) {
|
|
1857
1896
|
const { state: state2, context } = element;
|
|
@@ -2307,13 +2346,14 @@ var Domql = (() => {
|
|
|
2307
2346
|
createAdapter: () => createAdapter,
|
|
2308
2347
|
default: () => fetch_default,
|
|
2309
2348
|
executeFetch: () => executeFetch,
|
|
2349
|
+
fetchPlugin: () => fetchPlugin,
|
|
2310
2350
|
initAdapterAuth: () => initAdapterAuth,
|
|
2311
2351
|
parseDuration: () => parseDuration,
|
|
2312
2352
|
queryClient: () => queryClient,
|
|
2313
2353
|
registerAdapter: () => registerAdapter,
|
|
2314
2354
|
resolveDb: () => resolveDb
|
|
2315
2355
|
});
|
|
2316
|
-
var ADAPTER_METHODS, BUILTIN_ADAPTERS, registerAdapter, createAdapter, resolveDb, parseDuration, cacheStore, querySubscribers, activeQueries, buildCacheKey, getCacheEntry, setCacheEntry, invalidateCache, removeCache, parseCacheConfig, gcTimer, startGC, DEFAULT_RETRY, DEFAULT_RETRY_DELAY, resolveRetryConfig, withRetry, globalListeners, globalListenersAttached, attachGlobalListeners, resolveFetchConfig, resolveParamsSync, resolveParams, initAdapterAuth, resolveAdapter, triggerCallback, collectFormData, updateElementState, setFetchStatus, runFetch, bindEvent, bindAutoRefetch, applyOptimisticUpdate, rollbackOptimistic, runMutation, executeFetch, queryClient, fetch_default;
|
|
2356
|
+
var ADAPTER_METHODS, BUILTIN_ADAPTERS, registerAdapter, createAdapter, resolveDb, parseDuration, cacheStore, querySubscribers, activeQueries, buildCacheKey, getCacheEntry, setCacheEntry, invalidateCache, removeCache, parseCacheConfig, gcTimer, startGC, DEFAULT_RETRY, DEFAULT_RETRY_DELAY, resolveRetryConfig, withRetry, globalListeners, globalListenersAttached, attachGlobalListeners, resolveFetchConfig, resolveParamsSync, resolveLanguage, resolveParams, initAdapterAuth, resolveAdapter, triggerCallback, collectFormData, updateElementState, setFetchStatus, runFetch, bindEvent, bindAutoRefetch, applyOptimisticUpdate, rollbackOptimistic, runMutation, executeFetch, queryClient, fetchPlugin, fetch_default;
|
|
2317
2357
|
var init_fetch = __esm({
|
|
2318
2358
|
"../../plugins/fetch/index.js"() {
|
|
2319
2359
|
"use strict";
|
|
@@ -2509,13 +2549,23 @@ var Domql = (() => {
|
|
|
2509
2549
|
if (!params || isFunction(params)) return params;
|
|
2510
2550
|
return params;
|
|
2511
2551
|
};
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
if (
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2552
|
+
resolveLanguage = (element, context) => {
|
|
2553
|
+
const root = element?.state?.root || context?.state?.root;
|
|
2554
|
+
if (root?.lang) return root.lang;
|
|
2555
|
+
return void 0;
|
|
2556
|
+
};
|
|
2557
|
+
resolveParams = (params, element, context) => {
|
|
2558
|
+
let resolved;
|
|
2559
|
+
if (!params) {
|
|
2560
|
+
resolved = void 0;
|
|
2561
|
+
} else if (isFunction(params)) {
|
|
2562
|
+
resolved = params(element, element.state);
|
|
2563
|
+
} else {
|
|
2564
|
+
resolved = {};
|
|
2565
|
+
for (const key in params) {
|
|
2566
|
+
const val = params[key];
|
|
2567
|
+
resolved[key] = isFunction(val) ? val(element, element.state) : val;
|
|
2568
|
+
}
|
|
2519
2569
|
}
|
|
2520
2570
|
return resolved;
|
|
2521
2571
|
};
|
|
@@ -2553,7 +2603,7 @@ var Domql = (() => {
|
|
|
2553
2603
|
db.__resolving = resolveDb(db);
|
|
2554
2604
|
const resolved = await db.__resolving;
|
|
2555
2605
|
db.__resolved = resolved;
|
|
2556
|
-
context.
|
|
2606
|
+
context.fetch = resolved;
|
|
2557
2607
|
delete db.__resolving;
|
|
2558
2608
|
if (db.auth !== false) await initAdapterAuth(resolved, context);
|
|
2559
2609
|
return resolved;
|
|
@@ -2601,7 +2651,7 @@ var Domql = (() => {
|
|
|
2601
2651
|
ref.__fetchError = status.error;
|
|
2602
2652
|
};
|
|
2603
2653
|
runFetch = async (config, element, context, opts = {}) => {
|
|
2604
|
-
const db = context?.
|
|
2654
|
+
const db = context?.fetch;
|
|
2605
2655
|
if (!db) return;
|
|
2606
2656
|
if (config.enabled === false) return;
|
|
2607
2657
|
if (isFunction(config.enabled) && !config.enabled(element, element.state)) return;
|
|
@@ -2641,7 +2691,7 @@ var Domql = (() => {
|
|
|
2641
2691
|
const q = element.getQuery(adapter.name || "paths");
|
|
2642
2692
|
if (q) select = q.select || q.length && q.join(",") || void 0;
|
|
2643
2693
|
}
|
|
2644
|
-
const params = resolveParams(rawParams, element);
|
|
2694
|
+
const params = resolveParams(rawParams, element, context);
|
|
2645
2695
|
const cacheConfig = parseCacheConfig(cacheRaw);
|
|
2646
2696
|
const retryConfig = resolveRetryConfig(config);
|
|
2647
2697
|
const cacheKey = cacheConfig ? cacheRaw?.key || `${from}:${method}:${JSON.stringify(params || "")}${infinite ? ":infinite" : ""}${page ? ":p" + JSON.stringify(page) : ""}` : null;
|
|
@@ -2711,6 +2761,10 @@ var Domql = (() => {
|
|
|
2711
2761
|
const fn = adapter[method];
|
|
2712
2762
|
if (!isFunction(fn)) return { data: null, error: { message: `Method "${method}" not found on adapter` } };
|
|
2713
2763
|
const request2 = { from, select, params, single, limit, offset, order, headers, baseUrl };
|
|
2764
|
+
const lang = resolveLanguage(element, context);
|
|
2765
|
+
if (lang) {
|
|
2766
|
+
request2.headers = { ...request2.headers, "Accept-Language": lang };
|
|
2767
|
+
}
|
|
2714
2768
|
if (page !== void 0) {
|
|
2715
2769
|
if (isObject(page)) {
|
|
2716
2770
|
if (page.offset !== void 0) request2.offset = page.offset;
|
|
@@ -2893,7 +2947,7 @@ var Domql = (() => {
|
|
|
2893
2947
|
}
|
|
2894
2948
|
};
|
|
2895
2949
|
runMutation = async (config, element, context) => {
|
|
2896
|
-
const db = context?.
|
|
2950
|
+
const db = context?.fetch;
|
|
2897
2951
|
if (!db) return;
|
|
2898
2952
|
const adapter = await resolveAdapter(db, context);
|
|
2899
2953
|
if (!adapter) return;
|
|
@@ -2930,7 +2984,11 @@ var Domql = (() => {
|
|
|
2930
2984
|
const fn = adapter[method];
|
|
2931
2985
|
if (!isFunction(fn)) return;
|
|
2932
2986
|
const request2 = { from, data: mutationData, headers, baseUrl };
|
|
2933
|
-
if (config.params) request2.params = resolveParams(config.params, element);
|
|
2987
|
+
if (config.params) request2.params = resolveParams(config.params, element, context);
|
|
2988
|
+
const lang = resolveLanguage(element, context);
|
|
2989
|
+
if (lang) {
|
|
2990
|
+
request2.headers = { ...request2.headers, "Accept-Language": lang };
|
|
2991
|
+
}
|
|
2934
2992
|
const retryConfig = resolveRetryConfig(config);
|
|
2935
2993
|
const result = await withRetry(() => fn(request2), retryConfig);
|
|
2936
2994
|
const { data: data2, error: error2 } = result || {};
|
|
@@ -2975,7 +3033,7 @@ var Domql = (() => {
|
|
|
2975
3033
|
};
|
|
2976
3034
|
executeFetch = (param, element, state2, context) => {
|
|
2977
3035
|
if (!param) return;
|
|
2978
|
-
const db = context?.
|
|
3036
|
+
const db = context?.fetch;
|
|
2979
3037
|
if (!db) return;
|
|
2980
3038
|
const fetchProp = exec(param, element);
|
|
2981
3039
|
if (!fetchProp) return;
|
|
@@ -3061,7 +3119,7 @@ var Domql = (() => {
|
|
|
3061
3119
|
setCacheEntry(key, data2, null);
|
|
3062
3120
|
},
|
|
3063
3121
|
prefetchQuery: async (config, context) => {
|
|
3064
|
-
const db = context?.
|
|
3122
|
+
const db = context?.fetch;
|
|
3065
3123
|
if (!db) return;
|
|
3066
3124
|
const adapter = await resolveAdapter(db, context);
|
|
3067
3125
|
if (!adapter) return;
|
|
@@ -3085,6 +3143,15 @@ var Domql = (() => {
|
|
|
3085
3143
|
getCache: () => cacheStore,
|
|
3086
3144
|
clear: () => removeCache()
|
|
3087
3145
|
};
|
|
3146
|
+
fetchPlugin = {
|
|
3147
|
+
name: "fetch",
|
|
3148
|
+
// Hook into element creation to auto-execute fetch configs
|
|
3149
|
+
create(element) {
|
|
3150
|
+
const fetchProp = element.fetch || element.props?.fetch;
|
|
3151
|
+
if (!fetchProp) return;
|
|
3152
|
+
executeFetch(fetchProp, element, element.state, element.context);
|
|
3153
|
+
}
|
|
3154
|
+
};
|
|
3088
3155
|
fetch_default = executeFetch;
|
|
3089
3156
|
}
|
|
3090
3157
|
});
|
|
@@ -3395,7 +3462,7 @@ var Domql = (() => {
|
|
|
3395
3462
|
}
|
|
3396
3463
|
async function getDB() {
|
|
3397
3464
|
const element = this;
|
|
3398
|
-
const db = element.context?.
|
|
3465
|
+
const db = element.context?.fetch;
|
|
3399
3466
|
if (!db) return null;
|
|
3400
3467
|
if (typeof db.select === "function") {
|
|
3401
3468
|
if (!db.__authInitialized && db.getSession) {
|
|
@@ -3416,7 +3483,7 @@ var Domql = (() => {
|
|
|
3416
3483
|
db.__resolving = resolvePromise;
|
|
3417
3484
|
const resolved = await resolvePromise;
|
|
3418
3485
|
db.__resolved = resolved;
|
|
3419
|
-
element.context.
|
|
3486
|
+
element.context.fetch = resolved;
|
|
3420
3487
|
delete db.__resolving;
|
|
3421
3488
|
if (resolved.getSession) {
|
|
3422
3489
|
const { initAdapterAuth: initAdapterAuth2 } = await Promise.resolve().then(() => (init_fetch(), fetch_exports));
|
|
@@ -3776,7 +3843,7 @@ ${element}` : "";
|
|
|
3776
3843
|
return props[propKey];
|
|
3777
3844
|
};
|
|
3778
3845
|
var registerNodeEvent = (param, element, node, options) => {
|
|
3779
|
-
const appliedFunction = getOnOrPropsEvent2(param, element);
|
|
3846
|
+
const appliedFunction = resolveHandler(getOnOrPropsEvent2(param, element), element);
|
|
3780
3847
|
if (isFunction(appliedFunction)) {
|
|
3781
3848
|
const { __ref: ref } = element;
|
|
3782
3849
|
if (!ref.__eventListeners) ref.__eventListeners = {};
|
|
@@ -3811,24 +3878,11 @@ ${element}` : "";
|
|
|
3811
3878
|
}
|
|
3812
3879
|
};
|
|
3813
3880
|
var applyEventsOnNode = (element, options) => {
|
|
3814
|
-
const { node, on
|
|
3815
|
-
const handled = /* @__PURE__ */ new Set();
|
|
3881
|
+
const { node, on } = element;
|
|
3816
3882
|
for (const param in on) {
|
|
3817
3883
|
if (DOMQL_EVENTS.has(param)) continue;
|
|
3818
|
-
handled.add(param);
|
|
3819
3884
|
registerNodeEvent(param, element, node, options);
|
|
3820
3885
|
}
|
|
3821
|
-
if (props) {
|
|
3822
|
-
for (const key in props) {
|
|
3823
|
-
if (key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && isFunction(props[key])) {
|
|
3824
|
-
const thirdChar = key[2];
|
|
3825
|
-
if (thirdChar !== thirdChar.toUpperCase()) continue;
|
|
3826
|
-
const eventName = thirdChar.toLowerCase() + key.slice(3);
|
|
3827
|
-
if (handled.has(eventName) || DOMQL_EVENTS.has(eventName)) continue;
|
|
3828
|
-
registerNodeEvent(eventName, element, node, options);
|
|
3829
|
-
}
|
|
3830
|
-
}
|
|
3831
|
-
}
|
|
3832
3886
|
};
|
|
3833
3887
|
|
|
3834
3888
|
// ../element/dist/esm/event/can.js
|
|
@@ -3918,25 +3972,30 @@ ${element}` : "";
|
|
|
3918
3972
|
if (isFunction(origEvent)) {
|
|
3919
3973
|
on[eventName] = (...args) => {
|
|
3920
3974
|
const originalEventRetunrs = origEvent(...args);
|
|
3921
|
-
if (originalEventRetunrs !== false)
|
|
3975
|
+
if (originalEventRetunrs !== false) {
|
|
3976
|
+
if (isFunction(funcFromProps)) return funcFromProps(...args);
|
|
3977
|
+
}
|
|
3922
3978
|
};
|
|
3923
3979
|
} else on[eventName] = funcFromProps;
|
|
3924
3980
|
}
|
|
3925
3981
|
};
|
|
3926
3982
|
var propagateEventsFromElement = (element) => {
|
|
3927
3983
|
const { on } = element;
|
|
3984
|
+
const pluginActive = hasHandlerPlugin(element.context);
|
|
3928
3985
|
for (const param in element) {
|
|
3929
3986
|
if (param.charCodeAt(0) !== 111 || param.charCodeAt(1) !== 110 || !Object.prototype.hasOwnProperty.call(element, param)) continue;
|
|
3930
|
-
const
|
|
3931
|
-
if (!isFunction(
|
|
3987
|
+
const handler = element[param];
|
|
3988
|
+
if (!isFunction(handler) && !(pluginActive && handler != null)) continue;
|
|
3932
3989
|
const eventName = lowercaseFirstLetter(param.slice(2));
|
|
3933
3990
|
const origEvent = on[eventName];
|
|
3934
3991
|
if (isFunction(origEvent)) {
|
|
3935
3992
|
on[eventName] = (...args) => {
|
|
3936
3993
|
const ret = origEvent(...args);
|
|
3937
|
-
if (ret !== false)
|
|
3994
|
+
if (ret !== false) {
|
|
3995
|
+
if (isFunction(handler)) return handler(...args);
|
|
3996
|
+
}
|
|
3938
3997
|
};
|
|
3939
|
-
} else on[eventName] =
|
|
3998
|
+
} else on[eventName] = handler;
|
|
3940
3999
|
}
|
|
3941
4000
|
};
|
|
3942
4001
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "domql",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.3",
|
|
4
4
|
"license": "CC-BY-NC-4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild index.js --bundle --target=es2020 --format=iife --global-name=Domql --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@domql/element": "^3.
|
|
29
|
-
"@domql/state": "^3.
|
|
30
|
-
"@domql/utils": "^3.
|
|
28
|
+
"@domql/element": "^3.7.3",
|
|
29
|
+
"@domql/state": "^3.7.3",
|
|
30
|
+
"@domql/utils": "^3.7.3"
|
|
31
31
|
},
|
|
32
32
|
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
|
|
33
33
|
"browser": "./dist/esm/index.js",
|