@noteplanco/noteplan-mcp 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +257 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/noteplan/embeddings.d.ts +170 -0
- package/dist/noteplan/embeddings.d.ts.map +1 -0
- package/dist/noteplan/embeddings.js +684 -0
- package/dist/noteplan/embeddings.js.map +1 -0
- package/dist/noteplan/file-reader.d.ts +77 -0
- package/dist/noteplan/file-reader.d.ts.map +1 -0
- package/dist/noteplan/file-reader.js +488 -0
- package/dist/noteplan/file-reader.js.map +1 -0
- package/dist/noteplan/file-writer.d.ts +108 -0
- package/dist/noteplan/file-writer.d.ts.map +1 -0
- package/dist/noteplan/file-writer.js +621 -0
- package/dist/noteplan/file-writer.js.map +1 -0
- package/dist/noteplan/filter-store.d.ts +28 -0
- package/dist/noteplan/filter-store.d.ts.map +1 -0
- package/dist/noteplan/filter-store.js +180 -0
- package/dist/noteplan/filter-store.js.map +1 -0
- package/dist/noteplan/frontmatter-parser.d.ts +45 -0
- package/dist/noteplan/frontmatter-parser.d.ts.map +1 -0
- package/dist/noteplan/frontmatter-parser.js +259 -0
- package/dist/noteplan/frontmatter-parser.js.map +1 -0
- package/dist/noteplan/fuzzy-search.d.ts +7 -0
- package/dist/noteplan/fuzzy-search.d.ts.map +1 -0
- package/dist/noteplan/fuzzy-search.js +66 -0
- package/dist/noteplan/fuzzy-search.js.map +1 -0
- package/dist/noteplan/markdown-parser.d.ts +87 -0
- package/dist/noteplan/markdown-parser.d.ts.map +1 -0
- package/dist/noteplan/markdown-parser.js +519 -0
- package/dist/noteplan/markdown-parser.js.map +1 -0
- package/dist/noteplan/preferences.d.ts +44 -0
- package/dist/noteplan/preferences.d.ts.map +1 -0
- package/dist/noteplan/preferences.js +156 -0
- package/dist/noteplan/preferences.js.map +1 -0
- package/dist/noteplan/ripgrep-search.d.ts +29 -0
- package/dist/noteplan/ripgrep-search.d.ts.map +1 -0
- package/dist/noteplan/ripgrep-search.js +110 -0
- package/dist/noteplan/ripgrep-search.js.map +1 -0
- package/dist/noteplan/sqlite-reader.d.ts +77 -0
- package/dist/noteplan/sqlite-reader.d.ts.map +1 -0
- package/dist/noteplan/sqlite-reader.js +605 -0
- package/dist/noteplan/sqlite-reader.js.map +1 -0
- package/dist/noteplan/sqlite-writer.d.ts +63 -0
- package/dist/noteplan/sqlite-writer.d.ts.map +1 -0
- package/dist/noteplan/sqlite-writer.js +574 -0
- package/dist/noteplan/sqlite-writer.js.map +1 -0
- package/dist/noteplan/types.d.ts +97 -0
- package/dist/noteplan/types.d.ts.map +1 -0
- package/dist/noteplan/types.js +33 -0
- package/dist/noteplan/types.js.map +1 -0
- package/dist/noteplan/unified-store.d.ts +289 -0
- package/dist/noteplan/unified-store.d.ts.map +1 -0
- package/dist/noteplan/unified-store.js +1308 -0
- package/dist/noteplan/unified-store.js.map +1 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +2468 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/calendar.d.ts +311 -0
- package/dist/tools/calendar.d.ts.map +1 -0
- package/dist/tools/calendar.js +504 -0
- package/dist/tools/calendar.js.map +1 -0
- package/dist/tools/embeddings.d.ts +244 -0
- package/dist/tools/embeddings.d.ts.map +1 -0
- package/dist/tools/embeddings.js +226 -0
- package/dist/tools/embeddings.js.map +1 -0
- package/dist/tools/events.d.ts +176 -0
- package/dist/tools/events.d.ts.map +1 -0
- package/dist/tools/events.js +326 -0
- package/dist/tools/events.js.map +1 -0
- package/dist/tools/filters.d.ts +205 -0
- package/dist/tools/filters.d.ts.map +1 -0
- package/dist/tools/filters.js +347 -0
- package/dist/tools/filters.js.map +1 -0
- package/dist/tools/memory.d.ts +6 -0
- package/dist/tools/memory.d.ts.map +1 -0
- package/dist/tools/memory.js +161 -0
- package/dist/tools/memory.js.map +1 -0
- package/dist/tools/notes.d.ts +1221 -0
- package/dist/tools/notes.d.ts.map +1 -0
- package/dist/tools/notes.js +1868 -0
- package/dist/tools/notes.js.map +1 -0
- package/dist/tools/plugins.d.ts +140 -0
- package/dist/tools/plugins.d.ts.map +1 -0
- package/dist/tools/plugins.js +782 -0
- package/dist/tools/plugins.js.map +1 -0
- package/dist/tools/reminders.d.ts +207 -0
- package/dist/tools/reminders.d.ts.map +1 -0
- package/dist/tools/reminders.js +323 -0
- package/dist/tools/reminders.js.map +1 -0
- package/dist/tools/search.d.ts +58 -0
- package/dist/tools/search.d.ts.map +1 -0
- package/dist/tools/search.js +373 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/spaces.d.ts +484 -0
- package/dist/tools/spaces.d.ts.map +1 -0
- package/dist/tools/spaces.js +870 -0
- package/dist/tools/spaces.js.map +1 -0
- package/dist/tools/tasks.d.ts +313 -0
- package/dist/tools/tasks.d.ts.map +1 -0
- package/dist/tools/tasks.js +690 -0
- package/dist/tools/tasks.js.map +1 -0
- package/dist/tools/themes.d.ts +91 -0
- package/dist/tools/themes.d.ts.map +1 -0
- package/dist/tools/themes.js +294 -0
- package/dist/tools/themes.js.map +1 -0
- package/dist/tools/ui.d.ts +89 -0
- package/dist/tools/ui.d.ts.map +1 -0
- package/dist/tools/ui.js +137 -0
- package/dist/tools/ui.js.map +1 -0
- package/dist/utils/applescript.d.ts +5 -0
- package/dist/utils/applescript.d.ts.map +1 -0
- package/dist/utils/applescript.js +27 -0
- package/dist/utils/applescript.js.map +1 -0
- package/dist/utils/confirmation-tokens.d.ts +19 -0
- package/dist/utils/confirmation-tokens.d.ts.map +1 -0
- package/dist/utils/confirmation-tokens.js +58 -0
- package/dist/utils/confirmation-tokens.js.map +1 -0
- package/dist/utils/date-filters.d.ts +15 -0
- package/dist/utils/date-filters.d.ts.map +1 -0
- package/dist/utils/date-filters.js +129 -0
- package/dist/utils/date-filters.js.map +1 -0
- package/dist/utils/date-utils.d.ts +113 -0
- package/dist/utils/date-utils.d.ts.map +1 -0
- package/dist/utils/date-utils.js +341 -0
- package/dist/utils/date-utils.js.map +1 -0
- package/dist/utils/folder-matcher.d.ts +14 -0
- package/dist/utils/folder-matcher.d.ts.map +1 -0
- package/dist/utils/folder-matcher.js +191 -0
- package/dist/utils/folder-matcher.js.map +1 -0
- package/dist/utils/version.d.ts +10 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +88 -0
- package/dist/utils/version.js.map +1 -0
- package/docs/plugin-api/Calendar.md +448 -0
- package/docs/plugin-api/CalendarItem.md +198 -0
- package/docs/plugin-api/Clipboard.md +101 -0
- package/docs/plugin-api/CommandBar.md +251 -0
- package/docs/plugin-api/DataStore.md +700 -0
- package/docs/plugin-api/Editor.md +982 -0
- package/docs/plugin-api/HTMLView.md +337 -0
- package/docs/plugin-api/NoteObject.md +588 -0
- package/docs/plugin-api/NotePlan.md +398 -0
- package/docs/plugin-api/ParagraphObject.md +242 -0
- package/docs/plugin-api/RangeObject.md +56 -0
- package/docs/plugin-api/getting-started.md +545 -0
- package/docs/plugin-api/plugin-api-condensed.md +526 -0
- package/docs/plugin-api/plugin.json +26 -0
- package/docs/plugin-api/script.js +542 -0
- package/package.json +60 -0
- package/scripts/calendar-helper +0 -0
- package/scripts/reminders-helper +0 -0
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
# Getting Started with NotePlan Plugins
|
|
2
|
+
|
|
3
|
+
This guide will help you create your first NotePlan plugin, whether you're a developer or using AI assistants like Claude Code or Cursor.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
|
|
7
|
+
1. [What are NotePlan Plugins?](#what-are-noteplan-plugins)
|
|
8
|
+
2. [Plugin Structure](#plugin-structure)
|
|
9
|
+
3. [Installation & Setup](#installation--setup)
|
|
10
|
+
4. [Creating Your First Plugin](#creating-your-first-plugin)
|
|
11
|
+
5. [Using AI Assistants (Claude Code / Cursor)](#using-ai-assistants-claude-code--cursor)
|
|
12
|
+
6. [Testing Your Plugin](#testing-your-plugin)
|
|
13
|
+
7. [HTML Plugins (Persistent Views)](#html-plugins-persistent-views)
|
|
14
|
+
8. [API Documentation](#api-documentation)
|
|
15
|
+
9. [Next Steps](#next-steps)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## What are NotePlan Plugins?
|
|
20
|
+
|
|
21
|
+
NotePlan plugins extend the functionality of NotePlan by adding custom commands and views. They are written in JavaScript and can:
|
|
22
|
+
|
|
23
|
+
- Manipulate notes and paragraphs using the Editor API
|
|
24
|
+
- Access calendar events and reminders using the Calendar API
|
|
25
|
+
- Create HTML-based user interfaces
|
|
26
|
+
- Integrate with NotePlan's core functionality
|
|
27
|
+
|
|
28
|
+
### Types of Plugins
|
|
29
|
+
|
|
30
|
+
1. **Command-based Plugins**: Functions that run when called from NotePlan's command palette
|
|
31
|
+
2. **HTML Plugins**: Persistent views that appear in the main window, perfect for dashboards and widgets
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Plugin Structure
|
|
36
|
+
|
|
37
|
+
A NotePlan plugin consists of two essential files:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
np.myplugin/
|
|
41
|
+
├── plugin.json # Plugin configuration and metadata
|
|
42
|
+
└── script.js # JavaScript code with plugin functions
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### plugin.json
|
|
46
|
+
|
|
47
|
+
The configuration file that defines:
|
|
48
|
+
|
|
49
|
+
- Plugin metadata (name, version, author, description)
|
|
50
|
+
- Minimum NotePlan version requirements
|
|
51
|
+
- Available commands and their JavaScript function mappings
|
|
52
|
+
|
|
53
|
+
### script.js
|
|
54
|
+
|
|
55
|
+
The main plugin script containing:
|
|
56
|
+
|
|
57
|
+
- JavaScript functions that become NotePlan commands
|
|
58
|
+
- Each function in `plugin.json` maps to a function in `script.js` via `"jsFunction"`
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Installation & Setup
|
|
63
|
+
|
|
64
|
+
### Step 1: Find Your Plugin Folder
|
|
65
|
+
|
|
66
|
+
1. Open **NotePlan Settings**
|
|
67
|
+
2. Click the **"Open plugin folder"** button
|
|
68
|
+
3. This opens the `Plugins` directory in your NotePlan sync folder
|
|
69
|
+
|
|
70
|
+
### Step 2: Create Your Plugin Folder
|
|
71
|
+
|
|
72
|
+
1. In the `Plugins` directory, create a new folder for your plugin
|
|
73
|
+
2. Use a descriptive name starting with `np.` (e.g., `np.myplugin`, `np.calendar-widget`)
|
|
74
|
+
3. This folder will contain your `plugin.json` and `script.js` files
|
|
75
|
+
|
|
76
|
+
### Step 3: Copy the Boilerplate
|
|
77
|
+
|
|
78
|
+
1. Copy `plugin.json` and `script.js` from this API Docs folder
|
|
79
|
+
2. Paste them into your new plugin folder
|
|
80
|
+
3. Rename and customize as needed
|
|
81
|
+
|
|
82
|
+
**Example structure:**
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
NotePlan Sync Folder/
|
|
86
|
+
Plugins/
|
|
87
|
+
np.myplugin/
|
|
88
|
+
├── plugin.json
|
|
89
|
+
└── script.js
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
---
|
|
93
|
+
|
|
94
|
+
## Creating Your First Plugin
|
|
95
|
+
|
|
96
|
+
### Step 1: Update plugin.json
|
|
97
|
+
|
|
98
|
+
Edit `plugin.json` with your plugin details:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"plugin.id": "np.myplugin",
|
|
103
|
+
"plugin.name": "My Plugin",
|
|
104
|
+
"plugin.description": "What my plugin does",
|
|
105
|
+
"plugin.author": "@yourusername",
|
|
106
|
+
"plugin.version": "1.0.0",
|
|
107
|
+
"plugin.commands": [
|
|
108
|
+
{
|
|
109
|
+
"name": "myCommand",
|
|
110
|
+
"description": "What this command does",
|
|
111
|
+
"jsFunction": "myCommand"
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**Important fields:**
|
|
118
|
+
|
|
119
|
+
- `plugin.id`: Unique identifier (must start with `np.`)
|
|
120
|
+
- `plugin.name`: Display name in NotePlan
|
|
121
|
+
- `plugin.commands`: Array of commands your plugin provides
|
|
122
|
+
- `name`: Command name shown in NotePlan
|
|
123
|
+
- `jsFunction`: Function name in `script.js` that runs when command is executed
|
|
124
|
+
|
|
125
|
+
### Step 2: Write Your Function
|
|
126
|
+
|
|
127
|
+
In `script.js`, create a function matching the `jsFunction` name:
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
async function myCommand() {
|
|
131
|
+
try {
|
|
132
|
+
// Check if API is available
|
|
133
|
+
if (typeof Editor === "undefined") {
|
|
134
|
+
console.log("❌ Editor API not available")
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// Your plugin logic here
|
|
139
|
+
const filename = Editor.filename
|
|
140
|
+
console.log(`Current note: ${filename}`)
|
|
141
|
+
|
|
142
|
+
console.log("✅ Command executed successfully")
|
|
143
|
+
} catch (error) {
|
|
144
|
+
console.log(`❌ Error: ${error.message}`)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Step 3: Test Your Plugin
|
|
150
|
+
|
|
151
|
+
1. Save your files
|
|
152
|
+
2. In NotePlan, open the command palette (⌘⇧P or Cmd+Shift+P)
|
|
153
|
+
3. Type your command name
|
|
154
|
+
4. Run it and check the console for output
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Using AI Assistants (Claude Code / Cursor)
|
|
159
|
+
|
|
160
|
+
AI assistants can help you build NotePlan plugins more efficiently. Here's how to get the best results:
|
|
161
|
+
|
|
162
|
+
### For Claude Code / Cursor
|
|
163
|
+
|
|
164
|
+
1. **Open the API Docs folder** in your workspace
|
|
165
|
+
|
|
166
|
+
- The AI can reference the `.md` files for API documentation
|
|
167
|
+
- Files like `Calendar.md`, `Editor.md`, `HTMLView.md` contain complete API references
|
|
168
|
+
|
|
169
|
+
2. **Provide context about your plugin**
|
|
170
|
+
|
|
171
|
+
- Tell the AI what you want to build
|
|
172
|
+
- Mention if it's a command-based plugin or HTML plugin
|
|
173
|
+
- Specify which APIs you need (Editor, Calendar, HTMLView, etc.)
|
|
174
|
+
|
|
175
|
+
3. **Reference the boilerplate**
|
|
176
|
+
|
|
177
|
+
- Point the AI to `script.js` and `plugin.json` for structure
|
|
178
|
+
- The boilerplate includes examples for common use cases
|
|
179
|
+
|
|
180
|
+
4. **Ask for specific functionality**
|
|
181
|
+
- "Create a command that lists all headings in the current note"
|
|
182
|
+
- "Build an HTML view that shows today's calendar events"
|
|
183
|
+
- "Add a function that creates a new note with a template"
|
|
184
|
+
|
|
185
|
+
### Example AI Prompts
|
|
186
|
+
|
|
187
|
+
**For a command plugin:**
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
I want to create a NotePlan plugin command that:
|
|
191
|
+
- Gets all headings from the current note
|
|
192
|
+
- Creates a table of contents at the cursor position
|
|
193
|
+
- Uses the Editor API
|
|
194
|
+
|
|
195
|
+
Use the boilerplate in script.js as a reference.
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**For an HTML plugin:**
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
Create an HTML plugin that:
|
|
202
|
+
- Shows today's calendar events in a nice UI
|
|
203
|
+
- Uses the Calendar API (only API available in HTML views)
|
|
204
|
+
- Has a reload button for testing
|
|
205
|
+
- Follows the HTML plugin example in script.js
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Important Notes for AI Assistants
|
|
209
|
+
|
|
210
|
+
- **API Availability**: HTML views can directly use the Calendar API. Other APIs (Editor, NotePlan) must be accessed via the JavaScript bridge (`window.webkit.messageHandlers.jsBridge.postMessage()`)
|
|
211
|
+
- **Bridge Pattern**: When coding HTML views that need Editor/NotePlan APIs, use the bridge pattern shown in the examples above
|
|
212
|
+
- **Plugin Location**: Plugins must be in the NotePlan sync folder's `Plugins` directory
|
|
213
|
+
- **Testing**: Use the reload button in HTML views or re-run commands to test changes
|
|
214
|
+
- **Documentation**: All API docs are in `.md` files in the same directory as the boilerplate
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## Testing Your Plugin
|
|
219
|
+
|
|
220
|
+
### Testing Native Plugin Functions
|
|
221
|
+
|
|
222
|
+
1. Edit `script.js` in your plugin folder
|
|
223
|
+
2. Save the file
|
|
224
|
+
3. In NotePlan, run the command again
|
|
225
|
+
4. NotePlan automatically reloads the plugin script when commands are executed
|
|
226
|
+
5. Check the console (View → Show Console) for `console.log()` output
|
|
227
|
+
|
|
228
|
+
### Testing HTML Views
|
|
229
|
+
|
|
230
|
+
1. Edit `script.js` to update the HTML content
|
|
231
|
+
2. Save the file
|
|
232
|
+
3. **Option 1**: Click the reload button in the HTML view's navigation bar (if `showReloadButton: true`)
|
|
233
|
+
4. **Option 2**: Run the command again to reload the view
|
|
234
|
+
5. Changes appear immediately without restarting NotePlan
|
|
235
|
+
|
|
236
|
+
### Debugging Tips
|
|
237
|
+
|
|
238
|
+
- Use `console.log()` for debugging (visible in NotePlan's console)
|
|
239
|
+
- Check API availability before using: `if (typeof Editor === "undefined")`
|
|
240
|
+
- Wrap code in try/catch blocks to handle errors gracefully
|
|
241
|
+
- Test with different note types (daily notes, regular notes, etc.)
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## HTML Plugins (Persistent Views)
|
|
246
|
+
|
|
247
|
+
HTML plugins create persistent views that appear in NotePlan's main window. They're perfect for dashboards, widgets, and calendar-based UIs.
|
|
248
|
+
|
|
249
|
+
### Key Characteristics
|
|
250
|
+
|
|
251
|
+
1. **Main View Integration**: Loaded into the main view using `HTMLView.showInMainWindow()`
|
|
252
|
+
2. **Persistent Access**: Users can access them without running commands every time
|
|
253
|
+
3. **Session Persistence**: Views persist across NotePlan sessions (when using `customId`)
|
|
254
|
+
|
|
255
|
+
### API Availability in HTML Views
|
|
256
|
+
|
|
257
|
+
⚠️ **IMPORTANT**: HTML views can ONLY directly access the Calendar API.
|
|
258
|
+
|
|
259
|
+
- ✅ **Calendar API**: Available directly (Calendar.availableCalendars, Calendar.eventsToday, etc.)
|
|
260
|
+
- ❌ **Editor API**: NOT directly available
|
|
261
|
+
- ❌ **NotePlan API**: NOT directly available
|
|
262
|
+
- ❌ **Other APIs**: NOT directly available
|
|
263
|
+
|
|
264
|
+
### Accessing Other APIs from HTML Views (JavaScript Bridge)
|
|
265
|
+
|
|
266
|
+
While only the Calendar API is directly available in HTML views, you can access other NotePlan APIs (Editor, NotePlan, etc.) through the **JavaScript Bridge**. This allows HTML views to call back to NotePlan's JavaScript Core API.
|
|
267
|
+
|
|
268
|
+
#### How It Works
|
|
269
|
+
|
|
270
|
+
1. **In your plugin function**: Create the HTML with embedded JavaScript that uses `window.webkit.messageHandlers.jsBridge.postMessage()`
|
|
271
|
+
2. **Stringify the API call**: Wrap your NotePlan API call in a JSON stringified function
|
|
272
|
+
3. **Send via bridge**: Post the message with the code and a callback handler name
|
|
273
|
+
4. **Handle response**: Define a callback function in your HTML to process the result
|
|
274
|
+
|
|
275
|
+
#### Example: Opening a Note from HTML View
|
|
276
|
+
|
|
277
|
+
```javascript
|
|
278
|
+
async function showHTMLWithEditorAPI() {
|
|
279
|
+
// Stringify the NotePlan API call
|
|
280
|
+
const openNoteCode = JSON.stringify(`
|
|
281
|
+
(function() {
|
|
282
|
+
Editor.openNoteByFilename("10 - Projects/HTML View.md");
|
|
283
|
+
})()
|
|
284
|
+
`)
|
|
285
|
+
|
|
286
|
+
const html = `
|
|
287
|
+
<html>
|
|
288
|
+
<head>
|
|
289
|
+
<meta charset="utf-8">
|
|
290
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
291
|
+
<style>
|
|
292
|
+
body { font-family: -apple-system, sans-serif; padding: 20px; }
|
|
293
|
+
button { padding: 10px 20px; background: #007AFF; color: white; border: none; border-radius: 6px; cursor: pointer; }
|
|
294
|
+
</style>
|
|
295
|
+
</head>
|
|
296
|
+
<body>
|
|
297
|
+
<h1>HTML View with Editor API</h1>
|
|
298
|
+
<p id="result">Ready</p>
|
|
299
|
+
<button onclick="openNote()">Open Note</button>
|
|
300
|
+
|
|
301
|
+
<script>
|
|
302
|
+
// Function to call NotePlan API via bridge
|
|
303
|
+
function openNote() {
|
|
304
|
+
window.webkit.messageHandlers.jsBridge.postMessage({
|
|
305
|
+
code: ${openNoteCode},
|
|
306
|
+
onHandle: "onHandleOpenNote", // Callback function name
|
|
307
|
+
id: "1" // Optional: ID for tracking multiple calls
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
// Callback function to handle the response
|
|
312
|
+
function onHandleOpenNote(result, id) {
|
|
313
|
+
document.getElementById("result").innerHTML = "Note opened successfully!";
|
|
314
|
+
console.log("Result:", result);
|
|
315
|
+
console.log("Call ID:", id);
|
|
316
|
+
}
|
|
317
|
+
</script>
|
|
318
|
+
</body>
|
|
319
|
+
</html>
|
|
320
|
+
`
|
|
321
|
+
|
|
322
|
+
await HTMLView.showInMainWindow(html, "Editor API Example", {
|
|
323
|
+
icon: "file",
|
|
324
|
+
customId: "editor-api-example",
|
|
325
|
+
showReloadButton: true,
|
|
326
|
+
})
|
|
327
|
+
}
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
#### Key Points for AI Assistants
|
|
331
|
+
|
|
332
|
+
When coding HTML views that need to access non-Calendar APIs:
|
|
333
|
+
|
|
334
|
+
1. **Stringify the API call**: Wrap your NotePlan API code in `JSON.stringify()` with a function wrapper
|
|
335
|
+
2. **Use the bridge**: Call `window.webkit.messageHandlers.jsBridge.postMessage()` with:
|
|
336
|
+
- `code`: The stringified API call
|
|
337
|
+
- `onHandle`: Name of the callback function in your HTML
|
|
338
|
+
- `id`: Optional identifier for tracking
|
|
339
|
+
3. **Handle callbacks**: Define the callback function in your HTML's `<script>` tag
|
|
340
|
+
4. **Template literals**: Use template literals (backticks) for the HTML string to embed the stringified code
|
|
341
|
+
|
|
342
|
+
#### More Examples
|
|
343
|
+
|
|
344
|
+
**Getting current note filename:**
|
|
345
|
+
|
|
346
|
+
```javascript
|
|
347
|
+
const getFilenameCode = JSON.stringify(`
|
|
348
|
+
(function() {
|
|
349
|
+
return Editor.filename || Editor.resolvedFilename;
|
|
350
|
+
})()
|
|
351
|
+
`)
|
|
352
|
+
|
|
353
|
+
// In HTML:
|
|
354
|
+
window.webkit.messageHandlers.jsBridge.postMessage({
|
|
355
|
+
code: ${getFilenameCode},
|
|
356
|
+
onHandle: "onHandleFilename",
|
|
357
|
+
id: "2"
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
function onHandleFilename(filename, id) {
|
|
361
|
+
document.getElementById("result").textContent = \`Current note: \${filename}\`;
|
|
362
|
+
}
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
**Inserting text at cursor:**
|
|
366
|
+
|
|
367
|
+
```javascript
|
|
368
|
+
const insertTextCode = JSON.stringify(`
|
|
369
|
+
(function() {
|
|
370
|
+
Editor.insertTextAtCursor("Hello from HTML view!\\n");
|
|
371
|
+
return "Text inserted";
|
|
372
|
+
})()
|
|
373
|
+
`)
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Creating an HTML Plugin
|
|
377
|
+
|
|
378
|
+
```javascript
|
|
379
|
+
async function showMyHTMLView() {
|
|
380
|
+
const html = `
|
|
381
|
+
<html>
|
|
382
|
+
<head>
|
|
383
|
+
<style>
|
|
384
|
+
body { font-family: -apple-system, sans-serif; padding: 20px; }
|
|
385
|
+
</style>
|
|
386
|
+
</head>
|
|
387
|
+
<body>
|
|
388
|
+
<h1>My HTML View</h1>
|
|
389
|
+
<button onclick="testCalendar()">Test Calendar API</button>
|
|
390
|
+
<div id="result"></div>
|
|
391
|
+
<script>
|
|
392
|
+
async function testCalendar() {
|
|
393
|
+
const events = await Calendar.eventsToday('');
|
|
394
|
+
document.getElementById('result').textContent =
|
|
395
|
+
\`Found \${events.length} events today\`;
|
|
396
|
+
}
|
|
397
|
+
</script>
|
|
398
|
+
</body>
|
|
399
|
+
</html>
|
|
400
|
+
`
|
|
401
|
+
|
|
402
|
+
await HTMLView.showInMainWindow(html, "My View", {
|
|
403
|
+
icon: "star",
|
|
404
|
+
iconColor: "blue-500",
|
|
405
|
+
customId: "my-view",
|
|
406
|
+
showReloadButton: true, // Useful for testing
|
|
407
|
+
})
|
|
408
|
+
}
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### Communication Patterns
|
|
412
|
+
|
|
413
|
+
- **Calendar API**: Exposed directly in HTML views (no bridge needed)
|
|
414
|
+
- **Other APIs**: Must use the JavaScript bridge (`window.webkit.messageHandlers.jsBridge.postMessage()`)
|
|
415
|
+
- The bridge allows HTML views to execute NotePlan JavaScript Core API calls
|
|
416
|
+
- Responses are handled via callback functions defined in your HTML
|
|
417
|
+
|
|
418
|
+
### External API Access (fetch)
|
|
419
|
+
|
|
420
|
+
HTML WebViews include a native `fetch()` implementation backed by URLSession — **no CORS restrictions**. You can call external APIs (weather, stocks, REST endpoints) directly using the standard Fetch API:
|
|
421
|
+
|
|
422
|
+
```html
|
|
423
|
+
<script>
|
|
424
|
+
async function loadWeather() {
|
|
425
|
+
try {
|
|
426
|
+
const response = await fetch('https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41¤t_weather=true');
|
|
427
|
+
if (response.ok) {
|
|
428
|
+
const data = await response.json();
|
|
429
|
+
document.getElementById('weather').textContent = JSON.stringify(data.current_weather);
|
|
430
|
+
} else {
|
|
431
|
+
console.log('Fetch error: ' + response.status);
|
|
432
|
+
}
|
|
433
|
+
} catch(e) {
|
|
434
|
+
console.log('Fetch error: ' + e.message);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
</script>
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
**Key rules:**
|
|
441
|
+
- `fetch()` works just like the standard browser Fetch API (`response.json()`, `response.text()`, `response.ok`, `response.status`)
|
|
442
|
+
- Only **HTTPS** URLs work (HTTP is blocked by App Transport Security)
|
|
443
|
+
- Requests have a 30-second timeout
|
|
444
|
+
|
|
445
|
+
---
|
|
446
|
+
|
|
447
|
+
## API Documentation
|
|
448
|
+
|
|
449
|
+
All API documentation is available in `.md` files in this directory:
|
|
450
|
+
|
|
451
|
+
- **Calendar.md** - Calendar and Reminder APIs
|
|
452
|
+
- **CalendarItem.md** - CalendarItem object structure
|
|
453
|
+
- **Editor.md** - Editor APIs for note manipulation
|
|
454
|
+
- **HTMLView.md** - HTML view APIs for creating UI
|
|
455
|
+
- **NotePlan.md** - Core NotePlan APIs
|
|
456
|
+
- **NoteObject.md** - Note object structure
|
|
457
|
+
- **ParagraphObject.md** - Paragraph object structure
|
|
458
|
+
- **RangeObject.md** - Range object structure
|
|
459
|
+
- And more...
|
|
460
|
+
|
|
461
|
+
### Quick API Reference
|
|
462
|
+
|
|
463
|
+
**Editor API** (Native functions only):
|
|
464
|
+
|
|
465
|
+
```javascript
|
|
466
|
+
Editor.filename // Current note filename
|
|
467
|
+
Editor.paragraphs // Array of paragraph objects
|
|
468
|
+
Editor.insertTextAtCursor() // Insert text at cursor
|
|
469
|
+
Editor.replaceSelection() // Replace selected text
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
**Calendar API** (Available in both native and HTML views):
|
|
473
|
+
|
|
474
|
+
```javascript
|
|
475
|
+
Calendar.availableCalendars() // Get all calendars
|
|
476
|
+
Calendar.eventsToday(filter) // Get today's events
|
|
477
|
+
Calendar.eventsBetween(start, end, filter) // Get events in range
|
|
478
|
+
Calendar.add(calendarItem) // Create event/reminder
|
|
479
|
+
Calendar.update(calendarItem) // Update event/reminder
|
|
480
|
+
Calendar.remove(calendarItem) // Delete event/reminder
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
**HTMLView API** (Native functions only):
|
|
484
|
+
|
|
485
|
+
```javascript
|
|
486
|
+
HTMLView.showInMainWindow(html, title, options) // Show in main view
|
|
487
|
+
HTMLView.showWindow(html, title, width, height) // Show in window
|
|
488
|
+
HTMLView.showSheet(html, width, height) // Show as sheet
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
---
|
|
492
|
+
|
|
493
|
+
## Next Steps
|
|
494
|
+
|
|
495
|
+
1. **Explore the Examples**: Check `script.js` for working examples of:
|
|
496
|
+
|
|
497
|
+
- Basic command functions
|
|
498
|
+
- HTML view creation
|
|
499
|
+
- Calendar API usage
|
|
500
|
+
- Editor API usage
|
|
501
|
+
- Error handling patterns
|
|
502
|
+
|
|
503
|
+
2. **Read the API Docs**: Browse the `.md` files to understand available APIs
|
|
504
|
+
|
|
505
|
+
3. **Start Building**: Create your first plugin command or HTML view
|
|
506
|
+
|
|
507
|
+
4. **Test Iteratively**: Use the reload button or re-run commands to test changes quickly
|
|
508
|
+
|
|
509
|
+
5. **Share Your Plugin**: Once ready, consider sharing it with the NotePlan community
|
|
510
|
+
|
|
511
|
+
### Common Use Cases
|
|
512
|
+
|
|
513
|
+
- **Note Manipulation**: Templates, formatting, text processing
|
|
514
|
+
- **Calendar Integration**: Event creation, reminders, calendar views
|
|
515
|
+
- **Dashboards**: HTML views showing calendar data, statistics, widgets
|
|
516
|
+
- **Automation**: Batch operations, note organization, data extraction
|
|
517
|
+
|
|
518
|
+
---
|
|
519
|
+
|
|
520
|
+
## Troubleshooting
|
|
521
|
+
|
|
522
|
+
### Plugin Not Appearing
|
|
523
|
+
|
|
524
|
+
- Check that files are in the correct `Plugins` folder
|
|
525
|
+
- Verify `plugin.json` has valid JSON syntax
|
|
526
|
+
- Ensure `plugin.id` starts with `np.`
|
|
527
|
+
- Restart NotePlan if needed
|
|
528
|
+
|
|
529
|
+
### Command Not Working
|
|
530
|
+
|
|
531
|
+
- Check console for error messages
|
|
532
|
+
- Verify function name matches `jsFunction` in `plugin.json`
|
|
533
|
+
- Ensure API is available before using it
|
|
534
|
+
- Wrap code in try/catch to see errors
|
|
535
|
+
|
|
536
|
+
### HTML View Not Loading
|
|
537
|
+
|
|
538
|
+
- Verify Calendar API is available (only API in HTML views)
|
|
539
|
+
- Check browser console for JavaScript errors
|
|
540
|
+
- Ensure `waitForBridge()` is called before using Calendar API
|
|
541
|
+
- Use `showReloadButton: true` for easier testing
|
|
542
|
+
|
|
543
|
+
---
|
|
544
|
+
|
|
545
|
+
**Happy Plugin Development! 🚀**
|