chore: 添加TypeScript类型定义
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cwd-admin",
|
"name": "cwd-admin",
|
||||||
"version": "0.1.4-beta",
|
"version": "0.1.4-rc-1",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cwd-api",
|
"name": "cwd-api",
|
||||||
"version": "0.1.4-beta",
|
"version": "0.1.4-rc-1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"deploy": "node scripts/index.js && wrangler deploy",
|
"deploy": "node scripts/index.js && wrangler deploy",
|
||||||
"dev": "wrangler dev",
|
"dev": "wrangler dev",
|
||||||
|
|||||||
@@ -1,14 +1,16 @@
|
|||||||
{
|
{
|
||||||
"name": "cwd-widget",
|
"name": "cwd-widget",
|
||||||
"version": "0.1.4-beta",
|
"version": "0.1.4-rc-1",
|
||||||
"description": "Server-free, extremely fast and secure, plug-and-play commenting system based on Cloudflare Workers and the Global Edge Network.",
|
"description": "Server-free, extremely fast and secure, plug-and-play commenting system based on Cloudflare Workers and the Global Edge Network.",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"author": "anghunk",
|
"author": "anghunk",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"main": "./dist/cwd.umd.js",
|
"main": "./dist/cwd.umd.js",
|
||||||
"module": "./dist/cwd.es.js",
|
"module": "./dist/cwd.es.js",
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
|
"types": "./dist/index.d.ts",
|
||||||
"import": "./dist/cwd.es.js",
|
"import": "./dist/cwd.es.js",
|
||||||
"require": "./dist/cwd.umd.js"
|
"require": "./dist/cwd.umd.js"
|
||||||
}
|
}
|
||||||
|
|||||||
101
docs/widget/src/index.d.ts
vendored
Normal file
101
docs/widget/src/index.d.ts
vendored
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
export interface CWDCommentsConfig {
|
||||||
|
/**
|
||||||
|
* Selector or DOM element to mount the widget
|
||||||
|
*/
|
||||||
|
el: string | HTMLElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base URL of the CWD Comments API
|
||||||
|
*/
|
||||||
|
apiBaseUrl: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Site ID for multi-site support
|
||||||
|
*/
|
||||||
|
siteId?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current post slug (defaults to window.location.pathname)
|
||||||
|
*/
|
||||||
|
postSlug?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current post title (defaults to document.title)
|
||||||
|
*/
|
||||||
|
postTitle?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Current post URL (defaults to window.location.href)
|
||||||
|
*/
|
||||||
|
postUrl?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Widget theme
|
||||||
|
* @default 'light'
|
||||||
|
*/
|
||||||
|
theme?: 'light' | 'dark' | string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comments per page
|
||||||
|
* @default 20
|
||||||
|
*/
|
||||||
|
pageSize?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Widget language
|
||||||
|
* @default 'auto'
|
||||||
|
*/
|
||||||
|
lang?: 'zh-CN' | 'en-US' | 'auto' | string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom CSS URL to load
|
||||||
|
*/
|
||||||
|
customCssUrl?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/Disable comment likes
|
||||||
|
*/
|
||||||
|
enableCommentLike?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/Disable article likes
|
||||||
|
*/
|
||||||
|
enableArticleLike?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/Disable image lightbox
|
||||||
|
*/
|
||||||
|
enableImageLightbox?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Placeholder text for comment input
|
||||||
|
*/
|
||||||
|
commentPlaceholder?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CWDComments {
|
||||||
|
constructor(config: CWDCommentsConfig);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Mount the widget to the DOM
|
||||||
|
*/
|
||||||
|
mount(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unmount the widget and clean up
|
||||||
|
*/
|
||||||
|
unmount(): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update widget configuration
|
||||||
|
* @param newConfig Partial configuration to update
|
||||||
|
*/
|
||||||
|
updateConfig(newConfig: Partial<CWDCommentsConfig>): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current configuration
|
||||||
|
*/
|
||||||
|
getConfig(): CWDCommentsConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CWDComments;
|
||||||
@@ -1,13 +1,29 @@
|
|||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import { resolve } from 'path';
|
import { resolve } from 'path';
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync, copyFileSync } from 'fs';
|
||||||
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js';
|
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js';
|
||||||
|
|
||||||
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8'));
|
const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8'));
|
||||||
const banner = `/*! CWDComments widget v${pkg.version} */`;
|
const banner = `/*! CWDComments widget v${pkg.version} */`;
|
||||||
|
|
||||||
|
function copyDtsPlugin() {
|
||||||
|
return {
|
||||||
|
name: 'copy-dts',
|
||||||
|
closeBundle() {
|
||||||
|
const src = resolve(__dirname, 'src/index.d.ts');
|
||||||
|
const dest = resolve(__dirname, 'dist/index.d.ts');
|
||||||
|
try {
|
||||||
|
copyFileSync(src, dest);
|
||||||
|
console.log(`[copy-dts] Copied ${src} to ${dest}`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`[copy-dts] Failed to copy .d.ts file: ${e}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [cssInjectedByJsPlugin()],
|
plugins: [cssInjectedByJsPlugin(), copyDtsPlugin()],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': resolve(__dirname, 'src'),
|
'@': resolve(__dirname, 'src'),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "cwd",
|
"name": "cwd",
|
||||||
"version": "0.1.4-beta",
|
"version": "0.1.4-rc-1",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
Reference in New Issue
Block a user