@svgrid/enterprise 3.1.35 → 3.1.37

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/ExpressionEditorHarness.svelte +1 -1
  2. package/dist/SvAdvancedFilter.svelte +1 -1
  3. package/dist/SvAlertRuleEditor.svelte +1 -1
  4. package/dist/SvAlertsManager.svelte +1 -1
  5. package/dist/SvAlertsPanel.svelte +1 -1
  6. package/dist/SvExpressionEditor.svelte +1 -1
  7. package/dist/SvGridBoard.svelte +1 -1
  8. package/dist/SvGridBulkEditDrawer.svelte +1 -1
  9. package/dist/SvGridEditPanel.svelte +1 -1
  10. package/dist/SvGridGallery.svelte +1 -1
  11. package/dist/SvGridMasterDetail.svelte +1 -1
  12. package/dist/SvGridScheduler.svelte +1 -1
  13. package/dist/SvGridSelectionBar.svelte +1 -1
  14. package/dist/SvPivotDesigner.svelte +1 -1
  15. package/dist/SvSchemaChart.svelte +1 -1
  16. package/dist/SvSchemaDashboard.svelte +1 -1
  17. package/dist/SvSheet.svelte +1 -1
  18. package/dist/SvSheetChartSetup.svelte +1 -1
  19. package/dist/SvSheetConditionalFormat.svelte +1 -1
  20. package/dist/SvSheetDataValidation.svelte +1 -1
  21. package/dist/SvSheetEditRanges.svelte +1 -1
  22. package/dist/SvSheetErrors.svelte +1 -1
  23. package/dist/SvSheetEvaluate.svelte +1 -1
  24. package/dist/SvSheetFindReplace.svelte +1 -1
  25. package/dist/SvSheetFormatCells.svelte +1 -1
  26. package/dist/SvSheetGoalSeek.svelte +1 -1
  27. package/dist/SvSheetInsertFunction.svelte +1 -1
  28. package/dist/SvSheetIteration.svelte +1 -1
  29. package/dist/SvSheetLink.svelte +1 -1
  30. package/dist/SvSheetManageRules.svelte +1 -1
  31. package/dist/SvSheetNameManager.svelte +1 -1
  32. package/dist/SvSheetPageSetup.svelte +1 -1
  33. package/dist/SvSheetPasteSpecial.svelte +1 -1
  34. package/dist/SvSheetPivot.svelte +1 -1
  35. package/dist/SvSheetProtectSheet.svelte +1 -1
  36. package/dist/SvSheetRemoveDuplicates.svelte +1 -1
  37. package/dist/SvSheetRibbon.svelte +1 -1
  38. package/dist/SvSheetSizeDialog.svelte +1 -1
  39. package/dist/SvSheetSort.svelte +1 -1
  40. package/dist/SvSheetSparklines.svelte +1 -1
  41. package/dist/SvSheetTable.svelte +1 -1
  42. package/dist/SvSheetTabs.svelte +1 -1
  43. package/dist/SvSheetTextToColumns.svelte +1 -1
  44. package/dist/SvSheetValidationAlert.svelte +1 -1
  45. package/dist/cdn/svgrid-enterprise.svelte-external.js +1 -1
  46. package/dist/designer/assets/{index-Eyxa9vgS.js → index-BLM_udE-.js} +100 -100
  47. package/dist/designer/index.html +1 -1
  48. package/dist/fields/AiCell.svelte +1 -1
  49. package/dist/fields/AttachmentCell.svelte +1 -1
  50. package/dist/fields/AttachmentDialog.svelte +1 -1
  51. package/dist/fields/AttachmentEditor.svelte +1 -1
  52. package/dist/fields/AttachmentPreview.svelte +1 -1
  53. package/dist/fields/BaseAutomations.svelte +1 -1
  54. package/dist/fields/BaseChartView.svelte +1 -1
  55. package/dist/fields/BaseDashboardView.svelte +1 -1
  56. package/dist/fields/BaseImport.svelte +1 -1
  57. package/dist/fields/BaseInboxView.svelte +1 -1
  58. package/dist/fields/BaseListView.svelte +1 -1
  59. package/dist/fields/BaseSearch.svelte +1 -1
  60. package/dist/fields/BaseTableView.svelte +1 -1
  61. package/dist/fields/BaseTabs.svelte +1 -1
  62. package/dist/fields/BaseTrash.svelte +1 -1
  63. package/dist/fields/CheckboxCell.svelte +1 -1
  64. package/dist/fields/ChecklistEditor.svelte +1 -1
  65. package/dist/fields/ColorEditor.svelte +1 -1
  66. package/dist/fields/DashboardRecords.svelte +1 -1
  67. package/dist/fields/DashboardTileEditor.svelte +1 -1
  68. package/dist/fields/DeleteFieldConfirm.svelte +1 -1
  69. package/dist/fields/DeleteRecordConfirm.svelte +1 -1
  70. package/dist/fields/FieldEditor.svelte +1 -1
  71. package/dist/fields/FieldInput.svelte +1 -1
  72. package/dist/fields/FieldsHeaderEnd.svelte +1 -1
  73. package/dist/fields/FootRowAdder.svelte +1 -1
  74. package/dist/fields/GroupHeader.svelte +1 -1
  75. package/dist/fields/LinkPickerEditor.svelte +1 -1
  76. package/dist/fields/LinkPreview.svelte +1 -1
  77. package/dist/fields/LinkedRecordView.svelte +1 -1
  78. package/dist/fields/LinkedRecordsCell.svelte +1 -1
  79. package/dist/fields/ListChips.svelte +1 -1
  80. package/dist/fields/LongTextEditor.svelte +1 -1
  81. package/dist/fields/MentionInput.svelte +1 -1
  82. package/dist/fields/NumberEditor.svelte +1 -1
  83. package/dist/fields/OptionsEditor.svelte +1 -1
  84. package/dist/fields/PercentCell.svelte +1 -1
  85. package/dist/fields/PropertyInput.svelte +1 -1
  86. package/dist/fields/RatingCell.svelte +1 -1
  87. package/dist/fields/RatingEditor.svelte +1 -1
  88. package/dist/fields/RecordView.svelte +1 -1
  89. package/dist/fields/RowHeader.svelte +1 -1
  90. package/dist/fields/SelectCell.svelte +1 -1
  91. package/dist/fields/SelectEditor.svelte +1 -1
  92. package/dist/fields/SummaryCell.svelte +1 -1
  93. package/dist/fields/SvBase.svelte +1 -1
  94. package/dist/fields/SvBaseForm.svelte +1 -1
  95. package/dist/fields/SvBaseViewBar.svelte +1 -1
  96. package/dist/fields/TimeOfDayEditor.svelte +1 -1
  97. package/dist/fields/UserCell.svelte +1 -1
  98. package/dist/fields/viewbar/ChartPanel.svelte +1 -1
  99. package/dist/fields/viewbar/ColorPanel.svelte +1 -1
  100. package/dist/fields/viewbar/ConditionValue.svelte +1 -1
  101. package/dist/fields/viewbar/FilterPanel.svelte +1 -1
  102. package/dist/fields/viewbar/GanttPanel.svelte +1 -1
  103. package/dist/fields/viewbar/HideFieldsPanel.svelte +1 -1
  104. package/dist/fields/viewbar/ListPanel.svelte +1 -1
  105. package/dist/fields/viewbar/SortPanel.svelte +1 -1
  106. package/dist/fields/viewbar/ViewsMenu.svelte +1 -1
  107. package/dist/gantt/SvGridGantt.svelte +1 -1
  108. package/dist/node/studio.js +1 -1
  109. package/dist/review/RichCellMark.svelte +1 -1
  110. package/dist/review/SvReviewPanel.svelte +1 -1
  111. package/dist/server/SvGroupCell.svelte +1 -1
  112. package/dist/server/SvRowGroupPanel.svelte +1 -1
  113. package/dist/version.d.ts +2 -2
  114. package/dist/version.js +1 -1
  115. package/dist/wc/sv-base-element.js +39 -39
  116. package/dist/wc/sv-sheet-element.js +27 -27
  117. package/package.json +5 -4
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{copyObject}from"./sheet/objects";import{colToLetters}from"./sheet/address";let{open=$bindable(false),chart,seriesLabels=[],onApply,onDelete,onClose}=$props();const t=useSheetText();let type=$state("bar");let title=$state("");let headers=$state(true);let series=$state("columns");let stacked=$state(false);let trend=$state("");let secondary=$state("");let first=$state(null);$effect(()=>{if(!open)return;type=chart.type;title=chart.title??"";headers=chart.headers;series=chart.series;stacked=Boolean(chart.stacked);trend=chart.trend??"";secondary=chart.secondary??"";queueMicrotask(()=>first?.focus())});const rangeText=$derived.by(()=>{const[r1,c1,r2,c2]=chart.range;return`${colToLetters(c1)}${r1+1}:${colToLetters(c2)}${r2+1}`});const stackable=$derived(type==="bar"||type==="area"||type==="line");const twoAxes=$derived(type!=="pie");function ok(){const next=copyObject(chart);next.type=type;next.headers=headers;next.series=series;if(title.trim())next.title=title.trim();else delete next.title;if(stacked&&stackable)next.stacked=true;else delete next.stacked;if(trend&&twoAxes)next.trend=trend;else delete next.trend;if(secondary&&twoAxes&&seriesLabels.includes(secondary))next.secondary=secondary;else delete next.secondary;open=false;onApply(next);onClose?.()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";import{SHEET_CHART_TYPES,SHEET_CHART_TRENDS,copyObject}from"./sheet/objects";import{colToLetters}from"./sheet/address";let{open=$bindable(false),chart,seriesLabels=[],onApply,onDelete,onClose}=$props();const t=useSheetText();let type=$state("bar");let title=$state("");let headers=$state(true);let series=$state("columns");let stacked=$state(false);let trend=$state("");let secondary=$state("");let first=$state(null);$effect(()=>{if(!open)return;type=chart.type;title=chart.title??"";headers=chart.headers;series=chart.series;stacked=Boolean(chart.stacked);trend=chart.trend??"";secondary=chart.secondary??"";queueMicrotask(()=>first?.focus())});const rangeText=$derived.by(()=>{const[r1,c1,r2,c2]=chart.range;return`${colToLetters(c1)}${r1+1}:${colToLetters(c2)}${r2+1}`});const stackable=$derived(type==="bar"||type==="area"||type==="line");const twoAxes=$derived(type!=="pie");function ok(){const next=copyObject(chart);next.type=type;next.headers=headers;next.series=series;if(title.trim())next.title=title.trim();else delete next.title;if(stacked&&stackable)next.stacked=true;else delete next.stacked;if(trend&&twoAxes)next.trend=trend;else delete next.trend;if(secondary&&twoAxes&&seriesLabels.includes(secondary))next.secondary=secondary;else delete next.secondary;open=false;onApply(next);onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('chartSetup.title')} size="sm">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{CF_PRESET_STYLES}from"./sheet/conditional-formats";let{open=$bindable(false),preset,rule=null,address,onApply,onClose}=$props();const t=useSheetText();let value1=$state("");let value2=$state("");let rank=$state("10");let percent=$state(false);let unique=$state(false);let styleId=$state(CF_PRESET_STYLES[0].id);let first=$state(null);$effect(()=>{if(!open)return;value1="";value2="";rank="10";percent=false;unique=false;styleId=CF_PRESET_STYLES[0].id;const r=rule;if(r){if(r.kind==="cellIs"){value1=r.value1;value2=r.value2??""}else if(r.kind==="text")value1=r.value;else if(r.kind==="duplicates")unique=!!r.unique;else if(r.kind==="topBottom"){rank=String(r.rank);percent=!!r.percent}else if(r.kind==="formula")value1=r.formula;const match=CF_PRESET_STYLES.find(p=>JSON.stringify(p.style)===JSON.stringify(r.style));if(match)styleId=match.id}queueMicrotask(()=>first?.focus())});const needsValue=$derived(preset==="greater"||preset==="less"||preset==="between"||preset==="equal"||preset==="text"||preset==="formula");const valid=$derived((!needsValue||value1.trim()!=="")&&(preset!=="between"||value2.trim()!=="")&&(preset!=="top10"&&preset!=="bottom10"||Number.isInteger(Number(rank))&&Number(rank)>0));function body(){const style=CF_PRESET_STYLES.find(p=>p.id===styleId)?.style??CF_PRESET_STYLES[0].style;switch(preset){case"greater":return{kind:"cellIs",operator:"greater",value1:value1.trim(),style};case"less":return{kind:"cellIs",operator:"less",value1:value1.trim(),style};case"between":return{kind:"cellIs",operator:"between",value1:value1.trim(),value2:value2.trim(),style};case"equal":return{kind:"cellIs",operator:"equal",value1:value1.trim(),style};case"text":return{kind:"text",match:"contains",value:value1.trim(),style};case"duplicates":return{kind:"duplicates",unique,style};case"top10":return{kind:"topBottom",top:true,rank:Number(rank),percent,style};case"bottom10":return{kind:"topBottom",top:false,rank:Number(rank),percent,style};case"aboveAverage":return{kind:"average",above:true,style};case"belowAverage":return{kind:"average",above:false,style};case"formula":{const text=value1.trim();return{kind:"formula",formula:text.startsWith("=")?text:`=${text}`,style}}}}function ok(){if(!valid)return;onApply(body());open=false;onClose?.()}function close(){open=false;onClose?.()}const sample=$derived(CF_PRESET_STYLES.find(p=>p.id===styleId)?.style??{});
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";import{CF_PRESET_STYLES}from"./sheet/conditional-formats";let{open=$bindable(false),preset,rule=null,address,onApply,onClose}=$props();const t=useSheetText();let value1=$state("");let value2=$state("");let rank=$state("10");let percent=$state(false);let unique=$state(false);let styleId=$state(CF_PRESET_STYLES[0].id);let first=$state(null);$effect(()=>{if(!open)return;value1="";value2="";rank="10";percent=false;unique=false;styleId=CF_PRESET_STYLES[0].id;const r=rule;if(r){if(r.kind==="cellIs"){value1=r.value1;value2=r.value2??""}else if(r.kind==="text")value1=r.value;else if(r.kind==="duplicates")unique=!!r.unique;else if(r.kind==="topBottom"){rank=String(r.rank);percent=!!r.percent}else if(r.kind==="formula")value1=r.formula;const match=CF_PRESET_STYLES.find(p=>JSON.stringify(p.style)===JSON.stringify(r.style));if(match)styleId=match.id}queueMicrotask(()=>first?.focus())});const needsValue=$derived(preset==="greater"||preset==="less"||preset==="between"||preset==="equal"||preset==="text"||preset==="formula");const valid=$derived((!needsValue||value1.trim()!=="")&&(preset!=="between"||value2.trim()!=="")&&(preset!=="top10"&&preset!=="bottom10"||Number.isInteger(Number(rank))&&Number(rank)>0));function body(){const style=CF_PRESET_STYLES.find(p=>p.id===styleId)?.style??CF_PRESET_STYLES[0].style;switch(preset){case"greater":return{kind:"cellIs",operator:"greater",value1:value1.trim(),style};case"less":return{kind:"cellIs",operator:"less",value1:value1.trim(),style};case"between":return{kind:"cellIs",operator:"between",value1:value1.trim(),value2:value2.trim(),style};case"equal":return{kind:"cellIs",operator:"equal",value1:value1.trim(),style};case"text":return{kind:"text",match:"contains",value:value1.trim(),style};case"duplicates":return{kind:"duplicates",unique,style};case"top10":return{kind:"topBottom",top:true,rank:Number(rank),percent,style};case"bottom10":return{kind:"topBottom",top:false,rank:Number(rank),percent,style};case"aboveAverage":return{kind:"average",above:true,style};case"belowAverage":return{kind:"average",above:false,style};case"formula":{const text=value1.trim();return{kind:"formula",formula:text.startsWith("=")?text:`=${text}`,style}}}}function ok(){if(!valid)return;onApply(body());open=false;onClose?.()}function close(){open=false;onClose?.()}const sample=$derived(CF_PRESET_STYLES.find(p=>p.id===styleId)?.style??{});
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t(`cf.title.${preset}`)} size="sm" width={440}>
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{OPERATOR_LABELS}from"./sheet/validation";let{open=$bindable(false),rule,address,onApply,onClear,onClose}=$props();const t=useSheetText();let tab=$state("settings");const ALLOWS=[{id:"any",label:"validation.allow.any"},{id:"whole",label:"validation.allow.whole"},{id:"decimal",label:"validation.allow.decimal"},{id:"list",label:"validation.allow.list"},{id:"date",label:"validation.allow.date"},{id:"textLength",label:"validation.allow.textLength"},{id:"custom",label:"validation.allow.custom"}];const OPERATORS=Object.keys(OPERATOR_LABELS);let allow=$state("any");let operator=$state("between");let value1=$state("");let value2=$state("");let ignoreBlank=$state(true);let inCellDropdown=$state(true);let style=$state("stop");let title=$state("");let message=$state("");let showInput=$state(true);let inputTitle=$state("");let inputMessage=$state("");let first=$state(null);$effect(()=>{if(!open)return;tab="settings";allow=rule?.allow??"any";operator=rule?.operator??"between";value1=rule?.value1??"";value2=rule?.value2??"";ignoreBlank=rule?.ignoreBlank??true;inCellDropdown=rule?.inCellDropdown??true;style=rule?.alert.style??"stop";title=rule?.alert.title??"";message=rule?.alert.message??"";showInput=rule?rule.input!==void 0:true;inputTitle=rule?.input?.title??"";inputMessage=rule?.input?.message??"";queueMicrotask(()=>first?.focus())});const bounded=$derived(allow==="whole"||allow==="decimal"||allow==="date"||allow==="textLength");const twoBounds=$derived(operator==="between"||operator==="notBetween");const firstLabel=$derived(allow==="list"?t("validation.source"):allow==="custom"?t("validation.formula"):twoBounds?t(allow==="date"?"validation.startDate":"validation.minimum"):t(allow==="date"?"validation.date":allow==="textLength"?"validation.length":"validation.value"));const secondLabel=$derived(t(allow==="date"?"validation.endDate":"validation.maximum"));const valid=$derived(allow==="any"||allow==="list"&&value1.trim()!==""||allow==="custom"&&value1.trim()!==""||bounded&&value1.trim()!==""&&(!twoBounds||value2.trim()!==""));function ok(){if(!valid)return;const spec={allow,ignoreBlank,inCellDropdown:allow==="list"?inCellDropdown:false,alert:{style,title:title.trim()||void 0,message:message.trim()||void 0}};if(showInput&&(inputTitle.trim()||inputMessage.trim())){spec.input={title:inputTitle.trim()||void 0,message:inputMessage.trim()||void 0}}if(bounded){spec.operator=operator;spec.value1=value1.trim();if(twoBounds)spec.value2=value2.trim()}else if(allow==="list"||allow==="custom"){spec.value1=value1.trim()}onApply(spec);open=false;onClose?.()}function clearAll(){onClear();open=false;onClose?.()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";import{OPERATOR_LABELS}from"./sheet/validation";let{open=$bindable(false),rule,address,onApply,onClear,onClose}=$props();const t=useSheetText();let tab=$state("settings");const ALLOWS=[{id:"any",label:"validation.allow.any"},{id:"whole",label:"validation.allow.whole"},{id:"decimal",label:"validation.allow.decimal"},{id:"list",label:"validation.allow.list"},{id:"date",label:"validation.allow.date"},{id:"textLength",label:"validation.allow.textLength"},{id:"custom",label:"validation.allow.custom"}];const OPERATORS=Object.keys(OPERATOR_LABELS);let allow=$state("any");let operator=$state("between");let value1=$state("");let value2=$state("");let ignoreBlank=$state(true);let inCellDropdown=$state(true);let style=$state("stop");let title=$state("");let message=$state("");let showInput=$state(true);let inputTitle=$state("");let inputMessage=$state("");let first=$state(null);$effect(()=>{if(!open)return;tab="settings";allow=rule?.allow??"any";operator=rule?.operator??"between";value1=rule?.value1??"";value2=rule?.value2??"";ignoreBlank=rule?.ignoreBlank??true;inCellDropdown=rule?.inCellDropdown??true;style=rule?.alert.style??"stop";title=rule?.alert.title??"";message=rule?.alert.message??"";showInput=rule?rule.input!==void 0:true;inputTitle=rule?.input?.title??"";inputMessage=rule?.input?.message??"";queueMicrotask(()=>first?.focus())});const bounded=$derived(allow==="whole"||allow==="decimal"||allow==="date"||allow==="textLength");const twoBounds=$derived(operator==="between"||operator==="notBetween");const firstLabel=$derived(allow==="list"?t("validation.source"):allow==="custom"?t("validation.formula"):twoBounds?t(allow==="date"?"validation.startDate":"validation.minimum"):t(allow==="date"?"validation.date":allow==="textLength"?"validation.length":"validation.value"));const secondLabel=$derived(t(allow==="date"?"validation.endDate":"validation.maximum"));const valid=$derived(allow==="any"||allow==="list"&&value1.trim()!==""||allow==="custom"&&value1.trim()!==""||bounded&&value1.trim()!==""&&(!twoBounds||value2.trim()!==""));function ok(){if(!valid)return;const spec={allow,ignoreBlank,inCellDropdown:allow==="list"?inCellDropdown:false,alert:{style,title:title.trim()||void 0,message:message.trim()||void 0}};if(showInput&&(inputTitle.trim()||inputMessage.trim())){spec.input={title:inputTitle.trim()||void 0,message:inputMessage.trim()||void 0}}if(bounded){spec.operator=operator;spec.value1=value1.trim();if(twoBounds)spec.value2=value2.trim()}else if(allow==="list"||allow==="custom"){spec.value1=value1.trim()}onApply(spec);open=false;onClose?.()}function clearAll(){onClear();open=false;onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('validation.title')} size="sm" width={400}>
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{newEditRangeId,parseRangeText,rangeText}from"./sheet/protection";let{open=$bindable(false),ranges,selection,onApply,onProtect,onClose}=$props();const t=useSheetText();let working=$state([]);let newTitle=$state("");let newRefers=$state("");let editing=$state(null);let editTitle=$state("");let editRefers=$state("");let problem=$state(null);let titleBox=$state(null);$effect(()=>{if(!open)return;const copy=ranges.map(r=>({...r,rects:r.rects.map(([r1,c1,r2,c2])=>[r1,c1,r2,c2])}));working=copy;newTitle=`Range${copy.length+1}`;newRefers=selection;editing=null;problem=null;queueMicrotask(()=>titleBox?.focus())});function add(){const rects=parseRangeText(newRefers);if(!rects){problem=t("editRanges.invalidRef",{text:newRefers});return}const title=newTitle.trim()||`Range${working.length+1}`;working=[...working,{id:newEditRangeId(),title,rects}];newTitle=`Range${working.length+1}`;newRefers="";problem=null}function startEdit(range){editing=range.id;editTitle=range.title;editRefers=rangeText(range.rects);problem=null}function saveEdit(){const rects=parseRangeText(editRefers);if(!rects){problem=t("editRanges.invalidRef",{text:editRefers});return}working=working.map(r=>r.id===editing?{...r,title:editTitle.trim()||r.title,rects}:r);editing=null;problem=null}function remove(id){working=working.filter(r=>r.id!==id);if(editing===id)editing=null}function ok(){open=false;onApply(working);onClose?.()}function protect(){open=false;onApply(working);onProtect()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";import{newEditRangeId,parseRangeText,rangeText}from"./sheet/protection";let{open=$bindable(false),ranges,selection,onApply,onProtect,onClose}=$props();const t=useSheetText();let working=$state([]);let newTitle=$state("");let newRefers=$state("");let editing=$state(null);let editTitle=$state("");let editRefers=$state("");let problem=$state(null);let titleBox=$state(null);$effect(()=>{if(!open)return;const copy=ranges.map(r=>({...r,rects:r.rects.map(([r1,c1,r2,c2])=>[r1,c1,r2,c2])}));working=copy;newTitle=`Range${copy.length+1}`;newRefers=selection;editing=null;problem=null;queueMicrotask(()=>titleBox?.focus())});function add(){const rects=parseRangeText(newRefers);if(!rects){problem=t("editRanges.invalidRef",{text:newRefers});return}const title=newTitle.trim()||`Range${working.length+1}`;working=[...working,{id:newEditRangeId(),title,rects}];newTitle=`Range${working.length+1}`;newRefers="";problem=null}function startEdit(range){editing=range.id;editTitle=range.title;editRefers=rangeText(range.rects);problem=null}function saveEdit(){const rects=parseRangeText(editRefers);if(!rects){problem=t("editRanges.invalidRef",{text:editRefers});return}working=working.map(r=>r.id===editing?{...r,title:editTitle.trim()||r.title,rects}:r);editing=null;problem=null}function remove(id){working=working.filter(r=>r.id!==id);if(editing===id)editing=null}function ok(){open=false;onApply(working);onClose?.()}function protect(){open=false;onApply(working);onProtect()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('editRanges.title')} size="md">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{untrack}from"svelte";import{useSheetText}from"./sheet-text";import{colToLetters}from"./sheet/address";import{checkSheet}from"./sheet/error-check";let{open=$bindable(false),workbook,sheet,onGoTo,onSteps,onClose}=$props();const t=useSheetText();let findings=$state([]);let at=$state(0);let nextButton=$state(null);const current=$derived(findings[at]??null);const address=$derived(current?`${colToLetters(current.col)}${current.row+1}`:"");$effect(()=>{if(!open)return;untrack(load)});function load(){const found=checkSheet(sheet,{rowCount:()=>workbook.rowCount(sheet),colCount:()=>workbook.colCount(sheet),getRaw:(row,col)=>workbook.getRaw(sheet,row,col),getValue:(row,col)=>workbook.getValue(sheet,row,col)});findings=found;at=0;show(found[0]);queueMicrotask(()=>nextButton?.focus())}function show(finding){if(finding)onGoTo({row:finding.row,col:finding.col})}function move(by){const list=findings;if(list.length===0)return;at=(at+by+list.length)%list.length;show(list[at])}function close(){open=false;onClose?.()}
2
+ import{untrack}from"svelte";import{SvModal}from"@svgrid/grid";import{useSheetText}from"./sheet-text";import{colToLetters}from"./sheet/address";import{checkSheet,describeFinding}from"./sheet/error-check";let{open=$bindable(false),workbook,sheet,onGoTo,onSteps,onClose}=$props();const t=useSheetText();let findings=$state([]);let at=$state(0);let nextButton=$state(null);const current=$derived(findings[at]??null);const address=$derived(current?`${colToLetters(current.col)}${current.row+1}`:"");$effect(()=>{if(!open)return;untrack(load)});function load(){const found=checkSheet(sheet,{rowCount:()=>workbook.rowCount(sheet),colCount:()=>workbook.colCount(sheet),getRaw:(row,col)=>workbook.getRaw(sheet,row,col),getValue:(row,col)=>workbook.getValue(sheet,row,col)});findings=found;at=0;show(found[0]);queueMicrotask(()=>nextButton?.focus())}function show(finding){if(finding)onGoTo({row:finding.row,col:finding.col})}function move(by){const list=findings;if(list.length===0)return;at=(at+by+list.length)%list.length;show(list[at])}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('errors.title')} size="sm">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{untrack}from"svelte";import{useSheetText}from"./sheet-text";import{colToLetters}from"./sheet/address";import{parseFormula}from"./sheet/parse";import{evaluationSteps}from"./sheet/evaluate-steps";let{open=$bindable(false),workbook,sheet,cell,onClose}=$props();const t=useSheetText();let steps=$state([]);let at=$state(0);let problem=$state("");let evaluateButton=$state(null);const address=$derived(`${sheet}!${colToLetters(cell.col)}${cell.row+1}`);const current=$derived(steps[at]??null);const finished=$derived(steps.length>0&&at>=steps.length);const answer=$derived(steps.length>0?steps[steps.length-1].value:null);$effect(()=>{if(!open)return;const target=cell;untrack(()=>walk(target))});function walk(target){at=0;problem="";steps=[];const text=workbook.getRaw(sheet,target.row,target.col).trim();if(!text.startsWith("=")){problem=t("evaluate.noFormula");return}try{steps=evaluationSteps(parseFormula(text),formula=>workbook.evaluateText(sheet,formula,void 0,{row:target.row,col:target.col}))}catch{problem=t("evaluate.noFormula")}queueMicrotask(()=>evaluateButton?.focus())}function close(){open=false;onClose?.()}
2
+ import{untrack}from"svelte";import{SvModal}from"@svgrid/grid";import{useSheetText}from"./sheet-text";import{colToLetters}from"./sheet/address";import{parseFormula}from"./sheet/parse";import{evaluationSteps,printValue}from"./sheet/evaluate-steps";let{open=$bindable(false),workbook,sheet,cell,onClose}=$props();const t=useSheetText();let steps=$state([]);let at=$state(0);let problem=$state("");let evaluateButton=$state(null);const address=$derived(`${sheet}!${colToLetters(cell.col)}${cell.row+1}`);const current=$derived(steps[at]??null);const finished=$derived(steps.length>0&&at>=steps.length);const answer=$derived(steps.length>0?steps[steps.length-1].value:null);$effect(()=>{if(!open)return;const target=cell;untrack(()=>walk(target))});function walk(target){at=0;problem="";steps=[];const text=workbook.getRaw(sheet,target.row,target.col).trim();if(!text.startsWith("=")){problem=t("evaluate.noFormula");return}try{steps=evaluationSteps(parseFormula(text),formula=>workbook.evaluateText(sheet,formula,void 0,{row:target.row,col:target.col}))}catch{problem=t("evaluate.noFormula")}queueMicrotask(()=>evaluateButton?.focus())}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('evaluate.title')} size="md">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{findAll,findNext,replaceOne,replaceAll}from"./sheet/find-replace";let{open=$bindable(false),cmd,onClose}=$props();const t=useSheetText();let findText=$state("");let replaceText=$state("");let matchCase=$state(false);let entireCell=$state(false);let lookIn=$state("values");let status=$state("");let findInput=$state(null);const options=()=>({matchCase,matchEntireCell:entireCell,lookIn});$effect(()=>{if(open){status="";queueMicrotask(()=>findInput?.focus())}});function land(hit){const c=cmd();if(!c)return;if(!hit){status=findText?t("findReplace.notFound"):"";return}c.setActiveCell(hit.rowIndex,hit.colIndex);c.setSelection(hit.rowIndex,hit.colIndex);c.scrollIntoView(hit.rowIndex,hit.colIndex);status=""}function next(direction=1){const c=cmd();if(!c||!findText)return;land(findNext(c,findText,options(),direction))}function countAll(){const c=cmd();if(!c||!findText)return;const n=findAll(c,findText,options()).length;status=n===0?t("findReplace.notFound"):t(n===1?"findReplace.cellFound":"findReplace.cellsFound",{count:n})}function replace(){const c=cmd();if(!c||!findText)return;replaceOne(c,findText,replaceText,options())}function all(){const c=cmd();if(!c||!findText)return;const n=replaceAll(c,findText,replaceText,options());status=n===0?t("findReplace.nothingToReplace"):t(n===1?"findReplace.replacedOne":"findReplace.replacedMany",{count:n})}function close(){open=false;onClose?.()}function onKey(event){if(event.key==="Enter"){event.preventDefault();next(event.shiftKey?-1:1)}}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";import{findAll,findNext,replaceOne,replaceAll}from"./sheet/find-replace";let{open=$bindable(false),cmd,onClose}=$props();const t=useSheetText();let findText=$state("");let replaceText=$state("");let matchCase=$state(false);let entireCell=$state(false);let lookIn=$state("values");let status=$state("");let findInput=$state(null);const options=()=>({matchCase,matchEntireCell:entireCell,lookIn});$effect(()=>{if(open){status="";queueMicrotask(()=>findInput?.focus())}});function land(hit){const c=cmd();if(!c)return;if(!hit){status=findText?t("findReplace.notFound"):"";return}c.setActiveCell(hit.rowIndex,hit.colIndex);c.setSelection(hit.rowIndex,hit.colIndex);c.scrollIntoView(hit.rowIndex,hit.colIndex);status=""}function next(direction=1){const c=cmd();if(!c||!findText)return;land(findNext(c,findText,options(),direction))}function countAll(){const c=cmd();if(!c||!findText)return;const n=findAll(c,findText,options()).length;status=n===0?t("findReplace.notFound"):t(n===1?"findReplace.cellFound":"findReplace.cellsFound",{count:n})}function replace(){const c=cmd();if(!c||!findText)return;replaceOne(c,findText,replaceText,options())}function all(){const c=cmd();if(!c||!findText)return;const n=replaceAll(c,findText,replaceText,options());status=n===0?t("findReplace.nothingToReplace"):t(n===1?"findReplace.replacedOne":"findReplace.replacedMany",{count:n})}function close(){open=false;onClose?.()}function onKey(event){if(event.key==="Enter"){event.preventDefault();next(event.shiftKey?-1:1)}}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('findReplace.title')} size="sm">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{compileNumberFormat,FORMAT_PRESETS,SPECIAL_FORMATS,formatCategory,accountingPattern,accountingParts}from"./sheet/number-format";let{open=$bindable(false),entry,sample,mixedLocked=false,onApply,onClose}=$props();const t=useSheetText();const TABS=[{id:"number",label:"formatCells.tab.number"},{id:"alignment",label:"formatCells.tab.alignment"},{id:"font",label:"formatCells.tab.font"},{id:"border",label:"formatCells.tab.border"},{id:"fill",label:"formatCells.tab.fill"},{id:"protection",label:"formatCells.tab.protection"}];let tab=$state("number");const CATEGORIES=[{id:"general",label:"formatCells.category.general"},{id:"number",label:"formatCells.category.number"},{id:"currency",label:"formatCells.category.currency"},{id:"accounting",label:"formatCells.category.accounting"},{id:"percent",label:"formatCells.category.percent"},{id:"date",label:"formatCells.category.date"},{id:"time",label:"formatCells.category.time"},{id:"scientific",label:"formatCells.category.scientific"},{id:"special",label:"formatCells.category.special"},{id:"custom",label:"formatCells.category.custom"}];const SYMBOLS=[{value:"$",label:"$"},{value:"",label:"formatCells.symbol.none"},{value:"€",label:"formatCells.symbol.euro"},{value:"£",label:"formatCells.symbol.pound"},{value:"¥",label:"formatCells.symbol.yen"}];const SPECIALS=Object.keys(SPECIAL_FORMATS);let category=$state("general");let decimals=$state(2);let thousands=$state(true);let symbol=$state("$");let special=$state("zip");let custom=$state("");let align=$state("");let valign=$state("center");let wrap=$state(false);let indent=$state(0);let fontFamily=$state("");let fontSize=$state("");let bold=$state(false);let italic=$state(false);let underline=$state(false);let strike=$state(false);let colorAuto=$state(true);let color=$state("#000000");let border=$state("");let fill=$state(null);let locked=$state(true);let initial={};let initialColor="#000000";const categoryOf=fmt=>formatCategory(fmt);const zeros=n=>n>0?"."+"0".repeat(n):"";const pattern=$derived.by(()=>{switch(category){case"general":return void 0;case"number":return`${thousands?"#,##":""}0${zeros(decimals)}`;case"currency":return`$#,##0${zeros(decimals)};($#,##0${zeros(decimals)})`;case"accounting":return accountingPattern(symbol,decimals);case"special":return SPECIAL_FORMATS[special].pattern;case"percent":return`0${zeros(decimals)}%`;case"date":return FORMAT_PRESETS.date;case"time":return FORMAT_PRESETS.time;case"scientific":return`0${zeros(decimals)}E+00`;case"custom":return custom||void 0}});const preview=$derived.by(()=>{if(sample===""||sample==null)return"";if(!pattern)return String(sample);try{return compileNumberFormat(pattern).format(sample).text}catch{return String(sample)}});$effect(()=>{if(!open)return;initial={...entry??{}};const num=categoryOf(initial.numFmt);category=num.category;decimals=num.decimals;thousands=num.thousands;symbol=accountingParts(initial.numFmt)?.symbol??"$";special=SPECIALS.find(id=>SPECIAL_FORMATS[id].pattern===initial.numFmt)??"zip";custom=initial.numFmt??"";align=initial.align??"";valign=initial.valign??"center";wrap=initial.wrap??false;indent=initial.indent??0;fontFamily=initial.fontFamily??"";fontSize=initial.fontSize?String(initial.fontSize):"";bold=!!initial.bold;italic=!!initial.italic;underline=!!initial.underline;strike=!!initial.strike;colorAuto=!initial.color;color=/^#[0-9a-f]{6}$/i.test(initial.color??"")?initial.color:"#000000";initialColor=color;border="";fill=initial.fill??null;locked=mixedLocked?null:initial.locked!==false});function ok(){const patch={};const set=(key,next)=>{if(initial[key]!==next)patch[key]=next};set("numFmt",pattern);set("align",align||void 0);set("valign",valign==="center"?void 0:valign);set("wrap",wrap||void 0);set("indent",indent>0?indent:void 0);set("fontFamily",fontFamily||void 0);set("fontSize",fontSize?Number(fontSize):void 0);set("bold",bold||void 0);set("italic",italic||void 0);set("underline",underline||void 0);set("strike",strike||void 0);set("color",colorAuto?void 0:color===initialColor?initial.color:color);set("fill",fill??void 0);if(locked!==null){const next=locked?void 0:false;if(mixedLocked||initial.locked!==next)patch.locked=next}onApply(patch,border||null);open=false;onClose?.()}function close(){open=false;onClose?.()}const BORDERS=[{value:"none",label:"formatCells.border.none"},{value:"outside",label:"formatCells.border.outside"},{value:"all",label:"formatCells.border.all"},{value:"top",label:"formatCells.border.top"},{value:"bottom",label:"formatCells.border.bottom"},{value:"left",label:"formatCells.border.left"},{value:"right",label:"formatCells.border.right"},{value:"thick-bottom",label:"formatCells.border.thick-bottom"}];
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";import{compileNumberFormat,FORMAT_PRESETS,SPECIAL_FORMATS,formatCategory,accountingPattern,accountingParts}from"./sheet/number-format";import{FONT_FAMILIES,FONT_SIZES}from"./sheet/ribbon";import{ALL_COLOURS}from"./sheet/palette";let{open=$bindable(false),entry,sample,mixedLocked=false,onApply,onClose}=$props();const t=useSheetText();const TABS=[{id:"number",label:"formatCells.tab.number"},{id:"alignment",label:"formatCells.tab.alignment"},{id:"font",label:"formatCells.tab.font"},{id:"border",label:"formatCells.tab.border"},{id:"fill",label:"formatCells.tab.fill"},{id:"protection",label:"formatCells.tab.protection"}];let tab=$state("number");const CATEGORIES=[{id:"general",label:"formatCells.category.general"},{id:"number",label:"formatCells.category.number"},{id:"currency",label:"formatCells.category.currency"},{id:"accounting",label:"formatCells.category.accounting"},{id:"percent",label:"formatCells.category.percent"},{id:"date",label:"formatCells.category.date"},{id:"time",label:"formatCells.category.time"},{id:"scientific",label:"formatCells.category.scientific"},{id:"special",label:"formatCells.category.special"},{id:"custom",label:"formatCells.category.custom"}];const SYMBOLS=[{value:"$",label:"$"},{value:"",label:"formatCells.symbol.none"},{value:"€",label:"formatCells.symbol.euro"},{value:"£",label:"formatCells.symbol.pound"},{value:"¥",label:"formatCells.symbol.yen"}];const SPECIALS=Object.keys(SPECIAL_FORMATS);let category=$state("general");let decimals=$state(2);let thousands=$state(true);let symbol=$state("$");let special=$state("zip");let custom=$state("");let align=$state("");let valign=$state("center");let wrap=$state(false);let indent=$state(0);let fontFamily=$state("");let fontSize=$state("");let bold=$state(false);let italic=$state(false);let underline=$state(false);let strike=$state(false);let colorAuto=$state(true);let color=$state("#000000");let border=$state("");let fill=$state(null);let locked=$state(true);let initial={};let initialColor="#000000";const categoryOf=fmt=>formatCategory(fmt);const zeros=n=>n>0?"."+"0".repeat(n):"";const pattern=$derived.by(()=>{switch(category){case"general":return void 0;case"number":return`${thousands?"#,##":""}0${zeros(decimals)}`;case"currency":return`$#,##0${zeros(decimals)};($#,##0${zeros(decimals)})`;case"accounting":return accountingPattern(symbol,decimals);case"special":return SPECIAL_FORMATS[special].pattern;case"percent":return`0${zeros(decimals)}%`;case"date":return FORMAT_PRESETS.date;case"time":return FORMAT_PRESETS.time;case"scientific":return`0${zeros(decimals)}E+00`;case"custom":return custom||void 0}});const preview=$derived.by(()=>{if(sample===""||sample==null)return"";if(!pattern)return String(sample);try{return compileNumberFormat(pattern).format(sample).text}catch{return String(sample)}});$effect(()=>{if(!open)return;initial={...entry??{}};const num=categoryOf(initial.numFmt);category=num.category;decimals=num.decimals;thousands=num.thousands;symbol=accountingParts(initial.numFmt)?.symbol??"$";special=SPECIALS.find(id=>SPECIAL_FORMATS[id].pattern===initial.numFmt)??"zip";custom=initial.numFmt??"";align=initial.align??"";valign=initial.valign??"center";wrap=initial.wrap??false;indent=initial.indent??0;fontFamily=initial.fontFamily??"";fontSize=initial.fontSize?String(initial.fontSize):"";bold=!!initial.bold;italic=!!initial.italic;underline=!!initial.underline;strike=!!initial.strike;colorAuto=!initial.color;color=/^#[0-9a-f]{6}$/i.test(initial.color??"")?initial.color:"#000000";initialColor=color;border="";fill=initial.fill??null;locked=mixedLocked?null:initial.locked!==false});function ok(){const patch={};const set=(key,next)=>{if(initial[key]!==next)patch[key]=next};set("numFmt",pattern);set("align",align||void 0);set("valign",valign==="center"?void 0:valign);set("wrap",wrap||void 0);set("indent",indent>0?indent:void 0);set("fontFamily",fontFamily||void 0);set("fontSize",fontSize?Number(fontSize):void 0);set("bold",bold||void 0);set("italic",italic||void 0);set("underline",underline||void 0);set("strike",strike||void 0);set("color",colorAuto?void 0:color===initialColor?initial.color:color);set("fill",fill??void 0);if(locked!==null){const next=locked?void 0:false;if(mixedLocked||initial.locked!==next)patch.locked=next}onApply(patch,border||null);open=false;onClose?.()}function close(){open=false;onClose?.()}const BORDERS=[{value:"none",label:"formatCells.border.none"},{value:"outside",label:"formatCells.border.outside"},{value:"all",label:"formatCells.border.all"},{value:"top",label:"formatCells.border.top"},{value:"bottom",label:"formatCells.border.bottom"},{value:"left",label:"formatCells.border.left"},{value:"right",label:"formatCells.border.right"},{value:"thick-bottom",label:"formatCells.border.thick-bottom"}];
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('formatCells.title')} size="md">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{untrack}from"svelte";import{goalSeekCell}from"./sheet/goal-seek";import{parseA1,colToLetters}from"./sheet/address";let{open=$bindable(false),workbook,cmd,onClose}=$props();const t=useSheetText();let step=$state("ask");let setCell=$state("");let toValue=$state("");let byCell=$state("");let problem=$state(null);let found=$state(null);let firstInput=$state(null);$effect(()=>{if(!open)return;untrack(prepare)});function prepare(){const at=cmd()?.activeCell;setCell=at?`${colToLetters(at.colIndex)}${at.rowIndex+1}`:"";toValue="";byCell="";step="ask";problem=null;found=null;queueMicrotask(()=>firstInput?.focus())}function address(text){const ref=parseA1(text.trim().toUpperCase());return ref&&ref.row!==null?{row:ref.row,col:ref.col}:null}function solve(){const formula=address(setCell);const input=address(byCell);const target=Number(toValue);if(!formula){problem=t("goalSeek.notAddress",{text:setCell});return}if(!input){problem=t("goalSeek.notAddress",{text:byCell});return}if(toValue.trim()===""||!Number.isFinite(target)){problem=t("goalSeek.toValueNumber");return}const sheet=workbook.active;if(!workbook.getRaw(sheet,formula.row,formula.col).startsWith("=")){problem=t("goalSeek.needsFormula",{cell:setCell.toUpperCase()});return}if(workbook.getRaw(sheet,input.row,input.col).startsWith("=")){problem=`${byCell.toUpperCase()} must contain a value, not a formula`;return}found=goalSeekCell(workbook,{sheet,...formula},{sheet,...input},target,{maxIterations:100});problem=null;step="done"}function keep(){const input=address(byCell);const c=cmd();if(!input||!found||!c)return;c.setCellValue(input.row,input.col,String(round(found.value)));c.setActiveCell(input.row,input.col);close()}function close(){open=false;onClose?.()}const round=n=>Number(n.toFixed(4));const money=n=>n.toLocaleString("en-US",{maximumFractionDigits:2});
2
+ import{useSheetText}from"./sheet-text";import{untrack}from"svelte";import{SvModal}from"@svgrid/grid";import{goalSeekCell}from"./sheet/goal-seek";import{parseA1,colToLetters}from"./sheet/address";let{open=$bindable(false),workbook,cmd,onClose}=$props();const t=useSheetText();let step=$state("ask");let setCell=$state("");let toValue=$state("");let byCell=$state("");let problem=$state(null);let found=$state(null);let firstInput=$state(null);$effect(()=>{if(!open)return;untrack(prepare)});function prepare(){const at=cmd()?.activeCell;setCell=at?`${colToLetters(at.colIndex)}${at.rowIndex+1}`:"";toValue="";byCell="";step="ask";problem=null;found=null;queueMicrotask(()=>firstInput?.focus())}function address(text){const ref=parseA1(text.trim().toUpperCase());return ref&&ref.row!==null?{row:ref.row,col:ref.col}:null}function solve(){const formula=address(setCell);const input=address(byCell);const target=Number(toValue);if(!formula){problem=t("goalSeek.notAddress",{text:setCell});return}if(!input){problem=t("goalSeek.notAddress",{text:byCell});return}if(toValue.trim()===""||!Number.isFinite(target)){problem=t("goalSeek.toValueNumber");return}const sheet=workbook.active;if(!workbook.getRaw(sheet,formula.row,formula.col).startsWith("=")){problem=t("goalSeek.needsFormula",{cell:setCell.toUpperCase()});return}if(workbook.getRaw(sheet,input.row,input.col).startsWith("=")){problem=`${byCell.toUpperCase()} must contain a value, not a formula`;return}found=goalSeekCell(workbook,{sheet,...formula},{sheet,...input},target,{maxIterations:100});problem=null;step="done"}function keep(){const input=address(byCell);const c=cmd();if(!input||!found||!c)return;c.setCellValue(input.row,input.col,String(round(found.value)));c.setActiveCell(input.row,input.col);close()}function close(){open=false;onClose?.()}const round=n=>Number(n.toFixed(4));const money=n=>n.toLocaleString("en-US",{maximumFractionDigits:2});
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t(step === 'ask' ? 'goalSeek.title' : 'goalSeek.statusTitle')} size="sm">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{functionCatalog}from"./sheet/function-catalog";let{open=$bindable(false),onPick,onClose}=$props();const t=useSheetText();const all=functionCatalog();let search=$state("");let group=$state("All");let selected=$state(all[0]?.name??"");let searchInput=$state(null);const shown=$derived.by(()=>{const needle=search.trim().toUpperCase();return all.filter(f=>(group==="All"||f.group===group)&&(needle===""||f.name.includes(needle)||f.description.toUpperCase().includes(needle)))});const current=$derived(all.find(f=>f.name===selected)??null);$effect(()=>{if(shown.length&&!shown.some(f=>f.name===selected))selected=shown[0].name});$effect(()=>{if(open)queueMicrotask(()=>searchInput?.focus())});function ok(){if(!current)return;onPick(current.name);open=false;onClose?.()}function close(){open=false;onClose?.()}function onListKey(event){const index=shown.findIndex(f=>f.name===selected);if(event.key==="ArrowDown"){event.preventDefault();selected=shown[Math.min(index+1,shown.length-1)]?.name??selected}else if(event.key==="ArrowUp"){event.preventDefault();selected=shown[Math.max(index-1,0)]?.name??selected}else if(event.key==="Enter"){event.preventDefault();ok()}}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";import{functionCatalog,FUNCTION_GROUPS}from"./sheet/function-catalog";let{open=$bindable(false),onPick,onClose}=$props();const t=useSheetText();const all=functionCatalog();let search=$state("");let group=$state("All");let selected=$state(all[0]?.name??"");let searchInput=$state(null);const shown=$derived.by(()=>{const needle=search.trim().toUpperCase();return all.filter(f=>(group==="All"||f.group===group)&&(needle===""||f.name.includes(needle)||f.description.toUpperCase().includes(needle)))});const current=$derived(all.find(f=>f.name===selected)??null);$effect(()=>{if(shown.length&&!shown.some(f=>f.name===selected))selected=shown[0].name});$effect(()=>{if(open)queueMicrotask(()=>searchInput?.focus())});function ok(){if(!current)return;onPick(current.name);open=false;onClose?.()}function close(){open=false;onClose?.()}function onListKey(event){const index=shown.findIndex(f=>f.name===selected);if(event.key==="ArrowDown"){event.preventDefault();selected=shown[Math.min(index+1,shown.length-1)]?.name??selected}else if(event.key==="ArrowUp"){event.preventDefault();selected=shown[Math.max(index-1,0)]?.name??selected}else if(event.key==="Enter"){event.preventDefault();ok()}}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('insertFunction.title')} size="md">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";let{open=$bindable(false),iteration,onApply,onClose}=$props();const t=useSheetText();let enabled=$state(false);let passes=$state("100");let change=$state("0.001");let error=$state("");let first=$state(null);$effect(()=>{if(!open)return;enabled=iteration.enabled;passes=String(iteration.maxIterations);change=String(iteration.maxChange);error="";queueMicrotask(()=>first?.focus())});function ok(){const maxIterations=Number(passes);const maxChange=Number(change);if(!Number.isFinite(maxIterations)||maxIterations<1||!Number.isFinite(maxChange)||maxChange<0){error=t("iteration.badNumbers");return}open=false;onApply({enabled,maxIterations:Math.round(maxIterations),maxChange});onClose?.()}function close(){open=false;onClose?.()}
2
+ import{SvModal}from"@svgrid/grid";import{useSheetText}from"./sheet-text";let{open=$bindable(false),iteration,onApply,onClose}=$props();const t=useSheetText();let enabled=$state(false);let passes=$state("100");let change=$state("0.001");let error=$state("");let first=$state(null);$effect(()=>{if(!open)return;enabled=iteration.enabled;passes=String(iteration.maxIterations);change=String(iteration.maxChange);error="";queueMicrotask(()=>first?.focus())});function ok(){const maxIterations=Number(passes);const maxChange=Number(change);if(!Number.isFinite(maxIterations)||maxIterations<1||!Number.isFinite(maxChange)||maxChange<0){error=t("iteration.badNumbers");return}open=false;onApply({enabled,maxIterations:Math.round(maxIterations),maxChange});onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('iteration.title')} size="sm">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{isSafeLinkTarget,parseLinkTarget}from"./sheet/links";let{open=$bindable(false),link,text,where,existing=false,onApply,onRemove,onClose}=$props();const t=useSheetText();let address=$state("");let label=$state("");let tip=$state("");let error=$state("");let first=$state(null);$effect(()=>{if(!open)return;address=link.target;label=text;tip=link.tip??"";error="";queueMicrotask(()=>first?.focus())});function ok(){const target=parseLinkTarget(address);if(!target){error=address.trim()&&!isSafeLinkTarget(address)?t("link.unsafeScheme"):t("link.badAddress");return}const next={target:address.trim()};if(tip.trim())next.tip=tip.trim();open=false;onApply(next,label);onClose?.()}function close(){open=false;onClose?.()}
2
+ import{SvModal}from"@svgrid/grid";import{useSheetText}from"./sheet-text";import{isSafeLinkTarget,parseLinkTarget}from"./sheet/links";let{open=$bindable(false),link,text,where,existing=false,onApply,onRemove,onClose}=$props();const t=useSheetText();let address=$state("");let label=$state("");let tip=$state("");let error=$state("");let first=$state(null);$effect(()=>{if(!open)return;address=link.target;label=text;tip=link.tip??"";error="";queueMicrotask(()=>first?.focus())});function ok(){const target=parseLinkTarget(address);if(!target){error=address.trim()&&!isSafeLinkTarget(address)?t("link.unsafeScheme"):t("link.badAddress");return}const next={target:address.trim()};if(tip.trim())next.tip=tip.trim();open=false;onApply(next,label);onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={`${t('link.title')} – ${where}`} size="sm">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{hasStyle,cfIn}from"./sheet/conditional-formats";import{colToLetters}from"./sheet/address";let{open=$bindable(false),rules,selection,onApply,onEdit,onClose}=$props();const t=useSheetText();let working=$state([]);let scope=$state("sheet");let selected=$state(null);$effect(()=>{if(!open)return;const copy=rules.map(r=>({...r,rects:r.rects.map(x=>[...x])}));working=copy;scope="sheet";selected=copy[0]?.id??null});const shown=$derived(scope==="sheet"?working:cfIn(working,selection));const current=$derived(working.find(r=>r.id===selected)??null);const index=$derived(current?working.indexOf(current):-1);const address=rects=>rects.map(([r1,c1,r2,c2])=>{const a=`${colToLetters(c1)}${r1+1}`;const b=`${colToLetters(c2)}${r2+1}`;return a===b?a:`${a}:${b}`}).join(", ");const sample=rule=>{if(hasStyle(rule))return{background:rule.style.fill,color:rule.style.color,text:"AaBbCcYyZz"};if(rule.kind==="dataBar")return{background:`linear-gradient(90deg, ${rule.color} 60%, transparent 60%)`,text:""};if(rule.kind==="colorScale")return{background:`linear-gradient(90deg, ${rule.colors.join(", ")})`,text:""};return{text:t("manageRules.iconSet")}};function remove(){if(index<0)return;working=working.filter((_,i)=>i!==index);selected=working[Math.min(index,working.length-1)]?.id??null}function move(delta){if(index<0)return;const to=index+delta;if(to<0||to>=working.length)return;const next=working.slice();const[rule]=next.splice(index,1);next.splice(to,0,rule);working=next}function toggleStop(rule){working=working.map(r=>r.id===rule.id?{...r,stopIfTrue:!r.stopIfTrue}:r)}function edit(){const rule=current;if(!rule||!hasStyle(rule))return;onEdit(rule,next=>{working=working.map(r=>r.id===rule.id?next:r)})}function ok(){onApply(working);open=false;onClose?.()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";import{describeCf,hasStyle,cfIn}from"./sheet/conditional-formats";import{colToLetters}from"./sheet/address";let{open=$bindable(false),rules,selection,onApply,onEdit,onClose}=$props();const t=useSheetText();let working=$state([]);let scope=$state("sheet");let selected=$state(null);$effect(()=>{if(!open)return;const copy=rules.map(r=>({...r,rects:r.rects.map(x=>[...x])}));working=copy;scope="sheet";selected=copy[0]?.id??null});const shown=$derived(scope==="sheet"?working:cfIn(working,selection));const current=$derived(working.find(r=>r.id===selected)??null);const index=$derived(current?working.indexOf(current):-1);const address=rects=>rects.map(([r1,c1,r2,c2])=>{const a=`${colToLetters(c1)}${r1+1}`;const b=`${colToLetters(c2)}${r2+1}`;return a===b?a:`${a}:${b}`}).join(", ");const sample=rule=>{if(hasStyle(rule))return{background:rule.style.fill,color:rule.style.color,text:"AaBbCcYyZz"};if(rule.kind==="dataBar")return{background:`linear-gradient(90deg, ${rule.color} 60%, transparent 60%)`,text:""};if(rule.kind==="colorScale")return{background:`linear-gradient(90deg, ${rule.colors.join(", ")})`,text:""};return{text:t("manageRules.iconSet")}};function remove(){if(index<0)return;working=working.filter((_,i)=>i!==index);selected=working[Math.min(index,working.length-1)]?.id??null}function move(delta){if(index<0)return;const to=index+delta;if(to<0||to>=working.length)return;const next=working.slice();const[rule]=next.splice(index,1);next.splice(to,0,rule);working=next}function toggleStop(rule){working=working.map(r=>r.id===rule.id?{...r,stopIfTrue:!r.stopIfTrue}:r)}function edit(){const rule=current;if(!rule||!hasStyle(rule))return;onEdit(rule,next=>{working=working.map(r=>r.id===rule.id?next:r)})}function ok(){onApply(working);open=false;onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('manageRules.title')} size="md" width={640}>
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{isValidName}from"./sheet/names";import{parseA1}from"./sheet/address";let{open=$bindable(false),workbook,onChange,onClose}=$props();const t=useSheetText();let names=$state([]);let newName=$state("");let newRefersTo=$state("");let editing=$state(null);let editRefersTo=$state("");let problem=$state(null);function reload(){names=workbook.names.list()}$effect(()=>{if(!open)return;reload();newName="";newRefersTo="";editing=null;problem=null});function valueOf(entry){const text=entry.refersTo.replace(/^=/,"");const bang=text.lastIndexOf("!");const sheetName=bang>=0?text.slice(0,bang).replace(/^'(.*)'$/,"$1"):workbook.active;const address=bang>=0?text.slice(bang+1):text;const[first,last]=address.split(":");const from=parseA1(first??"");if(!from||from.row===null)return"";if(last){const to=parseA1(last);if(to&&to.row!==null){const cells=(to.row-from.row+1)*(to.col-from.col+1);return`${cells} cells`}}const v=workbook.getValue(sheetName,from.row,from.col);if(typeof v==="object"&&v!==null)return v.error;if(typeof v==="number")return v.toLocaleString("en-US",{maximumFractionDigits:4});return String(v)}function normalise(refersTo){const text=refersTo.trim().replace(/^=/,"");if(text==="")return null;const bang=text.lastIndexOf("!");const address=bang>=0?text.slice(bang+1):text;const[first,last]=address.split(":");if(!parseA1(first??""))return null;if(last!==void 0&&!parseA1(last))return null;const sheet=bang>=0?text.slice(0,bang+1):`${quote(workbook.active)}!`;return`=${sheet}${address}`}const quote=name=>/^[A-Za-z_][A-Za-z0-9_.]*$/.test(name)?name:`'${name.replace(/'/g,"''")}'`;function changed(){onChange();reload()}function add(){const name=newName.trim();if(!isValidName(name)){problem=`"${name}" is not a valid name: letters, digits and underscores, not a cell address`;return}if(workbook.names.has(name)){problem=`${name} is already defined; edit it below instead`;return}const refersTo=normalise(newRefersTo);if(!refersTo){problem=`"${newRefersTo}" is not a cell or range`;return}workbook.names.define(name,refersTo);newName="";newRefersTo="";problem=null;changed()}function startEdit(entry){editing=entry.name;editRefersTo=entry.refersTo;problem=null}function saveEdit(){if(!editing)return;const refersTo=normalise(editRefersTo);if(!refersTo){problem=`"${editRefersTo}" is not a cell or range`;return}workbook.names.define(editing,refersTo);editing=null;problem=null;changed()}function remove(name){workbook.names.remove(name);changed()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";import{isValidName}from"./sheet/names";import{parseA1}from"./sheet/address";let{open=$bindable(false),workbook,onChange,onClose}=$props();const t=useSheetText();let names=$state([]);let newName=$state("");let newRefersTo=$state("");let editing=$state(null);let editRefersTo=$state("");let problem=$state(null);function reload(){names=workbook.names.list()}$effect(()=>{if(!open)return;reload();newName="";newRefersTo="";editing=null;problem=null});function valueOf(entry){const text=entry.refersTo.replace(/^=/,"");const bang=text.lastIndexOf("!");const sheetName=bang>=0?text.slice(0,bang).replace(/^'(.*)'$/,"$1"):workbook.active;const address=bang>=0?text.slice(bang+1):text;const[first,last]=address.split(":");const from=parseA1(first??"");if(!from||from.row===null)return"";if(last){const to=parseA1(last);if(to&&to.row!==null){const cells=(to.row-from.row+1)*(to.col-from.col+1);return`${cells} cells`}}const v=workbook.getValue(sheetName,from.row,from.col);if(typeof v==="object"&&v!==null)return v.error;if(typeof v==="number")return v.toLocaleString("en-US",{maximumFractionDigits:4});return String(v)}function normalise(refersTo){const text=refersTo.trim().replace(/^=/,"");if(text==="")return null;const bang=text.lastIndexOf("!");const address=bang>=0?text.slice(bang+1):text;const[first,last]=address.split(":");if(!parseA1(first??""))return null;if(last!==void 0&&!parseA1(last))return null;const sheet=bang>=0?text.slice(0,bang+1):`${quote(workbook.active)}!`;return`=${sheet}${address}`}const quote=name=>/^[A-Za-z_][A-Za-z0-9_.]*$/.test(name)?name:`'${name.replace(/'/g,"''")}'`;function changed(){onChange();reload()}function add(){const name=newName.trim();if(!isValidName(name)){problem=`"${name}" is not a valid name: letters, digits and underscores, not a cell address`;return}if(workbook.names.has(name)){problem=`${name} is already defined; edit it below instead`;return}const refersTo=normalise(newRefersTo);if(!refersTo){problem=`"${newRefersTo}" is not a cell or range`;return}workbook.names.define(name,refersTo);newName="";newRefersTo="";problem=null;changed()}function startEdit(entry){editing=entry.name;editRefersTo=entry.refersTo;problem=null}function saveEdit(){if(!editing)return;const refersTo=normalise(editRefersTo);if(!refersTo){problem=`"${editRefersTo}" is not a cell or range`;return}workbook.names.define(editing,refersTo);editing=null;problem=null;changed()}function remove(name){workbook.names.remove(name);changed()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('nameManager.title')} size="md">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{MARGIN_PRESETS,PAPER_SIZES,marginPresetOf,copyPageSetup}from"./sheet/page-setup";import{parseRangeText,rangeText}from"./sheet/protection";let{open=$bindable(false),setup,onApply,onPrint,onClose}=$props();const t=useSheetText();let orientation=$state("portrait");let paper=$state("A4");let margins=$state("normal");let scale=$state("100");let area=$state("");let titles=$state("");let gridlines=$state(false);let headings=$state(false);let problem=$state(null);let first=$state(null);const PAPERS=Object.keys(PAPER_SIZES);$effect(()=>{if(!open)return;orientation=setup.orientation;paper=setup.paper;margins=marginPresetOf(setup.margins)??"custom";scale=String(setup.scale);area=setup.printArea?rangeText(setup.printArea):"";titles=setup.printTitleRows?`${setup.printTitleRows[0]+1}:${setup.printTitleRows[1]+1}`:"";gridlines=setup.gridlines;headings=setup.headings;problem=null;queueMicrotask(()=>first?.focus())});function read(){const next=copyPageSetup(setup);next.orientation=orientation;next.paper=paper;if(margins!=="custom")next.margins={...MARGIN_PRESETS[margins]};const pct=Number(scale);next.scale=Number.isFinite(pct)&&pct>=10&&pct<=400?Math.round(pct):100;if(area.trim()){const rects=parseRangeText(area);if(!rects){problem=t("pageSetup.invalidArea",{text:area});return null}next.printArea=rects}else next.printArea=null;if(titles.trim()){const m=/^\$?(\d+)\s*:\s*\$?(\d+)$/.exec(titles.trim())??/^\$?(\d+)$/.exec(titles.trim());if(!m){problem=t("pageSetup.invalidRows",{text:titles});return null}const a=Number(m[1])-1;const b=Number(m[2]??m[1])-1;if(a<0||b<a){problem=t("pageSetup.invalidRows",{text:titles});return null}next.printTitleRows=[a,b]}else next.printTitleRows=null;next.gridlines=gridlines;next.headings=headings;problem=null;return next}function ok(){const next=read();if(!next)return;open=false;onApply(next);onClose?.()}function print(){const next=read();if(!next)return;open=false;onApply(next);onPrint()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";import{MARGIN_PRESETS,PAPER_SIZES,marginPresetOf,copyPageSetup}from"./sheet/page-setup";import{parseRangeText,rangeText}from"./sheet/protection";let{open=$bindable(false),setup,onApply,onPrint,onClose}=$props();const t=useSheetText();let orientation=$state("portrait");let paper=$state("A4");let margins=$state("normal");let scale=$state("100");let area=$state("");let titles=$state("");let gridlines=$state(false);let headings=$state(false);let problem=$state(null);let first=$state(null);const PAPERS=Object.keys(PAPER_SIZES);$effect(()=>{if(!open)return;orientation=setup.orientation;paper=setup.paper;margins=marginPresetOf(setup.margins)??"custom";scale=String(setup.scale);area=setup.printArea?rangeText(setup.printArea):"";titles=setup.printTitleRows?`${setup.printTitleRows[0]+1}:${setup.printTitleRows[1]+1}`:"";gridlines=setup.gridlines;headings=setup.headings;problem=null;queueMicrotask(()=>first?.focus())});function read(){const next=copyPageSetup(setup);next.orientation=orientation;next.paper=paper;if(margins!=="custom")next.margins={...MARGIN_PRESETS[margins]};const pct=Number(scale);next.scale=Number.isFinite(pct)&&pct>=10&&pct<=400?Math.round(pct):100;if(area.trim()){const rects=parseRangeText(area);if(!rects){problem=t("pageSetup.invalidArea",{text:area});return null}next.printArea=rects}else next.printArea=null;if(titles.trim()){const m=/^\$?(\d+)\s*:\s*\$?(\d+)$/.exec(titles.trim())??/^\$?(\d+)$/.exec(titles.trim());if(!m){problem=t("pageSetup.invalidRows",{text:titles});return null}const a=Number(m[1])-1;const b=Number(m[2]??m[1])-1;if(a<0||b<a){problem=t("pageSetup.invalidRows",{text:titles});return null}next.printTitleRows=[a,b]}else next.printTitleRows=null;next.gridlines=gridlines;next.headings=headings;problem=null;return next}function ok(){const next=read();if(!next)return;open=false;onApply(next);onClose?.()}function print(){const next=read();if(!next)return;open=false;onApply(next);onPrint()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('pageSetup.title')} size="sm" width={420}>
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";let{open=$bindable(false),hasClipboard,onPaste,onClose}=$props();const t=useSheetText();let what=$state("all");let operation=$state("none");let skipBlanks=$state(false);let transpose=$state(false);const WHAT=[{value:"all",label:"pasteSpecial.all"},{value:"formulas",label:"pasteSpecial.formulas"},{value:"values",label:"pasteSpecial.values"},{value:"formats",label:"pasteSpecial.formats"}];const OPERATIONS=[{value:"none",label:"pasteSpecial.none"},{value:"add",label:"pasteSpecial.add"},{value:"subtract",label:"pasteSpecial.subtract"},{value:"multiply",label:"pasteSpecial.multiply"},{value:"divide",label:"pasteSpecial.divide"}];function ok(){onPaste({what,operation,skipBlanks,transpose});open=false;onClose?.()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";let{open=$bindable(false),hasClipboard,onPaste,onClose}=$props();const t=useSheetText();let what=$state("all");let operation=$state("none");let skipBlanks=$state(false);let transpose=$state(false);const WHAT=[{value:"all",label:"pasteSpecial.all"},{value:"formulas",label:"pasteSpecial.formulas"},{value:"values",label:"pasteSpecial.values"},{value:"formats",label:"pasteSpecial.formats"}];const OPERATIONS=[{value:"none",label:"pasteSpecial.none"},{value:"add",label:"pasteSpecial.add"},{value:"subtract",label:"pasteSpecial.subtract"},{value:"multiply",label:"pasteSpecial.multiply"},{value:"divide",label:"pasteSpecial.divide"}];function ok(){onPaste({what,operation,skipBlanks,transpose});open=false;onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('pasteSpecial.title')} size="sm">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{parseRangeText,rangeText}from"./sheet/protection";import{parseA1,formatA1}from"./sheet/address";let{open=$bindable(false),pivot,fields,valuesOf,existing=false,onApply,onDelete,onClose}=$props();const t=useSheetText();let source=$state("");let target=$state("");let rows=$state([]);let cols=$state([]);let values=$state([]);let filters=$state([]);let grandTotalRow=$state(true);let rowSubtotals=$state(true);let error=$state("");let first=$state(null);$effect(()=>{if(!open)return;source=rangeText([pivot.source]);target=formatA1({sheet:null,row:pivot.target.row,col:pivot.target.col,rowAbs:false,colAbs:false});rows=[...pivot.rows];cols=[...pivot.cols];values=pivot.values.map(v=>({...v}));filters=(pivot.filters??[]).map(f=>({...f}));grandTotalRow=pivot.grandTotalRow!==false;rowSubtotals=pivot.rowSubtotals!==false;error="";queueMicrotask(()=>first?.focus())});function placeOf(field){if(rows.includes(field))return"rows";if(cols.includes(field))return"cols";if(values.some(v=>v.field===field))return"values";if(filters.some(f=>f.field===field))return"filters";return"none"}function place(field,to){rows=rows.filter(f=>f!==field);cols=cols.filter(f=>f!==field);values=values.filter(v=>v.field!==field);filters=filters.filter(f=>f.field!==field);if(to==="rows")rows=[...rows,field];else if(to==="cols")cols=[...cols,field];else if(to==="values")values=[...values,{field,agg:"sum"}];else if(to==="filters")filters=[...filters,{field,value:""}]}function setFilter(field,value){filters=filters.map(f=>f.field===field?{...f,value}:f)}function setAgg(field,agg){values=values.map(v=>v.field===field?{...v,agg}:v)}function ok(){const rects=parseRangeText(source);const block=rects&&rects.length===1?rects[0]:null;const at=parseA1(target.trim());if(!block||!at||at.row===null){error=t("pivot.badRange");return}if(!values.length){error=t("pivot.needValue");return}const next={...pivot,source:block,target:{row:at.row,col:at.col},rows:[...rows],cols:[...cols],values:values.map(v=>({...v})),...filters.length?{filters:filters.map(f=>({...f}))}:{filters:[]},grandTotalRow,rowSubtotals};if(!next.filters?.length)delete next.filters;open=false;onApply(next);onClose?.()}function close(){open=false;onClose?.()}
2
+ import{SvModal}from"@svgrid/grid";import{useSheetText}from"./sheet-text";import{parseRangeText,rangeText}from"./sheet/protection";import{parseA1,formatA1}from"./sheet/address";import{SHEET_PIVOT_AGGS,ALL_VALUES}from"./sheet/pivot-range";let{open=$bindable(false),pivot,fields,valuesOf,existing=false,onApply,onDelete,onClose}=$props();const t=useSheetText();let source=$state("");let target=$state("");let rows=$state([]);let cols=$state([]);let values=$state([]);let filters=$state([]);let grandTotalRow=$state(true);let rowSubtotals=$state(true);let error=$state("");let first=$state(null);$effect(()=>{if(!open)return;source=rangeText([pivot.source]);target=formatA1({sheet:null,row:pivot.target.row,col:pivot.target.col,rowAbs:false,colAbs:false});rows=[...pivot.rows];cols=[...pivot.cols];values=pivot.values.map(v=>({...v}));filters=(pivot.filters??[]).map(f=>({...f}));grandTotalRow=pivot.grandTotalRow!==false;rowSubtotals=pivot.rowSubtotals!==false;error="";queueMicrotask(()=>first?.focus())});function placeOf(field){if(rows.includes(field))return"rows";if(cols.includes(field))return"cols";if(values.some(v=>v.field===field))return"values";if(filters.some(f=>f.field===field))return"filters";return"none"}function place(field,to){rows=rows.filter(f=>f!==field);cols=cols.filter(f=>f!==field);values=values.filter(v=>v.field!==field);filters=filters.filter(f=>f.field!==field);if(to==="rows")rows=[...rows,field];else if(to==="cols")cols=[...cols,field];else if(to==="values")values=[...values,{field,agg:"sum"}];else if(to==="filters")filters=[...filters,{field,value:""}]}function setFilter(field,value){filters=filters.map(f=>f.field===field?{...f,value}:f)}function setAgg(field,agg){values=values.map(v=>v.field===field?{...v,agg}:v)}function ok(){const rects=parseRangeText(source);const block=rects&&rects.length===1?rects[0]:null;const at=parseA1(target.trim());if(!block||!at||at.row===null){error=t("pivot.badRange");return}if(!values.length){error=t("pivot.needValue");return}const next={...pivot,source:block,target:{row:at.row,col:at.col},rows:[...rows],cols:[...cols],values:values.map(v=>({...v})),...filters.length?{filters:filters.map(f=>({...f}))}:{filters:[]},grandTotalRow,rowSubtotals};if(!next.filters?.length)delete next.filters;open=false;onApply(next);onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('pivot.title')} size="md">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{PROTECTION_PERMISSIONS}from"./sheet/protection";let{open=$bindable(false),allow,onApply,onClose}=$props();const t=useSheetText();let ticks=$state({});let first=$state(null);$effect(()=>{if(!open)return;const next={};for(const key of PROTECTION_PERMISSIONS)next[key]=Boolean(allow[key]);ticks=next;queueMicrotask(()=>first?.focus())});function ok(){const next={};for(const key of PROTECTION_PERMISSIONS)if(ticks[key])next[key]=true;open=false;onApply(next);onClose?.()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";import{PROTECTION_PERMISSIONS}from"./sheet/protection";let{open=$bindable(false),allow,onApply,onClose}=$props();const t=useSheetText();let ticks=$state({});let first=$state(null);$effect(()=>{if(!open)return;const next={};for(const key of PROTECTION_PERMISSIONS)next[key]=Boolean(allow[key]);ticks=next;queueMicrotask(()=>first?.focus())});function ok(){const next={};for(const key of PROTECTION_PERMISSIONS)if(ticks[key])next[key]=true;open=false;onApply(next);onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('protectSheet.title')} size="sm">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{untrack}from"svelte";import{findDuplicates}from"./sheet/transforms";import{colToLetters}from"./sheet/address";let{open=$bindable(false),workbook,cmd,onDone,onClose}=$props();const t=useSheetText();let block=$state({top:0,left:0,bottom:0,right:0});let chosen=$state([]);let hasHeaders=$state(true);const raw=(r,c)=>workbook.getRaw(workbook.active,r,c);const headers=$derived.by(()=>Array.from({length:block.right-block.left+1},(_,i)=>{const letter=colToLetters(block.left+i);const fallback=t("removeDuplicates.columnLetter",{letter});return hasHeaders?raw(block.top,block.left+i)||fallback:fallback}));$effect(()=>{if(!open)return;untrack(prepare)});function prepare(){const c=cmd();const range=c?.ranges[c.ranges.length-1];const rows=Math.max(workbook.rowCount(workbook.active)-1,0);const cols=Math.max(workbook.colCount(workbook.active)-1,0);if(range&&(range[0]!==range[2]||range[1]!==range[3])){block={top:range[0],left:range[1],bottom:Math.min(range[2],rows),right:Math.min(range[3],cols)}}else{const left=c?.activeCell?.colIndex??0;block={top:0,left,bottom:rows,right:Math.max(cols,left)}}chosen=Array.from({length:block.right-block.left+1},()=>true)}function remove(){const c=cmd();if(!c)return;const first=hasHeaders?block.top+1:block.top;const width=block.right-block.left+1;const rows=Array.from({length:Math.max(block.bottom-first+1,0)},(_,i)=>Array.from({length:width},(_2,k)=>raw(first+i,block.left+k)));const columns=chosen.flatMap((on,i)=>on?[i]:[]);const report=findDuplicates(rows,{columns});const message=`${report.remove.length} duplicate value${report.remove.length===1?"":"s"} found and removed; ${report.keep.length} unique value${report.keep.length===1?"":"s"} remain.`;if(report.remove.length>0){const kept=report.keep.map(i=>rows[i]);c.batch(()=>{for(let i=0;i<rows.length;i+=1){const source=kept[i];for(let k=0;k<width;k+=1){c.setCellValue(first+i,block.left+k,source?source[k]??"":"")}}})}open=false;if(report.remove.length>0){c.setSelection(block.top,block.left);c.extendSelection(first+(report.keep.length||1)-1,block.right)}onDone(message);onClose?.()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{untrack}from"svelte";import{SvModal}from"@svgrid/grid";import{findDuplicates}from"./sheet/transforms";import{colToLetters}from"./sheet/address";let{open=$bindable(false),workbook,cmd,onDone,onClose}=$props();const t=useSheetText();let block=$state({top:0,left:0,bottom:0,right:0});let chosen=$state([]);let hasHeaders=$state(true);const raw=(r,c)=>workbook.getRaw(workbook.active,r,c);const headers=$derived.by(()=>Array.from({length:block.right-block.left+1},(_,i)=>{const letter=colToLetters(block.left+i);const fallback=t("removeDuplicates.columnLetter",{letter});return hasHeaders?raw(block.top,block.left+i)||fallback:fallback}));$effect(()=>{if(!open)return;untrack(prepare)});function prepare(){const c=cmd();const range=c?.ranges[c.ranges.length-1];const rows=Math.max(workbook.rowCount(workbook.active)-1,0);const cols=Math.max(workbook.colCount(workbook.active)-1,0);if(range&&(range[0]!==range[2]||range[1]!==range[3])){block={top:range[0],left:range[1],bottom:Math.min(range[2],rows),right:Math.min(range[3],cols)}}else{const left=c?.activeCell?.colIndex??0;block={top:0,left,bottom:rows,right:Math.max(cols,left)}}chosen=Array.from({length:block.right-block.left+1},()=>true)}function remove(){const c=cmd();if(!c)return;const first=hasHeaders?block.top+1:block.top;const width=block.right-block.left+1;const rows=Array.from({length:Math.max(block.bottom-first+1,0)},(_,i)=>Array.from({length:width},(_2,k)=>raw(first+i,block.left+k)));const columns=chosen.flatMap((on,i)=>on?[i]:[]);const report=findDuplicates(rows,{columns});const message=`${report.remove.length} duplicate value${report.remove.length===1?"":"s"} found and removed; ${report.keep.length} unique value${report.keep.length===1?"":"s"} remain.`;if(report.remove.length>0){const kept=report.keep.map(i=>rows[i]);c.batch(()=>{for(let i=0;i<rows.length;i+=1){const source=kept[i];for(let k=0;k<width;k+=1){c.setCellValue(first+i,block.left+k,source?source[k]??"":"")}}})}open=false;if(report.remove.length>0){c.setSelection(block.top,block.left);c.extendSelection(first+(report.keep.length||1)-1,block.right)}onDone(message);onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('removeDuplicates.title')} size="sm">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{tick}from"svelte";import{RIBBON_TABS}from"./sheet/ribbon";import{useSheetText}from"./sheet-text";import{defaultSheetMessages}from"./sheet/messages";let{cmd,onChange,onAction,activeActions=[],tabs=RIBBON_TABS,tab=$bindable(tabs.some(t2=>t2.id==="home")?"home":tabs[0]?.id??"home"),without=[],collapsed=$bindable(false)}=$props();let peek=$state(false);function onTabClick(id){if(collapsed){peek=tab===id?!peek:true}tab=id}function toggleCollapsed(){collapsed=!collapsed;peek=false}$effect(()=>{if(!collapsed)peek=false});$effect(()=>{if(!peek)return;const away=e=>{if(!rootEl?.contains(e.target)&&!e.target?.closest?.(".sv-popover, .sv-modal"))peek=false};const esc=e=>{if(e.key==="Escape")peek=false};window.addEventListener("pointerdown",away,true);window.addEventListener("keydown",esc,true);return()=>{window.removeEventListener("pointerdown",away,true);window.removeEventListener("keydown",esc,true)}});let version=$state(0);const current=$derived.by(()=>{const found=tabs.find(t2=>t2.id===tab)??tabs[0];if(!found||without.length===0)return found;const groups=found.groups.map(g=>({...g,items:g.items.filter(i=>!i.emits||!without.includes(i.emits))})).filter(g=>g.items.length>0);return{...found,groups}});function stateOf(item){void version;const context=cmd();if(!context)return{on:false,enabled:false};if(item.emits){return{on:activeActions.includes(item.emits),enabled:true}}return{on:item.lit?activeActions.includes(item.lit):item.isOn?.(context)??false,enabled:item.isEnabled?.(context)??true}}function currentOf(item){void version;const context=cmd();return context&&item.current?item.current(context):""}function run(item,value){const context=cmd();if(!context)return;if(item.emits){onAction?.(item.emits,context);version+=1;context.focus();peek=false;return}if(item.run?.(context,value))onChange?.();version+=1;context.focus();peek=false}function launch(action){const context=cmd();if(context)onAction?.(action,context);peek=false}const t=useSheetText();const label=item=>t(`ribbon.${item.id}.label`);const title=item=>t(`ribbon.${item.id}.title`);const optionLabel=(item,option)=>{const key=`ribbon.${item.id}.option.${option.value}`;return defaultSheetMessages[key]===option.label?t(key):option.label};const groupLabel=group=>t(`ribbon.group.${group.id}`);function tip(item){return item.keys?`${title(item)} (${item.keys})`:title(item)}function refresh(){version+=1}let picked=$state({});let menuOpen=$state(Object.fromEntries(tabs.flatMap(t2=>t2.groups.flatMap(g=>g.items.map(i=>[i.id,false])))));function faceValue(item){return picked[item.id]??item.initial??item.options?.[0]?.value??""}function pick(item,value){picked={...picked,[item.id]:value};menuOpen={...menuOpen,[item.id]:false};run(item,value)}function pickOption(item,option){menuOpen={...menuOpen,[item.id]:false};if(option.emits){const context=cmd();if(!context)return;onAction?.(option.emits,context);version+=1;context.focus();peek=false;return}run(item,option.value)}function barColour(item){const value=faceValue(item);return value===item.none?.value?null:value}const natural=new Map;const compactWidth=new Map;const foldedWidth=new Map;let measured=$state(0);let bandWidth=$state(0);let groupOpen=$state(Object.fromEntries(tabs.flatMap(t2=>t2.groups.map(g=>[g.id,false]))));const COLLAPSED_WIDTH=66;const BAND_PADDING=8+24;function measure(node,key){const colon=key.indexOf(":");const id=colon<0?key:key.slice(0,colon);const into=key.endsWith(":compact")?compactWidth:key.endsWith(":folded")?foldedWidth:natural;const record=()=>{const width=node.getBoundingClientRect().width;if(width>0&&into.get(id)!==width){into.set(id,width);measured+=1}};record();const observer=typeof ResizeObserver==="undefined"?null:new ResizeObserver(record);observer?.observe(node);return{destroy:()=>observer?.disconnect()}}const fit=$derived.by(()=>{void measured;const groups=current?.groups??[];const compact=new Set;const folded=new Set;if(!bandWidth)return{compact,folded};const wide=g=>natural.get(g.id)??120;const narrow=g=>compactWidth.get(g.id)??wide(g);const oneButton=g=>foldedWidth.get(g.id)??COLLAPSED_WIDTH;let total=BAND_PADDING;for(const group of groups)total+=wide(group);for(let i=groups.length-1;i>=0&&total>bandWidth;i-=1){const group=groups[i];if(narrow(group)<wide(group)){total+=narrow(group)-wide(group);compact.add(group.id)}}for(let i=groups.length-1;i>=0&&total>bandWidth;i-=1){const group=groups[i];total+=oneButton(group)-(compact.has(group.id)?narrow(group):wide(group));folded.add(group.id)}return{compact,folded}});const collapsedGroups=$derived(fit.folded);function placed(items){let col=0;let lastRow=99;return items.map(item=>{const row=item.size==="large"?1:item.row??1;if(item.size==="large"||row<=lastRow)col+=1;lastRow=item.size==="large"?99:row;return{item,col}})}function groupIcon(group){return group.icon??(group.items.find(i=>i.size==="large")??group.items.find(i=>i.icon))?.icon??"format-cells"}let rootEl=$state(null);let themeFont=$state("Default");$effect(()=>{if(!rootEl)return;const first=getComputedStyle(rootEl).fontFamily.split(",")[0]?.replace(/["']/g,"").trim();if(first)themeFont=first});function onTabKey(event){const ids=tabs.map(t2=>t2.id);const at=ids.indexOf(tab);const strip=event.currentTarget.parentElement;const rtl=strip?getComputedStyle(strip).direction==="rtl":false;const forward=rtl?"ArrowLeft":"ArrowRight";const back=rtl?"ArrowRight":"ArrowLeft";let next=-1;if(event.key===forward&&at<ids.length-1)next=at+1;else if(event.key===back&&at>0)next=at-1;else if(event.key==="Home")next=0;else if(event.key==="End")next=ids.length-1;if(next<0||next===at)return;event.preventDefault();tab=ids[next];void tick().then(()=>strip?.querySelector('[role="tab"][aria-selected="true"]')?.focus())}
2
+ import{tick}from"svelte";import{SvPopover}from"@svgrid/grid";import SvRibbonIcon from"./SvRibbonIcon.svelte";import{RIBBON_TABS}from"./sheet/ribbon";import{THEME_COLOURS,STANDARD_COLOURS}from"./sheet/palette";import{useSheetText}from"./sheet-text";import{defaultSheetMessages}from"./sheet/messages";let{cmd,onChange,onAction,activeActions=[],tabs=RIBBON_TABS,tab=$bindable(tabs.some(t2=>t2.id==="home")?"home":tabs[0]?.id??"home"),without=[],collapsed=$bindable(false)}=$props();let peek=$state(false);function onTabClick(id){if(collapsed){peek=tab===id?!peek:true}tab=id}function toggleCollapsed(){collapsed=!collapsed;peek=false}$effect(()=>{if(!collapsed)peek=false});$effect(()=>{if(!peek)return;const away=e=>{if(!rootEl?.contains(e.target)&&!e.target?.closest?.(".sv-popover, .sv-modal"))peek=false};const esc=e=>{if(e.key==="Escape")peek=false};window.addEventListener("pointerdown",away,true);window.addEventListener("keydown",esc,true);return()=>{window.removeEventListener("pointerdown",away,true);window.removeEventListener("keydown",esc,true)}});let version=$state(0);const current=$derived.by(()=>{const found=tabs.find(t2=>t2.id===tab)??tabs[0];if(!found||without.length===0)return found;const groups=found.groups.map(g=>({...g,items:g.items.filter(i=>!i.emits||!without.includes(i.emits))})).filter(g=>g.items.length>0);return{...found,groups}});function stateOf(item){void version;const context=cmd();if(!context)return{on:false,enabled:false};if(item.emits){return{on:activeActions.includes(item.emits),enabled:true}}return{on:item.lit?activeActions.includes(item.lit):item.isOn?.(context)??false,enabled:item.isEnabled?.(context)??true}}function currentOf(item){void version;const context=cmd();return context&&item.current?item.current(context):""}function run(item,value){const context=cmd();if(!context)return;if(item.emits){onAction?.(item.emits,context);version+=1;context.focus();peek=false;return}if(item.run?.(context,value))onChange?.();version+=1;context.focus();peek=false}function launch(action){const context=cmd();if(context)onAction?.(action,context);peek=false}const t=useSheetText();const label=item=>t(`ribbon.${item.id}.label`);const title=item=>t(`ribbon.${item.id}.title`);const optionLabel=(item,option)=>{const key=`ribbon.${item.id}.option.${option.value}`;return defaultSheetMessages[key]===option.label?t(key):option.label};const groupLabel=group=>t(`ribbon.group.${group.id}`);function tip(item){return item.keys?`${title(item)} (${item.keys})`:title(item)}function refresh(){version+=1}let picked=$state({});let menuOpen=$state(Object.fromEntries(tabs.flatMap(t2=>t2.groups.flatMap(g=>g.items.map(i=>[i.id,false])))));function faceValue(item){return picked[item.id]??item.initial??item.options?.[0]?.value??""}function pick(item,value){picked={...picked,[item.id]:value};menuOpen={...menuOpen,[item.id]:false};run(item,value)}function pickOption(item,option){menuOpen={...menuOpen,[item.id]:false};if(option.emits){const context=cmd();if(!context)return;onAction?.(option.emits,context);version+=1;context.focus();peek=false;return}run(item,option.value)}function barColour(item){const value=faceValue(item);return value===item.none?.value?null:value}const natural=new Map;const compactWidth=new Map;const foldedWidth=new Map;let measured=$state(0);let bandWidth=$state(0);let groupOpen=$state(Object.fromEntries(tabs.flatMap(t2=>t2.groups.map(g=>[g.id,false]))));const COLLAPSED_WIDTH=66;const BAND_PADDING=8+24;function measure(node,key){const colon=key.indexOf(":");const id=colon<0?key:key.slice(0,colon);const into=key.endsWith(":compact")?compactWidth:key.endsWith(":folded")?foldedWidth:natural;const record=()=>{const width=node.getBoundingClientRect().width;if(width>0&&into.get(id)!==width){into.set(id,width);measured+=1}};record();const observer=typeof ResizeObserver==="undefined"?null:new ResizeObserver(record);observer?.observe(node);return{destroy:()=>observer?.disconnect()}}const fit=$derived.by(()=>{void measured;const groups=current?.groups??[];const compact=new Set;const folded=new Set;if(!bandWidth)return{compact,folded};const wide=g=>natural.get(g.id)??120;const narrow=g=>compactWidth.get(g.id)??wide(g);const oneButton=g=>foldedWidth.get(g.id)??COLLAPSED_WIDTH;let total=BAND_PADDING;for(const group of groups)total+=wide(group);for(let i=groups.length-1;i>=0&&total>bandWidth;i-=1){const group=groups[i];if(narrow(group)<wide(group)){total+=narrow(group)-wide(group);compact.add(group.id)}}for(let i=groups.length-1;i>=0&&total>bandWidth;i-=1){const group=groups[i];total+=oneButton(group)-(compact.has(group.id)?narrow(group):wide(group));folded.add(group.id)}return{compact,folded}});const collapsedGroups=$derived(fit.folded);function placed(items){let col=0;let lastRow=99;return items.map(item=>{const row=item.size==="large"?1:item.row??1;if(item.size==="large"||row<=lastRow)col+=1;lastRow=item.size==="large"?99:row;return{item,col}})}function groupIcon(group){return group.icon??(group.items.find(i=>i.size==="large")??group.items.find(i=>i.icon))?.icon??"format-cells"}let rootEl=$state(null);let themeFont=$state("Default");$effect(()=>{if(!rootEl)return;const first=getComputedStyle(rootEl).fontFamily.split(",")[0]?.replace(/["']/g,"").trim();if(first)themeFont=first});function onTabKey(event){const ids=tabs.map(t2=>t2.id);const at=ids.indexOf(tab);const strip=event.currentTarget.parentElement;const rtl=strip?getComputedStyle(strip).direction==="rtl":false;const forward=rtl?"ArrowLeft":"ArrowRight";const back=rtl?"ArrowRight":"ArrowLeft";let next=-1;if(event.key===forward&&at<ids.length-1)next=at+1;else if(event.key===back&&at>0)next=at-1;else if(event.key==="Home")next=0;else if(event.key==="End")next=ids.length-1;if(next<0||next===at)return;event.preventDefault();tab=ids[next];void tick().then(()=>strip?.querySelector('[role="tab"][aria-selected="true"]')?.focus())}
3
3
  </script>
4
4
 
5
5
  <svelte:window onpointerup={refresh} onkeyup={refresh} />
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";let{open=$bindable(false),title,label,value,onApply,onClose}=$props();const t=useSheetText();let draft=$state("");let input=$state(null);$effect(()=>{if(!open)return;draft=String(Math.round(value));queueMicrotask(()=>{input?.focus();input?.select()})});const px=$derived(Number(draft));const valid=$derived(Number.isFinite(px)&&px>=4&&px<=2e3);function ok(){if(!valid)return;onApply(Math.round(px));open=false;onClose?.()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";let{open=$bindable(false),title,label,value,onApply,onClose}=$props();const t=useSheetText();let draft=$state("");let input=$state(null);$effect(()=>{if(!open)return;draft=String(Math.round(value));queueMicrotask(()=>{input?.focus();input?.select()})});const px=$derived(Number(draft));const valid=$derived(Number.isFinite(px)&&px>=4&&px<=2e3);function ok(){if(!valid)return;onApply(Math.round(px));open=false;onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} {title} size="sm">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{untrack}from"svelte";import{colToLetters}from"./sheet/address";let{open=$bindable(false),workbook,block,headerGuess,activeCol,colourAt,onApply,onClose}=$props();const t=useSheetText();let levels=$state([]);let hasHeaders=$state(true);const raw=(r,c)=>workbook.getRaw(workbook.active,r,c);const columns=$derived.by(()=>Array.from({length:block.right-block.left+1},(_,i)=>{const col=block.left+i;const letter=t("sort.columnLetter",{letter:colToLetters(col)});return{col,label:hasHeaders?raw(block.top,col)||letter:letter}}));$effect(()=>{if(!open)return;untrack(()=>{hasHeaders=headerGuess;levels=[{col:Math.min(Math.max(activeCol,block.left),block.right),direction:"asc",on:"value"}]})});function coloursIn(col,on){if(!colourAt)return[];const seen=[];for(let r=block.top+(hasHeaders?1:0);r<=block.bottom;r+=1){const colour=colourAt(r,col,on)?.trim().toLowerCase();if(colour&&!seen.includes(colour))seen.push(colour)}return seen}function onSortOnChange(level){if(level.on==="value"){level.colour=void 0;return}const colours=coloursIn(level.col,level.on==="color"?"color":"fill");if(!level.colour||!colours.includes(level.colour))level.colour=colours[0]}function addLevel(){const used=new Set(levels.map(l=>l.col));const free=columns.find(c=>!used.has(c.col))??columns[0];if(!free)return;levels=[...levels,{col:free.col,direction:"asc",on:"value"}]}function deleteLevel(index){if(levels.length<=1)return;levels=levels.filter((_,i)=>i!==index)}function ok(){if(!levels.length)return;onApply(levels.map(l=>({...l})),hasHeaders);open=false;onClose?.()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{untrack}from"svelte";import{SvModal}from"@svgrid/grid";import{colToLetters}from"./sheet/address";let{open=$bindable(false),workbook,block,headerGuess,activeCol,colourAt,onApply,onClose}=$props();const t=useSheetText();let levels=$state([]);let hasHeaders=$state(true);const raw=(r,c)=>workbook.getRaw(workbook.active,r,c);const columns=$derived.by(()=>Array.from({length:block.right-block.left+1},(_,i)=>{const col=block.left+i;const letter=t("sort.columnLetter",{letter:colToLetters(col)});return{col,label:hasHeaders?raw(block.top,col)||letter:letter}}));$effect(()=>{if(!open)return;untrack(()=>{hasHeaders=headerGuess;levels=[{col:Math.min(Math.max(activeCol,block.left),block.right),direction:"asc",on:"value"}]})});function coloursIn(col,on){if(!colourAt)return[];const seen=[];for(let r=block.top+(hasHeaders?1:0);r<=block.bottom;r+=1){const colour=colourAt(r,col,on)?.trim().toLowerCase();if(colour&&!seen.includes(colour))seen.push(colour)}return seen}function onSortOnChange(level){if(level.on==="value"){level.colour=void 0;return}const colours=coloursIn(level.col,level.on==="color"?"color":"fill");if(!level.colour||!colours.includes(level.colour))level.colour=colours[0]}function addLevel(){const used=new Set(levels.map(l=>l.col));const free=columns.find(c=>!used.has(c.col))??columns[0];if(!free)return;levels=[...levels,{col:free.col,direction:"asc",on:"value"}]}function deleteLevel(index){if(levels.length<=1)return;levels=levels.filter((_,i)=>i!==index)}function ok(){if(!levels.length)return;onApply(levels.map(l=>({...l})),hasHeaders);open=false;onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('sort.title')} size="sm" width={460}>
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{parseRangeText,rangeText}from"./sheet/protection";let{open=$bindable(false),group,existing=false,onApply,onDelete,onClose}=$props();const t=useSheetText();let type=$state("line");let data=$state("");let location=$state("");let colour=$state("");let negative=$state("");let sameScale=$state(false);let markers=$state(false);let error=$state("");let first=$state(null);$effect(()=>{if(!open)return;type=group.type;data=rangeText([group.data]);location=rangeText([group.location]);colour=group.color??"";negative=group.negativeColor??"";sameScale=Boolean(group.sameScale);markers=Boolean(group.markers);error="";queueMicrotask(()=>first?.focus())});function oneRect(text){const rects=parseRangeText(text);return rects&&rects.length===1?rects[0]:null}function shapesAgree(d,l){const lines=l[2]-l[0]>=l[3]-l[1]?d[2]-d[0]:d[3]-d[1];const cells=Math.max(l[2]-l[0],l[3]-l[1]);return lines===cells}function ok(){const d=oneRect(data);const l=oneRect(location);if(!d||!l){error=t("sparklines.badRange");return}if(!shapesAgree(d,l)){error=t("sparklines.mismatch");return}const next={...group,type,data:d,location:l,sameScale,markers};if(colour.trim())next.color=colour.trim();else delete next.color;if(negative.trim())next.negativeColor=negative.trim();else delete next.negativeColor;open=false;onApply(next);onClose?.()}function close(){open=false;onClose?.()}
2
+ import{SvModal}from"@svgrid/grid";import{useSheetText}from"./sheet-text";import{parseRangeText,rangeText}from"./sheet/protection";import{SPARKLINE_TYPES}from"./sheet/sparklines";let{open=$bindable(false),group,existing=false,onApply,onDelete,onClose}=$props();const t=useSheetText();let type=$state("line");let data=$state("");let location=$state("");let colour=$state("");let negative=$state("");let sameScale=$state(false);let markers=$state(false);let error=$state("");let first=$state(null);$effect(()=>{if(!open)return;type=group.type;data=rangeText([group.data]);location=rangeText([group.location]);colour=group.color??"";negative=group.negativeColor??"";sameScale=Boolean(group.sameScale);markers=Boolean(group.markers);error="";queueMicrotask(()=>first?.focus())});function oneRect(text){const rects=parseRangeText(text);return rects&&rects.length===1?rects[0]:null}function shapesAgree(d,l){const lines=l[2]-l[0]>=l[3]-l[1]?d[2]-d[0]:d[3]-d[1];const cells=Math.max(l[2]-l[0],l[3]-l[1]);return lines===cells}function ok(){const d=oneRect(data);const l=oneRect(location);if(!d||!l){error=t("sparklines.badRange");return}if(!shapesAgree(d,l)){error=t("sparklines.mismatch");return}const next={...group,type,data:d,location:l,sameScale,markers};if(colour.trim())next.color=colour.trim();else delete next.color;if(negative.trim())next.negativeColor=negative.trim();else delete next.negativeColor;open=false;onApply(next);onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('sparklines.title')} size="sm">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{parseRangeText,rangeText}from"./sheet/protection";import{isValidTableName}from"./sheet/tables";import{DEFAULT_TABLE_STYLE}from"./sheet/table-styles";let{open=$bindable(false),range,name,headers=true,totals=false,existing=false,style=DEFAULT_TABLE_STYLE,onApply,onRemove,onClose}=$props();const t=useSheetText();let where=$state("");let label=$state("");let hasHeaders=$state(true);let hasTotals=$state(false);let look=$state(DEFAULT_TABLE_STYLE);let error=$state("");let first=$state(null);$effect(()=>{if(!open)return;where=rangeText([range]);label=name;hasHeaders=headers;hasTotals=totals;look=style;error="";queueMicrotask(()=>first?.focus())});function ok(){const rects=parseRangeText(where);const block=rects&&rects.length===1?rects[0]:null;if(!block){error=t("table.badRange");return}if(!isValidTableName(label.trim())){error=t("table.badName");return}open=false;onApply({range:block,name:label.trim(),headers:hasHeaders,totals:hasTotals,style:look});onClose?.()}function close(){open=false;onClose?.()}
2
+ import{SvModal}from"@svgrid/grid";import{useSheetText}from"./sheet-text";import{parseRangeText,rangeText}from"./sheet/protection";import{isValidTableName}from"./sheet/tables";import{TABLE_STYLES,DEFAULT_TABLE_STYLE,NO_TABLE_STYLE,tableStyleColours,tableStyleLabel}from"./sheet/table-styles";let{open=$bindable(false),range,name,headers=true,totals=false,existing=false,style=DEFAULT_TABLE_STYLE,onApply,onRemove,onClose}=$props();const t=useSheetText();let where=$state("");let label=$state("");let hasHeaders=$state(true);let hasTotals=$state(false);let look=$state(DEFAULT_TABLE_STYLE);let error=$state("");let first=$state(null);$effect(()=>{if(!open)return;where=rangeText([range]);label=name;hasHeaders=headers;hasTotals=totals;look=style;error="";queueMicrotask(()=>first?.focus())});function ok(){const rects=parseRangeText(where);const block=rects&&rects.length===1?rects[0]:null;if(!block){error=t("table.badRange");return}if(!isValidTableName(label.trim())){error=t("table.badName");return}open=false;onApply({range:block,name:label.trim(),headers:hasHeaders,totals:hasTotals,style:look});onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
 
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{tick}from"svelte";import{isValidSheetName}from"./sheet/workbook";import{useSheetText}from"./sheet-text";let{workbook,onChange,onRename,onRemove,onReturnFocus,hidden=[],onHide,onUnhide,onDuplicate,editable=true,version=0}=$props();const t=useSheetText();let renaming=$state(null);let draft=$state("");let error=$state(null);let dragging=$state(null);let localVersion=$state(0);const isHidden=name=>hidden.some(h=>h.toLowerCase()===name.toLowerCase());const sheets=$derived.by(()=>{void version;void localVersion;return workbook.sheets.filter(name=>!isHidden(name))});const hiddenSheets=$derived.by(()=>{void version;void localVersion;return workbook.sheets.filter(name=>isHidden(name))});const activeSheet=$derived.by(()=>{void version;void localVersion;return workbook.active});function changed(){localVersion+=1;onChange?.()}function select(name){workbook.setActive(name);changed()}let renameInput=$state(null);function startRename(name){if(!editable)return;renaming=name;draft=name;error=null;void tick().then(()=>{renameInput?.focus();renameInput?.select()})}function commitRename(){const from=renaming;if(from===null)return;const to=draft.trim();renaming=null;if(to===""||to===from)return;if(!isValidSheetName(to)){error=t("invalidSheetName",{name:to});return}if(!workbook.renameSheet(from,to)){error=t("duplicateSheetName",{name:to});return}error=null;onRename?.(from,to);changed()}function focusActiveTab(){void tick().then(()=>strip?.querySelector('[role="tab"][aria-selected="true"]')?.focus())}function add(){workbook.addSheet();changed()}let confirmDelete=$state(null);function hasContent(name){for(let r=0;r<workbook.rowCount(name);r+=1){for(let c=0;c<workbook.colCount(name);c+=1){if(workbook.getRaw(name,r,c).trim()!=="")return true}}return false}function askRemove(name){if(workbook.sheets.length<2)return;if(hasContent(name))confirmDelete=name;else remove(name)}export function deleteSheet(name=workbook.active){askRemove(name)}function remove(name){confirmDelete=null;if(!workbook.removeSheet(name))return;onRemove?.(name);changed()}function hide(name){if(sheets.length<2)return;onHide?.(name);changed()}function unhide(name){onUnhide?.(name);changed()}function duplicate(name){onDuplicate?.(name);changed()}let menu=$state(null);function openMenu(event,name){if(!editable)return;event.preventDefault();select(name);menu={name,x:event.clientX,y:event.clientY}}function closeMenu(){menu=null;if(renaming===null&&confirmDelete===null)onReturnFocus?.()}function keepMenuInView(node,_at){const fit=()=>{const box=node.getBoundingClientRect();if(!menu)return;const x=Math.max(8,Math.min(menu.x,window.innerWidth-box.width-8));const y=menu.y+box.height>window.innerHeight-8?Math.max(8,menu.y-box.height):menu.y;if(x!==menu.x||y!==menu.y)menu={...menu,x,y}};fit();return{update:fit}}function moveBy(name,delta){const at=workbook.sheets.indexOf(name);const to=at+delta;if(at<0||to<0||to>=workbook.sheets.length)return;workbook.moveSheet(name,to);changed()}function insertBefore(name){const at=workbook.sheets.indexOf(name);const added=workbook.addSheet(void 0,Math.max(at,0));workbook.setActive(added);changed()}let strip=$state(null);let canLeft=$state(false);let canRight=$state(false);function measureStrip(){const el=strip;if(!el){canLeft=false;canRight=false;return}canLeft=el.scrollLeft>1;canRight=el.scrollLeft+el.clientWidth<el.scrollWidth-1}$effect(()=>{const el=strip;if(!el)return;void version;void sheets;measureStrip();const ro=typeof ResizeObserver==="undefined"?null:new ResizeObserver(measureStrip);ro?.observe(el);el.addEventListener("scroll",measureStrip);return()=>{ro?.disconnect();el.removeEventListener("scroll",measureStrip)}});function scrollTabs(delta){strip?.scrollBy({left:delta,behavior:"smooth"})}function onDrop(target){const moved=dragging;dragging=null;if(!moved||moved===target)return;const to=workbook.sheets.indexOf(target);if(to<0)return;workbook.moveSheet(moved,to);changed()}function onTabKey(event,name){if(event.key==="F2"){event.preventDefault();startRename(name);return}const at=sheets.indexOf(name);const list=event.currentTarget.closest('[role="tablist"]');const rtl=list?getComputedStyle(list).direction==="rtl":false;const forward=rtl?"ArrowLeft":"ArrowRight";const back=rtl?"ArrowRight":"ArrowLeft";let next=-1;if(event.key===forward&&at<sheets.length-1)next=at+1;else if(event.key===back&&at>0)next=at-1;else if(event.key==="Home")next=0;else if(event.key==="End")next=sheets.length-1;if(next<0||next===at)return;event.preventDefault();select(sheets[next]);void tick().then(()=>list?.querySelector('[role="tab"][aria-selected="true"]')?.focus())}
2
+ import{tick}from"svelte";import{SvModal}from"@svgrid/grid";import{isValidSheetName}from"./sheet/workbook";import{useSheetText}from"./sheet-text";let{workbook,onChange,onRename,onRemove,onReturnFocus,hidden=[],onHide,onUnhide,onDuplicate,editable=true,version=0}=$props();const t=useSheetText();let renaming=$state(null);let draft=$state("");let error=$state(null);let dragging=$state(null);let localVersion=$state(0);const isHidden=name=>hidden.some(h=>h.toLowerCase()===name.toLowerCase());const sheets=$derived.by(()=>{void version;void localVersion;return workbook.sheets.filter(name=>!isHidden(name))});const hiddenSheets=$derived.by(()=>{void version;void localVersion;return workbook.sheets.filter(name=>isHidden(name))});const activeSheet=$derived.by(()=>{void version;void localVersion;return workbook.active});function changed(){localVersion+=1;onChange?.()}function select(name){workbook.setActive(name);changed()}let renameInput=$state(null);function startRename(name){if(!editable)return;renaming=name;draft=name;error=null;void tick().then(()=>{renameInput?.focus();renameInput?.select()})}function commitRename(){const from=renaming;if(from===null)return;const to=draft.trim();renaming=null;if(to===""||to===from)return;if(!isValidSheetName(to)){error=t("invalidSheetName",{name:to});return}if(!workbook.renameSheet(from,to)){error=t("duplicateSheetName",{name:to});return}error=null;onRename?.(from,to);changed()}function focusActiveTab(){void tick().then(()=>strip?.querySelector('[role="tab"][aria-selected="true"]')?.focus())}function add(){workbook.addSheet();changed()}let confirmDelete=$state(null);function hasContent(name){for(let r=0;r<workbook.rowCount(name);r+=1){for(let c=0;c<workbook.colCount(name);c+=1){if(workbook.getRaw(name,r,c).trim()!=="")return true}}return false}function askRemove(name){if(workbook.sheets.length<2)return;if(hasContent(name))confirmDelete=name;else remove(name)}export function deleteSheet(name=workbook.active){askRemove(name)}function remove(name){confirmDelete=null;if(!workbook.removeSheet(name))return;onRemove?.(name);changed()}function hide(name){if(sheets.length<2)return;onHide?.(name);changed()}function unhide(name){onUnhide?.(name);changed()}function duplicate(name){onDuplicate?.(name);changed()}let menu=$state(null);function openMenu(event,name){if(!editable)return;event.preventDefault();select(name);menu={name,x:event.clientX,y:event.clientY}}function closeMenu(){menu=null;if(renaming===null&&confirmDelete===null)onReturnFocus?.()}function keepMenuInView(node,_at){const fit=()=>{const box=node.getBoundingClientRect();if(!menu)return;const x=Math.max(8,Math.min(menu.x,window.innerWidth-box.width-8));const y=menu.y+box.height>window.innerHeight-8?Math.max(8,menu.y-box.height):menu.y;if(x!==menu.x||y!==menu.y)menu={...menu,x,y}};fit();return{update:fit}}function moveBy(name,delta){const at=workbook.sheets.indexOf(name);const to=at+delta;if(at<0||to<0||to>=workbook.sheets.length)return;workbook.moveSheet(name,to);changed()}function insertBefore(name){const at=workbook.sheets.indexOf(name);const added=workbook.addSheet(void 0,Math.max(at,0));workbook.setActive(added);changed()}let strip=$state(null);let canLeft=$state(false);let canRight=$state(false);function measureStrip(){const el=strip;if(!el){canLeft=false;canRight=false;return}canLeft=el.scrollLeft>1;canRight=el.scrollLeft+el.clientWidth<el.scrollWidth-1}$effect(()=>{const el=strip;if(!el)return;void version;void sheets;measureStrip();const ro=typeof ResizeObserver==="undefined"?null:new ResizeObserver(measureStrip);ro?.observe(el);el.addEventListener("scroll",measureStrip);return()=>{ro?.disconnect();el.removeEventListener("scroll",measureStrip)}});function scrollTabs(delta){strip?.scrollBy({left:delta,behavior:"smooth"})}function onDrop(target){const moved=dragging;dragging=null;if(!moved||moved===target)return;const to=workbook.sheets.indexOf(target);if(to<0)return;workbook.moveSheet(moved,to);changed()}function onTabKey(event,name){if(event.key==="F2"){event.preventDefault();startRename(name);return}const at=sheets.indexOf(name);const list=event.currentTarget.closest('[role="tablist"]');const rtl=list?getComputedStyle(list).direction==="rtl":false;const forward=rtl?"ArrowLeft":"ArrowRight";const back=rtl?"ArrowRight":"ArrowLeft";let next=-1;if(event.key===forward&&at<sheets.length-1)next=at+1;else if(event.key===back&&at>0)next=at-1;else if(event.key==="Home")next=0;else if(event.key==="End")next=sheets.length-1;if(next<0||next===at)return;event.preventDefault();select(sheets[next]);void tick().then(()=>list?.querySelector('[role="tab"][aria-selected="true"]')?.focus())}
3
3
  </script>
4
4
 
5
5
  <svelte:window
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";import{untrack}from"svelte";import{textToColumns,guessDelimiter}from"./sheet/transforms";let{open=$bindable(false),workbook,cmd,onDone,onClose}=$props();const t=useSheetText();const DELIMITERS=[{id:"tab",label:"textToColumns.tab",sep:" "},{id:"semicolon",label:"textToColumns.semicolon",sep:";"},{id:"comma",label:"textToColumns.comma",sep:","},{id:"space",label:"textToColumns.space",sep:" "},{id:"other",label:"textToColumns.other",sep:""}];let delimiter=$state("comma");let other=$state("|");let collapse=$state(false);let trim=$state(true);let column=$state({index:0,top:0,texts:[]});const separator=$derived(delimiter==="other"?other:DELIMITERS.find(d=>d.id===delimiter).sep);const preview=$derived.by(()=>textToColumns(column.texts.slice(0,6),{delimiters:separator?[separator]:[","],collapse,trim}));$effect(()=>{if(!open)return;untrack(prepare)});function prepare(){const c=cmd();const range=c?.ranges[c.ranges.length-1];const left=range?range[1]:c?.activeCell?.colIndex??0;const top=range?range[0]:c?.activeCell?.rowIndex??0;const bottom=Math.max(workbook.rowCount(workbook.active)-1,top);const texts=Array.from({length:bottom-top+1},(_,i)=>workbook.getRaw(workbook.active,top+i,left));column={index:left,top,texts};const guess=guessDelimiter(texts.filter(t2=>t2!==""));const known=DELIMITERS.find(d=>d.sep===guess&&d.id!=="other");if(known)delimiter=known.id;else if(guess){delimiter="other";other=guess}}function finish(){const c=cmd();if(!c)return;const{rows,width}=textToColumns(column.texts,{delimiters:separator?[separator]:[","],collapse,trim});c.batch(()=>{rows.forEach((fields,r)=>{for(let i=0;i<width;i+=1){c.setCellValue(column.top+r,column.index+i,fields[i]??"")}})});open=false;c.setSelection(column.top,column.index);c.extendSelection(column.top+rows.length-1,column.index+width-1);onDone(t("textToColumns.done",{rows:rows.length,columns:width}));onClose?.()}function close(){open=false;onClose?.()}
2
+ import{useSheetText}from"./sheet-text";import{untrack}from"svelte";import{SvModal}from"@svgrid/grid";import{textToColumns,guessDelimiter}from"./sheet/transforms";import{colToLetters}from"./sheet/address";let{open=$bindable(false),workbook,cmd,onDone,onClose}=$props();const t=useSheetText();const DELIMITERS=[{id:"tab",label:"textToColumns.tab",sep:" "},{id:"semicolon",label:"textToColumns.semicolon",sep:";"},{id:"comma",label:"textToColumns.comma",sep:","},{id:"space",label:"textToColumns.space",sep:" "},{id:"other",label:"textToColumns.other",sep:""}];let delimiter=$state("comma");let other=$state("|");let collapse=$state(false);let trim=$state(true);let column=$state({index:0,top:0,texts:[]});const separator=$derived(delimiter==="other"?other:DELIMITERS.find(d=>d.id===delimiter).sep);const preview=$derived.by(()=>textToColumns(column.texts.slice(0,6),{delimiters:separator?[separator]:[","],collapse,trim}));$effect(()=>{if(!open)return;untrack(prepare)});function prepare(){const c=cmd();const range=c?.ranges[c.ranges.length-1];const left=range?range[1]:c?.activeCell?.colIndex??0;const top=range?range[0]:c?.activeCell?.rowIndex??0;const bottom=Math.max(workbook.rowCount(workbook.active)-1,top);const texts=Array.from({length:bottom-top+1},(_,i)=>workbook.getRaw(workbook.active,top+i,left));column={index:left,top,texts};const guess=guessDelimiter(texts.filter(t2=>t2!==""));const known=DELIMITERS.find(d=>d.sep===guess&&d.id!=="other");if(known)delimiter=known.id;else if(guess){delimiter="other";other=guess}}function finish(){const c=cmd();if(!c)return;const{rows,width}=textToColumns(column.texts,{delimiters:separator?[separator]:[","],collapse,trim});c.batch(()=>{rows.forEach((fields,r)=>{for(let i=0;i<width;i+=1){c.setCellValue(column.top+r,column.index+i,fields[i]??"")}})});open=false;c.setSelection(column.top,column.index);c.extendSelection(column.top+rows.length-1,column.index+width-1);onDone(t("textToColumns.done",{rows:rows.length,columns:width}));onClose?.()}function close(){open=false;onClose?.()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onClose} title={t('textToColumns.title')} size="md">
@@ -1,5 +1,5 @@
1
1
  <script lang="ts">
2
- import{useSheetText}from"./sheet-text";let{open=$bindable(false),alert,onRetry,onAccept,onCancel}=$props();const t=useSheetText();let first=$state(null);$effect(()=>{if(!open)return;queueMicrotask(()=>first?.focus())});function done(fn){open=false;fn()}
2
+ import{useSheetText}from"./sheet-text";import{SvModal}from"@svgrid/grid";let{open=$bindable(false),alert,onRetry,onAccept,onCancel}=$props();const t=useSheetText();let first=$state(null);$effect(()=>{if(!open)return;queueMicrotask(()=>first?.focus())});function done(fn){open=false;fn()}
3
3
  </script>
4
4
 
5
5
  <SvModal bind:open onClose={onCancel} title={alert?.title ?? t('dataValidationTitle')} size="sm">
@@ -1487,7 +1487,7 @@ ${Q}
1487
1487
  @keyframes st-home-spin { to { transform: rotate(360deg); } }
1488
1488
  </style>
1489
1489
  `}}function M2(t){for(let n of t)zo(n);let r=new Map(t.map(n=>[n.name,n])),a=t.map(n=>{let l=mle(n,r);return{schema:vle(n,l),infos:l}});return{entries:a,seed:ble(a)}}function n4(t,r={}){let{entries:a,seed:n}=M2(t),{file:l,needs:i}=Ple(a,n,r.sources,r.supabaseConn,r.serverMemory),o=[xle(a),l];(i.supabase||r.supabaseAuth)&&!i.supabaseUrl&&(r.supabaseConn?.url||r.supabaseConn?.key)&&(i.supabaseUrl=r.supabaseConn.url,i.supabaseKey=r.supabaseConn.key),(i.supabase||r.supabaseAuth)&&o.push(jle(i));for(let s of i.sqlRoutes)o.push(Rle(s.schema,s.table,s.dialect,{access:r.accessEnabled,audit:r.auditEnabled,screenIds:r.screensByEntity?.get(s.schema.name)??[],triggers:r.triggers?.[s.schema.name],dbSchema:s.dbSchema,tenantField:r.tenantField&&r.tenantScoped?.(s.schema.name)!==!1?r.tenantField:void 0}));if(i.memoryRoutes.length){o.push(Ile(i.memoryRoutes));for(let s of i.memoryRoutes)o.push(Ele(s.schema,{access:r.accessEnabled,audit:r.auditEnabled,screenIds:r.screensByEntity?.get(s.schema.name)??[],triggers:r.triggers?.[s.schema.name],tenantField:r.tenantField&&r.tenantScoped?.(s.schema.name)!==!1?r.tenantField:void 0}))}return{files:o,prepared:a.map(s=>s.schema)}}function qle(t){if(t.length===0)throw Error("emitStudioApp: no schemas to emit");let{files:r,prepared:a}=n4(t),n=a.map(i=>{let o=En(i);return{href:`/${o.route}`,label:o.label}}),l={path:"src/custom.css",description:"Your custom styles (imported after app.css so it overrides).",userOwned:!0,contents:`/* Your custom styles. Imported after app.css, so these rules override the defaults. */
1490
- `};return[...r,...a.map(i=>Ule(i)),r4(n),a4(n),l]}var Ble="3.1.35",Vle="3.0.32",ml=(t,r)=>t.some(a=>a.config.kind===r),l4=t=>`activeTab_${t.replace(/[^a-zA-Z0-9_$]/g,"_")}`,Zh=(t,r)=>`${t}-${r}`,i4=t=>`accOpen_${t.replace(/[^a-zA-Z0-9_$]/g,"_")}`,Qh=(t,r)=>`${t}-s${r}`,em=t=>`md_${t.replace(/[^a-zA-Z0-9]/g,"_")}_rows`;function Hle(t){switch(t.type){case"number":{let r=t.decimals;return r==null?"{ type: 'number' }":`{ type: 'number', options: { minimumFractionDigits: ${r}, maximumFractionDigits: ${r} } }`}case"currency":return`{ type: 'currency', currency: ${_r(t.currency||"USD")} }`;case"percent":{let r=["type: 'percent'"];return t.valueIsPercentPoints&&r.push("valueIsPercentPoints: true"),t.decimals!=null&&r.push(`options: { minimumFractionDigits: ${t.decimals}, maximumFractionDigits: ${t.decimals} }`),`{ ${r.join(", ")} }`}case"date":case"datetime":return t.pattern?`{ type: '${t.type}', pattern: ${_r(t.pattern)} }`:`{ type: '${t.type}' }`}}function Wle(t,r,a,n){if(r.config.kind!=="grid")return`schemaToColumns(${t})`;let l=r.config,i=r.id.replace(/-/g,"_"),o=l.columns.filter(v=>v.show),s=new Set(o.map(v=>v.field)),c=new Set,d=o.map(v=>{let x=n?.get(v.field);return{c:v,col:x&&!s.has(x)?x:v.field}}).filter(v=>!c.has(v.col)&&!!c.add(v.col)),u=l.editing==="inline"?"":", editable: false";if(d.length===0)return u?`schemaToColumns(${t}).map((c) => ({ ...c${u} }))`:`schemaToColumns(${t})`;let p=d.map(v=>`'${v.col}'`),f=d.map(({c:v,col:x})=>{let w=[];return v.header&&w.push(`header: ${JSON.stringify(v.header)}`),v.width!=null&&w.push(`width: ${v.width}`),v.align&&w.push(`align: '${v.align}'`),v.aggregate&&w.push(`aggregate: '${v.aggregate}'`),l.treeData&&v.field===l.treeData.labelField&&a?w.push(`cell: (ctx: CellContext<${a}>) => renderSnippet(treeCell_${i}, { value: ctx.getValue(), row: ctx.row.original })`):v.cellType&&a?w.push(`cell: (ctx: CellContext<${a}>) => renderSnippet(${p4(i,v.field)}, { value: ctx.getValue() })`):v.format&&w.push(`format: ${Hle(v.format)}`),w.length?`'${x}': { ${w.join(", ")} }`:null}).filter(v=>!!v),y=f.length?` const ov: Record<string, Partial<(typeof all)[number]>> = { ${f.join(", ")} };`:"",h=f.length?", ...(ov[String(c.field)] ?? {})":"",_=`[${p.join(", ")}].map((f) => all.find((c) => c.field === f)).filter((c): c is (typeof all)[number] => !!c)`;return`(() => { const all = schemaToColumns(${t});${y} return ${u||h?`${_}.map((c) => ({ ...c${u}${h} }))`:_} })()`}function kd(t,r){let a=[`grid-column: span ${Hae(t)}`,"min-width: 0"];r&&a.push(r);let n=Gae(t.style);return n&&a.push(n),`style="${a.join("; ")}"`}var Gle=t=>t&&t.replace(/[^#a-zA-Z0-9(),.%\s_-]/g,"").slice(0,40)||"var(--sg-accent)";function qc(t,r){let a=[r,Vae(t)].filter(Boolean).join(" ");return a?` class="${a}"`:""}function $0(t){let r=f2(t.className);return r?` ${r}`:""}function Kle(t){let r=Og(t);if(r==="grid"){let a=sne(t),n=a.maxWidth?` max-width: ${a.maxWidth}px; margin-inline: auto;`:"";return` .st-screen { grid-template-columns: repeat(12, 1fr); gap: ${a.rowGap}px ${a.colGap}px; align-items: ${a.align};${n} }
1490
+ `};return[...r,...a.map(i=>Ule(i)),r4(n),a4(n),l]}var Ble="3.1.37",Vle="3.0.33",ml=(t,r)=>t.some(a=>a.config.kind===r),l4=t=>`activeTab_${t.replace(/[^a-zA-Z0-9_$]/g,"_")}`,Zh=(t,r)=>`${t}-${r}`,i4=t=>`accOpen_${t.replace(/[^a-zA-Z0-9_$]/g,"_")}`,Qh=(t,r)=>`${t}-s${r}`,em=t=>`md_${t.replace(/[^a-zA-Z0-9]/g,"_")}_rows`;function Hle(t){switch(t.type){case"number":{let r=t.decimals;return r==null?"{ type: 'number' }":`{ type: 'number', options: { minimumFractionDigits: ${r}, maximumFractionDigits: ${r} } }`}case"currency":return`{ type: 'currency', currency: ${_r(t.currency||"USD")} }`;case"percent":{let r=["type: 'percent'"];return t.valueIsPercentPoints&&r.push("valueIsPercentPoints: true"),t.decimals!=null&&r.push(`options: { minimumFractionDigits: ${t.decimals}, maximumFractionDigits: ${t.decimals} }`),`{ ${r.join(", ")} }`}case"date":case"datetime":return t.pattern?`{ type: '${t.type}', pattern: ${_r(t.pattern)} }`:`{ type: '${t.type}' }`}}function Wle(t,r,a,n){if(r.config.kind!=="grid")return`schemaToColumns(${t})`;let l=r.config,i=r.id.replace(/-/g,"_"),o=l.columns.filter(v=>v.show),s=new Set(o.map(v=>v.field)),c=new Set,d=o.map(v=>{let x=n?.get(v.field);return{c:v,col:x&&!s.has(x)?x:v.field}}).filter(v=>!c.has(v.col)&&!!c.add(v.col)),u=l.editing==="inline"?"":", editable: false";if(d.length===0)return u?`schemaToColumns(${t}).map((c) => ({ ...c${u} }))`:`schemaToColumns(${t})`;let p=d.map(v=>`'${v.col}'`),f=d.map(({c:v,col:x})=>{let w=[];return v.header&&w.push(`header: ${JSON.stringify(v.header)}`),v.width!=null&&w.push(`width: ${v.width}`),v.align&&w.push(`align: '${v.align}'`),v.aggregate&&w.push(`aggregate: '${v.aggregate}'`),l.treeData&&v.field===l.treeData.labelField&&a?w.push(`cell: (ctx: CellContext<${a}>) => renderSnippet(treeCell_${i}, { value: ctx.getValue(), row: ctx.row.original })`):v.cellType&&a?w.push(`cell: (ctx: CellContext<${a}>) => renderSnippet(${p4(i,v.field)}, { value: ctx.getValue() })`):v.format&&w.push(`format: ${Hle(v.format)}`),w.length?`'${x}': { ${w.join(", ")} }`:null}).filter(v=>!!v),y=f.length?` const ov: Record<string, Partial<(typeof all)[number]>> = { ${f.join(", ")} };`:"",h=f.length?", ...(ov[String(c.field)] ?? {})":"",_=`[${p.join(", ")}].map((f) => all.find((c) => c.field === f)).filter((c): c is (typeof all)[number] => !!c)`;return`(() => { const all = schemaToColumns(${t});${y} return ${u||h?`${_}.map((c) => ({ ...c${u}${h} }))`:_} })()`}function kd(t,r){let a=[`grid-column: span ${Hae(t)}`,"min-width: 0"];r&&a.push(r);let n=Gae(t.style);return n&&a.push(n),`style="${a.join("; ")}"`}var Gle=t=>t&&t.replace(/[^#a-zA-Z0-9(),.%\s_-]/g,"").slice(0,40)||"var(--sg-accent)";function qc(t,r){let a=[r,Vae(t)].filter(Boolean).join(" ");return a?` class="${a}"`:""}function $0(t){let r=f2(t.className);return r?` ${r}`:""}function Kle(t){let r=Og(t);if(r==="grid"){let a=sne(t),n=a.maxWidth?` max-width: ${a.maxWidth}px; margin-inline: auto;`:"";return` .st-screen { grid-template-columns: repeat(12, 1fr); gap: ${a.rowGap}px ${a.colGap}px; align-items: ${a.align};${n} }
1491
1491
  @media (max-width: ${a.mobileBreakpoint}px) { .st-screen { grid-template-columns: 1fr; gap: 12px; } }
1492
1492
  `}if(r==="stack"){let a=dne(t),n=a.maxWidth?` max-width: ${a.maxWidth}px;${a.align==="center"?" margin-inline: auto;":""}`:"",l=a.minHeight?`
1493
1493
  .st-stack > * { min-height: ${a.minHeight}px; }`:"",i=a.dividers?`