@operato/input 1.0.0-alpha.45 → 1.0.0-alpha.48
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/CHANGELOG.md +33 -0
- package/demo/index-work-shift.html +59 -0
- package/demo/index.html +1 -0
- package/dist/src/ox-form-field.d.ts +2 -2
- package/dist/src/ox-form-field.js.map +1 -1
- package/dist/src/ox-input-barcode.d.ts +1 -1
- package/dist/src/ox-input-barcode.js +1 -1
- package/dist/src/ox-input-barcode.js.map +1 -1
- package/dist/src/ox-input-search.d.ts +1 -0
- package/dist/src/ox-input-search.js +7 -1
- package/dist/src/ox-input-search.js.map +1 -1
- package/dist/src/ox-input-work-shift.d.ts +33 -0
- package/dist/src/ox-input-work-shift.js +229 -0
- package/dist/src/ox-input-work-shift.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -8
- package/src/ox-form-field.ts +2 -2
- package/src/ox-input-barcode.ts +2 -3
- package/src/ox-input-search.ts +9 -1
- package/src/ox-input-work-shift.ts +251 -0
- package/dist/src/ox-input-id.d.ts +0 -11
- package/dist/src/ox-input-id.js +0 -68
- package/dist/src/ox-input-id.js.map +0 -1
@@ -0,0 +1,251 @@
|
|
1
|
+
/**
|
2
|
+
* @license Copyright © HatioLab Inc. All rights reserved.
|
3
|
+
*/
|
4
|
+
|
5
|
+
import './ox-input-color'
|
6
|
+
|
7
|
+
import { css, html } from 'lit'
|
8
|
+
import { customElement, property } from 'lit/decorators.js'
|
9
|
+
|
10
|
+
import { OxFormField } from './ox-form-field.js'
|
11
|
+
|
12
|
+
type WorkShift = { name: string; fromDate: number; fromTime: string; toDate: number; toTime: string }
|
13
|
+
|
14
|
+
/**
|
15
|
+
work-shift array value editor element
|
16
|
+
|
17
|
+
Example:
|
18
|
+
|
19
|
+
<ox-input-work-shift
|
20
|
+
.value=${value}
|
21
|
+
</ox-input-work-shift>
|
22
|
+
*/
|
23
|
+
|
24
|
+
@customElement('ox-input-work-shift')
|
25
|
+
export class OxInputWorkShift extends OxFormField {
|
26
|
+
static styles = css`
|
27
|
+
:host {
|
28
|
+
display: flex;
|
29
|
+
flex-direction: column;
|
30
|
+
align-content: center;
|
31
|
+
|
32
|
+
width: 100%;
|
33
|
+
overflow: hidden;
|
34
|
+
border: 1px solid #ccc;
|
35
|
+
}
|
36
|
+
|
37
|
+
div {
|
38
|
+
display: flex;
|
39
|
+
flex-flow: row nowrap;
|
40
|
+
align-items: center;
|
41
|
+
|
42
|
+
border-bottom: 1px solid #c0c0c0;
|
43
|
+
}
|
44
|
+
|
45
|
+
div:last-child {
|
46
|
+
border-bottom: none;
|
47
|
+
}
|
48
|
+
|
49
|
+
div > * {
|
50
|
+
min-width: 0px;
|
51
|
+
margin: 2px;
|
52
|
+
padding: 0;
|
53
|
+
}
|
54
|
+
|
55
|
+
button,
|
56
|
+
empty-element {
|
57
|
+
width: 20px;
|
58
|
+
text-align: center;
|
59
|
+
}
|
60
|
+
|
61
|
+
input,
|
62
|
+
select,
|
63
|
+
span {
|
64
|
+
flex: 1;
|
65
|
+
}
|
66
|
+
|
67
|
+
input:required:invalid {
|
68
|
+
border: 1px dashed red;
|
69
|
+
}
|
70
|
+
|
71
|
+
[placeholder='value'] {
|
72
|
+
flex: 2;
|
73
|
+
}
|
74
|
+
|
75
|
+
div {
|
76
|
+
border-bottom: 1px solid #c0c0c0;
|
77
|
+
}
|
78
|
+
|
79
|
+
div:last-child {
|
80
|
+
border-bottom: none;
|
81
|
+
}
|
82
|
+
`
|
83
|
+
|
84
|
+
@property({ type: Object }) value: WorkShift[] = []
|
85
|
+
|
86
|
+
private _changingNow: boolean = false
|
87
|
+
|
88
|
+
firstUpdated() {
|
89
|
+
this.renderRoot.addEventListener('change', this._onChange.bind(this))
|
90
|
+
}
|
91
|
+
|
92
|
+
render() {
|
93
|
+
return html`
|
94
|
+
<div data-header>
|
95
|
+
<span>name</span>
|
96
|
+
<span>from date</span>
|
97
|
+
<span>from time</span>
|
98
|
+
<span>to date</span>
|
99
|
+
<span>to time</span>
|
100
|
+
<empty-element></empty-element>
|
101
|
+
</div>
|
102
|
+
|
103
|
+
${this.value.map(
|
104
|
+
item => html`
|
105
|
+
<div data-record>
|
106
|
+
<input type="text" data-name .value=${item.name} required />
|
107
|
+
|
108
|
+
<select data-from-date .value=${item.fromDate || 0}>
|
109
|
+
<option value="-1">The day before</option>
|
110
|
+
<option value="0">The day</option>
|
111
|
+
<option value="1">The day after</option>
|
112
|
+
</select>
|
113
|
+
<input type="time" data-from-time .value=${item.fromTime} step="1800" required />
|
114
|
+
|
115
|
+
<select data-to-date .value=${item.toDate || 0}>
|
116
|
+
<option value="-1">The day before</option>
|
117
|
+
<option value="0">The day</option>
|
118
|
+
<option value="1">The day after</option>
|
119
|
+
</select>
|
120
|
+
<input type="time" data-to-time .value=${item.toTime} step="1800" required />
|
121
|
+
|
122
|
+
<button class="record-action" @click=${(e: Event) => this._delete(e)} tabindex="-1">-</button>
|
123
|
+
</div>
|
124
|
+
`
|
125
|
+
)}
|
126
|
+
|
127
|
+
<div data-record-new>
|
128
|
+
<input type="text" data-name />
|
129
|
+
|
130
|
+
<select data-from-date>
|
131
|
+
<option value="-1">The day before</option>
|
132
|
+
<option value="0" selected>The day</option>
|
133
|
+
<option value="+1">The day after</option>
|
134
|
+
</select>
|
135
|
+
<input type="time" data-from-time step="1800" />
|
136
|
+
|
137
|
+
<select data-to-date>
|
138
|
+
<option value="-1">The day before</option>
|
139
|
+
<option value="0" selected>The day</option>
|
140
|
+
<option value="+1">The day after</option>
|
141
|
+
</select>
|
142
|
+
<input type="time" data-to-time step="1800" />
|
143
|
+
|
144
|
+
<button class="record-action" @click=${(e: Event) => this._add()} tabindex="-1">+</button>
|
145
|
+
</div>
|
146
|
+
`
|
147
|
+
}
|
148
|
+
|
149
|
+
_onChange(e: Event) {
|
150
|
+
if (this._changingNow) {
|
151
|
+
return
|
152
|
+
}
|
153
|
+
|
154
|
+
this._changingNow = true
|
155
|
+
|
156
|
+
const input = e.target as HTMLInputElement
|
157
|
+
|
158
|
+
const div = input.parentElement as HTMLDivElement
|
159
|
+
|
160
|
+
if (div.hasAttribute('data-record')) {
|
161
|
+
this._build()
|
162
|
+
} else if (div.hasAttribute('data-record-new') && input.hasAttribute('data-value')) {
|
163
|
+
this._add()
|
164
|
+
}
|
165
|
+
|
166
|
+
this._changingNow = false
|
167
|
+
}
|
168
|
+
|
169
|
+
_build(includeNewRecord?: boolean) {
|
170
|
+
if (includeNewRecord) {
|
171
|
+
var records = this.renderRoot.querySelectorAll('[data-record],[data-record-new]')
|
172
|
+
} else {
|
173
|
+
var records = this.renderRoot.querySelectorAll('[data-record]')
|
174
|
+
}
|
175
|
+
|
176
|
+
var value: WorkShift[] = []
|
177
|
+
for (var i = 0; i < records.length; i++) {
|
178
|
+
const record = records[i]
|
179
|
+
|
180
|
+
const name = (record.querySelector('[data-name]') as HTMLInputElement).value
|
181
|
+
|
182
|
+
const fromDate = (record.querySelector('[data-from-date]') as HTMLSelectElement).value
|
183
|
+
const fromTime = (record.querySelector('[data-from-time]') as HTMLInputElement).value
|
184
|
+
const toDate = (record.querySelector('[data-to-date]') as HTMLSelectElement).value
|
185
|
+
const toTime = (record.querySelector('[data-to-time]') as HTMLInputElement).value
|
186
|
+
|
187
|
+
if (!name) {
|
188
|
+
;(record.querySelector('[data-name]') as HTMLInputElement).focus()
|
189
|
+
return
|
190
|
+
}
|
191
|
+
|
192
|
+
if (!fromDate) {
|
193
|
+
;(record.querySelector('[data-from-date]') as HTMLInputElement).focus()
|
194
|
+
return
|
195
|
+
}
|
196
|
+
|
197
|
+
if (!fromTime) {
|
198
|
+
;(record.querySelector('[data-from-time]') as HTMLInputElement).focus()
|
199
|
+
return
|
200
|
+
}
|
201
|
+
|
202
|
+
if (!toDate) {
|
203
|
+
;(record.querySelector('[data-to-date]') as HTMLInputElement).focus()
|
204
|
+
return
|
205
|
+
}
|
206
|
+
|
207
|
+
if (!toTime) {
|
208
|
+
;(record.querySelector('[data-to-time]') as HTMLInputElement).focus()
|
209
|
+
return
|
210
|
+
}
|
211
|
+
|
212
|
+
if (name) {
|
213
|
+
value.push({
|
214
|
+
name,
|
215
|
+
fromDate: Number(fromDate),
|
216
|
+
fromTime,
|
217
|
+
toDate: Number(toDate),
|
218
|
+
toTime
|
219
|
+
})
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
this.value = value
|
224
|
+
|
225
|
+
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true, detail: this.value }))
|
226
|
+
}
|
227
|
+
|
228
|
+
_add() {
|
229
|
+
this._build(true)
|
230
|
+
|
231
|
+
const inputs = this.renderRoot.querySelectorAll(
|
232
|
+
'[data-record-new] input:not([style*="display: none"])'
|
233
|
+
) as NodeListOf<HTMLInputElement & { value: any; type: string }>
|
234
|
+
|
235
|
+
for (var i = 0; i < inputs.length; i++) {
|
236
|
+
let input = inputs[i]
|
237
|
+
input.value = ''
|
238
|
+
}
|
239
|
+
|
240
|
+
inputs[0].focus()
|
241
|
+
}
|
242
|
+
|
243
|
+
_delete(e: Event) {
|
244
|
+
const record = (e.target as Element).parentElement
|
245
|
+
|
246
|
+
const dataName = record!.querySelector('[data-name]') as HTMLInputElement
|
247
|
+
dataName.name = ''
|
248
|
+
|
249
|
+
this._build()
|
250
|
+
}
|
251
|
+
}
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import { OxFormField } from './ox-form-field';
|
2
|
-
export declare class OxInputId extends OxFormField {
|
3
|
-
static styles: import("lit").CSSResult;
|
4
|
-
property: {
|
5
|
-
component?: string;
|
6
|
-
} | null | undefined;
|
7
|
-
_ids: Array<string>;
|
8
|
-
render(): import("lit-html").TemplateResult<1>;
|
9
|
-
_onInputFocused(e: FocusEvent): void;
|
10
|
-
_onInputChanged(e: InputEvent): void;
|
11
|
-
}
|
package/dist/src/ox-input-id.js
DELETED
@@ -1,68 +0,0 @@
|
|
1
|
-
import { __decorate } from "tslib";
|
2
|
-
import { css, html } from 'lit';
|
3
|
-
import { customElement, property, state } from 'lit/decorators.js';
|
4
|
-
import { OxFormField } from './ox-form-field';
|
5
|
-
let OxInputId = class OxInputId extends OxFormField {
|
6
|
-
constructor() {
|
7
|
-
super(...arguments);
|
8
|
-
this._ids = [];
|
9
|
-
}
|
10
|
-
static { this.styles = css `
|
11
|
-
:host {
|
12
|
-
position: relative;
|
13
|
-
display: inline-flex;
|
14
|
-
align-items: center;
|
15
|
-
justify-content: flex-end;
|
16
|
-
}
|
17
|
-
|
18
|
-
input {
|
19
|
-
width: 100%;
|
20
|
-
height: 100%;
|
21
|
-
box-sizing: border-box;
|
22
|
-
border: 1px solid rgba(0, 0, 0, 0.2);
|
23
|
-
}
|
24
|
-
`; }
|
25
|
-
render() {
|
26
|
-
const ids = this._ids || [];
|
27
|
-
return html `
|
28
|
-
<input
|
29
|
-
id="text"
|
30
|
-
type="text"
|
31
|
-
.value=${this.value || ''}
|
32
|
-
@focusin=${(e) => this._onInputFocused(e)}
|
33
|
-
@change=${(e) => this._onInputChanged(e)}
|
34
|
-
.placeholder=${this.getAttribute('placeholder') || ''}
|
35
|
-
list="ids"
|
36
|
-
/>
|
37
|
-
|
38
|
-
<datalist id="ids">${ids.map(id => html ` <option value=${id}></option> `)}</datalist>
|
39
|
-
`;
|
40
|
-
}
|
41
|
-
_onInputFocused(e) {
|
42
|
-
var { component } = this.property || {};
|
43
|
-
document.dispatchEvent(new CustomEvent('get-all-scene-component-ids', {
|
44
|
-
detail: {
|
45
|
-
component,
|
46
|
-
callback: (ids) => {
|
47
|
-
this._ids = ids;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
}));
|
51
|
-
}
|
52
|
-
_onInputChanged(e) {
|
53
|
-
e.stopPropagation();
|
54
|
-
this.value = e.target.value;
|
55
|
-
this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }));
|
56
|
-
}
|
57
|
-
};
|
58
|
-
__decorate([
|
59
|
-
property({ type: Object })
|
60
|
-
], OxInputId.prototype, "property", void 0);
|
61
|
-
__decorate([
|
62
|
-
state()
|
63
|
-
], OxInputId.prototype, "_ids", void 0);
|
64
|
-
OxInputId = __decorate([
|
65
|
-
customElement('ox-input-id')
|
66
|
-
], OxInputId);
|
67
|
-
export { OxInputId };
|
68
|
-
//# sourceMappingURL=ox-input-id.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"ox-input-id.js","sourceRoot":"","sources":["../../src/ox-input-id.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAA;AAC/B,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAElE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG7C,IAAa,SAAS,GAAtB,MAAa,SAAU,SAAQ,WAAW;IAA1C;;QAmBW,SAAI,GAAkB,EAAE,CAAA;IA0CnC,CAAC;aA5DQ,WAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;GAclB,CAAA;IAMD,MAAM;QACJ,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,IAAI,EAAE,CAAA;QAE3B,OAAO,IAAI,CAAA;;;;iBAIE,IAAI,CAAC,KAAK,IAAI,EAAE;mBACd,CAAC,CAAa,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;kBAC3C,CAAC,CAAa,EAAE,EAAE,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC;uBACrC,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,IAAI,EAAE;;;;2BAIlC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CAAA,kBAAkB,EAAE,aAAa,CAAC;KAC1E,CAAA;IACH,CAAC;IAED,eAAe,CAAC,CAAa;QAC3B,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,QAAQ,IAAI,EAAE,CAAA;QAEvC,QAAQ,CAAC,aAAa,CACpB,IAAI,WAAW,CAAC,6BAA6B,EAAE;YAC7C,MAAM,EAAE;gBACN,SAAS;gBACT,QAAQ,EAAE,CAAC,GAAa,EAAE,EAAE;oBAC1B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;gBACjB,CAAC;aACF;SACF,CAAC,CACH,CAAA;IACH,CAAC;IAED,eAAe,CAAC,CAAa;QAC3B,CAAC,CAAC,eAAe,EAAE,CAAA;QAEnB,IAAI,CAAC,KAAK,GAAI,CAAC,CAAC,MAA2B,CAAC,KAAK,CAAA;QAEjD,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;IAClF,CAAC;CACF,CAAA;AA5C6B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;2CAAoD;AAEtE;IAAR,KAAK,EAAE;uCAAyB;AAnBtB,SAAS;IADrB,aAAa,CAAC,aAAa,CAAC;GAChB,SAAS,CA6DrB;SA7DY,SAAS","sourcesContent":["import { css, html } from 'lit'\nimport { customElement, property, state } from 'lit/decorators.js'\n\nimport { OxFormField } from './ox-form-field'\n\n@customElement('ox-input-id')\nexport class OxInputId extends OxFormField {\n static styles = css`\n :host {\n position: relative;\n display: inline-flex;\n align-items: center;\n justify-content: flex-end;\n }\n\n input {\n width: 100%;\n height: 100%;\n box-sizing: border-box;\n border: 1px solid rgba(0, 0, 0, 0.2);\n }\n `\n\n @property({ type: Object }) property: { component?: string } | null | undefined\n\n @state() _ids: Array<string> = []\n\n render() {\n const ids = this._ids || []\n\n return html`\n <input\n id=\"text\"\n type=\"text\"\n .value=${this.value || ''}\n @focusin=${(e: FocusEvent) => this._onInputFocused(e)}\n @change=${(e: InputEvent) => this._onInputChanged(e)}\n .placeholder=${this.getAttribute('placeholder') || ''}\n list=\"ids\"\n />\n\n <datalist id=\"ids\">${ids.map(id => html` <option value=${id}></option> `)}</datalist>\n `\n }\n\n _onInputFocused(e: FocusEvent) {\n var { component } = this.property || {}\n\n document.dispatchEvent(\n new CustomEvent('get-all-scene-component-ids', {\n detail: {\n component,\n callback: (ids: string[]) => {\n this._ids = ids\n }\n }\n })\n )\n }\n\n _onInputChanged(e: InputEvent) {\n e.stopPropagation()\n\n this.value = (e.target as HTMLInputElement).value\n\n this.dispatchEvent(new CustomEvent('change', { bubbles: true, composed: true }))\n }\n}\n"]}
|