tw5-typed 0.2.27 → 0.3.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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "description": "Types for tiddlywiki",
3
3
  "license": "MIT",
4
4
  "name": "tw5-typed",
5
- "version": "0.2.27",
5
+ "version": "0.3.1",
6
6
  "url": "https://github.com/tiddly-gittly/tw5-typed",
7
7
  "homepage": "https://github.com/tiddly-gittly/tw5-typed",
8
8
  "bugs": {
@@ -53,4 +53,29 @@ declare module 'tiddlywiki' {
53
53
  htmlUnsafeElements: string[];
54
54
  [configName: string]: any;
55
55
  }
56
+
57
+ export interface ITiddlyWikiInfoJSON {
58
+ description: string
59
+ plugins: string[]
60
+ themes: string[]
61
+ languages: any[]
62
+ build: ITiddlyWikiInfoJSONBuild
63
+ config: ITiddlyWikiInfoJSONConfig
64
+ }
65
+
66
+ export interface ITiddlyWikiInfoJSONBuild {
67
+ index: string[]
68
+ empty: string[]
69
+ encrypted: string[]
70
+ favicon: string[]
71
+ readmes: string[]
72
+ tw2: string[]
73
+ static: string[]
74
+ "external-js": string[]
75
+ }
76
+
77
+ export interface ITiddlyWikiInfoJSONConfig {
78
+ "retain-original-tiddler-path": boolean
79
+ }
80
+
56
81
  }
@@ -28,5 +28,11 @@ declare module 'tiddlywiki' {
28
28
  trapErrors: boolean;
29
29
  };
30
30
  excludeRegExp: RegExp;
31
+ /** Exist in nodejs wiki, Load the tiddlers from the wiki directory */
32
+ wikiInfo?: ITiddlyWikiInfoJSON;
33
+ /** Exist in nodejs wiki, absolute path of wiki root folder */
34
+ wikiPath?: string;
35
+ /** Exist in nodejs wiki, usually is `./tiddlers` */
36
+ wikiTiddlersPath?: string;
31
37
  }
32
38
  }
package/src/core.d.ts CHANGED
@@ -7,6 +7,7 @@
7
7
  /// <reference path="plugins/index.d.ts" />
8
8
 
