@odoo/o-spreadsheet 16.2.7 → 16.2.9

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.
@@ -1722,27 +1722,36 @@ function removeTrailingZeroes(numberString) {
1722
1722
  }
1723
1723
  return numberString.slice(0, i + 1) || undefined;
1724
1724
  }
1725
+ const leadingZeroesRegexp = /^0+/;
1725
1726
  /**
1726
1727
  * Limit the size of the decimal part of a number to the given number of digits.
1727
1728
  */
1728
1729
  function limitDecimalDigits(decimalDigits, maxDecimals) {
1730
+ var _a;
1729
1731
  let integerDigits = "0";
1730
1732
  let resultDecimalDigits = decimalDigits;
1731
1733
  // Note : we'd want to simply use number.toFixed() to handle the max digits & rounding,
1732
1734
  // but it has very strange behaviour. Ex: 12.345.toFixed(2) => "12.35", but 1.345.toFixed(2) => "1.34"
1733
1735
  let slicedDecimalDigits = decimalDigits.slice(0, maxDecimals);
1734
1736
  const i = maxDecimals;
1735
- if (Number(Number(decimalDigits[i]) < 5)) {
1737
+ if (Number(decimalDigits[i]) < 5) {
1736
1738
  return { integerDigits, decimalDigits: slicedDecimalDigits };
1737
1739
  }
1738
1740
  // round up
1741
+ const leadingZeroes = ((_a = slicedDecimalDigits.match(leadingZeroesRegexp)) === null || _a === void 0 ? void 0 : _a[0]) || "";
1739
1742
  const slicedRoundedUp = (Number(slicedDecimalDigits) + 1).toString();
1740
- if (slicedRoundedUp.length > slicedDecimalDigits.length) {
1741
- integerDigits = (Number(integerDigits) + 1).toString();
1743
+ const withoutLeadingZeroes = slicedDecimalDigits.slice(leadingZeroes.length);
1744
+ // e.g. carry over from 99 to 100
1745
+ const carryOver = slicedRoundedUp.length > withoutLeadingZeroes.length;
1746
+ if (carryOver && !leadingZeroes) {
1747
+ integerDigits = "1";
1742
1748
  resultDecimalDigits = undefined;
1743
1749
  }
1750
+ else if (carryOver) {
1751
+ resultDecimalDigits = leadingZeroes.slice(0, -1) + slicedRoundedUp;
1752
+ }
1744
1753
  else {
1745
- resultDecimalDigits = slicedRoundedUp;
1754
+ resultDecimalDigits = leadingZeroes + slicedRoundedUp;
1746
1755
  }
1747
1756
  return { integerDigits, decimalDigits: resultDecimalDigits };
1748
1757
  }
@@ -16859,7 +16868,7 @@ class LineBarPieConfigPanel extends Component {
16859
16868
  return !!((_a = this.state.labelsDispatchResult) === null || _a === void 0 ? void 0 : _a.isCancelledBecause(33 /* CommandResult.InvalidLabelRange */));
16860
16869
  }
16861
16870
  onUpdateDataSetsHaveTitle(ev) {
16862
- this.props.updateChart({
16871
+ this.props.updateChart(this.props.figureId, {
16863
16872
  dataSetsHaveTitle: ev.target.checked,
16864
16873
  });
16865
16874
  }
@@ -16871,7 +16880,7 @@ class LineBarPieConfigPanel extends Component {
16871
16880
  this.dataSeriesRanges = ranges;
16872
16881
  }
16873
16882
  onDataSeriesConfirmed() {
16874
- this.state.datasetDispatchResult = this.props.updateChart({
16883
+ this.state.datasetDispatchResult = this.props.updateChart(this.props.figureId, {
16875
16884
  dataSets: this.dataSeriesRanges,
16876
16885
  });
16877
16886
  }
@@ -16883,12 +16892,12 @@ class LineBarPieConfigPanel extends Component {
16883
16892
  this.labelRange = ranges[0];
16884
16893
  }
16885
16894
  onLabelRangeConfirmed() {
16886
- this.state.labelsDispatchResult = this.props.updateChart({
16895
+ this.state.labelsDispatchResult = this.props.updateChart(this.props.figureId, {
16887
16896
  labelRange: this.labelRange,
16888
16897
  });
16889
16898
  }
16890
16899
  onUpdateAggregated(ev) {
16891
- this.props.updateChart({
16900
+ this.props.updateChart(this.props.figureId, {
16892
16901
  aggregated: ev.target.checked,
16893
16902
  });
16894
16903
  }
@@ -16903,12 +16912,12 @@ LineBarPieConfigPanel.props = {
16903
16912
 
16904
16913
  class BarConfigPanel extends LineBarPieConfigPanel {
16905
16914
  onUpdateStacked(ev) {
16906
- this.props.updateChart({
16915
+ this.props.updateChart(this.props.figureId, {
16907
16916
  stacked: ev.target.checked,
16908
16917
  });
16909
16918
  }
16910
16919
  onUpdateAggregated(ev) {
16911
- this.props.updateChart({
16920
+ this.props.updateChart(this.props.figureId, {
16912
16921
  aggregated: ev.target.checked,
16913
16922
  });
16914
16923
  }
@@ -16949,6 +16958,7 @@ css /* scss */ `
16949
16958
  .o-color-picker-toggler {
16950
16959
  display: flex;
16951
16960
  .o-color-picker-toggler-sign {
16961
+ display: flex;
16952
16962
  margin: auto auto;
16953
16963
  width: 55%;
16954
16964
  height: 55%;
@@ -17251,17 +17261,17 @@ class LineBarPieDesignPanel extends Component {
17251
17261
  this.state.fillColorTool = !this.state.fillColorTool;
17252
17262
  }
17253
17263
  updateBackgroundColor(color) {
17254
- this.props.updateChart({
17264
+ this.props.updateChart(this.props.figureId, {
17255
17265
  background: color,
17256
17266
  });
17257
17267
  }
17258
17268
  updateTitle(ev) {
17259
- this.props.updateChart({
17269
+ this.props.updateChart(this.props.figureId, {
17260
17270
  title: ev.target.value,
17261
17271
  });
17262
17272
  }
17263
17273
  updateSelect(attr, ev) {
17264
- this.props.updateChart({
17274
+ this.props.updateChart(this.props.figureId, {
17265
17275
  [attr]: ev.target.value,
17266
17276
  });
17267
17277
  }
@@ -17299,7 +17309,7 @@ class GaugeChartConfigPanel extends Component {
17299
17309
  this.dataRange = ranges[0];
17300
17310
  }
17301
17311
  updateDataRange() {
17302
- this.state.dataRangeDispatchResult = this.props.updateChart({
17312
+ this.state.dataRangeDispatchResult = this.props.updateChart(this.props.figureId, {
17303
17313
  dataRange: this.dataRange,
17304
17314
  });
17305
17315
  }
@@ -17361,12 +17371,12 @@ class GaugeChartDesignPanel extends Component {
17361
17371
  }
17362
17372
  updateBackgroundColor(color) {
17363
17373
  this.state.openedMenu = undefined;
17364
- this.props.updateChart({
17374
+ this.props.updateChart(this.props.figureId, {
17365
17375
  background: color,
17366
17376
  });
17367
17377
  }
17368
17378
  updateTitle(ev) {
17369
- this.props.updateChart({
17379
+ this.props.updateChart(this.props.figureId, {
17370
17380
  title: ev.target.value,
17371
17381
  });
17372
17382
  }
@@ -17435,7 +17445,7 @@ class GaugeChartDesignPanel extends Component {
17435
17445
  }
17436
17446
  }
17437
17447
  updateSectionRule(sectionRule) {
17438
- this.state.sectionRuleDispatchResult = this.props.updateChart({
17448
+ this.state.sectionRuleDispatchResult = this.props.updateChart(this.props.figureId, {
17439
17449
  sectionRule,
17440
17450
  });
17441
17451
  }
@@ -17460,17 +17470,17 @@ class LineConfigPanel extends LineBarPieConfigPanel {
17460
17470
  return false;
17461
17471
  }
17462
17472
  onUpdateLabelsAsText(ev) {
17463
- this.props.updateChart({
17473
+ this.props.updateChart(this.props.figureId, {
17464
17474
  labelsAsText: ev.target.checked,
17465
17475
  });
17466
17476
  }
17467
17477
  onUpdateStacked(ev) {
17468
- this.props.updateChart({
17478
+ this.props.updateChart(this.props.figureId, {
17469
17479
  stacked: ev.target.checked,
17470
17480
  });
17471
17481
  }
17472
17482
  onUpdateAggregated(ev) {
17473
- this.props.updateChart({
17483
+ this.props.updateChart(this.props.figureId, {
17474
17484
  aggregated: ev.target.checked,
17475
17485
  });
17476
17486
  }
@@ -17511,7 +17521,7 @@ class ScorecardChartConfigPanel extends Component {
17511
17521
  this.keyValue = ranges[0];
17512
17522
  }
17513
17523
  updateKeyValueRange() {
17514
- this.state.keyValueDispatchResult = this.props.updateChart({
17524
+ this.state.keyValueDispatchResult = this.props.updateChart(this.props.figureId, {
17515
17525
  keyValue: this.keyValue,
17516
17526
  });
17517
17527
  }
@@ -17519,12 +17529,12 @@ class ScorecardChartConfigPanel extends Component {
17519
17529
  this.baseline = ranges[0];
17520
17530
  }
17521
17531
  updateBaselineRange() {
17522
- this.state.baselineDispatchResult = this.props.updateChart({
17532
+ this.state.baselineDispatchResult = this.props.updateChart(this.props.figureId, {
17523
17533
  baseline: this.baseline,
17524
17534
  });
17525
17535
  }
17526
17536
  updateBaselineMode(ev) {
17527
- this.props.updateChart({ baselineMode: ev.target.value });
17537
+ this.props.updateChart(this.props.figureId, { baselineMode: ev.target.value });
17528
17538
  }
17529
17539
  }
17530
17540
  ScorecardChartConfigPanel.template = "o-spreadsheet-ScorecardChartConfigPanel";
@@ -17546,12 +17556,12 @@ class ScorecardChartDesignPanel extends Component {
17546
17556
  useExternalListener(window, "click", this.closeMenus);
17547
17557
  }
17548
17558
  updateTitle(ev) {
17549
- this.props.updateChart({
17559
+ this.props.updateChart(this.props.figureId, {
17550
17560
  title: ev.target.value,
17551
17561
  });
17552
17562
  }
17553
17563
  updateBaselineDescr(ev) {
17554
- this.props.updateChart({ baselineDescr: ev.target.value });
17564
+ this.props.updateChart(this.props.figureId, { baselineDescr: ev.target.value });
17555
17565
  }
17556
17566
  toggleColorPicker(colorPickerId) {
17557
17567
  if (this.state.openedColorPicker === colorPickerId) {
@@ -17564,13 +17574,13 @@ class ScorecardChartDesignPanel extends Component {
17564
17574
  setColor(color, colorPickerId) {
17565
17575
  switch (colorPickerId) {
17566
17576
  case "backgroundColor":
17567
- this.props.updateChart({ background: color });
17577
+ this.props.updateChart(this.props.figureId, { background: color });
17568
17578
  break;
17569
17579
  case "baselineColorDown":
17570
- this.props.updateChart({ baselineColorDown: color });
17580
+ this.props.updateChart(this.props.figureId, { baselineColorDown: color });
17571
17581
  break;
17572
17582
  case "baselineColorUp":
17573
- this.props.updateChart({ baselineColorUp: color });
17583
+ this.props.updateChart(this.props.figureId, { baselineColorUp: color });
17574
17584
  break;
17575
17585
  }
17576
17586
  this.closeMenus();
@@ -17635,16 +17645,9 @@ css /* scss */ `
17635
17645
  }
17636
17646
  `;
17637
17647
  class ChartPanel extends Component {
17638
- constructor() {
17639
- super(...arguments);
17640
- this.shouldUpdateChart = true;
17641
- }
17642
17648
  get figureId() {
17643
17649
  return this.state.figureId;
17644
17650
  }
17645
- get sheetId() {
17646
- return this.state.sheetId;
17647
- }
17648
17651
  setup() {
17649
17652
  const selectedFigureId = this.env.model.getters.getSelectedFigureId();
17650
17653
  if (!selectedFigureId) {
@@ -17653,17 +17656,11 @@ class ChartPanel extends Component {
17653
17656
  this.state = useState({
17654
17657
  panel: "configuration",
17655
17658
  figureId: selectedFigureId,
17656
- sheetId: this.env.model.getters.getActiveSheetId(),
17657
17659
  });
17658
17660
  onWillUpdateProps(() => {
17659
17661
  const selectedFigureId = this.env.model.getters.getSelectedFigureId();
17660
17662
  if (selectedFigureId && selectedFigureId !== this.state.figureId) {
17661
17663
  this.state.figureId = selectedFigureId;
17662
- this.state.sheetId = this.env.model.getters.getActiveSheetId();
17663
- this.shouldUpdateChart = false;
17664
- }
17665
- else {
17666
- this.shouldUpdateChart = true;
17667
17664
  }
17668
17665
  if (!this.env.model.getters.isChartDefined(this.figureId)) {
17669
17666
  this.props.onCloseSidePanel();
@@ -17671,8 +17668,8 @@ class ChartPanel extends Component {
17671
17668
  }
17672
17669
  });
17673
17670
  }
17674
- updateChart(updateDefinition) {
17675
- if (!this.shouldUpdateChart) {
17671
+ updateChart(figureId, updateDefinition) {
17672
+ if (figureId !== this.figureId) {
17676
17673
  return;
17677
17674
  }
17678
17675
  const definition = {
@@ -17681,8 +17678,8 @@ class ChartPanel extends Component {
17681
17678
  };
17682
17679
  return this.env.model.dispatch("UPDATE_CHART", {
17683
17680
  definition,
17684
- id: this.figureId,
17685
- sheetId: this.sheetId,
17681
+ id: figureId,
17682
+ sheetId: this.env.model.getters.getFigureSheetId(figureId),
17686
17683
  });
17687
17684
  }
17688
17685
  onTypeChange(type) {
@@ -17694,7 +17691,7 @@ class ChartPanel extends Component {
17694
17691
  this.env.model.dispatch("UPDATE_CHART", {
17695
17692
  definition,
17696
17693
  id: this.figureId,
17697
- sheetId: this.sheetId,
17694
+ sheetId: this.env.model.getters.getFigureSheetId(this.figureId),
17698
17695
  });
17699
17696
  }
17700
17697
  get chartPanel() {
@@ -19856,6 +19853,7 @@ class Composer extends Component {
19856
19853
  (this.autoCompleteState.selectedIndex + 1) % this.autoCompleteState.values.length;
19857
19854
  }
19858
19855
  }
19856
+ this.updateCursorIfNeeded();
19859
19857
  }
19860
19858
  processTabKey(ev) {
19861
19859
  var _a;
@@ -19926,10 +19924,12 @@ class Composer extends Component {
19926
19924
  }
19927
19925
  else {
19928
19926
  ev.stopPropagation();
19927
+ this.updateCursorIfNeeded();
19929
19928
  }
19930
- const { start, end } = this.contentHelper.getCurrentSelection();
19931
- if (!this.env.model.getters.isSelectingForComposer() &&
19932
- !(ev.key === "Enter" && (ev.altKey || ev.ctrlKey))) {
19929
+ }
19930
+ updateCursorIfNeeded() {
19931
+ if (!this.env.model.getters.isSelectingForComposer()) {
19932
+ const { start, end } = this.contentHelper.getCurrentSelection();
19933
19933
  this.env.model.dispatch("CHANGE_COMPOSER_CURSOR_SELECTION", { start, end });
19934
19934
  this.isKeyStillDown = true;
19935
19935
  }
@@ -19987,7 +19987,12 @@ class Composer extends Component {
19987
19987
  };
19988
19988
  });
19989
19989
  if (searchTerm) {
19990
- values = fuzzyLookup(searchTerm, values, (t) => t.text);
19990
+ if (searchTerm.toLowerCase() === "true" || searchTerm.toLowerCase() === "false") {
19991
+ values = [];
19992
+ }
19993
+ else {
19994
+ values = fuzzyLookup(searchTerm, values, (t) => t.text);
19995
+ }
19991
19996
  }
19992
19997
  else {
19993
19998
  // alphabetical order
@@ -23064,6 +23069,16 @@ const XLSX_INDEXED_COLORS = {
23064
23069
  63: "333333",
23065
23070
  64: "000000",
23066
23071
  65: "FFFFFF", // system background
23072
+ };
23073
+ const IMAGE_MIMETYPE_EXTENSION_MAPPING = {
23074
+ "image/avif": "avif",
23075
+ "image/bmp": "bmp",
23076
+ "image/gif": "gif",
23077
+ "image/vnd.microsoft.icon": "ico",
23078
+ "image/jpeg": "jpeg",
23079
+ "image/png": "png",
23080
+ "image/tiff": "tiff",
23081
+ "image/webp": "webp",
23067
23082
  };
23068
23083
 
23069
23084
  /**
@@ -25500,6 +25515,11 @@ function createOverride(partName, contentType) {
25500
25515
  <Override ContentType="${contentType}" PartName="${partName}" />
25501
25516
  `;
25502
25517
  }
25518
+ function createDefaultXMLElement(extension, contentType) {
25519
+ return escapeXml /*xml*/ `
25520
+ <Default Extension="${extension}" ContentType="${contentType}" />
25521
+ `;
25522
+ }
25503
25523
  function joinXmlNodes(xmlNodes) {
25504
25524
  return new XMLString(xmlNodes.join("\n"));
25505
25525
  }
@@ -39561,7 +39581,7 @@ class ImageProvider {
39561
39581
  const file = await this.getImageFromUser();
39562
39582
  const path = await this.fileStore.upload(file);
39563
39583
  const size = await this.getImageSize(path);
39564
- return { path, size };
39584
+ return { path, size, mimetype: file.type };
39565
39585
  }
39566
39586
  getImageFromUser() {
39567
39587
  return new Promise((resolve, reject) => {
@@ -44627,8 +44647,7 @@ function createWorksheets(data, construct) {
44627
44647
  // Figures and Charts
44628
44648
  let drawingNode = escapeXml ``;
44629
44649
  const drawingRelIds = [];
44630
- const charts = sheet.charts;
44631
- for (const chart of charts) {
44650
+ for (const chart of sheet.charts) {
44632
44651
  const xlsxChartId = convertChartId(chart.id);
44633
44652
  const chartRelId = addRelsToFile(construct.relsFiles, `xl/drawings/_rels/drawing${sheetIndex}.xml.rels`, {
44634
44653
  target: `../charts/chart${xlsxChartId}.xml`,
@@ -44637,20 +44656,27 @@ function createWorksheets(data, construct) {
44637
44656
  drawingRelIds.push(chartRelId);
44638
44657
  files.push(createXMLFile(createChart(chart, sheetIndex, data), `xl/charts/chart${xlsxChartId}.xml`, "chart"));
44639
44658
  }
44640
- const images = sheet.images;
44641
- for (const image of images) {
44659
+ for (const image of sheet.images) {
44660
+ const mimeType = image.data.mimetype;
44661
+ if (mimeType === undefined)
44662
+ continue;
44663
+ const extension = IMAGE_MIMETYPE_EXTENSION_MAPPING[mimeType];
44664
+ // only support exporting images with mimetypes specified in the mapping
44665
+ if (extension === undefined)
44666
+ continue;
44642
44667
  const xlsxImageId = convertImageId(image.id);
44668
+ let imageFileName = `image${xlsxImageId}.${extension}`;
44643
44669
  const imageRelId = addRelsToFile(construct.relsFiles, `xl/drawings/_rels/drawing${sheetIndex}.xml.rels`, {
44644
- target: `../media/image${xlsxImageId}`,
44670
+ target: `../media/${imageFileName}`,
44645
44671
  type: XLSX_RELATION_TYPE.image,
44646
44672
  });
44647
44673
  drawingRelIds.push(imageRelId);
44648
44674
  files.push({
44649
- path: `xl/media/image${xlsxImageId}`,
44650
- imagePath: image.data.path,
44675
+ path: `xl/media/${imageFileName}`,
44676
+ imageSrc: image.data.path,
44651
44677
  });
44652
44678
  }
44653
- const drawings = [...charts, ...images];
44679
+ const drawings = [...sheet.charts, ...sheet.images];
44654
44680
  if (drawings.length) {
44655
44681
  const drawingRelId = addRelsToFile(construct.relsFiles, `xl/worksheets/_rels/sheet${sheetIndex}.xml.rels`, {
44656
44682
  target: `../drawings/drawing${sheetIndex}.xml`,
@@ -44769,6 +44795,8 @@ function createRelsFiles(relsFiles) {
44769
44795
  }
44770
44796
  function createContentTypes(files) {
44771
44797
  const overrideNodes = [];
44798
+ // hard-code supported image mimetypes
44799
+ const imageDefaultNodes = Object.entries(IMAGE_MIMETYPE_EXTENSION_MAPPING).map(([mimetype, extension]) => createDefaultXMLElement(extension, mimetype));
44772
44800
  for (const file of files) {
44773
44801
  if ("contentType" in file && file.contentType) {
44774
44802
  overrideNodes.push(createOverride("/" + file.path, CONTENT_TYPES[file.contentType]));
@@ -44776,6 +44804,7 @@ function createContentTypes(files) {
44776
44804
  }
44777
44805
  const xml = escapeXml /*xml*/ `
44778
44806
  <Types xmlns="${NAMESPACE["Types"]}">
44807
+ ${joinXmlNodes(Object.values(imageDefaultNodes))}
44779
44808
  <Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml" />
44780
44809
  <Default Extension="xml" ContentType="application/xml" />
44781
44810
  ${joinXmlNodes(overrideNodes)}
@@ -45307,6 +45336,6 @@ function addFunction(functionName, functionDescription) {
45307
45336
  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 };
45308
45337
 
45309
45338
 
45310
- __info__.version = '16.2.7';
45311
- __info__.date = '2023-05-25T12:56:32.163Z';
45312
- __info__.hash = '047a6d5';
45339
+ __info__.version = '16.2.9';
45340
+ __info__.date = '2023-06-12T13:49:57.216Z';
45341
+ __info__.hash = '37e2719';