@svgrid/enterprise 3.1.34 → 3.1.36

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 (250) hide show
  1. package/dist/ExpressionEditorHarness.svelte +1 -1
  2. package/dist/SvAdvancedFilter.svelte +1 -1
  3. package/dist/SvAlertRuleEditor.svelte +1 -1
  4. package/dist/SvAlertsManager.svelte +1 -1
  5. package/dist/SvAlertsPanel.svelte +1 -1
  6. package/dist/SvExpressionEditor.svelte +1 -1
  7. package/dist/SvGridBoard.svelte +1 -1
  8. package/dist/SvGridBulkEditDrawer.svelte +1 -1
  9. package/dist/SvGridEditPanel.svelte +1 -1
  10. package/dist/SvGridGallery.svelte +1 -1
  11. package/dist/SvGridMasterDetail.svelte +1 -1
  12. package/dist/SvGridScheduler.svelte +1 -1
  13. package/dist/SvGridSelectionBar.svelte +1 -1
  14. package/dist/SvPivotDesigner.svelte +1 -1
  15. package/dist/SvSchemaChart.svelte +1 -1
  16. package/dist/SvSchemaDashboard.svelte +1 -1
  17. package/dist/SvSheet.svelte +1 -1
  18. package/dist/SvSheetChartSetup.svelte +1 -1
  19. package/dist/SvSheetConditionalFormat.svelte +1 -1
  20. package/dist/SvSheetDataValidation.svelte +1 -1
  21. package/dist/SvSheetEditRanges.svelte +1 -1
  22. package/dist/SvSheetErrors.svelte +1 -1
  23. package/dist/SvSheetEvaluate.svelte +1 -1
  24. package/dist/SvSheetFindReplace.svelte +1 -1
  25. package/dist/SvSheetFormatCells.svelte +1 -1
  26. package/dist/SvSheetGoalSeek.svelte +1 -1
  27. package/dist/SvSheetInsertFunction.svelte +1 -1
  28. package/dist/SvSheetIteration.svelte +1 -1
  29. package/dist/SvSheetLink.svelte +1 -1
  30. package/dist/SvSheetManageRules.svelte +1 -1
  31. package/dist/SvSheetNameManager.svelte +1 -1
  32. package/dist/SvSheetPageSetup.svelte +1 -1
  33. package/dist/SvSheetPasteSpecial.svelte +1 -1
  34. package/dist/SvSheetPivot.svelte +1 -1
  35. package/dist/SvSheetProtectSheet.svelte +1 -1
  36. package/dist/SvSheetRemoveDuplicates.svelte +1 -1
  37. package/dist/SvSheetRibbon.svelte +1 -1
  38. package/dist/SvSheetSizeDialog.svelte +1 -1
  39. package/dist/SvSheetSort.svelte +1 -1
  40. package/dist/SvSheetSparklines.svelte +1 -1
  41. package/dist/SvSheetTable.svelte +1 -1
  42. package/dist/SvSheetTabs.svelte +1 -1
  43. package/dist/SvSheetTextToColumns.svelte +1 -1
  44. package/dist/SvSheetValidationAlert.svelte +1 -1
  45. package/dist/cdn/svgrid-enterprise.svelte-external.js +2 -2
  46. package/dist/designer/assets/{index-v61ZvIWw.js → index-CsdyIRos.js} +3 -3
  47. package/dist/designer/assets/{src-DkFgWld_.js → src-CSmsOfsG.js} +15 -15
  48. package/dist/designer/index.html +2 -2
  49. package/dist/fields/AiCell.svelte +41 -0
  50. package/dist/fields/AiCell.svelte.d.ts +5 -0
  51. package/dist/fields/AttachmentCell.svelte +1 -1
  52. package/dist/fields/AttachmentDialog.svelte +1 -1
  53. package/dist/fields/AttachmentEditor.svelte +1 -1
  54. package/dist/fields/AttachmentPreview.svelte +1 -1
  55. package/dist/fields/BaseAutomations.svelte +1 -1
  56. package/dist/fields/BaseChartView.svelte +1 -1
  57. package/dist/fields/BaseDashboardView.svelte +133 -0
  58. package/dist/fields/BaseDashboardView.svelte.d.ts +17 -0
  59. package/dist/fields/BaseImport.svelte +89 -0
  60. package/dist/fields/BaseImport.svelte.d.ts +15 -0
  61. package/dist/fields/BaseInboxView.svelte +112 -0
  62. package/dist/fields/BaseInboxView.svelte.d.ts +8 -0
  63. package/dist/fields/BaseListView.svelte +90 -0
  64. package/dist/fields/BaseListView.svelte.d.ts +8 -0
  65. package/dist/fields/BaseSearch.svelte +78 -0
  66. package/dist/fields/BaseSearch.svelte.d.ts +10 -0
  67. package/dist/fields/BaseTableView.svelte +28 -3
  68. package/dist/fields/BaseTableView.svelte.d.ts +5 -1
  69. package/dist/fields/BaseTabs.svelte +45 -8
  70. package/dist/fields/BaseTabs.svelte.d.ts +25 -1
  71. package/dist/fields/BaseTrash.svelte +63 -0
  72. package/dist/fields/BaseTrash.svelte.d.ts +15 -0
  73. package/dist/fields/CheckboxCell.svelte +1 -1
  74. package/dist/fields/ChecklistCell.svelte +22 -0
  75. package/dist/fields/ChecklistCell.svelte.d.ts +10 -0
  76. package/dist/fields/ChecklistEditor.svelte +81 -0
  77. package/dist/fields/ChecklistEditor.svelte.d.ts +12 -0
  78. package/dist/fields/ColorCell.svelte +13 -0
  79. package/dist/fields/ColorCell.svelte.d.ts +8 -0
  80. package/dist/fields/ColorEditor.svelte +60 -0
  81. package/dist/fields/ColorEditor.svelte.d.ts +11 -0
  82. package/dist/fields/DashboardRecords.svelte +35 -0
  83. package/dist/fields/DashboardRecords.svelte.d.ts +11 -0
  84. package/dist/fields/DashboardTileEditor.svelte +138 -0
  85. package/dist/fields/DashboardTileEditor.svelte.d.ts +15 -0
  86. package/dist/fields/DeleteFieldConfirm.svelte +1 -1
  87. package/dist/fields/DeleteRecordConfirm.svelte +1 -1
  88. package/dist/fields/FieldEditor.svelte +32 -3
  89. package/dist/fields/FieldInput.svelte +1 -1
  90. package/dist/fields/FieldsHeaderEnd.svelte +1 -1
  91. package/dist/fields/FootRowAdder.svelte +1 -1
  92. package/dist/fields/GroupHeader.svelte +3 -3
  93. package/dist/fields/LinkPickerEditor.svelte +1 -1
  94. package/dist/fields/LinkPreview.svelte +1 -1
  95. package/dist/fields/LinkedRecordView.svelte +1 -1
  96. package/dist/fields/LinkedRecordsCell.svelte +1 -1
  97. package/dist/fields/ListChips.svelte +21 -0
  98. package/dist/fields/ListChips.svelte.d.ts +9 -0
  99. package/dist/fields/LongTextEditor.svelte +1 -1
  100. package/dist/fields/MentionInput.svelte +59 -0
  101. package/dist/fields/MentionInput.svelte.d.ts +11 -0
  102. package/dist/fields/NumberEditor.svelte +1 -1
  103. package/dist/fields/OptionsEditor.svelte +1 -1
  104. package/dist/fields/PercentCell.svelte +1 -1
  105. package/dist/fields/PropertyInput.svelte +13 -10
  106. package/dist/fields/RatingCell.svelte +1 -1
  107. package/dist/fields/RatingEditor.svelte +1 -1
  108. package/dist/fields/RecordView.svelte +20 -25
  109. package/dist/fields/RowHeader.svelte +1 -1
  110. package/dist/fields/SelectCell.svelte +1 -1
  111. package/dist/fields/SelectEditor.svelte +1 -1
  112. package/dist/fields/SummaryCell.svelte +1 -1
  113. package/dist/fields/SvBase.svelte +48 -9
  114. package/dist/fields/SvBase.svelte.d.ts +33 -1
  115. package/dist/fields/SvBaseForm.svelte +2 -2
  116. package/dist/fields/SvBaseForm.svelte.d.ts +14 -0
  117. package/dist/fields/SvBaseViewBar.svelte +33 -12
  118. package/dist/fields/SvBaseViewBar.svelte.d.ts +2 -0
  119. package/dist/fields/TimeOfDayEditor.svelte +39 -0
  120. package/dist/fields/TimeOfDayEditor.svelte.d.ts +12 -0
  121. package/dist/fields/UserCell.svelte +1 -1
  122. package/dist/fields/activity.svelte.d.ts +29 -0
  123. package/dist/fields/activity.svelte.js +1 -1
  124. package/dist/fields/ai-field.svelte.d.ts +91 -0
  125. package/dist/fields/ai-field.svelte.js +1 -0
  126. package/dist/fields/ai-prompt.d.ts +64 -0
  127. package/dist/fields/ai-prompt.js +7 -0
  128. package/dist/fields/airtable.d.ts +90 -0
  129. package/dist/fields/airtable.js +1 -0
  130. package/dist/fields/bar-request.svelte.d.ts +1 -1
  131. package/dist/fields/base-history.d.ts +56 -0
  132. package/dist/fields/base-history.js +1 -0
  133. package/dist/fields/base-import.d.ts +54 -0
  134. package/dist/fields/base-import.js +2 -0
  135. package/dist/fields/base-search.d.ts +34 -0
  136. package/dist/fields/base-search.js +1 -0
  137. package/dist/fields/base-share.d.ts +45 -0
  138. package/dist/fields/base-share.js +1 -0
  139. package/dist/fields/base-sql.js +3 -3
  140. package/dist/fields/base-trash.d.ts +51 -0
  141. package/dist/fields/base-trash.js +1 -0
  142. package/dist/fields/builtin-types.js +1 -1
  143. package/dist/fields/chart-view.d.ts +12 -0
  144. package/dist/fields/chart-view.js +1 -1
  145. package/dist/fields/checklist.d.ts +36 -0
  146. package/dist/fields/checklist.js +4 -0
  147. package/dist/fields/color-value.d.ts +14 -0
  148. package/dist/fields/color-value.js +1 -0
  149. package/dist/fields/convert.js +1 -1
  150. package/dist/fields/copy-text.d.ts +1 -1
  151. package/dist/fields/copy-text.js +1 -1
  152. package/dist/fields/dashboard.d.ts +143 -0
  153. package/dist/fields/dashboard.js +1 -0
  154. package/dist/fields/field-access.svelte.d.ts +37 -0
  155. package/dist/fields/field-access.svelte.js +1 -0
  156. package/dist/fields/field-ops.js +1 -1
  157. package/dist/fields/filter-model.d.ts +4 -11
  158. package/dist/fields/filter-model.js +1 -1
  159. package/dist/fields/form-logic.d.ts +69 -0
  160. package/dist/fields/form-logic.js +1 -0
  161. package/dist/fields/formula.js +1 -1
  162. package/dist/fields/grid-access.d.ts +8 -0
  163. package/dist/fields/grid-access.js +1 -1
  164. package/dist/fields/index.d.ts +16 -0
  165. package/dist/fields/index.js +1 -1
  166. package/dist/fields/list-view.d.ts +40 -0
  167. package/dist/fields/list-view.js +1 -0
  168. package/dist/fields/mentions.d.ts +50 -0
  169. package/dist/fields/mentions.js +1 -0
  170. package/dist/fields/palette.d.ts +4 -2
  171. package/dist/fields/palette.js +1 -1
  172. package/dist/fields/record-menu.js +1 -1
  173. package/dist/fields/registry.svelte.d.ts +5 -0
  174. package/dist/fields/registry.svelte.js +1 -1
  175. package/dist/fields/time-of-day.d.ts +28 -0
  176. package/dist/fields/time-of-day.js +1 -0
  177. package/dist/fields/view-model.d.ts +24 -2
  178. package/dist/fields/view-model.js +1 -1
  179. package/dist/fields/viewbar/ChartPanel.svelte +1 -1
  180. package/dist/fields/viewbar/ColorPanel.svelte +1 -1
  181. package/dist/fields/viewbar/ConditionValue.svelte +4 -4
  182. package/dist/fields/viewbar/FilterPanel.svelte +1 -1
  183. package/dist/fields/viewbar/GanttPanel.svelte +1 -1
  184. package/dist/fields/viewbar/HideFieldsPanel.svelte +1 -1
  185. package/dist/fields/viewbar/ListPanel.svelte +36 -0
  186. package/dist/fields/viewbar/ListPanel.svelte.d.ts +11 -0
  187. package/dist/fields/viewbar/SortPanel.svelte +1 -1
  188. package/dist/fields/viewbar/ViewsMenu.svelte +27 -4
  189. package/dist/fields/viewbar/ViewsMenu.svelte.d.ts +6 -0
  190. package/dist/gantt/SvGridGantt.svelte +1 -1
  191. package/dist/node/studio.js +1 -1
  192. package/dist/review/RichCellMark.svelte +1 -1
  193. package/dist/review/SvReviewPanel.svelte +1 -1
  194. package/dist/server/SvGroupCell.svelte +1 -1
  195. package/dist/server/SvRowGroupPanel.svelte +1 -1
  196. package/dist/version.d.ts +2 -2
  197. package/dist/version.js +1 -1
  198. package/dist/wc/GridFind-DsTvdUXq.js +1 -0
  199. package/dist/wc/GridFooter-D-i8boBh.js +1 -0
  200. package/dist/wc/GridMenus-CYe9Fw2I.js +20 -0
  201. package/dist/wc/PinSplitter-LvyyrLhe.js +6 -0
  202. package/dist/wc/SvChartMenu-XKW_LOYw.js +1 -0
  203. package/dist/wc/SvDateRangeInput-CSOxqTB1.js +1 -0
  204. package/dist/wc/SvDateTimePicker-DvvFs2T9.js +4 -0
  205. package/dist/wc/SvField-BmQphyOs.js +20 -0
  206. package/dist/wc/SvForm-HD7y5vmk.js +46 -0
  207. package/dist/wc/SvGridCellEditor-776KAOe1.js +3 -0
  208. package/dist/wc/SvGridChart-DC7ZUhp8.js +171 -0
  209. package/dist/wc/SvGridChartBuilder-Dd3vWBvq.js +7 -0
  210. package/dist/wc/SvGridChartPanel-CwYjF46U.js +5 -0
  211. package/dist/wc/SvGridChartView-CSF38rBs.js +3 -0
  212. package/dist/wc/SvGridDropdown-4S1G7gsP.js +30 -0
  213. package/dist/wc/SvMenuList-D3ZLXjL_.js +1 -0
  214. package/dist/wc/SvModal-Dk0YwPWp.js +7 -0
  215. package/dist/wc/SvSwitchButton-DdZmc3ew.js +1 -0
  216. package/dist/wc/SvTabs-BI2cQHyw.js +2 -0
  217. package/dist/wc/base-react.d.ts +38 -0
  218. package/dist/wc/base-react.js +1 -0
  219. package/dist/wc/base-vue.d.ts +29 -0
  220. package/dist/wc/base-vue.js +1 -0
  221. package/dist/wc/board-RQp5fHPR.js +21 -0
  222. package/dist/wc/board-view.svelte-CpxuZcEg.js +1 -0
  223. package/dist/wc/card-marks.svelte-QwxIcKcZ.js +1 -0
  224. package/dist/wc/client-DNdLmGcu.js +3 -0
  225. package/dist/wc/createOverlay.svelte-CDw3RXgs.js +1 -0
  226. package/dist/wc/custom-filter-Dp8JxlQu.js +2 -0
  227. package/dist/wc/date-format-DtSmFyEB.js +18 -0
  228. package/dist/wc/editor-registry-CkKfcVLc.js +1 -0
  229. package/dist/wc/export-format-CGfE9_O5.js +5 -0
  230. package/dist/wc/gallery-CNOHNWEJ.js +4 -0
  231. package/dist/wc/gallery-view.svelte-27X-wCQH.js +1 -0
  232. package/dist/wc/grid-extension.svelte-hgqOteka.js +1 -0
  233. package/dist/wc/import-B9mIERCl.js +4 -0
  234. package/dist/wc/js-scroller.svelte-BP8Up6_q.js +1 -0
  235. package/dist/wc/license-CWVWqb-i.js +27 -0
  236. package/dist/wc/list-option-CI4nMshZ.js +1 -0
  237. package/dist/wc/react.d.ts +1 -0
  238. package/dist/wc/react.js +1 -1
  239. package/dist/wc/scheduler-CkVY4od-.js +147 -0
  240. package/dist/wc/scheduler-view.svelte-SzG7rU8b.js +1 -0
  241. package/dist/wc/sparkline-DWRBQubt.js +1 -0
  242. package/dist/wc/sv-base-element.d.ts +87 -0
  243. package/dist/wc/sv-base-element.js +273 -0
  244. package/dist/wc/sv-sheet-element.d.ts +2 -0
  245. package/dist/wc/sv-sheet-element.js +55 -55
  246. package/dist/wc/svelte-virtualizer.svelte-CSBwEZt9.js +1 -0
  247. package/dist/wc/types/sv-base-element.d.ts +87 -0
  248. package/dist/wc/vue.d.ts +1 -0
  249. package/dist/wc/vue.js +1 -1
  250. package/package.json +19 -4
