utools-api-types 7.5.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,102 +1,112 @@
1
- # uTools 官方类型辅助文件
1
+ # 类型定义
2
2
 
3
- ## 提供代码提示文件
3
+ uTools 提供官方的 API 类型定义,可在插件应用开发过程中获得代码提示和类型检查支持。
4
4
 
5
- - [utools.api.d.ts](./utools.api.d.ts) `window.utools` 对象类型提示
6
- - [electron.d.ts](./electron.d.ts) preload 内 `electron` 模块导入提示
7
- - [resource/utools.schema](./resource/utools.schema.json) 配置文件 JSON Schema
5
+ ## uTools API 类型定义
8
6
 
9
- ## `window.utools` 对象类型提示
7
+ [`utools-api-types`](https://github.com/uTools-Labs/utools-api-types) 是 uTools 官方维护的 TypeScript 类型定义库,提供当前 `utools` API 的完整类型定义,并会随着 uTools API 的版本迭代持续更新。
10
8
 
11
- 目前将 utools 挂载到全局 window 下,提供在渲染层跟 preload 层的群体代码提示
9
+ 无论使用 JavaScript 还是 TypeScript 开发插件应用,都可以借助它获得 `utools` API 的代码提示和类型检查。
12
10
 
13
- 第一步
11
+ > `utools-api-types` 基于全局变量 `utools` 进行类型声明,安装并配置后无需手动引入,编辑器即可自动识别。
14
12
 
15
- ```bash
13
+ ## 安装
14
+
15
+ 在项目中安装 `utools-api-types`:
16
+
17
+ ::: code-group
18
+
19
+ ```shell [npm]
16
20
  npm install utools-api-types --save-dev
17
21
  ```
18
22
 
19
- 第二步 配置 tsconfig.json
23
+ ```shell [pnpm]
24
+ pnpm add -D utools-api-types
25
+ ```
26
+
27
+ ```shell [yarn]
28
+ yarn add -D utools-api-types
29
+ ```
30
+
31
+ :::
32
+
33
+ ## JavaScript 项目
34
+
35
+ ### 配置 jsconfig.json
20
36
 
21
- ```json
37
+ 在项目根目录创建 `jsconfig.json`,并在 `compilerOptions.types` 中引入 `utools-api-types`:
38
+
39
+ ```json5
22
40
  {
23
41
  "compilerOptions": {
24
42
  "types": ["utools-api-types"]
25
43
  },
26
- "includes": [
27
- // 如果使用ts或者框架,请添加需要类型提示的文件范围
28
- // 案例:
29
- // src/**/*.ts
30
- // preload.js
44
+ "include": [
45
+ // 需要类型提示和类型检查的文件范围,请根据项目实际目录结构调整
46
+ "src/**/*.js",
47
+ "bridge/**/*.js"
31
48
  ]
32
49
  }
33
50
  ```
34
51
 
35
- ### API 代码示例
52
+ ## TypeScript 项目
36
53
 
37
- ```javascript
38
- // 默认浏览器打开网页
39
- window.utools.shellOpenExternal("https://u.tools");
54
+ ### 配置 tsconfig.json
40
55
 
41
- // 在资源管理器中显示文件
42
- window.utools.shellShowItemInFolder("d:\\test");
56
+ 在 `tsconfig.json` 的 `compilerOptions.types` 中添加 `utools-api-types`:
43
57
 
44
- // ubrowser 网页自动化
45
- window.utools.ubrowser
46
- .goto("https://cn.bing.com")
47
- .value("#sb_form_q", "uTools")
48
- .click("#sb_form_go")
49
- .run({ width: 1000, height: 600 });
58
+ ```json5
59
+ {
60
+ "compilerOptions": {
61
+ "types": ["utools-api-types"]
62
+ },
63
+ "include": [
64
+ // 需要类型提示和类型检查的文件范围,请根据项目实际目录结构调整
65
+ "src/**/*.ts",
66
+ "bridge/**/*.js"
67
+ ]
68
+ }
69
+ ```
50
70
 
51
- // 值键对方式存储数据
52
- window.utools.dbStorage.setItem("key", "value");
71
+ 字段说明:
53
72
 
54
- // 执行截图
55
- window.utools.screenCapture((imagebase64) => {
56
- // 截图完的回调
57
- });
73
+ | 字段 | 说明 |
74
+ | --- | --- |
75
+ | `compilerOptions.types` | 指定参与类型检查的全局类型定义包,需包含 `utools-api-types` |
76
+ | `include` | 指定需要提供代码提示和类型检查的文件范围,请根据项目实际目录结构调整 |
58
77
 
59
- // 执行取色
60
- window.utools.screenColorPick(({ hex, rgb }) => {
61
- // 取色完的回调
62
- });
63
- ```
78
+ > 如果项目已经通过其他方式配置了 `types`,请将 `utools-api-types` 追加到现有配置中,避免覆盖原有类型定义。
64
79
 
65
- ## `electron` 模块代码提示
80
+ ## 验证代码提示
66
81
 
67
- 引入此类型文件后,支持在 cjs 模式下也提供定制化的 `electron` 模块 api 提示
82
+ 配置完成后,在 `include` 范围内的文件中输入 `window.utools.`,编辑器即可提示可用的 API:
68
83
 
69
- > 在 uTools 中,可以通过 cjs 的形式直接使用部分 `electron` 的 api ,但是此部分支持是直接通过 uTools 内置的 nodejs 实现,因此请勿下载额外的 `electron` 依赖。
84
+ ```js
85
+ window.utools.
86
+ ```
70
87
 
71
- ### API 代码示例
88
+ 编辑器还会根据 API 类型定义提供参数提示、返回值提示和类型检查。例如:
72
89
 
73
- ```javascript
74
- // preload.js
90
+ ```js
91
+ window.utools.showNotification('hello world')
92
+ ```
75
93
 
76
- const { ipcRenderer } = require("electron");
94
+ ## 常见问题
77
95
 
78
- window.onMyChannel = (callback) => {
79
- ipcRenderer.on("myChannel", (e, data) => {
80
- callback?.({
81
- ...data,
82
- senderId: e.senderId,
83
- });
84
- });
85
- };
96
+ ### 编辑器没有代码提示
86
97
 
87
- window.ipc = ipcRenderer;
88
- ```
98
+ - 确认已安装 `utools-api-types`,并在 `jsconfig.json` 或 `tsconfig.json` 中完成配置。
99
+ - 确认当前编辑的文件处于 `include` 指定的文件范围内。
100
+ - 若修改配置后仍无提示,请重启编辑器,或重新加载 TypeScript/JavaScript 语言服务。
89
101
 
90
- ## 配置文件 JSON Schema
102
+ ### 与已有 types 配置冲突
91
103
 
92
- 通过 JSON Schema 实现了在 `plugin.json` 内的代码提示
104
+ 如果项目已通过其他方式配置了 `compilerOptions.types`,请将 `utools-api-types` 追加到现有数组中,避免覆盖原有类型定义。
93
105
 
94
- 引入 JSON Schema 需要在 `plugin.json` 的第一行添加 `$schema` 字段:
106
+ ### 类型定义与实际版本不一致
95
107
 
96
- ```json
97
- {
98
- "$schema": "./node_modules/utools-api-types/resource/utools.schema.json"
99
- }
100
- ```
108
+ `utools-api-types` 会随 uTools API 版本迭代更新,如发现类型缺失或过期,请升级到最新版本:
101
109
 
102
- > 添加 `$schema` 时,需要注意跟 `plugin.json` 所在的文件位置有关系,必须是相对于 `plugin.json` 的位置
110
+ ```shell
111
+ npm install utools-api-types@latest --save-dev
112
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utools-api-types",
3
- "version": "7.5.0",
3
+ "version": "8.0.0",
4
4
  "description": "TypeScript definitions for uTools API",
5
5
  "repository": {
6
6
  "type": "git",
@@ -22,6 +22,6 @@
22
22
  }
23
23
  },
24
24
  "dependencies": {
25
- "@types/sharp": "^0.31.1"
25
+ "@types/sharp": "^0.32.0"
26
26
  }
27
27
  }