@silverbulletmd/silverbullet 2.4.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.
Files changed (117) hide show
  1. package/LICENSE.md +18 -0
  2. package/README.md +98 -0
  3. package/client/asset_bundle/bundle.ts +95 -0
  4. package/client/data/datastore.ts +85 -0
  5. package/client/data/kv_primitives.ts +25 -0
  6. package/client/markdown_parser/constants.ts +13 -0
  7. package/client/plugos/event.ts +36 -0
  8. package/client/plugos/eventhook.ts +8 -0
  9. package/client/plugos/hooks/code_widget.ts +59 -0
  10. package/client/plugos/hooks/command.ts +104 -0
  11. package/client/plugos/hooks/document_editor.ts +77 -0
  12. package/client/plugos/hooks/event.ts +187 -0
  13. package/client/plugos/hooks/mq.ts +154 -0
  14. package/client/plugos/hooks/plug_namespace.ts +85 -0
  15. package/client/plugos/hooks/slash_command.ts +192 -0
  16. package/client/plugos/hooks/syscall.ts +66 -0
  17. package/client/plugos/manifest_cache.ts +67 -0
  18. package/client/plugos/plug.ts +99 -0
  19. package/client/plugos/plug_compile.ts +202 -0
  20. package/client/plugos/protocol.ts +40 -0
  21. package/client/plugos/proxy_fetch.ts +53 -0
  22. package/client/plugos/sandboxes/deno_worker_sandbox.ts +6 -0
  23. package/client/plugos/sandboxes/sandbox.ts +14 -0
  24. package/client/plugos/sandboxes/web_worker_sandbox.ts +17 -0
  25. package/client/plugos/sandboxes/worker_sandbox.ts +132 -0
  26. package/client/plugos/syscalls/asset.ts +35 -0
  27. package/client/plugos/syscalls/clientStore.ts +21 -0
  28. package/client/plugos/syscalls/client_code_widget.ts +12 -0
  29. package/client/plugos/syscalls/code_widget.ts +24 -0
  30. package/client/plugos/syscalls/config.ts +46 -0
  31. package/client/plugos/syscalls/datastore.ts +89 -0
  32. package/client/plugos/syscalls/editor.ts +673 -0
  33. package/client/plugos/syscalls/event.ts +36 -0
  34. package/client/plugos/syscalls/fetch.ts +128 -0
  35. package/client/plugos/syscalls/index.ts +102 -0
  36. package/client/plugos/syscalls/jsonschema.ts +69 -0
  37. package/client/plugos/syscalls/language.ts +23 -0
  38. package/client/plugos/syscalls/lua.ts +58 -0
  39. package/client/plugos/syscalls/markdown.ts +84 -0
  40. package/client/plugos/syscalls/mq.ts +52 -0
  41. package/client/plugos/syscalls/service_registry.ts +43 -0
  42. package/client/plugos/syscalls/shell.ts +39 -0
  43. package/client/plugos/syscalls/space.ts +139 -0
  44. package/client/plugos/syscalls/sync.ts +77 -0
  45. package/client/plugos/syscalls/system.ts +150 -0
  46. package/client/plugos/system.ts +201 -0
  47. package/client/plugos/types.ts +60 -0
  48. package/client/plugos/util.ts +14 -0
  49. package/client/plugos/worker_runtime.ts +195 -0
  50. package/client/space_lua/ast.ts +328 -0
  51. package/client/space_lua/ast_narrow.ts +81 -0
  52. package/client/space_lua/eval.ts +2478 -0
  53. package/client/space_lua/labels.ts +416 -0
  54. package/client/space_lua/numeric.ts +240 -0
  55. package/client/space_lua/parse.ts +1522 -0
  56. package/client/space_lua/query_collection.ts +232 -0
  57. package/client/space_lua/rp.ts +27 -0
  58. package/client/space_lua/runtime.ts +1702 -0
  59. package/client/space_lua/stdlib/crypto.ts +10 -0
  60. package/client/space_lua/stdlib/encoding.ts +19 -0
  61. package/client/space_lua/stdlib/format.ts +770 -0
  62. package/client/space_lua/stdlib/js.ts +73 -0
  63. package/client/space_lua/stdlib/load.ts +52 -0
  64. package/client/space_lua/stdlib/math.ts +193 -0
  65. package/client/space_lua/stdlib/net.ts +113 -0
  66. package/client/space_lua/stdlib/os.ts +368 -0
  67. package/client/space_lua/stdlib/space_lua.ts +153 -0
  68. package/client/space_lua/stdlib/string.ts +286 -0
  69. package/client/space_lua/stdlib/table.ts +401 -0
  70. package/client/space_lua/stdlib.ts +489 -0
  71. package/client/space_lua/tonumber.ts +501 -0
  72. package/client/space_lua/util.ts +96 -0
  73. package/dist/plug-compile.js +1513 -0
  74. package/package.json +120 -0
  75. package/plug-api/constants.ts +42 -0
  76. package/plug-api/lib/async.ts +162 -0
  77. package/plug-api/lib/crypto.ts +202 -0
  78. package/plug-api/lib/dates.ts +13 -0
  79. package/plug-api/lib/json.ts +136 -0
  80. package/plug-api/lib/limited_map.ts +72 -0
  81. package/plug-api/lib/memory_cache.ts +21 -0
  82. package/plug-api/lib/native_fetch.ts +6 -0
  83. package/plug-api/lib/ref.ts +275 -0
  84. package/plug-api/lib/resolve.ts +90 -0
  85. package/plug-api/lib/tags.ts +15 -0
  86. package/plug-api/lib/transclusion.ts +122 -0
  87. package/plug-api/lib/tree.ts +232 -0
  88. package/plug-api/lib/yaml.ts +284 -0
  89. package/plug-api/syscall.ts +15 -0
  90. package/plug-api/syscalls/asset.ts +36 -0
  91. package/plug-api/syscalls/client_store.ts +33 -0
  92. package/plug-api/syscalls/code_widget.ts +8 -0
  93. package/plug-api/syscalls/config.ts +58 -0
  94. package/plug-api/syscalls/datastore.ts +96 -0
  95. package/plug-api/syscalls/editor.ts +517 -0
  96. package/plug-api/syscalls/event.ts +47 -0
  97. package/plug-api/syscalls/index.ts +77 -0
  98. package/plug-api/syscalls/jsonschema.ts +25 -0
  99. package/plug-api/syscalls/language.ts +23 -0
  100. package/plug-api/syscalls/lua.ts +20 -0
  101. package/plug-api/syscalls/markdown.ts +38 -0
  102. package/plug-api/syscalls/mq.ts +79 -0
  103. package/plug-api/syscalls/shell.ts +14 -0
  104. package/plug-api/syscalls/space.ts +212 -0
  105. package/plug-api/syscalls/sync.ts +28 -0
  106. package/plug-api/syscalls/system.ts +102 -0
  107. package/plug-api/syscalls/yaml.ts +28 -0
  108. package/plug-api/syscalls.ts +21 -0
  109. package/plug-api/system_mock.ts +89 -0
  110. package/plug-api/types/client.ts +116 -0
  111. package/plug-api/types/config.ts +22 -0
  112. package/plug-api/types/datastore.ts +28 -0
  113. package/plug-api/types/event.ts +27 -0
  114. package/plug-api/types/index.ts +56 -0
  115. package/plug-api/types/manifest.ts +98 -0
  116. package/plug-api/types/namespace.ts +6 -0
  117. package/plugs/builtin_plugs.ts +14 -0
