x4js 1.4.2

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 (176) hide show
  1. package/lib/application.d.ts +95 -0
  2. package/lib/application.js +137 -0
  3. package/lib/base64.d.ts +31 -0
  4. package/lib/base64.js +135 -0
  5. package/lib/base_component.d.ts +64 -0
  6. package/lib/base_component.js +77 -0
  7. package/lib/button.d.ts +145 -0
  8. package/lib/button.js +235 -0
  9. package/lib/calendar.d.ts +77 -0
  10. package/lib/calendar.js +236 -0
  11. package/lib/canvas.d.ts +88 -0
  12. package/lib/canvas.js +354 -0
  13. package/lib/cardview.d.ts +83 -0
  14. package/lib/cardview.js +152 -0
  15. package/lib/checkbox.d.ts +72 -0
  16. package/lib/checkbox.js +126 -0
  17. package/lib/color.d.ts +144 -0
  18. package/lib/color.js +584 -0
  19. package/lib/colorpicker.d.ts +98 -0
  20. package/lib/colorpicker.js +1457 -0
  21. package/lib/combobox.d.ts +97 -0
  22. package/lib/combobox.js +246 -0
  23. package/lib/component.d.ts +572 -0
  24. package/lib/component.js +1712 -0
  25. package/lib/datastore.d.ts +392 -0
  26. package/lib/datastore.js +986 -0
  27. package/lib/dialog.d.ts +171 -0
  28. package/lib/dialog.js +468 -0
  29. package/lib/dom_events.d.ts +284 -0
  30. package/lib/dom_events.js +13 -0
  31. package/lib/drag_manager.d.ts +26 -0
  32. package/lib/drag_manager.js +118 -0
  33. package/lib/drawtext.d.ts +43 -0
  34. package/lib/drawtext.js +261 -0
  35. package/lib/fileupload.d.ts +60 -0
  36. package/lib/fileupload.js +158 -0
  37. package/lib/form.d.ts +122 -0
  38. package/lib/form.js +293 -0
  39. package/lib/formatters.d.ts +31 -0
  40. package/lib/formatters.js +75 -0
  41. package/lib/gridview.d.ts +171 -0
  42. package/lib/gridview.js +786 -0
  43. package/lib/hosts/host.d.ts +44 -0
  44. package/lib/hosts/host.js +69 -0
  45. package/lib/i18n.d.ts +67 -0
  46. package/lib/i18n.js +169 -0
  47. package/lib/icon.d.ts +56 -0
  48. package/lib/icon.js +173 -0
  49. package/lib/image.d.ts +51 -0
  50. package/lib/image.js +149 -0
  51. package/lib/index.js +1 -0
  52. package/lib/input.d.ts +86 -0
  53. package/lib/input.js +172 -0
  54. package/lib/label.d.ts +54 -0
  55. package/lib/label.js +86 -0
  56. package/lib/layout.d.ts +77 -0
  57. package/lib/layout.js +261 -0
  58. package/lib/link.d.ts +46 -0
  59. package/lib/link.js +55 -0
  60. package/lib/listview.d.ts +173 -0
  61. package/lib/listview.js +532 -0
  62. package/lib/md5.d.ts +56 -0
  63. package/lib/md5.js +397 -0
  64. package/lib/menu.d.ts +122 -0
  65. package/lib/menu.js +276 -0
  66. package/lib/messagebox.d.ts +64 -0
  67. package/lib/messagebox.js +141 -0
  68. package/lib/panel.d.ts +42 -0
  69. package/lib/panel.js +61 -0
  70. package/lib/popup.d.ts +71 -0
  71. package/lib/popup.js +373 -0
  72. package/lib/property_editor.d.ts +67 -0
  73. package/lib/property_editor.js +247 -0
  74. package/lib/radiobtn.d.ts +68 -0
  75. package/lib/radiobtn.js +131 -0
  76. package/lib/rating.d.ts +49 -0
  77. package/lib/rating.js +93 -0
  78. package/lib/request.d.ts +48 -0
  79. package/lib/request.js +220 -0
  80. package/lib/router.d.ts +13 -0
  81. package/lib/router.js +27 -0
  82. package/lib/settings.d.ts +33 -0
  83. package/lib/settings.js +63 -0
  84. package/lib/sidebarview.d.ts +44 -0
  85. package/lib/sidebarview.js +73 -0
  86. package/lib/smartedit.d.ts +103 -0
  87. package/lib/smartedit.js +381 -0
  88. package/lib/spreadsheet.d.ts +214 -0
  89. package/lib/spreadsheet.js +1073 -0
  90. package/lib/styles.d.ts +81 -0
  91. package/lib/styles.js +262 -0
  92. package/lib/svgcomponent.d.ts +165 -0
  93. package/lib/svgcomponent.js +350 -0
  94. package/lib/tabbar.d.ts +41 -0
  95. package/lib/tabbar.js +66 -0
  96. package/lib/tabview.d.ts +45 -0
  97. package/lib/tabview.js +79 -0
  98. package/lib/textarea.d.ts +59 -0
  99. package/lib/textarea.js +119 -0
  100. package/lib/textedit.d.ts +118 -0
  101. package/lib/textedit.js +406 -0
  102. package/lib/texthiliter.d.ts +56 -0
  103. package/lib/texthiliter.js +219 -0
  104. package/lib/toaster.d.ts +38 -0
  105. package/lib/toaster.js +58 -0
  106. package/lib/tools.d.ts +382 -0
  107. package/lib/tools.js +1096 -0
  108. package/lib/tooltips.d.ts +42 -0
  109. package/lib/tooltips.js +148 -0
  110. package/lib/treeview.d.ts +128 -0
  111. package/lib/treeview.js +490 -0
  112. package/lib/x4_events.d.ts +253 -0
  113. package/lib/x4_events.js +363 -0
  114. package/package.json +21 -0
  115. package/src/README.md +2 -0
  116. package/src/application.ts +191 -0
  117. package/src/base64.ts +162 -0
  118. package/src/base_component.ts +118 -0
  119. package/src/button.ts +327 -0
  120. package/src/calendar.ts +312 -0
  121. package/src/canvas.ts +501 -0
  122. package/src/cardview.ts +220 -0
  123. package/src/checkbox.ts +178 -0
  124. package/src/color.ts +748 -0
  125. package/src/colorpicker.ts +1618 -0
  126. package/src/combobox.ts +348 -0
  127. package/src/component.ts +2330 -0
  128. package/src/datastore.ts +1318 -0
  129. package/src/dialog.ts +631 -0
  130. package/src/dom_events.ts +297 -0
  131. package/src/drag_manager.ts +168 -0
  132. package/src/drawtext.ts +342 -0
  133. package/src/fileupload.ts +208 -0
  134. package/src/form.ts +362 -0
  135. package/src/formatters.ts +96 -0
  136. package/src/gridview.ts +1051 -0
  137. package/src/hosts/electron.ts +161 -0
  138. package/src/hosts/host.ts +100 -0
  139. package/src/hosts/nwjs.ts +141 -0
  140. package/src/hosts/nwjs_types.ts +339 -0
  141. package/src/i18n.ts +205 -0
  142. package/src/icon.ts +237 -0
  143. package/src/image.ts +198 -0
  144. package/src/input.ts +236 -0
  145. package/src/label.ts +124 -0
  146. package/src/layout.ts +366 -0
  147. package/src/link.ts +82 -0
  148. package/src/listview.ts +749 -0
  149. package/src/md5.ts +432 -0
  150. package/src/menu.ts +394 -0
  151. package/src/messagebox.ts +199 -0
  152. package/src/panel.ts +81 -0
  153. package/src/popup.ts +488 -0
  154. package/src/property_editor.ts +333 -0
  155. package/src/radiobtn.ts +190 -0
  156. package/src/rating.ts +131 -0
  157. package/src/request.ts +296 -0
  158. package/src/router.ts +43 -0
  159. package/src/settings.ts +75 -0
  160. package/src/sidebarview.ts +97 -0
  161. package/src/smartedit.ts +532 -0
  162. package/src/spreadsheet.ts +1423 -0
  163. package/src/styles.ts +332 -0
  164. package/src/svgcomponent.ts +440 -0
  165. package/src/tabbar.ts +105 -0
  166. package/src/tabview.ts +106 -0
  167. package/src/textarea.ts +183 -0
  168. package/src/textedit.ts +535 -0
  169. package/src/texthiliter.ts +284 -0
  170. package/src/toaster.ts +76 -0
  171. package/src/tools.ts +1391 -0
  172. package/src/tooltips.ts +185 -0
  173. package/src/treeview.ts +670 -0
  174. package/src/x4.less +1940 -0
  175. package/src/x4_events.ts +558 -0
  176. package/tsconfig.json +14 -0
