-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathNoteplan.js
2265 lines (2189 loc) · 99.5 KB
/
Noteplan.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @flow
/*
* # How Flow Definitions work:
*
* ## The `+` before keys within object types means that key is read-only.
* - Flow editor plugins should give autocomplete for various keys.
* - Some editor plugins should also show you documentation during autocomplete
*
* ## Declaring Global Variables
* - Every `declare var` declares a variable that is available globally
* - Every `type` declaration defines that type to be used globally as well.
* - The `.eslintrc` will also need to be updated to ignore these globals
*
* ## Unique Names
* Variables and Types *must* have unique names from each other. So when there
* is a collision, the type names is prefixed with a `T`.
* e.g. `Editor` and `TEditor`.
*
* Read More at https://flow.org/en/docs/libdefs/creation/
*
*/
/*
* This refers to the markdown editor and the currently opened note.
* You can access the text directly from here, change the selection and even
* highlight parts.
*
* However, be careful about character positions, because NotePlan hides
* Markdown characters and replaces whole parts of text such as the URL in
* Markdown links or folded text with a single symbol. This can make
* calculating character positions and changing the text a bit tricky. Prefer
* working with the paragraph objects instead to modify text directly.
*
* Here are the available functions you can call with the Editor object:
*/
declare var Editor: TEditor
/**
* The Editor class. This lets you access the currently opened note.
*/
declare interface TEditor extends CoreNoteFields {
/**
* Get the note object of the opened note in the editor
*/
+note: ?TNote;
/**
* Inserts the given text at the given character position (index)
* @param text - Text to insert
* @param index - Position to insert at (you can get this using 'renderedSelection' for example)
*/
insertTextAtCharacterIndex(text: string, index: number): void;
/**
* Get an array of selected lines. The cursor doesn't have to select the full
* line, NotePlan returns all complete lines the cursor "touches".
*/
+selectedLinesText: $ReadOnlyArray<string>;
/**
* Get an array of selected paragraphs. The cursor doesn't have to select the
* full paragraph, NotePlan returns all complete paragraphs the cursor
* "touches". NOTE: note all of the paragraph object data is complete, e.g.
* "headingLevel", "heading" and other properties may not be set properly.
* Use the result and a map to get all the correct data, e.g.:
* const selectedParagraphs = Editor.selectedParagraphs.map((p) => Editor.paragraphs[p.lineIndex])
*/
+selectedParagraphs: $ReadOnlyArray<TParagraph>;
/**
* Get the raw selection range (hidden Markdown is considered).
*/
+selection: ?Range;
/**
* Get the rendered selection range (hidden Markdown is NOT considered).
*/
+renderedSelection: ?Range;
/**
* Get the selected text.
*/
+selectedText: ?string;
/**
* Inserts the given text at the current cursor position
* @param text - Text to insert
*/
insertTextAtCursor(text: string): void;
/**
* Inserts a plain paragraph before the selected paragraph (or the paragraph the cursor is currently positioned)
* @param name - Text of the paragraph
* @param type - paragraph type
* @param indents - How much it should be indented
*/
insertParagraphAtCursor(name: string, type: ParagraphType, indents: number): void;
/**
* Replaces the current cursor selection with the given text
* @param text - Text to insert
*/
replaceSelectionWithText(text: string): void;
/**
* Opens a note using the given filename. Returns the note if it exists or fails, returning null if the file has not been created yet.
* Note: some parameters introduced in v3.4 and v3.5.2
* @param {string} filename - Filename of the note file (can be without extension), but has to include the relative folder such as `folder/filename.txt`.
* Note: if the note doesn't exist, then returns null
* @param {boolean} newWindow - (optional) Open note in new window (default = false)?
* @param {number} highlightStart - (optional) Start position of text highlighting
* @param {number} highlightEnd - (optional) End position of text highlighting
* @param {boolean} splitView - (optional) Open note in a new split view (Note: Available from v3.4)
* @param {boolean} createIfNeeded - (optional) Create the note with the given filename if it doesn't exist (only project notes, v3.5.2+)
* @param {string} content - (optional) Content to fill the note (replaces contents if the note already existed) (from v3.7.2)
* @return {Promise<TNote>} - When the note has been opened, a promise will be returned (use with await ... or .then())
*/
openNoteByFilename(
filename: string,
newWindow?: boolean,
highlightStart?: number,
highlightEnd?: number,
splitView?: boolean,
createIfNeeded?: boolean,
content?: string,
): Promise<TNote | void>;
openNoteByFilename(
filename: string,
newWindow?: boolean,
highlightStart?: number,
highlightEnd?: number,
splitView?: boolean,
createIfNeeded: boolean,
content?: string,
): Promise<TNote>;
/**
* Opens a note by searching for the give title (first line of the note)
* Note: 'splitView' parameter available for macOS from v3.4
* @param {string} title - Title (case sensitive) of the note (first line)
* @param {boolean} newWindow - (optional) Open note in new window (default = false)?
* @param {number} highlightStart - (optional) Start position of text highlighting
* @param {number} highlightEnd - (optional) End position of text highlighting
* @param {boolean} splitView - (optional) Open note in a new split view
* @return {Promise<TNote>} - When the note has been opened, a promise will be returned
*/
openNoteByTitle(title: string, newWindow?: boolean, highlightStart?: number, highlightEnd?: number, splitView?: boolean): Promise<TNote | void>;
/**
* Opens a note by searching for the give title (first line of the note)
* Note: 'splitView' parameter available for macOS from v3.4
* @param {string} title - Title (case sensitive) of the note (first line)
* @param {boolean} newWindow - (optional) Open note in new window (default = false)?
* @param {number} highlightStart - (optional) Start position of text highlighting
* @param {number} highlightEnd - (optional) End position of text highlighting
* @param {boolean} splitView - (optional) Open note in a new split view
* @return {Promise<TNote>} - When the note has been opened, a promise will be returned
*/
openNoteByTitleCaseInsensitive(
title: string,
newWindow?: boolean,
caseSensitive?: boolean,
highlightStart?: number,
highlightEnd?: number,
splitView?: boolean,
): Promise<TNote | void>;
/**
* Opens a calendar note by the given date
* Note: 'splitView' parameter available for macOS from v3.4
* Note: 'timeframe' parameter available for macOS from v3.6
* @param {Date} date - The date that should be opened, this is a normal JavaScript date object
* @param {boolean} newWindow - (optional) Open note in new window (default = false)?
* @param {number} highlightStart - (optional) Start position of text highlighting
* @param {number} highlightEnd - (optional) End position of text highlighting
* @param {boolean} splitView - (optional) Open note in a new split view
* @param {string} timeframe - (optional) Use "week", "month", "quarter" or "year" to open a calendar note other than a daily one
* @return {Promise<TNote>} - When the note has been opened, a promise will be returned
*/
openNoteByDate(date: Date, newWindow?: boolean, highlightStart?: number, highlightEnd?: number, splitView?: boolean, timeframe?: string): Promise<TNote | void>;
/**
* Opens a calendar note by the given date string
* Note: from v3.6 also accepts weeks in the main parameter
* @param {string} dateString - The date string that should be opened, in ISO format for days ("YYYYMMDD") or (from v3.6) in "YYYY-Wnn" format for weeks
* @param {boolean} newWindow - (optional) Open note in new window (default = false)?
* @param {number} highlightStart - (optional) Start position of text highlighting
* @param {number} highlightEnd - (optional) End position of text highlighting
* @param {boolean} splitView - (optional) Open note in a new split view
* @return {Promise<TNote>} - When the note has been opened, a promise will be returned
*/
openNoteByDateString(dateString: string, newWindow?: boolean, highlightStart?: number, highlightEnd?: number, splitView?: boolean): Promise<TNote | void>;
/**
* Opens a weekly calendar note by the given year and week number
* Note: available from v3.6
* @param {number} year - The year of the week
* @param {number} weeknumber - The number of the week (0-52/53)
* @param {boolean} newWindow - (optional) Open note in new window (default = false)?
* @param {number} highlightStart - (optional) Start position of text highlighting
* @param {number} highlightEnd - (optional) End position of text highlighting
* @param {boolean} splitView - (optional) Open note in a new split view
* @return {Promise<void>} - When the note has been opened, a promise will be returned
*/
openWeeklyNote(year: number, weeknumber: number, newWindow?: boolean, highlightStart?: number, highlightEnd?: number, splitView?: boolean): Promise<TNote | void>;
/**
* Selects the full text in the editor.
* Note: Available from v3.2
*/
selectAll(): void;
/**
* (Raw) select text in the editor (like select 10 characters = length from position 2 = start)
* Raw means here that the position is calculated with the Markdown revealed,
* including Markdown links and folded text.
* @param {number} start - Character start position
* @param {number} length - Character length
*/
select(start: number, length: number): void;
/**
* (Rendered) select text in the editor (like select 10 characters = length from position 2 = start)
* Rendered means here that the position is calculated with the Markdown hidden,
* including Markdown links and folded text.
* @param {number} start - Character start position
* @param {number} length - Character length
*/
renderedSelect(start: number, length: number): void;
/**
* Copies the currently selected text in the editor to the system clipboard.
* See also Clipboard object.
* Note: Available from v3.2
*/
copySelection(): void;
/**
* Pastes the current content in the system clipboard into the current selection in the editor.
* See also Clipboard object.
* Note: Available from v3.2
*/
pasteClipboard(): void;
/**
* Scrolls to and highlights the given paragraph.
* If the paragraph is folded, it will be unfolded.
* @param {TParagraph} paragraph to highlight
*/
highlight(paragraph: TParagraph): void;
/**
* Scrolls to and highlights the given character range.
* If the range exists in a folded heading, it will be unfolded.
* @param {Range} range
*/
highlightByRange(range: TRange): void;
/**
* Scrolls to and highlights the given range defined by the character index and the character length it should cover.
* If the paragraph is folded, it will be unfolded.
* Note: Available from v3.0.23
* @param {number} index
* @param {number} length
*/
highlightByIndex(index: number, length: number): void;
/**
* Folds the given paragraph or unfolds it if its already folded. If the paragraph is not a heading, it will look for the heading this paragraph exists under.
* Note: Available from v3.6.0
* @param {TParagraph}
*/
toggleFolding(paragraph: TParagraph): void;
/**
* Checks if the given paragraph is folded or not. If it's not a heading, it will look for the heading this paragraph exists under.
* Note: Available from v3.6.0
* @param {TParagraph}
* @return {boolean}
*/
isFolded(paragraph: TParagraph): boolean;
/**
* Shows or hides a window with a loading indicator or a progress ring (if progress is defined) and an info text (optional).
* `text` is optional, if you define it, it will be shown below the loading indicator.
* `progress` is also optional. If it's defined, the loading indicator will change into a progress ring. Use float numbers from 0-1 to define how much the ring is filled.
* When you are done, call `showLoading(false)` to hide the window.
* Note: Available from v3.0.26
* @param {boolean}
* @param {string?}
* @param {Float?}
*/
showLoading(visible: boolean, text?: ?string, progress?: number): void;
/**
* If you call this, anything after `await CommandBar.onAsyncThread()` will run on an asynchronous thread.
* Use this together with `showLoading`, so that the work you do is not blocking the user interface.
* Otherwise the loading window will be also blocked.
*
* Warning: Don't use any user interface calls (including Editor.* calls, other than showLoading) on an asynchronous thread. The app might crash.
* You need to return to the main thread before you change anything in the window (such as Editor functions do).
* Use `onMainThread()` to return to the main thread.
* Note: Available from v3.0.26
* @return {Promise}
*/
onAsyncThread(): Promise<void>;
/**
* If you call this, anything after `await CommandBar.onMainThread()` will run on the main thread.
* Call this after `onAsyncThread`, once your background work is done.
* It is safe to call Editor and other user interface functions on the main thread.
* Note: Available from v3.0.26
* @return {Promise}
*/
onMainThread(): Promise<void>;
/**
* Save content of Editor to file. This can be used before updateCache() to ensure latest changes are available quickly.
* Warning: beware possiblity of this causing an infinite loop, particularly if used in a function call be an onEditorWillSave trigger.
* WARNING: from @jgclark and @dwertheimer: use helper editor.js function saveEditorIfNecessary() instead, as too often this silently fails, and stops plugins from running.
* Note: Available from 3.9.3
*/
save(): Promise<void>;
/**
* Get the names of all supported themes (including custom themes imported into the Theme folder).
* Use together with `.setTheme(name)`
* Note: available from v3.6.2, returning array of these objects:
* {
"name": String, // name as in the JSON
"mode": String, // "dark", or "light" = reported value in the json
"filename": String, // filename.json in the folder
"values": Object // fully parsed JSON theme file
}
* (Originally available from v3.1, returning a read-only array of strings)
* @return {$ReadOnlyArray<Object>}
*/
+availableThemes: $ReadOnlyArray<Object>;
/**
* Get the current theme name and mode as an object with these keys:
* - "name" in the JSON theme
* - "filename" of the JSON theme file
* - "mode" ("dark" or "light")
* - "values" -- all the JSON in the theme
* Note: Available from NotePlan v3.6.2 (build >847)
* @return {Object}
*/
+currentTheme: Object;
/**
* Change the current theme.
* Get all available theme names using `.availableThemes`. Custom themes are also supported.
* Note: Available from NotePlan v3.1
* @param {string} name of theme to change to.
*/
setTheme(name: string): void;
/**
* Save theme as the default for the specified mode.
* @param {string} theme_name (already-installed; not filename)
* @param {string} mode "dark" | "light" | "auto"
*/
saveDefaultTheme(name: string, mode: string): void;
/**
* Add a new theme using the raw json string. It will be added as a custom theme and you can load it right away with `.setTheme(name)` using the filename defined as second parameter. Use ".json" as file extension.
* It returns true if adding was successful and false if not. An error will be also printed into the console.
* Adding a theme might fail, if the given json text was invalid.
* Note: Available from v3.1
* @param {string} json
* @param {string} filename
* @returns {boolean}
*/
addTheme(json: string, filename: string): boolean;
/**
* Get the current system mode, either "dark" or "light.
* Note: Available from NotePlan v3.6.2+
* @returns {string}
*/
+currentSystemMode: string;
/**
* Get a unique ID for the editor to make it easier to identify it later
* Note: Available from NotePlan v3.8.1 build 973
* @returns {string}
*/
+id: string;
/**
* Set / get a custom identifier, so you don't need to cache the unique id.
* Generally speaking you should set (or at least start) this string with the plugin's ID, e.g. pluginJson['plugin.id']
* Note: Available from NotePlan v3.8.1 build 973
* @returns {string}
*/
customId: string;
/**
* Get the type of window where the editor is embedded in.
* Possible values: main|split|floating|unsupported
* It's unsupported on iOS at the moment.
* Note: Available from NotePlan v3.8.1 build 973
* @returns {string}
*/
+windowType: string;
/**
* Get the cursor into a specific editor and send the window to the front.
* Note: Available from NotePlan v3.8.1 build 973
*/
focus(): void;
/**
* Close the split view or window. If it's the main note, it will close the complete main window.
* Note: Available from NotePlan v3.8.1 build 973
*/
close(): void;
/**
* Set / get the position and size of the window that contains the editor. Returns an object with x, y, width, height values.
* If you want to change the coordinates or size, save the rect in a variable, modify the variable, then assign it to windowRect.
* The position of the window might not be very intuitive, because the coordinate system of the screen works differently (starts at the bottom left for example). Recommended is to adjust the size and position of the window relatively to it's values or other windows.
* Example:
* const rect = Editor.windowRect
* rect.height -= 50
* Editor.windowRect = rect
*
* Note: from JGC: for split & main windows, x/y returns the position and size of the whole window
* WARNING: from JGC: for split & main windows, height is reliable, but width doesn't always seem to be consistent.
* WARNING: from JGC: for floating Editor windows, setting this doesn't seem reliable
* Note: Available with v3.9.1 build 1020
*/
windowRect: Rect;
/**
* Prevents the next "Delete future todos" dialog when deleting a line with a @repeat(...) tag. Will be reset automatically.
* Note: introduced in 3.15 build 1284/1230
* @param {boolean}
*/
skipNextRepeatDeletionCheck: boolean;
/**
* Sets a frontmatter attribute with the given key and value.
* If the key already exists, updates its value. If it doesn't exist, adds a new key-value pair.
* To set multiple frontmatter attributes, use frontmatterAttributes = key-value object.
* @param {string} key - The frontmatter key to set
* @param {string} value - The value to set for the key
* Note: Available from v3.17 - only for Editor!
*/
setFrontmatterAttribute(key: string, value: string): void;
}
/**
* With DataStore you can query, create and move notes which are cached by
* NotePlan. It allows you to query a set of user preferences, too.
*/
type TDataStore = Class<DataStore>
declare class DataStore {
// Impossible constructor
constructor(_: empty): empty;
/**
* Get the preference for the default file (note) extension,
* such as "txt" or "md".
*/
static +defaultFileExtension: string;
/**
* Get all folders as array of strings.
* Note: Includes the root "/" and folders that begin with "@" such as "@Archive" and "@Templates". It excludes the trash folder though.
*/
static +folders: $ReadOnlyArray<string>;
/**
* Create folder, if it doesn't already exist.
* e.g. `DataStore.createFolder("test/hello world")`
* Returns true if created OK (or it already existed) and false otherwise.
* Note: Available from v3.8.0
* @param {string} folderPath
* @returns {boolean} succesful?
*/
static createFolder(folderPath: string): boolean;
/**
* Get all calendar notes.
* Note: from v3.4 this includes all future-referenced dates, not just those with an actual created note.
* TODO: from v3.17.0 does this return Teamspace calendar notes?
*/
static +calendarNotes: $ReadOnlyArray<TNote>;
/**
* Get all regular notes (earlier called "project notes").
* From v3.17.0, this includes Teamspace regular notes. These have as their 'filename' a path represented with an ID, followed by any number of folders, and then a note ID.
* Example: %%NotePlanCloud%%/275ce631-6c20-4f76-b5fd-a082a9ac5160/Projects/Research/b79735c9-144b-4fbf-8633-eaeb40c182fa
* Note: This includes notes and templates from folders that begin with "@" such as "@Archive" and "@Templates". It excludes notes in the trash folder though.
* Note: @jgclark adds that this will return non-note document files (e.g. PDFs) as well as notes.
*/
static +projectNotes: $ReadOnlyArray<TNote>;
/**
* Get all cached hashtags (#tag) that are used across notes.
* It returns hashtags without leading '#'.
* @type {Array<string>}
* Note: Available from v3.6.0
*/
static +hashtags: $ReadOnlyArray<string>;
/**
* Get all cached mentions (@name) that are used across notes.
* It returns mentions without leading '@'.
* Note: Available from v3.6.0
* @type {Array<string>}
*/
static +mentions: $ReadOnlyArray<string>;
/**
* Get list of all filter names
* Note: Available from v3.6.0
* @type {Array<string>}
*/
static +filters: $ReadOnlyArray<string>;
/**
* Get list of all overdue tasks as paragraphs
* Note: Available from v3.8.1
* @type {Array<TParagraph>}
*/
static listOverdueTasks(): $ReadOnlyArray<TParagraph>;
/**
* Get or set settings for the current plugin (as a JavaScript object).
* Example: settings.shortcutExpenses[0].category
* Note: Available from v3.3.2
*/
static settings: Object;
/**
* Returns the value of a given preference.
* Available keys for built-in NotePlan preferences:
* "themeLight" // theme used in light mode
* "themeDark" // theme used in dark mode
* "fontDelta" // delta to default font size
* "firstDayOfWeek" // first day of calendar week
* "isAgendaVisible" // only iOS, indicates if the calendar and note below calendar are visible
* "isAgendaExpanded" // only iOS, indicates if calendar above note is shown as week (true) or month (false)
* "isAsteriskTodo" // "Recognize * as todo" = checked in markdown preferences
* "isDashTodo" // "Recognize - as todo" = checked in markdown preferences
* "isNumbersTodo" // "Recognize 1. as todo" = checked in markdown preferences
* "defaultTodoCharacter" // returns * or -
* "isAppendScheduleLinks" // "Append links when scheduling" checked in todo preferences
* "isAppendCompletionLinks" // "Append completion date" checked in todo preferences
* "isCopyScheduleGeneralNoteTodos" // "Only add date when scheduling in notes" checked in todo preferences
* "isSmartMarkdownLink" // "Smart Markdown Links" checked in markdown preferences
* "fontSize" // Font size defined in editor preferences (might be overwritten by custom theme)
* "fontFamily" // Font family defined in editor preferences (might be overwritten by custom theme)
* "timeblockTextMustContainString" // Optional text to trigger timeblock detection in a line. JGC notes that this is case sensitive and must match on a whole word.
* "openAIKey" // Optional user's openAIKey (from v3.9.3 build 1063)
* Others can be set by plugins.
* Note: these keys and values do not sync across a user's devices; they are only local.
* The keys are case-sensitive (it uses the Apple UserDefaults mechanism).
*/
static +preference: (key: string) => mixed;
/**
* Change a saved preference or create a new one.
* It will most likely be picked up by NotePlan after a restart, if you use one of the keys utilized by NotePlan.
*
* To change a NotePlan preference, use the keys found in the description of the function `.preference(key)`.
* You can also save custom preferences specific to the plugin, if you need any.
* repend it with the plugin id or similar to avoid collisions with existing keys.
* Note: these keys and values do not sync across a user's devices; they are only local.
* Note: Available from v3.1
* @param {string}
* @param {any}
*/
static setPreference(key: string, value: mixed): void;
/**
* Save a JavaScript object to the Plugins folder as JSON file.
* This can be used to save preferences or other persistent data.
* It's saved automatically into a new folder "data" in the Plugins folder.
* But you can "escape" this folder using relative paths: ../Plugins/<folder or filename>.
* Note: Available from v3.1
* @param {Object} jsonData to save
* @param {string?} filename (defaults to plugin's setting.json file)
* @param {boolean?} shouldBlockUpdate? (defaults to false)
* @returns {boolean} success
*/
static saveJSON(object: Object, filename?: string, shouldBlockUpdate?: boolean): boolean;
/**
* Load a JavaScript object from a JSON file located (by default) in the <Plugin>/data folder.
* But you can also use relative paths: ../Plugins/<folder or filename>.
* Note: Available from v3.1
* @param {string} filename (defaults to plugin's setting.json)
* @returns {Object}
*/
static loadJSON(filename?: string): Object;
/**
* Save data to a file.
* Can use this with base64 encoding to save arbitary binary data, or with string-based data (using loadAsString flag).
* The file will be saved under "[NotePlan Folder]/Plugins/data/[plugin-id]/[filename]".
* If the file already exists, it will be over-written.
* Returns true if the file could be saved, false if not and prints the error.
* Note: Available from v3.2.0; loadAsString option only from v3.6.2.
* @param {string} data to write
* @param {string} filename to write to
* @param {boolean} loadAsString?
* @returns {boolean}
*/
static saveData(data: string, filename: string, loadAsString: boolean): boolean;
/**
* Load data from a file.
* Can be used with saveData() to save and load binary data from encoded as a base64 string, or string-based data (using loadAsString flag).
* The file has to be located in "[NotePlan Folder]/Plugins/data/[plugin-id]/[filename]".
* You can access the files of other plugins as well, if the filename is known using relative paths "../[other plugin-id]/[filename]" or simply go into the "data"'s root directory "../[filename]" to access a global file.
* Returns undefined if the file couldn't be loaded and prints an error message.
* Note: Available from v3.2.0; loadAsString option only from v3.6.2.
* @param {string} filename
* @param {boolean} loadAsString?
* @returns {string?}
*/
static loadData(filename: string, loadAsString: boolean): ?string;
/**
* Check to see if a file in the available folders exists.
* It starts in the plugin's own data folder, but can be used to check for files in other folders.
* Note: Available from v3.8.1
* @param {string} filename
* @returns {boolean}
*/
static fileExists(filename: string): boolean;
/**
* Returns the calendar note for the given date and timeframe (optional, the default is "day", see below for more options).
* Note: from v3.17.0, this includes Teamspace calendar notes. Calendar Notes are represented with the ISO date + extension in the path.
* Note: 'timeframe' available from v3.6.0
* Note: 'parent' available from v3.17.0
* WARNING: @jgclark: I think from use in Dashboard, this is unreliable, but I can't yet prove it. Instead use calendarNoteByDateString() below.
*
* @param {Date}
* @param {string?} timeframe: "day" (default), "week", "month", "quarter" or "year"
* @param {string?} parent: Teamspace (if relevant) = the ID or filename of the teamspace it belongs to. If left undefined, the private calendar note will be returned as before.
* @returns {NoteObject}
*/
static calendarNoteByDate(date: Date, timeframe ?: string, parent ?: string): ?TNote;
/**
* Returns the calendar note for the given date string (can be undefined, if the calendar note was not created yet). See the date formats below for various types of calendar notes:
* Daily: "YYYYMMDD", example: "20210410"
* Weekly: "YYYY-Wwn", example: "2022-W24"
* Quarter: "YYYY-Qq", example: "2022-Q4"
* Monthly: "YYYY-MM", example: "2022-10"
* Yearly: "YYYY", example: "2022".
* Note: from v3.17.0, this includes Teamspace calendar notes. Calendar Notes are represented with the ISO date + extension in the path.
* Note: Some timeframes available from v3.7.2
* Note: 'parent' available from v3.17.0
* Note: In response to questions about yet-to-exist future dates, @EM says "The file gets created when you assign content to a future, non-existing note." In this situation when this call is made, note.content will be empty.
* @param {string} dateString
* @param {string?} parent: Teamspace (if relevant) = the ID or filename of the teamspace it belongs to. If left undefined, the private calendar note will be returned as before.
* @returns {NoteObject}
*/
static calendarNoteByDateString(dateString: string, parent ?: string): ?TNote;
/**
* Returns all regular notes with the given title.
* Since multiple notes can have the same title, an array is returned.
* Use 'caseSensitive' (default = false) to search for a note ignoring
* the case and set 'searchAllFolders' to true if you want to look for
* notes in trash and archive as well.
* By default NotePlan won't return notes in trash and archive.
*/
static projectNoteByTitle(title: string, caseInsensitive?: boolean, searchAllFolders?: boolean): ?$ReadOnlyArray<TNote>;
/**
* Returns all regular notes with the given case insensitive title.
* Note: Since multiple notes can have the same title, an array is returned.
*/
static projectNoteByTitleCaseInsensitive(title: string): ?$ReadOnlyArray<TNote>;
/**
* Returns the regular note with the given filename (including file-extension).
* The filename has to include the relative folder such as folder/filename.txt` but without leading slash. Use no leading slash if it's in the root folder.
*/
static projectNoteByFilename(filename: string): ?TNote;
/**
* Returns a regular or calendar note for the given filename. Type can be "Notes" or "Calendar". Include relative folder and file extension (`folder/filename.txt` for example).
* Use "YYYYMMDD.ext" for calendar notes, like "20210503.txt".
* Note: 'parent' available from v3.17.0
* @param {string} filename
* @param {NoteType} type
* @param {string?} parent: Teamspace (if relevant) = the ID or filename of the teamspace it belongs to. Applies only to calendar notes.
* @returns {?TNote}
*/
static noteByFilename(filename: string, type: NoteType, parent ?: string): ?TNote;
/**
* Move a regular note using the given filename (with extension) to another folder. Use "/" for the root folder.
* Note: Can also move *folders* by specifying its filename (without trailing slash).
* Note: You can also use this to delete notes or folders by moveNote(filepath, '@Trash')
* Note: from v3.9.3 you can also use 'type' set to 'Calendar' to move a calendar note.
* Returns the final filename; if the there is a duplicate, it will add a number.
* @param {string} filename of the new note
* @param {string} folder to move the note to
* @param {NoteType} type? for note
* @returns {?string} resulting final filename
*/
static moveNote(filename: string, folder: string, type?: NoteType): ?string;
/**
* Creates a regular note using the given title and folder.
* Use "/" for the root folder.
* It will write the given title as "# title" into the new file.
* Returns the final filename; if the there is a duplicate, it will add a number.
* Note: @jgclark finds that if 'folder' has different capitalisation than an existing folder, NP gets confused, in a way that reset caches doesn't solve. It needs a restart.
* @param {string} noteTitle of the new note
* @param {string} folder to create the note in
* @returns {?string} resulting final filename
*/
static newNote(noteTitle: string, folder: string): ?string;
/**
* Creates a regular note using the given content, folder and filename. Use "/" for the root folder.
* The content should ideally also include a note title at the top.
* Returns the final filename with relative folder (`folder/filename.txt` for example).
* If the there is a duplicate, it will add a number.
* Alternatively, you can also define the filename as the third optional variable (v3.5.2+)
* Note: available from v3.5, with 'filename' parameter added in v3.5.2
* @param {string} content for note
* @param {string} folder to create the note in
* @param {string} filename of the new note (optional) (available from v3.5.2)
* @returns {string}
*/
static newNoteWithContent(content: string, folder: string, filename?: string): string;
/**
* Returns an array of paragraphs having the same blockID like the given one (which is also part of the return array).
* Or use without an argument to return all paragraphs with blockIDs.
* You can use `paragraph[0].note` to access the note behind it and make updates via `paragraph[0].note.updateParagraph(paragraph[0])` if you make changes to the content, type, etc (like checking it off as type = "done").
* Note: Available from v3.5.2
* @param {TParagraph}
* @return {Array<TParagraph>}
*/
static referencedBlocks(): Array<TParagraph>;
static referencedBlocks(paragraph: TParagraph): Array<TParagraph>;
/**
* Updates the cache, so you can access changes faster.
* 'shouldUpdateTags' parameter controls whether to update .hashtags and .mentions too.
* EM also commented "[and] things like .backlinks".
* If so, the note has to be reloaded for the updated .mentions to be available.
* EM has also said "It doesn't have to be async, because it runs on the same thread and updates the cache directly, but that has nothing to do with the content of the paragraph or note, that's read directly out of the file again".
*
* Note: Available from NotePlan v3.7.1
* @param {TNote} note to update
* @param {boolean} shouldUpdateTags?
* @returns {TNote?} updated note object
*/
static updateCache(note: TNote, shouldUpdateTags: boolean): TNote | null;
/**
* Loads all available plugins asynchronously from the GitHub repository and returns a list.
* Note: Available from NotePlan v3.5.2; 'skipMatchingLocalPlugins' added v3.7.2 build 926
* @param {boolean} showLoading? - You can show a loading indicator using the first parameter (true) if this is part of some user interaction. Otherwise, pass "false" so it happens in the background.
* @param {boolean} showHidden? - Set `showHidden` to true if it should also load hidden plugins. Hidden plugins have a flag `isHidden`
* @param {boolean} skipMatchingLocalPlugins? - Set the third parameter `skipMatchingLocalPlugins` to true if you want to see only the available plugins from GitHub and not merge the data with the locally available plugins. Then the version will always be that of the plugin that is available online.
* @return {Promise<any>} pluginList
*/
static listPlugins(showLoading?: boolean, showHidden?: boolean, skipMatchingLocalPlugins?: boolean): Promise<Array<PluginObject>>;
/**
* Installs a given plugin (load a list of plugins using `.listPlugins` first). If this is part of a user interfaction, pass "true" for `showLoading` to show a loading indicator.
* Note: Available from v3.5.2
* @param {PluginObject}
* @param {boolean}
* @return {Promise<PluginObject>} the pluginObject of the installed plugin
*/
static installPlugin(pluginObject: PluginObject, showLoading?: boolean): Promise<PluginObject>;
/**
* Returns all installed plugins as PluginObject(s).
* Note: Available from v3.5.2
* @return {Array<PluginObject>}
*/
static installedPlugins(): Array<PluginObject>;
/**
* Invoke a given command from a plugin (load a list of plugins using `.listPlugins` first, then get the command from the `.commands` list).
* If the command supports it, you can also pass an array of arguments which can contain any type (object, date, string, integer,...)
* It returns the particular return value of that command which can be a Promise so you can use it with `await`.
* You can await for a return value, but even if you plan to ignore the value, the receiving function should return a value (even a blank {}) or you will get an error in the log
* Note: Available from v3.5.2
* @param {PluginCommandObject}
* @param {$ReadOnlyArray<mixed>}
* @return {any} Return value of the command, like a Promise
*/
static invokePluginCommand(command: PluginCommandObject, arguments: $ReadOnlyArray<mixed>): Promise<any>;
/**
* Invoke a given command from a plugin using the name and plugin ID, so you don't need to load it from the list.
* If the command doesn't exist locally null will be returned with a log message.
* If the command supports it, you can also pass an array of arguments which can contain any type (object, date, string, integer,...)
* You can await for a return value, but even if you plan to ignore the value, the receiving function should return a value (even a blank {}) or you will get an error in the log
* Note: Available from v3.5.2
* @param {string} - commandName - the NAME field from the command in plugin.json (not the jsFunction!)
* @param {string}
* @param {$ReadOnlyArray<mixed>}
* @return {any} Return value of the command, like a Promise
*/
static invokePluginCommandByName(commandName: string, pluginID: string, arguments?: $ReadOnlyArray<mixed>): Promise<any>;
/**
* Checks if the given pluginID is installed or not.
* Note: Available from v3.6.0
* @param {string}
* @return {boolean}
*/
static isPluginInstalledByID(pluginID: string): boolean;
/**
* Installs a given array of pluginIDs if needed. It checks online if a new version is available and downloads it.
* Use it without `await` so it keeps running in the background or use it with `await` in "blocking mode" if you need to install a plugin as a dependency. In this case you can use `showPromptIfSuccessful = true` to show the user a message that a plugin was installed and `showProgressPrompt` will show a loading indicator beforehand. With both values set to false or not defined it will run in "silent" mode and show no prompts.
* returns an object with an error code and a message { code: -1, message: "something went wrong" } for example. Anything code >= 0 is a success.
* Note: Available from v3.6.0
* @param {Array<string>} IDs
* @param {boolean} showPromptIfSuccessful
* @param {boolean} showProgressPrompt
* @param {boolean} showFailedPrompt
* @return {Promise<{number, string}>}
*/
static installOrUpdatePluginsByID(
pluginIDs: Array<string>,
showPromptIfSuccessful: boolean,
showProgressPrompt: boolean,
showFailedPrompt: boolean,
): Promise<{ code: number, message: string }>;
/**
* Searches all notes for a keyword (uses multiple threads to speed it up).
* By default it searches in project notes and in the calendar notes. Use the second parameters "typesToInclude" to include specific types. Otherwise, pass `null` or nothing to include all of them.
* This function is async, use it with `await`, so that the UI is not being blocked during a long search.
* Optionally pass a list of folders (`inNotes`) to limit the search to notes that ARE in those folders (applies only to project notes). If empty, it is ignored.
* Optionally pass a list of folders (`notInFolders`) to limit the search to notes NOT in those folders (applies only to project notes). If empty, it is ignored.
* Searches for keywords are case-insensitive.
* It will sort it by filename (so search results from the same notes stay together) and calendar notes also by filename with the newest at the top (highest dates).
* Note: Available from v3.6.0
* @param {string} = keyword to search for
* @param {Array<string> | null?} typesToInclude ["notes", "calendar"] (by default all, or pass `null`)
* @param {Array<string> | null?} inFolders list (optional)
* @param {Array<string> | null?} notInFolderslist (optional)
* @param {boolean?} shouldLoadDatedTodos? (optional) true to enable date-referenced items to be included in the search
* @return {$ReadOnlyArray<TParagraph>} array of results
*/
static search(
keyword: string,
typesToInclude?: Array<string>,
inFolders?: Array<string>,
notInFolders?: Array<string>,
shouldLoadDatedTodos?: boolean,
): Promise<$ReadOnlyArray<TParagraph>>;
/**
* Searches all project notes for a keyword (uses multiple threads to speed it up).
* This function is async, use it with `await`, so that the UI is not being blocked during a long search.
* Optionally pass a list of folders (`inNotes`) to limit the search to notes that ARE in those folders (applies only to project notes)
* Optionally pass a list of folders (`notInFolders`) to limit the search to notes NOT in those folders (applies only to project notes)
* Searches for keywords are case-insensitive.
* Note: Available from v3.6.0
* @param {string} = keyword to search for
* @param {Array<string> | null?} folders list (optional)
* @param {Array<string> | null?} folders list (optional)
* @return {$ReadOnlyArray<TParagraph>} results array
*/
static searchProjectNotes(keyword: string, inFolders?: Array<string>, notInFolders?: Array<string>): Promise<$ReadOnlyArray<TParagraph>>;
/**
* Searches all calendar notes for a keyword (uses multiple threads to speed it up).
* This function is async, use it with `await`, so that the UI is not being blocked during a long search.
* Note: Available from v3.6.0
* @param {string?} (optional) keyword to search for
* @param {boolean?} (optional) true to enable date-referenced items to be included in the search
* @return {$ReadOnlyArray<TParagraph>} array of results
*/
static searchCalendarNotes(keyword?: string, shouldLoadDatedTodos?: boolean): Promise<$ReadOnlyArray<TParagraph>>;
/**
* Returns list of all overdue tasks (i.e. tasks that are open and in the past). Use with await, it runs in the background. If there are a lot of tasks consider showing a loading bar.
* Note: this does not include open checklist items.
* Note: Available from v3.8.1
* @param {string} = keyword to search for
* @return {$ReadOnlyArray<TParagraph>} Promise to array of results
*/
static listOverdueTasks(keyword: string): Promise<$ReadOnlyArray<TParagraph>>;
/**
* DataStore.teamspaces returns an array of teamspaces represented as Note Objects with title and filename populated. Example of a filename: %%NotePlanCloud%%/275ce631-6c20-4f76-b5fd-a082a9ac5160
* Note: No object for private notes is included here.
* Note: Available from v3.17.0
*/
static teamspaces: $ReadOnlyArray < TNote >;
}
/**
* Object to pass window details (from Swift)
*/
type Rect = {
x: number, // in practice are all integers
y: number,
width: number,
height: number,
}
/**
* An object when trying to run a plugin Object
*/
type PluginCommandObject = {
/**
* Name of the plugin command (getter)
*/
+name: string,
/**
* Description of the plugin command (getter)
*/
+desc: string,
/**
* ID of the plugin this command belongs to (getter)
*/
+pluginID: string,
/**
* Name of the plugin this command belongs to (getter)
*/
+pluginName: string,
/**
* Whether this is marked as a hidden command (getter)
*/
+isHidden: boolean,
+hidden: boolean,
/**
* List of optional argument descriptions for the specific command (getter). Use this if you want to invoke this command from another plugin to inform the user what he nees to enter for example.
*/
+arguments: $ReadOnlyArray<string>,
}
/**
* An object that represents a plugin
*/
type PluginObject = {
/**
* ID of the plugin (getter)
*/
+id: string,
/**
* Name of the plugin (getter)
*/
+name: string,
/**
* Description of the plugin (getter)
*/
+desc: string,
/**
* Author of the plugin (getter)
*/
+author: string,
/**
* RepoUrl of the plugin (getter)
*/
+repoUrl: ?string,
/**
* Release page URL of the plugin (on GitHub) (getter)
*/
+releaseUrl: ?string,
/**
* Version of the plugin (getter)
*/
+version: string,
/**
* This is the online data of the plugin. It might not be installed locally. (getter)
*/
+isOnline: boolean,
/**
* Whether this plugin is marked as hidden (getter)
*/
+isHidden: boolean,
+hidden: boolean,
/**
* Script filename that contains the code for this plugin (like script.js) (getter)
*/
+script: string,
/**
* If this is a locally installed plugin, you can use this variable to check if an updated version is available online. (getter)
*/
+availableUpdate: PluginObject,
/**
* A list of available commands for this plugin. (getter)
* @type {PluginCommandObject}
*/
+commands: $ReadOnlyArray<PluginCommandObject>,
}
/**
* Use CommandBar to get user input. Either by asking the user to type in a
* free-form string, like a note title, or by giving him a list of choices.
* This list can be "fuzzy-search" filtered by the user. So, it's fine to show
* a long list of options, like all folders or notes or tasks in a note.
*/
type TCommandBar = Class<CommandBar>
declare class CommandBar {
// Impossible constructor
constructor(_: empty): empty;
/**
* Get or set the current text input placeholder (what you can read when no
* input is typed in) of the Command Bar.
*/
static placeholder: string;
/**
* Get or set the current text input content of the Command Bar
* (what the user normally types in).
*/
static searchText: string;
/**
* Hides the Command Bar
*/
static hide(): void;
// show(): void,
/**
* Display an array of choices as a list (only strings) which the user can
* "fuzzy-search" filter by typing something.
* The user selection is returned as a Promise.
* So use it with `await CommandBar.showOptions(...)`.
* The result is a CommandBarResultObject (as Promise success result), which
* has `.value` and `.index`.
* Use the `.index` attribute to refer back to the selected item in the
* original array.
* Also can optionally set the default option text to show. (from 3.11.1)
* @param {$ReadOnlyArray<TOption>} options
* @param {string} placeholder
* @param {string?} optionTextDefault?
* @returns {Promise<{ +index: number, +value: TOption }>}
*/
static showOptions<TOption: string = string>(options: $ReadOnlyArray<TOption>, placeholder: string, optionTextDefault?: string): Promise<{ +index: number, +value: TOption }>;
/**
* Asks the user to enter something into the CommandBar.
* Use the "placeholder" value to display a question, like "Type the name of the task".
* Use the "submitText" to describe what happens with the selection, like "Create task named '%@'".
* The "submitText" value supports the variable "%@" in the string, that NotePlan autofill with the typed text.
* Also can optionally set the default search text to show. (from 3.11.1)
* It returns a Promise, so you can wait (using "await...") for the user
* input with the entered text as success result.
* @param {string} placeholder
* @param {string} submitText
* @param {string?} searchTextDefault?
* @returns {Promise<string>}
*/
static showInput(placeholder: string, submitText: string): Promise<string>;
/**
* Shows or hides a window with a loading indicator or a progress ring (if progress is defined) and an info text (optional).
* `text` is optional, if you define it, it will be shown below the loading indicator.
* `progress` is also optional. If it's defined, the loading indicator will change into a progress ring. Use float numbers from 0-1 to define how much the ring is filled.
* When you are done, call `showLoading(false)` to hide the window.
* Note: Available from v3.0.26
* @param {boolean} visible?
* @param {string?} text
* @param {number?} progress (floating point)
*/
static showLoading(visible: boolean, text?: string, progress?: number): void;
/**