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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
import { Document } from "../fields/Document";
import { KeyStore } from "../fields/Key";
import { TextField } from "../fields/TextField";
import { NumberField } from "../fields/NumberField";
import { ListField } from "../fields/ListField";
import { FieldTextBox } from "../views/nodes/FieldTextBox";
import { CollectionDockingView } from "../views/collections/CollectionDockingView";
interface DocumentOptions {
x?: number;
y?: number;
width?: number;
height?: number;
title?: string;
}
export namespace Documents {
function setupOptions(doc: Document, options: DocumentOptions): void {
if (options.x) {
doc.SetFieldValue(KeyStore.X, options.x, NumberField);
}
if (options.y) {
doc.SetFieldValue(KeyStore.Y, options.y, NumberField);
}
if (options.width) {
doc.SetFieldValue(KeyStore.Width, options.width, NumberField);
}
if (options.height) {
doc.SetFieldValue(KeyStore.Height, options.height, NumberField);
}
if (options.title) {
doc.SetFieldValue(KeyStore.Title, options.title, TextField);
}
doc.SetFieldValue(KeyStore.Scale, 1, NumberField);
doc.SetFieldValue(KeyStore.PanX, 0, NumberField);
doc.SetFieldValue(KeyStore.PanY, 0, NumberField);
}
let textProto: Document;
function GetTextPrototype(): Document {
if (!textProto) {
textProto = new Document();
textProto.SetField(KeyStore.X, new NumberField(0));
textProto.SetField(KeyStore.Y, new NumberField(0));
textProto.SetField(KeyStore.Width, new NumberField(300));
textProto.SetField(KeyStore.Height, new NumberField(150));
textProto.SetField(KeyStore.Layout, new TextField(FieldTextBox.LayoutString()));
textProto.SetField(KeyStore.LayoutKeys, new ListField([ KeyStore.Data ]));
}
return textProto;
}
export function TextDocument(text: string, options: DocumentOptions = {}): Document {
let doc = GetTextPrototype().MakeDelegate();
setupOptions(doc, options);
// doc.SetField(KeyStore.Data, new TextField(text));
return doc;
}
let dockProto: Document;
function GetDockPrototype(): Document {
if (!dockProto) {
dockProto = new Document();
dockProto.SetField(KeyStore.X, new NumberField(0));
dockProto.SetField(KeyStore.Y, new NumberField(0));
dockProto.SetField(KeyStore.Width, new NumberField(300));
dockProto.SetField(KeyStore.Height, new NumberField(150));
dockProto.SetField(KeyStore.Layout, new TextField(CollectionDockingView.LayoutString()));
dockProto.SetField(KeyStore.LayoutKeys, new ListField([ KeyStore.Data ]));
}
return dockProto;
}
export function DockDocument(documents: Array<Document>, options: DocumentOptions = {}): Document {
let doc = GetDockPrototype().MakeDelegate();
setupOptions(doc, options);
doc.SetField(KeyStore.Data, new ListField(documents));
return doc;
}
let imageProto: Document;
function GetImagePrototype(): Document {
if (!imageProto) {
imageProto = new Document();
imageProto.SetField(KeyStore.X, new NumberField(0));
imageProto.SetField(KeyStore.Y, new NumberField(0));
imageProto.SetField(KeyStore.Width, new NumberField(300));
imageProto.SetField(KeyStore.Height, new NumberField(300));
imageProto.SetField(KeyStore.Layout, new TextField('<img src={Data} draggable="false" width="100%" alt="Image not found"/>'));
// imageProto.SetField(KeyStore.Layout, new TextField('<div style={"background-image: " + {Data}} />'));
imageProto.SetField(KeyStore.LayoutFields, new ListField([ KeyStore.Data ]));
}
return imageProto;
}
export function ImageDocument(url: string, options: DocumentOptions = {}): Document {
let doc = GetImagePrototype().MakeDelegate();
setupOptions(doc, options);
doc.SetField(KeyStore.Data, new TextField(url));
return doc;
}
let collectionProto: Document;
function GetCollectionPrototype(): Document {
if (!collectionProto) {
collectionProto = new Document();
collectionProto.SetField(KeyStore.X, new NumberField(0));
collectionProto.SetField(KeyStore.Y, new NumberField(0));
collectionProto.SetField(KeyStore.Scale, new NumberField(1));
collectionProto.SetField(KeyStore.PanX, new NumberField(0));
collectionProto.SetField(KeyStore.PanY, new NumberField(0));
collectionProto.SetField(KeyStore.Width, new NumberField(300));
collectionProto.SetField(KeyStore.Height, new NumberField(300));
collectionProto.SetField(KeyStore.Layout, new TextField('<CollectionFreeFormView Document={Document} fieldKey={DataKey} ContainingDocumentView={ContainingDocumentView}/>'));
collectionProto.SetField(KeyStore.LayoutKeys, new ListField([ KeyStore.Data ]));
}
return collectionProto;
}
export function CollectionDocument(documents: Array<Document>, options: DocumentOptions = {}): Document {
let doc = GetCollectionPrototype().MakeDelegate();
setupOptions(doc, options);
doc.SetField(KeyStore.Data, new ListField(documents));
return doc;
}
}
|