3.0.0原版
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"scripts": {
|
||||
"build": "tsc && rslib build",
|
||||
"dev": "rslib build --watch"
|
||||
},
|
||||
"dependencies": {
|
||||
"@halo-dev/comment-widget": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rslib/core": "^0.12.1"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { defineConfig } from '@rslib/core';
|
||||
|
||||
const PLUGIN_NAME = 'PluginCommentWidget';
|
||||
|
||||
export default defineConfig({
|
||||
lib: [
|
||||
{
|
||||
format: 'esm',
|
||||
autoExternal: false,
|
||||
},
|
||||
],
|
||||
output: {
|
||||
target: 'web',
|
||||
minify: true,
|
||||
cleanDistPath: true,
|
||||
filename: {
|
||||
js: (pathData) => {
|
||||
if (pathData.chunk.name === 'index') {
|
||||
return 'comment-widget.js';
|
||||
}
|
||||
return '[name].[contenthash:8].js';
|
||||
},
|
||||
},
|
||||
publicPath: `/plugins/${PLUGIN_NAME}/assets/static/`,
|
||||
distPath: {
|
||||
root: fileURLToPath(
|
||||
new URL('../../src/main/resources/static', import.meta.url)
|
||||
),
|
||||
},
|
||||
},
|
||||
});
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
/// <reference types="@rslib/core/types" />
|
||||
@@ -0,0 +1,41 @@
|
||||
import { CommentWidget } from '@halo-dev/comment-widget';
|
||||
import '@halo-dev/comment-widget/var.css';
|
||||
|
||||
export { CommentWidget };
|
||||
|
||||
interface Props {
|
||||
group: string;
|
||||
kind: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export function init(el: string, props: Props) {
|
||||
const parent = document.querySelector(el) as HTMLElement;
|
||||
|
||||
if (!parent) {
|
||||
console.error('Element not found', el);
|
||||
}
|
||||
|
||||
const commentWidget = document.createElement(
|
||||
'comment-widget'
|
||||
) as CommentWidget;
|
||||
|
||||
commentWidget.kind = props.kind;
|
||||
commentWidget.group = props.group;
|
||||
commentWidget.version = 'v1alpha1';
|
||||
commentWidget.name = props.name;
|
||||
|
||||
const observer = new IntersectionObserver((entries) => {
|
||||
entries.forEach((entry) => {
|
||||
if (entry.isIntersecting && parent.childElementCount === 0) {
|
||||
parent.appendChild(commentWidget);
|
||||
|
||||
parent.animate([{ opacity: 0 }, { opacity: 1 }], {
|
||||
duration: 300,
|
||||
fill: 'forwards',
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
observer.observe(parent as Element);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user