tw5-typed 0.1.12 → 0.2.2
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 +12 -12
- package/src/Tiddler.d.ts +7 -3
- package/src/Wiki.d.ts +51 -2
- package/src/ast.d.ts +16 -16
- package/src/filter-operator.d.ts +4 -1
- package/src/index.d.ts +13 -18
- package/src/modules.d.ts +1 -1
- package/src/parser.d.ts +11 -11
- package/src/server.d.ts +105 -0
- package/src/tw.d.ts +3 -3
- package/src/utils.d.ts +7 -4
- package/src/widget.d.ts +32 -9
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.
|
|
5
|
+
"version": "0.2.2",
|
|
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
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
25
|
-
"@typescript-eslint/parser": "5.
|
|
26
|
-
"eslint": "8.
|
|
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",
|
|
27
27
|
"eslint-config-prettier": "8.5.0",
|
|
28
28
|
"eslint-config-standard": "16.0.3",
|
|
29
29
|
"eslint-config-standard-with-typescript": "21.0.1",
|
|
30
30
|
"eslint-import-resolver-alias": "1.1.2",
|
|
31
|
-
"eslint-import-resolver-typescript": "2.
|
|
31
|
+
"eslint-import-resolver-typescript": "2.7.1",
|
|
32
32
|
"eslint-plugin-html": "6.2.0",
|
|
33
|
-
"eslint-plugin-import": "2.
|
|
34
|
-
"eslint-plugin-n": "15.0
|
|
33
|
+
"eslint-plugin-import": "2.26.0",
|
|
34
|
+
"eslint-plugin-n": "15.1.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.
|
|
39
|
+
"eslint-plugin-react-hooks": "4.4.0",
|
|
40
40
|
"eslint-plugin-security": "1.4.0",
|
|
41
41
|
"eslint-plugin-security-node": "1.1.1",
|
|
42
42
|
"eslint-plugin-typescript-sort-keys": "2.1.0",
|
|
43
|
-
"eslint-plugin-unicorn": "
|
|
44
|
-
"prettier": "2.6.
|
|
45
|
-
"typescript": "4.6.
|
|
43
|
+
"eslint-plugin-unicorn": "42.0.0",
|
|
44
|
+
"prettier": "2.6.2",
|
|
45
|
+
"typescript": "4.6.3"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/src/Tiddler.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
declare module 'tiddlywiki' {
|
|
2
2
|
export class Tiddler {
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param tiddlers multiple tiddler fields or instances, will merge them to create a new one
|
|
6
|
+
*/
|
|
7
|
+
constructor(...tiddlers: Array<Record<string, unknown> | Tiddler>);
|
|
4
8
|
readonly cache: ITiddlerCache;
|
|
5
9
|
readonly fields: ITiddlerFields;
|
|
6
10
|
static fieldModules: Record<string, IModuleInfo>;
|
|
@@ -10,9 +14,9 @@ declare module 'tiddlywiki' {
|
|
|
10
14
|
|
|
11
15
|
export interface ITiddlerFields {
|
|
12
16
|
readonly [anyKey: string]: unknown;
|
|
13
|
-
readonly color
|
|
17
|
+
readonly color?: string;
|
|
14
18
|
readonly created: Date;
|
|
15
|
-
readonly list
|
|
19
|
+
readonly list?: string[];
|
|
16
20
|
readonly modified: Date;
|
|
17
21
|
readonly tags: string[];
|
|
18
22
|
readonly text: string;
|
package/src/Wiki.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ declare module 'tiddlywiki' {
|
|
|
10
10
|
*/
|
|
11
11
|
constructor(options: { enableIndexers: unknown[] });
|
|
12
12
|
addIndexer(indexer: unknown, name: string): void;
|
|
13
|
-
getTiddler: (title: string) =>
|
|
13
|
+
getTiddler: <T extends Tiddler>(title: string) => T | undefined;
|
|
14
14
|
/**
|
|
15
15
|
* Get full list of tiddler titles in the wiki
|
|
16
16
|
*/
|
|
@@ -22,13 +22,18 @@ declare module 'tiddlywiki' {
|
|
|
22
22
|
compileFilter: (filterString: string) => (iterator?: SourceIterator) => string[];
|
|
23
23
|
/**
|
|
24
24
|
* Set JSON tiddler, Object in data field will be JSON.stringify and put into the text.
|
|
25
|
+
* 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.
|
|
25
26
|
*/
|
|
26
27
|
setTiddlerData: (title: string, data?: object, fields?: ITiddlerFields, options?: any) => void;
|
|
27
28
|
/**
|
|
28
29
|
* Create or update tiddler.
|
|
29
30
|
* Update existed tiddler based on the title field.
|
|
30
31
|
*/
|
|
31
|
-
addTiddler: (tiddler: Tiddler | ITiddlerFields) => void;
|
|
32
|
+
addTiddler: (tiddler: Tiddler | Partial<ITiddlerFields>) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Call `addTiddler` for each iton of the list, but should passing `tiddler.fields`, directly passing tiddler object may failed to add in some cases.
|
|
35
|
+
*/
|
|
36
|
+
addTiddlers: (tiddler: Array<Partial<ITiddlerFields>>) => void;
|
|
32
37
|
/**
|
|
33
38
|
* Get tiddler's text field, with an optional default text.
|
|
34
39
|
* If have _is_skinny field, will just return null (this is a rare case, so not put in the return type for now).
|
|
@@ -38,6 +43,36 @@ declare module 'tiddlywiki' {
|
|
|
38
43
|
*/
|
|
39
44
|
getTiddlerText(title: string, fallbackText: string): string;
|
|
40
45
|
getTiddlerText(title: string, fallbackText?: string): string | undefined;
|
|
46
|
+
/**
|
|
47
|
+
Get the content of a tiddler as a JavaScript object. How this is done depends on the type of the tiddler:
|
|
48
|
+
|
|
49
|
+
application/json: the tiddler JSON is parsed into an object
|
|
50
|
+
application/x-tiddler-dictionary: the tiddler is parsed as sequence of name:value pairs
|
|
51
|
+
|
|
52
|
+
Other types currently just return undefined or as same as fallbackData.
|
|
53
|
+
|
|
54
|
+
titleOrTiddler: string tiddler title or a tiddler object
|
|
55
|
+
defaultData: default data to be returned if the tiddler is missing or doesn't contain data
|
|
56
|
+
|
|
57
|
+
Alternative, uncached version of getTiddlerDataCached(). The return value can be mutated freely and reused
|
|
58
|
+
*/
|
|
59
|
+
getTiddlerData<D extends Record<string, unknown> | undefined>(titleOrTiddler: string, fallbackData?: D): D;
|
|
60
|
+
getTiddlerData<D extends Record<string, unknown> | undefined>(titleOrTiddler: Tiddler, fallbackData?: D): D;
|
|
61
|
+
/**
|
|
62
|
+
Get the content of a tiddler as a JavaScript object. How this is done depends on the type of the tiddler:
|
|
63
|
+
|
|
64
|
+
application/json: the tiddler JSON is parsed into an object
|
|
65
|
+
application/x-tiddler-dictionary: the tiddler is parsed as sequence of name:value pairs
|
|
66
|
+
|
|
67
|
+
Other types currently just return undefined or as same as fallbackData.
|
|
68
|
+
|
|
69
|
+
titleOrTiddler: string tiddler title or a tiddler object
|
|
70
|
+
defaultData: default data to be returned if the tiddler is missing or doesn't contain data
|
|
71
|
+
|
|
72
|
+
Note that the same value is returned for repeated calls for the same tiddler data. The value is frozen to prevent modification; otherwise modifications would be visible to all callers
|
|
73
|
+
*/
|
|
74
|
+
getTiddlerDataCached<D extends Record<string, unknown> | undefined>(titleOrTiddler: string, fallbackData?: D): D;
|
|
75
|
+
getTiddlerDataCached<D extends Record<string, unknown> | undefined>(titleOrTiddler: Tiddler, fallbackData?: D): D;
|
|
41
76
|
/**
|
|
42
77
|
* Set tiddler text of any field.
|
|
43
78
|
*
|
|
@@ -50,5 +85,19 @@ declare module 'tiddlywiki' {
|
|
|
50
85
|
setText: (title: string, field?: string, index?: string | undefined, value?: string, options?: any) => void;
|
|
51
86
|
parseTiddler(title: string, options?: IParserOptions): WikiParser;
|
|
52
87
|
parseText(type: string, text: string, options?: IParserOptions): WikiParser;
|
|
88
|
+
/*
|
|
89
|
+
Parse text from a tiddler and render it into another format
|
|
90
|
+
outputType: content type for the output
|
|
91
|
+
title: title of the tiddler to be rendered
|
|
92
|
+
options: see below
|
|
93
|
+
Options include:
|
|
94
|
+
variables: hashmap of variables to set
|
|
95
|
+
parentWidget: optional parent widget for the root node
|
|
96
|
+
*/
|
|
97
|
+
renderTiddler(
|
|
98
|
+
outputType: 'text/html' | 'text/plain-formatted' | 'text/plain',
|
|
99
|
+
title: string,
|
|
100
|
+
options?: { parentWidget?: Widget; variables?: Record<string, any> },
|
|
101
|
+
): string;
|
|
53
102
|
}
|
|
54
103
|
}
|
package/src/ast.d.ts
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
declare module 'tiddlywiki' {
|
|
2
2
|
export interface IParseTreeAttribute {
|
|
3
|
-
|
|
3
|
+
end?: number;
|
|
4
4
|
name?: string;
|
|
5
|
+
start?: number;
|
|
5
6
|
type: 'string' | 'number';
|
|
6
7
|
value: string;
|
|
7
|
-
end?: number;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export interface IWikiASTNode {
|
|
11
|
-
|
|
11
|
+
attributes?: Record<string, IParseTreeAttribute>;
|
|
12
12
|
children?: IParseTreeNode[];
|
|
13
|
-
start?: number;
|
|
14
13
|
end?: number;
|
|
15
14
|
isBlock?: boolean;
|
|
16
15
|
isSelfClosing?: boolean;
|
|
17
|
-
attributes?: Record<string, IParseTreeAttribute>;
|
|
18
16
|
orderedAttributes?: IParseTreeAttribute[];
|
|
17
|
+
start?: number;
|
|
18
|
+
type: string;
|
|
19
19
|
}
|
|
20
20
|
export interface ITextParseTreeNode extends IWikiASTNode {
|
|
21
|
-
type: 'text';
|
|
22
21
|
text: string;
|
|
22
|
+
type: 'text';
|
|
23
23
|
}
|
|
24
24
|
export interface ILinkParseTreeNode extends IWikiASTNode {
|
|
25
|
-
type: 'link';
|
|
26
25
|
text: string;
|
|
26
|
+
type: 'link';
|
|
27
27
|
}
|
|
28
28
|
export type HTMLTags = keyof HTMLElementTagNameMap | 'strike';
|
|
29
29
|
|
|
30
30
|
export interface IDomParseTreeNode extends IWikiASTNode {
|
|
31
|
-
type: 'element';
|
|
32
31
|
tag: HTMLTags;
|
|
32
|
+
type: 'element';
|
|
33
33
|
}
|
|
34
34
|
export interface ICodeBlockParseTreeNode extends IWikiASTNode {
|
|
35
|
-
type: 'codeblock';
|
|
36
35
|
attributes: {
|
|
37
36
|
code?:
|
|
38
37
|
| {
|
|
@@ -47,22 +46,23 @@ declare module 'tiddlywiki' {
|
|
|
47
46
|
}
|
|
48
47
|
| undefined;
|
|
49
48
|
};
|
|
49
|
+
type: 'codeblock';
|
|
50
50
|
}
|
|
51
|
-
export interface
|
|
51
|
+
export interface IMacroParameterCallParseTreeNode extends IWikiASTNode {
|
|
52
|
+
name?: string;
|
|
52
53
|
type: 'macro-parameter';
|
|
53
54
|
value: string;
|
|
54
|
-
name?: string;
|
|
55
55
|
}
|
|
56
56
|
export interface IMacroCallParseTreeNode extends IWikiASTNode {
|
|
57
|
-
type: 'macrocall';
|
|
58
57
|
name: string;
|
|
59
|
-
params:
|
|
58
|
+
params: IMacroParameterCallParseTreeNode[];
|
|
59
|
+
type: 'macrocall';
|
|
60
60
|
}
|
|
61
61
|
export interface ICustomParseTreeNode extends IWikiASTNode {
|
|
62
|
-
|
|
62
|
+
params: IMacroParameterCallParseTreeNode[];
|
|
63
63
|
tag?: string;
|
|
64
|
-
params: IMacroParamCallParseTreeNode[];
|
|
65
64
|
text?: string;
|
|
65
|
+
type: string;
|
|
66
66
|
}
|
|
67
|
-
export type IParseTreeNode = IDomParseTreeNode |
|
|
67
|
+
export type IParseTreeNode = IDomParseTreeNode | IMacroParameterCallParseTreeNode | IMacroCallParseTreeNode | ITextParseTreeNode | ICustomParseTreeNode;
|
|
68
68
|
}
|
package/src/filter-operator.d.ts
CHANGED
|
@@ -93,7 +93,10 @@ Either way, we could interpret the `!` flag on the filter, if present, to mean t
|
|
|
93
93
|
As with [JavaScript Macros](#JavaScript%20Macros), filter operators should not make modifications to tiddlers, but only return a list of tiddlers or a tiddler iterator.
|
|
94
94
|
|
|
95
95
|
*/
|
|
96
|
-
export type IFilterOperator = (
|
|
96
|
+
export type IFilterOperator = (
|
|
97
|
+
source: (iter: SourceIterator) => void,
|
|
98
|
+
operator: IFilterOperatorParameterOperator,
|
|
99
|
+
) => string[] | ((iter: SourceIterator) => void);
|
|
97
100
|
|
|
98
101
|
/**
|
|
99
102
|
* A [tiddler iterator](#Tiddler%20Iterators) representing the results of the previous filter step (or all tiddlers, if this filter appears first in an expression), conventionally named `source`.
|
package/src/index.d.ts
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
/// <reference path="tw.d.ts" />
|
|
2
|
-
|
|
3
|
-
export * from 'tiddlywiki';
|
|
2
|
+
/// <reference path="server.d.ts" />
|
|
4
3
|
|
|
5
4
|
import * as TW from 'tiddlywiki';
|
|
6
5
|
|
|
7
|
-
|
|
6
|
+
export * from 'tiddlywiki';
|
|
8
7
|
declare global {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
declare module '@types/tiddlywiki' {
|
|
23
|
-
export const TiddlyWiki: TW.TW5InitFunction;
|
|
8
|
+
const $tw: TW.ITiddlyWiki;
|
|
9
|
+
// const Buffer: ?Buffer;
|
|
10
|
+
// const clearInterval: typeof global.clearInterval;
|
|
11
|
+
// const clearTimeout: typeof global.clearTimeout;
|
|
12
|
+
// const console: Console;
|
|
13
|
+
// const exports: TW.ITWModuleExports;
|
|
14
|
+
// const module: { exports: TW.ITWModuleExports; readonly id: string };
|
|
15
|
+
// const process: ?NodeJS.Process;
|
|
16
|
+
// const require: ITWRequire;
|
|
17
|
+
// const setInterval: typeof global.setInterval;
|
|
18
|
+
// const setTimeout: typeof global.setTimeout;
|
|
24
19
|
}
|
package/src/modules.d.ts
CHANGED
|
@@ -69,7 +69,7 @@ declare module 'tiddlywiki' {
|
|
|
69
69
|
* @param {(title, moduleExports) => void} callback function called as callback(title,moduleExports) for each module
|
|
70
70
|
* @memberof ITWModules
|
|
71
71
|
*/
|
|
72
|
-
forEachModuleOfType(moduleType: string, callback: (title, moduleExports) => void): void;
|
|
72
|
+
forEachModuleOfType(moduleType: string, callback: (title: string, moduleExports: unknown) => void): void;
|
|
73
73
|
/** Get all the modules of a particular type in a hashmap by their `name` field */
|
|
74
74
|
getModulesByTypeAsHashmap(moduleType: string, nameField: string): Record<string, IModuleInfo>;
|
|
75
75
|
/** hashmap by module name of moduleInfo */
|
package/src/parser.d.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
declare module 'tiddlywiki' {
|
|
4
4
|
export interface IParserOptions {
|
|
5
|
-
/**
|
|
6
|
-
* While calling `getCacheForTiddler`, use inlineParseTree or blockParseTree
|
|
7
|
-
*/
|
|
8
|
-
parseAsInline?: boolean;
|
|
9
5
|
/**
|
|
10
6
|
* Optional source uri, used in parseText
|
|
11
7
|
*/
|
|
12
8
|
_canonical_uri?: string;
|
|
9
|
+
/**
|
|
10
|
+
* While calling `getCacheForTiddler`, use inlineParseTree or blockParseTree
|
|
11
|
+
*/
|
|
12
|
+
parseAsInline?: boolean;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
export class WikiParseRule {
|
|
@@ -20,18 +20,18 @@ declare module 'tiddlywiki' {
|
|
|
20
20
|
nextTag?: null;
|
|
21
21
|
/** `{type: 'macrocall', start: 261, params: Array(1), name: 'reuse-tiddler', end: 290}` */
|
|
22
22
|
nextCall?: {
|
|
23
|
-
type: string;
|
|
24
|
-
start: number;
|
|
25
23
|
end: number;
|
|
26
|
-
/** `{ type: 'macro-parameter'; start: 276; value: '快速创建新笔记按钮'; end: 288 }` */
|
|
27
|
-
params: { type: string; start: number; end: number; value: string };
|
|
28
24
|
name: string;
|
|
25
|
+
/** `{ type: 'macro-parameter'; start: 276; value: '快速创建新笔记按钮'; end: 288 }` */
|
|
26
|
+
params: { end: number; start: number; type: string; value: string };
|
|
27
|
+
start: number;
|
|
28
|
+
type: string;
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
export class WikiParser {
|
|
32
|
-
blockRules: { rule: WikiParseRule
|
|
33
|
-
inlineRules: { rule: WikiParseRule
|
|
34
|
-
pragmaRules: { rule: WikiParseRule
|
|
32
|
+
blockRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
|
|
33
|
+
inlineRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
|
|
34
|
+
pragmaRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
|
|
35
35
|
configTrimWhiteSpace: boolean;
|
|
36
36
|
pos: number;
|
|
37
37
|
source: string;
|
package/src/server.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/// <reference path="Wiki.d.ts" />
|
|
2
|
+
|
|
3
|
+
import type Http from 'http';
|
|
4
|
+
|
|
5
|
+
declare module 'tiddlywiki' {
|
|
6
|
+
export interface IServerStatus {
|
|
7
|
+
anonymous: boolean;
|
|
8
|
+
read_only: boolean;
|
|
9
|
+
space: {
|
|
10
|
+
recipe: string;
|
|
11
|
+
};
|
|
12
|
+
tiddlywiki_version: string;
|
|
13
|
+
username: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface IRoute {
|
|
17
|
+
handler: ServerEndpointHandler;
|
|
18
|
+
method: 'GET' | 'POST' | 'DELETE' | 'PUT' | 'OPTIONS' | 'HEAD';
|
|
19
|
+
path: RegExp;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface IServerOptions {
|
|
23
|
+
routes: IRoute[];
|
|
24
|
+
variables?: { [key: string]: string };
|
|
25
|
+
wiki: Wiki;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
A simple HTTP server with regexp-based routes
|
|
30
|
+
|
|
31
|
+
options: variables - optional hashmap of variables to set (a misnomer - they are really constant parameters)
|
|
32
|
+
routes - optional array of routes to use
|
|
33
|
+
wiki - reference to wiki object
|
|
34
|
+
*/
|
|
35
|
+
export class Server {
|
|
36
|
+
constructor(options: IServerOptions);
|
|
37
|
+
routes: IRoute[];
|
|
38
|
+
addRoute(route: IRoute): void;
|
|
39
|
+
/**
|
|
40
|
+
* ```json
|
|
41
|
+
* {
|
|
42
|
+
port: "8080",
|
|
43
|
+
host: "127.0.0.1",
|
|
44
|
+
"required-plugins": "$:/plugins/tiddlywiki/filesystem,$:/plugins/tiddlywiki/tiddlyweb",
|
|
45
|
+
"root-tiddler": "$:/core/save/all",
|
|
46
|
+
"root-render-type": "text/plain",
|
|
47
|
+
"root-serve-type": "text/html",
|
|
48
|
+
"tiddler-render-type": "text/html",
|
|
49
|
+
"tiddler-render-template": "$:/core/templates/server/static.tiddler.html",
|
|
50
|
+
"system-tiddler-render-type": "text/plain",
|
|
51
|
+
"system-tiddler-render-template": "$:/core/templates/wikified-tiddler",
|
|
52
|
+
"debug-level": "none",
|
|
53
|
+
"gzip": "no",
|
|
54
|
+
"use-browser-cache": "no"
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
*/
|
|
58
|
+
defaultVariables: {
|
|
59
|
+
'debug-level': string;
|
|
60
|
+
gzip: string;
|
|
61
|
+
host: string;
|
|
62
|
+
port: string;
|
|
63
|
+
'required-plugins': string;
|
|
64
|
+
'root-render-type': string;
|
|
65
|
+
'root-serve-type': string;
|
|
66
|
+
'root-tiddler': string;
|
|
67
|
+
'system-tiddler-render-template': string;
|
|
68
|
+
'system-tiddler-render-type': string;
|
|
69
|
+
'tiddler-render-template': string;
|
|
70
|
+
'tiddler-render-type': string;
|
|
71
|
+
'use-browser-cache': string;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
variables: Record<string, any>;
|
|
75
|
+
get(variableName: string): any;
|
|
76
|
+
requestHandler: ServerEndpointHandler;
|
|
77
|
+
/*
|
|
78
|
+
Listen for requests
|
|
79
|
+
port: optional port number (falls back to value of "port" variable)
|
|
80
|
+
host: optional host address (falls back to value of "host" variable)
|
|
81
|
+
prefix: optional prefix (falls back to value of "path-prefix" variable)
|
|
82
|
+
*/
|
|
83
|
+
listen(port?: string, host?: string, prefix?: string): void;
|
|
84
|
+
/*
|
|
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
|
+
*/
|
|
87
|
+
isAuthorized(authorizationType: 'readers' | 'writers', username?: string | undefined): boolean;
|
|
88
|
+
close(): void;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface ServerEndpointContext {
|
|
92
|
+
authenticatedUsername: string | undefined;
|
|
93
|
+
data: string;
|
|
94
|
+
server: Server;
|
|
95
|
+
wiki: Wiki;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @link https://talk.tiddlywiki.org/t/what-is-the-state-in-server-route-handler/2877
|
|
99
|
+
*/
|
|
100
|
+
export type ServerEndpointHandler<T = Record<string, unknown>> = (
|
|
101
|
+
request: Http.ClientRequest,
|
|
102
|
+
response: Http.ServerResponse,
|
|
103
|
+
context: ServerEndpointContext & T,
|
|
104
|
+
) => void;
|
|
105
|
+
}
|
package/src/tw.d.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
/// <reference path="parser.d.ts" />
|
|
9
9
|
/// <reference path="ast.d.ts" />
|
|
10
10
|
|
|
11
|
+
import { Server } from 'http';
|
|
12
|
+
|
|
11
13
|
declare module 'tiddlywiki' {
|
|
12
14
|
export interface IBootFilesIndexItem {
|
|
13
15
|
filepath: string;
|
|
@@ -24,8 +26,6 @@ declare module 'tiddlywiki' {
|
|
|
24
26
|
tiddlers: ITiddlerFields[];
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
export class Server {}
|
|
28
|
-
|
|
29
29
|
export interface IFileExtensionInfo {
|
|
30
30
|
type: string;
|
|
31
31
|
}
|
|
@@ -43,11 +43,11 @@ declare module 'tiddlywiki' {
|
|
|
43
43
|
|
|
44
44
|
boot: {
|
|
45
45
|
argv: string[];
|
|
46
|
+
boot(callback?: () => unknown): void;
|
|
46
47
|
files: IBootFilesIndex;
|
|
47
48
|
log(logString: string): void;
|
|
48
49
|
logMessages: string[];
|
|
49
50
|
startup(options: { callback?: () => unknown }): void;
|
|
50
|
-
boot(callback?: () => unknown): void;
|
|
51
51
|
/** Default boot tasks */
|
|
52
52
|
tasks: {
|
|
53
53
|
readBrowserTiddlers: boolean;
|
package/src/utils.d.ts
CHANGED
|
@@ -6,15 +6,15 @@ declare module 'tiddlywiki' {
|
|
|
6
6
|
export type TWDOMElement = Element;
|
|
7
7
|
export type TWEachCallback<T> = (element?: unknown, index?: string | number, object?: T) => boolean | undefined;
|
|
8
8
|
export interface ITWUtils {
|
|
9
|
+
Crypto: typeof Crypto;
|
|
10
|
+
PasswordPrompt: typeof PasswordPrompt;
|
|
9
11
|
/**
|
|
10
12
|
* Alternative to `element.classList.add`, add a css class name to an element, see issue for detail.
|
|
11
13
|
* @link https://github.com/Jermolene/TiddlyWiki5/issues/6475
|
|
12
|
-
* @param element
|
|
13
|
-
* @param className
|
|
14
|
+
* @param element
|
|
15
|
+
* @param className
|
|
14
16
|
*/
|
|
15
17
|
addClass(element: Element, className: string): void;
|
|
16
|
-
Crypto: typeof Crypto;
|
|
17
|
-
PasswordPrompt: typeof PasswordPrompt;
|
|
18
18
|
/** Returns true if the version string A is greater than the version string B. Returns true if the versions are the same */
|
|
19
19
|
checkVersions(versionStringA: string, versionStringB: string): boolean;
|
|
20
20
|
/**
|
|
@@ -26,6 +26,8 @@ declare module 'tiddlywiki' {
|
|
|
26
26
|
decodeURIComponentSafe(uri: string): string;
|
|
27
27
|
/** Convert a URI encoded string to a string safely */
|
|
28
28
|
decodeURISafe(uri: string): string;
|
|
29
|
+
/** the function behind `<<now "format">> */
|
|
30
|
+
formatDateString(date: Date, format: string): string;
|
|
29
31
|
/** 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 */
|
|
30
32
|
deepDefaults(object: object, ...sourceObjectList: object[]): object;
|
|
31
33
|
/**
|
|
@@ -102,6 +104,7 @@ declare module 'tiddlywiki' {
|
|
|
102
104
|
parseDate(value: string | Date): Date;
|
|
103
105
|
/** Parse a block of name:value fields. The `fields` object is used as the basis for the return value */
|
|
104
106
|
parseFields(text: string, fields?: object): object;
|
|
107
|
+
parseJSONSafe(input: string): any;
|
|
105
108
|
/** Parse a string array from a bracketted list. For example "OneTiddler [[Another Tiddler]] LastOne" */
|
|
106
109
|
parseStringArray(value: string | string[], allowDuplicate?: boolean): string[];
|
|
107
110
|
/** Parse a semantic version string into its constituent parts -- see https://semver.org */
|
package/src/widget.d.ts
CHANGED
|
@@ -8,6 +8,29 @@ declare module 'tiddlywiki' {
|
|
|
8
8
|
modified: boolean;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
export interface IWidgetEvent {
|
|
12
|
+
/** widget event can carry any other parameters
|
|
13
|
+
*
|
|
14
|
+
* For example, `<$action-sendmessage $message="tw-mobile-sync-set-active-server-and-sync" title={{!!title}} />` will produce `paramObject: { title: "xxxx" }`
|
|
15
|
+
*/
|
|
16
|
+
paramObject?: {
|
|
17
|
+
[othersParamKeys: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Get `$param`
|
|
21
|
+
*/
|
|
22
|
+
param?: string | undefined;
|
|
23
|
+
/** the first parameter of addEventListener
|
|
24
|
+
*
|
|
25
|
+
* For example, the `'open-command-palette'` in `$tw.rootWidget.addEventListener('open-command-palette', (e: IWidgetEvent) => this.openPalette(e));`
|
|
26
|
+
*/
|
|
27
|
+
type: string;
|
|
28
|
+
widget: Widget;
|
|
29
|
+
/** maybe a DOM click event, if trigger by button click */
|
|
30
|
+
event: Event;
|
|
31
|
+
navigateFromTitle?: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
11
34
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
12
35
|
class variablesConstructor {}
|
|
13
36
|
|
|
@@ -24,17 +47,17 @@ declare module 'tiddlywiki' {
|
|
|
24
47
|
variables: unknown;
|
|
25
48
|
domNodes: Node[];
|
|
26
49
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
addEventListener(type: string, handler: (
|
|
50
|
+
Add an event listener
|
|
51
|
+
*/
|
|
52
|
+
addEventListener(type: string, handler: (event: IWidgetEvent) => void | Promise<void>): void;
|
|
30
53
|
/**
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
dispatchEvent(
|
|
54
|
+
Dispatch an event to a widget. If the widget doesn't handle the event then it is also dispatched to the parent widget
|
|
55
|
+
*/
|
|
56
|
+
dispatchEvent(typeOrEvent: string | Omit<IWidgetEvent, 'widget'>): void;
|
|
34
57
|
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
addEventListeners(listeners: Array<{ handler: (
|
|
58
|
+
Add a list of event listeners from an array [{type:,handler:},...]
|
|
59
|
+
*/
|
|
60
|
+
addEventListeners(listeners: Array<{ handler: (event: IWidgetEvent) => void | Promise<void>; type: string }>): void;
|
|
38
61
|
|
|
39
62
|
parentDomNode: Node;
|
|
40
63
|
execute: () => void;
|