juxscript 1.1.240 → 1.1.244

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.
Files changed (297) hide show
  1. package/index.js +7 -137
  2. package/lib/components/dataframe.ts +0 -569
  3. package/lib/components/include.ts +229 -229
  4. package/lib/components/tag.ts +68 -0
  5. package/lib/styles/shadcn.css +17 -5
  6. package/lib/utils/idgen.ts +6 -0
  7. package/package.json +5 -6
  8. package/index.d.ts +0 -239
  9. package/index.d.ts.map +0 -1
  10. package/lib/components/alert.d.ts +0 -36
  11. package/lib/components/alert.d.ts.map +0 -1
  12. package/lib/components/alert.js +0 -172
  13. package/lib/components/alert.ts +0 -219
  14. package/lib/components/app.d.ts +0 -89
  15. package/lib/components/app.d.ts.map +0 -1
  16. package/lib/components/app.js +0 -175
  17. package/lib/components/app.ts +0 -247
  18. package/lib/components/badge.d.ts +0 -26
  19. package/lib/components/badge.d.ts.map +0 -1
  20. package/lib/components/badge.js +0 -91
  21. package/lib/components/badge.ts +0 -118
  22. package/lib/components/base/Animations.d.ts +0 -36
  23. package/lib/components/base/Animations.d.ts.map +0 -1
  24. package/lib/components/base/Animations.js +0 -70
  25. package/lib/components/base/Animations.ts +0 -112
  26. package/lib/components/base/BaseComponent.d.ts +0 -294
  27. package/lib/components/base/BaseComponent.d.ts.map +0 -1
  28. package/lib/components/base/BaseComponent.js +0 -735
  29. package/lib/components/base/BaseComponent.ts +0 -884
  30. package/lib/components/base/FormInput.d.ts +0 -77
  31. package/lib/components/base/FormInput.d.ts.map +0 -1
  32. package/lib/components/base/FormInput.js +0 -171
  33. package/lib/components/base/FormInput.ts +0 -237
  34. package/lib/components/blueprint.d.ts +0 -40
  35. package/lib/components/blueprint.d.ts.map +0 -1
  36. package/lib/components/blueprint.js +0 -327
  37. package/lib/components/button.d.ts +0 -70
  38. package/lib/components/button.d.ts.map +0 -1
  39. package/lib/components/button.js +0 -177
  40. package/lib/components/button.ts +0 -237
  41. package/lib/components/card.d.ts +0 -35
  42. package/lib/components/card.d.ts.map +0 -1
  43. package/lib/components/card.js +0 -130
  44. package/lib/components/card.ts +0 -177
  45. package/lib/components/chart.d.ts +0 -49
  46. package/lib/components/chart.d.ts.map +0 -1
  47. package/lib/components/chart.js +0 -205
  48. package/lib/components/chart.ts +0 -254
  49. package/lib/components/checkbox.d.ts +0 -33
  50. package/lib/components/checkbox.d.ts.map +0 -1
  51. package/lib/components/checkbox.js +0 -202
  52. package/lib/components/checkbox.ts +0 -260
  53. package/lib/components/code.d.ts +0 -52
  54. package/lib/components/code.d.ts.map +0 -1
  55. package/lib/components/code.js +0 -201
  56. package/lib/components/code.ts +0 -260
  57. package/lib/components/container.d.ts +0 -60
  58. package/lib/components/container.d.ts.map +0 -1
  59. package/lib/components/container.js +0 -195
  60. package/lib/components/container.ts +0 -259
  61. package/lib/components/data.d.ts +0 -36
  62. package/lib/components/data.d.ts.map +0 -1
  63. package/lib/components/data.js +0 -110
  64. package/lib/components/data.ts +0 -135
  65. package/lib/components/dataframe/DataFrameSource.d.ts +0 -118
  66. package/lib/components/dataframe/DataFrameSource.d.ts.map +0 -1
  67. package/lib/components/dataframe/DataFrameSource.js +0 -421
  68. package/lib/components/dataframe/DataFrameSource.ts +0 -532
  69. package/lib/components/dataframe/ImportSettingsModal.d.ts +0 -60
  70. package/lib/components/dataframe/ImportSettingsModal.d.ts.map +0 -1
  71. package/lib/components/dataframe/ImportSettingsModal.js +0 -442
  72. package/lib/components/dataframe/ImportSettingsModal.ts +0 -531
  73. package/lib/components/dataframe.d.ts +0 -110
  74. package/lib/components/dataframe.d.ts.map +0 -1
  75. package/lib/components/dataframe.js +0 -470
  76. package/lib/components/datepicker.d.ts +0 -40
  77. package/lib/components/datepicker.d.ts.map +0 -1
  78. package/lib/components/datepicker.js +0 -193
  79. package/lib/components/datepicker.ts +0 -251
  80. package/lib/components/dialog.d.ts +0 -39
  81. package/lib/components/dialog.d.ts.map +0 -1
  82. package/lib/components/dialog.js +0 -131
  83. package/lib/components/dialog.ts +0 -178
  84. package/lib/components/divider.d.ts +0 -31
  85. package/lib/components/divider.d.ts.map +0 -1
  86. package/lib/components/divider.js +0 -72
  87. package/lib/components/divider.ts +0 -104
  88. package/lib/components/dropdown-menu.d.ts +0 -42
  89. package/lib/components/dropdown-menu.d.ts.map +0 -1
  90. package/lib/components/dropdown-menu.js +0 -177
  91. package/lib/components/dropdown-menu.ts +0 -214
  92. package/lib/components/dropdown.d.ts +0 -41
  93. package/lib/components/dropdown.d.ts.map +0 -1
  94. package/lib/components/dropdown.js +0 -136
  95. package/lib/components/dropdown.ts +0 -188
  96. package/lib/components/element.d.ts +0 -51
  97. package/lib/components/element.d.ts.map +0 -1
  98. package/lib/components/element.js +0 -209
  99. package/lib/components/element.ts +0 -271
  100. package/lib/components/event-chain.d.ts +0 -9
  101. package/lib/components/event-chain.d.ts.map +0 -1
  102. package/lib/components/event-chain.js +0 -33
  103. package/lib/components/fileupload.d.ts +0 -98
  104. package/lib/components/fileupload.d.ts.map +0 -1
  105. package/lib/components/fileupload.js +0 -351
  106. package/lib/components/fileupload.ts +0 -449
  107. package/lib/components/grid.d.ts +0 -88
  108. package/lib/components/grid.d.ts.map +0 -1
  109. package/lib/components/grid.js +0 -208
  110. package/lib/components/grid.ts +0 -295
  111. package/lib/components/heading.d.ts +0 -25
  112. package/lib/components/heading.d.ts.map +0 -1
  113. package/lib/components/heading.js +0 -83
  114. package/lib/components/heading.ts +0 -113
  115. package/lib/components/helpers.d.ts +0 -9
  116. package/lib/components/helpers.d.ts.map +0 -1
  117. package/lib/components/helpers.js +0 -30
  118. package/lib/components/helpers.ts +0 -41
  119. package/lib/components/hero.d.ts +0 -60
  120. package/lib/components/hero.d.ts.map +0 -1
  121. package/lib/components/hero.js +0 -239
  122. package/lib/components/hero.ts +0 -302
  123. package/lib/components/history/StateHistory.d.ts +0 -91
  124. package/lib/components/history/StateHistory.d.ts.map +0 -1
  125. package/lib/components/history/StateHistory.js +0 -154
  126. package/lib/components/history/StateHistory.ts +0 -200
  127. package/lib/components/icon.d.ts +0 -36
  128. package/lib/components/icon.d.ts.map +0 -1
  129. package/lib/components/icon.js +0 -135
  130. package/lib/components/icon.ts +0 -182
  131. package/lib/components/icons.d.ts +0 -25
  132. package/lib/components/icons.d.ts.map +0 -1
  133. package/lib/components/icons.js +0 -440
  134. package/lib/components/icons.ts +0 -464
  135. package/lib/components/image.d.ts +0 -42
  136. package/lib/components/image.d.ts.map +0 -1
  137. package/lib/components/image.js +0 -204
  138. package/lib/components/image.ts +0 -260
  139. package/lib/components/include.d.ts +0 -86
  140. package/lib/components/include.d.ts.map +0 -1
  141. package/lib/components/include.js +0 -238
  142. package/lib/components/input.d.ts +0 -85
  143. package/lib/components/input.d.ts.map +0 -1
  144. package/lib/components/input.js +0 -362
  145. package/lib/components/input.ts +0 -473
  146. package/lib/components/layer.d.ts +0 -72
  147. package/lib/components/layer.d.ts.map +0 -1
  148. package/lib/components/layer.js +0 -219
  149. package/lib/components/layer.ts +0 -304
  150. package/lib/components/link.d.ts +0 -41
  151. package/lib/components/link.d.ts.map +0 -1
  152. package/lib/components/link.js +0 -216
  153. package/lib/components/link.ts +0 -268
  154. package/lib/components/list.d.ts +0 -83
  155. package/lib/components/list.d.ts.map +0 -1
  156. package/lib/components/list.js +0 -314
  157. package/lib/components/list.ts +0 -423
  158. package/lib/components/loading.d.ts +0 -25
  159. package/lib/components/loading.d.ts.map +0 -1
  160. package/lib/components/loading.js +0 -76
  161. package/lib/components/loading.ts +0 -104
  162. package/lib/components/menu.d.ts +0 -38
  163. package/lib/components/menu.d.ts.map +0 -1
  164. package/lib/components/menu.js +0 -205
  165. package/lib/components/menu.ts +0 -279
  166. package/lib/components/modal.d.ts +0 -97
  167. package/lib/components/modal.d.ts.map +0 -1
  168. package/lib/components/modal.js +0 -463
  169. package/lib/components/modal.ts +0 -576
  170. package/lib/components/nav.d.ts +0 -46
  171. package/lib/components/nav.d.ts.map +0 -1
  172. package/lib/components/nav.js +0 -193
  173. package/lib/components/nav.ts +0 -261
  174. package/lib/components/paragraph.d.ts +0 -30
  175. package/lib/components/paragraph.d.ts.map +0 -1
  176. package/lib/components/paragraph.js +0 -93
  177. package/lib/components/paragraph.ts +0 -123
  178. package/lib/components/pen.d.ts +0 -125
  179. package/lib/components/pen.d.ts.map +0 -1
  180. package/lib/components/pen.js +0 -443
  181. package/lib/components/pen.ts +0 -567
  182. package/lib/components/progress.d.ts +0 -40
  183. package/lib/components/progress.d.ts.map +0 -1
  184. package/lib/components/progress.js +0 -116
  185. package/lib/components/progress.ts +0 -163
  186. package/lib/components/radio.d.ts +0 -43
  187. package/lib/components/radio.d.ts.map +0 -1
  188. package/lib/components/radio.js +0 -226
  189. package/lib/components/radio.ts +0 -303
  190. package/lib/components/registry.d.ts +0 -34
  191. package/lib/components/registry.d.ts.map +0 -1
  192. package/lib/components/registry.js +0 -163
  193. package/lib/components/registry.ts +0 -193
  194. package/lib/components/req.d.ts +0 -155
  195. package/lib/components/req.d.ts.map +0 -1
  196. package/lib/components/req.js +0 -253
  197. package/lib/components/req.ts +0 -303
  198. package/lib/components/script.d.ts +0 -14
  199. package/lib/components/script.d.ts.map +0 -1
  200. package/lib/components/script.js +0 -33
  201. package/lib/components/script.ts +0 -41
  202. package/lib/components/select.d.ts +0 -42
  203. package/lib/components/select.d.ts.map +0 -1
  204. package/lib/components/select.js +0 -209
  205. package/lib/components/select.ts +0 -281
  206. package/lib/components/sidebar.d.ts +0 -59
  207. package/lib/components/sidebar.d.ts.map +0 -1
  208. package/lib/components/sidebar.js +0 -298
  209. package/lib/components/sidebar.ts +0 -395
  210. package/lib/components/stack/BaseStack.d.ts +0 -65
  211. package/lib/components/stack/BaseStack.d.ts.map +0 -1
  212. package/lib/components/stack/BaseStack.js +0 -274
  213. package/lib/components/stack/BaseStack.ts +0 -328
  214. package/lib/components/stack/HStack.d.ts +0 -18
  215. package/lib/components/stack/HStack.d.ts.map +0 -1
  216. package/lib/components/stack/HStack.js +0 -22
  217. package/lib/components/stack/HStack.ts +0 -25
  218. package/lib/components/stack/VStack.d.ts +0 -19
  219. package/lib/components/stack/VStack.d.ts.map +0 -1
  220. package/lib/components/stack/VStack.js +0 -23
  221. package/lib/components/stack/VStack.ts +0 -26
  222. package/lib/components/stack/ZStack.d.ts +0 -18
  223. package/lib/components/stack/ZStack.d.ts.map +0 -1
  224. package/lib/components/stack/ZStack.js +0 -22
  225. package/lib/components/stack/ZStack.ts +0 -25
  226. package/lib/components/style.d.ts +0 -14
  227. package/lib/components/style.d.ts.map +0 -1
  228. package/lib/components/style.js +0 -33
  229. package/lib/components/style.ts +0 -41
  230. package/lib/components/switch.d.ts +0 -34
  231. package/lib/components/switch.d.ts.map +0 -1
  232. package/lib/components/switch.js +0 -209
  233. package/lib/components/switch.ts +0 -272
  234. package/lib/components/table.d.ts +0 -137
  235. package/lib/components/table.d.ts.map +0 -1
  236. package/lib/components/table.js +0 -1019
  237. package/lib/components/table.ts +0 -1225
  238. package/lib/components/tabs.d.ts +0 -53
  239. package/lib/components/tabs.d.ts.map +0 -1
  240. package/lib/components/tabs.js +0 -275
  241. package/lib/components/tabs.ts +0 -349
  242. package/lib/components/theme-toggle.d.ts +0 -45
  243. package/lib/components/theme-toggle.d.ts.map +0 -1
  244. package/lib/components/theme-toggle.js +0 -218
  245. package/lib/components/theme-toggle.ts +0 -297
  246. package/lib/components/tooltip.d.ts +0 -31
  247. package/lib/components/tooltip.d.ts.map +0 -1
  248. package/lib/components/tooltip.js +0 -112
  249. package/lib/components/tooltip.ts +0 -148
  250. package/lib/components/watcher.d.ts +0 -195
  251. package/lib/components/watcher.d.ts.map +0 -1
  252. package/lib/components/watcher.js +0 -241
  253. package/lib/components/watcher.ts +0 -261
  254. package/lib/components/write.d.ts +0 -107
  255. package/lib/components/write.d.ts.map +0 -1
  256. package/lib/components/write.js +0 -222
  257. package/lib/components/write.ts +0 -272
  258. package/lib/data/DataPipeline.d.ts +0 -113
  259. package/lib/data/DataPipeline.d.ts.map +0 -1
  260. package/lib/data/DataPipeline.js +0 -359
  261. package/lib/data/DataPipeline.ts +0 -452
  262. package/lib/facades/dataframe.jux +0 -0
  263. package/lib/globals.d.ts +0 -21
  264. package/lib/reactivity/state.d.ts +0 -36
  265. package/lib/reactivity/state.d.ts.map +0 -1
  266. package/lib/reactivity/state.js +0 -67
  267. package/lib/reactivity/state.ts +0 -78
  268. package/lib/storage/DataFrame.d.ts +0 -284
  269. package/lib/storage/DataFrame.d.ts.map +0 -1
  270. package/lib/storage/DataFrame.js +0 -1022
  271. package/lib/storage/DataFrame.ts +0 -1195
  272. package/lib/storage/DataFrameSource.d.ts +0 -158
  273. package/lib/storage/DataFrameSource.d.ts.map +0 -1
  274. package/lib/storage/DataFrameSource.js +0 -409
  275. package/lib/storage/DataFrameSource.ts +0 -556
  276. package/lib/storage/FileStorage.d.ts +0 -53
  277. package/lib/storage/FileStorage.d.ts.map +0 -1
  278. package/lib/storage/FileStorage.js +0 -80
  279. package/lib/storage/FileStorage.ts +0 -95
  280. package/lib/storage/IndexedDBDriver.d.ts +0 -75
  281. package/lib/storage/IndexedDBDriver.d.ts.map +0 -1
  282. package/lib/storage/IndexedDBDriver.js +0 -177
  283. package/lib/storage/IndexedDBDriver.ts +0 -226
  284. package/lib/storage/TabularDriver.d.ts +0 -118
  285. package/lib/storage/TabularDriver.d.ts.map +0 -1
  286. package/lib/storage/TabularDriver.js +0 -731
  287. package/lib/storage/TabularDriver.ts +0 -874
  288. package/lib/utils/codeparser.d.ts +0 -29
  289. package/lib/utils/codeparser.d.ts.map +0 -1
  290. package/lib/utils/codeparser.js +0 -409
  291. package/lib/utils/fetch.d.ts +0 -176
  292. package/lib/utils/fetch.d.ts.map +0 -1
  293. package/lib/utils/fetch.js +0 -427
  294. package/lib/utils/formatId.d.ts +0 -16
  295. package/lib/utils/formatId.d.ts.map +0 -1
  296. package/lib/utils/formatId.js +0 -27
  297. package/lib/utils/path-resolver.js +0 -23
