Skip to content

Commit

Permalink
Doc: Updated doc and tests for plugin postMessage() update
Browse files Browse the repository at this point in the history
  • Loading branch information
laurent22 committed Jan 11, 2021
1 parent 2489409 commit 79dde36
Show file tree
Hide file tree
Showing 184 changed files with 9,887 additions and 1,155 deletions.
3 changes: 2 additions & 1 deletion Assets/PluginDocTheme/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ module.exports = {

return `joplin.${camelCaseToDots(p)
.replace(/menu\.items/, 'menuItems')
.replace(/toolbar\.buttons/, 'toolbarButtons')}`;
.replace(/toolbar\.buttons/, 'toolbarButtons')
.replace(/content\.scripts/, 'contentScripts')}`;
},

jpIsAllowedGroup: function(name) {
Expand Down
2 changes: 1 addition & 1 deletion docs/api/references/plugin_api/assets/js/search.json

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions docs/api/references/plugin_api/classes/joplin.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ <h2>Index</h2>
<h3>Accessors</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="joplin.html#commands" class="tsd-kind-icon">commands</a></li>
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="joplin.html#contentscripts" class="tsd-kind-icon">content<wbr>Scripts</a></li>
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="joplin.html#data" class="tsd-kind-icon">data</a></li>
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="joplin.html#interop" class="tsd-kind-icon">interop</a></li>
<li class="tsd-kind-get-signature tsd-parent-kind-class"><a href="joplin.html#plugins" class="tsd-kind-icon">plugins</a></li>
Expand Down Expand Up @@ -131,6 +132,24 @@ <h3>commands</h3>
<h4 class="tsd-returns-title">Returns <a href="joplincommands.html" class="tsd-signature-type">joplin.commands</a></h4>
-->
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-get-signature tsd-parent-kind-class">
<a name="contentscripts" class="tsd-anchor"></a>
<h3>content<wbr>Scripts</h3>
<ul class="tsd-signatures tsd-kind-get-signature tsd-parent-kind-class">
<li class="tsd-signature tsd-kind-icon"><span class="tsd-signature-symbol">get</span> contentScripts<span class="tsd-signature-symbol">(</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="joplincontentscripts.html" class="tsd-signature-type">joplin.contentScripts</a></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<aside class="tsd-sources">
</aside>
<!-- JOPLINCHANGE
<h4 class="tsd-returns-title">Returns <a href="joplincontentscripts.html" class="tsd-signature-type">joplin.contentScripts</a></h4>
-->
</li>
</ul>
Expand Down Expand Up @@ -268,6 +287,9 @@ <h4 class="tsd-returns-title">Returns <a href="joplinworkspace.html" class="tsd-
<li class=" tsd-kind-get-signature tsd-parent-kind-class">
<a href="joplin.html#commands" class="tsd-kind-icon">commands</a>
</li>
<li class=" tsd-kind-get-signature tsd-parent-kind-class">
<a href="joplin.html#contentscripts" class="tsd-kind-icon">content<wbr>Scripts</a>
</li>
<li class=" tsd-kind-get-signature tsd-parent-kind-class">
<a href="joplin.html#data" class="tsd-kind-icon">data</a>
</li>
Expand Down
256 changes: 256 additions & 0 deletions docs/api/references/plugin_api/classes/joplincontentscripts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
<!doctype html>
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>joplin.contentScripts | Joplin Plugin API Documentation</title>
<meta name="description" content="Documentation for Joplin Plugin API Documentation">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="../assets/css/main.css">
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="../assets/js/search.json" data-base="..">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="joplin.html" class="title">Joplin Plugin API Documentation</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<ul class="tsd-breadcrumb">
<!--
<li>
<a href="../globals.html">Globals</a>
</li>
-->
<li>
<a href="joplincontentscripts.html">joplin.contentScripts</a>
</li>
</ul>
<h1><!-- Class -->joplin.contentScripts</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<!--
<section class="tsd-panel tsd-hierarchy">
<h3>Hierarchy</h3>
<ul class="tsd-hierarchy">
<li>
<span class="target">JoplinContentScripts</span>
</li>
</ul>
</section>
-->
<section class="tsd-panel-group tsd-index-group">
<h2>Index</h2>
<section class="tsd-panel tsd-index-panel">
<div class="tsd-index-content">
<section class="tsd-index-section ">
</section>
<section class="tsd-index-section ">
<h3>Methods</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-method tsd-parent-kind-class"><a href="joplincontentscripts.html#onmessage" class="tsd-kind-icon">on<wbr>Message</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="joplincontentscripts.html#register" class="tsd-kind-icon">register</a></li>
</ul>
</section>
</div>
</section>
</section>
<section class="tsd-panel-group tsd-member-group ">
</section>
<section class="tsd-panel-group tsd-member-group ">
<h2>Methods</h2>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
<a name="onmessage" class="tsd-anchor"></a>
<h3>on<wbr>Message</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class">
<li class="tsd-signature tsd-kind-icon">on<wbr>Message<span class="tsd-signature-symbol">(</span>contentScriptId<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, callback<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<aside class="tsd-sources">
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Listens to a messages sent from the content script using postMessage().
See <a href="../enums/contentscripttype.html">ContentScriptType</a> for more information as well as the
<a href="https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages">postMessage
demo</a></p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>contentScriptId: <span class="tsd-signature-type">string</span></h5>
</li>
<li>
<h5>callback: <span class="tsd-signature-type">any</span></h5>
</li>
</ul>
<!-- JOPLINCHANGE
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></h4>
-->
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
<a name="register" class="tsd-anchor"></a>
<h3>register</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class">
<li class="tsd-signature tsd-kind-icon">register<span class="tsd-signature-symbol">(</span>type<span class="tsd-signature-symbol">: </span><a href="../enums/contentscripttype.html" class="tsd-signature-type">ContentScriptType</a>, id<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, scriptPath<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<aside class="tsd-sources">
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Registers a new content script. Unlike regular plugin code, which runs in
a separate process, content scripts run within the main process code and
thus allow improved performances and more customisations in specific
cases. It can be used for example to load a Markdown or editor plugin.</p>
</div>
<p>Note that registering a content script in itself will do nothing - it
will only be loaded in specific cases by the relevant app modules (eg.
the Markdown renderer or the code editor). So it is not a way to inject
and run arbitrary code in the app, which for safety and performance
reasons is not supported.</p>
<p>The plugin generator provides a way to build any content script you might
want to package as well as its dependencies. See the <a href="https://github.com/laurent22/joplin/blob/dev/packages/generator-joplin/README.md">Plugin Generator
doc</a>
for more information.</p>
<ul>
<li><a href="https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script">View the renderer demo plugin</a></li>
<li><a href="https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script">View the editor demo plugin</a></li>
</ul>
<p>See also the <a href="https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages">postMessage demo</a></p>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>type: <a href="../enums/contentscripttype.html" class="tsd-signature-type">ContentScriptType</a></h5>
<div class="tsd-comment tsd-typography">
<p>Defines how the script will be used. See the type definition for more information about each supported type.</p>
</div>
</li>
<li>
<h5>id: <span class="tsd-signature-type">string</span></h5>
<div class="tsd-comment tsd-typography">
<p>A unique ID for the content script.</p>
</div>
</li>
<li>
<h5>scriptPath: <span class="tsd-signature-type">string</span></h5>
<div class="tsd-comment tsd-typography">
<p>Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set <code>scriptPath</code> to <code>&quot;./content_script.js</code>.</p>
</div>
</li>
</ul>
<!-- JOPLINCHANGE
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">Promise</span><span class="tsd-signature-symbol">&lt;</span><span class="tsd-signature-type">void</span><span class="tsd-signature-symbol">&gt;</span></h4>
-->
</li>
</ul>
</section>
</section>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<!--
<nav class="tsd-navigation primary">
<ul>
<li class="globals ">
<a href="../globals.html"><em>Globals</em></a>
</li>
</ul>
</nav>
-->
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
</ul>
<ul class="current">
<li class="current tsd-kind-class">
<a href="joplincontentscripts.html" class="tsd-kind-icon">joplin.contentScripts</a>
<ul>
<li class=" tsd-kind-constructor tsd-parent-kind-class">
<a href="joplincontentscripts.html#constructor" class="tsd-kind-icon">constructor</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="joplincontentscripts.html#onmessage" class="tsd-kind-icon">on<wbr>Message</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="joplincontentscripts.html#register" class="tsd-kind-icon">register</a>
</li>
</ul>
</li>
</ul>
<ul class="after-current">
</ul>
</nav>
</div>
</div>
</div>
<!-- JOPLINCHANGE
<footer class="with-border-bottom">
<div class="container">
<h2>Legend</h2>
<div class="tsd-legend-group">
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li>
</ul>
</div>
</div>
</footer>
<div class="container tsd-generator">
<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p>
</div>
-->
<div class="overlay"></div>
<script src="../assets/js/main.js"></script>
</body>
</html>
33 changes: 5 additions & 28 deletions docs/api/references/plugin_api/classes/joplinplugins.html
Original file line number Diff line number Diff line change
Expand Up @@ -149,45 +149,22 @@ <h3>register<wbr>Content<wbr>Script</h3>
<aside class="tsd-sources">
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Registers a new content script. Unlike regular plugin code, which runs in
a separate process, content scripts run within the main process code and
thus allow improved performances and more customisations in specific
cases. It can be used for example to load a Markdown or editor plugin.</p>
</div>
<p>Note that registering a content script in itself will do nothing - it
will only be loaded in specific cases by the relevant app modules (eg.
the Markdown renderer or the code editor). So it is not a way to inject
and run arbitrary code in the app, which for safety and performance
reasons is not supported.</p>
<p>The plugin generator provides a way to build any content script you might
want to package as well as its dependencies. See the <a href="https://github.com/laurent22/joplin/blob/dev/packages/generator-joplin/README.md">Plugin Generator
doc</a>
for more information.</p>
<ul>
<li><a href="https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/content_script">View the renderer demo plugin</a></li>
<li><a href="https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/codemirror_content_script">View the editor demo plugin</a></li>
</ul>
<dl class="tsd-comment-tags">
<dt>deprecated</dt>
<dd><p>Use joplin.contentScripts.register()</p>
</dd>
</dl>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>type: <a href="../enums/contentscripttype.html" class="tsd-signature-type">ContentScriptType</a></h5>
<div class="tsd-comment tsd-typography">
<p>Defines how the script will be used. See the type definition for more information about each supported type.</p>
</div>
</li>
<li>
<h5>id: <span class="tsd-signature-type">string</span></h5>
<div class="tsd-comment tsd-typography">
<p>A unique ID for the content script.</p>
</div>
</li>
<li>
<h5>scriptPath: <span class="tsd-signature-type">string</span></h5>
<div class="tsd-comment tsd-typography">
<p>Must be a path relative to the plugin main script. For example, if your file content_script.js is next to your index.ts file, you would set <code>scriptPath</code> to <code>&quot;./content_script.js</code>.</p>
</div>
</li>
</ul>
<!-- JOPLINCHANGE
Expand Down
10 changes: 10 additions & 0 deletions docs/api/references/plugin_api/classes/joplinviewspanels.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,16 @@ <h3>on<wbr>Message</h3>
<div class="lead">
<p>Called when a message is sent from the webview (using postMessage).</p>
</div>
<p>To post a message from the webview to the plugin use:</p>
<pre><code class="language-javascript"><span class="hljs-keyword">const</span> response = <span class="hljs-keyword">await</span> webviewApi.postMessage(message);</code></pre>
<ul>
<li><code>message</code> can be any JavaScript object, string or number</li>
<li><code>response</code> is whatever was returned by the <code>onMessage</code> handler</li>
</ul>
<p>Using this mechanism, you can have two-way communication between the
plugin and webview.</p>
<p>See the <a href="https://github.com/laurent22/joplin/tree/dev/packages/app-cli/tests/support/plugins/post_messages">postMessage
demo</a> for more details.</p>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
Expand Down
Loading

0 comments on commit 79dde36

Please sign in to comment.