@d-mok/quasar-app-extension-quasar-axe 1.0.75 → 1.0.78

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/utils/dialog.ts +84 -108
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@d-mok/quasar-app-extension-quasar-axe",
3
- "version": "1.0.75",
3
+ "version": "1.0.78",
4
4
  "description": "A Quasar App Extension",
5
5
  "author": "d-mok <49301824+d-mok@users.noreply.github.com>",
6
6
  "license": "MIT",
@@ -63,10 +63,13 @@ function extractObj<T extends object>(
63
63
  return obj
64
64
  }
65
65
 
66
+ function maxStringLength(strings: string[]): number {
67
+ return Math.max(0, ...strings.map($ => $.length))
68
+ }
69
+
66
70
  class QDialog {
67
71
  /**
68
72
  * The basic dialog. If cancel, throw error.
69
- * For interal use.
70
73
  */
71
74
  private async baseDialog(options: QDialogOptions): Promise<string> {
72
75
  let base: QDialogOptions = {
@@ -87,6 +90,58 @@ class QDialog {
87
90
  })
88
91
  }
89
92
 
93
+ /**
94
+ * The basic textarea.
95
+ */
96
+ private async baseTextarea(options: QDialogOptions): Promise<string> {
97
+ let { prompt, ...rest } = options
98
+ let str = await this.baseDialog({
99
+ prompt: {
100
+ type: 'textarea',
101
+ outlined: true,
102
+ //@ts-ignore // This is a bug from quasar
103
+ style: "font-family: 'Courier New', monospace;",
104
+ rows: 20,
105
+ ...prompt,
106
+ },
107
+ ...rest,
108
+ })
109
+ return str
110
+ }
111
+
112
+ /**
113
+ * The basic CSV.
114
+ */
115
+ private async baseCSV(
116
+ options: QDialogOptions,
117
+ sample: object[]
118
+ ): Promise<string> {
119
+ let lines = unparseCSV(sample).split('\n')
120
+ let words = lines.flatMap(l => l.split('\t'))
121
+ let maxWordLength = maxStringLength(words)
122
+ let maxLineLength = maxStringLength(
123
+ lines.map($ => $.replace('\t', ' '.repeat(maxWordLength + 2)))
124
+ )
125
+
126
+ let { prompt, ...rest } = options
127
+ let csv = await this.baseDialog({
128
+ prompt: {
129
+ type: 'textarea',
130
+ outlined: true,
131
+ //@ts-ignore // This is a bug from quasar
132
+ style:
133
+ "font-family: 'Courier New', monospace;" +
134
+ 'tab-size: ' +
135
+ (maxWordLength + 2),
136
+ rows: 20,
137
+ ...prompt,
138
+ },
139
+ fullWidth: maxLineLength > 35,
140
+ ...rest,
141
+ })
142
+ return csv
143
+ }
144
+
90
145
  /**
91
146
  * Show a confirm dialog.
92
147
  * If OK, continue. If cancel, throw error.
@@ -194,13 +249,11 @@ class QDialog {
194
249
  prefill: string = '',
195
250
  isValid: Predicate<string> = $ => true
196
251
  ): Promise<string> {
197
- return this.baseDialog({
252
+ return this.baseTextarea({
198
253
  title,
199
254
  message,
200
255
  prompt: {
201
256
  model: prefill,
202
- type: 'textarea',
203
- outlined: true,
204
257
  isValid: isValid,
205
258
  },
206
259
  })
@@ -288,37 +341,20 @@ class QDialog {
288
341
  if (sample.length === 0)
289
342
  throw 'Dialog askCSV must provide at least one sample object.'
290
343
 
291
- let words = unparseCSV(sample)
292
- .split('\n')
293
- .flatMap(l => l.split('\t'))
294
- let maxWordLength = Math.max(...words.map($ => $.length))
295
-
296
- let lines = unparseCSV(sample)
297
- .split('\n')
298
- .map($ => $.replace('\t', ' '.repeat(maxWordLength + 2)))
299
- let maxLineLength = Math.max(...lines.map($ => $.length))
300
-
301
- let csv = await this.baseDialog({
302
- title,
303
- message,
304
- prompt: {
305
- model: unparseCSV(sample),
306
- type: 'textarea',
307
- outlined: true,
308
- isValid: (csv: string) =>
309
- parseCSV(csv, sample[0]).every(
310
- $ => schemaEqual($, sample[0]) && isValid($)
311
- ),
312
- //@ts-ignore // This is a bug from quasar
313
- style:
314
- "font-family: 'Courier New', monospace;" +
315
- 'tab-size: ' +
316
- (maxWordLength + 2),
317
- rows: Math.min(25, sample.length + 1),
318
- cols: maxLineLength + 5,
344
+ let csv = await this.baseCSV(
345
+ {
346
+ title,
347
+ message,
348
+ prompt: {
349
+ model: unparseCSV(sample),
350
+ isValid: (csv: string) =>
351
+ parseCSV(csv, sample[0]).every(
352
+ $ => schemaEqual($, sample[0]) && isValid($)
353
+ ),
354
+ },
319
355
  },
320
- fullWidth: maxLineLength > 35,
321
- })
356
+ sample
357
+ )
322
358
  return parseCSV(csv, sample[0])
323
359
  }
324
360
 
@@ -341,13 +377,11 @@ class QDialog {
341
377
  return s.split('\n').filter($ => $.trim() !== '')
342
378
  }
343
379
 
344
- let str = await this.baseDialog({
380
+ let str = await this.baseTextarea({
345
381
  title,
346
382
  message,
347
383
  prompt: {
348
384
  model: sample.join('\n'),
349
- type: 'textarea',
350
- outlined: true,
351
385
  isValid: (s: string) => strToArr(s).every(isValid),
352
386
  },
353
387
  })
@@ -366,41 +400,14 @@ class QDialog {
366
400
  message: string = '',
367
401
  content: string = ''
368
402
  ): Promise<void> {
369
- await this.baseDialog({
370
- title,
371
- message,
372
- prompt: {
373
- model: content,
374
- type: 'textarea',
375
- outlined: true,
376
- },
377
- cancel: false,
378
- })
379
- }
380
-
381
- /**
382
- * Show a dialog with big text area display.
383
- * @param title - the title
384
- * @param message - the message
385
- * @param content - content string in the text area
386
- */
387
- async showBigTextarea(
388
- title: string,
389
- message: string = '',
390
- content: string = ''
391
- ): Promise<void> {
392
- await this.baseDialog({
403
+ await this.baseTextarea({
393
404
  title,
394
405
  message,
395
406
  prompt: {
396
407
  model: content,
397
- type: 'textarea',
398
- outlined: true,
399
- //@ts-ignore // This is a bug from quasar
400
- rows: 25,
401
408
  },
402
409
  cancel: false,
403
- fullWidth: true,
410
+ fullWidth: content.length > 200,
404
411
  })
405
412
  }
406
413
 
@@ -419,46 +426,17 @@ class QDialog {
419
426
  let filteredContent: Partial<T>[] = [...content]
420
427
  if (fields.length > 0)
421
428
  filteredContent = content.map($ => extractObj($, fields))
422
- await this.baseDialog({
423
- title,
424
- message,
425
- prompt: {
426
- model: unparseCSV(filteredContent),
427
- type: 'textarea',
428
- outlined: true,
429
- },
430
- cancel: false,
431
- })
432
- }
433
-
434
- /**
435
- * Show a dialog with big CSV display.
436
- * @param title - the title
437
- * @param message - the message
438
- * @param content - objects to display as CSV
439
- */
440
- async showBigCSV<T extends object>(
441
- title: string,
442
- message: string = '',
443
- content: T[] = [],
444
- fields: strKeyOf<T>[] = []
445
- ): Promise<void> {
446
- let filteredContent: Partial<T>[] = [...content]
447
- if (fields.length > 0)
448
- filteredContent = content.map($ => extractObj($, fields))
449
- await this.baseDialog({
450
- title,
451
- message,
452
- prompt: {
453
- model: unparseCSV(filteredContent),
454
- type: 'textarea',
455
- outlined: true,
456
- //@ts-ignore // This is a bug from quasar
457
- rows: 25,
429
+ await this.baseCSV(
430
+ {
431
+ title,
432
+ message,
433
+ prompt: {
434
+ model: unparseCSV(filteredContent),
435
+ },
436
+ cancel: false,
458
437
  },
459
- cancel: false,
460
- fullWidth: true,
461
- })
438
+ filteredContent
439
+ )
462
440
  }
463
441
 
464
442
  /**
@@ -472,13 +450,11 @@ class QDialog {
472
450
  message: string = '',
473
451
  content: T[] = []
474
452
  ): Promise<void> {
475
- await this.baseDialog({
453
+ await this.baseTextarea({
476
454
  title,
477
455
  message,
478
456
  prompt: {
479
457
  model: content.map($ => String($)).join('\n'),
480
- type: 'textarea',
481
- outlined: true,
482
458
  },
483
459
  cancel: false,
484
460
  })