x4js 2.2.64 → 2.2.66

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x4js",
3
- "version": "2.2.64",
3
+ "version": "2.2.66",
4
4
  "type": "module",
5
5
  "main": "src/x4.ts",
6
6
  "module": "src/x4.ts",
@@ -70,11 +70,13 @@
70
70
 
71
71
  &> .x4button {
72
72
  min-width: 80px;
73
+ #label {
74
+ white-space: nowrap;
75
+ }
73
76
 
74
77
  .x-simple-label {
75
78
  text-align: center;
76
79
  }
77
-
78
80
  }
79
81
  }
80
82
  }
@@ -21,18 +21,18 @@
21
21
  }
22
22
 
23
23
  .x4form {
24
- @extend %vbox;
24
+ @extend %vbox;
25
25
  @extend %flex;
26
-
27
- padding: 16px;
26
+
27
+ padding: 16px;
28
28
  background-color: var( --color-form );
29
+
30
+ &.horizontal {
31
+ flex-direction: row;
32
+ }
29
33
 
30
34
  &.no-flex {
31
35
  flex-grow: 0;
32
36
  }
33
-
34
- &>.xcontainer {
35
-
36
- }
37
37
  }
38
38
 
@@ -431,8 +431,11 @@ class CMover {
431
431
  this.self = ref ? true : false;
432
432
 
433
433
  const mouseDown = ( e: PointerEvent ) => {
434
- if( this.self && e.target && (e.target as HTMLElement).tagName!=="DIV" ) {
435
- return;
434
+ if( this.self && e.target ) {
435
+ const clickable = (e.target as HTMLElement).closest('button, input, a, [role="button"]');
436
+ if( clickable ) {
437
+ return;
438
+ }
436
439
  }
437
440
 
438
441
  x.setCapture( e.pointerId );
@@ -43,48 +43,66 @@
43
43
  .group {
44
44
  padding: 6px 4px 4px 4px;
45
45
  min-height: 2em;
46
- font-weight: bold;
47
- background-color: white;
48
- color: var(--color-primary-a50);
49
-
50
- .x4box > .desc {
51
- font-style: italic;
52
- font-weight: normal;
53
- font-size: 90%;
54
- color: var( --text-ternary );
55
- }
56
-
57
- &:not(:first-child ) {
58
- border-top: 1px solid var(--color-primary-a50);
59
- }
60
-
61
- &:not( :last-child ) {
62
- border-bottom: 1px solid var(--color-primary-a50);
63
- //box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.2);
64
- }
65
-
66
- display: flex;
46
+ background-color: var( --background-secondary );
47
+ margin-bottom: 8px;
48
+ box-shadow: 4px 3px 8px rgba(0, 0, 0, 0.4);
49
+ color: var(--color-primary-a50);
50
+ display: flex;
67
51
  align-items: center;
68
- padding-left: 8px;
52
+ padding: 8px;
69
53
  gap: 8px;
70
54
 
71
- &>.x4box {
72
- flex-grow: 1;
73
- }
55
+ &.sticky {
56
+ position: sticky;
57
+ top: 0;
58
+ z-index: 1;
59
+ }
60
+
61
+ .hdr {
62
+ &>.gadgets {
63
+ gap: 8px;
64
+ &> .x4 {
65
+ margin: 0;
66
+ padding: 0;
67
+ }
68
+ }
74
69
 
75
- &>.x4icon {
76
- .fa-secondary,
77
- .fa-primary {
78
- fill: var( --color-primary-a50 );
79
- }
70
+ .title {
71
+ font-weight: bold;
72
+ }
73
+
74
+ &>.x4button {
75
+ background-color: transparent;
76
+ color: var(--color-primary-a50);
77
+ }
78
+
79
+ &>.x4label {
80
+ .x4icon {
81
+ .fa-secondary,
82
+ .fa-primary {
83
+ fill: var( --color-primary-a50 );
84
+ }
85
+
86
+ width: 1em;
87
+ height: 1em;
88
+ }
89
+ }
90
+ }
80
91
 
81
- width: 1em;
82
- height: 1em;
92
+ &>.desc {
93
+ font-style: italic;
94
+ font-weight: normal;
95
+ font-size: 90%;
96
+ color: var( --text-ternary );
97
+ }
98
+
99
+ &:not(:first-child ) {
100
+ //border-top: 1px solid var(--color-primary-a50);
83
101
  }
84
102
 
85
- &>.x4button {
86
- background-color: transparent;
87
- color: var(--color-primary-a50);
103
+ &:not( :last-child ) {
104
+ border-bottom: 1px solid var(--color-primary-a50);
105
+ //box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.2);
88
106
  }
89
107
  }
90
108
 
@@ -50,10 +50,12 @@ export interface PropertyValue {
50
50
  export interface PropertyGroup {
51
51
  title: string;
52
52
  desc?: string;
53
+ name?: string;
53
54
  icon?: string;
54
55
  cls?: string;
55
56
  collapsible?: boolean | number; // -1 for collapsible+collapsed
56
57
  items: PropertyValue[];
58
+ gadgets?: Component[];
57
59
  }
58
60
 
59
61
  export interface PropertyProps extends ComponentProps {
@@ -118,6 +120,9 @@ export class PropertyGrid extends VBox {
118
120
  if( i ) {
119
121
  const row = this.makePropertyRow(i);
120
122
  row.addClass( idx&1 ? "even" : "odd" );
123
+ if( g.name ) {
124
+ row.setData( "group", g.name );
125
+ }
121
126
 
122
127
  items.push( row );
123
128
  }
@@ -163,13 +168,16 @@ export class PropertyGrid extends VBox {
163
168
 
164
169
  const tr = new HBox({
165
170
  cls,
171
+ flex: 1,
166
172
  content: [
167
- g.icon ? new Icon({ id: "icon", iconId: g.icon }) : null,
168
- new VBox( { content: [
169
- new SimpleText({ cls: "title", text: g.title }),
170
- g.desc ? new SimpleText({ cls: "desc", text: g.desc }) : null,
171
- ]}),
172
- g.collapsible? new Button({ icon: icons.updown, click: (e) => toggle(tr) }) : null,
173
+ new VBox( { flex: 1, content: [
174
+ new HBox( { cls: 'hdr', content: [
175
+ new Label({ flex:1, cls: "title", text: g.title, icon: g.icon }),
176
+ g.gadgets ? new HBox( { cls: 'gadgets', content: g.gadgets } ) : null,
177
+ g.collapsible? new Button({ icon: icons.updown, click: (e) => toggle(tr) }) : null,
178
+ ]}),
179
+ g.desc ? new SimpleText({ cls: "desc", text: g.desc }) : null,
180
+ ]}),
173
181
  ]
174
182
  });
175
183
 
@@ -352,5 +360,10 @@ export class PropertyGrid extends VBox {
352
360
  this.setPropValue( p, props[p] );
353
361
  }
354
362
  }
363
+
364
+ enableGroup( group_name: string, ena = true ) {
365
+ const els = this.queryAll( `.row[data-group="${group_name}"]` );
366
+ els.forEach( x => x.enable( ena ) );
367
+ }
355
368
  }
356
369
 
@@ -45,13 +45,12 @@ const RE_NUMBER = /^-?\d+(\.\d*)?$/;
45
45
 
46
46
  function genClassNames( x: any ): string[] {
47
47
 
48
- const classes = [];
49
48
  let self = Object.getPrototypeOf(x);
50
-
51
49
  if( self.constructor==Component ) {
52
- return ["x4-comp"];
50
+ return ["x4-comp","x4"];
53
51
  }
54
52
 
53
+ const classes = [];
55
54
  while (self && self.constructor !== Component ) {
56
55
  const clsname:string = self.constructor.name;
57
56
  const clsns: string = Object.prototype.hasOwnProperty.call(self.constructor,x4_class_ns_sym) ? self.constructor[x4_class_ns_sym] : "";
@@ -59,6 +58,7 @@ function genClassNames( x: any ): string[] {
59
58
  self = Object.getPrototypeOf(self);
60
59
  }
61
60
 
61
+ classes.push( "x4" );
62
62
  return classes;
63
63
  }
64
64
 
@@ -8,7 +8,7 @@
8
8
  * @file core_data.ts
9
9
  * @author Etienne Cochard
10
10
  *
11
- * @copyright (c) 2026 R-libre ingenierie
11
+ * @copyright (c) 2024 R-libre ingenierie
12
12
  *
13
13
  * Use of this source code is governed by an MIT-style license
14
14
  * that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
@@ -78,7 +78,18 @@ const metaFields = Symbol( 'metaField' );
78
78
  function _getMetas( obj: object, create = true ) : MetaInfos {
79
79
 
80
80
  let ctor = obj.constructor as any;
81
- let mfld = Object.prototype.hasOwnProperty.call(ctor,metaFields) ? ctor[metaFields] : undefined;
81
+ let mfld = null;
82
+ let direct = false;
83
+
84
+ // comming from new DataModel(...)
85
+ if( ctor.name=="DataModel" ) {
86
+ direct = true;
87
+ mfld = (obj as any)[metaFields];
88
+ }
89
+ // standard @data....
90
+ else {
91
+ mfld = Object.prototype.hasOwnProperty.call(ctor,metaFields) ? ctor[metaFields] : undefined;
92
+ }
82
93
 
83
94
  if( mfld===undefined ) {
84
95
  if( !create && ctor!=DataModel ) {
@@ -102,7 +113,12 @@ function _getMetas( obj: object, create = true ) : MetaInfos {
102
113
  }
103
114
  }
104
115
 
105
- (obj.constructor as any)[metaFields] = mfld;
116
+ if( !direct ) {
117
+ (obj.constructor as any)[metaFields] = mfld;
118
+ }
119
+ else {
120
+ (obj as any)[metaFields] = mfld;
121
+ }
106
122
  }
107
123
 
108
124
  return mfld;
@@ -119,17 +135,17 @@ export namespace data {
119
135
  **/
120
136
 
121
137
  export function id( ) {
122
- return ( ownerCls: any, fldName: string ) => {
123
- let metas = _getMetas( ownerCls );
124
- metas.fields.push( {
125
- name: fldName,
126
- type: 'any',
127
- required: true,
128
- });
129
-
130
- metas.id = fldName;
131
- }
132
- }
138
+ return ( ownerCls: any, fldName: string ) => {
139
+ let metas = _getMetas( ownerCls );
140
+ metas.fields.push( {
141
+ name: fldName,
142
+ type: 'any',
143
+ required: true,
144
+ });
145
+
146
+ metas.id = fldName;
147
+ }
148
+ }
133
149
 
134
150
  /**
135
151
  * @ignore
@@ -254,12 +270,6 @@ export namespace data {
254
270
 
255
271
  export class DataModel<T = any> {
256
272
 
257
- constructor( fields?: FieldInfo[] ) {
258
- if( fields && fields.length ) {
259
- this.addField( ...fields );
260
- }
261
- }
262
-
263
273
  /**
264
274
  * dynamic DataModel
265
275
  */
@@ -270,11 +280,11 @@ export class DataModel<T = any> {
270
280
  }
271
281
 
272
282
  let metas = _getMetas( this, false );
273
- if( metas.fields.length==0 ) {
283
+ metas.fields.push( ...fields );
284
+
285
+ if( !metas.id ) {
274
286
  metas.id = fields[0].name;
275
287
  }
276
-
277
- metas.fields.push( ...fields );
278
288
  }
279
289
 
280
290
  /**
@@ -523,24 +533,16 @@ export class DataProxy extends CoreElement<DataEventMap> {
523
533
  url += '?' + this.m_props.params.join( '&' );
524
534
  }
525
535
 
526
- try {
527
- const r = await fetch( url );
528
- if( r.ok ) {
529
- const raw = await r.json( );
530
-
531
- let json = raw;
532
- if( this.m_props.solver ) {
533
- json = this.m_props.solver( json );
534
- }
535
-
536
- this.fire( 'change', {value:json,context:raw} );
537
- }
538
- else {
539
- console.error( r.statusText );
536
+ const r = await fetch( url );
537
+ if( r.ok ) {
538
+ const raw = await r.json( );
539
+
540
+ let json = raw;
541
+ if( this.m_props.solver ) {
542
+ json = this.m_props.solver( json );
540
543
  }
541
- }
542
- catch( e ) {
543
- console.error( e );
544
+
545
+ this.fire( 'change', {value:json,context:raw} );
544
546
  }
545
547
  }
546
548
  }
@@ -608,6 +610,7 @@ export class DataStore<T = any> extends EventSource<DataStoreEventMap> {
608
610
 
609
611
  /**
610
612
  *
613
+ * @param records
611
614
  */
612
615
 
613
616
  async load( url?: string ) {
@@ -671,7 +674,7 @@ export class DataStore<T = any> extends EventSource<DataStoreEventMap> {
671
674
 
672
675
  /**
673
676
  *
674
- * @param rec
677
+ * @param data
675
678
  */
676
679
 
677
680
  public appendRaw( rec: T ) {
@@ -1211,6 +1214,8 @@ export class DataView extends CoreElement<DataViewEventMap>
1211
1214
 
1212
1215
  /**
1213
1216
  *
1217
+ * @param columns
1218
+ * @param ascending
1214
1219
  */
1215
1220
 
1216
1221
  public sort( props: SortProp[] ) {