inertia-bootstrap-forms 4.0.0 → 4.0.2

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/dist/style.css ADDED
@@ -0,0 +1 @@
1
+ .voice-recorder-box{display:block;background-color:var(--bg-1);border-radius:var(--border-radius);border:2px dashed var(--border-color)}.voice-recorder-box audio{vertical-align:middle}
package/index.d.ts CHANGED
@@ -87,6 +87,12 @@ export declare const VoiceRecorderInput: FieldComponent<{
87
87
  locale?: Locale | null;
88
88
  }>;
89
89
 
90
+ export declare const VoiceRecorderResultArea: DefineComponent<{
91
+ for: string; showList?: boolean; showProblem?: boolean;
92
+ listClass?: string | string[] | Record<string, boolean>;
93
+ alertClass?: string | string[] | Record<string, boolean>; internal?: boolean;
94
+ }>;
95
+
90
96
  export declare const ComboboxInput: FieldComponent<{
91
97
  options?: OptionItem[];
92
98
  valueKey?: string | null;
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "inertia-bootstrap-forms",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "description": "Bootstrap 6 form components for Vue 3 + Inertia.js (Laravel). Every field is bound to a single FormContainer v-model.",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
8
8
  "types": "./index.d.ts",
9
- "sideEffects": false,
9
+ "sideEffects": ["**/*.css"],
10
10
  "scripts": {
11
11
  "dev": "vite build --watch",
12
12
  "build": "vite build",
@@ -66,6 +66,7 @@
66
66
  "import": "./dist/country-codes.js",
67
67
  "require": "./dist/country-codes.cjs"
68
68
  },
69
+ "./style.css": "./dist/style.css",
69
70
  "./src/*": "./src/*",
70
71
  "./package.json": "./package.json"
71
72
  },
