@shortfuse/materialdesignweb 0.3.0 → 0.4.0
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/.eslintrc.json +136 -30
- package/.stylelintrc.json +6 -40
- package/.vscode/launch.json +20 -5
- package/CHANGELOG.md +24 -0
- package/README.md +12 -9
- package/adapters/datatable/column.js +82 -74
- package/adapters/datatable/index.js +173 -131
- package/adapters/dom/index.js +529 -75
- package/adapters/list/index.js +25 -12
- package/adapters/search/index.js +13 -13
- package/components/appbar/_spec.scss +87 -64
- package/components/appbar/index.scss +2 -2
- package/components/banner/_spec.scss +8 -8
- package/components/banner/index.scss +2 -2
- package/components/bottomnav/_spec.scss +22 -17
- package/components/bottomnav/index.js +61 -52
- package/components/bottomnav/index.scss +2 -2
- package/components/bottomnav/item.js +44 -25
- package/components/button/README.md +14 -14
- package/components/button/_spec.scss +23 -22
- package/components/button/_theme.scss +37 -21
- package/components/button/index.eta +32 -0
- package/components/button/index.js +12 -12
- package/components/button/index.scss +2 -2
- package/components/card/_spec.scss +40 -36
- package/components/card/index.scss +2 -2
- package/components/chip/_spec.scss +7 -8
- package/components/chip/_theme.scss +31 -31
- package/components/chip/index.js +3 -2
- package/components/chip/index.scss +2 -2
- package/components/chip/item.js +1 -16
- package/components/datatable/_spec.scss +71 -85
- package/components/datatable/_theme.scss +61 -156
- package/components/datatable/cell.js +45 -0
- package/components/datatable/columnheader.js +47 -0
- package/components/datatable/index.js +279 -366
- package/components/datatable/index.scss +2 -2
- package/components/datatable/row.js +49 -0
- package/components/datatable/rowheader.js +18 -0
- package/components/dialog/_spec.scss +61 -41
- package/components/dialog/index.js +325 -297
- package/components/dialog/index.scss +2 -2
- package/components/divider/_spec.scss +8 -6
- package/components/divider/index.scss +2 -2
- package/components/elevation/_spec.scss +2 -2
- package/components/elevation/index.scss +2 -2
- package/components/fab/_spec.scss +23 -24
- package/components/fab/index.js +50 -50
- package/components/fab/index.scss +2 -2
- package/components/grid/_spec.scss +33 -31
- package/components/grid/index.scss +2 -2
- package/components/layout/_mixins.scss +5 -5
- package/components/layout/_spec.scss +206 -176
- package/components/layout/_theme.scss +14 -16
- package/components/layout/index.js +181 -153
- package/components/layout/index.scss +2 -2
- package/components/list/_spec.scss +117 -104
- package/components/list/_theme.scss +31 -34
- package/components/list/content.js +68 -52
- package/components/list/index.js +194 -61
- package/components/list/index.scss +2 -2
- package/components/list/item.js +136 -12
- package/components/list/secondary.js +46 -0
- package/components/menu/_spec.scss +32 -19
- package/components/menu/index.js +242 -229
- package/components/menu/index.scss +2 -2
- package/components/menu/item.js +95 -110
- package/components/progress/_spec.scss +35 -27
- package/components/progress/index.js +21 -0
- package/components/progress/index.scss +2 -1
- package/components/selection/_spec.scss +242 -224
- package/components/selection/_theme.scss +100 -95
- package/components/selection/index.eta +60 -0
- package/components/selection/index.js +76 -0
- package/components/selection/index.pug +15 -8
- package/components/selection/index.scss +2 -2
- package/components/selection/input.js +56 -0
- package/components/selection/radiogroup.js +47 -0
- package/components/slider/_spec.scss +10 -8
- package/components/slider/index.scss +2 -2
- package/components/snackbar/_spec.scss +22 -21
- package/components/snackbar/index.js +102 -111
- package/components/snackbar/index.scss +2 -2
- package/components/tab/_spec.scss +20 -19
- package/components/tab/content.js +41 -40
- package/components/tab/index.js +192 -99
- package/components/tab/index.scss +2 -2
- package/components/tab/item.js +38 -55
- package/components/tab/list.js +96 -72
- package/components/tab/panel.js +12 -13
- package/components/template/_theme.scss +11 -11
- package/components/textfield/_mixins.scss +52 -0
- package/components/textfield/_spec.scss +215 -266
- package/components/textfield/_theme.scss +95 -72
- package/components/textfield/index.eta +74 -0
- package/components/textfield/index.js +63 -57
- package/components/textfield/index.scss +2 -2
- package/components/tooltip/_spec.scss +27 -25
- package/components/tooltip/index.scss +2 -2
- package/components/type/_spec.scss +51 -38
- package/components/type/index.scss +2 -2
- package/core/_breakpoint.scss +75 -91
- package/core/_elevation.scss +10 -10
- package/core/_length.scss +9 -0
- package/core/_motion.scss +14 -14
- package/core/_platform.scss +9 -15
- package/core/_type.scss +33 -32
- package/core/aria/attributes.js +125 -25
- package/core/aria/button.js +23 -23
- package/core/aria/keyboard.js +93 -0
- package/core/aria/rovingtabindex.js +69 -154
- package/core/aria/tab.js +31 -28
- package/core/color/_theme.scss +240 -280
- package/core/color/index.scss +2 -2
- package/core/document/index.js +39 -0
- package/core/dom.js +12 -12
- package/core/overlay/_spec.scss +0 -3
- package/core/overlay/_theme.scss +56 -74
- package/core/overlay/index.js +49 -18
- package/core/overlay/index.scss +2 -2
- package/core/ripple/_spec.scss +22 -39
- package/core/ripple/_theme.scss +13 -13
- package/core/ripple/index.js +137 -134
- package/core/ripple/index.scss +2 -2
- package/core/theme/_config.scss +2 -0
- package/core/theme/_mixins.scss +172 -0
- package/core/theme/_palettes.scss +155 -135
- package/core/theme/_variables.scss +24 -15
- package/core/theme/index.js +50 -0
- package/core/throttler.js +1 -1
- package/core/transition/index.js +36 -20
- package/{docs-src → docs}/_flex.scss +0 -0
- package/{docs-src → docs}/_menuoptions.js +21 -34
- package/{docs-src → docs}/_mixins.pug +39 -26
- package/docs/_partials/_androidnavbar.eta +5 -0
- package/docs/_partials/_androidstatusbar.eta +13 -0
- package/docs/_partials/_appbar.eta +29 -0
- package/docs/_partials/_buttontest.eta +31 -0
- package/docs/_partials/_header.eta +149 -0
- package/docs/_partials/_navlistitem.eta +16 -0
- package/docs/_partials/_target.eta +1 -0
- package/{docs-src → docs}/_sample-utils.js +8 -6
- package/{docs-src → docs}/_storage.js +0 -0
- package/{docs-src → docs}/docs.scss +5 -2
- package/docs/index.eta +16 -0
- package/{docs-src → docs}/index.js +0 -0
- package/docs/pages/appbar.eta +114 -0
- package/{docs-src/components → docs/pages}/appbar.js +0 -0
- package/{docs-src/components → docs/pages}/appbar.pug +15 -18
- package/docs/pages/bottomnav.eta +188 -0
- package/{docs-src/components → docs/pages}/bottomnav.js +23 -24
- package/{docs-src/components → docs/pages}/bottomnav.pug +4 -4
- package/docs/pages/button.eta +124 -0
- package/{docs-src/components → docs/pages}/button.js +19 -19
- package/{docs-src/components → docs/pages}/button.pug +15 -15
- package/docs/pages/card.eta +90 -0
- package/{docs-src/components → docs/pages}/card.js +3 -3
- package/{docs-src/components → docs/pages}/card.pug +7 -7
- package/docs/pages/chip.eta +122 -0
- package/{docs-src/components → docs/pages}/chip.js +3 -6
- package/{docs-src/components → docs/pages}/chip.pug +2 -2
- package/docs/pages/color.eta +143 -0
- package/{docs-src/core → docs/pages}/color.js +95 -20
- package/docs/pages/color.pug +121 -0
- package/docs/pages/datatable.eta +323 -0
- package/{docs-src/components → docs/pages}/datatable.js +26 -13
- package/docs/pages/datatable.pug +283 -0
- package/docs/pages/dialog.eta +186 -0
- package/{docs-src/components → docs/pages}/dialog.js +26 -13
- package/{docs-src/components → docs/pages}/dialog.pug +46 -28
- package/docs/pages/dom.eta +26 -0
- package/docs/pages/dom.js +143 -0
- package/docs/pages/dom.pug +22 -0
- package/docs/pages/elevation.eta +35 -0
- package/{docs-src/components → docs/pages}/elevation.js +0 -0
- package/{docs-src/components → docs/pages}/elevation.pug +0 -0
- package/docs/pages/fab.eta +99 -0
- package/{docs-src/components → docs/pages}/fab.js +3 -3
- package/{docs-src/components → docs/pages}/fab.pug +2 -2
- package/docs/pages/grid.eta +135 -0
- package/{docs-src/components → docs/pages}/grid.js +1 -1
- package/{docs-src/components → docs/pages}/grid.pug +3 -3
- package/docs/pages/layout.eta +8 -0
- package/{docs-src/components → docs/pages}/layout.js +0 -0
- package/{docs-src/components → docs/pages}/layout.pug +0 -0
- package/docs/pages/list.eta +465 -0
- package/{docs-src/components → docs/pages}/list.js +2 -2
- package/{docs-src/components → docs/pages}/list.pug +7 -14
- package/docs/pages/menu.eta +276 -0
- package/{docs-src/components → docs/pages}/menu.js +14 -10
- package/{docs-src/components → docs/pages}/menu.pug +0 -0
- package/docs/pages/overlay.eta +69 -0
- package/docs/pages/overlay.js +4 -0
- package/{docs-src/core → docs/pages}/overlay.pug +14 -11
- package/docs/pages/progress.eta +23 -0
- package/{docs-src/components → docs/pages}/progress.js +1 -1
- package/{docs-src/components → docs/pages}/progress.pug +1 -1
- package/docs/pages/ripple.eta +27 -0
- package/docs/pages/ripple.js +4 -0
- package/{docs-src/core → docs/pages}/ripple.pug +4 -4
- package/docs/pages/search.eta +246 -0
- package/{docs-src/components → docs/pages}/search.js +59 -42
- package/{docs-src/components → docs/pages}/search.pug +50 -51
- package/docs/pages/selection.eta +111 -0
- package/docs/pages/selection.js +13 -0
- package/docs/pages/selection.pug +74 -0
- package/docs/pages/slider.eta +23 -0
- package/{docs-src/components → docs/pages}/slider.js +0 -0
- package/{docs-src/components → docs/pages}/slider.pug +0 -0
- package/docs/pages/snackbar.eta +83 -0
- package/{docs-src/components → docs/pages}/snackbar.js +3 -3
- package/{docs-src/components → docs/pages}/snackbar.pug +0 -0
- package/docs/pages/tab.eta +421 -0
- package/{docs-src/components → docs/pages}/tab.js +18 -35
- package/{docs-src/components → docs/pages}/tab.pug +4 -4
- package/docs/pages/textfield.eta +486 -0
- package/{docs-src/components → docs/pages}/textfield.js +3 -4
- package/{docs-src/components → docs/pages}/textfield.pug +87 -35
- package/docs/pages/tooltip.eta +94 -0
- package/{docs-src/components → docs/pages}/tooltip.js +0 -0
- package/{docs-src/components → docs/pages}/tooltip.pug +0 -1
- package/docs/pages/transition.eta +117 -0
- package/{docs-src/core → docs/pages}/transition.js +7 -8
- package/{docs-src/core → docs/pages}/transition.pug +0 -0
- package/docs/pages/type.eta +31 -0
- package/{docs-src/components → docs/pages}/type.js +0 -0
- package/{docs-src/components → docs/pages}/type.pug +0 -1
- package/docs/postrender.js +39 -0
- package/{docs-src → docs}/prerender.js +3 -9
- package/docs/pwa/_dialogs.eta +143 -0
- package/docs/pwa/_dialogs.pug +96 -0
- package/docs/pwa/_menus.eta +16 -0
- package/{docs-src → docs}/pwa/_menus.pug +0 -0
- package/docs/pwa/pwa-prerender.js +3 -0
- package/docs/pwa/pwa.eta +480 -0
- package/docs/pwa/pwa.js +306 -0
- package/{docs-src → docs}/pwa/pwa.pug +166 -263
- package/docs/pwa/pwa.scss +26 -0
- package/docs/spec.scss +26 -0
- package/docs/themes/_component-themes.scss +26 -0
- package/docs/themes/theme-colored-fallbacks.scss +17 -0
- package/docs/themes/theme-colored.scss +17 -0
- package/docs/themes/theme-default-fallbacks.scss +17 -0
- package/docs/themes/theme-default.scss +17 -0
- package/jsconfig.json +4 -2
- package/package.json +40 -27
- package/scripts/deploy-docs.sh +9 -0
- package/templates/index.eta +2 -0
- package/utils/function.js +3 -0
- package/webpack.config.cjs +257 -0
- package/_spec.scss +0 -27
- package/_theme.scss +0 -27
- package/components/list/expander.js +0 -142
- package/components/list/itemgroup.js +0 -22
- package/core/theme/_builder.scss +0 -116
- package/core/theme/index.scss +0 -68
- package/docs/appbar.html +0 -1
- package/docs/appbar.min.js +0 -2
- package/docs/appbar.min.js.map +0 -1
- package/docs/bottomnav.html +0 -1
- package/docs/bottomnav.min.js +0 -2
- package/docs/bottomnav.min.js.map +0 -1
- package/docs/button.html +0 -1
- package/docs/button.min.js +0 -2
- package/docs/button.min.js.map +0 -1
- package/docs/card.html +0 -1
- package/docs/card.min.js +0 -2
- package/docs/card.min.js.map +0 -1
- package/docs/chip.html +0 -1
- package/docs/chip.min.js +0 -2
- package/docs/chip.min.js.map +0 -1
- package/docs/color.html +0 -1
- package/docs/color.min.js +0 -2
- package/docs/color.min.js.map +0 -1
- package/docs/datatable.html +0 -1
- package/docs/datatable.min.js +0 -2
- package/docs/datatable.min.js.map +0 -1
- package/docs/default.common.min.js +0 -2
- package/docs/default.common.min.js.map +0 -1
- package/docs/dialog.html +0 -1
- package/docs/dialog.min.js +0 -2
- package/docs/dialog.min.js.map +0 -1
- package/docs/docs.min.css +0 -1
- package/docs/docs.min.js +0 -2
- package/docs/docs.min.js.map +0 -1
- package/docs/elevation.html +0 -1
- package/docs/elevation.min.js +0 -2
- package/docs/elevation.min.js.map +0 -1
- package/docs/fab.html +0 -1
- package/docs/fab.min.js +0 -2
- package/docs/fab.min.js.map +0 -1
- package/docs/grid.html +0 -1
- package/docs/grid.min.js +0 -2
- package/docs/grid.min.js.map +0 -1
- package/docs/index.html +0 -1
- package/docs/index.min.js +0 -2
- package/docs/index.min.js.map +0 -1
- package/docs/ink.html +0 -1
- package/docs/ink.min.js +0 -2
- package/docs/ink.min.js.map +0 -1
- package/docs/layout.html +0 -1
- package/docs/layout.min.js +0 -2
- package/docs/layout.min.js.map +0 -1
- package/docs/list.html +0 -1
- package/docs/list.min.js +0 -2
- package/docs/list.min.js.map +0 -1
- package/docs/menu.html +0 -1
- package/docs/menu.min.js +0 -2
- package/docs/menu.min.js.map +0 -1
- package/docs/overlay.html +0 -1
- package/docs/overlay.min.js +0 -2
- package/docs/overlay.min.js.map +0 -1
- package/docs/prerender.common.min.js +0 -2
- package/docs/prerender.common.min.js.map +0 -1
- package/docs/prerender.min.js +0 -2
- package/docs/prerender.min.js.map +0 -1
- package/docs/progress.html +0 -1
- package/docs/progress.min.js +0 -2
- package/docs/progress.min.js.map +0 -1
- package/docs/pwa-prerender.min.js +0 -2
- package/docs/pwa-prerender.min.js.map +0 -1
- package/docs/pwa.html +0 -11
- package/docs/pwa.min.css +0 -1
- package/docs/pwa.min.js +0 -2
- package/docs/pwa.min.js.map +0 -1
- package/docs/ripple.html +0 -1
- package/docs/ripple.min.js +0 -2
- package/docs/ripple.min.js.map +0 -1
- package/docs/search.html +0 -1
- package/docs/search.min.js +0 -2
- package/docs/search.min.js.map +0 -1
- package/docs/selection.html +0 -1
- package/docs/selection.min.js +0 -2
- package/docs/selection.min.js.map +0 -1
- package/docs/slider.html +0 -1
- package/docs/slider.min.js +0 -2
- package/docs/slider.min.js.map +0 -1
- package/docs/snackbar.html +0 -1
- package/docs/snackbar.min.js +0 -2
- package/docs/snackbar.min.js.map +0 -1
- package/docs/spec.min.css +0 -1
- package/docs/spec.min.js +0 -2
- package/docs/spec.min.js.map +0 -1
- package/docs/surface.html +0 -1
- package/docs/surface.min.js +0 -2
- package/docs/surface.min.js.map +0 -1
- package/docs/tab.html +0 -1
- package/docs/tab.min.js +0 -2
- package/docs/tab.min.js.map +0 -1
- package/docs/textfield.html +0 -2
- package/docs/textfield.min.js +0 -2
- package/docs/textfield.min.js.map +0 -1
- package/docs/theme-colored-fallbacks.min.css +0 -1
- package/docs/theme-colored-fallbacks.min.js +0 -2
- package/docs/theme-colored-fallbacks.min.js.map +0 -1
- package/docs/theme-colored.min.css +0 -1
- package/docs/theme-colored.min.js +0 -2
- package/docs/theme-colored.min.js.map +0 -1
- package/docs/theme-default-fallbacks.min.css +0 -1
- package/docs/theme-default-fallbacks.min.js +0 -2
- package/docs/theme-default-fallbacks.min.js.map +0 -1
- package/docs/theme-default.min.css +0 -1
- package/docs/theme-default.min.js +0 -2
- package/docs/theme-default.min.js.map +0 -1
- package/docs/themes-fallbacks.min.css +0 -1
- package/docs/themes-fallbacks.min.js +0 -2
- package/docs/themes-fallbacks.min.js.map +0 -1
- package/docs/themes.min.css +0 -1
- package/docs/themes.min.js +0 -2
- package/docs/themes.min.js.map +0 -1
- package/docs/tooltip.html +0 -1
- package/docs/tooltip.min.js +0 -2
- package/docs/tooltip.min.js.map +0 -1
- package/docs/transition.html +0 -1
- package/docs/transition.min.js +0 -2
- package/docs/transition.min.js.map +0 -1
- package/docs/type.html +0 -1
- package/docs/type.min.js +0 -2
- package/docs/type.min.js.map +0 -1
- package/docs-src/components/datatable.pug +0 -327
- package/docs-src/components/selection.js +0 -9
- package/docs-src/components/selection.pug +0 -77
- package/docs-src/core/color.pug +0 -201
- package/docs-src/core/overlay.js +0 -4
- package/docs-src/core/ripple.js +0 -4
- package/docs-src/index.pug +0 -9
- package/docs-src/pwa/_dialogs.pug +0 -15
- package/docs-src/pwa/pwa-prerender.js +0 -3
- package/docs-src/pwa/pwa.js +0 -182
- package/docs-src/pwa/pwa.scss +0 -25
- package/docs-src/spec.scss +0 -1
- package/docs-src/themes/theme-colored-fallbacks.scss +0 -14
- package/docs-src/themes/theme-colored.scss +0 -14
- package/docs-src/themes/theme-default-fallbacks.scss +0 -14
- package/docs-src/themes/theme-default.scss +0 -14
- package/index.js +0 -51
- package/index.scss +0 -2
- package/webpack.config.js +0 -187
package/adapters/dom/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { getPassiveEventListenerOption } from '../../core/dom.js';
|
|
2
|
+
|
|
1
3
|
/** @return {HTMLElement} */
|
|
2
|
-
function
|
|
4
|
+
function AnyDomAdapterCreator() {
|
|
3
5
|
return document.createElement('div');
|
|
4
6
|
}
|
|
5
7
|
|
|
@@ -8,7 +10,7 @@ function AnyDomAdapterCreatorFn() {
|
|
|
8
10
|
* @param {any} data
|
|
9
11
|
* @return {void}
|
|
10
12
|
*/
|
|
11
|
-
function
|
|
13
|
+
function AnyDomAdapterRenderer(element, data) {
|
|
12
14
|
let s = '';
|
|
13
15
|
if (data != null) {
|
|
14
16
|
if (data.toString) {
|
|
@@ -24,120 +26,572 @@ function AnyDomAdapterRendererFn(element, data) {
|
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
/**
|
|
30
|
+
* @typedef {Object} DomAdapterRecycleOptions
|
|
31
|
+
* @prop {HTMLElement} scroller Scrolling container element
|
|
32
|
+
* @prop {boolean} [equalSize=false] All elements are equally sized
|
|
33
|
+
* @prop {boolean} [block=false] All elements are block-like
|
|
34
|
+
* @prop {boolean} [fastMeasure=false] Use integer precision for layout
|
|
35
|
+
* @prop {boolean} [deferRender=false] Render on scroll idle
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @template T1
|
|
40
|
+
* @template {HTMLElement} T2
|
|
41
|
+
* @typedef {Object} DomAdapterCreateOptions
|
|
42
|
+
* @prop {HTMLElement} element
|
|
43
|
+
* @prop {Array<T1>} datasource
|
|
44
|
+
* @prop {DomAdapterRecycleOptions} [recycle]
|
|
45
|
+
* @prop {function(T1):T2} [create={function(T1):HTMLElement}]
|
|
46
|
+
* @prop {function(T2, T1, number):void} [render={function(HTMLElement,T1):void}]
|
|
47
|
+
*/
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @typedef {Object} DomAdapterBounds
|
|
51
|
+
* @prop {number} top
|
|
52
|
+
* @prop {number=} right
|
|
53
|
+
* @prop {number=} bottom
|
|
54
|
+
* @prop {number=} left
|
|
55
|
+
* @prop {number=} height
|
|
56
|
+
* @prop {number=} width
|
|
57
|
+
*/
|
|
58
|
+
|
|
27
59
|
/**
|
|
28
60
|
* @template T1
|
|
29
61
|
* @template {HTMLElement} T2
|
|
30
62
|
*/
|
|
31
63
|
export default class DomAdapter {
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* @param {function():T2=} createFn
|
|
37
|
-
*/
|
|
38
|
-
constructor(element, datasource, renderFn, createFn) {
|
|
39
|
-
this.element = element;
|
|
40
|
-
this.datasource = datasource;
|
|
64
|
+
/** @param {DomAdapterCreateOptions<T1, T2>} options */
|
|
65
|
+
constructor(options) {
|
|
66
|
+
this.element = options.element;
|
|
67
|
+
this.datasource = options.datasource;
|
|
41
68
|
/** @type {Map<T1, T2>} */
|
|
42
|
-
this.
|
|
69
|
+
this.dataElementMap = new Map();
|
|
43
70
|
/** @type {WeakMap<T2, T1>} */
|
|
44
|
-
this.
|
|
45
|
-
|
|
46
|
-
this.
|
|
71
|
+
this.elementDataMap = new WeakMap();
|
|
72
|
+
/** @type {WeakMap<any, DomAdapterBounds>} */
|
|
73
|
+
this.dataBoundsMap = new WeakMap();
|
|
74
|
+
this.create = options.create || AnyDomAdapterCreator;
|
|
75
|
+
this.render = options.render || AnyDomAdapterRenderer;
|
|
76
|
+
this.onScrollerScrollListener = () => this.onScrollerScroll();
|
|
77
|
+
this.setupRecycleOptions(options.recycle);
|
|
47
78
|
}
|
|
48
79
|
|
|
49
|
-
/**
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.
|
|
62
|
-
}
|
|
80
|
+
/**
|
|
81
|
+
* @param {DomAdapterRecycleOptions} recycleOptions
|
|
82
|
+
* @return {void}
|
|
83
|
+
*/
|
|
84
|
+
setupRecycleOptions(recycleOptions) {
|
|
85
|
+
this.recycle = recycleOptions;
|
|
86
|
+
if (!this.recycle) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this.recycle.scroller.addEventListener('scroll', this.onScrollerScrollListener, getPassiveEventListenerOption());
|
|
90
|
+
const scrollerStyle = window.getComputedStyle(this.recycle.scroller);
|
|
91
|
+
if (scrollerStyle.position === 'static') {
|
|
92
|
+
this.recycle.scroller.style.setProperty('position', 'relative');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
onScrollerScroll() {
|
|
97
|
+
this.drawViewport(false);
|
|
98
|
+
if (this.deferRenderDebounce) {
|
|
99
|
+
clearTimeout(this.deferRenderDebounce);
|
|
100
|
+
this.deferRenderDebounce = null;
|
|
101
|
+
}
|
|
102
|
+
if (this.recycle && this.recycle.deferRender) {
|
|
103
|
+
this.deferRenderDebounce = setTimeout(() => {
|
|
104
|
+
this.drawViewport(true);
|
|
105
|
+
}, 50);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* @param {boolean} [checkForRemovedItems=true]
|
|
111
|
+
* @return {void}
|
|
112
|
+
*/
|
|
113
|
+
refresh(checkForRemovedItems = true) {
|
|
114
|
+
if (checkForRemovedItems) {
|
|
115
|
+
/** @type {T1[]} */
|
|
116
|
+
const unlinkedDataItems = [];
|
|
117
|
+
/** @type {T2[]} */
|
|
118
|
+
const orphanedElements = [];
|
|
119
|
+
this.dataElementMap.forEach((element, data) => {
|
|
120
|
+
if (this.datasource.indexOf(data) === -1) {
|
|
121
|
+
unlinkedDataItems.push(data);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
for (let i = this.element.children.length - 1; i >= 0; i -= 1) {
|
|
125
|
+
/** @type {T2} */
|
|
126
|
+
const child = (this.element.children.item(i));
|
|
127
|
+
const data = this.elementDataMap.get(child);
|
|
128
|
+
if (data && this.datasource.indexOf(data) === -1) {
|
|
129
|
+
orphanedElements.push(child);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
unlinkedDataItems.forEach((data) => {
|
|
133
|
+
this.removeItem(data);
|
|
134
|
+
});
|
|
135
|
+
orphanedElements.forEach((el) => {
|
|
136
|
+
this.removeElement(el);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
if (this.recycle) {
|
|
140
|
+
this.element.style.removeProperty('box-sizing');
|
|
141
|
+
this.element.style.removeProperty('padding-top');
|
|
142
|
+
this.element.style.removeProperty('padding-bottom');
|
|
143
|
+
this.element.style.removeProperty('height');
|
|
144
|
+
this.clear();
|
|
145
|
+
this.drawViewport(true);
|
|
146
|
+
} else {
|
|
147
|
+
this.datasource.forEach((data) => {
|
|
148
|
+
this.refreshItem(data);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
63
151
|
}
|
|
64
152
|
|
|
65
153
|
/** @return {void} */
|
|
66
154
|
clear() {
|
|
67
|
-
this.
|
|
68
|
-
this.
|
|
155
|
+
this.maxBottomBounds = 0;
|
|
156
|
+
this.dataElementMap.clear();
|
|
157
|
+
this.dataBoundsMap = new WeakMap();
|
|
158
|
+
this.elementDataMap = new WeakMap();
|
|
69
159
|
while (this.element.lastChild) {
|
|
70
160
|
this.element.removeChild(this.element.lastChild);
|
|
71
161
|
}
|
|
72
162
|
}
|
|
73
163
|
|
|
74
164
|
/**
|
|
75
|
-
* @param {
|
|
76
|
-
* @param {boolean} [checkPosition=true]
|
|
165
|
+
* @param {boolean} [idle=true]
|
|
77
166
|
* @return {void}
|
|
78
167
|
*/
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (index === -1) {
|
|
82
|
-
this.removeItem(data);
|
|
168
|
+
drawViewport(idle = true) {
|
|
169
|
+
if (!this.recycle || !this.recycle.scroller) {
|
|
83
170
|
return;
|
|
84
171
|
}
|
|
85
|
-
|
|
86
|
-
let
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
172
|
+
const itemsToDraw = [];
|
|
173
|
+
let foundVisibleItem = false;
|
|
174
|
+
let expectedTop = null;
|
|
175
|
+
let paddingTopSet = false;
|
|
176
|
+
let lastBottom = 0;
|
|
177
|
+
const additionalPrerenderSize = (window.screen.height - this.recycle.scroller.clientHeight) / 2;
|
|
178
|
+
const viewportTop = this.recycle.scroller.scrollTop;
|
|
179
|
+
const viewportBottom = (this.recycle.scroller.scrollTop + this.recycle.scroller.offsetHeight);
|
|
180
|
+
const preRenderTop = viewportTop - additionalPrerenderSize;
|
|
181
|
+
const preRenderBottom = viewportBottom + additionalPrerenderSize;
|
|
182
|
+
for (let i = 0; i < this.datasource.length; i += 1) {
|
|
183
|
+
const data = this.datasource[i];
|
|
184
|
+
let dataBounds = this.getBounds(data, i);
|
|
185
|
+
let newBounds = false;
|
|
186
|
+
let element = null;
|
|
187
|
+
if (!dataBounds || dataBounds.top == null || dataBounds.bottom == null) {
|
|
188
|
+
if (!this.recycle.block && !paddingTopSet) {
|
|
189
|
+
if (expectedTop != null) {
|
|
190
|
+
this.element.style.setProperty('padding-top', `${expectedTop}px`);
|
|
191
|
+
} else {
|
|
192
|
+
this.element.style.setProperty('padding-top', `${lastBottom}px`);
|
|
193
|
+
}
|
|
194
|
+
paddingTopSet = true;
|
|
195
|
+
}
|
|
196
|
+
element = this.refreshItem(data, {
|
|
197
|
+
create: true,
|
|
198
|
+
render: !this.recycle.deferRender,
|
|
199
|
+
invalidate: false,
|
|
200
|
+
});
|
|
201
|
+
dataBounds = this.storeBoundsCache(data, element);
|
|
202
|
+
newBounds = true;
|
|
203
|
+
}
|
|
204
|
+
lastBottom = dataBounds.bottom;
|
|
205
|
+
const isBottomInPrerender = (dataBounds.bottom >= preRenderTop
|
|
206
|
+
&& dataBounds.bottom <= preRenderBottom);
|
|
207
|
+
const isTopInPrerender = (dataBounds.top >= preRenderTop
|
|
208
|
+
&& dataBounds.top <= preRenderBottom);
|
|
209
|
+
if (isBottomInPrerender || isTopInPrerender) {
|
|
210
|
+
if (expectedTop == null) {
|
|
211
|
+
expectedTop = dataBounds.top;
|
|
212
|
+
}
|
|
213
|
+
itemsToDraw.push({
|
|
214
|
+
data,
|
|
215
|
+
index: i,
|
|
216
|
+
});
|
|
217
|
+
if (!foundVisibleItem) {
|
|
218
|
+
const isBottomVisible = (dataBounds.bottom >= viewportTop
|
|
219
|
+
&& dataBounds.bottom <= viewportBottom);
|
|
220
|
+
const isTopVisible = (dataBounds.top >= viewportTop
|
|
221
|
+
&& dataBounds.top <= viewportBottom);
|
|
222
|
+
foundVisibleItem = (isBottomVisible || isTopVisible);
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
if (!element && !paddingTopSet) {
|
|
226
|
+
element = this.dataElementMap.get(data);
|
|
227
|
+
if (element && element.parentElement) {
|
|
228
|
+
this.removeElement(element);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (foundVisibleItem) {
|
|
232
|
+
if (newBounds) {
|
|
233
|
+
this.dataBoundsMap.delete(data);
|
|
234
|
+
}
|
|
100
235
|
break;
|
|
101
236
|
}
|
|
102
|
-
sibling = sibling.nextSibling;
|
|
103
237
|
}
|
|
104
238
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
239
|
+
const renderedElements = [];
|
|
240
|
+
let newPaddingTop = 0;
|
|
241
|
+
let lastRenderedBounds;
|
|
242
|
+
for (let i = 0; i < itemsToDraw.length; i += 1) {
|
|
243
|
+
const item = itemsToDraw[i];
|
|
244
|
+
let element = this.dataElementMap.get(item.data);
|
|
245
|
+
|
|
246
|
+
if (!element) {
|
|
247
|
+
element = this.refreshItem(item.data, {
|
|
248
|
+
create: true,
|
|
249
|
+
render: (this.recycle.deferRender ? idle : true),
|
|
250
|
+
invalidate: false,
|
|
251
|
+
});
|
|
252
|
+
} else if (this.recycle.deferRender && idle) {
|
|
253
|
+
this.render(element, item.data, item.index);
|
|
254
|
+
}
|
|
255
|
+
const cachedBounds = this.getBounds(item.data);
|
|
256
|
+
if (i === 0 && !this.recycle.block) {
|
|
257
|
+
newPaddingTop = cachedBounds.top;
|
|
258
|
+
}
|
|
259
|
+
if (i === itemsToDraw.length - 1) {
|
|
260
|
+
lastRenderedBounds = cachedBounds;
|
|
261
|
+
}
|
|
262
|
+
renderedElements.push(element);
|
|
108
263
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.
|
|
264
|
+
for (let i = this.element.children.length - 1; i >= 0; i -= 1) {
|
|
265
|
+
/** @type {T2} */
|
|
266
|
+
const child = (this.element.children.item(i));
|
|
267
|
+
if (renderedElements.indexOf(child) === -1) {
|
|
268
|
+
this.removeElement(child);
|
|
269
|
+
}
|
|
112
270
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
271
|
+
this.element.style.setProperty('padding-top', `${newPaddingTop}px`);
|
|
272
|
+
const lastItem = this.datasource[this.datasource.length - 1];
|
|
273
|
+
const lastItemBounds = this.dataBoundsMap.get(lastItem);
|
|
274
|
+
|
|
275
|
+
if (lastItemBounds) {
|
|
276
|
+
this.element.style.setProperty('box-sizing', 'border-box');
|
|
277
|
+
this.element.style.setProperty('height', `${lastItemBounds.bottom}px`);
|
|
278
|
+
this.element.style.removeProperty('padding-bottom');
|
|
279
|
+
} else if (this.recycle.equalSize) {
|
|
280
|
+
this.element.style.setProperty('box-sizing', 'border-box');
|
|
281
|
+
this.element.style.setProperty('height', `${lastRenderedBounds.height * this.datasource.length}px`);
|
|
282
|
+
this.element.style.removeProperty('padding-bottom');
|
|
283
|
+
} else {
|
|
284
|
+
if (this.maxBottomBounds && lastRenderedBounds
|
|
285
|
+
&& lastRenderedBounds.bottom <= this.maxBottomBounds) {
|
|
286
|
+
this.maxBottomBounds = lastRenderedBounds.bottom;
|
|
120
287
|
}
|
|
121
|
-
|
|
122
|
-
|
|
288
|
+
const height = this.maxBottomBounds - newPaddingTop;
|
|
289
|
+
this.element.style.setProperty('box-sizing', 'content-box');
|
|
290
|
+
this.element.style.setProperty('height', `${height}px`);
|
|
291
|
+
this.element.style.setProperty('padding-bottom', `${64}px`);
|
|
123
292
|
}
|
|
124
|
-
this.element.appendChild(element);
|
|
125
293
|
}
|
|
126
294
|
|
|
127
295
|
/**
|
|
128
296
|
* @param {T1} data
|
|
129
|
-
* @
|
|
297
|
+
* @param {number} [indexHint]
|
|
298
|
+
* @return {DomAdapterBounds}
|
|
299
|
+
*/
|
|
300
|
+
getBounds(data, indexHint) {
|
|
301
|
+
const cached = this.dataBoundsMap.get(data);
|
|
302
|
+
if (cached) {
|
|
303
|
+
return cached;
|
|
304
|
+
}
|
|
305
|
+
let index = -1;
|
|
306
|
+
if (indexHint === -1 || indexHint == null) {
|
|
307
|
+
index = this.datasource.indexOf(data);
|
|
308
|
+
} else {
|
|
309
|
+
index = indexHint;
|
|
310
|
+
}
|
|
311
|
+
if (index === -1) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
let top = null;
|
|
315
|
+
if (index === 0) {
|
|
316
|
+
const cache = {
|
|
317
|
+
top: 0,
|
|
318
|
+
};
|
|
319
|
+
this.dataBoundsMap.set(data, cache);
|
|
320
|
+
return cache;
|
|
321
|
+
}
|
|
322
|
+
if (!this.recycle.block) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
let height = null;
|
|
326
|
+
const previousBounds = this.dataBoundsMap.get(this.datasource[index - 1]);
|
|
327
|
+
if (previousBounds && previousBounds.bottom) {
|
|
328
|
+
top = previousBounds.bottom;
|
|
329
|
+
} else if (this.recycle.equalSize) {
|
|
330
|
+
const firstBounds = this.dataBoundsMap.get(this.datasource[0]);
|
|
331
|
+
if (firstBounds && firstBounds.height) {
|
|
332
|
+
top = firstBounds.height * index;
|
|
333
|
+
// eslint-disable-next-line prefer-destructuring
|
|
334
|
+
height = firstBounds.height;
|
|
335
|
+
} else {
|
|
336
|
+
return null;
|
|
337
|
+
}
|
|
338
|
+
} else {
|
|
339
|
+
return null;
|
|
340
|
+
}
|
|
341
|
+
if (height == null) {
|
|
342
|
+
const cache = {
|
|
343
|
+
top,
|
|
344
|
+
};
|
|
345
|
+
this.dataBoundsMap.set(data, cache);
|
|
346
|
+
return cache;
|
|
347
|
+
}
|
|
348
|
+
const cache = {
|
|
349
|
+
top,
|
|
350
|
+
height,
|
|
351
|
+
bottom: top + height,
|
|
352
|
+
};
|
|
353
|
+
this.dataBoundsMap.set(data, cache);
|
|
354
|
+
return cache;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* @param {T2} element
|
|
359
|
+
* @return {DomAdapterBounds} bounds
|
|
130
360
|
*/
|
|
131
|
-
|
|
132
|
-
|
|
361
|
+
measureElementBounds(element) {
|
|
362
|
+
if (this.recycle.fastMeasure) {
|
|
363
|
+
return {
|
|
364
|
+
top: element.offsetTop,
|
|
365
|
+
right: element.offsetWidth + element.offsetLeft,
|
|
366
|
+
bottom: element.offsetHeight + element.offsetTop,
|
|
367
|
+
left: element.offsetLeft,
|
|
368
|
+
height: element.clientHeight,
|
|
369
|
+
width: element.clientWidth,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
const offsetParentRect = element.offsetParent.getBoundingClientRect();
|
|
373
|
+
const elementRect = element.getBoundingClientRect();
|
|
374
|
+
const top = elementRect.top - offsetParentRect.top + element.offsetParent.scrollTop;
|
|
375
|
+
const left = elementRect.left - offsetParentRect.left + element.offsetParent.scrollLeft;
|
|
376
|
+
return {
|
|
377
|
+
top,
|
|
378
|
+
right: elementRect.width + left,
|
|
379
|
+
bottom: elementRect.height + top,
|
|
380
|
+
left,
|
|
381
|
+
height: elementRect.height,
|
|
382
|
+
width: elementRect.width,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* @param {T1} data
|
|
388
|
+
* @param {T2} element
|
|
389
|
+
* @return {DomAdapterBounds} bounds
|
|
390
|
+
*/
|
|
391
|
+
storeBoundsCache(data, element) {
|
|
392
|
+
if (!this.recycle) {
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
const cache = this.measureElementBounds(element);
|
|
396
|
+
this.dataBoundsMap.set(data, cache);
|
|
397
|
+
return cache;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
invalidateAll() {
|
|
401
|
+
/** @type {WeakMap<any, DomAdapterBounds>} */
|
|
402
|
+
this.dataBoundsMap = new WeakMap();
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* @param {T1} data
|
|
407
|
+
* @param {Object} [options]
|
|
408
|
+
* @param {boolean} [options.checkPosition=true]
|
|
409
|
+
* @param {boolean} [options.create] Automatic
|
|
410
|
+
* @param {boolean} [options.render] Automatic based on deferRender
|
|
411
|
+
* @param {boolean} [options.invalidate] Automatic
|
|
412
|
+
* @return {T2} element
|
|
413
|
+
*/
|
|
414
|
+
refreshItem(data, options = {}) {
|
|
415
|
+
const dataIndex = this.datasource.indexOf(data);
|
|
416
|
+
if (dataIndex === -1) {
|
|
417
|
+
// Item has been removed
|
|
418
|
+
this.removeItem(data);
|
|
419
|
+
return null;
|
|
420
|
+
}
|
|
421
|
+
let elementIndex = -1;
|
|
422
|
+
let element = this.dataElementMap.get(data);
|
|
423
|
+
let invalidate = false;
|
|
424
|
+
if (element && this.recycle && this.recycle.deferRender && options.invalidate === true) {
|
|
425
|
+
// Deferred Render has a forced invalidation
|
|
426
|
+
// Item should be recreated
|
|
427
|
+
this.removeElement(element);
|
|
428
|
+
element = null;
|
|
429
|
+
}
|
|
133
430
|
if (!element) {
|
|
134
|
-
|
|
431
|
+
// Element does not exist, assume size changed
|
|
432
|
+
invalidate = true;
|
|
433
|
+
/** @type {T2} */
|
|
434
|
+
element = (this.create(data));
|
|
435
|
+
this.dataElementMap.set(data, element);
|
|
436
|
+
this.elementDataMap.set(element, data);
|
|
437
|
+
}
|
|
438
|
+
if (element && this.recycle && this.recycle.block) {
|
|
439
|
+
const bounds = this.getBounds(data, dataIndex);
|
|
440
|
+
element.style.setProperty('position', 'absolute');
|
|
441
|
+
element.style.setProperty('left', '0');
|
|
442
|
+
element.style.setProperty('right', '0');
|
|
443
|
+
if (bounds) {
|
|
444
|
+
element.style.setProperty('top', `${bounds.top}px`);
|
|
445
|
+
} else {
|
|
446
|
+
this.removeElement(element);
|
|
447
|
+
element = null;
|
|
448
|
+
invalidate = true;
|
|
449
|
+
}
|
|
135
450
|
}
|
|
451
|
+
if (element && options.checkPosition === false) {
|
|
452
|
+
if (!element.parentElement) {
|
|
453
|
+
this.element.appendChild(element);
|
|
454
|
+
}
|
|
455
|
+
} else if (element) {
|
|
456
|
+
if (element.parentElement === this.element) {
|
|
457
|
+
// Element is in DOM
|
|
458
|
+
let sibling = this.element.firstElementChild;
|
|
459
|
+
let siblingIndex = -1;
|
|
460
|
+
while (sibling) {
|
|
461
|
+
siblingIndex += 1;
|
|
462
|
+
if (sibling === element) {
|
|
463
|
+
elementIndex = siblingIndex;
|
|
464
|
+
break;
|
|
465
|
+
}
|
|
466
|
+
sibling = sibling.nextElementSibling;
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if (elementIndex !== dataIndex) {
|
|
470
|
+
if (!this.element.children.length) {
|
|
471
|
+
if (element.parentElement) {
|
|
472
|
+
element.parentElement.removeChild(element);
|
|
473
|
+
}
|
|
474
|
+
this.element.appendChild(element);
|
|
475
|
+
} else {
|
|
476
|
+
// Iterate through datasource to previous sibling element
|
|
477
|
+
let siblingIndex = dataIndex - 1;
|
|
478
|
+
let inserted = false;
|
|
479
|
+
let previousDataObject;
|
|
480
|
+
do {
|
|
481
|
+
previousDataObject = this.datasource[siblingIndex];
|
|
482
|
+
const previousElement = this.dataElementMap.get(previousDataObject);
|
|
483
|
+
if (previousElement) {
|
|
484
|
+
if (element.previousElementSibling !== previousElement) {
|
|
485
|
+
if (element.parentElement) {
|
|
486
|
+
element.parentElement.removeChild(element);
|
|
487
|
+
}
|
|
488
|
+
previousElement.insertAdjacentElement('afterend', element);
|
|
489
|
+
}
|
|
490
|
+
inserted = true;
|
|
491
|
+
} else {
|
|
492
|
+
siblingIndex -= 1;
|
|
493
|
+
}
|
|
494
|
+
} while (previousDataObject && !inserted);
|
|
495
|
+
if (!inserted) {
|
|
496
|
+
if (element.parentElement) {
|
|
497
|
+
element.parentElement.removeChild(element);
|
|
498
|
+
}
|
|
499
|
+
this.element.insertBefore(element, this.element.firstElementChild);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
if ((options.render === false)
|
|
505
|
+
|| (options.render !== true && this.recycle && this.recycle.deferRender)) {
|
|
506
|
+
invalidate = true;
|
|
507
|
+
} else if (element
|
|
508
|
+
&& (options.render === true || (!this.recycle || !this.recycle.deferRender))) {
|
|
509
|
+
let prevClientWidth;
|
|
510
|
+
let prevClientHeight;
|
|
511
|
+
if (!invalidate && options.invalidate !== false) {
|
|
512
|
+
// Store width and height for later comparison
|
|
513
|
+
prevClientWidth = element.clientWidth;
|
|
514
|
+
prevClientHeight = element.clientHeight;
|
|
515
|
+
}
|
|
516
|
+
this.render(element, data, dataIndex);
|
|
517
|
+
if (!invalidate && options.invalidate !== false) {
|
|
518
|
+
if (element.clientWidth !== prevClientWidth || element.clientHeight !== prevClientHeight) {
|
|
519
|
+
// Element width or height has changed
|
|
520
|
+
invalidate = true;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (options.invalidate === true || (invalidate && options.invalidate !== false)) {
|
|
525
|
+
this.invalidateItem(data, dataIndex);
|
|
526
|
+
}
|
|
527
|
+
return element;
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* @param {T2} element
|
|
532
|
+
* @return {void}
|
|
533
|
+
*/
|
|
534
|
+
removeElement(element) {
|
|
136
535
|
if (element.parentElement) {
|
|
137
536
|
element.parentElement.removeChild(element);
|
|
138
537
|
}
|
|
139
|
-
this.
|
|
140
|
-
|
|
538
|
+
const data = this.elementDataMap.get(element);
|
|
539
|
+
if (data) {
|
|
540
|
+
this.dataElementMap.delete(data);
|
|
541
|
+
}
|
|
542
|
+
this.elementDataMap.delete(element);
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* @param {T1} data
|
|
547
|
+
* @param {number} [indexHint]
|
|
548
|
+
* @return {boolean} change
|
|
549
|
+
*/
|
|
550
|
+
invalidateItem(data, indexHint) {
|
|
551
|
+
if (!this.recycle || this.recycle.equalSize) {
|
|
552
|
+
return false;
|
|
553
|
+
}
|
|
554
|
+
// Don't auto-create on non-block layouts
|
|
555
|
+
// Invalidate in case of size change
|
|
556
|
+
const currentBounds = this.dataBoundsMap.get(data);
|
|
557
|
+
if (!currentBounds) {
|
|
558
|
+
return false;
|
|
559
|
+
}
|
|
560
|
+
this.dataBoundsMap.delete(data);
|
|
561
|
+
const dataIndex = (indexHint != null ? indexHint : this.datasource.indexOf(data));
|
|
562
|
+
if (dataIndex === -1) {
|
|
563
|
+
// Item was removed
|
|
564
|
+
return true;
|
|
565
|
+
}
|
|
566
|
+
// Invalidate previous items at same Y position
|
|
567
|
+
for (let j = dataIndex - 1; j >= 0; j -= 1) {
|
|
568
|
+
const previousBounds = this.dataBoundsMap.get(this.datasource[j]);
|
|
569
|
+
if (!previousBounds || previousBounds.top < currentBounds.top) {
|
|
570
|
+
break;
|
|
571
|
+
}
|
|
572
|
+
this.dataBoundsMap.delete(this.datasource[j]);
|
|
573
|
+
}
|
|
574
|
+
// Invalidate next items
|
|
575
|
+
for (let j = dataIndex + 1; j < this.datasource.length; j += 1) {
|
|
576
|
+
if (!this.dataBoundsMap.delete(this.datasource[j])) {
|
|
577
|
+
break;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return true;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
/**
|
|
584
|
+
* @param {T1} data
|
|
585
|
+
* @param {number} [previousIndex]
|
|
586
|
+
* @return {void}
|
|
587
|
+
*/
|
|
588
|
+
removeItem(data, previousIndex) {
|
|
589
|
+
this.invalidateItem(data, previousIndex);
|
|
590
|
+
this.dataElementMap.delete(data);
|
|
591
|
+
const element = this.dataElementMap.get(data);
|
|
592
|
+
if (element) {
|
|
593
|
+
this.removeElement(element);
|
|
594
|
+
}
|
|
141
595
|
}
|
|
142
596
|
|
|
143
597
|
detach() {
|