feat: add responsive component (#704)

This commit is contained in:
pataar authored and GitHub committed 2022-03-07 18:44:30 +01:00
1 parent 0da05047a1
commit 8f96aba9d8
9 files changed
+154 -1

No files matched your search

+53
View File
@@ -26,9 +26,11 @@
"echarts": "^5.2.2",
"echarts-gl": "^2.0.8",
"js-sha256": "^0.9.0",
"lodash.throttle": "^4.1.1",
"overlayscrollbars": "^1.13.1",
"overlayscrollbars-vue": "^0.2.2",
"regenerator-runtime": "^0.13.9",
"resize-observer-polyfill": "^1.5.1",
"semver": "^7.3.5",
"uuid": "^8.3.2",
"vue": "^2.6.14",
@@ -47,6 +49,7 @@
"devDependencies": {
"@intlify/vite-plugin-vue-i18n": "^2.5.0",
"@mdi/js": "^6.5.95",
"@types/lodash.throttle": "^4.1.6",
"@types/semver": "^7.3.8",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^5.11.0",
@@ -2724,6 +2727,21 @@
"integrity": "sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==",
"dev": true
},
"node_modules/@types/lodash": {
"version": "4.14.179",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.179.tgz",
"integrity": "sha512-uwc1x90yCKqGcIOAT6DwOSuxnrAbpkdPsUOZtwrXb4D/6wZs+6qG7QnIawDuZWg0sWpxl+ltIKCaLoMlna678w==",
"dev": true
},
"node_modules/@types/lodash.throttle": {
"version": "4.1.6",
"resolved": "https://registry.npmjs.org/@types/lodash.throttle/-/lodash.throttle-4.1.6.tgz",
"integrity": "sha512-/UIH96i/sIRYGC60NoY72jGkCJtFN5KVPhEMMMTjol65effe1gPn0tycJqV5tlSwMTzX8FqzB5yAj0rfGHTPNg==",
"dev": true,
"dependencies": {
"@types/lodash": "*"
}
},
"node_modules/@types/node": {
"version": "16.11.26",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.26.tgz",
@@ -6917,6 +6935,11 @@
"integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=",
"dev": true
},
"node_modules/lodash.throttle": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz",
"integrity": "sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ="
},
"node_modules/log-symbols": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz",
@@ -7637,6 +7660,11 @@
"resolved": "https://registry.npmjs.org/resize-detector/-/resize-detector-0.3.0.tgz",
"integrity": "sha512-R/tCuvuOHQ8o2boRP6vgx8hXCCy87H1eY9V5imBYeVNyNVpuL9ciReSccLj2gDcax9+2weXy3bc8Vv+NRXeEvQ=="
},
"node_modules/resize-observer-polyfill": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz",
"integrity": "sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg=="
},
"node_modules/resolve": {
"version": "1.22.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz",
@@ -11435,6 +11463,21 @@
"integrity": "sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==",
"dev": true
},
"@types/lodash": {
"version": "4.14.179",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.179.tgz",
"integrity": "sha512-uwc1x90yCKqGcIOAT6DwOSuxnrAbpkdPsUOZtwrXb4D/6wZs+6qG7QnIawDuZWg0sWpxl+ltIKCaLoMlna678w==",
"dev": true
},
"@types/lodash.throttle": {
"version": "4.1.6",
"resolved": "https://registry.npmjs.org/@types/lodash.throttle/-/lodash.throttle-4.1.6.tgz",
"integrity": "sha512-/UIH96i/sIRYGC60NoY72jGkCJtFN5KVPhEMMMTjol65effe1gPn0tycJqV5tlSwMTzX8FqzB5yAj0rfGHTPNg==",
"dev": true,
"requires": {
"@types/lodash": "*"
}
},
"@types/node": {
"version": "16.11.26",
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.11.26.tgz",
@@ -14416,6 +14459,11 @@
"integrity": "sha1-7dFMgk4sycHgsKG0K7UhBRakJDg=",
"dev": true
},
"lodash.throttle": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz",
"integrity": "sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ="
},
"log-symbols": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz",
@@ -14953,6 +15001,11 @@
"resolved": "https://registry.npmjs.org/resize-detector/-/resize-detector-0.3.0.tgz",
"integrity": "sha512-R/tCuvuOHQ8o2boRP6vgx8hXCCy87H1eY9V5imBYeVNyNVpuL9ciReSccLj2gDcax9+2weXy3bc8Vv+NRXeEvQ=="
},
"resize-observer-polyfill": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/resize-observer-polyfill/-/resize-observer-polyfill-1.5.1.tgz",
"integrity": "sha512-LwZrotdHOo12nQuZlHEmtuXdqGoOD0OhaxopaNFxWzInpEgaLWoVuAMbTzixuosCx2nEG58ngzW3vxdWoxIgdg=="
},
"resolve": {
"version": "1.22.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz",
+3
View File
@@ -40,9 +40,11 @@
"echarts": "^5.2.2",
"echarts-gl": "^2.0.8",
"js-sha256": "^0.9.0",
"lodash.throttle": "^4.1.1",
"overlayscrollbars": "^1.13.1",
"overlayscrollbars-vue": "^0.2.2",
"regenerator-runtime": "^0.13.9",
"resize-observer-polyfill": "^1.5.1",
"semver": "^7.3.5",
"uuid": "^8.3.2",
"vue": "^2.6.14",
@@ -61,6 +63,7 @@
"devDependencies": {
"@intlify/vite-plugin-vue-i18n": "^2.5.0",
"@mdi/js": "^6.5.95",
"@types/lodash.throttle": "^4.1.6",
"@types/semver": "^7.3.8",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^5.11.0",
+48
View File
@@ -0,0 +1,48 @@
import Component from 'vue-class-component'
import BaseMixin from './base'
import { Prop } from 'vue-property-decorator'
import throttle from 'lodash.throttle'
export type ResponsiveElement = {
is: {
[key: string]: boolean
}
}
@Component
export default class ResponsiveMixin extends BaseMixin {
@Prop() protected declare breakpoints: {
[key: string]: (el: DOMRect) => boolean
}
observer?: ResizeObserver
el: ResponsiveElement = {
is: {},
}
mounted() {
if (this.breakpoints) {
this.$nextTick(() => {
this.observer = new ResizeObserver(throttle(this.onResize, 50))
if (this.$el instanceof Element) {
this.observer.observe(this.$el)
}
})
}
}
beforeDestroy() {
if (this.$el instanceof Element) {
this.observer?.unobserve(this.$el)
}
}
private onResize(entries: ResizeObserverEntry[]) {
const cr = entries[0].contentRect
const conds = this.breakpoints
for (const breakpoint in conds) {
this.$set(this.el.is, breakpoint, conds[breakpoint](cr))
}
}
}
@@ -561,6 +561,7 @@ import {
mdiPencil,
mdiDelete,
mdiCloseThick,
mdiClose,
} from '@mdi/js'
interface draggingFile {
@@ -609,6 +610,7 @@ export default class GcodefilesPanel extends Mixins(BaseMixin) {
mdiPlay = mdiPlay
mdiPlaylistPlus = mdiPlaylistPlus
mdiFire = mdiFire
mdiClose = mdiClose
mdiVideo3d = mdiVideo3d
mdiCloudDownload = mdiCloudDownload
mdiRenameBox = mdiRenameBox
+26
View File
@@ -0,0 +1,26 @@
<template>
<div>
<div v-if="!noHide && !init" style="visibility: hidden">
<slot :el="el"></slot>
</div>
<slot :el="el"></slot>
</div>
</template>
<script lang="ts">
import Component from 'vue-class-component'
import { Mixins, Prop } from 'vue-property-decorator'
import ResponsiveMixin from '@/components/mixins/responsive'
@Component
export default class Responsive extends Mixins(ResponsiveMixin) {
@Prop({ default: false }) protected declare noHide: boolean
init = false
mounted() {
this.init = true
}
}
</script>
File renamed without changes.
+16
View File
@@ -0,0 +1,16 @@
import throttle from 'lodash.throttle'
import Vue from 'vue'
Vue.directive('responsive-class', {
inserted(el, conds) {
const handleResize = throttle((entries: ResizeObserverEntry[]) => {
const cr = entries[0].contentRect
for (const breakpoint in conds.value) {
el.classList.toggle(breakpoint, conds.value[breakpoint](cr))
}
}, 50)
const observer = new ResizeObserver(handleResize)
observer.observe(el)
},
})
+5 -1
View File
@@ -1,10 +1,10 @@
import 'regenerator-runtime' // async polyfill used by the gcodeviewer
import 'resize-observer-polyfill' // polyfill needed by the responsive class detection
import Vue from 'vue'
import App from '@/App.vue'
import vuetify from '@/plugins/vuetify'
import i18n from '@/plugins/i18n'
import './plugins/longpress'
import store from '@/store'
import router from '@/plugins/router'
@@ -50,6 +50,10 @@ Vue.use(OverlayScrollbarsPlugin, {
},
})
// Directives
import './directives/longpress'
import './directives/responsive-class'
// Echarts
import ECharts from 'vue-echarts'
import { use } from 'echarts/core'
+1
View File
@@ -11,6 +11,7 @@
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"sourceMap": true,
"skipLibCheck": true,
"baseUrl": ".",
"types": [
"cypress",