intelliwaketssveltekitv25 0.3.50 → 0.3.51
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/dist/Functions.d.ts +1 -1
- package/dist/Functions.js +51 -7
- package/dist/TextArea.svelte +4 -1
- package/package.json +1 -1
package/dist/Functions.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare const DoIDsMatch: (a: any, b: any) => boolean;
|
|
|
32
32
|
* @param el
|
|
33
33
|
*/
|
|
34
34
|
export declare function autoFocus(el: HTMLElement | HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | never): void;
|
|
35
|
-
export declare function autoGrow(node: HTMLTextAreaElement): {
|
|
35
|
+
export declare function autoGrow(node: HTMLTextAreaElement, _value?: string | null): {
|
|
36
36
|
update(): void;
|
|
37
37
|
destroy(): void;
|
|
38
38
|
};
|
package/dist/Functions.js
CHANGED
|
@@ -186,29 +186,73 @@ export function autoFocus(el) {
|
|
|
186
186
|
el.focus();
|
|
187
187
|
});
|
|
188
188
|
}
|
|
189
|
-
export function autoGrow(node) {
|
|
189
|
+
export function autoGrow(node, _value) {
|
|
190
|
+
let userResized = false;
|
|
191
|
+
let pointerDown = false;
|
|
192
|
+
let lastSetHeightPx = 0;
|
|
193
|
+
const getPx = (n) => `${Math.round(n)}px`;
|
|
190
194
|
const resize = () => {
|
|
195
|
+
if (userResized)
|
|
196
|
+
return;
|
|
191
197
|
// Temporarily reset height to measure the full scroll height
|
|
192
198
|
node.style.height = 'auto';
|
|
193
|
-
|
|
199
|
+
const target = node.scrollHeight;
|
|
200
|
+
lastSetHeightPx = target;
|
|
201
|
+
node.style.height = getPx(target);
|
|
194
202
|
};
|
|
195
|
-
// Prevent scrollbars while growing
|
|
203
|
+
// Prevent scrollbars while growing; remove if you want visible scrollbar
|
|
196
204
|
node.style.overflowY = 'hidden';
|
|
197
205
|
resize();
|
|
198
206
|
const onInput = () => resize();
|
|
199
207
|
node.addEventListener('input', onInput);
|
|
200
|
-
//
|
|
201
|
-
const
|
|
208
|
+
// Track potential manual resize start/end
|
|
209
|
+
const onPointerDown = () => {
|
|
210
|
+
pointerDown = true;
|
|
211
|
+
};
|
|
212
|
+
const endPointer = () => {
|
|
213
|
+
pointerDown = false;
|
|
214
|
+
};
|
|
215
|
+
node.addEventListener('pointerdown', onPointerDown);
|
|
216
|
+
window.addEventListener('pointerup', endPointer, { passive: true });
|
|
217
|
+
window.addEventListener('blur', endPointer);
|
|
218
|
+
window.addEventListener('pointercancel', endPointer);
|
|
219
|
+
// Observe size changes; if size changes while pointer is down
|
|
220
|
+
// and differs from our last programmatically set height, assume manual resize
|
|
221
|
+
const ro = new ResizeObserver((entries) => {
|
|
222
|
+
if (userResized)
|
|
223
|
+
return;
|
|
224
|
+
const entry = entries[0];
|
|
225
|
+
if (!entry)
|
|
226
|
+
return;
|
|
227
|
+
const h = entry.contentRect.height;
|
|
228
|
+
// If user is interacting and the height deviates from our target,
|
|
229
|
+
// treat this as manual resize
|
|
230
|
+
if (pointerDown && Math.abs(h - lastSetHeightPx) > 0.5) {
|
|
231
|
+
userResized = true;
|
|
232
|
+
node.dataset.autogrowLocked = 'true';
|
|
233
|
+
// Stop forcing overflow hidden so the user's resize behaves naturally
|
|
234
|
+
node.style.overflowY = '';
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
// Otherwise, if container width changes, keep adjusting unless locked
|
|
238
|
+
if (!pointerDown)
|
|
239
|
+
resize();
|
|
240
|
+
});
|
|
202
241
|
ro.observe(node);
|
|
203
242
|
return {
|
|
204
243
|
update() {
|
|
205
|
-
|
|
244
|
+
if (userResized)
|
|
245
|
+
return;
|
|
206
246
|
resize();
|
|
207
247
|
},
|
|
208
248
|
destroy() {
|
|
209
249
|
node.removeEventListener('input', onInput);
|
|
250
|
+
node.removeEventListener('pointerdown', onPointerDown);
|
|
251
|
+
window.removeEventListener('pointerup', endPointer);
|
|
252
|
+
window.removeEventListener('blur', endPointer);
|
|
253
|
+
window.removeEventListener('pointercancel', endPointer);
|
|
210
254
|
ro.disconnect();
|
|
211
|
-
}
|
|
255
|
+
},
|
|
212
256
|
};
|
|
213
257
|
}
|
|
214
258
|
/**
|
package/dist/TextArea.svelte
CHANGED
|
@@ -26,5 +26,8 @@
|
|
|
26
26
|
<DisplayHTML {value} hidden={!!otherProps.hidden} />
|
|
27
27
|
</div>
|
|
28
28
|
{:else}
|
|
29
|
-
<textarea {...otherProps}
|
|
29
|
+
<textarea {...otherProps}
|
|
30
|
+
bind:value={value}
|
|
31
|
+
use:useActions={use}
|
|
32
|
+
use:autoGrow={value}></textarea>
|
|
30
33
|
{/if}
|