cotomy 1.0.4 → 1.0.5

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 CHANGED
@@ -255,8 +255,15 @@ The Form layer builds on `CotomyElement` for common form flows.
255
255
  - `mail`, `tel`, `url` — Wrap the value in a corresponding anchor tag.
256
256
  - `number` — Uses `Intl.NumberFormat` with `data-cotomy-locale`/`data-cotomy-currency` inheritance.
257
257
  - `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`).
258
- - `utc` — Treats the value as UTC (or appends `Z` when missing) and formats with `data-cotomy-format` (default `YYYY/MM/DD HH:mm`).
259
- - `date` — Renders local dates with `data-cotomy-format` (default `YYYY/MM/DD`) when the input is a valid `Date` value.
258
+ - `utc` — Treats the value as UTC (or appends `Z` when missing) and formats with `data-cotomy-format` (default `YYYY/MM/DD HH:mm`). By default it renders in local time; set `data-cotomy-timezone` (element or ancestor) to render in a specific IANA timezone.
259
+ - `date` — Renders local dates with `data-cotomy-format` (default `YYYY/MM/DD`) when the input is a valid `Date` value. By default it renders in local time; set `data-cotomy-timezone` (element or ancestor) to render in a specific IANA timezone.
260
+
261
+ ### UTC Renderer
262
+
263
+ - Supports ISO 8601 offsets (`+09:00`, `-05:00`)
264
+ - Explicitly supports `Z` (UTC indicator)
265
+ - Offset-less timestamps are treated as UTC (internally appends "Z" before parsing)
266
+ - `data-cotomy-timezone` is optional. When omitted, output stays local; when set, output is converted to the specified IANA timezone (supports ancestor inheritance).
260
267
 
261
268
  Example:
262
269
 
