@tesouro/embedded-components-react 0.7.64 → 0.7.67

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.
Files changed (23) hide show
  1. package/README.md +1 -1
  2. package/dist/index.css +3 -0
  3. package/dist/index.d.ts +10 -10
  4. package/dist/lib/ProductsWidget.d.ts +40 -10
  5. package/dist/lib/ReceivablesWidget.d.ts +9 -9
  6. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/apiValidationErrors.js +34 -63
  7. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/currencyDisplay.js +6 -0
  8. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/discount.js +31 -30
  9. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/helpers.js +89 -87
  10. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/lineItems.js +84 -82
  11. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/preview.js +77 -75
  12. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/totals.js +54 -53
  13. package/dist/libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/useReceivableForm.js +458 -457
  14. package/dist/libs/tesouro-embedded-components-react/products-widget/feature/dist/lib/ProductsWidget/ProductsWidget.js +0 -2
  15. package/dist/libs/tesouro-embedded-components-react/shared/feature/dist/lib/analytics/build-info.js +1 -1
  16. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/helpers.js +33 -41
  17. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/labels.js +3 -4
  18. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/feature/dist/lib/useProductForm.js +42 -44
  19. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index2.js +14 -13
  20. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index3.js +128 -147
  21. package/dist/libs/tesouro-embedded-components-react/shared/product-catalog/ui/dist/index4.js +109 -92
  22. package/dist/libs/tesouro-embedded-components-react/shared/util/dist/lib/apiValidationErrors.js +33 -0
  23. package/package.json +1 -1
@@ -1,15 +1,16 @@
1
1
  import { minorExponentForCurrency as e } from "../../../../../shared/util/dist/lib/amountOutputToMajorUnits.js";
2
- import { isBlankLineItem as t, keepsSavedTaxRates as n, lineItemTaxRateMinorUnits as r, maxAmountLabel as i, parseQuantity as a, priceInputToMinorUnits as o } from "./lineItems.js";
3
- import { discountFromDraft as s } from "./discount.js";
2
+ import { currencyDisplayFor as t } from "./currencyDisplay.js";
3
+ import { isBlankLineItem as n, keepsSavedTaxRates as r, lineItemTaxRateMinorUnits as i, maxAmountLabel as a, parseQuantity as o, priceInputToMinorUnits as s } from "./lineItems.js";
4
+ import { discountFromDraft as c } from "./discount.js";
4
5
  //#region ../../libs/tesouro-embedded-components-react/invoicing-widget/feature/dist/lib/ReceivablesWidget/totals.js
