@fy-/fws-vue 0.3.47 → 0.3.48

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.
@@ -5,7 +5,7 @@
5
5
  @keydown.delete.prevent="removeLastTag"
6
6
  @keydown.enter.prevent="addTag"
7
7
  >
8
- <span v-for="(tag, index) in tags" :key="index" :class="`tag ${color}`">
8
+ <span v-for="(tag, index) in model" :key="index" :class="`tag ${color}`">
9
9
  {{ tag }}
10
10
  <button type="button" @click.prevent="removeTag(index)">
11
11
  <svg
@@ -37,7 +37,7 @@
37
37
  </template>
38
38
 
39
39
  <script setup lang="ts">
40
- import { ref, watch, onMounted } from "vue";
40
+ import { ref, computed, onMounted } from "vue";
41
41
  type colorType = "blue" | "red" | "green" | "purple" | "orange" | "neutral";
42
42
 
43
43
  const props = withDefaults(
@@ -59,17 +59,15 @@ const props = withDefaults(
59
59
  },
60
60
  );
61
61
 
62
- const emit = defineEmits(["update:modelValue"]);
63
- const tags = ref([...props.modelValue]);
64
62
  const textInput = ref<HTMLElement>();
65
63
 
66
- watch(
67
- tags,
68
- (newTags) => {
69
- emit("update:modelValue", newTags);
64
+ const emit = defineEmits(["update:modelValue"]);
65
+ const model = computed({
66
+ get: () => props.modelValue,
67
+ set: (items) => {
68
+ emit("update:modelValue", items);
70
69
  },
71
- { deep: true },
72
- );
70
+ });
73
71
 
74
72
  onMounted(() => {
75
73
  if (props.autofocus) {
@@ -92,19 +90,19 @@ const addTag = () => {
92
90
  .split(separatorsRegex)
93
91
  .map((tag: string) => tag.trim())
94
92
  .filter((tag: string) => tag.length > 0);
95
- tags.value.push(...newTags);
93
+ model.value.push(...newTags);
96
94
  textInput.value.innerText = "";
97
95
  };
98
96
 
99
97
  const removeTag = (index: number) => {
100
- tags.value.splice(index, 1);
98
+ model.value.splice(index, 1);
101
99
  focusInput();
102
100
  };
103
101
 
104
102
  const removeLastTag = () => {
105
103
  if (!textInput.value) return;
106
104
  if (textInput.value.innerText === "") {
107
- tags.value.pop();
105
+ model.value.pop();
108
106
  } else {
109
107
  const currentLength = textInput.value.innerText.length;
110
108
  textInput.value.innerText = textInput.value.innerText.slice(0, -1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "0.3.47",
3
+ "version": "0.3.48",
4
4
  "author": "Florian 'Fy' Gasquez <m@fy.to>",
5
5
  "license": "MIT",
6
6
  "repository": {