namirasoft-site-react 1.4.553 → 1.4.554

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 (472) hide show
  1. package/.dockerignore +86 -86
  2. package/.env.template +10 -10
  3. package/Dockerfile +18 -18
  4. package/SKILL.md +307 -307
  5. package/config-overrides.js +72 -72
  6. package/dist/App.css +34 -0
  7. package/dist/App.d.ts +1 -1
  8. package/dist/NSBoxBuilder.d.ts +25 -25
  9. package/dist/components/NSBanner.d.ts +1 -1
  10. package/dist/components/NSBanner.module.css +47 -47
  11. package/dist/components/NSBarAction.d.ts +1 -1
  12. package/dist/components/NSBarAction.module.css +91 -91
  13. package/dist/components/NSBarAlert.d.ts +1 -1
  14. package/dist/components/NSBarAlert.module.css +79 -79
  15. package/dist/components/NSBarNotification.d.ts +1 -1
  16. package/dist/components/NSBarNotification.module.css +34 -34
  17. package/dist/components/NSBarTitle.d.ts +1 -1
  18. package/dist/components/NSBarTitle.module.css +9 -9
  19. package/dist/components/NSBox.module.css +87 -87
  20. package/dist/components/NSBoxBaseCombo.d.ts +1 -1
  21. package/dist/components/NSBoxBaseCombo.module.css +6 -6
  22. package/dist/components/NSBoxBaseLayout.d.ts +1 -1
  23. package/dist/components/NSBoxBaseLayoutRecursive.d.ts +1 -1
  24. package/dist/components/NSBoxBoolean.d.ts +1 -1
  25. package/dist/components/NSBoxBoolean.module.css +73 -73
  26. package/dist/components/NSBoxBooleans.d.ts +1 -1
  27. package/dist/components/NSBoxColor.d.ts +1 -1
  28. package/dist/components/NSBoxCombo.d.ts +1 -1
  29. package/dist/components/NSBoxDate.d.ts +1 -1
  30. package/dist/components/NSBoxDate.module.css +4 -4
  31. package/dist/components/NSBoxDateRange.d.ts +1 -1
  32. package/dist/components/NSBoxDateRangeBase.d.ts +1 -1
  33. package/dist/components/NSBoxDateRangeBase.module.css +73 -73
  34. package/dist/components/NSBoxDateTime.d.ts +1 -1
  35. package/dist/components/NSBoxDateTime.module.css +4 -4
  36. package/dist/components/NSBoxDateTimeRange.d.ts +1 -1
  37. package/dist/components/NSBoxDouble.d.ts +1 -1
  38. package/dist/components/NSBoxDuration.d.ts +1 -1
  39. package/dist/components/NSBoxDuration.module.css +4 -4
  40. package/dist/components/NSBoxDynamic.d.ts +1 -1
  41. package/dist/components/NSBoxDynamics.d.ts +1 -1
  42. package/dist/components/NSBoxEmail.d.ts +1 -1
  43. package/dist/components/NSBoxEntity.d.ts +1 -1
  44. package/dist/components/NSBoxEnum.d.ts +1 -1
  45. package/dist/components/NSBoxFile.d.ts +1 -1
  46. package/dist/components/NSBoxFile.module.css +10 -10
  47. package/dist/components/NSBoxFilePath.d.ts +1 -1
  48. package/dist/components/NSBoxFont.d.ts +1 -1
  49. package/dist/components/NSBoxIPV4.d.ts +1 -1
  50. package/dist/components/NSBoxIPV4Range.d.ts +1 -1
  51. package/dist/components/NSBoxIPV6.d.ts +1 -1
  52. package/dist/components/NSBoxIPV6Range.d.ts +1 -1
  53. package/dist/components/NSBoxInteger.d.ts +1 -1
  54. package/dist/components/NSBoxInteger.module.css +16 -16
  55. package/dist/components/NSBoxMoney.d.ts +1 -1
  56. package/dist/components/NSBoxPhone.d.ts +1 -1
  57. package/dist/components/NSBoxPhone.module.css +35 -35
  58. package/dist/components/NSBoxRadio.d.ts +1 -1
  59. package/dist/components/NSBoxRadio.module.css +33 -33
  60. package/dist/components/NSBoxSchemaBase.d.ts +1 -1
  61. package/dist/components/NSBoxSchemaBase.module.css +17 -17
  62. package/dist/components/NSBoxSchemaVariable.d.ts +1 -1
  63. package/dist/components/NSBoxSchemaVariable.module.css +16 -16
  64. package/dist/components/NSBoxSearch.d.ts +1 -1
  65. package/dist/components/NSBoxSensitive.d.ts +1 -1
  66. package/dist/components/NSBoxString.d.ts +1 -1
  67. package/dist/components/NSBoxTextArea.d.ts +1 -1
  68. package/dist/components/NSBoxTextArea.module.css +12 -12
  69. package/dist/components/NSBoxTime.d.ts +1 -1
  70. package/dist/components/NSBoxTime.module.css +4 -4
  71. package/dist/components/NSBoxTimeRange.d.ts +1 -1
  72. package/dist/components/NSBoxTimeZone.d.ts +1 -1
  73. package/dist/components/NSBoxURL.d.ts +1 -1
  74. package/dist/components/NSBoxVersion.d.ts +1 -1
  75. package/dist/components/NSButton.module.css +57 -57
  76. package/dist/components/NSButtonBlue.d.ts +1 -1
  77. package/dist/components/NSButtonBlue.module.css +4 -4
  78. package/dist/components/NSButtonGreen.d.ts +1 -1
  79. package/dist/components/NSButtonGreen.module.css +4 -4
  80. package/dist/components/NSButtonRed.d.ts +1 -1
  81. package/dist/components/NSButtonRed.module.css +4 -4
  82. package/dist/components/NSCard.d.ts +1 -1
  83. package/dist/components/NSCard.module.css +113 -113
  84. package/dist/components/NSCardScreenshot.d.ts +1 -1
  85. package/dist/components/NSCardScreenshot.module.css +41 -41
  86. package/dist/components/NSChartColumn.d.ts +1 -1
  87. package/dist/components/NSChartColumn.module.css +7 -7
  88. package/dist/components/NSChartDoughnut.d.ts +1 -1
  89. package/dist/components/NSChartPie.d.ts +1 -1
  90. package/dist/components/NSChartRange.d.ts +1 -1
  91. package/dist/components/NSChartTable.d.ts +1 -1
  92. package/dist/components/NSChartTable.module.css +21 -21
  93. package/dist/components/NSColumn.d.ts +1 -1
  94. package/dist/components/NSColumn.module.css +16 -16
  95. package/dist/components/NSCopy.d.ts +1 -1
  96. package/dist/components/NSCopyBox.d.ts +1 -1
  97. package/dist/components/NSCopyBox.module.css +39 -39
  98. package/dist/components/NSDialog.d.ts +1 -1
  99. package/dist/components/NSDialog.module.css +105 -105
  100. package/dist/components/NSDialogBox.d.ts +1 -1
  101. package/dist/components/NSDialogBoxDate.d.ts +1 -1
  102. package/dist/components/NSDialogBoxDateTime.d.ts +1 -1
  103. package/dist/components/NSDialogBoxPhone.d.ts +1 -1
  104. package/dist/components/NSDialogBoxString.d.ts +1 -1
  105. package/dist/components/NSDialogDelete.d.ts +1 -1
  106. package/dist/components/NSDialogInfo.d.ts +1 -1
  107. package/dist/components/NSDialogPageSelection.d.ts +2 -2
  108. package/dist/components/NSDialogPageSelection.module.css +103 -103
  109. package/dist/components/NSDownTimer.d.ts +1 -1
  110. package/dist/components/NSDownTimer.module.css +55 -55
  111. package/dist/components/NSDownload.d.ts +1 -1
  112. package/dist/components/NSDownload.module.css +46 -46
  113. package/dist/components/NSElectronicCard.d.ts +1 -1
  114. package/dist/components/NSElectronicCard.module.css +60 -60
  115. package/dist/components/NSEntityCardBackground.d.ts +1 -1
  116. package/dist/components/NSEntityCardBackground.module.css +27 -27
  117. package/dist/components/NSFilterBox.d.ts +2 -2
  118. package/dist/components/NSFilterBox.module.css +27 -27
  119. package/dist/components/NSFilterBoxItems.d.ts +1 -1
  120. package/dist/components/NSFilterBoxItems.module.css +15 -15
  121. package/dist/components/NSFilterItem.d.ts +1 -1
  122. package/dist/components/NSFilterItem.module.css +24 -24
  123. package/dist/components/NSFooter.d.ts +1 -1
  124. package/dist/components/NSFooter.module.css +140 -140
  125. package/dist/components/NSGauge.d.ts +1 -1
  126. package/dist/components/NSGauge.module.css +67 -67
  127. package/dist/components/NSGaugeDate.d.ts +1 -1
  128. package/dist/components/NSGaugeDate.module.css +57 -57
  129. package/dist/components/NSGaugeNumber.d.ts +1 -1
  130. package/dist/components/NSGaugeNumber.module.css +66 -66
  131. package/dist/components/NSHeader.d.ts +1 -1
  132. package/dist/components/NSHeader.module.css +316 -316
  133. package/dist/components/NSHeaderScreenshot.d.ts +1 -1
  134. package/dist/components/NSHeaderScreenshot.module.css +35 -35
  135. package/dist/components/NSID.d.ts +1 -1
  136. package/dist/components/NSInfo.d.ts +1 -1
  137. package/dist/components/NSLabel.d.ts +1 -1
  138. package/dist/components/NSLabel.module.css +25 -25
  139. package/dist/components/NSLabelErrorNotifier.d.ts +1 -1
  140. package/dist/components/NSLabelErrorNotifier.module.css +2 -2
  141. package/dist/components/NSLabelSensitive.d.ts +1 -1
  142. package/dist/components/NSLabelSensitive.module.css +9 -9
  143. package/dist/components/NSLayout.d.ts +1 -1
  144. package/dist/components/NSLayout.module.css +23 -23
  145. package/dist/components/NSLine.d.ts +1 -1
  146. package/dist/components/NSLine.module.css +15 -15
  147. package/dist/components/NSLineText.d.ts +1 -1
  148. package/dist/components/NSLineText.module.css +38 -38
  149. package/dist/components/NSLink.d.ts +1 -1
  150. package/dist/components/NSLink.module.css +36 -36
  151. package/dist/components/NSLinkBlue.d.ts +1 -1
  152. package/dist/components/NSLinkGreen.d.ts +1 -1
  153. package/dist/components/NSLinkRed.d.ts +1 -1
  154. package/dist/components/NSListGrouped.d.ts +1 -1
  155. package/dist/components/NSListGrouped.module.css +69 -69
  156. package/dist/components/NSListProduct.d.ts +1 -1
  157. package/dist/components/NSLoading.d.ts +1 -1
  158. package/dist/components/NSLoading.module.css +10 -10
  159. package/dist/components/NSMegaMenu.d.ts +1 -1
  160. package/dist/components/NSMegaMenu.module.css +133 -133
  161. package/dist/components/NSMenuAction.d.ts +1 -1
  162. package/dist/components/NSMenuAction.module.css +88 -88
  163. package/dist/components/NSMenuButton.d.ts +1 -1
  164. package/dist/components/NSMenuButton.module.css +44 -44
  165. package/dist/components/NSNoData.d.ts +1 -1
  166. package/dist/components/NSNoData.module.css +11 -11
  167. package/dist/components/NSPagination.d.ts +1 -1
  168. package/dist/components/NSPagination.module.css +86 -86
  169. package/dist/components/NSPanel.d.ts +1 -1
  170. package/dist/components/NSPanel.module.css +19 -19
  171. package/dist/components/NSPanelAccordion.d.ts +1 -1
  172. package/dist/components/NSPanelAccordion.module.css +4 -4
  173. package/dist/components/NSProductSearch.d.ts +1 -1
  174. package/dist/components/NSProductSearch.module.css +73 -73
  175. package/dist/components/NSProgressBar.d.ts +1 -1
  176. package/dist/components/NSProgressBar.module.css +38 -38
  177. package/dist/components/NSRange.d.ts +1 -1
  178. package/dist/components/NSRange.module.css +66 -66
  179. package/dist/components/NSRepeater.d.ts +1 -1
  180. package/dist/components/NSRepeaterNSBoxSchemaVariable.d.ts +1 -1
  181. package/dist/components/NSRepeaterNSTag.d.ts +1 -1
  182. package/dist/components/NSRow.d.ts +1 -1
  183. package/dist/components/NSRow.module.css +17 -17
  184. package/dist/components/NSSection.d.ts +1 -1
  185. package/dist/components/NSSection.module.css +4 -4
  186. package/dist/components/NSSectionCards.d.ts +1 -1
  187. package/dist/components/NSSectionCards.module.css +38 -38
  188. package/dist/components/NSSectionTiles.d.ts +1 -1
  189. package/dist/components/NSSectionTiles.module.css +10 -10
  190. package/dist/components/NSSectionTitle.d.ts +1 -1
  191. package/dist/components/NSSpace.d.ts +1 -1
  192. package/dist/components/NSSplitter.d.ts +1 -1
  193. package/dist/components/NSSplitter.module.css +58 -58
  194. package/dist/components/NSTabPage.d.ts +1 -1
  195. package/dist/components/NSTabPage.module.css +59 -59
  196. package/dist/components/NSTable.d.ts +1 -1
  197. package/dist/components/NSTable.js +1 -1
  198. package/dist/components/NSTable.js.map +1 -1
  199. package/dist/components/NSTable.module.css +411 -411
  200. package/dist/components/NSTag.d.ts +1 -1
  201. package/dist/components/NSTile.d.ts +1 -1
  202. package/dist/components/NSTile.module.css +76 -76
  203. package/dist/components/NSTimelineMonthly.d.ts +1 -1
  204. package/dist/components/NSTimelineMonthly.module.css +71 -71
  205. package/dist/components/NSTitle.d.ts +1 -1
  206. package/dist/components/NSTitle.module.css +15 -15
  207. package/dist/formatter/StringFormatter.d.ts +1 -1
  208. package/dist/index.css +6 -0
  209. package/dist/pages/NSImplementing.d.ts +1 -1
  210. package/dist/pages/NSImplementing.module.css +35 -35
  211. package/dist/pages/NSNotFoundPage.d.ts +1 -1
  212. package/dist/pages/NSNotFoundPage.module.css +18 -18
  213. package/dist/pages/NSUpdating.d.ts +1 -1
  214. package/dist/pages/NSUpdating.module.css +35 -35
  215. package/package.json +86 -86
  216. package/public/index.html +38 -38
  217. package/src/App.css +33 -33
  218. package/src/App.tsx +198 -198
  219. package/src/Color.tsx +10 -10
  220. package/src/CopyToClipboard.ts +6 -6
  221. package/src/EncryptionOperation.ts +98 -98
  222. package/src/NSBoxBuilder.tsx +922 -922
  223. package/src/ProductCacheService.ts +15 -15
  224. package/src/Validator.ts +199 -199
  225. package/src/components/INSBox.tsx +7 -7
  226. package/src/components/NSBanner.module.css +47 -47
  227. package/src/components/NSBanner.tsx +80 -80
  228. package/src/components/NSBarAction.module.css +91 -91
  229. package/src/components/NSBarAction.tsx +95 -95
  230. package/src/components/NSBarAlert.module.css +79 -79
  231. package/src/components/NSBarAlert.tsx +35 -35
  232. package/src/components/NSBarNotification.module.css +34 -34
  233. package/src/components/NSBarNotification.tsx +86 -86
  234. package/src/components/NSBarTitle.module.css +9 -9
  235. package/src/components/NSBarTitle.tsx +23 -23
  236. package/src/components/NSBox.module.css +87 -87
  237. package/src/components/NSBox.tsx +19 -19
  238. package/src/components/NSBoxBaseCombo.module.css +6 -6
  239. package/src/components/NSBoxBaseCombo.tsx +479 -479
  240. package/src/components/NSBoxBaseLayout.tsx +163 -163
  241. package/src/components/NSBoxBaseLayoutRecursive.tsx +59 -59
  242. package/src/components/NSBoxBoolean.module.css +73 -73
  243. package/src/components/NSBoxBoolean.tsx +152 -152
  244. package/src/components/NSBoxBooleans.tsx +181 -181
  245. package/src/components/NSBoxColor.tsx +107 -107
  246. package/src/components/NSBoxCombo.tsx +95 -95
  247. package/src/components/NSBoxDate.module.css +4 -4
  248. package/src/components/NSBoxDate.tsx +119 -119
  249. package/src/components/NSBoxDateRange.tsx +88 -88
  250. package/src/components/NSBoxDateRangeBase.module.css +73 -73
  251. package/src/components/NSBoxDateRangeBase.tsx +198 -198
  252. package/src/components/NSBoxDateTime.module.css +4 -4
  253. package/src/components/NSBoxDateTime.tsx +116 -116
  254. package/src/components/NSBoxDateTimeRange.tsx +65 -65
  255. package/src/components/NSBoxDouble.tsx +110 -110
  256. package/src/components/NSBoxDuration.module.css +4 -4
  257. package/src/components/NSBoxDuration.tsx +107 -107
  258. package/src/components/NSBoxDynamic.tsx +77 -77
  259. package/src/components/NSBoxDynamics.tsx +68 -68
  260. package/src/components/NSBoxEmail.tsx +117 -117
  261. package/src/components/NSBoxEntity.tsx +181 -181
  262. package/src/components/NSBoxEnum.tsx +113 -113
  263. package/src/components/NSBoxFile.module.css +10 -10
  264. package/src/components/NSBoxFile.tsx +106 -106
  265. package/src/components/NSBoxFilePath.tsx +106 -106
  266. package/src/components/NSBoxFont.tsx +107 -107
  267. package/src/components/NSBoxIPV4.tsx +107 -107
  268. package/src/components/NSBoxIPV4Range.tsx +107 -107
  269. package/src/components/NSBoxIPV6.tsx +104 -104
  270. package/src/components/NSBoxIPV6Range.tsx +107 -107
  271. package/src/components/NSBoxInteger.module.css +16 -16
  272. package/src/components/NSBoxInteger.tsx +126 -126
  273. package/src/components/NSBoxMoney.tsx +115 -115
  274. package/src/components/NSBoxPhone.module.css +35 -35
  275. package/src/components/NSBoxPhone.tsx +120 -120
  276. package/src/components/NSBoxRadio.module.css +33 -33
  277. package/src/components/NSBoxRadio.tsx +104 -104
  278. package/src/components/NSBoxSchemaBase.module.css +17 -17
  279. package/src/components/NSBoxSchemaBase.tsx +562 -562
  280. package/src/components/NSBoxSchemaVariable.module.css +16 -16
  281. package/src/components/NSBoxSchemaVariable.tsx +263 -263
  282. package/src/components/NSBoxSearch.tsx +112 -112
  283. package/src/components/NSBoxSensitive.tsx +133 -133
  284. package/src/components/NSBoxString.tsx +106 -106
  285. package/src/components/NSBoxTextArea.module.css +12 -12
  286. package/src/components/NSBoxTextArea.tsx +136 -136
  287. package/src/components/NSBoxTime.module.css +4 -4
  288. package/src/components/NSBoxTime.tsx +106 -106
  289. package/src/components/NSBoxTimeRange.tsx +220 -220
  290. package/src/components/NSBoxTimeZone.tsx +122 -122
  291. package/src/components/NSBoxURL.tsx +117 -117
  292. package/src/components/NSBoxVersion.tsx +107 -107
  293. package/src/components/NSButton.module.css +57 -57
  294. package/src/components/NSButton.tsx +74 -74
  295. package/src/components/NSButtonBlue.module.css +4 -4
  296. package/src/components/NSButtonBlue.tsx +29 -29
  297. package/src/components/NSButtonGreen.module.css +4 -4
  298. package/src/components/NSButtonGreen.tsx +29 -29
  299. package/src/components/NSButtonRed.module.css +4 -4
  300. package/src/components/NSButtonRed.tsx +29 -29
  301. package/src/components/NSCard.module.css +113 -113
  302. package/src/components/NSCard.tsx +67 -67
  303. package/src/components/NSCardScreenshot.module.css +41 -41
  304. package/src/components/NSCardScreenshot.tsx +31 -31
  305. package/src/components/NSChartColumn.module.css +7 -7
  306. package/src/components/NSChartColumn.tsx +130 -130
  307. package/src/components/NSChartDoughnut.tsx +112 -112
  308. package/src/components/NSChartPie.tsx +105 -105
  309. package/src/components/NSChartRange.tsx +14 -14
  310. package/src/components/NSChartTable.module.css +21 -21
  311. package/src/components/NSChartTable.tsx +94 -94
  312. package/src/components/NSColumn.module.css +16 -16
  313. package/src/components/NSColumn.tsx +24 -24
  314. package/src/components/NSCopy.tsx +58 -58
  315. package/src/components/NSCopyBox.module.css +39 -39
  316. package/src/components/NSCopyBox.tsx +53 -53
  317. package/src/components/NSDialog.module.css +105 -105
  318. package/src/components/NSDialog.tsx +72 -72
  319. package/src/components/NSDialogBox.tsx +38 -38
  320. package/src/components/NSDialogBoxDate.tsx +28 -28
  321. package/src/components/NSDialogBoxDateTime.tsx +28 -28
  322. package/src/components/NSDialogBoxPhone.tsx +28 -28
  323. package/src/components/NSDialogBoxString.tsx +28 -28
  324. package/src/components/NSDialogDelete.tsx +36 -36
  325. package/src/components/NSDialogInfo.tsx +49 -49
  326. package/src/components/NSDialogPageSelection.module.css +103 -103
  327. package/src/components/NSDialogPageSelection.tsx +219 -219
  328. package/src/components/NSDownTimer.module.css +55 -55
  329. package/src/components/NSDownTimer.tsx +91 -91
  330. package/src/components/NSDownload.module.css +46 -46
  331. package/src/components/NSDownload.tsx +69 -69
  332. package/src/components/NSElectronicCard.module.css +60 -60
  333. package/src/components/NSElectronicCard.tsx +46 -46
  334. package/src/components/NSEntityCardBackground.module.css +27 -27
  335. package/src/components/NSEntityCardBackground.tsx +36 -36
  336. package/src/components/NSFilterBox.module.css +27 -27
  337. package/src/components/NSFilterBox.tsx +477 -477
  338. package/src/components/NSFilterBoxItems.module.css +15 -15
  339. package/src/components/NSFilterBoxItems.tsx +52 -52
  340. package/src/components/NSFilterItem.module.css +24 -24
  341. package/src/components/NSFilterItem.tsx +27 -27
  342. package/src/components/NSFooter.module.css +140 -140
  343. package/src/components/NSFooter.tsx +321 -321
  344. package/src/components/NSGauge.module.css +67 -67
  345. package/src/components/NSGauge.tsx +52 -52
  346. package/src/components/NSGaugeDate.module.css +57 -57
  347. package/src/components/NSGaugeDate.tsx +125 -125
  348. package/src/components/NSGaugeNumber.module.css +66 -66
  349. package/src/components/NSGaugeNumber.tsx +90 -90
  350. package/src/components/NSHeader.module.css +316 -316
  351. package/src/components/NSHeader.tsx +334 -334
  352. package/src/components/NSHeaderScreenshot.module.css +35 -35
  353. package/src/components/NSHeaderScreenshot.tsx +39 -39
  354. package/src/components/NSID.tsx +159 -159
  355. package/src/components/NSInfo.tsx +50 -50
  356. package/src/components/NSLabel.module.css +25 -25
  357. package/src/components/NSLabel.tsx +47 -47
  358. package/src/components/NSLabelErrorNotifier.module.css +2 -2
  359. package/src/components/NSLabelErrorNotifier.tsx +35 -35
  360. package/src/components/NSLabelSensitive.module.css +9 -9
  361. package/src/components/NSLabelSensitive.tsx +85 -85
  362. package/src/components/NSLayout.module.css +23 -23
  363. package/src/components/NSLayout.tsx +140 -140
  364. package/src/components/NSLine.module.css +15 -15
  365. package/src/components/NSLine.tsx +13 -13
  366. package/src/components/NSLineText.module.css +38 -38
  367. package/src/components/NSLineText.tsx +17 -17
  368. package/src/components/NSLink.module.css +36 -36
  369. package/src/components/NSLink.tsx +26 -26
  370. package/src/components/NSLinkBlue.tsx +22 -22
  371. package/src/components/NSLinkGreen.tsx +13 -13
  372. package/src/components/NSLinkRed.tsx +13 -13
  373. package/src/components/NSListGrouped.module.css +69 -69
  374. package/src/components/NSListGrouped.tsx +106 -106
  375. package/src/components/NSListProduct.tsx +78 -78
  376. package/src/components/NSLoading.module.css +10 -10
  377. package/src/components/NSLoading.tsx +43 -43
  378. package/src/components/NSMegaMenu.module.css +133 -133
  379. package/src/components/NSMegaMenu.tsx +188 -188
  380. package/src/components/NSMenuAction.module.css +88 -88
  381. package/src/components/NSMenuAction.tsx +106 -106
  382. package/src/components/NSMenuButton.module.css +44 -44
  383. package/src/components/NSMenuButton.tsx +197 -197
  384. package/src/components/NSNoData.module.css +11 -11
  385. package/src/components/NSNoData.tsx +24 -24
  386. package/src/components/NSPagination.module.css +86 -86
  387. package/src/components/NSPagination.tsx +182 -182
  388. package/src/components/NSPanel.module.css +19 -19
  389. package/src/components/NSPanel.tsx +24 -24
  390. package/src/components/NSPanelAccordion.module.css +4 -4
  391. package/src/components/NSPanelAccordion.tsx +51 -51
  392. package/src/components/NSProductSearch.module.css +73 -73
  393. package/src/components/NSProductSearch.tsx +193 -193
  394. package/src/components/NSProgressBar.module.css +38 -38
  395. package/src/components/NSProgressBar.tsx +29 -29
  396. package/src/components/NSRange.module.css +66 -66
  397. package/src/components/NSRange.tsx +83 -83
  398. package/src/components/NSRepeater.tsx +328 -328
  399. package/src/components/NSRepeaterNSBoxSchemaVariable.tsx +94 -94
  400. package/src/components/NSRepeaterNSTag.tsx +86 -86
  401. package/src/components/NSRow.module.css +17 -17
  402. package/src/components/NSRow.tsx +24 -24
  403. package/src/components/NSSection.module.css +4 -4
  404. package/src/components/NSSection.tsx +26 -26
  405. package/src/components/NSSectionCards.module.css +38 -38
  406. package/src/components/NSSectionCards.tsx +51 -51
  407. package/src/components/NSSectionTiles.module.css +10 -10
  408. package/src/components/NSSectionTiles.tsx +25 -25
  409. package/src/components/NSSectionTitle.tsx +19 -19
  410. package/src/components/NSSpace.tsx +28 -28
  411. package/src/components/NSSplitter.module.css +58 -58
  412. package/src/components/NSSplitter.tsx +95 -95
  413. package/src/components/NSTabPage.module.css +59 -59
  414. package/src/components/NSTabPage.tsx +122 -122
  415. package/src/components/NSTable.module.css +411 -411
  416. package/src/components/NSTable.tsx +1120 -1118
  417. package/src/components/NSTag.tsx +74 -74
  418. package/src/components/NSTile.module.css +76 -76
  419. package/src/components/NSTile.tsx +27 -27
  420. package/src/components/NSTimelineMonthly.module.css +71 -71
  421. package/src/components/NSTimelineMonthly.tsx +44 -44
  422. package/src/components/NSTitle.module.css +15 -15
  423. package/src/components/NSTitle.tsx +19 -19
  424. package/src/formatter/BackColorFormatter.tsx +23 -23
  425. package/src/formatter/BaseColumnFormatter.ts +18 -18
  426. package/src/formatter/BaseURLImageFormatter.tsx +33 -33
  427. package/src/formatter/BooleanFormatter.ts +22 -22
  428. package/src/formatter/BytesFormatter.tsx +15 -15
  429. package/src/formatter/DateFormatter.ts +22 -22
  430. package/src/formatter/DateTimeFormatter.ts +22 -22
  431. package/src/formatter/DurationFormatter.ts +13 -13
  432. package/src/formatter/EmailFormatter.tsx +21 -21
  433. package/src/formatter/EnumFormatter.ts +13 -13
  434. package/src/formatter/FloatFormatter.ts +23 -23
  435. package/src/formatter/ForeColorFormatter.tsx +24 -24
  436. package/src/formatter/IDFormatter.tsx +53 -53
  437. package/src/formatter/IPFormatter.ts +13 -13
  438. package/src/formatter/IntegerFormatter.ts +23 -23
  439. package/src/formatter/JsonFormatter.tsx +58 -58
  440. package/src/formatter/MoneyFormatter.ts +35 -35
  441. package/src/formatter/PercentFormatter.tsx +39 -39
  442. package/src/formatter/PhoneFormatter.tsx +21 -21
  443. package/src/formatter/SensitiveFormatter.tsx +33 -33
  444. package/src/formatter/StringFormatter.tsx +43 -43
  445. package/src/formatter/TimeFormatter.ts +21 -21
  446. package/src/formatter/URLFormatter.tsx +24 -24
  447. package/src/formatter/UnknowFormatter.ts +18 -18
  448. package/src/index.tsx +7 -7
  449. package/src/main.ts +258 -258
  450. package/src/pages/NSImplementing.module.css +35 -35
  451. package/src/pages/NSImplementing.tsx +32 -32
  452. package/src/pages/NSNotFoundPage.module.css +18 -18
  453. package/src/pages/NSNotFoundPage.tsx +14 -14
  454. package/src/pages/NSUpdating.module.css +35 -35
  455. package/src/pages/NSUpdating.tsx +32 -32
  456. package/src/props/IBackgroundProps.ts +5 -5
  457. package/src/props/IBaseComponentProps.ts +8 -8
  458. package/src/props/IHeaderIconProps.ts +10 -10
  459. package/src/props/IHeaderLeftProps.ts +6 -6
  460. package/src/props/IHeaderRightProps.ts +8 -8
  461. package/src/props/IImageProps.ts +4 -4
  462. package/src/props/ILinkProps.ts +4 -4
  463. package/src/props/IValidationNumberProps.ts +4 -4
  464. package/src/props/IValidationPrecisionProps.ts +3 -3
  465. package/src/props/IValidationProps.ts +9 -9
  466. package/src/props/IValidationRegexProps.ts +4 -4
  467. package/src/props/IValidationStringProps.ts +4 -4
  468. package/src/routing/NSNotifier.ts +114 -114
  469. package/src/routing/NSRouterMaker.tsx +20 -20
  470. package/src/routing/NSRouterMakerComponent.ts +5 -5
  471. package/src/routing/NSRouterMakerProps.ts +5 -5
  472. package/tsconfig.json +43 -43
