@svgrid/enterprise 3.1.34 → 3.1.35

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 (171) hide show
  1. package/dist/SvGridBoard.svelte +1 -1
  2. package/dist/cdn/svgrid-enterprise.svelte-external.js +2 -2
  3. package/dist/designer/assets/{index-v61ZvIWw.js → index-Eyxa9vgS.js} +3 -3
  4. package/dist/designer/assets/{src-DkFgWld_.js → src-CSmsOfsG.js} +15 -15
  5. package/dist/designer/index.html +2 -2
  6. package/dist/fields/AiCell.svelte +41 -0
  7. package/dist/fields/AiCell.svelte.d.ts +5 -0
  8. package/dist/fields/BaseChartView.svelte +1 -1
  9. package/dist/fields/BaseDashboardView.svelte +133 -0
  10. package/dist/fields/BaseDashboardView.svelte.d.ts +17 -0
  11. package/dist/fields/BaseImport.svelte +89 -0
  12. package/dist/fields/BaseImport.svelte.d.ts +15 -0
  13. package/dist/fields/BaseInboxView.svelte +112 -0
  14. package/dist/fields/BaseInboxView.svelte.d.ts +8 -0
  15. package/dist/fields/BaseListView.svelte +90 -0
  16. package/dist/fields/BaseListView.svelte.d.ts +8 -0
  17. package/dist/fields/BaseSearch.svelte +78 -0
  18. package/dist/fields/BaseSearch.svelte.d.ts +10 -0
  19. package/dist/fields/BaseTableView.svelte +28 -3
  20. package/dist/fields/BaseTableView.svelte.d.ts +5 -1
  21. package/dist/fields/BaseTabs.svelte +45 -8
  22. package/dist/fields/BaseTabs.svelte.d.ts +25 -1
  23. package/dist/fields/BaseTrash.svelte +63 -0
  24. package/dist/fields/BaseTrash.svelte.d.ts +15 -0
  25. package/dist/fields/ChecklistCell.svelte +22 -0
  26. package/dist/fields/ChecklistCell.svelte.d.ts +10 -0
  27. package/dist/fields/ChecklistEditor.svelte +81 -0
  28. package/dist/fields/ChecklistEditor.svelte.d.ts +12 -0
  29. package/dist/fields/ColorCell.svelte +13 -0
  30. package/dist/fields/ColorCell.svelte.d.ts +8 -0
  31. package/dist/fields/ColorEditor.svelte +60 -0
  32. package/dist/fields/ColorEditor.svelte.d.ts +11 -0
  33. package/dist/fields/DashboardRecords.svelte +35 -0
  34. package/dist/fields/DashboardRecords.svelte.d.ts +11 -0
  35. package/dist/fields/DashboardTileEditor.svelte +138 -0
  36. package/dist/fields/DashboardTileEditor.svelte.d.ts +15 -0
  37. package/dist/fields/FieldEditor.svelte +32 -3
  38. package/dist/fields/FieldInput.svelte +1 -1
  39. package/dist/fields/GroupHeader.svelte +3 -3
  40. package/dist/fields/ListChips.svelte +21 -0
  41. package/dist/fields/ListChips.svelte.d.ts +9 -0
  42. package/dist/fields/MentionInput.svelte +59 -0
  43. package/dist/fields/MentionInput.svelte.d.ts +11 -0
  44. package/dist/fields/PropertyInput.svelte +13 -10
  45. package/dist/fields/RecordView.svelte +20 -25
  46. package/dist/fields/SvBase.svelte +48 -9
  47. package/dist/fields/SvBase.svelte.d.ts +33 -1
  48. package/dist/fields/SvBaseForm.svelte +2 -2
  49. package/dist/fields/SvBaseForm.svelte.d.ts +14 -0
  50. package/dist/fields/SvBaseViewBar.svelte +33 -12
  51. package/dist/fields/SvBaseViewBar.svelte.d.ts +2 -0
  52. package/dist/fields/TimeOfDayEditor.svelte +39 -0
  53. package/dist/fields/TimeOfDayEditor.svelte.d.ts +12 -0
  54. package/dist/fields/activity.svelte.d.ts +29 -0
  55. package/dist/fields/activity.svelte.js +1 -1
  56. package/dist/fields/ai-field.svelte.d.ts +91 -0
  57. package/dist/fields/ai-field.svelte.js +1 -0
  58. package/dist/fields/ai-prompt.d.ts +64 -0
  59. package/dist/fields/ai-prompt.js +7 -0
  60. package/dist/fields/airtable.d.ts +90 -0
  61. package/dist/fields/airtable.js +1 -0
  62. package/dist/fields/bar-request.svelte.d.ts +1 -1
  63. package/dist/fields/base-history.d.ts +56 -0
  64. package/dist/fields/base-history.js +1 -0
  65. package/dist/fields/base-import.d.ts +54 -0
  66. package/dist/fields/base-import.js +2 -0
  67. package/dist/fields/base-search.d.ts +34 -0
  68. package/dist/fields/base-search.js +1 -0
  69. package/dist/fields/base-share.d.ts +45 -0
  70. package/dist/fields/base-share.js +1 -0
  71. package/dist/fields/base-sql.js +3 -3
  72. package/dist/fields/base-trash.d.ts +51 -0
  73. package/dist/fields/base-trash.js +1 -0
  74. package/dist/fields/builtin-types.js +1 -1
  75. package/dist/fields/chart-view.d.ts +12 -0
  76. package/dist/fields/chart-view.js +1 -1
  77. package/dist/fields/checklist.d.ts +36 -0
  78. package/dist/fields/checklist.js +4 -0
  79. package/dist/fields/color-value.d.ts +14 -0
  80. package/dist/fields/color-value.js +1 -0
  81. package/dist/fields/convert.js +1 -1
  82. package/dist/fields/copy-text.d.ts +1 -1
  83. package/dist/fields/copy-text.js +1 -1
  84. package/dist/fields/dashboard.d.ts +143 -0
  85. package/dist/fields/dashboard.js +1 -0
  86. package/dist/fields/field-access.svelte.d.ts +37 -0
  87. package/dist/fields/field-access.svelte.js +1 -0
  88. package/dist/fields/field-ops.js +1 -1
  89. package/dist/fields/filter-model.d.ts +4 -11
  90. package/dist/fields/filter-model.js +1 -1
  91. package/dist/fields/form-logic.d.ts +69 -0
  92. package/dist/fields/form-logic.js +1 -0
  93. package/dist/fields/formula.js +1 -1
  94. package/dist/fields/grid-access.d.ts +8 -0
  95. package/dist/fields/grid-access.js +1 -1
  96. package/dist/fields/index.d.ts +16 -0
  97. package/dist/fields/index.js +1 -1
  98. package/dist/fields/list-view.d.ts +40 -0
  99. package/dist/fields/list-view.js +1 -0
  100. package/dist/fields/mentions.d.ts +50 -0
  101. package/dist/fields/mentions.js +1 -0
  102. package/dist/fields/palette.d.ts +4 -2
  103. package/dist/fields/palette.js +1 -1
  104. package/dist/fields/record-menu.js +1 -1
  105. package/dist/fields/registry.svelte.d.ts +5 -0
  106. package/dist/fields/registry.svelte.js +1 -1
  107. package/dist/fields/time-of-day.d.ts +28 -0
  108. package/dist/fields/time-of-day.js +1 -0
  109. package/dist/fields/view-model.d.ts +24 -2
  110. package/dist/fields/view-model.js +1 -1
  111. package/dist/fields/viewbar/ConditionValue.svelte +3 -3
  112. package/dist/fields/viewbar/ListPanel.svelte +36 -0
  113. package/dist/fields/viewbar/ListPanel.svelte.d.ts +11 -0
  114. package/dist/fields/viewbar/ViewsMenu.svelte +27 -4
  115. package/dist/fields/viewbar/ViewsMenu.svelte.d.ts +6 -0
  116. package/dist/node/studio.js +1 -1
  117. package/dist/version.d.ts +2 -2
  118. package/dist/version.js +1 -1
  119. package/dist/wc/GridFind-DsTvdUXq.js +1 -0
  120. package/dist/wc/GridFooter-D-i8boBh.js +1 -0
  121. package/dist/wc/GridMenus-CYe9Fw2I.js +20 -0
  122. package/dist/wc/PinSplitter-LvyyrLhe.js +6 -0
  123. package/dist/wc/SvChartMenu-XKW_LOYw.js +1 -0
  124. package/dist/wc/SvDateRangeInput-CSOxqTB1.js +1 -0
  125. package/dist/wc/SvDateTimePicker-DvvFs2T9.js +4 -0
  126. package/dist/wc/SvField-BmQphyOs.js +20 -0
  127. package/dist/wc/SvForm-HD7y5vmk.js +46 -0
  128. package/dist/wc/SvGridCellEditor-776KAOe1.js +3 -0
  129. package/dist/wc/SvGridChart-DC7ZUhp8.js +171 -0
  130. package/dist/wc/SvGridChartBuilder-Dd3vWBvq.js +7 -0
  131. package/dist/wc/SvGridChartPanel-CwYjF46U.js +5 -0
  132. package/dist/wc/SvGridChartView-CSF38rBs.js +3 -0
  133. package/dist/wc/SvGridDropdown-4S1G7gsP.js +30 -0
  134. package/dist/wc/SvMenuList-D3ZLXjL_.js +1 -0
  135. package/dist/wc/SvModal-Dk0YwPWp.js +7 -0
  136. package/dist/wc/SvSwitchButton-DdZmc3ew.js +1 -0
  137. package/dist/wc/SvTabs-BI2cQHyw.js +2 -0
  138. package/dist/wc/base-react.d.ts +38 -0
  139. package/dist/wc/base-react.js +1 -0
  140. package/dist/wc/base-vue.d.ts +29 -0
  141. package/dist/wc/base-vue.js +1 -0
  142. package/dist/wc/board-RQp5fHPR.js +21 -0
  143. package/dist/wc/board-view.svelte-CpxuZcEg.js +1 -0
  144. package/dist/wc/card-marks.svelte-QwxIcKcZ.js +1 -0
  145. package/dist/wc/client-DNdLmGcu.js +3 -0
  146. package/dist/wc/createOverlay.svelte-CDw3RXgs.js +1 -0
  147. package/dist/wc/custom-filter-Dp8JxlQu.js +2 -0
  148. package/dist/wc/date-format-DtSmFyEB.js +18 -0
  149. package/dist/wc/editor-registry-CkKfcVLc.js +1 -0
  150. package/dist/wc/export-format-CGfE9_O5.js +5 -0
  151. package/dist/wc/gallery-CNOHNWEJ.js +4 -0
  152. package/dist/wc/gallery-view.svelte-27X-wCQH.js +1 -0
  153. package/dist/wc/grid-extension.svelte-hgqOteka.js +1 -0
  154. package/dist/wc/import-B9mIERCl.js +4 -0
  155. package/dist/wc/js-scroller.svelte-BP8Up6_q.js +1 -0
  156. package/dist/wc/license-CWVWqb-i.js +27 -0
  157. package/dist/wc/list-option-CI4nMshZ.js +1 -0
  158. package/dist/wc/react.d.ts +1 -0
  159. package/dist/wc/react.js +1 -1
  160. package/dist/wc/scheduler-CkVY4od-.js +147 -0
  161. package/dist/wc/scheduler-view.svelte-SzG7rU8b.js +1 -0
  162. package/dist/wc/sparkline-DWRBQubt.js +1 -0
  163. package/dist/wc/sv-base-element.d.ts +87 -0
  164. package/dist/wc/sv-base-element.js +273 -0
  165. package/dist/wc/sv-sheet-element.d.ts +2 -0
  166. package/dist/wc/sv-sheet-element.js +55 -55
  167. package/dist/wc/svelte-virtualizer.svelte-CSBwEZt9.js +1 -0
  168. package/dist/wc/types/sv-base-element.d.ts +87 -0
  169. package/dist/wc/vue.d.ts +1 -0
  170. package/dist/wc/vue.js +1 -1
  171. package/package.json +18 -4
