tw5-typed 0.1.10 → 0.2.0

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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "description": "Types for tiddlywiki",
3
3
  "license": "MIT",
4
4
  "name": "tw5-typed",
5
- "version": "0.1.10",
5
+ "version": "0.2.0",
6
6
  "url": "https://github.com/tiddly-gittly/tw5-typed",
7
7
  "homepage": "https://github.com/tiddly-gittly/tw5-typed",
8
8
  "bugs": {
@@ -20,28 +20,28 @@
20
20
  "prepublishOnly": "npx tsc --noEmit"
21
21
  },
22
22
  "devDependencies": {
23
- "@types/node": "^17.0.18",
24
- "@typescript-eslint/eslint-plugin": "5.11.0",
25
- "@typescript-eslint/parser": "5.11.0",
26
- "eslint": "8.8.0",
27
- "eslint-config-prettier": "8.3.0",
28
- "eslint-config-standard": "17.0.0-1",
23
+ "@types/node": "^17.0.23",
24
+ "@typescript-eslint/eslint-plugin": "5.17.0",
25
+ "@typescript-eslint/parser": "5.17.0",
26
+ "eslint": "8.12.0",
27
+ "eslint-config-prettier": "8.5.0",
28
+ "eslint-config-standard": "16.0.3",
29
29
  "eslint-config-standard-with-typescript": "21.0.1",
30
30
  "eslint-import-resolver-alias": "1.1.2",
31
- "eslint-import-resolver-typescript": "2.5.0",
31
+ "eslint-import-resolver-typescript": "2.7.0",
32
32
  "eslint-plugin-html": "6.2.0",
33
33
  "eslint-plugin-import": "2.25.4",
34
- "eslint-plugin-n": "14.0.0",
34
+ "eslint-plugin-n": "15.1.0",
35
35
  "eslint-plugin-node": "11.1.0",
36
36
  "eslint-plugin-prettier": "4.0.0",
37
37
  "eslint-plugin-promise": "6.0.0",
38
- "eslint-plugin-react": "7.28.0",
39
- "eslint-plugin-react-hooks": "4.3.0",
38
+ "eslint-plugin-react": "7.29.4",
39
+ "eslint-plugin-react-hooks": "4.4.0",
40
40
  "eslint-plugin-security": "1.4.0",
41
41
  "eslint-plugin-security-node": "1.1.1",
42
42
  "eslint-plugin-typescript-sort-keys": "2.1.0",
43
- "eslint-plugin-unicorn": "40.1.0",
44
- "prettier": "2.5.1",
45
- "typescript": "4.5.5"
43
+ "eslint-plugin-unicorn": "42.0.0",
44
+ "prettier": "2.6.1",
45
+ "typescript": "4.6.3"
46
46
  }
47
47
  }
