@jirawatpyk/aura-react 4.16.0 → 4.18.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.
@@ -15,7 +15,12 @@ function Command(props) {
15
15
  const id = uid(), listId = id + "-list";
16
16
  const box = React.useRef(null);
17
17
  const input = React.useRef(null);
18
- const q = React.useState(""), act = React.useState(0);
18
+ const qState = React.useState(""), act = React.useState(null);
19
+ const query = props.query !== void 0 ? props.query : qState[0];
20
+ function setQuery(v) {
21
+ if (props.query === void 0) qState[1](v);
22
+ if (props.onQueryChange) props.onQueryChange(v);
23
+ }
19
24
  const openRef = React.useRef(props.open);
20
25
  openRef.current = props.open;
21
26
  const close = function() {
@@ -41,15 +46,15 @@ function Command(props) {
41
46
  React.useEffect(
42
47
  function() {
43
48
  if (!props.open) {
44
- q[1]("");
45
- act[1](0);
49
+ if (query) setQuery("");
50
+ act[1](null);
46
51
  }
47
52
  },
48
53
  [props.open]
49
54
  );
50
- const filter = props.filter || defaultFilter;
55
+ const filter = props.filter === false ? null : props.filter || defaultFilter;
51
56
  const shown = (props.items || []).filter(function(it) {
52
- return filter(it, q[0]);
57
+ return !filter || filter(it, query);
53
58
  });
54
59
  const groups = [];
55
60
  shown.forEach(function(it) {
@@ -71,7 +76,10 @@ function Command(props) {
71
76
  }).filter(function(i2) {
72
77
  return i2 >= 0;
73
78
  });
74
- const active = enabled.indexOf(act[0]) >= 0 ? act[0] : enabled.length ? enabled[0] : -1;
79
+ const byId = act[0] == null ? -1 : flat.findIndex(function(it) {
80
+ return it.id === act[0];
81
+ });
82
+ const active = enabled.indexOf(byId) >= 0 ? byId : enabled.length ? enabled[0] : -1;
75
83
  const optId = function(i2) {
76
84
  return id + "-o" + i2;
77
85
  };
@@ -96,7 +104,7 @@ function Command(props) {
96
104
  if (dir === "first") n = 0;
97
105
  else if (dir === "last") n = enabled.length - 1;
98
106
  else n = (at + dir + enabled.length) % enabled.length;
99
- act[1](enabled[n]);
107
+ act[1](flat[enabled[n]].id);
100
108
  }
101
109
  function onKey(e) {
102
110
  if (e.key === "ArrowDown") {
@@ -147,63 +155,77 @@ function Command(props) {
147
155
  "data-autofocus": "",
148
156
  type: "text",
149
157
  role: "combobox",
150
- "aria-expanded": true,
151
- "aria-controls": listId,
158
+ "aria-expanded": flat.length > 0,
159
+ "aria-controls": flat.length ? listId : void 0,
152
160
  "aria-autocomplete": "list",
153
161
  "aria-activedescendant": active >= 0 ? optId(active) : void 0,
154
162
  "aria-label": props.label || t.commandMenu,
155
163
  placeholder: props.placeholder || t.commandPlaceholder,
156
164
  className: "aura-command__input",
157
- value: q[0],
165
+ value: query,
158
166
  autoComplete: "off",
159
167
  spellCheck: false,
160
168
  onChange: function(e) {
161
- q[1](e.target.value);
162
- act[1](0);
169
+ setQuery(e.target.value);
170
+ act[1](null);
163
171
  },
164
172
  onKeyDown: onKey
165
173
  }
166
174
  ), /* @__PURE__ */ React.createElement("kbd", { className: "aura-command__kbd" }, "Esc")),
167
- /* @__PURE__ */ React.createElement("div", { className: "aura-command__list", id: listId, role: "listbox", "aria-label": props.label || t.commandMenu }, !flat.length ? /* @__PURE__ */ React.createElement("p", { className: "aura-command__empty", role: "presentation" }, props.emptyText || t.noMatches) : groups.map(function(g, gi) {
168
- const gid = id + "-g" + gi;
169
- return /* @__PURE__ */ React.createElement(
170
- "div",
171
- {
172
- key: g.name || gi,
173
- role: "group",
174
- "aria-labelledby": g.name ? gid : void 0,
175
- className: "aura-command__group"
176
- },
177
- g.name ? /* @__PURE__ */ React.createElement("div", { className: "aura-command__heading", id: gid, role: "presentation" }, g.name) : null,
178
- g.items.map(function(it) {
179
- i++;
180
- const n = i;
181
- return /* @__PURE__ */ React.createElement(
182
- "div",
183
- {
184
- key: it.id,
185
- id: optId(n),
186
- role: "option",
187
- "aria-selected": n === active,
188
- "aria-disabled": it.disabled || void 0,
189
- className: cx("aura-command__item", n === active && "is-active", it.disabled && "is-disabled"),
190
- onPointerDown: function(e) {
191
- e.preventDefault();
192
- },
193
- onPointerMove: function() {
194
- if (!it.disabled && act[0] !== n) act[1](n);
175
+ /* @__PURE__ */ React.createElement("div", { className: "aura-command__list", "aria-busy": props.loading || void 0 }, props.loading ? /* @__PURE__ */ React.createElement("div", { className: "aura-command__loading" }, /* @__PURE__ */ React.createElement(Icon, { name: "loader-circle", className: "aura-spin" }), t.searching) : null, !flat.length ? props.loading ? null : /* @__PURE__ */ React.createElement("div", { className: "aura-command__empty" }, props.empty != null ? props.empty : props.emptyText || t.noMatches) : /* @__PURE__ */ React.createElement(
176
+ "div",
177
+ {
178
+ id: listId,
179
+ role: "listbox",
180
+ "aria-label": props.label || t.commandMenu,
181
+ "aria-busy": props.loading || void 0
182
+ },
183
+ groups.map(function(g, gi) {
184
+ const gid = id + "-g" + gi;
185
+ return /* @__PURE__ */ React.createElement(
186
+ "div",
187
+ {
188
+ key: g.name || gi,
189
+ role: "group",
190
+ "aria-labelledby": g.name ? gid : void 0,
191
+ className: "aura-command__group"
192
+ },
193
+ g.name ? /* @__PURE__ */ React.createElement("div", { className: "aura-command__heading", id: gid, role: "presentation" }, g.name) : null,
194
+ g.items.map(function(it) {
195
+ i++;
196
+ const n = i;
197
+ return /* @__PURE__ */ React.createElement(
198
+ "div",
199
+ {
200
+ key: it.id,
201
+ id: optId(n),
202
+ role: "option",
203
+ "aria-selected": n === active,
204
+ "aria-disabled": it.disabled || void 0,
205
+ className: cx(
206
+ "aura-command__item",
207
+ n === active && "is-active",
208
+ it.disabled && "is-disabled"
209
+ ),
210
+ onPointerDown: function(e) {
211
+ e.preventDefault();
212
+ },
213
+ onPointerMove: function() {
214
+ if (!it.disabled && act[0] !== it.id) act[1](it.id);
215
+ },
216
+ onClick: function() {
217
+ run(it);
218
+ }
195
219
  },
196
- onClick: function() {
197
- run(it);
198
- }
199
- },
200
- it.icon ? /* @__PURE__ */ React.createElement(Icon, { name: it.icon }) : null,
201
- /* @__PURE__ */ React.createElement("span", { className: "aura-command__text" }, /* @__PURE__ */ React.createElement("span", { className: "aura-command__label" }, it.label), it.description ? /* @__PURE__ */ React.createElement("span", { className: "aura-command__desc" }, it.description) : null),
202
- it.shortcut ? /* @__PURE__ */ React.createElement("kbd", { className: "aura-command__kbd" }, it.shortcut) : null
203
- );
204
- })
205
- );
206
- })),
220
+ it.icon ? /* @__PURE__ */ React.createElement(Icon, { name: it.icon }) : null,
221
+ /* @__PURE__ */ React.createElement("span", { className: "aura-command__text" }, /* @__PURE__ */ React.createElement("span", { className: "aura-command__label" }, it.label), it.description ? /* @__PURE__ */ React.createElement("span", { className: "aura-command__desc" }, it.description) : null),
222
+ it.shortcut ? /* @__PURE__ */ React.createElement("kbd", { className: "aura-command__kbd" }, it.shortcut) : null
223
+ );
224
+ })
225
+ );
226
+ })
227
+ )),
228
+ /* @__PURE__ */ React.createElement("span", { className: "aura-sr-only", role: "status" }, props.loading ? t.searching : query && !flat.length ? t.noMatches : props.loading === false && query ? t.results(flat.length) : ""),
207
229
  /* @__PURE__ */ React.createElement("div", { className: "aura-command__foot", "aria-hidden": true }, t.commandHint, /* @__PURE__ */ React.createElement("span", { className: "aura-command__mod" }, isMac() ? "\u2318K" : "Ctrl K"))
208
230
  )
209
231
  ),
@@ -34,11 +34,20 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
34
34
  const selectable = !!props.selectable;
35
35
  const reorderable = props.reorderable !== false && !!props.columnControls;
36
36
  const controls = !!props.columnControls;
37
- const sortState = useMaybeControlled(props.sort, props.defaultSort || null, props.onSortChange);
37
+ const oneCallback = !!props.onStateChange;
38
+ const sortState = useMaybeControlled(
39
+ props.sort,
40
+ props.defaultSort || null,
41
+ oneCallback ? null : props.onSortChange
42
+ );
38
43
  const sort = sortState[0], setSort = sortState[1];
39
44
  const selState = useMaybeControlled(props.selected, props.defaultSelected || [], props.onSelectionChange);
40
45
  const selected = selState[0], setSelected = selState[1];
41
- const pageState = useMaybeControlled(props.page, props.defaultPage || 1, props.onPageChange);
46
+ const pageState = useMaybeControlled(
47
+ props.page,
48
+ props.defaultPage || 1,
49
+ oneCallback ? null : props.onPageChange
50
+ );
42
51
  const orderState = useMaybeControlled(
43
52
  props.columnOrder,
44
53
  columns.map(function(c) {
@@ -208,11 +217,15 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
208
217
  const pageRows = pageSize && !manual ? view.slice(first, first + pageSize) : view;
209
218
  const canSortAny = !busy && (manual ? total > 1 : rows.length > 1);
210
219
  const shownTotal = manual && props.totalRows == null ? first + rows.length : total;
211
- const linkPaging = !!props.getPageHref && !props.onPageChange;
220
+ const linkPaging = !!props.getPageHref && !props.onPageChange && !oneCallback;
212
221
  const prevLink = React.useRef(null), nextLink = React.useRef(null);
213
- function goPage(p, focus) {
222
+ function emit(s, p) {
223
+ if (props.onStateChange) props.onStateChange({ sort: s, page: p });
224
+ }
225
+ function goPage(p, focus, quiet) {
214
226
  const next = Math.min(Math.max(1, p), pageCount);
215
227
  if (next === page) return false;
228
+ if (!quiet) emit(sort, next);
216
229
  if (linkPaging) {
217
230
  const a = next === page - 1 ? prevLink.current : next === page + 1 ? nextLink.current : null;
218
231
  if (a) a.click();
@@ -224,8 +237,12 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
224
237
  return true;
225
238
  }
226
239
  function sortBy(key) {
227
- setSort(nextSort(key));
228
- if (!(manual && linkPaging)) goPage(1);
240
+ applySort(nextSort(key));
241
+ }
242
+ function applySort(s) {
243
+ setSort(s);
244
+ if (!(manual && linkPaging)) goPage(1, void 0, true);
245
+ emit(s, 1);
229
246
  }
230
247
  const rowHref = props.getRowHref;
231
248
  function followRow(el, e) {
@@ -440,16 +457,14 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
440
457
  label: t.sortAsc,
441
458
  icon: "arrow-up",
442
459
  onSelect: function() {
443
- setSort({ key: c.key, dir: "asc" });
444
- goPage(1);
460
+ applySort({ key: c.key, dir: "asc" });
445
461
  }
446
462
  },
447
463
  {
448
464
  label: t.sortDesc,
449
465
  icon: "arrow-down",
450
466
  onSelect: function() {
451
- setSort({ key: c.key, dir: "desc" });
452
- goPage(1);
467
+ applySort({ key: c.key, dir: "desc" });
453
468
  }
454
469
  },
455
470
  { separator: true }
@@ -886,9 +901,10 @@ const DataTable = React.forwardRef(function DataTable2(props, ref) {
886
901
  className: "aura-icon-btn",
887
902
  "aria-label": label,
888
903
  onClick: function(e) {
889
- if (props.onPageChange) {
904
+ if (props.onPageChange || oneCallback) {
890
905
  e.preventDefault();
891
906
  pageState[1](p);
907
+ emit(sort, p);
892
908
  }
893
909
  }
894
910
  },
@@ -6,111 +6,21 @@ 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 "./Field.js";
9
- const ERA = /^พ\.ศ\.\s?|\s?(BE|พ\.ศ\.)$/g;
10
- const pad = function(n) {
11
- return (n < 10 ? "0" : "") + n;
12
- };
13
- function toISO(d) {
14
- return d ? d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate()) : null;
15
- }
16
- function fromISO(s) {
17
- if (!s) return null;
18
- const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(s);
19
- return m ? new Date(+m[1], +m[2] - 1, +m[3]) : null;
20
- }
21
- function addDays(d, n) {
22
- return new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
23
- }
24
- function addMonths(d, n) {
25
- const t = new Date(d.getFullYear(), d.getMonth() + n, 1);
26
- const last = new Date(t.getFullYear(), t.getMonth() + 1, 0).getDate();
27
- return new Date(t.getFullYear(), t.getMonth(), Math.min(d.getDate(), last));
28
- }
29
- function same(a, b) {
30
- return !!a && !!b && a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
31
- }
32
- const TAGS = { th: "th-TH", en: "en-GB", sv: "sv-SE" };
33
- function defaultCalendar(locale) {
34
- return locale === "th" ? "buddhist" : "gregory";
35
- }
36
- function localeTag(locale, calendar) {
37
- const cal = calendar || defaultCalendar(locale);
38
- return (TAGS[locale || "en"] || "en-GB") + "-u-ca-" + (cal === "gregory" ? "gregory" : "buddhist");
39
- }
40
- const DATE_TEXT = {
41
- th: {
42
- prevYears: "\u0E0A\u0E48\u0E27\u0E07\u0E1B\u0E35\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32",
43
- nextYears: "\u0E0A\u0E48\u0E27\u0E07\u0E1B\u0E35\u0E16\u0E31\u0E14\u0E44\u0E1B",
44
- prevMonth: "\u0E40\u0E14\u0E37\u0E2D\u0E19\u0E01\u0E48\u0E2D\u0E19\u0E2B\u0E19\u0E49\u0E32",
45
- nextMonth: "\u0E40\u0E14\u0E37\u0E2D\u0E19\u0E16\u0E31\u0E14\u0E44\u0E1B",
46
- today: "\u0E27\u0E31\u0E19\u0E19\u0E35\u0E49",
47
- clear: "\u0E25\u0E49\u0E32\u0E07",
48
- chooseDate: "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48",
49
- datePlaceholder: "\u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B",
50
- clearDate: "\u0E25\u0E49\u0E32\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48",
51
- openCalendar: "\u0E40\u0E1B\u0E34\u0E14\u0E1B\u0E0F\u0E34\u0E17\u0E34\u0E19",
52
- chooseDates: "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E0A\u0E48\u0E27\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48",
53
- rangePlaceholder: "\u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B \u2013 \u0E27\u0E27/\u0E14\u0E14/\u0E1B\u0E1B\u0E1B\u0E1B",
54
- clearDates: "\u0E25\u0E49\u0E32\u0E07\u0E0A\u0E48\u0E27\u0E07\u0E27\u0E31\u0E19\u0E17\u0E35\u0E48",
55
- chooseStart: "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E40\u0E23\u0E34\u0E48\u0E21\u0E15\u0E49\u0E19",
56
- chooseEnd: "\u0E40\u0E25\u0E37\u0E2D\u0E01\u0E27\u0E31\u0E19\u0E2A\u0E34\u0E49\u0E19\u0E2A\u0E38\u0E14"
57
- },
58
- en: {
59
- prevYears: "Previous years",
60
- nextYears: "Next years",
61
- prevMonth: "Previous month",
62
- nextMonth: "Next month",
63
- today: "Today",
64
- clear: "Clear",
65
- chooseDate: "Choose date",
66
- datePlaceholder: "DD/MM/YYYY",
67
- clearDate: "Clear date",
68
- openCalendar: "Open calendar",
69
- chooseDates: "Choose dates",
70
- rangePlaceholder: "DD/MM/YYYY \u2013 DD/MM/YYYY",
71
- clearDates: "Clear dates",
72
- chooseStart: "Choose the start date",
73
- chooseEnd: "Choose the end date"
74
- },
75
- sv: {
76
- prevYears: "Tidigare \xE5r",
77
- nextYears: "Senare \xE5r",
78
- prevMonth: "F\xF6reg\xE5ende m\xE5nad",
79
- nextMonth: "N\xE4sta m\xE5nad",
80
- today: "Idag",
81
- clear: "Rensa",
82
- chooseDate: "V\xE4lj datum",
83
- datePlaceholder: "\xE5\xE5\xE5\xE5-mm-dd",
84
- clearDate: "Rensa datum",
85
- openCalendar: "\xD6ppna kalendern",
86
- chooseDates: "V\xE4lj datum",
87
- rangePlaceholder: "\xE5\xE5\xE5\xE5-mm-dd \u2013 \xE5\xE5\xE5\xE5-mm-dd",
88
- clearDates: "Rensa datumen",
89
- chooseStart: "V\xE4lj startdatum",
90
- chooseEnd: "V\xE4lj slutdatum"
91
- }
92
- };
93
- function dateText(locale) {
94
- return DATE_TEXT[locale || "en"] || DATE_TEXT.en;
95
- }
96
- const fmtCache = {};
97
- const PRESETS = {
98
- short: { day: "numeric", month: "short", year: "numeric" },
99
- long: { day: "numeric", month: "long", year: "numeric" },
100
- numeric: { day: "2-digit", month: "2-digit", year: "numeric" }
101
- };
102
- function fmt(tag, opts, d) {
103
- const k = tag + JSON.stringify(opts);
104
- if (!fmtCache[k]) fmtCache[k] = new Intl.DateTimeFormat(tag, opts);
105
- return fmtCache[k].format(d);
106
- }
107
- function formatDate(iso, opts) {
108
- const o = opts || {}, d = fromISO(iso);
109
- if (!d) return "";
110
- const f = typeof o.format === "object" ? o.format : PRESETS[o.format || "short"];
111
- const loc = o.locale || "th";
112
- return fmt(localeTag(loc, o.calendar || defaultCalendar(loc)), f, d).replace(ERA, "");
113
- }
9
+ import {
10
+ ERA,
11
+ addDays,
12
+ addMonths,
13
+ dateText,
14
+ defaultCalendar,
15
+ fmt,
16
+ formatDate,
17
+ fromISO,
18
+ localeTag,
19
+ parseDate,
20
+ same,
21
+ toISO
22
+ } from "./dates.js";
23
+ import { formatDate as formatDate2, parseDate as parseDate2 } from "./dates.js";
114
24
  function useFormatDate() {
115
25
  const ctx = useAuraLocale(), locale = ctx.locale || "en", calendar = ctx.calendar;
116
26
  return React.useCallback(
@@ -127,43 +37,6 @@ function useFormatDate() {
127
37
  [locale, calendar]
128
38
  );
129
39
  }
130
- let MONTHS = null;
131
- function monthIndex(word) {
132
- if (!MONTHS) {
133
- MONTHS = {};
134
- ["th-TH", "en-GB", "sv-SE"].forEach(function(tag) {
135
- ["short", "long"].forEach(function(w) {
136
- for (let i = 0; i < 12; i++) {
137
- const n = new Intl.DateTimeFormat(tag, { month: w }).format(new Date(2020, i, 1)).toLowerCase().replace(/\.$/, "");
138
- MONTHS[n] = i;
139
- if (/^[a-zåäö]/.test(n)) MONTHS[n.slice(0, 3)] = i;
140
- }
141
- });
142
- });
143
- }
144
- const k = word.toLowerCase().replace(/\.$/, "");
145
- return MONTHS[k] != null ? MONTHS[k] : -1;
146
- }
147
- function parseDate(text) {
148
- const s = String(text || "").trim();
149
- let m = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(s), y, mo, d;
150
- if (m) {
151
- y = +m[1];
152
- mo = +m[2];
153
- d = +m[3];
154
- } else if (m = /^(\d{1,2})[\/.\-](\d{1,2})[\/.\-](\d{4})$/.exec(s)) {
155
- d = +m[1];
156
- mo = +m[2];
157
- y = +m[3];
158
- } else if ((m = /^(\d{1,2})\s+(\S+)\s+(\d{4})$/.exec(s.replace(ERA, "").trim())) && monthIndex(m[2]) >= 0) {
159
- d = +m[1];
160
- mo = monthIndex(m[2]) + 1;
161
- y = +m[3];
162
- } else return null;
163
- if (y >= 2400) y -= 543;
164
- const dt = new Date(y, mo - 1, d);
165
- return dt.getMonth() === mo - 1 && dt.getDate() === d ? toISO(dt) : null;
166
- }
167
40
  const Calendar = React.forwardRef(function Calendar2(props, ref) {
168
41
  const ctx = useAuraLocale(), locale = props.locale || ctx.locale || "en", calendar = props.calendar || ctx.calendar || defaultCalendar(locale), tag = localeTag(locale, calendar);
169
42
  const weekStart = props.weekStartsOn == null ? locale === "sv" ? 1 : 0 : props.weekStartsOn;
@@ -721,9 +594,7 @@ export {
721
594
  Calendar,
722
595
  DatePicker,
723
596
  DateRangePicker,
724
- formatDate,
725
- fromISO,
726
- parseDate,
727
- toISO,
597
+ formatDate2 as formatDate,
598
+ parseDate2 as parseDate,
728
599
  useFormatDate
729
600
  };
@@ -5,16 +5,7 @@ import { useStrings } from "./locale.js";
5
5
  import { Icon } from "./Icon.js";
6
6
  import { IconButton } from "./IconButton.js";
7
7
  import { Field } from "./Field.js";
8
- function formatBytes(n) {
9
- if (n == null) return "";
10
- if (n < 1024) return n + " B";
11
- let u = ["KB", "MB", "GB"], i = -1;
12
- do {
13
- n /= 1024;
14
- i++;
15
- } while (n >= 1024 && i < u.length - 1);
16
- return (n >= 10 || Math.round(n) === n ? Math.round(n) : n.toFixed(1)) + " " + u[i];
17
- }
8
+ import { formatBytes } from "./text.js";
18
9
  function matches(file, accept) {
19
10
  if (!accept) return true;
20
11
  const name = (file.name || "").toLowerCase(), type = (file.type || "").toLowerCase();
@@ -1,5 +1,6 @@
1
1
  'use client';
2
2
  import * as React from "react";
3
+ import { Icon } from "./Icon.js";
3
4
  import { IconButton } from "./IconButton.js";
4
5
  import { cx, useMaybeControlled } from "./internal.js";
5
6
  import { useLinkComponent, useStrings } from "./locale.js";
@@ -31,7 +32,7 @@ const Pagination = React.forwardRef(function Pagination2(props, ref) {
31
32
  if (p >= 1 && p <= count && p !== page) st[1](p);
32
33
  }
33
34
  const link = props.getHref;
34
- const Link = useLinkComponent();
35
+ const Link = useLinkComponent(props.linkComponent);
35
36
  function item(p, label, extra) {
36
37
  const common = Object.assign(
37
38
  {
@@ -66,29 +67,40 @@ const Pagination = React.forwardRef(function Pagination2(props, ref) {
66
67
  label
67
68
  );
68
69
  }
69
- return /* @__PURE__ */ React.createElement("nav", { ref, className: cx("aura-pagination", props.className), "aria-label": props.label || t.pagination }, /* @__PURE__ */ React.createElement(
70
- IconButton,
71
- {
72
- icon: "chevron-left",
73
- label: t.prevPage,
74
- disabled: page <= 1,
75
- onClick: function() {
76
- go(page - 1);
77
- }
78
- }
79
- ), /* @__PURE__ */ React.createElement("ol", { className: "aura-pagination__list" }, pageList(page, count, props.siblingCount == null ? 1 : props.siblingCount).map(function(p) {
70
+ function arrow(p, icon, label, rel, disabled) {
71
+ if (!link || disabled)
72
+ return /* @__PURE__ */ React.createElement(
73
+ IconButton,
74
+ {
75
+ icon,
76
+ label,
77
+ disabled,
78
+ onClick: function() {
79
+ go(p);
80
+ }
81
+ }
82
+ );
83
+ return /* @__PURE__ */ React.createElement(
84
+ Link,
85
+ {
86
+ href: link(p),
87
+ rel,
88
+ className: "aura-icon-btn",
89
+ "aria-label": label,
90
+ title: label,
91
+ onClick: function(e) {
92
+ if (props.onChange) {
93
+ e.preventDefault();
94
+ go(p);
95
+ }
96
+ }
97
+ },
98
+ /* @__PURE__ */ React.createElement(Icon, { name: icon, size: "sm" })
99
+ );
100
+ }
101
+ return /* @__PURE__ */ React.createElement("nav", { ref, className: cx("aura-pagination", props.className), "aria-label": props.label || t.pagination }, arrow(page - 1, "chevron-left", t.prevPage, "prev", page <= 1), /* @__PURE__ */ React.createElement("ol", { className: "aura-pagination__list" }, pageList(page, count, props.siblingCount == null ? 1 : props.siblingCount).map(function(p) {
80
102
  return typeof p === "number" ? /* @__PURE__ */ React.createElement("li", { key: p }, item(p, p)) : /* @__PURE__ */ React.createElement("li", { key: p, className: "aura-pagination__gap", "aria-hidden": true }, "\u2026");
81
- })), /* @__PURE__ */ React.createElement("span", { className: "aura-pagination__compact", "aria-hidden": true }, t.page(page, count)), /* @__PURE__ */ React.createElement(
82
- IconButton,
83
- {
84
- icon: "chevron-right",
85
- label: t.nextPage,
86
- disabled: page >= count,
87
- onClick: function() {
88
- go(page + 1);
89
- }
90
- }
91
- ));
103
+ })), /* @__PURE__ */ React.createElement("span", { className: "aura-pagination__compact", "aria-hidden": true }, t.page(page, count)), arrow(page + 1, "chevron-right", t.nextPage, "next", page >= count));
92
104
  });
93
105
  export {
94
106
  Pagination
package/dist/esm/Stat.js CHANGED
@@ -7,7 +7,7 @@ const Stat = React.forwardRef(function Stat2(props, ref) {
7
7
  const ch = props.change;
8
8
  const dir = ch && (ch.direction || "flat");
9
9
  const tone = ch && (ch.tone || (dir === "up" ? "positive" : dir === "down" ? "negative" : "neutral"));
10
- const Link = useLinkComponent();
10
+ const Link = useLinkComponent(props.linkComponent);
11
11
  const v = props.value;
12
12
  const numeric = typeof v === "number" || typeof v === "string" && /\d/.test(v) && /^[\s\d.,:+\-\u2212%()\u0E3F$\u20AC\u00A3\u00A5kKmMbB]+$/.test(v.replace(/\b[A-Z]{3}\b/g, ""));
13
13
  const Tag = props.href ? Link : props.onClick ? "button" : "div";
@@ -8,17 +8,8 @@ const TONE_ICON = {
8
8
  ready: "circle-check",
9
9
  blocked: "ban"
10
10
  };
11
- const TONE_WORDS = {
12
- ready: ["ready", "done", "complete", "completed", "approved", "live", "passed"],
13
- progress: ["in progress", "in review", "review", "syncing", "running", "pending"],
14
- blocked: ["blocked", "failed", "error", "rejected", "on hold", "cancelled"]
15
- };
16
- function toneFor(status) {
17
- const s = String(status == null ? "" : status).trim().toLowerCase();
18
- for (const t in TONE_WORDS) if (TONE_WORDS[t].indexOf(s) >= 0) return t;
19
- return "neutral";
20
- }
21
- const TONE_ORDER = { neutral: 0, progress: 1, ready: 2, blocked: 3 };
11
+ import { toneFor } from "./status.js";
12
+ import { toneFor as toneFor2, statusTone, TONE_ORDER } from "./status.js";
22
13
  const StatusPill = React.forwardRef(function StatusPill2(props, ref) {
23
14
  const tone = props.tone || toneFor(props.children);
24
15
  return /* @__PURE__ */ React.createElement("span", { ref, className: cx("aura-pill", "aura-pill--" + tone, props.className) }, /* @__PURE__ */ React.createElement(Icon, { name: TONE_ICON[tone] || "circle", size: 12 }), props.children);
@@ -26,6 +17,6 @@ const StatusPill = React.forwardRef(function StatusPill2(props, ref) {
26
17
  export {
27
18
  StatusPill,
28
19
  TONE_ORDER,
29
- toneFor as statusTone,
30
- toneFor
20
+ statusTone,
21
+ toneFor2 as toneFor
31
22
  };
@@ -15,18 +15,7 @@ function toMin(t) {
15
15
  function fromMin(n) {
16
16
  return pad(Math.floor(n / 60)) + ":" + pad(n % 60);
17
17
  }
18
- function parseTime(text) {
19
- let s = String(text || "").trim().toLowerCase().replace(/\s*(น\.?|นาฬิกา)$/, "").trim();
20
- const pm = /\s*(pm|p\.m\.)$/.test(s), am = /\s*(am|a\.m\.)$/.test(s);
21
- s = s.replace(/\s*(am|pm|a\.m\.|p\.m\.)$/, "");
22
- const m = /^(\d{1,2})(?:[:.](\d{2}))?$/.exec(s) || /^(\d{1,2})(\d{2})$/.exec(s);
23
- if (!m) return null;
24
- let hh = +m[1], mm = m[2] ? +m[2] : 0;
25
- if (pm && hh < 12) hh += 12;
26
- if (am && hh === 12) hh = 0;
27
- if (hh > 23 || mm > 59) return null;
28
- return pad(hh) + ":" + pad(mm);
29
- }
18
+ import { parseTime } from "./text.js";
30
19
  const TimePicker = React.forwardRef(function TimePicker2(props, ref) {
31
20
  const t = useStrings();
32
21
  const auto = uid(), id = props.id || auto, listId = id + "-list";
@@ -0,0 +1,5 @@
1
+ 'use client';
2
+ const breakpoints = { sm: 640, md: 768, lg: 1024, xl: 1280 };
3
+ export {
4
+ breakpoints
5
+ };
@@ -3,17 +3,7 @@ import * as React from "react";
3
3
  import { useStrings } from "./locale.js";
4
4
  import { IconButton } from "./IconButton.js";
5
5
  import { DropdownMenu } from "./DropdownMenu.js";
6
- const DEFAULT_KEY = "aura-color-scheme";
7
- const SCHEMES = ["light", "dark", "system"];
8
- const EVENT = "aura-color-scheme";
9
- function valid(v) {
10
- return typeof v === "string" && SCHEMES.indexOf(v) >= 0;
11
- }
12
- function colorSchemeScript(options) {
13
- const key = JSON.stringify(options && options.storageKey || DEFAULT_KEY);
14
- const fallback = JSON.stringify(options && options.defaultScheme || "system");
15
- return "(function(){try{var s=localStorage.getItem(" + key + ");if(s!=='light'&&s!=='dark'&&s!=='system')s=" + fallback + `;var d=document.documentElement;d.setAttribute("data-theme",s);var dark=s==='dark'||(s==='system'&&window.matchMedia('(prefers-color-scheme: dark)').matches);d.classList.toggle("dark",dark);}catch(e){}})();`;
16
- }
6
+ import { DEFAULT_KEY, SCHEMES, EVENT, valid, colorSchemeScript } from "./colorSchemeScript.js";
17
7
  function ColorSchemeScript(props) {
18
8
  return /* @__PURE__ */ React.createElement(
19
9
  "script",
@@ -0,0 +1,19 @@
1
+ 'use client';
2
+ const DEFAULT_KEY = "aura-color-scheme";
3
+ const SCHEMES = ["light", "dark", "system"];
4
+ const EVENT = "aura-color-scheme";
5
+ function valid(v) {
6
+ return typeof v === "string" && SCHEMES.indexOf(v) >= 0;
7
+ }
8
+ function colorSchemeScript(options) {
9
+ const key = JSON.stringify(options && options.storageKey || DEFAULT_KEY);
10
+ const fallback = JSON.stringify(options && options.defaultScheme || "system");
11
+ return "(function(){try{var s=localStorage.getItem(" + key + ");if(s!=='light'&&s!=='dark'&&s!=='system')s=" + fallback + `;var d=document.documentElement;d.setAttribute("data-theme",s);var dark=s==='dark'||(s==='system'&&window.matchMedia('(prefers-color-scheme: dark)').matches);d.classList.toggle("dark",dark);}catch(e){}})();`;
12
+ }
13
+ export {
14
+ DEFAULT_KEY,
15
+ EVENT,
16
+ SCHEMES,
17
+ colorSchemeScript,
18
+ valid
19
+ };