-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): initial support for youtube and vimeo embed
- Loading branch information
Showing
8 changed files
with
238 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import type { ViewStateResult } from "obsidian"; | ||
import type { MediaRemoteViewState } from "./base"; | ||
import { MediaRemoteView } from "./base"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
export const MEDIA_EMBED_VIEW_TYPE = "mx-embed"; | ||
|
||
export type MediaEmbedViewState = MediaRemoteViewState; | ||
|
||
export const hostTitleMap: Record<string, string> = { | ||
"video/vimeo": "Vimeo", | ||
"video/youtube": "YouTube", | ||
}; | ||
|
||
export function isEmbedSrc(src: string) { | ||
return src.includes("youtube") || src.includes("vimeo"); | ||
} | ||
|
||
export class MediaEmbedView extends MediaRemoteView { | ||
async setState( | ||
state: MediaRemoteViewState, | ||
result: ViewStateResult, | ||
): Promise<void> { | ||
if (typeof state.source === "string") { | ||
this.store.setState({ source: { src: state.source } }); | ||
} | ||
return super.setState(state, result); | ||
} | ||
getState(): MediaRemoteViewState { | ||
const fromStore = this.store.getState(); | ||
const state = super.getState(); | ||
return { | ||
...state, | ||
source: fromStore.source?.src, | ||
}; | ||
} | ||
getDisplayText(): string { | ||
const source = hostTitleMap[this._sourceType] ?? "Embed"; | ||
if (!this._title) return source; | ||
return `${this._title} - ${source}`; | ||
} | ||
getIcon(): string { | ||
return this._sourceType === "video/youtube" ? "youtube" : "video"; | ||
} | ||
getViewType(): string { | ||
return MEDIA_EMBED_VIEW_TYPE; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.