@odoo/o-spreadsheet 16.1.14 → 16.1.15

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.
@@ -722,12 +722,20 @@ function getDefaultCellHeight(style) {
722
722
  return computeTextLinesHeight(fontSize) + 2 * PADDING_AUTORESIZE_VERTICAL;
723
723
  }
724
724
  function computeTextWidth(context, text, style) {
725
- context.save();
726
- context.font = computeTextFont(style);
727
- const textWidth = context.measureText(text).width;
728
- context.restore();
729
- return textWidth;
725
+ const font = computeTextFont(style);
726
+ if (!textWidthCache[font]) {
727
+ textWidthCache[font] = {};
728
+ }
729
+ if (textWidthCache[font][text] === undefined) {
730
+ context.save();
731
+ context.font = font;
732
+ const textWidth = context.measureText(text).width;
733
+ context.restore();
734
+ textWidthCache[font][text] = textWidth;
735
+ }
736
+ return textWidthCache[font][text];
730
737
  }
738
+ const textWidthCache = {};
731
739
  function computeTextFont(style) {
732
740
  const italic = style.italic ? "italic " : "";
733
741
  const weight = style.bold ? "bold" : DEFAULT_FONT_WEIGHT;
@@ -29556,7 +29564,14 @@ class FiltersPlugin extends CorePlugin {
29556
29564
  this.history.update("tables", filterTables);
29557
29565
  break;
29558
29566
  case "DUPLICATE_SHEET":
29559
- this.history.update("tables", cmd.sheetIdTo, deepCopy(this.tables[cmd.sheetId]));
29567
+ const tables = {};
29568
+ for (const filterTable of Object.values(this.tables[cmd.sheetId] || {})) {
29569
+ if (filterTable) {
29570
+ const newFilterTable = deepCopy(filterTable);
29571
+ tables[newFilterTable.id] = newFilterTable;
29572
+ }
29573
+ }
29574
+ this.history.update("tables", cmd.sheetIdTo, tables);
29560
29575
  break;
29561
29576
  case "ADD_COLUMNS_ROWS":
29562
29577
  this.onAddColumnsRows(cmd);
@@ -33100,6 +33115,7 @@ class FilterEvaluationPlugin extends UIPlugin {
33100
33115
  }
33101
33116
  exportForExcel(data) {
33102
33117
  for (const sheetData of data.sheets) {
33118
+ const sheetId = sheetData.id;
33103
33119
  for (const tableData of sheetData.filterTables) {
33104
33120
  const tableZone = toZone(tableData.range);
33105
33121
  const filters = [];
@@ -33115,20 +33131,20 @@ class FilterEvaluationPlugin extends UIPlugin {
33115
33131
  if (!filter)
33116
33132
  continue;
33117
33133
  const valuesInFilterZone = filter.filteredZone
33118
- ? positions(filter.filteredZone)
33119
- .map(({ col, row }) => this.getters.getEvaluatedCell({ sheetId: sheetData.id, col, row }))
33120
- .filter((cell) => cell.type !== CellValueType.empty)
33121
- .map((cell) => cell.formattedValue)
33134
+ ? positions(filter.filteredZone).map((position) => this.getters.getEvaluatedCell({ sheetId, ...position }).formattedValue)
33122
33135
  : [];
33123
- // In xlsx, filtered values = values that are displayed, not values that are hidden
33124
- const xlsxFilteredValues = valuesInFilterZone.filter((val) => !filteredValues.includes(val));
33125
- filters.push({ colId: i, filteredValues: [...new Set(xlsxFilteredValues)] });
33126
- // In xlsx, filter header should ALWAYS be a string and should be unique
33127
- const headerPosition = {
33128
- col: filter.col,
33129
- row: filter.zoneWithHeaders.top,
33130
- sheetId: sheetData.id,
33131
- };
33136
+ if (filteredValues.length) {
33137
+ const xlsxDisplayedValues = valuesInFilterZone
33138
+ .filter((val) => val)
33139
+ .filter((val) => !filteredValues.includes(val));
33140
+ filters.push({
33141
+ colId: i,
33142
+ displayedValues: [...new Set(xlsxDisplayedValues)],
33143
+ displayBlanks: !filteredValues.includes("") && valuesInFilterZone.some((val) => !val),
33144
+ });
33145
+ }
33146
+ // In xlsx, filter header should ALWAYS be a string and should be unique in the table
33147
+ const headerPosition = { col: filter.col, row: filter.zoneWithHeaders.top, sheetId };
33132
33148
  const headerString = this.getters.getEvaluatedCell(headerPosition).formattedValue;
33133
33149
  const headerName = this.getUniqueColNameForExcel(i, headerString, headerNames);
33134
33150
  headerNames.push(headerName);
@@ -36157,15 +36173,15 @@ SelectionInputPlugin.getters = [];
36157
36173
  * This plugin handles this internal state.
36158
36174
  */
36159
36175
  class SelectionInputsManagerPlugin extends UIPlugin {
36176
+ get currentInput() {
36177
+ return this.focusedInputId ? this.inputs[this.focusedInputId] : null;
36178
+ }
36160
36179
  constructor(config) {
36161
36180
  super(config);
36162
36181
  this.config = config;
36163
36182
  this.inputs = {};
36164
36183
  this.focusedInputId = null;
36165
36184
  }
36166
- get currentInput() {
36167
- return this.focusedInputId ? this.inputs[this.focusedInputId] : null;
36168
- }
36169
36185
  // ---------------------------------------------------------------------------
36170
36186
  // Command Handling
36171
36187
  // ---------------------------------------------------------------------------
@@ -43296,15 +43312,10 @@ function addAutoFilter(table) {
43296
43312
  `;
43297
43313
  }
43298
43314
  function addFilterColumns(table) {
43299
- const tableZone = toZone(table.range);
43300
43315
  const columns = [];
43301
- for (const i of range(0, zoneToDimension(tableZone).width)) {
43302
- const filter = table.filters[i];
43303
- if (!filter || !filter.filteredValues.length) {
43304
- continue;
43305
- }
43316
+ for (const filter of table.filters) {
43306
43317
  const colXml = escapeXml /*xml*/ `
43307
- <filterColumn ${formatAttributes([["colId", i]])}>
43318
+ <filterColumn ${formatAttributes([["colId", filter.colId]])}>
43308
43319
  ${addFilter(filter)}
43309
43320
  </filterColumn>
43310
43321
  `;
@@ -43313,9 +43324,10 @@ function addFilterColumns(table) {
43313
43324
  return columns;
43314
43325
  }
43315
43326
  function addFilter(filter) {
43316
- const filterValues = filter.filteredValues.map((val) => escapeXml /*xml*/ `<filter ${formatAttributes([["val", val]])}/>`);
43327
+ const filterValues = filter.displayedValues.map((val) => escapeXml /*xml*/ `<filter ${formatAttributes([["val", val]])}/>`);
43328
+ const filterAttributes = filter.displayBlanks ? [["blank", 1]] : [];
43317
43329
  return escapeXml /*xml*/ `
43318
- <filters>
43330
+ <filters ${formatAttributes(filterAttributes)}>
43319
43331
  ${joinXmlNodes(filterValues)}
43320
43332
  </filters>
43321
43333
  `;
@@ -44240,6 +44252,6 @@ function addFunction(functionName, functionDescription) {
44240
44252
  export { AbstractChart, CommandResult, CorePlugin, DATETIME_FORMAT, DispatchResult, EvaluationError, Model, Registry, Revision, SPREADSHEET_DIMENSIONS, Spreadsheet, UIPlugin, __info__, addFunction, astToFormula, compile, components, convertAstNodes, coreTypes, findCellInNewZone, functionCache, helpers, invalidateEvaluationCommands, links, load, parse, readonlyAllowedCommands, registries, setTranslationMethod, tokenize };
44241
44253
 
44242
44254
 
44243
- __info__.version = '16.1.14';
44244
- __info__.date = '2023-06-12T13:50:13.693Z';
44245
- __info__.hash = 'a51d9fa';
44255
+ __info__.version = '16.1.15';
44256
+ __info__.date = '2023-06-26T14:33:07.859Z';
44257
+ __info__.hash = '2b264ad';
@@ -723,12 +723,20 @@
723
723
  return computeTextLinesHeight(fontSize) + 2 * PADDING_AUTORESIZE_VERTICAL;
724
724
  }
725
725
  function computeTextWidth(context, text, style) {
726
- context.save();
727
- context.font = computeTextFont(style);
728
- const textWidth = context.measureText(text).width;
729
- context.restore();
730
- return textWidth;
726
+ const font = computeTextFont(style);
727
+ if (!textWidthCache[font]) {
728
+ textWidthCache[font] = {};
729
+ }
730
+ if (textWidthCache[font][text] === undefined) {
731
+ context.save();
732
+ context.font = font;
733
+ const textWidth = context.measureText(text).width;
734
+ context.restore();
735
+ textWidthCache[font][text] = textWidth;
736
+ }
737
+ return textWidthCache[font][text];
731
738
  }
739
+ const textWidthCache = {};
732
740
  function computeTextFont(style) {
733
741
  const italic = style.italic ? "italic " : "";
734
742
  const weight = style.bold ? "bold" : DEFAULT_FONT_WEIGHT;
@@ -29557,7 +29565,14 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
29557
29565
  this.history.update("tables", filterTables);
29558
29566
  break;
29559
29567
  case "DUPLICATE_SHEET":
29560
- this.history.update("tables", cmd.sheetIdTo, deepCopy(this.tables[cmd.sheetId]));
29568
+ const tables = {};
29569
+ for (const filterTable of Object.values(this.tables[cmd.sheetId] || {})) {
29570
+ if (filterTable) {
29571
+ const newFilterTable = deepCopy(filterTable);
29572
+ tables[newFilterTable.id] = newFilterTable;
29573
+ }
29574
+ }
29575
+ this.history.update("tables", cmd.sheetIdTo, tables);
29561
29576
  break;
29562
29577
  case "ADD_COLUMNS_ROWS":
29563
29578
  this.onAddColumnsRows(cmd);
@@ -33101,6 +33116,7 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
33101
33116
  }
33102
33117
  exportForExcel(data) {
33103
33118
  for (const sheetData of data.sheets) {
33119
+ const sheetId = sheetData.id;
33104
33120
  for (const tableData of sheetData.filterTables) {
33105
33121
  const tableZone = toZone(tableData.range);
33106
33122
  const filters = [];
@@ -33116,20 +33132,20 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
33116
33132
  if (!filter)
33117
33133
  continue;
33118
33134
  const valuesInFilterZone = filter.filteredZone
33119
- ? positions(filter.filteredZone)
33120
- .map(({ col, row }) => this.getters.getEvaluatedCell({ sheetId: sheetData.id, col, row }))
33121
- .filter((cell) => cell.type !== CellValueType.empty)
33122
- .map((cell) => cell.formattedValue)
33135
+ ? positions(filter.filteredZone).map((position) => this.getters.getEvaluatedCell({ sheetId, ...position }).formattedValue)
33123
33136
  : [];
33124
- // In xlsx, filtered values = values that are displayed, not values that are hidden
33125
- const xlsxFilteredValues = valuesInFilterZone.filter((val) => !filteredValues.includes(val));
33126
- filters.push({ colId: i, filteredValues: [...new Set(xlsxFilteredValues)] });
33127
- // In xlsx, filter header should ALWAYS be a string and should be unique
33128
- const headerPosition = {
33129
- col: filter.col,
33130
- row: filter.zoneWithHeaders.top,
33131
- sheetId: sheetData.id,
33132
- };
33137
+ if (filteredValues.length) {
33138
+ const xlsxDisplayedValues = valuesInFilterZone
33139
+ .filter((val) => val)
33140
+ .filter((val) => !filteredValues.includes(val));
33141
+ filters.push({
33142
+ colId: i,
33143
+ displayedValues: [...new Set(xlsxDisplayedValues)],
33144
+ displayBlanks: !filteredValues.includes("") && valuesInFilterZone.some((val) => !val),
33145
+ });
33146
+ }
33147
+ // In xlsx, filter header should ALWAYS be a string and should be unique in the table
33148
+ const headerPosition = { col: filter.col, row: filter.zoneWithHeaders.top, sheetId };
33133
33149
  const headerString = this.getters.getEvaluatedCell(headerPosition).formattedValue;
33134
33150
  const headerName = this.getUniqueColNameForExcel(i, headerString, headerNames);
33135
33151
  headerNames.push(headerName);
@@ -36158,15 +36174,15 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
36158
36174
  * This plugin handles this internal state.
36159
36175
  */
36160
36176
  class SelectionInputsManagerPlugin extends UIPlugin {
36177
+ get currentInput() {
36178
+ return this.focusedInputId ? this.inputs[this.focusedInputId] : null;
36179
+ }
36161
36180
  constructor(config) {
36162
36181
  super(config);
36163
36182
  this.config = config;
36164
36183
  this.inputs = {};
36165
36184
  this.focusedInputId = null;
36166
36185
  }
36167
- get currentInput() {
36168
- return this.focusedInputId ? this.inputs[this.focusedInputId] : null;
36169
- }
36170
36186
  // ---------------------------------------------------------------------------
36171
36187
  // Command Handling
36172
36188
  // ---------------------------------------------------------------------------
@@ -43297,15 +43313,10 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
43297
43313
  `;
43298
43314
  }
43299
43315
  function addFilterColumns(table) {
43300
- const tableZone = toZone(table.range);
43301
43316
  const columns = [];
43302
- for (const i of range(0, zoneToDimension(tableZone).width)) {
43303
- const filter = table.filters[i];
43304
- if (!filter || !filter.filteredValues.length) {
43305
- continue;
43306
- }
43317
+ for (const filter of table.filters) {
43307
43318
  const colXml = escapeXml /*xml*/ `
43308
- <filterColumn ${formatAttributes([["colId", i]])}>
43319
+ <filterColumn ${formatAttributes([["colId", filter.colId]])}>
43309
43320
  ${addFilter(filter)}
43310
43321
  </filterColumn>
43311
43322
  `;
@@ -43314,9 +43325,10 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
43314
43325
  return columns;
43315
43326
  }
43316
43327
  function addFilter(filter) {
43317
- const filterValues = filter.filteredValues.map((val) => escapeXml /*xml*/ `<filter ${formatAttributes([["val", val]])}/>`);
43328
+ const filterValues = filter.displayedValues.map((val) => escapeXml /*xml*/ `<filter ${formatAttributes([["val", val]])}/>`);
43329
+ const filterAttributes = filter.displayBlanks ? [["blank", 1]] : [];
43318
43330
  return escapeXml /*xml*/ `
43319
- <filters>
43331
+ <filters ${formatAttributes(filterAttributes)}>
43320
43332
  ${joinXmlNodes(filterValues)}
43321
43333
  </filters>
43322
43334
  `;
@@ -44271,9 +44283,9 @@ day_count_convention (number, default=${DEFAULT_DAY_COUNT_CONVENTION} ) ${_lt("A
44271
44283
  Object.defineProperty(exports, '__esModule', { value: true });
44272
44284
 
44273
44285
 
44274
- __info__.version = '16.1.14';
44275
- __info__.date = '2023-06-12T13:50:13.693Z';
44276
- __info__.hash = 'a51d9fa';
44286
+ __info__.version = '16.1.15';
44287
+ __info__.date = '2023-06-26T14:33:07.859Z';
44288
+ __info__.hash = '2b264ad';
44277
44289
 
44278
44290
 
44279
44291
  })(this.o_spreadsheet = this.o_spreadsheet || {}, owl);