@rockshin/tao-ui 0.0.44 → 0.0.46
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 +9 -1
- package/component-manifest.json +38 -4
- package/dist/components/alert/alert.js +20 -17
- package/dist/components/auto-complete/auto-complete.js +12 -3
- package/dist/components/avatar/avatar.js +2 -1
- package/dist/components/breadcrumb/breadcrumb.css +4 -0
- package/dist/components/breadcrumb/breadcrumb.js +82 -77
- package/dist/components/calendar/calendar.d.ts +1 -1
- package/dist/components/calendar/calendar.js +51 -33
- package/dist/components/card/card-tabs.js +204 -182
- package/dist/components/card/card.js +1 -1
- package/dist/components/carousel/carousel.js +11 -5
- package/dist/components/cascader/cascader.js +16 -4
- package/dist/components/collapse/collapse.css +8 -0
- package/dist/components/color-picker/color-picker.js +273 -269
- package/dist/components/context-menu/context-menu.d.ts +2 -1
- package/dist/components/context-menu/context-menu.js +57 -44
- package/dist/components/date-picker/calendar/calendar-grid.js +13 -6
- package/dist/components/date-picker/calendar/use-calendar.d.ts +2 -2
- package/dist/components/date-picker/calendar/use-calendar.js +2 -3
- package/dist/components/date-picker/date-localization.d.ts +3 -0
- package/dist/components/date-picker/date-localization.js +76 -0
- package/dist/components/date-picker/date-picker.css +4 -0
- package/dist/components/date-picker/date-picker.d.ts +1 -0
- package/dist/components/date-picker/date-picker.js +48 -30
- package/dist/components/date-picker/range-picker.d.ts +1 -0
- package/dist/components/date-picker/range-picker.js +41 -23
- package/dist/components/drawer/drawer.d.ts +2 -1
- package/dist/components/drawer/drawer.js +32 -20
- package/dist/components/dropdown/dropdown.d.ts +1 -0
- package/dist/components/dropdown/dropdown.js +160 -143
- package/dist/components/float-button/float-button.js +3 -2
- package/dist/components/form/form.js +88 -103
- package/dist/components/image/image.js +202 -137
- package/dist/components/list/list-pagination.js +148 -147
- package/dist/components/mentions/mentions.js +6 -2
- package/dist/components/modal/confirm-dialog.js +4 -2
- package/dist/components/modal/modal.d.ts +2 -1
- package/dist/components/modal/modal.js +387 -375
- package/dist/components/pagination/pagination.css +4 -0
- package/dist/components/pagination/pagination.js +115 -110
- package/dist/components/popconfirm/popconfirm.js +109 -107
- package/dist/components/popover/popover.d.ts +2 -1
- package/dist/components/popover/popover.js +185 -176
- package/dist/components/qr-code/qr-code.js +22 -21
- package/dist/components/rate/rate.js +114 -88
- package/dist/components/scroll-area/scroll-area.js +132 -120
- package/dist/components/segmented/segmented.js +52 -29
- package/dist/components/select/mobile-select.d.ts +3 -2
- package/dist/components/select/mobile-select.js +54 -48
- package/dist/components/select/select-types.d.ts +1 -0
- package/dist/components/select/select.js +19 -6
- package/dist/components/slider/slider.js +136 -133
- package/dist/components/sonner/sonner.js +10 -10
- package/dist/components/spinner/spinner.js +1 -1
- package/dist/components/splitter/splitter.css +4 -0
- package/dist/components/splitter/splitter.js +29 -24
- package/dist/components/statistic/statistic.d.ts +2 -0
- package/dist/components/statistic/statistic.js +203 -187
- package/dist/components/table/table-filter.js +61 -52
- package/dist/components/table/table-icons.js +3 -1
- package/dist/components/table/table.css +29 -11
- package/dist/components/table/table.d.ts +1 -1
- package/dist/components/table/table.js +384 -547
- package/dist/components/tabs/tabs.js +3 -2
- package/dist/components/tag/tag.js +22 -19
- package/dist/components/time-picker/time-picker.d.ts +0 -1
- package/dist/components/time-picker/time-picker.js +160 -103
- package/dist/components/tooltip/tooltip.d.ts +2 -1
- package/dist/components/tooltip/tooltip.js +82 -71
- package/dist/components/transfer/transfer-list.js +224 -488
- package/dist/components/transfer/transfer-parts.js +14 -4
- package/dist/components/transfer/transfer-types.d.ts +1 -0
- package/dist/components/transfer/transfer.js +23 -20
- package/dist/components/tree/tree-keyboard.d.ts +6 -0
- package/dist/components/tree/tree-keyboard.js +27 -0
- package/dist/components/tree/tree.js +14 -3
- package/dist/components/tree-select/select-engine.d.ts +2 -1
- package/dist/components/tree-select/select-engine.js +23 -15
- package/dist/components/tree-select/tree-select.js +20 -10
- package/dist/components/upload/upload.js +30 -26
- package/dist/docs/component-docs.d.ts +13 -2
- package/dist/docs/components/headless-input-number.doc.d.ts +5 -0
- package/dist/docs/components/headless-input-number.doc.js +7 -0
- package/dist/docs/components/input-number.doc.d.ts +5 -0
- package/dist/docs/components/input-number.doc.js +7 -0
- package/dist/docs/components/statistic.doc.d.ts +5 -0
- package/dist/docs/components/statistic.doc.js +7 -0
- package/dist/docs/components/tao-provider.doc.d.ts +8 -2
- package/dist/docs/components/tao-provider.doc.js +16 -3
- package/dist/docs/components/tooltip.doc.d.ts +2 -2
- package/dist/entries/provider.d.ts +2 -1
- package/dist/entries/provider.js +1 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -0
- package/dist/locales/ar-EG.d.ts +3 -0
- package/dist/locales/ar-EG.js +199 -0
- package/dist/locales/create-locale.d.ts +41 -0
- package/dist/locales/create-locale.js +88 -0
- package/dist/locales/de-DE.d.ts +3 -0
- package/dist/locales/de-DE.js +195 -0
- package/dist/locales/en-US.d.ts +2 -0
- package/dist/locales/en-US.js +194 -0
- package/dist/locales/es-ES.d.ts +3 -0
- package/dist/locales/es-ES.js +195 -0
- package/dist/locales/fr-FR.d.ts +3 -0
- package/dist/locales/fr-FR.js +195 -0
- package/dist/locales/hi-IN.d.ts +3 -0
- package/dist/locales/hi-IN.js +194 -0
- package/dist/locales/id-ID.d.ts +3 -0
- package/dist/locales/id-ID.js +194 -0
- package/dist/locales/index.d.ts +18 -0
- package/dist/locales/index.js +17 -0
- package/dist/locales/it-IT.d.ts +3 -0
- package/dist/locales/it-IT.js +195 -0
- package/dist/locales/ja-JP.d.ts +3 -0
- package/dist/locales/ja-JP.js +194 -0
- package/dist/locales/ko-KR.d.ts +3 -0
- package/dist/locales/ko-KR.js +194 -0
- package/dist/locales/pt-BR.d.ts +3 -0
- package/dist/locales/pt-BR.js +195 -0
- package/dist/locales/ru-RU.d.ts +3 -0
- package/dist/locales/ru-RU.js +197 -0
- package/dist/locales/th-TH.d.ts +3 -0
- package/dist/locales/th-TH.js +194 -0
- package/dist/locales/tr-TR.d.ts +3 -0
- package/dist/locales/tr-TR.js +194 -0
- package/dist/locales/types.d.ts +176 -0
- package/dist/locales/types.js +0 -0
- package/dist/locales/vi-VN.d.ts +3 -0
- package/dist/locales/vi-VN.js +194 -0
- package/dist/locales/zh-CN.d.ts +3 -0
- package/dist/locales/zh-CN.js +194 -0
- package/dist/locales/zh-TW.d.ts +3 -0
- package/dist/locales/zh-TW.js +194 -0
- package/dist/number-input/format.d.ts +4 -3
- package/dist/number-input/format.js +9 -7
- package/dist/number-input/locale.d.ts +19 -0
- package/dist/number-input/locale.js +44 -0
- package/dist/number-input/number-input.js +1 -0
- package/dist/number-input/use-number-input.d.ts +2 -0
- package/dist/number-input/use-number-input.js +180 -176
- package/dist/provider/locale.d.ts +3 -65
- package/dist/provider/locale.js +2 -146
- package/dist/provider/merge-locale.d.ts +8 -0
- package/dist/provider/merge-locale.js +53 -0
- package/dist/provider/tao-provider.d.ts +16 -5
- package/dist/provider/tao-provider.js +200 -92
- package/dist/utils/scroll-left.d.ts +3 -0
- package/dist/utils/scroll-left.js +7 -0
- package/llms.txt +3 -3
- package/package.json +5 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import zh_TW from "@rc-component/picker/locale/zh_TW";
|
|
2
|
+
import "dayjs/locale/zh-tw";
|
|
3
|
+
import { createFormMessages, createItemCount, createLocale } from "./create-locale.js";
|
|
4
|
+
const zhTW = createLocale({
|
|
5
|
+
locale: 'zh_TW',
|
|
6
|
+
numberLocale: 'zh-TW',
|
|
7
|
+
dayjsLocale: 'zh-tw',
|
|
8
|
+
weekStartsOn: 0,
|
|
9
|
+
pickerLocale: zh_TW,
|
|
10
|
+
select: '選擇',
|
|
11
|
+
searchPlaceholder: '搜尋…',
|
|
12
|
+
search: '搜尋',
|
|
13
|
+
showPassword: '顯示密碼',
|
|
14
|
+
hidePassword: '隱藏密碼',
|
|
15
|
+
otpLabel: (index, length)=>`第 ${index} 位,共 ${length} 位`,
|
|
16
|
+
searchOptions: '搜尋選項',
|
|
17
|
+
noResults: '沒有結果',
|
|
18
|
+
emptyDescription: '暫無資料',
|
|
19
|
+
done: '完成',
|
|
20
|
+
clear: '清除',
|
|
21
|
+
close: '關閉',
|
|
22
|
+
remove: (label)=>`移除${label}`,
|
|
23
|
+
dateTime: '選擇日期和時間',
|
|
24
|
+
selectDate: '選擇日期',
|
|
25
|
+
selectTime: '選擇時間',
|
|
26
|
+
startTime: '開始時間',
|
|
27
|
+
endTime: '結束時間',
|
|
28
|
+
dateRange: '選擇日期範圍',
|
|
29
|
+
startDate: '開始日期',
|
|
30
|
+
endDate: '結束日期',
|
|
31
|
+
now: '此刻',
|
|
32
|
+
ok: '確定',
|
|
33
|
+
cancel: '取消',
|
|
34
|
+
previous: '上一頁',
|
|
35
|
+
next: '下一頁',
|
|
36
|
+
previousMonth: '上個月',
|
|
37
|
+
nextMonth: '下個月',
|
|
38
|
+
previousYear: '上一年',
|
|
39
|
+
nextYear: '下一年',
|
|
40
|
+
hour: '時',
|
|
41
|
+
minute: '分',
|
|
42
|
+
second: '秒',
|
|
43
|
+
qrCode: {
|
|
44
|
+
expired: 'QR 碼已過期',
|
|
45
|
+
refresh: '重新整理',
|
|
46
|
+
scanned: '已掃描'
|
|
47
|
+
},
|
|
48
|
+
messages: {
|
|
49
|
+
tableEmpty: '暫無資料',
|
|
50
|
+
loading: '載入中',
|
|
51
|
+
pagination: '分頁',
|
|
52
|
+
previousPage: '上一頁',
|
|
53
|
+
nextPage: '下一頁',
|
|
54
|
+
itemsPerPage: '筆/頁',
|
|
55
|
+
pageSize: '每頁筆數',
|
|
56
|
+
jumpTo: '跳至',
|
|
57
|
+
jumpToConfirm: '確定',
|
|
58
|
+
previousPages: '向前翻頁',
|
|
59
|
+
nextPages: '向後翻頁',
|
|
60
|
+
selectAllRows: '選取所有列',
|
|
61
|
+
expandRow: '展開列',
|
|
62
|
+
collapseRow: '收合列',
|
|
63
|
+
uploadFile: '上傳檔案',
|
|
64
|
+
uploadDrop: '按一下或將檔案拖曳至此區域上傳',
|
|
65
|
+
removeFile: '刪除檔案',
|
|
66
|
+
previewFile: '預覽檔案',
|
|
67
|
+
downloadFile: '下載檔案',
|
|
68
|
+
uploadError: '上傳失敗',
|
|
69
|
+
previewUnavailable: '無法預覽',
|
|
70
|
+
source: '來源清單',
|
|
71
|
+
target: '目標清單',
|
|
72
|
+
itemUnit: '項',
|
|
73
|
+
itemsUnit: '項',
|
|
74
|
+
selectAll: '全選',
|
|
75
|
+
deselectAll: '取消全選',
|
|
76
|
+
selectCurrent: '選取目前頁面',
|
|
77
|
+
invertCurrent: '反向選取目前頁面',
|
|
78
|
+
removeAll: '移除全部',
|
|
79
|
+
removeCurrent: '移除目前頁面',
|
|
80
|
+
moveToTarget: '移至目標清單',
|
|
81
|
+
moveToSource: '移至來源清單',
|
|
82
|
+
clearSearch: '清空搜尋',
|
|
83
|
+
calendarYear: '年',
|
|
84
|
+
calendarMonth: '月',
|
|
85
|
+
calendarView: '行事曆檢視',
|
|
86
|
+
zoomIn: '放大',
|
|
87
|
+
zoomOut: '縮小',
|
|
88
|
+
rotateLeft: '向左旋轉',
|
|
89
|
+
rotateRight: '向右旋轉',
|
|
90
|
+
flipX: '水平翻轉',
|
|
91
|
+
flipY: '垂直翻轉',
|
|
92
|
+
colorMode: '色彩模式',
|
|
93
|
+
colorSingle: '單色',
|
|
94
|
+
colorGradient: '漸層',
|
|
95
|
+
colorStop: '色標',
|
|
96
|
+
addColorStop: '新增色標',
|
|
97
|
+
removeColorStop: '刪除色標',
|
|
98
|
+
colorPosition: '位置',
|
|
99
|
+
colorStopPosition: '色標位置',
|
|
100
|
+
colorFormat: '色彩格式',
|
|
101
|
+
colorHex: '十六進位色彩',
|
|
102
|
+
colorRed: '紅色',
|
|
103
|
+
colorGreen: '綠色',
|
|
104
|
+
colorBlue: '藍色',
|
|
105
|
+
colorHue: '色相',
|
|
106
|
+
colorSaturation: '飽和度',
|
|
107
|
+
colorBrightness: '亮度',
|
|
108
|
+
colorAlpha: '透明度',
|
|
109
|
+
clearColor: '清除色彩',
|
|
110
|
+
colorPreset: '預設',
|
|
111
|
+
colorTransparent: '透明',
|
|
112
|
+
chooseColor: '選擇色彩',
|
|
113
|
+
colorPicker: '色彩選擇器',
|
|
114
|
+
loadingQrCode: '正在載入 QR 碼',
|
|
115
|
+
loadingNotification: '正在載入通知',
|
|
116
|
+
closeNotification: '關閉通知',
|
|
117
|
+
floatingActions: '浮動操作',
|
|
118
|
+
breadcrumb: '麵包屑導覽',
|
|
119
|
+
showMore: '顯示更多',
|
|
120
|
+
collapsePanel: '收合面板',
|
|
121
|
+
selectionActions: '選取操作',
|
|
122
|
+
more: '更多',
|
|
123
|
+
scrollVertically: '垂直捲動',
|
|
124
|
+
scrollHorizontally: '水平捲動',
|
|
125
|
+
filter: '篩選',
|
|
126
|
+
filterReset: '重設篩選',
|
|
127
|
+
page: (page)=>`第 ${page} 頁`,
|
|
128
|
+
selectRow: (label)=>`選取列 ${label}`,
|
|
129
|
+
moreUsers: (count)=>`另外 ${count} 位使用者`,
|
|
130
|
+
resizePanels: (first, second)=>`調整面板 ${first} 和 ${second} 的大小`,
|
|
131
|
+
backToTop: '回到頂端',
|
|
132
|
+
successNotification: '成功通知',
|
|
133
|
+
errorNotification: '錯誤通知',
|
|
134
|
+
warningNotification: '警告通知',
|
|
135
|
+
infoNotification: '資訊通知',
|
|
136
|
+
notification: '通知',
|
|
137
|
+
removeFileError: '無法刪除檔案',
|
|
138
|
+
readFileError: '無法讀取檔案',
|
|
139
|
+
millisecond: '毫秒',
|
|
140
|
+
meridiem: '上午/下午',
|
|
141
|
+
pageUnit: '頁',
|
|
142
|
+
itemCount: createItemCount('zh-TW', {
|
|
143
|
+
other: '# 項'
|
|
144
|
+
})
|
|
145
|
+
},
|
|
146
|
+
form: createFormMessages({
|
|
147
|
+
default: "欄位「${name}」驗證失敗",
|
|
148
|
+
required: "「${name}」為必填項目",
|
|
149
|
+
enum: "「${name}」必須是 [${enum}] 中的一項",
|
|
150
|
+
whitespace: "「${name}」不能為空白",
|
|
151
|
+
invalid: "「${name}」不是有效的${type}",
|
|
152
|
+
dateFormat: "「${name}」的日期格式無效",
|
|
153
|
+
dateParse: "無法將「${name}」解析為日期",
|
|
154
|
+
dateInvalid: "「${name}」不是有效日期",
|
|
155
|
+
string: {
|
|
156
|
+
len: "「${name}」必須為 ${len} 個字元",
|
|
157
|
+
min: "「${name}」至少需要 ${min} 個字元",
|
|
158
|
+
max: "「${name}」不能超過 ${max} 個字元",
|
|
159
|
+
range: "「${name}」需要 ${min} 到 ${max} 個字元"
|
|
160
|
+
},
|
|
161
|
+
number: {
|
|
162
|
+
len: "「${name}」必須等於 ${len}",
|
|
163
|
+
min: "「${name}」不能小於 ${min}",
|
|
164
|
+
max: "「${name}」不能大於 ${max}",
|
|
165
|
+
range: "「${name}」必須介於 ${min} 到 ${max} 之間"
|
|
166
|
+
},
|
|
167
|
+
array: {
|
|
168
|
+
len: "「${name}」必須包含 ${len} 項",
|
|
169
|
+
min: "「${name}」至少需要 ${min} 項",
|
|
170
|
+
max: "「${name}」不能超過 ${max} 項",
|
|
171
|
+
range: "「${name}」需要包含 ${min} 到 ${max} 項"
|
|
172
|
+
},
|
|
173
|
+
pattern: "「${name}」不符合模式 ${pattern}",
|
|
174
|
+
typeNames: {
|
|
175
|
+
string: '字串',
|
|
176
|
+
method: '函式',
|
|
177
|
+
array: '陣列',
|
|
178
|
+
object: '物件',
|
|
179
|
+
number: '數字',
|
|
180
|
+
date: '日期',
|
|
181
|
+
boolean: '布林值',
|
|
182
|
+
integer: '整數',
|
|
183
|
+
float: '小數',
|
|
184
|
+
regexp: '正規表示式',
|
|
185
|
+
email: '電子郵件地址',
|
|
186
|
+
tel: '電話號碼',
|
|
187
|
+
url: '網址',
|
|
188
|
+
hex: '十六進位值'
|
|
189
|
+
}
|
|
190
|
+
})
|
|
191
|
+
});
|
|
192
|
+
const locales_zh_TW = zhTW;
|
|
193
|
+
export default locales_zh_TW;
|
|
194
|
+
export { zhTW };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
1
|
+
import { type NumberFormatOptions } from './locale.js';
|
|
2
|
+
import type { PadDecimalsOnBlur } from './types.js';
|
|
3
|
+
export declare function format(canonical: string, opts: NumberFormatOptions): string;
|
|
4
|
+
export declare function parse(display: string, opts: NumberFormatOptions): string;
|
|
4
5
|
export declare function truncateDecimals(canonical: string, decimalPlaces: number): string;
|
|
5
6
|
export declare function padOnBlur(canonical: string, decimalPlaces: number, mode: PadDecimalsOnBlur): string;
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { groupInteger, localizeDigits, normalizeDigits } from "./locale.js";
|
|
2
2
|
function format(canonical, opts) {
|
|
3
|
-
if ('' === canonical
|
|
3
|
+
if ('' === canonical) return canonical;
|
|
4
|
+
if ('-' === canonical) return opts.minusSign ?? '-';
|
|
4
5
|
const negative = canonical.startsWith('-');
|
|
5
6
|
const abs = negative ? canonical.slice(1) : canonical;
|
|
6
7
|
const dotIndex = abs.indexOf('.');
|
|
7
8
|
const intPart = -1 === dotIndex ? abs : abs.slice(0, dotIndex);
|
|
8
9
|
const fracPart = -1 === dotIndex ? '' : abs.slice(dotIndex + 1);
|
|
9
|
-
const groupedInt =
|
|
10
|
+
const groupedInt = groupInteger(intPart, opts);
|
|
10
11
|
let result = groupedInt;
|
|
11
12
|
if (-1 !== dotIndex) result += opts.decimalSeparator + fracPart;
|
|
12
|
-
return (negative ? '-' : '') + result;
|
|
13
|
+
return (negative ? opts.minusSign ?? '-' : '') + localizeDigits(result, opts);
|
|
13
14
|
}
|
|
14
15
|
function parse(display, opts) {
|
|
15
16
|
if (!display) return '';
|
|
16
|
-
const
|
|
17
|
-
const
|
|
17
|
+
const text = normalizeDigits(display, opts).replace(/[\u061c\u200e\u200f\u202a-\u202e\u2066-\u2069]/g, '');
|
|
18
|
+
const negative = text.startsWith('-') || text.startsWith(opts.minusSign ?? '-');
|
|
19
|
+
const body = negative ? text.slice(1) : text;
|
|
18
20
|
let cleaned = '';
|
|
19
21
|
let seenDecimal = false;
|
|
20
22
|
for (const ch of body)if (ch >= '0' && ch <= '9') cleaned += ch;
|
|
21
|
-
else if (ch === opts.decimalSeparator &&
|
|
23
|
+
else if (!seenDecimal && (ch === opts.decimalSeparator || opts.allowAsciiDecimal && '.' === ch && '.' !== opts.thousandsSeparator)) {
|
|
22
24
|
cleaned += '.';
|
|
23
25
|
seenDecimal = true;
|
|
24
26
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Formatting metadata only: numeric values remain exact decimal strings. */
|
|
2
|
+
export interface NumberFormatOptions {
|
|
3
|
+
decimalSeparator: string;
|
|
4
|
+
thousandsSeparator: string;
|
|
5
|
+
digits?: readonly string[];
|
|
6
|
+
primaryGrouping?: number;
|
|
7
|
+
secondaryGrouping?: number;
|
|
8
|
+
minimumGrouping?: number;
|
|
9
|
+
minusSign?: string;
|
|
10
|
+
allowAsciiDecimal?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function resolveNumberFormat(locale: string | undefined, overrides?: {
|
|
13
|
+
decimalSeparator?: string;
|
|
14
|
+
thousandsSeparator?: string;
|
|
15
|
+
}): NumberFormatOptions;
|
|
16
|
+
export declare function localizeDigits(value: string, options: NumberFormatOptions): string;
|
|
17
|
+
/** Normalize only digits; date/time parsers retain their own punctuation grammar. */
|
|
18
|
+
export declare function normalizeDigits(value: string, options: Pick<NumberFormatOptions, 'digits'>): string;
|
|
19
|
+
export declare function groupInteger(value: string, options: NumberFormatOptions): string;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
function resolveNumberFormat(locale, overrides = {}) {
|
|
2
|
+
const formatter = new Intl.NumberFormat(locale ?? 'en-US');
|
|
3
|
+
const parts = formatter.formatToParts(1234567890123);
|
|
4
|
+
const groups = parts.filter((part)=>'integer' === part.type);
|
|
5
|
+
const primaryGrouping = groups.at(-1).value.length;
|
|
6
|
+
const secondaryGrouping = groups.at(-2)?.value.length ?? primaryGrouping;
|
|
7
|
+
const digitFormatter = new Intl.NumberFormat(locale ?? 'en-US', {
|
|
8
|
+
useGrouping: false
|
|
9
|
+
});
|
|
10
|
+
return {
|
|
11
|
+
decimalSeparator: overrides.decimalSeparator ?? formatter.formatToParts(1.1).find((part)=>'decimal' === part.type).value,
|
|
12
|
+
thousandsSeparator: overrides.thousandsSeparator ?? parts.find((part)=>'group' === part.type).value,
|
|
13
|
+
digits: Array.from({
|
|
14
|
+
length: 10
|
|
15
|
+
}, (_, digit)=>digitFormatter.format(digit)),
|
|
16
|
+
primaryGrouping,
|
|
17
|
+
secondaryGrouping,
|
|
18
|
+
minimumGrouping: formatter.formatToParts(1000).some((part)=>'group' === part.type) ? 4 : 5,
|
|
19
|
+
minusSign: formatter.formatToParts(-1).find((part)=>'minusSign' === part.type).value,
|
|
20
|
+
allowAsciiDecimal: void 0 !== locale && void 0 === overrides.decimalSeparator
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function localizeDigits(value, options) {
|
|
24
|
+
return options.digits ? value.replace(/\d/g, (digit)=>options.digits[Number(digit)]) : value;
|
|
25
|
+
}
|
|
26
|
+
function normalizeDigits(value, options) {
|
|
27
|
+
return options.digits ? value.replace(/[^\d]/gu, (character)=>{
|
|
28
|
+
const digit = options.digits.indexOf(character);
|
|
29
|
+
return -1 === digit ? character : String(digit);
|
|
30
|
+
}) : value;
|
|
31
|
+
}
|
|
32
|
+
function groupInteger(value, options) {
|
|
33
|
+
if (!options.thousandsSeparator || value.length < (options.minimumGrouping ?? 4)) return value;
|
|
34
|
+
const groups = [];
|
|
35
|
+
let end = value.length;
|
|
36
|
+
let size = options.primaryGrouping ?? 3;
|
|
37
|
+
while(end > 0){
|
|
38
|
+
groups.unshift(value.slice(Math.max(0, end - size), end));
|
|
39
|
+
end -= size;
|
|
40
|
+
size = options.secondaryGrouping ?? 3;
|
|
41
|
+
}
|
|
42
|
+
return groups.join(options.thousandsSeparator);
|
|
43
|
+
}
|
|
44
|
+
export { groupInteger, localizeDigits, normalizeDigits, resolveNumberFormat };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type ChangeEvent, type FocusEvent, type KeyboardEvent, type MutableRefObject } from 'react';
|
|
2
2
|
import type { PadDecimalsOnBlur } from './types.js';
|
|
3
3
|
export interface UseNumberInputOptions {
|
|
4
|
+
/** BCP 47 locale. Defaults to the provider's number locale. */
|
|
5
|
+
locale?: string;
|
|
4
6
|
value?: string;
|
|
5
7
|
defaultValue?: string;
|
|
6
8
|
onChange?: (value: string) => void;
|