@@ -0,0 +1,34 @@
1
+ import { type BaseTable } from './base-tables.js';
2
+ type Def = Record<string, any>;
3
+ /** One record that matched. */
4
+ export type BaseSearchHit = {
5
+ table: string;
6
+ rowId: string;
7
+ /** The record's name: its primary field as the cell shows it. */
8
+ title: string;
9
+ /** The field the match is shown in: its column id and name. */
10
+ field: string;
11
+ fieldName: string;
12
+ /** Whether that field is the primary field (then `text` is the title). */
13
+ primary: boolean;
14
+ /** The field's text, cut around the match when it is long. */
15
+ text: string;
16
+ /** Where the query's words are in `text`: [start, end) pairs, in order. */
17
+ marks: Array<[number, number]>;
18
+ };
19
+ /** The records of one table that matched: the first `limit` of them, and how many there are. */
20
+ export type BaseSearchGroup = {
21
+ table: string;
22
+ name: string;
23
+ hits: BaseSearchHit[];
24
+ total: number;
25
+ };
26
+ export type BaseSearchOptions = {
27
+ /** Records listed per table (default 5); `total` still counts them all. */
28
+ limit?: number;
29
+ /** Whether to search a field of a table (default: every field a cell shows as text). */
30
+ field?: (table: BaseTable, column: Def) => boolean;
31
+ };
32
+ /** Search the records of every table for `query`. Tables without a match are left out. */
33
+ export declare function searchBase(tables: ReadonlyArray<BaseTable>, query: string, options?: BaseSearchOptions): BaseSearchGroup[];
34
+ export {};
@@ -0,0 +1 @@
1
+ import{cellText as G}from"./grid-access.js";import{fillFieldColumn as H}from"./registry.svelte.js";import{colId as F,primaryOf as L,rowIdOf as W}from"./base-tables.js";const J=new Set(["checkbox","button","rating","number","currency","percent","duration","autoNumber","rollup","count"]),j=90;function v(i){let o="";const t=[];let u=0;for(const a of i){const s=a.normalize("NFD").replace(/\p{M}/gu,"").toLowerCase();for(let p=0;p<s.length;p++)t.push(u);o+=s,u+=a.length}return t.push(i.length),{text:o,from:t}}const K=i=>!!i&&/[\p{L}\p{N}]/u.test(i);function z(i,o){if(!o)return-1;let t=i.indexOf(o);if(t<0)return-1;if(i===o)return 0;if(t===0)return 1;for(;t>=0;t=i.indexOf(o,t+1))if(!K(i[t-1]))return 2;return 3}const D=new WeakMap;function P(i){let o=D.get(i);return o||(o=i.filter(t=>t.field!=null||typeof t.fieldFn=="function").map(t=>{const u=H(t,i);return{id:F(t),field:String(t.field??F(t)),header:String(t.header??t.field??F(t)),fieldType:t.fieldType,def:u,visible:!0}}),D.set(i,o)),o}export function searchBase(i,o,t={}){const u=Math.max(0,t.limit??5),a=v(o.trim()).text.replace(/\s+/g," ");if(!a)return[];const s=[...new Set(a.split(" "))].sort((e,f)=>f.length-e.length),p=new Map,y=(e,f)=>{let n=p.get(e);if(!n){n=new Map;const r=i.find(c=>c.id===e);if(r){const c=L(r),k=P(r.columns).find(d=>d.field===c||d.id===c);for(const d of r.data)n.set(W(r,d),k&&k.fieldType!=="link"?m(k,d):String(d?.[c]??""))}p.set(e,n)}return n.get(f)??""};function m(e,f){if(e.fieldType==="link"){const r=f?.[e.field];return(Array.isArray(r)?r.map(String):r==null||r===""?[]:[String(r)]).map(k=>y(String(e.def.fieldProps?.table??""),k)).filter(Boolean).join(", ")}let n;try{n=typeof e.def.fieldFn=="function"?e.def.fieldFn(f):f?.[e.field]}catch{return""}return G(e,n,f)}const g=[];return i.forEach((e,f)=>{const n=L(e),r=P(e.columns).filter(l=>!J.has(l.fieldType??"")&&(!t.field||t.field(e,l.def))),c=r.find(l=>l.field===n||l.id===n),k=c??P(e.columns).find(l=>l.field===n||l.id===n),d=c?[c,...r.filter(l=>l!==c)]:r,w=[];e.data.forEach((l,S)=>{const C=d.map(h=>m(h,l)),A=C.map(h=>v(h).text);if(!s.every(h=>A.some(O=>O.includes(h))))return;let M=-1,N=[];if(A.forEach((h,O)=>{const E=z(h,a),B=s.filter(T=>h.includes(T)).length;if(!B)return;const q=E>=0?E:Math.min(...s.map(T=>z(h,T)).filter(T=>T>=0)),I=[E>=0?0:1,s.length-B,d[O]===c?0:1,q,O];(M<0||x(I,N))&&(M=O,N=I)}),M<0)return;const b=d[M],{text:U,marks:X}=Q(C[M],s),_=c?C[0]:k?m(k,l):"";w.push({hit:{table:e.id,rowId:W(e,l),title:_||"Untitled",field:b.id,fieldName:b.header,primary:b===c,text:U,marks:X},rank:[...N,S]})}),w.length&&(w.sort((l,S)=>x(l.rank,S.rank)?-1:x(S.rank,l.rank)?1:0),g.push({group:{table:e.id,name:e.name,hits:w.slice(0,u).map(l=>l.hit),total:w.length},best:w[0].rank.slice(0,4),order:f}))}),g.sort((e,f)=>x(e.best,f.best)?-1:x(f.best,e.best)?1:e.order-f.order),g.map(e=>e.group)}function x(i,o){for(let t=0;t<Math.min(i.length,o.length);t++)if(i[t]!==o[t])return i[t]<o[t];return!1}function Q(i,o){const{text:t,from:u}=v(i),a=[];for(const n of o)for(let r=t.indexOf(n);r>=0;r=t.indexOf(n,r+1))a.push([u[r],u[r+n.length]]);a.sort((n,r)=>n[0]-r[0]);const s=[];for(const n of a){const r=s[s.length-1];r&&n[0]<=r[1]?r[1]=Math.max(r[1],n[1]):s.push([n[0],n[1]])}if(i.length<=j)return{text:i,marks:s};const p=s[0]?.[0]??0,y=p>30?p-30:0,m=Math.min(i.length,y+j),g=y>0?"…":"",e=g+i.slice(y,m)+(m<i.length?"…":""),f=s.filter(([n])=>n<m).map(([n,r])=>[n-y+g.length,Math.min(r,m)-y+g.length]).filter(([n])=>n>=g.length);return{text:e,marks:f}}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * A base shown to people who may look but not change anything: `<SvBase
3
+ * readOnly>`, for a share link the app serves. The base is the same; what a
4
+ * viewer gets is decided here, as plain data, so the app can also build the
5
+ * shared copy on its server and send only that.
6
+ *
7
+ * `sharedTables` keeps the tables and views the share lists, and drops the
8
+ * fields it hides, with every field that would show what they hold: a link
9
+ * to a table that is not shared, the lookups, rollups and counts that read a
10
+ * dropped link, a lookup or rollup of a dropped field in the linked table,
11
+ * and the formulas that read any of them. A form view is not shared: there
12
+ * is nothing a viewer may send.
13
+ *
14
+ * The shared copy's records lose the dropped fields' values. A page that
15
+ * gets the whole base still has them in memory, so a share of something
16
+ * secret is the copy `sharedTables` makes on the server, sent alone.
17
+ */
18
+ import { type BaseTable } from './base-tables.js';
19
+ import type { FieldView } from './view-model.js';
20
+ /** What a read-only base shows. Every list is optional; without one, all of it is shown. */
21
+ export type BaseShare = {
22
+ /** The ids of the tables shown, in their order in the base. */
23
+ tables?: ReadonlyArray<string>;
24
+ /** The ids of the views shown. A table none of whose views is listed shows its first one. */
25
+ views?: ReadonlyArray<string>;
26
+ /** Fields left out: a column id (in every table) or `tableId.columnId`. The primary field always shows. */
27
+ hideFields?: ReadonlyArray<string>;
28
+ };
29
+ /** The share a `readOnly` prop describes, or null for a base people can edit. */
30
+ export declare function shareOf(readOnly: boolean | BaseShare | null | undefined): BaseShare | null;
31
+ /** A grid of a read-only base (`<SvBase readOnly>` hands its grids `baseReadOnly`). */
32
+ export declare const isReadOnlyGrid: (ctrl: any) => boolean;
33
+ /** The field menu of a read-only grid: filter, group, hide and color by, no field changes. */
34
+ export declare function viewOnlyItems<T extends {
35
+ key?: string;
36
+ }>(ctrl: any, items: T[]): T[];
37
+ /** The tables of `tables` a share shows, with its fields and views. */
38
+ export declare function sharedTables(tables: ReadonlyArray<BaseTable>, share: BaseShare): BaseTable[];
39
+ /** The views of a table a share shows: no form, only the listed ones, and at least one. */
40
+ export declare function sharedViews(views: ReadonlyArray<FieldView> | undefined, share: BaseShare): FieldView[] | undefined;
41
+ /**
42
+ * A `selectionBar` prop without the buttons that change records ("Edit
43
+ * fields", "Delete"). An app's own actions stay: they are the app's to judge.
44
+ */
45
+ export declare function readOnlySelectionBar(bar: unknown): unknown;
@@ -0,0 +1 @@
1
+ import{colId as d,linkReaders as k,primaryOf as P}from"./base-tables.js";import{formulaReaders as v}from"./formula.js";export function shareOf(i){return i?i===!0?{}:i:null}export const isReadOnlyGrid=i=>i?.props?.baseReadOnly===!0;const T=new Set(["field-rowcolor","field-filter","field-group","field-hide"]);export function viewOnlyItems(i,t){return isReadOnlyGrid(i)?t.filter(l=>T.has(String(l.key))):t}export function sharedTables(i,t){const l=t.tables?new Set(t.tables):null,r=l?i.filter(e=>l.has(e.id)):[...i],p=new Set(r.map(e=>e.id)),a=new Set(t.hideFields??[]),m=new Map(r.map(e=>[e.id,new Set])),S=new Map(r.map(e=>[e.id,P(e)])),y=(e,n)=>d(n)===S.get(e.id)||String(n.field??"")===S.get(e.id),h=(e,n)=>{const f=m.get(e.id);return f.has(d(n))||y(e,n)?!1:(f.add(d(n)),!0)};for(const e of r)for(const n of e.columns){const f=d(n);(a.has(f)||a.has(`${e.id}.${f}`)||n.fieldType==="link"&&!p.has(String(n.fieldProps?.table??"")))&&h(e,n)}for(let e=!0;e;){e=!1;for(const n of r){const f=m.get(n.id);for(const o of n.columns){if(!f.has(d(o)))continue;const s=[...o.fieldType==="link"?k(n,o):[],...v(n.columns,o)];for(const c of s)h(n,c)&&(e=!0)}for(const o of n.columns){if(o.fieldType!=="lookup"&&o.fieldType!=="rollup")continue;const s=n.columns.find(u=>d(u)===String(o.fieldProps?.linkField??"")||String(u.field??"")===String(o.fieldProps?.linkField??"")),c=r.find(u=>u.id===String(s?.fieldProps?.table??"")),g=c?.columns.find(u=>d(u)===String(o.fieldProps?.field??"")||String(u.field??"")===String(o.fieldProps?.field??""));c&&g&&m.get(c.id).has(d(g))&&h(n,o)&&(e=!0)}}}const w=e=>e.map(n=>({...n,editable:!1}));return r.map(e=>{const n=m.get(e.id);if(!n.size)return{...e,columns:w(e.columns),views:sharedViews(e.views,t)};const f=e.columns.filter(s=>n.has(d(s))&&s.field!=null).map(s=>String(s.field)),o=f.length?e.data.map(s=>{const c={...s};for(const g of f)delete c[g];return c}):e.data;return{...e,columns:w(e.columns.filter(s=>!n.has(d(s)))),data:o,views:sharedViews(e.views,t)}})}export function sharedViews(i,t){if(!i)return;const l=i.filter(a=>a.type!=="form"),r=t.views?new Set(t.views):null,p=r?l.filter(a=>r.has(a.id)):l;return p.length?p:l.length?[l[0]]:void 0}export function readOnlySelectionBar(i){const t=l=>l.filter(r=>r!=="editFields"&&r!=="deleteRows");return Array.isArray(i)?t(i):i&&typeof i=="object"&&Array.isArray(i.actions)?{...i,actions:t(i.actions)}:i}
@@ -1,13 +1,13 @@
1
- import{colId as q,primaryOf as z,rowIdOf as T}from"./base-tables.js";import{fillFieldColumn as C}from"./registry.svelte.js";export const SQL_COMMENT_PREFIX="svgrid:",BASE_ORDER_COLUMN="svgrid_order";export function sqlName(o){const f=String(o).replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,"").toLowerCase();return/^[a-z_]/.test(f)?f:`t_${f}`}const F=new Set(["formula","lookup","rollup","count","button"]),s=o=>`"${o.replace(/"/g,'""')}"`,p=o=>`'${o.replace(/'/g,"''")}'`,y=o=>Array.isArray(o)?o.map(String):o==null||o===""?[]:[String(o)];function S(o){switch(o.fieldType){case"number":case"currency":case"percent":case"rating":case"duration":case"autoNumber":return"double precision";case"checkbox":return"boolean";case"date":return o.fieldProps?.time?"timestamptz":"date";case"createdTime":case"lastModifiedTime":return"timestamptz";case"multiSelect":return"text[]";case"user":case"createdBy":case"lastModifiedBy":return o.fieldProps?.multiple?"text[]":"text";case"attachment":return"jsonb";default:return J(o)}}const N=new WeakMap;function J(o){let f=N.get(o);if(f===void 0){const m=C(o).cellDataType;f=m==="number"?"double precision":m==="boolean"?"boolean":m==="date"?"timestamptz":m==="dateString"?"date":"text",N.set(o,f)}return f}const E=864e5;export function baseToSql(o,f={}){const m=f.today??new Date,A=Date.UTC(m.getFullYear(),m.getMonth(),m.getDate()),k=f.relativeDays??400,_=new Set,u=new Map;for(const e of o){let n=sqlName(e.name||e.id);for(;_.has(n);)n=`${n}_2`;_.add(n),u.set(e.id,n)}const j=e=>o.find(n=>n.id===e),D=(e,n)=>e.columns.find(t=>q(t)===n);function P(e,n){const t=j(String(n.fieldProps?.table??"")),r=n.fieldProps?.inverse&&t?D(t,String(n.fieldProps.inverse)):void 0,l=n.fieldProps?.multiple!==!1;if(!r||t===e)return l?"junction":"fk";const c=r.fieldProps?.multiple!==!1;return l?c&&o.indexOf(e)<=o.indexOf(t)?"junction":"derived":"fk"}const b=e=>JSON.parse(JSON.stringify(e??null),(n,t)=>n==="table"&&typeof t=="string"&&u.has(t)?u.get(t):t),g=[],$=[];for(const e of o){const n=u.get(e.id),t=[],r=[],l=new Set(["id",BASE_ORDER_COLUMN]),c=a=>{let d=sqlName(a);for(;l.has(d);)d=`${d}_2`;return l.add(d),d};for(const a of e.columns){if(a.field==null)continue;const d=String(a.field);if(F.has(String(a.fieldType))){r.push(a);continue}if(a.fieldType==="link"){const O=P(e,a),w=j(String(a.fieldProps?.table??""));if(!w)continue;if(O==="fk")t.push({def:a,column:c(`${d}_id`),fk:u.get(w.id)});else if(r.push(a),O==="junction"){const M=`${sqlName(n).replace(/s$/,"")}_id`;let h=`${sqlName(d).replace(/s$/,"")}_id`;h===M&&(h=`${h}_2`),$.push({name:`${n}_${sqlName(d)}`,owner:e,field:d,from:M,to:h,target:w})}continue}t.push({def:a,column:c(d)})}const x=[' "id" text primary key default gen_random_uuid()::text',` ${s(BASE_ORDER_COLUMN)} bigint generated always as identity`,...t.map(a=>` ${s(a.column)} ${a.fk?"text":S(a.def)}`)];g.push({table:e,columns:t,extra:r,sql:`create table ${s(n)} (
1
+ import{colId as q,primaryOf as z,rowIdOf as T}from"./base-tables.js";import{fillFieldColumn as C}from"./registry.svelte.js";export const SQL_COMMENT_PREFIX="svgrid:",BASE_ORDER_COLUMN="svgrid_order";export function sqlName(o){const f=String(o).replace(/([a-z0-9])([A-Z])/g,"$1_$2").replace(/[^A-Za-z0-9]+/g,"_").replace(/^_+|_+$/g,"").toLowerCase();return/^[a-z_]/.test(f)?f:`t_${f}`}const F=new Set(["formula","lookup","rollup","count","button"]),s=o=>`"${o.replace(/"/g,'""')}"`,m=o=>`'${o.replace(/'/g,"''")}'`,y=o=>Array.isArray(o)?o.map(String):o==null||o===""?[]:[String(o)];function S(o){switch(o.fieldType){case"number":case"currency":case"percent":case"rating":case"duration":case"autoNumber":return"double precision";case"checkbox":return"boolean";case"date":return o.fieldProps?.time?"timestamptz":"date";case"createdTime":case"lastModifiedTime":return"timestamptz";case"multiSelect":return"text[]";case"user":case"createdBy":case"lastModifiedBy":return o.fieldProps?.multiple?"text[]":"text";case"attachment":case"checklist":return"jsonb";case"timeOfDay":return"time";default:return J(o)}}const N=new WeakMap;function J(o){let f=N.get(o);if(f===void 0){const p=C(o).cellDataType;f=p==="number"?"double precision":p==="boolean"?"boolean":p==="date"?"timestamptz":p==="dateString"?"date":"text",N.set(o,f)}return f}const E=864e5;export function baseToSql(o,f={}){const p=f.today??new Date,D=Date.UTC(p.getFullYear(),p.getMonth(),p.getDate()),w=f.relativeDays??400,_=new Set,u=new Map;for(const e of o){let n=sqlName(e.name||e.id);for(;_.has(n);)n=`${n}_2`;_.add(n),u.set(e.id,n)}const j=e=>o.find(n=>n.id===e),A=(e,n)=>e.columns.find(t=>q(t)===n);function P(e,n){const t=j(String(n.fieldProps?.table??"")),r=n.fieldProps?.inverse&&t?A(t,String(n.fieldProps.inverse)):void 0,l=n.fieldProps?.multiple!==!1;if(!r||t===e)return l?"junction":"fk";const c=r.fieldProps?.multiple!==!1;return l?c&&o.indexOf(e)<=o.indexOf(t)?"junction":"derived":"fk"}const b=e=>JSON.parse(JSON.stringify(e??null),(n,t)=>n==="table"&&typeof t=="string"&&u.has(t)?u.get(t):t),g=[],$=[];for(const e of o){const n=u.get(e.id),t=[],r=[],l=new Set(["id",BASE_ORDER_COLUMN]),c=a=>{let d=sqlName(a);for(;l.has(d);)d=`${d}_2`;return l.add(d),d};for(const a of e.columns){if(a.field==null)continue;const d=String(a.field);if(F.has(String(a.fieldType))){r.push(a);continue}if(a.fieldType==="link"){const O=P(e,a),k=j(String(a.fieldProps?.table??""));if(!k)continue;if(O==="fk")t.push({def:a,column:c(`${d}_id`),fk:u.get(k.id)});else if(r.push(a),O==="junction"){const M=`${sqlName(n).replace(/s$/,"")}_id`;let h=`${sqlName(d).replace(/s$/,"")}_id`;h===M&&(h=`${h}_2`),$.push({name:`${n}_${sqlName(d)}`,owner:e,field:d,from:M,to:h,target:k})}continue}t.push({def:a,column:c(d)})}const x=[' "id" text primary key default gen_random_uuid()::text',` ${s(BASE_ORDER_COLUMN)} bigint generated always as identity`,...t.map(a=>` ${s(a.column)} ${a.fk?"text":S(a.def)}`)];g.push({table:e,columns:t,extra:r,sql:`create table ${s(n)} (
2
2
  ${x.join(`,
3
3
  `)}
4
4
  );`})}const i=[];i.push(`-- ${f.title??"A base"}, as Postgres tables. Made by baseToSql (@svgrid/enterprise/base);`),i.push("-- the svgrid: comments keep what SQL has no type for, so baseFromDatabase opens it as the same base."),i.push("");for(const e of g)i.push(e.sql);for(const e of $)i.push(`create table ${s(e.name)} (
5
5
  "id" serial primary key,
6
6
  ${s(e.from)} text not null,
7
7
  ${s(e.to)} text not null
8
- );`);i.push("");for(const e of g){const n=u.get(e.table.id);for(const r of e.columns)i.push(`comment on column ${s(n)}.${s(r.column)} is ${p(SQL_COMMENT_PREFIX+JSON.stringify(b(r.def)))};`);const t={v:1,name:e.table.name,position:g.indexOf(e),primaryField:z(e.table),order:e.table.columns.filter(r=>r.field!=null).map(r=>String(r.field)),extra:b(e.extra),...e.table.views?{views:b(e.table.views)}:{},...e.table.automations?.length?{automations:b(e.table.automations)}:{}};i.push(`comment on table ${s(n)} is ${p(SQL_COMMENT_PREFIX+JSON.stringify(t))};`)}for(const e of $){const n={v:1,junction:{owner:u.get(e.owner.id),field:e.field,from:e.from,to:e.to}};i.push(`comment on table ${s(e.name)} is ${p(SQL_COMMENT_PREFIX+JSON.stringify(n))};`)}if(f.data!==!1){const e=(n,t)=>{if(t==null||t===""||Array.isArray(t)&&t.length===0&&S(n)!=="text[]"&&S(n)!=="jsonb")return"null";const r=S(n);if(r==="jsonb"){const l=Array.isArray(t)?t.filter(c=>!(c&&typeof c=="object"&&String(c.url??"").startsWith("blob:"))):t;return`${p(JSON.stringify(l))}::jsonb`}if(r==="text[]")return`array[${y(t).map(p).join(", ")}]::text[]`;if(r==="boolean")return t?"true":"false";if(r==="double precision")return Number.isFinite(Number(t))?String(Number(t)):"null";if(r==="date"&&typeof t=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t)&&k>0){const l=Math.round((Date.parse(`${t}T00:00:00Z`)-A)/E);if(Math.abs(l)<=k)return l===0?"current_date":`current_date ${l>0?"+":"-"} ${Math.abs(l)}`}return p(String(t))};i.push("");for(const n of g){const t=n.table.data.filter(Boolean);if(!t.length)continue;const r=["id",...n.columns.map(c=>c.column)],l=t.map(c=>` (${[p(T(n.table,c)),...n.columns.map(a=>a.fk?y(c[String(a.def.field)])[0]!=null?p(y(c[String(a.def.field)])[0]):"null":e(a.def,c[String(a.def.field)]))].join(", ")})`);i.push(`insert into ${s(u.get(n.table.id))} (${r.map(s).join(", ")}) values
8
+ );`);i.push("");for(const e of g){const n=u.get(e.table.id);for(const r of e.columns)i.push(`comment on column ${s(n)}.${s(r.column)} is ${m(SQL_COMMENT_PREFIX+JSON.stringify(b(r.def)))};`);const t={v:1,name:e.table.name,position:g.indexOf(e),primaryField:z(e.table),order:e.table.columns.filter(r=>r.field!=null).map(r=>String(r.field)),extra:b(e.extra),...e.table.views?{views:b(e.table.views)}:{},...e.table.automations?.length?{automations:b(e.table.automations)}:{}};i.push(`comment on table ${s(n)} is ${m(SQL_COMMENT_PREFIX+JSON.stringify(t))};`)}for(const e of $){const n={v:1,junction:{owner:u.get(e.owner.id),field:e.field,from:e.from,to:e.to}};i.push(`comment on table ${s(e.name)} is ${m(SQL_COMMENT_PREFIX+JSON.stringify(n))};`)}if(f.data!==!1){const e=(n,t)=>{if(t==null||t===""||Array.isArray(t)&&t.length===0&&S(n)!=="text[]"&&S(n)!=="jsonb")return"null";const r=S(n);if(r==="jsonb"){const l=Array.isArray(t)?t.filter(c=>!(c&&typeof c=="object"&&String(c.url??"").startsWith("blob:"))):t;return`${m(JSON.stringify(l))}::jsonb`}if(r==="text[]")return`array[${y(t).map(m).join(", ")}]::text[]`;if(r==="boolean")return t?"true":"false";if(r==="double precision")return Number.isFinite(Number(t))?String(Number(t)):"null";if(r==="date"&&typeof t=="string"&&/^\d{4}-\d{2}-\d{2}$/.test(t)&&w>0){const l=Math.round((Date.parse(`${t}T00:00:00Z`)-D)/E);if(Math.abs(l)<=w)return l===0?"current_date":`current_date ${l>0?"+":"-"} ${Math.abs(l)}`}return m(String(t))};i.push("");for(const n of g){const t=n.table.data.filter(Boolean);if(!t.length)continue;const r=["id",...n.columns.map(c=>c.column)],l=t.map(c=>` (${[m(T(n.table,c)),...n.columns.map(a=>a.fk?y(c[String(a.def.field)])[0]!=null?m(y(c[String(a.def.field)])[0]):"null":e(a.def,c[String(a.def.field)]))].join(", ")})`);i.push(`insert into ${s(u.get(n.table.id))} (${r.map(s).join(", ")}) values
9
9
  ${l.join(`,
10
- `)};`)}for(const n of $){const t=[];for(const r of n.owner.data)if(r)for(const l of y(r[n.field]))t.push(` (${p(T(n.owner,r))}, ${p(l)})`);t.length&&i.push(`insert into ${s(n.name)} (${s(n.from)}, ${s(n.to)}) values
10
+ `)};`)}for(const n of $){const t=[];for(const r of n.owner.data)if(r)for(const l of y(r[n.field]))t.push(` (${m(T(n.owner,r))}, ${m(l)})`);t.length&&i.push(`insert into ${s(n.name)} (${s(n.from)}, ${s(n.to)}) values
11
11
  ${t.join(`,
12
12
  `)};`)}}i.push("");for(const e of g){const n=u.get(e.table.id);for(const t of e.columns)t.fk&&i.push(`alter table ${s(n)} add foreign key (${s(t.column)}) references ${s(t.fk)}("id") on delete set null;`)}for(const e of $)i.push(`alter table ${s(e.name)} add foreign key (${s(e.from)}) references ${s(u.get(e.owner.id))}("id") on delete cascade;`),i.push(`alter table ${s(e.name)} add foreign key (${s(e.to)}) references ${s(u.get(e.target.id))}("id") on delete cascade;`);return i.join(`
13
13
  `)+`
@@ -0,0 +1,51 @@
1
+ /**
2
+ * The trash of a base: records, fields and tables that were deleted, kept so
3
+ * they can be put back. Restoring puts a record back in its table at the
4
+ * place it had, a field back among its table's fields (its values were never
5
+ * taken out of the records), and a table back among the tabs. Links come
6
+ * back from the restored side: a record that linked to others lists them
7
+ * again, and so do they.
8
+ *
9
+ * The trash is plain data (`BaseTrashItem[]`), so an app can store it with
10
+ * the tables. Items older than the base's `trashDays` are dropped when the
11
+ * base opens.
12
+ */
13
+ import { type BaseTable } from './base-tables.js';
14
+ type Row = Record<string, unknown>;
15
+ type Def = Record<string, any>;
16
+ type Deleted = {
17
+ /** The item's own id in the trash. */
18
+ id: string;
19
+ /** When it was deleted (ISO). */
20
+ deletedAt: string;
21
+ /** Who deleted it: the current user's id (`setCurrentUser`), when there is one. */
22
+ deletedBy?: string;
23
+ };
24
+ export type BaseTrashItem = (Deleted & {
25
+ kind: 'record';
26
+ table: string;
27
+ row: Row;
28
+ index: number;
29
+ }) | (Deleted & {
30
+ kind: 'field';
31
+ table: string;
32
+ column: Def;
33
+ index: number;
34
+ }) | (Deleted & {
35
+ kind: 'table';
36
+ table: BaseTable;
37
+ index: number;
38
+ });
39
+ /** Trash items for records just deleted from `table`: `before` is its rows as they were. */
40
+ export declare function trashRecords(table: BaseTable, before: ReadonlyArray<Row>, ids: ReadonlyArray<string>, by?: string, now?: Date): BaseTrashItem[];
41
+ export declare function trashField(table: BaseTable, column: Def, index: number, by?: string, now?: Date): BaseTrashItem;
42
+ export declare function trashTable(table: BaseTable, index: number, by?: string, now?: Date): BaseTrashItem;
43
+ /** What an item is called in the trash: the record's name, the field's, the table's. */
44
+ export declare function trashLabel(item: BaseTrashItem, tables: ReadonlyArray<BaseTable>): string;
45
+ /** Why an item cannot go back now, or '' when it can. */
46
+ export declare function cannotRestore(item: BaseTrashItem, tables: ReadonlyArray<BaseTable>): string;
47
+ /** The tables with `items` put back (each one that can be). */
48
+ export declare function restoreItems(tables: BaseTable[], items: ReadonlyArray<BaseTrashItem>): BaseTable[];
49
+ /** The items deleted within the last `days` days. */
50
+ export declare function freshTrash(items: ReadonlyArray<BaseTrashItem>, days: number, now?: Date): BaseTrashItem[];
51
+ export {};
@@ -0,0 +1 @@
1
+ import{addInverse as u,colId as a,primaryOf as h,rowIdOf as c,syncAllInverses as p}from"./base-tables.js";let m=0;const x=()=>`trash-${Date.now().toString(36)}-${m+=1}`;function f(t,o){return{id:x(),deletedAt:o.toISOString(),...t?{deletedBy:t}:{}}}export function trashRecords(t,o,e,r,l=new Date){const s=new Set(e),n=[];return o.forEach((i,d)=>{i&&s.has(c(t,i))&&n.push({...f(r,l),kind:"record",table:t.id,row:i,index:d})}),n}export function trashField(t,o,e,r,l=new Date){return{...f(r,l),kind:"field",table:t.id,column:o,index:e}}export function trashTable(t,o,e,r=new Date){return{...f(e,r),kind:"table",table:t,index:o}}export function trashLabel(t,o){if(t.kind==="table")return t.table.name;if(t.kind==="field")return String(t.column.header??t.column.field??"Field");const e=o.find(s=>s.id===t.table),r=e?t.row[h(e)]:void 0;return(Array.isArray(r)?r.join(", "):r==null?"":String(r)).trim()||"Unnamed record"}export function cannotRestore(t,o){if(t.kind==="table")return o.some(r=>r.id===t.table.id)?"A table with its id is in the base":"";const e=o.find(r=>r.id===t.table);return e?t.kind==="record"?e.data.some(r=>r&&c(e,r)===c(e,t.row))?"The record is in its table":"":e.columns.some(r=>a(r)===a(t.column))?"A field with its id is in the table":"":"Its table was deleted: restore the table first"}export function restoreItems(t,o){let e=t;const r={table:0,field:1,record:2},l=[...o].sort((n,i)=>r[n.kind]-r[i.kind]||n.index-i.index),s=new Set;for(const n of l)if(!cannotRestore(n,e))if(n.kind==="table"){const i=e.slice();i.splice(Math.min(n.index,i.length),0,n.table),e=i;for(const d of n.table.columns)d.fieldType==="link"&&e.some(b=>b.id===d.fieldProps?.table)&&(e=u(e,n.table.id,a(d)));s.add(n.table.id)}else n.kind==="field"?(e=e.map(i=>{if(i.id!==n.table)return i;const d=i.columns.slice();return d.splice(Math.min(n.index,d.length),0,n.column),{...i,columns:d}}),n.column.fieldType==="link"&&(e=u(e,n.table,a(n.column))),s.add(n.table)):(e=e.map(i=>{if(i.id!==n.table)return i;const d=i.data.slice();return d.splice(Math.min(n.index,d.length),0,n.row),{...i,data:d}}),s.add(n.table));for(const n of s)e=p(e,n);return e}export function freshTrash(t,o,e=new Date){if(!(o>0))return[...t];const r=e.getTime()-o*864e5;return t.filter(l=>new Date(l.deletedAt).getTime()>=r)}
@@ -1 +1 @@
1
- import{fillFieldColumn as B}from"./registry.svelte.js";import ne from"./RatingCell.svelte";import T from"./LinkCell.svelte";import se from"./AttachmentCell.svelte";import ce from"./CheckboxCell.svelte";import V from"./PercentCell.svelte";import A from"./UserCell.svelte";import ue from"./ButtonCell.svelte";import de from"./BarcodeCell.svelte";import me from"./LinkedRecordsCell.svelte";import pe from"./RichTextCell.svelte";import z from"./SelectCell.svelte";import{attachmentsText as fe,parseAttachments as be}from"./attachments.js";import{dateEditTokens as he,formatCurrency as _,formatDate as C,formatDuration as ye,formatNumber as F,formatPercent as H,numberFieldShape as j,numberFromText as ge,numberKind as ke,parseDuration as G,toNumber as b}from"./format.js";import{BRIGHT as N,CHECKBOX_ICONS as we,RATING_ICONS as ve}from"./palette.js";import{compileFormula as Me,isoDate as Se,selfReferenceError as Te}from"./formula.js";import{findFieldUser as Ae,getCurrentUser as W,getFieldUsers as K,getLinkedTable as k,linkedRows as w,listLinkedTables as Ce,resolveLinkIds as Fe}from"./sources.svelte.js";import{splitNames as $}from"./name-list.js";import{linkedFields as Ne}from"./linked-fields.js";const X=new WeakMap;let h=0;const Le=new Set(["formula","lookup","rollup","count"]);function Y(e,t){const l=o=>o?.[t];if(!e?.fields?.length)return l;let r=X.get(e.fields);if(r||X.set(e.fields,r=new Map),!r.has(t)){const o=Ne(e).find(n=>n.def.field===t);r.set(t,o?.def.fieldFn??null)}const i=r.get(t);return i?o=>{if(h>3)return l(o);h+=1;try{return i(o)}finally{h-=1}}:l}const a={text:"M4 6h16M4 12h10M4 18h7",longText:"M4 6h16M4 10h16M4 14h16M4 18h10",number:"M9 4 7 20M17 4l-2 16M4 9h16M3 15h16",currency:"M12 3v18M16 7.5C16 5.6 14.2 4.5 12 4.5S8 5.6 8 7.5s1.8 2.7 4 3.5 4 1.6 4 3.5-1.8 3-4 3-4-1.1-4-3",percent:"M19 5 5 19M7 7h.01M17 17h.01",date:"M4 6h16v14H4zM4 10h16M8 3v4M16 3v4",duration:"M12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16zM12 8v4l3 2",checkbox:"M4 4h16v16H4zM8 12l3 3 5-6",singleSelect:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM8 11l4 4 4-4",multiSelect:"M3 7h11M3 12h11M3 17h11M17 6l2 2 3-3M17 16l2 2 3-3",rating:"M12 3l2.8 5.7 6.2.9-4.5 4.4 1 6.2L12 17.3 6.5 20.2l1-6.2L3 9.6l6.2-.9z",url:"M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1",email:"M3 6h18v12H3zM3 7l9 6 9-6",phone:"M5 4h4l2 5-2.5 1.5a11 11 0 0 0 5 5L15 13l5 2v4a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2",attachment:"M20 11.5 12.3 19a5 5 0 0 1-7.1-7.1l7.8-7.8a3.3 3.3 0 0 1 4.7 4.7L9.9 16.6a1.7 1.7 0 0 1-2.4-2.4l7.1-7",user:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0",createdTime:"M12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16zM12 8v4h4",modifiedTime:"M4 12a8 8 0 1 0 2.3-5.7M4 4v4h4M12 8v4l3 2",createdBy:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 11-7.5M19 15v6M16 18h6",modifiedBy:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 11-7.5M16 21l5-5-2-2-5 5v2z",autoNumber:"M5 7h3v10M11 9a2 2 0 1 1 4 0c0 2-4 3-4 6h4M18 7h2v10",barcode:"M4 5v14M7 5v14M10 5v14M13 5v14M15 5v14M18 5v14M20 5v14",button:"M4 7h16v10H4zM9 12h6",formula:"M7 20c2 0 2.5-2 3-5l2-10c.5-2 1.5-2 3-2M8 9h7",link:"M9 7H6a5 5 0 0 0 0 10h3M15 7h3a5 5 0 0 1 0 10h-3M8 12h8",lookup:"M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM20 20l-4-4M8 11h6",rollup:"M6 4h12L12 12l6 8H6",count:"M5 5h14v14H5zM9 9v6M12 9v6M15 9v6"},Ie={key:"separators",label:"Separators",kind:"choice",choices:[{value:"local",label:"Local"},{value:"comma-period",label:"1,000,000.00"},{value:"period-comma",label:"1.000.000,00"},{value:"space-comma",label:"1 000 000,00"},{value:"space-period",label:"1 000 000.00"}]},Pe={key:"showThousands",label:"Show thousands separator",kind:"checkbox"},Oe={key:"abbreviation",label:"Large number abbreviation",kind:"choice",choices:[{value:"none",label:"None"},{value:"thousand",label:"Thousand (K)"},{value:"million",label:"Million (M)"},{value:"billion",label:"Billion (B)"}]},De={key:"allowNegative",label:"Allow negative numbers",kind:"checkbox"},y={key:"default",label:"Default value",kind:"default",hint:"New rows start with this value."},L=(e,t)=>Array.from({length:t-e+1},(l,r)=>{const i=e+r;return{value:String(i),label:i===0?"1":`1.${"0".repeat(i)}`}}),v={key:"dateFormat",label:"Date format",kind:"choice",choices:[{value:"local",label:"Local"},{value:"friendly",label:"Friendly (October 14, 2026)"},{value:"us",label:"US (10/14/2026)"},{value:"european",label:"European (14/10/2026)"},{value:"iso",label:"ISO (2026-10-14)"}]},I=[{key:"time",label:"Include time",kind:"checkbox"},{key:"timeFormat",label:"Time format",kind:"segmented",choices:[{value:"12hour",label:"12 hour"},{value:"24hour",label:"24 hour"}],visible:e=>!!e.time},{key:"gmt",label:"Use the same time zone (GMT) for everyone",kind:"checkbox",visible:e=>!!e.time},{key:"showTimeZone",label:"Display time zone",kind:"checkbox",visible:e=>!!e.time}],Re=e=>e.columns.filter(t=>t.fieldType==="link").map(t=>({value:String(t.id??t.field),label:String(t.header??t.field)})),P={key:"linkField",label:"Link field",kind:"choice",choices:Re,hint:"A link-to-records field of this table."},Ee=e=>{const t=e.columns.find(i=>String(i.id??i.field)===e.props.linkField),l=k(t?.fieldProps?.table);return l?(l.fields??[{field:l.primaryField,header:l.primaryField}]).map(i=>({value:i.field,label:i.header})):[]},q={key:"field",label:"Field in the linked table",kind:"choice",choices:Ee,visible:e=>!!e.linkField},J=(e,t=0)=>{const l=Number(e.precision);return Number.isInteger(l)&&l>=0&&l<=8?l:t},Ue=e=>({precision:e.format==="integer"?0:J(e,e.format==="decimal"?1:0),separators:e.separators,showThousands:e.showThousands!==!1,abbreviation:e.abbreviation}),xe=(e,t)=>l=>{const r=typeof l.rawInput=="string"?l.rawInput:l.newValue;if(typeof r=="number"||r==null)return r;if(String(r).trim()==="")return null;const i=ge(String(r),e,t);return i??l.oldValue},Be=(e,t)=>t.allowNegative===!1&&!e.validate?{rejectInvalid:!0,validate:l=>Number(l.value)<0?"Negative numbers are not allowed":null}:{},Ve=(e,t)=>{const l={precision:j(e,t).places,separators:t.separators,showThousands:t.showThousands!==!1,abbreviation:e==="percent"?void 0:t.abbreviation};return r=>{const i=b(r.value);return i==null?"":e==="currency"?_(i,{...l,symbol:t.symbol,symbolPosition:t.symbolPosition}):e==="percent"?H(i,{...l,points:t.points}):F(i,l)}},O=(e,t,l)=>({...e,cellDataType:e.cellDataType??"number",editorType:e.editorType??"fieldNumber",align:e.align??(l==="percent"&&t.showBar?"left":"right"),...Be(e,t),valueParser:e.valueParser??xe(l,t),formatter:e.formatter??Ve(l,t)}),g=e=>Array.isArray(e.options)?e.options.map(t=>({value:t.value,label:t.label??String(t.value),...t.color?{color:t.color}:{}})):[],Q=(e,t)=>{const l=new Map;for(const i of g(e))l.set(String(i.value).toLowerCase(),i.value),l.set(String(i.label).toLowerCase(),i.value);const r=i=>l.get(i.toLowerCase())??i;return i=>{if(typeof i.rawInput!="string")return i.newValue;const o=i.rawInput.split(t?",":/\n/).map(n=>n.trim()).filter(Boolean);return t?[...new Set(o.map(r))]:o.length?r(o[0]):null}},Z=e=>{const t=new Map(g(e).map(l=>[String(l.value),l.label]));return l=>(Array.isArray(l.value)?l.value:l.value==null||l.value===""?[]:[l.value]).map(r=>t.get(String(r))??String(r)).join(", ")},ze=e=>{const t=new Map(g(e).map((l,r)=>[String(l.value),r]));return l=>l==null||l===""?null:t.get(String(l))??t.size},ee=e=>{const t={};for(const l of e){const r=String(l.field??l.id??"");r&&(t[r.toLowerCase()]=r,typeof l.header=="string"&&(t[l.header.trim().toLowerCase()]=r))}return t},d=e=>({editable:e.editable??!1}),D=e=>t=>C(t.value,e),R=e=>(Array.isArray(e)?e:e==null||e===""?[]:[e]).map(t=>Ae(t)?.name??String(t)).join(", "),_e=e=>t=>{if(typeof t.rawInput!="string")return t.newValue;const l=K(),r=o=>{const n=o.toLowerCase();return l.find(m=>m.id.toLowerCase()===n||m.name.toLowerCase()===n||m.email?.toLowerCase()===n)?.id??o},i=e?$(t.rawInput):t.rawInput.split(/\n/).map(o=>o.trim()).filter(Boolean);return e?[...new Set(i.map(r))]:i.length?r(i[0]):null},He=e=>t=>{if(typeof t.rawInput!="string")return t.newValue;const l=k(e.table);if(!l)return t.newValue;const r=Fe(l,$(t.rawInput));return e.multiple===!1?r.slice(0,1):r};function te(e,t){if(e==null)return"";if(Array.isArray(e))return e.map(l=>te(l,t)).join(", ");if(e instanceof Date)return C(e,t);if(typeof e=="boolean")return e?"true":"false";if(typeof e=="number"){if(t.result==="currency"||t.result==="percent"||t.result==="number"){const l=t.result,r={...Ue(t),precision:j(l,{precision:t.precision}).places};return l==="currency"?_(e,{...r,symbol:t.symbol}):l==="percent"?H(e,r):F(e,r)}return String(Math.round(e*1e10)/1e10)}if(t.result==="date"){const l=Se(String(e));if(l)return C(l,t)}return String(e)}const E={SUM:e=>e.reduce((t,l)=>t+(b(l)??0),0),AVERAGE:e=>{const t=e.map(b).filter(l=>l!=null);return t.length?t.reduce((l,r)=>l+r,0)/t.length:null},MIN:e=>{const t=e.map(b).filter(l=>l!=null);return t.length?Math.min(...t):null},MAX:e=>{const t=e.map(b).filter(l=>l!=null);return t.length?Math.max(...t):null},COUNT:e=>e.filter(t=>typeof t=="number").length,COUNTA:e=>e.filter(t=>t!=null&&t!=="").length,COUNTALL:e=>e.length,ARRAYJOIN:e=>e.filter(t=>t!=null&&t!=="").map(String).join(", "),ARRAYUNIQUE:e=>[...new Set(e.filter(t=>t!=null&&t!=="").map(String))].join(", "),CONCATENATE:e=>e.map(t=>t==null?"":String(t)).join(""),AND:e=>e.every(Boolean),OR:e=>e.some(Boolean)},U=(e,t)=>{const l=t.columns.find(i=>String(i.id??i.field)===e.linkField);if(!l)return null;const r=l.fieldProps?.table;return{key:String(l.field??l.id),get table(){return k(r)}}},le=new WeakMap;function re(e,t){const l=e?.table?.fields;if(!l)return;let r=le.get(l);r||le.set(l,r=new Map);const i=String(t);if(r.has(i))return r.get(i);const o=l.find(m=>m.field===i),n=o?.fieldType?B({field:o.field,fieldType:o.fieldType,fieldProps:o.fieldProps}).formatter:void 0;return r.set(i,n),n}const M=()=>new Date().toISOString(),ie=[{key:"watch",label:"Changes to",kind:"segmented",choices:[{value:"all",label:"All fields"},{value:"specific",label:"Specific fields"}]},{key:"watchFields",label:"Fields",kind:"columns",visible:e=>e.watch==="specific"}];export const BUILTIN_FIELD_TYPES=[{id:"text",label:"Single line text",description:"A short line of text, like a name or a title.",icon:a.text,group:"basic",properties:[y],fill:e=>({...e,editorType:e.editorType??"text"})},{id:"longText",label:"Long text",description:"Several lines of text; Alt+Enter starts a new line.",icon:a.longText,group:"basic",width:260,properties:[{key:"richText",label:"Enable rich text formatting",kind:"checkbox",hint:"**bold**, *italic*, `code`, [links](https://...) and lists."}],fill:e=>({...e,editorType:e.editorType??"fieldLongText"}),cell:pe,hasCell:e=>!!e.richText},{id:"attachment",label:"Attachment",description:"Images and files: thumbnails in the cell, a dialog to add more.",icon:a.attachment,group:"basic",width:180,defaults:{maxFiles:20},properties:[{key:"accept",label:"Accepted types",kind:"text",placeholder:"image/*,.pdf (any when empty)"},{key:"maxFiles",label:"Most files per cell",kind:"number",min:1,max:100}],fill:(e,t)=>({...e,editorType:e.editorType??"attachment",formatter:e.formatter??(l=>fe(l.value)),valueParser:e.valueParser??(l=>be(l.newValue,t))}),cell:se},{id:"checkbox",label:"Checkbox",description:"Done or not done: one click to toggle.",icon:a.checkbox,group:"basic",width:90,defaults:{icon:"check",color:"#20c933"},properties:[{key:"icon",label:"Icon",kind:"icon",icons:we},{key:"color",label:"Color",kind:"color",palette:N},y],fill:e=>({...e,editorType:e.editorType??"checkbox",align:e.align??"center"}),cell:ce},{id:"singleSelect",label:"Single select",description:"One choice from a list of colored options.",icon:a.singleSelect,group:"basic",width:140,defaults:{options:[]},properties:[{key:"options",label:"Options",kind:"options"},y],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",editorOptions:e.editorOptions??g(t),formatter:e.formatter??Z(t),valueParser:e.valueParser??Q(t,!1),sortValue:e.sortValue??ze(t)}),cell:z},{id:"multiSelect",label:"Multiple select",description:"Any number of choices from a list of colored options.",icon:a.multiSelect,group:"basic",width:200,defaults:{options:[]},properties:[{key:"options",label:"Options",kind:"options"},y],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",editorMultiple:e.editorMultiple??!0,editorOptions:e.editorOptions??g(t),formatter:e.formatter??Z(t),valueParser:e.valueParser??Q(t,!0)}),cell:z},{id:"user",label:"User",description:"A person (or several) from the people the app lists.",icon:a.user,group:"basic",width:170,properties:[{key:"multiple",label:"Allow adding multiple users",kind:"checkbox"},y],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",valueParser:e.valueParser??_e(!!t.multiple),editorMultiple:e.editorMultiple??!!t.multiple,editorOptions:e.editorOptions??K().map(l=>({value:l.id,label:l.name})),formatter:e.formatter??(l=>R(l.value))}),cell:A},{id:"date",label:"Date",description:"A calendar date, with or without the time.",icon:a.date,group:"basic",width:150,defaults:{dateFormat:"local",timeFormat:"12hour"},properties:[v,...I,{key:"defaultToday",label:"Default to today",kind:"checkbox"}],fill:(e,t)=>({...e,cellDataType:e.cellDataType??(t.time?"date":"dateString"),editorType:e.editorType??(t.time?"datetime":"date"),editorFormatString:e.editorFormatString??he(t),formatter:e.formatter??D(t)}),newRowValue:({props:e})=>e.defaultToday?e.time?M():new Date().toISOString().slice(0,10):void 0},{id:"phone",label:"Phone number",description:"A phone number, shown as a tel link.",icon:a.phone,group:"basic",fill:e=>({...e,editorType:e.editorType??"text"}),cell:T},{id:"email",label:"Email",description:"An email address, shown as a mailto link.",icon:a.email,group:"basic",width:200,fill:e=>({...e,editorType:e.editorType??"text"}),cell:T},{id:"url",label:"URL",description:"A web address, shown as a link.",icon:a.url,group:"basic",width:200,fill:e=>({...e,editorType:e.editorType??"text"}),cell:T},{id:"barcode",label:"Barcode",description:"A barcode's text, from a scanner or typed.",icon:a.barcode,group:"basic",width:160,fill:e=>({...e,editorType:e.editorType??"text",formatter:e.formatter??(t=>t.value&&typeof t.value=="object"?String(t.value.text??""):String(t.value??""))}),cell:de},{id:"button",label:"Button",description:"A button in every row that opens a link made from the row.",icon:a.button,group:"basic",width:120,defaults:{label:"Open",color:"#2d7ff9"},properties:[{key:"label",label:"Label",kind:"text",placeholder:"Open"},{key:"color",label:"Style",kind:"color",palette:N},{key:"url",label:"URL",kind:"text",placeholder:"https://example.com/orders/{Order id}",hint:"Use {Field name} for that field's value in the row. An app can set fieldProps.onClick instead."}],fill:(e,t,l)=>({...e,...d(e),sortable:e.sortable??!1,__fieldNames:ee(l.columns)}),cell:ue},{id:"number",label:"Number",description:"A number: whole, decimal, an amount of money or a percentage.",icon:a.number,group:"number",width:120,defaults:{format:"decimal",precision:1,separators:"local",showThousands:!0,abbreviation:"none",allowNegative:!0,symbol:"$",symbolPosition:"before",showBar:!1,points:!1,step:1},properties:[{key:"format",label:"Format",kind:"segmented",choices:[{value:"integer",label:"Integer"},{value:"decimal",label:"Decimal"},{value:"currency",label:"Currency"},{value:"percent",label:"Percent"}],alsoSets:e=>({precision:e==="decimal"?1:e==="currency"?2:0})},{key:"symbol",label:"Currency symbol",kind:"text",placeholder:"$, €, £, ¥, CHF, kr",visible:e=>e.format==="currency"},{key:"symbolPosition",label:"Symbol position",kind:"segmented",visible:e=>e.format==="currency",choices:[{value:"before",label:"Before ($1.00)"},{value:"after",label:"After (1.00 kr)"}]},{key:"precision",label:"Precision",kind:"choice",choices:L(0,8),visible:e=>e.format!=="integer"},{key:"step",label:"Spinner step",kind:"number",min:0,hint:"What the editor's arrows and Up / Down add or take away; Shift for ten times as much."},Ie,Pe,{...Oe,visible:e=>e.format!=="percent"},De,{key:"showBar",label:"Show as a progress bar",kind:"checkbox",visible:e=>e.format==="percent"},{key:"points",label:"Values are 0 to 100 (not 0 to 1)",kind:"checkbox",visible:e=>e.format==="percent"},y],fill:(e,t)=>O(e,t,ke("number",t)),cell:V,hasCell:e=>e.format==="percent"&&!!e.showBar},{id:"currency",label:"Currency",description:"An amount, with a currency symbol.",icon:a.currency,group:"number",width:120,defaults:{symbol:"$",symbolPosition:"before",precision:2,separators:"local",showThousands:!0,abbreviation:"none",allowNegative:!0},editAs:{type:"number",props:{format:"currency"}},fill:(e,t)=>O(e,t,"currency")},{id:"percent",label:"Percent",description:"A share, shown with a percent sign.",icon:a.percent,group:"number",width:110,defaults:{precision:0,separators:"local",showThousands:!0,allowNegative:!0,points:!1},editAs:{type:"number",props:{format:"percent"}},fill:(e,t)=>O(e,t,"percent"),cell:V,hasCell:e=>!!e.showBar},{id:"duration",label:"Duration",description:"A length of time, typed as 1:30 or 1h 30m.",icon:a.duration,group:"number",width:110,defaults:{durationFormat:"h:mm"},properties:[{key:"durationFormat",label:"Duration format",kind:"choice",choices:[{value:"h:mm",label:"h:mm"},{value:"h:mm:ss",label:"h:mm:ss"},{value:"h:mm:ss.S",label:"h:mm:ss.S"},{value:"h:mm:ss.SS",label:"h:mm:ss.SS"},{value:"h:mm:ss.SSS",label:"h:mm:ss.SSS"}]}],fill:(e,t)=>({...e,cellDataType:e.cellDataType??"number",editorType:e.editorType??"fieldNumber",formatter:e.formatter??(l=>{const r=b(l.value);return r==null?"":ye(r,t.durationFormat)}),valueParser:e.valueParser??(l=>typeof l.rawInput=="string"?l.rawInput.trim()?G(l.rawInput)??l.oldValue:null:typeof l.newValue=="number"?l.newValue:G(l.newValue))})},{id:"rating",label:"Rating",description:"One to ten stars, hearts, thumbs, flags or dots.",icon:a.rating,group:"number",width:130,defaults:{max:5,icon:"star",color:"#fcb400"},properties:[{key:"icon",label:"Icon",kind:"icon",icons:ve},{key:"color",label:"Color",kind:"color",palette:N},{key:"max",label:"Maximum",kind:"choice",choices:Array.from({length:10},(e,t)=>({value:String(t+1),label:String(t+1)}))}],fill:e=>({...e,cellDataType:e.cellDataType??"number",align:e.align??"left",editorType:e.editorType??"fieldRating"}),cell:ne},{id:"formula",label:"Formula",description:"A value computed from the row's other fields.",icon:a.formula,group:"computed",width:160,defaults:{formula:"",result:"auto"},properties:[{key:"formula",label:"Formula",kind:"formula"},{key:"result",label:"Format the result as",kind:"choice",choices:[{value:"auto",label:"As computed"},{value:"number",label:"Number"},{value:"currency",label:"Currency"},{value:"percent",label:"Percent"},{value:"date",label:"Date"}]},{key:"precision",label:"Precision",kind:"choice",choices:L(0,8),visible:e=>["number","currency","percent"].includes(e.result)},{key:"symbol",label:"Currency symbol",kind:"text",placeholder:"$",visible:e=>e.result==="currency"},{...v,visible:e=>e.result==="date"}],fill:(e,t,l)=>{const r=ee(l.columns),i=String(t.formula??""),o=String(e.field??e.id),n=new Set([o.toLowerCase(),typeof e.header=="string"?e.header.trim().toLowerCase():""].filter(Boolean)),m=s=>{const p=s.trim().toLowerCase(),f=r[p]??null;if(f===o||f==null&&n.has(p))throw Te(s);return f};let c=null;try{c=i.trim()?Me(i,m).fn:()=>null}catch{c=null}let u=null;const oe=()=>{if(u)return u;u=new Map;for(const s of l.columns){if(!Le.has(String(s.fieldType))||String(s.field??s.id)===o)continue;const p=B(s,l.columns);typeof p.fieldFn=="function"&&u.set(String(s.field??s.id),p.fieldFn)}return u},ae=s=>{const p=oe();return!p.size||!s?s:new Proxy(s,{get:(f,S)=>{const x=typeof S=="string"?p.get(S):void 0;if(!x||h>3)return f[S];h+=1;try{return x(f)}finally{h-=1}}})};return{...e,...d(e),fieldFn:s=>c?c(ae(s)):"#ERROR",align:e.align??(["number","currency","percent"].includes(t.result)?"right":void 0),formatter:e.formatter??(s=>te(s.value,t))}}},{id:"createdTime",label:"Created time",description:"When the row was added. Set automatically.",icon:a.createdTime,group:"computed",width:170,defaults:{dateFormat:"local",time:!0,timeFormat:"12hour"},properties:[v,...I],fill:(e,t)=>({...e,...d(e),formatter:e.formatter??D(t)}),newRowValue:()=>M(),onCreate:({rows:e})=>e.map(()=>M())},{id:"lastModifiedTime",label:"Last modified time",description:"When the row last changed. Set automatically.",icon:a.modifiedTime,group:"computed",width:170,defaults:{dateFormat:"local",time:!0,timeFormat:"12hour",watch:"all"},properties:[...ie,v,...I],fill:(e,t)=>({...e,...d(e),formatter:e.formatter??D(t)}),newRowValue:()=>M()},{id:"createdBy",label:"Created by",description:"Who added the row. Set automatically.",icon:a.createdBy,group:"computed",width:160,fill:e=>({...e,...d(e),formatter:e.formatter??(t=>R(t.value))}),newRowValue:()=>W()?.id??null,cell:A},{id:"lastModifiedBy",label:"Last modified by",description:"Who last changed the row. Set automatically.",icon:a.modifiedBy,group:"computed",width:160,defaults:{watch:"all"},properties:ie,fill:e=>({...e,...d(e),formatter:e.formatter??(t=>R(t.value))}),newRowValue:()=>W()?.id??null,cell:A},{id:"autoNumber",label:"Autonumber",description:"A number every row gets, counting up. Set automatically.",icon:a.autoNumber,group:"computed",width:100,fill:e=>({...e,...d(e),cellDataType:e.cellDataType??"number"}),newRowValue:({rows:e,field:t})=>e.reduce((l,r)=>Math.max(l,Number(r?.[t])||0),0)+1,onCreate:({rows:e})=>e.map((t,l)=>l+1)},{id:"link",label:"Link to records",description:"Rows of another table this row points at.",icon:a.link,group:"relation",width:200,defaults:{multiple:!0},properties:[{key:"table",label:"Table",kind:"choice",choices:()=>Ce().map(e=>({value:e.id,label:e.name})),hint:"The table gets a field that links back to this one."},{key:"multiple",label:"Allow linking to multiple records",kind:"checkbox"}],fill:(e,t)=>({...e,editorType:e.editorType??"fieldLink",formatter:e.formatter??(l=>{const r=k(t.table);return w(r,l.value).map(i=>String(i[r.primaryField]??"")).join(", ")}),valueParser:e.valueParser??He(t)}),cell:me},{id:"lookup",label:"Lookup",description:"A field of the linked rows, shown here.",icon:a.lookup,group:"relation",width:180,properties:[P,q],fill:(e,t,l)=>{const r=U(t,l),i=o=>{const n=re(r,t.field);return String(n?n({value:o})??"":o)};return{...e,...d(e),fieldFn:o=>{if(!r)return[];const n=Y(r.table,String(t.field));return w(r.table,o?.[r.key]).map(n)},formatter:e.formatter??(o=>Array.isArray(o.value)?o.value.filter(n=>n!=null&&n!=="").map(i).join(", "):o.value==null?"":i(o.value))}}},{id:"rollup",label:"Rollup",description:"A summary of a field over the linked rows (a sum, a count, a list).",icon:a.rollup,group:"relation",width:140,defaults:{aggregation:"SUM"},properties:[P,q,{key:"aggregation",label:"Aggregation",kind:"choice",choices:Object.keys(E).map(e=>({value:e,label:e}))},{key:"precision",label:"Precision",kind:"choice",choices:L(0,8),visible:e=>["SUM","AVERAGE","MIN","MAX"].includes(e.aggregation)}],fill:(e,t,l)=>{const r=U(t,l),i=E[String(t.aggregation)]??E.SUM,o=["SUM","AVERAGE","MIN","MAX","COUNT","COUNTA","COUNTALL"].includes(String(t.aggregation)),n=["SUM","AVERAGE","MIN","MAX"].includes(String(t.aggregation))&&t.precision==null,m=c=>{const u=n?re(r,t.field):void 0;return u?String(u({value:c})??""):F(c,{precision:J(t,0)})};return{...e,...d(e),...o?{cellDataType:e.cellDataType??"number"}:{},align:e.align??(o?"right":void 0),fieldFn:c=>{if(!r)return null;const u=Y(r.table,String(t.field));return i(w(r.table,c?.[r.key]).map(u))},formatter:e.formatter??(c=>typeof c.value=="number"?m(c.value):String(c.value??""))}}},{id:"count",label:"Count",description:"How many rows a link field points at.",icon:a.count,group:"relation",width:90,properties:[P],fill:(e,t,l)=>{const r=U(t,l);return{...e,...d(e),cellDataType:e.cellDataType??"number",fieldFn:i=>r?w(r.table,i?.[r.key]).length:0}}}];
1
+ import{fillFieldColumn as x}from"./registry.svelte.js";import ce from"./RatingCell.svelte";import T from"./LinkCell.svelte";import de from"./AttachmentCell.svelte";import me from"./CheckboxCell.svelte";import z from"./PercentCell.svelte";import A from"./UserCell.svelte";import fe from"./ButtonCell.svelte";import pe from"./BarcodeCell.svelte";import he from"./LinkedRecordsCell.svelte";import be from"./RichTextCell.svelte";import _ from"./SelectCell.svelte";import ye from"./ChecklistCell.svelte";import ge from"./ColorCell.svelte";import{attachmentsText as ke,parseAttachments as we}from"./attachments.js";import{dateEditTokens as ve,formatCurrency as H,formatDate as C,formatDuration as Me,formatNumber as F,formatPercent as j,numberFieldShape as G,numberFromText as Se,numberKind as Te,parseDuration as W,toNumber as b}from"./format.js";import{BRIGHT as P,CHECKBOX_ICONS as Ae,RATING_ICONS as Ce}from"./palette.js";import{compileFormula as Fe,isoDate as Pe,selfReferenceError as Ie}from"./formula.js";import{findFieldUser as Le,getCurrentUser as K,getFieldUsers as $,getLinkedTable as k,linkedRows as w,listLinkedTables as Oe,resolveLinkIds as Ne}from"./sources.svelte.js";import{splitNames as X}from"./name-list.js";import{linkedFields as De}from"./linked-fields.js";import{AI_FIELD_TYPE as Ve}from"./ai-field.svelte.js";import{CHECKLIST_GROUPS as Y,checklistGroup as Re,checklistSortValue as Ee,checklistText as Ue,parseChecklist as Be,toChecklist as xe}from"./checklist.js";import{colorSortValue as ze,parseColor as I}from"./color-value.js";import{formatTimeOfDay as _e,parseTimeOfDay as q,timeSeconds as He}from"./time-of-day.js";const J=new WeakMap;let y=0;const je=new Set(["formula","lookup","rollup","count"]);function Q(e,t){const l=i=>i?.[t];if(!e?.fields?.length)return l;let r=J.get(e.fields);if(r||J.set(e.fields,r=new Map),!r.has(t)){const i=De(e).find(n=>n.def.field===t);r.set(t,i?.def.fieldFn??null)}const o=r.get(t);return o?i=>{if(y>3)return l(i);y+=1;try{return o(i)}finally{y-=1}}:l}const a={text:"M4 6h16M4 12h10M4 18h7",longText:"M4 6h16M4 10h16M4 14h16M4 18h10",number:"M9 4 7 20M17 4l-2 16M4 9h16M3 15h16",currency:"M12 3v18M16 7.5C16 5.6 14.2 4.5 12 4.5S8 5.6 8 7.5s1.8 2.7 4 3.5 4 1.6 4 3.5-1.8 3-4 3-4-1.1-4-3",percent:"M19 5 5 19M7 7h.01M17 17h.01",date:"M4 6h16v14H4zM4 10h16M8 3v4M16 3v4",duration:"M12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16zM12 8v4l3 2",checkbox:"M4 4h16v16H4zM8 12l3 3 5-6",singleSelect:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM8 11l4 4 4-4",multiSelect:"M3 7h11M3 12h11M3 17h11M17 6l2 2 3-3M17 16l2 2 3-3",rating:"M12 3l2.8 5.7 6.2.9-4.5 4.4 1 6.2L12 17.3 6.5 20.2l1-6.2L3 9.6l6.2-.9z",url:"M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1",email:"M3 6h18v12H3zM3 7l9 6 9-6",phone:"M5 4h4l2 5-2.5 1.5a11 11 0 0 0 5 5L15 13l5 2v4a2 2 0 0 1-2 2A16 16 0 0 1 3 6a2 2 0 0 1 2-2",attachment:"M20 11.5 12.3 19a5 5 0 0 1-7.1-7.1l7.8-7.8a3.3 3.3 0 0 1 4.7 4.7L9.9 16.6a1.7 1.7 0 0 1-2.4-2.4l7.1-7",user:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0",createdTime:"M12 4a8 8 0 1 0 0 16 8 8 0 0 0 0-16zM12 8v4h4",modifiedTime:"M4 12a8 8 0 1 0 2.3-5.7M4 4v4h4M12 8v4l3 2",createdBy:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 11-7.5M19 15v6M16 18h6",modifiedBy:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 11-7.5M16 21l5-5-2-2-5 5v2z",autoNumber:"M5 7h3v10M11 9a2 2 0 1 1 4 0c0 2-4 3-4 6h4M18 7h2v10",barcode:"M4 5v14M7 5v14M10 5v14M13 5v14M15 5v14M18 5v14M20 5v14",button:"M4 7h16v10H4zM9 12h6",formula:"M7 20c2 0 2.5-2 3-5l2-10c.5-2 1.5-2 3-2M8 9h7",link:"M9 7H6a5 5 0 0 0 0 10h3M15 7h3a5 5 0 0 1 0 10h-3M8 12h8",lookup:"M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM20 20l-4-4M8 11h6",rollup:"M6 4h12L12 12l6 8H6",count:"M5 5h14v14H5zM9 9v6M12 9v6M15 9v6",checklist:"M3.5 6l1.5 1.5L7.5 5M3.5 12l1.5 1.5 2.5-2.5M3.5 18l1.5 1.5 2.5-2.5M11 6h9M11 12h9M11 18h9",color:"M12 3a9 9 0 1 0 0 18c1 0 1.6-.7 1.6-1.6 0-1-.8-1.4-.8-2.3 0-1 .8-1.7 1.8-1.7H17a4 4 0 0 0 4-4C21 6.6 17 3 12 3zM7.5 12h.01M9.5 7.5h.01M14.5 7.5h.01",timeOfDay:"M12 3a9 9 0 1 0 0 18 9 9 0 0 0 0-18zM12 7v5l-3 2M12 3v2M21 12h-2M12 21v-2M3 12h2"},Ge={key:"separators",label:"Separators",kind:"choice",choices:[{value:"local",label:"Local"},{value:"comma-period",label:"1,000,000.00"},{value:"period-comma",label:"1.000.000,00"},{value:"space-comma",label:"1 000 000,00"},{value:"space-period",label:"1 000 000.00"}]},We={key:"showThousands",label:"Show thousands separator",kind:"checkbox"},Ke={key:"abbreviation",label:"Large number abbreviation",kind:"choice",choices:[{value:"none",label:"None"},{value:"thousand",label:"Thousand (K)"},{value:"million",label:"Million (M)"},{value:"billion",label:"Billion (B)"}]},$e={key:"allowNegative",label:"Allow negative numbers",kind:"checkbox"},p={key:"default",label:"Default value",kind:"default",hint:"New rows start with this value."},L=(e,t)=>Array.from({length:t-e+1},(l,r)=>{const o=e+r;return{value:String(o),label:o===0?"1":`1.${"0".repeat(o)}`}}),v={key:"dateFormat",label:"Date format",kind:"choice",choices:[{value:"local",label:"Local"},{value:"friendly",label:"Friendly (October 14, 2026)"},{value:"us",label:"US (10/14/2026)"},{value:"european",label:"European (14/10/2026)"},{value:"iso",label:"ISO (2026-10-14)"}]},O=[{key:"time",label:"Include time",kind:"checkbox"},{key:"timeFormat",label:"Time format",kind:"segmented",choices:[{value:"12hour",label:"12 hour"},{value:"24hour",label:"24 hour"}],visible:e=>!!e.time},{key:"gmt",label:"Use the same time zone (GMT) for everyone",kind:"checkbox",visible:e=>!!e.time},{key:"showTimeZone",label:"Display time zone",kind:"checkbox",visible:e=>!!e.time}],Xe=e=>e.columns.filter(t=>t.fieldType==="link").map(t=>({value:String(t.id??t.field),label:String(t.header??t.field)})),N={key:"linkField",label:"Link field",kind:"choice",choices:Xe,hint:"A link-to-records field of this table."},Ye=e=>{const t=e.columns.find(o=>String(o.id??o.field)===e.props.linkField),l=k(t?.fieldProps?.table);return l?(l.fields??[{field:l.primaryField,header:l.primaryField}]).map(o=>({value:o.field,label:o.header})):[]},Z={key:"field",label:"Field in the linked table",kind:"choice",choices:Ye,visible:e=>!!e.linkField},ee=(e,t=0)=>{const l=Number(e.precision);return Number.isInteger(l)&&l>=0&&l<=8?l:t},qe=e=>({precision:e.format==="integer"?0:ee(e,e.format==="decimal"?1:0),separators:e.separators,showThousands:e.showThousands!==!1,abbreviation:e.abbreviation}),Je=(e,t)=>l=>{const r=typeof l.rawInput=="string"?l.rawInput:l.newValue;if(typeof r=="number"||r==null)return r;if(String(r).trim()==="")return null;const o=Se(String(r),e,t);return o??l.oldValue},Qe=(e,t)=>t.allowNegative===!1&&!e.validate?{rejectInvalid:!0,validate:l=>Number(l.value)<0?"Negative numbers are not allowed":null}:{},Ze=(e,t)=>{const l={precision:G(e,t).places,separators:t.separators,showThousands:t.showThousands!==!1,abbreviation:e==="percent"?void 0:t.abbreviation};return r=>{const o=b(r.value);return o==null?"":e==="currency"?H(o,{...l,symbol:t.symbol,symbolPosition:t.symbolPosition}):e==="percent"?j(o,{...l,points:t.points}):F(o,l)}},D=(e,t,l)=>({...e,cellDataType:e.cellDataType??"number",editorType:e.editorType??"fieldNumber",align:e.align??(l==="percent"&&t.showBar?"left":"right"),...Qe(e,t),valueParser:e.valueParser??Je(l,t),formatter:e.formatter??Ze(l,t)}),g=e=>Array.isArray(e.options)?e.options.map(t=>({value:t.value,label:t.label??String(t.value),...t.color?{color:t.color}:{}})):[],te=(e,t)=>{const l=new Map;for(const o of g(e))l.set(String(o.value).toLowerCase(),o.value),l.set(String(o.label).toLowerCase(),o.value);const r=o=>l.get(o.toLowerCase())??o;return o=>{if(typeof o.rawInput!="string")return o.newValue;const i=o.rawInput.split(t?",":/\n/).map(n=>n.trim()).filter(Boolean);return t?[...new Set(i.map(r))]:i.length?r(i[0]):null}},le=e=>{const t=new Map(g(e).map(l=>[String(l.value),l.label]));return l=>(Array.isArray(l.value)?l.value:l.value==null||l.value===""?[]:[l.value]).map(r=>t.get(String(r))??String(r)).join(", ")},et=e=>{const t=new Map(g(e).map((l,r)=>[String(l.value),r]));return l=>l==null||l===""?null:t.get(String(l))??t.size},re=e=>{const t={};for(const l of e){const r=String(l.field??l.id??"");r&&(t[r.toLowerCase()]=r,typeof l.header=="string"&&(t[l.header.trim().toLowerCase()]=r))}return t},d=e=>({editable:e.editable??!1}),V=e=>t=>C(t.value,e),R=e=>(Array.isArray(e)?e:e==null||e===""?[]:[e]).map(t=>Le(t)?.name??String(t)).join(", "),tt=e=>t=>{if(typeof t.rawInput!="string")return t.newValue;const l=$(),r=i=>{const n=i.toLowerCase();return l.find(m=>m.id.toLowerCase()===n||m.name.toLowerCase()===n||m.email?.toLowerCase()===n)?.id??i},o=e?X(t.rawInput):t.rawInput.split(/\n/).map(i=>i.trim()).filter(Boolean);return e?[...new Set(o.map(r))]:o.length?r(o[0]):null},lt=e=>t=>{if(typeof t.rawInput!="string")return t.newValue;const l=k(e.table);if(!l)return t.newValue;const r=Ne(l,X(t.rawInput));return e.multiple===!1?r.slice(0,1):r},rt=e=>typeof e.rawInput=="string"?e.rawInput.trim()?Be(e.rawInput):null:Array.isArray(e.newValue)?xe(e.newValue):e.newValue??null,ot=e=>{const t=typeof e.rawInput=="string"?e.rawInput:e.newValue;return t==null||String(t).trim()===""?null:I(t)??e.oldValue},it=e=>t=>{const l=typeof t.rawInput=="string"?t.rawInput:t.newValue;return l==null||typeof l=="string"&&l.trim()===""?null:q(l,{seconds:!!e.showSeconds})??t.oldValue};function oe(e,t){if(e==null)return"";if(Array.isArray(e))return e.map(l=>oe(l,t)).join(", ");if(e instanceof Date)return C(e,t);if(typeof e=="boolean")return e?"true":"false";if(typeof e=="number"){if(t.result==="currency"||t.result==="percent"||t.result==="number"){const l=t.result,r={...qe(t),precision:G(l,{precision:t.precision}).places};return l==="currency"?H(e,{...r,symbol:t.symbol}):l==="percent"?j(e,r):F(e,r)}return String(Math.round(e*1e10)/1e10)}if(t.result==="date"){const l=Pe(String(e));if(l)return C(l,t)}return String(e)}const E={SUM:e=>e.reduce((t,l)=>t+(b(l)??0),0),AVERAGE:e=>{const t=e.map(b).filter(l=>l!=null);return t.length?t.reduce((l,r)=>l+r,0)/t.length:null},MIN:e=>{const t=e.map(b).filter(l=>l!=null);return t.length?Math.min(...t):null},MAX:e=>{const t=e.map(b).filter(l=>l!=null);return t.length?Math.max(...t):null},COUNT:e=>e.filter(t=>typeof t=="number").length,COUNTA:e=>e.filter(t=>t!=null&&t!=="").length,COUNTALL:e=>e.length,ARRAYJOIN:e=>e.filter(t=>t!=null&&t!=="").map(String).join(", "),ARRAYUNIQUE:e=>[...new Set(e.filter(t=>t!=null&&t!=="").map(String))].join(", "),CONCATENATE:e=>e.map(t=>t==null?"":String(t)).join(""),AND:e=>e.every(Boolean),OR:e=>e.some(Boolean)},U=(e,t)=>{const l=t.columns.find(o=>String(o.id??o.field)===e.linkField);if(!l)return null;const r=l.fieldProps?.table;return{key:String(l.field??l.id),get table(){return k(r)}}},ie=new WeakMap;function ae(e,t){const l=e?.table?.fields;if(!l)return;let r=ie.get(l);r||ie.set(l,r=new Map);const o=String(t);if(r.has(o))return r.get(o);const i=l.find(m=>m.field===o),n=i?.fieldType?x({field:i.field,fieldType:i.fieldType,fieldProps:i.fieldProps}).formatter:void 0;return r.set(o,n),n}const M=()=>new Date().toISOString(),at=(e,t)=>{const l=r=>r?Y.indexOf(r):Y.length;return l(e)-l(t)},ne=[{key:"watch",label:"Changes to",kind:"segmented",choices:[{value:"all",label:"All fields"},{value:"specific",label:"Specific fields"}]},{key:"watchFields",label:"Fields",kind:"columns",visible:e=>e.watch==="specific"}];export const BUILTIN_FIELD_TYPES=[{id:"text",label:"Single line text",description:"A short line of text, like a name or a title.",icon:a.text,group:"basic",properties:[p],fill:e=>({...e,editorType:e.editorType??"text"})},{id:"longText",label:"Long text",description:"Several lines of text; Alt+Enter starts a new line.",icon:a.longText,group:"basic",width:260,properties:[{key:"richText",label:"Enable rich text formatting",kind:"checkbox",hint:"**bold**, *italic*, `code`, [links](https://...) and lists."}],fill:e=>({...e,editorType:e.editorType??"fieldLongText"}),cell:be,hasCell:e=>!!e.richText},{id:"attachment",label:"Attachment",description:"Images and files: thumbnails in the cell, a dialog to add more.",icon:a.attachment,group:"basic",width:180,defaults:{maxFiles:20},properties:[{key:"accept",label:"Accepted types",kind:"text",placeholder:"image/*,.pdf (any when empty)"},{key:"maxFiles",label:"Most files per cell",kind:"number",min:1,max:100}],fill:(e,t)=>({...e,editorType:e.editorType??"attachment",formatter:e.formatter??(l=>ke(l.value)),valueParser:e.valueParser??(l=>we(l.newValue,t))}),cell:de},{id:"checkbox",label:"Checkbox",description:"Done or not done: one click to toggle.",icon:a.checkbox,group:"basic",width:90,defaults:{icon:"check",color:"#20c933"},properties:[{key:"icon",label:"Icon",kind:"icon",icons:Ae},{key:"color",label:"Color",kind:"color",palette:P},p],fill:e=>({...e,editorType:e.editorType??"checkbox",align:e.align??"center"}),cell:me},{id:"singleSelect",label:"Single select",description:"One choice from a list of colored options.",icon:a.singleSelect,group:"basic",width:140,defaults:{options:[]},properties:[{key:"options",label:"Options",kind:"options"},p],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",editorOptions:e.editorOptions??g(t),formatter:e.formatter??le(t),valueParser:e.valueParser??te(t,!1),sortValue:e.sortValue??et(t)}),cell:_},{id:"multiSelect",label:"Multiple select",description:"Any number of choices from a list of colored options.",icon:a.multiSelect,group:"basic",width:200,defaults:{options:[]},properties:[{key:"options",label:"Options",kind:"options"},p],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",editorMultiple:e.editorMultiple??!0,editorOptions:e.editorOptions??g(t),formatter:e.formatter??le(t),valueParser:e.valueParser??te(t,!0)}),cell:_},{id:"user",label:"User",description:"A person (or several) from the people the app lists.",icon:a.user,group:"basic",width:170,properties:[{key:"multiple",label:"Allow adding multiple users",kind:"checkbox"},p],fill:(e,t)=>({...e,editorType:e.editorType??"fieldSelect",valueParser:e.valueParser??tt(!!t.multiple),editorMultiple:e.editorMultiple??!!t.multiple,editorOptions:e.editorOptions??$().map(l=>({value:l.id,label:l.name})),formatter:e.formatter??(l=>R(l.value))}),cell:A},{id:"date",label:"Date",description:"A calendar date, with or without the time.",icon:a.date,group:"basic",width:150,defaults:{dateFormat:"local",timeFormat:"12hour"},properties:[v,...O,{key:"defaultToday",label:"Default to today",kind:"checkbox"}],fill:(e,t)=>({...e,cellDataType:e.cellDataType??(t.time?"date":"dateString"),editorType:e.editorType??(t.time?"datetime":"date"),editorFormatString:e.editorFormatString??ve(t),formatter:e.formatter??V(t)}),newRowValue:({props:e})=>e.defaultToday?e.time?M():new Date().toISOString().slice(0,10):void 0},{id:"phone",label:"Phone number",description:"A phone number, shown as a tel link.",icon:a.phone,group:"basic",fill:e=>({...e,editorType:e.editorType??"text"}),cell:T},{id:"email",label:"Email",description:"An email address, shown as a mailto link.",icon:a.email,group:"basic",width:200,fill:e=>({...e,editorType:e.editorType??"text"}),cell:T},{id:"url",label:"URL",description:"A web address, shown as a link.",icon:a.url,group:"basic",width:200,fill:e=>({...e,editorType:e.editorType??"text"}),cell:T},{id:"barcode",label:"Barcode",description:"A barcode's text, from a scanner or typed.",icon:a.barcode,group:"basic",width:160,fill:e=>({...e,editorType:e.editorType??"text",formatter:e.formatter??(t=>t.value&&typeof t.value=="object"?String(t.value.text??""):String(t.value??""))}),cell:pe},{id:"button",label:"Button",description:"A button in every row that opens a link made from the row.",icon:a.button,group:"basic",width:120,defaults:{label:"Open",color:"#2d7ff9"},properties:[{key:"label",label:"Label",kind:"text",placeholder:"Open"},{key:"color",label:"Style",kind:"color",palette:P},{key:"url",label:"URL",kind:"text",placeholder:"https://example.com/orders/{Order id}",hint:"Use {Field name} for that field's value in the row. An app can set fieldProps.onClick instead."}],fill:(e,t,l)=>({...e,...d(e),sortable:e.sortable??!1,__fieldNames:re(l.columns)}),cell:fe},{id:"checklist",label:"Checklist",description:"A list of to-dos; the cell shows how many are done.",icon:a.checklist,group:"basic",width:150,fill:e=>({...e,editorType:e.editorType??"fieldChecklist",formatter:e.formatter??(t=>Ue(t.value)),valueParser:e.valueParser??rt,sortValue:e.sortValue??Ee,groupValue:e.groupValue??Re,groupOrder:e.groupOrder??at}),cell:ye},{id:"color",label:"Color",description:"A color from the palette, or any hex code.",icon:a.color,group:"basic",width:130,properties:[p],fill:e=>({...e,editorType:e.editorType??"fieldColor",formatter:e.formatter??(t=>I(t.value)??String(t.value??"")),valueParser:e.valueParser??ot,sortValue:e.sortValue??ze}),newRowValue:({props:e})=>e.default==null||e.default===""?void 0:I(e.default),cell:ge},{id:"number",label:"Number",description:"A number: whole, decimal, an amount of money or a percentage.",icon:a.number,group:"number",width:120,defaults:{format:"decimal",precision:1,separators:"local",showThousands:!0,abbreviation:"none",allowNegative:!0,symbol:"$",symbolPosition:"before",showBar:!1,points:!1,step:1},properties:[{key:"format",label:"Format",kind:"segmented",choices:[{value:"integer",label:"Integer"},{value:"decimal",label:"Decimal"},{value:"currency",label:"Currency"},{value:"percent",label:"Percent"}],alsoSets:e=>({precision:e==="decimal"?1:e==="currency"?2:0})},{key:"symbol",label:"Currency symbol",kind:"text",placeholder:"$, €, £, ¥, CHF, kr",visible:e=>e.format==="currency"},{key:"symbolPosition",label:"Symbol position",kind:"segmented",visible:e=>e.format==="currency",choices:[{value:"before",label:"Before ($1.00)"},{value:"after",label:"After (1.00 kr)"}]},{key:"precision",label:"Precision",kind:"choice",choices:L(0,8),visible:e=>e.format!=="integer"},{key:"step",label:"Spinner step",kind:"number",min:0,hint:"What the editor's arrows and Up / Down add or take away; Shift for ten times as much."},Ge,We,{...Ke,visible:e=>e.format!=="percent"},$e,{key:"showBar",label:"Show as a progress bar",kind:"checkbox",visible:e=>e.format==="percent"},{key:"points",label:"Values are 0 to 100 (not 0 to 1)",kind:"checkbox",visible:e=>e.format==="percent"},p],fill:(e,t)=>D(e,t,Te("number",t)),cell:z,hasCell:e=>e.format==="percent"&&!!e.showBar},{id:"currency",label:"Currency",description:"An amount, with a currency symbol.",icon:a.currency,group:"number",width:120,defaults:{symbol:"$",symbolPosition:"before",precision:2,separators:"local",showThousands:!0,abbreviation:"none",allowNegative:!0},editAs:{type:"number",props:{format:"currency"}},fill:(e,t)=>D(e,t,"currency")},{id:"percent",label:"Percent",description:"A share, shown with a percent sign.",icon:a.percent,group:"number",width:110,defaults:{precision:0,separators:"local",showThousands:!0,allowNegative:!0,points:!1},editAs:{type:"number",props:{format:"percent"}},fill:(e,t)=>D(e,t,"percent"),cell:z,hasCell:e=>!!e.showBar},{id:"duration",label:"Duration",description:"A length of time, typed as 1:30 or 1h 30m.",icon:a.duration,group:"number",width:110,defaults:{durationFormat:"h:mm"},properties:[{key:"durationFormat",label:"Duration format",kind:"choice",choices:[{value:"h:mm",label:"h:mm"},{value:"h:mm:ss",label:"h:mm:ss"},{value:"h:mm:ss.S",label:"h:mm:ss.S"},{value:"h:mm:ss.SS",label:"h:mm:ss.SS"},{value:"h:mm:ss.SSS",label:"h:mm:ss.SSS"}]}],fill:(e,t)=>({...e,cellDataType:e.cellDataType??"number",editorType:e.editorType??"fieldNumber",formatter:e.formatter??(l=>{const r=b(l.value);return r==null?"":Me(r,t.durationFormat)}),valueParser:e.valueParser??(l=>typeof l.rawInput=="string"?l.rawInput.trim()?W(l.rawInput)??l.oldValue:null:typeof l.newValue=="number"?l.newValue:W(l.newValue))})},{id:"timeOfDay",label:"Time of day",description:"A time on the clock with no date, typed as 9:30 am, 14:05 or 2pm.",icon:a.timeOfDay,group:"number",width:120,defaults:{timeFormat:"12hour",showSeconds:!1},properties:[{key:"timeFormat",label:"Time format",kind:"segmented",choices:[{value:"12hour",label:"12 hour"},{value:"24hour",label:"24 hour"}]},{key:"showSeconds",label:"Show seconds",kind:"checkbox"},p],fill:(e,t)=>({...e,editorType:e.editorType??"fieldTime",formatter:e.formatter??(l=>_e(l.value,t)),valueParser:e.valueParser??it(t),sortValue:e.sortValue??He}),newRowValue:({props:e})=>e.default==null||e.default===""?void 0:q(e.default,{seconds:!!e.showSeconds})},{id:"rating",label:"Rating",description:"One to ten stars, hearts, thumbs, flags or dots.",icon:a.rating,group:"number",width:130,defaults:{max:5,icon:"star",color:"#fcb400"},properties:[{key:"icon",label:"Icon",kind:"icon",icons:Ce},{key:"color",label:"Color",kind:"color",palette:P},{key:"max",label:"Maximum",kind:"choice",choices:Array.from({length:10},(e,t)=>({value:String(t+1),label:String(t+1)}))}],fill:e=>({...e,cellDataType:e.cellDataType??"number",align:e.align??"left",editorType:e.editorType??"fieldRating"}),cell:ce},{id:"formula",label:"Formula",description:"A value computed from the row's other fields.",icon:a.formula,group:"computed",width:160,defaults:{formula:"",result:"auto"},properties:[{key:"formula",label:"Formula",kind:"formula"},{key:"result",label:"Format the result as",kind:"choice",choices:[{value:"auto",label:"As computed"},{value:"number",label:"Number"},{value:"currency",label:"Currency"},{value:"percent",label:"Percent"},{value:"date",label:"Date"}]},{key:"precision",label:"Precision",kind:"choice",choices:L(0,8),visible:e=>["number","currency","percent"].includes(e.result)},{key:"symbol",label:"Currency symbol",kind:"text",placeholder:"$",visible:e=>e.result==="currency"},{...v,visible:e=>e.result==="date"}],fill:(e,t,l)=>{const r=re(l.columns),o=String(t.formula??""),i=String(e.field??e.id),n=new Set([i.toLowerCase(),typeof e.header=="string"?e.header.trim().toLowerCase():""].filter(Boolean)),m=s=>{const f=s.trim().toLowerCase(),h=r[f]??null;if(h===i||h==null&&n.has(f))throw Ie(s);return h};let u=null;try{u=o.trim()?Fe(o,m).fn:()=>null}catch{u=null}let c=null;const se=()=>{if(c)return c;c=new Map;for(const s of l.columns){if(!je.has(String(s.fieldType))||String(s.field??s.id)===i)continue;const f=x(s,l.columns);typeof f.fieldFn=="function"&&c.set(String(s.field??s.id),f.fieldFn)}return c},ue=s=>{const f=se();return!f.size||!s?s:new Proxy(s,{get:(h,S)=>{const B=typeof S=="string"?f.get(S):void 0;if(!B||y>3)return h[S];y+=1;try{return B(h)}finally{y-=1}}})};return{...e,...d(e),fieldFn:s=>u?u(ue(s)):"#ERROR",align:e.align??(["number","currency","percent"].includes(t.result)?"right":void 0),formatter:e.formatter??(s=>oe(s.value,t))}}},{id:"createdTime",label:"Created time",description:"When the row was added. Set automatically.",icon:a.createdTime,group:"computed",width:170,defaults:{dateFormat:"local",time:!0,timeFormat:"12hour"},properties:[v,...O],fill:(e,t)=>({...e,...d(e),formatter:e.formatter??V(t)}),newRowValue:()=>M(),onCreate:({rows:e})=>e.map(()=>M())},{id:"lastModifiedTime",label:"Last modified time",description:"When the row last changed. Set automatically.",icon:a.modifiedTime,group:"computed",width:170,defaults:{dateFormat:"local",time:!0,timeFormat:"12hour",watch:"all"},properties:[...ne,v,...O],fill:(e,t)=>({...e,...d(e),formatter:e.formatter??V(t)}),newRowValue:()=>M()},{id:"createdBy",label:"Created by",description:"Who added the row. Set automatically.",icon:a.createdBy,group:"computed",width:160,fill:e=>({...e,...d(e),formatter:e.formatter??(t=>R(t.value))}),newRowValue:()=>K()?.id??null,cell:A},{id:"lastModifiedBy",label:"Last modified by",description:"Who last changed the row. Set automatically.",icon:a.modifiedBy,group:"computed",width:160,defaults:{watch:"all"},properties:ne,fill:e=>({...e,...d(e),formatter:e.formatter??(t=>R(t.value))}),newRowValue:()=>K()?.id??null,cell:A},{id:"autoNumber",label:"Autonumber",description:"A number every row gets, counting up. Set automatically.",icon:a.autoNumber,group:"computed",width:100,fill:e=>({...e,...d(e),cellDataType:e.cellDataType??"number"}),newRowValue:({rows:e,field:t})=>e.reduce((l,r)=>Math.max(l,Number(r?.[t])||0),0)+1,onCreate:({rows:e})=>e.map((t,l)=>l+1)},{id:"link",label:"Link to records",description:"Rows of another table this row points at.",icon:a.link,group:"relation",width:200,defaults:{multiple:!0},properties:[{key:"table",label:"Table",kind:"choice",choices:()=>Oe().map(e=>({value:e.id,label:e.name})),hint:"The table gets a field that links back to this one."},{key:"multiple",label:"Allow linking to multiple records",kind:"checkbox"}],fill:(e,t)=>({...e,editorType:e.editorType??"fieldLink",formatter:e.formatter??(l=>{const r=k(t.table);return w(r,l.value).map(o=>String(o[r.primaryField]??"")).join(", ")}),valueParser:e.valueParser??lt(t)}),cell:he},{id:"lookup",label:"Lookup",description:"A field of the linked rows, shown here.",icon:a.lookup,group:"relation",width:180,properties:[N,Z],fill:(e,t,l)=>{const r=U(t,l),o=i=>{const n=ae(r,t.field);return String(n?n({value:i})??"":i)};return{...e,...d(e),fieldFn:i=>{if(!r)return[];const n=Q(r.table,String(t.field));return w(r.table,i?.[r.key]).map(n)},formatter:e.formatter??(i=>Array.isArray(i.value)?i.value.filter(n=>n!=null&&n!=="").map(o).join(", "):i.value==null?"":o(i.value))}}},{id:"rollup",label:"Rollup",description:"A summary of a field over the linked rows (a sum, a count, a list).",icon:a.rollup,group:"relation",width:140,defaults:{aggregation:"SUM"},properties:[N,Z,{key:"aggregation",label:"Aggregation",kind:"choice",choices:Object.keys(E).map(e=>({value:e,label:e}))},{key:"precision",label:"Precision",kind:"choice",choices:L(0,8),visible:e=>["SUM","AVERAGE","MIN","MAX"].includes(e.aggregation)}],fill:(e,t,l)=>{const r=U(t,l),o=E[String(t.aggregation)]??E.SUM,i=["SUM","AVERAGE","MIN","MAX","COUNT","COUNTA","COUNTALL"].includes(String(t.aggregation)),n=["SUM","AVERAGE","MIN","MAX"].includes(String(t.aggregation))&&t.precision==null,m=u=>{const c=n?ae(r,t.field):void 0;return c?String(c({value:u})??""):F(u,{precision:ee(t,0)})};return{...e,...d(e),...i?{cellDataType:e.cellDataType??"number"}:{},align:e.align??(i?"right":void 0),fieldFn:u=>{if(!r)return null;const c=Q(r.table,String(t.field));return o(w(r.table,u?.[r.key]).map(c))},formatter:e.formatter??(u=>typeof u.value=="number"?m(u.value):String(u.value??""))}}},{id:"count",label:"Count",description:"How many rows a link field points at.",icon:a.count,group:"relation",width:90,properties:[N],fill:(e,t,l)=>{const r=U(t,l);return{...e,...d(e),cellDataType:e.cellDataType??"number",fieldFn:o=>r?w(r.table,o?.[r.key]).length:0}}},Ve];
@@ -30,6 +30,18 @@ export declare const chartYColumns: (ctrl: any) => FieldColumn[];
30
30
  export declare function defaultChart(ctrl: any): ChartSetting | null;
31
31
  /** The chart for `rows` (the records the view shows), or null when its fields are gone. */
32
32
  export declare function chartSpec(ctrl: any, setting: ChartSetting, rows: ReadonlyArray<Row>): ChartSpec | null;
33
+ /**
34
+ * The value axis gutter fits the widest tick as the field writes it
35
+ * ("$1,000,000"); the chart's own default fits its short "1M" style. A pie
36
+ * and a horizontal bar have no such axis.
37
+ */
38
+ export declare function withValueGutter(spec: ChartSpec, formatValue: ((value: number) => string) | undefined): ChartSpec;
33
39
  /** How a value shows on the axis and in tooltips: as the summed field shows it ($48,000), a count as a whole number. */
34
40
  export declare function chartFormatter(ctrl: any, setting: ChartSetting): ((value: number) => string) | undefined;
41
+ /**
42
+ * The rows in one of the chart's buckets: the ones grouped under `category`,
43
+ * the label the chart shows ("Won", "Nov 2026", "Empty"). A row in several
44
+ * buckets (a multiple select, a link) is in each of them.
45
+ */
46
+ export declare function chartBucketRows<R extends Row>(ctrl: any, setting: ChartSetting, rows: ReadonlyArray<R>, category: string): R[];
35
47
  export {};
@@ -1 +1 @@
1
- import{fieldColumns as y}from"./grid-access.js";import{fieldPropsOf as g,originalColumn as b}from"./registry.svelte.js";import{findFieldUser as v,getLinkedTable as D,linkedRows as w}from"./sources.svelte.js";export const CHART_KINDS=[{kind:"bar",label:"Bar"},{kind:"barH",label:"Horizontal bar"},{kind:"line",label:"Line"},{kind:"pie",label:"Pie"},{kind:"donut",label:"Donut"}];const C=new Set(["singleSelect","multiSelect","user","date","checkbox","link","text","rating","createdTime","createdBy","formula","lookup"]),$=new Set(["number","currency","percent","rating","duration","count","rollup"]),E=new Set(["number","currency","percent"]);export const chartXColumns=n=>y(n).filter(r=>C.has(r.fieldType??"")||r.def.cellDataType==="date"||r.def.cellDataType==="dateString"),chartYColumns=n=>y(n).filter(r=>$.has(r.fieldType??"")||r.fieldType==="formula"&&E.has(String(g(b(r.def)).result))||!r.fieldType&&r.def.cellDataType==="number");export function defaultChart(n){const r=chartXColumns(n),o=r.find(l=>l.fieldType==="singleSelect")??r[0];return o?{kind:"bar",x:o.id}:null}const u="Empty",F=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function N(n,r){const o=n.def.fieldFn;return o?o(r):r?.[n.field]}function O(n,r){const o=N(n,r),l=Array.isArray(o)?o:o==null||o===""?[]:[o];if(n.fieldType==="checkbox")return[o===!0?"Checked":"Unchecked"];if(!l.length)return[u];if(n.fieldType==="user"||n.fieldType==="createdBy")return l.map(t=>v(t)?.name??String(t));if(n.fieldType==="link"){const t=D(g(b(n.def)).table),i=t?w(t,o).map(e=>String(e[t.primaryField]??"")):[];return i.length?i:[u]}if(n.fieldType==="lookup"){const t=n.def.formatter,i=l.map(e=>String(t?t({value:e})??"":e)).filter(e=>e!=="");return i.length?[...new Set(i)]:[u]}if(n.fieldType==="formula"){const t=g(b(n.def)).result==="date"||n.def.cellDataType==="date"||n.def.cellDataType==="dateString",i=l.map(e=>e instanceof Date?Number.isNaN(e.getTime())?u:`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}`:typeof e=="number"?String(Math.round(e*1e10)/1e10):t&&typeof e=="string"&&/^\d{4}-\d{2}-\d{2}/.test(e)?e.slice(0,7):String(e));return[...new Set(i)]}if(n.fieldType==="date"||n.fieldType==="createdTime"||n.def.cellDataType==="date"||n.def.cellDataType==="dateString"){const t=String(l[0]),i=/^(\d{4})-(\d{2})/.exec(t);return[i?`${i[1]}-${i[2]}`:t]}return l.map(t=>String(t))}function H(n,r){const o={},l=r.includes(u)?[u]:[],t=r.filter(e=>e!==u);if(n.fieldType==="singleSelect"||n.fieldType==="multiSelect"){const e=g(b(n.def)).options??[],d=new Map(e.map((s,c)=>[String(s.value),c]));for(const s of e)s.color&&(o[String(s.value)]=s.color);return t.sort((s,c)=>(d.get(s)??1e9)-(d.get(c)??1e9)),{keys:[...t,...l],label:s=>s,colors:o}}return t.length>0&&t.every(e=>/^\d{4}-\d{2}$/.test(e))?(t.sort(),{keys:[...t,...l],label:e=>e===u?e:`${F[Number(e.slice(5))-1]} ${e.slice(0,4)}`,colors:o}):(t.length&&t.every(e=>e!==""&&!Number.isNaN(Number(e)))&&t.sort((e,d)=>Number(e)-Number(d)),{keys:[...t,...l],label:e=>e,colors:o})}export function chartSpec(n,r,o){const l=y(n),t=l.find(a=>a.id===r.x);if(!t)return null;const i=r.y?l.find(a=>a.id===r.y):void 0,e=new Map;for(const a of o){if(a==null)continue;const f=i?Number(N(i,a)):1;for(const k of O(t,a)){const S=e.get(k)??{total:0,n:0};(!i||Number.isFinite(f))&&(S.total+=Number.isFinite(f)?f:0,S.n+=1),e.set(k,S)}}const{keys:d,label:s,colors:c}=H(t,[...e.keys()]),T=!!i&&r.aggregation==="avg",M=d.map(a=>{const f=e.get(a);return T?f.n?f.total/f.n:0:f.total}),h=d.map(s),m={};d.forEach((a,f)=>{c[a]&&(m[h[f]]=c[a])});const p=r.kind;return{type:p==="barH"?"bar":p==="donut"?"pie":p,categories:h,series:[{label:i?`${T?"Average":"Sum"} of ${i.header}`:"Records",values:M,...Object.keys(m).length&&(p==="bar"||p==="barH")?{colors:d.map(a=>c[a]??null)}:{}}],...Object.keys(m).length?{categoryColors:m}:{},...p==="barH"?{orientation:"horizontal"}:{},...p==="donut"?{innerRadius:.58}:{}}}export function chartFormatter(n,r){const o=r.y?y(n).find(t=>t.id===r.y):void 0;if(!o)return t=>String(Math.round(t));const l=o.def.formatter;return l?t=>String(l({value:t})??t):void 0}
1
+ import{fieldColumns as m}from"./grid-access.js";import{fieldPropsOf as g,originalColumn as b}from"./registry.svelte.js";import{findFieldUser as x,getLinkedTable as D,linkedRows as C}from"./sources.svelte.js";export const CHART_KINDS=[{kind:"bar",label:"Bar"},{kind:"barH",label:"Horizontal bar"},{kind:"line",label:"Line"},{kind:"pie",label:"Pie"},{kind:"donut",label:"Donut"}];const $=new Set(["singleSelect","multiSelect","user","date","checkbox","link","text","rating","createdTime","createdBy","formula","lookup"]),E=new Set(["number","currency","percent","rating","duration","count","rollup"]),F=new Set(["number","currency","percent"]);export const chartXColumns=n=>m(n).filter(r=>$.has(r.fieldType??"")||r.def.cellDataType==="date"||r.def.cellDataType==="dateString"),chartYColumns=n=>m(n).filter(r=>E.has(r.fieldType??"")||r.fieldType==="formula"&&F.has(String(g(b(r.def)).result))||!r.fieldType&&r.def.cellDataType==="number");export function defaultChart(n){const r=chartXColumns(n),o=r.find(l=>l.fieldType==="singleSelect")??r[0];return o?{kind:"bar",x:o.id}:null}const d="Empty",O=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function M(n,r){const o=n.def.fieldFn;return o?o(r):r?.[n.field]}function N(n,r){const o=M(n,r),l=Array.isArray(o)?o:o==null||o===""?[]:[o];if(n.fieldType==="checkbox")return[o===!0?"Checked":"Unchecked"];if(!l.length)return[d];if(n.fieldType==="user"||n.fieldType==="createdBy")return l.map(e=>x(e)?.name??String(e));if(n.fieldType==="link"){const e=D(g(b(n.def)).table),i=e?C(e,o).map(t=>String(t[e.primaryField]??"")):[];return i.length?i:[d]}if(n.fieldType==="lookup"){const e=n.def.formatter,i=l.map(t=>String(e?e({value:t})??"":t)).filter(t=>t!=="");return i.length?[...new Set(i)]:[d]}if(n.fieldType==="formula"){const e=g(b(n.def)).result==="date"||n.def.cellDataType==="date"||n.def.cellDataType==="dateString",i=l.map(t=>t instanceof Date?Number.isNaN(t.getTime())?d:`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}`:typeof t=="number"?String(Math.round(t*1e10)/1e10):e&&typeof t=="string"&&/^\d{4}-\d{2}-\d{2}/.test(t)?t.slice(0,7):String(t));return[...new Set(i)]}if(n.fieldType==="date"||n.fieldType==="createdTime"||n.def.cellDataType==="date"||n.def.cellDataType==="dateString"){const e=String(l[0]),i=/^(\d{4})-(\d{2})/.exec(e);return[i?`${i[1]}-${i[2]}`:e]}return l.map(e=>String(e))}function v(n,r){const o={},l=r.includes(d)?[d]:[],e=r.filter(t=>t!==d);if(n.fieldType==="singleSelect"||n.fieldType==="multiSelect"){const t=g(b(n.def)).options??[],a=new Map(t.map((f,c)=>[String(f.value),c]));for(const f of t)f.color&&(o[String(f.value)]=f.color);return e.sort((f,c)=>(a.get(f)??1e9)-(a.get(c)??1e9)),{keys:[...e,...l],label:f=>f,colors:o}}return e.length>0&&e.every(t=>/^\d{4}-\d{2}$/.test(t))?(e.sort(),{keys:[...e,...l],label:t=>t===d?t:`${O[Number(t.slice(5))-1]} ${t.slice(0,4)}`,colors:o}):(e.length&&e.every(t=>t!==""&&!Number.isNaN(Number(t)))&&e.sort((t,a)=>Number(t)-Number(a)),{keys:[...e,...l],label:t=>t,colors:o})}export function chartSpec(n,r,o){const l=m(n),e=l.find(s=>s.id===r.x);if(!e)return null;const i=r.y?l.find(s=>s.id===r.y):void 0,t=new Map;for(const s of o){if(s==null)continue;const u=i?Number(M(i,s)):1;for(const k of N(e,s)){const S=t.get(k)??{total:0,n:0};(!i||Number.isFinite(u))&&(S.total+=Number.isFinite(u)?u:0,S.n+=1),t.set(k,S)}}const{keys:a,label:f,colors:c}=v(e,[...t.keys()]),h=!!i&&r.aggregation==="avg",w=a.map(s=>{const u=t.get(s);return h?u.n?u.total/u.n:0:u.total}),T=a.map(f),y={};a.forEach((s,u)=>{c[s]&&(y[T[u]]=c[s])});const p=r.kind;return{type:p==="barH"?"bar":p==="donut"?"pie":p,categories:T,series:[{label:i?`${h?"Average":"Sum"} of ${i.header}`:"Records",values:w,...Object.keys(y).length&&(p==="bar"||p==="barH")?{colors:a.map(s=>c[s]??null)}:{}}],...Object.keys(y).length?{categoryColors:y}:{},...p==="barH"?{orientation:"horizontal"}:{},...p==="donut"?{innerRadius:.58}:{}}}export function withValueGutter(n,r){if(!r||n.type==="pie"||n.orientation==="horizontal")return n;const o=Math.max(0,...n.series.flatMap(i=>i.values)),l=o>0?10**Math.ceil(Math.log10(o)):1,e=Math.max(48,Math.round(r(l).length*6.4+14));return{...n,yAxis:{width:e}}}export function chartFormatter(n,r){const o=r.y?m(n).find(e=>e.id===r.y):void 0;if(!o)return e=>String(Math.round(e));const l=o.def.formatter;return l?e=>String(l({value:e})??e):void 0}export function chartBucketRows(n,r,o,l){const e=m(n).find(a=>a.id===r.x);if(!e)return[];const i=o.filter(a=>a!=null).map(a=>({row:a,keys:N(e,a)})),{label:t}=v(e,[...new Set(i.flatMap(a=>a.keys))]);return i.filter(a=>a.keys.some(f=>t(f)===l)).map(a=>a.row)}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The checklist field's value: to-do items in order, each with its own id so
3
+ * a rename or a reorder keeps it the same item. The text a copy, an export
4
+ * and a type change write is one item per line, "[x] Done thing" or
5
+ * "[ ] Open thing", and that text reads back into items.
6
+ */
7
+ export type ChecklistItem = {
8
+ id: string;
9
+ text: string;
10
+ done: boolean;
11
+ };
12
+ export declare const newChecklistItemId: () => string;
13
+ /**
14
+ * A stored value as items: an array of items (or of plain strings, each an
15
+ * open item), or text as `parseChecklist` reads it. Anything else is no items.
16
+ */
17
+ export declare function toChecklist(v: unknown): ChecklistItem[];
18
+ /**
19
+ * Text as items: one per line, "[x]" for a done item, "[ ]" or no mark for an
20
+ * open one. A single line with several marks ("[x] Draft [ ] Review", what a
21
+ * copy of one cell writes) holds several items.
22
+ */
23
+ export declare function parseChecklist(text: string): ChecklistItem[];
24
+ /** Items as text: "[x] text" per item, a line each (`sep`: what goes between them). */
25
+ export declare function checklistText(v: unknown, sep?: string): string;
26
+ /** How many items are done, of how many. */
27
+ export declare function checklistProgress(v: unknown): {
28
+ done: number;
29
+ total: number;
30
+ };
31
+ /** What a checklist sorts by: the share done, 0 to 1; no items sorts with the blanks. */
32
+ export declare function checklistSortValue(v: unknown): number | null;
33
+ /** The groups a checklist falls in, in their order; no items is the blank group. */
34
+ export declare const CHECKLIST_GROUPS: readonly ["Not started", "In progress", "Done"];
35
+ /** What a checklist groups by: "Not started", "In progress", "Done", or '' with no items. */
36
+ export declare function checklistGroup(v: unknown): string;
@@ -0,0 +1,4 @@
1
+ let c=0;export const newChecklistItemId=()=>`ci-${Date.now().toString(36)}-${(c++).toString(36)}`;const l=/^\s*(?:[-*]\s+)?\[( |x|X)?\]\s*/;export function toChecklist(o){if(typeof o=="string")return parseChecklist(o);if(!Array.isArray(o))return[];const e=[];for(const t of o)if(typeof t=="string")t.trim()&&e.push({id:newChecklistItemId(),text:t.trim(),done:!1});else if(t&&typeof t=="object"){const n=t,r=String(n.text??n.name??"").trim();if(!r)continue;e.push({id:typeof n.id=="string"&&n.id?n.id:newChecklistItemId(),text:r,done:n.done===!0||n.checked===!0})}return e}export function parseChecklist(o){const e=[];for(const t of o.replace(/\r\n?/g,`
2
+ `).split(`
3
+ `)){const n=[];for(const r of t.split(/\s+(?=\[(?: |x|X)?\]\s)/))n.length&&/^\s*[-*]$/.test(n[n.length-1])?n[n.length-1]+=` ${r}`:n.push(r);for(const r of n){const s=l.exec(r),i=(s?r.slice(s[0].length):r).trim();i&&e.push({id:newChecklistItemId(),text:i,done:!!s&&(s[1]==="x"||s[1]==="X")})}}return e}export function checklistText(o,e=`
4
+ `){return toChecklist(o).map(t=>`[${t.done?"x":" "}] ${t.text}`).join(e)}export function checklistProgress(o){const e=toChecklist(o);return{done:e.filter(t=>t.done).length,total:e.length}}export function checklistSortValue(o){const{done:e,total:t}=checklistProgress(o);return t?e/t:null}export const CHECKLIST_GROUPS=["Not started","In progress","Done"];export function checklistGroup(o){const{done:e,total:t}=checklistProgress(o);return t?e===t?CHECKLIST_GROUPS[2]:e?CHECKLIST_GROUPS[1]:CHECKLIST_GROUPS[0]:""}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * The color field's value: a hex color, stored lower case as '#rrggbb'.
3
+ * Typed or pasted text is read as '#rgb', '#rrggbb' (the '#' may be left
4
+ * out when the code has a digit in it), 'rgb(45, 127, 249)', or one of the
5
+ * CSS color names below. Other text (a name not listed, 'hsl()', a color
6
+ * with alpha) is not a color here: a paste of it keeps the cell as it was.
7
+ */
8
+ /** Text (or a stored value) as '#rrggbb', or null when it is not a color this field reads. */
9
+ export declare function parseColor(v: unknown): string | null;
10
+ /**
11
+ * What a color sorts and groups by: around the color wheel from red, then
12
+ * the grays from dark to light after every hue.
13
+ */
14
+ export declare function colorSortValue(v: unknown): number | null;
@@ -0,0 +1 @@
1
+ const u={black:"#000000",white:"#ffffff",gray:"#808080",grey:"#808080",silver:"#c0c0c0",red:"#ff0000",maroon:"#800000",orange:"#ffa500",yellow:"#ffff00",olive:"#808000",lime:"#00ff00",green:"#008000",teal:"#008080",cyan:"#00ffff",aqua:"#00ffff",blue:"#0000ff",navy:"#000080",purple:"#800080",magenta:"#ff00ff",fuchsia:"#ff00ff",pink:"#ffc0cb",brown:"#a52a2a",gold:"#ffd700",indigo:"#4b0082",violet:"#ee82ee"};export function parseColor(n){if(typeof n!="string")return null;const t=n.trim().toLowerCase();if(!t)return null;if(u[t])return u[t];let f=/^#?([0-9a-f]{6})$/.exec(t);if(f&&(t.startsWith("#")||/\d/.test(f[1])))return`#${f[1]}`;if(f=/^#([0-9a-f]{3})$/.exec(t),f)return`#${[...f[1]].map(e=>e+e).join("")}`;if(f=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/.exec(t),f){const e=[f[1],f[2],f[3]].map(Number);if(e.every(r=>r<=255))return`#${e.map(r=>r.toString(16).padStart(2,"0")).join("")}`}return null}export function colorSortValue(n){const t=parseColor(n);if(!t)return null;const[f,e,r]=[1,3,5].map(c=>parseInt(t.slice(c,c+2),16)/255),a=Math.max(f,e,r),l=Math.min(f,e,r),s=(a+l)/2,o=a-l;if(o<.08)return 1e3+s;let i=a===f?(e-r)/o%6:a===e?(r-f)/o+2:(f-e)/o+4;return i=(i*60+360)%360,i+s/2}
@@ -1 +1 @@
1
- import{attachmentsFromText as y,attachmentsText as d,toAttachments as h}from"./attachments.js";import{parseDuration as b}from"./format.js";import{fillFieldColumn as g,getFieldType as S}from"./registry.svelte.js";import{splitNames as A}from"./name-list.js";import{getLinkedTable as l,resolveLinkId as x,resolveLinkIds as N}from"./sources.svelte.js";const T=new Set(["text","longText","url","email","phone","barcode"]),f=new Set(["formula","lookup","rollup","count","createdTime","lastModifiedTime","createdBy","lastModifiedBy","autoNumber","button"]),k=new Set(["number","currency","percent","rating"]);export const keepsStoredValues=t=>f.has(t),isEmptyValue=t=>t==null||t===""||Array.isArray(t)&&t.length===0||typeof t=="number"&&Number.isNaN(t);export function asText(t,r){return t==null?"":r==="attachment"?d(t):Array.isArray(t)?t.map(e=>asText(e)).filter(Boolean).join(", "):t instanceof Date?u(t):String(t)}const u=t=>`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`;export function convertValue(t,r,e,n){if(f.has(e))return t;if(isEmptyValue(t))return e==="checkbox"?!1:e==="multiSelect"||e==="attachment"?[]:null;if(r===e)return t;if(T.has(e))return asText(t,r);if(e==="duration")return typeof t=="number"?t:b(asText(t,r));if(e==="user")return Array.isArray(t)?t.map(s=>asText(s)):asText(t,r)||null;if(e==="link"){const s=l(n?.table),o=s?N(s,m(t,r)):[];return n?.multiple===!1?o.slice(0,1):o}if(k.has(e)){if(typeof t=="boolean")return t?1:0;if(typeof t=="number")return e==="rating"?Math.max(0,Math.min(10,Math.round(t))):t;if(Array.isArray(t))return t.length===1?convertValue(t[0],void 0,e):null;const s=asText(t,r).replace(/[^0-9.eE+-]/g,""),o=/\d/.test(s)?Number(s):NaN;return Number.isFinite(o)?e==="rating"?Math.max(0,Math.min(10,Math.round(o))):o:null}if(e==="checkbox")return typeof t=="boolean"?t:typeof t=="number"?t!==0:/^(true|yes|y|1|x|on|done|checked)$/i.test(asText(t,r).trim());if(e==="date"){if(t instanceof Date)return Number.isNaN(t.getTime())?null:u(t);const s=new Date(asText(t,r));return Number.isNaN(s.getTime())?null:s.toISOString().slice(0,10)}if(e==="singleSelect")return(Array.isArray(t)?asText(t[0]):asText(t,r)).trim()||null;if(e==="multiSelect"){const s=Array.isArray(t)?t.map(o=>asText(o)):asText(t,r).split(",");return[...new Set(s.map(o=>o.trim()).filter(Boolean))]}if(e==="attachment")return r==="attachment"?h(t):y(asText(t,r));const i=M(e,n),a=asText(t,r);if(!i)return t!==null&&typeof t=="object"?a||null:t;const c=i(a);return c===void 0?null:c}const p=new WeakMap;function M(t,r){const e=S(t);if(!e)return null;let n=p.get(e);n||p.set(e,n=new Map);const i=JSON.stringify(r??{});if(!n.has(i)){const a=g({field:"__convert",fieldType:t,fieldProps:r??{}}).valueParser;n.set(i,typeof a=="function"?c=>{try{return a({newValue:c,oldValue:null,rawInput:c})}catch{return null}}:null)}return n.get(i)}function m(t,r){return Array.isArray(t)?t.map(e=>asText(e).trim()).filter(Boolean):A(asText(t,r))}function w(t,r,e,n){if(e==="singleSelect")return Array.isArray(t)&&new Set(t.map(i=>asText(i).trim()).filter(Boolean)).size>1;if(e==="link"){const i=l(n?.table);if(!i)return!1;const a=m(t,r).map(c=>x(i,c));return a.some(c=>c==null)||n?.multiple===!1&&new Set(a).size>1}return!1}export function countCleared(t,r,e,n){if(f.has(e)||r===e)return 0;let i=0;for(const a of t)isEmptyValue(a)||(isEmptyValue(convertValue(a,r,e,n))||w(a,r,e,n))&&(i+=1);return i}export function optionsFromValues(t){const r=new Set;for(const e of t)for(const n of Array.isArray(e)?e:[e]){const i=n==null?"":String(n).trim();i&&r.add(i)}return[...r].slice(0,200).map(e=>({value:e}))}
1
+ import{attachmentsFromText as d,attachmentsText as h,toAttachments as S}from"./attachments.js";import{parseDuration as b}from"./format.js";import{fillFieldColumn as g,getFieldType as A}from"./registry.svelte.js";import{splitNames as k}from"./name-list.js";import{checklistText as x,toChecklist as l}from"./checklist.js";import{parseColor as T}from"./color-value.js";import{parseTimeOfDay as N,timeFromSeconds as w}from"./time-of-day.js";import{getLinkedTable as u,resolveLinkId as M,resolveLinkIds as D}from"./sources.svelte.js";const E=new Set(["text","longText","url","email","phone","barcode"]),f=new Set(["formula","lookup","rollup","count","createdTime","lastModifiedTime","createdBy","lastModifiedBy","autoNumber","button"]),F=new Set(["number","currency","percent","rating"]);export const keepsStoredValues=t=>f.has(t),isEmptyValue=t=>t==null||t===""||Array.isArray(t)&&t.length===0||typeof t=="number"&&Number.isNaN(t);export function asText(t,e){return t==null?"":e==="attachment"?h(t):e==="checklist"?x(t):Array.isArray(t)?t.map(r=>asText(r)).filter(Boolean).join(", "):t instanceof Date?m(t):String(t)}const m=t=>`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`;export function convertValue(t,e,r,n){if(f.has(r))return t;if(isEmptyValue(t))return r==="checkbox"?!1:r==="multiSelect"||r==="attachment"?[]:null;if(e===r)return t;if(E.has(r))return asText(t,e);if(r==="duration")return typeof t=="number"?t:b(asText(t,e));if(r==="user")return Array.isArray(t)?t.map(s=>asText(s)):asText(t,e)||null;if(r==="link"){const s=u(n?.table),o=s?D(s,y(t,e)):[];return n?.multiple===!1?o.slice(0,1):o}if(F.has(r)){if(typeof t=="boolean")return t?1:0;if(typeof t=="number")return r==="rating"?Math.max(0,Math.min(10,Math.round(t))):t;if(Array.isArray(t))return t.length===1?convertValue(t[0],void 0,r):null;const s=asText(t,e).replace(/[^0-9.eE+-]/g,""),o=/\d/.test(s)?Number(s):NaN;return Number.isFinite(o)?r==="rating"?Math.max(0,Math.min(10,Math.round(o))):o:null}if(r==="checkbox")return typeof t=="boolean"?t:typeof t=="number"?t!==0:/^(true|yes|y|1|x|on|done|checked)$/i.test(asText(t,e).trim());if(r==="date"){if(t instanceof Date)return Number.isNaN(t.getTime())?null:m(t);const s=new Date(asText(t,e));return Number.isNaN(s.getTime())?null:s.toISOString().slice(0,10)}if(r==="singleSelect")return(Array.isArray(t)?asText(t[0]):asText(t,e)).trim()||null;if(r==="multiSelect"){const s=Array.isArray(t)?t.map(o=>asText(o)):asText(t,e).split(",");return[...new Set(s.map(o=>o.trim()).filter(Boolean))]}if(r==="attachment")return e==="attachment"?S(t):d(asText(t,e));if(r==="checklist"){const s=Array.isArray(t)&&e!=="checklist"?l(t.map(o=>asText(o))):l(asText(t,e));return s.length?s:null}if(r==="color")return T(asText(t,e));if(r==="timeOfDay")return e==="duration"&&typeof t=="number"?w(t):N(t instanceof Date?t:asText(t,e),{seconds:!!n?.showSeconds});const i=B(r,n),c=asText(t,e);if(!i)return t!==null&&typeof t=="object"?c||null:t;const a=i(c);return a===void 0?null:a}const p=new WeakMap;function B(t,e){const r=A(t);if(!r)return null;let n=p.get(r);n||p.set(r,n=new Map);const i=JSON.stringify(e??{});if(!n.has(i)){const c=g({field:"__convert",fieldType:t,fieldProps:e??{}}).valueParser;n.set(i,typeof c=="function"?a=>{try{return c({newValue:a,oldValue:null,rawInput:a})}catch{return null}}:null)}return n.get(i)}function y(t,e){return Array.isArray(t)?t.map(r=>asText(r).trim()).filter(Boolean):k(asText(t,e))}function V(t,e,r,n){if(r==="singleSelect")return Array.isArray(t)&&new Set(t.map(i=>asText(i).trim()).filter(Boolean)).size>1;if(r==="link"){const i=u(n?.table);if(!i)return!1;const c=y(t,e).map(a=>M(i,a));return c.some(a=>a==null)||n?.multiple===!1&&new Set(c).size>1}return!1}export function countCleared(t,e,r,n){if(f.has(r)||e===r)return 0;let i=0;for(const c of t)isEmptyValue(c)||(isEmptyValue(convertValue(c,e,r,n))||V(c,e,r,n))&&(i+=1);return i}export function optionsFromValues(t){const e=new Set;for(const r of t)for(const n of Array.isArray(r)?r:[r]){const i=n==null?"":String(n).trim();i&&e.add(i)}return[...e].slice(0,200).map(r=>({value:r}))}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * What a copy (Ctrl+C) writes for a field of a base: names for people and
3
3
  * links (their paste reads names back), the URLs of attachments (a paste of
4
- * URLs attaches them), a barcode's text. Every other value is copied as
4
+ * URLs attaches them), a barcode's text, a checklist's "[x] item" marks. Every other value is copied as
5
5
  * stored, so numbers and dates paste back exactly. Names of linked records
