@neovici/cosmoz-input 5.5.1 → 5.6.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.
@@ -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/styles.js CHANGED
@@ -69,6 +69,7 @@ export const styles = css `
69
69
  line-height: var(--line-height);
70
70
  font-family: var(--font-family);
71
71
  caret-color: var(--focused-color);
72
+ cursor: text;
72
73
  }
73
74
 
74
75
  :host([disabled]) {
@@ -128,6 +129,7 @@ export const styles = css `
128
129
  text-transform: var(--cosmoz-input-label-text-transform);
129
130
  font-weight: var(--cosmoz-input-label-font-weight);
130
131
  user-select: none;
132
+ cursor: text;
131
133
  }
132
134
 
133
135
  .wrap:has(#input:not(:placeholder-shown)) {
package/dist/use-input.js CHANGED
@@ -1,31 +1,27 @@
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
15
  const onMouseDown = (e) => {
15
- if (e.defaultPrevented ||
16
- host.disabled ||
17
- e.target.matches('input, textarea, label')) {
16
+ const target = e.composedPath()[0];
17
+ if (target?.closest?.('input, textarea'))
18
18
  return;
19
- }
20
- e.preventDefault(); // don't blur
21
- if (!host.matches(':focus-within')) {
22
- // if input not focused
23
- focus(); // focus input
24
- }
19
+ e.preventDefault();
20
+ inputRef.current?.focus();
25
21
  };
26
22
  root.addEventListener('mousedown', onMouseDown);
27
23
  return () => root.removeEventListener('mousedown', onMouseDown);
28
- }, [focus]);
24
+ }, []);
29
25
  return {
30
26
  onChange,
31
27
  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.1",
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": "^25.2.3",
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": "^28.0.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
  }