tw5-typed 0.2.17 → 0.2.19

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Tiddly Gittly
3
+ Copyright (c) 2023 Tiddly Gittly
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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.2.17",
5
+ "version": "0.2.19",
6
6
  "url": "https://github.com/tiddly-gittly/tw5-typed",
7
7
  "homepage": "https://github.com/tiddly-gittly/tw5-typed",
8
8
  "bugs": {
@@ -16,6 +16,9 @@
16
16
  "files": [
17
17
  "src/"
18
18
  ],
19
+ "scripts": {
20
+ "check": "tsc --noEmit && eslint src/**/*.ts"
21
+ },
19
22
  "husky": {
20
23
  "hooks": {
21
24
  "pre-commit": "lint-staged"
@@ -32,14 +35,15 @@
32
35
  "devDependencies": {
33
36
  "@modern-js/eslint-config": "latest",
34
37
  "@modern-js/tsconfig": "latest",
35
- "@types/node": "^18.11.9",
36
38
  "husky": "^8.0.2",
37
39
  "lint-staged": "^13.1.0",
38
40
  "rimraf": "^3.0.2",
39
41
  "tiddlywiki": "^5.2.5",
40
42
  "typescript": "^4.9.4"
41
43
  },
42
- "scripts": {
43
- "check": "tsc --noEmit && eslint src/**/*.ts"
44
+ "dependencies": {
45
+ "@types/codemirror": "^5.60.6",
46
+ "@types/echarts": "^4.9.16",
47
+ "@types/node": "^18.11.9"
44
48
  }
45
- }
49
+ }
@@ -10,42 +10,46 @@ declare module 'tiddlywiki' {
10
10
  type: string;
11
11
  }
12
12
 
13
- interface ITWConfig {
13
+ export type ITWConfig = IConfig;
14
+
15
+ interface IConfig {
14
16
  [configName: string]: unknown;
15
17
  /** Map type to file content type */
16
18
  contentTypeInfo: Record<string, IContentTypeInfo>;
17
- /** Default is `TIDDLYWIKI_EDITION_PATH` */
19
+ /** @default 'TIDDLYWIKI_EDITION_PATH' */
18
20
  editionsEnvVar: string;
19
- /** Default is `../editions/` */
21
+ /** @default '../editions/' */
20
22
  editionsPath: string;
21
23
  /** Map file extension */
22
24
  fileExtensionInfo: Record<string, IFileExtensionInfo>;
23
- /** Default is `^\\/\\*\\\\(?:\\r?\\n)((?:^[^\\r\\n]*(?:\\r?\\n))+?)(^\\\\\\*\\/$(?:\\r?\\n)?)` */
25
+ /**
26
+ * @default '^\\/\\*\\\\(?:\\r?\\n)((?:^[^\\r\\n]*(?:\\r?\\n))+?)(^\\\\\\*\\/$(?:\\r?\\n)?)
27
+ */
24
28
  jsModuleHeaderRegExpString: string;
25
- /** Default is `TIDDLYWIKI_LANGUAGE_PATH` */
29
+ /** @default 'TIDDLYWIKI_LANGUAGE_PATH' */
26
30
  languagesEnvVar: string;
27
- /** Default is `../languages/` */
31
+ /** @default '../languages/' */
28
32
  languagesPath: string;
29
33
  //
30
- /** Default is `TIDDLYWIKI_PLUGIN_PATH` */
34
+ /** @default 'TIDDLYWIKI_PLUGIN_PATH' */
31
35
  pluginsEnvVar: string;
32
- /** Default is `../plugins/` */
36
+ /** @default '../plugins/'' */
33
37
  pluginsPath: string;
34
- /** Default is `TIDDLYWIKI_THEME_PATH` */
38
+ /** @default 'TIDDLYWIKI_THEME_PATH' */
35
39
  themesEnvVar: string;
36
- /** Default is `../themes/` */
40
+ /** @default '../themes/' */
37
41
  themesPath: string;
38
- /** Default is `./tiddlywiki.info` */
42
+ /** @default './tiddlywiki.info' */
39
43
  wikiInfo: string;
40
- /** Default is `./languages` */
44
+ /** @default './languages' */
41
45
  wikiLanguagesSubDir: string;
42
- /** Default is `./output` */
46
+ /** @default './output' */
43
47
  wikiOutputSubDir: string;
44
- /** Default is `./plugins` */
48
+ /** @default './plugins' */
45
49
  wikiPluginsSubDir: string;
46
- /** Default is `./themes` */
50
+ /** @default './themes' */
47
51
  wikiThemesSubDir: string;
48
- /** Default is `./tiddlers` */
52
+ /** @default './tiddlers' */
49
53
  wikiTiddlersSubDir: string;
50
54
  }
51
55
  }
package/src/core.d.ts CHANGED
@@ -1,8 +1,10 @@
1
+ /// <reference path="hooks.d.ts" />
1
2
  /// <reference path="boot/index.d.ts" />
2
3
  /// <reference path="wiki/index.d.ts" />
3
4
  /// <reference path="utils/index.d.ts" />
4
5
  /// <reference path="tiddler/index.d.ts" />
5
6
  /// <reference path="modules/index.d.ts" />
7
+ /// <reference path="plugins/index.d.ts" />
6
8
 
7
9
  declare module 'tiddlywiki' {
8
10
  export interface IPluginInfo {
@@ -22,19 +24,20 @@ declare module 'tiddlywiki' {
22
24
 
23
25
  export interface ITiddlyWiki {
24
26
  Wiki: typeof Wiki;
27
+ Story: typeof Story;
25
28
  Tiddler: typeof Tiddler;
26
29
 
27
30
  wiki: Wiki;
28
31
  boot: IBoot;
29
32
  crypto: Crypto;
30
- utils: ITWUtils;
33
+ utils: IUtils;
31
34
  version: string;
32
35
  safeMode: boolean;
33
- config: ITWConfig;
36
+ config: IConfig;
34
37
  rootWidget: Widget;
35
38
  notifier: Notifier;
36
39
  language: ILanguage;
37
- modules: ITWModules;
40
+ modules: IModules;
38
41
  locationHash: string;
39
42
  passwordPrompt: PasswordPrompt;
40
43
  packageInfo: Record<string, unknown>;
@@ -46,34 +49,14 @@ declare module 'tiddlywiki' {
46
49
  dragInProgress?: boolean;
47
50
 
48
51
  /**
49
- Global Hooks mechanism which allows plugins to modify default functionality
50
- */
51
- hooks: {
52
- names: Record<string, any>;
53
- /**
54
- Add hooks to the hashmap
55
- */
56
- addHook(
57
- hookName: 'th-server-command-post-start',
58
- callback: (listenCommand: unknown, server: Server) => void,
59
- ): void;
60
- addHook(
61
- hookName: string,
62
- callback: (...arguments_: unknown[]) => unknown,
63
- ): void;
64
- /**
65
- Invoke the hook by key
66
- */
67
- invokeHook(
68
- hookName: string,
69
- event: IWidgetEvent,
70
- ): undefined | IWidgetEvent;
71
- };
52
+ * Global Hooks mechanism which allows plugins to modify default functionality
53
+ */
54
+ hooks: IHooks;
72
55
 
73
- addUnloadTask(task: any): void;
56
+ addUnloadTask(task: any);
74
57
 
75
58
  /** Convenience function for pushing a tiddler onto the preloading array */
76
- preloadTiddler(fields: Record<string, unknown>): void;
59
+ preloadTiddler(fields: Record<string, unknown>);
77
60
  /** Convenience function for pushing an array of tiddlers onto the preloading array */
78
61
  preloadTiddlerArray(fieldsArray: Array<Record<string, unknown>>): void;
79
62
  /** External JavaScript can populate this array before calling boot.js in order to preload tiddlers */
package/src/hooks.d.ts ADDED
@@ -0,0 +1,83 @@
1
+ declare module 'tiddlywiki' {
2
+ interface IHooks {
3
+ names: Record<string, Function[]>;
4
+ /** Add hooks to the hashmap */
5
+ addHook(
6
+ hookName: 'th-server-command-post-start',
7
+ callback: (
8
+ server: unknown,
9
+ nodeServer: Server,
10
+ who: 'tiddlywiki',
11
+ ) => void,
12
+ );
13
+ addHook(
14
+ hookName: 'th-saving-tiddler',
15
+ callback: (toTiddler: Tiddler, fromTiddler: Tiddler) => Tiddler | void,
16
+ );
17
+ addHook(
18
+ hookName: 'th-renaming-tiddler',
19
+ callback: (toTiddler: Tiddler, fromTiddler: Tiddler) => Tiddler | void,
20
+ );
21
+ addHook(
22
+ hookName: 'th-relinking-tiddler',
23
+ callback: (toTiddler: Tiddler, fromTiddler: Tiddler) => Tiddler | void,
24
+ );
25
+ addHook(
26
+ hookName: 'th-importing-tiddler',
27
+ callback: (tiddler: Tiddler) => Tiddler | void,
28
+ );
29
+ addHook(
30
+ hookName: 'th-before-importing',
31
+ callback: (tiddler: Tiddler) => Tiddler | void,
32
+ );
33
+ addHook(
34
+ hookName: 'th-opening-default-tiddlers-list',
35
+ callback: (storyList: string[]) => string[],
36
+ );
37
+ addHook(
38
+ hookName: 'th-make-tiddler-path',
39
+ callback: (fullPath: string, fullPath: string) => string,
40
+ );
41
+ addHook(
42
+ hookName: 'th-rendering-element',
43
+ callback: (
44
+ parseTreeNodes: IParseTreeNode | null,
45
+ widget: Widget,
46
+ ) => parseTreeNodes,
47
+ );
48
+ addHook(hookName: 'th-navigating', callback: (event: unknown) => unknown);
49
+ addHook(
50
+ hookName: 'th-closing-tiddler',
51
+ callback: (event: unknown) => unknown,
52
+ );
53
+ addHook(
54
+ hookName: 'th-editing-tiddler',
55
+ callback: (event: unknown) => unknown,
56
+ );
57
+ addHook(
58
+ hookName: 'th-cancelling-tiddler',
59
+ callback: (event: unknown) => unknown,
60
+ );
61
+ addHook(hookName: 'th-new-tiddler', callback: (event: unknown) => unknown);
62
+ addHook(hookName: 'th-deleting-tiddler', callback: (title: string) => void);
63
+ addHook(hookName: 'th-page-refreshed', callback: () => void);
64
+ addHook(hookName: 'th-boot-tiddlers-loaded', callback: () => void);
65
+ addHook(hookName: 'th-page-refreshed', callback: () => void);
66
+ addHook(hookName: 'th-page-refreshing', callback: () => void);
67
+ addHook(hookName: 'th-page-refreshed', callback: () => void);
68
+ addHook(
69
+ hookName: 'th-importing-file',
70
+ callback: (props: {
71
+ file: unknown;
72
+ type: string;
73
+ isBinary: boolean;
74
+ callback: Function;
75
+ }) => boolean | void,
76
+ );
77
+ addHook(hookName: string, callback: (...arguments_: unknown[]) => unknown);
78
+ /**
79
+ * Invoke the hook by key
80
+ */
81
+ invokeHook(hookName: string, event: IWidgetEvent): undefined | IWidgetEvent;
82
+ }
83
+ }
@@ -1,3 +1,6 @@
1
+ /// <reference path="wiki.d.ts" />
2
+ /// <reference path="story.d.ts" />
3
+ /// <reference path="utils/index.d.ts" />
1
4
  /// <reference path="server/index.d.ts" />
2
5
  /// <reference path="parsers/index.d.ts" />
3
6
  /// <reference path="widgets/index.d.ts" />
@@ -18,7 +21,7 @@ declare module 'tiddlywiki' {
18
21
  (title: string): ITWModuleExports;
19
22
  readonly main: NodeJS.Module | { TiddlyWiki: TW5InitFunction };
20
23
  }
21
- export interface IModuleSandbox {
24
+ export interface IEvalContent {
22
25
  $tw: ITiddlyWiki;
23
26
  // eslint-disable-next-line node/prefer-global/buffer
24
27
  Buffer?: Buffer;
@@ -37,6 +40,9 @@ declare module 'tiddlywiki' {
37
40
  exports: ITWModuleExports,
38
41
  requireFunction: ITWRequire,
39
42
  ) => void;
43
+
44
+ export type ITWModules = IModules;
45
+
40
46
  /**
41
47
  * Information about each module is kept in an object with these members:
42
48
  *
@@ -52,7 +58,7 @@ declare module 'tiddlywiki' {
52
58
  *
53
59
  * 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
54
60
  */
55
- interface ITWModules {
61
+ interface IModules {
56
62
  /** Apply the exports of the modules of a particular type to a target object */
57
63
  applyMethods: (
58
64
  moduleType: string,
@@ -0,0 +1,56 @@
1
+ declare module 'tiddlywiki' {
2
+ export class Story {
3
+ wiki: Wiki;
4
+ storyTitle: string;
5
+ historyTitle: string;
6
+
7
+ constructor(options: {
8
+ wiki?: Wiki;
9
+ storyTitle?: string;
10
+ historyTitle?: string;
11
+ });
12
+
13
+ getStoryList(): string[];
14
+
15
+ navigateTiddler(
16
+ navigateTo: string,
17
+ navigateFromTitle: string,
18
+ navigateFromClientRect: DOMRect,
19
+ );
20
+
21
+ addToStory(
22
+ navigateTo: string,
23
+ navigateFromTitle: string,
24
+ options?: {
25
+ openLinkFromInsideRiver?: 'top' | 'bottom' | 'above' | 'below';
26
+ },
27
+ );
28
+
29
+ addToHistory(
30
+ navigateTo: string | string[],
31
+ navigateFromClientRect: DOMRect,
32
+ );
33
+
34
+ saveStoryList(storyList: string[] | string);
35
+
36
+ storyCloseTiddler(targetTitle: string);
37
+
38
+ storyCloseAllTiddlers();
39
+
40
+ storyCloseOtherTiddlers(targetTitle: string);
41
+
42
+ storyEditTiddler(targetTitle: string);
43
+
44
+ storyDeleteTiddler(targetTitle: string);
45
+
46
+ storySaveTiddler(targetTitle: string);
47
+
48
+ storyCancelTiddler(targetTitle: string);
49
+
50
+ storyNewTiddler(targetTitle: string);
51
+ }
52
+ }
53
+
54
+ declare module '$:/core/modules/story.js' {
55
+ export { Story } from 'tiddlywiki';
56
+ }
@@ -0,0 +1,51 @@
1
+ declare const addClass: (element: Element, className: string) => void;
2
+ declare const addEventListeners: (
3
+ domNode: Node,
4
+ events: {
5
+ handlerFunction?: (event: MouseEvent) => void;
6
+ handlerMethod?: string;
7
+ handlerObject?: Widget;
8
+ name: string;
9
+ }[],
10
+ ) => void;
11
+
12
+ export class Notifier {
13
+ /**
14
+ * Display a notification
15
+ * * title: Title of tiddler containing the notification text
16
+ * * options: see below
17
+ * Options include:
18
+ */
19
+ display(title: string, options?: Record<string, unknown>): void;
20
+ }
21
+
22
+ declare module 'tiddlywiki' {
23
+ interface IUtils {
24
+ /**
25
+ * Alternative to `element.classList.add`, add a css class name to an element, see issue for detail.
26
+ * @link https://github.com/Jermolene/TiddlyWiki5/issues/6475
27
+ * @param element
28
+ * @param className
29
+ */
30
+ addClass: typeof addClass;
31
+ /**
32
+ * Attach specified event handlers to a DOM node
33
+ * @param domNode: where to attach the event handlers
34
+ * @param events: array of event handlers to be added (see below)
35
+ * Each entry in the events array is an object with these properties:
36
+ * * name: event name of `addEventListener`
37
+ * * handlerFunction: optional event handler function
38
+ * * handlerObject: optional event handler object
39
+ * * handlerMethod: optionally specifies object handler method name (defaults to `handleEvent`)
40
+ */
41
+ addEventListeners: typeof addEventListeners;
42
+ /**
43
+ * Notifier mechanism
44
+ */
45
+ Notifier: typeof Notifier;
46
+ }
47
+ }
48
+
49
+ declare module '$:/core/modules/utils/dom.js' {
50
+ export { addClass, addEventListeners, Notifier };
51
+ }
@@ -0,0 +1,33 @@
1
+ declare const generateTiddlerFilepath: (
2
+ title: string,
3
+ options?: {
4
+ directory?: string;
5
+ extension?: string;
6
+ fileInfo?: {
7
+ originalpath?: string;
8
+ filePath?: string;
9
+ writeError?: boolean;
10
+ };
11
+ pathFilters?: string[];
12
+ wiki?: Wiki;
13
+ },
14
+ ) => string;
15
+
16
+ declare module 'tiddlywiki' {
17
+ interface IUtils {
18
+ /**
19
+ * Generate the filepath for saving a tiddler
20
+ * Options include:
21
+ * * extension: file extension to be added the finished filepath
22
+ * * directory: absolute path of root directory to which we are saving
23
+ * * pathFilters: optional array of filters to be used to generate the base path
24
+ * * wiki: optional wiki for evaluating the pathFilters
25
+ * * fileInfo: an existing fileInfo object to check against
26
+ */
27
+ generateTiddlerFilepath: typeof generateTiddlerFilepath;
28
+ }
29
+ }
30
+
31
+ declare module '$:/core/modules/utils/utils.js' {
32
+ export { generateTiddlerFilepath };
33
+ }
@@ -0,0 +1,3 @@
1
+ /// <reference path="dom.d.ts" />
2
+ /// <reference path="utils.d.ts" />
3
+ /// <reference path="filesystem.d.ts" />
@@ -0,0 +1,25 @@
1
+ declare const count: (object: object) => number;
2
+ declare const hashString: (str: string) => number;
3
+ declare const formatDateString: (date: Date, format: string) => string;
4
+
5
+ declare module 'tiddlywiki' {
6
+ interface IUtils {
7
+ /**
8
+ * @en
9
+ * Return the number of keys in an object
10
+ * @zh
11
+ * 返回一个对象中的键的数量
12
+ */
13
+ count: typeof count;
14
+ /** the function behind `<<now "format">> */
15
+ formatDateString: typeof formatDateString;
16
+ /** Hash a string to a number
17
+ * Derived from http://stackoverflow.com/a/15710692
18
+ */
19
+ hashString: typeof hashString;
20
+ }
21
+ }
22
+
23
+ declare module '$:/core/modules/utils/utils.js' {
24
+ export { count, formatDateString, hashString };
25
+ }
@@ -36,11 +36,22 @@ declare module 'tiddlywiki' {
36
36
  widget: Widget;
37
37
  }
38
38
 
39
- // eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-extraneous-class
40
- class variablesConstructor {}
39
+ export interface IWidgetInitializeOptions {
40
+ wiki?: ITiddlyWiki;
41
+ parentWidget?: Widget;
42
+ }
41
43
 
42
44
  /**
43
45
  * @link https://tiddlywiki.com/dev/#Widgets
46
+ *
47
+ * Create a widget object for a parse tree node
48
+ * * parseTreeNode: reference to the parse tree node to be rendered
49
+ * * options: see below
50
+ *
51
+ * Options include:
52
+ * * wiki: mandatory reference to wiki associated with this render tree
53
+ * * parentWidget: optional reference to a parent renderer node for the context chain
54
+ * * document: optional document object to use instead of global document
44
55
  */
45
56
  export class Widget {
46
57
  parseTreeNode: IParseTreeNode;
@@ -51,30 +62,48 @@ declare module 'tiddlywiki' {
51
62
 
52
63
  parentWidget?: Widget;
53
64
 
54
- /** we can use $tw.rootWidget.widgetClasses.widget to new a widget
55
- *
56
- * This is a set of all widgets defined in tiddlywiki.
57
- */
58
- widgetClasses: Record<string, Widget>;
65
+ attributes: Record<string, string>;
66
+
67
+ domNodes: Node[];
68
+
69
+ parentDomNode: Node;
59
70
 
60
- /** we can use $tw.rootWidget.widgetClasses.widget to new a widget
71
+ eventListeners: Record<string, Function>;
72
+
73
+ /**
74
+ * we can use $tw.rootWidget.widgetClasses.xxx to new a widget
61
75
  *
62
- * Like `new widget.widget(widgetNode,{` in `$tw.wiki.makeWidget`
76
+ * This is a set of all widgets defined in tiddlywiki.
63
77
  */
64
- widget: new (parseTreeNode: IParseTreeNode, options?: unknown) => Widget;
78
+ widgetClasses: Record<string, typeof Widget>;
65
79
 
66
80
  children: Widget[];
67
81
 
68
- variablesConstructor: variablesConstructor;
82
+ qualifiers?: Record<string, string>;
69
83
 
70
- variables: unknown;
84
+ ancestorCount?: number;
71
85
 
72
- domNodes: Node[];
86
+ /**
87
+ * Set the value of a context variable
88
+ * * name: name of the variable
89
+ * * value: value of the variable
90
+ * * params: array of {name:, default:} for each parameter
91
+ * * isMacroDefinition: true if the variable is set via a \define macro pragma (and hence should have variable substitution performed)
92
+ */
93
+ variables: Record<
94
+ string,
95
+ {
96
+ value: string;
97
+ params?: { name: string; default: string }[];
98
+ isMacroDefinition: boolean;
99
+ }
100
+ >;
73
101
 
74
- parentDomNode: Node;
102
+ constructor(
103
+ parseTreeNode: IParseTreeNode,
104
+ options?: IWidgetInitializeOptions,
105
+ );
75
106
 
76
- constructor(parseTreeNode: IParseTreeNode, options?: unknown);
77
- initialize(parseTreeNode: IParseTreeNode, options?: unknown): void;
78
107
  /**
79
108
  Make child widgets correspondng to specified parseTreeNodes
80
109
  And push them to `this.children`
@@ -84,9 +113,10 @@ declare module 'tiddlywiki' {
84
113
  parseTreeNodes?: IParseTreeNode[],
85
114
  options?: { variables?: unknown },
86
115
  ): void;
87
- /*
88
- Initialise widget properties. These steps are pulled out of the constructor so that we can reuse them in subclasses
89
- */
116
+
117
+ /**
118
+ * Initialise widget properties. These steps are pulled out of the constructor so that we can reuse them in subclasses
119
+ */
90
120
  initialise(
91
121
  parseTreeNode: IParseTreeNode,
92
122
  options?: {
@@ -280,3 +310,8 @@ declare module 'tiddlywiki' {
280
310
  new (wiki: Wiki): ModalWidget;
281
311
  };
282
312
  }
313
+
314
+ declare module '$:/core/modules/widgets/widget.js' {
315
+ import { Widget } from 'tiddlywiki';
316
+ export { Widget as widget };
317
+ }
@@ -0,0 +1,20 @@
1
+ declare const getCreationFields: () => { created?: Date; creator?: string };
2
+ declare const getModificationFields: () => {
3
+ modified?: Date;
4
+ modifier?: string;
5
+ };
6
+ declare const getTiddlersWithTag: (tag: string) => string[];
7
+
8
+ declare module 'tiddlywiki' {
9
+ export interface Wiki {
10
+ getCreationFields: typeof getCreationFields;
11
+
12
+ getModificationFields: typeof getModificationFields;
13
+
14
+ getTiddlersWithTag: typeof getTiddlersWithTag;
15
+ }
16
+ }
17
+
18
+ declare module '$:/core/modules/wiki.js' {
19
+ export { getModificationFields, getCreationFields, getTiddlersWithTag };
20
+ }
@@ -0,0 +1,4 @@
1
+ declare module '$:/plugins/Gk0Wk/echarts/echarts.min.js' {
2
+ import ECharts from 'echarts';
3
+ export = ECharts;
4
+ }
@@ -0,0 +1 @@
1
+ /// <reference path="echarts/index.d.ts" />
@@ -0,0 +1,2 @@
1
+ /// <reference path="tiddlywiki/index.d.ts" />
2
+ /// <reference path="Gk0Wk/index.d.ts" />
@@ -0,0 +1,4 @@
1
+ declare module '$:/plugins/tiddlywiki/codemirror/lib/codemirror.js' {
2
+ import CodeMirror from 'codemirror';
3
+ export = CodeMirror;
4
+ }
@@ -0,0 +1 @@
1
+ /// <reference path="codemirror/index.d.ts" />
@@ -1,164 +1,360 @@
1
1
  /// <reference path="Crypto.d.ts" />
2
2
  /// <reference path="PasswordPrompt.d.ts" />
3
3
 
4
+ type OptionalPropertyNames<T> = {
5
+ [K in keyof T]-?: {} extends { [P in K]: T[K] } ? K : never;
6
+ }[keyof T];
7
+
8
+ type SpreadProperties<L, R, K extends keyof L & keyof R> = {
9
+ [P in K]: L[P] | Exclude<R[P], undefined>;
10
+ };
11
+
12
+ type Id<T> = T extends infer U ? { [K in keyof U]: U[K] } : never;
13
+
14
+ type SpreadTwo<L, R> = Id<
15
+ Pick<L, Exclude<keyof L, keyof R>> &
16
+ Pick<R, Exclude<keyof R, OptionalPropertyNames<R>>> &
17
+ Pick<R, Exclude<OptionalPropertyNames<R>, keyof L>> &
18
+ SpreadProperties<L, R, OptionalPropertyNames<R> & keyof L>
19
+ >;
20
+
21
+ type Spread<A extends readonly [...any]> = A extends [infer L, ...infer R]
22
+ ? SpreadTwo<L, Spread<R>>
23
+ : unknown;
24
+
4
25
  declare module 'tiddlywiki' {
5
26
  export type TWDocument = Document;
6
- export type TWDOMElement = Element;
7
- /** Callback is invoked with (element, index, object), if callback returns false, then the each loop will be terminated. */
8
- export type TWEachCallback<O, I> = (
9
- element?: I,
10
- indexOrKey?: string | number,
11
- object?: O,
12
- ) => boolean | void;
13
- export interface ITWUtils {
27
+ export type TWElement = Element;
28
+ export type TWDOMElement = TWElement;
29
+ export type ITWUtils = IUtils;
30
+
31
+ export interface IDomMakerOptions {
32
+ /**
33
+ * @type {string}
34
+ * @default 'http://www.w3.org/1999/xhtml'
35
+ * @memberof IDomMakerOptions
36
+ */
37
+ namespace?: string;
38
+
39
+ /**
40
+ * @en
41
+ * hashmap of attribute values
42
+ * @zh
43
+ * 属性值的 map
44
+ *
45
+ * @type {Record<string, unknown>}
46
+ * @memberof IDomMakerOptions
47
+ */
48
+ attributes?: Record<string, unknown>;
49
+
50
+ /**
51
+ * @en
52
+ * Styles for Element
53
+ * @zh
54
+ * 元素的样式
55
+ *
56
+ * @type {CSSStyleDeclaration}
57
+ * @memberof IDomMakerOptions
58
+ */
59
+ style?: CSSStyleDeclaration;
60
+
61
+ /**
62
+ * @en
63
+ * text to add as a child node
64
+ * @zh
65
+ * 添加为子节点的文本
66
+ *
67
+ * @type {string}
68
+ * @memberof IDomMakerOptions
69
+ */
70
+ text?: string;
71
+
72
+ /**
73
+ * @en
74
+ * array of further child nodes
75
+ * @zh
76
+ * 其他子节点的数组
77
+ *
78
+ * @type {TWElement[]}
79
+ * @memberof IDomMakerOptions
80
+ */
81
+ children?: TWElement[];
82
+
83
+ /**
84
+ * @en
85
+ * optional HTML for element
86
+ * @zh
87
+ * 元素的 HTML 内容
88
+ *
89
+ * @type {string}
90
+ * @memberof IDomMakerOptions
91
+ */
92
+ innerHTML?: string;
93
+
94
+ /**
95
+ * @en
96
+ * class name(s)
97
+ * @zh
98
+ * 元素的 class,多个则以空格分隔
99
+ *
100
+ * @type {string}
101
+ * @memberof IDomMakerOptions
102
+ */
103
+ class?: string;
104
+
105
+ /**
106
+ * @en
107
+ * defaults to current document
108
+ * @zh
109
+ * 默认为当前 document
110
+ *
111
+ * @type {TWDocument}
112
+ * @memberof IDomMakerOptions
113
+ */
114
+ document?: TWDocument;
115
+
116
+ /**
117
+ * @en
118
+ * array of event listeners (this option won't work until `$tw.utils.addEventListeners()` has been loaded)
119
+ * @zh
120
+ * 事件监听器的数组(这个选项在`$tw.utils.addEventListeners()`被加载之前不会起作用)。
121
+ *
122
+ * @type {EventListener[]}
123
+ * @memberof IDomMakerOptions
124
+ */
125
+ eventListeners?: EventListener[];
126
+ }
127
+
128
+ export interface IUtils {
14
129
  Crypto: typeof Crypto;
15
130
  PasswordPrompt: typeof PasswordPrompt;
131
+
16
132
  /**
17
- * Alternative to `element.classList.add`, add a css class name to an element, see issue for detail.
18
- * @link https://github.com/Jermolene/TiddlyWiki5/issues/6475
19
- * @param element
20
- * @param className
21
- */
22
- addClass: (element: Element, className: string) => void;
23
- /**
24
- Attach specified event handlers to a DOM node
25
- @param domNode: where to attach the event handlers
26
- @param events: array of event handlers to be added (see below)
27
- Each entry in the events array is an object with these properties:
28
- - name: event name of `addEventListener`
29
- - handlerFunction: optional event handler function
30
- - handlerObject: optional event handler object
31
- - handlerMethod: optionally specifies object handler method name (defaults to `handleEvent`)
32
- */
33
- addEventListeners: (
34
- domNode: Node,
35
- events: {
36
- handlerFunction?: (event: MouseEvent) => void;
37
- handlerMethod?: string;
38
- handlerObject?: Widget;
39
- name: string;
40
- }[],
41
- ) => void;
42
- /** Returns true if the version string A is greater than the version string B. Returns true if the versions are the same */
43
- checkVersions: (versionStringA: string, versionStringB: string) => boolean;
133
+ * @en
134
+ * Check if an object has a property.
135
+ * @zh
136
+ * 检查一个对象是否有一个属性。
137
+ */
138
+ hop: (object: Object, property: string | symbol) => boolean;
139
+
44
140
  /**
45
- * 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.
46
- * Missing or malformed version strings are parsed as 0.0.0
141
+ * @en
142
+ * Determine if a value is an array.
143
+ * @zh
144
+ * 判断对象是否是一个数组。
47
145
  */
48
- compareVersions: (
49
- versionStringA: string,
50
- versionStringB: string,
51
- ) => -1 | 0 | 1;
52
- /*
53
- Return the number of keys in an object
54
- */
55
- count: (object: Record<string, any>) => number;
56
- /** Convert a URIComponent encoded string to a string safely */
57
- decodeURIComponentSafe: (uri: string) => string;
58
- /** Convert a URI encoded string to a string safely */
59
- decodeURISafe: (uri: string) => string;
60
- /** 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 */
61
- deepDefaults: (
62
- origin: Record<string | symbol, unknown>,
63
- ...defaults: Record<string | symbol, unknown>[]
64
- ) => Record<string | symbol, unknown>;
146
+ isArray: (value: unknown) => boolean;
147
+
65
148
  /**
66
- * Helper for making DOM elements
67
- * @param {string} tag tag name
68
- * @param {{
69
- * namespace?: string;
70
- * attributes?: Record<string, unknown>;
71
- * style?: Record<string, string>;
72
- * text?: string;
73
- * children?: Element[];
74
- * innerHTML?: string;
75
- * class?: string;
76
- * document?: Document;
77
- * eventListeners?: EventListener[];
78
- * }} options Options include:
79
- * * namespace: defaults to http://www.w3.org/1999/xhtml
80
- * * attributes: hashmap of attribute values
81
- * * style: hashmap of styles
82
- * * text: text to add as a child node
83
- * * children: array of further child nodes
84
- * * innerHTML: optional HTML for element
85
- * * class: class name(s)
86
- * * document: defaults to current document
87
- * * eventListeners: array of event listeners (this option won't work until `$tw.utils.addEventListeners()` has been loaded)
88
- * @returns {Element}
89
- */
90
- domMaker: (
91
- tag: string,
92
- options: {
93
- attributes?: Record<string, unknown>;
94
- children?: TWDOMElement[];
95
- class?: string;
96
- document?: TWDocument;
97
- eventListeners?: EventListener[];
98
- innerHTML?: string;
99
- namespace?: string;
100
- style?: Record<string, string>;
101
- text?: string;
102
- },
103
- ) => TWDOMElement;
149
+ * @en
150
+ * Check if an array is equal by value and by reference.
151
+ * @zh
152
+ * 检查一个数组的值和引用是否相等。
153
+ */
154
+ isArrayEqual: (array1: unknown[], array2: unknown[]) => boolean;
155
+
156
+ /**
157
+ * @en
158
+ * Add an entry to a sorted array if it doesn't already exist, while maintaining the sort order
159
+ * @zh
160
+ * 如果一个已排序的数组中不存在一个条目,则添加该条目,同时保持排序顺序
161
+ */
162
+ insertSortedArray: <T extends Array<unknown>>(
163
+ array: T,
164
+ value: unknown,
165
+ ) => T;
166
+
104
167
  /**
168
+ * @en
169
+ * Push entries onto an array, removing them first if they already exist in the array
170
+ * @zh
171
+ * 将条目推送到一个数组中,如果它们已经存在于数组中,则先将其删除。
172
+ *
173
+ * @param {unknown[]} array array to modify (assumed to be free of duplicates)
174
+ * @param {unknown} value a single value to push or an array of values to push
175
+ * @returns {unknown[]}
176
+ */
177
+ pushTop: <T extends Array<unknown>>(array: T, value: unknown) => T;
178
+
179
+ /**
180
+ * @en
181
+ * Determine if a value is a date
182
+ * @zh
183
+ * 确定一个值是否是一个日期
184
+ */
185
+ isDate: (value: unknown) => void;
186
+
187
+ /**
188
+ * @en
105
189
  * Iterate through all the own properties of an object or array.
106
190
  * Callback is invoked with (element, index, object), if callback returns false, then the each loop will be terminated.
191
+ * @zh
192
+ * 遍历一个对象或数组的所有自身属性。
193
+ * callback 被遍历调用 (element, index, object),如果回调返回 false,那么每个循环将被终止。
194
+ * @param {T} object
195
+ * @param {(element: T[keyof T], index: keyof T, object: T) => void | false} callback
196
+ * @example
197
+ * $tw.utils.each([1, 2, 3], element => console.log(element));
198
+ * $tw.utils.each({ a: 1, b: 2 }, (value, key) => console.log(key, value));
107
199
  */
108
- each: <I = any>(
109
- object: Record<string, I> | I[],
110
- callback: TWEachCallback<Record<string, I> | I[], I>,
200
+ each: <T, K = T extends Array<any> ? number : keyof T>(
201
+ object: T,
202
+ callback: (element: T[K], index: K, object: T) => void | false,
111
203
  ) => void;
112
- /** Display an error and exit */
113
- error: (error: Event | string) => void;
114
- /** Run code globally with specified context variables in scope */
115
- evalGlobal: (
116
- code: string,
117
- context: IModuleSandbox,
118
- filename: string,
119
- ) => unknown;
120
- /** Run code in a sandbox with only the specified context variables in scope */
121
- evalSandboxed: (
122
- code: string,
123
- context: IModuleSandbox,
124
- filename: string,
125
- ) => unknown;
126
- /** Extend an object with the properties from a list of source objects */
127
- extend: (
128
- origin: Record<string | symbol, unknown>,
129
- ...sources: Record<string | symbol, unknown>[]
130
- ) => Record<string | symbol, unknown>;
131
- /** the function behind `<<now "format">> */
132
- formatDateString: (date: Date, format: string) => string;
133
- /** Given an extension, always access the $tw.config.fileExtensionInfo using a lowercase extension only. */
134
- getFileExtensionInfo: (extension: string) => IFileExtensionInfo | null;
135
- /** 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) */
136
- getLocationHash: () => string;
137
- /** Given an extension, get the correct encoding for that file. defaults to utf8 */
138
- getTypeEncoding: (extension: string) => string;
139
- /** Check if an object has a property. */
140
- hop: (object: object, property: string) => boolean;
141
- /** Convert "&amp;" to &, "&nbsp;" to nbsp, "&lt;" to <, "&gt;" to > and "&quot;" to " */
204
+
205
+ /**
206
+ * @en
207
+ * Helper for making DOM elements
208
+ * @zh
209
+ * 产生一个 DOM 元素
210
+ *
211
+ * @param {string} tag tag name
212
+ * @param {IDomMakerOptions} [options]
213
+ * @returns {TWElement}
214
+ */
215
+ domMaker: (tag: string, options?: IDomMakerOptions) => TWElement;
216
+
217
+ /**
218
+ * @en
219
+ * Display an error and exit
220
+ * @zh
221
+ * 打印一个错误,如果在 Node 环境下,会退出进程
222
+ */
223
+ error: (error: Event | Error | string) => null | never;
224
+
225
+ /**
226
+ * @en
227
+ * Extend an object with the properties from a list of source objects
228
+ * @zh
229
+ * 用源对象列表中的属性扩展一个对象
230
+ */
231
+ extend: <O extends object, S extends object[]>(
232
+ origin: O,
233
+ ...sources: [...S]
234
+ ) => Spread<[O, ...S]>;
235
+
236
+ /**
237
+ * @en
238
+ * 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
239
+ * @zh
240
+ * 用源对象列表中的属性来填充对象的任何空或未定义的属性。每个属于对象的属性都被递归地调用
241
+ */
242
+ deepDefaults: <O extends object, S extends object[]>(
243
+ origin: O,
244
+ ...sources: [...S]
245
+ ) => Spread<[O, ...S]>;
246
+
247
+ /**
248
+ * @en
249
+ * Convert a URIComponent encoded string to a string safely
250
+ * @zh
251
+ * 将一个URIComponent编码的字符串安全地转换为一个字符串。
252
+ */
253
+ decodeURIComponentSafe: (uri: string) => string;
254
+
255
+ /**
256
+ * @en
257
+ * Convert a URI encoded string to a string safely
258
+ * @zh
259
+ * 将一个URI编码的字符串安全地转换为一个字符串
260
+ */
261
+ decodeURISafe: (uri: string) => string;
262
+
263
+ /**
264
+ * @en
265
+ * Convert `&amp;` to `&`, `&nbsp;` to ` `, `&lt;` to `<`, `&gt;` to `>` and `&quot;` to `"`
266
+ * @zh
267
+ * 将`&amp;`转换成`&`,`&nbsp;`转换成` `,`&lt;`转换成`<`,`&gt;`转换成`>`,`&quot;`转换成`"`
268
+ */
142
269
  htmlDecode: (text: string) => string;
143
- /** Determine if a value is an array. */
144
- isArray: (value: unknown) => boolean;
145
- /** Check if an array is equal by value and by reference. */
146
- isArrayEqual: (array1: unknown[], array2: unknown[]) => boolean;
147
- /** Determine if a value is a date */
148
- isDate: (value: unknown) => void;
149
- /** Pad a string to a given length with "0"s. Length defaults to 2 */
270
+
271
+ /**
272
+ * @en
273
+ * 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)
274
+ * @zh
275
+ * 获取浏览器的location.hash。我们不使用location.hash,因为Firefox的自动解码方式(见http://stackoverflow.com/questions/1703552/encoding-of-window-location-hash)。
276
+ */
277
+ getLocationHash: () => string;
278
+
279
+ /**
280
+ * @en
281
+ * Pad a string to a given length with "0"s. Length defaults to 2
282
+ * @zh
283
+ * 用 "0 "将一个字符串填充到指定的长度。长度默认为2
284
+ */
150
285
  pad: (value: number, length?: number) => string;
151
- /** Parse a date from a UTC YYYYMMDDHHMMSSmmm format string */
152
- parseDate: (value: string | Date) => Date;
153
- /** Parse a block of name:value fields. The `fields` object is used as the basis for the return value */
154
- parseFields: (text: string, fields?: object) => object;
155
- parseJSONSafe: (input: string) => any;
156
- /** Parse a string array from a bracketted list. For example "OneTiddler [[Another Tiddler]] LastOne" */
286
+
287
+ /**
288
+ * @en
289
+ * Convert a date into UTC `YYYYMMDDHHMMSSmmm` format
290
+ * @zh
291
+ * 将日期转换成UTC `YYYYMMDDHMMSSmmm` 格式
292
+ */
293
+ stringifyDate: (value: Date) => string;
294
+
295
+ /**
296
+ * @en
297
+ * Parse a date from a UTC `YYYYMMDDHHMMSSmmm` format string
298
+ * @zh
299
+ * 从UTC `YYYYMMDDHHMMSSmmm` 格式字符串中解析一个日期
300
+ */
301
+ parseDate: (value: string | Date) => Date | null;
302
+
303
+ /**
304
+ * @en
305
+ * Stringify an array of tiddler titles into a list string
306
+ * @zh
307
+ * 将一个数组的tiddler标题字符串化为一个列表字符串
308
+ */
309
+ stringifyList: (value: string[]) => string;
310
+
311
+ /**
312
+ * @en
313
+ * Parse a string array from a bracketted list. For example `OneTiddler [[Another Tiddler]] LastOne`
314
+ * @zh
315
+ * 从一个带括号的列表中解析一个字符串数组。例如,`OneTiddler [[Another Tiddler]] LastOne`
316
+ */
157
317
  parseStringArray: (
158
318
  value: string | string[],
159
319
  allowDuplicate?: boolean,
160
- ) => string[];
161
- /** Parse a semantic version string into its constituent parts -- see https://semver.org */
320
+ ) => string[] | null;
321
+
322
+ /**
323
+ * @en
324
+ * Parse a block of name:value fields. The `fields` object is used as the basis for the return value
325
+ * @zh
326
+ * 解析一个name:value字段的块。`fields`对象被用作返回值的基础。
327
+ */
328
+ parseFields: (text: string, fields?: object) => Record<string, string>;
329
+
330
+ /**
331
+ * @en
332
+ * Safely parse a string as JSON
333
+ * @zh
334
+ * 安全地解析一个字符串为 JSON 对象
335
+ */
336
+ parseJSONSafe: (
337
+ input: string,
338
+ defaultJSON?: (error: Error) => unknown,
339
+ ) => unknown;
340
+
341
+ /**
342
+ * @en
343
+ * Resolves a source filepath delimited with `/` relative to a specified absolute root filepath.
344
+ * In relative paths, the special folder name `..` refers to immediate parent directory, and the
345
+ * name `.` refers to the current directory
346
+ * @zh
347
+ * 将以`/`为界的源文件路径相对于指定的绝对根文件路径进行解析。
348
+ * 在相对路径中,特殊的文件夹名称`...`指的是直接的父目录,而名称`.`指的是当前目录。
349
+ */
350
+ resolvePath: (sourcepath: string, rootpath: string) => string;
351
+
352
+ /**
353
+ * @en
354
+ * Parse a semantic version string into its constituent parts -- see https://semver.org
355
+ * @zh
356
+ * 将一个语义版本字符串解析为其构成部分 -- 见 https://semver.org
357
+ */
162
358
  parseVersion: (version: string) => {
163
359
  build?: string;
164
360
  major: number;
@@ -167,14 +363,34 @@ declare module 'tiddlywiki' {
167
363
  prerelease?: string;
168
364
  version: string;
169
365
  } | null;
366
+
170
367
  /**
171
- * Push entries onto an array, removing them first if they already exist in the array
172
- * * array: array to modify (assumed to be free of duplicates)
173
- * * value: a single value to push or an array of values to push
368
+ * @en
369
+ * 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.
370
+ * Missing or malformed version strings are parsed as 0.0.0
371
+ * @zh
372
+ * 如果版本字符串A大于版本字符串B,则返回+1;如果它们相同,则返回0;如果B大于A,则返回+1;
373
+ * 缺失或畸形的版本字符串被解析为0.0.0
174
374
  */
175
- pushTop: (array: unknown[], value: unknown) => void;
375
+ compareVersions: (
376
+ versionStringA: string,
377
+ versionStringB: string,
378
+ ) => -1 | 0 | 1;
379
+
380
+ /**
381
+ * @en
382
+ * Returns true if the version string A is greater than the version string B. Returns true if the versions are the same
383
+ * @zh
384
+ * 如果版本字符串A大于版本字符串B,返回true;如果版本相同,返回true。
385
+ */
386
+ checkVersions: (versionStringA: string, versionStringB: string) => boolean;
387
+
176
388
  /**
389
+ * @en
177
390
  * Register file type information
391
+ * @zh
392
+ * 注册文件类型信息
393
+ *
178
394
  * @param {string} contentType
179
395
  * @param {string} encoding
180
396
  * @param {(string | string[])} extension
@@ -194,41 +410,45 @@ declare module 'tiddlywiki' {
194
410
  flags?: string[];
195
411
  },
196
412
  ) => void;
413
+
197
414
  /**
198
- * Resolves a source filepath delimited with `/` relative to a specified absolute root filepath.
199
- * In relative paths, the special folder name `..` refers to immediate parent directory, and the
200
- * name `.` refers to the current directory
415
+ * @en
416
+ * Given an extension, always access the $tw.config.fileExtensionInfo using a lowercase extension only.
417
+ * @zh
418
+ * 给定一个扩展名,总是只使用小写的扩展名来访问$tw.config.fileExtensionInfo。
201
419
  */
202
- resolvePath: (sourcepath: string, rootpath: string) => string;
203
- /** Convert a date into UTC YYYYMMDDHHMMSSmmm format */
204
- stringifyDate: (value: Date) => string;
205
- /** Stringify an array of tiddler titles into a list string */
206
- stringifyList: (value: string[]) => string;
207
- generateTiddlerFilepath: (
208
- title: string,
209
- options?: {
210
- directory?: string;
211
- extension?: string;
212
- fileInfo?: {
213
- originalpath?: string;
214
- filePath?: string;
215
- writeError?: boolean;
216
- };
217
- pathFilters?: string[];
218
- wiki?: Wiki;
219
- },
220
- ) => string;
221
- }
222
- /**
223
- * Notifier mechanism
224
- */
225
- export class Notifier {
226
- /*
227
- Display a notification
228
- title: Title of tiddler containing the notification text
229
- options: see below
230
- Options include:
231
- */
232
- display(title: string, options?: Record<string, unknown>): void;
420
+ getFileExtensionInfo: (extension: string) => IFileExtensionInfo | null;
421
+
422
+ /**
423
+ * @en
424
+ * Given an extension, get the correct encoding for that file. defaults to utf8
425
+ * @zh
426
+ * 给定一个扩展名,获得该文件的正确编码。 默认为utf8
427
+ */
428
+ getTypeEncoding: (extension: string) => string;
429
+
430
+ /**
431
+ * @en
432
+ * Run code globally with specified context variables in scope
433
+ * @zh
434
+ * 在全局范围内运行代码,范围内有指定的上下文变量
435
+ */
436
+ evalGlobal: (
437
+ code: string,
438
+ context: IEvalContent,
439
+ filename: string,
440
+ ) => unknown;
441
+
442
+ /**
443
+ * @en
444
+ * Run code in a sandbox with only the specified context variables in scope
445
+ * @zh
446
+ * 在沙盒中运行代码,范围内只有指定的上下文变量
447
+ */
448
+ evalSandboxed: (
449
+ code: string,
450
+ context: IEvalContent,
451
+ filename: string,
452
+ ) => unknown;
233
453
  }
234
454
  }
@@ -257,5 +257,6 @@ declare module 'tiddlywiki' {
257
257
  getShadowSource(title: string): string | null;
258
258
  getTiddlerBacklinks(targetTitle: string): string[];
259
259
  getTiddlerLinks(title: string): string[];
260
+ getPluginInfo(title: string): { tiddlers: Record<string, ITiddlerFields> };
260
261
  }
261
262
  }