x4js 1.5.18 → 1.5.20

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 (242) hide show
  1. package/lib/{README.md → README.txt} +0 -0
  2. package/lib/cjs/index.js +39 -103
  3. package/lib/cjs/index.js.map +7 -0
  4. package/lib/esm/index.mjs +39 -87
  5. package/lib/esm/index.mjs.map +7 -0
  6. package/lib/{license.md → licence.md} +0 -0
  7. package/lib/src/MIT-license.md +14 -0
  8. package/lib/{types/action.d.ts → src/action.ts} +64 -33
  9. package/lib/src/alpha.jpg +0 -0
  10. package/lib/src/app_sockets.ts +81 -0
  11. package/lib/src/application.ts +251 -0
  12. package/lib/src/autocomplete.ts +197 -0
  13. package/lib/src/base64.ts +166 -0
  14. package/lib/src/base_component.ts +152 -0
  15. package/lib/src/button.ts +355 -0
  16. package/lib/src/calendar.ts +328 -0
  17. package/lib/src/canvas.ts +505 -0
  18. package/lib/src/cardview.ts +227 -0
  19. package/lib/src/checkbox.ts +188 -0
  20. package/lib/src/color.ts +752 -0
  21. package/lib/src/colorpicker.ts +1639 -0
  22. package/lib/src/combobox.ts +465 -0
  23. package/lib/src/component.ts +2329 -0
  24. package/lib/{esm/dom_events.js → src/copyright.txt} +27 -29
  25. package/lib/src/datastore.ts +1322 -0
  26. package/lib/src/dialog.ts +656 -0
  27. package/lib/src/dom_events.ts +315 -0
  28. package/lib/src/drag_manager.ts +199 -0
  29. package/lib/src/drawtext.ts +355 -0
  30. package/lib/src/fileupload.ts +213 -0
  31. package/lib/src/form.ts +375 -0
  32. package/lib/src/formatters.ts +105 -0
  33. package/lib/src/gridview.ts +1185 -0
  34. package/lib/src/i18n.ts +346 -0
  35. package/lib/src/icon.ts +335 -0
  36. package/lib/src/image.ts +204 -0
  37. package/lib/src/index.ts +89 -0
  38. package/lib/src/input.ts +249 -0
  39. package/lib/src/label.ts +128 -0
  40. package/lib/src/layout.ts +430 -0
  41. package/lib/src/link.ts +86 -0
  42. package/lib/src/listview.ts +765 -0
  43. package/lib/{esm/md5.js → src/md5.ts} +438 -403
  44. package/lib/src/menu.ts +425 -0
  45. package/lib/src/messagebox.ts +224 -0
  46. package/lib/src/panel.ts +86 -0
  47. package/lib/src/popup.ts +494 -0
  48. package/lib/src/property_editor.ts +337 -0
  49. package/lib/src/radiobtn.ts +197 -0
  50. package/lib/src/rating.ts +135 -0
  51. package/lib/src/request.ts +300 -0
  52. package/lib/src/router.ts +185 -0
  53. package/lib/src/settings.ts +77 -0
  54. package/lib/src/sidebarview.ts +103 -0
  55. package/lib/src/spreadsheet.ts +1449 -0
  56. package/lib/src/styles.ts +343 -0
  57. package/lib/src/svgcomponent.ts +577 -0
  58. package/lib/src/tabbar.ts +151 -0
  59. package/lib/src/tabview.ts +110 -0
  60. package/lib/src/textarea.ts +235 -0
  61. package/lib/src/textedit.ts +544 -0
  62. package/lib/src/toaster.ts +80 -0
  63. package/lib/src/tools.ts +1473 -0
  64. package/lib/src/tooltips.ts +191 -0
  65. package/lib/src/treeview.ts +716 -0
  66. package/lib/{esm/version.js → src/version.ts} +30 -29
  67. package/lib/{styles → src}/x4.less +0 -0
  68. package/lib/src/x4dom.ts +57 -0
  69. package/lib/src/x4events.ts +585 -0
  70. package/lib/src/x4react.ts +90 -0
  71. package/package.json +52 -46
  72. package/lib/cjs/action.js +0 -58
  73. package/lib/cjs/app_sockets.js +0 -74
  74. package/lib/cjs/application.js +0 -182
  75. package/lib/cjs/autocomplete.js +0 -155
  76. package/lib/cjs/base_component.js +0 -124
  77. package/lib/cjs/button.js +0 -263
  78. package/lib/cjs/calendar.js +0 -254
  79. package/lib/cjs/canvas.js +0 -361
  80. package/lib/cjs/cardview.js +0 -161
  81. package/lib/cjs/checkbox.js +0 -139
  82. package/lib/cjs/color.js +0 -591
  83. package/lib/cjs/colorpicker.js +0 -1468
  84. package/lib/cjs/combobox.js +0 -349
  85. package/lib/cjs/component.js +0 -1719
  86. package/lib/cjs/datastore.js +0 -985
  87. package/lib/cjs/dialog.js +0 -478
  88. package/lib/cjs/dom_events.js +0 -30
  89. package/lib/cjs/drag_manager.js +0 -145
  90. package/lib/cjs/drawtext.js +0 -276
  91. package/lib/cjs/fileupload.js +0 -167
  92. package/lib/cjs/form.js +0 -304
  93. package/lib/cjs/formatters.js +0 -90
  94. package/lib/cjs/gridview.js +0 -881
  95. package/lib/cjs/i18n.js +0 -266
  96. package/lib/cjs/icon.js +0 -272
  97. package/lib/cjs/image.js +0 -157
  98. package/lib/cjs/input.js +0 -174
  99. package/lib/cjs/label.js +0 -95
  100. package/lib/cjs/layout.js +0 -322
  101. package/lib/cjs/link.js +0 -64
  102. package/lib/cjs/listview.js +0 -546
  103. package/lib/cjs/md5.js +0 -403
  104. package/lib/cjs/menu.js +0 -301
  105. package/lib/cjs/messagebox.js +0 -177
  106. package/lib/cjs/panel.js +0 -68
  107. package/lib/cjs/popup.js +0 -383
  108. package/lib/cjs/property_editor.js +0 -252
  109. package/lib/cjs/radiobtn.js +0 -140
  110. package/lib/cjs/rating.js +0 -102
  111. package/lib/cjs/request.js +0 -246
  112. package/lib/cjs/router.js +0 -139
  113. package/lib/cjs/settings.js +0 -69
  114. package/lib/cjs/sidebarview.js +0 -82
  115. package/lib/cjs/spreadsheet.js +0 -1084
  116. package/lib/cjs/styles.js +0 -275
  117. package/lib/cjs/svgcomponent.js +0 -447
  118. package/lib/cjs/tabbar.js +0 -111
  119. package/lib/cjs/tabview.js +0 -85
  120. package/lib/cjs/textarea.js +0 -165
  121. package/lib/cjs/textedit.js +0 -415
  122. package/lib/cjs/toaster.js +0 -64
  123. package/lib/cjs/tools.js +0 -1197
  124. package/lib/cjs/tooltips.js +0 -157
  125. package/lib/cjs/treeview.js +0 -535
  126. package/lib/cjs/version.js +0 -32
  127. package/lib/cjs/x4dom.js +0 -32
  128. package/lib/cjs/x4events.js +0 -384
  129. package/lib/cjs/x4react.js +0 -72
  130. package/lib/esm/action.js +0 -53
  131. package/lib/esm/app_sockets.js +0 -70
  132. package/lib/esm/application.js +0 -184
  133. package/lib/esm/autocomplete.js +0 -155
  134. package/lib/esm/base_component.js +0 -107
  135. package/lib/esm/button.js +0 -257
  136. package/lib/esm/calendar.js +0 -249
  137. package/lib/esm/canvas.js +0 -358
  138. package/lib/esm/cardview.js +0 -159
  139. package/lib/esm/checkbox.js +0 -134
  140. package/lib/esm/color.js +0 -588
  141. package/lib/esm/colorpicker.js +0 -1475
  142. package/lib/esm/combobox.js +0 -351
  143. package/lib/esm/component.js +0 -1711
  144. package/lib/esm/datastore.js +0 -990
  145. package/lib/esm/dialog.js +0 -490
  146. package/lib/esm/drag_manager.js +0 -147
  147. package/lib/esm/drawtext.js +0 -271
  148. package/lib/esm/fileupload.js +0 -163
  149. package/lib/esm/form.js +0 -304
  150. package/lib/esm/formatters.js +0 -81
  151. package/lib/esm/gridview.js +0 -889
  152. package/lib/esm/i18n.js +0 -257
  153. package/lib/esm/icon.js +0 -261
  154. package/lib/esm/image.js +0 -154
  155. package/lib/esm/input.js +0 -182
  156. package/lib/esm/label.js +0 -90
  157. package/lib/esm/layout.js +0 -310
  158. package/lib/esm/link.js +0 -59
  159. package/lib/esm/listview.js +0 -534
  160. package/lib/esm/menu.js +0 -300
  161. package/lib/esm/messagebox.js +0 -161
  162. package/lib/esm/panel.js +0 -65
  163. package/lib/esm/popup.js +0 -379
  164. package/lib/esm/property_editor.js +0 -251
  165. package/lib/esm/radiobtn.js +0 -136
  166. package/lib/esm/rating.js +0 -97
  167. package/lib/esm/request.js +0 -224
  168. package/lib/esm/router.js +0 -136
  169. package/lib/esm/settings.js +0 -66
  170. package/lib/esm/sidebarview.js +0 -79
  171. package/lib/esm/spreadsheet.js +0 -1097
  172. package/lib/esm/styles.js +0 -270
  173. package/lib/esm/svgcomponent.js +0 -450
  174. package/lib/esm/tabbar.js +0 -107
  175. package/lib/esm/tabview.js +0 -83
  176. package/lib/esm/textarea.js +0 -160
  177. package/lib/esm/textedit.js +0 -412
  178. package/lib/esm/toaster.js +0 -62
  179. package/lib/esm/tools.js +0 -1158
  180. package/lib/esm/tooltips.js +0 -153
  181. package/lib/esm/treeview.js +0 -527
  182. package/lib/esm/x4dom.js +0 -29
  183. package/lib/esm/x4events.js +0 -376
  184. package/lib/esm/x4react.js +0 -71
  185. package/lib/types/app_sockets.d.ts +0 -29
  186. package/lib/types/application.d.ts +0 -104
  187. package/lib/types/autocomplete.d.ts +0 -58
  188. package/lib/types/base_component.d.ts +0 -88
  189. package/lib/types/button.d.ts +0 -151
  190. package/lib/types/calendar.d.ts +0 -82
  191. package/lib/types/canvas.d.ts +0 -92
  192. package/lib/types/cardview.d.ts +0 -87
  193. package/lib/types/checkbox.d.ts +0 -77
  194. package/lib/types/color.d.ts +0 -148
  195. package/lib/types/colorpicker.d.ts +0 -107
  196. package/lib/types/combobox.d.ts +0 -107
  197. package/lib/types/component.d.ts +0 -601
  198. package/lib/types/datastore.d.ts +0 -396
  199. package/lib/types/dialog.d.ts +0 -175
  200. package/lib/types/dom_events.d.ts +0 -302
  201. package/lib/types/drag_manager.d.ts +0 -54
  202. package/lib/types/drawtext.d.ts +0 -48
  203. package/lib/types/fileupload.d.ts +0 -64
  204. package/lib/types/form.d.ts +0 -133
  205. package/lib/types/formatters.d.ts +0 -35
  206. package/lib/types/gridview.d.ts +0 -175
  207. package/lib/types/i18n.d.ts +0 -73
  208. package/lib/types/icon.d.ts +0 -64
  209. package/lib/types/image.d.ts +0 -55
  210. package/lib/types/index.d.ts +0 -84
  211. package/lib/types/input.d.ts +0 -91
  212. package/lib/types/label.d.ts +0 -58
  213. package/lib/types/layout.d.ts +0 -87
  214. package/lib/types/link.d.ts +0 -50
  215. package/lib/types/listview.d.ts +0 -178
  216. package/lib/types/md5.d.ts +0 -61
  217. package/lib/types/menu.d.ts +0 -130
  218. package/lib/types/messagebox.d.ts +0 -69
  219. package/lib/types/panel.d.ts +0 -47
  220. package/lib/types/popup.d.ts +0 -75
  221. package/lib/types/property_editor.d.ts +0 -71
  222. package/lib/types/radiobtn.d.ts +0 -73
  223. package/lib/types/rating.d.ts +0 -53
  224. package/lib/types/request.d.ts +0 -52
  225. package/lib/types/router.d.ts +0 -42
  226. package/lib/types/settings.d.ts +0 -37
  227. package/lib/types/sidebarview.d.ts +0 -49
  228. package/lib/types/spreadsheet.d.ts +0 -222
  229. package/lib/types/styles.d.ts +0 -85
  230. package/lib/types/svgcomponent.d.ts +0 -215
  231. package/lib/types/tabbar.d.ts +0 -58
  232. package/lib/types/tabview.d.ts +0 -49
  233. package/lib/types/textarea.d.ts +0 -77
  234. package/lib/types/textedit.d.ts +0 -123
  235. package/lib/types/toaster.d.ts +0 -42
  236. package/lib/types/tools.d.ts +0 -394
  237. package/lib/types/tooltips.d.ts +0 -46
  238. package/lib/types/treeview.d.ts +0 -144
  239. package/lib/types/version.d.ts +0 -29
  240. package/lib/types/x4dom.d.ts +0 -49
  241. package/lib/types/x4events.d.ts +0 -269
  242. package/lib/types/x4react.d.ts +0 -41
