tw5-typed 0.2.6 → 0.2.9

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.6",
5
+ "version": "0.2.9",
6
6
  "url": "https://github.com/tiddly-gittly/tw5-typed",
7
7
  "homepage": "https://github.com/tiddly-gittly/tw5-typed",
8
8
  "bugs": {
@@ -20,10 +20,10 @@
20
20
  "prepublishOnly": "npx tsc --noEmit"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/node": "^17.0.29",
24
- "@typescript-eslint/eslint-plugin": "5.21.0",
25
- "@typescript-eslint/parser": "5.21.0",
26
- "eslint": "8.14.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
28
  "eslint-config-standard": "17.0.0",
29
29
  "eslint-config-standard-with-typescript": "21.0.1",
@@ -42,6 +42,6 @@
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
@@ -46,8 +46,19 @@ declare module 'tiddlywiki' {
46
46
  /**
47
47
  * Compile filter string to be a function that execute the filter in the wiki.
48
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.
49
53
  */
50
- compileFilter: (filterString: string) => (iterator?: SourceIterator) => string[];
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)
60
+ */
61
+ filterTiddlers(filterString: string, widget?: Widget, source?: SourceIterator): string[];
51
62
  /**
52
63
  * Set JSON tiddler, Object in data field will be JSON.stringify and put into the text.
53
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.
@@ -111,7 +122,20 @@ declare module 'tiddlywiki' {
111
122
  * @param {object} options options, see tiddlywiki dev doc for details
112
123
  */
113
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
+ */
114
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
+ */
115
139
  parseText(type: string, text: string, options?: IParserOptions): WikiParser;
116
140
  /**
117
141
  Parse text from a tiddler and render it into another format
@@ -123,6 +147,16 @@ declare module 'tiddlywiki' {
123
147
  parentWidget: optional parent widget for the root node
124
148
  */
125
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;
126
160
  /**
127
161
  Make a widget tree for a parse tree
128
162
  @params parser: parser object
@@ -132,17 +166,6 @@ declare module 'tiddlywiki' {
132
166
  variables: hashmap of variables to set
133
167
  parentWidget: optional parent widget for the root node
134
168
  */
135
- /**
136
- Parse text in a specified format and render it into another format
137
- outputType: content type for the output
138
- textType: content type of the input text
139
- text: input text
140
- options: see below
141
- Options include:
142
- variables: hashmap of variables to set
143
- parentWidget: optional parent widget for the root node
144
- */
145
- renderText(outputType: OutputMimeTypes, textType: TextMimeTypes, text: string, options?: Partial<IMakeWidgetOptions> & IParserOptions): string;
146
169
  makeWidget(parser: WikiParser, options?: IMakeWidgetOptions): Widget;
147
170
  /**
148
171
  Make a widget tree for transclusion
package/src/ast.d.ts CHANGED
@@ -3,8 +3,8 @@ declare module 'tiddlywiki' {
3
3
  end?: number;
4
4
  name?: string;
5
5
  start?: number;
6
- type: 'string' | 'number';
7
- value: string;
6
+ type: 'string' | 'number' | 'bigint' | 'boolean' | 'macro' | 'macro-parameter';
7
+ value: string | IMacroCallParseTreeNode;
8
8
  }
9
9
 
10
10
  export interface IWikiASTNode {
@@ -22,7 +22,7 @@ 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
28
  export interface IImageParseTreeNode extends IWikiASTNode {
@@ -42,19 +42,15 @@ declare module 'tiddlywiki' {
42
42
  }
43
43
  export interface ICodeBlockParseTreeNode extends IWikiASTNode {
44
44
  attributes: {
45
- code?:
46
- | {
47
- type: 'string';
48
- value: string;
49
- }
50
- | undefined;
51
- language?:
52
- | {
53
- type: 'string';
54
- value: string;
55
- }
56
- | undefined;
57
- };
45
+ code?: {
46
+ type: 'string';
47
+ value: string;
48
+ };
49
+ language?: {
50
+ type: 'string';
51
+ value: string;
52
+ };
53
+ } & IWikiASTNode['attributes'];
58
54
  type: 'codeblock';
59
55
  }
60
56
  export interface IMacroParameterCallParseTreeNode extends IWikiASTNode {
@@ -63,10 +59,17 @@ declare module 'tiddlywiki' {
63
59
  value: string;
64
60
  }
65
61
  export interface IMacroCallParseTreeNode extends IWikiASTNode {
66
- name: string;
67
- params: IMacroParameterCallParseTreeNode[];
62
+ name?: string;
63
+ params?: IMacroParameterCallParseTreeNode[];
64
+ /** `tag: '$macrocall',` */
65
+ tag?: string;
68
66
  type: 'macrocall';
69
67
  }
