x4js 2.3.24 → 2.3.26

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 (68) hide show
  1. package/aicontext.md +101 -17
  2. package/aiguide.md +64 -15
  3. package/package.json +1 -1
  4. package/src/components/assets/icons.ts +2 -0
  5. package/src/components/autocomplete/autocomplete.ts +2 -2
  6. package/src/components/boxes/boxes.module.scss +16 -2
  7. package/src/components/boxes/boxes.ts +24 -11
  8. package/src/components/breadcrumb/breadcrumb.ts +1 -2
  9. package/src/components/btngroup/btngroup.ts +2 -2
  10. package/src/components/button/button.ts +7 -2
  11. package/src/components/calendar/calendar.ts +4 -2
  12. package/src/components/canvas/canvas.ts +1 -2
  13. package/src/components/chart/chart.ts +3 -3
  14. package/src/components/checkbox/checkbox.ts +2 -2
  15. package/src/components/colorinput/colorinput.ts +3 -2
  16. package/src/components/colorpicker/colorpicker.ts +5 -5
  17. package/src/components/combobox/combobox.ts +3 -3
  18. package/src/components/dialog/dialog.ts +8 -2
  19. package/src/components/dockingview/dockingview.ts +1 -2
  20. package/src/components/filedrop/filedrop.ts +3 -2
  21. package/src/components/form/form.module.scss +2 -1
  22. package/src/components/form/form.ts +7 -3
  23. package/src/components/gauge/gauge.ts +2 -2
  24. package/src/components/gridview/gridview.module.scss +8 -5
  25. package/src/components/gridview/gridview.ts +11 -13
  26. package/src/components/header/header.ts +2 -2
  27. package/src/components/icon/icon.ts +1 -2
  28. package/src/components/image/image.ts +1 -2
  29. package/src/components/input/input.ts +3 -2
  30. package/src/components/keyboard/keyboard.ts +2 -2
  31. package/src/components/label/label.ts +3 -3
  32. package/src/components/link/link.ts +3 -2
  33. package/src/components/listbox/listbox.module.scss +59 -2
  34. package/src/components/listbox/listbox.ts +133 -23
  35. package/src/components/menu/menu.ts +5 -4
  36. package/src/components/messages/messages.module.scss +95 -3
  37. package/src/components/messages/messages.ts +113 -27
  38. package/src/components/notification/notification.ts +6 -6
  39. package/src/components/panel/panel.ts +2 -2
  40. package/src/components/popup/popup.ts +17 -2
  41. package/src/components/progress/progress.ts +1 -2
  42. package/src/components/propgrid/progrid.module.scss +2 -3
  43. package/src/components/propgrid/propgrid.ts +32 -38
  44. package/src/components/radio/radio.ts +1 -2
  45. package/src/components/rating/rating.ts +2 -2
  46. package/src/components/select/select.ts +2 -2
  47. package/src/components/settingsview/settingsview.module.scss +6 -5
  48. package/src/components/settingsview/settingsview.ts +3 -3
  49. package/src/components/sizers/sizer.ts +21 -29
  50. package/src/components/slider/slider.ts +2 -2
  51. package/src/components/spreadsheet/spreadsheet.ts +8 -10
  52. package/src/components/switch/switch.ts +2 -2
  53. package/src/components/tabs/tabs.ts +4 -4
  54. package/src/components/tag/tag.ts +2 -2
  55. package/src/components/textarea/textarea.ts +3 -3
  56. package/src/components/textedit/textedit.ts +2 -2
  57. package/src/components/themes.scss +2 -0
  58. package/src/components/tickline/tickline.ts +3 -3
  59. package/src/components/tooltips/tooltips.ts +11 -2
  60. package/src/components/treeview/treeview.ts +3 -3
  61. package/src/components/video/video.ts +1 -2
  62. package/src/components/viewport/viewport.ts +4 -3
  63. package/src/core/component.ts +15 -24
  64. package/src/core/core_application.ts +36 -3
  65. package/src/core/core_events.ts +14 -2
  66. package/src/core/core_i18n.ts +67 -0
  67. package/src/core/core_svg.ts +1 -0
  68. package/src/core/core_tools.ts +83 -24
@@ -16,7 +16,6 @@
16
16
 