@@ -289,6 +289,12 @@ __webpack_require__.d(__webpack_exports__, {
289
289
  // EXTERNAL MODULE: ./node_modules/dayjs/dayjs.min.js
290
290
  var dayjs_min = __webpack_require__(353);
291
291
  var dayjs_min_default = /*#__PURE__*/__webpack_require__.n(dayjs_min);
292
+ // EXTERNAL MODULE: ./node_modules/dayjs/plugin/timezone.js
293
+ var timezone = __webpack_require__(569);
294
+ var timezone_default = /*#__PURE__*/__webpack_require__.n(timezone);
295
+ // EXTERNAL MODULE: ./node_modules/dayjs/plugin/utc.js
296
+ var utc = __webpack_require__(826);
297
+ var utc_default = /*#__PURE__*/__webpack_require__.n(utc);
292
298
  ;// ./node_modules/http-status-codes/build/es/status-codes.js
293
299
  // Generated file. Do not edit
294
300
  var StatusCodes;
@@ -2257,6 +2263,10 @@ CotomyWindow._instance = null;
2257
2263
 
2258
2264
 
2259
2265
 
2266
+
2267
+
2268
+ dayjs_min_default().extend((utc_default()));
2269
+ dayjs_min_default().extend((timezone_default()));
2260
2270
  class CotomyApiException extends Error {
2261
2271
  constructor(status, message, response, bodyText = "") {
2262
2272
  super(message);
@@ -2451,40 +2461,21 @@ class CotomyDotBindNameGenerator {
2451
2461
  return parent ? `${parent}[${index}]` : `[${index}]`;
2452
2462
  }
2453
2463
  }
2454
- class CotomyBindNameGeneratorProvider {
2455
- static getDefault() {
2456
- return this._default ?? (this._default = new CotomyBracketBindNameGenerator());
2457
- }
2458
- static setDefault(generator) {
2459
- this._default = generator;
2460
- }
2461
- static resetDefault() {
2462
- this._default = undefined;
2463
- }
2464
- }
2465
2464
  class CotomyViewRenderer {
2466
2465
  static get defaultBindNameGenerator() {
2467
- return CotomyBindNameGeneratorProvider.getDefault();
2466
+ return this._defaultBindNameGenerator ?? new CotomyBracketBindNameGenerator();
2468
2467
  }
2469
2468
  static set defaultBindNameGenerator(generator) {
2470
- CotomyBindNameGeneratorProvider.setDefault(generator);
2469
+ this._defaultBindNameGenerator = generator;
2471
2470
  }
2472
2471
  static resetDefaultBindNameGenerator() {
2473
- CotomyBindNameGeneratorProvider.resetDefault();
2472
+ this._defaultBindNameGenerator = null;
2474
2473
  }
2475
2474
  constructor(element, bindNameGenerator = CotomyViewRenderer.defaultBindNameGenerator) {
2476
2475
  this.element = element;
2477
2476
  this.bindNameGenerator = bindNameGenerator;
2478
2477
  this._renderers = {};
2479
- this._builded = false;
2480
- }
2481
- get locale() {
2482
- const languages = (navigator.languages && navigator.languages.length ? navigator.languages : [navigator.language]).filter(Boolean);
2483
- let locale = this.element.attribute("data-cotomy-locale")
2484
- || this.element.closest("[data-cotomy-locale]")?.attribute("data-cotomy-locale")
2485
- || languages[0]
2486
- || 'en-US';
2487
- return locale.includes("-") ? locale.split("-")[0] : locale;
2478
+ this._initialized = false;
2488
2479
  }
2489
2480
  renderer(type, callback) {
2490
2481
  this._renderers[type] = callback;
@@ -2495,7 +2486,7 @@ class CotomyViewRenderer {
2495
2486
  return this._renderers;
2496
2487
  }
2497
2488
  get initialized() {
2498
- return this._builded;
2489
+ return this._initialized;
2499
2490
  }
2500
2491
  initialize() {
2501
2492
  if (!this.initialized) {
@@ -2527,16 +2518,27 @@ class CotomyViewRenderer {
2527
2518
  ...(currency ? { style: "currency", currency } : {}),
2528
2519
  ...(hasFractionDigits ? { minimumFractionDigits: fractionDigits, maximumFractionDigits: fractionDigits } : {}),
2529
2520
  };
2530
- element.text = new Intl.NumberFormat(this.locale, options).format(value);
2521
+ const languages = (navigator.languages && navigator.languages.length ? navigator.languages : [navigator.language]).filter(Boolean);
2522
+ const localeAttribute = element.attribute("data-cotomy-locale")
2523
+ || element.closest("[data-cotomy-locale]")?.attribute("data-cotomy-locale")
2524
+ || this.element.attribute("data-cotomy-locale")
2525
+ || this.element.closest("[data-cotomy-locale]")?.attribute("data-cotomy-locale")
2526
+ || languages[0]
2527
+ || "en-US";
2528
+ const locale = localeAttribute.includes("-") ? localeAttribute.split("-")[0] : localeAttribute;
2529
+ element.text = new Intl.NumberFormat(locale, options).format(value);
2531
2530
  }
2532
2531
  });
2533
2532
  this.renderer("utc", (element, value) => {
2534
2533
  if (value) {
2535
- const hasOffset = /[+-]\d{2}:\d{2}$/.test(value);
2534
+ const hasOffset = /([+-]\d{2}:\d{2}|Z)$/.test(value);
2536
2535
  const date = hasOffset ? new Date(value) : new Date(`${value}Z`);
2537
2536
  if (!isNaN(date.getTime())) {
2538
2537
  const format = element.attribute("data-cotomy-format") ?? "YYYY/MM/DD HH:mm";
2539
- element.text = dayjs_min_default()(date).format(format);
2538
+ const timezone = element.attribute("data-cotomy-timezone")
2539
+ || element.closest("[data-cotomy-timezone]")?.attribute("data-cotomy-timezone");
2540
+ const dt = dayjs_min_default()(date);
2541
+ element.text = timezone && timezone.trim() !== "" ? dt.tz(timezone).format(format) : dt.format(format);
2540
2542
  }
2541
2543
  }
2542
2544
  });
@@ -2545,11 +2547,14 @@ class CotomyViewRenderer {
2545
2547
  const date = new Date(value);
2546
2548
  if (!isNaN(date.getTime())) {
2547
2549
  const format = element.attribute("data-cotomy-format") ?? "YYYY/MM/DD";
2548
- element.text = dayjs_min_default()(date).format(format);
2550
+ const timezone = element.attribute("data-cotomy-timezone")
2551
+ || element.closest("[data-cotomy-timezone]")?.attribute("data-cotomy-timezone");
2552
+ const dt = dayjs_min_default()(date);
2553
+ element.text = timezone && timezone.trim() !== "" ? dt.tz(timezone).format(format) : dt.format(format);
2549
2554
  }
2550
2555
  }
2551
2556
  });
2552
- this._builded = true;
2557
+ this._initialized = true;
2553
2558
  }
2554
2559
  return this;
2555
2560
  }
@@ -2607,6 +2612,7 @@ class CotomyViewRenderer {
2607
2612
  return this;
2608
2613
  }
2609
2614
  }
2615
+ CotomyViewRenderer._defaultBindNameGenerator = null;
2610
2616
  class CotomyApi {
2611
2617
  constructor(_options = {
2612
2618
  baseUrl: null, headers: null, credentials: null, redirect: null,
@@ -3160,12 +3166,6 @@ class CotomyEntityFillApiForm extends CotomyEntityApiForm {
3160
3166
  }
3161
3167
  }
3162
3168
 
3163
- // EXTERNAL MODULE: ./node_modules/dayjs/plugin/timezone.js
3164
- var timezone = __webpack_require__(569);
3165
- var timezone_default = /*#__PURE__*/__webpack_require__.n(timezone);
3166
- // EXTERNAL MODULE: ./node_modules/dayjs/plugin/utc.js
3167
- var utc = __webpack_require__(826);
3168
- var utc_default = /*#__PURE__*/__webpack_require__.n(utc);
3169
3169
  ;// ./src/page.ts
3170
3170
 
3171
3171