6
6
  * and of several people are quoted when they hold a comma ("Acme, Inc."),
7
7
  * so the paste splits them back the same way.
@@ -1 +1 @@
1
- import{toAttachments as l}from"./attachments.js";import{joinNames as i}from"./name-list.js";import{findFieldUser as a,getLinkedTable as u,linkedRows as f}from"./sources.svelte.js";const m=new Set(["user","createdBy","lastModifiedBy","link","lookup","barcode"]);function c(e){if(typeof location>"u")return e;try{return new URL(e,location.href).href}catch{return e}}export function fieldCopyText(e){const r=e.column?.columnDef,n=r?.fieldType;if(n==="attachment")return l(e.value).map(t=>t.url).filter(Boolean).map(c).join(" ");if(n==="link"){const t=u(r?.fieldProps?.table);if(t)return i(f(t,e.value).map(o=>String(o[t.primaryField]??"")))}if(n==="user"&&r?.fieldProps?.multiple){const t=Array.isArray(e.value)?e.value:e.value==null||e.value===""?[]:[e.value];return i(t.map(o=>a(o)?.name??String(o)))}return!m.has(n)||typeof r?.formatter!="function"?e.value:r.formatter({value:e.value,row:e.row,column:e.column})}
1
+ import{toAttachments as l}from"./attachments.js";import{checklistText as a}from"./checklist.js";import{joinNames as i}from"./name-list.js";import{findFieldUser as u,getLinkedTable as f,linkedRows as c}from"./sources.svelte.js";const m=new Set(["user","createdBy","lastModifiedBy","link","lookup","barcode"]);function s(e){if(typeof location>"u")return e;try{return new URL(e,location.href).href}catch{return e}}export function fieldCopyText(e){const r=e.column?.columnDef,o=r?.fieldType;if(o==="attachment")return l(e.value).map(t=>t.url).filter(Boolean).map(s).join(" ");if(o==="checklist")return a(e.value," ");if(o==="link"){const t=f(r?.fieldProps?.table);if(t)return i(c(t,e.value).map(n=>String(n[t.primaryField]??"")))}if(o==="user"&&r?.fieldProps?.multiple){const t=Array.isArray(e.value)?e.value:e.value==null||e.value===""?[]:[e.value];return i(t.map(n=>u(n)?.name??String(n)))}return!m.has(o)||typeof r?.formatter!="function"?e.value:r.formatter({value:e.value,row:e.row,column:e.column})}