@trebco/treb 29.8.1 → 29.8.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.
package/package.json
CHANGED
|
@@ -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
|
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
IsArea,
|
|
49
49
|
} from 'treb-base-types';
|
|
50
50
|
|
|
51
|
-
import type { ExpressionUnit, UnitAddress } from 'treb-parser';
|
|
51
|
+
import type { ExpressionUnit, RenderOptions, UnitAddress } from 'treb-parser';
|
|
52
52
|
import {
|
|
53
53
|
DecimalMarkType,
|
|
54
54
|
ArgumentSeparatorType,
|
|
@@ -4614,9 +4614,17 @@ export class Grid extends GridBase {
|
|
|
4614
4614
|
}
|
|
4615
4615
|
|
|
4616
4616
|
for (let row = start; row >= 0 && row < target_rows; row += step, offset += step, pattern_increment += pattern) {
|
|
4617
|
+
|
|
4618
|
+
const render_options: Partial<RenderOptions> = {
|
|
4619
|
+
offset: transposed ? {
|
|
4620
|
+
rows: 0, columns: offset,
|
|
4621
|
+
} : {
|
|
4622
|
+
rows: offset, columns: 0,
|
|
4623
|
+
}
|
|
4624
|
+
};
|
|
4625
|
+
|
|
4617
4626
|
if (translate) {
|
|
4618
|
-
data[row][column] = '=' + this.parser.Render(translate,
|
|
4619
|
-
offset: { rows: offset, columns: 0 }});
|
|
4627
|
+
data[row][column] = '=' + this.parser.Render(translate, render_options);
|
|
4620
4628
|
}
|
|
4621
4629
|
else {
|
|
4622
4630
|
const cell = cells[source_row][column];
|
|
@@ -6885,6 +6893,27 @@ export class Grid extends GridBase {
|
|
|
6885
6893
|
else {
|
|
6886
6894
|
|
|
6887
6895
|
const area = this.active_sheet.RealArea(this.primary_selection.area);
|
|
6896
|
+
|
|
6897
|
+
const column_width: number[] = [];
|
|
6898
|
+
const row_height: number[] = [];
|
|
6899
|
+
|
|
6900
|
+
if (this.primary_selection.area.entire_column) {
|
|
6901
|
+
for (let c = area.start.column; c <= area.end.column; c++) {
|
|
6902
|
+
const width = this.active_sheet.GetColumnWidth(c);
|
|
6903
|
+
if (width !== this.active_sheet.default_column_width) {
|
|
6904
|
+
column_width[c - area.start.column] = width;
|
|
6905
|
+
}
|
|
6906
|
+
}
|
|
6907
|
+
}
|
|
6908
|
+
if (this.primary_selection.area.entire_row) {
|
|
6909
|
+
for (let r = area.start.row; r <= area.end.row; r++) {
|
|
6910
|
+
const height = this.active_sheet.GetRowHeight(r);
|
|
6911
|
+
if (height !== this.active_sheet.default_row_height) {
|
|
6912
|
+
row_height[r - area.start.row] = height;
|
|
6913
|
+
}
|
|
6914
|
+
}
|
|
6915
|
+
}
|
|
6916
|
+
|
|
6888
6917
|
const columns = area.columns;
|
|
6889
6918
|
const rows = area.rows;
|
|
6890
6919
|
|
|
@@ -6961,7 +6990,12 @@ export class Grid extends GridBase {
|
|
|
6961
6990
|
if (event.clipboardData) {
|
|
6962
6991
|
event.clipboardData.clearData();
|
|
6963
6992
|
event.clipboardData.setData('text/plain', tsv);
|
|
6964
|
-
event.clipboardData.setData('text/x-treb', JSON.stringify({
|
|
6993
|
+
event.clipboardData.setData('text/x-treb', JSON.stringify({
|
|
6994
|
+
source: area,
|
|
6995
|
+
data: treb_data,
|
|
6996
|
+
column_width,
|
|
6997
|
+
row_height,
|
|
6998
|
+
}));
|
|
6965
6999
|
}
|
|
6966
7000
|
}
|
|
6967
7001
|
|
|
@@ -7114,7 +7148,14 @@ export class Grid extends GridBase {
|
|
|
7114
7148
|
if (treb_data) {
|
|
7115
7149
|
|
|
7116
7150
|
try {
|
|
7117
|
-
|
|
7151
|
+
|
|
7152
|
+
const object_data: {
|
|
7153
|
+
source: Area,
|
|
7154
|
+
data: ClipboardCellData[],
|
|
7155
|
+
column_width?: number[],
|
|
7156
|
+
row_height?: number[],
|
|
7157
|
+
} = JSON.parse(treb_data);
|
|
7158
|
+
|
|
7118
7159
|
const source_area = new Area(object_data.source.start, object_data.source.end);
|
|
7119
7160
|
|
|
7120
7161
|
// recycle...
|
|
@@ -7220,6 +7261,32 @@ export class Grid extends GridBase {
|
|
|
7220
7261
|
|
|
7221
7262
|
});
|
|
7222
7263
|
|
|
7264
|
+
if (object_data.column_width?.length) {
|
|
7265
|
+
for (const [index, width] of object_data.column_width.entries()) {
|
|
7266
|
+
if (typeof width === 'number') {
|
|
7267
|
+
const column = index + paste_area.start.column;
|
|
7268
|
+
commands.push({
|
|
7269
|
+
key: CommandKey.ResizeColumns,
|
|
7270
|
+
column,
|
|
7271
|
+
width,
|
|
7272
|
+
});
|
|
7273
|
+
}
|
|
7274
|
+
}
|
|
7275
|
+
}
|
|
7276
|
+
|
|
7277
|
+
if (object_data.row_height?.length) {
|
|
7278
|
+
for (const [index, height] of object_data.row_height.entries()) {
|
|
7279
|
+
if (typeof height === 'number') {
|
|
7280
|
+
const row = index + paste_area.start.row;
|
|
7281
|
+
commands.push({
|
|
7282
|
+
key: CommandKey.ResizeRows,
|
|
7283
|
+
row,
|
|
7284
|
+
height,
|
|
7285
|
+
});
|
|
7286
|
+
}
|
|
7287
|
+
}
|
|
7288
|
+
}
|
|
7289
|
+
|
|
7223
7290
|
}
|
|
7224
7291
|
|
|
7225
7292
|
}
|