9
9
  declare module 'tiddlywiki' {
10
+
10
11
  export interface IPluginInfo {
11
12
  version: string;
12
13
  'plugin-type': string;
@@ -42,6 +43,7 @@ declare module 'tiddlywiki' {
42
43
  fakeDocument: IFakeDocument;
43
44
  passwordPrompt: PasswordPrompt;
44
45
  packageInfo: Record<string, unknown>;
46
+ syncadaptor: SyncAdaptor;
45
47
 
46
48
  /**
47
49
  * Check for this window being the source of the drag. If true, some drop target widget will stop responding to the drop event, so you can handle drop event in your own widget.
@@ -5,6 +5,7 @@
5
5
  /// <reference path="parsers/index.d.ts" />
6
6
  /// <reference path="widgets/index.d.ts" />
7
7
  /// <reference path="parsers/index.d.ts" />
8
+ /// <reference path="syncer/syncAdaptor.d.ts" />
8
9
 
9
10
  declare module 'tiddlywiki' {
10
11
  export interface ITWModuleExports {
@@ -0,0 +1,13 @@
1
+ declare module 'tiddlywiki' {
2
+ export abstract class SyncAdaptor {
3
+ name: string;
4
+ supportsLazyLoading: boolean;
5
+ isReady(): boolean;
6
+ getTiddlerInfo(title: string): IBootFilesIndexItem;
7
+ getTiddlerFileInfo(
8
+ title: string,
9
+ callback: (error: null, fileInfo: IFileInfo) => void,
10
+ ): void;
11
+ wiki: Wiki;
12
+ }
13
+ }
@@ -1,25 +1,5 @@
1
- declare const addClass: (element: Element, className: string) => void;
2
- declare const addEventListeners: (
3
- domNode: Element,
4
- events: {
5
- handlerFunction?: (event: MouseEvent) => void;
6
- handlerMethod?: string;
7
- handlerObject?: Widget;
8
- name: string;
9
- }[],
10
- ) => void;
11
-
12
- export class Notifier {
13
- /**
14
- * Display a notification
15
- * * title: Title of tiddler containing the notification text
16
- * * options: see below
17
- * Options include:
18
- */
19
- display(title: string, options?: Record<string, unknown>): void;
20
- }
21
-
22
1
  declare module 'tiddlywiki' {
2
+ import { addClass, addEventListeners } from '$:/core/modules/utils/dom.js';
23
3
  interface IUtils {
24
4
  /**
25
5
  * Alternative to `element.classList.add`, add a css class name to an element, see issue for detail.
@@ -44,8 +24,28 @@ declare module 'tiddlywiki' {
44
24
  */
45
25
  Notifier: typeof Notifier;
46
26
  }
27
+ export class Notifier {
28
+ /**
29
+ * Display a notification
30
+ * * title: Title of tiddler containing the notification text
31
+ * * options: see below
32
+ * Options include:
33
+ */
34
+ display(title: string, options?: Record<string, unknown>): void;
35
+ }
47
36
  }
48
37
 
49
38
  declare module '$:/core/modules/utils/dom.js' {
50
- export { addClass, addEventListeners, Notifier };
39
+ import { Widget, Notifier } from 'tiddlywiki';
40
+ export const addClass: (element: Element, className: string) => void;
41
+ export const addEventListeners: (
42
+ domNode: Element,
43
+ events: {
44
+ handlerFunction?: (event: MouseEvent) => void;
45
+ handlerMethod?: string;
46
+ handlerObject?: Widget;
47
+ name: string;
48
+ }[],
49
+ ) => void;
50
+ export { Notifier }
51
51
  }
@@ -1,19 +1,42 @@
1
- declare const generateTiddlerFilepath: (
2
- title: string,
3
- options?: {
4
- directory?: string;
5
- extension?: string;
6
- fileInfo?: {
7
- originalpath?: string;
8
- filePath?: string;
9
- writeError?: boolean;
10
- };
11
- pathFilters?: string[];
12
- wiki?: Wiki;
13
- },
14
- ) => string;
1
+ declare module '$:/core/modules/utils/utils.js' {
2
+ import { IFileInfo, Tiddler, Wiki } from 'tiddlywiki';
3
+
4
+ export const generateTiddlerFilepath: (
5
+ title: string,
6
+ options?: {
7
+ directory?: string;
8
+ extension?: string;
9
+ fileInfo?: {
10
+ originalpath?: string;
11
+ filePath?: string;
12
+ writeError?: boolean;
13
+ };
14
+ pathFilters?: string[];
15
+ wiki?: Wiki;
16
+ },
17
+ ) => string;
18
+ export function generateTiddlerFileInfo(
19
+ tiddler: Tiddler,
20
+ options: {
21
+ directory?: string;
22
+ pathFilters?: string[];
23
+ extFilters?: string[];
24
+ wiki?: Wiki;
25
+ fileInfo?: IFileInfo;
26
+ },
27
+ ): IFileInfo;
28
+ }
15
29
 
16
30
  declare module 'tiddlywiki' {
31
+ import { generateTiddlerFileInfo, generateTiddlerFilepath } from '$:/core/modules/utils/utils.js';
32
+ export interface IFileInfo {
33
+ isEditableFile: boolean;
34
+ originalpath: string;
35
+ type: string;
36
+ hasMetaFile: boolean;
37
+ encoding: string;
38
+ filepath: string;
39
+ }
17
40
  interface IUtils {
18
41
  /**
19
42
  * Generate the filepath for saving a tiddler
@@ -25,9 +48,19 @@ declare module 'tiddlywiki' {
25
48
  * * fileInfo: an existing fileInfo object to check against
26
49
  */
27
50
  generateTiddlerFilepath: typeof generateTiddlerFilepath;
51
+ /**
52
+ Create a fileInfo object for saving a tiddler:
53
+ filepath: the absolute path to the file containing the tiddler
54
+ type: the type of the tiddler file on disk (NOT the type of the tiddler)
55
+ hasMetaFile: true if the file also has a companion .meta file
56
+ isEditableFile: true if the tiddler was loaded via non-standard options & marked editable
57
+ Options include:
58
+ directory: absolute path of root directory to which we are saving
59
+ pathFilters: optional array of filters to be used to generate the base path
60
+ extFilters: optional array of filters to be used to generate the base path
61
+ wiki: optional wiki for evaluating the pathFilters,
62
+ fileInfo: an existing fileInfo to check against
63
+ */
64
+ generateTiddlerFileInfo: typeof generateTiddlerFileInfo;
28
65
  }
29
66
  }
30
-
31
- declare module '$:/core/modules/utils/utils.js' {
32
- export { generateTiddlerFilepath };
33
- }
@@ -1,8 +1,6 @@
1
- declare const count: (object: object) => number;
2
- declare const hashString: (str: string) => number;
3
- declare const formatDateString: (date: Date, format: string) => string;
4
1
 
5
2
  declare module 'tiddlywiki' {
3
+ import { formatDateString, hashString, count } from "$:/core/modules/utils/utils.js";
6
4
  interface IUtils {
7
5
  /**
8
6
  * @en
@@ -21,5 +19,7 @@ declare module 'tiddlywiki' {
21
19
  }
22
20
 
23
21
  declare module '$:/core/modules/utils/utils.js' {
24
- export { count, formatDateString, hashString };
22
+ export const count: (object: object) => number;
23
+ export const hashString: (str: string) => number;
24
+ export const formatDateString: (date: Date, format: string) => string;
25
25
  }
@@ -26,7 +26,22 @@ declare module 'tiddlywiki' {
26
26
  */
27
27
  constructor(...tiddlers: Array<Record<string, unknown> | Tiddler>);
28
28
 
29
- hasField(field: string): boolean;
29
+ hasTag(field: string): boolean;
30
+ hasField(): boolean;
31
+ isPlugin(): boolean;
32
+ isDraft(): boolean;
33
+ getFieldStrings(field: string, defaultValue: string): string;
34
+ getFieldDay(field: string): string;
35
+ /**
36
+ Get the value of a field as a list
37
+ */
38
+ getFieldList(field: string, defaultValue: string): string[];
39
+ /**
40
+ Get all the fields as a name:value block.
41
+ @param options:
42
+ - exclude: an array of field names to exclude
43
+ */
44
+ getFieldStringBlock(options: { exclude?: string[] }): string;
30
45
 
31
46
  isEqual(tiddler: Tiddler, excludeFields: string[]): boolean;
32
47
  }
@@ -318,11 +318,13 @@ declare module 'tiddlywiki' {
318
318
  * Parse a string array from a bracketted list. For example `OneTiddler [[Another Tiddler]] LastOne`
319
319
  * @zh
320
320
  * 从一个带括号的列表中解析一个字符串数组。例如,`OneTiddler [[Another Tiddler]] LastOne`
321
+ *
322
+ * @returns {string[]} An array of tiddler titles. null if input is not string or string array. This won't happened in TS.
321
323
  */
322
324
  parseStringArray: (
323
325
  value: string | string[],
324
326
  allowDuplicate?: boolean,
325
- ) => string[] | null;
327
+ ) => string[];
326
328
 
327
329
  /**
328
330
  * @en
@@ -455,5 +457,20 @@ declare module 'tiddlywiki' {
455
457
  context: IEvalContent,
456
458
  filename: string,
457
459
  ) => unknown;
460
+ /**
461
+ * Transliterate string to ASCII
462
+ * (Some pairs taken from http://semplicewebsites.com/ removing-accents-javascript)
463
+ */
464
+ transliterationPairs: Record<string, string>;
465
+ /**
466
+ * Remove any of the characters that are illegal in Windows filenames
467
+ * See `$tw.utils.transliterationPairs` for the list of replacements
468
+ */
469
+ transliterate: (str: string) => string;
470
+ /**
471
+ * Remove any of the characters that are illegal in Windows filenames
472
+ * See `$tw.utils.transliterationPairs` for the list of replacements
473
+ */
474
+ transliterateToSafeASCII: (str: string) => string;
458
475
  }
459
476
  }
@@ -78,6 +78,18 @@ declare module 'tiddlywiki' {
78
78
  * Returns a function iterator(callback) that iterates through the specified titles, and invokes the callback with callback(tiddler,title)
79
79
  */
80
80
  makeTiddlerIterator(titles: string[]): SourceIterator;
81
+ /**
82
+ * You can use this with `makeTiddlerIterator`:
83
+ *
84
+ * ```js
85
+ * $tw.wiki.filterTiddlers(filter, undefined, $tw.wiki.makeTiddlerIterator(['title']))
86
+ * ```
87
+ *
88
+ * This calls `compileFilter`
89
+ * @param filterString
90
+ * @param widget
91
+ * @param source
92
+ */
81
93
  filterTiddlers(
82
94
  filterString: string,
83
95
  widget?: Widget,