jpf 4.2.15 → 4.2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/controls/codeMirror/HtmlEditor/HtmlEditor.d.ts +2 -1
  2. package/dist/controls/codeMirror/HtmlEditor/HtmlEditor.js +4 -0
  3. package/dist/controls/codeMirror/HtmlEditor/HtmlEditor.js.map +1 -1
  4. package/dist/controls/codeMirror/JsonEditor/JsonEditor.d.ts +2 -1
  5. package/dist/controls/codeMirror/JsonEditor/JsonEditor.js +4 -0
  6. package/dist/controls/codeMirror/JsonEditor/JsonEditor.js.map +1 -1
  7. package/dist/controls/custom/FileSelector/FileSelector.d.ts +2 -1
  8. package/dist/controls/custom/FileSelector/FileSelector.js +4 -0
  9. package/dist/controls/custom/FileSelector/FileSelector.js.map +1 -1
  10. package/dist/controls/custom/LabeledControl/LabeledControl.d.ts +2 -1
  11. package/dist/controls/custom/LabeledControl/LabeledControl.js +4 -0
  12. package/dist/controls/custom/LabeledControl/LabeledControl.js.map +1 -1
  13. package/dist/controls/custom/ListItem/ListItem.d.ts +4 -2
  14. package/dist/controls/custom/ListItem/ListItem.js +8 -0
  15. package/dist/controls/custom/ListItem/ListItem.js.map +1 -1
  16. package/dist/controls/html/Button/Button.d.ts +2 -1
  17. package/dist/controls/html/Button/Button.js +4 -0
  18. package/dist/controls/html/Button/Button.js.map +1 -1
  19. package/dist/controls/html/Div/Div.d.ts +2 -1
  20. package/dist/controls/html/Div/Div.js +4 -0
  21. package/dist/controls/html/Div/Div.js.map +1 -1
  22. package/dist/controls/html/Image/Image.d.ts +2 -1
  23. package/dist/controls/html/Image/Image.js +4 -0
  24. package/dist/controls/html/Image/Image.js.map +1 -1
  25. package/dist/controls/html/Input/Input.d.ts +2 -1
  26. package/dist/controls/html/Input/Input.js +4 -0
  27. package/dist/controls/html/Input/Input.js.map +1 -1
  28. package/dist/controls/html/Select/Select.d.ts +2 -1
  29. package/dist/controls/html/Select/Select.js +4 -0
  30. package/dist/controls/html/Select/Select.js.map +1 -1
  31. package/dist/controls/html/Span/Span.d.ts +2 -1
  32. package/dist/controls/html/Span/Span.js +4 -0
  33. package/dist/controls/html/Span/Span.js.map +1 -1
  34. package/dist/controls/jsonViewAwesome/jsonFormatter/JsonFormatter.d.ts +2 -1
  35. package/dist/controls/jsonViewAwesome/jsonFormatter/JsonFormatter.js +4 -0
  36. package/dist/controls/jsonViewAwesome/jsonFormatter/JsonFormatter.js.map +1 -1
  37. package/dist/controls/kendo/Editor/Editor.d.ts +2 -1
  38. package/dist/controls/kendo/Editor/Editor.js +4 -0
  39. package/dist/controls/kendo/Editor/Editor.js.map +1 -1
  40. package/dist/controls/kendo/Grid/Grid.d.ts +2 -1
  41. package/dist/controls/kendo/Grid/Grid.js +4 -0
  42. package/dist/controls/kendo/Grid/Grid.js.map +1 -1
  43. package/dist/controls/kendo/Menu/Menu.js.map +1 -1
  44. package/dist/controls/leaflet/Map/Map.d.ts +2 -1
  45. package/dist/controls/leaflet/Map/Map.js +4 -0
  46. package/dist/controls/leaflet/Map/Map.js.map +1 -1
  47. package/dist/framework/ViewModel.d.ts +2 -2
  48. package/dist/framework/ViewModel.js +2 -2
  49. package/dist/framework/ViewModel.js.map +1 -1
  50. package/package.json +3 -2
  51. package/src/controls/codeMirror/HtmlEditor/HtmlEditor.ts +153 -0
  52. package/src/controls/codeMirror/JsonEditor/JsonEditor.ts +136 -0
  53. package/src/controls/codeMirror/index.ts +2 -0
  54. package/src/controls/custom/FileSelector/FileSelector.ts +74 -0
  55. package/src/controls/custom/LabeledControl/LabeledControl.ts +58 -0
  56. package/src/controls/custom/ListItem/ListItem.ts +99 -0
  57. package/src/controls/custom/index.ts +3 -0
  58. package/src/controls/html/Button/Button.ts +70 -0
  59. package/src/controls/html/Div/Div.ts +41 -0
  60. package/src/controls/html/Image/Image.ts +46 -0
  61. package/src/controls/html/Input/Input.ts +228 -0
  62. package/src/controls/html/Select/Select.ts +146 -0
  63. package/src/controls/html/Span/Span.ts +38 -0
  64. package/src/controls/html/index.ts +6 -0
  65. package/src/controls/index.ts +15 -0
  66. package/src/controls/jsonViewAwesome/index.ts +1 -0
  67. package/src/controls/jsonViewAwesome/jsonFormatter/JsonFormatter.ts +91 -0
  68. package/src/controls/kendo/Chart/Chart.ts +97 -0
  69. package/src/controls/kendo/Culture/Culture.ts +32 -0
  70. package/src/controls/kendo/DataSource/DataSource.ts +4 -0
  71. package/src/controls/kendo/Dialog/Dialog.ts +64 -0
  72. package/src/controls/kendo/Editor/Editor.ts +142 -0
  73. package/src/controls/kendo/Grid/Grid.ts +291 -0
  74. package/src/controls/kendo/Menu/Menu.ts +125 -0
  75. package/src/controls/kendo/ObservableObject/ObservableObject.ts +45 -0
  76. package/src/controls/kendo/Tree/Tree.ts +147 -0
  77. package/src/controls/kendo/index.ts +9 -0
  78. package/src/controls/leaflet/LabelControl/LabelControl.ts +42 -0
  79. package/src/controls/leaflet/Map/Map.ts +180 -0
  80. package/src/controls/leaflet/OpenStreetMapTileLayer/OpenStreetMapTileLayer.ts +19 -0
  81. package/src/controls/leaflet/PointerEvent/PointerEvent.ts +9 -0
  82. package/src/controls/leaflet/index.ts +4 -0
  83. package/src/controls/svg/Circle/Circle.ts +34 -0
  84. package/src/controls/svg/Ellipse/Ellipse.ts +36 -0
  85. package/src/controls/svg/ForeignObject/ForeignObject.ts +38 -0
  86. package/src/controls/svg/Group/Group.ts +38 -0
  87. package/src/controls/svg/Line/Line.ts +36 -0
  88. package/src/controls/svg/Pattern/Pattern.ts +49 -0
  89. package/src/controls/svg/Polygon/Polygon.ts +31 -0
  90. package/src/controls/svg/Polyline/Polyline.ts +31 -0
  91. package/src/controls/svg/Rectangle/Rectangle.ts +36 -0
  92. package/src/controls/svg/Svg/Svg.ts +43 -0
  93. package/src/controls/svg/Text/Text.ts +38 -0
  94. package/src/controls/svg/Title/Title.ts +28 -0
  95. package/src/controls/svg/index.ts +13 -0
  96. package/src/controls/svg/svg.ts +20 -0
  97. package/src/framework/View.ts +213 -0
  98. package/src/framework/ViewModel.ts +525 -0
  99. package/src/framework/attributes.ts +92 -0
  100. package/src/framework/event.ts +98 -0
  101. package/src/framework/observable.ts +80 -0
  102. package/src/framework/style.ts +3271 -0
  103. package/src/framework/types.ts +277 -0
  104. package/src/framework/userAgent.ts +51 -0
  105. package/src/index.ts +14 -0
  106. package/src/utilities/blob/blob.ts +19 -0
  107. package/src/utilities/cookie/cookie.ts +28 -0
  108. package/src/utilities/dataReaderTable/dataReaderTable.ts +34 -0
  109. package/src/utilities/fetch/fetch.ts +179 -0
  110. package/src/utilities/float/float.ts +3 -0
  111. package/src/utilities/formData/formData.ts +12 -0
  112. package/src/utilities/html/html.ts +8 -0
  113. package/src/utilities/htmlElement/htmlElement.ts +15 -0
  114. package/src/utilities/image/image.ts +1 -0
  115. package/src/utilities/index.ts +37 -0
  116. package/src/utilities/integer/integer.ts +31 -0
  117. package/src/utilities/key/key.ts +7 -0
  118. package/src/utilities/navigator/navigator.ts +7 -0
  119. package/src/utilities/notification/notification.ts +88 -0
  120. package/src/utilities/querystring/querystring.ts +61 -0
  121. package/src/utilities/router/router.ts +124 -0
  122. package/src/utilities/stylesheet/stylesheet.ts +58 -0
  123. package/src/utilities/uniqueId/uniqueId.ts +5 -0
  124. package/src/utilities/webSocket/webSocket.ts +72 -0
