@neovici/cosmoz-autocomplete 3.2.0 → 4.0.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.
package/cosmoz-listbox.js CHANGED
@@ -1,14 +1,93 @@
1
1
  import { html, component, useEffect } from 'haunted';
2
- import { scroll } from 'lit-virtualizer';
2
+ import { virtualize } from '@lit-labs/virtualizer/virtualize.js';
3
+ import { tagged as css } from '@neovici/cosmoz-utils';
3
4
  import { portal } from '@neovici/cosmoz-utils/lib/directives/portal';
5
+ import { spreadProps } from '@neovici/cosmoz-utils/lib/directives/spread-props';
4
6
  import { props } from '@neovici/cosmoz-utils/lib/object';
5
- import { spreadProps } from '@open-wc/lit-helpers';
6
7
  import { useListbox, properties } from './lib/use-listbox';
7
8
  import { scrollIntoViewIfNeeded } from './lib/utils';
8
9
 
9
10
  const svg =
10
11
  'data:image/svg+xml,%3Csvg width=\'11\' height=\'8\' viewBox=\'0 0 11 8\' fill=\'none\' xmlns=\'http://www.w3.org/2000/svg\'%3E%3Cpath ' +
11
12
  'd=\'M9.5 1L5.20039 7.04766L1.66348 3.46152\' stroke=\'white\' stroke-width=\'1.5\' stroke-linecap=\'round\' stroke-linejoin=\'round\'/%3E%3C/svg%3E',
13
+ styles = ({ index, height, itemHeight }) => css`
14
+ :host {
15
+ position: fixed;
16
+ min-height: ${itemHeight}px;
17
+ z-index: 1000;
18
+ height: ${height}px;
19
+ font-family: var(--paper-font-subhead_-_font-family, initial);
20
+ background: #fff;
21
+ min-width: 72px;
22
+ box-shadow: 0 3px 4px 0 rgba(0, 0, 0, 0.14),
23
+ 0 1px 8px 0 rgba(0, 0, 0, 0.12), 0 3px 3px -2px rgba(0, 0, 0, 0.4);
24
+ }
25
+ .items {
26
+ position: relative;
27
+ overflow-y: auto;
28
+ contain: layout paint !important;
29
+ height: 100%;
30
+ }
31
+ .item {
32
+ font-size: 14px;
33
+ line-height: ${itemHeight}px;
34
+ height: ${itemHeight}px;
35
+ padding: 0 20px;
36
+ box-sizing: border-box;
37
+ width: 100%;
38
+ cursor: pointer;
39
+ text-overflow: ellipsis;
40
+ white-space: nowrap;
41
+ transition: background 0.2s;
42
+ color: var(--cosmoz-listbox-color, #101010);
43
+ }
44
+
45
+ .item[data-index="${index || '0'}"] {
46
+ background: var(
47
+ --cosmoz-listbox-active-color,
48
+ var(--cosmoz-selection-color, rgba(58, 145, 226, 0.1))
49
+ );
50
+ }
51
+ .sizer {
52
+ position: relative;
53
+ visibility: hidden;
54
+ opacity: 0;
55
+ pointer-events: none;
56
+ z-index: -1;
57
+ height: 0;
58
+ width: auto;
59
+ padding: 0 20px;
60
+ overflow: hidden;
61
+ max-width: inherit;
62
+ font-size: 14px;
63
+ }
64
+
65
+ :host(:not([multi])) .item[aria-selected] {
66
+ background: var(--cosmoz-listbox-single-selection-color, #dadada);
67
+ }
68
+
69
+ :host([multi]) .item {
70
+ padding-left: 0;
71
+ }
72
+ :host([multi]) .item::before {
73
+ content: '';
74
+ font-size: 0;
75
+ padding: 7.5px;
76
+ margin: 0 8px;
77
+ background: #fff;
78
+ border: 1px solid #d6d6d5;
79
+ border-radius: 4px;
80
+ vertical-align: top;
81
+ }
82
+ :host([multi]) .item[aria-selected]::before {
83
+ border-color: #5881f6;
84
+ /* prettier-ignore */
85
+ background: url("${svg}") #5881f6 no-repeat 50%;
86
+ }
87
+ :host([multi]) .sizer {
88
+ padding-left: 33px;
89
+ }
90
+ `,
12
91
  Listbox = (host) => {
13
92
  const { index, items, renderItem, height, itemHeight } = useListbox(host);
14
93
 
@@ -22,86 +101,12 @@ const svg =
22
101
  }, [index]);
23
102
 
