@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.
- package/dist/SvGridBoard.svelte +1 -1
- package/dist/cdn/svgrid-enterprise.svelte-external.js +2 -2
- package/dist/designer/assets/{index-v61ZvIWw.js → index-Eyxa9vgS.js} +3 -3
- package/dist/designer/assets/{src-DkFgWld_.js → src-CSmsOfsG.js} +15 -15
- package/dist/designer/index.html +2 -2
- package/dist/fields/AiCell.svelte +41 -0
- package/dist/fields/AiCell.svelte.d.ts +5 -0
- package/dist/fields/BaseChartView.svelte +1 -1
- package/dist/fields/BaseDashboardView.svelte +133 -0
- package/dist/fields/BaseDashboardView.svelte.d.ts +17 -0
- package/dist/fields/BaseImport.svelte +89 -0
- package/dist/fields/BaseImport.svelte.d.ts +15 -0
- package/dist/fields/BaseInboxView.svelte +112 -0
- package/dist/fields/BaseInboxView.svelte.d.ts +8 -0
- package/dist/fields/BaseListView.svelte +90 -0
- package/dist/fields/BaseListView.svelte.d.ts +8 -0
- package/dist/fields/BaseSearch.svelte +78 -0
- package/dist/fields/BaseSearch.svelte.d.ts +10 -0
- package/dist/fields/BaseTableView.svelte +28 -3
- package/dist/fields/BaseTableView.svelte.d.ts +5 -1
- package/dist/fields/BaseTabs.svelte +45 -8
- package/dist/fields/BaseTabs.svelte.d.ts +25 -1
- package/dist/fields/BaseTrash.svelte +63 -0
- package/dist/fields/BaseTrash.svelte.d.ts +15 -0
- package/dist/fields/ChecklistCell.svelte +22 -0
- package/dist/fields/ChecklistCell.svelte.d.ts +10 -0
- package/dist/fields/ChecklistEditor.svelte +81 -0
- package/dist/fields/ChecklistEditor.svelte.d.ts +12 -0
- package/dist/fields/ColorCell.svelte +13 -0
- package/dist/fields/ColorCell.svelte.d.ts +8 -0
- package/dist/fields/ColorEditor.svelte +60 -0
- package/dist/fields/ColorEditor.svelte.d.ts +11 -0
- package/dist/fields/DashboardRecords.svelte +35 -0
- package/dist/fields/DashboardRecords.svelte.d.ts +11 -0
- package/dist/fields/DashboardTileEditor.svelte +138 -0
- package/dist/fields/DashboardTileEditor.svelte.d.ts +15 -0
- package/dist/fields/FieldEditor.svelte +32 -3
- package/dist/fields/FieldInput.svelte +1 -1
- package/dist/fields/GroupHeader.svelte +3 -3
- package/dist/fields/ListChips.svelte +21 -0
- package/dist/fields/ListChips.svelte.d.ts +9 -0
- package/dist/fields/MentionInput.svelte +59 -0
- package/dist/fields/MentionInput.svelte.d.ts +11 -0
- package/dist/fields/PropertyInput.svelte +13 -10
- package/dist/fields/RecordView.svelte +20 -25
- package/dist/fields/SvBase.svelte +48 -9
- package/dist/fields/SvBase.svelte.d.ts +33 -1
- package/dist/fields/SvBaseForm.svelte +2 -2
- package/dist/fields/SvBaseForm.svelte.d.ts +14 -0
- package/dist/fields/SvBaseViewBar.svelte +33 -12
- package/dist/fields/SvBaseViewBar.svelte.d.ts +2 -0
- package/dist/fields/TimeOfDayEditor.svelte +39 -0
- package/dist/fields/TimeOfDayEditor.svelte.d.ts +12 -0
- package/dist/fields/activity.svelte.d.ts +29 -0
- package/dist/fields/activity.svelte.js +1 -1
- package/dist/fields/ai-field.svelte.d.ts +91 -0
- package/dist/fields/ai-field.svelte.js +1 -0
- package/dist/fields/ai-prompt.d.ts +64 -0
- package/dist/fields/ai-prompt.js +7 -0
- package/dist/fields/airtable.d.ts +90 -0
- package/dist/fields/airtable.js +1 -0
- package/dist/fields/bar-request.svelte.d.ts +1 -1
- package/dist/fields/base-history.d.ts +56 -0
- package/dist/fields/base-history.js +1 -0
- package/dist/fields/base-import.d.ts +54 -0
- package/dist/fields/base-import.js +2 -0
- package/dist/fields/base-search.d.ts +34 -0
- package/dist/fields/base-search.js +1 -0
- package/dist/fields/base-share.d.ts +45 -0
- package/dist/fields/base-share.js +1 -0
- package/dist/fields/base-sql.js +3 -3
- package/dist/fields/base-trash.d.ts +51 -0
- package/dist/fields/base-trash.js +1 -0
- package/dist/fields/builtin-types.js +1 -1
- package/dist/fields/chart-view.d.ts +12 -0
- package/dist/fields/chart-view.js +1 -1
- package/dist/fields/checklist.d.ts +36 -0
- package/dist/fields/checklist.js +4 -0
- package/dist/fields/color-value.d.ts +14 -0
- package/dist/fields/color-value.js +1 -0
- package/dist/fields/convert.js +1 -1
- package/dist/fields/copy-text.d.ts +1 -1
- package/dist/fields/copy-text.js +1 -1
- package/dist/fields/dashboard.d.ts +143 -0
- package/dist/fields/dashboard.js +1 -0
- package/dist/fields/field-access.svelte.d.ts +37 -0
- package/dist/fields/field-access.svelte.js +1 -0
- package/dist/fields/field-ops.js +1 -1
- package/dist/fields/filter-model.d.ts +4 -11
- package/dist/fields/filter-model.js +1 -1
- package/dist/fields/form-logic.d.ts +69 -0
- package/dist/fields/form-logic.js +1 -0
- package/dist/fields/formula.js +1 -1
- package/dist/fields/grid-access.d.ts +8 -0
- package/dist/fields/grid-access.js +1 -1
- package/dist/fields/index.d.ts +16 -0
- package/dist/fields/index.js +1 -1
- package/dist/fields/list-view.d.ts +40 -0
- package/dist/fields/list-view.js +1 -0
- package/dist/fields/mentions.d.ts +50 -0
- package/dist/fields/mentions.js +1 -0
- package/dist/fields/palette.d.ts +4 -2
- package/dist/fields/palette.js +1 -1
- package/dist/fields/record-menu.js +1 -1
- package/dist/fields/registry.svelte.d.ts +5 -0
- package/dist/fields/registry.svelte.js +1 -1
- package/dist/fields/time-of-day.d.ts +28 -0
- package/dist/fields/time-of-day.js +1 -0
- package/dist/fields/view-model.d.ts +24 -2
- package/dist/fields/view-model.js +1 -1
- package/dist/fields/viewbar/ConditionValue.svelte +3 -3
- package/dist/fields/viewbar/ListPanel.svelte +36 -0
- package/dist/fields/viewbar/ListPanel.svelte.d.ts +11 -0
- package/dist/fields/viewbar/ViewsMenu.svelte +27 -4
- package/dist/fields/viewbar/ViewsMenu.svelte.d.ts +6 -0
- package/dist/node/studio.js +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +1 -1
- package/dist/wc/GridFind-DsTvdUXq.js +1 -0
- package/dist/wc/GridFooter-D-i8boBh.js +1 -0
- package/dist/wc/GridMenus-CYe9Fw2I.js +20 -0
- package/dist/wc/PinSplitter-LvyyrLhe.js +6 -0
- package/dist/wc/SvChartMenu-XKW_LOYw.js +1 -0
- package/dist/wc/SvDateRangeInput-CSOxqTB1.js +1 -0
- package/dist/wc/SvDateTimePicker-DvvFs2T9.js +4 -0
- package/dist/wc/SvField-BmQphyOs.js +20 -0
- package/dist/wc/SvForm-HD7y5vmk.js +46 -0
- package/dist/wc/SvGridCellEditor-776KAOe1.js +3 -0
- package/dist/wc/SvGridChart-DC7ZUhp8.js +171 -0
- package/dist/wc/SvGridChartBuilder-Dd3vWBvq.js +7 -0
- package/dist/wc/SvGridChartPanel-CwYjF46U.js +5 -0
- package/dist/wc/SvGridChartView-CSF38rBs.js +3 -0
- package/dist/wc/SvGridDropdown-4S1G7gsP.js +30 -0
- package/dist/wc/SvMenuList-D3ZLXjL_.js +1 -0
- package/dist/wc/SvModal-Dk0YwPWp.js +7 -0
- package/dist/wc/SvSwitchButton-DdZmc3ew.js +1 -0
- package/dist/wc/SvTabs-BI2cQHyw.js +2 -0
- package/dist/wc/base-react.d.ts +38 -0
- package/dist/wc/base-react.js +1 -0
- package/dist/wc/base-vue.d.ts +29 -0
- package/dist/wc/base-vue.js +1 -0
- package/dist/wc/board-RQp5fHPR.js +21 -0
- package/dist/wc/board-view.svelte-CpxuZcEg.js +1 -0
- package/dist/wc/card-marks.svelte-QwxIcKcZ.js +1 -0
- package/dist/wc/client-DNdLmGcu.js +3 -0
- package/dist/wc/createOverlay.svelte-CDw3RXgs.js +1 -0
- package/dist/wc/custom-filter-Dp8JxlQu.js +2 -0
- package/dist/wc/date-format-DtSmFyEB.js +18 -0
- package/dist/wc/editor-registry-CkKfcVLc.js +1 -0
- package/dist/wc/export-format-CGfE9_O5.js +5 -0
- package/dist/wc/gallery-CNOHNWEJ.js +4 -0
- package/dist/wc/gallery-view.svelte-27X-wCQH.js +1 -0
- package/dist/wc/grid-extension.svelte-hgqOteka.js +1 -0
- package/dist/wc/import-B9mIERCl.js +4 -0
- package/dist/wc/js-scroller.svelte-BP8Up6_q.js +1 -0
- package/dist/wc/license-CWVWqb-i.js +27 -0
- package/dist/wc/list-option-CI4nMshZ.js +1 -0
- package/dist/wc/react.d.ts +1 -0
- package/dist/wc/react.js +1 -1
- package/dist/wc/scheduler-CkVY4od-.js +147 -0
- package/dist/wc/scheduler-view.svelte-SzG7rU8b.js +1 -0
- package/dist/wc/sparkline-DWRBQubt.js +1 -0
- package/dist/wc/sv-base-element.d.ts +87 -0
- package/dist/wc/sv-base-element.js +273 -0
- package/dist/wc/sv-sheet-element.d.ts +2 -0
- package/dist/wc/sv-sheet-element.js +55 -55
- package/dist/wc/svelte-virtualizer.svelte-CSBwEZt9.js +1 -0
- package/dist/wc/types/sv-base-element.d.ts +87 -0
- package/dist/wc/vue.d.ts +1 -0
- package/dist/wc/vue.js +1 -1
- package/package.json +18 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import{onMount,untrack}from"svelte";import{getRecordRequest}from"./editor-request.svelte";import{getFieldType}from"./registry.svelte";import{cellText,fieldColumns,primaryIdOf}from"./grid-access";import{addComment,changesOf,commentsOf,markSeen,unseenOf}from"./activity.svelte";import{findFieldUser}from"./sources.svelte";let{ctrl,rowId,editPrimary=false,focus,onClose}=$props();let current=$state(rowId);let open=$state(true);let editing=$state(null);let showHidden=$state(false);let comment=$state("");const rows=$derived(ctrl.allRows??[]);const index=$derived(rows.findIndex(r=>r.id===current));const row=$derived(index>=0?rows[index]:null);let lastIndex=0;const at=$derived.by(()=>{if(index>=0)lastIndex=index;return lastIndex});const canPrev=$derived(at>0&&rows.length>0);const canNext=$derived(at<rows.length-(index>=0?1:0));const columns=$derived((ctrl.allColumns??[]).filter(c=>!c.id.startsWith("__")&&(c.columnDef.field!=null||c.columnDef.fieldFn!=null)));const hidden=$derived.by(()=>{const shownIds=new Set(columns.map(c=>c.id));return fieldColumns(ctrl).filter(c=>!shownIds.has(c.id)).map(c=>({id:c.id,columnDef:c.def}))});function valueOf(c){if(!row)return void 0;const base=c.columnDef.fieldFn?c.columnDef.fieldFn(row.original):row.original?.[c.columnDef.field];return ctrl.getCellDisplayValue(row.id,c.id,columns.includes(c)?row.getCellValueByColumnId(c.id):base)}const asField=c=>({id:c.id,field:String(c.columnDef.field??c.id),header:label(c),fieldType:c.columnDef.fieldType,def:c.columnDef,visible:true});const primaryId=$derived(primaryIdOf(ctrl));const primary=$derived(columns.find(c=>c.id===primaryId)??columns.find(c=>c.columnDef.fieldType==="text"||!c.columnDef.fieldType&&c.columnDef.editorType==null)??columns[0]);const title=$derived(row&&primary?cellText(asField(primary),valueOf(primary),row)||"Untitled":"Record");function label(c){return typeof c.columnDef.header==="string"?c.columnDef.header:c.id}const iconOf=c=>c.columnDef.fieldType?getFieldType(c.columnDef.fieldType)?.icon:void 0;function editable(c){if(!row||!ctrl.editingEnabled)return false;const ci=ctrl.allColumns.findIndex(x=>x.id===c.id);if(ci<0)return false;return ctrl.isCellEditableAt?!!ctrl.isCellEditableAt(index,ci):c.columnDef.editable!==false}onMount(()=>{if(editPrimary&&primary&&editable(primary))editing=primary.id});let commentBox=$state(null);const commentFocusFor=r=>r?.focus==="comment"&&r.ctrl===ctrl;const initialFocus=()=>focus==="comment"||commentFocusFor(getRecordRequest())?commentBox:null;$effect(()=>{const r=getRecordRequest();if(!commentFocusFor(r))return;untrack(()=>{if(r.rowId!==current)current=r.rowId;queueMicrotask(()=>commentBox?.focus())})});function commit(c,v){editing=null;if(!row||v===void 0)return;const at2=ctrl.allRows.findIndex(r=>r.id===current);if(at2<0||!ctrl.startEditing(at2,c.id))return;ctrl.updateEditingCellValue(v);ctrl.saveEditingCell()}function editBeside(c,dir){const at2=columns.findIndex(x=>x.id===c.id);for(let i=at2+dir;i>=0&&i<columns.length;i+=dir){const next=columns[i];if(editable(next)&&next.columnDef.editorType!=="checkbox"){editing=next.id;return}}}function go(by){const next=index>=0?rows[index+by]:rows[Math.min(at,rows.length)-(by<0?1:0)];if(!next)return;editing=null;current=next.id}const allCols=$derived([...columns,...hidden]);const feed=$derived.by(()=>{if(!row)return[];const edits=changesOf(ctrl,row.id).map(ch=>{if(ch.added)return{key:`a${ch.at}`,at:ch.at,by:ch.by,remote:true,kind:"added",field:"",text:""};const c=allCols.find(x=>x.id===ch.columnId);const show=v=>c?cellText(asField(c),v,row):String(v??"");return{key:`e${ch.at}${ch.columnId}`,at:ch.at,by:ch.by,automation:ch.automation,via:ch.via,remote:ch.remote,kind:"edit",field:c?label(c):ch.columnId,text:show(ch.value),..."from"in ch&&show(ch.from)?{from:show(ch.from)}:{}}});const notes=commentsOf(ctrl,row.id).map(n=>({key:n.id,at:n.at,by:n.by,kind:"comment",field:"",text:n.text}));return[...edits,...notes].sort((a,b)=>a.at-b.at)});const person=item=>item.by?findFieldUser(item.by)?.name??"Someone":item.remote?"Someone else":"You";const who=item=>item.automation?`Automation: ${item.automation}`:item.via?`${item.via} (accepted by ${person(item)})`:person(item);$effect(()=>{const id=row?.id;if(id!=null&&unseenOf(ctrl,id))untrack(()=>markSeen(ctrl,id))});function send(){if(!row||!comment.trim())return;addComment(ctrl,row.id,comment);comment=""}
|
|
2
|
+
import{onMount,untrack}from"svelte";import{getRecordRequest}from"./editor-request.svelte";import{fieldPropsOf,getFieldType,originalColumn}from"./registry.svelte";import{protectionText}from"./field-access.svelte";import{isReadOnlyGrid}from"./base-share";import{cellText,fieldColumns,primaryIdOf}from"./grid-access";import{addComment,changesOf,commentsOf,markSeen,unseenOf}from"./activity.svelte";import{findFieldUser}from"./sources.svelte";import{encodeMentions,parseMentions}from"./mentions";let{ctrl,rowId,editPrimary=false,focus,onClose}=$props();let current=$state(rowId);let open=$state(true);let editing=$state(null);let showHidden=$state(false);let comment=$state("");let picked=$state([]);const rows=$derived(ctrl.allRows??[]);const index=$derived(rows.findIndex(r=>r.id===current));const row=$derived(index>=0?rows[index]:null);let lastIndex=0;const at=$derived.by(()=>{if(index>=0)lastIndex=index;return lastIndex});const canPrev=$derived(at>0&&rows.length>0);const canNext=$derived(at<rows.length-(index>=0?1:0));const columns=$derived((ctrl.allColumns??[]).filter(c=>!c.id.startsWith("__")&&(c.columnDef.field!=null||c.columnDef.fieldFn!=null)));const hidden=$derived.by(()=>{const shownIds=new Set(columns.map(c=>c.id));return fieldColumns(ctrl).filter(c=>!shownIds.has(c.id)).map(c=>({id:c.id,columnDef:c.def}))});function valueOf(c){if(!row)return void 0;const base=c.columnDef.fieldFn?c.columnDef.fieldFn(row.original):row.original?.[c.columnDef.field];return ctrl.getCellDisplayValue(row.id,c.id,columns.includes(c)?row.getCellValueByColumnId(c.id):base)}const asField=c=>({id:c.id,field:String(c.columnDef.field??c.id),header:label(c),fieldType:c.columnDef.fieldType,def:c.columnDef,visible:true});const primaryId=$derived(primaryIdOf(ctrl));const primary=$derived(columns.find(c=>c.id===primaryId)??columns.find(c=>c.columnDef.fieldType==="text"||!c.columnDef.fieldType&&c.columnDef.editorType==null)??columns[0]);const title=$derived(row&&primary?cellText(asField(primary),valueOf(primary),row)||"Untitled":"Record");function label(c){return typeof c.columnDef.header==="string"?c.columnDef.header:c.id}const protectionOf=c=>c.columnDef.fieldType?protectionText(originalColumn(c.columnDef),fieldPropsOf(originalColumn(c.columnDef))):null;const iconOf=c=>c.columnDef.fieldType?getFieldType(c.columnDef.fieldType)?.icon:void 0;function editable(c){if(!row||!ctrl.editingEnabled)return false;const ci=ctrl.allColumns.findIndex(x=>x.id===c.id);if(ci<0)return false;return ctrl.isCellEditableAt?!!ctrl.isCellEditableAt(index,ci):c.columnDef.editable!==false}onMount(()=>{if(editPrimary&&primary&&editable(primary))editing=primary.id});let commentBox=$state(null);const commentFocusFor=r=>r?.focus==="comment"&&r.ctrl===ctrl;const initialFocus=()=>focus==="comment"||commentFocusFor(getRecordRequest())?commentBox:null;$effect(()=>{const r=getRecordRequest();if(!commentFocusFor(r))return;untrack(()=>{if(r.rowId!==current)current=r.rowId;queueMicrotask(()=>commentBox?.focus())})});function commit(c,v){editing=null;if(!row||v===void 0)return;const at2=ctrl.allRows.findIndex(r=>r.id===current);if(at2<0||!ctrl.startEditing(at2,c.id))return;ctrl.updateEditingCellValue(v);ctrl.saveEditingCell()}function editBeside(c,dir){const at2=columns.findIndex(x=>x.id===c.id);for(let i=at2+dir;i>=0&&i<columns.length;i+=dir){const next=columns[i];if(editable(next)&&next.columnDef.editorType!=="checkbox"){editing=next.id;return}}}function go(by){const next=index>=0?rows[index+by]:rows[Math.min(at,rows.length)-(by<0?1:0)];if(!next)return;editing=null;current=next.id}const allCols=$derived([...columns,...hidden]);const feed=$derived.by(()=>{if(!row)return[];const edits=changesOf(ctrl,row.id).map(ch=>{if(ch.added)return{key:`a${ch.at}`,at:ch.at,by:ch.by,remote:true,kind:"added",field:"",text:""};const c=allCols.find(x=>x.id===ch.columnId);const show=v=>c?cellText(asField(c),v,row):String(v??"");return{key:`e${ch.at}${ch.columnId}`,at:ch.at,by:ch.by,automation:ch.automation,via:ch.via,remote:ch.remote,kind:"edit",field:c?label(c):ch.columnId,text:show(ch.value),..."from"in ch&&show(ch.from)?{from:show(ch.from)}:{}}});const notes=commentsOf(ctrl,row.id).map(n=>({key:n.id,at:n.at,by:n.by,kind:"comment",field:"",text:n.text,parts:parseMentions(n.text)}));return[...edits,...notes].sort((a,b)=>a.at-b.at)});const person=item=>item.by?findFieldUser(item.by)?.name??"Someone":item.remote?"Someone else":"You";const who=item=>item.automation?`Automation: ${item.automation}`:item.via?`${item.via} (accepted by ${person(item)})`:person(item);$effect(()=>{const id=row?.id;if(id!=null&&unseenOf(ctrl,id))untrack(()=>markSeen(ctrl,id))});const readOnly=$derived(isReadOnlyGrid(ctrl));function send(){if(!row||!comment.trim()||readOnly)return;addComment(ctrl,row.id,encodeMentions(comment,picked));comment="";picked=[]}const mentioned=(id,name)=>findFieldUser(id)??{id,name:name||"Someone"};
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
5
|
{#snippet field(c: Col, canEdit: boolean)}
|
|
@@ -7,7 +7,11 @@ import{onMount,untrack}from"svelte";import{getRecordRequest}from"./editor-reques
|
|
|
7
7
|
<div class="sv-frv-label">
|
|
8
8
|
{#if iconOf(c)}<svg viewBox="0 0 24 24" width="14" height="14" aria-hidden="true"><path d={iconOf(c)} fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" /></svg>{/if}
|
|
9
9
|
<span>{label(c)}</span>
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
{#if !canEdit && !readOnly}
|
|
12
|
+
{@const locked = protectionOf(c)}
|
|
13
|
+
<span class="sv-frv-ro" title={locked ?? undefined}>{locked ? 'protected' : columns.includes(c) ? 'read-only' : 'hidden in the grid'}</span>
|
|
14
|
+
{/if}
|
|
11
15
|
</div>
|
|
12
16
|
<FieldInput
|
|
13
17
|
{ctrl}
|
|
@@ -54,7 +58,7 @@ import{onMount,untrack}from"svelte";import{getRecordRequest}from"./editor-reques
|
|
|
54
58
|
<div class="sv-frv-item-head"><strong>{who(item)}</strong>{item.kind === 'edit' ? ` changed ${item.field}` : item.kind === 'added' ? ' added this record' : ''}<span class="sv-frv-when">{timeAgo(item.at)}</span></div>
|
|
55
59
|
{#if item.kind !== 'added'}
|
|
56
60
|
<div class="sv-frv-item-body">
|
|
57
|
-
{#if item.from !== undefined}<span class="sv-frv-from">{item.from}</span><span class="sv-frv-arrow" aria-label="to">→</span>{/if}{item.text || (item.kind === 'edit' ? '(cleared)' : '')}
|
|
61
|
+
{#if item.parts}{#each item.parts as part, i (i)}{#if 'mention' in part}{@const user = mentioned(part.mention, part.name)}<span class="sv-frv-mention" title={user.email ?? user.name}><UserFace {user} size={14} />@{user.name}</span>{:else}{part.text}{/if}{/each}{:else}{#if item.from !== undefined}<span class="sv-frv-from">{item.from}</span><span class="sv-frv-arrow" aria-label="to">→</span>{/if}{item.text || (item.kind === 'edit' ? '(cleared)' : '')}{/if}
|
|
58
62
|
</div>
|
|
59
63
|
{/if}
|
|
60
64
|
</li>
|
|
@@ -62,28 +66,19 @@ import{onMount,untrack}from"svelte";import{getRecordRequest}from"./editor-reques
|
|
|
62
66
|
<li class="sv-frv-none">No changes or comments yet.</li>
|
|
63
67
|
{/each}
|
|
64
68
|
</ol>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
<textarea
|
|
73
|
-
bind:this={commentBox}
|
|
74
|
-
rows="2"
|
|
75
|
-
placeholder="Leave a comment"
|
|
76
|
-
aria-label="Leave a comment"
|
|
77
|
-
bind:value={comment}
|
|
78
|
-
onkeydown={(e) => {
|
|
79
|
-
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
|
|
80
|
-
e.preventDefault()
|
|
81
|
-
send()
|
|
82
|
-
}
|
|
69
|
+
|
|
70
|
+
{#if !readOnly}
|
|
71
|
+
<form
|
|
72
|
+
class="sv-frv-comment"
|
|
73
|
+
onsubmit={(e) => {
|
|
74
|
+
e.preventDefault()
|
|
75
|
+
send()
|
|
83
76
|
}}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
>
|
|
78
|
+
<MentionInput bind:value={comment} bind:picked bind:box={commentBox} onSubmit={send} />
|
|
79
|
+
<button type="submit" class="sv-frv-btn" disabled={!comment.trim()}>Comment</button>
|
|
80
|
+
</form>
|
|
81
|
+
{/if}
|
|
87
82
|
</aside>
|
|
88
83
|
</div>
|
|
89
84
|
{/if}
|
|
@@ -110,5 +105,5 @@ import{onMount,untrack}from"svelte";import{getRecordRequest}from"./editor-reques
|
|
|
110
105
|
</SvModal>
|
|
111
106
|
|
|
112
107
|
<style>
|
|
113
|
-
.sv-frv-layout{display:grid;grid-template-columns:minmax(0,1fr) 280px;gap:20px;align-items:start}.sv-frv-fields{display:flex;flex-direction:column;gap:14px;min-width:0}.sv-frv-field{display:flex;flex-direction:column;gap:6px}.sv-frv-label{display:flex;align-items:center;gap:6px;font-size:12px;font-weight:600;color:var(--sg-muted, #64748b)}.sv-frv-ro{font-weight:400;font-size:11px;opacity:.8}.sv-frv-hidden-toggle{align-self:flex-start;border:0;padding:2px 0;background:none;font:inherit;font-size:13px;color:var(--sg-accent, #2563eb);cursor:pointer}.sv-frv-activity{position:sticky;top:0;display:flex;flex-direction:column;gap:8px;max-height:70vh;padding-inline-start:16px;border-inline-start:1px solid var(--sg-border, #e2e8f0)}.sv-frv-activity-title{margin:0;font-size:13px;font-weight:600}.sv-frv-feed{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px;overflow:auto;min-height:60px}.sv-frv-item{font-size:12px}.sv-frv-item-head{color:var(--sg-muted, #64748b)}.sv-frv-item-head strong{color:var(--sg-fg, #0f172a);font-weight:600}.sv-frv-from{color:var(--sg-muted, #64748b);text-decoration:line-through}.sv-frv-arrow{margin:0 5px;color:var(--sg-muted, #64748b)}.sv-frv-when{margin-inline-start:6px;opacity:.8}.sv-frv-item-body{margin-top:2px;white-space:pre-wrap;word-break:break-word}.sv-frv-item.is-comment .sv-frv-item-body{padding:6px 8px;border-radius:8px;background:color-mix(in srgb,var(--sg-fg, #0f172a) 5%,transparent)}.sv-frv-none{color:var(--sg-muted, #64748b);font-size:12px}.sv-frv-comment{display:grid;gap:6px}.sv-frv-
|
|
108
|
+
.sv-frv-layout{display:grid;grid-template-columns:minmax(0,1fr) 280px;gap:20px;align-items:start}.sv-frv-fields{display:flex;flex-direction:column;gap:14px;min-width:0}.sv-frv-field{display:flex;flex-direction:column;gap:6px}.sv-frv-label{display:flex;align-items:center;gap:6px;font-size:12px;font-weight:600;color:var(--sg-muted, #64748b)}.sv-frv-ro{font-weight:400;font-size:11px;opacity:.8}.sv-frv-hidden-toggle{align-self:flex-start;border:0;padding:2px 0;background:none;font:inherit;font-size:13px;color:var(--sg-accent, #2563eb);cursor:pointer}.sv-frv-activity{position:sticky;top:0;display:flex;flex-direction:column;gap:8px;max-height:70vh;padding-inline-start:16px;border-inline-start:1px solid var(--sg-border, #e2e8f0)}.sv-frv-activity-title{margin:0;font-size:13px;font-weight:600}.sv-frv-feed{list-style:none;margin:0;padding:0;display:flex;flex-direction:column;gap:10px;overflow:auto;min-height:60px}.sv-frv-item{font-size:12px}.sv-frv-item-head{color:var(--sg-muted, #64748b)}.sv-frv-item-head strong{color:var(--sg-fg, #0f172a);font-weight:600}.sv-frv-from{color:var(--sg-muted, #64748b);text-decoration:line-through}.sv-frv-arrow{margin:0 5px;color:var(--sg-muted, #64748b)}.sv-frv-when{margin-inline-start:6px;opacity:.8}.sv-frv-item-body{margin-top:2px;white-space:pre-wrap;word-break:break-word}.sv-frv-item.is-comment .sv-frv-item-body{padding:6px 8px;border-radius:8px;background:color-mix(in srgb,var(--sg-fg, #0f172a) 5%,transparent)}.sv-frv-none{color:var(--sg-muted, #64748b);font-size:12px}.sv-frv-comment{display:grid;gap:6px}.sv-frv-mention{display:inline-flex;align-items:center;gap:3px;padding:0 5px 0 2px;border-radius:999px;vertical-align:baseline;font-weight:600;color:var(--sg-accent, #2563eb);background:color-mix(in srgb,var(--sg-accent, #2563eb) 12%,transparent)}.sv-frv-comment .sv-frv-btn{justify-self:end}.sv-frv-gone{color:var(--sg-muted, #64748b)}.sv-frv-footer{display:flex;align-items:center;gap:6px;width:100%}.sv-frv-pos{flex:1;font-size:13px;color:var(--sg-muted, #64748b)}.sv-frv-btn{display:inline-flex;align-items:center;justify-content:center;height:32px;min-width:32px;padding:0 12px;font:inherit;font-size:13px;cursor:pointer;border:1px solid var(--sg-border, #e2e8f0);border-radius:var(--sg-radius, 6px);background:var(--sg-bg, #fff);color:var(--sg-fg, #0f172a)}.sv-frv-btn:disabled{opacity:.4;cursor:default}.sv-frv-btn.is-primary{background:var(--sg-fg, #0f172a);color:var(--sg-bg, #fff);border-color:var(--sg-fg, #0f172a)}@media(max-width:760px){.sv-frv-layout{grid-template-columns:minmax(0,1fr)}.sv-frv-activity{position:static;padding-inline-start:0;border-inline-start:0;border-top:1px solid var(--sg-border, #e2e8f0);padding-top:12px}}@media(max-width:600px){:global(.sv-modal:has(.sv-frv-layout)){width:100vw!important;max-width:100vw;height:100dvh;max-height:100dvh;border-radius:0}}
|
|
114
109
|
</style>
|
|
@@ -1,20 +1,30 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import{onMount,untrack}from"svelte";import{toast}from"@svgrid/grid";import{createBaseSync}from"./base-sync";import{noteRemoteChange}from"./activity.svelte";import{registerLinkedTable,unregisterLinkedTable}from"./sources.svelte";import{gridOf}from"./grid-access";import{openRecord,closeRecord}from"./editor-request.svelte";import{addInverse,blankTable,checkLinks,colId,copyTable,fieldChanged,newRecordId,primaryOf,removeLinkField,removeTable,rowIdOf,syncAllInverses,syncInverse}from"./base-tables";import{baseToSql}from"./base-sql";import{createAutomationRunner}from"./automations.svelte";const GRID_ONLY=[{id:"grid",name:"Grid view",type:"grid"}];let{tables=$bindable(void 0),activeTable=$bindable(""),onTablesChange,data,columns,views=$bindable([{id:"grid",name:"Grid view",type:"grid"}]),activeView=$bindable(""),onViewsChange,viewTypes,rowHeights,containerHeight=560,onApiReady,serverRuns,automations=true,onRemoteChange,...grid}=$props();const current=$derived(tables?tables.find(t=>t.id===activeTable)??tables[0]:void 0);const currentId=$derived(current?.id??"");let api=$state.raw(null);let gridData=$state.raw(current?.data??[]);let shownId=current?.id??"";let pendingOpen=null;let viewOf=$state(Object.fromEntries((tables??[]).map(t=>[t.id,""])));$effect.pre(()=>{const t=current;if(!t)return;untrack(()=>{if(viewOf[t.id]===void 0)viewOf[t.id]="";if(t.id===shownId)return;shownId=t.id;gridData=t.data;if(activeTable!==t.id)activeTable=t.id})});const height=$derived(typeof containerHeight==="number"?`${containerHeight}px`:containerHeight);const tableOf=id=>tables?.find(t=>t.id===id);function commit(next){const before=tables;put(next);sync.push(next);linkedChanges(before,next)}function linkedChanges(prev,next){if(!prev)return;for(const t of next){if(t.id===current?.id||t.id===chainWrote||!(t.automations??[]).length)continue;const old=prev.find(x=>x.id===t.id);if(!old||old.data===t.data)continue;const byId=new Map(old.data.map(r=>[rowIdOf(old,r),r]));for(const r of t.data){const was=byId.get(rowIdOf(t,r));if(!was||was===r)continue;const fields=t.columns.filter(d=>d.field!=null&&JSON.stringify(was[String(d.field)]??null)!==JSON.stringify(r[String(d.field)]??null)).map(d=>colId(d));if(fields.length)void runner.handle({type:"updated",table:t.id,record:r,before:was,fields,depth:chainDepth})}}}function put(next){const before=current;tables=next;const after=next.find(t=>t.id===before?.id);if(after&&before&&after.data!==before.data&&after.data!==liveRows())gridData=after.data;onTablesChange?.(next)}let syncState=$state({state:"idle"});let savedOnce=$state(false);const sync=createBaseSync({getTables:()=>tables?pulled():void 0,apply:put,onStatus:s=>{if(s.state==="saving")savedOnce=true;syncState=s},onError:e=>toast.error(`Could not ${e.action==="load"?"load":"save"} ${e.table}: ${e.message}`),onRemoteChange:list=>{for(const c of list)noteRemote(c);onRemoteChange?.(list)}});const STAMPS=new Set(["createdTime","createdBy","lastModifiedTime","lastModifiedBy","autoNumber"]);function authorOf(t,record,added){const order=added?["createdBy","lastModifiedBy"]:["lastModifiedBy"];for(const type of order){const d=t.columns.find(x=>x.fieldType===type&&x.field!=null);const v=d?record[String(d.field)]:void 0;if(v!=null&&v!=="")return String(v)}return void 0}function noteRemote(c){const t=tableOf(c.table);if(!t||c.type==="delete")return;const scope={base:baseScope,tableId:t.id};const by=authorOf(t,c.record,c.type==="insert");if(c.type==="insert")return noteRemoteChange(scope,c.id,{by,added:true});const fields=(c.fields??[]).flatMap(f=>{const d=t.columns.find(x=>x.field!=null&&String(x.field)===f.field);return d&&!STAMPS.has(d.fieldType)?[{columnId:colId(d),from:f.from,to:f.to}]:[]});noteRemoteChange(scope,c.id,{by,fields})}onMount(()=>{void sync.load();return()=>{sync.dispose();runner.stop()}});let chainDepth=0;let chainWrote;const baseScope={};const runner=createAutomationRunner({scope:baseScope,getTables:()=>tables?pulled():void 0,apply:(next,depth=0,wrote)=>{chainDepth=depth;chainWrote=wrote;try{commit(next)}finally{chainDepth=0;chainWrote=void 0}}});$effect(()=>{void tables?.map(t=>t.automations);untrack(()=>runner.schedule())});const touched=new Map;function noteUpdate(tableId,record,columnId,oldValue){const t=tableOf(tableId);if(!t||!record)return;const key=`${tableId}:${rowIdOf(t,record)}`;let hit=touched.get(key);if(!hit){hit={table:tableId,record,before:{...record},fields:new Set};touched.set(key,hit);if(touched.size===1)queueMicrotask(flushTouched)}const field=t.columns.find(d=>colId(d)===columnId)?.field;if(field!=null&&!hit.fields.has(columnId))hit.before[String(field)]=oldValue;hit.fields.add(columnId)}function flushTouched(){const list=[...touched.values()];touched.clear();for(const u of list)void runner.handle({type:"updated",table:u.table,record:u.record,before:u.before,fields:[...u.fields]})}function buttonFor(tableId,columnId){const on=(tableOf(tableId)?.automations??[]).some(a=>a.enabled&&a.trigger.type==="button"&&a.trigger.field===columnId);return on?row=>void runner.handle({type:"button",table:tableId,record:row,field:columnId}):null}const syncLine=$derived.by(()=>{const s=syncState;if(!tables?.some(t=>t.source))return null;if(s.state==="loading")return{text:"Loading records…"};if(s.state==="saving")return{text:"Saving…"};if(s.state==="error")return{text:`Not saved: ${s.message}`,tone:"error",title:`${s.table}: ${s.message}`};if(s.state==="limited")return{text:`${s.table}: the first ${s.limit.toLocaleString()} records`};return savedOnce?{text:"All changes saved"}:null});function liveRows(){return api?gridOf(api)?.internalData:void 0}function pulled(change={}){const list=tables??[];const id=current?.id;const live=liveRows();return list.map(t=>t.id===id?{...t,...live?{data:live}:{},...change}:t)}function switchTo(id){if(!tables||id===current?.id)return;commit(pulled());show(id)}function show(id){const t=tableOf(id);if(!t)return;closeRecord();api=null;if(viewOf[id]===void 0)viewOf[id]="";shownId=id;gridData=t.data;activeTable=id}const linkFieldOf=(t,id)=>t?.columns.find(d=>colId(d)===id&&d.fieldType==="link");function call(name,e){;current?.props?.[name]?.(e);grid[name]?.(e)}const handlers={onColumnAdd:e=>{const id=current.id;let next=pulled({columns:e.columns,...e.data?{data:e.data}:{}});if(e.column?.fieldType==="link")next=addInverse(next,id,colId(e.column));commit(next);call("onColumnAdd",e)},onColumnChange:e=>{const id=current.id;let next=pulled({columns:e.columns,...e.data?{data:e.data}:{}});if(e.previous?.fieldType==="link"||e.column?.fieldType==="link")next=fieldChanged(next,id,e.previous,colId(e.column));commit(next);call("onColumnChange",e)},onColumnRemove:e=>{const removed=linkFieldOf(current,e.columnId);commit(removeLinkField(pulled({columns:e.columns}),current.id,removed));call("onColumnRemove",e)},onCellValueChange:e=>{const id=current.id;const next=pulled();commit(linkFieldOf(current,e.columnId)?.fieldProps?.inverse?syncInverse(next,id,e.columnId):next);noteUpdate(id,e.row,e.columnId,e.oldValue);call("onCellValueChange",e)},onRowAdd:e=>{const id=current.id;commit(syncAllInverses(pulled(),id));if(e?.row)void runner.handle({type:"created",table:id,record:e.row});call("onRowAdd",e)},onRowsDelete:e=>{commit(syncAllInverses(pulled({data:e.data}),current.id));call("onRowsDelete",e)}};function createIn(id,name){const t=tableOf(id);const row={id:newRecordId(),[primaryOf(t)]:name};if(id===current?.id&&api){api.addRow(row,"bottom");commit(pulled())}else{commit(pulled().map(x=>x.id===id?{...x,data:[...x.data,row]}:x))}return row}function openIn(id,rowId){if(id===current?.id){const ctrl=api?gridOf(api):null;if(ctrl)openRecord({ctrl,rowId});return}pendingOpen=rowId;switchTo(id)}const registered=new Map;const owner={};onMount(()=>{if(tables)checkLinks(tables);return()=>{for(const id of registered.keys())unregisterLinkedTable(id,owner)}});$effect(()=>{const list=tables;if(!list)return;for(const t of list){const primary=primaryOf(t);const seen=registered.get(t.id);if(seen&&seen.name===t.name&&seen.columns===t.columns&&seen.primary===primary)continue;registered.set(t.id,{name:t.name,columns:t.columns,primary});const id=t.id;registerLinkedTable({id,name:t.name,rows:()=>id===current?.id?liveRows()??tableOf(id)?.data??[]:tableOf(id)?.data??[],getRowId:r=>{const own=tableOf(id);return own?rowIdOf(own,r):String(r.id??"")},primaryField:primary,fields:t.columns.filter(d=>d.field).map(d=>({field:String(d.field),header:String(d.header??d.field),fieldType:d.fieldType,fieldProps:d.fieldProps})),create:name=>createIn(id,name),open:rowId=>openIn(id,rowId)},owner)}for(const id of[...registered.keys()]){if(list.some(t=>t.id===id))continue;registered.delete(id);unregisterLinkedTable(id,owner)}});function addTable(){const list=pulled();const t=blankTable(list);commit([...list,t]);switchTo(t.id)}function renameTable(id,name){commit(pulled().map(t=>t.id===id?{...t,name}:t))}function duplicateTable(id){const list=pulled();const source=list.find(t=>t.id===id);if(!source)return;const copy=copyTable(list,source);let next=[...list,copy];for(const d of copy.columns)if(d.fieldType==="link")next=addInverse(next,copy.id,colId(d));commit(next);switchTo(copy.id)}function exportSql(){const list=pulled();const sql=baseToSql(list,{title:list.map(t=>t.name).join(", ")});const url=URL.createObjectURL(new Blob([sql],{type:"application/sql"}));const a=document.createElement("a");a.href=url;a.download="base.sql";a.click();setTimeout(()=>URL.revokeObjectURL(url),1e3)}function deleteTable(id){const list=pulled();if(list.length<2)return;const i=list.findIndex(t=>t.id===id);const next=removeTable(list,id);const shown=id===current?.id;commit(next);if(shown)show(next[Math.max(0,i-1)].id)}const singleRowId=(r,i)=>grid.getRowId?grid.getRowId(r,i):r?.id!=null&&r.id!==""?String(r.id):String(i);const gridProps=$derived.by(()=>{const id=currentId;if(!id)return{};const t=untrack(()=>tableOf(id));if(!t)return{};const own=t.props??{};const adder=own.rowAdder??grid.rowAdder??true;const rowAdder=adder===false?false:{...typeof adder==="object"?adder:{},defaults:()=>({id:newRecordId(),...typeof adder==="object"&&typeof adder.defaults==="function"?adder.defaults():{}})};return{...grid,...own,...handlers,rowAdder,primaryField:primaryOf(t),getRowId:r=>rowIdOf(tableOf(id)??t,r),baseTableId:id,baseScope,fieldButtons:columnId=>buttonFor(id,columnId)}});
|
|
2
|
+
import{onMount,untrack}from"svelte";import{hasGanttView,toast}from"@svgrid/grid";import{createBaseSync}from"./base-sync";import{noteRemoteChange}from"./activity.svelte";import{registerLinkedTable,unregisterLinkedTable}from"./sources.svelte";import{gridOf}from"./grid-access";import{openRecord,closeRecord}from"./editor-request.svelte";import{addInverse,blankTable,checkLinks,colId,copyTable,fieldChanged,newRecordId,primaryOf,removeLinkField,removeTable,rowIdOf,syncAllInverses,syncInverse}from"./base-tables";import{baseToSql}from"./base-sql";import{createAutomationRunner}from"./automations.svelte";import{claimBase,forgetBase,nextStepLabel,pushUndoStep,records,snapshot,takeHistory,usedLast}from"./base-history";import{cannotRestore,freshTrash,restoreItems,trashField,trashLabel,trashRecords,trashTable}from"./base-trash";import{getCurrentUser}from"./sources.svelte";import{releaseCanEditField,setCanEditField,setFieldProtection}from"./field-access.svelte";import{readOnlySelectionBar,shareOf,sharedTables,sharedViews}from"./base-share";import{searchBase}from"./base-search";const GRID_ONLY=[{id:"grid",name:"Grid view",type:"grid"}];let{tables=$bindable(void 0),activeTable=$bindable(""),onTablesChange,data,columns,views=$bindable([{id:"grid",name:"Grid view",type:"grid"}]),activeView=$bindable(""),onViewsChange,viewTypes,rowHeights,containerHeight=560,onApiReady,serverRuns,automations=true,onRemoteChange,undoRedo=true,trash=$bindable([]),onTrashChange,trashDays=30,fileImport=true,canEditField,protectFields=true,readOnly=false,search=true,...grid}=$props();if(canEditField)setCanEditField(canEditField);setFieldProtection(protectFields);$effect.pre(()=>{const fn=canEditField;if(fn)setCanEditField(fn);return()=>{if(fn)releaseCanEditField(fn)}});$effect.pre(()=>setFieldProtection(protectFields));const share=$derived(shareOf(readOnly));const shown=$derived(tables&&share?sharedTables(tables,share):tables);let localViews=$state({});const single=$derived(!tables&&share?sharedTables([{id:"",name:"",data:data??[],columns:columns??[],views,primaryField:grid.primaryField}],{...share,tables:void 0})[0]:void 0);let singleViews=$state.raw(sharedViews(views,shareOf(readOnly)??{})??GRID_ONLY);const LOCKED={editable:false,columnAdder:false,rowAdder:false,rowDragManaged:false,baseReadOnly:true};const lockedGrid=props=>({...props,...LOCKED,selectionBar:readOnlySelectionBar(props.selectionBar)});const shareTypes=$derived((viewTypes??["grid","kanban","calendar",...hasGanttView()?["gantt"]:[],"gallery","chart"]).filter(t=>t!=="form"));const current=$derived(shown?shown.find(t=>t.id===activeTable)??shown[0]:void 0);const currentId=$derived(current?.id??"");let api=$state.raw(null);let gridData=$state.raw(current?.data??[]);let shownId=current?.id??"";let pendingOpen=null;let viewOf=$state(Object.fromEntries((tables??[]).map(t=>[t.id,""])));$effect.pre(()=>{const t=current;if(!t)return;untrack(()=>{if(viewOf[t.id]===void 0)viewOf[t.id]="";if(t.id===shownId)return;shownId=t.id;gridData=t.data;if(activeTable!==t.id)activeTable=t.id})});const height=$derived(typeof containerHeight==="number"?`${containerHeight}px`:containerHeight);const tableOf=id=>tables?.find(t=>t.id===id);function commit(next){if(share)return;const before=tables;put(next);sync.push(next);linkedChanges(before,next)}function linkedChanges(prev,next){if(!prev)return;for(const t of next){if(t.id===current?.id||t.id===chainWrote||!(t.automations??[]).length)continue;const old=prev.find(x=>x.id===t.id);if(!old||old.data===t.data)continue;const byId=new Map(old.data.map(r=>[rowIdOf(old,r),r]));for(const r of t.data){const was=byId.get(rowIdOf(t,r));if(!was||was===r)continue;const fields=t.columns.filter(d=>d.field!=null&&JSON.stringify(was[String(d.field)]??null)!==JSON.stringify(r[String(d.field)]??null)).map(d=>colId(d));if(fields.length)void runner.handle({type:"updated",table:t.id,record:r,before:was,fields,depth:chainDepth})}}}function put(next){const before=current;tables=next;lastSnap=snapshot(next);const after=next.find(t=>t.id===before?.id);if(after&&before&&after.data!==before.data&&after.data!==liveRows())gridData=after.data;onTablesChange?.(next)}let syncState=$state({state:"idle"});let savedOnce=$state(false);const sync=createBaseSync({getTables:()=>tables?pulled():void 0,apply:put,onStatus:s=>{if(s.state==="saving")savedOnce=true;syncState=s},onError:e=>toast.error(`Could not ${e.action==="load"?"load":"save"} ${e.table}: ${e.message}`),onRemoteChange:list=>{for(const c of list)noteRemote(c);onRemoteChange?.(list)}});const STAMPS=new Set(["createdTime","createdBy","lastModifiedTime","lastModifiedBy","autoNumber"]);function authorOf(t,record,added){const order=added?["createdBy","lastModifiedBy"]:["lastModifiedBy"];for(const type of order){const d=t.columns.find(x=>x.fieldType===type&&x.field!=null);const v=d?record[String(d.field)]:void 0;if(v!=null&&v!=="")return String(v)}return void 0}function noteRemote(c){const t=tableOf(c.table);if(!t||c.type==="delete")return;const scope={base:baseScope,tableId:t.id};const by=authorOf(t,c.record,c.type==="insert");if(c.type==="insert")return noteRemoteChange(scope,c.id,{by,added:true});const fields=(c.fields??[]).flatMap(f=>{const d=t.columns.find(x=>x.field!=null&&String(x.field)===f.field);return d&&!STAMPS.has(d.fieldType)?[{columnId:colId(d),from:f.from,to:f.to}]:[]});noteRemoteChange(scope,c.id,{by,fields})}onMount(()=>{void sync.load();return()=>{sync.dispose();runner.stop()}});let chainDepth=0;let chainWrote;const baseScope={};const runner=createAutomationRunner({scope:baseScope,getTables:()=>tables?pulled():void 0,apply:(next,depth=0,wrote)=>{chainDepth=depth;chainWrote=wrote;try{commit(next)}finally{chainDepth=0;chainWrote=void 0}}});$effect(()=>{void tables?.map(t=>t.automations);if(share)return;untrack(()=>runner.schedule())});const touched=new Map;function noteUpdate(tableId,record,columnId,oldValue){const t=tableOf(tableId);if(!t||!record)return;const key=`${tableId}:${rowIdOf(t,record)}`;let hit=touched.get(key);if(!hit){hit={table:tableId,record,before:{...record},fields:new Set};touched.set(key,hit);if(touched.size===1)queueMicrotask(flushTouched)}const field=t.columns.find(d=>colId(d)===columnId)?.field;if(field!=null&&!hit.fields.has(columnId))hit.before[String(field)]=oldValue;hit.fields.add(columnId)}function flushTouched(){const list=[...touched.values()];touched.clear();for(const u of list)void runner.handle({type:"updated",table:u.table,record:u.record,before:u.before,fields:[...u.fields]})}function buttonFor(tableId,columnId){const on=(tableOf(tableId)?.automations??[]).some(a=>a.enabled&&a.trigger.type==="button"&&a.trigger.field===columnId);return on?row=>void runner.handle({type:"button",table:tableId,record:row,field:columnId}):null}const syncLine=$derived.by(()=>{const s=syncState;if(!tables?.some(t=>t.source))return null;if(s.state==="loading")return{text:"Loading records…"};if(s.state==="saving")return{text:"Saving…"};if(s.state==="error")return{text:`Not saved: ${s.message}`,tone:"error",title:`${s.table}: ${s.message}`};if(s.state==="limited")return{text:`${s.table}: the first ${s.limit.toLocaleString()} records`};return savedOnce?{text:"All changes saved"}:null});function liveRows(){return api?gridOf(api)?.internalData:void 0}function pulled(change={}){const list=tables??[];const id=current?.id;const live=liveRows();return list.map(t=>t.id===id?{...t,...live?{data:live}:{},...change}:t)}function switchTo(id){if(!tables||id===current?.id)return;commit(pulled());show(id)}function show(id){const t=shown?.find(x=>x.id===id);if(!t)return;closeRecord();const kept=api?takeHistory(gridOf(api)):void 0;if(kept)keptHistory.set(shownId,kept);api=null;if(viewOf[id]===void 0)viewOf[id]="";shownId=id;gridData=t.data;activeTable=id}const linkFieldOf=(t,id)=>t?.columns.find(d=>colId(d)===id&&d.fieldType==="link");let lastSnap=snapshot(tables??[]);const keptHistory=new Map;function recordStep(label,before,after,also){const ctrl=api?gridOf(api):void 0;if(!ctrl)return;pushUndoStep(ctrl,label,()=>{restoreTo(before);also?.undo()},()=>{restoreTo(after);also?.redo()})}function restoreTo(snap){const byId=new Map(snap.map(t=>[t.id,t]));commit(pulled().map(t=>{const was=byId.get(t.id);return was?{...t,data:was.data.slice(),columns:was.columns}:t}))}const me=()=>getCurrentUser()?.id;function setTrash(next){trash=next;onTrashChange?.(next)}function addTrash(items){if(items.length)setTrash([...items,...trash])}function dropTrash(ids){const gone=new Set(ids);if(trash.some(i=>gone.has(i.id)))setTrash(trash.filter(i=>!gone.has(i.id)))}onMount(()=>{const kept=freshTrash(trash,trashDays);if(kept.length!==trash.length)setTrash(kept)});function restoreFromTrash(ids){const want=new Set(ids);const items=trash.filter(i=>want.has(i.id));if(!items.length)return;const before=lastSnap;const next=restoreItems(pulled(),items);const back=items.filter(i=>i.kind==="table"?next.some(t=>t.id===i.table.id)&&!before.some(t=>t.id===i.table.id):!cannotRestore(i,before));if(!back.length)return;commit(next);dropTrash(back.map(i=>i.id));if(!back.some(i=>i.kind==="table")){recordStep("restore from the trash",before,lastSnap,{undo:()=>addTrash(back),redo:()=>dropTrash(back.map(i=>i.id))})}toast.success(`Restored ${back.length===1?trashLabel(back[0],next):`${back.length} items`}`)}function saidDeleted(items,what){if(!items.length)return;toast(`Deleted ${what}`,{action:{label:"Restore",onClick:()=>restoreFromTrash(items.map(i=>i.id))}})}let trashOpen=$state(false);let importOpen=$state(false);let importMode=$state("new");let importFile=$state.raw(null);export function openImport(mode="new",file){importMode=mode;importFile=file??null;importOpen=true}function imported(r){if(r.mode==="new"){commit([...pulled(),r.table]);switchTo(r.table.id);toast.success(`Imported ${records(r.table.data.length)} into a new table, ${r.table.name}`);return}const before=lastSnap;commit(pulled().map(t=>t.id===r.table?{...t,columns:r.columns,data:[...t.data,...r.rows]}:t));recordStep(`import ${records(r.rows.length)}`,before,lastSnap);toast.success(`Imported ${records(r.rows.length)} into ${tableOf(r.table)?.name??"the table"}`)}const undoBar=$derived.by(()=>{if(!undoRedo||!api)return null;const a=api;const ctrl=gridOf(a);return{canUndo:!!a.canUndo?.(),canRedo:!!a.canRedo?.(),undoLabel:nextStepLabel(ctrl,"undo"),redoLabel:nextStepLabel(ctrl,"redo"),onUndo:()=>a.undo?.(),onRedo:()=>a.redo?.()}});function undoKey(e){if(share||e.defaultPrevented||!(e.ctrlKey||e.metaKey)||e.altKey||!api)return;const k=e.key.toLowerCase();if(k!=="z"&&k!=="y")return;const target=e.target;if(target?.closest?.('input, textarea, select, [contenteditable]:not([contenteditable="false"])'))return;e.preventDefault();if(k==="z"&&!e.shiftKey)api.undo?.();else api.redo?.()}const keyOwner={};onMount(()=>{claimBase(keyOwner);return()=>forgetBase(keyOwner)});function pageKey(e){if(e.target!==document.body&&e.target!==document.documentElement)return;if(tables&&usedLast(keyOwner))undoKey(e)}let tabs=$state(null);const searchBar=$derived(search&&tables?{run:q=>searchBase(share?sharedTables(pulled(),share):pulled(),q),onPick:(table,rowId)=>openIn(table,rowId)}:null);function baseKey(e){if(!searchKey(e))undoKey(e)}function searchKey(e){if(!searchBar||e.defaultPrevented||e.altKey)return false;const target=e.target;const mod=e.ctrlKey||e.metaKey;const typing=!!target?.closest?.('input, textarea, select, [contenteditable]:not([contenteditable="false"])');const k=e.key.toLowerCase();const wanted=mod&&!e.shiftKey&&k==="k"||!mod&&e.key==="/"&&!typing&&!target?.closest?.(".sv-grid-root");if(!wanted||!tabs?.focusSearch())return false;e.preventDefault();return true}function call(name,e){;current?.props?.[name]?.(e);grid[name]?.(e)}const handlers={onColumnAdd:e=>{const id=current.id;const before=lastSnap;let next=pulled({columns:e.columns,...e.data?{data:e.data}:{}});if(e.column?.fieldType==="link")next=addInverse(next,id,colId(e.column));commit(next);recordStep(`add field ${String(e.column?.header??e.column?.field??"")}`.trim(),before,lastSnap);call("onColumnAdd",e)},onColumnChange:e=>{const id=current.id;const before=lastSnap;let next=pulled({columns:e.columns,...e.data?{data:e.data}:{}});if(e.previous?.fieldType==="link"||e.column?.fieldType==="link")next=fieldChanged(next,id,e.previous,colId(e.column));commit(next);recordStep(`change field ${String(e.column?.header??e.column?.field??"")}`.trim(),before,lastSnap);call("onColumnChange",e)},onColumnRemove:e=>{const t=current;const before=lastSnap;const index=t.columns.findIndex(d=>colId(d)===e.columnId);const def=t.columns[index];const removed=linkFieldOf(t,e.columnId);commit(removeLinkField(pulled({columns:e.columns}),t.id,removed));const items=def?[trashField(t,def,index,me())]:[];addTrash(items);const name=String(def?.header??def?.field??"a field");recordStep(`delete field ${name}`,before,lastSnap,{undo:()=>dropTrash(items.map(i=>i.id)),redo:()=>addTrash(items)});saidDeleted(items,`the field ${name}`);call("onColumnRemove",e)},onCellValueChange:e=>{const id=current.id;const next=pulled();commit(linkFieldOf(current,e.columnId)?.fieldProps?.inverse?syncInverse(next,id,e.columnId):next);noteUpdate(id,e.row,e.columnId,e.oldValue);call("onCellValueChange",e)},onRowAdd:e=>{const id=current.id;const before=lastSnap;commit(syncAllInverses(pulled(),id));recordStep("add record",before,lastSnap);if(e?.row)void runner.handle({type:"created",table:id,record:e.row});call("onRowAdd",e)},onRowsDelete:e=>{const t=current;const before=lastSnap;const was=before.find(x=>x.id===t.id)?.data??[];const ids=e.ids??(e.rows??[]).map(r=>rowIdOf(t,r));commit(syncAllInverses(pulled({data:e.data}),t.id));const items=trashRecords(t,was,ids,me());addTrash(items);recordStep(`delete ${records(ids.length)}`,before,lastSnap,{undo:()=>dropTrash(items.map(i=>i.id)),redo:()=>addTrash(items)});saidDeleted(items,items.length===1?trashLabel(items[0],tables??[]):records(items.length));call("onRowsDelete",e)}};function createIn(id,name){const t=tableOf(id);const row={id:newRecordId(),[primaryOf(t)]:name};if(id===current?.id&&api){api.addRow(row,"bottom");commit(pulled())}else{commit(pulled().map(x=>x.id===id?{...x,data:[...x.data,row]}:x))}return row}function openIn(id,rowId){if(id===current?.id){const ctrl=api?gridOf(api):null;if(ctrl)openRecord({ctrl,rowId});return}pendingOpen=rowId;switchTo(id)}const registered=new Map;const owner={};onMount(()=>{if(tables)checkLinks(tables);return()=>{for(const id of registered.keys())unregisterLinkedTable(id,owner)}});$effect(()=>{const list=shown;if(!list)return;for(const t of list){const primary=primaryOf(t);const seen=registered.get(t.id);if(seen&&seen.name===t.name&&seen.columns===t.columns&&seen.primary===primary)continue;registered.set(t.id,{name:t.name,columns:t.columns,primary});const id=t.id;registerLinkedTable({id,name:t.name,rows:()=>id===current?.id?liveRows()??tableOf(id)?.data??[]:tableOf(id)?.data??[],getRowId:r=>{const own=tableOf(id);return own?rowIdOf(own,r):String(r.id??"")},primaryField:primary,fields:t.columns.filter(d=>d.field).map(d=>({field:String(d.field),header:String(d.header??d.field),fieldType:d.fieldType,fieldProps:d.fieldProps})),create:name=>createIn(id,name),open:rowId=>openIn(id,rowId)},owner)}for(const id of[...registered.keys()]){if(list.some(t=>t.id===id))continue;registered.delete(id);unregisterLinkedTable(id,owner)}});function addTable(){const list=pulled();const t=blankTable(list);commit([...list,t]);switchTo(t.id)}function renameTable(id,name){commit(pulled().map(t=>t.id===id?{...t,name}:t))}function duplicateTable(id){const list=pulled();const source=list.find(t=>t.id===id);if(!source)return;const copy=copyTable(list,source);let next=[...list,copy];for(const d of copy.columns)if(d.fieldType==="link")next=addInverse(next,copy.id,colId(d));commit(next);switchTo(copy.id)}function exportSql(){const list=pulled();const sql=baseToSql(list,{title:list.map(t=>t.name).join(", ")});const url=URL.createObjectURL(new Blob([sql],{type:"application/sql"}));const a=document.createElement("a");a.href=url;a.download="base.sql";a.click();setTimeout(()=>URL.revokeObjectURL(url),1e3)}function deleteTable(id){const list=pulled();if(list.length<2)return;const i=list.findIndex(t=>t.id===id);const next=removeTable(list,id);const shown2=id===current?.id;const items=[trashTable(list[i],i,me())];commit(next);keptHistory.delete(id);addTrash(items);if(shown2)show(next[Math.max(0,i-1)].id);saidDeleted(items,`the table ${list[i].name}`)}const singleRowId=(r,i)=>grid.getRowId?grid.getRowId(r,i):r?.id!=null&&r.id!==""?String(r.id):String(i);const gridProps=$derived.by(()=>{const id=currentId;if(!id)return{};const t=untrack(()=>tableOf(id));if(!t)return{};const locked=!!share;const own=t.props??{};const adder=own.rowAdder??grid.rowAdder??true;const rowAdder=adder===false?false:{...typeof adder==="object"?adder:{},defaults:()=>({id:newRecordId(),...typeof adder==="object"&&typeof adder.defaults==="function"?adder.defaults():{}})};const props={...grid,...own,...handlers,rowAdder,primaryField:primaryOf(t),getRowId:r=>rowIdOf(tableOf(id)??t,r),baseTableId:id,baseScope,fieldButtons:columnId=>locked?null:buttonFor(id,columnId)};return locked?lockedGrid(props):props});
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
|
+
<svelte:window onkeydown={pageKey} />
|
|
6
|
+
|
|
5
7
|
|
|
6
8
|
{#if tables}
|
|
7
|
-
|
|
9
|
+
|
|
10
|
+
<div class="sv-fbase-tables" style:height onkeydown={baseKey} onpointerdown={() => useBase(keyOwner)} onfocusin={() => useBase(keyOwner)}>
|
|
8
11
|
<BaseTabs
|
|
9
|
-
{
|
|
12
|
+
bind:this={tabs}
|
|
13
|
+
tables={shown ?? []}
|
|
10
14
|
activeId={current?.id ?? ''}
|
|
11
15
|
onSwitch={switchTo}
|
|
12
16
|
onAdd={addTable}
|
|
13
17
|
onRename={renameTable}
|
|
14
18
|
onDuplicate={duplicateTable}
|
|
15
19
|
onDelete={deleteTable}
|
|
16
|
-
onExportSql={exportSql}
|
|
20
|
+
onExportSql={share ? undefined : exportSql}
|
|
17
21
|
status={syncLine}
|
|
22
|
+
undo={share ? null : undoBar}
|
|
23
|
+
trashCount={trash.length}
|
|
24
|
+
onOpenTrash={share ? undefined : () => (trashOpen = true)}
|
|
25
|
+
onImport={fileImport && !share ? openImport : undefined}
|
|
26
|
+
readOnly={!!share}
|
|
27
|
+
search={searchBar}
|
|
18
28
|
/>
|
|
19
29
|
<div class="sv-fbase-slot">
|
|
20
30
|
{#if current}
|
|
@@ -24,22 +34,29 @@ import{onMount,untrack}from"svelte";import{toast}from"@svgrid/grid";import{creat
|
|
|
24
34
|
bare
|
|
25
35
|
data={gridData}
|
|
26
36
|
columns={current.columns}
|
|
27
|
-
views={current.views
|
|
37
|
+
views={(share && localViews[current.id]) || current.views || GRID_ONLY}
|
|
28
38
|
bind:activeView={viewOf[current.id]}
|
|
29
|
-
onViewsChange={(v: FieldView[]) => commit(pulled({ views: v }))}
|
|
39
|
+
onViewsChange={(v: FieldView[]) => (share ? (localViews[current!.id] = v) : commit(pulled({ views: v })))}
|
|
30
40
|
table={current}
|
|
31
41
|
tables={() => pulled()}
|
|
32
|
-
runner={automations ? runner : undefined}
|
|
42
|
+
runner={automations && !share ? runner : undefined}
|
|
33
43
|
{serverRuns}
|
|
34
44
|
onAutomationsChange={(list: BaseAutomation[]) => commit(pulled({ automations: list }))}
|
|
35
45
|
onFormSubmit={(row: Row, viewId: string) => void runner.handle({ type: 'form', table: current!.id, record: row, view: viewId })}
|
|
36
46
|
newRecord={() => ({ id: newRecordId() })}
|
|
37
|
-
{viewTypes}
|
|
47
|
+
viewTypes={share ? shareTypes : viewTypes}
|
|
48
|
+
lockViews={!share}
|
|
38
49
|
{rowHeights}
|
|
39
50
|
containerHeight="100%"
|
|
40
51
|
onApiReady={(a: any) => {
|
|
41
52
|
api = a
|
|
42
53
|
onApiReady?.(a)
|
|
54
|
+
const tableId = current!.id
|
|
55
|
+
const history = keptHistory.get(tableId)
|
|
56
|
+
if (history) queueMicrotask(() => {
|
|
57
|
+
keptHistory.delete(tableId)
|
|
58
|
+
giveHistory(gridOf(a), history)
|
|
59
|
+
})
|
|
43
60
|
const rowId = pendingOpen
|
|
44
61
|
pendingOpen = null
|
|
45
62
|
if (rowId) queueMicrotask(() => {
|
|
@@ -52,10 +69,32 @@ import{onMount,untrack}from"svelte";import{toast}from"@svgrid/grid";import{creat
|
|
|
52
69
|
{/if}
|
|
53
70
|
</div>
|
|
54
71
|
</div>
|
|
72
|
+
{#if !share}
|
|
73
|
+
<BaseTrash bind:open={trashOpen} items={trash} {tables} days={trashDays} onRestore={restoreFromTrash} onDelete={dropTrash} onEmpty={() => setTrash([])} />
|
|
74
|
+
{/if}
|
|
75
|
+
{#if fileImport && !share}
|
|
76
|
+
<BaseImport bind:open={importOpen} bind:mode={importMode} file={importFile} {tables} {current} onImport={imported} />
|
|
77
|
+
{/if}
|
|
78
|
+
{:else if single}
|
|
79
|
+
|
|
80
|
+
<BaseTableView
|
|
81
|
+
{...lockedGrid(grid)}
|
|
82
|
+
getRowId={singleRowId}
|
|
83
|
+
data={single.data}
|
|
84
|
+
columns={single.columns}
|
|
85
|
+
views={singleViews}
|
|
86
|
+
bind:activeView
|
|
87
|
+
onViewsChange={(v: FieldView[]) => (singleViews = v)}
|
|
88
|
+
viewTypes={shareTypes}
|
|
89
|
+
lockViews={false}
|
|
90
|
+
{rowHeights}
|
|
91
|
+
{containerHeight}
|
|
92
|
+
{onApiReady}
|
|
93
|
+
/>
|
|
55
94
|
{:else}
|
|
56
95
|
<BaseTableView {...grid} getRowId={singleRowId} data={data ?? []} columns={columns ?? []} bind:views bind:activeView {onViewsChange} {viewTypes} {rowHeights} {containerHeight} {onApiReady} />
|
|
57
96
|
{/if}
|
|
58
97
|
|
|
59
98
|
<style>
|
|
60
|
-
.sv-fbase-tables{display:flex;flex-direction:column;min-height:0;box-sizing:border-box;overflow:hidden;border:1px solid var(--sg-border, #e2e8f0);border-radius:var(--sg-radius-lg, 10px);background:var(--sg-bg, #fff)}.sv-fbase-slot{flex:1 1 auto;min-height:0}
|
|
99
|
+
.sv-fbase-tables{display:flex;flex-direction:column;min-height:0;box-sizing:border-box;overflow:hidden;border:1px solid var(--sg-border, #e2e8f0);border-radius:var(--sg-radius-lg, 10px);background:var(--sg-bg, #fff);container-type:inline-size}.sv-fbase-slot{flex:1 1 auto;min-height:0}
|
|
61
100
|
</style>
|
|
@@ -2,6 +2,9 @@ import { type BaseRemoteChange } from './base-sync.js';
|
|
|
2
2
|
import { type BaseTable } from './base-tables.js';
|
|
3
3
|
import type { FieldView, FieldViewType } from './view-model.js';
|
|
4
4
|
import { type AutomationRun } from './automations.svelte.js';
|
|
5
|
+
import { type BaseTrashItem } from './base-trash.js';
|
|
6
|
+
import { type CanEditField } from './field-access.svelte.js';
|
|
7
|
+
import { type BaseShare } from './base-share.js';
|
|
5
8
|
type $$ComponentProps = {
|
|
6
9
|
/** Several tables, shown as tabs. Without it, `data` and `columns` are the one table. */
|
|
7
10
|
tables?: BaseTable[];
|
|
@@ -26,8 +29,37 @@ type $$ComponentProps = {
|
|
|
26
29
|
automations?: boolean;
|
|
27
30
|
/** Changes made in the database by someone else, once they are in the page (tables with a `source` that has `realtime`). */
|
|
28
31
|
onRemoteChange?: (changes: BaseRemoteChange[]) => void;
|
|
32
|
+
/** Undo and Redo buttons in the tab bar (default true). Ctrl+Z works either way. */
|
|
33
|
+
undoRedo?: boolean;
|
|
34
|
+
/** Deleted records, fields and tables, to restore (bind it, or keep it with `onTrashChange`, to store it). */
|
|
35
|
+
trash?: BaseTrashItem[];
|
|
36
|
+
onTrashChange?: (trash: BaseTrashItem[]) => void;
|
|
37
|
+
/** Days an item stays in the trash (0: until it is emptied). Default 30. */
|
|
38
|
+
trashDays?: number;
|
|
39
|
+
/** "Import a file" in the tab bar's menus (default true). */
|
|
40
|
+
fileImport?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Who may change a field's values, in place of each field's own
|
|
43
|
+
* `fieldProps.editors` list (roles, a server's answer). Applies to every
|
|
44
|
+
* base on the page, as `setCanEditField` does.
|
|
45
|
+
*/
|
|
46
|
+
canEditField?: CanEditField;
|
|
47
|
+
/** Whether the signed-in person may set who can edit a field, in the field editor (default true). */
|
|
48
|
+
protectFields?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Look, do not touch (a share link): nothing can be edited, added or
|
|
51
|
+
* deleted, comments are read only, and view changes stay in the page.
|
|
52
|
+
* An object picks what is shown too: `{ tables, views, hideFields }`
|
|
53
|
+
* (ids; a hidden field takes the fields that read it along). Hiding is
|
|
54
|
+
* for display: send a copy without the data when it is secret.
|
|
55
|
+
*/
|
|
56
|
+
readOnly?: boolean | BaseShare;
|
|
57
|
+
/** The search box in the tab bar, over every table's records (default true; Ctrl+K focuses it). */
|
|
58
|
+
search?: boolean;
|
|
29
59
|
[prop: string]: any;
|
|
30
60
|
};
|
|
31
|
-
declare const SvBase: import("svelte").Component<$$ComponentProps, {
|
|
61
|
+
declare const SvBase: import("svelte").Component<$$ComponentProps, {
|
|
62
|
+
openImport: (mode?: "new" | "append", file?: File) => void;
|
|
63
|
+
}, "tables" | "trash" | "views" | "activeView" | "activeTable">;
|
|
32
64
|
type SvBase = ReturnType<typeof SvBase>;
|
|
33
65
|
export default SvBase;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import{untrack}from"svelte";import{
|
|
2
|
+
import{untrack}from"svelte";import{fieldColumns,gridOf,primaryIdOf}from"./grid-access";import{newRowValues}from"./field-ops";import{linkHref}from"./links";import{compileFormConditions,formPrefillKey,formValue,prefillValue,readFormPrefill,settleFormAnswers}from"./form-logic";let{api,fields,required=[],title="New record",description="",submitLabel="Submit",defaults,conditions,prefill,onSubmit}=$props();const COMPUTED=new Set(["formula","lookup","rollup","count","autoNumber","createdTime","lastModifiedTime","createdBy","lastModifiedBy","button"]);const ctrl=$derived(api?gridOf(api):void 0);const columns=$derived.by(()=>{if(!ctrl)return[];const all=fieldColumns(ctrl).filter(c=>!COMPUTED.has(c.fieldType??"")&&c.def.editable!==false&&!c.def.fieldFn);if(!fields){const p=primaryIdOf(ctrl);return[...all.filter(c=>c.id===p),...all.filter(c=>c.id!==p)]}return fields.map(id=>all.find(c=>c.id===id)).filter(c=>!!c)});function placeholderFor(c){const t=c.fieldType??"";if(t==="singleSelect"||t==="multiSelect"||t==="user")return"Choose";if(t==="date")return"Pick a date";if(t==="attachment")return"Add files";if(t==="link")return"Link records";return"Type here"}let draft=$state({});let editing=$state(null);let errors=$state({});let sent=$state(false);let busy=$state(false);let failure=$state("");let seed=null;let prefilled={};let context={};let hidden=$state.raw(new Set);let linkHidden=$state.raw(new Set);const isBlank=v=>v==null||v===""||Array.isArray(v)&&v.length===0;const tests=$derived(ctrl?compileFormConditions(conditions,fieldColumns(ctrl)):new Map);const shown=$derived(columns.filter(c=>!hidden.has(c.id)&&!linkHidden.has(c.id)));function settle(next){const out=settleFormAnswers(next,columns,tests,{initial:prefilled,context,was:hidden});hidden=out.hidden;draft=out.draft}function startRecord(){if(!ctrl)return;const cfg=ctrl.props.rowAdder;const fromAdder=cfg&&typeof cfg==="object"&&typeof cfg.defaults==="function"?cfg.defaults():{};const base={...defaults?.()??{},...fromAdder};seed=base;const start=newRowValues(ctrl,base);const next={};for(const c of columns){const v=start[c.field];if(v!==void 0&&!isBlank(v))next[c.field]=Array.isArray(v)?v.slice():v}const fromLink=readFormPrefill(prefill,columns);for(const c of columns){if(!(c.id in fromLink.values))continue;const v=prefillValue(c,fromLink.values[c.id],next);if(v!==void 0)next[c.field]=v}linkHidden=new Set(columns.filter(c=>fromLink.hide.has(c.id)&&!isBlank(next[c.field])).map(c=>c.id));const asked=new Set(columns.map(c=>c.field));context=Object.fromEntries(Object.entries(start).filter(([k])=>!asked.has(k)));prefilled={...next};hidden=new Set;settle(next)}const prefillKey=$derived(formPrefillKey(prefill));let appliedKey=null;$effect.pre(()=>{const key=prefillKey;if(!ctrl||seed&&key===appliedKey)return;untrack(()=>{const fresh=!seed;appliedKey=key;if(fresh)startRecord();else again()})});const parsed=(c,raw)=>formValue(c,raw,draft);function set(c,v){settle({...draft,[c.field]:parsed(c,v)});const stale=Object.keys(errors).filter(id=>id===c.id||hidden.has(id));if(stale.length){const rest={...errors};for(const id of stale)delete rest[id];errors=rest}}const FORMATS={email:{kind:"email",message:"Not a valid email address"},url:{kind:"url",message:"Not a valid web address"},phone:{kind:"phone",message:"Not a valid phone number"}};function problem(c,v){const blank=isBlank(v);if(blank&&required.includes(c.id))return`${c.header} is required`;const format=FORMATS[c.fieldType??""];if(!blank&&format&&!linkHref(format.kind,v))return format.message;const validate=c.def.validate;if(typeof validate==="function"){const verdict=validate({value:v,row:draft,rowIndex:-1,column:{id:c.id,columnDef:c.def}});if(verdict===false)return`${c.header} is not valid`;if(typeof verdict==="string"&&verdict)return verdict}return""}function editBeside(c,dir){const at=shown.findIndex(x=>x.id===c.id);const next=shown[at+dir];editing=next&&next.def.editorType!=="checkbox"?next.id:null}function given(){const out={};for(const[field,v]of Object.entries(draft)){if(!isBlank(v)||field in prefilled)out[field]=v}return out}async function submit(e){e.preventDefault();if(!ctrl||busy)return;editing=null;failure="";const found={};for(const c of columns){if(hidden.has(c.id))continue;const why=problem(c,draft[c.field]);if(why)found[c.id]=why}errors=found;if(Object.keys(found).length){if([...linkHidden].some(id=>found[id]))linkHidden=new Set([...linkHidden].filter(id=>!found[id]));return}if(!seed)startRecord();const row=newRowValues(ctrl,{...seed,...given()});for(const c of columns)if(hidden.has(c.id))delete row[c.field];api.addRow(row,"bottom");ctrl.props.onRowAdd?.({row});let result;try{result=onSubmit?.(row)}catch(err){return fail(row,err)}if(result&&typeof result.then==="function"){busy=true;try{await result}catch(err){return fail(row,err)}finally{busy=false}}sent=true}function fail(row,err){const at=ctrl?ctrl.internalData.indexOf(row):-1;if(at>=0)api.removeRows([at]);failure=err instanceof Error&&err.message?err.message:"The record could not be sent. Try again."}function again(){seed=null;errors={};failure="";startRecord();sent=false}
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
5
|
{#if ctrl}
|
|
@@ -14,7 +14,7 @@ import{untrack}from"svelte";import{parseEditorValue}from"@svgrid/grid";import{fi
|
|
|
14
14
|
<form class="sv-fform" onsubmit={submit} novalidate>
|
|
15
15
|
<h2 class="sv-fform-title">{title}</h2>
|
|
16
16
|
{#if description}<p class="sv-fform-desc">{description}</p>{/if}
|
|
17
|
-
{#each
|
|
17
|
+
{#each shown as c (c.id)}
|
|
18
18
|
{@const v = draft[c.field]}
|
|
19
19
|
<div class="sv-fform-field" class:is-missing={!!errors[c.id]}>
|
|
20
20
|
<div class="sv-fform-label">
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { FieldFilter } from './filter-model.js';
|
|
2
|
+
import { type FormPrefill } from './form-logic.js';
|
|
1
3
|
type $$ComponentProps = {
|
|
2
4
|
/** The grid's api. */
|
|
3
5
|
api: any;
|
|
@@ -10,6 +12,18 @@ type $$ComponentProps = {
|
|
|
10
12
|
submitLabel?: string;
|
|
11
13
|
/** Values each record from this form starts with, under the row adder's `defaults` (`<SvBase>` gives an id). */
|
|
12
14
|
defaults?: () => Record<string, unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* Column id -> when that field is shown, as a view bar filter over the
|
|
17
|
+
* other answers. A hidden field is not required, not checked, and not in
|
|
18
|
+
* the record; what was typed in it is cleared when it hides.
|
|
19
|
+
*/
|
|
20
|
+
conditions?: Record<string, FieldFilter>;
|
|
21
|
+
/**
|
|
22
|
+
* Answers to start with: a link or query string with
|
|
23
|
+
* `prefill_<Field name>=value` and `hide_<Field name>=true`, `true` for
|
|
24
|
+
* the page's own URL, or values by field name or column id.
|
|
25
|
+
*/
|
|
26
|
+
prefill?: FormPrefill;
|
|
13
27
|
/**
|
|
14
28
|
* After the row was added. Return a Promise to wait on it: the button is
|
|
15
29
|
* busy until it settles, and a rejection takes the row back out of the
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import{tick,untrack}from"svelte";import{hasGanttView}from"@svgrid/grid";import{conditionCount,isGroup,isComplete}from"./filter-model";import{fieldColumns,gridOf,groupLeaves,leafFilter,primaryIdOf}from"./grid-access";import{getLinkedTable,linkedRows}from"./sources.svelte";import{PLAIN_STATE,applyColor,applyGanttSettings,applyView,boardConfig,captureView,galleryConfig,colorSettingOf,newViewId}from"./view-model";import{groupRules,userSorts}from"./viewbar/sort-state";import{recordHeightOf,syncGroupRowHeight}from"./row-height";import{getRecordRequest}from"./editor-request.svelte";import{getDeleteRecordRequest}from"./record-delete.svelte";import{clearBarRequest,getBarRequest,registerBar}from"./bar-request.svelte";let{api,views=$bindable([{id:"grid",name:"Grid view",type:"grid"}]),activeView=$bindable(""),onViewsChange,viewTypes,automations=null,changed=null,rowHeights=[{label:"Short",height:34},{label:"Medium",height:56},{label:"Tall",height:88},{label:"Extra tall",height:128}]}=$props();const ctrl=$derived(api?gridOf(api):void 0);const active=$derived(views.find(v=>v.id===activeView)??views[0]);const types=$derived(viewTypes??["grid","kanban","calendar",...hasGanttView()?["gantt"]:[]]);const linkNames=(table,value)=>{const t=getLinkedTable(table);return t?linkedRows(t,value).map(r=>String(r[t.primaryField]??"")):[]};const primaryField=$derived.by(()=>{if(!ctrl)return void 0;const id=primaryIdOf(ctrl);return fieldColumns(ctrl).find(c=>c.id===id)?.field});let appliedId=null;let appliedKey="";let applying=false;let showSeq=0;const keyOf=v=>JSON.stringify(v);function setViews(next){views=next;const shown=next.find(v=>v.id===appliedId);if(shown)appliedKey=keyOf(shown);onViewsChange?.(next)}async function ready(t){if(t==="kanban")(await import("../board")).enableBoardView();else if(t==="calendar")(await import("../scheduler")).enableSchedulerView();else if(t==="gallery")(await import("../gallery")).enableGalleryView()}async function show(view){const seq=showSeq+=1;appliedId=view.id;appliedKey=keyOf(view);applying=true;await ready(view.type);if(seq!==showSeq)return;applying=false;if(!ctrl)return;applyView(ctrl,api,view,{primaryField,linkNames});colorSetting=view.color??colorSettingOf(ctrl)}const capture=v=>captureView(ctrl,api,{...v,color:$state.snapshot(colorSetting)});function switchTo(id){if(!ctrl||!active||id===active.id)return;const next=views.map(v=>v.id===active.id?capture(v):v);const target=next.find(v=>v.id===id);if(!target)return;setViews(next);activeView=id;void show(target);viewsOpen=false}function create(partial){if(!ctrl||!active)return;const select=columns.find(c=>c.fieldType==="singleSelect");const timed=partial.type==="calendar"||partial.type==="gantt";const view={...partial,id:newViewId(),state:{...PLAIN_STATE},color:timed&&select?{mode:"field",field:select.field}:{mode:"none"}};const next=[...views.map(v=>v.id===active.id?capture(v):v),view];setViews(next);activeView=view.id;void show(view);viewsOpen=false}function duplicate(id){if(!ctrl)return;const src=id===active?.id?capture(active):views.find(v=>v.id===id);if(!src)return;const copy={...JSON.parse(JSON.stringify(src)),id:newViewId(),name:`${src.name} copy`};const at=views.findIndex(v=>v.id===id);const next=[...views];next.splice(at+1,0,copy);setViews(next)}function remove(id){if(views.length<2)return;const next=views.filter(v=>v.id!==id);setViews(next);if(id===active?.id){activeView=next[0].id;void show(next[0])}}const rename=(id,name)=>setViews(views.map(v=>v.id===id?{...v,name}:v));function setGantt(next){if(!ctrl||!active)return;const updated={...active,...next};setViews(views.map(v=>v.id===active.id?updated:v));applyGanttSettings(ctrl,api,updated,primaryField)}const NO_CHART={kind:"bar",x:""};const setChart=chart=>setViews(views.map(v=>v.id===active?.id?{...v,chart}:v));$effect(()=>{if(!ctrl||!active)return;const view=active;const key=keyOf(view);untrack(()=>{if(!activeView)activeView=view.id;if(view.id===appliedId&&key===appliedKey)return;if(appliedId===null&&!(view.state||view.type!=="grid"||view.color||view.rowHeight!=null)){appliedId=view.id;appliedKey=key;return}void show(view)})});$effect(()=>{if(!ctrl||!active)return;const snapshot=JSON.stringify([ctrl.gridStateVersion,api.getState(),recordHeightOf(api.getOption("rowHeight")),effectiveColor]);const view=active;const timer=setTimeout(()=>{untrack(()=>{if(applying||view.id!==appliedId||keyOf(view)!==appliedKey)return;const kept=capture(view);const before=JSON.stringify([view.state,view.rowHeight,view.color]);const after=JSON.stringify([kept.state,kept.rowHeight,kept.color]);if(before!==after)setViews(views.map(v=>v.id===view.id?kept:v))})},400);void snapshot;return()=>clearTimeout(timer)});let viewsOpen=$state(false);let panel=$state(null);function setPanel(p,open){if(open)panel=p;else if(panel===p)panel=null}$effect(()=>{if(ctrl)return registerBar(ctrl)});$effect(()=>{const r=getBarRequest();if(!r||r.ctrl!==ctrl)return;untrack(()=>{panel=r.panel;clearBarRequest()})});let colorSetting=$state({mode:"none"});$effect(()=>{if(ctrl)untrack(()=>colorSetting=active?.color??colorSettingOf(ctrl))});function setColor(s){colorSetting=s;if(ctrl)applyColor(ctrl,s,linkNames);if(ctrl&&active&&(active.type==="calendar"||active.type==="gantt")){const updated={...active,color:$state.snapshot(s)};setViews(views.map(v=>v.id===active.id?updated:v));applyGanttSettings(ctrl,api,updated,primaryField)}}const columns=$derived(ctrl?fieldColumns(ctrl):[]);const hiddenCount=$derived(columns.filter(c=>!c.visible).length);const filter=$derived.by(()=>{const f=ctrl?.advancedFilter;return f?.kind==="fieldFilter"?f:null});const filterCount=$derived(conditionCount(filter));const filterLabel=$derived.by(()=>{if(!filter||!filterCount)return"Filter";const ids=new Set;for(const c of filter.conditions)for(const x of isGroup(c)?c.conditions:[c])if(isComplete(x))ids.add(x.column);if(ids.size===1)return`Filtered by ${columns.find(c=>ids.has(c.id))?.header??"1 field"}`;return`Filtered by ${ids.size} fields`});const groupCount=$derived(ctrl?groupRules(ctrl).length:0);const sortCount=$derived(ctrl?userSorts(ctrl).length:0);const effectiveColor=$derived(ctrl?colorSettingOf(ctrl,colorSetting):colorSetting);const colorLabel=$derived(effectiveColor.mode==="field"?`Colored by ${columns.find(c=>c.field===effectiveColor.field)?.header??"field"}`:effectiveColor.mode==="conditions"&&effectiveColor.rules.length?"Colored by conditions":"Color");const rowHeight=$derived(recordHeightOf(api?.getOption?.("rowHeight"))??0);$effect(()=>{const grouped=groupCount>0;void rowHeight;untrack(()=>syncGroupRowHeight(ctrl,api,grouped))});const records=$derived.by(()=>{if(!ctrl)return 0;const tops=(ctrl.allRows??[]).filter(r=>(r.depth??0)===0&&!r.__treeRow&&typeof r.getCanExpand==="function"&&r.getCanExpand()&&r.leafCount!=null);if(!groupCount||!tops.length)return api.getDisplayedRows().length;const keep=leafFilter(ctrl);return keep?tops.reduce((n,r)=>n+groupLeaves(r,keep).length,0):tops.reduce((n,r)=>n+(r.leafCount??0),0)});const plural=(n,one,many)=>`${n} ${n===1?one:many}`;let searching=$state(false);const quickSearch=$derived(active?.type!=="grid");async function openSearch(){if(quickSearch){searching=true;return}ctrl.findOpen=true;await tick();const root=ctrl.scrollContainer?.closest(".sv-grid-root");root?.querySelector(".sv-grid-find-input")?.focus()}function focusBox(node){node.focus()}let galleryKey="";$effect(()=>{if(!ctrl||active?.type!=="gallery"){galleryKey="";return}const view=active;const cfg=galleryConfig(ctrl,api,view);const key=JSON.stringify([cfg.coverField,cfg.titleField,cfg.cardFields]);if(key===galleryKey)return;galleryKey=key;untrack(()=>api.setOption("gallery",cfg))});let boardKey="";$effect(()=>{if(!ctrl||active?.type!=="kanban"){boardKey="";return}const cfg=boardConfig(ctrl,api,active);if(!cfg)return;const key=JSON.stringify([cfg.groupBy,cfg.titleField,cfg.cardFields]);if(key===boardKey)return;boardKey=key;untrack(()=>api.setOption("board",cfg))});const record=$derived.by(()=>{const r=getRecordRequest();const t=active?.type;return r&&ctrl&&r.ctrl===ctrl&&(t==="kanban"||t==="calendar"||t==="gantt"||t==="gallery")?r:null});const deleting=$derived.by(()=>{const r=getDeleteRecordRequest();const t=active?.type;return r&&ctrl&&r.ctrl===ctrl&&(t==="kanban"||t==="calendar"||t==="gantt"||t==="gallery")?r:null});const has=$derived.by(()=>{const t=active?.type??"grid";if(t==="form")return new Set;if(t==="grid")return new Set(["hide","filter","group","sort","color","height"]);if(t==="chart")return new Set(["filter","chart"]);if(t==="gantt")return new Set(["hide","filter","sort","color","gantt"]);if(t==="calendar")return new Set(["hide","filter","sort","color"]);return new Set(["hide","filter","sort"])});const ICON={hide:"M3 3l18 18M10.6 10.6a2 2 0 0 0 2.8 2.8M9.9 5.1A9.8 9.8 0 0 1 12 5c5 0 9 5 10 7a13.4 13.4 0 0 1-3 3.9M6.6 6.6A13.5 13.5 0 0 0 2 12c1 2 5 7 10 7a9.6 9.6 0 0 0 4.4-1.1",filter:"M4 5h16l-6 7v6l-4 2v-8z",group:"M4 5h16M4 10h10M4 15h16M4 20h10",sort:"M7 4v16M3 16l4 4 4-4M17 20V4M13 8l4-4 4 4",color:"M12 3l6 7a6.5 6.5 0 1 1-12 0l6-7z",chart:"M4 20h16M6 20V11M11 20V5M16 20v-7",gantt:"M4 5h9M7 10h11M10 15h8M4 20h16",height:"M4 6h16M4 12h16M4 18h16M20 3v18",search:"M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM20 20l-4-4",chevron:"M6 9l6 6 6-6",bolt:"M13 3L5 14h6l-1 7 8-11h-6z"};
|
|
2
|
+
import{tick,untrack}from"svelte";import{hasGanttView}from"@svgrid/grid";import{conditionCount,isGroup,isComplete}from"./filter-model";import{fieldColumns,gridOf,groupLeaves,leafFilter,primaryIdOf}from"./grid-access";import{findFieldUser,getCurrentUser,getLinkedTable,linkedRows}from"./sources.svelte";import{PLAIN_STATE,applyColor,applyGanttSettings,applyView,boardConfig,captureView,galleryConfig,colorSettingOf,newViewId}from"./view-model";import{groupRules,userSorts}from"./viewbar/sort-state";import{recordHeightOf,syncGroupRowHeight}from"./row-height";import{getRecordRequest}from"./editor-request.svelte";import{getDeleteRecordRequest}from"./record-delete.svelte";import{clearBarRequest,getBarRequest,registerBar}from"./bar-request.svelte";let{api,views=$bindable([{id:"grid",name:"Grid view",type:"grid"}]),activeView=$bindable(""),onViewsChange,viewTypes,automations=null,changed=null,lockViews=true,rowHeights=[{label:"Short",height:34},{label:"Medium",height:56},{label:"Tall",height:88},{label:"Extra tall",height:128}]}=$props();const ctrl=$derived(api?gridOf(api):void 0);const me=$derived(getCurrentUser()?.id);const visible=$derived(views.filter(v=>!v.personal||!me||v.personal===me));const active=$derived(visible.find(v=>v.id===activeView)??visible[0]??views[0]);const locked=$derived(!!active?.locked);let lockedDirty=$state(false);let lockedBaseline=null;const lockTitle=$derived.by(()=>{const by=active?.lockedBy?findFieldUser(active.lockedBy)?.name:void 0;return`This view is locked${by?` by ${by}`:""}: its settings stay as saved`});const types=$derived(viewTypes??["grid","kanban","calendar",...hasGanttView()?["gantt"]:[]]);const linkNames=(table,value)=>{const t=getLinkedTable(table);return t?linkedRows(t,value).map(r=>String(r[t.primaryField]??"")):[]};const primaryField=$derived.by(()=>{if(!ctrl)return void 0;const id=primaryIdOf(ctrl);return fieldColumns(ctrl).find(c=>c.id===id)?.field});let appliedId=null;let appliedKey="";let applying=false;let showSeq=0;const keyOf=v=>JSON.stringify(v);function setViews(next){views=next;const shown=next.find(v=>v.id===appliedId);if(shown)appliedKey=keyOf(shown);onViewsChange?.(next)}async function ready(t){if(t==="kanban")(await import("../board")).enableBoardView();else if(t==="calendar")(await import("../scheduler")).enableSchedulerView();else if(t==="gallery")(await import("../gallery")).enableGalleryView()}async function show(view){const seq=showSeq+=1;appliedId=view.id;appliedKey=keyOf(view);applying=true;lockedDirty=false;lockedBaseline=null;await ready(view.type);if(seq!==showSeq)return;applying=false;if(!ctrl)return;applyView(ctrl,api,view,{primaryField,linkNames});colorSetting=view.color??colorSettingOf(ctrl)}const capture=v=>captureView(ctrl,api,{...v,color:$state.snapshot(colorSetting)});const keptViews=()=>views.map(v=>v.id===active?.id&&!v.locked?capture(v):v);function switchTo(id){if(!ctrl||!active||id===active.id)return;const next=keptViews();const target=next.find(v=>v.id===id);if(!target)return;setViews(next);activeView=id;void show(target);viewsOpen=false}function create(partial){if(!ctrl||!active)return;const select=columns.find(c=>c.fieldType==="singleSelect");const timed=partial.type==="calendar"||partial.type==="gantt";const view={...partial,id:newViewId(),state:{...PLAIN_STATE},color:timed&&select?{mode:"field",field:select.field}:{mode:"none"}};const next=[...keptViews(),view];setViews(next);activeView=view.id;void show(view);viewsOpen=false}function duplicate(id){if(!ctrl)return;const src=id===active?.id&&!active.locked?capture(active):views.find(v=>v.id===id);if(!src)return;const{locked:_locked,lockedBy:_by,...open}=JSON.parse(JSON.stringify(src));const copy={...open,id:newViewId(),name:`${src.name} copy`};const at=views.findIndex(v=>v.id===id);const next=[...views];next.splice(at+1,0,copy);setViews(next)}function remove(id){if(views.length<2||views.find(v=>v.id===id)?.locked)return;const next=views.filter(v=>v.id!==id);setViews(next);if(id===active?.id){const first=next.find(v=>!v.personal||!me||v.personal===me)??next[0];activeView=first.id;void show(first)}}function toggleLock(id){if(!lockViews)return;setViews(views.map(v=>{if(v.id!==id)return v;if(v.locked){const{locked:_locked,lockedBy:_by,...open}=v;return open}const kept=v.id===active?.id?capture(v):v;return{...kept,locked:true,...me?{lockedBy:me}:{}}}));lockedDirty=false;lockedBaseline=null}function resetLocked(){if(active)void show(active)}const rename=(id,name)=>setViews(views.map(v=>v.id===id?{...v,name}:v));function setGantt(next){if(!ctrl||!active)return;const updated={...active,...next};setViews(views.map(v=>v.id===active.id?updated:v));applyGanttSettings(ctrl,api,updated,primaryField)}const NO_CHART={kind:"bar",x:""};const setChart=chart=>setViews(views.map(v=>v.id===active?.id?{...v,chart}:v));const setList=next=>setViews(views.map(v=>v.id===active?.id?{...v,...next}:v));$effect(()=>{if(!ctrl||!active)return;const view=active;const key=keyOf(view);untrack(()=>{if(!activeView)activeView=view.id;if(view.id===appliedId&&key===appliedKey)return;if(appliedId===null&&!(view.state||view.type!=="grid"||view.color||view.rowHeight!=null)){appliedId=view.id;appliedKey=key;return}void show(view)})});$effect(()=>{if(!ctrl||!active)return;const snapshot=JSON.stringify([ctrl.gridStateVersion,api.getState(),recordHeightOf(api.getOption("rowHeight")),effectiveColor]);const view=active;const timer=setTimeout(()=>{untrack(()=>{if(applying||view.id!==appliedId||keyOf(view)!==appliedKey)return;const kept=capture(view);const before=JSON.stringify([view.state,view.rowHeight,view.color]);const after=JSON.stringify([kept.state,kept.rowHeight,kept.color]);if(view.locked){const{expanded:_open,...shown}=kept.state??{};const now=JSON.stringify([shown,kept.rowHeight,kept.color]);if(lockedBaseline===null)lockedBaseline=now;else lockedDirty=now!==lockedBaseline}else if(before!==after)setViews(views.map(v=>v.id===view.id?kept:v))})},400);void snapshot;return()=>clearTimeout(timer)});let viewsOpen=$state(false);let panel=$state(null);function setPanel(p,open){if(open)panel=p;else if(panel===p)panel=null}$effect(()=>{if(ctrl)return registerBar(ctrl)});$effect(()=>{const r=getBarRequest();if(!r||r.ctrl!==ctrl)return;untrack(()=>{if(!locked)panel=r.panel;clearBarRequest()})});let colorSetting=$state({mode:"none"});$effect(()=>{if(ctrl)untrack(()=>colorSetting=active?.color??colorSettingOf(ctrl))});function setColor(s){colorSetting=s;if(ctrl)applyColor(ctrl,s,linkNames);if(ctrl&&active&&(active.type==="calendar"||active.type==="gantt")){const updated={...active,color:$state.snapshot(s)};setViews(views.map(v=>v.id===active.id?updated:v));applyGanttSettings(ctrl,api,updated,primaryField)}}const columns=$derived(ctrl?fieldColumns(ctrl):[]);const hiddenCount=$derived(columns.filter(c=>!c.visible).length);const filter=$derived.by(()=>{const f=ctrl?.advancedFilter;return f?.kind==="fieldFilter"?f:null});const filterCount=$derived(conditionCount(filter));const filterLabel=$derived.by(()=>{if(!filter||!filterCount)return"Filter";const ids=new Set;for(const c of filter.conditions)for(const x of isGroup(c)?c.conditions:[c])if(isComplete(x))ids.add(x.column);if(ids.size===1)return`Filtered by ${columns.find(c=>ids.has(c.id))?.header??"1 field"}`;return`Filtered by ${ids.size} fields`});const groupCount=$derived(ctrl?groupRules(ctrl).length:0);const sortCount=$derived(ctrl?userSorts(ctrl).length:0);const effectiveColor=$derived(ctrl?colorSettingOf(ctrl,colorSetting):colorSetting);const colorLabel=$derived(effectiveColor.mode==="field"?`Colored by ${columns.find(c=>c.field===effectiveColor.field)?.header??"field"}`:effectiveColor.mode==="conditions"&&effectiveColor.rules.length?"Colored by conditions":"Color");const rowHeight=$derived(recordHeightOf(api?.getOption?.("rowHeight"))??0);$effect(()=>{const grouped=groupCount>0;void rowHeight;untrack(()=>syncGroupRowHeight(ctrl,api,grouped))});const records=$derived.by(()=>{if(!ctrl)return 0;const tops=(ctrl.allRows??[]).filter(r=>(r.depth??0)===0&&!r.__treeRow&&typeof r.getCanExpand==="function"&&r.getCanExpand()&&r.leafCount!=null);if(!groupCount||!tops.length)return api.getDisplayedRows().length;const keep=leafFilter(ctrl);return keep?tops.reduce((n,r)=>n+groupLeaves(r,keep).length,0):tops.reduce((n,r)=>n+(r.leafCount??0),0)});const plural=(n,one,many)=>`${n} ${n===1?one:many}`;let searching=$state(false);const quickSearch=$derived(active?.type!=="grid");async function openSearch(){if(quickSearch){searching=true;return}ctrl.findOpen=true;await tick();const root=ctrl.scrollContainer?.closest(".sv-grid-root");root?.querySelector(".sv-grid-find-input")?.focus()}function focusBox(node){node.focus()}let galleryKey="";$effect(()=>{if(!ctrl||active?.type!=="gallery"){galleryKey="";return}const view=active;const cfg=galleryConfig(ctrl,api,view);const key=JSON.stringify([cfg.coverField,cfg.titleField,cfg.cardFields]);if(key===galleryKey)return;galleryKey=key;untrack(()=>api.setOption("gallery",cfg))});let boardKey="";$effect(()=>{if(!ctrl||active?.type!=="kanban"){boardKey="";return}const cfg=boardConfig(ctrl,api,active);if(!cfg)return;const key=JSON.stringify([cfg.groupBy,cfg.titleField,cfg.cardFields]);if(key===boardKey)return;boardKey=key;untrack(()=>api.setOption("board",cfg))});const record=$derived.by(()=>{const r=getRecordRequest();const t=active?.type;return r&&ctrl&&r.ctrl===ctrl&&(t==="kanban"||t==="calendar"||t==="gantt"||t==="gallery")?r:null});const deleting=$derived.by(()=>{const r=getDeleteRecordRequest();const t=active?.type;return r&&ctrl&&r.ctrl===ctrl&&(t==="kanban"||t==="calendar"||t==="gantt"||t==="gallery")?r:null});const has=$derived.by(()=>{const t=active?.type??"grid";if(t==="form")return new Set;if(t==="dashboard")return new Set;if(t==="grid")return new Set(["hide","filter","group","sort","color","height"]);if(t==="chart")return new Set(["filter","chart"]);if(t==="gantt")return new Set(["hide","filter","sort","color","gantt"]);if(t==="calendar")return new Set(["hide","filter","sort","color"]);if(t==="list")return new Set(["hide","filter","group","sort","list"]);if(t==="inbox")return new Set(["hide","filter","sort","list"]);return new Set(["hide","filter","sort"])});const ICON={hide:"M3 3l18 18M10.6 10.6a2 2 0 0 0 2.8 2.8M9.9 5.1A9.8 9.8 0 0 1 12 5c5 0 9 5 10 7a13.4 13.4 0 0 1-3 3.9M6.6 6.6A13.5 13.5 0 0 0 2 12c1 2 5 7 10 7a9.6 9.6 0 0 0 4.4-1.1",filter:"M4 5h16l-6 7v6l-4 2v-8z",group:"M4 5h16M4 10h10M4 15h16M4 20h10",sort:"M7 4v16M3 16l4 4 4-4M17 20V4M13 8l4-4 4 4",color:"M12 3l6 7a6.5 6.5 0 1 1-12 0l6-7z",chart:"M4 20h16M6 20V11M11 20V5M16 20v-7",gantt:"M4 5h9M7 10h11M10 15h8M4 20h16",height:"M4 6h16M4 12h16M4 18h16M20 3v18",search:"M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM20 20l-4-4",chevron:"M6 9l6 6 6-6",bolt:"M13 3L5 14h6l-1 7 8-11h-6z",lock:"M6 11h12v9H6zM8 11V8a4 4 0 0 1 8 0v3",person:"M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM4 21a8 8 0 0 1 16 0"};
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
5
|
{#snippet glyph(path: string, size = 15)}
|
|
@@ -18,22 +18,33 @@ import{tick,untrack}from"svelte";import{hasGanttView}from"@svgrid/grid";import{c
|
|
|
18
18
|
{/snippet}
|
|
19
19
|
<ViewsMenu
|
|
20
20
|
{ctrl}
|
|
21
|
-
{
|
|
21
|
+
views={visible}
|
|
22
22
|
activeId={active.id}
|
|
23
23
|
{types}
|
|
24
|
+
{me}
|
|
25
|
+
canLock={lockViews}
|
|
24
26
|
onSwitch={switchTo}
|
|
25
27
|
onCreate={create}
|
|
26
28
|
onRename={rename}
|
|
27
29
|
onDuplicate={duplicate}
|
|
28
30
|
onDelete={remove}
|
|
31
|
+
onLock={toggleLock}
|
|
29
32
|
/>
|
|
30
33
|
</SvPopover>
|
|
34
|
+
{#if locked}
|
|
35
|
+
<span class="sv-fvb-lock" title={lockTitle}>
|
|
36
|
+
{@render glyph(ICON.lock, 13)}<span>{lockedDirty ? 'Locked, not saved' : 'Locked'}</span>
|
|
37
|
+
{#if lockedDirty}<button type="button" class="sv-fvb-lock-reset" onclick={resetLocked}>Reset</button>{/if}
|
|
38
|
+
</span>
|
|
39
|
+
{:else if active.personal}
|
|
40
|
+
<span class="sv-fvb-lock" title="A personal view: only you see it">{@render glyph(ICON.person, 13)}<span>Personal</span></span>
|
|
41
|
+
{/if}
|
|
31
42
|
<span class="sv-fvb-sep" aria-hidden="true"></span>
|
|
32
43
|
|
|
33
44
|
{#if has.has('hide')}
|
|
34
45
|
<SvPopover open={panel === 'hide'} onOpenChange={(o) => setPanel('hide', o)} arrow={false} placement="bottom-start" ariaLabel="Hide fields">
|
|
35
46
|
{#snippet anchor()}
|
|
36
|
-
<button type="button" class="sv-fvb-btn" class:is-set={hiddenCount > 0}>
|
|
47
|
+
<button type="button" disabled={locked} title={locked ? lockTitle : undefined} class="sv-fvb-btn" class:is-set={hiddenCount > 0}>
|
|
37
48
|
{@render glyph(ICON.hide)}<span>{hiddenCount ? plural(hiddenCount, 'hidden field', 'hidden fields') : 'Hide fields'}</span>
|
|
38
49
|
</button>
|
|
39
50
|
{/snippet}
|
|
@@ -43,7 +54,7 @@ import{tick,untrack}from"svelte";import{hasGanttView}from"@svgrid/grid";import{c
|
|
|
43
54
|
{#if has.has('filter')}
|
|
44
55
|
<SvPopover open={panel === 'filter'} onOpenChange={(o) => setPanel('filter', o)} arrow={false} placement="bottom-start" ariaLabel="Filter">
|
|
45
56
|
{#snippet anchor()}
|
|
46
|
-
<button type="button" class="sv-fvb-btn" class:is-set={filterCount > 0}>{@render glyph(ICON.filter)}<span>{filterLabel}</span></button>
|
|
57
|
+
<button type="button" disabled={locked} title={locked ? lockTitle : undefined} class="sv-fvb-btn" class:is-set={filterCount > 0}>{@render glyph(ICON.filter)}<span>{filterLabel}</span></button>
|
|
47
58
|
{/snippet}
|
|
48
59
|
<FilterPanel {ctrl} {api} />
|
|
49
60
|
</SvPopover>
|
|
@@ -51,7 +62,7 @@ import{tick,untrack}from"svelte";import{hasGanttView}from"@svgrid/grid";import{c
|
|
|
51
62
|
{#if has.has('group')}
|
|
52
63
|
<SvPopover open={panel === 'group'} onOpenChange={(o) => setPanel('group', o)} arrow={false} placement="bottom-start" ariaLabel="Group">
|
|
53
64
|
{#snippet anchor()}
|
|
54
|
-
<button type="button" class="sv-fvb-btn" class:is-set={groupCount > 0}>
|
|
65
|
+
<button type="button" disabled={locked} title={locked ? lockTitle : undefined} class="sv-fvb-btn" class:is-set={groupCount > 0}>
|
|
55
66
|
{@render glyph(ICON.group)}<span>{groupCount ? `Grouped by ${plural(groupCount, 'field', 'fields')}` : 'Group'}</span>
|
|
56
67
|
</button>
|
|
57
68
|
{/snippet}
|
|
@@ -61,7 +72,7 @@ import{tick,untrack}from"svelte";import{hasGanttView}from"@svgrid/grid";import{c
|
|
|
61
72
|
{#if has.has('sort')}
|
|
62
73
|
<SvPopover open={panel === 'sort'} onOpenChange={(o) => setPanel('sort', o)} arrow={false} placement="bottom-start" ariaLabel="Sort">
|
|
63
74
|
{#snippet anchor()}
|
|
64
|
-
<button type="button" class="sv-fvb-btn" class:is-set={sortCount > 0}>
|
|
75
|
+
<button type="button" disabled={locked} title={locked ? lockTitle : undefined} class="sv-fvb-btn" class:is-set={sortCount > 0}>
|
|
65
76
|
{@render glyph(ICON.sort)}<span>{sortCount ? `Sorted by ${plural(sortCount, 'field', 'fields')}` : 'Sort'}</span>
|
|
66
77
|
</button>
|
|
67
78
|
{/snippet}
|
|
@@ -71,7 +82,7 @@ import{tick,untrack}from"svelte";import{hasGanttView}from"@svgrid/grid";import{c
|
|
|
71
82
|
{#if has.has('color')}
|
|
72
83
|
<SvPopover open={panel === 'color'} onOpenChange={(o) => setPanel('color', o)} arrow={false} placement="bottom-start" ariaLabel="Color">
|
|
73
84
|
{#snippet anchor()}
|
|
74
|
-
<button type="button" class="sv-fvb-btn" class:is-set={effectiveColor.mode !== 'none'}>{@render glyph(ICON.color)}<span>{colorLabel}</span></button>
|
|
85
|
+
<button type="button" disabled={locked} title={locked ? lockTitle : undefined} class="sv-fvb-btn" class:is-set={effectiveColor.mode !== 'none'}>{@render glyph(ICON.color)}<span>{colorLabel}</span></button>
|
|
75
86
|
{/snippet}
|
|
76
87
|
<ColorPanel {ctrl} setting={effectiveColor} onChange={setColor} />
|
|
77
88
|
</SvPopover>
|
|
@@ -80,7 +91,7 @@ import{tick,untrack}from"svelte";import{hasGanttView}from"@svgrid/grid";import{c
|
|
|
80
91
|
{@const chart = active.chart ?? NO_CHART}
|
|
81
92
|
<SvPopover open={panel === 'chart'} onOpenChange={(o) => setPanel('chart', o)} arrow={false} placement="bottom-start" ariaLabel="Customize chart">
|
|
82
93
|
{#snippet anchor()}
|
|
83
|
-
<button type="button" class="sv-fvb-btn">{@render glyph(ICON.chart)}<span>Customize chart</span></button>
|
|
94
|
+
<button type="button" disabled={locked} title={locked ? lockTitle : undefined} class="sv-fvb-btn">{@render glyph(ICON.chart)}<span>Customize chart</span></button>
|
|
84
95
|
{/snippet}
|
|
85
96
|
<ChartPanel {ctrl} setting={chart} onChange={setChart} />
|
|
86
97
|
</SvPopover>
|
|
@@ -89,15 +100,25 @@ import{tick,untrack}from"svelte";import{hasGanttView}from"@svgrid/grid";import{c
|
|
|
89
100
|
{@const settings = active}
|
|
90
101
|
<SvPopover open={panel === 'gantt'} onOpenChange={(o) => setPanel('gantt', o)} arrow={false} placement="bottom-start" ariaLabel="Customize timeline">
|
|
91
102
|
{#snippet anchor()}
|
|
92
|
-
<button type="button" class="sv-fvb-btn">{@render glyph(ICON.gantt)}<span>Customize timeline</span></button>
|
|
103
|
+
<button type="button" disabled={locked} title={locked ? lockTitle : undefined} class="sv-fvb-btn">{@render glyph(ICON.gantt)}<span>Customize timeline</span></button>
|
|
93
104
|
{/snippet}
|
|
94
105
|
<GanttPanel {ctrl} view={settings} onChange={setGantt} />
|
|
95
106
|
</SvPopover>
|
|
96
107
|
{/if}
|
|
108
|
+
{#if has.has('list') && active}
|
|
109
|
+
{@const settings = active}
|
|
110
|
+
{@const what = active.type === 'inbox' ? 'inbox' : 'list'}
|
|
111
|
+
<SvPopover open={panel === 'list'} onOpenChange={(o) => setPanel('list', o)} arrow={false} placement="bottom-start" ariaLabel={`Customize ${what}`}>
|
|
112
|
+
{#snippet anchor()}
|
|
113
|
+
<button type="button" disabled={locked} title={locked ? lockTitle : undefined} class="sv-fvb-btn">{@render glyph(viewTypeInfo(settings.type).icon)}<span>Customize {what}</span></button>
|
|
114
|
+
{/snippet}
|
|
115
|
+
<ListPanel {ctrl} view={settings} inbox={settings.type === 'inbox'} onChange={setList} />
|
|
116
|
+
</SvPopover>
|
|
117
|
+
{/if}
|
|
97
118
|
{#if has.has('height')}
|
|
98
119
|
<SvPopover arrow={false} placement="bottom-start" ariaLabel="Row height">
|
|
99
120
|
{#snippet anchor()}
|
|
100
|
-
<button type="button" class="sv-fvb-btn sv-fvb-icon-only" aria-label="Row height" title="Row height">{@render glyph(ICON.height)}</button>
|
|
121
|
+
<button type="button" disabled={locked} class="sv-fvb-btn sv-fvb-icon-only" aria-label="Row height" title={locked ? lockTitle : "Row height"}>{@render glyph(ICON.height)}</button>
|
|
101
122
|
{/snippet}
|
|
102
123
|
<div class="sv-fvb-panel sv-fvb-heights" role="menu" aria-label="Row height" use:panelFocus>
|
|
103
124
|
{#each rowHeights as h (h.height)}
|
|
@@ -128,7 +149,7 @@ import{tick,untrack}from"svelte";import{hasGanttView}from"@svgrid/grid";import{c
|
|
|
128
149
|
{@render glyph(ICON.bolt)}<span>{automations.count ? plural(automations.count, 'automation', 'automations') : 'Automations'}</span>
|
|
129
150
|
</button>
|
|
130
151
|
{/if}
|
|
131
|
-
{#if active.type !== 'form'}
|
|
152
|
+
{#if active.type !== 'form' && active.type !== 'dashboard'}
|
|
132
153
|
<span class="sv-fvb-count" aria-live="polite">{plural(records, 'record', 'records')}</span>
|
|
133
154
|
{#if quickSearch && (searching || ctrl.globalFilter)}
|
|
134
155
|
<label class="sv-fvb-search">
|
|
@@ -168,5 +189,5 @@ import{tick,untrack}from"svelte";import{hasGanttView}from"@svgrid/grid";import{c
|
|
|
168
189
|
{/if}
|
|
169
190
|
|
|
170
191
|
<style>
|
|
171
|
-
.sv-fvb-changed{color:var(--sg-fg, #0f172a)}.sv-fvb-changed-dot{width:7px;height:7px;border-radius:50%;background:var(--sg-accent, #2563eb);flex:none}.sv-fvb{container-type:inline-size;display:flex;align-items:center;gap:2px;flex-wrap:wrap;min-height:40px;padding:4px 6px;font-family:var(--sg-font, inherit);font-size:13px;color:var(--sg-fg, #0f172a);border-bottom:1px solid var(--sg-border, #e2e8f0);background:var(--sg-bg, #fff)}.sv-fvb-btn{position:relative;display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 8px;border:0;border-radius:6px;background:none;color:inherit;font:inherit;cursor:pointer;white-space:nowrap}.sv-fvb-btn:hover{background:var(--sg-row-hover-bg, #f1f5f9)}.sv-fvb-btn:focus-visible{outline:2px solid var(--sg-accent, #2563eb);outline-offset:-2px}.sv-fvb-btn.is-set{background:color-mix(in srgb,var(--sg-accent, #2563eb) 13%,transparent)}.sv-fvb-view{font-weight:600;max-width:240px}.sv-fvb-view-name{overflow:hidden;text-overflow:ellipsis}.sv-fvb-icon-only{padding:0 6px}.sv-fvb-sep{width:1px;height:18px;margin:0 6px;background:var(--sg-border, #e2e8f0)}.sv-fvb-spacer{flex:1}@container (max-width: 640px){.sv-fvb-btn:not(.sv-fvb-view)>span{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}.sv-fvb-btn{padding:0 6px}.sv-fvb-view{max-width:150px}}@container (max-width: 420px){.sv-fvb-count{display:none}}.sv-fvb-search{display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 8px;border-radius:6px;border:1px solid var(--sg-border, #cbd5e1);color:var(--sg-muted, #64748b)}.sv-fvb-search input{width:160px;border:0;outline:none;background:none;color:var(--sg-fg, #0f172a);font:inherit}.sv-fvb-search:focus-within{border-color:var(--sg-accent, #2563eb)}.sv-fvb-count{color:var(--sg-muted, #64748b);font-size:12px;margin-inline-end:4px;font-variant-numeric:tabular-nums}:global(.sv-pop__panel:has(.sv-fvb-panel-wide)){max-width:min(94vw,760px)}:global(.sv-fvb-panel){font-size:13px;max-width:100%}:global(.sv-fvb-title){margin:0 0 6px;color:var(--sg-muted, #64748b);font-size:12px}:global(.sv-fvb-empty){margin:2px 0 8px;color:var(--sg-muted, #64748b)}:global(.sv-fvb-foot){display:flex;gap:12px;margin-top:8px;align-items:center}:global(.sv-fvb-select),:global(.sv-fvb-input){width:100%;min-width:0;height:28px;box-sizing:border-box;padding:0 6px;font:inherit;font-size:13px;color:inherit;background:var(--sg-bg, #fff);border:1px solid var(--sg-border, #cbd5e1);border-radius:6px}:global(.sv-fvb-select:focus-visible),:global(.sv-fvb-input:focus-visible){outline:2px solid var(--sg-accent, #2563eb);outline-offset:-1px}:global(.sv-fvb-text-btn){border:0;padding:2px 0;background:none;font:inherit;color:var(--sg-accent, #2563eb);cursor:pointer}:global(.sv-fvb-text-btn:hover){text-decoration:underline}:global(.sv-fvb-solid-btn){border:0;border-radius:6px;padding:5px 12px;font:inherit;cursor:pointer;background:var(--sg-accent, #2563eb);color:var(--sg-accent-fg, #fff)}:global(.sv-fvb-icon-btn){display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;padding:0;border:0;border-radius:6px;background:none;color:var(--sg-muted, #64748b);cursor:pointer}:global(.sv-fvb-icon-btn:hover){background:var(--sg-row-hover-bg, #f1f5f9);color:var(--sg-fg, #0f172a)}:global(.sv-fvb-switch){appearance:none;flex:none;position:relative;width:26px;height:15px;margin:0;border-radius:999px;cursor:pointer;background:color-mix(in srgb,var(--sg-fg, #0f172a) 22%,transparent);transition:background-color .12s}:global(.sv-fvb-switch:before){content:"";position:absolute;top:2px;left:2px;width:11px;height:11px;border-radius:50%;background:var(--sg-bg, #fff);transition:transform .12s}:global(.sv-fvb-switch:checked){background:var(--sg-accent, #2563eb)}:global(.sv-fvb-switch:checked:before){transform:translate(11px)}:global(.sv-fvb-switch:disabled){opacity:.5;cursor:default}:global(.sv-fvb-switch:focus-visible){outline:2px solid var(--sg-accent, #2563eb);outline-offset:2px}.sv-fvb-heights{display:grid;min-width:150px}.sv-fvb-height{display:flex;align-items:center;gap:10px;padding:6px 8px;border:0;border-radius:6px;background:none;color:inherit;font:inherit;text-align:start;cursor:pointer}.sv-fvb-height:hover,.sv-fvb-height.is-on{background:var(--sg-row-hover-bg, #f1f5f9)}.sv-fvb-height.is-on{font-weight:600}.sv-fvb-height-mark{width:14px;height:14px;border:1.5px solid currentColor;border-radius:3px;box-sizing:border-box;background:repeating-linear-gradient(to bottom,transparent 0 2px,currentColor 2px 3px) center / 8px calc(var(--lines) * 3px) no-repeat}
|
|
192
|
+
.sv-fvb-changed{color:var(--sg-fg, #0f172a)}.sv-fvb-changed-dot{width:7px;height:7px;border-radius:50%;background:var(--sg-accent, #2563eb);flex:none}.sv-fvb{container-type:inline-size;display:flex;align-items:center;gap:2px;flex-wrap:wrap;min-height:40px;padding:4px 6px;font-family:var(--sg-font, inherit);font-size:13px;color:var(--sg-fg, #0f172a);border-bottom:1px solid var(--sg-border, #e2e8f0);background:var(--sg-bg, #fff)}.sv-fvb-btn{position:relative;display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 8px;border:0;border-radius:6px;background:none;color:inherit;font:inherit;cursor:pointer;white-space:nowrap}.sv-fvb-btn:hover{background:var(--sg-row-hover-bg, #f1f5f9)}.sv-fvb-btn:focus-visible{outline:2px solid var(--sg-accent, #2563eb);outline-offset:-2px}.sv-fvb-btn.is-set{background:color-mix(in srgb,var(--sg-accent, #2563eb) 13%,transparent)}.sv-fvb-view{font-weight:600;max-width:240px}.sv-fvb-view-name{overflow:hidden;text-overflow:ellipsis}.sv-fvb-icon-only{padding:0 6px}.sv-fvb-sep{width:1px;height:18px;margin:0 6px;background:var(--sg-border, #e2e8f0)}.sv-fvb-lock{display:inline-flex;flex:none;align-items:center;gap:4px;height:24px;margin-left:4px;padding:0 8px;border-radius:999px;font-size:12px;color:var(--sg-muted, #64748b);background:color-mix(in srgb,var(--sg-fg, #0f172a) 7%,transparent)}.sv-fvb-lock-reset{margin-left:2px;padding:0;border:0;background:none;font:inherit;font-weight:600;color:var(--sg-accent, #2563eb);cursor:pointer}:global(.sv-fvb-btn:disabled){opacity:.45;cursor:default}.sv-fvb-spacer{flex:1}@container (max-width: 640px){.sv-fvb-btn:not(.sv-fvb-view)>span{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}.sv-fvb-btn{padding:0 6px}.sv-fvb-view{max-width:150px}.sv-fvb-lock>span{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}.sv-fvb-lock{padding:0 6px}}@container (max-width: 420px){.sv-fvb-count{display:none}}.sv-fvb-search{display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 8px;border-radius:6px;border:1px solid var(--sg-border, #cbd5e1);color:var(--sg-muted, #64748b)}.sv-fvb-search input{width:160px;border:0;outline:none;background:none;color:var(--sg-fg, #0f172a);font:inherit}.sv-fvb-search:focus-within{border-color:var(--sg-accent, #2563eb)}.sv-fvb-count{color:var(--sg-muted, #64748b);font-size:12px;margin-inline-end:4px;font-variant-numeric:tabular-nums}:global(.sv-pop__panel:has(.sv-fvb-panel-wide)){max-width:min(94vw,760px)}:global(.sv-fvb-panel){font-size:13px;max-width:100%}:global(.sv-fvb-title){margin:0 0 6px;color:var(--sg-muted, #64748b);font-size:12px}:global(.sv-fvb-empty){margin:2px 0 8px;color:var(--sg-muted, #64748b)}:global(.sv-fvb-foot){display:flex;gap:12px;margin-top:8px;align-items:center}:global(.sv-fvb-select),:global(.sv-fvb-input){width:100%;min-width:0;height:28px;box-sizing:border-box;padding:0 6px;font:inherit;font-size:13px;color:inherit;background:var(--sg-bg, #fff);border:1px solid var(--sg-border, #cbd5e1);border-radius:6px}:global(.sv-fvb-select:focus-visible),:global(.sv-fvb-input:focus-visible){outline:2px solid var(--sg-accent, #2563eb);outline-offset:-1px}:global(.sv-fvb-text-btn){border:0;padding:2px 0;background:none;font:inherit;color:var(--sg-accent, #2563eb);cursor:pointer}:global(.sv-fvb-text-btn:hover){text-decoration:underline}:global(.sv-fvb-solid-btn){border:0;border-radius:6px;padding:5px 12px;font:inherit;cursor:pointer;background:var(--sg-accent, #2563eb);color:var(--sg-accent-fg, #fff)}:global(.sv-fvb-icon-btn){display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;padding:0;border:0;border-radius:6px;background:none;color:var(--sg-muted, #64748b);cursor:pointer}:global(.sv-fvb-icon-btn:hover){background:var(--sg-row-hover-bg, #f1f5f9);color:var(--sg-fg, #0f172a)}:global(.sv-fvb-switch){appearance:none;flex:none;position:relative;width:26px;height:15px;margin:0;border-radius:999px;cursor:pointer;background:color-mix(in srgb,var(--sg-fg, #0f172a) 22%,transparent);transition:background-color .12s}:global(.sv-fvb-switch:before){content:"";position:absolute;top:2px;left:2px;width:11px;height:11px;border-radius:50%;background:var(--sg-bg, #fff);transition:transform .12s}:global(.sv-fvb-switch:checked){background:var(--sg-accent, #2563eb)}:global(.sv-fvb-switch:checked:before){transform:translate(11px)}:global(.sv-fvb-switch:disabled){opacity:.5;cursor:default}:global(.sv-fvb-switch:focus-visible){outline:2px solid var(--sg-accent, #2563eb);outline-offset:2px}.sv-fvb-heights{display:grid;min-width:150px}.sv-fvb-height{display:flex;align-items:center;gap:10px;padding:6px 8px;border:0;border-radius:6px;background:none;color:inherit;font:inherit;text-align:start;cursor:pointer}.sv-fvb-height:hover,.sv-fvb-height.is-on{background:var(--sg-row-hover-bg, #f1f5f9)}.sv-fvb-height.is-on{font-weight:600}.sv-fvb-height-mark{width:14px;height:14px;border:1.5px solid currentColor;border-radius:3px;box-sizing:border-box;background:repeating-linear-gradient(to bottom,transparent 0 2px,currentColor 2px 3px) center / 8px calc(var(--lines) * 3px) no-repeat}
|
|
172
193
|
</style>
|
|
@@ -25,6 +25,8 @@ type Props = {
|
|
|
25
25
|
label: string;
|
|
26
26
|
onSeen: () => void;
|
|
27
27
|
} | null;
|
|
28
|
+
/** Whether the person may lock and unlock views (default true). */
|
|
29
|
+
lockViews?: boolean;
|
|
28
30
|
};
|
|
29
31
|
declare const SvBaseViewBar: import("svelte").Component<Props, {}, "views" | "activeView">;
|
|
30
32
|
type SvBaseViewBar = ReturnType<typeof SvBaseViewBar>;
|