x4js 2.2.53 → 2.2.55
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 +1 -1
- package/src/components/boxes/boxes.module.scss +509 -27
- package/src/components/boxes/boxes.ts +32 -3
- package/src/components/header/header.ts +14 -3
- package/src/components/label/label.module.scss +20 -0
- package/src/components/panel/panel.module.scss +2 -0
- package/src/components/select/select.module.scss +11 -0
- package/src/components/sizers/sizer.ts +40 -8
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* / \____ _|
|
|
6
6
|
* /__/\__\ |_|
|
|
7
7
|
*
|
|
8
|
-
* @file boxes.
|
|
8
|
+
* @file boxes.ts
|
|
9
9
|
* @author Etienne Cochard
|
|
10
10
|
*
|
|
11
11
|
* @copyright (c) 2026 R-libre ingenierie
|
|
@@ -14,47 +14,529 @@
|
|
|
14
14
|
* that can be found in the LICENSE file or at https://opensource.org/licenses/MIT.
|
|
15
15
|
**/
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
import { asap, class_ns, isArray, isNumber } from '../../core/core_tools';
|
|
18
|
+
import { Component, ComponentEvents, ComponentProps, EvSelectionChange } from "../../core/component"
|
|
19
|
+
import { EventCallback } from '../../core/core_events';
|
|
18
20
|
|
|
19
|
-
.
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
import "./boxes.module.scss";
|
|
22
|
+
|
|
23
|
+
export interface BoxProps extends ComponentProps {
|
|
24
|
+
/** Optional HTML tag to use for the box. */
|
|
25
|
+
tag?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* A generic container component for grouping and laying out child components.
|
|
30
|
+
*
|
|
31
|
+
* The `refs` object is a typed directory of the children you need to reach
|
|
32
|
+
* again later. Assign a child to `refs` as you build the content: the
|
|
33
|
+
* assignment expression evaluates to the component itself, so it can be
|
|
34
|
+
* inlined directly in the content array.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* using refs: in your code, you can type
|
|
38
|
+
*
|
|
39
|
+
* class MyBox extends Box {
|
|
40
|
+
* declare refs: {
|
|
41
|
+
* a: Combobox;
|
|
42
|
+
* b: Input;
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* constructor( props ) {
|
|
46
|
+
* super( props );
|
|
47
|
+
*
|
|
48
|
+
* this.setContent( [
|
|
49
|
+
* this.refs.a = new ComboBox( { ... } );
|
|
50
|
+
* this.refs.b = new Input( { ... } );
|
|
51
|
+
* ])
|
|
52
|
+
*
|
|
53
|
+
* onSomeEvent() {
|
|
54
|
+
* this.refs.a.getValue();
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
*
|
|
59
|
+
*
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
@class_ns( "x4" )
|
|
63
|
+
export class Box<P extends BoxProps=BoxProps,E extends ComponentEvents=ComponentEvents> extends Component<P,E> {
|
|
64
|
+
protected refs: Record<string,Component> = {};
|
|
23
65
|
}
|
|
24
66
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* A horizontal box layout component.
|
|
70
|
+
* Arranges child components in a horizontal line.
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
@class_ns( "x4" )
|
|
74
|
+
export class HBox<P extends BoxProps=BoxProps,E extends ComponentEvents=ComponentEvents> extends Box<P,E> {
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* A vertical box layout component.
|
|
79
|
+
* Arranges child components in a vertical stack.
|
|
80
|
+
* The CSS class for this component is automatically generated as `x4vbox`.
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
@class_ns( "x4" )
|
|
84
|
+
export class VBox<P extends BoxProps=BoxProps,E extends ComponentEvents=ComponentEvents> extends Box<P,E> {
|
|
85
|
+
constructor( p: P ) {
|
|
86
|
+
super( p );
|
|
29
87
|
}
|
|
30
88
|
}
|
|
31
89
|
|
|
32
|
-
|
|
33
|
-
|
|
90
|
+
|
|
91
|
+
type ContentBuilder = ( ) => Component;
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Represents an item in a {@link StackBox}.
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
interface StackItem {
|
|
99
|
+
/** Unique name for the stack item. */
|
|
100
|
+
name: string;
|
|
101
|
+
/** Content of the stack item, either a component or a builder function. */
|
|
102
|
+
content: Component | ContentBuilder;
|
|
103
|
+
title?: string;
|
|
34
104
|
}
|
|
35
105
|
|
|
36
|
-
|
|
37
|
-
|
|
106
|
+
/**
|
|
107
|
+
* Events specific to the {@link StackBox} component.
|
|
108
|
+
*/
|
|
109
|
+
|
|
110
|
+
interface StackeBoxEvents extends ComponentEvents {
|
|
111
|
+
/** Fired when the current page changes. */
|
|
112
|
+
pageChange?: EvSelectionChange;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Properties for the {@link StackBox} component.
|
|
117
|
+
*/
|
|
118
|
+
|
|
119
|
+
export interface StackBoxProps extends Omit<ComponentProps,"content"> {
|
|
120
|
+
/** Name of the default page to display. */
|
|
121
|
+
default: string;
|
|
122
|
+
|
|
123
|
+
/** List of stack items. */
|
|
124
|
+
items: StackItem[];
|
|
125
|
+
|
|
126
|
+
/** Callback for page change events. */
|
|
127
|
+
pageChange?: EventCallback<EvSelectionChange>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
interface StackItemEx extends StackItem {
|
|
132
|
+
page: Component;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A stack of widgets where only one widget is visible at a time.
|
|
137
|
+
* The CSS class for this component is automatically generated as `x4stackbox`.
|
|
138
|
+
*/
|
|
139
|
+
|
|
140
|
+
@class_ns( "x4" )
|
|
141
|
+
export class StackBox<P extends StackBoxProps = StackBoxProps, E extends StackeBoxEvents = StackeBoxEvents> extends Box<StackBoxProps,StackeBoxEvents> {
|
|
38
142
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
143
|
+
protected _items: StackItemEx[];
|
|
144
|
+
protected _cur: number;
|
|
145
|
+
|
|
146
|
+
constructor( props: StackBoxProps ) {
|
|
147
|
+
super( props );
|
|
148
|
+
|
|
149
|
+
this.mapPropEvents( props, "pageChange" );
|
|
150
|
+
|
|
151
|
+
this._items = props.items?.map( itm => {
|
|
152
|
+
return { ...itm, page: null as any};
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
if( props.default ) {
|
|
156
|
+
this.select( props.default );
|
|
157
|
+
}
|
|
158
|
+
else if( this._items.length ) {
|
|
159
|
+
this.select( this._items[0].name );
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Adds a new item to the stack.
|
|
165
|
+
* @param item - The item to add.
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
addItem( item: StackItem ) {
|
|
169
|
+
this._items.push( {
|
|
170
|
+
name: item.name,
|
|
171
|
+
content: item.content,
|
|
172
|
+
page: null
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Removes an item from the stack by its name.
|
|
178
|
+
* @param name - The name of the item to remove.
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
removeItem( name: string ) {
|
|
182
|
+
const index = this._items.findIndex( x => x.name==name );
|
|
183
|
+
if( index>=0 ) {
|
|
184
|
+
const pg = this._items[index];
|
|
185
|
+
if( pg?.page ) {
|
|
186
|
+
this.removeChild( pg.page );
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
this._items.splice( index, 1 );
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Selects a page by its name.
|
|
195
|
+
* @param name - The name of the page to select.
|
|
196
|
+
* @returns The selected page component, if any.
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
select( name: string ) {
|
|
200
|
+
let sel = this.query( `:scope > .selected` );
|
|
201
|
+
if( sel ) {
|
|
202
|
+
sel.setClass( "selected", false );
|
|
203
|
+
(sel as any).deactivate?.( );
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
this._cur = this._items.findIndex( x => x.name==name );
|
|
207
|
+
const pg = this._items[this._cur];
|
|
208
|
+
|
|
209
|
+
if( pg ) {
|
|
210
|
+
if( !pg.page ) {
|
|
211
|
+
pg.page = this._createPage( pg );
|
|
212
|
+
this.appendContent( pg.page );
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
sel = pg.page;
|
|
216
|
+
if( sel ) {
|
|
217
|
+
(sel as any).activate?.( );
|
|
218
|
+
sel.setClass( "selected", true );
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
asap( ( ) => this.fire( "pageChange", { selection: [pg.name], empty: !sel } ) );
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return pg?.page;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
*
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
private _createPage( page: StackItemEx ) {
|
|
232
|
+
|
|
233
|
+
let content: Component;
|
|
234
|
+
if( page.content instanceof Function ) {
|
|
235
|
+
content = page.content( );
|
|
236
|
+
page.content = content; // keep it
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
content = page.content;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
content?.setData( "stackname", page.name );
|
|
243
|
+
return content;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Retrieves a page by its name.
|
|
248
|
+
* @param name - The name of the page to retrieve.
|
|
249
|
+
* @returns The page content, if found.
|
|
250
|
+
*/
|
|
251
|
+
|
|
252
|
+
getPage( name: string ) {
|
|
253
|
+
const pg = this._items.find( x => x.name==name );
|
|
254
|
+
return pg ? pg.content : null;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Gets the total number of pages in the stack.
|
|
259
|
+
* @returns The number of pages.
|
|
260
|
+
*/
|
|
261
|
+
|
|
262
|
+
getPageCount( ) {
|
|
263
|
+
return this._items.length;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Enumerates the names of all pages in the stack.
|
|
268
|
+
* @returns An array of page names.
|
|
269
|
+
*/
|
|
270
|
+
|
|
271
|
+
enumPageNames( ) {
|
|
272
|
+
return this._items.map( x => x.name );
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Retrieves a stack item by its name.
|
|
277
|
+
* @param name - The name of the item to retrieve.
|
|
278
|
+
* @returns The stack item, if found.
|
|
279
|
+
*/
|
|
280
|
+
|
|
281
|
+
getItem( name: string ) {
|
|
282
|
+
const pg = this._items.find( x => x.name==name );
|
|
283
|
+
return pg;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Gets the name of the currently selected page.
|
|
288
|
+
* @returns The name of the current page, if any.
|
|
289
|
+
*/
|
|
290
|
+
|
|
291
|
+
getCurPage( ) {
|
|
292
|
+
const c = this._items[this._cur];
|
|
293
|
+
return c?.name;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// :: ASSIST BOX ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* A specialized stack box for assisted navigation, such as wizards or carousels.
|
|
302
|
+
* The CSS class for this component is automatically generated as `x4assistbox`.
|
|
303
|
+
*/
|
|
304
|
+
|
|
305
|
+
@class_ns( "x4" )
|
|
306
|
+
export class AssistBox extends StackBox {
|
|
307
|
+
|
|
308
|
+
/**
|
|
309
|
+
* Selects the next or previous page in the stack.
|
|
310
|
+
* @param nxt - If `true`, selects the next page; otherwise, selects the previous page.
|
|
311
|
+
*/
|
|
312
|
+
|
|
313
|
+
selectNextPage( nxt = true ) {
|
|
314
|
+
let p;
|
|
315
|
+
if( nxt && this._cur<this._items.length-1 ) {
|
|
316
|
+
p = this._items[this._cur+1];
|
|
317
|
+
}
|
|
318
|
+
else if( !nxt && this._cur>0 ) {
|
|
319
|
+
p = this._items[this._cur-1];
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if( p ) {
|
|
323
|
+
this.select( p.name );
|
|
324
|
+
}
|
|
42
325
|
}
|
|
43
326
|
|
|
44
|
-
|
|
45
|
-
|
|
327
|
+
/**
|
|
328
|
+
* Checks if the current page is the first page.
|
|
329
|
+
* @returns `true` if the current page is the first page.
|
|
330
|
+
*/
|
|
331
|
+
|
|
332
|
+
isFirstPage( ) {
|
|
333
|
+
return this._cur==0;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Checks if the current page is the last page.
|
|
338
|
+
* @returns `true` if the current page is the last page.
|
|
339
|
+
*/
|
|
340
|
+
|
|
341
|
+
isLastPage( ) {
|
|
342
|
+
return this._cur==this._items.length-1;
|
|
46
343
|
}
|
|
47
344
|
}
|
|
48
345
|
|
|
49
|
-
|
|
50
|
-
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
// :: GRIDBOX ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
349
|
+
|
|
350
|
+
interface GridBoxItem {
|
|
351
|
+
row: number; // starts at 0
|
|
352
|
+
col: number; // starts at 0
|
|
353
|
+
item: Component;
|
|
51
354
|
}
|
|
52
355
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
356
|
+
export interface GridBoxProps extends Omit<BoxProps,"content"> {
|
|
357
|
+
rows?: number | string | string[];
|
|
358
|
+
columns?: number | string | string[];
|
|
359
|
+
items?: GridBoxItem[];
|
|
360
|
+
}
|
|
58
361
|
|
|
59
|
-
|
|
362
|
+
/**
|
|
363
|
+
* Grid-based layout container.
|
|
364
|
+
* Auto-generates CSS class: `x4gridbox`.
|
|
365
|
+
*/
|
|
366
|
+
|
|
367
|
+
@class_ns("x4")
|
|
368
|
+
export class GridBox<P extends GridBoxProps=GridBoxProps,E extends ComponentEvents=ComponentEvents> extends Box<P,E> {
|
|
369
|
+
|
|
370
|
+
constructor( props: P ) {
|
|
371
|
+
super( props );
|
|
372
|
+
|
|
373
|
+
if( props.rows!==undefined ) {
|
|
374
|
+
this.setRows( props.rows );
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
if( props.columns!==undefined ) {
|
|
378
|
+
this.setCols( props.columns );
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
if( props.items ) {
|
|
382
|
+
this.setItems( props.items );
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Sets grid rows (e.g., `2`, `"1fr 2fr"`, `["1fr", "2fr"]`).
|
|
388
|
+
* @param r - Rows definition.
|
|
389
|
+
*/
|
|
390
|
+
|
|
391
|
+
setRows( r: number | string | string[] ) {
|
|
392
|
+
if( isArray(r) ) {
|
|
393
|
+
r = r.join( " " );
|
|
394
|
+
}
|
|
395
|
+
else if( isNumber(r) ) {
|
|
396
|
+
r = `repeat( ${r}, 1fr )`;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
this.setStyleValue( "gridTemplateRows", r );
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Sets grid columns (e.g., `3`, `"1fr 1fr"`, `["auto", "1fr"]`).
|
|
404
|
+
* @param r - Columns definition.
|
|
405
|
+
*/
|
|
406
|
+
|
|
407
|
+
setCols( r: number | string | string[] ) {
|
|
408
|
+
if( isArray(r) ) {
|
|
409
|
+
r = r.join( " " );
|
|
410
|
+
}
|
|
411
|
+
else if( isNumber(r) ) {
|
|
412
|
+
r = `repeat( ${r}, 1fr )`;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
this.setStyleValue( "gridTemplateColumns", r );
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Sets the number of rows.
|
|
420
|
+
* @param n - Row count.
|
|
421
|
+
*/
|
|
422
|
+
|
|
423
|
+
setRowCount( n: number ) {
|
|
424
|
+
this.setStyleValue( "gridTemplateRows", `repeat(${n})` );
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Sets the number of columns.
|
|
429
|
+
* @param n - Column count.
|
|
430
|
+
*/
|
|
431
|
+
|
|
432
|
+
setColCount( n: number ) {
|
|
433
|
+
this.setStyleValue( "gridTemplateColumns", `repeat(${n})` );
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Sets grid template areas (e.g., `["a a", "b c"]`).
|
|
438
|
+
* @param t - Template strings.
|
|
439
|
+
*/
|
|
440
|
+
|
|
441
|
+
setTemplate( t: string[] ) {
|
|
442
|
+
this.setAttribute( "grid-template-area", t.map( x => '"' + x + '"' ).join(" ") );
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Places items at specific grid positions.
|
|
447
|
+
* @param items - Array of `{row, col, item}`.
|
|
448
|
+
*/
|
|
449
|
+
|
|
450
|
+
setItems( items: GridBoxItem[] ) {
|
|
451
|
+
items.forEach( x => {
|
|
452
|
+
x.item.setStyle( {
|
|
453
|
+
gridColumn: (x.col+1)+"",
|
|
454
|
+
gridRow: (x.row+1)+"",
|
|
455
|
+
} );
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
this.setContent( items.map( x => x.item ) );
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
// :: MASONRY ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
|
|
464
|
+
|
|
465
|
+
// from a nice article of Andy Barefoot
|
|
466
|
+
// https://medium.com/@andybarefoot/a-masonry-style-layout-using-css-grid-8c663d355ebb
|
|
467
|
+
|
|
468
|
+
interface MasonryProps extends Omit<BoxProps,"content"> {
|
|
469
|
+
items: Component[];
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Masonry-style layout (Pinterest-like).
|
|
474
|
+
* Auto-generates CSS class: `x4masonrybox`.
|
|
475
|
+
*/
|
|
476
|
+
|
|
477
|
+
@class_ns("x4")
|
|
478
|
+
export class MasonryBox extends Box<MasonryProps> {
|
|
479
|
+
|
|
480
|
+
constructor(props: MasonryProps ) {
|
|
481
|
+
super(props);
|
|
482
|
+
|
|
483
|
+
this.addDOMEvent( 'resized', () => {
|
|
484
|
+
this.resizeAllItems( );
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
if( props.items ) {
|
|
488
|
+
this.setItems( props.items );
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
/**
|
|
493
|
+
* Resizes a single masonry item.
|
|
494
|
+
* @param item - Item to resize.
|
|
495
|
+
*/
|
|
496
|
+
|
|
497
|
+
resizeItem(item: Component) {
|
|
498
|
+
const style = this.getComputedStyle();
|
|
499
|
+
|
|
500
|
+
const rowHeight = parseInt(style['gridAutoRows']);
|
|
501
|
+
const rowGap = parseInt(style['rowGap']);
|
|
502
|
+
|
|
503
|
+
let content = item.query('.content');
|
|
504
|
+
if( !content ) {
|
|
505
|
+
content = item;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
if (content && (rowHeight + rowGap)) {
|
|
509
|
+
const rc = content.getBoundingRect();
|
|
510
|
+
const rowSpan = Math.ceil( (rc.height + rowGap) / (rowHeight + rowGap) );
|
|
511
|
+
item.setStyleValue('gridRowEnd', "span " + rowSpan);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
/**
|
|
516
|
+
* Resizes all items to fit the grid.
|
|
517
|
+
*/
|
|
518
|
+
|
|
519
|
+
resizeAllItems( ) {
|
|
520
|
+
const els = this.queryAll( ".item" );
|
|
521
|
+
els.forEach( itm => {
|
|
522
|
+
this.resizeItem( itm );
|
|
523
|
+
} );
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
/**
|
|
527
|
+
* Sets masonry items.
|
|
528
|
+
* @param items - Array of components.
|
|
529
|
+
*/
|
|
530
|
+
|
|
531
|
+
setItems( items: Component[] ) {
|
|
532
|
+
const els = items.map( x => {
|
|
533
|
+
return new Box( {
|
|
534
|
+
cls: 'item',
|
|
535
|
+
content: x
|
|
536
|
+
} );
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
this.setContent( els );
|
|
540
|
+
}
|
|
60
541
|
}
|
|
542
|
+
|
|
@@ -26,19 +26,48 @@ export interface BoxProps extends ComponentProps {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
|
-
|
|
30
|
-
*
|
|
29
|
+
* A generic container component for grouping and laying out child components.
|
|
30
|
+
*
|
|
31
|
+
* The `refs` object is a typed directory of the children you need to reach
|
|
32
|
+
* again later. Assign a child to `refs` as you build the content: the
|
|
33
|
+
* assignment expression evaluates to the component itself, so it can be
|
|
34
|
+
* inlined directly in the content array.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* using refs: in your code, you can type
|
|
38
|
+
*
|
|
39
|
+
* class MyBox extends Box {
|
|
40
|
+
* declare refs: {
|
|
41
|
+
* a: Combobox;
|
|
42
|
+
* b: Input;
|
|
43
|
+
* }
|
|
44
|
+
*
|
|
45
|
+
* constructor( props ) {
|
|
46
|
+
* super( props );
|
|
47
|
+
*
|
|
48
|
+
* this.setContent( [
|
|
49
|
+
* this.refs.a = new ComboBox( { ... } );
|
|
50
|
+
* this.refs.b = new Input( { ... } );
|
|
51
|
+
* ])
|
|
52
|
+
*
|
|
53
|
+
* onSomeEvent() {
|
|
54
|
+
* this.refs.a.getValue();
|
|
55
|
+
* }
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
*
|
|
59
|
+
*
|
|
31
60
|
*/
|
|
32
61
|
|
|
33
62
|
@class_ns( "x4" )
|
|
34
63
|
export class Box<P extends BoxProps=BoxProps,E extends ComponentEvents=ComponentEvents> extends Component<P,E> {
|
|
64
|
+
protected refs: Record<string,Component> = {};
|
|
35
65
|
}
|
|
36
66
|
|
|
37
67
|
|
|
38
68
|
/**
|
|
39
69
|
* A horizontal box layout component.
|
|
40
70
|
* Arranges child components in a horizontal line.
|
|
41
|
-
* The CSS class for this component is automatically generated as `x4hbox`.
|
|
42
71
|
*/
|
|
43
72
|
|
|
44
73
|
@class_ns( "x4" )
|
|
@@ -7,7 +7,7 @@ import { CSizer } from '../sizers/sizer';
|
|
|
7
7
|
import "./header.module.scss"
|
|
8
8
|
|
|
9
9
|
interface HeaderItem {
|
|
10
|
-
name
|
|
10
|
+
name?: string; // default to ref-cx
|
|
11
11
|
title: string;
|
|
12
12
|
iconId?: string;
|
|
13
13
|
width?: number; // <0 for flex
|
|
@@ -15,7 +15,7 @@ interface HeaderItem {
|
|
|
15
15
|
|
|
16
16
|
interface HeaderProps extends Omit<ComponentProps,"content"> {
|
|
17
17
|
items: HeaderItem[]
|
|
18
|
-
target?: Component; // target element to set header col variable width var( --
|
|
18
|
+
target?: Component; // target element to set header col variable width var( --{name}-width ) parent element if not set
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -38,7 +38,12 @@ export class Header extends HBox<HeaderProps> {
|
|
|
38
38
|
constructor( props: HeaderProps ) {
|
|
39
39
|
super( props );
|
|
40
40
|
|
|
41
|
-
this._els = props.items?.map( x => {
|
|
41
|
+
this._els = props.items?.map( (x,index) => {
|
|
42
|
+
|
|
43
|
+
if( !x.name ) {
|
|
44
|
+
x.name = `ref-c${index+1}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
42
47
|
const cell = new Label( { cls: "cell", text: x.title, icon: x.iconId } );
|
|
43
48
|
const sizer = new CSizer( "right" );
|
|
44
49
|
|
|
@@ -126,7 +131,13 @@ export class Header extends HBox<HeaderProps> {
|
|
|
126
131
|
c.setWidth( width );
|
|
127
132
|
|
|
128
133
|
const item = c.getInternalData<HeaderItem>( 'data' );
|
|
134
|
+
|
|
135
|
+
if( !this.props.target ) {
|
|
136
|
+
this.parentElement().setStyleVariable( `--${item.name}-width`, width + "px");
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
129
139
|
this.props.target?.setStyleVariable( `--${item.name}-width`, width + "px");
|
|
140
|
+
}
|
|
130
141
|
|
|
131
142
|
fullw += width;
|
|
132
143
|
} );
|
|
@@ -53,6 +53,16 @@
|
|
|
53
53
|
&:empty {
|
|
54
54
|
display: none;
|
|
55
55
|
}
|
|
56
|
+
|
|
57
|
+
code {
|
|
58
|
+
padding: 0.2em 0.4em;
|
|
59
|
+
margin: 0;
|
|
60
|
+
font-size: 95%;
|
|
61
|
+
white-space: break-spaces;
|
|
62
|
+
background-color: var(--background-ternary);
|
|
63
|
+
border-radius: 6px;
|
|
64
|
+
border: 1px solid var(--border);
|
|
65
|
+
}
|
|
56
66
|
}
|
|
57
67
|
|
|
58
68
|
#icon {
|
|
@@ -81,6 +91,16 @@
|
|
|
81
91
|
text-align: left;
|
|
82
92
|
&.al-center { text-align: center; }
|
|
83
93
|
&.al-right { text-align: right; }
|
|
94
|
+
|
|
95
|
+
code {
|
|
96
|
+
padding: 0.2em 0.4em;
|
|
97
|
+
margin: 0;
|
|
98
|
+
font-size: 95%;
|
|
99
|
+
white-space: break-spaces;
|
|
100
|
+
background-color: var(--background-ternary);
|
|
101
|
+
border-radius: 6px;
|
|
102
|
+
border: 1px solid var(--border);
|
|
103
|
+
}
|
|
84
104
|
}
|
|
85
105
|
|
|
86
106
|
[disabled] .x4label,
|
|
@@ -12,6 +12,17 @@
|
|
|
12
12
|
background-color: white;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
.x4select {
|
|
16
|
+
appearance: none;
|
|
17
|
+
-webkit-appearance: none;
|
|
18
|
+
-moz-appearance: none;
|
|
19
|
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%23333' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
|
|
20
|
+
background-repeat: no-repeat;
|
|
21
|
+
background-position: right 6px center;
|
|
22
|
+
background-size: 12px 8px;
|
|
23
|
+
padding-right: 23px;
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
//-- global saddly
|
|
16
27
|
option {
|
|
17
28
|
padding: 5px;
|
|
@@ -112,6 +112,7 @@ export class CSizer extends Component<ComponentProps,CSizerEvent> {
|
|
|
112
112
|
|
|
113
113
|
let nr: any = {};
|
|
114
114
|
let horz = true;
|
|
115
|
+
let size = 0;
|
|
115
116
|
|
|
116
117
|
//const center = this._ref.hasClass("center");
|
|
117
118
|
//if( center ) {
|
|
@@ -124,38 +125,69 @@ export class CSizer extends Component<ComponentProps,CSizerEvent> {
|
|
|
124
125
|
|
|
125
126
|
if( this._type.includes("top") ) {
|
|
126
127
|
nr.top = pt.y,
|
|
127
|
-
nr.height = (rc.top+rc.height)-pt.y;
|
|
128
|
+
size = nr.height = (rc.top+rc.height)-pt.y;
|
|
128
129
|
horz = false;
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
if( this._type=="vsize-next" ) {
|
|
132
|
-
nr.height = (rc.top+rc.height)-pt.y;
|
|
133
|
+
size = nr.height = (rc.top+rc.height)-pt.y;
|
|
133
134
|
horz = false;
|
|
134
135
|
}
|
|
135
136
|
|
|
136
137
|
if( this._type.includes("bottom") || this._type=='vsize-prev' ) {
|
|
137
|
-
nr.height = (pt.y-rc.top);
|
|
138
|
+
size = nr.height = (pt.y-rc.top);
|
|
138
139
|
horz = false;
|
|
139
140
|
}
|
|
140
141
|
|
|
141
142
|
if( this._type.includes("left") ) {
|
|
142
143
|
nr.left = pt.x;
|
|
143
|
-
nr.width = ((rc.left+rc.width)-pt.x);
|
|
144
|
+
size = nr.width = ((rc.left+rc.width)-pt.x);
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
if( this._type=="hsize-next" ) {
|
|
147
|
-
nr.width = ((rc.left+rc.width)-pt.x);
|
|
148
|
+
size = nr.width = ((rc.left+rc.width)-pt.x);
|
|
148
149
|
}
|
|
149
150
|
|
|
150
151
|
if( this._type.includes("right") || this._type=='hsize-prev' ) {
|
|
151
|
-
nr.width = (pt.x-rc.left);
|
|
152
|
+
size = nr.width = (pt.x-rc.left);
|
|
152
153
|
}
|
|
153
154
|
|
|
155
|
+
const isFlex = ( c : Component ) => {
|
|
156
|
+
if( !c ) {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if( c.hasClass( "x4flex" ) ) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return c.getStyleValue( "flexGrow" )!==undefined;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if( this._type.includes("-prev") ) {
|
|
168
|
+
if( isFlex(this.prevElement() ) ) {
|
|
169
|
+
this._ref.setStyleValue( "flex", `0 0 ${size}px` );
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
this._ref.setStyle( nr );
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
else if( this._type.includes("-next") ) {
|
|
176
|
+
if( isFlex(this.nextElement() ) ) {
|
|
177
|
+
this._ref.setStyleValue( "flex", `0 0 ${size}px` );
|
|
178
|
+
}
|
|
179
|
+
else {
|
|
180
|
+
this._ref.setStyle( nr );
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
154
186
|
this._ref.setStyle( nr );
|
|
155
|
-
|
|
187
|
+
}
|
|
156
188
|
|
|
157
189
|
const nrc = this._ref.getBoundingRect( );
|
|
158
|
-
this.fire( "resize", { size
|
|
190
|
+
this.fire( "resize", { size, width: nrc.width, height: nrc.height })
|
|
159
191
|
|
|
160
192
|
e.preventDefault( );
|
|
161
193
|
e.stopPropagation( );
|