@domql/utils 3.1.2 → 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 (59) 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 +6 -6
  7. package/dist/cjs/env.js +1 -1
  8. package/dist/cjs/events.js +3 -3
  9. package/dist/cjs/extends.js +44 -28
  10. package/dist/cjs/function.js +3 -3
  11. package/dist/cjs/index.js +1 -0
  12. package/dist/cjs/key.js +2 -2
  13. package/dist/cjs/keys.js +29 -15
  14. package/dist/cjs/methods.js +88 -33
  15. package/dist/cjs/object.js +154 -141
  16. package/dist/cjs/props.js +43 -34
  17. package/dist/cjs/scope.js +1 -2
  18. package/dist/cjs/state.js +12 -11
  19. package/dist/cjs/string.js +15 -20
  20. package/dist/cjs/tags.js +71 -16
  21. package/dist/cjs/triggerEvent.js +90 -0
  22. package/dist/cjs/types.js +4 -12
  23. package/dist/esm/array.js +11 -5
  24. package/dist/esm/component.js +4 -6
  25. package/dist/esm/element.js +9 -27
  26. package/dist/esm/env.js +1 -1
  27. package/dist/esm/events.js +3 -3
  28. package/dist/esm/extends.js +48 -50
  29. package/dist/esm/function.js +3 -3
  30. package/dist/esm/index.js +1 -0
  31. package/dist/esm/key.js +2 -2
  32. package/dist/esm/keys.js +29 -15
  33. package/dist/esm/methods.js +86 -31
  34. package/dist/esm/object.js +158 -165
  35. package/dist/esm/props.js +43 -50
  36. package/dist/esm/scope.js +1 -2
  37. package/dist/esm/state.js +21 -38
  38. package/dist/esm/string.js +15 -20
  39. package/dist/esm/tags.js +71 -16
  40. package/dist/esm/triggerEvent.js +70 -0
  41. package/dist/esm/types.js +4 -12
  42. package/dist/iife/index.js +2779 -0
  43. package/element.js +2 -2
  44. package/events.js +3 -3
  45. package/extends.js +28 -17
  46. package/function.js +10 -9
  47. package/index.js +1 -0
  48. package/keys.js +25 -15
  49. package/log.js +0 -1
  50. package/methods.js +99 -24
  51. package/object.js +155 -215
  52. package/package.json +34 -13
  53. package/props.js +44 -27
  54. package/state.js +12 -12
  55. package/string.js +20 -38
  56. package/tags.js +45 -16
  57. package/triggerEvent.js +76 -0
  58. package/types.js +8 -25
  59. package/dist/cjs/package.json +0 -4
