@m3e/textarea-autosize 1.0.0-rc.1

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 ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 matraic
4
+ Contact: matraic@yahoo.com
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/NOTICE.md ADDED
@@ -0,0 +1,8 @@
1
+ # NOTICE
2
+
3
+ This package includes code adapted from third-party sources under the MIT license:
4
+
5
+ - Angular Material CDK
6
+ Source: https://github.com/angular/components
7
+ License: MIT
8
+ Copyright (c) Google LLC
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # @m3e/textarea-autosize
2
+
3
+ The `m3e-textarea-autosize` component automatically adjusts the height of a linked `textarea` to fit its content, preserving layout integrity and user experience. This non-visual element listens to input changes and applies dynamic resizing, constrained by optional row limits. It supports declarative configuration via attributes and can be disabled when manual control is preferred.
4
+
5
+ > **Part of the [M3E](../../README.md) monorepo**
6
+ > This package is maintained within the unified M3E repository, which provides a suite of Material 3 web components.
7
+
8
+ ## ๐Ÿ“ฆ Installation
9
+
10
+ ```bash
11
+ npm install @m3e/textarea-autosize
12
+ ```
13
+
14
+ ## ๐Ÿ’ป Editor Integration
15
+
16
+ This package includes a [Custom Elements Manifest](https://github.com/webcomponents/custom-elements-manifest) to support enhanced editor tooling and developer experience.
17
+
18
+ ### Visual Studio Code
19
+
20
+ To enable autocomplete and hover documentation for `@m3e/textarea-autosize`, install the [Custom Elements Manifest Language Server](https://marketplace.visualstudio.com/items?itemName=pwrs.cem-language-server-vscode) extension. It will automatically detect the manifest bundled with this package and surface tag names, attributes, slots, and events in supported files.
21
+
22
+ Alternately, you can explicitly reference the `html-custom-data.json` and `css-custom-data.json` in your workspace settings:
23
+
24
+ ```json
25
+ {
26
+ "html.customData": ["./node_modules/@m3e/textarea-autosize/dist/html-custom-data.json"],
27
+ "css.customData": ["./node_modules/@m3e/textarea-autosize/dist/css-custom-data.json"]
28
+ }
29
+ ```
30
+
31
+ ## ๐Ÿš€ Browser Usage
32
+
33
+ This package uses [JavaScript Modules](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#module_specifiers). To use it directly in a browser without a bundler, use a module script similar to the following.
34
+
35
+ ```html
36
+ <script type="module" src="/node_modules/@m3e/textarea-autosize/dist/index.js"></script>
37
+ ```
38
+
39
+ In addition, you must use an [import map](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/script/type/importmap) to include dependencies.
40
+
41
+ ```html
42
+ <script type="importmap">
43
+ {
44
+ "imports": {
45
+ "lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
46
+ "@m3e/core": "/node_modules/@m3e/core/dist/index.js"
47
+ }
48
+ }
49
+ </script>
50
+ ```
51
+
52
+ > For production, use index.min.js for faster load times.
53
+
54
+ ## ๐Ÿ—‚๏ธ Elements
55
+
56
+ - `m3e-textarea-autosize` โ€” A non-visual element used to automatically resize a `textarea` to fit its content.
57
+
58
+ ## ๐Ÿงช Examples
59
+
60
+ The following example illustrates the `m3e-textarea-autosize` in conjunction with the `m3e-form-field` to automatically resize a field's `textarea` with a 5 row limit.
61
+
62
+ ```html
63
+ <m3e-form-field>
64
+ <label slot="label" for="fld">Textarea Autosize</label>
65
+ <textarea id="fld"></textarea>
66
+ <m3e-textarea-autosize for="fld" max-rows="5"></m3e-textarea-autosize>
67
+ </m3e-form-field>
68
+ ```
69
+
70
+ ## ๐Ÿ“– API Reference
71
+
72
+ This section details the attributes available for the `m3e-textarea-autosize` component.
73
+
74
+ ### โš™๏ธ Attributes
75
+
76
+ | Attribute | Type | Default | Description |
77
+ | ---------- | --------- | ------- | ----------------------------------------------------------------------- |
78
+ | `disabled` | `boolean` | `false` | Whether auto-sizing is disabled. |
79
+ | `for` | `string` | | The query selector used to specify the element related to this element. |
80
+ | `max-rows` | `number` | `0` | The maximum amount of rows in the `textarea`. |
81
+ | `min-rows` | `number` | `0` | The minimum amount of rows in the `textarea`. |
82
+
83
+ ## ๐Ÿค Contributing
84
+
85
+ See the root monorepo `CONTRIBUTING.md` for guidelines on contributing to this package.
86
+
87
+ ## ๐Ÿ“„ License
88
+
89
+ This package is licensed under the MIT License.
package/cem.config.mjs ADDED
@@ -0,0 +1,16 @@
1
+ import { customElementVsCodePlugin } from "custom-element-vs-code-integration";
2
+
3
+ export default {
4
+ globs: ["src/**/*.ts"],
5
+ exclude: ["src/**/*.spec.ts"],
6
+ packagejson: true,
7
+ outdir: "dist",
8
+ litelement: true,
9
+ plugins: [
10
+ customElementVsCodePlugin({
11
+ outdir: "dist",
12
+ htmlFileName: "html-custom-data.json",
13
+ cssFileName: "css-custom-data.json",
14
+ }),
15
+ ],
16
+ };
@@ -0,0 +1,49 @@
1
+ <!doctype html>
2
+ <html lang="en" style="overflow-y: auto">
3
+ <head>
4
+ <title>Textarea Autosize for M3E</title>
5
+ <meta charset="utf-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
7
+ <meta name="description" content="Textarea Autosize for M3E" />
8
+ <base href="./" />
9
+ <link rel="preconnect" href="https://fonts.googleapis.com" />
10
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
11
+ <link
12
+ href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100..900;1,100..900&display=swap"
13
+ rel="stylesheet"
14
+ />
15
+ <link
16
+ href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0..1,0"
17
+ rel="stylesheet"
18
+ />
19
+ <script type="importmap">
20
+ {
21
+ "imports": {
22
+ "lit": "https://cdn.jsdelivr.net/npm/lit@3.3.0/+esm",
23
+ "@m3e/core": "../../core/dist/index.min.js",
24
+ "@m3e/core/a11y": "../../core/dist/a11y.min.js"
25
+ }
26
+ }
27
+ </script>
28
+ <script type="module" src="../../form-field/dist/index.min.js"></script>
29
+ <script type="module" src="../../theme/dist/index.min.js"></script>
30
+ <script type="module" src="../dist/index.min.js"></script>
31
+ <style>
32
+ body {
33
+ font-family: "Roboto";
34
+ }
35
+ *:not(:defined) {
36
+ display: none;
37
+ }
38
+ </style>
39
+ </head>
40
+ <body>
41
+ <m3e-theme strong-focus>
42
+ <m3e-form-field>
43
+ <label slot="label" for="fld">Textarea Autosize</label>
44
+ <textarea id="fld"></textarea>
45
+ <m3e-textarea-autosize for="fld" max-rows="5"></m3e-textarea-autosize>
46
+ </m3e-form-field>
47
+ </m3e-theme>
48
+ </body>
49
+ </html>
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/microsoft/vscode-css-languageservice/main/docs/customData.schema.json",
3
+ "version": 1.1,
4
+ "properties": [],
5
+ "pseudoElements": []
6
+ }
@@ -0,0 +1,317 @@
1
+ {
2
+ "schemaVersion": "1.0.0",
3
+ "readme": "",
4
+ "modules": [
5
+ {
6
+ "kind": "javascript-module",
7
+ "path": "src/index.ts",
8
+ "declarations": [],
9
+ "exports": [
10
+ {
11
+ "kind": "js",
12
+ "name": "*",
13
+ "declaration": {
14
+ "name": "*",
15
+ "package": "\"./TextareaAutosizeElement\""
16
+ }
17
+ }
18
+ ]
19
+ },
20
+ {
21
+ "kind": "javascript-module",
22
+ "path": "src/TextareaAutosizeElement.ts",
23
+ "declarations": [
24
+ {
25
+ "kind": "class",
26
+ "description": "",
27
+ "name": "M3eTextareaAutosizeElement",
28
+ "members": [
29
+ {
30
+ "kind": "field",
31
+ "name": "#initialHeight",
32
+ "privacy": "private",
33
+ "type": {
34
+ "text": "string | undefined"
35
+ }
36
+ },
37
+ {
38
+ "kind": "field",
39
+ "name": "#cachedLineHeight",
40
+ "privacy": "private",
41
+ "type": {
42
+ "text": "number | undefined"
43
+ }
44
+ },
45
+ {
46
+ "kind": "field",
47
+ "name": "#cachedPlaceholderHeight",
48
+ "privacy": "private",
49
+ "type": {
50
+ "text": "number | undefined"
51
+ }
52
+ },
53
+ {
54
+ "kind": "field",
55
+ "name": "#previousMinRows",
56
+ "privacy": "private",
57
+ "type": {
58
+ "text": "number | undefined"
59
+ }
60
+ },
61
+ {
62
+ "kind": "field",
63
+ "name": "#previousValue",
64
+ "privacy": "private",
65
+ "type": {
66
+ "text": "string | undefined"
67
+ }
68
+ },
69
+ {
70
+ "kind": "field",
71
+ "name": "#hasFocus",
72
+ "privacy": "private",
73
+ "type": {
74
+ "text": "boolean"
75
+ },
76
+ "default": "false"
77
+ },
78
+ {
79
+ "kind": "field",
80
+ "name": "#windowResizeHandler",
81
+ "privacy": "private",
82
+ "readonly": true
83
+ },
84
+ {
85
+ "kind": "field",
86
+ "name": "#focusHandler",
87
+ "privacy": "private",
88
+ "readonly": true
89
+ },
90
+ {
91
+ "kind": "field",
92
+ "name": "#inputHandler",
93
+ "privacy": "private",
94
+ "readonly": true
95
+ },
96
+ {
97
+ "kind": "field",
98
+ "name": "maxRows",
99
+ "type": {
100
+ "text": "number"
101
+ },
102
+ "default": "0",
103
+ "description": "The maximum amount of rows in the `textarea`.",
104
+ "attribute": "max-rows"
105
+ },
106
+ {
107
+ "kind": "field",
108
+ "name": "minRows",
109
+ "type": {
110
+ "text": "number"
111
+ },
112
+ "default": "0",
113
+ "description": "The minimum amount of rows in the `textarea`.",
114
+ "attribute": "min-rows"
115
+ },
116
+ {
117
+ "kind": "field",
118
+ "name": "disabled",
119
+ "type": {
120
+ "text": "boolean"
121
+ },
122
+ "default": "false",
123
+ "description": "Whether auto-sizing is disabled.",
124
+ "attribute": "disabled",
125
+ "reflects": true
126
+ },
127
+ {
128
+ "kind": "method",
129
+ "name": "attach",
130
+ "return": {
131
+ "type": {
132
+ "text": "void"
133
+ }
134
+ },
135
+ "parameters": [
136
+ {
137
+ "name": "control",
138
+ "type": {
139
+ "text": "HTMLElement"
140
+ }
141
+ }
142
+ ]
143
+ },
144
+ {
145
+ "kind": "method",
146
+ "name": "detach",
147
+ "return": {
148
+ "type": {
149
+ "text": "void"
150
+ }
151
+ }
152
+ },
153
+ {
154
+ "kind": "method",
155
+ "name": "resizeToFitContent",
156
+ "return": {
157
+ "type": {
158
+ "text": "void"
159
+ }
160
+ },
161
+ "parameters": [
162
+ {
163
+ "name": "force",
164
+ "default": "false",
165
+ "type": {
166
+ "text": "boolean"
167
+ },
168
+ "description": "Whether to force a height recalculation.",
169
+ "optional": true
170
+ }
171
+ ],
172
+ "description": "Resize the `textarea` to fit its content."
173
+ },
174
+ {
175
+ "kind": "method",
176
+ "name": "reset",
177
+ "description": "Resets the `textarea` to its original size."
178
+ },
179
+ {
180
+ "kind": "method",
181
+ "name": "#cacheTextareaLineHeight",
182
+ "privacy": "private",
183
+ "return": {
184
+ "type": {
185
+ "text": "void"
186
+ }
187
+ }
188
+ },
189
+ {
190
+ "kind": "method",
191
+ "name": "#cacheTextareaPlaceholderHeight",
192
+ "privacy": "private",
193
+ "return": {
194
+ "type": {
195
+ "text": "void"
196
+ }
197
+ }
198
+ },
199
+ {
200
+ "kind": "method",
201
+ "name": "#setMinHeight",
202
+ "privacy": "private",
203
+ "return": {
204
+ "type": {
205
+ "text": "void"
206
+ }
207
+ }
208
+ },
209
+ {
210
+ "kind": "method",
211
+ "name": "#setMaxHeight",
212
+ "privacy": "private",
213
+ "return": {
214
+ "type": {
215
+ "text": "void"
216
+ }
217
+ }
218
+ },
219
+ {
220
+ "kind": "method",
221
+ "name": "#measureScrollHeight",
222
+ "privacy": "private",
223
+ "return": {
224
+ "type": {
225
+ "text": "number"
226
+ }
227
+ }
228
+ },
229
+ {
230
+ "kind": "method",
231
+ "name": "#scrollToCaretPosition",
232
+ "privacy": "private"
233
+ },
234
+ {
235
+ "kind": "method",
236
+ "name": "_handleWindowResize",
237
+ "privacy": "private",
238
+ "return": {
239
+ "type": {
240
+ "text": "void"
241
+ }
242
+ }
243
+ }
244
+ ],
245
+ "attributes": [
246
+ {
247
+ "description": "Whether auto-sizing is disabled.",
248
+ "name": "disabled",
249
+ "type": {
250
+ "text": "boolean"
251
+ },
252
+ "default": "false",
253
+ "fieldName": "disabled"
254
+ },
255
+ {
256
+ "description": "The query selector used to specify the element related to this element.",
257
+ "name": "for"
258
+ },
259
+ {
260
+ "description": "The maximum amount of rows in the `textarea`.",
261
+ "name": "max-rows",
262
+ "type": {
263
+ "text": "number"
264
+ },
265
+ "default": "0",
266
+ "fieldName": "maxRows"
267
+ },
268
+ {
269
+ "description": "The minimum amount of rows in the `textarea`.",
270
+ "name": "min-rows",
271
+ "type": {
272
+ "text": "number"
273
+ },
274
+ "default": "0",
275
+ "fieldName": "minRows"
276
+ }
277
+ ],
278
+ "mixins": [
279
+ {
280
+ "name": "HtmlFor",
281
+ "package": "@m3e/core"
282
+ },
283
+ {
284
+ "name": "Role",
285
+ "package": "@m3e/core"
286
+ }
287
+ ],
288
+ "superclass": {
289
+ "name": "LitElement",
290
+ "package": "lit"
291
+ },
292
+ "tagName": "m3e-textarea-autosize",
293
+ "customElement": true,
294
+ "summary": "A non-visual element used to automatically resize a `textarea` to fit its content."
295
+ }
296
+ ],
297
+ "exports": [
298
+ {
299
+ "kind": "js",
300
+ "name": "M3eTextareaAutosizeElement",
301
+ "declaration": {
302
+ "name": "M3eTextareaAutosizeElement",
303
+ "module": "src/TextareaAutosizeElement.ts"
304
+ }
305
+ },
306
+ {
307
+ "kind": "custom-element-definition",
308
+ "name": "m3e-textarea-autosize",
309
+ "declaration": {
310
+ "name": "M3eTextareaAutosizeElement",
311
+ "module": "src/TextareaAutosizeElement.ts"
312
+ }
313
+ }
314
+ ]
315
+ }
316
+ ]
317
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/microsoft/vscode-html-languageservice/main/docs/customData.schema.json",
3
+ "version": 1.1,
4
+ "tags": [
5
+ {
6
+ "name": "m3e-textarea-autosize",
7
+ "description": "A non-visual element used to automatically resize a `textarea` to fit its content.\n---\n\n\n### **Methods:**\n - **resizeToFitContent(force: _boolean_): _void_** - Resize the `textarea` to fit its content.\n- **reset()** - Resets the `textarea` to its original size.",
8
+ "attributes": [
9
+ {
10
+ "name": "disabled",
11
+ "description": "Whether auto-sizing is disabled.",
12
+ "values": []
13
+ },
14
+ {
15
+ "name": "for",
16
+ "description": "The query selector used to specify the element related to this element.",
17
+ "values": []
18
+ },
19
+ {
20
+ "name": "max-rows",
21
+ "description": "The maximum amount of rows in the `textarea`.",
22
+ "values": []
23
+ },
24
+ {
25
+ "name": "min-rows",
26
+ "description": "The minimum amount of rows in the `textarea`.",
27
+ "values": []
28
+ }
29
+ ],
30
+ "references": []
31
+ }
32
+ ]
33
+ }