@@ -0,0 +1,97 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file combobox.ts
9
+ * @author Etienne Cochard
10
+ * @license
11
+ * Copyright (c) 2019-2021 R-libre ingenierie
12
+ *
13
+ * This program is free software; you can redistribute it and/or modify
14
+ * it under the terms of the GNU General Public License as published by
15
+ * the Free Software Foundation; either version 3 of the License, or
16
+ * (at your option) any later version.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
24
+ **/
25
+ /**
26
+ * TODO: replace custom combo list by listview or gridview
27
+ */
28
+ import { Component, CProps, ContainerEventMap } from './component';
29
+ import { EvChange, EvSelectionChange, EventCallback } from './x4_events';
30
+ import { Input } from './input';
31
+ import { HLayout } from './layout';
32
+ import { ListViewItem, PopulateItems, EvCancel } from './listview';
33
+ import { DataStore, DataView, Record } from './datastore';
34
+ import { HtmlString } from './tools';
35
+ export interface ComboStoreProxyProps {
36
+ store: DataView | DataStore;
37
+ display: (rec: Record) => string | HtmlString;
38
+ }
39
+ export interface ComboItemRender {
40
+ (itm: ListViewItem): Component;
41
+ }
42
+ interface ComboBoxEventMap extends ContainerEventMap {
43
+ readonly change: EvChange;
44
+ readonly selectionChange?: EvSelectionChange;
45
+ readonly cancel?: EvCancel;
46
+ }
47
+ export interface ComboBoxProps extends CProps<ComboBoxEventMap> {
48
+ tabIndex?: number | boolean;
49
+ name?: string;
50
+ readOnly?: boolean;
51
+ label?: string;
52
+ labelWidth?: number;
53
+ labelAlign?: 'left' | 'right';
54
+ items?: ListViewItem[];
55
+ populate?: PopulateItems;
56
+ value?: any;
57
+ renderer?: ComboItemRender;
58
+ selectionChange?: EventCallback<EvSelectionChange>;
59
+ }
60
+ /**
61
+ * @review use textedit
62
+ */
63
+ export declare class ComboBox extends HLayout<ComboBoxProps, ComboBoxEventMap> {
64
+ private m_ui_input;
65
+ private m_ui_button;
66
+ private m_popup;
67
+ private m_selection;
68
+ private m_defer_sel;
69
+ constructor(props: ComboBoxProps);
70
+ set items(items: ListViewItem[]);
71
+ /** @ignore */
72
+ render(props: ComboBoxProps): void;
73
+ componentDisposed(): void;
74
+ /**
75
+ * display the popup
76
+ */
77
+ showPopup(): void;
78
+ /** @ignore
79
+ */
80
+ private _selectItem;
81
+ /**
82
+ *
83
+ */
84
+ private _setInput;
85
+ /**
86
+ *
87
+ */
88
+ get value(): any;
89
+ get valueText(): string | HtmlString;
90
+ /**
91
+ *
92
+ */
93
+ set value(id: any);
94
+ get input(): Input;
95
+ static storeProxy(props: ComboStoreProxyProps): PopulateItems;
96
+ }
97
+ export {};
@@ -0,0 +1,246 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file combobox.ts
9
+ * @author Etienne Cochard
10
+ * @license
11
+ * Copyright (c) 2019-2021 R-libre ingenierie
12
+ *
13
+ * This program is free software; you can redistribute it and/or modify
14
+ * it under the terms of the GNU General Public License as published by
15
+ * the Free Software Foundation; either version 3 of the License, or
16
+ * (at your option) any later version.
17
+ *
18
+ * This program is distributed in the hope that it will be useful,
19
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
+ * GNU General Public License for more details.
22
+ *
23
+ * You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
24
+ **/
25
+ /**
26
+ * TODO: replace custom combo list by listview or gridview
27
+ */
28
+ import { Component } from './component';
29
+ import { EvChange, EvSelectionChange } from './x4_events';
30
+ import { Input } from './input';
31
+ import { Label } from './label';
32
+ import { Button } from './button';
33
+ import { HLayout } from './layout';
34
+ import { PopupListView } from './listview';
35
+ import { DataStore } from './datastore';
36
+ import { isFunction } from './tools';
37
+ /**
38
+ * @review use textedit
39
+ */
40
+ export class ComboBox extends HLayout {
41
+ m_ui_input;
42
+ m_ui_button;
43
+ m_popup;
44
+ m_selection;
45
+ m_defer_sel;
46
+ constructor(props) {
47
+ super(props);
48
+ this.setDomEvent('keypress', () => this.showPopup());
49
+ this.setDomEvent('click', () => this.showPopup());
50
+ this.mapPropEvents(props, 'selectionChange');
51
+ }
52
+ set items(items) {
53
+ this.m_props.items = items;
54
+ if (this.m_popup) {
55
+ this.m_popup.items = items;
56
+ }
57
+ }
58
+ /** @ignore */
59
+ render(props) {
60
+ if (!props.renderer) {
61
+ this.m_ui_input = new Input({
62
+ flex: 1,
63
+ readOnly: true,
64
+ tabIndex: 0,
65
+ name: props.name,
66
+ value_hook: {
67
+ get: () => { return this.value; },
68
+ set: (v) => { this.value = v; }
69
+ }
70
+ });
71
+ }
72
+ else {
73
+ this.m_ui_input = new Component({
74
+ flex: 1,
75
+ cls: '@fake-input @hlayout',
76
+ tabIndex: 1
77
+ });
78
+ }
79
+ let width = undefined, flex = undefined;
80
+ let labelWidth = props.labelWidth ?? 0;
81
+ if (labelWidth > 0) {
82
+ width = labelWidth;
83
+ }
84
+ else if (labelWidth < 0) {
85
+ flex = -labelWidth;
86
+ }
87
+ this.setContent([
88
+ // todo: why 'label1' class name
89
+ new Label({
90
+ cls: 'label1' + (props.label ? '' : ' @hidden'),
91
+ text: props.label,
92
+ width,
93
+ flex,
94
+ align: props.labelAlign
95
+ }),
96
+ new HLayout({
97
+ flex: 1,
98
+ content: [
99
+ this.m_ui_input,
100
+ this.m_ui_button = new Button({
101
+ cls: 'gadget',
102
+ icon: 'cls(far fa-angle-down)',
103
+ tabIndex: false,
104
+ click: () => this.showPopup(),
105
+ dom_events: {
106
+ focus: () => { this.dom.focus(); },
107
+ }
108
+ })
109
+ ]
110
+ }),
111
+ ]);
112
+ if (props.value !== undefined) {
113
+ this.value = props.value;
114
+ }
115
+ }
116
+ componentDisposed() {
117
+ if (this.m_popup) {
118
+ this.m_popup.close();
119
+ }
120
+ super.componentDisposed();
121
+ }
122
+ /**
123
+ * display the popup
124
+ */
125
+ showPopup() {
126
+ let props = this.m_props;
127
+ if (props.readOnly) {
128
+ return;
129
+ }
130
+ // need creation ?
131
+ if (!this.m_popup) {
132
+ let cstyle = this.getComputedStyle();
133
+ let fontFamily = cstyle.value('fontFamily');
134
+ let fontSize = cstyle.value('fontSize');
135
+ // prepare the combo listview
136
+ this.m_popup = new PopupListView({
137
+ cls: '@combo-popup',
138
+ items: props.items,
139
+ populate: props.populate,
140
+ renderItem: this.m_props.renderer,
141
+ selectionChange: (e) => this._selectItem(e),
142
+ cancel: (e) => this.signal('cancel', e),
143
+ style: {
144
+ fontFamily,
145
+ fontSize
146
+ }
147
+ });
148
+ }
149
+ let r1 = this.m_ui_button.getBoundingRect(), r2 = this.m_ui_input.getBoundingRect();
150
+ this.m_popup.setStyle({
151
+ minWidth: r1.right - r2.left,
152
+ });
153
+ this.m_popup.displayAt(r2.left, r2.bottom);
154
+ if (this.value !== undefined) {
155
+ this.m_popup.selection = this.value;
156
+ }
157
+ }
158
+ /** @ignore
159
+ */
160
+ _selectItem(ev) {
161
+ let item = ev.selection;
162
+ if (!item) {
163
+ return;
164
+ }
165
+ this._setInput(item, true);
166
+ this.m_selection = {
167
+ id: item.id,
168
+ text: item.text
169
+ };
170
+ this.emit('selectionChange', EvSelectionChange(item));
171
+ this.emit('change', EvChange(item.id));
172
+ this.m_ui_input.focus();
173
+ this.m_popup.hide();
174
+ }
175
+ /**
176
+ *
177
+ */
178
+ _setInput(item, fireEv = false) {
179
+ if (item) {
180
+ if (this.m_ui_input) {
181
+ if (this.m_ui_input instanceof Input) {
182
+ this.m_ui_input.value = item.text;
183
+ // fires a change event
184
+ if (fireEv) {
185
+ this.m_ui_input.dom.dispatchEvent(new Event('input'));
186
+ }
187
+ }
188
+ else {
189
+ this.m_ui_input.setContent(this.m_props.renderer(item));
190
+ }
191
+ }
192
+ else {
193
+ this.m_props.value = item.id;
194
+ }
195
+ }
196
+ }
197
+ /**
198
+ *
199
+ */
200
+ get value() {
201
+ return this.m_selection ? this.m_selection.id : undefined;
202
+ }
203
+ get valueText() {
204
+ return this.m_selection ? this.m_selection.text : undefined;
205
+ }
206
+ /**
207
+ *
208
+ */
209
+ set value(id) {
210
+ let items = this.m_props.items;
211
+ if (isFunction(items)) {
212
+ items = items();
213
+ }
214
+ items.some((v) => {
215
+ if (v.id === id) {
216
+ this._setInput(v);
217
+ this.m_selection = v;
218
+ return true;
219
+ }
220
+ });
221
+ }
222
+ get input() {
223
+ return this.m_ui_input instanceof Input ? this.m_ui_input : null;
224
+ }
225
+ static storeProxy(props) {
226
+ let view = props.store instanceof DataStore ? props.store.createView() : props.store;
227
+ return () => {
228
+ let result = new Array(props.store.count);
229
+ props.store.forEach((rec, index) => {
230
+ result[index] = {
231
+ id: rec.getID(),
232
+ text: props.display(rec)
233
+ };
234
+ });
235
+ return result;
236
+ };
237
+ }
238
+ }
239
+ /*
240
+ export type CBComboBoxRenderer = ( rec: Record ) => string;
241
+ export interface ComboBoxStore {
242
+ store: DataStore;
243
+ display: string | CBComboBoxRenderer; // if string, the field name to display
244
+ }
245
+
246
+ */