cotomy 0.3.12 → 0.3.14
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/README.md +1 -0
- package/dist/browser/cotomy.js +14 -5
- package/dist/browser/cotomy.js.map +1 -1
- package/dist/browser/cotomy.min.js +1 -1
- package/dist/browser/cotomy.min.js.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/api.js +10 -3
- package/dist/esm/api.js.map +1 -1
- package/dist/esm/view.js +4 -2
- package/dist/esm/view.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -243,6 +243,7 @@ The Form layer builds on `CotomyElement` for common form flows.
|
|
|
243
243
|
|
|
244
244
|
- `mail`, `tel`, `url` — Wrap the value in a corresponding anchor tag.
|
|
245
245
|
- `number` — Uses `Intl.NumberFormat` with `data-cotomy-locale`/`data-cotomy-currency` inheritance.
|
|
246
|
+
- `data-cotomy-fraction-digits="2"` — Forces fixed fraction digits (sets both `minimumFractionDigits` and `maximumFractionDigits`). Works with or without `data-cotomy-currency` (e.g. `0` → `0.00`).
|
|
246
247
|
- `utc` — Treats the value as UTC (or appends `Z` when missing) and formats with `data-cotomy-format` (default `YYYY/MM/DD HH:mm`).
|
|
247
248
|
- `date` — Renders local dates with `data-cotomy-format` (default `YYYY/MM/DD`) when the input is a valid `Date` value.
|
|
248
249
|
|
package/dist/browser/cotomy.js
CHANGED
|
@@ -893,7 +893,7 @@ class CotomyElement {
|
|
|
893
893
|
return new ctor(element);
|
|
894
894
|
}
|
|
895
895
|
static last(selector, type) {
|
|
896
|
-
const elements =
|
|
896
|
+
const elements = CotomyElement.find(selector, type);
|
|
897
897
|
return elements.pop();
|
|
898
898
|
}
|
|
899
899
|
static find(selector, type) {
|
|
@@ -905,7 +905,9 @@ class CotomyElement {
|
|
|
905
905
|
return document.querySelector(selector) !== null;
|
|
906
906
|
}
|
|
907
907
|
static byId(id, type) {
|
|
908
|
-
|
|
908
|
+
const element = document.getElementById(id);
|
|
909
|
+
const ctor = (type ?? CotomyElement);
|
|
910
|
+
return !element ? undefined : new ctor(element);
|
|
909
911
|
}
|
|
910
912
|
static containsById(id) {
|
|
911
913
|
return document.getElementById(id) !== null;
|
|
@@ -2274,9 +2276,16 @@ class CotomyViewRenderer {
|
|
|
2274
2276
|
if (value !== undefined && value !== null) {
|
|
2275
2277
|
const currency = element.attribute("data-cotomy-currency")
|
|
2276
2278
|
|| element.closest("[data-cotomy-currency]")?.attribute("data-cotomy-currency");
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2279
|
+
const fractionDigitsAttribute = element.attribute("data-cotomy-fraction-digits")
|
|
2280
|
+
|| element.closest("[data-cotomy-fraction-digits]")?.attribute("data-cotomy-fraction-digits");
|
|
2281
|
+
const fractionDigits = fractionDigitsAttribute ? Number.parseInt(fractionDigitsAttribute, 10) : undefined;
|
|
2282
|
+
const hasFractionDigits = Number.isFinite(fractionDigits)
|
|
2283
|
+
&& fractionDigits && fractionDigits >= 0 && fractionDigits <= 20;
|
|
2284
|
+
const options = {
|
|
2285
|
+
...(currency ? { style: "currency", currency } : {}),
|
|
2286
|
+
...(hasFractionDigits ? { minimumFractionDigits: fractionDigits, maximumFractionDigits: fractionDigits } : {}),
|
|
2287
|
+
};
|
|
2288
|
+
element.text = new Intl.NumberFormat(this.locale, options).format(value);
|
|
2280
2289
|
}
|
|
2281
2290
|
});
|
|
2282
2291
|
this.renderer("utc", (element, value) => {
|