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
|
/* eslint-disable prefer-destructuring */
/* eslint-disable default-param-last */
/* eslint-disable no-use-before-define */
import { Doc, DocListCast } from '../../fields/Doc';
import { InkField } from '../../fields/InkField';
import { List } from '../../fields/List';
import { AudioField, ImageField, PdfField, VideoField } from '../../fields/URLField';
import { InkingStroke } from '../views/InkingStroke';
import { CollectionView } from '../views/collections/CollectionView';
import { AudioBox } from '../views/nodes/AudioBox';
import { ImageBox } from '../views/nodes/ImageBox';
import { PDFBox } from '../views/nodes/PDFBox';
import { VideoBox } from '../views/nodes/VideoBox';
import { FormattedTextBox } from '../views/nodes/formattedText/FormattedTextBox';
import { Docs, DocumentOptions } from './Documents';
export function DocumentFromField(target: Doc, fieldKey: string, proto?: Doc, options?: DocumentOptions): Doc | undefined {
let created: Doc | undefined;
const field = target[fieldKey];
const resolved = options ?? {};
if (field instanceof ImageField) {
created = Docs.Create.ImageDocument(field.url.href, resolved);
created.layout = ImageBox.LayoutString(fieldKey);
} else if (field instanceof Doc) {
created = field;
} else if (field instanceof VideoField) {
created = Docs.Create.VideoDocument(field.url.href, resolved);
created.layout = VideoBox.LayoutString(fieldKey);
} else if (field instanceof PdfField) {
created = Docs.Create.PdfDocument(field.url.href, resolved);
created.layout = PDFBox.LayoutString(fieldKey);
} else if (field instanceof AudioField) {
created = Docs.Create.AudioDocument(field.url.href, resolved);
created.layout = AudioBox.LayoutString(fieldKey);
} else if (field instanceof InkField) {
created = Docs.Create.InkDocument(field.inkData, resolved);
created.layout = InkingStroke.LayoutString(fieldKey);
} else if (field instanceof List && field[0] instanceof Doc) {
created = Docs.Create.StackingDocument(DocListCast(field), resolved);
created.layout = CollectionView.LayoutString(fieldKey);
} else {
created = Docs.Create.TextDocument('', { ...{ _width: 200, _height: 25, _layout_autoHeight: true }, ...resolved });
created.layout = FormattedTextBox.LayoutString(fieldKey);
}
if (created) {
created.title = fieldKey;
proto && created.proto && (created.proto = Doc.GetProto(proto));
}
return created;
}
|