@@ -1,351 +0,0 @@
1
- import { BaseComponent } from './base/BaseComponent.js';
2
- import { renderIcon } from './icons.js';
3
- import { formatIdAsLabel } from '../utils/formatId.js';
4
- import { TabularDriver } from '../storage/TabularDriver.js';
5
- // Event definitions
6
- const TRIGGER_EVENTS = [];
7
- const CALLBACK_EVENTS = ['change', 'filesSelected', 'clear', 'stored'];
8
- export class FileUpload extends BaseComponent {
9
- constructor(id, options = {}) {
10
- super(id, {
11
- visible: true,
12
- disabled: options.disabled ?? false,
13
- loading: false,
14
- class: options.class ?? '',
15
- style: options.style ?? '',
16
- attributes: {},
17
- label: options.label ?? formatIdAsLabel(id),
18
- required: options.required ?? false,
19
- name: options.name ?? id,
20
- errorMessage: undefined,
21
- files: [],
22
- accept: options.accept ?? '',
23
- multiple: options.multiple ?? false,
24
- icon: options.icon ?? 'upload',
25
- variant: options.variant ?? 'outline',
26
- showFileList: options.showFileList ?? true,
27
- maxFiles: options.maxFiles ?? 10,
28
- maxFileSize: options.maxFileSize ?? 10,
29
- });
30
- this._fileListElement = null;
31
- this._storage = null;
32
- /** IndexedDB caching */
33
- this._cacheEnabled = false;
34
- this._cacheDriver = null;
35
- this._cacheDbName = 'jux-dataframes';
36
- this._cacheStoreName = 'frames';
37
- this._cacheKeyPrefix = '';
38
- this._storageKeys = new Map();
39
- this._lastStorageKey = null;
40
- this._cachedDataFrames = new Map();
41
- if (options.onValidate) {
42
- this._onValidate = options.onValidate;
43
- }
44
- this._storage = options.storage ?? null;
45
- this._metadata = options.metadata;
46
- }
47
- getTriggerEvents() {
48
- return TRIGGER_EVENTS;
49
- }
50
- getCallbackEvents() {
51
- return CALLBACK_EVENTS;
52
- }
53
- /* ═════════════════════════════════════════════════════════════════
54
- * FLUENT API
55
- * ═════════════════════════════════════════════════════════════════ */
56
- accept(value) {
57
- this.state.accept = value;
58
- return this;
59
- }
60
- multiple(value) {
61
- this.state.multiple = value;
62
- return this;
63
- }
64
- icon(value) {
65
- this.state.icon = value;
66
- return this;
67
- }
68
- variant(value) {
69
- this.state.variant = value;
70
- return this;
71
- }
72
- storage(store, metadata) {
73
- this._storage = store;
74
- this._metadata = metadata;
75
- return this;
76
- }
77
- /**
78
- * Enable IndexedDB caching of uploaded files.
79
- * After upload, the file is parsed and stored as a DataFrame.
80
- * The storage key is available via .storageKey and a 'stored' event fires.
81
- *
82
- * Usage:
83
- * jux.fileUpload('my-upload', { accept: '.csv' })
84
- * .cache() // enable with defaults
85
- * .cache({ prefix: 'raw/' }) // key prefix
86
- * .cache({ dbName: 'my-db' }) // custom DB
87
- *
88
- * upload.bind('stored', (key, df) => {
89
- * await data().fromStorage(key).into(myTable);
90
- * });
91
- */
92
- cache(options = {}) {
93
- this._cacheEnabled = options.enabled ?? true;
94
- if (options.dbName)
95
- this._cacheDbName = options.dbName;
96
- if (options.storeName)
97
- this._cacheStoreName = options.storeName;
98
- if (options.prefix)
99
- this._cacheKeyPrefix = options.prefix;
100
- if (this._cacheEnabled && !this._cacheDriver) {
101
- this._cacheDriver = new TabularDriver(this._cacheDbName, this._cacheStoreName);
102
- }
103
- return this;
104
- }
105
- /* ═════════════════════════════════════════════════════════════════
106
- * STORAGE KEY ACCESSORS
107
- * ═════════════════════════════════════════════════════════════════ */
108
- /** The IndexedDB key for the most recently cached upload, or null. */
109
- get storageKey() {
110
- return this._lastStorageKey;
111
- }
112
- /** Map of filename → storage key for all cached files this session. */
113
- get storageKeys() {
114
- return this._storageKeys;
115
- }
116
- /** Get the storage key for a specific filename. */
117
- storageKeyFor(filename) {
118
- return this._storageKeys.get(filename) ?? null;
119
- }
120
- /** The cached DataFrame for the most recent upload (after 'stored' fires). */
121
- get cachedDf() {
122
- if (!this._lastStorageKey)
123
- return null;
124
- return this._cachedDataFrames.get(this._lastStorageKey) ?? null;
125
- }
126
- clear() {
127
- this.state.files = [];
128
- if (this._inputElement) {
129
- this._inputElement.value = '';
130
- }
131
- if (this._fileListElement) {
132
- this._fileListElement.innerHTML = '';
133
- }
134
- this._lastStorageKey = null;
135
- this._triggerCallback('clear', null, null, this);
136
- return this;
137
- }
138
- clearFiles() {
139
- this.state.files = [];
140
- this._updateFileList();
141
- this._triggerCallback('change', [], null, this);
142
- return this;
143
- }
144
- /* ═════════════════════════════════════════════════════════════════
145
- * FORM INPUT IMPLEMENTATION
146
- * ═════════════════════════════════════════════════════════════════ */
147
- getValue() {
148
- return this.state.files;
149
- }
150
- setValue(files) {
151
- this.state.files = files;
152
- this._updateFileList();
153
- return this;
154
- }
155
- validate() {
156
- this._hasBeenValidated = true;
157
- const files = this.getValue();
158
- const result = this._validateValue(files);
159
- if (result === true) {
160
- this._clearError();
161
- return true;
162
- }
163
- else {
164
- this._showError(result);
165
- return false;
166
- }
167
- }
168
- isValid() {
169
- const files = this.getValue();
170
- return this._validateValue(files) === true;
171
- }
172
- _validateValue(files) {
173
- const { required } = this.state;
174
- if (required && files.length === 0) {
175
- return 'Please select at least one file';
176
- }
177
- if (this._onValidate) {
178
- const result = this._onValidate(files);
179
- if (result !== true) {
180
- return result || 'Invalid files';
181
- }
182
- }
183
- return true;
184
- }
185
- _updateFileList() {
186
- if (!this._fileListElement)
187
- return;
188
- this._fileListElement.innerHTML = '';
189
- if (this.state.files.length === 0) {
190
- return;
191
- }
192
- this.state.files.forEach((file, index) => {
193
- const fileItem = document.createElement('div');
194
- fileItem.className = 'jux-fileupload-item';
195
- fileItem.innerHTML = `
196
- <span class="jux-fileupload-filename">${file.name}</span>
197
- <span class="jux-fileupload-filesize">${this._formatFileSize(file.size)}</span>
198
- <button class="jux-fileupload-remove" data-index="${index}">×</button>
199
- `;
200
- const removeBtn = fileItem.querySelector('.jux-fileupload-remove');
201
- removeBtn?.addEventListener('click', () => {
202
- this.state.files = this.state.files.filter((_, i) => i !== index);
203
- this._updateFileList();
204
- this._triggerCallback('change', this.state.files, null, this);
205
- });
206
- this._fileListElement.appendChild(fileItem);
207
- });
208
- }
209
- _formatFileSize(bytes) {
210
- if (bytes === 0)
211
- return '0 Bytes';
212
- const k = 1024;
213
- const sizes = ['Bytes', 'KB', 'MB', 'GB'];
214
- const i = Math.floor(Math.log(bytes) / Math.log(k));
215
- return Math.round(bytes / Math.pow(k, i) * 100) / 100 + ' ' + sizes[i];
216
- }
217
- /* ═════════════════════════════════════════════════════════════════
218
- * INTERNAL — CACHE FILE TO INDEXEDDB
219
- * ═════════════════════════════════════════════════════════════════ */
220
- async _cacheFile(file) {
221
- if (!this._cacheEnabled || !this._cacheDriver)
222
- return;
223
- try {
224
- const key = this._cacheKeyPrefix + file.name;
225
- let df;
226
- const isExcel = /\.(xlsx?|xls)$/i.test(file.name);
227
- if (isExcel) {
228
- const sheets = await this._cacheDriver.streamFileMultiSheet(file, {});
229
- const sheetNames = Object.keys(sheets);
230
- if (sheetNames.length === 0)
231
- return;
232
- df = sheets[sheetNames[0]];
233
- }
234
- else {
235
- const text = await file.text();
236
- df = this._cacheDriver.parseCSV(text, {
237
- autoDetectDelimiter: true,
238
- hasHeader: true
239
- });
240
- }
241
- await this._cacheDriver.store(key, df, {
242
- source: file.name,
243
- size: file.size,
244
- type: file.type,
245
- cachedAt: new Date().toISOString(),
246
- ...this._metadata
247
- });
248
- this._lastStorageKey = key;
249
- this._storageKeys.set(file.name, key);
250
- this._cachedDataFrames.set(key, df);
251
- this._triggerCallback('stored', key, null, this);
252
- }
253
- catch (err) {
254
- console.warn(`[FileUpload] Failed to cache ${file.name}:`, err.message);
255
- }
256
- }
257
- /* ═════════════════════════════════════════════════════════════════
258
- * RENDER
259
- * ═════════════════════════════════════════════════════════════════ */
260
- update(prop, value) {
261
- // No reactive updates needed
262
- }
263
- render(targetId) {
264
- const container = this._setupContainer(targetId);
265
- const { label, accept, multiple, icon, variant, showFileList, style, class: className } = this.state;
266
- const wrapper = document.createElement('div');
267
- wrapper.className = 'jux-fileupload';
268
- wrapper.id = this._id;
269
- if (className)
270
- wrapper.className += ` ${className}`;
271
- if (style)
272
- wrapper.setAttribute('style', style);
273
- const fileInput = document.createElement('input');
274
- fileInput.type = 'file';
275
- fileInput.accept = accept;
276
- fileInput.multiple = multiple;
277
- fileInput.style.display = 'none';
278
- fileInput.id = `${this._id}-input`;
279
- this._inputElement = fileInput;
280
- const btn = document.createElement('button');
281
- btn.className = `jux-fileupload-button jux-button-${variant}`;
282
- btn.type = 'button';
283
- if (icon) {
284
- const iconEl = document.createElement('span');
285
- iconEl.className = 'jux-fileupload-icon';
286
- iconEl.appendChild(renderIcon(icon));
287
- btn.appendChild(iconEl);
288
- }
289
- const labelSpan = document.createElement('span');
290
- labelSpan.textContent = label;
291
- btn.appendChild(labelSpan);
292
- const buttonContainer = document.createElement('div');
293
- buttonContainer.className = 'jux-fileupload-button-container';
294
- buttonContainer.appendChild(fileInput);
295
- buttonContainer.appendChild(btn);
296
- wrapper.appendChild(buttonContainer);
297
- if (showFileList) {
298
- const fileList = document.createElement('div');
299
- fileList.className = 'jux-fileupload-filelist';
300
- this._fileListElement = fileList;
301
- wrapper.appendChild(fileList);
302
- }
303
- wrapper.appendChild(this._renderError());
304
- btn.addEventListener('click', () => fileInput.click());
305
- // Wire up file input change — with caching
306
- fileInput.addEventListener('change', async (e) => {
307
- const files = Array.from(fileInput.files || []);
308
- this.state.files = files;
309
- this._updateFileList();
310
- this._clearError();
311
- this._triggerCallback('change', files, e, this);
312
- this._triggerCallback('filesSelected', files, e, this);
313
- if (this._storage && files.length > 0) {
314
- this._storage.storeAll(files, this._metadata).then((stored) => {
315
- this._triggerCallback('stored', stored, e, this);
316
- }).catch((err) => {
317
- console.error('[FileUpload] Storage error:', err);
318
- });
319
- }
320
- // Cache to IndexedDB as parsed DataFrames
321
- if (this._cacheEnabled && files.length > 0) {
322
- for (const file of files) {
323
- await this._cacheFile(file);
324
- }
325
- }
326
- });
327
- this._wireStandardEvents(wrapper);
328
- fileInput.addEventListener('blur', () => {
329
- if (this._hasBeenValidated) {
330
- this.validate();
331
- }
332
- });
333
- const labelSync = this._syncBindings.find(b => b.property === 'label');
334
- if (labelSync) {
335
- const transform = labelSync.toComponent || ((v) => String(v));
336
- labelSync.stateObj.subscribe((val) => {
337
- this.label(transform(val));
338
- });
339
- }
340
- container.appendChild(wrapper);
341
- requestAnimationFrame(() => {
342
- if (window.lucide) {
343
- window.lucide.createIcons();
344
- }
345
- });
346
- return this;
347
- }
348
- }
349
- export function fileupload(id, options = {}) {
350
- return new FileUpload(id, options);
351
- }