package/package.json CHANGED
@@ -1,31 +1,52 @@
1
1
  {
2
2
  "name": "@domql/utils",
3
- "version": "3.1.2",
3
+ "version": "3.2.7",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
- "module": "index.js",
7
- "main": "index.js",
6
+ "module": "./dist/esm/index.js",
7
+ "main": "./dist/cjs/index.js",
8
8
  "exports": {
9
9
  ".": {
10
- "default": "./index.js",
11
10
  "import": "./dist/esm/index.js",
12
- "require": "./dist/cjs/index.js"
11
+ "require": "./dist/cjs/index.js",
12
+ "browser": "./dist/iife/index.js",
13
+ "default": "./dist/esm/index.js"
14
+ },
15
+ "./methods": {
16
+ "import": "./dist/esm/methods.js",
17
+ "require": "./dist/cjs/methods.js",
18
+ "default": "./dist/esm/methods.js"
19
+ },
20
+ "./*.js": {
21
+ "import": "./dist/esm/*.js",
22
+ "require": "./dist/cjs/*.js",
23
+ "default": "./dist/esm/*.js"
24
+ },
25
+ "./*": {
26
+ "import": "./dist/esm/*.js",
27
+ "require": "./dist/cjs/*.js",
28
+ "default": "./dist/esm/*.js"
13
29
  }
14
30
  },
15
31
  "source": "index.js",
16
32
  "files": [
17
- "*.js",
18
- "dist"
33
+ "dist",
34
+ "*.js"
19
35
  ],
20
36
  "scripts": {
21
37
  "copy:package:cjs": "cp ../../build/package-cjs.json dist/cjs/package.json",
22
- "build:esm": "npx esbuild *.js --target=es2017 --format=esm --outdir=dist/esm",
23
- "build:cjs": "npx esbuild *.js --target=node16 --format=cjs --outdir=dist/cjs",
24
- "build": "npx rimraf -I dist; npm run build:cjs; npm run build:esm",
25
- "prepublish": "npm run build; npm run copy:package:cjs"
38
+ "build:esm": "cross-env NODE_ENV=$NODE_ENV esbuild *.js --target=es2020 --format=esm --outdir=dist/esm --define:process.env.NODE_ENV=process.env.NODE_ENV",
39
+ "build:cjs": "cross-env NODE_ENV=$NODE_ENV esbuild *.js --target=node18 --format=cjs --outdir=dist/cjs --define:process.env.NODE_ENV=process.env.NODE_ENV",
40
+ "build": "node ../../build/build.js",
41
+ "prepublish": "npm run build && npm run copy:package:cjs",
42
+ "build:iife": "cross-env NODE_ENV=$NODE_ENV esbuild index.js --bundle --target=es2020 --format=iife --global-name=DomqlUtils --outfile=dist/iife/index.js --define:process.env.NODE_ENV=process.env.NODE_ENV --external:@domql/element"
26
43
  },
27
- "gitHead": "429b36616aa04c8587a26ce3c129815115e35897",
44
+ "gitHead": "9fc1b79b41cdc725ca6b24aec64920a599634681",
28
45
  "devDependencies": {
29
46
  "@babel/core": "^7.26.0"
30
- }
47
+ },
48
+ "browser": "./dist/iife/index.js",
49
+ "unpkg": "./dist/iife/index.js",
50
+ "jsdelivr": "./dist/iife/index.js",
51
+ "sideEffects": false
31
52
  }
package/props.js CHANGED
@@ -4,11 +4,14 @@ import { DOMQ_PROPERTIES, PROPS_METHODS } from './keys.js'
4
4
  import { addEventFromProps } from './events.js'
5
5
  import { deepClone, deepMerge, exec } from './object.js'
6
6
  import { is, isArray, isFunction, isObject, isObjectLike } from './types.js'
7
+ import { lowercaseFirstLetter } from './string.js'
8
+
9
+ const RE_UPPER = /^[A-Z]/
10
+ const RE_DIGITS = /^\d+$/
7
11
 
