@digital-realty/ix-multi-select 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 ix-multi-select
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # \<ix-multi-select>
2
+
3
+ This webcomponent follows the [open-wc](https://github.com/open-wc/open-wc) recommendation.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i ix-multi-select
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import 'ix-multi-select/ix-multi-select.js';
16
+ const items = [
17
+ 'item 1',
18
+ 'item 2'
19
+ ]
20
+ </script>
21
+
22
+ <ix-multi-select items=${items}></ix-multi-select>
23
+ ```
24
+
25
+ ## Linting and formatting
26
+
27
+ To scan the project for linting and formatting errors, run
28
+
29
+ ```bash
30
+ npm run lint
31
+ ```
32
+
33
+ To automatically fix linting and formatting errors, run
34
+
35
+ ```bash
36
+ npm run format
37
+ ```
38
+
39
+ ## Testing with Web Test Runner
40
+
41
+ To execute a single test run:
42
+
43
+ ```bash
44
+ npm run test
45
+ ```
46
+
47
+ To run the tests in interactive watch mode run:
48
+
49
+ ```bash
50
+ npm run test:watch
51
+ ```
52
+
53
+
54
+ ## Tooling configs
55
+
56
+ For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
57
+
58
+ If you customize the configuration a lot, you can consider moving them to individual files.
59
+
60
+ ## Local Demo with `web-dev-server`
61
+
62
+ ```bash
63
+ npm start
64
+ ```
65
+
66
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,31 @@
1
+ import { LitElement } from 'lit';
2
+ import '@digital-realty/ix-chip/ix-chip-set.js';
3
+ import '@digital-realty/ix-chip/ix-chip.js';
4
+ import '@digital-realty/ix-field/ix-field.js';
5
+ import '@digital-realty/ix-menu/ix-menu.js';
6
+ import '@digital-realty/ix-menu/ix-menu-item.js';
7
+ import '@digital-realty/ix-icon-button/ix-icon-button.js';
8
+ import { IxMenu } from '@digital-realty/ix-menu';
9
+ export declare class IxMultiSelect extends LitElement {
10
+ static get styles(): import("lit").CSSResult[];
11
+ menu: IxMenu;
12
+ inputFilter: HTMLInputElement;
13
+ items: string[];
14
+ label: string;
15
+ private _items;
16
+ private filterValue;
17
+ private menuOpen;
18
+ private focused;
19
+ private noFilteredOptions;
20
+ get value(): string[];
21
+ firstUpdated(): void;
22
+ private optionSelect;
23
+ private chipRemove;
24
+ private filterOptions;
25
+ focusin: () => void;
26
+ handleMenuOpen: () => void;
27
+ handleMenuClose: () => void;
28
+ toggleOpen: (e: Event) => void;
29
+ clear: (e: Event) => void;
30
+ render(): import("lit").TemplateResult<1>;
31
+ }
@@ -0,0 +1,189 @@
1
+ import { __decorate } from "tslib";
2
+ import { html, LitElement, nothing } from 'lit';
3
+ import { property, query, state } from 'lit/decorators.js';
4
+ import '@digital-realty/ix-chip/ix-chip-set.js';
5
+ import '@digital-realty/ix-chip/ix-chip.js';
6
+ import '@digital-realty/ix-field/ix-field.js';
7
+ import '@digital-realty/ix-menu/ix-menu.js';
8
+ import '@digital-realty/ix-menu/ix-menu-item.js';
9
+ import '@digital-realty/ix-icon-button/ix-icon-button.js';
10
+ import { IxMultiSelectStyles } from './ix-multi-select-styles.js';
11
+ export class IxMultiSelect extends LitElement {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.items = [];
15
+ this.label = '';
16
+ this._items = [];
17
+ this.filterValue = '';
18
+ this.menuOpen = false;
19
+ this.focused = false;
20
+ this.noFilteredOptions = 'No options';
21
+ this.optionSelect = (e, id) => {
22
+ const ischecked = e.target.checked;
23
+ this._items = this._items.map((item, i) => id === i
24
+ ? { ...item, selected: ischecked, filtered: false }
25
+ : { ...item, filtered: false });
26
+ this.filterValue = '';
27
+ };
28
+ this.chipRemove = (id) => {
29
+ this._items = this._items.map((item, i) => id === i ? { ...item, selected: false } : { ...item });
30
+ };
31
+ this.filterOptions = (e) => {
32
+ const filterValue = e.target.value.toLocaleLowerCase();
33
+ this.filterValue = filterValue;
34
+ this._items = this._items.map(item => {
35
+ const filtered = item.label.toLowerCase().indexOf(filterValue) === -1;
36
+ return { ...item, filtered };
37
+ });
38
+ };
39
+ this.focusin = () => {
40
+ this.menu.show();
41
+ this.focused = true;
42
+ };
43
+ this.handleMenuOpen = () => {
44
+ var _a;
45
+ this.focused = true;
46
+ this.menuOpen = true;
47
+ const innerMenu = (_a = this.menu.shadowRoot) === null || _a === void 0 ? void 0 : _a.querySelector('.menu');
48
+ if (innerMenu) {
49
+ innerMenu.style.width = '100%';
50
+ innerMenu.style.insetBlockStart = '0';
51
+ }
52
+ };
53
+ this.handleMenuClose = () => {
54
+ if (this.value.length === 0) {
55
+ this.focused = false;
56
+ }
57
+ this.menuOpen = false;
58
+ };
59
+ this.toggleOpen = (e) => {
60
+ e.stopPropagation();
61
+ if (!this.menuOpen) {
62
+ this.focusin();
63
+ }
64
+ else {
65
+ this.menu.close();
66
+ }
67
+ };
68
+ this.clear = (e) => {
69
+ e.stopPropagation();
70
+ this._items = this._items.map(item => ({ ...item, selected: false }));
71
+ };
72
+ }
73
+ static get styles() {
74
+ return [IxMultiSelectStyles];
75
+ }
76
+ get value() {
77
+ return this._items.filter(item => item.selected).map(item => item.label);
78
+ }
79
+ firstUpdated() {
80
+ this._items = this.items.map(el => ({
81
+ label: el,
82
+ selected: false,
83
+ filtered: false,
84
+ }));
85
+ }
86
+ render() {
87
+ return html `
88
+ <div class="multi-select">
89
+ <ix-field
90
+ id="anchor"
91
+ .focused=${this.focused}
92
+ label=${this.label}
93
+ @click=${() => this.inputFilter.focus()}
94
+ >
95
+ <ix-chip-set>
96
+ ${this._items.map((item, id) => item.selected
97
+ ? html `<span
98
+ ><ix-chip
99
+ @remove=${() => this.chipRemove(id)}
100
+ label=${item.label}
101
+ appearance="input"
102
+ removable
103
+ remove-only
104
+ ></ix-chip
105
+ ></span>`
106
+ : nothing)}
107
+ <input
108
+ id="filter"
109
+ @input=${this.filterOptions}
110
+ @focus=${this.focusin}
111
+ .value=${this.filterValue}
112
+ class="flex-fill"
113
+ type="text"
114
+ />
115
+ </ix-chip-set>
116
+ <slot name="end" slot="end">
117
+ ${this.value.length
118
+ ? html `<ix-icon-button
119
+ @click=${this.clear}
120
+ icon="close"
121
+ aria-label="clear"
122
+ ></ix-icon-button>`
123
+ : nothing}
124
+ <ix-icon-button
125
+ @click=${this.toggleOpen}
126
+ class="open-icon"
127
+ icon=${`arrow_drop_${this.menuOpen ? 'up' : 'down'}`}
128
+ aria-label="options"
129
+ ></ix-icon-button>
130
+ </slot>
131
+ </ix-field>
132
+ <div class="menu">
133
+ <ix-menu
134
+ anchor="anchor"
135
+ skip-restore-focus
136
+ quick
137
+ @opening=${this.handleMenuOpen}
138
+ @closing=${this.handleMenuClose}
139
+ >
140
+ ${this._items.filter(item => !item.filtered).length
141
+ ? this._items.map((item, id) => html `${!item.filtered
142
+ ? html `<ix-menu-item
143
+ keep-open
144
+ class=${item.selected ? 'selected' : ''}
145
+ >
146
+ <div slot="headline">
147
+ <label>
148
+ <input
149
+ type="checkbox"
150
+ @change=${(e) => this.optionSelect(e, id)}
151
+ .checked=${item.selected}
152
+ />
153
+ ${item.label}
154
+ </label>
155
+ </div>
156
+ </ix-menu-item>`
157
+ : nothing}`)
158
+ : html `<ix-menu-item>${this.noFilteredOptions}</ix-menu-item>`}
159
+ </ix-menu>
160
+ </div>
161
+ </div>
162
+ `;
163
+ }
164
+ }
165
+ __decorate([
166
+ query('ix-menu')
167
+ ], IxMultiSelect.prototype, "menu", void 0);
168
+ __decorate([
169
+ query('#filter')
170
+ ], IxMultiSelect.prototype, "inputFilter", void 0);
171
+ __decorate([
172
+ property({ type: Array })
173
+ ], IxMultiSelect.prototype, "items", void 0);
174
+ __decorate([
175
+ property({ type: String })
176
+ ], IxMultiSelect.prototype, "label", void 0);
177
+ __decorate([
178
+ state()
179
+ ], IxMultiSelect.prototype, "_items", void 0);
180
+ __decorate([
181
+ state()
182
+ ], IxMultiSelect.prototype, "filterValue", void 0);
183
+ __decorate([
184
+ state()
185
+ ], IxMultiSelect.prototype, "menuOpen", void 0);
186
+ __decorate([
187
+ state()
188
+ ], IxMultiSelect.prototype, "focused", void 0);
189
+ //# sourceMappingURL=IxMultiSelect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IxMultiSelect.js","sourceRoot":"","sources":["../src/IxMultiSelect.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,KAAK,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,wCAAwC,CAAC;AAChD,OAAO,oCAAoC,CAAC;AAC5C,OAAO,sCAAsC,CAAC;AAC9C,OAAO,o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AQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;4CAAsB;AAEpB;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;4CAAY;AAE9B;IAAR,KAAK,EAAE;6CAAwC;AAEvC;IAAR,KAAK,EAAE;kDAA0B;AAEzB;IAAR,KAAK,EAAE;+CAA0B;AAEzB;IAAR,KAAK,EAAE;8CAAyB","sourcesContent":["import { html, LitElement, nothing } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport '@digital-realty/ix-chip/ix-chip-set.js';\nimport '@digital-realty/ix-chip/ix-chip.js';\nimport '@digital-realty/ix-field/ix-field.js';\nimport '@digital-realty/ix-menu/ix-menu.js';\nimport '@digital-realty/ix-menu/ix-menu-item.js';\nimport '@digital-realty/ix-icon-button/ix-icon-button.js';\nimport { IxMenu } from '@digital-realty/ix-menu';\nimport { IxMultiSelectStyles } from './ix-multi-select-styles.js';\n\ninterface MultiSelectItem {\n label: string;\n selected: boolean;\n filtered: boolean;\n}\n\nexport class IxMultiSelect extends LitElement {\n static get styles() {\n return [IxMultiSelectStyles];\n }\n\n @query('ix-menu') menu!: IxMenu;\n\n @query('#filter') inputFilter!: HTMLInputElement;\n\n @property({ type: Array }) items: string[] = [];\n\n @property({ type: String }) label = '';\n\n @state() private _items: MultiSelectItem[] = [];\n\n @state() private filterValue = '';\n\n @state() private menuOpen = false;\n\n @state() private focused = false;\n\n private noFilteredOptions = 'No options';\n\n get value() {\n return this._items.filter(item => item.selected).map(item => item.label);\n }\n\n firstUpdated() {\n this._items = this.items.map(el => ({\n label: el,\n selected: false,\n filtered: false,\n }));\n }\n\n private optionSelect = (e: InputEvent, id: number) => {\n const ischecked = (<HTMLInputElement>e.target).checked;\n this._items = this._items.map((item, i: number) =>\n id === i\n ? { ...item, selected: ischecked, filtered: false }\n : { ...item, filtered: false }\n );\n this.filterValue = '';\n };\n\n private chipRemove = (id: number) => {\n this._items = this._items.map((item, i: number) =>\n id === i ? { ...item, selected: false } : { ...item }\n );\n };\n\n private filterOptions = (e: InputEvent) => {\n const filterValue = (<HTMLInputElement>e.target).value.toLocaleLowerCase();\n this.filterValue = filterValue;\n this._items = this._items.map(item => {\n const filtered = item.label.toLowerCase().indexOf(filterValue) === -1;\n return { ...item, filtered };\n });\n };\n\n focusin = () => {\n this.menu.show();\n this.focused = true;\n };\n\n handleMenuOpen = () => {\n this.focused = true;\n this.menuOpen = true;\n const innerMenu = this.menu.shadowRoot?.querySelector(\n '.menu'\n ) as HTMLElement;\n if (innerMenu) {\n innerMenu.style.width = '100%';\n innerMenu.style.insetBlockStart = '0';\n }\n };\n\n handleMenuClose = () => {\n if (this.value.length === 0) {\n this.focused = false;\n }\n this.menuOpen = false;\n };\n\n toggleOpen = (e: Event) => {\n e.stopPropagation();\n if (!this.menuOpen) {\n this.focusin();\n } else {\n this.menu.close();\n }\n };\n\n clear = (e: Event) => {\n e.stopPropagation();\n this._items = this._items.map(item => ({ ...item, selected: false }));\n };\n\n render() {\n return html`\n <div class=\"multi-select\">\n <ix-field\n id=\"anchor\"\n .focused=${this.focused}\n label=${this.label}\n @click=${() => this.inputFilter.focus()}\n >\n <ix-chip-set>\n ${this._items.map((item, id: number) =>\n item.selected\n ? html`<span\n ><ix-chip\n @remove=${() => this.chipRemove(id)}\n label=${item.label}\n appearance=\"input\"\n removable\n remove-only\n ></ix-chip\n ></span>`\n : nothing\n )}\n <input\n id=\"filter\"\n @input=${this.filterOptions}\n @focus=${this.focusin}\n .value=${this.filterValue}\n class=\"flex-fill\"\n type=\"text\"\n />\n </ix-chip-set>\n <slot name=\"end\" slot=\"end\">\n ${this.value.length\n ? html`<ix-icon-button\n @click=${this.clear}\n icon=\"close\"\n aria-label=\"clear\"\n ></ix-icon-button>`\n : nothing}\n <ix-icon-button\n @click=${this.toggleOpen}\n class=\"open-icon\"\n icon=${`arrow_drop_${this.menuOpen ? 'up' : 'down'}`}\n aria-label=\"options\"\n ></ix-icon-button>\n </slot>\n </ix-field>\n <div class=\"menu\">\n <ix-menu\n anchor=\"anchor\"\n skip-restore-focus\n quick\n @opening=${this.handleMenuOpen}\n @closing=${this.handleMenuClose}\n >\n ${this._items.filter(item => !item.filtered).length\n ? this._items.map(\n (item, id: number) =>\n html`${!item.filtered\n ? html`<ix-menu-item\n keep-open\n class=${item.selected ? 'selected' : ''}\n >\n <div slot=\"headline\">\n <label>\n <input\n type=\"checkbox\"\n @change=${(e: InputEvent) =>\n this.optionSelect(e, id)}\n .checked=${item.selected}\n />\n ${item.label}\n </label>\n </div>\n </ix-menu-item>`\n : nothing}`\n )\n : html`<ix-menu-item>${this.noFilteredOptions}</ix-menu-item>`}\n </ix-menu>\n </div>\n </div>\n `;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export { IxMultiSelect } from './IxMultiSelect.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { IxMultiSelect } from './IxMultiSelect.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export { IxMultiSelect } from './IxMultiSelect.js';\n"]}
@@ -0,0 +1 @@
1
+ export declare const IxMultiSelectStyles: import("lit").CSSResult;
@@ -0,0 +1,71 @@
1
+ import { css } from 'lit';
2
+ export const IxMultiSelectStyles = css `
3
+ :host {
4
+ display: block;
5
+ }
6
+ ix-field {
7
+ display: block;
8
+ --md-outlined-field-label-text-color: var(--md-sys-text-color-secondary);
9
+ }
10
+ ix-field label {
11
+ display: none;
12
+ }
13
+ .flex-fill {
14
+ flex: 1;
15
+ }
16
+ .menu {
17
+ position: relative;
18
+ }
19
+ .menu label,
20
+ .menu input {
21
+ cursor: pointer;
22
+ }
23
+ input {
24
+ border: none;
25
+ background: transparent;
26
+ outline: none;
27
+ min-width: 3rem;
28
+ }
29
+ ix-chip-set {
30
+ min-height: var(--_content-line-height);
31
+ }
32
+ ix-menu {
33
+ --md-menu-container-color: #fff;
34
+ }
35
+ ix-menu-item {
36
+ position: relative;
37
+ }
38
+ ix-menu-item label {
39
+ display: flex;
40
+ align-items: center;
41
+ position: absolute;
42
+ top: 0;
43
+ left: 0;
44
+ right: 0;
45
+ bottom: 0;
46
+ }
47
+ ix-menu-item label input[type='checkbox'] {
48
+ margin: 0 1rem 2px;
49
+ }
50
+ ix-menu-item.selected {
51
+ background: var(--md-sys-color-tertiary-container);
52
+ }
53
+ ix-icon-button {
54
+ --md-icon-button-icon-color: var(--md-sys-text-color-secondary);
55
+ --md-icon-button-hover-icon-color: var(--md-sys-text-color-secondary);
56
+ --md-icon-button-hover-state-layer-color: var(
57
+ --md-sys-text-color-secondary
58
+ );
59
+ --md-icon-button-pressed-icon-color: var(--md-sys-text-color-secondary);
60
+ --md-icon-button-pressed-state-layer-color: var(
61
+ --md-sys-text-color-secondary
62
+ );
63
+ }
64
+ .open-icon {
65
+ margin-right: 0.5rem;
66
+ }
67
+ .multi-select {
68
+ position: relative;
69
+ }
70
+ `;
71
+ //# sourceMappingURL=ix-multi-select-styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ix-multi-select-styles.js","sourceRoot":"","sources":["../src/ix-multi-select-styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoErC,CAAC","sourcesContent":["import { css } from 'lit';\n\nexport const IxMultiSelectStyles = css`\n :host {\n display: block;\n }\n ix-field {\n display: block;\n --md-outlined-field-label-text-color: var(--md-sys-text-color-secondary);\n }\n ix-field label {\n display: none;\n }\n .flex-fill {\n flex: 1;\n }\n .menu {\n position: relative;\n }\n .menu label,\n .menu input {\n cursor: pointer;\n }\n input {\n border: none;\n background: transparent;\n outline: none;\n min-width: 3rem;\n }\n ix-chip-set {\n min-height: var(--_content-line-height);\n }\n ix-menu {\n --md-menu-container-color: #fff;\n }\n ix-menu-item {\n position: relative;\n }\n ix-menu-item label {\n display: flex;\n align-items: center;\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n }\n ix-menu-item label input[type='checkbox'] {\n margin: 0 1rem 2px;\n }\n ix-menu-item.selected {\n background: var(--md-sys-color-tertiary-container);\n }\n ix-icon-button {\n --md-icon-button-icon-color: var(--md-sys-text-color-secondary);\n --md-icon-button-hover-icon-color: var(--md-sys-text-color-secondary);\n --md-icon-button-hover-state-layer-color: var(\n --md-sys-text-color-secondary\n );\n --md-icon-button-pressed-icon-color: var(--md-sys-text-color-secondary);\n --md-icon-button-pressed-state-layer-color: var(\n --md-sys-text-color-secondary\n );\n }\n .open-icon {\n margin-right: 0.5rem;\n }\n .multi-select {\n position: relative;\n }\n`;\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { IxMultiSelect } from './IxMultiSelect.js';
2
+ window.customElements.define('ix-multi-select', IxMultiSelect);
3
+ //# sourceMappingURL=ix-multi-select.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ix-multi-select.js","sourceRoot":"","sources":["../src/ix-multi-select.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import { IxMultiSelect } from './IxMultiSelect.js';\n\nwindow.customElements.define('ix-multi-select', IxMultiSelect);\n"]}
package/package.json ADDED
@@ -0,0 +1,101 @@
1
+ {
2
+ "name": "@digital-realty/ix-multi-select",
3
+ "description": "Webcomponent ix-multi-select following open-wc recommendations",
4
+ "license": "MIT",
5
+ "author": "Digital Realty",
6
+ "version": "0.0.1",
7
+ "type": "module",
8
+ "main": "dist/index.js",
9
+ "module": "dist/index.js",
10
+ "exports": {
11
+ ".": "./dist/index.js",
12
+ "./ix-multi-select.js": "./dist/ix-multi-select.js"
13
+ },
14
+ "publishConfig": {
15
+ "access": "public"
16
+ },
17
+ "scripts": {
18
+ "analyze": "cem analyze --litelement",
19
+ "start": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
20
+ "build": "tsc && npm run analyze -- --exclude dist",
21
+ "prepublish": "tsc && npm run analyze -- --exclude dist",
22
+ "lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
23
+ "format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore",
24
+ "test": "tsc && wtr --coverage",
25
+ "test:watch": "tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wtr --watch\""
26
+ },
27
+ "dependencies": {
28
+ "@digital-realty/ix-chip": "^1.0.6",
29
+ "@digital-realty/ix-field": "^0.0.3",
30
+ "@digital-realty/ix-icon-button": "^1.0.13",
31
+ "@digital-realty/ix-menu": "^0.0.4",
32
+ "@digital-realty/theme": "^1.0.6",
33
+ "@material/web": "^1.0.0",
34
+ "lit": "^2.0.2"
35
+ },
36
+ "devDependencies": {
37
+ "@custom-elements-manifest/analyzer": "^0.4.17",
38
+ "@open-wc/eslint-config": "^9.2.1",
39
+ "@open-wc/testing": "^3.1.6",
40
+ "@typescript-eslint/eslint-plugin": "^5.48.0",
41
+ "@typescript-eslint/parser": "^5.48.0",
42
+ "@web/dev-server": "^0.1.34",
43
+ "@web/test-runner": "^0.14.0",
44
+ "concurrently": "^5.3.0",
45
+ "eslint": "^8.31.0",
46
+ "eslint-config-prettier": "^8.3.0",
47
+ "husky": "^4.3.8",
48
+ "lint-staged": "^10.5.4",
49
+ "prettier": "^2.4.1",
50
+ "tslib": "^2.3.1",
51
+ "typescript": "^4.5.2"
52
+ },
53
+ "customElements": "custom-elements.json",
54
+ "eslintConfig": {
55
+ "parser": "@typescript-eslint/parser",
56
+ "extends": [
57
+ "@open-wc",
58
+ "prettier"
59
+ ],
60
+ "plugins": [
61
+ "@typescript-eslint"
62
+ ],
63
+ "rules": {
64
+ "no-unused-vars": "off",
65
+ "@typescript-eslint/no-unused-vars": [
66
+ "error"
67
+ ],
68
+ "import/no-unresolved": "off",
69
+ "import/extensions": [
70
+ "error",
71
+ "always",
72
+ {
73
+ "ignorePackages": true
74
+ }
75
+ ]
76
+ }
77
+ },
78
+ "prettier": {
79
+ "singleQuote": true,
80
+ "arrowParens": "avoid"
81
+ },
82
+ "husky": {
83
+ "hooks": {
84
+ "pre-commit": "lint-staged"
85
+ }
86
+ },
87
+ "lint-staged": {
88
+ "*.ts": [
89
+ "eslint --fix",
90
+ "prettier --write"
91
+ ]
92
+ },
93
+ "files": [
94
+ "/dist",
95
+ "!/dist/test",
96
+ "package.json",
97
+ "README.md",
98
+ "LICENSE"
99
+ ],
100
+ "gitHead": "6cd64253a78e37e6ba8882a8c94e6cae73d82d51"
101
+ }