x4js 1.4.46 → 1.4.49

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.
@@ -0,0 +1,58 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \/ / / _
4
+ * \ / /_| |_
5
+ * / \____ _|
6
+ * /__/\__\ |_|
7
+ *
8
+ * @file autocomplete.ts
9
+ * @author Etienne Cochard
10
+ *
11
+ * Copyright (c) 2019-2022 R-libre ingenierie
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17
+ * of the Software, and to permit persons to whom the Software is furnished to do so,
18
+ * subject to the following conditions:
19
+ * The above copyright notice and this permission notice shall be included in all copies
20
+ * or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
23
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
24
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+ **/
29
+ import { TextEdit, TextEditProps } from './textedit';
30
+ /**
31
+ *
32
+ */
33
+ interface AutoCompleteProps extends TextEditProps {
34
+ enumValues: (filter: string) => string[];
35
+ }
36
+ /**
37
+ *
38
+ */
39
+ export declare class AutoComplete extends TextEdit<AutoCompleteProps> {
40
+ private m_popup;
41
+ private m_popvis;
42
+ private m_needval;
43
+ private m_lockpop;
44
+ constructor(props: AutoCompleteProps);
45
+ _onKey(e: KeyboardEvent): void;
46
+ private _onChange;
47
+ componentDisposed(): void;
48
+ /**
49
+ * display the popup
50
+ */
51
+ showPopup(items: string[]): void;
52
+ protected _validate(value: string): boolean;
53
+ validate(): boolean;
54
+ private _checkFocus;
55
+ private _hidePopup;
56
+ private _onFocus;
57
+ }
58
+ export {};
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ /**
3
+ * ___ ___ __
4
+ * \ \/ / / _
5
+ * \ / /_| |_
6
+ * / \____ _|
7
+ * /__/\__\ |_|
8
+ *
9
+ * @file autocomplete.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.AutoComplete = void 0;
32
+ const listview_1 = require("./listview");
33
+ const textedit_1 = require("./textedit");
34
+ /**
35
+ *
36
+ */
37
+ class AutoComplete extends textedit_1.TextEdit {
38
+ m_popup;
39
+ m_popvis;
40
+ m_needval;
41
+ m_lockpop;
42
+ constructor(props) {
43
+ super(props);
44
+ this.setDomEvent("input", () => this._onChange());
45
+ this.setDomEvent("focusin", () => this._onFocus());
46
+ this.startTimer("focus-check", 100, true, () => this._checkFocus());
47
+ this.m_popvis = false;
48
+ this.m_needval = false;
49
+ this.m_lockpop = false;
50
+ this.setDomEvent("keydown", e => this._onKey(e));
51
+ }
52
+ _onKey(e) {
53
+ if (this.m_popvis) {
54
+ if (e.key == "ArrowUp" || e.key == "ArrowDown") {
55
+ this.m_lockpop = true;
56
+ this.m_popup.handleKey(e);
57
+ this.m_lockpop = false;
58
+ e.preventDefault();
59
+ e.stopPropagation();
60
+ }
61
+ else if (e.key == "Escape") {
62
+ this._hidePopup();
63
+ e.preventDefault();
64
+ e.stopPropagation();
65
+ }
66
+ }
67
+ else if (e.key == "ArrowDown") {
68
+ this._onChange();
69
+ e.preventDefault();
70
+ e.stopPropagation();
71
+ }
72
+ }
73
+ _onChange() {
74
+ const items = this.m_props.enumValues(this.value);
75
+ this.showPopup(items);
76
+ }
77
+ componentDisposed() {
78
+ if (this.m_popup) {
79
+ this._hidePopup();
80
+ }
81
+ super.componentDisposed();
82
+ }
83
+ /**
84
+ * display the popup
85
+ */
86
+ showPopup(items) {
87
+ let props = this.m_props;
88
+ if (props.readOnly || this.hasClass("@disable")) {
89
+ return;
90
+ }
91
+ // need creation ?
92
+ if (!this.m_popup) {
93
+ let cstyle = this.getComputedStyle();
94
+ let fontFamily = cstyle.value('fontFamily');
95
+ let fontSize = cstyle.value('fontSize');
96
+ // prepare the combo listview
97
+ this.m_popup = new listview_1.PopupListView({
98
+ cls: '@combo-popup',
99
+ attrs: {
100
+ tabindex: 0
101
+ },
102
+ selectionChange: (e) => {
103
+ this.value = e.selection.id;
104
+ if (!this.m_lockpop) {
105
+ this._hidePopup();
106
+ }
107
+ },
108
+ style: {
109
+ fontFamily,
110
+ fontSize
111
+ }
112
+ });
113
+ }
114
+ this.m_popup.items = items.map(c => ({ id: c, text: c }));
115
+ let r1 = this.m_ui_input.getBoundingRect();
116
+ this.m_popup.setStyle({
117
+ minWidth: r1.width,
118
+ });
119
+ this.m_popup.displayAt(r1.left, r1.bottom);
120
+ this.m_popvis = true;
121
+ //if( this.value!==undefined ) {
122
+ // this.m_popup.selection = this.value;
123
+ //}
124
+ }
125
+ _validate(value) {
126
+ return true;
127
+ }
128
+ validate() {
129
+ return super._validate(this.value);
130
+ }
131
+ _checkFocus() {
132
+ const focus = document.activeElement;
133
+ if (this.dom.contains(focus)) {
134
+ return;
135
+ }
136
+ if (this.m_popup && this.m_popup.dom && this.m_popup.dom.contains(focus)) {
137
+ return;
138
+ }
139
+ this._hidePopup();
140
+ }
141
+ _hidePopup() {
142
+ if (this.m_popvis) {
143
+ this.m_popup.close();
144
+ this.m_popvis = false;
145
+ }
146
+ if (this.m_needval) {
147
+ this.validate();
148
+ this.m_needval = false;
149
+ }
150
+ }
151
+ _onFocus() {
152
+ if (this.value.length == 0) {
153
+ this._onChange();
154
+ }
155
+ this.m_needval = true;
156
+ }
157
+ }
158
+ exports.AutoComplete = AutoComplete;
package/lib/index.d.ts CHANGED
@@ -27,6 +27,7 @@
27
27
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
28
  **/
