@domql/element 3.7.0 → 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/cjs/event/on.js +2 -15
- package/dist/cjs/utils/propEvents.js +10 -5
- package/dist/esm/event/on.js +3 -16
- package/dist/esm/utils/propEvents.js +11 -6
- package/dist/iife/index.js +100 -41
- package/event/on.js +3 -19
- package/package.json +5 -5
- package/utils/propEvents.js +11 -6
package/dist/cjs/event/on.js
CHANGED
|
@@ -36,7 +36,7 @@ const getOnOrPropsEvent = (param, element) => {
|
|
|
36
36
|
return props[propKey];
|
|
37
37
|
};
|
|
38
38
|
const registerNodeEvent = (param, element, node, options) => {
|
|
39
|
-
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
39
|
+
const appliedFunction = (0, import_utils.resolveHandler)(getOnOrPropsEvent(param, element), element);
|
|
40
40
|
if ((0, import_utils.isFunction)(appliedFunction)) {
|
|
41
41
|
const { __ref: ref } = element;
|
|
42
42
|
if (!ref.__eventListeners) ref.__eventListeners = {};
|
|
@@ -71,22 +71,9 @@ const registerNodeEvent = (param, element, node, options) => {
|
|
|
71
71
|
}
|
|
72
72
|
};
|
|
73
73
|
const applyEventsOnNode = (element, options) => {
|
|
74
|
-
const { node, on
|
|
75
|
-
const handled = /* @__PURE__ */ new Set();
|
|
74
|
+
const { node, on } = element;
|
|
76
75
|
for (const param in on) {
|
|
77
76
|
if (import_utils.DOMQL_EVENTS.has(param)) continue;
|
|
78
|
-
handled.add(param);
|
|
79
77
|
registerNodeEvent(param, element, node, options);
|
|
80
78
|
}
|
|
81
|
-
if (props) {
|
|
82
|
-
for (const key in props) {
|
|
83
|
-
if (key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && (0, import_utils.isFunction)(props[key])) {
|
|
84
|
-
const thirdChar = key[2];
|
|
85
|
-
if (thirdChar !== thirdChar.toUpperCase()) continue;
|
|
86
|
-
const eventName = thirdChar.toLowerCase() + key.slice(3);
|
|
87
|
-
if (handled.has(eventName) || import_utils.DOMQL_EVENTS.has(eventName)) continue;
|
|
88
|
-
registerNodeEvent(eventName, element, node, options);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
79
|
};
|
|
@@ -33,24 +33,29 @@ const propagateEventsFromProps = (element) => {
|
|
|
33
33
|
if ((0, import_utils.isFunction)(origEvent)) {
|
|
34
34
|
on[eventName] = (...args) => {
|
|
35
35
|
const originalEventRetunrs = origEvent(...args);
|
|
36
|
-
if (originalEventRetunrs !== false)
|
|
36
|
+
if (originalEventRetunrs !== false) {
|
|
37
|
+
if ((0, import_utils.isFunction)(funcFromProps)) return funcFromProps(...args);
|
|
38
|
+
}
|
|
37
39
|
};
|
|
38
40
|
} else on[eventName] = funcFromProps;
|
|
39
41
|
}
|
|
40
42
|
};
|
|
41
43
|
const propagateEventsFromElement = (element) => {
|
|
42
44
|
const { on } = element;
|
|
45
|
+
const pluginActive = (0, import_utils.hasHandlerPlugin)(element.context);
|
|
43
46
|
for (const param in element) {
|
|
44
47
|
if (param.charCodeAt(0) !== 111 || param.charCodeAt(1) !== 110 || !Object.prototype.hasOwnProperty.call(element, param)) continue;
|
|
45
|
-
const
|
|
46
|
-
if (!(0, import_utils.isFunction)(
|
|
48
|
+
const handler = element[param];
|
|
49
|
+
if (!(0, import_utils.isFunction)(handler) && !(pluginActive && handler != null)) continue;
|
|
47
50
|
const eventName = (0, import_utils.lowercaseFirstLetter)(param.slice(2));
|
|
48
51
|
const origEvent = on[eventName];
|
|
49
52
|
if ((0, import_utils.isFunction)(origEvent)) {
|
|
50
53
|
on[eventName] = (...args) => {
|
|
51
54
|
const ret = origEvent(...args);
|
|
52
|
-
if (ret !== false)
|
|
55
|
+
if (ret !== false) {
|
|
56
|
+
if ((0, import_utils.isFunction)(handler)) return handler(...args);
|
|
57
|
+
}
|
|
53
58
|
};
|
|
54
|
-
} else on[eventName] =
|
|
59
|
+
} else on[eventName] = handler;
|
|
55
60
|
}
|
|
56
61
|
};
|
package/dist/esm/event/on.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DOMQL_EVENTS, isFunction } from "@domql/utils";
|
|
1
|
+
import { DOMQL_EVENTS, isFunction, resolveHandler } from "@domql/utils";
|
|
2
2
|
import { applyEvent, triggerEventOn, applyEventUpdate, triggerEventOnUpdate } from "@domql/utils";
|
|
3
3
|
const getOnOrPropsEvent = (param, element) => {
|
|
4
4
|
const onEvent = element.on?.[param];
|
|
@@ -9,7 +9,7 @@ const getOnOrPropsEvent = (param, element) => {
|
|
|
9
9
|
return props[propKey];
|
|
10
10
|
};
|
|
11
11
|
const registerNodeEvent = (param, element, node, options) => {
|
|
12
|
-
const appliedFunction = getOnOrPropsEvent(param, element);
|
|
12
|
+
const appliedFunction = resolveHandler(getOnOrPropsEvent(param, element), element);
|
|
13
13
|
if (isFunction(appliedFunction)) {
|
|
14
14
|
const { __ref: ref } = element;
|
|
15
15
|
if (!ref.__eventListeners) ref.__eventListeners = {};
|
|
@@ -44,24 +44,11 @@ const registerNodeEvent = (param, element, node, options) => {
|
|
|
44
44
|
}
|
|
45
45
|
};
|
|
46
46
|
const applyEventsOnNode = (element, options) => {
|
|
47
|
-
const { node, on
|
|
48
|
-
const handled = /* @__PURE__ */ new Set();
|
|
47
|
+
const { node, on } = element;
|
|
49
48
|
for (const param in on) {
|
|
50
49
|
if (DOMQL_EVENTS.has(param)) continue;
|
|
51
|
-
handled.add(param);
|
|
52
50
|
registerNodeEvent(param, element, node, options);
|
|
53
51
|
}
|
|
54
|
-
if (props) {
|
|
55
|
-
for (const key in props) {
|
|
56
|
-
if (key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && isFunction(props[key])) {
|
|
57
|
-
const thirdChar = key[2];
|
|
58
|
-
if (thirdChar !== thirdChar.toUpperCase()) continue;
|
|
59
|
-
const eventName = thirdChar.toLowerCase() + key.slice(3);
|
|
60
|
-
if (handled.has(eventName) || DOMQL_EVENTS.has(eventName)) continue;
|
|
61
|
-
registerNodeEvent(eventName, element, node, options);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
52
|
};
|
|
66
53
|
export {
|
|
67
54
|
applyEvent,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isFunction, lowercaseFirstLetter } from "@domql/utils";
|
|
1
|
+
import { isFunction, hasHandlerPlugin, lowercaseFirstLetter } from "@domql/utils";
|
|
2
2
|
const propagateEventsFromProps = (element) => {
|
|
3
3
|
const { props, on } = element;
|
|
4
4
|
for (const v in props) {
|
|
@@ -9,25 +9,30 @@ const propagateEventsFromProps = (element) => {
|
|
|
9
9
|
if (isFunction(origEvent)) {
|
|
10
10
|
on[eventName] = (...args) => {
|
|
11
11
|
const originalEventRetunrs = origEvent(...args);
|
|
12
|
-
if (originalEventRetunrs !== false)
|
|
12
|
+
if (originalEventRetunrs !== false) {
|
|
13
|
+
if (isFunction(funcFromProps)) return funcFromProps(...args);
|
|
14
|
+
}
|
|
13
15
|
};
|
|
14
16
|
} else on[eventName] = funcFromProps;
|
|
15
17
|
}
|
|
16
18
|
};
|
|
17
19
|
const propagateEventsFromElement = (element) => {
|
|
18
20
|
const { on } = element;
|
|
21
|
+
const pluginActive = hasHandlerPlugin(element.context);
|
|
19
22
|
for (const param in element) {
|
|
20
23
|
if (param.charCodeAt(0) !== 111 || param.charCodeAt(1) !== 110 || !Object.prototype.hasOwnProperty.call(element, param)) continue;
|
|
21
|
-
const
|
|
22
|
-
if (!isFunction(
|
|
24
|
+
const handler = element[param];
|
|
25
|
+
if (!isFunction(handler) && !(pluginActive && handler != null)) continue;
|
|
23
26
|
const eventName = lowercaseFirstLetter(param.slice(2));
|
|
24
27
|
const origEvent = on[eventName];
|
|
25
28
|
if (isFunction(origEvent)) {
|
|
26
29
|
on[eventName] = (...args) => {
|
|
27
30
|
const ret = origEvent(...args);
|
|
28
|
-
if (ret !== false)
|
|
31
|
+
if (ret !== false) {
|
|
32
|
+
if (isFunction(handler)) return handler(...args);
|
|
33
|
+
}
|
|
29
34
|
};
|
|
30
|
-
} else on[eventName] =
|
|
35
|
+
} else on[eventName] = handler;
|
|
31
36
|
}
|
|
32
37
|
};
|
|
33
38
|
export {
|
package/dist/iife/index.js
CHANGED
|
@@ -631,8 +631,38 @@ var DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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 DomqlElement = (() => {
|
|
|
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));
|
|
@@ -3797,7 +3864,7 @@ ${element}` : "";
|
|
|
3797
3864
|
return props[propKey];
|
|
3798
3865
|
};
|
|
3799
3866
|
var registerNodeEvent = (param, element, node, options) => {
|
|
3800
|
-
const appliedFunction = getOnOrPropsEvent2(param, element);
|
|
3867
|
+
const appliedFunction = resolveHandler(getOnOrPropsEvent2(param, element), element);
|
|
3801
3868
|
if (isFunction(appliedFunction)) {
|
|
3802
3869
|
const { __ref: ref } = element;
|
|
3803
3870
|
if (!ref.__eventListeners) ref.__eventListeners = {};
|
|
@@ -3832,24 +3899,11 @@ ${element}` : "";
|
|
|
3832
3899
|
}
|
|
3833
3900
|
};
|
|
3834
3901
|
var applyEventsOnNode = (element, options) => {
|
|
3835
|
-
const { node, on
|
|
3836
|
-
const handled = /* @__PURE__ */ new Set();
|
|
3902
|
+
const { node, on } = element;
|
|
3837
3903
|
for (const param in on) {
|
|
3838
3904
|
if (DOMQL_EVENTS.has(param)) continue;
|
|
3839
|
-
handled.add(param);
|
|
3840
3905
|
registerNodeEvent(param, element, node, options);
|
|
3841
3906
|
}
|
|
3842
|
-
if (props) {
|
|
3843
|
-
for (const key in props) {
|
|
3844
|
-
if (key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && isFunction(props[key])) {
|
|
3845
|
-
const thirdChar = key[2];
|
|
3846
|
-
if (thirdChar !== thirdChar.toUpperCase()) continue;
|
|
3847
|
-
const eventName = thirdChar.toLowerCase() + key.slice(3);
|
|
3848
|
-
if (handled.has(eventName) || DOMQL_EVENTS.has(eventName)) continue;
|
|
3849
|
-
registerNodeEvent(eventName, element, node, options);
|
|
3850
|
-
}
|
|
3851
|
-
}
|
|
3852
|
-
}
|
|
3853
3907
|
};
|
|
3854
3908
|
|
|
3855
3909
|
// event/can.js
|
|
@@ -3944,25 +3998,30 @@ ${element}` : "";
|
|
|
3944
3998
|
if (isFunction(origEvent)) {
|
|
3945
3999
|
on[eventName] = (...args) => {
|
|
3946
4000
|
const originalEventRetunrs = origEvent(...args);
|
|
3947
|
-
if (originalEventRetunrs !== false)
|
|
4001
|
+
if (originalEventRetunrs !== false) {
|
|
4002
|
+
if (isFunction(funcFromProps)) return funcFromProps(...args);
|
|
4003
|
+
}
|
|
3948
4004
|
};
|
|
3949
4005
|
} else on[eventName] = funcFromProps;
|
|
3950
4006
|
}
|
|
3951
4007
|
};
|
|
3952
4008
|
var propagateEventsFromElement = (element) => {
|
|
3953
4009
|
const { on } = element;
|
|
4010
|
+
const pluginActive = hasHandlerPlugin(element.context);
|
|
3954
4011
|
for (const param in element) {
|
|
3955
4012
|
if (param.charCodeAt(0) !== 111 || param.charCodeAt(1) !== 110 || !Object.prototype.hasOwnProperty.call(element, param)) continue;
|
|
3956
|
-
const
|
|
3957
|
-
if (!isFunction(
|
|
4013
|
+
const handler = element[param];
|
|
4014
|
+
if (!isFunction(handler) && !(pluginActive && handler != null)) continue;
|
|
3958
4015
|
const eventName = lowercaseFirstLetter(param.slice(2));
|
|
3959
4016
|
const origEvent = on[eventName];
|
|
3960
4017
|
if (isFunction(origEvent)) {
|
|
3961
4018
|
on[eventName] = (...args) => {
|
|
3962
4019
|
const ret = origEvent(...args);
|
|
3963
|
-
if (ret !== false)
|
|
4020
|
+
if (ret !== false) {
|
|
4021
|
+
if (isFunction(handler)) return handler(...args);
|
|
4022
|
+
}
|
|
3964
4023
|
};
|
|
3965
|
-
} else on[eventName] =
|
|
4024
|
+
} else on[eventName] = handler;
|
|
3966
4025
|
}
|
|
3967
4026
|
};
|
|
3968
4027
|
|
package/event/on.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { DOMQL_EVENTS, isFunction } from '@domql/utils'
|
|
3
|
+
import { DOMQL_EVENTS, isFunction, resolveHandler } from '@domql/utils'
|
|
4
4
|
|
|
5
5
|
// Re-export event trigger functions from @domql/utils (moved there to break circular dep)
|
|
6
6
|
export { applyEvent, triggerEventOn, applyEventUpdate, triggerEventOnUpdate } from '@domql/utils'
|
|
@@ -15,7 +15,7 @@ const getOnOrPropsEvent = (param, element) => {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
const registerNodeEvent = (param, element, node, options) => {
|
|
18
|
-
const appliedFunction = getOnOrPropsEvent(param, element)
|
|
18
|
+
const appliedFunction = resolveHandler(getOnOrPropsEvent(param, element), element)
|
|
19
19
|
if (isFunction(appliedFunction)) {
|
|
20
20
|
const { __ref: ref } = element
|
|
21
21
|
if (!ref.__eventListeners) ref.__eventListeners = {}
|
|
@@ -55,26 +55,10 @@ const registerNodeEvent = (param, element, node, options) => {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export const applyEventsOnNode = (element, options) => {
|
|
58
|
-
const { node, on
|
|
59
|
-
const handled = new Set()
|
|
58
|
+
const { node, on } = element
|
|
60
59
|
|
|
61
|
-
// Register events from on: { click: ..., input: ... }
|
|
62
60
|
for (const param in on) {
|
|
63
61
|
if (DOMQL_EVENTS.has(param)) continue
|
|
64
|
-
handled.add(param)
|
|
65
62
|
registerNodeEvent(param, element, node, options)
|
|
66
63
|
}
|
|
67
|
-
|
|
68
|
-
// Also pick up props.onClick, props.onInput, etc.
|
|
69
|
-
if (props) {
|
|
70
|
-
for (const key in props) {
|
|
71
|
-
if (key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && isFunction(props[key])) {
|
|
72
|
-
const thirdChar = key[2]
|
|
73
|
-
if (thirdChar !== thirdChar.toUpperCase()) continue
|
|
74
|
-
const eventName = thirdChar.toLowerCase() + key.slice(3)
|
|
75
|
-
if (handled.has(eventName) || DOMQL_EVENTS.has(eventName)) continue
|
|
76
|
-
registerNodeEvent(eventName, element, node, options)
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
64
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@domql/element",
|
|
3
|
-
"version": "3.7.
|
|
3
|
+
"version": "3.7.3",
|
|
4
4
|
"license": "CC-BY-NC-4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
"build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild index.js --bundle --target=es2020 --format=iife --global-name=DomqlElement --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@domql/report": "^3.7.
|
|
50
|
-
"@domql/state": "^3.7.
|
|
51
|
-
"@domql/utils": "^3.7.
|
|
52
|
-
"attrs-in-props": "^3.7.
|
|
49
|
+
"@domql/report": "^3.7.3",
|
|
50
|
+
"@domql/state": "^3.7.3",
|
|
51
|
+
"@domql/utils": "^3.7.3",
|
|
52
|
+
"attrs-in-props": "^3.7.3"
|
|
53
53
|
},
|
|
54
54
|
"gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
|
|
55
55
|
"devDependencies": {
|
package/utils/propEvents.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import { isFunction, lowercaseFirstLetter } from '@domql/utils'
|
|
3
|
+
import { isFunction, hasHandlerPlugin, lowercaseFirstLetter } from '@domql/utils'
|
|
4
4
|
|
|
5
5
|
export const propagateEventsFromProps = (element) => {
|
|
6
6
|
const { props, on } = element
|
|
@@ -12,7 +12,9 @@ export const propagateEventsFromProps = (element) => {
|
|
|
12
12
|
if (isFunction(origEvent)) {
|
|
13
13
|
on[eventName] = (...args) => {
|
|
14
14
|
const originalEventRetunrs = origEvent(...args)
|
|
15
|
-
if (originalEventRetunrs !== false)
|
|
15
|
+
if (originalEventRetunrs !== false) {
|
|
16
|
+
if (isFunction(funcFromProps)) return funcFromProps(...args)
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
} else on[eventName] = funcFromProps
|
|
18
20
|
}
|
|
@@ -20,17 +22,20 @@ export const propagateEventsFromProps = (element) => {
|
|
|
20
22
|
|
|
21
23
|
export const propagateEventsFromElement = (element) => {
|
|
22
24
|
const { on } = element
|
|
25
|
+
const pluginActive = hasHandlerPlugin(element.context)
|
|
23
26
|
for (const param in element) {
|
|
24
27
|
if (param.charCodeAt(0) !== 111 || param.charCodeAt(1) !== 110 || !Object.prototype.hasOwnProperty.call(element, param)) continue
|
|
25
|
-
const
|
|
26
|
-
if (!isFunction(
|
|
28
|
+
const handler = element[param]
|
|
29
|
+
if (!isFunction(handler) && !(pluginActive && handler != null)) continue
|
|
27
30
|
const eventName = lowercaseFirstLetter(param.slice(2))
|
|
28
31
|
const origEvent = on[eventName]
|
|
29
32
|
if (isFunction(origEvent)) {
|
|
30
33
|
on[eventName] = (...args) => {
|
|
31
34
|
const ret = origEvent(...args)
|
|
32
|
-
if (ret !== false)
|
|
35
|
+
if (ret !== false) {
|
|
36
|
+
if (isFunction(handler)) return handler(...args)
|
|
37
|
+
}
|
|
33
38
|
}
|
|
34
|
-
} else on[eventName] =
|
|
39
|
+
} else on[eventName] = handler
|
|
35
40
|
}
|
|
36
41
|
}
|