-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
365 additions
and
4 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
import PublishHook from "./publish-hook" | ||
import { SiyuanDevice, BrowserUtil, DeviceDetection, DeviceTypeEnum } from "zhi-device" | ||
|
||
export default PublishHook | ||
export { SiyuanDevice, BrowserUtil, DeviceDetection, DeviceTypeEnum } | ||
export { PublishHook, SiyuanDevice, BrowserUtil, DeviceDetection, DeviceTypeEnum } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
VITE_DEBUG_MODE=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ["./node_modules/@terwer/eslint-config-custom/typescript/index.cjs"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# platform | ||
|
||
# Ignore artifacts: | ||
dist | ||
node_modules | ||
|
||
# Ignore all dts files: | ||
*.d.ts | ||
|
||
# lib | ||
/pnpm-lock.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2023, Terwer . All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Terwer designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Terwer in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com | ||
* or visit www.terwer.space if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
module.exports = { | ||
semi: false, | ||
singleQuote: false, | ||
printWidth: 120 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# siyuan-hook | ||
|
||
siyuanhook for sy-post-publisher | ||
|
||
## Usage | ||
|
||
```js | ||
// usage | ||
``` | ||
|
||
## Deps | ||
|
||
``` | ||
## Congregations! siyuan-hook need no deps, it is just pure js code 🎉 | ||
``` | ||
|
||
## Dev | ||
|
||
```bash | ||
pnpm dev -F siyuan-hook | ||
``` | ||
|
||
## Build | ||
|
||
```bash | ||
pnpm build -F siyuan-hook | ||
``` | ||
|
||
## Test | ||
|
||
Execute the unit tests via [vitest](https://vitest.dev) | ||
|
||
```bash | ||
pnpm test -F siyuan-hook | ||
``` | ||
|
||
## Publish | ||
|
||
```bash | ||
pnpm publish -F siyuan-hook --tag latest | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + Vue + TS</title> | ||
</head> | ||
<body> | ||
This file is for lib hot-load test only, see <a href="/src/index.ts">/src/index.ts</a> | ||
<script type="module" src="/src/index.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "siyuan-hook", | ||
"version": "0.0.1", | ||
"type": "module", | ||
"description": "siyuanhook for sy-post-publisher", | ||
"repository": "terwer/siyuan-plugin-publisher", | ||
"homepage": "https://github.com/terwer/siyuan-plugin-publisher/tree/main/libs/siyuan-hook", | ||
"author": "terwer", | ||
"license": "GPL", | ||
"files": [ | ||
"dist", | ||
"README.md" | ||
], | ||
"keywords": [ | ||
"zhi", | ||
"lib" | ||
], | ||
"scripts": { | ||
"serve": "vite", | ||
"dev": "vite build --watch", | ||
"build": "vite build", | ||
"start": "vite preview", | ||
"test": "vitest --watch" | ||
}, | ||
"devDependencies": { | ||
"@terwer/eslint-config-custom": "^1.2.0", | ||
"@terwer/vite-config-custom": "^0.2.0" | ||
}, | ||
"dependencies": { | ||
"@terwer/publisher-hook": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* Copyright (c) 2023, Terwer . All rights reserved. | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* This code is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License version 2 only, as | ||
* published by the Free Software Foundation. Terwer designates this | ||
* particular file as subject to the "Classpath" exception as provided | ||
* by Terwer in the LICENSE file that accompanied this code. | ||
* | ||
* This code is distributed in the hope that it will be useful, but WITHOUT | ||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
* version 2 for more details (a copy is included in the LICENSE file that | ||
* accompanied this code). | ||
* | ||
* You should have received a copy of the GNU General Public License version | ||
* 2 along with this work; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
* | ||
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com | ||
* or visit www.terwer.space if you need additional information or have any | ||
* questions. | ||
*/ | ||
|
||
// 警告1⚠️:请勿在非思源笔记浏览器环境调用此文件中的任何方法 | ||
// 警告2⚠️:此文件请勿引用其他任何需要编译的类库 | ||
// 提示3⚠️:此文件是挂件唯一的hook入口 | ||
|
||
import { PublishHook, DeviceDetection, BrowserUtil, DeviceTypeEnum } from "@terwer/publisher-hook" | ||
|
||
// 统一的初始化入口 | ||
;(async () => { | ||
console.warn( | ||
"从 0.6.8+ 开始,siyuanhook.js 将作为挂件统一的 hook 入口。" + | ||
"当前 siyuanhook.js 源码已迁移至:https://github.com/terwer/siyuan-plugin-publisher/tree/main/libs/siyuan-hook 统一管理。" | ||
) | ||
try { | ||
const device = DeviceDetection.getDevice() | ||
const publisherHook = new PublishHook() | ||
|
||
// init | ||
const init = async () => { | ||
// Electron里面有3种情况 | ||
// 1、js片段 | ||
// 2、iframe挂件 | ||
// 3、新窗口打开 | ||
const isElectron = BrowserUtil.isElectron() | ||
if (!isElectron) { | ||
console.warn("不在Electron环境中,插槽菜单、JsonLocalStorage等将不可用") | ||
return | ||
} | ||
|
||
// iframe挂件 | ||
const initIframeWidget = () => { | ||
publisherHook.doInit({ | ||
// 挂载JsonLocalStorage到window | ||
isInitLocalStorage: true, | ||
// 初始化插槽 | ||
isInitSlot: true, | ||
// 初始化主题适配 | ||
isInitThemeAdaptor: true, | ||
// 初始化发布辅助功能 | ||
isInitPublishHelper: true, | ||
// 初始化PicGO配置 | ||
isInitPicgoExtension: true, | ||
// 初始化SyCmd配置 | ||
isInitCmder: true, | ||
}) | ||
} | ||
|
||
// 新窗口打开 | ||
const initSiyuanNewWin = () => { | ||
publisherHook.doInit({ | ||
// 挂载JsonLocalStorage到window | ||
isInitLocalStorage: true, | ||
// 初始化发布辅助功能 | ||
isInitPublishHelper: true, | ||
// 初始化PicGO配置 | ||
isInitPicgoExtension: true, | ||
// 初始化SyCmd配置 | ||
isInitCmder: true, | ||
}) | ||
} | ||
|
||
// js片段 | ||
const initJsCode = () => { | ||
publisherHook.doInit({ | ||
// 挂载JsonLocalStorage到window | ||
isInitLocalStorage: true, | ||
// 初始化插槽 | ||
isInitSlot: true, | ||
// 初始化主题适配 | ||
isInitThemeAdaptor: true, | ||
// 初始化发布辅助功能 | ||
isInitPublishHelper: true, | ||
// 初始化PicGO配置 | ||
isInitPicgoExtension: true, | ||
// 初始化SyCmd配置 | ||
isInitCmder: true, | ||
}) | ||
} | ||
|
||
if (device == DeviceTypeEnum.DeviceType_Siyuan_Widget) { | ||
// iframe挂件 | ||
initIframeWidget() | ||
} else { | ||
if (device == DeviceTypeEnum.DeviceType_Siyuan_NewWin) { | ||
// 新窗口打开 | ||
initSiyuanNewWin() | ||
} else { | ||
// 自定义js片段 | ||
initJsCode() | ||
} | ||
} | ||
} | ||
|
||
// 启动入口 | ||
await init() | ||
} catch (e) { | ||
console.warn("初始化siyuanhook失败,可能导致扩展功能无法使用,请知悉。错误信息如下", e) | ||
} | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"useDefineForClassFields": true, | ||
"module": "ESNext", | ||
"lib": [ | ||
"ES2020", | ||
"DOM", | ||
"DOM.Iterable" | ||
], | ||
"skipLibCheck": true, | ||
/* Bundler mode */ | ||
"moduleResolution": "Node", | ||
// "allowImportingTsExtensions": true, | ||
"allowSyntheticDefaultImports": true, | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"jsx": "preserve", | ||
/* Linting */ | ||
"strict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"types": [ | ||
"node", | ||
"vite/client" | ||
] | ||
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
"src/**/*.d.ts", | ||
"src/**/*.tsx", | ||
"src/**/*.vue" | ||
], | ||
"references": [ | ||
{ | ||
"path": "./tsconfig.node.json" | ||
} | ||
], | ||
"root": "." | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"composite": true, | ||
"skipLibCheck": true, | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"allowSyntheticDefaultImports": true | ||
}, | ||
"include": ["vite.config.ts"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/// <reference types="vitest" /> | ||
|
||
import { resolve } from "path" | ||
import { defineConfig } from "vite" | ||
import minimist from "minimist"; | ||
|
||
const args = minimist(process.argv.slice(2)) | ||
const isWatch = args.watch || args.w | ||
const devDistDir = "/Users/terwer/Documents/mydocs/siyuan-widgets/sy-post-publisher/public/lib" | ||
const distDir = isWatch ? devDistDir : "./dist" | ||
|
||
export default defineConfig({ | ||
build: { | ||
// 输出路径 | ||
outDir: distDir, | ||
|
||
lib: { | ||
// Could also be a dictionary or array of multiple entry points | ||
entry: resolve(__dirname, "src/siyuanhook.ts"), | ||
// the proper extensions will be added | ||
fileName: "siyuanhook", | ||
formats: ["cjs"], | ||
}, | ||
rollupOptions: { | ||
// make sure to externalize deps that shouldn't be bundled | ||
// into your library | ||
external: [], | ||
output: { | ||
entryFileNames: "[name].js", | ||
}, | ||
}, | ||
minify: false, | ||
}, | ||
|
||
test: { | ||
globals: true, | ||
environment: "jsdom", | ||
include: ["src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"], | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.