tw5-typed 0.2.5 → 0.2.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
@@ -2,7 +2,7 @@
2
2
  "description": "Types for tiddlywiki",
3
3
  "license": "MIT",
4
4
  "name": "tw5-typed",
5
- "version": "0.2.5",
5
+ "version": "0.2.8",
6
6
  "url": "https://github.com/tiddly-gittly/tw5-typed",
7
7
  "homepage": "https://github.com/tiddly-gittly/tw5-typed",
8
8
  "bugs": {
@@ -20,28 +20,28 @@
20
20
  "prepublishOnly": "npx tsc --noEmit"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/node": "^17.0.24",
24
- "@typescript-eslint/eslint-plugin": "5.19.0",
25
- "@typescript-eslint/parser": "5.19.0",
26
- "eslint": "8.13.0",
23
+ "@types/node": "^17.0.31",
24
+ "@typescript-eslint/eslint-plugin": "5.22.0",
25
+ "@typescript-eslint/parser": "5.22.0",
26
+ "eslint": "8.15.0",
27
27
  "eslint-config-prettier": "8.5.0",
28
- "eslint-config-standard": "16.0.3",
28
+ "eslint-config-standard": "17.0.0",
29
29
  "eslint-config-standard-with-typescript": "21.0.1",
30
30
  "eslint-import-resolver-alias": "1.1.2",
31
31
  "eslint-import-resolver-typescript": "2.7.1",
32
32
  "eslint-plugin-html": "6.2.0",
33
33
  "eslint-plugin-import": "2.26.0",
34
- "eslint-plugin-n": "15.1.0",
34
+ "eslint-plugin-n": "15.2.0",
35
35
  "eslint-plugin-node": "11.1.0",
36
36
  "eslint-plugin-prettier": "4.0.0",
37
37
  "eslint-plugin-promise": "6.0.0",
38
38
  "eslint-plugin-react": "7.29.4",
39
- "eslint-plugin-react-hooks": "4.4.0",
40
- "eslint-plugin-security": "1.4.0",
39
+ "eslint-plugin-react-hooks": "4.5.0",
40
+ "eslint-plugin-security": "1.5.0",
41
41
  "eslint-plugin-security-node": "1.1.1",
42
42
  "eslint-plugin-typescript-sort-keys": "2.1.0",
43
43
  "eslint-plugin-unicorn": "42.0.0",
44
44
  "prettier": "2.6.2",
45
- "typescript": "4.6.3"
45
+ "typescript": "4.6.4"
46
46
  }
47
47
  }
