@nanoporetech-digital/components 4.9.0 → 4.9.2
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 +22 -0
- package/dist/cjs/{nano-table-c0eb1f40.js → nano-table-a9452165.js} +42 -18
- package/dist/cjs/nano-table-a9452165.js.map +1 -0
- package/dist/cjs/nano-table.cjs.entry.js +1 -1
- package/dist/cjs/{table.worker-444f9491.js → table.worker-a50cf617.js} +3 -3
- package/dist/cjs/table.worker-a50cf617.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.js +22 -11
- package/dist/collection/components/table/table.js.map +1 -1
- package/dist/collection/components/table/table.store.js +2 -2
- package/dist/collection/components/table/table.store.js.map +1 -1
- package/dist/collection/components/table/table.utils.js +16 -3
- package/dist/collection/components/table/table.utils.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.js +40 -16
- package/dist/components/table.js.map +1 -1
- package/dist/components/table.worker.js +1 -1
- package/dist/esm/{nano-table-c5d30202.js → nano-table-14764c56.js} +42 -18
- package/dist/esm/nano-table-14764c56.js.map +1 -0
- package/dist/esm/nano-table.entry.js +1 -1
- package/dist/esm/{table.worker-fee0d673.js → table.worker-a3dd27a2.js} +3 -3
- package/dist/esm/table.worker-a3dd27a2.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-8157414f.entry.js → p-0ffd130d.entry.js} +2 -2
- package/dist/nano-components/p-3b0e2b23.js +5 -0
- package/dist/nano-components/p-94aebbfe.js +5 -0
- package/dist/nano-components/p-94aebbfe.js.map +1 -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/dist/types/components/table/table.store.d.ts +2 -1
- package/docs-json.json +1 -1
- package/hydrate/index.js +60 -20
- package/package.json +2 -2
- package/dist/cjs/nano-table-c0eb1f40.js.map +0 -1
- package/dist/cjs/table.worker-444f9491.js.map +0 -1
- package/dist/esm/nano-table-c5d30202.js.map +0 -1
- package/dist/esm/table.worker-fee0d673.js.map +0 -1
- package/dist/nano-components/p-08c62411.js +0 -5
- package/dist/nano-components/p-08c62411.js.map +0 -1
- package/dist/nano-components/p-aeb1d0a0.js +0 -5
- /package/dist/nano-components/{p-8157414f.entry.js.map → p-0ffd130d.entry.js.map} +0 -0
- /package/dist/nano-components/{p-aeb1d0a0.js.map → p-3b0e2b23.js.map} +0 -0
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"table.utils.js","sourceRoot":"","sources":["../../../src/components/table/table.utils.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAS,CAAC,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKjD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,QAAgB,EAChB,QAAgB;EAEhB,MAAM,KAAK,GAAG,WAAW,EAAE,CAAC;EAC5B,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;EAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;EAEnC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;EACjC,MAAM,IAAI,GAAsC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC;EAC7D,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;EAChC,MAAM,SAAS,GAAG,QAAQ,CAAC,CA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MAAM,CAAC,GAAG,EAAE,CAAC,qBAAqB,EAAE,CAAC;EACrC,MAAM,YAAY,GAChB,MAAM,CAAC,WAAW,IAAI,QAAQ,CAAC,eAAe,CAAC,YAAY,CAAC;EAE9D,IACE,CAAC,CAAC,CAAC,MAAM;IACT,CAAC,CAAC,CAAC,GAAG;IACN,CAAC,CAAC,CAAC,IAAI;IACP,CAAC,CAAC,CAAC,KAAK;IACR,CAAC,CAAC,CAAC,MAAM;IACT,CAAC,CAAC,CAAC,KAAK;IACR,CAAC,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC,CAAC;IAEJ,OAAO,KAAK,CAAC;EAEf,OAAO,CAAC,CACN,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC;IAC7D,cAAc;IAChB,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC;MAC5D,cAAc,CACjB,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,OAAO,CAAC,IAAY,EAAE,EAAU,EAAE,GAAU;EAC1D,MAAM,MAAM,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;EACxB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;EACvC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;EAC3B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { getRenderingRef, getElement, VNode, h, Fragment } from '@stencil/core';\nimport { getStore } from './table.store';\nimport { CSSNAMESPACE } from './table.constants';\nimport type { TableTypes } from '../../interface';\n\ntype ValidRenderTypes = 'tr' | 'th' | 'td';\n\n/**\n * Get a model object for custom cell / property renderers.\n * @param rowIndex - the current row index being rendered\n * @param colIndex - the current column index being rendered\n * @returns a model object which will be passed to custom renderers\n */\nexport function colDataModel(\n rowIndex: number,\n colIndex: number\n): TableTypes.RenderModel {\n const store = fetchStores();\n const columns = store.config.state.columns;\n const rows = store.data.state.rows;\n\n const column = columns[colIndex];\n const prop: TableTypes.ColumnProp | undefined = column?.prop;\n const rowModel = rows[rowIndex];\n const cellModel = rowModel ? rowModel[columns[colIndex].prop] : '';\n\n return {\n prop,\n cellModel,\n column,\n rowIndex,\n rowModel,\n };\n}\n\n/**\n * Get a model object for custom row renderers.\n * @param rowIndex\n * @returns a model object passed to custom row renderers\n */\nexport function rowDataModel(rowIndex: number): TableTypes.RowDataSchemaModel {\n const store = fetchStores();\n const rows = store.data.state.rows;\n const rowModel = rows[rowIndex];\n\n return {\n rowModel,\n rowIndex,\n };\n}\n\n/**\n * Merges 2 objects of properties together\n * @param current - property object\n * @param extra - additional object property\n * @returns - merged properties that can be applied to a node\n */\nexport function mergeProperties<\n T extends TableTypes.CellProps | TableTypes.CellProps\n>(current: T, extra: T) {\n if (!extra) return current;\n\n // top level merge\n const props: T = { ...extra, ...current };\n\n // deeper merge\n // merge classes maps or strings\n if (extra.class) {\n if (typeof extra.class === 'object' && typeof props.class === 'object') {\n props.class = { ...extra.class, ...props.class };\n } else if (\n typeof extra.class === 'string' &&\n typeof props.class === 'object'\n ) {\n props.class[extra.class] = true;\n } else if (typeof props.class === 'string') {\n props.class += ' ' + extra.class;\n }\n }\n // merge style\n if (extra.style) {\n props.style = { ...extra.style, ...props.style };\n }\n return props;\n}\n\n/**\n * Returns the current nano-table's stores.\n * @returns the current nano-table stores\n */\nexport function fetchStores() {\n return getStore(getElement(getRenderingRef()));\n}\n\n/**\n * Merges any defined cell properties with properties\n * required by `nano-table` functionality\n * @param rowIndex - the current row index being rendered\n * @param colIndex = the current column index being rendered\n * @param defaultProps - default properties required by `nano-table`\n * @returns - the merged properties that will be applied to a node\n */\nexport function mergeCellProperties(\n rowIndex: number,\n colIndex: number,\n defaultProps: TableTypes.CellProps\n): TableTypes.CellProps {\n const props: TableTypes.CellProps = { ...defaultProps };\n const extraPropsFunc =\n fetchStores().config.state.columns[colIndex]?.cellProperties;\n if (!extraPropsFunc) return props;\n\n const data = colDataModel(rowIndex, colIndex);\n const extra = extraPropsFunc(data);\n if (!extra) return props;\n\n return mergeProperties(props, extra);\n}\n\n/**\n * Renders a table header (within a thead) using a custom template if set.\n * @param col - the current column config object\n * @returns - a JSX node\n */\nexport function colheadFootRender(col: TableTypes.ColumnConfig): VNode {\n const tpl = col?.columnTemplate;\n return tpl ? (\n tpl(h as unknown as TableTypes.HFunc<VNode>, col)\n ) : (\n <Fragment>{col.title}</Fragment>\n );\n}\n\nconst stickyHIOs: WeakMap<HTMLTableCellElement, IntersectionObserver> =\n new WeakMap();\nconst stickyVIOs: WeakMap<HTMLTableCellElement, IntersectionObserver> =\n new WeakMap();\n\n/**\n * Adds element to Intersection Observer. Fires when element changes on the x axis\n * @param el - an element to observe\n * @param pos - the edge to watch (start or end)\n * @param cb - callback when an intersection state changes.\n */\nexport function addHObserver(\n el: HTMLTableCellElement,\n pos: TableTypes.Position,\n cb: TableTypes.PinnedCb\n) {\n if (stickyHIOs.get(el)) return;\n\n const store = fetchStores();\n const root = store.general.state.scrollParent;\n\n const observer = new IntersectionObserver(\n ([e]) => {\n const rootBounds =\n e.rootBounds || document.scrollingElement.getBoundingClientRect();\n const positions: { [key in TableTypes.Position]?: boolean } = {};\n if (pos === 'start') {\n positions.start =\n e.boundingClientRect.x - (rootBounds.x + root.scrollLeft) < 0 &&\n !e.isIntersecting;\n }\n if (pos === 'end') {\n // TODO - sort these out for RtL\n positions.end =\n e.boundingClientRect.right > e.boundingClientRect.width &&\n !e.isIntersecting;\n }\n if (!!cb) cb(positions);\n },\n {\n threshold: [1],\n rootMargin: '1px 0px 100px 0px',\n root: root === document.scrollingElement ? null : root,\n }\n );\n stickyHIOs.set(el, observer);\n // dirty fix - wait a tick 'cos nano-size-observer isn't always ready in-time\n setTimeout(() => observer.observe(el), 300);\n}\n\n/**\n * Adds element to Intersection Observer. Fires when element changes on the y axis\n * @param el - an element to observe\n * @param pos - the edge to watch (start or end)\n * @param cb - callback when an intersection state changes.\n */\nexport function addVObserver(\n el: HTMLTableCellElement,\n pos: TableTypes.Position,\n cb: TableTypes.PinnedCb\n) {\n if (stickyVIOs.get(el)) return;\n\n const store = fetchStores();\n const root = store.general.state.scrollParent;\n\n const observer = new IntersectionObserver(\n ([e]) => {\n const rootBounds =\n e.rootBounds || document.scrollingElement.getBoundingClientRect();\n const positions: { [key in TableTypes.Position]?: boolean } = {};\n if (pos === 'top') {\n positions.top =\n e.boundingClientRect.y - (rootBounds.y + root.scrollTop) < 0 &&\n !e.isIntersecting;\n }\n if (pos === 'bottom') {\n const boundingClientRect = e.target.getBoundingClientRect();\n positions.bottom =\n boundingClientRect.height + boundingClientRect.y >\n rootBounds.height && !e.isIntersecting;\n }\n if (!!cb) cb(positions);\n },\n {\n threshold: [1],\n rootMargin: '0px 100px 0px 100px',\n root: root === document.scrollingElement ? null : root,\n }\n );\n stickyVIOs.set(el, observer);\n requestAnimationFrame(() => observer.observe(el));\n}\n\n/**\n * Renders a class string or map for pinned classes on the v axis.\n * @param type - element tagName\n * @param vPinned - whether element is currently pinned vertically to top or bottom\n * @param toString - render as a string (defaults to class map)\n * @returns a class string or class map\n */\nexport function headerPinClasses(\n type: ValidRenderTypes,\n vPinned?: TableTypes.Position,\n toString?: false\n): { [key: string]: boolean };\nexport function headerPinClasses(\n type: ValidRenderTypes,\n vPinned?: TableTypes.Position,\n toString?: true\n): string;\nexport function headerPinClasses(\n type: ValidRenderTypes,\n vPinned?: TableTypes.Position,\n toString = false\n): { [key: string]: boolean } | string {\n const classes = {\n [`${CSSNAMESPACE}__${type}`]: true,\n [`${CSSNAMESPACE}__pin`]: !!vPinned,\n [`${CSSNAMESPACE}__pin--top`]: vPinned === 'top',\n [`${CSSNAMESPACE}__pin--bottom`]: vPinned === 'bottom',\n };\n\n if (toString) return classListToStr(classes);\n return classes;\n}\n\n/**\n * Turns a class map {'string': boolean} to class string\n * @param classes - the class map to convert\n * @returns a class string\n */\nexport function classListToStr(classes: { [key: string]: boolean }): string {\n let classString = '';\n Object.entries(classes).forEach(([className, on]) => {\n if (on) classString += className + ' ';\n });\n return classString;\n}\n\n/**\n * Detects the current scroll speed as a number.\n * Use within a scroll listener\n */\nexport const detectScrollSpeed = (() => {\n let lastPos: number;\n let newPos: number;\n let timer: number;\n let delta: number;\n const delay = 60; // in \"ms\" (higher means lower fidelity )\n\n const clear = () => {\n lastPos = null;\n delta = 0;\n };\n clear();\n\n return () => {\n newPos = window.scrollY;\n if (lastPos != null) delta = newPos - lastPos;\n lastPos = newPos;\n window.clearTimeout(timer);\n timer = window.setTimeout(clear, delay);\n return delta;\n };\n})();\n\n/**\n * Attempts to find the closes scrolling parental element\n * @param element - the element from which to traverse up the DOM\n * @returns - the closest scrolling parental element\n */\nexport function findScrollParent(element: HTMLElement) {\n let style = getComputedStyle(element);\n const excludeStaticParent = style.position === 'absolute';\n const overflowRegex = /(auto|scroll)/;\n\n if (style.position === 'fixed') return document.documentElement;\n for (let parent = element; (parent = parent.parentElement); ) {\n style = getComputedStyle(parent);\n if (excludeStaticParent && style.position === 'static') {\n continue;\n }\n if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX))\n return parent;\n }\n return document.documentElement;\n}\n\n/**\n * Checks whether an element is currently viewable within the viewport\n * @param el - element to check\n * @param percentVisible - the percentage of the element that should be within the viewport\n * @returns true if the element's area percentage is visible\n */\nexport function isInViewport(el: Element, percentVisible = 100) {\n const r = el.getBoundingClientRect();\n const windowHeight =\n window.innerHeight || document.documentElement.clientHeight;\n\n if (\n !r.bottom &&\n !r.top &&\n !r.left &&\n !r.right &&\n !r.height &&\n !r.width &&\n !r.x &&\n !r.y\n )\n return false;\n\n return !(\n Math.floor(100 - ((r.top >= 0 ? 0 : r.top) / +-r.height) * 100) <\n percentVisible ||\n Math.floor(100 - ((r.bottom - windowHeight) / r.height) * 100) <\n percentVisible\n );\n}\n\n/**\n * Immutable array re-order\n * @param from - the index to move from\n * @param to - the index to move to\n * @param arr - the array to re-order\n * @returns - a new, re-orderd array\n */\nexport function arrMove(from: number, to: number, arr: any[]) {\n const newArr = [...arr];\n const item = newArr.splice(from, 1)[0];\n newArr.splice(to, 0, item);\n return newArr;\n}\n"]}
|
1
|
+
{"version":3,"file":"table.utils.js","sourceRoot":"","sources":["../../../src/components/table/table.utils.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,UAAU,EAAS,CAAC,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAKjD;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAC1B,QAAgB,EAChB,QAAgB;EAEhB,MAAM,KAAK,GAAG,WAAW,EAAE,CAAC;EAC5B,MAAM,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC;EAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;EAEnC,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;EACjC,MAAM,IAAI,GAAsC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,IAAI,CAAC;EAC7D,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;EAChC,MAAM,SAAS,GAAG,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;EAEnE,OA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C1D,MAAM,MAAM,GAAG,CAAC,GAAG,GAAG,CAAC,CAAC;EACxB,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;EACvC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC;EAC3B,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { getRenderingRef, getElement, VNode, h, Fragment } from '@stencil/core';\nimport { getStore } from './table.store';\nimport { CSSNAMESPACE } from './table.constants';\nimport type { TableTypes } from '../../interface';\n\ntype ValidRenderTypes = 'tr' | 'th' | 'td';\n\n/**\n * Get a model object for custom cell / property renderers.\n * @param rowIndex - the current row index being rendered\n * @param colIndex - the current column index being rendered\n * @returns a model object which will be passed to custom renderers\n */\nexport function colDataModel(\n rowIndex: number,\n colIndex: number\n): TableTypes.RenderModel {\n const store = fetchStores();\n const columns = store.config.state.columns;\n const rows = store.data.state.rows;\n\n const column = columns[colIndex];\n const prop: TableTypes.ColumnProp | undefined = column?.prop;\n const rowModel = rows[rowIndex];\n const cellModel = rowModel ? rowModel[columns[colIndex].prop] : '';\n\n return {\n prop,\n cellModel,\n column,\n rowIndex,\n rowModel,\n };\n}\n\n/**\n * Get a model object for custom row renderers.\n * @param rowIndex\n * @returns a model object passed to custom row renderers\n */\nexport function rowDataModel(rowIndex: number): TableTypes.RowDataSchemaModel {\n const store = fetchStores();\n const rows = store.data.state.rows;\n const rowModel = rows[rowIndex];\n\n return {\n rowModel,\n rowIndex,\n };\n}\n\n/**\n * Merges 2 objects of properties together\n * @param current - property object\n * @param extra - additional object property\n * @returns - merged properties that can be applied to a node\n */\nexport function mergeProperties<\n T extends TableTypes.CellProps | TableTypes.CellProps\n>(current: T, extra: T) {\n if (!extra) return current;\n\n // top level merge\n const props: T = { ...extra, ...current };\n\n // deeper merge\n // merge classes maps or strings\n if (extra.class) {\n if (typeof extra.class === 'object' && typeof props.class === 'object') {\n props.class = { ...extra.class, ...props.class };\n } else if (\n typeof extra.class === 'string' &&\n typeof props.class === 'object'\n ) {\n props.class[extra.class] = true;\n } else if (typeof props.class === 'string') {\n props.class += ' ' + extra.class;\n }\n }\n // merge style\n if (extra.style) {\n props.style = { ...extra.style, ...props.style };\n }\n return props;\n}\n\n/**\n * Returns the current nano-table's stores.\n * @returns the current nano-table stores\n */\nexport function fetchStores() {\n return getStore(getElement(getRenderingRef()));\n}\n\n/**\n * Merges any defined cell properties with properties\n * required by `nano-table` functionality\n * @param rowIndex - the current row index being rendered\n * @param colIndex = the current column index being rendered\n * @param defaultProps - default properties required by `nano-table`\n * @returns - the merged properties that will be applied to a node\n */\nexport function mergeCellProperties(\n rowIndex: number,\n colIndex: number,\n defaultProps: TableTypes.CellProps\n): TableTypes.CellProps {\n const props: TableTypes.CellProps = { ...defaultProps };\n const extraPropsFunc =\n fetchStores().config.state.columns[colIndex]?.cellProperties;\n if (!extraPropsFunc) return props;\n\n const data = colDataModel(rowIndex, colIndex);\n const extra = extraPropsFunc(data);\n if (!extra) return props;\n\n return mergeProperties(props, extra);\n}\n\n/**\n * Renders a table header (within a thead) using a custom template if set.\n * @param col - the current column config object\n * @returns - a JSX node\n */\nexport function colheadFootRender(col: TableTypes.ColumnConfig): VNode {\n const tpl = col?.columnTemplate;\n return tpl ? (\n tpl(h as unknown as TableTypes.HFunc<VNode>, col)\n ) : (\n <Fragment>{col.title}</Fragment>\n );\n}\n\nconst stickyHIOs: WeakMap<HTMLTableCellElement, IntersectionObserver> =\n new WeakMap();\nconst stickyVIOs: WeakMap<HTMLTableCellElement, IntersectionObserver> =\n new WeakMap();\n\n/**\n * Adds element to Intersection Observer. Fires when element changes on the x axis\n * @param el - an element to observe\n * @param pos - the edge to watch (start or end)\n * @param cb - callback when an intersection state changes.\n */\nexport function addHObserver(\n el: HTMLTableCellElement,\n pos: TableTypes.Position,\n cb: TableTypes.PinnedCb\n) {\n if (stickyHIOs.get(el)) return;\n\n const store = fetchStores();\n const root = store.general.state.scrollParent;\n\n const observer = new IntersectionObserver(\n ([e]) => {\n const rootBounds =\n e.rootBounds || document.scrollingElement.getBoundingClientRect();\n const positions: { [key in TableTypes.Position]?: boolean } = {};\n if (pos === 'start') {\n positions.start =\n e.boundingClientRect.x - (rootBounds.x + root.scrollLeft) < 0 &&\n !e.isIntersecting;\n }\n if (pos === 'end') {\n // TODO - sort these out for RtL\n positions.end =\n e.boundingClientRect.right > e.boundingClientRect.width &&\n !e.isIntersecting;\n }\n if (!!cb) cb(positions);\n },\n {\n threshold: [1],\n rootMargin: '1px 0px 100px 0px',\n root: root === document.scrollingElement ? null : root,\n }\n );\n stickyHIOs.set(el, observer);\n\n if (store.general.state.isReady) {\n observer.observe(el);\n } else {\n store.general.state.host.addEventListener(\n 'nanoTblReady',\n () => {\n observer.observe(el);\n },\n { once: true }\n );\n }\n}\n\n/**\n * Adds element to Intersection Observer. Fires when element changes on the y axis\n * @param el - an element to observe\n * @param pos - the edge to watch (start or end)\n * @param cb - callback when an intersection state changes.\n */\nexport function addVObserver(\n el: HTMLTableCellElement,\n pos: TableTypes.Position,\n cb: TableTypes.PinnedCb\n) {\n if (stickyVIOs.get(el)) return;\n\n const store = fetchStores();\n const root = store.general.state.scrollParent;\n\n const observer = new IntersectionObserver(\n ([e]) => {\n const rootBounds =\n e.rootBounds || document.scrollingElement.getBoundingClientRect();\n const positions: { [key in TableTypes.Position]?: boolean } = {};\n if (pos === 'top') {\n positions.top =\n e.boundingClientRect.y - (rootBounds.y + root.scrollTop) < 0 &&\n !e.isIntersecting;\n }\n if (pos === 'bottom') {\n const boundingClientRect = e.target.getBoundingClientRect();\n positions.bottom =\n boundingClientRect.height + boundingClientRect.y >\n rootBounds.height && !e.isIntersecting;\n }\n if (!!cb) cb(positions);\n },\n {\n threshold: [1],\n rootMargin: '0px 100px 0px 100px',\n root: root === document.scrollingElement ? null : root,\n }\n );\n stickyVIOs.set(el, observer);\n\n if (store.general.state.isReady) {\n observer.observe(el);\n } else {\n store.general.state.host.addEventListener(\n 'nanoTblReady',\n () => {\n observer.observe(el);\n },\n { once: true }\n );\n }\n}\n\n/**\n * Renders a class string or map for pinned classes on the v axis.\n * @param type - element tagName\n * @param vPinned - whether element is currently pinned vertically to top or bottom\n * @param toString - render as a string (defaults to class map)\n * @returns a class string or class map\n */\nexport function headerPinClasses(\n type: ValidRenderTypes,\n vPinned?: TableTypes.Position,\n toString?: false\n): { [key: string]: boolean };\nexport function headerPinClasses(\n type: ValidRenderTypes,\n vPinned?: TableTypes.Position,\n toString?: true\n): string;\nexport function headerPinClasses(\n type: ValidRenderTypes,\n vPinned?: TableTypes.Position,\n toString = false\n): { [key: string]: boolean } | string {\n const classes = {\n [`${CSSNAMESPACE}__${type}`]: true,\n [`${CSSNAMESPACE}__pin`]: !!vPinned,\n [`${CSSNAMESPACE}__pin--top`]: vPinned === 'top',\n [`${CSSNAMESPACE}__pin--bottom`]: vPinned === 'bottom',\n };\n\n if (toString) return classListToStr(classes);\n return classes;\n}\n\n/**\n * Turns a class map {'string': boolean} to class string\n * @param classes - the class map to convert\n * @returns a class string\n */\nexport function classListToStr(classes: { [key: string]: boolean }): string {\n let classString = '';\n Object.entries(classes).forEach(([className, on]) => {\n if (on) classString += className + ' ';\n });\n return classString;\n}\n\n/**\n * Detects the current scroll speed as a number.\n * Use within a scroll listener\n */\nexport const detectScrollSpeed = (() => {\n let lastPos: number;\n let newPos: number;\n let timer: number;\n let delta: number;\n const delay = 60; // in \"ms\" (higher means lower fidelity )\n\n const clear = () => {\n lastPos = null;\n delta = 0;\n };\n clear();\n\n return () => {\n newPos = window.scrollY;\n if (lastPos != null) delta = newPos - lastPos;\n lastPos = newPos;\n window.clearTimeout(timer);\n timer = window.setTimeout(clear, delay);\n return delta;\n };\n})();\n\n/**\n * Attempts to find the closes scrolling parental element\n * @param element - the element from which to traverse up the DOM\n * @returns - the closest scrolling parental element\n */\nexport function findScrollParent(element: HTMLElement) {\n let style = getComputedStyle(element);\n const excludeStaticParent = style.position === 'absolute';\n const overflowRegex = /(auto|scroll)/;\n\n if (style.position === 'fixed') return document.documentElement;\n for (let parent = element; (parent = parent.parentElement); ) {\n style = getComputedStyle(parent);\n if (excludeStaticParent && style.position === 'static') {\n continue;\n }\n if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX))\n return parent;\n }\n return document.documentElement;\n}\n\n/**\n * Checks whether an element is currently viewable within the viewport\n * @param el - element to check\n * @param percentVisible - the percentage of the element that should be within the viewport\n * @returns true if the element's area percentage is visible\n */\nexport function isInViewport(el: Element, percentVisible = 100) {\n const r = el.getBoundingClientRect();\n const windowHeight =\n window.innerHeight || document.documentElement.clientHeight;\n\n if (\n !r.bottom &&\n !r.top &&\n !r.left &&\n !r.right &&\n !r.height &&\n !r.width &&\n !r.x &&\n !r.y\n )\n return false;\n\n return !(\n Math.floor(100 - ((r.top >= 0 ? 0 : r.top) / +-r.height) * 100) <\n percentVisible ||\n Math.floor(100 - ((r.bottom - windowHeight) / r.height) * 100) <\n percentVisible\n );\n}\n\n/**\n * Immutable array re-order\n * @param from - the index to move from\n * @param to - the index to move to\n * @param arr - the array to re-order\n * @returns - a new, re-orderd array\n */\nexport function arrMove(from: number, to: number, arr: any[]) {\n const newArr = [...arr];\n const item = newArr.splice(from, 1)[0];\n newArr.splice(to, 0, item);\n return newArr;\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,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,IAAkC,EAClC,OAA2C;EAE3C,MAAM,EA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,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,CAAC,WAAW;IAAE,MAAM,6BAA6B,GAAG,QAAQ,CAAC;EAEjE,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC;EACxB,IAAI,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,OA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I,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"]}
|
package/dist/components/table.js
CHANGED
@@ -135,11 +135,11 @@ function colsToWorker(columns) {
|
|
135
135
|
return safeColumns;
|
136
136
|
}
|
137
137
|
const stores = new WeakMap();
|
138
|
-
async function generateStore(host, columns, scrollParent) {
|
138
|
+
async function generateStore(host, columns, scrollParent, isReady) {
|
139
139
|
const store = {
|
140
140
|
data: createStore({ rows: [] }),
|
141
141
|
config: createStore({ columns }),
|
142
|
-
general: createStore({ workerId: null, scrollParent, host }),
|
142
|
+
general: createStore({ workerId: null, scrollParent, host, isReady }),
|
143
143
|
};
|
144
144
|
const id = await createWorkerStore(store.data.state.rows, colsToWorker(store.config.state.columns));
|
145
145
|
store.general.state.workerId = id;
|
@@ -402,8 +402,14 @@ function addHObserver(el, pos, cb) {
|
|
402
402
|
root: root === document.scrollingElement ? null : root,
|
403
403
|
});
|
404
404
|
stickyHIOs.set(el, observer);
|
405
|
-
|
406
|
-
|
405
|
+
if (store.general.state.isReady) {
|
406
|
+
observer.observe(el);
|
407
|
+
}
|
408
|
+
else {
|
409
|
+
store.general.state.host.addEventListener('nanoTblReady', () => {
|
410
|
+
observer.observe(el);
|
411
|
+
}, { once: true });
|
412
|
+
}
|
407
413
|
}
|
408
414
|
/**
|
409
415
|
* Adds element to Intersection Observer. Fires when element changes on the y axis
|
@@ -438,7 +444,14 @@ function addVObserver(el, pos, cb) {
|
|
438
444
|
root: root === document.scrollingElement ? null : root,
|
439
445
|
});
|
440
446
|
stickyVIOs.set(el, observer);
|
441
|
-
|
447
|
+
if (store.general.state.isReady) {
|
448
|
+
observer.observe(el);
|
449
|
+
}
|
450
|
+
else {
|
451
|
+
store.general.state.host.addEventListener('nanoTblReady', () => {
|
452
|
+
observer.observe(el);
|
453
|
+
}, { once: true });
|
454
|
+
}
|
442
455
|
}
|
443
456
|
function headerPinClasses(type, vPinned, toString = false) {
|
444
457
|
const classes = {
|
@@ -1324,18 +1337,29 @@ const Table = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
1324
1337
|
readTask(() => {
|
1325
1338
|
this.setMeasureElement();
|
1326
1339
|
// find the first active block
|
1327
|
-
if (!this.measureEle && !this.unitHeight)
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1340
|
+
if (!this.measureEle && !this.unitHeight) {
|
1341
|
+
// it's likely this table is hidden in the dom.
|
1342
|
+
// we need to wait until it's visible
|
1343
|
+
const observer = new IntersectionObserver(([e]) => {
|
1344
|
+
if (e.isIntersecting) {
|
1345
|
+
resolve();
|
1346
|
+
observer.disconnect();
|
1347
|
+
}
|
1348
|
+
}, { root: this.scrollParent });
|
1349
|
+
observer.observe(this.tableEle);
|
1350
|
+
}
|
1351
|
+
else {
|
1352
|
+
this.blockElements.forEach((el, i) => {
|
1353
|
+
var _a;
|
1354
|
+
if (!el || !((_a = el.classList) === null || _a === void 0 ? void 0 : _a.contains(`${CSSNAMESPACE}__inactive`))) {
|
1355
|
+
if (i === this.blockElements.length - 1)
|
1356
|
+
resolve();
|
1357
|
+
return;
|
1358
|
+
}
|
1332
1359
|
if (i === this.blockElements.length - 1)
|
1333
1360
|
resolve();
|
1334
|
-
|
1335
|
-
|
1336
|
-
if (i === this.blockElements.length - 1)
|
1337
|
-
resolve();
|
1338
|
-
});
|
1361
|
+
});
|
1362
|
+
}
|
1339
1363
|
});
|
1340
1364
|
});
|
1341
1365
|
// we're all finished.
|
@@ -1452,7 +1476,7 @@ const Table = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
1452
1476
|
async componentWillLoad() {
|
1453
1477
|
perMark('init');
|
1454
1478
|
this.scrollParent = findScrollParent(this.host);
|
1455
|
-
this.store = await generateStore(this.host, this.columns, this.scrollParent);
|
1479
|
+
this.store = await generateStore(this.host, this.columns, this.scrollParent, this.isReady);
|
1456
1480
|
await this.handleRowsChange();
|
1457
1481
|
this.processSlots();
|
1458
1482
|
this.store.data.onChange('rows', () => this.setBlocks());
|