@svgrid/enterprise 3.1.39 → 3.1.41

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 (307) hide show
  1. package/dist/SvGridBoard.svelte +20 -3
  2. package/dist/SvGridScheduler.svelte +112 -6
  3. package/dist/cdn/smart.export.entry-BvRk9kiK.js +0 -0
  4. package/dist/cdn/svgrid-enterprise.svelte-external.js +541 -538
  5. package/dist/designer/assets/GridFind-DSgjlakI.js +1 -0
  6. package/dist/designer/assets/GridFooter-EjA_7y8w.js +1 -0
  7. package/dist/designer/assets/GridMenus-BBsuf2vC.js +1 -0
  8. package/dist/designer/assets/PinSplitter-oi6ffxQy.js +1 -0
  9. package/dist/designer/assets/SvChartMenu-Durtznhb.js +1 -0
  10. package/dist/designer/assets/SvDateRangeInput-oZyXTEr3.js +1 -0
  11. package/dist/designer/assets/SvDateTimePicker-CUobIgHE.js +1 -0
  12. package/dist/designer/assets/SvGridCellEditor-D_rvqE02.js +3 -0
  13. package/dist/designer/assets/SvGridChart-D0XxAoxS.js +2 -0
  14. package/dist/designer/assets/SvGridChartBuilder-CkuDEcl1.js +1 -0
  15. package/dist/designer/assets/SvGridChartPanel-BUsAzEtx.js +3 -0
  16. package/dist/designer/assets/SvGridChartView-CU_9mwuA.js +1 -0
  17. package/dist/designer/assets/SvGridDropdown-BtnFfHzX.js +1 -0
  18. package/dist/designer/assets/SvListBox-0SCz8lCl.js +2 -0
  19. package/dist/designer/assets/SvMenuList-DpXScUvp.js +1 -0
  20. package/dist/designer/assets/SvTabs-CYhfWOzJ.js +1 -0
  21. package/dist/designer/assets/chart-D0Hi9Ajj.js +1 -0
  22. package/dist/designer/assets/{chart-panel-messages-D2esv6rR.js → chart-panel-messages-CUwx2rdP.js} +1 -1
  23. package/dist/designer/assets/date-format-C5MG3rPF.js +1 -0
  24. package/dist/designer/assets/dismissable-BA8Sdkgf.js +1 -0
  25. package/dist/designer/assets/grid-extension.svelte-BKJJBM8e.js +1 -0
  26. package/dist/designer/assets/{index-6iBLPJQo.js → index-OcSC-rI4.js} +654 -654
  27. package/dist/designer/assets/index-axFTZtlf.css +1 -0
  28. package/dist/designer/assets/index-client-CwjHmKgT.js +2 -0
  29. package/dist/designer/assets/{range-commit-CvP8vrGh.js → range-commit-B_t6HYjs.js} +1 -1
  30. package/dist/designer/assets/row-drag-Dt3zdAss.js +1 -0
  31. package/dist/designer/assets/smart.export.entry-BvRk9kiK.js +0 -0
  32. package/dist/designer/assets/src-CYr2fa73.js +35 -0
  33. package/dist/designer/assets/src-rcijGyZS.js +1 -0
  34. package/dist/designer/index.html +17 -18
  35. package/dist/export.js +1 -1
  36. package/dist/fields/AttachmentDialog.svelte +5 -1
  37. package/dist/fields/AutomationAction.svelte +159 -0
  38. package/dist/fields/AutomationAction.svelte.d.ts +25 -0
  39. package/dist/fields/AutomationSteps.svelte +32 -0
  40. package/dist/fields/AutomationSteps.svelte.d.ts +25 -0
  41. package/dist/fields/AutomationTrigger.svelte +54 -0
  42. package/dist/fields/AutomationTrigger.svelte.d.ts +15 -0
  43. package/dist/fields/BarcodeScanner.svelte +17 -0
  44. package/dist/fields/BarcodeScanner.svelte.d.ts +6 -0
  45. package/dist/fields/BaseAutomations.svelte +11 -128
  46. package/dist/fields/BaseAutomations.svelte.d.ts +4 -0
  47. package/dist/fields/BaseDashboardView.svelte +58 -6
  48. package/dist/fields/BaseImport.svelte +2 -2
  49. package/dist/fields/BaseImport.svelte.d.ts +7 -0
  50. package/dist/fields/BasePivotView.svelte +56 -0
  51. package/dist/fields/BasePivotView.svelte.d.ts +9 -0
  52. package/dist/fields/BaseTableView.svelte +25 -3
  53. package/dist/fields/BaseTableView.svelte.d.ts +16 -1
  54. package/dist/fields/BaseTabs.svelte +54 -6
  55. package/dist/fields/BaseTabs.svelte.d.ts +7 -1
  56. package/dist/fields/DashboardTileEditor.svelte +62 -5
  57. package/dist/fields/DashboardTileEditor.svelte.d.ts +2 -0
  58. package/dist/fields/DateEditor.svelte +8 -3
  59. package/dist/fields/FieldInput.svelte +9 -2
  60. package/dist/fields/LinkPickerEditor.svelte +3 -2
  61. package/dist/fields/RecordTemplates.svelte +52 -0
  62. package/dist/fields/RecordTemplates.svelte.d.ts +10 -0
  63. package/dist/fields/RecordView.svelte +15 -3
  64. package/dist/fields/RowAdder.svelte +21 -3
  65. package/dist/fields/RowHeader.svelte +21 -2
  66. package/dist/fields/SelectEditor.svelte +12 -6
  67. package/dist/fields/SummaryCell.svelte +1 -1
  68. package/dist/fields/SvBase.svelte +13 -4
  69. package/dist/fields/SvBase.svelte.d.ts +52 -1
  70. package/dist/fields/SvBaseAutomations.svelte +205 -0
  71. package/dist/fields/SvBaseAutomations.svelte.d.ts +27 -0
  72. package/dist/fields/SvBaseForm.svelte +69 -34
  73. package/dist/fields/SvBaseForm.svelte.d.ts +13 -0
  74. package/dist/fields/SvBaseViewBar.svelte +29 -9
  75. package/dist/fields/SvBaseViewBar.svelte.d.ts +10 -0
  76. package/dist/fields/TimerCell.svelte +28 -0
  77. package/dist/fields/TimerCell.svelte.d.ts +16 -0
  78. package/dist/fields/TimerEditor.svelte +7 -0
  79. package/dist/fields/TimerEditor.svelte.d.ts +14 -0
  80. package/dist/fields/activity.svelte.d.ts +5 -0
  81. package/dist/fields/airtable.js +1 -1
  82. package/dist/fields/attachments.d.ts +8 -0
  83. package/dist/fields/attachments.js +1 -1
  84. package/dist/fields/automation-edit.d.ts +36 -0
  85. package/dist/fields/automation-edit.js +12 -0
  86. package/dist/fields/automation-outbound.d.ts +17 -0
  87. package/dist/fields/automation-outbound.js +1 -1
  88. package/dist/fields/automation-script.d.ts +59 -0
  89. package/dist/fields/automation-script.js +101 -0
  90. package/dist/fields/automation-server.d.ts +3 -0
  91. package/dist/fields/automation-server.js +1 -1
  92. package/dist/fields/automations.svelte.d.ts +74 -5
  93. package/dist/fields/automations.svelte.js +1 -1
  94. package/dist/fields/barcode-scan.d.ts +8 -0
  95. package/dist/fields/barcode-scan.js +1 -0
  96. package/dist/fields/base-compute.js +1 -1
  97. package/dist/fields/base-export.js +1 -1
  98. package/dist/fields/base-import.d.ts +6 -0
  99. package/dist/fields/base-import.js +1 -1
  100. package/dist/fields/base-permissions.d.ts +1 -1
  101. package/dist/fields/base-permissions.js +1 -1
  102. package/dist/fields/base-search.js +1 -1
  103. package/dist/fields/base-sync.d.ts +12 -2
  104. package/dist/fields/base-sync.js +1 -1
  105. package/dist/fields/base-tables.d.ts +20 -0
  106. package/dist/fields/base-tables.js +1 -1
  107. package/dist/fields/builtin-types.js +1 -1
  108. package/dist/fields/chart-view.d.ts +4 -0
  109. package/dist/fields/chart-view.js +1 -1
  110. package/dist/fields/convert.js +1 -1
  111. package/dist/fields/copy-text.js +1 -1
  112. package/dist/fields/dashboard.d.ts +84 -1
  113. package/dist/fields/dashboard.js +1 -1
  114. package/dist/fields/field-ops.js +1 -1
  115. package/dist/fields/filter-model.d.ts +1 -1
  116. package/dist/fields/filter-model.js +1 -1
  117. package/dist/fields/index.d.ts +12 -4
  118. package/dist/fields/index.js +1 -1
  119. package/dist/fields/messages/extras.d.ts +94 -0
  120. package/dist/fields/messages/extras.js +1 -1
  121. package/dist/fields/messages/fields.d.ts +19 -0
  122. package/dist/fields/messages/fields.js +1 -1
  123. package/dist/fields/messages/record.d.ts +13 -0
  124. package/dist/fields/messages/record.js +1 -1
  125. package/dist/fields/messages/shell.d.ts +5 -0
  126. package/dist/fields/messages/shell.js +1 -1
  127. package/dist/fields/messages/viewbar.d.ts +68 -2
  128. package/dist/fields/messages/viewbar.js +1 -1
  129. package/dist/fields/messages.svelte.d.ts +199 -2
  130. package/dist/fields/phone-sheet.d.ts +6 -0
  131. package/dist/fields/phone-sheet.js +1 -0
  132. package/dist/fields/record-actions.d.ts +23 -0
  133. package/dist/fields/record-actions.js +1 -0
  134. package/dist/fields/record-menu.js +1 -1
  135. package/dist/fields/record-store.svelte.d.ts +6 -2
  136. package/dist/fields/record-store.svelte.js +1 -1
  137. package/dist/fields/sources.svelte.d.ts +8 -0
  138. package/dist/fields/summaries.js +1 -1
  139. package/dist/fields/timer-clock.svelte.d.ts +4 -0
  140. package/dist/fields/timer-clock.svelte.js +1 -0
  141. package/dist/fields/timer.d.ts +22 -0
  142. package/dist/fields/timer.js +1 -0
  143. package/dist/fields/tree-edit.d.ts +47 -0
  144. package/dist/fields/tree-edit.js +1 -0
  145. package/dist/fields/view-actions.d.ts +23 -0
  146. package/dist/fields/view-actions.js +1 -0
  147. package/dist/fields/view-model.d.ts +28 -3
  148. package/dist/fields/view-model.js +1 -1
  149. package/dist/fields/viewbar/FilterPanel.svelte +1 -1
  150. package/dist/fields/viewbar/GanttPanel.svelte +13 -3
  151. package/dist/fields/viewbar/GanttPanel.svelte.d.ts +3 -1
  152. package/dist/fields/viewbar/HideFieldsPanel.svelte +13 -2
  153. package/dist/fields/viewbar/ViewsMenu.svelte +69 -7
  154. package/dist/fields/viewbar/ViewsMenu.svelte.d.ts +4 -0
  155. package/dist/node/studio.js +2 -2
  156. package/dist/scheduler-config.d.ts +10 -0
  157. package/dist/smart.export.entry.d.ts +3 -0
  158. package/dist/smart.export.entry.js +1 -0
  159. package/dist/smart.export.shim.d.ts +1 -0
  160. package/dist/smart.export.shim.js +1 -0
  161. package/dist/sources/rest.d.ts +5 -2
  162. package/dist/sources/rest.js +1 -1
  163. package/dist/studio/ui-components.generated.js +1 -1
  164. package/dist/version.d.ts +2 -2
  165. package/dist/version.js +1 -1
  166. package/dist/wc/CardMenu-D7hQ19pw.js +1 -0
  167. package/dist/wc/GridFind-CBZMU9J6.js +1 -0
  168. package/dist/wc/GridFind-DtGF31ks.js +1 -0
  169. package/dist/wc/GridFooter-DQq6qsE3.js +1 -0
  170. package/dist/wc/GridFooter-p4dE9uns.js +1 -0
  171. package/dist/wc/GridMenus-C4QZ5jnj.js +16 -0
  172. package/dist/wc/GridMenus-sqW-Y7S5.js +16 -0
  173. package/dist/wc/{PinSplitter-DyRfU4Wz.js → PinSplitter-3i65naKl.js} +2 -2
  174. package/dist/wc/{PinSplitter-1fKh3Bwq.js → PinSplitter-CLTE0bRc.js} +2 -2
  175. package/dist/wc/SvChartMenu-B9HnHez5.js +3 -0
  176. package/dist/wc/SvChartMenu-B_tNFTkg.js +1 -0
  177. package/dist/wc/SvDateRangeInput-BPlKigkO.js +1 -0
  178. package/dist/wc/SvDateRangeInput-Djc93m9x.js +1 -0
  179. package/dist/wc/SvDateTimePicker-BEAAe3-f.js +4 -0
  180. package/dist/wc/SvDateTimePicker-DgPz0cBp.js +4 -0
  181. package/dist/wc/{SvField-DUBHk-OY.js → SvField-JpRX8GTw.js} +2 -2
  182. package/dist/wc/SvGridCellEditor-BrFHlf2T.js +3 -0
  183. package/dist/wc/SvGridCellEditor-DK9sYePL.js +3 -0
  184. package/dist/wc/SvGridChart-BHlM2v-1.js +171 -0
  185. package/dist/wc/SvGridChart-CH3IBusu.js +171 -0
  186. package/dist/wc/SvGridChartBuilder-BPbq8uLi.js +7 -0
  187. package/dist/wc/SvGridChartBuilder-Dil4AM1y.js +8 -0
  188. package/dist/wc/SvGridChartPanel-BNX4ElVR.js +5 -0
  189. package/dist/wc/{SvGridChartPanel-CTW5z6Vb.js → SvGridChartPanel-gLhTPhip.js} +3 -3
  190. package/dist/wc/{SvGridChartView-DOOboBce.js → SvGridChartView-CIogzaUy.js} +2 -2
  191. package/dist/wc/{SvGridChartView-CcIMqWgn.js → SvGridChartView-TujvKvl6.js} +2 -2
  192. package/dist/wc/{SvGridDropdown-Co1FnDeB.js → SvGridDropdown-B1iMiyRf.js} +2 -2
  193. package/dist/wc/{SvGridDropdown-CbVCAI1K.js → SvGridDropdown-DauXQKai.js} +2 -2
  194. package/dist/wc/SvMenuList-DD8DyfUc.js +3 -0
  195. package/dist/wc/SvModal-BN4l4cAE.js +7 -0
  196. package/dist/wc/SvModal-CbOvVSpm.js +7 -0
  197. package/dist/wc/SvTabs-CGPGO9Vn.js +2 -0
  198. package/dist/wc/board-DS5OxhbF.js +23 -0
  199. package/dist/wc/board-view.svelte-DZiQ6CpS.js +1 -0
  200. package/dist/wc/{card-marks.svelte-DEmCHZCd.js → card-marks.svelte-Dym4W2PD.js} +1 -1
  201. package/dist/wc/chart-0z2N0RUb.js +1 -0
  202. package/dist/wc/chart-Cbakc50a.js +1 -0
  203. package/dist/wc/chart-panel-messages-P6qAeRsp.js +1 -0
  204. package/dist/wc/client-CjVagnyk.js +3 -0
  205. package/dist/wc/client-DTHOsJhV.js +3 -0
  206. package/dist/wc/core-BhGMIO3G.js +1 -0
  207. package/dist/wc/date-format-DAQ3T50M.js +18 -0
  208. package/dist/wc/{date-format-C_AhjL_N.js → date-format-DYC0HfpK.js} +3 -3
  209. package/dist/wc/dismissable-CuL0k6PX.js +1 -0
  210. package/dist/wc/{dist-xwz8hbY3.js → dist-CU5leork.js} +1 -1
  211. package/dist/wc/{export-CduUYesa.js → export-CzdwAsQD.js} +2 -2
  212. package/dist/wc/extent-Dg7_h_Do.js +1 -0
  213. package/dist/wc/gallery-Bij5kkwt.js +11 -0
  214. package/dist/wc/gantt-DkHZhrMS.js +114 -0
  215. package/dist/wc/grid-extension.svelte-BhPbpIEL.js +1 -0
  216. package/dist/wc/grid-extension.svelte-CgyuY7mw.js +1 -0
  217. package/dist/wc/{js-scroller.svelte-yqKev7S0.js → js-scroller.svelte-DhpfIqCT.js} +1 -1
  218. package/dist/wc/palette-DkaM8TCP.js +46 -0
  219. package/dist/wc/popover-sheets.svelte-DkljoAro.js +2 -0
  220. package/dist/wc/popover-sheets.svelte-ra8as21o.js +2 -0
  221. package/dist/wc/{range-commit-BeTBd6HK.js → range-commit-CGSw1ziH.js} +1 -1
  222. package/dist/wc/{range-commit-CKuvQBcr.js → range-commit-i3L3UjPV.js} +1 -1
  223. package/dist/wc/row-drag-DbVYQ0eO.js +1 -0
  224. package/dist/wc/row-drag-DevACK09.js +1 -0
  225. package/dist/wc/scheduler-BMmQ_wly.js +156 -0
  226. package/dist/wc/scheduler-view.svelte-B4snqguw.js +1 -0
  227. package/dist/wc/{server-block-cache-CQ03vNXZ.js → server-block-cache-C9XwJyu2.js} +1 -1
  228. package/dist/wc/{server-row-model-DHuIO53Q.js → server-row-model-C-FV79zV.js} +1 -1
  229. package/dist/wc/smart.export.entry-BvRk9kiK.js +0 -0
  230. package/dist/wc/sv-base-element.js +229 -84
  231. package/dist/wc/sv-sheet-element.js +54 -158
  232. package/dist/wc/{validate-Blppk1Na.js → validate--KGSlMvP.js} +1 -1
  233. package/package.json +3 -3
  234. package/dist/cdn/smart.export-0xDkly3x.js +0 -250
  235. package/dist/designer/assets/GridFind-PWsi9BvQ.js +0 -1
  236. package/dist/designer/assets/GridFooter-CsnWeWLs.js +0 -1
  237. package/dist/designer/assets/GridMenus-Cu5uIXlg.js +0 -1
  238. package/dist/designer/assets/PinSplitter-66yg1L9j.js +0 -1
  239. package/dist/designer/assets/SvChartMenu-CdTEogez.js +0 -1
  240. package/dist/designer/assets/SvDateRangeInput-DsFP11vx.js +0 -1
  241. package/dist/designer/assets/SvDateTimePicker-Bzaaz3Kp.js +0 -1
  242. package/dist/designer/assets/SvGridCellEditor-DkBK-Cs_.js +0 -3
  243. package/dist/designer/assets/SvGridChart-BqMTsa_R.js +0 -2
  244. package/dist/designer/assets/SvGridChartBuilder-BNcFOTeW.js +0 -1
  245. package/dist/designer/assets/SvGridChartPanel-wUSKfW0h.js +0 -3
  246. package/dist/designer/assets/SvGridChartView-D_815ueY.js +0 -1
  247. package/dist/designer/assets/SvGridDropdown-CvyfuIx7.js +0 -1
  248. package/dist/designer/assets/SvListBox-BZg4K2A3.js +0 -2
  249. package/dist/designer/assets/SvMenuList-COwzLYsg.js +0 -1
  250. package/dist/designer/assets/SvTabs-DkOt7l9F.js +0 -1
  251. package/dist/designer/assets/chart-SJcjQYZM.js +0 -1
  252. package/dist/designer/assets/date-format-rjHbB1Og.js +0 -1
  253. package/dist/designer/assets/dismissable-ChWRPkoa.js +0 -1
  254. package/dist/designer/assets/grid-extension.svelte-BoCs0zu4.js +0 -1
  255. package/dist/designer/assets/index-client-C8cere9K.js +0 -2
  256. package/dist/designer/assets/index-nV1iesTT.css +0 -1
  257. package/dist/designer/assets/row-drag-D5c8CRVe.js +0 -1
  258. package/dist/designer/assets/smart.export-AxSFVWeW.js +0 -250
  259. package/dist/designer/assets/src--KGN0Gre.js +0 -1
  260. package/dist/designer/assets/src-DfTRqPD7.js +0 -35
  261. package/dist/wc/CardMenu-Bufk2vwa.js +0 -1
  262. package/dist/wc/GridFind-BMXaq4Jr.js +0 -1
  263. package/dist/wc/GridFind-vvGzjjGo.js +0 -1
  264. package/dist/wc/GridFooter-DPREGhF6.js +0 -1
  265. package/dist/wc/GridFooter-DwsjY5ez.js +0 -1
  266. package/dist/wc/GridMenus-BV3fRFIY.js +0 -16
  267. package/dist/wc/GridMenus-VSOeAZFV.js +0 -16
  268. package/dist/wc/SvChartMenu-DJqv1cuY.js +0 -1
  269. package/dist/wc/SvChartMenu-NRen7QjH.js +0 -3
  270. package/dist/wc/SvDateRangeInput-Fw2yWBDs.js +0 -1
  271. package/dist/wc/SvDateRangeInput-v249WzvQ.js +0 -1
  272. package/dist/wc/SvDateTimePicker-B5kJLiH0.js +0 -4
  273. package/dist/wc/SvDateTimePicker-DrUJNzaQ.js +0 -4
  274. package/dist/wc/SvGridCellEditor-BNPMZZF7.js +0 -3
  275. package/dist/wc/SvGridCellEditor-ChV2GkV8.js +0 -3
  276. package/dist/wc/SvGridChart-DKSo4yAM.js +0 -171
  277. package/dist/wc/SvGridChart-D_AKt54D.js +0 -171
  278. package/dist/wc/SvGridChartBuilder-BOSvwoMN.js +0 -8
  279. package/dist/wc/SvGridChartBuilder-DE8Lua1j.js +0 -7
  280. package/dist/wc/SvGridChartPanel-D1Dn-DNm.js +0 -5
  281. package/dist/wc/SvMenuList-QPKlIa2U.js +0 -3
  282. package/dist/wc/SvModal-CT6ZMBaI.js +0 -7
  283. package/dist/wc/SvModal-Cf-6zzOA.js +0 -7
  284. package/dist/wc/SvTabs-pQfMJw-6.js +0 -2
  285. package/dist/wc/board-D39-qF4t.js +0 -23
  286. package/dist/wc/board-view.svelte-BctMVU40.js +0 -1
  287. package/dist/wc/chart-QqgKrWNe.js +0 -1
  288. package/dist/wc/chart-j-Izih1o.js +0 -1
  289. package/dist/wc/chart-panel-messages-Ce4fBC6l.js +0 -1
  290. package/dist/wc/client-BzI-P2yq.js +0 -3
  291. package/dist/wc/client-DA6JtMaz.js +0 -3
  292. package/dist/wc/core-SYwyf5FD.js +0 -1
  293. package/dist/wc/custom-filter-Dp8JxlQu.js +0 -2
  294. package/dist/wc/date-format-DFerRDR7.js +0 -18
  295. package/dist/wc/dismissable-CQ6XFXsk.js +0 -1
  296. package/dist/wc/extent-CcmrrtGQ.js +0 -1
  297. package/dist/wc/gallery-v54gmeKF.js +0 -11
  298. package/dist/wc/gantt-CQ4bjQWL.js +0 -114
  299. package/dist/wc/grid-extension.svelte-CVqh736Q.js +0 -1
  300. package/dist/wc/grid-extension.svelte-DvHfl92l.js +0 -1
  301. package/dist/wc/palette-ChsQ7Bm9.js +0 -46
  302. package/dist/wc/row-drag-DD3TudN_.js +0 -1
  303. package/dist/wc/row-drag-DLQMyiV3.js +0 -1
  304. package/dist/wc/scheduler-GWTte7aX.js +0 -153
  305. package/dist/wc/scheduler-view.svelte-BFCITmR8.js +0 -1
  306. package/dist/wc/smart.export-0xDkly3x.js +0 -250
  307. package/dist/wc/svelte-virtualizer.svelte-DYCT_xZg.js +0 -2
