@quazardous/qdadm 2.42.0 → 2.43.0

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": "@quazardous/qdadm",
3
- "version": "2.42.0",
3
+ "version": "2.43.0",
4
4
  "description": "Vue 3 framework for admin dashboards with PrimeVue",
5
5
  "author": "quazardous",
6
6
  "license": "MIT",
@@ -77,7 +77,7 @@
77
77
  "vue": "^3.3.0",
78
78
  "vue-router": "^4.0.0 || ^5.0.0",
79
79
  "postal-mime": ">=3.0.0",
80
- "@quazardous/vanilla-yamleditor": "^0.1.0"
80
+ "@quazardous/vanilla-yamleditor": "^0.4.0"
81
81
  },
82
82
  "peerDependenciesMeta": {
83
83
  "vanilla-jsoneditor": {
@@ -112,7 +112,7 @@
112
112
  "devDependencies": {
113
113
  "@eslint/js": "^9.39.2",
114
114
  "@primeuix/themes": "^1.0.0",
115
- "@quazardous/vanilla-yamleditor": "https://github.com/quazardous/vanilla-yamleditor/releases/download/v0.1.0/quazardous-vanilla-yamleditor-0.1.0.tgz",
115
+ "@quazardous/vanilla-yamleditor": "https://github.com/quazardous/vanilla-yamleditor/releases/download/v0.4.0/quazardous-vanilla-yamleditor-0.4.0.tgz",
116
116
  "@types/node": "^25.0.6",
117
117
  "@vitejs/plugin-vue": "^6.0.0",
118
118
  "@vue/test-utils": "^2.4.6",
@@ -15,7 +15,7 @@
15
15
  import { computed, ref, watch } from 'vue'
16
16
  import QdButton from '../base/QdButton.vue'
17
17
  import { useI18n } from '../../i18n/useI18n'
18
- import { formatBytes } from '../../utils/formatters'
18
+ import { useFormatBytes } from '../../composables/useFormatBytes'
19
19
  import {
20
20
  attachmentSize,
21
21
  attachmentUrl,
@@ -50,6 +50,7 @@ const props = withDefaults(defineProps<Props>(), {
50
50
  })
51
51
 
52
52
  const { t, locale } = useI18n()
53
+ const formatBytes = useFormatBytes()
53
54
 
54
55
  // --- The email ---
55
56
 
@@ -34,7 +34,7 @@ import {
34
34
  type PayloadFormat,
35
35
  type PayloadMask,
36
36
  } from '../../utils/payload'
37
- import { formatBytes } from '../../utils/formatters'
37
+ import { useFormatBytes } from '../../composables/useFormatBytes'
38
38
 
39
39
  export interface PayloadRequest {
40
40
  method?: string
@@ -70,6 +70,7 @@ const props = withDefaults(defineProps<Props>(), {
70
70
  })
71
71
 
72
72
  const { t } = useI18n()
73
+ const formatBytes = useFormatBytes()
73
74
  const orchestrator = inject<{ toast: { success: (...a: unknown[]) => void; error: (...a: unknown[]) => void } } | null>('qdadmOrchestrator', null)
74
75
 
75
76
  const contentTypeHeader = computed(() => {
@@ -1,10 +1,11 @@
1
1
  <script setup lang="ts">
2
2
  /**
3
- * VanillaYamlEditor - a YAML text with a text view and a form view (#4303)
3
+ * VanillaYamlEditor - a YAML text with text, tree and form views (#4303)
4
4
  *
5
5
  * Wraps @quazardous/vanilla-yamleditor (an optional peer): CodeMirror text,
6
- * and a form generated from a JSON Schema whose edits keep the file's
7
- * comments and formatting. v-model is the YAML text.
6
+ * a technical tree, and a form generated from a JSON Schema, whose edits keep
7
+ * the file's comments and formatting. v-model is the YAML text. The default
8
+ * view is the lib's: form with a schema, tree without.
8
9
  *
9
10
  * <VanillaYamlEditor v-model="yaml" :schema="schema" :problems="serverProblems" />
10
11
  *
@@ -31,6 +32,8 @@ interface Props {
31
32
  validator?: (value: unknown, parsed: ParsedYaml) => YamlProblemInput[]
32
33
  /** Problems found elsewhere (a server check), shown on their line and field. */
33
34
  problems?: YamlProblemInput[]
35
+ /** Warn on valid YAML that is likely a typo (`key ::`). */
36
+ lint?: boolean
34
37
  readOnly?: boolean
35
38
  mainMenuBar?: boolean
36
39
  height?: string
@@ -42,6 +45,7 @@ const props = withDefaults(defineProps<Props>(), {
42
45
  schema: undefined,
43
46
  validator: undefined,
44
47
  problems: () => [],
48
+ lint: true,
45
49
  readOnly: false,
46
50
  mainMenuBar: true,
47
51
  height: '400px',
@@ -64,10 +68,14 @@ function labels() {
64
68
  const n = (key: string, one: string, many: string) => (count: number) => tOr(`core.yamlEditor.${key}`, `${one} | ${many}`, { count })
65
69
  return {
66
70
  text: tOr('core.yamlEditor.text', 'Text'),
67
- tree: tOr('core.yamlEditor.tree', 'Form'),
71
+ tree: tOr('core.yamlEditor.tree', 'Tree'),
72
+ form: tOr('core.yamlEditor.form', 'Form'),
68
73
  modes: tOr('core.yamlEditor.modes', 'View'),
69
- syntaxBlocked: tOr('core.yamlEditor.syntaxBlocked', 'Fix the syntax errors before switching to the form'),
74
+ syntaxBlocked: tOr('core.yamlEditor.syntaxBlocked', 'Fix the syntax errors before switching to the tree or the form'),
70
75
  syntaxErrors: n('syntaxErrors', '{count} syntax error', '{count} syntax errors'),
76
+ warnings: n('warnings', '{count} warning', '{count} warnings'),
77
+ colonKey: (key: string, suggestion: string) => tOr('core.yamlEditor.colonKey', 'The key is "{key}": did you mean "{suggestion}:"?', { key, suggestion }),
78
+ spacedKey: (key: string) => tOr('core.yamlEditor.spacedKey', 'The key "{key}" starts or ends with a space', { key }),
71
79
  addItem: tOr('core.yamlEditor.addItem', 'Add item'),
72
80
  addKey: tOr('core.yamlEditor.addKey', 'Add'),
73
81
  newKey: tOr('core.yamlEditor.newKey', 'new key'),
@@ -92,6 +100,7 @@ onMounted(() => {
92
100
  schema: props.schema,
93
101
  validator: props.validator,
94
102
  problems: props.problems,
103
+ lint: props.lint,
95
104
  readOnly: props.readOnly,
96
105
  mainMenuBar: props.mainMenuBar,
97
106
  labels: labels(),
@@ -116,9 +125,9 @@ watch(
116
125
  }
117
126
  )
118
127
  watch(
119
- () => [props.schema, props.validator, props.problems, props.readOnly, props.mainMenuBar] as const,
128
+ () => [props.schema, props.validator, props.problems, props.lint, props.readOnly, props.mainMenuBar] as const,
120
129
  () => {
121
- editor?.updateProps({ schema: props.schema, validator: props.validator, problems: props.problems, readOnly: props.readOnly, mainMenuBar: props.mainMenuBar })
130
+ editor?.updateProps({ schema: props.schema, validator: props.validator, problems: props.problems, lint: props.lint, readOnly: props.readOnly, mainMenuBar: props.mainMenuBar })
122
131
  if (editor) emit('status', editor.status())
123
132
  }
124
133
  )
@@ -14,7 +14,7 @@
14
14
  */
15
15
  import { computed, onMounted, onUnmounted, ref, shallowRef } from 'vue'
16
16
  import Textarea from 'primevue/textarea'
17
- import { validate, type YamlEditorStatus, type YamlProblem } from '@quazardous/vanilla-yamleditor'
17
+ import { validate, type YamlEditorMode, type YamlEditorStatus, type YamlProblem } from '@quazardous/vanilla-yamleditor'
18
18
  import QdButton from '../../base/QdButton.vue'
19
19
  import QdMessage from '../../base/QdMessage.vue'
20
20
  import SimpleDialog from '../../dialogs/SimpleDialog.vue'
@@ -29,6 +29,10 @@ interface Props {
29
29
  adapter: YamlConfigAdapter
30
30
  /** Read only, whatever the server says. */
31
31
  readOnly?: boolean
32
+ /** Force a view; default: form with a schema, tree without. */
33
+ mode?: YamlEditorMode
34
+ /** Warn on valid YAML that is likely a typo (`key ::`); never blocks a save. */
35
+ lint?: boolean
32
36
  height?: string
33
37
  /** Ask before leaving the page with unsaved changes. */
34
38
  guard?: boolean
@@ -36,6 +40,8 @@ interface Props {
36
40
 
37
41
  const props = withDefaults(defineProps<Props>(), {
38
42
  readOnly: false,
43
+ mode: undefined,
44
+ lint: true,
39
45
  height: '28rem',
40
46
  guard: true,
41
47
  })
@@ -290,6 +296,8 @@ defineExpose({ reload: load, check: runCheck, save: startSave, dirty })
290
296
  v-model="text"
291
297
  :schema="original.schema"
292
298
  :problems="serverProblems"
299
+ :mode="mode"
300
+ :lint="lint"
293
301
  :read-only="readOnly"
294
302
  :height="height"
295
303
  @status="onStatus"
@@ -23,12 +23,14 @@
23
23
  * - url: clickable link
24
24
  * - json: formatted JSON
25
25
  * - currency: formatted currency
26
+ * - bytes: a file size ("1,4 Mo"), in the app's language
26
27
  * - badge: styled tag
27
28
  */
28
29
  import { computed, type PropType } from 'vue'
29
30
  import { RouterLink, type RouteLocationRaw } from 'vue-router'
30
31
  import Tag from 'primevue/tag'
31
- import { formatDate, formatNumber, formatCurrency, getEmptyPlaceholder } from '../../utils/formatters'
32
+ import { formatDate, formatNumber, formatCurrency, formatBytes, getEmptyPlaceholder } from '../../utils/formatters'
33
+ import { useFormatBytes } from '../../composables/useFormatBytes'
32
34
 
33
35
  type DisplayType =
34
36
  | 'text'
@@ -45,6 +47,7 @@ type DisplayType =
45
47
  | 'url'
46
48
  | 'json'
47
49
  | 'currency'
50
+ | 'bytes'
48
51
  | 'badge'
49
52
 
50
53
  type DisplayValue = string | number | boolean | Date | null | undefined | unknown
@@ -128,6 +131,15 @@ const currencyValue = computed(() => {
128
131
  return formatCurrency(num, props.field.currencyCode || 'USD', props.field.locale)
129
132
  })
130
133
 
134
+ // Format a size in bytes: the app's language and catalogue units, or the field's locale
135
+ const appBytes = useFormatBytes()
136
+ const bytesValue = computed(() => {
137
+ if (isEmpty.value) return emptyText.value
138
+ const num = Number(props.value)
139
+ if (isNaN(num)) return String(props.value)
140
+ return props.field.locale ? formatBytes(num, props.field.locale) : appBytes(num)
141
+ })
142
+
131
143
  // Format boolean value
132
144
  const booleanValue = computed(() => {
133
145
  if (isEmpty.value) return emptyText.value
@@ -268,6 +280,11 @@ const imageStyle = computed(() => ({
268
280
  {{ currencyValue }}
269
281
  </span>
270
282
 
283
+ <!-- Size in bytes -->
284
+ <span v-else-if="displayType === 'bytes'" class="show-display show-display--bytes">
285
+ {{ bytesValue }}
286
+ </span>
287
+
271
288
  <!-- Boolean (icon) -->
272
289
  <span v-else-if="displayType === 'boolean'" class="show-display show-display--boolean" :class="booleanIconClass">
273
290
  <i :class="['pi', booleanIcon]"></i>
@@ -245,7 +245,7 @@ onBeforeUnmount(() => {
245
245
  </slot>
246
246
  </div>
247
247
  <LogStream v-if="logSource" :key="run.id" class="qd-task-log" :source="logSource" :filename="logFilename" height="16rem"
248
- error-pattern="error|fatal|failed" @done="store.poke(run.id)" />
248
+ :error-pattern="ui.logPatterns.errorPattern" :timestamp-pattern="ui.logPatterns.timestampPattern" @done="store.poke(run.id)" />
249
249
  <div v-if="has('after-log')" class="qd-task-after-log">
250
250
  <slot name="after-log" v-bind="slotProps">
251
251
  <component :is="slotComponent('after-log')!" v-bind="slotProps" />
@@ -91,6 +91,8 @@ export const SHOW_TYPE_MAPPINGS: Record<string, string> = {
91
91
  float: 'number',
92
92
  decimal: 'number',
93
93
  currency: 'currency',
94
+ bytes: 'bytes',
95
+ filesize: 'bytes',
94
96
  boolean: 'boolean',
95
97
  bool: 'boolean',
96
98
  date: 'date',
@@ -48,6 +48,7 @@ export {
48
48
  type BulkStatusActionReturn,
49
49
  } from './useListPage'
50
50
  export { usePageTitle, type UsePageTitleReturn, type TitleParts, type TitleInput } from './usePageTitle'
51
+ export { useFormatBytes } from './useFormatBytes'
51
52
  export { useApp, type UseAppReturn } from './useApp'
52
53
  export { useAuth, type UseAuthReturn } from './useAuth'
53
54
  export { useUserBox, resolveUserAvatar, isExternalUserLink, type UseUserBoxReturn, type UserAvatarResolver, type UserBoxUser } from './useUserBox'
@@ -0,0 +1,20 @@
1
+ /**
2
+ * useFormatBytes (#4384): formatBytes in the app's language, with the unit
3
+ * labels of the catalogue (core.units.bytes.*), so an app can rename them.
4
+ *
5
+ * const formatBytes = useFormatBytes()
6
+ * formatBytes(1468006) // "1,4 Mo" in French
7
+ */
8
+ import { useI18n } from '../i18n/useI18n'
9
+ import { byteUnits, formatBytes } from '../utils/formatters'
10
+
11
+ const KEYS = ['b', 'kb', 'mb', 'gb', 'tb']
12
+
13
+ export function useFormatBytes(): (bytes: number | null | undefined) => string {
14
+ const { tOr, locale } = useI18n()
15
+ return (bytes) => {
16
+ const fallback = byteUnits(locale.value)
17
+ const units = KEYS.map((key, i) => tOr(`core.units.bytes.${key}`, fallback[i]!))
18
+ return formatBytes(bytes, locale.value, units)
19
+ }
20
+ }
@@ -262,13 +262,25 @@ export default `core:
262
262
  next: Next message
263
263
  position: "{index} of {count}"
264
264
  close: Close this message
265
+ # formatBytes in qdadm's own components (#4384)
266
+ units:
267
+ bytes:
268
+ b: B
269
+ kb: KB
270
+ mb: MB
271
+ gb: GB
272
+ tb: TB
265
273
  # VanillaYamlEditor and YamlConfigEditor (#4303)
266
274
  yamlEditor:
267
275
  text: Text
268
- tree: Form
276
+ tree: Tree
277
+ form: Form
269
278
  modes: View
270
- syntaxBlocked: Fix the syntax errors before switching to the form
279
+ syntaxBlocked: "Fix the syntax errors before switching to the tree or the form"
271
280
  syntaxErrors: "{count} syntax error | {count} syntax errors"
281
+ warnings: "{count} warning | {count} warnings"
282
+ colonKey: 'The key is "{key}": did you mean "{suggestion}:"?'
283
+ spacedKey: 'The key "{key}" starts or ends with a space'
272
284
  addItem: Add item
273
285
  addKey: Add
274
286
  newKey: new key
@@ -260,13 +260,25 @@ core:
260
260
  next: Next message
261
261
  position: "{index} of {count}"
262
262
  close: Close this message
263
+ # formatBytes in qdadm's own components (#4384)
264
+ units:
265
+ bytes:
266
+ b: B
267
+ kb: KB
268
+ mb: MB
269
+ gb: GB
270
+ tb: TB
263
271
  # VanillaYamlEditor and YamlConfigEditor (#4303)
264
272
  yamlEditor:
265
273
  text: Text
266
- tree: Form
274
+ tree: Tree
275
+ form: Form
267
276
  modes: View
268
- syntaxBlocked: Fix the syntax errors before switching to the form
277
+ syntaxBlocked: "Fix the syntax errors before switching to the tree or the form"
269
278
  syntaxErrors: "{count} syntax error | {count} syntax errors"
279
+ warnings: "{count} warning | {count} warnings"
280
+ colonKey: 'The key is "{key}": did you mean "{suggestion}:"?'
281
+ spacedKey: 'The key "{key}" starts or ends with a space'
270
282
  addItem: Add item
271
283
  addKey: Add
272
284
  newKey: new key
@@ -262,13 +262,25 @@ export default `core:
262
262
  next: Message suivant
263
263
  position: "{index} sur {count}"
264
264
  close: Fermer ce message
265
+ # formatBytes in qdadm's own components (#4384)
266
+ units:
267
+ bytes:
268
+ b: o
269
+ kb: ko
270
+ mb: Mo
271
+ gb: Go
272
+ tb: To
265
273
  # VanillaYamlEditor and YamlConfigEditor (#4303)
266
274
  yamlEditor:
267
275
  text: Texte
268
- tree: Formulaire
276
+ tree: Arbre
277
+ form: Formulaire
269
278
  modes: Vue
270
- syntaxBlocked: Corrigez les erreurs de syntaxe avant de passer au formulaire
279
+ syntaxBlocked: "Corrigez les erreurs de syntaxe avant de passer à l'arbre ou au formulaire"
271
280
  syntaxErrors: "{count} erreur de syntaxe | {count} erreurs de syntaxe"
281
+ warnings: "{count} avertissement | {count} avertissements"
282
+ colonKey: 'La clé est « {key} » : vouliez-vous dire « {suggestion}: » ?'
283
+ spacedKey: 'La clé « {key} » commence ou finit par une espace'
272
284
  addItem: Ajouter un élément
273
285
  addKey: Ajouter
274
286
  newKey: nouvelle clé
@@ -260,13 +260,25 @@ core:
260
260
  next: Message suivant
261
261
  position: "{index} sur {count}"
262
262
  close: Fermer ce message
263
+ # formatBytes in qdadm's own components (#4384)
264
+ units:
265
+ bytes:
266
+ b: o
267
+ kb: ko
268
+ mb: Mo
269
+ gb: Go
270
+ tb: To
263
271
  # VanillaYamlEditor and YamlConfigEditor (#4303)
264
272
  yamlEditor:
265
273
  text: Texte
266
- tree: Formulaire
274
+ tree: Arbre
275
+ form: Formulaire
267
276
  modes: Vue
268
- syntaxBlocked: Corrigez les erreurs de syntaxe avant de passer au formulaire
277
+ syntaxBlocked: "Corrigez les erreurs de syntaxe avant de passer à l'arbre ou au formulaire"
269
278
  syntaxErrors: "{count} erreur de syntaxe | {count} erreurs de syntaxe"
279
+ warnings: "{count} avertissement | {count} avertissements"
280
+ colonKey: 'La clé est « {key} » : vouliez-vous dire « {suggestion}: » ?'
281
+ spacedKey: 'La clé « {key} » commence ou finit par une espace'
270
282
  addItem: Ajouter un élément
271
283
  addKey: Ajouter
272
284
  newKey: nouvelle clé
package/src/index.ts CHANGED
@@ -261,6 +261,7 @@ export {
261
261
  type TitleParts,
262
262
  type TitleInput,
263
263
  } from './composables/usePageTitle'
264
+ export { useFormatBytes } from './composables/useFormatBytes'
264
265
  export { useApp, type UseAppReturn } from './composables/useApp'
265
266
  export { useAuth, type UseAuthReturn } from './composables/useAuth'
266
267
  export { useUserBox, resolveUserAvatar, isExternalUserLink, type UseUserBoxReturn, type UserAvatarResolver, type UserBoxUser } from './composables/useUserBox'
@@ -457,6 +458,8 @@ export {
457
458
  getTaskUi,
458
459
  resolveTaskUi,
459
460
  TASK_DIALOG_DEFAULTS,
461
+ TASK_LOG_DEFAULTS,
462
+ type TaskLogPatterns,
460
463
  type TaskDialogOptions,
461
464
  type TaskDialogSlotName,
462
465
  type TaskUiOptions,
@@ -12,7 +12,7 @@
12
12
  * they live in. Runs of a registered kind survive a reload (sessionStorage).
13
13
  */
14
14
 
15
- import type { TaskDialogOptions, TaskUiOptions } from './taskUi'
15
+ import type { TaskDialogOptions, TaskLogPatterns, TaskUiOptions } from './taskUi'
16
16
  import { reactive, computed, type ComputedRef } from 'vue'
17
17
  import type { LogSource } from '../composables/useLogStream'
18
18
 
@@ -58,6 +58,8 @@ export interface TaskKind {
58
58
  onSettled?: (run: TaskRun) => void
59
59
  /** The follow dialog's window options for this kind, over the app's (#4334). */
60
60
  dialog?: TaskDialogOptions
61
+ /** What the log flags as an error or a timestamp for this kind, over the app's (#4386). */
62
+ logPatterns?: TaskLogPatterns
61
63
  /** Slot components for this kind's dialog, over the app's. */
62
64
  slots?: TaskUiOptions['slots']
63
65
  /** A dialog of its own for this kind, instead of TaskDialog. */
@@ -1,11 +1,13 @@
1
1
  /**
2
2
  * How the TaskRunner looks (#4334): the follow dialog's window options, slot
3
- * components, a replacement dialog, and the tray's row. Layered: qdadm's
3
+ * components, a replacement dialog, the tray's row, and what its log flags as
4
+ * an error or a timestamp (#4386). Layered: qdadm's
4
5
  * defaults, then the app's (configureTasks), then the task kind's
5
6
  * (registerTaskKind / run options), then a page's own TaskDialog props.
6
7
  *
7
8
  * configureTasks({ dialog: { width: '56rem', modal: false }, slots: { 'after-log': DeliverySummary } })
8
9
  * registerTaskKind('deploy', { task, log, dialog: { maximizable: false }, component: DeployDialog })
10
+ * registerTaskKind('deliver', { task, log, logPatterns: { errorPattern: /\[error\]|^→ failed/ } })
9
11
  */
10
12
  import { shallowReactive, type Component } from 'vue'
11
13
 
@@ -29,8 +31,17 @@ export interface TaskDialogOptions {
29
31
  /** The TaskDialog slots an app fills with components; each gets `{ run, kind, final }`. */
30
32
  export type TaskDialogSlotName = 'header' | 'before-log' | 'after-log' | 'actions' | 'result'
31
33
 
34
+ /** The follow dialog's log (LogStream): a string is a case-insensitive pattern; null turns it off. */
35
+ export interface TaskLogPatterns {
36
+ /** The lines flagged as errors, and counted by the "N errors" button */
37
+ errorPattern?: RegExp | string | null
38
+ /** The timestamp at the start of a line, shown dimmed */
39
+ timestampPattern?: RegExp | string | null
40
+ }
41
+
32
42
  export interface TaskUiOptions {
33
43
  dialog?: TaskDialogOptions
44
+ logPatterns?: TaskLogPatterns
34
45
  slots?: Partial<Record<TaskDialogSlotName, Component>>
35
46
  /**
36
47
  * Renders instead of TaskDialog, with props `{ runId, options }` and a
@@ -54,12 +65,19 @@ export const TASK_DIALOG_DEFAULTS: Required<Omit<TaskDialogOptions, 'position' |
54
65
  class: undefined,
55
66
  }
56
67
 
68
+ // Whole words only, so a file name such as shipping_error.php is not an error
69
+ export const TASK_LOG_DEFAULTS: Required<TaskLogPatterns> = {
70
+ errorPattern: /\b(error|fatal|failed)\b/i,
71
+ timestampPattern: null,
72
+ }
73
+
57
74
  const app = shallowReactive<TaskUiOptions>({})
58
75
 
59
76
  /** The app's TaskRunner look, once at boot. Later calls merge over earlier ones. */
60
77
  export function configureTasks(options: TaskUiOptions): void {
61
78
  if (options.dialog) app.dialog = { ...app.dialog, ...options.dialog }
62
79
  if (options.slots) app.slots = { ...app.slots, ...options.slots }
80
+ if (options.logPatterns) app.logPatterns = { ...app.logPatterns, ...options.logPatterns }
63
81
  if (options.component !== undefined) app.component = options.component
64
82
  if (options.tray) app.tray = { ...app.tray, ...options.tray }
65
83
  }
@@ -68,6 +86,7 @@ export function configureTasks(options: TaskUiOptions): void {
68
86
  export function resetTaskUi(): void {
69
87
  delete app.dialog
70
88
  delete app.slots
89
+ delete app.logPatterns
71
90
  delete app.component
72
91
  delete app.tray
73
92
  }
@@ -79,10 +98,11 @@ export function getTaskUi(): Readonly<TaskUiOptions> {
79
98
 
80
99
  /** One run's look: defaults, then the app's, then the kind's, then a page's props. */
81
100
  export function resolveTaskUi(kind?: TaskUiOptions | null, page?: TaskDialogOptions | null) {
82
- const strip = (o?: TaskDialogOptions | null) =>
83
- Object.fromEntries(Object.entries(o ?? {}).filter(([, v]) => v !== undefined)) as TaskDialogOptions
101
+ const strip = <T extends object>(o?: T | null) => Object.fromEntries(Object.entries(o ?? {}).filter(([, v]) => v !== undefined)) as T
84
102
  return {
85
103
  dialog: { ...TASK_DIALOG_DEFAULTS, ...strip(app.dialog), ...strip(kind?.dialog), ...strip(page) },
104
+ // null is kept: it turns a pattern off
105
+ logPatterns: { ...TASK_LOG_DEFAULTS, ...strip(app.logPatterns), ...strip(kind?.logPatterns) } as Required<TaskLogPatterns>,
86
106
  slots: { ...app.slots, ...kind?.slots } as Partial<Record<TaskDialogSlotName, Component>>,
87
107
  component: kind?.component ?? app.component ?? null,
88
108
  }
@@ -201,18 +201,37 @@ export function formatCurrency(
201
201
  return new Intl.NumberFormat(locale, { style: 'currency', currency: currencyCode }).format(value)
202
202
  }
203
203
 
204
+ /** Size units by language (octets in French); any other language gets the English ones. */
205
+ const BYTE_UNITS: Record<string, string[]> = {
206
+ en: ['B', 'KB', 'MB', 'GB', 'TB'],
207
+ fr: ['o', 'ko', 'Mo', 'Go', 'To'],
208
+ }
209
+
204
210
  /**
205
- * Format bytes to human-readable size
211
+ * The size units of a locale: B, KB, MB, GB, TB, or o, ko, Mo, Go, To in French
212
+ *
213
+ * @param locale - Explicit locale override (default: browser locale)
206
214
  */
207
- export function formatBytes(bytes: number | null | undefined): string {
208
- if (bytes === null || bytes === undefined) return emptyPlaceholder
209
- if (bytes === 0) return '0 B'
215
+ export function byteUnits(locale?: string): string[] {
216
+ const lang = new Intl.NumberFormat(locale).resolvedOptions().locale.split('-')[0] ?? 'en'
217
+ return BYTE_UNITS[lang] ?? BYTE_UNITS.en!
218
+ }
210
219
 
211
- const units = ['B', 'KB', 'MB', 'GB', 'TB']
220
+ /**
221
+ * Format bytes to human-readable size, base 1024 ("1 Mo", "1,4 Mo", "512 o")
222
+ *
223
+ * @param locale - Explicit locale override (default: browser locale)
224
+ * @param units - The five unit labels, B to TB (default: the locale's, see byteUnits)
225
+ */
226
+ export function formatBytes(bytes: number | null | undefined, locale?: string, units?: string[]): string {
227
+ if (bytes === null || bytes === undefined) return emptyPlaceholder
228
+ const labels = units ?? byteUnits(locale)
212
229
  const k = 1024
213
- const i = Math.floor(Math.log(bytes) / Math.log(k))
214
-
215
- return `${(bytes / Math.pow(k, i)).toFixed(1)} ${units[i]}`
230
+ let i = bytes === 0 ? 0 : Math.min(Math.max(Math.floor(Math.log(Math.abs(bytes)) / Math.log(k)), 0), labels.length - 1)
231
+ // 1023.96 KB shows as 1 MB, not 1 024 KB
232
+ if (i < labels.length - 1 && Math.round((Math.abs(bytes) / Math.pow(k, i)) * 10) / 10 >= k) i++
233
+ const value = new Intl.NumberFormat(locale, { maximumFractionDigits: i === 0 ? 0 : 1 }).format(bytes / Math.pow(k, i))
234
+ return `${value} ${labels[i]}`
216
235
  }
217
236
 
218
237
  /**
@@ -15,6 +15,7 @@ export {
15
15
  formatNumber,
16
16
  formatCurrency,
17
17
  formatBytes,
18
+ byteUnits,
18
19
  formatPercent,
19
20
  setEmptyPlaceholder,
20
21
  getEmptyPlaceholder,