@trebco/treb 29.8.1 → 29.8.3

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": "@trebco/treb",
3
- "version": "29.8.1",
3
+ "version": "29.8.3",
4
4
  "license": "LGPL-3.0-or-later",
5
5
  "homepage": "https://treb.app",
6
6
  "repository": {
@@ -923,6 +923,91 @@ export const BaseFunctionLibrary: FunctionMap = {
923
923
 
924
924
  },
925
925
 
926
+ /**
927
+ *
928
+ */
929
+ Filter: {
930
+ description: "Filter an array using a second array.",
931
+ arguments: [
932
+ { name: 'source', description: 'Source array' },
933
+ { name: 'filter', description: 'Filter array' },
934
+ // if_empty
935
+ ],
936
+
937
+ fn: (source: CellValue|CellValue[][], filter: CellValue|CellValue[][]) => {
938
+
939
+ if (typeof source === 'undefined' || typeof filter === 'undefined') {
940
+ return ArgumentError();
941
+ }
942
+
943
+ if (!Array.isArray(source)) {
944
+ source = [[source]];
945
+ }
946
+ if (!Array.isArray(filter)) {
947
+ filter = [[filter]];
948
+ }
949
+
950
+ const source_cols = source.length;
951
+ const source_rows = source[0].length;
952
+
953
+ const filter_cols = filter.length;
954
+ const filter_rows = filter[0].length;
955
+
956
+ // prefer rows
957
+
958
+ if (source_rows === filter_rows) {
959
+
960
+ const result: UnionValue[][] = [];
961
+
962
+ for (let i = 0; i < source_cols; i++) {
963
+ result.push([]);
964
+ }
965
+
966
+ for (const [index, entry] of filter[0].entries()) {
967
+
968
+ // FIXME: don't allow strings? errors? (...)
969
+
970
+ if (entry) {
971
+ for (let i = 0; i < source_cols; i++) {
972
+ result[i].push(Box(source[i][index]));
973
+ }
974
+ }
975
+
976
+ }
977
+
978
+ return {
979
+ type: ValueType.array,
980
+ value: result,
981
+ }
982
+
983
+ }
984
+ else if (source_cols === filter_cols) {
985
+
986
+ const result: UnionValue[][] = [];
987
+
988
+ for (const [index, [entry]] of filter.entries()) {
989
+
990
+ // FIXME: don't allow strings? errors? (...)
991
+
992
+ if (entry) {
993
+ result.push(source[index].map(value => Box(value)));
994
+ }
995
+
996
+ }
997
+
998
+ return {
999
+ type: ValueType.array,
1000
+ value: result,
1001
+ }
1002
+
1003
+ }
1004
+
1005
+ return ArgumentError();
1006
+
1007
+ },
1008
+
1009
+ },
1010
+
926
1011
  /**
927
1012
  * sort arguments, but ensure we return empty strings to
928
1013
  * fill up the result array
@@ -6885,6 +6885,27 @@ export class Grid extends GridBase {
6885
6885
  else {
6886
6886
 
6887
6887
  const area = this.active_sheet.RealArea(this.primary_selection.area);
6888
+
6889
+ const column_width: number[] = [];
6890
+ const row_height: number[] = [];
6891
+
6892
+ if (this.primary_selection.area.entire_column) {
6893
+ for (let c = area.start.column; c <= area.end.column; c++) {
6894
+ const width = this.active_sheet.GetColumnWidth(c);
6895
+ if (width !== this.active_sheet.default_column_width) {
6896
+ column_width[c - area.start.column] = width;
6897
+ }
6898
+ }
6899
+ }
6900
+ if (this.primary_selection.area.entire_row) {
6901
+ for (let r = area.start.row; r <= area.end.row; r++) {
6902
+ const height = this.active_sheet.GetRowHeight(r);
6903
+ if (height !== this.active_sheet.default_row_height) {
6904
+ row_height[r - area.start.row] = height;
6905
+ }
6906
+ }
6907
+ }
6908
+
6888
6909
  const columns = area.columns;
6889
6910
  const rows = area.rows;
6890
6911
 
@@ -6961,7 +6982,12 @@ export class Grid extends GridBase {
6961
6982
  if (event.clipboardData) {
6962
6983
  event.clipboardData.clearData();
6963
6984
  event.clipboardData.setData('text/plain', tsv);
6964
- event.clipboardData.setData('text/x-treb', JSON.stringify({ source: area, data: treb_data }));
6985
+ event.clipboardData.setData('text/x-treb', JSON.stringify({
6986
+ source: area,
6987
+ data: treb_data,
6988
+ column_width,
6989
+ row_height,
6990
+ }));
6965
6991
  }
6966
6992
  }
6967
6993
 
@@ -7114,7 +7140,14 @@ export class Grid extends GridBase {
7114
7140
  if (treb_data) {
7115
7141
 
7116
7142
  try {
7117
- const object_data = JSON.parse(treb_data);
7143
+
7144
+ const object_data: {
7145
+ source: Area,
7146
+ data: ClipboardCellData[],
7147
+ column_width?: number[],
7148
+ row_height?: number[],
7149
+ } = JSON.parse(treb_data);
7150
+
7118
7151
  const source_area = new Area(object_data.source.start, object_data.source.end);
7119
7152
 
7120
7153
  // recycle...
@@ -7220,6 +7253,32 @@ export class Grid extends GridBase {
7220
7253
 
7221
7254
  });
7222
7255
 
7256
+ if (object_data.column_width?.length) {
7257
+ for (const [index, width] of object_data.column_width.entries()) {
7258
+ if (typeof width === 'number') {
7259
+ const column = index + paste_area.start.column;
7260
+ commands.push({
7261
+ key: CommandKey.ResizeColumns,
7262
+ column,
7263
+ width,
7264
+ });
7265
+ }
7266
+ }
7267
+ }
7268
+
7269
+ if (object_data.row_height?.length) {
7270
+ for (const [index, height] of object_data.row_height.entries()) {
7271
+ if (typeof height === 'number') {
7272
+ const row = index + paste_area.start.row;
7273
+ commands.push({
7274
+ key: CommandKey.ResizeRows,
7275
+ row,
7276
+ height,
7277
+ });
7278
+ }
7279
+ }
7280
+ }
7281
+
7223
7282
  }
7224
7283
 
7225
7284
  }