tw5-typed 0.0.10 → 0.1.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 +2 -1
- package/src/Tiddler.d.ts +1 -1
- package/src/Wiki.d.ts +33 -0
- package/src/filter-operator.d.ts +3 -3
- package/src/index.d.ts +22 -4
- package/src/modules.d.ts +2 -2
- package/src/tw.d.ts +10 -10
- package/src/twconfig.d.ts +1 -1
- package/src/utils.d.ts +4 -1
- package/src/widget.d.ts +31 -27
- package/src/tiddlywiki-test.ts +0 -17
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.1.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,6 +20,7 @@
|
|
|
20
20
|
"prepublishOnly": "npx tsc --noEmit"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
+
"@types/node": "^17.0.18",
|
|
23
24
|
"@typescript-eslint/eslint-plugin": "5.11.0",
|
|
24
25
|
"@typescript-eslint/parser": "5.11.0",
|
|
25
26
|
"eslint": "8.8.0",
|
package/src/Tiddler.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ declare module 'tiddlywiki' {
|
|
|
3
3
|
constructor(...fields: Array<Record<string, unknown> | Tiddler>);
|
|
4
4
|
readonly cache: ITiddlerCache;
|
|
5
5
|
readonly fields: ITiddlerFields;
|
|
6
|
-
static fieldModules:
|
|
6
|
+
static fieldModules: Record<string, IModuleInfo>;
|
|
7
7
|
hasField(field: string): boolean;
|
|
8
8
|
isEqual(tiddler: Tiddler, excludeFields: string[]): boolean;
|
|
9
9
|
}
|
package/src/Wiki.d.ts
CHANGED
|
@@ -13,5 +13,38 @@ declare module 'tiddlywiki' {
|
|
|
13
13
|
* Get full list of tiddler titles in the wiki
|
|
14
14
|
*/
|
|
15
15
|
getTiddlers: () => string[];
|
|
16
|
+
/**
|
|
17
|
+
* Compile filter string to be a function that execute the filter in the wiki.
|
|
18
|
+
* You can pass an optional iterator that provide the input to the returned function. If no iterator is provided, filter will use first operator to get input.
|
|
19
|
+
*/
|
|
20
|
+
compileFilter: (filterString: string) => (iterator?: SourceIterator) => string[];
|
|
21
|
+
/**
|
|
22
|
+
* Set JSON tiddler, Object in data field will be JSON.stringify and put into the text.
|
|
23
|
+
*/
|
|
24
|
+
setTiddlerData: (title: string, data?: object, fields?: ITiddlerFields, options?: any) => void;
|
|
25
|
+
/**
|
|
26
|
+
* Create or update tiddler.
|
|
27
|
+
* Update existed tiddler based on the title field.
|
|
28
|
+
*/
|
|
29
|
+
addTiddler: (tiddler: Tiddler | ITiddlerFields) => void;
|
|
30
|
+
/**
|
|
31
|
+
* Get tiddler's text field, with an optional default text.
|
|
32
|
+
* If have _is_skinny field, will just return null (this is a rare case, so not put in the return type for now).
|
|
33
|
+
*
|
|
34
|
+
* @param title will return undefined (or fallback) if the tiddler isn't found
|
|
35
|
+
* @param fallbackText default text when text field is empty or undefined
|
|
36
|
+
*/
|
|
37
|
+
getTiddlerText(title: string, fallbackText: string): string;
|
|
38
|
+
getTiddlerText(title: string, fallbackText?: string): string | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Set tiddler text of any field.
|
|
41
|
+
*
|
|
42
|
+
* @param {string} title title of tiddler
|
|
43
|
+
* @param {string} field field name to set
|
|
44
|
+
* @param {string | undefined} index data index(key) to set, if you are setting a JSON data tiddler. Be `undefined` if you are just setting a normal tiddler's field, this will be most of the case.
|
|
45
|
+
* @param {string} value text content to set
|
|
46
|
+
* @param {object} options options, see tiddlywiki dev doc for details
|
|
47
|
+
*/
|
|
48
|
+
setText: (title: string, field?: string, index?: string | undefined, value?: string, options?: any) => void;
|
|
16
49
|
}
|
|
17
50
|
}
|
package/src/filter-operator.d.ts
CHANGED
|
@@ -93,13 +93,13 @@ 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 = (source: (iter: SourceIterator) => void, operator:
|
|
96
|
+
export type IFilterOperator = (source: (iter: SourceIterator) => void, operator: IFilterOperatorParameterOperator) => string[] | ((iter: SourceIterator) => void);
|
|
97
97
|
|
|
98
98
|
/**
|
|
99
99
|
* 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`.
|
|
100
|
-
*
|
|
100
|
+
*
|
|
101
101
|
* For Example, with an iterator over all the tiddlers tagged as `interesting`, use it like this:
|
|
102
|
-
*
|
|
102
|
+
*
|
|
103
103
|
* ```js
|
|
104
104
|
* var result = [];
|
|
105
105
|
var include = true;
|
package/src/index.d.ts
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
import './filter-operator';
|
|
1
|
+
/// <reference path="tw.d.ts" />
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export * from 'tiddlywiki';
|
|
4
|
+
|
|
5
|
+
import * as TW from 'tiddlywiki';
|
|
6
|
+
|
|
7
|
+
import '@types/node';
|
|
8
|
+
declare global {
|
|
9
|
+
const $tw: TW.ITiddlyWiki;
|
|
10
|
+
// const Buffer: ?Buffer;
|
|
11
|
+
// const clearInterval: typeof global.clearInterval;
|
|
12
|
+
// const clearTimeout: typeof global.clearTimeout;
|
|
13
|
+
// const console: Console;
|
|
14
|
+
// const exports: TW.ITWModuleExports;
|
|
15
|
+
// const module: { exports: TW.ITWModuleExports; readonly id: string };
|
|
16
|
+
// const process: ?NodeJS.Process;
|
|
17
|
+
// const require: ITWRequire;
|
|
18
|
+
// const setInterval: typeof global.setInterval;
|
|
19
|
+
// const setTimeout: typeof global.setTimeout;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare module '@types/tiddlywiki' {
|
|
23
|
+
export const TiddlyWiki: TW.TW5InitFunction;
|
|
6
24
|
}
|
package/src/modules.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare module 'tiddlywiki' {
|
|
2
2
|
export interface ITWModuleExports {
|
|
3
|
-
[exportName:
|
|
3
|
+
[exportName: string]: unknown;
|
|
4
4
|
name?: string;
|
|
5
5
|
type?: string;
|
|
6
6
|
}
|
|
@@ -11,7 +11,7 @@ declare module 'tiddlywiki' {
|
|
|
11
11
|
}
|
|
12
12
|
export interface ITWRequire {
|
|
13
13
|
(title: string): ITWModuleExports;
|
|
14
|
-
readonly main: NodeJS.Module | { TiddlyWiki:
|
|
14
|
+
readonly main: NodeJS.Module | { TiddlyWiki: TW5InitFunction };
|
|
15
15
|
}
|
|
16
16
|
export interface IModuleSandbox {
|
|
17
17
|
$tw: ITiddlyWiki;
|
package/src/tw.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference path="filter-operator.d.ts" />
|
|
2
|
+
/// <reference path="modules.d.ts" />
|
|
3
|
+
/// <reference path="Tiddler.d.ts" />
|
|
4
|
+
/// <reference path="twconfig.d.ts" />
|
|
5
|
+
/// <reference path="utils.d.ts" />
|
|
6
|
+
/// <reference path="Widget.d.ts" />
|
|
7
|
+
/// <reference path="Wiki.d.ts" />
|
|
2
8
|
|
|
3
9
|
declare module 'tiddlywiki' {
|
|
4
10
|
export interface IBootFilesIndexItem {
|
|
@@ -65,19 +71,13 @@ declare module 'tiddlywiki' {
|
|
|
65
71
|
/** External JavaScript can populate this array before calling boot.js in order to preload tiddlers */
|
|
66
72
|
preloadTiddlers: Record<string, Record<string, unknown>>;
|
|
67
73
|
|
|
74
|
+
rootWidget: Widget;
|
|
75
|
+
|
|
68
76
|
utils: ITWUtils;
|
|
69
77
|
|
|
70
78
|
version: string;
|
|
71
|
-
|
|
72
79
|
wiki: Wiki;
|
|
73
|
-
rootWidget: Widget;
|
|
74
80
|
}
|
|
75
81
|
|
|
76
|
-
export
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
import { ITiddlyWiki } from 'tiddlywiki';
|
|
80
|
-
declare global {
|
|
81
|
-
const $tw: ITiddlyWiki;
|
|
82
|
+
export type TW5InitFunction = ($tw?: ITiddlyWiki) => ITiddlyWiki;
|
|
82
83
|
}
|
|
83
|
-
export {}
|
package/src/twconfig.d.ts
CHANGED
package/src/utils.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
/// <reference path="Crypto.d.ts" />
|
|
2
|
+
/// <reference path="PasswordPrompt.d.ts" />
|
|
3
|
+
|
|
1
4
|
declare module 'tiddlywiki' {
|
|
2
5
|
export type TWDocument = Document;
|
|
3
6
|
export type TWDOMElement = Element;
|
|
4
7
|
export type TWEachCallback<T> = (element?: unknown, index?: string | number, object?: T) => boolean | undefined;
|
|
5
|
-
interface ITWUtils {
|
|
8
|
+
export interface ITWUtils {
|
|
6
9
|
Crypto: typeof Crypto;
|
|
7
10
|
PasswordPrompt: typeof PasswordPrompt;
|
|
8
11
|
/** Returns true if the version string A is greater than the version string B. Returns true if the versions are the same */
|
package/src/widget.d.ts
CHANGED
|
@@ -1,37 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
declare module 'tiddlywiki' {
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
3
|
+
class variablesConstructor {}
|
|
3
4
|
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
export class Widget {
|
|
6
|
+
constructor(parseTreeNode: unknown, options: unknown);
|
|
7
|
+
initialize: (parseTreeNode: unknown, options: unknown) => void;
|
|
8
|
+
parseTreeNode: unknown;
|
|
9
|
+
wiki: unknown;
|
|
10
|
+
parentWidget?: Widget;
|
|
11
|
+
variablesConstructor: variablesConstructor;
|
|
12
|
+
variables: unknown;
|
|
13
|
+
domNodes: Node[];
|
|
14
|
+
/**
|
|
14
15
|
Add an event listener
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
addEventListener(type: string, handler: (arguments_: unknown[]) => void): void;
|
|
18
|
+
/**
|
|
18
19
|
Dispatch an event to a widget. If the widget doesn't handle the event then it is also dispatched to the parent widget
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
dispatchEvent(type: string): void;
|
|
22
|
+
/**
|
|
22
23
|
Add a list of event listeners from an array [{type:,handler:},...]
|
|
23
24
|
*/
|
|
24
|
-
|
|
25
|
+
addEventListeners(listeners: Array<{ handler: (arguments_: unknown[]) => void; type: string }>): void;
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
parentDomNode: Node;
|
|
28
|
+
execute: () => void;
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Lifecycle method: Render this widget into the DOM
|
|
32
|
+
*/
|
|
33
|
+
render(parent: Node, nextSibling: Node): void;
|
|
34
|
+
computeAttributes(): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get parameters that user set in the widget
|
|
37
|
+
* @param name attribute name, for example, `actions` in the button widget
|
|
38
|
+
*/
|
|
39
|
+
getAttribute(name: string): string;
|
|
40
|
+
}
|
|
37
41
|
}
|
package/src/tiddlywiki-test.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Widget as IWidget } from 'tiddlywiki'
|
|
2
|
-
|
|
3
|
-
const Widget = {} as unknown as IWidget;
|
|
4
|
-
export class ReactWidget extends Widget {
|
|
5
|
-
constructor(parseTreeNode: any, options: any) {
|
|
6
|
-
super(parseTreeNode, options);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
render(parent: Node, nextSibling: Node) {
|
|
10
|
-
this.parentDomNode = parent;
|
|
11
|
-
this.execute();
|
|
12
|
-
this.computeAttributes();
|
|
13
|
-
const containerElement = document.createElement('div');
|
|
14
|
-
this.domNodes.push(containerElement);
|
|
15
|
-
parent.appendChild(containerElement);
|
|
16
|
-
}
|
|
17
|
-
}
|