@@ -1 +1 @@
1
- import{fillFieldColumn as q}from"./registry.svelte.js";import Me from"./RatingCell.svelte";import I from"./LinkCell.svelte";import Ce from"./AttachmentCell.svelte";import Pe from"./CheckboxCell.svelte";import J from"./PercentCell.svelte";import L from"./UserCell.svelte";import De from"./ButtonCell.svelte";import Ve from"./BarcodeCell.svelte";import Fe from"./LinkedRecordsCell.svelte";import Ie from"./RichTextCell.svelte";import Le from"./RichHtmlCell.svelte";import{richPlain as P}from"./rich-html.js";import{toRichHtml as Ae}from"./rich-html-write.js";import Q from"./SelectCell.svelte";import Oe from"./ChecklistCell.svelte";import Ne from"./ColorCell.svelte";import{attachmentsText as Re,parseAttachments as Be}from"./attachments.js";import{dateEditTokens as Ee,dateFromParts as A,exactNumber as Ue,formatCurrency as ee,formatDate as O,formatDuration as He,formatNumber as N,formatPercent as te,numberFieldShape as re,numberFromText as _e,numberKind as ze,parseDateText as xe,parseDuration as le,toNumber as R}from"./format.js";import{BRIGHT as ie,CHECKBOX_ICONS as Ge,RATING_ICONS as je}from"./palette.js";import{COMPUTED_TYPES as $e,ROLLUPS as B,fieldNameMap as Ke}from"./rollups.js";import{sparklineValues as E,voteCount as ne,voteIds as We}from"./vote.js";import Ye from"./VoteCell.svelte";import Xe from"./SparklineCell.svelte";import{compileFormula as Ze,isoDate as qe,selfReferenceError as Je}from"./formula.js";import{findFieldUser as oe,getCurrentUser as ae,getFieldUsers as U,getLinkedTable as k,idOf as Qe,linkedRows as H,listLinkedTables as et,liveLink as tt,recordsNaming as rt,resolveLinkId as lt,resolveLinkIds as it}from"./sources.svelte.js";import{splitNames as _}from"./name-list.js";import{linkedFields as nt}from"./linked-fields.js";import{AI_FIELD_TYPE as ot}from"./ai-field.svelte.js";import{CHECKLIST_GROUPS as se,checklistGroup as at,checklistSortValue as st,checklistText as ut,parseChecklist as ct,toChecklist as dt}from"./checklist.js";import{colorSortValue as pt,parseColor as z}from"./color-value.js";import{formatTimeOfDay as ft,parseTimeOfDay as ue,timeSeconds as mt}from"./time-of-day.js";import{bm as l}from"./messages.svelte.js";const gt=new Set(["user","createdBy","lastModifiedBy"]);function ht(e){const t=String(e.field??e.id),r=o=>o.length===1?o[0]:o;if(gt.has(String(e.fieldType)))return o=>{const n=o?.[t];return n==null||n===""?n:r((Array.isArray(n)?n:[n]).map(a=>oe(a)?.name??a))};if(e.fieldType!=="link")return null;const i=e.fieldProps?.table;return o=>{const n=o?.[t],a=k(i);if(!a||n==null||n==="")return n;const f=x(a,a.primaryField),c=new Map(H(a,n).map(d=>[Qe(a,d),f(d)]));return r((Array.isArray(n)?n:[n]).map(d=>c.get(String(d))??d))}}const ce=new WeakMap;let v=0;function x(e,t){const r=n=>n?.[t];if(!e?.fields?.length)return r;let i=ce.get(e.fields);if(i||ce.set(e.fields,i=new Map),!i.has(t)){const n=nt(e).find(a=>a.def.field===t);i.set(t,n?.def.fieldFn??null)}const o=i.get(t);return o?n=>{if(v>3)return r(n);v+=1;try{return o(n)}finally{v-=1}}:r}const s={text:"M4 6h16M4 12h10M4 18h7",longText:"M4 6h16M4 10h16M4 14h16M4 18h10",richText:"M6 4h7a4 4 0 0 1 0 8H6zM6 12h8a4 4 0 0 1 0 8H6zM6 4v16",vote:"M12 19V5M5 12l7-7 7 7",sparkline:"M3 17l5-6 4 4 8-9",number:"M9 4 7 20M17 4l-2 16M4 9h16M3 15h16",currency:"M12 3v18M16 7.5C16 5.6 14.2 4.5 12 4.5S8 5.6 8 7.5s1.8 2.7 4 3.5 4 1.6 4 3.5-1.8 3-4 3-4-1.1-4-3",percent:"M19 5 5 19M7 7h.01M17 17h.01",date:"M4 6h16v14H4zM4 10h16M8 3v4M16 3v4",duration:"M12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16zM12 8v4l3 2",checkbox:"M4 4h16v16H4zM8 12l3 3 5-6",singleSelect:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM8 11l4 4 4-4",multiSelect:"M3 7h11M3 12h11M3 17h11M17 6l2 2 3-3M17 16l2 2 3-3",rating:"M12 3l2.8 5.7 6.2.9-4.5 4.4 1 6.2L12 17.3 6.5 20.2l1-6.2L3 9.6l6.2-.9z",url:"M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1",email:"M3 6h18v12H3zM3 7l9 6 9-6",phone:"M5 4h4l2 5-2.5 1.5a11 11 0 0 0 5 5L15 13l5 2v4a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2",attachment:"M20 11.5 12.3 19a5 5 0 0 1-7.1-7.1l7.8-7.8a3.3 3.3 0 0 1 4.7 4.7L9.9 16.6a1.7 1.7 0 0 1-2.4-2.4l7.1-7",user:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0",createdTime:"M12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16zM12 8v4h4",modifiedTime:"M4 12a8 8 0 1 0 2.3-5.7M4 4v4h4M12 8v4l3 2",createdBy:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 11-7.5M19 15v6M16 18h6",modifiedBy:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 11-7.5M16 21l5-5-2-2-5 5v2z",autoNumber:"M5 7h3v10M11 9a2 2 0 1 1 4 0c0 2-4 3-4 6h4M18 7h2v10",barcode:"M4 5v14M7 5v14M10 5v14M13 5v14M15 5v14M18 5v14M20 5v14",button:"M4 7h16v10H4zM9 12h6",formula:"M7 20c2 0 2.5-2 3-5l2-10c.5-2 1.5-2 3-2M8 9h7",link:"M9 7H6a5 5 0 0 0 0 10h3M15 7h3a5 5 0 0 1 0 10h-3M8 12h8",lookup:"M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM20 20l-4-4M8 11h6",rollup:"M6 4h12L12 12l6 8H6",count:"M5 5h14v14H5zM9 9v6M12 9v6M15 9v6",checklist:"M3.5 6l1.5 1.5L7.5 5M3.5 12l1.5 1.5 2.5-2.5M3.5 18l1.5 1.5 2.5-2.5M11 6h9M11 12h9M11 18h9",color:"M12 3a9 9 0 1 0 0 18c1 0 1.6-.7 1.6-1.6 0-1-.8-1.4-.8-2.3 0-1 .8-1.7 1.8-1.7H17a4 4 0 0 0 4-4C21 6.6 17 3 12 3zM7.5 12h.01M9.5 7.5h.01M14.5 7.5h.01",timeOfDay:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM12 7v5l-3 2M12 3v2M21 12h-2M12 21v-2M3 12h2"},u=(e,t)=>({value:e,get label(){return l(t)}}),de=e=>e?{visible:e}:{},yt={key:"separators",get label(){return l("fields.propSeparators")},kind:"choice",choices:[u("local","fields.choiceLocal"),{value:"comma-period",label:"1,000,000.00"},{value:"period-comma",label:"1.000.000,00"},{value:"space-comma",label:"1 000 000,00"},{value:"space-period",label:"1 000 000.00"}]},bt={key:"showThousands",get label(){return l("fields.propShowThousands")},kind:"checkbox"},kt=e=>({key:"abbreviation",get label(){return l("fields.propAbbreviation")},kind:"choice",choices:[u("none","fields.choiceNone"),u("thousand","fields.choiceThousand"),u("million","fields.choiceMillion"),u("billion","fields.choiceBillion")],...de(e)}),wt={key:"allowNegative",get label(){return l("fields.propAllowNegative")},kind:"checkbox"},b={key:"default",get label(){return l("fields.propDefault")},kind:"default",get hint(){return l("fields.propDefaultHint")}},G=(e,t)=>Array.from({length:t-e+1},(r,i)=>{const o=e+i;return{value:String(o),label:o===0?"1":`1.${"0".repeat(o)}`}}),j=(e,t)=>({key:"precision",get label(){return l("fields.propPrecision")},kind:"choice",choices:e,visible:t}),vt=[u("local","fields.choiceLocal"),u("friendly","fields.choiceFriendly"),u("us","fields.choiceUs"),u("european","fields.choiceEuropean"),u("iso","fields.choiceIso")],D=e=>({key:"dateFormat",get label(){return l("fields.propDateFormat")},kind:"choice",choices:vt,...de(e)}),pe=[u("12hour","fields.choice12Hour"),u("24hour","fields.choice24Hour")],$=[{key:"time",get label(){return l("fields.propIncludeTime")},kind:"checkbox"},{key:"timeFormat",get label(){return l("fields.propTimeFormat")},kind:"segmented",choices:pe,visible:e=>!!e.time},{key:"gmt",get label(){return l("fields.propGmt")},kind:"checkbox",visible:e=>!!e.time},{key:"showTimeZone",get label(){return l("fields.propShowTimeZone")},kind:"checkbox",visible:e=>!!e.time}],St=e=>e.columns.filter(t=>t.fieldType==="link").map(t=>({value:String(t.id??t.field),label:String(t.header??t.field)})),K={key:"linkField",get label(){return l("fields.propLinkField")},kind:"choice",choices:St,get hint(){return l("fields.propLinkFieldHint")}},Tt=e=>{const t=e.columns.find(o=>String(o.id??o.field)===e.props.linkField),r=k(t?.fieldProps?.table);return r?(r.fields??[{field:r.primaryField,header:r.primaryField}]).map(o=>({value:o.field,label:o.header})):[]},fe={key:"field",get label(){return l("fields.propLinkedField")},kind:"choice",choices:Tt,visible:e=>!!e.linkField},V={key:"color",get label(){return l("fields.propColor")},kind:"color",palette:ie},me={key:"options",get label(){return l("fields.propOptions")},kind:"options"},ge=(e,t=0)=>{const r=Number(e.precision);return Number.isInteger(r)&&r>=0&&r<=8?r:t},Mt=e=>({precision:e.format==="integer"?0:ge(e,e.format==="decimal"?1:0),separators:e.separators,showThousands:e.showThousands!==!1,abbreviation:e.abbreviation}),Ct=(e,t)=>r=>{const i=typeof r.rawInput=="string"?r.rawInput:r.newValue;if(typeof i=="number"||i==null)return i;if(String(i).trim()==="")return null;const o=_e(String(i),e,t);return o??r.oldValue},Pt=(e,t)=>t.allowNegative===!1&&!e.validate?{rejectInvalid:!0,validate:r=>Number(r.value)<0?l("fields.negativeNotAllowed"):null}:{},Dt=(e,t)=>{const r={precision:re(e,t).places,separators:t.separators,showThousands:t.showThousands!==!1,abbreviation:e==="percent"?void 0:t.abbreviation};return i=>{const o=Ue(i.value);return o==null?"":e==="currency"?ee(o,{...r,symbol:t.symbol,symbolPosition:t.symbolPosition}):e==="percent"?te(o,{...r,points:t.points}):N(o,r)}},W=(e,t,r)=>({...e,cellDataType:e.cellDataType??"number",editorType:e.editorType??"fieldNumber",align:e.align??(r==="percent"&&t.showBar?"left":"right"),...Pt(e,t),valueParser:e.valueParser??Ct(r,t),formatter:e.formatter??Dt(r,t),sortValue:e.sortValue??R}),T=e=>Array.isArray(e.options)?e.options.map(t=>({value:t.value,label:t.label??String(t.value),...t.color?{color:t.color}:{}})):[],he=(e,t)=>{const r=new Map;for(const n of T(e))r.set(String(n.value).toLowerCase(),n.value),r.set(String(n.label).toLowerCase(),n.value);const i=n=>r.get(n.toLowerCase()),o=r.size===0;return n=>{if(typeof n.rawInput!="string")return n.newValue;const a=t?_(n.rawInput):n.rawInput.split(/\n/).map(c=>c.trim()).filter(Boolean);if(o)return t?[...new Set(a)]:a[0]??null;const f=a.map(i).filter(c=>c!==void 0);return a.length&&!f.length?n.oldValue:t?[...new Set(f)]:a.length?i(a[0])===void 0?n.oldValue:i(a[0]):null}},ye=e=>{const t=new Map(T(e).map(r=>[String(r.value),r.label]));return r=>(Array.isArray(r.value)?r.value:r.value==null||r.value===""?[]:[r.value]).map(i=>t.get(String(i))??String(i)).join(", ")},Vt=e=>{const t=new Map(T(e).map((r,i)=>[String(r.value),i]));return r=>r==null||r===""?null:t.get(String(r))??t.size},be=Ke,m=e=>({editable:e.editable??!1}),Y=e=>t=>O(t.value,e),M=e=>e.oldValue!=null&&typeof e.oldValue!="string"&&String(e.oldValue)===e.newValue?e.oldValue:e.newValue,Ft=e=>t=>{const r=typeof t.rawInput=="string"?t.rawInput:t.newValue;if(r==null||typeof r=="string"&&r.trim()==="")return null;if(r instanceof Date)return e.time?r.toISOString():A({y:r.getFullYear(),mo:r.getMonth()+1,d:r.getDate(),time:null},e);const i=String(r).trim();if(/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2})?/.test(i)){if(!e.time)return i.slice(0,10);if(i.length>10&&i[10]==="T")return i}const o=xe(i,e);return o?A(o,e,t.oldValue):t.oldValue},X=e=>(Array.isArray(e)?e:e==null||e===""?[]:[e]).map(t=>oe(t)?.name??String(t)).join(", "),ke=e=>t=>{if(typeof t.rawInput!="string")return t.newValue;const r=U(),i=a=>{const f=a.toLowerCase();return r.find(d=>d.id.toLowerCase()===f||d.name.toLowerCase()===f||d.email?.toLowerCase()===f)?.id??(r.length?void 0:a)},o=e?_(t.rawInput):t.rawInput.split(/\n/).map(a=>a.trim()).filter(Boolean),n=o.map(i).filter(a=>a!==void 0);return o.length&&!n.length?t.oldValue:e?[...new Set(n)]:o.length?n[0]:null},It=e=>t=>{if(typeof t.rawInput!="string")return t.newValue;const r=k(e.table);if(!r)return t.newValue;const i=_(t.rawInput),o=it(r,i);if(r.records&&r.resolveNames&&t.data&&t.columnId){const n=i.filter(a=>lt(r,a)==null);n.length&&r.resolveNames({row:t.data,columnId:t.columnId,multiple:e.multiple!==!1},n,o)}return i.length&&!o.length?t.oldValue:e.multiple===!1?o.slice(0,1):o},Lt=e=>typeof e.rawInput=="string"?e.rawInput.trim()?ct(e.rawInput):null:Array.isArray(e.newValue)?dt(e.newValue):e.newValue??null,At=e=>t=>{if(typeof t.rawInput!="string")return t.newValue;const r=t.rawInput.trim();if(!r)return null;const i=Number(r);return Number.isInteger(i)&&i>=0&&i<=Number(e.max??5)?i:t.oldValue},Ot=e=>{const t=typeof e.rawInput=="string"?e.rawInput:e.newValue;return t==null||String(t).trim()===""?null:z(t)??e.oldValue},Nt=e=>t=>{const r=typeof t.rawInput=="string"?t.rawInput:t.newValue;return r==null||typeof r=="string"&&r.trim()===""?null:ue(r,{seconds:!!e.showSeconds})??t.oldValue};function we(e,t){if(e==null)return"";if(Array.isArray(e))return e.map(r=>we(r,t)).join(", ");if(e instanceof Date)return O(e,t);if(typeof e=="boolean")return e?"true":"false";if(typeof e=="number"){if(t.result==="currency"||t.result==="percent"||t.result==="number"){const r=t.result,i={...Mt(t),precision:re(r,{precision:t.precision}).places};return r==="currency"?ee(e,{...i,symbol:t.symbol}):r==="percent"?te(e,i):N(e,i)}return String(Math.round(e*1e10)/1e10)}if(t.result==="date"){const r=qe(String(e));if(r)return O(r,t)}return String(e)}const Z=(e,t)=>{const r=t.columns.find(n=>String(n.id??n.field)===e.linkField);if(!r)return null;const i=r.fieldProps?.table,o=r.fieldProps?.inverse;return{key:String(r.field??r.id),get table(){return k(i)},rowsOf(n){const a=k(i),f=String(r.field??r.id);return a&&o&&!a.records&&n?.[f]===void 0?rt(a,o,String(n?.id??"")):H(a,n?.[f])},get stored(){const n=k(i)?.records;return n&&o&&n.stores(o)?{records:n,field:o}:null}}},Rt={SUM:"sum",AVERAGE:"avg",MIN:"min",MAX:"max",COUNT:"count"},ve=new WeakMap;function Se(e,t,r){const i=e?.table?.fields;if(!i)return;let o=ve.get(i);o||ve.set(i,o=new Map);const n=`${String(t)}|${r??""}`;if(o.has(n))return o.get(n);const a=i.find(c=>c.field===String(t)),f=a?.fieldType?q({field:a.field,fieldType:a.fieldType,fieldProps:{...a.fieldProps,...r==null?{}:{precision:r}}}).formatter:void 0;return o.set(n,f),f}const F=()=>new Date().toISOString(),Bt=new Intl.Collator(void 0,{sensitivity:"base",numeric:!0}),Et=(e,t)=>{const r=i=>i?se.indexOf(i):se.length;return r(e)-r(t)},Te=[{key:"watch",get label(){return l("fields.propWatch")},kind:"segmented",choices:[u("all","fields.choiceAllFields"),u("specific","fields.choiceSpecificFields")]},{key:"watchFields",get label(){return l("fields.propWatchFields")},kind:"columns",visible:e=>e.watch==="specific"}];export const BUILTIN_FIELD_TYPES=[{id:"text",get label(){return l("fields.typeText")},get description(){return l("fields.typeTextDescription")},icon:s.text,group:"basic",properties:[b],fill:e=>({...e,editorType:e.editorType??"text",valueParser:e.valueParser??M})},{id:"longText",get label(){return l("fields.typeLongText")},get description(){return l("fields.typeLongTextDescription")},icon:s.longText,group:"basic",width:260,properties:[{key:"richText",get label(){return l("fields.propMarkdown")},kind:"checkbox",get hint(){return l("fields.propMarkdownHint")}}],fill:e=>({...e,editorType:e.editorType??"fieldLongText",valueParser:e.valueParser??M}),cell:Ie,hasCell:e=>!!e.richText},{id:"richText",get label(){return l("fields.typeRichText")},get description(){return l("fields.typeRichTextDescription")},icon:s.richText,group:"basic",width:280,defaults:{toolbar:"standard"},properties:[{key:"toolbar",get label(){return l("fields.propToolbar")},kind:"segmented",choices:[u("standard","fields.choiceStandard"),u("full","fields.choiceFull")],get hint(){return l("fields.propToolbarHint")}}],fill:e=>({...e,editorType:e.editorType??"fieldRichText",formatter:e.formatter??(t=>P(t.value)),sortComparator:e.sortComparator??((t,r)=>Bt.compare(P(t),P(r))),valueParser:e.valueParser??(t=>Ae(t.newValue))}),cell:Le},{id:"attachment",get label(){return l("fields.typeAttachment")},get description(){return l("fields.typeAttachmentDescription")},icon:s.attachment,group:"basic",width:180,defaults:{maxFiles:20},properties:[{key:"accept",get label(){return l("fields.propAccept")},kind:"text",get placeholder(){return l("fields.propAcceptPlaceholder")}},{key:"maxFiles",get label(){return l("fields.propMaxFiles")},kind:"number",min:1,max:100}],fill:(e,t)=>({...e,editorType:e.editorType??"attachment",formatter:e.formatter??(r=>Re(r.value)),valueParser:e.valueParser??(r=>Be(r.newValue,t))}),cell:Ce},{id:"checkbox",get label(){return l("fields.typeCheckbox")},get description(){return l("fields.typeCheckboxDescription")},icon:s.checkbox,group:"basic",width:90,defaults:{icon:"check",color:"#20c933"},properties:[{key:"icon",get label(){return l("fields.propIcon")},kind:"icon",icons:Ge},V,b],fill:e=>({...e,editorType:e.editorType??"checkbox",align:e.align??"center",toggleOnSecondClick:e.toggleOnSecondClick??!0}),cell:Pe},{id:"singleSelect",get label(){return l("fields.typeSingleSelect")},get description(){return l("fields.typeSingleSelectDescription")},icon:s.singleSelect,group:"basic",width:140,defaults:{options:[]},properties:[me,b],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",editorOptions:e.editorOptions??T(t),formatter:e.formatter??ye(t),valueParser:e.valueParser??he(t,!1),sortValue:e.sortValue??Vt(t)}),cell:Q},{id:"multiSelect",get label(){return l("fields.typeMultiSelect")},get description(){return l("fields.typeMultiSelectDescription")},icon:s.multiSelect,group:"basic",width:200,defaults:{options:[]},properties:[me,b],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",editorMultiple:e.editorMultiple??!0,editorOptions:e.editorOptions??T(t),formatter:e.formatter??ye(t),valueParser:e.valueParser??he(t,!0)}),cell:Q},{id:"user",get label(){return l("fields.typeUser")},get description(){return l("fields.typeUserDescription")},icon:s.user,group:"basic",width:170,properties:[{key:"multiple",get label(){return l("fields.propMultipleUsers")},kind:"checkbox"},b],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",valueParser:e.valueParser??ke(!!t.multiple),editorMultiple:e.editorMultiple??!!t.multiple,editorOptions:e.editorOptions??U().map(r=>({value:r.id,label:r.name})),formatter:e.formatter??(r=>X(r.value))}),cell:L},{id:"date",get label(){return l("fields.typeDate")},get description(){return l("fields.typeDateDescription")},icon:s.date,group:"basic",width:150,defaults:{dateFormat:"local",timeFormat:"12hour"},properties:[D(),...$,{key:"defaultToday",get label(){return l("fields.propDefaultToday")},kind:"checkbox"}],fill:(e,t)=>({...e,cellDataType:e.cellDataType??(t.time?"date":"dateString"),editorType:e.editorType??"fieldDate",editorFormatString:e.editorFormatString??Ee(t),formatter:e.formatter??Y(t),valueParser:e.valueParser??Ft(t)}),newRowValue:({props:e})=>{if(!e.defaultToday)return;if(e.time)return F();const t=new Date;return A({y:t.getFullYear(),mo:t.getMonth()+1,d:t.getDate(),time:null},{})}},{id:"phone",get label(){return l("fields.typePhone")},get description(){return l("fields.typePhoneDescription")},icon:s.phone,group:"basic",fill:e=>({...e,editorType:e.editorType??"text",valueParser:e.valueParser??M}),cell:I},{id:"email",get label(){return l("fields.typeEmail")},get description(){return l("fields.typeEmailDescription")},icon:s.email,group:"basic",width:200,fill:e=>({...e,editorType:e.editorType??"text",valueParser:e.valueParser??M}),cell:I},{id:"url",get label(){return l("fields.typeUrl")},get description(){return l("fields.typeUrlDescription")},icon:s.url,group:"basic",width:200,fill:e=>({...e,editorType:e.editorType??"text",valueParser:e.valueParser??M}),cell:I},{id:"barcode",get label(){return l("fields.typeBarcode")},get description(){return l("fields.typeBarcodeDescription")},icon:s.barcode,group:"basic",width:160,fill:e=>({...e,editorType:e.editorType??"text",formatter:e.formatter??(t=>t.value&&typeof t.value=="object"?String(t.value.text??""):String(t.value??""))}),cell:Ve},{id:"button",get label(){return l("fields.typeButton")},get description(){return l("fields.typeButtonDescription")},icon:s.button,group:"basic",width:120,defaults:{label:"Open",color:"#2d7ff9"},properties:[{key:"label",get label(){return l("fields.propButtonLabel")},kind:"text",get placeholder(){return l("fields.propButtonLabelPlaceholder")}},{key:"color",get label(){return l("fields.propButtonStyle")},kind:"color",palette:ie},{key:"url",get label(){return l("fields.propButtonUrl")},kind:"text",get placeholder(){return l("fields.propButtonUrlPlaceholder")},get hint(){return l("fields.propButtonUrlHint")}}],fill:(e,t,r)=>({...e,...m(e),sortable:e.sortable??!1,__fieldNames:be(r.columns)}),cell:De},{id:"checklist",get label(){return l("fields.typeChecklist")},get description(){return l("fields.typeChecklistDescription")},icon:s.checklist,group:"basic",width:150,fill:e=>({...e,editorType:e.editorType??"fieldChecklist",formatter:e.formatter??(t=>ut(t.value)),valueParser:e.valueParser??Lt,sortValue:e.sortValue??st,groupValue:e.groupValue??at,groupOrder:e.groupOrder??Et}),cell:Oe},{id:"color",get label(){return l("fields.typeColor")},get description(){return l("fields.typeColorDescription")},icon:s.color,group:"basic",width:130,properties:[b],fill:e=>({...e,editorType:e.editorType??"fieldColor",formatter:e.formatter??(t=>z(t.value)??String(t.value??"")),valueParser:e.valueParser??Ot,sortValue:e.sortValue??pt}),newRowValue:({props:e})=>e.default==null||e.default===""?void 0:z(e.default),cell:Ne},{id:"number",get label(){return l("fields.typeNumber")},get description(){return l("fields.typeNumberDescription")},icon:s.number,group:"number",width:120,defaults:{format:"decimal",precision:1,separators:"local",showThousands:!0,abbreviation:"none",allowNegative:!0,symbol:"$",symbolPosition:"before",showBar:!1,points:!1,step:1},properties:[{key:"format",get label(){return l("fields.propFormat")},kind:"segmented",choices:[u("integer","fields.choiceInteger"),u("decimal","fields.choiceDecimal"),u("currency","fields.choiceCurrency"),u("percent","fields.choicePercent")],alsoSets:e=>({precision:e==="decimal"?1:e==="currency"?2:0})},{key:"symbol",get label(){return l("fields.propCurrencySymbol")},kind:"text",placeholder:"$, €, £, ¥, CHF, kr",visible:e=>e.format==="currency"},{key:"symbolPosition",get label(){return l("fields.propSymbolPosition")},kind:"segmented",visible:e=>e.format==="currency",choices:[u("before","fields.choiceBefore"),u("after","fields.choiceAfter")]},j(G(0,8),e=>e.format!=="integer"),{key:"step",get label(){return l("fields.propStep")},kind:"number",min:0,get hint(){return l("fields.propStepHint")}},yt,bt,kt(e=>e.format!=="percent"),wt,{key:"showBar",get label(){return l("fields.propShowBar")},kind:"checkbox",visible:e=>e.format==="percent"},{key:"points",get label(){return l("fields.propPoints")},kind:"checkbox",visible:e=>e.format==="percent"},b],fill:(e,t)=>W(e,t,ze("number",t)),cell:J,hasCell:e=>e.format==="percent"&&!!e.showBar},{id:"currency",get label(){return l("fields.typeCurrency")},get description(){return l("fields.typeCurrencyDescription")},icon:s.currency,group:"number",width:120,defaults:{symbol:"$",symbolPosition:"before",precision:2,separators:"local",showThousands:!0,abbreviation:"none",allowNegative:!0},editAs:{type:"number",props:{format:"currency"}},fill:(e,t)=>W(e,t,"currency")},{id:"percent",get label(){return l("fields.typePercent")},get description(){return l("fields.typePercentDescription")},icon:s.percent,group:"number",width:110,defaults:{precision:0,separators:"local",showThousands:!0,allowNegative:!0,points:!1},editAs:{type:"number",props:{format:"percent"}},fill:(e,t)=>W(e,t,"percent"),cell:J,hasCell:e=>!!e.showBar},{id:"duration",get label(){return l("fields.typeDuration")},get description(){return l("fields.typeDurationDescription")},icon:s.duration,group:"number",width:110,defaults:{durationFormat:"h:mm"},properties:[{key:"durationFormat",get label(){return l("fields.propDurationFormat")},kind:"choice",choices:[{value:"h:mm",label:"h:mm"},{value:"h:mm:ss",label:"h:mm:ss"},{value:"h:mm:ss.S",label:"h:mm:ss.S"},{value:"h:mm:ss.SS",label:"h:mm:ss.SS"},{value:"h:mm:ss.SSS",label:"h:mm:ss.SSS"}]}],fill:(e,t)=>({...e,cellDataType:e.cellDataType??"number",editorType:e.editorType??"fieldNumber",formatter:e.formatter??(r=>{const i=R(r.value);return i==null?"":He(i,t.durationFormat)}),valueParser:e.valueParser??(r=>typeof r.rawInput=="string"?r.rawInput.trim()?le(r.rawInput)??r.oldValue:null:typeof r.newValue=="number"?r.newValue:le(r.newValue))})},{id:"timeOfDay",get label(){return l("fields.typeTimeOfDay")},get description(){return l("fields.typeTimeOfDayDescription")},icon:s.timeOfDay,group:"number",width:120,defaults:{timeFormat:"12hour",showSeconds:!1},properties:[{key:"timeFormat",get label(){return l("fields.propTimeFormat")},kind:"segmented",choices:pe},{key:"showSeconds",get label(){return l("fields.propShowSeconds")},kind:"checkbox"},b],fill:(e,t)=>({...e,editorType:e.editorType??"fieldTime",formatter:e.formatter??(r=>ft(r.value,t)),valueParser:e.valueParser??Nt(t),sortValue:e.sortValue??mt}),newRowValue:({props:e})=>e.default==null||e.default===""?void 0:ue(e.default,{seconds:!!e.showSeconds})},{id:"rating",get label(){return l("fields.typeRating")},get description(){return l("fields.typeRatingDescription")},icon:s.rating,group:"number",width:130,defaults:{max:5,icon:"star",color:"#fcb400"},properties:[{key:"icon",get label(){return l("fields.propIcon")},kind:"icon",icons:je},V,{key:"max",get label(){return l("fields.propMaximum")},kind:"choice",choices:Array.from({length:10},(e,t)=>({value:String(t+1),label:String(t+1)}))}],fill:(e,t)=>({...e,cellDataType:e.cellDataType??"number",align:e.align??"left",editorType:e.editorType??"fieldRating",valueParser:e.valueParser??At(t)}),cell:Me},{id:"vote",get label(){return l("fields.typeVote")},get description(){return l("fields.typeVoteDescription")},icon:s.vote,group:"basic",width:100,defaults:{icon:"up"},properties:[{key:"icon",get label(){return l("fields.propIcon")},kind:"segmented",choices:[u("up","fields.choiceArrow"),u("thumb","fields.choiceThumb"),u("heart","fields.choiceHeart")]},V],fill:e=>({...e,editorType:e.editorType??"fieldVote",editorOptions:e.editorOptions??U().map(t=>({value:t.id,label:t.name})),align:e.align??"left",sortValue:e.sortValue??(t=>ne(t)),formatter:e.formatter??(t=>String(ne(t.value))),valueParser:e.valueParser??(t=>We(ke(!0)(t)))}),newRowValue:()=>[],cell:Ye},{id:"sparkline",get label(){return l("fields.typeSparkline")},get description(){return l("fields.typeSparklineDescription")},icon:s.sparkline,group:"number",width:160,defaults:{chart:"line"},properties:[{key:"chart",get label(){return l("fields.propChart")},kind:"segmented",choices:[u("line","fields.choiceLine"),u("area","fields.choiceArea"),u("bar","fields.choiceColumns")]},V,{key:"showLast",get label(){return l("fields.propShowLast")},kind:"checkbox"}],fill:e=>({...e,formatter:e.formatter??(t=>E(t.value).join(", ")),valueParser:e.valueParser??(t=>{const r=E(t.newValue);return r.length?r:null}),sortValue:e.sortValue??(t=>E(t).at(-1)??null)}),cell:Xe},{id:"formula",get label(){return l("fields.typeFormula")},get description(){return l("fields.typeFormulaDescription")},icon:s.formula,group:"computed",width:160,defaults:{formula:"",result:"auto"},properties:[{key:"formula",get label(){return l("fields.propFormula")},kind:"formula"},{key:"result",get label(){return l("fields.propResult")},kind:"choice",choices:[u("auto","fields.choiceAsComputed"),u("number","fields.choiceNumber"),u("currency","fields.choiceCurrency"),u("percent","fields.choicePercent"),u("date","fields.choiceDate")]},j(G(0,8),e=>["number","currency","percent"].includes(e.result)),{key:"symbol",get label(){return l("fields.propCurrencySymbol")},kind:"text",placeholder:"$",visible:e=>e.result==="currency"},D(e=>e.result==="date")],fill:(e,t,r)=>{const i=be(r.columns),o=String(t.formula??""),n=String(e.field??e.id),a=new Set([n.toLowerCase(),typeof e.header=="string"?e.header.trim().toLowerCase():""].filter(Boolean)),f=p=>{const y=p.trim().toLowerCase(),h=i[y]??null;if(h===n||h==null&&a.has(y))throw Je(p);return h};let c=null;try{c=o.trim()?Ze(o,f).fn:()=>null}catch{c=null}let d=null;const g=()=>{if(d)return d;d=new Map;for(const p of r.columns){if(p.fieldType==="richText"){const w=String(p.field??p.id);d.set(w,C=>P(C?.[w]));continue}const y=ht(p);if(y){d.set(String(p.field??p.id),y);continue}if(!$e.has(String(p.fieldType))||String(p.field??p.id)===n)continue;const h=q(p,r.columns);typeof h.fieldFn=="function"&&d.set(String(p.field??p.id),h.fieldFn)}return d},S=p=>{const y=g();return!y.size||!p?p:new Proxy(p,{get:(h,w)=>{const C=typeof w=="string"?y.get(w):void 0;if(!C||v>3)return h[w];v+=1;try{return C(h)}finally{v-=1}}})};return{...e,...m(e),fieldFn:p=>c?c(S(p)):"#ERROR",align:e.align??(["number","currency","percent"].includes(t.result)?"right":void 0),formatter:e.formatter??(p=>we(p.value,t))}}},{id:"createdTime",get label(){return l("fields.typeCreatedTime")},get description(){return l("fields.typeCreatedTimeDescription")},icon:s.createdTime,group:"computed",width:170,defaults:{dateFormat:"local",time:!0,timeFormat:"12hour"},properties:[D(),...$],fill:(e,t)=>({...e,...m(e),formatter:e.formatter??Y(t)}),newRowValue:()=>F(),onCreate:({rows:e})=>e.map(()=>F())},{id:"lastModifiedTime",get label(){return l("fields.typeLastModifiedTime")},get description(){return l("fields.typeLastModifiedTimeDescription")},icon:s.modifiedTime,group:"computed",width:170,defaults:{dateFormat:"local",time:!0,timeFormat:"12hour",watch:"all"},properties:[...Te,D(),...$],fill:(e,t)=>({...e,...m(e),formatter:e.formatter??Y(t)}),newRowValue:()=>F()},{id:"createdBy",get label(){return l("fields.typeCreatedBy")},get description(){return l("fields.typeCreatedByDescription")},icon:s.createdBy,group:"computed",width:160,fill:e=>({...e,...m(e),formatter:e.formatter??(t=>X(t.value))}),newRowValue:()=>ae()?.id??null,cell:L},{id:"lastModifiedBy",get label(){return l("fields.typeLastModifiedBy")},get description(){return l("fields.typeLastModifiedByDescription")},icon:s.modifiedBy,group:"computed",width:160,defaults:{watch:"all"},properties:Te,fill:e=>({...e,...m(e),formatter:e.formatter??(t=>X(t.value))}),newRowValue:()=>ae()?.id??null,cell:L},{id:"autoNumber",get label(){return l("fields.typeAutoNumber")},get description(){return l("fields.typeAutoNumberDescription")},icon:s.autoNumber,group:"computed",width:100,fill:e=>({...e,...m(e),cellDataType:e.cellDataType??"number"}),newRowValue:({rows:e,field:t})=>e.reduce((r,i)=>Math.max(r,Number(i?.[t])||0),0)+1,onCreate:({rows:e})=>e.map((t,r)=>r+1)},{id:"link",get label(){return l("fields.typeLink")},get description(){return l("fields.typeLinkDescription")},icon:s.link,group:"relation",width:200,defaults:{multiple:!0},properties:[{key:"table",get label(){return l("fields.propTable")},kind:"choice",choices:()=>et().map(e=>({value:e.id,label:e.name})),get hint(){return l("fields.propTableHint")}},{key:"multiple",get label(){return l("fields.propMultipleRecords")},kind:"checkbox"}],fill:(e,t)=>({...e,editorType:e.editorType??"fieldLink",formatter:e.formatter??(r=>{const i=k(t.table);return H(i,r.value).map(o=>String(o[i.primaryField]??"")).join(", ")}),valueParser:e.valueParser??It(t),groupValue:e.groupValue??(r=>tt(t.table,r)),groupCopies:!0}),cell:Fe},{id:"lookup",get label(){return l("fields.typeLookup")},get description(){return l("fields.typeLookupDescription")},icon:s.lookup,group:"relation",width:180,properties:[K,fe],fill:(e,t,r)=>{const i=Z(t,r),o=n=>{const a=Se(i,t.field);return String(a?a({value:n})??"":n)};return{...e,...m(e),fieldSource:()=>i?.table?.fields?.find(n=>n.field===String(t.field)),fieldFn:n=>{if(!i)return[];const a=x(i.table,String(t.field)),f=i.stored;return f?f.records.allLinkedTo(f.field,String(n?.id??"")).map(a):i.rowsOf(n).map(a)},formatter:e.formatter??(n=>Array.isArray(n.value)?n.value.filter(a=>a!=null&&a!=="").map(o).join(", "):n.value==null?"":o(n.value))}}},{id:"rollup",get label(){return l("fields.typeRollup")},get description(){return l("fields.typeRollupDescription")},icon:s.rollup,group:"relation",width:140,defaults:{aggregation:"SUM"},properties:[K,fe,{key:"aggregation",get label(){return l("fields.propAggregation")},kind:"choice",choices:Object.keys(B).map(e=>({value:e,label:e}))},j(G(0,8),e=>["SUM","AVERAGE","MIN","MAX"].includes(e.aggregation))],fill:(e,t,r)=>{const i=Z(t,r),o=B[String(t.aggregation)]??B.SUM,n=["SUM","AVERAGE","MIN","MAX","COUNT","COUNTA","COUNTALL"].includes(String(t.aggregation)),a=["SUM","AVERAGE","MIN","MAX"].includes(String(t.aggregation)),f=c=>{const d=a?Se(i,t.field,t.precision):void 0;return d?String(d({value:c})??""):N(c,{precision:ge(t,0)})};return{...e,...m(e),...n?{cellDataType:e.cellDataType??"number"}:{},align:e.align??(n?"right":void 0),fieldSource:()=>i?.table?.fields?.find(c=>c.field===String(t.field)),fieldFn:c=>{if(!i)return null;const d=x(i.table,String(t.field)),g=i.stored;if(g){const S=String(c?.id??""),p=Rt[String(t.aggregation)];return p?g.records.total(g.field,S,String(t.field),p)??null:t.aggregation==="COUNTA"||t.aggregation==="COUNTALL"?g.records.total(g.field,S)??null:o(g.records.allLinkedTo(g.field,S).map(d))}return o(i.rowsOf(c).map(d))},formatter:e.formatter??(c=>{const d=n?R(c.value):typeof c.value=="number"?c.value:null;return d==null?String(c.value??""):f(d)})}}},{id:"count",get label(){return l("fields.typeCount")},get description(){return l("fields.typeCountDescription")},icon:s.count,group:"relation",width:90,properties:[K],fill:(e,t,r)=>{const i=Z(t,r);return{...e,...m(e),cellDataType:e.cellDataType??"number",formatter:o=>o.value==null?"":Number(o.value).toLocaleString(),fieldFn:o=>{if(!i)return 0;const n=i.stored;return n?n.records.total(n.field,String(o?.id??""))??null:i.rowsOf(o).length}}}},ot];
1
+ import{fillFieldColumn as Q}from"./registry.svelte.js";import Pe from"./RatingCell.svelte";import A from"./LinkCell.svelte";import De from"./AttachmentCell.svelte";import Ve from"./CheckboxCell.svelte";import ee from"./PercentCell.svelte";import O from"./UserCell.svelte";import Fe from"./ButtonCell.svelte";import Ie from"./BarcodeCell.svelte";import Le from"./LinkedRecordsCell.svelte";import Ae from"./RichTextCell.svelte";import Oe from"./RichHtmlCell.svelte";import{richPlain as D}from"./rich-html.js";import{toRichHtml as Ne}from"./rich-html-write.js";import te from"./SelectCell.svelte";import Re from"./ChecklistCell.svelte";import Be from"./ColorCell.svelte";import{attachmentsText as Ee,parseAttachments as Ue}from"./attachments.js";import{dateEditTokens as He,dateFromParts as N,exactNumber as _e,formatCurrency as re,formatDate as R,formatDuration as le,formatNumber as B,formatPercent as ie,numberFieldShape as ne,numberFromText as ze,numberKind as Ge,parseDateText as je,parseDuration as V,toNumber as E}from"./format.js";import{BRIGHT as oe,CHECKBOX_ICONS as $e,RATING_ICONS as Ke}from"./palette.js";import{COMPUTED_TYPES as We,ROLLUPS as U,fieldNameMap as Ye}from"./rollups.js";import{sparklineValues as H,voteCount as ae,voteIds as Xe}from"./vote.js";import xe from"./VoteCell.svelte";import Ze from"./TimerCell.svelte";import{timerSeconds as F,timerTotal as qe}from"./timer.js";import Je from"./SparklineCell.svelte";import{compileFormula as Qe,isoDate as et,selfReferenceError as tt}from"./formula.js";import{findFieldUser as se,getCurrentUser as ue,getFieldUsers as _,getLinkedTable as k,idOf as rt,linkedRows as z,listLinkedTables as lt,liveLink as it,recordsNaming as nt,resolveLinkId as ot,resolveLinkIds as at}from"./sources.svelte.js";import{splitNames as G}from"./name-list.js";import{linkedFields as st}from"./linked-fields.js";import{AI_FIELD_TYPE as ut}from"./ai-field.svelte.js";import{CHECKLIST_GROUPS as ce,checklistGroup as ct,checklistSortValue as dt,checklistText as pt,parseChecklist as ft,toChecklist as mt}from"./checklist.js";import{colorSortValue as gt,parseColor as j}from"./color-value.js";import{formatTimeOfDay as ht,parseTimeOfDay as de,timeSeconds as yt}from"./time-of-day.js";import{bm as l}from"./messages.svelte.js";const bt=new Set(["user","createdBy","lastModifiedBy"]);function kt(e){const t=String(e.field??e.id),r=o=>o.length===1?o[0]:o;if(bt.has(String(e.fieldType)))return o=>{const n=o?.[t];return n==null||n===""?n:r((Array.isArray(n)?n:[n]).map(a=>se(a)?.name??a))};if(e.fieldType!=="link")return null;const i=e.fieldProps?.table;return o=>{const n=o?.[t],a=k(i);if(!a||n==null||n==="")return n;const p=$(a,a.primaryField),f=new Map(z(a,n).map(d=>[rt(a,d),p(d)]));return r((Array.isArray(n)?n:[n]).map(d=>f.get(String(d))??d))}}const pe=new WeakMap;let v=0;function $(e,t){const r=n=>n?.[t];if(!e?.fields?.length)return r;let i=pe.get(e.fields);if(i||pe.set(e.fields,i=new Map),!i.has(t)){const n=st(e).find(p=>p.def.field===t),a=n?.def.fieldType==="timer"?p=>F(p?.[t]):null;i.set(t,a??n?.def.fieldFn??null)}const o=i.get(t);return o?n=>{if(v>3)return r(n);v+=1;try{return o(n)}finally{v-=1}}:r}const s={text:"M4 6h16M4 12h10M4 18h7",longText:"M4 6h16M4 10h16M4 14h16M4 18h10",richText:"M6 4h7a4 4 0 0 1 0 8H6zM6 12h8a4 4 0 0 1 0 8H6zM6 4v16",vote:"M12 19V5M5 12l7-7 7 7",sparkline:"M3 17l5-6 4 4 8-9",number:"M9 4 7 20M17 4l-2 16M4 9h16M3 15h16",currency:"M12 3v18M16 7.5C16 5.6 14.2 4.5 12 4.5S8 5.6 8 7.5s1.8 2.7 4 3.5 4 1.6 4 3.5-1.8 3-4 3-4-1.1-4-3",percent:"M19 5 5 19M7 7h.01M17 17h.01",date:"M4 6h16v14H4zM4 10h16M8 3v4M16 3v4",duration:"M12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16zM12 8v4l3 2",timer:"M12 7a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM12 10v4l2.5 1.5M9.5 2.5h5M12 2.5V5",checkbox:"M4 4h16v16H4zM8 12l3 3 5-6",singleSelect:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM8 11l4 4 4-4",multiSelect:"M3 7h11M3 12h11M3 17h11M17 6l2 2 3-3M17 16l2 2 3-3",rating:"M12 3l2.8 5.7 6.2.9-4.5 4.4 1 6.2L12 17.3 6.5 20.2l1-6.2L3 9.6l6.2-.9z",url:"M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1",email:"M3 6h18v12H3zM3 7l9 6 9-6",phone:"M5 4h4l2 5-2.5 1.5a11 11 0 0 0 5 5L15 13l5 2v4a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2",attachment:"M20 11.5 12.3 19a5 5 0 0 1-7.1-7.1l7.8-7.8a3.3 3.3 0 0 1 4.7 4.7L9.9 16.6a1.7 1.7 0 0 1-2.4-2.4l7.1-7",user:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0",createdTime:"M12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16zM12 8v4h4",modifiedTime:"M4 12a8 8 0 1 0 2.3-5.7M4 4v4h4M12 8v4l3 2",createdBy:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 11-7.5M19 15v6M16 18h6",modifiedBy:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 11-7.5M16 21l5-5-2-2-5 5v2z",autoNumber:"M5 7h3v10M11 9a2 2 0 1 1 4 0c0 2-4 3-4 6h4M18 7h2v10",barcode:"M4 5v14M7 5v14M10 5v14M13 5v14M15 5v14M18 5v14M20 5v14",button:"M4 7h16v10H4zM9 12h6",formula:"M7 20c2 0 2.5-2 3-5l2-10c.5-2 1.5-2 3-2M8 9h7",link:"M9 7H6a5 5 0 0 0 0 10h3M15 7h3a5 5 0 0 1 0 10h-3M8 12h8",lookup:"M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM20 20l-4-4M8 11h6",rollup:"M6 4h12L12 12l6 8H6",count:"M5 5h14v14H5zM9 9v6M12 9v6M15 9v6",checklist:"M3.5 6l1.5 1.5L7.5 5M3.5 12l1.5 1.5 2.5-2.5M3.5 18l1.5 1.5 2.5-2.5M11 6h9M11 12h9M11 18h9",color:"M12 3a9 9 0 1 0 0 18c1 0 1.6-.7 1.6-1.6 0-1-.8-1.4-.8-2.3 0-1 .8-1.7 1.8-1.7H17a4 4 0 0 0 4-4C21 6.6 17 3 12 3zM7.5 12h.01M9.5 7.5h.01M14.5 7.5h.01",timeOfDay:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM12 7v5l-3 2M12 3v2M21 12h-2M12 21v-2M3 12h2"},u=(e,t)=>({value:e,get label(){return l(t)}}),fe=e=>e?{visible:e}:{},wt={key:"separators",get label(){return l("fields.propSeparators")},kind:"choice",choices:[u("local","fields.choiceLocal"),{value:"comma-period",label:"1,000,000.00"},{value:"period-comma",label:"1.000.000,00"},{value:"space-comma",label:"1 000 000,00"},{value:"space-period",label:"1 000 000.00"}]},Tt={key:"showThousands",get label(){return l("fields.propShowThousands")},kind:"checkbox"},vt=e=>({key:"abbreviation",get label(){return l("fields.propAbbreviation")},kind:"choice",choices:[u("none","fields.choiceNone"),u("thousand","fields.choiceThousand"),u("million","fields.choiceMillion"),u("billion","fields.choiceBillion")],...fe(e)}),St={key:"allowNegative",get label(){return l("fields.propAllowNegative")},kind:"checkbox"},w={key:"default",get label(){return l("fields.propDefault")},kind:"default",get hint(){return l("fields.propDefaultHint")}},K=(e,t)=>Array.from({length:t-e+1},(r,i)=>{const o=e+i;return{value:String(o),label:o===0?"1":`1.${"0".repeat(o)}`}}),W=(e,t)=>({key:"precision",get label(){return l("fields.propPrecision")},kind:"choice",choices:e,visible:t}),Mt=[u("local","fields.choiceLocal"),u("friendly","fields.choiceFriendly"),u("us","fields.choiceUs"),u("european","fields.choiceEuropean"),u("iso","fields.choiceIso")],I=e=>({key:"dateFormat",get label(){return l("fields.propDateFormat")},kind:"choice",choices:Mt,...fe(e)}),me=[u("12hour","fields.choice12Hour"),u("24hour","fields.choice24Hour")],Y=[{key:"time",get label(){return l("fields.propIncludeTime")},kind:"checkbox"},{key:"timeFormat",get label(){return l("fields.propTimeFormat")},kind:"segmented",choices:me,visible:e=>!!e.time},{key:"gmt",get label(){return l("fields.propGmt")},kind:"checkbox",visible:e=>!!e.time},{key:"showTimeZone",get label(){return l("fields.propShowTimeZone")},kind:"checkbox",visible:e=>!!e.time}],Ct=e=>e.columns.filter(t=>t.fieldType==="link").map(t=>({value:String(t.id??t.field),label:String(t.header??t.field)})),X={key:"linkField",get label(){return l("fields.propLinkField")},kind:"choice",choices:Ct,get hint(){return l("fields.propLinkFieldHint")}},Pt=e=>{const t=e.columns.find(o=>String(o.id??o.field)===e.props.linkField),r=k(t?.fieldProps?.table);return r?(r.fields??[{field:r.primaryField,header:r.primaryField}]).map(o=>({value:o.field,label:o.header})):[]},ge={key:"field",get label(){return l("fields.propLinkedField")},kind:"choice",choices:Pt,visible:e=>!!e.linkField},M={key:"color",get label(){return l("fields.propColor")},kind:"color",palette:oe},he={key:"options",get label(){return l("fields.propOptions")},kind:"options"},ye=(e,t=0)=>{const r=Number(e.precision);return Number.isInteger(r)&&r>=0&&r<=8?r:t},Dt=e=>({precision:e.format==="integer"?0:ye(e,e.format==="decimal"?1:0),separators:e.separators,showThousands:e.showThousands!==!1,abbreviation:e.abbreviation}),Vt=(e,t)=>r=>{const i=typeof r.rawInput=="string"?r.rawInput:r.newValue;if(typeof i=="number"||i==null)return i;if(String(i).trim()==="")return null;const o=ze(String(i),e,t);return o??r.oldValue},Ft=(e,t)=>t.allowNegative===!1&&!e.validate?{rejectInvalid:!0,validate:r=>Number(r.value)<0?l("fields.negativeNotAllowed"):null}:{},It=(e,t)=>{const r={precision:ne(e,t).places,separators:t.separators,showThousands:t.showThousands!==!1,abbreviation:e==="percent"?void 0:t.abbreviation};return i=>{const o=_e(i.value);return o==null?"":e==="currency"?re(o,{...r,symbol:t.symbol,symbolPosition:t.symbolPosition}):e==="percent"?ie(o,{...r,points:t.points}):B(o,r)}},x=(e,t,r)=>({...e,cellDataType:e.cellDataType??"number",editorType:e.editorType??"fieldNumber",align:e.align??(r==="percent"&&t.showBar?"left":"right"),...Ft(e,t),valueParser:e.valueParser??Vt(r,t),formatter:e.formatter??It(r,t),sortValue:e.sortValue??E}),C=e=>Array.isArray(e.options)?e.options.map(t=>({value:t.value,label:t.label??String(t.value),...t.color?{color:t.color}:{}})):[],be=(e,t)=>{const r=new Map;for(const n of C(e))r.set(String(n.value).toLowerCase(),n.value),r.set(String(n.label).toLowerCase(),n.value);const i=n=>r.get(n.toLowerCase()),o=r.size===0;return n=>{if(typeof n.rawInput!="string")return n.newValue;const a=t?G(n.rawInput):n.rawInput.split(/\n/).map(f=>f.trim()).filter(Boolean);if(o)return t?[...new Set(a)]:a[0]??null;const p=a.map(i).filter(f=>f!==void 0);return a.length&&!p.length?n.oldValue:t?[...new Set(p)]:a.length?i(a[0])===void 0?n.oldValue:i(a[0]):null}},ke=e=>{const t=new Map(C(e).map(r=>[String(r.value),r.label]));return r=>(Array.isArray(r.value)?r.value:r.value==null||r.value===""?[]:[r.value]).map(i=>t.get(String(i))??String(i)).join(", ")},Lt=e=>{const t=new Map(C(e).map((r,i)=>[String(r.value),i]));return r=>r==null||r===""?null:t.get(String(r))??t.size},we=Ye,m=e=>({editable:e.editable??!1}),Z=e=>t=>R(t.value,e),P=e=>e.oldValue!=null&&typeof e.oldValue!="string"&&String(e.oldValue)===e.newValue?e.oldValue:e.newValue,At=e=>t=>{const r=typeof t.rawInput=="string"?t.rawInput:t.newValue;if(r==null||typeof r=="string"&&r.trim()==="")return null;if(r instanceof Date)return e.time?r.toISOString():N({y:r.getFullYear(),mo:r.getMonth()+1,d:r.getDate(),time:null},e);const i=String(r).trim();if(/^\d{4}-\d{2}-\d{2}(T\d{2}:\d{2})?/.test(i)){if(!e.time)return i.slice(0,10);if(i.length>10&&i[10]==="T")return i}const o=je(i,e);return o?N(o,e,t.oldValue):t.oldValue},q=e=>(Array.isArray(e)?e:e==null||e===""?[]:[e]).map(t=>se(t)?.name??String(t)).join(", "),Te=e=>t=>{if(typeof t.rawInput!="string")return t.newValue;const r=_(),i=a=>{const p=a.toLowerCase();return r.find(d=>d.id.toLowerCase()===p||d.name.toLowerCase()===p||d.email?.toLowerCase()===p)?.id??(r.length?void 0:a)},o=e?G(t.rawInput):t.rawInput.split(/\n/).map(a=>a.trim()).filter(Boolean),n=o.map(i).filter(a=>a!==void 0);return o.length&&!n.length?t.oldValue:e?[...new Set(n)]:o.length?n[0]:null},Ot=e=>t=>{if(typeof t.rawInput!="string")return t.newValue;const r=k(e.table);if(!r)return t.newValue;const i=G(t.rawInput),o=at(r,i);if(r.records&&r.resolveNames&&t.data&&t.columnId){const n=i.filter(a=>ot(r,a)==null);n.length&&r.resolveNames({row:t.data,columnId:t.columnId,multiple:e.multiple!==!1},n,o)}return i.length&&!o.length?t.oldValue:e.multiple===!1?o.slice(0,1):o},Nt=e=>typeof e.rawInput=="string"?e.rawInput.trim()?ft(e.rawInput):null:Array.isArray(e.newValue)?mt(e.newValue):e.newValue??null,Rt=e=>t=>{if(typeof t.rawInput!="string")return t.newValue;const r=t.rawInput.trim();if(!r)return null;const i=Number(r);return Number.isInteger(i)&&i>=0&&i<=Number(e.max??5)?i:t.oldValue},Bt=e=>{const t=typeof e.rawInput=="string"?e.rawInput:e.newValue;return t==null||String(t).trim()===""?null:j(t)??e.oldValue},Et=e=>t=>{const r=typeof t.rawInput=="string"?t.rawInput:t.newValue;return r==null||typeof r=="string"&&r.trim()===""?null:de(r,{seconds:!!e.showSeconds})??t.oldValue};function ve(e,t){if(e==null)return"";if(Array.isArray(e))return e.map(r=>ve(r,t)).join(", ");if(e instanceof Date)return R(e,t);if(typeof e=="boolean")return e?"true":"false";if(typeof e=="number"){if(t.result==="currency"||t.result==="percent"||t.result==="number"){const r=t.result,i={...Dt(t),precision:ne(r,{precision:t.precision}).places};return r==="currency"?re(e,{...i,symbol:t.symbol}):r==="percent"?ie(e,i):B(e,i)}return String(Math.round(e*1e10)/1e10)}if(t.result==="date"){const r=et(String(e));if(r)return R(r,t)}return String(e)}const J=(e,t)=>{const r=t.columns.find(n=>String(n.id??n.field)===e.linkField);if(!r)return null;const i=r.fieldProps?.table,o=r.fieldProps?.inverse;return{key:String(r.field??r.id),get table(){return k(i)},rowsOf(n){const a=k(i),p=String(r.field??r.id);return a&&o&&!a.records&&n?.[p]===void 0?nt(a,o,String(n?.id??"")):z(a,n?.[p])},get stored(){const n=k(i)?.records;return n&&o&&n.stores(o)?{records:n,field:o}:null}}},Ut={SUM:"sum",AVERAGE:"avg",MIN:"min",MAX:"max",COUNT:"count"},Se=new WeakMap;function Me(e,t,r){const i=e?.table?.fields;if(!i)return;let o=Se.get(i);o||Se.set(i,o=new Map);const n=`${String(t)}|${r??""}`;if(o.has(n))return o.get(n);const a=i.find(f=>f.field===String(t)),p=a?.fieldType?Q({field:a.field,fieldType:a.fieldType,fieldProps:{...a.fieldProps,...r==null?{}:{precision:r}}}).formatter:void 0;return o.set(n,p),p}const L=()=>new Date().toISOString(),Ht=new Intl.Collator(void 0,{sensitivity:"base",numeric:!0}),_t=(e,t)=>{const r=i=>i?ce.indexOf(i):ce.length;return r(e)-r(t)},Ce=[{key:"watch",get label(){return l("fields.propWatch")},kind:"segmented",choices:[u("all","fields.choiceAllFields"),u("specific","fields.choiceSpecificFields")]},{key:"watchFields",get label(){return l("fields.propWatchFields")},kind:"columns",visible:e=>e.watch==="specific"}];export const BUILTIN_FIELD_TYPES=[{id:"text",get label(){return l("fields.typeText")},get description(){return l("fields.typeTextDescription")},icon:s.text,group:"basic",properties:[w],fill:e=>({...e,editorType:e.editorType??"text",valueParser:e.valueParser??P})},{id:"longText",get label(){return l("fields.typeLongText")},get description(){return l("fields.typeLongTextDescription")},icon:s.longText,group:"basic",width:260,properties:[{key:"richText",get label(){return l("fields.propMarkdown")},kind:"checkbox",get hint(){return l("fields.propMarkdownHint")}}],fill:e=>({...e,editorType:e.editorType??"fieldLongText",valueParser:e.valueParser??P}),cell:Ae,hasCell:e=>!!e.richText},{id:"richText",get label(){return l("fields.typeRichText")},get description(){return l("fields.typeRichTextDescription")},icon:s.richText,group:"basic",width:280,defaults:{toolbar:"standard"},properties:[{key:"toolbar",get label(){return l("fields.propToolbar")},kind:"segmented",choices:[u("standard","fields.choiceStandard"),u("full","fields.choiceFull")],get hint(){return l("fields.propToolbarHint")}}],fill:e=>({...e,editorType:e.editorType??"fieldRichText",formatter:e.formatter??(t=>D(t.value)),sortComparator:e.sortComparator??((t,r)=>Ht.compare(D(t),D(r))),valueParser:e.valueParser??(t=>Ne(t.newValue))}),cell:Oe},{id:"attachment",get label(){return l("fields.typeAttachment")},get description(){return l("fields.typeAttachmentDescription")},icon:s.attachment,group:"basic",width:180,defaults:{maxFiles:20},properties:[{key:"accept",get label(){return l("fields.propAccept")},kind:"text",get placeholder(){return l("fields.propAcceptPlaceholder")}},{key:"maxFiles",get label(){return l("fields.propMaxFiles")},kind:"number",min:1,max:100}],fill:(e,t)=>({...e,editorType:e.editorType??"attachment",formatter:e.formatter??(r=>Ee(r.value)),valueParser:e.valueParser??(r=>Ue(r.newValue,t))}),cell:De},{id:"checkbox",get label(){return l("fields.typeCheckbox")},get description(){return l("fields.typeCheckboxDescription")},icon:s.checkbox,group:"basic",width:90,defaults:{icon:"check",color:"#20c933"},properties:[{key:"icon",get label(){return l("fields.propIcon")},kind:"icon",icons:$e},M,w],fill:e=>({...e,editorType:e.editorType??"checkbox",align:e.align??"center",toggleOnSecondClick:e.toggleOnSecondClick??!0}),cell:Ve},{id:"singleSelect",get label(){return l("fields.typeSingleSelect")},get description(){return l("fields.typeSingleSelectDescription")},icon:s.singleSelect,group:"basic",width:140,defaults:{options:[]},properties:[he,w],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",editorOptions:e.editorOptions??C(t),formatter:e.formatter??ke(t),valueParser:e.valueParser??be(t,!1),sortValue:e.sortValue??Lt(t)}),cell:te},{id:"multiSelect",get label(){return l("fields.typeMultiSelect")},get description(){return l("fields.typeMultiSelectDescription")},icon:s.multiSelect,group:"basic",width:200,defaults:{options:[]},properties:[he,w],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",editorMultiple:e.editorMultiple??!0,editorOptions:e.editorOptions??C(t),formatter:e.formatter??ke(t),valueParser:e.valueParser??be(t,!0)}),cell:te},{id:"user",get label(){return l("fields.typeUser")},get description(){return l("fields.typeUserDescription")},icon:s.user,group:"basic",width:170,properties:[{key:"multiple",get label(){return l("fields.propMultipleUsers")},kind:"checkbox"},w],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",valueParser:e.valueParser??Te(!!t.multiple),editorMultiple:e.editorMultiple??!!t.multiple,editorOptions:e.editorOptions??_().map(r=>({value:r.id,label:r.name})),formatter:e.formatter??(r=>q(r.value))}),cell:O},{id:"date",get label(){return l("fields.typeDate")},get description(){return l("fields.typeDateDescription")},icon:s.date,group:"basic",width:150,defaults:{dateFormat:"local",timeFormat:"12hour"},properties:[I(),...Y,{key:"defaultToday",get label(){return l("fields.propDefaultToday")},kind:"checkbox"}],fill:(e,t)=>({...e,cellDataType:e.cellDataType??(t.time?"date":"dateString"),editorType:e.editorType??"fieldDate",editorFormatString:e.editorFormatString??He(t),formatter:e.formatter??Z(t),valueParser:e.valueParser??At(t)}),newRowValue:({props:e})=>{if(!e.defaultToday)return;if(e.time)return L();const t=new Date;return N({y:t.getFullYear(),mo:t.getMonth()+1,d:t.getDate(),time:null},{})}},{id:"phone",get label(){return l("fields.typePhone")},get description(){return l("fields.typePhoneDescription")},icon:s.phone,group:"basic",fill:e=>({...e,editorType:e.editorType??"text",valueParser:e.valueParser??P}),cell:A},{id:"email",get label(){return l("fields.typeEmail")},get description(){return l("fields.typeEmailDescription")},icon:s.email,group:"basic",width:200,fill:e=>({...e,editorType:e.editorType??"text",valueParser:e.valueParser??P}),cell:A},{id:"url",get label(){return l("fields.typeUrl")},get description(){return l("fields.typeUrlDescription")},icon:s.url,group:"basic",width:200,fill:e=>({...e,editorType:e.editorType??"text",valueParser:e.valueParser??P}),cell:A},{id:"barcode",get label(){return l("fields.typeBarcode")},get description(){return l("fields.typeBarcodeDescription")},icon:s.barcode,group:"basic",width:160,fill:e=>({...e,editorType:e.editorType??"text",formatter:e.formatter??(t=>t.value&&typeof t.value=="object"?String(t.value.text??""):String(t.value??""))}),cell:Ie},{id:"button",get label(){return l("fields.typeButton")},get description(){return l("fields.typeButtonDescription")},icon:s.button,group:"basic",width:120,defaults:{label:"Open",color:"#2d7ff9"},properties:[{key:"label",get label(){return l("fields.propButtonLabel")},kind:"text",get placeholder(){return l("fields.propButtonLabelPlaceholder")}},{key:"color",get label(){return l("fields.propButtonStyle")},kind:"color",palette:oe},{key:"url",get label(){return l("fields.propButtonUrl")},kind:"text",get placeholder(){return l("fields.propButtonUrlPlaceholder")},get hint(){return l("fields.propButtonUrlHint")}}],fill:(e,t,r)=>({...e,...m(e),sortable:e.sortable??!1,__fieldNames:we(r.columns)}),cell:Fe},{id:"checklist",get label(){return l("fields.typeChecklist")},get description(){return l("fields.typeChecklistDescription")},icon:s.checklist,group:"basic",width:150,fill:e=>({...e,editorType:e.editorType??"fieldChecklist",formatter:e.formatter??(t=>pt(t.value)),valueParser:e.valueParser??Nt,sortValue:e.sortValue??dt,groupValue:e.groupValue??ct,groupOrder:e.groupOrder??_t}),cell:Re},{id:"color",get label(){return l("fields.typeColor")},get description(){return l("fields.typeColorDescription")},icon:s.color,group:"basic",width:130,properties:[w],fill:e=>({...e,editorType:e.editorType??"fieldColor",formatter:e.formatter??(t=>j(t.value)??String(t.value??"")),valueParser:e.valueParser??Bt,sortValue:e.sortValue??gt}),newRowValue:({props:e})=>e.default==null||e.default===""?void 0:j(e.default),cell:Be},{id:"number",get label(){return l("fields.typeNumber")},get description(){return l("fields.typeNumberDescription")},icon:s.number,group:"number",width:120,defaults:{format:"decimal",precision:1,separators:"local",showThousands:!0,abbreviation:"none",allowNegative:!0,symbol:"$",symbolPosition:"before",showBar:!1,points:!1,step:1},properties:[{key:"format",get label(){return l("fields.propFormat")},kind:"segmented",choices:[u("integer","fields.choiceInteger"),u("decimal","fields.choiceDecimal"),u("currency","fields.choiceCurrency"),u("percent","fields.choicePercent")],alsoSets:e=>({precision:e==="decimal"?1:e==="currency"?2:0})},{key:"symbol",get label(){return l("fields.propCurrencySymbol")},kind:"text",placeholder:"$, €, £, ¥, CHF, kr",visible:e=>e.format==="currency"},{key:"symbolPosition",get label(){return l("fields.propSymbolPosition")},kind:"segmented",visible:e=>e.format==="currency",choices:[u("before","fields.choiceBefore"),u("after","fields.choiceAfter")]},W(K(0,8),e=>e.format!=="integer"),{key:"step",get label(){return l("fields.propStep")},kind:"number",min:0,get hint(){return l("fields.propStepHint")}},wt,Tt,vt(e=>e.format!=="percent"),St,{key:"showBar",get label(){return l("fields.propShowBar")},kind:"checkbox",visible:e=>e.format==="percent"},{key:"points",get label(){return l("fields.propPoints")},kind:"checkbox",visible:e=>e.format==="percent"},w],fill:(e,t)=>x(e,t,Ge("number",t)),cell:ee,hasCell:e=>e.format==="percent"&&!!e.showBar},{id:"currency",get label(){return l("fields.typeCurrency")},get description(){return l("fields.typeCurrencyDescription")},icon:s.currency,group:"number",width:120,defaults:{symbol:"$",symbolPosition:"before",precision:2,separators:"local",showThousands:!0,abbreviation:"none",allowNegative:!0},editAs:{type:"number",props:{format:"currency"}},fill:(e,t)=>x(e,t,"currency")},{id:"percent",get label(){return l("fields.typePercent")},get description(){return l("fields.typePercentDescription")},icon:s.percent,group:"number",width:110,defaults:{precision:0,separators:"local",showThousands:!0,allowNegative:!0,points:!1},editAs:{type:"number",props:{format:"percent"}},fill:(e,t)=>x(e,t,"percent"),cell:ee,hasCell:e=>!!e.showBar},{id:"duration",get label(){return l("fields.typeDuration")},get description(){return l("fields.typeDurationDescription")},icon:s.duration,group:"number",width:110,defaults:{durationFormat:"h:mm"},properties:[{key:"durationFormat",get label(){return l("fields.propDurationFormat")},kind:"choice",choices:[{value:"h:mm",label:"h:mm"},{value:"h:mm:ss",label:"h:mm:ss"},{value:"h:mm:ss.S",label:"h:mm:ss.S"},{value:"h:mm:ss.SS",label:"h:mm:ss.SS"},{value:"h:mm:ss.SSS",label:"h:mm:ss.SSS"}]}],fill:(e,t)=>({...e,cellDataType:e.cellDataType??"number",editorType:e.editorType??"fieldNumber",formatter:e.formatter??(r=>{const i=E(r.value);return i==null?"":le(i,t.durationFormat)}),valueParser:e.valueParser??(r=>typeof r.rawInput=="string"?r.rawInput.trim()?V(r.rawInput)??r.oldValue:null:typeof r.newValue=="number"?r.newValue:V(r.newValue))})},{id:"timeOfDay",get label(){return l("fields.typeTimeOfDay")},get description(){return l("fields.typeTimeOfDayDescription")},icon:s.timeOfDay,group:"number",width:120,defaults:{timeFormat:"12hour",showSeconds:!1},properties:[{key:"timeFormat",get label(){return l("fields.propTimeFormat")},kind:"segmented",choices:me},{key:"showSeconds",get label(){return l("fields.propShowSeconds")},kind:"checkbox"},w],fill:(e,t)=>({...e,editorType:e.editorType??"fieldTime",formatter:e.formatter??(r=>ht(r.value,t)),valueParser:e.valueParser??Et(t),sortValue:e.sortValue??yt}),newRowValue:({props:e})=>e.default==null||e.default===""?void 0:de(e.default,{seconds:!!e.showSeconds})},{id:"rating",get label(){return l("fields.typeRating")},get description(){return l("fields.typeRatingDescription")},icon:s.rating,group:"number",width:130,defaults:{max:5,icon:"star",color:"#fcb400"},properties:[{key:"icon",get label(){return l("fields.propIcon")},kind:"icon",icons:Ke},M,{key:"max",get label(){return l("fields.propMaximum")},kind:"choice",choices:Array.from({length:10},(e,t)=>({value:String(t+1),label:String(t+1)}))}],fill:(e,t)=>({...e,cellDataType:e.cellDataType??"number",align:e.align??"left",editorType:e.editorType??"fieldRating",valueParser:e.valueParser??Rt(t)}),cell:Pe},{id:"timer",get label(){return l("fields.typeTimer")},get description(){return l("fields.typeTimerDescription")},icon:s.timer,group:"number",width:130,defaults:{durationFormat:"h:mm:ss"},properties:[{key:"durationFormat",get label(){return l("fields.propDurationFormat")},kind:"choice",choices:[{value:"h:mm",label:"h:mm"},{value:"h:mm:ss",label:"h:mm:ss"}]},M],fill:(e,t)=>({...e,cellDataType:e.cellDataType??"number",editorType:e.editorType??"fieldTimer",align:e.align??"left",sortValue:e.sortValue??(r=>F(r)),formatter:e.formatter??(r=>{const i=F(r.value);return i==null?"":le(i,t.durationFormat??"h:mm:ss")}),valueParser:e.valueParser??(r=>typeof r.rawInput=="string"?r.rawInput.trim()?V(r.rawInput)??r.oldValue:null:r.newValue==null||r.newValue===""?null:typeof r.newValue=="number"||typeof r.newValue=="object"&&qe(r.newValue)!=null?r.newValue:V(r.newValue))}),cell:Ze},{id:"vote",get label(){return l("fields.typeVote")},get description(){return l("fields.typeVoteDescription")},icon:s.vote,group:"basic",width:100,defaults:{icon:"up"},properties:[{key:"icon",get label(){return l("fields.propIcon")},kind:"segmented",choices:[u("up","fields.choiceArrow"),u("thumb","fields.choiceThumb"),u("heart","fields.choiceHeart")]},M],fill:e=>({...e,editorType:e.editorType??"fieldVote",editorOptions:e.editorOptions??_().map(t=>({value:t.id,label:t.name})),align:e.align??"left",sortValue:e.sortValue??(t=>ae(t)),formatter:e.formatter??(t=>String(ae(t.value))),valueParser:e.valueParser??(t=>Xe(Te(!0)(t)))}),newRowValue:()=>[],cell:xe},{id:"sparkline",get label(){return l("fields.typeSparkline")},get description(){return l("fields.typeSparklineDescription")},icon:s.sparkline,group:"number",width:160,defaults:{chart:"line"},properties:[{key:"chart",get label(){return l("fields.propChart")},kind:"segmented",choices:[u("line","fields.choiceLine"),u("area","fields.choiceArea"),u("bar","fields.choiceColumns")]},M,{key:"showLast",get label(){return l("fields.propShowLast")},kind:"checkbox"}],fill:e=>({...e,formatter:e.formatter??(t=>H(t.value).join(", ")),valueParser:e.valueParser??(t=>{const r=H(t.newValue);return r.length?r:null}),sortValue:e.sortValue??(t=>H(t).at(-1)??null)}),cell:Je},{id:"formula",get label(){return l("fields.typeFormula")},get description(){return l("fields.typeFormulaDescription")},icon:s.formula,group:"computed",width:160,defaults:{formula:"",result:"auto"},properties:[{key:"formula",get label(){return l("fields.propFormula")},kind:"formula"},{key:"result",get label(){return l("fields.propResult")},kind:"choice",choices:[u("auto","fields.choiceAsComputed"),u("number","fields.choiceNumber"),u("currency","fields.choiceCurrency"),u("percent","fields.choicePercent"),u("date","fields.choiceDate")]},W(K(0,8),e=>["number","currency","percent"].includes(e.result)),{key:"symbol",get label(){return l("fields.propCurrencySymbol")},kind:"text",placeholder:"$",visible:e=>e.result==="currency"},I(e=>e.result==="date")],fill:(e,t,r)=>{const i=we(r.columns),o=String(t.formula??""),n=String(e.field??e.id),a=new Set([n.toLowerCase(),typeof e.header=="string"?e.header.trim().toLowerCase():""].filter(Boolean)),p=c=>{const b=c.trim().toLowerCase(),h=i[b]??null;if(h===n||h==null&&a.has(b))throw tt(c);return h};let f=null;try{f=o.trim()?Qe(o,p).fn:()=>null}catch{f=null}let d=null;const g=()=>{if(d)return d;d=new Map;for(const c of r.columns){if(c.fieldType==="richText"){const y=String(c.field??c.id);d.set(y,T=>D(T?.[y]));continue}if(c.fieldType==="timer"){const y=String(c.field??c.id);d.set(y,T=>F(T?.[y]));continue}const b=kt(c);if(b){d.set(String(c.field??c.id),b);continue}if(!We.has(String(c.fieldType))||String(c.field??c.id)===n)continue;const h=Q(c,r.columns);typeof h.fieldFn=="function"&&d.set(String(c.field??c.id),h.fieldFn)}return d},S=c=>{const b=g();return!b.size||!c?c:new Proxy(c,{get:(h,y)=>{const T=typeof y=="string"?b.get(y):void 0;if(!T||v>3)return h[y];v+=1;try{return T(h)}finally{v-=1}}})};return{...e,...m(e),fieldFn:c=>f?f(S(c)):"#ERROR",align:e.align??(["number","currency","percent"].includes(t.result)?"right":void 0),formatter:e.formatter??(c=>ve(c.value,t))}}},{id:"createdTime",get label(){return l("fields.typeCreatedTime")},get description(){return l("fields.typeCreatedTimeDescription")},icon:s.createdTime,group:"computed",width:170,defaults:{dateFormat:"local",time:!0,timeFormat:"12hour"},properties:[I(),...Y],fill:(e,t)=>({...e,...m(e),formatter:e.formatter??Z(t)}),newRowValue:()=>L(),onCreate:({rows:e})=>e.map(()=>L())},{id:"lastModifiedTime",get label(){return l("fields.typeLastModifiedTime")},get description(){return l("fields.typeLastModifiedTimeDescription")},icon:s.modifiedTime,group:"computed",width:170,defaults:{dateFormat:"local",time:!0,timeFormat:"12hour",watch:"all"},properties:[...Ce,I(),...Y],fill:(e,t)=>({...e,...m(e),formatter:e.formatter??Z(t)}),newRowValue:()=>L()},{id:"createdBy",get label(){return l("fields.typeCreatedBy")},get description(){return l("fields.typeCreatedByDescription")},icon:s.createdBy,group:"computed",width:160,fill:e=>({...e,...m(e),formatter:e.formatter??(t=>q(t.value))}),newRowValue:()=>ue()?.id??null,cell:O},{id:"lastModifiedBy",get label(){return l("fields.typeLastModifiedBy")},get description(){return l("fields.typeLastModifiedByDescription")},icon:s.modifiedBy,group:"computed",width:160,defaults:{watch:"all"},properties:Ce,fill:e=>({...e,...m(e),formatter:e.formatter??(t=>q(t.value))}),newRowValue:()=>ue()?.id??null,cell:O},{id:"autoNumber",get label(){return l("fields.typeAutoNumber")},get description(){return l("fields.typeAutoNumberDescription")},icon:s.autoNumber,group:"computed",width:100,fill:e=>({...e,...m(e),cellDataType:e.cellDataType??"number"}),newRowValue:({rows:e,field:t})=>e.reduce((r,i)=>Math.max(r,Number(i?.[t])||0),0)+1,onCreate:({rows:e})=>e.map((t,r)=>r+1)},{id:"link",get label(){return l("fields.typeLink")},get description(){return l("fields.typeLinkDescription")},icon:s.link,group:"relation",width:200,defaults:{multiple:!0},properties:[{key:"table",get label(){return l("fields.propTable")},kind:"choice",choices:()=>lt().map(e=>({value:e.id,label:e.name})),get hint(){return l("fields.propTableHint")},alsoSets:()=>({pickFrom:""})},{key:"multiple",get label(){return l("fields.propMultipleRecords")},kind:"checkbox"},{key:"pickFrom",get label(){return l("fields.propPickFrom")},kind:"choice",choices:e=>[{value:"",label:l("fields.pickFromAll")},...(k(e.props.table)?.views?.()??[]).filter(t=>!t.personal&&t.type!=="form").map(t=>({value:t.id,label:t.name}))],visible:e=>!!e.table,get hint(){return l("fields.propPickFromHint")}}],fill:(e,t)=>({...e,editorType:e.editorType??"fieldLink",formatter:e.formatter??(r=>{const i=k(t.table);return z(i,r.value).map(o=>String(o[i.primaryField]??"")).join(", ")}),valueParser:e.valueParser??Ot(t),groupValue:e.groupValue??(r=>it(t.table,r)),groupCopies:!0}),cell:Le},{id:"lookup",get label(){return l("fields.typeLookup")},get description(){return l("fields.typeLookupDescription")},icon:s.lookup,group:"relation",width:180,properties:[X,ge],fill:(e,t,r)=>{const i=J(t,r),o=n=>{const a=Me(i,t.field);return String(a?a({value:n})??"":n)};return{...e,...m(e),fieldSource:()=>i?.table?.fields?.find(n=>n.field===String(t.field)),fieldFn:n=>{if(!i)return[];const a=$(i.table,String(t.field)),p=i.stored;return p?p.records.allLinkedTo(p.field,String(n?.id??"")).map(a):i.rowsOf(n).map(a)},formatter:e.formatter??(n=>Array.isArray(n.value)?n.value.filter(a=>a!=null&&a!=="").map(o).join(", "):n.value==null?"":o(n.value))}}},{id:"rollup",get label(){return l("fields.typeRollup")},get description(){return l("fields.typeRollupDescription")},icon:s.rollup,group:"relation",width:140,defaults:{aggregation:"SUM"},properties:[X,ge,{key:"aggregation",get label(){return l("fields.propAggregation")},kind:"choice",choices:Object.keys(U).map(e=>({value:e,label:e}))},W(K(0,8),e=>["SUM","AVERAGE","MIN","MAX"].includes(e.aggregation))],fill:(e,t,r)=>{const i=J(t,r),o=U[String(t.aggregation)]??U.SUM,n=["SUM","AVERAGE","MIN","MAX","COUNT","COUNTA","COUNTALL"].includes(String(t.aggregation)),a=["SUM","AVERAGE","MIN","MAX"].includes(String(t.aggregation)),p=f=>{const d=a?Me(i,t.field,t.precision):void 0;return d?String(d({value:f})??""):B(f,{precision:ye(t,0)})};return{...e,...m(e),...n?{cellDataType:e.cellDataType??"number"}:{},align:e.align??(n?"right":void 0),fieldSource:()=>i?.table?.fields?.find(f=>f.field===String(t.field)),fieldFn:f=>{if(!i)return null;const d=$(i.table,String(t.field)),g=i.stored;if(g){const S=String(f?.id??""),c=Ut[String(t.aggregation)];return c?g.records.total(g.field,S,String(t.field),c)??null:t.aggregation==="COUNTA"||t.aggregation==="COUNTALL"?g.records.total(g.field,S)??null:o(g.records.allLinkedTo(g.field,S).map(d))}return o(i.rowsOf(f).map(d))},formatter:e.formatter??(f=>{const d=n?E(f.value):typeof f.value=="number"?f.value:null;return d==null?String(f.value??""):p(d)})}}},{id:"count",get label(){return l("fields.typeCount")},get description(){return l("fields.typeCountDescription")},icon:s.count,group:"relation",width:90,properties:[X],fill:(e,t,r)=>{const i=J(t,r);return{...e,...m(e),cellDataType:e.cellDataType??"number",formatter:o=>o.value==null?"":Number(o.value).toLocaleString(),fieldFn:o=>{if(!i)return 0;const n=i.stored;return n?n.records.total(n.field,String(o?.id??""))??null:i.rowsOf(o).length}}}},ut];
@@ -30,6 +30,10 @@ export declare const chartXColumns: (ctrl: any) => FieldColumn[];
30
30
  export declare const chartYColumns: (ctrl: any) => FieldColumn[];
31
31
  /** A first setting for a new chart view: the first select (or any field it can group by), counted. */
32
32
  export declare function defaultChart(ctrl: any): ChartSetting | null;
33
+ /** The labels a record falls under for field `c`, as a chart shows them (a pivot's rows and columns). */
34
+ export declare function groupLabelsOf(c: FieldColumn, row: Row): string[];
35
+ /** A record's value of field `c` as a number, or null when it is not one (a pivot's sums). */
36
+ export declare function numberOf(c: FieldColumn, row: Row): number | null;
33
37
  /** The chart for `rows` (the records the view shows), or null when its fields are gone. */
34
38
  export declare function chartSpec(ctrl: any, setting: ChartSetting, rows: ReadonlyArray<Row>): ChartSpec | null;
35
39
  export type ServerChart = {
@@ -1 +1 @@
1
- import{isMoment as U}from"./filter-model.js";import{askAll as G,dayKey as R,noGroups as Z,offsetSpans as ee}from"./view-feed.svelte.js";import{fieldColumns as D}from"./grid-access.js";import{fieldPropsOf as x,originalColumn as C}from"./registry.svelte.js";import{findFieldUser as Y,getLinkedTable as te,linkedRows as ne}from"./sources.svelte.js";import{bm as g}from"./messages.svelte.js";import{maxOf as re}from"../extent.js";export const CHART_KINDS=[{kind:"bar",get label(){return g("viewbar.chartBar")}},{kind:"barH",get label(){return g("viewbar.chartBarH")}},{kind:"line",get label(){return g("viewbar.chartLine")}},{kind:"pie",get label(){return g("viewbar.chartPie")}},{kind:"donut",get label(){return g("viewbar.chartDonut")}}];const oe=new Set(["singleSelect","multiSelect","user","date","checkbox","link","text","rating","createdTime","createdBy","formula","lookup"]),ie=new Set(["number","currency","percent","rating","duration","count","rollup"]),ae=new Set(["number","currency","percent"]);export const chartXColumns=t=>D(t).filter(n=>oe.has(n.fieldType??"")||n.def.cellDataType==="date"||n.def.cellDataType==="dateString"),chartYColumns=t=>D(t).filter(n=>ie.has(n.fieldType??"")||n.fieldType==="formula"&&ae.has(String(x(C(n.def)).result))||!n.fieldType&&n.def.cellDataType==="number");export function defaultChart(t){const n=chartXColumns(t),o=n.find(i=>i.fieldType==="singleSelect")??n[0];return o?{kind:"bar",x:o.id}:null}const m="Empty",E="Checked",$="Unchecked",se=["viewbar.monthJan","viewbar.monthFeb","viewbar.monthMar","viewbar.monthApr","viewbar.monthMay","viewbar.monthJun","viewbar.monthJul","viewbar.monthAug","viewbar.monthSep","viewbar.monthOct","viewbar.monthNov","viewbar.monthDec"];function H(t,n){return n===m?g("viewbar.empty"):t.fieldType==="checkbox"?n===E?g("viewbar.chartChecked"):n===$?g("viewbar.chartUnchecked"):n:n}const B=t=>{if(U(t)){const n=t instanceof Date?t:new Date(String(t));return Number.isNaN(n.getTime())?null:R(n).slice(0,7)}return/^\d{4}-\d{2}/.exec(String(t))?.[0]??null};function z(t,n){const o=t.def.fieldFn;return o?o(n):n?.[t.field]}function I(t,n){const o=z(t,n),i=Array.isArray(o)?o:o==null||o===""?[]:[o];if(t.fieldType==="checkbox")return[o===!0?E:$];if(!i.length)return[m];if(t.fieldType==="user"||t.fieldType==="createdBy")return i.map(e=>Y(e)?.name??String(e));if(t.fieldType==="link"){const e=te(x(C(t.def)).table),l=e?ne(e,o).map(r=>String(r[e.primaryField]??"")):[];return l.length?l:[m]}if(t.fieldType==="lookup"){const e=t.def.formatter,l=i.map(r=>String(e?e({value:r})??"":r)).filter(r=>r!=="");return l.length?[...new Set(l)]:[m]}if(t.fieldType==="formula"){const e=x(C(t.def)).result==="date"||t.def.cellDataType==="date"||t.def.cellDataType==="dateString",l=i.map(r=>r instanceof Date?Number.isNaN(r.getTime())?m:`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}`:typeof r=="number"?String(Math.round(r*1e10)/1e10):e&&typeof r=="string"&&/^\d{4}-\d{2}-\d{2}/.test(r)?B(r):String(r));return[...new Set(l)]}return t.fieldType==="date"||t.fieldType==="createdTime"||t.def.cellDataType==="date"||t.def.cellDataType==="dateString"?[B(i[0])??String(i[0])]:i.map(e=>String(e))}function F(t,n){const o={},i=n.includes(m)?[m]:[],e=n.filter(r=>r!==m);if(t.fieldType==="singleSelect"||t.fieldType==="multiSelect"){const r=x(C(t.def)).options??[],s=new Map(r.map((d,f)=>[String(d.value),f]));for(const d of r)d.color&&(o[String(d.value)]=d.color);return e.sort((d,f)=>(s.get(d)??1e9)-(s.get(f)??1e9)),{keys:[...e,...i],label:d=>H(t,d),colors:o}}return e.length>0&&e.every(r=>/^\d{4}-\d{2}$/.test(r))?(e.sort(),{keys:[...e,...i],label:r=>r===m?H(t,r):g("viewbar.chartMonth",{month:g(se[Number(r.slice(5))-1]),year:r.slice(0,4)}),colors:o}):(e.length&&e.every(r=>r!==""&&!Number.isNaN(Number(r)))&&e.sort((r,s)=>Number(r)-Number(s)),{keys:[...e,...i],label:r=>H(t,r),colors:o})}export function chartSpec(t,n,o){const i=D(t),e=i.find(s=>s.id===n.x);if(!e)return null;const l=n.y?i.find(s=>s.id===n.y):void 0,r=new Map;for(const s of o){if(s==null)continue;const d=l?Number(z(l,s)):1;for(const f of I(e,s)){const b=r.get(f)??{total:0,n:0};(!l||Number.isFinite(d))&&(b.total+=Number.isFinite(d)?d:0,b.n+=1),r.set(f,b)}}return K(e,l,n,r)}function K(t,n,o,i){const{keys:e,label:l,colors:r}=F(t,[...i.keys()]),s=!!n&&o.aggregation==="avg",d=e.map(y=>{const S=i.get(y);return s?S.n?S.total/S.n:0:S.total}),f=e.map(l),b={};e.forEach((y,S)=>{r[y]&&(b[f[S]]=r[y])});const w=o.kind;return{type:w==="barH"?"bar":w==="donut"?"pie":w,categories:f,series:[{label:n?g(s?"viewbar.averageOf":"viewbar.sumOf",{field:n.header}):g("viewbar.chartRecords"),values:d,...Object.keys(b).length&&(w==="bar"||w==="barH")?{colors:e.map(y=>r[y]??null)}:{}}],...Object.keys(b).length?{categoryColors:b}:{},...w==="barH"?{orientation:"horizontal"}:{},...w==="donut"?{innerRadius:.58}:{}}}const _=t=>t.fieldType==="date"||t.fieldType==="createdTime"||t.def.cellDataType==="date"||t.def.cellDataType==="dateString",J=t=>({mode:"exactDate",date:t});function P(t,n){const o=Number(n.slice(0,4)),i=Number(n.slice(5,7)),e=i===12?`${o+1}-01`:`${o}-${String(i+1).padStart(2,"0")}`;return[{column:t,kind:"date",op:"isOnOrAfter",value:J(`${n}-01`)},{column:t,kind:"date",op:"isBefore",value:J(`${e}-01`)}]}function le(t,n){return n===""?m:t.fieldType==="checkbox"?n==="true"||n===E?E:$:t.fieldType==="user"||t.fieldType==="createdBy"?Y(n)?.name??n:n}export async function serverChart(t,n,o){const i=D(t),e=i.find(a=>a.id===n.x),l={spec:null,records:0,buckets:new Map};if(!e)return l;const r=n.y?i.find(a=>a.id===n.y):void 0,s=n.aggregation==="avg"?"avg":"sum",d=r?{aggregations:[{col:r.id,fn:s}]}:{},f=new Map,b=new Map;let w=0;const y=(a,c,p,h)=>{if(!p)return;w+=p;const u=f.get(a)??{total:0,n:0},k=Number(c??0);f.set(a,{total:u.total+(r?s==="avg"?k*p:k:p),n:u.n+p}),b.set(a,h)},S=a=>B(a),M=()=>[{column:e.id,kind:"date",op:"isEmpty"}],L=[{column:e.id,kind:"date",op:"isNotEmpty"}],O=a=>o({startRow:0,endRow:1,conditions:L,sorting:[{id:e.id,desc:a}]});async function j(){if(e.fieldType!=="createdTime"&&e.fieldType!=="lastModifiedTime"&&x(C(e.def)).time!==!0)return null;const a=(await O(!1)).rows[0]?.[e.field];if(a==null||!U(a))return null;const c=(await O(!0)).rows[0]?.[e.field],p=h=>(h instanceof Date?h:new Date(String(h))).getTime();return ee(new Date(p(a)-864e5),new Date(p(c??a)+864e5))}const X=(a,c)=>[{column:e.id,kind:"date",op:"isOnOrAfter",value:{mode:"exactDate",date:R(a),at:a.toISOString()}},{column:e.id,kind:"date",op:"isBefore",value:{mode:"exactDate",date:R(c),at:c.toISOString()}}];async function q(){const a=await j();for(const c of a??[null]){const p=await G(o,{groupBy:[e.id],sorting:[],skipCount:!0,groupMonths:!0,...d,...c?{conditions:X(c.from,c.to),dayOffset:c.minutes}:{}}).catch(u=>{if(Z(u))return null;throw u}),h=p?.map(u=>u[e.field]??u[e.id]??"").map(u=>u===""?"":S(u));if(!p||h.some(u=>u===null)){if(c&&f.size)throw new Error("The source stopped grouping part way.");return!1}p.forEach((u,k)=>{const v=h[k];y(v||m,r?u[r.id]:void 0,Number(u.leafCount??u.childCount??0),v?P(e.id,v):M())})}if(a){const c=await o({conditions:M(),sorting:[],...r?{needsGrandTotal:!0,...d}:{}});y(m,r?c.grandTotal?.[r.id]:void 0,c.rowCount,M())}return!0}if(_(e)&&!await q()){const[a,c,p]=await Promise.all([O(!1),O(!0),o({conditions:M(),sorting:[]})]),h=T=>T?.[e.field]==null?void 0:B(T[e.field])??void 0,u=h(a.rows[0]),k=h(c.rows[0]),v=[];if(u&&k){let T=Number(u.slice(0,4)),N=Number(u.slice(5,7));for(let A=u;A<=k;A=`${T}-${String(N).padStart(2,"0")}`)v.push(A),N+=1,N>12&&(N=1,T+=1)}(await Promise.all(v.map(T=>o({conditions:P(e.id,T),sorting:[],...r?{needsGrandTotal:!0,...d}:{}})))).forEach((T,N)=>y(v[N],r?T.grandTotal?.[r.id]:void 0,T.rowCount,P(e.id,v[N]))),y(m,0,p.rowCount,M())}else if(!_(e))for(const a of await G(o,{groupBy:[e.id],sorting:[],skipCount:!0,...d})){const c=String(a[e.field]??a[e.id]??""),p=e.fieldType==="singleSelect"||e.fieldType==="user"?"select":"text";y(le(e,c),r?a[r.id]:void 0,Number(a.childCount??0),c===""?[{column:e.id,kind:p,op:"isEmpty"}]:[{column:e.id,kind:p,op:"is",value:c}])}if(!f.size)return{...l,spec:K(e,r,n,f)};const Q=K(e,r,n,f),{keys:V,label:W}=F(e,[...f.keys()]);return{spec:Q,records:w,buckets:new Map(V.map(a=>[W(a),b.get(a)]))}}export function withValueGutter(t,n){if(!n||t.type==="pie"||t.orientation==="horizontal")return t;const o=re(t.series.flatMap(l=>l.values),0),i=o>0?10**Math.ceil(Math.log10(o)):1,e=Math.max(48,Math.round(n(i).length*6.4+14));return{...t,yAxis:{width:e}}}export function chartFormatter(t,n){const o=n.y?D(t).find(e=>e.id===n.y):void 0;if(!o)return e=>String(Math.round(e));const i=o.def.formatter;return i?e=>String(i({value:e})??e):void 0}export function chartBucketRows(t,n,o,i){const e=D(t).find(s=>s.id===n.x);if(!e)return[];const l=o.filter(s=>s!=null).map(s=>({row:s,keys:I(e,s)})),{label:r}=F(e,[...new Set(l.flatMap(s=>s.keys))]);return l.filter(s=>s.keys.some(d=>r(d)===i)).map(s=>s.row)}
1
+ import{isMoment as Y}from"./filter-model.js";import{askAll as z,dayKey as F,noGroups as Z,offsetSpans as ee}from"./view-feed.svelte.js";import{fieldColumns as x}from"./grid-access.js";import{fieldPropsOf as M,originalColumn as C}from"./registry.svelte.js";import{findFieldUser as I,getLinkedTable as te,linkedRows as ne}from"./sources.svelte.js";import{timerSeconds as re}from"./timer.js";import{bm as g}from"./messages.svelte.js";import{maxOf as oe}from"../extent.js";export const CHART_KINDS=[{kind:"bar",get label(){return g("viewbar.chartBar")}},{kind:"barH",get label(){return g("viewbar.chartBarH")}},{kind:"line",get label(){return g("viewbar.chartLine")}},{kind:"pie",get label(){return g("viewbar.chartPie")}},{kind:"donut",get label(){return g("viewbar.chartDonut")}}];const ie=new Set(["singleSelect","multiSelect","user","date","checkbox","link","text","rating","createdTime","createdBy","formula","lookup"]),ae=new Set(["number","currency","percent","rating","duration","timer","count","rollup"]),se=new Set(["number","currency","percent"]);export const chartXColumns=t=>x(t).filter(n=>ie.has(n.fieldType??"")||n.def.cellDataType==="date"||n.def.cellDataType==="dateString"),chartYColumns=t=>x(t).filter(n=>ae.has(n.fieldType??"")||n.fieldType==="formula"&&se.has(String(M(C(n.def)).result))||!n.fieldType&&n.def.cellDataType==="number");export function defaultChart(t){const n=chartXColumns(t),o=n.find(i=>i.fieldType==="singleSelect")??n[0];return o?{kind:"bar",x:o.id}:null}const p="Empty",E="Checked",H="Unchecked",le=["viewbar.monthJan","viewbar.monthFeb","viewbar.monthMar","viewbar.monthApr","viewbar.monthMay","viewbar.monthJun","viewbar.monthJul","viewbar.monthAug","viewbar.monthSep","viewbar.monthOct","viewbar.monthNov","viewbar.monthDec"];function B(t,n){return n===p?g("viewbar.empty"):t.fieldType==="checkbox"?n===E?g("viewbar.chartChecked"):n===H?g("viewbar.chartUnchecked"):n:n}const A=t=>{if(Y(t)){const n=t instanceof Date?t:new Date(String(t));return Number.isNaN(n.getTime())?null:F(n).slice(0,7)}return/^\d{4}-\d{2}/.exec(String(t))?.[0]??null};function R(t,n){const o=t.def.fieldFn;return o?o(n):n?.[t.field]}export function groupLabelsOf(t,n){return K(t,n).map(o=>B(t,o))}export function numberOf(t,n){const o=t.fieldType==="timer"?re(R(t,n)):R(t,n);if(o==null||o==="")return null;const i=Number(o);return Number.isFinite(i)?i:null}function K(t,n){const o=R(t,n),i=Array.isArray(o)?o:o==null||o===""?[]:[o];if(t.fieldType==="checkbox")return[o===!0?E:H];if(!i.length)return[p];if(t.fieldType==="user"||t.fieldType==="createdBy")return i.map(e=>I(e)?.name??String(e));if(t.fieldType==="link"){const e=te(M(C(t.def)).table),l=e?ne(e,o).map(r=>String(r[e.primaryField]??"")):[];return l.length?l:[p]}if(t.fieldType==="lookup"){const e=t.def.formatter,l=i.map(r=>String(e?e({value:r})??"":r)).filter(r=>r!=="");return l.length?[...new Set(l)]:[p]}if(t.fieldType==="formula"){const e=M(C(t.def)).result==="date"||t.def.cellDataType==="date"||t.def.cellDataType==="dateString",l=i.map(r=>r instanceof Date?Number.isNaN(r.getTime())?p:`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}`:typeof r=="number"?String(Math.round(r*1e10)/1e10):e&&typeof r=="string"&&/^\d{4}-\d{2}-\d{2}/.test(r)?A(r):String(r));return[...new Set(l)]}return t.fieldType==="date"||t.fieldType==="createdTime"||t.def.cellDataType==="date"||t.def.cellDataType==="dateString"?[A(i[0])??String(i[0])]:i.map(e=>String(e))}function P(t,n){const o={},i=n.includes(p)?[p]:[],e=n.filter(r=>r!==p);if(t.fieldType==="singleSelect"||t.fieldType==="multiSelect"){const r=M(C(t.def)).options??[],s=new Map(r.map((d,c)=>[String(d.value),c]));for(const d of r)d.color&&(o[String(d.value)]=d.color);return e.sort((d,c)=>(s.get(d)??1e9)-(s.get(c)??1e9)),{keys:[...e,...i],label:d=>B(t,d),colors:o}}return e.length>0&&e.every(r=>/^\d{4}-\d{2}$/.test(r))?(e.sort(),{keys:[...e,...i],label:r=>r===p?B(t,r):g("viewbar.chartMonth",{month:g(le[Number(r.slice(5))-1]),year:r.slice(0,4)}),colors:o}):(e.length&&e.every(r=>r!==""&&!Number.isNaN(Number(r)))&&e.sort((r,s)=>Number(r)-Number(s)),{keys:[...e,...i],label:r=>B(t,r),colors:o})}export function chartSpec(t,n,o){const i=x(t),e=i.find(s=>s.id===n.x);if(!e)return null;const l=n.y?i.find(s=>s.id===n.y):void 0,r=new Map;for(const s of o){if(s==null)continue;const d=l?Number(R(l,s)):1;for(const c of K(e,s)){const b=r.get(c)??{total:0,n:0};(!l||Number.isFinite(d))&&(b.total+=Number.isFinite(d)?d:0,b.n+=1),r.set(c,b)}}return U(e,l,n,r)}function U(t,n,o,i){const{keys:e,label:l,colors:r}=P(t,[...i.keys()]),s=!!n&&o.aggregation==="avg",d=e.map(y=>{const S=i.get(y);return s?S.n?S.total/S.n:0:S.total}),c=e.map(l),b={};e.forEach((y,S)=>{r[y]&&(b[c[S]]=r[y])});const w=o.kind;return{type:w==="barH"?"bar":w==="donut"?"pie":w,categories:c,series:[{label:n?g(s?"viewbar.averageOf":"viewbar.sumOf",{field:n.header}):g("viewbar.chartRecords"),values:d,...Object.keys(b).length&&(w==="bar"||w==="barH")?{colors:e.map(y=>r[y]??null)}:{}}],...Object.keys(b).length?{categoryColors:b}:{},...w==="barH"?{orientation:"horizontal"}:{},...w==="donut"?{innerRadius:.58}:{}}}const L=t=>t.fieldType==="date"||t.fieldType==="createdTime"||t.def.cellDataType==="date"||t.def.cellDataType==="dateString",_=t=>({mode:"exactDate",date:t});function G(t,n){const o=Number(n.slice(0,4)),i=Number(n.slice(5,7)),e=i===12?`${o+1}-01`:`${o}-${String(i+1).padStart(2,"0")}`;return[{column:t,kind:"date",op:"isOnOrAfter",value:_(`${n}-01`)},{column:t,kind:"date",op:"isBefore",value:_(`${e}-01`)}]}function de(t,n){return n===""?p:t.fieldType==="checkbox"?n==="true"||n===E?E:H:t.fieldType==="user"||t.fieldType==="createdBy"?I(n)?.name??n:n}export async function serverChart(t,n,o){const i=x(t),e=i.find(a=>a.id===n.x),l={spec:null,records:0,buckets:new Map};if(!e)return l;const r=n.y?i.find(a=>a.id===n.y):void 0,s=n.aggregation==="avg"?"avg":"sum",d=r?{aggregations:[{col:r.id,fn:s}]}:{},c=new Map,b=new Map;let w=0;const y=(a,f,m,h)=>{if(!m)return;w+=m;const u=c.get(a)??{total:0,n:0},N=Number(f??0);c.set(a,{total:u.total+(r?s==="avg"?N*m:N:m),n:u.n+m}),b.set(a,h)},S=a=>A(a),D=()=>[{column:e.id,kind:"date",op:"isEmpty"}],J=[{column:e.id,kind:"date",op:"isNotEmpty"}],O=a=>o({startRow:0,endRow:1,conditions:J,sorting:[{id:e.id,desc:a}]});async function j(){if(e.fieldType!=="createdTime"&&e.fieldType!=="lastModifiedTime"&&M(C(e.def)).time!==!0)return null;const a=(await O(!1)).rows[0]?.[e.field];if(a==null||!Y(a))return null;const f=(await O(!0)).rows[0]?.[e.field],m=h=>(h instanceof Date?h:new Date(String(h))).getTime();return ee(new Date(m(a)-864e5),new Date(m(f??a)+864e5))}const X=(a,f)=>[{column:e.id,kind:"date",op:"isOnOrAfter",value:{mode:"exactDate",date:F(a),at:a.toISOString()}},{column:e.id,kind:"date",op:"isBefore",value:{mode:"exactDate",date:F(f),at:f.toISOString()}}];async function q(){const a=await j();for(const f of a??[null]){const m=await z(o,{groupBy:[e.id],sorting:[],skipCount:!0,groupMonths:!0,...d,...f?{conditions:X(f.from,f.to),dayOffset:f.minutes}:{}}).catch(u=>{if(Z(u))return null;throw u}),h=m?.map(u=>u[e.field]??u[e.id]??"").map(u=>u===""?"":S(u));if(!m||h.some(u=>u===null)){if(f&&c.size)throw new Error("The source stopped grouping part way.");return!1}m.forEach((u,N)=>{const v=h[N];y(v||p,r?u[r.id]:void 0,Number(u.leafCount??u.childCount??0),v?G(e.id,v):D())})}if(a){const f=await o({conditions:D(),sorting:[],...r?{needsGrandTotal:!0,...d}:{}});y(p,r?f.grandTotal?.[r.id]:void 0,f.rowCount,D())}return!0}if(L(e)&&!await q()){const[a,f,m]=await Promise.all([O(!1),O(!0),o({conditions:D(),sorting:[]})]),h=T=>T?.[e.field]==null?void 0:A(T[e.field])??void 0,u=h(a.rows[0]),N=h(f.rows[0]),v=[];if(u&&N){let T=Number(u.slice(0,4)),k=Number(u.slice(5,7));for(let $=u;$<=N;$=`${T}-${String(k).padStart(2,"0")}`)v.push($),k+=1,k>12&&(k=1,T+=1)}(await Promise.all(v.map(T=>o({conditions:G(e.id,T),sorting:[],...r?{needsGrandTotal:!0,...d}:{}})))).forEach((T,k)=>y(v[k],r?T.grandTotal?.[r.id]:void 0,T.rowCount,G(e.id,v[k]))),y(p,0,m.rowCount,D())}else if(!L(e))for(const a of await z(o,{groupBy:[e.id],sorting:[],skipCount:!0,...d})){const f=String(a[e.field]??a[e.id]??""),m=e.fieldType==="singleSelect"||e.fieldType==="user"?"select":"text";y(de(e,f),r?a[r.id]:void 0,Number(a.childCount??0),f===""?[{column:e.id,kind:m,op:"isEmpty"}]:[{column:e.id,kind:m,op:"is",value:f}])}if(!c.size)return{...l,spec:U(e,r,n,c)};const Q=U(e,r,n,c),{keys:V,label:W}=P(e,[...c.keys()]);return{spec:Q,records:w,buckets:new Map(V.map(a=>[W(a),b.get(a)]))}}export function withValueGutter(t,n){if(!n||t.type==="pie"||t.orientation==="horizontal")return t;const o=oe(t.series.flatMap(l=>l.values),0),i=o>0?10**Math.ceil(Math.log10(o)):1,e=Math.max(48,Math.round(n(i).length*6.4+14));return{...t,yAxis:{width:e}}}export function chartFormatter(t,n){const o=n.y?x(t).find(e=>e.id===n.y):void 0;if(!o)return e=>String(Math.round(e));const i=o.def.formatter;return i?e=>String(i({value:e})??e):void 0}export function chartBucketRows(t,n,o,i){const e=x(t).find(s=>s.id===n.x);if(!e)return[];const l=o.filter(s=>s!=null).map(s=>({row:s,keys:K(e,s)})),{label:r}=P(e,[...new Set(l.flatMap(s=>s.keys))]);return l.filter(s=>s.keys.some(d=>r(d)===i)).map(s=>s.row)}
@@ -1 +1 @@
1
- import{attachmentsFromText as F,attachmentsText as D,toAttachments as M}from"./attachments.js";import{dateFromParts as B,numberFromText as b,numberKind as E,parseDateText as O,parseDuration as V}from"./format.js";import{fillFieldColumn as I,getFieldType as _}from"./registry.svelte.js";import{splitNames as d}from"./name-list.js";import{checklistText as U,toChecklist as A}from"./checklist.js";import{parseColor as Y}from"./color-value.js";import{richLines as $,richPlain as j}from"./rich-html.js";import{toRichHtml as q}from"./rich-html-write.js";import{parseTimeOfDay as z,timeFromSeconds as R}from"./time-of-day.js";import{findFieldUser as H,getFieldUsers as f,getLinkedTable as S,resolveLinkId as J,resolveLinkIds as K}from"./sources.svelte.js";import{sparklineValues as W,voteCount as X,voteIds as w}from"./vote.js";const T=new Set(["text","longText","url","email","phone","barcode"]),y=new Set(["formula","lookup","rollup","count","createdTime","lastModifiedTime","createdBy","lastModifiedBy","autoNumber","button"]),x=new Set(["number","currency","percent","rating"]);export const keepsStoredValues=t=>y.has(t),isEmptyValue=t=>t==null||t===""||Array.isArray(t)&&t.length===0||typeof t=="number"&&Number.isNaN(t);export function asText(t,n){return t==null?"":n==="attachment"?D(t):n==="checklist"?U(t):n==="richText"?j(t):Array.isArray(t)?t.map(r=>asText(r)).filter(Boolean).join(", "):t instanceof Date?h(t):String(t)}const h=t=>`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`;function l(t){const n=String(t??"").trim().toLowerCase();return n?f().find(r=>r.id.toLowerCase()===n||r.name.toLowerCase()===n||r.email?.toLowerCase()===n)?.id:void 0}const g=(t,n)=>Array.isArray(t)?t.map(r=>asText(r).trim()).filter(Boolean):d(asText(t,n));function G(t,n,r){if(!f().length)return Array.isArray(t)?t.map(s=>asText(s)):asText(t,n)||null;const e=Array.isArray(t)?void 0:l(asText(t,n)),i=[...new Set(e?[e]:g(t,n).map(l).filter(s=>!!s))];return r?i.length?i:null:i[0]??null}function Q(t,n,r){const e={...r,separators:"comma-period"},i=E(n,e),s=b(t,i,e);if(s!=null)return s;const c=t.replace(/[^0-9.eE+-]/g,"");return/\d/.test(c)?b(c,i,e)??(Number.isFinite(Number(c))?Number(c):null):null}function k(t,n){const r=t.toLowerCase(),i=(Array.isArray(n?.options)?n.options:[]).find(s=>String(s.value).toLowerCase()===r||s.label!=null&&String(s.label).toLowerCase()===r);return i?i.value:t}function Z(t,n){const r=n??{},e=O(t,r);if(e)return B(e,r);const i=new Date(t);return Number.isNaN(i.getTime())?null:r.time?i.toISOString():h(i)}export function convertValue(t,n,r,e){if(y.has(r))return t;if(isEmptyValue(t))return r==="checkbox"?!1:r==="multiSelect"||r==="attachment"||r==="vote"?[]:null;if(n===r)return t;if(n==="vote"&&x.has(r))return X(t);if(n==="vote"&&T.has(r))return w(t).map(o=>H(o)?.name??o).join(", ");if(r==="vote"){const o=Array.isArray(t)?t:asText(t,n).split(","),a=f(),u=L=>{const m=String(L??"").trim().toLowerCase();return a.find(p=>p.id.toLowerCase()===m||p.name.toLowerCase()===m||p.email?.toLowerCase()===m)?.id};return w(o.map(u).filter(Boolean))}if(r==="sparkline"){const o=W(Array.isArray(t)?t:asText(t,n));return o.length?o:null}if(n==="richText"&&r==="longText")return $(t)||null;if(T.has(r))return asText(t,n);if(r==="richText")return q(asText(t,n),n==="longText");if(r==="duration")return typeof t=="number"?t:V(asText(t,n));if(r==="user")return G(t,n,!!e?.multiple);if(r==="link"){const o=S(e?.table),a=o?K(o,C(t,n)):[];return e?.multiple===!1?a.slice(0,1):a}if(x.has(r)){if(typeof t=="boolean")return t?1:0;const o=u=>Math.max(0,Math.min(Number(e?.max??10),Math.round(u)));if(typeof t=="number")return r==="rating"?o(t):t;if(Array.isArray(t))return t.length===1?convertValue(t[0],void 0,r,e):null;const a=Q(asText(t,n),r,e);return a==null?null:r==="rating"?o(Number(a)):a}if(r==="checkbox")return typeof t=="boolean"?t:typeof t=="number"?t!==0:/^(true|yes|y|1|x|on|done|checked)$/i.test(asText(t,n).trim());if(r==="date")return t instanceof Date?Number.isNaN(t.getTime())?null:e?.time?t.toISOString():h(t):Z(asText(t,n),e);if(r==="singleSelect"){const o=(Array.isArray(t)?asText(t[0]):asText(t,n)).trim();return o?k(o,e):null}if(r==="multiSelect"){const o=Array.isArray(t)?t.map(a=>asText(a)):d(asText(t,n));return[...new Set(o.map(a=>a.trim()).filter(Boolean).map(a=>k(a,e)))]}if(r==="attachment")return n==="attachment"?M(t):F(asText(t,n));if(r==="checklist"){const o=Array.isArray(t)&&n!=="checklist"?A(t.map(a=>asText(a))):A(asText(t,n));return o.length?o:null}if(r==="color")return Y(asText(t,n));if(r==="timeOfDay")return n==="duration"&&typeof t=="number"?R(t):z(t instanceof Date?t:asText(t,n),{seconds:!!e?.showSeconds});const i=P(r,e),s=asText(t,n);if(!i)return t!==null&&typeof t=="object"?s||null:t;const c=i(s);return c===void 0?null:c}const N=new WeakMap;function P(t,n){const r=_(t);if(!r)return null;let e=N.get(r);e||N.set(r,e=new Map);const i=JSON.stringify(n??{});if(!e.has(i)){const s=I({field:"__convert",fieldType:t,fieldProps:n??{}}).valueParser;e.set(i,typeof s=="function"?c=>{try{return s({newValue:c,oldValue:null,rawInput:c})}catch{return null}}:null)}return e.get(i)}function C(t,n){return Array.isArray(t)?t.map(r=>asText(r).trim()).filter(Boolean):d(asText(t,n))}function v(t,n,r,e){if(r==="singleSelect")return Array.isArray(t)&&new Set(t.map(i=>asText(i).trim()).filter(Boolean)).size>1;if(r==="vote")return g(t,n).some(i=>!l(i));if(r==="user"){if(!f().length||!Array.isArray(t)&&l(asText(t,n)))return!1;const i=g(t,n);return i.some(s=>!l(s))||!e?.multiple&&i.length>1}if(r==="link"){const i=S(e?.table);if(!i)return!1;const s=C(t,n).map(c=>J(i,c));return s.some(c=>c==null)||e?.multiple===!1&&new Set(s).size>1}return!1}export function countCleared(t,n,r,e){if(y.has(r)||n===r)return 0;let i=0;for(const s of t)isEmptyValue(s)||(isEmptyValue(convertValue(s,n,r,e))||v(s,n,r,e))&&(i+=1);return i}export function optionsFromValues(t){const n=new Set;for(const r of t)for(const e of Array.isArray(r)?r:[r]){const i=e==null?"":String(e).trim();i&&n.add(i)}return[...n].slice(0,200).map(r=>({value:r}))}
1
+ import{attachmentsFromText as M,attachmentsText as B,toAttachments as E}from"./attachments.js";import{dateFromParts as O,formatDuration as V,numberFromText as A,numberKind as I,parseDateText as _,parseDuration as w}from"./format.js";import{fillFieldColumn as U,getFieldType as Y}from"./registry.svelte.js";import{splitNames as d}from"./name-list.js";import{checklistText as $,toChecklist as T}from"./checklist.js";import{parseColor as j}from"./color-value.js";import{richLines as q,richPlain as z}from"./rich-html.js";import{toRichHtml as R}from"./rich-html-write.js";import{parseTimeOfDay as H,timeFromSeconds as J}from"./time-of-day.js";import{findFieldUser as K,getFieldUsers as f,getLinkedTable as x,resolveLinkId as W,resolveLinkIds as X}from"./sources.svelte.js";import{sparklineValues as G,voteCount as Q,voteIds as k}from"./vote.js";import{timerSeconds as N}from"./timer.js";const y=new Set(["text","longText","url","email","phone","barcode"]),h=new Set(["formula","lookup","rollup","count","createdTime","lastModifiedTime","createdBy","lastModifiedBy","autoNumber","button"]),g=new Set(["number","currency","percent","rating"]);export const keepsStoredValues=t=>h.has(t),isEmptyValue=t=>t==null||t===""||Array.isArray(t)&&t.length===0||typeof t=="number"&&Number.isNaN(t);export function asText(t,n){return t==null?"":n==="attachment"?B(t):n==="checklist"?$(t):n==="richText"?z(t):Array.isArray(t)?t.map(r=>asText(r)).filter(Boolean).join(", "):t instanceof Date?b(t):String(t)}const b=t=>`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`;function l(t){const n=String(t??"").trim().toLowerCase();return n?f().find(r=>r.id.toLowerCase()===n||r.name.toLowerCase()===n||r.email?.toLowerCase()===n)?.id:void 0}const S=(t,n)=>Array.isArray(t)?t.map(r=>asText(r).trim()).filter(Boolean):d(asText(t,n));function Z(t,n,r){if(!f().length)return Array.isArray(t)?t.map(s=>asText(s)):asText(t,n)||null;const e=Array.isArray(t)?void 0:l(asText(t,n)),i=[...new Set(e?[e]:S(t,n).map(l).filter(s=>!!s))];return r?i.length?i:null:i[0]??null}function P(t,n,r){const e={...r,separators:"comma-period"},i=I(n,e),s=A(t,i,e);if(s!=null)return s;const a=t.replace(/[^0-9.eE+-]/g,"");return/\d/.test(a)?A(a,i,e)??(Number.isFinite(Number(a))?Number(a):null):null}function C(t,n){const r=t.toLowerCase(),i=(Array.isArray(n?.options)?n.options:[]).find(s=>String(s.value).toLowerCase()===r||s.label!=null&&String(s.label).toLowerCase()===r);return i?i.value:t}function v(t,n){const r=n??{},e=_(t,r);if(e)return O(e,r);const i=new Date(t);return Number.isNaN(i.getTime())?null:r.time?i.toISOString():b(i)}export function convertValue(t,n,r,e){if(h.has(r))return t;if(isEmptyValue(t))return r==="checkbox"?!1:r==="multiSelect"||r==="attachment"||r==="vote"?[]:null;if(n===r)return t;if(n==="vote"&&g.has(r))return Q(t);if(n==="vote"&&y.has(r))return k(t).map(o=>K(o)?.name??o).join(", ");if(n==="timer"&&(g.has(r)||r==="duration"))return N(t);if(n==="timer"&&y.has(r)){const o=N(t);return o==null?null:V(o,"h:mm:ss")}if(r==="timer")return typeof t=="number"?t:w(asText(t,n));if(r==="vote"){const o=Array.isArray(t)?t:asText(t,n).split(","),c=f(),u=F=>{const m=String(F??"").trim().toLowerCase();return c.find(p=>p.id.toLowerCase()===m||p.name.toLowerCase()===m||p.email?.toLowerCase()===m)?.id};return k(o.map(u).filter(Boolean))}if(r==="sparkline"){const o=G(Array.isArray(t)?t:asText(t,n));return o.length?o:null}if(n==="richText"&&r==="longText")return q(t)||null;if(y.has(r))return asText(t,n);if(r==="richText")return R(asText(t,n),n==="longText");if(r==="duration")return typeof t=="number"?t:w(asText(t,n));if(r==="user")return Z(t,n,!!e?.multiple);if(r==="link"){const o=x(e?.table),c=o?X(o,D(t,n)):[];return e?.multiple===!1?c.slice(0,1):c}if(g.has(r)){if(typeof t=="boolean")return t?1:0;const o=u=>Math.max(0,Math.min(Number(e?.max??10),Math.round(u)));if(typeof t=="number")return r==="rating"?o(t):t;if(Array.isArray(t))return t.length===1?convertValue(t[0],void 0,r,e):null;const c=P(asText(t,n),r,e);return c==null?null:r==="rating"?o(Number(c)):c}if(r==="checkbox")return typeof t=="boolean"?t:typeof t=="number"?t!==0:/^(true|yes|y|1|x|on|done|checked)$/i.test(asText(t,n).trim());if(r==="date")return t instanceof Date?Number.isNaN(t.getTime())?null:e?.time?t.toISOString():b(t):v(asText(t,n),e);if(r==="singleSelect"){const o=(Array.isArray(t)?asText(t[0]):asText(t,n)).trim();return o?C(o,e):null}if(r==="multiSelect"){const o=Array.isArray(t)?t.map(c=>asText(c)):d(asText(t,n));return[...new Set(o.map(c=>c.trim()).filter(Boolean).map(c=>C(c,e)))]}if(r==="attachment")return n==="attachment"?E(t):M(asText(t,n));if(r==="checklist"){const o=Array.isArray(t)&&n!=="checklist"?T(t.map(c=>asText(c))):T(asText(t,n));return o.length?o:null}if(r==="color")return j(asText(t,n));if(r==="timeOfDay")return n==="duration"&&typeof t=="number"?J(t):H(t instanceof Date?t:asText(t,n),{seconds:!!e?.showSeconds});const i=tt(r,e),s=asText(t,n);if(!i)return t!==null&&typeof t=="object"?s||null:t;const a=i(s);return a===void 0?null:a}const L=new WeakMap;function tt(t,n){const r=Y(t);if(!r)return null;let e=L.get(r);e||L.set(r,e=new Map);const i=JSON.stringify(n??{});if(!e.has(i)){const s=U({field:"__convert",fieldType:t,fieldProps:n??{}}).valueParser;e.set(i,typeof s=="function"?a=>{try{return s({newValue:a,oldValue:null,rawInput:a})}catch{return null}}:null)}return e.get(i)}function D(t,n){return Array.isArray(t)?t.map(r=>asText(r).trim()).filter(Boolean):d(asText(t,n))}function rt(t,n,r,e){if(r==="singleSelect")return Array.isArray(t)&&new Set(t.map(i=>asText(i).trim()).filter(Boolean)).size>1;if(r==="vote")return S(t,n).some(i=>!l(i));if(r==="user"){if(!f().length||!Array.isArray(t)&&l(asText(t,n)))return!1;const i=S(t,n);return i.some(s=>!l(s))||!e?.multiple&&i.length>1}if(r==="link"){const i=x(e?.table);if(!i)return!1;const s=D(t,n).map(a=>W(i,a));return s.some(a=>a==null)||e?.multiple===!1&&new Set(s).size>1}return!1}export function countCleared(t,n,r,e){if(h.has(r)||n===r)return 0;let i=0;for(const s of t)isEmptyValue(s)||(isEmptyValue(convertValue(s,n,r,e))||rt(s,n,r,e))&&(i+=1);return i}export function optionsFromValues(t){const n=new Set;for(const r of t)for(const e of Array.isArray(r)?r:[r]){const i=e==null?"":String(e).trim();i&&n.add(i)}return[...n].slice(0,200).map(r=>({value:r}))}
@@ -1 +1 @@
1
- import{toAttachments as c}from"./attachments.js";import{checklistText as s}from"./checklist.js";import{joinNames as l}from"./name-list.js";import{richPlain as m}from"./rich-html.js";import{findFieldUser as u,getLinkedTable as d,linkedRows as v}from"./sources.svelte.js";import{voteIds as y}from"./vote.js";const S=new Set(["user","createdBy","lastModifiedBy","link","barcode","number","currency","percent","duration","date","timeOfDay","singleSelect","color","sparkline"]);function h(e,t,n,i){if(typeof e.valueParser!="function")return!1;try{const r=e.valueParser({newValue:t,oldValue:void 0,rawInput:String(t??""),data:i,columnId:String(e.id??e.field)});return JSON.stringify(r)===JSON.stringify(n)}catch{return!1}}function g(e){if(typeof location>"u")return e;try{return new URL(e,location.href).href}catch{return e}}export function fieldCopyText(e){const t=e.column?.columnDef,n=t?.fieldType;if(n==="attachment")return c(e.value).map(r=>r.url).filter(Boolean).map(g).join(" ");if(n==="checklist")return s(e.value," ");if(n==="richText")return m(e.value);if(n==="link"){const r=d(t?.fieldProps?.table);if(r)return l(v(r,e.value).map(a=>String(a[r.primaryField]??"")))}if(n==="user"&&t?.fieldProps?.multiple){const r=Array.isArray(e.value)?e.value:e.value==null||e.value===""?[]:[e.value];return l(r.map(a=>u(a)?.name??String(a)))}if(n==="vote")return l(y(e.value).map(r=>u(r)?.name??r));if(n==="multiSelect"){const r=Array.isArray(t?.editorOptions)?t.editorOptions:[],a=o=>r.find(f=>String(f.value)===String(o))?.label??String(o);return l((Array.isArray(e.value)?e.value:e.value==null||e.value===""?[]:[e.value]).map(a))}if(typeof t?.formatter!="function")return e.value;const i=t.formatter({value:e.value,row:e.row,column:e.column});return S.has(n)||t.editable===!1||h(t,i,e.value,e.row)?i:e.value}
1
+ import{toAttachments as c}from"./attachments.js";import{checklistText as s}from"./checklist.js";import{joinNames as l}from"./name-list.js";import{richPlain as m}from"./rich-html.js";import{findFieldUser as u,getLinkedTable as d,linkedRows as v}from"./sources.svelte.js";import{voteIds as y}from"./vote.js";const S=new Set(["user","createdBy","lastModifiedBy","link","barcode","number","currency","percent","duration","timer","date","timeOfDay","singleSelect","color","sparkline"]);function h(e,t,n,a){if(typeof e.valueParser!="function")return!1;try{const r=e.valueParser({newValue:t,oldValue:void 0,rawInput:String(t??""),data:a,columnId:String(e.id??e.field)});return JSON.stringify(r)===JSON.stringify(n)}catch{return!1}}function g(e){if(typeof location>"u")return e;try{return new URL(e,location.href).href}catch{return e}}export function fieldCopyText(e){const t=e.column?.columnDef,n=t?.fieldType;if(n==="attachment")return c(e.value).map(r=>r.url).filter(Boolean).map(g).join(" ");if(n==="checklist")return s(e.value," ");if(n==="richText")return m(e.value);if(n==="link"){const r=d(t?.fieldProps?.table);if(r)return l(v(r,e.value).map(i=>String(i[r.primaryField]??"")))}if(n==="user"&&t?.fieldProps?.multiple){const r=Array.isArray(e.value)?e.value:e.value==null||e.value===""?[]:[e.value];return l(r.map(i=>u(i)?.name??String(i)))}if(n==="vote")return l(y(e.value).map(r=>u(r)?.name??r));if(n==="multiSelect"){const r=Array.isArray(t?.editorOptions)?t.editorOptions:[],i=o=>r.find(f=>String(f.value)===String(o))?.label??String(o);return l((Array.isArray(e.value)?e.value:e.value==null||e.value===""?[]:[e.value]).map(i))}if(typeof t?.formatter!="function")return e.value;const a=t.formatter({value:e.value,row:e.row,column:e.column});return S.has(n)||t.editable===!1||h(t,a,e.value,e.row)?a:e.value}
@@ -13,7 +13,7 @@ import { type FieldFilter } from './filter-model.js';
13
13
  import { type FieldColumn } from './grid-access.js';
14
14
  import { type BaseTable } from './base-tables.js';
15
15
  type Row = Record<string, unknown>;
16
- export type DashboardTileKind = 'number' | 'chart' | 'list' | 'progress';
16
+ export type DashboardTileKind = 'number' | 'chart' | 'list' | 'progress' | 'text' | 'button' | 'image' | 'divider' | 'picker';
17
17
  /** Columns x rows of the dashboard's grid a tile takes. */
18
18
  export type DashboardTileSize = '1x1' | '2x1' | '2x2';
19
19
  export type NumberAggregation = 'count' | 'sum' | 'avg' | 'min' | 'max';
@@ -44,7 +44,65 @@ export type DashboardTile = {
44
44
  limit?: number;
45
45
  /** List: the field shown beside each record's name (default: the sort field). */
46
46
  detail?: string;
47
+ /**
48
+ * Text: what it says. A line starting with "#" is a heading, a blank line
49
+ * starts a paragraph; **bold** and [words](https://...) links inside lines.
50
+ */
51
+ text?: string;
52
+ /** Button: what it says (default "Open"). */
53
+ label?: string;
54
+ /** Button: where it goes (https:, http:, mailto: or a path); opened in a new tab unless a path. Image: the picture (https:, http: or a path). */
55
+ url?: string;
56
+ /** Image: what it shows, for people who cannot see it. */
57
+ alt?: string;
58
+ /** Image: the whole picture (default), or the tile filled with it. */
59
+ fit?: 'contain' | 'cover';
60
+ /** Record picker: the fields shown of the record picked (default: the next four after its name). */
61
+ fields?: string[];
62
+ /**
63
+ * A number, chart, list or progress tile narrowed by a record picker on the
64
+ * same dashboard: once a record is picked there, only the records whose link
65
+ * field `field` holds it count.
66
+ */
67
+ pickedBy?: {
68
+ tile: string;
69
+ field: string;
70
+ };
71
+ };
72
+ /** Tiles that read no table: they say, show or link to something. */
73
+ export declare const freeTile: (kind: DashboardTileKind) => boolean;
74
+ /** A picture a tile may show: http(s), or a path on the site. */
75
+ export declare function safeImage(url: string | undefined): string | null;
76
+ /**
77
+ * A tile as it reads when a record is picked: `picks` holds each picker's
78
+ * record (by the picker's tile id). A tile narrowed by a picker with a pick
79
+ * counts only the records linked to it; any other tile is as it is.
80
+ */
81
+ export declare function narrowedTile(tile: DashboardTile, picks: Readonly<Record<string, string | undefined>>): DashboardTile;
82
+ /**
83
+ * What a tile on table `t` can be narrowed by: each record picker of the
84
+ * dashboard on a table `t` links to, with the link fields that do.
85
+ */
86
+ export declare function pickerChoices(tiles: ReadonlyArray<DashboardTile>, t: BaseTable | undefined, tables: ReadonlyArray<BaseTable>, home: string): Array<{
87
+ tile: string;
88
+ field: string;
89
+ label: string;
90
+ }>;
91
+ /** One run of a text tile's line: plain, bold, or a link. */
92
+ export type TextRun = {
93
+ text: string;
94
+ bold?: boolean;
95
+ href?: string;
96
+ };
97
+ /** A text tile's blocks: headings and paragraphs, each as runs. */
98
+ export type TextBlock = {
99
+ kind: 'heading' | 'paragraph';
100
+ runs: TextRun[];
47
101
  };
102
+ /** A link a tile may open: http(s), mailto, or a path on this site; anything else is no link. */
103
+ export declare function safeHref(url: string | undefined): string | null;
104
+ /** A text tile's text as blocks to draw (never HTML: each run is drawn as text). */
105
+ export declare function textBlocks(text: string | undefined): TextBlock[];
48
106
  export declare const TILE_KINDS: ReadonlyArray<{
49
107
  kind: DashboardTileKind;
50
108
  label: string;
@@ -98,6 +156,31 @@ export type TileResult = {
98
156
  part: number;
99
157
  whole: number;
100
158
  percent: number;
159
+ } | {
160
+ kind: 'text';
161
+ blocks: TextBlock[];
162
+ } | {
163
+ kind: 'button';
164
+ label: string;
165
+ href: string | null;
166
+ external: boolean;
167
+ } | {
168
+ kind: 'image';
169
+ src: string;
170
+ alt: string;
171
+ fit: 'contain' | 'cover';
172
+ } | {
173
+ kind: 'divider';
174
+ } | {
175
+ kind: 'picker';
176
+ table: BaseTable;
177
+ items: Array<{
178
+ id: string;
179
+ title: string;
180
+ }>;
181
+ rows: Row[];
182
+ fields: FieldColumn[];
183
+ more: boolean;
101
184
  };
102
185
  /** What a tile draws, read from the base's tables; `home` is the table the view is on. */
103
186
  export declare function tileResult(tile: DashboardTile, tables: ReadonlyArray<BaseTable>, home: string): TileResult;
@@ -1 +1 @@
1
- import{chartBucketRows as G,chartFormatter as x,chartSpec as O,chartXColumns as I,chartYColumns as k,defaultChart as C,serverChart as L,withValueGutter as T}from"./chart-view.js";import{compileFieldFilter as A,describeFieldFilter as M}from"./filter-model.js";import{fieldColumns as N}from"./grid-access.js";import{primaryOf as b,rowIdOf as y}from"./base-tables.js";import{tableFields as f}from"./automations.svelte.js";import{fieldText as h,fieldValue as v,linkNames as V}from"./base-alerts.js";import{bm as u}from"./messages.svelte.js";import{maxOf as D,minOf as E}from"../extent.js";export const TILE_KINDS=[{kind:"number",get label(){return u("viewbar.tileNumber")}},{kind:"chart",get label(){return u("viewbar.chart")}},{kind:"list",get label(){return u("viewbar.tileList")}},{kind:"progress",get label(){return u("viewbar.progress")}}],TILE_SIZES=[{size:"1x1",get label(){return u("viewbar.sizeSmall")}},{size:"2x1",get label(){return u("viewbar.sizeWide")}},{size:"2x2",get label(){return u("viewbar.sizeLarge")}}],AGGREGATIONS=[{aggregation:"count",get label(){return u("viewbar.numberOfRecords")}},{aggregation:"sum",get label(){return u("viewbar.sum")}},{aggregation:"avg",get label(){return u("viewbar.average")}},{aggregation:"min",get label(){return u("viewbar.smallest")}},{aggregation:"max",get label(){return u("viewbar.largest")}}],tileSize=e=>e.size??(e.kind==="chart"||e.kind==="list"?"2x2":"1x1");let W=0;export const newTileId=()=>`tile-${Date.now().toString(36)}-${W+=1}`;const S=new WeakMap;export function tableCtrl(e){const t=S.get(e.columns);if(t)return t;const r={internalColumns:[...f(e).values()].map(s=>s.def),allColumns:[...f(e).keys()].map(s=>({id:s})),hiddenColumns:{}};return S.set(e.columns,r),r}export const numberColumns=e=>k(tableCtrl(e)),tileFieldColumns=e=>N(tableCtrl(e)).filter(t=>t.fieldType!=="button"&&t.fieldType!=="attachment");export function tileRows(e,t){const i=e.data.filter(n=>n!=null);if(!t)return i;const r=f(e),s=A(t,(n,a)=>{const o=r.get(a);return o?v(o,n):n[a]},V);return s?i.filter(s):i}export const tileTable=(e,t,i)=>t.find(r=>r.id===(e.table||i));const R=e=>{if(e==null||e===""||typeof e=="boolean")return null;const t=Number(e);return Number.isFinite(t)?t:null};function F(e,t){const i=e?.def.formatter;if(e&&i)try{return String(i({value:t,row:{},column:{id:e.id,columnDef:e.def}})??t)}catch{}return(Math.round(t*100)/100).toLocaleString()}function U(e,t,i){const r=e.aggregation??"count";if(r==="count")return{kind:"number",value:i.length,text:i.length.toLocaleString(),records:i.length};const s=f(t).get(e.field??"");if(!s)return{kind:"missing",message:u("viewbar.chooseFieldToAddUp")};const n=i.map(o=>R(v(s,o))).filter(o=>o!=null);let a;return r==="sum"?a=n.reduce((o,l)=>o+l,0):n.length?r==="avg"?a=n.reduce((o,l)=>o+l,0)/n.length:a=r==="min"?E(n):D(n):a=null,{kind:"number",value:a,text:a==null?u("viewbar.noValues"):F(s,a),records:i.length}}function _(e,t,i){const r=e.def.groupOrder??((o,l)=>String(o).localeCompare(String(l),void 0,{numeric:!0})),s=o=>o==null||o===""||Array.isArray(o)&&!o.length,n=t.map(o=>({r:o,v:v(e,o)})),a=n.filter(o=>!s(o.v));return a.sort((o,l)=>(i?-1:1)*r(o.v,l.v)),[...a,...n.filter(o=>s(o.v))].map(o=>o.r)}function B(e,t,i){const r=f(t),s=r.get(b(t))??[...r.values()].find(c=>c.field===b(t))??[...r.values()][0],n=e.sortBy?r.get(e.sortBy):void 0,a=e.detail?r.get(e.detail):n;return{kind:"list",items:(n?_(n,i,!!e.sortDesc):i).slice(0,Math.max(1,e.limit??5)).map(c=>({id:y(t,c),title:(s?h(s,c):"")||u("viewbar.unnamedRecord"),detail:a&&a!==s?h(a,c):""})),records:i.length}}export function tileResult(e,t,i){const r=tileTable(e,t,i);if(!r)return{kind:"missing",message:u("viewbar.tileTableGone")};if(e.kind==="progress"){const l=r.data.filter(m=>m!=null).length,c=e.filter?tileRows(r,e.filter).length:l;return{kind:"progress",part:c,whole:l,percent:l?c/l:0}}const s=tileRows(r,e.filter);if(e.kind==="number")return U(e,r,s);if(e.kind==="list")return B(e,r,s);const n=tableCtrl(r),a=e.chart?O(n,e.chart,s):null;if(!a)return{kind:"missing",message:u("viewbar.chooseFieldToGroup")};const o=x(n,e.chart);return{kind:"chart",spec:T(a,o),formatValue:o,records:s.length}}export async function serverTileResult(e,t,i,r){if(e.kind==="progress"){const[o,l]=await Promise.all([r({}),i({})]);return{kind:"progress",part:l.rowCount,whole:o.rowCount,percent:o.rowCount?l.rowCount/o.rowCount:0}}if(e.kind==="number"){const o=e.aggregation??"count";if(o==="count"){const g=await i({});return{kind:"number",value:g.rowCount,text:g.rowCount.toLocaleString(),records:g.rowCount}}const l=f(t).get(e.field??"");if(!l)return{kind:"missing",message:u("viewbar.chooseFieldToAddUp")};const c=await i({needsGrandTotal:!0,aggregations:[{col:l.id,fn:o}]}),m=R(c.grandTotal?.[l.id]);return{kind:"number",value:m,text:m==null?u("viewbar.noValues"):F(l,m),records:c.rowCount}}if(e.kind==="list"){const o=e.sortBy?f(t).get(e.sortBy):void 0,l=await i({startRow:0,endRow:Math.max(1,e.limit??5),sorting:o?[{id:o.id,desc:!!e.sortDesc}]:[]}),c=[...l.rows];return{...B({...e,sortBy:void 0,detail:e.detail??e.sortBy},t,c),records:l.rowCount,rows:c}}const s=tableCtrl(t);if(!e.chart)return{kind:"missing",message:u("viewbar.chooseFieldToGroup")};const n=await L(s,e.chart,i);if(!n.spec)return{kind:"missing",message:u("viewbar.chooseFieldToGroup")};const a=x(s,e.chart);return z.set(e,n.buckets),{kind:"chart",spec:T(n.spec,a),formatValue:a,records:n.records}}const z=new WeakMap;export async function serverTileRecords(e,t,i,r,s){const n=tileRecords(e,[{...t,data:[]}],t.id,r);if(!n)return null;const a=r!=null?z.get(e)?.get(r):void 0,o=await i({startRow:0,endRow:200,...a?{conditions:a}:{}}),l=c=>tileRecords({...e,filter:void 0,kind:e.kind==="chart"?"number":e.kind},[{...t,data:c}],t.id)?.items??[];return{...n,items:l([...o.rows]),total:o.rowCount,...s?{list:{slot:s.slot("drill",{blockSize:50,total:o.rowCount,...a?{conditions:a}:{}}),item:c=>l([c])[0]}}:{}}}export function tileRecords(e,t,i,r,s=3){const n=tileTable(e,t,i);if(!n)return null;let a=tileRows(n,e.filter),o;e.kind==="chart"&&e.chart&&r!=null&&(a=G(tableCtrl(n),e.chart,a,r),o={field:f(n).get(e.chart.x)?.header??e.chart.x,label:r});const l=tileFieldColumns(n),c=l.find(d=>d.field===b(n))??l[0],m=[e.field,e.chart?.y,e.sortBy,e.detail].map(d=>l.find(w=>w.id===d)).filter(d=>!!d),g=new Set([c?.id,o?e.chart?.x:void 0]),p=[];for(const d of[...m,...l])p.length<s&&!g.has(d.id)&&!p.includes(d)&&p.push(d);return{table:n,items:a.map(d=>({id:y(n,d),title:(c?h(c,d):"")||u("viewbar.unnamedRecord"),cells:p.map(w=>h(w,d))})),fields:p.map(d=>d.header),...o?{bucket:o}:{}}}export function tileTitle(e,t,i){if(e.title?.trim())return e.title.trim();const r=tileTable(e,t,i);if(!r)return u("viewbar.tile");const s=n=>n?f(r).get(n)?.header:void 0;if(e.kind==="number"){const n=e.aggregation??"count",a=s(e.field);return n==="count"||!a?r.name:u(n==="sum"?"viewbar.titleTotal":n==="avg"?"viewbar.titleAverage":n==="min"?"viewbar.titleSmallest":"viewbar.titleLargest",{field:a})}if(e.kind==="chart"){const n=s(e.chart?.x),a=s(e.chart?.y);return n?u("viewbar.titleBy",{value:a??r.name,field:n}):r.name}if(e.kind==="list"){const n=s(e.sortBy);return n?u("viewbar.titleBy",{value:r.name,field:n}):r.name}return e.filter?M(e.filter,n=>s(n)??n):r.name}export function newTile(e,t,i){const r={id:newTileId(),kind:e,...t&&t.id!==i?{table:t.id}:{}};if(!t)return r;if(e==="number")return{...r,aggregation:"count"};if(e==="chart"){const s=C(tableCtrl(t));return s?{...r,chart:s}:r}if(e==="list"){const s=tileFieldColumns(t).find(n=>n.field===b(t))??tileFieldColumns(t)[0];return{...r,...s?{sortBy:s.id}:{},limit:5}}return r}export function starterTiles(e){const t=C(e);return[{id:newTileId(),kind:"number",aggregation:"count"},...t?[{id:newTileId(),kind:"chart",chart:t}]:[]]}export const tileChartColumns=e=>({x:I(tableCtrl(e)),y:k(tableCtrl(e))});export function putTile(e,t){return e.some(i=>i.id===t.id)?e.map(i=>i.id===t.id?t:i):[...e,t]}export const removeTile=(e,t)=>e.filter(i=>i.id!==t);export function moveTile(e,t,i){const r=[...e];if(t<0||t>=r.length)return r;const[s]=r.splice(t,1);return r.splice(Math.max(0,Math.min(r.length,i)),0,s),r}
1
+ import{chartBucketRows as W,chartFormatter as y,chartSpec as E,chartXColumns as L,chartYColumns as T,defaultChart as C,serverChart as M,withValueGutter as S}from"./chart-view.js";import{compileFieldFilter as D,describeFieldFilter as N}from"./filter-model.js";import{fieldColumns as V}from"./grid-access.js";import{primaryOf as p,rowIdOf as x}from"./base-tables.js";import{tableFields as m}from"./automations.svelte.js";import{fieldText as h,fieldValue as v,linkNames as j}from"./base-alerts.js";import{bm as l}from"./messages.svelte.js";import{maxOf as P,minOf as _}from"../extent.js";export const freeTile=e=>e==="text"||e==="button"||e==="image"||e==="divider";export function safeImage(e){const t=(e??"").trim();return t&&(/^https?:\/\//i.test(t)||t.startsWith("/")&&!t.startsWith("//"))?t:null}export function narrowedTile(e,t){const i=e.pickedBy,r=i?t[i.tile]:void 0;if(!i||!r)return e;const o={column:i.field,kind:"linked",op:"hasAnyOf",value:[r]},n=e.filter&&e.filter.conditions.length?{kind:"fieldFilter",conjunction:"and",conditions:[{conjunction:e.filter.conjunction,conditions:e.filter.conditions},o]}:{kind:"fieldFilter",conjunction:"and",conditions:[o]};return{...e,filter:n}}export function pickerChoices(e,t,i,r){if(!t)return[];const o=[];for(const n of e){if(n.kind!=="picker")continue;const u=n.table||r,s=tileTitle(n,i,r);for(const a of t.columns)a.fieldType==="link"&&String(a.fieldProps?.table??"")===String(u)&&o.push({tile:n.id,field:String(a.id??a.field),label:l("viewbar.narrowOption",{picker:s,field:String(a.header??a.field)})})}return o}export function safeHref(e){const t=(e??"").trim();return t&&(/^(https?:\/\/|mailto:)/i.test(t)||t.startsWith("/")&&!t.startsWith("//"))?t:null}function R(e){const t=[],i=/\*\*(.+?)\*\*|\[([^\]]+)\]\(([^)\s]+)\)/g;let r=0,o;for(;o=i.exec(e);){if(o.index>r&&t.push({text:e.slice(r,o.index)}),o[1]!=null)t.push({text:o[1],bold:!0});else{const n=safeHref(o[3]);t.push(n?{text:o[2],href:n}:{text:o[2]})}r=o.index+o[0].length}return r<e.length&&t.push({text:e.slice(r)}),t}export function textBlocks(e){const t=[];let i=[];const r=()=>{i.length&&t.push({kind:"paragraph",runs:R(i.join(" "))}),i=[]};for(const o of(e??"").split(/\r?\n/)){const n=o.trim();n?n.startsWith("#")?(r(),t.push({kind:"heading",runs:R(n.replace(/^#+\s*/,""))})):i.push(n):r()}return r(),t}export const TILE_KINDS=[{kind:"number",get label(){return l("viewbar.tileNumber")}},{kind:"chart",get label(){return l("viewbar.chart")}},{kind:"list",get label(){return l("viewbar.tileList")}},{kind:"progress",get label(){return l("viewbar.progress")}},{kind:"text",get label(){return l("viewbar.tileText")}},{kind:"button",get label(){return l("viewbar.tileButton")}},{kind:"image",get label(){return l("viewbar.tileImage")}},{kind:"divider",get label(){return l("viewbar.tileDivider")}},{kind:"picker",get label(){return l("viewbar.tilePicker")}}],TILE_SIZES=[{size:"1x1",get label(){return l("viewbar.sizeSmall")}},{size:"2x1",get label(){return l("viewbar.sizeWide")}},{size:"2x2",get label(){return l("viewbar.sizeLarge")}}],AGGREGATIONS=[{aggregation:"count",get label(){return l("viewbar.numberOfRecords")}},{aggregation:"sum",get label(){return l("viewbar.sum")}},{aggregation:"avg",get label(){return l("viewbar.average")}},{aggregation:"min",get label(){return l("viewbar.smallest")}},{aggregation:"max",get label(){return l("viewbar.largest")}}],tileSize=e=>e.size??(e.kind==="chart"||e.kind==="list"||e.kind==="picker"?"2x2":e.kind==="text"||e.kind==="image"||e.kind==="divider"?"2x1":"1x1");let K=0;export const newTileId=()=>`tile-${Date.now().toString(36)}-${K+=1}`;const B=new WeakMap;export function tableCtrl(e){const t=B.get(e.columns);if(t)return t;const r={internalColumns:[...m(e).values()].map(o=>o.def),allColumns:[...m(e).keys()].map(o=>({id:o})),hiddenColumns:{}};return B.set(e.columns,r),r}export const numberColumns=e=>T(tableCtrl(e)),tileFieldColumns=e=>V(tableCtrl(e)).filter(t=>t.fieldType!=="button"&&t.fieldType!=="attachment");export function tileRows(e,t){const i=e.data.filter(n=>n!=null);if(!t)return i;const r=m(e),o=D(t,(n,u)=>{const s=r.get(u);return s?v(s,n):n[u]},j);return o?i.filter(o):i}export const tileTable=(e,t,i)=>t.find(r=>r.id===(e.table||i));function F(e){if(e.kind==="divider")return{kind:"divider"};if(e.kind==="image"){const i=safeImage(e.url);return i?{kind:"image",src:i,alt:e.alt?.trim()??"",fit:e.fit==="cover"?"cover":"contain"}:{kind:"missing",message:l("viewbar.tileImageEmpty")}}if(e.kind==="text"){const i=textBlocks(e.text);return i.length?{kind:"text",blocks:i}:{kind:"missing",message:l("viewbar.tileTextEmpty")}}const t=safeHref(e.url);return t?{kind:"button",label:e.label?.trim()||l("viewbar.tileButtonDefault"),href:t,external:!t.startsWith("/")}:{kind:"missing",message:l("viewbar.tileButtonEmpty")}}const O=e=>{if(e==null||e===""||typeof e=="boolean")return null;const t=Number(e);return Number.isFinite(t)?t:null};function I(e,t){const i=e?.def.formatter;if(e&&i)try{return String(i({value:t,row:{},column:{id:e.id,columnDef:e.def}})??t)}catch{}return(Math.round(t*100)/100).toLocaleString()}function U(e,t,i){const r=e.aggregation??"count";if(r==="count")return{kind:"number",value:i.length,text:i.length.toLocaleString(),records:i.length};const o=m(t).get(e.field??"");if(!o)return{kind:"missing",message:l("viewbar.chooseFieldToAddUp")};const n=i.map(s=>O(v(o,s))).filter(s=>s!=null);let u;return r==="sum"?u=n.reduce((s,a)=>s+a,0):n.length?r==="avg"?u=n.reduce((s,a)=>s+a,0)/n.length:u=r==="min"?_(n):P(n):u=null,{kind:"number",value:u,text:u==null?l("viewbar.noValues"):I(o,u),records:i.length}}function X(e,t,i){const r=e.def.groupOrder??((s,a)=>String(s).localeCompare(String(a),void 0,{numeric:!0})),o=s=>s==null||s===""||Array.isArray(s)&&!s.length,n=t.map(s=>({r:s,v:v(e,s)})),u=n.filter(s=>!o(s.v));return u.sort((s,a)=>(i?-1:1)*r(s.v,a.v)),[...u,...n.filter(s=>o(s.v))].map(s=>s.r)}function z(e,t,i){const r=m(t),o=r.get(p(t))??[...r.values()].find(c=>c.field===p(t))??[...r.values()][0],n=e.sortBy?r.get(e.sortBy):void 0,u=e.detail?r.get(e.detail):n;return{kind:"list",items:(n?X(n,i,!!e.sortDesc):i).slice(0,Math.max(1,e.limit??5)).map(c=>({id:x(t,c),title:(o?h(o,c):"")||l("viewbar.unnamedRecord"),detail:u&&u!==o?h(u,c):""})),records:i.length}}const w=500;function A(e,t,i,r){const o=m(t),n=tileFieldColumns(t),u=o.get(p(t))??n.find(d=>d.field===p(t))??n[0],s=e.fields?.length?e.fields.map(d=>n.find(g=>g.id===d)).filter(d=>!!d):n.filter(d=>d.id!==u?.id).slice(0,4),a=i.slice(0,w),c=a.map(d=>({id:x(t,d),title:(u?h(u,d):"")||l("viewbar.unnamedRecord")}));return{kind:"picker",table:t,items:c,rows:a,fields:s,more:r||i.length>w}}export function tileResult(e,t,i){if(freeTile(e.kind))return F(e);const r=tileTable(e,t,i);if(!r)return{kind:"missing",message:l("viewbar.tileTableGone")};if(e.kind==="picker")return A(e,r,r.data.filter(a=>a!=null),!1);if(e.kind==="progress"){const a=r.data.filter(d=>d!=null).length,c=e.filter?tileRows(r,e.filter).length:a;return{kind:"progress",part:c,whole:a,percent:a?c/a:0}}const o=tileRows(r,e.filter);if(e.kind==="number")return U(e,r,o);if(e.kind==="list")return z(e,r,o);const n=tableCtrl(r),u=e.chart?E(n,e.chart,o):null;if(!u)return{kind:"missing",message:l("viewbar.chooseFieldToGroup")};const s=y(n,e.chart);return{kind:"chart",spec:S(u,s),formatValue:s,records:o.length}}export async function serverTileResult(e,t,i,r){if(freeTile(e.kind))return F(e);if(e.kind==="picker"){const s=await i({startRow:0,endRow:w,sorting:[]});return A(e,t,[...s.rows],s.rowCount>w)}if(e.kind==="progress"){const[s,a]=await Promise.all([r({}),i({})]);return{kind:"progress",part:a.rowCount,whole:s.rowCount,percent:s.rowCount?a.rowCount/s.rowCount:0}}if(e.kind==="number"){const s=e.aggregation??"count";if(s==="count"){const g=await i({});return{kind:"number",value:g.rowCount,text:g.rowCount.toLocaleString(),records:g.rowCount}}const a=m(t).get(e.field??"");if(!a)return{kind:"missing",message:l("viewbar.chooseFieldToAddUp")};const c=await i({needsGrandTotal:!0,aggregations:[{col:a.id,fn:s}]}),d=O(c.grandTotal?.[a.id]);return{kind:"number",value:d,text:d==null?l("viewbar.noValues"):I(a,d),records:c.rowCount}}if(e.kind==="list"){const s=e.sortBy?m(t).get(e.sortBy):void 0,a=await i({startRow:0,endRow:Math.max(1,e.limit??5),sorting:s?[{id:s.id,desc:!!e.sortDesc}]:[]}),c=[...a.rows];return{...z({...e,sortBy:void 0,detail:e.detail??e.sortBy},t,c),records:a.rowCount,rows:c}}const o=tableCtrl(t);if(!e.chart)return{kind:"missing",message:l("viewbar.chooseFieldToGroup")};const n=await M(o,e.chart,i);if(!n.spec)return{kind:"missing",message:l("viewbar.chooseFieldToGroup")};const u=y(o,e.chart);return G.set(e,n.buckets),{kind:"chart",spec:S(n.spec,u),formatValue:u,records:n.records}}const G=new WeakMap;export async function serverTileRecords(e,t,i,r,o){const n=tileRecords(e,[{...t,data:[]}],t.id,r);if(!n)return null;const u=r!=null?G.get(e)?.get(r):void 0,s=await i({startRow:0,endRow:200,...u?{conditions:u}:{}}),a=c=>tileRecords({...e,filter:void 0,kind:e.kind==="chart"?"number":e.kind},[{...t,data:c}],t.id)?.items??[];return{...n,items:a([...s.rows]),total:s.rowCount,...o?{list:{slot:o.slot("drill",{blockSize:50,total:s.rowCount,...u?{conditions:u}:{}}),item:c=>a([c])[0]}}:{}}}export function tileRecords(e,t,i,r,o=3){if(freeTile(e.kind)||e.kind==="picker")return null;const n=tileTable(e,t,i);if(!n)return null;let u=tileRows(n,e.filter),s;e.kind==="chart"&&e.chart&&r!=null&&(u=W(tableCtrl(n),e.chart,u,r),s={field:m(n).get(e.chart.x)?.header??e.chart.x,label:r});const a=tileFieldColumns(n),c=a.find(f=>f.field===p(n))??a[0],d=[e.field,e.chart?.y,e.sortBy,e.detail].map(f=>a.find(k=>k.id===f)).filter(f=>!!f),g=new Set([c?.id,s?e.chart?.x:void 0]),b=[];for(const f of[...d,...a])b.length<o&&!g.has(f.id)&&!b.includes(f)&&b.push(f);return{table:n,items:u.map(f=>({id:x(n,f),title:(c?h(c,f):"")||l("viewbar.unnamedRecord"),cells:b.map(k=>h(k,f))})),fields:b.map(f=>f.header),...s?{bucket:s}:{}}}export function tileTitle(e,t,i){if(e.title?.trim())return e.title.trim();if(freeTile(e.kind))return"";const r=tileTable(e,t,i);if(!r)return l("viewbar.tile");const o=n=>n?m(r).get(n)?.header:void 0;if(e.kind==="number"){const n=e.aggregation??"count",u=o(e.field);return n==="count"||!u?r.name:l(n==="sum"?"viewbar.titleTotal":n==="avg"?"viewbar.titleAverage":n==="min"?"viewbar.titleSmallest":"viewbar.titleLargest",{field:u})}if(e.kind==="chart"){const n=o(e.chart?.x),u=o(e.chart?.y);return n?l("viewbar.titleBy",{value:u??r.name,field:n}):r.name}if(e.kind==="list"){const n=o(e.sortBy);return n?l("viewbar.titleBy",{value:r.name,field:n}):r.name}return e.filter?N(e.filter,n=>o(n)??n):r.name}export function newTile(e,t,i){if(e==="text")return{id:newTileId(),kind:e,text:""};if(e==="button")return{id:newTileId(),kind:e,label:"",url:""};if(e==="image")return{id:newTileId(),kind:e,url:"",alt:""};if(e==="divider")return{id:newTileId(),kind:e};const r={id:newTileId(),kind:e,...t&&t.id!==i?{table:t.id}:{}};if(!t)return r;if(e==="number")return{...r,aggregation:"count"};if(e==="chart"){const o=C(tableCtrl(t));return o?{...r,chart:o}:r}if(e==="list"){const o=tileFieldColumns(t).find(n=>n.field===p(t))??tileFieldColumns(t)[0];return{...r,...o?{sortBy:o.id}:{},limit:5}}return r}export function starterTiles(e){const t=C(e);return[{id:newTileId(),kind:"number",aggregation:"count"},...t?[{id:newTileId(),kind:"chart",chart:t}]:[]]}export const tileChartColumns=e=>({x:L(tableCtrl(e)),y:T(tableCtrl(e))});export function putTile(e,t){return e.some(i=>i.id===t.id)?e.map(i=>i.id===t.id?t:i):[...e,t]}export const removeTile=(e,t)=>e.filter(i=>i.id!==t);export function moveTile(e,t,i){const r=[...e];if(t<0||t>=r.length)return r;const[o]=r.splice(t,1);return r.splice(Math.max(0,Math.min(r.length,i)),0,o),r}
@@ -1 +1 @@
1
- import{convertValue as k,countCleared as M,keepsStoredValues as V,optionsFromValues as E}from"./convert.js";import{renameFormulaRefs as W}from"./formula.js";import{renamePromptRefs as $}from"./ai-prompt.js";import{isGroup as q}from"./filter-model.js";import{fieldPropsOf as h,fillFieldColumn as w,getFieldType as S,originalColumn as f}from"./registry.svelte.js";import{getLinkedTable as j,linkedRows as B}from"./sources.svelte.js";import{SELECT_TYPES as g,changedValue as I,filterWithOptions as K,optionChanges as F,optionUse as _,rowsWithOptions as z,touches as G}from"./select-options.js";const H=["editorType","cellDataType","format","align","editorOptions","editorMultiple","formatter","valueParser"];export const defId=e=>String(e.id??e.field??"");export function plainDef(e){return{...f(e)}}export const plainColumns=e=>e.internalColumns.map(o=>plainDef(o));export function uniqueId(e,o){const i=new Set([...o,"id"]),n=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"field";let t=n;for(let r=2;i.has(t);r++)t=`${n}_${r}`;return t}export function moveFieldKey(e,o,i){e.internalColumns=m(e.internalColumns.map(n=>f(n).id===o?{...f(n),id:i,field:i}:n))}export function nameTaken(e,o,i){const n=o.trim().toLowerCase();return e.internalColumns.some(t=>defId(t)!==i&&String(t.header??"").trim().toLowerCase()===n)}function T(e){const o={};for(const[i,n]of Object.entries(e))n!==void 0&&n!==""&&!(Array.isArray(n)&&n.length===0&&i!=="options"&&i!=="editors")&&(o[i]=n);return o}function m(e){return e.map(o=>f(o).fieldType?w(f(o),e):o)}function P(e,o){if(typeof requestAnimationFrame!="function")return;const i=n=>n.querySelector(`[data-svgrid-header-col="${o}"]`);requestAnimationFrame(()=>{const n=e.scrollContainer;if(!n)return;const t=i(n);if(t)return b(n,t);const r=N(e,o);r!=null&&(n.scrollLeft=r-A(n),requestAnimationFrame(()=>{const l=i(n);l&&b(n,l)}))})}function N(e,o){let i=e.systemColumnsWidth??0;for(const n of e.allColumns??[])if(i+=e.getColumnWidth?.(n.id)??0,n.id===o)return i;return null}function A(e){const o=e.querySelector(".sv-field-column-adder")?.offsetWidth??0;return e.clientWidth-(parseFloat(getComputedStyle(e).paddingRight)||0)-o}function b(e,o){const i=e.getBoundingClientRect(),n=o.getBoundingClientRect(),t=i.left+A(e);n.right>t?e.scrollLeft+=Math.min(n.right-t,n.left-i.left):n.left<i.left&&(e.scrollLeft-=i.left-n.left)}function D(e,o,i){const n=e.slice();return n.splice(i==="end"?n.length:Math.max(0,Math.min(i,n.length)),0,o),n}function x(e){Array.isArray(e.options)&&(e.options=e.options.map(o=>({...o,value:String(o.value??"").trim()})).filter(o=>o.value))}function Q(e,o){const i=e.editedCellValues;if(!i)return;const n=`:${o}`,t=Object.entries(i).filter(([r])=>!r.endsWith(n));t.length!==Object.keys(i).length&&(e.editedCellValues=Object.fromEntries(t))}export function addField(e,o,i="end"){const n=uniqueId(o.name,e.internalColumns.map(defId)),t=S(o.fieldType),r=T(o.fieldProps);x(r);const l={id:n,field:n,header:o.name.trim(),width:t?.width??150,fieldType:o.fieldType,fieldProps:r,...o.description?.trim()?{description:o.description.trim()}:{}};let s;const a=e.props.rowModel?void 0:t?.onCreate?.({props:h(l),field:n,rows:e.internalData});return a&&(s=e.internalData.map((u,d)=>u==null?u:{...u,[n]:a[d]}),e.internalData=s),e.internalColumns=m(D(e.internalColumns,l,i)),e.props.onColumnAdd?.({column:l,columns:plainColumns(e),...s?{data:s}:{}}),P(e,n),l}let v=0,y=0;const U=36**3;export function newRecordId(){let e=Math.max(Date.now(),v);e===v?y+=1:y=0,y>=U&&(e+=1,y=0),v=e;const o=Math.floor(Math.random()*36**4).toString(36).padStart(4,"0");return`rec${e.toString(36).padStart(9,"0")}${y.toString(36).padStart(3,"0")}${o}`}export function newRowValues(e,o={}){const i={};for(const n of e.internalColumns){const t=f(n);if(!t.fieldType||!n.field)continue;const r=String(n.field),l=h(t),s=S(t.fieldType)?.newRowValue?.({props:l,field:r,rows:e.internalData}),a=s!==void 0?s:l.default;a!==void 0&&(i[r]=Array.isArray(a)?a.slice():a)}return!("id"in o)&&(e.internalData??[]).some(n=>n&&typeof n=="object"&&"id"in n)&&(i.id=newRecordId()),{...i,...o}}const Y=new Set(["autoNumber","createdTime","createdBy","lastModifiedTime","lastModifiedBy"]),J=e=>Y.has(String(e))||S(e)?.copy===!1;export function recordCopyValues(e,o){const i={};for(const n of e.internalColumns){const t=f(n);if(!n.field||n.fieldFn||t.fieldFn||t.recordKey===!0||J(t.fieldType))continue;const r=o[String(n.field)];r!==void 0&&(i[String(n.field)]=Array.isArray(r)?r.slice():r)}return i}function R(e,o,i){const n=String(o.field),t=e.internalData.map(s=>s?.[n]);if(V(i))return t;const r=f(o),l=(r.fieldType?w(r,e.internalColumns):o).fieldFn;if(typeof l=="function")return e.internalData.map(s=>{if(s==null)return;const a=l(s);return a==="#ERROR"?null:a});if(r.fieldType==="link"&&i!=="link"){const s=j(h(r).table);if(s)return t.map(a=>B(s,a).map(u=>u[s.primaryField]).filter(u=>u!=null&&u!==""))}return t}export function previewChange(e,o,i){const n=e.internalColumns.find(t=>defId(t)===o);return!n||n.fieldType===i.fieldType||!n.field?0:M(R(e,n,i.fieldType),n.fieldType,i.fieldType,T(i.fieldProps))}export function previewOptions(e,o,i){const n=e.internalColumns.find(r=>defId(r)===o);if(!n||!g.has(n.fieldType)||!g.has(i.fieldType))return null;const t={...i.fieldProps};return x(t),F(h(f(n)).options,t.options)}export function optionRecords(e,o,i){const n=e.internalColumns.find(t=>defId(t)===o)?.field;return _(e.internalData,String(n),i)}function X(e,o,i,n){const t=i.trim().toLowerCase();return!t||t===n.trim().toLowerCase()?e:e.map(r=>{const l=f(r);if(String(l.field??l.id)===o)return r;if(l.fieldType==="ai"){const u=String(l.fieldProps?.prompt??""),d=$(u,c=>c.trim().toLowerCase()===t?n:null);return d===u?r:{...l,fieldProps:{...l.fieldProps,prompt:d}}}if(l.fieldType!=="formula")return r;const s=String(l.fieldProps?.formula??""),a=W(s,u=>u.trim().toLowerCase()===t?n:null);return a===s?r:{...l,fieldProps:{...l.fieldProps,formula:a}}})}export function updateField(e,o,i){const n=e.internalColumns.findIndex(p=>defId(p)===o);if(n<0)return null;const t=plainDef(e.internalColumns[n]);t.recordKey===!0&&(i={...i,fieldType:String(t.fieldType),fieldProps:{...t.fieldProps??{}}});const r=t.fieldType!==i.fieldType,l=T(i.fieldProps);x(l);let s;if(r&&t.field){const p=String(t.field),L=R(e,e.internalColumns[n],i.fieldType);s=e.internalData.map((C,O)=>C==null?C:{...C,[p]:k(L[O],t.fieldType,i.fieldType,l)}),(i.fieldType==="singleSelect"||i.fieldType==="multiSelect")&&!l.options?.length&&(l.options=E(s.map(C=>C?.[p])))}const a=g.has(t.fieldType)&&g.has(i.fieldType)?F(t.fieldProps?.options,l.options):null;a&&G(l.default,a)&&(l.default=I(l.default,a)),a&&t.field&&!e.props.rowModel&&!e.props.baseFeed&&(s=z(s??e.internalData,String(t.field),a));const u={...t};if(r)for(const p of H)delete u[p];const d={...u,header:i.name.trim(),fieldType:i.fieldType,fieldProps:l};i.description?.trim()?d.description=i.description.trim():delete d.description;let c=e.internalColumns.slice();if(c[n]=d,typeof t.header=="string"&&t.field&&(c=X(c,String(t.field),t.header,String(d.header))),e.internalColumns=m(c),s&&(e.internalData=s,Q(e,o)),a){const p=K(e.advancedFilter,o,a);p!==e.advancedFilter&&e.buildApi?.()?.setAdvancedFilter?.(p)}return e.props.onColumnChange?.({column:d,previous:t,columns:plainColumns(e),...s?{data:s}:{},...a?{options:a}:{}}),d}export function addSelectOptions(e,o,i){const n=e.internalColumns.findIndex(u=>defId(u)===o);if(n<0||!i.length)return null;const t=plainDef(e.internalColumns[n]),r=Array.isArray(t.fieldProps?.options)?t.fieldProps.options.slice():[],l=new Set(r.map(u=>String(u.value)));for(const u of i)l.has(u.value)||(l.add(u.value),r.push({...u}));const s={...t,fieldProps:{...t.fieldProps,options:r}},a=e.internalColumns.slice();return a[n]=s,e.internalColumns=m(a),e.props.onColumnChange?.({column:s,previous:t,columns:plainColumns(e)}),s}export function setFieldSummary(e,o,i){const n=e.internalColumns.findIndex(a=>defId(a)===o);if(n<0)return null;const t=plainDef(e.internalColumns[n]),r={...t.fieldProps};i==="none"?delete r.summary:r.summary=i;const l={...t,fieldProps:r},s=e.internalColumns.slice();return s[n]=l,e.internalColumns=m(s),e.props.onColumnChange?.({column:l,previous:t,columns:plainColumns(e)}),l}export function duplicateField(e,o){const i=e.internalColumns.findIndex(a=>defId(a)===o);if(i<0)return null;const n=plainDef(e.internalColumns[i]);n.recordKey===!0&&(delete n.recordKey,delete n.editable);const t=`${String(n.header??o)} copy`,r=uniqueId(t,e.internalColumns.map(defId)),l={...n,id:r,field:r,header:t};let s;if(n.field){const a=String(n.field);s=e.internalData.map(u=>u==null?u:{...u,[r]:Z(u[a])}),e.internalData=s}return e.internalColumns=m(D(e.internalColumns,l,i+1)),e.props.onColumnAdd?.({column:l,columns:plainColumns(e),...s?{data:s}:{}}),P(e,r),l}export function filterWithout(e,o){const i=e;if(i?.kind!=="fieldFilter")return e;const n=i.conditions.flatMap(t=>{if(!q(t))return o(t.column)?[]:[t];const r=t.conditions.filter(l=>!o(l.column));return r.length===t.conditions.length?[t]:r.length?[{...t,conditions:r}]:[]});return n.length===i.conditions.length&&n.every((t,r)=>t===i.conditions[r])?e:n.length?{...i,conditions:n}:null}export function removeField(e,o){e.internalColumns=m(e.internalColumns.filter(n=>defId(n)!==o));const i=filterWithout(e.advancedFilter,n=>n===o);i!==e.advancedFilter&&e.buildApi?.()?.setAdvancedFilter?.(i),e.props.onColumnRemove?.({columnId:o,columns:plainColumns(e)})}export function hideField(e,o){e.buildApi?.()?.setColumnVisible?.(o,!1)}export function indexBeside(e,o,i){const n=e.internalColumns.findIndex(t=>defId(t)===o);return n<0?e.internalColumns.length:i==="left"?n:n+1}function Z(e){if(e==null||typeof e!="object")return e;try{return structuredClone(e)}catch{return Array.isArray(e)?e.slice():{...e}}}
1
+ import{convertValue as k,countCleared as M,keepsStoredValues as V,optionsFromValues as E}from"./convert.js";import{renameFormulaRefs as W}from"./formula.js";import{renamePromptRefs as $}from"./ai-prompt.js";import{isGroup as q}from"./filter-model.js";import{fieldPropsOf as h,fillFieldColumn as w,getFieldType as S,originalColumn as m}from"./registry.svelte.js";import{getLinkedTable as j,linkedRows as B}from"./sources.svelte.js";import{SELECT_TYPES as g,changedValue as I,filterWithOptions as K,optionChanges as F,optionUse as _,rowsWithOptions as z,touches as G}from"./select-options.js";const H=["editorType","cellDataType","format","align","editorOptions","editorMultiple","formatter","valueParser"];export const defId=e=>String(e.id??e.field??"");export function plainDef(e){return{...m(e)}}export const plainColumns=e=>e.internalColumns.map(o=>plainDef(o));export function uniqueId(e,o){const i=new Set([...o,"id"]),n=e.trim().toLowerCase().replace(/[^a-z0-9]+/g,"_").replace(/^_+|_+$/g,"")||"field";let t=n;for(let r=2;i.has(t);r++)t=`${n}_${r}`;return t}export function moveFieldKey(e,o,i){e.internalColumns=c(e.internalColumns.map(n=>m(n).id===o?{...m(n),id:i,field:i}:n))}export function nameTaken(e,o,i){const n=o.trim().toLowerCase();return e.internalColumns.some(t=>defId(t)!==i&&String(t.header??"").trim().toLowerCase()===n)}function T(e){const o={};for(const[i,n]of Object.entries(e))n!==void 0&&n!==""&&!(Array.isArray(n)&&n.length===0&&i!=="options"&&i!=="editors")&&(o[i]=n);return o}function c(e){return e.map(o=>m(o).fieldType?w(m(o),e):o)}function A(e,o){if(typeof requestAnimationFrame!="function")return;const i=n=>n.querySelector(`[data-svgrid-header-col="${o}"]`);requestAnimationFrame(()=>{const n=e.scrollContainer;if(!n)return;const t=i(n);if(t)return b(n,t);const r=N(e,o);r!=null&&(n.scrollLeft=r-P(n),requestAnimationFrame(()=>{const l=i(n);l&&b(n,l)}))})}function N(e,o){let i=e.systemColumnsWidth??0;for(const n of e.allColumns??[])if(i+=e.getColumnWidth?.(n.id)??0,n.id===o)return i;return null}function P(e){const o=e.querySelector(".sv-field-column-adder")?.offsetWidth??0;return e.clientWidth-(parseFloat(getComputedStyle(e).paddingRight)||0)-o}function b(e,o){const i=e.getBoundingClientRect(),n=o.getBoundingClientRect(),t=i.left+P(e);n.right>t?e.scrollLeft+=Math.min(n.right-t,n.left-i.left):n.left<i.left&&(e.scrollLeft-=i.left-n.left)}function D(e,o,i){const n=e.slice();return n.splice(i==="end"?n.length:Math.max(0,Math.min(i,n.length)),0,o),n}function x(e){Array.isArray(e.options)&&(e.options=e.options.map(o=>({...o,value:String(o.value??"").trim()})).filter(o=>o.value))}function Q(e,o){const i=e.editedCellValues;if(!i)return;const n=`:${o}`,t=Object.entries(i).filter(([r])=>!r.endsWith(n));t.length!==Object.keys(i).length&&(e.editedCellValues=Object.fromEntries(t))}export function addField(e,o,i="end"){const n=uniqueId(o.name,e.internalColumns.map(defId)),t=S(o.fieldType),r=T(o.fieldProps);x(r);const l={id:n,field:n,header:o.name.trim(),width:t?.width??150,fieldType:o.fieldType,fieldProps:r,...o.description?.trim()?{description:o.description.trim()}:{}};let s;const a=h(l),u=a.default,d=e.props.rowModel?void 0:t?.onCreate?.({props:a,field:n,rows:e.internalData})??(u!==void 0?e.internalData.map(()=>Array.isArray(u)?u.slice():u):void 0);return d&&(s=e.internalData.map((p,f)=>p==null?p:{...p,[n]:d[f]}),e.internalData=s),e.internalColumns=c(D(e.internalColumns,l,i)),e.props.onColumnAdd?.({column:l,columns:plainColumns(e),...s?{data:s}:{}}),A(e,n),l}let v=0,C=0;const U=36**3;export function newRecordId(){let e=Math.max(Date.now(),v);e===v?C+=1:C=0,C>=U&&(e+=1,C=0),v=e;const o=Math.floor(Math.random()*36**4).toString(36).padStart(4,"0");return`rec${e.toString(36).padStart(9,"0")}${C.toString(36).padStart(3,"0")}${o}`}export function newRowValues(e,o={}){const i={};for(const n of e.internalColumns){const t=m(n);if(!t.fieldType||!n.field)continue;const r=String(n.field),l=h(t),s=S(t.fieldType)?.newRowValue?.({props:l,field:r,rows:e.internalData}),a=s!==void 0?s:l.default;a!==void 0&&(i[r]=Array.isArray(a)?a.slice():a)}return!("id"in o)&&(e.internalData??[]).some(n=>n&&typeof n=="object"&&"id"in n)&&(i.id=newRecordId()),{...i,...o}}const Y=new Set(["autoNumber","createdTime","createdBy","lastModifiedTime","lastModifiedBy"]),J=e=>Y.has(String(e))||S(e)?.copy===!1;export function recordCopyValues(e,o){const i={};for(const n of e.internalColumns){const t=m(n);if(!n.field||n.fieldFn||t.fieldFn||t.recordKey===!0||J(t.fieldType))continue;const r=o[String(n.field)];r!==void 0&&(i[String(n.field)]=Array.isArray(r)?r.slice():r)}return i}function R(e,o,i){const n=String(o.field),t=e.internalData.map(s=>s?.[n]);if(V(i))return t;const r=m(o),l=(r.fieldType?w(r,e.internalColumns):o).fieldFn;if(typeof l=="function")return e.internalData.map(s=>{if(s==null)return;const a=l(s);return a==="#ERROR"?null:a});if(r.fieldType==="link"&&i!=="link"){const s=j(h(r).table);if(s)return t.map(a=>B(s,a).map(u=>u[s.primaryField]).filter(u=>u!=null&&u!==""))}return t}export function previewChange(e,o,i){const n=e.internalColumns.find(t=>defId(t)===o);return!n||n.fieldType===i.fieldType||!n.field?0:M(R(e,n,i.fieldType),n.fieldType,i.fieldType,T(i.fieldProps))}export function previewOptions(e,o,i){const n=e.internalColumns.find(r=>defId(r)===o);if(!n||!g.has(n.fieldType)||!g.has(i.fieldType))return null;const t={...i.fieldProps};return x(t),F(h(m(n)).options,t.options)}export function optionRecords(e,o,i){const n=e.internalColumns.find(t=>defId(t)===o)?.field;return _(e.internalData,String(n),i)}function X(e,o,i,n){const t=i.trim().toLowerCase();return!t||t===n.trim().toLowerCase()?e:e.map(r=>{const l=m(r);if(String(l.field??l.id)===o)return r;if(l.fieldType==="ai"){const u=String(l.fieldProps?.prompt??""),d=$(u,p=>p.trim().toLowerCase()===t?n:null);return d===u?r:{...l,fieldProps:{...l.fieldProps,prompt:d}}}if(l.fieldType!=="formula")return r;const s=String(l.fieldProps?.formula??""),a=W(s,u=>u.trim().toLowerCase()===t?n:null);return a===s?r:{...l,fieldProps:{...l.fieldProps,formula:a}}})}export function updateField(e,o,i){const n=e.internalColumns.findIndex(f=>defId(f)===o);if(n<0)return null;const t=plainDef(e.internalColumns[n]);t.recordKey===!0&&(i={...i,fieldType:String(t.fieldType),fieldProps:{...t.fieldProps??{}}});const r=t.fieldType!==i.fieldType,l=T(i.fieldProps);x(l);let s;if(r&&t.field){const f=String(t.field),L=R(e,e.internalColumns[n],i.fieldType);s=e.internalData.map((y,O)=>y==null?y:{...y,[f]:k(L[O],t.fieldType,i.fieldType,l)}),(i.fieldType==="singleSelect"||i.fieldType==="multiSelect")&&!l.options?.length&&(l.options=E(s.map(y=>y?.[f])))}const a=g.has(t.fieldType)&&g.has(i.fieldType)?F(t.fieldProps?.options,l.options):null;a&&G(l.default,a)&&(l.default=I(l.default,a)),a&&t.field&&!e.props.rowModel&&!e.props.baseFeed&&(s=z(s??e.internalData,String(t.field),a));const u={...t};if(r)for(const f of H)delete u[f];const d={...u,header:i.name.trim(),fieldType:i.fieldType,fieldProps:l};i.description?.trim()?d.description=i.description.trim():delete d.description;let p=e.internalColumns.slice();if(p[n]=d,typeof t.header=="string"&&t.field&&(p=X(p,String(t.field),t.header,String(d.header))),e.internalColumns=c(p),s&&(e.internalData=s,Q(e,o)),a){const f=K(e.advancedFilter,o,a);f!==e.advancedFilter&&e.buildApi?.()?.setAdvancedFilter?.(f)}return e.props.onColumnChange?.({column:d,previous:t,columns:plainColumns(e),...s?{data:s}:{},...a?{options:a}:{}}),d}export function addSelectOptions(e,o,i){const n=e.internalColumns.findIndex(u=>defId(u)===o);if(n<0||!i.length)return null;const t=plainDef(e.internalColumns[n]),r=Array.isArray(t.fieldProps?.options)?t.fieldProps.options.slice():[],l=new Set(r.map(u=>String(u.value)));for(const u of i)l.has(u.value)||(l.add(u.value),r.push({...u}));const s={...t,fieldProps:{...t.fieldProps,options:r}},a=e.internalColumns.slice();return a[n]=s,e.internalColumns=c(a),e.props.onColumnChange?.({column:s,previous:t,columns:plainColumns(e)}),s}export function setFieldSummary(e,o,i){const n=e.internalColumns.findIndex(a=>defId(a)===o);if(n<0)return null;const t=plainDef(e.internalColumns[n]),r={...t.fieldProps};i==="none"?delete r.summary:r.summary=i;const l={...t,fieldProps:r},s=e.internalColumns.slice();return s[n]=l,e.internalColumns=c(s),e.props.onColumnChange?.({column:l,previous:t,columns:plainColumns(e)}),l}export function duplicateField(e,o){const i=e.internalColumns.findIndex(a=>defId(a)===o);if(i<0)return null;const n=plainDef(e.internalColumns[i]);n.recordKey===!0&&(delete n.recordKey,delete n.editable);const t=`${String(n.header??o)} copy`,r=uniqueId(t,e.internalColumns.map(defId)),l={...n,id:r,field:r,header:t};let s;if(n.field){const a=String(n.field);s=e.internalData.map(u=>u==null?u:{...u,[r]:Z(u[a])}),e.internalData=s}return e.internalColumns=c(D(e.internalColumns,l,i+1)),e.props.onColumnAdd?.({column:l,columns:plainColumns(e),...s?{data:s}:{}}),A(e,r),l}export function filterWithout(e,o){const i=e;if(i?.kind!=="fieldFilter")return e;const n=i.conditions.flatMap(t=>{if(!q(t))return o(t.column)?[]:[t];const r=t.conditions.filter(l=>!o(l.column));return r.length===t.conditions.length?[t]:r.length?[{...t,conditions:r}]:[]});return n.length===i.conditions.length&&n.every((t,r)=>t===i.conditions[r])?e:n.length?{...i,conditions:n}:null}export function removeField(e,o){e.internalColumns=c(e.internalColumns.filter(n=>defId(n)!==o));const i=filterWithout(e.advancedFilter,n=>n===o);i!==e.advancedFilter&&e.buildApi?.()?.setAdvancedFilter?.(i),e.props.onColumnRemove?.({columnId:o,columns:plainColumns(e)})}export function hideField(e,o){e.buildApi?.()?.setColumnVisible?.(o,!1)}export function indexBeside(e,o,i){const n=e.internalColumns.findIndex(t=>defId(t)===o);return n<0?e.internalColumns.length:i==="left"?n:n+1}function Z(e){if(e==null||typeof e!="object")return e;try{return structuredClone(e)}catch{return Array.isArray(e)?e.slice():{...e}}}
@@ -8,7 +8,7 @@ export declare function resolveMeWith(fn: () => string | undefined): void;
8
8
  /** Where a filter's words come from: `lookup(key, english)` returns the word for a `viewbar.*` key. Null goes back to English. */
9
9
  export declare function setFilterWords(lookup: ((key: string, english: string) => string) | null): void;
10
10
  /** What a condition compares, from the field's type. */
11
- export type FilterKind = 'text' | 'number' | 'select' | 'multi' | 'checkbox' | 'date' | 'files' | 'link' | 'checklist' | 'time';
11
+ export type FilterKind = 'text' | 'number' | 'select' | 'multi' | 'checkbox' | 'date' | 'files' | 'link' | 'checklist' | 'time' | 'linked';
12
12
  export type FilterOp = 'contains' | 'notContains' | 'is' | 'isNot' | 'isEmpty' | 'isNotEmpty' | 'eq' | 'neq' | 'lt' | 'gt' | 'lte' | 'gte' | 'isAnyOf' | 'isNoneOf' | 'hasAnyOf' | 'hasAllOf' | 'hasNoneOf' | 'isExactly' | 'isBefore' | 'isAfter' | 'isOnOrBefore' | 'isOnOrAfter' | 'isWithin' | 'allDone' | 'notAllDone';
13
13
  /** A day a date condition names, relative to today or exact. */
14
14
  export type DateTarget = {