@volverjs/ui-vue 0.0.14 → 0.0.15

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 (97) hide show
  1. package/dist/Volver.d.ts +5 -5
  2. package/dist/components/VvAction/VvAction.es.js +26 -26
  3. package/dist/components/VvAction/VvAction.umd.js +1 -1
  4. package/dist/components/VvAction/index.d.ts +1 -44
  5. package/dist/components/VvAlert/VvAlert.es.js +43 -44
  6. package/dist/components/VvAlert/VvAlert.umd.js +1 -1
  7. package/dist/components/VvAlert/VvAlert.vue.d.ts +1 -1
  8. package/dist/components/VvAlertGroup/VvAlertGroup.es.js +54 -55
  9. package/dist/components/VvAlertGroup/VvAlertGroup.umd.js +1 -1
  10. package/dist/components/VvBreadcrumb/VvBreadcrumb.es.js +34 -34
  11. package/dist/components/VvBreadcrumb/VvBreadcrumb.umd.js +1 -1
  12. package/dist/components/VvBreadcrumb/VvBreadcrumb.vue.d.ts +1 -1
  13. package/dist/components/VvButton/VvButton.es.js +186 -187
  14. package/dist/components/VvButton/VvButton.umd.js +1 -1
  15. package/dist/components/VvCheckbox/VvCheckbox.es.js +215 -217
  16. package/dist/components/VvCheckbox/VvCheckbox.umd.js +1 -1
  17. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.es.js +235 -237
  18. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.umd.js +1 -1
  19. package/dist/components/VvCheckboxGroup/VvCheckboxGroup.vue.d.ts +2 -2
  20. package/dist/components/VvCheckboxGroup/index.d.ts +1 -78
  21. package/dist/components/VvCombobox/VvCombobox.es.js +810 -813
  22. package/dist/components/VvCombobox/VvCombobox.umd.js +1 -1
  23. package/dist/components/VvCombobox/VvCombobox.vue.d.ts +1 -1
  24. package/dist/components/VvCombobox/index.d.ts +2 -2
  25. package/dist/components/VvDropdown/VvDropdown.es.js +4 -4
  26. package/dist/components/VvDropdown/VvDropdown.umd.js +1 -1
  27. package/dist/components/VvDropdownAction/VvDropdownAction.es.js +50 -50
  28. package/dist/components/VvDropdownAction/VvDropdownAction.umd.js +1 -1
  29. package/dist/components/VvIcon/VvIcon.es.js +30 -31
  30. package/dist/components/VvIcon/VvIcon.umd.js +1 -1
  31. package/dist/components/VvInputFile/VvInputFile.es.js +415 -418
  32. package/dist/components/VvInputFile/VvInputFile.umd.js +1 -1
  33. package/dist/components/VvInputText/VvInputText.es.js +595 -588
  34. package/dist/components/VvInputText/VvInputText.umd.js +1 -1
  35. package/dist/components/VvInputText/VvInputText.vue.d.ts +6 -6
  36. package/dist/components/VvInputText/index.d.ts +3 -3
  37. package/dist/components/VvNav/VvNav.es.js +63 -63
  38. package/dist/components/VvNav/VvNav.umd.js +1 -1
  39. package/dist/components/VvNavItem/VvNavItem.es.js +41 -41
  40. package/dist/components/VvNavItem/VvNavItem.umd.js +1 -1
  41. package/dist/components/VvRadio/VvRadio.es.js +222 -224
  42. package/dist/components/VvRadio/VvRadio.umd.js +1 -1
  43. package/dist/components/VvRadioGroup/VvRadioGroup.es.js +234 -236
  44. package/dist/components/VvRadioGroup/VvRadioGroup.umd.js +1 -1
  45. package/dist/components/VvRadioGroup/VvRadioGroup.vue.d.ts +2 -2
  46. package/dist/components/VvRadioGroup/index.d.ts +1 -78
  47. package/dist/components/VvSelect/VvSelect.es.js +200 -203
  48. package/dist/components/VvSelect/VvSelect.umd.js +1 -1
  49. package/dist/components/VvSelect/VvSelect.vue.d.ts +1 -1
  50. package/dist/components/VvSelect/index.d.ts +2 -2
  51. package/dist/components/VvTab/VvTab.es.js +35 -35
  52. package/dist/components/VvTab/VvTab.umd.js +1 -1
  53. package/dist/components/VvTextarea/VvTextarea.es.js +341 -344
  54. package/dist/components/VvTextarea/VvTextarea.umd.js +1 -1
  55. package/dist/components/index.es.js +1965 -1958
  56. package/dist/components/index.umd.js +1 -1
  57. package/dist/composables/index.es.js +34 -34
  58. package/dist/composables/index.umd.js +2 -2
  59. package/dist/composables/useModifiers.d.ts +1 -1
  60. package/dist/constants.d.ts +2 -2
  61. package/dist/directives/index.es.js +22 -22
  62. package/dist/directives/index.umd.js +1 -1
  63. package/dist/directives/v-contextmenu.es.js +13 -13
  64. package/dist/directives/v-contextmenu.umd.js +1 -1
  65. package/dist/index.d.ts +2 -2
  66. package/dist/index.es.js +19 -19
  67. package/dist/index.umd.js +1 -1
  68. package/dist/json-render/index.es.js +1877 -1870
  69. package/dist/json-render/index.umd.js +1 -1
  70. package/dist/props/index.d.ts +1 -1
  71. package/dist/resolvers/unplugin.es.js +28 -28
  72. package/dist/resolvers/unplugin.umd.js +1 -1
  73. package/dist/types/alert.d.ts +1 -1
  74. package/dist/types/nav.d.ts +1 -1
  75. package/dist/utils/ObjectUtilities.d.ts +0 -6
  76. package/package.json +1 -1
  77. package/src/Volver.ts +8 -6
  78. package/src/components/VvAction/index.ts +1 -3
  79. package/src/components/VvButton/VvButton.vue +1 -1
  80. package/src/components/VvCheckboxGroup/index.ts +1 -3
  81. package/src/components/VvCombobox/VvCombobox.vue +3 -3
  82. package/src/components/VvDropdown/VvDropdown.vue +8 -8
  83. package/src/components/VvIcon/VvIcon.vue +3 -6
  84. package/src/components/VvInputFile/VvInputFile.vue +6 -6
  85. package/src/components/VvInputText/VvInputText.vue +95 -78
  86. package/src/components/VvRadioGroup/index.ts +1 -3
  87. package/src/composables/useBlurhash.ts +1 -1
  88. package/src/composables/useDebouncedInput.ts +1 -1
  89. package/src/composables/useDefaults.ts +55 -44
  90. package/src/composables/useModifiers.ts +1 -1
  91. package/src/index.ts +2 -2
  92. package/src/resolvers/unplugin.ts +6 -6
  93. package/src/types/alert.ts +1 -1
  94. package/src/types/nav.ts +1 -1
  95. package/src/utils/DateUtilities.ts +3 -3
  96. package/src/utils/DomUtilities.ts +7 -1
  97. package/src/utils/ObjectUtilities.ts +60 -59
