cx 24.3.2 → 24.3.4

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.
@@ -157,7 +157,7 @@ export class Grid extends Container {
157
157
  )
158
158
  row.hasResizableColumns = true;
159
159
 
160
- if (c.aggregate && (c.aggregateField || isDefined(c.aggregateValue))) {
160
+ if (c.aggregate && c.aggregateAlias && (c.aggregateField || isDefined(c.aggregateValue))) {
161
161
  aggregates[c.aggregateAlias] = {
162
162
  value: isDefined(c.aggregateValue)
163
163
  ? c.aggregateValue
@@ -608,16 +608,15 @@ export class Grid extends Container {
608
608
  if (!header) return null;
609
609
 
610
610
  let skip = {};
611
- let lineIndex = 0;
612
611
 
613
- header.children.forEach((line) => {
612
+ header.children.forEach((line, lineIndex) => {
614
613
  let empty = [true, true, true];
615
614
  let result = [[], [], []];
616
615
 
617
616
  line.children.forEach((hdinst, colIndex) => {
618
617
  let hdwidget = hdinst.widget;
619
618
  for (let l = 0; l < 3; l++) {
620
- let colKey = `${lineIndex + l}-${colIndex}`;
619
+ let colKey = `${lineIndex}-${colIndex}-${l}`;
621
620
 
622
621
  if (skip[colKey]) continue;
623
622
 
@@ -690,7 +689,7 @@ export class Grid extends Container {
690
689
 
691
690
  for (let r = 0; r < header.data.rowSpan; r++)
692
691
  for (let c = 0; c < header.data.colSpan; c++)
693
- skip[`${lineIndex + l + r}-${colIndex + c}`] = true;
692
+ skip[`${lineIndex}-${colIndex + c}-${l + r}`] = true;
694
693
  }
695
694
 
696
695
  if ((hdwidget.resizable || header.data.resizable) && header.data.colSpan < 2) {
@@ -745,7 +744,6 @@ export class Grid extends Container {
745
744
  });
746
745
 
747
746
  result = result.filter((_, i) => !empty[i]);
748
- lineIndex += result.length;
749
747
 
750
748
  if (result[0]) {
751
749
  if (fixed && !fixedColumns) {
@@ -883,15 +881,22 @@ export class Grid extends Container {
883
881
  let v,
884
882
  c = ci.widget,
885
883
  colSpan,
886
- pad;
884
+ pad,
885
+ cls = "",
886
+ style = null;
887
887
  if (c.caption) {
888
888
  if (c.caption.children)
889
889
  v = <Cx widget={c.caption.children} store={store} parentInstance={instance} subscribe />;
890
- else v = c.caption.value(data);
890
+ else {
891
+ v = c.caption.value(data);
892
+ let fmt = c.caption.format(data);
893
+ if (fmt) v = Format.value(v, fmt);
894
+ }
891
895
  pad = c.caption.pad;
892
896
  colSpan = c.caption.colSpan;
893
897
  empty = false;
894
-
898
+ cls = CSS.expand(c.caption.class(data)) || "";
899
+ style = parseStyle(c.caption.style(data));
895
900
  if (c.caption.expand) {
896
901
  colSpan = 1;
897
902
  for (
@@ -905,19 +910,19 @@ export class Grid extends Container {
905
910
  }
906
911
 
907
912
  if (colSpan > 1) skip = colSpan - 1;
908
- } else if (c.aggregate && c.aggregateField && c.caption !== false) {
913
+ } else if (c.aggregate && c.aggregateAlias && c.caption !== false) {
909
914
  empty = false;
910
- v = group[c.aggregateField];
915
+ v = group[c.aggregateAlias];
911
916
  if (isString(ci.data.format)) v = Format.value(v, ci.data.format);
912
917
  }
913
918
 
914
- let cls = "";
919
+ if (cls) cls += " ";
915
920
  if (c.align) cls += CSS.state("aligned-" + c.align);
916
921
 
917
922
  if (pad !== false) cls += (cls ? " " : "") + CSS.state("pad");
918
923
 
919
924
  return (
920
- <td key={i} className={cls} colSpan={colSpan}>
925
+ <td key={i} className={cls} colSpan={colSpan} style={style}>
921
926
  {v}
922
927
  </td>
923
928
  );
@@ -988,9 +993,9 @@ export class Grid extends Container {
988
993
  }
989
994
 
990
995
  if (colSpan > 1) skip = colSpan - 1;
991
- } else if (c.aggregate && c.aggregateField && c.footer !== false) {
996
+ } else if (c.aggregate && c.aggregateAlias && c.footer !== false) {
992
997
  empty = false;
993
- v = group[c.aggregateField];
998
+ v = group[c.aggregateAlias];
994
999
  if (isString(ci.data.format)) v = Format.value(v, ci.data.format);
995
1000
  }
996
1001
 
@@ -1240,6 +1245,7 @@ class GridComponent extends VDOM.Component {
1240
1245
  cursorCellIndex: 0,
1241
1246
  focused: widget.focused,
1242
1247
  dropInsertionIndex: null,
1248
+ dropNextToTheRowAbove: null,
1243
1249
  start: 0,
1244
1250
  end: end,
1245
1251
  };
@@ -1333,79 +1339,68 @@ class GridComponent extends VDOM.Component {
1333
1339
  mod["draggable"] = draggable;
1334
1340
  mod["non-draggable"] = !draggable;
1335
1341
 
1336
- let wrap = (children) => {
1337
- let skipCells = {};
1338
- return (
1339
- <GridRowComponent
1340
- key={key}
1341
- className={CSS.state(mod)}
1342
- store={store}
1343
- dragSource={dragSource}
1344
- instance={row}
1345
- grid={instance}
1346
- record={record}
1347
- parent={this}
1348
- cursorIndex={index}
1349
- selected={row.selected}
1350
- isBeingDragged={dragged}
1351
- isDraggedOver={mod.over}
1352
- cursor={mod.cursor}
1353
- cursorCellIndex={index == cursor && cursorCellIndex}
1354
- cellEdit={index == cursor && cursorCellIndex != null && cellEdit}
1355
- shouldUpdate={row.shouldUpdate}
1356
- dimensionsVersion={dimensionsVersion}
1357
- fixed={fixed}
1358
- >
1359
- {children.content.map(({ key, data, content }, line) => (
1360
- <tr key={key} className={data.classNames} style={data.style}>
1361
- {content.map(({ key, data, content, uniqueColumnId }, cellIndex) => {
1362
- if (Boolean(data.fixed) !== fixed) return null;
1363
- let cellected =
1364
- index == cursor && cellIndex == cursorCellIndex && widget.cellEditable && line == 0;
1365
- let className = cellected
1366
- ? CSS.expand(data.classNames, CSS.state("cellected"))
1367
- : data.classNames;
1368
- if (cellected && cellEdit) {
1369
- let column = visibleColumns[cursorCellIndex];
1370
- if (column && column.editor && data.editable)
1371
- return this.renderCellEditor(key, CSS, baseClass, row, column);
1372
- }
1373
- let width = colWidth[uniqueColumnId];
1374
- let style = data.style;
1375
- if (width) {
1376
- style = {
1377
- ...style,
1378
- maxWidth: `${width}px`,
1379
- };
1380
- }
1381
-
1382
- if (skipCells[`${line}-${cellIndex}`]) return null;
1383
-
1384
- if (data.colSpan > 1 || data.rowSpan > 1) {
1385
- for (let r = line; r < line + (data.rowSpan ?? 1); r++)
1386
- for (let c = cellIndex; c < cellIndex + (data.colSpan ?? 1); c++)
1387
- skipCells[`${r}-${c}`] = true;
1388
- }
1389
-
1390
- if (cellWrap) content = cellWrap(content);
1391
-
1392
- return (
1393
- <td
1394
- key={key}
1395
- className={className}
1396
- style={style}
1397
- colSpan={data.colSpan}
1398
- rowSpan={data.rowSpan}
1399
- >
1400
- {content}
1401
- </td>
1402
- );
1403
- })}
1404
- </tr>
1405
- ))}
1406
- </GridRowComponent>
1407
- );
1408
- };
1342
+ let wrap = (children) => (
1343
+ <GridRowComponent
1344
+ key={key}
1345
+ className={CSS.state(mod)}
1346
+ store={store}
1347
+ dragSource={dragSource}
1348
+ instance={row}
1349
+ grid={instance}
1350
+ record={record}
1351
+ parent={this}
1352
+ cursorIndex={index}
1353
+ selected={row.selected}
1354
+ isBeingDragged={dragged}
1355
+ isDraggedOver={mod.over}
1356
+ cursor={mod.cursor}
1357
+ cursorCellIndex={index == cursor && cursorCellIndex}
1358
+ cellEdit={index == cursor && cursorCellIndex != null && cellEdit}
1359
+ shouldUpdate={row.shouldUpdate}
1360
+ dimensionsVersion={dimensionsVersion}
1361
+ fixed={fixed}
1362
+ >
1363
+ {children.content.map(({ key, data, content }, line) => (
1364
+ <tr key={key} className={data.classNames} style={data.style}>
1365
+ {content.map(({ key, data, content, uniqueColumnId }, cellIndex) => {
1366
+ if (Boolean(data.fixed) !== fixed) return null;
1367
+ let cellected =
1368
+ index == cursor && cellIndex == cursorCellIndex && widget.cellEditable && line == 0;
1369
+ let className = cellected
1370
+ ? CSS.expand(data.classNames, CSS.state("cellected"))
1371
+ : data.classNames;
1372
+ if (cellected && cellEdit) {
1373
+ let column = visibleColumns[cursorCellIndex];
1374
+ if (column && column.editor && data.editable)
1375
+ return this.renderCellEditor(key, CSS, baseClass, row, column);
1376
+ }
1377
+ let width = colWidth[uniqueColumnId];
1378
+ let style = data.style;
1379
+ if (width) {
1380
+ style = {
1381
+ ...style,
1382
+ maxWidth: `${width}px`,
1383
+ };
1384
+ }
1385
+
1386
+ if (cellWrap) content = cellWrap(content);
1387
+
1388
+ return (
1389
+ <td
1390
+ key={key}
1391
+ className={className}
1392
+ style={style}
1393
+ colSpan={data.colSpan}
1394
+ rowSpan={data.rowSpan}
1395
+ >
1396
+ {content}
1397
+ </td>
1398
+ );
1399
+ })}
1400
+ </tr>
1401
+ ))}
1402
+ </GridRowComponent>
1403
+ );
1409
1404
 
1410
1405
  if (!standalone) return wrap(record.vdom);
1411
1406
 
@@ -1597,7 +1592,25 @@ class GridComponent extends VDOM.Component {
1597
1592
  </tr>
1598
1593
  </tbody>
1599
1594
  );
1600
- children.splice(this.state.dropInsertionIndex, 0, dragInsertionRow);
1595
+
1596
+ let index = 0;
1597
+ while (index < children.length && children[index]?.props?.record?.type != "data") index++;
1598
+
1599
+ let count = 0;
1600
+ while (count < this.state.dropInsertionIndex) {
1601
+ if (children[index]?.props?.record?.type == "data") count++;
1602
+ index++;
1603
+ }
1604
+
1605
+ let savedIndexPos = index;
1606
+
1607
+ if (!this.state.dropNextToTheRowAbove)
1608
+ while (index < children.length && children[index]?.props?.record?.type != "data") index++;
1609
+
1610
+ // do not allow insertion after the last group footer
1611
+ if (savedIndexPos < index && index == children.length) index = savedIndexPos;
1612
+
1613
+ children.splice(index, 0, dragInsertionRow);
1601
1614
  }
1602
1615
 
1603
1616
  let content = [],
@@ -1984,12 +1997,13 @@ class GridComponent extends VDOM.Component {
1984
1997
  let { instance } = this.props;
1985
1998
  let { widget } = instance;
1986
1999
  let { start } = this.getBufferStartEnd();
1987
- let { dropInsertionIndex, dropTarget } = this.state;
2000
+ let { dropInsertionIndex, dropTarget, dropNextToTheRowAbove } = this.state;
1988
2001
  if (dropTarget == "grid" && widget.onDrop && dropInsertionIndex != null) {
1989
2002
  e.target = {
1990
2003
  insertionIndex: start + dropInsertionIndex,
1991
2004
  recordBefore: this.getRecordAt(start + dropInsertionIndex - 1),
1992
2005
  recordAfter: this.getRecordAt(start + dropInsertionIndex),
2006
+ dropNextToTheRowAbove,
1993
2007
  };
1994
2008
  instance.invoke("onDrop", e, instance);
1995
2009
  } else if (dropTarget == "row") {
@@ -2103,6 +2117,7 @@ class GridComponent extends VDOM.Component {
2103
2117
  let cy = ev.cursor.clientY - parentOffset.top;
2104
2118
 
2105
2119
  let rowOverIndex = null;
2120
+ let nextToTheRowAbove = false;
2106
2121
 
2107
2122
  while (s < e) {
2108
2123
  m = Math.floor((s + e) / 2);
@@ -2141,8 +2156,10 @@ class GridComponent extends VDOM.Component {
2141
2156
  }
2142
2157
  }
2143
2158
 
2144
- if (cy > (b.bottom + b.top) / 2) s = e = m + 1;
2145
- else s = e = m;
2159
+ if (cy > (b.bottom + b.top) / 2) {
2160
+ s = e = m + 1;
2161
+ nextToTheRowAbove = true;
2162
+ } else s = e = m;
2146
2163
  }
2147
2164
  }
2148
2165
 
@@ -2160,6 +2177,7 @@ class GridComponent extends VDOM.Component {
2160
2177
  else if (rowOverIndex != this.state.dropInsertionIndex || this.state.dropTarget != "row") {
2161
2178
  this.setState({
2162
2179
  dropInsertionIndex: rowOverIndex,
2180
+ dropNextToTheRowAbove: false,
2163
2181
  dropItemHeight: ev.source.height - 1,
2164
2182
  dropTarget: "row",
2165
2183
  });
@@ -2178,6 +2196,7 @@ class GridComponent extends VDOM.Component {
2178
2196
  else if (s != this.state.dropInsertionIndex || this.state.dropTarget != "grid") {
2179
2197
  this.setState({
2180
2198
  dropInsertionIndex: s,
2199
+ dropNextToTheRowAbove: nextToTheRowAbove,
2181
2200
  dropItemHeight: ev.source.height - 1,
2182
2201
  dropTarget: "grid",
2183
2202
  });
@@ -2186,6 +2205,7 @@ class GridComponent extends VDOM.Component {
2186
2205
  if (cancel) {
2187
2206
  this.setState({
2188
2207
  dropInsertionIndex: null,
2208
+ dropNextToTheRowAbove: null,
2189
2209
  dropTarget: null,
2190
2210
  });
2191
2211
  }
@@ -2194,6 +2214,7 @@ class GridComponent extends VDOM.Component {
2194
2214
  onDragLeave(e) {
2195
2215
  this.setState({
2196
2216
  dropInsertionIndex: null,
2217
+ dropNextToTheRowAbove: null,
2197
2218
  dropTarget: null,
2198
2219
  });
2199
2220
  }
@@ -3102,7 +3123,12 @@ class GridColumnHeader extends Widget {
3102
3123
  if (children) {
3103
3124
  delete this.caption.items;
3104
3125
  this.caption.children = Widget.create(children);
3105
- } else this.caption.value = getSelector(this.caption.value);
3126
+ } else {
3127
+ this.caption.value = getSelector(this.caption.value);
3128
+ this.caption.class = getSelector(this.caption.class);
3129
+ this.caption.style = getSelector(this.caption.style);
3130
+ this.caption.format = getSelector(this.caption.format);
3131
+ }
3106
3132
  }
3107
3133
 
3108
3134
  super.init();