a tool for shared writing and social publishing

auto add youtube iframe w/ embed button

+84 -1
+34 -1
components/Blocks/TextBlock/index.tsx
··· 445 445 editorState?.doc.textContent.includes("post"); 446 446 // only if the line stats with http or https and doesn't have other content 447 447 // if its bluesky, change text to embed post 448 + 448 449 if ( 449 450 !isLocked && 450 451 focused && ··· 455 456 return ( 456 457 <button 457 458 onClick={async (e) => { 459 + if (!rep.rep) return; 458 460 rep.undoManager.startGroup(); 459 - if (isBlueskyPost && rep.rep) { 461 + let isYoutubeUrl = editorState.doc.textContent.startsWith( 462 + "https://www.youtube.com/watch?v=", 463 + ); 464 + if (isYoutubeUrl) { 465 + let url = new URL(editorState.doc.textContent); 466 + let videoId = url.searchParams.get("v"); 467 + await rep.rep.mutate.assertFact([ 468 + { 469 + entity: props.entityID, 470 + attribute: "block/type", 471 + data: { type: "block-type-union", value: "embed" }, 472 + }, 473 + { 474 + entity: props.entityID, 475 + attribute: "embed/url", 476 + data: { 477 + type: "string", 478 + value: `https://youtube.com/embed/${videoId}`, 479 + }, 480 + }, 481 + { 482 + entity: props.entityID, 483 + attribute: "embed/height", 484 + data: { 485 + type: "number", 486 + value: 315, 487 + }, 488 + }, 489 + ]); 490 + return; 491 + } 492 + if (isBlueskyPost) { 460 493 let success = await addBlueskyPostBlock( 461 494 editorState.doc.textContent, 462 495 props.entityID,
+27
lexicons/api/types/pub/leaflet/blocks/iframe.ts
··· 1 + /** 2 + * GENERATED CODE - DO NOT MODIFY 3 + */ 4 + import { ValidationResult, BlobRef } from '@atproto/lexicon' 5 + import { CID } from 'multiformats/cid' 6 + import { validate as _validate } from '../../../../lexicons' 7 + import { $Typed, is$typed as _is$typed, OmitKey } from '../../../../util' 8 + 9 + const is$typed = _is$typed, 10 + validate = _validate 11 + const id = 'pub.leaflet.blocks.iframe' 12 + 13 + export interface Main { 14 + $type?: 'pub.leaflet.blocks.iframe' 15 + url: string 16 + height?: number 17 + } 18 + 19 + const hashMain = 'main' 20 + 21 + export function isMain<V>(v: V) { 22 + return is$typed(v, id, hashMain) 23 + } 24 + 25 + export function validateMain<V>(v: V) { 26 + return validate<Main & V>(v, id, hashMain) 27 + }
+23
lexicons/pub/leaflet/blocks/iframe.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "pub.leaflet.blocks.iframe", 4 + "defs": { 5 + "main": { 6 + "type": "object", 7 + "required": [ 8 + "url" 9 + ], 10 + "properties": { 11 + "url": { 12 + "type": "string", 13 + "format": "uri" 14 + }, 15 + "height": { 16 + "type": "integer", 17 + "minimum": 16, 18 + "maximum": 1600 19 + } 20 + } 21 + } 22 + } 23 + }