@webstudio-is/sdk-components-react 0.252.2 → 0.253.0

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.
@@ -214,9 +214,16 @@ const e = {
214
214
  options: ["full", "long", "medium", "short", "none"]
215
215
  },
216
216
  format: {
217
- description: `Custom format template string. When provided, overrides Date Style and Time Style.
218
- Supports tokens: YYYY, YY, MM, M, DD, D, HH, H, mm, m, ss, s.
219
- Example: "YYYY-MM-DD HH:mm:ss" displays as "2025-11-03 18:47:25"`,
217
+ description: `Custom format template. Overrides Date Style and Time Style.
218
+
219
+ Tokens: YYYY/YY (year), MMMM/MMM/MM/M (month), DDDD/DDD/DD/D (day), HH/H (hours), mm/m (minutes), ss/s (seconds)
220
+
221
+ Examples:
222
+ "YYYY-MM-DD" → 2025-11-03
223
+ "DDDD, MMMM D" → Monday, November 3
224
+ "DDD, D. MMM YYYY" → Mon, 3. Nov 2025
225
+
226
+ Day and month names use the selected language.`,
220
227
  required: !1,
221
228
  control: "text",
222
229
  type: "string"
package/lib/time.js CHANGED
@@ -1,5 +1,5 @@
1
- import { jsx as m } from "react/jsx-runtime";
2
- import { forwardRef as a } from "react";
1
+ import { jsx as S } from "react/jsx-runtime";
2
+ import { forwardRef as A } from "react";
3
3
  const N = [
4
4
  "af",
5
5
  "am",
@@ -72,7 +72,7 @@ const N = [
72
72
  "uz",
73
73
  "vi",
74
74
  "zh"
75
- ], E = [
75
+ ], g = [
76
76
  "AF",
77
77
  "AL",
78
78
  "DZ",
@@ -272,75 +272,84 @@ const N = [
272
272
  "YE",
273
273
  "ZM",
274
274
  "ZW"
275
- ], G = "dateTime attribute is not set", L = "", M = "en", u = "GB", f = "medium", Y = "none", g = (t) => N.includes(t) ? t : M, I = (t) => E.includes(t) ? t : u, B = (t) => {
275
+ ], f = "dateTime attribute is not set", E = "", c = "en", u = "GB", G = "medium", I = "none", L = (t) => N.includes(t) ? t : c, h = (t) => g.includes(t) ? t : u, B = (t) => {
276
276
  if (["full", "long", "medium", "short"].includes(t))
277
277
  return t;
278
278
  }, R = (t) => {
279
279
  if (["full", "long", "medium", "short"].includes(t))
280
280
  return t;
281
- }, C = (t) => {
281
+ }, U = (t) => {
282
282
  if (t === "")
283
283
  return;
284
- let n = new Date(t);
285
- if (Number.isNaN(n.getTime()) === !1)
286
- return n;
284
+ let e = new Date(t);
285
+ if (Number.isNaN(e.getTime()) === !1)
286
+ return e;
287
287
  if (/^\d+$/.test(t)) {
288
- let e = Number(t);
289
- t.length === 10 && (e *= 1e3), n = new Date(e);
288
+ let n = Number(t);
289
+ t.length === 10 && (n *= 1e3), e = new Date(n);
290
290
  }
291
- if (Number.isNaN(n.getTime()) === !1)
292
- return n;
293
- }, U = (t, n) => {
294
- const e = (s, r = 2) => String(s).padStart(r, "0"), o = {
291
+ if (Number.isNaN(e.getTime()) === !1)
292
+ return e;
293
+ }, Y = (t, e, n = "en-US") => {
294
+ const r = (o, s = 2) => String(o).padStart(s, "0"), D = new Intl.DateTimeFormat(n, {
295
+ weekday: "long"
296
+ }).format(t), T = new Intl.DateTimeFormat(n, {
297
+ weekday: "short"
298
+ }).format(t), l = new Intl.DateTimeFormat(n, {
299
+ month: "long"
300
+ }).format(t), M = new Intl.DateTimeFormat(n, {
301
+ month: "short"
302
+ }).format(t), m = {
295
303
  YYYY: t.getFullYear(),
296
304
  YY: String(t.getFullYear()).slice(-2),
297
- MM: e(t.getMonth() + 1),
305
+ MMMM: l,
306
+ MMM: M,
307
+ MM: r(t.getMonth() + 1),
298
308
  M: t.getMonth() + 1,
299
- DD: e(t.getDate()),
309
+ DDDD: D,
310
+ DDD: T,
311
+ DD: r(t.getDate()),
300
312
  D: t.getDate(),
301
- HH: e(t.getHours()),
313
+ HH: r(t.getHours()),
302
314
  H: t.getHours(),
303
- mm: e(t.getMinutes()),
315
+ mm: r(t.getMinutes()),
304
316
  m: t.getMinutes(),
305
- ss: e(t.getSeconds()),
317
+ ss: r(t.getSeconds()),
306
318
  s: t.getSeconds()
307
- };
308
- return n.replace(
309
- /\b(YYYY|YY|MM|M|DD|D|HH|H|mm|m|ss|s)\b/g,
310
- (s) => String(o[s])
311
- );
312
- }, h = a(
319
+ }, a = Object.keys(m).sort((o, s) => s.length - o.length), i = new RegExp(`\\b(${a.join("|")})\\b`, "g");
320
+ return e.replace(i, (o) => String(m[o]));
321
+ }, H = A(
313
322
  ({
314
- language: t = M,
315
- country: n = u,
316
- dateStyle: e = f,
317
- timeStyle: o = Y,
318
- format: s,
323
+ language: t = c,
324
+ country: e = u,
325
+ dateStyle: n = G,
326
+ timeStyle: r = I,
327
+ format: D,
319
328
  // native html attribute in react style
320
- dateTime: r = G,
321
- ...c
322
- }, S) => {
323
- const A = `${g(t)}-${I(
324
- n
325
- )}`, D = {
326
- dateStyle: B(e),
327
- timeStyle: R(o)
328
- }, i = r === null ? L : r.toString(), l = C(i);
329
- let T = i;
330
- if (l)
331
- if (s)
329
+ dateTime: T = f,
330
+ ...l
331
+ }, M) => {
332
+ const m = `${L(t)}-${h(
333
+ e
334
+ )}`, a = {
335
+ dateStyle: B(n),
336
+ timeStyle: R(r)
337
+ }, i = T === null ? E : T.toString(), o = U(i);
338
+ let s = i;
339
+ if (o)
340
+ if (D)
332
341
  try {
333
- T = U(l, s);
342
+ s = Y(o, D, m);
334
343
  } catch {
335
344
  }
336
345
  else
337
346
  try {
338
- T = new Intl.DateTimeFormat(A, D).format(l);
347
+ s = new Intl.DateTimeFormat(m, a).format(o);
339
348
  } catch {
340
349
  }
341
- return /* @__PURE__ */ m("time", { ref: S, dateTime: i, ...c, children: T });
350
+ return /* @__PURE__ */ S("time", { ref: M, dateTime: i, ...l, children: s });
342
351
  }
343
352
  );
344
353
  export {
345
- h as Time
354
+ H as Time
346
355
  };
@@ -10,14 +10,21 @@ export declare const Time: import("react").ForwardRefExoticComponent<Pick<import
10
10
  dateStyle?: DateStyle;
11
11
  timeStyle?: TimeStyle;
12
12
  /**
13
- * Custom format template string. When provided, overrides Date Style and Time Style.
14
- * Supports tokens: YYYY, YY, MM, M, DD, D, HH, H, mm, m, ss, s.
15
- * Example: "YYYY-MM-DD HH:mm:ss" displays as "2025-11-03 18:47:25"
13
+ * Custom format template. Overrides Date Style and Time Style.
14
+ *
15
+ * Tokens: YYYY/YY (year), MMMM/MMM/MM/M (month), DDDD/DDD/DD/D (day), HH/H (hours), mm/m (minutes), ss/s (seconds)
16
+ *
17
+ * Examples:
18
+ * - "YYYY-MM-DD" → 2025-11-03
19
+ * - "DDDD, MMMM D" → Monday, November 3
20
+ * - "DDD, D. MMM YYYY" → Mon, 3. Nov 2025
21
+ *
22
+ * Day and month names use the selected language.
16
23
  */
17
24
  format?: string;
18
25
  } & import("react").RefAttributes<HTMLTimeElement>>;
19
26
  export declare const __testing__: {
20
27
  parseDate: (datetimeString: string) => Date | undefined;
21
- formatDate: (date: Date, template: string) => string;
28
+ formatDate: (date: Date, template: string, locale?: string) => string;
22
29
  };
23
30
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/sdk-components-react",
3
- "version": "0.252.2",
3
+ "version": "0.253.0",
4
4
  "description": "Webstudio default library for react",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -44,10 +44,10 @@
44
44
  "colord": "^2.9.3",
45
45
  "micromark": "^4.0.2",
46
46
  "micromark-extension-gfm-table": "^2.1.1",
47
- "@webstudio-is/icons": "0.252.2",
48
- "@webstudio-is/image": "0.252.2",
49
- "@webstudio-is/sdk": "0.252.2",
50
- "@webstudio-is/react-sdk": "0.252.2"
47
+ "@webstudio-is/icons": "0.253.0",
48
+ "@webstudio-is/react-sdk": "0.253.0",
49
+ "@webstudio-is/image": "0.253.0",
50
+ "@webstudio-is/sdk": "0.253.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@testing-library/dom": "^10.4.0",
@@ -60,8 +60,8 @@
60
60
  "vitest": "^3.1.2",
61
61
  "@webstudio-is/generate-arg-types": "0.0.0",
62
62
  "@webstudio-is/sdk-cli": "0.94.0",
63
- "@webstudio-is/template": "0.252.2",
64
- "@webstudio-is/tsconfig": "1.0.7"
63
+ "@webstudio-is/tsconfig": "1.0.7",
64
+ "@webstudio-is/template": "0.253.0"
65
65
  },
66
66
  "scripts": {
67
67
  "build": "vite build --config ../../vite.sdk-components.config.ts",