@8sheets/data-grid 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +36 -0
- package/README.md +52 -2
- package/a11y/cell-alt-text.js +1 -0
- package/api/overlay.js +1 -0
- package/api/serialize.js +1 -0
- package/api/skins.js +1 -0
- package/api/style-refs.js +1 -0
- package/api/watermark-xml.js +2 -0
- package/calc/adjust.js +1 -0
- package/calc/cell-set.js +1 -0
- package/calc/compile.js +1 -0
- package/calc/engine.js +1 -0
- package/calc/fill-shape.js +2 -0
- package/calc/functions/array.js +1 -0
- package/calc/functions/database.js +1 -0
- package/calc/functions/date.js +1 -0
- package/calc/functions/engineering.js +1 -0
- package/calc/functions/financial.js +1 -0
- package/calc/functions/helpers.js +1 -0
- package/calc/functions/index.js +1 -0
- package/calc/functions/info.js +1 -0
- package/calc/functions/logical.js +1 -0
- package/calc/functions/lookup.js +1 -0
- package/calc/functions/math.js +1 -0
- package/calc/functions/registry.js +1 -0
- package/calc/functions/stat.js +1 -0
- package/calc/functions/text.js +1 -0
- package/calc/parser.js +3 -0
- package/calc/values.js +1 -0
- package/calcx/ai/client.js +1 -0
- package/calcx/ai/functions.js +15 -0
- package/calcx/ai/settings.js +1 -0
- package/calcx/async.js +1 -0
- package/calcx/culture/format-locale.js +1 -0
- package/calcx/culture/lcid.js +1 -0
- package/calcx/external-read.js +1 -0
- package/calcx/external-write.js +3 -0
- package/calcx/external.js +1 -0
- package/calcx/functions/dynamic.js +1 -0
- package/calcx/functions/ets.js +1 -0
- package/calcx/functions/index.js +1 -0
- package/calcx/functions/misc.js +1 -0
- package/calcx/functions/text.js +1 -0
- package/calcx/functions/xml.js +1 -0
- package/calcx/refresh.js +1 -0
- package/cells/auto-merge.js +1 -0
- package/cells/axis-limits.js +1 -0
- package/cells/axis-ops.js +1 -0
- package/cells/background-xml.js +1 -0
- package/cells/background.js +1 -0
- package/cells/book-css.js +206 -0
- package/cells/book-read.js +1 -0
- package/cells/book-view.js +1 -0
- package/cells/cell-defaults.js +1 -0
- package/cells/cell-extras.js +1 -0
- package/cells/cell-options-ui.js +1 -0
- package/cells/cell-styles-xml.js +1 -0
- package/cells/cf-engine.js +1 -0
- package/cells/cf-file.js +1 -0
- package/cells/cf-paint.js +1 -0
- package/cells/consolidate-links.js +1 -0
- package/cells/docprops-xml.js +2 -0
- package/cells/filter-file.js +1 -0
- package/cells/find-engine.js +2 -0
- package/cells/find.js +1 -0
- package/cells/format-code.js +1 -0
- package/cells/format-panes.js +3 -0
- package/cells/format-tabs.js +102 -0
- package/cells/goto.js +1 -0
- package/cells/header-colors.js +1 -0
- package/cells/mask.js +1 -0
- package/cells/menu-extras.js +1 -0
- package/cells/name-box.js +1 -0
- package/cells/note-xml.js +1 -0
- package/cells/options.js +1 -0
- package/cells/outline-column.js +1 -0
- package/cells/paint.js +1 -0
- package/cells/panes.js +1 -0
- package/cells/rich-data-xml.js +2 -0
- package/cells/rich-data.js +1 -0
- package/cells/rich-runs.js +2 -0
- package/cells/rich-values.js +1 -0
- package/cells/rich-xml.js +1 -0
- package/cells/rounded.js +1 -0
- package/cells/sections.js +2 -0
- package/cells/selection-modes.js +1 -0
- package/cells/style-xml.js +1 -0
- package/cells/text-layout.js +8 -0
- package/cells/undo-group.js +1 -0
- package/cells/validation-alert.js +2 -0
- package/cells/view-options.js +1 -0
- package/cells/view-xml.js +1 -0
- package/celltypes/barcode-tables.js +31 -0
- package/celltypes/barcode.js +2 -0
- package/celltypes/base.js +1 -0
- package/celltypes/cell-buttons.js +1 -0
- package/celltypes/cell-types.js +2 -0
- package/celltypes/data-object.js +1 -0
- package/celltypes/diagonal.js +1 -0
- package/celltypes/dropdowns-more.js +13 -0
- package/celltypes/dropdowns.js +42 -0
- package/celltypes/file-cell.js +2 -0
- package/celltypes/glyphs.js +1 -0
- package/celltypes/persist.js +2 -0
- package/celltypes/range-template.js +2 -0
- package/charts/chartex.js +3 -0
- package/charts/geo/geo-xml.js +1 -0
- package/charts/geo/map-state.js +1 -0
- package/charts/patterns.js +1 -0
- package/core/address.js +1 -0
- package/core/axis.js +1 -0
- package/core/base64.js +1 -0
- package/core/changes.js +1 -0
- package/core/color.js +1 -0
- package/core/cond-format.js +1 -0
- package/core/custom-views.js +1 -0
- package/core/default-names.js +1 -0
- package/core/formula-refs.js +1 -0
- package/core/formula-store.js +1 -0
- package/core/input.js +1 -0
- package/core/math.js +1 -0
- package/core/numfmt.js +1 -0
- package/core/online.js +1 -0
- package/core/protection.js +1 -0
- package/core/regexp.js +1 -0
- package/core/sheet-group.js +1 -0
- package/core/sheet.js +1 -0
- package/core/sparklines.js +1 -0
- package/core/sparse.js +1 -0
- package/core/strings.js +1 -0
- package/core/styles.js +1 -0
- package/core/table-presets.js +7 -0
- package/core/tables.js +2 -0
- package/core/tsv.js +4 -0
- package/core/whatif.js +1 -0
- package/core/workbook.js +1 -0
- package/datasheets/bind.js +1 -0
- package/datasheets/calendar.js +1 -0
- package/datasheets/cross.js +1 -0
- package/datasheets/data-core.js +1 -0
- package/datasheets/data.js +1 -0
- package/datasheets/formula.js +1 -0
- package/datasheets/gantt-paint.js +1 -0
- package/datasheets/gantt-resources.js +1 -0
- package/datasheets/gantt-shapes.js +1 -0
- package/datasheets/gantt.js +1 -0
- package/datasheets/manager.js +1 -0
- package/datasheets/path-binding.js +2 -0
- package/datasheets/persist-writer.js +2 -0
- package/datasheets/persist.js +1 -0
- package/datasheets/query-function.js +1 -0
- package/datasheets/remote.js +3 -0
- package/datasheets/report-entry.js +1 -0
- package/datasheets/report.js +1 -0
- package/datasheets/rules.js +1 -0
- package/datasheets/sort.js +1 -0
- package/datasheets/table-sheet.js +1 -0
- package/datasheets/view.js +3 -0
- package/datasheets/virtual-sheet.js +1 -0
- package/datasheets/window.js +1 -0
- package/extras/getdata/persist.js +2 -0
- package/extras/getdata/rows.js +1 -0
- package/extras/getdata/steps.js +1 -0
- package/i18n/dom.js +1 -0
- package/i18n/en/a11y.js +1 -0
- package/i18n/en/cells.js +1 -0
- package/i18n/en/charts.js +1 -0
- package/i18n/en/common.js +1 -0
- package/i18n/en/datasheets.js +1 -0
- package/i18n/en/format.js +1 -0
- package/i18n/en/misc.js +1 -0
- package/i18n/en/pivot.js +1 -0
- package/i18n/en/proofing.js +1 -0
- package/i18n/en/ribbon.js +1 -0
- package/i18n/en/shapes.js +1 -0
- package/i18n/en/shell.js +1 -0
- package/i18n/en/touch.js +1 -0
- package/i18n/en.js +1 -0
- package/i18n/index.js +1 -0
- package/i18n/key-text.js +1 -0
- package/i18n/languages.js +1 -0
- package/i18n/pl/a11y.js +1 -0
- package/i18n/pl/cells.js +1 -0
- package/i18n/pl/charts.js +1 -0
- package/i18n/pl/common.js +1 -0
- package/i18n/pl/datasheets.js +1 -0
- package/i18n/pl/format.js +1 -0
- package/i18n/pl/misc.js +1 -0
- package/i18n/pl/pivot.js +1 -0
- package/i18n/pl/proofing.js +1 -0
- package/i18n/pl/ribbon.js +1 -0
- package/i18n/pl/shapes.js +1 -0
- package/i18n/pl/shell.js +1 -0
- package/i18n/pl/touch.js +1 -0
- package/i18n/pl.js +1 -0
- package/io/client.js +1 -0
- package/io/crc32.js +1 -0
- package/io/crypto/aes.js +1 -0
- package/io/crypto/agile.js +2 -0
- package/io/crypto/cfb-read.js +1 -0
- package/io/crypto/cfb-write.js +1 -0
- package/io/crypto/dataspaces.js +1 -0
- package/io/crypto/errors.js +1 -0
- package/io/crypto/hash.js +1 -0
- package/io/crypto/index.js +1 -0
- package/io/crypto/package-read.js +1 -0
- package/io/crypto/package-write.js +1 -0
- package/io/crypto/spool.js +1 -0
- package/io/crypto/standard.js +1 -0
- package/io/csv.js +8 -0
- package/io/export-blocks.js +1 -0
- package/io/foreign-parts.js +1 -0
- package/io/foreign-sheets.js +2 -0
- package/io/io.worker.js +1 -0
- package/io/package-paths.js +1 -0
- package/io/plan.js +1 -0
- package/io/text-split.js +3 -0
- package/io/xlsx-read.js +1 -0
- package/io/xlsx-styles.js +2 -0
- package/io/xlsx-tail.js +1 -0
- package/io/xlsx-write.js +2 -0
- package/io/xml-escape.js +1 -0
- package/io/xml-scan.js +1 -0
- package/io/zip-reader.js +1 -0
- package/io/zip-writer.js +1 -0
- package/objects/chart-model.js +1 -0
- package/objects/dml.js +5 -0
- package/objects/drawing-xml.js +1 -0
- package/objects/picture-url.js +1 -0
- package/package.json +57 -4
- package/pivot/engine.js +1 -0
- package/pivot/xml.js +2 -0
- package/print/page-setup.js +1 -0
- package/print/paginate.js +1 -0
- package/print/pdf.js +35 -0
- package/print/render-page.js +3 -0
- package/render/patterns.js +1 -0
- package/shapes/form-xml.js +1 -0
- package/shapes/watermark.js +1 -0
- package/slicers/custom-styles.js +1 -0
- package/slicers/date-filters.js +1 -0
- package/slicers/format.js +2 -0
- package/slicers/pivot-file.js +1 -0
- package/slicers/structured.js +1 -0
- package/slicers/table-file.js +1 -0
- package/slicers/write.js +1 -0
- package/sparklines/colors.js +1 -0
- package/sparklines/data.js +1 -0
- package/sparklines/descriptor.js +1 -0
- package/sparklines/excel-paint.js +1 -0
- package/sparklines/functions.js +1 -0
- package/sparklines/paint-core.js +1 -0
- package/sparklines/paint-measure.js +1 -0
- package/sparklines/paint-other.js +2 -0
- package/sparklines/paint-series.js +1 -0
- package/sparklines/paint.js +1 -0
- package/sparklines/print.js +1 -0
- package/sparklines/rule.js +1 -0
- package/table-view/api.js +1 -0
- package/table-view/cell-editor.js +1 -0
- package/table-view/cell-format.js +1 -0
- package/table-view/chrome.js +1 -0
- package/table-view/client.js +1 -0
- package/table-view/column-drag.js +1 -0
- package/table-view/column-input.js +1 -0
- package/table-view/column-window.js +1 -0
- package/table-view/events.js +1 -0
- package/table-view/files.js +1 -0
- package/table-view/grid-keys.js +2 -0
- package/table-view/index.d.ts +4 -0
- package/table-view/index.js +1 -0
- package/table-view/labels.js +1 -0
- package/table-view/model.js +1 -0
- package/table-view/mount.js +1 -0
- package/table-view/panel.js +1 -0
- package/table-view/pivot.js +1 -0
- package/table-view/public.d.ts +841 -0
- package/table-view/quick-filter.js +1 -0
- package/table-view/reader.worker.js +1 -0
- package/table-view/remote.js +1 -0
- package/table-view/row-cache.js +1 -0
- package/table-view/row-selection.js +1 -0
- package/table-view/table-css.js +1207 -0
- package/table-view/totals.js +1 -0
- package/table-view/version.js +1 -0
- package/table-view/worksheet-table.js +1 -0
- package/ui/dialogs.js +3 -0
- package/ui/dom.js +1 -0
- package/ui/icons.js +1 -0
- package/ui/menu-base.js +1 -0
- package/ui/protection-ui.js +1 -0
- package/ui/ui-scale.js +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const m={">":"gt",">=":"gte","<":"lt","<=":"lte","=":"equal","<>":"notEqual","!=":"notEqual"};function s(r,u){const n=r.trim();if(u==="date")return n;const t=Number(n.replace(/\s/g,"").replace(/^(-?\d+),(\d+)$/,"$1.$2"));return Number.isFinite(t)?t:null}function f(r,u,n){const t=String(u??"").trim();if(!t)return null;const e={field:r,quick:!0,text:t};if(n==="number"||n==="date"){const l=t.match(/^(.+?)\s*\.\.\s*(.+)$/);if(l){const i=s(l[1],n),o=s(l[2],n);if(i!==null&&o!==null&&i!==""&&o!=="")return{...e,op:"between",value:i,value2:o}}const c=t.match(/^(>=|<=|<>|!=|>|<|=)?\s*(.+)$/),a=s(c[2],n);return a!==null&&a!==""?{...e,op:m[c[1]??"="],value:a}:{...e,op:"contains",value:t}}return t.startsWith("=")&&t.length>1?{...e,op:"equal",value:t.slice(1).trim()}:{...e,op:"contains",value:t}}export{f as parseQuickFilter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{STR as S}from"../core/sheet.js";import{DataManager as x}from"../datasheets/data-core.js";import{Reader as h,display as w}from"./model.js";import{MAX_COLS as O,MAX_ROWS as C,parseRangeRef as T}from"../core/address.js";import{STAGE as m}from"../datasheets/view.js";import{countSelected as F,selectedRecords as A,selectionTest as q}from"./row-selection.js";const N=new Set(["page","toggle","distinct","detail","chart","records","selectionCount","selectedIds","rows","record","rowOf"]),L=e=>e.formula==null&&e.trigger==null&&e.validator==null&&!(typeof e.defaultValue=="string"&&e.defaultValue.startsWith("="));function P(e){return e.op==="data"?!(e.fields??[]).every(L):e.op==="page"?e.state?.filters?.some(t=>t.formula!=null)??!1:!N.has(e.op)}let v=null;function V(){return v??=import("../datasheets/data.js").catch(e=>{throw v=null,e}),v}const W={file:()=>[import("./files.js"),import("./worksheet-table.js")],selectionStart:()=>[import("../core/workbook.js"),import("./worksheet-table.js")]};let o,u,k,f,d;const p=new Map;let b;function y(e,t){return o?.view.dispose(),o=new h(e,t),o.fields}let R=()=>{};function j(e){let t=0;return r=>{const n=performance.now();n-t<100||(t=n,self.postMessage({requestId:e,progress:r}))}}async function U(e){switch(e.op){case"selectionStart":{const{Workbook:t}=await import("../core/workbook.js");d=new t;return}case"selectionBatch":{const t=e.codes.map(r=>d.styles.derive(0,{numFmt:r}));for(let r=0;r<e.kinds.length;r++){if(!e.kinds[r])continue;const n=Math.floor((e.from+r)/e.cols),a=(e.from+r)%e.cols,l=e.kinds[r]===S?d.strings.add(e.texts[e.values[r]]):e.values[r];d.sheet.setCell(n,a,e.kinds[r],l),t[e.styles[r]]&&d.sheet.setStyle(n,a,t[e.styles[r]])}return}case"selectionEnd":{const{worksheetTable:t}=await import("./worksheet-table.js"),r=t(d,d.sheet,{r0:0,c0:0,r1:e.rows-1,c1:e.cols-1},e.headers,e.headerRows);return d=null,y(r,!1)}case"enableEdit":return o.editable=!0,o.fields;case"paste":{const t=o.view,r=t.perm.subarray(0,t.filteredCount),n=r.indexOf(e.id),a=t.columnIndex(e.field),l=e.lines.length*e.repeat;if(n<0||a<0||!Number.isSafeInteger(e.repeat)||e.repeat<1||n+l>r.length||e.lines.some(c=>a+c.length>t.columns.length))throw new Error("Paste exceeds the available records or columns.");const i=[];for(let c=0;c<l;c++)e.lines[c%e.lines.length].forEach((I,M)=>i.push({id:r[n+c],field:t.columns[a+M].field,value:I}));const s=o.edit(i);s.length&&(o.undo.push(s),o.redo.length=0);return}case"file":{const{openFile:t,sourcesOf:r}=await import("./files.js"),n=await t(e.file,e.csv,R),a=r(n);if(!a.length)throw new Error("This file contains no visible data.");return u=n,k=a,p.clear(),f=null,a}case"source":{const t=k[e.index],r=e.range?T(e.range.replaceAll("$","")):t.range;if(!r||r.r0<0||r.c0<0||r.r1>=C||r.c1>=O||r.r0<t.range.r0||r.c0<t.range.c0||r.r1>t.range.r1||r.c1>t.range.c1)throw new Error("Choose a range inside the source.");const n=t.whole?+(e.header!==!1):t.headerRows,a=JSON.stringify([e.index,t.native?null:[r.r0,r.c0,r.r1,r.c1],n]);if(f&&o.editable&&(p.set(f,o),o=null),f=a,p.has(a))return o?.view.dispose(),o=p.get(a),o.editable=e.editable,o.fields;const{worksheetTable:l}=await import("./worksheet-table.js"),i=t.native?u.book.sheets[t.sheet].table:l(u.book,u.book.sheets[t.sheet],r,t.headers,n,t.name);return y(i,e.editable)}case"data":{const t=new x;for(const[n,a]of Object.entries(e.strings??{})){const l=a.map(s=>t.strings.add(s)),i=e.data[n];for(let s=0;s<i.length;s++)i[s]>=0&&(i[s]=l[i[s]])}const r=t.addTable("Records",{fields:e.fields,data:e.data});return y(r,e.editable)}case"pivot":{const{pivotTable:t}=await import("./pivot.js"),r=t(o,e);return b=o,o=new h(r),o.fields}case"records":return o.view.dispose(),o=b,b=null,o.fields;case"chart":{const t=o.view,r=o.table.column(e.field);if(!r||!t.columns.some(l=>l.field===e.field))throw new Error("Field unavailable.");const n=o.table.column(t.columns[0].field),a=[];for(const l of t.perm){const i=r.get(l);l===o.table.rowCount-1||typeof i!="number"||!Number.isFinite(i)||a.length===20&&Math.abs(i)<=Math.abs(a[19].value)||(a.push({label:w(n.get(l),n.format),value:i,text:w(i,r.format)}),a.sort((s,c)=>Math.abs(c.value)-Math.abs(s.value)),a.length>20&&a.pop())}return a}case"distinct":return o.view.distinctValues(e.field,{limit:500});case"detail":return o.view.columns.map(t=>({field:t.field,value:w(t.col.get(e.id),t.format)}));case"page":return e.state&&o.apply(e.state),o.page(e.offset,e.limit,e.columnOffset,e.columnLimit);case"toggle":return o.view.toggleRow(e.index),o.page(e.offset,e.limit,e.columnOffset,e.columnLimit);case"edit":{const t=o.edit(e.cells);t.length&&(o.undo.push(t),o.redo.length=0);break}case"add":case"remove":{const t=e.op==="add"?(e.records??[e.values]).map(n=>({kind:"add",values:n??{}})):(e.ids??[e.record]).map(n=>({kind:"remove",id:n}));if(!t.length)return[];const r=o.rowActions(t);return o.undo.push(r),o.redo.length=0,e.op==="add"?r.kind==="batch"?r.actions.map(n=>n.id).reverse():[r.id]:t.map(n=>n.id)}case"rows":return o.records(e.offset,e.limit);case"record":return o.record(e.id);case"rowOf":{const t=o.view;return t.refresh(),Number.isInteger(e.id)&&e.id>=0?t.rowOfRecord(e.id):-1}case"undo":case"redo":{const t=o[e.op],r=e.op==="undo"?o.redo:o.undo;if(t.length){const n=t.at(-1);r.push(Array.isArray(n)?o.edit(n,!0):o.rowAction(n)),t.pop()}break}case"formula":{if(!o.editable)throw new Error("This view is read-only.");if(!e.name.trim()||!e.formula.trim()||o.table.column(e.name))throw new Error("Choose an unused column name and a formula.");return o.table.addField({name:e.name,type:"any",formula:e.formula.replace(/^=/,"")}),o.fields}case"export":{const{exportResults:t}=await import("./files.js"),r=new h(o.table);try{r.apply(e.state);const n=e.selection&&q(e.selection);return n&&(r.view.spec.filters=[...r.view.spec.filters,{fn:n}],r.view.invalidate(m.FILTER)),await t(r,e.format)}finally{r.view.dispose()}}case"selectionCount":{const t=o.view;return t.refresh(),F(e.selection,t.filtered,t.filteredCount)}case"selectedIds":{const t=o.view;return t.refresh(),A(e.selection,t.perm,t.filteredCount)}default:throw new Error("Unknown table action.")}}let E=Promise.resolve();self.onmessage=({data:e})=>{E=E.then(async()=>{try{P(e)&&await Promise.all([V(),...W[e.op]?.()??[]]),R=j(e.requestId),self.postMessage({requestId:e.requestId,value:await U(e)})}catch(t){self.postMessage({requestId:e.requestId,error:t.message})}})};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function T({queryUrl:d,exportUrl:w,detailUrl:y,updateUrl:p,headers:u,credentials:l="same-origin",formats:b=["xlsx","csv"],selectionExport:h=!1}){async function i(s,t,e){const a=typeof u=="function"?await u():u,c=new Headers(a);c.set("Content-Type","application/json");const n=await fetch(s,{method:"POST",credentials:l,headers:c,body:JSON.stringify(t),signal:e});if(n.status===409)throw new Error("The data changed. Reopen the record before editing.");if(!n.ok)throw new Error(`Table request failed (HTTP ${n.status}).`);return n}const o={formats:b,async query({state:s,offset:t,limit:e,columnOffset:a,columnLimit:c,signal:n}){const r=await(await i(d,{state:s,offset:t,limit:e,columnOffset:a,columnLimit:c},n)).json();if(!Array.isArray(r.rows)||r.rows.length>e||!Array.isArray(r.columns)||!Number.isSafeInteger(r.offset)||r.offset<0||![r.count,r.matches,r.sourceCount].every(f=>f===void 0||Number.isSafeInteger(f)&&f>=0))throw new Error("Invalid table response.");return r}};return p&&(o.update=async({state:s,revision:t,cells:e})=>(await i(p,{state:s,revision:t,cells:e})).json()),y&&(o.detail=async({id:s,state:t,signal:e})=>(await i(y,{id:s,state:t},e)).json()),w&&(o.selectionExport=h,o.exportResults=async({state:s,format:t,selection:e,signal:a})=>(await i(w,e?{state:s,format:t,selection:e}:{state:s,format:t},a)).blob()),o}export{T as remoteTableSource};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class f{constructor({fetch:t,blockSize:s=100,maxBlocks:i=24,onLoad:l=()=>{},onError:n=()=>{}}){this.fetch=t,this.blockSize=s,this.maxBlocks=Math.max(4,i),this.onLoad=l,this.onError=n,this.blocks=new Map,this.inflight=new Map,this.generation=0,this.key=null,this.meta=null,this.total=null,this.known=0,this.wanted=new Set,this.reaching=new Set}reset(t=null){this.abortAll(),this.reaching.clear(),this.generation++,this.key=t,this.blocks.clear(),this.meta=null,this.total=null,this.known=0}invalidate(){this.abortAll(),this.generation++,this.blocks.clear()}abortAll(){for(const{controller:t}of this.inflight.values())t.abort();this.inflight.clear()}get count(){return this.total!==null?this.total:this.known+this.blockSize}get exact(){return this.total!==null}has(t){return this.blocks.has(t)}window(t,s){const i=[],l=Math.min(this.count,t+s);let n=!1;for(let h=Math.max(0,t);h<l;h++){const o=Math.floor(h/this.blockSize),r=this.blocks.get(o);if(!r){i.push({loading:!0,index:h}),n=!0;continue}const e=r[h-o*this.blockSize];if(e===void 0)break;i.push(e)}return{rows:i,missing:n}}covers(t,s){const i=Math.min(this.count,t+s);for(let l=Math.floor(Math.max(0,t)/this.blockSize);l*this.blockSize<i;l++)if(!this.blocks.has(l))return!1;return!0}request(t,s){const i=this.blockSize,l=Math.floor(Math.max(0,t)/i),n=Math.max(l,Math.floor(Math.max(t,t+s-1)/i)),h=[];for(let e=l;e<=n;e++)(e*i<this.count||e===0)&&h.push(e);const o=new Set(h),r=n+1;r*i<this.count&&o.add(r),this.wanted=o;for(const[e,a]of this.inflight)!o.has(e)&&!this.reaching.has(e)&&(a.controller.abort(),this.inflight.delete(e));for(const e of o)!this.blocks.has(e)&&!this.inflight.has(e)&&this.load(e);for(const e of h)this.touch(e);return Promise.all(h.map(e=>this.inflight.get(e)?.promise)).then(()=>{})}reach(t){const s=Math.floor(Math.max(0,t)/this.blockSize);if(this.blocks.has(s))return Promise.resolve();this.inflight.has(s)||this.load(s);const i=this.inflight.get(s)?.promise??Promise.resolve();return this.reaching.add(s),i.finally(()=>this.reaching.delete(s))}touch(t){const s=this.blocks.get(t);s&&(this.blocks.delete(t),this.blocks.set(t,s))}load(t){const s=new AbortController,i=this.generation,l=t*this.blockSize;let n;try{n=Promise.resolve(this.fetch(l,this.blockSize,s.signal))}catch(o){n=Promise.reject(o)}const h=n.then(o=>{i!==this.generation||s.signal.aborted||(this.inflight.delete(t),this.accept(t,o),this.onLoad())},o=>{i!==this.generation||s.signal.aborted||o?.name==="AbortError"||(this.inflight.delete(t),this.onError(o))});this.inflight.set(t,{controller:s,promise:h})}accept(t,s){const i=this.blockSize,l=t*i,n=s.rows,h=Number.isSafeInteger(s.offset)&&s.offset!==l;if(h||this.blocks.set(t,n),this.meta=s,Number.isSafeInteger(s.count)&&s.count>=0?this.total=s.count:(h||n.length<i)&&(this.total=h?Math.min(this.known,s.offset+n.length):l+n.length),h||(this.known=Math.max(this.known,l+n.length)),this.total!==null){this.known=this.total;for(const o of this.blocks.keys())o*i>=this.total&&o>0&&this.blocks.delete(o)}this.evict()}evict(){for(const t of this.blocks.keys()){if(this.blocks.size<=this.maxBlocks)break;this.wanted.has(t)||this.blocks.delete(t)}}}export{f as BlockCache};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class d{constructor(t="multiple"){this.mode=t==="single"?"single":"multiple",this.all=!1,this.ids=new Set}has(t){return this.all!==this.ids.has(t)}get empty(){return!this.all&&this.ids.size===0}toggle(t,s=!this.has(t)){if(this.mode==="single"){this.all=!1,this.ids.clear(),s&&this.ids.add(t);return}s===this.all?this.ids.delete(t):this.ids.add(t)}selectAll(){this.mode!=="single"&&(this.all=!0,this.ids.clear())}clear(){this.all=!1,this.ids.clear()}toJSON(){return this.all?{all:!0,except:[...this.ids]}:{all:!1,ids:[...this.ids]}}set(t){if(this.clear(),!!t)if(t.all===!0&&this.mode==="multiple"){this.all=!0;for(const s of t.except??[])this.ids.add(s)}else for(const s of(t.ids??[]).slice(0,this.mode==="single"?1:void 0))this.ids.add(s)}}function h(e,t=s=>s){if(!e)return null;if(e.all){const i=new Set(e.except??[]);return i.size?l=>!i.has(t(l)):null}const s=new Set(e.ids??[]);return i=>s.has(t(i))}function a(e,t,s){let i=0,l=t-1;for(;i<=l;){const r=i+l>>>1,n=e[r];if(n===s)return!0;n<s?i=r+1:l=r-1}return!1}function o(e,t,s=t.length){if(!e)return 0;const i=e.all?e.except??[]:e.ids??[];let l=0;for(const r of new Set(i))Number.isInteger(r)&&a(t,s,r)&&l++;return e.all?s-l:l}function u(e,t,s=t.length){const i=h(e);if(!i)return Array.from(t.subarray(0,s));const l=[];for(let r=0;r<s;r++)i(t[r])&&l.push(t[r]);return l}export{d as RowSelection,o as countSelected,u as selectedRecords,h as selectionTest};
|