@nanoporetech-digital/components 4.9.0 → 4.9.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/CHANGELOG.md +11 -0
- package/dist/cjs/{nano-table-c0eb1f40.js → nano-table-ba660665.js} +2 -2
- package/dist/cjs/{nano-table-c0eb1f40.js.map → nano-table-ba660665.js.map} +1 -1
- package/dist/cjs/nano-table.cjs.entry.js +1 -1
- package/dist/cjs/{table.worker-444f9491.js → table.worker-1e265707.js} +3 -3
- package/dist/cjs/table.worker-1e265707.js.map +1 -0
- package/dist/cjs/{table.worker-c784fdac.js → table.worker-f820b411.js} +1 -1
- package/dist/collection/components/table/table-interface.js.map +1 -1
- package/dist/collection/components/table/table.worker.js +20 -4
- package/dist/collection/components/table/table.worker.js.map +1 -1
- package/dist/components/table.worker.js +1 -1
- package/dist/esm/{nano-table-c5d30202.js → nano-table-c68bc58c.js} +2 -2
- package/dist/esm/{nano-table-c5d30202.js.map → nano-table-c68bc58c.js.map} +1 -1
- package/dist/esm/nano-table.entry.js +1 -1
- package/dist/esm/{table.worker-fee0d673.js → table.worker-8c883d01.js} +3 -3
- package/dist/esm/table.worker-8c883d01.js.map +1 -0
- package/dist/esm/{table.worker-c784fdac.js → table.worker-f820b411.js} +1 -1
- package/dist/nano-components/nano-components.esm.js +1 -1
- package/dist/nano-components/{p-08c62411.js → p-097270e7.js} +2 -2
- package/dist/nano-components/{p-8157414f.entry.js → p-26cae735.entry.js} +2 -2
- package/dist/nano-components/p-a26ec47a.js +5 -0
- package/dist/nano-components/{p-c784fdac.js → p-f820b411.js} +1 -1
- package/dist/types/components/table/table-interface.d.ts +2 -2
- package/docs-json.json +1 -1
- package/hydrate/index.js +20 -4
- package/package.json +2 -2
- package/dist/cjs/table.worker-444f9491.js.map +0 -1
- package/dist/esm/table.worker-fee0d673.js.map +0 -1
- package/dist/nano-components/p-aeb1d0a0.js +0 -5
- /package/dist/nano-components/{p-08c62411.js.map → p-097270e7.js.map} +0 -0
- /package/dist/nano-components/{p-8157414f.entry.js.map → p-26cae735.entry.js.map} +0 -0
- /package/dist/nano-components/{p-aeb1d0a0.js.map → p-a26ec47a.js.map} +0 -0
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Object.defineProperty(exports, '__esModule', { value: true });
|
7
7
|
|
8
|
-
const nanoTable_entry = require('./nano-table-
|
8
|
+
const nanoTable_entry = require('./nano-table-ba660665.js');
|
9
9
|
require('./index-71f899a7.js');
|
10
10
|
require('./math-a8123703.js');
|
11
11
|
require('./throttle-f55496c8.js');
|
@@ -3,7 +3,7 @@
|
|
3
3
|
*/
|
4
4
|
'use strict';
|
5
5
|
|
6
|
-
const nanoTable_entry = require('./nano-table-
|
6
|
+
const nanoTable_entry = require('./nano-table-ba660665.js');
|
7
7
|
require('./index-71f899a7.js');
|
8
8
|
require('./math-a8123703.js');
|
9
9
|
require('./throttle-f55496c8.js');
|
@@ -11,7 +11,7 @@ require('./index-99649bef.js');
|
|
11
11
|
|
12
12
|
const workerName = 'table.worker';
|
13
13
|
const workerMsgId = 'stencil.table.worker';
|
14
|
-
const workerPath = /*@__PURE__*/(typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/table.worker-
|
14
|
+
const workerPath = /*@__PURE__*/(typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __dirname + '/table.worker-f820b411.js').href : new URL('table.worker-f820b411.js', document.currentScript && document.currentScript.src || document.baseURI).href);
|
15
15
|
const blob = new Blob(['importScripts("' + workerPath + '")'], { type: 'text/javascript' });
|
16
16
|
const url = URL.createObjectURL(blob);
|
17
17
|
const worker = /*@__PURE__*/nanoTable_entry.createWorker(url, workerName, workerMsgId);
|
@@ -22,4 +22,4 @@ exports.workerMsgId = workerMsgId;
|
|
22
22
|
exports.workerName = workerName;
|
23
23
|
exports.workerPath = workerPath;
|
24
24
|
|
25
|
-
//# sourceMappingURL=table.worker-
|
25
|
+
//# sourceMappingURL=table.worker-1e265707.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"file":"table.worker-1e265707.js","mappings":";;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":[],"sourcesContent":[],"version":3}
|
@@ -1,4 +1,4 @@
|
|
1
1
|
/*!
|
2
2
|
* Web Components for Nanopore digital Web Apps
|
3
3
|
*/
|
4
|
-
(()=>{"use strict";const e=(e,t)=>{const n=globalThis[t];return n!=null&&e instanceof n};const t=n=>{if(n!=null){if(e(n,"ArrayBuffer")||e(n,"MessagePort")||e(n,"ImageBitmap")||e(n,"OffscreenCanvas")){return[n]}if(typeof n==="object"){if(n.constructor===Object){n=Object.values(n)}if(Array.isArray(n)){return n.flatMap(t)}return t(n.buffer)}}return[]};const n={};const r="stencil.table.worker";const o=r+".cb";addEventListener("message",(async({data:e})=>{if(e&&e[0]===r){let
|
4
|
+
(()=>{"use strict";const e=(e,t)=>{const n=globalThis[t];return n!=null&&e instanceof n};const t=n=>{if(n!=null){if(e(n,"ArrayBuffer")||e(n,"MessagePort")||e(n,"ImageBitmap")||e(n,"OffscreenCanvas")){return[n]}if(typeof n==="object"){if(n.constructor===Object){n=Object.values(n)}if(Array.isArray(n)){return n.flatMap(t)}return t(n.buffer)}}return[]};const n={};const r="stencil.table.worker";const o=r+".cb";addEventListener("message",(async({data:e})=>{if(e&&e[0]===r){let i=e[1];let s=e[2];let f=e[3];let u=0;let c=f.length;let a;let l;try{for(;u<c;u++){if(Array.isArray(f[u])&&f[u][0]===o){const e=f[u][1];f[u]=(...t)=>{postMessage([o,e,t])}}}a=await n[s](...f)}catch(e){a=null;if(e instanceof Error){l={isError:true,value:{message:e.message,name:e.name,stack:e.stack}}}else{l={isError:false,value:e}}a=undefined}const p=t(a);postMessage([r,i,a,l],p)}}));var i=typeof globalThis!=="undefined"?globalThis:typeof window!=="undefined"?window:typeof global!=="undefined"?global:typeof self!=="undefined"?self:{};var s=1/0;var f="[object Symbol]";var u=/[\\^$.*+?()[\]{}|]/g,c=RegExp(u.source);var a=typeof i=="object"&&i&&i.Object===Object&&i;var l=typeof self=="object"&&self&&self.Object===Object&&self;var p=a||l||Function("return this")();var d=Object.prototype;var h=d.toString;var w=p.Symbol;var y=w?w.prototype:undefined,g=y?y.toString:undefined;function b(e){if(typeof e=="string"){return e}if(m(e)){return g?g.call(e):""}var t=e+"";return t=="0"&&1/e==-s?"-0":t}function v(e){return!!e&&typeof e=="object"}function m(e){return typeof e=="symbol"||v(e)&&h.call(e)==f}function k(e){return e==null?"":b(e)}function $(e){e=k(e);return e&&c.test(e)?e.replace(u,"\\$&"):e}var E=$;function x(e,t){if(typeof e==="string"){return t.checkString(e)}else if(typeof e==="number"){return t.checkNumber(e)}else{return false}}function A(e,t,n,r){if(typeof e==="object"){if(Array.isArray(e)){for(const o of e){if(A(o,t,n,r)){return true}}}else{for(const o in e){n.push(o);const i=A(e[o],t,n,r);n.pop();if(i)return true}}}else if(t.type==="exists"){if(t.key.test(n.join("."))){return!!e}else{return false}}else{const o=n.join(".");for(const e of r.ignorePaths){if(e.test(o))return false}if(r.includePaths){let e=false;for(const t of r.includePaths){if(t.test(o)){e=true;break}}if(!e)return false}if(t.key){if(!t.key.test(o))return false}return x(e,t)}return false}function j(e,t,n,r){if(t.length){let o=false;for(const i of t){if(A(e,i,[],r)?!i.negate:i.negate){if(n==="OR"){return true}o=true}else if(n==="AND"){return false}}return o}return true}function N(e,t){const n=[];let r=false;let o=0;let i="";for(let s=0;s<e.length;s++){const f=e[s];if(r){if(f===i){r=false;i=""}}else if(f==='"'||f==="'"){r=true;i=f}else if(f.match(t)&&!r){n.push(e.slice(o,s).trim());o=s+1}if(s===e.length-1){n.push(e.slice(o).trim())}}return n.map((e=>{if(e.startsWith('"')&&e.endsWith('"')){return e.slice(1,-1)}if(e.startsWith("'")&&e.endsWith("'")){return e.slice(1,-1)}return e})).filter((e=>e))}const O={"<":function e(t){const n=Number(t[0]);return e=>e<n},"<=":function e(t){const n=Number(t[0]);return e=>e<=n},"=":function e(t){const n=t[0].split(",").filter((e=>e)).map(Number);return e=>{for(let t=0;t<n.length;t++){if(e===n[t]){return true}}return false}},">=":function e(t){const n=Number(t[0]);return e=>e>=n},">":function e(t){const n=Number(t[0]);return e=>e>n},"..":function e(t){const n=Number(t[0]);const r=Number(t[1]);return e=>e>=n&&e<=r}};function P(e){const{values:t,operator:n}=R(e);const r=O[n];if(!r){throw new Error(`unknown operator ${n}`)}return r(t)}function R(e){const t=/^\s*\(?\s*(?<startOperator><=|>=|<|=|>|\.\.\s*)?\s*(?<firstValue>-?\d*\.?\d+)\s*(?:(?<afterDots>\.\.)\s*(?<secondValue>-?\d*\.?\d*))?\s*\)?\s*$/.exec(e);if(!t){return{operator:"=",values:[e]}}if(!t.groups){throw new Error("unreachable")}const{startOperator:n,firstValue:r,afterDots:o,secondValue:i}=t.groups;let s=n;let f=r?[r]:[];if(n===".."){s="<="}else if(!n&&o&&!i){s=">="}else if(o){s=".."}if(i){f.push(i)}return{values:f,operator:s||"="}}const D={"<":function e(t){return e=>e<t[0]},"<=":function e(t){return e=>e<=t[0]},"=":function e(t,n){const r=N(t[0],",").filter((e=>e)).map((e=>new RegExp(`^${E(e)}$`,n)));return e=>{for(const t of r){if(t.test(e)){return true}}return false}},"~":function e(t,n){const r=N(t[0],",").filter((e=>e)).map((e=>new RegExp(E(e),n)));return e=>{for(const t of r){if(t.test(e)){return true}}return false}},">=":function e(t){return e=>e>=t[0]},">":function e(t){return e=>e>t[0]},"..":function e(t){return e=>e>=t[0]&&e<=t[1]}};function _(e,t){const{values:n,operator:r}=I(e);const o=D[r];if(!o){throw new Error(`unreachable unknown operator ${r}`)}return o(n,t)}function I(e){const t=e.split("..");const n=/^\s*\(?(?<operator><=|<|=|>=|>)?\s*(?<value>\S*)\s*\)?$/.exec(t[0]);if(!n){return{operator:"~",values:[e]}}if(!n.groups){throw new Error("unreachable")}let{operator:r,value:o}=n.groups;let i=t[1]?.trim();let s=[o];if(t.length>1){r="..";if(!i){r=">="}else if(!o){s=[i];r="<="}else{s.push(i)}}return{operator:r||"~",values:s}}function S(e,t={pathAlias:{}}){const{caseSensitive:n,pathAlias:r}=t;const o=n?"":"i";let i=false;if(e.startsWith("-")){i=true;e=e.substring(1)}const s=e.indexOf(":");if(s>-1){const t=e.substring(s+1);if(s>0){const n=e.substring(0,s);if(n==="is"){return{type:"exists",negate:i,key:new RegExp(`(^|\\.)${E(t)}(\\.|$)`,o)}}else{return{type:"matches",negate:i,key:r[n]?r[n]:new RegExp(`(^|\\.)${E(n)}(\\.|$)`,o),checkNumber:P(t),checkString:_(t,o)}}}}return{type:"matches",negate:i,checkNumber:P(e),checkString:_(e,o)}}function M(e,t={pathAlias:{}}){return e.map((e=>S(e,t)))}function V(e,t){const{insensitive:n}=t;const r={};for(const[t,o]of Object.entries(e)){if(o instanceof RegExp){r[t]=o}else{r[t]=new RegExp(`(^|\\.)${E(o)}(\\.|$)`,n)}}return r}function T(e,t={}){let{index:n=false,predicate:r="AND",ignorePaths:o=[],includePaths:i,pathAlias:s={}}=t;const f=t.limit?t.limit:Infinity;const u=t.caseSensitive?"":"i";let c=t.keywords||[];const a=V(s,{insensitive:u});const l=o.map((e=>typeof e==="string"?new RegExp(`(^|\\.)${E(e)}(\\.|$)`,u):e));const p=i?i.map((e=>typeof e==="string"?new RegExp(`(^|\\.)${E(e)}(\\.|$)`,u):e)):undefined;if(typeof c==="string"){c=N(c,/[ \t\r\n]/)}const d=M(c,{caseSensitive:t.caseSensitive,pathAlias:a});let h=0;if(n){const t=[];for(let n=0;n<e.length&&h<f;n++){if(j(e[n],d,r,{ignorePaths:l,includePaths:p,pathAlias:a})){h=t.push(n)}}return t}else{const t=[];for(let n=0;n<e.length&&h<f;n++){if(j(e[n],d,r,{ignorePaths:l,includePaths:p,pathAlias:a})){h=t.push(e[n])}}return t}}const B=new Map;function F(){return Date.now().toString(36)+Math.random().toString(36).substring(2)}async function C(e,t){const n=F();B.set(n,{rows:e,columns:X(t)});return n}async function L(e,t){const n=B.get(e);if(!n)throw"cannot find worker with ID "+e;n.rows=t;if(!n.rows&&!n.columns)Y(e);return true}async function q(e,t){const n=B.get(e);if(!n)throw"cannot find worker with ID "+e;n.columns=X(t);if(!n.rows&&!n.columns)Y(e);return true}async function z(e,t){const n=B.get(e);if(!n)throw"cannot find worker with ID "+e;n.searchTerm=t;if(!t||!t.length){n.filterRows=n.rows;return W(n,n.rows)}const r=n.columns.filter((e=>e.searchable!==false));n.filterRows=T(n.rows,{keywords:t,predicate:"OR",includePaths:[...r.map((e=>e.prop))],ignorePaths:["__uuid","__index"]});return W(n,n.filterRows)}function G(e){return e.columns.filter((e=>e.filter!==undefined&&e.filter!==null)).reduce(((e,t)=>{const{prop:n,filter:r}=t;e.push({prop:n,filter:r});return e}),[])}function H(e,t,n=[]){if(!n||!n.length)n=G(e);if(!n||!n.length)return t;n.forEach((e=>{if(typeof e.filter==="boolean"){t=t.filter((t=>t[e.prop]===e.filter))}else{t=T(t,{keywords:e.filter,includePaths:[e.prop],ignorePaths:["__uuid","__index"]})}}));return t}async function J(e,t){const n=B.get(e);if(!n)throw"cannot find worker with ID "+e;const r=(!t||!t.length)&&n.searchTerm?await z(e,n.searchTerm):n.searchTerm?n.filterRows:n.rows;n.filterRows=H(n,r,t);return Q(n,n.filterRows)}function K(e){const t=e.columns.find((e=>!!e.order));if(t){const{prop:e,order:n}=t;return{prop:e,order:n}}return null}function Q(e,t,n,r){if(!n&&!r){const t=K(e);if(t){({prop:n,order:r}=t)}}if(!n||!r||!t.length)return t;const o=e.columns.find((e=>e.prop===n));if(!!o.sortCompareFn&&typeof o.sortCompareFn==="function"){const e=t.slice().sort(o.sortCompareFn(n,r));return e}if(o.type==="text"&&typeof t[0][n]==="string"){const e=t.slice().sort(((e,t)=>{if(!e[n])return 1;if(!t[n])return-1;return r==="asc"?e[n].localeCompare(t[n]):t[n].localeCompare(e[n])}));return e}const i=t.slice().sort(((e,t)=>{if(!e[n])return 1;if(!t[n])return-1;if(e[n]<t[n])return r==="asc"?-1:1;if(e[n]>t[n])return r==="asc"?1:-1;return 0}));return i}async function U(e,t,n){const r=B.get(e);if(!r)throw"cannot find worker with ID "+e;const o=r.filterRows||r.rows;return Q(r,o,t,n)}function W(e,t){t=H(e,t);return Q(e,t)}function X(e){return e.map((e=>{if(!!e.sortCompareFn){e.sortCompareFn=new Function("return "+e.sortCompareFn)()}return e}))}async function Y(e){B.delete(e)}n.createWorkerStore=C;n.destroyWorkerStore=Y;n.syncConfigToWorker=q;n.syncDataToWorker=L;n.workerFilter=J;n.workerSearch=z;n.workerSort=U})();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"table-interface.js","sourceRoot":"","sources":["../../../src/components/table/table-interface.ts"],"names":[],"mappings":"","sourcesContent":["import type { JSXBase } from '@stencil/core/internal';\nimport type { VNode, FunctionalComponent } from '@stencil/core';\n\nexport declare namespace TableTypes {\n /** The column property */\n type ColumnProp = string | number;\n\n /** Possible positions. Horizontally means l/r. Vertically means top/bottom */\n type Position = 'start' | 'end' | 'top' | 'bottom';\n\n /** A function to assess whether a rendered row will be pinned to the top or bottom */\n type PinFunc = (props?: RowDataSchemaModel) => Position;\n\n /** Function called, via intersection observer, when an element's pinned status changes */\n type PinnedCb = (positions: { [key in Position]?: boolean }) => void;\n\n /** Potential column ordering options */\n type Order = 'asc' | 'desc' | undefined;\n\n /** Column filtering */\n interface Filter {\n prop: TableTypes.Prop;\n filter: string;\n }\n\n /** Column sorting */\n interface Sort {\n prop: TableTypes.Prop;\n order: TableTypes.Order;\n }\n\n /** Potential html properties which can be passed to a cell or column */\n type CellProps = JSXBase.ThHTMLAttributes<HTMLTableCellElement>;\n\n /** Potential html properties which can be passed to a row */\n type RowProps = JSXBase.HTMLAttributes<HTMLTableRowElement>;\n\n /** data model passed to cell rendering functions */\n interface RenderModel<T = RowGeneric> {\n /** The column property being iterated over */\n prop: keyof T;\n /** The data for this cell */\n cellModel: any;\n /** The column config object */\n column: ColumnConfig<T>;\n /** The row index currently being iterated over */\n rowIndex: number;\n /** The row model currently being iterated over */\n rowModel: RowData<T>;\n }\n\n /** data model passed to row rendering functions */\n interface RowDataSchemaModel<T = RowGeneric> {\n /** the current data row model being iterated over */\n rowModel?: RowData<T>;\n /** the current data row index */\n rowIndex?: number;\n /** The row being rendered. You *must* nest this in your render function otherwise it will not be shown */\n renderedRow?: VNode;\n }\n\n /** A JSX `createElement` function passed to rendering functions.\n * You can use this to create markup outside of JSX environments\n * e.g. https://reactjs.org/docs/react-without-jsx.html */\n interface HFunc<T> {\n (tag: any): T;\n }\n interface HFunc<T> {\n (tag: any, data: any): T;\n }\n interface HFunc<T> {\n (tag: any, text: string): T;\n }\n interface HFunc<T> {\n (sel: any, children: Array<T | undefined | null>): T;\n }\n interface HFunc<T> {\n (sel: any, data: any, text: string): T;\n }\n interface HFunc<T> {\n (sel: any, data: any, children: Array<T | undefined | null>): T;\n }\n interface HFunc<T> {\n (sel: any, data: any, children: T): T;\n }\n\n /**\n * A row render function, called during a any row's render to the dom.\n * It can be used to add extra markup around any given table row\n **/\n type RowTemplateFunc<T, P> = (\n /** use this to create markup outside of JSX environments\n * e.g. https://reactjs.org/docs/react-without-jsx.html */\n createElement: HFunc<T>,\n /** data passed to each template */\n props: RowDataSchemaModel<P>,\n /** a helper template to minimise boilerplate.\n * A shortcut for `<td><div class=\"nano-tbl__cell-content\"></div></td>` */\n TableCell: FunctionalComponent<{ header?: boolean }>\n ) => T | undefined;\n\n /**\n * A cell render function, called during any cell's render to the dom.\n * It can be used to add any markup within a table cell.\n */\n type CellTemplateFunc<T, P> = (\n createElement: HFunc<T>,\n props: RenderModel<P>\n ) => T | string | undefined;\n\n /**\n * A table header render function, called during any column's render to the dom.\n * It can be used to add any markup within a table header `th`.\n */\n type ColumnTemplateFunc<T, P> = (\n createElement: HFunc<T>,\n col: ColumnConfig<P>\n ) => T | string | undefined;\n\n /** A function used to assess the order of any given column.\n * e.g. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\n */\n type ColSortComparator = (\n prop: keyof RowData,\n order: Order\n ) => (a: RowData, b: RowData) => number;\n\n /** A function which can be used to apply any html attribute/s onto a table cell `td` */\n type PropertiesFunc = (props: RenderModel) => CellProps | void | undefined;\n\n /** A function which can be used to apply any html attribute/s onto a table head `th` */\n type ColPropertiesFunc<T> = (\n props: ColumnConfig<T>\n ) => CellProps | void | undefined;\n\n /** A function which can be used to apply any html attribute/s onto a table row `tr` */\n type RowPropertiesFunc<T> = (\n props: RowDataSchemaModel<T>\n ) => RowProps | void | undefined;\n\n type RowGeneric = { [key: string | number]: any };\n\n /** An individual table cell's data */\n type RowData<T = RowGeneric> = T & {\n __uuid?: string | number;\n __index?: number;\n };\n\n /** A data property */\n type Prop = keyof RowData;\n\n /** Valid column data types */\n type ColumnType =\n | 'text'\n | 'string'\n | 'number'\n | 'date'\n | 'boolean'\n | 'unknown';\n\n /**\n * A table column's configuration\n */\n interface ColumnConfig<T = RowData> {\n /** The title of the column. Displayed in the table header `th` */\n title: string;\n /** The row's data property to retrieve per cell render */\n prop: keyof T;\n /** The type of data. Will affect how it is sorted and the available\n * filter operations ('text' uses browser locale to compare).\n * If none supplied, it will be derived by default using the first row of data retrieved. */\n type?: ColumnType;\n /** Whether this column is horizontally pinned to viewport */\n pinned?: Position;\n /** By default cell content too wide for the cell will not wrap,\n * but rather be trimmed with '...'.\n * *Note* 'wrap' is mutually-exclusive from `autoTooltip` */\n wrap?: boolean;\n /** Setting this to true, will automatically watch content that\n * doesn't fit and duplicate it to show in a tooltip.\n * *Note* 'autoTooltip' is mutually-exclusive from `wrap` */\n autoTooltip?: boolean;\n /** Whether this column is a row header; the cell will render a `th` not a `td` */\n rowHeader?: boolean;\n /** Whether this column can be sorted. Defaults to true */\n sortable?: boolean;\n /** Current order of this column */\n order?: Order;\n /** Whether to include this column when doing a general search. Defaults to true */\n searchable?: boolean;\n /** Current filters applied to this column */\n filter?: string;\n /** Whether this column can be dragged to change column order */\n draggable?: boolean;\n /**\n * A cell render function, called during any cell's render to the dom.\n * It can be used to add any markup within a table cell.\n */\n cellTemplate?: CellTemplateFunc<VNode | VNode[], T>;\n /** A function which can be used to apply any html attribute/s onto a table cell `td` */\n cellProperties?: PropertiesFunc;\n /**\n * A table header render function, called during any column's render to the dom.\n * It can be used to add any markup within a table header `th`.\n */\n columnTemplate?: ColumnTemplateFunc<VNode | VNode[], T>;\n /** A function which can be used to apply any html attribute/s onto a table head `th` */\n columnProperties?: ColPropertiesFunc<T>;\n /** A custom sorting comparator function - assess the order of any given column.\n * e.g. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort */\n sortCompareFn?: ColSortComparator | string;\n }\n\n /**\n * Row renderer property. Called during the rendering of any table row\n * controlling it's visual state.\n */\n interface RowRenderer<T = RowData> {\n /** Function to decide whether the row is vertically pinned. */\n pinned?: PinFunc;\n /**\n * A row render function, called during a any row's render to the dom.\n * It can be used to add extra markup around any given table row\n **/\n template?: RowTemplateFunc<VNode | VNode[], T>;\n /** A function which can be used to apply any html attribute/s onto a table row `tr` */\n rowProperties?: RowPropertiesFunc<T>;\n }\n\n /**\n * Row renderer property. Called during the rendering of a tables head and foot\n * controlling their visual state.\n */\n interface HeadFootRenderer<T = RowData> {\n /** Function to decide whether the row is vertically pinned. Defaults to `start` for the header and `end` the footer */\n pinned: Position;\n /**\n * A row render function, called during a any row's render to the dom.\n * It can be used to add extra markup around any given table row.\n * If used, and you want to see the rendered row, you *must* nest it within your\n * jsx function e.g. `(h, props) => { return [props.renderedRow, <tr><td>Custom thing</td></tr>]}`\n **/\n template?: RowTemplateFunc<VNode | VNode[], T>;\n /** A function which can be used to apply any html attribute/s onto a table row `tr` */\n rowProperties?: () => RowProps | void | undefined;\n }\n\n type TBody = {\n rows: TableTypes.NanoTable['rows'];\n __uuid: string | number;\n };\n\n class NanoTable<T = RowGeneric> {\n rows: T[];\n columns: ColumnConfig<T>[];\n rowRender: RowRenderer<T>;\n headRender: HeadFootRenderer<T>;\n footRender: HeadFootRenderer<T>;\n }\n\n type Falsy = false | 0 | '' | null | undefined;\n}\n"]}
|
1
|
+
{"version":3,"file":"table-interface.js","sourceRoot":"","sources":["../../../src/components/table/table-interface.ts"],"names":[],"mappings":"","sourcesContent":["import type { JSXBase } from '@stencil/core/internal';\nimport type { VNode, FunctionalComponent } from '@stencil/core';\n\nexport declare namespace TableTypes {\n /** The column property */\n type ColumnProp = string | number;\n\n /** Possible positions. Horizontally means l/r. Vertically means top/bottom */\n type Position = 'start' | 'end' | 'top' | 'bottom';\n\n /** A function to assess whether a rendered row will be pinned to the top or bottom */\n type PinFunc = (props?: RowDataSchemaModel) => Position;\n\n /** Function called, via intersection observer, when an element's pinned status changes */\n type PinnedCb = (positions: { [key in Position]?: boolean }) => void;\n\n /** Potential column ordering options */\n type Order = 'asc' | 'desc' | undefined;\n\n /** Column filtering */\n interface Filter {\n prop: TableTypes.Prop;\n filter: string | boolean;\n }\n\n /** Column sorting */\n interface Sort {\n prop: TableTypes.Prop;\n order: TableTypes.Order;\n }\n\n /** Potential html properties which can be passed to a cell or column */\n type CellProps = JSXBase.ThHTMLAttributes<HTMLTableCellElement>;\n\n /** Potential html properties which can be passed to a row */\n type RowProps = JSXBase.HTMLAttributes<HTMLTableRowElement>;\n\n /** data model passed to cell rendering functions */\n interface RenderModel<T = RowGeneric> {\n /** The column property being iterated over */\n prop: keyof T;\n /** The data for this cell */\n cellModel: any;\n /** The column config object */\n column: ColumnConfig<T>;\n /** The row index currently being iterated over */\n rowIndex: number;\n /** The row model currently being iterated over */\n rowModel: RowData<T>;\n }\n\n /** data model passed to row rendering functions */\n interface RowDataSchemaModel<T = RowGeneric> {\n /** the current data row model being iterated over */\n rowModel?: RowData<T>;\n /** the current data row index */\n rowIndex?: number;\n /** The row being rendered. You *must* nest this in your render function otherwise it will not be shown */\n renderedRow?: VNode;\n }\n\n /** A JSX `createElement` function passed to rendering functions.\n * You can use this to create markup outside of JSX environments\n * e.g. https://reactjs.org/docs/react-without-jsx.html */\n interface HFunc<T> {\n (tag: any): T;\n }\n interface HFunc<T> {\n (tag: any, data: any): T;\n }\n interface HFunc<T> {\n (tag: any, text: string): T;\n }\n interface HFunc<T> {\n (sel: any, children: Array<T | undefined | null>): T;\n }\n interface HFunc<T> {\n (sel: any, data: any, text: string): T;\n }\n interface HFunc<T> {\n (sel: any, data: any, children: Array<T | undefined | null>): T;\n }\n interface HFunc<T> {\n (sel: any, data: any, children: T): T;\n }\n\n /**\n * A row render function, called during a any row's render to the dom.\n * It can be used to add extra markup around any given table row\n **/\n type RowTemplateFunc<T, P> = (\n /** use this to create markup outside of JSX environments\n * e.g. https://reactjs.org/docs/react-without-jsx.html */\n createElement: HFunc<T>,\n /** data passed to each template */\n props: RowDataSchemaModel<P>,\n /** a helper template to minimise boilerplate.\n * A shortcut for `<td><div class=\"nano-tbl__cell-content\"></div></td>` */\n TableCell: FunctionalComponent<{ header?: boolean }>\n ) => T | undefined;\n\n /**\n * A cell render function, called during any cell's render to the dom.\n * It can be used to add any markup within a table cell.\n */\n type CellTemplateFunc<T, P> = (\n createElement: HFunc<T>,\n props: RenderModel<P>\n ) => T | string | undefined;\n\n /**\n * A table header render function, called during any column's render to the dom.\n * It can be used to add any markup within a table header `th`.\n */\n type ColumnTemplateFunc<T, P> = (\n createElement: HFunc<T>,\n col: ColumnConfig<P>\n ) => T | string | undefined;\n\n /** A function used to assess the order of any given column.\n * e.g. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort\n */\n type ColSortComparator = (\n prop: keyof RowData,\n order: Order\n ) => (a: RowData, b: RowData) => number;\n\n /** A function which can be used to apply any html attribute/s onto a table cell `td` */\n type PropertiesFunc = (props: RenderModel) => CellProps | void | undefined;\n\n /** A function which can be used to apply any html attribute/s onto a table head `th` */\n type ColPropertiesFunc<T> = (\n props: ColumnConfig<T>\n ) => CellProps | void | undefined;\n\n /** A function which can be used to apply any html attribute/s onto a table row `tr` */\n type RowPropertiesFunc<T> = (\n props: RowDataSchemaModel<T>\n ) => RowProps | void | undefined;\n\n type RowGeneric = { [key: string | number]: any };\n\n /** An individual table cell's data */\n type RowData<T = RowGeneric> = T & {\n __uuid?: string | number;\n __index?: number;\n };\n\n /** A data property */\n type Prop = keyof RowData;\n\n /** Valid column data types */\n type ColumnType =\n | 'text'\n | 'string'\n | 'number'\n | 'date'\n | 'boolean'\n | 'unknown';\n\n /**\n * A table column's configuration\n */\n interface ColumnConfig<T = RowData> {\n /** The title of the column. Displayed in the table header `th` */\n title: string;\n /** The row's data property to retrieve per cell render */\n prop: keyof T;\n /** The type of data. Will affect how it is sorted and the available\n * filter operations ('text' uses browser locale to compare).\n * If none supplied, it will be derived by default using the first row of data retrieved. */\n type?: ColumnType;\n /** Whether this column is horizontally pinned to viewport */\n pinned?: Position;\n /** By default cell content too wide for the cell will not wrap,\n * but rather be trimmed with '...'.\n * *Note* 'wrap' is mutually-exclusive from `autoTooltip` */\n wrap?: boolean;\n /** Setting this to true, will automatically watch content that\n * doesn't fit and duplicate it to show in a tooltip.\n * *Note* 'autoTooltip' is mutually-exclusive from `wrap` */\n autoTooltip?: boolean;\n /** Whether this column is a row header; the cell will render a `th` not a `td` */\n rowHeader?: boolean;\n /** Whether this column can be sorted. Defaults to true */\n sortable?: boolean;\n /** Current order of this column */\n order?: Order;\n /** Whether to include this column when doing a general search. Defaults to true */\n searchable?: boolean;\n /** Current filters applied to this column */\n filter?: string | boolean;\n /** Whether this column can be dragged to change column order */\n draggable?: boolean;\n /**\n * A cell render function, called during any cell's render to the dom.\n * It can be used to add any markup within a table cell.\n */\n cellTemplate?: CellTemplateFunc<VNode | VNode[], T>;\n /** A function which can be used to apply any html attribute/s onto a table cell `td` */\n cellProperties?: PropertiesFunc;\n /**\n * A table header render function, called during any column's render to the dom.\n * It can be used to add any markup within a table header `th`.\n */\n columnTemplate?: ColumnTemplateFunc<VNode | VNode[], T>;\n /** A function which can be used to apply any html attribute/s onto a table head `th` */\n columnProperties?: ColPropertiesFunc<T>;\n /** A custom sorting comparator function - assess the order of any given column.\n * e.g. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort */\n sortCompareFn?: ColSortComparator | string;\n }\n\n /**\n * Row renderer property. Called during the rendering of any table row\n * controlling it's visual state.\n */\n interface RowRenderer<T = RowData> {\n /** Function to decide whether the row is vertically pinned. */\n pinned?: PinFunc;\n /**\n * A row render function, called during a any row's render to the dom.\n * It can be used to add extra markup around any given table row\n **/\n template?: RowTemplateFunc<VNode | VNode[], T>;\n /** A function which can be used to apply any html attribute/s onto a table row `tr` */\n rowProperties?: RowPropertiesFunc<T>;\n }\n\n /**\n * Row renderer property. Called during the rendering of a tables head and foot\n * controlling their visual state.\n */\n interface HeadFootRenderer<T = RowData> {\n /** Function to decide whether the row is vertically pinned. Defaults to `start` for the header and `end` the footer */\n pinned: Position;\n /**\n * A row render function, called during a any row's render to the dom.\n * It can be used to add extra markup around any given table row.\n * If used, and you want to see the rendered row, you *must* nest it within your\n * jsx function e.g. `(h, props) => { return [props.renderedRow, <tr><td>Custom thing</td></tr>]}`\n **/\n template?: RowTemplateFunc<VNode | VNode[], T>;\n /** A function which can be used to apply any html attribute/s onto a table row `tr` */\n rowProperties?: () => RowProps | void | undefined;\n }\n\n type TBody = {\n rows: TableTypes.NanoTable['rows'];\n __uuid: string | number;\n };\n\n class NanoTable<T = RowGeneric> {\n rows: T[];\n columns: ColumnConfig<T>[];\n rowRender: RowRenderer<T>;\n headRender: HeadFootRenderer<T>;\n footRender: HeadFootRenderer<T>;\n }\n\n type Falsy = false | 0 | '' | null | undefined;\n}\n"]}
|
@@ -58,8 +58,24 @@ export async function workerSearch(workerId, term) {
|
|
58
58
|
return applyFiltersAndSort(workerStore, workerStore.filterRows);
|
59
59
|
}
|
60
60
|
/** FILTER */
|
61
|
-
|
62
|
-
|
61
|
+
/**
|
62
|
+
* Finds any currently applied filter conditions from the column config
|
63
|
+
* @param workerStore
|
64
|
+
* @returns the found column filter object array
|
65
|
+
*/
|
66
|
+
function getCurrentFilters(workerStore) {
|
67
|
+
return workerStore.columns
|
68
|
+
.filter((c) => c.filter !== undefined && c.filter !== null)
|
69
|
+
.reduce((filters, col) => {
|
70
|
+
const { prop, filter } = col;
|
71
|
+
filters.push({ prop, filter });
|
72
|
+
return filters;
|
73
|
+
}, []);
|
74
|
+
}
|
75
|
+
function filter(workerStore, rows, filters = []) {
|
76
|
+
if (!filters || !filters.length)
|
77
|
+
filters = getCurrentFilters(workerStore);
|
78
|
+
if (!filters || !filters.length)
|
63
79
|
return rows;
|
64
80
|
filters.forEach((filter) => {
|
65
81
|
if (typeof filter.filter === 'boolean') {
|
@@ -85,7 +101,7 @@ export async function workerFilter(workerId, filters) {
|
|
85
101
|
: workerStore.searchTerm
|
86
102
|
? workerStore.filterRows
|
87
103
|
: workerStore.rows;
|
88
|
-
workerStore.filterRows = filter(data, filters);
|
104
|
+
workerStore.filterRows = filter(workerStore, data, filters);
|
89
105
|
// apply sort
|
90
106
|
return sort(workerStore, workerStore.filterRows);
|
91
107
|
}
|
@@ -158,7 +174,7 @@ export async function workerSort(workerId, prop, order) {
|
|
158
174
|
// used after a search, it only sorts rn
|
159
175
|
// (search acting like a filter 'reset' atm)
|
160
176
|
function applyFiltersAndSort(workerStore, rows) {
|
161
|
-
rows = filter(rows);
|
177
|
+
rows = filter(workerStore, rows);
|
162
178
|
return sort(workerStore, rows);
|
163
179
|
}
|
164
180
|
function colsFromStore(safeColumns) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"table.worker.js","sourceRoot":"","sources":["../../../src/components/table/table.worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAc3D,MAAM,WAAW,GAA6B,IAAI,GAAG,EAAE,CAAC;AAExD,SAAS,GAAG;EACV,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,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AI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED,YAAY;AAEZ,wCAAwC;AACxC,4CAA4C;AAC5C,SAAS,mBAAmB,CAC1B,WAAwB,EACxB,IAAkC;EAElC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;EACpB,OAAO,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,aAAa,CAAC,WAA+C;EACpE,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;IAC3B,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE;MACrB,CAAC,CAAC,aAAa,GAAG,IAAI,QAAQ,CAAC,SAAS,GAAG,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC;KAC/D;IACD,OAAO,CAAC,CAAC;EACX,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,QAAgB;EACvD,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { filter as smartFilter } from 'smart-array-filter';\nimport type { TableTypes } from '../../interface';\n\n// we'll do ordering and filtering in here\n\n/** SETUP */\n\ninterface WorkerStore {\n rows: TableTypes.NanoTable['rows'];\n columns: Partial<TableTypes.ColumnConfig>[];\n filterRows?: TableTypes.NanoTable['rows'];\n searchTerm?: string;\n}\n\nconst dataWorkers: Map<string, WorkerStore> = new Map();\n\nfunction uid() {\n return Date.now().toString(36) + Math.random().toString(36).substring(2);\n}\n\nexport async function createWorkerStore(\n rows: TableTypes.NanoTable['rows'],\n columns: Partial<TableTypes.ColumnConfig>[]\n) {\n const id = uid();\n dataWorkers.set(id, { rows, columns: colsFromStore(columns) });\n return id;\n}\n\nexport async function syncDataToWorker(\n workerId: string,\n rows: TableTypes.NanoTable['rows']\n) {\n const workerStore = dataWorkers.get(workerId);\n if (!workerStore) throw 'cannot find worker with ID ' + workerId;\n\n workerStore.rows = rows;\n if (!workerStore.rows && !workerStore.columns) destroyWorkerStore(workerId);\n return true;\n}\n\nexport async function syncConfigToWorker(\n workerId: string,\n columns: Partial<TableTypes.ColumnConfig>[]\n) {\n const workerStore = dataWorkers.get(workerId);\n if (!workerStore) throw 'cannot find worker with ID ' + workerId;\n\n workerStore.columns = colsFromStore(columns);\n if (!workerStore.rows && !workerStore.columns) destroyWorkerStore(workerId);\n return true;\n}\n\n/** SEARCH */\n\n/**\n * A general text search across all table columns.\n * Search is the first thing we do. Cache the result for filtering / sorting\n * @param workerId\n * @param term\n * @returns the searched for data rows - with col filters / sorts also applied\n */\nexport async function workerSearch(workerId: string, term: string) {\n const workerStore = dataWorkers.get(workerId);\n if (!workerStore) throw 'cannot find worker with ID ' + workerId;\n\n workerStore.searchTerm = term;\n if (!term || !term.length) {\n workerStore.filterRows = workerStore.rows;\n return applyFiltersAndSort(workerStore, workerStore.rows);\n }\n\n const availCols = workerStore.columns.filter((c) => c.searchable !== false);\n // cache result\n workerStore.filterRows = smartFilter(workerStore.rows, {\n keywords: term,\n predicate: 'OR',\n includePaths: [...(availCols.map((c) => c.prop) as string[])],\n ignorePaths: ['__uuid', '__index'],\n });\n\n // apply filter and sort\n return applyFiltersAndSort(workerStore, workerStore.filterRows);\n}\n\n/** FILTER */\n\nfunction filter(\n rows: TableTypes.NanoTable['rows'],\n filters: TableTypes.Filter[] = []\n) {\n if (!filters) return rows;\n\n filters.forEach((filter) => {\n if (typeof filter.filter === 'boolean') {\n rows = rows.filter((row) => row[filter.prop] === filter.filter);\n } else {\n rows = smartFilter(rows, {\n keywords: filter.filter,\n includePaths: [filter.prop as string],\n ignorePaths: ['__uuid', '__index'],\n });\n }\n });\n return rows;\n}\n\nexport async function workerFilter(\n workerId: string,\n filters: TableTypes.Filter[]\n) {\n const workerStore = dataWorkers.get(workerId);\n if (!workerStore) throw 'cannot find worker with ID ' + workerId;\n\n // get cached results from a search\n const data =\n (!filters || !filters.length) && workerStore.searchTerm\n ? await workerSearch(workerId, workerStore.searchTerm)\n : workerStore.searchTerm\n ? workerStore.filterRows\n : workerStore.rows;\n workerStore.filterRows = filter(data, filters);\n\n // apply sort\n return sort(workerStore, workerStore.filterRows);\n}\n\n/** SORT */\n\n/**\n * Finds any currently applied sort conditions from the column config\n * @param workerStore\n * @returns the found column name and it's sort direction\n */\nfunction getCurrentSort(workerStore: WorkerStore) {\n const foundSort = workerStore.columns.find((c) => !!c.order);\n\n if (foundSort) {\n const { prop, order } = foundSort;\n return { prop, order };\n }\n return null;\n}\n\nfunction sort(\n workerStore: WorkerStore,\n rows: TableTypes.NanoTable['rows'],\n prop?: TableTypes.Prop,\n order?: TableTypes.Order\n) {\n if (!prop && !order) {\n const currentSort = getCurrentSort(workerStore);\n if (currentSort) {\n ({ prop, order } = currentSort);\n }\n }\n if (!prop || !order || !rows.length) return rows;\n\n const col = workerStore.columns.find((c) => c.prop === prop);\n\n // custom sort\n if (!!col.sortCompareFn && typeof col.sortCompareFn === 'function') {\n const sorted = rows.slice().sort(col.sortCompareFn(prop, order));\n return sorted;\n }\n\n // text sort\n if (col.type === 'text' && typeof rows[0][prop] === 'string') {\n const sorted = rows.slice().sort((a, b) => {\n if (!a[prop]) return 1;\n if (!b[prop]) return -1;\n return order === 'asc'\n ? a[prop].localeCompare(b[prop])\n : b[prop].localeCompare(a[prop]);\n });\n return sorted;\n }\n\n // catch-all - number / date / string sort\n const sorted = rows.slice().sort((a, b) => {\n if (!a[prop]) return 1;\n if (!b[prop]) return -1;\n if (a[prop]! < b[prop]!) return order === 'asc' ? -1 : 1;\n if (a[prop]! > b[prop]!) return order === 'asc' ? 1 : -1;\n return 0;\n });\n return sorted;\n}\n\n/** Sorting is the last thing we do - don't cache this, there's no point */\nexport async function workerSort(\n workerId: string,\n prop: TableTypes.Prop,\n order: TableTypes.Order\n) {\n const workerStore = dataWorkers.get(workerId);\n if (!workerStore) throw 'cannot find worker with ID ' + workerId;\n\n // get cached results from a search / filter\n const data = workerStore.filterRows || workerStore.rows;\n return sort(workerStore, data, prop, order);\n}\n\n/** UTILS */\n\n// used after a search, it only sorts rn\n// (search acting like a filter 'reset' atm)\nfunction applyFiltersAndSort(\n workerStore: WorkerStore,\n rows: TableTypes.NanoTable['rows']\n) {\n rows = filter(rows);\n return sort(workerStore, rows);\n}\n\nfunction colsFromStore(safeColumns: Partial<TableTypes.ColumnConfig>[]) {\n return safeColumns.map((c) => {\n if (!!c.sortCompareFn) {\n c.sortCompareFn = new Function('return ' + c.sortCompareFn)();\n }\n return c;\n });\n}\n\n/**\n * Clean up\n * @param workerId\n */\nexport async function destroyWorkerStore(workerId: string) {\n dataWorkers.delete(workerId);\n}\n"]}
|
1
|
+
{"version":3,"file":"table.worker.js","sourceRoot":"","sources":["../../../src/components/table/table.worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAc3D,MAAM,WAAW,GAA6B,IAAI,GAAG,EAAE,CAAC;AAExD,SAAS,GAAG;EACV,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAkC,EAClC,OAA2C;EAE3C,MAAM,EAAE,GAAG,GAAG,EAAE,CAAC;EACjB,WAAW,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;EAC/D,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,QAAgB,EAChB,IAAkC;EAElC,MAAM,WAAW,GAAG,WAAW,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;EAC9C,IAAI,CAA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QAAQ,CAAC;EAEjE,4CAA4C;EAC5C,MAAM,IAAI,GAAG,WAAW,CAAC,UAAU,IAAI,WAAW,CAAC,IAAI,CAAC;EACxD,OAAO,IAAI,CAAC,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AAC9C,CAAC;AAED,YAAY;AAEZ,wCAAwC;AACxC,4CAA4C;AAC5C,SAAS,mBAAmB,CAC1B,WAAwB,EACxB,IAAkC;EAElC,IAAI,GAAG,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;EACjC,OAAO,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,aAAa,CAAC,WAA+C;EACpE,OAAO,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;IAC3B,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,EAAE;MACrB,CAAC,CAAC,aAAa,GAAG,IAAI,QAAQ,CAAC,SAAS,GAAG,CAAC,CAAC,aAAa,CAAC,EAAE,CAAC;KAC/D;IACD,OAAO,CAAC,CAAC;EACX,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,QAAgB;EACvD,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { filter as smartFilter } from 'smart-array-filter';\nimport type { TableTypes } from '../../interface';\n\n// we'll do ordering and filtering in here\n\n/** SETUP */\n\ninterface WorkerStore {\n rows: TableTypes.NanoTable['rows'];\n columns: Partial<TableTypes.ColumnConfig>[];\n filterRows?: TableTypes.NanoTable['rows'];\n searchTerm?: string;\n}\n\nconst dataWorkers: Map<string, WorkerStore> = new Map();\n\nfunction uid() {\n return Date.now().toString(36) + Math.random().toString(36).substring(2);\n}\n\nexport async function createWorkerStore(\n rows: TableTypes.NanoTable['rows'],\n columns: Partial<TableTypes.ColumnConfig>[]\n) {\n const id = uid();\n dataWorkers.set(id, { rows, columns: colsFromStore(columns) });\n return id;\n}\n\nexport async function syncDataToWorker(\n workerId: string,\n rows: TableTypes.NanoTable['rows']\n) {\n const workerStore = dataWorkers.get(workerId);\n if (!workerStore) throw 'cannot find worker with ID ' + workerId;\n\n workerStore.rows = rows;\n if (!workerStore.rows && !workerStore.columns) destroyWorkerStore(workerId);\n return true;\n}\n\nexport async function syncConfigToWorker(\n workerId: string,\n columns: Partial<TableTypes.ColumnConfig>[]\n) {\n const workerStore = dataWorkers.get(workerId);\n if (!workerStore) throw 'cannot find worker with ID ' + workerId;\n\n workerStore.columns = colsFromStore(columns);\n if (!workerStore.rows && !workerStore.columns) destroyWorkerStore(workerId);\n return true;\n}\n\n/** SEARCH */\n\n/**\n * A general text search across all table columns.\n * Search is the first thing we do. Cache the result for filtering / sorting\n * @param workerId\n * @param term\n * @returns the searched for data rows - with col filters / sorts also applied\n */\nexport async function workerSearch(workerId: string, term: string) {\n const workerStore = dataWorkers.get(workerId);\n if (!workerStore) throw 'cannot find worker with ID ' + workerId;\n\n workerStore.searchTerm = term;\n if (!term || !term.length) {\n workerStore.filterRows = workerStore.rows;\n return applyFiltersAndSort(workerStore, workerStore.rows);\n }\n\n const availCols = workerStore.columns.filter((c) => c.searchable !== false);\n // cache result\n workerStore.filterRows = smartFilter(workerStore.rows, {\n keywords: term,\n predicate: 'OR',\n includePaths: [...(availCols.map((c) => c.prop) as string[])],\n ignorePaths: ['__uuid', '__index'],\n });\n\n // apply filter and sort\n return applyFiltersAndSort(workerStore, workerStore.filterRows);\n}\n\n/** FILTER */\n\n/**\n * Finds any currently applied filter conditions from the column config\n * @param workerStore\n * @returns the found column filter object array\n */\nfunction getCurrentFilters(workerStore: WorkerStore) {\n return workerStore.columns\n .filter((c) => c.filter !== undefined && c.filter !== null)\n .reduce((filters, col) => {\n const { prop, filter } = col;\n filters.push({ prop, filter });\n return filters;\n }, [] as TableTypes.Filter[]);\n}\n\nfunction filter(\n workerStore: WorkerStore,\n rows: TableTypes.NanoTable['rows'],\n filters: TableTypes.Filter[] = []\n) {\n if (!filters || !filters.length) filters = getCurrentFilters(workerStore);\n if (!filters || !filters.length) return rows;\n\n filters.forEach((filter) => {\n if (typeof filter.filter === 'boolean') {\n rows = rows.filter((row) => row[filter.prop] === filter.filter);\n } else {\n rows = smartFilter(rows, {\n keywords: filter.filter,\n includePaths: [filter.prop as string],\n ignorePaths: ['__uuid', '__index'],\n });\n }\n });\n return rows;\n}\n\nexport async function workerFilter(\n workerId: string,\n filters: TableTypes.Filter[]\n) {\n const workerStore = dataWorkers.get(workerId);\n if (!workerStore) throw 'cannot find worker with ID ' + workerId;\n\n // get cached results from a search\n const data =\n (!filters || !filters.length) && workerStore.searchTerm\n ? await workerSearch(workerId, workerStore.searchTerm)\n : workerStore.searchTerm\n ? workerStore.filterRows\n : workerStore.rows;\n workerStore.filterRows = filter(workerStore, data, filters);\n\n // apply sort\n return sort(workerStore, workerStore.filterRows);\n}\n\n/** SORT */\n\n/**\n * Finds any currently applied sort conditions from the column config\n * @param workerStore\n * @returns the found column name and it's sort direction\n */\nfunction getCurrentSort(workerStore: WorkerStore) {\n const foundSort = workerStore.columns.find((c) => !!c.order);\n\n if (foundSort) {\n const { prop, order } = foundSort;\n return { prop, order };\n }\n return null;\n}\n\nfunction sort(\n workerStore: WorkerStore,\n rows: TableTypes.NanoTable['rows'],\n prop?: TableTypes.Prop,\n order?: TableTypes.Order\n) {\n if (!prop && !order) {\n const currentSort = getCurrentSort(workerStore);\n if (currentSort) {\n ({ prop, order } = currentSort);\n }\n }\n if (!prop || !order || !rows.length) return rows;\n\n const col = workerStore.columns.find((c) => c.prop === prop);\n\n // custom sort\n if (!!col.sortCompareFn && typeof col.sortCompareFn === 'function') {\n const sorted = rows.slice().sort(col.sortCompareFn(prop, order));\n return sorted;\n }\n\n // text sort\n if (col.type === 'text' && typeof rows[0][prop] === 'string') {\n const sorted = rows.slice().sort((a, b) => {\n if (!a[prop]) return 1;\n if (!b[prop]) return -1;\n return order === 'asc'\n ? a[prop].localeCompare(b[prop])\n : b[prop].localeCompare(a[prop]);\n });\n return sorted;\n }\n\n // catch-all - number / date / string sort\n const sorted = rows.slice().sort((a, b) => {\n if (!a[prop]) return 1;\n if (!b[prop]) return -1;\n if (a[prop]! < b[prop]!) return order === 'asc' ? -1 : 1;\n if (a[prop]! > b[prop]!) return order === 'asc' ? 1 : -1;\n return 0;\n });\n return sorted;\n}\n\n/** Sorting is the last thing we do - don't cache this, there's no point */\nexport async function workerSort(\n workerId: string,\n prop: TableTypes.Prop,\n order: TableTypes.Order\n) {\n const workerStore = dataWorkers.get(workerId);\n if (!workerStore) throw 'cannot find worker with ID ' + workerId;\n\n // get cached results from a search / filter\n const data = workerStore.filterRows || workerStore.rows;\n return sort(workerStore, data, prop, order);\n}\n\n/** UTILS */\n\n// used after a search, it only sorts rn\n// (search acting like a filter 'reset' atm)\nfunction applyFiltersAndSort(\n workerStore: WorkerStore,\n rows: TableTypes.NanoTable['rows']\n) {\n rows = filter(workerStore, rows);\n return sort(workerStore, rows);\n}\n\nfunction colsFromStore(safeColumns: Partial<TableTypes.ColumnConfig>[]) {\n return safeColumns.map((c) => {\n if (!!c.sortCompareFn) {\n c.sortCompareFn = new Function('return ' + c.sortCompareFn)();\n }\n return c;\n });\n}\n\n/**\n * Clean up\n * @param workerId\n */\nexport async function destroyWorkerStore(workerId: string) {\n dataWorkers.delete(workerId);\n}\n"]}
|
@@ -5,7 +5,7 @@ import { c as createWorker } from './table.js';
|
|
5
5
|
|
6
6
|
const workerName = 'table.worker';
|
7
7
|
const workerMsgId = 'stencil.table.worker';
|
8
|
-
const workerPath = /*@__PURE__*/new URL('./assets/table.worker-
|
8
|
+
const workerPath = /*@__PURE__*/new URL('./assets/table.worker-f820b411.js', import.meta.url).href;
|
9
9
|
const blob = new Blob(['importScripts("' + workerPath + '")'], { type: 'text/javascript' });
|
10
10
|
const url = URL.createObjectURL(blob);
|
11
11
|
const worker = /*@__PURE__*/createWorker(url, workerName, workerMsgId);
|
@@ -110,7 +110,7 @@ const createWorkerProxy = (worker, workerMsgId, exportedMethod) => (
|
|
110
110
|
})
|
111
111
|
);
|
112
112
|
|
113
|
-
const workerPromise = import('./table.worker-
|
113
|
+
const workerPromise = import('./table.worker-8c883d01.js').then(m => m.worker);
|
114
114
|
const createWorkerStore = /*@__PURE__*/createWorkerProxy(workerPromise, 'stencil.table.worker', 'createWorkerStore');
|
115
115
|
const syncConfigToWorker = /*@__PURE__*/createWorkerProxy(workerPromise, 'stencil.table.worker', 'syncConfigToWorker');
|
116
116
|
const syncDataToWorker = /*@__PURE__*/createWorkerProxy(workerPromise, 'stencil.table.worker', 'syncDataToWorker');
|
@@ -1488,4 +1488,4 @@ Table.style = tableCss;
|
|
1488
1488
|
|
1489
1489
|
export { Table as T, createWorker as c };
|
1490
1490
|
|
1491
|
-
//# sourceMappingURL=nano-table-
|
1491
|
+
//# sourceMappingURL=nano-table-c68bc58c.js.map
|