package/src/Wiki.d.ts CHANGED
@@ -29,6 +29,10 @@ declare module 'tiddlywiki' {
29
29
  * Update existed tiddler based on the title field.
30
30
  */
31
31
  addTiddler: (tiddler: Tiddler | ITiddlerFields) => void;
32
+ /**
33
+ * Call `addTiddler` for each iton of the list
34
+ */
35
+ addTiddlers: (tiddler: Array<Tiddler | ITiddlerFields>) => void;
32
36
  /**
33
37
  * Get tiddler's text field, with an optional default text.
34
38
  * If have _is_skinny field, will just return null (this is a rare case, so not put in the return type for now).
package/src/ast.d.ts CHANGED
@@ -1,49 +1,68 @@
1
1
  declare module 'tiddlywiki' {
2
2
  export interface IParseTreeAttribute {
3
- start: number;
4
- name: string;
3
+ end?: number;
4
+ name?: string;
5
+ start?: number;
5
6
  type: 'string' | 'number';
6
7
  value: string;
7
- end: number;
8
8
  }
9
+
9
10
  export interface IWikiASTNode {
10
- type: string;
11
+ attributes?: Record<string, IParseTreeAttribute>;
11
12
  children?: IParseTreeNode[];
12
- start?: number;
13
13
  end?: number;
14
14
  isBlock?: boolean;
15
15
  isSelfClosing?: boolean;
16
- attributes?: Record<string, IParseTreeAttribute>;
17
16
  orderedAttributes?: IParseTreeAttribute[];
17
+ start?: number;
18
+ type: string;
18
19
  }
19
20
  export interface ITextParseTreeNode extends IWikiASTNode {
20
- type: 'text';
21
21
  text: string;
22
+ type: 'text';
22
23
  }
23
24
  export interface ILinkParseTreeNode extends IWikiASTNode {
24
- type: 'link';
25
25
  text: string;
26
+ type: 'link';
26
27
  }
27
- export type HTMLTags = keyof HTMLElementTagNameMap
28
+ export type HTMLTags = keyof HTMLElementTagNameMap | 'strike';
29
+
28
30
  export interface IDomParseTreeNode extends IWikiASTNode {
29
- type: 'element';
30
31
  tag: HTMLTags;
32
+ type: 'element';
33
+ }
34
+ export interface ICodeBlockParseTreeNode extends IWikiASTNode {
35
+ attributes: {
36
+ code?:
37
+ | {
38
+ type: 'string';
39
+ value: string;
40
+ }
41
+ | undefined;
42
+ language?:
43
+ | {
44
+ type: 'string';
45
+ value: string;
46
+ }
47
+ | undefined;
48
+ };
49
+ type: 'codeblock';
31
50
  }
32
- export interface IMacroParamCallParseTreeNode extends IWikiASTNode {
51
+ export interface IMacroParameterCallParseTreeNode extends IWikiASTNode {
52
+ name?: string;
33
53
  type: 'macro-parameter';
34
54
  value: string;
35
- name?: string;
36
55
  }
37
56
  export interface IMacroCallParseTreeNode extends IWikiASTNode {
38
- type: 'macrocall';
39
57
  name: string;
40
- params: IMacroParamCallParseTreeNode[];
58
+ params: IMacroParameterCallParseTreeNode[];
59
+ type: 'macrocall';
41
60
  }
42
61
  export interface ICustomParseTreeNode extends IWikiASTNode {
43
- type: string;
62
+ params: IMacroParameterCallParseTreeNode[];
44
63
  tag?: string;
45
- params: IMacroParamCallParseTreeNode[];
46
64
  text?: string;
65
+ type: string;
47
66
  }
48
- export type IParseTreeNode = IDomParseTreeNode | IMacroParamCallParseTreeNode | IMacroCallParseTreeNode | ITextParseTreeNode | ICustomParseTreeNode;
67
+ export type IParseTreeNode = IDomParseTreeNode | IMacroParameterCallParseTreeNode | IMacroCallParseTreeNode | ITextParseTreeNode | ICustomParseTreeNode;
49
68
  }
@@ -93,7 +93,10 @@ 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: IFilterOperatorParameterOperator) => string[] | ((iter: SourceIterator) => void);
96
+ export type IFilterOperator = (
97
+ source: (iter: SourceIterator) => void,
98
+ operator: IFilterOperatorParameterOperator,
99
+ ) => string[] | ((iter: SourceIterator) => void);
97
100
 
98
101
  /**
99
102
  * 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`.
package/src/index.d.ts CHANGED
@@ -1,24 +1,19 @@
1
1
  /// <reference path="tw.d.ts" />
2
-
3
- export * from 'tiddlywiki';
2
+ /// <reference path="server.d.ts" />
4
3
 
5
4
  import * as TW from 'tiddlywiki';
6
5
 
7
- import '@types/node';
6
+ export * from 'tiddlywiki';
8
7
  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;
8
+ const $tw: TW.ITiddlyWiki;
9
+ // const Buffer: ?Buffer;
10
+ // const clearInterval: typeof global.clearInterval;
11
+ // const clearTimeout: typeof global.clearTimeout;
12
+ // const console: Console;
13
+ // const exports: TW.ITWModuleExports;
14
+ // const module: { exports: TW.ITWModuleExports; readonly id: string };
15
+ // const process: ?NodeJS.Process;
16
+ // const require: ITWRequire;
17
+ // const setInterval: typeof global.setInterval;
18
+ // const setTimeout: typeof global.setTimeout;
24
19
  }
package/src/modules.d.ts CHANGED
@@ -69,7 +69,7 @@ declare module 'tiddlywiki' {
69
69
  * @param {(title, moduleExports) => void} callback function called as callback(title,moduleExports) for each module
70
70
  * @memberof ITWModules
71
71
  */
72
- forEachModuleOfType(moduleType: string, callback: (title, moduleExports) => void): void;
72
+ forEachModuleOfType(moduleType: string, callback: (title: string, moduleExports: unknown) => void): void;
73
73
  /** Get all the modules of a particular type in a hashmap by their `name` field */
74
74
  getModulesByTypeAsHashmap(moduleType: string, nameField: string): Record<string, IModuleInfo>;
75
75
  /** hashmap by module name of moduleInfo */
package/src/parser.d.ts CHANGED
@@ -1,16 +1,18 @@
1
+ /// <reference path="ast.d.ts" />
2
+
1
3
  declare module 'tiddlywiki' {
2
4
  export interface IParserOptions {
3
- /**
4
- * While calling `getCacheForTiddler`, use inlineParseTree or blockParseTree
5
- */
6
- parseAsInline?: boolean;
7
5
  /**
8
6
  * Optional source uri, used in parseText
9
7
  */
10
8
  _canonical_uri?: string;
9
+ /**
10
+ * While calling `getCacheForTiddler`, use inlineParseTree or blockParseTree
11
+ */
12
+ parseAsInline?: boolean;
11
13
  }
12
14
 
13
- export declare class WikiParseRule {
15
+ export class WikiParseRule {
14
16
  is: { block?: boolean; inline?: boolean };
15
17
  match?: null;
16
18
  matchRegExp?: RegExp;
@@ -18,25 +20,18 @@ declare module 'tiddlywiki' {
18
20
  nextTag?: null;
19
21
  /** `{type: 'macrocall', start: 261, params: Array(1), name: 'reuse-tiddler', end: 290}` */
20
22
  nextCall?: {
21
- type: string;
22
- start: number;
23
23
  end: number;
24
- /** `{ type: 'macro-parameter'; start: 276; value: '快速创建新笔记按钮'; end: 288 }` */
25
- params: { type: string; start: number; end: number; value: string };
26
24
  name: string;
25
+ /** `{ type: 'macro-parameter'; start: 276; value: '快速创建新笔记按钮'; end: 288 }` */
26
+ params: { end: number; start: number; type: string; value: string };
27
+ start: number;
28
+ type: string;
27
29
  };
28
30
  }
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 }[];
31
+ export class WikiParser {
32
+ blockRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
33
+ inlineRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
34
+ pragmaRules: Array<{ matchIndex?: number; rule: WikiParseRule }>;
40
35
  configTrimWhiteSpace: boolean;
41
36
  pos: number;
42
37
  source: string;
@@ -0,0 +1,28 @@
1
+ /// <reference path="Wiki.d.ts" />
2
+
3
+ import type Http from 'http';
4
+
5
+ declare module 'tiddlywiki' {
6
+ export interface IServerStatus {
7
+ anonymous: boolean;
8
+ read_only: boolean;
9
+ space: {
10
+ recipe: string;
11
+ };
12
+ tiddlywiki_version: string;
13
+ username: string;
14
+ }
15
+
16
+ export interface ServerEndpointContext {
17
+ data: string;
18
+ wiki: Wiki;
19
+ }
20
+ /**
21
+ * @link https://talk.tiddlywiki.org/t/what-is-the-state-in-server-route-handler/2877
22
+ */
23
+ export type ServerEndpointHandler<T = Record<string, any>> = (
24
+ request: Http.ClientRequest,
25
+ response: Http.ServerResponse,
26
+ context: ServerEndpointContext & T,
27
+ ) => void;
28
+ }
package/src/tw.d.ts CHANGED
@@ -8,6 +8,8 @@
8
8
  /// <reference path="parser.d.ts" />
9
9
  /// <reference path="ast.d.ts" />
10
10
 
11
+ import { Server } from 'http';
12
+
11
13
  declare module 'tiddlywiki' {
12
14
  export interface IBootFilesIndexItem {
13
15
  filepath: string;
@@ -24,8 +26,6 @@ declare module 'tiddlywiki' {
24
26
  tiddlers: ITiddlerFields[];
25
27
  }
26
28
 
27
- export class Server {}
28
-
29
29
  export interface IFileExtensionInfo {
30
30
  type: string;
31
31
  }
@@ -43,11 +43,11 @@ declare module 'tiddlywiki' {
43
43
 
44
44
  boot: {
45
45
  argv: string[];
46
+ boot(callback?: () => unknown): void;
46
47
  files: IBootFilesIndex;
47
48
  log(logString: string): void;
48
49
  logMessages: string[];
49
50
  startup(options: { callback?: () => unknown }): void;
50
- boot(callback?: () => unknown): void;
51
51
  /** Default boot tasks */
52
52
  tasks: {
53
53
  readBrowserTiddlers: boolean;
package/src/utils.d.ts CHANGED
@@ -8,6 +8,13 @@ declare module 'tiddlywiki' {
8
8
  export interface ITWUtils {
9
9
  Crypto: typeof Crypto;
10
10
  PasswordPrompt: typeof PasswordPrompt;
11
+ /**
12
+ * Alternative to `element.classList.add`, add a css class name to an element, see issue for detail.
13
+ * @link https://github.com/Jermolene/TiddlyWiki5/issues/6475
14
+ * @param element
15
+ * @param className
16
+ */
17
+ addClass(element: Element, className: string): void;
11
18
  /** Returns true if the version string A is greater than the version string B. Returns true if the versions are the same */
12
19
  checkVersions(versionStringA: string, versionStringB: string): boolean;
13
20
  /**
@@ -95,6 +102,7 @@ declare module 'tiddlywiki' {
95
102
  parseDate(value: string | Date): Date;
96
103
  /** Parse a block of name:value fields. The `fields` object is used as the basis for the return value */
97
104
  parseFields(text: string, fields?: object): object;
105
+ parseJSONSafe(input: string): any;
98
106
  /** Parse a string array from a bracketted list. For example "OneTiddler [[Another Tiddler]] LastOne" */
99
107
  parseStringArray(value: string | string[], allowDuplicate?: boolean): string[];
100
108
  /** Parse a semantic version string into its constituent parts -- see https://semver.org */
package/src/widget.d.ts CHANGED
@@ -1,4 +1,13 @@
1
1
  declare module 'tiddlywiki' {
2
+ /**
3
+ * Parameter of Widget.refresh
4
+ * Key is tiddler title
5
+ */
6
+ export type IChangedTiddlers = Record<string, IChangedTiddlersMeta>;
7
+ export interface IChangedTiddlersMeta {
8
+ modified: boolean;
9
+ }
10
+
2
11
  // eslint-disable-next-line @typescript-eslint/no-extraneous-class
3
12
  class variablesConstructor {}
4
13
 
@@ -40,9 +49,7 @@ declare module 'tiddlywiki' {
40
49
  * @param changedTiddlers Object key is tiddler title, value is metadata about the change
41
50
  * @link https://tiddlywiki.com/dev/#Selective%20Update
42
51
  */
43
- refresh(changedTiddlers: Record<string, {
44
- modified: boolean
45
- }>): boolean;
52
+ refresh(changedTiddlers: IChangedTiddlers): boolean;
46
53
  computeAttributes(): void;
47
54
  /**
48
55
  * Get parameters that user set in the widget