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