@spectrum-web-components/base 0.5.0 → 0.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectrum-web-components/base",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -56,5 +56,5 @@
56
56
  "types": "./src/index.d.ts",
57
57
  "customElements": "custom-elements.json",
58
58
  "sideEffects": false,
59
- "gitHead": "7ce77352f6894043bceac9ef92b21e5f85420969"
59
+ "gitHead": "df3f333ee26a45f9fc247716b6e8ef051dca630b"
60
60
  }
@@ -3,12 +3,14 @@ declare type Constructor<T = Record<string, unknown>> = {
3
3
  new (...args: any[]): T;
4
4
  prototype: T;
5
5
  };
6
- export declare type ElementSize = 's' | 'm' | 'l' | 'xl' | 'xxl';
6
+ export declare type ElementSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';
7
+ export declare type DefaultElementSize = Exclude<ElementSize, 'xxs' | 'xs' | 'xxl'>;
7
8
  export interface SizedElementInterface {
8
9
  size: ElementSize;
9
10
  }
10
- export declare function SizedMixin<T extends Constructor<ReactiveElement>>(constructor: T, { validSizes, noDefaultSize, }?: {
11
+ export declare function SizedMixin<T extends Constructor<ReactiveElement>>(constructor: T, { validSizes, noDefaultSize, defaultSize, }?: {
11
12
  validSizes?: ElementSize[];
12
13
  noDefaultSize?: boolean;
14
+ defaultSize?: ElementSize;
13
15
  }): T & Constructor<SizedElementInterface>;
14
16
  export {};
package/src/sizedMixin.js CHANGED
@@ -1,18 +1,18 @@
1
1
  import { __decorate } from "tslib";
2
2
  import { property } from 'lit/decorators.js';
3
- export function SizedMixin(constructor, { validSizes = ['s', 'm', 'l', 'xl'], noDefaultSize, } = {}) {
3
+ export function SizedMixin(constructor, { validSizes = ['s', 'm', 'l', 'xl'], noDefaultSize, defaultSize = 'm', } = {}) {
4
4
  class SizedElement extends constructor {
5
5
  constructor() {
6
6
  super(...arguments);
7
- this._size = 'm';
7
+ this._size = defaultSize;
8
8
  }
9
9
  get size() {
10
- return this._size || 'm';
10
+ return this._size || defaultSize;
11
11
  }
12
12
  set size(value) {
13
- const defaultSize = noDefaultSize ? null : 'm';
13
+ const fallbackSize = noDefaultSize ? null : defaultSize;
14
14
  const size = (value ? value.toLocaleLowerCase() : value);
15
- const validSize = (validSizes.includes(size) ? size : defaultSize);
15
+ const validSize = (validSizes.includes(size) ? size : fallbackSize);
16
16
  if (validSize) {
17
17
  this.setAttribute('size', validSize);
18
18
  }
@@ -1 +1 @@
1
- {"version":3,"file":"sizedMixin.js","sourceRoot":"","sources":["sizedMixin.ts"],"names":[],"mappings":";AAYA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAc7C,MAAM,UAAU,UAAU,CACtB,WAAc,EACd,EACI,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAClC,aAAa,MAIb,EAAE;IAEN,MAAM,YAAa,SAAQ,WAAW;QAAtC;;YAyBY,UAAK,GAAuB,GAAG,CAAC;QAQ5C,CAAC;QA/BG,IAAW,IAAI;YACX,OAAO,IAAI,CAAC,KAAK,IAAI,GAAG,CAAC;QAC7B,CAAC;QAED,IAAW,IAAI,CAAC,KAAkB;YAC9B,MAAM,WAAW,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC;YAC/C,MAAM,IAAI,GAAG,CACT,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,KAAK,CAC7B,CAAC;YACjB,MAAM,SAAS,GAAG,CACd,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAClC,CAAC;YACjB,IAAI,SAAS,EAAE;gBACX,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;aACxC;YACD,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;gBAC1B,OAAO;aACV;YACD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC;YAC3B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;YACvB,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC;QAIS,YAAY,CAAC,OAAuB;YAC1C,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE;gBAC9C,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;aACxC;QACL,CAAC;KACJ;IA/BG;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;4CAGzC;IA8BL,OAAO,YAAY,CAAC;AACxB,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 { PropertyValues, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport type ElementSize = 's' | 'm' | 'l' | 'xl' | 'xxl';\n\nexport interface SizedElementInterface {\n size: ElementSize;\n}\n\nexport function SizedMixin<T extends Constructor<ReactiveElement>>(\n constructor: T,\n {\n validSizes = ['s', 'm', 'l', 'xl'],\n noDefaultSize,\n }: {\n validSizes?: ElementSize[];\n noDefaultSize?: boolean;\n } = {}\n): T & Constructor<SizedElementInterface> {\n class SizedElement extends constructor {\n @property({ type: String, reflect: true })\n public get size(): ElementSize {\n return this._size || 'm';\n }\n\n public set size(value: ElementSize) {\n const defaultSize = noDefaultSize ? null : 'm';\n const size = (\n value ? value.toLocaleLowerCase() : value\n ) as ElementSize;\n const validSize = (\n validSizes.includes(size) ? size : defaultSize\n ) as ElementSize;\n if (validSize) {\n this.setAttribute('size', validSize);\n }\n if (this._size === validSize) {\n return;\n }\n const oldSize = this._size;\n this._size = validSize;\n this.requestUpdate('size', oldSize);\n }\n\n private _size: ElementSize | null = 'm';\n\n protected firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n if (!this.hasAttribute('size') && !noDefaultSize) {\n this.setAttribute('size', this.size);\n }\n }\n }\n return SizedElement;\n}\n"]}
1
+ {"version":3,"file":"sizedMixin.js","sourceRoot":"","sources":["sizedMixin.ts"],"names":[],"mappings":";AAYA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAe7C,MAAM,UAAU,UAAU,CACtB,WAAc,EACd,EACI,UAAU,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,EAClC,aAAa,EACb,WAAW,GAAG,GAAG,MAKjB,EAAE;IAEN,MAAM,YAAa,SAAQ,WAAW;QAAtC;;YAyBY,UAAK,GAAuB,WAAW,CAAC;QAQpD,CAAC;QA/BG,IAAW,IAAI;YACX,OAAO,IAAI,CAAC,KAAK,IAAI,WAAW,CAAC;QACrC,CAAC;QAED,IAAW,IAAI,CAAC,KAAkB;YAC9B,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,WAAW,CAAC;YACxD,MAAM,IAAI,GAAG,CACT,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,EAAE,CAAC,CAAC,CAAC,KAAK,CAC7B,CAAC;YACjB,MAAM,SAAS,GAAG,CACd,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CACnC,CAAC;YACjB,IAAI,SAAS,EAAE;gBACX,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;aACxC;YACD,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE;gBAC1B,OAAO;aACV;YACD,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC;YAC3B,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;YACvB,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACxC,CAAC;QAIS,YAAY,CAAC,OAAuB;YAC1C,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;YAC5B,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE;gBAC9C,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;aACxC;QACL,CAAC;KACJ;IA/BG;QADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;4CAGzC;IA8BL,OAAO,YAAY,CAAC;AACxB,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 { PropertyValues, ReactiveElement } from 'lit';\nimport { property } from 'lit/decorators.js';\n\ntype Constructor<T = Record<string, unknown>> = {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n new (...args: any[]): T;\n prototype: T;\n};\n\nexport type ElementSize = 'xxs' | 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl';\nexport type DefaultElementSize = Exclude<ElementSize, 'xxs' | 'xs' | 'xxl'>;\n\nexport interface SizedElementInterface {\n size: ElementSize;\n}\n\nexport function SizedMixin<T extends Constructor<ReactiveElement>>(\n constructor: T,\n {\n validSizes = ['s', 'm', 'l', 'xl'],\n noDefaultSize,\n defaultSize = 'm',\n }: {\n validSizes?: ElementSize[];\n noDefaultSize?: boolean;\n defaultSize?: ElementSize;\n } = {}\n): T & Constructor<SizedElementInterface> {\n class SizedElement extends constructor {\n @property({ type: String, reflect: true })\n public get size(): ElementSize {\n return this._size || defaultSize;\n }\n\n public set size(value: ElementSize) {\n const fallbackSize = noDefaultSize ? null : defaultSize;\n const size = (\n value ? value.toLocaleLowerCase() : value\n ) as ElementSize;\n const validSize = (\n validSizes.includes(size) ? size : fallbackSize\n ) as ElementSize;\n if (validSize) {\n this.setAttribute('size', validSize);\n }\n if (this._size === validSize) {\n return;\n }\n const oldSize = this._size;\n this._size = validSize;\n this.requestUpdate('size', oldSize);\n }\n\n private _size: ElementSize | null = defaultSize;\n\n protected firstUpdated(changes: PropertyValues): void {\n super.firstUpdated(changes);\n if (!this.hasAttribute('size') && !noDefaultSize) {\n this.setAttribute('size', this.size);\n }\n }\n }\n return SizedElement;\n}\n"]}
package/test/base.test.js DELETED
@@ -1,30 +0,0 @@
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
- Unless required by applicable law or agreed to in writing, software distributed under
7
- the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
8
- OF ANY KIND, either express or implied. See the License for the specific language
9
- governing permissions and limitations under the License.
10
- */
11
- import { SpectrumElement } from '../';
12
- import { elementUpdated, expect, fixture, html } from '@open-wc/testing';
13
- class DirElement extends SpectrumElement {
14
- }
15
- customElements.define('dir-element', DirElement);
16
- describe('Base', () => {
17
- after(() => {
18
- document.dir = '';
19
- });
20
- it('sets `dir` from `document`', async () => {
21
- document.dir = 'rtl';
22
- const el = await fixture(html `
23
- <dir-element></dir-element>
24
- `);
25
- await elementUpdated(el);
26
- expect(el.dir).to.equal('rtl');
27
- expect(el.isLTR).to.be.false;
28
- });
29
- });
30
- //# sourceMappingURL=base.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"base.test.js","sourceRoot":"","sources":["base.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;EASE;AACF,OAAO,EAAE,eAAe,EAAE,MAAM,KAAK,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEzE,MAAM,UAAW,SAAQ,eAAe;CAAG;AAE3C,cAAc,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AAEjD,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IAClB,KAAK,CAAC,GAAG,EAAE;QACP,QAAQ,CAAC,GAAG,GAAG,EAAE,CAAC;IACtB,CAAC,CAAC,CAAC;IACH,EAAE,CAAC,4BAA4B,EAAE,KAAK,IAAI,EAAE;QACxC,QAAQ,CAAC,GAAG,GAAG,KAAK,CAAC;QACrB,MAAM,EAAE,GAAG,MAAM,OAAO,CACpB,IAAI,CAAA;;aAEH,CACJ,CAAC;QAEF,MAAM,cAAc,CAAC,EAAE,CAAC,CAAC;QAEzB,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC/B,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,KAAK,CAAC;IACjC,CAAC,CAAC,CAAC;AACP,CAAC,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\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 { SpectrumElement } from '../';\nimport { elementUpdated, expect, fixture, html } from '@open-wc/testing';\n\nclass DirElement extends SpectrumElement {}\n\ncustomElements.define('dir-element', DirElement);\n\ndescribe('Base', () => {\n after(() => {\n document.dir = '';\n });\n it('sets `dir` from `document`', async () => {\n document.dir = 'rtl';\n const el = await fixture<DirElement>(\n html`\n <dir-element></dir-element>\n `\n );\n\n await elementUpdated(el);\n\n expect(el.dir).to.equal('rtl');\n expect(el.isLTR).to.be.false;\n });\n});\n"]}