24
103
  return html` <style>
25
- :host {
26
- position: fixed;
27
- min-height: ${itemHeight}px;
28
- z-index: 1000;
29
- height: ${height}px;
30
- font-family: var(--paper-font-subhead_-_font-family, initial);
31
- background: #fff;
32
- min-width: 72px;
33
- box-shadow: 0 3px 4px 0 rgba(0, 0, 0, 0.14),
34
- 0 1px 8px 0 rgba(0, 0, 0, 0.12), 0 3px 3px -2px rgba(0, 0, 0, 0.4);
35
- }
36
- .items {
37
- position: relative;
38
- overflow-y: auto;
39
- height: 100%;
40
- }
41
- .item {
42
- font-size: 14px;
43
- line-height: ${itemHeight}px;
44
- height: ${itemHeight}px;
45
- padding: 0 20px;
46
- box-sizing: border-box;
47
- width: 100%;
48
- cursor: pointer;
49
- overflow: hidden;
50
- text-overflow: ellipsis;
51
- white-space: nowrap;
52
- transition: background 0.2s;
53
- color: var(--cosmoz-listbox-color, #101010);
54
- }
55
-
56
- .item[data-index='${index}'] {
57
- background: var(
58
- --cosmoz-listbox-active-color,
59
- var(--cosmoz-selection-color, rgba(58, 145, 226, 0.1))
60
- );
61
- }
62
- .sizer {
63
- position: relative;
64
- visibility: hidden;
65
- opacity: 0;
66
- pointer-events: none;
67
- z-index: -1;
68
- height: 0;
69
- width: auto;
70
- padding: 0 20px;
71
- overflow: hidden;
72
- max-width: inherit;
73
- font-size: 14px;
74
- }
75
- .items > :first-child {
76
- line-height: 1;
77
- }
78
-
79
- :host(:not([multi])) .item[aria-selected] {
80
- background: var(--cosmoz-listbox-single-selection-color, #dadada);
81
- }
82
-
83
- :host([multi]) .item {
84
- padding-left: 0;
85
- }
86
- :host([multi]) .item::before {
87
- content: '';
88
- font-size: 0;
89
- padding: 7.5px;
90
- margin: 0 8px;
91
- background: #fff;
92
- border: 1px solid #d6d6d5;
93
- border-radius: 4px;
94
- vertical-align: top;
95
- }
96
- :host([multi]) .item[aria-selected]::before {
97
- border-color: #5881f6;
98
- background: url("${svg}") #5881f6 no-repeat 50%;
99
- }
100
- :host([multi]) .sizer {
101
- padding-left: 33px;
102
- }
104
+ ${styles({ index, height, itemHeight })}
103
105
  </style>
104
- <div class="items">${scroll({ items, renderItem })}</div>`;
106
+ <div class="items">
107
+ <div virtualizer-sizer></div>
108
+ ${virtualize({ items, renderItem, scroller: true })}
109
+ </div>`;
105
110
  };
106
111
 
107
112
  customElements.define('cosmoz-listbox', component(Listbox));
@@ -1,6 +1,6 @@
1
1
  import { html, nothing } from 'lit-html'; // eslint-disable-line object-curly-newline
2
- import { live } from 'lit-html/directives/live';
3
- import { until } from 'lit-html/directives/until';
2
+ import { live } from 'lit-html/directives/live.js';
3
+ import { until } from 'lit-html/directives/until.js';
4
4
  import { useCallback } from 'haunted';
5
5
  import { useHost } from '@neovici/cosmoz-utils/lib/hooks/use-host';
6
6
  import { array } from '@neovici/cosmoz-utils/lib/array';
@@ -23,5 +23,5 @@ export default (
23
23
  @mousedown=${ e => e.preventDefault() }
24
24
  title=${ text }
25
25
  >${ content }</div>
26
- <div class="sizer">${ content }</div>`;
26
+ <div class="sizer" virtualizer-sizer>${ content }</div>`;
27
27
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neovici/cosmoz-autocomplete",
3
- "version": "3.2.0",
3
+ "version": "4.0.0",
4
4
  "description": "A autocomplete input web component",
5
5
  "keywords": [
6
6
  "lit-html",
@@ -23,10 +23,9 @@
23
23
  "scripts": {
24
24
  "lint": "eslint --cache --ext .js .",
25
25
  "lint-tsc": "tsc",
26
- "start": "npm run storybook",
26
+ "start": "wds",
27
27
  "test": "wtr --coverage",
28
28
  "test:watch": "wtr --watch",
29
- "storybook": "start-storybook --node-resolve --watch --open",
30
29
  "storybook:build": "build-storybook",
31
30
  "storybook:deploy": "storybook-to-ghpages",
32
31
  "prepare": "husky install"
@@ -53,30 +52,36 @@
53
52
  "commitlint": {
54
53
  "extends": [
55
54
  "@commitlint/config-conventional"
56
- ]
55
+ ],
56
+ "rules": {
57
+ "body-max-line-length": [
58
+ 1,
59
+ "always",
60
+ 100
61
+ ]
62
+ }
57
63
  },
58
64
  "dependencies": {
59
- "@neovici/cosmoz-input": "^1.5.0",
60
- "@neovici/cosmoz-utils": "^3.20.0",
61
- "@open-wc/lit-helpers": "^0.3.12",
62
- "haunted": "^4.7.0",
63
- "lit-html": "^1.4.0",
64
- "lit-virtualizer": "^0.4.2",
65
+ "@lit-labs/virtualizer": "^0.7.0",
66
+ "@neovici/cosmoz-dropdown": "^2.0.0",
67
+ "@neovici/cosmoz-input": "^2.0.0",
68
+ "@neovici/cosmoz-utils": "^4.0.0",
69
+ "haunted": "^5.0.0",
70
+ "lit-html": "^2.0.0",
65
71
  "position.js": "^0.3.0"
66
72
  },
67
73
  "devDependencies": {
68
- "@commitlint/cli": "^16.0.0",
69
- "@commitlint/config-conventional": "^16.0.0",
74
+ "@commitlint/cli": "^17.0.0",
75
+ "@commitlint/config-conventional": "^17.0.0",
70
76
  "@neovici/cfg": "^1.13.0",
71
- "@neovici/cosmoz-dropdown": "^1.8.0",
72
- "@open-wc/demoing-storybook": "^2.1.0",
73
- "@open-wc/testing": "^2.5.32",
77
+ "@open-wc/testing": "^3.0.0",
74
78
  "@semantic-release/changelog": "^6.0.0",
75
79
  "@semantic-release/git": "^10.0.0",
76
80
  "@storybook/storybook-deployer": "^2.8.5",
77
- "husky": "^7.0.0",
81
+ "@web/dev-server-storybook": "^0.5.1",
82
+ "husky": "^8.0.0",
78
83
  "semantic-release": "^19.0.0",
79
- "sinon": "^13.0.0",
84
+ "sinon": "^14.0.0",
80
85
  "typescript": "^4.6.0"
81
86
  }
82
87
  }