diff --git a/auto-i18n.project.yaml b/auto-i18n.project.yaml new file mode 100644 index 0000000..c67c389 --- /dev/null +++ b/auto-i18n.project.yaml @@ -0,0 +1,11 @@ +code_files: +- './src/**/*.ts' +- './src/**/*.tsx' +dict: {} +export_dir: src/types +i18n_dir: public/i18n +i18n_pattern: \(\(`(.+?)`\)\) +i18n_var_mid: filename +i18n_var_prefix: i18n +main_file: zh_CN.yaml +strategy: diff diff --git a/package.json b/package.json index 4ac6e8e..2256e0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sy-bookmark-plus", - "version": "1.3.3", + "version": "1.4.0", "type": "module", "description": "A more powerful bookmark", "repository": "", @@ -8,13 +8,10 @@ "author": "frostime", "license": "GPL-3.0-only", "scripts": { - "make-link": "node --no-warnings ./scripts/make_dev_link.js", - "make-link-win": "powershell.exe -NoProfile -ExecutionPolicy Bypass -File ./scripts/elevate.ps1 -scriptPath ./scripts/make_dev_link.js", - "update-version": "node --no-warnings ./scripts/update_version.js", - "dev": "vite build --watch", - "dev-srcmap": "vite build --watch --sourcemap=inline", - "build": "vite build", - "make-install": "vite build && node --no-warnings ./scripts/make_install.js" + "dev": "cross-env NODE_ENV=development VITE_SOURCEMAP=inline vite build --watch", + "build": "cross-env NODE_ENV=production vite build", + "build-srcmap": "cross-env NODE_ENV=production VITE_SOURCEMAP=inline vite build", + "make-install": "cross-env NODE_ENV=production vite build && node --no-warnings ./scripts/make_install.js" }, "devDependencies": { "@types/node": "^20.3.0", @@ -24,7 +21,7 @@ "minimist": "^1.2.8", "rollup-plugin-livereload": "^2.0.5", "sass": "^1.72.0", - "siyuan": "0.9.9", + "siyuan": "1.0.3", "solid-js": "^1.8.17", "solid-styled-jsx": "^0.27.1", "ts-node": "^10.9.2", @@ -32,7 +29,8 @@ "vite": "^5.2.13", "vite-plugin-solid": "^2.10.2", "vite-plugin-static-copy": "^1.0.5", - "vite-plugin-zip-pack": "^1.2.2" + "vite-plugin-zip-pack": "^1.2.2", + "cross-env": "^7.0.3" }, "dependencies": { "solid-transition-group": "^0.2.3" diff --git a/plugin.json b/plugin.json index d2492a4..5aefa86 100644 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "name": "sy-bookmark-plus", "author": "frostime", "url": "https://github.com/frostime/sy-bookmark-plus", - "version": "1.3.3", + "version": "1.4.0", "minAppVersion": "3.0.12", "backends": [ "all" diff --git a/public/i18n/en_US.yaml b/public/i18n/en_US.yaml index 24330ec..0c8d323 100644 --- a/public/i18n/en_US.yaml +++ b/public/i18n/en_US.yaml @@ -103,6 +103,9 @@ newgroup: omit: No Process fb2p: First child of container b2doc: Display as document block + icontitle: Group Icon + # icondesc: 可以手动选择分组的图标;如果不设置,插件会根据分组类型分配默认的图标。 + icondesc: Select the icon for the group; if not set, the plugin will assign a default icon based on the group type. bookmarktype: normal: 'Normal Bookmark' @@ -120,3 +123,7 @@ template: todo: Unsolved Task attr: dailynote: Daily Note +selecticon: + title: Change Group Icon + h3: Please select an icon + reset: Reset diff --git a/public/i18n/zh_CN.yaml b/public/i18n/zh_CN.yaml index 83d5d7a..62fc4f6 100644 --- a/public/i18n/zh_CN.yaml +++ b/public/i18n/zh_CN.yaml @@ -103,6 +103,8 @@ newgroup: omit: 无处理 fb2p: 容器首个子块 b2doc: 显示为文档块 + icontitle: 分组图标 + icondesc: 可以手动选择分组的图标;如果不设置,插件会根据分组类型分配默认的图标。 bookmarktype: normal: '普通书签' dynamic: '动态书签' @@ -119,3 +121,7 @@ template: todo: 未完成的任务 attr: dailynote: Daily Note +selecticon: + title: 更改组图标 + h3: 请选择图标 + reset: 重置 diff --git a/src/components/bookmark.tsx b/src/components/bookmark.tsx index fdd49f8..740ab67 100644 --- a/src/components/bookmark.tsx +++ b/src/components/bookmark.tsx @@ -20,27 +20,30 @@ const createNewGroup = (confirmCb: (data: any) => void) => { let container = document.createElement("div") as HTMLDivElement; container.style.display = 'contents'; - const [group, setGroup] = createSignal({name: "", type: "normal"}); - const [rule, setRule] = createSignal({type: "", input: ""}); + const [group, setGroup] = createSignal({ name: "", type: "normal" }); + const [rule, setRule] = createSignal({ type: "", input: "" }); + const [icon, setIcon] = createSignal(null); render(() => NewGroup({ setGroup: (args) => { let current = group(); - let newval = {...current, ...args}; + let newval = { ...current, ...args }; setGroup(newval); }, setRule: (args) => { let current = rule(); - let newval = {...current, ...args}; + let newval = { ...current, ...args }; setRule(newval); - } + }, + icon, + setIcon }), container); confirmDialog({ title: i18n.bookmark.new, content: container, - width: '600px', + width: '800px', confirm: () => { - confirmCb({group: group(), rule: rule()}); + confirmCb({ group: group(), rule: rule(), icon: icon() }); } }); } @@ -60,14 +63,14 @@ const BookmarkComponent: Component = (props) => { }); const groupAdd = () => { - createNewGroup((result: {group: any, rule: any}) => { + createNewGroup((result: { group: any, rule: any, icon?: IBookmarkGroup['icon'] }) => { console.log(result); - let { group, rule } = result; + let { group, rule, icon } = result; if (group.name === "") { showMessage(i18n.msg.groupNameEmpty, 3000, 'error'); return; } - props.model.newGroup(group.name, group.type, rule); + props.model.newGroup(group.name, group.type, rule, icon); }); }; diff --git a/src/components/group.tsx b/src/components/group.tsx index be502ff..c4988bd 100644 --- a/src/components/group.tsx +++ b/src/components/group.tsx @@ -1,5 +1,5 @@ -import { Component, createEffect, createMemo, createSignal, Match, useContext, Show } from "solid-js"; -import { For, Switch } from "solid-js"; +import { Component, createEffect, createMemo, createSignal, useContext, Show } from "solid-js"; +import { For } from "solid-js"; import { Transition } from "solid-transition-group"; import { Menu, Constants, confirm, showMessage } from "siyuan"; @@ -13,6 +13,56 @@ import Item from "./item"; import { groups, setGroups, configs, itemInfo } from "../model"; import { BookmarkContext, itemMoving, setItemMoving, groupDrop, setGroupDrop } from "./context"; import { getActiveDoc } from "@/utils"; +import Icon from "./icon"; +import { parseEmoji } from "./icon"; + +import { selectGroupIcon } from "./select-icon"; + +const useGroupIcon = (props: Parameters[0]) => { + const { model } = useContext(BookmarkContext); + + const changeGroupIcon = () => { + selectGroupIcon({ + onReset: () => { + model.setGroups(props.group.id, 'icon', null); + showMessage('Reset!'); + }, + onUpdate: (icon) => { + model.setGroups(props.group.id, 'icon', icon); + showMessage((icon.type === 'symbol' ? icon.value : parseEmoji(icon.value))); + } + }); + } + + const onClickIcon = (e: MouseEvent) => { + e.stopPropagation(); + e.preventDefault(); + changeGroupIcon(); + } + + const ShowIcon = (icon?: { + type: 'symbol' | 'emoji' | ''; value: string; + }) => { + if (!icon || icon.type === '') { + return + } else if (icon.type === 'symbol') { + return + } else if (icon.type === 'emoji') { + return + } + } + + const IconView = () => ( + + {(() => ShowIcon(props.group.icon))()} + + ) + + return { + IconView, + changeGroupIcon + } +} interface Props { @@ -24,6 +74,8 @@ interface Props { const Group: Component = (props) => { const { model, doAction } = useContext(BookmarkContext); + const { IconView, changeGroupIcon } = useGroupIcon(props); + const isDynamicGroup = () => props.group.type === 'dynamic'; const i18n_ = i18n.group; @@ -190,6 +242,12 @@ const Group: Component = (props) => { }); }, }); + menu.addItem({ + label: i18n.selecticon.title, + icon: "iconImage", + click: changeGroupIcon + }); + if (isDynamicGroup()) { let type: "textline" | "textarea" = 'textline'; let height = null; @@ -362,7 +420,7 @@ const Group: Component = (props) => { const info = meta.split(Constants.ZWSP); const nodeId = info[2]; addItemByBlockId(nodeId); - } else if (type.startsWith(Constants.SIYUAN_DROP_FILE)) { + } else if (type.startsWith(Constants.SIYUAN_DROP_FILE)) { const ele: HTMLElement = window.siyuan.dragElement; if (ele && ele.innerText) { const blockid = ele.innerText; @@ -420,7 +478,7 @@ const Group: Component = (props) => { - + {/* }> @@ -429,7 +487,9 @@ const Group: Component = (props) => { - + */} + + {props.group.name} diff --git a/src/components/icon.tsx b/src/components/icon.tsx index 053d6e0..c7705a6 100644 --- a/src/components/icon.tsx +++ b/src/components/icon.tsx @@ -1,4 +1,4 @@ -import { Component } from "solid-js"; +import { Component, JSX } from "solid-js"; import { Dynamic } from "solid-js/web"; export const parseEmoji = (code: string) => { @@ -11,7 +11,7 @@ interface CommonProps { fontSize?: string; height?: string; width?: string; - style?: { [key: string]: string | number }; + style?: JSX.CSSProperties; } interface SymbolProps extends CommonProps { @@ -37,7 +37,7 @@ type IProps = SymbolProps | EmojiCodeProps | ImgProps; const Icon: Component = (props) => { - let style = { + let style: JSX.CSSProperties = { "font-size": props?.fontSize ?? '14px', "height": props?.height, "width": props?.width, @@ -48,7 +48,7 @@ const Icon: Component = (props) => { } const Symbol = () => ( - + ); diff --git a/src/components/new-group.tsx b/src/components/new-group.tsx index ee1665e..b2af77e 100644 --- a/src/components/new-group.tsx +++ b/src/components/new-group.tsx @@ -13,6 +13,7 @@ import { RuleTemplate } from "@/utils/const"; import { createContext, useContext } from "solid-js"; import { Caret } from "@/utils/const"; +import { selectGroupIcon } from "./select-icon"; const NewGroupContext = createContext<{ groupType: Accessor; @@ -234,6 +235,8 @@ const RuleEditor = () => { interface IPrpos { setGroup: (arg: { name?: string, type?: TBookmarkGroupType }) => void; setRule: (arg: { type?: string, input?: string }) => void; + icon: Accessor; + setIcon: (args: IBookmarkGroup['icon']) => void; } const NewGroup = (props: IPrpos) => { @@ -249,6 +252,17 @@ const NewGroup = (props: IPrpos) => { const transitionDuration = 100; + const changeGroupIcon = () => { + selectGroupIcon({ + onReset: () => { + props.setIcon(null); + }, + onUpdate: (icon) => { + props.setIcon(icon); + } + }); + } + return (
{ @@ -293,6 +307,22 @@ const NewGroup = (props: IPrpos) => { }} /> + +
+ {(() => { + if (!props.icon()) { + return + } else if (props.icon()?.type === 'symbol') { + return + } else { + return + } + })()} +
+
{ diff --git a/src/components/select-icon.tsx b/src/components/select-icon.tsx new file mode 100644 index 0000000..4ee999a --- /dev/null +++ b/src/components/select-icon.tsx @@ -0,0 +1,104 @@ +import { createSignal, For, Show } from "solid-js"; +import Icon from "./icon"; +import { inject } from "@/libs/inject"; +import { solidDialog } from "@/libs/dialog"; + +import { i18n } from "@/utils/i18n"; + +type ImojiGroup = { + id: string; + items: { + unicode: string; + }[] +} + +interface IProps { + choose: (args: { type: 'symbol' | 'emoji' | ''; value: string }) => void; +} + +const SelectIcons = (props: IProps) => { + const [activeTab, setActiveTab] = createSignal<'symbols' | 'emojis'>('symbols'); + const symbols = Array.from(document.querySelectorAll('symbol')); + + const i18n = inject('i18n'); + + const ALLOWED_EMOJI_GROUP = ['activity', 'travel', 'people', 'nature', 'food', 'symbols', 'object', 'flags']; + let EmojisGroups = (window.siyuan.emojis as ImojiGroup[]).filter(emoji => ALLOWED_EMOJI_GROUP.includes(emoji.id)); + EmojisGroups.sort((a, b) => ALLOWED_EMOJI_GROUP.indexOf(a.id) - ALLOWED_EMOJI_GROUP.indexOf(b.id)) + const emojiUnicodes = EmojisGroups.map(group => group.items.map(item => item.unicode)).flat(); + + const SIZE = '20px'; + + const AllSymbols = () => ( +
+ + {(symbol) => ( +
props.choose({ type: 'symbol', value: symbol.id })}> + +
+ )} +
+
+ ); + + const EmojiIcons = () => ( +
+ + {(unicode) => ( +
props.choose({ type: 'emoji', value: unicode })}> + +
+ )} +
+
+ ); + + return ( +
+
+

{i18n.selecticon.h3}

+
+ + +
+ +
+ +
+ + + + + + + +
+ ); +} + +export const selectGroupIcon = (param: { + onReset: () => void; + onUpdate: (icon: { type: 'symbol' | 'emoji' | ''; value: string }) => void; +}) => { + const chooseIcon = (icon: { + type: 'symbol' | 'emoji' | ''; value: string; + }) => { + close(); + if (icon.type === '' && icon.value === '') { + param.onReset(); + } else { + param.onUpdate(icon); + } + } + + const { close } = solidDialog({ + title: i18n.selecticon.title, + loader: () => , + width: '800px', + height: '600px' + }); +} + +export default SelectIcons; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 2512ab4..c215d3f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ * @Author : frostime * @Date : 2024-06-12 19:48:53 * @FilePath : /src/index.ts - * @LastEditTime : 2024-08-15 17:38:22 + * @LastEditTime : 2024-10-03 14:55:24 * @Description : */ import { @@ -26,11 +26,11 @@ import { setI18n } from "@/utils/i18n"; import "@/index.scss"; import { isMobile } from "./utils"; +import { provide, purge } from "./libs/inject"; let model: BookmarkDataModel; const initBookmark = async (ele: HTMLElement, plugin: PluginBookmarkPlus) => { - await model.updateAll(); ele.classList.add('fn__flex-column'); if (isMobile()) { @@ -42,6 +42,7 @@ const initBookmark = async (ele: HTMLElement, plugin: PluginBookmarkPlus) => { plugin: plugin, model: model }), ele); + await model.updateAll(); }; const destroyBookmark = () => { @@ -65,7 +66,9 @@ export default class PluginBookmarkPlus extends Plugin { } async onload() { - setI18n(this.i18n); + setI18n(this.i18n as I18n); + provide('i18n', this.i18n as I18n); + provide('plugin', this); let svgs = Object.values(Svg); this.addIcons(svgs.join('')); @@ -120,6 +123,7 @@ export default class PluginBookmarkPlus extends Plugin { } onunload(): void { + purge(); destroyBookmark(); bookmarkKeymap.custom = bookmarkKeymap.default; // this.commands = this.commands.filter((command) => command.langKey !== 'F-Misc::Bookmark'); diff --git a/src/libs/dialog.ts b/src/libs/dialog.ts index 60e5efa..c023ba5 100644 --- a/src/libs/dialog.ts +++ b/src/libs/dialog.ts @@ -3,10 +3,12 @@ * @Author : frostime * @Date : 2024-03-23 21:37:33 * @FilePath : /src/libs/dialog.ts - * @LastEditTime : 2024-07-07 22:58:44 + * @LastEditTime : 2024-10-03 16:44:41 * @Description : 对话框相关工具 */ import { Dialog } from "siyuan"; +import { JSXElement } from "solid-js"; +import { render } from "solid-js/web"; export const simpleDialog = (args: { title: string, ele: HTMLElement | DocumentFragment, @@ -24,6 +26,24 @@ export const simpleDialog = (args: { return dialog; } +export const solidDialog = (args: { + title: string, loader: () => JSXElement, + width?: string, height?: string, + callback?: () => void; +}) => { + let container = document.createElement('div') + container.style.display = 'contents'; + let disposer = render(args.loader, container); + const dialog = simpleDialog({...args, ele: container, callback: () => { + disposer(); + if (args.callback) args.callback();; + }}); + return { + dialog, + close: () => dialog.destroy(), + container + } +} interface IConfirmDialogArgs { title: string; diff --git a/src/libs/inject.ts b/src/libs/inject.ts new file mode 100644 index 0000000..6867186 --- /dev/null +++ b/src/libs/inject.ts @@ -0,0 +1,19 @@ +const Storage = {}; + +export const provide = (key: string, value: T) => { + Storage[key] = value; +} + +export const inject = (key: string): T => { + return Storage[key]; +} + +export const purge = (key?: string) => { + if (key) { + delete Storage[key]; + } else { + for (const key in Storage) { + delete Storage[key]; + } + } +} diff --git a/src/model/index.ts b/src/model/index.ts index aeedbf5..6b8a174 100644 --- a/src/model/index.ts +++ b/src/model/index.ts @@ -100,6 +100,16 @@ export class BookmarkDataModel { save = debounce(this.saveCore.bind(this), 1000); + setGroups(gid: TBookmarkGroupId, key: keyof IBookmarkGroup, value: IBookmarkGroup[keyof IBookmarkGroup]) { + setGroups((gs) => gs.id === gid, key, value); + this.save(); + } + + setItemInfo(id: BlockId, key: keyof IBookmarkItemInfo, value: IBookmarkItemInfo[keyof IBookmarkItemInfo]) { + setItemInfo(id, key, value); + this.save(); + } + hasItem(id: BlockId, groupId?: TBookmarkGroupId) { if (groupId === undefined) { return itemInfo[id] !== undefined @@ -321,18 +331,19 @@ export class BookmarkDataModel { } } - newGroup(name: string, type?: TBookmarkGroupType, rule?: IDynamicRule) { + newGroup(name: string, type?: TBookmarkGroupType, rule?: IDynamicRule, icon?: IBookmarkGroup['icon']) { //6位 36进制 let id: TBookmarkGroupId; while (id === undefined || groupMap().has(id)) { id = Math.random().toString(36).slice(-6); } - let group = { + let group: IBookmarkGroup = { id, name, items: [], type, - rule + rule, + icon: icon ?? null }; setGroups((gs) => [...gs, group]); diff --git a/src/types/bookmark.d.ts b/src/types/bookmark.d.ts index 4c65eeb..128b9ad 100644 --- a/src/types/bookmark.d.ts +++ b/src/types/bookmark.d.ts @@ -2,8 +2,8 @@ * Copyright (c) 2024 by frostime. All Rights Reserved. * @Author : frostime * @Date : 2024-05-20 18:54:29 - * @FilePath : /src/func/bookmarks/types/bookmark.d.ts - * @LastEditTime : 2024-07-07 14:51:19 + * @FilePath : /src/types/bookmark.d.ts + * @LastEditTime : 2024-10-03 17:06:24 * @Description : */ type TBookmarkGroupId = string; @@ -47,6 +47,9 @@ interface IBookmarkGroup { items: IItemCore[]; type?: TBookmarkGroupType; rule?: IDynamicRule; + icon?: { + type: 'symbol' | 'emoji' | ''; value: string; + } } diff --git a/src/types/i18n.d.ts b/src/types/i18n.d.ts new file mode 100644 index 0000000..c92ba1f --- /dev/null +++ b/src/types/i18n.d.ts @@ -0,0 +1,145 @@ +interface I18n { + msg: { + ruleFailed: string; + ruleInvalid: string; + itemHasInGroup: string; + itemNotFoundInGroup: string; + groupNameEmpty: string; + }; + itemErr: { + closed: string; + deleted: string; + }; + setting: { + replaceDefault: { + title: string; + description: string; + }; + viewMode: { + title: string; + description: string; + }; + hideClosed: { + title: string; + description: string; + }; + hideDeleted: { + title: string; + description: string; + }; + grouplist: { + title: string; + description: string; + }; + autoRefreshOnExpand: { + title: string; + description: string; + }; + ariaLabel: { + title: string; + description: string; + }; + }; + viewMode: { + bookmark: string; + card: string; + }; + bookmark: { + new: string; + delete: { + title: string; + desc: string; + }; + cache: string; + logo: { + name: string; + setting: string; + add: string; + refresh: string; + expand: string; + collapse: string; + min: string; + }; + }; + group: { + msgexist: string; + msg404: string; + refresh: string; + copyref: string; + copylink: string; + msgcopy: string; + docflow: string; + rename: string; + edit: string; + delete: string; + move: string; + top: string; + up: string; + down: string; + bottom: string; + fromclipboard: string; + msgparse: string; + currentdoc: string; + msgdelconfirm: string[]; + }; + item: { + copyref: string; + copylink: string; + msgcopy: string; + style: string; + transfer: string; + move: string; + top: string; + bottom: string; + del: string; + checkerritem: string; + copyitem: string; + }; + newgroup: { + name: string[]; + type: string[]; + rtype: string[]; + rinput: string; + desc: { + sql: string; + backlinks: string; + attr: string; + }; + choosetemplate: string; + postprocess: { + ariaLabel: string; + name: string; + omit: string; + fb2p: string; + b2doc: string; + }; + icontitle: string; + icondesc: string; + }; + bookmarktype: { + normal: string; + dynamic: string; + composed: string; + }; + ruletype: { + sql: string; + backlinks: string; + attr: string; + }; + template: { + sql: { + random: string; + updated: string; + thisday: string; + todo: string; + }; + attr: { + dailynote: string; + }; + }; + selecticon: { + title: string; + h3: string; + reset: string; + }; +} diff --git a/src/utils/i18n.ts b/src/utils/i18n.ts index c42391d..0282af5 100644 --- a/src/utils/i18n.ts +++ b/src/utils/i18n.ts @@ -3,14 +3,13 @@ * @Author : frostime * @Date : 2024-07-07 18:57:06 * @FilePath : /src/utils/i18n.ts - * @LastEditTime : 2024-07-07 21:24:01 + * @LastEditTime : 2024-09-28 22:07:01 * @Description : */ -import type I18n from '@/../dev/i18n/zh_CN.json'; -export let i18n: typeof I18n = {} as any; +export let i18n: I18n = {} as any; -export const setI18n = (_i18n_: any) => { +export const setI18n = (_i18n_: I18n) => { i18n = new Proxy(_i18n_, { set: (..._) => { console.warn("Attempt to modify read-only i18n object"); diff --git a/vite.config.ts b/vite.config.ts index 0f112ad..0183a40 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,5 @@ import { resolve } from "path" import { defineConfig, loadEnv } from "vite" -import minimist from "minimist" import { viteStaticCopy } from "vite-plugin-static-copy" import livereload from "rollup-plugin-livereload" import solidPlugin from 'vite-plugin-solid'; @@ -9,86 +8,66 @@ import fg from 'fast-glob'; import vitePluginYamlI18n from './yaml-plugin'; -const args = minimist(process.argv.slice(2)); -const isWatch = args.watch || args.w || false; -const isSrcmap = args.sourcemap || false; -const devDistDir = "dev"; -const distDir = isWatch ? devDistDir : "dist"; +export default defineConfig(({ mode }) => { + const env = loadEnv(mode, process.cwd(), ''); + const isSrcmap = env.VITE_SOURCEMAP === 'inline'; + const isDev = env.NODE_ENV === 'development'; + const distDir = isDev ? "dev" : "dist"; -console.log("isWatch=>", isWatch); -console.log("isSrcmap=>", isSrcmap); + console.log("isDev=>", isDev); + console.log("isSrcmap=>", isSrcmap); + console.log("distDir=>", distDir); -export default defineConfig({ - resolve: { - alias: { - "@": resolve(__dirname, "src"), - } - }, - - plugins: [ - solidPlugin({ - babel: { - plugins: ['solid-styled-jsx/babel'] + return { + resolve: { + alias: { + "@": resolve(__dirname, "src"), } - }), - - vitePluginYamlI18n({ - inDir: 'public/i18n', - outDir: `${distDir}/i18n` - }), + }, - viteStaticCopy({ - targets: [ - { - src: "./README*.md", - dest: "./", - }, - { - src: "./plugin.json", - dest: "./", - }, - { - src: "./preview.png", - dest: "./", - }, - { - src: "./icon.png", - dest: "./", + plugins: [ + solidPlugin({ + babel: { + plugins: ['solid-styled-jsx/babel'] } - ], - }), - ], + }), - // https://github.com/vitejs/vite/issues/1930 - // https://vitejs.dev/guide/env-and-mode.html#env-files - // https://github.com/vitejs/vite/discussions/3058#discussioncomment-2115319 - // 在这里自定义变量 - define: { - "process.env.DEV_MODE": `"${isWatch}"`, - "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV) - }, + vitePluginYamlI18n({ + inDir: 'public/i18n', + outDir: `${distDir}/i18n` + }), - build: { - // 输出路径 - outDir: distDir, - emptyOutDir: false, + viteStaticCopy({ + targets: [ + { src: "./README*.md", dest: "./" }, + { src: "./plugin.json", dest: "./" }, + { src: "./preview.png", dest: "./" }, + { src: "./icon.png", dest: "./" } + ], + }), + ], - minify: !isWatch || (isWatch && (isSrcmap === 'inline')), - - lib: { - // Could also be a dictionary or array of multiple entry points - entry: resolve(__dirname, "src/index.ts"), - // the proper extensions will be added - fileName: "index", - formats: ["cjs"], + define: { + "process.env.DEV_MODE": JSON.stringify(isDev), + "process.env.NODE_ENV": JSON.stringify(env.NODE_ENV) }, - rollupOptions: { - plugins: [ - ...( - isWatch ? [ - livereload(devDistDir), + + build: { + outDir: distDir, + emptyOutDir: false, + minify: true, + sourcemap: isSrcmap ? 'inline' : false, + + lib: { + entry: resolve(__dirname, "src/index.ts"), + fileName: "index", + formats: ["cjs"], + }, + rollupOptions: { + plugins: [ + ...(isDev ? [ + livereload(distDir), { - //监听静态资源文件 name: 'watch-external', async buildStart() { const files = await fg([ @@ -107,23 +86,21 @@ export default defineConfig({ outDir: './', outFileName: 'package.zip' }) - ] - ) - ], + ]) + ], - // make sure to externalize deps that shouldn't be bundled - // into your library - external: ["siyuan", "process"], + external: ["siyuan", "process"], - output: { - entryFileNames: "[name].js", - assetFileNames: (assetInfo) => { - if (assetInfo.name === "style.css") { - return "index.css" - } - return assetInfo.name + output: { + entryFileNames: "[name].js", + assetFileNames: (assetInfo) => { + if (assetInfo.name === "style.css") { + return "index.css" + } + return assetInfo.name + }, }, }, - }, + } } })