@manohub/ui 1.1.1 → 1.1.3
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/README.md +2 -2
- package/dist/components/code-block/index.js +7 -2
- package/dist/components/date-picker/calendar.d.ts +78 -0
- package/dist/components/date-picker/calendar.js +91 -0
- package/dist/components/date-picker/date-panel.d.ts +312 -0
- package/dist/components/date-picker/date-panel.js +265 -0
- package/dist/components/date-picker/date-time-row.d.ts +84 -0
- package/dist/components/date-picker/date-time-row.js +105 -0
- package/dist/components/date-picker/index.d.ts +863 -0
- package/dist/components/date-picker/index.js +549 -0
- package/dist/components/date-picker/panel.d.ts +73 -0
- package/dist/components/date-picker/panel.js +53 -0
- package/dist/components/date-picker/shared.d.ts +37 -0
- package/dist/components/date-picker/shared.js +20 -0
- package/dist/components/date-picker/trigger.d.ts +147 -0
- package/dist/components/date-picker/trigger.js +107 -0
- package/dist/components/input/composition.d.ts +25 -0
- package/dist/components/input/composition.js +31 -0
- package/dist/components/input/index.d.ts +5 -5
- package/dist/components/input/index.js +91 -12
- package/dist/components/search/index.d.ts +1 -1
- package/dist/components/select/index.d.ts +5 -2
- package/dist/components/select/select-panel.d.ts +3 -0
- package/dist/components/table/index.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -0
- package/dist/styles/components/date-picker.css +278 -0
- package/dist/styles/components/date-picker.tokens.css +14 -0
- package/dist/styles/components/select.css +3 -33
- package/dist/styles/components/select.tokens.css +0 -1
- package/dist/styles/components/table.css +15 -1
- package/dist/styles/components/table.tokens.css +1 -1
- package/dist/styles/index.css +2 -0
- package/dist/utils/state-illustration.d.ts +1 -14
- package/dist/utils/state-illustration.js +81 -69
- package/package.json +2 -2
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import { defineComponent, ref, computed, createVNode, watch, nextTick } from "vue";
|
|
2
|
+
import { DatePanel } from "./date-panel.js";
|
|
3
|
+
import { DatePanelShell } from "./panel.js";
|
|
4
|
+
import { DateTrigger } from "./trigger.js";
|
|
5
|
+
import { createPanelId, hidePanel, showPanel, createTriggerKeydown } from "./shared.js";
|
|
6
|
+
import { parseTime, timePartOf, displayDateTime, datePartOf, todayISO, monthOf, parseDate, nowTime, nowDateTime, joinDateTime, formatTime } from "./calendar.js";
|
|
7
|
+
const CELL_SELECTOR = {
|
|
8
|
+
date: ".mh-date-picker__date",
|
|
9
|
+
month: ".mh-date-picker__cal-month"
|
|
10
|
+
};
|
|
11
|
+
const KEY_OFFSETS = {
|
|
12
|
+
date: {
|
|
13
|
+
ArrowLeft: -1,
|
|
14
|
+
ArrowRight: 1,
|
|
15
|
+
ArrowUp: -7,
|
|
16
|
+
ArrowDown: 7
|
|
17
|
+
},
|
|
18
|
+
month: {
|
|
19
|
+
ArrowLeft: -1,
|
|
20
|
+
ArrowRight: 1,
|
|
21
|
+
ArrowUp: -3,
|
|
22
|
+
ArrowDown: 3
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
function useDatePanel(options) {
|
|
26
|
+
const today = todayISO();
|
|
27
|
+
const panelId = createPanelId();
|
|
28
|
+
const hostRef = ref(null);
|
|
29
|
+
const panelRef = ref(null);
|
|
30
|
+
const panelOpen = ref(false);
|
|
31
|
+
const view = ref(monthOf(parseDate(options.anchor()) ?? /* @__PURE__ */ new Date()));
|
|
32
|
+
const mode = ref("date");
|
|
33
|
+
const preview = ref(void 0);
|
|
34
|
+
const setPreview = (iso) => {
|
|
35
|
+
preview.value = options.previewing() ? iso : void 0;
|
|
36
|
+
};
|
|
37
|
+
const clearPreview = () => {
|
|
38
|
+
preview.value = void 0;
|
|
39
|
+
};
|
|
40
|
+
const shiftMonth = (delta) => {
|
|
41
|
+
view.value = monthOf(new Date(view.value.year, view.value.month + delta, 1));
|
|
42
|
+
};
|
|
43
|
+
const shiftYear = (delta) => {
|
|
44
|
+
view.value = {
|
|
45
|
+
year: view.value.year + delta,
|
|
46
|
+
month: view.value.month
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const toggleMode = () => {
|
|
50
|
+
mode.value = mode.value === "date" ? "month" : "date";
|
|
51
|
+
};
|
|
52
|
+
const pickMonth = (month) => {
|
|
53
|
+
view.value = {
|
|
54
|
+
year: view.value.year,
|
|
55
|
+
month
|
|
56
|
+
};
|
|
57
|
+
mode.value = "date";
|
|
58
|
+
void nextTick(focusInitial);
|
|
59
|
+
};
|
|
60
|
+
const cellButtons = () => [...panelRef.value?.querySelectorAll(CELL_SELECTOR[mode.value]) ?? []];
|
|
61
|
+
const focusInitial = () => {
|
|
62
|
+
const panel = panelRef.value;
|
|
63
|
+
if (!panel) return;
|
|
64
|
+
const target = panel.querySelector('.mh-date-picker__date[data-state="selected"]') ?? panel.querySelector(".mh-date-picker__date--today") ?? cellButtons().find((button) => !button.disabled);
|
|
65
|
+
target?.focus();
|
|
66
|
+
};
|
|
67
|
+
const focusByOffset = (offset) => {
|
|
68
|
+
const buttons = cellButtons();
|
|
69
|
+
if (!buttons.length) return;
|
|
70
|
+
const size = buttons.length;
|
|
71
|
+
const at = buttons.findIndex((button) => button === document.activeElement);
|
|
72
|
+
const step = offset > 0 ? 1 : -1;
|
|
73
|
+
let index = ((at < 0 ? step > 0 ? -1 : 0 : at) + offset + size * 2) % size;
|
|
74
|
+
for (let guard = 0; guard < size && buttons[index].disabled; guard += 1) {
|
|
75
|
+
index = (index + step + size) % size;
|
|
76
|
+
}
|
|
77
|
+
const target = buttons[index];
|
|
78
|
+
target?.focus();
|
|
79
|
+
setPreview(target?.getAttribute("aria-label") ?? void 0);
|
|
80
|
+
};
|
|
81
|
+
const onCellKeydown = (event) => {
|
|
82
|
+
const offset = KEY_OFFSETS[mode.value][event.key];
|
|
83
|
+
if (offset === void 0) return;
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
focusByOffset(offset);
|
|
86
|
+
};
|
|
87
|
+
const hide = () => {
|
|
88
|
+
clearPreview();
|
|
89
|
+
hidePanel(panelRef.value);
|
|
90
|
+
};
|
|
91
|
+
const show = () => {
|
|
92
|
+
view.value = monthOf(parseDate(options.anchor()) ?? /* @__PURE__ */ new Date());
|
|
93
|
+
mode.value = "date";
|
|
94
|
+
clearPreview();
|
|
95
|
+
options.onShow?.();
|
|
96
|
+
panelOpen.value = true;
|
|
97
|
+
showPanel(panelRef.value);
|
|
98
|
+
void nextTick(focusInitial);
|
|
99
|
+
};
|
|
100
|
+
const onToggle = (event) => {
|
|
101
|
+
const opening = event.newState === "open";
|
|
102
|
+
panelOpen.value = opening;
|
|
103
|
+
if (opening) return;
|
|
104
|
+
clearPreview();
|
|
105
|
+
if (!panelRef.value?.contains(document.activeElement)) return;
|
|
106
|
+
hostRef.value?.querySelector(".mh-date-picker")?.focus();
|
|
107
|
+
};
|
|
108
|
+
const onTriggerKeydown = (event) => createTriggerKeydown({
|
|
109
|
+
clearable: options.clearable(),
|
|
110
|
+
disabled: options.disabled(),
|
|
111
|
+
readonly: options.readonly(),
|
|
112
|
+
clear: options.clear,
|
|
113
|
+
openPanel: show
|
|
114
|
+
})(event);
|
|
115
|
+
return {
|
|
116
|
+
today,
|
|
117
|
+
panelId,
|
|
118
|
+
hostRef,
|
|
119
|
+
panelRef,
|
|
120
|
+
panelOpen,
|
|
121
|
+
view,
|
|
122
|
+
mode,
|
|
123
|
+
preview,
|
|
124
|
+
setPreview,
|
|
125
|
+
shiftMonth,
|
|
126
|
+
shiftYear,
|
|
127
|
+
toggleMode,
|
|
128
|
+
pickMonth,
|
|
129
|
+
onCellKeydown,
|
|
130
|
+
onTriggerKeydown,
|
|
131
|
+
onToggle,
|
|
132
|
+
show,
|
|
133
|
+
hide,
|
|
134
|
+
onPick: options.onPick
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
const sharedProps = {
|
|
138
|
+
/** 可选下界(含,`YYYY-MM-DD`) */
|
|
139
|
+
min: {
|
|
140
|
+
type: String,
|
|
141
|
+
default: void 0
|
|
142
|
+
},
|
|
143
|
+
/** 可选上界(含,`YYYY-MM-DD`) */
|
|
144
|
+
max: {
|
|
145
|
+
type: String,
|
|
146
|
+
default: void 0
|
|
147
|
+
},
|
|
148
|
+
/** 自定义禁用日期(界之外的规则) */
|
|
149
|
+
disabledDate: {
|
|
150
|
+
type: Function,
|
|
151
|
+
default: void 0
|
|
152
|
+
},
|
|
153
|
+
clearable: {
|
|
154
|
+
type: Boolean,
|
|
155
|
+
default: false
|
|
156
|
+
},
|
|
157
|
+
disabled: {
|
|
158
|
+
type: Boolean,
|
|
159
|
+
default: false
|
|
160
|
+
},
|
|
161
|
+
/** 只读:值不可改、面板不展开、箭头与清除位都不给;观感与可编辑档一致(口径同 `Select`) */
|
|
162
|
+
readonly: {
|
|
163
|
+
type: Boolean,
|
|
164
|
+
default: false
|
|
165
|
+
},
|
|
166
|
+
size: {
|
|
167
|
+
type: String,
|
|
168
|
+
default: "md"
|
|
169
|
+
},
|
|
170
|
+
status: {
|
|
171
|
+
type: String,
|
|
172
|
+
default: void 0
|
|
173
|
+
},
|
|
174
|
+
/** 有无边框(三档口径同 `Input`) */
|
|
175
|
+
bordered: {
|
|
176
|
+
type: [Boolean, String],
|
|
177
|
+
default: true
|
|
178
|
+
},
|
|
179
|
+
/** 每周起始日:`1` 周一(缺省)/ `0` 周日 */
|
|
180
|
+
weekStart: {
|
|
181
|
+
type: Number,
|
|
182
|
+
default: 1
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const DatePickerSingle = /* @__PURE__ */ defineComponent({
|
|
186
|
+
name: "DatePicker",
|
|
187
|
+
inheritAttrs: false,
|
|
188
|
+
props: {
|
|
189
|
+
/** 受控值(`YYYY-MM-DD`;空值 `''`) */
|
|
190
|
+
modelValue: {
|
|
191
|
+
type: String,
|
|
192
|
+
default: void 0
|
|
193
|
+
},
|
|
194
|
+
/** 非受控初值 */
|
|
195
|
+
defaultValue: {
|
|
196
|
+
type: String,
|
|
197
|
+
default: ""
|
|
198
|
+
},
|
|
199
|
+
...sharedProps,
|
|
200
|
+
placeholder: {
|
|
201
|
+
type: String,
|
|
202
|
+
default: "请选择日期"
|
|
203
|
+
},
|
|
204
|
+
/** 值变更回调(模型与 `emit` 双走) */
|
|
205
|
+
onChange: {
|
|
206
|
+
type: Function,
|
|
207
|
+
default: void 0
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
emits: {
|
|
211
|
+
"update:modelValue": (value) => true
|
|
212
|
+
},
|
|
213
|
+
setup(props, {
|
|
214
|
+
emit,
|
|
215
|
+
attrs
|
|
216
|
+
}) {
|
|
217
|
+
const inner = ref(props.defaultValue);
|
|
218
|
+
const current = computed(() => props.modelValue ?? inner.value);
|
|
219
|
+
const commit = (value) => {
|
|
220
|
+
if (props.modelValue === void 0) inner.value = value;
|
|
221
|
+
emit("update:modelValue", value);
|
|
222
|
+
props.onChange?.(value);
|
|
223
|
+
};
|
|
224
|
+
const clear = () => commit("");
|
|
225
|
+
const pick = (day) => {
|
|
226
|
+
commit(day.iso);
|
|
227
|
+
panel.hide();
|
|
228
|
+
};
|
|
229
|
+
const panel = useDatePanel({
|
|
230
|
+
clearable: () => props.clearable,
|
|
231
|
+
disabled: () => props.disabled,
|
|
232
|
+
readonly: () => props.readonly,
|
|
233
|
+
clear,
|
|
234
|
+
min: () => props.min,
|
|
235
|
+
max: () => props.max,
|
|
236
|
+
disabledDate: () => props.disabledDate,
|
|
237
|
+
weekStart: () => props.weekStart,
|
|
238
|
+
anchor: () => current.value || void 0,
|
|
239
|
+
/* 单选没有「半选」一说:预览端恒不跟踪 */
|
|
240
|
+
previewing: () => false,
|
|
241
|
+
onPick: pick
|
|
242
|
+
});
|
|
243
|
+
return () => createVNode("div", {
|
|
244
|
+
"ref": panel.hostRef,
|
|
245
|
+
"class": ["mh-popup-host", attrs.class].filter(Boolean).join(" "),
|
|
246
|
+
"style": attrs.style
|
|
247
|
+
}, [createVNode(DateTrigger, {
|
|
248
|
+
"panelId": panel.panelId,
|
|
249
|
+
"size": props.size,
|
|
250
|
+
"status": props.status,
|
|
251
|
+
"disabled": props.disabled,
|
|
252
|
+
"readonly": props.readonly,
|
|
253
|
+
"bordered": props.bordered,
|
|
254
|
+
"clearable": props.clearable,
|
|
255
|
+
"hasValue": !!current.value,
|
|
256
|
+
"placeholder": props.placeholder,
|
|
257
|
+
"label": current.value,
|
|
258
|
+
"expanded": panel.panelOpen.value,
|
|
259
|
+
"onKeydown": panel.onTriggerKeydown,
|
|
260
|
+
"onClear": clear
|
|
261
|
+
}, null), createVNode(DatePanelShell, {
|
|
262
|
+
"id": panel.panelId,
|
|
263
|
+
"elementRef": panel.panelRef,
|
|
264
|
+
"label": "日期选择",
|
|
265
|
+
"onToggle": panel.onToggle
|
|
266
|
+
}, {
|
|
267
|
+
default: () => createVNode(DatePanel, {
|
|
268
|
+
"year": panel.view.value.year,
|
|
269
|
+
"month": panel.view.value.month,
|
|
270
|
+
"weekStart": props.weekStart,
|
|
271
|
+
"selected": current.value,
|
|
272
|
+
"min": props.min,
|
|
273
|
+
"max": props.max,
|
|
274
|
+
"disabledDate": props.disabledDate,
|
|
275
|
+
"today": panel.today,
|
|
276
|
+
"mode": panel.mode.value,
|
|
277
|
+
"preview": panel.preview.value,
|
|
278
|
+
"onPick": panel.onPick,
|
|
279
|
+
"onPreview": panel.setPreview,
|
|
280
|
+
"onShiftMonth": panel.shiftMonth,
|
|
281
|
+
"onShiftYear": panel.shiftYear,
|
|
282
|
+
"onPickMonth": panel.pickMonth,
|
|
283
|
+
"onToggleMode": panel.toggleMode,
|
|
284
|
+
"onKeydown": panel.onCellKeydown
|
|
285
|
+
}, null)
|
|
286
|
+
})]);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
const DateRangePickerSingle = /* @__PURE__ */ defineComponent({
|
|
290
|
+
name: "DateRangePicker",
|
|
291
|
+
inheritAttrs: false,
|
|
292
|
+
props: {
|
|
293
|
+
/** 受控值(`[起点, 终点]`;起段后是 `[起点]`,空值 `[]`) */
|
|
294
|
+
modelValue: {
|
|
295
|
+
type: Array,
|
|
296
|
+
default: void 0
|
|
297
|
+
},
|
|
298
|
+
/** 非受控初值 */
|
|
299
|
+
defaultValue: {
|
|
300
|
+
type: Array,
|
|
301
|
+
default: () => []
|
|
302
|
+
},
|
|
303
|
+
...sharedProps,
|
|
304
|
+
placeholder: {
|
|
305
|
+
type: String,
|
|
306
|
+
default: "请选择日期范围"
|
|
307
|
+
},
|
|
308
|
+
/** 两端的连接符(触发器回显与文档口径共用;`…` 表示另一端未选) */
|
|
309
|
+
separator: {
|
|
310
|
+
type: String,
|
|
311
|
+
default: " ~ "
|
|
312
|
+
},
|
|
313
|
+
/** 值变更回调(模型与 `emit` 双走) */
|
|
314
|
+
onChange: {
|
|
315
|
+
type: Function,
|
|
316
|
+
default: void 0
|
|
317
|
+
}
|
|
318
|
+
},
|
|
319
|
+
emits: {
|
|
320
|
+
"update:modelValue": (value) => true
|
|
321
|
+
},
|
|
322
|
+
setup(props, {
|
|
323
|
+
emit,
|
|
324
|
+
attrs
|
|
325
|
+
}) {
|
|
326
|
+
const inner = ref(props.defaultValue);
|
|
327
|
+
const values = computed(() => props.modelValue ?? inner.value);
|
|
328
|
+
const start = computed(() => values.value[0]);
|
|
329
|
+
const end = computed(() => values.value[1]);
|
|
330
|
+
const text = computed(() => {
|
|
331
|
+
if (!start.value) return "";
|
|
332
|
+
return end.value ? `${start.value}${props.separator}${end.value}` : `${start.value}${props.separator}…`;
|
|
333
|
+
});
|
|
334
|
+
const commit = (value) => {
|
|
335
|
+
if (props.modelValue === void 0) inner.value = value;
|
|
336
|
+
emit("update:modelValue", value);
|
|
337
|
+
props.onChange?.(value);
|
|
338
|
+
};
|
|
339
|
+
const clear = () => commit([]);
|
|
340
|
+
const pick = (day) => {
|
|
341
|
+
if (start.value && !end.value && day.iso >= start.value) {
|
|
342
|
+
commit([start.value, day.iso]);
|
|
343
|
+
panel.hide();
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
commit([day.iso]);
|
|
347
|
+
};
|
|
348
|
+
const panel = useDatePanel({
|
|
349
|
+
clearable: () => props.clearable,
|
|
350
|
+
disabled: () => props.disabled,
|
|
351
|
+
readonly: () => props.readonly,
|
|
352
|
+
clear,
|
|
353
|
+
min: () => props.min,
|
|
354
|
+
max: () => props.max,
|
|
355
|
+
disabledDate: () => props.disabledDate,
|
|
356
|
+
weekStart: () => props.weekStart,
|
|
357
|
+
anchor: () => start.value || void 0,
|
|
358
|
+
/* 半选 = 已起段、未收尾:只有这时才把 `[起点, 预览端]` 铺成区间(收尾后按真值算) */
|
|
359
|
+
previewing: () => !!start.value && !end.value,
|
|
360
|
+
onPick: pick
|
|
361
|
+
});
|
|
362
|
+
return () => createVNode("div", {
|
|
363
|
+
"ref": panel.hostRef,
|
|
364
|
+
"class": ["mh-popup-host", attrs.class].filter(Boolean).join(" "),
|
|
365
|
+
"style": attrs.style
|
|
366
|
+
}, [createVNode(DateTrigger, {
|
|
367
|
+
"panelId": panel.panelId,
|
|
368
|
+
"size": props.size,
|
|
369
|
+
"status": props.status,
|
|
370
|
+
"disabled": props.disabled,
|
|
371
|
+
"readonly": props.readonly,
|
|
372
|
+
"bordered": props.bordered,
|
|
373
|
+
"clearable": props.clearable,
|
|
374
|
+
"hasValue": !!start.value,
|
|
375
|
+
"placeholder": props.placeholder,
|
|
376
|
+
"label": text.value,
|
|
377
|
+
"expanded": panel.panelOpen.value,
|
|
378
|
+
"onKeydown": panel.onTriggerKeydown,
|
|
379
|
+
"onClear": clear
|
|
380
|
+
}, null), createVNode(DatePanelShell, {
|
|
381
|
+
"id": panel.panelId,
|
|
382
|
+
"elementRef": panel.panelRef,
|
|
383
|
+
"label": "日期范围选择",
|
|
384
|
+
"onToggle": panel.onToggle
|
|
385
|
+
}, {
|
|
386
|
+
default: () => createVNode(DatePanel, {
|
|
387
|
+
"year": panel.view.value.year,
|
|
388
|
+
"month": panel.view.value.month,
|
|
389
|
+
"weekStart": props.weekStart,
|
|
390
|
+
"range": true,
|
|
391
|
+
"rangeStart": start.value,
|
|
392
|
+
"rangeEnd": end.value,
|
|
393
|
+
"min": props.min,
|
|
394
|
+
"max": props.max,
|
|
395
|
+
"disabledDate": props.disabledDate,
|
|
396
|
+
"today": panel.today,
|
|
397
|
+
"mode": panel.mode.value,
|
|
398
|
+
"preview": panel.preview.value,
|
|
399
|
+
"onPick": panel.onPick,
|
|
400
|
+
"onPreview": panel.setPreview,
|
|
401
|
+
"onShiftMonth": panel.shiftMonth,
|
|
402
|
+
"onShiftYear": panel.shiftYear,
|
|
403
|
+
"onPickMonth": panel.pickMonth,
|
|
404
|
+
"onToggleMode": panel.toggleMode,
|
|
405
|
+
"onKeydown": panel.onCellKeydown
|
|
406
|
+
}, null)
|
|
407
|
+
})]);
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
const DateTimePickerSingle = /* @__PURE__ */ defineComponent({
|
|
411
|
+
name: "DateTimePicker",
|
|
412
|
+
inheritAttrs: false,
|
|
413
|
+
props: {
|
|
414
|
+
/** 受控值(`YYYY-MM-DD HH:mm:ss`;空值 `''`) */
|
|
415
|
+
modelValue: {
|
|
416
|
+
type: String,
|
|
417
|
+
default: void 0
|
|
418
|
+
},
|
|
419
|
+
/** 非受控初值 */
|
|
420
|
+
defaultValue: {
|
|
421
|
+
type: String,
|
|
422
|
+
default: ""
|
|
423
|
+
},
|
|
424
|
+
...sharedProps,
|
|
425
|
+
placeholder: {
|
|
426
|
+
type: String,
|
|
427
|
+
default: "请选择日期时间"
|
|
428
|
+
},
|
|
429
|
+
/** 时间精度:`minute` 不显示秒位(值仍写 `:00`) */
|
|
430
|
+
precision: {
|
|
431
|
+
type: String,
|
|
432
|
+
default: "second"
|
|
433
|
+
},
|
|
434
|
+
/** 值变更回调(模型与 `emit` 双走) */
|
|
435
|
+
onChange: {
|
|
436
|
+
type: Function,
|
|
437
|
+
default: void 0
|
|
438
|
+
}
|
|
439
|
+
},
|
|
440
|
+
emits: {
|
|
441
|
+
"update:modelValue": (value) => true
|
|
442
|
+
},
|
|
443
|
+
setup(props, {
|
|
444
|
+
emit,
|
|
445
|
+
attrs
|
|
446
|
+
}) {
|
|
447
|
+
const inner = ref(props.defaultValue);
|
|
448
|
+
const current = computed(() => props.modelValue ?? inner.value);
|
|
449
|
+
const time = ref(parseTime(timePartOf(current.value)) ?? [0, 0, 0]);
|
|
450
|
+
const commit = (value) => {
|
|
451
|
+
if (props.modelValue === void 0) inner.value = value;
|
|
452
|
+
emit("update:modelValue", value);
|
|
453
|
+
props.onChange?.(value);
|
|
454
|
+
};
|
|
455
|
+
watch(current, (value) => {
|
|
456
|
+
const parts = parseTime(timePartOf(value));
|
|
457
|
+
if (parts) time.value = parts;
|
|
458
|
+
});
|
|
459
|
+
const clear = () => commit("");
|
|
460
|
+
const pick = (day) => commit(joinDateTime(day.iso, formatTime(time.value)));
|
|
461
|
+
const setTime = (parts) => {
|
|
462
|
+
time.value = parts;
|
|
463
|
+
const date = datePartOf(current.value);
|
|
464
|
+
if (date) commit(joinDateTime(date, formatTime(parts)));
|
|
465
|
+
};
|
|
466
|
+
const setNow = () => {
|
|
467
|
+
time.value = nowTime();
|
|
468
|
+
commit(nowDateTime());
|
|
469
|
+
};
|
|
470
|
+
const panel = useDatePanel({
|
|
471
|
+
clearable: () => props.clearable,
|
|
472
|
+
disabled: () => props.disabled,
|
|
473
|
+
readonly: () => props.readonly,
|
|
474
|
+
clear,
|
|
475
|
+
min: () => props.min,
|
|
476
|
+
max: () => props.max,
|
|
477
|
+
disabledDate: () => props.disabledDate,
|
|
478
|
+
weekStart: () => props.weekStart,
|
|
479
|
+
anchor: () => datePartOf(current.value) || void 0,
|
|
480
|
+
previewing: () => false,
|
|
481
|
+
/* 每次打开按当前值重置时间草稿:上次没提交的输入不该跨次沿用 */
|
|
482
|
+
onShow: () => {
|
|
483
|
+
time.value = parseTime(timePartOf(current.value)) ?? [0, 0, 0];
|
|
484
|
+
},
|
|
485
|
+
onPick: pick
|
|
486
|
+
});
|
|
487
|
+
return () => createVNode("div", {
|
|
488
|
+
"ref": panel.hostRef,
|
|
489
|
+
"class": ["mh-popup-host", attrs.class].filter(Boolean).join(" "),
|
|
490
|
+
"style": attrs.style
|
|
491
|
+
}, [createVNode(DateTrigger, {
|
|
492
|
+
"panelId": panel.panelId,
|
|
493
|
+
"size": props.size,
|
|
494
|
+
"status": props.status,
|
|
495
|
+
"disabled": props.disabled,
|
|
496
|
+
"readonly": props.readonly,
|
|
497
|
+
"bordered": props.bordered,
|
|
498
|
+
"clearable": props.clearable,
|
|
499
|
+
"hasValue": !!current.value,
|
|
500
|
+
"placeholder": props.placeholder,
|
|
501
|
+
"label": displayDateTime(current.value, props.precision),
|
|
502
|
+
"expanded": panel.panelOpen.value,
|
|
503
|
+
"onKeydown": panel.onTriggerKeydown,
|
|
504
|
+
"onClear": clear
|
|
505
|
+
}, null), createVNode(DatePanelShell, {
|
|
506
|
+
"id": panel.panelId,
|
|
507
|
+
"elementRef": panel.panelRef,
|
|
508
|
+
"label": "日期时间选择",
|
|
509
|
+
"onToggle": panel.onToggle
|
|
510
|
+
}, {
|
|
511
|
+
default: () => createVNode(DatePanel, {
|
|
512
|
+
"year": panel.view.value.year,
|
|
513
|
+
"month": panel.view.value.month,
|
|
514
|
+
"weekStart": props.weekStart,
|
|
515
|
+
"selected": datePartOf(current.value),
|
|
516
|
+
"min": props.min,
|
|
517
|
+
"max": props.max,
|
|
518
|
+
"disabledDate": props.disabledDate,
|
|
519
|
+
"today": panel.today,
|
|
520
|
+
"mode": panel.mode.value,
|
|
521
|
+
"preview": panel.preview.value,
|
|
522
|
+
"onPick": panel.onPick,
|
|
523
|
+
"onPreview": panel.setPreview,
|
|
524
|
+
"onShiftMonth": panel.shiftMonth,
|
|
525
|
+
"onShiftYear": panel.shiftYear,
|
|
526
|
+
"onPickMonth": panel.pickMonth,
|
|
527
|
+
"onToggleMode": panel.toggleMode,
|
|
528
|
+
"onKeydown": panel.onCellKeydown,
|
|
529
|
+
"withTime": true,
|
|
530
|
+
"precision": props.precision,
|
|
531
|
+
"hour": time.value[0],
|
|
532
|
+
"minute": time.value[1],
|
|
533
|
+
"second": time.value[2],
|
|
534
|
+
"onTime": setTime,
|
|
535
|
+
"onNow": setNow
|
|
536
|
+
}, null)
|
|
537
|
+
})]);
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
const DatePicker = Object.assign(DatePickerSingle, {
|
|
541
|
+
Range: DateRangePickerSingle
|
|
542
|
+
});
|
|
543
|
+
const DateRangePicker = DateRangePickerSingle;
|
|
544
|
+
const DateTimePicker = DateTimePickerSingle;
|
|
545
|
+
export {
|
|
546
|
+
DatePicker,
|
|
547
|
+
DateRangePicker,
|
|
548
|
+
DateTimePicker
|
|
549
|
+
};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DatePanelShell —— 日期族的**面板壳内件**(三件共用,不对外导出)。
|
|
3
|
+
*
|
|
4
|
+
* 它只有三样东西:**原生 popover 元素**(开合 / Esc / 点外部关闭 / 顶层渲染 / 定位全归浏览器与
|
|
5
|
+
* `styles/operations/popup.css`)、**内容区**(`.mh-date-picker__body`)与**内容槽**(日历 / 月份网格 /
|
|
6
|
+
* 时间行,由 `date-panel.tsx` 渲染)。
|
|
7
|
+
*
|
|
8
|
+
* 与选择器族那个壳的差别:**没有搜索行**(日期面板里没有可搜的东西)、**角色固定 `dialog`**
|
|
9
|
+
* (面板里是日历,不是选项列表 —— 写死 `listbox` 之类会让读屏读错),故 `label` 必给(需要名字的角色)。
|
|
10
|
+
*
|
|
11
|
+
* 组合类名与定位属性都是**操作层的组合**,不是本件新造的浮层:`class="mh-popup mh-date-picker__panel
|
|
12
|
+
* mh-popup--anchored"`(状态根 + 本族皮肤 + 显式锚档)、`data-side` / `data-align`(`popup.css` 的定位档)、
|
|
13
|
+
* `popover="auto"`(原生轻关闭)。锚显式钉在**表壳**上(触发器进壳后隐式锚会缩成壳内控件)。
|
|
14
|
+
*
|
|
15
|
+
* `elementRef` 是**由消费方持有的 ref**(不是本件自己的):开面板、收起面板、以及按 `[data-state]` 取
|
|
16
|
+
* 选中格(滚动 / 聚焦)都要在父层拿到这个 DOM 元素。
|
|
17
|
+
*/
|
|
18
|
+
import { type PropType, type SlotsType, type VNodeChild } from 'vue';
|
|
19
|
+
import type { ElementRef } from './shared';
|
|
20
|
+
export declare const DatePanelShell: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
21
|
+
/** 面板 id(必须与触发器的 `popovertarget` 成对) */
|
|
22
|
+
id: {
|
|
23
|
+
type: StringConstructor;
|
|
24
|
+
required: true;
|
|
25
|
+
};
|
|
26
|
+
/** 面板的可访问名(`aria-label`) */
|
|
27
|
+
label: {
|
|
28
|
+
type: StringConstructor;
|
|
29
|
+
required: true;
|
|
30
|
+
};
|
|
31
|
+
/** 面板元素的 ref,由消费方持有(父层要用它开合、遍历格子与回收焦点) */
|
|
32
|
+
elementRef: {
|
|
33
|
+
type: PropType<ElementRef>;
|
|
34
|
+
default: undefined;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* 面板的原生 `toggle` 事件(开合态变化,含 Esc 与点外部关闭)。声明成 prop 而不是靠 `attrs`:本件的
|
|
38
|
+
* `attrs` 是关掉的(`inheritAttrs: false`),且这个事件要落到**面板元素**上(只有它派发 `toggle`)。
|
|
39
|
+
*/
|
|
40
|
+
onToggle: {
|
|
41
|
+
type: PropType<(event: Event) => void>;
|
|
42
|
+
default: undefined;
|
|
43
|
+
};
|
|
44
|
+
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
45
|
+
/** 面板 id(必须与触发器的 `popovertarget` 成对) */
|
|
46
|
+
id: {
|
|
47
|
+
type: StringConstructor;
|
|
48
|
+
required: true;
|
|
49
|
+
};
|
|
50
|
+
/** 面板的可访问名(`aria-label`) */
|
|
51
|
+
label: {
|
|
52
|
+
type: StringConstructor;
|
|
53
|
+
required: true;
|
|
54
|
+
};
|
|
55
|
+
/** 面板元素的 ref,由消费方持有(父层要用它开合、遍历格子与回收焦点) */
|
|
56
|
+
elementRef: {
|
|
57
|
+
type: PropType<ElementRef>;
|
|
58
|
+
default: undefined;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* 面板的原生 `toggle` 事件(开合态变化,含 Esc 与点外部关闭)。声明成 prop 而不是靠 `attrs`:本件的
|
|
62
|
+
* `attrs` 是关掉的(`inheritAttrs: false`),且这个事件要落到**面板元素**上(只有它派发 `toggle`)。
|
|
63
|
+
*/
|
|
64
|
+
onToggle: {
|
|
65
|
+
type: PropType<(event: Event) => void>;
|
|
66
|
+
default: undefined;
|
|
67
|
+
};
|
|
68
|
+
}>> & Readonly<{}>, {
|
|
69
|
+
onToggle: (event: Event) => void;
|
|
70
|
+
elementRef: ElementRef;
|
|
71
|
+
}, SlotsType<{
|
|
72
|
+
default?: () => VNodeChild;
|
|
73
|
+
}>, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { defineComponent, createVNode, mergeProps } from "vue";
|
|
2
|
+
const DatePanelShell = /* @__PURE__ */ defineComponent({
|
|
3
|
+
name: "DatePanelShell",
|
|
4
|
+
inheritAttrs: false,
|
|
5
|
+
props: {
|
|
6
|
+
/** 面板 id(必须与触发器的 `popovertarget` 成对) */
|
|
7
|
+
id: {
|
|
8
|
+
type: String,
|
|
9
|
+
required: true
|
|
10
|
+
},
|
|
11
|
+
/** 面板的可访问名(`aria-label`) */
|
|
12
|
+
label: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: true
|
|
15
|
+
},
|
|
16
|
+
/** 面板元素的 ref,由消费方持有(父层要用它开合、遍历格子与回收焦点) */
|
|
17
|
+
elementRef: {
|
|
18
|
+
type: Object,
|
|
19
|
+
default: void 0
|
|
20
|
+
},
|
|
21
|
+
/**
|
|
22
|
+
* 面板的原生 `toggle` 事件(开合态变化,含 Esc 与点外部关闭)。声明成 prop 而不是靠 `attrs`:本件的
|
|
23
|
+
* `attrs` 是关掉的(`inheritAttrs: false`),且这个事件要落到**面板元素**上(只有它派发 `toggle`)。
|
|
24
|
+
*/
|
|
25
|
+
onToggle: {
|
|
26
|
+
type: Function,
|
|
27
|
+
default: void 0
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
slots: Object,
|
|
31
|
+
setup(props, {
|
|
32
|
+
slots
|
|
33
|
+
}) {
|
|
34
|
+
return () => createVNode("div", mergeProps({
|
|
35
|
+
"ref": props.elementRef,
|
|
36
|
+
"id": props.id
|
|
37
|
+
}, {
|
|
38
|
+
popover: "auto"
|
|
39
|
+
}, {
|
|
40
|
+
"class": "mh-popup mh-date-picker__panel mh-popup--anchored",
|
|
41
|
+
"data-side": "bottom",
|
|
42
|
+
"data-align": "start",
|
|
43
|
+
"role": "dialog",
|
|
44
|
+
"aria-label": props.label,
|
|
45
|
+
"onToggle": props.onToggle
|
|
46
|
+
}), [createVNode("div", {
|
|
47
|
+
"class": "mh-date-picker__body"
|
|
48
|
+
}, [slots.default?.()])]);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
export {
|
|
52
|
+
DatePanelShell
|
|
53
|
+
};
|