@fictjs/runtime 0.0.3 → 0.0.4

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/slim.js CHANGED
@@ -1311,6 +1311,27 @@ function removeNodes(nodes) {
1311
1311
  function isReactive(value) {
1312
1312
  return typeof value === "function" && value.length === 0;
1313
1313
  }
1314
+ function callEventHandler(handler, event, node, data) {
1315
+ if (!handler) return;
1316
+ const context = node ?? event.currentTarget ?? void 0;
1317
+ const invoke = (fn) => {
1318
+ if (typeof fn === "function") {
1319
+ const result = data === void 0 ? fn.call(context, event) : fn.call(context, data, event);
1320
+ if (typeof result === "function" && result !== fn) {
1321
+ if (data === void 0) {
1322
+ result.call(context, event);
1323
+ } else {
1324
+ result.call(context, data, event);
1325
+ }
1326
+ } else if (result && typeof result.handleEvent === "function") {
1327
+ result.handleEvent.call(result, event);
1328
+ }
1329
+ } else if (fn && typeof fn.handleEvent === "function") {
1330
+ fn.handleEvent.call(fn, event);
1331
+ }
1332
+ };
1333
+ invoke(handler);
1334
+ }
1314
1335
  var PRIMITIVE_PROXY = Symbol("fict:primitive-proxy");
1315
1336
  var PRIMITIVE_PROXY_RAW_VALUE = Symbol("fict:primitive-proxy:raw-value");
1316
1337
  function createValueProxy(read) {
@@ -1797,14 +1818,10 @@ function globalEventHandler(e) {
1797
1818
  const hasData = rawData !== void 0;
1798
1819
  const resolvedNodeData = hasData ? resolveData(rawData) : void 0;
1799
1820
  if (typeof handler === "function") {
1800
- if (hasData) {
1801
- handler.call(node, resolvedNodeData, e);
1802
- } else {
1803
- handler.call(node, e);
1804
- }
1821
+ callEventHandler(handler, e, node, hasData ? resolvedNodeData : void 0);
1805
1822
  } else if (Array.isArray(handler)) {
1806
1823
  const tupleData = resolveData(handler[1]);
1807
- handler[0].call(node, tupleData, e);
1824
+ callEventHandler(handler[0], e, node, tupleData);
1808
1825
  }
1809
1826
  if (e.cancelBubble) return false;
1810
1827
  }
@@ -1852,23 +1869,15 @@ function bindEvent(el, eventName, handler, options2) {
1852
1869
  if (DelegatedEvents.has(eventName) && !options2) {
1853
1870
  const key = `$$${eventName}`;
1854
1871
  delegateEvents([eventName]);
1855
- const createWrapped = (resolve) => {
1856
- const wrapped2 = function(...args) {
1857
- try {
1858
- const fn = resolve();
1859
- if (typeof fn === "function") {
1860
- return fn.apply(this, args);
1861
- } else if (fn && typeof fn.handleEvent === "function") {
1862
- return fn.handleEvent.apply(fn, args);
1863
- }
1864
- } catch (err) {
1865
- handleError(err, { source: "event", eventName }, rootRef);
1866
- }
1867
- };
1868
- return wrapped2;
1869
- };
1870
1872
  const resolveHandler = isReactive(handler) ? handler : () => handler;
1871
- el[key] = createWrapped(resolveHandler);
1873
+ el[key] = function(...args) {
1874
+ try {
1875
+ const fn = resolveHandler();
1876
+ callEventHandler(fn, args[0], el);
1877
+ } catch (err) {
1878
+ handleError(err, { source: "event", eventName }, rootRef);
1879
+ }
1880
+ };
1872
1881
  return () => {
1873
1882
  el[key] = void 0;
1874
1883
  };
@@ -1877,13 +1886,7 @@ function bindEvent(el, eventName, handler, options2) {
1877
1886
  const wrapped = (event) => {
1878
1887
  try {
1879
1888
  const resolved = getHandler();
1880
- if (typeof resolved === "function") {
1881
- ;
1882
- resolved(event);
1883
- } else if (resolved && typeof resolved.handleEvent === "function") {
1884
- ;
1885
- resolved.handleEvent(event);
1886
- }
1889
+ callEventHandler(resolved, event, el);
1887
1890
  } catch (err) {
1888
1891
  if (handleError(err, { source: "event", eventName }, rootRef)) {
1889
1892
  return;