@spectrum-web-components/tags 0.8.6 → 0.8.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/tags",
3
- "version": "0.8.6",
3
+ "version": "0.8.9",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -46,20 +46,20 @@
46
46
  "lit-html"
47
47
  ],
48
48
  "dependencies": {
49
- "@spectrum-web-components/base": "^0.5.3",
50
- "@spectrum-web-components/button": "^0.17.0",
51
- "@spectrum-web-components/reactive-controllers": "^0.2.1",
52
- "@spectrum-web-components/shared": "^0.13.5",
49
+ "@spectrum-web-components/base": "^0.5.5",
50
+ "@spectrum-web-components/button": "^0.17.3",
51
+ "@spectrum-web-components/reactive-controllers": "^0.2.2",
52
+ "@spectrum-web-components/shared": "^0.14.0",
53
53
  "tslib": "^2.0.0"
54
54
  },
55
55
  "devDependencies": {
56
- "@spectrum-css/tag": "^3.3.3",
57
- "@spectrum-css/taggroup": "^3.3.3"
56
+ "@spectrum-css/tag": "^3.3.9",
57
+ "@spectrum-css/taggroup": "^3.3.9"
58
58
  },
59
59
  "types": "./src/index.d.ts",
60
60
  "customElements": "custom-elements.json",
61
61
  "sideEffects": [
62
62
  "./sp-*.js"
63
63
  ],
64
- "gitHead": "57aba8030b6af96af4015a0aa830e342a17dc219"
64
+ "gitHead": "bdff893e2b95aba7737c58d01c6ac68861cb8b2e"
65
65
  }
