tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
28
pulls
pipelines
auto add youtube iframe w/ embed button
awarm.space
6 months ago
515933e3
3e0ed7c7
+84
-1
3 changed files
expand all
collapse all
unified
split
components
Blocks
TextBlock
index.tsx
lexicons
api
types
pub
leaflet
blocks
iframe.ts
pub
leaflet
blocks
iframe.json
+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
+
448
449
if (
449
450
!isLocked &&
450
451
focused &&
···
455
456
return (
456
457
<button
457
458
onClick={async (e) => {
459
459
+
if (!rep.rep) return;
458
460
rep.undoManager.startGroup();
459
459
-
if (isBlueskyPost && rep.rep) {
461
461
+
let isYoutubeUrl = editorState.doc.textContent.startsWith(
462
462
+
"https://www.youtube.com/watch?v=",
463
463
+
);
464
464
+
if (isYoutubeUrl) {
465
465
+
let url = new URL(editorState.doc.textContent);
466
466
+
let videoId = url.searchParams.get("v");
467
467
+
await rep.rep.mutate.assertFact([
468
468
+
{
469
469
+
entity: props.entityID,
470
470
+
attribute: "block/type",
471
471
+
data: { type: "block-type-union", value: "embed" },
472
472
+
},
473
473
+
{
474
474
+
entity: props.entityID,
475
475
+
attribute: "embed/url",
476
476
+
data: {
477
477
+
type: "string",
478
478
+
value: `https://youtube.com/embed/${videoId}`,
479
479
+
},
480
480
+
},
481
481
+
{
482
482
+
entity: props.entityID,
483
483
+
attribute: "embed/height",
484
484
+
data: {
485
485
+
type: "number",
486
486
+
value: 315,
487
487
+
},
488
488
+
},
489
489
+
]);
490
490
+
return;
491
491
+
}
492
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
1
+
/**
2
2
+
* GENERATED CODE - DO NOT MODIFY
3
3
+
*/
4
4
+
import { ValidationResult, BlobRef } from '@atproto/lexicon'
5
5
+
import { CID } from 'multiformats/cid'
6
6
+
import { validate as _validate } from '../../../../lexicons'
7
7
+
import { $Typed, is$typed as _is$typed, OmitKey } from '../../../../util'
8
8
+
9
9
+
const is$typed = _is$typed,
10
10
+
validate = _validate
11
11
+
const id = 'pub.leaflet.blocks.iframe'
12
12
+
13
13
+
export interface Main {
14
14
+
$type?: 'pub.leaflet.blocks.iframe'
15
15
+
url: string
16
16
+
height?: number
17
17
+
}
18
18
+
19
19
+
const hashMain = 'main'
20
20
+
21
21
+
export function isMain<V>(v: V) {
22
22
+
return is$typed(v, id, hashMain)
23
23
+
}
24
24
+
25
25
+
export function validateMain<V>(v: V) {
26
26
+
return validate<Main & V>(v, id, hashMain)
27
27
+
}
+23
lexicons/pub/leaflet/blocks/iframe.json
···
1
1
+
{
2
2
+
"lexicon": 1,
3
3
+
"id": "pub.leaflet.blocks.iframe",
4
4
+
"defs": {
5
5
+
"main": {
6
6
+
"type": "object",
7
7
+
"required": [
8
8
+
"url"
9
9
+
],
10
10
+
"properties": {
11
11
+
"url": {
12
12
+
"type": "string",
13
13
+
"format": "uri"
14
14
+
},
15
15
+
"height": {
16
16
+
"type": "integer",
17
17
+
"minimum": 16,
18
18
+
"maximum": 1600
19
19
+
}
20
20
+
}
21
21
+
}
22
22
+
}
23
23
+
}