17
17
  import { Component, ComponentEvent, ComponentEvents } from '../../core/component';
18
18
  import { EventCallback } from '../../core/core_events';
19
- import { class_ns } from '../../core/core_tools';
20
19
 
21
20
  import { BoxProps, HBox, VBox } from '../boxes/boxes';
22
21
  import { Input } from '../input/input';
@@ -43,8 +42,8 @@ export interface SettingItemProps extends BoxProps {
43
42
  * together, put the items in a Form and give the controls a name.
44
43
  */
45
44
 
46
- @class_ns( "x4" )
47
45
  export class SettingItem extends VBox<SettingItemProps> {
46
+ static classPrefix = "x4";
48
47
 
49
48
  constructor( props: SettingItemProps ) {
50
49
  // the content goes under the name and the description, not in the box itself
@@ -112,13 +111,14 @@ function normalize( text: string ) {
112
111
  * --settingsview-toc-width
113
112
  * --settingsview-section-background
114
113
  * --settingsview-section-title-background
114
+ * --settingsview-section-title-color
115
115
  * --settingsview-hover-background
116
116
  * --settingsview-marker
117
117
  * ```
118
118
  */
119
119
 
120
- @class_ns( "x4" )
121
120
  export class SettingsView<P extends SettingsViewProps = SettingsViewProps> extends VBox<P,SettingsViewEvents> {
121
+ static classPrefix = "x4";
122
122
 
123
123
  // fields, not refs: refs belong to the classes that derive from this one
124
124
  private _search: Input = null;
@@ -15,7 +15,7 @@
15
15
  **/
16
16
 
17
17
  import { Component, ComponentEvent, ComponentEvents, ComponentProps, componentFromDOM } from '../../core/component';
18
- import { class_ns, Point } from '../../core/core_tools';
18
+ import { Point } from '../../core/core_tools';
19
19
 
20
20
  import "./sizer.module.scss"
21
21
 
@@ -43,8 +43,8 @@ type SizerType = "left" | "top" | "right" | "bottom" | "top-left" | "top-right"
43
43
  */
44
44
 
45
45
 
46
- @class_ns( "x4" )
47
46
  export class CSizer extends Component<ComponentProps,CSizerEvent> {
47
+ static classPrefix = "x4";
48
48
 
49
49
  private _type: SizerType;
50
50
  private _ref: Component;
@@ -98,6 +98,15 @@ export class CSizer extends Component<ComponentProps,CSizerEvent> {
98
98
  this._ref = null;
99
99
  });
100
100
 
101
+ // cancelled by the browser (a touch taken by a scroll, a gesture...): no pointerup will
102
+ // come, the moves after are not a resize. The browser releases the capture itself
103
+ this.addDOMEvent( "pointercancel", ( ) => {
104
+ if( this._ref ) {
105
+ this.fire( "stop", { })
106
+ this._ref = null;
107
+ }
108
+ });
109
+
101
110
  this.addDOMEvent( "pointermove", ( e: PointerEvent ) => {
102
111
  this._onMouseMove( e );
103
112
  });
@@ -153,36 +162,17 @@ export class CSizer extends Component<ComponentProps,CSizerEvent> {
153
162
  size = nr.width = (pt.x-rc.left);
154
163
  }
155
164
 
156
- const isFlex = ( c : Component ) => {
157
- if( !c ) {
158
- return false;
159
- }
160
-
161
- if( c.hasClass( "x4flex" ) ) {
162
- return true;
163
- }
164
-
165
- return c.getStyleValue( "flexGrow" )!==undefined;
166
- }
167
-
168
- if( this._type.includes("-prev") ) {
169
- if( isFlex(this.prevElement() ) ) {
170
- this._ref.setStyleValue( "flex", `0 0 ${size}px` );
165
+ // between two boxes: the neighbour sized by the basis of its flex; without a neighbour
166
+ // (the sizer first or last in its box), the box itself by its size
167
+ if( this._type.includes("-prev") || this._type.includes("-next") ) {
168
+ const neighbour = this._type.includes("-prev") ? this.prevElement( ) : this.nextElement( );
169
+ if( neighbour ) {
170
+ this._ref.setStyleValue( "flex", `0 0 ${size}px` );
171
171
  }
172
172
  else {
173
173
  this._ref.setStyle( nr );
174
174
  }
175
175
  }
176
- else if( this._type.includes("-next") ) {
177
- if( isFlex(this.nextElement() ) ) {
178
- this._ref.setStyleValue( "flex", `0 0 ${size}px` );
179
- }
180
- else {
181
- this._ref.setStyle( nr );
182
- }
183
-
184
- return;
185
- }
186
176
  else {
187
177
  this._ref.setStyle( nr );
188
178
  }
@@ -195,15 +185,17 @@ export class CSizer extends Component<ComponentProps,CSizerEvent> {
195
185
  }
196
186
  }
197
187
 
198
- @class_ns( "x4" )
199
188
  export class HSizer extends CSizer {
189
+ static classPrefix = "x4";
190
+
200
191
  constructor( next = true ) {
201
192
  super( next ? "hsize-next" : "hsize-prev" );
202
193
  }
203
194
  }
204
195
 
205
- @class_ns( "x4" )
206
196
  export class VSizer extends CSizer {
197
+ static classPrefix = "x4";
198
+
207
199
  constructor( next = true ) {
208
200
  super( next ? "vsize-next" : "vsize-prev" );
209
201
  }
@@ -16,7 +16,7 @@
16
16
 
17
17
  import { EventCallback } from '../../core/core_events';
18
18
  import { Component, ComponentEvents, ComponentProps, EvChange } from '../../core/component';
19
- import { class_ns, IComponentInterface, IFormElement, Rect } from '../../core/core_tools';
19
+ import { IComponentInterface, IFormElement, Rect } from '../../core/core_tools';
20
20
 
21
21
  import { HBox } from '../boxes/boxes';
22
22
  import { Input } from '../input/input';
@@ -49,8 +49,8 @@ interface SliderProps extends ComponentProps {
49
49
  * ```
50
50
  */
51
51
 
52
- @class_ns( "x4" )
53
52
  export class Slider extends Component<SliderProps,SliderEvents> {
53
+ static classPrefix = "x4";
54
54
 
55
55
  private _mdown = false;
56
56
  private _irect: Rect = null;
@@ -18,7 +18,7 @@
18
18
  import { Component, ComponentContent, ComponentEvent, ComponentEvents, ComponentProps, EvChange, EvClick, EvContextMenu, EvDblClick, EvSelectionChange, componentFromDOM } from '../../core/component';
19
19
  import { GridColumn } from '../gridview/gridview'
20
20
 
21
- import { class_ns, IFormElement, isFunction, isNumber, isString, UnsafeHtml } from '../../core/core_tools';
21
+ import { formatDate, formatMoney, formatNumber, IFormElement, isFunction, isNumber, isString, UnsafeHtml } from '../../core/core_tools';
22
22
  import { CoreEvent, EventCallback, EventMap } from '../../core/core_events';
23
23
  import { kbNav } from '../../core/core_tools';
24
24
 
@@ -282,8 +282,8 @@ export interface SpreadsheetProps extends ComponentProps {
282
282
  * ```
283
283
  */
284
284
 
285
- @class_ns("x4")
286
285
  export class Spreadsheet<P extends SpreadsheetProps = SpreadsheetProps, E extends SpreadsheetEvents = SpreadsheetEvents> extends Component<P, E> {
286
+ static classPrefix = "x4";
287
287
 
288
288
  private _columns: SpreadsheetColumn[];
289
289
  private _store: Store;
@@ -310,9 +310,6 @@ export class Spreadsheet<P extends SpreadsheetProps = SpreadsheetProps, E extend
310
310
  private _end: number;
311
311
 
312
312
  private _selection: Set<number>;
313
- private _num_fmt = new Intl.NumberFormat('fr-FR');
314
- private _mny_fmt = new Intl.NumberFormat('fr-FR', { style: 'currency', currency: 'EUR' });
315
- private _dte_fmt = new Intl.DateTimeFormat('fr-FR', {});
316
313
 
317
314
  private _has_fixed: boolean;
318
315
  private _has_footer: boolean;
@@ -821,12 +818,13 @@ export class Spreadsheet<P extends SpreadsheetProps = SpreadsheetProps, E extend
821
818
  })
822
819
 
823
820
  sizer.on("resize", (ev) => {
824
- cdata.width = ev.size;
821
+ const size = Math.max( ev.size, 16 ); // 16px at least: the min-width of a .cell
822
+ cdata.width = size;
825
823
  cdata.flex = 0;
826
824
 
827
825
  const cols = this.queryAll(`[data-col="${col}"]`)
828
826
  cols.forEach(c => {
829
- c.setStyleValue("width", ev.size + "px");
827
+ c.setStyleValue("width", size + "px");
830
828
  });
831
829
 
832
830
  const rh = header.getBoundingRect();
@@ -990,7 +988,7 @@ export class Spreadsheet<P extends SpreadsheetProps = SpreadsheetProps, E extend
990
988
  return "NaN";
991
989
  }
992
990
 
993
- data = this._num_fmt.format(data as number);
991
+ data = formatNumber(data as number);
994
992
  break;
995
993
  }
996
994
 
@@ -999,7 +997,7 @@ export class Spreadsheet<P extends SpreadsheetProps = SpreadsheetProps, E extend
999
997
  return "NaN";
1000
998
  }
1001
999
 
1002
- data = this._mny_fmt.format(data as number);
1000
+ data = formatMoney(data as number);
1003
1001
  break;
1004
1002
  }
1005
1003
 
@@ -1015,7 +1013,7 @@ export class Spreadsheet<P extends SpreadsheetProps = SpreadsheetProps, E extend
1015
1013
  }
1016
1014
 
1017
1015
  case "date": {
1018
- data = this._dte_fmt.format(data as Date);
1016
+ data = formatDate(data as Date);
1019
1017
  break;
1020
1018
  }
1021
1019
 
@@ -22,7 +22,6 @@ import { Label } from '../label/label';
22
22
  import { HBox } from '../boxes/boxes';
23
23
 
24
24
  import "./switch.module.scss";
25
- import { class_ns } from '../../core/core_tools';
26
25
 
27
26
  interface SwitchProps extends ComponentProps {
28
27
  label: string;
@@ -43,8 +42,9 @@ interface SwitchProps extends ComponentProps {
43
42
  * ```
44
43
  */
45
44
 
46
- @class_ns( "x4" )
47
45
  export class Switch extends HBox<SwitchProps> {
46
+ static classPrefix = "x4";
47
+
48
48
  constructor(props: SwitchProps ) {
49
49
  super( props );
50
50
 
@@ -20,7 +20,6 @@ import { Button, ButtonProps } from '../button/button';
20
20
  import { HBox, VBox, StackBox, Box } from '../boxes/boxes';
21
21
 
22
22
  import "./tabs.module.scss"
23
- import { class_ns } from '../../core/core_tools';
24
23
 
25
24
  /**
26
25
  *
@@ -40,8 +39,9 @@ export interface TabItem {
40
39
  *
41
40
  */
42
41
 
43
- @class_ns( "x4" )
44
42
  class CTab extends Button {
43
+ static classPrefix = "x4";
44
+
45
45
  constructor( props: ButtonProps, item: TabItem ) {
46
46
  super( props );
47
47
 
@@ -78,8 +78,8 @@ interface TablistEvents extends ComponentEvents {
78
78
  * @internal
79
79
  */
80
80
 
81
- @class_ns( "x4" )
82
81
  class CTabList extends HBox<TablistProps,TablistEvents> {
82
+ static classPrefix = "x4";
83
83
 
84
84
  private _selitem: Button;
85
85
 
@@ -152,8 +152,8 @@ interface TabsProps extends Omit<ComponentProps,"content"> {
152
152
  * ```
153
153
  */
154
154
 
155
- @class_ns( "x4" )
156
155
  export class Tabs extends Box<TabsProps> {
156
+ static classPrefix = "x4";
157
157
 
158
158
  private _list: CTabList;
159
159
  private _stack: StackBox;
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
  import { ComponentProps } from '../../core/component';
19
- import { class_ns, UnsafeHtml } from '../../core/core_tools';
19
+ import { UnsafeHtml } from '../../core/core_tools';
20
20
  import { HBox } from '../boxes/boxes';
21
21
  import { Icon } from '../icon/icon';
22
22
  import { SimpleText } from '../label/label';
@@ -40,8 +40,8 @@ export interface TagProps extends ComponentProps {
40
40
  * ```
41
41
  */
42
42
 
43
- @class_ns( "x4" )
44
43
  export class Tag extends HBox<TagProps> {
44
+ static classPrefix = "x4";
45
45
 
46
46
  constructor( props: TagProps ) {
47
47
  super( props );
@@ -23,7 +23,7 @@ import { Label } from '../label/label';
23
23
  import { VBox } from '../boxes/boxes';
24
24
 
25
25
  import "./textarea.module.scss";
26
- import { class_ns, IFormElement } from '../../core/core_tools';
26
+ import { IFormElement } from '../../core/core_tools';
27
27
 
28
28
  /**
29
29
  *
@@ -50,8 +50,8 @@ export interface TextAreaEvents extends ComponentEvents {
50
50
  *
51
51
  */
52
52
 
53
- @class_ns( "x4" )
54
53
  export class SimpleTextArea extends Component<SimpleTextAreaProps,TextAreaEvents> {
54
+ static classPrefix = "x4";
55
55
 
56
56
  constructor( props: SimpleTextAreaProps ) {
57
57
  super( { ...props, tag: "textarea" } );
@@ -142,8 +142,8 @@ export class SimpleTextArea extends Component<SimpleTextAreaProps,TextAreaEvents
142
142
  * ```
143
143
  */
144
144
 
145
- @class_ns( "x4" )
146
145
  export class TextArea extends VBox {
146
+ static classPrefix = "x4";
147
147
 
148
148
  private _input: SimpleTextArea;
149
149
 
@@ -16,7 +16,7 @@
16
16
 
17
17
  //import { EventCallback } from '../../core/core_events';
18
18
  import { Component, ComponentEvents, makeUniqueComponentId } from '../../core/component';
19
- import { class_ns, UnsafeHtml } from '../../core/core_tools';
19
+ import { UnsafeHtml } from '../../core/core_tools';
20
20
 
21
21
  import { BoxProps, HBox } from '../boxes/boxes';
22
22
  import { DateProps, Input, InputProps, NumberProps, TextInputProps, TimeProps } from "../input/input"
@@ -81,8 +81,8 @@ interface TextEditProps extends InputProps {
81
81
  * ```
82
82
  */
83
83
 
84
- @class_ns( "x4" )
85
84
  export class TextEdit<E extends ComponentEvents = ComponentEvents> extends HBox<BoxProps,E> {
85
+ static classPrefix = "x4";
86
86
 
87
87
  private input: Input;
88
88
 
@@ -92,9 +92,11 @@ $color--interval: 8.4%;
92
92
  // the red, orange and green do not follow the scale: their text stays white
93
93
  --alert-background: var(--color-danger-a50);
94
94
  --alert-background-active: var(--color-danger-a60);
95
+ --alert-background-light: color-mix(in srgb, var(--alert-background) 15%, transparent); // the red at 15%
95
96
  --alert-color: #ffffff;
96
97
 
97
98
  --warning-background: var(--color-warning-a50);
99
+ --warning-background-light: color-mix(in srgb, var(--warning-background) 15%, transparent); // the orange at 15%
98
100
  --warning-color: #ffffff;
99
101
 
100
102
  --success-background: var(--color-success-a50);
@@ -3,7 +3,7 @@ import { Color } from '../../core/core_colors';
3
3
  import { Component, ComponentProps } from '../../core/component';
4
4
 
5
5
  import "./tickline.module.scss"
6
- import { class_ns } from '../../core/core_tools';
6
+ import { formatNumber } from '../../core/core_tools';
7
7
 
8
8
  export interface TickLineProps extends ComponentProps {
9
9
  values: number[];
@@ -31,8 +31,8 @@ export interface TickLineProps extends ComponentProps {
31
31
  *
32
32
  */
33
33
 
34
- @class_ns( "x4" )
35
34
  export class TickLine extends Component<TickLineProps> {
35
+ static classPrefix = "x4";
36
36
 
37
37
  constructor( props: TickLineProps ) {
38
38
  super( props );
@@ -102,7 +102,7 @@ export class TickLine extends Component<TickLineProps> {
102
102
  .antiAlias( false );
103
103
 
104
104
  if( props.display?.tooltips ) {
105
- r.setAttr( 'tooltip', vals[x].toFixed(1) )
105
+ r.setAttr( 'tooltip', formatNumber( vals[x], 1 ) )
106
106
  }
107
107
  }
108
108
  }
@@ -15,7 +15,7 @@
15
15
  **/
16
16
 
17
17
  import { Component, wrapDOM } from '../../core/component';
18
- import { class_ns, ITipHandler, Point, Rect, Timer, UnsafeHtml, unsafeHtml } from '../../core/core_tools';
18
+ import { ITipHandler, Point, Rect, Timer, UnsafeHtml, unsafeHtml } from '../../core/core_tools';
19
19
 
20
20
  import { HBox } from '../boxes/boxes';
21
21
  import { Popup, PopupProps } from '../popup/popup';
@@ -32,6 +32,15 @@ let mouse_pos: Point = {x:0, y:0 };
32
32
 
33
33
  const timer = new Timer( );
34
34
 
35
+ /**
36
+ * the tooltips are shown once this is called: the text of the attribute "tooltip" (the prop
37
+ * tooltip of a component), or the one getTip( ) of a "tip-handler" gives.
38
+ * This text is shown as html: a text that comes from a user is escaped by the application,
39
+ * with sanitizeHtml( text ).
40
+ * @example
41
+ * new Button( { label: "Open", tooltip: `Open <b>${sanitizeHtml( file.name )}</b>` } );
42
+ */
43
+
35
44
  export function initTooltips( ) {
36
45
 
37
46
  document.addEventListener( "mouseenter", ( ev: MouseEvent ) => {
@@ -108,8 +117,8 @@ function closeTT( ) {
108
117
  * ```
109
118
  */
110
119
 
111
- @class_ns( "x4" )
112
120
  class Tooltip extends Popup {
121
+ static classPrefix = "x4";
113
122
 
114
123
  constructor( props: PopupProps ) {
115
124
  super( props );
@@ -14,7 +14,7 @@
14
14
  * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
15
15
  **/
16
16
 
17
- import { asap, class_ns } from '../../core/core_tools';
17
+ import { asap } from '../../core/core_tools';
18
18
  import { EventCallback } from '../../core/core_events';
19
19
  import { Component, ComponentEvent, ComponentEvents, ComponentProps, EvClick, EvDblClick, EvSelectionChange, componentFromDOM } from '../../core/component';
20
20
 
@@ -84,8 +84,8 @@ export interface TreeviewEvents extends ComponentEvents {
84
84
  * ```
85
85
  */
86
86
 
87
- @class_ns( "x4" )
88
87
  class CTreeViewItem extends Box {
88
+ static classPrefix = "x4";
89
89
 
90
90
  private _item: TreeItem;
91
91
  private _label: Component;
@@ -187,8 +187,8 @@ class CTreeViewItem extends Box {
187
187
  *
188
188
  */
189
189
 
190
- @class_ns( "x4" )
191
190
  export class Treeview extends Component<TreeviewProps,TreeviewEvents> {
191
+ static classPrefix = "x4";
192
192
 
193
193
  private _view: Viewport;
194
194
  private _selection: ListboxID;
@@ -15,7 +15,6 @@
15
15
  **/
16
16
 
17
17
  import { Component, ComponentProps } from '../../core/component';
18
- import { class_ns } from '../../core/core_tools';
19
18
  import { Box } from '../boxes/boxes';
20
19
 
21
20
  import "./video.module.scss"
@@ -31,8 +30,8 @@ interface VideoProps extends ComponentProps {
31
30
  *
32
31
  */
33
32
 
34
- @class_ns( "x4" )
35
33
  export class Video extends Box {
34
+ static classPrefix = "x4";
36
35
 
37
36
  private _vplayer: HTMLVideoElement;
38
37
 
@@ -14,7 +14,6 @@
14
14
  * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
15
15
  **/
16
16
 
17
- import { class_ns } from '../../core/core_tools';
18
17
  import { Component, ComponentProps } from "../../core/component"
19
18
 
20
19
  import "./viewport.module.scss"
@@ -24,8 +23,9 @@ import { Box, BoxProps } from '../components';
24
23
  *
25
24
  */
26
25
 
27
- @class_ns( "x4" )
28
26
  export class Viewport extends Component {
27
+ static classPrefix = "x4";
28
+
29
29
  constructor( props: ComponentProps ) {
30
30
  super( props );
31
31
  }
@@ -35,8 +35,9 @@ export class Viewport extends Component {
35
35
  *
36
36
  */
37
37
 
38
- @class_ns( "x4" )
39
38
  export class ScrollView extends Box {
39
+ static classPrefix = "x4";
40
+
40
41
  constructor( props: BoxProps ) {
41
42
  super( props );
42
43
  this.setContent( new Viewport( {} ) );
@@ -14,7 +14,7 @@
14
14
  * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
15
15
  **/
16
16
 
17
- import { isArray, UnsafeHtml, isNumber, Rect, Constructor, class_ns, x4_class_ns_sym } from './core_tools';
17
+ import { isArray, UnsafeHtml, isNumber, Rect, Constructor } from './core_tools';
18
18
  import { CoreElement } from './core_element';
19
19
  import { AriaAttributes, unitless } from './core_styles';
20
20
  import { CoreEvent, EventMap } from './core_events';
@@ -31,17 +31,19 @@ const FRAGMENT = Symbol( "fragment" );
31
31
  const RE_NUMBER = /^-?\d+(\.\d*)?$/;
32
32
 
33
33
  /**
34
- * you can change css classname prefix by adding
34
+ * the css classes of a component: the name of each class of its chain, in lower case, after
35
+ * the prefix that class declares itself (not the one of its parent):
35
36
  *
36
37
  * ```
37
- * static "$cls-ns" = "<your prefix>";
38
+ * static classPrefix = "<your prefix>";
38
39
  * ```
39
- *
40
- * to your class to avoid autogenerated css class names conflicts
40
+ *
41
+ * every component of x4 declares "x4" (x4button...); the classes of an application have
42
+ * none unless they declare one
41
43
  */
42
44
 
43
45
  function genClassNames( x: any ): string[] {
44
-
46
+
45
47
  let self = Object.getPrototypeOf(x);
46
48
  if( self.constructor==Component ) {
47
49
  return ["x4-comp","x4"];
@@ -50,8 +52,8 @@ function genClassNames( x: any ): string[] {
50
52
  const classes = [];
51
53
  while (self && self.constructor !== Component ) {
52
54
  const clsname:string = self.constructor.name;
53
- const clsns: string = Object.prototype.hasOwnProperty.call(self.constructor,x4_class_ns_sym) ? self.constructor[x4_class_ns_sym] : "";
54
- classes.push( clsns+clsname.toLowerCase() );
55
+ const prefix: string = Object.prototype.hasOwnProperty.call(self.constructor,"classPrefix") ? self.constructor.classPrefix : "";
56
+ classes.push( prefix+clsname.toLowerCase() );
55
57
  self = Object.getPrototypeOf(self);
56
58
  }
57
59
 
@@ -156,9 +158,9 @@ export interface ComponentEvents extends EventMap {
156
158
  * ```
157
159
  */
158
160
 
159
- @class_ns("x4")
160
161
  export class Component<P extends ComponentProps = ComponentProps, E extends ComponentEvents = ComponentEvents>
161
162
  extends CoreElement<E> {
163
+ static classPrefix = "x4";
162
164
 
163
165
  /** The underlying DOM element of the component. */
164
166
  readonly dom: Element;
@@ -907,19 +909,6 @@ export class Component<P extends ComponentProps = ComponentProps, E extends Comp
907
909
  this.setAttribute( "disabled", !ena ? 'true' : null );
908
910
  this.setAttribute( "inert", !ena ? 'true' : null );
909
911
 
910
- /*
911
- boxes are now fieldset, this is native
912
- if( this.dom instanceof HTMLInputElement || this.dom instanceof HTMLButtonElement ) {
913
- this.dom.disabled = !ena;
914
- }
915
-
916
- // propagate enable state to all input children
917
- const nodes = this.enumChildComponents( true );
918
- nodes.forEach( x => {
919
- x.enable( ena );
920
- });
921
- */
922
-
923
912
  return this;
924
913
  }
925
914
 
@@ -1294,8 +1283,9 @@ export function wrapDOM( el: HTMLElement ): Component {
1294
1283
  * Automatically generates CSS class: `x4flex`.
1295
1284
  */
1296
1285
 
1297
- @class_ns( "x4" )
1298
1286
  export class Flex extends Component {
1287
+ static classPrefix = "x4";
1288
+
1299
1289
  constructor( ) {
1300
1290
  super({})
1301
1291
  }
@@ -1311,8 +1301,9 @@ export class Flex extends Component {
1311
1301
  * ```
1312
1302
  */
1313
1303
 
1314
- @class_ns( "x4" )
1315
1304
  export class Space extends Component {
1305
+ static classPrefix = "x4";
1306
+
1316
1307
  constructor( width?: number|string, cls?: string ) {
1317
1308
  super( { width, cls } )
1318
1309
  }
@@ -19,6 +19,7 @@ import { CoreElement } from './core_element';
19
19
  import { CoreEvent, EventMap } from './core_events';
20
20
  import { asap, getFocusableElements, ITabHandler } from './core_tools';
21
21
  import { Shortcuts, ShortcutCallback, ShortcutOptions } from './core_shortcuts';
22
+ import { _setLocale, getCurrentLocale, getCurrentCurrency } from './core_i18n';
22
23
 
23
24
  const socket_sent = Symbol( 'socket' );
24
25
 
@@ -249,13 +250,44 @@ export class Application<E extends ApplicationEvents = ApplicationEvents> extend
249
250
  }
250
251
 
251
252
  /**
252
- *
253
+ * Forces the locale of the formats of numbers, amounts and dates (formatNumber, formatMoney,
254
+ * formatDate, formatDateTime), and the currency of the amounts. Without it, the locale is the one of the language (`_tr.global.locale`: "fr-FR"
255
+ * for fr, "en-US" for en...) and the currency "EUR".
256
+ * A field of type number is shown by the browser, in its own locale, whatever this one.
257
+ * @param locale - "fr-CH", "en-GB"...; null: the one of the language again
258
+ * @param currency - "CHF", "USD"...; not given: the currency does not change
259
+ * @example
260
+ * Application.setLocale( "fr-CH", "CHF" );
261
+ */
262
+
263
+ static setLocale( locale: string, currency?: string ) {
264
+ _setLocale( locale, currency );
265
+ }
266
+
267
+ /** The locale of the formats: the one forced by setLocale, else the one of the language. */
268
+
269
+ static getLocale( ): string {
270
+ return getCurrentLocale( );
271
+ }
272
+
273
+ /** The currency of the amounts: "EUR" unless setLocale gave another. */
274
+
275
+ static getCurrency( ): string {
276
+ return getCurrentCurrency( );
277
+ }
278
+
279
+ /**
280
+ *
253
281
  */
254
282
 
255
283
  private _setupKeyboard( ) {
256
284
 
257
285
  document.addEventListener( "keydown", (ev) => {
258
- if( ev.key=="Tab" || ev.key=="Enter" ) {
286
+ // Enter in a text of several lines is a new line, not the next field
287
+ const target = ev.target as HTMLElement;
288
+ const multiline = target.tagName==="TEXTAREA" || target.isContentEditable;
289
+
290
+ if( ev.key=="Tab" || ( ev.key=="Enter" && !multiline ) ) {
259
291
  if( this.focusNext( !ev.shiftKey ) ) {
260
292
  ev.preventDefault( );
261
293
  }
@@ -263,7 +295,8 @@ export class Application<E extends ApplicationEvents = ApplicationEvents> extend
263
295
 
264
296
  // The focus is nowhere: the shortcuts of the view the user worked in last.
265
297
  // (when it is in a view, the view has seen the key before us)
266
- if( ev.target===document.body && this._active?.owner.dom.isConnected && this._active.shortcuts.handle( ev ) ) {
298
+ // (a view hidden, in a tab not shown: its shortcuts sleep)
299
+ if( ev.target===document.body && this._active?.owner.isVisible( ) && this._active.shortcuts.handle( ev ) ) {
267
300
  return;
268
301
  }
269
302