29
29
  export * from "./application";
30
+ export * from "./autocomplete";
30
31
  export * from "./base_component";
31
32
  export * from "./button";
32
33
  export * from "./calendar";
package/lib/index.js CHANGED
@@ -43,6 +43,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
43
43
  };
44
44
  Object.defineProperty(exports, "__esModule", { value: true });
45
45
  __exportStar(require("./application"), exports);
46
+ __exportStar(require("./autocomplete"), exports);
46
47
  __exportStar(require("./base_component"), exports);
47
48
  //export * from "./base64"
48
49
  __exportStar(require("./button"), exports);
package/lib/input.d.ts CHANGED
@@ -48,6 +48,7 @@ export interface InputProps<P extends InputEventMap = InputEventMap> extends CPr
48
48
  value_hook?: ValueHook;
49
49
  min?: number;
50
50
  max?: number;
51
+ autosel?: boolean;
51
52
  }
52
53
  /**
53
54
  * base class for elements implementing an input
package/lib/input.js CHANGED
@@ -56,9 +56,15 @@ class Input extends component_1.Component {
56
56
  max: props.max,
57
57
  ...props.attrs
58
58
  });
59
+ this.m_props.autosel = props.autosel ?? true;
59
60
  if (props.uppercase) {
60
61
  this.setStyleValue('textTransform', 'uppercase');
61
62
  }
63
+ if (this.m_props.autosel) {
64
+ this.setDomEvent("focus", () => {
65
+ this.selectAll();
66
+ });
67
+ }
62
68
  }
63
69
  getType() {
64
70
  return this.m_props.type;
package/lib/textedit.d.ts CHANGED
@@ -46,6 +46,7 @@ export interface TextEditProps extends InputProps<TextEditEventMap> {
46
46
  pattern?: string;
47
47
  uppercase?: boolean;
48
48
  format?: string | 'native';
49
+ autosel?: boolean;
49
50
  gadgets?: Component[];
50
51
  validator?: ValidationFunction;
51
52
  change?: EventCallback<EvChange>;
package/lib/textedit.js CHANGED
@@ -91,6 +91,7 @@ class TextEdit extends component_1.Component {
91
91
  attrs: props.attrs,
92
92
  min: props.min,
93
93
  max: props.max,
94
+ autosel: props.autosel,
94
95
  };
95
96
  // date is handled manually with popupcalendar
96
97
  if (props.type == 'date') {
package/lib/version.d.ts CHANGED
@@ -1 +1,29 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \_/ / / _
4
+ * \ / /_| |_
5
+ * / _ \____ _|
6
+ * /__/ \__\ |_|
7
+ *
8
+ * @file version.ts
9
+ * @author Etienne Cochard
10
+ *
11
+ * Copyright (c) 2019-2022 R-libre ingenierie
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17
+ * of the Software, and to permit persons to whom the Software is furnished to do so,
18
+ * subject to the following conditions:
19
+ * The above copyright notice and this permission notice shall be included in all copies
20
+ * or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
23
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
24
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+ **/
1
29
  export declare const x4js_version = "1.4";