package/sp-tag.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Tag } from './src/Tag.js';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'sp-tag': Tag;
5
+ }
6
+ }
package/sp-tag.js ADDED
@@ -0,0 +1,14 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { Tag } from './src/Tag.js';
13
+ customElements.define('sp-tag', Tag);
14
+ //# sourceMappingURL=sp-tag.js.map
package/sp-tag.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sp-tag.js","sourceRoot":"","sources":["sp-tag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAEnC,cAAc,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { Tag } from './src/Tag.js';\n\ncustomElements.define('sp-tag', Tag);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-tag': Tag;\n }\n}\n"]}
package/sp-tags.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import { Tags } from './src/Tags.js';
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ 'sp-tags': Tags;
5
+ }
6
+ }
package/sp-tags.js ADDED
@@ -0,0 +1,14 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { Tags } from './src/Tags.js';
13
+ customElements.define('sp-tags', Tags);
14
+ //# sourceMappingURL=sp-tags.js.map
package/sp-tags.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sp-tags.js","sourceRoot":"","sources":["sp-tags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AACF,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\nimport { Tags } from './src/Tags.js';\n\ncustomElements.define('sp-tags', Tags);\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'sp-tags': Tags;\n }\n}\n"]}
package/src/Tag.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { CSSResultArray, PropertyValues, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
2
+ import '@spectrum-web-components/button/sp-clear-button.js';
3
+ declare const Tag_base: typeof SpectrumElement & {
4
+ new (...args: any[]): import("@spectrum-web-components/base").SizedElementInterface;
5
+ prototype: import("@spectrum-web-components/base").SizedElementInterface;
6
+ };
7
+ /**
8
+ * @element sp-tag
9
+ *
10
+ * @slot - text content for labeling the tag
11
+ * @slot avatar - an avatar element to display within the Tag
12
+ * @slot icon - an icon element to display within the Tag
13
+ */
14
+ export declare class Tag extends Tag_base {
15
+ static get styles(): CSSResultArray;
16
+ deletable: boolean;
17
+ disabled: boolean;
18
+ readonly: boolean;
19
+ private get hasIcon();
20
+ private get hasAvatar();
21
+ constructor();
22
+ private handleFocusin;
23
+ private handleFocusout;
24
+ private handleKeydown;
25
+ private delete;
26
+ protected render(): TemplateResult;
27
+ protected firstUpdated(changes: PropertyValues): void;
28
+ protected updated(changes: PropertyValues): void;
29
+ }
30
+ export {};
package/src/Tag.js ADDED
@@ -0,0 +1,135 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { __decorate } from "tslib";
13
+ import { html, SizedMixin, SpectrumElement, } from '@spectrum-web-components/base';
14
+ import { property } from '@spectrum-web-components/base/src/decorators.js';
15
+ import '@spectrum-web-components/button/sp-clear-button.js';
16
+ import styles from './tag.css.js';
17
+ /**
18
+ * @element sp-tag
19
+ *
20
+ * @slot - text content for labeling the tag
21
+ * @slot avatar - an avatar element to display within the Tag
22
+ * @slot icon - an icon element to display within the Tag
23
+ */
24
+ export class Tag extends SizedMixin(SpectrumElement, {
25
+ validSizes: ['s', 'm', 'l'],
26
+ }) {
27
+ constructor() {
28
+ super();
29
+ this.deletable = false;
30
+ this.disabled = false;
31
+ this.readonly = false;
32
+ this.handleFocusin = () => {
33
+ this.addEventListener('focusout', this.handleFocusout);
34
+ this.addEventListener('keydown', this.handleKeydown);
35
+ };
36
+ this.handleFocusout = () => {
37
+ this.removeEventListener('keydown', this.handleKeydown);
38
+ this.removeEventListener('focusout', this.handleFocusout);
39
+ };
40
+ this.handleKeydown = (event) => {
41
+ if (!this.deletable) {
42
+ return;
43
+ }
44
+ const { code } = event;
45
+ switch (code) {
46
+ case 'Backspace':
47
+ case 'Space':
48
+ case 'Delete':
49
+ this.delete();
50
+ return;
51
+ default:
52
+ return;
53
+ }
54
+ };
55
+ this.addEventListener('focusin', this.handleFocusin);
56
+ }
57
+ static get styles() {
58
+ return [styles];
59
+ }
60
+ get hasIcon() {
61
+ return !!this.querySelector('[slot="icon"]');
62
+ }
63
+ get hasAvatar() {
64
+ return !!this.querySelector('[slot="avatar"]');
65
+ }
66
+ delete() {
67
+ if (this.readonly) {
68
+ return;
69
+ }
70
+ this.dispatchEvent(new Event('delete', {
71
+ bubbles: true,
72
+ }));
73
+ }
74
+ render() {
75
+ const slots = [];
76
+ if (this.hasAvatar) {
77
+ slots.push(html `
78
+ <slot name="avatar"></slot>
79
+ `);
80
+ }
81
+ if (this.hasIcon) {
82
+ slots.push(html `
83
+ <slot name="icon"></slot>
84
+ `);
85
+ }
86
+ return html `
87
+ ${slots}
88
+ <span class="label"><slot></slot></span>
89
+ ${this.deletable
90
+ ? html `
91
+ <sp-clear-button
92
+ class="clear-button"
93
+ ?disabled=${this.disabled}
94
+ label="Remove"
95
+ size="s"
96
+ tabindex="-1"
97
+ @click=${this.delete}
98
+ ></sp-clear-button>
99
+ `
100
+ : html ``}
101
+ `;
102
+ }
103
+ firstUpdated(changes) {
104
+ super.firstUpdated(changes);
105
+ if (!this.hasAttribute('role')) {
106
+ this.setAttribute('role', 'listitem');
107
+ }
108
+ if (this.deletable) {
109
+ this.setAttribute('tabindex', !this.disabled && this.matches(':first-of-type:not([disabled])')
110
+ ? '0'
111
+ : '-1');
112
+ }
113
+ }
114
+ updated(changes) {
115
+ super.updated(changes);
116
+ if (changes.has('disabled')) {
117
+ if (this.disabled) {
118
+ this.setAttribute('aria-disabled', 'true');
119
+ }
120
+ else {
121
+ this.removeAttribute('aria-disabled');
122
+ }
123
+ }
124
+ }
125
+ }
126
+ __decorate([
127
+ property({ type: Boolean, reflect: true })
128
+ ], Tag.prototype, "deletable", void 0);
129
+ __decorate([
130
+ property({ type: Boolean, reflect: true })
131
+ ], Tag.prototype, "disabled", void 0);
132
+ __decorate([
133
+ property({ type: Boolean, reflect: true })
134
+ ], Tag.prototype, "readonly", void 0);
135
+ //# sourceMappingURL=Tag.js.map
package/src/Tag.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tag.js","sourceRoot":"","sources":["Tag.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAEH,IAAI,EAEJ,UAAU,EACV,eAAe,GAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,iDAAiD,CAAC;AAE3E,OAAO,oDAAoD,CAAC;AAE5D,OAAO,MAAM,MAAM,cAAc,CAAC;AAElC;;;;;;GAMG;AACH,MAAM,OAAO,GAAI,SAAQ,UAAU,CAAC,eAAe,EAAE;IACjD,UAAU,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;CAC9B,CAAC;IAsBE;QACI,KAAK,EAAE,CAAC;QAjBL,cAAS,GAAG,KAAK,CAAC;QAGlB,aAAQ,GAAG,KAAK,CAAC;QAGjB,aAAQ,GAAG,KAAK,CAAC;QAehB,kBAAa,GAAG,GAAS,EAAE;YAC/B,IAAI,CAAC,gBAAgB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;YACvD,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QACzD,CAAC,CAAC;QAEM,mBAAc,GAAG,GAAS,EAAE;YAChC,IAAI,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;YACxD,IAAI,CAAC,mBAAmB,CAAC,UAAU,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAC9D,CAAC,CA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AC,QAAQ;;;;mCAIhB,IAAI,CAAC,MAAM;;mBAE3B;YACH,CAAC,CAAC,IAAI,CAAA,EAAE;SACf,CAAC;IACN,CAAC;IAES,YAAY,CAAC,OAAuB;QAC1C,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;YAC5B,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;SACzC;QACD,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,IAAI,CAAC,YAAY,CACb,UAAU,EACV,CAAC,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,OAAO,CAAC,gCAAgC,CAAC;gBAC5D,CAAC,CAAC,GAAG;gBACL,CAAC,CAAC,IAAI,CACb,CAAC;SACL;IACL,CAAC;IAES,OAAO,CAAC,OAAuB;QACrC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE;YACzB,IAAI,IAAI,CAAC,QAAQ,EAAE;gBACf,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,CAAC,CAAC;aAC9C;iBAAM;gBACH,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;aACzC;SACJ;IACL,CAAC;CACJ;AArHG;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;sCAClB;AAGzB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;qCACnB;AAGxB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;qCACnB","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n PropertyValues,\n SizedMixin,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { property } from '@spectrum-web-components/base/src/decorators.js';\n\nimport '@spectrum-web-components/button/sp-clear-button.js';\n\nimport styles from './tag.css.js';\n\n/**\n * @element sp-tag\n *\n * @slot - text content for labeling the tag\n * @slot avatar - an avatar element to display within the Tag\n * @slot icon - an icon element to display within the Tag\n */\nexport class Tag extends SizedMixin(SpectrumElement, {\n validSizes: ['s', 'm', 'l'],\n}) {\n public static get styles(): CSSResultArray {\n return [styles];\n }\n\n @property({ type: Boolean, reflect: true })\n public deletable = false;\n\n @property({ type: Boolean, reflect: true })\n public disabled = false;\n\n @property({ type: Boolean, reflect: true })\n public readonly = false;\n\n private get hasIcon(): boolean {\n return !!this.querySelector('[slot=\"icon\"]');\n }\n\n private get hasAvatar(): boolean {\n return !!this.querySelector('[slot=\"avatar\"]');\n }\n\n constructor() {\n super();\n this.addEventListener('focusin', this.handleFocusin);\n }\n\n private handleFocusin = (): void => {\n this.addEventListener('focusout', this.handleFocusout);\n this.addEventListener('keydown', this.handleKeydown);\n };\n\n private handleFocusout = (): void => {\n this.removeEventListener('keydown', this.handleKeydown);\n this.removeEventListener('focusout', this.handleFocusout);\n };\n\n private handleKeydown = (event: KeyboardEvent): void => {\n if (!this.deletable) {\n return;\n }\n const { code } = event;\n switch (code) {\n case 'Backspace':\n case 'Space':\n case 'Delete':\n this.delete();\n return;\n default:\n return;\n }\n };\n\n private delete(): void {\n if (this.readonly) {\n return;\n }\n this.dispatchEvent(\n new Event('delete', {\n bubbles: true,\n })\n );\n }\n\n protected render(): TemplateResult {\n const slots: TemplateResult[] = [];\n if (this.hasAvatar) {\n slots.push(\n html`\n <slot name=\"avatar\"></slot>\n `\n );\n }\n if (this.hasIcon) {\n slots.push(\n html`\n <slot name=\"icon\"></slot>\n `\n );\n }\n return html`\n ${slots}\n <span class=\"label\"><slot></slot></span>\n ${this.deletable\n ? html`\n <sp-clear-button\n class=\"clear-button\"\n ?disabled=${this.disabled}\n label=\"Remove\"\n size=\"s\"\n tabindex=\"-1\"\n @click=${this.delete}\n ></sp-clear-button>\n `\n : html``}\n `;\n }\n\n protected firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n if (!this.hasAttribute('role')) {\n this.setAttribute('role', 'listitem');\n }\n if (this.deletable) {\n this.setAttribute(\n 'tabindex',\n !this.disabled && this.matches(':first-of-type:not([disabled])')\n ? '0'\n : '-1'\n );\n }\n }\n\n protected updated(changes: PropertyValues): void {\n super.updated(changes);\n if (changes.has('disabled')) {\n if (this.disabled) {\n this.setAttribute('aria-disabled', 'true');\n } else {\n this.removeAttribute('aria-disabled');\n }\n }\n }\n}\n"]}
package/src/Tags.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { CSSResultArray, SpectrumElement, TemplateResult } from '@spectrum-web-components/base';
2
+ import { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';
3
+ import { Tag } from './Tag.js';
4
+ declare const Tags_base: typeof SpectrumElement;
5
+ /**
6
+ * @element sp-tags
7
+ *
8
+ * @slot - Tag elements to manage as a group
9
+ */
10
+ export declare class Tags extends Tags_base {
11
+ static get styles(): CSSResultArray;
12
+ defaultNodes: Node[];
13
+ get tags(): Tag[];
14
+ rovingTabindexController: RovingTabindexController<Tag>;
15
+ constructor();
16
+ focus(): void;
17
+ private handleFocusin;
18
+ private handleKeydown;
19
+ private handleFocusout;
20
+ private handleSlotchange;
21
+ protected render(): TemplateResult;
22
+ protected firstUpdated(): void;
23
+ }
24
+ export {};
package/src/Tags.js ADDED
@@ -0,0 +1,97 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ import { __decorate } from "tslib";
13
+ import { html, SpectrumElement, } from '@spectrum-web-components/base';
14
+ import { queryAssignedNodes } from '@spectrum-web-components/base/src/decorators.js';
15
+ import { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared/src/focus-visible.js';
16
+ import { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';
17
+ import { Tag } from './Tag.js';
18
+ import styles from './tags.css.js';
19
+ /**
20
+ * @element sp-tags
21
+ *
22
+ * @slot - Tag elements to manage as a group
23
+ */
24
+ export class Tags extends FocusVisiblePolyfillMixin(SpectrumElement) {
25
+ constructor() {
26
+ super();
27
+ this.rovingTabindexController = new RovingTabindexController(this, {
28
+ focusInIndex: (elements) => {
29
+ return elements.findIndex((el) => {
30
+ return !el.disabled && el.deletable;
31
+ });
32
+ },
33
+ elements: () => this.tags,
34
+ isFocusableElement: (el) => !el.disabled && el.deletable,
35
+ });
36
+ this.handleFocusin = () => {
37
+ this.addEventListener('focusout', this.handleFocusout);
38
+ this.addEventListener('keydown', this.handleKeydown);
39
+ };
40
+ this.handleKeydown = (event) => {
41
+ const { code } = event;
42
+ if (code !== 'PageUp' && code !== 'PageDown')
43
+ return;
44
+ const circularIndexedElement = (list, index) => list[(list.length + index) % list.length];
45
+ const tagsSiblings = [
46
+ ...this.getRootNode().querySelectorAll('sp-tags'),
47
+ ];
48
+ if (tagsSiblings.length < 2) {
49
+ return;
50
+ }
51
+ event.preventDefault();
52
+ const currentIndex = tagsSiblings.indexOf(this);
53
+ const offset = code === 'PageUp' ? -1 : 1;
54
+ let nextTagsIndex = currentIndex + offset;
55
+ let nextTags = circularIndexedElement(tagsSiblings, nextTagsIndex);
56
+ while (!nextTags.tags.length) {
57
+ nextTagsIndex += offset;
58
+ nextTags = circularIndexedElement(tagsSiblings, nextTagsIndex);
59
+ }
60
+ nextTags.focus();
61
+ };
62
+ this.handleFocusout = () => {
63
+ this.removeEventListener('keydown', this.handleKeydown);
64
+ this.removeEventListener('focusout', this.handleFocusout);
65
+ };
66
+ this.addEventListener('focusin', this.handleFocusin);
67
+ }
68
+ static get styles() {
69
+ return [styles];
70
+ }
71
+ get tags() {
72
+ return this.defaultNodes.filter((node) => node instanceof Tag);
73
+ }
74
+ focus() {
75
+ this.rovingTabindexController.focus();
76
+ }
77
+ handleSlotchange() {
78
+ this.rovingTabindexController.clearElementCache();
79
+ }
80
+ render() {
81
+ return html `
82
+ <slot @slotchange=${this.handleSlotchange}></slot>
83
+ `;
84
+ }
85
+ firstUpdated() {
86
+ if (!this.hasAttribute('role')) {
87
+ this.setAttribute('role', 'list');
88
+ }
89
+ if (!this.hasAttribute('aria-label')) {
90
+ this.setAttribute('aria-label', 'Tags');
91
+ }
92
+ }
93
+ }
94
+ __decorate([
95
+ queryAssignedNodes('')
96
+ ], Tags.prototype, "defaultNodes", void 0);
97
+ //# sourceMappingURL=Tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tags.js","sourceRoot":"","sources":["Tags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;;AAEF,OAAO,EAEH,IAAI,EACJ,eAAe,GAElB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,kBAAkB,EAAE,MAAM,iDAAiD,CAAC;AACrF,OAAO,EAAE,yBAAyB,EAAE,MAAM,sDAAsD,CAAC;AACjG,OAAO,EAAE,wBAAwB,EAAE,MAAM,qEAAqE,CAAC;AAE/G,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAE/B,OAAO,MAAM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,OAAO,IAAI,CAAA;gCACa,IAAI,CAAC,gBAAgB;SAC5C,CAAC;IACN,CAAC;IAES,YAAY;QAClB,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE;YAC5B,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;SACrC;QACD,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE;YAClC,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;SAC3C;IACL,CAAC;CACJ;AAnFG;IADC,kBAAkB,CAAC,EAAE,CAAC;0CACM","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nimport {\n CSSResultArray,\n html,\n SpectrumElement,\n TemplateResult,\n} from '@spectrum-web-components/base';\nimport { queryAssignedNodes } from '@spectrum-web-components/base/src/decorators.js';\nimport { FocusVisiblePolyfillMixin } from '@spectrum-web-components/shared/src/focus-visible.js';\nimport { RovingTabindexController } from '@spectrum-web-components/reactive-controllers/src/RovingTabindex.js';\n\nimport { Tag } from './Tag.js';\n\nimport styles from './tags.css.js';\n\n/**\n * @element sp-tags\n *\n * @slot - Tag elements to manage as a group\n */\nexport class Tags extends FocusVisiblePolyfillMixin(SpectrumElement) {\n public static get styles(): CSSResultArray {\n return [styles];\n }\n\n @queryAssignedNodes('')\n public defaultNodes!: Node[];\n\n public get tags(): Tag[] {\n return this.defaultNodes.filter(\n (node) => (node as HTMLElement) instanceof Tag\n ) as Tag[];\n }\n\n rovingTabindexController = new RovingTabindexController<Tag>(this, {\n focusInIndex: (elements: Tag[]) => {\n return elements.findIndex((el) => {\n return !el.disabled && el.deletable;\n });\n },\n elements: () => this.tags,\n isFocusableElement: (el: Tag) => !el.disabled && el.deletable,\n });\n\n constructor() {\n super();\n this.addEventListener('focusin', this.handleFocusin);\n }\n\n public focus(): void {\n this.rovingTabindexController.focus();\n }\n\n private handleFocusin = (): void => {\n this.addEventListener('focusout', this.handleFocusout);\n this.addEventListener('keydown', this.handleKeydown);\n };\n\n private handleKeydown = (event: KeyboardEvent): void => {\n const { code } = event;\n if (code !== 'PageUp' && code !== 'PageDown') return;\n\n const circularIndexedElement = <T extends HTMLElement>(\n list: T[],\n index: number\n ): T => list[(list.length + index) % list.length];\n const tagsSiblings = [\n ...(this.getRootNode() as Document).querySelectorAll<Tags>(\n 'sp-tags'\n ),\n ];\n if (tagsSiblings.length < 2) {\n return;\n }\n event.preventDefault();\n const currentIndex = tagsSiblings.indexOf(this);\n const offset = code === 'PageUp' ? -1 : 1;\n let nextTagsIndex = currentIndex + offset;\n let nextTags = circularIndexedElement(tagsSiblings, nextTagsIndex);\n while (!nextTags.tags.length) {\n nextTagsIndex += offset;\n nextTags = circularIndexedElement(tagsSiblings, nextTagsIndex);\n }\n nextTags.focus();\n };\n\n private handleFocusout = (): void => {\n this.removeEventListener('keydown', this.handleKeydown);\n this.removeEventListener('focusout', this.handleFocusout);\n };\n\n private handleSlotchange(): void {\n this.rovingTabindexController.clearElementCache();\n }\n\n protected render(): TemplateResult {\n return html`\n <slot @slotchange=${this.handleSlotchange}></slot>\n `;\n }\n\n protected firstUpdated(): void {\n if (!this.hasAttribute('role')) {\n this.setAttribute('role', 'list');\n }\n if (!this.hasAttribute('aria-label')) {\n this.setAttribute('aria-label', 'Tags');\n }\n }\n}\n"]}
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './Tags.js';
2
+ export * from './Tag.js';
package/src/index.js ADDED
@@ -0,0 +1,14 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+ export * from './Tags.js';
13
+ export * from './Tag.js';
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;EAUE;AAEF,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC","sourcesContent":["/*\nCopyright 2020 Adobe. All rights reserved.\nThis file is licensed to you under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License. You may obtain a copy\nof the License at http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software distributed under\nthe License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\nOF ANY KIND, either express or implied. See the License for the specific language\ngoverning permissions and limitations under the License.\n*/\n\nexport * from './Tags.js';\nexport * from './Tag.js';\n"]}
@@ -0,0 +1,2 @@
1
+ declare const styles: import("@spectrum-web-components/base").CSSResult;
2
+ export default styles;