@domql/utils 3.2.3 → 3.2.7

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.
Files changed (53) hide show
  1. package/array.js +11 -5
  2. package/cache.js +3 -0
  3. package/component.js +3 -4
  4. package/dist/cjs/array.js +11 -5
  5. package/dist/cjs/component.js +4 -6
  6. package/dist/cjs/element.js +5 -5
  7. package/dist/cjs/extends.js +43 -27
  8. package/dist/cjs/function.js +3 -3
  9. package/dist/cjs/index.js +1 -0
  10. package/dist/cjs/key.js +2 -2
  11. package/dist/cjs/keys.js +30 -16
  12. package/dist/cjs/methods.js +64 -28
  13. package/dist/cjs/object.js +141 -125
  14. package/dist/cjs/props.js +41 -32
  15. package/dist/cjs/scope.js +1 -2
  16. package/dist/cjs/state.js +9 -8
  17. package/dist/cjs/string.js +15 -20
  18. package/dist/cjs/tags.js +69 -4
  19. package/dist/cjs/triggerEvent.js +90 -0
  20. package/dist/cjs/types.js +4 -12
  21. package/dist/esm/array.js +11 -5
  22. package/dist/esm/component.js +4 -6
  23. package/dist/esm/element.js +8 -26
  24. package/dist/esm/extends.js +47 -49
  25. package/dist/esm/function.js +3 -3
  26. package/dist/esm/index.js +1 -0
  27. package/dist/esm/key.js +2 -2
  28. package/dist/esm/keys.js +30 -16
  29. package/dist/esm/methods.js +63 -42
  30. package/dist/esm/object.js +145 -149
  31. package/dist/esm/props.js +41 -48
  32. package/dist/esm/scope.js +1 -2
  33. package/dist/esm/state.js +17 -34
  34. package/dist/esm/string.js +15 -20
  35. package/dist/esm/tags.js +69 -4
  36. package/dist/esm/triggerEvent.js +70 -0
  37. package/dist/esm/types.js +4 -12
  38. package/dist/iife/index.js +2779 -0
  39. package/element.js +2 -2
  40. package/extends.js +28 -17
  41. package/function.js +4 -6
  42. package/index.js +1 -0
  43. package/keys.js +26 -16
  44. package/methods.js +63 -18
  45. package/object.js +142 -200
  46. package/package.json +33 -12
  47. package/props.js +42 -25
  48. package/state.js +7 -7
  49. package/string.js +20 -38
  50. package/tags.js +43 -4
  51. package/triggerEvent.js +76 -0
  52. package/types.js +4 -23
  53. package/dist/cjs/package.json +0 -4
package/dist/esm/props.js CHANGED
@@ -1,23 +1,10 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
1
  import { DOMQ_PROPERTIES, PROPS_METHODS } from "./keys.js";
18
2
  import { addEventFromProps } from "./events.js";
19
3
  import { deepClone, deepMerge, exec } from "./object.js";
20
4
  import { is, isArray, isFunction, isObject, isObjectLike } from "./types.js";
5
+ import { lowercaseFirstLetter } from "./string.js";
6
+ const RE_UPPER = /^[A-Z]/;
7
+ const RE_DIGITS = /^\d+$/;
21
8
  const createProps = (element, parent, key) => {
22
9
  const { props, __ref: ref } = element;
23
10
  ref.__propsStack = [];
@@ -27,17 +14,23 @@ const createProps = (element, parent, key) => {
27
14
  ref.__propsStack.push(props);
28
15
  return {};
29
16
  }
30
- return __spreadValues({}, props);
17
+ return { ...props };
31
18
  };
