@livenetworks/ashlar 1.5.1 → 1.6.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.
- package/README.md +189 -177
- package/js/COMPONENTS.md +55 -49
- package/js/index.js +22 -5
- package/js/ln-accordion/README.md +186 -137
- package/js/ln-accordion/ln-accordion.js +1 -1
- package/js/ln-ajax/README.md +73 -4
- package/js/ln-ajax/ln-ajax.js +1 -1
- package/js/ln-ajax/src/ln-ajax.js +13 -13
- package/js/ln-api-connector/README.md +261 -150
- package/js/ln-api-connector/ln-api-connector.js +1 -1
- package/js/ln-api-connector/src/ln-api-connector.js +368 -265
- package/js/ln-api-queue/README.md +219 -0
- package/js/ln-api-queue/ln-api-queue.js +1 -0
- package/js/ln-api-queue/src/ln-api-queue.js +320 -0
- package/js/ln-api-queue/src/queue-storage.js +455 -0
- package/js/ln-autoresize/README.md +47 -0
- package/js/ln-autoresize/ln-autoresize.js +1 -1
- package/js/ln-autosave/README.md +33 -1
- package/js/ln-autosave/ln-autosave.js +1 -1
- package/js/ln-autosave/src/ln-autosave.js +4 -4
- package/js/ln-circular-progress/README.md +27 -13
- package/js/ln-circular-progress/ln-circular-progress.js +1 -1
- package/js/ln-circular-progress/src/ln-circular-progress.js +18 -5
- package/js/ln-confirm/README.md +162 -86
- package/js/ln-confirm/_ln-confirm.scss +11 -0
- package/js/ln-confirm/ln-confirm.js +1 -1
- package/js/ln-confirm/src/ln-confirm.js +77 -41
- package/js/ln-core/README.md +896 -0
- package/js/ln-core/hash.js +92 -0
- package/js/ln-core/helpers.js +337 -8
- package/js/ln-core/index.js +4 -2
- package/js/ln-core/persist.js +29 -3
- package/js/ln-core/positioning.js +1 -35
- package/js/ln-core/window-cache.js +213 -0
- package/js/ln-couchdb-connector/README.md +177 -156
- package/js/ln-couchdb-connector/ln-couchdb-connector.js +1 -1
- package/js/ln-couchdb-connector/src/ln-couchdb-connector.js +398 -348
- package/js/ln-data-coordinator/README.md +536 -165
- package/js/ln-data-coordinator/ln-data-coordinator.js +1 -1
- package/js/ln-data-coordinator/src/data-read-policy.js +18 -0
- package/js/ln-data-coordinator/src/ln-data-coordinator.js +1042 -249
- package/js/ln-data-coordinator/src/mutation-receipts.js +46 -0
- package/js/ln-data-store/README.md +241 -94
- package/js/ln-data-store/ln-data-store.js +1 -1
- package/js/ln-data-store/src/ln-data-store.js +694 -699
- package/js/ln-date/README.md +39 -1
- package/js/ln-date/ln-date-dev.scss +14 -0
- package/js/ln-date/ln-date.js +1 -1
- package/js/ln-date/src/ln-date.js +236 -178
- package/js/ln-debug/README.md +58 -0
- package/js/ln-debug/ln-debug.js +1 -0
- package/js/ln-debug/src/ln-debug.js +19 -0
- package/js/ln-dropdown/README.md +31 -8
- package/js/ln-dropdown/ln-dropdown.js +1 -1
- package/js/ln-dropdown/src/ln-dropdown.js +30 -13
- package/js/ln-editor/README.md +274 -0
- package/js/ln-editor/ln-editor.js +1 -0
- package/js/ln-editor/ln-editor.scss +43 -0
- package/js/ln-editor/src/ln-editor.js +619 -0
- package/js/ln-external-links/README.md +44 -5
- package/js/ln-external-links/ln-external-links.js +1 -1
- package/js/ln-fill/README.md +199 -0
- package/js/ln-fill/ln-fill.js +1 -0
- package/js/ln-fill/src/ln-fill.js +87 -0
- package/js/ln-filter/README.md +92 -2
- package/js/ln-filter/ln-filter-dev.scss +8 -0
- package/js/ln-filter/ln-filter.js +1 -1
- package/js/ln-filter/src/ln-filter.js +22 -7
- package/js/ln-form/README.md +212 -49
- package/js/ln-form/ln-form.js +1 -1
- package/js/ln-form/src/ln-form.js +99 -199
- package/js/ln-http/README.md +125 -89
- package/js/ln-http/ln-http.js +1 -1
- package/js/ln-http/src/ln-http.js +32 -13
- package/js/ln-icon/README.md +130 -0
- package/js/ln-icon/ln-icon.js +1 -0
- package/js/{ln-icons/src/ln-icons.js → ln-icon/src/ln-icon.js} +20 -15
- package/js/ln-link/README.md +47 -9
- package/js/ln-link/ln-link.js +1 -1
- package/js/ln-link/src/ln-link.js +22 -6
- package/js/ln-list/README.md +129 -0
- package/js/ln-list/ln-list.js +1 -0
- package/js/ln-list/ln-list.scss +28 -0
- package/js/ln-list/src/ln-list.js +1216 -0
- package/js/ln-modal/README.md +185 -154
- package/js/ln-modal/ln-modal-dev.scss +13 -0
- package/js/ln-modal/ln-modal.js +1 -1
- package/js/ln-modal/ln-modal.scss +28 -4
- package/js/ln-modal/src/ln-modal.js +137 -201
- package/js/ln-modal-coordinator/README.md +99 -0
- package/js/ln-modal-coordinator/ln-modal-coordinator-dev.scss +8 -0
- package/js/ln-modal-coordinator/ln-modal-coordinator.js +1 -0
- package/js/ln-modal-coordinator/src/ln-modal-coordinator.js +345 -0
- package/js/ln-nav/README.md +46 -3
- package/js/ln-nav/ln-nav.js +1 -1
- package/js/ln-nav/src/ln-nav.js +92 -127
- package/js/ln-number/README.md +28 -1
- package/js/ln-number/ln-number-dev.scss +13 -0
- package/js/ln-number/ln-number.js +1 -1
- package/js/ln-number/src/ln-number.js +443 -350
- package/js/ln-options/README.md +66 -0
- package/js/ln-options/ln-options.js +1 -0
- package/js/ln-options/src/ln-options.js +74 -0
- package/js/ln-popover/README.md +40 -5
- package/js/ln-popover/ln-popover.js +1 -1
- package/js/ln-popover/src/ln-popover.js +38 -11
- package/js/ln-progress/README.md +413 -442
- package/js/ln-progress/ln-progress.js +1 -1
- package/js/ln-progress/src/ln-progress.js +98 -150
- package/js/ln-router/README.md +432 -0
- package/js/ln-router/ln-router.js +1 -0
- package/js/ln-router/src/ln-router.js +539 -0
- package/js/ln-search/README.md +158 -83
- package/js/ln-search/ln-search-dev.scss +8 -0
- package/js/ln-search/ln-search.js +1 -1
- package/js/ln-search/src/ln-search.js +12 -9
- package/js/ln-slug/README.md +110 -0
- package/js/ln-slug/ln-slug.js +1 -0
- package/js/ln-slug/src/ln-slug.js +74 -0
- package/js/ln-sort/README.md +170 -0
- package/js/ln-sort/ln-sort-dev.scss +8 -0
- package/js/ln-sort/ln-sort.js +1 -0
- package/js/ln-sort/src/ln-sort.js +178 -0
- package/js/ln-sortable/README.md +133 -95
- package/js/ln-sortable/ln-sortable.js +1 -1
- package/js/ln-stat/README.md +55 -0
- package/js/ln-stat/ln-stat.js +1 -0
- package/js/ln-stat/src/ln-stat.js +55 -0
- package/js/ln-table/README.md +285 -101
- package/js/ln-table/ln-table-dev.scss +17 -0
- package/js/ln-table/ln-table.js +1 -1
- package/js/ln-table/ln-table.scss +1 -1
- package/js/ln-table/src/ln-table.js +1493 -473
- package/js/ln-table-coordinator/README.md +73 -0
- package/js/ln-table-coordinator/ln-table-coordinator.js +1 -0
- package/js/ln-table-coordinator/src/ln-table-coordinator.js +160 -0
- package/js/ln-tabs/README.md +221 -137
- package/js/ln-tabs/ln-tabs-dev.scss +18 -0
- package/js/ln-tabs/ln-tabs.js +1 -1
- package/js/ln-tabs/src/ln-tabs.js +41 -24
- package/js/ln-time/README.md +14 -0
- package/js/ln-time/ln-time.js +1 -1
- package/js/ln-time/src/ln-time.js +223 -192
- package/js/ln-toast/README.md +178 -122
- package/js/ln-toast/ln-toast.js +1 -15
- package/js/ln-toast/src/ln-toast.js +232 -210
- package/js/ln-toast/template.html +16 -12
- package/js/ln-toggle/README.md +61 -2
- package/js/ln-toggle/ln-toggle-dev.scss +13 -0
- package/js/ln-toggle/ln-toggle.js +1 -1
- package/js/ln-toggle/src/ln-toggle.js +56 -43
- package/js/ln-tooltip/README.md +95 -58
- package/js/ln-tooltip/ln-tooltip-dev.scss +9 -0
- package/js/ln-tooltip/ln-tooltip.js +1 -1
- package/js/ln-tooltip/src/ln-tooltip.js +45 -6
- package/js/ln-translations/README.md +118 -96
- package/js/ln-translations/ln-translations.js +1 -1
- package/js/ln-translations/src/ln-translations.js +10 -5
- package/js/ln-upload/README.md +85 -10
- package/js/ln-upload/ln-upload.js +1 -1
- package/js/ln-upload/src/ln-upload.js +26 -10
- package/js/ln-validate/README.md +72 -0
- package/js/ln-validate/ln-validate-dev.scss +15 -0
- package/js/ln-validate/ln-validate.js +1 -1
- package/js/ln-validate/src/ln-validate.js +64 -0
- package/package.json +61 -56
- package/scss/base/_global.scss +2 -2
- package/scss/base/_typography.scss +1 -2
- package/scss/components/_date.scss +1 -0
- package/scss/components/_dropdown.scss +0 -5
- package/scss/components/_editor.scss +5 -0
- package/scss/components/_filter.scss +26 -25
- package/scss/components/_form.scss +7 -0
- package/scss/components/_ln-table.scss +13 -3
- package/scss/components/_sort.scss +10 -0
- package/scss/components/_table.scss +36 -23
- package/scss/components/_toast.scss +68 -41
- package/scss/components/_toggle.scss +16 -0
- package/scss/config/_density.scss +205 -117
- package/scss/config/_icons.scss +10 -9
- package/scss/config/_tokens.scss +69 -47
- package/scss/config/mixins/_accordion.scss +2 -7
- package/scss/config/mixins/_alert.scss +4 -4
- package/scss/config/mixins/_breadcrumbs.scss +2 -2
- package/scss/config/mixins/_btn.scss +1 -1
- package/scss/config/mixins/_card.scss +89 -14
- package/scss/config/mixins/_collapsible.scss +3 -0
- package/scss/config/mixins/_colors.scss +1 -1
- package/scss/config/mixins/_diagnostics.scss +11 -0
- package/scss/config/mixins/_display.scss +1 -0
- package/scss/config/mixins/_dropdown.scss +3 -5
- package/scss/config/mixins/_editor.scss +124 -0
- package/scss/config/mixins/_empty-state.scss +7 -0
- package/scss/config/mixins/_filter.scss +3 -5
- package/scss/config/mixins/_footer.scss +1 -2
- package/scss/config/mixins/_form.scss +207 -21
- package/scss/config/mixins/_index.scss +2 -0
- package/scss/config/mixins/_ln-table.scss +41 -2
- package/scss/config/mixins/_modal.scss +149 -66
- package/scss/config/mixins/_nav.scss +3 -4
- package/scss/config/mixins/_popover.scss +39 -0
- package/scss/config/mixins/_sidebar.scss +1 -1
- package/scss/config/mixins/_sort.scss +42 -0
- package/scss/config/mixins/_table.scss +85 -60
- package/scss/config/mixins/_toast.scss +179 -152
- package/scss/config/mixins/_tooltip.scss +17 -7
- package/scss/config/mixins/_typography.scss +4 -2
- package/scss/ln-ashlar-dev.scss +27 -9
- package/scss/ln-ashlar.scss +7 -1
- package/js/ln-data-table/README.md +0 -110
- package/js/ln-data-table/ln-data-table.js +0 -1
- package/js/ln-data-table/ln-data-table.scss +0 -10
- package/js/ln-data-table/src/ln-data-table.js +0 -1087
- package/js/ln-icons/README.md +0 -88
- package/js/ln-icons/ln-icons.js +0 -1
- package/js/ln-table/ln-table-sort.js +0 -1
- package/js/ln-table/src/ln-table-sort.js +0 -156
|
@@ -1,350 +1,443 @@
|
|
|
1
|
-
import { dispatch, getLocale, registerComponent, interceptValueProperty } from '../../ln-core';
|
|
2
|
-
|
|
3
|
-
(function () {
|
|
4
|
-
const DOM_SELECTOR = 'data-ln-number';
|
|
5
|
-
const DOM_ATTRIBUTE = 'lnNumber';
|
|
6
|
-
|
|
7
|
-
if (window[DOM_ATTRIBUTE] !== undefined) return;
|
|
8
|
-
|
|
9
|
-
// ─── Formatter Cache ──────────────────────────────────────
|
|
10
|
-
|
|
11
|
-
const _formatters = {};
|
|
12
|
-
const _inputValueDesc = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
|
|
13
|
-
|
|
14
|
-
function _getFormatter(locale) {
|
|
15
|
-
if (!_formatters[locale]) {
|
|
16
|
-
const fmt = new Intl.NumberFormat(locale, { useGrouping: true });
|
|
17
|
-
const parts = fmt.formatToParts(1234.5);
|
|
18
|
-
let groupSep = '';
|
|
19
|
-
let decimalSep = '.';
|
|
20
|
-
for (let i = 0; i < parts.length; i++) {
|
|
21
|
-
if (parts[i].type === 'group') groupSep = parts[i].value;
|
|
22
|
-
if (parts[i].type === 'decimal') decimalSep = parts[i].value;
|
|
23
|
-
}
|
|
24
|
-
_formatters[locale] = { fmt: fmt, groupSep: groupSep, decimalSep: decimalSep };
|
|
25
|
-
}
|
|
26
|
-
return _formatters[locale];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function _formatNum(locale, num, maxDecimals) {
|
|
30
|
-
if (maxDecimals !== null) {
|
|
31
|
-
const max = parseInt(maxDecimals, 10);
|
|
32
|
-
const key = locale + '|d' + max;
|
|
33
|
-
if (!_formatters[key]) {
|
|
34
|
-
_formatters[key] = new Intl.NumberFormat(locale, { useGrouping: true, minimumFractionDigits: 0, maximumFractionDigits: max });
|
|
35
|
-
}
|
|
36
|
-
return _formatters[key].format(num);
|
|
37
|
-
}
|
|
38
|
-
return _getFormatter(locale).fmt.format(num);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// ─── Component ─────────────────────────────────────────────
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
dom
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
hidden
|
|
57
|
-
hidden
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
dom.
|
|
61
|
-
dom.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// ── Intercept programmatic value sets on visible input (2-way binding) ──
|
|
87
|
-
interceptValueProperty(dom, _inputValueDesc, {
|
|
88
|
-
get: function () {
|
|
89
|
-
return _inputValueDesc.get.call(dom);
|
|
90
|
-
},
|
|
91
|
-
set: function (val
|
|
92
|
-
if (
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
//
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
}
|
|
1
|
+
import { dispatch, getLocale, registerComponent, interceptValueProperty } from '../../ln-core';
|
|
2
|
+
|
|
3
|
+
(function () {
|
|
4
|
+
const DOM_SELECTOR = 'data-ln-number';
|
|
5
|
+
const DOM_ATTRIBUTE = 'lnNumber';
|
|
6
|
+
|
|
7
|
+
if (window[DOM_ATTRIBUTE] !== undefined) return;
|
|
8
|
+
|
|
9
|
+
// ─── Formatter Cache ──────────────────────────────────────
|
|
10
|
+
|
|
11
|
+
const _formatters = {};
|
|
12
|
+
const _inputValueDesc = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value');
|
|
13
|
+
|
|
14
|
+
function _getFormatter(locale) {
|
|
15
|
+
if (!_formatters[locale]) {
|
|
16
|
+
const fmt = new Intl.NumberFormat(locale, { useGrouping: true });
|
|
17
|
+
const parts = fmt.formatToParts(1234.5);
|
|
18
|
+
let groupSep = '';
|
|
19
|
+
let decimalSep = '.';
|
|
20
|
+
for (let i = 0; i < parts.length; i++) {
|
|
21
|
+
if (parts[i].type === 'group') groupSep = parts[i].value;
|
|
22
|
+
if (parts[i].type === 'decimal') decimalSep = parts[i].value;
|
|
23
|
+
}
|
|
24
|
+
_formatters[locale] = { fmt: fmt, groupSep: groupSep, decimalSep: decimalSep };
|
|
25
|
+
}
|
|
26
|
+
return _formatters[locale];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function _formatNum(locale, num, maxDecimals) {
|
|
30
|
+
if (maxDecimals !== null) {
|
|
31
|
+
const max = parseInt(maxDecimals, 10);
|
|
32
|
+
const key = locale + '|d' + max;
|
|
33
|
+
if (!_formatters[key]) {
|
|
34
|
+
_formatters[key] = new Intl.NumberFormat(locale, { useGrouping: true, minimumFractionDigits: 0, maximumFractionDigits: max });
|
|
35
|
+
}
|
|
36
|
+
return _formatters[key].format(num);
|
|
37
|
+
}
|
|
38
|
+
return _getFormatter(locale).fmt.format(num);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ─── Component ─────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
// ─── Component ─────────────────────────────────────────────
|
|
44
|
+
|
|
45
|
+
function _component(dom) {
|
|
46
|
+
if (dom[DOM_ATTRIBUTE]) return dom[DOM_ATTRIBUTE];
|
|
47
|
+
dom[DOM_ATTRIBUTE] = this;
|
|
48
|
+
this.dom = dom;
|
|
49
|
+
|
|
50
|
+
if (dom.tagName !== 'INPUT') {
|
|
51
|
+
this.isTextElement = true;
|
|
52
|
+
this._initTextElement();
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ── Create hidden input ─────────────────────────────
|
|
57
|
+
const hidden = document.createElement('input');
|
|
58
|
+
hidden.type = 'hidden';
|
|
59
|
+
hidden.name = dom.name;
|
|
60
|
+
dom.removeAttribute('name');
|
|
61
|
+
if (dom.hasAttribute('data-ln-fill-as')) {
|
|
62
|
+
hidden.setAttribute('data-ln-fill-as', dom.getAttribute('data-ln-fill-as'));
|
|
63
|
+
}
|
|
64
|
+
dom.type = 'text';
|
|
65
|
+
dom.setAttribute('inputmode', 'decimal');
|
|
66
|
+
dom.insertAdjacentElement('afterend', hidden);
|
|
67
|
+
this._hidden = hidden;
|
|
68
|
+
|
|
69
|
+
// ── Intercept programmatic value sets on hidden input ──
|
|
70
|
+
const self = this;
|
|
71
|
+
Object.defineProperty(hidden, 'value', {
|
|
72
|
+
get: function () {
|
|
73
|
+
return _inputValueDesc.get.call(hidden);
|
|
74
|
+
},
|
|
75
|
+
set: function (val) {
|
|
76
|
+
_inputValueDesc.set.call(hidden, val); // store raw natively
|
|
77
|
+
if (val !== '' && !isNaN(parseFloat(val))) {
|
|
78
|
+
self._setDisplayRaw(_formatNum(getLocale(self.dom), parseFloat(val), self.dom.getAttribute('data-ln-number-decimals')));
|
|
79
|
+
} else {
|
|
80
|
+
self._setDisplayRaw('');
|
|
81
|
+
}
|
|
82
|
+
self.dom.dispatchEvent(new Event('input', { bubbles: true })); // single ecosystem signal → _handleInput emits ln-number:input
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// ── Intercept programmatic value sets on visible input (2-way binding) ──
|
|
87
|
+
interceptValueProperty(dom, _inputValueDesc, {
|
|
88
|
+
get: function () {
|
|
89
|
+
return _inputValueDesc.get.call(dom);
|
|
90
|
+
},
|
|
91
|
+
set: function (val) {
|
|
92
|
+
if (val === '') {
|
|
93
|
+
self._setDisplayRaw('');
|
|
94
|
+
self._setHiddenRaw('');
|
|
95
|
+
dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const num = typeof val === 'number' ? val : parseFloat(String(val).replace(/[^\d.-]/g, ''));
|
|
99
|
+
if (isNaN(num)) {
|
|
100
|
+
self._setDisplayRaw(String(val));
|
|
101
|
+
self._setHiddenRaw('');
|
|
102
|
+
} else {
|
|
103
|
+
self._setHiddenRaw(num);
|
|
104
|
+
self._setDisplayRaw(_formatNum(getLocale(dom), num, dom.getAttribute('data-ln-number-decimals')));
|
|
105
|
+
}
|
|
106
|
+
dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// ── Bind input event ────────────────────────────────
|
|
111
|
+
this._onInput = function () {
|
|
112
|
+
self._handleInput();
|
|
113
|
+
};
|
|
114
|
+
dom.addEventListener('input', this._onInput);
|
|
115
|
+
|
|
116
|
+
// ── Bind paste event ────────────────────────────────
|
|
117
|
+
this._onPaste = function (e) {
|
|
118
|
+
e.preventDefault();
|
|
119
|
+
const pasted = (e.clipboardData || window.clipboardData).getData('text');
|
|
120
|
+
const info = _getFormatter(getLocale(dom));
|
|
121
|
+
const decSepEscaped = info.decimalSep.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
122
|
+
// Strip everything except digits, minus, and decimal separators
|
|
123
|
+
let cleaned = pasted.replace(new RegExp('[^0-9\\-' + decSepEscaped + '.]', 'g'), '');
|
|
124
|
+
// Strip group separators before normalizing decimal
|
|
125
|
+
if (info.groupSep) {
|
|
126
|
+
cleaned = cleaned.split(info.groupSep).join('');
|
|
127
|
+
}
|
|
128
|
+
// Normalize: if locale decimal is not '.', replace it
|
|
129
|
+
if (info.decimalSep !== '.') {
|
|
130
|
+
cleaned = cleaned.replace(info.decimalSep, '.');
|
|
131
|
+
}
|
|
132
|
+
const num = parseFloat(cleaned);
|
|
133
|
+
self.value = isNaN(num) ? NaN : num;
|
|
134
|
+
};
|
|
135
|
+
dom.addEventListener('paste', this._onPaste);
|
|
136
|
+
|
|
137
|
+
// ── Handle pre-filled value ─────────────────────────
|
|
138
|
+
const initial = dom.value;
|
|
139
|
+
if (initial !== '') {
|
|
140
|
+
const num = parseFloat(initial);
|
|
141
|
+
if (!isNaN(num)) {
|
|
142
|
+
this._setHiddenRaw(num);
|
|
143
|
+
this._setDisplayRaw(_formatNum(getLocale(dom), num, dom.getAttribute('data-ln-number-decimals')));
|
|
144
|
+
dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return this;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function _parseRawNumber(val) {
|
|
152
|
+
if (typeof val === 'number') return isNaN(val) ? null : val;
|
|
153
|
+
if (!val || typeof val !== 'string') return null;
|
|
154
|
+
let str = val.trim();
|
|
155
|
+
if (str === '') return null;
|
|
156
|
+
// Remove spaces/non-breaking spaces/currency symbols
|
|
157
|
+
str = str.replace(/[\s\u00A0$€£]/g, '');
|
|
158
|
+
|
|
159
|
+
// Handle "1.234,56" (DE/MK) vs "1,234.56" (EN)
|
|
160
|
+
if (str.indexOf(',') !== -1 && str.indexOf('.') !== -1) {
|
|
161
|
+
if (str.indexOf('.') < str.indexOf(',')) {
|
|
162
|
+
// DE/MK style: 1.234,56 -> 1234.56
|
|
163
|
+
str = str.replace(/\./g, '').replace(',', '.');
|
|
164
|
+
} else {
|
|
165
|
+
// EN style: 1,234.56 -> 1234.56
|
|
166
|
+
str = str.replace(/,/g, '');
|
|
167
|
+
}
|
|
168
|
+
} else if (str.indexOf(',') !== -1) {
|
|
169
|
+
// Only comma e.g. "1499,50" -> 1499.50
|
|
170
|
+
str = str.replace(',', '.');
|
|
171
|
+
}
|
|
172
|
+
// Strip any remaining invalid chars
|
|
173
|
+
str = str.replace(/[^\d.-]/g, '');
|
|
174
|
+
const num = parseFloat(str);
|
|
175
|
+
return isNaN(num) ? null : num;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
_component.prototype._initTextElement = function () {
|
|
179
|
+
const dom = this.dom;
|
|
180
|
+
let valAttr = dom.getAttribute('data-ln-value');
|
|
181
|
+
let numAttr = dom.getAttribute('data-ln-number');
|
|
182
|
+
|
|
183
|
+
let candidate = null;
|
|
184
|
+
if (valAttr !== null && valAttr !== '') {
|
|
185
|
+
candidate = valAttr;
|
|
186
|
+
} else if (numAttr !== null && numAttr !== '' && numAttr !== 'true') {
|
|
187
|
+
candidate = numAttr;
|
|
188
|
+
} else {
|
|
189
|
+
candidate = dom.textContent.trim();
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const num = _parseRawNumber(candidate);
|
|
193
|
+
if (num !== null) {
|
|
194
|
+
this._rawValue = num;
|
|
195
|
+
if (!dom.hasAttribute('data-ln-value')) {
|
|
196
|
+
dom.setAttribute('data-ln-value', String(num));
|
|
197
|
+
}
|
|
198
|
+
this._formatTextContent();
|
|
199
|
+
} else {
|
|
200
|
+
this._rawValue = null;
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
_component.prototype._formatTextContent = function () {
|
|
205
|
+
if (this._rawValue !== null && !isNaN(this._rawValue)) {
|
|
206
|
+
const decimals = this.dom.getAttribute('data-ln-number-decimals');
|
|
207
|
+
this.dom.textContent = _formatNum(getLocale(this.dom), this._rawValue, decimals);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
_component.prototype._handleInput = function () {
|
|
212
|
+
const dom = this.dom;
|
|
213
|
+
const info = _getFormatter(getLocale(dom));
|
|
214
|
+
const raw = _inputValueDesc.get.call(dom);
|
|
215
|
+
|
|
216
|
+
// Edge case: empty
|
|
217
|
+
if (raw === '') {
|
|
218
|
+
this._setHiddenRaw('');
|
|
219
|
+
dispatch(dom, 'ln-number:input', { value: NaN, formatted: '' });
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Edge case: just minus sign
|
|
224
|
+
if (raw === '-') {
|
|
225
|
+
this._setHiddenRaw('');
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Save cursor context: count digits to the left of cursor
|
|
230
|
+
const cursorPos = dom.selectionStart;
|
|
231
|
+
let digitsBeforeCursor = 0;
|
|
232
|
+
for (let i = 0; i < cursorPos; i++) {
|
|
233
|
+
if (/[0-9]/.test(raw[i])) digitsBeforeCursor++;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// Parse: strip group separators, normalize decimal
|
|
237
|
+
let cleaned = raw;
|
|
238
|
+
if (info.groupSep) {
|
|
239
|
+
cleaned = cleaned.split(info.groupSep).join('');
|
|
240
|
+
}
|
|
241
|
+
cleaned = cleaned.replace(info.decimalSep, '.');
|
|
242
|
+
|
|
243
|
+
// Edge case: trailing decimal separator (user about to type decimals)
|
|
244
|
+
if (raw.endsWith(info.decimalSep) || raw.endsWith('.')) {
|
|
245
|
+
const beforeDecimal = cleaned.replace(/\.$/, '');
|
|
246
|
+
const num = parseFloat(beforeDecimal);
|
|
247
|
+
if (!isNaN(num)) {
|
|
248
|
+
this._setHiddenRaw(num);
|
|
249
|
+
}
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Edge case: trailing zeros after decimal (user still typing)
|
|
254
|
+
const decimalIndex = cleaned.indexOf('.');
|
|
255
|
+
if (decimalIndex !== -1) {
|
|
256
|
+
const afterDecimal = cleaned.slice(decimalIndex + 1);
|
|
257
|
+
if (afterDecimal.endsWith('0')) {
|
|
258
|
+
const num = parseFloat(cleaned);
|
|
259
|
+
if (!isNaN(num)) {
|
|
260
|
+
this._setHiddenRaw(num);
|
|
261
|
+
}
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Enforce decimal limit
|
|
267
|
+
const maxDecimals = dom.getAttribute('data-ln-number-decimals');
|
|
268
|
+
if (maxDecimals !== null && decimalIndex !== -1) {
|
|
269
|
+
const allowed = parseInt(maxDecimals, 10);
|
|
270
|
+
const afterDec = cleaned.slice(decimalIndex + 1);
|
|
271
|
+
if (afterDec.length > allowed) {
|
|
272
|
+
cleaned = cleaned.slice(0, decimalIndex + 1 + allowed);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
const num = parseFloat(cleaned);
|
|
277
|
+
if (isNaN(num)) return;
|
|
278
|
+
|
|
279
|
+
// Enforce min/max
|
|
280
|
+
const minAttr = dom.getAttribute('data-ln-number-min');
|
|
281
|
+
const maxAttr = dom.getAttribute('data-ln-number-max');
|
|
282
|
+
if (minAttr !== null && num < parseFloat(minAttr)) return;
|
|
283
|
+
if (maxAttr !== null && num > parseFloat(maxAttr)) return;
|
|
284
|
+
|
|
285
|
+
// Format
|
|
286
|
+
let formatted;
|
|
287
|
+
if (maxDecimals !== null) {
|
|
288
|
+
formatted = _formatNum(getLocale(dom), num, maxDecimals);
|
|
289
|
+
} else {
|
|
290
|
+
// Preserve the user's decimal places
|
|
291
|
+
const userDecimals = decimalIndex !== -1 ? cleaned.slice(decimalIndex + 1).length : 0;
|
|
292
|
+
if (userDecimals > 0) {
|
|
293
|
+
const key = getLocale(dom) + '|u' + userDecimals;
|
|
294
|
+
if (!_formatters[key]) {
|
|
295
|
+
_formatters[key] = new Intl.NumberFormat(getLocale(dom), { useGrouping: true, minimumFractionDigits: userDecimals, maximumFractionDigits: userDecimals });
|
|
296
|
+
}
|
|
297
|
+
formatted = _formatters[key].format(num);
|
|
298
|
+
} else {
|
|
299
|
+
formatted = info.fmt.format(num);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
this._setDisplayRaw(formatted);
|
|
304
|
+
|
|
305
|
+
// Restore cursor position
|
|
306
|
+
let targetDigits = digitsBeforeCursor;
|
|
307
|
+
let newPos = 0;
|
|
308
|
+
for (let i = 0; i < formatted.length && targetDigits > 0; i++) {
|
|
309
|
+
newPos = i + 1;
|
|
310
|
+
if (/[0-9]/.test(formatted[i])) targetDigits--;
|
|
311
|
+
}
|
|
312
|
+
// If we didn't consume all digits, put cursor at end
|
|
313
|
+
if (targetDigits > 0) newPos = formatted.length;
|
|
314
|
+
dom.setSelectionRange(newPos, newPos);
|
|
315
|
+
|
|
316
|
+
// Update hidden input (bypass our setter to avoid feedback loop)
|
|
317
|
+
this._setHiddenRaw(num);
|
|
318
|
+
|
|
319
|
+
dispatch(dom, 'ln-number:input', { value: num, formatted: formatted });
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
_component.prototype._setHiddenRaw = function (val) {
|
|
323
|
+
if (this._hidden) {
|
|
324
|
+
_inputValueDesc.set.call(this._hidden, String(val));
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
_component.prototype._setDisplayRaw = function (str) {
|
|
329
|
+
if (this.isTextElement) {
|
|
330
|
+
this.dom.textContent = String(str);
|
|
331
|
+
} else {
|
|
332
|
+
_inputValueDesc.set.call(this.dom, String(str));
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
_component.prototype._displayFormatted = function (num) {
|
|
337
|
+
if (this.isTextElement) {
|
|
338
|
+
this._formatTextContent();
|
|
339
|
+
} else {
|
|
340
|
+
this._setDisplayRaw(_formatNum(getLocale(this.dom), num, this.dom.getAttribute('data-ln-number-decimals')));
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
|
|
344
|
+
// ─── Public API ───────────────────────────────────────────
|
|
345
|
+
|
|
346
|
+
Object.defineProperty(_component.prototype, 'value', {
|
|
347
|
+
get: function () {
|
|
348
|
+
if (this.isTextElement) {
|
|
349
|
+
return this._rawValue;
|
|
350
|
+
}
|
|
351
|
+
const raw = _inputValueDesc.get.call(this._hidden);
|
|
352
|
+
return raw === '' ? NaN : parseFloat(raw);
|
|
353
|
+
},
|
|
354
|
+
set: function (num) {
|
|
355
|
+
if (this.isTextElement) {
|
|
356
|
+
if (typeof num !== 'number' || isNaN(num)) {
|
|
357
|
+
this._rawValue = null;
|
|
358
|
+
this.dom.textContent = '';
|
|
359
|
+
} else {
|
|
360
|
+
this._rawValue = num;
|
|
361
|
+
this.dom.setAttribute('data-ln-value', String(num));
|
|
362
|
+
this._formatTextContent();
|
|
363
|
+
}
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (typeof num !== 'number' || isNaN(num)) {
|
|
368
|
+
this._setDisplayRaw('');
|
|
369
|
+
this._setHiddenRaw('');
|
|
370
|
+
this.dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
this._setHiddenRaw(num);
|
|
374
|
+
this._setDisplayRaw(_formatNum(getLocale(this.dom), num, this.dom.getAttribute('data-ln-number-decimals')));
|
|
375
|
+
this.dom.dispatchEvent(new Event('input', { bubbles: true }));
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
Object.defineProperty(_component.prototype, 'formatted', {
|
|
380
|
+
get: function () {
|
|
381
|
+
if (this.isTextElement) {
|
|
382
|
+
return this.dom.textContent;
|
|
383
|
+
}
|
|
384
|
+
return _inputValueDesc.get.call(this.dom);
|
|
385
|
+
}
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
_component.prototype.destroy = function () {
|
|
389
|
+
if (!this.dom[DOM_ATTRIBUTE]) return;
|
|
390
|
+
if (!this.isTextElement) {
|
|
391
|
+
this.dom.removeEventListener('input', this._onInput);
|
|
392
|
+
this.dom.removeEventListener('paste', this._onPaste);
|
|
393
|
+
if (this._hidden) {
|
|
394
|
+
this.dom.name = this._hidden.name;
|
|
395
|
+
this._hidden.remove();
|
|
396
|
+
}
|
|
397
|
+
this.dom.type = 'number';
|
|
398
|
+
this.dom.removeAttribute('inputmode');
|
|
399
|
+
}
|
|
400
|
+
dispatch(this.dom, 'ln-number:destroyed', { target: this.dom });
|
|
401
|
+
delete this.dom[DOM_ATTRIBUTE];
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
// ─── Locale Observer ──────────────────────────────────────
|
|
405
|
+
|
|
406
|
+
function _localeObserver() {
|
|
407
|
+
new MutationObserver(function () {
|
|
408
|
+
const els = document.querySelectorAll('[' + DOM_SELECTOR + ']');
|
|
409
|
+
for (let i = 0; i < els.length; i++) {
|
|
410
|
+
const inst = els[i][DOM_ATTRIBUTE];
|
|
411
|
+
if (inst) {
|
|
412
|
+
if (inst.isTextElement) {
|
|
413
|
+
inst._formatTextContent();
|
|
414
|
+
} else if (!isNaN(inst.value)) {
|
|
415
|
+
inst._displayFormatted(inst.value);
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
}).observe(document.documentElement, { attributes: true, attributeFilter: ['lang'], subtree: true });
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// ─── Init ──────────────────────────────────────────────────
|
|
423
|
+
|
|
424
|
+
registerComponent(DOM_SELECTOR, DOM_ATTRIBUTE, _component, 'ln-number', {
|
|
425
|
+
extraAttributes: [
|
|
426
|
+
'data-ln-value',
|
|
427
|
+
'data-ln-number-decimals',
|
|
428
|
+
'data-ln-number-min',
|
|
429
|
+
'data-ln-number-max',
|
|
430
|
+
'lang'
|
|
431
|
+
],
|
|
432
|
+
onAttributeChange: function (el) {
|
|
433
|
+
const inst = el[DOM_ATTRIBUTE];
|
|
434
|
+
if (!inst) return;
|
|
435
|
+
if (inst.isTextElement) {
|
|
436
|
+
inst._initTextElement();
|
|
437
|
+
} else if (!isNaN(inst.value)) {
|
|
438
|
+
inst._displayFormatted(inst.value);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
_localeObserver();
|
|
443
|
+
})();
|