Skip to content

Commit 3280621

Browse files
committed
fix(app-ext): use setup() function over render() function
1 parent 6362d9a commit 3280621

File tree

1 file changed

+92
-101
lines changed

1 file changed

+92
-101
lines changed

app-extension/src/component/QPdfviewer.js

Lines changed: 92 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -9,114 +9,105 @@
99
* https://v3.vuejs.org/guide/migration/render-function-api.html#render-function-argument
1010
*/
1111

12-
import { defineComponent, h } from "vue"
13-
import { useQuasar } from "quasar"
12+
import { defineComponent, h } from "vue"
1413

15-
export default defineComponent({
16-
name: "QPdfviewer",
14+
export default defineComponent({
15+
name: "QPdfviewer",
1716

18-
props: {
19-
src: String,
20-
type: {
21-
type: String,
22-
default: 'html5',
23-
validator: (v) => ['html5', 'pdfjs'].indexOf(v) !== -1
24-
},
25-
errorString: {
26-
type: String,
27-
default:
28-
"This browser does not support PDFs. Download the PDF to view it:"
29-
},
30-
contentStyle: [String, Object, Array],
31-
contentClass: [String, Object, Array],
32-
innerContentStyle: [String, Object, Array],
33-
innerContentClass: [String, Object, Array]
34-
},
17+
props: {
18+
src: String,
19+
type: {
20+
type: String,
21+
default: 'html5',
22+
validator: (v) => [ 'html5', 'pdfjs' ].indexOf(v) !== -1
23+
},
24+
errorString: {
25+
type: String,
26+
default:
27+
"This browser does not support PDFs. Download the PDF to view it:"
28+
},
29+
contentStyle: [ String, Object, Array ],
30+
contentClass: [ String, Object, Array ],
31+
innerContentStyle: [ String, Object, Array ],
32+
innerContentClass: [ String, Object, Array ]
33+
},
3534

36-
emits: [
37-
],
35+
emits: [
36+
],
3837

39-
data() {
40-
return {
41-
hashId: 'q-pdfviewer-' + Math.random().toString(36).substr(2, 9)
42-
}
43-
},
38+
// Use discrete render fnction
39+
setup (props) {
40+
const hashId = 'q-pdfviewer-' + Math.random().toString(36).substr(2, 9)
4441

45-
// Use discrete render fnction
46-
render(prop) {
47-
const $q = useQuasar()
42+
function __renderObject () {
43+
return h('object', {
44+
// Change to new format style for Vue3
45+
class: [props.innerContentClass],
46+
style: [props.innerContentStyle],
47+
id: hashId,
48+
data: props.src,
49+
type: 'application/pdf',
50+
width: '100%',
51+
height: '100%'
52+
}, [
53+
// browser object not supported, try iframe
54+
__renderIFrame()
55+
])
56+
}
4857

49-
function __renderObject () {
50-
return h('object', {
51-
// Change to new format style for Vue3
52-
class: [prop.innerContentClass],
53-
style: [prop.innerContentStyle],
54-
id: prop.hashId,
55-
data: prop.src,
56-
type: 'application/pdf',
57-
width: '100%',
58-
height: '100%'
59-
}, [
60-
// browser object not supported, try iframe
61-
__renderIFrame()
62-
])
63-
}
58+
function __renderIFrame () {
59+
return h('iframe', {
60+
// Change to new format style for Vue3
61+
class: ['q-pdfviewer__iframe'],
62+
src: props.src,
63+
width: '100%',
64+
height: '100%'
65+
}, [
66+
// iframe not supported either, give user a link to download
67+
__renderText()
68+
])
69+
}
6470

65-
function __renderIFrame () {
66-
return h('iframe', {
67-
// Change to new format style for Vue3
68-
class: ['q-pdfviewer__iframe'],
69-
src: prop.src,
70-
width: '100%',
71-
height: '100%'
72-
}, [
73-
// iframe not supported either, give user a link to download
74-
__renderText()
75-
])
76-
}
71+
function __renderIFramePDFJS () {
72+
return h('iframe', {
73+
// Change to new format style for Vue3
74+
class: ['q-pdfviewer__iframe'],
75+
src: '/pdfjs/web/viewer.html?file=' + encodeURIComponent(props.src),
76+
width: '100%',
77+
height: '100%'
78+
}, [
79+
// iframe not supported either, give user a link to download
80+
__renderText()
81+
])
82+
}
7783

78-
function __renderIFramePDFJS () {
79-
return h('iframe', {
80-
// Change to new format style for Vue3
81-
class: ['q-pdfviewer__iframe'],
82-
src: '/pdfjs/web/viewer.html?file=' + encodeURIComponent(prop.src),
83-
width: '100%',
84-
height: '100%'
85-
}, [
86-
// iframe not supported either, give user a link to download
87-
__renderText()
88-
])
89-
}
84+
function __renderText () {
85+
// Render a link to the PDF
86+
return h('a', {
87+
// Change to new format style for Vue3
88+
href: props.src,
89+
target: '_blank'
90+
})
91+
}
9092

91-
function __renderText () {
92-
// Render a link to the PDF
93-
return h('a', {
94-
// Change to new format style for Vue3
95-
href: prop.src,
96-
target: '_blank'
97-
})
98-
}
93+
function __renderPdf () {
94+
if (props.src !== void 0 && props.src.length > 0) {
95+
return h(
96+
"div",
97+
{
98+
// Change to new format style for Vue3
99+
class: [ "q-pdfviewer", props.contentClass ],
100+
style: [props.contentStyle],
101+
},
102+
[
103+
props.type === "pdfjs"
104+
? __renderIFramePDFJS(h)
105+
: __renderObject(h),
106+
]
107+
)
108+
}
109+
}
99110

100-
if (prop.src !== void 0 && prop.src.length > 0) {
101-
return h(
102-
"div",
103-
{
104-
// Change to new format style for Vue3
105-
class: ["q-pdfviewer", prop.contentClass],
106-
style: [prop.contentStyle],
107-
},
108-
[
109-
$q.platform.is.electron || prop.type === "pdfjs"
110-
? __renderIFramePDFJS(h)
111-
: __renderObject(h),
112-
]
113-
);
114-
}
115-
return '';
116-
},
117-
118-
setup() {
119-
return {
120-
}
121-
}
122-
})
111+
return () => __renderPdf()
112+
}
113+
})

0 commit comments

Comments
 (0)