@@ -0,0 +1,70 @@
1
+ import { unwrap, Subscribable, isSubscribable } from "knockout";
2
+ import { ViewModel, Properties, extendProperties } from "../../../framework/ViewModel"
3
+ import { View, getView, registerView } from "../../../framework/View";
4
+
5
+ export interface ButtonProperties extends Properties {
6
+ content?: string | ViewModel | Subscribable<string | ViewModel>;
7
+ }
8
+
9
+ export class ButtonView extends View<ButtonProperties> {
10
+ constructor(properties: ButtonProperties) {
11
+ super(
12
+ {
13
+ tagName: "button",
14
+ properties: extendProperties(
15
+ {
16
+ viewType: "Button"
17
+ },
18
+ properties
19
+ )
20
+ }
21
+ );
22
+ }
23
+
24
+ build(): void {
25
+ super.build();
26
+
27
+ const viewModel = this.properties;
28
+ if (viewModel.content) {
29
+ if (isSubscribable(viewModel.content)) {
30
+ this.buildContent(unwrap(viewModel.content));
31
+ this.subscriptions.push(
32
+ viewModel.content.subscribe((content) => {
33
+ this.buildContent(content);
34
+ })
35
+ );
36
+ } else {
37
+ this.buildContent(viewModel.content);
38
+ }
39
+ }
40
+ }
41
+
42
+ private buildContent(content: string | ViewModel) {
43
+ if (content == null || content === undefined) {
44
+ this.element.innerText = null;
45
+ }
46
+ else if (typeof content === "string") {
47
+ this.element.innerText = content;
48
+ }
49
+ else if (content instanceof ViewModel) {
50
+ this.setChildren(getView(content as ViewModel));
51
+ }
52
+ }
53
+ }
54
+
55
+ export function buttonView(properties: ButtonProperties): ButtonView {
56
+ return new ButtonView(properties);
57
+ }
58
+
59
+ export class ButtonViewModel extends ViewModel implements ButtonProperties{
60
+ constructor(properties: ButtonProperties) {
61
+ super();
62
+ this.setProperties(this, properties);
63
+ }
64
+ content?: string | ViewModel | Subscribable<string | ViewModel>;
65
+ }
66
+
67
+ registerView(
68
+ ButtonViewModel,
69
+ ButtonView
70
+ );
@@ -0,0 +1,41 @@
1
+ import { View, IView, registerView } from "../../../framework/View";
2
+ import { Properties , extendProperties, ViewModel } from "../../../framework/ViewModel";
3
+ import { Subscribable } from "knockout";
4
+
5
+ export interface DivProperties extends Properties {
6
+ children?: Array<IView> | Subscribable<Array<IView>>;
7
+ }
8
+
9
+ export class DivView extends View<DivProperties> {
10
+ constructor(properties: DivProperties) {
11
+ super(
12
+ {
13
+ tagName: "div",
14
+ properties: extendProperties(
15
+ {
16
+ viewType: "Div"
17
+ },
18
+ properties
19
+ ),
20
+ children: properties.children
21
+ },
22
+ );
23
+ }
24
+ }
25
+
26
+ export function divView(properties: DivProperties): DivView {
27
+ return new DivView(properties);
28
+ }
29
+
30
+ export class DivViewModel extends ViewModel implements DivProperties{
31
+ constructor(properties: DivProperties) {
32
+ super();
33
+ this.setProperties(this, properties);
34
+ }
35
+ children?: Array<IView> | Subscribable<Array<IView>>;
36
+ }
37
+
38
+ registerView(
39
+ DivViewModel,
40
+ DivView
41
+ )
@@ -0,0 +1,46 @@
1
+ import { View, registerView } from "../../../framework/View";
2
+ import { ViewModel, Properties, extendProperties } from "../../../framework/ViewModel";
3
+ import { Subscribable } from "knockout";
4
+
5
+ export interface ImageProperties extends Properties {
6
+ src: string | Subscribable<string>;
7
+ alt: string | Subscribable<string>;
8
+ }
9
+
10
+ export class ImageView extends View<ImageProperties> {
11
+ constructor(properties: ImageProperties) {
12
+ super(
13
+ {
14
+ tagName: "img",
15
+ properties: extendProperties(
16
+ {
17
+ viewType: "Image",
18
+ attributes: {
19
+ src: properties.src,
20
+ alt: properties.alt
21
+ }
22
+ },
23
+ properties
24
+ )
25
+ }
26
+ );
27
+ }
28
+ }
29
+
30
+ export function imageView(properties: ImageProperties) {
31
+ return new ImageView(properties);
32
+ }
33
+
34
+ export class ImageViewModel extends ViewModel implements ImageProperties{
35
+ constructor(properties: ImageProperties) {
36
+ super();
37
+ this.setProperties(this, properties);
38
+ }
39
+ src: string | Subscribable<string>;
40
+ alt: string | Subscribable<string>;
41
+ }
42
+
43
+ registerView(
44
+ ImageViewModel,
45
+ ImageView
46
+ );
@@ -0,0 +1,228 @@
1
+ import { isSubscribable, unwrap, isObservable } from "knockout";
2
+ import { View, registerView } from "../../../framework/View";
3
+ import { ViewModel, Properties, extendProperties, isNullOrUndefined } from "../../../framework/ViewModel";
4
+ import { ObservableProperty, observableProperty, isObservableProperty } from "../../../framework/observable";
5
+ import { isInteger } from "../../../utilities/integer/integer";
6
+ import { isFloat } from "../../../utilities/float/float";
7
+
8
+
9
+ export type InputType = "text" | "checkbox" | "file" | "integer" | "float" | "range" | "radio";
10
+
11
+ export enum ValueUpdateModeEnum {
12
+ OnChange = 1,
13
+ OnInput = 2
14
+ }
15
+
16
+ export interface InputProperties<TValue> extends Properties {
17
+ value?: TValue | ObservableProperty<TValue>;
18
+ inputValidator?: (event: Event, inputViewModel: InputProperties<TValue>, value: string) => Promise<boolean>;
19
+ placeholder?: string | ObservableProperty<string>;
20
+ valueUpdateMode?: ValueUpdateModeEnum;
21
+ min?: number;
22
+ max?: number;
23
+ step?: number;
24
+ type?: InputType;
25
+ }
26
+
27
+ export class InputView<TValue> extends View<InputProperties<TValue>> {
28
+ constructor(properties: InputProperties<TValue>) {
29
+ super(
30
+ {
31
+ tagName: "input",
32
+ properties: extendProperties(
33
+ {
34
+ viewType: "Input"
35
+ },
36
+ properties
37
+ )
38
+ }
39
+ );
40
+ }
41
+
42
+ //Protected members
43
+ protected build() {
44
+ super.build();
45
+
46
+ const element = this.element;
47
+ const viewModel = this.properties;
48
+ if (!viewModel.valueUpdateMode) {
49
+ viewModel.valueUpdateMode = ValueUpdateModeEnum.OnChange;
50
+ }
51
+
52
+ const input = this.element as HTMLInputElement;
53
+ input.type = viewModel.type;
54
+
55
+ if (!isNullOrUndefined(viewModel.min)) {
56
+ input.min = viewModel.min as any;
57
+ }
58
+ if (!isNullOrUndefined(viewModel.max)) {
59
+ input.max = viewModel.max as any;
60
+ }
61
+ if (!isNullOrUndefined(viewModel.step)) {
62
+ input.step = viewModel.step as any;
63
+ }
64
+
65
+ switch (viewModel.type) {
66
+ case "checkbox":
67
+ input.checked = unwrap(viewModel.value) as unknown as boolean;
68
+ if (isObservable(viewModel.value)) {
69
+ this.subscriptions.push(
70
+ viewModel.value.subscribe((value: TValue) => {
71
+ input.checked = value as unknown as boolean;
72
+ })
73
+ );
74
+ }
75
+
76
+ break;
77
+
78
+ case "file":
79
+ //An input type file can not be set.
80
+ break;
81
+
82
+ case "radio":
83
+ input.checked = input.value === unwrap(viewModel.value);
84
+ if (isSubscribable(viewModel.value)) {
85
+ this.subscriptions.push(
86
+ viewModel.value.subscribe((value) => {
87
+ input.checked = input.value === (value as any as string);
88
+ })
89
+ );
90
+ }
91
+ break;
92
+
93
+ default:
94
+ const value = unwrap(viewModel.value);
95
+ if (value) {
96
+ input.value = value as unknown as string;
97
+ }
98
+ if (isObservable(viewModel.value)) {
99
+ this.subscriptions.push(
100
+ viewModel.value.subscribe((value: TValue) => {
101
+ input.value = value as unknown as string;
102
+ })
103
+ );
104
+ }
105
+ }
106
+
107
+ const placeholder = unwrap(viewModel.placeholder) as unknown as string;
108
+ if (placeholder) {
109
+ input.placeholder = placeholder;
110
+ }
111
+ if (isSubscribable(viewModel.placeholder)) {
112
+ this.subscriptions.push(
113
+ viewModel.placeholder.subscribe((placeholder) => {
114
+ if (placeholder) {
115
+ input.placeholder = placeholder;
116
+ } else {
117
+ input.removeAttribute("placeholder");
118
+ }
119
+ })
120
+ );
121
+ }
122
+
123
+ if (this.properties.valueUpdateMode === ValueUpdateModeEnum.OnChange) {
124
+ this.element.addEventListener(
125
+ "change",
126
+ handleEvent
127
+ );
128
+ }
129
+
130
+ if (this.properties.valueUpdateMode === ValueUpdateModeEnum.OnInput || viewModel.inputValidator) {
131
+ this.element.addEventListener(
132
+ "input",
133
+ handleEvent
134
+ );
135
+ }
136
+
137
+ async function handleEvent(event: Event) {
138
+ let newValue = null;
139
+ switch (viewModel.type) {
140
+ case "checkbox":
141
+ newValue = input.checked;
142
+ break;
143
+
144
+ case "file":
145
+ newValue = input.files;
146
+ break;
147
+
148
+ case "radio":
149
+ const name = element.getAttribute("name");
150
+ if (name) {
151
+ const selectedRadioButton = document.querySelector("input[type='radio'][name='" + name + "']:checked") as HTMLInputElement;
152
+ if (selectedRadioButton) {
153
+ newValue = selectedRadioButton.value;
154
+ }
155
+ }
156
+ break;
157
+
158
+ default:
159
+ newValue = input.value as any as TValue;
160
+ if (newValue + "" === "") {
161
+ newValue = null;
162
+ }
163
+ }
164
+
165
+ if (viewModel.inputValidator) {
166
+ if (!await viewModel.inputValidator(event, viewModel, newValue as any as string)) {
167
+ input.value = unwrap(viewModel.value) as any as string;
168
+ return;
169
+ };
170
+ }
171
+
172
+ if (viewModel.type === "integer") {
173
+ if (isInteger(newValue)) {
174
+ newValue = parseInt(newValue);
175
+ } else {
176
+ input.value = unwrap(viewModel.value) as any as string;
177
+ return;
178
+ }
179
+ }
180
+
181
+ if (viewModel.type === "float") {
182
+ if (isFloat(newValue)) {
183
+ newValue = parseFloat(newValue);
184
+ } else {
185
+ input.value = unwrap(viewModel.value) as any as string;
186
+ return;
187
+ }
188
+ }
189
+
190
+ //if validation has succeeded we set the viewModel value
191
+ if (isObservableProperty(viewModel.value)) {
192
+ if ((event.type === "change" && viewModel.valueUpdateMode === ValueUpdateModeEnum.OnChange) ||
193
+ (event.type === "input" && viewModel.valueUpdateMode === ValueUpdateModeEnum.OnInput)) {
194
+ viewModel.value.set(newValue);
195
+ } else {
196
+ viewModel.value.set(newValue, false);
197
+ }
198
+ } else if (isObservable(viewModel.value)) {
199
+ viewModel.value(newValue);
200
+ }
201
+ }
202
+ }
203
+ }
204
+
205
+ export function inputView<TValue>(properties: InputProperties<TValue>) {
206
+ return new InputView<TValue>(properties);
207
+ }
208
+
209
+ export class InputViewModel<TValue> extends ViewModel implements InputProperties<TValue> {
210
+ constructor(properties: InputProperties<TValue>) {
211
+ super();
212
+ this.setProperties(this, properties);
213
+ }
214
+
215
+ value?: TValue | ObservableProperty<TValue>;
216
+ inputValidator?: (event: Event, inputViewModel: InputProperties<TValue>, value: string) => Promise<boolean>;
217
+ placeholder?: string | ObservableProperty<string>;
218
+ valueUpdateMode?: ValueUpdateModeEnum;
219
+ min?: number;
220
+ max?: number;
221
+ step?: number;
222
+ type?: InputType;
223
+ }
224
+
225
+ registerView(
226
+ InputViewModel,
227
+ InputView
228
+ );
@@ -0,0 +1,146 @@
1
+ import { unwrap, isSubscribable } from "knockout";
2
+ import { View, registerView } from "../../../framework/View";
3
+ import { ViewModel, Properties, extendProperties } from "../../../framework/ViewModel";
4
+ import { ObservableProperty, ObservableArrayProperty, isObservableProperty, observableArrayProperty, observableProperty } from "../../../framework/observable";
5
+
6
+ export interface SelectProperties<TItem, TValue, TSetter = TValue> extends Properties {
7
+ value?: TValue | ObservableProperty<TValue, TSetter>;
8
+ items?: Array<TItem> | ObservableArrayProperty<TItem>;
9
+ textFunction: (item: TItem) => string;
10
+ valueFunction: (item: TItem) => TValue;
11
+ setFunction?: (item: TItem) => TSetter;
12
+ inputValidator?: (event: Event, selectViewModel: SelectProperties<TItem, TValue, TSetter>, value: TValue) => Promise<boolean>;
13
+ emptyItemText?: string;
14
+ }
15
+
16
+ export class SelectView<TItem, TValue, TSetter = TValue> extends View<SelectProperties<TItem, TValue, TSetter>> {
17
+ constructor(properties: SelectProperties<TItem, TValue, TSetter>) {
18
+ super(
19
+ {
20
+ tagName: "select",
21
+ properties: extendProperties(
22
+ {
23
+ viewType: "Select"
24
+ },
25
+ properties
26
+ )
27
+ }
28
+ );
29
+ }
30
+
31
+ //Protected members
32
+ protected build() {
33
+ super.build();
34
+ const select = this.element as HTMLSelectElement;
35
+
36
+ const viewModel = this.properties;
37
+
38
+ this.setItems(unwrap(viewModel.items) as Array<TItem>);
39
+ if (isSubscribable(viewModel.items)) {
40
+ this.subscriptions.push(
41
+ viewModel.items.subscribe((items) => {
42
+ this.setItems(items);
43
+ })
44
+ );
45
+ }
46
+
47
+ this.setSelectedValue(unwrap(viewModel.value) as TValue);
48
+ if (isSubscribable(viewModel.value)) {
49
+ this.subscriptions.push(
50
+ viewModel.value.subscribe((value) => {
51
+ this.setSelectedValue(value);
52
+ })
53
+ );
54
+ }
55
+
56
+ this.element.addEventListener(
57
+ "change",
58
+ async (event: Event) => {
59
+ let selectedValue = select.value as any as TValue;
60
+ let selectedItem: TItem = null;
61
+ if (selectedValue + "" === "") {
62
+ selectedValue = null;
63
+ } else {
64
+ selectedItem = this.itemDictionary[selectedValue.toString()];
65
+ selectedValue = this.properties.valueFunction(selectedItem);
66
+ }
67
+ if (viewModel.inputValidator) {
68
+ if (!await viewModel.inputValidator(event, viewModel, selectedValue)) {
69
+ select.value = unwrap(viewModel.value) as any as string;
70
+ return;
71
+ };
72
+ }
73
+
74
+ if (isObservableProperty(viewModel.value)) {
75
+ if (viewModel.setFunction) {
76
+ const setValue = viewModel.setFunction(selectedItem);
77
+ viewModel.value.set(setValue);
78
+ } else {
79
+ viewModel.value.set(selectedValue as any);
80
+ }
81
+ }
82
+ }
83
+ );
84
+ }
85
+
86
+ private itemDictionary: { [key: string]: TItem };
87
+
88
+ private setItems(items: Array<TItem>) {
89
+ if (this.element) {
90
+ this.itemDictionary = {};
91
+ if (items) {
92
+ const select = this.element as HTMLSelectElement;
93
+ select.innerHTML = null;
94
+ if (this.properties.emptyItemText) {
95
+ const emptyOption = document.createElement("option") as HTMLOptionElement;
96
+ emptyOption.value = "";
97
+ emptyOption.text = this.properties.emptyItemText;
98
+ select.options.add(emptyOption);
99
+ }
100
+
101
+ items.forEach((item: TItem) => {
102
+ const value = this.properties.valueFunction(item).toString();
103
+ this.itemDictionary[value] = item;
104
+ var option = document.createElement("option") as HTMLOptionElement;
105
+ option.value = value;
106
+ option.text = this.properties.textFunction(item);
107
+ select.options.add(option);
108
+ });
109
+ }
110
+ }
111
+ }
112
+
113
+ private setSelectedValue(value: TValue) {
114
+ if (this.element) {
115
+ const select = this.element as HTMLSelectElement;
116
+ if (value === null || value === undefined) {
117
+ select.value = "";
118
+ } else {
119
+ select.value = value.toString();
120
+ }
121
+ }
122
+ }
123
+ }
124
+
125
+ export function selectView<TItem, TValue, TSetter = TValue>(properties: SelectProperties<TItem, TValue, TSetter>) {
126
+ return new SelectView(properties);
127
+ }
128
+
129
+ export class SelectViewModel<TItem, TValue, TSetter = TValue> extends ViewModel implements SelectProperties<TItem, TValue, TSetter> {
130
+ constructor(properties: SelectProperties<TItem, TValue, TSetter>) {
131
+ super();
132
+ this.setProperties(this, properties);
133
+ }
134
+ value?: TValue | ObservableProperty<TValue, TSetter>;
135
+ items?: Array<TItem> | ObservableArrayProperty<TItem>;
136
+ textFunction: (item: TItem) => string;
137
+ valueFunction: (item: TItem) => TValue;
138
+ setFunction?: (item: TItem) => TSetter;
139
+ inputValidator?: (event: Event, selectViewModel: SelectProperties<TItem, TValue, TSetter>, value: TValue) => Promise<boolean>;
140
+ emptyItemText?: string;
141
+ }
142
+
143
+ registerView(
144
+ SelectViewModel,
145
+ SelectView
146
+ );
@@ -0,0 +1,38 @@
1
+ import { View, registerView } from "../../../framework/View";
2
+ import { ViewModel, Properties, extendProperties } from "../../../framework/ViewModel";
3
+
4
+ export interface SpanProperties extends Properties {
5
+
6
+ }
7
+
8
+ export class SpanView extends View<SpanProperties> {
9
+ constructor(properties: SpanProperties) {
10
+ super(
11
+ {
12
+ tagName: "span",
13
+ properties: extendProperties(
14
+ {
15
+ viewType: "Span"
16
+ },
17
+ properties
18
+ )
19
+ }
20
+ );
21
+ }
22
+ }
23
+
24
+ export function spanView(properties: SpanProperties) {
25
+ return new SpanView(properties);
26
+ }
27
+
28
+ export class SpanViewModel extends ViewModel implements SpanProperties {
29
+ constructor(properties: SpanProperties) {
30
+ super();
31
+ this.setProperties(this, properties);
32
+ }
33
+ }
34
+
35
+ registerView(
36
+ SpanViewModel,
37
+ SpanView
38
+ );
@@ -0,0 +1,6 @@
1
+ export * from "./Button/Button";
2
+ export * from "./Div/Div";
3
+ export * from "./Image/Image";
4
+ export * from "./Input/Input";
5
+ export * from "./Select/Select";
6
+ export * from "./Span/Span";
@@ -0,0 +1,15 @@
1
+ import * as codeMirror from "./codeMirror/index";
2
+ import * as custom from "./custom/index";
3
+ import * as html from "./html/index";
4
+ import * as jsonViewAwesome from "./jsonViewAwesome/index";
5
+ import * as kendo from "./kendo/index";
6
+ import * as leaflet from "./leaflet/index";
7
+ import * as svg from "./svg/index";
8
+
9
+ export { codeMirror };
10
+ export { custom };
11
+ export { html };
12
+ export { jsonViewAwesome };
13
+ export { kendo };
14
+ export { leaflet };
15
+ export { svg };
@@ -0,0 +1 @@
1
+ export * from "./jsonFormatter/JsonFormatter";
@@ -0,0 +1,91 @@
1
+ import { View, registerView } from "../../../framework/View";
2
+ import { ViewModel, Properties, extendProperties } from "../../../framework/ViewModel";
3
+ import { Subscribable, unwrap, isObservable } from "knockout";
4
+ import { JSONFormatter } from "json-viewer-awesome/lib/json-formatter";
5
+
6
+ export interface JsonFormatterProperties extends Properties {
7
+ json: object | Subscribable<object>;
8
+ showArrayIndex?: boolean;
9
+ quotesOnKeys?: boolean;
10
+ displayDataTypes?: boolean;
11
+ displayObjectSize?: boolean;
12
+ sortKeys?: boolean;
13
+ collapsed?: boolean;
14
+ }
15
+
16
+ export class JsonFormatterView extends View<JsonFormatterProperties> {
17
+ constructor(properties: JsonFormatterProperties) {
18
+ super(
19
+ {
20
+ tagName: "div",
21
+ properties: extendProperties(
22
+ {
23
+ viewType: "JsonFormatter"
24
+ },
25
+ properties
26
+ )
27
+ }
28
+ );
29
+ }
30
+
31
+ build(): void {
32
+ super.build();
33
+
34
+ const viewModel = this.properties;
35
+ this.setJson(unwrap(viewModel.json));
36
+ if (isObservable(viewModel.json)) {
37
+ this.subscriptions.push(
38
+ viewModel.json.subscribe((json) => {
39
+ this.setJson(json);
40
+ })
41
+ );
42
+ }
43
+ }
44
+
45
+ private setJson(json: object) {
46
+ if (json) {
47
+ if (typeof json === "object") {
48
+ const jsonFormatter = new JSONFormatter({
49
+ showArrayIndex: this.properties.showArrayIndex,
50
+ quotesOnKeys: this.properties.quotesOnKeys,
51
+ displayDataTypes: this.properties.displayDataTypes,
52
+ displayObjectSize: this.properties.displayObjectSize,
53
+ sortKeys: false,
54
+ collapsed: true,
55
+ iconStyle: 0,
56
+ theme: undefined,
57
+ src: json
58
+ });
59
+
60
+ this.element.replaceChildren(jsonFormatter.render());
61
+ } else {
62
+ this.element.innerHTML = (json as any).toString();
63
+ }
64
+ } else {
65
+ this.empty();
66
+ }
67
+ }
68
+ }
69
+
70
+ export function jsonFormatterView(properties: JsonFormatterProperties) {
71
+ return new JsonFormatterView(properties);
72
+ }
73
+
74
+ export class JsonFormatterViewModel extends ViewModel implements JsonFormatterProperties {
75
+ constructor(properties: JsonFormatterProperties) {
76
+ super();
77
+ this.setProperties(this, properties);
78
+ }
79
+ json: object | Subscribable<object>;
80
+ showArrayIndex?: boolean;
81
+ quotesOnKeys?: boolean;
82
+ displayDataTypes?: boolean;
83
+ displayObjectSize?: boolean;
84
+ sortKeys?: boolean;
85
+ collapsed?: boolean;
86
+ }
87
+
88
+ registerView(
89
+ JsonFormatterViewModel,
90
+ JsonFormatterView
91
+ );