tw5-typed 0.2.14 → 0.2.16

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.14",
5
+ "version": "0.2.16",
6
6
  "url": "https://github.com/tiddly-gittly/tw5-typed",
7
7
  "homepage": "https://github.com/tiddly-gittly/tw5-typed",
8
8
  "bugs": {
@@ -17,31 +17,28 @@
17
17
  "src/"
18
18
  ],
19
19
  "scripts": {
20
- "prepublishOnly": "npx tsc --noEmit"
20
+ "check": "tsc --noEmit && eslint src/**/*.ts"
21
+ },
22
+ "husky": {
23
+ "hooks": {
24
+ "pre-commit": "lint-staged"
25
+ }
26
+ },
27
+ "lint-staged": {
28
+ "*.{ts,tsx}": [
29
+ "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"
30
+ ],
31
+ "*.{js,jsx,mjs,mjsx,cjs,cjsx}": [
32
+ "node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"
33
+ ]
21
34
  },
22
35
  "devDependencies": {
23
- "@types/node": "^18.11.12",
24
- "@typescript-eslint/eslint-plugin": "5.46.0",
25
- "@typescript-eslint/parser": "5.46.0",
26
- "eslint": "8.29.0",
27
- "eslint-config-prettier": "8.5.0",
28
- "eslint-config-standard": "17.0.0",
29
- "eslint-config-standard-with-typescript": "23.0.0",
30
- "eslint-import-resolver-alias": "1.1.2",
31
- "eslint-import-resolver-typescript": "3.5.2",
32
- "eslint-plugin-html": "7.1.0",
33
- "eslint-plugin-import": "2.26.0",
34
- "eslint-plugin-n": "15.6.0",
35
- "eslint-plugin-node": "11.1.0",
36
- "eslint-plugin-prettier": "4.2.1",
37
- "eslint-plugin-promise": "6.1.1",
38
- "eslint-plugin-react": "7.31.11",
39
- "eslint-plugin-react-hooks": "4.6.0",
40
- "eslint-plugin-security": "1.5.0",
41
- "eslint-plugin-security-node": "1.1.1",
42
- "eslint-plugin-typescript-sort-keys": "2.1.0",
43
- "eslint-plugin-unicorn": "45.0.1",
44
- "prettier": "2.8.1",
45
- "typescript": "4.9.4"
36
+ "@modern-js/eslint-config": "latest",
37
+ "@modern-js/tsconfig": "latest",
38
+ "@types/node": "^18.11.9",
39
+ "husky": "^8.0.2",
40
+ "lint-staged": "^13.1.0",
41
+ "rimraf": "^3.0.2",
42
+ "typescript": "^4.9.4"
46
43
  }
47
44
  }
@@ -15,11 +15,12 @@ declare module 'tiddlywiki' {
15
15
  ) => boolean;
16
16
 
17
17
  export class PasswordPrompt {
18
- /** Creates a PasswordPrompt object */
19
- constructor();
20
18
  /** Store of pending password prompts */
21
19
  passwordPrompts: PasswordPromptInfo[];
20
+
22
21
  promptWrapper: TWDOMElement;
22
+ /** Creates a PasswordPrompt object */
23
+ constructor();
23
24
  /** Hides or shows the wrapper depending on whether there are any outstanding prompts */
24
25
  setWrapperDisplay(): void;
25
26
  /**
package/src/Tiddler.d.ts CHANGED
@@ -1,13 +1,15 @@
1
1
  declare module 'tiddlywiki' {
2
2
  export class Tiddler {
3
+ static fieldModules: Record<string, IModuleInfo>;
4
+
5
+ readonly cache: ITiddlerCache;
6
+
7
+ readonly fields: ITiddlerFields;
3
8
  /**
4
9
  *
5
10
  * @param tiddlers multiple tiddler fields or instances, will merge them to create a new one
6
11
  */
7
12
  constructor(...tiddlers: Array<Record<string, unknown> | Tiddler>);
8
- readonly cache: ITiddlerCache;
9
- readonly fields: ITiddlerFields;
10
- static fieldModules: Record<string, IModuleInfo>;
11
13
  hasField(field: string): boolean;
12
14
  isEqual(tiddler: Tiddler, excludeFields: string[]): boolean;
13
15
  }
package/src/Wiki.d.ts CHANGED
@@ -5,14 +5,22 @@ declare module 'tiddlywiki' {
5
5
  document: typeof document | IFakeDocument;
6
6
  }
7
7
 
8
- export type OutputMimeTypes = 'text/html' | 'text/plain-formatted' | 'text/plain';
9
- export type TextMimeTypes = 'text/html' | 'text/vnd.tiddlywiki' | 'text/plain';
8
+ export type OutputMimeTypes =
9
+ | 'text/html'
10
+ | 'text/plain-formatted'
11
+ | 'text/plain';
12
+ export type TextMimeTypes =
13
+ | 'text/html'
14
+ | 'text/vnd.tiddlywiki'
15
+ | 'text/plain';
10
16
  export interface IRenderOptions {
11
17
  parentWidget?: Widget;
12
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
18
  variables?: Record<string, any>;
14
19
  }
