tw5-typed 0.0.6 → 0.0.7
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 +18 -0
- package/package.json +27 -4
- package/src/tw.d.ts +147 -16
- package/src/widget.d.ts +13 -0
package/README.md
CHANGED
|
@@ -26,8 +26,24 @@ Then you will have global types like `$tw` automatically. You can import the res
|
|
|
26
26
|
import type { ISearchOptions, SourceIterator, IFilterOperatorParamOperator } from 'tiddlywiki';
|
|
27
27
|
```
|
|
28
28
|
|
|
29
|
+
### Alias
|
|
30
|
+
|
|
31
|
+
Sometimes you may want to use a modified version of tw, you can re-export types like this in your `src/type.d.ts`:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
declare module '@tiddlygit/tiddlywiki' {
|
|
35
|
+
export * from 'tiddlywiki';
|
|
36
|
+
}
|
|
37
|
+
```
|
|
38
|
+
|
|
29
39
|
## Development
|
|
30
40
|
|
|
41
|
+
Firstly, Install eslint using npm:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npm i
|
|
45
|
+
```
|
|
46
|
+
|
|
31
47
|
You can add new `*.d.ts` file to contain your types:
|
|
32
48
|
|
|
33
49
|
1. use `declare module 'tiddlywiki' { }` to wrap all your types.
|
|
@@ -35,3 +51,5 @@ You can add new `*.d.ts` file to contain your types:
|
|
|
35
51
|
1. to add type for global variable, add `global { }` inside that `declare module 'tiddlywiki' { }`, like `global { var $tw: I$TW; }`
|
|
36
52
|
|
|
37
53
|
And add `import './xxx';` in the `index.d.ts` file.
|
|
54
|
+
|
|
55
|
+
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
|
@@ -2,16 +2,39 @@
|
|
|
2
2
|
"description": "Types for tiddlywiki",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "tw5-typed",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.7",
|
|
6
6
|
"url": "https://github.com/tiddly-gittly/tw5-typed",
|
|
7
|
+
"homepage": "https://github.com/tiddly-gittly/tw5-typed",
|
|
8
|
+
"bugs": {
|
|
9
|
+
"url": "https://github.com/tiddly-gittly/tw5-typed/issues"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/tiddly-gittly/tw5-typed.git"
|
|
14
|
+
},
|
|
7
15
|
"types": "src/index.d.ts",
|
|
8
16
|
"files": [
|
|
9
17
|
"src/"
|
|
10
18
|
],
|
|
11
|
-
"
|
|
12
|
-
|
|
19
|
+
"scripts": {
|
|
20
|
+
"prepublishOnly": "npx tsc --noEmit"
|
|
21
|
+
},
|
|
13
22
|
"devDependencies": {
|
|
14
|
-
"typescript": "
|
|
23
|
+
"@typescript-eslint/eslint-plugin": "5.10.2",
|
|
24
|
+
"@typescript-eslint/parser": "5.10.2",
|
|
25
|
+
"typescript": "4.5.5",
|
|
26
|
+
"eslint": "8.8.0",
|
|
27
|
+
"eslint-config-prettier": "8.3.0",
|
|
28
|
+
"eslint-config-standard": "17.0.0-1",
|
|
29
|
+
"eslint-config-standard-with-typescript": "21.0.1",
|
|
30
|
+
"eslint-import-resolver-alias": "1.1.2",
|
|
31
|
+
"eslint-import-resolver-typescript": "2.5.0",
|
|
32
|
+
"eslint-plugin-import": "2.25.4",
|
|
33
|
+
"eslint-plugin-node": "11.1.0",
|
|
34
|
+
"eslint-plugin-prettier": "4.0.0",
|
|
35
|
+
"eslint-plugin-typescript-sort-keys": "2.1.0",
|
|
36
|
+
"eslint-plugin-unicorn": "40.1.0",
|
|
37
|
+
"prettier": "2.5.1"
|
|
15
38
|
},
|
|
16
39
|
"dependencies": {}
|
|
17
40
|
}
|
package/src/tw.d.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
declare module 'tiddlywiki' {
|
|
2
2
|
export interface ITiddler {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
constructor(...fields: (Record<string, unknown> | ITiddler)[]);
|
|
4
|
+
readonly cache: ITiddlerCache;
|
|
5
|
+
readonly fields: ITiddlerFields;
|
|
6
|
+
// static fieldModules: IModule;
|
|
7
|
+
hasField(field: string): boolean;
|
|
8
|
+
isEqual(tiddler: ITiddler, excludeFields: string[]): boolean;
|
|
5
9
|
}
|
|
6
10
|
|
|
7
11
|
export interface ITiddlerFields {
|
|
8
|
-
created:
|
|
9
|
-
list: string[];
|
|
10
|
-
modified:
|
|
11
|
-
tags: string[];
|
|
12
|
-
text: string;
|
|
13
|
-
title: string;
|
|
14
|
-
type: string;
|
|
15
|
-
|
|
12
|
+
readonly created: Date;
|
|
13
|
+
readonly list: string[];
|
|
14
|
+
readonly modified: Date;
|
|
15
|
+
readonly tags: string[];
|
|
16
|
+
readonly text: string;
|
|
17
|
+
readonly title: string;
|
|
18
|
+
readonly type: string;
|
|
19
|
+
readonly color: string;
|
|
20
|
+
readonly [anyKey: string]: unknown;
|
|
16
21
|
}
|
|
17
22
|
|
|
18
23
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
@@ -35,9 +40,71 @@ declare module 'tiddlywiki' {
|
|
|
35
40
|
*/
|
|
36
41
|
export type IBootFilesIndex = Partial<Record<string, IBootFilesIndexItem>>;
|
|
37
42
|
|
|
38
|
-
export interface
|
|
39
|
-
|
|
40
|
-
|
|
43
|
+
export interface IModule {
|
|
44
|
+
moduleType: string;
|
|
45
|
+
definition: unknown;
|
|
46
|
+
exports: object | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface TiddlyWiki {
|
|
50
|
+
boot: {
|
|
51
|
+
argv: string[];
|
|
52
|
+
files: IBootFilesIndex;
|
|
53
|
+
startup(options: { callback?: () => unknown }): void;
|
|
54
|
+
/** Default boot tasks */
|
|
55
|
+
tasks: {
|
|
56
|
+
trapErrors: boolean;
|
|
57
|
+
readBrowserTiddlers: boolean;
|
|
58
|
+
};
|
|
59
|
+
logMessages: string[];
|
|
60
|
+
log(str: string): void;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Broswer features, if tw isn't running on a browser environment, the value will be `null` */
|
|
64
|
+
browser: null | object;
|
|
65
|
+
/** NodeJS features, if tw isn't running on a NodeJS environment, the value will be `null` */
|
|
66
|
+
node: null | object;
|
|
67
|
+
nodeWebKit: null | object;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Information about each module is kept in an object with these members:
|
|
71
|
+
*
|
|
72
|
+
* * moduleType: type of module
|
|
73
|
+
* * definition: object, function or string defining the module; see below
|
|
74
|
+
* * exports: exports of the module, filled in after execution
|
|
75
|
+
*
|
|
76
|
+
* The `definition` can be of several types:
|
|
77
|
+
*
|
|
78
|
+
* * An object can be used to directly specify the exports of the module
|
|
79
|
+
* * A function with the arguments `module,require,exports` that returns `exports`
|
|
80
|
+
* * A string function body with the same arguments
|
|
81
|
+
*
|
|
82
|
+
* Each moduleInfo object is stored in two hashmaps: $tw.modules.titles and $tw.modules.types. The first is indexed by title and the second is indexed by type and then title
|
|
83
|
+
*/
|
|
84
|
+
modules: {
|
|
85
|
+
/** hashmap by module name of moduleInfo */
|
|
86
|
+
titles: Record<string, IModule>;
|
|
87
|
+
/** hashmap by module type and then name of moduleInfo */
|
|
88
|
+
types: Record<string, Record<string, IModule>>;
|
|
89
|
+
/**
|
|
90
|
+
* Define a JavaScript tiddler module for later execution
|
|
91
|
+
* @param {string} moduleName name of module being defined
|
|
92
|
+
* @param {string} moduleType type of module
|
|
93
|
+
* @param {unknown} definition module definition; see discussion above
|
|
94
|
+
*/
|
|
95
|
+
define(moduleName: string, moduleType: string, definition: unknown): void;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/** External JavaScript can populate this array before calling boot.js in order to preload tiddlers */
|
|
99
|
+
preloadTiddlers: Record<string, Record<string, unknown>>;
|
|
100
|
+
/** Convenience function for pushing a tiddler onto the preloading array */
|
|
101
|
+
preloadTiddler(fields: Record<string, unknown>): void;
|
|
102
|
+
/** Convenience function for pushing an array of tiddlers onto the preloading array */
|
|
103
|
+
preloadTiddlerArray(fieldsArray: Record<string, unknown>[]): void;
|
|
104
|
+
|
|
105
|
+
hooks: {
|
|
106
|
+
addHook: (hookName: string, callback: (...arguments_: any[]) => unknown) => void;
|
|
107
|
+
};
|
|
41
108
|
wiki: {
|
|
42
109
|
getTiddler: (title: string) => ITiddler | undefined;
|
|
43
110
|
/**
|
|
@@ -45,11 +112,75 @@ declare module 'tiddlywiki' {
|
|
|
45
112
|
*/
|
|
46
113
|
getTiddlers: () => string[];
|
|
47
114
|
};
|
|
48
|
-
utils:
|
|
115
|
+
utils: {
|
|
116
|
+
/** Check if an object has a property. */
|
|
117
|
+
hop(object: object, property: string): boolean;
|
|
118
|
+
/** Determine if a value is an array. */
|
|
119
|
+
isArray(value: unknown): boolean;
|
|
120
|
+
/** Check if an array is equal by value and by reference. */
|
|
121
|
+
isArrayEqual(array1: unknown[], array2: unknown[]): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* Push entries onto an array, removing them first if they already exist in the array
|
|
124
|
+
*
|
|
125
|
+
* * array: array to modify (assumed to be free of duplicates)
|
|
126
|
+
* * value: a single value to push or an array of values to push
|
|
127
|
+
*/
|
|
128
|
+
pushTop(array: unknown[], value: unknown): void;
|
|
129
|
+
/** Determine if a value is a date */
|
|
130
|
+
isDate(value: unknown): void;
|
|
131
|
+
/**
|
|
132
|
+
* Iterate through all the own properties of an object or array.
|
|
133
|
+
*
|
|
134
|
+
* Callback is invoked with (element, index, object), if callback returns false, then the each loop will be terminated.
|
|
135
|
+
* */
|
|
136
|
+
each<T = object | unknown[]>(object: T, callback: (element?: unknown, index?: string | number, object?: T) => boolean | void);
|
|
137
|
+
/**
|
|
138
|
+
* Helper for making DOM elements
|
|
139
|
+
* Options include:
|
|
140
|
+
* * namespace:
|
|
141
|
+
* * attributes: hashmap of attribute values
|
|
142
|
+
* * style: hashmap of styles
|
|
143
|
+
* * text: text to add as a child node
|
|
144
|
+
* * children: array of further child nodes
|
|
145
|
+
* * innerHTML: optional HTML for element
|
|
146
|
+
* * class: class name(s)
|
|
147
|
+
* * document: defaults to current document
|
|
148
|
+
* * eventListeners: array of event listeners (this option won't work until `$tw.utils.addEventListeners()` has been loaded)
|
|
149
|
+
*
|
|
150
|
+
* @param {string} tag tag name
|
|
151
|
+
* @param {{
|
|
152
|
+
* namespace?: string;
|
|
153
|
+
* attributes?: Record<string, unknown>;
|
|
154
|
+
* style?: Record<string, string>;
|
|
155
|
+
* text?: string;
|
|
156
|
+
* children?: Element[];
|
|
157
|
+
* innerHTML?: string;
|
|
158
|
+
* class?: string;
|
|
159
|
+
* document?: Document;
|
|
160
|
+
* eventListeners?: EventListener[];
|
|
161
|
+
* }} options
|
|
162
|
+
* @returns {Element}
|
|
163
|
+
*/
|
|
164
|
+
domMaker(
|
|
165
|
+
tag: string,
|
|
166
|
+
options: {
|
|
167
|
+
namespace?: string;
|
|
168
|
+
attributes?: Record<string, unknown>;
|
|
169
|
+
style?: Record<string, string>;
|
|
170
|
+
text?: string;
|
|
171
|
+
children?: Element[];
|
|
172
|
+
innerHTML?: string;
|
|
173
|
+
class?: string;
|
|
174
|
+
document?: Document;
|
|
175
|
+
eventListeners?: EventListener[];
|
|
176
|
+
},
|
|
177
|
+
): Element;
|
|
178
|
+
};
|
|
49
179
|
}
|
|
50
|
-
|
|
180
|
+
|
|
181
|
+
export function TiddlyWiki(): TiddlyWiki;
|
|
51
182
|
|
|
52
183
|
global {
|
|
53
|
-
|
|
184
|
+
const $tw: TiddlyWiki;
|
|
54
185
|
}
|
|
55
186
|
}
|
package/src/widget.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare class variablesConstructor {
|
|
2
|
+
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export class Widget {
|
|
6
|
+
constructor(parseTreeNode: any, options: any);
|
|
7
|
+
initialize: (parseTreeNode: any, options: any) => void;
|
|
8
|
+
parseTreeNode: any;
|
|
9
|
+
wiki: any;
|
|
10
|
+
parentWidget?: Widget;
|
|
11
|
+
variablesConstructor: variablesConstructor;
|
|
12
|
+
variables: any;
|
|
13
|
+
}
|