@citizenplane/pimp 9.7.11 → 9.7.14

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": "@citizenplane/pimp",
3
- "version": "9.7.11",
3
+ "version": "9.7.14",
4
4
  "scripts": {
5
5
  "dev": "storybook dev -p 8080",
6
6
  "build-storybook": "storybook build --output-dir ./docs",
@@ -145,7 +145,6 @@ const selectModel = computed({
145
145
  if (typeof value === 'string') {
146
146
  return
147
147
  }
148
-
149
148
  emit('update:modelValue', value)
150
149
  },
151
150
  })
@@ -197,7 +196,6 @@ const handleOverlayHidden = () => emit('overlayHidden')
197
196
 
198
197
  const handleValueChange = (newValue: string | object) => {
199
198
  if (typeof newValue !== 'string') return
200
-
201
199
  searchQuery.value = newValue
202
200
  emit('searchChange', newValue)
203
201
  }
@@ -210,9 +208,7 @@ const getInputElement = () => {
210
208
 
211
209
  const selectInputContent = () => {
212
210
  const inputElement = getInputElement()
213
- if (inputElement) {
214
- inputElement.select()
215
- }
211
+ if (inputElement) inputElement.select()
216
212
  }
217
213
 
218
214
  const focusAndSelectInput = () => {
@@ -245,9 +241,7 @@ const toggleDropdown = () => {
245
241
 
246
242
  const handleUpdateModelValue = (value: Record<string, unknown> | string[] | null) => {
247
243
  // Autocomplete will set the model value to the query string if not blocked
248
- if (!value || typeof value === 'string') {
249
- return
250
- }
244
+ if (!value || typeof value === 'string') return
251
245
  }
252
246
 
253
247
  const overrideAlignOverlay = () => {
@@ -0,0 +1,12 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ // https://decipher.dev/30-seconds-of-typescript/docs/debounce/
3
+ export function debounce<T extends (...args: any[]) => any>(
4
+ fn: T,
5
+ wait: number = 300,
6
+ ): (...args: Parameters<T>) => void {
7
+ let timeout: ReturnType<typeof setTimeout>
8
+ return function (this: any, ...args: Parameters<T>) {
9
+ clearTimeout(timeout)
10
+ timeout = setTimeout(() => fn.apply(this, args), wait)
11
+ }
12
+ }
@@ -4,7 +4,14 @@ import type { Meta, StoryObj } from '@storybook/vue3'
4
4
 
5
5
  import CpMultiselect from '@/components/CpMultiselect.vue'
6
6
 
7
- const supplierOptions = [
7
+ interface IOption {
8
+ disabled?: boolean
9
+ iata_code?: string
10
+ id: number
11
+ name: string
12
+ }
13
+
14
+ const supplierOptions: IOption[] = [
8
15
  { id: 1, name: 'MGA AIRLINES' },
9
16
  { id: 2, name: 'ZENITH - EUROATLANTIC AIRWAYS' },
10
17
  { id: 3, name: 'ZENITH - SOUTHERN AIRWAYS EXPRESS MOKULELE AIRLINES AND SURF AIR MOBILITY' },
@@ -18,7 +25,7 @@ const supplierOptions = [
18
25
  { id: 11, name: 'UNITRAVEL UTAZÁSI IRODA' },
19
26
  ]
20
27
 
21
- const airlineOptions = [
28
+ const airlineOptions: IOption[] = [
22
29
  { id: 1, name: 'United Airlines', iata_code: 'UA' },
23
30
  { id: 2, name: 'Delta Airlines', iata_code: 'DL' },
24
31
  { id: 3, name: 'American Airlines', iata_code: 'AA' },
@@ -123,24 +130,21 @@ export const Single: Story = {
123
130
 
124
131
  const originalOptions = ref(args.options)
125
132
  const dynamicOptions = ref(toValue(originalOptions))
133
+ const selectedSupplier = ref(null)
126
134
 
127
135
  const handleSearch = async (query: string) => {
128
136
  isLoading.value = true
129
137
  searchQuery.value = query
130
138
 
131
- dynamicOptions.value = originalOptions.value
132
-
133
139
  await new Promise((resolve) => setTimeout(resolve, 500))
134
140
 
135
- dynamicOptions.value = dynamicOptions.value?.filter((option) => {
136
- // @ts-expect-error option is unknown
137
- return option.name.toLowerCase().includes(searchQuery.value.toLowerCase())
141
+ dynamicOptions.value = originalOptions.value?.filter((option) => {
142
+ return (option as IOption).name.toLowerCase().includes(searchQuery.value.toLowerCase())
138
143
  })
139
144
 
140
145
  isLoading.value = false
141
146
  }
142
147
 
143
- const selectedSupplier = ref(null)
144
148
  return { args, selectedSupplier, dynamicOptions, handleSearch, isLoading }
145
149
  },
146
150
  template: `
@@ -174,24 +178,21 @@ export const Multiple: Story = {
174
178
 
175
179
  const originalOptions = ref(args.options)
176
180
  const dynamicOptions = ref(toValue(originalOptions))
181
+ const selectedAirlines = ref([])
177
182
 
178
183
  const handleSearch = async (query: string) => {
179
184
  isLoading.value = true
180
185
  searchQuery.value = query
181
186
 
182
- if (!searchQuery.value) return (dynamicOptions.value = originalOptions.value)
183
-
184
187
  await new Promise((resolve) => setTimeout(resolve, 500))
185
188
 
186
- dynamicOptions.value = dynamicOptions.value?.filter((option) => {
187
- // @ts-expect-error option is unknown
188
- return option.name.toLowerCase().includes(searchQuery.value.toLowerCase())
189
+ dynamicOptions.value = originalOptions.value?.filter((option) => {
190
+ return (option as IOption).name.toLowerCase().includes(searchQuery.value.toLowerCase())
189
191
  })
190
192
 
191
193
  isLoading.value = false
192
194
  }
193
195
 
194
- const selectedAirlines = ref([])
195
196
  return { args, selectedAirlines, dynamicOptions, handleSearch, isLoading }
196
197
  },
197
198
  template: `