@@ -1 +1 @@
1
- export const ME="@me";let h=()=>{};export function resolveMeWith(e){h=e}export const isGroup=e=>Array.isArray(e.conditions);const b=new Set(["text","longText","url","email","phone","barcode"]),y=new Set(["number","currency","percent","rating","duration","autoNumber","count"]),x=new Set(["date","createdTime","lastModifiedTime"]),N={formula:"text",lookup:"text",rollup:"text"},k=new Set(["AND","OR"]);function g(e){const t=e.cellDataType;return t==="number"?"number":t==="date"||t==="dateString"?"date":t==="boolean"?"checkbox":null}export function filterKindOf(e){const t=e.fieldType;if(t==="button")return null;if(t==="singleSelect")return"select";if(t==="multiSelect")return"multi";if(t==="user"||t==="createdBy"||t==="lastModifiedBy")return e.fieldProps?.multiple?"multi":"select";if(t==="checkbox")return"checkbox";if(t==="attachment")return"files";if(t==="link")return"link";if(t&&x.has(t))return"date";if(t&&y.has(t))return"number";if(t&&b.has(t))return"text";if(t==="rollup"&&!e.cellDataType&&k.has(String(e.fieldProps?.aggregation)))return"checkbox";const r=t==="formula"?e.fieldProps?.result:void 0;return r==="number"||r==="currency"||r==="percent"?"number":r==="date"?"date":g(e)??(t?N[t]:void 0)??"text"}const p=[{op:"isEmpty",label:"is empty"},{op:"isNotEmpty",label:"is not empty"}];export function operatorsFor(e){switch(e){case"number":return[{op:"eq",label:"="},{op:"neq",label:"≠"},{op:"lt",label:"<"},{op:"gt",label:">"},{op:"lte",label:"≤"},{op:"gte",label:"≥"},...p];case"select":return[{op:"is",label:"is"},{op:"isNot",label:"is not"},{op:"isAnyOf",label:"is any of"},{op:"isNoneOf",label:"is none of"},...p];case"multi":return[{op:"hasAnyOf",label:"has any of"},{op:"hasAllOf",label:"has all of"},{op:"isExactly",label:"is exactly"},{op:"hasNoneOf",label:"has none of"},...p];case"checkbox":return[{op:"is",label:"is"}];case"date":return[{op:"is",label:"is"},{op:"isBefore",label:"is before"},{op:"isAfter",label:"is after"},{op:"isOnOrBefore",label:"is on or before"},{op:"isOnOrAfter",label:"is on or after"},{op:"isWithin",label:"is within"},...p];case"files":return[{op:"contains",label:"file name contains"},...p];case"link":case"text":return[{op:"contains",label:"contains"},{op:"notContains",label:"does not contain"},{op:"is",label:"is"},{op:"isNot",label:"is not"},...p]}}export function defaultValue(e,t){if(!(t==="isEmpty"||t==="isNotEmpty"))return e==="checkbox"?!0:e==="date"?t==="isWithin"?{span:"pastWeek"}:{mode:"today"}:e==="select"&&(t==="is"||t==="isNot")?"":e==="select"||e==="multi"?[]:""}export function newCondition(e,t){const r=filterKindOf(t);if(!r)return null;const n=operatorsFor(r)[0].op,s=r==="link"&&typeof t.fieldProps?.table=="string"?t.fieldProps.table:void 0;return{column:e,kind:r,op:n,value:defaultValue(r,n),...s?{table:s}:{}}}export function isComplete(e){if(e.op==="isEmpty"||e.op==="isNotEmpty"||e.kind==="checkbox")return!0;const t=e.value;if(t==null)return!1;if(Array.isArray(t))return t.length>0;if(typeof t=="string")return t.trim()!=="";if(e.kind==="date"&&typeof t=="object"){const r=t;if(r.mode==="exactDate")return!!r.date;if(r.span==="pastDays"||r.span==="nextDays")return Number(r.days)>0}return!0}export function conditionCount(e){if(!e)return 0;let t=0;for(const r of e.conditions)isGroup(r)?t+=r.conditions.filter(isComplete).length:isComplete(r)&&(t+=1);return t}const m=e=>String(e??"").trim().toLocaleLowerCase(),f=e=>e==null||e===""?[]:Array.isArray(e)?e.map(t=>String(t&&typeof t=="object"?t.id??t.name??"":t)):[String(e)],d=e=>e==null||e===""||Array.isArray(e)&&e.length===0||typeof e=="number"&&Number.isNaN(e),w=864e5;export function dayOf(e){if(e==null||e==="")return null;let t;if(e instanceof Date)t=e;else if(typeof e=="number")t=new Date(e);else{const r=String(e),n=/^(\d{4})-(\d{2})-(\d{2})$/.exec(r);t=n?new Date(Number(n[1]),Number(n[2])-1,Number(n[3])):new Date(r)}return Number.isNaN(t.getTime())?null:Math.floor((t.getTime()-t.getTimezoneOffset()*6e4)/w)}function A(e,t){switch(e.mode){case"today":return t;case"tomorrow":return t+1;case"yesterday":return t-1;case"oneWeekAgo":return t-7;case"oneWeekFromNow":return t+7;case"oneMonthAgo":return t-30;case"oneMonthFromNow":return t+30;case"exactDate":return dayOf(e.date)}}function O(e,t){const r=Math.max(1,Math.floor(Number(e.days)||1));switch(e.span){case"pastWeek":return[t-7,t];case"pastMonth":return[t-30,t];case"pastYear":return[t-365,t];case"nextWeek":return[t,t+7];case"nextMonth":return[t,t+30];case"nextYear":return[t,t+365];case"pastDays":return[t-r,t];case"nextDays":return[t,t+r]}}export function compileCondition(e,t,r=new Date){if(e.op==="isEmpty")return d;if(e.op==="isNotEmpty")return n=>!d(n);switch(e.kind){case"number":{const n=Number(e.value);if(!Number.isFinite(n))return()=>!0;const s=o=>d(o)?NaN:Number(o),i={eq:o=>o===n,neq:o=>o!==n,lt:o=>o<n,gt:o=>o>n,lte:o=>o<=n,gte:o=>o>=n}[e.op]??(()=>!0);return o=>{const u=s(o);return Number.isNaN(u)?e.op==="neq":i(u)}}case"checkbox":{const n=e.value!==!1;return s=>!!s===n}case"select":case"multi":{const n=h(),s=f(e.value).map(i=>i==="@me"&&n!=null?n:i),a=new Set(s);return e.op==="is"?i=>f(i)[0]===s[0]:e.op==="isNot"?i=>f(i)[0]!==s[0]:e.op==="isAnyOf"||e.op==="hasAnyOf"?i=>f(i).some(o=>a.has(o)):e.op==="isNoneOf"||e.op==="hasNoneOf"?i=>!f(i).some(o=>a.has(o)):e.op==="hasAllOf"?i=>{const o=new Set(f(i));return[...a].every(u=>o.has(u))}:e.op==="isExactly"?i=>{const o=new Set(f(i));return o.size===a.size&&[...a].every(u=>o.has(u))}:()=>!0}case"date":{const n=dayOf(r);if(e.op==="isWithin"){const[o,u]=O(e.value??{span:"pastWeek"},n);return l=>{const c=dayOf(l);return c!=null&&c>=o&&c<=u}}const s=A(e.value??{mode:"today"},n);if(s==null)return()=>!0;const i={is:o=>o===s,isBefore:o=>o<s,isAfter:o=>o>s,isOnOrBefore:o=>o<=s,isOnOrAfter:o=>o>=s}[e.op]??(()=>!0);return o=>{const u=dayOf(o);return u!=null&&i(u)}}case"files":{const n=m(e.value);return s=>(Array.isArray(s)?s:[]).some(a=>m(a?.name).includes(n))}case"link":case"text":{const n=m(e.value),s=a=>e.kind==="link"&&e.table&&t?m(t(e.table,a).join(", ")):m(Array.isArray(a)?a.map(i=>i&&typeof i=="object"?i.name??"":i).join(", "):a);return e.op==="contains"?a=>s(a).includes(n):e.op==="notContains"?a=>!s(a).includes(n):e.op==="is"?a=>s(a)===n:e.op==="isNot"?a=>s(a)!==n:()=>!0}}}export function compileFieldFilter(e,t,r,n){const s=o=>{const u=compileCondition(o,r,n);return l=>u(t(l,o.column))},a=(o,u)=>o==="or"?l=>u.some(c=>c(l)):l=>u.every(c=>c(l)),i=[];for(const o of e.conditions)if(isGroup(o)){const u=o.conditions.filter(isComplete).map(s);u.length&&i.push(a(o.conjunction,u))}else isComplete(o)&&i.push(s(o));return i.length?a(e.conjunction,i):null}const D={today:"today",tomorrow:"tomorrow",yesterday:"yesterday",oneWeekAgo:"one week ago",oneWeekFromNow:"one week from now",oneMonthAgo:"one month ago",oneMonthFromNow:"one month from now"},S={pastWeek:"the past week",pastMonth:"the past month",pastYear:"the past year",nextWeek:"the next week",nextMonth:"the next month",nextYear:"the next year"};function E(e){if(e.op==="isEmpty"||e.op==="isNotEmpty")return"";if(e.kind==="checkbox")return e.value===!1?"unchecked":"checked";if(e.kind==="date"){if(e.op==="isWithin"){const n=e.value??{span:"pastWeek"};return n.span==="pastDays"?`the past ${n.days??0} days`:n.span==="nextDays"?`the next ${n.days??0} days`:S[n.span]??n.span}const r=e.value??{mode:"today"};return r.mode==="exactDate"?r.date:D[r.mode]??r.mode}const t=r=>r==="@me"?"me":String(r);return Array.isArray(e.value)?e.value.map(t).join(", "):t(e.value??"")}export function describeCondition(e,t=r=>r){const r=operatorsFor(e.kind).find(n=>n.op===e.op)?.label??e.op;return[t(e.column),r,E(e)].filter(Boolean).join(" ")}export function describeFieldFilter(e,t){const r=[];for(const n of e.conditions)if(isGroup(n)){const s=n.conditions.filter(isComplete).map(a=>describeCondition(a,t));s.length&&r.push(s.length>1?`(${s.join(` ${n.conjunction} `)})`:s[0])}else isComplete(n)&&r.push(describeCondition(n,t));return r.length?r.join(` ${e.conjunction} `):"every record"}export function fieldFilterColumns(e){const t=new Set;for(const r of e.conditions)for(const n of isGroup(r)?r.conditions:[r])isComplete(n)&&t.add(n.column);return[...t]}
1
+ import{checklistProgress as y,checklistSortValue as x,toChecklist as g}from"./checklist.js";import{parseTimeOfDay as k,timeSeconds as h}from"./time-of-day.js";export const ME="@me";let b=()=>{};export function resolveMeWith(e){b=e}export const isGroup=e=>Array.isArray(e.conditions);const A=new Set(["text","longText","url","email","phone","barcode","color"]),N=new Set(["number","currency","percent","rating","duration","autoNumber","count"]),O=new Set(["date","createdTime","lastModifiedTime"]),w={formula:"text",lookup:"text",rollup:"text"},D=new Set(["AND","OR"]);function S(e){const t=e.cellDataType;return t==="number"?"number":t==="date"||t==="dateString"?"date":t==="boolean"?"checkbox":null}export function filterKindOf(e){const t=e.fieldType;if(t==="button")return null;if(t==="singleSelect")return"select";if(t==="multiSelect")return"multi";if(t==="user"||t==="createdBy"||t==="lastModifiedBy")return e.fieldProps?.multiple?"multi":"select";if(t==="checkbox")return"checkbox";if(t==="attachment")return"files";if(t==="link")return"link";if(t==="checklist")return"checklist";if(t==="timeOfDay")return"time";if(t&&O.has(t))return"date";if(t&&N.has(t))return"number";if(t&&A.has(t))return"text";if(t==="ai")return e.fieldProps?.output==="singleSelect"?"select":e.fieldProps?.output==="number"?"number":"text";if(t==="rollup"&&!e.cellDataType&&D.has(String(e.fieldProps?.aggregation)))return"checkbox";const o=t==="formula"?e.fieldProps?.result:void 0;return o==="number"||o==="currency"||o==="percent"?"number":o==="date"?"date":S(e)??(t?w[t]:void 0)??"text"}const f=[{op:"isEmpty",label:"is empty"},{op:"isNotEmpty",label:"is not empty"}];export function operatorsFor(e){switch(e){case"number":return[{op:"eq",label:"="},{op:"neq",label:"≠"},{op:"lt",label:"<"},{op:"gt",label:">"},{op:"lte",label:"≤"},{op:"gte",label:"≥"},...f];case"select":return[{op:"is",label:"is"},{op:"isNot",label:"is not"},{op:"isAnyOf",label:"is any of"},{op:"isNoneOf",label:"is none of"},...f];case"multi":return[{op:"hasAnyOf",label:"has any of"},{op:"hasAllOf",label:"has all of"},{op:"isExactly",label:"is exactly"},{op:"hasNoneOf",label:"has none of"},...f];case"checkbox":return[{op:"is",label:"is"}];case"date":return[{op:"is",label:"is"},{op:"isBefore",label:"is before"},{op:"isAfter",label:"is after"},{op:"isOnOrBefore",label:"is on or before"},{op:"isOnOrAfter",label:"is on or after"},{op:"isWithin",label:"is within"},...f];case"files":return[{op:"contains",label:"file name contains"},...f];case"checklist":return[{op:"allDone",label:"is complete"},{op:"notAllDone",label:"is not complete"},{op:"gte",label:"% done ≥"},{op:"lt",label:"% done <"},{op:"contains",label:"has an item containing"},...f];case"time":return[{op:"is",label:"is"},{op:"isBefore",label:"is before"},{op:"isAfter",label:"is after"},{op:"isOnOrBefore",label:"is at or before"},{op:"isOnOrAfter",label:"is at or after"},...f];case"link":case"text":return[{op:"contains",label:"contains"},{op:"notContains",label:"does not contain"},{op:"is",label:"is"},{op:"isNot",label:"is not"},...f]}}export const NO_VALUE=new Set(["isEmpty","isNotEmpty","allDone","notAllDone"]);export function defaultValue(e,t){if(!NO_VALUE.has(t))return e==="checkbox"?!0:e==="date"?t==="isWithin"?{span:"pastWeek"}:{mode:"today"}:e==="select"&&(t==="is"||t==="isNot")?"":e==="select"||e==="multi"?[]:""}export function newCondition(e,t){const o=filterKindOf(t);if(!o)return null;const n=operatorsFor(o)[0].op,i=o==="link"&&typeof t.fieldProps?.table=="string"?t.fieldProps.table:void 0;return{column:e,kind:o,op:n,value:defaultValue(o,n),...i?{table:i}:{}}}export function isComplete(e){if(NO_VALUE.has(e.op)||e.kind==="checkbox")return!0;const t=e.value;if(t==null)return!1;if(Array.isArray(t))return t.length>0;if(typeof t=="string")return t.trim()!=="";if(e.kind==="date"&&typeof t=="object"){const o=t;if(o.mode==="exactDate")return!!o.date;if(o.span==="pastDays"||o.span==="nextDays")return Number(o.days)>0}return!0}export function conditionCount(e){if(!e)return 0;let t=0;for(const o of e.conditions)isGroup(o)?t+=o.conditions.filter(isComplete).length:isComplete(o)&&(t+=1);return t}const p=e=>String(e??"").trim().toLocaleLowerCase(),m=e=>e==null||e===""?[]:Array.isArray(e)?e.map(t=>String(t&&typeof t=="object"?t.id??t.name??"":t)):[String(e)],d=e=>e==null||e===""||Array.isArray(e)&&e.length===0||typeof e=="number"&&Number.isNaN(e),E=864e5;export function dayOf(e){if(e==null||e==="")return null;let t;if(e instanceof Date)t=e;else if(typeof e=="number")t=new Date(e);else{const o=String(e),n=/^(\d{4})-(\d{2})-(\d{2})$/.exec(o);t=n?new Date(Number(n[1]),Number(n[2])-1,Number(n[3])):new Date(o)}return Number.isNaN(t.getTime())?null:Math.floor((t.getTime()-t.getTimezoneOffset()*6e4)/E)}function M(e,t){switch(e.mode){case"today":return t;case"tomorrow":return t+1;case"yesterday":return t-1;case"oneWeekAgo":return t-7;case"oneWeekFromNow":return t+7;case"oneMonthAgo":return t-30;case"oneMonthFromNow":return t+30;case"exactDate":return dayOf(e.date)}}function T(e,t){const o=Math.max(1,Math.floor(Number(e.days)||1));switch(e.span){case"pastWeek":return[t-7,t];case"pastMonth":return[t-30,t];case"pastYear":return[t-365,t];case"nextWeek":return[t,t+7];case"nextMonth":return[t,t+30];case"nextYear":return[t,t+365];case"pastDays":return[t-o,t];case"nextDays":return[t,t+o]}}export function compileCondition(e,t,o=new Date){if(e.op==="isEmpty")return d;if(e.op==="isNotEmpty")return n=>!d(n);switch(e.kind){case"number":{const n=Number(e.value);if(!Number.isFinite(n))return()=>!0;const i=r=>d(r)?NaN:Number(r),s={eq:r=>r===n,neq:r=>r!==n,lt:r=>r<n,gt:r=>r>n,lte:r=>r<=n,gte:r=>r>=n}[e.op]??(()=>!0);return r=>{const l=i(r);return Number.isNaN(l)?e.op==="neq":s(l)}}case"checkbox":{const n=e.value!==!1;return i=>!!i===n}case"select":case"multi":{const n=b(),i=m(e.value).map(s=>s===ME&&n!=null?n:s),a=new Set(i);return e.op==="is"?s=>m(s)[0]===i[0]:e.op==="isNot"?s=>m(s)[0]!==i[0]:e.op==="isAnyOf"||e.op==="hasAnyOf"?s=>m(s).some(r=>a.has(r)):e.op==="isNoneOf"||e.op==="hasNoneOf"?s=>!m(s).some(r=>a.has(r)):e.op==="hasAllOf"?s=>{const r=new Set(m(s));return[...a].every(l=>r.has(l))}:e.op==="isExactly"?s=>{const r=new Set(m(s));return r.size===a.size&&[...a].every(l=>r.has(l))}:()=>!0}case"date":{const n=dayOf(o);if(e.op==="isWithin"){const[r,l]=T(e.value??{span:"pastWeek"},n);return u=>{const c=dayOf(u);return c!=null&&c>=r&&c<=l}}const i=M(e.value??{mode:"today"},n);if(i==null)return()=>!0;const s={is:r=>r===i,isBefore:r=>r<i,isAfter:r=>r>i,isOnOrBefore:r=>r<=i,isOnOrAfter:r=>r>=i}[e.op]??(()=>!0);return r=>{const l=dayOf(r);return l!=null&&s(l)}}case"files":{const n=p(e.value);return i=>(Array.isArray(i)?i:[]).some(a=>p(a?.name).includes(n))}case"checklist":{const n=a=>{const s=y(a);return s.total>0&&s.done===s.total};if(e.op==="allDone")return n;if(e.op==="notAllDone")return a=>!n(a);if(e.op==="contains"){const a=p(e.value);return s=>g(s).some(r=>p(r.text).includes(a))}const i=parseFloat(String(e.value??""));return Number.isFinite(i)?a=>{const s=x(a);return s==null?!1:e.op==="lt"?s*100<i:s*100>=i}:()=>!0}case"time":{const n=k(String(e.value??"")),i=h(n);if(n==null||i==null)return()=>!0;const a=n.length>5?1:60,s=Math.floor(i/a),l={is:u=>u===s,isBefore:u=>u<s,isAfter:u=>u>s,isOnOrBefore:u=>u<=s,isOnOrAfter:u=>u>=s}[e.op]??(()=>!0);return u=>{const c=h(u);return c!=null&&l(Math.floor(c/a))}}case"link":case"text":{const n=p(e.value),i=a=>e.kind==="link"&&e.table&&t?p(t(e.table,a).join(", ")):p(Array.isArray(a)?a.map(s=>s&&typeof s=="object"?s.name??"":s).join(", "):a);return e.op==="contains"?a=>i(a).includes(n):e.op==="notContains"?a=>!i(a).includes(n):e.op==="is"?a=>i(a)===n:e.op==="isNot"?a=>i(a)!==n:()=>!0}}}export function compileFieldFilter(e,t,o,n){const i=r=>{const l=compileCondition(r,o,n);return u=>l(t(u,r.column))},a=(r,l)=>r==="or"?u=>l.some(c=>c(u)):u=>l.every(c=>c(u)),s=[];for(const r of e.conditions)if(isGroup(r)){const l=r.conditions.filter(isComplete).map(i);l.length&&s.push(a(r.conjunction,l))}else isComplete(r)&&s.push(i(r));return s.length?a(e.conjunction,s):null}const W={today:"today",tomorrow:"tomorrow",yesterday:"yesterday",oneWeekAgo:"one week ago",oneWeekFromNow:"one week from now",oneMonthAgo:"one month ago",oneMonthFromNow:"one month from now"},P={pastWeek:"the past week",pastMonth:"the past month",pastYear:"the past year",nextWeek:"the next week",nextMonth:"the next month",nextYear:"the next year"};function j(e){if(NO_VALUE.has(e.op))return"";if(e.kind==="checkbox")return e.value===!1?"unchecked":"checked";if(e.kind==="date"){if(e.op==="isWithin"){const n=e.value??{span:"pastWeek"};return n.span==="pastDays"?`the past ${n.days??0} days`:n.span==="nextDays"?`the next ${n.days??0} days`:P[n.span]??n.span}const o=e.value??{mode:"today"};return o.mode==="exactDate"?o.date:W[o.mode]??o.mode}const t=o=>o===ME?"me":String(o);return Array.isArray(e.value)?e.value.map(t).join(", "):t(e.value??"")}export function describeCondition(e,t=o=>o){const o=operatorsFor(e.kind).find(n=>n.op===e.op)?.label??e.op;return[t(e.column),o,j(e)].filter(Boolean).join(" ")}export function describeFieldFilter(e,t){const o=[];for(const n of e.conditions)if(isGroup(n)){const i=n.conditions.filter(isComplete).map(a=>describeCondition(a,t));i.length&&o.push(i.length>1?`(${i.join(` ${n.conjunction} `)})`:i[0])}else isComplete(n)&&o.push(describeCondition(n,t));return o.length?o.join(` ${e.conjunction} `):"every record"}export function fieldFilterColumns(e){const t=new Set;for(const o of e.conditions)for(const n of isGroup(o)?o.conditions:[o])isComplete(n)&&t.add(n.column);return[...t]}
@@ -0,0 +1,69 @@
1
+ import { type FieldFilter } from './filter-model.js';
2
+ import type { FieldColumn } from './grid-access.js';
3
+ /**
4
+ * Where a form's prefilled answers come from: the link's query string (a
5
+ * whole URL, `?prefill_...` or `URLSearchParams`), `true` for the page's own
6
+ * URL, or values by field name or column id.
7
+ */
8
+ export type FormPrefill = Record<string, unknown> | URLSearchParams | string | boolean;
9
+ /**
10
+ * A value as the grid would store it from a cell edit: coerced for the
11
+ * editor type, then through the column's valueParser, so a custom field
12
+ * type parses the same in a form.
13
+ */
14
+ export declare function formValue(c: FieldColumn, raw: unknown, row: Record<string, unknown>): unknown;
15
+ /**
16
+ * A prefilled answer as the field's value, or undefined when it gives none:
17
+ * text a number field cannot read, a select option the field does not have
18
+ * (dropped, never added), a link to no record, a file.
19
+ */
20
+ export declare function prefillValue(c: FieldColumn, raw: unknown, row?: Record<string, unknown>): unknown;
21
+ /** The column a name in a link means: its name, its id, then either one in any case. */
22
+ export declare function formFieldNamed<C extends Pick<FieldColumn, 'id' | 'header'>>(columns: ReadonlyArray<C>, name: string): C | undefined;
23
+ /**
24
+ * The answers a prefill source gives the form's fields, by column id, still
25
+ * as written, and the ids a `hide_` parameter names. A name no field has is
26
+ * ignored.
27
+ */
28
+ export declare function readFormPrefill(source: FormPrefill | null | undefined, columns: ReadonlyArray<Pick<FieldColumn, 'id' | 'header'>>): {
29
+ values: Record<string, unknown>;
30
+ hide: Set<string>;
31
+ };
32
+ /** What a prefill source reads as now, to tell when it names other answers. */
33
+ export declare function formPrefillKey(source: FormPrefill | null | undefined): string;
34
+ /**
35
+ * A link that opens a form with answers filled in: `baseUrl` (the page the
36
+ * form is on, its own query kept) plus `prefill_<Field name>=value` for each
37
+ * value, keyed by column id or field. With `columns`, the parameter carries
38
+ * the field's name; without, the key itself. A list is comma-separated, a
39
+ * date `YYYY-MM-DD`. `hide` names the fields the form leaves out of sight.
40
+ */
41
+ export declare function formPrefillLink(baseUrl: string, values: Record<string, unknown>, columns?: ReadonlyArray<{
42
+ id?: string;
43
+ field?: string;
44
+ header?: unknown;
45
+ }>, options?: {
46
+ hide?: ReadonlyArray<string>;
47
+ }): string;
48
+ /**
49
+ * The form's conditions as one test per column id: given the answers so
50
+ * far (by field), whether the field is shown. A condition reads the other
51
+ * fields by column id, the way the view bar's filter does; one with no
52
+ * complete condition always shows its field.
53
+ */
54
+ export declare function compileFormConditions(conditions: Record<string, FieldFilter> | undefined, columns: ReadonlyArray<Pick<FieldColumn, 'id' | 'field'>>): Map<string, (values: Record<string, unknown>) => boolean>;
55
+ /**
56
+ * The answers with every hidden field taken out, and the ids hidden. Taking
57
+ * one out can hide another that depends on it, so it runs until nothing
58
+ * moves. A field shown again (hidden in `was`) gets back what it started
59
+ * with (`initial`). `context` holds values of fields the form does not ask
60
+ * for, which conditions may read.
61
+ */
62
+ export declare function settleFormAnswers(draft: Record<string, unknown>, columns: ReadonlyArray<Pick<FieldColumn, 'id' | 'field'>>, tests: Map<string, (values: Record<string, unknown>) => boolean>, opts?: {
63
+ initial?: Record<string, unknown>;
64
+ context?: Record<string, unknown>;
65
+ was?: ReadonlySet<string>;
66
+ }): {
67
+ draft: Record<string, unknown>;
68
+ hidden: Set<string>;
69
+ };
@@ -0,0 +1 @@
1
+ import{parseEditorValue as y}from"@svgrid/grid";import{compileFieldFilter as S}from"./filter-model.js";import{linkNames as g}from"./base-alerts.js";const h=e=>e==null||e===""||Array.isArray(e)&&e.length===0||typeof e=="number"&&Number.isNaN(e);function w(e,t){if(t instanceof Date&&e.def.cellDataType==="dateString"){const i=r=>String(r).padStart(2,"0");return`${t.getFullYear()}-${i(t.getMonth()+1)}-${i(t.getDate())}`}return t}export function formValue(e,t,i){const r=e.def,n=y(String(r.editorType??"text"),w(e,t),{multiple:r.editorMultiple===!0,dateOnly:r.cellDataType==="dateString"}),f=r.valueParser;return f?f({newValue:n,oldValue:i[e.field],rawInput:t,data:i,columnId:e.id}):n}const x=new Set(["attachment","formula","lookup","rollup","count","autoNumber","createdTime","lastModifiedTime","createdBy","lastModifiedBy","button"]),A=new Set(["singleSelect","multiSelect","user"]);export function prefillValue(e,t,i={}){if(x.has(e.fieldType??""))return;let r=t;Array.isArray(t)&&(r=t.map(f=>String(f)).join(",")),e.def.editorType==="checkbox"&&typeof r=="string"&&(r=/^(true|1|yes|on|checked)$/i.test(r.trim()));let n=formValue(e,r,i);if(A.has(e.fieldType??"")&&Array.isArray(e.def.editorOptions)){const f=new Set(e.def.editorOptions.map(o=>String(o.value)));n=Array.isArray(n)?n.filter(o=>f.has(String(o))):n!=null&&f.has(String(n))?n:void 0}return h(n)?void 0:n}function m(e){if(e instanceof URLSearchParams)return e;if(e===!0)return typeof window>"u"?new URLSearchParams:new URLSearchParams(window.location.search);if(typeof e=="string"){const t=e.split("#")[0]??"",i=t.indexOf("?");return new URLSearchParams(i>=0?t.slice(i+1):t)}return null}export function formFieldNamed(e,t){const i=t.trim(),r=i.toLocaleLowerCase();return e.find(n=>n.header===i)??e.find(n=>n.id===i)??e.find(n=>n.header.toLocaleLowerCase()===r||n.id.toLocaleLowerCase()===r)}export function readFormPrefill(e,t){const i={},r=new Set;if(e==null||e===!1)return{values:i,hide:r};const n=m(e);if(!n){for(const[f,o]of Object.entries(e)){const a=formFieldNamed(t,f);a&&(i[a.id]=o)}return{values:i,hide:r}}for(const[f,o]of n){const a=/^(prefill|hide)_(.+)$/.exec(f);if(!a)continue;const s=formFieldNamed(t,a[2]);s&&(a[1]==="prefill"?i[s.id]=o:/^(true|1|yes)$/i.test(o.trim())&&r.add(s.id))}return{values:i,hide:r}}export function formPrefillKey(e){if(e==null||e===!1)return"";const t=m(e);if(t)return t.toString();try{return JSON.stringify(e)}catch{return String(e)}}export function formPrefillLink(e,t,i,r={}){const n=l=>{const c=i?.find(d=>(d.id??d.field)===l||d.field===l);return c&&typeof c.header=="string"&&c.header?c.header:l},f=l=>Array.isArray(l)?l.map(f).join(","):l instanceof Date?l.toISOString().slice(0,10):String(l),o=e.indexOf("#")>=0?e.slice(e.indexOf("#")):"",a=o?e.slice(0,e.length-o.length):e,s=[];for(const[l,c]of Object.entries(t))h(c)||s.push(`prefill_${encodeURIComponent(n(l))}=${encodeURIComponent(f(c))}`);for(const l of r.hide??[])s.push(`hide_${encodeURIComponent(n(l))}=true`);if(!s.length)return e;const u=a.includes("?")?a.endsWith("?")||a.endsWith("&")?"":"&":"?";return`${a}${u}${s.join("&")}${o}`}export function compileFormConditions(e,t){const i=new Map;if(!e)return i;const r=new Map(t.map(n=>[n.id,n.field]));for(const[n,f]of Object.entries(e)){if(!f||!Array.isArray(f.conditions))continue;const o=S(f,(a,s)=>a[r.get(s)??s],g);o&&i.set(n,o)}return i}export function settleFormAnswers(e,t,i,r={}){const n=r.initial??{},f=r.context??{},o={...e};let a=new Set(r.was??[]);if(!i.size)return{draft:o,hidden:new Set};for(let s=0;s<=t.length;s++){const u={...f,...o},l=new Set(t.filter(d=>i.has(d.id)&&!i.get(d.id)(u)).map(d=>d.id));let c=!1;for(const d of t)if(l.has(d.id))d.field in o&&(delete o[d.field],c=!0);else if(a.has(d.id)&&!(d.field in o)&&d.field in n){const p=n[d.field];o[d.field]=Array.isArray(p)?p.slice():p,c=!0}if(a=l,!c)break}return{draft:o,hidden:a}}
@@ -1 +1 @@
1
- import{toDate as y}from"./format.js";export class FormulaError extends Error{}function w(t){const e=[];let n=0;for(;n<t.length;){const r=t[n];if(/\s/.test(r)){n++;continue}if(r==="{"){const i=t.indexOf("}",n);if(i<0)throw new FormulaError(`Unclosed "{" at ${n+1}`);e.push({k:"ref",v:t.slice(n+1,i).trim(),at:n}),n=i+1;continue}if(r==='"'||r==="'"){let i=n+1,a="";for(;i<t.length&&t[i]!==r;){if(t[i]==="\\"&&i+1<t.length){a+=t[i+1],i+=2;continue}a+=t[i++]}if(i>=t.length)throw new FormulaError(`Unclosed text at ${n+1}`);e.push({k:"str",v:a,at:n}),n=i+1;continue}const l=/^\d+(\.\d+)?|^\.\d+/.exec(t.slice(n));if(l){e.push({k:"num",v:l[0],at:n}),n+=l[0].length;continue}const o=/^[A-Za-z_][A-Za-z0-9_]*/.exec(t.slice(n));if(o){e.push({k:"id",v:o[0],at:n}),n+=o[0].length;continue}const c=/^(!=|<=|>=|<>|[-+*/&=<>])/.exec(t.slice(n));if(c){e.push({k:"op",v:c[0]==="<>"?"!=":c[0],at:n}),n+=c[0].length;continue}if(r==="("||r===")"||r===","){e.push({k:r,v:r,at:n}),n++;continue}throw new FormulaError(`Unexpected "${r}" at ${n+1}`)}return e}const g=t=>t==null||t===""||Array.isArray(t)&&t.length===0,s=t=>{if(typeof t=="number")return t;if(typeof t=="boolean")return t?1:0;if(t instanceof Date)return t.getTime();if(t==null||t==="")return 0;if(Array.isArray(t))return t.reduce((n,r)=>n+s(r),0);const e=Number(t);return Number.isFinite(e)?e:NaN},u=t=>t==null?"":t instanceof Date?t.toISOString():Array.isArray(t)?t.map(u).join(", "):String(t),d=t=>!g(t)&&t!==!1&&t!==0,I=/^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;export function isoDate(t){const e=t.trim();return I.test(e)?y(e):null}const h=t=>{if(t instanceof Date)return Number.isNaN(t.getTime())?null:t;if(t==null||t===""||typeof t=="boolean")return null;if(typeof t=="number")return y(t);const e=u(t).trim();return isoDate(e)??(/\d{4}/.test(e)&&/[/\s,.-]/.test(e)?y(e):null)},f=t=>t.flatMap(e=>Array.isArray(e)?e:[e]),A=t=>String(t).padStart(2,"0"),k=t=>Number(t.toPrecision(12)),U={milliseconds:"ms",millisecond:"ms",ms:"ms",seconds:"s",second:"s",s:"s",minutes:"m",minute:"m",m:"m",hours:"h",hour:"h",h:"h",days:"d",day:"d",d:"d",weeks:"w",week:"w",w:"w",months:"mo",month:"mo",years:"y",year:"y",y:"y"},T={ms:1,s:1e3,m:6e4,h:36e5},D=t=>U[u(t).trim().toLowerCase()]??null;function x(t,e){const n=new Date(t),r=n.getDate();return n.setDate(1),n.setMonth(n.getMonth()+e),n.setDate(Math.min(r,new Date(n.getFullYear(),n.getMonth()+1,0).getDate())),n}function F(t,e,n){if(T[n])return new Date(t.getTime()+e*T[n]);if(n==="mo"||n==="y")return x(t,Math.trunc(e)*(n==="y"?12:1));const r=e*(n==="w"?7:1),l=new Date(t);return l.setDate(l.getDate()+Math.trunc(r)),new Date(l.getTime()+(r-Math.trunc(r))*864e5)}const E=t=>t.getTime()-t.getTimezoneOffset()*6e4;function $(t,e,n){if(T[n])return Math.trunc((t.getTime()-e.getTime())/T[n]);if(n==="d"||n==="w")return Math.trunc((E(t)-E(e))/(n==="w"?6048e5:864e5));let r=(t.getFullYear()-e.getFullYear())*12+t.getMonth()-e.getMonth();const l=x(e,r).getTime();return r>0&&l>t.getTime()?r-=1:r<0&&l<t.getTime()&&(r+=1),n==="y"?Math.trunc(r/12):r}const S={IF:t=>d(t[0]??null)?t[1]??null:t[2]??null,AND:t=>f(t).every(d),OR:t=>f(t).some(d),NOT:t=>!d(t[0]??null),XOR:t=>f(t).filter(d).length%2===1,BLANK:()=>null,SWITCH:t=>{for(let e=1;e+1<t.length;e+=2)if(u(t[0]??null)===u(t[e]??null))return t[e+1]??null;return t.length%2===0?t[t.length-1]??null:null},CONCATENATE:t=>t.map(u).join(""),LEN:t=>u(t[0]??null).length,UPPER:t=>u(t[0]??null).toUpperCase(),LOWER:t=>u(t[0]??null).toLowerCase(),TRIM:t=>u(t[0]??null).trim(),LEFT:t=>u(t[0]??null).slice(0,s(t[1]??1)),RIGHT:t=>{const e=u(t[0]??null),n=s(t[1]??1);return n<=0?"":e.slice(-n)},MID:t=>{const e=u(t[0]??null),n=Math.max(0,s(t[1]??1)-1);return t.length>2?e.slice(n,n+Math.max(0,s(t[2]??0))):e.slice(n)},FIND:t=>u(t[1]??null).indexOf(u(t[0]??null),Math.max(0,s(t[2]??1)-1))+1,SUBSTITUTE:t=>u(t[0]??null).split(u(t[1]??null)).join(u(t[2]??null)),REPT:t=>u(t[0]??null).repeat(Math.max(0,Math.min(1e3,s(t[1]??0)))),T:t=>typeof t[0]=="string"?t[0]:"",VALUE:t=>{const e=u(t[0]??null).replace(/[^0-9.eE+-]/g,""),n=/\d/.test(e)?Number(e):NaN;return Number.isFinite(n)?n:null},ARRAYJOIN:t=>f([t[0]??null]).map(u).filter(Boolean).join(t.length>1?u(t[1]??null):", "),SUM:t=>f(t).reduce((e,n)=>e+s(n),0),AVERAGE:t=>{const e=f(t).filter(n=>!g(n));return e.length?e.reduce((n,r)=>n+s(r),0)/e.length:null},MAX:t=>{const e=f(t).filter(n=>!g(n)).map(s);return e.length?Math.max(...e):null},MIN:t=>{const e=f(t).filter(n=>!g(n)).map(s);return e.length?Math.min(...e):null},COUNT:t=>f(t).filter(e=>typeof e=="number").length,COUNTA:t=>f(t).filter(e=>!g(e)).length,ROUND:t=>{const e=10**s(t[1]??0);return Math.round(s(t[0]??null)*e)/e},ROUNDUP:t=>{const e=10**s(t[1]??0);return Math.ceil(s(t[0]??null)*e)/e},ROUNDDOWN:t=>{const e=10**s(t[1]??0);return Math.floor(s(t[0]??null)*e)/e},INT:t=>Math.floor(s(t[0]??null)),ABS:t=>Math.abs(s(t[0]??null)),MOD:t=>s(t[0]??null)%s(t[1]??1),POWER:t=>s(t[0]??null)**s(t[1]??1),SQRT:t=>Math.sqrt(s(t[0]??null)),CEILING:t=>{const e=s(t[1]??1);return e===0?0:k(Math.ceil(k(s(t[0]??null)/e))*e)},FLOOR:t=>{const e=s(t[1]??1);return e===0?0:k(Math.floor(k(s(t[0]??null)/e))*e)},TODAY:()=>{const t=new Date;return t.setHours(0,0,0,0),t},NOW:()=>new Date,YEAR:t=>h(t[0]??null)?.getFullYear()??null,MONTH:t=>{const e=h(t[0]??null);return e?e.getMonth()+1:null},DAY:t=>h(t[0]??null)?.getDate()??null,WEEKDAY:t=>h(t[0]??null)?.getDay()??null,DATEADD:t=>{const e=h(t[0]??null),n=t.length>2?D(t[2]??null):"d";return e&&n?F(e,s(t[1]??0),n):null},DATETIME_DIFF:t=>{const e=h(t[0]??null),n=h(t[1]??null),r=t.length>2?D(t[2]??null):"s";return e&&n&&r?$(e,n,r):null},IS_BEFORE:t=>{const e=h(t[0]??null),n=h(t[1]??null);return!!e&&!!n&&e<n},IS_AFTER:t=>{const e=h(t[0]??null),n=h(t[1]??null);return!!e&&!!n&&e>n},DATESTR:t=>{const e=h(t[0]??null);return e?`${e.getFullYear()}-${A(e.getMonth()+1)}-${A(e.getDate())}`:null}};function O(t,e,n){switch(t){case"=":return e===n;case"!=":return e!==n;case"<":return e<n;case">":return e>n;case"<=":return e<=n;default:return e>=n}}const b=new Set(["DATEADD","DATETIME_DIFF"]);export const FORMULA_FUNCTIONS=Object.keys(S).sort(),selfReferenceError=t=>new FormulaError(`A formula cannot read its own field {${t.trim()}}`);export function columnResolver(t,e=[]){const n=new Set(e.filter(r=>r!=null&&String(r).trim()!=="").map(r=>String(r).trim().toLowerCase()));return r=>{const l=r.trim().toLowerCase();if(n.has(l))throw selfReferenceError(r);const o=t.find(c=>String(c.header??"").trim().toLowerCase()===l||String(c.field??"").toLowerCase()===l);return o?String(o.field??o.id):null}}class C{constructor(e,n,r){this.toks=e,this.resolve=n,this.refs=r,this.i=0}peek(){return this.toks[this.i]}next(){return this.toks[this.i++]}expect(e,n){const r=this.next();if(!r||r.k!==e||n&&r.v!==n)throw new FormulaError(`Expected "${n??e}"${r?` at ${r.at+1}`:" at the end"}`);return r}parse(){const e=this.compare();if(this.peek())throw new FormulaError(`Unexpected "${this.peek().v}" at ${this.peek().at+1}`);return e}compare(){let e=this.concat();for(let n=this.peek();n&&n.k==="op"&&["=","!=","<",">","<=",">="].includes(n.v);n=this.peek()){this.next();const r=n.v,l=e,o=this.concat();e=c=>{const i=l(c),a=o(c);if(i instanceof Date||a instanceof Date){const M=h(i),N=h(a);return!M||!N?r==="!=":O(r,M.getTime(),N.getTime())}const m=typeof i=="number"||typeof a=="number",p=m?s(i):u(i),R=m?s(a):u(a);return O(r,p,R)}}return e}concat(){let e=this.add();for(;this.peek()?.k==="op"&&this.peek().v==="&";){this.next();const n=e,r=this.add();e=l=>u(n(l))+u(r(l))}return e}add(){let e=this.mul();for(let n=this.peek();n&&n.k==="op"&&(n.v==="+"||n.v==="-");n=this.peek()){this.next();const r=e,l=this.mul(),o=n.v==="+";e=c=>o?s(r(c))+s(l(c)):s(r(c))-s(l(c))}return e}mul(){let e=this.unary();for(let n=this.peek();n&&n.k==="op"&&(n.v==="*"||n.v==="/");n=this.peek()){this.next();const r=e,l=this.unary(),o=n.v==="*";e=c=>{if(o)return s(r(c))*s(l(c));const i=s(l(c));return i===0?null:s(r(c))/i}}return e}unary(){const e=this.peek();if(e?.k==="op"&&e.v==="-"){this.next();const n=this.unary();return r=>-s(n(r))}return this.primary()}primary(){const e=this.next();if(!e)throw new FormulaError("The formula ends too early");if(e.k==="num"){const n=Number(e.v);return()=>n}if(e.k==="str"){const n=e.v;return()=>n}if(e.k==="ref"){const n=this.resolve(e.v);if(n==null)throw new FormulaError(`No field named "${e.v}"`);return this.refs.add(n),r=>r?.[n]??null}if(e.k==="("){const n=this.compare();return this.expect(")"),n}if(e.k==="id"){const n=e.v.toUpperCase();if(n==="TRUE"&&this.peek()?.k!=="(")return()=>!0;if(n==="FALSE"&&this.peek()?.k!=="(")return()=>!1;const r=S[n];if(!r)throw new FormulaError(`Unknown function ${e.v}`);this.expect("(");const l=[],o=[],c=()=>{const a=this.i;l.push(this.compare());const m=this.i===a+1?this.toks[a]:void 0;o.push(m?.k==="str"?m.v:void 0)};if(this.peek()?.k!==")")for(c();this.peek()?.k===",";)this.next(),c();this.expect(")");const i=o[2];if(b.has(n)&&i!==void 0&&!D(i))throw new FormulaError(`Unknown unit "${i}" in ${n}: use ms, seconds, minutes, hours, days, weeks, months or years`);return n==="IF"?a=>d(l[0]?.(a)??null)?l[1]?.(a)??null:l[2]?.(a)??null:n==="SWITCH"?a=>{if(!l.length)return null;const m=u(l[0](a));for(let p=1;p+1<l.length;p+=2)if(m===u(l[p](a)))return l[p+1](a);return l.length%2===0?l[l.length-1](a):null}:a=>r(l.map(m=>m(a)))}throw new FormulaError(`Unexpected "${e.v}" at ${e.at+1}`)}}export function compileFormula(t,e){if(!t.trim())throw new FormulaError("The formula is empty");const n=new Set,r=new C(w(t),e,n).parse();return{fn:l=>{try{const o=r(l);return typeof o=="number"&&!Number.isFinite(o)?null:o}catch{return null}},refs:[...n]}}export function renameFormulaRefs(t,e){let n;try{n=w(t)}catch{return t}let r="",l=0;for(const o of n){if(o.k!=="ref")continue;const c=e(o.v);if(c==null)continue;const i=t.indexOf("}",o.at);r+=`${t.slice(l,o.at)}{${c}}`,l=i+1}return l?r+t.slice(l):t}export function formulaRefs(t,e){let n;try{n=w(t)}catch{return[]}const r=new Set;for(const l of n)if(l.k==="ref")try{const o=e(l.v);o!=null&&r.add(o)}catch{}return[...r]}export function formulaReaders(t,e){const n=new Set([e.field,e.id].filter(l=>l!=null&&l!=="").map(String));if(!n.size)return[];const r=columnResolver(t);return t.filter(l=>l.fieldType!=="formula"||n.has(String(l.field??l.id??""))?!1:formulaRefs(String(l.fieldProps?.formula??""),r).some(o=>n.has(o)))}export function formulaError(t,e){try{return compileFormula(t,e),null}catch(n){return n instanceof FormulaError?n.message:"The formula is not valid"}}
1
+ import{toDate as $}from"./format.js";export class FormulaError extends Error{}function b(e){const n=[];let t=0;for(;t<e.length;){const r=e[t];if(/\s/.test(r)){t++;continue}if(r==="{"){const i=e.indexOf("}",t);if(i<0)throw new FormulaError(`Unclosed "{" at ${t+1}`);n.push({k:"ref",v:e.slice(t+1,i).trim(),at:t}),t=i+1;continue}if(r==='"'||r==="'"){let i=t+1,c="";for(;i<e.length&&e[i]!==r;){if(e[i]==="\\"&&i+1<e.length){c+=e[i+1],i+=2;continue}c+=e[i++]}if(i>=e.length)throw new FormulaError(`Unclosed text at ${t+1}`);n.push({k:"str",v:c,at:t}),t=i+1;continue}const l=/^\d+(\.\d+)?|^\.\d+/.exec(e.slice(t));if(l){n.push({k:"num",v:l[0],at:t}),t+=l[0].length;continue}const s=/^[A-Za-z_][A-Za-z0-9_]*/.exec(e.slice(t));if(s){n.push({k:"id",v:s[0],at:t}),t+=s[0].length;continue}const f=/^(!=|<=|>=|<>|[-+*/&=<>])/.exec(e.slice(t));if(f){n.push({k:"op",v:f[0]==="<>"?"!=":f[0],at:t}),t+=f[0].length;continue}if(r==="("||r===")"||r===","){n.push({k:r,v:r,at:t}),t++;continue}throw new FormulaError(`Unexpected "${r}" at ${t+1}`)}return n}const y=e=>e==null||e===""||Array.isArray(e)&&e.length===0,o=e=>{if(typeof e=="number")return e;if(typeof e=="boolean")return e?1:0;if(e instanceof Date)return e.getTime();if(e==null||e==="")return 0;if(Array.isArray(e))return e.reduce((t,r)=>t+o(r),0);const n=Number(e);return Number.isFinite(n)?n:NaN},u=e=>e==null?"":e instanceof Date?e.toISOString():Array.isArray(e)?e.map(u).join(", "):String(e),A=e=>!y(e)&&e!==!1&&e!==0,ne=/^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;export function isoDate(e){const n=e.trim();return ne.test(n)?$(n):null}const h=e=>{if(e instanceof Date)return Number.isNaN(e.getTime())?null:e;if(e==null||e===""||typeof e=="boolean")return null;if(typeof e=="number")return $(e);const n=u(e).trim();return isoDate(n)??(/\d{4}/.test(n)&&/[/\s,.-]/.test(n)?$(n):null)},d=e=>e.flatMap(n=>Array.isArray(n)?n:[n]),M=e=>String(e).padStart(2,"0"),R=e=>Number(e.toPrecision(12)),re={milliseconds:"ms",millisecond:"ms",ms:"ms",seconds:"s",second:"s",s:"s",minutes:"m",minute:"m",m:"m",hours:"h",hour:"h",h:"h",days:"d",day:"d",d:"d",weeks:"w",week:"w",w:"w",months:"mo",month:"mo",quarters:"q",quarter:"q",q:"q",years:"y",year:"y",y:"y"},k={ms:1,s:1e3,m:6e4,h:36e5},x=e=>re[u(e).trim().toLowerCase()]??null;function W(e,n){const t=new Date(e),r=t.getDate();return t.setDate(1),t.setMonth(t.getMonth()+n),t.setDate(Math.min(r,new Date(t.getFullYear(),t.getMonth()+1,0).getDate())),t}function le(e,n,t){if(k[t])return new Date(e.getTime()+n*k[t]);if(t==="mo"||t==="q"||t==="y")return W(e,Math.trunc(n)*(t==="y"?12:t==="q"?3:1));const r=n*(t==="w"?7:1),l=new Date(e);return l.setDate(l.getDate()+Math.trunc(r)),new Date(l.getTime()+(r-Math.trunc(r))*864e5)}const L=e=>e.getTime()-e.getTimezoneOffset()*6e4;function _(e,n,t){if(k[t])return Math.trunc((e.getTime()-n.getTime())/k[t]);if(t==="d"||t==="w")return Math.trunc((L(e)-L(n))/(t==="w"?6048e5:864e5));let r=(e.getFullYear()-n.getFullYear())*12+e.getMonth()-n.getMonth();const l=W(n,r).getTime();return r>0&&l>e.getTime()?r-=1:r<0&&l<e.getTime()&&(r+=1),t==="y"?Math.trunc(r/12):t==="q"?Math.trunc(r/3):r}function Y(e,n){if(n==="ms")return e.getTime();const t=new Date(e);return n==="s"?t.setMilliseconds(0):n==="m"?t.setSeconds(0,0):n==="h"?t.setMinutes(0,0,0):(t.setHours(0,0,0,0),n==="w"&&t.setDate(t.getDate()-t.getDay()),(n==="mo"||n==="q"||n==="y")&&t.setDate(1),n==="q"&&t.setMonth(t.getMonth()-t.getMonth()%3),n==="y"&&t.setMonth(0),t.getTime())}const O=e=>`${e.getFullYear()}-${M(e.getMonth()+1)}-${M(e.getDate())}`;function z(e){const n=d([e??null]).flatMap(t=>typeof t=="string"?t.split(","):[t]);return new Set(n.map(t=>h(typeof t=="string"?t.trim():t)).filter(t=>!!t).map(O))}const X=(e,n)=>e.getDay()!==0&&e.getDay()!==6&&!n.has(O(e)),q=1e5;class se extends Date{}function v(e,n){const t=new se(e.getTime()),r=e;return t.locale=n.locale??r.locale,t.zone=n.zone??r.zone,t}const j=new Map;function G(e){let n=j.get(e);return n||(n=new Intl.DateTimeFormat("en-US",{timeZone:e,hourCycle:"h23",weekday:"short",year:"numeric",month:"numeric",day:"numeric",hour:"numeric",minute:"numeric",second:"numeric"}),j.set(e,n)),n}const oe=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function ue(e){const n=e.zone,t=e.getMilliseconds();if(!n)return{y:e.getFullYear(),mo:e.getMonth(),d:e.getDate(),h:e.getHours(),mi:e.getMinutes(),s:e.getSeconds(),ms:t,wd:e.getDay(),offset:-e.getTimezoneOffset()};const r={};for(const s of G(n).formatToParts(e))r[s.type]=s.value;const l={y:+r.year,mo:+r.month-1,d:+r.day,h:+r.hour%24,mi:+r.minute,s:+r.second,ms:t,wd:oe.indexOf(r.weekday),offset:0};return l.offset=Math.round((Date.UTC(l.y,l.mo,l.d,l.h,l.mi,l.s,t)-e.getTime())/6e4),l}const K=new Map;function I(e,n,t,r){const l=`${e??"en"}|${n}|${t}`;let s=K.get(l);return s||K.set(l,s=new Intl.DateTimeFormat(e??"en",{[n]:t,timeZone:"UTC"})),s.format(n==="month"?Date.UTC(2023,r,1):Date.UTC(2023,0,1+r))}const ie=e=>{const n=e%100;return`${e}${n>=11&&n<=13?"th":["th","st","nd","rd"][e%10]??"th"}`},B=(e,n)=>{const t=Math.abs(e);return`${e<0?"-":"+"}${M(Math.floor(t/60))}${n?":":""}${M(t%60)}`},ce={LTS:"h:mm:ss A",LT:"h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A",LLL:"MMMM D, YYYY h:mm A",LL:"MMMM D, YYYY",L:"MM/DD/YYYY"},ae=/\[([^\]]*)]|YYYY|YY|Q|MMMM|MMM|MM|M|DDDD|DDD|Do|DD|D|dddd|ddd|d|HH|H|hh|h|mm|m|ss|s|SSS|SS|S|A|a|ZZ|Z|X|x/g;function fe(e,n){const t=ue(e),r=e.locale,l=n.replace(/\[[^\]]*]|LTS|LT|LLLL|LLL|LL|L/g,i=>ce[i]??i),s=t.h%12||12,f=Math.round((Date.UTC(t.y,t.mo,t.d)-Date.UTC(t.y,0,1))/864e5)+1;return l.replace(ae,(i,c)=>{if(c!==void 0)return c;switch(i){case"YYYY":return String(t.y).padStart(4,"0");case"YY":return M(t.y%100);case"Q":return String(Math.floor(t.mo/3)+1);case"MMMM":return I(r,"month","long",t.mo);case"MMM":return I(r,"month","short",t.mo);case"MM":return M(t.mo+1);case"M":return String(t.mo+1);case"DDDD":return String(f).padStart(3,"0");case"DDD":return String(f);case"Do":return ie(t.d);case"DD":return M(t.d);case"D":return String(t.d);case"dddd":return I(r,"weekday","long",t.wd);case"ddd":return I(r,"weekday","short",t.wd);case"d":return String(t.wd);case"HH":return M(t.h);case"H":return String(t.h);case"hh":return M(s);case"h":return String(s);case"mm":return M(t.mi);case"m":return String(t.mi);case"ss":return M(t.s);case"s":return String(t.s);case"SSS":return String(t.ms).padStart(3,"0");case"SS":return M(Math.floor(t.ms/10));case"S":return String(Math.floor(t.ms/100));case"A":return t.h<12?"AM":"PM";case"a":return t.h<12?"am":"pm";case"ZZ":return B(t.offset,!1);case"Z":return B(t.offset,!0);case"X":return String(Math.floor(e.getTime()/1e3));default:return String(e.getTime())}})}const he=["january","february","march","april","may","june","july","august","september","october","november","december"],me=/\[([^\]]*)]|YYYY|YY|MMMM|MMM|MM|M|Do|DD|D|dddd|ddd|HH|H|hh|h|mm|m|ss|s|SSS|A|a|ZZ|Z|X|x/g;function de(e,n){const t=[];let r="^\\s*",l=0;const s=D=>D.replace(/[.*+?^${}()|[\]\\]/g,"\\$&").replace(/\s+/g,"\\s+");for(const D of n.matchAll(me)){if(r+=s(n.slice(l,D.index)),l=D.index+D[0].length,D[1]!==void 0){r+=s(D[1]);continue}const a=D[0];t.push(a),r+=a==="YYYY"?"(\\d{4})":a==="MMMM"||a==="MMM"||a==="dddd"||a==="ddd"?"([A-Za-z]+)\\.?":a==="Do"?"(\\d{1,2})(?:st|nd|rd|th)":a==="SSS"?"(\\d{1,3})":a==="A"||a==="a"?"([AaPp][Mm])":a==="Z"||a==="ZZ"?"(Z|[+-]\\d{2}:?\\d{2})":a==="X"||a==="x"?"(-?\\d+)":"(\\d{1,2})"}r+=`${s(n.slice(l))}\\s*$`;const f=new RegExp(r,"i").exec(e);if(!f)return null;let i=new Date().getFullYear(),c=0,m=1,g=0,E=0,S=0,w=0,U=null,N=null;for(let D=0;D<t.length;D++){const a=t[D],T=f[D+1],p=Number(T);if(a==="X"||a==="x")return new Date(a==="X"?p*1e3:p);if(a==="YYYY")i=p;else if(a==="YY")i=p+(p<69?2e3:1900);else if(a==="MMMM"||a==="MMM"){const P=he.findIndex(te=>te.startsWith(T.toLowerCase().slice(0,3)));if(P<0)return null;c=P}else a==="MM"||a==="M"?c=p-1:a==="DD"||a==="D"||a==="Do"?m=p:a==="HH"||a==="H"||a==="hh"||a==="h"?g=p:a==="mm"||a==="m"?E=p:a==="ss"||a==="s"?S=p:a==="SSS"?w=Number(T.padEnd(3,"0")):a==="A"||a==="a"?U=T.toLowerCase()==="pm":(a==="Z"||a==="ZZ")&&(N=T.toUpperCase()==="Z"?0:(T[0]==="-"?-1:1)*(Number(T.slice(1,3))*60+Number(T.slice(-2))))}if(U!=null&&(g=g%12+(U?12:0)),c<0||c>11||m<1||m>31||g>23||E>59||S>59)return null;const C=N==null?new Date(i,c,m,g,E,S,w):new Date(Date.UTC(i,c,m,g,E,S,w)-N*6e4);return N==null&&C.getDate()!==m||Number.isNaN(C.getTime())?null:C}const F=new Map;function H(e,n=!1){const t=`${n?"g":""}|${e}`;let r=F.get(t);if(!r){const l=/^\(\?([ims]+)\)/.exec(e);r=new RegExp(l?e.slice(l[0].length):e,`${l?.[1]??""}${n?"g":""}`),F.size>200&&F.clear(),F.set(t,r)}return r.lastIndex=0,r}const Z="#ERROR",V=e=>`${e instanceof Date?"d":typeof e}:${u(e)}`;function Me(e,n,t){const r=n<0?e.length+n:Math.max(0,n-1),l=t==null?e.length:t<0?e.length+t+1:t;return e.slice(r,l)}function Q(e,n){const t=e<0?-1:1;let r=Math.ceil(Math.abs(e));return r%2===1!==n&&(r+=1),t*r}const J={IF:e=>A(e[0]??null)?e[1]??null:e[2]??null,AND:e=>d(e).every(A),OR:e=>d(e).some(A),NOT:e=>!A(e[0]??null),XOR:e=>d(e).filter(A).length%2===1,TRUE:()=>!0,FALSE:()=>!1,BLANK:()=>null,ERROR:()=>{throw new FormulaError("ERROR()")},ISERROR:e=>e[0]===Z,RECORD_ID:()=>null,SWITCH:e=>{for(let n=1;n+1<e.length;n+=2)if(u(e[0]??null)===u(e[n]??null))return e[n+1]??null;return e.length%2===0?e[e.length-1]??null:null},CONCATENATE:e=>e.map(u).join(""),LEN:e=>u(e[0]??null).length,UPPER:e=>u(e[0]??null).toUpperCase(),LOWER:e=>u(e[0]??null).toLowerCase(),TRIM:e=>u(e[0]??null).trim(),LEFT:e=>u(e[0]??null).slice(0,o(e[1]??1)),RIGHT:e=>{const n=u(e[0]??null),t=o(e[1]??1);return t<=0?"":n.slice(-t)},MID:e=>{const n=u(e[0]??null),t=Math.max(0,o(e[1]??1)-1);return e.length>2?n.slice(t,t+Math.max(0,o(e[2]??0))):n.slice(t)},FIND:e=>u(e[1]??null).indexOf(u(e[0]??null),Math.max(0,o(e[2]??1)-1))+1,SEARCH:e=>{const n=u(e[1]??null).indexOf(u(e[0]??null),Math.max(0,o(e[2]??1)-1));return n<0?null:n+1},SUBSTITUTE:e=>{const n=u(e[0]??null).split(u(e[1]??null));if(e.length<4)return n.join(u(e[2]??null));const t=o(e[3]??null);return n.reduce((r,l,s)=>s===0?l:r+u(s===t?e[2]??null:e[1]??null)+l,"")},REPLACE:e=>{const n=u(e[0]??null),t=Math.max(0,o(e[1]??1)-1);return n.slice(0,t)+u(e[3]??null)+n.slice(t+Math.max(0,o(e[2]??0)))},ENCODE_URL_COMPONENT:e=>encodeURIComponent(u(e[0]??null)),REGEX_MATCH:e=>H(u(e[1]??null)).test(u(e[0]??null)),REGEX_EXTRACT:e=>H(u(e[1]??null)).exec(u(e[0]??null))?.[0]??null,REGEX_REPLACE:e=>u(e[0]??null).replace(H(u(e[1]??null),!0),u(e[2]??null)),REPT:e=>u(e[0]??null).repeat(Math.max(0,Math.min(1e3,o(e[1]??0)))),T:e=>typeof e[0]=="string"?e[0]:"",VALUE:e=>{const n=u(e[0]??null).replace(/[^0-9.eE+-]/g,""),t=/\d/.test(n)?Number(n):NaN;return Number.isFinite(t)?t:null},ARRAYJOIN:e=>d([e[0]??null]).map(u).filter(Boolean).join(e.length>1?u(e[1]??null):", "),ARRAYCOMPACT:e=>d([e[0]??null]).filter(n=>n!=null&&n!==""),ARRAYFLATTEN:e=>e.flat(1/0),ARRAYUNIQUE:e=>{const n=new Set;return d([e[0]??null]).filter(t=>!n.has(V(t))&&!!n.add(V(t)))},ARRAYSLICE:e=>Me(d([e[0]??null]),o(e[1]??1),e.length>2?o(e[2]??null):void 0),SUM:e=>d(e).reduce((n,t)=>n+o(t),0),AVERAGE:e=>{const n=d(e).filter(t=>!y(t));return n.length?n.reduce((t,r)=>t+o(r),0)/n.length:null},MAX:e=>{const n=d(e).filter(t=>!y(t)).map(o);return n.length?Math.max(...n):null},MIN:e=>{const n=d(e).filter(t=>!y(t)).map(o);return n.length?Math.min(...n):null},COUNT:e=>d(e).filter(n=>typeof n=="number").length,COUNTA:e=>d(e).filter(n=>!y(n)).length,COUNTALL:e=>d(e).length,ROUND:e=>{const n=10**o(e[1]??0);return Math.round(o(e[0]??null)*n)/n},ROUNDUP:e=>{const n=10**o(e[1]??0),t=o(e[0]??null);return Math.sign(t)*Math.ceil(R(Math.abs(t)*n))/n},ROUNDDOWN:e=>{const n=10**o(e[1]??0),t=o(e[0]??null);return Math.sign(t)*Math.floor(R(Math.abs(t)*n))/n},INT:e=>Math.floor(o(e[0]??null)),ABS:e=>Math.abs(o(e[0]??null)),MOD:e=>o(e[0]??null)%o(e[1]??1),POWER:e=>o(e[0]??null)**o(e[1]??1),SQRT:e=>Math.sqrt(o(e[0]??null)),EXP:e=>Math.exp(o(e[0]??null)),LOG:e=>Math.log(o(e[0]??null))/Math.log(e.length>1?o(e[1]??null):10),EVEN:e=>Q(o(e[0]??null),!1),ODD:e=>Q(o(e[0]??null),!0),CEILING:e=>{const n=o(e[1]??1);return n===0?0:R(Math.ceil(R(o(e[0]??null)/n))*n)},FLOOR:e=>{const n=o(e[1]??1);return n===0?0:R(Math.floor(R(o(e[0]??null)/n))*n)},TODAY:()=>{const e=new Date;return e.setHours(0,0,0,0),e},NOW:()=>new Date,YEAR:e=>h(e[0]??null)?.getFullYear()??null,MONTH:e=>{const n=h(e[0]??null);return n?n.getMonth()+1:null},DAY:e=>h(e[0]??null)?.getDate()??null,HOUR:e=>h(e[0]??null)?.getHours()??null,MINUTE:e=>h(e[0]??null)?.getMinutes()??null,SECOND:e=>h(e[0]??null)?.getSeconds()??null,WEEKDAY:e=>{const n=h(e[0]??null);return n?/^mon/i.test(u(e[1]??null))?(n.getDay()+6)%7:n.getDay():null},WEEKNUM:e=>{const n=h(e[0]??null);if(!n)return null;const t=/^mon/i.test(u(e[1]??null))?1:0,r=new Date(n.getFullYear(),0,1),l=Math.round((L(new Date(n.getFullYear(),n.getMonth(),n.getDate()))-L(r))/864e5);return Math.floor((l+(r.getDay()-t+7)%7)/7)+1},DATEADD:e=>{const n=h(e[0]??null),t=e.length>2?x(e[2]??null):"d";return n&&t?le(n,o(e[1]??0),t):null},DATETIME_DIFF:e=>{const n=h(e[0]??null),t=h(e[1]??null),r=e.length>2?x(e[2]??null):"s";return n&&t&&r?_(n,t,r):null},IS_BEFORE:e=>{const n=h(e[0]??null),t=h(e[1]??null);return!!n&&!!t&&n<t},IS_AFTER:e=>{const n=h(e[0]??null),t=h(e[1]??null);return!!n&&!!t&&n>t},IS_SAME:e=>{const n=h(e[0]??null),t=h(e[1]??null),r=e.length>2?x(e[2]??null):"ms";return!!n&&!!t&&!!r&&Y(n,r)===Y(t,r)},DATESTR:e=>{const n=h(e[0]??null);return n?O(n):null},TIMESTR:e=>{const n=h(e[0]??null);return n?`${M(n.getHours())}:${M(n.getMinutes())}:${M(n.getSeconds())}`:null},DATETIME_FORMAT:e=>{const n=h(e[0]??null);return n?fe(n,e.length>1&&!y(e[1]??null)?u(e[1]??null):"YYYY-MM-DDTHH:mm:ss.SSSZ"):null},DATETIME_PARSE:e=>e.length>1&&!y(e[1]??null)?de(u(e[0]??null),u(e[1]??null)):h(e[0]??null),SET_LOCALE:e=>{const n=h(e[0]??null),t=u(e[1]??null).trim();return!n||!t?n:v(n,{locale:Intl.DateTimeFormat.supportedLocalesOf(t)[0]??t})},SET_TIMEZONE:e=>{const n=h(e[0]??null),t=u(e[1]??null).trim();return!n||!t?n:(G(t),v(n,{zone:t}))},TONOW:e=>{const n=h(e[0]??null);return n?_(new Date(Y(new Date,"d")),new Date(Y(n,"d")),"d"):null},FROMNOW:e=>{const n=h(e[0]??null);return n?_(new Date(Y(n,"d")),new Date(Y(new Date,"d")),"d"):null},WORKDAY:e=>{const n=h(e[0]??null);if(!n)return null;const t=Math.trunc(o(e[1]??0)),r=t<0?-1:1,l=z(e[2]),s=new Date(n);for(let f=Math.abs(t),i=0;f>0;){if(++i>q)return null;s.setDate(s.getDate()+r),X(s,l)&&(f-=1)}return s},WORKDAY_DIFF:e=>{const n=h(e[0]??null),t=h(e[1]??null);if(!n||!t)return null;const r=z(e[2]),l=n>t?-1:1,s=new Date(l>0?n:t),f=O(l>0?t:n);let i=0;for(let c=0;O(s)<=f;c++){if(c>q)return null;X(s,r)&&(i+=1),s.setDate(s.getDate()+1)}return l*i}};function ee(e,n,t){switch(e){case"=":return n===t;case"!=":return n!==t;case"<":return n<t;case">":return n>t;case"<=":return n<=t;default:return n>=t}}const ge=new Set(["DATEADD","DATETIME_DIFF","IS_SAME"]);export const FORMULA_FUNCTIONS=Object.keys(J).sort(),selfReferenceError=e=>new FormulaError(`A formula cannot read its own field {${e.trim()}}`);export function columnResolver(e,n=[]){const t=new Set(n.filter(r=>r!=null&&String(r).trim()!=="").map(r=>String(r).trim().toLowerCase()));return r=>{const l=r.trim().toLowerCase();if(t.has(l))throw selfReferenceError(r);const s=e.find(f=>String(f.header??"").trim().toLowerCase()===l||String(f.field??"").toLowerCase()===l);return s?String(s.field??s.id):null}}class De{constructor(n,t,r){this.toks=n,this.resolve=t,this.refs=r,this.i=0}peek(){return this.toks[this.i]}next(){return this.toks[this.i++]}expect(n,t){const r=this.next();if(!r||r.k!==n||t&&r.v!==t)throw new FormulaError(`Expected "${t??n}"${r?` at ${r.at+1}`:" at the end"}`);return r}parse(){const n=this.compare();if(this.peek())throw new FormulaError(`Unexpected "${this.peek().v}" at ${this.peek().at+1}`);return n}compare(){let n=this.concat();for(let t=this.peek();t&&t.k==="op"&&["=","!=","<",">","<=",">="].includes(t.v);t=this.peek()){this.next();const r=t.v,l=n,s=this.concat();n=f=>{const i=l(f),c=s(f);if(i instanceof Date||c instanceof Date){const S=h(i),w=h(c);return!S||!w?r==="!=":ee(r,S.getTime(),w.getTime())}const m=typeof i=="number"||typeof c=="number",g=m?o(i):u(i),E=m?o(c):u(c);return ee(r,g,E)}}return n}concat(){let n=this.add();for(;this.peek()?.k==="op"&&this.peek().v==="&";){this.next();const t=n,r=this.add();n=l=>u(t(l))+u(r(l))}return n}add(){let n=this.mul();for(let t=this.peek();t&&t.k==="op"&&(t.v==="+"||t.v==="-");t=this.peek()){this.next();const r=n,l=this.mul(),s=t.v==="+";n=f=>s?o(r(f))+o(l(f)):o(r(f))-o(l(f))}return n}mul(){let n=this.unary();for(let t=this.peek();t&&t.k==="op"&&(t.v==="*"||t.v==="/");t=this.peek()){this.next();const r=n,l=this.unary(),s=t.v==="*";n=f=>{if(s)return o(r(f))*o(l(f));const i=o(l(f));return i===0?null:o(r(f))/i}}return n}unary(){const n=this.peek();if(n?.k==="op"&&n.v==="-"){this.next();const t=this.unary();return r=>-o(t(r))}return this.primary()}primary(){const n=this.next();if(!n)throw new FormulaError("The formula ends too early");if(n.k==="num"){const t=Number(n.v);return()=>t}if(n.k==="str"){const t=n.v;return()=>t}if(n.k==="ref"){const t=this.resolve(n.v);if(t==null)throw new FormulaError(`No field named "${n.v}"`);return this.refs.add(t),r=>r?.[t]??null}if(n.k==="("){const t=this.compare();return this.expect(")"),t}if(n.k==="id"){const t=n.v.toUpperCase();if(t==="TRUE"&&this.peek()?.k!=="(")return()=>!0;if(t==="FALSE"&&this.peek()?.k!=="(")return()=>!1;const r=J[t];if(!r)throw new FormulaError(`Unknown function ${n.v}`);this.expect("(");const l=[],s=[],f=()=>{const c=this.i;l.push(this.compare());const m=this.i===c+1?this.toks[c]:void 0;s.push(m?.k==="str"?m.v:void 0)};if(this.peek()?.k!==")")for(f();this.peek()?.k===",";)this.next(),f();this.expect(")");const i=s[2];if(ge.has(t)&&i!==void 0&&!x(i))throw new FormulaError(`Unknown unit "${i}" in ${t}: use ms, seconds, minutes, hours, days, weeks, months, quarters or years`);return t==="RECORD_ID"?c=>c?.id==null?null:String(c.id):t==="ISERROR"?c=>{try{const m=l[0]?.(c)??null;return m===Z||typeof m=="number"&&!Number.isFinite(m)}catch{return!0}}:t==="IF"?c=>A(l[0]?.(c)??null)?l[1]?.(c)??null:l[2]?.(c)??null:t==="SWITCH"?c=>{if(!l.length)return null;const m=u(l[0](c));for(let g=1;g+1<l.length;g+=2)if(m===u(l[g](c)))return l[g+1](c);return l.length%2===0?l[l.length-1](c):null}:c=>r(l.map(m=>m(c)))}throw new FormulaError(`Unexpected "${n.v}" at ${n.at+1}`)}}export function compileFormula(e,n){if(!e.trim())throw new FormulaError("The formula is empty");const t=new Set,r=new De(b(e),n,t).parse();return{fn:l=>{try{const s=r(l);return typeof s=="number"&&!Number.isFinite(s)?null:s}catch(s){return s instanceof FormulaError?Z:null}},refs:[...t]}}export function renameFormulaRefs(e,n){let t;try{t=b(e)}catch{return e}let r="",l=0;for(const s of t){if(s.k!=="ref")continue;const f=n(s.v);if(f==null)continue;const i=e.indexOf("}",s.at);r+=`${e.slice(l,s.at)}{${f}}`,l=i+1}return l?r+e.slice(l):e}export function formulaRefs(e,n){let t;try{t=b(e)}catch{return[]}const r=new Set;for(const l of t)if(l.k==="ref")try{const s=n(l.v);s!=null&&r.add(s)}catch{}return[...r]}export function formulaReaders(e,n){const t=new Set([n.field,n.id].filter(l=>l!=null&&l!=="").map(String));if(!t.size)return[];const r=columnResolver(e);return e.filter(l=>l.fieldType!=="formula"||t.has(String(l.field??l.id??""))?!1:formulaRefs(String(l.fieldProps?.formula??""),r).some(s=>t.has(s)))}export function formulaError(e,n){try{return compileFormula(e,n),null}catch(t){return t instanceof FormulaError?t.message:"The formula is not valid"}}
@@ -57,4 +57,12 @@ type TreeRow = {
57
57
  export declare function leafFilter(ctrl: any): ((row: unknown) => boolean) | null;
58
58
  /** The records under a group row, those the filter keeps. */
59
59
  export declare function groupLeaves<TRow extends TreeRow>(row: TRow, keep: ((row: unknown) => boolean) | null): TRow[];
60
+ /**
61
+ * Bring the row at display `index` into view, scrolling only when it is not
62
+ * already all on screen: a record added where the user is looking must not
63
+ * move the grid under them. A row the virtualizer has not drawn is off screen.
64
+ */
65
+ export declare function revealRow(ctrl: any, api: {
66
+ scrollToRow(index: number): void;
67
+ }, index: number): void;
60
68
  export {};
@@ -1 +1 @@
1
- import{getAdvancedFilterEngine as d}from"@svgrid/grid";const s=new WeakMap,u=new WeakMap;export function rememberGrid(e){const n=e?.buildApi?.();n&&!s.has(n)&&(s.set(n,e),typeof n.getData=="function"&&u.set(n.getData,e))}export function gridOf(e){if(!e||typeof e!="object")return;const n=e.getData;return s.get(e)??(typeof n=="function"?u.get(n):void 0)}export const columnIdOf=e=>String(e.id??e.field??"");export function fieldColumns(e){const n=e?.hiddenColumns??{},t=f(e?.internalColumns??[]).filter(o=>o.field!=null),r=new Map(t.map(o=>[columnIdOf(o),o])),i=(e?.allColumns??[]).map(o=>o.id).filter(o=>r.has(o)),l=t.map(columnIdOf).filter(o=>!i.includes(o));return[...i,...l].map(o=>{const a=r.get(o);return{id:o,field:String(a.field),header:typeof a.header=="string"?a.header:o,fieldType:a.fieldType,def:a,visible:!n[o]&&a.visible!==!1&&i.includes(o)}})}function f(e){return e.flatMap(n=>Array.isArray(n.columns)&&n.columns.length?f(n.columns):[n])}export function primaryIdOf(e){const n=e?.props?.primaryField;if(typeof n!="string"||!n)return null;const t=f(e?.internalColumns??[]),r=t.find(i=>columnIdOf(i)===n)??t.find(i=>i.field===n);return r?columnIdOf(r):null}export function writeCell(e,n,t,r){const i=(e?.allRows??[]).findIndex(l=>l.id===n);return i<0||!e.startEditing?.(i,t)?!1:(e.updateEditingCellValue(r),e.saveEditingCell(),!0)}export function cellValue(e,n,t){const r=n.getCellValueByColumnId?n.getCellValueByColumnId(t.id):n.original?.[t.field];return e?.getCellDisplayValue?e.getCellDisplayValue(n.id,t.id,r):r}export function cellText(e,n,t){const r=e.def.formatter;if(r)try{return String(r({value:n,row:t,column:{id:e.id,columnDef:e.def}})??"")}catch{}return Array.isArray(n)?n.map(i=>i&&typeof i=="object"?i.name??"":String(i)).join(", "):n==null?"":String(n)}export function dataRows(e){return(e?.allRows??[]).filter(n=>n.__treeRow||!(typeof n.getCanExpand=="function"&&n.getCanExpand()))}const p=e=>!e.__treeRow&&typeof e.getCanExpand=="function"&&e.getCanExpand();export function leafFilter(e){const n=e?.advancedFilter,t=n?d():null;if(!t)return null;try{return t(n,{getValue:e.getRowColumnValue,rows:[]})??null}catch{return null}}export function groupLeaves(e,n){const t=[],r=i=>{for(const l of i.subRows??[])p(l)?r(l):(!n||n(l))&&t.push(l)};return r(e),t}
1
+ import{getAdvancedFilterEngine as c}from"@svgrid/grid";const s=new WeakMap,d=new WeakMap;export function rememberGrid(e){const t=e?.buildApi?.();t&&!s.has(t)&&(s.set(t,e),typeof t.getData=="function"&&d.set(t.getData,e))}export function gridOf(e){if(!e||typeof e!="object")return;const t=e.getData;return s.get(e)??(typeof t=="function"?d.get(t):void 0)}export const columnIdOf=e=>String(e.id??e.field??"");export function fieldColumns(e){const t=e?.hiddenColumns??{},n=u(e?.internalColumns??[]).filter(r=>r.field!=null),o=new Map(n.map(r=>[columnIdOf(r),r])),i=(e?.allColumns??[]).map(r=>r.id).filter(r=>o.has(r)),l=n.map(columnIdOf).filter(r=>!i.includes(r));return[...i,...l].map(r=>{const a=o.get(r);return{id:r,field:String(a.field),header:typeof a.header=="string"?a.header:r,fieldType:a.fieldType,def:a,visible:!t[r]&&a.visible!==!1&&i.includes(r)}})}function u(e){return e.flatMap(t=>Array.isArray(t.columns)&&t.columns.length?u(t.columns):[t])}export function primaryIdOf(e){const t=e?.props?.primaryField;if(typeof t!="string"||!t)return null;const n=u(e?.internalColumns??[]),o=n.find(i=>columnIdOf(i)===t)??n.find(i=>i.field===t);return o?columnIdOf(o):null}export function writeCell(e,t,n,o){const i=(e?.allRows??[]).findIndex(l=>l.id===t);return i<0||!e.startEditing?.(i,n)?!1:(e.updateEditingCellValue(o),e.saveEditingCell(),!0)}export function cellValue(e,t,n){const o=t.getCellValueByColumnId?t.getCellValueByColumnId(n.id):t.original?.[n.field];return e?.getCellDisplayValue?e.getCellDisplayValue(t.id,n.id,o):o}export function cellText(e,t,n){const o=e.def.formatter;if(o)try{return String(o({value:t,row:n,column:{id:e.id,columnDef:e.def}})??"")}catch{}return Array.isArray(t)?t.map(i=>i&&typeof i=="object"?i.name??"":String(i)).join(", "):t==null?"":String(t)}export function dataRows(e){return(e?.allRows??[]).filter(t=>t.__treeRow||!(typeof t.getCanExpand=="function"&&t.getCanExpand()))}const p=e=>!e.__treeRow&&typeof e.getCanExpand=="function"&&e.getCanExpand();export function leafFilter(e){const t=e?.advancedFilter,n=t?c():null;if(!n)return null;try{return n(t,{getValue:e.getRowColumnValue,rows:[]})??null}catch{return null}}export function groupLeaves(e,t){const n=[],o=i=>{for(const l of i.subRows??[])p(l)?o(l):(!t||t(l))&&n.push(l)};return o(e),n}export function revealRow(e,t,n){const o=e?.scrollContainer??null,i=o?.querySelector(`[role="gridcell"][aria-rowindex="${n+1}"]`);if(o&&i){const l=o.getBoundingClientRect(),r=o.querySelector('[role="columnheader"]')?.getBoundingClientRect(),a=Math.max(l.top,r&&r.bottom>l.top?r.bottom:l.top),f=i.getBoundingClientRect();if(f.top>=a-1&&f.bottom<=l.top+o.clientHeight+1)return}t.scrollToRow(n)}
@@ -1,6 +1,7 @@
1
1
  export { registerFieldType, getFieldType, listFieldTypes, fieldPropsOf, fillFieldColumn, type FieldTypeDef, type FieldCellProps, } from './registry.svelte.js';
2
2
  export { linkHref, linkText, type LinkKind } from './links.js';
3
3
  export { setFieldUsers, getFieldUsers, setCurrentUser, getCurrentUser, registerLinkedTable, unregisterLinkedTable, getLinkedTable, listLinkedTables, type FieldUser, type LinkedTable, } from './sources.svelte.js';
4
+ export { canEditField, defaultCanEditField, fieldEditors, setCanEditField, setFieldProtection, type CanEditField, type FieldAccessField, } from './field-access.svelte.js';
4
5
  export { compileFormula, formulaError, FORMULA_FUNCTIONS, FormulaError } from './formula.js';
5
6
  export { formatNumber, formatCurrency, formatPercent, formatDuration, parseDuration, formatDate } from './format.js';
6
7
  export { BRIGHT, OPTION_COLORS } from './palette.js';
@@ -8,17 +9,23 @@ export { convertValue, countCleared } from './convert.js';
8
9
  export { openFieldEditor, closeFieldEditor, openRecord, closeRecord, type OpenRecordRequest } from './editor-request.svelte.js';
9
10
  export { default as SvBaseViewBar } from './SvBaseViewBar.svelte';
10
11
  export { default as SvBaseForm } from './SvBaseForm.svelte';
12
+ export { formPrefillLink, readFormPrefill, type FormPrefill } from './form-logic.js';
11
13
  export { default as SvBase } from './SvBase.svelte';
12
14
  export { blankTable, newRecordId, type BaseTable } from './base-tables.js';
13
15
  export { baseSource, createBaseSync, type BaseSource, type BaseSourceOptions, type BaseSyncStatus, type BaseRemoteChange, type ForeignKeyLink, type JunctionLink, } from './base-sync.js';
14
16
  export { baseFieldsFromSchema, baseTablesFromSchemas, baseSpecFromSchemas, baseTablesFromSpec, type BaseTableSpec, type BaseLinkSpec } from './base-schema.js';
15
17
  export { baseToSql, sqlName, type BaseToSqlOptions, type BaseTableComment, type BaseJunctionComment } from './base-sql.js';
16
18
  export { applyBaseComments, withInverses, type BaseComments } from './base-schema.js';
19
+ export { restoreItems, trashLabel, type BaseTrashItem } from './base-trash.js';
20
+ export { guessField, tableFromMatrix, recordsFromMatrix, matchColumns, type BaseImportResult, type ImportedField } from './base-import.js';
17
21
  export { baseFromDatabase, describeDatabase, createBaseEndpoint, baseFromEndpoint, baseFromSupabase, type DatabaseOptions, type BaseEndpointOptions, type SupabaseBaseOptions } from './base-connect.js';
22
+ export { baseFromAirtable, airtableFormulaSupport, airtableColor, formulaFunctionsUsed, type AirtableSchema, type AirtableTable, type AirtableField, type AirtableView, type AirtableRecord, type AirtableRecords, type AirtableCollaborator, type AirtableImportOptions, type AirtableImport, type AirtableReportItem, type AirtableFormulaSupport, type AirtableFormulaStatus, type AirtableFormulaGroup } from './airtable.js';
18
23
  export { registerAutomationAction, listAutomationActions, MAX_DEPTH as AUTOMATION_MAX_DEPTH, type BaseAutomation, type AutomationTrigger, type AutomationAction, type AutomationRun, type AutomationStep, type AutomationActionContext, type RegisteredAutomationAction, } from './automations.svelte.js';
19
24
  export { createAutomationServer, type AutomationServer, type AutomationServerOptions, type AutomationNotice } from './automation-server.js';
20
25
  export type { WebhookAction, EmailAction, OutgoingEmail } from './automation-outbound.js';
21
26
  export { setRecordComments, type RecordComment, type RecordCommentContext, type RecordCommentStore } from './activity.svelte.js';
27
+ export { setMentionHandler, type MentionEvent, type MentionHandler } from './activity.svelte.js';
28
+ export { mentionToken, mentionIds, mentionText, parseMentions, encodeMentions, type MentionPart } from './mentions.js';
22
29
  export { baseCondition, baseFilterOf } from './base-alerts.js';
23
30
  export { compileFieldFilter, describeFieldFilter, filterKindOf, operatorsFor, ME, type FieldFilter, type FieldCondition, type FieldConditionGroup, type FilterKind, type FilterOp, } from './filter-model.js';
24
31
  export type { FieldView, FieldViewType, ColorSetting } from './view-model.js';
@@ -50,3 +57,12 @@ export declare function baseReviewApplied(api: unknown): (applied: ReadonlyArray
50
57
  * grid shows the Enterprise watermark and the feature still runs.
51
58
  */
52
59
  export declare function enableFields(): void;
60
+ export { inboxRecords, listColumns, listGroups, viewRecords, type ListGroup } from './list-view.js';
61
+ export { generateAIField, regenerateAIFields, cancelAIField, pendingAIField, setAIFieldConcurrency, type AIFieldRun, type AIFieldCellState, type AIFieldChange } from './ai-field.svelte.js';
62
+ export { aiPromptError, readAIAnswer, type AIFieldProps, type AIFieldOutput } from './ai-prompt.js';
63
+ export { moveTile, newTile, putTile, removeTile, tileResult, tileRows, tileTitle, type DashboardTile, type DashboardTileKind, type DashboardTileSize, type NumberAggregation, type TileResult, } from './dashboard.js';
64
+ export { sharedTables, sharedViews, shareOf, type BaseShare } from './base-share.js';
65
+ export { searchBase, type BaseSearchGroup, type BaseSearchHit, type BaseSearchOptions } from './base-search.js';
66
+ export { toChecklist, parseChecklist, checklistText, checklistProgress, type ChecklistItem } from './checklist.js';
67
+ export { parseColor } from './color-value.js';
68
+ export { parseTimeOfDay, formatTimeOfDay, timeSeconds, type TimeOfDayProps } from './time-of-day.js';
@@ -1 +1 @@
1
- import{registerCellEditor as m,registerGridExtension as k,registerGridShortcuts as A}from"@svgrid/grid";import{nudgeEnterpriseFor as S}from"../license.js";import R from"./FieldCell.svelte";import D from"./RowAdder.svelte";import I from"./FootRowAdder.svelte";import x from"./AttachmentEditor.svelte";import B from"./FieldsHeaderEnd.svelte";import{askDeleteField as L,openFieldEditor as c,openRecord as O}from"./editor-request.svelte.js";import{enableAdvancedFilter as N,registerFilterKind as P}from"../advanced-filter-enable.js";import{compileFieldFilter as H,newCondition as g,resolveMeWith as U}from"./filter-model.js";import{hasBar as _,openBarPanel as C}from"./bar-request.svelte.js";import{groupRules as V,userSorts as G,writeSortState as K}from"./viewbar/sort-state.js";import{sortLabels as z}from"./view-model.js";import{noteChange as b}from"./activity.svelte.js";import{getLinkedTable as $}from"./sources.svelte.js";import{linkNames as j,registerBaseCondition as q}from"./base-alerts.js";import{duplicateField as X,hideField as Y,indexBeside as F,removeField as W}from"./field-ops.js";import{linkReaders as J}from"./base-tables.js";import{formulaReaders as Q}from"./formula.js";import{BUILTIN_FIELD_TYPES as Z}from"./builtin-types.js";import{rowColorOf as ee,rowColorRootClass as oe,tallRowClass as re,rowMarkColor as ie,rowMarkLabel as te}from"./row-colors.js";import{chooseRowColor as y}from"./row-color-choice.svelte.js";import{fieldPropsOf as ne,fillFieldColumn as le,getFieldType as h,originalColumn as de,registerFieldType as se,typeDrawsCell as ae}from"./registry.svelte.js";import fe from"./RatingEditor.svelte";import me from"./LinkPickerEditor.svelte";import pe from"./SelectEditor.svelte";import ue from"./NumberEditor.svelte";import ce from"./LongTextEditor.svelte";import ge from"./RowHeader.svelte";import Ce from"./GroupHeader.svelte";import be from"./SummaryCell.svelte";import{getCurrentUser as M}from"./sources.svelte.js";import{fieldColumns as Fe,gridOf as w,primaryIdOf as T,rememberGrid as ye}from"./grid-access.js";export{registerFieldType,getFieldType,listFieldTypes,fieldPropsOf,fillFieldColumn}from"./registry.svelte.js";export{linkHref,linkText}from"./links.js";export{setFieldUsers,getFieldUsers,setCurrentUser,getCurrentUser,registerLinkedTable,unregisterLinkedTable,getLinkedTable,listLinkedTables}from"./sources.svelte.js";export{compileFormula,formulaError,FORMULA_FUNCTIONS,FormulaError}from"./formula.js";export{formatNumber,formatCurrency,formatPercent,formatDuration,parseDuration,formatDate}from"./format.js";export{BRIGHT,OPTION_COLORS}from"./palette.js";export{convertValue,countCleared}from"./convert.js";export{openFieldEditor,closeFieldEditor,openRecord,closeRecord}from"./editor-request.svelte.js";export{default as SvBaseViewBar}from"./SvBaseViewBar.svelte";export{default as SvBaseForm}from"./SvBaseForm.svelte";export{default as SvBase}from"./SvBase.svelte";export{blankTable,newRecordId}from"./base-tables.js";export{baseSource,createBaseSync}from"./base-sync.js";export{baseFieldsFromSchema,baseTablesFromSchemas,baseSpecFromSchemas,baseTablesFromSpec}from"./base-schema.js";export{baseToSql,sqlName}from"./base-sql.js";export{applyBaseComments,withInverses}from"./base-schema.js";export{baseFromDatabase,describeDatabase,createBaseEndpoint,baseFromEndpoint,baseFromSupabase}from"./base-connect.js";export{registerAutomationAction,listAutomationActions,MAX_DEPTH as AUTOMATION_MAX_DEPTH}from"./automations.svelte.js";export{createAutomationServer}from"./automation-server.js";export{setRecordComments}from"./activity.svelte.js";export{baseCondition,baseFilterOf}from"./base-alerts.js";export{compileFieldFilter,describeFieldFilter,filterKindOf,operatorsFor,ME}from"./filter-model.js";export{BUILTIN_FIELD_TYPES}from"./builtin-types.js";export{setAttachmentUploader,attachmentsFromText,attachmentsText,toAttachments}from"./attachments.js";const s={edit:"M4 20h4L19 9l-4-4L4 16zM14 6l4 4",left:"M10 6l-6 6 6 6M4 12h11M20 5v14",right:"M14 6l6 6-6 6M20 12H9M4 5v14",duplicate:"M8 8h12v12H8zM16 8V4H4v12h4",hide:"M3 3l18 18M10.6 10.6a2 2 0 0 0 2.8 2.8M9.9 5.1A9.8 9.8 0 0 1 12 5c5 0 9 5 10 7a13.4 13.4 0 0 1-3 3.9M6.6 6.6A13.5 13.5 0 0 0 2 12c1 2 5 7 10 7a9.6 9.6 0 0 0 4.4-1.1",remove:"M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13",color:"M12 3l6 7a6.5 6.5 0 1 1-12 0l6-7z",filter:"M4 5h16l-6 7v6l-4 2v-8z",group:"M4 5h16M4 10h10M4 15h16M4 20h10",info:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM12 11v5M12 8h.01"};function he(o,e){const r=(o?.internalColumns??[]).find(t=>String(t.id??t.field)===e),n=r?.fieldType==="singleSelect"&&r.field?ee(o)?.field===r.field?{key:"field-rowcolor",label:"Stop coloring rows",icon:s.color,run:()=>y(o,null)}:{key:"field-rowcolor",label:"Color rows by this field",icon:s.color,run:()=>y(o,{field:String(r.field),...o.props.rowColor?.target?{target:o.props.rowColor.target}:{}})}:null,i=T(o)===e,l=r&&_(o)?[...g(e,r)?[{key:"field-filter",label:"Filter by this field",icon:s.filter,separatorBefore:!0,run:()=>Me(o,e,r)}]:[],...o.groupingControlsEnabled?[]:[{key:"field-group",label:"Group by this field",icon:s.group,run:()=>we(o,e)}]]:[];return[...n?[n]:[],{key:"field-edit",label:"Edit field",icon:s.edit,run:()=>c({ctrl:o,mode:"edit",columnId:e})},...i?[]:[{key:"field-left",label:"Insert left",icon:s.left,run:()=>c({ctrl:o,mode:"add",index:F(o,e,"left")})}],{key:"field-right",label:"Insert right",icon:s.right,run:()=>c({ctrl:o,mode:"add",index:F(o,e,"right")})},{key:"field-duplicate",label:"Duplicate field",icon:s.duplicate,run:()=>X(o,e)},...l,...i?[]:[{key:"field-hide",label:"Hide field",icon:s.hide,run:()=>Y(o,e)},{key:"field-delete",label:"Delete field",icon:s.remove,separatorBefore:!0,run:()=>r?.fieldType==="link"&&(r.fieldProps?.inverse&&$(r.fieldProps.table)||J({columns:o.internalColumns},r).length)||r&&Q(o.internalColumns??[],r).length?L({ctrl:o,columnId:e}):W(o,e)}]]}function Me(o,e,r){const n=g(e,r);if(!n)return;const i=o.advancedFilter,l=i?.kind==="fieldFilter"?i:{kind:"fieldFilter",conjunction:"and",conditions:[]};o.buildApi().setAdvancedFilter({...l,conditions:[...l.conditions,n]}),C(o,"filter")}function we(o,e){const r=V(o);r.some(n=>n.id===e)||K(o.buildApi(),[...r,{id:e,desc:!1}],G(o)),C(o,"group")}function v(o,e,r){if(!e)return;const n=M()?.id,i=o.buildApi?.().getRowId?.(e),l=(t,a)=>{i!=null&&o.editedCellValues&&(o.editedCellValues={...o.editedCellValues,[`${i}:${t}`]:a})};for(const t of o?.internalColumns??[]){if(t.fieldType!=="lastModifiedTime"&&t.fieldType!=="lastModifiedBy")continue;const a=String(t.id??t.field);if(a===r||!t.field)continue;const p=ne(de(t));p.watch==="specific"&&!(p.watchFields??[]).includes(r)||(t.fieldType==="lastModifiedTime"?l(a,e[t.field]=new Date().toISOString()):n!==void 0&&l(a,e[t.field]=n))}}export function baseReviewApplied(o){return(e,r,n)=>{const i=w(typeof o=="function"?o():o);if(!i)return;const l=i.buildApi?.(),t=l?.getOption?.("getRowId"),a=new Map;(n??l?.getData?.()??[]).forEach((d,f)=>a.set(String(t?t(d,f):f),d));const p=new Map((i.allColumns??[]).map(d=>[d.columnDef?.field,d.id]));for(const d of e){const f=a.get(d.rowId),u=p.get(d.field);!f||!u||(v(i,f,u),b(i,d.rowId,u,f[d.field],void 0,r==="undo"?void 0:d.source.label))}}}function Te(o,e,r){if(!e)return;const n=(o?.allColumns??[]).find(l=>l.id===r)?.columnDef;if(!n?.field)return;const i=o.buildApi?.().getRowId?.(e);i!=null&&b(o,String(i),r,e[n.field])}function ve(o,e){if(o.key!==" "||o.ctrlKey||o.metaKey||o.altKey||o.shiftKey||e.editing||!e.activeCell)return!1;const r=w(e.api);if(!r?.props?.expandRows||(r.allColumns??[]).find(l=>l.id===e.activeCell.columnId)?.columnDef.editorType==="checkbox")return!1;const i=(r.allRows??[])[e.activeCell.rowIndex];return i?(o.preventDefault(),O({ctrl:r,rowId:i.id}),!0):!1}let E=!1;export function enableFields(){if(E)return;E=!0;for(const e of Z)h(e.id)||se(e);k({column:(e,r)=>le(e,r),cell:R,hasCell:e=>ae(e??{}),cellEdited:(e,r)=>{v(e,r.row,r.columnId),Te(e,r.row,r.columnId)},bodyEnd:D,footEnd:I,rowMarkColor:(e,r)=>ie(e,r),rowMarkLabel:(e,r)=>te(e,r),headerIcon:e=>e?.fieldType?h(e.fieldType)?.icon:null,headerNote:e=>e?.fieldType&&typeof e.description=="string"&&e.description?{text:e.description,icon:s.info}:null,sortLabels:e=>e?.fieldType?z(e):null,lockColumn:(e,r)=>T(e)===r,rowHeader:e=>e?.props?.expandRows?ge:null,groupRow:e=>Fe(e).some(r=>r.fieldType)?Ce:null,summaryCell:()=>be,rootClass:e=>{ye(e);const r=e?.advancedFilter?.kind==="fieldFilter"?"sv-fields-own-filter":"";return[oe(e),re(e),r].filter(Boolean).join(" ")||null},headerEnd:B,columnMenuItems:(e,r)=>e?.props?.fieldMenu?he(e,r):[]});const o=e=>({value:e.value,typed:e.typed,columnDef:e.columnDef,columnId:e.columnId,row:e.row,onCommit:e.onCommit,onCancel:e.onCancel});m("fieldRating",{component:fe,props:o,typeToEdit:e=>/^[0-9]$/.test(e)}),m("fieldLink",{component:me,props:o,typeToEdit:!1}),m("fieldNumber",{component:ue,props:e=>({...o(e),onCommitAndMove:e.onCommitAndMove,onCommitAndMoveDown:e.onCommitAndMoveDown}),typeToEdit:e=>/[0-9.,:+\-(]/.test(e)}),m("fieldLongText",{component:ce,props:e=>({...o(e),onCommitAndMove:e.onCommitAndMove})}),m("fieldSelect",{component:pe,props:e=>({...o(e),grid:e.grid,onChange:e.onChange,onCommitAndMove:e.onCommitAndMove})}),m("attachment",{component:x,props:e=>({value:e.value,columnDef:e.columnDef,columnId:e.columnId,row:e.row,onCommit:e.onCommit,onCancel:e.onCancel}),typeToEdit:!1}),P("fieldFilter",(e,r)=>H(e,r.getValue,j)),U(()=>M()?.id),q(),N(),A(ve,{id:"svgrid-fields-space"}),S("base","SvGrid Base")}
1
+ import{registerCellEditor as m,registerGridExtension as x,registerGridShortcuts as S}from"@svgrid/grid";import{nudgeEnterpriseFor as I}from"../license.js";import R from"./FieldCell.svelte";import D from"./RowAdder.svelte";import O from"./FootRowAdder.svelte";import L from"./AttachmentEditor.svelte";import B from"./FieldsHeaderEnd.svelte";import{askDeleteField as P,openFieldEditor as c,openRecord as H}from"./editor-request.svelte.js";import{enableAdvancedFilter as N,registerFilterKind as U}from"../advanced-filter-enable.js";import{compileFieldFilter as V,newCondition as F,resolveMeWith as _}from"./filter-model.js";import{hasBar as G,openBarPanel as g}from"./bar-request.svelte.js";import{groupRules as z,userSorts as K,writeSortState as $}from"./viewbar/sort-state.js";import{sortLabels as j}from"./view-model.js";import{noteChange as b}from"./activity.svelte.js";import{getLinkedTable as q}from"./sources.svelte.js";import{linkNames as X,registerBaseCondition as Y}from"./base-alerts.js";import{duplicateField as W,hideField as J,indexBeside as h,removeField as Q}from"./field-ops.js";import{linkReaders as Z}from"./base-tables.js";import{viewOnlyItems as ee}from"./base-share.js";import{formulaReaders as oe}from"./formula.js";import{BUILTIN_FIELD_TYPES as re}from"./builtin-types.js";import{rowColorOf as ie,rowColorRootClass as te,tallRowClass as ne,rowMarkColor as le,rowMarkLabel as de}from"./row-colors.js";import{chooseRowColor as M}from"./row-color-choice.svelte.js";import{fieldPropsOf as y,fillFieldColumn as se,getFieldType as T,originalColumn as C,registerFieldType as me,typeDrawsCell as ae}from"./registry.svelte.js";import fe from"./RatingEditor.svelte";import pe from"./LinkPickerEditor.svelte";import ue from"./SelectEditor.svelte";import ce from"./NumberEditor.svelte";import Ce from"./LongTextEditor.svelte";import Fe from"./ChecklistEditor.svelte";import ge from"./ColorEditor.svelte";import be from"./TimeOfDayEditor.svelte";import he from"./RowHeader.svelte";import Me from"./GroupHeader.svelte";import ye from"./SummaryCell.svelte";import{getCurrentUser as w}from"./sources.svelte.js";import{fieldColumns as Te,gridOf as v,primaryIdOf as E,rememberGrid as we}from"./grid-access.js";export{registerFieldType,getFieldType,listFieldTypes,fieldPropsOf,fillFieldColumn}from"./registry.svelte.js";export{linkHref,linkText}from"./links.js";export{setFieldUsers,getFieldUsers,setCurrentUser,getCurrentUser,registerLinkedTable,unregisterLinkedTable,getLinkedTable,listLinkedTables}from"./sources.svelte.js";export{canEditField,defaultCanEditField,fieldEditors,setCanEditField,setFieldProtection}from"./field-access.svelte.js";import{protectionText as ve}from"./field-access.svelte.js";export{compileFormula,formulaError,FORMULA_FUNCTIONS,FormulaError}from"./formula.js";export{formatNumber,formatCurrency,formatPercent,formatDuration,parseDuration,formatDate}from"./format.js";export{BRIGHT,OPTION_COLORS}from"./palette.js";export{convertValue,countCleared}from"./convert.js";export{openFieldEditor,closeFieldEditor,openRecord,closeRecord}from"./editor-request.svelte.js";export{default as SvBaseViewBar}from"./SvBaseViewBar.svelte";export{default as SvBaseForm}from"./SvBaseForm.svelte";export{formPrefillLink,readFormPrefill}from"./form-logic.js";export{default as SvBase}from"./SvBase.svelte";export{blankTable,newRecordId}from"./base-tables.js";export{baseSource,createBaseSync}from"./base-sync.js";export{baseFieldsFromSchema,baseTablesFromSchemas,baseSpecFromSchemas,baseTablesFromSpec}from"./base-schema.js";export{baseToSql,sqlName}from"./base-sql.js";export{applyBaseComments,withInverses}from"./base-schema.js";export{restoreItems,trashLabel}from"./base-trash.js";export{guessField,tableFromMatrix,recordsFromMatrix,matchColumns}from"./base-import.js";export{baseFromDatabase,describeDatabase,createBaseEndpoint,baseFromEndpoint,baseFromSupabase}from"./base-connect.js";export{baseFromAirtable,airtableFormulaSupport,airtableColor,formulaFunctionsUsed}from"./airtable.js";export{registerAutomationAction,listAutomationActions,MAX_DEPTH as AUTOMATION_MAX_DEPTH}from"./automations.svelte.js";export{createAutomationServer}from"./automation-server.js";export{setRecordComments}from"./activity.svelte.js";export{setMentionHandler}from"./activity.svelte.js";export{mentionToken,mentionIds,mentionText,parseMentions,encodeMentions}from"./mentions.js";export{baseCondition,baseFilterOf}from"./base-alerts.js";export{compileFieldFilter,describeFieldFilter,filterKindOf,operatorsFor,ME}from"./filter-model.js";export{BUILTIN_FIELD_TYPES}from"./builtin-types.js";export{setAttachmentUploader,attachmentsFromText,attachmentsText,toAttachments}from"./attachments.js";const d={edit:"M4 20h4L19 9l-4-4L4 16zM14 6l4 4",left:"M10 6l-6 6 6 6M4 12h11M20 5v14",right:"M14 6l6 6-6 6M20 12H9M4 5v14",duplicate:"M8 8h12v12H8zM16 8V4H4v12h4",hide:"M3 3l18 18M10.6 10.6a2 2 0 0 0 2.8 2.8M9.9 5.1A9.8 9.8 0 0 1 12 5c5 0 9 5 10 7a13.4 13.4 0 0 1-3 3.9M6.6 6.6A13.5 13.5 0 0 0 2 12c1 2 5 7 10 7a9.6 9.6 0 0 0 4.4-1.1",remove:"M4 7h16M9 7V4h6v3M6 7l1 13h10l1-13",color:"M12 3l6 7a6.5 6.5 0 1 1-12 0l6-7z",filter:"M4 5h16l-6 7v6l-4 2v-8z",group:"M4 5h16M4 10h10M4 15h16M4 20h10",info:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM12 11v5M12 8h.01",lock:"M6 11h12v9H6zM8.5 11V8a3.5 3.5 0 0 1 7 0v3"};function Ee(o,i){const e=(o?.internalColumns??[]).find(n=>String(n.id??n.field)===i),r=e?.fieldType==="singleSelect"&&e.field?ie(o)?.field===e.field?{key:"field-rowcolor",label:"Stop coloring rows",icon:d.color,run:()=>M(o,null)}:{key:"field-rowcolor",label:"Color rows by this field",icon:d.color,run:()=>M(o,{field:String(e.field),...o.props.rowColor?.target?{target:o.props.rowColor.target}:{}})}:null,t=E(o)===i,l=e&&G(o)?[...F(i,e)?[{key:"field-filter",label:"Filter by this field",icon:d.filter,separatorBefore:!0,run:()=>ke(o,i,e)}]:[],...o.groupingControlsEnabled?[]:[{key:"field-group",label:"Group by this field",icon:d.group,run:()=>Ae(o,i)}]]:[];return[...r?[r]:[],{key:"field-edit",label:"Edit field",icon:d.edit,run:()=>c({ctrl:o,mode:"edit",columnId:i})},...t?[]:[{key:"field-left",label:"Insert left",icon:d.left,run:()=>c({ctrl:o,mode:"add",index:h(o,i,"left")})}],{key:"field-right",label:"Insert right",icon:d.right,run:()=>c({ctrl:o,mode:"add",index:h(o,i,"right")})},{key:"field-duplicate",label:"Duplicate field",icon:d.duplicate,run:()=>W(o,i)},...l,...Re(o,i,e),...t?[]:[{key:"field-hide",label:"Hide field",icon:d.hide,run:()=>J(o,i)},{key:"field-delete",label:"Delete field",icon:d.remove,separatorBefore:!0,run:()=>e?.fieldType==="link"&&(e.fieldProps?.inverse&&q(e.fieldProps.table)||Z({columns:o.internalColumns},e).length)||e&&oe(o.internalColumns??[],e).length?P({ctrl:o,columnId:i}):Q(o,i)}]]}function ke(o,i,e){const r=F(i,e);if(!r)return;const t=o.advancedFilter,l=t?.kind==="fieldFilter"?t:{kind:"fieldFilter",conjunction:"and",conditions:[]};o.buildApi().setAdvancedFilter({...l,conditions:[...l.conditions,r]}),g(o,"filter")}function Ae(o,i){const e=z(o);e.some(r=>r.id===i)||$(o.buildApi(),[...e,{id:i,desc:!1}],K(o)),g(o,"group")}function k(o,i,e){if(!i)return;const r=w()?.id,t=o.buildApi?.().getRowId?.(i),l=(n,a)=>{t!=null&&o.editedCellValues&&(o.editedCellValues={...o.editedCellValues,[`${t}:${n}`]:a})};for(const n of o?.internalColumns??[]){if(n.fieldType!=="lastModifiedTime"&&n.fieldType!=="lastModifiedBy")continue;const a=String(n.id??n.field);if(a===e||!n.field)continue;const p=y(C(n));p.watch==="specific"&&!(p.watchFields??[]).includes(e)||(n.fieldType==="lastModifiedTime"?l(a,i[n.field]=new Date().toISOString()):r!==void 0&&l(a,i[n.field]=r))}}export function baseReviewApplied(o){return(i,e,r)=>{const t=v(typeof o=="function"?o():o);if(!t)return;const l=t.buildApi?.(),n=l?.getOption?.("getRowId"),a=new Map;(r??l?.getData?.()??[]).forEach((s,f)=>a.set(String(n?n(s,f):f),s));const p=new Map((t.allColumns??[]).map(s=>[s.columnDef?.field,s.id]));for(const s of i){const f=a.get(s.rowId),u=p.get(s.field);!f||!u||(k(t,f,u),b(t,s.rowId,u,f[s.field],void 0,e==="undo"?void 0:s.source.label))}}}function xe(o,i,e){if(!i)return;const r=(o?.allColumns??[]).find(l=>l.id===e)?.columnDef;if(!r?.field)return;const t=o.buildApi?.().getRowId?.(i);t!=null&&b(o,String(t),e,i[r.field])}function Se(o,i){if(o.key!==" "||o.ctrlKey||o.metaKey||o.altKey||o.shiftKey||i.editing||!i.activeCell)return!1;const e=v(i.api);if(!e?.props?.expandRows||(e.allColumns??[]).find(l=>l.id===i.activeCell.columnId)?.columnDef.editorType==="checkbox")return!1;const t=(e.allRows??[])[i.activeCell.rowIndex];return t?(o.preventDefault(),H({ctrl:e,rowId:t.id}),!0):!1}let A=!1;export function enableFields(){if(A)return;A=!0;for(const e of re)T(e.id)||me(e);x({column:(e,r)=>se(e,r),cell:R,hasCell:e=>ae(e??{}),cellEdited:(e,r)=>{k(e,r.row,r.columnId),xe(e,r.row,r.columnId),Ie(e,r.row,r.columnId)},bodyEnd:D,footEnd:O,rowMarkColor:(e,r)=>le(e,r),rowMarkLabel:(e,r)=>de(e,r),headerIcon:e=>e?.fieldType?T(e.fieldType)?.icon:null,headerNote:e=>{if(!e?.fieldType)return null;const r=typeof e.description=="string"?e.description:"",t=ve(C(e),y(C(e)));return t?{text:r?`${t} ${r}`:t,icon:d.lock}:r?{text:r,icon:d.info}:null},sortLabels:e=>e?.fieldType?j(e):null,lockColumn:(e,r)=>E(e)===r,rowHeader:e=>e?.props?.expandRows?he:null,groupRow:e=>Te(e).some(r=>r.fieldType)?Me:null,summaryCell:()=>ye,rootClass:e=>{we(e);const r=e?.advancedFilter?.kind==="fieldFilter"?"sv-fields-own-filter":"";return[te(e),ne(e),r].filter(Boolean).join(" ")||null},headerEnd:B,columnMenuItems:(e,r)=>e?.props?.fieldMenu?ee(e,Ee(e,r)):[]});const o=e=>({value:e.value,typed:e.typed,columnDef:e.columnDef,columnId:e.columnId,row:e.row,onCommit:e.onCommit,onCancel:e.onCancel});m("fieldRating",{component:fe,props:o,typeToEdit:e=>/^[0-9]$/.test(e)}),m("fieldLink",{component:pe,props:o,typeToEdit:!1}),m("fieldNumber",{component:ce,props:e=>({...o(e),onCommitAndMove:e.onCommitAndMove,onCommitAndMoveDown:e.onCommitAndMoveDown}),typeToEdit:e=>/[0-9.,:+\-(]/.test(e)}),m("fieldLongText",{component:Ce,props:e=>({...o(e),onCommitAndMove:e.onCommitAndMove})}),m("fieldSelect",{component:ue,props:e=>({...o(e),grid:e.grid,onChange:e.onChange,onCommitAndMove:e.onCommitAndMove})}),m("attachment",{component:L,props:e=>({value:e.value,columnDef:e.columnDef,columnId:e.columnId,row:e.row,onCommit:e.onCommit,onCancel:e.onCancel}),typeToEdit:!1});const i=e=>({...o(e),onCommitAndMove:e.onCommitAndMove});m("fieldChecklist",{component:Fe,props:i}),m("fieldColor",{component:ge,props:i}),m("fieldTime",{component:be,props:e=>({...i(e),onCommitAndMoveDown:e.onCommitAndMoveDown}),typeToEdit:e=>/[0-9]/.test(e)}),U("fieldFilter",(e,r)=>V(e,r.getValue,X)),_(()=>w()?.id),Y(),N(),S(Se,{id:"svgrid-fields-space"}),I("base","SvGrid Base")}export{inboxRecords,listColumns,listGroups,viewRecords}from"./list-view.js";import{aiFieldEdited as Ie,aiFieldMenuItems as Re}from"./ai-field.svelte.js";export{generateAIField,regenerateAIFields,cancelAIField,pendingAIField,setAIFieldConcurrency}from"./ai-field.svelte.js";export{aiPromptError,readAIAnswer}from"./ai-prompt.js";export{moveTile,newTile,putTile,removeTile,tileResult,tileRows,tileTitle}from"./dashboard.js";export{sharedTables,sharedViews,shareOf}from"./base-share.js";export{searchBase}from"./base-search.js";export{toChecklist,parseChecklist,checklistText,checklistProgress}from"./checklist.js";export{parseColor}from"./color-value.js";export{parseTimeOfDay,formatTimeOfDay,timeSeconds}from"./time-of-day.js";
@@ -0,0 +1,40 @@
1
+ /**
2
+ * What the list and inbox views draw: the records the hidden grid shows
3
+ * (its filter, sort and groups), the fields under each record's name, and an
4
+ * inbox's newest-first order. The grid holds the row model; these only read it.
5
+ */
6
+ import { type FieldColumn, type GridRow } from './grid-access.js';
7
+ import type { FieldView } from './view-model.js';
8
+ /**
9
+ * One group of a list grouped by a field: its field, the value it holds, and
10
+ * its records (those of its subgroups too). Grouped by several fields, a
11
+ * group holds the next field's `groups`; `depth` is 0 for the first field.
12
+ */
13
+ export type ListGroup = {
14
+ id: string;
15
+ column: FieldColumn | undefined;
16
+ value: unknown;
17
+ rows: GridRow[];
18
+ depth: number;
19
+ groups: ListGroup[] | null;
20
+ };
21
+ /** The record's name: the primary field, else the first text field, else the first field. */
22
+ export declare function titleColumn(ctrl: any): FieldColumn | undefined;
23
+ /**
24
+ * The groups the grid shows, by its first grouped field, each with the records
25
+ * the filter keeps and, grouped by more fields, its subgroups; null when
26
+ * nothing groups. A group the grid shows folded still lists its records:
27
+ * folding here is the list's own.
28
+ */
29
+ export declare function listGroups(ctrl: any): ListGroup[] | null;
30
+ /** Every record the view shows, in its order, the folded groups' too. */
31
+ export declare function viewRecords(ctrl: any): GridRow[];
32
+ /** The fields a list or inbox shows under a record's name: those the view picked, else the next three the grid shows. */
33
+ export declare function listColumns(ctrl: any, view: Pick<FieldView, 'listFields'> | undefined): FieldColumn[];
34
+ /** A date cell's value as a time, NaN when empty or not a date. */
35
+ export declare function timeOf(value: unknown): number;
36
+ /**
37
+ * An inbox's records: newest first by its date field (records without a date
38
+ * last, in the view's order), or in the view's order without one.
39
+ */
40
+ export declare function inboxRecords(ctrl: any, view: Pick<FieldView, 'inboxDateField'> | undefined): GridRow[];
@@ -0,0 +1 @@
1
+ import{cellValue as N,dataRows as x,fieldColumns as l,groupLeaves as w,leafFilter as R,primaryIdOf as y}from"./grid-access.js";const b=n=>!n.__treeRow&&typeof n.getCanExpand=="function"&&n.getCanExpand();export function titleColumn(n){const e=l(n),o=y(n);return e.find(i=>i.id===o)??e.find(i=>i.visible&&i.fieldType==="text")??e.find(i=>i.visible)??e[0]}export function listGroups(n){const e=n?.groupingColumns??[];if(!e.length)return null;const i=(n?.allRowsBeforePagination??n?.allRows??[]).filter(u=>(u.depth??0)===0&&b(u));if(!i.length)return null;const r=l(n),t=e.map(u=>r.find(f=>f.id===u)),s=R(n),c=(u,f)=>{const d=t[f],m=[];for(const p of u){const a=w(p,s);if(!a.length)continue;const g=(p.subRows??[]).filter(b);m.push({id:p.id,column:d,value:d?N(n,a[0],d):void 0,rows:a,depth:f,groups:g.length?c(g,f+1):null})}return m};return c(i,0)}export function viewRecords(n){const e=listGroups(n);return e?e.flatMap(o=>o.rows):x(n)}export function listColumns(n,e){const o=l(n),i=titleColumn(n);if(e?.listFields){const r=new Map(o.map(t=>[t.id,t]));return e.listFields.map(t=>r.get(t)).filter(t=>!!t&&t.id!==i?.id)}return o.filter(r=>r.visible&&r.id!==i?.id).slice(0,3)}export function timeOf(n){if(n==null||n==="")return NaN;if(n instanceof Date)return n.getTime();if(typeof n=="number")return n;const e=/^(\d{4})-(\d{2})-(\d{2})$/.exec(String(n));return e?new Date(Number(e[1]),Number(e[2])-1,Number(e[3])).getTime():Date.parse(String(n))}export function inboxRecords(n,e){const o=viewRecords(n),i=e?.inboxDateField?l(n).find(t=>t.id===e.inboxDateField):void 0;if(!i)return o;const r=new Map(o.map(t=>[t,timeOf(N(n,t,i))]));return o.map((t,s)=>({r:t,i:s,t:r.get(t)})).sort((t,s)=>Number.isNaN(t.t)?Number.isNaN(s.t)?t.i-s.i:1:Number.isNaN(s.t)?-1:s.t-t.t||t.i-s.i).map(t=>t.r)}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @mentions in record comments. A comment keeps a mention inline as a token,
3
+ * `@[Ana Ruiz](u1)`: the name as it was when the comment was written, and the
4
+ * person's id. The id is what counts; the name is drawn from the people list
5
+ * (`setFieldUsers`) when the person is in it, so a rename shows everywhere,
6
+ * and the stored name is the fallback for someone who left.
7
+ *
8
+ * While typing, the comment box shows `@Ana Ruiz`; `encodeMentions` turns the
9
+ * people picked from the list into tokens when the comment is sent.
10
+ */
11
+ import type { FieldUser } from './sources.svelte.js';
12
+ /** A run of a comment's text, or a mention in it. */
13
+ export type MentionPart = {
14
+ text: string;
15
+ } | {
16
+ mention: string;
17
+ name: string;
18
+ };
19
+ /** The inline form of a mention of `user`. */
20
+ export declare function mentionToken(user: Pick<FieldUser, 'id' | 'name'>): string;
21
+ /** A comment's text cut into plain runs and mentions, in order. */
22
+ export declare function parseMentions(text: string): MentionPart[];
23
+ /** The ids a comment mentions, each once, in the order they first appear. */
24
+ export declare function mentionIds(text: string): string[];
25
+ /**
26
+ * The comment as plain text, each mention as `@Name` (for an email or a chat
27
+ * message). `nameOf` names a person by id; the token's name is the fallback.
28
+ */
29
+ export declare function mentionText(text: string, nameOf?: (id: string) => string | undefined): string;
30
+ /**
31
+ * Turn each `@Name` of the people picked while typing into a token. A name
32
+ * the user has since edited is no longer a mention and stays as typed.
33
+ */
34
+ export declare function encodeMentions(text: string, picked: ReadonlyArray<Pick<FieldUser, 'id' | 'name'>>): string;
35
+ /**
36
+ * The mention being typed at `caret`: where its `@` is and what follows it.
37
+ * Null when the caret is not in one (the `@` must start the text or follow a
38
+ * space or an opening bracket, so an email address does not open the list).
39
+ */
40
+ export declare function mentionQuery(text: string, caret: number): {
41
+ start: number;
42
+ query: string;
43
+ } | null;
44
+ /** The people whose name (any word of it) or email starts with `query`, best first. */
45
+ export declare function matchMentionUsers(users: ReadonlyArray<FieldUser>, query: string, limit?: number): FieldUser[];
46
+ /** Put `@Name ` where the mention being typed is (`start` to `caret`); returns the text and the caret after it. */
47
+ export declare function insertMention(text: string, start: number, caret: number, user: Pick<FieldUser, 'name'>): {
48
+ text: string;
49
+ caret: number;
50
+ };
@@ -0,0 +1 @@
1
+ const a=/@\[([^\]\n]*)\]\(([^)\s]+)\)/g,f=e=>{try{return decodeURIComponent(e)}catch{return e}};export function mentionToken(e){return`@[${e.name.replace(/[[\]\r\n]/g,"").trim()}](${encodeURIComponent(e.id).replace(/\)/g,"%29")})`}export function parseMentions(e){const r=[];let o=0;for(const t of e.matchAll(a)){const s=t.index??0;s>o&&r.push({text:e.slice(o,s)}),r.push({mention:f(t[2]),name:t[1]}),o=s+t[0].length}return o<e.length&&r.push({text:e.slice(o)}),r}export function mentionIds(e){const r=[];for(const o of e.matchAll(a)){const t=f(o[2]);r.includes(t)||r.push(t)}return r}export function mentionText(e,r){return parseMentions(e).map(o=>"mention"in o?`@${r?.(o.mention)??o.name}`:o.text).join("")}export function encodeMentions(e,r){const o=[...r].sort((s,n)=>n.name.length-s.name.length);let t=e;for(const s of o){const n=`@${s.name}`;let i=0;for(let c=t.indexOf(n,i);c>=0;c=t.indexOf(n,i)){const l=t[c+n.length];if(l!==void 0&&/[\p{L}\p{N}_]/u.test(l)){i=c+n.length;continue}const u=mentionToken(s);t=t.slice(0,c)+u+t.slice(c+n.length),i=c+u.length}}return t}export function mentionQuery(e,r){const o=e.slice(0,r),t=o.lastIndexOf("@");if(t<0)return null;const s=t>0?o[t-1]:" ";if(!/[\s([{"']/.test(s))return null;const n=o.slice(t+1);return n.length>30||/^\s|\s$|[\n@]/.test(n)?null:{start:t,query:n}}export function matchMentionUsers(e,r,o=8){const t=r.trim().toLowerCase();if(!t)return e.slice(0,o);const s=n=>{const i=n.name.toLowerCase();return i.startsWith(t)?0:i.split(/\s+/).some(c=>c.startsWith(t))?1:n.email?.toLowerCase().startsWith(t)?2:-1};return e.map(n=>({u:n,r:s(n)})).filter(n=>n.r>=0).sort((n,i)=>n.r-i.r).slice(0,o).map(n=>n.u)}export function insertMention(e,r,o,t){const s=`@${t.name} `,n=e.slice(o).replace(/^ /,"");return{text:e.slice(0,r)+s+n,caret:r+s.length}}
@@ -41,7 +41,9 @@ export declare const RATING_ICONS: {
41
41
  export declare const STROKE_ICONS: Set<"x" | "dot" | "check" | "flag" | "star" | "heart" | "thumbsUp">;
42
42
  /**
43
43
  * Text color for a pill filled with `color`: near-black or white, whichever
44
- * has more contrast on it. Colors that are not #rgb / #rrggbb get the theme's
45
- * text color.
44
+ * reads better on it by APCA lightness contrast. The WCAG 2 ratio is not used
45
+ * here: on a saturated blue or red (#2d7ff9, #f82b60) it ranks black above
46
+ * white by a hair, while white reads far better (APCA 70 against 37). Colors
47
+ * that are not #rgb / #rrggbb get the theme's text color.
46
48
  */
47
49
  export declare function textOn(color: string | undefined): string;
@@ -1 +1 @@
1
- const c=["blue","cyan","teal","green","yellow","orange","red","pink","purple","gray"];export const BRIGHT=[{value:"#2d7ff9",label:"Blue"},{value:"#18bfff",label:"Cyan"},{value:"#20d9d2",label:"Teal"},{value:"#20c933",label:"Green"},{value:"#fcb400",label:"Yellow"},{value:"#ff6f2c",label:"Orange"},{value:"#f82b60",label:"Red"},{value:"#ff08c2",label:"Pink"},{value:"#8b46ff",label:"Purple"},{value:"#666666",label:"Gray"}];const b={blue:["#cfdfff","#9cc7ff","#2d7ff9","#2750ae"],cyan:["#d0f0fd","#77d1f3","#18bfff","#0b76b7"],teal:["#c2f5e9","#72ddc3","#20d9d2","#06a09b"],green:["#d1f7c4","#93e088","#20c933","#338a17"],yellow:["#ffeab6","#ffd66e","#fcb400","#b87503"],orange:["#fee2d5","#ffa981","#ff6f2c","#d74d26"],red:["#ffdce5","#ff9eb7","#f82b60","#ba1e45"],pink:["#ffdaf6","#f99de2","#ff08c2","#b2158b"],purple:["#ede2fe","#cdb0ff","#8b46ff","#6b1cb0"],gray:["#eeeeee","#cccccc","#666666","#444444"]},s=["lightest","light","bright","dark"];export const OPTION_COLORS=s.flatMap((e,f)=>c.map(l=>({value:b[l][f],label:`${l[0].toUpperCase()}${l.slice(1)}, ${e}`}))),OPTION_CYCLE=c.map(e=>b[e][1]),ICONS={check:"M5 12.5l4.5 4.5L19 7.5",x:"M6 6l12 12M18 6 6 18",star:"M12 3.2l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17.2l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z",heart:"M12 20.3s-7.8-4.7-7.8-10.2A4.5 4.5 0 0 1 12 7.4a4.5 4.5 0 0 1 7.8 2.7c0 5.5-7.8 10.2-7.8 10.2z",thumbsUp:"M7 10v10H4V10zM7 10l4-7c1.4 0 2.3 1 2 2.4L12.4 9H19a2 2 0 0 1 2 2.3l-1.2 7A2 2 0 0 1 17.8 20H7",flag:"M5 21V4M5 4h11l-2 4 2 4H5",dot:"M12 7a5 5 0 1 0 0 10 5 5 0 0 0 0-10z"};const r={check:"Check",x:"Cross",star:"Star",heart:"Heart",thumbsUp:"Thumbs up",flag:"Flag",dot:"Dot"};export const CHECKBOX_ICONS=["check","x","star","heart","thumbsUp","flag","dot"].map(e=>({value:e,label:r[e],path:ICONS[e]})),RATING_ICONS=["star","heart","thumbsUp","flag","dot"].map(e=>({value:e,label:r[e],path:ICONS[e]})),STROKE_ICONS=new Set(["check","x","flag","thumbsUp"]);export function textOn(e){const f=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e??"");if(!f)return"var(--sg-fg, #0f172a)";const l=f[1].length===3?[...f[1]].map(a=>a+a).join(""):f[1],[o,n,p]=[0,2,4].map(a=>parseInt(l.slice(a,a+2),16)/255).map(a=>a<=.03928?a/12.92:((a+.055)/1.055)**2.4),t=.2126*o+.7152*n+.0722*p;return(t+.05)/.064>1.05/(t+.05)?"#1d1f25":"#ffffff"}
1
+ const r=["blue","cyan","teal","green","yellow","orange","red","pink","purple","gray"];export const BRIGHT=[{value:"#2d7ff9",label:"Blue"},{value:"#18bfff",label:"Cyan"},{value:"#20d9d2",label:"Teal"},{value:"#20c933",label:"Green"},{value:"#fcb400",label:"Yellow"},{value:"#ff6f2c",label:"Orange"},{value:"#f82b60",label:"Red"},{value:"#ff08c2",label:"Pink"},{value:"#8b46ff",label:"Purple"},{value:"#666666",label:"Gray"}];const b={blue:["#cfdfff","#9cc7ff","#2d7ff9","#2750ae"],cyan:["#d0f0fd","#77d1f3","#18bfff","#0b76b7"],teal:["#c2f5e9","#72ddc3","#20d9d2","#06a09b"],green:["#d1f7c4","#93e088","#20c933","#338a17"],yellow:["#ffeab6","#ffd66e","#fcb400","#b87503"],orange:["#fee2d5","#ffa981","#ff6f2c","#d74d26"],red:["#ffdce5","#ff9eb7","#f82b60","#ba1e45"],pink:["#ffdaf6","#f99de2","#ff08c2","#b2158b"],purple:["#ede2fe","#cdb0ff","#8b46ff","#6b1cb0"],gray:["#eeeeee","#cccccc","#666666","#444444"]},s=["lightest","light","bright","dark"];export const OPTION_COLORS=s.flatMap((e,a)=>r.map(f=>({value:b[f][a],label:`${f[0].toUpperCase()}${f.slice(1)}, ${e}`}))),OPTION_CYCLE=r.map(e=>b[e][1]),ICONS={check:"M5 12.5l4.5 4.5L19 7.5",x:"M6 6l12 12M18 6 6 18",star:"M12 3.2l2.7 5.6 6.1.9-4.4 4.3 1 6.1L12 17.2l-5.4 2.9 1-6.1-4.4-4.3 6.1-.9z",heart:"M12 20.3s-7.8-4.7-7.8-10.2A4.5 4.5 0 0 1 12 7.4a4.5 4.5 0 0 1 7.8 2.7c0 5.5-7.8 10.2-7.8 10.2z",thumbsUp:"M7 10v10H4V10zM7 10l4-7c1.4 0 2.3 1 2 2.4L12.4 9H19a2 2 0 0 1 2 2.3l-1.2 7A2 2 0 0 1 17.8 20H7",flag:"M5 21V4M5 4h11l-2 4 2 4H5",dot:"M12 7a5 5 0 1 0 0 10 5 5 0 0 0 0-10z"};const n={check:"Check",x:"Cross",star:"Star",heart:"Heart",thumbsUp:"Thumbs up",flag:"Flag",dot:"Dot"};export const CHECKBOX_ICONS=["check","x","star","heart","thumbsUp","flag","dot"].map(e=>({value:e,label:n[e],path:ICONS[e]})),RATING_ICONS=["star","heart","thumbsUp","flag","dot"].map(e=>({value:e,label:n[e],path:ICONS[e]})),STROKE_ICONS=new Set(["check","x","flag","thumbsUp"]);function o(e){const[a,f,c]=[0,2,4].map(t=>(parseInt(e.slice(t,t+2),16)/255)**2.4),l=.2126729*a+.7151522*f+.072175*c;return l>.022?l:l+(.022-l)**1.414}export function textOn(e){const a=/^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(e??"");if(!a)return"var(--sg-fg, #0f172a)";const f=o(a[1].length===3?[...a[1]].map(t=>t+t).join(""):a[1]),c=(f**.56-o("1d1f25")**.57)*1.14,l=(1-f**.62)*1.14;return c>=l?"#1d1f25":"#ffffff"}
@@ -1 +1 @@
1
- import{openRecord as y}from"./editor-request.svelte.js";import{newRowValues as x,recordCopyValues as R}from"./field-ops.js";import{askDeleteRecord as z}from"./record-delete.svelte.js";const t={expand:{paths:[{d:"M9.5 2.5h4v4M13.5 2.5 9 7M6.5 13.5h-4v-4M2.5 13.5 7 9"}]},above:{paths:[{d:"M2.5 9.5h11v4h-11zM8 2.5v5M5.5 5 8 2.5 10.5 5"}]},below:{paths:[{d:"M2.5 2.5h11v4h-11zM8 8.5v5M5.5 11 8 13.5 10.5 11"}]},duplicate:{paths:[{d:"M5.5 5.5h8v8h-8zM10.5 5.5v-3h-8v8h3M9.5 8v3M8 9.5h3"}]},copy:{paths:[{d:"M5.5 5.5h8v8h-8zM10.5 5.5v-3h-8v8h3"}]},paste:{paths:[{d:"M5.5 3h-2v10.5h9V3h-2M6 2h4v2.5H6zM6 8h4M6 10.5h4"}]},comment:{paths:[{d:"M2.5 3.5h11v7.5H8l-3 2.5V11H2.5z"}]},delete:{paths:[{d:"M2.5 4.5h11M6 4.5v-2h4v2M4 4.5l.7 9h6.6l.7-9M6.8 7v4.5M9.2 7v4.5"}]}},C=a=>Array.isArray(a)?[...a]:a;export function recordMenu(a,k){const r=()=>k(),M=()=>!!r()?.editingEnabled,w=o=>!o.row,l=o=>!o.row||!M();function p(o,d,s,h){const e=r(),n=a();if(!e||!n||!o.row)return;const c=e.props.rowAdder,I=c&&typeof c=="object"&&typeof c.defaults=="function"?c.defaults():{},f=x(e,{...I,...d}),b=o.row.id,m=e.internalData.findIndex(i=>i===o.row||b!=null&&i?.id===b);n.addRow(f,m<0?"bottom":m+s),e.props.onRowAdd?.({row:f}),queueMicrotask(()=>{const i=e.allRows.findIndex(u=>u.original===f);if(!(i<0)&&(n.scrollToRow(i),h)){for(const u of e.allColumns)if(n.startEditing(i,u.id))break}})}function v(o){const d=r(),s={},h=d?.grid?.getState?.().grouping??[];for(const e of h){const n=d.internalColumns.find(c=>String(c.id??c.field)===e);n?.field&&!n.fieldFn&&(s[n.field]=C(o.row[n.field]))}return s}function g(o){const d=r();d&&o.row&&p(o,R(d,o.row),1,!1)}return[{key:"expand",label:"Expand record",icon:t.expand,hidden:w,action:o=>y({ctrl:r(),rowId:o.rowId})},{key:"comment",label:"Comment",icon:t.comment,hidden:w,action:o=>y({ctrl:r(),rowId:o.rowId,focus:"comment"})},"separator",{key:"record_above",label:"Insert record above",icon:t.above,hidden:l,action:o=>p(o,v(o),0,!0)},{key:"record_below",label:"Insert record below",icon:t.below,hidden:l,action:o=>p(o,v(o),1,!0)},{key:"duplicate",label:"Duplicate record",icon:t.duplicate,hidden:l,action:g},"separator",{key:"copy",icon:t.copy},{key:"paste",icon:t.paste,hidden:()=>!M()},"separator",{key:"delete_record",label:"Delete record",icon:t.delete,hidden:l,action:o=>z({ctrl:r(),api:a(),row:o.row})}]}
1
+ import{openRecord as g}from"./editor-request.svelte.js";import{newRowValues as R,recordCopyValues as x}from"./field-ops.js";import{askDeleteRecord as z}from"./record-delete.svelte.js";import{revealRow as C}from"./grid-access.js";import{isReadOnlyGrid as V}from"./base-share.js";const d={expand:{paths:[{d:"M9.5 2.5h4v4M13.5 2.5 9 7M6.5 13.5h-4v-4M2.5 13.5 7 9"}]},above:{paths:[{d:"M2.5 9.5h11v4h-11zM8 2.5v5M5.5 5 8 2.5 10.5 5"}]},below:{paths:[{d:"M2.5 2.5h11v4h-11zM8 8.5v5M5.5 11 8 13.5 10.5 11"}]},duplicate:{paths:[{d:"M5.5 5.5h8v8h-8zM10.5 5.5v-3h-8v8h3M9.5 8v3M8 9.5h3"}]},copy:{paths:[{d:"M5.5 5.5h8v8h-8zM10.5 5.5v-3h-8v8h3"}]},paste:{paths:[{d:"M5.5 3h-2v10.5h9V3h-2M6 2h4v2.5H6zM6 8h4M6 10.5h4"}]},comment:{paths:[{d:"M2.5 3.5h11v7.5H8l-3 2.5V11H2.5z"}]},delete:{paths:[{d:"M2.5 4.5h11M6 4.5v-2h4v2M4 4.5l.7 9h6.6l.7-9M6.8 7v4.5M9.2 7v4.5"}]}},D=l=>Array.isArray(l)?[...l]:l;export function recordMenu(l,k){const t=()=>k(),w=()=>!!t()?.editingEnabled,v=o=>!o.row,f=o=>!o.row||!w();function M(o,r,u,h){const n=t(),i=l();if(!n||!i||!o.row)return;const e=n.props.rowAdder,c=e&&typeof e=="object"&&typeof e.defaults=="function"?e.defaults():{},s=R(n,{...c,...r}),a=o.row.id,y=n.internalData.findIndex(p=>p===o.row||a!=null&&p?.id===a);i.addRow(s,y<0?"bottom":y+u),n.props.onRowAdd?.({row:s}),queueMicrotask(()=>{const p=n.allRows.findIndex(m=>m.original===s);if(!(p<0)&&(C(n,i,p),h)){for(const m of n.allColumns)if(i.startEditing(p,m.id))break}})}function b(o){const r=t(),u={},h=r?.grid?.getState?.()??{},n=h.grouping??[],i=(h.sorting??[]).map(e=>e.id).filter(e=>!n.includes(e));for(const e of[...n,...i]){const c=r.internalColumns.find(a=>String(a.id??a.field)===e);if(!c?.field||c.fieldFn)continue;const s=r.allColumns?.find(a=>a.id===e)?.columnDef;i.includes(e)&&(c.editable===!1||s?.editable===!1)||typeof s?.groupValue!="function"&&(u[c.field]=D(o.row[c.field]))}return u}function I(o){const r=t();r&&o.row&&M(o,x(r,o.row),1,!1)}return[{key:"expand",label:"Expand record",icon:d.expand,hidden:v,action:o=>g({ctrl:t(),rowId:o.rowId})},{key:"comment",label:"Comment",icon:d.comment,hidden:o=>v(o)||V(t()),action:o=>g({ctrl:t(),rowId:o.rowId,focus:"comment"})},"separator",{key:"record_above",label:"Insert record above",icon:d.above,hidden:f,action:o=>M(o,b(o),0,!0)},{key:"record_below",label:"Insert record below",icon:d.below,hidden:f,action:o=>M(o,b(o),1,!0)},{key:"duplicate",label:"Duplicate record",icon:d.duplicate,hidden:f,action:I},"separator",{key:"copy",icon:d.copy},{key:"paste",icon:d.paste,hidden:()=>!w()},"separator",{key:"delete_record",label:"Delete record",icon:d.delete,hidden:f,action:o=>z({ctrl:t(),api:l(),row:o.row})}]}
@@ -92,6 +92,11 @@ export type FieldPropertyDef = Base & ({
92
92
  | {
93
93
  kind: 'formula';
94
94
  }
95
+ /** Text for a model, with `{Field name}` for the record's values (an AI field's prompt). */
96
+ | {
97
+ kind: 'prompt';
98
+ placeholder?: string;
99
+ }
95
100
  /** Some of the grid's other columns. */
96
101
  | {
97
102
  kind: 'columns';
@@ -1 +1 @@
1
- import{withSummary}from"./summaries.js";let types=$state.raw({});export function registerFieldType(def){types={...types,[def.id]:def}}export function getFieldType(id){return typeof id==="string"?types[id]:void 0}export function listFieldTypes(){return Object.values(types)}export function fieldPropsOf(def){return{...getFieldType(def.fieldType)?.defaults??{},...def.fieldProps??{}}}const ORIGINAL=new WeakMap;const SOURCE=Symbol("svgrid.fieldSource");export function fillFieldColumn(def,columns=[]){const type=getFieldType(def.fieldType);if(!type)return def;const source=originalColumn(def);const props=fieldPropsOf(source);const filled=type.fill?type.fill(source,props,{columns:columns.map(c=>originalColumn(c))}):{...source};const out=withSummary(filled,props);ORIGINAL.set(out,source);out[SOURCE]=source;return out}export function originalColumn(def){return def[SOURCE]??ORIGINAL.get(def)??def}export function typeDrawsCell(def){const type=getFieldType(def.fieldType);if(!type?.cell)return false;return type.hasCell?type.hasCell(fieldPropsOf(def)):true}
1
+ import{withSummary}from"./summaries.js";import{canEditField,fieldEditors,hasCanEditField}from"./field-access.svelte.js";let types=$state.raw({});export function registerFieldType(def){types={...types,[def.id]:def}}export function getFieldType(id){return typeof id==="string"?types[id]:void 0}export function listFieldTypes(){return Object.values(types)}export function fieldPropsOf(def){return{...getFieldType(def.fieldType)?.defaults??{},...def.fieldProps??{}}}const ORIGINAL=new WeakMap;const SOURCE=Symbol("svgrid.fieldSource");export function fillFieldColumn(def,columns=[]){const type=getFieldType(def.fieldType);if(!type)return def;const source=originalColumn(def);const props=fieldPropsOf(source);const filled=type.fill?type.fill(source,props,{columns:columns.map(c=>originalColumn(c))}):{...source};const out=withSummary(filled,props);if(out.groupOrder==null)out.groupOrder=groupOrderOf(out.sortValue);const own=out.editable;if(own!==false&&(fieldEditors(props)||hasCanEditField())){;out.editable=cell=>(typeof own==="function"?own(cell)!==false:true)&&canEditField(source,props)}ORIGINAL.set(out,source);out[SOURCE]=source;return out}const groupText=v=>Array.isArray(v)?v.map(groupText).join(", "):v==null?"":String(v);const groupCollator=new Intl.Collator(void 0,{numeric:true,sensitivity:"base"});function groupOrderOf(sortValue){return(a,b)=>{const ka=sortValue?sortValue(a):a;const kb=sortValue?sortValue(b):b;const ba=ka==null||ka===""||Array.isArray(ka)&&!ka.length;const bb=kb==null||kb===""||Array.isArray(kb)&&!kb.length;if(ba||bb)return Number(ba)-Number(bb);if(typeof ka==="number"&&typeof kb==="number")return ka-kb;if(typeof ka==="boolean"&&typeof kb==="boolean")return Number(ka)-Number(kb);return groupCollator.compare(groupText(ka),groupText(kb))}}export function originalColumn(def){return def[SOURCE]??ORIGINAL.get(def)??def}export function typeDrawsCell(def){const type=getFieldType(def.fieldType);if(!type?.cell)return false;return type.hasCell?type.hasCell(fieldPropsOf(def)):true}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * The time of day field's value: a wall-clock time with no date, stored as
3
+ * 'HH:MM' on a 24-hour clock, or 'HH:MM:SS' when it has seconds. Text rather
4
+ * than seconds since midnight: it reads the same in JSON, a CSV and a SQL
5
+ * `time` column, it sorts in time order as plain text, and it cannot be
6
+ * mistaken for a duration (which the base stores as seconds).
7
+ */
8
+ export type TimeOfDayProps = {
9
+ /** '12hour' (2:05 PM, the default) or '24hour' (14:05). */
10
+ timeFormat?: '12hour' | '24hour';
11
+ /** Show and keep seconds (2:05:30 PM). Without it a typed time keeps its minutes only. */
12
+ showSeconds?: boolean;
13
+ };
14
+ /** Seconds since midnight as the stored text; a day or more wraps around. */
15
+ export declare function timeFromSeconds(s: number): string | null;
16
+ /** A stored time as seconds since midnight; null for anything that is not one. */
17
+ export declare function timeSeconds(v: unknown): number | null;
18
+ /**
19
+ * Typed or pasted text as a stored time, or null: "14:05", "9:30 am",
20
+ * "9.30pm", "2pm", "12 a.m.", "0930", "noon", "midnight", a stored
21
+ * "14:05:30". A date with a time ("2026-10-14T09:30") gives its local time.
22
+ * `seconds: false` drops the seconds.
23
+ */
24
+ export declare function parseTimeOfDay(v: unknown, opts?: {
25
+ seconds?: boolean;
26
+ }): string | null;
27
+ /** A stored time as the field shows it: "2:05 PM" or "14:05", with ":30" seconds when the field shows them. */
28
+ export declare function formatTimeOfDay(v: unknown, props?: TimeOfDayProps): string;