@keenthemes/ktui 1.0.3

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 (426) hide show
  1. package/CONTRIBUTING.md +88 -0
  2. package/LICENSE.md +21 -0
  3. package/README.md +124 -0
  4. package/dist/ktui.js +19201 -0
  5. package/dist/ktui.min.js +2 -0
  6. package/dist/ktui.min.js.map +1 -0
  7. package/lib/cjs/components/accordion/accordion.js +168 -0
  8. package/lib/cjs/components/accordion/accordion.js.map +1 -0
  9. package/lib/cjs/components/accordion/index.js +6 -0
  10. package/lib/cjs/components/accordion/index.js.map +1 -0
  11. package/lib/cjs/components/accordion/types.js +3 -0
  12. package/lib/cjs/components/accordion/types.js.map +1 -0
  13. package/lib/cjs/components/collapse/collapse.js +169 -0
  14. package/lib/cjs/components/collapse/collapse.js.map +1 -0
  15. package/lib/cjs/components/collapse/index.js +6 -0
  16. package/lib/cjs/components/collapse/index.js.map +1 -0
  17. package/lib/cjs/components/collapse/types.js +3 -0
  18. package/lib/cjs/components/collapse/types.js.map +1 -0
  19. package/lib/cjs/components/component.js +135 -0
  20. package/lib/cjs/components/component.js.map +1 -0
  21. package/lib/cjs/components/config.js +26 -0
  22. package/lib/cjs/components/config.js.map +1 -0
  23. package/lib/cjs/components/config.umd.js +23 -0
  24. package/lib/cjs/components/config.umd.js.map +1 -0
  25. package/lib/cjs/components/constants.js +15 -0
  26. package/lib/cjs/components/constants.js.map +1 -0
  27. package/lib/cjs/components/datatable/datatable.js +1464 -0
  28. package/lib/cjs/components/datatable/datatable.js.map +1 -0
  29. package/lib/cjs/components/datatable/index.js +6 -0
  30. package/lib/cjs/components/datatable/index.js.map +1 -0
  31. package/lib/cjs/components/datatable/types.js +3 -0
  32. package/lib/cjs/components/datatable/types.js.map +1 -0
  33. package/lib/cjs/components/dismiss/dismiss.js +131 -0
  34. package/lib/cjs/components/dismiss/dismiss.js.map +1 -0
  35. package/lib/cjs/components/dismiss/index.js +6 -0
  36. package/lib/cjs/components/dismiss/index.js.map +1 -0
  37. package/lib/cjs/components/dismiss/types.js +3 -0
  38. package/lib/cjs/components/dismiss/types.js.map +1 -0
  39. package/lib/cjs/components/drawer/drawer.js +347 -0
  40. package/lib/cjs/components/drawer/drawer.js.map +1 -0
  41. package/lib/cjs/components/drawer/index.js +6 -0
  42. package/lib/cjs/components/drawer/index.js.map +1 -0
  43. package/lib/cjs/components/drawer/types.js +3 -0
  44. package/lib/cjs/components/drawer/types.js.map +1 -0
  45. package/lib/cjs/components/dropdown/dropdown.js +403 -0
  46. package/lib/cjs/components/dropdown/dropdown.js.map +1 -0
  47. package/lib/cjs/components/dropdown/index.js +6 -0
  48. package/lib/cjs/components/dropdown/index.js.map +1 -0
  49. package/lib/cjs/components/dropdown/types.js +3 -0
  50. package/lib/cjs/components/dropdown/types.js.map +1 -0
  51. package/lib/cjs/components/image-input/image-input.js +191 -0
  52. package/lib/cjs/components/image-input/image-input.js.map +1 -0
  53. package/lib/cjs/components/image-input/index.js +6 -0
  54. package/lib/cjs/components/image-input/index.js.map +1 -0
  55. package/lib/cjs/components/image-input/types.js +3 -0
  56. package/lib/cjs/components/image-input/types.js.map +1 -0
  57. package/lib/cjs/components/menu/index.js +6 -0
  58. package/lib/cjs/components/menu/index.js.map +1 -0
  59. package/lib/cjs/components/menu/menu.js +1021 -0
  60. package/lib/cjs/components/menu/menu.js.map +1 -0
  61. package/lib/cjs/components/menu/types.js +3 -0
  62. package/lib/cjs/components/menu/types.js.map +1 -0
  63. package/lib/cjs/components/modal/index.js +6 -0
  64. package/lib/cjs/components/modal/index.js.map +1 -0
  65. package/lib/cjs/components/modal/modal.js +316 -0
  66. package/lib/cjs/components/modal/modal.js.map +1 -0
  67. package/lib/cjs/components/modal/types.js +3 -0
  68. package/lib/cjs/components/modal/types.js.map +1 -0
  69. package/lib/cjs/components/reparent/index.js +6 -0
  70. package/lib/cjs/components/reparent/index.js.map +1 -0
  71. package/lib/cjs/components/reparent/reparent.js +93 -0
  72. package/lib/cjs/components/reparent/reparent.js.map +1 -0
  73. package/lib/cjs/components/reparent/types.js +3 -0
  74. package/lib/cjs/components/reparent/types.js.map +1 -0
  75. package/lib/cjs/components/scrollable/index.js +6 -0
  76. package/lib/cjs/components/scrollable/index.js.map +1 -0
  77. package/lib/cjs/components/scrollable/scrollable.js +259 -0
  78. package/lib/cjs/components/scrollable/scrollable.js.map +1 -0
  79. package/lib/cjs/components/scrollable/types.js +3 -0
  80. package/lib/cjs/components/scrollable/types.js.map +1 -0
  81. package/lib/cjs/components/scrollspy/index.js +6 -0
  82. package/lib/cjs/components/scrollspy/index.js.map +1 -0
  83. package/lib/cjs/components/scrollspy/scrollspy.js +174 -0
  84. package/lib/cjs/components/scrollspy/scrollspy.js.map +1 -0
  85. package/lib/cjs/components/scrollspy/types.js +3 -0
  86. package/lib/cjs/components/scrollspy/types.js.map +1 -0
  87. package/lib/cjs/components/scrollto/index.js +6 -0
  88. package/lib/cjs/components/scrollto/index.js.map +1 -0
  89. package/lib/cjs/components/scrollto/scrollto.js +103 -0
  90. package/lib/cjs/components/scrollto/scrollto.js.map +1 -0
  91. package/lib/cjs/components/scrollto/types.js +3 -0
  92. package/lib/cjs/components/scrollto/types.js.map +1 -0
  93. package/lib/cjs/components/stepper/index.js +6 -0
  94. package/lib/cjs/components/stepper/index.js.map +1 -0
  95. package/lib/cjs/components/stepper/stepper.js +258 -0
  96. package/lib/cjs/components/stepper/stepper.js.map +1 -0
  97. package/lib/cjs/components/stepper/types.js +3 -0
  98. package/lib/cjs/components/stepper/types.js.map +1 -0
  99. package/lib/cjs/components/sticky/index.js +6 -0
  100. package/lib/cjs/components/sticky/index.js.map +1 -0
  101. package/lib/cjs/components/sticky/sticky.js +297 -0
  102. package/lib/cjs/components/sticky/sticky.js.map +1 -0
  103. package/lib/cjs/components/sticky/types.js +3 -0
  104. package/lib/cjs/components/sticky/types.js.map +1 -0
  105. package/lib/cjs/components/tabs/index.js +6 -0
  106. package/lib/cjs/components/tabs/index.js.map +1 -0
  107. package/lib/cjs/components/tabs/tabs.js +146 -0
  108. package/lib/cjs/components/tabs/tabs.js.map +1 -0
  109. package/lib/cjs/components/tabs/types.js +3 -0
  110. package/lib/cjs/components/tabs/types.js.map +1 -0
  111. package/lib/cjs/components/theme/index.js +6 -0
  112. package/lib/cjs/components/theme/index.js.map +1 -0
  113. package/lib/cjs/components/theme/theme.js +147 -0
  114. package/lib/cjs/components/theme/theme.js.map +1 -0
  115. package/lib/cjs/components/theme/types.js +3 -0
  116. package/lib/cjs/components/theme/types.js.map +1 -0
  117. package/lib/cjs/components/toggle/index.js +6 -0
  118. package/lib/cjs/components/toggle/index.js.map +1 -0
  119. package/lib/cjs/components/toggle/toggle.js +139 -0
  120. package/lib/cjs/components/toggle/toggle.js.map +1 -0
  121. package/lib/cjs/components/toggle/types.js +3 -0
  122. package/lib/cjs/components/toggle/types.js.map +1 -0
  123. package/lib/cjs/components/toggle-password/index.js +6 -0
  124. package/lib/cjs/components/toggle-password/index.js.map +1 -0
  125. package/lib/cjs/components/toggle-password/toggle-password.js +131 -0
  126. package/lib/cjs/components/toggle-password/toggle-password.js.map +1 -0
  127. package/lib/cjs/components/toggle-password/types.js +3 -0
  128. package/lib/cjs/components/toggle-password/types.js.map +1 -0
  129. package/lib/cjs/components/tooltip/index.js +6 -0
  130. package/lib/cjs/components/tooltip/index.js.map +1 -0
  131. package/lib/cjs/components/tooltip/tooltip.js +271 -0
  132. package/lib/cjs/components/tooltip/tooltip.js.map +1 -0
  133. package/lib/cjs/components/tooltip/types.js +3 -0
  134. package/lib/cjs/components/tooltip/types.js.map +1 -0
  135. package/lib/cjs/helpers/data.js +33 -0
  136. package/lib/cjs/helpers/data.js.map +1 -0
  137. package/lib/cjs/helpers/dom.js +297 -0
  138. package/lib/cjs/helpers/dom.js.map +1 -0
  139. package/lib/cjs/helpers/event-handler.js +36 -0
  140. package/lib/cjs/helpers/event-handler.js.map +1 -0
  141. package/lib/cjs/helpers/utils.js +94 -0
  142. package/lib/cjs/helpers/utils.js.map +1 -0
  143. package/lib/cjs/index.js +105 -0
  144. package/lib/cjs/index.js.map +1 -0
  145. package/lib/cjs/types.js +3 -0
  146. package/lib/cjs/types.js.map +1 -0
  147. package/lib/esm/components/accordion/accordion.js +165 -0
  148. package/lib/esm/components/accordion/accordion.js.map +1 -0
  149. package/lib/esm/components/accordion/index.js +2 -0
  150. package/lib/esm/components/accordion/index.js.map +1 -0
  151. package/lib/esm/components/accordion/types.js +2 -0
  152. package/lib/esm/components/accordion/types.js.map +1 -0
  153. package/lib/esm/components/collapse/collapse.js +166 -0
  154. package/lib/esm/components/collapse/collapse.js.map +1 -0
  155. package/lib/esm/components/collapse/index.js +2 -0
  156. package/lib/esm/components/collapse/index.js.map +1 -0
  157. package/lib/esm/components/collapse/types.js +2 -0
  158. package/lib/esm/components/collapse/types.js.map +1 -0
  159. package/lib/esm/components/component.js +133 -0
  160. package/lib/esm/components/component.js.map +1 -0
  161. package/lib/esm/components/config.js +24 -0
  162. package/lib/esm/components/config.js.map +1 -0
  163. package/lib/esm/components/config.umd.js +23 -0
  164. package/lib/esm/components/config.umd.js.map +1 -0
  165. package/lib/esm/components/constants.js +12 -0
  166. package/lib/esm/components/constants.js.map +1 -0
  167. package/lib/esm/components/datatable/datatable.js +1461 -0
  168. package/lib/esm/components/datatable/datatable.js.map +1 -0
  169. package/lib/esm/components/datatable/index.js +2 -0
  170. package/lib/esm/components/datatable/index.js.map +1 -0
  171. package/lib/esm/components/datatable/types.js +2 -0
  172. package/lib/esm/components/datatable/types.js.map +1 -0
  173. package/lib/esm/components/dismiss/dismiss.js +128 -0
  174. package/lib/esm/components/dismiss/dismiss.js.map +1 -0
  175. package/lib/esm/components/dismiss/index.js +2 -0
  176. package/lib/esm/components/dismiss/index.js.map +1 -0
  177. package/lib/esm/components/dismiss/types.js +2 -0
  178. package/lib/esm/components/dismiss/types.js.map +1 -0
  179. package/lib/esm/components/drawer/drawer.js +344 -0
  180. package/lib/esm/components/drawer/drawer.js.map +1 -0
  181. package/lib/esm/components/drawer/index.js +2 -0
  182. package/lib/esm/components/drawer/index.js.map +1 -0
  183. package/lib/esm/components/drawer/types.js +2 -0
  184. package/lib/esm/components/drawer/types.js.map +1 -0
  185. package/lib/esm/components/dropdown/dropdown.js +400 -0
  186. package/lib/esm/components/dropdown/dropdown.js.map +1 -0
  187. package/lib/esm/components/dropdown/index.js +2 -0
  188. package/lib/esm/components/dropdown/index.js.map +1 -0
  189. package/lib/esm/components/dropdown/types.js +2 -0
  190. package/lib/esm/components/dropdown/types.js.map +1 -0
  191. package/lib/esm/components/image-input/image-input.js +188 -0
  192. package/lib/esm/components/image-input/image-input.js.map +1 -0
  193. package/lib/esm/components/image-input/index.js +2 -0
  194. package/lib/esm/components/image-input/index.js.map +1 -0
  195. package/lib/esm/components/image-input/types.js +2 -0
  196. package/lib/esm/components/image-input/types.js.map +1 -0
  197. package/lib/esm/components/menu/index.js +2 -0
  198. package/lib/esm/components/menu/index.js.map +1 -0
  199. package/lib/esm/components/menu/menu.js +1018 -0
  200. package/lib/esm/components/menu/menu.js.map +1 -0
  201. package/lib/esm/components/menu/types.js +2 -0
  202. package/lib/esm/components/menu/types.js.map +1 -0
  203. package/lib/esm/components/modal/index.js +2 -0
  204. package/lib/esm/components/modal/index.js.map +1 -0
  205. package/lib/esm/components/modal/modal.js +313 -0
  206. package/lib/esm/components/modal/modal.js.map +1 -0
  207. package/lib/esm/components/modal/types.js +2 -0
  208. package/lib/esm/components/modal/types.js.map +1 -0
  209. package/lib/esm/components/reparent/index.js +2 -0
  210. package/lib/esm/components/reparent/index.js.map +1 -0
  211. package/lib/esm/components/reparent/reparent.js +90 -0
  212. package/lib/esm/components/reparent/reparent.js.map +1 -0
  213. package/lib/esm/components/reparent/types.js +2 -0
  214. package/lib/esm/components/reparent/types.js.map +1 -0
  215. package/lib/esm/components/scrollable/index.js +2 -0
  216. package/lib/esm/components/scrollable/index.js.map +1 -0
  217. package/lib/esm/components/scrollable/scrollable.js +256 -0
  218. package/lib/esm/components/scrollable/scrollable.js.map +1 -0
  219. package/lib/esm/components/scrollable/types.js +2 -0
  220. package/lib/esm/components/scrollable/types.js.map +1 -0
  221. package/lib/esm/components/scrollspy/index.js +2 -0
  222. package/lib/esm/components/scrollspy/index.js.map +1 -0
  223. package/lib/esm/components/scrollspy/scrollspy.js +171 -0
  224. package/lib/esm/components/scrollspy/scrollspy.js.map +1 -0
  225. package/lib/esm/components/scrollspy/types.js +2 -0
  226. package/lib/esm/components/scrollspy/types.js.map +1 -0
  227. package/lib/esm/components/scrollto/index.js +2 -0
  228. package/lib/esm/components/scrollto/index.js.map +1 -0
  229. package/lib/esm/components/scrollto/scrollto.js +100 -0
  230. package/lib/esm/components/scrollto/scrollto.js.map +1 -0
  231. package/lib/esm/components/scrollto/types.js +2 -0
  232. package/lib/esm/components/scrollto/types.js.map +1 -0
  233. package/lib/esm/components/stepper/index.js +2 -0
  234. package/lib/esm/components/stepper/index.js.map +1 -0
  235. package/lib/esm/components/stepper/stepper.js +255 -0
  236. package/lib/esm/components/stepper/stepper.js.map +1 -0
  237. package/lib/esm/components/stepper/types.js +2 -0
  238. package/lib/esm/components/stepper/types.js.map +1 -0
  239. package/lib/esm/components/sticky/index.js +2 -0
  240. package/lib/esm/components/sticky/index.js.map +1 -0
  241. package/lib/esm/components/sticky/sticky.js +294 -0
  242. package/lib/esm/components/sticky/sticky.js.map +1 -0
  243. package/lib/esm/components/sticky/types.js +2 -0
  244. package/lib/esm/components/sticky/types.js.map +1 -0
  245. package/lib/esm/components/tabs/index.js +2 -0
  246. package/lib/esm/components/tabs/index.js.map +1 -0
  247. package/lib/esm/components/tabs/tabs.js +143 -0
  248. package/lib/esm/components/tabs/tabs.js.map +1 -0
  249. package/lib/esm/components/tabs/types.js +2 -0
  250. package/lib/esm/components/tabs/types.js.map +1 -0
  251. package/lib/esm/components/theme/index.js +2 -0
  252. package/lib/esm/components/theme/index.js.map +1 -0
  253. package/lib/esm/components/theme/theme.js +144 -0
  254. package/lib/esm/components/theme/theme.js.map +1 -0
  255. package/lib/esm/components/theme/types.js +2 -0
  256. package/lib/esm/components/theme/types.js.map +1 -0
  257. package/lib/esm/components/toggle/index.js +2 -0
  258. package/lib/esm/components/toggle/index.js.map +1 -0
  259. package/lib/esm/components/toggle/toggle.js +136 -0
  260. package/lib/esm/components/toggle/toggle.js.map +1 -0
  261. package/lib/esm/components/toggle/types.js +2 -0
  262. package/lib/esm/components/toggle/types.js.map +1 -0
  263. package/lib/esm/components/toggle-password/index.js +2 -0
  264. package/lib/esm/components/toggle-password/index.js.map +1 -0
  265. package/lib/esm/components/toggle-password/toggle-password.js +128 -0
  266. package/lib/esm/components/toggle-password/toggle-password.js.map +1 -0
  267. package/lib/esm/components/toggle-password/types.js +2 -0
  268. package/lib/esm/components/toggle-password/types.js.map +1 -0
  269. package/lib/esm/components/tooltip/index.js +2 -0
  270. package/lib/esm/components/tooltip/index.js.map +1 -0
  271. package/lib/esm/components/tooltip/tooltip.js +268 -0
  272. package/lib/esm/components/tooltip/tooltip.js.map +1 -0
  273. package/lib/esm/components/tooltip/types.js +2 -0
  274. package/lib/esm/components/tooltip/types.js.map +1 -0
  275. package/lib/esm/helpers/data.js +31 -0
  276. package/lib/esm/helpers/data.js.map +1 -0
  277. package/lib/esm/helpers/dom.js +295 -0
  278. package/lib/esm/helpers/dom.js.map +1 -0
  279. package/lib/esm/helpers/event-handler.js +34 -0
  280. package/lib/esm/helpers/event-handler.js.map +1 -0
  281. package/lib/esm/helpers/utils.js +92 -0
  282. package/lib/esm/helpers/utils.js.map +1 -0
  283. package/lib/esm/index.js +79 -0
  284. package/lib/esm/index.js.map +1 -0
  285. package/lib/esm/types.js +2 -0
  286. package/lib/esm/types.js.map +1 -0
  287. package/package.json +85 -0
  288. package/prettier.config.js +9 -0
  289. package/src/components/accordion/accordion-menu.css +51 -0
  290. package/src/components/accordion/accordion.css +86 -0
  291. package/src/components/accordion/accordion.ts +221 -0
  292. package/src/components/accordion/index.ts +7 -0
  293. package/src/components/accordion/types.ts +16 -0
  294. package/src/components/alert/alert.css +282 -0
  295. package/src/components/avatar/avatar.css +46 -0
  296. package/src/components/badge/badge.css +176 -0
  297. package/src/components/breadcrumb/breadcrumb.css +38 -0
  298. package/src/components/btn/btn.css +227 -0
  299. package/src/components/card/card.css +158 -0
  300. package/src/components/checkbox/checkbox.css +74 -0
  301. package/src/components/collapse/collapse.css +14 -0
  302. package/src/components/collapse/collapse.ts +200 -0
  303. package/src/components/collapse/index.ts +7 -0
  304. package/src/components/collapse/types.ts +16 -0
  305. package/src/components/component.ts +132 -0
  306. package/src/components/constants.ts +16 -0
  307. package/src/components/datatable/datatable-checkbox.ts +236 -0
  308. package/src/components/datatable/datatable-sort.ts +154 -0
  309. package/src/components/datatable/datatable.css +110 -0
  310. package/src/components/datatable/datatable.ts +1657 -0
  311. package/src/components/datatable/index.ts +19 -0
  312. package/src/components/datatable/types.ts +203 -0
  313. package/src/components/datepicker/calendar.ts +1397 -0
  314. package/src/components/datepicker/config.ts +368 -0
  315. package/src/components/datepicker/datepicker.css +7 -0
  316. package/src/components/datepicker/datepicker.ts +1287 -0
  317. package/src/components/datepicker/dropdown.ts +757 -0
  318. package/src/components/datepicker/events.ts +149 -0
  319. package/src/components/datepicker/index.ts +10 -0
  320. package/src/components/datepicker/keyboard.ts +646 -0
  321. package/src/components/datepicker/locales.ts +80 -0
  322. package/src/components/datepicker/templates.ts +792 -0
  323. package/src/components/datepicker/types.ts +154 -0
  324. package/src/components/datepicker/utils.ts +631 -0
  325. package/src/components/dismiss/dismiss.css +10 -0
  326. package/src/components/dismiss/dismiss.ts +152 -0
  327. package/src/components/dismiss/index.ts +7 -0
  328. package/src/components/dismiss/types.ts +17 -0
  329. package/src/components/drawer/drawer.css +97 -0
  330. package/src/components/drawer/drawer.ts +437 -0
  331. package/src/components/drawer/index.ts +7 -0
  332. package/src/components/drawer/types.ts +25 -0
  333. package/src/components/dropdown/dropdown-menu.css +56 -0
  334. package/src/components/dropdown/dropdown.css +46 -0
  335. package/src/components/dropdown/dropdown.ts +549 -0
  336. package/src/components/dropdown/index.ts +7 -0
  337. package/src/components/dropdown/types.ts +28 -0
  338. package/src/components/form/form.css +54 -0
  339. package/src/components/image-input/image-input.css +56 -0
  340. package/src/components/image-input/image-input.ts +249 -0
  341. package/src/components/image-input/index.ts +10 -0
  342. package/src/components/image-input/types.ts +12 -0
  343. package/src/components/input/input-group.css +42 -0
  344. package/src/components/input/input.css +136 -0
  345. package/src/components/kbd/kbd.css +30 -0
  346. package/src/components/label/label.css +20 -0
  347. package/src/components/link/link.css +81 -0
  348. package/src/components/modal/index.ts +7 -0
  349. package/src/components/modal/modal.css +73 -0
  350. package/src/components/modal/modal.ts +382 -0
  351. package/src/components/modal/types.ts +21 -0
  352. package/src/components/pagination/pagination.css +26 -0
  353. package/src/components/popover/popover.css +22 -0
  354. package/src/components/progress/progress.css +51 -0
  355. package/src/components/radio/radio.css +51 -0
  356. package/src/components/reparent/index.ts +7 -0
  357. package/src/components/reparent/reparent.ts +109 -0
  358. package/src/components/reparent/types.ts +15 -0
  359. package/src/components/scrollable/index.ts +10 -0
  360. package/src/components/scrollable/scrollable.css +29 -0
  361. package/src/components/scrollable/scrollable.ts +297 -0
  362. package/src/components/scrollable/types.ts +16 -0
  363. package/src/components/scrollspy/index.ts +7 -0
  364. package/src/components/scrollspy/scrollspy.css +13 -0
  365. package/src/components/scrollspy/scrollspy.ts +224 -0
  366. package/src/components/scrollspy/types.ts +15 -0
  367. package/src/components/scrollto/index.ts +7 -0
  368. package/src/components/scrollto/scrollto.ts +127 -0
  369. package/src/components/scrollto/types.ts +15 -0
  370. package/src/components/select/combobox.ts +305 -0
  371. package/src/components/select/config.ts +324 -0
  372. package/src/components/select/dropdown.ts +510 -0
  373. package/src/components/select/index.ts +13 -0
  374. package/src/components/select/option.ts +43 -0
  375. package/src/components/select/remote.ts +477 -0
  376. package/src/components/select/search.ts +430 -0
  377. package/src/components/select/select.css +105 -0
  378. package/src/components/select/select.ts +1916 -0
  379. package/src/components/select/tags.ts +123 -0
  380. package/src/components/select/templates.ts +531 -0
  381. package/src/components/select/types.ts +36 -0
  382. package/src/components/select/utils.ts +747 -0
  383. package/src/components/select/variants.css +5 -0
  384. package/src/components/separator/separator.css +14 -0
  385. package/src/components/skeleton/skeleton.css +10 -0
  386. package/src/components/stepper/index.ts +7 -0
  387. package/src/components/stepper/stepper.css +49 -0
  388. package/src/components/stepper/stepper.ts +308 -0
  389. package/src/components/stepper/types.ts +13 -0
  390. package/src/components/sticky/index.ts +7 -0
  391. package/src/components/sticky/sticky.css +22 -0
  392. package/src/components/sticky/sticky.ts +381 -0
  393. package/src/components/sticky/types.ts +23 -0
  394. package/src/components/switch/switch.css +110 -0
  395. package/src/components/table/table.css +168 -0
  396. package/src/components/tabs/index.ts +7 -0
  397. package/src/components/tabs/tabs.css +40 -0
  398. package/src/components/tabs/tabs.ts +190 -0
  399. package/src/components/tabs/types.ts +13 -0
  400. package/src/components/textarea/textarea.css +35 -0
  401. package/src/components/theme-switch/index.ts +10 -0
  402. package/src/components/theme-switch/theme-switch.css +22 -0
  403. package/src/components/theme-switch/theme-switch.ts +176 -0
  404. package/src/components/theme-switch/types.ts +15 -0
  405. package/src/components/toggle/index.ts +7 -0
  406. package/src/components/toggle/toggle.css +13 -0
  407. package/src/components/toggle/toggle.ts +173 -0
  408. package/src/components/toggle/types.ts +18 -0
  409. package/src/components/toggle-group/toggle-group.css +55 -0
  410. package/src/components/toggle-password/index.ts +10 -0
  411. package/src/components/toggle-password/toggle-password.css +13 -0
  412. package/src/components/toggle-password/toggle-password.ts +159 -0
  413. package/src/components/toggle-password/types.ts +13 -0
  414. package/src/components/tooltip/index.ts +7 -0
  415. package/src/components/tooltip/tooltip.css +18 -0
  416. package/src/components/tooltip/tooltip.ts +361 -0
  417. package/src/components/tooltip/types.ts +28 -0
  418. package/src/helpers/data.ts +46 -0
  419. package/src/helpers/dom.ts +405 -0
  420. package/src/helpers/event-handler.ts +61 -0
  421. package/src/helpers/utils.ts +183 -0
  422. package/src/index.ts +113 -0
  423. package/src/types.ts +23 -0
  424. package/styles.css +48 -0
  425. package/tsconfig.json +17 -0
  426. package/webpack.config.js +113 -0
