tw5-typed 0.3.11 → 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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "description": "Types for tiddlywiki",
3
3
  "license": "MIT",
4
4
  "name": "tw5-typed",
5
- "version": "0.3.11",
5
+ "version": "0.4.0",
6
6
  "url": "https://github.com/tiddly-gittly/tw5-typed",
7
7
  "homepage": "https://github.com/tiddly-gittly/tw5-typed",
8
8
  "bugs": {
package/src/core.d.ts CHANGED
@@ -62,10 +62,20 @@ declare module 'tiddlywiki' {
62
62
 
63
63
  addUnloadTask(task: any);
64
64
 
65
- /** Convenience function for pushing a tiddler onto the preloading array */
66
- preloadTiddler(fields: Record<string, unknown>);
67
- /** Convenience function for pushing an array of tiddlers onto the preloading array */
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
@@ -10,5 +10,5 @@ declare module 'tiddlywiki' {
10
10
  }
11
11
 
12
12
  declare global {
13
- export let $tw: ITiddlyWiki;
13
+ export const $tw: ITiddlyWiki;
14
14
  }
@@ -7,6 +7,14 @@ declare module '$:/core/modules/utils/dom.js' {
7
7
  */
8
8
  export function addClass(element: Element, className: string): void;
9
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
+
10
18
  /**
11
19
  * Attach specified event handlers to a DOM node
12
20
  * @param domNode: where to attach the event handlers
@@ -27,6 +35,189 @@ declare module '$:/core/modules/utils/dom.js' {
27
35
  }[],
28
36
  ): void;
29
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
+
30
221
  /**
31
222
  * Notifier mechanism
32
223
  */
File without changes