@neovici/cosmoz-input 5.5.1 → 5.6.0

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.
@@ -1,5 +1,5 @@
1
+ import { ObjectFromList, Render } from './render';
1
2
  import { BaseInput } from './use-input';
2
- import { Render, ObjectFromList } from './render';
3
3
  declare const observedAttributes: string[];
4
4
  type CosmozInput = HTMLElement & ObjectFromList<typeof observedAttributes> & BaseInput & Render;
5
5
  export declare const Input: (host: CosmozInput) => import("lit-html").TemplateResult<1>;
@@ -1,13 +1,13 @@
1
+ import { component, sheet } from '@pionjs/pion';
1
2
  import { html } from 'lit-html';
3
+ import { ifDefined } from 'lit-html/directives/if-defined.js';
2
4
  import { live } from 'lit-html/directives/live.js';
3
5
  import { ref } from 'lit-html/directives/ref.js';
4
- import { ifDefined } from 'lit-html/directives/if-defined.js';
5
- import { component, sheet } from '@pionjs/pion';
6
- import { useInput } from './use-input';
6
+ import { attributes, render } from './render';
7
+ import { styles } from './styles';
7
8
  import { useAllowedPattern } from './use-allowed-pattern';
8
- import { render, attributes } from './render';
9
+ import { useInput } from './use-input';
9
10
  import { getPlaceholder } from './util';
