@sfxcode/formkit-primevue 2.9.8 → 2.9.9

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.
@@ -1,9 +1,8 @@
1
1
  <script setup lang='ts'>
2
2
  import type { FormKitFrameworkContext } from '@formkit/core'
3
3
  import type { AutoCompleteCompleteEvent, AutoCompleteProps } from 'primevue/autocomplete'
4
-
5
4
  import type { PropType } from 'vue'
6
- import { ref } from 'vue'
5
+ import { ref, watch } from 'vue'
7
6
  import { useFormKitInput } from '../composables'
8
7
 
9
8
  export interface FormKitPrimeAutoCompleteProps {
@@ -35,11 +34,30 @@ const suggestions = ref(['', {}])
35
34
  suggestions.value = []
36
35
  const loading = ref(false)
37
36
 
37
+ // Local value for v-model
38
+ const localValue = ref(props.context._value)
39
+
40
+ // Sync localValue with context._value
41
+ watch(
42
+ () => props.context._value,
43
+ (newVal) => {
44
+ localValue.value = newVal
45
+ },
46
+ )
47
+
48
+ // Emit changes from localValue to context
49
+ watch(
50
+ localValue,
51
+ (newVal) => {
52
+ if (newVal !== props.context._value) {
53
+ props.context._value = newVal
54
+ props.context?.node?.input?.(newVal)
55
+ }
56
+ },
57
+ )
58
+
38
59
  /**
39
60
  * Searches for suggestions based on the input query.
40
- * If options and optionLabel are provided, it filters the options.
41
- * Otherwise, it calls the complete function from the context to fetch suggestions.
42
- * @param event - The AutoCompleteCompleteEvent containing the query.
43
61
  */
44
62
  async function search(event: AutoCompleteCompleteEvent) {
45
63
  if (props.context?.options && props.context?.optionLabel) {
@@ -64,7 +82,6 @@ async function search(event: AutoCompleteCompleteEvent) {
64
82
 
65
83
  /**
66
84
  * Handles paste event to transform a string separated by any of the provided separators into multiple items.
67
- * @param event - The paste event from the input.
68
85
  */
69
86
  function handlePaste(event: ClipboardEvent) {
70
87
  if (!props.context?.multiple)
@@ -76,21 +93,32 @@ function handlePaste(event: ClipboardEvent) {
76
93
  const separators = Array.isArray(props.context?.separators) && props.context.separators.length > 0
77
94
  ? props.context.separators
78
95
  : [',']
79
- // Create a regex to split by any separator, escaping special regex characters
80
96
  const regex = new RegExp(`[${separators.map(s => s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&')).join('')}]`)
97
+ // If separators are provided, split the pasted text by them
81
98
  if (pastedText && regex.test(pastedText)) {
82
99
  event.preventDefault()
83
100
  const items = pastedText
84
101
  .split(regex)
85
102
  .map(item => item.trim())
86
103
  .filter(item => item.length > 0)
87
- if (Array.isArray(props.context._value)) {
88
- props.context._value.push(...items)
104
+ // Use a local ref, never mutate context._value directly
105
+ if (Array.isArray(localValue.value)) {
106
+ localValue.value = [...localValue.value, ...items]
107
+ }
108
+ else {
109
+ localValue.value = items
110
+ }
111
+ }
112
+ // If no separators, just set the value directly
113
+ else if (pastedText) {
114
+ event.preventDefault()
115
+ // If no separators, just set the value directly
116
+ if (Array.isArray(localValue.value)) {
117
+ localValue.value = [...localValue.value, pastedText.trim()]
89
118
  }
90
119
  else {
91
- props.context._value = items
120
+ localValue.value = [pastedText.trim()]
92
121
  }
93
- props.context?.node?.input?.(props.context?._value)
94
122
  }
95
123
  }
96
124
  </script>
@@ -99,7 +127,7 @@ function handlePaste(event: ClipboardEvent) {
99
127
  <div class="p-formkit">
100
128
  <AutoComplete
101
129
  :id="context.id"
102
- v-model="context._value"
130
+ v-model="localValue"
103
131
  v-bind="context?.attrs"
104
132
  :disabled="!!context?.disabled"
105
133
  :class="context?.attrs?.class"
@@ -21,8 +21,11 @@ function useFormKitRepeater() {
21
21
  }
22
22
  function addListGroupFunctions(data, addNodeDefaultObject = {}) {
23
23
  const swapElements = (array, index1, index2) => {
24
- array[index1] = array.splice(index2, 1, array[index1])[0];
25
- return array;
24
+ const newArray = [...array];
25
+ const temp = newArray[index1];
26
+ newArray[index1] = newArray[index2];
27
+ newArray[index2] = temp;
28
+ return newArray;
26
29
  };
27
30
  data.addNode = parentNode => () => {
28
31
  const newArray = [...parentNode.value, addNodeDefaultObject];
@@ -8,8 +8,11 @@ export function useFormKitRepeater() {
8
8
  }
9
9
  function addListGroupFunctions(data, addNodeDefaultObject = {}) {
10
10
  const swapElements = (array, index1, index2) => {
11
- array[index1] = array.splice(index2, 1, array[index1])[0];
12
- return array;
11
+ const newArray = [...array];
12
+ const temp = newArray[index1];
13
+ newArray[index1] = newArray[index2];
14
+ newArray[index2] = temp;
15
+ return newArray;
13
16
  };
14
17
  data.addNode = (parentNode) => () => {
15
18
  const newArray = [...parentNode.value, addNodeDefaultObject];
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@sfxcode/formkit-primevue",
3
3
  "type": "module",
4
- "version": "2.9.8",
5
- "packageManager": "pnpm@10.10.0+sha512.d615db246fe70f25dcfea6d8d73dee782ce23e2245e3c4f6f888249fb568149318637dca73c2c5c8ef2a4ca0d5657fb9567188bfab47f566d1ee6ce987815c39",
4
+ "version": "2.9.9",
5
+ "packageManager": "pnpm@10.13.1+sha512.37ebf1a5c7a30d5fabe0c5df44ee8da4c965ca0c5af3dbab28c3a1681b70a256218d05c81c9c0dcf767ef6b8551eb5b960042b9ed4300c59242336377e01cfad",
6
6
  "author": {
7
7
  "name": "Tom",
8
8
  "email": "tom@sfxcode.com"
@@ -123,7 +123,7 @@
123
123
  "happy-dom": "^18.0.1",
124
124
  "json-editor-vue": "^0.18.1",
125
125
  "mkdist": "^2.3.0",
126
- "quill": "^2.0.3",
126
+ "quill": "1.3.7",
127
127
  "sass": "^1.89.2",
128
128
  "tslib": "^2.8.1",
129
129
  "typescript": "^5.8.3",