@digital-realty/ix-date 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-date
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,62 @@
1
+ # \<ix-date>
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 @digital-realty/ix-date
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```html
14
+ <script type="module">
15
+ import '@digital-realty/ix-date/ix-date.js';
16
+ </script>
17
+
18
+ <ix-date value="2024-01-17" label="Date"></ix-date>
19
+ ```
20
+
21
+ ## Linting and formatting
22
+
23
+ To scan the project for linting and formatting errors, run
24
+
25
+ ```bash
26
+ npm run lint
27
+ ```
28
+
29
+ To automatically fix linting and formatting errors, run
30
+
31
+ ```bash
32
+ npm run format
33
+ ```
34
+
35
+ ## Testing with Web Test Runner
36
+
37
+ To execute a single test run:
38
+
39
+ ```bash
40
+ npm run test
41
+ ```
42
+
43
+ To run the tests in interactive watch mode run:
44
+
45
+ ```bash
46
+ npm run test:watch
47
+ ```
48
+
49
+
50
+ ## Tooling configs
51
+
52
+ For most of the tools, the configuration is in the `package.json` to reduce the amount of files in your project.
53
+
54
+ If you customize the configuration a lot, you can consider moving them to individual files.
55
+
56
+ ## Local Demo with `web-dev-server`
57
+
58
+ ```bash
59
+ npm start
60
+ ```
61
+
62
+ To run a local development server that serves the basic demo located in `demo/index.html`
@@ -0,0 +1,86 @@
1
+ import { LitElement } from 'lit';
2
+ import '@digital-realty/ix-field/ix-field.js';
3
+ export declare class IxDate extends LitElement {
4
+ static get styles(): import("lit").CSSResult[];
5
+ label: string;
6
+ value: string;
7
+ min: string;
8
+ max: string;
9
+ /** @nocollapse */
10
+ static shadowRootOptions: {
11
+ delegatesFocus: boolean;
12
+ mode: ShadowRootMode;
13
+ slotAssignment?: SlotAssignmentMode | undefined;
14
+ customElements?: CustomElementRegistry | undefined;
15
+ registry?: CustomElementRegistry | undefined;
16
+ };
17
+ /** @nocollapse */
18
+ static readonly formAssociated = true;
19
+ private readonly internals;
20
+ dateInput: HTMLInputElement;
21
+ disabled: boolean;
22
+ /**
23
+ * Gets or sets whether or not the text field is in a visually invalid state.
24
+ *
25
+ * This error state overrides the error state controlled by
26
+ * `reportValidity()`.
27
+ */
28
+ error: boolean;
29
+ errorText: string;
30
+ errorTextBelowRange: string;
31
+ errorTextAboveRange: string;
32
+ private errorMsg;
33
+ required: boolean;
34
+ /**
35
+ * The associated form element with which this element's value will submit.
36
+ */
37
+ get form(): HTMLFormElement | null;
38
+ /**
39
+ * The labels this element is associated with.
40
+ */
41
+ get labels(): NodeList;
42
+ /**
43
+ * The HTML name to use in form submission.
44
+ */
45
+ get name(): string;
46
+ set name(name: string);
47
+ /**
48
+ * Returns the text field's validation error message.
49
+ *
50
+ * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation
51
+ */
52
+ get validationMessage(): string;
53
+ /**
54
+ * Returns a `ValidityState` object that represents the validity states of the
55
+ * text field.
56
+ *
57
+ * https://developer.mozilla.org/en-US/docs/Web/API/ValidityState
58
+ */
59
+ get validity(): ValidityState;
60
+ /**
61
+ * Returns whether an element will successfully validate based on forms
62
+ * validation rules and constraints.
63
+ *
64
+ * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/willValidate
65
+ */
66
+ get willValidate(): boolean;
67
+ checkValidity(): boolean;
68
+ reportValidity(): boolean;
69
+ /** @private */
70
+ formResetCallback(): void;
71
+ /**
72
+ * Reset the text field to its default value.
73
+ */
74
+ reset(): void;
75
+ protected updated(): void;
76
+ focus(): void;
77
+ onChanged: any;
78
+ private focused;
79
+ private range;
80
+ firstUpdated(): void;
81
+ focusin: () => void;
82
+ clear: () => void;
83
+ handleChange: (e: InputEvent) => void;
84
+ validateDate: () => void;
85
+ render(): import("lit").TemplateResult<1>;
86
+ }
package/dist/IxDate.js ADDED
@@ -0,0 +1,239 @@
1
+ import { __decorate } from "tslib";
2
+ import { html, LitElement } from 'lit';
3
+ import { property, query, state } from 'lit/decorators.js';
4
+ import { classMap } from 'lit/directives/class-map.js';
5
+ import '@digital-realty/ix-field/ix-field.js';
6
+ import { requestUpdateOnAriaChange } from '@material/web/internal/aria/delegate.js';
7
+ import { IxDateStyles } from './ix-date-styles.js';
8
+ export class IxDate extends LitElement {
9
+ constructor() {
10
+ super(...arguments);
11
+ this.label = '';
12
+ this.value = '';
13
+ this.min = '';
14
+ this.max = '';
15
+ this.internals = this /* needed for closure */
16
+ .attachInternals();
17
+ this.disabled = false;
18
+ /**
19
+ * Gets or sets whether or not the text field is in a visually invalid state.
20
+ *
21
+ * This error state overrides the error state controlled by
22
+ * `reportValidity()`.
23
+ */
24
+ this.error = false;
25
+ this.errorText = 'Invalid date';
26
+ this.errorTextBelowRange = 'Below range';
27
+ this.errorTextAboveRange = 'Above range';
28
+ this.errorMsg = 'Invalid date';
29
+ this.required = false;
30
+ // eslint-disable-next-line class-methods-use-this
31
+ this.onChanged = () => { };
32
+ this.focused = false;
33
+ this.range = {
34
+ min: undefined,
35
+ max: undefined,
36
+ };
37
+ this.focusin = () => {
38
+ this.focused = true;
39
+ };
40
+ this.clear = () => {
41
+ this.value = '';
42
+ };
43
+ this.handleChange = (e) => {
44
+ const { value } = e.target;
45
+ this.value = value;
46
+ this.validateDate();
47
+ this.onChanged(value);
48
+ };
49
+ this.validateDate = () => {
50
+ const date = new Date(this.value);
51
+ let errorType;
52
+ if (!date) {
53
+ errorType = 'errorText';
54
+ }
55
+ else if (this.range.min && date < this.range.min) {
56
+ errorType = 'errorTextBelowRange';
57
+ }
58
+ else if (this.range.max && date > this.range.max) {
59
+ errorType = 'errorTextAboveRange';
60
+ }
61
+ if (errorType) {
62
+ this.error = true;
63
+ this.errorMsg = this[errorType];
64
+ }
65
+ else {
66
+ this.error = false;
67
+ }
68
+ };
69
+ }
70
+ static get styles() {
71
+ return [IxDateStyles];
72
+ }
73
+ /**
74
+ * The associated form element with which this element's value will submit.
75
+ */
76
+ get form() {
77
+ return this.internals.form;
78
+ }
79
+ /**
80
+ * The labels this element is associated with.
81
+ */
82
+ get labels() {
83
+ return this.internals.labels;
84
+ }
85
+ /**
86
+ * The HTML name to use in form submission.
87
+ */
88
+ get name() {
89
+ var _a;
90
+ return (_a = this.getAttribute('name')) !== null && _a !== void 0 ? _a : '';
91
+ }
92
+ set name(name) {
93
+ this.setAttribute('name', name);
94
+ }
95
+ /**
96
+ * Returns the text field's validation error message.
97
+ *
98
+ * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation
99
+ */
100
+ get validationMessage() {
101
+ return this.internals.validationMessage;
102
+ }
103
+ /**
104
+ * Returns a `ValidityState` object that represents the validity states of the
105
+ * text field.
106
+ *
107
+ * https://developer.mozilla.org/en-US/docs/Web/API/ValidityState
108
+ */
109
+ get validity() {
110
+ return this.internals.validity;
111
+ }
112
+ /**
113
+ * Returns whether an element will successfully validate based on forms
114
+ * validation rules and constraints.
115
+ *
116
+ * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/willValidate
117
+ */
118
+ get willValidate() {
119
+ return this.internals.willValidate;
120
+ }
121
+ checkValidity() {
122
+ return this.internals.checkValidity();
123
+ }
124
+ reportValidity() {
125
+ return this.internals.reportValidity();
126
+ }
127
+ /** @private */
128
+ formResetCallback() {
129
+ this.reset();
130
+ }
131
+ /**
132
+ * Reset the text field to its default value.
133
+ */
134
+ reset() {
135
+ var _a;
136
+ this.clear();
137
+ this.value = (_a = this.getAttribute('value')) !== null && _a !== void 0 ? _a : '';
138
+ }
139
+ updated() {
140
+ this.internals.setValidity({
141
+ badInput: this.error,
142
+ }, this.error ? this.errorText : '', this.dateInput);
143
+ this.internals.setFormValue(this.value);
144
+ }
145
+ focus() {
146
+ this.dateInput.focus();
147
+ }
148
+ firstUpdated() {
149
+ this.focused = !!this.value;
150
+ this.range.min = new Date(this.min);
151
+ this.range.max = new Date(this.max);
152
+ this.validateDate();
153
+ }
154
+ render() {
155
+ const classes = {
156
+ disabled: this.disabled,
157
+ error: !this.disabled && this.error,
158
+ };
159
+ return html `
160
+ <ix-field
161
+ class="${classMap(classes)}"
162
+ ?focused=${this.focused}
163
+ ?disabled=${this.disabled}
164
+ ?required=${this.required}
165
+ ?error=${this.error}
166
+ error-text=${this.errorMsg}
167
+ label=${this.label}
168
+ >
169
+ <input
170
+ id="date-input"
171
+ @focus=${this.focusin}
172
+ @change=${this.handleChange}
173
+ .value=${this.value}
174
+ class="flex-fill"
175
+ type="date"
176
+ min=${this.min}
177
+ max=${this.max}
178
+ />
179
+ </ix-field>
180
+ `;
181
+ }
182
+ }
183
+ (() => {
184
+ requestUpdateOnAriaChange(IxDate);
185
+ })();
186
+ // Form association
187
+ /** @nocollapse */
188
+ IxDate.shadowRootOptions = {
189
+ ...LitElement.shadowRootOptions,
190
+ delegatesFocus: true,
191
+ };
192
+ /** @nocollapse */
193
+ IxDate.formAssociated = true;
194
+ __decorate([
195
+ property({ type: String })
196
+ ], IxDate.prototype, "label", void 0);
197
+ __decorate([
198
+ property({ type: String })
199
+ ], IxDate.prototype, "value", void 0);
200
+ __decorate([
201
+ property({ type: String })
202
+ ], IxDate.prototype, "min", void 0);
203
+ __decorate([
204
+ property({ type: String })
205
+ ], IxDate.prototype, "max", void 0);
206
+ __decorate([
207
+ query('#date-input')
208
+ ], IxDate.prototype, "dateInput", void 0);
209
+ __decorate([
210
+ property({ type: Boolean, reflect: true })
211
+ ], IxDate.prototype, "disabled", void 0);
212
+ __decorate([
213
+ property({ type: Boolean, reflect: true })
214
+ ], IxDate.prototype, "error", void 0);
215
+ __decorate([
216
+ property({ type: String, attribute: 'error-text' })
217
+ ], IxDate.prototype, "errorText", void 0);
218
+ __decorate([
219
+ property({ type: String, attribute: 'error-text-below-range' })
220
+ ], IxDate.prototype, "errorTextBelowRange", void 0);
221
+ __decorate([
222
+ property({ type: String, attribute: 'error-text-above-range' })
223
+ ], IxDate.prototype, "errorTextAboveRange", void 0);
224
+ __decorate([
225
+ state()
226
+ ], IxDate.prototype, "errorMsg", void 0);
227
+ __decorate([
228
+ property({ type: Boolean, reflect: true })
229
+ ], IxDate.prototype, "required", void 0);
230
+ __decorate([
231
+ property({ type: Function })
232
+ ], IxDate.prototype, "onChanged", void 0);
233
+ __decorate([
234
+ state()
235
+ ], IxDate.prototype, "focused", void 0);
236
+ __decorate([
237
+ state()
238
+ ], IxDate.prototype, "range", void 0);
239
+ //# sourceMappingURL=IxDate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IxDate.js","sourceRoot":"","sources":["../src/IxDate.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,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O,EAAE,IAAI,EAAE,CAAC;wCAAkB;AAQjB;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;qCAAe;AAEL;IAApD,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;yCACnC;AAGjB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;mDAC5B;AAGpC;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,wBAAwB,EAAE,CAAC;mDAC5B;AAE3B;IAAR,KAAK,EAAE;wCAAmC;AAEC;IAA3C,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;wCAAkB;AA6F/B;IAA7B,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;yCAA2B;AAE/C;IAAR,KAAK,EAAE;uCAAyB;AAExB;IAAR,KAAK,EAAE;qCAGN","sourcesContent":["import { html, LitElement } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\nimport { classMap } from 'lit/directives/class-map.js';\nimport '@digital-realty/ix-field/ix-field.js';\nimport { requestUpdateOnAriaChange } from '@material/web/internal/aria/delegate.js';\nimport { IxDateStyles } from './ix-date-styles.js';\n\nexport class IxDate extends LitElement {\n static {\n requestUpdateOnAriaChange(IxDate);\n }\n\n static get styles() {\n return [IxDateStyles];\n }\n\n @property({ type: String }) label = '';\n\n @property({ type: String }) value = '';\n\n @property({ type: String }) min = '';\n\n @property({ type: String }) max = '';\n\n // Form association\n\n /** @nocollapse */\n static override shadowRootOptions = {\n ...LitElement.shadowRootOptions,\n delegatesFocus: true,\n };\n\n /** @nocollapse */\n static readonly formAssociated = true;\n\n private readonly internals = (this as HTMLElement) /* needed for closure */\n .attachInternals();\n\n @query('#date-input') dateInput!: HTMLInputElement;\n\n @property({ type: Boolean, reflect: true }) disabled = false;\n\n /**\n * Gets or sets whether or not the text field is in a visually invalid state.\n *\n * This error state overrides the error state controlled by\n * `reportValidity()`.\n */\n @property({ type: Boolean, reflect: true }) error = false;\n\n @property({ type: String, attribute: 'error-text' }) errorText =\n 'Invalid date';\n\n @property({ type: String, attribute: 'error-text-below-range' })\n errorTextBelowRange = 'Below range';\n\n @property({ type: String, attribute: 'error-text-above-range' })\n errorTextAboveRange = 'Above range';\n\n @state() private errorMsg = 'Invalid date';\n\n @property({ type: Boolean, reflect: true }) required = false;\n\n /**\n * The associated form element with which this element's value will submit.\n */\n get form() {\n return this.internals.form;\n }\n\n /**\n * The labels this element is associated with.\n */\n get labels() {\n return this.internals.labels;\n }\n\n /**\n * The HTML name to use in form submission.\n */\n get name() {\n return this.getAttribute('name') ?? '';\n }\n\n set name(name: string) {\n this.setAttribute('name', name);\n }\n\n /**\n * Returns the text field's validation error message.\n *\n * https://developer.mozilla.org/en-US/docs/Web/HTML/Constraint_validation\n */\n get validationMessage() {\n return this.internals.validationMessage;\n }\n\n /**\n * Returns a `ValidityState` object that represents the validity states of the\n * text field.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ValidityState\n */\n get validity() {\n return this.internals.validity;\n }\n\n /**\n * Returns whether an element will successfully validate based on forms\n * validation rules and constraints.\n *\n * https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/willValidate\n */\n get willValidate() {\n return this.internals.willValidate;\n }\n\n checkValidity() {\n return this.internals.checkValidity();\n }\n\n reportValidity() {\n return this.internals.reportValidity();\n }\n\n /** @private */\n formResetCallback() {\n this.reset();\n }\n\n /**\n * Reset the text field to its default value.\n */\n reset() {\n this.clear();\n this.value = this.getAttribute('value') ?? '';\n }\n\n protected override updated() {\n this.internals.setValidity(\n {\n badInput: this.error,\n },\n this.error ? this.errorText : '',\n this.dateInput\n );\n this.internals.setFormValue(this.value);\n }\n\n override focus() {\n this.dateInput.focus();\n }\n\n // eslint-disable-next-line class-methods-use-this\n @property({ type: Function }) onChanged: any = () => {};\n\n @state() private focused = false;\n\n @state() private range: { min: Date | undefined; max: Date | undefined } = {\n min: undefined,\n max: undefined,\n };\n\n firstUpdated() {\n this.focused = !!this.value;\n this.range.min = new Date(this.min);\n this.range.max = new Date(this.max);\n this.validateDate();\n }\n\n focusin = () => {\n this.focused = true;\n };\n\n clear = () => {\n this.value = '';\n };\n\n handleChange = (e: InputEvent) => {\n const { value } = e.target as HTMLInputElement;\n this.value = value;\n this.validateDate();\n this.onChanged(value);\n };\n\n validateDate = () => {\n const date = new Date(this.value);\n let errorType:\n | 'errorText'\n | 'errorTextBelowRange'\n | 'errorTextAboveRange'\n | undefined;\n if (!date) {\n errorType = 'errorText';\n } else if (this.range.min && date < this.range.min) {\n errorType = 'errorTextBelowRange';\n } else if (this.range.max && date > this.range.max) {\n errorType = 'errorTextAboveRange';\n }\n if (errorType) {\n this.error = true;\n this.errorMsg = this[errorType];\n } else {\n this.error = false;\n }\n };\n\n render() {\n const classes = {\n disabled: this.disabled,\n error: !this.disabled && this.error,\n };\n\n return html`\n <ix-field\n class=\"${classMap(classes)}\"\n ?focused=${this.focused}\n ?disabled=${this.disabled}\n ?required=${this.required}\n ?error=${this.error}\n error-text=${this.errorMsg}\n label=${this.label}\n >\n <input\n id=\"date-input\"\n @focus=${this.focusin}\n @change=${this.handleChange}\n .value=${this.value}\n class=\"flex-fill\"\n type=\"date\"\n min=${this.min}\n max=${this.max}\n />\n </ix-field>\n `;\n }\n}\n"]}
@@ -0,0 +1 @@
1
+ export { IxDate } from './IxDate.js';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { IxDate } from './IxDate.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,MAAM,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { IxDate } from './IxDate.js';\n"]}
@@ -0,0 +1 @@
1
+ export declare const IxDateStyles: import("lit").CSSResult;
@@ -0,0 +1,25 @@
1
+ import { css } from 'lit';
2
+ export const IxDateStyles = 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-primary);
9
+ --md-outlined-field-outline-color: var(--md-outlined-field-outline-color);
10
+ }
11
+ .flex-fill {
12
+ flex: 1;
13
+ align-items: center;
14
+ }
15
+ input {
16
+ border: none;
17
+ background: transparent;
18
+ outline: none;
19
+ min-width: 3rem;
20
+ }
21
+ .date {
22
+ position: relative;
23
+ }
24
+ `;
25
+ //# sourceMappingURL=ix-date-styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ix-date-styles.js","sourceRoot":"","sources":["../src/ix-date-styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;CAsB9B,CAAC","sourcesContent":["import { css } from 'lit';\n\nexport const IxDateStyles = 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-primary);\n --md-outlined-field-outline-color: var(--md-outlined-field-outline-color);\n }\n .flex-fill {\n flex: 1;\n align-items: center;\n }\n input {\n border: none;\n background: transparent;\n outline: none;\n min-width: 3rem;\n }\n .date {\n position: relative;\n }\n`;\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { IxDate } from './IxDate.js';
2
+ window.customElements.define('ix-date', IxDate);
3
+ //# sourceMappingURL=ix-date.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ix-date.js","sourceRoot":"","sources":["../src/ix-date.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC","sourcesContent":["import { IxDate } from './IxDate.js';\n\nwindow.customElements.define('ix-date', IxDate);\n"]}
package/package.json ADDED
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "@digital-realty/ix-date",
3
+ "description": "Webcomponent ix-date 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-date.js": "./dist/ix-date.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-field": "^0.0.3",
29
+ "@digital-realty/theme": "^1.0.6",
30
+ "@material/web": "^1.0.0",
31
+ "@web/test-runner-commands": "^0.9.0",
32
+ "lit": "^2.0.2"
33
+ },
34
+ "devDependencies": {
35
+ "@custom-elements-manifest/analyzer": "^0.4.17",
36
+ "@open-wc/eslint-config": "^9.2.1",
37
+ "@open-wc/testing": "^3.1.6",
38
+ "@typescript-eslint/eslint-plugin": "^5.48.0",
39
+ "@typescript-eslint/parser": "^5.48.0",
40
+ "@web/dev-server": "^0.1.34",
41
+ "@web/test-runner": "^0.14.0",
42
+ "concurrently": "^5.3.0",
43
+ "eslint": "^8.31.0",
44
+ "eslint-config-prettier": "^8.3.0",
45
+ "husky": "^4.3.8",
46
+ "lint-staged": "^10.5.4",
47
+ "prettier": "^2.4.1",
48
+ "tslib": "^2.3.1",
49
+ "typescript": "^4.5.2"
50
+ },
51
+ "customElements": "custom-elements.json",
52
+ "eslintConfig": {
53
+ "parser": "@typescript-eslint/parser",
54
+ "extends": [
55
+ "@open-wc",
56
+ "prettier"
57
+ ],
58
+ "plugins": [
59
+ "@typescript-eslint"
60
+ ],
61
+ "rules": {
62
+ "no-unused-vars": "off",
63
+ "@typescript-eslint/no-unused-vars": [
64
+ "error"
65
+ ],
66
+ "import/no-unresolved": "off",
67
+ "import/extensions": [
68
+ "error",
69
+ "always",
70
+ {
71
+ "ignorePackages": true
72
+ }
73
+ ]
74
+ }
75
+ },
76
+ "prettier": {
77
+ "singleQuote": true,
78
+ "arrowParens": "avoid"
79
+ },
80
+ "husky": {
81
+ "hooks": {
82
+ "pre-commit": "lint-staged"
83
+ }
84
+ },
85
+ "lint-staged": {
86
+ "*.ts": [
87
+ "eslint --fix",
88
+ "prettier --write"
89
+ ]
90
+ },
91
+ "files": [
92
+ "/dist",
93
+ "!/dist/test",
94
+ "package.json",
95
+ "README.md",
96
+ "LICENSE"
97
+ ],
98
+ "gitHead": "ab9691521eda862a6136ca9c967a09b518dcc516"
99
+ }