tw5-typed 0.1.5 → 0.1.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/README.md +7 -1
- package/package.json +1 -1
- package/src/Wiki.d.ts +6 -2
- package/src/ast.d.ts +48 -0
- package/src/parser.d.ts +48 -0
- package/src/tw.d.ts +4 -0
package/README.md
CHANGED
|
@@ -49,7 +49,13 @@ You can add new `*.d.ts` file to contain your types:
|
|
|
49
49
|
1. use `declare module 'tiddlywiki' { }` to wrap all your types.
|
|
50
50
|
1. don't forget to `export` all your types.
|
|
51
51
|
1. to add type for global variable, add `global { }` inside that `declare module 'tiddlywiki' { }`, like `global { var $tw: I$TW; }`
|
|
52
|
+
1. add type import like `/// <reference path="ast.d.ts" />` in the `tw.d.ts`
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
### Importing type from other files
|
|
55
|
+
|
|
56
|
+
- add type import like `/// <reference path="parser.d.ts" />`
|
|
57
|
+
- using normal import, like `import { parse } from './parser';` will not work
|
|
58
|
+
|
|
59
|
+
### Test in your node_modules
|
|
54
60
|
|
|
55
61
|
To rapid prototype the type, just right click a type to open `.d.ts` file in the `node_modules`, and try create new file there, and copy to this repo after a success.
|
package/package.json
CHANGED
package/src/Wiki.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference path="parser.d.ts" />
|
|
2
|
+
|
|
1
3
|
declare module 'tiddlywiki' {
|
|
2
4
|
export class Wiki {
|
|
3
5
|
/**
|
|
@@ -7,7 +9,7 @@ declare module 'tiddlywiki' {
|
|
|
7
9
|
* @memberof Wiki
|
|
8
10
|
*/
|
|
9
11
|
constructor(options: { enableIndexers: unknown[] });
|
|
10
|
-
addIndexer(indexer, name): void;
|
|
12
|
+
addIndexer(indexer: unknown, name: string): void;
|
|
11
13
|
getTiddler: (title: string) => Tiddler | undefined;
|
|
12
14
|
/**
|
|
13
15
|
* Get full list of tiddler titles in the wiki
|
|
@@ -30,7 +32,7 @@ declare module 'tiddlywiki' {
|
|
|
30
32
|
/**
|
|
31
33
|
* Get tiddler's text field, with an optional default text.
|
|
32
34
|
* If have _is_skinny field, will just return null (this is a rare case, so not put in the return type for now).
|
|
33
|
-
*
|
|
35
|
+
*
|
|
34
36
|
* @param title will return undefined (or fallback) if the tiddler isn't found
|
|
35
37
|
* @param fallbackText default text when text field is empty or undefined
|
|
36
38
|
*/
|
|
@@ -46,5 +48,7 @@ declare module 'tiddlywiki' {
|
|
|
46
48
|
* @param {object} options options, see tiddlywiki dev doc for details
|
|
47
49
|
*/
|
|
48
50
|
setText: (title: string, field?: string, index?: string | undefined, value?: string, options?: any) => void;
|
|
51
|
+
parseTiddler(title: string, options?: IParserOptions): WikiParser;
|
|
52
|
+
parseText(type: string, text: string, options?: IParserOptions): WikiParser;
|
|
49
53
|
}
|
|
50
54
|
}
|
package/src/ast.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
export interface IParseTreeAttribute {
|
|
3
|
+
start: number;
|
|
4
|
+
name: string;
|
|
5
|
+
type: 'string' | 'number';
|
|
6
|
+
value: string;
|
|
7
|
+
end: number;
|
|
8
|
+
}
|
|
9
|
+
export interface IWikiASTNode {
|
|
10
|
+
type: string;
|
|
11
|
+
children?: IParseTreeNode[];
|
|
12
|
+
start?: number;
|
|
13
|
+
end?: number;
|
|
14
|
+
isBlock?: boolean;
|
|
15
|
+
isSelfClosing?: boolean;
|
|
16
|
+
attributes?: Record<string, IParseTreeAttribute>;
|
|
17
|
+
orderedAttributes?: IParseTreeAttribute[];
|
|
18
|
+
}
|
|
19
|
+
export interface ITextParseTreeNode extends IWikiASTNode {
|
|
20
|
+
type: 'text';
|
|
21
|
+
text: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ILinkParseTreeNode extends IWikiASTNode {
|
|
24
|
+
type: 'link';
|
|
25
|
+
text: string;
|
|
26
|
+
}
|
|
27
|
+
export interface IDomParseTreeNode extends IWikiASTNode {
|
|
28
|
+
type: 'element';
|
|
29
|
+
tag: string;
|
|
30
|
+
}
|
|
31
|
+
export interface IMacroParamCallParseTreeNode extends IWikiASTNode {
|
|
32
|
+
type: 'macro-parameter';
|
|
33
|
+
value: string;
|
|
34
|
+
name?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface IMacroCallParseTreeNode extends IWikiASTNode {
|
|
37
|
+
type: 'macrocall';
|
|
38
|
+
name: string;
|
|
39
|
+
params: IMacroParamCallParseTreeNode[];
|
|
40
|
+
}
|
|
41
|
+
export interface ICustomParseTreeNode extends IWikiASTNode {
|
|
42
|
+
type: string;
|
|
43
|
+
tag?: string;
|
|
44
|
+
params: IMacroParamCallParseTreeNode[];
|
|
45
|
+
text?: string;
|
|
46
|
+
}
|
|
47
|
+
export type IParseTreeNode = IDomParseTreeNode | IMacroParamCallParseTreeNode | IMacroCallParseTreeNode | ICustomParseTreeNode;
|
|
48
|
+
}
|
package/src/parser.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
export interface IParserOptions {
|
|
3
|
+
/**
|
|
4
|
+
* While calling `getCacheForTiddler`, use inlineParseTree or blockParseTree
|
|
5
|
+
*/
|
|
6
|
+
parseAsInline?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Optional source uri, used in parseText
|
|
9
|
+
*/
|
|
10
|
+
_canonical_uri?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export declare class WikiParseRule {
|
|
14
|
+
is: { block?: boolean; inline?: boolean };
|
|
15
|
+
match?: null;
|
|
16
|
+
matchRegExp?: RegExp;
|
|
17
|
+
parser?: WikiParser;
|
|
18
|
+
nextTag?: null;
|
|
19
|
+
/** `{type: 'macrocall', start: 261, params: Array(1), name: 'reuse-tiddler', end: 290}` */
|
|
20
|
+
nextCall?: {
|
|
21
|
+
type: string;
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
/** `{ type: 'macro-parameter'; start: 276; value: '快速创建新笔记按钮'; end: 288 }` */
|
|
25
|
+
params: { type: string; start: number; end: number; value: string };
|
|
26
|
+
name: string;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export interface IParseTreeAttribute {
|
|
30
|
+
start: number;
|
|
31
|
+
name: string;
|
|
32
|
+
type: 'string' | 'number';
|
|
33
|
+
value: string;
|
|
34
|
+
end: number;
|
|
35
|
+
}
|
|
36
|
+
export declare class WikiParser {
|
|
37
|
+
blockRules: { rule: WikiParseRule; matchIndex?: number }[];
|
|
38
|
+
inlineRules: { rule: WikiParseRule; matchIndex?: number }[];
|
|
39
|
+
pragmaRules: { rule: WikiParseRule; matchIndex?: number }[];
|
|
40
|
+
configTrimWhiteSpace: boolean;
|
|
41
|
+
pos: number;
|
|
42
|
+
source: string;
|
|
43
|
+
sourceLength: number;
|
|
44
|
+
type: string;
|
|
45
|
+
wiki: Wiki;
|
|
46
|
+
tree: IParseTreeNode[];
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/tw.d.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
/// <reference path="utils.d.ts" />
|
|
6
6
|
/// <reference path="Widget.d.ts" />
|
|
7
7
|
/// <reference path="Wiki.d.ts" />
|
|
8
|
+
/// <reference path="parser.d.ts" />
|
|
9
|
+
/// <reference path="ast.d.ts" />
|
|
8
10
|
|
|
9
11
|
declare module 'tiddlywiki' {
|
|
10
12
|
export interface IBootFilesIndexItem {
|
|
@@ -22,6 +24,8 @@ declare module 'tiddlywiki' {
|
|
|
22
24
|
tiddlers: ITiddlerFields[];
|
|
23
25
|
}
|
|
24
26
|
|
|
27
|
+
export class Server {}
|
|
28
|
+
|
|
25
29
|
export interface IFileExtensionInfo {
|
|
26
30
|
type: string;
|
|
27
31
|
}
|