@@ -1,1119 +1,1121 @@
1
- "use client";
2
- import { BaseMetaColumn, BaseMetaTable, IStorageLocal, SortItem } from "namirasoft-core";
3
- import { Component, createRef, ReactNode } from "react";
4
- import { utils, writeFile } from 'xlsx';
5
- import { BaseColumnFormatter } from '../formatter/BaseColumnFormatter';
6
- import { IBaseComponentProps } from "../props/IBaseComponentProps";
7
- import { NSButton, NSButtonProps } from './NSButton';
8
- import { NSDialogInfo } from './NSDialogInfo';
9
- import { NSDialogPageSelection } from './NSDialogPageSelection';
10
- import { NSLoading } from './NSLoading';
11
- import { NSNoData } from './NSNoData';
12
- import { NSPagination } from './NSPagination';
13
- import Styles from './NSTable.module.css';
14
-
15
- export interface TableInfo
16
- {
17
- name: string;
18
- text: string;
19
- }
20
-
21
- export interface TableColumnInfo
22
- {
23
- table: TableInfo;
24
- index: number;
25
- type: string;
26
- name: string;
27
- text: string;
28
- formatter: BaseColumnFormatter;
29
- group?: string;
30
- defaults?: {
31
- hidden?: boolean;
32
- };
33
- }
34
-
35
- export interface TableRowInfo<RowType>
36
- {
37
- index: number;
38
- value: RowType;
39
- }
40
-
41
- export interface TableCellInfo<RowType>
42
- {
43
- column: TableColumnInfo;
44
- row: TableRowInfo<RowType>;
45
- value: any;
46
- formatted: any;
47
- }
48
-
49
- export interface NSTableProps<RowType> extends IBaseComponentProps
50
- {
51
- name: string;
52
- checkbox: boolean;
53
- scroll?: boolean;
54
- columns: TableColumnInfo[];
55
- getRows: (page: number, size: number, sorts: SortItem[]) => Promise<{ rows: RowType[], count: number }>;
56
- getRowKey: (row: TableRowInfo<RowType>) => string;
57
- getRowAttributes?: (row_value: RowType, row_index: number) => { [key: string]: any };
58
- getColumnAttributes?: (column: TableColumnInfo) => { [key: string]: any };
59
- getCellFormattedValue?: (value: any, column: TableColumnInfo, row: TableRowInfo<RowType>, printable: boolean) => any;
60
- onColumnClick?: (e: React.MouseEvent<HTMLTableCellElement, MouseEvent>, column: TableColumnInfo) => void;
61
- onRowClick?: (e: React.MouseEvent<HTMLTableRowElement, MouseEvent>, row: TableRowInfo<RowType>) => void;
62
- onCellClick?: (e: React.MouseEvent<HTMLTableCellElement, MouseEvent>, cell: TableCellInfo<RowType>) => boolean | undefined;
63
- getRowCheckboxDisabled?: (row: TableRowInfo<RowType>) => boolean;
64
- buttons?: NSButtonProps[];
65
- children?: ReactNode;
66
- headerChildren?: ReactNode;
67
- hierarchy?: { id: string, parent: string, group?: string[] };
68
- defaultExpanded?: boolean;
69
- onSelectedIDsChanged?: () => void;
70
- onSortChanged?: (items: SortItem[] | null) => void;
71
- onVisibleColumnsChanged?: (visible_columns: { table: string, column: string }[]) => void;
72
- ui?: {
73
- pagination?: boolean;
74
- button_panel?: boolean;
75
- };
76
- }
77
-
78
- interface NSTableState<RowType>
79
- {
80
- columns: TableColumnInfo[];
81
- visible_columns: { table: string, column: string }[];
82
- totalItems: number;
83
- rows: RowType[] | null;
84
- title?: string;
85
- model: {
86
- show: boolean;
87
- description?: string;
88
- };
89
- selectedIDs: string[];
90
- selectedRows: RowType[];
91
- expandedIDs: string[];
92
- pageSelectionMode: PageSelectionMode;
93
- sortItems: SortItem[] | null;
94
- columnWidths: { [key: string]: number };
95
- fullscreen: boolean;
96
- }
97
-
98
- enum PageSelectionMode
99
- {
100
- Hidden = "Hidden",
101
- Print = "Print",
102
- CSV = "CSV"
103
- }
104
-
105
- export class NSTable<RowType> extends Component<NSTableProps<RowType>, NSTableState<RowType>>
106
- {
107
- private Table_Ref = createRef<HTMLTableElement>();
108
- private TableScrollbar_Ref = createRef<HTMLDivElement>();
109
- private TableScrollbarContent_Ref = createRef<HTMLDivElement>();
110
- NSPagination = createRef<NSPagination>();
111
-
112
- private LastSelectedRowID: number | null = null;
113
- private resizeMoveHandler: ((e: MouseEvent) => void) | null = null;
114
- private resizeUpHandler: (() => void) | null = null;
115
-
116
- constructor(props: NSTableProps<RowType>)
117
- {
118
- super(props);
119
- this.state = {
120
- columns: props.columns,
121
- visible_columns: this.getVisibleColumns(),
122
- rows: null,
123
- totalItems: 0,
124
- model: { show: false },
125
- selectedIDs: [],
126
- selectedRows: [],
127
- expandedIDs: [],
128
- pageSelectionMode: PageSelectionMode.Hidden,
129
- sortItems: this.getSortItems(),
130
- columnWidths: this.loadColumnWidths(),
131
- fullscreen: false,
132
- };
133
- this.getSortItemsKey = this.getSortItemsKey.bind(this);
134
- this.getSortItems = this.getSortItems.bind(this);
135
- this.setSortItems = this.setSortItems.bind(this);
136
- this.getVisibleColumnsKey = this.getVisibleColumnsKey.bind(this);
137
- this.getVisibleColumns = this.getVisibleColumns.bind(this);
138
- this.setVisibleColumns = this.setVisibleColumns.bind(this);
139
- this.setColumns = this.setColumns.bind(this);
140
- this.setColumns = this.setColumns.bind(this);
141
- this.setRows = this.setRows.bind(this);
142
- this.foreachColumn = this.foreachColumn.bind(this);
143
- this.getColumns = this.getColumns.bind(this);
144
- this.showModal = this.showModal.bind(this);
145
- this.hideModal = this.hideModal.bind(this);
146
- this.onPageChange = this.onPageChange.bind(this);
147
- this.isSomeSelected = this.isSomeSelected.bind(this);
148
- this.toggleAllSelections = this.toggleAllSelections.bind(this);
149
- this.print = this.print.bind(this);
150
- this.exportCSV = this.exportCSV.bind(this);
151
- this.isAllSelected = this.isAllSelected.bind(this);
152
- this.reload = this.reload.bind(this);
153
- this.toggleFullscreen = this.toggleFullscreen.bind(this);
154
- }
155
- private toggleFullscreen()
156
- {
157
- this.setState({ fullscreen: !this.state.fullscreen }, () => this.syncScrollbarWidth());
158
- }
159
- private getSortItemsKey(): string
160
- {
161
- return "ns_table_" + this.props.name + "_sort_items";
162
- }
163
- getSortItems(): SortItem[]
164
- {
165
- let storage = new IStorageLocal();
166
- let item = storage.get(this.getSortItemsKey(), "");
167
- try
168
- {
169
- return SortItem.parse(item);
170
- } catch (error)
171
- {
172
- }
173
- return [];
174
- }
175
- setSortItems(items: SortItem[] | null)
176
- {
177
- let storage = new IStorageLocal();
178
- storage.set(this.getSortItemsKey(), SortItem.stringify(items));
179
- this.setState({ sortItems: items }, () =>
180
- {
181
- this.props.onSortChanged?.(items);
182
- this.reload(null, null);
183
- });
184
- }
185
- private getVisibleColumnsKey(): string
186
- {
187
- return "ns_table_" + this.props.name + "_visible_columns";
188
- }
189
- getVisibleColumns(): { table: string, column: string }[]
190
- {
191
- let storage = new IStorageLocal();
192
- let item = storage.get(this.getVisibleColumnsKey(), "");
193
- try
194
- {
195
- return JSON.parse(item);
196
- } catch (error)
197
- {
198
- }
199
- return [];
200
- }
201
- setVisibleColumns(visible_columns: { table: string, column: string }[])
202
- {
203
- let storage = new IStorageLocal();
204
- storage.set(this.getVisibleColumnsKey(), JSON.stringify(visible_columns));
205
- this.setState({ visible_columns }, () =>
206
- {
207
- this.props.onVisibleColumnsChanged?.(visible_columns);
208
- });
209
- }
210
- setColumns(columns: TableColumnInfo[])
211
- {
212
- this.setState({ columns });
213
- }
214
- private syncScrollbarWidth()
215
- {
216
- if (this.TableScrollbarContent_Ref.current)
217
- this.TableScrollbarContent_Ref.current.style.width = (this.Table_Ref.current?.scrollWidth ?? 0) + "px";
218
- }
219
- setRows(rows: RowType[] | null, totalItems: number)
220
- {
221
- this.setState({ rows, totalItems }, () =>
222
- {
223
- if (this.props.scroll !== false)
224
- this.Table_Ref.current?.scrollIntoView({ behavior: 'smooth', block: 'center' });
225
- this.syncScrollbarWidth();
226
- });
227
- }
228
- foreachColumn(visible: boolean | null, handler: (column: TableColumnInfo) => void)
229
- {
230
- let vs = this.getVisibleColumns();
231
- let shouldBeVisible = (c: TableColumnInfo) =>
232
- {
233
- if (vs.length === 0)
234
- return !c.defaults?.hidden;
235
- return vs.filter(v => v.table === c.table.name && v.column === c.name).length > 0;
236
- };
237
- this.state.columns.forEach(c =>
238
- {
239
- if (visible === null || shouldBeVisible(c) === visible)
240
- handler(c);
241
- })
242
- }
243
- getColumns(visible: boolean | null): TableColumnInfo[]
244
- {
245
- let columns: TableColumnInfo[] = [];
246
- this.foreachColumn(visible, c => columns.push(c));
247
- if (visible === true)
248
- {
249
- let vs = this.getVisibleColumns();
250
- if (vs.length > 0)
251
- columns.sort((a, b) =>
252
- {
253
- let ai = vs.findIndex(v => v.table === a.table.name && v.column === a.name);
254
- let bi = vs.findIndex(v => v.table === b.table.name && v.column === b.name);
255
- return ai - bi;
256
- });
257
- }
258
- return columns;
259
- }
260
- private showModal(description: string, title?: string)
261
- {
262
- this.setState({ model: { show: true, description }, title });
263
- }
264
- private hideModal()
265
- {
266
- this.setState({ model: { show: false } });
267
- }
268
- private onPageChange(page: number, size: number)
269
- {
270
- this.reload(page, size);
271
- }
272
- public async reload(page: number | null, size: number | null)
273
- {
274
- this.setRows(null, 0);
275
- if (page === null)
276
- page = this.NSPagination.current?.getCurrentPage() ?? 0;
277
- if (size === null)
278
- size = this.NSPagination.current?.getPageSize() ?? 0;
279
- try
280
- {
281
- let sorts = this.getSortItems();
282
- let res = await this.props.getRows(page, size, sorts);
283
- this.setRows(res.rows, res.count);
284
- } catch (error)
285
- {
286
- }
287
- }
288
- private toggleAllSelections()
289
- {
290
- let selectedIDs: string[] = [];
291
- let selectedRows: RowType[] = [];
292
- this.LastSelectedRowID = null;
293
-
294
- if (this.getSelectedIDs().length === 0)
295
- {
296
- this.state.rows?.forEach((row, rowIndex) =>
297
- {
298
- let rowInfo = { index: rowIndex, value: row };
299
- if (this.props.getRowCheckboxDisabled?.(rowInfo))
300
- return;
301
- let id = this.props.getRowKey(rowInfo);
302
- selectedIDs.push(id);
303
- selectedRows.push(row);
304
- })
305
- }
306
-
307
- this.setSelectedIDs(selectedIDs, selectedRows);
308
- }
309
- print(rows: RowType[])
310
- {
311
- const printWindow = window.open('', '', 'height=500,width=800');
312
- printWindow!.document.write(`<html><head><title>${this.props.name}</title>`);
313
- printWindow!.document.write('<style>table { width: 100%; border-collapse: collapse; } th, td { border: 1px solid black; padding: 8px; text-align: left; }</style>');
314
- printWindow!.document.write('</head><body>');
315
- printWindow!.document.write('<table>');
316
- printWindow!.document.write('<thead><tr>');
317
-
318
- this.foreachColumn(true, column =>
319
- {
320
- printWindow!.document.write('<th>' + column.text + '</th>');
321
- });
322
-
323
- printWindow!.document.write('</tr></thead><tbody>');
324
-
325
- // Add table rows
326
- rows.forEach((rowValue, rowIndex) =>
327
- {
328
- let row = { index: rowIndex, value: rowValue };
329
- printWindow!.document.write('<tr>');
330
- this.foreachColumn(true, column =>
331
- {
332
- let cell = this.getCellTableInfo(column, row, true);
333
- printWindow!.document.write('<td>' + (cell.formatted ?? "") + '</td>');
334
- });
335
- printWindow!.document.write('</tr>');
336
- });
337
-
338
- printWindow!.document.write('</tbody></table>');
339
- printWindow!.document.write('</body></html>');
340
- printWindow!.document.close();
341
- printWindow!.print();
342
- }
343
- exportCSV(rows: RowType[])
344
- {
345
- const worksheet = utils.json_to_sheet(rows || []);
346
- const workbook = utils.book_new();
347
- utils.book_append_sheet(workbook, worksheet, this.props.name);
348
- writeFile(workbook, this.props.name + ".xlsx");
349
- }
350
-
351
- handleSelectRow(row: TableRowInfo<RowType>, selected: boolean, ctrlKey: boolean, shiftKey: boolean)
352
- {
353
- let selectedIDs = this.state.selectedIDs;
354
- let selectedRows = this.state.selectedRows;
355
- let rowID = this.props.getRowKey(row);
356
-
357
- if (shiftKey)
358
- {
359
- selectedRows = this.getRowsInRange(this.LastSelectedRowID ?? 0, row.index);
360
- selectedIDs = selectedRows.map(row => this.props.getRowKey({ index: -1, value: row }));
361
- }
362
- else if (selected)
363
- {
364
- if (this.isMultipleSelected() && !ctrlKey)
365
- {
366
- selectedIDs = [rowID];
367
- selectedRows = [row.value];
368
- this.LastSelectedRowID = row.index;
369
- }
370
- else
371
- {
372
- selectedIDs = selectedIDs.filter(x => x !== rowID);
373
- selectedRows = selectedRows.filter(x => this.props.getRowKey({ index: -1, value: x }) !== rowID);
374
- this.LastSelectedRowID = ctrlKey ? row.index : null;
375
- }
376
- }
377
- else
378
- {
379
- if (ctrlKey)
380
- {
381
- selectedIDs.push(rowID);
382
- selectedRows.push(row.value);
383
- }
384
- else
385
- {
386
- selectedIDs = [rowID];
387
- selectedRows = [row.value];
388
- }
389
- this.LastSelectedRowID = row.index;
390
- }
391
-
392
- this.setSelectedIDs(selectedIDs, selectedRows);
393
- }
394
- getRowsInRange(fromIndex: number, toIndex: number)
395
- {
396
- if (!this.state.rows)
397
- return [];
398
-
399
- let start = Math.min(fromIndex, toIndex);
400
- let end = Math.max(fromIndex, toIndex);
401
-
402
- return this.state.rows?.slice(start, end + 1);
403
- }
404
- getSelectedIDs(): string[]
405
- {
406
- return this.state.selectedIDs;
407
- }
408
- getSelectedRows(): RowType[]
409
- {
410
- return this.state.selectedRows;
411
- }
412
- setSelectedIDs(ids: string[], rows: RowType[], callback?: () => void)
413
- {
414
- this.setState({ selectedIDs: ids, selectedRows: rows }, () =>
415
- {
416
- if (this.props.onSelectedIDsChanged)
417
- this.props.onSelectedIDsChanged();
418
- if (callback)
419
- callback();
420
- });
421
- }
422
- private getGroupKey(row: RowType): string
423
- {
424
- let h = this.props.hierarchy;
425
- if (!h || !h.group || h.group.length === 0)
426
- return "";
427
- return h.group.map(g =>
428
- {
429
- let v = (row as any)[g];
430
- return v === null || v === undefined ? "" : String(v);
431
- }).join("");
432
- }
433
- private buildChildrenMap(): Map<string, RowType[]> | null
434
- {
435
- let h = this.props.hierarchy;
436
- if (!h || !this.state.rows)
437
- return null;
438
- let map = new Map<string, RowType[]>();
439
- for (let r of this.state.rows)
440
- {
441
- let pid = (r as any)[h.parent];
442
- let pidKey = pid === null || pid === undefined ? "" : String(pid);
443
- let key = pidKey + "" + this.getGroupKey(r);
444
- let arr = map.get(key);
445
- if (!arr) { arr = []; map.set(key, arr); }
446
- arr.push(r);
447
- }
448
- return map;
449
- }
450
- private getRowIdValue(row: RowType): string
451
- {
452
- let h = this.props.hierarchy;
453
- if (!h) return "";
454
- let v = (row as any)[h.id];
455
- return v === null || v === undefined ? "" : String(v);
456
- }
457
- private getRowChildLookupKey(row: RowType): string
458
- {
459
- return this.getRowIdValue(row) + "" + this.getGroupKey(row);
460
- }
461
- private isExpanded(rowKey: string): boolean
462
- {
463
- let inList = this.state.expandedIDs.includes(rowKey);
464
- return this.props.defaultExpanded ? !inList : inList;
465
- }
466
- private toggleExpanded(rowKey: string)
467
- {
468
- let ids = this.state.expandedIDs;
469
- if (ids.includes(rowKey))
470
- ids = ids.filter(x => x !== rowKey);
471
- else
472
- ids = [...ids, rowKey];
473
- this.setState({ expandedIDs: ids });
474
- }
475
- private isAllSelected(): boolean
476
- {
477
- if (!this.state.rows || this.state.rows.length === 0)
478
- return false;
479
- const selectableCount = this.state.rows.filter((row, i) =>
480
- !this.props.getRowCheckboxDisabled?.({ index: i, value: row })
481
- ).length;
482
- return selectableCount > 0 && this.state.selectedIDs.length === selectableCount;
483
- }
484
- private isSomeSelected(): boolean
485
- {
486
- return this.state.selectedIDs.length > 0 && !this.isAllSelected();
487
- }
488
- private isMultipleSelected(): boolean
489
- {
490
- return this.state.selectedIDs.length > 1;
491
- }
492
- private getCellTableInfo(column: TableColumnInfo, row: TableRowInfo<RowType>, printable: boolean)
493
- {
494
- let value = (row.value as any)[column.name];
495
- let formatted = this.getCellFormattedValue(value, column, row, printable);
496
- return { column, row, value, formatted };
497
- }
498
- private getCellFormattedValue(value: any, column: TableColumnInfo, row: TableRowInfo<RowType>, printable: boolean)
499
- {
500
- if (this.props.getCellFormattedValue)
501
- return this.props.getCellFormattedValue(value, column, row, printable);
502
- return column.formatter.format(value, column, row, printable);
503
- }
504
- private getColumnWidthsKey(): string
505
- {
506
- return "ns_table_" + this.props.name + "_column_widths";
507
- }
508
- private loadColumnWidths(): { [key: string]: number }
509
- {
510
- let storage = new IStorageLocal();
511
- let item = storage.get(this.getColumnWidthsKey(), "");
512
- try
513
- {
514
- return JSON.parse(item);
515
- }
516
- catch
517
- {
518
- return {};
519
- }
520
- }
521
- private saveColumnWidths(widths: { [key: string]: number })
522
- {
523
- let storage = new IStorageLocal();
524
- storage.set(this.getColumnWidthsKey(), JSON.stringify(widths));
525
- }
526
- private getColumnKey(column: TableColumnInfo): string
527
- {
528
- return column.table.name + "_" + column.name;
529
- }
530
- private getColumnWidth(column: TableColumnInfo): number
531
- {
532
- let key = this.getColumnKey(column);
533
- if (this.state.columnWidths[key] !== undefined)
534
- return this.state.columnWidths[key];
535
- let w = column.formatter.width;
536
- if (typeof w === 'number') return w;
537
- if (typeof w === 'string')
538
- {
539
- let parsed = parseInt(w, 10);
540
- if (!isNaN(parsed)) return parsed;
541
- }
542
- return 120;
543
- }
544
- private getGridTemplateColumns(): string
545
- {
546
- let parts: string[] = [];
547
- if (this.props.checkbox)
548
- parts.push("40px");
549
- this.getColumns(true).forEach(column =>
550
- {
551
- parts.push(this.getColumnWidth(column) + "px");
552
- });
553
- return parts.join(" ");
554
- }
555
- private startResize(e: React.MouseEvent, column: TableColumnInfo)
556
- {
557
- e.preventDefault();
558
- e.stopPropagation();
559
- let key = this.getColumnKey(column);
560
- let startX = e.clientX;
561
- let startWidth = this.getColumnWidth(column);
562
- let currentWidths = { ...this.state.columnWidths };
563
- document.body.style.cursor = 'col-resize';
564
- document.body.style.userSelect = 'none';
565
- const onMouseMove = (ev: MouseEvent) =>
566
- {
567
- let delta = ev.clientX - startX;
568
- let newWidth = Math.max(80, startWidth + delta);
569
- currentWidths = { ...currentWidths, [key]: newWidth };
570
- this.setState({ columnWidths: currentWidths }, () => this.syncScrollbarWidth());
571
- };
572
- const onMouseUp = () =>
573
- {
574
- document.body.style.cursor = '';
575
- document.body.style.userSelect = '';
576
- document.removeEventListener('mousemove', onMouseMove);
577
- document.removeEventListener('mouseup', onMouseUp);
578
- this.resizeMoveHandler = null;
579
- this.resizeUpHandler = null;
580
- this.saveColumnWidths(currentWidths);
581
- };
582
- this.resizeMoveHandler = onMouseMove;
583
- this.resizeUpHandler = onMouseUp;
584
- document.addEventListener('mousemove', onMouseMove);
585
- document.addEventListener('mouseup', onMouseUp);
586
- }
587
- override componentDidMount(): void
588
- {
589
- if (!this.NSPagination.current)
590
- this.reload(null, null);
591
-
592
- this.syncScrollbarWidth();
593
- }
594
- override componentWillUnmount(): void
595
- {
596
- if (this.resizeMoveHandler)
597
- document.removeEventListener('mousemove', this.resizeMoveHandler);
598
- if (this.resizeUpHandler)
599
- document.removeEventListener('mouseup', this.resizeUpHandler);
600
- }
601
- override render()
602
- {
603
-
604
- let show_pagination = this.props.ui?.pagination ?? true;
605
- let show_button_panel = this.props.ui?.button_panel ?? true;
606
- let getRowAttributes = (row_value: RowType, row_index: number) =>
607
- {
608
- if (this.props.getRowAttributes)
609
- return this.props.getRowAttributes(row_value, row_index);
610
- return {};
611
- }
612
- let getColumnAttributes = (column: TableColumnInfo) =>
613
- {
614
- if (this.props.getColumnAttributes)
615
- return this.props.getColumnAttributes(column);
616
- return {};
617
- }
618
- let onColumnClick = (e: React.MouseEvent<HTMLTableCellElement, MouseEvent>, column: TableColumnInfo) =>
619
- {
620
- if ((e.target as HTMLElement).tagName !== "SPAN")
621
- return;
622
-
623
- if (this.props.onColumnClick)
624
- this.props.onColumnClick(e, column);
625
- }
626
- let onRowClick = (e: React.MouseEvent<HTMLTableRowElement, MouseEvent>, row: TableRowInfo<RowType>, selected: boolean) =>
627
- {
628
- const target = e.target as HTMLElement;
629
-
630
- if (target.tagName === "TR" || target.tagName === "TD" || target.closest("td")?.dataset.cellType === "checkbox")
631
- this.handleSelectRow(row, selected, e.ctrlKey, e.shiftKey);
632
-
633
- if (this.props.onRowClick)
634
- this.props.onRowClick(e, row);
635
- };
636
- let onCellClick = (e: React.MouseEvent<HTMLTableCellElement, MouseEvent>, cell: TableCellInfo<RowType>) =>
637
- {
638
- if ((e.target as HTMLElement).tagName !== "SPAN")
639
- return;
640
-
641
- let overided = cell.column.formatter.onclick_overrided;
642
- if (this.props.onCellClick)
643
- overided = this.props.onCellClick(e, cell) ?? true;
644
- if (!overided)
645
- this.showModal(cell.formatted, cell.column.text);
646
- };
647
- let gridTemplateColumns = this.getGridTemplateColumns();
648
- let content;
649
- if (this.state.rows === null)
650
- {
651
- content = (
652
- <tr className="d-flex justify-content-center align-items-center p-0">
653
- <td className="w-100 h-100 m-0 mh-100">
654
- <NSLoading />
655
- </td>
656
- </tr>
657
- );
658
- }
659
- else if (this.state.rows.length === 0)
660
- {
661
- content = (
662
- <tr className="d-flex justify-content-center align-items-center p-0">
663
- <td className="w-100 h-100 m-0 mh-100">
664
- <NSNoData lable='No Data' classList={["p-3"]} />
665
- </td>
666
- </tr>
667
- );
668
- }
669
- else
670
- {
671
- let hierarchical = !!this.props.hierarchy;
672
- let childrenMap = this.buildChildrenMap();
673
- let indexOfRow = new Map<RowType, number>();
674
- this.state.rows.forEach((r, i) => indexOfRow.set(r, i));
675
- let INDENT = 16;
676
- let lineColor = "rgba(20, 27, 92, 0.35)";
677
- let renderRow = (rowValue: RowType, rowIndex: number, depth: number, parentKey: string, ancestorHasNext: boolean[], isLastChild: boolean): React.ReactNode[] =>
678
- {
679
- let row = { index: rowIndex, value: rowValue };
680
- let rowKey = this.props.getRowKey(row);
681
- let reactKey = parentKey ? `${parentKey}>${rowKey}` : rowKey;
682
- let isSelected = this.state.selectedIDs.includes(rowKey);
683
- let isLastSelected = this.LastSelectedRowID === row.index;
684
- let isCheckboxDisabled = this.props.getRowCheckboxDisabled?.(row) ?? false;
685
- let children: RowType[] = [];
686
- if (hierarchical && childrenMap)
687
- {
688
- let lookupKey = this.getRowChildLookupKey(rowValue);
689
- children = childrenMap.get(lookupKey) ?? [];
690
- }
691
- let hasChildren = children.length > 0;
692
- let expanded = this.isExpanded(rowKey);
693
- let rowAttrs = getRowAttributes(rowValue, rowIndex);
694
- let nodes: React.ReactNode[] = [];
695
- nodes.push(
696
- <tr
697
- key={reactKey}
698
- {...rowAttrs}
699
- style={{ ...(rowAttrs.style || {}), gridTemplateColumns }}
700
- className={`${isSelected ? Styles.ns_selected : ""} ${isLastSelected ? Styles.ns_last_selected : ""}`.trim()}
701
- onClick={(e) => !isCheckboxDisabled && onRowClick(e, row, isSelected)}
702
- >
703
- {
704
- this.props.checkbox &&
705
- <td data-cell-type="checkbox">
706
- <label
707
- htmlFor={`checkbox_device_${rowKey}`}
708
- className={Styles.ns_check_box_label}
709
- >
710
- <input
711
- id={`checkbox_device_${rowKey}`}
712
- type="checkbox"
713
- checked={isSelected}
714
- disabled={isCheckboxDisabled}
715
- className={Styles.ns_check_box}
716
- onChange={() => { }}
717
- />
718
- </label>
719
- </td>
720
- }
721
- {
722
- this.getColumns(true).map((column, index) =>
723
- {
724
- column.index = index + (this.props.checkbox ? 1 : 0);
725
- let cell = this.getCellTableInfo(column, row, false);
726
- let isFirstDataColumn = index === 0;
727
- return (
728
- <td
729
- key={column.index}
730
- {...getColumnAttributes(column)}
731
- data-label={`${column.text}: `}
732
- width={column.formatter.width}
733
- className=''
734
- style={isFirstDataColumn && hierarchical ? { overflow: "visible" } : undefined}
735
- onClick={(e) =>
736
- {
737
- onColumnClick(e, column);
738
- onCellClick(e, cell);
739
- }}
740
- >
741
- {isFirstDataColumn && hierarchical ? (
742
- <div
743
- style={{
744
- display: "flex",
745
- alignItems: "center",
746
- }}
747
- >
748
- {Array.from({ length: depth }).map((_, i) =>
749
- {
750
- let isLastLevel = i === depth - 1;
751
- let drawVerticalTop = i < depth - 1 ? ancestorHasNext[i] : true;
752
- let drawVerticalBottom = i < depth - 1 ? ancestorHasNext[i] : !isLastChild;
753
- let drawHorizontal = isLastLevel;
754
- return (
755
- <span
756
- key={i}
757
- style={{
758
- position: "relative",
759
- display: "inline-block",
760
- width: INDENT,
761
- alignSelf: "stretch",
762
- flex: "0 0 auto",
763
- }}
764
- >
765
- {drawVerticalTop && (
766
- <span style={{
767
- position: "absolute",
768
- left: INDENT / 2,
769
- top: -24,
770
- height: "calc(50% + 24px)",
771
- width: 1,
772
- background: lineColor,
773
- }} />
774
- )}
775
- {drawVerticalBottom && (
776
- <span style={{
777
- position: "absolute",
778
- left: INDENT / 2,
779
- top: "50%",
780
- height: "calc(50% + 24px)",
781
- width: 1,
782
- background: lineColor,
783
- }} />
784
- )}
785
- {drawHorizontal && (
786
- <span style={{
787
- position: "absolute",
788
- left: INDENT / 2,
789
- top: "50%",
790
- width: INDENT / 2,
791
- height: 1,
792
- background: lineColor,
793
- }} />
794
- )}
795
- </span>
796
- );
797
- })}
798
- <span
799
- data-cell-type="tree-toggle"
800
- style={{
801
- display: "inline-flex",
802
- alignItems: "center",
803
- justifyContent: "center",
804
- marginRight: 6,
805
- }}
806
- onClick={(e) => e.stopPropagation()}
807
- >
808
- {hasChildren ? (
809
- <button
810
- type="button"
811
- onClick={(e) =>
812
- {
813
- e.stopPropagation();
814
- this.toggleExpanded(rowKey);
815
- }}
816
- style={{
817
- width: 18,
818
- height: 18,
819
- lineHeight: "16px",
820
- padding: 0,
821
- border: "1px solid rgba(20, 27, 92, 0.4)",
822
- borderRadius: 3,
823
- background: "#fff",
824
- cursor: "pointer",
825
- fontSize: 14,
826
- fontWeight: "bold",
827
- color: "rgba(20, 27, 92, 1)",
828
- }}
829
- aria-label={expanded ? "Collapse" : "Expand"}
830
- >
831
- {expanded ? "−" : "+"}
832
- </button>
833
- ) : (
834
- <span style={{ display: "inline-block", width: 18, height: 18 }} />
835
- )}
836
- </span>
837
- <span>{cell.formatted ?? ""}</span>
838
- </div>
839
- ) : (
840
- <span>{cell.formatted ?? ""}</span>
841
- )}
842
- </td>
843
- );
844
- })
845
- }
846
- </tr>
847
- );
848
- if (hierarchical && hasChildren && expanded)
849
- {
850
- let childAncestors = [...ancestorHasNext, !isLastChild];
851
- children.forEach((child, ci2) =>
852
- {
853
- let ci = indexOfRow.get(child) ?? -1;
854
- let lastChild = ci2 === children.length - 1;
855
- renderRow(child, ci, depth + 1, reactKey, childAncestors, lastChild).forEach(n => nodes.push(n));
856
- });
857
- }
858
- return nodes;
859
- };
860
- let topLevel: RowType[];
861
- if (hierarchical && this.props.hierarchy)
862
- {
863
- let parentCol = this.props.hierarchy.parent;
864
- let ids = new Set<string>();
865
- this.state.rows.forEach(r => ids.add(this.getRowIdValue(r) + "" + this.getGroupKey(r)));
866
- topLevel = this.state.rows.filter(r =>
867
- {
868
- let pid = (r as any)[parentCol];
869
- let pidKey = pid === null || pid === undefined ? "" : String(pid);
870
- if (pidKey === "")
871
- return true;
872
- return !ids.has(pidKey + "" + this.getGroupKey(r));
873
- });
874
- }
875
- else
876
- {
877
- topLevel = this.state.rows;
878
- }
879
- content = topLevel.flatMap((rowValue, i) => renderRow(rowValue, indexOfRow.get(rowValue) ?? 0, 0, "", [], i === topLevel.length - 1));
880
- }
881
-
882
- let getSortSign = (column: TableColumnInfo) =>
883
- {
884
- if (this.state.sortItems)
885
- {
886
- let c = this.state.sortItems.filter(c => c.table.name === column.table.name && c.column.name === column.name)[0]
887
- if (c)
888
- {
889
- if (c.ascending)
890
- return "↑"
891
- return "↓";
892
- }
893
- }
894
- return "";
895
- };
896
-
897
- let buttonPanel = show_button_panel && (
898
- <div className={Styles.ns_button_panel}>
899
- {
900
- this.state.pageSelectionMode !== PageSelectionMode.Hidden &&
901
- <NSDialogPageSelection<RowType>
902
- icon={
903
- this.state.pageSelectionMode === PageSelectionMode.Print ? "https://static.namirasoft.com/image/concept/print/blue.svg" :
904
- this.state.pageSelectionMode === PageSelectionMode.CSV ? "https://static.namirasoft.com/image/concept/export/blue.svg" : ""
905
- }
906
- current_page={this.NSPagination.current?.getCurrentPage() ?? 1}
907
- current_size={this.NSPagination.current?.getPageSize() ?? 0}
908
- max_page={this.state.totalItems}
909
- getItems={async (page, size, selected) =>
910
- {
911
- if (selected)
912
- {
913
- let rows: RowType[] = [];
914
- if (this.state.rows)
915
- for (let i = 0; i < this.state.rows.length; i++)
916
- {
917
- const row = { index: i, value: this.state.rows[i] };
918
- let id = this.props.getRowKey(row);
919
- if (this.state.selectedIDs.includes(id))
920
- rows.push(row.value);
921
- }
922
- return rows;
923
- }
924
- let res = await this.props.getRows(page, size, this.getSortItems());
925
- return res.rows;
926
- }}
927
- onFinish={async (items: RowType[]) =>
928
- {
929
- if (this.state.pageSelectionMode === PageSelectionMode.Print)
930
- this.print(items);
931
- else if (this.state.pageSelectionMode === PageSelectionMode.CSV)
932
- this.exportCSV(items);
933
- }}
934
- onClose={() => this.setState({ pageSelectionMode: PageSelectionMode.Hidden })}
935
- />
936
- }
937
- {
938
- this.props.buttons?.map((button, index) => (
939
- <NSButton
940
- key={index}
941
- {...button}
942
- classList={[Styles.ns_table_button, ...(button.classList ?? [])]}
943
- />
944
- ))
945
- }
946
- <NSButton
947
- icon={{ src: `https://static.namirasoft.com/image/concept/full-screen/blue.svg` }}
948
- classList={[Styles.ns_table_button, Styles.ns_fullscreen_button]}
949
- onClick={{
950
- action: this.toggleFullscreen,
951
- showLoading: false
952
- }}
953
- attributes={{ title: this.state.fullscreen ? 'Minimize' : 'Maximize' }}
954
- />
955
- <NSButton
956
- attributes={{ title: 'Chart' }}
957
- icon={{ src: "https://static.namirasoft.com/image/concept/chart/blue.svg" }}
958
- onClick={{
959
- action: () =>
960
- {
961
- this.showModal(" ", "This feature will be available soon in upcoming versions.");
962
- },
963
- showLoading: false
964
- }}
965
- classList={[Styles.ns_table_button]}
966
- />
967
- <NSButton
968
- icon={{ src: "https://static.namirasoft.com/image/concept/export/blue.svg" }}
969
- onClick={{
970
- action: () => { this.setState({ pageSelectionMode: PageSelectionMode.CSV }); },
971
- showLoading: false
972
- }}
973
- classList={[Styles.ns_table_button]}
974
- attributes={{ title: 'Export' }}
975
- />
976
- <NSButton
977
- attributes={{ title: 'Print' }}
978
- icon={{ src: "https://static.namirasoft.com/image/concept/print/blue.svg" }}
979
- onClick={{
980
- action: () => { this.setState({ pageSelectionMode: PageSelectionMode.Print }); },
981
- showLoading: false
982
- }}
983
- classList={[Styles.ns_table_button]}
984
- />
985
- <NSButton
986
- attributes={{ title: 'Refresh' }}
987
- icon={{ src: "https://static.namirasoft.com/image/concept/refresh/blue.svg" }}
988
- onClick={{
989
- action: async (onFinished) =>
990
- {
991
- this.reload(null, null).then(onFinished).catch(onFinished);
992
- }
993
- }}
994
- classList={[Styles.ns_table_button]}
995
- style={{ border: '1px solid rgb(3, 119, 255)' }}
996
- />
997
- </div>
998
- );
999
-
1000
- return (
1001
- <div
1002
- id={this.props.id}
1003
- className={[...this.props.classList ?? [], Styles.ns_table_wrapper, this.state.fullscreen ? Styles.ns_fullscreen : ""].filter(Boolean).join(" ")}
1004
- style={{ ...this.props.style }}
1005
- >
1006
- <div className={Styles.ns_table_topbar}>
1007
- {
1008
- !this.state.fullscreen &&
1009
- this.props.headerChildren
1010
- }
1011
- {
1012
- show_pagination &&
1013
- <NSPagination ref={this.NSPagination} totalItems={this.state.totalItems} onPageChange={this.onPageChange} style={{ marginRight: "auto" }} />
1014
- }
1015
- {buttonPanel}
1016
- </div>
1017
- {
1018
- !this.state.fullscreen && this.props.children &&
1019
- <div className={Styles.ns_table_children}>
1020
- {this.props.children}
1021
- </div>
1022
- }
1023
- <table
1024
- ref={this.Table_Ref}
1025
- className={Styles.ns_table}
1026
- onScroll={() =>
1027
- {
1028
- if (this.TableScrollbar_Ref.current)
1029
- this.TableScrollbar_Ref.current.scrollLeft = this.Table_Ref.current?.scrollLeft ?? 0;
1030
- }}
1031
- >
1032
- <thead>
1033
- <tr style={{ gridTemplateColumns }}>
1034
- {
1035
- this.props.checkbox &&
1036
- <th data-cell-type="checkbox" style={{ width: "24px", height: "24px", padding: 0 }}>
1037
- <label
1038
- htmlFor='checkbox'
1039
- className={Styles.ns_checkbox_label}
1040
- >
1041
- <input
1042
- id="checkbox"
1043
- type="checkbox"
1044
- className={`${Styles.ns_check_box} ${this.isSomeSelected() ? Styles.ns_indeterminate : ""}`}
1045
- checked={this.getSelectedIDs().length > 0}
1046
- onChange={this.toggleAllSelections}
1047
- ></input>
1048
- </label>
1049
- </th>
1050
- }
1051
- {
1052
- this.getColumns(true).map(column => <th
1053
- key={column.name}
1054
- scope="col"
1055
- style={{ width: this.getColumnWidth(column), cursor: "pointer", position: "relative", userSelect: "none" }}
1056
- onClick={(e) =>
1057
- {
1058
- if ((e.target as HTMLElement).closest('[data-resize-handle]')) return;
1059
- let t = new BaseMetaTable(null, column.table.name, column.table.text);
1060
- let c = new BaseMetaColumn(t, column.name, column.text, "", false);
1061
- let items = this.getSortItems();
1062
- if (!items || items.length === 0 || items[0].table.name !== t.name || items[0].column.name !== c.name)
1063
- this.setSortItems([new SortItem(t, c, true)]);
1064
- else
1065
- {
1066
- if (items[0].ascending)
1067
- this.setSortItems([new SortItem(t, c, false)]);
1068
- else
1069
- this.setSortItems(null);
1070
- }
1071
- }}
1072
- >
1073
- <span>{column.text + " " + getSortSign(column)}</span>
1074
- <div
1075
- data-resize-handle="true"
1076
- className={Styles.ns_resize_handle}
1077
- onMouseDown={(e) => this.startResize(e, column)}
1078
- onClick={(e) => e.stopPropagation()}
1079
- />
1080
- </th>)
1081
- }
1082
- </tr>
1083
- </thead>
1084
-
1085
- <tbody className={Styles.ns_tbody}>
1086
- {content}
1087
- </tbody>
1088
- </table>
1089
-
1090
- <div
1091
- ref={this.TableScrollbar_Ref}
1092
- className={Styles.ns_table_scrollbar}
1093
- onScroll={() =>
1094
- {
1095
- if (this.Table_Ref.current)
1096
- this.Table_Ref.current.scrollLeft = this.TableScrollbar_Ref.current?.scrollLeft ?? 0;
1097
- }}
1098
- >
1099
- <div
1100
- ref={this.TableScrollbarContent_Ref}
1101
- className={Styles.ns_table_scrollbar_content}>
1102
- </div>
1103
- </div>
1104
-
1105
- {
1106
- this.state.model.show &&
1107
- <NSDialogInfo
1108
- description={this.state.model.description}
1109
- onClose={() => { this.hideModal(); }}
1110
- title={this.state.title}
1111
- show_as_code={true}
1112
- >
1113
- <></>
1114
- </NSDialogInfo>
1115
- }
1116
- </div>
1117
- );
1118
- }
1
+ "use client";
2
+ import { BaseMetaColumn, BaseMetaTable, IStorageLocal, SortItem } from "namirasoft-core";
3
+ import { Component, createRef, ReactNode } from "react";
4
+ import { utils, writeFile } from 'xlsx';
5
+ import { BaseColumnFormatter } from '../formatter/BaseColumnFormatter';
6
+ import { IBaseComponentProps } from "../props/IBaseComponentProps";
7
+ import { NSButton, NSButtonProps } from './NSButton';
8
+ import { NSDialogInfo } from './NSDialogInfo';
9
+ import { NSDialogPageSelection } from './NSDialogPageSelection';
10
+ import { NSLoading } from './NSLoading';
11
+ import { NSNoData } from './NSNoData';
12
+ import { NSPagination } from './NSPagination';
13
+ import Styles from './NSTable.module.css';
14
+
15
+ export interface TableInfo
16
+ {
17
+ name: string;
18
+ text: string;
19
+ }
20
+
21
+ export interface TableColumnInfo
22
+ {
23
+ table: TableInfo;
24
+ index: number;
25
+ type: string;
26
+ name: string;
27
+ text: string;
28
+ formatter: BaseColumnFormatter;
29
+ group?: string;
30
+ defaults?: {
31
+ hidden?: boolean;
32
+ };
33
+ }
34
+
35
+ export interface TableRowInfo<RowType>
36
+ {
37
+ index: number;
38
+ value: RowType;
39
+ }
40
+
41
+ export interface TableCellInfo<RowType>
42
+ {
43
+ column: TableColumnInfo;
44
+ row: TableRowInfo<RowType>;
45
+ value: any;
46
+ formatted: any;
47
+ }
48
+
49
+ export interface NSTableProps<RowType> extends IBaseComponentProps
50
+ {
51
+ name: string;
52
+ checkbox: boolean;
53
+ scroll?: boolean;
54
+ columns: TableColumnInfo[];
55
+ getRows: (page: number, size: number, sorts: SortItem[]) => Promise<{ rows: RowType[], count: number }>;
56
+ getRowKey: (row: TableRowInfo<RowType>) => string;
57
+ getRowAttributes?: (row_value: RowType, row_index: number) => { [key: string]: any };
58
+ getColumnAttributes?: (column: TableColumnInfo) => { [key: string]: any };
59
+ getCellFormattedValue?: (value: any, column: TableColumnInfo, row: TableRowInfo<RowType>, printable: boolean) => any;
60
+ onColumnClick?: (e: React.MouseEvent<HTMLTableCellElement, MouseEvent>, column: TableColumnInfo) => void;
61
+ onRowClick?: (e: React.MouseEvent<HTMLTableRowElement, MouseEvent>, row: TableRowInfo<RowType>) => void;
62
+ onCellClick?: (e: React.MouseEvent<HTMLTableCellElement, MouseEvent>, cell: TableCellInfo<RowType>) => boolean | undefined;
63
+ getRowCheckboxDisabled?: (row: TableRowInfo<RowType>) => boolean;
64
+ buttons?: NSButtonProps[];
65
+ children?: ReactNode;
66
+ headerChildren?: ReactNode;
67
+ hierarchy?: { id: string, parent: string, group?: string[] };
68
+ defaultExpanded?: boolean;
69
+ onSelectedIDsChanged?: () => void;
70
+ onSortChanged?: (items: SortItem[] | null) => void;
71
+ onVisibleColumnsChanged?: (visible_columns: { table: string, column: string }[]) => void;
72
+ ui?: {
73
+ pagination?: boolean;
74
+ button_panel?: boolean;
75
+ };
76
+ }
77
+
78
+ interface NSTableState<RowType>
79
+ {
80
+ columns: TableColumnInfo[];
81
+ visible_columns: { table: string, column: string }[];
82
+ totalItems: number;
83
+ rows: RowType[] | null;
84
+ title?: string;
85
+ model: {
86
+ show: boolean;
87
+ description?: string;
88
+ };
89
+ selectedIDs: string[];
90
+ selectedRows: RowType[];
91
+ expandedIDs: string[];
92
+ pageSelectionMode: PageSelectionMode;
93
+ sortItems: SortItem[] | null;
94
+ columnWidths: { [key: string]: number };
95
+ fullscreen: boolean;
96
+ }
97
+
98
+ enum PageSelectionMode
99
+ {
100
+ Hidden = "Hidden",
101
+ Print = "Print",
102
+ CSV = "CSV"
103
+ }
104
+
105
+ export class NSTable<RowType> extends Component<NSTableProps<RowType>, NSTableState<RowType>>
106
+ {
107
+ private Table_Ref = createRef<HTMLTableElement>();
108
+ private TableScrollbar_Ref = createRef<HTMLDivElement>();
109
+ private TableScrollbarContent_Ref = createRef<HTMLDivElement>();
110
+ NSPagination = createRef<NSPagination>();
111
+
112
+ private LastSelectedRowID: number | null = null;
113
+ private resizeMoveHandler: ((e: MouseEvent) => void) | null = null;
114
+ private resizeUpHandler: (() => void) | null = null;
115
+
116
+ constructor(props: NSTableProps<RowType>)
117
+ {
118
+ super(props);
119
+ this.state = {
120
+ columns: props.columns,
121
+ visible_columns: this.getVisibleColumns(),
122
+ rows: null,
123
+ totalItems: 0,
124
+ model: { show: false },
125
+ selectedIDs: [],
126
+ selectedRows: [],
127
+ expandedIDs: [],
128
+ pageSelectionMode: PageSelectionMode.Hidden,
129
+ sortItems: this.getSortItems(),
130
+ columnWidths: this.loadColumnWidths(),
131
+ fullscreen: false,
132
+ };
133
+ this.getSortItemsKey = this.getSortItemsKey.bind(this);
134
+ this.getSortItems = this.getSortItems.bind(this);
135
+ this.setSortItems = this.setSortItems.bind(this);
136
+ this.getVisibleColumnsKey = this.getVisibleColumnsKey.bind(this);
137
+ this.getVisibleColumns = this.getVisibleColumns.bind(this);
138
+ this.setVisibleColumns = this.setVisibleColumns.bind(this);
139
+ this.setColumns = this.setColumns.bind(this);
140
+ this.setColumns = this.setColumns.bind(this);
141
+ this.setRows = this.setRows.bind(this);
142
+ this.foreachColumn = this.foreachColumn.bind(this);
143
+ this.getColumns = this.getColumns.bind(this);
144
+ this.showModal = this.showModal.bind(this);
145
+ this.hideModal = this.hideModal.bind(this);
146
+ this.onPageChange = this.onPageChange.bind(this);
147
+ this.isSomeSelected = this.isSomeSelected.bind(this);
148
+ this.toggleAllSelections = this.toggleAllSelections.bind(this);
149
+ this.print = this.print.bind(this);
150
+ this.exportCSV = this.exportCSV.bind(this);
151
+ this.isAllSelected = this.isAllSelected.bind(this);
152
+ this.reload = this.reload.bind(this);
153
+ this.toggleFullscreen = this.toggleFullscreen.bind(this);
154
+ }
155
+ private toggleFullscreen()
156
+ {
157
+ this.setState({ fullscreen: !this.state.fullscreen }, () => this.syncScrollbarWidth());
158
+ }
159
+ private getSortItemsKey(): string
160
+ {
161
+ return "ns_table_" + this.props.name + "_sort_items";
162
+ }
163
+ getSortItems(): SortItem[]
164
+ {
165
+ let storage = new IStorageLocal();
166
+ let item = storage.get(this.getSortItemsKey(), "");
167
+ try
168
+ {
169
+ return SortItem.parse(item);
170
+ } catch (error)
171
+ {
172
+ }
173
+ return [];
174
+ }
175
+ setSortItems(items: SortItem[] | null)
176
+ {
177
+ let storage = new IStorageLocal();
178
+ storage.set(this.getSortItemsKey(), SortItem.stringify(items));
179
+ this.setState({ sortItems: items }, () =>
180
+ {
181
+ this.props.onSortChanged?.(items);
182
+ this.reload(null, null);
183
+ });
184
+ }
185
+ private getVisibleColumnsKey(): string
186
+ {
187
+ return "ns_table_" + this.props.name + "_visible_columns";
188
+ }
189
+ getVisibleColumns(): { table: string, column: string }[]
190
+ {
191
+ let storage = new IStorageLocal();
192
+ let item = storage.get(this.getVisibleColumnsKey(), "");
193
+ try
194
+ {
195
+ return JSON.parse(item);
196
+ } catch (error)
197
+ {
198
+ }
199
+ return [];
200
+ }
201
+ setVisibleColumns(visible_columns: { table: string, column: string }[])
202
+ {
203
+ let storage = new IStorageLocal();
204
+ storage.set(this.getVisibleColumnsKey(), JSON.stringify(visible_columns));
205
+ this.setState({ visible_columns }, () =>
206
+ {
207
+ this.props.onVisibleColumnsChanged?.(visible_columns);
208
+ });
209
+ }
210
+ setColumns(columns: TableColumnInfo[])
211
+ {
212
+ this.setState({ columns });
213
+ }
214
+ private syncScrollbarWidth()
215
+ {
216
+ if (this.TableScrollbarContent_Ref.current)
217
+ this.TableScrollbarContent_Ref.current.style.width = (this.Table_Ref.current?.scrollWidth ?? 0) + "px";
218
+ }
219
+ setRows(rows: RowType[] | null, totalItems: number)
220
+ {
221
+ this.setState({ rows, totalItems }, () =>
222
+ {
223
+ if (this.props.scroll !== false)
224
+ this.Table_Ref.current?.scrollIntoView({ behavior: 'smooth', block: 'center' });
225
+ this.syncScrollbarWidth();
226
+ });
227
+ }
228
+ foreachColumn(visible: boolean | null, handler: (column: TableColumnInfo) => void)
229
+ {
230
+ let vs = this.getVisibleColumns();
231
+ let shouldBeVisible = (c: TableColumnInfo) =>
232
+ {
233
+ if (vs.length === 0)
234
+ return !c.defaults?.hidden;
235
+ return vs.filter(v => v.table === c.table.name && v.column === c.name).length > 0;
236
+ };
237
+ this.state.columns.forEach(c =>
238
+ {
239
+ if (visible === null || shouldBeVisible(c) === visible)
240
+ handler(c);
241
+ })
242
+ }
243
+ getColumns(visible: boolean | null): TableColumnInfo[]
244
+ {
245
+ let columns: TableColumnInfo[] = [];
246
+ this.foreachColumn(visible, c => columns.push(c));
247
+ if (visible === true)
248
+ {
249
+ let vs = this.getVisibleColumns();
250
+ if (vs.length > 0)
251
+ columns.sort((a, b) =>
252
+ {
253
+ let ai = vs.findIndex(v => v.table === a.table.name && v.column === a.name);
254
+ let bi = vs.findIndex(v => v.table === b.table.name && v.column === b.name);
255
+ return ai - bi;
256
+ });
257
+ }
258
+ return columns;
259
+ }
260
+ private showModal(description: string, title?: string)
261
+ {
262
+ this.setState({ model: { show: true, description }, title });
263
+ }
264
+ private hideModal()
265
+ {
266
+ this.setState({ model: { show: false } });
267
+ }
268
+ private onPageChange(page: number, size: number)
269
+ {
270
+ this.reload(page, size);
271
+ }
272
+ public async reload(page: number | null, size: number | null)
273
+ {
274
+ this.setRows(null, 0);
275
+ if (page === null)
276
+ page = this.NSPagination.current?.getCurrentPage() ?? 0;
277
+ if (size === null)
278
+ size = this.NSPagination.current?.getPageSize() ?? 0;
279
+ try
280
+ {
281
+ let sorts = this.getSortItems();
282
+ let res = await this.props.getRows(page, size, sorts);
283
+ this.setRows(res.rows, res.count);
284
+ } catch (error)
285
+ {
286
+ }
287
+ }
288
+ private toggleAllSelections()
289
+ {
290
+ let selectedIDs: string[] = [];
291
+ let selectedRows: RowType[] = [];
292
+ this.LastSelectedRowID = null;
293
+
294
+ if (this.getSelectedIDs().length === 0)
295
+ {
296
+ this.state.rows?.forEach((row, rowIndex) =>
297
+ {
298
+ let rowInfo = { index: rowIndex, value: row };
299
+ if (this.props.getRowCheckboxDisabled?.(rowInfo))
300
+ return;
301
+ let id = this.props.getRowKey(rowInfo);
302
+ selectedIDs.push(id);
303
+ selectedRows.push(row);
304
+ })
305
+ }
306
+
307
+ this.setSelectedIDs(selectedIDs, selectedRows);
308
+ }
309
+ print(rows: RowType[])
310
+ {
311
+ const printWindow = window.open('', '', 'height=500,width=800');
312
+ printWindow!.document.write(`<html><head><title>${this.props.name}</title>`);
313
+ printWindow!.document.write('<style>table { width: 100%; border-collapse: collapse; } th, td { border: 1px solid black; padding: 8px; text-align: left; }</style>');
314
+ printWindow!.document.write('</head><body>');
315
+ printWindow!.document.write('<table>');
316
+ printWindow!.document.write('<thead><tr>');
317
+
318
+ this.foreachColumn(true, column =>
319
+ {
320
+ printWindow!.document.write('<th>' + column.text + '</th>');
321
+ });
322
+
323
+ printWindow!.document.write('</tr></thead><tbody>');
324
+
325
+ // Add table rows
326
+ rows.forEach((rowValue, rowIndex) =>
327
+ {
328
+ let row = { index: rowIndex, value: rowValue };
329
+ printWindow!.document.write('<tr>');
330
+ this.foreachColumn(true, column =>
331
+ {
332
+ let cell = this.getCellTableInfo(column, row, true);
333
+ printWindow!.document.write('<td>' + (cell.formatted ?? "") + '</td>');
334
+ });
335
+ printWindow!.document.write('</tr>');
336
+ });
337
+
338
+ printWindow!.document.write('</tbody></table>');
339
+ printWindow!.document.write('</body></html>');
340
+ printWindow!.document.close();
341
+ printWindow!.print();
342
+ }
343
+ exportCSV(rows: RowType[])
344
+ {
345
+ const worksheet = utils.json_to_sheet(rows || []);
346
+ const workbook = utils.book_new();
347
+ utils.book_append_sheet(workbook, worksheet, this.props.name);
348
+ writeFile(workbook, this.props.name + ".xlsx");
349
+ }
350
+
351
+ handleSelectRow(row: TableRowInfo<RowType>, selected: boolean, ctrlKey: boolean, shiftKey: boolean)
352
+ {
353
+ let selectedIDs = this.state.selectedIDs;
354
+ let selectedRows = this.state.selectedRows;
355
+ let rowID = this.props.getRowKey(row);
356
+
357
+ if (shiftKey)
358
+ {
359
+ selectedRows = this.getRowsInRange(this.LastSelectedRowID ?? 0, row.index);
360
+ selectedIDs = selectedRows.map(row => this.props.getRowKey({ index: -1, value: row }));
361
+ }
362
+ else if (selected)
363
+ {
364
+ if (this.isMultipleSelected() && !ctrlKey)
365
+ {
366
+ selectedIDs = [rowID];
367
+ selectedRows = [row.value];
368
+ this.LastSelectedRowID = row.index;
369
+ }
370
+ else
371
+ {
372
+ selectedIDs = selectedIDs.filter(x => x !== rowID);
373
+ selectedRows = selectedRows.filter(x => this.props.getRowKey({ index: -1, value: x }) !== rowID);
374
+ this.LastSelectedRowID = ctrlKey ? row.index : null;
375
+ }
376
+ }
377
+ else
378
+ {
379
+ if (ctrlKey)
380
+ {
381
+ selectedIDs.push(rowID);
382
+ selectedRows.push(row.value);
383
+ }
384
+ else
385
+ {
386
+ selectedIDs = [rowID];
387
+ selectedRows = [row.value];
388
+ }
389
+ this.LastSelectedRowID = row.index;
390
+ }
391
+
392
+ this.setSelectedIDs(selectedIDs, selectedRows);
393
+ }
394
+ getRowsInRange(fromIndex: number, toIndex: number)
395
+ {
396
+ if (!this.state.rows)
397
+ return [];
398
+
399
+ let start = Math.min(fromIndex, toIndex);
400
+ let end = Math.max(fromIndex, toIndex);
401
+
402
+ return this.state.rows?.slice(start, end + 1);
403
+ }
404
+ getSelectedIDs(): string[]
405
+ {
406
+ return this.state.selectedIDs;
407
+ }
408
+ getSelectedRows(): RowType[]
409
+ {
410
+ return this.state.selectedRows;
411
+ }
412
+ setSelectedIDs(ids: string[], rows: RowType[], callback?: () => void)
413
+ {
414
+ this.setState({ selectedIDs: ids, selectedRows: rows }, () =>
415
+ {
416
+ if (this.props.onSelectedIDsChanged)
417
+ this.props.onSelectedIDsChanged();
418
+ if (callback)
419
+ callback();
420
+ });
421
+ }
422
+ private getGroupKey(row: RowType): string
423
+ {
424
+ let h = this.props.hierarchy;
425
+ if (!h || !h.group || h.group.length === 0)
426
+ return "";
427
+ return h.group.map(g =>
428
+ {
429
+ let v = (row as any)[g];
430
+ return v === null || v === undefined ? "" : String(v);
431
+ }).join("");
432
+ }
433
+ private buildChildrenMap(): Map<string, RowType[]> | null
434
+ {
435
+ let h = this.props.hierarchy;
436
+ if (!h || !this.state.rows)
437
+ return null;
438
+ let map = new Map<string, RowType[]>();
439
+ for (let r of this.state.rows)
440
+ {
441
+ let pid = (r as any)[h.parent];
442
+ let pidKey = pid === null || pid === undefined ? "" : String(pid);
443
+ let key = pidKey + "" + this.getGroupKey(r);
444
+ let arr = map.get(key);
445
+ if (!arr) { arr = []; map.set(key, arr); }
446
+ arr.push(r);
447
+ }
448
+ return map;
449
+ }
450
+ private getRowIdValue(row: RowType): string
451
+ {
452
+ let h = this.props.hierarchy;
453
+ if (!h) return "";
454
+ let v = (row as any)[h.id];
455
+ return v === null || v === undefined ? "" : String(v);
456
+ }
457
+ private getRowChildLookupKey(row: RowType): string
458
+ {
459
+ return this.getRowIdValue(row) + "" + this.getGroupKey(row);
460
+ }
461
+ private isExpanded(rowKey: string): boolean
462
+ {
463
+ let inList = this.state.expandedIDs.includes(rowKey);
464
+ return this.props.defaultExpanded ? !inList : inList;
465
+ }
466
+ private toggleExpanded(rowKey: string)
467
+ {
468
+ let ids = this.state.expandedIDs;
469
+ if (ids.includes(rowKey))
470
+ ids = ids.filter(x => x !== rowKey);
471
+ else
472
+ ids = [...ids, rowKey];
473
+ this.setState({ expandedIDs: ids });
474
+ }
475
+ private isAllSelected(): boolean
476
+ {
477
+ if (!this.state.rows || this.state.rows.length === 0)
478
+ return false;
479
+ const selectableCount = this.state.rows.filter((row, i) =>
480
+ !this.props.getRowCheckboxDisabled?.({ index: i, value: row })
481
+ ).length;
482
+ return selectableCount > 0 && this.state.selectedIDs.length === selectableCount;
483
+ }
484
+ private isSomeSelected(): boolean
485
+ {
486
+ return this.state.selectedIDs.length > 0 && !this.isAllSelected();
487
+ }
488
+ private isMultipleSelected(): boolean
489
+ {
490
+ return this.state.selectedIDs.length > 1;
491
+ }
492
+ private getCellTableInfo(column: TableColumnInfo, row: TableRowInfo<RowType>, printable: boolean)
493
+ {
494
+ let value = (row.value as any)[column.name];
495
+ let formatted = this.getCellFormattedValue(value, column, row, printable);
496
+ return { column, row, value, formatted };
497
+ }
498
+ private getCellFormattedValue(value: any, column: TableColumnInfo, row: TableRowInfo<RowType>, printable: boolean)
499
+ {
500
+ if (this.props.getCellFormattedValue)
501
+ return this.props.getCellFormattedValue(value, column, row, printable);
502
+ return column.formatter.format(value, column, row, printable);
503
+ }
504
+ private getColumnWidthsKey(): string
505
+ {
506
+ return "ns_table_" + this.props.name + "_column_widths";
507
+ }
508
+ private loadColumnWidths(): { [key: string]: number }
509
+ {
510
+ let storage = new IStorageLocal();
511
+ let item = storage.get(this.getColumnWidthsKey(), "");
512
+ try
513
+ {
514
+ return JSON.parse(item);
515
+ }
516
+ catch
517
+ {
518
+ return {};
519
+ }
520
+ }
521
+ private saveColumnWidths(widths: { [key: string]: number })
522
+ {
523
+ let storage = new IStorageLocal();
524
+ storage.set(this.getColumnWidthsKey(), JSON.stringify(widths));
525
+ }
526
+ private getColumnKey(column: TableColumnInfo): string
527
+ {
528
+ return column.table.name + "_" + column.name;
529
+ }
530
+ private getColumnWidth(column: TableColumnInfo): number
531
+ {
532
+ let key = this.getColumnKey(column);
533
+ if (this.state.columnWidths[key] !== undefined)
534
+ return this.state.columnWidths[key];
535
+ let w = column.formatter.width;
536
+ if (typeof w === 'number') return w;
537
+ if (typeof w === 'string')
538
+ {
539
+ let parsed = parseInt(w, 10);
540
+ if (!isNaN(parsed)) return parsed;
541
+ }
542
+ return 120;
543
+ }
544
+ private getGridTemplateColumns(): string
545
+ {
546
+ let parts: string[] = [];
547
+ if (this.props.checkbox)
548
+ parts.push("40px");
549
+ this.getColumns(true).forEach(column =>
550
+ {
551
+ parts.push(this.getColumnWidth(column) + "px");
552
+ });
553
+ return parts.join(" ");
554
+ }
555
+ private startResize(e: React.MouseEvent, column: TableColumnInfo)
556
+ {
557
+ e.preventDefault();
558
+ e.stopPropagation();
559
+ let key = this.getColumnKey(column);
560
+ let startX = e.clientX;
561
+ let startWidth = this.getColumnWidth(column);
562
+ let currentWidths = { ...this.state.columnWidths };
563
+ document.body.style.cursor = 'col-resize';
564
+ document.body.style.userSelect = 'none';
565
+ const onMouseMove = (ev: MouseEvent) =>
566
+ {
567
+ let delta = ev.clientX - startX;
568
+ let newWidth = Math.max(80, startWidth + delta);
569
+ currentWidths = { ...currentWidths, [key]: newWidth };
570
+ this.setState({ columnWidths: currentWidths }, () => this.syncScrollbarWidth());
571
+ };
572
+ const onMouseUp = () =>
573
+ {
574
+ document.body.style.cursor = '';
575
+ document.body.style.userSelect = '';
576
+ document.removeEventListener('mousemove', onMouseMove);
577
+ document.removeEventListener('mouseup', onMouseUp);
578
+ this.resizeMoveHandler = null;
579
+ this.resizeUpHandler = null;
580
+ this.saveColumnWidths(currentWidths);
581
+ };
582
+ this.resizeMoveHandler = onMouseMove;
583
+ this.resizeUpHandler = onMouseUp;
584
+ document.addEventListener('mousemove', onMouseMove);
585
+ document.addEventListener('mouseup', onMouseUp);
586
+ }
587
+ override componentDidMount(): void
588
+ {
589
+ if (!this.NSPagination.current)
590
+ this.reload(null, null);
591
+
592
+ this.syncScrollbarWidth();
593
+ }
594
+ override componentWillUnmount(): void
595
+ {
596
+ if (this.resizeMoveHandler)
597
+ document.removeEventListener('mousemove', this.resizeMoveHandler);
598
+ if (this.resizeUpHandler)
599
+ document.removeEventListener('mouseup', this.resizeUpHandler);
600
+ }
601
+ override render()
602
+ {
603
+
604
+ let show_pagination = this.props.ui?.pagination ?? true;
605
+ let show_button_panel = this.props.ui?.button_panel ?? true;
606
+ let getRowAttributes = (row_value: RowType, row_index: number) =>
607
+ {
608
+ if (this.props.getRowAttributes)
609
+ return this.props.getRowAttributes(row_value, row_index);
610
+ return {};
611
+ }
612
+ let getColumnAttributes = (column: TableColumnInfo) =>
613
+ {
614
+ if (this.props.getColumnAttributes)
615
+ return this.props.getColumnAttributes(column);
616
+ return {};
617
+ }
618
+ let onColumnClick = (e: React.MouseEvent<HTMLTableCellElement, MouseEvent>, column: TableColumnInfo) =>
619
+ {
620
+ if ((e.target as HTMLElement).tagName !== "SPAN")
621
+ return;
622
+
623
+ if (this.props.onColumnClick)
624
+ this.props.onColumnClick(e, column);
625
+ }
626
+ let onRowClick = (e: React.MouseEvent<HTMLTableRowElement, MouseEvent>, row: TableRowInfo<RowType>, selected: boolean) =>
627
+ {
628
+ const target = e.target as HTMLElement;
629
+
630
+ if (target.tagName === "TR" || target.tagName === "TD" || target.closest("td")?.dataset.cellType === "checkbox")
631
+ this.handleSelectRow(row, selected, e.ctrlKey, e.shiftKey);
632
+
633
+ if (this.props.onRowClick)
634
+ this.props.onRowClick(e, row);
635
+ };
636
+ let onCellClick = (e: React.MouseEvent<HTMLTableCellElement, MouseEvent>, cell: TableCellInfo<RowType>) =>
637
+ {
638
+ if ((e.target as HTMLElement).tagName !== "SPAN")
639
+ return;
640
+
641
+ let overided = cell.column.formatter.onclick_overrided;
642
+ if (this.props.onCellClick)
643
+ overided = this.props.onCellClick(e, cell) ?? true;
644
+ if (!overided)
645
+ this.showModal(cell.formatted, cell.column.text);
646
+ };
647
+ let gridTemplateColumns = this.getGridTemplateColumns();
648
+ let content;
649
+ if (this.state.rows === null)
650
+ {
651
+ content = (
652
+ <tr className="d-flex justify-content-center align-items-center p-0">
653
+ <td className="w-100 h-100 m-0 mh-100">
654
+ <NSLoading />
655
+ </td>
656
+ </tr>
657
+ );
658
+ }
659
+ else if (this.state.rows.length === 0)
660
+ {
661
+ content = (
662
+ <tr className="d-flex justify-content-center align-items-center p-0">
663
+ <td className="w-100 h-100 m-0 mh-100">
664
+ <NSNoData lable='No Data' classList={["p-3"]} />
665
+ </td>
666
+ </tr>
667
+ );
668
+ }
669
+ else
670
+ {
671
+ let hierarchical = !!this.props.hierarchy;
672
+ let childrenMap = this.buildChildrenMap();
673
+ let indexOfRow = new Map<RowType, number>();
674
+ this.state.rows.forEach((r, i) => indexOfRow.set(r, i));
675
+ let INDENT = 16;
676
+ let lineColor = "rgba(20, 27, 92, 0.35)";
677
+ let renderRow = (rowValue: RowType, rowIndex: number, depth: number, parentKey: string, ancestorHasNext: boolean[], isLastChild: boolean): React.ReactNode[] =>
678
+ {
679
+ let row = { index: rowIndex, value: rowValue };
680
+ let rowKey = this.props.getRowKey(row);
681
+ let reactKey = parentKey ? `${parentKey}>${rowKey}` : rowKey;
682
+ let isSelected = this.state.selectedIDs.includes(rowKey);
683
+ let isLastSelected = this.LastSelectedRowID === row.index;
684
+ let isCheckboxDisabled = this.props.getRowCheckboxDisabled?.(row) ?? false;
685
+ let children: RowType[] = [];
686
+ if (hierarchical && childrenMap)
687
+ {
688
+ let lookupKey = this.getRowChildLookupKey(rowValue);
689
+ children = childrenMap.get(lookupKey) ?? [];
690
+ }
691
+ let hasChildren = children.length > 0;
692
+ let expanded = this.isExpanded(rowKey);
693
+ let rowAttrs = getRowAttributes(rowValue, rowIndex);
694
+ let nodes: React.ReactNode[] = [];
695
+ nodes.push(
696
+ <tr
697
+ key={reactKey}
698
+ {...rowAttrs}
699
+ style={{ ...(rowAttrs.style || {}), gridTemplateColumns }}
700
+ className={`${isSelected ? Styles.ns_selected : ""} ${isLastSelected ? Styles.ns_last_selected : ""}`.trim()}
701
+ onClick={(e) => !isCheckboxDisabled && onRowClick(e, row, isSelected)}
702
+ >
703
+ {
704
+ this.props.checkbox &&
705
+ <td data-cell-type="checkbox">
706
+ <label
707
+ htmlFor={`checkbox_device_${rowKey}`}
708
+ className={Styles.ns_check_box_label}
709
+ >
710
+ <input
711
+ id={`checkbox_device_${rowKey}`}
712
+ type="checkbox"
713
+ checked={isSelected}
714
+ disabled={isCheckboxDisabled}
715
+ className={Styles.ns_check_box}
716
+ onChange={() => { }}
717
+ />
718
+ </label>
719
+ </td>
720
+ }
721
+ {
722
+ this.getColumns(true).map((column, index) =>
723
+ {
724
+ column.index = index + (this.props.checkbox ? 1 : 0);
725
+ let cell = this.getCellTableInfo(column, row, false);
726
+ let isFirstDataColumn = index === 0;
727
+ return (
728
+ <td
729
+ key={column.index}
730
+ {...getColumnAttributes(column)}
731
+ data-label={`${column.text}: `}
732
+ width={column.formatter.width}
733
+ className=''
734
+ style={isFirstDataColumn && hierarchical ? { overflow: "visible" } : undefined}
735
+ onClick={(e) =>
736
+ {
737
+ onColumnClick(e, column);
738
+ onCellClick(e, cell);
739
+ }}
740
+ >
741
+ {isFirstDataColumn && hierarchical ? (
742
+ <div
743
+ style={{
744
+ display: "flex",
745
+ alignItems: "center",
746
+ }}
747
+ >
748
+ {Array.from({ length: depth }).map((_, i) =>
749
+ {
750
+ let isLastLevel = i === depth - 1;
751
+ let drawVerticalTop = i < depth - 1 ? ancestorHasNext[i] : true;
752
+ let drawVerticalBottom = i < depth - 1 ? ancestorHasNext[i] : !isLastChild;
753
+ let drawHorizontal = isLastLevel;
754
+ return (
755
+ <span
756
+ key={i}
757
+ style={{
758
+ position: "relative",
759
+ display: "inline-block",
760
+ width: INDENT,
761
+ alignSelf: "stretch",
762
+ flex: "0 0 auto",
763
+ }}
764
+ >
765
+ {drawVerticalTop && (
766
+ <span style={{
767
+ position: "absolute",
768
+ left: INDENT / 2,
769
+ top: -24,
770
+ height: "calc(50% + 24px)",
771
+ width: 1,
772
+ background: lineColor,
773
+ }} />
774
+ )}
775
+ {drawVerticalBottom && (
776
+ <span style={{
777
+ position: "absolute",
778
+ left: INDENT / 2,
779
+ top: "50%",
780
+ height: "calc(50% + 24px)",
781
+ width: 1,
782
+ background: lineColor,
783
+ }} />
784
+ )}
785
+ {drawHorizontal && (
786
+ <span style={{
787
+ position: "absolute",
788
+ left: INDENT / 2,
789
+ top: "50%",
790
+ width: INDENT / 2,
791
+ height: 1,
792
+ background: lineColor,
793
+ }} />
794
+ )}
795
+ </span>
796
+ );
797
+ })}
798
+ <span
799
+ data-cell-type="tree-toggle"
800
+ style={{
801
+ display: "inline-flex",
802
+ alignItems: "center",
803
+ justifyContent: "center",
804
+ marginRight: 6,
805
+ }}
806
+ onClick={(e) => e.stopPropagation()}
807
+ >
808
+ {hasChildren ? (
809
+ <button
810
+ type="button"
811
+ onClick={(e) =>
812
+ {
813
+ e.stopPropagation();
814
+ this.toggleExpanded(rowKey);
815
+ }}
816
+ style={{
817
+ width: 18,
818
+ height: 18,
819
+ lineHeight: "16px",
820
+ padding: 0,
821
+ border: "1px solid rgba(20, 27, 92, 0.4)",
822
+ borderRadius: 3,
823
+ background: "#fff",
824
+ cursor: "pointer",
825
+ fontSize: 14,
826
+ fontWeight: "bold",
827
+ color: "rgba(20, 27, 92, 1)",
828
+ }}
829
+ aria-label={expanded ? "Collapse" : "Expand"}
830
+ >
831
+ {expanded ? "−" : "+"}
832
+ </button>
833
+ ) : (
834
+ <span style={{ display: "inline-block", width: 18, height: 18 }} />
835
+ )}
836
+ </span>
837
+ {cell.formatted ?? ""}
838
+ </div>
839
+ ) : (
840
+ <>
841
+ {cell.formatted ?? ""}
842
+ </>
843
+ )}
844
+ </td>
845
+ );
846
+ })
847
+ }
848
+ </tr>
849
+ );
850
+ if (hierarchical && hasChildren && expanded)
851
+ {
852
+ let childAncestors = [...ancestorHasNext, !isLastChild];
853
+ children.forEach((child, ci2) =>
854
+ {
855
+ let ci = indexOfRow.get(child) ?? -1;
856
+ let lastChild = ci2 === children.length - 1;
857
+ renderRow(child, ci, depth + 1, reactKey, childAncestors, lastChild).forEach(n => nodes.push(n));
858
+ });
859
+ }
860
+ return nodes;
861
+ };
862
+ let topLevel: RowType[];
863
+ if (hierarchical && this.props.hierarchy)
864
+ {
865
+ let parentCol = this.props.hierarchy.parent;
866
+ let ids = new Set<string>();
867
+ this.state.rows.forEach(r => ids.add(this.getRowIdValue(r) + "" + this.getGroupKey(r)));
868
+ topLevel = this.state.rows.filter(r =>
869
+ {
870
+ let pid = (r as any)[parentCol];
871
+ let pidKey = pid === null || pid === undefined ? "" : String(pid);
872
+ if (pidKey === "")
873
+ return true;
874
+ return !ids.has(pidKey + "" + this.getGroupKey(r));
875
+ });
876
+ }
877
+ else
878
+ {
879
+ topLevel = this.state.rows;
880
+ }
881
+ content = topLevel.flatMap((rowValue, i) => renderRow(rowValue, indexOfRow.get(rowValue) ?? 0, 0, "", [], i === topLevel.length - 1));
882
+ }
883
+
884
+ let getSortSign = (column: TableColumnInfo) =>
885
+ {
886
+ if (this.state.sortItems)
887
+ {
888
+ let c = this.state.sortItems.filter(c => c.table.name === column.table.name && c.column.name === column.name)[0]
889
+ if (c)
890
+ {
891
+ if (c.ascending)
892
+ return "↑"
893
+ return "↓";
894
+ }
895
+ }
896
+ return "";
897
+ };
898
+
899
+ let buttonPanel = show_button_panel && (
900
+ <div className={Styles.ns_button_panel}>
901
+ {
902
+ this.state.pageSelectionMode !== PageSelectionMode.Hidden &&
903
+ <NSDialogPageSelection<RowType>
904
+ icon={
905
+ this.state.pageSelectionMode === PageSelectionMode.Print ? "https://static.namirasoft.com/image/concept/print/blue.svg" :
906
+ this.state.pageSelectionMode === PageSelectionMode.CSV ? "https://static.namirasoft.com/image/concept/export/blue.svg" : ""
907
+ }
908
+ current_page={this.NSPagination.current?.getCurrentPage() ?? 1}
909
+ current_size={this.NSPagination.current?.getPageSize() ?? 0}
910
+ max_page={this.state.totalItems}
911
+ getItems={async (page, size, selected) =>
912
+ {
913
+ if (selected)
914
+ {
915
+ let rows: RowType[] = [];
916
+ if (this.state.rows)
917
+ for (let i = 0; i < this.state.rows.length; i++)
918
+ {
919
+ const row = { index: i, value: this.state.rows[i] };
920
+ let id = this.props.getRowKey(row);
921
+ if (this.state.selectedIDs.includes(id))
922
+ rows.push(row.value);
923
+ }
924
+ return rows;
925
+ }
926
+ let res = await this.props.getRows(page, size, this.getSortItems());
927
+ return res.rows;
928
+ }}
929
+ onFinish={async (items: RowType[]) =>
930
+ {
931
+ if (this.state.pageSelectionMode === PageSelectionMode.Print)
932
+ this.print(items);
933
+ else if (this.state.pageSelectionMode === PageSelectionMode.CSV)
934
+ this.exportCSV(items);
935
+ }}
936
+ onClose={() => this.setState({ pageSelectionMode: PageSelectionMode.Hidden })}
937
+ />
938
+ }
939
+ {
940
+ this.props.buttons?.map((button, index) => (
941
+ <NSButton
942
+ key={index}
943
+ {...button}
944
+ classList={[Styles.ns_table_button, ...(button.classList ?? [])]}
945
+ />
946
+ ))
947
+ }
948
+ <NSButton
949
+ icon={{ src: `https://static.namirasoft.com/image/concept/full-screen/blue.svg` }}
950
+ classList={[Styles.ns_table_button, Styles.ns_fullscreen_button]}
951
+ onClick={{
952
+ action: this.toggleFullscreen,
953
+ showLoading: false
954
+ }}
955
+ attributes={{ title: this.state.fullscreen ? 'Minimize' : 'Maximize' }}
956
+ />
957
+ <NSButton
958
+ attributes={{ title: 'Chart' }}
959
+ icon={{ src: "https://static.namirasoft.com/image/concept/chart/blue.svg" }}
960
+ onClick={{
961
+ action: () =>
962
+ {
963
+ this.showModal(" ", "This feature will be available soon in upcoming versions.");
964
+ },
965
+ showLoading: false
966
+ }}
967
+ classList={[Styles.ns_table_button]}
968
+ />
969
+ <NSButton
970
+ icon={{ src: "https://static.namirasoft.com/image/concept/export/blue.svg" }}
971
+ onClick={{
972
+ action: () => { this.setState({ pageSelectionMode: PageSelectionMode.CSV }); },
973
+ showLoading: false
974
+ }}
975
+ classList={[Styles.ns_table_button]}
976
+ attributes={{ title: 'Export' }}
977
+ />
978
+ <NSButton
979
+ attributes={{ title: 'Print' }}
980
+ icon={{ src: "https://static.namirasoft.com/image/concept/print/blue.svg" }}
981
+ onClick={{
982
+ action: () => { this.setState({ pageSelectionMode: PageSelectionMode.Print }); },
983
+ showLoading: false
984
+ }}
985
+ classList={[Styles.ns_table_button]}
986
+ />
987
+ <NSButton
988
+ attributes={{ title: 'Refresh' }}
989
+ icon={{ src: "https://static.namirasoft.com/image/concept/refresh/blue.svg" }}
990
+ onClick={{
991
+ action: async (onFinished) =>
992
+ {
993
+ this.reload(null, null).then(onFinished).catch(onFinished);
994
+ }
995
+ }}
996
+ classList={[Styles.ns_table_button]}
997
+ style={{ border: '1px solid rgb(3, 119, 255)' }}
998
+ />
999
+ </div>
1000
+ );
1001
+
1002
+ return (
1003
+ <div
1004
+ id={this.props.id}
1005
+ className={[...this.props.classList ?? [], Styles.ns_table_wrapper, this.state.fullscreen ? Styles.ns_fullscreen : ""].filter(Boolean).join(" ")}
1006
+ style={{ ...this.props.style }}
1007
+ >
1008
+ <div className={Styles.ns_table_topbar}>
1009
+ {
1010
+ !this.state.fullscreen &&
1011
+ this.props.headerChildren
1012
+ }
1013
+ {
1014
+ show_pagination &&
1015
+ <NSPagination ref={this.NSPagination} totalItems={this.state.totalItems} onPageChange={this.onPageChange} style={{ marginRight: "auto" }} />
1016
+ }
1017
+ {buttonPanel}
1018
+ </div>
1019
+ {
1020
+ !this.state.fullscreen && this.props.children &&
1021
+ <div className={Styles.ns_table_children}>
1022
+ {this.props.children}
1023
+ </div>
1024
+ }
1025
+ <table
1026
+ ref={this.Table_Ref}
1027
+ className={Styles.ns_table}
1028
+ onScroll={() =>
1029
+ {
1030
+ if (this.TableScrollbar_Ref.current)
1031
+ this.TableScrollbar_Ref.current.scrollLeft = this.Table_Ref.current?.scrollLeft ?? 0;
1032
+ }}
1033
+ >
1034
+ <thead>
1035
+ <tr style={{ gridTemplateColumns }}>
1036
+ {
1037
+ this.props.checkbox &&
1038
+ <th data-cell-type="checkbox" style={{ width: "24px", height: "24px", padding: 0 }}>
1039
+ <label
1040
+ htmlFor='checkbox'
1041
+ className={Styles.ns_checkbox_label}
1042
+ >
1043
+ <input
1044
+ id="checkbox"
1045
+ type="checkbox"
1046
+ className={`${Styles.ns_check_box} ${this.isSomeSelected() ? Styles.ns_indeterminate : ""}`}
1047
+ checked={this.getSelectedIDs().length > 0}
1048
+ onChange={this.toggleAllSelections}
1049
+ ></input>
1050
+ </label>
1051
+ </th>
1052
+ }
1053
+ {
1054
+ this.getColumns(true).map(column => <th
1055
+ key={column.name}
1056
+ scope="col"
1057
+ style={{ width: this.getColumnWidth(column), cursor: "pointer", position: "relative", userSelect: "none" }}
1058
+ onClick={(e) =>
1059
+ {
1060
+ if ((e.target as HTMLElement).closest('[data-resize-handle]')) return;
1061
+ let t = new BaseMetaTable(null, column.table.name, column.table.text);
1062
+ let c = new BaseMetaColumn(t, column.name, column.text, "", false);
1063
+ let items = this.getSortItems();
1064
+ if (!items || items.length === 0 || items[0].table.name !== t.name || items[0].column.name !== c.name)
1065
+ this.setSortItems([new SortItem(t, c, true)]);
1066
+ else
1067
+ {
1068
+ if (items[0].ascending)
1069
+ this.setSortItems([new SortItem(t, c, false)]);
1070
+ else
1071
+ this.setSortItems(null);
1072
+ }
1073
+ }}
1074
+ >
1075
+ <span>{column.text + " " + getSortSign(column)}</span>
1076
+ <div
1077
+ data-resize-handle="true"
1078
+ className={Styles.ns_resize_handle}
1079
+ onMouseDown={(e) => this.startResize(e, column)}
1080
+ onClick={(e) => e.stopPropagation()}
1081
+ />
1082
+ </th>)
1083
+ }
1084
+ </tr>
1085
+ </thead>
1086
+
1087
+ <tbody className={Styles.ns_tbody}>
1088
+ {content}
1089
+ </tbody>
1090
+ </table>
1091
+
1092
+ <div
1093
+ ref={this.TableScrollbar_Ref}
1094
+ className={Styles.ns_table_scrollbar}
1095
+ onScroll={() =>
1096
+ {
1097
+ if (this.Table_Ref.current)
1098
+ this.Table_Ref.current.scrollLeft = this.TableScrollbar_Ref.current?.scrollLeft ?? 0;
1099
+ }}
1100
+ >
1101
+ <div
1102
+ ref={this.TableScrollbarContent_Ref}
1103
+ className={Styles.ns_table_scrollbar_content}>
1104
+ </div>
1105
+ </div>
1106
+
1107
+ {
1108
+ this.state.model.show &&
1109
+ <NSDialogInfo
1110
+ description={this.state.model.description}
1111
+ onClose={() => { this.hideModal(); }}
1112
+ title={this.state.title}
1113
+ show_as_code={true}
1114
+ >
1115
+ <></>
1116
+ </NSDialogInfo>
1117
+ }
1118
+ </div>
1119
+ );
1120
+ }
1119
1121
  }