package/src/Wiki.d.ts CHANGED
@@ -25,12 +25,40 @@ declare module 'tiddlywiki' {
25
25
  /**
26
26
  * Get full list of tiddler titles in the wiki
27
27
  */
28
- getTiddlers: () => string[];
28
+ getTiddlers(): string[];
29
+ /**
30
+ * Return a named global cache object. Global cache objects are cleared whenever a tiddler change.
31
+ * You can put anything into the cache.
32
+ * @param cacheName key of the cache
33
+ * @param initializer when cache miss, this will be called to get initial value
34
+ */
35
+ getGlobalCache<T>(cacheName: string, initializer: () => T): T;
36
+ /**
37
+ * Return the named cache object for a tiddler. If the cache doesn't exist then the initializer function is invoked to create it
38
+ * @param cacheName key of the cache
39
+ * @param initializer when cache miss, this will be called to get initial value
40
+ */
41
+ getCacheForTiddler<T>(title: string, cacheName: string, initializer: () => T): T;
42
+ /**
43
+ * clear all cache, will be called when a tiddler is changed
44
+ */
45
+ clearGlobalCache(): void;
29
46
  /**
30
47
  * Compile filter string to be a function that execute the filter in the wiki.
31
48
  * 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.
49
+ *
50
+ * @returns a function with the signature fn(source,widget) where:
51
+ source: an iterator function for the source tiddlers, called source(iterator), where iterator is called as iterator(tiddler,title)
52
+ widget: an optional widget node for retrieving the current tiddler etc.
53
+ */
54
+ compileFilter(filterString: string): (source?: SourceIterator, widget?: Widget) => string[];
55
+ /**
56
+ *
57
+ * @param filterString
58
+ * @param widget an optional widget node for retrieving the current tiddler etc.
59
+ * @param source an iterator function for the source tiddlers, called source(iterator), where iterator is called as iterator(tiddler,title)
32
60
  */
33
- compileFilter: (filterString: string) => (iterator?: SourceIterator) => string[];
61
+ filterTiddlers(filterString: string, widget?: Widget, source?: SourceIterator): string[];
34
62
  /**
35
63
  * Set JSON tiddler, Object in data field will be JSON.stringify and put into the text.
36
64
  * 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.
@@ -94,7 +122,20 @@ declare module 'tiddlywiki' {
94
122
  * @param {object} options options, see tiddlywiki dev doc for details
95
123
  */
96
124
  setText: (title: string, field?: string, index?: string | undefined, value?: string, options?: { suppressTimestamp?: boolean }) => void;
125
+ /**
126
+ Parse a tiddler according to its MIME type
127
+ */
97
128
  parseTiddler(title: string, options?: IParserOptions): WikiParser;
129
+ /**
130
+ Parse a block of text of a specified MIME type
131
+ @param {string} type: content type of text to be parsed
132
+ @param {string} text: text
133
+ @param {object}options: see below
134
+
135
+ Options include:
136
+ - parseAsInline: if true, the text of the tiddler will be parsed as an inline run
137
+ - _canonical_uri: optional string of the canonical URI of this content
138
+ */
98
139
  parseText(type: string, text: string, options?: IParserOptions): WikiParser;
99
140
  /**
100
141
  Parse text from a tiddler and render it into another format
@@ -106,6 +147,16 @@ declare module 'tiddlywiki' {
106
147
  parentWidget: optional parent widget for the root node
107
148
  */
108
149
  renderTiddler(outputType: OutputMimeTypes, title: string, options?: IRenderOptions): string;
150
+ /**
151
+ Parse text in a specified format and render it into another format
152
+ @param outputType content type for the output
153
+ @param textType content type of the input text
154
+ @param text input text
155
+ @param options see below, Options includes:
156
+ - variables: hashmap of variables to set
157
+ - parentWidget: optional parent widget for the root node
158
+ */
159
+ renderText(outputType: OutputMimeTypes, textType: TextMimeTypes, text: string, options?: Partial<IMakeWidgetOptions> & IParserOptions): string;
109
160
  /**
110
161
  Make a widget tree for a parse tree
111
162
  @params parser: parser object
@@ -115,17 +166,6 @@ declare module 'tiddlywiki' {
115
166
  variables: hashmap of variables to set
116
167
  parentWidget: optional parent widget for the root node
117
168
  */
118
- /**
119
- Parse text in a specified format and render it into another format
120
- outputType: content type for the output
121
- textType: content type of the input text
122
- text: input text
123
- options: see below
124
- Options include:
125
- variables: hashmap of variables to set
126
- parentWidget: optional parent widget for the root node
127
- */
128
- renderText(outputType: OutputMimeTypes, textType: TextMimeTypes, text: string, options?: Partial<IMakeWidgetOptions> & IParserOptions): string;
129
169
  makeWidget(parser: WikiParser, options?: IMakeWidgetOptions): Widget;
130
170
  /**
131
171
  Make a widget tree for transclusion
package/src/ast.d.ts CHANGED
@@ -3,7 +3,7 @@ declare module 'tiddlywiki' {
3
3
  end?: number;
4
4
  name?: string;
5
5
  start?: number;
6
- type: 'string' | 'number';
6
+ type: 'string' | 'number' | 'bigint' | 'boolean' | 'symbol' | 'undefined' | 'object' | 'function';
7
7
  value: string;
8
8
  }
9
9
 
@@ -22,9 +22,18 @@ declare module 'tiddlywiki' {
22
22
  type: 'text';
23
23
  }
24
24
  export interface ILinkParseTreeNode extends IWikiASTNode {
25
- text: string;
25
+ text?: string;
26
26
  type: 'link';
27
27
  }
28
+ export interface IImageParseTreeNode extends IWikiASTNode {
29
+ type: 'image';
30
+ }
31
+ export interface ITranscludeParseTreeNode extends IWikiASTNode {
32
+ type: 'transclude';
33
+ }
34
+ export interface ITiddlerParseTreeNode extends IWikiASTNode {
35
+ type: 'tiddler';
36
+ }
28
37
  export type HTMLTags = keyof HTMLElementTagNameMap | 'strike';
29
38
 
30
39
  export interface IDomParseTreeNode extends IWikiASTNode {
@@ -33,19 +42,15 @@ declare module 'tiddlywiki' {
33
42
  }
34
43
  export interface ICodeBlockParseTreeNode extends IWikiASTNode {
35
44
  attributes: {
36
- code?:
37
- | {
38
- type: 'string';
39
- value: string;
40
- }
41
- | undefined;
42
- language?:
43
- | {
44
- type: 'string';
45
- value: string;
46
- }
47
- | undefined;
48
- };
45
+ code?: {
46
+ type: 'string';
47
+ value: string;
48
+ };
49
+ language?: {
50
+ type: 'string';
51
+ value: string;
52
+ };
53
+ } & IWikiASTNode['attributes'];
49
54
  type: 'codeblock';
50
55
  }
51
56
  export interface IMacroParameterCallParseTreeNode extends IWikiASTNode {
@@ -64,5 +69,15 @@ declare module 'tiddlywiki' {
64
69
  text?: string;
65
70
  type: string;
66
71
  }
67
- export type IParseTreeNode = IDomParseTreeNode | IMacroParameterCallParseTreeNode | IMacroCallParseTreeNode | ITextParseTreeNode | ICustomParseTreeNode;
72
+ export type IParseTreeNode =
73
+ | IDomParseTreeNode
74
+ | IMacroParameterCallParseTreeNode
75
+ | IMacroCallParseTreeNode
76
+ | ITextParseTreeNode
77
+ | IImageParseTreeNode
78
+ | ITranscludeParseTreeNode
79
+ | ITiddlerParseTreeNode
80
+ | ICodeBlockParseTreeNode
81
+ | ILinkParseTreeNode
82
+ | ICustomParseTreeNode;
68
83
  }
package/src/server.d.ts CHANGED
@@ -81,6 +81,11 @@ declare module 'tiddlywiki' {
81
81
  prefix: optional prefix (falls back to value of "path-prefix" variable)
82
82
  */
83
83
  listen(port?: string, host?: string, prefix?: string): void;
84
+
85
+ on(eventName: 'error', callback: (error: Error) => void): void;
86
+ on(eventName: 'listening', callback: () => void): void;
87
+ on(eventName: string, callback: (...arguments_: unknown[]) => unknown): void;
88
+
84
89
  /**
85
90
  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
86
91
  */
package/src/tw.d.ts CHANGED
@@ -30,6 +30,10 @@ declare module 'tiddlywiki' {
30
30
  type: string;
31
31
  }
32
32
 
33
+ export interface ILanguage {
34
+ getString(key: string, options: { variables: { title: string } }): string;
35
+ }
36
+
33
37
  export interface IContentTypeInfo {
34
38
  deserializerType: string;
35
39
  encoding: string;
@@ -59,6 +63,12 @@ declare module 'tiddlywiki' {
59
63
 
60
64
  config: ITWConfig;
61
65
 
66
+ /**
67
+ * 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.
68
+ * Used by `DropZoneWidget.prototype.handleDropEvent`
69
+ */
70
+ dragInProgress?: boolean;
71
+
62
72
  /**
63
73
  Global Hooks mechanism which allows plugins to modify default functionality
64
74
  */
@@ -71,10 +81,13 @@ declare module 'tiddlywiki' {
71
81
  /**
72
82
  Invoke the hook by key
73
83
  */
74
- invokeHook(hookName: string): void;
84
+ invokeHook(hookName: string, event: IWidgetEvent): undefined | IWidgetEvent;
75
85
  };
76
-
86
+ /** Determines if a tiddler is a shadow tiddler, regardless of whether it has been overridden by a real tiddler */
87
+ isShadowTiddler(title: string): boolean;
88
+ language: ILanguage;
77
89
  modules: ITWModules;
90
+
78
91
  /** NodeJS features, if tw isn't running on a NodeJS environment, the value will be `null` */
79
92
  node: null | object;
80
93
  /** Broswer features, if tw isn't running on a browser environment, the value will be `null` */
@@ -91,6 +104,8 @@ declare module 'tiddlywiki' {
91
104
 
92
105
  rootWidget: Widget;
93
106
 
107
+ /** Test for the existence of a tiddler (excludes shadow tiddlers) */
108
+ tiddlerExists(title: string): boolean;
94
109
  utils: ITWUtils;
95
110
  version: string;
96
111
  wiki: Wiki;
package/src/utils.d.ts CHANGED
@@ -4,7 +4,10 @@
4
4
  declare module 'tiddlywiki' {
5
5
  export type TWDocument = Document;
6
6
  export type TWDOMElement = Element;
7
- export type TWEachCallback<T> = (element?: unknown, index?: string | number, object?: T) => boolean | undefined;
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
11
  export interface ITWUtils {
9
12
  Crypto: typeof Crypto;
10
13
  PasswordPrompt: typeof PasswordPrompt;
@@ -85,7 +88,7 @@ declare module 'tiddlywiki' {
85
88
  * Iterate through all the own properties of an object or array.
86
89
  * Callback is invoked with (element, index, object), if callback returns false, then the each loop will be terminated.
87
90
  */
88
- each<T = object | unknown[]>(object: T, callback: TWEachCallback<T>): void;
91
+ each<I = any>(object: Record<string, I> | I[], callback: TWEachCallback<Record<string, I> | I[], I>): void;
89
92
  /** Display an error and exit */
90
93
  error(error: Event | string): void;
91
94
  /** Run code globally with specified context variables in scope */
package/src/widget.d.ts CHANGED
@@ -9,8 +9,9 @@ declare module 'tiddlywiki' {
9
9
  }
10
10
 
11
11
  export interface IWidgetEvent {
12
+ [extraKeys: string]: unknown;
12
13
  /** maybe a DOM click event, if trigger by button click */
13
- event: Event;
14
+ event: UIEvent | Event;
14
15
  navigateFromTitle?: string;
15
16
  /**
16
17
  * Get `$param`
@@ -23,6 +24,7 @@ declare module 'tiddlywiki' {
23
24
  paramObject?: {
24
25
  [othersParamKeys: string]: unknown;
25
26
  };
27
+ tiddlerTitle?: string;
26
28
  /** the first parameter of addEventListener
27
29
  *
28
30
  * For example, the `'open-command-palette'` in `$tw.rootWidget.addEventListener('open-command-palette', (e: IWidgetEvent) => this.openPalette(e));`
@@ -39,21 +41,30 @@ declare module 'tiddlywiki' {
39
41
  */
40
42
  export class Widget {
41
43
  constructor(parseTreeNode: IParseTreeNode, options?: unknown);
42
- initialize: (parseTreeNode: IParseTreeNode, options?: unknown) => void;
44
+ initialize(parseTreeNode: IParseTreeNode, options?: unknown): void;
43
45
  parseTreeNode: IParseTreeNode;
44
46
  wiki: ITiddlyWiki;
45
47
  parentWidget?: Widget;
48
+ /** we can use $tw.rootWidget.widgetClasses.widget to new a widget */
49
+ widgetClasses: Widget;
50
+ /** we can use $tw.rootWidget.widgetClasses.widget to new a widget
51
+ *
52
+ * Like `new widget.widget(widgetNode,{` in `$tw.wiki.makeWidget`
53
+ */
54
+ widget: new (parseTreeNode: IParseTreeNode, options?: unknown) => Widget;
46
55
  children: Widget[];
47
- /*
48
- Make child widgets correspondng to specified parseTreeNodes
49
- */
50
- makeChildWidgets(parseTreeNodes: IParseTreeNode[], options?: { variables?: unknown }): void;
51
56
  /**
52
- Construct the widget object for a parse tree node
57
+ Make child widgets correspondng to specified parseTreeNodes
58
+ And push them to `this.children`
59
+ @param parseTreeNodes default to `this.parseTreeNode.children`, can be undefined
60
+ */
61
+ makeChildWidgets(parseTreeNodes?: IParseTreeNode[], options?: { variables?: unknown }): void;
62
+ /**
63
+ Construct the widget object for a parse tree node, and return the new widget
53
64
  options include:
54
65
  variables: optional hashmap of variables to wrap around the widget
55
66
  */
56
- makeChildWidget(parseTreeNode: IParseTreeNode, options?: { variables?: unknown }): void;
67
+ makeChildWidget(parseTreeNode: IParseTreeNode, options?: { variables?: unknown }): Widget;
57
68
  variablesConstructor: variablesConstructor;
58
69
  variables: unknown;
59
70
  domNodes: Node[];
@@ -71,12 +82,23 @@ Make child widgets correspondng to specified parseTreeNodes
71
82
  addEventListeners(listeners: Array<{ handler: (event: IWidgetEvent) => void | Promise<void>; type: string }>): void;
72
83
 
73
84
  parentDomNode: Node;
74
- execute: () => void;
85
+ /**
86
+ Compute the internal state of the widget.
87
+ This will be automatically called in the `render` method.
88
+
89
+ For example, `getAttribute` and set them to class members.
90
+
91
+ */
92
+ execute(): void;
75
93
 
76
94
  /**
77
95
  * Lifecycle method: Render this widget into the DOM
78
96
  */
79
97
  render(parent: Node, nextSibling: Node | null): void;
98
+ /**
99
+ * Render the children of this widget into the DOM
100
+ */
101
+ renderChildren(parent: Node, nextSibling: Node | null): void;
80
102
  /**
81
103
  * Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering.
82
104
  * You can do some cleanup or buildup before return true.
@@ -93,7 +115,7 @@ Make child widgets correspondng to specified parseTreeNodes
93
115
  Rebuild a previously rendered widget
94
116
  */
95
117
  refreshSelf(): boolean;
96
- computeAttributes(): void;
118
+ computeAttributes(): Record<string, IParseTreeAttribute>;
97
119
  /**
98
120
  * Get parameters that user set in the widget
99
121
  * @param name attribute name, for example, `actions` in the button widget