package/lib/version.js CHANGED
@@ -1,4 +1,32 @@
1
1
  "use strict";
2
+ /**
3
+ * ___ ___ __
4
+ * \ \_/ / / _
5
+ * \ / /_| |_
6
+ * / _ \____ _|
7
+ * /__/ \__\ |_|
8
+ *
9
+ * @file version.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
+ **/
2
30
  Object.defineProperty(exports, "__esModule", { value: true });
3
31
  exports.x4js_version = void 0;
4
32
  exports.x4js_version = "1.4";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x4js",
3
- "version": "1.4.46",
3
+ "version": "1.4.49",
4
4
  "description": "X4js core files",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -34,7 +34,7 @@ import { TextEdit, TextEditProps } from './textedit';
34
34
  *
35
35
  */
36
36
 
37
- interface EditSugProps extends TextEditProps {
37
+ interface AutoCompleteProps extends TextEditProps {
38
38
  enumValues: ( filter: string ) => string[];
39
39
  }
40
40
 
@@ -42,14 +42,14 @@ interface EditSugProps extends TextEditProps {
42
42
  *
43
43
  */
44
44
 
45
- export class EditSug extends TextEdit<EditSugProps> {
45
+ export class AutoComplete extends TextEdit<AutoCompleteProps> {
46
46
 
47
47
  private m_popup: PopupListView;
48
48
  private m_popvis: boolean;
49
49
  private m_needval: boolean;
50
50
  private m_lockpop: boolean;
51
51
 
52
- constructor( props: EditSugProps ) {
52
+ constructor( props: AutoCompleteProps ) {
53
53
  super( props );
54
54
 
55
55
  this.setDomEvent( "input", ( ) => this._onChange( ) );
package/src/index.ts CHANGED
@@ -28,6 +28,7 @@
28
28
  **/
29
29
 
30
30
  export * from "./application"
31
+ export * from "./autocomplete"
31
32
  export * from "./base_component"
32
33
  //export * from "./base64"
33
34
  export * from "./button"
package/src/input.ts CHANGED
@@ -56,6 +56,7 @@ export interface InputProps<P extends InputEventMap = InputEventMap> extends CPr
56
56
  value_hook?: ValueHook;
57
57
  min?: number;
58
58
  max?: number;
59
+ autosel?: boolean;
59
60
  }
60
61
 
61
62
 
@@ -91,9 +92,17 @@ export class Input extends Component<InputProps,InputEventMap>
91
92
  ...props.attrs
92
93
  });
93
94
 
95
+ this.m_props.autosel = props.autosel ?? true;
96
+
94
97
  if( props.uppercase ) {
95
98
  this.setStyleValue( 'textTransform', 'uppercase' );
96
99
  }
100
+
101
+ if( this.m_props.autosel ) {
102
+ this.setDomEvent( "focus", ( ) => {
103
+ this.selectAll( );
104
+ });
105
+ }
97
106
  }
98
107
 
99
108
  public getType( ) {
package/src/textedit.ts CHANGED
@@ -69,6 +69,8 @@ export interface TextEditProps extends InputProps<TextEditEventMap> {
69
69
  pattern?: string;
70
70
  uppercase?: boolean;
71
71
  format?: string | 'native'; // default store format on type date.
72
+ autosel?: boolean; // select content on focus
73
+
72
74
  // by default mysql format without time 'YYYY-MM-DD'
73
75
  // use 'native' to work on real Date object (get/set value)
74
76
 
@@ -142,6 +144,7 @@ export class TextEdit<T extends TextEditProps = TextEditProps, E extends TextEdi
142
144
  attrs: props.attrs,
143
145
  min: props.min,
144
146
  max: props.max,
147
+ autosel: props.autosel,
145
148
  };
146
149
 
147
150
  // date is handled manually with popupcalendar
package/src/version.ts CHANGED
@@ -1 +1,30 @@
1
+ /**
2
+ * ___ ___ __
3
+ * \ \_/ / / _
4
+ * \ / /_| |_
5
+ * / _ \____ _|
6
+ * /__/ \__\ |_|
7
+ *
8
+ * @file version.ts
9
+ * @author Etienne Cochard
10
+ *
11
+ * Copyright (c) 2019-2022 R-libre ingenierie
12
+ *
13
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
14
+ * of this software and associated documentation files (the "Software"), to deal
15
+ * in the Software without restriction, including without limitation the rights
16
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
17
+ * of the Software, and to permit persons to whom the Software is furnished to do so,
18
+ * subject to the following conditions:
19
+ * The above copyright notice and this permission notice shall be included in all copies
20
+ * or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
23
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
24
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
27
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+ **/
29
+
1
30
  export const x4js_version = "1.4";