@@ -0,0 +1,1464 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __rest = (this && this.__rest) || function (s, e) {
65
+ var t = {};
66
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
67
+ t[p] = s[p];
68
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
69
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
70
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
71
+ t[p[i]] = s[p[i]];
72
+ }
73
+ return t;
74
+ };
75
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
76
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
77
+ if (ar || !(i in from)) {
78
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
79
+ ar[i] = from[i];
80
+ }
81
+ }
82
+ return to.concat(ar || Array.prototype.slice.call(from));
83
+ };
84
+ Object.defineProperty(exports, "__esModule", { value: true });
85
+ exports.KTDataTable = void 0;
86
+ var component_1 = require("../component");
87
+ var event_handler_1 = require("../../helpers/event-handler");
88
+ var utils_1 = require("../../helpers/utils");
89
+ var index_1 = require("../../index");
90
+ var data_1 = require("../../helpers/data");
91
+ /**
92
+ * Custom DataTable plugin class with server-side API, pagination, and sorting
93
+ * @classdesc A custom KTComponent class that integrates server-side API, pagination, and sorting functionality into a table.
94
+ * It supports fetching data from a server-side API, pagination, and sorting of the fetched data.
95
+ * @class
96
+ * @extends {KTComponent}
97
+ * @param {HTMLElement} element The table element
98
+ * @param {KTDataTableConfigInterface} [config] Additional configuration options
99
+ */
100
+ var KTDataTable = /** @class */ (function (_super) {
101
+ __extends(KTDataTable, _super);
102
+ function KTDataTable(element, config) {
103
+ var _this = _super.call(this) || this;
104
+ _this._name = 'datatable';
105
+ _this._checkboxListener = function (event) {
106
+ _this._checkboxToggle(event); // Toggle row checkbox state
107
+ };
108
+ // private _searchListener: (value: string) => void;
109
+ _this._data = [];
110
+ if (data_1.default.has(element, _this._name))
111
+ return _this;
112
+ _this._defaultConfig = _this._initDefaultConfig(config);
113
+ _this._init(element);
114
+ _this._buildConfig();
115
+ // Store the instance directly on the element
116
+ element.instance = _this;
117
+ _this._initElements();
118
+ if (_this._config.stateSave === false) {
119
+ _this._deleteState();
120
+ }
121
+ if (_this._config.stateSave) {
122
+ _this._loadState();
123
+ }
124
+ _this._initTableHeader();
125
+ _this._updateData();
126
+ _this._fireEvent('init');
127
+ _this._dispatchEvent('init');
128
+ return _this;
129
+ }
130
+ /**
131
+ * Initialize default configuration for the datatable
132
+ * @param config User-provided configuration options
133
+ * @returns Default configuration merged with user-provided options
134
+ */
135
+ KTDataTable.prototype._initDefaultConfig = function (config) {
136
+ return __assign({
137
+ /**
138
+ * HTTP method for server-side API call
139
+ */
140
+ requestMethod: 'GET',
141
+ /**
142
+ * Custom HTTP headers for the API request
143
+ */
144
+ requestHeaders: {
145
+ 'Content-Type': 'application/x-www-form-urlencoded',
146
+ },
147
+ /**
148
+ * Pagination info template
149
+ */
150
+ info: '{start}-{end} of {total}',
151
+ /**
152
+ * Info text when there is no data
153
+ */
154
+ infoEmpty: 'No records found',
155
+ /**
156
+ * Available page sizes
157
+ */
158
+ pageSizes: [5, 10, 20, 30, 50],
159
+ /**
160
+ * Default page size
161
+ */
162
+ pageSize: 10,
163
+ /**
164
+ * Enable or disable pagination more button
165
+ */
166
+ pageMore: true,
167
+ /**
168
+ * Maximum number of pages before enabling pagination more button
169
+ */
170
+ pageMoreLimit: 3,
171
+ /**
172
+ * Pagination button templates
173
+ */
174
+ pagination: {
175
+ number: {
176
+ /**
177
+ * CSS classes to be added to the pagination button
178
+ */
179
+ class: 'btn',
180
+ /**
181
+ * Text to be displayed in the pagination button
182
+ */
183
+ text: '{page}',
184
+ },
185
+ previous: {
186
+ /**
187
+ * CSS classes to be added to the previous pagination button
188
+ */
189
+ class: 'btn',
190
+ /**
191
+ * Text to be displayed in the previous pagination button
192
+ */
193
+ text: '<i class="ki-outline ki-black-left"></i>',
194
+ },
195
+ next: {
196
+ /**
197
+ * CSS classes to be added to the next pagination button
198
+ */
199
+ class: 'btn',
200
+ /**
201
+ * Text to be displayed in the next pagination button
202
+ */
203
+ text: '<i class="ki-outline ki-black-right"></i>',
204
+ },
205
+ more: {
206
+ /**
207
+ * CSS classes to be added to the pagination more button
208
+ */
209
+ class: 'btn',
210
+ /**
211
+ * Text to be displayed in the pagination more button
212
+ */
213
+ text: '...',
214
+ }
215
+ },
216
+ /**
217
+ * Sorting options
218
+ */
219
+ sort: {
220
+ /**
221
+ * CSS classes to be added to the sortable headers
222
+ */
223
+ classes: {
224
+ base: 'sort',
225
+ asc: 'asc',
226
+ desc: 'desc',
227
+ },
228
+ /**
229
+ * Local sorting callback function
230
+ * Sorts the data array based on the sort field and order
231
+ * @param data Data array to be sorted
232
+ * @param sortField Property name of the data object to be sorted by
233
+ * @param sortOrder Sorting order (ascending or descending)
234
+ * @returns Sorted data array
235
+ */
236
+ callback: function (data, sortField, sortOrder) {
237
+ /**
238
+ * Compares two values by converting them to strings and removing any HTML tags or white spaces
239
+ * @param a First value to be compared
240
+ * @param b Second value to be compared
241
+ * @returns 1 if a > b, -1 if a < b, 0 if a === b
242
+ */
243
+ var compareValues = function (a, b) {
244
+ var aText = String(a).replace(/<[^>]*>|&nbsp;/g, '');
245
+ var bText = String(b).replace(/<[^>]*>|&nbsp;/g, '');
246
+ return aText > bText ? (sortOrder === 'asc' ? 1 : -1) : (aText < bText ? (sortOrder === 'asc' ? -1 : 1) : 0);
247
+ };
248
+ return data.sort(function (a, b) {
249
+ var aValue = a[sortField];
250
+ var bValue = b[sortField];
251
+ return compareValues(aValue, bValue);
252
+ });
253
+ },
254
+ }, search: {
255
+ /**
256
+ * Delay in milliseconds before the search function is applied to the data array
257
+ * @default 500
258
+ */
259
+ delay: 500, // ms
260
+ /**
261
+ * Local search callback function
262
+ * Filters the data array based on the search string
263
+ * @param data Data array to be filtered
264
+ * @param search Search string used to filter the data array
265
+ * @returns Filtered data array
266
+ */
267
+ callback: function (data, search) {
268
+ if (!data || !search) {
269
+ return [];
270
+ }
271
+ return data.filter(function (item) {
272
+ if (!item) {
273
+ return false;
274
+ }
275
+ return Object.values(item).some(function (value) {
276
+ if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean') {
277
+ return false;
278
+ }
279
+ var valueText = String(value).replace(/<[^>]*>|&nbsp;/g, '').toLowerCase();
280
+ return valueText.includes(search.toLowerCase());
281
+ });
282
+ });
283
+ }
284
+ },
285
+ /**
286
+ * Loading spinner options
287
+ */
288
+ loading: {
289
+ /**
290
+ * Template to be displayed during data fetching process
291
+ */
292
+ template: "\n\t\t\t\t\t<div class=\"absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2\">\n\t\t\t\t\t\t<div class=\"flex items-center gap-2 px-4 py-2 font-medium leading-none text-2sm border border-gray-200 shadow-default rounded-md text-gray-500 bg-light\">\n\t\t\t\t\t\t\t<svg class=\"animate-spin -ml-1 h-5 w-5 text-gray-600\" xmlns=\"http://www.w3.org/2000/svg\" fill=\"none\" viewBox=\"0 0 24 24\">\n\t\t\t\t\t\t\t\t<circle class=\"opacity-25\" cx=\"12\" cy=\"12\" r=\"10\" stroke=\"currentColor\" stroke-width=\"3\"></circle>\n\t\t\t\t\t\t\t\t<path class=\"opacity-75\" fill=\"currentColor\" d=\"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z\"></path>\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t\t{content}\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n\t\t\t\t",
293
+ /**
294
+ * Loading text to be displayed in the template
295
+ */
296
+ content: 'Loading...'
297
+ },
298
+ /**
299
+ * Selectors of the elements to be targeted
300
+ */
301
+ attributes: {
302
+ /**
303
+ * Data table element
304
+ */
305
+ table: 'table[data-datatable-table="true"]',
306
+ /**
307
+ * Pagination info element
308
+ */
309
+ info: '[data-datatable-info="true"]',
310
+ /**
311
+ * Page size dropdown element
312
+ */
313
+ size: '[data-datatable-size="true"]',
314
+ /**
315
+ * Pagination element
316
+ */
317
+ pagination: '[data-datatable-pagination="true"]',
318
+ /**
319
+ * Spinner element
320
+ */
321
+ spinner: '[data-datatable-spinner="true"]',
322
+ /**
323
+ * Checkbox element
324
+ */
325
+ check: '[data-datatable-check="true"]',
326
+ checkbox: '[data-datatable-row-check="true"]'
327
+ },
328
+ /**
329
+ * Enable or disable state saving
330
+ */
331
+ stateSave: true, checkbox: {
332
+ checkedClass: 'checked'
333
+ },
334
+ /**
335
+ * Private properties
336
+ */
337
+ _state: {} }, config);
338
+ };
339
+ /**
340
+ * Initialize table, tbody, thead, info, size, and pagination elements
341
+ * @returns {void}
342
+ */
343
+ KTDataTable.prototype._initElements = function () {
344
+ /**
345
+ * Data table element
346
+ */
347
+ this._tableElement = this._element.querySelector(this._config.attributes.table);
348
+ /**
349
+ * Table body element
350
+ */
351
+ this._tbodyElement = this._tableElement.tBodies[0] || this._tableElement.createTBody();
352
+ /**
353
+ * Table head element
354
+ */
355
+ this._theadElement = this._tableElement.tHead;
356
+ /**
357
+ * Pagination info element
358
+ */
359
+ this._infoElement = this._element.querySelector(this._config.attributes.info);
360
+ /**
361
+ * Page size dropdown element
362
+ */
363
+ this._sizeElement = this._element.querySelector(this._config.attributes.size);
364
+ /**
365
+ * Pagination element
366
+ */
367
+ this._paginationElement = this._element.querySelector(this._config.attributes.pagination);
368
+ };
369
+ /**
370
+ * Fetch data from the server or from the DOM if `apiEndpoint` is not defined.
371
+ * @returns {Promise<void>} Promise which is resolved after data has been fetched and checkbox plugin initialized.
372
+ */
373
+ KTDataTable.prototype._updateData = function () {
374
+ return __awaiter(this, void 0, void 0, function () {
375
+ return __generator(this, function (_a) {
376
+ this._showSpinner(); // Show spinner before fetching data
377
+ // Fetch data from the DOM and initialize the checkbox plugin
378
+ return [2 /*return*/, (typeof this._config.apiEndpoint === 'undefined')
379
+ ? this._fetchDataFromLocal().then(this._finalize.bind(this))
380
+ : this._fetchDataFromServer().then(this._finalize.bind(this))];
381
+ });
382
+ });
383
+ };
384
+ /**
385
+ * Finalize data table after data has been fetched
386
+ * @returns {void}
387
+ */
388
+ KTDataTable.prototype._finalize = function () {
389
+ this._element.classList.add('datatable-initialized');
390
+ var headerCheckElement = this._element.querySelector(this._config.attributes.check);
391
+ if (headerCheckElement) {
392
+ this._initChecbox(headerCheckElement);
393
+ }
394
+ this._attachSearchEvent();
395
+ if (typeof index_1.default !== "undefined") {
396
+ index_1.default.init();
397
+ }
398
+ /**
399
+ * Hide spinner
400
+ */
401
+ this._hideSpinner();
402
+ };
403
+ /**
404
+ * Attach search event to the search input element
405
+ * @returns {void}
406
+ */
407
+ KTDataTable.prototype._attachSearchEvent = function () {
408
+ var _this = this;
409
+ var tableId = this._tableId();
410
+ var searchElement = document.querySelector("[data-datatable-search=\"#".concat(tableId, "\"]"));
411
+ if (searchElement) {
412
+ // Check if a debounced search function already exists
413
+ if (searchElement._debouncedSearch) {
414
+ // Remove the existing debounced event listener
415
+ searchElement.removeEventListener('keyup', searchElement._debouncedSearch);
416
+ }
417
+ // Create a new debounced search function
418
+ var debouncedSearch = this._debounce(function () {
419
+ _this.search(searchElement.value);
420
+ }, this._config.search.delay);
421
+ // Store the new debounced function as a property of the element
422
+ searchElement._debouncedSearch = debouncedSearch;
423
+ // Add the new debounced event listener
424
+ searchElement.addEventListener('keyup', debouncedSearch);
425
+ }
426
+ };
427
+ /**
428
+ * Initialize the checkbox plugin
429
+ * @param {HTMLInputElement} headerCheckElement - The header checkbox element
430
+ * @returns {void}
431
+ */
432
+ KTDataTable.prototype._initChecbox = function (headerCheckElement) {
433
+ this._headerCheckElement = headerCheckElement;
434
+ this._headerChecked = headerCheckElement.checked;
435
+ this._targetElements = this._element.querySelectorAll(this._config.attributes.checkbox);
436
+ this._checkboxHandler();
437
+ };
438
+ /**
439
+ * Fetch data from the DOM
440
+ * Fetch data from the table element and save it to the `originalData` state property.
441
+ * This method is used when the data is not fetched from the server via an API endpoint.
442
+ */
443
+ KTDataTable.prototype._fetchDataFromLocal = function () {
444
+ return __awaiter(this, void 0, void 0, function () {
445
+ var _a, sortField, sortOrder, page, pageSize, search, originalData, _b, originalData_1, originalDataAttributes, _temp, startIndex, endIndex;
446
+ var _c;
447
+ return __generator(this, function (_d) {
448
+ switch (_d.label) {
449
+ case 0:
450
+ _a = this.getState(), sortField = _a.sortField, sortOrder = _a.sortOrder, page = _a.page, pageSize = _a.pageSize, search = _a.search;
451
+ originalData = this.getState().originalData;
452
+ // If the table element or the original data is not defined, bail
453
+ if (!this._tableElement || originalData === undefined || this._tableConfigInvalidate() || this._localTableHeaderInvalidate() || this._localTableContentInvalidate()) {
454
+ this._deleteState();
455
+ _b = this._localExtractTableContent(), originalData_1 = _b.originalData, originalDataAttributes = _b.originalDataAttributes;
456
+ this._config._state.originalData = originalData_1;
457
+ this._config._state.originalDataAttributes = originalDataAttributes;
458
+ }
459
+ // Update the original data variable
460
+ originalData = this.getState().originalData;
461
+ _temp = this._data = __spreadArray([], originalData, true);
462
+ if (search) {
463
+ _temp = this._data = this._config.search.callback.call(this, this._data, search);
464
+ }
465
+ // If sorting is defined, sort the data
466
+ if (sortField !== undefined && sortOrder !== undefined && sortOrder !== '') {
467
+ if (typeof this._config.sort.callback === 'function') {
468
+ this._data = this._config.sort.callback.call(this, this._data, sortField, sortOrder);
469
+ }
470
+ }
471
+ // If there is data, slice it to the current page size
472
+ if (((_c = this._data) === null || _c === void 0 ? void 0 : _c.length) > 0) {
473
+ startIndex = (page - 1) * pageSize;
474
+ endIndex = startIndex + pageSize;
475
+ this._data = this._data.slice(startIndex, endIndex);
476
+ }
477
+ // Determine number of total rows
478
+ this._config._state.totalItems = _temp.length;
479
+ // Draw the data
480
+ return [4 /*yield*/, this._draw()];
481
+ case 1:
482
+ // Draw the data
483
+ _d.sent();
484
+ return [2 /*return*/];
485
+ }
486
+ });
487
+ });
488
+ };
489
+ /**
490
+ * Checks if the table content has been invalidated by comparing the current checksum of the table body
491
+ * with the stored checksum in the state. If the checksums are different, the state is updated with the
492
+ * new checksum and `true` is returned. Otherwise, `false` is returned.
493
+ *
494
+ * @returns {boolean} `true` if the table content has been invalidated, `false` otherwise.
495
+ */
496
+ KTDataTable.prototype._localTableContentInvalidate = function () {
497
+ var checksum = utils_1.default.checksum(JSON.stringify(this._tbodyElement.innerHTML));
498
+ if (this.getState()._contentChecksum !== checksum) {
499
+ this._config._state._contentChecksum = checksum;
500
+ return true;
501
+ }
502
+ return false;
503
+ };
504
+ KTDataTable.prototype._tableConfigInvalidate = function () {
505
+ // Remove _data and _state from config
506
+ var _a = this._config, _data = _a._data, _state = _a._state, restConfig = __rest(_a, ["_data", "_state"]);
507
+ var checksum = utils_1.default.checksum(JSON.stringify(restConfig));
508
+ if (_state._configChecksum !== checksum) {
509
+ this._config._state._configChecksum = checksum;
510
+ return true;
511
+ }
512
+ return false;
513
+ };
514
+ /**
515
+ * Extracts the table content and returns it as an object containing an array of original data and an array of original data attributes.
516
+ *
517
+ * @returns {{originalData: T[], originalDataAttributes: KTDataTableAttributeInterface[]}} - An object containing an array of original data and an array of original data attributes.
518
+ */
519
+ KTDataTable.prototype._localExtractTableContent = function () {
520
+ var originalData = [];
521
+ var originalDataAttributes = [];
522
+ var rows = this._tbodyElement.querySelectorAll('tr');
523
+ rows.forEach(function (row) {
524
+ var dataRow = {};
525
+ var dataRowAttribute = {};
526
+ // Loop through each cell in the row
527
+ row.querySelectorAll('td').forEach(function (td, index) {
528
+ var _a;
529
+ var attributes = {};
530
+ // Copy all attributes to the cell data
531
+ Array.from(td.attributes).forEach(function (attr) {
532
+ attributes[attr.name] = attr.value;
533
+ });
534
+ // Set the data for the current row and cell
535
+ dataRow[index] = (_a = td.innerHTML) === null || _a === void 0 ? void 0 : _a.trim();
536
+ dataRowAttribute[index] = attributes;
537
+ });
538
+ // If the row has any data, add it to the original data array
539
+ if (Object.keys(dataRow).length > 0) {
540
+ originalData.push(dataRow);
541
+ originalDataAttributes.push(dataRowAttribute);
542
+ }
543
+ });
544
+ return { originalData: originalData, originalDataAttributes: originalDataAttributes };
545
+ };
546
+ /**
547
+ * Check if the table header is invalidated
548
+ * @returns {boolean} - Returns true if the table header is invalidated, false otherwise
549
+ */
550
+ KTDataTable.prototype._localTableHeaderInvalidate = function () {
551
+ var _a;
552
+ var originalData = this.getState().originalData;
553
+ var currentTableHeaders = ((_a = this._getTableHeaders()) === null || _a === void 0 ? void 0 : _a.length) || 0;
554
+ var totalColumns = originalData.length ? Object.keys(originalData[0]).length : 0;
555
+ return currentTableHeaders !== totalColumns;
556
+ };
557
+ /**
558
+ * Fetch data from the server
559
+ */
560
+ KTDataTable.prototype._fetchDataFromServer = function () {
561
+ return __awaiter(this, void 0, void 0, function () {
562
+ var queryParams, response, responseData, error_1;
563
+ return __generator(this, function (_a) {
564
+ switch (_a.label) {
565
+ case 0:
566
+ this._fireEvent('fetch');
567
+ this._dispatchEvent('fetch');
568
+ queryParams = this._getQueryParamsForFetchRequest();
569
+ return [4 /*yield*/, this._performFetchRequest(queryParams)];
570
+ case 1:
571
+ response = _a.sent();
572
+ responseData = null;
573
+ _a.label = 2;
574
+ case 2:
575
+ _a.trys.push([2, 4, , 5]);
576
+ return [4 /*yield*/, response.json()];
577
+ case 3:
578
+ responseData = _a.sent();
579
+ return [3 /*break*/, 5];
580
+ case 4:
581
+ error_1 = _a.sent();
582
+ this._noticeOnTable('Error parsing API response as JSON: ' + String(error_1));
583
+ return [2 /*return*/];
584
+ case 5:
585
+ this._fireEvent('fetched', { response: responseData });
586
+ this._dispatchEvent('fetched', { response: responseData });
587
+ // Use the mapResponse function to transform the data if provided
588
+ if (typeof this._config.mapResponse === 'function') {
589
+ responseData = this._config.mapResponse.call(this, responseData);
590
+ }
591
+ this._data = responseData.data;
592
+ this._config._state.totalItems = responseData.totalCount;
593
+ return [4 /*yield*/, this._draw()];
594
+ case 6:
595
+ _a.sent();
596
+ return [2 /*return*/];
597
+ }
598
+ });
599
+ });
600
+ };
601
+ /**
602
+ * Get the query params for a fetch request
603
+ * @returns The query params for the fetch request
604
+ */
605
+ KTDataTable.prototype._getQueryParamsForFetchRequest = function () {
606
+ // Get the current state of the datatable
607
+ var _a = this.getState(), page = _a.page, pageSize = _a.pageSize, sortField = _a.sortField, sortOrder = _a.sortOrder, filters = _a.filters, search = _a.search;
608
+ // Create a new URLSearchParams object to store the query params
609
+ var queryParams = new URLSearchParams();
610
+ // Add the current page number and page size to the query params
611
+ queryParams.set('page', String(page));
612
+ queryParams.set('size', String(pageSize));
613
+ // If there is a sort order and field set, add them to the query params
614
+ if (sortOrder !== undefined) {
615
+ queryParams.set('sortOrder', String(sortOrder));
616
+ }
617
+ if (sortField !== undefined) {
618
+ queryParams.set('sortField', String(sortField));
619
+ }
620
+ // If there are any filters set, add them to the query params
621
+ if (Array.isArray(filters) && filters.length) {
622
+ queryParams.set('filters', JSON.stringify(filters.map(function (filter) { return ({
623
+ // Map the filter object to a simpler object with just the necessary properties
624
+ column: filter.column,
625
+ type: filter.type,
626
+ value: filter.value,
627
+ }); })));
628
+ }
629
+ if (search) {
630
+ queryParams.set('search', typeof search === 'object' ? JSON.stringify(search) : search);
631
+ }
632
+ // If a mapRequest function is provided, call it with the query params object
633
+ if (typeof this._config.mapRequest === 'function') {
634
+ queryParams = this._config.mapRequest.call(this, queryParams);
635
+ }
636
+ // Return the query params object
637
+ return queryParams;
638
+ };
639
+ KTDataTable.prototype._performFetchRequest = function (queryParams) {
640
+ return __awaiter(this, void 0, void 0, function () {
641
+ var requestMethod, requestBody, apiEndpointWithQueryParams;
642
+ var _this = this;
643
+ return __generator(this, function (_a) {
644
+ requestMethod = this._config.requestMethod;
645
+ requestBody = undefined;
646
+ // If the request method is POST, send the query params as the request body
647
+ if (requestMethod === 'POST') {
648
+ requestBody = queryParams;
649
+ }
650
+ else if (requestMethod === 'GET') {
651
+ apiEndpointWithQueryParams = new URL(this._config.apiEndpoint);
652
+ apiEndpointWithQueryParams.search = queryParams.toString();
653
+ this._config.apiEndpoint = apiEndpointWithQueryParams.toString();
654
+ }
655
+ return [2 /*return*/, fetch(this._config.apiEndpoint, {
656
+ method: requestMethod,
657
+ body: requestBody,
658
+ headers: this._config.requestHeaders
659
+ }).catch(function (error) {
660
+ _this._noticeOnTable('Error performing fetch request: ' + String(error));
661
+ throw error;
662
+ })];
663
+ });
664
+ });
665
+ };
666
+ /**
667
+ * Update the table and pagination controls with new data
668
+ * @returns {Promise<void>} A promise that resolves when the table and pagination controls are updated
669
+ */
670
+ KTDataTable.prototype._draw = function () {
671
+ return __awaiter(this, void 0, void 0, function () {
672
+ return __generator(this, function (_a) {
673
+ this._config._state.totalPages = Math.ceil(this.getState().totalItems / this.getState().pageSize) || 0;
674
+ this._fireEvent('draw');
675
+ this._dispatchEvent('draw');
676
+ this._dispose();
677
+ // Update the table and pagination controls
678
+ if (this._theadElement && this._tbodyElement) {
679
+ this._updateTable();
680
+ }
681
+ if (this._infoElement && this._paginationElement) {
682
+ this._updatePagination();
683
+ }
684
+ this._fireEvent('drew');
685
+ this._dispatchEvent('drew');
686
+ this._hideSpinner(); // Hide spinner after data is fetched
687
+ if (this._config.stateSave) {
688
+ this._saveState();
689
+ }
690
+ return [2 /*return*/];
691
+ });
692
+ });
693
+ };
694
+ /**
695
+ * Update the HTML table with new data
696
+ * @returns {HTMLTableSectionElement} The new table body element
697
+ */
698
+ KTDataTable.prototype._updateTable = function () {
699
+ // Clear the existing table contents using a more efficient method
700
+ while (this._tableElement.tBodies.length) {
701
+ this._tableElement.removeChild(this._tableElement.tBodies[0]);
702
+ }
703
+ // Create the table body with the new data
704
+ var tbodyElement = this._tableElement.createTBody();
705
+ this._updateTableContent(tbodyElement);
706
+ return tbodyElement;
707
+ };
708
+ /**
709
+ * Initialize the table header
710
+ * Add sort event listener to all sortable columns
711
+ */
712
+ KTDataTable.prototype._initTableHeader = function () {
713
+ var _this = this;
714
+ if (!this._theadElement) {
715
+ return;
716
+ }
717
+ // Set the initial sort icon
718
+ this._setSortIcon(this.getState().sortField, this.getState().sortOrder);
719
+ // Get all the table headers
720
+ var headers = this._getTableHeaders();
721
+ // Loop through each table header
722
+ headers.forEach(function (header) {
723
+ // If the sort class is not found, it's not a sortable column
724
+ if (!header.querySelector(".".concat(_this._config.sort.classes.base))) {
725
+ return;
726
+ }
727
+ var sortAttribute = header.getAttribute('data-datatable-column-sort') || header.getAttribute('data-datatable-column');
728
+ var sortField = sortAttribute ? sortAttribute : header.cellIndex;
729
+ // Add click event listener to the header
730
+ header.addEventListener('click', function () {
731
+ var sortOrder = _this._toggleSortOrder(sortField);
732
+ _this._setSortIcon(sortField, sortOrder);
733
+ _this._sort(sortField);
734
+ });
735
+ });
736
+ };
737
+ /**
738
+ * Returns an array of table headers as HTMLTableCellElement.
739
+ * @returns {HTMLTableCellElement[]} An array of table headers.
740
+ */
741
+ KTDataTable.prototype._getTableHeaders = function () {
742
+ if (!this._theadElement) {
743
+ return [];
744
+ }
745
+ return Array.from(this._theadElement.querySelectorAll('th'));
746
+ };
747
+ /**
748
+ * Sets the sort icon in the table header
749
+ * @param sortField The field to set the sort icon for
750
+ * @param sortOrder The sort order (ascending or descending)
751
+ */
752
+ KTDataTable.prototype._setSortIcon = function (sortField, sortOrder) {
753
+ var sortClass = sortOrder ? (sortOrder === 'asc' ? this._config.sort.classes.asc : this._config.sort.classes.desc) : '';
754
+ // Get the appropriate table header element
755
+ var th = typeof sortField === 'number'
756
+ ? this._theadElement.querySelectorAll('th')[sortField]
757
+ : this._theadElement.querySelector("th[data-datatable-column=\"".concat(String(sortField), "\"], th[data-datatable-column-sort=\"").concat(String(sortField), "\"]"));
758
+ if (th) {
759
+ var sortElement = th.querySelector(".".concat(this._config.sort.classes.base));
760
+ if (sortElement) {
761
+ sortElement.className = "".concat(this._config.sort.classes.base, " ").concat(sortClass).trim();
762
+ }
763
+ }
764
+ };
765
+ /**
766
+ * Toggles the sort order of a column
767
+ * @param sortField The field to toggle the sort order for
768
+ * @returns The new sort order (ascending, descending or unsorted)
769
+ */
770
+ KTDataTable.prototype._toggleSortOrder = function (sortField) {
771
+ var _this = this;
772
+ // If the sort field is the same as the current sort field,
773
+ // toggle the sort order. Otherwise, set the sort order to ascending.
774
+ return (function () {
775
+ if (_this.getState().sortField === sortField) {
776
+ switch (_this.getState().sortOrder) {
777
+ case 'asc':
778
+ return 'desc'; // Descending
779
+ case 'desc':
780
+ return ''; // Unsorted
781
+ default:
782
+ return 'asc'; // Ascending
783
+ }
784
+ }
785
+ return 'asc'; // Ascending
786
+ })();
787
+ };
788
+ /**
789
+ * Update the table content
790
+ * @param tbodyElement The table body element
791
+ * @returns {HTMLTableSectionElement} The updated table body element
792
+ */
793
+ KTDataTable.prototype._updateTableContent = function (tbodyElement) {
794
+ var _this = this;
795
+ var fragment = document.createDocumentFragment();
796
+ tbodyElement.textContent = ''; // Clear the tbody element
797
+ if (this._data.length === 0) {
798
+ this._noticeOnTable(this._config.infoEmpty || '');
799
+ return tbodyElement;
800
+ }
801
+ this._data.forEach(function (item, rowIndex) {
802
+ var row = document.createElement('tr');
803
+ if (!_this._config.columns) {
804
+ var dataRowAttributes_1 = _this.getState().originalDataAttributes
805
+ ? _this.getState().originalDataAttributes[rowIndex]
806
+ : null;
807
+ Object.keys(item).forEach(function (key, colIndex) {
808
+ var td = document.createElement('td');
809
+ td.innerHTML = item[key];
810
+ if (dataRowAttributes_1) {
811
+ for (var attr in dataRowAttributes_1[colIndex]) {
812
+ td.setAttribute(attr, dataRowAttributes_1[colIndex][attr]);
813
+ }
814
+ }
815
+ row.appendChild(td);
816
+ });
817
+ }
818
+ else {
819
+ Object.keys(_this._config.columns).forEach(function (key) {
820
+ var td = document.createElement('td');
821
+ var columnDef = _this._config.columns[key];
822
+ if (typeof columnDef.render === 'function') {
823
+ td.innerHTML = columnDef.render.call(_this, item[key], item, _this);
824
+ }
825
+ else {
826
+ td.textContent = item[key];
827
+ }
828
+ if (typeof columnDef.createdCell === 'function') {
829
+ columnDef.createdCell.call(_this, td, item[key], item, row);
830
+ }
831
+ row.appendChild(td);
832
+ });
833
+ }
834
+ fragment.appendChild(row);
835
+ });
836
+ tbodyElement.appendChild(fragment);
837
+ return tbodyElement;
838
+ };
839
+ /**
840
+ * Show a notice on the table
841
+ * @param message The message to show. If empty, the message will be removed
842
+ * @returns {void}
843
+ */
844
+ KTDataTable.prototype._noticeOnTable = function (message) {
845
+ var _a;
846
+ if (message === void 0) { message = ''; }
847
+ var row = this._tbodyElement.insertRow();
848
+ var cell = row.insertCell();
849
+ cell.colSpan = ((_a = this._getTableHeaders()) === null || _a === void 0 ? void 0 : _a.length) || 0;
850
+ cell.innerHTML = message;
851
+ };
852
+ KTDataTable.prototype._updatePagination = function () {
853
+ this._removeChildElements(this._sizeElement);
854
+ this._createPageSizeControls(this._sizeElement);
855
+ this._removeChildElements(this._paginationElement);
856
+ this._createPaginationControls(this._infoElement, this._paginationElement);
857
+ };
858
+ /**
859
+ * Removes all child elements from the given container element.
860
+ * @param container The container element to remove the child elements from.
861
+ */
862
+ KTDataTable.prototype._removeChildElements = function (container) {
863
+ if (!container) {
864
+ return;
865
+ }
866
+ // Loop through all child elements of the container and remove them one by one
867
+ while (container.firstChild) {
868
+ // Remove the first child element (which is the first element in the list of child elements)
869
+ container.removeChild(container.firstChild);
870
+ }
871
+ };
872
+ /**
873
+ * Creates a container element for the items per page selector.
874
+ * @param _sizeElement The element to create the page size controls in.
875
+ * @returns The container element.
876
+ */
877
+ KTDataTable.prototype._createPageSizeControls = function (_sizeElement) {
878
+ var _this = this;
879
+ // If no element is provided, return early
880
+ if (!_sizeElement) {
881
+ return _sizeElement;
882
+ }
883
+ // Create <option> elements for each page size option
884
+ var options = this._config.pageSizes.map(function (size) {
885
+ var option = document.createElement('option');
886
+ option.value = String(size);
887
+ option.text = String(size);
888
+ option.selected = _this.getState().pageSize === size;
889
+ return option;
890
+ });
891
+ // Add the <option> elements to the provided element
892
+ _sizeElement.append.apply(_sizeElement, options);
893
+ // Create an event listener for the "change" event on the element
894
+ var _pageSizeControlsEvent = function (event) {
895
+ // When the element changes, reload the page with the new page size and page number 1
896
+ _this._reloadPageSize(Number(event.target.value), 1);
897
+ };
898
+ // Bind the event listener to the component instance
899
+ _sizeElement.onchange = _pageSizeControlsEvent.bind(this);
900
+ // Return the element
901
+ return _sizeElement;
902
+ };
903
+ /**
904
+ * Reloads the data with the specified page size and optional page number.
905
+ * @param pageSize The new page size.
906
+ * @param page The new page number (optional, defaults to 1).
907
+ */
908
+ KTDataTable.prototype._reloadPageSize = function (pageSize, page) {
909
+ if (page === void 0) { page = 1; }
910
+ // Update the page size and page number in the state
911
+ this._config._state.pageSize = pageSize;
912
+ this._config._state.page = page;
913
+ // Update the data with the new page size and page number
914
+ this._updateData();
915
+ };
916
+ /**
917
+ * Creates the pagination controls for the component.
918
+ * @param _infoElement The element to set the info text in.
919
+ * @param _paginationElement The element to create the pagination controls in.
920
+ * @return {HTMLElement} The element containing the pagination controls.
921
+ */
922
+ KTDataTable.prototype._createPaginationControls = function (_infoElement, _paginationElement) {
923
+ if (!_infoElement || !_paginationElement || this._data.length === 0) {
924
+ return null;
925
+ }
926
+ this._setPaginationInfoText(_infoElement);
927
+ var paginationContainer = this._createPaginationContainer(_paginationElement);
928
+ if (paginationContainer) {
929
+ this._createPaginationButtons(paginationContainer);
930
+ }
931
+ return paginationContainer;
932
+ };
933
+ /**
934
+ * Sets the info text for the pagination controls.
935
+ * @param _infoElement The element to set the info text in.
936
+ */
937
+ KTDataTable.prototype._setPaginationInfoText = function (_infoElement) {
938
+ _infoElement.textContent = this._config.info
939
+ .replace('{start}', (this.getState().page - 1) * this.getState().pageSize + 1 + '')
940
+ .replace('{end}', Math.min(this.getState().page * this.getState().pageSize, this.getState().totalItems) + '')
941
+ .replace('{total}', this.getState().totalItems + '');
942
+ };
943
+ /**
944
+ * Creates the container element for the pagination controls.
945
+ * @param _paginationElement The element to create the pagination controls in.
946
+ * @return {HTMLElement} The container element.
947
+ */
948
+ KTDataTable.prototype._createPaginationContainer = function (_paginationElement) {
949
+ var paginationContainer = document.createElement('div');
950
+ paginationContainer.className = 'pagination';
951
+ _paginationElement.appendChild(paginationContainer);
952
+ return paginationContainer;
953
+ };
954
+ /**
955
+ * Creates the pagination buttons for the component.
956
+ * @param paginationContainer The container element for the pagination controls.
957
+ */
958
+ KTDataTable.prototype._createPaginationButtons = function (paginationContainer) {
959
+ var _this = this;
960
+ var _a = this.getState(), currentPage = _a.page, totalPages = _a.totalPages;
961
+ var _b = this._config.pagination, previous = _b.previous, next = _b.next, number = _b.number, more = _b.more;
962
+ // Helper function to create a button
963
+ var createButton = function (text, className, disabled, handleClick) {
964
+ var button = document.createElement('button');
965
+ button.className = className;
966
+ button.innerHTML = text;
967
+ button.disabled = disabled;
968
+ button.onclick = handleClick;
969
+ return button;
970
+ };
971
+ // Add Previous Button
972
+ paginationContainer.appendChild(createButton(previous.text, "".concat(previous.class).concat(currentPage === 1 ? ' disabled' : ''), currentPage === 1, function () { return _this._paginateData(currentPage - 1); }));
973
+ // Calculate range of pages
974
+ var pageMoreEnabled = this._config.pageMore;
975
+ if (pageMoreEnabled) {
976
+ var maxButtons = this._config.pageMoreLimit;
977
+ var range_1 = this._calculatePageRange(currentPage, totalPages, maxButtons);
978
+ // Add start ellipsis
979
+ if (range_1.start > 1) {
980
+ paginationContainer.appendChild(createButton(more.text, more.class, false, function () { return _this._paginateData(Math.max(1, range_1.start - 1)); }));
981
+ }
982
+ var _loop_1 = function (i) {
983
+ paginationContainer.appendChild(createButton(number.text.replace('{page}', i.toString()), "".concat(number.class).concat(currentPage === i ? ' active disabled' : ''), currentPage === i, function () { return _this._paginateData(i); }));
984
+ };
985
+ // Add page buttons
986
+ for (var i = range_1.start; i <= range_1.end; i++) {
987
+ _loop_1(i);
988
+ }
989
+ // Add end ellipsis
990
+ if (pageMoreEnabled && range_1.end < totalPages) {
991
+ paginationContainer.appendChild(createButton(more.text, more.class, false, function () { return _this._paginateData(Math.min(totalPages, range_1.end + 1)); }));
992
+ }
993
+ }
994
+ else {
995
+ var _loop_2 = function (i) {
996
+ paginationContainer.appendChild(createButton(number.text.replace('{page}', i.toString()), "".concat(number.class).concat(currentPage === i ? ' active disabled' : ''), currentPage === i, function () { return _this._paginateData(i); }));
997
+ };
998
+ // Add page buttons
999
+ for (var i = 1; i <= totalPages; i++) {
1000
+ _loop_2(i);
1001
+ }
1002
+ }
1003
+ // Add Next Button
1004
+ paginationContainer.appendChild(createButton(next.text, "".concat(next.class).concat(currentPage === totalPages ? ' disabled' : ''), currentPage === totalPages, function () { return _this._paginateData(currentPage + 1); }));
1005
+ };
1006
+ // New helper method to calculate page range
1007
+ KTDataTable.prototype._calculatePageRange = function (currentPage, totalPages, maxButtons) {
1008
+ var startPage, endPage;
1009
+ var halfMaxButtons = Math.floor(maxButtons / 2);
1010
+ if (totalPages <= maxButtons) {
1011
+ startPage = 1;
1012
+ endPage = totalPages;
1013
+ }
1014
+ else {
1015
+ startPage = Math.max(currentPage - halfMaxButtons, 1);
1016
+ endPage = Math.min(startPage + maxButtons - 1, totalPages);
1017
+ if (endPage - startPage < maxButtons - 1) {
1018
+ startPage = Math.max(endPage - maxButtons + 1, 1);
1019
+ }
1020
+ }
1021
+ return { start: startPage, end: endPage };
1022
+ };
1023
+ /**
1024
+ * Method for handling pagination
1025
+ * @param page - The page number to navigate to
1026
+ */
1027
+ KTDataTable.prototype._paginateData = function (page) {
1028
+ if (page < 1 || !Number.isInteger(page)) {
1029
+ return;
1030
+ }
1031
+ this._fireEvent('pagination', { page: page });
1032
+ this._dispatchEvent('pagination', { page: page });
1033
+ if (page >= 1 && page <= this.getState().totalPages) {
1034
+ this._config._state.page = page;
1035
+ this._updateData();
1036
+ }
1037
+ };
1038
+ // Method to show the loading spinner
1039
+ KTDataTable.prototype._showSpinner = function () {
1040
+ var spinner = this._element.querySelector(this._config.attributes.spinner) || this._createSpinner();
1041
+ if (spinner) {
1042
+ spinner.style.display = 'block';
1043
+ }
1044
+ this._element.classList.add('loading');
1045
+ };
1046
+ // Method to hide the loading spinner
1047
+ KTDataTable.prototype._hideSpinner = function () {
1048
+ var spinner = this._element.querySelector(this._config.attributes.spinner);
1049
+ if (spinner) {
1050
+ spinner.style.display = 'none';
1051
+ }
1052
+ this._element.classList.remove('loading');
1053
+ };
1054
+ // Method to create a spinner element if it doesn't exist
1055
+ KTDataTable.prototype._createSpinner = function () {
1056
+ if (typeof this._config.loading === 'undefined') {
1057
+ return null;
1058
+ }
1059
+ var template = document.createElement('template');
1060
+ template.innerHTML = this._config.loading.template.trim().replace('{content}', this._config.loading.content);
1061
+ var spinner = template.content.firstChild;
1062
+ spinner.setAttribute('data-datatable-spinner', 'true');
1063
+ this._tableElement.appendChild(spinner);
1064
+ return spinner;
1065
+ };
1066
+ /**
1067
+ * Saves the current state of the table to local storage.
1068
+ * @returns {void}
1069
+ */
1070
+ KTDataTable.prototype._saveState = function () {
1071
+ this._fireEvent('stateSave');
1072
+ this._dispatchEvent('stateSave');
1073
+ var ns = this._tableNamespace();
1074
+ if (ns) {
1075
+ localStorage.setItem(ns, JSON.stringify(this.getState()));
1076
+ }
1077
+ };
1078
+ /**
1079
+ * Loads the saved state of the table from local storage, if it exists.
1080
+ * @returns {Object} The saved state of the table, or null if no saved state exists.
1081
+ */
1082
+ KTDataTable.prototype._loadState = function () {
1083
+ var stateString = localStorage.getItem(this._tableNamespace());
1084
+ if (!stateString)
1085
+ return null;
1086
+ try {
1087
+ var state = JSON.parse(stateString);
1088
+ if (state)
1089
+ this._config._state = state;
1090
+ return state;
1091
+ }
1092
+ catch (_a) { } // eslint-disable-line no-empty
1093
+ return null;
1094
+ };
1095
+ KTDataTable.prototype._deleteState = function () {
1096
+ var ns = this._tableNamespace();
1097
+ if (ns) {
1098
+ localStorage.removeItem(ns);
1099
+ }
1100
+ };
1101
+ /**
1102
+ * Gets the namespace for the table's state.
1103
+ * If a namespace is specified in the config, it is used.
1104
+ * Otherwise, if the table element has an ID, it is used.
1105
+ * Otherwise, if the component element has an ID, it is used.
1106
+ * Finally, the component's UID is used.
1107
+ * @returns {string} The namespace for the table's state.
1108
+ */
1109
+ KTDataTable.prototype._tableNamespace = function () {
1110
+ var _a;
1111
+ // Use the specified namespace, if one is given
1112
+ if (this._config.stateNamespace) {
1113
+ return this._config.stateNamespace;
1114
+ }
1115
+ // Fallback to the component's UID
1116
+ return (_a = this._tableId()) !== null && _a !== void 0 ? _a : this._name;
1117
+ };
1118
+ KTDataTable.prototype._tableId = function () {
1119
+ var _a, _b;
1120
+ var id = null;
1121
+ // If the table element has an ID, use that
1122
+ if ((_a = this._tableElement) === null || _a === void 0 ? void 0 : _a.getAttribute('id')) {
1123
+ id = this._tableElement.getAttribute('id');
1124
+ }
1125
+ // If the component element has an ID, use that
1126
+ if ((_b = this._element) === null || _b === void 0 ? void 0 : _b.getAttribute('id')) {
1127
+ id = this._element.getAttribute('id');
1128
+ }
1129
+ return id;
1130
+ };
1131
+ /**
1132
+ * Sorts the data in the table by the specified field.
1133
+ * @param sortField The field to sort by.
1134
+ */
1135
+ KTDataTable.prototype._sort = function (sortField) {
1136
+ // Determine the new sort order based on the current state
1137
+ var newSortOrder = this._toggleSortOrder(sortField);
1138
+ // Update the current sort field and order
1139
+ this._config._state.sortField = sortField;
1140
+ this._config._state.sortOrder = newSortOrder;
1141
+ this._fireEvent('sort', { field: sortField, order: newSortOrder });
1142
+ this._dispatchEvent('sort', { field: sortField, order: newSortOrder });
1143
+ // Fetch data from the server with the new sort order
1144
+ this._updateData();
1145
+ };
1146
+ KTDataTable.prototype._dispose = function () {
1147
+ if (this._headerCheckElement) {
1148
+ this._headerCheckElement.removeEventListener('click', this._checkboxListener);
1149
+ }
1150
+ };
1151
+ KTDataTable.prototype._debounce = function (func, wait) {
1152
+ var timeout;
1153
+ return function () {
1154
+ var args = [];
1155
+ for (var _i = 0; _i < arguments.length; _i++) {
1156
+ args[_i] = arguments[_i];
1157
+ }
1158
+ var later = function () {
1159
+ clearTimeout(timeout);
1160
+ func.apply(void 0, args);
1161
+ };
1162
+ clearTimeout(timeout);
1163
+ timeout = window.setTimeout(later, wait);
1164
+ };
1165
+ };
1166
+ /**
1167
+ * Event handlers
1168
+ */
1169
+ KTDataTable.prototype._checkboxHandler = function () {
1170
+ var _this = this;
1171
+ // Handle header checkbox change event
1172
+ this._headerCheckElement.addEventListener('click', this._checkboxListener);
1173
+ // Handle target checbox change event
1174
+ event_handler_1.default.on(document.body, this._config.attributes.checkbox, 'input', function (event) {
1175
+ _this._checkboxUpdate(event); // Update checkbox state based on checked rows
1176
+ });
1177
+ };
1178
+ /**
1179
+ * Checks if element is checked
1180
+ * @returns {boolean}
1181
+ */
1182
+ KTDataTable.prototype._isChecked = function () {
1183
+ return this._headerChecked;
1184
+ };
1185
+ /**
1186
+ * Change checkbox state
1187
+ * @param checked The new state of the checkbox
1188
+ * @returns {void}
1189
+ */
1190
+ KTDataTable.prototype._change = function (checked) {
1191
+ var payload = { cancel: false };
1192
+ this._fireEvent('change', payload);
1193
+ this._dispatchEvent('change', payload);
1194
+ if (payload.cancel === true) {
1195
+ return;
1196
+ }
1197
+ this._headerChecked = checked;
1198
+ this._headerCheckElement.checked = checked;
1199
+ if (this._targetElements) {
1200
+ this._targetElements.forEach(function (element) {
1201
+ if (element) {
1202
+ element.checked = checked;
1203
+ }
1204
+ });
1205
+ }
1206
+ this._fireEvent('changed');
1207
+ this._dispatchEvent('changed');
1208
+ };
1209
+ /**
1210
+ * Toggle checkbox state
1211
+ * @param event The event if available
1212
+ * @returns {void}
1213
+ */
1214
+ KTDataTable.prototype._checkboxToggle = function (event) {
1215
+ var checked = !this._isChecked();
1216
+ var eventType = checked ? 'checked' : 'unchecked';
1217
+ this._fireEvent(eventType);
1218
+ this._dispatchEvent(eventType);
1219
+ this._change(checked);
1220
+ };
1221
+ /**
1222
+ * Update checkbox state based on checked rows
1223
+ * @param event The event if available
1224
+ * @returns {void}
1225
+ */
1226
+ KTDataTable.prototype._checkboxUpdate = function (event) {
1227
+ var checked = 0;
1228
+ var total = this._targetElements.length;
1229
+ for (var i = 0; i < total; i++) {
1230
+ var element = this._targetElements[i];
1231
+ if (!element) {
1232
+ continue;
1233
+ }
1234
+ var row = element.closest('tr');
1235
+ if (!row) {
1236
+ continue;
1237
+ }
1238
+ if (element.checked) {
1239
+ row.classList.add(this._config.checkbox.checkedClass);
1240
+ checked++;
1241
+ }
1242
+ else {
1243
+ row.classList.remove(this._config.checkbox.checkedClass);
1244
+ }
1245
+ }
1246
+ if (checked === 0) {
1247
+ this._headerCheckElement.indeterminate = false;
1248
+ this._change(false);
1249
+ }
1250
+ if (checked > 0 && checked < total) {
1251
+ this._headerCheckElement.indeterminate = true;
1252
+ }
1253
+ if (checked === total) {
1254
+ this._headerCheckElement.indeterminate = false;
1255
+ this._change(true);
1256
+ }
1257
+ };
1258
+ /**
1259
+ * Get checked row IDs
1260
+ * @returns {string[]} An array of checked row IDs
1261
+ */
1262
+ KTDataTable.prototype._getChecked = function () {
1263
+ var checked = [];
1264
+ this._targetElements.forEach(function (element) {
1265
+ if (element && element.checked) {
1266
+ var value = element.value;
1267
+ if (value) {
1268
+ checked.push(value);
1269
+ }
1270
+ }
1271
+ });
1272
+ return checked;
1273
+ };
1274
+ KTDataTable.prototype.isChecked = function () {
1275
+ return this._isChecked();
1276
+ };
1277
+ KTDataTable.prototype.toggle = function () {
1278
+ this._checkboxToggle();
1279
+ };
1280
+ /**
1281
+ * Check all rows
1282
+ * @returns {void}
1283
+ */
1284
+ KTDataTable.prototype.check = function () {
1285
+ this._change(true);
1286
+ this._checkboxUpdate();
1287
+ };
1288
+ /**
1289
+ * Uncheck all rows
1290
+ * @returns {void}
1291
+ */
1292
+ KTDataTable.prototype.uncheck = function () {
1293
+ this._change(false);
1294
+ };
1295
+ /**
1296
+ * Get checked row IDs
1297
+ * @returns {string[]} An array of checked row IDs
1298
+ */
1299
+ KTDataTable.prototype.getChecked = function () {
1300
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
1301
+ return this._getChecked();
1302
+ };
1303
+ KTDataTable.prototype.update = function () {
1304
+ this._checkboxUpdate();
1305
+ };
1306
+ /**
1307
+ * Gets the current state of the table.
1308
+ * @returns {KTDataTableStateInterface} The current state of the table.
1309
+ */
1310
+ KTDataTable.prototype.getState = function () {
1311
+ return __assign({
1312
+ /**
1313
+ * The current page number.
1314
+ */
1315
+ page: 1,
1316
+ /**
1317
+ * The field that the data is sorted by.
1318
+ */
1319
+ sortField: null,
1320
+ /**
1321
+ * The sort order (ascending or descending).
1322
+ */
1323
+ sortOrder: '',
1324
+ /**
1325
+ * The number of rows to display per page.
1326
+ */
1327
+ pageSize: this._config.pageSize, filters: [] }, this._config._state);
1328
+ };
1329
+ /**
1330
+ * Sorts the data in the table by the specified field.
1331
+ * @param field The field to sort by.
1332
+ */
1333
+ KTDataTable.prototype.sort = function (field) {
1334
+ // Sort the data
1335
+ this._sort(field);
1336
+ };
1337
+ /**
1338
+ * Navigates to the specified page in the data table.
1339
+ * @param page The page number to navigate to.
1340
+ */
1341
+ KTDataTable.prototype.goPage = function (page) {
1342
+ if (page < 1 || !Number.isInteger(page)) {
1343
+ return;
1344
+ }
1345
+ // Navigate to the specified page
1346
+ this._paginateData(page);
1347
+ };
1348
+ /**
1349
+ * Set the page size of the data table.
1350
+ * @param pageSize The new page size.
1351
+ */
1352
+ KTDataTable.prototype.setPageSize = function (pageSize) {
1353
+ if (!Number.isInteger(pageSize)) {
1354
+ return;
1355
+ }
1356
+ /**
1357
+ * Reload the page size of the data table.
1358
+ * @param pageSize The new page size.
1359
+ */
1360
+ this._reloadPageSize(pageSize);
1361
+ };
1362
+ /**
1363
+ * Reloads the data from the server and updates the table.
1364
+ * Triggers the 'reload' event and the 'kt.datatable.reload' custom event.
1365
+ */
1366
+ KTDataTable.prototype.reload = function () {
1367
+ this._fireEvent('reload');
1368
+ this._dispatchEvent('reload');
1369
+ // Fetch the data from the server using the current sort and filter settings
1370
+ this._updateData();
1371
+ };
1372
+ KTDataTable.prototype.redraw = function (page) {
1373
+ if (page === void 0) { page = 1; }
1374
+ this._fireEvent('redraw');
1375
+ this._dispatchEvent('redraw');
1376
+ this._paginateData(page);
1377
+ };
1378
+ /**
1379
+ * Show the loading spinner of the data table.
1380
+ */
1381
+ KTDataTable.prototype.showSpinner = function () {
1382
+ /**
1383
+ * Show the loading spinner of the data table.
1384
+ */
1385
+ this._showSpinner();
1386
+ };
1387
+ /**
1388
+ * Hide the loading spinner of the data table.
1389
+ */
1390
+ KTDataTable.prototype.hideSpinner = function () {
1391
+ /**
1392
+ * Hide the loading spinner of the data table.
1393
+ */
1394
+ this._hideSpinner();
1395
+ };
1396
+ /**
1397
+ * Filter data using the specified filter object.
1398
+ * Replaces the existing filter object for the column with the new one.
1399
+ * @param filter Filter object containing the column name and its value.
1400
+ * @returns The KTDataTable instance.
1401
+ * @throws Error if the filter object is null or undefined.
1402
+ */
1403
+ KTDataTable.prototype.setFilter = function (filter) {
1404
+ this._config._state.filters = __spreadArray(__spreadArray([], (this.getState().filters || []).filter(function (f) { return f.column !== filter.column; }), true), [
1405
+ filter
1406
+ ], false);
1407
+ return this;
1408
+ };
1409
+ KTDataTable.prototype.dispose = function () {
1410
+ this._dispose();
1411
+ };
1412
+ KTDataTable.prototype.search = function (query) {
1413
+ this._config._state.search = query;
1414
+ this.reload();
1415
+ };
1416
+ /**
1417
+ * Create KTDataTable instances for all elements with a data-datatable="true" attribute.
1418
+ *
1419
+ * This function should be called after the control(s) have been
1420
+ * loaded and parsed by the browser. It will create instances of
1421
+ * KTDataTable for all elements with a data-datatable="true" attribute.
1422
+ */
1423
+ KTDataTable.createInstances = function () {
1424
+ var _this = this;
1425
+ var elements = document.querySelectorAll('[data-datatable="true"]');
1426
+ elements.forEach(function (element) {
1427
+ if (element.hasAttribute('data-datatable') && !element.classList.contains('datatable-initialized')) {
1428
+ /**
1429
+ * Create an instance of KTDataTable for the given element
1430
+ * @param element The element to create an instance for
1431
+ */
1432
+ var instance = new KTDataTable(element);
1433
+ _this._instances.set(element, instance);
1434
+ }
1435
+ });
1436
+ };
1437
+ /**
1438
+ * Get the KTDataTable instance for a given element.
1439
+ *
1440
+ * @param element The element to retrieve the instance for
1441
+ * @returns The KTDataTable instance or undefined if not found
1442
+ */
1443
+ KTDataTable.getInstance = function (element) {
1444
+ return this._instances.get(element);
1445
+ };
1446
+ /**
1447
+ * Initializes all KTDataTable instances on the page.
1448
+ *
1449
+ * This function should be called after the control(s) have been
1450
+ * loaded and parsed by the browser.
1451
+ */
1452
+ KTDataTable.init = function () {
1453
+ // Create instances of KTDataTable for all elements with a
1454
+ // data-datatable="true" attribute
1455
+ KTDataTable.createInstances();
1456
+ };
1457
+ /**
1458
+ * Static variables
1459
+ */
1460
+ KTDataTable._instances = new Map();
1461
+ return KTDataTable;
1462
+ }(component_1.default));
1463
+ exports.KTDataTable = KTDataTable;
1464
+ //# sourceMappingURL=datatable.js.map