@c2n/textarea 0.0.6 → 0.0.7

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/textarea.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { LitElement, html, nothing, unsafeCSS } from "lit";
2
- import { customElement, property, query, state } from "lit/decorators.js";
2
+ import { property, query, state } from "lit/decorators.js";
3
+ import { customElement } from "@c2n/core/element-helper.js";
3
4
  import { ifDefined } from "lit/directives/if-defined.js";
4
5
  import { live } from "lit/directives/live.js";
5
6
  import { redispatchEvent } from "@c2n/core/dom-helper.js";
@@ -18,6 +19,9 @@ function __decorate(decorators, target, key, desc) {
18
19
  var Textarea = class Textarea extends LitElement {
19
20
  constructor(..._args) {
20
21
  super(..._args);
22
+ this.internals = this.attachInternals();
23
+ this.customValidityMessage = "";
24
+ this.disabledByForm = false;
21
25
  this.value = "";
22
26
  this.name = "";
23
27
  this.label = "";
@@ -39,9 +43,29 @@ var Textarea = class Textarea extends LitElement {
39
43
  this.dirty = false;
40
44
  this.hasSupportingSlot = false;
41
45
  }
46
+ static {
47
+ this.formAssociated = true;
48
+ }
42
49
  static {
43
50
  this.styles = unsafeCSS(textarea_default);
44
51
  }
52
+ /** The containing form, when this control is associated with one. */
53
+ get form() {
54
+ return this.internals.form;
55
+ }
56
+ /** Labels associated with this form control. */
57
+ get labels() {
58
+ return this.internals.labels;
59
+ }
60
+ get validity() {
61
+ return this.internals.validity;
62
+ }
63
+ get validationMessage() {
64
+ return this.internals.validationMessage;
65
+ }
66
+ get willValidate() {
67
+ return this.internals.willValidate;
68
+ }
45
69
  attributeChangedCallback(name, oldValue, newValue) {
46
70
  if (name === "value" && this.dirty) return;
47
71
  super.attributeChangedCallback(name, oldValue, newValue);
@@ -71,17 +95,43 @@ var Textarea = class Textarea extends LitElement {
71
95
  this.value = this.getAttribute("value") ?? "";
72
96
  this.error = false;
73
97
  }
98
+ formResetCallback() {
99
+ this.reset();
100
+ }
101
+ formDisabledCallback(disabled) {
102
+ this.disabledByForm = disabled && !this.hasAttribute("disabled");
103
+ }
104
+ formStateRestoreCallback(state) {
105
+ if (typeof state === "string") this.value = state;
106
+ }
74
107
  /** Checks the native textarea constraints. Await updateComplete after changing properties. */
75
108
  checkValidity() {
76
- return this.input?.checkValidity() ?? true;
109
+ return this.internals.checkValidity();
77
110
  }
78
111
  /** Shows the browser's validation feedback. */
79
112
  reportValidity() {
80
- return this.input?.reportValidity() ?? true;
113
+ return this.internals.reportValidity();
81
114
  }
82
115
  /** Sets or clears the native validation message. */
83
116
  setCustomValidity(message) {
117
+ this.customValidityMessage = message;
84
118
  this.input?.setCustomValidity(message);
119
+ this.syncFormState();
120
+ }
121
+ updated(_changed) {
122
+ this.syncFormState();
123
+ }
124
+ syncFormState() {
125
+ this.internals.setFormValue(this.value, this.value);
126
+ if (!this.input || this.effectiveDisabled) {
127
+ this.internals.setValidity({});
128
+ return;
129
+ }
130
+ this.input.setCustomValidity(this.customValidityMessage);
131
+ this.internals.setValidity(this.input.validity, this.input.validationMessage, this.input);
132
+ }
133
+ get effectiveDisabled() {
134
+ return this.disabled || this.disabledByForm;
85
135
  }
86
136
  handleInput(event) {
87
137
  this.dirty = true;
@@ -99,7 +149,7 @@ var Textarea = class Textarea extends LitElement {
99
149
  this.hasSupportingSlot = event.target.assignedNodes({ flatten: true }).length > 0;
100
150
  }
101
151
  render() {
102
- const invalid = this.error && !this.disabled;
152
+ const invalid = this.error && !this.effectiveDisabled;
103
153
  const showError = invalid && !!this.errorText;
104
154
  const supporting = !!this.help || this.hasSupportingSlot || showError || this.maxLength >= 0;
105
155
  return html` <textarea
@@ -115,7 +165,7 @@ var Textarea = class Textarea extends LitElement {
115
165
  autocomplete=${ifDefined(this.autocomplete || void 0)}
116
166
  maxlength=${ifDefined(this.maxLength >= 0 ? this.maxLength : void 0)}
117
167
  minlength=${ifDefined(this.minLength >= 0 ? this.minLength : void 0)}
118
- ?disabled=${this.disabled}
168
+ ?disabled=${this.effectiveDisabled}
119
169
  ?readonly=${this.readOnly}
120
170
  ?required=${this.required}
121
171
  .value=${live(this.value)}
@@ -132,6 +182,7 @@ var Textarea = class Textarea extends LitElement {
132
182
  </div>`;
133
183
  }
134
184
  };
185
+ __decorate([state()], Textarea.prototype, "disabledByForm", void 0);
135
186
  __decorate([property()], Textarea.prototype, "value", void 0);
136
187
  __decorate([property()], Textarea.prototype, "name", void 0);
137
188
  __decorate([property()], Textarea.prototype, "label", void 0);
package/package.json CHANGED
@@ -1,18 +1,30 @@
1
1
  {
2
2
  "name": "@c2n/textarea",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "type": "module",
5
5
  "main": "dist/textarea.js",
6
6
  "exports": {
7
7
  ".": {
8
- "default": "./dist/textarea.js",
9
- "types": "./types/src/textarea.d.ts"
8
+ "types": "./types/src/textarea.d.ts",
9
+ "default": "./dist/textarea.js"
10
+ },
11
+ "./react": {
12
+ "types": "./react.d.ts",
13
+ "default": "./react.js"
14
+ },
15
+ "./vue": {
16
+ "types": "./vue.d.ts",
17
+ "default": "./vue.js"
10
18
  },
11
19
  "./custom-elements.json": "./custom-elements.json"
12
20
  },
13
21
  "files": [
14
22
  "dist",
15
- "types"
23
+ "types",
24
+ "react.d.ts",
25
+ "react.js",
26
+ "vue.d.ts",
27
+ "vue.js"
16
28
  ],
17
29
  "keywords": [
18
30
  "textarea",
@@ -50,12 +62,12 @@
50
62
  }
51
63
  },
52
64
  "dependencies": {
53
- "@c2n/core": "0.0.6",
65
+ "@c2n/core": "0.0.7",
54
66
  "lit": "3.3.3"
55
67
  },
56
68
  "devDependencies": {
57
69
  "@c2n/config": "*"
58
70
  },
59
71
  "customElements": "custom-elements.json",
60
- "gitHead": "2921054bc75299da66dad11c1e374246ff88a51e"
72
+ "gitHead": "c8db398a27f7cd417d665fdf5da455fee2d4e910"
61
73
  }
package/react.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // JSX types for the custom elements of @c2n/textarea. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/textarea/react'
6
+ //
7
+ // Register the elements at module scope before React renders, or React writes an object prop as an
8
+ // attribute and it stringifies.
9
+
10
+ import type { DetailedHTMLProps, HTMLAttributes } from 'react'
11
+ import type { Textarea } from '@c2n/textarea'
12
+
13
+ /** Standard React host-element attributes plus the element's own public properties. */
14
+ type C2Props<T> = DetailedHTMLProps<HTMLAttributes<T>, T> & Partial<Omit<T, keyof HTMLElement>>
15
+
16
+ declare module 'react' {
17
+ namespace JSX {
18
+ interface IntrinsicElements {
19
+ 'c2-textarea': C2Props<Textarea>
20
+ }
21
+ }
22
+ }
23
+
24
+ export {}
package/react.js ADDED
@@ -0,0 +1,3 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ // Types only — see the matching .d.ts.
3
+ export {}
@@ -1,4 +1,15 @@
1
- import { LitElement } from 'lit';
1
+ import { LitElement, type PropertyValues } from 'lit';
2
+ import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
3
+ /** Events fired by {@link Textarea}, keyed for `addEventListener`. */
4
+ export interface TextareaEventMap {
5
+ input: InputEvent;
6
+ change: Event;
7
+ select: Event;
8
+ }
9
+ export interface Textarea {
10
+ addEventListener: TypedAddEventListener<Textarea, TextareaEventMap>;
11
+ removeEventListener: TypedRemoveEventListener<Textarea, TextareaEventMap>;
12
+ }
2
13
  /**
3
14
  * Multiline text input with native resizing, helper text, error feedback and a character counter.
4
15
  * @tag c2-textarea
@@ -30,7 +41,11 @@ import { LitElement } from 'lit';
30
41
  * @cssproperty {color} [--c2-textarea__supporting-text__error--color=#dc2626]
31
42
  */
32
43
  export declare class Textarea extends LitElement {
44
+ static formAssociated: boolean;
33
45
  static styles: import("lit").CSSResult;
46
+ private readonly internals;
47
+ private customValidityMessage;
48
+ private disabledByForm;
34
49
  /** Current text. Set this property to update the value programmatically. */
35
50
  value: string;
36
51
  /** Name forwarded to the native control. */
@@ -70,6 +85,13 @@ export declare class Textarea extends LitElement {
70
85
  private dirty;
71
86
  private hasSupportingSlot;
72
87
  private input?;
88
+ /** The containing form, when this control is associated with one. */
89
+ get form(): HTMLFormElement | null;
90
+ /** Labels associated with this form control. */
91
+ get labels(): NodeList;
92
+ get validity(): ValidityState;
93
+ get validationMessage(): string;
94
+ get willValidate(): boolean;
73
95
  attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
74
96
  /** Focuses the native textarea. */
75
97
  focus(options?: FocusOptions): void;
@@ -82,12 +104,18 @@ export declare class Textarea extends LitElement {
82
104
  isDirty(): boolean;
83
105
  /** Restores the value attribute and clears the error state. */
84
106
  reset(): void;
107
+ formResetCallback(): void;
108
+ formDisabledCallback(disabled: boolean): void;
109
+ formStateRestoreCallback(state: string | File | FormData | null): void;
85
110
  /** Checks the native textarea constraints. Await updateComplete after changing properties. */
86
111
  checkValidity(): boolean;
87
112
  /** Shows the browser's validation feedback. */
88
113
  reportValidity(): boolean;
89
114
  /** Sets or clears the native validation message. */
90
115
  setCustomValidity(message: string): void;
116
+ protected updated(_changed: PropertyValues): void;
117
+ private syncFormState;
118
+ private get effectiveDisabled();
91
119
  private handleInput;
92
120
  private handleChange;
93
121
  private handleSelect;
@@ -1 +1 @@
1
- {"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../src/textarea.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,MAAM,KAAK,CAAA;AAO1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,qBACa,QAAS,SAAQ,UAAU;IACtC,OAAgB,MAAM,0BAAoB;IAE1C,4EAA4E;IAChE,KAAK,SAAK;IACtB,4CAA4C;IAChC,IAAI,SAAK;IACrB,+CAA+C;IACnC,KAAK,SAAK;IACtB,+CAA+C;IACC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAO;IAC/E,6BAA6B;IACjB,WAAW,SAAK;IAC5B,oCAAoC;IACR,IA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Md,OAAO,CAAC,QAAQ,EAAE,cAAc;IAInD,OAAO,CAAC,aAAa;IAUrB,OAAO,KAAK,iBAAiB,GAE5B;IAED,OAAO,CAAC,WAAW;IAKnB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,YAAY;IAGpB,OAAO,CAAC,gBAAgB;IAIf,MAAM;CAiChB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,aAAa,EAAE,QAAQ,CAAA;KACxB;CACF"}
package/vue.d.ts ADDED
@@ -0,0 +1,37 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ //
3
+ // Vue template types for the custom elements of @c2n/textarea. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/textarea/vue'
6
+ //
7
+ // Tell the compiler about the tags as well, or every c2-* tag is resolved as a Vue component and renders
8
+ // nothing: template.compilerOptions.isCustomElement = (tag) => tag.startsWith('c2-') in vite.config.ts.
9
+
10
+ import type { DefineComponent, HTMLAttributes } from 'vue'
11
+ import type { Textarea, TextareaEventMap } from '@c2n/textarea'
12
+
13
+ /** The element's own public properties, plus every attribute Vue understands on a host element. */
14
+ type C2Props<T> = Partial<Omit<T, keyof HTMLElement>> & HTMLAttributes
15
+
16
+ declare module 'vue' {
17
+ interface GlobalComponents {
18
+ 'c2-textarea': DefineComponent<
19
+ C2Props<Textarea> & {
20
+ 'aria-label'?: unknown
21
+ 'error-text'?: unknown
22
+ onInput?: (event: TextareaEventMap['input']) => void
23
+ onChange?: (event: TextareaEventMap['change']) => void
24
+ onSelect?: (event: TextareaEventMap['select']) => void
25
+ }
26
+ >
27
+ }
28
+ }
29
+
30
+ declare module '@vue/runtime-dom' {
31
+ interface HTMLAttributes {
32
+ /** Vue's own definition omits it, and slotting a plain element into a component needs it. */
33
+ slot?: string
34
+ }
35
+ }
36
+
37
+ export {}
package/vue.js ADDED
@@ -0,0 +1,3 @@
1
+ // GENERATED by @c2n/framework-types. Do not edit by hand.
2
+ // Types only — see the matching .d.ts.
3
+ export {}