@place-framework/place-block-image 1.0.1 → 1.0.2
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/dist/constants/index.d.ts +2 -2
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +4 -5
- package/dist/constants/index.js.map +1 -1
- package/dist/generate-components.d.ts +16 -0
- package/dist/generate-components.d.ts.map +1 -0
- package/dist/generate-components.js +93 -0
- package/dist/generate-components.js.map +1 -0
- package/dist/react/PlaceBlockImage.cjs +1 -0
- package/dist/react/PlaceBlockImage.js +67 -0
- package/dist/templates/shared/index.d.ts.map +1 -1
- package/dist/templates/shared/index.js +8 -16
- package/dist/templates/shared/index.js.map +1 -1
- package/dist/templates/shared/vue.d.ts +6 -0
- package/dist/templates/shared/vue.d.ts.map +1 -0
- package/dist/templates/shared/vue.js +26 -0
- package/dist/templates/shared/vue.js.map +1 -0
- package/dist/templates/vue.d.ts.map +1 -1
- package/dist/templates/vue.js +14 -19
- package/dist/templates/vue.js.map +1 -1
- package/dist/utils/index.d.ts +61 -14
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +108 -40
- package/dist/utils/index.js.map +1 -1
- package/dist/vue/PlaceBlockImage.cjs +1 -0
- package/dist/vue/PlaceBlockImage.js +83 -0
- package/dist/webpack-plugin.d.ts +20 -7
- package/dist/webpack-plugin.d.ts.map +1 -1
- package/dist/webpack-plugin.js +22 -28
- package/dist/webpack-plugin.js.map +1 -1
- package/package.json +36 -10
- package/src/constants/index.ts +5 -6
- package/src/react/PlaceBlockImage.tsx +63 -0
- package/src/react/index.ts +1 -0
- package/src/utils/index.ts +121 -44
- package/src/vue/PlaceBlockImage.vue +98 -0
- package/src/vue/index.ts +1 -0
- package/src/webpack-plugin.ts +45 -40
- package/tsconfig.json +8 -3
- package/vite.config.mts +27 -0
- package/vite.react.config.mts +25 -0
- package/vite.vue.config.mts +26 -0
- package/src/templates/react-jsx.ts +0 -27
- package/src/templates/react-tsx.ts +0 -33
- package/src/templates/shared/index.ts +0 -47
- package/src/templates/shared/react.ts +0 -51
- package/src/templates/vue.ts +0 -98
- package/src/templates.ts +0 -29
package/src/templates/vue.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { getSharedTemplate } from './shared/';
|
|
2
|
-
import { CLASS_NAMES } from '../constants';
|
|
3
|
-
|
|
4
|
-
export function getVueTemplate(imagePrefix: string): string {
|
|
5
|
-
const shared = getSharedTemplate(imagePrefix);
|
|
6
|
-
|
|
7
|
-
return `<template>
|
|
8
|
-
<picture :class="wrapperClassName">
|
|
9
|
-
<img
|
|
10
|
-
ref="imgRef"
|
|
11
|
-
:src="imageSrc"
|
|
12
|
-
:alt="alt"
|
|
13
|
-
:class="imgClassName"
|
|
14
|
-
v-bind="$attrs"
|
|
15
|
-
/>
|
|
16
|
-
</picture>
|
|
17
|
-
</template>
|
|
18
|
-
|
|
19
|
-
<script setup lang="ts">
|
|
20
|
-
import { computed, ref, onMounted, onUnmounted, watch } from 'vue';
|
|
21
|
-
|
|
22
|
-
interface Props {
|
|
23
|
-
src: string;
|
|
24
|
-
alt: string;
|
|
25
|
-
lazy?: boolean;
|
|
26
|
-
class?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const props = withDefaults(defineProps<Props>(), {
|
|
30
|
-
lazy: false,
|
|
31
|
-
class: ''
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
${shared.comment}
|
|
35
|
-
|
|
36
|
-
const imgRef = ref<HTMLImageElement | null>(null);
|
|
37
|
-
const imageSrc = ref(props.lazy ? '' : props.src);
|
|
38
|
-
const isLoaded = ref(!props.lazy);
|
|
39
|
-
let observer: IntersectionObserver | null = null;
|
|
40
|
-
|
|
41
|
-
${shared.getImageClassNameTemplate}
|
|
42
|
-
|
|
43
|
-
const imageClassName = computed(() => getImageClassName(props.src));
|
|
44
|
-
const wrapperClassName = computed(() =>
|
|
45
|
-
\`${imagePrefix}wrapper \${imageClassName.value}\`
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const lazyClass = computed(() =>
|
|
49
|
-
props.lazy ? (isLoaded.value ? '${CLASS_NAMES.LAZY} ${CLASS_NAMES.LOADED}' : '${CLASS_NAMES.LAZY}') : ''
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
const imgClassName = computed(() =>
|
|
53
|
-
\`\${props.class} \${lazyClass.value}\`.trim()
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
const setupLazyLoading = () => {
|
|
57
|
-
if (!props.lazy || isLoaded.value) return;
|
|
58
|
-
|
|
59
|
-
${shared.intersectionObserverTemplate}
|
|
60
|
-
|
|
61
|
-
if (imgRef.value) {
|
|
62
|
-
observer.observe(imgRef.value);
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const cleanupObserver = () => {
|
|
67
|
-
if (observer) {
|
|
68
|
-
observer.disconnect();
|
|
69
|
-
observer = null;
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
onMounted(() => {
|
|
74
|
-
setupLazyLoading();
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
onUnmounted(() => {
|
|
78
|
-
cleanupObserver();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
watch(() => props.src, (newSrc) => {
|
|
82
|
-
if (!props.lazy) {
|
|
83
|
-
imageSrc.value = newSrc;
|
|
84
|
-
} else if (!isLoaded.value) {
|
|
85
|
-
cleanupObserver();
|
|
86
|
-
setupLazyLoading();
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
watch(isLoaded, (loaded) => {
|
|
91
|
-
if (loaded) {
|
|
92
|
-
imageSrc.value = props.src;
|
|
93
|
-
cleanupObserver();
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
</script>
|
|
97
|
-
`;
|
|
98
|
-
}
|
package/src/templates.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
// Main template exports
|
|
2
|
-
import { getReactTsxTemplate as getReactTsx } from './templates/react-tsx';
|
|
3
|
-
import { getReactJsxTemplate as getReactJsx } from './templates/react-jsx';
|
|
4
|
-
import { getVueTemplate as getVue } from './templates/vue';
|
|
5
|
-
|
|
6
|
-
export function getReactTsxTemplate(imagePrefix: string): string {
|
|
7
|
-
return getReactTsx(imagePrefix);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function getReactJsxTemplate(imagePrefix: string): string {
|
|
11
|
-
return getReactJsx(imagePrefix);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function getVueTemplate(imagePrefix: string): string {
|
|
15
|
-
return getVue(imagePrefix);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function getTemplate(type: 'tsx' | 'jsx' | 'vue', imagePrefix: string): string {
|
|
19
|
-
switch (type) {
|
|
20
|
-
case 'tsx':
|
|
21
|
-
return getReactTsxTemplate(imagePrefix);
|
|
22
|
-
case 'jsx':
|
|
23
|
-
return getReactJsxTemplate(imagePrefix);
|
|
24
|
-
case 'vue':
|
|
25
|
-
return getVueTemplate(imagePrefix);
|
|
26
|
-
default:
|
|
27
|
-
throw new Error(`Unsupported component type: ${type}`);
|
|
28
|
-
}
|
|
29
|
-
}
|