@mptw/skylens-ui 1.2.10 → 1.2.12

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.
@@ -12,10 +12,10 @@
12
12
  .select-menu-popup(ref="popupEl")
13
13
  .select-header
14
14
  SLSearchInput(
15
- v-model='query',
15
+ v-model='queryProxy',
16
16
  :placeholder='searchPlaceholder',
17
17
  :lazy='500',
18
- :isSearch='query !== ""',
18
+ :isSearch='queryProxy !== ""',
19
19
  @clear="onClearQuery"
20
20
  )
21
21
  .select-body
@@ -111,36 +111,53 @@ export default defineComponent({
111
111
  >,
112
112
  default: () => [],
113
113
  },
114
+ query: {
115
+ type: String,
116
+ default: '',
117
+ }
114
118
  },
115
- emits: ["update:modelValue", "update:selecting"],
119
+ emits: ["update:modelValue", "update:selecting", 'update:query'],
116
120
  setup(props, { emit }) {
117
- const { size, modelValue, options, placement } = toRefs(props);
121
+ const { size, modelValue, options, placement, query } = toRefs(props);
118
122
 
119
123
  const selectEl = shallowRef<HTMLElement | null>(null);
120
124
  const toggleEl = shallowRef<HTMLElement | null>(null);
121
125
  const popupEl = shallowRef<HTMLElement | null>(null);
122
- const query = ref("");
126
+ const selfQuery = ref("");
123
127
  const selectedFirstOption = ref<string | null>(null);
124
128
  const isSelecting = ref(false);
125
129
 
126
130
  let popperInstance: any = null;
127
131
  let clickSubscriber: any = null;
128
132
 
133
+ const queryProxy = computed({
134
+ get() { query.value || selfQuery },
135
+ set(newValue: string) {
136
+ emit('update:query', newValue);
137
+ selfQuery.value = newValue;
138
+ },
139
+ });
129
140
  const sizeClass = computed(() => {
130
141
  if (size.value === "") return "";
131
142
  return `two-layer-multi-select-${size.value}`;
132
143
  });
133
144
  const filteredOptions = computed(() => {
134
- if (query.value === "") {
145
+ if (queryProxy.value === "") {
135
146
  return options.value;
136
147
  }
137
148
 
138
- const regexp = new RegExp(`.*${query.value}.*`, "i");
149
+ const regexp = new RegExp(`.*${queryProxy.value}.*`, "i");
139
150
  return options.value
140
- .map((option) => ({
141
- ...option,
142
- subOptions: option.subOptions.filter((o) => regexp.test(o.name)),
143
- }))
151
+ .map((option) => {
152
+ if (regexp.test(option.name)) {
153
+ return option;
154
+ }
155
+
156
+ return {
157
+ ...option,
158
+ subOptions: option.subOptions.filter((o) => regexp.test(o.name)),
159
+ };
160
+ })
144
161
  .filter((option) => option.subOptions.length > 0);
145
162
  });
146
163
  const firstOptions = computed(() => {
@@ -201,7 +218,7 @@ export default defineComponent({
201
218
  }
202
219
 
203
220
  function onClearQuery() {
204
- query.value = "";
221
+ queryProxy.value = "";
205
222
  }
206
223
 
207
224
  function subscribeClick() {
@@ -267,7 +284,7 @@ export default defineComponent({
267
284
  modifiers: [{ name: "eventListeners", enabled: false }],
268
285
  });
269
286
 
270
- query.value = "";
287
+ queryProxy.value = "";
271
288
  }
272
289
 
273
290
  function onClickedToggle() {
@@ -309,7 +326,7 @@ export default defineComponent({
309
326
  selectEl,
310
327
  toggleEl,
311
328
  popupEl,
312
- query,
329
+ queryProxy,
313
330
  sizeClass,
314
331
  selectedFirstOption,
315
332
  firstOptions,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mptw/skylens-ui",
3
3
  "type": "module",
4
- "version": "1.2.10",
4
+ "version": "1.2.12",
5
5
  "main": "./nuxt.config.ts",
6
6
  "scripts": {
7
7
  "dev": "nuxi dev .playground",