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,158 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 在插件中嵌入 WebView 面板
|
|
3
|
+
description: 从工具栏打开浮窗,浮窗内为 UIWebView,加载本地或内联 HTML,并与插件双向通信。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
**场景**:用户点击插件工具栏按钮后,在主界面上显示一个浮窗面板,面板内为 [UIWebView](/reference/uikit/uiwebview/),加载本地或内联 HTML;面板内可通过自定义 URL 触发插件逻辑(如 showHUD),插件也可通过 `evaluateJavaScript` 更新页面内容。
|
|
7
|
+
|
|
8
|
+
**要点**:浮窗为自定义 ViewController 的 view,在入口中 `JSB.require` 该 ViewController **一次**,在 `sceneWillConnect` 中创建实例;在 ViewController 的 **viewWillAppear** 中设置 `webView.delegate = self`,在 **viewWillDisappear** 中 `webView.stopLoading()` 并 `webView.delegate = null`。加载 HTML 用 `loadHTMLStringBaseURL(html, null)`,加载失败时在 `webViewDidFailLoadWithError` 中用 `error.localizedDescription` 拼 HTML 后用 `loadHTMLStringBaseURL` 显示错误页。双向通信写法见 [WebView 内 JS 与插件 JS 双向通信](/guides/cookbook/webview-bidirectional-js/)。
|
|
9
|
+
|
|
10
|
+
下文给出与 Samples/UIKit/WebView 同构的完整代码:main.js 中挂面板与切换显示,MyWebViewController.js 中创建 WebView、生命周期与 delegate。
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## main.js 中挂载面板
|
|
15
|
+
|
|
16
|
+
在 `JSB.newAddon` 内 **只** 在入口 require 一次 ViewController,在 `sceneWillConnect` 中创建实例并定义 `layoutViewController`,在 `notebookWillOpen` 中根据持久化 key 决定是否加 view,在 `toggleWebViewPanel` 中切换显示/隐藏;显示面板后可用 NSTimer 调用 `becomeFirstResponder` 便于在 iOS 上收起键盘。
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
JSB.newAddon = function (mainPath) {
|
|
20
|
+
JSB.require('MyWebViewController');
|
|
21
|
+
var newAddonClass = JSB.defineClass('MyWebViewAddon : JSExtension', {
|
|
22
|
+
sceneWillConnect: function () {
|
|
23
|
+
var self = this;
|
|
24
|
+
self.layoutViewController = function () {
|
|
25
|
+
var frame = Application.sharedInstance().studyController(self.window).view.bounds;
|
|
26
|
+
var width = frame.width > 300 ? (300 + (frame.width - 300) / 2) : 300;
|
|
27
|
+
self.webViewController.view.frame = {
|
|
28
|
+
x: (frame.width - width) / 2,
|
|
29
|
+
y: frame.height - 500,
|
|
30
|
+
width: width,
|
|
31
|
+
height: 480
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
self.webViewController = MyWebViewController.new();
|
|
35
|
+
self.webViewController.mainPath = mainPath;
|
|
36
|
+
},
|
|
37
|
+
notebookWillOpen: function (topicid) {
|
|
38
|
+
var self = this;
|
|
39
|
+
NSTimer.scheduledTimerWithTimeInterval(0.2, false, function () {
|
|
40
|
+
var on = NSUserDefaults.standardUserDefaults().objectForKey('my_webview_panel_on');
|
|
41
|
+
if (on === true) {
|
|
42
|
+
Application.sharedInstance().studyController(self.window).view.addSubview(self.webViewController.view);
|
|
43
|
+
self.layoutViewController();
|
|
44
|
+
Application.sharedInstance().studyController(self.window).refreshAddonCommands();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
controllerWillLayoutSubviews: function (controller) {
|
|
49
|
+
if (controller === Application.sharedInstance().studyController(self.window)) {
|
|
50
|
+
this.layoutViewController();
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
queryAddonCommandStatus: function () {
|
|
54
|
+
return {
|
|
55
|
+
image: 'icon.png',
|
|
56
|
+
object: this,
|
|
57
|
+
selector: 'toggleWebViewPanel:',
|
|
58
|
+
checked: this.webViewController.view.window ? true : false
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
toggleWebViewPanel: function (sender) {
|
|
62
|
+
var self = this;
|
|
63
|
+
if (self.webViewController.view.window) {
|
|
64
|
+
self.webViewController.view.removeFromSuperview();
|
|
65
|
+
NSUserDefaults.standardUserDefaults().setObjectForKey(false, 'my_webview_panel_on');
|
|
66
|
+
} else {
|
|
67
|
+
Application.sharedInstance().studyController(self.window).view.addSubview(self.webViewController.view);
|
|
68
|
+
self.layoutViewController();
|
|
69
|
+
NSUserDefaults.standardUserDefaults().setObjectForKey(true, 'my_webview_panel_on');
|
|
70
|
+
NSTimer.scheduledTimerWithTimeInterval(0.2, false, function () {
|
|
71
|
+
Application.sharedInstance().studyController(self.window).becomeFirstResponder();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
Application.sharedInstance().studyController(self.window).refreshAddonCommands();
|
|
75
|
+
}
|
|
76
|
+
}, {});
|
|
77
|
+
return newAddonClass;
|
|
78
|
+
};
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## MyWebViewController.js
|
|
84
|
+
|
|
85
|
+
将以下代码保存为 `MyWebViewController.js`,在入口中通过 `JSB.require('MyWebViewController')` 加载(见上一节)。
|
|
86
|
+
|
|
87
|
+
- **viewDidLoad**:创建 UIWebView,设置 `backgroundColor`、`scalesPageToFit`、`autoresizingMask`、`delegate`,`addSubview` 后 `loadRequest` 或 `loadHTMLStringBaseURL(html, null)`。
|
|
88
|
+
- **viewWillAppear**:`self.webView.delegate = self`。
|
|
89
|
+
- **viewWillDisappear**:`self.webView.stopLoading()`,`self.webView.delegate = null`。
|
|
90
|
+
- **webViewDidStartLoad / webViewDidFinishLoad**:可按需开关 `UIApplication.sharedApplication().networkActivityIndicatorVisible`。
|
|
91
|
+
- **webViewDidFailLoadWithError**:用 `error.localizedDescription` 替换错误页 HTML 中的占位符,`loadHTMLStringBaseURL(errorString, null)` 显示。
|
|
92
|
+
- **webViewShouldStartLoadWithRequestNavigationType**:若需双向通信,在此判断 `request.URL` 的 scheme(如 `marginnote`),解析后执行插件逻辑并 **return false**;否则 **return true**。
|
|
93
|
+
|
|
94
|
+
```javascript
|
|
95
|
+
var MyWebViewController = JSB.defineClass('MyWebViewController : UIViewController <UIWebViewDelegate>', {
|
|
96
|
+
viewDidLoad: function () {
|
|
97
|
+
self.view.backgroundColor = UIColor.whiteColor();
|
|
98
|
+
self.view.layer.shadowOffset = { width: 0, height: 0 };
|
|
99
|
+
self.view.layer.shadowRadius = 10;
|
|
100
|
+
self.view.layer.shadowOpacity = 0.5;
|
|
101
|
+
self.view.layer.shadowColor = UIColor.colorWithWhiteAlpha(0.5, 1);
|
|
102
|
+
|
|
103
|
+
var webFrame = { x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height };
|
|
104
|
+
self.webView = new UIWebView(webFrame);
|
|
105
|
+
self.webView.backgroundColor = UIColor.whiteColor();
|
|
106
|
+
self.webView.scalesPageToFit = true;
|
|
107
|
+
self.webView.autoresizingMask = (1 << 1 | 1 << 4 | 1 << 5);
|
|
108
|
+
self.webView.delegate = self;
|
|
109
|
+
self.view.addSubview(self.webView);
|
|
110
|
+
|
|
111
|
+
var html = '<!DOCTYPE html><html><body><p id="text">Hello</p><button id="btn">通知插件</button><script>document.getElementById("btn").onclick=function(){ window.location.href="marginnote://notify?msg="+encodeURIComponent("from page"); };</script></body></html>';
|
|
112
|
+
self.webView.loadHTMLStringBaseURL(html, null);
|
|
113
|
+
},
|
|
114
|
+
viewWillAppear: function (animated) {
|
|
115
|
+
self.webView.delegate = self;
|
|
116
|
+
},
|
|
117
|
+
viewWillDisappear: function (animated) {
|
|
118
|
+
self.webView.stopLoading();
|
|
119
|
+
self.webView.delegate = null;
|
|
120
|
+
UIApplication.sharedApplication().networkActivityIndicatorVisible = false;
|
|
121
|
+
},
|
|
122
|
+
webViewDidStartLoad: function (webView) {
|
|
123
|
+
UIApplication.sharedApplication().networkActivityIndicatorVisible = true;
|
|
124
|
+
},
|
|
125
|
+
webViewDidFinishLoad: function (webView) {
|
|
126
|
+
UIApplication.sharedApplication().networkActivityIndicatorVisible = false;
|
|
127
|
+
},
|
|
128
|
+
webViewDidFailLoadWithError: function (webView, error) {
|
|
129
|
+
UIApplication.sharedApplication().networkActivityIndicatorVisible = false;
|
|
130
|
+
var tpl = "<!DOCTYPE html><html><head><meta charset='utf-8'></head><body><div style='text-align:center;color:red;'>Error: %@</div></body></html>";
|
|
131
|
+
var errorString = tpl.replace("%@", error.localizedDescription);
|
|
132
|
+
self.webView.loadHTMLStringBaseURL(errorString, null);
|
|
133
|
+
},
|
|
134
|
+
webViewShouldStartLoadWithRequestNavigationType: function (webView, request, type) {
|
|
135
|
+
var url = request.URL;
|
|
136
|
+
if (!url) return true;
|
|
137
|
+
if (url.scheme === 'marginnote') {
|
|
138
|
+
var host = url.host || '';
|
|
139
|
+
var query = url.query || '';
|
|
140
|
+
if (host === 'notify') {
|
|
141
|
+
var msg = query.replace(/^msg=/, '').replace(/\+/g, ' ');
|
|
142
|
+
try { msg = decodeURIComponent(msg); } catch (e) {}
|
|
143
|
+
Application.sharedInstance().showHUD(msg, self.window, 2);
|
|
144
|
+
}
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## 相关
|
|
155
|
+
|
|
156
|
+
- [工具栏与命令](/guides/toolbar-and-commands/)、[原生 UI:使用 WebView](/guides/native-ui/#使用-webview)
|
|
157
|
+
- [WebView 内 JS 与插件 JS 双向通信](/guides/cookbook/webview-bidirectional-js/)、[UIWebView](/reference/uikit/uiwebview/)
|
|
158
|
+
- [网络请求](/guides/network-requests/) —— 获取远程数据后注入 HTML 或通过 evaluateJavaScript 注入
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 导出当前笔记本
|
|
3
|
+
description: 使用 Database.exportNotebook 导出当前笔记本并给出 HUD 提示。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
**场景**:用户点击插件按钮后,将当前打开的笔记本导出到指定路径,并显示成功或失败提示。
|
|
7
|
+
|
|
8
|
+
**步骤**:
|
|
9
|
+
|
|
10
|
+
1. 获取当前笔记本 ID:`studyController.notebookController.notebookId`。
|
|
11
|
+
2. 确定导出目标路径(如 `Application.sharedInstance().documentPath + "/Exports/" + 笔记本标题 + ".mnbk"`);若目录不存在,用 NSFileManager 创建。
|
|
12
|
+
3. 调用 `Database.sharedInstance().exportNotebook(topicid, storePath)`,返回 boolean 表示是否成功。
|
|
13
|
+
4. 用 `Application.sharedInstance().showHUD(message, self.window, 2)` 提示用户。
|
|
14
|
+
|
|
15
|
+
**完整示例**:
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
function exportCurrentNotebook() {
|
|
19
|
+
var studyController = Application.sharedInstance().studyController(self.window);
|
|
20
|
+
if (!studyController) return;
|
|
21
|
+
var topicid = studyController.notebookController.notebookId;
|
|
22
|
+
if (!topicid) return;
|
|
23
|
+
|
|
24
|
+
var notebook = Database.sharedInstance().getNotebookById(topicid);
|
|
25
|
+
if (!notebook) return;
|
|
26
|
+
|
|
27
|
+
var app = Application.sharedInstance();
|
|
28
|
+
var baseDir = app.documentPath + "/NotebookExports";
|
|
29
|
+
var fileManager = NSFileManager.defaultManager();
|
|
30
|
+
if (!fileManager.fileExistsAtPath(baseDir)) {
|
|
31
|
+
fileManager.createDirectoryAtPathWithIntermediateDirectoriesAttributes(baseDir, true, null);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var safeTitle = (notebook.title || "未命名").replace(/[/\\:*?"<>|]/g, "_");
|
|
35
|
+
var storePath = baseDir + "/" + safeTitle + "_" + Date.now() + ".mnbk";
|
|
36
|
+
|
|
37
|
+
var ok = Database.sharedInstance().exportNotebook(topicid, storePath);
|
|
38
|
+
if (ok) {
|
|
39
|
+
app.showHUD("已导出到:" + storePath, self.window, 3);
|
|
40
|
+
} else {
|
|
41
|
+
app.alert("导出失败");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
可将 `exportCurrentNotebook` 绑定到工具栏按钮(如 `exportNotebook:`),在对应实例方法中调用即可。
|
|
47
|
+
|
|
48
|
+
**相关**:[Database](/reference/global/database/)、[MbTopic](/reference/marginnote/mb-topic/)、[NSFileManager](/reference/foundation/ns-file-manager/)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 在脑图中高亮指定笔记
|
|
3
|
+
description: 使用 focusNoteInMindMapById 在脑图中滚动并高亮到指定笔记。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
**场景**:已知一条笔记的 `noteId`,希望脑图视图滚动并高亮到该节点,方便用户定位。
|
|
7
|
+
|
|
8
|
+
**步骤**:
|
|
9
|
+
|
|
10
|
+
1. 获取当前窗口的 StudyController:`Application.sharedInstance().studyController(self.window)`。
|
|
11
|
+
2. 调用 `studyController.focusNoteInMindMapById(noteId)`。
|
|
12
|
+
|
|
13
|
+
**完整示例**:从当前焦点笔记获取 noteId,再在脑图中高亮(可用于「重新定位到当前笔记」):
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
function focusCurrentNoteInMindMap() {
|
|
17
|
+
var studyController = Application.sharedInstance().studyController(self.window);
|
|
18
|
+
if (!studyController) return;
|
|
19
|
+
var focusNote = studyController.notebookController.focusNote;
|
|
20
|
+
if (!focusNote) {
|
|
21
|
+
Application.sharedInstance().alert("请先选中一条笔记");
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
studyController.focusNoteInMindMapById(focusNote.noteId);
|
|
25
|
+
}
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
若 noteId 来自其他来源(如列表选择、搜索结果的某条笔记),直接传入该 noteId 即可:
|
|
29
|
+
|
|
30
|
+
```javascript
|
|
31
|
+
studyController.focusNoteInMindMapById(someNoteId);
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**相关**:[StudyController](/reference/marginnote/study-controller/)、[脑图与选区](/guides/mindmap-and-selection/)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 调用远程 API
|
|
3
|
+
description: 用户点击插件按钮后,用 MNNetwork 调用 REST API,将返回的 JSON 或文本展示或写入笔记。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
**场景**:用户点击插件工具栏按钮后,调用某个 REST API(如公开接口),将返回的 JSON 或纯文本解析后通过 HUD/弹窗展示,或追加到当前焦点笔记的评论中。
|
|
7
|
+
|
|
8
|
+
**前提**:已按 [网络请求](/guides/network-requests/) 在插件内加入完整的 `base64.js` 与 `network.js`,并在入口中先 `JSB.require('base64')` 再 `JSB.require('network')`。以下示例均使用其中的 `MNNetwork.fetch`、`res.json()`、`res.text()`。
|
|
9
|
+
|
|
10
|
+
**步骤**:
|
|
11
|
+
|
|
12
|
+
1. 在工具栏命令对应的 selector 中调用封装:`await MNNetwork.fetch(url, options)` 得到响应,在 try 中用 `res.json()`(JSON)或 `res.text()`(纯文本)取结果
|
|
13
|
+
2. 将结果用 `showHUD` / `alert` 展示,或通过 `focusNote.appendTextComment` / `appendMarkdownComment` 写入笔记
|
|
14
|
+
3. 在 catch 中处理错误(如 `alert("请求失败: " + err)`)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 示例一:GET 并显示 HUD
|
|
19
|
+
|
|
20
|
+
调用公开接口获取一句话,解析 JSON 后用 HUD 显示。使用 [网络请求](/guides/network-requests/) 中的 `MNNetwork` 与 `base64.js`。
|
|
21
|
+
|
|
22
|
+
```javascript
|
|
23
|
+
// 入口中已执行:JSB.require('base64'); JSB.require('network');
|
|
24
|
+
|
|
25
|
+
async function fetchQuoteAndShow() {
|
|
26
|
+
try {
|
|
27
|
+
var res = await MNNetwork.fetch("https://api.quotable.io/random");
|
|
28
|
+
var obj = res.json();
|
|
29
|
+
if (!obj) {
|
|
30
|
+
Application.sharedInstance().showHUD("响应不是有效 JSON", self.window, 2);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
var text = (obj.content || obj.quote || JSON.stringify(obj)).substring(0, 80);
|
|
34
|
+
Application.sharedInstance().showHUD(text, self.window, 3);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
Application.sharedInstance().alert("请求失败: " + err);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
将 `fetchQuoteAndShow` 绑定到工具栏按钮的 selector(如 `fetchQuote:`),在 `fetchQuote:` 中调用即可。
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 示例二:GET 后写入笔记评论
|
|
46
|
+
|
|
47
|
+
将 API 返回的文本追加到当前焦点笔记的评论中,使用 `res.json()` 取内容后通过 UndoManager 写入。
|
|
48
|
+
|
|
49
|
+
```javascript
|
|
50
|
+
async function fetchAndAppendToNote() {
|
|
51
|
+
var studyController = Application.sharedInstance().studyController(self.window);
|
|
52
|
+
if (!studyController) return;
|
|
53
|
+
var focusNote = studyController.notebookController.focusNote;
|
|
54
|
+
if (!focusNote) {
|
|
55
|
+
Application.sharedInstance().alert("请先选中一条笔记");
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
var res = await MNNetwork.fetch("https://api.quotable.io/random");
|
|
61
|
+
var obj = res.json();
|
|
62
|
+
if (!obj) return;
|
|
63
|
+
|
|
64
|
+
var text = obj.content || obj.quote || JSON.stringify(obj);
|
|
65
|
+
var topicid = focusNote.notebookId;
|
|
66
|
+
UndoManager.sharedInstance().undoGrouping("追加 API 结果", topicid, function () {
|
|
67
|
+
focusNote.appendTextComment(text);
|
|
68
|
+
});
|
|
69
|
+
Application.sharedInstance().refreshAfterDBChanged(topicid);
|
|
70
|
+
Application.sharedInstance().showHUD("已追加到笔记", self.window, 2);
|
|
71
|
+
} catch (err) {
|
|
72
|
+
Application.sharedInstance().alert("请求失败: " + err);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 示例三:带 API Key 的请求
|
|
80
|
+
|
|
81
|
+
从 `NSUserDefaults` 读取保存的 API Key,通过 `options.headers` 传入。使用 [网络请求](/guides/network-requests/) 中的 `MNNetwork.fetch(url, { headers: { ... } })`。
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
async function fetchWithAPIKey() {
|
|
85
|
+
var apiKey = NSUserDefaults.standardUserDefaults().objectForKey("my_addon_api_key");
|
|
86
|
+
if (!apiKey) {
|
|
87
|
+
Application.sharedInstance().alert("请先在设置中填写 API Key");
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
try {
|
|
92
|
+
var res = await MNNetwork.fetch("https://api.example.com/data", {
|
|
93
|
+
headers: {
|
|
94
|
+
"Authorization": "Bearer " + apiKey,
|
|
95
|
+
"Accept": "application/json"
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
var obj = res.json();
|
|
99
|
+
if (NSJSONSerialization.isValidJSONObject(obj)) {
|
|
100
|
+
Application.sharedInstance().showHUD("获取成功", self.window, 2);
|
|
101
|
+
// 使用 obj...
|
|
102
|
+
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
Application.sharedInstance().alert("请求失败: " + err);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
API Key 的保存与读取见 [插件设置页](/guides/cookbook/addon-settings/)。保存后可选择调用简单 API 验证 Key 是否有效。
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 示例四:纯文本响应(res.text())
|
|
114
|
+
|
|
115
|
+
若接口返回的是纯文本(如 `text/plain`),用 `res.text()` 获取字符串。`text()` 依赖 [网络请求](/guides/network-requests/) 中的 `base64.js`(需已 `JSB.require('base64')`)。
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
async function fetchPlainText() {
|
|
119
|
+
try {
|
|
120
|
+
var res = await MNNetwork.fetch("https://example.com/plain");
|
|
121
|
+
var str = res.text();
|
|
122
|
+
Application.sharedInstance().showHUD(str.substring(0, 100), self.window, 3);
|
|
123
|
+
} catch (err) {
|
|
124
|
+
Application.sharedInstance().alert("请求失败: " + err);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
130
|
+
|
|
131
|
+
## 相关
|
|
132
|
+
|
|
133
|
+
- [网络请求](/guides/network-requests/) —— Base64 与 MNNetwork 完整代码、data 转 JSON/文本说明
|
|
134
|
+
- [插件设置页](/guides/cookbook/addon-settings/) —— 存储 API Key
|
|
135
|
+
- [笔记与数据库](/guides/notes-and-database/) —— 修改笔记与 Undo
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: WebView 内 JS 与插件 JS 双向通信
|
|
3
|
+
description: 通过 evaluateJavaScript 与自定义 URL Scheme 实现插件与 WebView 页面的双向调用。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
**场景**:插件内嵌 UIWebView 加载本地或远程 HTML,需要(1)插件向页面注入数据或执行脚本;(2)页面内按钮/脚本触发插件逻辑(如 showHUD、写数据库)。**WebView 内 JS 不能直接访问插件全局对象**(如 JSB、Application),只能通过「插件执行 evaluateJavaScript」或「页面跳转自定义 URL 被 delegate 拦截」实现通信。
|
|
7
|
+
|
|
8
|
+
**要点**:插件 → 页面用 `webView.evaluateJavaScript(script, completionHandler)`,直接对页面上下文执行 JS;页面 → 插件用自定义 URL(如 `marginnote://notify?msg=...`),在 `webViewShouldStartLoadWithRequestNavigationType` 中判断 `request.URL` 的 scheme,解析后执行插件逻辑并 **return false**。解析 URL 时注意:`marginnote://notify?msg=...` 中 `notify` 在 NSURL 里为 **host**,path 常为空,应使用 `url.host === "notify"` 或同时判断 path。
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 插件 → WebView 内 JS
|
|
13
|
+
|
|
14
|
+
使用 `webView.evaluateJavaScript(javaScriptString, completionHandler)` 在页面上下文中执行 JS。加载完成后(如在 `webViewDidFinishLoad` 中)调用。
|
|
15
|
+
|
|
16
|
+
**示例**:向页面注入数据并调用页面内全局函数。
|
|
17
|
+
|
|
18
|
+
```javascript
|
|
19
|
+
// 插件端(在 webViewDidFinishLoad 或用户点击后)
|
|
20
|
+
var data = { title: "来自插件", count: 1 };
|
|
21
|
+
var script = "window.receiveFromAddon && window.receiveFromAddon(" + JSON.stringify(JSON.stringify(data)) + ");";
|
|
22
|
+
self.webView.evaluateJavaScript(script, null);
|
|
23
|
+
|
|
24
|
+
// 或执行并取回结果
|
|
25
|
+
self.webView.evaluateJavaScript("document.title", function (result) {
|
|
26
|
+
JSB.log("页面标题: %@", result);
|
|
27
|
+
});
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
**页面内**(HTML 中):定义 `window.receiveFromAddon = function(jsonStr) { var data = JSON.parse(jsonStr); ... }` 即可在插件调用时收到数据。
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## WebView 内 JS → 插件
|
|
35
|
+
|
|
36
|
+
通过**自定义 URL Scheme** 由插件拦截:页面内执行 `location.href = 'marginnote://notify?msg=...'` 或创建 iframe 的 `src` 为自定义 URL。在 delegate 的 `webViewShouldStartLoadWithRequestNavigationType(webView, request, type)` 中判断 `request.URL` 的 scheme(如 `marginnote`),解析参数并执行插件逻辑,**return false** 阻止实际加载该 URL。
|
|
37
|
+
|
|
38
|
+
**HTML 片段**(内嵌或通过 `loadHTMLStringBaseURL` 加载):
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<button id="btn">通知插件</button>
|
|
42
|
+
<script>
|
|
43
|
+
document.getElementById("btn").onclick = function () {
|
|
44
|
+
var msg = "Hello from WebView";
|
|
45
|
+
window.location.href = "marginnote://notify?msg=" + encodeURIComponent(msg);
|
|
46
|
+
};
|
|
47
|
+
</script>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
**插件端**(ViewController 实例成员):`marginnote://notify?msg=...` 中 `notify` 为 **host**,不要只判断 path。
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
webViewShouldStartLoadWithRequestNavigationType: function (webView, request, type) {
|
|
54
|
+
var url = request.URL;
|
|
55
|
+
if (!url) return true;
|
|
56
|
+
if (url.scheme !== "marginnote") return true;
|
|
57
|
+
|
|
58
|
+
var host = url.host || "";
|
|
59
|
+
var isNotify = (host === "notify") || ((url.path || "").indexOf("notify") !== -1);
|
|
60
|
+
if (isNotify) {
|
|
61
|
+
var query = url.query || "";
|
|
62
|
+
var msg = query.replace(/^msg=/, "").replace(/\+/g, " ");
|
|
63
|
+
try { msg = decodeURIComponent(msg); } catch (e) {}
|
|
64
|
+
Application.sharedInstance().showHUD(msg, self.window, 2);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## 完整最小示例
|
|
74
|
+
|
|
75
|
+
**1. 插件内创建 WebView 并加载内联 HTML**(在 ViewController 的 viewDidLoad 中):
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
var html = [
|
|
79
|
+
"<!DOCTYPE html><html><body>",
|
|
80
|
+
"<p id='text'>初始</p>",
|
|
81
|
+
"<button id='send'>发送到插件</button>",
|
|
82
|
+
"<script>",
|
|
83
|
+
"document.getElementById('send').onclick = function() {",
|
|
84
|
+
" window.location.href = 'marginnote://notify?msg=' + encodeURIComponent('从页面发出');",
|
|
85
|
+
"};",
|
|
86
|
+
"</script>",
|
|
87
|
+
"</body></html>"
|
|
88
|
+
].join("");
|
|
89
|
+
self.webView = new UIWebView(frame);
|
|
90
|
+
self.webView.delegate = self;
|
|
91
|
+
self.view.addSubview(self.webView);
|
|
92
|
+
self.webView.loadHTMLStringBaseURL(html, null);
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**2. 实现 webViewShouldStartLoadWithRequestNavigationType**(见上一节,解析 `marginnote://notify?msg=...` 并 showHUD,return false)。
|
|
96
|
+
|
|
97
|
+
**3. 插件向页面更新文字**(如在 webViewDidFinishLoad 后执行):
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
self.webView.evaluateJavaScript("document.getElementById('text').innerText = '已由插件更新';", null);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
即形成「页面点击 → 自定义 URL → 插件拦截并 showHUD」与「插件 evaluateJavaScript 更新页面」的双向通信。
|
|
104
|
+
|
|
105
|
+
**加载失败**:在 `webViewDidFailLoadWithError` 中用 `error.localizedDescription` 拼 HTML,再 `loadHTMLStringBaseURL(errorString, null)` 显示错误页。
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## 相关
|
|
110
|
+
|
|
111
|
+
- [UIWebView](/reference/uikit/uiwebview/)、[原生 UI:使用 WebView](/guides/native-ui/#使用-webview)
|
|
112
|
+
- [Cookbook:在插件中嵌入 WebView 面板](/guides/cookbook/embed-webview-panel/)
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 快速开始
|
|
3
|
+
description: 从零运行你的第一个 MarginNote 插件(Hello World)。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
本教程将带你创建一个最简插件:在插件窗口连接时显示一条 "Hello World" 的 HUD 提示,并了解 `mnaddon.json` 与入口函数。
|
|
7
|
+
|
|
8
|
+
## 前提
|
|
9
|
+
|
|
10
|
+
- 已安装 MarginNote 3 或 MarginNote 4(MN3 建议 3.6.11 及以上)。
|
|
11
|
+
- 了解如何将 .mnaddon 包安装到 MarginNote 并在应用中启用插件。
|
|
12
|
+
|
|
13
|
+
## 第一步:插件包结构
|
|
14
|
+
|
|
15
|
+
创建一个文件夹作为插件包,至少包含:
|
|
16
|
+
|
|
17
|
+
- `main.js`:入口脚本,MarginNote 会加载并执行它。
|
|
18
|
+
- `mnaddon.json`:插件元数据,MarginNote 据此识别插件。
|
|
19
|
+
|
|
20
|
+
## 第二步:mnaddon.json
|
|
21
|
+
|
|
22
|
+
在插件包根目录创建 `mnaddon.json`,内容示例:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"addonid": "marginnote.extension.samplehelloworld",
|
|
27
|
+
"author": "你的名字",
|
|
28
|
+
"title": "Hello World",
|
|
29
|
+
"version": "1.0",
|
|
30
|
+
"marginnote_version_min": "3.6.11",
|
|
31
|
+
"cert_key": ""
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
- `addonid`:唯一 ID,建议用反向域名。
|
|
36
|
+
- `title`:在 MarginNote 中显示的插件名称。
|
|
37
|
+
- `marginnote_version_min`:最低支持的 MarginNote 版本。
|
|
38
|
+
|
|
39
|
+
## 第三步:实现 main.js 入口
|
|
40
|
+
|
|
41
|
+
MarginNote 加载插件时会调用全局函数 `JSB.newAddon(mainPath)`,你必须实现它并返回由 `JSB.defineClass` 创建的**类**(注意是类,不是实例;MarginNote 会自行实例化)。
|
|
42
|
+
|
|
43
|
+
在 `main.js` 中写入:
|
|
44
|
+
|
|
45
|
+
```javascript
|
|
46
|
+
JSB.newAddon = function (mainPath) {
|
|
47
|
+
var newAddonClass = JSB.defineClass(
|
|
48
|
+
"SampleHelloWorld : JSExtension",
|
|
49
|
+
{
|
|
50
|
+
sceneWillConnect: function () {
|
|
51
|
+
Application.sharedInstance().showHUD("Hello World", self.window, 2);
|
|
52
|
+
},
|
|
53
|
+
sceneDidDisconnect: function () {},
|
|
54
|
+
sceneWillResignActive: function () {},
|
|
55
|
+
sceneDidBecomeActive: function () {},
|
|
56
|
+
notebookWillOpen: function (topicid) {},
|
|
57
|
+
notebookWillClose: function (topicid) {},
|
|
58
|
+
documentDidOpen: function (docmd5) {},
|
|
59
|
+
documentWillClose: function (docmd5) {},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
addonDidConnect: function () {},
|
|
63
|
+
addonWillDisconnect: function () {},
|
|
64
|
+
applicationWillEnterForeground: function () {},
|
|
65
|
+
applicationDidEnterBackground: function () {},
|
|
66
|
+
applicationDidReceiveLocalNotification: function (notify) {},
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
return newAddonClass;
|
|
70
|
+
};
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
说明:
|
|
74
|
+
|
|
75
|
+
- `JSB.defineClass('类名 : JSExtension', 实例成员, 类成员)` 定义插件类;类名可自取,但必须继承 `JSExtension`。
|
|
76
|
+
- `sceneWillConnect` 在插件窗口即将连接时调用,这里用 `Application.sharedInstance().showHUD(message, view, duration)` 在 `self.window` 上显示 2 秒 HUD。
|
|
77
|
+
- `mainPath` 是插件包根目录路径,可用于加载包内资源。
|
|
78
|
+
|
|
79
|
+
## 第四步:安装与验证
|
|
80
|
+
|
|
81
|
+
1. 将包含 `main.js` 和 `mnaddon.json` 的文件夹打包成 `.mnaddon` 文件(本质为 zip:将上述文件放在 zip 根目录,扩展名改为 `.mnaddon`)。
|
|
82
|
+
2. 将 `.mnaddon` 安装到 MarginNote(按应用内说明或文档操作),并在应用中启用该插件。
|
|
83
|
+
3. 打开或切换到一个窗口,使插件窗口连接;应看到 "Hello World" 的 HUD。
|
|
84
|
+
|
|
85
|
+
## 下一步
|
|
86
|
+
|
|
87
|
+
- 了解各生命周期方法的调用时机:[生命周期与窗口](/guides/lifecycle-and-window/)。
|
|
88
|
+
- 查阅 [JSB](/reference/global/jsb/)、[Application](/reference/global/application/)、[JSExtension](/reference/marginnote/jsextension/) 的完整 API。
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 生命周期与窗口
|
|
3
|
+
description: 理解 scene/notebook/document 生命周期及何时可安全使用 studyController。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
插件通过 JSExtension 的生命周期方法感知「窗口」「笔记本」「文档」的创建与销毁。只有在合适的时机才能安全使用 `Application.sharedInstance().studyController(self.window)` 访问脑图与文档。
|
|
7
|
+
|
|
8
|
+
## 生命周期概览
|
|
9
|
+
|
|
10
|
+
### 窗口(Scene)
|
|
11
|
+
|
|
12
|
+
| 方法 | 调用时机 |
|
|
13
|
+
|------|----------|
|
|
14
|
+
| `sceneWillConnect()` | 插件窗口即将创建,可在此做轻量初始化;此时可能还没有打开笔记本。 |
|
|
15
|
+
| `sceneDidDisconnect()` | 插件窗口已断开。 |
|
|
16
|
+
| `sceneWillResignActive()` | 窗口即将失去活跃。 |
|
|
17
|
+
| `sceneDidBecomeActive()` | 窗口变为活跃。 |
|
|
18
|
+
|
|
19
|
+
### 笔记本
|
|
20
|
+
|
|
21
|
+
| 方法 | 调用时机 |
|
|
22
|
+
|------|----------|
|
|
23
|
+
| `notebookWillOpen(topicid)` | 某个笔记本即将打开;之后该窗口才会有 `studyController` 对应的学习界面。 |
|
|
24
|
+
| `notebookWillClose(topicid)` | 某个笔记本即将关闭。 |
|
|
25
|
+
|
|
26
|
+
### 文档
|
|
27
|
+
|
|
28
|
+
| 方法 | 调用时机 |
|
|
29
|
+
|------|----------|
|
|
30
|
+
| `documentDidOpen(docmd5)` | 某文档已打开。 |
|
|
31
|
+
| `documentWillClose(docmd5)` | 某文档即将关闭。 |
|
|
32
|
+
|
|
33
|
+
## 何时可使用 studyController
|
|
34
|
+
|
|
35
|
+
- `studyController(window)` 返回的是**当前窗口**的学习控制器;只有在该窗口已经打开过笔记本、学习界面已就绪时,返回值才可用。
|
|
36
|
+
- 在 `sceneWillConnect` 中通常**还没有**打开笔记本,因此一般不要在这里依赖 `studyController(self.window)` 去访问脑图或文档。
|
|
37
|
+
- 在 `notebookWillOpen(topicid)` 被调用后,该窗口即将或已经拥有学习界面;但若需在「打开笔记本」后立刻挂载 UI,建议用 `NSTimer.scheduledTimerWithTimeInterval(0.2, false, function () { ... })` 延迟约 0.2 秒再执行,以确保 studyController 与 view 已就绪。
|
|
38
|
+
|
|
39
|
+
## 示例:在笔记本打开时打日志并延迟挂载 UI
|
|
40
|
+
|
|
41
|
+
下面在 `notebookWillOpen` 中打日志,并在 0.2 秒后检查是否要显示之前保存的浮窗(用 NSUserDefaults 记住状态):
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
notebookWillOpen: function (topicid) {
|
|
45
|
+
JSB.log("MNLOG Open Notebook: %@", topicid);
|
|
46
|
+
|
|
47
|
+
NSTimer.scheduledTimerWithTimeInterval(0.2, false, function () {
|
|
48
|
+
var showPanel = NSUserDefaults.standardUserDefaults().objectForKey("my_addon_show_panel");
|
|
49
|
+
if (showPanel === true) {
|
|
50
|
+
var studyController = Application.sharedInstance().studyController(self.window);
|
|
51
|
+
if (studyController) {
|
|
52
|
+
studyController.view.addSubview(self.myPanelView);
|
|
53
|
+
self.layoutMyPanel();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## 布局回调:controllerWillLayoutSubviews
|
|
61
|
+
|
|
62
|
+
若你在学习界面上添加了自定义视图,窗口尺寸或布局变化时可能需要重新计算位置。实现 `controllerWillLayoutSubviews(controller)`,当传入的 controller 是当前窗口的 studyController 时,在其中更新你的面板 frame(例如根据 `controller.view.bounds` 计算)。
|
|
63
|
+
|
|
64
|
+
```javascript
|
|
65
|
+
controllerWillLayoutSubviews: function (controller) {
|
|
66
|
+
if (controller === Application.sharedInstance().studyController(self.window)) {
|
|
67
|
+
self.layoutMyPanel();
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## 相关
|
|
73
|
+
|
|
74
|
+
- [JSExtension](/reference/marginnote/jsextension/) — 完整生命周期与可选方法
|
|
75
|
+
- [StudyController](/reference/marginnote/study-controller/) — 通过 studyController 访问脑图与文档
|
|
76
|
+
- [快速开始](/guides/getting-started/)
|