From a5365d829219677b66667c40099102becc7a3644 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tu=C4=9F=C3=A7e=20K=C3=BC=C3=A7=C3=BCko=C4=9Flu?= Date: Fri, 16 Jul 2021 12:39:45 +0300 Subject: [PATCH] Fixed #692 - VirtualScroller Component --- api-generator/components/virtualscroller.js | 124 +++ src/assets/menu/menu.json | 5 + .../virtualscroller/VirtualScroller.d.ts | 27 + .../virtualscroller/VirtualScroller.vue | 545 ++++++++++++ src/components/virtualscroller/package.json | 9 + src/main.js | 2 + src/router/index.js | 5 + src/views/liveeditor/LiveEditor.vue | 2 + .../virtualscroller/VirtualScrollerDemo.vue | 243 ++++++ .../virtualscroller/VirtualScrollerDoc.vue | 824 ++++++++++++++++++ 10 files changed, 1786 insertions(+) create mode 100644 api-generator/components/virtualscroller.js create mode 100644 src/components/virtualscroller/VirtualScroller.d.ts create mode 100644 src/components/virtualscroller/VirtualScroller.vue create mode 100644 src/components/virtualscroller/package.json create mode 100644 src/views/virtualscroller/VirtualScrollerDemo.vue create mode 100644 src/views/virtualscroller/VirtualScrollerDoc.vue diff --git a/api-generator/components/virtualscroller.js b/api-generator/components/virtualscroller.js new file mode 100644 index 000000000..143fd2f33 --- /dev/null +++ b/api-generator/components/virtualscroller.js @@ -0,0 +1,124 @@ +const VirtualScrollerProps = [ + { + name: "items", + type: "array", + default: "null", + description: "An array of objects to display." + }, + { + name: "itemSize", + type: "number|array", + default: "null", + description: "The height/width of item according to orientation." + }, + { + name: "scrollHeight", + type: "string", + default: "null", + description: "Height of the scroll viewport." + }, + { + name: "scrollWidth", + type: "string", + default: "null", + description: "Width of the scroll viewport." + }, + { + name: "orientation", + type: "string", + default: "vertical", + description: "The orientation of scrollbar, valid values are 'vertical', 'horizontal' and 'both'." + }, + { + name: "numToleratedItems", + type: "number", + default: "null", + description: "Determines how many additional elements to add to the DOM outside of the view. According to the scrolls made up and down, extra items are added in a certain algorithm in the form of multiples of this number. Default value is half the number of items shown in the view." + }, + { + name: "delay", + type: "number", + default: "0", + description: "Delay in scroll before new data is loaded." + }, + { + name: "lazy", + type: "boolean", + default: "false", + description: "Defines if data is loaded and interacted with in lazy manner." + }, + { + name: "showLoader", + type: "boolean", + default: "false", + description: "Whether to show loader." + }, + { + name: "style", + type: "any", + default: "null", + description: "Inline style of the component." + }, + { + name: "class", + type: "string", + default: "null", + description: "Style class of the component." + } +]; + +const VirtualScrollerEvents = [ + { + name: "scroll-index-change", + description: "Callback to invoke when scroll position and item's range in view changes.", + arguments: [ + { + name: "event.first", + type: "number", + description: "First index of the new data range to be loaded." + }, + { + name: "event.last", + type: "number", + description: "Last index of the new data range to be loaded." + } + ] + }, + { + name: "lazy-load", + description: "Callback to invoke in lazy mode to load new data.", + arguments: [ + { + name: "event.first", + type: "number", + description: "First index of the new data range to be loaded." + }, + { + name: "event.last", + type: "number", + description: "Last index of the new data range to be loaded." + } + ] + } +]; + +const VirtualScrollerSlots = [ + { + name: "item", + description: "Content for the item" + }, + { + name: "loader", + description: "Custom content for the loader items" + } +]; + +module.exports = { + virtualscroller: { + name: "VirtualScroller", + description: "VirtualScroller is a performant approach to handle huge data efficiently.", + props: VirtualScrollerProps, + events: VirtualScrollerEvents, + slots: VirtualScrollerSlots + } +}; \ No newline at end of file diff --git a/src/assets/menu/menu.json b/src/assets/menu/menu.json index bda582c81..096dafd16 100644 --- a/src/assets/menu/menu.json +++ b/src/assets/menu/menu.json @@ -406,6 +406,11 @@ "name": "DataView", "to": "/dataview" }, + { + "name": "VirtualScroller", + "to": "/virtualscroller", + "badge": "New" + }, { "name": "FilterService", "to": "/filterservice" diff --git a/src/components/virtualscroller/VirtualScroller.d.ts b/src/components/virtualscroller/VirtualScroller.d.ts new file mode 100644 index 000000000..dcebabbf0 --- /dev/null +++ b/src/components/virtualscroller/VirtualScroller.d.ts @@ -0,0 +1,27 @@ +import { VNode } from 'vue'; + +interface VirtualScrollerProps { + items?: any[]|any[][]; + itemSize?: number|any[]; + scrollHeight?: string; + scrollWidth?: string; + orientation?: string; + numToleratedItems?: number; + delay?: number; + lazy?: boolean; + showLoader?: boolean; + loading?: boolean; + style?: any; + class?: string; +} + +declare class VirtualScroller { + $props: VirtualScrollerProps; + $emit(eventName: 'update:numToleratedItems', value: number): this; + $emit(eventName: 'scroll-index-change', value: { first: number, last: number }): this; + $emit(eventName: 'lazy-load', value: { first: number, last: number }): this; + $slots: { + items: VNode[]; + loader: VNode[]; + } +} \ No newline at end of file diff --git a/src/components/virtualscroller/VirtualScroller.vue b/src/components/virtualscroller/VirtualScroller.vue new file mode 100644 index 000000000..e40b2cf31 --- /dev/null +++ b/src/components/virtualscroller/VirtualScroller.vue @@ -0,0 +1,545 @@ + + + + + \ No newline at end of file diff --git a/src/components/virtualscroller/package.json b/src/components/virtualscroller/package.json new file mode 100644 index 000000000..de1ab36fe --- /dev/null +++ b/src/components/virtualscroller/package.json @@ -0,0 +1,9 @@ +{ + "main": "./virtualscroller.cjs.js", + "module": "./virtualscroller.esm.js", + "unpkg": "./virtualscroller.min.js", + "types": "./VirtualScroller.d.ts", + "browser": { + "./sfc": "./VirtualScroller.vue" + } + } \ No newline at end of file diff --git a/src/main.js b/src/main.js index 442ed9f6b..d54f26d2c 100644 --- a/src/main.js +++ b/src/main.js @@ -94,6 +94,7 @@ import Toolbar from './components/toolbar/Toolbar'; import Tooltip from './components/tooltip/Tooltip'; import TriStateCheckbox from './components/tristatecheckbox/TriStateCheckbox'; import Galleria from './components/galleria/Galleria'; +import VirtualScroller from './components/virtualscroller/VirtualScroller'; import AppInputStyleSwitch from './AppInputStyleSwitch'; import AppDemoActions from './AppDemoActions'; @@ -210,6 +211,7 @@ app.component('TreeSelect', TreeSelect); app.component('TreeTable', TreeTable); app.component('TriStateCheckbox', TriStateCheckbox); app.component('Galleria', Galleria); +app.component('VirtualScroller', VirtualScroller); app.component('AppDemoActions', AppDemoActions); app.component('AppInputStyleSwitch', AppInputStyleSwitch); diff --git a/src/router/index.js b/src/router/index.js index 8084b977f..d07b45819 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -831,6 +831,11 @@ const routes = [ name: 'galleriaadvvanced', component: () => import('../views/galleria/GalleriaAdvancedDemo.vue') }, + { + path: '/virtualscroller', + name: 'virtualscroller', + component: () => import('../views/virtualscroller/VirtualScrollerDemo.vue') + }, { path: '/vuelidate', name: 'vuelidateform', diff --git a/src/views/liveeditor/LiveEditor.vue b/src/views/liveeditor/LiveEditor.vue index 276bc7298..ba0e903c7 100644 --- a/src/views/liveeditor/LiveEditor.vue +++ b/src/views/liveeditor/LiveEditor.vue @@ -490,6 +490,7 @@ import Tree from 'primevue/tree'; import TreeSelect from 'primevue/treeselect'; import TreeTable from 'primevue/treetable'; import TriStateCheckbox from 'primevue/tristatecheckbox'; +import VirtualScroller from 'primevue/virtualscroller'; ${extImport} const app = createApp(${name}); @@ -586,6 +587,7 @@ app.component('Tree', Tree); app.component('TreeSelect', TreeSelect); app.component('TreeTable', TreeTable); app.component('TriStateCheckbox', TriStateCheckbox); +app.component('VirtualScroller', VirtualScroller); ${extElement} app.mount("#app"); diff --git a/src/views/virtualscroller/VirtualScrollerDemo.vue b/src/views/virtualscroller/VirtualScrollerDemo.vue new file mode 100644 index 000000000..51d5b3d02 --- /dev/null +++ b/src/views/virtualscroller/VirtualScrollerDemo.vue @@ -0,0 +1,243 @@ + + + + + \ No newline at end of file diff --git a/src/views/virtualscroller/VirtualScrollerDoc.vue b/src/views/virtualscroller/VirtualScrollerDoc.vue new file mode 100644 index 000000000..7924ad70f --- /dev/null +++ b/src/views/virtualscroller/VirtualScrollerDoc.vue @@ -0,0 +1,824 @@ + + + \ No newline at end of file