x4js 2.2.53 → 2.2.54

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.53",
3
+ "version": "2.2.54",
4
4
  "type": "module",
5
5
  "main": "src/x4.ts",
6
6
  "module": "src/x4.ts",
@@ -20,6 +20,7 @@
20
20
  min-width: 0;
21
21
  min-height: 0;
22
22
  flex-shrink: 0;
23
+ align-self: stretch;
23
24
  }
24
25
 
25
26
  .x4hbox {
@@ -26,19 +26,48 @@ export interface BoxProps extends ComponentProps {
26
26
  }
27
27
 
28
28
  /**
29
- * A generic container component for grouping and laying out child components.
30
- * The CSS class for this component is automatically generated as `x4box`.
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: string;
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( --hdr-item-{name}-width )
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,
@@ -40,6 +40,8 @@
40
40
  }
41
41
 
42
42
  & > .body {
43
+ flex-grow: 1;
44
+
43
45
  position: relative;
44
46
  left: 0;
45
47
  top: 0;
@@ -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
- //this._ref.setStyleValue( "flexGrow", 0 );
187
+ }
156
188
 
157
189
  const nrc = this._ref.getBoundingRect( );
158
- this.fire( "resize", { size: horz ? nrc.width : nrc.height, width: nrc.width, height: nrc.height })
190
+ this.fire( "resize", { size, width: nrc.width, height: nrc.height })
159
191
 
160
192
  e.preventDefault( );
161
193
  e.stopPropagation( );