8
12
  export const createProps = (element, parent, key) => {
9
13
  const { props, __ref: ref } = element
10
14
  ref.__propsStack = []
11
- // if (props !== undefined) ref.__initialProps = props
12
15
  if (props) ref.__initialProps = props
13
16
  else return {}
14
17
  if (!isObjectLike(props)) {
@@ -24,10 +27,19 @@ export function pickupPropsFromElement (obj, opts = {}) {
24
27
  for (const key in obj) {
25
28
  const value = obj[key]
26
29
 
30
+ // Move top-level onXxx handlers directly into on.xxx (v3 style)
31
+ const isEventHandler = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110 && key[2] === key[2].toUpperCase() && isFunction(value)
32
+ if (isEventHandler) {
33
+ const eventName = lowercaseFirstLetter(key.slice(2))
34
+ if (obj.on) obj.on[eventName] = value
35
+ delete obj[key]
36
+ continue
37
+ }
38
+
27
39
  const hasDefine = isObject(this.define?.[key])
28
40
  const hasGlobalDefine = isObject(this.context?.define?.[key])
29
- const isElement = /^[A-Z]/.test(key) || /^\d+$/.test(key)
30
- const isBuiltin = DOMQ_PROPERTIES.includes(key)
41
+ const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key)
42
+ const isBuiltin = DOMQ_PROPERTIES.has(key)
31
43
 
32
44
  // If it's not a special case, move to props
33
45
  if (!isElement && !isBuiltin && !hasDefine && !hasGlobalDefine) {
@@ -47,7 +59,7 @@ export function pickupElementFromProps (obj = this, opts) {
47
59
  const value = obj.props[key]
48
60
 
49
61
  // Handle event handlers
50
- const isEvent = key.startsWith('on') && key.length > 2
62
+ const isEvent = key.length > 2 && key.charCodeAt(0) === 111 && key.charCodeAt(1) === 110
51
63
  const isFn = isFunction(value)
52
64
 
53
65
  if (isEvent && isFn) {
@@ -61,14 +73,19 @@ export function pickupElementFromProps (obj = this, opts) {
61
73
 
62
74
  const hasDefine = isObject(this.define?.[key])
63
75
  const hasGlobalDefine = isObject(this.context?.define?.[key])
64
- const isElement = /^[A-Z]/.test(key) || /^\d+$/.test(key)
65
- const isBuiltin = DOMQ_PROPERTIES.includes(key)
76
+ const isElement = RE_UPPER.test(key) || RE_DIGITS.test(key)
77
+ const isBuiltin = DOMQ_PROPERTIES.has(key)
66
78
 
67
79
  // Move qualifying properties back to obj root
68
80
  if (isElement || isBuiltin || hasDefine || hasGlobalDefine) {
69
- obj[key] = value
70
-
71
- if (obj.props) delete obj.props[key]
81
+ // Don't overwrite if root already has this property explicitly set
82
+ // Exception: null values should override to allow nullifying children from props
83
+ if (obj[key] === undefined || value === null) {
84
+ obj[key] = value
85
+ if (obj.props) delete obj.props[key]
86
+ }
87
+ // If root already has the property (e.g. from extends), keep it in props
88
+ // so functions like `text: ({ props }) => props.text` can still access it
72
89
  }
73
90
  }
74
91
 
@@ -84,8 +101,9 @@ export function propertizeElement (element = this) {
84
101
  }
85
102
 
86
103
  export function propertizeUpdate (params = {}) {
87
- const obj = deepMerge({ on: {}, props: {} }, params)
88
- return propertizeElement.call(this, obj)
104
+ if (!params.on) params.on = {}
105
+ if (!params.props) params.props = {}
106
+ return propertizeElement.call(this, params)
89
107
  }
90
108
 
91
109
  export const objectizeStringProperty = propValue => {
@@ -97,11 +115,7 @@ export const objectizeStringProperty = propValue => {
97
115
 
98
116
  export const propExists = (prop, stack) => {
99
117
  if (!prop || !stack.length) return false
100
- const key = isObject(prop) ? JSON.stringify(prop) : prop
101
- return stack.some(existing => {
102
- const existingKey = isObject(existing) ? JSON.stringify(existing) : existing
103
- return existingKey === key
104
- })
118
+ return stack.includes(prop)
105
119
  }
106
120
 
107
121
  export const inheritParentProps = (element, parent) => {
@@ -129,9 +143,9 @@ export const inheritParentProps = (element, parent) => {
129
143
  return propsStack
130
144
  }
131
145
 
132
- export async function update (props, options) {
146
+ export function update (props, options) {
133
147
  const element = this.__element
134
- await element.update({ props }, options)
148
+ element.update({ props }, options)
135
149
  }
136
150
 
137
151
  // TODO: check bind with promise
@@ -144,17 +158,16 @@ export const removeDuplicateProps = propsStack => {
144
158
  const seen = new Set()
145
159
 
146
160
  return propsStack.filter(prop => {
147
- if (!prop || PROPS_METHODS.includes(prop)) return false
148
- const key = isObject(prop) ? JSON.stringify(prop) : prop
149
- if (seen.has(key)) return false
150
- seen.add(key)
161
+ if (!prop || PROPS_METHODS.has(prop)) return false
162
+ if (seen.has(prop)) return false
163
+ seen.add(prop)
151
164
  return true
152
165
  })
153
166
  }
154
167
 
155
168
  export const syncProps = (propsStack, element, opts) => {
156
169
  element.props = propsStack.reduce((mergedProps, v) => {
157
- if (PROPS_METHODS.includes(v)) return mergedProps
170
+ if (PROPS_METHODS.has(v)) return mergedProps
158
171
  while (isFunction(v)) v = exec(v, element)
159
172
  return deepMerge(mergedProps, deepClone(v, { exclude: PROPS_METHODS }))
160
173
  }, {})
@@ -169,7 +182,7 @@ export const createPropsStack = (element, parent) => {
169
182
  let propsStack = ref.__propsStack || []
170
183
 
171
184
  // Get parent props
172
- if (parent && parent.props) {
185
+ if (parent?.props) {
173
186
  const parentStack = inheritParentProps(element, parent)
174
187
  propsStack = [...parentStack]
175
188
  }
@@ -181,11 +194,12 @@ export const createPropsStack = (element, parent) => {
181
194
 
182
195
  // Add extends props
183
196
  if (isArray(ref.__extendsStack)) {
184
- ref.__extendsStack.forEach(_extends => {
197
+ for (let i = 0; i < ref.__extendsStack.length; i++) {
198
+ const _extends = ref.__extendsStack[i]
185
199
  if (_extends.props && _extends.props !== props) {
186
200
  propsStack.push(_extends.props)
187
201
  }
188
- })
202
+ }
189
203
  }
190
204
 
191
205
  // Remove duplicates and update reference
@@ -215,7 +229,10 @@ export const initProps = function (element, parent, options) {
215
229
  else {
216
230
  try {
217
231
  applyProps(element, parent)
218
- } catch {
232
+ } catch (e) {
233
+ if (element.context?.designSystem?.verbose) {
234
+ console.warn('initProps error at', ref.path?.join('.'), e)
235
+ }
219
236
  element.props = {}
220
237
  ref.__propsStack = []
221
238
  }
package/state.js CHANGED
@@ -5,7 +5,7 @@ import { STATE_METHODS } from './keys.js'
5
5
  import {
6
6
  deepClone,
7
7
  deepMerge,
8
- execPromise,
8
+ exec,
9
9
  overwriteDeep,
10
10
  overwriteShallow
11
11
  } from './object.js'
@@ -14,16 +14,15 @@ import {
14
14
  isFunction,
15
15
  isObject,
16
16
  isObjectLike,
17
- isString,
18
- isUndefined
17
+ isString
19
18
  } from './types.js'
20
19
 
21
- export const checkForStateTypes = async element => {
20
+ export const checkForStateTypes = element => {
22
21
  const { state: orig, props, __ref: ref } = element
23
22
  const state = props?.state || orig
24
23
  if (isFunction(state)) {
25
24
  ref.__state = state
26
- return await execPromise(state, element)
25
+ return exec(state, element)
27
26
  } else if (is(state)('string', 'number')) {
28
27
  ref.__state = state
29
28
  return { value: state }
@@ -101,7 +100,7 @@ export const findInheritedState = (element, parent, options = {}) => {
101
100
  export const createInheritedState = (element, parent) => {
102
101
  const ref = element.__ref
103
102
  const inheritedState = findInheritedState(element, parent)
104
- if (isUndefined(inheritedState)) return element.state
103
+ if (inheritedState === undefined) return element.state
105
104
 
106
105
  if (is(inheritedState)('object', 'array')) {
107
106
  return deepClone(inheritedState)
@@ -158,16 +157,17 @@ export const createNestedObjectByKeyPath = (path, value) => {
158
157
  const keys = path.split('/')
159
158
  const obj = {}
160
159
  let ref = obj
161
- keys.forEach((key, index) => {
162
- ref[key] = index === keys.length - 1 ? value || {} : {}
163
- ref = ref[key]
164
- })
160
+ const lastIdx = keys.length - 1
161
+ for (let i = 0; i <= lastIdx; i++) {
162
+ ref[keys[i]] = i === lastIdx ? value || {} : {}
163
+ ref = ref[keys[i]]
164
+ }
165
165
  return obj
166
166
  }
167
167
 
168
- export const applyDependentState = async (element, state) => {
168
+ export const applyDependentState = (element, state) => {
169
169
  const { __element } = state //
170
- const origState = await execPromise(__element?.state, element)
170
+ const origState = exec(__element?.state, element)
171
171
  if (!origState) return
172
172
  const dependentState = deepClone(origState, STATE_METHODS)
173
173
  const newDepends = { [element.key]: dependentState }
package/string.js CHANGED
@@ -31,17 +31,17 @@ const brackRegex = {
31
31
 
32
32
  const getNestedValue = (obj, path) => {
33
33
  return path.split('.').reduce((acc, part) => {
34
- return acc && acc[part] !== undefined ? acc[part] : undefined
34
+ return acc?.[part]
35
35
  }, obj)
36
36
  }
37
37
 
38
- export function replaceLiteralsWithObjectFields (str, state = {}, options = {}) {
38
+ export function replaceLiteralsWithObjectFields (str, state, options = {}) {
39
39
  const { bracketsLength = 2 } = options
40
40
  const bracketPattern = bracketsLength === 3 ? '{{{' : '{{'
41
41
  if (!str.includes(bracketPattern)) return str
42
42
 
43
43
  const reg = brackRegex[bracketsLength]
44
- const obj = state || {}
44
+ const obj = state || this.state || {}
45
45
 
46
46
  return str.replace(reg, (_, parentPath, variable) => {
47
47
  if (parentPath) {
@@ -56,14 +56,14 @@ export function replaceLiteralsWithObjectFields (str, state = {}, options = {})
56
56
  // If the variable is 'parent', return the value property
57
57
  const key = variable.trim()
58
58
  if (key === 'parent') {
59
- return parentState.value !== undefined ? String(parentState.value) : ''
59
+ return String(parentState.value ?? '')
60
60
  }
61
61
 
62
62
  const value = getNestedValue(parentState, key)
63
- return value !== undefined ? String(value) : ''
63
+ return String(value ?? '')
64
64
  } else {
65
65
  const value = getNestedValue(obj, variable.trim())
66
- return value !== undefined ? String(value) : ''
66
+ return String(value ?? '')
67
67
  }
68
68
  })
69
69
  }
@@ -131,50 +131,32 @@ export const findKeyPosition = (str, key) => {
131
131
  }
132
132
  }
133
133
 
134
+ const RE_OCTAL = /\\([0-7]{1,3})/g
135
+
134
136
  export const replaceOctalEscapeSequences = str => {
135
- // Regex to match octal escape sequences
136
- const octalRegex = /\\([0-7]{1,3})/g
137
-
138
- // Replace each match with the corresponding character
139
- return str.replace(octalRegex, (match, p1) => {
140
- // Convert the octal value to a decimal integer
141
- const octalValue = parseInt(p1, 8)
142
- // Convert the decimal value to the corresponding character
143
- const char = String.fromCharCode(octalValue)
144
- return char
145
- })
137
+ return str.replace(RE_OCTAL, (_, p1) => String.fromCharCode(parseInt(p1, 8)))
146
138
  }
147
139
 
148
140
  export const encodeNewlines = str => {
149
141
  return str
150
- .split('\n')
151
- .join('/////n')
152
- .split('`')
153
- .join('/////tilde')
154
- .split('$')
155
- .join('/////dlrsgn')
142
+ .replace(/\n/g, '/////n')
143
+ .replace(/`/g, '/////tilde')
144
+ .replace(/\$/g, '/////dlrsgn')
156
145
  }
157
146
 
158
147
  export const decodeNewlines = encodedStr => {
159
148
  return encodedStr
160
- .split('/////n')
161
- .join('\n')
162
- .split('/////tilde')
163
- .join('`')
164
- .split('/////dlrsgn')
165
- .join('$')
149
+ .replace(/\/\/\/\/\/n/g, '\n')
150
+ .replace(/\/\/\/\/\/tilde/g, '`')
151
+ .replace(/\/\/\/\/\/dlrsgn/g, '$')
166
152
  }
167
153
 
154
+ const RE_NON_ALNUM = /[^a-zA-Z0-9\s]/g
155
+
168
156
  export const customEncodeURIComponent = str => {
169
- return str
170
- .split('')
171
- .map(char => {
172
- if (/[^a-zA-Z0-9\s]/.test(char)) {
173
- return '%' + char.charCodeAt(0).toString(16).toUpperCase()
174
- }
175
- return char
176
- })
177
- .join('')
157
+ return str.replace(RE_NON_ALNUM, char =>
158
+ '%' + char.charCodeAt(0).toString(16).toUpperCase()
159
+ )
178
160
  }
179
161
 
180
162
  export const customDecodeURIComponent = encodedStr => {
package/tags.js CHANGED
@@ -1,21 +1,11 @@
1
1
  'use strict'
2
2
 
3
3
  export const HTML_TAGS = {
4
- root: [
5
- 'body',
6
- 'html'
7
- ],
4
+ root: ['body', 'html'],
8
5
 
9
- head: [
10
- 'title',
11
- 'base',
12
- 'meta',
13
- 'style',
14
- 'noscript',
15
- 'script'
16
- ],
6
+ head: ['title', 'base', 'meta', 'style', 'noscript', 'script'],
17
7
 
18
- body: [
8
+ body: new Set([
19
9
  'string',
20
10
  'style',
21
11
  'fragment',
@@ -140,8 +130,47 @@ export const HTML_TAGS = {
140
130
 
141
131
  // SVG
142
132
  'svg',
143
- 'path'
144
- ]
133
+ 'path',
134
+ 'circle',
135
+ 'ellipse',
136
+ 'line',
137
+ 'polygon',
138
+ 'polyline',
139
+ 'rect',
140
+ 'g',
141
+ 'defs',
142
+ 'symbol',
143
+ 'use',
144
+ 'text',
145
+ 'tspan',
146
+ 'image',
147
+ 'clipPath',
148
+ 'mask',
149
+ 'pattern',
150
+ 'marker',
151
+ 'linearGradient',
152
+ 'radialGradient',
153
+ 'stop',
154
+ 'filter',
155
+ 'feGaussianBlur',
156
+ 'feOffset',
157
+ 'feMerge',
158
+ 'feMergeNode',
159
+ 'feBlend',
160
+ 'feColorMatrix',
161
+ 'feFlood',
162
+ 'feComposite',
163
+ 'foreignObject'
164
+ ])
145
165
  }
146
166
 
147
- export const isValidHtmlTag = arg => HTML_TAGS.body.includes(arg)
167
+ export const SVG_TAGS = new Set([
168
+ 'svg', 'path', 'circle', 'ellipse', 'line', 'polygon', 'polyline',
169
+ 'rect', 'g', 'defs', 'symbol', 'use', 'text', 'tspan', 'image',
170
+ 'clipPath', 'mask', 'pattern', 'marker', 'linearGradient',
171
+ 'radialGradient', 'stop', 'filter', 'feGaussianBlur', 'feOffset',
172
+ 'feMerge', 'feMergeNode', 'feBlend', 'feColorMatrix', 'feFlood',
173
+ 'feComposite', 'foreignObject'
174
+ ])
175
+
176
+ export const isValidHtmlTag = arg => HTML_TAGS.body.has(arg)
@@ -0,0 +1,76 @@
1
+ 'use strict'
2
+
3
+ import { isFunction } from './types.js'
4
+
5
+ const getOnOrPropsEvent = (param, element) => {
6
+ const onEvent = element.on?.[param]
7
+ if (onEvent) return onEvent
8
+ const props = element.props
9
+ if (!props) return
10
+ const propKey = 'on' + param.charAt(0).toUpperCase() + param.slice(1)
11
+ return props[propKey]
12
+ }
13
+
14
+ export const applyEvent = (param, element, state, context, options) => {
15
+ if (!isFunction(param)) return
16
+ const result = param.call(
17
+ element,
18
+ element,
19
+ state || element.state,
20
+ context || element.context,
21
+ options
22
+ )
23
+ if (result && typeof result.then === 'function') {
24
+ result.catch(() => {})
25
+ }
26
+ return result
27
+ }
28
+
29
+ export const triggerEventOn = (param, element, options) => {
30
+ if (!element) {
31
+ throw new Error('Element is required')
32
+ }
33
+ const appliedFunction = getOnOrPropsEvent(param, element)
34
+ if (appliedFunction) {
35
+ const { state, context } = element
36
+ return applyEvent(appliedFunction, element, state, context, options)
37
+ }
38
+ }
39
+
40
+ export const applyEventUpdate = (
41
+ param,
42
+ updatedObj,
43
+ element,
44
+ state,
45
+ context,
46
+ options
47
+ ) => {
48
+ if (!isFunction(param)) return
49
+ const result = param.call(
50
+ element,
51
+ updatedObj,
52
+ element,
53
+ state || element.state,
54
+ context || element.context,
55
+ options
56
+ )
57
+ if (result && typeof result.then === 'function') {
58
+ result.catch(() => {})
59
+ }
60
+ return result
61
+ }
62
+
63
+ export const triggerEventOnUpdate = (param, updatedObj, element, options) => {
64
+ const appliedFunction = getOnOrPropsEvent(param, element)
65
+ if (appliedFunction) {
66
+ const { state, context } = element
67
+ return applyEventUpdate(
68
+ appliedFunction,
69
+ updatedObj,
70
+ element,
71
+ state,
72
+ context,
73
+ options
74
+ )
75
+ }
76
+ }
package/types.js CHANGED
@@ -4,7 +4,7 @@ import { isHtmlElement, isNode } from './node.js'
4
4
 
5
5
  export const isObject = arg => {
6
6
  if (arg === null) return false
7
- return (typeof arg === 'object') && (arg.constructor === Object)
7
+ return typeof arg === 'object' && arg.constructor === Object
8
8
  }
9
9
 
10
10
  export const isString = arg => typeof arg === 'string'
@@ -24,25 +24,12 @@ export const isDate = d => d instanceof Date
24
24
  export const isObjectLike = arg => {
25
25
  if (arg === null) return false
26
26
  // if (isArray(arg)) return false
27
- return (typeof arg === 'object')
27
+ return typeof arg === 'object'
28
28
  }
29
29
 
30
- export const isDefined = arg => {
31
- return isObject(arg) ||
32
- isObjectLike(arg) ||
33
- isString(arg) ||
34
- isNumber(arg) ||
35
- isFunction(arg) ||
36
- isArray(arg) ||
37
- isObjectLike(arg) ||
38
- isBoolean(arg) ||
39
- isDate(arg) ||
40
- isNull(arg)
41
- }
30
+ export const isDefined = arg => arg !== undefined
42
31
 
43
- export const isUndefined = arg => {
44
- return arg === undefined
45
- }
32
+ export const isUndefined = arg => arg === undefined
46
33
 
47
34
  export const TYPES = {
48
35
  boolean: isBoolean,
@@ -59,14 +46,10 @@ export const TYPES = {
59
46
  defined: isDefined
60
47
  }
61
48
 
62
- export const is = (arg) => {
63
- return (...args) => {
64
- return args.map(val => TYPES[val](arg)).filter(v => v).length > 0
65
- }
49
+ export const is = arg => {
50
+ return (...args) => args.some(val => TYPES[val](arg))
66
51
  }
67
52
 
68
- export const isNot = (arg) => {
69
- return (...args) => {
70
- return args.map(val => TYPES[val](arg)).filter(v => v).length === 0
71
- }
53
+ export const isNot = arg => {
54
+ return (...args) => !args.some(val => TYPES[val](arg))
72
55
  }
@@ -1,4 +0,0 @@
1
- {
2
- "type": "commonjs",
3
- "main": "index.js"
4
- }