@@ -10,6 +10,53 @@ type VueProp
10
10
  | BooleanConstructor
11
11
  | PropType<unknown>
12
12
 
13
+ type PropDefinition
14
+ = | VueProp
15
+ | VueProp[]
16
+ | { type: VueProp | VueProp[], default?: unknown }
17
+
18
+ /**
19
+ * Returns the value a prop should take: either the provided `propValue` or the
20
+ * `componentDefault` when `propValue` still matches the prop definition default.
21
+ * The three checks are intentionally independent (an array definition satisfies
22
+ * both `Array.isArray` and `typeof === 'object'`).
23
+ */
24
+ function resolveDefaultedProp(
25
+ definition: PropDefinition,
26
+ propValue: unknown,
27
+ componentDefault: unknown,
28
+ ): unknown {
29
+ let value = propValue
30
+ // array of types
31
+ if (Array.isArray(definition) && definition.length) {
32
+ const typeFunction = definition[0] as <T>() => T
33
+ if (typeFunction() === propValue) {
34
+ value = componentDefault
35
+ }
36
+ }
37
+ // single type
38
+ if (typeof definition === 'function') {
39
+ const typeFunction = definition as <T>() => T
40
+ if (typeFunction() === propValue) {
41
+ value = componentDefault
42
+ }
43
+ }
44
+ // object with type and default
45
+ if (typeof definition === 'object') {
46
+ let defaultValue = (definition as { default: unknown }).default
47
+ if (typeof defaultValue === 'function') {
48
+ defaultValue = defaultValue()
49
+ }
50
+ const matches = typeof defaultValue === 'object'
51
+ ? JSON.stringify(defaultValue) === JSON.stringify(propValue)
52
+ : defaultValue === propValue
53
+ if (matches) {
54
+ value = componentDefault
55
+ }
56
+ }
57
+ return value
58
+ }
59
+
13
60
  export function useDefaults<Definition>(
14
61
  componentName: string,
15
62
  propsDefinition: Definition,
@@ -18,7 +65,7 @@ export function useDefaults<Definition>(
18
65
  const volver = useVolver()
19
66
 
20
67
  const volverComponentDefaults = computed(() => {
21
- if (!volver || !volver.defaults.value?.[componentName]) {
68
+ if (!volver?.defaults.value?.[componentName]) {
22
69
  return undefined
23
70
  }
24
71
  return volver.defaults.value[componentName]
@@ -38,49 +85,13 @@ export function useDefaults<Definition>(
38
85
  const simplifiedProps = props as Record<string, unknown>
39
86
  return Object.keys(simplifiedPropsDefinition).reduce((acc, key) => {
40
87
  const propValue = simplifiedProps[key]
41
- acc[key] = propValue
42
- if (key in componentDefaults) {
43
- // array of types
44
- if (Array.isArray(simplifiedPropsDefinition[key])) {
45
- const typeArray = simplifiedPropsDefinition[
46
- key
47
- ] as VueProp[]
48
- if (typeArray.length) {
49
- const typeFunction = typeArray[0] as <T>() => T
50
- if (typeFunction === propValue) {
51
- acc[key] = componentDefaults[key]
52
- }
53
- }
54
- }
55
- // single type
56
- if (typeof simplifiedPropsDefinition[key] === 'function') {
57
- const typeFunction = simplifiedPropsDefinition[key] as <
58
- T,
59
- >() => T
60
- if (typeFunction() === propValue) {
61
- acc[key] = componentDefaults[key]
62
- }
63
- }
64
- // object with type and default
65
- if (typeof simplifiedPropsDefinition[key] === 'object') {
66
- let defaultValue = (
67
- simplifiedPropsDefinition[key] as { default: unknown }
68
- ).default
69
- if (typeof defaultValue === 'function') {
70
- defaultValue = defaultValue()
71
- }
72
- if (typeof defaultValue === 'object') {
73
- if (
74
- JSON.stringify(defaultValue)
75
- === JSON.stringify(propValue)
76
- ) {
77
- acc[key] = componentDefaults[key]
78
- }
79
- } else if (defaultValue === propValue) {
80
- acc[key] = componentDefaults[key]
81
- }
82
- }
83
- }
88
+ acc[key] = key in componentDefaults
89
+ ? resolveDefaultedProp(
90
+ simplifiedPropsDefinition[key],
91
+ propValue,
92
+ componentDefaults[key],
93
+ )
94
+ : propValue
84
95
  return acc
85
96
  }, {} as Record<string, unknown>) as Readonly<
86
97
  ExtractPropTypes<Definition>
@@ -2,7 +2,7 @@ import type { Ref } from 'vue'
2
2
 
3
3
  export function useModifiers(
4
4
  prefix: string,
5
- modifiers?: Ref<string | string[] | unknown | unknown[] | undefined>,
5
+ modifiers?: Ref<unknown>,
6
6
  others?: Ref<Record<string, boolean>>,
7
7
  ) {
8
8
  return computed(() => {
package/src/index.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { Volver, VolverOptions } from './Volver'
1
+ import type { Volver } from './Volver'
2
2
  import VolverPlugin from './Volver'
3
3
 
4
4
  export { VolverPlugin }
5
5
  export * from './types'
6
- export type { Volver, VolverOptions }
6
+ export type { Volver, VolverOptions } from './Volver'
7
7
 
8
8
  // https://vuejs.org/guide/typescript/options-api.html#augmenting-global-properties
9
9
  // Add custom property and extend vue type definition
@@ -35,12 +35,12 @@ export interface VolverResolverOptions {
35
35
  cherryPick?: boolean
36
36
  }
37
37
 
38
- const STYLE_EXCLUDE = ['vv-icon', 'vv-action']
38
+ const STYLE_EXCLUDE = new Set(['vv-icon', 'vv-action'])
39
39
  const VOLVER_PREFIX = 'vv'
40
- const DIRECTIVES = ['v-tooltip', 'v-contextmenu']
40
+ const DIRECTIVES = new Set(['v-tooltip', 'v-contextmenu'])
41
41
 
42
42
  export function getStyleNames(kebabName: string) {
43
- if (STYLE_EXCLUDE.includes(kebabName)) {
43
+ if (STYLE_EXCLUDE.has(kebabName)) {
44
44
  return undefined
45
45
  }
46
46
  if (kebabName === 'vv-dropdown') {
@@ -125,7 +125,7 @@ export function VolverResolver({
125
125
  `${VOLVER_PREFIX}-`,
126
126
  )
127
127
 
128
- if (ignore && ignore.includes(kebabName)) {
128
+ if (ignore?.includes(kebabName)) {
129
129
  return
130
130
  }
131
131
 
@@ -153,11 +153,11 @@ export function VolverResolver({
153
153
  const kebabName = `v-${kebabCase(name)}`
154
154
 
155
155
  // filter directive
156
- if (!DIRECTIVES.includes(kebabName)) {
156
+ if (!DIRECTIVES.has(kebabName)) {
157
157
  return
158
158
  }
159
159
 
160
- if (ignore && ignore.includes(kebabName)) {
160
+ if (ignore?.includes(kebabName)) {
161
161
  return
162
162
  }
163
163
 
@@ -8,7 +8,7 @@ export type AlertModifier
8
8
  | 'danger'
9
9
  | 'brand'
10
10
  | 'accent'
11
- | string
11
+ | (string & {})
12
12
 
13
13
  export type Alert = {
14
14
  id: string | number
package/src/types/nav.ts CHANGED
@@ -9,7 +9,7 @@ export type NavItem = {
9
9
  disabled?: boolean
10
10
  current?: boolean
11
11
  class?: string | string[]
12
- on?: Record<'click' | string, () => void>
12
+ on?: Record<'click' | (string & {}), () => void>
13
13
  data?: Record<string, unknown>
14
14
  }
15
15
 
@@ -12,14 +12,14 @@ const padTwoDigits = (num: number) => num.toString().padStart(2, '0')
12
12
  * @param dateString
13
13
  * @returns True if valid ISO date string
14
14
  * @example
15
- * isDateIsoString('2021-12-31T23:59:59') // true
15
+ * isDateIsoString('2021-12-31T23:59:59.000Z') // true
16
16
  */
17
- const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:?\d{2})?$/
17
+ // Canonical UTC form, matching what `Date.prototype.toISOString()` produces.
18
+ const ISO_DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/
18
19
  export function isDateIsoString(dateString: unknown) {
19
20
  if (typeof dateString !== 'string') {
20
21
  return false
21
22
  }
22
- // Support both with/without milliseconds and timezone variations
23
23
  if (!ISO_DATE_REGEX.test(dateString)) {
24
24
  return false
25
25
  }
@@ -2,9 +2,15 @@ export function findScrollContainer(element: HTMLElement | null) {
2
2
  if (!element) {
3
3
  return undefined
4
4
  }
5
+ if (
6
+ typeof globalThis.getComputedStyle !== 'function'
7
+ || typeof document === 'undefined'
8
+ ) {
9
+ return undefined
10
+ }
5
11
  let parent = element.parentElement
6
12
  while (parent) {
7
- const { overflow } = window.getComputedStyle(parent)
13
+ const { overflow } = globalThis.getComputedStyle(parent)
8
14
  if (overflow.split(' ').every(item => item === 'auto' || item === 'scroll')) {
9
15
  return parent
10
16
  }
@@ -22,67 +22,69 @@ export function equals(obj1: any, obj2: any, field?: string) {
22
22
  * @returns {boolean}
23
23
  */
24
24
 
25
- export function deepEquals(a: any, b: any) {
26
- if (a === b)
27
- return true
25
+ function deepEqualsArray(a: any[], b: any[]) {
26
+ if (a.length !== b.length)
27
+ return false
28
+ for (let i = a.length; i-- !== 0;) {
29
+ if (!deepEquals(a[i], b[i]))
30
+ return false
31
+ }
32
+ return true
33
+ }
28
34
 
29
- if (a && b && typeof a == 'object' && typeof b == 'object') {
30
- const arrA = Array.isArray(a)
31
- const arrB = Array.isArray(b)
32
- let i, length, key
33
-
34
- if (arrA && arrB) {
35
- length = a.length
36
- if (length !== b.length)
37
- return false
38
- for (i = length; i-- !== 0;) {
39
- if (!deepEquals(a[i], b[i]))
40
- return false
41
- }
35
+ function deepEqualsObject(a: any, b: any) {
36
+ const keys = Object.keys(a)
37
+ const { length } = keys
42
38
 
43
- return true
44
- }
39
+ if (length !== Object.keys(b).length)
40
+ return false
45
41
 
46
- if (arrA !== arrB)
42
+ for (let i = length; i-- !== 0;) {
43
+ if (!Object.hasOwn(b, keys[i]))
47
44
  return false
45
+ }
48
46
 
49
- const dateA = a instanceof Date
50
- const dateB = b instanceof Date
51
-
52
- if (dateA !== dateB)
47
+ for (let i = length; i-- !== 0;) {
48
+ const key = keys[i]
49
+ if (!deepEquals(a[key], b[key]))
53
50
  return false
54
- if (dateA && dateB)
55
- return a.getTime() === b.getTime()
51
+ }
56
52
 
57
- const regexpA = a instanceof RegExp
58
- const regexpB = b instanceof RegExp
53
+ return true
54
+ }
59
55
 
60
- if (regexpA !== regexpB)
61
- return false
62
- if (regexpA && regexpB)
63
- return a.toString() === b.toString()
56
+ export function deepEquals(a: any, b: any) {
57
+ if (a === b)
58
+ return true
64
59
 
65
- const keys = Object.keys(a)
60
+ if (!a || !b || typeof a !== 'object' || typeof b !== 'object')
61
+ return Number.isNaN(a) && Number.isNaN(b)
66
62
 
67
- length = keys.length
63
+ const arrA = Array.isArray(a)
64
+ const arrB = Array.isArray(b)
68
65
 
69
- if (length !== Object.keys(b).length)
70
- return false
66
+ if (arrA !== arrB)
67
+ return false
68
+ if (arrA && arrB)
69
+ return deepEqualsArray(a, b)
71
70
 
72
- for (i = length; i-- !== 0;) {
73
- if (!Object.hasOwn(b, keys[i]))
74
- return false
75
- }
71
+ const dateA = a instanceof Date
72
+ const dateB = b instanceof Date
76
73
 
77
- for (i = length; i-- !== 0;) {
78
- key = keys[i]
79
- if (!deepEquals(a[key], b[key]))
80
- return false
81
- }
74
+ if (dateA !== dateB)
75
+ return false
76
+ if (dateA && dateB)
77
+ return a.getTime() === b.getTime()
82
78
 
83
- return true
84
- }
85
- return Number.isNaN(a) && Number.isNaN(b)
79
+ const regexpA = a instanceof RegExp
80
+ const regexpB = b instanceof RegExp
81
+
82
+ if (regexpA !== regexpB)
83
+ return false
84
+ if (regexpA && regexpB)
85
+ return a.toString() === b.toString()
86
+
87
+ return deepEqualsObject(a, b)
86
88
  }
87
89
 
88
90
  /**
@@ -95,20 +97,19 @@ export function resolveFieldData(data: Record<string, unknown>, field: string) {
95
97
  if (data && Object.keys(data).length && field) {
96
98
  if (!field.includes('.')) {
97
99
  return data[field]
98
- } else {
99
- const fields = field.split('.')
100
- let value = data
101
-
102
- for (let i = 0, len = fields.length; i < len; ++i) {
103
- if (data == null) {
104
- return null
105
- }
100
+ }
101
+ const fields = field.split('.')
102
+ let value = data
106
103
 
107
- value = value[fields[i]] as Record<string, unknown>
104
+ for (let i = 0, len = fields.length; i < len; ++i) {
105
+ if (value == null) {
106
+ return null
108
107
  }
109
108
 
110
- return value
109
+ value = value[fields[i]] as Record<string, unknown>
111
110
  }
111
+
112
+ return value
112
113
  } else {
113
114
  return null
114
115
  }
@@ -120,7 +121,7 @@ export function resolveFieldData(data: Record<string, unknown>, field: string) {
120
121
  */
121
122
 
122
123
  export function isFunction(obj: any) {
123
- return !!(obj && obj.constructor && obj.call && obj.apply)
124
+ return !!(obj?.constructor && obj.call && obj.apply)
124
125
  }
125
126
 
126
127
  /**
@@ -151,7 +152,7 @@ export function findIndexInList<Type = unknown>(value: Type, list: Type[]) {
151
152
  * @returns {boolean} the index
152
153
  */
153
154
  export function contains<Type = unknown>(value: Type, list: Type[]) {
154
- if (value != null && list && list.length) {
155
+ if (value != null && list?.length) {
155
156
  for (const val of list) {
156
157
  if (equals(value, val)) {
157
158
  return true