@@ -67,7 +67,7 @@ export default defineComponent({
67
67
  * Multiple select only: show the chosen options themselves (true) instead of the
68
68
  * "N selected" counter (false, default).
69
69
  */
70
- showSelected: { type: Boolean, default: false },
70
+ showSelected: { type: Boolean, default: true },
71
71
  /** With `showSelected`: above this many chosen options the counter is shown instead. */
72
72
  maxVisible: { type: Number, default: null },
73
73
  /** Separator between the chosen labels (default: "، " for fa, ", " otherwise). */
@@ -2,8 +2,10 @@
2
2
  import {computed, defineComponent, onMounted, reactive, ref, watch} from 'vue';
3
3
  import {fieldProps, useField} from './composables/useField.js';
4
4
  import {useDisposables} from './composables/useDisposables.js';
5
+ import {formatTime, registerVoiceChannel, unregisterVoiceChannel, voiceAreaCounts} from './composables/useVoiceChannel.js';
5
6
  import {useI18n} from './i18n.js';
6
7
  import {laravelHeaders} from './utils/http.js';
8
+ import VoiceRecorderResultArea from './VoiceRecorderResultArea.vue';
7
9
 
8
10
  const MESSAGES = {
9
11
  en: {
@@ -29,7 +31,7 @@ const MESSAGES = {
29
31
  fa: {
30
32
  start: 'ضبط صدا',
31
33
  stop: 'پایان ضبط',
32
- idle: 'برای ضبط صدا اینجا کلیک کنید',
34
+ idle: 'برای ضبط روی میکروفن بزنید',
33
35
  starting: 'در انتظار اجازه دسترسی به میکروفن…',
34
36
  recording: 'در حال ضبط…',
35
37
  uploading: 'در حال ارسال…',
@@ -90,21 +92,24 @@ function classify(error) {
90
92
  }
91
93
  }
92
94
 
93
- const pad = (n) => String(Math.floor(n)).padStart(2, '0');
94
- const formatTime = (s) => `${pad(s / 60)}:${pad(s % 60)}`;
95
-
96
95
  /**
97
96
  * Voice recorder.
98
97
  * - variant="box" a full-width Bootstrap card with the record button, status and timer
99
- * - variant="button" a single button that takes your own classes (`button-class`, `recording-class`)
100
- * Every recording is uploaded to `url` and the result is stored in the form; recordings are listed in a
101
- * Bootstrap list-group with a player. No extra libraries: it uses the browser's MediaRecorder (needs HTTPS).
98
+ * - variant="button" a single button that takes your own classes (`button-class`, `recording-class`, `problem-class`)
99
+ * Every recording is uploaded to `url` and the result is stored in the form. No extra libraries: it uses the
100
+ * browser's MediaRecorder (needs HTTPS).
101
+ *
102
+ * Where the recordings (list-group with players) and the errors are shown:
103
+ * - by default right inside / under the recorder
104
+ * - anywhere you like with <VoiceRecorderResultArea for="<name or channel>" /> (the built-in output hides itself)
105
+ * - inside any element of the page with `result-target="#my-div"`
102
106
  *
103
107
  * Endpoint contract (same as FileInput): POST multipart `file` → JSON { data: { path } } (or { path });
104
108
  * DELETE with the raw `path` as request body.
105
109
  */
106
110
  export default defineComponent({
107
111
  name: 'VoiceRecorderInput',
112
+ components: {VoiceRecorderResultArea},
108
113
  emits: ['update:modelValue', 'change', 'start', 'stop', 'recorded', 'progress', 'uploaded', 'removed', 'error'],
109
114
  props: {
110
115
  ...fieldProps,
@@ -120,16 +125,27 @@ export default defineComponent({
120
125
  /** Bitrate of the recording; 32 kbps opus is plenty for speech and keeps files tiny. */
121
126
  audioBitsPerSecond: {type: Number, default: 32000},
122
127
  audioConstraints: {type: Object, default: () => ({echoCancellation: true, noiseSuppression: true, autoGainControl: true})},
123
- /** Classes of the button in `variant="button"` (idle) … */
124
- buttonClass: {type: [String, Array, Object], default: 'btn-solid theme-primary'},
128
+ /** Classes of the button (idle) … */
129
+ buttonClass: {type: [String, Array, Object], default: 'btn-solid theme-inverse'},
130
+ /** … while there is a problem to show … */
125
131
  problemClass: {type: [String, Array, Object], default: 'btn-solid theme-danger'},
126
132
  /** … and while recording. */
127
133
  recordingClass: {type: [String, Array, Object], default: 'btn-solid theme-danger'},
134
+ /** Show the list of recordings (in the built-in output, in `result-target` and in the result areas). */
128
135
  showList: {type: Boolean, default: true},
129
136
  /** Ask the server to delete the file (DELETE {url}) when a recording is removed. */
130
137
  deleteOnRemove: {type: Boolean, default: true},
131
138
  /** (storedValue) => playable URL — used for recordings that come from the form data (edit pages). */
132
139
  playbackUrl: {type: Function, default: (value) => value},
140
+ /**
141
+ * Key that <VoiceRecorderResultArea for="…"> uses to find this recorder. Defaults to `name`.
142
+ * Set it when two recorders share the same name or have no name.
143
+ */
144
+ channel: {type: String, default: null},
145
+ /** CSS selector (or element) the list and errors are moved into, e.g. "#voice-results". It must exist in the page. */
146
+ resultTarget: {type: [String, Object], default: null},
147
+ /** Force the built-in output on / off. null = automatic: hidden while a <VoiceRecorderResultArea> is attached. */
148
+ inlineResults: {type: Boolean, default: null},
133
149
  startText: {type: String, default: null},
134
150
  stopText: {type: String, default: null},
135
151
  locale: {type: String, default: null},
@@ -141,6 +157,9 @@ export default defineComponent({
141
157
 
142
158
  const t = (key) => (MESSAGES[locale.value] || MESSAGES.en)[key] ?? MESSAGES.en[key] ?? key;
143
159
 
160
+ const uid = `voice-${++counter}`;
161
+ const channelKey = props.channel ?? props.name ?? uid;
162
+
144
163
  const root = ref(null);
145
164
  const items = ref([]);
146
165
  const recording = ref(false);
@@ -148,6 +167,7 @@ export default defineComponent({
148
167
  const seconds = ref(0);
149
168
  const problem = ref(null); // { code, message }
150
169
  const supported = ref(true);
170
+ const mounted = ref(false);
151
171
 
152
172
  const requests = new Map();
153
173
  let recorder = null;
@@ -162,6 +182,13 @@ export default defineComponent({
162
182
  const uploading = computed(() => items.value.some((i) => i.status === 'uploading'));
163
183
  const blocked = computed(() => !supported.value || locked.value);
164
184
 
185
+ // where the results go
186
+ const externalArea = computed(() => (voiceAreaCounts[channelKey] || 0) > 0);
187
+ const showInline = computed(() => !props.resultTarget && (props.inlineResults ?? !externalArea.value));
188
+ const stateClass = computed(() =>
189
+ recording.value ? props.recordingClass : problem.value ? props.problemClass : props.buttonClass
190
+ );
191
+
165
192
  const statusText = computed(() => {
166
193
  if (starting.value) return t('starting');
167
194
  if (recording.value) return t('recording');
@@ -228,6 +255,12 @@ export default defineComponent({
228
255
  }
229
256
 
230
257
  onMounted(() => {
258
+ mounted.value = true;
259
+
260
+ // publish the list / errors so that <VoiceRecorderResultArea for="…"> can show them anywhere
261
+ registerVoiceChannel(channelKey, {owner: uid, items, problem, locked, t, remove, retry: upload});
262
+ d.add(() => unregisterVoiceChannel(channelKey, uid));
263
+
231
264
  supported.value =
232
265
  typeof navigator !== 'undefined' && !!navigator.mediaDevices?.getUserMedia && typeof MediaRecorder !== 'undefined';
233
266
 
@@ -480,13 +513,6 @@ export default defineComponent({
480
513
  if (notify) emit('removed', item);
481
514
  }
482
515
 
483
- // only one player at a time
484
- function onPlay(event) {
485
- root.value?.querySelectorAll('audio').forEach((audio) => {
486
- if (audio !== event.target) audio.pause();
487
- });
488
- }
489
-
490
516
  // ---------- cleanup ----------
491
517
  d.add(() => {
492
518
  discard = true;
@@ -504,7 +530,7 @@ export default defineComponent({
504
530
  if (field.form.value) field.form.value.uploading = null;
505
531
  });
506
532
 
507
- expose({start, stop, toggle});
533
+ expose({start, stop, toggle, channel: channelKey});
508
534
 
509
535
  return {
510
536
  ...field,
@@ -518,12 +544,13 @@ export default defineComponent({
518
544
  problem,
519
545
  supported,
520
546
  blocked,
547
+ mounted,
548
+ channelKey,
549
+ showInline,
550
+ stateClass,
521
551
  statusText,
522
552
  buttonLabel,
523
553
  toggle,
524
- upload,
525
- remove,
526
- onPlay,
527
554
  formatTime,
528
555
  };
529
556
  },
@@ -533,20 +560,25 @@ export default defineComponent({
533
560
  <template>
534
561
  <div ref="root" class="voice-recorder" :id="inputId" :class="{ 'is-invalid': isInvalid }">
535
562
  <!-- variant: box (full-width Bootstrap card) -->
536
- <div v-if="variant === 'box'" class="card w-100">
563
+ <div v-if="variant === 'box'" class="voice-recorder-box p-5">
537
564
  <div class="card-body">
538
565
  <div class="row gx-5">
539
- <div class="col-auto mx-auto" v-if="problem">
540
- <div class="alert theme-danger p-1 text-center mb-4" role="alert" :data-code="problem.code">{{ problem.message }}</div>
566
+ <div class="col-auto mx-auto" v-if="showInline && problem">
567
+ <VoiceRecorderResultArea
568
+ :for="channelKey"
569
+ internal
570
+ :show-list="false"
571
+ alert-class="alert theme-danger p-1 text-center mb-4"
572
+ />
541
573
  </div>
542
574
  <div class="col-12 text-center">
543
- <div class="btn btn-subtle theme-inverse mx-auto" @click="toggle">
575
+ <div class="btn btn-subtle mx-auto p-3" @click="toggle">
544
576
  <div class="row gx-5 align-items-center">
545
577
  <div class="col-auto">
546
578
  <button
547
579
  type="button"
548
580
  class="btn"
549
- :class="recording ? recordingClass : buttonClass"
581
+ :class="stateClass"
550
582
  :disabled="blocked || starting"
551
583
  :aria-label="buttonLabel"
552
584
  :aria-pressed="recording"
@@ -578,80 +610,51 @@ export default defineComponent({
578
610
  </div>
579
611
  </div>
580
612
  </div>
581
- <ul v-if="showList && items.length" class="list-group mt-2">
582
- <li v-for="item in items" :key="item.id" class="list-group-item">
583
- <div class="row gx-3 align-items-center">
584
- <div class="col-12 sm:col-4">
585
- <audio class="align-middle w-100" controls preload="metadata" :src="item.src" @play="onPlay"></audio>
586
- </div>
587
- <div class="col-auto" v-if="item.seconds !== null">
588
- <span class="fg-secondary fanum" dir="ltr">{{ formatTime(item.seconds) }}</span>
589
- </div>
590
- <div class="col">
591
- <div v-if="item.status === 'uploading'" class="progress" role="progressbar" :aria-valuenow="item.percent" aria-valuemin="0" aria-valuemax="100">
592
- <div class="progress-bar" :style="{ width: item.percent + '%' }"></div>
593
- </div>
594
- <div v-if="item.status === 'error'" class="fg-danger" role="alert">{{ item.error }}</div>
595
- </div>
596
- <div class="col-auto" v-if="item.status === 'error'">
597
- <button
598
- type="button"
599
- class="btn-text theme-secondary btn-icon"
600
- :aria-label="t('retry')"
601
- @click="upload(item)"
602
- >
603
- <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
604
- aria-hidden="true">
605
- <path d="M13.5 3v3.5H10"/>
606
- <path d="M3.2 6.5A5.5 5.5 0 0 1 13 6.5M12.8 9.5A5.5 5.5 0 0 1 3 9.5M2.5 13V9.5H6"/>
607
- </svg>
608
- </button>
609
- </div>
610
- <div class="col-auto">
611
- <button
612
- v-if="!locked"
613
- type="button"
614
- class="btn-text theme-danger btn-icon"
615
- :aria-label="t('remove')"
616
- @click="remove(item)"
617
- >
618
- <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
619
- aria-hidden="true">
620
- <path d="M2.5 4.5h11M6 4.5V3a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v1.5M4 4.5l.6 8.1a1 1 0 0 0 1 .9h4.8a1 1 0 0 0 1-.9l.6-8.1"/>
621
- </svg>
622
- </button>
623
- </div>
624
- </div>
625
- </li>
626
- </ul>
613
+ <VoiceRecorderResultArea
614
+ v-if="showInline && showList"
615
+ class="d-block mt-2"
616
+ :for="channelKey"
617
+ internal
618
+ :show-problem="false"
619
+ />
627
620
  </div>
628
621
  </div>
622
+
629
623
  <!-- variant: button (your own classes) -->
630
- <button
631
- v-else
632
- type="button"
633
- :disabled="blocked || starting"
634
- :aria-pressed="recording"
635
- :class="{
636
- [recordingClass]: recording,
637
- [buttonClass]: !problem && !recording,
638
- [problemClass]: problem,
639
- }"
640
- @click="toggle"
641
- >
642
- <slot :recording="recording" :starting="starting" :seconds="seconds" :time="time">
643
- <span v-if="starting" class="spinner-border spinner-sm me-2" role="status" aria-hidden="true"></span>
644
- <svg v-else-if="recording" class="me-2" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
645
- <rect x="3.5" y="3.5" width="9" height="9" rx="1.5"/>
646
- </svg>
647
- <svg v-else class="me-2" width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"
648
- stroke-linejoin="round" aria-hidden="true">
649
- <rect x="5.5" y="1.5" width="5" height="8" rx="2.5"/>
650
- <path d="M3 7.5a5 5 0 0 0 10 0M8 12.5v2"/>
651
- </svg>
652
- {{ buttonLabel }}
653
- <span v-if="recording" class="ms-2 fanum" dir="ltr">{{ time }}</span>
654
- </slot>
655
- </button>
624
+ <template v-else>
625
+ <button type="button" :disabled="blocked || starting" :aria-pressed="recording" :class="stateClass" @click="toggle">
626
+ <slot :recording="recording" :starting="starting" :seconds="seconds" :time="time">
627
+ <span v-if="starting" class="spinner-border spinner-sm me-2" role="status" aria-hidden="true"></span>
628
+ <svg v-else-if="recording" class="me-2" width="16" height="16" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
629
+ <rect x="3.5" y="3.5" width="9" height="9" rx="1.5"/>
630
+ </svg>
631
+ <svg v-else class="me-2" width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"
632
+ stroke-linejoin="round" aria-hidden="true">
633
+ <rect x="5.5" y="1.5" width="5" height="8" rx="2.5"/>
634
+ <path d="M3 7.5a5 5 0 0 0 10 0M8 12.5v2"/>
635
+ </svg>
636
+ {{ buttonLabel }}
637
+ <span v-if="recording" class="ms-2 fanum" dir="ltr">{{ time }}</span>
638
+ </slot>
639
+ </button>
640
+ <VoiceRecorderResultArea v-if="showInline" class="d-block mt-2" :for="channelKey" internal :show-list="showList" />
641
+ </template>
642
+
643
+ <!-- result-target="#some-div": list and errors are rendered inside that element -->
644
+ <Teleport v-if="resultTarget && mounted" :to="resultTarget">
645
+ <VoiceRecorderResultArea :for="channelKey" internal :show-list="showList" />
646
+ </Teleport>
656
647
  </div>
657
648
  </template>
649
+ <style>
650
+ .voice-recorder-box{
651
+ display: block;
652
+ background-color: var(--bg-1);
653
+ border-radius: var(--border-radius);
654
+ border: 2px dashed var(--border-color);
655
+ }
656
+
657
+ .voice-recorder-box audio{
658
+ vertical-align: middle;;
659
+ }
660
+ </style>
@@ -0,0 +1,109 @@
1
+ <script>
2
+ import {computed, defineComponent, onBeforeUnmount, onMounted, ref} from 'vue';
3
+ import {formatTime, retainVoiceArea, voiceChannels} from './composables/useVoiceChannel.js';
4
+
5
+ /**
6
+ * Shows the recordings (Bootstrap list-group with players) and/or the errors of a <VoiceRecorderInput>
7
+ * anywhere on the page:
8
+ *
9
+ * <VoiceRecorderInput name="voice" />
10
+ * ...
11
+ * <VoiceRecorderResultArea for="voice" />
12
+ *
13
+ * `for` is the `channel` (or, when it is not set, the `name`) of the recorder. As soon as an area is attached
14
+ * the recorder stops showing its own results (see its `inline-results` prop).
15
+ */
16
+ export default defineComponent({
17
+ name: 'VoiceRecorderResultArea',
18
+ props: {
19
+ /** channel / name of the recorder to display. */
20
+ for: {type: String, required: true},
21
+ showList: {type: Boolean, default: true},
22
+ showProblem: {type: Boolean, default: true},
23
+ /** Extra classes of the list-group. */
24
+ listClass: {type: [String, Array, Object], default: null},
25
+ /** Classes of the error alert. */
26
+ alertClass: {type: [String, Array, Object], default: 'alert theme-danger mb-2'},
27
+ /** Used by the recorder itself for its built-in output; does not count as an external area. */
28
+ internal: {type: Boolean, default: false},
29
+ },
30
+ setup(props) {
31
+ const root = ref(null);
32
+ const channel = computed(() => voiceChannels[props.for] ?? null);
33
+ let release = null;
34
+
35
+ onMounted(() => {
36
+ if (!props.internal) release = retainVoiceArea(props.for);
37
+ });
38
+ onBeforeUnmount(() => release?.());
39
+
40
+ const t = (key) => channel.value?.t?.(key) ?? key;
41
+
42
+ // only one player at a time
43
+ function onPlay(event) {
44
+ root.value?.querySelectorAll('audio').forEach((audio) => {
45
+ if (audio !== event.target) audio.pause();
46
+ });
47
+ }
48
+
49
+ return {root, channel, t, onPlay, formatTime};
50
+ },
51
+ });
52
+ </script>
53
+
54
+ <template>
55
+ <div
56
+ v-if="channel && ((showProblem && channel.problem) || (showList && channel.items.length))"
57
+ ref="root"
58
+ class="voice-recorder-results"
59
+ >
60
+ <div v-if="showProblem && channel.problem" :class="alertClass" role="alert" :data-code="channel.problem.code">
61
+ {{ channel.problem.message }}
62
+ </div>
63
+
64
+ <ul v-if="showList && channel.items.length" class="list-group" :class="listClass">
65
+ <li v-for="item in channel.items" :key="item.id" class="list-group-item">
66
+ <slot
67
+ name="item"
68
+ :item="item"
69
+ :time="item.seconds !== null ? formatTime(item.seconds) : null"
70
+ :locked="channel.locked"
71
+ :remove="() => channel.remove(item)"
72
+ :retry="() => channel.retry(item)"
73
+ >
74
+ <div class="row gx-3 align-items-center">
75
+ <div class="col-12 sm:col-4">
76
+ <audio class="flex-grow-1 w-100" controls preload="metadata" :src="item.src" @play="onPlay"></audio>
77
+ </div>
78
+ <div class="col-auto" v-if="item.seconds !== null">
79
+ <span class="fg-secondary fanum" dir="ltr">{{ formatTime(item.seconds) }}</span>
80
+ </div>
81
+ <div class="col">
82
+ <div v-if="item.status === 'uploading'" class="progress" role="progressbar" :aria-valuenow="item.percent" aria-valuemin="0" aria-valuemax="100">
83
+ <div class="progress-bar" :style="{ width: item.percent + '%' }"></div>
84
+ </div>
85
+ <div v-if="item.status === 'error'" class="fg-danger" role="alert">{{ item.error }}</div>
86
+ </div>
87
+ <div class="col-auto" v-if="item.status === 'error'">
88
+ <button type="button" class="btn-text theme-secondary btn-icon" :aria-label="t('retry')" @click="channel.retry(item)">
89
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
90
+ aria-hidden="true">
91
+ <path d="M13.5 3v3.5H10"/>
92
+ <path d="M3.2 6.5A5.5 5.5 0 0 1 13 6.5M12.8 9.5A5.5 5.5 0 0 1 3 9.5M2.5 13V9.5H6"/>
93
+ </svg>
94
+ </button>
95
+ </div>
96
+ <div class="col-auto">
97
+ <button v-if="!channel.locked" type="button" class="btn-text theme-danger btn-icon" :aria-label="t('remove')" @click="channel.remove(item)">
98
+ <svg width="16" height="16" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"
99
+ aria-hidden="true">
100
+ <path d="M2.5 4.5h11M6 4.5V3a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1v1.5M4 4.5l.6 8.1a1 1 0 0 0 1 .9h4.8a1 1 0 0 0 1-.9l.6-8.1"/>
101
+ </svg>
102
+ </button>
103
+ </div>
104
+ </div>
105
+ </slot>
106
+ </li>
107
+ </ul>
108
+ </div>
109
+ </template>
@@ -0,0 +1,31 @@
1
+ import { reactive } from 'vue';
2
+
3
+ /**
4
+ * Shared state between <VoiceRecorderInput> and any number of <VoiceRecorderResultArea> components.
5
+ * A recorder publishes its list of recordings and its current problem under a "channel" key
6
+ * (its `channel` prop, or its `name`); a result area with `for="<key>"` displays them anywhere on the page.
7
+ *
8
+ * The recorder registers itself in onMounted and removes itself on unmount, so nothing is shared between
9
+ * server-side requests and nothing is leaked between pages.
10
+ */
11
+ export const voiceChannels = reactive({});
12
+ export const voiceAreaCounts = reactive({});
13
+
14
+ export function registerVoiceChannel(key, entry) {
15
+ voiceChannels[key] = entry;
16
+ }
17
+
18
+ export function unregisterVoiceChannel(key, owner) {
19
+ if (voiceChannels[key]?.owner === owner) delete voiceChannels[key];
20
+ }
21
+
22
+ /** Counts the (non-internal) result areas attached to a channel; returns the release function. */
23
+ export function retainVoiceArea(key) {
24
+ voiceAreaCounts[key] = (voiceAreaCounts[key] || 0) + 1;
25
+ return () => {
26
+ voiceAreaCounts[key] = Math.max(0, (voiceAreaCounts[key] || 1) - 1);
27
+ };
28
+ }
29
+
30
+ const pad = (n) => String(Math.floor(n)).padStart(2, '0');
31
+ export const formatTime = (s) => `${pad(s / 60)}:${pad(s % 60)}`;
package/src/index.js CHANGED
@@ -25,6 +25,7 @@ import SwitchInput from './SwitchInput.vue';
25
25
  import TextAreaInput from './TextAreaInput.vue';
26
26
  import TextInput from './TextInput.vue';
27
27
  import VoiceRecorderInput from './VoiceRecorderInput.vue'; // کنار بقیه importها
28
+ import VoiceRecorderResultArea from './VoiceRecorderResultArea.vue'; // کنار importها
28
29
 
29
30
  import { configureBootstrap } from './utils/bootstrap.js';
30
31
  import { configureI18n } from './i18n.js';
@@ -38,6 +39,7 @@ const components = {
38
39
  AmountInput,
39
40
  CaptchaInput,
40
41
  VoiceRecorderInput,
42
+ VoiceRecorderResultArea,
41
43
  CheckboxButtonInput,
42
44
  CheckboxInput,
43
45
  CheckboxToggle,
@@ -87,6 +89,7 @@ export {
87
89
  AmountInput,
88
90
  CaptchaInput,
89
91
  VoiceRecorderInput,
92
+ VoiceRecorderResultArea,
90
93
  CheckboxButtonInput,
91
94
  CheckboxInput,
92
95
  CheckboxToggle,