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 _DuoyunDatePickElement_instances, _DuoyunDatePickElement_value_get, _DuoyunDatePickElement_valueString_get, _DuoyunDatePickElement_onSubmit, _DuoyunDatePickElement_onOpen, _DuoyunDatePickElement_onClear;
|
13 | import { connectStore, 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 './use';
|
26 | import './date-panel';
|
27 | import './button';
|
28 | const style = createCSSSheet(css `
|
29 | :host {
|
30 | width: 15em;
|
31 | }
|
32 | .value {
|
33 | flex-grow: 1;
|
34 | overflow: hidden;
|
35 | text-overflow: ellipsis;
|
36 | white-space: nowrap;
|
37 | }
|
38 | .placeholder {
|
39 | color: ${theme.describeColor};
|
40 | }
|
41 | .icon {
|
42 | display: flex;
|
43 | }
|
44 | .close,
|
45 | :host(:not([disabled])) .clearable:hover .date {
|
46 | display: none;
|
47 | }
|
48 | :host(:not([disabled])) .clearable:hover .close {
|
49 | display: inline-flex;
|
50 | }
|
51 | `);
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 | let DuoyunDatePickElement = class DuoyunDatePickElement extends GemElement {
|
62 | constructor() {
|
63 | super();
|
64 | _DuoyunDatePickElement_instances.add(this);
|
65 | _DuoyunDatePickElement_onSubmit.set(this, ({ detail }) => {
|
66 | this.change(detail);
|
67 | ContextMenu.close();
|
68 | });
|
69 | _DuoyunDatePickElement_onOpen.set(this, () => {
|
70 | if (this.disabled)
|
71 | return;
|
72 | let v = undefined;
|
73 | const onChange = ({ detail, target }) => {
|
74 | const panel = target;
|
75 | panel.highlights = [];
|
76 | panel.value = detail;
|
77 | const root = panel.getRootNode();
|
78 | const button = root.querySelector('dy-button');
|
79 | button.disabled = false;
|
80 | v = detail;
|
81 | };
|
82 | const onSubmit = () => {
|
83 | if (isNotNullish(v)) {
|
84 | this.change(v);
|
85 | ContextMenu.close();
|
86 | }
|
87 | };
|
88 | ContextMenu.open(html `
|
89 | <dy-date-panel
|
90 | style="border: none;"
|
91 | .value=${__classPrivateFieldGet(this, _DuoyunDatePickElement_instances, "a", _DuoyunDatePickElement_value_get)}
|
92 | ?time=${this.time}
|
93 | @change=${this.time ? onChange : __classPrivateFieldGet(this, _DuoyunDatePickElement_onSubmit, "f")}
|
94 | ></dy-date-panel>
|
95 | ${this.time
|
96 | ? html `
|
97 | <style>
|
98 | .footer {
|
99 | margin-block-start: 2em;
|
100 | display: flex;
|
101 | justify-content: flex-end;
|
102 | }
|
103 | </style>
|
104 | <div class="footer">
|
105 | <dy-button disabled @click=${onSubmit} small>${locale.ok}</dy-button>
|
106 | </div>
|
107 | `
|
108 | : ''}
|
109 | `, {
|
110 | activeElement: this,
|
111 | width: this.time ? '30em' : undefined,
|
112 | });
|
113 | });
|
114 | _DuoyunDatePickElement_onClear.set(this, (e) => {
|
115 | e.stopPropagation();
|
116 | this.clear(null);
|
117 | });
|
118 | this.mounted = () => {
|
119 | return () => this.active && ContextMenu.close();
|
120 | };
|
121 | this.render = () => {
|
122 | return html `
|
123 | <div class=${classMap({ value: true, placeholder: !__classPrivateFieldGet(this, _DuoyunDatePickElement_instances, "a", _DuoyunDatePickElement_value_get) })}>${__classPrivateFieldGet(this, _DuoyunDatePickElement_instances, "a", _DuoyunDatePickElement_valueString_get) || this.placeholder}</div>
|
124 | <div class=${classMap({ icon: true, clearable: this.clearable })}>
|
125 | <dy-use class="date" .element=${icons.date}></dy-use>
|
126 | <dy-use class="close" @click=${__classPrivateFieldGet(this, _DuoyunDatePickElement_onClear, "f")} .element=${icons.close}></dy-use>
|
127 | </div>
|
128 | `;
|
129 | };
|
130 | this.addEventListener('click', __classPrivateFieldGet(this, _DuoyunDatePickElement_onOpen, "f"));
|
131 | this.addEventListener('keydown', commonHandle);
|
132 | this.tabIndex = 0;
|
133 | this.internals.role = 'combobox';
|
134 | }
|
135 | showPicker() {
|
136 | __classPrivateFieldGet(this, _DuoyunDatePickElement_onOpen, "f").call(this);
|
137 | }
|
138 | };
|
139 | _DuoyunDatePickElement_onSubmit = new WeakMap(), _DuoyunDatePickElement_onOpen = new WeakMap(), _DuoyunDatePickElement_onClear = new WeakMap(), _DuoyunDatePickElement_instances = new WeakSet(), _DuoyunDatePickElement_value_get = function _DuoyunDatePickElement_value_get() {
|
140 | return isNotNullish(this.value) ? this.value : undefined;
|
141 | }, _DuoyunDatePickElement_valueString_get = function _DuoyunDatePickElement_valueString_get() {
|
142 | return __classPrivateFieldGet(this, _DuoyunDatePickElement_instances, "a", _DuoyunDatePickElement_value_get) && new Time(__classPrivateFieldGet(this, _DuoyunDatePickElement_instances, "a", _DuoyunDatePickElement_value_get)).format(this.time ? undefined : 'YYYY-MM-DD');
|
143 | };
|
144 | __decorate([
|
145 | attribute
|
146 | ], DuoyunDatePickElement.prototype, "placeholder", void 0);
|
147 | __decorate([
|
148 | boolattribute
|
149 | ], DuoyunDatePickElement.prototype, "time", void 0);
|
150 | __decorate([
|
151 | boolattribute
|
152 | ], DuoyunDatePickElement.prototype, "clearable", void 0);
|
153 | __decorate([
|
154 | boolattribute
|
155 | ], DuoyunDatePickElement.prototype, "disabled", void 0);
|
156 | __decorate([
|
157 | state
|
158 | ], DuoyunDatePickElement.prototype, "active", void 0);
|
159 | __decorate([
|
160 | property
|
161 | ], DuoyunDatePickElement.prototype, "value", void 0);
|
162 | __decorate([
|
163 | globalemitter
|
164 | ], DuoyunDatePickElement.prototype, "change", void 0);
|
165 | __decorate([
|
166 | emitter
|
167 | ], DuoyunDatePickElement.prototype, "clear", void 0);
|
168 | DuoyunDatePickElement = __decorate([
|
169 | customElement('dy-date-picker'),
|
170 | adoptedStyle(pickerStyle),
|
171 | adoptedStyle(style),
|
172 | adoptedStyle(focusStyle),
|
173 | connectStore(icons)
|
174 | ], DuoyunDatePickElement);
|
175 | export { DuoyunDatePickElement };
|
176 |
|
\ | No newline at end of file |