tw5-typed 0.3.10 → 0.4.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 +1 -1
- package/src/core.d.ts +13 -3
- package/src/index.d.ts +1 -1
- package/src/modules/utils/crypto.d.ts +32 -0
- package/src/modules/utils/csv.d.ts +38 -0
- package/src/modules/utils/dom.d.ts +223 -47
- package/src/modules/utils/edition-info.d.ts +11 -0
- package/src/modules/utils/escapecss.d.ts +8 -0
- package/src/modules/utils/fakedom.d.ts +2 -1
- package/src/modules/utils/filesystem.d.ts +116 -48
- package/src/modules/utils/index.d.ts +31 -1
- package/src/modules/utils/linked-list.d.ts +91 -0
- package/src/modules/utils/logger.d.ts +74 -13
- package/src/modules/utils/parsetree.d.ts +81 -0
- package/src/modules/utils/performance.d.ts +51 -0
- package/src/modules/utils/pluginmaker.d.ts +15 -0
- package/src/modules/utils/transliterate.d.ts +23 -0
- package/src/modules/utils/utils.d.ts +599 -22
- package/src/modules/widgets/index.d.ts +1 -0
- package/src/modules/wiki.d.ts +11 -3
- package/src/utils/index.d.ts +6 -4
- package/src/wiki/index.d.ts +24 -15
package/package.json
CHANGED
package/src/core.d.ts
CHANGED
|
@@ -62,10 +62,20 @@ declare module 'tiddlywiki' {
|
|
|
62
62
|
|
|
63
63
|
addUnloadTask(task: any);
|
|
64
64
|
|
|
65
|
-
/**
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
/**
|
|
66
|
+
* Convenience function for pushing a tiddler onto the preloading array.
|
|
67
|
+
* @param fields - The fields of the tiddler to push.
|
|
68
|
+
* @description 方便地将一个 tiddler 推入预加载数组中。
|
|
69
|
+
*/
|
|
70
|
+
preloadTiddler(fields: Record<string, unknown>): void;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Convenience function for pushing an array of tiddlers onto the preloading array.
|
|
74
|
+
* @param fieldsArray - The array of tiddlers to push.
|
|
75
|
+
* @description 方便地将若干 tiddler 数组推入预加载数组中。
|
|
76
|
+
*/
|
|
68
77
|
preloadTiddlerArray(fieldsArray: Array<Record<string, unknown>>): void;
|
|
78
|
+
|
|
69
79
|
/** External JavaScript can populate this array before calling boot.js in order to preload tiddlers */
|
|
70
80
|
preloadTiddlers: Record<string, Record<string, unknown>>;
|
|
71
81
|
|
package/src/index.d.ts
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare module '$:/core/modules/utils/crypto.js' {
|
|
2
|
+
/**
|
|
3
|
+
* Extracts an encrypted store area from a TiddlyWiki file.
|
|
4
|
+
* @param text - The text of the TiddlyWiki file.
|
|
5
|
+
* @returns The extracted encrypted store area, or null if not found.
|
|
6
|
+
*/
|
|
7
|
+
export function extractEncryptedStoreArea(text: string): string | null;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Attempts to decrypt an encrypted store area using the provided password.
|
|
11
|
+
* @param encryptedStoreArea - The encrypted store area to decrypt.
|
|
12
|
+
* @param password - The password to use for decryption.
|
|
13
|
+
* @returns An array of decrypted tiddlers, or null if decryption fails.
|
|
14
|
+
*/
|
|
15
|
+
export function decryptStoreArea(
|
|
16
|
+
encryptedStoreArea: string,
|
|
17
|
+
password?: string,
|
|
18
|
+
): any[] | null;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Prompts the user for a password and attempts to decrypt an encrypted store area using the provided password.
|
|
22
|
+
* @param encryptedStoreArea - The encrypted store area to decrypt.
|
|
23
|
+
* @param callback - The function to call with the decrypted tiddlers.
|
|
24
|
+
* @param options - Configuration options.
|
|
25
|
+
* @param options.usePasswordVault - Whether to store the password in the system password vault.
|
|
26
|
+
*/
|
|
27
|
+
export function decryptStoreAreaInteractive(
|
|
28
|
+
encryptedStoreArea: string,
|
|
29
|
+
callback: (tiddlers: any[]) => void,
|
|
30
|
+
options?: { usePasswordVault?: boolean },
|
|
31
|
+
): void;
|
|
32
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
declare module '$:/core/modules/utils/csv.js' {
|
|
2
|
+
/**
|
|
3
|
+
* Information about a CSV cell.
|
|
4
|
+
* @property {number} start - The start index of the cell in the CSV string.
|
|
5
|
+
* @property {number} end - The end index of the cell in the CSV string.
|
|
6
|
+
* @property {boolean} isQuoted - Whether the cell is quoted.
|
|
7
|
+
* @description CSV 单元格的信息。
|
|
8
|
+
*/
|
|
9
|
+
interface CellInfo {
|
|
10
|
+
start: number;
|
|
11
|
+
end: number;
|
|
12
|
+
isQuoted: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Parse a CSV string into an array of arrays.
|
|
17
|
+
* @param text - The CSV string to parse.
|
|
18
|
+
* @param options - The options for parsing the CSV string.
|
|
19
|
+
* @returns An array of arrays representing the CSV data.
|
|
20
|
+
* @description 将 CSV 字符串解析为数组的数组。
|
|
21
|
+
*/
|
|
22
|
+
export function parseCsvString(
|
|
23
|
+
text: string,
|
|
24
|
+
options?: { separator?: string },
|
|
25
|
+
): any[][];
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Parse a CSV string with a header row and return an array of objects.
|
|
29
|
+
* @param text - The CSV string to parse.
|
|
30
|
+
* @param options - The options for parsing the CSV string.
|
|
31
|
+
* @returns An array of objects representing the CSV data.
|
|
32
|
+
* @description 解析具有标题行的 CSV 字符串并返回对象数组。
|
|
33
|
+
*/
|
|
34
|
+
export function parseCsvStringWithHeader(
|
|
35
|
+
text: string,
|
|
36
|
+
options?: { separator?: string },
|
|
37
|
+
): object[];
|
|
38
|
+
}
|
|
@@ -1,35 +1,226 @@
|
|
|
1
|
-
declare module '
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
1
|
+
declare module '$:/core/modules/utils/dom.js' {
|
|
2
|
+
/**
|
|
3
|
+
* Alternative to `element.classList.add`, add a css class name to an element, see issue for detail.
|
|
4
|
+
* @link https://github.com/Jermolene/TiddlyWiki5/issues/6475
|
|
5
|
+
* @param element
|
|
6
|
+
* @param className
|
|
7
|
+
*/
|
|
8
|
+
export function addClass(element: Element, className: string): void;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Alternative to `element.classList.remove`, remove a css class name from an element, see issue for detail.
|
|
12
|
+
* @link https://github.com/Jermolene/TiddlyWiki5/issues/6475
|
|
13
|
+
* @param element
|
|
14
|
+
* @param className
|
|
15
|
+
*/
|
|
16
|
+
export function removeClass(element: Element, className: string): void;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Attach specified event handlers to a DOM node
|
|
20
|
+
* @param domNode: where to attach the event handlers
|
|
21
|
+
* @param events: array of event handlers to be added (see below)
|
|
22
|
+
* Each entry in the events array is an object with these properties:
|
|
23
|
+
* * name: event name of `addEventListener`
|
|
24
|
+
* * handlerFunction: optional event handler function
|
|
25
|
+
* * handlerObject: optional event handler object
|
|
26
|
+
* * handlerMethod: optionally specifies object handler method name (defaults to `handleEvent`)
|
|
27
|
+
*/
|
|
28
|
+
export function addEventListeners(
|
|
29
|
+
domNode: Element,
|
|
30
|
+
events: {
|
|
31
|
+
handlerFunction?: (event: MouseEvent) => void;
|
|
32
|
+
handlerMethod?: string;
|
|
33
|
+
handlerObject?: Widget;
|
|
34
|
+
name: string;
|
|
35
|
+
}[],
|
|
36
|
+
): void;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Determines whether element 'a' contains element 'b'.
|
|
40
|
+
* @param a The parent element.
|
|
41
|
+
* @param b The child element.
|
|
42
|
+
* @returns True if 'a' contains 'b', otherwise false.
|
|
43
|
+
*/
|
|
44
|
+
export function domContains(a: Element, b: Element): boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Checks if a node matches a specific CSS selector.
|
|
48
|
+
* @param node The DOM node to check.
|
|
49
|
+
* @param selector The CSS selector to match against.
|
|
50
|
+
* @returns True if the node matches the selector, otherwise false.
|
|
51
|
+
*/
|
|
52
|
+
export function domMatchesSelector(node: Element, selector: string): boolean;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Safely sets the selection range in an input or textarea element.
|
|
56
|
+
* @param node The DOM node (input or textarea).
|
|
57
|
+
* @param start The start position of the selection.
|
|
58
|
+
* @param end The end position of the selection.
|
|
59
|
+
* @param direction The direction of the selection.
|
|
60
|
+
*/
|
|
61
|
+
export function setSelectionRangeSafe(
|
|
62
|
+
node: HTMLInputElement | HTMLTextAreaElement,
|
|
63
|
+
start: number,
|
|
64
|
+
end: number,
|
|
65
|
+
direction?: 'forward' | 'backward' | 'none',
|
|
66
|
+
): void;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Selects text in an input or textarea by position.
|
|
70
|
+
* @param node The DOM node (input or textarea).
|
|
71
|
+
* @param selectFromStart Position from the start of the text.
|
|
72
|
+
* @param selectFromEnd Position from the end of the text.
|
|
73
|
+
*/
|
|
74
|
+
export function setSelectionByPosition(
|
|
75
|
+
node: HTMLInputElement | HTMLTextAreaElement,
|
|
76
|
+
selectFromStart: number,
|
|
77
|
+
selectFromEnd: number,
|
|
78
|
+
): void;
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Removes all child nodes of a given DOM node.
|
|
82
|
+
* @param node The parent DOM node.
|
|
83
|
+
*/
|
|
84
|
+
export function removeChildren(node: Node): void;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Checks if an element has a specific class.
|
|
88
|
+
* @param el The element to check.
|
|
89
|
+
* @param className The class name to look for.
|
|
90
|
+
* @returns True if the element has the class, otherwise false.
|
|
91
|
+
*/
|
|
92
|
+
export function hasClass(el: Element, className: string): boolean;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Toggles a class on an element based on a given condition.
|
|
96
|
+
* @param el The element to toggle the class on.
|
|
97
|
+
* @param className The class name to toggle.
|
|
98
|
+
* @param status If true, adds the class; if false, removes it. If undefined, toggles based on current state.
|
|
99
|
+
*/
|
|
100
|
+
export function toggleClass(
|
|
101
|
+
el: Element,
|
|
102
|
+
className: string,
|
|
103
|
+
status?: boolean,
|
|
104
|
+
): void;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Gets the first parent element that has scrollbars or uses the body as a fallback.
|
|
108
|
+
* @param el The starting element to search from.
|
|
109
|
+
* @returns The first scrollable parent element, or the body if none are found.
|
|
110
|
+
*/
|
|
111
|
+
export function getScrollContainer(el: Element): Element;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Get the scroll position of the viewport.
|
|
115
|
+
* @param srcWindow The source window to get the scroll position from, defaults to the current window if not specified.
|
|
116
|
+
* @returns An object with 'x' and 'y' properties representing the horizontal and vertical scroll positions in pixels.
|
|
117
|
+
*/
|
|
118
|
+
export function getScrollPosition(srcWindow?: Window): { x: number; y: number; };
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Adjusts the height of a textarea to fit its content, preserving scroll position, and returns the new height.
|
|
122
|
+
* @param domNode The DOM node (textarea) to resize.
|
|
123
|
+
* @param minHeight The minimum height to use for the textarea.
|
|
124
|
+
* @returns The new height of the textarea.
|
|
125
|
+
*/
|
|
126
|
+
export function resizeTextAreaToFit(domNode: HTMLTextAreaElement, minHeight: string): number;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Gets the bounding rectangle of an element in absolute page coordinates.
|
|
130
|
+
* @param element The element to get the bounding rectangle for.
|
|
131
|
+
* @returns An object representing the bounding rectangle with properties: left, width, right, top, height, bottom.
|
|
132
|
+
*/
|
|
133
|
+
export function getBoundingPageRect(element: Element): { left: number; width: number; right: number; top: number; height: number; bottom: number; };
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Saves a named password in the browser.
|
|
137
|
+
* @param name The name for the password.
|
|
138
|
+
* @param password The password to save.
|
|
139
|
+
*/
|
|
140
|
+
export function savePassword(name: string, password: string): void;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Retrieves a named password from the browser.
|
|
144
|
+
* @param name The name of the password to retrieve.
|
|
145
|
+
* @returns The password, or an empty string if not found.
|
|
146
|
+
*/
|
|
147
|
+
export function getPassword(name: string): string;
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Forces layout of a DOM node and its descendants.
|
|
151
|
+
* @param element The DOM element to force layout on.
|
|
152
|
+
*/
|
|
153
|
+
export function forceLayout(element: Element): void;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Pulses an element for debugging purposes.
|
|
157
|
+
* @param element The element to pulse.
|
|
158
|
+
*/
|
|
159
|
+
export function pulseElement(element: Element): void;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Get the computed styles applied to an element as an array of strings of individual CSS properties.
|
|
163
|
+
* @param domNode The DOM node to get the computed styles for.
|
|
164
|
+
* @returns An array of strings, each representing an individual CSS property and its value.
|
|
165
|
+
*/
|
|
166
|
+
export function getComputedStyles(domNode: Element): string[];
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Applies a set of styles to a DOM node, passed as an array of strings of individual CSS properties.
|
|
170
|
+
* @param domNode The DOM node to apply the styles to.
|
|
171
|
+
* @param styleDefs An array of strings, each representing an individual CSS property and its value.
|
|
172
|
+
*/
|
|
173
|
+
export function setStyles(domNode: Element, styleDefs: string[]): void;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Copies the computed styles from a source element to a destination element.
|
|
177
|
+
* @param srcDomNode The source DOM node.
|
|
178
|
+
* @param dstDomNode The destination DOM node.
|
|
179
|
+
*/
|
|
180
|
+
export function copyStyles(srcDomNode: Element, dstDomNode: Element): void;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Copies plain text to the clipboard on browsers that support it.
|
|
184
|
+
* @param text The text to copy.
|
|
185
|
+
* @param options Options for copying, including 'doNotNotify' to suppress notifications.
|
|
186
|
+
* @returns True if the operation succeeded, otherwise false.
|
|
187
|
+
*/
|
|
188
|
+
export function copyToClipboard(text: string, options?: { doNotNotify?: boolean }): boolean;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Gets the path part of the current location.
|
|
192
|
+
* @returns The path part of the current location URL.
|
|
193
|
+
*/
|
|
194
|
+
export function getLocationPath(): string;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Collects DOM variables from an event.
|
|
198
|
+
* @param selectedNode The node selected.
|
|
199
|
+
* @param domNode The DOM node catching the event.
|
|
200
|
+
* @param event The event object.
|
|
201
|
+
* @returns An object containing variables derived from the DOM and event.
|
|
202
|
+
*/
|
|
203
|
+
export function collectDOMVariables(selectedNode: Element, domNode: Element, event: Event): Record<string, string>;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Safely executes a querySelector, avoiding exceptions on invalid selectors.
|
|
207
|
+
* @param selector The CSS selector to query.
|
|
208
|
+
* @param baseElement The base element to start the query from, defaults to document.
|
|
209
|
+
* @returns The first element matching the selector, or null if none are found or the selector is invalid.
|
|
210
|
+
*/
|
|
211
|
+
export function querySelectorSafe(selector: string, baseElement?: Element): Element | null;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Safely executes a querySelectorAll, avoiding exceptions on invalid selectors.
|
|
215
|
+
* @param selector The CSS selector to query.
|
|
216
|
+
* @param baseElement The base element to start the query from, defaults to document.
|
|
217
|
+
* @returns A NodeList of elements matching the selector, or an empty NodeList if none are found or the selector is invalid.
|
|
218
|
+
*/
|
|
219
|
+
export function querySelectorAllSafe(selector: string, baseElement?: Element): NodeList;
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Notifier mechanism
|
|
223
|
+
*/
|
|
33
224
|
export class Notifier {
|
|
34
225
|
/**
|
|
35
226
|
* Display a notification
|
|
@@ -40,18 +231,3 @@ declare module 'tiddlywiki' {
|
|
|
40
231
|
display(title: string, options?: Record<string, unknown>): void;
|
|
41
232
|
}
|
|
42
233
|
}
|
|
43
|
-
|
|
44
|
-
declare module '$:/core/modules/utils/dom.js' {
|
|
45
|
-
import { Widget, Notifier } from 'tiddlywiki';
|
|
46
|
-
export const addClass: (element: Element, className: string) => void;
|
|
47
|
-
export const addEventListeners: (
|
|
48
|
-
domNode: Element,
|
|
49
|
-
events: {
|
|
50
|
-
handlerFunction?: (event: MouseEvent) => void;
|
|
51
|
-
handlerMethod?: string;
|
|
52
|
-
handlerObject?: Widget;
|
|
53
|
-
name: string;
|
|
54
|
-
}[],
|
|
55
|
-
) => void;
|
|
56
|
-
export { Notifier }
|
|
57
|
-
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare module '$:/core/modules/utils/edition-info.js' {
|
|
2
|
+
/**
|
|
3
|
+
* Get the edition information.
|
|
4
|
+
* @description 获取版本信息。
|
|
5
|
+
* @returns An object containing the edition information.
|
|
6
|
+
* @returns 包含版本信息的对象。
|
|
7
|
+
*/
|
|
8
|
+
export function getEditionInfo(): {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -23,5 +23,6 @@ declare module 'tiddlywiki' {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
declare module '$:/core/modules/utils/fakedom.js' {
|
|
26
|
-
|
|
26
|
+
import type { IFakeDocument } from 'tiddlywiki';
|
|
27
|
+
export const fakeDocument: IFakeDocument;
|
|
27
28
|
}
|
|
@@ -1,48 +1,126 @@
|
|
|
1
1
|
declare module '$:/core/modules/utils/utils.js' {
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Return the subdirectories of a path
|
|
4
|
+
* @param dirPath - The path to the directory
|
|
5
|
+
* @returns An array of subdirectories
|
|
6
|
+
* @description 返回路径的子目录
|
|
7
|
+
*/
|
|
8
|
+
export function getSubdirectories(dirPath: string): string[];
|
|
3
9
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Recursively (and synchronously) copy a directory and all its content
|
|
12
|
+
* @param srcPath - The source path of the directory to copy
|
|
13
|
+
* @param dstPath - The destination path of the directory to copy
|
|
14
|
+
* @returns An error message if there is an error, otherwise null
|
|
15
|
+
* @description 递归地(同步地)复制目录及其所有内容
|
|
16
|
+
*/
|
|
17
|
+
export function copyDirectory(srcPath: string, dstPath: string): string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Copy a file
|
|
21
|
+
* @param srcPath - The source path of the file to copy
|
|
22
|
+
* @param dstPath - The destination path of the file to copy
|
|
23
|
+
* @returns An error message if there is an error, otherwise null
|
|
24
|
+
* @description 复制文件
|
|
25
|
+
*/
|
|
26
|
+
export function copyFile(srcPath: string, dstPath: string): string;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Remove trailing path separator
|
|
30
|
+
* @param dirPath - The directory path to remove the trailing separator from
|
|
31
|
+
* @returns The directory path without the trailing separator
|
|
32
|
+
* @description 移除路径末尾的分隔符
|
|
33
|
+
*/
|
|
34
|
+
export function removeTrailingSeparator(dirPath: string): string;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Recursively create a directory
|
|
38
|
+
* @param dirPath - The path of the directory to create
|
|
39
|
+
* @returns An error message if there is an error, otherwise null
|
|
40
|
+
* @description 递归地创建目录
|
|
41
|
+
*/
|
|
42
|
+
export function createDirectory(dirPath: string): string;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Recursively create directories needed to contain a specified file
|
|
46
|
+
* @param filePath - The path of the file to create directories for
|
|
47
|
+
* @returns An error message if there is an error, otherwise null
|
|
48
|
+
* @description 递归地创建包含指定文件的目录
|
|
49
|
+
*/
|
|
50
|
+
export function createFileDirectories(filePath: string): string;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Recursively delete a directory
|
|
54
|
+
* @param dirPath - The path of the directory to delete
|
|
55
|
+
* @returns An error message if there is an error, otherwise null
|
|
56
|
+
* @description 递归地删除目录
|
|
57
|
+
*/
|
|
58
|
+
export function deleteDirectory(dirPath: string): string;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Check if a path identifies a directory
|
|
62
|
+
* @param dirPath - The path to check
|
|
63
|
+
* @returns True if the path identifies a directory, false otherwise
|
|
64
|
+
* @description 检查路径是否标识目录
|
|
65
|
+
*/
|
|
66
|
+
export function isDirectory(dirPath: string): boolean;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Check if a path identifies a directory that is empty
|
|
70
|
+
* @param dirPath - The path to check
|
|
71
|
+
* @returns True if the path identifies an empty directory, false otherwise
|
|
72
|
+
* @description 检查路径是否标识空目录
|
|
73
|
+
*/
|
|
74
|
+
export function isDirectoryEmpty(dirPath: string): boolean;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Recursively delete a tree of empty directories
|
|
78
|
+
* @param dirpath - The path of the directory to delete
|
|
79
|
+
* @param callback - A callback function to call when the operation is complete
|
|
80
|
+
* @description 递归地删除空目录树
|
|
81
|
+
*/
|
|
82
|
+
export function deleteEmptyDirs(
|
|
83
|
+
dirpath: string,
|
|
84
|
+
callback: (err: Error | null) => void,
|
|
85
|
+
): void;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Generate a fileInfo object for saving a tiddler
|
|
89
|
+
* @param tiddler - The tiddler to generate the fileInfo for
|
|
90
|
+
* @param options - Options for generating the fileInfo
|
|
91
|
+
* @returns A fileInfo object
|
|
92
|
+
* @description 生成用于保存 tiddler 的 fileInfo 对象
|
|
93
|
+
*/
|
|
18
94
|
export function generateTiddlerFileInfo(
|
|
19
95
|
tiddler: Tiddler,
|
|
20
96
|
options: {
|
|
21
|
-
directory
|
|
97
|
+
directory: string;
|
|
22
98
|
pathFilters?: string[];
|
|
23
99
|
extFilters?: string[];
|
|
24
100
|
wiki?: Wiki;
|
|
25
|
-
fileInfo?:
|
|
101
|
+
fileInfo?: FileInfo;
|
|
26
102
|
},
|
|
27
|
-
):
|
|
28
|
-
|
|
103
|
+
): FileInfo;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Generate the file extension for saving a tiddler
|
|
107
|
+
* @param title - The title of the tiddler
|
|
108
|
+
* @param options - Options for generating the file extension
|
|
109
|
+
* @returns The file extension
|
|
110
|
+
* @description 生成用于保存 tiddler 的文件扩展名
|
|
111
|
+
* 可选项包括:
|
|
112
|
+
* extFilters:用于生成扩展名的可选过滤器数组
|
|
113
|
+
* wiki:用于评估 extFilters 的可选 wiki
|
|
114
|
+
*/
|
|
115
|
+
export function generateTiddlerExtension(
|
|
116
|
+
title: string,
|
|
117
|
+
options: {
|
|
118
|
+
extFilters?: string[];
|
|
119
|
+
wiki?: Wiki;
|
|
120
|
+
},
|
|
121
|
+
): string;
|
|
29
122
|
|
|
30
123
|
declare module 'tiddlywiki' {
|
|
31
|
-
import { generateTiddlerFileInfo, generateTiddlerFilepath } from '$:/core/modules/utils/utils.js';
|
|
32
|
-
export interface IFileInfo {
|
|
33
|
-
isEditableFile: boolean;
|
|
34
|
-
originalpath: string;
|
|
35
|
-
type: string;
|
|
36
|
-
hasMetaFile: boolean;
|
|
37
|
-
encoding: string;
|
|
38
|
-
filepath: string;
|
|
39
|
-
}
|
|
40
|
-
export interface ITiddlersInFile {
|
|
41
|
-
filepath: string;
|
|
42
|
-
type: string;
|
|
43
|
-
tiddlers: ITiddlerFields[];
|
|
44
|
-
hasMetaFile: boolean;
|
|
45
|
-
}
|
|
46
124
|
interface IUtils {
|
|
47
125
|
/**
|
|
48
126
|
* Generate the filepath for saving a tiddler
|
|
@@ -54,19 +132,9 @@ declare module 'tiddlywiki' {
|
|
|
54
132
|
* * fileInfo: an existing fileInfo object to check against
|
|
55
133
|
*/
|
|
56
134
|
generateTiddlerFilepath: typeof generateTiddlerFilepath;
|
|
57
|
-
/**
|
|
58
|
-
Create a fileInfo object for saving a tiddler:
|
|
59
|
-
filepath: the absolute path to the file containing the tiddler
|
|
60
|
-
type: the type of the tiddler file on disk (NOT the type of the tiddler)
|
|
61
|
-
hasMetaFile: true if the file also has a companion .meta file
|
|
62
|
-
isEditableFile: true if the tiddler was loaded via non-standard options & marked editable
|
|
63
|
-
Options include:
|
|
64
|
-
directory: absolute path of root directory to which we are saving
|
|
65
|
-
pathFilters: optional array of filters to be used to generate the base path
|
|
66
|
-
extFilters: optional array of filters to be used to generate the base path
|
|
67
|
-
wiki: optional wiki for evaluating the pathFilters,
|
|
68
|
-
fileInfo: an existing fileInfo to check against
|
|
69
|
-
*/
|
|
70
|
-
generateTiddlerFileInfo: typeof generateTiddlerFileInfo;
|
|
71
135
|
}
|
|
72
136
|
}
|
|
137
|
+
|
|
138
|
+
declare module '$:/core/modules/utils/utils.js' {
|
|
139
|
+
export { generateTiddlerFilepath };
|
|
140
|
+
}
|
|
@@ -2,4 +2,34 @@
|
|
|
2
2
|
/// <reference path="utils.d.ts" />
|
|
3
3
|
/// <reference path="fakedom.d.ts" />
|
|
4
4
|
/// <reference path="filesystem.d.ts" />
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
declare module 'tiddlywiki' {
|
|
7
|
+
// Thanks for GitHub Copilot, you has helped me a lot!
|
|
8
|
+
import * as dom from '$:/core/modules/utils/dom.js';
|
|
9
|
+
import * as utils from '$:/core/modules/utils/utils.js';
|
|
10
|
+
import * as filesystem from '$:/core/modules/utils/filesystem.js';
|
|
11
|
+
import * as LinkedList from '$:/core/modules/utils/linked-list.js';
|
|
12
|
+
import * as performance from '$:/core/modules/utils/performance.js';
|
|
13
|
+
import * as logger from '$:/core/modules/utils/logger.js';
|
|
14
|
+
import * as parsetree from '$:/core/modules/utils/parsetree.js';
|
|
15
|
+
import * as pluginMaker from '$:/core/modules/utils/pluginmaker.js';
|
|
16
|
+
import * as transliterate from '$:/core/modules/utils/transliterate.js';
|
|
17
|
+
import * as crypto from '$:/core/modules/utils/crypto.js';
|
|
18
|
+
import * as csv from '$:/core/modules/utils/csv.js';
|
|
19
|
+
import * as editionInfo from '$:/core/modules/utils/edition-info.js';
|
|
20
|
+
import * as escapecss from '$:/core/modules/utils/escapecss.js';
|
|
21
|
+
|
|
22
|
+
type IUtilsModules = Pick<typeof dom, keyof typeof dom> &
|
|
23
|
+
Partial<Pick<typeof filesystem, keyof typeof filesystem>> &
|
|
24
|
+
Pick<typeof utils, keyof typeof utils> &
|
|
25
|
+
Pick<typeof LinkedList, keyof typeof LinkedList> &
|
|
26
|
+
Pick<typeof performance, keyof typeof performance> &
|
|
27
|
+
Pick<typeof logger, keyof typeof logger> &
|
|
28
|
+
Pick<typeof parsetree, keyof typeof parsetree> &
|
|
29
|
+
Pick<typeof pluginMaker, keyof typeof pluginMaker> &
|
|
30
|
+
Pick<typeof transliterate, keyof typeof transliterate> &
|
|
31
|
+
Pick<typeof crypto, keyof typeof crypto> &
|
|
32
|
+
Pick<typeof csv, keyof typeof csv> &
|
|
33
|
+
Pick<typeof editionInfo, keyof typeof editionInfo> &
|
|
34
|
+
Pick<typeof escapecss, keyof typeof escapecss>;
|
|
35
|
+
}
|