@@ -1,177 +0,0 @@
1
- "use strict";
2
- /**
3
- * ___ ___ __
4
- * \ \_/ / / _
5
- * \ / /_| |_
6
- * / _ \____ _|
7
- * /__/ \__\ |_|
8
- *
9
- * @file messagebox.ts
10
- * @author Etienne Cochard
11
- *
12
- * Copyright (c) 2019-2022 R-libre ingenierie
13
- *
14
- * Permission is hereby granted, free of charge, to any person obtaining a copy
15
- * of this software and associated documentation files (the "Software"), to deal
16
- * in the Software without restriction, including without limitation the rights
17
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
18
- * of the Software, and to permit persons to whom the Software is furnished to do so,
19
- * subject to the following conditions:
20
- * The above copyright notice and this permission notice shall be included in all copies
21
- * or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
24
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
25
- * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
- **/
30
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
31
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
32
- return new (P || (P = Promise))(function (resolve, reject) {
33
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
34
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
35
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
36
- step((generator = generator.apply(thisArg, _arguments || [])).next());
37
- });
38
- };
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- exports.PromptDialogBox = exports.MessageBox = void 0;
41
- const dialog_1 = require("./dialog");
42
- const tools_1 = require("./tools");
43
- const layout_1 = require("./layout");
44
- const icon_1 = require("./icon");
45
- const label_1 = require("./label");
46
- const textedit_1 = require("./textedit");
47
- class MessageBox extends dialog_1.Dialog {
48
- constructor(props) {
49
- var _a;
50
- // remove overloaded elements from DialogBoxProps
51
- let icon = (_a = props.icon) !== null && _a !== void 0 ? _a : 'var( --x4-icon-exclamation )'; // todo: resolve that
52
- props.icon = undefined;
53
- let buttons = props.buttons === undefined ? ['ok'] : props.buttons;
54
- props.buttons = undefined;
55
- super(props);
56
- let msg = props.message;
57
- this.form.updateContent(new layout_1.HLayout({
58
- style: { padding: 8 },
59
- content: [
60
- icon ? new icon_1.Icon({ cls: 'icon', icon }) : null,
61
- this.m_label = new label_1.Label({ cls: 'text', text: msg, multiline: true })
62
- ]
63
- }), buttons);
64
- this.on('btnClick', (ev) => {
65
- // no prevent default -> always close the messagebox
66
- if (!this.m_props.click) {
67
- return;
68
- }
69
- (0, tools_1.asap)(() => {
70
- this.m_props.click(ev.button);
71
- });
72
- });
73
- }
74
- set text(txt) {
75
- this.m_label.text = txt;
76
- }
77
- /**
78
- * display a messagebox
79
- */
80
- static show(props) {
81
- let msg;
82
- if ((0, tools_1.isString)(props) || (0, tools_1.isHtmlString)(props)) {
83
- msg = new MessageBox({ message: props, click: () => { } });
84
- }
85
- else {
86
- msg = new MessageBox(props);
87
- }
88
- msg.show();
89
- return msg;
90
- }
91
- static showAsync(props) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- return new Promise((resolve, reject) => {
94
- let _props;
95
- const cb = (btn) => {
96
- resolve(btn);
97
- };
98
- if ((0, tools_1.isString)(props) || (0, tools_1.isHtmlString)(props)) {
99
- _props = { message: props, click: cb };
100
- }
101
- else {
102
- _props = Object.assign(Object.assign({}, props), { click: cb });
103
- }
104
- const msg = new MessageBox(_props);
105
- msg.show();
106
- });
107
- });
108
- }
109
- /**
110
- * display an alert message
111
- */
112
- static alert(text, title = null) {
113
- new MessageBox({
114
- cls: 'warning',
115
- title,
116
- message: text,
117
- buttons: ['ok'],
118
- click: () => { },
119
- }).show();
120
- }
121
- }
122
- exports.MessageBox = MessageBox;
123
- class PromptDialogBox extends dialog_1.Dialog {
124
- constructor(props) {
125
- var _a;
126
- // remove overloaded elements from DialogBoxProps
127
- //let icon = props.icon; // ?? 'cls(far fa-comment-check)'; // todo: resolve that
128
- //props.icon = undefined;
129
- props.buttons = undefined;
130
- props.width = (_a = props.width) !== null && _a !== void 0 ? _a : 500;
131
- super(props);
132
- this.form.updateContent(new layout_1.HLayout({
133
- cls: 'panel',
134
- content: [
135
- //icon ? new Icon({
136
- // cls: 'icon',
137
- // icon: icon
138
- //}) : null,
139
- this.m_edit = new textedit_1.TextEdit({
140
- flex: 1,
141
- autoFocus: true,
142
- label: props.message,
143
- value: props.value
144
- }),
145
- ]
146
- }), ['ok', 'cancel']);
147
- if (props.click) {
148
- this.on('btnClick', (ev) => {
149
- if (ev.button === 'ok') {
150
- // no prevent default -> always close the messagebox
151
- // asap to allow
152
- (0, tools_1.asap)(() => {
153
- this.m_props.click(this.m_edit.value);
154
- });
155
- }
156
- });
157
- }
158
- }
159
- set text(txt) {
160
- this.m_edit.label = txt;
161
- }
162
- /**
163
- * display a messagebox
164
- */
165
- static show(props, inputCallback) {
166
- let msg;
167
- if ((0, tools_1.isString)(props) || (0, tools_1.isHtmlString)(props)) {
168
- msg = new PromptDialogBox({ message: props, click: inputCallback });
169
- }
170
- else {
171
- msg = new PromptDialogBox(props);
172
- }
173
- msg.show();
174
- return msg;
175
- }
176
- }
177
- exports.PromptDialogBox = PromptDialogBox;
package/lib/cjs/panel.js DELETED
@@ -1,68 +0,0 @@
1
- "use strict";
2
- /**
3
- * ___ ___ __
4
- * \ \_/ / / _
5
- * \ / /_| |_
6
- * / _ \____ _|
7
- * /__/ \__\ |_|
8
- *
9
- * @file panel.ts
10
- * @author Etienne Cochard
11
- *
12
- * Copyright (c) 2019-2022 R-libre ingenierie
13
- *
14
- * Permission is hereby granted, free of charge, to any person obtaining a copy
15
- * of this software and associated documentation files (the "Software"), to deal
16
- * in the Software without restriction, including without limitation the rights
17
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
18
- * of the Software, and to permit persons to whom the Software is furnished to do so,
19
- * subject to the following conditions:
20
- * The above copyright notice and this permission notice shall be included in all copies
21
- * or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
24
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
25
- * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
- **/
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.Panel = void 0;
32
- const component_1 = require("./component");
33
- const layout_1 = require("./layout");
34
- const label_1 = require("./label");
35
- const icon_1 = require("./icon");
36
- class Panel extends layout_1.VLayout {
37
- constructor(props) {
38
- super(props);
39
- const sens = (props === null || props === void 0 ? void 0 : props.sens) == 'horizontal' ? '@hlayout' : '@vlayout';
40
- //todo: cannot be called twice do to content overload
41
- this.m_ui_title = new label_1.Label({ cls: 'title', text: this.m_props.title });
42
- this.m_ui_body = new component_1.Component({ cls: 'body ' + sens, content: this.m_props.content, style: props.bodyStyle });
43
- }
44
- /** @ignore */
45
- render() {
46
- var _a;
47
- const gadgets = (_a = this.m_props.gadgets) !== null && _a !== void 0 ? _a : [];
48
- const icon = this.m_props.icon ? new icon_1.Icon({ icon: this.m_props.icon }) : null;
49
- super.setContent([
50
- new layout_1.HLayout({
51
- cls: 'title',
52
- content: [
53
- icon,
54
- this.m_ui_title,
55
- ...gadgets
56
- ]
57
- }),
58
- this.m_ui_body
59
- ]);
60
- }
61
- setContent(els) {
62
- this.m_ui_body.setContent(els);
63
- }
64
- set title(text) {
65
- this.m_ui_title.text = text;
66
- }
67
- }
68
- exports.Panel = Panel;
package/lib/cjs/popup.js DELETED
@@ -1,383 +0,0 @@
1
- "use strict";
2
- /**
3
- * ___ ___ __
4
- * \ \_/ / / _
5
- * \ / /_| |_
6
- * / _ \____ _|
7
- * /__/ \__\ |_|
8
- *
9
- * @file popup.ts
10
- * @author Etienne Cochard
11
- *
12
- * Copyright (c) 2019-2022 R-libre ingenierie
13
- *
14
- * Permission is hereby granted, free of charge, to any person obtaining a copy
15
- * of this software and associated documentation files (the "Software"), to deal
16
- * in the Software without restriction, including without limitation the rights
17
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
18
- * of the Software, and to permit persons to whom the Software is furnished to do so,
19
- * subject to the following conditions:
20
- * The above copyright notice and this permission notice shall be included in all copies
21
- * or substantial portions of the Software.
22
- *
23
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
24
- * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
25
- * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
26
- * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
- * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
- **/
30
- Object.defineProperty(exports, "__esModule", { value: true });
31
- exports.Popup = exports.EvMove = void 0;
32
- const x4dom_1 = require("./x4dom");
33
- const component_1 = require("./component");
34
- const tools_1 = require("./tools");
35
- const x4events_1 = require("./x4events");
36
- const application_1 = require("./application");
37
- function EvMove(pos) {
38
- return (0, x4events_1.BasicEvent)({ pos });
39
- }
40
- exports.EvMove = EvMove;
41
- /**
42
- * base class for all popup elements
43
- */
44
- class Popup extends component_1.Container {
45
- constructor(props) {
46
- super(props);
47
- this.m_hasMask = true;
48
- this.addClass('@hidden');
49
- }
50
- enableMask(enable = true) {
51
- this.m_hasMask = enable;
52
- }
53
- /**
54
- * display the popup on screen
55
- */
56
- show(modal) {
57
- if (modal !== undefined) {
58
- this.m_hasMask = modal ? true : false;
59
- }
60
- else {
61
- modal = this.m_hasMask;
62
- }
63
- if (this.m_hasMask) {
64
- // remove the focus
65
- const focus = x4dom_1.x4document.activeElement;
66
- if (focus) {
67
- focus.blur();
68
- }
69
- this.m_ui_mask = x4dom_1.x4document.body.lastChild;
70
- while (this.m_ui_mask) {
71
- if (this.m_ui_mask.nodeType == 1) { // only element nodes
72
- let elUI = (0, component_1.flyWrap)(this.m_ui_mask);
73
- if (elUI.hasClass('@menu') || elUI.hasClass('@non-maskable')) {
74
- /* avoid circular dependencies instanceof Menu*/
75
- /* avoid nonmaskable elements tobe masked */
76
- }
77
- else if (elUI.getStyleValue('display') == 'none' || !elUI.isUserVisible()) {
78
- /* avoid masking hidden elements */
79
- }
80
- else if (!elUI.hasClass('@comp')) {
81
- /* avoid masking element that are not to us */
82
- }
83
- else {
84
- break;
85
- }
86
- }
87
- this.m_ui_mask = this.m_ui_mask.previousSibling;
88
- }
89
- if (this.m_ui_mask) {
90
- (0, component_1.flyWrap)(this.m_ui_mask).addClass('@mask');
91
- }
92
- }
93
- if (modal) {
94
- application_1.Application.instance().enterModal(true);
95
- }
96
- // to avoid body growing because of appendChild
97
- this.setStyle({
98
- left: 0,
99
- top: 0
100
- });
101
- x4dom_1.x4document.body.appendChild(this._build());
102
- this.removeClass('@hidden');
103
- this.centerOnScreen();
104
- if (modal) {
105
- let focus = x4dom_1.x4document.activeElement;
106
- if (!this.dom.contains(focus)) {
107
- const autofocus = this.queryItem('[autofocus]');
108
- if (autofocus) {
109
- autofocus.focus();
110
- }
111
- else {
112
- let tabbable = this.queryAll('[tabindex]');
113
- if (tabbable) {
114
- // remove hidden elements
115
- tabbable = tabbable.filter((el) => el.offsetParent !== null);
116
- if (tabbable.length) {
117
- tabbable[0].focus();
118
- }
119
- }
120
- }
121
- }
122
- Popup.modal_stack.push(this.dom);
123
- }
124
- }
125
- centerOnScreen() {
126
- let rc = this.getBoundingRect();
127
- //let x = (x4document.body.clientWidth - rc.width) / 2,
128
- // y = (x4document.body.clientHeight - rc.height) / 2;
129
- const x = `max( 0px, 50vw - ${rc.width / 2}px )`; //(x4dom_1.x4document.body.clientWidth - rc.width) / 2;
130
- const y = `max( 0px, 50vh - ${rc.height / 2}px )`; //(x4dom_1.x4document.body.clientHeight - rc.height) / 2;
131
- this.setStyleValue('left', x);
132
- this.setStyleValue('top', y);
133
- }
134
- /**
135
- * display the popup at a specific position
136
- * @param x
137
- * @param y
138
- */
139
- displayAt(x, y, align = 'top left', offset, modal = false) {
140
- this.show(modal);
141
- let halign = 'l', valign = 't';
142
- if (align.indexOf('right') >= 0) {
143
- halign = 'r';
144
- }
145
- if (align.indexOf('bottom') >= 0) {
146
- valign = 'b';
147
- }
148
- // @TODO: this is a minimal overflow problem solution
149
- let rc = x4dom_1.x4document.body.getBoundingClientRect(), rm = this.getBoundingRect();
150
- if (halign == 'r') {
151
- x -= rm.width;
152
- }
153
- if (valign == 'b') {
154
- y -= rm.height;
155
- }
156
- if (offset) {
157
- x += offset.x;
158
- y += offset.y;
159
- }
160
- if (x < 4) {
161
- x = 4;
162
- }
163
- if ((x + rm.width) > rc.right - 4) {
164
- x = rc.right - 4 - rm.width;
165
- if ((offset === null || offset === void 0 ? void 0 : offset.x) < 0) {
166
- x += offset.x;
167
- }
168
- }
169
- if (y < 4) {
170
- y = 4;
171
- }
172
- if ((y + rm.height) > rc.bottom - 4) {
173
- y = rc.bottom - 4 - rm.height;
174
- if ((offset === null || offset === void 0 ? void 0 : offset.y) < 0) {
175
- y += offset.y;
176
- }
177
- }
178
- this.setStyle({ left: x, top: y });
179
- }
180
- /**
181
- * close the popup
182
- */
183
- close() {
184
- this.hide();
185
- if (this.m_hasMask && this.m_ui_mask) {
186
- (0, component_1.flyWrap)(this.m_ui_mask).removeClass('@mask');
187
- const app = application_1.Application.instance();
188
- app.enterModal(false);
189
- }
190
- let index = Popup.modal_stack.indexOf(this.dom);
191
- if (index >= 0) {
192
- Popup.modal_stack.splice(index);
193
- }
194
- this.dispose();
195
- }
196
- componentCreated() {
197
- if (this.m_props.sizable) {
198
- this.addClass('@size-all');
199
- let els = ['top', 'right', 'bottom', 'left', 'topleft', 'topright', 'bottomleft', 'bottomright'];
200
- for (let sens of els) {
201
- new component_1.SizerOverlay({
202
- target: this,
203
- sens: sens,
204
- events: { rawresize: (e) => this._mouseResize(e) }
205
- });
206
- }
207
- }
208
- }
209
- /**
210
- * resize for 'all' resize attribute
211
- */
212
- _mouseResize(event) {
213
- event.preventDefault();
214
- let irc = this.getBoundingRect();
215
- let st = this.getComputedStyle();
216
- let ev = event.ui_event;
217
- let tm = st.parse('marginTop'), lm = st.parse('marginLeft'), rm = st.parse('marginRight'), bm = st.parse('marginBottom');
218
- let ix = 0, iy = 0;
219
- let mp = (0, tools_1.getMousePos)(ev, true);
220
- // horz
221
- switch (event.sens) {
222
- case 'topright':
223
- case 'bottomright':
224
- case 'right':
225
- ix = (irc.right - rm) - mp.x;
226
- break;
227
- case 'topleft':
228
- case 'bottomleft':
229
- case 'left':
230
- ix = (irc.left - lm) - mp.x;
231
- break;
232
- }
233
- // vert
234
- switch (event.sens) {
235
- case 'bottomleft':
236
- case 'bottomright':
237
- case 'bottom':
238
- iy = (irc.bottom - bm) - mp.y;
239
- break;
240
- case 'topleft':
241
- case 'topright':
242
- case 'top':
243
- iy = (irc.top - tm) - mp.y;
244
- break;
245
- }
246
- // left & top are with margin
247
- // width & height not
248
- irc.left -= lm;
249
- irc.top -= tm;
250
- //console.log( 'capture' );
251
- let sens = event.sens;
252
- component_1.Component.setCapture(this, (ne) => {
253
- //console.log( ne );
254
- let __move = (ex, ey) => {
255
- let left = irc.left, top = irc.top, width = irc.width, height = irc.height;
256
- let dx, dy;
257
- let px = ex + ix, py = ey + iy;
258
- if (px < 0) {
259
- px = 0;
260
- }
261
- if (py < 0) {
262
- py = 0;
263
- }
264
- // horz
265
- switch (sens) {
266
- case 'topright':
267
- case 'bottomright':
268
- case 'right':
269
- width = px - left;
270
- break;
271
- case 'topleft':
272
- case 'bottomleft':
273
- case 'left':
274
- dx = left - px;
275
- width += dx;
276
- left -= dx;
277
- break;
278
- }
279
- // vert
280
- switch (sens) {
281
- case 'bottomleft':
282
- case 'bottomright':
283
- case 'bottom':
284
- height = py - top;
285
- break;
286
- case 'topleft':
287
- case 'topright':
288
- case 'top':
289
- dy = top - py;
290
- height += dy;
291
- top -= dy;
292
- break;
293
- }
294
- let newsize = new tools_1.Size(width, height);
295
- this.setStyle({ left, top, width: newsize.width, height: newsize.height });
296
- this.emit('size', (0, component_1.EvSize)(newsize));
297
- };
298
- if (ne.type == 'mouseup' || ne.type == 'touchend') {
299
- component_1.Component.releaseCapture();
300
- }
301
- else if (ne.type == 'mousemove') {
302
- let me = ne;
303
- __move(me.pageX, me.pageY);
304
- }
305
- else if (ne.type == 'touchmove') {
306
- let tev = ne;
307
- __move(tev.touches[0].pageX, tev.touches[0].pageY);
308
- }
309
- });
310
- }
311
- }
312
- exports.Popup = Popup;
313
- Popup.modal_stack = [];
314
- /**
315
- * handle tab key
316
- */
317
- function x4handleKeyDown(e) {
318
- if (e.key == 'Tab' || e.key == 'Enter') {
319
- const target = e.target;
320
- if (target.tagName == 'TEXTAREA') {
321
- return;
322
- }
323
- const el = component_1.Component.getElement(target);
324
- if (el && (el.hasAttribute('wants-tab') || el.hasAttribute('wants-enter'))) {
325
- return;
326
- }
327
- let topStack = x4dom_1.x4document.body;
328
- if (Popup.modal_stack.length) {
329
- topStack = Popup.modal_stack[Popup.modal_stack.length - 1];
330
- }
331
- _nextTab(topStack, e.target, e.shiftKey);
332
- e.stopPropagation();
333
- e.preventDefault();
334
- }
335
- }
336
- /**
337
- * cycle through tabs
338
- */
339
- function _nextTab(root, el, prev) {
340
- // first check if the focus is one of our child (disabled...)
341
- let focusEl = x4dom_1.x4document.activeElement;
342
- if (!root.contains(focusEl)) {
343
- return;
344
- }
345
- let comp = component_1.Component.getElement(el);
346
- // get a list of elements with tab index, this way we should abble to
347
- // cycle on them (not on browser address nor under dialog elements)
348
- let tab_indexes = Array.from(root.querySelectorAll('[tabindex]'));
349
- // remove hidden elements
350
- tab_indexes = tab_indexes.filter((el) => el.offsetParent !== null);
351
- if (!tab_indexes.length) {
352
- return;
353
- }
354
- let ct = tab_indexes.indexOf(el);
355
- if (ct < 0) {
356
- ct = 0;
357
- }
358
- else {
359
- if (prev) {
360
- if (ct > 0) {
361
- ct--;
362
- }
363
- else {
364
- ct = tab_indexes.length - 1;
365
- }
366
- }
367
- else {
368
- if (ct < tab_indexes.length - 1) {
369
- ct++;
370
- }
371
- else {
372
- ct = 0;
373
- }
374
- }
375
- }
376
- tab_indexes[ct].focus();
377
- }
378
- function installKBHandler() {
379
- // set on body to be called after document (where all component domevent go)
380
- x4dom_1.x4document.body.addEventListener('keydown', x4handleKeyDown, true);
381
- }
382
- // too early ?
383
- x4dom_1.x4document.body ? installKBHandler() : window.addEventListener('load', installKBHandler);