tw5-typed 0.2.2 → 0.2.3
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 +1 -1
- package/src/Wiki.d.ts +45 -1
- package/src/server.d.ts +2 -2
- package/src/tw.d.ts +12 -1
- package/src/utils.d.ts +28 -2
- package/src/widget.d.ts +54 -13
package/package.json
CHANGED
package/src/Wiki.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
/// <reference path="parser.d.ts" />
|
|
2
2
|
|
|
3
3
|
declare module 'tiddlywiki' {
|
|
4
|
+
export interface IMakeWidgetOptions {
|
|
5
|
+
document: typeof document | IFakeDocument;
|
|
6
|
+
parentWidget?: Widget;
|
|
7
|
+
variables?: Record<string, any>;
|
|
8
|
+
}
|
|
4
9
|
export class Wiki {
|
|
5
10
|
/**
|
|
6
11
|
* 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.
|
|
@@ -85,7 +90,7 @@ declare module 'tiddlywiki' {
|
|
|
85
90
|
setText: (title: string, field?: string, index?: string | undefined, value?: string, options?: any) => void;
|
|
86
91
|
parseTiddler(title: string, options?: IParserOptions): WikiParser;
|
|
87
92
|
parseText(type: string, text: string, options?: IParserOptions): WikiParser;
|
|
88
|
-
|
|
93
|
+
/**
|
|
89
94
|
Parse text from a tiddler and render it into another format
|
|
90
95
|
outputType: content type for the output
|
|
91
96
|
title: title of the tiddler to be rendered
|
|
@@ -99,5 +104,44 @@ declare module 'tiddlywiki' {
|
|
|
99
104
|
title: string,
|
|
100
105
|
options?: { parentWidget?: Widget; variables?: Record<string, any> },
|
|
101
106
|
): string;
|
|
107
|
+
/**
|
|
108
|
+
Make a widget tree for a parse tree
|
|
109
|
+
@params parser: parser object
|
|
110
|
+
@params options: see below
|
|
111
|
+
Options include:
|
|
112
|
+
document: optional document to use
|
|
113
|
+
variables: hashmap of variables to set
|
|
114
|
+
parentWidget: optional parent widget for the root node
|
|
115
|
+
*/
|
|
116
|
+
makeWidget(parser: WikiParser, options?: IMakeWidgetOptions): Widget;
|
|
117
|
+
/**
|
|
118
|
+
Make a widget tree for transclusion
|
|
119
|
+
@params title: target tiddler title
|
|
120
|
+
@params options: as for wiki.makeWidget() plus:
|
|
121
|
+
|
|
122
|
+
- options.field: optional field to transclude (defaults to "text")
|
|
123
|
+
- options.mode: transclusion mode "inline" or "block"
|
|
124
|
+
- options.recursionMarker : optional flag to set a recursion marker, defaults to "yes"
|
|
125
|
+
- options.children: optional array of children for the transclude widget
|
|
126
|
+
- options.importVariables: optional importvariables filter string for macros to be included
|
|
127
|
+
- options.importPageMacros: optional boolean; if true, equivalent to passing "[[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]" to options.importVariables
|
|
128
|
+
*/
|
|
129
|
+
makeTranscludeWidget(
|
|
130
|
+
title: string,
|
|
131
|
+
options: {
|
|
132
|
+
/** optional array of children for the transclude widget */
|
|
133
|
+
children?: Widget[];
|
|
134
|
+
/** optional field to transclude (defaults to "text") */
|
|
135
|
+
field?: string;
|
|
136
|
+
/** optional boolean; if true, equivalent to passing "[[$:/core/ui/PageMacros]] [all[shadows+tiddlers]tag[$:/tags/Macro]!has[draft.of]]" to options.importVariables */
|
|
137
|
+
importPageMacros?: boolean;
|
|
138
|
+
/** optional importvariables filter string for macros to be included */
|
|
139
|
+
importVariables?: string;
|
|
140
|
+
/** transclusion mode "inline" or "block" */
|
|
141
|
+
mode?: 'inline' | 'block';
|
|
142
|
+
/** optional flag to set a recursion marker, defaults to "yes" */
|
|
143
|
+
recursionMarker?: 'yes' | 'no';
|
|
144
|
+
} & IMakeWidgetOptions,
|
|
145
|
+
): Widget;
|
|
102
146
|
}
|
|
103
147
|
}
|
package/src/server.d.ts
CHANGED
|
@@ -74,14 +74,14 @@ declare module 'tiddlywiki' {
|
|
|
74
74
|
variables: Record<string, any>;
|
|
75
75
|
get(variableName: string): any;
|
|
76
76
|
requestHandler: ServerEndpointHandler;
|
|
77
|
-
|
|
77
|
+
/**
|
|
78
78
|
Listen for requests
|
|
79
79
|
port: optional port number (falls back to value of "port" variable)
|
|
80
80
|
host: optional host address (falls back to value of "host" variable)
|
|
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
|
-
|
|
84
|
+
/**
|
|
85
85
|
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
86
|
*/
|
|
87
87
|
isAuthorized(authorizationType: 'readers' | 'writers', username?: string | undefined): boolean;
|
package/src/tw.d.ts
CHANGED
|
@@ -59,9 +59,19 @@ declare module 'tiddlywiki' {
|
|
|
59
59
|
|
|
60
60
|
config: ITWConfig;
|
|
61
61
|
|
|
62
|
+
/**
|
|
63
|
+
Global Hooks mechanism which allows plugins to modify default functionality
|
|
64
|
+
*/
|
|
62
65
|
hooks: {
|
|
66
|
+
/**
|
|
67
|
+
Add hooks to the hashmap
|
|
68
|
+
*/
|
|
63
69
|
addHook(hookName: 'th-server-command-post-start', callback: (listenCommand: unknown, server: Server) => void): void;
|
|
64
70
|
addHook(hookName: string, callback: (...arguments_: unknown[]) => unknown): void;
|
|
71
|
+
/**
|
|
72
|
+
Invoke the hook by key
|
|
73
|
+
*/
|
|
74
|
+
invokeHook(hookName: string): void;
|
|
65
75
|
};
|
|
66
76
|
|
|
67
77
|
modules: ITWModules;
|
|
@@ -70,17 +80,18 @@ declare module 'tiddlywiki' {
|
|
|
70
80
|
/** Broswer features, if tw isn't running on a browser environment, the value will be `null` */
|
|
71
81
|
nodeWebKit: null | object;
|
|
72
82
|
|
|
83
|
+
notifier: Notifier;
|
|
73
84
|
/** Convenience function for pushing a tiddler onto the preloading array */
|
|
74
85
|
preloadTiddler(fields: Record<string, unknown>): void;
|
|
75
86
|
/** Convenience function for pushing an array of tiddlers onto the preloading array */
|
|
76
87
|
preloadTiddlerArray(fieldsArray: Array<Record<string, unknown>>): void;
|
|
88
|
+
|
|
77
89
|
/** External JavaScript can populate this array before calling boot.js in order to preload tiddlers */
|
|
78
90
|
preloadTiddlers: Record<string, Record<string, unknown>>;
|
|
79
91
|
|
|
80
92
|
rootWidget: Widget;
|
|
81
93
|
|
|
82
94
|
utils: ITWUtils;
|
|
83
|
-
|
|
84
95
|
version: string;
|
|
85
96
|
wiki: Wiki;
|
|
86
97
|
}
|
package/src/utils.d.ts
CHANGED
|
@@ -15,6 +15,20 @@ declare module 'tiddlywiki' {
|
|
|
15
15
|
* @param className
|
|
16
16
|
*/
|
|
17
17
|
addClass(element: Element, className: string): void;
|
|
18
|
+
/**
|
|
19
|
+
Attach specified event handlers to a DOM node
|
|
20
|
+
@param domNode: where to attach the event handlers
|
|
21
|
+
@param events: array of event handlers to be added (see below)
|
|
22
|
+
Each entry in the events array is an object with these properties:
|
|
23
|
+
- name: event name of `addEventListener`
|
|
24
|
+
- handlerFunction: optional event handler function
|
|
25
|
+
- handlerObject: optional event handler object
|
|
26
|
+
- handlerMethod: optionally specifies object handler method name (defaults to `handleEvent`)
|
|
27
|
+
*/
|
|
28
|
+
addEventListeners(
|
|
29
|
+
domNode: Node,
|
|
30
|
+
events: Array<{ handlerFunction?: (event: MouseEvent) => void; handlerMethod?: string; handlerObject?: Widget; name: string }>,
|
|
31
|
+
): void;
|
|
18
32
|
/** Returns true if the version string A is greater than the version string B. Returns true if the versions are the same */
|
|
19
33
|
checkVersions(versionStringA: string, versionStringB: string): boolean;
|
|
20
34
|
/**
|
|
@@ -26,8 +40,6 @@ declare module 'tiddlywiki' {
|
|
|
26
40
|
decodeURIComponentSafe(uri: string): string;
|
|
27
41
|
/** Convert a URI encoded string to a string safely */
|
|
28
42
|
decodeURISafe(uri: string): string;
|
|
29
|
-
/** the function behind `<<now "format">> */
|
|
30
|
-
formatDateString(date: Date, format: string): string;
|
|
31
43
|
/** 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 */
|
|
32
44
|
deepDefaults(object: object, ...sourceObjectList: object[]): object;
|
|
33
45
|
/**
|
|
@@ -82,6 +94,8 @@ declare module 'tiddlywiki' {
|
|
|
82
94
|
evalSandboxed(code: string, context: IModuleSandbox, filename: string): unknown;
|
|
83
95
|
/** Extend an object with the properties from a list of source objects */
|
|
84
96
|
extend(object: object, ...sourceObjectList: object[]): object;
|
|
97
|
+
/** the function behind `<<now "format">> */
|
|
98
|
+
formatDateString(date: Date, format: string): string;
|
|
85
99
|
/** Given an extension, always access the $tw.config.fileExtensionInfo using a lowercase extension only. */
|
|
86
100
|
getFileExtensionInfo(extension: string): IFileExtensionInfo | null;
|
|
87
101
|
/** 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) */
|
|
@@ -154,4 +168,16 @@ declare module 'tiddlywiki' {
|
|
|
154
168
|
/** Stringify an array of tiddler titles into a list string */
|
|
155
169
|
stringifyList(value: string[]): string;
|
|
156
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Notifier mechanism
|
|
173
|
+
*/
|
|
174
|
+
export class Notifier {
|
|
175
|
+
/*
|
|
176
|
+
Display a notification
|
|
177
|
+
title: Title of tiddler containing the notification text
|
|
178
|
+
options: see below
|
|
179
|
+
Options include:
|
|
180
|
+
*/
|
|
181
|
+
display(title: string, options?: Record<string, unknown>): void;
|
|
182
|
+
}
|
|
157
183
|
}
|
package/src/widget.d.ts
CHANGED
|
@@ -9,26 +9,26 @@ declare module 'tiddlywiki' {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export interface IWidgetEvent {
|
|
12
|
-
/**
|
|
12
|
+
/** maybe a DOM click event, if trigger by button click */
|
|
13
|
+
event: Event;
|
|
14
|
+
navigateFromTitle?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Get `$param`
|
|
17
|
+
*/
|
|
18
|
+
param?: string | undefined;
|
|
19
|
+
/** Optional hashmap of additional tiddler fields. Widget event can carry any other parameters
|
|
13
20
|
*
|
|
14
21
|
* For example, `<$action-sendmessage $message="tw-mobile-sync-set-active-server-and-sync" title={{!!title}} />` will produce `paramObject: { title: "xxxx" }`
|
|
15
22
|
*/
|
|
16
23
|
paramObject?: {
|
|
17
24
|
[othersParamKeys: string]: unknown;
|
|
18
25
|
};
|
|
19
|
-
/**
|
|
20
|
-
* Get `$param`
|
|
21
|
-
*/
|
|
22
|
-
param?: string | undefined;
|
|
23
26
|
/** the first parameter of addEventListener
|
|
24
27
|
*
|
|
25
28
|
* For example, the `'open-command-palette'` in `$tw.rootWidget.addEventListener('open-command-palette', (e: IWidgetEvent) => this.openPalette(e));`
|
|
26
29
|
*/
|
|
27
30
|
type: string;
|
|
28
31
|
widget: Widget;
|
|
29
|
-
/** maybe a DOM click event, if trigger by button click */
|
|
30
|
-
event: Event;
|
|
31
|
-
navigateFromTitle?: string;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
@@ -38,11 +38,22 @@ declare module 'tiddlywiki' {
|
|
|
38
38
|
* @link https://tiddlywiki.com/dev/#Widgets
|
|
39
39
|
*/
|
|
40
40
|
export class Widget {
|
|
41
|
-
constructor(parseTreeNode:
|
|
42
|
-
initialize: (parseTreeNode:
|
|
43
|
-
parseTreeNode:
|
|
44
|
-
wiki:
|
|
41
|
+
constructor(parseTreeNode: IParseTreeNode, options?: unknown);
|
|
42
|
+
initialize: (parseTreeNode: IParseTreeNode, options?: unknown) => void;
|
|
43
|
+
parseTreeNode: IParseTreeNode;
|
|
44
|
+
wiki: ITiddlyWiki;
|
|
45
45
|
parentWidget?: Widget;
|
|
46
|
+
children: Widget[];
|
|
47
|
+
/*
|
|
48
|
+
Make child widgets correspondng to specified parseTreeNodes
|
|
49
|
+
*/
|
|
50
|
+
makeChildWidgets(parseTreeNodes: IParseTreeNode[], options?: { variables?: unknown }): void;
|
|
51
|
+
/**
|
|
52
|
+
Construct the widget object for a parse tree node
|
|
53
|
+
options include:
|
|
54
|
+
variables: optional hashmap of variables to wrap around the widget
|
|
55
|
+
*/
|
|
56
|
+
makeChildWidget(parseTreeNode: IParseTreeNode, options?: { variables?: unknown }): void;
|
|
46
57
|
variablesConstructor: variablesConstructor;
|
|
47
58
|
variables: unknown;
|
|
48
59
|
domNodes: Node[];
|
|
@@ -65,7 +76,7 @@ declare module 'tiddlywiki' {
|
|
|
65
76
|
/**
|
|
66
77
|
* Lifecycle method: Render this widget into the DOM
|
|
67
78
|
*/
|
|
68
|
-
render(parent: Node, nextSibling: Node): void;
|
|
79
|
+
render(parent: Node, nextSibling: Node | null): void;
|
|
69
80
|
/**
|
|
70
81
|
* Selectively refreshes the widget if needed. Returns true if the widget or any of its children needed re-rendering.
|
|
71
82
|
* You can do some cleanup or buildup before return true.
|
|
@@ -73,6 +84,15 @@ declare module 'tiddlywiki' {
|
|
|
73
84
|
* @link https://tiddlywiki.com/dev/#Selective%20Update
|
|
74
85
|
*/
|
|
75
86
|
refresh(changedTiddlers: IChangedTiddlers): boolean;
|
|
87
|
+
/**
|
|
88
|
+
Refresh all the children of a widget
|
|
89
|
+
will call `this.render`
|
|
90
|
+
*/
|
|
91
|
+
refreshChildren(changedTiddlers: IChangedTiddlers): boolean;
|
|
92
|
+
/**
|
|
93
|
+
Rebuild a previously rendered widget
|
|
94
|
+
*/
|
|
95
|
+
refreshSelf(): boolean;
|
|
76
96
|
computeAttributes(): void;
|
|
77
97
|
/**
|
|
78
98
|
* Get parameters that user set in the widget
|
|
@@ -97,4 +117,25 @@ declare module 'tiddlywiki' {
|
|
|
97
117
|
*/
|
|
98
118
|
getVariable(name: string, options?: object): string;
|
|
99
119
|
}
|
|
120
|
+
|
|
121
|
+
export interface IFakeDocument {
|
|
122
|
+
compatMode: string;
|
|
123
|
+
createElement: (tag: string) => TW_Element;
|
|
124
|
+
createElementNS: (namespace: string, tag: string) => TW_Element;
|
|
125
|
+
createTextNode: (text: string) => TW_TextNode;
|
|
126
|
+
isTiddlyWikiFakeDom: boolean;
|
|
127
|
+
setSequenceNumber: (value: any) => void;
|
|
128
|
+
}
|
|
129
|
+
export class TW_Element {
|
|
130
|
+
isTiddlyWikiFakeDom: boolean;
|
|
131
|
+
tag: string;
|
|
132
|
+
attributes: Record<string, unknown>;
|
|
133
|
+
isRaw: boolean;
|
|
134
|
+
children: Array<TW_Element | TW_TextNode>;
|
|
135
|
+
_style: Record<string, unknown>;
|
|
136
|
+
namespaceURI: string;
|
|
137
|
+
}
|
|
138
|
+
export class TW_TextNode {
|
|
139
|
+
textContent: string;
|
|
140
|
+
}
|
|
100
141
|
}
|