@@ -0,0 +1,96 @@
1
+ import type { LuaCollectionQuery } from "../../client/space_lua/query_collection.ts";
2
+ import { syscall } from "../syscall.ts";
3
+
4
+ import type { KV, KvKey, KvQuery } from "../../plug-api/types/datastore.ts";
5
+
6
+ /**
7
+ * Exposes a key value story with query capabilities.
8
+ * @module
9
+ */
10
+
11
+ /**
12
+ * Sets a value in the key value store.
13
+ * @param key the key to set
14
+ * @param value the value to set
15
+ */
16
+ export function set(key: KvKey, value: any): Promise<void> {
17
+ return syscall("datastore.set", key, value);
18
+ }
19
+
20
+ /**
21
+ * Sets multiple values in the key value store.
22
+ * @param kvs the key value pairs to set
23
+ */
24
+ export function batchSet(kvs: KV[]): Promise<void> {
25
+ return syscall("datastore.batchSet", kvs);
26
+ }
27
+
28
+ /**
29
+ * Gets a value from the key value store.
30
+ * @param key the key to get
31
+ * @returns the value associated with the key (or undefined if not found)
32
+ */
33
+ export function get(key: KvKey): Promise<any | undefined> {
34
+ return syscall("datastore.get", key);
35
+ }
36
+
37
+ /**
38
+ * Gets multiple values from the key value store.
39
+ * @param keys the keys to get
40
+ * @returns the values associated with the keys (or undefined if not found)
41
+ */
42
+ export function batchGet(keys: KvKey[]): Promise<(any | undefined)[]> {
43
+ return syscall("datastore.batchGet", keys);
44
+ }
45
+
46
+ /**
47
+ * Deletes a value from the key value store.
48
+ * @param key the key to delete
49
+ */
50
+ export function del(key: KvKey): Promise<void> {
51
+ return syscall("datastore.delete", key);
52
+ }
53
+
54
+ /**
55
+ * Deletes multiple values from the key value store.
56
+ * @param keys the keys to delete
57
+ */
58
+ export function batchDel(keys: KvKey[]): Promise<void> {
59
+ return syscall("datastore.batchDelete", keys);
60
+ }
61
+
62
+ export function query(options: KvQuery): Promise<KV[]> {
63
+ return syscall("datastore.query", options);
64
+ }
65
+
66
+ export function queryLua(
67
+ prefix: string[],
68
+ query: LuaCollectionQuery,
69
+ scopeVariables?: Record<string, any>,
70
+ ): Promise<any[]> {
71
+ return syscall("datastore.queryLua", prefix, query, scopeVariables);
72
+ }
73
+
74
+ export function batchDeletePrefix(prefix: KvKey): Promise<void> {
75
+ return syscall("datastore.batchDeletePrefix", prefix);
76
+ }
77
+
78
+ /**
79
+ * Queries the key value store and deletes all matching items
80
+ * @param query the query to run
81
+ * @param variables the variables that can be referenced inside the query
82
+ */
83
+ export function queryDelete(
84
+ query: KvQuery,
85
+ variables?: Record<string, any>,
86
+ ): Promise<void> {
87
+ return syscall("datastore.queryDelete", query, variables);
88
+ }
89
+
90
+ /**
91
+ * Lists all functions currently defined and available for use in queries
92
+ * @returns the names of all functions in the key value store
93
+ */
94
+ export function listFunctions(): Promise<string[]> {
95
+ return syscall("datastore.listFunctions");
96
+ }
@@ -0,0 +1,517 @@
1
+ import { syscall } from "../syscall.ts";
2
+ import type { FilterOption, UploadFile } from "../../plug-api/types/client.ts";
3
+ import type { Path, Ref } from "../lib/ref.ts";
4
+ import type { PageMeta } from "../../plug-api/types/index.ts";
5
+
6
+ /**
7
+ * Exposes various editor utilities.
8
+ * Important: These syscalls are only available in the client.
9
+ * @module
10
+ */
11
+
12
+ /**
13
+ * Returns the name of the page or document currently open in the editor.
14
+ * @returns the current page name
15
+ */
16
+ export function getCurrentPage(): Promise<string> {
17
+ return syscall("editor.getCurrentPage");
18
+ }
19
+
20
+ /**
21
+ * Returns the meta data of the page or document currently open in the editor.
22
+ * @returns the current page meta data
23
+ */
24
+ export function getCurrentPageMeta(): Promise<PageMeta | undefined> {
25
+ return syscall("editor.getCurrentPageMeta");
26
+ }
27
+
28
+ /**
29
+ * Returns the path of the page or document currently open in the editor.
30
+ * @returns the current page path
31
+ */
32
+ export function getCurrentPath(): Promise<Path> {
33
+ return syscall("editor.getCurrentPath");
34
+ }
35
+
36
+ /**
37
+ * Returns the names of the pages that have been recently opened
38
+ * @returns the names of the recently opened pages
39
+ */
40
+ export function getRecentlyOpenedPages(): Promise<PageMeta[]> {
41
+ return syscall("editor.getRecentlyOpenedPages");
42
+ }
43
+
44
+ /**
45
+ * Returns the name of the currently open editor.
46
+ * @returns the name of the current editor
47
+ */
48
+ export function getCurrentEditor(): Promise<string> {
49
+ return syscall("editor.getCurrentEditor");
50
+ }
51
+
52
+ /**
53
+ * Returns the full text of the currently open page
54
+ */
55
+ export function getText(): Promise<string> {
56
+ return syscall("editor.getText");
57
+ }
58
+
59
+ /**
60
+ * This updates the editor text, but in a minimal-diff way:
61
+ * it compares the current editor text with the new text, and only sends the changes to the editor, thereby preserving cursor location
62
+ */
63
+ export function setText(
64
+ newText: string,
65
+ isolateHistory = false,
66
+ ): Promise<void> {
67
+ return syscall("editor.setText", newText, isolateHistory);
68
+ }
69
+
70
+ /**
71
+ * Returns the position (in # of characters from the beginning of the file) of the cursor in the editor
72
+ */
73
+ export function getCursor(): Promise<number> {
74
+ return syscall("editor.getCursor");
75
+ }
76
+
77
+ /**
78
+ * Returns the line number and column number of the cursor in the editor
79
+ */
80
+ export function getSelection(): Promise<
81
+ { from: number; to: number; text: string }
82
+ > {
83
+ return syscall("editor.getSelection");
84
+ }
85
+
86
+ /**
87
+ * Sets the position of the cursor in the editor
88
+ * @param from the start position of the selection
89
+ * @param to the end position of the selection
90
+ */
91
+ export function setSelection(from: number, to: number): Promise<void> {
92
+ return syscall("editor.setSelection", from, to);
93
+ }
94
+
95
+ /**
96
+ * Invoke a client command by name
97
+ * Note: only available on the client
98
+ * @param name name of the command
99
+ * @param args arguments to pass to the command
100
+ */
101
+ export function invokeCommand(name: string, args?: string[]): Promise<any> {
102
+ return syscall("editor.invokeCommand", name, args);
103
+ }
104
+
105
+ /**
106
+ * Forces a save of the current page
107
+ */
108
+ export function save(): Promise<void> {
109
+ return syscall("editor.save");
110
+ }
111
+
112
+ /**
113
+ * Navigates to the specified page reference
114
+ * @param pageRef the page reference to navigate to
115
+ * @param replaceState whether to replace the current history state in the browser history
116
+ * @param newWindow whether to open the page in a new window
117
+ */
118
+ export function navigate(
119
+ ref: Ref | string,
120
+ replaceState = false,
121
+ newWindow = false,
122
+ ): Promise<void> {
123
+ return syscall("editor.navigate", ref, replaceState, newWindow);
124
+ }
125
+
126
+ /**
127
+ * Opens the page navigator
128
+ * @param mode the mode to open the navigator in
129
+ */
130
+ export function openPageNavigator(
131
+ mode: "page" | "meta" | "document" | "all" = "page",
132
+ ): Promise<void> {
133
+ return syscall("editor.openPageNavigator", mode);
134
+ }
135
+
136
+ /**
137
+ * Opens the command palette
138
+ */
139
+ export function openCommandPalette(): Promise<void> {
140
+ return syscall("editor.openCommandPalette");
141
+ }
142
+
143
+ /**
144
+ * Force reloads the current page
145
+ */
146
+ export function reloadPage(): Promise<void> {
147
+ return syscall("editor.reloadPage");
148
+ }
149
+
150
+ /**
151
+ * Force reloads the browser UI
152
+ */
153
+ export function reloadUI(): Promise<void> {
154
+ return syscall("editor.reloadUI");
155
+ }
156
+
157
+ /**
158
+ * Rebuilds the editor state to ensure the dispatch updates the state.
159
+ */
160
+ export function rebuildEditorState(): Promise<void> {
161
+ return syscall("editor.rebuildEditorState");
162
+ }
163
+
164
+ /**
165
+ * Reloads the config and commands, also in the server
166
+ */
167
+ export function reloadConfigAndCommands(): Promise<void> {
168
+ return syscall("editor.reloadConfigAndCommands");
169
+ }
170
+
171
+ /**
172
+ * Opens the specified URL in the browser
173
+ * @param url the URL to open
174
+ * @param existingWindow whether to open the URL in an existing window
175
+ */
176
+ export function openUrl(url: string, existingWindow = false): Promise<void> {
177
+ return syscall("editor.openUrl", url, existingWindow);
178
+ }
179
+
180
+ export function newWindow(): Promise<void> {
181
+ return syscall("editor.newWindow");
182
+ }
183
+
184
+ /**
185
+ * This is calling the `go()` method from the History Web API.
186
+ * @param delta Position in history to move to relative to the current page,
187
+ * where a negative value moves backwards, and positive forwards
188
+ */
189
+ export function goHistory(delta: number): Promise<void> {
190
+ return syscall("editor.goHistory", delta);
191
+ }
192
+
193
+ /**
194
+ * Force the client to download the file in dataUrl with filename as file name
195
+ * @param filename the name of the file to download
196
+ * @param dataUrl the dataUrl of the file to download
197
+ */
198
+ export function downloadFile(filename: string, dataUrl: string): Promise<void> {
199
+ return syscall("editor.downloadFile", filename, dataUrl);
200
+ }
201
+
202
+ /**
203
+ * Triggers the browser's native file upload dialog/popup
204
+ * @param accept the file types to accept
205
+ * @param capture the capture mode for the file input
206
+ */
207
+ export function uploadFile(
208
+ accept?: string,
209
+ capture?: string,
210
+ ): Promise<UploadFile> {
211
+ return syscall("editor.uploadFile", accept, capture);
212
+ }
213
+
214
+ /**
215
+ * Shows a flash notification to the user (top right corner)
216
+ * @param message the message to show
217
+ * @param type the type of notification to show
218
+ */
219
+ export function flashNotification(
220
+ message: string,
221
+ type: "info" | "error" = "info",
222
+ ): Promise<void> {
223
+ return syscall("editor.flashNotification", message, type);
224
+ }
225
+
226
+ /**
227
+ * Exposes a filter box UI (similar to the page navigator and command palette)
228
+ * @param label the label to show left of the input box
229
+ * @param options the options to show and to filter on
230
+ * @param helpText the help text to show below the input box
231
+ * @param placeHolder the placeholder text to show in the input box
232
+ */
233
+ export function filterBox(
234
+ label: string,
235
+ options: FilterOption[],
236
+ helpText = "",
237
+ placeHolder = "",
238
+ ): Promise<FilterOption | undefined> {
239
+ return syscall("editor.filterBox", label, options, helpText, placeHolder);
240
+ }
241
+
242
+ /**
243
+ * Shows a panel in the editor
244
+ * @param id the location of the panel to show
245
+ * @param mode the mode or "size" of the panel
246
+ * @param html the html content of the panel
247
+ * @param script the script content of the panel
248
+ */
249
+ export function showPanel(
250
+ id: "lhs" | "rhs" | "bhs" | "modal",
251
+ mode: number,
252
+ html: string,
253
+ script = "",
254
+ ): Promise<void> {
255
+ return syscall("editor.showPanel", id, mode, html, script);
256
+ }
257
+
258
+ /**
259
+ * Hides a panel in the editor
260
+ * @param id the location of the panel to hide
261
+ */
262
+ export function hidePanel(
263
+ id: "lhs" | "rhs" | "bhs" | "modal",
264
+ ): Promise<void> {
265
+ return syscall("editor.hidePanel", id);
266
+ }
267
+
268
+ export function showProgress(
269
+ progressPercentage?: number,
270
+ progressType?: string,
271
+ ): Promise<void> {
272
+ return syscall("editor.showProgress", progressPercentage, progressType);
273
+ }
274
+
275
+ /**
276
+ * Insert text at the specified position into the editor
277
+ * @param text the text to insert
278
+ * @param pos
279
+ */
280
+ export function insertAtPos(text: string, pos: number): Promise<void> {
281
+ return syscall("editor.insertAtPos", text, pos);
282
+ }
283
+
284
+ /**
285
+ * Replace the text in the specified range in the editor
286
+ * @param from the start position of the range
287
+ * @param to the end position of the range
288
+ * @param text the text to replace with
289
+ */
290
+ export function replaceRange(
291
+ from: number,
292
+ to: number,
293
+ text: string,
294
+ ): Promise<void> {
295
+ return syscall("editor.replaceRange", from, to, text);
296
+ }
297
+
298
+ /**
299
+ * Move the cursor to the specified position in the editor
300
+ * @param pos the position to move the cursor to
301
+ * @param center whether to center the cursor in the editor after moving
302
+ */
303
+ export function moveCursor(pos: number, center = false): Promise<void> {
304
+ return syscall("editor.moveCursor", pos, center);
305
+ }
306
+
307
+ /**
308
+ * Move the cursor to the specified line and column in the editor
309
+ * @param line the line number to move the cursor to
310
+ * @param column the column number to move the cursor to
311
+ * @param center whether to center the cursor in the editor after moving
312
+ */
313
+ export function moveCursorToLine(
314
+ line: number,
315
+ column = 1,
316
+ center = false,
317
+ ): Promise<void> {
318
+ return syscall("editor.moveCursorToLine", line, column, center);
319
+ }
320
+
321
+ /**
322
+ * Insert text at the cursor position in the editor
323
+ * @param text the text to insert
324
+ */
325
+ export function insertAtCursor(
326
+ text: string,
327
+ scrollIntoView = false,
328
+ cursorPlaceHolder = false,
329
+ ): Promise<void> {
330
+ return syscall(
331
+ "editor.insertAtCursor",
332
+ text,
333
+ scrollIntoView,
334
+ cursorPlaceHolder,
335
+ );
336
+ }
337
+
338
+ /**
339
+ * Dispatch a CodeMirror transaction: https://codemirror.net/docs/ref/#state.Transaction
340
+ */
341
+ export function dispatch(change: any): Promise<void> {
342
+ return syscall("editor.dispatch", change);
343
+ }
344
+
345
+ /**
346
+ * Prompt the user for text input
347
+ * @param message the message to show in the prompt
348
+ * @param defaultValue a default value pre-filled in the prompt
349
+ * @returns
350
+ */
351
+ export function prompt(
352
+ message: string,
353
+ defaultValue = "",
354
+ ): Promise<string | undefined> {
355
+ return syscall("editor.prompt", message, defaultValue);
356
+ }
357
+
358
+ /**
359
+ * Prompt the user for confirmation
360
+ * @param message the message to show in the confirmation dialog
361
+ * @returns
362
+ */
363
+ export function confirm(
364
+ message: string,
365
+ ): Promise<boolean> {
366
+ return syscall("editor.confirm", message);
367
+ }
368
+
369
+ /**
370
+ * Prompt the user for confirmation
371
+ * @param message the message to show in the confirmation dialog
372
+ * @returns
373
+ */
374
+ export function alert(
375
+ message: string,
376
+ ): Promise<boolean> {
377
+ return syscall("editor.alert", message);
378
+ }
379
+
380
+ /**
381
+ * Get the value of a UI option
382
+ * @param key the key of the UI option to get
383
+ * @returns
384
+ */
385
+ export function getUiOption(key: string): Promise<any> {
386
+ return syscall("editor.getUiOption", key);
387
+ }
388
+
389
+ /**
390
+ * Set the value of a UI option
391
+ * @param key the key of the UI option to set
392
+ * @param value the value to set the UI option to
393
+ */
394
+ export function setUiOption(key: string, value: any): Promise<void> {
395
+ return syscall("editor.setUiOption", key, value);
396
+ }
397
+
398
+ /**
399
+ * Perform a fold at the current cursor position
400
+ */
401
+ export function fold(): Promise<void> {
402
+ return syscall("editor.fold");
403
+ }
404
+
405
+ /**
406
+ * Perform an unfold at the current cursor position
407
+ */
408
+ export function unfold(): Promise<void> {
409
+ return syscall("editor.unfold");
410
+ }
411
+
412
+ /**
413
+ * Toggle the fold at the current cursor position
414
+ */
415
+ export function toggleFold(): Promise<void> {
416
+ return syscall("editor.toggleFold");
417
+ }
418
+
419
+ /**
420
+ * Fold all code blocks in the editor
421
+ */
422
+ export function foldAll(): Promise<void> {
423
+ return syscall("editor.foldAll");
424
+ }
425
+
426
+ /**
427
+ * Unfold all code blocks in the editor
428
+ */
429
+ export function unfoldAll(): Promise<void> {
430
+ return syscall("editor.unfoldAll");
431
+ }
432
+
433
+ /**
434
+ * Perform an undo operation of the last edit in the editor
435
+ */
436
+ export function undo(): Promise<void> {
437
+ return syscall("editor.undo");
438
+ }
439
+
440
+ /**
441
+ * Perform a redo operation of the last undo in the editor
442
+ */
443
+ export function redo(): Promise<void> {
444
+ return syscall("editor.redo");
445
+ }
446
+
447
+ /**
448
+ * Open the editor's native search panel
449
+ */
450
+ export function openSearchPanel(): Promise<void> {
451
+ return syscall("editor.openSearchPanel");
452
+ }
453
+
454
+ /**
455
+ * Copy the specified data to the clipboard
456
+ * @param data the data to copy
457
+ */
458
+ export function copyToClipboard(data: string | Blob): Promise<void> {
459
+ return syscall("editor.copyToClipboard", data);
460
+ }
461
+
462
+ /**
463
+ * Delete the current line in the editor
464
+ */
465
+ export function deleteLine(): Promise<void> {
466
+ return syscall("editor.deleteLine");
467
+ }
468
+
469
+ /**
470
+ * Comment or uncomment the current line in the editor
471
+ */
472
+ export function toggleComment(): Promise<void> {
473
+ return syscall("editor.toggleComment");
474
+ }
475
+
476
+ export function moveLineUp(): Promise<void> {
477
+ return syscall("editor.moveLineUp");
478
+ }
479
+
480
+ export function moveLineDown(): Promise<void> {
481
+ return syscall("editor.moveLineDown");
482
+ }
483
+
484
+ // Vim-mode specific syscalls
485
+
486
+ /**
487
+ * Execute a Vim ex command
488
+ * @param exCommand the ex command to execute
489
+ */
490
+ export function vimEx(exCommand: string): Promise<any> {
491
+ return syscall("editor.vimEx", exCommand);
492
+ }
493
+
494
+ /**
495
+ * Execute a vim config using the CodeMirror Vim Mode API
496
+ */
497
+ export function configureVimMode(): Promise<any> {
498
+ return syscall("editor.configureVimMode");
499
+ }
500
+
501
+ // Document editor specific syscalls
502
+
503
+ /**
504
+ * Send a message - or event if you will - to the currently used document editor
505
+ * @param type the message type, which can be listend to
506
+ * @param data data attached to the message
507
+ */
508
+ export function sendMessage(type: string, data?: any): Promise<void> {
509
+ return syscall("editor.sendMessage", type, data);
510
+ }
511
+
512
+ /**
513
+ * Check if the editor is running on a mobile device
514
+ */
515
+ export function isMobile(): Promise<boolean> {
516
+ return syscall("editor.isMobile");
517
+ }
@@ -0,0 +1,47 @@
1
+ import { syscall } from "../syscall.ts";
2
+
3
+ /**
4
+ * Exposes the SilverBullet event bus.
5
+ * @module
6
+ */
7
+
8
+ /**
9
+ * Triggers an event on the SilverBullet event bus.
10
+ * This can be used to implement an RPC-style system too, because event handlers can return values,
11
+ * which are then accumulated in an array and returned to the caller.
12
+ * @param eventName the name of the event to trigger
13
+ * @param data payload to send with the event
14
+ * @param timeout optional timeout in milliseconds to wait for a response
15
+ * @returns an array of responses from the event handlers (if any)
16
+ */
17
+ export function dispatchEvent(
18
+ eventName: string,
19
+ data: any,
20
+ timeout?: number,
21
+ ): Promise<any[]> {
22
+ return new Promise((resolve, reject) => {
23
+ let timeouter: any = -1;
24
+ if (timeout) {
25
+ timeouter = setTimeout(() => {
26
+ console.log("Timeout!");
27
+ reject("timeout");
28
+ }, timeout);
29
+ }
30
+ syscall("event.dispatch", eventName, data)
31
+ .then((r: any) => {
32
+ if (timeouter !== -1) {
33
+ clearTimeout(timeouter);
34
+ }
35
+ resolve(r);
36
+ })
37
+ .catch(reject);
38
+ });
39
+ }
40
+
41
+ /**
42
+ * List all events currently registered (listened to) on the SilverBullet event bus.
43
+ * @returns an array of event names
44
+ */
45
+ export function listEvents(): Promise<string[]> {
46
+ return syscall("event.listEvents");
47
+ }