1 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6 | };
|
7 | var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
8 | if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
9 | if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10 | return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11 | };
|
12 | var _DuoyunTimePickElement_instances, _DuoyunTimePickElement_value_get, _DuoyunTimePickElement_valueString_get, _DuoyunTimePickElement_onOpen, _DuoyunTimePickElement_onClear;
|
13 | import { adoptedStyle, customElement, attribute, emitter, globalemitter, property, boolattribute, state, } from '@mantou/gem/lib/decorators';
|
14 | import { GemElement, html } from '@mantou/gem/lib/element';
|
15 | import { createCSSSheet, css, classMap } from '@mantou/gem/lib/utils';
|
16 | import { Time } from '../lib/time';
|
17 | import { theme } from '../lib/theme';
|
18 | import { icons } from '../lib/icons';
|
19 | import { locale } from '../lib/locale';
|
20 | import { isNotNullish } from '../lib/types';
|
21 | import { commonHandle } from '../lib/hotkeys';
|
22 | import { focusStyle } from '../lib/styles';
|
23 | import { ContextMenu } from './menu';
|
24 | import { pickerStyle } from './picker';
|
25 | import './time-panel';
|
26 | const style = createCSSSheet(css `
|
27 | :host {
|
28 | width: 10em;
|
29 | }
|
30 | .value {
|
31 | flex-grow: 1;
|
32 | overflow: hidden;
|
33 | text-overflow: ellipsis;
|
34 | white-space: nowrap;
|
35 | }
|
36 | .placeholder {
|
37 | color: ${theme.describeColor};
|
38 | }
|
39 | .icon {
|
40 | display: flex;
|
41 | }
|
42 | .close,
|
43 | :host(:not([disabled])) .clearable:hover .date {
|
44 | display: none;
|
45 | }
|
46 | :host(:not([disabled])) .clearable:hover .close {
|
47 | display: inline-flex;
|
48 | }
|
49 | `);
|
50 |
|
51 |
|
52 |
|
53 | let DuoyunTimePickElement = class DuoyunTimePickElement extends GemElement {
|
54 | constructor() {
|
55 | super();
|
56 | _DuoyunTimePickElement_instances.add(this);
|
57 | _DuoyunTimePickElement_onOpen.set(this, () => {
|
58 | if (this.disabled)
|
59 | return;
|
60 | let v = undefined;
|
61 | const onChange = ({ detail, target }) => {
|
62 | const panel = target;
|
63 | panel.value = detail;
|
64 | const root = panel.getRootNode();
|
65 | const button = root.querySelector('dy-button');
|
66 | button.disabled = false;
|
67 | v = detail;
|
68 | };
|
69 | const onSubmit = () => {
|
70 | if (isNotNullish(v)) {
|
71 | this.change(v);
|
72 | ContextMenu.close();
|
73 | }
|
74 | };
|
75 | ContextMenu.open(html `
|
76 | <div class="container">
|
77 | <style>
|
78 | .container {
|
79 | display: flex;
|
80 | flex-direction: column;
|
81 | height: 46vh;
|
82 | }
|
83 | dy-time-panel {
|
84 | box-sizing: border-box;
|
85 | height: 0;
|
86 | flex-grow: 1;
|
87 | }
|
88 | .footer {
|
89 | flex-shrink: 0;
|
90 | margin-block-start: 1em;
|
91 | display: flex;
|
92 | justify-content: flex-end;
|
93 | }
|
94 | </style>
|
95 | <dy-time-panel .value=${this.value} @change=${onChange}></dy-time-panel>
|
96 | <div class="footer">
|
97 | <dy-button disabled @click=${onSubmit} small>${locale.ok}</dy-button>
|
98 | </div>
|
99 | </div>
|
100 | `, {
|
101 | activeElement: this,
|
102 | });
|
103 | });
|
104 | _DuoyunTimePickElement_onClear.set(this, (e) => {
|
105 | e.stopPropagation();
|
106 | this.clear(null);
|
107 | });
|
108 | this.mounted = () => {
|
109 | return () => this.active && ContextMenu.close();
|
110 | };
|
111 | this.render = () => {
|
112 | return html `
|
113 | <div class=${classMap({ value: true, placeholder: !__classPrivateFieldGet(this, _DuoyunTimePickElement_instances, "a", _DuoyunTimePickElement_value_get) })}>${__classPrivateFieldGet(this, _DuoyunTimePickElement_instances, "a", _DuoyunTimePickElement_valueString_get) || this.placeholder}</div>
|
114 | <div class=${classMap({ icon: true, clearable: this.clearable })}>
|
115 | <dy-use class="date" .element=${icons.schedule}></dy-use>
|
116 | <dy-use class="close" @click=${__classPrivateFieldGet(this, _DuoyunTimePickElement_onClear, "f")} .element=${icons.close}></dy-use>
|
117 | </div>
|
118 | `;
|
119 | };
|
120 | this.addEventListener('click', __classPrivateFieldGet(this, _DuoyunTimePickElement_onOpen, "f"));
|
121 | this.addEventListener('keydown', commonHandle);
|
122 | this.tabIndex = 0;
|
123 | this.internals.role = 'combobox';
|
124 | }
|
125 | showPicker() {
|
126 | __classPrivateFieldGet(this, _DuoyunTimePickElement_onOpen, "f").call(this);
|
127 | }
|
128 | };
|
129 | _DuoyunTimePickElement_onOpen = new WeakMap(), _DuoyunTimePickElement_onClear = new WeakMap(), _DuoyunTimePickElement_instances = new WeakSet(), _DuoyunTimePickElement_value_get = function _DuoyunTimePickElement_value_get() {
|
130 | return isNotNullish(this.value) ? this.value : undefined;
|
131 | }, _DuoyunTimePickElement_valueString_get = function _DuoyunTimePickElement_valueString_get() {
|
132 | return __classPrivateFieldGet(this, _DuoyunTimePickElement_instances, "a", _DuoyunTimePickElement_value_get) && new Time(__classPrivateFieldGet(this, _DuoyunTimePickElement_instances, "a", _DuoyunTimePickElement_value_get)).format('HH:mm:ss');
|
133 | };
|
134 | __decorate([
|
135 | attribute
|
136 | ], DuoyunTimePickElement.prototype, "placeholder", void 0);
|
137 | __decorate([
|
138 | boolattribute
|
139 | ], DuoyunTimePickElement.prototype, "clearable", void 0);
|
140 | __decorate([
|
141 | boolattribute
|
142 | ], DuoyunTimePickElement.prototype, "disabled", void 0);
|
143 | __decorate([
|
144 | state
|
145 | ], DuoyunTimePickElement.prototype, "active", void 0);
|
146 | __decorate([
|
147 | property
|
148 | ], DuoyunTimePickElement.prototype, "value", void 0);
|
149 | __decorate([
|
150 | globalemitter
|
151 | ], DuoyunTimePickElement.prototype, "change", void 0);
|
152 | __decorate([
|
153 | emitter
|
154 | ], DuoyunTimePickElement.prototype, "clear", void 0);
|
155 | DuoyunTimePickElement = __decorate([
|
156 | customElement('dy-time-picker'),
|
157 | adoptedStyle(style),
|
158 | adoptedStyle(pickerStyle),
|
159 | adoptedStyle(focusStyle)
|
160 | ], DuoyunTimePickElement);
|
161 | export { DuoyunTimePickElement };
|
162 |
|
\ | No newline at end of file |