diff --git a/cwd-admin/package.json b/cwd-admin/package.json index 60ca258..3334137 100644 --- a/cwd-admin/package.json +++ b/cwd-admin/package.json @@ -1,6 +1,6 @@ { "name": "cwd-admin", - "version": "0.1.4-beta", + "version": "0.1.4-rc-1", "type": "module", "scripts": { "dev": "vite", diff --git a/cwd-api/package.json b/cwd-api/package.json index 0b21dbe..fa4f312 100644 --- a/cwd-api/package.json +++ b/cwd-api/package.json @@ -1,6 +1,6 @@ { "name": "cwd-api", - "version": "0.1.4-beta", + "version": "0.1.4-rc-1", "scripts": { "deploy": "node scripts/index.js && wrangler deploy", "dev": "wrangler dev", diff --git a/docs/widget/package.json b/docs/widget/package.json index 3614ae2..1f9a6aa 100644 --- a/docs/widget/package.json +++ b/docs/widget/package.json @@ -1,14 +1,16 @@ { "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.", "type": "module", "author": "anghunk", "license": "Apache-2.0", "main": "./dist/cwd.umd.js", "module": "./dist/cwd.es.js", + "types": "./dist/index.d.ts", "exports": { ".": { + "types": "./dist/index.d.ts", "import": "./dist/cwd.es.js", "require": "./dist/cwd.umd.js" } diff --git a/docs/widget/src/index.d.ts b/docs/widget/src/index.d.ts new file mode 100644 index 0000000..35d60cf --- /dev/null +++ b/docs/widget/src/index.d.ts @@ -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): void; + + /** + * Get current configuration + */ + getConfig(): CWDCommentsConfig; +} + +export default CWDComments; diff --git a/docs/widget/vite.config.js b/docs/widget/vite.config.js index 7cc5159..32eaeca 100644 --- a/docs/widget/vite.config.js +++ b/docs/widget/vite.config.js @@ -1,13 +1,29 @@ import { defineConfig } from 'vite'; import { resolve } from 'path'; -import { readFileSync } from 'fs'; +import { readFileSync, copyFileSync } from 'fs'; import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'; const pkg = JSON.parse(readFileSync(new URL('./package.json', import.meta.url), 'utf-8')); 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({ - plugins: [cssInjectedByJsPlugin()], + plugins: [cssInjectedByJsPlugin(), copyDtsPlugin()], resolve: { alias: { '@': resolve(__dirname, 'src'), diff --git a/package.json b/package.json index a639736..d02c18a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cwd", - "version": "0.1.4-beta", + "version": "0.1.4-rc-1", "license": "Apache-2.0", "repository": { "type": "git",