mn-docs-mcp 0.1.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/.env.example +4 -0
- package/.vscode/extensions.json +4 -0
- package/.vscode/launch.json +11 -0
- package/README.md +99 -0
- package/astro.config.mjs +126 -0
- package/package.json +30 -0
- package/pnpm-workspace.yaml +4 -0
- package/public/favicon.svg +1 -0
- package/scripts/mcp/build-index.mjs +9 -0
- package/scripts/mcp/cli.mjs +61 -0
- package/scripts/mcp/lib.mjs +303 -0
- package/scripts/mcp/server-http.mjs +74 -0
- package/scripts/mcp/server.mjs +91 -0
- package/src/assets/houston.webp +0 -0
- package/src/client/jsb-api-footer.ts +242 -0
- package/src/components/Footer.astro +57 -0
- package/src/components/Search.astro +330 -0
- package/src/content/docs/guides/contributing.md +82 -0
- package/src/content/docs/guides/cookbook/addon-settings.md +53 -0
- package/src/content/docs/guides/cookbook/append-selection-as-comment.md +46 -0
- package/src/content/docs/guides/cookbook/batch-rename-notes.md +53 -0
- package/src/content/docs/guides/cookbook/embed-webview-panel.md +158 -0
- package/src/content/docs/guides/cookbook/export-notebook.md +48 -0
- package/src/content/docs/guides/cookbook/focus-note-in-mindmap.md +34 -0
- package/src/content/docs/guides/cookbook/network-api-call.md +135 -0
- package/src/content/docs/guides/cookbook/webview-bidirectional-js.md +112 -0
- package/src/content/docs/guides/getting-started.md +88 -0
- package/src/content/docs/guides/lifecycle-and-window.md +76 -0
- package/src/content/docs/guides/mindmap-and-selection.md +76 -0
- package/src/content/docs/guides/native-ui.md +136 -0
- package/src/content/docs/guides/network-requests.md +309 -0
- package/src/content/docs/guides/notes-and-database.md +99 -0
- package/src/content/docs/guides/shortcut-keys.md +105 -0
- package/src/content/docs/guides/storage-and-files.md +91 -0
- package/src/content/docs/guides/toolbar-and-commands.md +64 -0
- package/src/content/docs/index.mdx +44 -0
- package/src/content/docs/reference/black-box.md +19 -0
- package/src/content/docs/reference/foundation/ns-array.md +699 -0
- package/src/content/docs/reference/foundation/ns-attributed-string.md +379 -0
- package/src/content/docs/reference/foundation/ns-character-set.md +436 -0
- package/src/content/docs/reference/foundation/ns-counted-set.md +78 -0
- package/src/content/docs/reference/foundation/ns-data.md +183 -0
- package/src/content/docs/reference/foundation/ns-date-components.md +24 -0
- package/src/content/docs/reference/foundation/ns-date-formatter.md +70 -0
- package/src/content/docs/reference/foundation/ns-date.md +236 -0
- package/src/content/docs/reference/foundation/ns-decimal-number.md +437 -0
- package/src/content/docs/reference/foundation/ns-dictionary.md +376 -0
- package/src/content/docs/reference/foundation/ns-enumerator.md +36 -0
- package/src/content/docs/reference/foundation/ns-error.md +75 -0
- package/src/content/docs/reference/foundation/ns-file-handle.md +445 -0
- package/src/content/docs/reference/foundation/ns-file-manager.md +275 -0
- package/src/content/docs/reference/foundation/ns-formatter.md +131 -0
- package/src/content/docs/reference/foundation/ns-hash-table.md +304 -0
- package/src/content/docs/reference/foundation/ns-http-url-response.md +73 -0
- package/src/content/docs/reference/foundation/ns-index-path.md +185 -0
- package/src/content/docs/reference/foundation/ns-index-set.md +527 -0
- package/src/content/docs/reference/foundation/ns-json-serialization.md +24 -0
- package/src/content/docs/reference/foundation/ns-keyed-archiver.md +364 -0
- package/src/content/docs/reference/foundation/ns-keyed-unarchiver.md +324 -0
- package/src/content/docs/reference/foundation/ns-locale.md +82 -0
- package/src/content/docs/reference/foundation/ns-map-table.md +216 -0
- package/src/content/docs/reference/foundation/ns-mutable-array.md +452 -0
- package/src/content/docs/reference/foundation/ns-mutable-attributed-string.md +336 -0
- package/src/content/docs/reference/foundation/ns-mutable-character-set.md +132 -0
- package/src/content/docs/reference/foundation/ns-mutable-data.md +206 -0
- package/src/content/docs/reference/foundation/ns-mutable-dictionary.md +176 -0
- package/src/content/docs/reference/foundation/ns-mutable-index-set.md +155 -0
- package/src/content/docs/reference/foundation/ns-mutable-ordered-set.md +465 -0
- package/src/content/docs/reference/foundation/ns-mutable-set.md +189 -0
- package/src/content/docs/reference/foundation/ns-mutable-string.md +190 -0
- package/src/content/docs/reference/foundation/ns-mutable-url-request.md +26 -0
- package/src/content/docs/reference/foundation/ns-notification-center.md +30 -0
- package/src/content/docs/reference/foundation/ns-notification.md +73 -0
- package/src/content/docs/reference/foundation/ns-null.md +24 -0
- package/src/content/docs/reference/foundation/ns-number-formatter.md +147 -0
- package/src/content/docs/reference/foundation/ns-number.md +393 -0
- package/src/content/docs/reference/foundation/ns-operation-queue.md +227 -0
- package/src/content/docs/reference/foundation/ns-operation.md +248 -0
- package/src/content/docs/reference/foundation/ns-ordered-set.md +706 -0
- package/src/content/docs/reference/foundation/ns-pointer-array.md +192 -0
- package/src/content/docs/reference/foundation/ns-predicate.md +199 -0
- package/src/content/docs/reference/foundation/ns-proxy.md +178 -0
- package/src/content/docs/reference/foundation/ns-scanner.md +448 -0
- package/src/content/docs/reference/foundation/ns-set.md +586 -0
- package/src/content/docs/reference/foundation/ns-simple-c-string.md +20 -0
- package/src/content/docs/reference/foundation/ns-time-zone.md +86 -0
- package/src/content/docs/reference/foundation/ns-timer.md +24 -0
- package/src/content/docs/reference/foundation/ns-url-components.md +80 -0
- package/src/content/docs/reference/foundation/ns-url-connection.md +169 -0
- package/src/content/docs/reference/foundation/ns-url-request.md +224 -0
- package/src/content/docs/reference/foundation/ns-url-response.md +97 -0
- package/src/content/docs/reference/foundation/ns-url.md +31 -0
- package/src/content/docs/reference/foundation/ns-user-defaults.md +302 -0
- package/src/content/docs/reference/foundation/ns-uuid.md +52 -0
- package/src/content/docs/reference/foundation/ns-value.md +194 -0
- package/src/content/docs/reference/global/application.md +301 -0
- package/src/content/docs/reference/global/builtin-commands.md +294 -0
- package/src/content/docs/reference/global/database.md +395 -0
- package/src/content/docs/reference/global/global-variables.md +32 -0
- package/src/content/docs/reference/global/jsb.md +89 -0
- package/src/content/docs/reference/global/note.md +64 -0
- package/src/content/docs/reference/global/popup-menu-item.md +18 -0
- package/src/content/docs/reference/global/popup-menu.md +38 -0
- package/src/content/docs/reference/global/search-manager.md +51 -0
- package/src/content/docs/reference/global/self.md +28 -0
- package/src/content/docs/reference/js-runtime.md +28 -0
- package/src/content/docs/reference/marginnote/document-controller.md +45 -0
- package/src/content/docs/reference/marginnote/jsextension.md +119 -0
- package/src/content/docs/reference/marginnote/mb-book-note.md +192 -0
- package/src/content/docs/reference/marginnote/mb-book.md +35 -0
- package/src/content/docs/reference/marginnote/mb-model-tool.md +66 -0
- package/src/content/docs/reference/marginnote/mb-topic.md +36 -0
- package/src/content/docs/reference/marginnote/mindmap-node.md +27 -0
- package/src/content/docs/reference/marginnote/mindmap-view.md +24 -0
- package/src/content/docs/reference/marginnote/note-comment.md +29 -0
- package/src/content/docs/reference/marginnote/notebook-controller.md +36 -0
- package/src/content/docs/reference/marginnote/outline-view.md +23 -0
- package/src/content/docs/reference/marginnote/reader-controller.md +26 -0
- package/src/content/docs/reference/marginnote/study-controller.md +100 -0
- package/src/content/docs/reference/quartzcore/caanimation-group.md +44 -0
- package/src/content/docs/reference/quartzcore/caanimation.md +23 -0
- package/src/content/docs/reference/quartzcore/cabasic-animation.md +19 -0
- package/src/content/docs/reference/quartzcore/cagradient-layer.md +27 -0
- package/src/content/docs/reference/quartzcore/cakeyframe-animation.md +19 -0
- package/src/content/docs/reference/quartzcore/calayer.md +135 -0
- package/src/content/docs/reference/quartzcore/camedia-timing-function.md +25 -0
- package/src/content/docs/reference/quartzcore/caproperty-animation.md +46 -0
- package/src/content/docs/reference/quartzcore/careplicator-layer.md +27 -0
- package/src/content/docs/reference/quartzcore/cascroll-layer.md +21 -0
- package/src/content/docs/reference/quartzcore/cashape-layer.md +34 -0
- package/src/content/docs/reference/quartzcore/catext-layer.md +28 -0
- package/src/content/docs/reference/quartzcore/catiled-layer.md +26 -0
- package/src/content/docs/reference/quartzcore/catransaction.md +46 -0
- package/src/content/docs/reference/quartzcore/catransform-layer.md +18 -0
- package/src/content/docs/reference/quartzcore/catransition.md +44 -0
- package/src/content/docs/reference/quartzcore/cavalue-function.md +22 -0
- package/src/content/docs/reference/uikit/ns-mutable-paragraph-style.md +20 -0
- package/src/content/docs/reference/uikit/ns-paragraph-style.md +20 -0
- package/src/content/docs/reference/uikit/ns-text-storage.md +20 -0
- package/src/content/docs/reference/uikit/uiactivity-indicator-view.md +20 -0
- package/src/content/docs/reference/uikit/uialertview.md +25 -0
- package/src/content/docs/reference/uikit/uiapplication.md +128 -0
- package/src/content/docs/reference/uikit/uibar-button-item.md +20 -0
- package/src/content/docs/reference/uikit/uibar-item.md +20 -0
- package/src/content/docs/reference/uikit/uibezier-path.md +143 -0
- package/src/content/docs/reference/uikit/uibutton.md +27 -0
- package/src/content/docs/reference/uikit/uicollection-view-cell.md +24 -0
- package/src/content/docs/reference/uikit/uicollection-view-controller.md +32 -0
- package/src/content/docs/reference/uikit/uicollection-view-layout-attributes.md +43 -0
- package/src/content/docs/reference/uikit/uicollection-view-layout.md +60 -0
- package/src/content/docs/reference/uikit/uicollection-view.md +83 -0
- package/src/content/docs/reference/uikit/uicolor.md +23 -0
- package/src/content/docs/reference/uikit/uicontrol.md +20 -0
- package/src/content/docs/reference/uikit/uidate-picker.md +37 -0
- package/src/content/docs/reference/uikit/uidevice.md +83 -0
- package/src/content/docs/reference/uikit/uievent.md +36 -0
- package/src/content/docs/reference/uikit/uifont.md +39 -0
- package/src/content/docs/reference/uikit/uigesture-recognizer.md +152 -0
- package/src/content/docs/reference/uikit/uiimage-picker-controller.md +41 -0
- package/src/content/docs/reference/uikit/uiimage-view.md +38 -0
- package/src/content/docs/reference/uikit/uiimage.md +58 -0
- package/src/content/docs/reference/uikit/uikey-command.md +31 -0
- package/src/content/docs/reference/uikit/uilabel.md +27 -0
- package/src/content/docs/reference/uikit/uilocal-notification.md +28 -0
- package/src/content/docs/reference/uikit/uilong-press-gesture-recognizer.md +25 -0
- package/src/content/docs/reference/uikit/uinavigation-bar.md +52 -0
- package/src/content/docs/reference/uikit/uinavigation-controller.md +46 -0
- package/src/content/docs/reference/uikit/uinavigation-item.md +42 -0
- package/src/content/docs/reference/uikit/uipage-control.md +35 -0
- package/src/content/docs/reference/uikit/uipage-view-controller.md +37 -0
- package/src/content/docs/reference/uikit/uipan-gesture-recognizer.md +32 -0
- package/src/content/docs/reference/uikit/uipasteboard.md +24 -0
- package/src/content/docs/reference/uikit/uipicker-view.md +37 -0
- package/src/content/docs/reference/uikit/uipinch-gesture-recognizer.md +23 -0
- package/src/content/docs/reference/uikit/uipopover-controller.md +39 -0
- package/src/content/docs/reference/uikit/uiresponder.md +20 -0
- package/src/content/docs/reference/uikit/uirotation-gesture-recognizer.md +23 -0
- package/src/content/docs/reference/uikit/uiscreen-mode.md +17 -0
- package/src/content/docs/reference/uikit/uiscreen.md +65 -0
- package/src/content/docs/reference/uikit/uiscrollview.md +134 -0
- package/src/content/docs/reference/uikit/uisearch-bar.md +58 -0
- package/src/content/docs/reference/uikit/uisegmented-control.md +64 -0
- package/src/content/docs/reference/uikit/uislider.md +50 -0
- package/src/content/docs/reference/uikit/uiswipe-gesture-recognizer.md +23 -0
- package/src/content/docs/reference/uikit/uiswitch.md +22 -0
- package/src/content/docs/reference/uikit/uitab-bar-controller.md +39 -0
- package/src/content/docs/reference/uikit/uitab-bar-item.md +34 -0
- package/src/content/docs/reference/uikit/uitab-bar.md +44 -0
- package/src/content/docs/reference/uikit/uitable-view-cell.md +57 -0
- package/src/content/docs/reference/uikit/uitable-view-controller.md +30 -0
- package/src/content/docs/reference/uikit/uitable-view.md +100 -0
- package/src/content/docs/reference/uikit/uitap-gesture-recognizer.md +20 -0
- package/src/content/docs/reference/uikit/uitext-input-mode.md +47 -0
- package/src/content/docs/reference/uikit/uitext-position.md +44 -0
- package/src/content/docs/reference/uikit/uitext-range.md +42 -0
- package/src/content/docs/reference/uikit/uitext-view.md +46 -0
- package/src/content/docs/reference/uikit/uitextfield.md +32 -0
- package/src/content/docs/reference/uikit/uitoolbar.md +35 -0
- package/src/content/docs/reference/uikit/uitouch.md +39 -0
- package/src/content/docs/reference/uikit/uiview-controller.md +36 -0
- package/src/content/docs/reference/uikit/uiview.md +47 -0
- package/src/content/docs/reference/uikit/uiwebview.md +229 -0
- package/src/content/docs/reference/uikit/uiwindow.md +47 -0
- package/src/content/docs/reference/utility/menu-controller.md +27 -0
- package/src/content/docs/reference/utility/speech-manager.md +118 -0
- package/src/content/docs/reference/utility/sqlite-database.md +201 -0
- package/src/content/docs/reference/utility/sqlite-result-set.md +266 -0
- package/src/content/docs/reference/utility/sqlite-statement.md +44 -0
- package/src/content/docs/reference/utility/undo-manager.md +89 -0
- package/src/content/docs/reference/utility/zip-archive.md +29 -0
- package/src/content.config.ts +7 -0
- package/src/definitions/Foundation/JSBFoundation.h +9 -0
- package/src/definitions/Foundation/JSBFoundation.m +530 -0
- package/src/definitions/Foundation/JSBNSArray.h +81 -0
- package/src/definitions/Foundation/JSBNSAssertionHandler.h +23 -0
- package/src/definitions/Foundation/JSBNSAttributedString.h +42 -0
- package/src/definitions/Foundation/JSBNSBlockOperation.h +20 -0
- package/src/definitions/Foundation/JSBNSBundle.h +80 -0
- package/src/definitions/Foundation/JSBNSByteCountFormatter.h +28 -0
- package/src/definitions/Foundation/JSBNSCache.h +31 -0
- package/src/definitions/Foundation/JSBNSCachedURLResponse.h +22 -0
- package/src/definitions/Foundation/JSBNSCalendar.h +88 -0
- package/src/definitions/Foundation/JSBNSCharacterSet.h +50 -0
- package/src/definitions/Foundation/JSBNSCoder.h +88 -0
- package/src/definitions/Foundation/JSBNSComparisonPredicate.h +27 -0
- package/src/definitions/Foundation/JSBNSCompoundPredicate.h +23 -0
- package/src/definitions/Foundation/JSBNSCondition.h +22 -0
- package/src/definitions/Foundation/JSBNSConditionLock.h +26 -0
- package/src/definitions/Foundation/JSBNSConstantString.h +18 -0
- package/src/definitions/Foundation/JSBNSCountedSet.h +21 -0
- package/src/definitions/Foundation/JSBNSData.h +44 -0
- package/src/definitions/Foundation/JSBNSDataDetector.h +20 -0
- package/src/definitions/Foundation/JSBNSDate.h +37 -0
- package/src/definitions/Foundation/JSBNSDateComponents.h +56 -0
- package/src/definitions/Foundation/JSBNSDateFormatter.h +91 -0
- package/src/definitions/Foundation/JSBNSDecimalNumber.h +47 -0
- package/src/definitions/Foundation/JSBNSDecimalNumberHandler.h +23 -0
- package/src/definitions/Foundation/JSBNSDictionary.h +79 -0
- package/src/definitions/Foundation/JSBNSDirectoryEnumerator.h +25 -0
- package/src/definitions/Foundation/JSBNSEnumerator.h +18 -0
- package/src/definitions/Foundation/JSBNSError.h +28 -0
- package/src/definitions/Foundation/JSBNSException.h +30 -0
- package/src/definitions/Foundation/JSBNSExpression.h +48 -0
- package/src/definitions/Foundation/JSBNSFileCoordinator.h +29 -0
- package/src/definitions/Foundation/JSBNSFileHandle.h +51 -0
- package/src/definitions/Foundation/JSBNSFileManager.h +82 -0
- package/src/definitions/Foundation/JSBNSFileSecurity.h +32 -0
- package/src/definitions/Foundation/JSBNSFileVersion.h +35 -0
- package/src/definitions/Foundation/JSBNSFileWrapper.h +41 -0
- package/src/definitions/Foundation/JSBNSFormatter.h +23 -0
- package/src/definitions/Foundation/JSBNSHTTPCookie.h +34 -0
- package/src/definitions/Foundation/JSBNSHTTPCookieStorage.h +26 -0
- package/src/definitions/Foundation/JSBNSHTTPURLResponse.h +21 -0
- package/src/definitions/Foundation/JSBNSHashTable.h +38 -0
- package/src/definitions/Foundation/JSBNSIndexPath.h +34 -0
- package/src/definitions/Foundation/JSBNSIndexSet.h +47 -0
- package/src/definitions/Foundation/JSBNSInputStream.h +28 -0
- package/src/definitions/Foundation/JSBNSInvocation.h +32 -0
- package/src/definitions/Foundation/JSBNSInvocationOperation.h +20 -0
- package/src/definitions/Foundation/JSBNSJSONSerialization.h +19 -0
- package/src/definitions/Foundation/JSBNSKeyedArchiver.h +40 -0
- package/src/definitions/Foundation/JSBNSKeyedUnarchiver.h +38 -0
- package/src/definitions/Foundation/JSBNSLinguisticTagger.h +31 -0
- package/src/definitions/Foundation/JSBNSLocale.h +39 -0
- package/src/definitions/Foundation/JSBNSLock.h +20 -0
- package/src/definitions/Foundation/JSBNSMachPort.h +26 -0
- package/src/definitions/Foundation/JSBNSMapTable.h +34 -0
- package/src/definitions/Foundation/JSBNSMessagePort.h +15 -0
- package/src/definitions/Foundation/JSBNSMetadataItem.h +22 -0
- package/src/definitions/Foundation/JSBNSMetadataQuery.h +53 -0
- package/src/definitions/Foundation/JSBNSMetadataQueryAttributeValueTuple.h +21 -0
- package/src/definitions/Foundation/JSBNSMetadataQueryResultGroup.h +24 -0
- package/src/definitions/Foundation/JSBNSMethodSignature.h +24 -0
- package/src/definitions/Foundation/JSBNSMutableArray.h +51 -0
- package/src/definitions/Foundation/JSBNSMutableAttributedString.h +39 -0
- package/src/definitions/Foundation/JSBNSMutableCharacterSet.h +26 -0
- package/src/definitions/Foundation/JSBNSMutableData.h +29 -0
- package/src/definitions/Foundation/JSBNSMutableDictionary.h +29 -0
- package/src/definitions/Foundation/JSBNSMutableIndexSet.h +25 -0
- package/src/definitions/Foundation/JSBNSMutableOrderedSet.h +50 -0
- package/src/definitions/Foundation/JSBNSMutableSet.h +28 -0
- package/src/definitions/Foundation/JSBNSMutableString.h +31 -0
- package/src/definitions/Foundation/JSBNSMutableURLRequest.h +38 -0
- package/src/definitions/Foundation/JSBNSNetService.h +43 -0
- package/src/definitions/Foundation/JSBNSNetServiceBrowser.h +33 -0
- package/src/definitions/Foundation/JSBNSNotification.h +23 -0
- package/src/definitions/Foundation/JSBNSNotificationCenter.h +27 -0
- package/src/definitions/Foundation/JSBNSNotificationQueue.h +22 -0
- package/src/definitions/Foundation/JSBNSNull.h +17 -0
- package/src/definitions/Foundation/JSBNSNumber.h +51 -0
- package/src/definitions/Foundation/JSBNSNumberFormatter.h +136 -0
- package/src/definitions/Foundation/JSBNSOperation.h +34 -0
- package/src/definitions/Foundation/JSBNSOperationQueue.h +32 -0
- package/src/definitions/Foundation/JSBNSOrderedSet.h +70 -0
- package/src/definitions/Foundation/JSBNSOrthography.h +27 -0
- package/src/definitions/Foundation/JSBNSOutputStream.h +33 -0
- package/src/definitions/Foundation/JSBNSPipe.h +26 -0
- package/src/definitions/Foundation/JSBNSPointerArray.h +33 -0
- package/src/definitions/Foundation/JSBNSPort.h +27 -0
- package/src/definitions/Foundation/JSBNSPredicate.h +31 -0
- package/src/definitions/Foundation/JSBNSProcessInfo.h +42 -0
- package/src/definitions/Foundation/JSBNSProgress.h +45 -0
- package/src/definitions/Foundation/JSBNSPropertyListSerialization.h +24 -0
- package/src/definitions/Foundation/JSBNSProxy.h +29 -0
- package/src/definitions/Foundation/JSBNSPurgeableData.h +16 -0
- package/src/definitions/Foundation/JSBNSRecursiveLock.h +20 -0
- package/src/definitions/Foundation/JSBNSRegularExpression.h +35 -0
- package/src/definitions/Foundation/JSBNSRunLoop.h +38 -0
- package/src/definitions/Foundation/JSBNSScanner.h +44 -0
- package/src/definitions/Foundation/JSBNSSet.h +52 -0
- package/src/definitions/Foundation/JSBNSSimpleCString.h +18 -0
- package/src/definitions/Foundation/JSBNSSortDescriptor.h +32 -0
- package/src/definitions/Foundation/JSBNSStream.h +26 -0
- package/src/definitions/Foundation/JSBNSString.h +178 -0
- package/src/definitions/Foundation/JSBNSTextCheckingResult.h +52 -0
- package/src/definitions/Foundation/JSBNSThread.h +46 -0
- package/src/definitions/Foundation/JSBNSTimeZone.h +46 -0
- package/src/definitions/Foundation/JSBNSTimer.h +29 -0
- package/src/definitions/Foundation/JSBNSURL.h +110 -0
- package/src/definitions/Foundation/JSBNSURLAuthenticationChallenge.h +24 -0
- package/src/definitions/Foundation/JSBNSURLCache.h +30 -0
- package/src/definitions/Foundation/JSBNSURLComponents.h +38 -0
- package/src/definitions/Foundation/JSBNSURLConnection.h +45 -0
- package/src/definitions/Foundation/JSBNSURLCredential.h +30 -0
- package/src/definitions/Foundation/JSBNSURLCredentialStorage.h +25 -0
- package/src/definitions/Foundation/JSBNSURLProtectionSpace.h +29 -0
- package/src/definitions/Foundation/JSBNSURLProtocol.h +32 -0
- package/src/definitions/Foundation/JSBNSURLRequest.h +40 -0
- package/src/definitions/Foundation/JSBNSURLResponse.h +22 -0
- package/src/definitions/Foundation/JSBNSURLSession.h +103 -0
- package/src/definitions/Foundation/JSBNSURLSessionConfiguration.h +58 -0
- package/src/definitions/Foundation/JSBNSURLSessionDataTask.h +18 -0
- package/src/definitions/Foundation/JSBNSURLSessionDownloadTask.h +20 -0
- package/src/definitions/Foundation/JSBNSURLSessionTask.h +58 -0
- package/src/definitions/Foundation/JSBNSURLSessionUploadTask.h +18 -0
- package/src/definitions/Foundation/JSBNSUUID.h +22 -0
- package/src/definitions/Foundation/JSBNSUbiquitousKeyValueStore.h +37 -0
- package/src/definitions/Foundation/JSBNSUndoManager.h +50 -0
- package/src/definitions/Foundation/JSBNSUserDefaults.h +52 -0
- package/src/definitions/Foundation/JSBNSValue.h +53 -0
- package/src/definitions/Foundation/JSBNSValueTransformer.h +24 -0
- package/src/definitions/Foundation/JSBNSXMLParser.h +34 -0
- package/src/definitions/JSBApplication.h +59 -0
- package/src/definitions/JSBDocumentController.h +32 -0
- package/src/definitions/JSBJSExtension.h +34 -0
- package/src/definitions/JSBMNFileSystem.h +50 -0
- package/src/definitions/JSBMNFileSystem.m +267 -0
- package/src/definitions/JSBMarginNote.h +9 -0
- package/src/definitions/JSBMarginNote.m +183 -0
- package/src/definitions/JSBMbBook.h +22 -0
- package/src/definitions/JSBMbBookNote.h +78 -0
- package/src/definitions/JSBMbModelTool.h +47 -0
- package/src/definitions/JSBMbTopic.h +28 -0
- package/src/definitions/JSBMenuController.h +21 -0
- package/src/definitions/JSBMindMapNode.h +20 -0
- package/src/definitions/JSBMindMapView.h +15 -0
- package/src/definitions/JSBNotebookController.h +22 -0
- package/src/definitions/JSBOutlineView.h +14 -0
- package/src/definitions/JSBPopupMenu.h +37 -0
- package/src/definitions/JSBPopupMenuItem.h +19 -0
- package/src/definitions/JSBReaderController.h +18 -0
- package/src/definitions/JSBSQLite.h +109 -0
- package/src/definitions/JSBSearchManager.h +55 -0
- package/src/definitions/JSBSearchManager.m +4 -0
- package/src/definitions/JSBSpeechManager.h +31 -0
- package/src/definitions/JSBStudyController.h +32 -0
- package/src/definitions/JSBUndoManager.h +23 -0
- package/src/definitions/JSBZipArchive.h +28 -0
- package/src/definitions/QuartzCore/JSBCAAnimation.h +21 -0
- package/src/definitions/QuartzCore/JSBCAAnimationGroup.h +37 -0
- package/src/definitions/QuartzCore/JSBCABasicAnimation.h +16 -0
- package/src/definitions/QuartzCore/JSBCADisplayLink.h +26 -0
- package/src/definitions/QuartzCore/JSBCAEAGLLayer.h +16 -0
- package/src/definitions/QuartzCore/JSBCAEmitterBehavior.h +24 -0
- package/src/definitions/QuartzCore/JSBCAEmitterCell.h +40 -0
- package/src/definitions/QuartzCore/JSBCAEmitterLayer.h +31 -0
- package/src/definitions/QuartzCore/JSBCAGradientLayer.h +20 -0
- package/src/definitions/QuartzCore/JSBCAKeyframeAnimation.h +16 -0
- package/src/definitions/QuartzCore/JSBCALayer.h +98 -0
- package/src/definitions/QuartzCore/JSBCAMediaTimingFunction.h +22 -0
- package/src/definitions/QuartzCore/JSBCAPropertyAnimation.h +39 -0
- package/src/definitions/QuartzCore/JSBCAReplicatorLayer.h +23 -0
- package/src/definitions/QuartzCore/JSBCAScrollLayer.h +18 -0
- package/src/definitions/QuartzCore/JSBCAShapeLayer.h +27 -0
- package/src/definitions/QuartzCore/JSBCATextLayer.h +23 -0
- package/src/definitions/QuartzCore/JSBCATiledLayer.h +21 -0
- package/src/definitions/QuartzCore/JSBCATransaction.h +32 -0
- package/src/definitions/QuartzCore/JSBCATransformLayer.h +15 -0
- package/src/definitions/QuartzCore/JSBCATransition.h +37 -0
- package/src/definitions/QuartzCore/JSBCAValueFunction.h +20 -0
- package/src/definitions/QuartzCore/JSBQuartzCore.h +9 -0
- package/src/definitions/QuartzCore/JSBQuartzCore.m +106 -0
- package/src/definitions/UIKit/JSBNSLayoutConstraint.h +30 -0
- package/src/definitions/UIKit/JSBNSLayoutManager.h +94 -0
- package/src/definitions/UIKit/JSBNSMutableParagraphStyle.h +16 -0
- package/src/definitions/UIKit/JSBNSParagraphStyle.h +37 -0
- package/src/definitions/UIKit/JSBNSShadow.h +20 -0
- package/src/definitions/UIKit/JSBNSStringDrawingContext.h +22 -0
- package/src/definitions/UIKit/JSBNSTextAttachment.h +24 -0
- package/src/definitions/UIKit/JSBNSTextContainer.h +27 -0
- package/src/definitions/UIKit/JSBNSTextStorage.h +31 -0
- package/src/definitions/UIKit/JSBNSTextTab.h +38 -0
- package/src/definitions/UIKit/JSBUIAcceleration.h +24 -0
- package/src/definitions/UIKit/JSBUIAccelerometer.h +28 -0
- package/src/definitions/UIKit/JSBUIAccessibilityElement.h +24 -0
- package/src/definitions/UIKit/JSBUIActionSheet.h +37 -0
- package/src/definitions/UIKit/JSBUIActivity.h +26 -0
- package/src/definitions/UIKit/JSBUIActivityIndicatorView.h +22 -0
- package/src/definitions/UIKit/JSBUIActivityItemProvider.h +22 -0
- package/src/definitions/UIKit/JSBUIActivityViewController.h +20 -0
- package/src/definitions/UIKit/JSBUIAlertView.h +39 -0
- package/src/definitions/UIKit/JSBUIApplication.h +37 -0
- package/src/definitions/UIKit/JSBUIAttachmentBehavior.h +26 -0
- package/src/definitions/UIKit/JSBUIBarButtonItem.h +48 -0
- package/src/definitions/UIKit/JSBUIBarItem.h +26 -0
- package/src/definitions/UIKit/JSBUIBezierPath.h +55 -0
- package/src/definitions/UIKit/JSBUIButton.h +51 -0
- package/src/definitions/UIKit/JSBUICollectionReusableView.h +26 -0
- package/src/definitions/UIKit/JSBUICollectionView.h +53 -0
- package/src/definitions/UIKit/JSBUICollectionViewCell.h +14 -0
- package/src/definitions/UIKit/JSBUICollectionViewController.h +21 -0
- package/src/definitions/UIKit/JSBUICollectionViewFlowLayout.h +29 -0
- package/src/definitions/UIKit/JSBUICollectionViewFlowLayoutInvalidationContext.h +25 -0
- package/src/definitions/UIKit/JSBUICollectionViewLayout.h +58 -0
- package/src/definitions/UIKit/JSBUICollectionViewLayoutAttributes.h +40 -0
- package/src/definitions/UIKit/JSBUICollectionViewLayoutInvalidationContext.h +36 -0
- package/src/definitions/UIKit/JSBUICollectionViewTransitionLayout.h +15 -0
- package/src/definitions/UIKit/JSBUICollectionViewUpdateItem.h +36 -0
- package/src/definitions/UIKit/JSBUICollisionBehavior.h +30 -0
- package/src/definitions/UIKit/JSBUIColor.h +67 -0
- package/src/definitions/UIKit/JSBUIControl.h +39 -0
- package/src/definitions/UIKit/JSBUIDatePicker.h +26 -0
- package/src/definitions/UIKit/JSBUIDevice.h +37 -0
- package/src/definitions/UIKit/JSBUIDictationPhrase.h +38 -0
- package/src/definitions/UIKit/JSBUIDocument.h +46 -0
- package/src/definitions/UIKit/JSBUIDocumentInteractionController.h +32 -0
- package/src/definitions/UIKit/JSBUIDynamicAnimator.h +27 -0
- package/src/definitions/UIKit/JSBUIDynamicBehavior.h +27 -0
- package/src/definitions/UIKit/JSBUIDynamicItemBehavior.h +30 -0
- package/src/definitions/UIKit/JSBUIEvent.h +24 -0
- package/src/definitions/UIKit/JSBUIFont.h +30 -0
- package/src/definitions/UIKit/JSBUIFontDescriptor.h +36 -0
- package/src/definitions/UIKit/JSBUIGestureRecognizer.h +44 -0
- package/src/definitions/UIKit/JSBUIGravityBehavior.h +24 -0
- package/src/definitions/UIKit/JSBUIImage.h +59 -0
- package/src/definitions/UIKit/JSBUIImagePickerController.h +30 -0
- package/src/definitions/UIKit/JSBUIImageView.h +28 -0
- package/src/definitions/UIKit/JSBUIInputView.h +15 -0
- package/src/definitions/UIKit/JSBUIInterpolatingMotionEffect.h +18 -0
- package/src/definitions/UIKit/JSBUIKeyCommand.h +25 -0
- package/src/definitions/UIKit/JSBUIKit.h +9 -0
- package/src/definitions/UIKit/JSBUIKit.m +614 -0
- package/src/definitions/UIKit/JSBUILabel.h +38 -0
- package/src/definitions/UIKit/JSBUILocalNotification.h +20 -0
- package/src/definitions/UIKit/JSBUILocalizedIndexedCollation.h +23 -0
- package/src/definitions/UIKit/JSBUILongPressGestureRecognizer.h +22 -0
- package/src/definitions/UIKit/JSBUIManagedDocument.h +26 -0
- package/src/definitions/UIKit/JSBUIMarkupTextPrintFormatter.h +17 -0
- package/src/definitions/UIKit/JSBUIMenuController.h +28 -0
- package/src/definitions/UIKit/JSBUIMenuItem.h +25 -0
- package/src/definitions/UIKit/JSBUIMotionEffect.h +24 -0
- package/src/definitions/UIKit/JSBUIMotionEffectGroup.h +16 -0
- package/src/definitions/UIKit/JSBUINavigationBar.h +47 -0
- package/src/definitions/UIKit/JSBUINavigationController.h +34 -0
- package/src/definitions/UIKit/JSBUINavigationItem.h +45 -0
- package/src/definitions/UIKit/JSBUINib.h +19 -0
- package/src/definitions/UIKit/JSBUIPageControl.h +24 -0
- package/src/definitions/UIKit/JSBUIPageViewController.h +27 -0
- package/src/definitions/UIKit/JSBUIPanGestureRecognizer.h +23 -0
- package/src/definitions/UIKit/JSBUIPasteboard.h +46 -0
- package/src/definitions/UIKit/JSBUIPercentDrivenInteractiveTransition.h +24 -0
- package/src/definitions/UIKit/JSBUIPickerView.h +28 -0
- package/src/definitions/UIKit/JSBUIPinchGestureRecognizer.h +19 -0
- package/src/definitions/UIKit/JSBUIPopoverBackgroundView.h +22 -0
- package/src/definitions/UIKit/JSBUIPopoverController.h +31 -0
- package/src/definitions/UIKit/JSBUIPrintFormatter.h +33 -0
- package/src/definitions/UIKit/JSBUIPrintInfo.h +26 -0
- package/src/definitions/UIKit/JSBUIPrintInteractionController.h +36 -0
- package/src/definitions/UIKit/JSBUIPrintPageRenderer.h +31 -0
- package/src/definitions/UIKit/JSBUIPrintPaper.h +22 -0
- package/src/definitions/UIKit/JSBUIProgressView.h +24 -0
- package/src/definitions/UIKit/JSBUIPushBehavior.h +28 -0
- package/src/definitions/UIKit/JSBUIReferenceLibraryViewController.h +19 -0
- package/src/definitions/UIKit/JSBUIRefreshControl.h +21 -0
- package/src/definitions/UIKit/JSBUIResponder.h +57 -0
- package/src/definitions/UIKit/JSBUIRotationGestureRecognizer.h +19 -0
- package/src/definitions/UIKit/JSBUIScreen.h +36 -0
- package/src/definitions/UIKit/JSBUIScreenEdgePanGestureRecognizer.h +18 -0
- package/src/definitions/UIKit/JSBUIScreenMode.h +19 -0
- package/src/definitions/UIKit/JSBUIScrollView.h +53 -0
- package/src/definitions/UIKit/JSBUISearchBar.h +55 -0
- package/src/definitions/UIKit/JSBUISearchDisplayController.h +28 -0
- package/src/definitions/UIKit/JSBUISegmentedControl.h +46 -0
- package/src/definitions/UIKit/JSBUISimpleTextPrintFormatter.h +18 -0
- package/src/definitions/UIKit/JSBUISlider.h +41 -0
- package/src/definitions/UIKit/JSBUISnapBehavior.h +18 -0
- package/src/definitions/UIKit/JSBUISplitViewController.h +26 -0
- package/src/definitions/UIKit/JSBUIStepper.h +31 -0
- package/src/definitions/UIKit/JSBUIStoryboard.h +19 -0
- package/src/definitions/UIKit/JSBUIStoryboardPopoverSegue.h +17 -0
- package/src/definitions/UIKit/JSBUIStoryboardSegue.h +23 -0
- package/src/definitions/UIKit/JSBUISwipeGestureRecognizer.h +19 -0
- package/src/definitions/UIKit/JSBUISwitch.h +20 -0
- package/src/definitions/UIKit/JSBUITabBar.h +33 -0
- package/src/definitions/UIKit/JSBUITabBarController.h +26 -0
- package/src/definitions/UIKit/JSBUITabBarItem.h +26 -0
- package/src/definitions/UIKit/JSBUITableView.h +70 -0
- package/src/definitions/UIKit/JSBUITableViewCell.h +48 -0
- package/src/definitions/UIKit/JSBUITableViewController.h +19 -0
- package/src/definitions/UIKit/JSBUITableViewHeaderFooterView.h +22 -0
- package/src/definitions/UIKit/JSBUITapGestureRecognizer.h +20 -0
- package/src/definitions/UIKit/JSBUITextChecker.h +27 -0
- package/src/definitions/UIKit/JSBUITextField.h +44 -0
- package/src/definitions/UIKit/JSBUITextInputMode.h +41 -0
- package/src/definitions/UIKit/JSBUITextInputStringTokenizer.h +40 -0
- package/src/definitions/UIKit/JSBUITextPosition.h +38 -0
- package/src/definitions/UIKit/JSBUITextRange.h +38 -0
- package/src/definitions/UIKit/JSBUITextSelectionRect.h +36 -0
- package/src/definitions/UIKit/JSBUITextView.h +34 -0
- package/src/definitions/UIKit/JSBUIToolbar.h +22 -0
- package/src/definitions/UIKit/JSBUITouch.h +49 -0
- package/src/definitions/UIKit/JSBUIVideoEditorController.h +19 -0
- package/src/definitions/UIKit/JSBUIView.h +140 -0
- package/src/definitions/UIKit/JSBUIViewController.h +127 -0
- package/src/definitions/UIKit/JSBUIViewPrintFormatter.h +15 -0
- package/src/definitions/UIKit/JSBUIWebView.h +38 -0
- package/src/definitions/UIKit/JSBUIWindow.h +32 -0
- package/src/styles/starlight-overrides.css +23 -0
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 脑图与选区
|
|
3
|
+
description: 获取当前脑图、焦点笔记与文档选区,并高亮指定笔记。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
通过 StudyController 可以访问当前窗口的脑图、焦点笔记和文档选区;还可以在脑图或文档中高亮指定笔记。
|
|
7
|
+
|
|
8
|
+
## 获取学习控制器与脑图
|
|
9
|
+
|
|
10
|
+
在已打开笔记本的窗口内(例如在工具栏按钮的回调或 `notebookWillOpen` 延迟后):
|
|
11
|
+
|
|
12
|
+
```javascript
|
|
13
|
+
var studyController = Application.sharedInstance().studyController(self.window);
|
|
14
|
+
if (!studyController) return;
|
|
15
|
+
|
|
16
|
+
var notebookController = studyController.notebookController;
|
|
17
|
+
var mindmapView = notebookController.mindmapView;
|
|
18
|
+
var focusNote = notebookController.focusNote; // 当前脑图中聚焦的笔记
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## 获取文档与选区
|
|
22
|
+
|
|
23
|
+
当前显示的文档控制器与用户在 PDF 中的选区文本:
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
var readerController = studyController.readerController;
|
|
27
|
+
var docController = readerController.currentDocumentController;
|
|
28
|
+
var document = docController.document; // MbBook
|
|
29
|
+
var selectionText = docController.selectionText; // 用户选中的文本
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
若用户未选中任何内容,`selectionText` 可能为 undefined 或空字符串。
|
|
33
|
+
|
|
34
|
+
## 在脑图中高亮指定笔记
|
|
35
|
+
|
|
36
|
+
若你已知某条笔记的 `noteId`,希望脑图滚动并高亮到该节点:
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
studyController.focusNoteInMindMapById(noteId);
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## 在文档中高亮指定笔记
|
|
43
|
+
|
|
44
|
+
若希望文档视图滚动并高亮到某条笔记对应的摘录位置:
|
|
45
|
+
|
|
46
|
+
```javascript
|
|
47
|
+
studyController.focusNoteInDocumentById(noteId);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 示例:将当前选区追加为评论
|
|
51
|
+
|
|
52
|
+
当用户先在 PDF 中选中一段文字,再点击插件按钮时,可将选区文本追加到当前焦点笔记的评论中:
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
var studyController = Application.sharedInstance().studyController(self.window);
|
|
56
|
+
if (!studyController) return;
|
|
57
|
+
var docController = studyController.readerController.currentDocumentController;
|
|
58
|
+
var focusNote = studyController.notebookController.focusNote;
|
|
59
|
+
var text = docController.selectionText;
|
|
60
|
+
|
|
61
|
+
if (focusNote && text && text.length > 0) {
|
|
62
|
+
var topicid = focusNote.notebookId;
|
|
63
|
+
UndoManager.sharedInstance().undoGrouping("追加选区为评论", topicid, function () {
|
|
64
|
+
focusNote.appendTextComment(text);
|
|
65
|
+
});
|
|
66
|
+
Application.sharedInstance().refreshAfterDBChanged(topicid);
|
|
67
|
+
Application.sharedInstance().showHUD("已追加为评论", self.window, 2);
|
|
68
|
+
} else {
|
|
69
|
+
Application.sharedInstance().alert("请先选中一条笔记并在文档中选中文字");
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## 相关
|
|
74
|
+
|
|
75
|
+
- [StudyController](/reference/marginnote/study-controller/)、[NotebookController](/reference/marginnote/notebook-controller/)、[DocumentController](/reference/marginnote/document-controller/)
|
|
76
|
+
- [Cookbook:将选区追加为评论](/guides/cookbook/append-selection-as-comment/)、[在脑图中高亮指定笔记](/guides/cookbook/focus-note-in-mindmap/)
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 原生 UI
|
|
3
|
+
description: 使用 UIView、UILabel、UIButton、UIAlertView 等构建简单界面。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
插件可以使用 MarginNote 暴露的 UIKit 接口创建原生界面,例如浮窗、按钮、标签和弹窗。将视图添加到 `Application.sharedInstance().studyController(self.window).view` 即可显示在主学习界面上。
|
|
7
|
+
|
|
8
|
+
## 创建并添加一个视图
|
|
9
|
+
|
|
10
|
+
```javascript
|
|
11
|
+
var frame = { x: 0, y: 0, width: 100, height: 50 };
|
|
12
|
+
var myView = new UIView(frame);
|
|
13
|
+
myView.backgroundColor = UIColor.colorWithHexString("#FF0000"); // 红色,若支持 hex
|
|
14
|
+
|
|
15
|
+
Application.sharedInstance().studyController(self.window).view.addSubview(myView);
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
若没有 `colorWithHexString`,可用 `UIColor.colorWithRedGreenBlueAlpha(1, 0, 0, 1)`。
|
|
19
|
+
|
|
20
|
+
## 添加标签(UILabel)
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
var label = new UILabel({ x: 10, y: 10, width: 80, height: 30 });
|
|
24
|
+
label.text = "Hello!";
|
|
25
|
+
label.textColor = UIColor.whiteColor();
|
|
26
|
+
myView.addSubview(label);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 添加按钮并响应点击
|
|
30
|
+
|
|
31
|
+
按钮的点击必须通过 **addTargetActionForControlEvents** 绑定到 **JSB.defineClass 的实例方法**,且该方法名**必须以冒号结尾**(如 `myButtonTapped:`)。
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
var btn = UIButton.buttonWithType(0);
|
|
35
|
+
btn.frame = { x: 10, y: 60, width: 80, height: 40 };
|
|
36
|
+
btn.setTitleForState("Click Me", 0);
|
|
37
|
+
btn.addTargetActionForControlEvents(self, "myButtonTapped:", 1 << 6); // 1<<6 = TouchUpInside
|
|
38
|
+
myView.addSubview(btn);
|
|
39
|
+
|
|
40
|
+
// 在实例方法中定义:
|
|
41
|
+
// myButtonTapped: function (sender) {
|
|
42
|
+
// Application.sharedInstance().alert("Button was tapped!");
|
|
43
|
+
// }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## 弹窗(UIAlertView)
|
|
47
|
+
|
|
48
|
+
带回调的确认框可这样写:
|
|
49
|
+
|
|
50
|
+
```javascript
|
|
51
|
+
UIAlertView.showWithTitleMessageStyleCancelButtonTitleOtherButtonTitlesTapBlock(
|
|
52
|
+
"确认",
|
|
53
|
+
"是否执行该操作?",
|
|
54
|
+
0,
|
|
55
|
+
"取消",
|
|
56
|
+
["确定"],
|
|
57
|
+
function (alert, buttonIndex) {
|
|
58
|
+
if (buttonIndex === 0) {
|
|
59
|
+
JSB.log("用户点击了确定");
|
|
60
|
+
} else {
|
|
61
|
+
JSB.log("用户取消");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
`buttonIndex` 为 0 表示第一个「其他」按钮,-1 表示取消。
|
|
68
|
+
|
|
69
|
+
## 使用 WebView
|
|
70
|
+
|
|
71
|
+
在插件中嵌入网页或本地 HTML 可使用 [UIWebView](/reference/uikit/uiwebview/)。创建 WebView、设置 frame 与 delegate,在承载它的 ViewController 的**实例成员**中实现 UIWebViewDelegate 回调(webViewDidStartLoad、webViewDidFinishLoad、webViewDidFailLoadWithError、webViewShouldStartLoadWithRequestNavigationType)。
|
|
72
|
+
|
|
73
|
+
### 创建并加载远程 URL
|
|
74
|
+
|
|
75
|
+
```javascript
|
|
76
|
+
var webFrame = { x: 0, y: 40, width: self.view.bounds.width, height: self.view.bounds.height - 40 };
|
|
77
|
+
self.webView = new UIWebView(webFrame);
|
|
78
|
+
self.webView.backgroundColor = UIColor.whiteColor();
|
|
79
|
+
self.webView.scalesPageToFit = true;
|
|
80
|
+
self.webView.autoresizingMask = (1 << 1 | 1 << 4 | 1 << 5);
|
|
81
|
+
self.webView.delegate = self;
|
|
82
|
+
self.view.addSubview(self.webView);
|
|
83
|
+
self.webView.loadRequest(NSURLRequest.requestWithURL(NSURL.URLWithString("http://www.apple.com/")));
|
|
84
|
+
// 若需设置 User-Agent 等,可用 NSMutableURLRequest 构建请求,再 loadRequest(req)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### 加载本地 HTML 字符串
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
var html = "<html><body><h1>Hello</h1></body></html>";
|
|
91
|
+
self.webView.loadHTMLStringBaseURL(html, null); // 以示例为准,JS 中方法名为 loadHTMLStringBaseURL(string, baseURL);若环境不同则可能为 loadHTMLString
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Delegate 回调(实例成员)
|
|
95
|
+
|
|
96
|
+
建议在 **viewWillAppear** 中设置 `self.webView.delegate = self`(确保每次显示时 delegate 有效),在 **viewWillDisappear** 中调用 `self.webView.stopLoading()` 并设置 `self.webView.delegate = null`,避免视图消失后仍收到回调。
|
|
97
|
+
|
|
98
|
+
在 `JSB.defineClass` 的第二个参数中定义:
|
|
99
|
+
|
|
100
|
+
```javascript
|
|
101
|
+
webViewDidStartLoad: function (webView) {
|
|
102
|
+
// 开始加载,可显示 loading
|
|
103
|
+
},
|
|
104
|
+
webViewDidFinishLoad: function (webView) {
|
|
105
|
+
// 加载完成
|
|
106
|
+
},
|
|
107
|
+
webViewDidFailLoadWithError: function (webView, error) {
|
|
108
|
+
// 加载失败;可用 error.localizedDescription 获取错误信息,拼接 HTML 后用 loadHTMLStringBaseURL 显示错误页
|
|
109
|
+
},
|
|
110
|
+
webViewShouldStartLoadWithRequestNavigationType: function (webView, request, type) {
|
|
111
|
+
return true; // 若拦截自定义 URL Scheme 则解析后 return false
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### 插件向页面注入 JS
|
|
116
|
+
|
|
117
|
+
加载完成后可用 `evaluateJavaScript` 在页面上下文中执行脚本:
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
self.webView.evaluateJavaScript("document.title", function (result) {
|
|
121
|
+
JSB.log("页面标题: %@", result);
|
|
122
|
+
});
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
WebView 内 JS 与插件 JS 的双向通信(自定义 URL Scheme 拦截 + evaluateJavaScript)见 [Cookbook:WebView 内 JS 与插件 JS 双向通信](/guides/cookbook/webview-bidirectional-js/)。
|
|
126
|
+
|
|
127
|
+
## 布局与圆角
|
|
128
|
+
|
|
129
|
+
- 通过设置 `view.frame` 控制位置和大小;在 `controllerWillLayoutSubviews` 中根据 `studyController.view.bounds` 重新计算 frame,可适配窗口变化。
|
|
130
|
+
- 使用 `view.layer.cornerRadius`、`view.layer.borderWidth`、`view.layer.borderColor` 设置圆角与边框。
|
|
131
|
+
|
|
132
|
+
## 相关
|
|
133
|
+
|
|
134
|
+
- [UIView](/reference/uikit/uiview/)、[UIButton](/reference/uikit/uibutton/)、[UIAlertView](/reference/uikit/uialertview/)、[UIWebView](/reference/uikit/uiwebview/)、[UIColor](/reference/uikit/uicolor/)
|
|
135
|
+
- [工具栏与命令](/guides/toolbar-and-commands/) — 将面板与工具栏按钮联动
|
|
136
|
+
- [Cookbook:WebView 内 JS 与插件 JS 双向通信](/guides/cookbook/webview-bidirectional-js/)
|
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 网络请求
|
|
3
|
+
description: 使用 NSURLConnection 发起 HTTP 请求;含 Base64 解码与 Response 封装完整代码,解析 JSON 与纯文本。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
插件运行在 JavaScriptCore 环境中,**没有浏览器的 `fetch`**,也**没有内置的 Base64 解码**。网络请求需使用系统导出的 `NSURLConnection`,配合 `NSMutableURLRequest`、`NSOperationQueue`、`NSData`、`NSJSONSerialization` 等完成。响应体在回调的 **data**(NSData)里;**data 转 JSON 与 data 转纯文本方式不同**:JSON 用 `NSJSONSerialization` 直接对 data 解析,纯文本需先用 `data.base64Encoding()` 再经 Base64 解码得字符串(需自行提供 Base64 解码实现)。下文给出完整可用的 Base64 解码与网络封装代码,照抄即用。
|
|
7
|
+
|
|
8
|
+
## 核心要点
|
|
9
|
+
|
|
10
|
+
- **读 data**:异步回调形参为 `(response, data, error)`。响应体在 **data**(NSData)里,处理结果以 data 为主;`response` 用于取 `statusCode()`,`error` 用于判断失败,不必用到所有参数。
|
|
11
|
+
- **data → JSON**:直接对 **NSData** 调用 `NSJSONSerialization.JSONObjectWithDataOptions(data, 0 或 1)`,得到 JS 对象;**不要**先转成字符串再 `JSON.parse`。
|
|
12
|
+
- **data → 纯文本**:环境中无现成「NSData → 字符串」API 时,用 `data.base64Encoding()` 得到 base64 字符串,再用 **Base64 解码**得到 JS 字符串。运行时不提供 Base64 解码,需在插件内实现(见下一节完整代码)。
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Base64 解码
|
|
17
|
+
|
|
18
|
+
环境中没有 Base64 的 decode,需在插件中自备。将以下代码保存为 `base64.js`,放在插件包内,在入口(如 main.js)中先 `JSB.require('base64')` 再使用依赖它的网络封装。
|
|
19
|
+
|
|
20
|
+
```javascript
|
|
21
|
+
// base64.js —— Base64 解码工具,供 NSData 转纯文本使用
|
|
22
|
+
var Base64 = {
|
|
23
|
+
_keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
|
|
24
|
+
|
|
25
|
+
decode: function (input) {
|
|
26
|
+
var output = "";
|
|
27
|
+
var i = 0;
|
|
28
|
+
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
|
|
29
|
+
|
|
30
|
+
while (i < input.length) {
|
|
31
|
+
enc1 = this._keyStr.indexOf(input.charAt(i++));
|
|
32
|
+
enc2 = this._keyStr.indexOf(input.charAt(i++));
|
|
33
|
+
enc3 = this._keyStr.indexOf(input.charAt(i++));
|
|
34
|
+
enc4 = this._keyStr.indexOf(input.charAt(i++));
|
|
35
|
+
|
|
36
|
+
chr1 = (enc1 << 2) | (enc2 >> 4);
|
|
37
|
+
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
|
|
38
|
+
chr3 = ((enc3 & 3) << 6) | enc4;
|
|
39
|
+
|
|
40
|
+
output = output + String.fromCharCode(chr1);
|
|
41
|
+
if (enc3 != 64) {
|
|
42
|
+
output = output + String.fromCharCode(chr2);
|
|
43
|
+
}
|
|
44
|
+
if (enc4 != 64) {
|
|
45
|
+
output = output + String.fromCharCode(chr3);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return output;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 网络封装:Response + MNNetwork
|
|
57
|
+
|
|
58
|
+
以下封装提供 `Response#text()`(data → 纯文本,依赖 Base64)和 `Response#json()`(data → JS 对象,直接对 NSData 用 NSJSONSerialization)。将代码保存为 `network.js`,在入口中先 `JSB.require('base64')` 再 `JSB.require('network')`,然后使用 `MNNetwork.fetch(url, options)`。
|
|
59
|
+
|
|
60
|
+
```javascript
|
|
61
|
+
// network.js —— Response#text() 依赖 Base64,由入口加载 base64.js 后可用
|
|
62
|
+
|
|
63
|
+
class Response {
|
|
64
|
+
constructor(data, nsResponse) {
|
|
65
|
+
this.data = data;
|
|
66
|
+
this.nsResponse = nsResponse;
|
|
67
|
+
this.status = nsResponse ? nsResponse.statusCode() : 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static isNil(obj) {
|
|
71
|
+
return obj === null || typeof obj === 'undefined' || obj instanceof NSNull;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
text() {
|
|
75
|
+
if (Response.isNil(this.data) || this.data.length() === 0) return "";
|
|
76
|
+
|
|
77
|
+
var encoding = this.data.base64Encoding();
|
|
78
|
+
var decoding = Base64.decode(encoding);
|
|
79
|
+
return decoding;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
json() {
|
|
83
|
+
if (Response.isNil(this.data) || this.data.length() === 0) return {};
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
return NSJSONSerialization.JSONObjectWithDataOptions(this.data, 1);
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
class MNNetwork {
|
|
94
|
+
static isNil(obj) {
|
|
95
|
+
return obj === null || typeof obj === 'undefined' || obj instanceof NSNull;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static _initRequest(url, options) {
|
|
99
|
+
var fullUrl = url.trim();
|
|
100
|
+
if (fullUrl.indexOf("://") === -1) fullUrl = "https://" + fullUrl;
|
|
101
|
+
|
|
102
|
+
var request = NSMutableURLRequest.requestWithURL(NSURL.URLWithString(fullUrl));
|
|
103
|
+
request.setHTTPMethod(options.method || "GET");
|
|
104
|
+
request.setTimeoutInterval(options.timeout || 10);
|
|
105
|
+
|
|
106
|
+
var headers = {
|
|
107
|
+
"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 15_0 like Mac OS X)",
|
|
108
|
+
"Content-Type": "application/json",
|
|
109
|
+
"Accept": "application/json"
|
|
110
|
+
};
|
|
111
|
+
if (options.headers) {
|
|
112
|
+
for (var k in options.headers) headers[k] = options.headers[k];
|
|
113
|
+
}
|
|
114
|
+
request.setAllHTTPHeaderFields(headers);
|
|
115
|
+
|
|
116
|
+
if (options.json) {
|
|
117
|
+
request.setHTTPBody(NSJSONSerialization.dataWithJSONObjectOptions(options.json, 1));
|
|
118
|
+
} else if (options.body) {
|
|
119
|
+
request.setHTTPBody(NSData.dataWithStringEncoding(String(options.body), 4));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (options.search) {
|
|
123
|
+
var components = NSURLComponents.componentsWithString(fullUrl);
|
|
124
|
+
var qs = Object.keys(options.search).map(function (k) {
|
|
125
|
+
return encodeURIComponent(k) + "=" + encodeURIComponent(options.search[k]);
|
|
126
|
+
}).join("&");
|
|
127
|
+
components.query = qs;
|
|
128
|
+
request.setURL(components.URL());
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return request;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static fetch(url, options) {
|
|
135
|
+
var req = this._initRequest(url, options || {});
|
|
136
|
+
|
|
137
|
+
return new Promise(function (resolve, reject) {
|
|
138
|
+
NSURLConnection.sendAsynchronousRequestQueueCompletionHandler(
|
|
139
|
+
req,
|
|
140
|
+
NSOperationQueue.mainQueue(),
|
|
141
|
+
function (res, data, err) {
|
|
142
|
+
if (!MNNetwork.isNil(err)) {
|
|
143
|
+
reject(err.localizedDescription ? err.localizedDescription() : "Network Error");
|
|
144
|
+
} else {
|
|
145
|
+
var response = new Response(data, res);
|
|
146
|
+
resolve(response);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**说明**:
|
|
156
|
+
|
|
157
|
+
- `Response#text()`:用 `data.base64Encoding()` 得到 base64 串,再 `Base64.decode(encoding)` 得到 JS 字符串;环境无 Base64 解码,故依赖上面的 `base64.js`。
|
|
158
|
+
- `Response#json()`:直接对 **NSData** 调用 `NSJSONSerialization.JSONObjectWithDataOptions(this.data, 1)`,不经过 base64 或字符串。
|
|
159
|
+
- 错误信息:`error.localizedDescription` 在部分运行时为方法,需 `error.localizedDescription()`,封装里已按「有则调用」处理。
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## 使用封装发起请求
|
|
164
|
+
|
|
165
|
+
在 main.js(或入口)中的使用示例:
|
|
166
|
+
|
|
167
|
+
```javascript
|
|
168
|
+
JSB.require('base64');
|
|
169
|
+
JSB.require('network');
|
|
170
|
+
|
|
171
|
+
// GET JSON
|
|
172
|
+
async function fetchQuote() {
|
|
173
|
+
try {
|
|
174
|
+
var res = await MNNetwork.fetch("https://api.quotable.io/random");
|
|
175
|
+
var obj = res.json();
|
|
176
|
+
if (obj && obj.content) {
|
|
177
|
+
Application.sharedInstance().showHUD(obj.content, self.window, 3);
|
|
178
|
+
}
|
|
179
|
+
} catch (err) {
|
|
180
|
+
Application.sharedInstance().alert("请求失败: " + err);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// GET 纯文本(如某接口返回 text/plain)
|
|
185
|
+
async function fetchPlain() {
|
|
186
|
+
try {
|
|
187
|
+
var res = await MNNetwork.fetch("https://example.com/plain");
|
|
188
|
+
var str = res.text();
|
|
189
|
+
Application.sharedInstance().showHUD(str.substring(0, 80), self.window, 2);
|
|
190
|
+
} catch (err) {
|
|
191
|
+
Application.sharedInstance().alert("请求失败: " + err);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// POST JSON
|
|
196
|
+
async function postEcho() {
|
|
197
|
+
try {
|
|
198
|
+
var res = await MNNetwork.fetch("https://api.example.com/echo", {
|
|
199
|
+
method: "POST",
|
|
200
|
+
json: { key: "value" }
|
|
201
|
+
});
|
|
202
|
+
var obj = res.json();
|
|
203
|
+
// 使用 obj...
|
|
204
|
+
} catch (err) {
|
|
205
|
+
Application.sharedInstance().alert("请求失败: " + err);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// 自定义 Headers(如 Authorization)
|
|
210
|
+
async function fetchWithAuth() {
|
|
211
|
+
try {
|
|
212
|
+
var res = await MNNetwork.fetch("https://api.example.com/data", {
|
|
213
|
+
headers: {
|
|
214
|
+
"Authorization": "Bearer YOUR_API_KEY",
|
|
215
|
+
"Accept": "application/json"
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
var obj = res.json(); // 或 res.text()
|
|
219
|
+
// 使用 obj...
|
|
220
|
+
} catch (err) {
|
|
221
|
+
Application.sharedInstance().alert("请求失败: " + err);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 不使用封装时的原始写法
|
|
229
|
+
|
|
230
|
+
若不引入上述封装,直接使用系统 API 时要点如下。
|
|
231
|
+
|
|
232
|
+
- **回调**:`NSURLConnection.sendAsynchronousRequestQueueCompletionHandler(request, NSOperationQueue.mainQueue(), function (response, data, error) { ... })`。有用的是 **data**(响应体)、可选的 `response.statusCode()`、以及 **error**(失败时)。
|
|
233
|
+
- **JSON**:直接对 **data**(NSData)解析,不要先转字符串再 `JSON.parse`:
|
|
234
|
+
- `var obj = NSJSONSerialization.JSONObjectWithDataOptions(data, 0);` 或选项 `1`(若运行时支持)。
|
|
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
|
+
|
|
238
|
+
**原始 GET + JSON 示例**:
|
|
239
|
+
|
|
240
|
+
```javascript
|
|
241
|
+
var req = NSMutableURLRequest.requestWithURL(NSURL.URLWithString("https://api.quotable.io/random"));
|
|
242
|
+
req.setTimeoutInterval(10);
|
|
243
|
+
|
|
244
|
+
NSURLConnection.sendAsynchronousRequestQueueCompletionHandler(
|
|
245
|
+
req,
|
|
246
|
+
NSOperationQueue.mainQueue(),
|
|
247
|
+
function (response, data, error) {
|
|
248
|
+
if (error) {
|
|
249
|
+
var msg = (typeof error.localizedDescription === "function" ? error.localizedDescription() : error.localizedDescription) || "未知错误";
|
|
250
|
+
Application.sharedInstance().alert("请求失败: " + msg);
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (!data || data.length() === 0) {
|
|
254
|
+
Application.sharedInstance().alert("无响应数据");
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
var obj = NSJSONSerialization.JSONObjectWithDataOptions(data, 0);
|
|
258
|
+
if (NSJSONSerialization.isValidJSONObject(obj)) {
|
|
259
|
+
Application.sharedInstance().showHUD(obj.content || JSON.stringify(obj), self.window, 3);
|
|
260
|
+
} else {
|
|
261
|
+
Application.sharedInstance().alert("响应不是有效 JSON");
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
);
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
**原始 POST JSON 示例**:
|
|
268
|
+
|
|
269
|
+
```javascript
|
|
270
|
+
var req = NSMutableURLRequest.requestWithURL(NSURL.URLWithString(url));
|
|
271
|
+
req.setHTTPMethod("POST");
|
|
272
|
+
req.setTimeoutInterval(10);
|
|
273
|
+
req.setValueForHTTPHeaderField("application/json", "Content-Type");
|
|
274
|
+
req.setHTTPBody(NSJSONSerialization.dataWithJSONObjectOptions(jsonBody, 0));
|
|
275
|
+
|
|
276
|
+
NSURLConnection.sendAsynchronousRequestQueueCompletionHandler(
|
|
277
|
+
req,
|
|
278
|
+
NSOperationQueue.mainQueue(),
|
|
279
|
+
function (response, data, error) {
|
|
280
|
+
if (error) {
|
|
281
|
+
var msg = (typeof error.localizedDescription === "function" ? error.localizedDescription() : error.localizedDescription) || "未知错误";
|
|
282
|
+
Application.sharedInstance().alert("请求失败: " + msg);
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
if (!data || data.length() === 0) return;
|
|
286
|
+
var obj = NSJSONSerialization.JSONObjectWithDataOptions(data, 0);
|
|
287
|
+
// 使用 obj...
|
|
288
|
+
}
|
|
289
|
+
);
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
---
|
|
293
|
+
|
|
294
|
+
## 小结
|
|
295
|
+
|
|
296
|
+
| 目的 | 做法 |
|
|
297
|
+
|------|------|
|
|
298
|
+
| 响应体 | 使用回调中的 **data**(NSData),不必依赖 response 的其他字段 |
|
|
299
|
+
| data → JSON | `NSJSONSerialization.JSONObjectWithDataOptions(data, 0)` 或 `1`,直接对 data |
|
|
300
|
+
| data → 纯文本 | `data.base64Encoding()` 得到 base64 串,再 **Base64.decode**(需自备 base64.js) |
|
|
301
|
+
| 错误信息 | `error.localizedDescription` 或 `error.localizedDescription()`,依运行时而定 |
|
|
302
|
+
|
|
303
|
+
推荐在插件内包含完整的 `base64.js` 与 `network.js`(如上),先 `JSB.require('base64')` 再 `JSB.require('network')`,然后用 `MNNetwork.fetch` 发起请求,在 try/catch 中用 `res.json()` 或 `res.text()` 处理 JSON 与纯文本。
|
|
304
|
+
|
|
305
|
+
## 相关
|
|
306
|
+
|
|
307
|
+
- [Cookbook:调用远程 API](/guides/cookbook/network-api-call/) —— 将 API 结果展示或写入笔记
|
|
308
|
+
- [JavaScript 原生环境](/reference/js-runtime/) —— 为何没有 fetch
|
|
309
|
+
- [NSURLConnection](/reference/foundation/ns-url-connection/)、[NSMutableURLRequest](/reference/foundation/ns-mutable-url-request/)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 笔记与数据库
|
|
3
|
+
description: 通过 Database 获取与修改笔记,并正确使用 Undo 与刷新。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
插件的核心能力之一是对笔记与笔记本进行读写。通过 `Database.sharedInstance()` 获取数据库单例;**修改笔记或笔记本数据时,应使用 UndoManager 的 `undoGrouping` 包裹**,以支持撤销并在执行后刷新界面。
|
|
7
|
+
|
|
8
|
+
## 获取数据库与笔记
|
|
9
|
+
|
|
10
|
+
```javascript
|
|
11
|
+
var db = Database.sharedInstance();
|
|
12
|
+
var note = db.getNoteById("某个笔记 ID");
|
|
13
|
+
var notebook = db.getNotebookById("某个笔记本 ID");
|
|
14
|
+
var doc = db.getDocumentById("某个文档 MD5");
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
- `getNoteById(noteId)`:返回 `MbBookNote` 或 undefined。
|
|
18
|
+
- `getNotebookById(topicId)`:返回 `MbTopic` 或 undefined。
|
|
19
|
+
- `getDocumentById(docMd5)`:返回 `MbBook` 或 undefined。
|
|
20
|
+
|
|
21
|
+
获取列表:
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
var allNotebooks = db.allNotebooks();
|
|
25
|
+
var allDocuments = db.allDocuments();
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## 修改笔记与 Undo
|
|
29
|
+
|
|
30
|
+
修改笔记属性后,应放在 **UndoManager 的 undoGrouping** 中执行。常用属性:`noteTitle`(笔记标题)、`excerptText`(摘录/高亮文本)、`colorIndex`(颜色索引),并传入**当前笔记本 ID**(可从 `note.notebookId` 取)。这样用户可撤销,且界面会正确刷新。
|
|
31
|
+
|
|
32
|
+
```javascript
|
|
33
|
+
var noteId = "要修改的笔记 ID";
|
|
34
|
+
var note = Database.sharedInstance().getNoteById(noteId);
|
|
35
|
+
if (note) {
|
|
36
|
+
var topicid = note.notebookId;
|
|
37
|
+
UndoManager.sharedInstance().undoGrouping(
|
|
38
|
+
"修改笔记标题",
|
|
39
|
+
topicid,
|
|
40
|
+
function () {
|
|
41
|
+
note.noteTitle = "新标题"; // 或修改 excerptText、colorIndex 等
|
|
42
|
+
}
|
|
43
|
+
);
|
|
44
|
+
Application.sharedInstance().refreshAfterDBChanged(topicid);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## 创建新笔记
|
|
49
|
+
|
|
50
|
+
使用全局 `Note` 对象创建新笔记:`Note.createWithTitleNotebookDocument(title, notebook, doc)`(`notebook` 为 `MbTopic`,`doc` 为 `MbBook`)。创建后同样建议放在 undoGrouping 中并刷新。
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
var db = Database.sharedInstance();
|
|
54
|
+
var notebook = db.getNotebookById("某个笔记本 ID");
|
|
55
|
+
var doc = db.getDocumentById("某个文档 MD5");
|
|
56
|
+
|
|
57
|
+
if (notebook && doc) {
|
|
58
|
+
var topicid = notebook.topicId || notebook.topicid;
|
|
59
|
+
UndoManager.sharedInstance().undoGrouping(
|
|
60
|
+
"创建笔记",
|
|
61
|
+
topicid,
|
|
62
|
+
function () {
|
|
63
|
+
var note = Note.createWithTitleNotebookDocument("新笔记", notebook, doc);
|
|
64
|
+
// note 为 MbBookNote
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
Application.sharedInstance().refreshAfterDBChanged(topicid);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## 删除笔记
|
|
72
|
+
|
|
73
|
+
- `Database.sharedInstance().deleteBookNote(noteId)`:只删除该条笔记,不删子节点。
|
|
74
|
+
- `Database.sharedInstance().deleteBookNoteTree(noteId)`:删除该笔记及其所有后代。
|
|
75
|
+
|
|
76
|
+
删除后也应调用 `Application.sharedInstance().refreshAfterDBChanged(topicid)` 刷新对应笔记本界面。
|
|
77
|
+
|
|
78
|
+
## 示例:根据 noteId 修改标题并刷新
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
var noteId = "A_VALID_NOTE_ID";
|
|
82
|
+
var note = Database.sharedInstance().getNoteById(noteId);
|
|
83
|
+
if (note) {
|
|
84
|
+
var topicid = note.notebookId;
|
|
85
|
+
UndoManager.sharedInstance().undoGrouping(
|
|
86
|
+
"修改标题",
|
|
87
|
+
topicid,
|
|
88
|
+
function () {
|
|
89
|
+
note.noteTitle = "由插件修改后的标题";
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
Application.sharedInstance().refreshAfterDBChanged(topicid);
|
|
93
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 相关
|
|
97
|
+
|
|
98
|
+
- [Database](/reference/global/database/)、[MbBookNote](/reference/marginnote/mb-book-note/)、[UndoManager](/reference/utility/undo-manager/)
|
|
99
|
+
- [Cookbook:批量修改笔记标题](/guides/cookbook/batch-rename-notes/)
|