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 _DuoyunShortcutRecordElement_instances, _DuoyunShortcutRecordElement_tooltip_get, _DuoyunShortcutRecordElement_onKeydown;
|
13 | var DuoyunShortcutRecordElement_1;
|
14 | import { adoptedStyle, customElement, attribute, globalemitter, property, boolattribute, part, } from '@mantou/gem/lib/decorators';
|
15 | import { GemElement, html } from '@mantou/gem/lib/element';
|
16 | import { createCSSSheet, css } from '@mantou/gem/lib/utils';
|
17 | import { theme } from '../lib/theme';
|
18 | import { isNotNullish } from '../lib/types';
|
19 | import { normalizeKey, getDisplayKey } from '../lib/hotkeys';
|
20 | import { focusStyle } from '../lib/styles';
|
21 | import './paragraph';
|
22 | const style = createCSSSheet(css `
|
23 | :host(:where(:not([hidden]))) {
|
24 | display: inline-flex;
|
25 | align-items: center;
|
26 | font-size: 0.875em;
|
27 | box-sizing: border-box;
|
28 | width: 15em;
|
29 | height: calc(2.2em + 2px);
|
30 | padding-inline: 0.4em;
|
31 | gap: 0.2em;
|
32 | border-radius: ${theme.normalRound};
|
33 | border: 1px solid ${theme.borderColor};
|
34 | white-space: nowrap;
|
35 | }
|
36 | :host(:focus) {
|
37 | border-color: ${theme.textColor};
|
38 | background-color: ${theme.lightBackgroundColor};
|
39 | }
|
40 | .paragraph {
|
41 | display: contents;
|
42 | line-height: 1.2;
|
43 | }
|
44 | .placeholder,
|
45 | .tooltip {
|
46 | color: ${theme.describeColor};
|
47 | -webkit-user-select: none;
|
48 | user-select: none;
|
49 | }
|
50 | :host(:focus) .placeholder {
|
51 | display: none;
|
52 | }
|
53 | .tooltip {
|
54 | font-style: italic;
|
55 | }
|
56 | :host(:not(:focus)) .tooltip {
|
57 | display: none;
|
58 | }
|
59 | `);
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | let DuoyunShortcutRecordElement = DuoyunShortcutRecordElement_1 = class DuoyunShortcutRecordElement extends GemElement {
|
67 | constructor() {
|
68 | super();
|
69 | _DuoyunShortcutRecordElement_instances.add(this);
|
70 | _DuoyunShortcutRecordElement_onKeydown.set(this, (evt) => {
|
71 | const keys = [
|
72 | ...new Set([
|
73 | evt.ctrlKey ? 'ctrl' : null,
|
74 | evt.metaKey ? 'meta' : null,
|
75 | evt.shiftKey ? 'shift' : null,
|
76 | evt.altKey ? 'alt' : null,
|
77 | evt.code,
|
78 | ]
|
79 | .filter(isNotNullish)
|
80 | .map(normalizeKey)),
|
81 | ];
|
82 | this.change(keys);
|
83 | evt.stopPropagation();
|
84 | evt.preventDefault();
|
85 | });
|
86 | this.render = () => {
|
87 | return html `
|
88 | <dy-paragraph class="paragraph">
|
89 | ${this.value
|
90 | ? html `${this.value.map((key) => html `<kbd part=${DuoyunShortcutRecordElement_1.kbd}>${getDisplayKey(key)}</kbd>`)}`
|
91 | : html `
|
92 | <div class="placeholder">${this.placeholder}</div>
|
93 | <div class="tooltip">${__classPrivateFieldGet(this, _DuoyunShortcutRecordElement_instances, "a", _DuoyunShortcutRecordElement_tooltip_get)}</div>
|
94 | `}
|
95 | </dy-paragraph>
|
96 | `;
|
97 | };
|
98 | this.internals.role = 'input';
|
99 | this.addEventListener('keydown', __classPrivateFieldGet(this, _DuoyunShortcutRecordElement_onKeydown, "f"));
|
100 | this.effect(() => {
|
101 | if (this.disabled) {
|
102 | this.removeAttribute('tabindex');
|
103 | }
|
104 | else {
|
105 | this.tabIndex = 0;
|
106 | }
|
107 | this.internals.ariaDisabled = String(this.disabled);
|
108 | });
|
109 | }
|
110 | };
|
111 | _DuoyunShortcutRecordElement_onKeydown = new WeakMap(), _DuoyunShortcutRecordElement_instances = new WeakSet(), _DuoyunShortcutRecordElement_tooltip_get = function _DuoyunShortcutRecordElement_tooltip_get() {
|
112 | return this.tooltip || 'Please keypress...';
|
113 | };
|
114 | __decorate([
|
115 | attribute
|
116 | ], DuoyunShortcutRecordElement.prototype, "placeholder", void 0);
|
117 | __decorate([
|
118 | attribute
|
119 | ], DuoyunShortcutRecordElement.prototype, "tooltip", void 0);
|
120 | __decorate([
|
121 | boolattribute
|
122 | ], DuoyunShortcutRecordElement.prototype, "disabled", void 0);
|
123 | __decorate([
|
124 | globalemitter
|
125 | ], DuoyunShortcutRecordElement.prototype, "change", void 0);
|
126 | __decorate([
|
127 | property
|
128 | ], DuoyunShortcutRecordElement.prototype, "value", void 0);
|
129 | __decorate([
|
130 | part
|
131 | ], DuoyunShortcutRecordElement, "kbd", void 0);
|
132 | DuoyunShortcutRecordElement = DuoyunShortcutRecordElement_1 = __decorate([
|
133 | customElement('dy-shortcut-record'),
|
134 | adoptedStyle(style),
|
135 | adoptedStyle(focusStyle)
|
136 | ], DuoyunShortcutRecordElement);
|
137 | export { DuoyunShortcutRecordElement };
|
138 |
|
\ | No newline at end of file |