@jirawatpyk/aura-react 4.4.2 → 4.5.1

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.
@@ -6,9 +6,8 @@ import { cx, uid, useMaybeControlled, useMounted, useIsoLayoutEffect, trapTab, u
6
6
  import { Icon } from "./Icon.js";
7
7
  import { IconButton } from "./IconButton.js";
8
8
  import { Field } from "./forms.js";
9
- const h = React.createElement;
10
- var ERA = /^พ\.ศ\.\s?|\s?(BE|พ\.ศ\.)$/g;
11
- var pad = function(n) {
9
+ const ERA = /^พ\.ศ\.\s?|\s?(BE|พ\.ศ\.)$/g;
10
+ const pad = function(n) {
12
11
  return (n < 10 ? "0" : "") + n;
13
12
  };
14
13
  function toISO(d) {
@@ -16,15 +15,15 @@ function toISO(d) {
16
15
  }
17
16
  function fromISO(s) {
18
17
  if (!s) return null;
19
- var m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
18
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
20
19
  return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null;
21
20
  }
22
21
  function addDays(d, n) {
23
22
  return new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
24
23
  }
25
24
  function addMonths(d, n) {
26
- var t = new Date(d.getFullYear(), d.getMonth() + n, 1);
27
- var last = new Date(t.getFullYear(), t.getMonth() + 1, 0).getDate();
25
+ const t = new Date(d.getFullYear(), d.getMonth() + n, 1);
26
+ const last = new Date(t.getFullYear(), t.getMonth() + 1, 0).getDate();
28
27
  return new Date(t.getFullYear(), t.getMonth(), Math.min(d.getDate(), last));
29
28
  }
30
29
  function same(a, b) {
@@ -33,39 +32,43 @@ function same(a, b) {
33
32
  function localeTag(locale, calendar) {
34
33
  return (locale === "en" ? "en-GB" : "th-TH") + "-u-ca-" + (calendar === "gregory" ? "gregory" : "buddhist");
35
34
  }
36
- var fmtCache = {};
37
- var PRESETS = { short: { day: "numeric", month: "short", year: "numeric" }, long: { day: "numeric", month: "long", year: "numeric" }, numeric: { day: "2-digit", month: "2-digit", year: "numeric" } };
35
+ const fmtCache = {};
36
+ const PRESETS = {
37
+ short: { day: "numeric", month: "short", year: "numeric" },
38
+ long: { day: "numeric", month: "long", year: "numeric" },
39
+ numeric: { day: "2-digit", month: "2-digit", year: "numeric" }
40
+ };
38
41
  function fmt(tag, opts, d) {
39
- var k = tag + JSON.stringify(opts);
42
+ const k = tag + JSON.stringify(opts);
40
43
  if (!fmtCache[k]) fmtCache[k] = new Intl.DateTimeFormat(tag, opts);
41
44
  return fmtCache[k].format(d);
42
45
  }
43
46
  function formatDate(iso, opts) {
44
- var o = opts || {}, d = fromISO(iso);
47
+ const o = opts || {}, d = fromISO(iso);
45
48
  if (!d) return "";
46
- var f = typeof o.format === "object" ? o.format : PRESETS[o.format || "short"];
49
+ const f = typeof o.format === "object" ? o.format : PRESETS[o.format || "short"];
47
50
  return fmt(localeTag(o.locale, o.calendar), f, d).replace(ERA, "");
48
51
  }
49
- var MONTHS = null;
52
+ let MONTHS = null;
50
53
  function monthIndex(word) {
51
54
  if (!MONTHS) {
52
55
  MONTHS = {};
53
56
  ["th-TH", "en-GB"].forEach(function(tag) {
54
57
  ["short", "long"].forEach(function(w) {
55
- for (var i = 0; i < 12; i++) {
56
- var n = new Intl.DateTimeFormat(tag, { month: w }).format(new Date(2020, i, 1)).toLowerCase().replace(/\.$/, "");
58
+ for (let i = 0; i < 12; i++) {
59
+ const n = new Intl.DateTimeFormat(tag, { month: w }).format(new Date(2020, i, 1)).toLowerCase().replace(/\.$/, "");
57
60
  MONTHS[n] = i;
58
61
  if (/^[a-z]/.test(n)) MONTHS[n.slice(0, 3)] = i;
59
62
  }
60
63
  });
61
64
  });
62
65
  }
63
- var k = word.toLowerCase().replace(/\.$/, "");
66
+ const k = word.toLowerCase().replace(/\.$/, "");
64
67
  return MONTHS[k] != null ? MONTHS[k] : -1;
65
68
  }
66
69
  function parseDate(text) {
67
- var s = String(text || "").trim();
68
- var m = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(s), y, mo, d;
70
+ const s = String(text || "").trim();
71
+ let m = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(s), y, mo, d;
69
72
  if (m) {
70
73
  y = +m[1];
71
74
  mo = +m[2];
@@ -80,50 +83,50 @@ function parseDate(text) {
80
83
  y = +m[3];
81
84
  } else return null;
82
85
  if (y >= 2400) y -= 543;
83
- var dt = new Date(y, mo - 1, d);
86
+ const dt = new Date(y, mo - 1, d);
84
87
  return dt.getMonth() === mo - 1 && dt.getDate() === d ? toISO(dt) : null;
85
88
  }
86
89
  const Calendar = React.forwardRef(function Calendar2(props, ref) {
87
- var ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar || "buddhist", tag = localeTag(locale, calendar);
88
- var weekStart = props.weekStartsOn == null ? 0 : props.weekStartsOn;
89
- var today = /* @__PURE__ */ new Date();
90
+ const ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar || "buddhist", tag = localeTag(locale, calendar);
91
+ const weekStart = props.weekStartsOn == null ? 0 : props.weekStartsOn;
92
+ let today = /* @__PURE__ */ new Date();
90
93
  today = new Date(today.getFullYear(), today.getMonth(), today.getDate());
91
- var min = fromISO(props.min), max = fromISO(props.max);
92
- var start = fromISO(props.start), end = fromISO(props.end);
93
- var focusState = React.useState(fromISO(props.focus) || start || today);
94
- var focusDate = focusState[0], setFocus = focusState[1];
95
- var viewState = React.useState("days"), view = viewState[0], setView = viewState[1];
96
- var hoverState = React.useState(null);
97
- var gridRef = React.useRef(null), gridMerged = useMergedRef(ref, gridRef), moved = React.useRef(false);
98
- var th = locale !== "en";
94
+ const min = fromISO(props.min), max = fromISO(props.max);
95
+ const start = fromISO(props.start), end = fromISO(props.end);
96
+ const focusState = React.useState(fromISO(props.focus) || start || today);
97
+ const focusDate = focusState[0], setFocus = focusState[1];
98
+ const viewState = React.useState("days"), view = viewState[0], setView = viewState[1];
99
+ const hoverState = React.useState(null);
100
+ const gridRef = React.useRef(null), gridMerged = useMergedRef(ref, gridRef), moved = React.useRef(false);
101
+ const th = locale !== "en";
99
102
  function disabled(d) {
100
- return min && d < min || max && d > max || props.isDateDisabled && props.isDateDisabled(toISO(d));
103
+ return !!(min && d < min || max && d > max || props.isDateDisabled && props.isDateDisabled(toISO(d)));
101
104
  }
102
105
  React.useEffect(function() {
103
106
  if (!moved.current) return;
104
107
  moved.current = false;
105
- var el = gridRef.current && gridRef.current.querySelector('[data-date="' + toISO(focusDate) + '"]');
108
+ const el = gridRef.current && gridRef.current.querySelector('[data-date="' + toISO(focusDate) + '"]');
106
109
  if (el) el.focus();
107
110
  });
108
111
  React.useEffect(function() {
109
112
  if (props.autoFocus === false) return;
110
- var el = gridRef.current && gridRef.current.querySelector('[tabindex="0"]');
113
+ const el = gridRef.current && gridRef.current.querySelector('[tabindex="0"]');
111
114
  if (el) el.focus();
112
115
  }, []);
113
116
  function move(d) {
114
117
  moved.current = true;
115
118
  setFocus(d);
116
119
  }
117
- var first = new Date(focusDate.getFullYear(), focusDate.getMonth(), 1);
118
- var lead = (first.getDay() - weekStart + 7) % 7;
119
- var gridStart = addDays(first, -lead);
120
- var days = [];
121
- for (var i = 0; i < 42; i++) days.push(addDays(gridStart, i));
122
- var weeks = [];
123
- for (var w = 0; w < 6; w++) weeks.push(days.slice(w * 7, w * 7 + 7));
120
+ const first = new Date(focusDate.getFullYear(), focusDate.getMonth(), 1);
121
+ const lead = (first.getDay() - weekStart + 7) % 7;
122
+ const gridStart = addDays(first, -lead);
123
+ const days = [];
124
+ for (let i = 0; i < 42; i++) days.push(addDays(gridStart, i));
125
+ const weeks = [];
126
+ for (let w = 0; w < 6; w++) weeks.push(days.slice(w * 7, w * 7 + 7));
124
127
  if (weeks[5][0].getMonth() !== focusDate.getMonth()) weeks.pop();
125
128
  function onKey(e, d) {
126
- var k = e.key, n = null;
129
+ let k = e.key, n = null;
127
130
  if (k === "ArrowLeft") n = addDays(d, -1);
128
131
  else if (k === "ArrowRight") n = addDays(d, 1);
129
132
  else if (k === "ArrowUp") n = addDays(d, -7);
@@ -142,104 +145,127 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
142
145
  move(n);
143
146
  }
144
147
  }
145
- var hover = hoverState[0];
146
- var rangeEnd = end || (props.range && start && hover ? hover : null);
148
+ const hover = hoverState[0];
149
+ const rangeEnd = end || (props.range && start && hover ? hover : null);
147
150
  function inRange(d) {
148
151
  if (!props.range || !start || !rangeEnd) return false;
149
- var a = start < rangeEnd ? start : rangeEnd, b = start < rangeEnd ? rangeEnd : start;
152
+ const a = start < rangeEnd ? start : rangeEnd, b = start < rangeEnd ? rangeEnd : start;
150
153
  return d > a && d < b;
151
154
  }
152
- var monthTitle = fmt(tag, { month: "long", year: "numeric" }, focusDate).replace(ERA, "");
153
- var weekdayNames = weeks[0].map(function(d) {
155
+ const monthTitle = fmt(tag, { month: "long", year: "numeric" }, focusDate).replace(ERA, "");
156
+ const weekdayNames = weeks[0].map(function(d) {
154
157
  return { short: fmt(tag, { weekday: th ? "narrow" : "short" }, d), long: fmt(tag, { weekday: "long" }, d) };
155
158
  });
156
159
  if (view === "years") {
157
- var yr = focusDate.getFullYear(), base = yr - yr % 12;
158
- var years = [];
159
- for (var y = base; y < base + 12; y++) years.push(y);
160
- return h(
161
- "div",
162
- { className: "aura-cal", ref: gridMerged },
163
- h(
164
- "div",
165
- { className: "aura-cal__head" },
166
- h(IconButton, { icon: "chevron-left", label: th ? "\u0E0A\u0E48\u0E27\u0E07\u0E1B\u0E35\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32" : "Previous years", onClick: function() {
160
+ const yr = focusDate.getFullYear(), base = yr - yr % 12;
161
+ const years = [];
162
+ for (let y = base; y < base + 12; y++) years.push(y);
163
+ return /* @__PURE__ */ React.createElement("div", { className: "aura-cal", ref: gridMerged }, /* @__PURE__ */ React.createElement("div", { className: "aura-cal__head" }, /* @__PURE__ */ React.createElement(
164
+ IconButton,
165
+ {
166
+ icon: "chevron-left",
167
+ label: th ? "\u0E0A\u0E48\u0E27\u0E07\u0E1B\u0E35\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32" : "Previous years",
168
+ onClick: function() {
167
169
  setFocus(new Date(yr - 12, focusDate.getMonth(), 1));
168
- } }),
169
- h(
170
- "button",
171
- { type: "button", className: "aura-cal__title", onClick: function() {
172
- setView("days");
173
- } },
174
- fmt(tag, { year: "numeric" }, new Date(base, 0, 1)).replace(ERA, "") + " \u2013 " + fmt(tag, { year: "numeric" }, new Date(base + 11, 0, 1)).replace(ERA, "")
175
- ),
176
- h(IconButton, { icon: "chevron-right", label: th ? "\u0E0A\u0E48\u0E27\u0E07\u0E1B\u0E35\u0E16\u0E31\u0E14\u0E44\u0E1B" : "Next years", onClick: function() {
170
+ }
171
+ }
172
+ ), /* @__PURE__ */ React.createElement(
173
+ "button",
174
+ {
175
+ type: "button",
176
+ className: "aura-cal__title",
177
+ onClick: function() {
178
+ setView("days");
179
+ }
180
+ },
181
+ fmt(tag, { year: "numeric" }, new Date(base, 0, 1)).replace(ERA, "") + " \u2013 " + fmt(tag, { year: "numeric" }, new Date(base + 11, 0, 1)).replace(ERA, "")
182
+ ), /* @__PURE__ */ React.createElement(
183
+ IconButton,
184
+ {
185
+ icon: "chevron-right",
186
+ label: th ? "\u0E0A\u0E48\u0E27\u0E07\u0E1B\u0E35\u0E16\u0E31\u0E14\u0E44\u0E1B" : "Next years",
187
+ onClick: function() {
177
188
  setFocus(new Date(yr + 12, focusDate.getMonth(), 1));
178
- } })
179
- ),
180
- h("div", { className: "aura-cal__years" }, years.map(function(y2) {
181
- var d = new Date(y2, focusDate.getMonth(), 1);
182
- return h(
183
- "button",
184
- {
185
- key: y2,
186
- type: "button",
187
- tabIndex: y2 === yr ? 0 : -1,
188
- className: cx("aura-cal__year", y2 === yr && "is-selected"),
189
- onClick: function() {
190
- setFocus(new Date(y2, focusDate.getMonth(), Math.min(focusDate.getDate(), 28)));
191
- setView("days");
192
- moved.current = true;
193
- }
194
- },
195
- fmt(tag, { year: "numeric" }, d).replace(ERA, "")
196
- );
197
- }))
198
- );
189
+ }
190
+ }
191
+ )), /* @__PURE__ */ React.createElement("div", { className: "aura-cal__years" }, years.map(function(y) {
192
+ const d = new Date(y, focusDate.getMonth(), 1);
193
+ return /* @__PURE__ */ React.createElement(
194
+ "button",
195
+ {
196
+ key: y,
197
+ type: "button",
198
+ tabIndex: y === yr ? 0 : -1,
199
+ className: cx("aura-cal__year", y === yr && "is-selected"),
200
+ onClick: function() {
201
+ setFocus(new Date(y, focusDate.getMonth(), Math.min(focusDate.getDate(), 28)));
202
+ setView("days");
203
+ moved.current = true;
204
+ }
205
+ },
206
+ fmt(tag, { year: "numeric" }, d).replace(ERA, "")
207
+ );
208
+ })));
199
209
  }
200
- return h(
201
- "div",
202
- { className: "aura-cal", ref: gridMerged },
203
- h(
204
- "div",
205
- { className: "aura-cal__head" },
206
- h(IconButton, { icon: "chevron-left", label: th ? "\u0E40\u0E14\u0E37\u0E2D\u0E19\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32" : "Previous month", onClick: function() {
210
+ return /* @__PURE__ */ React.createElement("div", { className: "aura-cal", ref: gridMerged }, /* @__PURE__ */ React.createElement("div", { className: "aura-cal__head" }, /* @__PURE__ */ React.createElement(
211
+ IconButton,
212
+ {
213
+ icon: "chevron-left",
214
+ label: th ? "\u0E40\u0E14\u0E37\u0E2D\u0E19\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32" : "Previous month",
215
+ onClick: function() {
207
216
  setFocus(addMonths(focusDate, -1));
208
- } }),
209
- h(
210
- "button",
211
- { type: "button", className: "aura-cal__title", "aria-live": "polite", onClick: function() {
212
- setView("years");
213
- } },
214
- monthTitle,
215
- h(Icon, { name: "chevron-down", size: 14 })
216
- ),
217
- h(IconButton, { icon: "chevron-right", label: th ? "\u0E40\u0E14\u0E37\u0E2D\u0E19\u0E16\u0E31\u0E14\u0E44\u0E1B" : "Next month", onClick: function() {
217
+ }
218
+ }
219
+ ), /* @__PURE__ */ React.createElement(
220
+ "button",
221
+ {
222
+ type: "button",
223
+ className: "aura-cal__title",
224
+ "aria-live": "polite",
225
+ onClick: function() {
226
+ setView("years");
227
+ }
228
+ },
229
+ monthTitle,
230
+ /* @__PURE__ */ React.createElement(Icon, { name: "chevron-down", size: 14 })
231
+ ), /* @__PURE__ */ React.createElement(
232
+ IconButton,
233
+ {
234
+ icon: "chevron-right",
235
+ label: th ? "\u0E40\u0E14\u0E37\u0E2D\u0E19\u0E16\u0E31\u0E14\u0E44\u0E1B" : "Next month",
236
+ onClick: function() {
218
237
  setFocus(addMonths(focusDate, 1));
219
- } })
220
- ),
221
- h(
222
- "table",
223
- { role: "grid", className: "aura-cal__grid", "aria-label": monthTitle },
224
- h("thead", null, h("tr", null, weekdayNames.map(function(n, i2) {
225
- return h("th", { key: i2, scope: "col", abbr: n.long }, h("span", { "aria-hidden": true }, n.short));
226
- }))),
227
- h("tbody", { onMouseLeave: function() {
238
+ }
239
+ }
240
+ )), /* @__PURE__ */ React.createElement("table", { role: "grid", className: "aura-cal__grid", "aria-label": monthTitle }, /* @__PURE__ */ React.createElement("thead", null, /* @__PURE__ */ React.createElement("tr", null, weekdayNames.map(function(n, i) {
241
+ return /* @__PURE__ */ React.createElement("th", { key: i, scope: "col", abbr: n.long }, /* @__PURE__ */ React.createElement("span", { "aria-hidden": true }, n.short));
242
+ }))), /* @__PURE__ */ React.createElement(
243
+ "tbody",
244
+ {
245
+ onMouseLeave: function() {
228
246
  hoverState[1](null);
229
- } }, weeks.map(function(wk, wi) {
230
- return h("tr", { key: wi }, wk.map(function(d) {
231
- var iso = toISO(d), out = d.getMonth() !== focusDate.getMonth(), dis = disabled(d);
232
- var isStart = same(d, start), isEnd = same(d, end) || !end && props.range && same(d, hover) && start;
233
- var sel = isStart || same(d, end);
234
- return h(
235
- "td",
247
+ }
248
+ },
249
+ weeks.map(function(wk, wi) {
250
+ return /* @__PURE__ */ React.createElement("tr", { key: wi }, wk.map(function(d) {
251
+ const iso = toISO(d), out = d.getMonth() !== focusDate.getMonth(), dis = disabled(d);
252
+ const isStart = same(d, start), isEnd = same(d, end) || !end && props.range && same(d, hover) && start;
253
+ const sel = isStart || same(d, end);
254
+ return /* @__PURE__ */ React.createElement(
255
+ "td",
256
+ {
257
+ key: iso,
258
+ role: "gridcell",
259
+ "aria-selected": sel || void 0,
260
+ className: cx(
261
+ inRange(d) && "is-in-range",
262
+ props.range && isStart && rangeEnd && "is-range-start",
263
+ props.range && isEnd && start && "is-range-end"
264
+ )
265
+ },
266
+ /* @__PURE__ */ React.createElement(
267
+ "button",
236
268
  {
237
- key: iso,
238
- role: "gridcell",
239
- "aria-selected": sel || void 0,
240
- className: cx(inRange(d) && "is-in-range", props.range && isStart && rangeEnd && "is-range-start", props.range && isEnd && start && "is-range-end")
241
- },
242
- h("button", {
243
269
  type: "button",
244
270
  "data-date": iso,
245
271
  tabIndex: same(d, focusDate) ? 0 : -1,
@@ -247,7 +273,12 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
247
273
  "aria-label": fmt(tag, { weekday: "long", day: "numeric", month: "long", year: "numeric" }, d),
248
274
  "aria-current": same(d, today) ? "date" : void 0,
249
275
  "aria-pressed": sel || void 0,
250
- className: cx("aura-cal__day", out && "is-outside", sel && "is-selected", same(d, today) && "is-today"),
276
+ className: cx(
277
+ "aura-cal__day",
278
+ out && "is-outside",
279
+ sel && "is-selected",
280
+ same(d, today) && "is-today"
281
+ ),
251
282
  onClick: function() {
252
283
  setFocus(d);
253
284
  props.onSelect(iso);
@@ -258,62 +289,80 @@ const Calendar = React.forwardRef(function Calendar2(props, ref) {
258
289
  onMouseEnter: function() {
259
290
  if (props.range) hoverState[1](d);
260
291
  }
261
- }, d.getDate())
262
- );
263
- }));
264
- }))
265
- ),
266
- props.footer === false ? null : h(
267
- "div",
268
- { className: "aura-cal__foot" },
269
- h("button", { type: "button", className: "aura-cal__link", disabled: disabled(today), onClick: function() {
292
+ },
293
+ d.getDate()
294
+ )
295
+ );
296
+ }));
297
+ })
298
+ )), props.footer === false ? null : /* @__PURE__ */ React.createElement("div", { className: "aura-cal__foot" }, /* @__PURE__ */ React.createElement(
299
+ "button",
300
+ {
301
+ type: "button",
302
+ className: "aura-cal__link",
303
+ disabled: disabled(today),
304
+ onClick: function() {
270
305
  move(today);
271
306
  props.onSelect(toISO(today));
272
- } }, th ? "\u0E27\u0E31\u0E19\u0E19\u0E35\u0E49" : "Today"),
273
- props.onClear ? h("button", { type: "button", className: "aura-cal__link", onClick: props.onClear }, th ? "\u0E25\u0E49\u0E32\u0E07" : "Clear") : null
274
- )
275
- );
307
+ }
308
+ },
309
+ th ? "\u0E27\u0E31\u0E19\u0E19\u0E35\u0E49" : "Today"
310
+ ), props.onClear ? /* @__PURE__ */ React.createElement("button", { type: "button", className: "aura-cal__link", onClick: props.onClear }, th ? "\u0E25\u0E49\u0E32\u0E07" : "Clear") : null));
276
311
  });
277
312
  function useCalendarPopover(boxRef) {
278
- var openState = React.useState(false), open = openState[0], setOpen = openState[1];
279
- var pos = React.useState(null), popRef = React.useRef(null), mounted = useMounted();
313
+ const openState = React.useState(false), open = openState[0], setOpen = openState[1];
314
+ const pos = React.useState(null), popRef = React.useRef(null), mounted = useMounted();
280
315
  function place() {
281
316
  if (!boxRef.current) return;
282
- var r = boxRef.current.getBoundingClientRect(), H = 380;
283
- var up = window.innerHeight - r.bottom < H && r.top > H;
284
- var left = Math.max(8, Math.min(r.left, window.innerWidth - 320 - 8));
317
+ const r = boxRef.current.getBoundingClientRect(), H = 380;
318
+ const up = window.innerHeight - r.bottom < H && r.top > H;
319
+ const left = Math.max(8, Math.min(r.left, window.innerWidth - 320 - 8));
285
320
  pos[1](up ? { left, bottom: window.innerHeight - r.top + 4 } : { left, top: r.bottom + 4 });
286
321
  }
287
- useIsoLayoutEffect(function() {
288
- if (open) place();
289
- }, [open]);
290
- React.useEffect(function() {
291
- if (!open) return;
292
- function outside(e) {
293
- if (boxRef.current && boxRef.current.contains(e.target)) return;
294
- if (popRef.current && popRef.current.contains(e.target)) return;
295
- setOpen(false);
296
- }
297
- document.addEventListener("pointerdown", outside, true);
298
- window.addEventListener("resize", place);
299
- window.addEventListener("scroll", place, true);
300
- return function() {
301
- document.removeEventListener("pointerdown", outside, true);
302
- window.removeEventListener("resize", place);
303
- window.removeEventListener("scroll", place, true);
304
- };
305
- }, [open]);
322
+ useIsoLayoutEffect(
323
+ function() {
324
+ if (open) place();
325
+ },
326
+ [open]
327
+ );
328
+ React.useEffect(
329
+ function() {
330
+ if (!open) return;
331
+ function outside(e) {
332
+ if (boxRef.current && boxRef.current.contains(e.target)) return;
333
+ if (popRef.current && popRef.current.contains(e.target)) return;
334
+ setOpen(false);
335
+ }
336
+ document.addEventListener("pointerdown", outside, true);
337
+ window.addEventListener("resize", place);
338
+ window.addEventListener("scroll", place, true);
339
+ return function() {
340
+ document.removeEventListener("pointerdown", outside, true);
341
+ window.removeEventListener("resize", place);
342
+ window.removeEventListener("scroll", place, true);
343
+ };
344
+ },
345
+ [open]
346
+ );
306
347
  return { open, setOpen, pos: pos[0], popRef, mounted };
307
348
  }
308
349
  function DateField(props) {
309
- var editState = React.useState(null), editing = editState[0], setEditing = editState[1];
310
- return h(
350
+ const editState = React.useState(null), editing = editState[0], setEditing = editState[1];
351
+ return /* @__PURE__ */ React.createElement(
311
352
  Field,
312
- { id: props.id, label: props.label, hint: props.hint, error: props.error, required: props.required, optional: props.optional, disabled: props.disabled, className: props.className },
313
- h(
314
- "div",
315
- { ref: props.boxRef, className: cx("aura-input aura-date", props.open && "is-open") },
316
- h("input", {
353
+ {
354
+ id: props.id,
355
+ label: props.label,
356
+ hint: props.hint,
357
+ error: props.error,
358
+ required: props.required,
359
+ optional: props.optional,
360
+ disabled: props.disabled,
361
+ className: props.className
362
+ },
363
+ /* @__PURE__ */ React.createElement("div", { ref: props.boxRef, className: cx("aura-input aura-date", props.open && "is-open") }, /* @__PURE__ */ React.createElement(
364
+ "input",
365
+ {
317
366
  ref: props.inputRef,
318
367
  id: props.id,
319
368
  type: "text",
@@ -349,9 +398,20 @@ function DateField(props) {
349
398
  props.onToggle(false);
350
399
  }
351
400
  }
352
- }),
353
- props.clearable !== false && props.hasValue && !props.disabled ? h("button", { type: "button", tabIndex: -1, className: "aura-combo__clear", "aria-label": props.clearLabel, onClick: props.onClear }, h(Icon, { name: "x" })) : null,
354
- h("button", {
401
+ }
402
+ ), props.clearable !== false && props.hasValue && !props.disabled ? /* @__PURE__ */ React.createElement(
403
+ "button",
404
+ {
405
+ type: "button",
406
+ tabIndex: -1,
407
+ className: "aura-combo__clear",
408
+ "aria-label": props.clearLabel,
409
+ onClick: props.onClear
410
+ },
411
+ /* @__PURE__ */ React.createElement(Icon, { name: "x" })
412
+ ) : null, /* @__PURE__ */ React.createElement(
413
+ "button",
414
+ {
355
415
  type: "button",
356
416
  className: "aura-date__toggle",
357
417
  disabled: props.disabled,
@@ -362,30 +422,35 @@ function DateField(props) {
362
422
  onClick: function() {
363
423
  props.onToggle(!props.open);
364
424
  }
365
- }, h(Icon, { name: "calendar" }))
366
- )
425
+ },
426
+ /* @__PURE__ */ React.createElement(Icon, { name: "calendar" })
427
+ ))
367
428
  );
368
429
  }
369
430
  const DatePicker = React.forwardRef(function DatePicker2(props, ref) {
370
- var auto = uid(), id = props.id || auto, dialogId = id + "-cal";
371
- var ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar || "buddhist", th = locale !== "en";
372
- var st = useMaybeControlled(props.value, props.defaultValue == null ? null : props.defaultValue, props.onChange);
373
- var boxRef = React.useRef(null), inputRef = React.useRef(null), inputMerged = useMergedRef(ref, inputRef);
374
- var pop = useCalendarPopover(boxRef);
431
+ const auto = uid(), id = props.id || auto, dialogId = id + "-cal";
432
+ const ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar || "buddhist", th = locale !== "en";
433
+ const st = useMaybeControlled(
434
+ props.value,
435
+ props.defaultValue == null ? null : props.defaultValue,
436
+ props.onChange
437
+ );
438
+ const boxRef = React.useRef(null), inputRef = React.useRef(null), inputMerged = useMergedRef(ref, inputRef);
439
+ const pop = useCalendarPopover(boxRef);
375
440
  function commit(text) {
376
441
  if (!text.trim()) {
377
442
  st[1](null);
378
443
  return;
379
444
  }
380
- var iso = parseDate(text);
445
+ const iso = parseDate(text);
381
446
  if (iso) st[1](iso);
382
447
  }
383
448
  function close() {
384
449
  pop.setOpen(false);
385
450
  if (inputRef.current) inputRef.current.focus();
386
451
  }
387
- var cal = pop.open && pop.mounted && pop.pos ? createPortal(
388
- h(
452
+ const cal = pop.open && pop.mounted && pop.pos ? createPortal(
453
+ /* @__PURE__ */ React.createElement(
389
454
  "div",
390
455
  {
391
456
  ref: pop.popRef,
@@ -402,27 +467,29 @@ const DatePicker = React.forwardRef(function DatePicker2(props, ref) {
402
467
  } else trapTab(e, pop.popRef.current);
403
468
  }
404
469
  },
405
- h(Calendar, {
406
- locale,
407
- calendar,
408
- weekStartsOn: props.weekStartsOn,
409
- min: props.min,
410
- max: props.max,
411
- isDateDisabled: props.isDateDisabled,
412
- start: st[0],
413
- focus: st[0],
414
- onSelect: function(iso) {
415
- st[1](iso);
416
- close();
470
+ /* @__PURE__ */ React.createElement(
471
+ Calendar,
472
+ {
473
+ locale,
474
+ calendar,
475
+ weekStartsOn: props.weekStartsOn,
476
+ min: props.min,
477
+ max: props.max,
478
+ isDateDisabled: props.isDateDisabled,
479
+ start: st[0],
480
+ focus: st[0],
481
+ onSelect: function(iso) {
482
+ st[1](iso);
483
+ close();
484
+ }
417
485
  }
418
- })
486
+ )
419
487
  ),
420
488
  document.body
421
489
  ) : null;
422
- return h(
423
- React.Fragment,
424
- null,
425
- h(DateField, {
490
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
491
+ DateField,
492
+ {
426
493
  id,
427
494
  dialogId,
428
495
  label: props.label,
@@ -451,119 +518,125 @@ const DatePicker = React.forwardRef(function DatePicker2(props, ref) {
451
518
  pop.setOpen(o);
452
519
  if (!o && inputRef.current) inputRef.current.focus();
453
520
  }
454
- }),
455
- cal
456
- );
521
+ }
522
+ ), cal);
457
523
  });
458
- const DateRangePicker = React.forwardRef(function DateRangePicker2(props, ref) {
459
- var auto = uid(), id = props.id || auto, dialogId = id + "-cal";
460
- var ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar || "buddhist", th = locale !== "en";
461
- var st = useMaybeControlled(props.value, props.defaultValue || { start: null, end: null }, props.onChange);
462
- var v = st[0] || { start: null, end: null };
463
- var draft = React.useState(null);
464
- var boxRef = React.useRef(null), inputRef = React.useRef(null), inputMerged = useMergedRef(ref, inputRef);
465
- var pop = useCalendarPopover(boxRef);
466
- var o = { locale, calendar };
467
- function show(r) {
468
- if (!r.start) return "";
469
- if (!r.end) return formatDate(r.start, o) + " \u2013";
470
- return formatDate(r.start, o) + " \u2013 " + formatDate(r.end, o);
471
- }
472
- function commit(text) {
473
- var parts = String(text).split(/\s[–-]\s|\s*–\s*/);
474
- if (!text.trim()) {
475
- st[1]({ start: null, end: null });
476
- return;
524
+ const DateRangePicker = React.forwardRef(
525
+ function DateRangePicker2(props, ref) {
526
+ const auto = uid(), id = props.id || auto, dialogId = id + "-cal";
527
+ const ctx = useAuraLocale(), locale = props.locale || ctx.locale || "th", calendar = props.calendar || ctx.calendar || "buddhist", th = locale !== "en";
528
+ const st = useMaybeControlled(
529
+ props.value,
530
+ props.defaultValue || { start: null, end: null },
531
+ props.onChange
532
+ );
533
+ const v = st[0] || { start: null, end: null };
534
+ const draft = React.useState(null);
535
+ const boxRef = React.useRef(null), inputRef = React.useRef(null), inputMerged = useMergedRef(ref, inputRef);
536
+ const pop = useCalendarPopover(boxRef);
537
+ const o = { locale, calendar };
538
+ function show(r) {
539
+ if (!r.start) return "";
540
+ if (!r.end) return formatDate(r.start, o) + " \u2013";
541
+ return formatDate(r.start, o) + " \u2013 " + formatDate(r.end, o);
477
542
  }
478
- var a = parseDate(parts[0]), b = parseDate(parts[1] || "");
479
- if (a && b) st[1](a <= b ? { start: a, end: b } : { start: b, end: a });
480
- }
481
- function close() {
482
- pop.setOpen(false);
483
- draft[1](null);
484
- if (inputRef.current) inputRef.current.focus();
485
- }
486
- function pick(iso) {
487
- if (!draft[0]) {
488
- draft[1](iso);
489
- return;
543
+ function commit(text) {
544
+ const parts = String(text).split(/\s[–-]\s|\s*–\s*/);
545
+ if (!text.trim()) {
546
+ st[1]({ start: null, end: null });
547
+ return;
548
+ }
549
+ const a = parseDate(parts[0]), b = parseDate(parts[1] || "");
550
+ if (a && b) st[1](a <= b ? { start: a, end: b } : { start: b, end: a });
490
551
  }
491
- var a = draft[0], b = iso;
492
- st[1](a <= b ? { start: a, end: b } : { start: b, end: a });
493
- close();
494
- }
495
- var cal = pop.open && pop.mounted && pop.pos ? createPortal(
496
- h(
497
- "div",
552
+ function close() {
553
+ pop.setOpen(false);
554
+ draft[1](null);
555
+ if (inputRef.current) inputRef.current.focus();
556
+ }
557
+ function pick(iso) {
558
+ if (!draft[0]) {
559
+ draft[1](iso);
560
+ return;
561
+ }
562
+ const a = draft[0], b = iso;
563
+ st[1](a <= b ? { start: a, end: b } : { start: b, end: a });
564
+ close();
565
+ }
566
+ const cal = pop.open && pop.mounted && pop.pos ? createPortal(
567
+ /* @__PURE__ */ React.createElement(
568
+ "div",
569
+ {
570
+ ref: pop.popRef,
571
+ id: dialogId,
572
+ role: "dialog",
573
+ "aria-modal": false,
574
+ "aria-label": props.label || (th ? "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E0A\u0E48\u0E27\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48" : "Choose dates"),
575
+ className: "aura-cal__popover",
576
+ style: pop.pos,
577
+ onKeyDown: function(e) {
578
+ if (e.key === "Escape") {
579
+ e.stopPropagation();
580
+ close();
581
+ } else trapTab(e, pop.popRef.current);
582
+ }
583
+ },
584
+ /* @__PURE__ */ React.createElement("p", { className: "aura-cal__hint", "aria-live": "polite" }, draft[0] ? th ? "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E2A\u0E34\u0E49\u0E19\u0E2A\u0E38\u0E14" : "Choose the end date" : th ? "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19" : "Choose the start date"),
585
+ /* @__PURE__ */ React.createElement(
586
+ Calendar,
587
+ {
588
+ range: true,
589
+ locale,
590
+ calendar,
591
+ weekStartsOn: props.weekStartsOn,
592
+ min: props.min,
593
+ max: props.max,
594
+ isDateDisabled: props.isDateDisabled,
595
+ start: draft[0] || v.start,
596
+ end: draft[0] ? null : v.end,
597
+ focus: draft[0] || v.start,
598
+ onSelect: pick
599
+ }
600
+ )
601
+ ),
602
+ document.body
603
+ ) : null;
604
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
605
+ DateField,
498
606
  {
499
- ref: pop.popRef,
500
- id: dialogId,
501
- role: "dialog",
502
- "aria-modal": false,
503
- "aria-label": props.label || (th ? "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E0A\u0E48\u0E27\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48" : "Choose dates"),
504
- className: "aura-cal__popover",
505
- style: pop.pos,
506
- onKeyDown: function(e) {
507
- if (e.key === "Escape") {
508
- e.stopPropagation();
509
- close();
510
- } else trapTab(e, pop.popRef.current);
607
+ id,
608
+ dialogId,
609
+ label: props.label,
610
+ hint: props.hint,
611
+ error: props.error,
612
+ required: props.required,
613
+ optional: props.optional,
614
+ disabled: props.disabled,
615
+ className: props.className,
616
+ name: props.name,
617
+ boxRef,
618
+ inputRef: inputMerged,
619
+ open: pop.open,
620
+ display: show(v),
621
+ placeholder: props.placeholder || (th ? "\u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B \u2013 \u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B" : "dd/mm/yyyy \u2013 dd/mm/yyyy"),
622
+ hasValue: v.start != null,
623
+ clearable: props.clearable,
624
+ onClear: function() {
625
+ st[1]({ start: null, end: null });
626
+ inputRef.current && inputRef.current.focus();
627
+ },
628
+ clearLabel: th ? "\u0E25\u0E49\u0E32\u0E07\u0E0A\u0E48\u0E27\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48" : "Clear dates",
629
+ toggleLabel: th ? "\u0E40\u0E1B\u0E34\u0E14\u0E1B\u0E0F\u0E34\u0E17\u0E34\u0E19" : "Open calendar",
630
+ onCommit: commit,
631
+ onToggle: function(op) {
632
+ pop.setOpen(op);
633
+ draft[1](null);
634
+ if (!op && inputRef.current) inputRef.current.focus();
511
635
  }
512
- },
513
- h("p", { className: "aura-cal__hint", "aria-live": "polite" }, draft[0] ? th ? "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E2A\u0E34\u0E49\u0E19\u0E2A\u0E38\u0E14" : "Choose the end date" : th ? "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19" : "Choose the start date"),
514
- h(Calendar, {
515
- range: true,
516
- locale,
517
- calendar,
518
- weekStartsOn: props.weekStartsOn,
519
- min: props.min,
520
- max: props.max,
521
- isDateDisabled: props.isDateDisabled,
522
- start: draft[0] || v.start,
523
- end: draft[0] ? null : v.end,
524
- focus: draft[0] || v.start,
525
- onSelect: pick
526
- })
527
- ),
528
- document.body
529
- ) : null;
530
- return h(
531
- React.Fragment,
532
- null,
533
- h(DateField, {
534
- id,
535
- dialogId,
536
- label: props.label,
537
- hint: props.hint,
538
- error: props.error,
539
- required: props.required,
540
- optional: props.optional,
541
- disabled: props.disabled,
542
- className: props.className,
543
- name: props.name,
544
- boxRef,
545
- inputRef: inputMerged,
546
- open: pop.open,
547
- display: show(v),
548
- placeholder: props.placeholder || (th ? "\u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B \u2013 \u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B" : "dd/mm/yyyy \u2013 dd/mm/yyyy"),
549
- hasValue: v.start != null,
550
- clearable: props.clearable,
551
- onClear: function() {
552
- st[1]({ start: null, end: null });
553
- inputRef.current && inputRef.current.focus();
554
- },
555
- clearLabel: th ? "\u0E25\u0E49\u0E32\u0E07\u0E0A\u0E48\u0E27\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48" : "Clear dates",
556
- toggleLabel: th ? "\u0E40\u0E1B\u0E34\u0E14\u0E1B\u0E0F\u0E34\u0E17\u0E34\u0E19" : "Open calendar",
557
- onCommit: commit,
558
- onToggle: function(op) {
559
- pop.setOpen(op);
560
- draft[1](null);
561
- if (!op && inputRef.current) inputRef.current.focus();
562
636
  }
563
- }),
564
- cal
565
- );
566
- });
637
+ ), cal);
638
+ }
639
+ );
567
640
  export {
568
641
  Calendar,
569
642
  DatePicker,