@sveltia/ui 0.2.2 → 0.2.3
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.
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
<svelte:options accessors={true} />
|
|
6
6
|
|
|
7
7
|
<script>
|
|
8
|
+
import { onMount, tick } from 'svelte';
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* CSS class name on the button.
|
|
10
12
|
* @type {String}
|
|
@@ -26,35 +28,67 @@
|
|
|
26
28
|
|
|
27
29
|
/** @type {(String|undefined)} */
|
|
28
30
|
let height;
|
|
31
|
+
/** @type {(HTMLTextAreaElement|undefined)} */
|
|
32
|
+
let outer = undefined;
|
|
33
|
+
let resizing = false;
|
|
34
|
+
let lastWidth = 0;
|
|
29
35
|
|
|
30
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Resize the `<textarea>` based on the filled text content.
|
|
38
|
+
*/
|
|
39
|
+
const resizeTextarea = async () => {
|
|
40
|
+
resizing = true;
|
|
31
41
|
height = 'auto';
|
|
32
42
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
43
|
+
await tick();
|
|
44
|
+
|
|
45
|
+
height = value && element?.scrollHeight ? `${element.scrollHeight + 4}px` : undefined;
|
|
46
|
+
resizing = false;
|
|
36
47
|
};
|
|
37
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Call {@link resizeTextarea} whenever the text content is updated.
|
|
51
|
+
*/
|
|
38
52
|
$: {
|
|
39
|
-
if (
|
|
40
|
-
resizeTextarea();
|
|
53
|
+
if (autoResize) {
|
|
54
|
+
resizeTextarea(value);
|
|
41
55
|
}
|
|
42
56
|
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Call {@link resizeTextarea} whenever it’s horizontally resized.
|
|
60
|
+
*/
|
|
61
|
+
onMount(() => {
|
|
62
|
+
const observer = new ResizeObserver(([{ contentRect }]) => {
|
|
63
|
+
const { width } = contentRect;
|
|
64
|
+
|
|
65
|
+
if (autoResize && lastWidth !== width) {
|
|
66
|
+
lastWidth = width;
|
|
67
|
+
resizeTextarea();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
observer.observe(outer);
|
|
72
|
+
|
|
73
|
+
// onUnmount
|
|
74
|
+
return () => {
|
|
75
|
+
observer.disconnect();
|
|
76
|
+
};
|
|
77
|
+
});
|
|
43
78
|
</script>
|
|
44
79
|
|
|
45
|
-
<div class="sui text-area {className}">
|
|
80
|
+
<div class="sui text-area {className}" bind:this={outer}>
|
|
46
81
|
<textarea
|
|
47
82
|
name={name || undefined}
|
|
48
83
|
{...$$restProps}
|
|
49
84
|
style:height
|
|
85
|
+
class:resizing
|
|
50
86
|
bind:this={element}
|
|
87
|
+
bind:value
|
|
51
88
|
on:click
|
|
52
89
|
on:input
|
|
53
90
|
on:keypress
|
|
54
|
-
|
|
55
|
-
value = element.value;
|
|
56
|
-
}}>{value}</textarea
|
|
57
|
-
>
|
|
91
|
+
/>
|
|
58
92
|
</div>
|
|
59
93
|
|
|
60
94
|
<style>.text-area {
|
|
@@ -80,6 +114,9 @@ textarea {
|
|
|
80
114
|
resize: vertical;
|
|
81
115
|
transition: all 200ms;
|
|
82
116
|
}
|
|
117
|
+
textarea.resizing {
|
|
118
|
+
transition-duration: 0ms;
|
|
119
|
+
}
|
|
83
120
|
textarea:focus {
|
|
84
121
|
border-color: var(--primary-accent-color);
|
|
85
122
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltia/ui",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"svelte": "^3.55.1"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@babel/core": "^7.21.
|
|
30
|
+
"@babel/core": "^7.21.5",
|
|
31
31
|
"@babel/eslint-parser": "^7.21.3",
|
|
32
|
-
"@playwright/test": "^1.
|
|
33
|
-
"@sveltejs/adapter-auto": "2.0.
|
|
34
|
-
"@sveltejs/kit": "1.15.
|
|
32
|
+
"@playwright/test": "^1.33.0",
|
|
33
|
+
"@sveltejs/adapter-auto": "2.0.1",
|
|
34
|
+
"@sveltejs/kit": "1.15.9",
|
|
35
35
|
"@sveltejs/package": "^2.0.2",
|
|
36
36
|
"cspell": "^6.31.1",
|
|
37
37
|
"eslint": "^8.39.0",
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"postcss-html": "^1.5.0",
|
|
45
45
|
"prettier": "^2.8.8",
|
|
46
46
|
"prettier-plugin-svelte": "^2.10.0",
|
|
47
|
-
"sass": "^1.62.
|
|
47
|
+
"sass": "^1.62.1",
|
|
48
48
|
"stylelint": "^15.6.0",
|
|
49
|
-
"stylelint-config-recommended-scss": "^
|
|
50
|
-
"stylelint-scss": "^
|
|
49
|
+
"stylelint-config-recommended-scss": "^11.0.0",
|
|
50
|
+
"stylelint-scss": "^5.0.0",
|
|
51
51
|
"svelte-check": "^3.2.0",
|
|
52
52
|
"svelte-i18n": "^3.6.0",
|
|
53
53
|
"svelte-migrate": "^1.1.3",
|
|
54
54
|
"svelte-preprocess": "^5.0.3",
|
|
55
55
|
"tslib": "^2.5.0",
|
|
56
|
-
"vite": "^4.3.
|
|
56
|
+
"vite": "^4.3.3",
|
|
57
57
|
"vitest": "^0.30.1"
|
|
58
58
|
},
|
|
59
59
|
"exports": {
|