5
- var c = 1e4;
6
- function l(e, t) {
7
- return Math.round(o(e.price, t) * a(e.quantity));
6
+ var l = 1e4;
7
+ function u(e, t) {
8
+ return Math.round(s(e.price, t) * o(e.quantity));
8
9
  }
9
- function u({ lineItems: e, currency: t, taxRate: n }) {
10
+ function d({ lineItems: e, currency: t, taxRate: n }) {
10
11
  let r = n ? Math.round(n * 100) : 0, i = 0, a = 0;
11
12
  for (let n of e) {
12
- let e = l(n, t);
13
+ let e = u(n, t);
13
14
  n.taxable ? i += e : a += e;
14
15
  }
15
16
  return {
@@ -19,84 +20,84 @@ function u({ lineItems: e, currency: t, taxRate: n }) {
19
20
  rateMinorUnits: r
20
21
  };
21
22
  }
22
- function d({ discount: e, subtotal: t }) {
23
+ function f({ discount: e, subtotal: t }) {
23
24
  if (!e) return 0;
24
25
  let n = e.value ?? (e.type === "amount" ? e.amount : Math.round(t * e.amount / 1e4));
25
26
  return Math.min(Math.max(n, 0), t);
26
27
  }
27
- function f({ taxableItemsSubtotal: e, nonTaxableItemsSubtotal: t, discountAmount: n }) {
28
+ function p({ taxableItemsSubtotal: e, nonTaxableItemsSubtotal: t, discountAmount: n }) {
28
29
  let r = e + t, i = r > 0 ? Math.round(e / r * n) : 0;
29
30
  return {
30
31
  taxableSubtotal: e - i,
31
32
  nonTaxableSubtotal: t - (n - i)
32
33
  };
33
34
  }
34
- function p({ lineItems: e, currency: t, rateMinorUnits: n, keepSavedRate: i, taxableItemsSubtotal: a, taxableSubtotal: o }) {
35
+ function m({ lineItems: e, currency: t, rateMinorUnits: n, keepSavedRate: r, taxableItemsSubtotal: a, taxableSubtotal: o }) {
35
36
  if (a <= 0) return 0;
36
37
  let s = /* @__PURE__ */ new Map();
37
38
  for (let a of e) {
38
39
  if (!a.taxable) continue;
39
- let e = r(a, n, i);
40
- s.set(e, (s.get(e) ?? 0) + l(a, t));
40
+ let e = i(a, n, r);
41
+ s.set(e, (s.get(e) ?? 0) + u(a, t));
41
42
  }
42
- let u = [...s], d = o, f = 0;
43
- return u.forEach(([e, t], n) => {
44
- let r = n === u.length - 1 ? d : Math.round(o * t / a);
43
+ let c = [...s], d = o, f = 0;
44
+ return c.forEach(([e, t], n) => {
45
+ let r = n === c.length - 1 ? d : Math.round(o * t / a);
45
46
  d -= r, f += r * e;
46
- }), Math.round(f / c);
47
+ }), Math.round(f / l);
47
48
  }
48
- function m({ lineItems: e, currency: t, taxRate: n, keepSavedRate: r = !1, discount: i }) {
49
- let a = u({
49
+ function h({ lineItems: e, currency: t, taxRate: n, keepSavedRate: r = !1, discount: i }) {
50
+ let a = d({
50
51
  lineItems: e,
51
52
  currency: t,
52
53
  taxRate: n
53
- }), o = d({
54
+ }), o = f({
54
55
  discount: i,
55
56
  subtotal: a.subtotal
56
- }), { taxableSubtotal: s, nonTaxableSubtotal: c } = f({
57
+ }), { taxableSubtotal: s, nonTaxableSubtotal: c } = p({
57
58
  ...a,
58
59
  discountAmount: o
59
- }), l = p({
60
+ }), l = m({
60
61
  lineItems: e,
61
62
  currency: t,
62
63
  rateMinorUnits: a.rateMinorUnits,
63
64
  keepSavedRate: r,
64
65
  taxableItemsSubtotal: a.taxableItemsSubtotal,
65
66
  taxableSubtotal: s
66
- }), m = a.subtotal - o;
67
+ }), u = a.subtotal - o;
67
68
  return {
68
69
  ...a,
69
70
  discountAmount: o,
70
- discountedSubtotal: m,
71
+ discountedSubtotal: u,
71
72
  taxableSubtotal: s,
72
73
  nonTaxableSubtotal: c,
73
74
  totalTaxes: l,
74
- total: m + l
75
+ total: u + l
75
76
  };
76
77
  }
77
- function h(e) {
78
- return m({
79
- lineItems: e.lineItems.filter((e) => !t(e)),
78
+ function g(e) {
79
+ return h({
80
+ lineItems: e.lineItems.filter((e) => !n(e)),
80
81
  currency: e.currency,
81
82
  taxRate: Number(e.taxRate) || void 0,
82
- keepSavedRate: n(e.taxRate, e.savedTaxRate),
83
- discount: s(e)
83
+ keepSavedRate: r(e.taxRate, e.savedTaxRate),
84
+ discount: c(e)
84
85
  });
85
86
  }
86
- function g(e, t) {
87
- let n = s(e);
88
- if (n) return n.type === "percentage" ? n.amount > 1e4 ? t.discountPercentageTooHigh : void 0 : n.amount > h(e).subtotal ? t.discountExceedsSubtotal : void 0;
89
- }
90
- function _(e, n) {
91
- if (e.lineItems.filter((e) => !t(e)).some((t) => o(t.price, e.currency) > 9e15)) return;
92
- let { subtotal: r, total: a } = h(e), s = i(e.currency);
93
- if (r > 9e15) return n.invoiceSubtotalTooHigh.replace("{maxAmount}", s);
94
- if (a > 9e15) return n.invoiceTotalTooHigh.replace("{maxAmount}", s);
87
+ function _(e, t) {
88
+ let n = c(e);
89
+ if (n) return n.type === "percentage" ? n.amount > 1e4 ? t.discountPercentageTooHigh : void 0 : n.amount > g(e).subtotal ? t.discountExceedsSubtotal : void 0;
95
90
  }
96
91
  function v(e, t) {
97
- return h(e).total > 0 ? void 0 : t.invoiceTotalZero;
92
+ if (e.lineItems.filter((e) => !n(e)).some((t) => s(t.price, e.currency) > 9e15)) return;
93
+ let { subtotal: r, total: i } = g(e), o = a(e.currency);
94
+ if (r > 9e15) return t.invoiceSubtotalTooHigh.replace("{maxAmount}", o);
95
+ if (i > 9e15) return t.invoiceTotalTooHigh.replace("{maxAmount}", o);
98
96
  }
99
97
  function y(e, t) {
98
+ return g(e).total > 0 ? void 0 : t.invoiceTotalZero;
99
+ }
100
+ function b(e, t) {
100
101
  let n = e.formatToParts(t), r = (e) => e.type !== "currency" && e.type !== "literal", i = n.findIndex(r);
101
102
  if (i === -1) return e.format(t);
102
103
  let a = n.length - 1;
@@ -104,23 +105,23 @@ function y(e, t) {
104
105
  let o = (e) => e.map((e) => e.value).join("");
105
106
  return `${o(n.slice(0, i))}(${o(n.slice(i, a + 1))})${o(n.slice(a + 1))}`;
106
107
  }
107
- function b(t, n, r = !1) {
108
- let i = new Intl.NumberFormat(void 0, {
108
+ function x(n, r, i = !1) {
109
+ let a = new Intl.NumberFormat(void 0, {
109
110
  style: "currency",
110
- currency: n,
111
- currencyDisplay: "narrowSymbol"
112
- }), a = t / 10 ** e(n);
113
- return r ? y(i, a) : i.format(a);
111
+ currency: r,
112
+ currencyDisplay: t(r)
113
+ }), o = n / 10 ** e(r);
114
+ return i ? b(a, o) : a.format(o);
114
115
  }
115
- function x(e, t) {
116
+ function S(e, t) {
116
117
  return {
117
- subtotal: b(e.subtotal, t),
118
- discount: e.discountAmount > 0 ? b(e.discountAmount, t, !0) : b(0, t),
119
- nonTaxableSubtotal: b(e.nonTaxableSubtotal, t),
120
- taxableSubtotal: b(e.taxableSubtotal, t),
121
- tax: b(e.totalTaxes, t),
122
- total: b(e.total, t)
118
+ subtotal: x(e.subtotal, t),
119
+ discount: e.discountAmount > 0 ? x(e.discountAmount, t, !0) : x(0, t),
120
+ nonTaxableSubtotal: x(e.nonTaxableSubtotal, t),
121
+ taxableSubtotal: x(e.taxableSubtotal, t),
122
+ tax: x(e.totalTaxes, t),
123
+ total: x(e.total, t)
123
124
  };
124
125
  }
125
126
  //#endregion
126
- export { c as FULL_PERCENT_MINOR_UNITS, f as allocateDiscount, y as bracketAmount, x as buildFormTotalsView, h as calculateFormTotals, m as calculateInvoiceTotals, u as calculateItemsSubtotals, d as resolveDiscountAmount, g as validateDiscount, _ as validateInvoiceTotals, v as validateIssuableTotal };
127
+ export { l as FULL_PERCENT_MINOR_UNITS, p as allocateDiscount, b as bracketAmount, S as buildFormTotalsView, g as calculateFormTotals, h as calculateInvoiceTotals, d as calculateItemsSubtotals, f as resolveDiscountAmount, _ as validateDiscount, v as validateInvoiceTotals, y as validateIssuableTotal };