tw5-typed 0.2.3 → 0.2.6
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 +9 -9
- package/src/Wiki.d.ts +38 -8
- package/src/ast.d.ts +18 -1
- package/src/widget.d.ts +26 -7
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
|
+
"version": "0.2.6",
|
|
6
6
|
"url": "https://github.com/tiddly-gittly/tw5-typed",
|
|
7
7
|
"homepage": "https://github.com/tiddly-gittly/tw5-typed",
|
|
8
8
|
"bugs": {
|
|
@@ -20,24 +20,24 @@
|
|
|
20
20
|
"prepublishOnly": "npx tsc --noEmit"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@types/node": "^17.0.
|
|
24
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
25
|
-
"@typescript-eslint/parser": "5.
|
|
26
|
-
"eslint": "8.
|
|
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",
|
|
27
27
|
"eslint-config-prettier": "8.5.0",
|
|
28
|
-
"eslint-config-standard": "
|
|
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.
|
|
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.
|
|
40
|
-
"eslint-plugin-security": "1.
|
|
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",
|
package/src/Wiki.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/// <reference path="parser.d.ts" />
|
|
2
2
|
|
|
3
3
|
declare module 'tiddlywiki' {
|
|
4
|
-
export interface IMakeWidgetOptions {
|
|
4
|
+
export interface IMakeWidgetOptions extends IRenderOptions {
|
|
5
5
|
document: typeof document | IFakeDocument;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export type OutputMimeTypes = 'text/html' | 'text/plain-formatted' | 'text/plain';
|
|
9
|
+
export type TextMimeTypes = 'text/html' | 'text/vnd.tiddlywiki' | 'text/plain';
|
|
10
|
+
export interface IRenderOptions {
|
|
6
11
|
parentWidget?: Widget;
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
13
|
variables?: Record<string, any>;
|
|
8
14
|
}
|
|
9
15
|
export class Wiki {
|
|
@@ -19,7 +25,24 @@ declare module 'tiddlywiki' {
|
|
|
19
25
|
/**
|
|
20
26
|
* Get full list of tiddler titles in the wiki
|
|
21
27
|
*/
|
|
22
|
-
getTiddlers
|
|
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;
|
|
23
46
|
/**
|
|
24
47
|
* Compile filter string to be a function that execute the filter in the wiki.
|
|
25
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.
|
|
@@ -87,7 +110,7 @@ declare module 'tiddlywiki' {
|
|
|
87
110
|
* @param {string} value text content to set
|
|
88
111
|
* @param {object} options options, see tiddlywiki dev doc for details
|
|
89
112
|
*/
|
|
90
|
-
setText: (title: string, field?: string, index?: string | undefined, value?: string, options?:
|
|
113
|
+
setText: (title: string, field?: string, index?: string | undefined, value?: string, options?: { suppressTimestamp?: boolean }) => void;
|
|
91
114
|
parseTiddler(title: string, options?: IParserOptions): WikiParser;
|
|
92
115
|
parseText(type: string, text: string, options?: IParserOptions): WikiParser;
|
|
93
116
|
/**
|
|
@@ -99,11 +122,7 @@ declare module 'tiddlywiki' {
|
|
|
99
122
|
variables: hashmap of variables to set
|
|
100
123
|
parentWidget: optional parent widget for the root node
|
|
101
124
|
*/
|
|
102
|
-
renderTiddler(
|
|
103
|
-
outputType: 'text/html' | 'text/plain-formatted' | 'text/plain',
|
|
104
|
-
title: string,
|
|
105
|
-
options?: { parentWidget?: Widget; variables?: Record<string, any> },
|
|
106
|
-
): string;
|
|
125
|
+
renderTiddler(outputType: OutputMimeTypes, title: string, options?: IRenderOptions): string;
|
|
107
126
|
/**
|
|
108
127
|
Make a widget tree for a parse tree
|
|
109
128
|
@params parser: parser object
|
|
@@ -113,6 +132,17 @@ declare module 'tiddlywiki' {
|
|
|
113
132
|
variables: hashmap of variables to set
|
|
114
133
|
parentWidget: optional parent widget for the root node
|
|
115
134
|
*/
|
|
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;
|
|
116
146
|
makeWidget(parser: WikiParser, options?: IMakeWidgetOptions): Widget;
|
|
117
147
|
/**
|
|
118
148
|
Make a widget tree for transclusion
|
package/src/ast.d.ts
CHANGED
|
@@ -25,6 +25,15 @@ declare module 'tiddlywiki' {
|
|
|
25
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 {
|
|
@@ -64,5 +73,13 @@ declare module 'tiddlywiki' {
|
|
|
64
73
|
text?: string;
|
|
65
74
|
type: string;
|
|
66
75
|
}
|
|
67
|
-
export type IParseTreeNode =
|
|
76
|
+
export type IParseTreeNode =
|
|
77
|
+
| IDomParseTreeNode
|
|
78
|
+
| IMacroParameterCallParseTreeNode
|
|
79
|
+
| IMacroCallParseTreeNode
|
|
80
|
+
| ITextParseTreeNode
|
|
81
|
+
| IImageParseTreeNode
|
|
82
|
+
| ITranscludeParseTreeNode
|
|
83
|
+
| ITiddlerParseTreeNode
|
|
84
|
+
| ICustomParseTreeNode;
|
|
68
85
|
}
|
package/src/widget.d.ts
CHANGED
|
@@ -39,15 +39,23 @@ declare module 'tiddlywiki' {
|
|
|
39
39
|
*/
|
|
40
40
|
export class Widget {
|
|
41
41
|
constructor(parseTreeNode: IParseTreeNode, options?: unknown);
|
|
42
|
-
initialize
|
|
42
|
+
initialize(parseTreeNode: IParseTreeNode, options?: unknown): void;
|
|
43
43
|
parseTreeNode: IParseTreeNode;
|
|
44
44
|
wiki: ITiddlyWiki;
|
|
45
45
|
parentWidget?: Widget;
|
|
46
|
+
/** we can use $tw.rootWidget.widgetClasses.widget to new a widget */
|
|
47
|
+
widgetClasses: Widget;
|
|
48
|
+
/** we can use $tw.rootWidget.widgetClasses.widget to new a widget
|
|
49
|
+
*
|
|
50
|
+
* Like `new widget.widget(widgetNode,{` in `$tw.wiki.makeWidget`
|
|
51
|
+
*/
|
|
52
|
+
widget: new (parseTreeNode: IParseTreeNode, options?: unknown) => Widget;
|
|
46
53
|
children: Widget[];
|
|
47
|
-
|
|
48
|
-
Make child widgets correspondng to specified parseTreeNodes
|
|
49
|
-
|
|
50
|
-
|
|
54
|
+
/**
|
|
55
|
+
Make child widgets correspondng to specified parseTreeNodes
|
|
56
|
+
@param parseTreeNodes default to `this.parseTreeNode.children`, can be undefined
|
|
57
|
+
*/
|
|
58
|
+
makeChildWidgets(parseTreeNodes?: IParseTreeNode[], options?: { variables?: unknown }): void;
|
|
51
59
|
/**
|
|
52
60
|
Construct the widget object for a parse tree node
|
|
53
61
|
options include:
|
|
@@ -71,12 +79,23 @@ Make child widgets correspondng to specified parseTreeNodes
|
|
|
71
79
|
addEventListeners(listeners: Array<{ handler: (event: IWidgetEvent) => void | Promise<void>; type: string }>): void;
|
|
72
80
|
|
|
73
81
|
parentDomNode: Node;
|
|
74
|
-
|
|
82
|
+
/**
|
|
83
|
+
Compute the internal state of the widget.
|
|
84
|
+
This will be automatically called in the `render` method.
|
|
85
|
+
|
|
86
|
+
For example, `getAttribute` and set them to class members.
|
|
87
|
+
|
|
88
|
+
*/
|
|
89
|
+
execute(): void;
|
|
75
90
|
|
|
76
91
|
/**
|
|
77
92
|
* Lifecycle method: Render this widget into the DOM
|
|
78
93
|
*/
|
|
79
94
|
render(parent: Node, nextSibling: Node | null): void;
|
|
95
|
+
/**
|
|
96
|
+
* Render the children of this widget into the DOM
|
|
97
|
+
*/
|
|
98
|
+
renderChildren(parent: Node, nextSibling: Node | null): void;
|
|
80
99
|
/**
|
|
81
100
|
* Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering.
|
|
82
101
|
* You can do some cleanup or buildup before return true.
|
|
@@ -93,7 +112,7 @@ Make child widgets correspondng to specified parseTreeNodes
|
|
|
93
112
|
Rebuild a previously rendered widget
|
|
94
113
|
*/
|
|
95
114
|
refreshSelf(): boolean;
|
|
96
|
-
computeAttributes():
|
|
115
|
+
computeAttributes(): Record<string, IParseTreeAttribute>;
|
|
97
116
|
/**
|
|
98
117
|
* Get parameters that user set in the widget
|
|
99
118
|
* @param name attribute name, for example, `actions` in the button widget
|