32
19
  function pickupPropsFromElement(obj, opts = {}) {
33
- var _a, _b, _c;
34
20
  const cachedKeys = opts.cachedKeys || [];
35
21
  for (const key in obj) {
36
22
  const value = obj[key];
37
- const hasDefine = isObject((_a = this.define) == null ? void 0 : _a[key]);
38
- const hasGlobalDefine = isObject((_c = (_b = this.context) == null ? void 0 : _b.define) == null ? void 0 : _c[key]);
39
- const isElement = /^[A-Z]/.test(key) || /^\d+$/.test(key);
40
- const isBuiltin = DOMQ_PROPERTIES.includes(key);
23
+ const isEventHandler = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key[2] === key[2].toUpperCase() && isFunction(value);
24
+ if (isEventHandler) {
25
+ const eventName = lowercaseFirstLetter(key.slice(2));
26
+ if (obj.on) obj.on[eventName] = value;
27
+ delete obj[key];
28
+ continue;
29
+ }
30
+ const hasDefine = isObject(this.define?.[key]);
31
+ const hasGlobalDefine = isObject(this.context?.define?.[key]);
32
+ const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
33
+ const isBuiltin = DOMQ_PROPERTIES.has(key);
41
34
  if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
42
35
  obj.props[key] = value;
43
36
  delete obj[key];
@@ -47,11 +40,10 @@ function pickupPropsFromElement(obj, opts = {}) {
47
40
  return obj;
48
41
  }
49
42
  function pickupElementFromProps(obj = this, opts) {
50
- var _a, _b, _c;
51
43
  const cachedKeys = opts.cachedKeys || [];
52
44
  for (const key in obj.props) {
53
45
  const value = obj.props[key];
54
- const isEvent = key.startsWith("on") && key.length > 2;
46
+ const isEvent = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110;
55
47
  const isFn = isFunction(value);
56
48
  if (isEvent && isFn) {
57
49
  addEventFromProps(key, obj);
@@ -59,13 +51,15 @@ function pickupElementFromProps(obj = this, opts) {
59
51
  continue;
60
52
  }
61
53
  if (cachedKeys.includes(key)) continue;
62
- const hasDefine = isObject((_a = this.define) == null ? void 0 : _a[key]);
63
- const hasGlobalDefine = isObject((_c = (_b = this.context) == null ? void 0 : _b.define) == null ? void 0 : _c[key]);
64
- const isElement = /^[A-Z]/.test(key) || /^\d+$/.test(key);
65
- const isBuiltin = DOMQ_PROPERTIES.includes(key);
54
+ const hasDefine = isObject(this.define?.[key]);
55
+ const hasGlobalDefine = isObject(this.context?.define?.[key]);
56
+ const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key);
57
+ const isBuiltin = DOMQ_PROPERTIES.has(key);
66
58
  if (isElement || isBuiltin || hasDefine || hasGlobalDefine) {
67
- obj[key] = value;
68
- if (obj.props) delete obj.props[key];
59
+ if (obj[key] === void 0 || value === null) {
60
+ obj[key] = value;
61
+ if (obj.props) delete obj.props[key];
62
+ }
69
63
  }
70
64
  }
71
65
  return obj;
@@ -77,8 +71,9 @@ function propertizeElement(element = this) {
77
71
  return element;
78
72
  }
79
73
  function propertizeUpdate(params = {}) {
80
- const obj = deepMerge({ on: {}, props: {} }, params);
81
- return propertizeElement.call(this, obj);
74
+ if (!params.on) params.on = {};
75
+ if (!params.props) params.props = {};
76
+ return propertizeElement.call(this, params);
82
77
  }
83
78
  const objectizeStringProperty = (propValue) => {
84
79
  if (is(propValue)("string", "number")) {
@@ -88,21 +83,16 @@ const objectizeStringProperty = (propValue) => {
88
83
  };
89
84
  const propExists = (prop, stack) => {
90
85
  if (!prop || !stack.length) return false;
91
- const key = isObject(prop) ? JSON.stringify(prop) : prop;
92
- return stack.some((existing) => {
93
- const existingKey = isObject(existing) ? JSON.stringify(existing) : existing;
94
- return existingKey === key;
95
- });
86
+ return stack.includes(prop);
96
87
  };
97
88
  const inheritParentProps = (element, parent) => {
98
- var _a;
99
89
  const { __ref: ref } = element;
100
90
  const propsStack = ref.__propsStack || [];
101
91
  const parentProps = parent.props;
102
92
  if (!parentProps) return propsStack;
103
93
  const matchParentKeyProps = parentProps[element.key];
104
94
  const matchParentChildProps = parentProps.childProps;
105
- const ignoreChildProps = (_a = element.props) == null ? void 0 : _a.ignoreChildProps;
95
+ const ignoreChildProps = element.props?.ignoreChildProps;
106
96
  if (matchParentChildProps && !ignoreChildProps) {
107
97
  const childProps = objectizeStringProperty(matchParentChildProps);
108
98
  propsStack.unshift(childProps);
@@ -124,16 +114,15 @@ function setPropsPrototype(element) {
124
114
  const removeDuplicateProps = (propsStack) => {
125
115
  const seen = /* @__PURE__ */ new Set();
126
116
  return propsStack.filter((prop) => {
127
- if (!prop || PROPS_METHODS.includes(prop)) return false;
128
- const key = isObject(prop) ? JSON.stringify(prop) : prop;
129
- if (seen.has(key)) return false;
130
- seen.add(key);
117
+ if (!prop || PROPS_METHODS.has(prop)) return false;
118
+ if (seen.has(prop)) return false;
119
+ seen.add(prop);
131
120
  return true;
132
121
  });
133
122
  };
134
123
  const syncProps = (propsStack, element, opts) => {
135
124
  element.props = propsStack.reduce((mergedProps, v) => {
136
- if (PROPS_METHODS.includes(v)) return mergedProps;
125
+ if (PROPS_METHODS.has(v)) return mergedProps;
137
126
  while (isFunction(v)) v = exec(v, element);
138
127
  return deepMerge(mergedProps, deepClone(v, { exclude: PROPS_METHODS }));
139
128
  }, {});
@@ -143,19 +132,20 @@ const syncProps = (propsStack, element, opts) => {
143
132
  const createPropsStack = (element, parent) => {
144
133
  const { props, __ref: ref } = element;
145
134
  let propsStack = ref.__propsStack || [];
146
- if (parent && parent.props) {
135
+ if (parent?.props) {
147
136
  const parentStack = inheritParentProps(element, parent);
148
137
  propsStack = [...parentStack];
149
138
  }
150
139
  if (isObject(props)) propsStack.push(props);
151
- else if (props === "inherit" && (parent == null ? void 0 : parent.props)) propsStack.push(parent.props);
140
+ else if (props === "inherit" && parent?.props) propsStack.push(parent.props);
152
141
  else if (props) propsStack.push(props);
153
142
  if (isArray(ref.__extendsStack)) {
154
- ref.__extendsStack.forEach((_extends) => {
143
+ for (let i = 0; i < ref.__extendsStack.length; i++) {
144
+ const _extends = ref.__extendsStack[i];
155
145
  if (_extends.props && _extends.props !== props) {
156
146
  propsStack.push(_extends.props);
157
147
  }
158
- });
148
+ }
159
149
  }
160
150
  ref.__propsStack = removeDuplicateProps(propsStack);
161
151
  return ref.__propsStack;
@@ -177,6 +167,9 @@ const initProps = function(element, parent, options) {
177
167
  try {
178
168
  applyProps(element, parent);
179
169
  } catch (e) {
170
+ if (element.context?.designSystem?.verbose) {
171
+ console.warn("initProps error at", ref.path?.join("."), e);
172
+ }
180
173
  element.props = {};
181
174
  ref.__propsStack = [];
182
175
  }
package/dist/esm/scope.js CHANGED
@@ -1,7 +1,6 @@
1
1
  const createScope = (element, parent) => {
2
- var _a;
3
2
  const { __ref: ref } = element;
4
- if (!element.scope) element.scope = parent.scope || ((_a = ref.root) == null ? void 0 : _a.scope) || {};
3
+ if (!element.scope) element.scope = parent.scope || ref.root?.scope || {};
5
4
  };
6
5
  export {
7
6
  createScope
package/dist/esm/state.js CHANGED
@@ -1,22 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
1
  import { addProtoToArray } from "./array.js";
21
2
  import { STATE_METHODS } from "./keys.js";
22
3
  import {
@@ -31,12 +12,11 @@ import {
31
12
  isFunction,
32
13
  isObject,
33
14
  isObjectLike,
34
- isString,
35
- isUndefined
15
+ isString
36
16
  } from "./types.js";
37
17
  const checkForStateTypes = (element) => {
38
18
  const { state: orig, props, __ref: ref } = element;
39
- const state = (props == null ? void 0 : props.state) || orig;
19
+ const state = props?.state || orig;
40
20
  if (isFunction(state)) {
41
21
  ref.__state = state;
42
22
  return exec(state, element);
@@ -106,7 +86,7 @@ const findInheritedState = (element, parent, options = {}) => {
106
86
  const createInheritedState = (element, parent) => {
107
87
  const ref = element.__ref;
108
88
  const inheritedState = findInheritedState(element, parent);
109
- if (isUndefined(inheritedState)) return element.state;
89
+ if (inheritedState === void 0) return element.state;
110
90
  if (is(inheritedState)("object", "array")) {
111
91
  return deepClone(inheritedState);
112
92
  } else if (is(inheritedState)("string", "number", "boolean")) {
@@ -117,7 +97,7 @@ const createInheritedState = (element, parent) => {
117
97
  };
118
98
  const checkIfInherits = (element) => {
119
99
  const { __ref: ref } = element;
120
- const stateKey = ref == null ? void 0 : ref.__state;
100
+ const stateKey = ref?.__state;
121
101
  if (stateKey && is(stateKey)("number", "string", "boolean")) return true;
122
102
  return false;
123
103
  };
@@ -134,27 +114,30 @@ const createNestedObjectByKeyPath = (path, value) => {
134
114
  const keys = path.split("/");
135
115
  const obj = {};
136
116
  let ref = obj;
137
- keys.forEach((key, index) => {
138
- ref[key] = index === keys.length - 1 ? value || {} : {};
139
- ref = ref[key];
140
- });
117
+ const lastIdx = keys.length - 1;
118
+ for (let i = 0; i <= lastIdx; i++) {
119
+ ref[keys[i]] = i === lastIdx ? value || {} : {};
120
+ ref = ref[keys[i]];
121
+ }
141
122
  return obj;
142
123
  };
143
124
  const applyDependentState = (element, state) => {
144
125
  const { __element } = state;
145
- const origState = exec(__element == null ? void 0 : __element.state, element);
126
+ const origState = exec(__element?.state, element);
146
127
  if (!origState) return;
147
128
  const dependentState = deepClone(origState, STATE_METHODS);
148
129
  const newDepends = { [element.key]: dependentState };
149
- const __depends = isObject(origState.__depends) ? __spreadValues(__spreadValues({}, origState.__depends), newDepends) : newDepends;
130
+ const __depends = isObject(origState.__depends) ? { ...origState.__depends, ...newDepends } : newDepends;
150
131
  if (Array.isArray(origState)) {
151
- addProtoToArray(origState, __spreadProps(__spreadValues({}, Object.getPrototypeOf(origState)), {
132
+ addProtoToArray(origState, {
133
+ ...Object.getPrototypeOf(origState),
152
134
  __depends
153
- }));
135
+ });
154
136
  } else {
155
- Object.setPrototypeOf(origState, __spreadProps(__spreadValues({}, Object.getPrototypeOf(origState)), {
137
+ Object.setPrototypeOf(origState, {
138
+ ...Object.getPrototypeOf(origState),
156
139
  __depends
157
- }));
140
+ });
158
141
  }
159
142
  return dependentState;
160
143
  };
@@ -16,15 +16,15 @@ const brackRegex = {
16
16
  };
17
17
  const getNestedValue = (obj, path) => {
18
18
  return path.split(".").reduce((acc, part) => {
19
- return acc && acc[part] !== void 0 ? acc[part] : void 0;
19
+ return acc?.[part];
20
20
  }, obj);
21
21
  };
22
- function replaceLiteralsWithObjectFields(str, state = {}, options = {}) {
22
+ function replaceLiteralsWithObjectFields(str, state, options = {}) {
23
23
  const { bracketsLength = 2 } = options;
24
24
  const bracketPattern = bracketsLength === 3 ? "{{{" : "{{";
25
25
  if (!str.includes(bracketPattern)) return str;
26
26
  const reg = brackRegex[bracketsLength];
27
- const obj = state || {};
27
+ const obj = state || this.state || {};
28
28
  return str.replace(reg, (_, parentPath, variable) => {
29
29
  if (parentPath) {
30
30
  const parentLevels = (parentPath.match(/\.\.\//g) || []).length;
@@ -35,13 +35,13 @@ function replaceLiteralsWithObjectFields(str, state = {}, options = {}) {
35
35
  }
36
36
  const key = variable.trim();
37
37
  if (key === "parent") {
38
- return parentState.value !== void 0 ? String(parentState.value) : "";
38
+ return String(parentState.value ?? "");
39
39
  }
40
40
  const value = getNestedValue(parentState, key);
41
- return value !== void 0 ? String(value) : "";
41
+ return String(value ?? "");
42
42
  } else {
43
43
  const value = getNestedValue(obj, variable.trim());
44
- return value !== void 0 ? String(value) : "";
44
+ return String(value ?? "");
45
45
  }
46
46
  });
47
47
  }
@@ -94,27 +94,22 @@ const findKeyPosition = (str, key) => {
94
94
  endLineNumber
95
95
  };
96
96
  };
97
+ const RE_OCTAL = /\\([0-7]{1,3})/g;
97
98
  const replaceOctalEscapeSequences = (str) => {
98
- const octalRegex = /\\([0-7]{1,3})/g;
99
- return str.replace(octalRegex, (match, p1) => {
100
- const octalValue = parseInt(p1, 8);
101
- const char = String.fromCharCode(octalValue);
102
- return char;
103
- });
99
+ return str.replace(RE_OCTAL, (_, p1) => String.fromCharCode(parseInt(p1, 8)));
104
100
  };
105
101
  const encodeNewlines = (str) => {
106
- return str.split("\n").join("/////n").split("`").join("/////tilde").split("$").join("/////dlrsgn");
102
+ return str.replace(/\n/g, "/////n").replace(/`/g, "/////tilde").replace(/\$/g, "/////dlrsgn");
107
103
  };
108
104
  const decodeNewlines = (encodedStr) => {
109
- return encodedStr.split("/////n").join("\n").split("/////tilde").join("`").split("/////dlrsgn").join("$");
105
+ return encodedStr.replace(/\/\/\/\/\/n/g, "\n").replace(/\/\/\/\/\/tilde/g, "`").replace(/\/\/\/\/\/dlrsgn/g, "$");
110
106
  };
107
+ const RE_NON_ALNUM = /[^a-zA-Z0-9\s]/g;
111
108
  const customEncodeURIComponent = (str) => {
112
- return str.split("").map((char) => {
113
- if (/[^a-zA-Z0-9\s]/.test(char)) {
114
- return "%" + char.charCodeAt(0).toString(16).toUpperCase();
115
- }
116
- return char;
117
- }).join("");
109
+ return str.replace(
110
+ RE_NON_ALNUM,
111
+ (char) => "%" + char.charCodeAt(0).toString(16).toUpperCase()
112
+ );
118
113
  };
119
114
  const customDecodeURIComponent = (encodedStr) => {
120
115
  return encodedStr.replace(
package/dist/esm/tags.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const HTML_TAGS = {
2
2
  root: ["body", "html"],
3
3
  head: ["title", "base", "meta", "style", "noscript", "script"],
4
- body: [
4
+ body: /* @__PURE__ */ new Set([
5
5
  "string",
6
6
  "style",
7
7
  "fragment",
@@ -125,11 +125,76 @@ const HTML_TAGS = {
125
125
  "wbr",
126
126
  // SVG
127
127
  "svg",
128
- "path"
129
- ]
128
+ "path",
129
+ "circle",
130
+ "ellipse",
131
+ "line",
132
+ "polygon",
133
+ "polyline",
134
+ "rect",
135
+ "g",
136
+ "defs",
137
+ "symbol",
138
+ "use",
139
+ "text",
140
+ "tspan",
141
+ "image",
142
+ "clipPath",
143
+ "mask",
144
+ "pattern",
145
+ "marker",
146
+ "linearGradient",
147
+ "radialGradient",
148
+ "stop",
149
+ "filter",
150
+ "feGaussianBlur",
151
+ "feOffset",
152
+ "feMerge",
153
+ "feMergeNode",
154
+ "feBlend",
155
+ "feColorMatrix",
156
+ "feFlood",
157
+ "feComposite",
158
+ "foreignObject"
159
+ ])
130
160
  };
131
- const isValidHtmlTag = (arg) => HTML_TAGS.body.includes(arg);
161
+ const SVG_TAGS = /* @__PURE__ */ new Set([
162
+ "svg",
163
+ "path",
164
+ "circle",
165
+ "ellipse",
166
+ "line",
167
+ "polygon",
168
+ "polyline",
169
+ "rect",
170
+ "g",
171
+ "defs",
172
+ "symbol",
173
+ "use",
174
+ "text",
175
+ "tspan",
176
+ "image",
177
+ "clipPath",
178
+ "mask",
179
+ "pattern",
180
+ "marker",
181
+ "linearGradient",
182
+ "radialGradient",
183
+ "stop",
184
+ "filter",
185
+ "feGaussianBlur",
186
+ "feOffset",
187
+ "feMerge",
188
+ "feMergeNode",
189
+ "feBlend",
190
+ "feColorMatrix",
191
+ "feFlood",
192
+ "feComposite",
193
+ "foreignObject"
194
+ ]);
195
+ const isValidHtmlTag = (arg) => HTML_TAGS.body.has(arg);
132
196
  export {
133
197
  HTML_TAGS,
198
+ SVG_TAGS,
134
199
  isValidHtmlTag
135
200
  };
@@ -0,0 +1,70 @@
1
+ import { isFunction } from "./types.js";
2
+ const getOnOrPropsEvent = (param, element) => {
3
+ const onEvent = element.on?.[param];
4
+ if (onEvent) return onEvent;
5
+ const props = element.props;
6
+ if (!props) return;
7
+ const propKey = "on" + param.charAt(0).toUpperCase() + param.slice(1);
8
+ return props[propKey];
9
+ };
10
+ const applyEvent = (param, element, state, context, options) => {
11
+ if (!isFunction(param)) return;
12
+ const result = param.call(
13
+ element,
14
+ element,
15
+ state || element.state,
16
+ context || element.context,
17
+ options
18
+ );
19
+ if (result && typeof result.then === "function") {
20
+ result.catch(() => {
21
+ });
22
+ }
23
+ return result;
24
+ };
25
+ const triggerEventOn = (param, element, options) => {
26
+ if (!element) {
27
+ throw new Error("Element is required");
28
+ }
29
+ const appliedFunction = getOnOrPropsEvent(param, element);
30
+ if (appliedFunction) {
31
+ const { state, context } = element;
32
+ return applyEvent(appliedFunction, element, state, context, options);
33
+ }
34
+ };
35
+ const applyEventUpdate = (param, updatedObj, element, state, context, options) => {
36
+ if (!isFunction(param)) return;
37
+ const result = param.call(
38
+ element,
39
+ updatedObj,
40
+ element,
41
+ state || element.state,
42
+ context || element.context,
43
+ options
44
+ );
45
+ if (result && typeof result.then === "function") {
46
+ result.catch(() => {
47
+ });
48
+ }
49
+ return result;
50
+ };
51
+ const triggerEventOnUpdate = (param, updatedObj, element, options) => {
52
+ const appliedFunction = getOnOrPropsEvent(param, element);
53
+ if (appliedFunction) {
54
+ const { state, context } = element;
55
+ return applyEventUpdate(
56
+ appliedFunction,
57
+ updatedObj,
58
+ element,
59
+ state,
60
+ context,
61
+ options
62
+ );
63
+ }
64
+ };
65
+ export {
66
+ applyEvent,
67
+ applyEventUpdate,
68
+ triggerEventOn,
69
+ triggerEventOnUpdate
70
+ };
package/dist/esm/types.js CHANGED
@@ -14,12 +14,8 @@ const isObjectLike = (arg) => {
14
14
  if (arg === null) return false;
15
15
  return typeof arg === "object";
16
16
  };
17
- const isDefined = (arg) => {
18
- return isObject(arg) || isObjectLike(arg) || isString(arg) || isNumber(arg) || isFunction(arg) || isArray(arg) || isObjectLike(arg) || isBoolean(arg) || isDate(arg) || isNull(arg);
19
- };
20
- const isUndefined = (arg) => {
21
- return arg === void 0;
22
- };
17
+ const isDefined = (arg) => arg !== void 0;
18
+ const isUndefined = (arg) => arg === void 0;
23
19
  const TYPES = {
24
20
  boolean: isBoolean,
25
21
  array: isArray,
@@ -35,14 +31,10 @@ const TYPES = {
35
31
  defined: isDefined
36
32
  };
37
33
  const is = (arg) => {
38
- return (...args) => {
39
- return args.map((val) => TYPES[val](arg)).filter((v) => v).length > 0;
40
- };
34
+ return (...args) => args.some((val) => TYPES[val](arg));
41
35
  };
42
36
  const isNot = (arg) => {
43
- return (...args) => {
44
- return args.map((val) => TYPES[val](arg)).filter((v) => v).length === 0;
45
- };
37
+ return (...args) => !args.some((val) => TYPES[val](arg));
46
38
  };
47
39
  export {
48
40
  TYPES,