sprintify-ui 0.0.58 → 0.0.60

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprintify-ui",
3
- "version": "0.0.58",
3
+ "version": "0.0.60",
4
4
  "scripts": {
5
5
  "build": "rimraf dist && vue-tsc && vite build",
6
6
  "build-fast": "rimraf dist && vite build",
@@ -33,7 +33,14 @@ const Template = (args) => ({
33
33
  // For optional, make sure the default option is selected
34
34
  // For required, try to submit, it should be prevented
35
35
  const value = ref('test');
36
- return { args, value, onSubmit };
36
+
37
+ // Test if dynamically added options are available & selected
38
+ const showTest = ref(false);
39
+ setTimeout(() => {
40
+ showTest.value = true;
41
+ }, 3000);
42
+
43
+ return { args, value, showTest, onSubmit };
37
44
  },
38
45
  template: `
39
46
  <form @submit.prevent="onSubmit" class="border-none">
@@ -42,6 +49,7 @@ const Template = (args) => ({
42
49
  <option value="javascript">JavaScript</option>
43
50
  <option value="typescript">Typescript</option>
44
51
  <option value="golang">Golang</option>
52
+ <option v-if="showTest" value="test">Test</option>
45
53
  </BaseSelect>
46
54
  <button type="submit" class="btn btn-primary mt-5">Submit</button>
47
55
  </form>
@@ -29,7 +29,7 @@
29
29
  <script lang="ts" setup>
30
30
  import { PropType, Ref } from 'vue';
31
31
  import { get, isEqual } from 'lodash';
32
- import { useMounted } from '@vueuse/core';
32
+ import { useMutationObserver } from '@vueuse/core';
33
33
  import { useField } from '@/composables/field';
34
34
 
35
35
  type Option = string | number | null;
@@ -76,6 +76,8 @@ const { nameInternal, requiredInternal, hasErrorInternal, emitUpdate } =
76
76
  emit: emit,
77
77
  });
78
78
 
79
+ const options = ref([] as HTMLOptionElement[]);
80
+
79
81
  function isEmptyExternal(value: string | number | null | undefined) {
80
82
  if (value === undefined || value === EMPTY_VALUE_EXTERNAL) {
81
83
  return true;
@@ -101,7 +103,7 @@ const modelValueInternal = computed(() => {
101
103
  return EMPTY_VALUE_INTERNAL;
102
104
  }
103
105
 
104
- if (!validModelValue()) {
106
+ if (!checkIfModelValueIsValid()) {
105
107
  return EMPTY_VALUE_INTERNAL;
106
108
  }
107
109
 
@@ -111,13 +113,30 @@ const modelValueInternal = computed(() => {
111
113
  /**
112
114
  * Checks if the current modelValue is valid
113
115
  */
114
- function validModelValue(): boolean {
116
+ useMutationObserver(
117
+ select,
118
+ () => {
119
+ options.value = getOptions();
120
+ },
121
+ { attributes: false, childList: true }
122
+ );
123
+
124
+ onMounted(() => {
125
+ options.value = getOptions();
126
+ });
127
+
128
+ function getOptions(): HTMLOptionElement[] {
129
+ return [...(select.value?.options ?? [])];
130
+ }
131
+
132
+ function checkIfModelValueIsValid(): boolean {
115
133
  if (props.modelValue === EMPTY_VALUE_EXTERNAL) {
116
134
  return true;
117
135
  }
118
136
 
119
- const options = [...(select.value?.options ?? [])];
120
- return options.findIndex((o) => isEqual(o.value, props.modelValue)) != -1;
137
+ return (
138
+ options.value.findIndex((o) => isEqual(o.value, props.modelValue)) != -1
139
+ );
121
140
  }
122
141
 
123
142
  /**