@c2n/slider 0.0.6 → 0.0.8

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/slider.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { LitElement, html, nothing, unsafeCSS } from "lit";
2
- import { customElement, property, query } 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 { classMap } from "lit/directives/class-map.js";
4
5
  import { ifDefined } from "lit/directives/if-defined.js";
5
6
  import { styleMap } from "lit/directives/style-map.js";
@@ -20,6 +21,11 @@ var MAX_TICKS = 200;
20
21
  var Slider = class Slider extends LitElement {
21
22
  constructor(..._args) {
22
23
  super(..._args);
24
+ this.internals = this.attachInternals();
25
+ this.customValidityMessage = "";
26
+ this.disabledByForm = false;
27
+ this.defaultValue = 0;
28
+ this.defaultValueCaptured = false;
23
29
  this.value = 0;
24
30
  this.min = 0;
25
31
  this.max = 100;
@@ -31,9 +37,56 @@ var Slider = class Slider extends LitElement {
31
37
  this.ticks = false;
32
38
  this.formatValue = (value) => String(value);
33
39
  }
40
+ static {
41
+ this.formAssociated = true;
42
+ }
34
43
  static {
35
44
  this.styles = unsafeCSS(slider_default);
36
45
  }
46
+ connectedCallback() {
47
+ super.connectedCallback();
48
+ if (!this.defaultValueCaptured) {
49
+ this.defaultValue = Number(this.getAttribute("value") ?? 0);
50
+ this.defaultValueCaptured = true;
51
+ }
52
+ }
53
+ /** The containing form, when this control is associated with one. */
54
+ get form() {
55
+ return this.internals.form;
56
+ }
57
+ /** Labels associated with this form control. */
58
+ get labels() {
59
+ return this.internals.labels;
60
+ }
61
+ get validity() {
62
+ return this.internals.validity;
63
+ }
64
+ get validationMessage() {
65
+ return this.internals.validationMessage;
66
+ }
67
+ get willValidate() {
68
+ return this.internals.willValidate;
69
+ }
70
+ formResetCallback() {
71
+ this.value = this.defaultValue;
72
+ }
73
+ formDisabledCallback(disabled) {
74
+ this.disabledByForm = disabled && !this.hasAttribute("disabled");
75
+ }
76
+ formStateRestoreCallback(state) {
77
+ if (typeof state === "string") this.value = Number(state);
78
+ }
79
+ checkValidity() {
80
+ return this.internals.checkValidity();
81
+ }
82
+ reportValidity() {
83
+ return this.internals.reportValidity();
84
+ }
85
+ setCustomValidity(message) {
86
+ this.customValidityMessage = message;
87
+ this.formElement?.setCustomValidity(message);
88
+ this.syncFormState();
89
+ }
37
90
  focus(options) {
38
91
  this.formElement?.focus(options);
39
92
  }
@@ -51,6 +104,27 @@ var Slider = class Slider extends LitElement {
51
104
  this.value = Number(this.formElement.value);
52
105
  redispatchEvent(this, event);
53
106
  }
107
+ updated(changed) {
108
+ if (changed.has("value") || changed.has("min") || changed.has("max") || changed.has("step")) {
109
+ const value = this.formElement.valueAsNumber;
110
+ if (Number.isFinite(value) && value !== this.value) this.value = value;
111
+ }
112
+ this.syncFormState();
113
+ }
114
+ syncFormState() {
115
+ if (!this.formElement) return;
116
+ const value = this.formElement.value;
117
+ this.internals.setFormValue(value, value);
118
+ if (this.effectiveDisabled) {
119
+ this.internals.setValidity({});
120
+ return;
121
+ }
122
+ this.formElement.setCustomValidity(this.customValidityMessage);
123
+ this.internals.setValidity(this.formElement.validity, this.formElement.validationMessage, this.formElement);
124
+ }
125
+ get effectiveDisabled() {
126
+ return this.disabled || this.disabledByForm;
127
+ }
54
128
  handleChange(event) {
55
129
  this.value = Number(this.formElement.value);
56
130
  redispatchEvent(this, event);
@@ -91,7 +165,7 @@ var Slider = class Slider extends LitElement {
91
165
  max=${this.max}
92
166
  step=${this.step}
93
167
  .value=${String(this.value)}
94
- ?disabled=${this.disabled}
168
+ ?disabled=${this.effectiveDisabled}
95
169
  aria-label=${ifDefined(this.ariaLabel)}
96
170
  aria-labelledby=${ifDefined(this.ariaLabelledBy)}
97
171
  aria-valuetext=${formatted}
@@ -103,6 +177,7 @@ var Slider = class Slider extends LitElement {
103
177
  `;
104
178
  }
105
179
  };
180
+ __decorate([state()], Slider.prototype, "disabledByForm", void 0);
106
181
  __decorate([query("input")], Slider.prototype, "formElement", void 0);
107
182
  __decorate([property({
108
183
  type: Number,
package/package.json CHANGED
@@ -1,18 +1,30 @@
1
1
  {
2
2
  "name": "@c2n/slider",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "type": "module",
5
5
  "main": "dist/slider.js",
6
6
  "exports": {
7
7
  ".": {
8
- "default": "./dist/slider.js",
9
- "types": "./types/src/slider.d.ts"
8
+ "types": "./types/src/slider.d.ts",
9
+ "default": "./dist/slider.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
  "slider",
@@ -50,12 +62,12 @@
50
62
  }
51
63
  },
52
64
  "dependencies": {
53
- "@c2n/core": "0.0.6",
65
+ "@c2n/core": "0.0.8",
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": "be59cbccee1d33ca248e39f69b05c0b595ec6c6d"
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/slider. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/slider/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 { Slider } from '@c2n/slider'
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-slider': C2Props<Slider>
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,5 +1,15 @@
1
1
  import { LitElement, type PropertyValues } from 'lit';
2
+ import type { TypedAddEventListener, TypedRemoveEventListener } from '@c2n/core/event-helper.js';
2
3
  export type SliderOrientation = 'horizontal' | 'vertical';
4
+ /** Events fired by {@link Slider}, keyed for `addEventListener`. */
5
+ export interface SliderEventMap {
6
+ input: Event;
7
+ change: Event;
8
+ }
9
+ export interface Slider {
10
+ addEventListener: TypedAddEventListener<Slider, SliderEventMap>;
11
+ removeEventListener: TypedRemoveEventListener<Slider, SliderEventMap>;
12
+ }
3
13
  /**
4
14
  * Single-value slider built on a native `<input type="range">`, so dragging, keyboard steps (Arrow keys, Page Up/Down,
5
15
  * Home/End), RTL and the `slider` role come from the browser. The component draws the track, the filled part, the
@@ -43,11 +53,19 @@ export type SliderOrientation = 'horizontal' | 'vertical';
43
53
  * @cssproperty {opacity} [--c2-slider__value--opacity=0] - Resting opacity of the bubble; it is fully visible while hovering, dragging or focused. `1` keeps it always on.
44
54
  */
45
55
  export declare class Slider extends LitElement {
56
+ static formAssociated: boolean;
46
57
  static styles: import("lit").CSSResult;
58
+ private readonly internals;
59
+ private customValidityMessage;
60
+ private disabledByForm;
61
+ private defaultValue;
62
+ private defaultValueCaptured;
47
63
  protected formElement: HTMLInputElement;
48
64
  /** Current value, clamped to `min`/`max` and snapped to `step` by the inner input. */
49
65
  value: number;
66
+ /** Minimum selectable value. */
50
67
  min: number;
68
+ /** Maximum selectable value. */
51
69
  max: number;
52
70
  /** Increment between values; also the distance between `ticks`. */
53
71
  step: number;
@@ -63,13 +81,32 @@ export declare class Slider extends LitElement {
63
81
  ticks: boolean;
64
82
  /** Formats the value for the bubble and `aria-valuetext`, e.g. `(v) => \`${v}%\``. Property only. */
65
83
  formatValue: (value: number) => string;
84
+ /** Accessible name used when no visible label names the slider. */
66
85
  ariaLabel: string;
86
+ /** Id of the element that labels the slider. */
67
87
  ariaLabelledBy: undefined | string;
88
+ connectedCallback(): void;
89
+ /** The containing form, when this control is associated with one. */
90
+ get form(): HTMLFormElement | null;
91
+ /** Labels associated with this form control. */
92
+ get labels(): NodeList;
93
+ get validity(): ValidityState;
94
+ get validationMessage(): string;
95
+ get willValidate(): boolean;
96
+ formResetCallback(): void;
97
+ formDisabledCallback(disabled: boolean): void;
98
+ formStateRestoreCallback(state: string | File | FormData | null): void;
99
+ checkValidity(): boolean;
100
+ reportValidity(): boolean;
101
+ setCustomValidity(message: string): void;
68
102
  focus(options?: FocusOptions): void;
69
103
  /** Position of the value along the track, `0` at `min` and `1` at `max`. */
70
104
  get fraction(): number;
71
105
  protected update(changed: PropertyValues<this>): void;
72
106
  private handleInput;
107
+ protected updated(changed: PropertyValues<this>): void;
108
+ private syncFormState;
109
+ private get effectiveDisabled();
73
110
  private handleChange;
74
111
  private renderTicks;
75
112
  render(): import("lit-html").TemplateResult<1>;
@@ -1 +1 @@
1
- {"version":3,"file":"slider.d.ts","sourceRoot":"","sources":["../../src/slider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA4B,KAAK,cAAc,EAAE,MAAM,KAAK,CAAA;AAQ/E,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG,UAAU,CAAA;AAIzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AACH,qBACa,MAAO,SAAQ,UAAU;IACpC,OAAgB,MAAM,0BAAoB;IAE1B,SAAS,CAAC,WAAW,EAAG,gBAAgB,CAAA;IAExD,sFA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,GAAG,IAAI;IAI/D,aAAa;IAIb,cAAc;IAId,iBAAiB,CAAC,OAAO,EAAE,MAAM;IAMxB,KAAK,CAAC,OAAO,CAAC,EAAE,YAAY;IAIrC,4EAA4E;IAC5E,IAAI,QAAQ,IAAI,MAAM,CAIrB;cAEkB,MAAM,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAKvD,OAAO,CAAC,WAAW;cAKA,OAAO,CAAC,OAAO,EAAE,cAAc,CAAC,IAAI,CAAC;IAUxD,OAAO,CAAC,aAAa;IAYrB,OAAO,KAAK,iBAAiB,GAE5B;IAED,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,WAAW;IAiBV,MAAM;CA8BhB;AAED,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,WAAW,EAAE,MAAM,CAAA;KACpB;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/slider. Import once, anywhere in the program:
4
+ //
5
+ // import '@c2n/slider/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 { Slider, SliderEventMap } from '@c2n/slider'
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-slider': DefineComponent<
19
+ C2Props<Slider> & {
20
+ 'show-value'?: unknown
21
+ 'aria-label'?: unknown
22
+ 'aria-labelledby'?: unknown
23
+ onInput?: (event: SliderEventMap['input']) => void
24
+ onChange?: (event: SliderEventMap['change']) => 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 {}