tw5-typed 1.1.3 → 1.1.5
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 +44 -1
- package/package.json +1 -1
- package/src/hooks.d.ts +75 -1
- package/src/index.d.ts +6 -2
- package/src/modules/server/index.d.ts +1 -2
- package/src/modules/utils/index.d.ts +1 -1
- package/src/modules/utils/performance.d.ts +1 -2
- package/src/modules/widgets/index.d.ts +0 -0
- package/src/modules/wiki.d.ts +4 -4
- package/src/utils/index.d.ts +3 -3
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ TypeScript type definitions for TiddlyWiki5.
|
|
|
9
9
|
First, install it as dev-dependency:
|
|
10
10
|
|
|
11
11
|
```sh
|
|
12
|
-
|
|
12
|
+
pnpm add -D tw5-typed
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Add `tw5-typed` to your `tsconfig.json`'s `compilerOptions`
|
|
@@ -28,6 +28,40 @@ Then you will have global types like `$tw` automatically. You can import the res
|
|
|
28
28
|
import type { ISearchOptions, SourceIterator, IFilterOperatorParamOperator } from 'tiddlywiki';
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
+
If your project already has an ambient declaration file such as `src/global.d.ts` or `src/ambient.d.ts`, add this line there as well:
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
/// <reference types="tw5-typed" />
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
That extra reference helps VS Code pick the package up reliably in template-based projects.
|
|
38
|
+
|
|
39
|
+
## Troubleshooting
|
|
40
|
+
|
|
41
|
+
If VS Code shows `Could not find a declaration file for module 'tiddlywiki'`, the usual cause is configuration, not missing types.
|
|
42
|
+
|
|
43
|
+
Use this:
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"compilerOptions": {
|
|
48
|
+
"types": ["node", "tw5-typed"]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Do not use this:
|
|
54
|
+
|
|
55
|
+
```json
|
|
56
|
+
{
|
|
57
|
+
"compilerOptions": {
|
|
58
|
+
"typeRoots": ["node_modules/@types", "node_modules/tw5-typed"]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`tw5-typed` is a normal package with its own `types` entrypoint. Pointing `typeRoots` at the package directory can prevent TypeScript or VS Code from loading the `declare module 'tiddlywiki'` entry correctly.
|
|
64
|
+
|
|
31
65
|
### Alias
|
|
32
66
|
|
|
33
67
|
Sometimes you may want to use a modified version of tw, you can re-export types like this in your `src/type.d.ts`:
|
|
@@ -58,6 +92,15 @@ You can add new `*.d.ts` file to contain your types:
|
|
|
58
92
|
- add type import like `/// <reference path="parser.d.ts" />`
|
|
59
93
|
- using normal import, like `import { parse } from './parser';` will not work
|
|
60
94
|
|
|
95
|
+
Could import from `"tiddlywiki"` inside `declare module` like
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
declare module '$:/core/modules/utils/parsetree.js' {
|
|
99
|
+
import { IParseTreeNode } from 'tiddlywiki';
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Import outside of `declare module` will cause error.
|
|
103
|
+
|
|
61
104
|
### Test in your node_modules
|
|
62
105
|
|
|
63
106
|
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/hooks.d.ts
CHANGED
|
@@ -8,6 +8,26 @@ declare module 'tiddlywiki' {
|
|
|
8
8
|
type: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
interface NavigatingInfo {
|
|
12
|
+
navigateTo: string;
|
|
13
|
+
navigateFromTitle: string;
|
|
14
|
+
navigateFromClientRect: {
|
|
15
|
+
bottom: number;
|
|
16
|
+
height: number;
|
|
17
|
+
left: number;
|
|
18
|
+
right: number;
|
|
19
|
+
top: number;
|
|
20
|
+
width: number;
|
|
21
|
+
};
|
|
22
|
+
navigateFromClientTop: number;
|
|
23
|
+
navigateFromClientLeft: number;
|
|
24
|
+
navigateFromClientWidth: number;
|
|
25
|
+
navigateFromClientRight: number;
|
|
26
|
+
navigateFromClientBottom: number;
|
|
27
|
+
navigateFromClientHeight: number;
|
|
28
|
+
navigateSuppressNavigation: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
11
31
|
interface IHooks {
|
|
12
32
|
/** Add hooks to the hashmap */
|
|
13
33
|
addHook(
|
|
@@ -41,7 +61,13 @@ declare module 'tiddlywiki' {
|
|
|
41
61
|
widget: Widget,
|
|
42
62
|
) => parseTreeNodes,
|
|
43
63
|
);
|
|
44
|
-
addHook(
|
|
64
|
+
addHook(
|
|
65
|
+
hookName: 'th-navigating',
|
|
66
|
+
callback: (
|
|
67
|
+
event: NavigatingInfo & IWidgetEvent,
|
|
68
|
+
) => NavigatingInfo & IWidgetEvent,
|
|
69
|
+
): void;
|
|
70
|
+
addHook(hookName: 'th-closing-tiddler' | 'th-editing-tiddler' | 'th-cancelling-tiddler' | 'th-new-tiddler', callback: (event: unknown) => unknown);
|
|
45
71
|
addHook(hookName: 'th-deleting-tiddler', callback: (title: Tiddler) => void);
|
|
46
72
|
addHook(hookName: 'th-page-refreshed' | 'th-boot-tiddlers-loaded' | 'th-page-refreshing', callback: () => void);
|
|
47
73
|
addHook(
|
|
@@ -53,6 +79,54 @@ declare module 'tiddlywiki' {
|
|
|
53
79
|
* Invoke the hook by key
|
|
54
80
|
*/
|
|
55
81
|
invokeHook(hookName: string, event: IWidgetEvent): undefined | IWidgetEvent;
|
|
82
|
+
/**
|
|
83
|
+
* Remove hooks
|
|
84
|
+
*/
|
|
85
|
+
removeHook(
|
|
86
|
+
hookName: 'th-server-command-post-start',
|
|
87
|
+
callback: (
|
|
88
|
+
server: unknown,
|
|
89
|
+
nodeServer: HttpServer,
|
|
90
|
+
who: 'tiddlywiki',
|
|
91
|
+
) => void,
|
|
92
|
+
): void;
|
|
93
|
+
removeHook(
|
|
94
|
+
hookName: 'th-saving-tiddler' | 'th-renaming-tiddler' | 'th-relinking-tiddler',
|
|
95
|
+
callback: (toTiddler: Tiddler, fromTiddler: Tiddler) => Tiddler | undefined,
|
|
96
|
+
);
|
|
97
|
+
removeHook(
|
|
98
|
+
hookName: 'th-importing-tiddler' | 'th-before-importing',
|
|
99
|
+
callback: (tiddler: Tiddler) => Tiddler | undefined,
|
|
100
|
+
);
|
|
101
|
+
removeHook(
|
|
102
|
+
hookName: 'th-opening-default-tiddlers-list',
|
|
103
|
+
callback: (storyList: string[]) => string[],
|
|
104
|
+
);
|
|
105
|
+
removeHook(
|
|
106
|
+
hookName: 'th-make-tiddler-path',
|
|
107
|
+
callback: (fullPath: string, fullPath: string) => string,
|
|
108
|
+
);
|
|
109
|
+
removeHook(
|
|
110
|
+
hookName: 'th-rendering-element',
|
|
111
|
+
callback: (
|
|
112
|
+
parseTreeNodes: IParseTreeNode | null,
|
|
113
|
+
widget: Widget,
|
|
114
|
+
) => parseTreeNodes,
|
|
115
|
+
);
|
|
116
|
+
removeHook(
|
|
117
|
+
hookName: 'th-navigating',
|
|
118
|
+
callback: (
|
|
119
|
+
event: NavigatingInfo & IWidgetEvent,
|
|
120
|
+
) => NavigatingInfo & IWidgetEvent,
|
|
121
|
+
): void;
|
|
122
|
+
removeHook(hookName: 'th-closing-tiddler' | 'th-editing-tiddler' | 'th-cancelling-tiddler' | 'th-new-tiddler', callback: (event: unknown) => unknown);
|
|
123
|
+
removeHook(hookName: 'th-deleting-tiddler', callback: (title: Tiddler) => void);
|
|
124
|
+
removeHook(hookName: 'th-page-refreshed' | 'th-boot-tiddlers-loaded' | 'th-page-refreshing', callback: () => void);
|
|
125
|
+
removeHook(
|
|
126
|
+
hookName: 'th-importing-file',
|
|
127
|
+
callback: (props: ImportFileInfo) => boolean | undefined,
|
|
128
|
+
);
|
|
129
|
+
removeHook(hookName: string, callback: (...arguments_: unknown[]) => unknown);
|
|
56
130
|
names: Record<string, Array<(...arguments_: unknown[]) => unknown>>;
|
|
57
131
|
}
|
|
58
132
|
}
|
package/src/index.d.ts
CHANGED
|
@@ -13,12 +13,16 @@
|
|
|
13
13
|
/// <reference path="./modules/parsers/index.d.ts" />
|
|
14
14
|
/// <reference path="./modules/server/index.d.ts" />
|
|
15
15
|
/// <reference path="./modules/story.d.ts" />
|
|
16
|
+
/// <reference path="./modules/utils/index.d.ts" />
|
|
16
17
|
/// <reference path="./modules/utils/filesystem.d.ts" />
|
|
17
18
|
/// <reference path="./modules/utils/logger.d.ts" />
|
|
19
|
+
/// <reference path="./modules/utils/dom/dom.d.ts" />
|
|
20
|
+
/// <reference path="./modules/utils/dom/modal.d.ts" />
|
|
21
|
+
/// <reference path="./modules/utils/dom/notifier.d.ts" />
|
|
22
|
+
/// <reference path="./modules/utils/fakedom.d.ts" />
|
|
23
|
+
/// <reference path="./modules/utils/linked-list.d.ts" />
|
|
18
24
|
/// <reference path="./modules/syncer/syncadaptor.d.ts" />
|
|
19
25
|
/// <reference path="./modules/syncer/syncer.d.ts" />
|
|
20
|
-
/// <reference path="./modules/utils/dom/index.d.ts" />
|
|
21
|
-
/// <reference path="./modules/utils/linked-list.d.ts" />
|
|
22
26
|
/// <reference path="./modules/widgets/index.d.ts" />
|
|
23
27
|
/// <reference path="./plugins/index.d.ts" />
|
|
24
28
|
|
|
@@ -16,7 +16,7 @@ declare module 'tiddlywiki' {
|
|
|
16
16
|
import * as editionInfo from '$:/core/modules/utils/edition-info.js';
|
|
17
17
|
import * as escapecss from '$:/core/modules/utils/escapecss.js';
|
|
18
18
|
|
|
19
|
-
type IUtilitiesModules =
|
|
19
|
+
export type IUtilitiesModules =
|
|
20
20
|
& Pick<typeof dom, keyof typeof dom>
|
|
21
21
|
& Pick<typeof logger, keyof typeof logger>
|
|
22
22
|
& Pick<typeof filesystem, keyof typeof filesystem>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { Logger } from '$:/core/modules/utils/logger.js';
|
|
2
|
-
|
|
3
1
|
declare module '$:/core/modules/utils/performance.js' {
|
|
2
|
+
import { Logger } from '$:/core/modules/utils/logger.js';
|
|
4
3
|
/**
|
|
5
4
|
* A performance measurement utility.
|
|
6
5
|
* @param enabled - Whether performance measurements are enabled.
|
|
File without changes
|
package/src/modules/wiki.d.ts
CHANGED
|
@@ -120,10 +120,10 @@ declare module 'tiddlywiki' {
|
|
|
120
120
|
getTiddlerList(title: string, field?: string, index?: string): string[];
|
|
121
121
|
/**
|
|
122
122
|
* Get the value of a text reference. Text references can have any of these forms:
|
|
123
|
-
* -
|
|
124
|
-
* -
|
|
125
|
-
* -
|
|
126
|
-
* -
|
|
123
|
+
* - `tiddlertitle`
|
|
124
|
+
* - `tiddlertitle!!fieldname`
|
|
125
|
+
* - `!!fieldname` - specifies a field of the current tiddlers
|
|
126
|
+
* - `tiddlertitle##index`
|
|
127
127
|
* @param textRef The text reference string
|
|
128
128
|
* @param defaultText Default text to return if the reference is not found
|
|
129
129
|
* @param currTiddlerTitle Current tiddler title for relative references
|
package/src/utils/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { Logger } from '$:/core/modules/utils/logger.js';
|
|
2
|
-
import { Spread } from 'type-fest';
|
|
3
|
-
|
|
4
1
|
declare module 'tiddlywiki' {
|
|
2
|
+
import type { Logger } from '$:/core/modules/utils/logger.js';
|
|
3
|
+
import { Spread } from 'type-fest';
|
|
5
4
|
export type TWDocument = Document | IFakeDocument;
|
|
6
5
|
export type TWElement = Element;
|
|
7
6
|
export type TWDOMElement = TWElement;
|
|
@@ -500,5 +499,6 @@ declare module 'tiddlywiki' {
|
|
|
500
499
|
formatDateString: (date: Date, template: string) => string;
|
|
501
500
|
}
|
|
502
501
|
|
|
502
|
+
import type { IUtilitiesModules } from 'tiddlywiki';
|
|
503
503
|
export type IUtilities = IUtilitiesBoot & IUtilitiesModules;
|
|
504
504
|
}
|