@@ -6,8 +6,8 @@ import { createFigureWithCaption } from "../../blocks/FileBlockContent/helpers/t
66import { createLinkWithCaption } from "../../blocks/FileBlockContent/helpers/toExternalHTML/createLinkWithCaption.js" ;
77import {
88 createBlockConfig ,
9- createBlockSpec ,
10- } from "../../schema/blocks/playground .js" ;
9+ createBlockDefinition ,
10+ } from "../../schema/index .js" ;
1111
1212export const FILE_AUDIO_ICON_SVG =
1313 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><path d="M2 16.0001H5.88889L11.1834 20.3319C11.2727 20.405 11.3846 20.4449 11.5 20.4449C11.7761 20.4449 12 20.2211 12 19.9449V4.05519C12 3.93977 11.9601 3.8279 11.887 3.73857C11.7121 3.52485 11.3971 3.49335 11.1834 3.66821L5.88889 8.00007H2C1.44772 8.00007 1 8.44778 1 9.00007V15.0001C1 15.5524 1.44772 16.0001 2 16.0001ZM23 12C23 15.292 21.5539 18.2463 19.2622 20.2622L17.8445 18.8444C19.7758 17.1937 21 14.7398 21 12C21 9.26016 19.7758 6.80629 17.8445 5.15557L19.2622 3.73779C21.5539 5.75368 23 8.70795 23 12ZM18 12C18 10.0883 17.106 8.38548 15.7133 7.28673L14.2842 8.71584C15.3213 9.43855 16 10.64 16 12C16 13.36 15.3213 14.5614 14.2842 15.2841L15.7133 16.7132C17.106 15.6145 18 13.9116 18 12Z"></path></svg>' ;
@@ -42,89 +42,91 @@ const config = createBlockConfig((_ctx: AudioOptions) => ({
4242 } ,
4343} ) ) ;
4444
45- export const definition = createBlockSpec ( config ) . implementation ( ( config ) => ( {
46- parse : ( element ) => {
47- if ( element . tagName === "AUDIO" ) {
48- // Ignore if parent figure has already been parsed.
49- if ( element . closest ( "figure" ) ) {
50- return undefined ;
51- }
52-
53- return parseAudioElement ( element as HTMLAudioElement ) ;
54- }
45+ export const definition = createBlockDefinition ( config ) . implementation (
46+ ( config ) => ( {
47+ parse : ( element ) => {
48+ if ( element . tagName === "AUDIO" ) {
49+ // Ignore if parent figure has already been parsed.
50+ if ( element . closest ( "figure" ) ) {
51+ return undefined ;
52+ }
5553
56- if ( element . tagName === "FIGURE" ) {
57- const parsedFigure = parseFigureElement ( element , "audio" ) ;
58- if ( ! parsedFigure ) {
59- return undefined ;
54+ return parseAudioElement ( element as HTMLAudioElement ) ;
6055 }
6156
62- const { targetElement, caption } = parsedFigure ;
57+ if ( element . tagName === "FIGURE" ) {
58+ const parsedFigure = parseFigureElement ( element , "audio" ) ;
59+ if ( ! parsedFigure ) {
60+ return undefined ;
61+ }
6362
64- return {
65- ...parseAudioElement ( targetElement as HTMLAudioElement ) ,
66- caption,
67- } ;
68- }
63+ const { targetElement, caption } = parsedFigure ;
6964
70- return undefined ;
71- } ,
72- render : ( block , editor ) => {
73- const icon = document . createElement ( "div" ) ;
74- icon . innerHTML = config . icon ?? FILE_AUDIO_ICON_SVG ;
65+ return {
66+ ... parseAudioElement ( targetElement as HTMLAudioElement ) ,
67+ caption ,
68+ } ;
69+ }
7570
76- const audio = document . createElement ( "audio" ) ;
77- audio . className = "bn-audio" ;
78- if ( editor . resolveFileUrl ) {
79- editor . resolveFileUrl ( block . props . url ) . then ( ( downloadUrl ) => {
80- audio . src = downloadUrl ;
81- } ) ;
82- } else {
83- audio . src = block . props . url ;
84- }
85- audio . controls = true ;
86- audio . contentEditable = "false" ;
87- audio . draggable = false ;
71+ return undefined ;
72+ } ,
73+ render : ( block , editor ) => {
74+ const icon = document . createElement ( "div" ) ;
75+ icon . innerHTML = config . icon ?? FILE_AUDIO_ICON_SVG ;
8876
89- return createFileBlockWrapper (
90- block ,
91- editor ,
92- { dom : audio } ,
93- editor . dictionary . file_blocks . audio . add_button_text ,
94- icon . firstElementChild as HTMLElement ,
95- ) ;
96- } ,
97- toExternalHTML ( block ) {
98- if ( ! block . props . url ) {
99- const div = document . createElement ( "p" ) ;
100- div . textContent = "Add audio" ;
77+ const audio = document . createElement ( "audio" ) ;
78+ audio . className = "bn-audio" ;
79+ if ( editor . resolveFileUrl ) {
80+ editor . resolveFileUrl ( block . props . url ) . then ( ( downloadUrl ) => {
81+ audio . src = downloadUrl ;
82+ } ) ;
83+ } else {
84+ audio . src = block . props . url ;
85+ }
86+ audio . controls = true ;
87+ audio . contentEditable = "false" ;
88+ audio . draggable = false ;
10189
102- return {
103- dom : div ,
104- } ;
105- }
90+ return createFileBlockWrapper (
91+ block ,
92+ editor ,
93+ { dom : audio } ,
94+ editor . dictionary . file_blocks . audio . add_button_text ,
95+ icon . firstElementChild as HTMLElement ,
96+ ) ;
97+ } ,
98+ toExternalHTML ( block ) {
99+ if ( ! block . props . url ) {
100+ const div = document . createElement ( "p" ) ;
101+ div . textContent = "Add audio" ;
106102
107- let audio ;
108- if ( block . props . showPreview ) {
109- audio = document . createElement ( "audio" ) ;
110- audio . src = block . props . url ;
111- } else {
112- audio = document . createElement ( "a" ) ;
113- audio . href = block . props . url ;
114- audio . textContent = block . props . name || block . props . url ;
115- }
103+ return {
104+ dom : div ,
105+ } ;
106+ }
116107
117- if ( block . props . caption ) {
108+ let audio ;
118109 if ( block . props . showPreview ) {
119- return createFigureWithCaption ( audio , block . props . caption ) ;
110+ audio = document . createElement ( "audio" ) ;
111+ audio . src = block . props . url ;
120112 } else {
121- return createLinkWithCaption ( audio , block . props . caption ) ;
113+ audio = document . createElement ( "a" ) ;
114+ audio . href = block . props . url ;
115+ audio . textContent = block . props . name || block . props . url ;
122116 }
123- }
124117
125- return {
126- dom : audio ,
127- } ;
128- } ,
129- runsBefore : [ "file" ] ,
130- } ) ) ;
118+ if ( block . props . caption ) {
119+ if ( block . props . showPreview ) {
120+ return createFigureWithCaption ( audio , block . props . caption ) ;
121+ } else {
122+ return createLinkWithCaption ( audio , block . props . caption ) ;
123+ }
124+ }
125+
126+ return {
127+ dom : audio ,
128+ } ;
129+ } ,
130+ runsBefore : [ "file" ] ,
131+ } ) ,
132+ ) ;
0 commit comments