-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathiframe.ts
More file actions
86 lines (84 loc) · 2.24 KB
/
iframe.ts
File metadata and controls
86 lines (84 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { DOMOutputSpec } from 'prosemirror-model';
import { pruneFalsyValues } from 'utils/arrays';
import { withValue } from 'utils/fp';
import { buildLabel } from '../utils/references';
import { renderHtmlChildren } from '../utils/renderHtml';
import { counter } from './reactive/counter';
import { label } from './reactive/label';
export default {
iframe: {
atom: true,
reactive: true,
attrs: {
id: { default: null },
url: { default: '' },
size: { default: 75 }, // number as percentage
height: { default: 419 },
align: { default: 'center' },
caption: { default: '' },
hideLabel: { default: false },
},
reactiveAttrs: {
count: counter({ useNodeLabels: true }),
label: label(),
},
parseDOM: [
{
tag: 'figure',
getAttrs: (node) => {
if (node.getAttribute('data-node-type') !== 'iframe') {
return false;
}
return {
id: node.getAttribute('id') || null,
url: node.firstChild.getAttribute('src') || null,
size: Number(node.getAttribute('data-size')) || 75,
height: Number(node.firstChild.getAttribute('height')) || 419,
align: node.getAttribute('data-align') || 'center',
caption: node.firstChild.getAttribute('alt') || '',
hideLabel: node.getAttribute('data-hide-label') || '',
};
},
},
],
toDOM: (node, { isStaticallyRendered } = { isStaticallyRendered: false }) => {
const figcaptionId = `${node.attrs.id}-figure-caption`;
return [
'figure',
{
...(node.attrs.id && { id: node.attrs.id }),
'data-node-type': 'iframe',
'data-size': node.attrs.size,
'data-align': node.attrs.align,
'data-hide-label': node.attrs.hideLabel,
},
[
'iframe',
{
alt: node.attrs.caption,
src: node.attrs.url,
height: node.attrs.height,
'aria-describedby': figcaptionId,
allowfullscreen: 'true',
},
],
[
'figcaption',
{ id: figcaptionId },
pruneFalsyValues([
'div',
{},
withValue(buildLabel(node), (builtLabel) => [
'strong',
{ spellcheck: 'false' },
builtLabel,
]),
renderHtmlChildren(isStaticallyRendered, node.attrs.caption, 'div'),
]),
],
] as DOMOutputSpec;
},
inline: false,
group: 'block',
},
};