68
+ export interface IMacroParseTreeNode extends IWikiASTNode {
69
+ name: string;
70
+ type: 'macro';
71
+ value: IMacroCallParseTreeNode;
72
+ }
70
73
  export interface ICustomParseTreeNode extends IWikiASTNode {
71
74
  params: IMacroParameterCallParseTreeNode[];
72
75
  tag?: string;
@@ -74,6 +77,7 @@ declare module 'tiddlywiki' {
74
77
  type: string;
75
78
  }
76
79
  export type IParseTreeNode =
80
+ | IWikiASTNode
77
81
  | IDomParseTreeNode
78
82
  | IMacroParameterCallParseTreeNode
79
83
  | IMacroCallParseTreeNode
@@ -81,5 +85,9 @@ declare module 'tiddlywiki' {
81
85
  | IImageParseTreeNode
82
86
  | ITranscludeParseTreeNode
83
87
  | ITiddlerParseTreeNode
84
- | ICustomParseTreeNode;
88
+ | ICodeBlockParseTreeNode
89
+ | ILinkParseTreeNode
90
+ | ICustomParseTreeNode
91
+ | IMacroParseTreeNode
92
+ | IParseTreeAttribute;
85
93
  }
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;
@@ -55,10 +59,52 @@ declare module 'tiddlywiki' {
55
59
  };
56
60
  };
57
61
 
58
- browser: null | object;
62
+ browser: null | {
63
+ is?: {
64
+ android?: boolean;
65
+ bada?: boolean;
66
+ blackberry?: boolean;
67
+ chrome?: boolean;
68
+ firefox?: boolean;
69
+ firefoxos?: boolean;
70
+ gecko?: boolean;
71
+ ios?: boolean;
72
+ ipad?: boolean;
73
+ iphone?: boolean;
74
+ mobile?: boolean;
75
+ name?: boolean;
76
+ opera?: boolean;
77
+ phantomjs?: boolean;
78
+ safari?: boolean;
79
+ sailfish?: boolean;
80
+ seamonkey?: boolean;
81
+ silk?: boolean;
82
+ tizen?: boolean;
83
+ version?: boolean;
84
+ webkit?: boolean;
85
+ webos?: boolean;
86
+ windowsphone?: boolean;
87
+ };
88
+ /**
89
+ * @deprecated
90
+ * Install `$:/plugins/tiddlywiki/browser-sniff` to use `browser.is`
91
+ */
92
+ isFirefox: boolean;
93
+ /**
94
+ * @deprecated
95
+ * Install `$:/plugins/tiddlywiki/browser-sniff` to use `browser.is`
96
+ */
97
+ isIE: boolean;
98
+ };
59
99
 
60
100
  config: ITWConfig;
61
101
 
102
+ /**
103
+ * 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.
104
+ * Used by `DropZoneWidget.prototype.handleDropEvent`
105
+ */
106
+ dragInProgress?: boolean;
107
+
62
108
  /**
63
109
  Global Hooks mechanism which allows plugins to modify default functionality
64
110
  */
@@ -71,10 +117,13 @@ declare module 'tiddlywiki' {
71
117
  /**
72
118
  Invoke the hook by key
73
119
  */
74
- invokeHook(hookName: string): void;
120
+ invokeHook(hookName: string, event: IWidgetEvent): undefined | IWidgetEvent;
75
121
  };
76
-
122
+ /** Determines if a tiddler is a shadow tiddler, regardless of whether it has been overridden by a real tiddler */
123
+ isShadowTiddler(title: string): boolean;
124
+ language: ILanguage;
77
125
  modules: ITWModules;
126
+
78
127
  /** NodeJS features, if tw isn't running on a NodeJS environment, the value will be `null` */
79
128
  node: null | object;
80
129
  /** Broswer features, if tw isn't running on a browser environment, the value will be `null` */
