diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-card-audio.hbs b/ghost/admin/lib/koenig-editor/addon/components/koenig-card-audio.hbs index 19552df957..1181deac62 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-card-audio.hbs +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-card-audio.hbs @@ -24,84 +24,147 @@ >
- -
- {{#if (or this.previewThumbnailSrc @payload.thumbnailSrc)}} - - {{#if this.isDraggedOver}} -
- - Drop to replace audio - + {{#if (not @payload.src)}} + +
+ {{#if (or uploader.errors uploader.isUploading)}} +
+ {{#if uploader.errors}} + + {{uploader.errors.firstObject.message}} + + {{/if}} + + {{#if this.isDraggedOver}} + + Drop it like it's hot 🔥 + + {{else if uploader.isUploading}} + {{uploader.progressBar}} + {{/if}} +
+ {{else}} +
+ {{#if this.isDraggedOver}} + + Drop it like it's hot 🔥 + + {{else if uploader.isUploading}} + {{uploader.progressBar}} + {{else}} + + {{/if}}
{{/if}} - {{/if}} +
- {{#if (or uploader.errors uploader.isUploading (not @payload.src))}} -
- {{#if uploader.errors}} - - {{uploader.errors.firstObject.message}} - - {{/if}} +
+ +
+ - {{#if this.isDraggedOver}} - - Drop it like it's hot 🔥 - - {{else if uploader.isUploading}} - {{uploader.progressBar}} - {{else if (not this.previewThumbnailSrc @payload.src)}} - - {{/if}} -
- {{else}} -
- {{#if this.isDraggedOver}} - - Drop it like it's hot 🔥 - - {{else if uploader.isUploading}} - {{uploader.progressBar}} - {{else if (not this.previewThumbnailSrc @payload.src)}} - - {{/if}} -
- {{/if}} -
+ {{else}} + +
-
- -
- + {{#if (or uploader.errors uploader.isUploading)}} +
+ {{#if uploader.errors}} + + {{uploader.errors.firstObject.message}} + + {{/if}} + {{#if this.isDraggedOver}} + + Drop it like it's hot 🔥 + + {{else if uploader.isUploading}} + {{uploader.progressBar}} + {{else if (not @payload.thumbnailSrc)}} + + {{else}} + + {{#if this.isDraggedOver}} +
+ + Drop to replace thumbnail + +
+ {{/if}} + {{/if}} +
+ {{else}} +
+ {{#if this.isDraggedOver}} + + Drop it like it's hot 🔥 + + {{else if uploader.isUploading}} + {{uploader.progressBar}} + {{else if @payload.thumbnailSrc}} + + {{else}} + + {{/if}} +
+ {{/if}} +
+
+ +
+
+ + {{/if}}
-
- Click to upload an audio file -
+ {{#if @payload.src}} +
+ +
+ {{else}} +
+ Click to upload an audio file +
+ {{/if}}
- {{!-- {{#if (or @isSelected (clean-basic-html @payload.caption))}} - - {{/if}} --}} {{#if (and @isEditing @payload.src)}} diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-card-audio.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-card-audio.js index 1727747e16..dde46f9ad2 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-card-audio.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-card-audio.js @@ -1,4 +1,8 @@ import Component from '@glimmer/component'; +import { + IMAGE_EXTENSIONS, + IMAGE_MIME_TYPES +} from 'ghost-admin/components/gh-image-uploader'; import {TrackedObject} from 'tracked-built-ins'; import {action} from '@ember/object'; import {bind} from '@ember/runloop'; @@ -8,7 +12,6 @@ import {inject as service} from '@ember/service'; import {set} from '@ember/object'; import {task} from 'ember-concurrency-decorators'; import {tracked} from '@glimmer/tracking'; - export const AUDIO_EXTENSIONS = ['mp4', 'mp3', 'wav']; export const AUDIO_MIME_TYPES = ['audio/mp4', 'audio/mpeg', 'audio/ogg']; @@ -37,6 +40,7 @@ export default class KoenigCardAudioComponent extends Component { @service ghostPaths; @tracked files; + @tracked thumbnailFiles; @tracked isDraggedOver = false; @tracked previewThumbnailSrc; @@ -46,6 +50,8 @@ export default class KoenigCardAudioComponent extends Component { audioExtensions = AUDIO_EXTENSIONS; audioMimeTypes = AUDIO_MIME_TYPES; + imageExtensions = IMAGE_EXTENSIONS; + imageMimeTypes = IMAGE_MIME_TYPES; placeholder = PLACEHOLDERS[Math.floor(Math.random() * PLACEHOLDERS.length)] payloadAudioAttrs = ['src', 'fileName', 'width', 'height', 'duration', 'mimeType', 'thumbnailSrc', 'thumbnailWidth', 'thumbnailHeight']; @@ -91,6 +97,11 @@ export default class KoenigCardAudioComponent extends Component { }); } + _afterRender() { + // this._placeCursorAtEnd(); + // this._focusInput(); + } + @action didInsert(element) { // required for snippet rects to be calculated - editor reaches in to component, @@ -121,6 +132,11 @@ export default class KoenigCardAudioComponent extends Component { this._audioFileInput = input; } + @action + registerAudioThumbnailFileInput(input) { + this._audioThumbnailFileInput = input; + } + @action triggerAudioFileDialog(event) { if (this._audioFileInput) { @@ -137,11 +153,32 @@ export default class KoenigCardAudioComponent extends Component { } } + @action + triggerThumbnailFileDialog(event) { + if (this._audioThumbnailFileInput) { + return this._audioThumbnailFileInput.click(); + } + + const target = event?.target || this.element; + + const cardElem = target.closest('.__mobiledoc-card'); + const fileInput = cardElem?.querySelector('input[type="file"]'); + + if (fileInput) { + fileInput.click(); + } + } + @action async audioUploadStarted() { // TODO: Placeholder for any processing on audio upload } + @action + async audioThumbnailUploadStarted() { + // TODO: Placeholder for any processing on audio upload + } + @action async audioUploadCompleted([audio]) { this.previewPayload.src = audio.url; @@ -158,6 +195,22 @@ export default class KoenigCardAudioComponent extends Component { this.previewPayload = new TrackedObject({}); } + @action + async audioThumbnailUploadCompleted([audio]) { + this.previewPayload.thumbnailSrc = audio.url; + + // save preview payload attrs into actual payload and create undo snapshot + this.args.editor.run(() => { + this.updatePayloadAttr('thumbnailSrc', this.previewPayload.thumbnailSrc); + // this.payloadAudioAttrs.forEach((attr) => { + // this.updatePayloadAttr(attr, this.previewPayload[attr]); + // }); + }); + + // reset preview so we're back to rendering saved data + this.previewPayload = new TrackedObject({}); + } + @action audioUploadFailed() { // reset all attrs, creating an undo snapshot @@ -168,6 +221,19 @@ export default class KoenigCardAudioComponent extends Component { }); } + @action + setAudioTitle(content) { + this.updatePayloadAttr('fileName', content); + } + + @action + audioThumbnailUploadFailed() { + this.previewPayload.thumbnailSrc = null; + this.args.editor.run(() => { + this.updatePayloadAttr('thumbnailSrc', this.previewPayload.thumbnailSrc); + }); + } + @task *uploadThumbnailFromBlobTask(audioUrl, fileBlob) { const formData = new FormData();