Add video command

This commit is contained in:
Christoph Hagen
2025-06-08 17:02:05 +02:00
parent ee2993318f
commit 73d9c4ec29
3 changed files with 123 additions and 4 deletions

View File

@ -0,0 +1,116 @@
import SwiftUI
import SFSafeSymbols
struct InsertableVideo: View, InsertableCommandView {
final class Model: ObservableObject, InsertableCommandModel {
@Published
var posterImage: FileResource?
@Published
var videoH265: FileResource?
@Published
var videoH264: FileResource?
@Published
var videoWebm: FileResource?
@Published
var controls: Bool = false
@Published
var autoplay: Bool = false
@Published
var loop: Bool = false
@Published
var muted: Bool = false
@Published
var playsinline = false
@Published
var preload = false
var isReady: Bool {
videoH265 != nil || videoH264 != nil
}
init() {
}
var command: String? {
var lines: [String] = []
lines.append("```video")
if let posterImage {
lines.append("\(VideoBlock.Key.poster): \(posterImage.id)")
}
if let videoH265 {
lines.append("\(VideoBlock.Key.h265): \(videoH265.id)")
}
if let videoH264 {
lines.append("\(VideoBlock.Key.h264): \(videoH264.id)")
}
if let videoWebm {
lines.append("\(VideoBlock.Key.webm): \(videoWebm.id)")
}
if controls { lines.append(VideoBlock.Key.controls.rawValue) }
if autoplay { lines.append(VideoBlock.Key.autoplay.rawValue) }
if loop { lines.append(VideoBlock.Key.loop.rawValue) }
if muted { lines.append(VideoBlock.Key.muted.rawValue) }
if playsinline { lines.append(VideoBlock.Key.playsinline.rawValue) }
if preload { lines.append(VideoBlock.Key.preload.rawValue) }
lines.append("```")
return lines.joined(separator: "\n")
}
}
static let title = "Video"
static let sheetTitle = "Insert video"
static let icon: SFSymbol = .movieclapper
@ObservedObject
private var model: Model
init(model: Model) {
self.model = model
}
var body: some View {
VStack {
FilePropertyView(
title: "Video (h265)",
footer: "Select the video encoded using h265",
selectedFile: $model.videoH265,
allowedType: .video)
FilePropertyView(
title: "Video (h264)",
footer: "Select the video encoded using h264",
selectedFile: $model.videoH264,
allowedType: .video)
FilePropertyView(
title: "Poster image",
footer: "Select the image to show as the poster",
selectedFile: $model.posterImage,
allowedType: .image)
HStack {
Toggle("controls", isOn: $model.controls)
Toggle("autoplay", isOn: $model.autoplay)
Toggle("loop", isOn: $model.loop)
}
HStack {
Toggle("muted", isOn: $model.muted)
Toggle("playsinline", isOn: $model.playsinline)
Toggle("preload", isOn: $model.preload)
}
}
.toggleStyle(.checkbox)
}
}

View File

@ -4,9 +4,8 @@ struct InsertableItemsView: View {
var body: some View {
HStack {
Text("Commands")
.font(.headline)
InsertableView<InsertableImage>()
InsertableView<InsertableVideo>()
InsertableView<InsertableGallery>()
InsertableView<InsertableLabels>()
InsertableView<InsertableButtons>()