@@ -91,6 +140,8 @@ declare module 'tiddlywiki' {
91
140
 
92
141
  rootWidget: Widget;
93
142
 
143
+ /** Test for the existence of a tiddler (excludes shadow tiddlers) */
144
+ tiddlerExists(title: string): boolean;
94
145
  utils: ITWUtils;
95
146
  version: string;
96
147
  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,10 @@ 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;
15
+ name: string;
14
16
  navigateFromTitle?: string;
15
17
  /**
16
18
  * Get `$param`
@@ -23,6 +25,7 @@ declare module 'tiddlywiki' {
23
25
  paramObject?: {
24
26
  [othersParamKeys: string]: unknown;
25
27
  };
28
+ tiddlerTitle?: string;
26
29
  /** the first parameter of addEventListener
27
30
  *
28
31
  * For example, the `'open-command-palette'` in `$tw.rootWidget.addEventListener('open-command-palette', (e: IWidgetEvent) => this.openPalette(e));`
@@ -43,8 +46,11 @@ declare module 'tiddlywiki' {
43
46
  parseTreeNode: IParseTreeNode;
44
47
  wiki: ITiddlyWiki;
45
48
  parentWidget?: Widget;
46
- /** we can use $tw.rootWidget.widgetClasses.widget to new a widget */
47
- widgetClasses: Widget;
49
+ /** we can use $tw.rootWidget.widgetClasses.widget to new a widget
50
+ *
51
+ * This is a set of all widgets defined in tiddlywiki.
52
+ */
53
+ widgetClasses: Record<string, Widget>;
48
54
  /** we can use $tw.rootWidget.widgetClasses.widget to new a widget
49
55
  *
50
56
  * Like `new widget.widget(widgetNode,{` in `$tw.wiki.makeWidget`
@@ -53,15 +59,23 @@ declare module 'tiddlywiki' {
53
59
  children: Widget[];
54
60
  /**
55
61
  Make child widgets correspondng to specified parseTreeNodes
62
+ And push them to `this.children`
56
63
  @param parseTreeNodes default to `this.parseTreeNode.children`, can be undefined
57
64
  */
58
65
  makeChildWidgets(parseTreeNodes?: IParseTreeNode[], options?: { variables?: unknown }): void;
59
66
  /**
60
- Construct the widget object for a parse tree node
67
+ * Remove any DOM nodes created by this widget or its children
68
+ *
69
+ * If this widget has directly created DOM nodes, delete them and exit. This assumes that any child widgets are contained within the created DOM nodes, which would normally be the case.
70
+ * Otherwise, ask the child widgets to delete their DOM nodes
71
+ */
72
+ removeChildDomNodes(): void;
73
+ /**
74
+ Construct the widget object for a parse tree node, and return the new widget
61
75
  options include:
62
76
  variables: optional hashmap of variables to wrap around the widget
63
77
  */
64
- makeChildWidget(parseTreeNode: IParseTreeNode, options?: { variables?: unknown }): void;
78
+ makeChildWidget(parseTreeNode: IParseTreeNode, options?: { variables?: unknown }): Widget;
65
79
  variablesConstructor: variablesConstructor;
66
80
  variables: unknown;
67
81
  domNodes: Node[];
@@ -87,6 +101,23 @@ declare module 'tiddlywiki' {
87
101
 
88
102
  */
89
103
  execute(): void;
104
+ /**
105
+ * Invoke the action widgets that are descendents of the current widget. Will call child widget's invokeAction recursively.
106
+ *
107
+ * @param triggeringWidget
108
+ * @param event
109
+ * @returns handled by any children
110
+ */
111
+ invokeActions(triggeringWidget: Widget, event: IWidgetEvent): boolean;
112
+ /**
113
+ * Invoke the action associated with this widget
114
+ *
115
+ * No every widget has this method, but some do, like `action-xxx` widget, e.g., `action-sendmessage`
116
+ * @param triggeringWidget
117
+ * @param event
118
+ * @returns handled
119
+ */
120
+ invokeAction: (triggeringWidget: Widget, event: IWidgetEvent) => boolean | undefined;
90
121
 
91
122
  /**
92
123
  * Lifecycle method: Render this widget into the DOM
@@ -109,9 +140,18 @@ declare module 'tiddlywiki' {
109
140
  */
110
141
  refreshChildren(changedTiddlers: IChangedTiddlers): boolean;
111
142
  /**
112
- Rebuild a previously rendered widget
113
- */
114
- refreshSelf(): boolean;
143
+ * Rebuild a previously rendered widget
144
+ */
145
+ refreshSelf(): boolean | void;
146
+ /**
147
+ * Find the next sibling in the DOM to this widget. This is done by scanning the widget tree through all next siblings and their descendents that share the same parent DOM node
148
+ * @param startIndex Refer to this widget by its index within its parents children
149
+ */
150
+ findNextSiblingDomNode(startIndex?: number): Node | null;
151
+ /**
152
+ * Find the first DOM node generated by a widget or its children
153
+ */
154
+ findFirstDomNode(): Node | null;
115
155
  computeAttributes(): Record<string, IParseTreeAttribute>;
116
156
  /**
117
157
  * Get parameters that user set in the widget