mn-docs-mcp 0.6.1 → 1.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/astro.config.mjs +4 -0
- package/package.json +1 -1
- package/src/content/docs/guides/contributing.md +4 -4
- package/src/content/docs/guides/getting-started.md +2 -2
- package/src/content/docs/guides/lifecycle-and-window.md +4 -4
- package/src/content/docs/guides/mindmap-and-selection.md +1 -1
- package/src/content/docs/guides/native-ui.md +2 -2
- package/src/content/docs/guides/network-requests.md +7 -8
- package/src/content/docs/guides/notes-and-database.md +1 -1
- package/src/content/docs/guides/shortcut-keys.md +9 -9
- package/src/content/docs/guides/storage-and-files.md +3 -3
- package/src/content/docs/guides/toolbar-and-commands.md +1 -1
- package/src/content/docs/reference/black-box.md +2 -2
- package/src/content/docs/reference/foundation/ns-attributed-string.md +1 -1
- package/src/content/docs/reference/foundation/ns-counted-set.md +1 -1
- package/src/content/docs/reference/foundation/ns-date-components.md +2 -2
- package/src/content/docs/reference/foundation/ns-date-formatter.md +1 -3
- package/src/content/docs/reference/foundation/ns-decimal-number.md +1 -1
- package/src/content/docs/reference/foundation/ns-enumerator.md +1 -1
- package/src/content/docs/reference/foundation/ns-error.md +2 -2
- package/src/content/docs/reference/foundation/ns-file-manager.md +1 -1
- package/src/content/docs/reference/foundation/ns-formatter.md +2 -2
- package/src/content/docs/reference/foundation/ns-json-serialization.md +10 -2
- package/src/content/docs/reference/foundation/ns-mutable-attributed-string.md +1 -1
- package/src/content/docs/reference/foundation/ns-mutable-character-set.md +1 -1
- package/src/content/docs/reference/foundation/ns-mutable-dictionary.md +1 -1
- package/src/content/docs/reference/foundation/ns-mutable-index-set.md +1 -1
- package/src/content/docs/reference/foundation/ns-mutable-set.md +1 -1
- package/src/content/docs/reference/foundation/ns-mutable-string.md +1 -1
- package/src/content/docs/reference/foundation/ns-mutable-url-request.md +2 -3
- package/src/content/docs/reference/foundation/ns-null.md +1 -1
- package/src/content/docs/reference/foundation/ns-number-formatter.md +2 -2
- package/src/content/docs/reference/foundation/ns-operation.md +2 -2
- package/src/content/docs/reference/foundation/ns-pointer-array.md +1 -1
- package/src/content/docs/reference/foundation/ns-proxy.md +5 -3
- package/src/content/docs/reference/foundation/ns-scanner.md +7 -1
- package/src/content/docs/reference/foundation/ns-set.md +1 -1
- package/src/content/docs/reference/foundation/ns-simple-c-string.md +3 -4
- package/src/content/docs/reference/foundation/ns-time-zone.md +1 -1
- package/src/content/docs/reference/foundation/ns-timer.md +1 -1
- package/src/content/docs/reference/foundation/ns-ubiquitous-key-value-store.md +61 -0
- package/src/content/docs/reference/foundation/ns-url-connection.md +2 -2
- package/src/content/docs/reference/foundation/ns-url-request.md +2 -2
- package/src/content/docs/reference/foundation/ns-url-response.md +5 -5
- package/src/content/docs/reference/foundation/ns-url.md +1 -1
- package/src/content/docs/reference/foundation/ns-user-defaults.md +4 -4
- package/src/content/docs/reference/foundation/ns-value.md +15 -15
- package/src/content/docs/reference/global/agent-tools.md +91 -0
- package/src/content/docs/reference/global/application.md +5 -5
- package/src/content/docs/reference/global/builtin-commands.md +2 -2
- package/src/content/docs/reference/global/database.md +4 -4
- package/src/content/docs/reference/global/document.md +21 -0
- package/src/content/docs/reference/global/global-variables.md +22 -5
- package/src/content/docs/reference/global/jsb.md +7 -5
- package/src/content/docs/reference/global/note.md +5 -5
- package/src/content/docs/reference/global/notebook.md +21 -0
- package/src/content/docs/reference/global/popup-menu-item.md +2 -2
- package/src/content/docs/reference/global/popup-menu.md +5 -6
- package/src/content/docs/reference/global/search-manager.md +12 -6
- package/src/content/docs/reference/global/self.md +1 -13
- package/src/content/docs/reference/js-runtime.md +6 -5
- package/src/content/docs/reference/marginnote/document-controller.md +41 -9
- package/src/content/docs/reference/marginnote/jsextension.md +7 -7
- package/src/content/docs/reference/marginnote/mb-book-note.md +123 -30
- package/src/content/docs/reference/marginnote/mb-book.md +6 -6
- package/src/content/docs/reference/marginnote/mb-model-tool.md +2 -2
- package/src/content/docs/reference/marginnote/mb-topic.md +18 -7
- package/src/content/docs/reference/marginnote/mindmap-node.md +4 -4
- package/src/content/docs/reference/marginnote/mindmap-view.md +2 -2
- package/src/content/docs/reference/marginnote/notebook-controller.md +3 -3
- package/src/content/docs/reference/marginnote/outline-view.md +2 -2
- package/src/content/docs/reference/marginnote/reader-controller.md +3 -3
- package/src/content/docs/reference/marginnote/study-controller.md +6 -6
- package/src/content/docs/reference/quartzcore/caanimation-group.md +3 -3
- package/src/content/docs/reference/quartzcore/cabasic-animation.md +3 -3
- package/src/content/docs/reference/quartzcore/caemitter-layer.md +44 -0
- package/src/content/docs/reference/quartzcore/cagradient-layer.md +1 -1
- package/src/content/docs/reference/quartzcore/cakeyframe-animation.md +3 -3
- package/src/content/docs/reference/quartzcore/calayer.md +1 -1
- package/src/content/docs/reference/quartzcore/camedia-timing-function.md +1 -1
- package/src/content/docs/reference/quartzcore/caproperty-animation.md +1 -1
- package/src/content/docs/reference/quartzcore/careplicator-layer.md +2 -2
- package/src/content/docs/reference/quartzcore/cascroll-layer.md +1 -1
- package/src/content/docs/reference/quartzcore/cashape-layer.md +2 -2
- package/src/content/docs/reference/quartzcore/catext-layer.md +4 -4
- package/src/content/docs/reference/quartzcore/catransaction.md +5 -3
- package/src/content/docs/reference/quartzcore/catransform-layer.md +3 -3
- package/src/content/docs/reference/quartzcore/catransition.md +10 -6
- package/src/content/docs/reference/quartzcore/cavalue-function.md +1 -1
- package/src/content/docs/reference/uikit/ns-mutable-paragraph-style.md +3 -3
- package/src/content/docs/reference/uikit/ns-paragraph-style.md +3 -4
- package/src/content/docs/reference/uikit/ns-text-storage.md +4 -5
- package/src/content/docs/reference/uikit/uiactivity-indicator-view.md +2 -2
- package/src/content/docs/reference/uikit/uiapplication.md +1 -1
- package/src/content/docs/reference/uikit/uibar-button-item.md +3 -4
- package/src/content/docs/reference/uikit/uibar-item.md +2 -3
- package/src/content/docs/reference/uikit/uibezier-path.md +2 -2
- package/src/content/docs/reference/uikit/uibutton.md +1 -1
- package/src/content/docs/reference/uikit/uicollection-view-cell.md +5 -5
- package/src/content/docs/reference/uikit/uicollection-view-controller.md +22 -2
- package/src/content/docs/reference/uikit/uicollection-view-flow-layout.md +54 -0
- package/src/content/docs/reference/uikit/uicollection-view-layout.md +9 -2
- package/src/content/docs/reference/uikit/uicollection-view.md +13 -4
- package/src/content/docs/reference/uikit/uicolor.md +1 -1
- package/src/content/docs/reference/uikit/uicontrol.md +3 -5
- package/src/content/docs/reference/uikit/uidate-picker.md +1 -1
- package/src/content/docs/reference/uikit/uievent.md +2 -2
- package/src/content/docs/reference/uikit/uifont.md +1 -1
- package/src/content/docs/reference/uikit/uigesture-recognizer.md +1 -1
- package/src/content/docs/reference/uikit/uiimage-picker-controller.md +1 -1
- package/src/content/docs/reference/uikit/uiimage-view.md +2 -2
- package/src/content/docs/reference/uikit/uiimage.md +2 -2
- package/src/content/docs/reference/uikit/uikey-command.md +2 -2
- package/src/content/docs/reference/uikit/uilabel.md +3 -3
- package/src/content/docs/reference/uikit/uilocal-notification.md +2 -2
- package/src/content/docs/reference/uikit/uilong-press-gesture-recognizer.md +2 -2
- package/src/content/docs/reference/uikit/uinavigation-bar.md +2 -2
- package/src/content/docs/reference/uikit/uinavigation-controller.md +1 -1
- package/src/content/docs/reference/uikit/uinavigation-item.md +1 -1
- package/src/content/docs/reference/uikit/uipage-control.md +1 -1
- package/src/content/docs/reference/uikit/uipage-view-controller.md +1 -1
- package/src/content/docs/reference/uikit/uipan-gesture-recognizer.md +1 -1
- package/src/content/docs/reference/uikit/uipasteboard.md +1 -1
- package/src/content/docs/reference/uikit/uipicker-view.md +3 -3
- package/src/content/docs/reference/uikit/uipinch-gesture-recognizer.md +1 -1
- package/src/content/docs/reference/uikit/uipopover-controller.md +1 -1
- package/src/content/docs/reference/uikit/uiresponder.md +3 -4
- package/src/content/docs/reference/uikit/uirotation-gesture-recognizer.md +1 -1
- package/src/content/docs/reference/uikit/uiscreen-mode.md +2 -2
- package/src/content/docs/reference/uikit/uiscrollview.md +1 -1
- package/src/content/docs/reference/uikit/uisearch-bar.md +25 -2
- package/src/content/docs/reference/uikit/uisegmented-control.md +1 -1
- package/src/content/docs/reference/uikit/uislider.md +1 -1
- package/src/content/docs/reference/uikit/uiswipe-gesture-recognizer.md +1 -1
- package/src/content/docs/reference/uikit/uiswitch.md +2 -2
- package/src/content/docs/reference/uikit/uitab-bar-controller.md +2 -2
- package/src/content/docs/reference/uikit/uitab-bar-item.md +1 -1
- package/src/content/docs/reference/uikit/uitab-bar.md +1 -1
- package/src/content/docs/reference/uikit/uitable-view-cell.md +6 -6
- package/src/content/docs/reference/uikit/uitable-view-controller.md +1 -1
- package/src/content/docs/reference/uikit/uitable-view.md +3 -3
- package/src/content/docs/reference/uikit/uitap-gesture-recognizer.md +2 -2
- package/src/content/docs/reference/uikit/uitext-input-mode.md +7 -3
- package/src/content/docs/reference/uikit/uitext-position.md +5 -5
- package/src/content/docs/reference/uikit/uitext-range.md +4 -4
- package/src/content/docs/reference/uikit/uitext-view.md +2 -2
- package/src/content/docs/reference/uikit/uitextfield.md +3 -3
- package/src/content/docs/reference/uikit/uitoolbar.md +1 -1
- package/src/content/docs/reference/uikit/uitouch.md +3 -3
- package/src/content/docs/reference/uikit/uiview-controller.md +2 -2
- package/src/content/docs/reference/uikit/uiview.md +5 -5
- package/src/content/docs/reference/uikit/uiwebview.md +5 -5
- package/src/content/docs/reference/uikit/uiwindow.md +2 -2
- package/src/content/docs/reference/utility/menu-controller.md +1 -1
- package/src/content/docs/reference/utility/sqlite-result-set.md +1 -1
- package/src/content/docs/reference/utility/sqlite-statement.md +2 -2
- package/src/content/docs/reference/utility/zip-archive.md +13 -14
- package/src/content/docs/reference/value-sturct.md +105 -0
package/astro.config.mjs
CHANGED
|
@@ -58,7 +58,10 @@ export default defineConfig({
|
|
|
58
58
|
{ label: 'Application', slug: 'reference/global/application' },
|
|
59
59
|
{ label: 'SearchManager', slug: 'reference/global/search-manager' },
|
|
60
60
|
{ label: 'Database', slug: 'reference/global/database' },
|
|
61
|
+
{ label: 'Document', slug: 'reference/global/document' },
|
|
62
|
+
{ label: 'Notebook', slug: 'reference/global/notebook' },
|
|
61
63
|
{ label: 'Note', slug: 'reference/global/note' },
|
|
64
|
+
{ label: 'AgentTools', slug: 'reference/global/agent-tools' },
|
|
62
65
|
{ label: 'PopupMenu', slug: 'reference/global/popup-menu' },
|
|
63
66
|
{ label: 'PopupMenuItem', slug: 'reference/global/popup-menu-item' },
|
|
64
67
|
{ label: 'self', slug: 'reference/global/self' },
|
|
@@ -102,6 +105,7 @@ export default defineConfig({
|
|
|
102
105
|
label: '运行时边界',
|
|
103
106
|
items: [
|
|
104
107
|
{ label: 'JavaScript 原生环境', slug: 'reference/js-runtime' },
|
|
108
|
+
{ label: 'Value Sturct', slug: 'reference/value-sturct' },
|
|
105
109
|
{ label: '隐藏的边界(The Black Box)', slug: 'reference/black-box' },
|
|
106
110
|
],
|
|
107
111
|
},
|
package/package.json
CHANGED
|
@@ -8,12 +8,12 @@ description: 文档贡献流程与格式规范(API 参考、教程、Markdown
|
|
|
8
8
|
## 贡献流程
|
|
9
9
|
|
|
10
10
|
1. **Fork** 本仓库到你的 GitHub 账号。
|
|
11
|
-
2. **创建分支**:从默认分支(如 `main
|
|
11
|
+
2. **创建分支**:从默认分支(如 `main`)拉取新分支,命名 `docs/xxx` 或 `fix/typo-xxx`。
|
|
12
12
|
3. **修改**:在本地或 GitHub 网页编辑器中修改文档。
|
|
13
13
|
4. **提交并推送**:提交到你的 Fork,推送到 GitHub。
|
|
14
14
|
5. **发起 Pull Request**:在本仓库创建 PR,目标分支为默认分支(如 `main`)。
|
|
15
15
|
|
|
16
|
-
**PR
|
|
16
|
+
**PR 描述应包含**:修改类型(纠错 / 新增教程 / 新增或修订 API 页)、涉及文件或路径、简要说明。
|
|
17
17
|
|
|
18
18
|
## 文档结构约定
|
|
19
19
|
|
|
@@ -76,7 +76,7 @@ description: 文档贡献流程与格式规范(API 参考、教程、Markdown
|
|
|
76
76
|
- **语言**:文档正文与说明统一使用**简体中文**;API 名称、代码、技术术语保留英文。
|
|
77
77
|
- **标点**:中文句子使用中文标点;英文或代码片段内使用英文标点。
|
|
78
78
|
- **专有名词**:MarginNote、API、JavaScript 等大小写保持一致;首次出现可加简短解释。
|
|
79
|
-
- **链接**:避免裸 URL,使用 `[描述](url)` 或 `[描述](/path/)`;API
|
|
79
|
+
- **链接**:避免裸 URL,使用 `[描述](url)` 或 `[描述](/path/)`;API 交叉引用用「相关」小节或正文内链接到对应 reference 页。
|
|
80
80
|
- **代码块**:标注语言、保持缩进一致;长示例可省略无关部分并用注释说明。
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
若对某条规范有疑问或改进意见,欢迎在 Issue 中提出。
|
|
@@ -7,7 +7,7 @@ description: 从零运行你的第一个 MarginNote 插件(Hello World)。
|
|
|
7
7
|
|
|
8
8
|
## 前提
|
|
9
9
|
|
|
10
|
-
- 已安装 MarginNote 3 或 MarginNote 4(MN3
|
|
10
|
+
- 已安装 MarginNote 3 或 MarginNote 4(MN3使用 3.6.11 及以上)。
|
|
11
11
|
- 了解如何将 .mnaddon 包安装到 MarginNote 并在应用中启用插件。
|
|
12
12
|
|
|
13
13
|
## 第一步:插件包结构
|
|
@@ -32,7 +32,7 @@ description: 从零运行你的第一个 MarginNote 插件(Hello World)。
|
|
|
32
32
|
}
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
- `addonid`:唯一 ID
|
|
35
|
+
- `addonid`:唯一 ID,用反向域名。
|
|
36
36
|
- `title`:在 MarginNote 中显示的插件名称。
|
|
37
37
|
- `marginnote_version_min`:最低支持的 MarginNote 版本。
|
|
38
38
|
|
|
@@ -11,7 +11,7 @@ description: 理解 scene/notebook/document 生命周期及何时可安全使用
|
|
|
11
11
|
|
|
12
12
|
| 方法 | 调用时机 |
|
|
13
13
|
|------|----------|
|
|
14
|
-
| `sceneWillConnect()` |
|
|
14
|
+
| `sceneWillConnect()` | 插件窗口即将创建,可在此做轻量初始化;此时会还没有打开笔记本。 |
|
|
15
15
|
| `sceneDidDisconnect()` | 插件窗口已断开。 |
|
|
16
16
|
| `sceneWillResignActive()` | 窗口即将失去活跃。 |
|
|
17
17
|
| `sceneDidBecomeActive()` | 窗口变为活跃。 |
|
|
@@ -33,8 +33,8 @@ description: 理解 scene/notebook/document 生命周期及何时可安全使用
|
|
|
33
33
|
## 何时可使用 studyController
|
|
34
34
|
|
|
35
35
|
- `studyController(window)` 返回的是**当前窗口**的学习控制器;只有在该窗口已经打开过笔记本、学习界面已就绪时,返回值才可用。
|
|
36
|
-
- 在 `sceneWillConnect`
|
|
37
|
-
- 在 `notebookWillOpen(topicid)` 被调用后,该窗口即将或已经拥有学习界面;但若需在「打开笔记本」后立刻挂载 UI
|
|
36
|
+
- 在 `sceneWillConnect` 中默认**还没有**打开笔记本,因此直接不要在这里依赖 `studyController(self.window)` 去访问脑图或文档。
|
|
37
|
+
- 在 `notebookWillOpen(topicid)` 被调用后,该窗口即将或已经拥有学习界面;但若需在「打开笔记本」后立刻挂载 UI,用 `NSTimer.scheduledTimerWithTimeInterval(0.2, false, function () { ... })` 延迟约 0.2 秒再执行,以确保 studyController 与 view 已就绪。
|
|
38
38
|
|
|
39
39
|
## 示例:在笔记本打开时打日志并延迟挂载 UI
|
|
40
40
|
|
|
@@ -59,7 +59,7 @@ notebookWillOpen: function (topicid) {
|
|
|
59
59
|
|
|
60
60
|
## 布局回调:controllerWillLayoutSubviews
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
若你在学习界面上添加了自定义视图,窗口尺寸或布局变化时会需要重新计算位置。实现 `controllerWillLayoutSubviews(controller)`,当传入的 controller 是当前窗口的 studyController 时,在其中更新你的面板 frame(例如根据 `controller.view.bounds` 计算)。
|
|
63
63
|
|
|
64
64
|
```javascript
|
|
65
65
|
controllerWillLayoutSubviews: function (controller) {
|
|
@@ -88,12 +88,12 @@ self.webView.loadRequest(NSURLRequest.requestWithURL(NSURL.URLWithString("http:/
|
|
|
88
88
|
|
|
89
89
|
```javascript
|
|
90
90
|
var html = "<html><body><h1>Hello</h1></body></html>";
|
|
91
|
-
self.webView.loadHTMLStringBaseURL(html, null); //
|
|
91
|
+
self.webView.loadHTMLStringBaseURL(html, null); // JS 中方法名为 loadHTMLStringBaseURL(string, baseURL);
|
|
92
92
|
```
|
|
93
93
|
|
|
94
94
|
### Delegate 回调(实例成员)
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
在 **viewWillAppear** 中设置 `self.webView.delegate = self`(确保每次显示时 delegate 有效),在 **viewWillDisappear** 中调用 `self.webView.stopLoading()` 并设置 `self.webView.delegate = null`,避免视图消失后仍收到回调。
|
|
97
97
|
|
|
98
98
|
在 `JSB.defineClass` 的第二个参数中定义:
|
|
99
99
|
|
|
@@ -9,7 +9,7 @@ description: 使用 NSURLConnection 发起 HTTP 请求;含 Base64 解码与 Re
|
|
|
9
9
|
|
|
10
10
|
- **读 data**:异步回调形参为 `(response, data, error)`。响应体在 **data**(NSData)里,处理结果以 data 为主;`response` 用于取 `statusCode()`,`error` 用于判断失败,不必用到所有参数。
|
|
11
11
|
- **data → JSON**:直接对 **NSData** 调用 `NSJSONSerialization.JSONObjectWithDataOptions(data, 0 或 1)`,得到 JS 对象;**不要**先转成字符串再 `JSON.parse`。
|
|
12
|
-
- **data →
|
|
12
|
+
- **data → 纯文本**:环境中无「NSData → 字符串」API ,用 `data.base64Encoding()` 得到 base64 字符串,再用 **Base64 解码**得到 JS 字符串。插件环境不提供 Base64 解码,需在插件内实现(见下一节完整代码)。
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
@@ -140,7 +140,7 @@ class MNNetwork {
|
|
|
140
140
|
NSOperationQueue.mainQueue(),
|
|
141
141
|
function (res, data, err) {
|
|
142
142
|
if (!MNNetwork.isNil(err)) {
|
|
143
|
-
reject(err.localizedDescription
|
|
143
|
+
reject(err.localizedDescription);
|
|
144
144
|
} else {
|
|
145
145
|
var response = new Response(data, res);
|
|
146
146
|
resolve(response);
|
|
@@ -156,7 +156,7 @@ class MNNetwork {
|
|
|
156
156
|
|
|
157
157
|
- `Response#text()`:用 `data.base64Encoding()` 得到 base64 串,再 `Base64.decode(encoding)` 得到 JS 字符串;环境无 Base64 解码,故依赖上面的 `base64.js`。
|
|
158
158
|
- `Response#json()`:直接对 **NSData** 调用 `NSJSONSerialization.JSONObjectWithDataOptions(this.data, 1)`,不经过 base64 或字符串。
|
|
159
|
-
- 错误信息:`error.localizedDescription`
|
|
159
|
+
- 错误信息:`error.localizedDescription` 为方法,需 `error.localizedDescription`,封装里已按「有则调用」处理。
|
|
160
160
|
|
|
161
161
|
---
|
|
162
162
|
|
|
@@ -231,9 +231,8 @@ async function fetchWithAuth() {
|
|
|
231
231
|
|
|
232
232
|
- **回调**:`NSURLConnection.sendAsynchronousRequestQueueCompletionHandler(request, NSOperationQueue.mainQueue(), function (response, data, error) { ... })`。有用的是 **data**(响应体)、可选的 `response.statusCode()`、以及 **error**(失败时)。
|
|
233
233
|
- **JSON**:直接对 **data**(NSData)解析,不要先转字符串再 `JSON.parse`:
|
|
234
|
-
- `var obj = NSJSONSerialization.JSONObjectWithDataOptions(data, 0);` 或选项 `1
|
|
234
|
+
- `var obj = NSJSONSerialization.JSONObjectWithDataOptions(data, 0);` 或选项 `1`(环境支持)。
|
|
235
235
|
- **纯文本**:无 Base64 解码时无法从 NSData 得到字符串;必须先按上文提供 `base64.js`,再 `var str = Base64.decode(data.base64Encoding());`。
|
|
236
|
-
- **错误**:`error.localizedDescription` 可能是属性或方法,建议统一写成:`var msg = (typeof error.localizedDescription === "function" ? error.localizedDescription() : error.localizedDescription) || "未知错误";`。
|
|
237
236
|
|
|
238
237
|
**原始 GET + JSON 示例**:
|
|
239
238
|
|
|
@@ -246,7 +245,7 @@ NSURLConnection.sendAsynchronousRequestQueueCompletionHandler(
|
|
|
246
245
|
NSOperationQueue.mainQueue(),
|
|
247
246
|
function (response, data, error) {
|
|
248
247
|
if (error) {
|
|
249
|
-
var msg =
|
|
248
|
+
var msg = error.localizedDescription;
|
|
250
249
|
Application.sharedInstance().alert("请求失败: " + msg);
|
|
251
250
|
return;
|
|
252
251
|
}
|
|
@@ -278,7 +277,7 @@ NSURLConnection.sendAsynchronousRequestQueueCompletionHandler(
|
|
|
278
277
|
NSOperationQueue.mainQueue(),
|
|
279
278
|
function (response, data, error) {
|
|
280
279
|
if (error) {
|
|
281
|
-
var msg =
|
|
280
|
+
var msg = error.localizedDescription;
|
|
282
281
|
Application.sharedInstance().alert("请求失败: " + msg);
|
|
283
282
|
return;
|
|
284
283
|
}
|
|
@@ -298,7 +297,7 @@ NSURLConnection.sendAsynchronousRequestQueueCompletionHandler(
|
|
|
298
297
|
| 响应体 | 使用回调中的 **data**(NSData),不必依赖 response 的其他字段 |
|
|
299
298
|
| data → JSON | `NSJSONSerialization.JSONObjectWithDataOptions(data, 0)` 或 `1`,直接对 data |
|
|
300
299
|
| data → 纯文本 | `data.base64Encoding()` 得到 base64 串,再 **Base64.decode**(需自备 base64.js) |
|
|
301
|
-
| 错误信息 | `error.localizedDescription`
|
|
300
|
+
| 错误信息 | `error.localizedDescription` |
|
|
302
301
|
|
|
303
302
|
推荐在插件内包含完整的 `base64.js` 与 `network.js`(如上),先 `JSB.require('base64')` 再 `JSB.require('network')`,然后用 `MNNetwork.fetch` 发起请求,在 try/catch 中用 `res.json()` 或 `res.text()` 处理 JSON 与纯文本。
|
|
304
303
|
|
|
@@ -47,7 +47,7 @@ if (note) {
|
|
|
47
47
|
|
|
48
48
|
## 创建新笔记
|
|
49
49
|
|
|
50
|
-
使用全局 `Note` 对象创建新笔记:`Note.createWithTitleNotebookDocument(title, notebook, doc)`(`notebook` 为 `MbTopic`,`doc` 为 `MbBook
|
|
50
|
+
使用全局 `Note` 对象创建新笔记:`Note.createWithTitleNotebookDocument(title, notebook, doc)`(`notebook` 为 `MbTopic`,`doc` 为 `MbBook`)。创建后同样放在 undoGrouping 中并刷新。
|
|
51
51
|
|
|
52
52
|
```javascript
|
|
53
53
|
var db = Database.sharedInstance();
|
|
@@ -5,7 +5,7 @@ description: 在JSExtension中注册快捷键,并用query/process稳定处理
|
|
|
5
5
|
|
|
6
6
|
MarginNote插件提供了一套“扩展快捷键”机制:你可以在插件主类(继承`JSExtension`)中实现`additionalShortcutKeys()`返回快捷键声明,然后用`queryShortcutKeyWithKeyFlags(command,keyFlags)`与`processShortcutKeyWithKeyFlags(command,keyFlags)`完成“可用性判断”和“按下处理”。
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
本页按标准教程结构介绍该机制:接口作用、注册方式、推荐实现范式、参数语义、组合键选择规范与常见问题。
|
|
9
9
|
|
|
10
10
|
## 概述
|
|
11
11
|
|
|
@@ -16,8 +16,8 @@ MarginNote插件提供了一套“扩展快捷键”机制:你可以在插件
|
|
|
16
16
|
|
|
17
17
|
边界与限制:
|
|
18
18
|
|
|
19
|
-
- 当用户正在编辑文本时(firstResponder
|
|
20
|
-
-
|
|
19
|
+
- 当用户正在编辑文本时(firstResponder在输入框/编辑器上),按键会被输入控件优先消费,插件快捷键不会稳定触发。这是预期行为。
|
|
20
|
+
- 组合键会与系统或应用内建快捷键冲突,导致命中率不稳定;应优先选择冲突更少的组合键,并允许用户自定义(如你的插件有设置页)。
|
|
21
21
|
|
|
22
22
|
## 接口一览
|
|
23
23
|
|
|
@@ -57,8 +57,8 @@ additionalShortcutKeys: function () {
|
|
|
57
57
|
|
|
58
58
|
这两者的职责必须严格区分:
|
|
59
59
|
|
|
60
|
-
- `queryShortcutKeyWithKeyFlags(...)
|
|
61
|
-
- `processShortcutKeyWithKeyFlags(...)
|
|
60
|
+
- `queryShortcutKeyWithKeyFlags(...)`用于“查询状态”。系统会在可用性判断、快捷键列表重建、焦点变化等场景批量调用它,因此调用次数与传入参数都会远超你的预期。为了保证性能与行为可控,在query中只做轻量判断并返回状态:避免任何IO操作、耗时计算、网络请求、文件读写,以及无差别日志输出;更不要在这里修改笔记/数据库或触发UI。
|
|
61
|
+
- `processShortcutKeyWithKeyFlags(...)`用于“处理按下”。真正的业务动作应放在这里;如果会修改笔记/笔记本数据,使用`UndoManager.undoGrouping(...)`包裹,保证撤销/重做稳定。
|
|
62
62
|
|
|
63
63
|
推荐写法:只匹配你关心的组合键,其余保持静默(例如直接`return null`)。
|
|
64
64
|
|
|
@@ -66,7 +66,7 @@ additionalShortcutKeys: function () {
|
|
|
66
66
|
|
|
67
67
|
### command
|
|
68
68
|
|
|
69
|
-
`command
|
|
69
|
+
`command`是系统传入的标识。已确认它是:
|
|
70
70
|
|
|
71
71
|
- 内建命令名:例如`NewChildNote`、`ToggleExpand`、`EditAddTitle`等。
|
|
72
72
|
- 输入常量/字符:例如`UIKeyInputLeftArrow`、`UIKeyInputUpArrow`,以及`z`这类字符输入。
|
|
@@ -86,16 +86,16 @@ additionalShortcutKeys: function () {
|
|
|
86
86
|
| Command+Shift | `1179648` |
|
|
87
87
|
|
|
88
88
|
|
|
89
|
-
##
|
|
89
|
+
## 组合键选择规范
|
|
90
90
|
|
|
91
91
|
- 优先选择不常被系统/应用占用的组合键。
|
|
92
92
|
- 避免与“通用编辑快捷键”冲突(例如撤销/重做/复制粘贴等),除非你非常确定不会影响用户习惯。
|
|
93
|
-
-
|
|
93
|
+
- 若某个组合键命中率不稳定,默认是冲突或编辑态吞键导致;提供替代键位或设置项。
|
|
94
94
|
|
|
95
95
|
## 注意事项
|
|
96
96
|
|
|
97
97
|
- 在query里做副作用:导致“未按下也触发动作”、撤销链异常、或出现难以定位的状态错乱。
|
|
98
|
-
- 无差别打印日志:query
|
|
98
|
+
- 无差别打印日志:query会被批量调用,导致刷屏,反而遮蔽真正有用的命中日志。
|
|
99
99
|
- 忽略编辑态:用户在输入时快捷键不触发属于预期,需要在产品交互上规避或提示。
|
|
100
100
|
|
|
101
101
|
## 相关
|
|
@@ -23,7 +23,7 @@ var counter = defaults.integerForKey("my_addon_counter");
|
|
|
23
23
|
var on = defaults.boolForKey("my_addon_switch");
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
键名加插件前缀,避免与其他插件冲突。
|
|
27
27
|
|
|
28
28
|
## NSFileManager:目录与文件
|
|
29
29
|
|
|
@@ -50,7 +50,7 @@ textData.writeToFileAtomically(filePath, true);
|
|
|
50
50
|
读取文件为 NSData 后,若需转为 JS 可用的形式:
|
|
51
51
|
|
|
52
52
|
- **若文件为 JSON**:用 `NSJSONSerialization.JSONObjectWithDataOptions(data, 0)` 解析为对象/数组;解析前可用 `data.length() === 0` 判断是否为空。
|
|
53
|
-
-
|
|
53
|
+
- **若需纯文本字符串**:使用 `NSString.stringWithContentsOfData(data)` 将 `NSData` 转为字符串。
|
|
54
54
|
|
|
55
55
|
示例:从文件读取 JSON 并解析
|
|
56
56
|
|
|
@@ -67,7 +67,7 @@ if (data && data.length() > 0) {
|
|
|
67
67
|
## 路径说明
|
|
68
68
|
|
|
69
69
|
- `Application.sharedInstance().documentPath`:文稿目录,适合存放用户数据。
|
|
70
|
-
- `Application.sharedInstance().tempPath
|
|
70
|
+
- `Application.sharedInstance().tempPath`:临时目录,系统会清理。
|
|
71
71
|
- 插件包根路径由 `JSB.newAddon(mainPath)` 的 `mainPath` 传入,可用于读取包内资源(如图标)。
|
|
72
72
|
|
|
73
73
|
## 完整示例:保存与读取一个开关
|
|
@@ -12,7 +12,7 @@ MarginNote 会调用插件的 `queryAddonCommandStatus()`。若希望显示工
|
|
|
12
12
|
| 字段 | 类型 | 说明 |
|
|
13
13
|
|------|------|------|
|
|
14
14
|
| `image` | string | 图标文件名(相对于插件包根目录,如 `'sample.png'`)。 |
|
|
15
|
-
| `object` | object |
|
|
15
|
+
| `object` | object | 接收点击的对象,为 `self`(插件实例)。 |
|
|
16
16
|
| `selector` | string | 点击时调用的方法名,**必须以冒号结尾**(如 `'toggleSample:'`)。 |
|
|
17
17
|
| `checked` | boolean | 是否显示为「选中」状态(如面板是否已显示)。 |
|
|
18
18
|
|
|
@@ -3,7 +3,7 @@ title: 隐藏的边界(The Black Box)
|
|
|
3
3
|
description: 只作为属性返回、但没有 JSExport 接口文件的对象与风险边界。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
本节记录一些在 API
|
|
6
|
+
本节记录一些在 API 中会“能拿到对象实例”,但由于**没有对应的 `JSB*.h`(JSExport)接口文件**,因此你无法在 JS 中安全地调用其独有方法的“黑盒对象”。
|
|
7
7
|
|
|
8
8
|
典型表现:某个对象作为属性被返回,但你在文档/头文件清单里找不到它的 JSB 接口定义。
|
|
9
9
|
|
|
@@ -13,7 +13,7 @@ description: 只作为属性返回、但没有 JSExport 接口文件的对象与
|
|
|
13
13
|
- `NSTextContainer`:同上。
|
|
14
14
|
- `UIFontDescriptor`:在头文件中被注释掉或未导出。
|
|
15
15
|
|
|
16
|
-
##
|
|
16
|
+
## 规范
|
|
17
17
|
|
|
18
18
|
- **不要**依赖 KVC/KVO 等高危手段“硬调用”黑盒对象。
|
|
19
19
|
- 如果必须实现相关功能:优先寻找已导出对象提供的替代 API(例如通过 `UITextView`/`NSAttributedString` 侧可用方法绕开)。
|
|
@@ -3,7 +3,7 @@ title: NSDateComponents
|
|
|
3
3
|
description: 日期组成部分(年/月/日/时/分/秒等)。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
`NSDateComponents`
|
|
6
|
+
`NSDateComponents` 用于表示日期的组成部分(年/月/日/时/分/秒等)。默认与 `NSCalendar`(如可用)配合用于构造/分解日期。
|
|
7
7
|
|
|
8
8
|
## 实例成员 (Instance members)
|
|
9
9
|
|
|
@@ -16,7 +16,7 @@ description: 日期组成部分(年/月/日/时/分/秒等)。
|
|
|
16
16
|
|
|
17
17
|
## 类成员 (Class members)
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
当前接口未额外暴露 `NSDateComponents` 的类成员。
|
|
20
20
|
|
|
21
21
|
## 相关
|
|
22
22
|
|
|
@@ -9,13 +9,11 @@ description: 日期格式化与解析。
|
|
|
9
9
|
|
|
10
10
|
### 创建
|
|
11
11
|
|
|
12
|
-
通过 `new
|
|
12
|
+
通过 `new NSDateFormatter()` 创建。
|
|
13
13
|
|
|
14
14
|
```javascript
|
|
15
15
|
// 示例
|
|
16
16
|
var formatter = new NSDateFormatter();
|
|
17
|
-
// 或
|
|
18
|
-
var formatter = NSDateFormatter.alloc().init();
|
|
19
17
|
```
|
|
20
18
|
|
|
21
19
|
## 实例成员 (Instance members)
|
|
@@ -3,7 +3,7 @@ title: NSError
|
|
|
3
3
|
description: 错误对象,包含 domain/code/userInfo 与本地化描述信息。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
`NSError` 用于表示错误信息。网络请求(如 `NSURLConnection`)或文件
|
|
6
|
+
`NSError` 用于表示错误信息。网络请求(如 `NSURLConnection`)或文件API会通过`NSError **`返回错误对象,JS侧默认作为回调参数或返回值的一部分出现。
|
|
7
7
|
|
|
8
8
|
## 类成员 (Class members)
|
|
9
9
|
|
|
@@ -44,7 +44,7 @@ static errorWithDomainCodeUserInfo(domain: string, code: number, userInfo: NSDic
|
|
|
44
44
|
|
|
45
45
|
### `initWithDomainCodeUserInfo`
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
初始化错误实例(默认由工厂方法创建,较少直接调用)。
|
|
48
48
|
|
|
49
49
|
```javascript
|
|
50
50
|
initWithDomainCodeUserInfo(domain: string, code: number, userInfo: NSDictionary): void
|
|
@@ -65,7 +65,7 @@ createDirectoryAtPathWithIntermediateDirectoriesAttributes(path: string, withInt
|
|
|
65
65
|
| :--- | :--- | :--- |
|
|
66
66
|
| `path` | `string` | 目录路径。 |
|
|
67
67
|
| `withIntermediateDirectories` | `boolean` | 是否创建中间目录。 |
|
|
68
|
-
| `attributes` | `NSDictionary \| null` |
|
|
68
|
+
| `attributes` | `NSDictionary \| null` | 目录属性(默认传 null)。 |
|
|
69
69
|
|
|
70
70
|
### `createDirectoryAtPathAttributes` (简易版)
|
|
71
71
|
|
|
@@ -5,7 +5,7 @@ description: 格式化基类(对象↔字符串转换)。
|
|
|
5
5
|
|
|
6
6
|
`NSFormatter` 是格式化器基类,用于把对象转换成字符串、或从字符串解析回对象。
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
常用的是其具体子类(例如 `NSDateFormatter`、`NSNumberFormatter`)。
|
|
9
9
|
|
|
10
10
|
## 实例成员 (Instance members)
|
|
11
11
|
|
|
@@ -128,4 +128,4 @@ isPartialStringValidProposedSelectedRangeOriginalStringOriginalSelectedRangeErro
|
|
|
128
128
|
|
|
129
129
|
## 类成员 (Class members)
|
|
130
130
|
|
|
131
|
-
|
|
131
|
+
当前接口未额外暴露 `NSFormatter` 的类成员。
|
|
@@ -7,7 +7,7 @@ description: JSON 与 Foundation 对象之间的序列化与反序列化。
|
|
|
7
7
|
|
|
8
8
|
## 实例成员 (Instance members)
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
当前接口未额外暴露 `NSJSONSerialization` 的实例成员;默认直接使用其类成员完成序列化/反序列化。
|
|
11
11
|
|
|
12
12
|
## 类成员 (Class members)
|
|
13
13
|
|
|
@@ -17,7 +17,15 @@ description: JSON 与 Foundation 对象之间的序列化与反序列化。
|
|
|
17
17
|
| `dataWithJSONObjectOptions(obj, options)` | obj, options: number | NSData | 将对象/数组序列化为 NSData。 |
|
|
18
18
|
| `JSONObjectWithDataOptions(data, options)` | data: NSData, options: number | any | 将 NSData 解析为对象/数组。 |
|
|
19
19
|
|
|
20
|
-
options
|
|
20
|
+
`options`默认传`0`。最新导出接口不包含`error`参数。
|
|
21
|
+
|
|
22
|
+
### 已确认行为
|
|
23
|
+
|
|
24
|
+
- `JSONObjectWithDataOptions(data, 0)`解析非法JSON时返回`undefined`,不抛桥接层错误。
|
|
25
|
+
- `dataWithJSONObjectOptions(obj, 0)`在传入包含函数成员的对象时,插件环境仍会返回`NSData`。
|
|
26
|
+
- `isValidJSONObject(obj)`对包含函数成员的对象返回`true`。
|
|
27
|
+
|
|
28
|
+
要求:不要只依赖`isValidJSONObject`判断可序列化性,序列化后仍应检查返回值并记录日志。
|
|
21
29
|
|
|
22
30
|
## 相关
|
|
23
31
|
|
|
@@ -41,7 +41,7 @@ static dictionaryWithSharedKeySet(sharedKeySet: any): NSMutableDictionary
|
|
|
41
41
|
static sharedKeySetForKeys(keys: NSArray): any
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
> 注:`NSMutableDictionary`
|
|
44
|
+
> 注:`NSMutableDictionary` 的工厂方法在插件环境的导出范围较小;请以本页底部的「头文件 API 清单」为准。
|
|
45
45
|
|
|
46
46
|
## 实例成员 (Instance members)
|
|
47
47
|
|
|
@@ -5,7 +5,7 @@ description: 可变 URL 请求对象(NSURLRequest 子类),用于设置 met
|
|
|
5
5
|
|
|
6
6
|
完整用法见 [网络请求](/guides/network-requests/) 教程。
|
|
7
7
|
|
|
8
|
-
`NSMutableURLRequest` 继承自 `NSURLRequest`,用于构造可变的 HTTP 请求(设置 method/header/body 等)。在插件的网络请求里(例如 `NSURLConnection
|
|
8
|
+
`NSMutableURLRequest` 继承自 `NSURLRequest`,用于构造可变的 HTTP 请求(设置 method/header/body 等)。在插件的网络请求里(例如 `NSURLConnection`)默认用它来构造请求。
|
|
9
9
|
|
|
10
10
|
## 实例成员 (Instance members)
|
|
11
11
|
|
|
@@ -20,7 +20,6 @@ req.setHTTPBody(NSData.dataWithStringEncoding("{}", 4));
|
|
|
20
20
|
|
|
21
21
|
## 类成员 (Class members)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
`NSMutableURLRequest` 通过 `requestWithURL(...)` 工厂方法创建。
|
|
24
24
|
|
|
25
25
|
相关:[网络请求](/guides/network-requests/) 教程含完整请求构建示例。
|
|
26
|
-
|
|
@@ -117,7 +117,7 @@ getObjectValueForStringRangeError(obj: any, string: string, rangep: any, error:
|
|
|
117
117
|
|
|
118
118
|
- `boolean`: 是否解析成功。
|
|
119
119
|
|
|
120
|
-
###
|
|
120
|
+
### 配置(属性/方法)
|
|
121
121
|
|
|
122
122
|
| 方法/属性 | 说明 |
|
|
123
123
|
| :--- | :--- |
|
|
@@ -139,7 +139,7 @@ getObjectValueForStringRangeError(obj: any, string: string, rangep: any, error:
|
|
|
139
139
|
|
|
140
140
|
### 进阶
|
|
141
141
|
|
|
142
|
-
|
|
142
|
+
本类型还导出了大量与舍入、科学计数、货币、百分比、解析容错、符号显示相关的可读写成员,例如`roundingMode`、`currencyCode`、`percentSymbol`、`lenient`、`usesSignificantDigits`等。可通过站内搜索成员名定位。
|
|
143
143
|
|
|
144
144
|
## 相关
|
|
145
145
|
|
|
@@ -5,7 +5,7 @@ description: 可调度的任务单元,常与 NSOperationQueue 配合使用。
|
|
|
5
5
|
|
|
6
6
|
`NSOperation` 表示一个可调度任务。常与 `NSOperationQueue` 搭配,用于异步调度(例如 `NSURLConnection.sendAsynchronousRequest...` 的 queue 参数)。
|
|
7
7
|
|
|
8
|
-
>
|
|
8
|
+
> 注意:默认直接使用 `NSOperationQueue.mainQueue()` / `currentQueue()` 即可,不会稳定需要手动构造自定义 operation。
|
|
9
9
|
|
|
10
10
|
## 实例成员 (Instance members)
|
|
11
11
|
|
|
@@ -245,4 +245,4 @@ setThreadPriority(p: number): void
|
|
|
245
245
|
|
|
246
246
|
## 类成员 (Class members)
|
|
247
247
|
|
|
248
|
-
|
|
248
|
+
当前接口未额外暴露 `NSOperation` 的类成员。
|
|
@@ -3,7 +3,7 @@ title: NSPointerArray
|
|
|
3
3
|
description: 指针数组(可配置强/弱引用语义)。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
`NSPointerArray` 是“指针数组”容器,允许存放对象指针或空洞,并支持强/弱语义(例如 `weakObjectsPointerArray()
|
|
6
|
+
`NSPointerArray` 是“指针数组”容器,允许存放对象指针或空洞,并支持强/弱语义(例如 `weakObjectsPointerArray()`)。在插件里默认把它当成“特殊数组”来用。
|
|
7
7
|
|
|
8
8
|
## 类成员 (Class members)
|
|
9
9
|
|
|
@@ -3,10 +3,12 @@ title: NSProxy
|
|
|
3
3
|
description: 代理基类(消息转发基础设施)。
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
`NSProxy
|
|
6
|
+
`NSProxy`是系统代理基类,提供消息转发相关能力。你直接不会直接创建它,但会在调试/反射/桥接场景里遇到它的基础方法。
|
|
7
7
|
|
|
8
8
|
## 类成员 (Class members)
|
|
9
9
|
|
|
10
|
+
> 注意:插件业务代码不建议调用`alloc/allocWithZone`,推荐使用`.new()`或工厂方法。
|
|
11
|
+
|
|
10
12
|
### `alloc`
|
|
11
13
|
|
|
12
14
|
分配实例。
|
|
@@ -107,7 +109,7 @@ forwardInvocation(invocation: any): void
|
|
|
107
109
|
|
|
108
110
|
### `dealloc`
|
|
109
111
|
|
|
110
|
-
|
|
112
|
+
析构。
|
|
111
113
|
|
|
112
114
|
```javascript
|
|
113
115
|
dealloc(): void
|
|
@@ -119,7 +121,7 @@ dealloc(): void
|
|
|
119
121
|
|
|
120
122
|
### `finalize`
|
|
121
123
|
|
|
122
|
-
|
|
124
|
+
终结。
|
|
123
125
|
|
|
124
126
|
```javascript
|
|
125
127
|
finalize(): void
|