@commercelayer/app-elements 0.0.21 → 0.0.22

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.
@@ -1,8 +1,8 @@
1
1
  import * as r from "react";
2
2
  import a, { forwardRef as s } from "react";
3
- import { u as m, S as c, d as p, s as i } from "./overrides-a8601925.js";
3
+ import { u as m, S as c, d as p, s as i } from "./overrides-4cc26c3c.js";
4
4
  import "react-dom";
5
- import "./main-efbde4bf.js";
5
+ import "./main-95dd7764.js";
6
6
  import "@commercelayer/sdk";
7
7
  var l = /* @__PURE__ */ s(function(e, t) {
8
8
  var o = m(e);
@@ -1,5 +1,5 @@
1
- type Format = 'full' | 'noTime' | 'noYear';
2
- type FormatDateOptions = {
1
+ type Format = 'date' | 'time' | 'timeWithSeconds' | 'full' | 'fullWithSeconds' | 'distanceToNow';
2
+ interface FormatDateOptions {
3
3
  /**
4
4
  * JavaScript ISO date string. Example '2022-10-06T11:59:30.371Z'
5
5
  */
@@ -8,32 +8,57 @@ type FormatDateOptions = {
8
8
  * Set a specific timezone, when not passed default value is 'UTC'
9
9
  */
10
10
  timezone?: string;
11
- } & ({
12
11
  /**
13
12
  * How to format the date:
14
- * - full `Feb 28, 2023 · 5:30 PM`
15
- * - noTime `Feb 28, 2023`
16
- * - noYear `Feb 28`
17
- * @default noTime
13
+ * - `date` – can be `Today` when today, `Feb 28` when current year or `Feb 28, 2022` when previous year
14
+ * - `time` `04:34` `18:54`
15
+ * - `timeWithSeconds` `04:34:23` `18:54:12`
16
+ * - `full` – `Feb 28, 2023 · 15:30` the date in this string behaves like the `date` format
17
+ * - `fullWithSeconds` – `Feb 28, 2023 · 15:30:43` the date in this string behaves like the `date` format
18
+ * - `distanceToNow` – `about 1 hour ago` `10 months ago` `less than a minute ago`
19
+ * @default date
18
20
  */
19
21
  format?: Format;
20
- } | {
21
- /**
22
- * When set as `custom` a `customTemplate` is required
23
- */
24
- format: 'custom';
25
- /**
26
- * Custom template to override the default one ('LLL dd, yyyy').
27
- * @link https://date-fns.org/v2.29.3/docs/format
28
- */
29
- customTemplate: string;
30
- });
22
+ }
31
23
  /**
32
24
  * Format the date as nice string also specifying a custom timezone
33
25
  * @param opts a set of `FormatDateOptions`
34
26
  * @returns a nice string representation. Example: 'Jul 21, 2022' or 'Jul 21, 2022 · 1:16 PM' if includeTime
35
27
  */
36
28
  export declare function formatDate({ isoDate, timezone, ...opts }: FormatDateOptions): string;
37
- export declare function isCurrentYear(isoDate: string): boolean;
38
- export declare function isToday(isoDate: string): boolean;
29
+ export declare const timeSeparator = "\u00B7";
30
+ type DateISOString = string;
31
+ /**
32
+ * Calculate the time-zoned start or end of the day from an ISO date string.
33
+ * Useful when getting date from a date range picker.
34
+ * @param isoString a JavaScript ISO date string. Example '2022-10-06T11:59:30.371Z'
35
+ * @param edge 'startOfTheDay' or 'endOfTheDay'
36
+ * @param timezone Set a specific timezone, when not passed default value is 'UTC'
37
+ * @returns a JavaScript ISO date string that reflect the start or end of the day
38
+ * based on the user timezone. Example '2022-10-06T22:00:00.000Z' when timezone is 'Europe/Rome'
39
+ */
40
+ export declare function getIsoDateAtDayEdge({ isoString, edge, timezone }: {
41
+ isoString: DateISOString;
42
+ edge: 'startOfTheDay' | 'endOfTheDay';
43
+ timezone?: string;
44
+ }): string | undefined;
45
+ /**
46
+ * Subtract n days from an ISO date string
47
+ * to always return the correspondent time-zoned start of the day
48
+ *
49
+ * Example: if date-now is the 8th of March at 16:00 Italian time
50
+ * and I want to get the date at -7, the result will be
51
+ * '2022-03-01T23:00:00.000Z' as UTC string since my timezone is 'Europe/Rome'
52
+ * and on the 8th of March I was at +1 from UTC
53
+ *
54
+ * @param isoString JavaScript ISO date (eg: '2022-03-01T23:00:00.000Z')
55
+ * @param days positive number of days to subtract
56
+ * @param timezone (optional) in case of working with a specific timezone different from UTC
57
+ * @returns a new iso string
58
+ */
59
+ export declare function getIsoDateAtDaysBefore({ isoString, days, timezone }: {
60
+ isoString: DateISOString;
61
+ days: number;
62
+ timezone?: string;
63
+ }): string | undefined;
39
64
  export {};