@nanoporetech-digital/components 4.9.1 → 4.9.3
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 +23 -0
- package/dist/cjs/{nano-table-ba660665.js → nano-table-0bac0552.js} +79 -35
- package/dist/cjs/nano-table-0bac0552.js.map +1 -0
- package/dist/cjs/nano-table.cjs.entry.js +1 -1
- package/dist/cjs/{table.worker-1e265707.js → table.worker-13b5bc18.js} +2 -2
- package/dist/cjs/table.worker-13b5bc18.js.map +1 -0
- package/dist/collection/components/table/table.js +59 -28
- 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/components/table.js +77 -33
- package/dist/components/table.js.map +1 -1
- package/dist/esm/{nano-table-c68bc58c.js → nano-table-ece658c4.js} +79 -35
- package/dist/esm/nano-table-ece658c4.js.map +1 -0
- package/dist/esm/nano-table.entry.js +1 -1
- package/dist/esm/{table.worker-8c883d01.js → table.worker-e89525d3.js} +2 -2
- package/dist/esm/table.worker-e89525d3.js.map +1 -0
- package/dist/nano-components/nano-components.esm.js +1 -1
- package/dist/nano-components/p-11025069.js +5 -0
- package/dist/nano-components/p-11025069.js.map +1 -0
- package/dist/nano-components/{p-26cae735.entry.js → p-27d5d32b.entry.js} +2 -2
- package/dist/nano-components/{p-a26ec47a.js → p-bd2d0c58.js} +2 -2
- package/dist/types/components/table/table.d.ts +8 -3
- package/dist/types/components/table/table.store.d.ts +3 -1
- package/docs-json.json +1 -1
- package/hydrate/index.js +77 -33
- package/package.json +2 -2
- package/dist/cjs/nano-table-ba660665.js.map +0 -1
- package/dist/cjs/table.worker-1e265707.js.map +0 -1
- package/dist/esm/nano-table-c68bc58c.js.map +0 -1
- package/dist/esm/table.worker-8c883d01.js.map +0 -1
- package/dist/nano-components/p-097270e7.js +0 -5
- package/dist/nano-components/p-097270e7.js.map +0 -1
- /package/dist/nano-components/{p-26cae735.entry.js.map → p-27d5d32b.entry.js.map} +0 -0
- /package/dist/nano-components/{p-a26ec47a.js.map → p-bd2d0c58.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,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;EAEnE,OAAO;IACL,IAAI;IACJ,SAAS;IACT,MAAM;IACN,QAAQ;IACR,QAAQ;GACT,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB;EAC3C,MAAM,KAAK,GAAG,WAAW,EAAE,CAAC;EAC5B,MAAM,I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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,OAAO;IACL,IAAI;IACJ,SAAS;IACT,MAAM;IACN,QAAQ;IACR,QAAQ;GACT,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,QAAgB;EAC3C,MAAM,KAAK,GAAG,WAAW,EAAE,CAAC;EAC5B,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;EACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CA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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"]}
|
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 = {
|
@@ -970,6 +983,8 @@ const Table = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
970
983
|
}
|
971
984
|
};
|
972
985
|
this.scrollHandler = () => {
|
986
|
+
if (!this.store.general.state.isActive)
|
987
|
+
return;
|
973
988
|
this.cacheScrollPosition = this.scrollParent.scrollTop || window.scrollY;
|
974
989
|
requestAnimationFrame(() => {
|
975
990
|
let cumulativeHeight = 0;
|
@@ -1054,7 +1069,7 @@ const Table = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
1054
1069
|
this.currentSort = '';
|
1055
1070
|
await this.columnInit();
|
1056
1071
|
if (!this.isReady)
|
1057
|
-
this.setInitialBlockDimension();
|
1072
|
+
requestAnimationFrame(() => this.setInitialBlockDimension());
|
1058
1073
|
this._loading = false;
|
1059
1074
|
});
|
1060
1075
|
}
|
@@ -1147,8 +1162,9 @@ const Table = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
1147
1162
|
? document
|
1148
1163
|
: this._scrollParent).removeEventListener('scroll', this.scrollHandler);
|
1149
1164
|
}
|
1150
|
-
(ele === document.documentElement ? document : ele).addEventListener('scroll', this.scrollHandler);
|
1165
|
+
(ele === document.documentElement ? document : ele).addEventListener('scroll', this.scrollHandler, { passive: true });
|
1151
1166
|
this._scrollParent = ele;
|
1167
|
+
this.setupActiveWatcher();
|
1152
1168
|
}
|
1153
1169
|
// used to fire `nanoTblBlockRendered` on block render change
|
1154
1170
|
get primaryBlockIndex() {
|
@@ -1306,45 +1322,49 @@ const Table = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
1306
1322
|
this.scrollHandler();
|
1307
1323
|
}
|
1308
1324
|
setMeasureElement() {
|
1309
|
-
|
1310
|
-
|
1325
|
+
return new Promise((resolve) => {
|
1326
|
+
readTask(() => {
|
1327
|
+
this.measureEle = this.blockElements.find((b) => { var _a; return !((_a = b === null || b === void 0 ? void 0 : b.classList) === null || _a === void 0 ? void 0 : _a.contains(`${CSSNAMESPACE}__inactive`)); });
|
1328
|
+
resolve();
|
1329
|
+
});
|
1311
1330
|
});
|
1312
1331
|
}
|
1313
1332
|
/**
|
1314
|
-
*
|
1315
|
-
*
|
1316
|
-
*
|
1333
|
+
* Makes sure we have dimensions on at least one, active tbody element.
|
1334
|
+
* We'll use this is a yard stick for inactive tbody elements in future.
|
1335
|
+
* These elements have no natural height (on account of all their rows being hidden)
|
1317
1336
|
*/
|
1318
1337
|
setInitialBlockDimension() {
|
1319
1338
|
var _a;
|
1320
1339
|
if (!((_a = this.blockElements) === null || _a === void 0 ? void 0 : _a.length))
|
1321
1340
|
return;
|
1322
1341
|
perMark('blockDims');
|
1323
|
-
const
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
if (
|
1342
|
+
const testForDimensions = async () => {
|
1343
|
+
await this.setMeasureElement();
|
1344
|
+
if (this.unitHeight)
|
1345
|
+
return true;
|
1346
|
+
return false;
|
1347
|
+
};
|
1348
|
+
const dimensionsReady = new Promise(async (resolve) => {
|
1349
|
+
if (await testForDimensions())
|
1350
|
+
resolve();
|
1351
|
+
else {
|
1352
|
+
// it's likely this table is hidden in the dom.
|
1353
|
+
// we need to wait until it's visible
|
1354
|
+
const observer = new IntersectionObserver(async () => {
|
1355
|
+
if (await testForDimensions()) {
|
1337
1356
|
resolve();
|
1338
|
-
|
1339
|
-
|
1357
|
+
observer.disconnect();
|
1358
|
+
}
|
1359
|
+
}, { root: this.scrollParent });
|
1360
|
+
observer.observe(this.tableEle);
|
1361
|
+
}
|
1340
1362
|
});
|
1341
1363
|
// we're all finished.
|
1342
|
-
|
1364
|
+
dimensionsReady.then(() => {
|
1343
1365
|
perMark('blockDims', true);
|
1344
1366
|
perMark('init', true);
|
1345
|
-
requestAnimationFrame(() =>
|
1346
|
-
this.isReady = true;
|
1347
|
-
});
|
1367
|
+
requestAnimationFrame(() => (this.isReady = true));
|
1348
1368
|
});
|
1349
1369
|
}
|
1350
1370
|
/** Apply initial columns settings */
|
@@ -1448,11 +1468,29 @@ const Table = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
1448
1468
|
console.error('For accessibility you must set a `caption` prop or use the `caption` slot');
|
1449
1469
|
}
|
1450
1470
|
}
|
1471
|
+
/** Adds an IO. Makes sure our scroll listener is only active when
|
1472
|
+
* the table is in viewport */
|
1473
|
+
setupActiveWatcher() {
|
1474
|
+
if (!this.host || !this.scrollParent)
|
1475
|
+
return;
|
1476
|
+
if (this.activeWatcherIo) {
|
1477
|
+
this.activeWatcherIo.disconnect();
|
1478
|
+
this.activeWatcherIo = undefined;
|
1479
|
+
}
|
1480
|
+
const io = (this.activeWatcherIo = new IntersectionObserver(async ([e]) => {
|
1481
|
+
if (e.isIntersecting)
|
1482
|
+
this.store.general.state.isActive = true;
|
1483
|
+
else
|
1484
|
+
this.store.general.state.isActive = false;
|
1485
|
+
}, { root: this.scrollParent }));
|
1486
|
+
io.observe(this.host);
|
1487
|
+
}
|
1451
1488
|
// Component lifecycle
|
1452
1489
|
async componentWillLoad() {
|
1453
1490
|
perMark('init');
|
1454
1491
|
this.scrollParent = findScrollParent(this.host);
|
1455
|
-
this.store = await generateStore(this.host, this.columns, this.scrollParent);
|
1492
|
+
this.store = await generateStore(this.host, this.columns, this.scrollParent, this.isReady);
|
1493
|
+
this.store.general.onChange('isActive', this.scrollHandler);
|
1456
1494
|
await this.handleRowsChange();
|
1457
1495
|
this.processSlots();
|
1458
1496
|
this.store.data.onChange('rows', () => this.setBlocks());
|
@@ -1480,6 +1518,12 @@ const Table = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
|
|
1480
1518
|
this.setMeasureElement();
|
1481
1519
|
perMark('render', true);
|
1482
1520
|
}
|
1521
|
+
disconnectedCallback() {
|
1522
|
+
if (!this.activeWatcherIo)
|
1523
|
+
return;
|
1524
|
+
this.activeWatcherIo.disconnect();
|
1525
|
+
this.activeWatcherIo = undefined;
|
1526
|
+
}
|
1483
1527
|
render() {
|
1484
1528
|
this.blockElements = [];
|
1485
1529
|
return (h(Host, null, h("div", { class: `${CSSNAMESPACE}__top-anchor`, ref: (a) => (this.topAnchorEle = a) }, "\u00A0"), h("nano-resize-observe", { "aria-labelledby": 'table-caption-' + this.renderId, tabindex: this.type === 'grid' ? '0' : undefined, states: "576w sm, 768w md", class: "sm md", onNanoResizeStateChange: this.handleResizeChange }), h("div", { class: `${CSSNAMESPACE}__wrap sm md`, ref: (div) => (this.tableWrapperEle = div) }, h("nano-progress-bar", { indeterminate: true, class: {
|