@lotics/app-sdk 0.131.0 → 0.131.2

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 (2) hide show
  1. package/dist/index.js +48 -8
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -2852,7 +2852,7 @@ __export(expression_string_exports, {
2852
2852
  contains: () => contains,
2853
2853
  endsWith: () => endsWith,
2854
2854
  formatDecimal: () => formatDecimal,
2855
- formatNumber: () => formatNumber,
2855
+ formatNumber: () => formatNumber2,
2856
2856
  join: () => join,
2857
2857
  length: () => length,
2858
2858
  localeCompare: () => localeCompare,
@@ -3241,6 +3241,27 @@ function uuidV5(name, namespace) {
3241
3241
  return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
3242
3242
  }
3243
3243
 
3244
+ // ../shared/src/format_unit.ts
3245
+ function signed(format2, n) {
3246
+ return n < 0 ? `\u2212${format2(-n)}` : format2(n + 0);
3247
+ }
3248
+
3249
+ // ../shared/src/format_money.ts
3250
+ function numberFormatter(locale, maximumFractionDigits) {
3251
+ const key = `${locale}\0${maximumFractionDigits}`;
3252
+ let format2 = numberFormatters.get(key);
3253
+ if (format2 === void 0) {
3254
+ format2 = new Intl.NumberFormat(locale, { maximumFractionDigits });
3255
+ numberFormatters.set(key, format2);
3256
+ }
3257
+ return format2;
3258
+ }
3259
+ var numberFormatters = /* @__PURE__ */ new Map();
3260
+ function formatNumber(value, options = {}) {
3261
+ const { locale = "vi-VN", maxFractionDigits = 2 } = options;
3262
+ return signed((magnitude) => numberFormatter(locale, maxFractionDigits).format(magnitude), value);
3263
+ }
3264
+
3244
3265
  // ../shared/src/expression_string.ts
3245
3266
  function join(arr, separator = ",") {
3246
3267
  if (arr == null) return "";
@@ -3625,7 +3646,7 @@ function enNumberToWords(n, negative) {
3625
3646
  const result = parts.join(" ");
3626
3647
  return negative ? "minus " + result : result;
3627
3648
  }
3628
- function formatNumber(value, decimals) {
3649
+ function formatNumber2(value, decimals) {
3629
3650
  if (value == null) return "";
3630
3651
  if (typeof value !== "number" || Number.isNaN(value)) {
3631
3652
  throw new ExpressionArgumentError("formatNumber: expected number, got " + typeof value);
@@ -3638,6 +3659,13 @@ function formatDecimal(value, decimals, locale) {
3638
3659
  if (typeof value !== "number" || Number.isNaN(value)) {
3639
3660
  throw new ExpressionArgumentError("formatDecimal: expected number, got " + typeof value);
3640
3661
  }
3662
+ if (typeof decimals === "string" && locale === void 0) {
3663
+ if (!isUsableLocale(decimals)) {
3664
+ throw new ExpressionArgumentError(`formatDecimal(value, locale) requires a locale tag, got "${decimals}". Example: formatDecimal(2.5, "vi-VN").`);
3665
+ }
3666
+ return formatNumber(value, { locale: decimals });
3667
+ }
3668
+ if (typeof decimals !== "number") throw new ExpressionArgumentError("formatDecimal: decimals must be an integer between 0 and 100");
3641
3669
  assertDecimals(decimals, "formatDecimal");
3642
3670
  if (typeof locale !== "string" || locale === "" || !isUsableLocale(locale)) {
3643
3671
  throw new ExpressionArgumentError(
@@ -7918,8 +7946,20 @@ var formulaOnlyFunctions = {
7918
7946
  const declared = names ?? {};
7919
7947
  for (const key of held2) if (typeof key !== "string" || !Object.hasOwn(declared, key)) throw new UndeclaredOptionError(field);
7920
7948
  return Object.entries(declared).filter(([key]) => held2.has(key)).map(([, name]) => name).join(", ");
7921
- }
7949
+ },
7950
+ // A lookup through a link holding several rows reaches a formula as its one value while it holds one row, so a
7951
+ // list helper reads a single value as a list of it.
7952
+ join: (list2, separator) => join(asList(list2), separator),
7953
+ sum: (list2) => sum(asList(list2)),
7954
+ mean: (list2) => mean(asList(list2)),
7955
+ first: (list2) => first(asList(list2)),
7956
+ last: (list2) => last(asList(list2)),
7957
+ unique: (list2) => unique(asList(list2)),
7958
+ compact: (list2) => compact(asList(list2))
7922
7959
  };
7960
+ function asList(value) {
7961
+ return value === null || value === void 0 || Array.isArray(value) ? value : [value];
7962
+ }
7923
7963
  var MAX_HELD_TIMEZONES = 512;
7924
7964
  var functionsByTimezone = /* @__PURE__ */ new Map();
7925
7965
  function timezoneAwareFunctions(defaultTimezone) {
@@ -10244,14 +10284,14 @@ function asIds(ids) {
10244
10284
  if (!Array.isArray(ids) || !ids.every((id) => typeof id === "string")) return null;
10245
10285
  return ids;
10246
10286
  }
10247
- function asList(cell) {
10287
+ function asList2(cell) {
10248
10288
  if (Array.isArray(cell)) return cell;
10249
10289
  return cell === null || cell === void 0 ? [] : [cell];
10250
10290
  }
10251
10291
  function adjusted(current, items, op) {
10252
10292
  const keyOf2 = (item) => item !== null && typeof item === "object" && "id" in item ? item.id : item;
10253
- const held2 = asList(current);
10254
- const given = asList(items);
10293
+ const held2 = asList2(current);
10294
+ const given = asList2(items);
10255
10295
  if (op === "add_to") {
10256
10296
  const have = new Set(held2.map(keyOf2));
10257
10297
  return [...held2, ...given.filter((item) => !have.has(keyOf2(item)))];
@@ -10260,8 +10300,8 @@ function adjusted(current, items, op) {
10260
10300
  return held2.filter((item) => !gone.has(keyOf2(item)));
10261
10301
  }
10262
10302
  function withoutMade(current, templates) {
10263
- const gone = new Set(asList(templates));
10264
- return asList(current).filter((item) => !(item !== null && typeof item === "object" && "document_template_id" in item && gone.has(item.document_template_id)));
10303
+ const gone = new Set(asList2(templates));
10304
+ return asList2(current).filter((item) => !(item !== null && typeof item === "object" && "document_template_id" in item && gone.has(item.document_template_id)));
10265
10305
  }
10266
10306
  function note(walk, effect) {
10267
10307
  if (walk.unsure && effect.kind !== "unknown") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lotics/app-sdk",
3
- "version": "0.131.0",
3
+ "version": "0.131.2",
4
4
  "description": "The SDK a Lotics custom-code app reads and writes through — typed hooks over the host bridge, cell readers, mount() and AppRouter",
5
5
  "type": "module",
6
6
  "exports": {