10
- import { styles } from './styles';
11
11
  const observedAttributes = [
12
12
  'type',
13
13
  'pattern',
@@ -52,4 +52,5 @@ export const Input = (host) => {
52
52
  customElements.define('cosmoz-input', component(Input, {
53
53
  observedAttributes,
54
54
  styleSheets: [sheet(styles)],
55
+ shadowRootInit: { mode: 'open', delegatesFocus: true },
55
56
  }));
@@ -1,5 +1,5 @@
1
+ import { ObjectFromList, Render } from './render';
1
2
  import { BaseInput } from './use-input';
2
- import { Render, ObjectFromList } from './render';
3
3
  declare const observedAttributes: string[];
4
4
  type CosmozInput = HTMLElement & ObjectFromList<typeof observedAttributes> & BaseInput & Render;
5
5
  export declare const Textarea: (host: CosmozInput) => import("lit-html").TemplateResult<1>;
@@ -1,12 +1,12 @@
1
1
  import { html } from 'lit-html';
2
+ import { ifDefined } from 'lit-html/directives/if-defined.js';
2
3
  import { live } from 'lit-html/directives/live.js';
3
4
  import { ref } from 'lit-html/directives/ref.js';
4
- import { ifDefined } from 'lit-html/directives/if-defined.js';
5
5
  import { component, sheet } from '@pionjs/pion';
6
- import { useInput } from './use-input';
7
- import { useAutoHeight } from './use-auto-height';
8
- import { render, attributes } from './render';
6
+ import { attributes, render } from './render';
9
7
  import { styles } from './styles';
8
+ import { useAutoHeight } from './use-auto-height';
9
+ import { useInput } from './use-input';
10
10
  const observedAttributes = ['rows', 'placeholder', ...attributes];
11
11
  export const Textarea = (host) => {
12
12
  const { autocomplete, value, placeholder, readonly, disabled, rows, cols, maxlength, } = host, { onChange, onFocus, onInput, onRef } = useInput(host);
@@ -24,4 +24,5 @@ export const Textarea = (host) => {
24
24
  customElements.define('cosmoz-textarea', component(Textarea, {
25
25
  observedAttributes,
26
26
  styleSheets: [sheet(styles)],
27
+ shadowRootInit: { mode: 'open', delegatesFocus: true },
27
28
  }));
package/dist/use-input.js CHANGED
@@ -1,31 +1,25 @@
1
- import { useCallback, useEffect, useRef } from '@pionjs/pion';
2
1
  import { useImperativeApi } from '@neovici/cosmoz-utils/hooks/use-imperative-api';
3
2
  import { notifyProperty } from '@neovici/cosmoz-utils/hooks/use-notify-property';
3
+ import { useCallback, useEffect, useRef } from '@pionjs/pion';
4
4
  export const useInput = (host) => {
5
5
  const inputRef = useRef(undefined);
6
6
  const onRef = useCallback((el) => (inputRef.current = el), []);
7
- const root = host.shadowRoot, onChange = useCallback((e) => host.dispatchEvent(new Event(e.type, { bubbles: e.bubbles })), []), onInput = useCallback((e) => notifyProperty(host, 'value', e.target.value), []), onFocus = useCallback((e) => notifyProperty(host, 'focused', e.type === 'focus'), []), focus = useCallback(() => inputRef.current?.focus(), []), validate = useCallback(() => {
7
+ const root = host.shadowRoot, onChange = useCallback((e) => host.dispatchEvent(new Event(e.type, { bubbles: e.bubbles })), []), onInput = useCallback((e) => notifyProperty(host, 'value', e.target.value), []), onFocus = useCallback((e) => notifyProperty(host, 'focused', e.type === 'focus'), []), validate = useCallback(() => {
8
8
  const valid = inputRef.current?.checkValidity();
9
9
  host.toggleAttribute('invalid', !valid);
10
10
  return valid;
11
11
  }, []);
12
- useImperativeApi({ focus, validate }, [focus, validate]);
12
+ useImperativeApi({ validate }, [validate]);
13
+ // delegatesFocus doesn't cover clicks on slotted light-DOM content
13
14
  useEffect(() => {
14
- const onMouseDown = (e) => {
15
- if (e.defaultPrevented ||
16
- host.disabled ||
17
- e.target.matches('input, textarea, label')) {
18
- return;
19
- }
20
- e.preventDefault(); // don't blur
15
+ const onMouseDown = () => {
21
16
  if (!host.matches(':focus-within')) {
22
- // if input not focused
23
- focus(); // focus input
17
+ host.focus();
24
18
  }
25
19
  };
26
20
  root.addEventListener('mousedown', onMouseDown);
27
21
  return () => root.removeEventListener('mousedown', onMouseDown);
28
- }, [focus]);
22
+ }, []);
29
23
  return {
30
24
  onChange,
31
25
  onFocus,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-input",
3
- "version": "5.5.1",
3
+ "version": "5.6.0",
4
4
  "description": "A input web component",
5
5
  "keywords": [
6
6
  "lit-html",
@@ -17,18 +17,17 @@
17
17
  "license": "Apache-2.0",
18
18
  "author": "",
19
19
  "main": "dist/index.js",
20
- "directories": {
21
- "test": "test"
22
- },
23
20
  "files": [
24
21
  "dist/"
25
22
  ],
26
23
  "scripts": {
27
24
  "lint": "tsc && eslint --cache .",
25
+ "check:duplicates": "check-duplicate-components",
28
26
  "build": "tsc -p tsconfig.build.json",
29
27
  "start": "wds",
30
- "test": "wtr --coverage",
31
- "test:watch": "wtr --watch",
28
+ "test": "vitest --run",
29
+ "test:storybook": "vitest --project=storybook --run",
30
+ "test:watch": "vitest",
32
31
  "prepare": "husky",
33
32
  "storybook:start": "storybook dev -p 8000",
34
33
  "storybook:build": "storybook build",
@@ -77,16 +76,25 @@
77
76
  "devDependencies": {
78
77
  "@commitlint/cli": "^20.0.0",
79
78
  "@commitlint/config-conventional": "^20.0.0",
80
- "@neovici/cfg": "^2.0.0",
81
- "@open-wc/testing": "^4.0.0",
79
+ "@neovici/cfg": "^2.8.0",
80
+ "@neovici/testing": "^2.3.0",
81
+ "@playwright/test": "^1.58.1",
82
82
  "@semantic-release/changelog": "^6.0.0",
83
83
  "@semantic-release/git": "^10.0.0",
84
- "@storybook/web-components-vite": "^10.0.0",
85
- "@types/mocha": "^10.0.3",
84
+ "@storybook/addon-docs": "^10.0.0",
85
+ "@storybook/addon-vitest": "^10.2.4",
86
+ "@storybook/web-components-vite": "^10.2.4",
87
+ "@types/node": "^24.0.0",
88
+ "@vitest/browser": "^4.0.18",
89
+ "@vitest/browser-playwright": "^4.0.18",
86
90
  "http-server": "^14.1.1",
87
91
  "husky": "^9.1.7",
92
+ "jsdom": "^26.1.0",
93
+ "lint-staged": "^16.2.7",
88
94
  "semantic-release": "^25.0.2",
95
+ "shadow-dom-testing-library": "^1.13.1",
89
96
  "sinon": "^21.0.0",
90
- "storybook": "^10.1.9"
97
+ "storybook": "^10.1.9",
98
+ "vitest": "^4.0.18"
91
99
  }
92
100
  }