tw5-typed 0.6.7 → 0.6.8

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tw5-typed",
3
- "version": "0.6.7",
3
+ "version": "0.6.8",
4
4
  "scripts": {
5
5
  "check": "tsc --noEmit && eslint src/**/*.ts",
6
6
  "docs": "docs-ts",
package/src/core.d.ts CHANGED
@@ -42,7 +42,11 @@ declare module 'tiddlywiki' {
42
42
  Syncer: new() => Syncer;
43
43
  Tiddler: typeof Tiddler;
44
44
  Wiki: typeof Wiki;
45
- addUnloadTask(task: any);
45
+ /**
46
+ * Add another unload task
47
+ * @param task - Function to be called on unload
48
+ */
49
+ addUnloadTask(task: any): void;
46
50
  boot: IBoot;
47
51
 
48
52
  browser: null | {
@@ -110,33 +114,89 @@ declare module 'tiddlywiki' {
110
114
  hooks: IHooks;
111
115
  keyboardManager: KeyboardManager;
112
116
  language: ILanguage;
117
+ /**
118
+ * Load the metadata fields in the .meta file corresponding to a particular file
119
+ * @param filepath - The path to the file
120
+ * @returns The metadata fields or null if no .meta file exists
121
+ */
113
122
  loadMetadataForFile(filepath: string): ITiddlerFields | null;
123
+ /**
124
+ * Load a plugin by name from the given search paths
125
+ * @param name - Name of the plugin (e.g., "tiddlywiki/filesystemadaptor")
126
+ * @param paths - Array of file paths to search for it
127
+ */
114
128
  loadPlugin(name: string, paths: string[]): void;
129
+ /**
130
+ * Load the tiddlers from a plugin folder, and package them up into a proper JSON plugin tiddler
131
+ * @param filepath - Path to the plugin folder
132
+ * @param excludeRegExp - Optional regex for files to exclude
133
+ * @returns Plugin info object or null if not a valid plugin
134
+ */
115
135
  loadPluginFolder(
116
136
  filepath: string,
117
137
  excludeRegExp?: RegExp,
118
138
  ): IPluginInfo | null;
139
+ /**
140
+ * Load multiple plugins
141
+ * @param plugins - Array of plugin names (e.g., ["tiddlywiki/filesystemadaptor"])
142
+ * @param libraryPath - Path of library folder for these plugins (relative to core path)
143
+ * @param environmentVariable - Environment variable name for these plugins
144
+ */
119
145
  loadPlugins(plugins: string[], libraryPath: string, environmentVariable?: string): void;
146
+ /**
147
+ * Load tiddlers in browser environment
148
+ */
120
149
  loadTiddlersBrowser(): void;
150
+ /**
151
+ * Load the tiddlers contained in a particular file (and optionally extract fields from the accompanying .meta file)
152
+ * @param filepath - The path to the file to load
153
+ * @param defaultFields - Optional default fields to apply to loaded tiddlers
154
+ * @returns Object containing filepath, type, tiddlers array, and hasMetaFile flag
155
+ */
121
156
  loadTiddlersFromFile(
122
157
  filepath: string,
123
158
  defaultFields?: Record<string, unknown>,
124
159
  ): ITiddlersInFile;
160
+ /**
161
+ * Load all the tiddlers recursively from a directory, including honouring `tiddlywiki.files` files for drawing in external files
162
+ * @param filepath - The path to load from
163
+ * @param excludeRegExp - Optional regex for files to exclude
164
+ * @returns Array of objects containing filepath, type, tiddlers array, and hasMetaFile flag
165
+ * @description Note that no file information is returned for externally loaded tiddlers, just the `tiddlers` property.
166
+ */
125
167
  loadTiddlersFromPath(
126
168
  filepath: string,
127
169
  excludeRegExp?: RegExp,
128
- ): ITiddlerFields[];
170
+ ): ITiddlersInFile[];
171
+ /**
172
+ * Load all the tiddlers defined by a `tiddlywiki.files` specification file
173
+ * @param filepath - Pathname of the directory containing the specification file
174
+ * @param excludeRegExp - Optional regex for files to exclude
175
+ * @returns Array of objects containing filepath, type, tiddlers array, and hasMetaFile flag
176
+ */
129
177
  loadTiddlersFromSpecification(
130
178
  filepath: string,
131
179
  excludeRegExp?: RegExp,
132
- ): ITiddlerFields[];
180
+ ): ITiddlersInFile[];
133
181
 
182
+ /**
183
+ * Load tiddlers in Node.js environment
184
+ * @description Load boot tiddlers, core tiddlers, extra plugins, and wiki tiddlers
185
+ */
134
186
  loadTiddlersNode(): void;
135
187
 
188
+ /**
189
+ * Load wiki tiddlers from a wiki directory
190
+ * @param wikiPath - Path to the wiki directory
191
+ * @param options - Options for loading
192
+ * @param options.parentPaths - Array of parent paths that we mustn't recurse into
193
+ * @param options.readOnly - True if the tiddler file paths should not be retained
194
+ * @returns Wiki info object or null if no tiddlywiki.info file exists
195
+ */
136
196
  loadWikiTiddlers(
137
197
  wikiPath: string,
138
- options?: { parentPaths?: string; readOnly?: boolean },
139
- ): IWikiInfo;
198
+ options?: { parentPaths?: string[]; readOnly?: boolean },
199
+ ): IWikiInfo | null;
140
200
 
141
201
  locationHash: string;
142
202
 
@@ -168,13 +168,24 @@ declare module 'tiddlywiki' {
168
168
  * @param {string } name name of the variable
169
169
  * @param {string} value value of the variable
170
170
  * @param {IWidgetVariableParam[]} [params=[]] array of `{name: string, default: string}` for each parameter
171
- * @param {boolean} [isMacroDefinition=true] true if the variable is set via a \define macro pragma (and hence should have variable substitution performed)
171
+ * @param {boolean} [isMacroDefinition=false] true if the variable is set via a \define macro pragma (and hence should have variable substitution performed)
172
+ * @param {object} [options] Additional options
173
+ * @param {boolean} [options.isProcedureDefinition] true if the variable is set via a \procedure pragma
174
+ * @param {boolean} [options.isFunctionDefinition] true if the variable is set via a \function pragma
175
+ * @param {boolean} [options.isWidgetDefinition] true if the variable is set via a \widget pragma
176
+ * @param {boolean} [options.configTrimWhiteSpace] whether to trim whitespace
172
177
  */
173
178
  setVariable(
174
179
  name: string,
175
180
  value: string,
176
181
  parameters?: IWidgetVariableParameter[],
177
182
  isMacroDefinition?: boolean,
183
+ options?: {
184
+ configTrimWhiteSpace?: boolean;
185
+ isFunctionDefinition?: boolean;
186
+ isProcedureDefinition?: boolean;
187
+ isWidgetDefinition?: boolean;
188
+ },
178
189
  ): void;
179
190
 
180
191
  /**
@@ -254,10 +265,14 @@ declare module 'tiddlywiki' {
254
265
  * @zh
255
266
  * 计算微件的属性的当前值。返回一个已经改变的属性名称的哈希图
256
267
  *
268
+ * @param {object} [options] Options
269
+ * @param {Function} [options.filterFn] only include attributes where filterFn(name) returns true
257
270
  * @return Object with keys of the names of the attributes that have changed
258
271
  * @memberof Widget
259
272
  */
260
- computeAttributes(): Record<string, true>;
273
+ computeAttributes(options?: {
274
+ filterFn?: (name: string) => boolean;
275
+ }): Record<string, true>;
261
276
 
262
277
  computeAttribute(attribute: string): string;
263
278
 
@@ -302,9 +317,15 @@ declare module 'tiddlywiki' {
302
317
  * Assign the computed attributes of the widget to a domNode
303
318
  * options include:
304
319
  * * `excludeEventAttributes`: ignores attributes whose name begins with "on"
320
+ * * `sourcePrefix`: prefix of attributes that are to be directly assigned (defaults to the empty string)
321
+ * * `destPrefix`: prefix to be applied to attribute names that are to be directly assigned (defaults to the empty string)
322
+ * * `changedAttributes`: hashmap by attribute name of attributes to process (if missing, process all attributes)
305
323
  * @zh
306
324
  * 将微件的计算属性分配给一个 domNode, 选项包括:
307
325
  * * `excludeEventAttributes`: 忽略名称以 "on "开头的属性
326
+ * * `sourcePrefix`: 要直接分配的属性的前缀(默认为空字符串)
327
+ * * `destPrefix`: 要应用到直接分配的属性名称的前缀(默认为空字符串)
328
+ * * `changedAttributes`: 按属性名称的哈希图,要处理的属性(如果缺失,处理所有属性)
308
329
  * 一些特殊的属性:
309
330
  * * `xlink:<xlink-name>`
310
331
  * * `style.<css-style-name>`
@@ -315,7 +336,12 @@ declare module 'tiddlywiki' {
315
336
  */
316
337
  assignAttributes(
317
338
  domNode: Element,
318
- options?: { excludeEventAttributes?: boolean },
339
+ options?: {
340
+ changedAttributes?: Record<string, string>;
341
+ destPrefix?: string;
342
+ excludeEventAttributes?: boolean;
343
+ sourcePrefix?: string;
344
+ },
319
345
  );
320
346
 
321
347
  /**
@@ -392,6 +418,14 @@ declare module 'tiddlywiki' {
392
418
  handler: (event: IWidgetEvent) => undefined | Promise<void> | boolean,
393
419
  ): void;
394
420
 
421
+ /**
422
+ * Remove an event listener
423
+ */
424
+ removeEventListener(
425
+ type: string,
426
+ handler: (event: IWidgetEvent) => undefined | Promise<void> | boolean,
427
+ ): void;
428
+
395
429
  /**
396
430
  * Dispatch an event to a widget. If the widget doesn't handle the event then it is also dispatched to the parent widget
397
431
  * Events added via `addEventListener`, like `tm-notify`, can be invoked by this.
@@ -479,12 +513,65 @@ declare module 'tiddlywiki' {
479
513
  variables?: Record<string, string>,
480
514
  ): boolean;
481
515
 
516
+ /**
517
+ * @en
518
+ * Execute action tiddlers by tag
519
+ * @zh
520
+ * 按标签执行 action tiddlers
521
+ *
522
+ * @param {string} tag The tag to filter action tiddlers
523
+ * @param {IWidgetEvent} event The widget event
524
+ * @param {Record<string, string>} variables Optional variables to pass to the action string
525
+ * @memberof Widget
526
+ */
527
+ invokeActionsByTag(
528
+ tag: string,
529
+ event?: IWidgetEvent | null,
530
+ variables?: Record<string, string>,
531
+ ): void;
532
+
533
+ /**
534
+ * @en
535
+ * Find child `<$data>` widgets recursively. The tag name allows aliased versions of the widget to be found too
536
+ * @zh
537
+ * 递归查找子 `<$data>` widgets。标签名称允许查找该 widget 的别名版本
538
+ *
539
+ * @param {Widget[]} children The children widgets to search
540
+ * @param {string} tag The tag name to search for (e.g., "$data")
541
+ * @param {Function} callback Callback function called for each found widget
542
+ * @memberof Widget
543
+ */
544
+ findChildrenDataWidgets(
545
+ children: Widget[],
546
+ tag: string,
547
+ callback: (widget: Widget) => void,
548
+ ): void;
549
+
482
550
  removeLocalDomNodes(): void;
483
551
 
484
552
  /**
485
553
  * Make a fake widget with specified variables, suitable for variable lookup in filters
486
554
  */
487
555
  makeFakeWidgetWithVariables(variables: Record<string, string>): Widget;
556
+
557
+ /**
558
+ * @en
559
+ * Evaluate a variable with parameters. This is a static convenience method that attempts to evaluate a variable as a function, returning an array of strings
560
+ * @zh
561
+ * 使用参数评估变量。这是一个静态便捷方法,尝试将变量作为函数评估,返回字符串数组
562
+ *
563
+ * @param {Widget} widget The widget context for variable lookup
564
+ * @param {string} name The variable name to evaluate
565
+ * @param {IGetWidgetVariableOptions} options Options for variable evaluation
566
+ * @returns {string[]} Array of result strings
567
+ * @static
568
+ * @memberof Widget
569
+ */
570
+ static evaluateVariable(
571
+ widget: Widget,
572
+ name: string,
573
+ options?: IGetWidgetVariableOptions,
574
+ ): string[];
488
575
  }
489
576
  }
490
577