Skip to content

Commit

Permalink
Run autoformatter
Browse files Browse the repository at this point in the history
  • Loading branch information
delphaber committed Mar 24, 2020
1 parent 6b3b515 commit 6a6901a
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
examples/
coverage/
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
examples/
coverage/
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"trailingComma": "all",
"trailingComma": "all"
}
8 changes: 4 additions & 4 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module.exports = {
presets: [
'@vue/babel-preset-jsx',
"@vue/babel-preset-jsx",
[
'@babel/preset-env',
"@babel/preset-env",
{
targets: {
node: 'current',
node: "current",
},
},
],
],
};
};
10 changes: 5 additions & 5 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ export default {
file: "bundle.js",
name: "VueDatoCms",
globals: {
"@znck/prop-types": "PropTypes"
}
"@znck/prop-types": "PropTypes",
},
},
external: ["@znck/prop-types"],
plugins: [
babel({
exclude: "node_modules/**",
runtimeHelpers: true
runtimeHelpers: true,
}),
commonjs()
]
commonjs(),
],
};
72 changes: 36 additions & 36 deletions src/Image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const absolutePositioning = {

// @vue/component
export const Image = {
inheritAttrs: false,
props: {
data: PropTypes.shape({
aspectRatio: PropTypes.number.isRequired,
Expand All @@ -33,11 +34,10 @@ export const Image = {
rootStyle: PropTypes.object.defaultValue(() => ({})),
explicitWidth: PropTypes.bool.defaultValue(false),
},
inheritAttrs: false,
data: () => ({
observer: null,
inView: false,
loaded: false
loaded: false,
}),
computed: {
addImage() {
Expand Down Expand Up @@ -69,14 +69,37 @@ export const Image = {
}

return true;
},
},
mounted() {
if ("IntersectionObserver" in window) {
this.observer = new IntersectionObserver(
(entries) => {
const image = entries[0];
if (image.isIntersecting) {
this.inView = true;
this.observer.disconnect();
}
},
{
threshold: this.intersectionTreshold,
rootMargin: this.intersectionMargin,
},
);
this.observer.observe(this.$el);
}
},
destroyed() {
if ("IntersectionObserver" in window && this.observer) {
this.observer.disconnect();
}
},
methods: {
load() {
if (this.$el.getAttribute("src") !== this.srcPlaceholder) {
this.loaded = true;
}
}
},
},
render(h) {
const {
Expand All @@ -87,7 +110,7 @@ export const Image = {
showImage,
addImage,
rootStyle,
explicitWidth
explicitWidth,
} = this;

const webpSource = data.webpSrcSet && (
Expand All @@ -109,7 +132,7 @@ export const Image = {
!fadeInDuration || fadeInDuration > 0
? `opacity ${fadeInDuration}ms ${fadeInDuration}ms`
: null,
...absolutePositioning
...absolutePositioning,
}}
/>
);
Expand All @@ -124,7 +147,7 @@ export const Image = {
width: explicitWidth ? `${width}px` : "100%",
height: "auto",
display: "block",
...pictureStyle
...pictureStyle,
}}
height={height}
width={width}
Expand All @@ -137,7 +160,7 @@ export const Image = {
display: "inline-block",
overflow: "hidden",
...rootStyle,
position: "relative"
position: "relative",
}}
>
{sizer}
Expand All @@ -151,7 +174,7 @@ export const Image = {
transition:
!fadeInDuration || fadeInDuration > 0
? `opacity ${fadeInDuration}ms`
: null
: null,
}}
>
{webpSource}
Expand All @@ -161,7 +184,7 @@ export const Image = {
src={data.src}
alt={data.alt}
title={data.title}
vOn:load={this.load}
v-on:load={this.load}
style={{ width: "100%" }}
/>
)}
Expand All @@ -180,39 +203,16 @@ export const Image = {
</picture>
);
},
staticRenderFns: []
}
staticRenderFns: [],
},
})}
</div>
);
},
mounted() {
if ("IntersectionObserver" in window) {
this.observer = new IntersectionObserver(
entries => {
const image = entries[0];
if (image.isIntersecting) {
this.inView = true;
this.observer.disconnect();
}
},
{
threshold: this.intersectionTreshold,
rootMargin: this.intersectionMargin
}
);
this.observer.observe(this.$el);
}
},
destroyed() {
if ("IntersectionObserver" in window && this.observer) {
this.observer.disconnect();
}
}
};

export const DatocmsImagePlugin = {
install: Vue => {
install: (Vue) => {
Vue.component("DatocmsImage", Image);
}
},
};
24 changes: 13 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
export * from './Image';
export * from "./Image";

export const toHead = (...args) => {
const tags = [].concat(...args);

const titleTag = tags && tags.find(t => t.tag === 'title');
const metaTags = tags ? tags.filter(t => t.tag === 'meta') : [];
const linkTags = tags ? tags.filter(t => t.tag === 'link') : [];
const titleTag = tags && tags.find((t) => t.tag === "title");
const metaTags = tags ? tags.filter((t) => t.tag === "meta") : [];
const linkTags = tags ? tags.filter((t) => t.tag === "link") : [];

return {
title: titleTag && titleTag.content,
meta: metaTags.map(tag => ({
meta: metaTags.map((tag) => ({
...tag.attributes,
hid: tag.attributes.name || tag.attributes.property,
vmid: tag.attributes.name || tag.attributes.property,
})),
link: linkTags.map(tag => ({
link: linkTags.map((tag) => ({
...tag.attributes,
hid: tag.attributes.name || (`${tag.attributes.rel}-${tag.attributes.sizes}`),
vmid: tag.attributes.name || (`${tag.attributes.rel}-${tag.attributes.sizes}`),
}))
}
}
hid:
tag.attributes.name || `${tag.attributes.rel}-${tag.attributes.sizes}`,
vmid:
tag.attributes.name || `${tag.attributes.rel}-${tag.attributes.sizes}`,
})),
};
};

0 comments on commit 6a6901a

Please sign in to comment.