Skip to content

Beautiful Open-Source Form Builder

Add audio block support and related components (#1197)

Chirag Chhatrala3a1b5abd3f63
diff --git a/api/app/Rules/PropertyValidators/LogicPropertyValidator.php b/api/app/Rules/PropertyValidators/LogicPropertyValidator.php
index b4609686d..d6066917d 100644
--- a/api/app/Rules/PropertyValidators/LogicPropertyValidator.php
+++ b/api/app/Rules/PropertyValidators/LogicPropertyValidator.php
@@ -223,7 +223,7 @@ class LogicPropertyValidator implements PropertyValidatorInterface
return;
}
- $layoutBlocks = ['nf-text', 'nf-code', 'nf-page-break', 'nf-divider', 'nf-image', 'nf-video'];
+ $layoutBlocks = ['nf-text', 'nf-code', 'nf-page-break', 'nf-divider', 'nf-image', 'nf-video', 'nf-audio'];
$fieldType = $this->field['type'] ?? null;
$isHidden = $this->field['hidden'] ?? false;
$isRequired = $this->field['required'] ?? false;
diff --git a/api/app/Service/AI/Prompts/Form/FormFieldSchemas.php b/api/app/Service/AI/Prompts/Form/FormFieldSchemas.php
index 45a1ec46f..9b43d59bb 100644
--- a/api/app/Service/AI/Prompts/Form/FormFieldSchemas.php
+++ b/api/app/Service/AI/Prompts/Form/FormFieldSchemas.php
@@ -371,6 +371,15 @@ class FormFieldSchemas
'core' => ['$ref' => '#/definitions/baseProperty'],
]
],
+ 'nfAudioProperty' => [
+ 'type' => 'object',
+ 'required' => ['core', 'type'],
+ 'additionalProperties' => false,
+ 'properties' => [
+ 'type' => ['type' => 'string', 'enum' => ['nf-audio']],
+ 'core' => ['$ref' => '#/definitions/baseProperty'],
+ ]
+ ],
'nfCodeProperty' => [
'type' => 'object',
'required' => ['core', 'type'],
diff --git a/api/app/Service/AI/Prompts/Form/GenerateFormFieldsPrompt.php b/api/app/Service/AI/Prompts/Form/GenerateFormFieldsPrompt.php
index aa7a95966..8d04c1b94 100644
--- a/api/app/Service/AI/Prompts/Form/GenerateFormFieldsPrompt.php
+++ b/api/app/Service/AI/Prompts/Form/GenerateFormFieldsPrompt.php
@@ -94,6 +94,7 @@ class GenerateFormFieldsPrompt extends Prompt
['$ref' => '#/definitions/nfDividerProperty'],
['$ref' => '#/definitions/nfImageProperty'],
['$ref' => '#/definitions/nfVideoProperty'],
+ ['$ref' => '#/definitions/nfAudioProperty'],
['$ref' => '#/definitions/nfCodeProperty']
]
]
@@ -175,6 +176,7 @@ class GenerateFormFieldsPrompt extends Prompt
'nf-divider' => 'nf-divider: Visual divider (not an input field)',
'nf-image' => 'nf-image: Image element',
'nf-video' => 'nf-video: Video element',
+ 'nf-audio' => 'nf-audio: Audio element',
'nf-code' => 'nf-code: Code block',
];
diff --git a/api/app/Service/AI/Prompts/Form/GenerateFormPrompt.php b/api/app/Service/AI/Prompts/Form/GenerateFormPrompt.php
index cf4716714..f5b5ed94f 100644
--- a/api/app/Service/AI/Prompts/Form/GenerateFormPrompt.php
+++ b/api/app/Service/AI/Prompts/Form/GenerateFormPrompt.php
@@ -126,6 +126,7 @@ class GenerateFormPrompt extends Prompt
['$ref' => '#/definitions/nfDividerProperty'],
['$ref' => '#/definitions/nfImageProperty'],
['$ref' => '#/definitions/nfVideoProperty'],
+ ['$ref' => '#/definitions/nfAudioProperty'],
['$ref' => '#/definitions/nfCodeProperty']
]
]
@@ -224,6 +225,7 @@ class GenerateFormPrompt extends Prompt
'nf-divider' => 'nf-divider: Visual divider (not an input field)',
'nf-image' => 'nf-image: Image element',
'nf-video' => 'nf-video: Video element',
+ 'nf-audio' => 'nf-audio: Audio element',
'nf-code' => 'nf-code: Code block',
];
diff --git a/api/app/Service/Storage/SafeFileResponseService.php b/api/app/Service/Storage/SafeFileResponseService.php
index aefc115a4..2274d42c2 100644
--- a/api/app/Service/Storage/SafeFileResponseService.php
+++ b/api/app/Service/Storage/SafeFileResponseService.php
@@ -22,7 +22,7 @@ class SafeFileResponseService
'X-Frame-Options' => 'DENY',
];
- if (!Str::startsWith($mimeType, 'image/')) {
+ if (!Str::startsWith($mimeType, ['image/', 'audio/'])) {
$headers['Content-Disposition'] = 'attachment; filename="' . ($downloadName ?? basename($path)) . '"';
}
diff --git a/api/resources/data/forms/blocks_types.json b/api/resources/data/forms/blocks_types.json
index 13f8f6443..4d375b3f6 100644
--- a/api/resources/data/forms/blocks_types.json
+++ b/api/resources/data/forms/blocks_types.json
@@ -391,6 +391,16 @@
"is_input": false,
"default_values": {}
},
+ "nf-audio": {
+ "name": "nf-audio",
+ "title": "Audio",
+ "icon": "i-heroicons-speaker-wave",
+ "default_block_name": "Audio Block",
+ "bg_class": "bg-yellow-100",
+ "text_class": "text-yellow-900",
+ "is_input": false,
+ "default_values": {}
+ },
"nf-code": {
"name": "nf-code",
"title": "Code",
diff --git a/api/tests/Unit/Service/Storage/SafeFileResponseServiceTest.php b/api/tests/Unit/Service/Storage/SafeFileResponseServiceTest.php
new file mode 100644
index 000000000..dc49c791d
--- /dev/null
+++ b/api/tests/Unit/Service/Storage/SafeFileResponseServiceTest.php
@@ -0,0 +1,29 @@
+<?php
+
+use App\Service\Storage\SafeFileResponseService;
+use Illuminate\Support\Facades\Storage;
+use Tests\TestCase;
+
+uses(TestCase::class);
+
+it('serves audio assets inline', function () {
+ $stream = fopen('php://temp', 'r+');
+ fwrite($stream, 'audio content');
+ rewind($stream);
+
+ Storage::shouldReceive('readStream')
+ ->once()
+ ->with('forms/assets/podcast.mp3')
+ ->andReturn($stream);
+ Storage::shouldReceive('mimeType')
+ ->once()
+ ->with('forms/assets/podcast.mp3')
+ ->andReturn('audio/mpeg');
+
+ $response = app(SafeFileResponseService::class)->serve('forms/assets/podcast.mp3', 'podcast.mp3');
+
+ expect($response->headers->get('Content-Type'))->toBe('audio/mpeg');
+ expect($response->headers->get('Content-Disposition'))->toBeNull();
+
+ fclose($stream);
+});
diff --git a/client/components/forms/heavy/AudioInput.vue b/client/components/forms/heavy/AudioInput.vue
new file mode 100644
index 000000000..54980fe25
--- /dev/null
+++ b/client/components/forms/heavy/AudioInput.vue
@@ -0,0 +1,291 @@
+<template>
+ <InputWrapper v-bind="inputWrapperProps">
+ <template #label>
+ <slot name="label" />
+ </template>
+
+ <div class="inline-block w-full rounded-md shadow-xs">
+ <button
+ v-if="currentUrl == null"
+ type="button"
+ aria-haspopup="listbox"
+ aria-expanded="true"
+ aria-labelledby="listbox-label"
+ class="cursor-pointer relative w-full"
+ :class="ui.button({ class: props.ui?.slots?.button })"
+ :style="inputStyle"
+ :disabled="disabled ? true : null"
+ @click.prevent="showUploadModal = true"
+ >
+ <div class="text-neutral-600 dark:text-neutral-400 flex justify-center">
+ <Icon
+ name="heroicons:cloud-arrow-up"
+ class="h-5 w-5"
+ />
+ <span class="ml-2">
+ Upload
+ </span>
+ </div>
+ </button>
+ <div
+ v-else
+ class="text-neutral-600 dark:text-neutral-400 flex items-center gap-2"
+ :style="inputStyle"
+ >
+ <div class="flex-grow min-w-0">
+ <EmbedMedia
+ :src="currentUrl"
+ :force-audio="true"
+ :theme="resolvedTheme"
+ :size="resolvedSize"
+ :border-radius="resolvedBorderRadius"
+ />
+ </div>
+ <button
+ v-if="!disabled"
+ class="text-neutral-500 hover:text-red-500 flex items-center shrink-0"
+ type="button"
+ aria-label="Remove audio"
+ @click="clearUrl"
+ >
+ <Icon
+ name="heroicons:trash"
+ class="h-5 w-5"
+ />
+ </button>
+ </div>
+ </div>
+
+ <template #help>
+ <slot name="help" />
+ </template>
+ <template #error>
+ <slot name="error" />
+ </template>
+
+ <UModal
+ v-model:open="showUploadModal"
+ title="Upload an audio file"
+ :ui="{ content: 'sm:max-w-xl', body: 'pt-2!' }"
+ >
+ <template #body>
+ <div class="max-w-3xl mx-auto lg:max-w-none">
+ <UTabs
+ v-model="activeTab"
+ :items="tabItems"
+ :content="false"
+ variant="link"
+ class="mb-2"
+ />
+
+ <div v-if="activeTab === 'upload'" class="sm:grid sm:grid-cols-1 sm:gap-4 sm:items-start">
+ <div class="sm:col-span-2 mb-5 mt-2">
+ <div
+ v-cloak
+ class="w-full flex justify-center items-center px-6 pt-5 pb-6 border-2 border-neutral-300 border-dashed rounded-md h-54"
+ @dragover.prevent="onUploadDragoverEvent($event)"
+ @drop.prevent="onUploadDropEvent($event)"
+ >
+ <div
+ v-if="loading"
+ class="text-neutral-600 dark:text-neutral-400"
+ >
+ <loader class="h-5 w-5 mx-auto m-10" />
+ <p class="text-center mt-6">
+ Uploading your file...
+ </p>
+ </div>
+ <template v-else>
+ <div
+ class="absolute rounded-full bg-neutral-100 h-20 w-20 z-10 transition-opacity duration-500 ease-in-out"
+ :class="{
+ 'opacity-100': uploadDragoverTracking,
+ 'opacity-0': !uploadDragoverTracking,
+ }"
+ />
+ <div class="relative z-20 text-center">
+ <input
+ ref="actual-input"
+ class="hidden"
+ type="file"
+ :name="name"
+ accept="audio/mpeg, audio/wav, audio/ogg, audio/mp4, audio/aac, audio/webm, .mp3, .wav, .ogg, .m4a, .aac, .webm"
+ @change="manualFileUpload"
+ >
+ <Icon
+ name="heroicons:cloud-arrow-up"
+ class="x-auto h-24 w-24 text-neutral-200"
+ />
+ <p class="mt-5 text-sm text-neutral-600">
+ <button
+ type="button"
+ class="font-semibold text-blue-500 hover:text-blue-800 focus:outline-hidden focus:underline transition duration-150 ease-in-out"
+ @click="openFileUpload"
+ >
+ Upload your audio,
+ </button>
+ use drag and drop or paste it
+ </p>
+ <p class="mt-1 text-xs text-neutral-500">
+ .mp3, .wav, .ogg, .m4a, .aac, .webm up to 5mb
+ </p>
+ </div>
+ </template>
+ </div>
+ </div>
+ </div>
+
+ <div v-else-if="activeTab === 'url'" class="p-4">
+ <TextInput
+ v-model="urlInput"
+ name="audio_url"
+ label="Enter the URL of the audio you want to use"
+ placeholder="https://example.com/audio.mp3"
+ />
+ <div class="mt-4 flex justify-end gap-2">
+ <UButton color="primary" :disabled="!urlInput" @click="insertUrl">
+ Insert
+ </UButton>
+ </div>
+ </div>
+ </div>
+ </template>
+ </UModal>
+ </InputWrapper>
+</template>
+
+<script>
+import { inputProps, useFormInput } from "../useFormInput.js"
+import { storeFile } from "~/lib/file-uploads.js"
+import { formsApi } from '~/api'
+import { imageInputTheme } from '~/lib/forms/themes/image-input.theme.js'
+
+export default {
+ props: {
+ ...inputProps,
+ },
+
+ setup(props, context) {
+ const formInput = useFormInput(props, context, {
+ variants: imageInputTheme
+ })
+ return {
+ ...formInput,
+ props
+ }
+ },
+
+ data: () => ({
+ showUploadModal: false,
+ activeTab: 'upload',
+ urlInput: '',
+
+ file: [],
+ uploadDragoverTracking: false,
+ uploadDragoverEvent: false,
+ loading: false,
+ }),
+
+ computed: {
+ currentUrl() {
+ return this.compVal
+ },
+ tabItems() {
+ return [
+ { label: 'Upload', value: 'upload' },
+ { label: 'URL', value: 'url' },
+ ]
+ },
+ },
+
+ watch: {
+ showUploadModal: {
+ handler() {
+ if (import.meta.server) return
+ document.removeEventListener("paste", this.onUploadPasteEvent)
+ if (this.showUploadModal) {
+ document.addEventListener("paste", this.onUploadPasteEvent)
+ }
+ },
+ },
+ },
+
+ methods: {
+ clearUrl() {
+ if (this.disabled) return
+ this.compVal = null
+ },
+ onUploadDragoverEvent() {
+ this.uploadDragoverEvent = true
+ this.uploadDragoverTracking = true
+ },
+ onUploadDropEvent(e) {
+ this.uploadDragoverEvent = false
+ this.uploadDragoverTracking = false
+ this.droppedFiles(e.dataTransfer.files)
+ },
+ onUploadPasteEvent(e) {
+ if (!this.showUploadModal || this.activeTab !== 'upload') return
+ this.uploadDragoverEvent = false
+ this.uploadDragoverTracking = false
+ this.droppedFiles(e.clipboardData.files)
+ },
+ insertUrl() {
+ if (this.disabled) return
+ if (!this.urlInput || !/^https?:\/\/[^\s$.?#].[^\s]*$/i.test(this.urlInput)) return
+ this.compVal = this.urlInput
+ this.urlInput = ''
+ this.showUploadModal = false
+ },
+ droppedFiles(droppedFiles) {
+ if (this.disabled) return
+ if (!droppedFiles) return
+
+ this.file = droppedFiles[0]
+ this.uploadFileToServer()
+ },
+ openFileUpload() {
+ if (this.disabled) return
+ this.$refs["actual-input"].click()
+ },
+ manualFileUpload(e) {
+ if (this.disabled) return
+ this.file = e.target.files[0]
+ this.uploadFileToServer()
+ },
+ uploadFileToServer() {
+ this.loading = true
+ storeFile(this.file)
+ .then((response) => {
+ formsApi.assets.upload({
+ url:
+ this.file.name.split(".").slice(0, -1).join(".") +
+ "_" +
+ response.uuid +
+ "." +
+ response.extension,
+ })
+ .then((moveFileResponseData) => {
+ this.compVal = moveFileResponseData.url
+ })
+ .catch((error) => {
+ this.compVal = null
+ this.showUploadError(error)
+ })
+ })
+ .catch((error) => {
+ this.compVal = null
+ this.showUploadError(error)
+ })
+ .finally(() => {
+ this.showUploadModal = false
+ this.loading = false
+ })
+ },
+ showUploadError(error) {
+ const data = error?.data || error?.response?._data
+ useAlert().error(data?.errors?.url?.[0] || error?.message || 'Failed to upload audio file. Please try again.')
+ },
+ },
+}
+</script>
diff --git a/client/components/forms/heavy/components/EmbedMedia.vue b/client/components/forms/heavy/components/EmbedMedia.vue
index 526b7760b..bb4885083 100644
--- a/client/components/forms/heavy/components/EmbedMedia.vue
+++ b/client/components/forms/heavy/components/EmbedMedia.vue
@@ -20,9 +20,14 @@
/>
</div>
- <div v-else-if="descriptor.kind === 'audio'">
- <audio :src="descriptor.src" class="w-full" controls />
- </div>
+ <NativeAudioPlayer
+ v-else-if="descriptor.kind === 'audio'"
+ :src="descriptor.src"
+ :theme="theme"
+ :size="size"
+ :border-radius="borderRadius"
+ :ui="ui"
+ />
<div v-else-if="descriptor.kind === 'image'" :class="['inline-block', 'max-w-full']">
<img :src="descriptor.src" :alt="descriptor.title || ''" :class="[roundedClass, 'max-w-full']" />
@@ -43,15 +48,25 @@
<script setup>
import { resolveEmbed } from 'embedkit'
+import NativeAudioPlayer from './NativeAudioPlayer.vue'
const props = defineProps({
src: { type: String, required: true },
+ forceAudio: { type: Boolean, default: false },
isDark: { type: Boolean, default: false },
- preferLang: { type: String, default: 'en' }
+ preferLang: { type: String, default: 'en' },
+ theme: { type: String, default: null },
+ size: { type: String, default: null },
+ borderRadius: { type: String, default: null },
+ ui: { type: Object, default: () => ({}) },
})
const result = computed(() => {
if (!props.src) return null
+ if (props.forceAudio) {
+ return { ok: true, descriptor: { kind: 'audio', src: props.src } }
+ }
+
try {
const options = {
preferLang: props.preferLang,
@@ -94,4 +109,3 @@ const roundedClass = computed(() => {
})
</script>
-
diff --git a/client/components/forms/heavy/components/NativeAudioPlayer.vue b/client/components/forms/heavy/components/NativeAudioPlayer.vue
new file mode 100644
index 000000000..c6e988203
--- /dev/null
+++ b/client/components/forms/heavy/components/NativeAudioPlayer.vue
@@ -0,0 +1,191 @@
+<template>
+ <div :class="ui.container({ class: props.ui?.slots?.container })">
+ <button
+ type="button"
+ :class="ui.button({ class: props.ui?.slots?.button })"
+ :aria-label="isPlaying ? 'Pause' : 'Play'"
+ @click="togglePlay"
+ >
+ <Icon
+ :name="isPlaying ? 'i-heroicons-pause' : 'i-heroicons-play'"
+ :class="ui.icon({ class: props.ui?.slots?.icon })"
+ />
+ </button>
+
+ <span :class="ui.time({ class: props.ui?.slots?.time })">
+ {{ formatTime(currentTime) }}
+ </span>
+
+ <input
+ type="range"
+ :class="ui.progress({ class: props.ui?.slots?.progress })"
+ min="0"
+ max="100"
+ step="0.1"
+ :value="progressPercent"
+ :disabled="!duration"
+ @input="seek"
+ >
+
+ <span :class="[ui.time({ class: props.ui?.slots?.time }), 'text-end']">
+ {{ formatTime(duration) }}
+ </span>
+
+ <button
+ type="button"
+ :class="ui.button({ class: props.ui?.slots?.button })"
+ :aria-label="isMuted ? 'Unmute' : 'Mute'"
+ @click="toggleMute"
+ >
+ <Icon
+ :name="isMuted ? 'i-heroicons-speaker-x-mark' : 'i-heroicons-speaker-wave'"
+ :class="ui.icon({ class: props.ui?.slots?.icon })"
+ />
+ </button>
+
+ <audio
+ ref="audioRef"
+ :src="src"
+ class="hidden"
+ @timeupdate="onTimeUpdate"
+ @loadedmetadata="onLoadedMetadata"
+ @ended="onEnded"
+ @play="isPlaying = true"
+ @pause="isPlaying = false"
+ />
+ </div>
+</template>
+
+<script setup>
+import { tv } from 'tailwind-variants'
+import { nativeAudioPlayerTheme } from '~/lib/forms/themes/native-audio-player.theme.js'
+
+const props = defineProps({
+ src: { type: String, required: true },
+ theme: { type: String, default: null },
+ size: { type: String, default: null },
+ borderRadius: { type: String, default: null },
+ ui: { type: Object, default: () => ({}) },
+})
+
+const injectedTheme = inject('formTheme', null)
+const injectedSize = inject('formSize', null)
+const injectedBorderRadius = inject('formBorderRadius', null)
+
+const resolvedTheme = computed(() => props.theme || injectedTheme?.value || 'default')
+const resolvedSize = computed(() => props.size || injectedSize?.value || 'md')
+const resolvedBorderRadius = computed(() => props.borderRadius || injectedBorderRadius?.value || 'small')
+
+const ui = computed(() => tv(nativeAudioPlayerTheme, { twMerge: true })({
+ theme: resolvedTheme.value,
+ size: resolvedSize.value,
+ borderRadius: resolvedBorderRadius.value,
+}))
+
+const audioRef = ref(null)
+const isPlaying = ref(false)
+const isMuted = ref(false)
+const currentTime = ref(0)
+const duration = ref(0)
+
+const progressPercent = computed(() => {
+ if (!duration.value) return 0
+ return (currentTime.value / duration.value) * 100
+})
+
+function formatTime(seconds) {
+ if (!seconds || Number.isNaN(seconds)) return '0:00'
+ const minutes = Math.floor(seconds / 60)
+ const secs = Math.floor(seconds % 60)
+ return `${minutes}:${String(secs).padStart(2, '0')}`
+}
+
+function togglePlay() {
+ const audio = audioRef.value
+ if (!audio) return
+
+ if (audio.paused) {
+ audio.play().catch(() => {})
+ } else {
+ audio.pause()
+ }
+}
+
+function toggleMute() {
+ const audio = audioRef.value
+ if (!audio) return
+
+ audio.muted = !audio.muted
+ isMuted.value = audio.muted
+}
+
+function seek(event) {
+ const audio = audioRef.value
+ if (!audio || !duration.value) return
+
+ const percent = Number(event.target.value) / 100
+ audio.currentTime = percent * duration.value
+}
+
+function onTimeUpdate() {
+ currentTime.value = audioRef.value?.currentTime || 0
+}
+
+function onLoadedMetadata() {
+ duration.value = audioRef.value?.duration || 0
+}
+
+function onEnded() {
+ isPlaying.value = false
+ currentTime.value = 0
+}
+
+watch(() => props.src, () => {
+ if (audioRef.value) {
+ audioRef.value.muted = false
+ }
+
+ isPlaying.value = false
+ isMuted.value = false
+ currentTime.value = 0
+ duration.value = 0
+})
+</script>
+
+<style scoped>
+.native-audio-player__progress {
+ -webkit-appearance: none;
+ appearance: none;
+ background: transparent;
+}
+
+.native-audio-player__progress::-webkit-slider-runnable-track {
+ height: 4px;
+ border-radius: 9999px;
+ background: rgb(163 163 163 / 0.45);
+}
+
+.native-audio-player__progress::-webkit-slider-thumb {
+ -webkit-appearance: none;
+ appearance: none;
+ width: 12px;
+ height: 12px;
+ margin-top: -4px;
+ border-radius: 9999px;
+ background: currentColor;
+}
+
+.native-audio-player__progress::-moz-range-track {
+ height: 4px;
+ border-radius: 9999px;
+ background: rgb(163 163 163 / 0.45);
+}
+
+.native-audio-player__progress::-moz-range-thumb {
+ width: 12px;
+ height: 12px;
+ border: 0;
+ border-radius: 9999px;
+ background: currentColor;
+}
+</style>
diff --git a/client/components/open/forms/BlockRenderer.vue b/client/components/open/forms/BlockRenderer.vue
index 2143d1858..f6010f12c 100644
--- a/client/components/open/forms/BlockRenderer.vue
+++ b/client/components/open/forms/BlockRenderer.vue
@@ -94,6 +94,31 @@
:is-dark="darkMode"
/>
</div>
+ <div
+ v-else-if="block.type === 'nf-audio' && (isAdminPreview || (!isAdminPreview && block.audio_block))"
+ :id="block.id"
+ :key="'audio-' + block.id"
+ class="my-4 w-full"
+ :class="[getFieldAlignClasses(block)]"
+ @dblclick="editFieldOptions"
+ >
+ <div
+ v-if="!block.audio_block"
+ class="p-4 border border-dashed text-center"
+ >
+ <a
+ href="#"
+ class="text-blue-800 dark:text-blue-200"
+ @click.prevent="editFieldOptions"
+ >Open block settings to add audio.</a>
+ </div>
+ <EmbedMedia
+ v-else
+ :src="block.audio_block"
+ :force-audio="true"
+ :is-dark="darkMode"
+ />
+ </div>
</div>
</template>
diff --git a/client/components/open/forms/components/form-logic-components/FormBlockLogicEditor.vue b/client/components/open/forms/components/form-logic-components/FormBlockLogicEditor.vue
index 487b0b804..3050fc806 100644
--- a/client/components/open/forms/components/form-logic-components/FormBlockLogicEditor.vue
+++ b/client/components/open/forms/components/form-logic-components/FormBlockLogicEditor.vue
@@ -266,6 +266,7 @@ export default {
"nf-divider",
"nf-image",
"nf-video",
+ "nf-audio",
].includes(this.field.type)
) {
if (this.field.hidden) {
diff --git a/client/components/open/forms/fields/components/BlockOptions.vue b/client/components/open/forms/fields/components/BlockOptions.vue
index 11b88f65b..8b7ea6a7f 100644
--- a/client/components/open/forms/fields/components/BlockOptions.vue
+++ b/client/components/open/forms/fields/components/BlockOptions.vue
@@ -40,7 +40,7 @@
:columns="6"
/>
<OptionSelectorInput
- v-if="['nf-text', 'nf-image', 'nf-video'].includes(field.type)"
+ v-if="['nf-text', 'nf-image', 'nf-video', 'nf-audio'].includes(field.type)"
v-model="field.align"
name="align"
class="mt-4 w-2/3"
@@ -125,6 +125,19 @@
/>
</div>
+ <div
+ v-else-if="field.type == 'nf-audio'"
+ class="border-t mt-4"
+ >
+ <AudioInput
+ name="audio_block"
+ class="mx-4"
+ :form="field"
+ label="Audio"
+ help="Upload an audio file or paste a URL. It will be displayed as an audio block."
+ />
+ </div>
+
<div
v-else-if="field.type == 'nf-code'"
class="border-t mt-6"
diff --git a/client/composables/components/useComponentRegistry.js b/client/composables/components/useComponentRegistry.js
index 55a5ae9c8..3d5c9e8eb 100644
--- a/client/composables/components/useComponentRegistry.js
+++ b/client/composables/components/useComponentRegistry.js
@@ -42,6 +42,7 @@ const heavyFormComponentsRegistry = new Map([
['SignatureInput', () => import('~/components/forms/heavy/SignatureInput.vue')],
['FileInput', () => import('~/components/forms/heavy/FileInput.vue')],
['ImageInput', () => import('~/components/forms/heavy/ImageInput.vue')],
+ ['AudioInput', () => import('~/components/forms/heavy/AudioInput.vue')],
['LogicConfirmationModal', () => import('~/components/forms/heavy/LogicConfirmationModal.vue')],
['MatrixInput', () => import('~/components/forms/heavy/MatrixInput.vue')],
['PhoneInput', () => import('~/components/forms/heavy/PhoneInput.vue')],
diff --git a/client/data/blocks_types.json b/client/data/blocks_types.json
index 13f8f6443..4d375b3f6 100644
--- a/client/data/blocks_types.json
+++ b/client/data/blocks_types.json
@@ -391,6 +391,16 @@
"is_input": false,
"default_values": {}
},
+ "nf-audio": {
+ "name": "nf-audio",
+ "title": "Audio",
+ "icon": "i-heroicons-speaker-wave",
+ "default_block_name": "Audio Block",
+ "bg_class": "bg-yellow-100",
+ "text_class": "text-yellow-900",
+ "is_input": false,
+ "default_values": {}
+ },
"nf-code": {
"name": "nf-code",
"title": "Code",
diff --git a/client/lib/forms/FormPropertyLogicRule.js b/client/lib/forms/FormPropertyLogicRule.js
index 5a09fbc4b..4a8d5ba56 100644
--- a/client/lib/forms/FormPropertyLogicRule.js
+++ b/client/lib/forms/FormPropertyLogicRule.js
@@ -137,7 +137,8 @@ class FormPropertyLogicRule {
"nf-page-break",
"nf-divider",
"nf-image",
- "nf-video"
+ "nf-video",
+ "nf-audio"
].indexOf(this.property["type"]) > -1 &&
["hide-block", "show-block"].indexOf(val) === -1) ||
(this.property["hidden"] !== undefined &&
diff --git a/client/lib/forms/themes/native-audio-player.theme.js b/client/lib/forms/themes/native-audio-player.theme.js
new file mode 100644
index 000000000..7023ca19d
--- /dev/null
+++ b/client/lib/forms/themes/native-audio-player.theme.js
@@ -0,0 +1,87 @@
+/**
+ * NativeAudioPlayer tailwind-variants configuration
+ */
+export const nativeAudioPlayerTheme = {
+ slots: {
+ container: [
+ 'flex items-center w-full border',
+ 'transition-colors duration-200'
+ ],
+ button: [
+ 'shrink-0 flex items-center justify-center',
+ 'text-current hover:opacity-80 transition-opacity'
+ ],
+ icon: '',
+ time: 'tabular-nums shrink-0',
+ progress: 'native-audio-player__progress flex-1 min-w-0 cursor-pointer'
+ },
+ variants: {
+ theme: {
+ default: {
+ container: [
+ 'border-neutral-300 dark:border-neutral-600',
+ 'bg-white text-neutral-700 dark:bg-notion-dark-light dark:text-neutral-300',
+ 'shadow-xs'
+ ]
+ },
+ minimal: {
+ container: [
+ 'border-2 border-transparent',
+ 'bg-neutral-100 text-neutral-700 dark:bg-notion-dark-light dark:text-neutral-300'
+ ]
+ },
+ notion: {
+ container: [
+ 'border-notion-input-border dark:border-notion-input-borderDark',
+ 'bg-notion-input-background dark:bg-notion-dark-light',
+ 'text-neutral-900 dark:text-neutral-100'
+ ]
+ },
+ transparent: {
+ container: [
+ 'border-0',
+ 'bg-transparent dark:bg-transparent',
+ 'text-neutral-700 dark:text-neutral-300',
+ 'shadow-[inset_0_-1px_0_0_rgb(212_212_212)] dark:shadow-[inset_0_-1px_0_0_rgb(82_82_82)]',
+ '!rounded-none'
+ ]
+ }
+ },
+ size: {
+ xs: {
+ container: 'px-2 py-1 gap-1',
+ time: 'text-xs min-w-[2rem]',
+ icon: 'h-4 w-4',
+ progress: 'h-0.5'
+ },
+ sm: {
+ container: 'px-2.5 py-1.5 gap-1.5',
+ time: 'text-xs min-w-[2.25rem]',
+ icon: 'h-4 w-4',
+ progress: 'h-0.5'
+ },
+ md: {
+ container: 'px-3 py-2 gap-2',
+ time: 'text-sm min-w-[2.25rem]',
+ icon: 'h-5 w-5',
+ progress: 'h-1'
+ },
+ lg: {
+ container: 'px-4 py-3 gap-2',
+ time: 'text-base min-w-[2.5rem]',
+ icon: 'h-6 w-6',
+ progress: 'h-1'
+ }
+ },
+ borderRadius: {
+ none: { container: 'rounded-none' },
+ small: { container: 'rounded-lg' },
+ full: { container: 'rounded-[20px]' }
+ }
+ },
+ defaultVariants: {
+ theme: 'default',
+ size: 'md',
+ borderRadius: 'small'
+ }
+}
diff --git a/client/test/nuxt/native-audio-player.spec.ts b/client/test/nuxt/native-audio-player.spec.ts
new file mode 100644
index 000000000..9901dbc79
--- /dev/null
+++ b/client/test/nuxt/native-audio-player.spec.ts
@@ -0,0 +1,21 @@
+import { mount } from '@vue/test-utils'
+import { describe, expect, it } from 'vitest'
+import NativeAudioPlayer from '~/components/forms/heavy/components/NativeAudioPlayer.vue'
+
+describe('NativeAudioPlayer', () => {
+ it('unmutes the native audio element when the source changes', async () => {
+ const wrapper = mount(NativeAudioPlayer, {
+ props: { src: 'https://example.test/first.mp3' },
+ global: {
+ stubs: { Icon: true },
+ },
+ })
+ const audio = wrapper.get('audio').element
+
+ audio.muted = true
+ await wrapper.setProps({ src: 'https://example.test/second.mp3' })
+
+ expect(audio.muted).toBe(false)
+ expect(wrapper.get('button[aria-label="Mute"]').exists()).toBe(true)
+ })
+})