15
- export type ITiddlerFieldsParam = Omit<Partial<ITiddlerFields>, 'created' | 'modified'> & { created?: string; modified?: string };
20
+ export type ITiddlerFieldsParam = Omit<
21
+ Partial<ITiddlerFields>,
22
+ 'created' | 'modified'
23
+ > & { created?: string; modified?: string };
16
24
  export class Wiki {
17
25
  /**
18
26
  * Wiki constructor. State is stored in private members that only a small number of privileged accessor methods have direct access. Methods added via the prototype have to use these accessors and cannot access the state data directly.
@@ -22,11 +30,13 @@ declare module 'tiddlywiki' {
22
30
  */
23
31
  constructor(options: { enableIndexers: unknown[] });
24
32
  addIndexer(indexer: unknown, name: string): void;
25
- getTiddler: <T extends Tiddler>(title: string) => T | undefined;
33
+ getTiddler<T extends Tiddler>(title: string): T | void;
26
34
  /**
27
35
  * Get full list of tiddler titles in the wiki
28
36
  */
29
37
  getTiddlers(): string[];
38
+ deleteTiddler(title: string): void;
39
+ each(callback: (tiddler: Tiddler, title: string) => void): void;
30
40
  /**
31
41
  * Return a named global cache object. Global cache objects are cleared whenever a tiddler change.
32
42
  * You can put anything into the cache.
@@ -39,7 +49,11 @@ declare module 'tiddlywiki' {
39
49
  * @param cacheName key of the cache
40
50
  * @param initializer when cache miss, this will be called to get initial value
41
51
  */
42
- getCacheForTiddler<T>(title: string, cacheName: string, initializer: () => T): T;
52
+ getCacheForTiddler<T>(
53
+ title: string,
54
+ cacheName: string,
55
+ initializer: () => T,
56
+ ): T;
43
57
  /**
44
58
  * clear all cache, will be called when a tiddler is changed
45
59
  */
@@ -47,33 +61,48 @@ declare module 'tiddlywiki' {
47
61
  /**
48
62
  * Compile filter string to be a function that execute the filter in the wiki.
49
63
  * You can pass an optional iterator that provide the input to the returned function. If no iterator is provided, filter will use first operator to get input.
50
- *
64
+ *
51
65
  * @returns a function with the signature fn(source,widget) where:
52
66
  source: an iterator function for the source tiddlers, called source(iterator), where iterator is called as iterator(tiddler,title)
53
67
  widget: an optional widget node for retrieving the current tiddler etc.
54
68
  */
55
- compileFilter(filterString: string): (source?: SourceIterator, widget?: Widget) => string[];
69
+ compileFilter(
70
+ filterString: string,
71
+ ): (source?: SourceIterator, widget?: Widget) => string[];
56
72
  /**
57
73
  *
58
74
  * @param filterString
59
75
  * @param widget an optional widget node for retrieving the current tiddler etc.
60
76
  * @param source an iterator function for the source tiddlers, called source(iterator), where iterator is called as iterator(tiddler,title)
61
77
  */
62
- filterTiddlers(filterString: string, widget?: Widget, source?: SourceIterator): string[];
78
+ filterTiddlers(
79
+ filterString: string,
80
+ widget?: Widget,
81
+ source?: SourceIterator,
82
+ ): string[];
63
83
  /**
64
84
  * Set JSON tiddler, Object in data field will be JSON.stringify and put into the text.
65
85
  * This will make tiddler to be JSON data tiddler `"type":"application/json"`, so if you just want to modify existed tiddler's data, use `addTiddler` instead.
66
86
  */
67
- setTiddlerData: (title: string, data?: object, fields?: ITiddlerFieldsParam, options?: any) => void;
87
+ setTiddlerData(
88
+ title: string,
89
+ data?: object,
90
+ fields?: ITiddlerFieldsParam,
91
+ options?: any,
92
+ ): void;
68
93
  /**
69
94
  * Create or update tiddler.
70
95
  * Update existed tiddler based on the title field.
71
96
  */
72
- addTiddler: (tiddler: Tiddler | Partial<ITiddlerFieldsParam> | Partial<ITiddlerFields>) => void;
97
+ addTiddler(
98
+ tiddler: Tiddler | Partial<ITiddlerFieldsParam> | Partial<ITiddlerFields>,
99
+ ): void;
73
100
  /**
74
101
  * Call `addTiddler` for each iton of the list, but should passing `tiddler.fields`, directly passing tiddler object may failed to add in some cases.
75
102
  */
76
- addTiddlers: (tiddler: Array<Partial<ITiddlerFieldsParam>| Partial<ITiddlerFields>>) => void;
103
+ addTiddlers(
104
+ tiddler: Array<Partial<ITiddlerFieldsParam> | Partial<ITiddlerFields>>,
105
+ ): void;
77
106
  /**
78
107
  * Get tiddler's text field, with an optional default text.
79
108
  * If have _is_skinny field, will just return null (this is a rare case, so not put in the return type for now).
@@ -96,11 +125,13 @@ declare module 'tiddlywiki' {
96
125
 
97
126
  Alternative, uncached version of getTiddlerDataCached(). The return value can be mutated freely and reused
98
127
  */
99
- getTiddlerData<D extends Record<any, unknown> | any[] | undefined>(titleOrTiddler: string, fallbackData?: D): D;
100
- getTiddlerData<D extends Record<any, unknown> | any[] | undefined>(titleOrTiddler: Tiddler, fallbackData?: D): D;
128
+ getTiddlerData<D extends Record<any, unknown> | any[] | undefined>(
129
+ titleOrTiddler: string | Tiddler,
130
+ fallbackData?: D,
131
+ ): D;
101
132
  /**
102
133
  * D is any JSON, like JSON object or JSON array
103
- *
134
+ *
104
135
  * Get the content of a tiddler as a JavaScript object. How this is done depends on the type of the tiddler:
105
136
 
106
137
  application/json: the tiddler JSON is parsed into an object
@@ -113,8 +144,10 @@ declare module 'tiddlywiki' {
113
144
 
114
145
  Note that the same value is returned for repeated calls for the same tiddler data. The value is frozen to prevent modification; otherwise modifications would be visible to all callers
115
146
  */
116
- getTiddlerDataCached<D>(titleOrTiddler: string, fallbackData?: D): D;
117
- getTiddlerDataCached<D>(titleOrTiddler: Tiddler, fallbackData?: D): D;
147
+ getTiddlerDataCached<D>(
148
+ titleOrTiddler: string | Tiddler,
149
+ fallbackData?: D,
150
+ ): D;
118
151
  /**
119
152
  * Set tiddler text of any field.
120
153
  *
@@ -124,7 +157,13 @@ declare module 'tiddlywiki' {
124
157
  * @param {string} value text content to set
125
158
  * @param {object} options options, see tiddlywiki dev doc for details
126
159
  */
127
- setText: (title: string, field?: string, index?: string | undefined, value?: string, options?: { suppressTimestamp?: boolean }) => void;
160
+ setText(
161
+ title: string,
162
+ field?: string,
163
+ index?: string,
164
+ value?: string,
165
+ options?: { suppressTimestamp?: boolean },
166
+ ): void;
128
167
  /**
129
168
  Parse a tiddler according to its MIME type
130
169
  */
@@ -149,7 +188,11 @@ declare module 'tiddlywiki' {
149
188
  variables: hashmap of variables to set
150
189
  parentWidget: optional parent widget for the root node
151
190
  */
152
- renderTiddler(outputType: OutputMimeTypes, title: string, options?: IRenderOptions): string;
191
+ renderTiddler(
192
+ outputType: OutputMimeTypes,
193
+ title: string,
194
+ options?: IRenderOptions,
195
+ ): string;
153
196
  /**
154
197
  Parse text in a specified format and render it into another format
155
198
  @param outputType content type for the output
@@ -159,7 +202,12 @@ declare module 'tiddlywiki' {
159
202
  - variables: hashmap of variables to set
160
203
  - parentWidget: optional parent widget for the root node
161
204
  */
162
- renderText(outputType: OutputMimeTypes, textType: TextMimeTypes, text: string, options?: Partial<IMakeWidgetOptions> & IParserOptions): string;
205
+ renderText(
206
+ outputType: OutputMimeTypes,
207
+ textType: TextMimeTypes,
208
+ text: string,
209
+ options?: Partial<IMakeWidgetOptions> & IParserOptions,
210
+ ): string;
163
211
  /**
164
212
  Make a widget tree for a parse tree
165
213
  @params parser: parser object
@@ -203,7 +251,11 @@ declare module 'tiddlywiki' {
203
251
  tiddlerExists(title: string): boolean;
204
252
  /** Determines if a tiddler is a shadow tiddler, regardless of whether it has been overridden by a real tiddler */
205
253
  isShadowTiddler(title: string): boolean;
254
+ isBinaryTiddler(title: string): boolean;
255
+ isImageTiddler(title: string): boolean;
206
256
  /** return shadowTiddlers[title].source; */
207
257
  getShadowSource(title: string): string | null;
258
+ getTiddlerBacklinks(targetTitle: string): string[];
259
+ getTiddlerLinks(title: string): string[];
208
260
  }
209
261
  }
package/src/ast.d.ts CHANGED
@@ -3,7 +3,13 @@ declare module 'tiddlywiki' {
3
3
  end?: number;
4
4
  name?: string;
5
5
  start?: number;
6
- type: 'string' | 'number' | 'bigint' | 'boolean' | 'macro' | 'macro-parameter';
6
+ type:
7
+ | 'string'
8
+ | 'number'
9
+ | 'bigint'
10
+ | 'boolean'
11
+ | 'macro'
12
+ | 'macro-parameter';
7
13
  value: string | IMacroCallParseTreeNode;
8
14
  }
9
15
 
package/src/modules.d.ts CHANGED
@@ -15,6 +15,7 @@ declare module 'tiddlywiki' {
15
15
  }
16
16
  export interface IModuleSandbox {
17
17
  $tw: ITiddlyWiki;
18
+ // eslint-disable-next-line node/prefer-global/buffer
18
19
  Buffer?: Buffer;
19
20
  clearInterval: typeof clearInterval;
20
21
  clearTimeout: typeof clearTimeout;
@@ -26,7 +27,11 @@ declare module 'tiddlywiki' {
26
27
  setInterval: typeof setInterval;
27
28
  setTimeout: typeof setTimeout;
28
29
  }
29
- export type TWModuleDefinitionFucntion = (moduleInfo: IModuleInfo, exports: ITWModuleExports, requireFunction: ITWRequire) => void;
30
+ export type TWModuleDefinitionFucntion = (
31
+ moduleInfo: IModuleInfo,
32
+ exports: ITWModuleExports,
33
+ requireFunction: ITWRequire,
34
+ ) => void;
30
35
  /**
31
36
  * Information about each module is kept in an object with these members:
32
37
  *
@@ -44,11 +49,21 @@ declare module 'tiddlywiki' {
44
49
  */
45
50
  interface ITWModules {
46
51
  /** Apply the exports of the modules of a particular type to a target object */
47
- applyMethods(moduleType: string, targetObject?: ITWModuleExports): ITWModuleExports;
52
+ applyMethods: (
53
+ moduleType: string,
54
+ targetObject?: ITWModuleExports,
55
+ ) => ITWModuleExports;
48
56
  /** Return a class created from a modules. The module should export the properties to be added to those of the optional base class */
49
- createClassFromModule(moduleExports: ITWModuleExports, baseClass: new () => unknown): ITWModuleExports;
57
+ createClassFromModule: (
58
+ moduleExports: ITWModuleExports,
59
+ baseClass: new () => unknown,
60
+ ) => ITWModuleExports;
50
61
  /** Return an array of classes created from the modules of a specified type. Each module should export the properties to be added to those of the optional base class */
51
- createClassesFromModules(moduleType: string, subType: string | null | undefined, baseClass: new () => unknown): Record<string, ITWModuleExports>;
62
+ createClassesFromModules: (
63
+ moduleType: string,
64
+ subType: string | null | undefined,
65
+ baseClass: new () => unknown,
66
+ ) => Record<string, ITWModuleExports>;
52
67
  /**
53
68
  * Define a JavaScript tiddler module for later execution
54
69
  * @param {string} moduleName name of module being defined
@@ -56,12 +71,16 @@ declare module 'tiddlywiki' {
56
71
  * @param {(string | TWModuleDefinitionFucntion | ITWModuleExports)} definition module definition; see discussion above
57
72
  * @memberof ITWModules
58
73
  */
59
- define(moduleName: string, moduleType: string, definition: string | TWModuleDefinitionFucntion | ITWModuleExports): void;
74
+ define: (
75
+ moduleName: string,
76
+ moduleType: string,
77
+ definition: string | TWModuleDefinitionFucntion | ITWModuleExports,
78
+ ) => void;
60
79
  /**
61
80
  * Execute the module named 'moduleName'. The name can optionally be relative to the module named 'moduleRoot'
62
81
  * @memberof ITWModules
63
82
  */
64
- execute(moduleName: string, moduleRoot: string): ITWModuleExports;
83
+ execute: (moduleName: string, moduleRoot: string) => ITWModuleExports;
65
84
  /**
66
85
  * Apply a callback to each module of a particular type
67
86
  *
@@ -69,9 +88,15 @@ declare module 'tiddlywiki' {
69
88
  * @param {(title, moduleExports) => void} callback function called as callback(title,moduleExports) for each module
70
89
  * @memberof ITWModules
71
90
  */
72
- forEachModuleOfType(moduleType: string, callback: (title: string, moduleExports: unknown) => void): void;
91
+ forEachModuleOfType: (
92
+ moduleType: string,
93
+ callback: (title: string, moduleExports: unknown) => void,
94
+ ) => void;
73
95
  /** Get all the modules of a particular type in a hashmap by their `name` field */
74
- getModulesByTypeAsHashmap(moduleType: string, nameField: string): Record<string, IModuleInfo>;
96
+ getModulesByTypeAsHashmap: (
97
+ moduleType: string,
98
+ nameField: string,
99
+ ) => Record<string, IModuleInfo>;
75
100
  /** hashmap by module name of moduleInfo */
76
101
  titles: Record<string, IModuleInfo>;
77
102
  /** hashmap by module type and then name of moduleInfo */
package/src/parser.d.ts CHANGED
@@ -14,10 +14,15 @@ declare module 'tiddlywiki' {
14
14
 
15
15
  export class WikiParseRule {
16
16
  is: { block?: boolean; inline?: boolean };
17
- match?: null;
17
+
18
+ match?: unknown;
19
+
18
20
  matchRegExp?: RegExp;
21
+
19
22
  parser?: WikiParser;
20
- nextTag?: null;
23
+
24
+ nextTag?: unknown;
25
+
21
26
  /** `{type: 'macrocall', start: 261, params: Array(1), name: 'reuse-tiddler', end: 290}` */
22
27
  nextCall?: {
23
28
  end: number;
@@ -29,15 +34,24 @@ declare module 'tiddlywiki' {
29
34
  };
30
35
  }
31
36
  export class WikiParser {
32
- blockRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
33
- inlineRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
34
- pragmaRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
37
+ blockRules: { matchIndex?: number; rule: WikiParseRule }[];
38
+
39
+ inlineRules: { matchIndex?: number; rule: WikiParseRule }[];
40
+
41
+ pragmaRules: { matchIndex?: number; rule: WikiParseRule }[];
42
+
35
43
  configTrimWhiteSpace: boolean;
44
+
36
45
  pos: number;
46
+
37
47
  source: string;
48
+
38
49
  sourceLength: number;
50
+
39
51
  type: string;
52
+
40
53
  wiki: Wiki;
54
+
41
55
  tree: IParseTreeNode[];
42
56
  }
43
57
  }
package/src/server.d.ts CHANGED
@@ -33,10 +33,8 @@ declare module 'tiddlywiki' {
33
33
  wiki - reference to wiki object
34
34
  */
35
35
  export class Server {
36
- constructor(options: IServerOptions);
37
- routes: IRoute[];
38
- addRoute(route: IRoute): void;
39
36
  /**
37
+ * @example
40
38
  * ```json
41
39
  * {
42
40
  port: "8080",
@@ -71,9 +69,15 @@ declare module 'tiddlywiki' {
71
69
  'use-browser-cache': string;
72
70
  };
73
71
 
72
+ requestHandler: ServerEndpointHandler;
73
+
74
74
  variables: Record<string, any>;
75
+
76
+ routes: IRoute[];
77
+
78
+ constructor(options: IServerOptions);
79
+ addRoute(route: IRoute): void;
75
80
  get(variableName: string): any;
76
- requestHandler: ServerEndpointHandler;
77
81
  /**
78
82
  Listen for requests
79
83
  port: optional port number (falls back to value of "port" variable)
@@ -84,12 +88,18 @@ declare module 'tiddlywiki' {
84
88
 
85
89
  on(eventName: 'error', callback: (error: Error) => void): void;
86
90
  on(eventName: 'listening', callback: () => void): void;
87
- on(eventName: string, callback: (...arguments_: unknown[]) => unknown): void;
91
+ on(
92
+ eventName: string,
93
+ callback: (...arguments_: unknown[]) => unknown,
94
+ ): void;
88
95
 
89
96
  /**
90
97
  Check whether a given user is authorized for the specified authorizationType ("readers" or "writers"). Pass null or undefined as the username to check for anonymous access
91
98
  */
92
- isAuthorized(authorizationType: 'readers' | 'writers', username?: string | undefined): boolean;
99
+ isAuthorized(
100
+ authorizationType: 'readers' | 'writers',
101
+ username?: string | undefined,
102
+ ): boolean;
93
103
  close(): void;
94
104
  }
95
105
 
@@ -103,7 +113,7 @@ declare module 'tiddlywiki' {
103
113
  * @link https://talk.tiddlywiki.org/t/what-is-the-state-in-server-route-handler/2877
104
114
  */
105
115
  export type ServerEndpointHandler<T = Record<string, unknown>> = (
106
- request: Http.ClientRequest,
116
+ request: Http.ClientRequest & Http.InformationEvent,
107
117
  response: Http.ServerResponse,
108
118
  context: ServerEndpointContext & T,
109
119
  ) => void;
package/src/tw.d.ts CHANGED
@@ -31,7 +31,10 @@ declare module 'tiddlywiki' {
31
31
  }
32
32
 
33
33
  export interface ILanguage {
34
- getString(key: string, options: { variables: { title: string } }): string;
34
+ getString: (
35
+ key: string,
36
+ options: { variables: { title: string } },
37
+ ) => string;
35
38
  }
36
39
 
37
40
  export interface IContentTypeInfo {
@@ -41,22 +44,28 @@ declare module 'tiddlywiki' {
41
44
  flags: string[];
42
45
  }
43
46
 
47
+ export interface IStartUpOption {
48
+ bootPath?: string;
49
+ callback?: () => unknown;
50
+ }
51
+
44
52
  export interface ITiddlyWiki {
45
53
  Tiddler: typeof Tiddler;
46
54
  Wiki: typeof Wiki;
47
55
 
48
56
  boot: {
49
57
  argv: string[];
50
- boot(callback?: () => unknown): void;
58
+ boot: (callback?: () => void) => void;
51
59
  files: IBootFilesIndex;
52
- log(logString: string): void;
60
+ log: (logString: string) => void;
53
61
  logMessages: string[];
54
- startup(options: { callback?: () => unknown }): void;
62
+ startup: (options: IStartUpOption) => void;
55
63
  /** Default boot tasks */
56
64
  tasks: {
57
65
  readBrowserTiddlers: boolean;
58
66
  trapErrors: boolean;
59
67
  };
68
+ excludeRegExp: RegExp;
60
69
  };
61
70
 
62
71
  browser: null | {
@@ -112,15 +121,24 @@ declare module 'tiddlywiki' {
112
121
  /**
113
122
  Add hooks to the hashmap
114
123
  */
115
- addHook(hookName: 'th-server-command-post-start', callback: (listenCommand: unknown, server: Server) => void): void;
116
- addHook(hookName: string, callback: (...arguments_: unknown[]) => unknown): void;
124
+ addHook: (
125
+ hookName: 'th-server-command-post-start',
126
+ callback: (listenCommand: unknown, server: Server) => void,
127
+ ) => void;
128
+ addHook: (
129
+ hookName: string,
130
+ callback: (...arguments_: unknown[]) => unknown,
131
+ ) => void;
117
132
  /**
118
133
  Invoke the hook by key
119
134
  */
120
- invokeHook(hookName: string, event: IWidgetEvent): undefined | IWidgetEvent;
135
+ invokeHook: (
136
+ hookName: string,
137
+ event: IWidgetEvent,
138
+ ) => undefined | IWidgetEvent;
121
139
  };
122
140
  /** Determines if a tiddler is a shadow tiddler, regardless of whether it has been overridden by a real tiddler */
123
- isShadowTiddler(title: string): boolean;
141
+ isShadowTiddler: (title: string) => boolean;
124
142
  language: ILanguage;
125
143
  modules: ITWModules;
126
144
 
@@ -131,17 +149,28 @@ declare module 'tiddlywiki' {
131
149
 
132
150
  notifier: Notifier;
133
151
  /** Convenience function for pushing a tiddler onto the preloading array */
134
- preloadTiddler(fields: Record<string, unknown>): void;
152
+ preloadTiddler: (fields: Record<string, unknown>) => void;
135
153
  /** Convenience function for pushing an array of tiddlers onto the preloading array */
136
- preloadTiddlerArray(fieldsArray: Array<Record<string, unknown>>): void;
154
+ preloadTiddlerArray: (fieldsArray: Array<Record<string, unknown>>) => void;
137
155
 
138
156
  /** External JavaScript can populate this array before calling boot.js in order to preload tiddlers */
139
157
  preloadTiddlers: Record<string, Record<string, unknown>>;
140
158
 
159
+ getLibraryItemSearchPaths: (libraryPath: string, envVar?: string) => string;
160
+
161
+ findLibraryItem: (name: string, paths: string[]) => string | null;
162
+
163
+ loadMetadataForFile: (filepath: string) => ITiddlerFields | null;
164
+
165
+ loadPluginFolder: (
166
+ filepath: string,
167
+ excludeRegExp?: RegExp,
168
+ ) => ITiddlerFields | null;
169
+
141
170
  rootWidget: Widget;
142
171
 
143
172
  /** Test for the existence of a tiddler (excludes shadow tiddlers) */
144
- tiddlerExists(title: string): boolean;
173
+ tiddlerExists: (title: string) => boolean;
145
174
  utils: ITWUtils;
146
175
  version: string;
147
176
  wiki: Wiki;
package/src/utils.d.ts CHANGED
@@ -5,9 +5,11 @@ declare module 'tiddlywiki' {
5
5
  export type TWDocument = Document;
6
6
  export type TWDOMElement = Element;
7
7
  /** Callback is invoked with (element, index, object), if callback returns false, then the each loop will be terminated. */
8
- export type TWEachCallback<O, I> =
9
- | ((element?: I, indexOrKey?: string | number, object?: O) => boolean | undefined)
10
- | ((element?: I, indexOrKey?: string | number, object?: O) => void);
8
+ export type TWEachCallback<O, I> = (
9
+ element?: I,
10
+ indexOrKey?: string | number,
11
+ object?: O,
12
+ ) => boolean | void;
11
13
  export interface ITWUtils {
12
14
  Crypto: typeof Crypto;
13
15
  PasswordPrompt: typeof PasswordPrompt;
@@ -17,7 +19,7 @@ declare module 'tiddlywiki' {
17
19
  * @param element
18
20
  * @param className
19
21
  */
20
- addClass(element: Element, className: string): void;
22
+ addClass: (element: Element, className: string) => void;
21
23
  /**
22
24
  Attach specified event handlers to a DOM node
23
25
  @param domNode: where to attach the event handlers
@@ -28,27 +30,38 @@ declare module 'tiddlywiki' {
28
30
  - handlerObject: optional event handler object
29
31
  - handlerMethod: optionally specifies object handler method name (defaults to `handleEvent`)
30
32
  */
31
- addEventListeners(
33
+ addEventListeners: (
32
34
  domNode: Node,
33
- events: Array<{ handlerFunction?: (event: MouseEvent) => void; handlerMethod?: string; handlerObject?: Widget; name: string }>,
34
- ): void;
35
+ events: {
36
+ handlerFunction?: (event: MouseEvent) => void;
37
+ handlerMethod?: string;
38
+ handlerObject?: Widget;
39
+ name: string;
40
+ }[],
41
+ ) => void;
35
42
  /** Returns true if the version string A is greater than the version string B. Returns true if the versions are the same */
36
- checkVersions(versionStringA: string, versionStringB: string): boolean;
43
+ checkVersions: (versionStringA: string, versionStringB: string) => boolean;
37
44
  /**
38
45
  * Returns +1 if the version string A is greater than the version string B, 0 if they are the same, and +1 if B is greater than A.
39
46
  * Missing or malformed version strings are parsed as 0.0.0
40
47
  */
41
- compareVersions(versionStringA: string, versionStringB: string): -1 | 0 | 1;
48
+ compareVersions: (
49
+ versionStringA: string,
50
+ versionStringB: string,
51
+ ) => -1 | 0 | 1;
42
52
  /*
43
53
  Return the number of keys in an object
44
54
  */
45
- count(object: Record<string, any>): number;
55
+ count: (object: Record<string, any>) => number;
46
56
  /** Convert a URIComponent encoded string to a string safely */
47
- decodeURIComponentSafe(uri: string): string;
57
+ decodeURIComponentSafe: (uri: string) => string;
48
58
  /** Convert a URI encoded string to a string safely */
49
- decodeURISafe(uri: string): string;
59
+ decodeURISafe: (uri: string) => string;
50
60
  /** Fill in any null or undefined properties of an object with the properties from a list of source objects. Each property that is an object is called recursively */
51
- deepDefaults(object: object, ...sourceObjectList: object[]): object;
61
+ deepDefaults: (
62
+ origin: Record<string | symbol, unknown>,
63
+ ...defaults: Record<string | symbol, unknown>[]
64
+ ) => Record<string | symbol, unknown>;
52
65
  /**
53
66
  * Helper for making DOM elements
54
67
  * @param {string} tag tag name
@@ -74,7 +87,7 @@ declare module 'tiddlywiki' {
74
87
  * * eventListeners: array of event listeners (this option won't work until `$tw.utils.addEventListeners()` has been loaded)
75
88
  * @returns {Element}
76
89
  */
77
- domMaker(
90
+ domMaker: (
78
91
  tag: string,
79
92
  options: {
80
93
  attributes?: Record<string, unknown>;
@@ -87,49 +100,66 @@ declare module 'tiddlywiki' {
87
100
  style?: Record<string, string>;
88
101
  text?: string;
89
102
  },
90
- ): TWDOMElement;
103
+ ) => TWDOMElement;
91
104
  /**
92
105
  * Iterate through all the own properties of an object or array.
93
106
  * Callback is invoked with (element, index, object), if callback returns false, then the each loop will be terminated.
94
107
  */
95
- each<I = any>(object: Record<string, I> | I[], callback: TWEachCallback<Record<string, I> | I[], I>): void;
108
+ each: <I = any>(
109
+ object: Record<string, I> | I[],
110
+ callback: TWEachCallback<Record<string, I> | I[], I>,
111
+ ) => void;
96
112
  /** Display an error and exit */
97
- error(error: Event | string): void;
113
+ error: (error: Event | string) => void;
98
114
  /** Run code globally with specified context variables in scope */
99
- evalGlobal(code: string, context: IModuleSandbox, filename: string): unknown;
115
+ evalGlobal: (
116
+ code: string,
117
+ context: IModuleSandbox,
118
+ filename: string,
119
+ ) => unknown;
100
120
  /** Run code in a sandbox with only the specified context variables in scope */
101
- evalSandboxed(code: string, context: IModuleSandbox, filename: string): unknown;
121
+ evalSandboxed: (
122
+ code: string,
123
+ context: IModuleSandbox,
124
+ filename: string,
125
+ ) => unknown;
102
126
  /** Extend an object with the properties from a list of source objects */
103
- extend(object: object, ...sourceObjectList: object[]): object;
127
+ extend: (
128
+ origin: Record<string | symbol, unknown>,
129
+ ...sources: Record<string | symbol, unknown>[]
130
+ ) => Record<string | symbol, unknown>;
104
131
  /** the function behind `<<now "format">> */
105
- formatDateString(date: Date, format: string): string;
132
+ formatDateString: (date: Date, format: string) => string;
106
133
  /** Given an extension, always access the $tw.config.fileExtensionInfo using a lowercase extension only. */
107
- getFileExtensionInfo(extension: string): IFileExtensionInfo | null;
134
+ getFileExtensionInfo: (extension: string) => IFileExtensionInfo | null;
108
135
  /** Get the browser location.hash. We don't use location.hash because of the way that Firefox auto-urldecodes it (see http://stackoverflow.com/questions/1703552/encoding-of-window-location-hash) */
109
- getLocationHash(): string;
136
+ getLocationHash: () => string;
110
137
  /** Given an extension, get the correct encoding for that file. defaults to utf8 */
111
- getTypeEncoding(extension: string): string;
138
+ getTypeEncoding: (extension: string) => string;
112
139
  /** Check if an object has a property. */
113
- hop(object: object, property: string): boolean;
140
+ hop: (object: object, property: string) => boolean;
114
141
  /** Convert "&amp;" to &, "&nbsp;" to nbsp, "&lt;" to <, "&gt;" to > and "&quot;" to " */
115
- htmlDecode(text: string): string;
142
+ htmlDecode: (text: string) => string;
116
143
  /** Determine if a value is an array. */
117
- isArray(value: unknown): boolean;
144
+ isArray: (value: unknown) => boolean;
118
145
  /** Check if an array is equal by value and by reference. */
119
- isArrayEqual(array1: unknown[], array2: unknown[]): boolean;
146
+ isArrayEqual: (array1: unknown[], array2: unknown[]) => boolean;
120
147
  /** Determine if a value is a date */
121
- isDate(value: unknown): void;
148
+ isDate: (value: unknown) => void;
122
149
  /** Pad a string to a given length with "0"s. Length defaults to 2 */
123
- pad(value: number, length?: number): string;
150
+ pad: (value: number, length?: number) => string;
124
151
  /** Parse a date from a UTC YYYYMMDDHHMMSSmmm format string */
125
- parseDate(value: string | Date): Date;
152
+ parseDate: (value: string | Date) => Date;
126
153
  /** Parse a block of name:value fields. The `fields` object is used as the basis for the return value */
127
- parseFields(text: string, fields?: object): object;
128
- parseJSONSafe(input: string): any;
154
+ parseFields: (text: string, fields?: object) => object;
155
+ parseJSONSafe: (input: string) => any;
129
156
  /** Parse a string array from a bracketted list. For example "OneTiddler [[Another Tiddler]] LastOne" */
130
- parseStringArray(value: string | string[], allowDuplicate?: boolean): string[];
157
+ parseStringArray: (
158
+ value: string | string[],
159
+ allowDuplicate?: boolean,
160
+ ) => string[];
131
161
  /** Parse a semantic version string into its constituent parts -- see https://semver.org */
132
- parseVersion(version: string): {
162
+ parseVersion: (version: string) => {
133
163
  build?: string;
134
164
  major: number;
135
165
  minor: number;
@@ -142,7 +172,7 @@ declare module 'tiddlywiki' {
142
172
  * * array: array to modify (assumed to be free of duplicates)
143
173
  * * value: a single value to push or an array of values to push
144
174
  */
145
- pushTop(array: unknown[], value: unknown): void;
175
+ pushTop: (array: unknown[], value: unknown) => void;
146
176
  /**
147
177
  * Register file type information
148
178
  * @param {string} contentType
@@ -155,7 +185,7 @@ declare module 'tiddlywiki' {
155
185
  * * flags:"image" for image types
156
186
  * * deserializerType: defaults to type if not specified
157
187
  */
158
- registerFileType(
188
+ registerFileType: (
159
189
  contentType: string,
160
190
  encoding: string,
161
191
  extension: string | string[],
@@ -163,17 +193,31 @@ declare module 'tiddlywiki' {
163
193
  deserializerType?: string;
164
194
  flags?: string[];
165
195
  },
166
- ): void;
196
+ ) => void;
167
197
  /**
168
198
  * Resolves a source filepath delimited with `/` relative to a specified absolute root filepath.
169
199
  * In relative paths, the special folder name `..` refers to immediate parent directory, and the
170
200
  * name `.` refers to the current directory
171
201
  */
172
- resolvePath(sourcepath: string, rootpath: string): string;
202
+ resolvePath: (sourcepath: string, rootpath: string) => string;
173
203
  /** Convert a date into UTC YYYYMMDDHHMMSSmmm format */
174
- stringifyDate(value: Date): string;
204
+ stringifyDate: (value: Date) => string;
175
205
  /** Stringify an array of tiddler titles into a list string */
176
- stringifyList(value: string[]): string;
206
+ stringifyList: (value: string[]) => string;
207
+ generateTiddlerFilepath: (
208
+ title: string,
209
+ options?: {
210
+ directory?: string;
211
+ extension?: string;
212
+ fileInfo?: {
213
+ originalpath?: string;
214
+ filePath?: string;
215
+ writeError?: boolean;
216
+ };
217
+ pathFilters?: string[];
218
+ wiki?: Wiki;
219
+ },
220
+ ) => string;
177
221
  }
178
222
  /**
179
223
  * Notifier mechanism
package/src/widget.d.ts CHANGED
@@ -36,40 +36,65 @@ declare module 'tiddlywiki' {
36
36
  widget: Widget;
37
37
  }
38
38
 
39
- // eslint-disable-next-line @typescript-eslint/no-extraneous-class
39
+ // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-extraneous-class
40
40
  class variablesConstructor {}
41
41
 
42
42
  /**
43
43
  * @link https://tiddlywiki.com/dev/#Widgets
44
44
  */
45
45
  export class Widget {
46
- constructor(parseTreeNode: IParseTreeNode, options?: unknown);
47
- initialize(parseTreeNode: IParseTreeNode, options?: unknown): void;
48
46
  parseTreeNode: IParseTreeNode;
47
+
49
48
  wiki: ITiddlyWiki;
49
+
50
50
  document: IFakeDocument;
51
+
51
52
  parentWidget?: Widget;
53
+
52
54
  /** we can use $tw.rootWidget.widgetClasses.widget to new a widget
53
55
  *
54
56
  * This is a set of all widgets defined in tiddlywiki.
55
57
  */
56
58
  widgetClasses: Record<string, Widget>;
59
+
57
60
  /** we can use $tw.rootWidget.widgetClasses.widget to new a widget
58
61
  *
59
62
  * Like `new widget.widget(widgetNode,{` in `$tw.wiki.makeWidget`
60
63
  */
61
64
  widget: new (parseTreeNode: IParseTreeNode, options?: unknown) => Widget;
65
+
62
66
  children: Widget[];
67
+
68
+ variablesConstructor: variablesConstructor;
69
+
70
+ variables: unknown;
71
+
72
+ domNodes: Node[];
73
+
74
+ parentDomNode: Node;
75
+
76
+ constructor(parseTreeNode: IParseTreeNode, options?: unknown);
77
+ initialize(parseTreeNode: IParseTreeNode, options?: unknown): void;
63
78
  /**
64
79
  Make child widgets correspondng to specified parseTreeNodes
65
80
  And push them to `this.children`
66
81
  @param parseTreeNodes default to `this.parseTreeNode.children`, can be undefined
67
82
  */
68
- makeChildWidgets(parseTreeNodes?: IParseTreeNode[], options?: { variables?: unknown }): void;
83
+ makeChildWidgets(
84
+ parseTreeNodes?: IParseTreeNode[],
85
+ options?: { variables?: unknown },
86
+ ): void;
69
87
  /*
70
88
  Initialise widget properties. These steps are pulled out of the constructor so that we can reuse them in subclasses
71
89
  */
72
- initialise(parseTreeNode: IParseTreeNode, options?: { document?: Document; parentWidget?: Widget; wiki?: ITiddlyWiki }): void;
90
+ initialise(
91
+ parseTreeNode: IParseTreeNode,
92
+ options?: {
93
+ document?: Document;
94
+ parentWidget?: Widget;
95
+ wiki?: ITiddlyWiki;
96
+ },
97
+ ): void;
73
98
  /**
74
99
  * Remove any DOM nodes created by this widget or its children
75
100
  *
@@ -82,14 +107,17 @@ declare module 'tiddlywiki' {
82
107
  options include:
83
108
  variables: optional hashmap of variables to wrap around the widget
84
109
  */
85
- makeChildWidget(parseTreeNode: IParseTreeNode, options?: { variables?: unknown }): Widget;
86
- variablesConstructor: variablesConstructor;
87
- variables: unknown;
88
- domNodes: Node[];
110
+ makeChildWidget(
111
+ parseTreeNode: IParseTreeNode,
112
+ options?: { variables?: unknown },
113
+ ): Widget;
89
114
  /**
90
115
  Add an event listener
91
116
  */
92
- addEventListener(type: string, handler: (event: IWidgetEvent) => void | Promise<void>): void;
117
+ addEventListener(
118
+ type: string,
119
+ handler: (event: IWidgetEvent) => void | Promise<void>,
120
+ ): void;
93
121
  /**
94
122
  Dispatch an event to a widget. If the widget doesn't handle the event then it is also dispatched to the parent widget
95
123
 
@@ -99,15 +127,19 @@ declare module 'tiddlywiki' {
99
127
  /**
100
128
  Add a list of event listeners from an array [{type:,handler:},...]
101
129
  */
102
- addEventListeners(listeners: Array<{ handler: (event: IWidgetEvent) => void | Promise<void>; type: string }>): void;
130
+ addEventListeners(
131
+ listeners: Array<{
132
+ handler: (event: IWidgetEvent) => void | Promise<void>;
133
+ type: string;
134
+ }>,
135
+ ): void;
103
136
 
104
- parentDomNode: Node;
105
137
  /**
106
138
  Compute the internal state of the widget.
107
139
  This will be automatically called in the `render` method.
108
140
 
109
141
  For example, `getAttribute` and set them to class members.
110
-
142
+
111
143
  */
112
144
  execute(): void;
113
145
  /**
@@ -126,7 +158,10 @@ declare module 'tiddlywiki' {
126
158
  * @param event
127
159
  * @returns handled
128
160
  */
129
- invokeAction(triggeringWidget: Widget, event: IWidgetEvent): boolean | undefined;
161
+ invokeAction(
162
+ triggeringWidget: Widget,
163
+ event: IWidgetEvent,
164
+ ): boolean | undefined;
130
165
 
131
166
  /**
132
167
  * Lifecycle method: Render this widget into the DOM
@@ -146,8 +181,10 @@ declare module 'tiddlywiki' {
146
181
  /**
147
182
  Refresh all the children of a widget
148
183
  will call `this.render`
184
+
185
+ Need to call this after `setVariable`
149
186
  */
150
- refreshChildren(changedTiddlers: IChangedTiddlers): boolean;
187
+ refreshChildren(changedTiddlers?: IChangedTiddlers): boolean;
151
188
  /**
152
189
  * Rebuild a previously rendered widget
153
190
  */
@@ -173,7 +210,7 @@ declare module 'tiddlywiki' {
173
210
  * Simplified version of getVariableInfo() that just returns the text.
174
211
  * @param name variable name, for example, `currentTiddler` in the widget context
175
212
  * @param options options for getVariableInfo()
176
- *
213
+ *
177
214
  * Options include
178
215
  params: array of {name:, value:} for each parameter
179
216
  defaultValue: default value if the variable is not defined
@@ -184,6 +221,20 @@ declare module 'tiddlywiki' {
184
221
  text: text of variable, with parameters properly substituted
185
222
  */
186
223
  getVariable(name: string, options?: object): string;
224
+ /**
225
+ Set the value of a context variable
226
+
227
+ @param name name of the variable
228
+ @param value value of the variable
229
+ @param params array of {name:, default:} for each parameter
230
+ @param isMacroDefinition true if the variable is set via a \define macro pragma (and hence should have variable substitution performed)
231
+ */
232
+ setVariable(
233
+ name: string,
234
+ value: string,
235
+ parameters?: object[],
236
+ isMacroDefinition?: boolean,
237
+ ): void;
187
238
  }
188
239
 
189
240
  export interface IFakeDocument {
@@ -194,6 +245,7 @@ declare module 'tiddlywiki' {
194
245
  isTiddlyWikiFakeDom: boolean;
195
246
  setSequenceNumber: (value: any) => void;
196
247
  }
248
+ // eslint-disable-next-line @typescript-eslint/naming-convention
197
249
  export interface TW_Element extends HTMLElement {
198
250
  _style: Record<string, unknown>;
199
251
  appendChild: <T extends TW_Element | TW_TextNode | Node>(node: T) => T;
@@ -202,13 +254,13 @@ declare module 'tiddlywiki' {
202
254
  namespaceURI: string;
203
255
  tag: string;
204
256
  }
257
+ // eslint-disable-next-line @typescript-eslint/naming-convention
205
258
  export interface TW_TextNode extends Node {
206
259
  textContent: string;
207
260
  }
208
261
 
209
- export interface ModalWidget {
210
- new (wiki: Wiki): ModalWidget;
211
- adjustPageClass(): void;
262
+ export type ModalWidget = {
263
+ adjustPageClass: () => void;
212
264
  /**
213
265
  *
214
266
  * @param title
@@ -216,6 +268,15 @@ declare module 'tiddlywiki' {
216
268
  * variables: optional hashmap of variables to wrap around the widget
217
269
  * downloadLink: normally is used for "Right-click to save changes"
218
270
  */
219
- display(title: string, options?: { downloadLink?: string; event?: IWidgetEvent; variables?: unknown }): void;
220
- }
271
+ display: (
272
+ title: string,
273
+ options?: {
274
+ downloadLink?: string;
275
+ event?: IWidgetEvent;
276
+ variables?: unknown;
277
+ },
278
+ ) => void;
279
+
280
+ new (wiki: Wiki): ModalWidget;
281
+ };
221
282
  }