tw5-typed 0.0.4 → 0.0.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 +29 -1
- package/package.json +35 -6
- package/src/Crypto.d.ts +9 -0
- package/src/PasswordPrompt.d.ts +54 -0
- package/src/Tiddler.d.ts +25 -0
- package/src/Wiki.d.ts +17 -0
- package/src/filter-operator.d.ts +40 -38
- package/src/index.d.ts +4 -9
- package/src/modules.d.ts +80 -0
- package/src/tw.d.ts +75 -46
- package/src/twconfig.d.ts +40 -0
- package/src/utils.d.ts +144 -0
- package/src/widget.d.ts +12 -0
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Add `tw5-typed` to your `tsconfig.json`'s `compilerOptions`
|
|
|
15
15
|
```json
|
|
16
16
|
{
|
|
17
17
|
"compilerOptions": {
|
|
18
|
-
"types": ["node", "tw5-typed"] /* Type declaration files to be included in compilation.
|
|
18
|
+
"types": ["node", "tw5-typed"] /* Type declaration files to be included in compilation. */
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
```
|
|
@@ -23,5 +23,33 @@ Add `tw5-typed` to your `tsconfig.json`'s `compilerOptions`
|
|
|
23
23
|
Then you will have global types like `$tw` automatically. You can import the rest of the types using `import type` statement:
|
|
24
24
|
|
|
25
25
|
```typescript
|
|
26
|
+
import type { ISearchOptions, SourceIterator, IFilterOperatorParamOperator } from 'tiddlywiki';
|
|
27
|
+
```
|
|
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
|
+
```
|
|
26
38
|
|
|
39
|
+
## Development
|
|
40
|
+
|
|
41
|
+
Firstly, Install eslint using npm:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npm i
|
|
27
45
|
```
|
|
46
|
+
|
|
47
|
+
You can add new `*.d.ts` file to contain your types:
|
|
48
|
+
|
|
49
|
+
1. use `declare module 'tiddlywiki' { }` to wrap all your types.
|
|
50
|
+
1. don't forget to `export` all your types.
|
|
51
|
+
1. to add type for global variable, add `global { }` inside that `declare module 'tiddlywiki' { }`, like `global { var $tw: I$TW; }`
|
|
52
|
+
|
|
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,45 @@
|
|
|
2
2
|
"description": "Types for tiddlywiki",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "tw5-typed",
|
|
5
|
-
"version": "0.0.
|
|
5
|
+
"version": "0.0.8",
|
|
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
|
-
|
|
13
|
-
"devDependencies": {
|
|
14
|
-
"typescript": "^4.5.5"
|
|
19
|
+
"scripts": {
|
|
20
|
+
"prepublishOnly": "npx tsc --noEmit"
|
|
15
21
|
},
|
|
16
|
-
"
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@typescript-eslint/eslint-plugin": "5.10.2",
|
|
24
|
+
"@typescript-eslint/parser": "5.10.2",
|
|
25
|
+
"eslint": "8.8.0",
|
|
26
|
+
"eslint-config-prettier": "8.3.0",
|
|
27
|
+
"eslint-config-standard": "17.0.0-1",
|
|
28
|
+
"eslint-config-standard-with-typescript": "21.0.1",
|
|
29
|
+
"eslint-import-resolver-alias": "1.1.2",
|
|
30
|
+
"eslint-import-resolver-typescript": "2.5.0",
|
|
31
|
+
"eslint-plugin-html": "6.2.0",
|
|
32
|
+
"eslint-plugin-import": "2.25.4",
|
|
33
|
+
"eslint-plugin-n": "14.0.0",
|
|
34
|
+
"eslint-plugin-node": "11.1.0",
|
|
35
|
+
"eslint-plugin-prettier": "4.0.0",
|
|
36
|
+
"eslint-plugin-promise": "6.0.0",
|
|
37
|
+
"eslint-plugin-react": "7.28.0",
|
|
38
|
+
"eslint-plugin-react-hooks": "4.3.0",
|
|
39
|
+
"eslint-plugin-security": "1.4.0",
|
|
40
|
+
"eslint-plugin-security-node": "1.1.1",
|
|
41
|
+
"eslint-plugin-typescript-sort-keys": "2.1.0",
|
|
42
|
+
"eslint-plugin-unicorn": "40.1.0",
|
|
43
|
+
"prettier": "2.5.1",
|
|
44
|
+
"typescript": "4.5.5"
|
|
45
|
+
}
|
|
17
46
|
}
|
package/src/Crypto.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
export class Crypto {
|
|
3
|
+
setPassword(newPassword: string): void;
|
|
4
|
+
updateCryptoStateTiddler(): void;
|
|
5
|
+
hasPassword(): boolean;
|
|
6
|
+
encrypt(text: string, password: string): string | null;
|
|
7
|
+
decrypt(text: string, password: string): string | null;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
export interface PasswordPromptInfo {
|
|
3
|
+
callback: PasswordPromptInfoCallback;
|
|
4
|
+
form: TWDOMElement;
|
|
5
|
+
owner: PasswordPrompt;
|
|
6
|
+
serviceName: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type PasswordPromptInfoCallback = (
|
|
10
|
+
data: {
|
|
11
|
+
password: string;
|
|
12
|
+
password2?: string;
|
|
13
|
+
username: string;
|
|
14
|
+
} | null,
|
|
15
|
+
) => boolean;
|
|
16
|
+
|
|
17
|
+
export class PasswordPrompt {
|
|
18
|
+
/** Creates a PasswordPrompt object */
|
|
19
|
+
constructor();
|
|
20
|
+
/** Store of pending password prompts */
|
|
21
|
+
passwordPrompts: PasswordPromptInfo[];
|
|
22
|
+
promptWrapper: TWDOMElement;
|
|
23
|
+
/** Hides or shows the wrapper depending on whether there are any outstanding prompts */
|
|
24
|
+
setWrapperDisplay(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Adds a new password prompt. Options are:
|
|
27
|
+
* @param {{
|
|
28
|
+
* submitText: string;
|
|
29
|
+
* serviceName: string;
|
|
30
|
+
* noUserName: boolean;
|
|
31
|
+
* canCancel: boolean;
|
|
32
|
+
* repeatPassword: boolean;
|
|
33
|
+
* callback: PasswordPromptInfoCallback;
|
|
34
|
+
* }} options Options are:
|
|
35
|
+
* * submitText: text to use for submit button (defaults to "Login")
|
|
36
|
+
* * serviceName: text of the human readable service name
|
|
37
|
+
* * noUserName: set true to disable username prompt
|
|
38
|
+
* * canCancel: set true to enable a cancel button (callback called with null)
|
|
39
|
+
* * repeatPassword: set true to prompt for the password twice
|
|
40
|
+
* * callback: function to be called on submission with parameter of object {username:,password:}. Callback must return `true` to remove the password prompt
|
|
41
|
+
* @returns {PasswordPromptInfo}
|
|
42
|
+
* @memberof PasswordPrompt
|
|
43
|
+
*/
|
|
44
|
+
createPrompt(options: {
|
|
45
|
+
callback: PasswordPromptInfoCallback;
|
|
46
|
+
canCancel: boolean;
|
|
47
|
+
noUserName: boolean;
|
|
48
|
+
repeatPassword: boolean;
|
|
49
|
+
serviceName: string;
|
|
50
|
+
submitText: string;
|
|
51
|
+
}): PasswordPromptInfo;
|
|
52
|
+
removePrompt(promptInfo: PasswordPromptInfo): void;
|
|
53
|
+
}
|
|
54
|
+
}
|
package/src/Tiddler.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
export class Tiddler {
|
|
3
|
+
constructor(...fields: Array<Record<string, unknown> | Tiddler>);
|
|
4
|
+
readonly cache: ITiddlerCache;
|
|
5
|
+
readonly fields: ITiddlerFields;
|
|
6
|
+
static fieldModules: IModule;
|
|
7
|
+
hasField(field: string): boolean;
|
|
8
|
+
isEqual(tiddler: Tiddler, excludeFields: string[]): boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface ITiddlerFields {
|
|
12
|
+
readonly [anyKey: string]: unknown;
|
|
13
|
+
readonly color: string;
|
|
14
|
+
readonly created: Date;
|
|
15
|
+
readonly list: string[];
|
|
16
|
+
readonly modified: Date;
|
|
17
|
+
readonly tags: string[];
|
|
18
|
+
readonly text: string;
|
|
19
|
+
readonly title: string;
|
|
20
|
+
readonly type: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
24
|
+
export interface ITiddlerCache {}
|
|
25
|
+
}
|
package/src/Wiki.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
export class Wiki {
|
|
3
|
+
/**
|
|
4
|
+
* 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.
|
|
5
|
+
* @param {{ enableIndexers: unknown[] }} options options include:
|
|
6
|
+
* * enableIndexers - Array of indexer names to enable, or null to use all available indexers
|
|
7
|
+
* @memberof Wiki
|
|
8
|
+
*/
|
|
9
|
+
constructor(options: { enableIndexers: unknown[] });
|
|
10
|
+
addIndexer(indexer, name): void;
|
|
11
|
+
getTiddler: (title: string) => Tiddler | undefined;
|
|
12
|
+
/**
|
|
13
|
+
* Get full list of tiddler titles in the wiki
|
|
14
|
+
*/
|
|
15
|
+
getTiddlers: () => string[];
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/filter-operator.d.ts
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
export type SourceIterator = (tiddler: Tiddler, title: string) => void;
|
|
3
|
+
export interface ISearchOptions {
|
|
4
|
+
/** If true, forces all but regexp searches to be anchored to the start of text */
|
|
5
|
+
anchored?: boolean;
|
|
6
|
+
/** If true forces a case sensitive search */
|
|
7
|
+
caseSensitive?: boolean;
|
|
8
|
+
/** An array of tiddler titles to exclude from the search */
|
|
9
|
+
exclude?: string[];
|
|
10
|
+
/** If true, the field options are inverted to specify the fields that are not to be searched */
|
|
11
|
+
excludeField?: boolean;
|
|
12
|
+
/** If specified, restricts the search to the specified field, or an array of field names */
|
|
13
|
+
field?: string | string[];
|
|
14
|
+
/** If true returns tiddlers that do not contain the specified string */
|
|
15
|
+
invert?: boolean;
|
|
16
|
+
/** searches for literal string */
|
|
17
|
+
literal?: boolean;
|
|
18
|
+
/** an iterator function for the source tiddlers, called source(iterator), where iterator is called as iterator(tiddler,title) */
|
|
19
|
+
source?: (iter: SourceIterator) => void;
|
|
20
|
+
/** same as literal except runs of whitespace are treated as a single space */
|
|
21
|
+
whitespace?: boolean;
|
|
22
|
+
/** (default) treats search string as a list of tokens, and matches if all tokens are found, regardless of adjacency or ordering */
|
|
23
|
+
words?: boolean;
|
|
24
|
+
}
|
|
24
25
|
|
|
25
|
-
export interface
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
26
|
+
export interface IFilterOperatorParameterOperator {
|
|
27
|
+
/** the operand for the filter step (as a string; if the filter specified it in angle brackets or braces, the text reference or letiable name will have already been resolved); */
|
|
28
|
+
operand: string;
|
|
29
|
+
/** the name of the filter operator specified in the WikiText; */
|
|
30
|
+
operator: string;
|
|
31
|
+
/** (optional) a string containing a single exclamation mark if the filter operator is to be negated; */
|
|
32
|
+
prefix?: string;
|
|
33
|
+
/** (optional, deprecated) used instead of `operand` if the filter operand is a regexp. */
|
|
34
|
+
regexp?: string;
|
|
35
|
+
/** (optional) a string containing an additional filter argument (typically a tiddler field name) following the filter name (separated by a colon in the filter syntax); */
|
|
36
|
+
suffix?: string;
|
|
37
|
+
/** multiple suffix
|
|
38
|
+
* for example, in `search:<field list>:<flag list>[<operand>]`, you will get `<field list>` as suffixes[0], and `<flag list>` as suffixes[1]
|
|
39
|
+
*/
|
|
40
|
+
suffixes?: string[][];
|
|
41
|
+
}
|
|
40
42
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export * from './filter-operator';
|
|
1
|
+
import './tw';
|
|
2
|
+
import './filter-operator';
|
|
4
3
|
|
|
5
|
-
declare module 'tiddlywiki' {
|
|
6
|
-
|
|
7
|
-
declare module '@tiddlygit/tiddlywiki' {}
|
|
8
|
-
|
|
9
|
-
declare global {
|
|
10
|
-
var $tw: I$TW;
|
|
4
|
+
declare module '@tiddlygit/tiddlywiki' {
|
|
5
|
+
export * from 'tiddlywiki';
|
|
11
6
|
}
|
package/src/modules.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
export interface ITWModuleExports {
|
|
3
|
+
[exportName: unknown]: unknown;
|
|
4
|
+
name?: string;
|
|
5
|
+
type?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface IModuleInfo {
|
|
8
|
+
definition: string | TWModuleDefinitionFucntion | ITWModuleExports;
|
|
9
|
+
exports: ITWModuleExports | null;
|
|
10
|
+
moduleType: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ITWRequire {
|
|
13
|
+
(title: string): ITWModuleExports;
|
|
14
|
+
readonly main: NodeJS.Module | { TiddlyWiki: typeof TiddlyWiki };
|
|
15
|
+
}
|
|
16
|
+
export interface IModuleSandbox {
|
|
17
|
+
$tw: ITiddlyWiki;
|
|
18
|
+
Buffer?: Buffer;
|
|
19
|
+
clearInterval: typeof clearInterval;
|
|
20
|
+
clearTimeout: typeof clearTimeout;
|
|
21
|
+
console: Console;
|
|
22
|
+
exports: ITWModuleExports;
|
|
23
|
+
module: { exports: ITWModuleExports; readonly id: string };
|
|
24
|
+
process?: NodeJS.Process;
|
|
25
|
+
require: ITWRequire;
|
|
26
|
+
setInterval: typeof setInterval;
|
|
27
|
+
setTimeout: typeof setTimeout;
|
|
28
|
+
}
|
|
29
|
+
export type TWModuleDefinitionFucntion = (moduleInfo: IModuleInfo, exports: ITWModuleExports, requireFunction: ITWRequire) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Information about each module is kept in an object with these members:
|
|
32
|
+
*
|
|
33
|
+
* * moduleType: type of module
|
|
34
|
+
* * definition: object, function or string defining the module; see below
|
|
35
|
+
* * exports: exports of the module, filled in after execution
|
|
36
|
+
*
|
|
37
|
+
* The `definition` can be of several types:
|
|
38
|
+
*
|
|
39
|
+
* * An object can be used to directly specify the exports of the module
|
|
40
|
+
* * A function with the arguments `module,require,exports` that returns `exports`
|
|
41
|
+
* * A string function body with the same arguments
|
|
42
|
+
*
|
|
43
|
+
* 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
|
|
44
|
+
*/
|
|
45
|
+
interface ITWModules {
|
|
46
|
+
/** Apply the exports of the modules of a particular type to a target object */
|
|
47
|
+
applyMethods(moduleType: string, targetObject?: ITWModuleExports): ITWModuleExports;
|
|
48
|
+
/** Return a class created from a modules. The module should export the properties to be added to those of the optional base class */
|
|
49
|
+
createClassFromModule(moduleExports: ITWModuleExports, baseClass: new () => unknown): ITWModuleExports;
|
|
50
|
+
/** Return an array of classes created from the modules of a specified type. Each module should export the properties to be added to those of the optional base class */
|
|
51
|
+
createClassesFromModules(moduleType: string, subType: string | null | undefined, baseClass: new () => unknown): Record<string, ITWModuleExports>;
|
|
52
|
+
/**
|
|
53
|
+
* Define a JavaScript tiddler module for later execution
|
|
54
|
+
* @param {string} moduleName name of module being defined
|
|
55
|
+
* @param {string} moduleType type of module
|
|
56
|
+
* @param {(string | TWModuleDefinitionFucntion | ITWModuleExports)} definition module definition; see discussion above
|
|
57
|
+
* @memberof ITWModules
|
|
58
|
+
*/
|
|
59
|
+
define(moduleName: string, moduleType: string, definition: string | TWModuleDefinitionFucntion | ITWModuleExports): void;
|
|
60
|
+
/**
|
|
61
|
+
* Execute the module named 'moduleName'. The name can optionally be relative to the module named 'moduleRoot'
|
|
62
|
+
* @memberof ITWModules
|
|
63
|
+
*/
|
|
64
|
+
execute(moduleName: string, moduleRoot: string): ITWModuleExports;
|
|
65
|
+
/**
|
|
66
|
+
* Apply a callback to each module of a particular type
|
|
67
|
+
*
|
|
68
|
+
* @param {string} moduleType type of modules to enumerate
|
|
69
|
+
* @param {(title, moduleExports) => void} callback function called as callback(title,moduleExports) for each module
|
|
70
|
+
* @memberof ITWModules
|
|
71
|
+
*/
|
|
72
|
+
forEachModuleOfType(moduleType: string, callback: (title, moduleExports) => void): void;
|
|
73
|
+
/** Get all the modules of a particular type in a hashmap by their `name` field */
|
|
74
|
+
getModulesByTypeAsHashmap(moduleType: string, nameField: string): Record<string, IModuleInfo>;
|
|
75
|
+
/** hashmap by module name of moduleInfo */
|
|
76
|
+
titles: Record<string, IModuleInfo>;
|
|
77
|
+
/** hashmap by module type and then name of moduleInfo */
|
|
78
|
+
types: Record<string, Record<string, IModuleInfo>>;
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/tw.d.ts
CHANGED
|
@@ -1,49 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
export interface IBootFilesIndexItem {
|
|
3
|
+
filepath: string;
|
|
4
|
+
hasMetaFile: boolean;
|
|
5
|
+
tiddlerTitle: string;
|
|
6
|
+
type: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Record<tiddlerTitle, IBootFilesIndexItem>
|
|
10
|
+
*/
|
|
11
|
+
export type IBootFilesIndex = Partial<Record<string, IBootFilesIndexItem>>;
|
|
5
12
|
|
|
6
|
-
export interface
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
modified: string;
|
|
10
|
-
tags: string[];
|
|
11
|
-
text: string;
|
|
12
|
-
title: string;
|
|
13
|
-
type: string;
|
|
14
|
-
[anyKey: string]: unknown;
|
|
15
|
-
}
|
|
13
|
+
export interface IPluginInfo {
|
|
14
|
+
tiddlers: ITiddlerFields[];
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
17
|
+
export interface IFileExtensionInfo {
|
|
18
|
+
type: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface IContentTypeInfo {
|
|
22
|
+
deserializerType: string;
|
|
23
|
+
encoding: string;
|
|
24
|
+
extension: string;
|
|
25
|
+
flags: string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface ITiddlyWiki {
|
|
29
|
+
Tiddler: typeof Tiddler;
|
|
30
|
+
Wiki: typeof Wiki;
|
|
31
|
+
|
|
32
|
+
boot: {
|
|
33
|
+
argv: string[];
|
|
34
|
+
files: IBootFilesIndex;
|
|
35
|
+
log(logString: string): void;
|
|
36
|
+
logMessages: string[];
|
|
37
|
+
startup(options: { callback?: () => unknown }): void;
|
|
38
|
+
/** Default boot tasks */
|
|
39
|
+
tasks: {
|
|
40
|
+
readBrowserTiddlers: boolean;
|
|
41
|
+
trapErrors: boolean;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
browser: null | object;
|
|
46
|
+
|
|
47
|
+
config: ITWConfig;
|
|
48
|
+
|
|
49
|
+
hooks: {
|
|
50
|
+
addHook: (hookName: string, callback: (...arguments_: unknown[]) => unknown) => void;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
modules: ITWModules;
|
|
54
|
+
/** NodeJS features, if tw isn't running on a NodeJS environment, the value will be `null` */
|
|
55
|
+
node: null | object;
|
|
56
|
+
/** Broswer features, if tw isn't running on a browser environment, the value will be `null` */
|
|
57
|
+
nodeWebKit: null | object;
|
|
58
|
+
|
|
59
|
+
/** Convenience function for pushing a tiddler onto the preloading array */
|
|
60
|
+
preloadTiddler(fields: Record<string, unknown>): void;
|
|
61
|
+
/** Convenience function for pushing an array of tiddlers onto the preloading array */
|
|
62
|
+
preloadTiddlerArray(fieldsArray: Array<Record<string, unknown>>): void;
|
|
63
|
+
/** External JavaScript can populate this array before calling boot.js in order to preload tiddlers */
|
|
64
|
+
preloadTiddlers: Record<string, Record<string, unknown>>;
|
|
65
|
+
|
|
66
|
+
utils: ITWUtils;
|
|
67
|
+
|
|
68
|
+
version: string;
|
|
69
|
+
|
|
70
|
+
wiki: Wiki;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export declare function TiddlyWiki($tw: object): ITiddlyWiki;
|
|
74
|
+
|
|
75
|
+
global {
|
|
76
|
+
const $tw: ITiddlyWiki;
|
|
77
|
+
}
|
|
48
78
|
}
|
|
49
|
-
export function TiddlyWiki(): I$TW;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
declare interface ITWConfig {
|
|
3
|
+
[configName: string]: unknown;
|
|
4
|
+
/** Map type to file content type */
|
|
5
|
+
contentTypeInfo: Record<string, IContentTypeInfo>;
|
|
6
|
+
/** Default is `TIDDLYWIKI_EDITION_PATH` */
|
|
7
|
+
editionsEnvVar: string;
|
|
8
|
+
/** Default is `../editions/` */
|
|
9
|
+
editionsPath: string;
|
|
10
|
+
/** Map file extension */
|
|
11
|
+
fileExtensionInfo: Record<string, IFileExtensionInfo>;
|
|
12
|
+
/** Default is `^\\/\\*\\\\(?:\\r?\\n)((?:^[^\\r\\n]*(?:\\r?\\n))+?)(^\\\\\\*\\/$(?:\\r?\\n)?)` */
|
|
13
|
+
jsModuleHeaderRegExpString: string;
|
|
14
|
+
/** Default is `TIDDLYWIKI_LANGUAGE_PATH` */
|
|
15
|
+
languagesEnvVar: string;
|
|
16
|
+
/** Default is `../languages/` */
|
|
17
|
+
languagesPath: string;
|
|
18
|
+
//
|
|
19
|
+
/** Default is `TIDDLYWIKI_PLUGIN_PATH` */
|
|
20
|
+
pluginsEnvVar: string;
|
|
21
|
+
/** Default is `../plugins/` */
|
|
22
|
+
pluginsPath: string;
|
|
23
|
+
/** Default is `TIDDLYWIKI_THEME_PATH` */
|
|
24
|
+
themesEnvVar: string;
|
|
25
|
+
/** Default is `../themes/` */
|
|
26
|
+
themesPath: string;
|
|
27
|
+
/** Default is `./tiddlywiki.info` */
|
|
28
|
+
wikiInfo: string;
|
|
29
|
+
/** Default is `./languages` */
|
|
30
|
+
wikiLanguagesSubDir: string;
|
|
31
|
+
/** Default is `./output` */
|
|
32
|
+
wikiOutputSubDir: string;
|
|
33
|
+
/** Default is `./plugins` */
|
|
34
|
+
wikiPluginsSubDir: string;
|
|
35
|
+
/** Default is `./themes` */
|
|
36
|
+
wikiThemesSubDir: string;
|
|
37
|
+
/** Default is `./tiddlers` */
|
|
38
|
+
wikiTiddlersSubDir: string;
|
|
39
|
+
}
|
|
40
|
+
}
|
package/src/utils.d.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
export type TWDocument = Document;
|
|
3
|
+
export type TWDOMElement = Element;
|
|
4
|
+
export type TWEachCallback<T> = (element?: unknown, index?: string | number, object?: T) => boolean | undefined;
|
|
5
|
+
interface ITWUtils {
|
|
6
|
+
Crypto: typeof Crypto;
|
|
7
|
+
PasswordPrompt: typeof PasswordPrompt;
|
|
8
|
+
/** Returns true if the version string A is greater than the version string B. Returns true if the versions are the same */
|
|
9
|
+
checkVersions(versionStringA: string, versionStringB: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Returns +1 if the version string A is greater than the version string B, 0 if they are the same, and +1 if B is greater than A.
|
|
12
|
+
* Missing or malformed version strings are parsed as 0.0.0
|
|
13
|
+
*/
|
|
14
|
+
compareVersions(versionStringA: string, versionStringB: string): -1 | 0 | 1;
|
|
15
|
+
/** Convert a URIComponent encoded string to a string safely */
|
|
16
|
+
decodeURIComponentSafe(uri: string): string;
|
|
17
|
+
/** Convert a URI encoded string to a string safely */
|
|
18
|
+
decodeURISafe(uri: string): string;
|
|
19
|
+
/** 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 */
|
|
20
|
+
deepDefaults(object: object, ...sourceObjectList: object[]): object;
|
|
21
|
+
/**
|
|
22
|
+
* Helper for making DOM elements
|
|
23
|
+
* @param {string} tag tag name
|
|
24
|
+
* @param {{
|
|
25
|
+
* namespace?: string;
|
|
26
|
+
* attributes?: Record<string, unknown>;
|
|
27
|
+
* style?: Record<string, string>;
|
|
28
|
+
* text?: string;
|
|
29
|
+
* children?: Element[];
|
|
30
|
+
* innerHTML?: string;
|
|
31
|
+
* class?: string;
|
|
32
|
+
* document?: Document;
|
|
33
|
+
* eventListeners?: EventListener[];
|
|
34
|
+
* }} options Options include:
|
|
35
|
+
* * namespace: defaults to http://www.w3.org/1999/xhtml
|
|
36
|
+
* * attributes: hashmap of attribute values
|
|
37
|
+
* * style: hashmap of styles
|
|
38
|
+
* * text: text to add as a child node
|
|
39
|
+
* * children: array of further child nodes
|
|
40
|
+
* * innerHTML: optional HTML for element
|
|
41
|
+
* * class: class name(s)
|
|
42
|
+
* * document: defaults to current document
|
|
43
|
+
* * eventListeners: array of event listeners (this option won't work until `$tw.utils.addEventListeners()` has been loaded)
|
|
44
|
+
* @returns {Element}
|
|
45
|
+
*/
|
|
46
|
+
domMaker(
|
|
47
|
+
tag: string,
|
|
48
|
+
options: {
|
|
49
|
+
attributes?: Record<string, unknown>;
|
|
50
|
+
children?: TWDOMElement[];
|
|
51
|
+
class?: string;
|
|
52
|
+
document?: TWDocument;
|
|
53
|
+
eventListeners?: EventListener[];
|
|
54
|
+
innerHTML?: string;
|
|
55
|
+
namespace?: string;
|
|
56
|
+
style?: Record<string, string>;
|
|
57
|
+
text?: string;
|
|
58
|
+
},
|
|
59
|
+
): TWDOMElement;
|
|
60
|
+
/**
|
|
61
|
+
* Iterate through all the own properties of an object or array.
|
|
62
|
+
* Callback is invoked with (element, index, object), if callback returns false, then the each loop will be terminated.
|
|
63
|
+
*/
|
|
64
|
+
each<T = object | unknown[]>(object: T, callback: TWEachCallback<T>): void;
|
|
65
|
+
/** Display an error and exit */
|
|
66
|
+
error(error: Event | string): void;
|
|
67
|
+
/** Run code globally with specified context variables in scope */
|
|
68
|
+
evalGlobal(code: string, context: IModuleSandbox, filename: string): unknown;
|
|
69
|
+
/** Run code in a sandbox with only the specified context variables in scope */
|
|
70
|
+
evalSandboxed(code: string, context: IModuleSandbox, filename: string): unknown;
|
|
71
|
+
/** Extend an object with the properties from a list of source objects */
|
|
72
|
+
extend(object: object, ...sourceObjectList: object[]): object;
|
|
73
|
+
/** Given an extension, always access the $tw.config.fileExtensionInfo using a lowercase extension only. */
|
|
74
|
+
getFileExtensionInfo(extension: string): IFileExtensionInfo | null;
|
|
75
|
+
/** 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) */
|
|
76
|
+
getLocationHash(): string;
|
|
77
|
+
/** Given an extension, get the correct encoding for that file. defaults to utf8 */
|
|
78
|
+
getTypeEncoding(extension: string): string;
|
|
79
|
+
/** Check if an object has a property. */
|
|
80
|
+
hop(object: object, property: string): boolean;
|
|
81
|
+
/** Convert "&" to &, " " to nbsp, "<" to <, ">" to > and """ to " */
|
|
82
|
+
htmlDecode(text: string): string;
|
|
83
|
+
/** Determine if a value is an array. */
|
|
84
|
+
isArray(value: unknown): boolean;
|
|
85
|
+
/** Check if an array is equal by value and by reference. */
|
|
86
|
+
isArrayEqual(array1: unknown[], array2: unknown[]): boolean;
|
|
87
|
+
/** Determine if a value is a date */
|
|
88
|
+
isDate(value: unknown): void;
|
|
89
|
+
/** Pad a string to a given length with "0"s. Length defaults to 2 */
|
|
90
|
+
pad(value: number, length?: number): string;
|
|
91
|
+
/** Parse a date from a UTC YYYYMMDDHHMMSSmmm format string */
|
|
92
|
+
parseDate(value: string | Date): Date;
|
|
93
|
+
/** Parse a block of name:value fields. The `fields` object is used as the basis for the return value */
|
|
94
|
+
parseFields(text: string, fields?: object): object;
|
|
95
|
+
/** Parse a string array from a bracketted list. For example "OneTiddler [[Another Tiddler]] LastOne" */
|
|
96
|
+
parseStringArray(value: string | string[], allowDuplicate?: boolean): string[];
|
|
97
|
+
/** Parse a semantic version string into its constituent parts -- see https://semver.org */
|
|
98
|
+
parseVersion(version: string): {
|
|
99
|
+
build?: string;
|
|
100
|
+
major: number;
|
|
101
|
+
minor: number;
|
|
102
|
+
patch: number;
|
|
103
|
+
prerelease?: string;
|
|
104
|
+
version: string;
|
|
105
|
+
} | null;
|
|
106
|
+
/**
|
|
107
|
+
* Push entries onto an array, removing them first if they already exist in the array
|
|
108
|
+
* * array: array to modify (assumed to be free of duplicates)
|
|
109
|
+
* * value: a single value to push or an array of values to push
|
|
110
|
+
*/
|
|
111
|
+
pushTop(array: unknown[], value: unknown): void;
|
|
112
|
+
/**
|
|
113
|
+
* Register file type information
|
|
114
|
+
* @param {string} contentType
|
|
115
|
+
* @param {string} encoding
|
|
116
|
+
* @param {(string | string[])} extension
|
|
117
|
+
* @param {{
|
|
118
|
+
* flags: string[];
|
|
119
|
+
* deserializerType: string;
|
|
120
|
+
* }} [options] Options includes:
|
|
121
|
+
* * flags:"image" for image types
|
|
122
|
+
* * deserializerType: defaults to type if not specified
|
|
123
|
+
*/
|
|
124
|
+
registerFileType(
|
|
125
|
+
contentType: string,
|
|
126
|
+
encoding: string,
|
|
127
|
+
extension: string | string[],
|
|
128
|
+
options?: {
|
|
129
|
+
deserializerType?: string;
|
|
130
|
+
flags?: string[];
|
|
131
|
+
},
|
|
132
|
+
): void;
|
|
133
|
+
/**
|
|
134
|
+
* Resolves a source filepath delimited with `/` relative to a specified absolute root filepath.
|
|
135
|
+
* In relative paths, the special folder name `..` refers to immediate parent directory, and the
|
|
136
|
+
* name `.` refers to the current directory
|
|
137
|
+
*/
|
|
138
|
+
resolvePath(sourcepath: string, rootpath: string): string;
|
|
139
|
+
/** Convert a date into UTC YYYYMMDDHHMMSSmmm format */
|
|
140
|
+
stringifyDate(value: Date): string;
|
|
141
|
+
/** Stringify an array of tiddler titles into a list string */
|
|
142
|
+
stringifyList(value: string[]): string;
|
|
143
|
+
}
|
|
144
|
+
}
|
package/src/widget.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
2
|
+
declare class variablesConstructor {}
|
|
3
|
+
|
|
4
|
+
export class Widget {
|
|
5
|
+
constructor(parseTreeNode: unknown, options: unknown);
|
|
6
|
+
initialize: (parseTreeNode: unknown, options: unknown) => void;
|
|
7
|
+
parseTreeNode: unknown;
|
|
8
|
+
wiki: unknown;
|
|
9
|
+
parentWidget?: Widget;
|
|
10
|
+
variablesConstructor: variablesConstructor;
|
|
11
|
+
variables: unknown;
|
|
12
|
+
}
|