@h-ai/ui 1.0.0-beta.33 → 1.0.0-beta.35
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.en.md +4 -0
- package/README.ja.md +4 -0
- package/README.md +4 -0
- package/auto-import.d.ts +2 -0
- package/auto-import.js +2 -0
- package/dist/components/compounds/CronExpressionBuilder.svelte +655 -0
- package/dist/components/compounds/CronExpressionBuilder.svelte.d.ts +40 -0
- package/dist/components/compounds/DatePicker.svelte +5 -1
- package/dist/components/compounds/DatePicker.svelte.d.ts +2 -0
- package/dist/components/compounds/ScheduleInput.svelte +475 -0
- package/dist/components/compounds/ScheduleInput.svelte.d.ts +51 -0
- package/dist/components/compounds/cron-expression-builder-types.d.ts +97 -0
- package/dist/components/compounds/cron-expression-builder-types.js +1 -0
- package/dist/components/compounds/cron-expression-builder.d.ts +63 -0
- package/dist/components/compounds/cron-expression-builder.js +293 -0
- package/dist/components/compounds/index.d.ts +6 -0
- package/dist/components/compounds/index.js +5 -0
- package/dist/components/compounds/schedule-input-config.d.ts +8 -0
- package/dist/components/compounds/schedule-input-config.js +7 -0
- package/dist/components/compounds/schedule-input.d.ts +170 -0
- package/dist/components/compounds/schedule-input.js +262 -0
- package/dist/components/scenes/ai/AiDocumentEditor.svelte +15 -3
- package/dist/components/scenes/ai/document-parse.d.ts +2 -0
- package/dist/components/scenes/ai/document-parse.js +9 -5
- package/dist/components/scenes/ai/document-source-range.d.ts +10 -0
- package/dist/components/scenes/ai/document-source-range.js +90 -0
- package/dist/components/scenes/ai/document-types.d.ts +20 -0
- package/dist/components/scenes/ai/index.d.ts +1 -1
- package/dist/components/scenes/ai/markdown-parse.d.ts +2 -0
- package/dist/components/scenes/ai/markdown-parse.js +8 -5
- package/dist/components/scenes/ai/safe-html.d.ts +12 -2
- package/dist/components/scenes/ai/safe-html.js +22 -8
- package/dist/messages/en-US.json +28 -0
- package/dist/messages/ja-JP.json +28 -0
- package/dist/messages/zh-CN.json +28 -0
- package/package.json +8 -2
|
@@ -62,6 +62,8 @@
|
|
|
62
62
|
size?: Size
|
|
63
63
|
/** 错误消息 */
|
|
64
64
|
error?: FormText
|
|
65
|
+
/** 无障碍名称;未提供时优先使用外层 FormField 标签。 */
|
|
66
|
+
ariaLabel?: string
|
|
65
67
|
/** 自定义类名 */
|
|
66
68
|
class?: string
|
|
67
69
|
/** 日期变更回调 */
|
|
@@ -77,6 +79,7 @@
|
|
|
77
79
|
disabled = false,
|
|
78
80
|
size = 'md',
|
|
79
81
|
error,
|
|
82
|
+
ariaLabel,
|
|
80
83
|
class: className = '',
|
|
81
84
|
onchange,
|
|
82
85
|
...restProps
|
|
@@ -103,7 +106,8 @@
|
|
|
103
106
|
onValueChange={v => onchange?.(v)}
|
|
104
107
|
>
|
|
105
108
|
<BitsDatePicker.Input
|
|
106
|
-
aria-
|
|
109
|
+
aria-label={ariaLabel}
|
|
110
|
+
aria-labelledby={ariaLabel ? undefined : field?.labelId}
|
|
107
111
|
aria-describedby={[
|
|
108
112
|
field?.messageId,
|
|
109
113
|
localError && !field?.error
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component ScheduleInput
|
|
3
|
+
日期时间与高级 Cron 的统一调度输入。
|
|
4
|
+
|
|
5
|
+
日期时间使用配置的 IANA 时区,默认 Asia/Shanghai。Cron 编辑由
|
|
6
|
+
CronExpressionBuilder 提供。
|
|
7
|
+
-->
|
|
8
|
+
<script lang='ts'>
|
|
9
|
+
import type { DateValue } from '@internationalized/date'
|
|
10
|
+
import type { DataAttributes, FormText, Size } from '../../types.js'
|
|
11
|
+
import type { ScheduleDateTimeDraft, ScheduleInputConfig } from './schedule-input.js'
|
|
12
|
+
import { parseDate } from '@internationalized/date'
|
|
13
|
+
import { getFormFieldContext } from '../../internal/form-context.js'
|
|
14
|
+
import { resolveFormText, useControlFeedback } from '../../internal/form-validation.svelte.js'
|
|
15
|
+
import { uiM } from '../../messages.js'
|
|
16
|
+
import { cn, getDataAttributes } from '../../utils.js'
|
|
17
|
+
import Input from '../primitives/Input.svelte'
|
|
18
|
+
import Select from '../primitives/Select.svelte'
|
|
19
|
+
import { isCronExpressionValid } from './cron-expression-builder.js'
|
|
20
|
+
import CronExpressionBuilder from './CronExpressionBuilder.svelte'
|
|
21
|
+
import DatePicker from './DatePicker.svelte'
|
|
22
|
+
import {
|
|
23
|
+
DEFAULT_SCHEDULE_INPUT_CONFIG,
|
|
24
|
+
inspectScheduleDateTimeDraft,
|
|
25
|
+
normalizeScheduleInputConfig,
|
|
26
|
+
parseScheduleDateTimeValue,
|
|
27
|
+
serializeScheduleDateTime,
|
|
28
|
+
} from './schedule-input.js'
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* ScheduleInput 的编辑模式。
|
|
32
|
+
*
|
|
33
|
+
* @example 模块内部上下文
|
|
34
|
+
* ```ts
|
|
35
|
+
* const mode: ScheduleInputMode = 'datetime'
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
type ScheduleInputMode = 'datetime' | 'cron'
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* ScheduleInput 组件的属性契约;通过公开组件配置使用。
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { mount, unmount } from 'svelte'
|
|
46
|
+
* import { ScheduleInput } from '@h-ai/ui'
|
|
47
|
+
* const component = mount(ScheduleInput, {
|
|
48
|
+
* target: document.body,
|
|
49
|
+
* props: { required: true },
|
|
50
|
+
* })
|
|
51
|
+
* await unmount(component)
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
interface Props {
|
|
55
|
+
/** Schema 元数据;省略时使用默认的北京时间、分钟精度配置。 */
|
|
56
|
+
config?: ScheduleInputConfig
|
|
57
|
+
/** 日期时间 canonical 值或 Cron 表达式。 */
|
|
58
|
+
value?: string
|
|
59
|
+
/** 当前值是否通过组件边界校验。 */
|
|
60
|
+
valid?: boolean
|
|
61
|
+
/** 是否必须填写。 */
|
|
62
|
+
required?: boolean
|
|
63
|
+
/** 是否禁用交互。 */
|
|
64
|
+
disabled?: boolean
|
|
65
|
+
/** 自定义错误提示。 */
|
|
66
|
+
error?: FormText
|
|
67
|
+
/** 表单字段名。 */
|
|
68
|
+
name?: string
|
|
69
|
+
/** 控件 ID。 */
|
|
70
|
+
id?: string
|
|
71
|
+
/** 控件尺寸。 */
|
|
72
|
+
size?: Size
|
|
73
|
+
/** 自定义类名。 */
|
|
74
|
+
class?: string
|
|
75
|
+
/** 值变化回调。 */
|
|
76
|
+
onchange?: (value: string) => void
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let {
|
|
80
|
+
config: rawConfig = DEFAULT_SCHEDULE_INPUT_CONFIG,
|
|
81
|
+
value = $bindable(''),
|
|
82
|
+
valid = $bindable(false),
|
|
83
|
+
required = false,
|
|
84
|
+
disabled = false,
|
|
85
|
+
error,
|
|
86
|
+
name,
|
|
87
|
+
id,
|
|
88
|
+
size = 'md',
|
|
89
|
+
class: className = '',
|
|
90
|
+
onchange,
|
|
91
|
+
...restProps
|
|
92
|
+
}: Props & DataAttributes = $props()
|
|
93
|
+
|
|
94
|
+
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
95
|
+
const field = getFormFieldContext()
|
|
96
|
+
const uniqueId = $props.id()
|
|
97
|
+
const controlId = $derived(id ?? field?.controlId ?? `${uniqueId}-control`)
|
|
98
|
+
const messageId = `${uniqueId}-error`
|
|
99
|
+
const normalizedConfig = $derived(normalizeScheduleInputConfig(rawConfig))
|
|
100
|
+
const effectiveConfig = $derived(normalizedConfig ?? DEFAULT_SCHEDULE_INPUT_CONFIG)
|
|
101
|
+
const configIsValid = $derived(normalizedConfig !== undefined)
|
|
102
|
+
|
|
103
|
+
let mode = $state<ScheduleInputMode>('datetime')
|
|
104
|
+
let dateDraft = $state<ScheduleDateTimeDraft>({ date: '', hour: '', minute: '' })
|
|
105
|
+
let calendarDate = $state<DateValue | undefined>(undefined)
|
|
106
|
+
let cronDraft = $state('')
|
|
107
|
+
let lastSyncedValue = $state<string | undefined>(undefined)
|
|
108
|
+
let hasSyncedExternalValue = $state(false)
|
|
109
|
+
let dateTimeFormatValid = $state(true)
|
|
110
|
+
let dateTimeOffset = $state<string>()
|
|
111
|
+
let validationClock = $state(Date.now())
|
|
112
|
+
let nativeInput = $state<HTMLInputElement | undefined>(undefined)
|
|
113
|
+
|
|
114
|
+
const modeOptions = $derived([
|
|
115
|
+
{
|
|
116
|
+
value: 'datetime' as const,
|
|
117
|
+
label: uiM('schedule_input_mode_datetime'),
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
value: 'cron' as const,
|
|
121
|
+
label: uiM('schedule_input_mode_cron'),
|
|
122
|
+
},
|
|
123
|
+
])
|
|
124
|
+
const cronLabels = $derived({
|
|
125
|
+
presets: uiM('schedule_input_cron_presets'),
|
|
126
|
+
modeMinute: uiM('schedule_input_cron_mode_minute'),
|
|
127
|
+
modeHour: uiM('schedule_input_cron_mode_hour'),
|
|
128
|
+
modeDay: uiM('schedule_input_cron_mode_day'),
|
|
129
|
+
modeWeek: uiM('schedule_input_cron_mode_week'),
|
|
130
|
+
modeMonth: uiM('schedule_input_cron_mode_month'),
|
|
131
|
+
modeCustom: uiM('schedule_input_cron_mode_custom'),
|
|
132
|
+
fieldInterval: uiM('schedule_input_cron_field_interval'),
|
|
133
|
+
fieldMinute: uiM('schedule_input_cron_field_minute'),
|
|
134
|
+
fieldTime: uiM('schedule_input_cron_field_time'),
|
|
135
|
+
fieldWeekdays: uiM('schedule_input_cron_field_weekdays'),
|
|
136
|
+
fieldMonthDay: uiM('schedule_input_cron_field_month_day'),
|
|
137
|
+
fieldExpression: uiM('schedule_input_cron_field_expression'),
|
|
138
|
+
})
|
|
139
|
+
const dateTimeStatus = $derived(inspectScheduleDateTimeDraft(dateDraft, new Date(validationClock), effectiveConfig.timezone, dateTimeOffset))
|
|
140
|
+
const dateTimeDraftValue = $derived(serializeScheduleDateTime(dateDraft, effectiveConfig.timezone, dateTimeOffset) ?? '')
|
|
141
|
+
const draftMatchesValue = $derived(mode === 'datetime'
|
|
142
|
+
? dateTimeDraftValue === value
|
|
143
|
+
: cronDraft.trim() === value.trim())
|
|
144
|
+
const cronIsValid = $derived(isFiveSegmentCronExpressionValid(cronDraft))
|
|
145
|
+
const inputIsValid = $derived.by(() => {
|
|
146
|
+
if (!configIsValid)
|
|
147
|
+
return false
|
|
148
|
+
if (mode === 'datetime') {
|
|
149
|
+
return draftMatchesValue
|
|
150
|
+
&& dateTimeFormatValid
|
|
151
|
+
&& (dateTimeStatus === 'valid' || (dateTimeStatus === 'empty' && !required))
|
|
152
|
+
}
|
|
153
|
+
if (!effectiveConfig.allowCron)
|
|
154
|
+
return false
|
|
155
|
+
return draftMatchesValue && (cronIsValid || (!cronDraft.trim() && !required))
|
|
156
|
+
})
|
|
157
|
+
const validationMessage = $derived.by(() => {
|
|
158
|
+
if (!configIsValid)
|
|
159
|
+
return uiM('schedule_input_invalid_config')
|
|
160
|
+
if (mode === 'datetime') {
|
|
161
|
+
if (!draftMatchesValue || !dateTimeFormatValid)
|
|
162
|
+
return uiM('schedule_input_invalid')
|
|
163
|
+
switch (dateTimeStatus) {
|
|
164
|
+
case 'empty': return required
|
|
165
|
+
? uiM('schedule_input_required')
|
|
166
|
+
: ''
|
|
167
|
+
case 'partial': return uiM('schedule_input_partial')
|
|
168
|
+
case 'invalid': return uiM('schedule_input_invalid')
|
|
169
|
+
case 'past': return uiM('schedule_input_past')
|
|
170
|
+
case 'valid': return ''
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (!cronDraft.trim()) {
|
|
174
|
+
return required
|
|
175
|
+
? uiM('schedule_input_required')
|
|
176
|
+
: ''
|
|
177
|
+
}
|
|
178
|
+
if (!draftMatchesValue)
|
|
179
|
+
return uiM('schedule_input_cron_invalid')
|
|
180
|
+
return cronIsValid
|
|
181
|
+
? ''
|
|
182
|
+
: uiM('schedule_input_cron_invalid')
|
|
183
|
+
})
|
|
184
|
+
const localError = $derived(resolveFormText(error) || validationMessage)
|
|
185
|
+
const effectiveError = $derived(field?.error || localError)
|
|
186
|
+
const cronError = $derived(mode === 'cron'
|
|
187
|
+
? localError
|
|
188
|
+
: '')
|
|
189
|
+
|
|
190
|
+
useControlFeedback(() => localError)
|
|
191
|
+
|
|
192
|
+
// 外部回填只同步对应模式的草稿;用户在模式之间切换时不走这条路径。
|
|
193
|
+
$effect(() => {
|
|
194
|
+
const incoming = typeof value === 'string'
|
|
195
|
+
? value
|
|
196
|
+
: ''
|
|
197
|
+
if (hasSyncedExternalValue && incoming === lastSyncedValue)
|
|
198
|
+
return
|
|
199
|
+
|
|
200
|
+
syncExternalValue(incoming)
|
|
201
|
+
lastSyncedValue = incoming
|
|
202
|
+
hasSyncedExternalValue = true
|
|
203
|
+
})
|
|
204
|
+
|
|
205
|
+
$effect(() => {
|
|
206
|
+
if (!effectiveConfig.allowCron && mode === 'cron')
|
|
207
|
+
mode = 'datetime'
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
$effect(() => {
|
|
211
|
+
valid = inputIsValid
|
|
212
|
+
if (nativeInput) {
|
|
213
|
+
nativeInput.setCustomValidity(inputIsValid ? '' : localError)
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
$effect(() => {
|
|
218
|
+
if (mode !== 'datetime' || !dateTimeDraftValue)
|
|
219
|
+
return
|
|
220
|
+
|
|
221
|
+
const deadline = Date.parse(dateTimeDraftValue)
|
|
222
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
223
|
+
function updateClock() {
|
|
224
|
+
const now = Date.now()
|
|
225
|
+
validationClock = now
|
|
226
|
+
const remaining = deadline - now
|
|
227
|
+
if (remaining > 0)
|
|
228
|
+
timer = setTimeout(updateClock, Math.min(remaining, 2_147_483_647))
|
|
229
|
+
}
|
|
230
|
+
updateClock()
|
|
231
|
+
return () => clearTimeout(timer)
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
$effect(() => {
|
|
235
|
+
const form = nativeInput?.form
|
|
236
|
+
if (!form)
|
|
237
|
+
return
|
|
238
|
+
// 后台标签页可能延迟计时器,原生提交用即时钟再核对一次。
|
|
239
|
+
form.addEventListener('submit', checkSubmissionTime, true)
|
|
240
|
+
return () => form.removeEventListener('submit', checkSubmissionTime, true)
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
function checkSubmissionTime(event: SubmitEvent): void {
|
|
244
|
+
const now = Date.now()
|
|
245
|
+
if (disabled || mode !== 'datetime' || !dateTimeDraftValue || Date.parse(dateTimeDraftValue) > now)
|
|
246
|
+
return
|
|
247
|
+
|
|
248
|
+
event.preventDefault()
|
|
249
|
+
event.stopImmediatePropagation()
|
|
250
|
+
validationClock = now
|
|
251
|
+
nativeInput?.setCustomValidity(uiM('schedule_input_past'))
|
|
252
|
+
nativeInput?.reportValidity()
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function focusInvalidControl(event: Event & { currentTarget: HTMLInputElement }): void {
|
|
256
|
+
// 表单值由代理输入提交,用户在当前模式的可见输入中修正错误。
|
|
257
|
+
event.preventDefault()
|
|
258
|
+
const input = event.currentTarget
|
|
259
|
+
if (!input.form || input.form.querySelector(':invalid') === input)
|
|
260
|
+
input.ownerDocument.getElementById(controlId)?.focus()
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function syncExternalValue(incoming: string): void {
|
|
264
|
+
const parsed = parseScheduleDateTimeValue(incoming)
|
|
265
|
+
if (parsed) {
|
|
266
|
+
mode = 'datetime'
|
|
267
|
+
dateTimeFormatValid = parsed.seconds === '00'
|
|
268
|
+
dateTimeOffset = parsed.offset
|
|
269
|
+
dateDraft = {
|
|
270
|
+
date: parsed.date,
|
|
271
|
+
hour: parsed.hour,
|
|
272
|
+
minute: parsed.minute,
|
|
273
|
+
}
|
|
274
|
+
calendarDate = parseCalendarDate(parsed.date)
|
|
275
|
+
return
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (effectiveConfig.allowCron && incoming.trim()) {
|
|
279
|
+
mode = 'cron'
|
|
280
|
+
cronDraft = incoming.trim()
|
|
281
|
+
return
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
mode = 'datetime'
|
|
285
|
+
dateTimeFormatValid = !incoming.trim()
|
|
286
|
+
dateTimeOffset = undefined
|
|
287
|
+
dateDraft = { date: '', hour: '', minute: '' }
|
|
288
|
+
calendarDate = undefined
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function setValue(nextValue: string): void {
|
|
292
|
+
if (disabled)
|
|
293
|
+
return
|
|
294
|
+
|
|
295
|
+
value = nextValue
|
|
296
|
+
lastSyncedValue = nextValue
|
|
297
|
+
hasSyncedExternalValue = true
|
|
298
|
+
onchange?.(nextValue)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function syncDateTimeValue(): void {
|
|
302
|
+
dateTimeFormatValid = true
|
|
303
|
+
dateTimeOffset = undefined
|
|
304
|
+
setValue(dateTimeDraftValue)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function handleDateChange(nextDate: DateValue | undefined): void {
|
|
308
|
+
if (disabled)
|
|
309
|
+
return
|
|
310
|
+
|
|
311
|
+
calendarDate = nextDate
|
|
312
|
+
dateDraft = {
|
|
313
|
+
...dateDraft,
|
|
314
|
+
date: nextDate?.toString() ?? '',
|
|
315
|
+
}
|
|
316
|
+
syncDateTimeValue()
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
function updateTime(part: 'hour' | 'minute', nextValue: string): void {
|
|
320
|
+
if (disabled)
|
|
321
|
+
return
|
|
322
|
+
|
|
323
|
+
dateDraft = {
|
|
324
|
+
...dateDraft,
|
|
325
|
+
[part]: nextValue,
|
|
326
|
+
}
|
|
327
|
+
syncDateTimeValue()
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function handleModeChange(nextMode: string): void {
|
|
331
|
+
if (nextMode !== 'datetime' && nextMode !== 'cron')
|
|
332
|
+
return
|
|
333
|
+
|
|
334
|
+
if (disabled || nextMode === mode || (!effectiveConfig.allowCron && nextMode === 'cron'))
|
|
335
|
+
return
|
|
336
|
+
|
|
337
|
+
mode = nextMode
|
|
338
|
+
if (nextMode === 'datetime') {
|
|
339
|
+
calendarDate = parseCalendarDate(dateDraft.date)
|
|
340
|
+
setValue(dateTimeDraftValue)
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
setValue(cronDraft.trim())
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
function handleCronChange(nextValue: string): void {
|
|
348
|
+
if (disabled)
|
|
349
|
+
return
|
|
350
|
+
|
|
351
|
+
cronDraft = nextValue
|
|
352
|
+
setValue(nextValue)
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
function isFiveSegmentCronExpressionValid(expression: string): boolean {
|
|
356
|
+
const normalized = expression.trim()
|
|
357
|
+
return normalized.split(/\s+/).length === 5 && isCronExpressionValid(normalized)
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function parseCalendarDate(valueToParse: string): DateValue | undefined {
|
|
361
|
+
if (!valueToParse)
|
|
362
|
+
return undefined
|
|
363
|
+
|
|
364
|
+
try {
|
|
365
|
+
return parseDate(valueToParse)
|
|
366
|
+
}
|
|
367
|
+
catch {
|
|
368
|
+
return undefined
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
</script>
|
|
372
|
+
|
|
373
|
+
<div {...dataAttributes} class={cn('fieldset w-full min-w-0', className)}>
|
|
374
|
+
<input
|
|
375
|
+
bind:this={nativeInput}
|
|
376
|
+
type='text'
|
|
377
|
+
class='sr-only'
|
|
378
|
+
tabindex='-1'
|
|
379
|
+
aria-hidden='true'
|
|
380
|
+
aria-invalid={effectiveError ? true : undefined}
|
|
381
|
+
aria-describedby={[
|
|
382
|
+
field?.messageId,
|
|
383
|
+
localError && !field?.error
|
|
384
|
+
? messageId
|
|
385
|
+
: '',
|
|
386
|
+
].filter(Boolean).join(' ') || undefined}
|
|
387
|
+
{name}
|
|
388
|
+
{required}
|
|
389
|
+
{disabled}
|
|
390
|
+
value={value}
|
|
391
|
+
oninvalid={focusInvalidControl}
|
|
392
|
+
/>
|
|
393
|
+
|
|
394
|
+
<div class={cn('grid min-w-0 gap-3', effectiveError && 'rounded-lg ring-1 ring-error/35', size === 'sm' && 'gap-2')}>
|
|
395
|
+
{#if effectiveConfig.allowCron}
|
|
396
|
+
<label class='sr-only' for={`${controlId}-mode`}>{uiM('schedule_input_mode')}</label>
|
|
397
|
+
<Select
|
|
398
|
+
id={`${controlId}-mode`}
|
|
399
|
+
size={size}
|
|
400
|
+
options={modeOptions}
|
|
401
|
+
value={mode}
|
|
402
|
+
disabled={disabled}
|
|
403
|
+
onchange={handleModeChange}
|
|
404
|
+
/>
|
|
405
|
+
{/if}
|
|
406
|
+
|
|
407
|
+
{#if mode === 'datetime'}
|
|
408
|
+
<div class='grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_minmax(9rem,0.75fr)]'>
|
|
409
|
+
<DatePicker
|
|
410
|
+
value={calendarDate}
|
|
411
|
+
size={size}
|
|
412
|
+
disabled={disabled}
|
|
413
|
+
ariaLabel={uiM('schedule_input_date')}
|
|
414
|
+
onchange={handleDateChange}
|
|
415
|
+
/>
|
|
416
|
+
<div class='grid min-w-0 grid-cols-2 gap-2'>
|
|
417
|
+
<label class='sr-only' for={controlId}>{uiM('schedule_input_hour')}</label>
|
|
418
|
+
<Input
|
|
419
|
+
id={controlId}
|
|
420
|
+
data-schedule-hour
|
|
421
|
+
error={localError || undefined}
|
|
422
|
+
type='number'
|
|
423
|
+
size={size}
|
|
424
|
+
min={0}
|
|
425
|
+
max={23}
|
|
426
|
+
step={1}
|
|
427
|
+
inputmode='numeric'
|
|
428
|
+
value={dateDraft.hour}
|
|
429
|
+
disabled={disabled}
|
|
430
|
+
placeholder='HH'
|
|
431
|
+
oninput={event => updateTime('hour', event.currentTarget.value)}
|
|
432
|
+
/>
|
|
433
|
+
<label class='sr-only' for={`${controlId}-minute`}>{uiM('schedule_input_minute')}</label>
|
|
434
|
+
<Input
|
|
435
|
+
id={`${controlId}-minute`}
|
|
436
|
+
type='number'
|
|
437
|
+
size={size}
|
|
438
|
+
min={0}
|
|
439
|
+
max={59}
|
|
440
|
+
step={1}
|
|
441
|
+
inputmode='numeric'
|
|
442
|
+
value={dateDraft.minute}
|
|
443
|
+
disabled={disabled}
|
|
444
|
+
placeholder='MM'
|
|
445
|
+
oninput={event => updateTime('minute', event.currentTarget.value)}
|
|
446
|
+
/>
|
|
447
|
+
</div>
|
|
448
|
+
</div>
|
|
449
|
+
<p class='text-xs text-base-content/55'>
|
|
450
|
+
{effectiveConfig.timezone === 'Asia/Shanghai'
|
|
451
|
+
? uiM('schedule_input_timezone_hint')
|
|
452
|
+
: uiM('schedule_input_timezone_explicit', { timezone: effectiveConfig.timezone })}
|
|
453
|
+
</p>
|
|
454
|
+
{:else}
|
|
455
|
+
<CronExpressionBuilder
|
|
456
|
+
id={controlId}
|
|
457
|
+
name=''
|
|
458
|
+
value={cronDraft}
|
|
459
|
+
disabled={disabled}
|
|
460
|
+
required={required}
|
|
461
|
+
error={cronError || undefined}
|
|
462
|
+
describedBy={field?.error
|
|
463
|
+
? field.messageId
|
|
464
|
+
: cronError ? messageId : undefined}
|
|
465
|
+
labels={cronLabels}
|
|
466
|
+
onchange={handleCronChange}
|
|
467
|
+
/>
|
|
468
|
+
<p class='text-xs text-base-content/55'>{uiM('schedule_input_cron_hint')}</p>
|
|
469
|
+
{/if}
|
|
470
|
+
</div>
|
|
471
|
+
|
|
472
|
+
{#if localError && !field?.error}
|
|
473
|
+
<p id={messageId} class='mt-1 text-xs text-error'>{localError}</p>
|
|
474
|
+
{/if}
|
|
475
|
+
</div>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { DataAttributes, FormText, Size } from '../../types.js';
|
|
2
|
+
import type { ScheduleInputConfig } from './schedule-input.js';
|
|
3
|
+
/**
|
|
4
|
+
* ScheduleInput 组件的属性契约;通过公开组件配置使用。
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { mount, unmount } from 'svelte'
|
|
9
|
+
* import { ScheduleInput } from '@h-ai/ui'
|
|
10
|
+
* const component = mount(ScheduleInput, {
|
|
11
|
+
* target: document.body,
|
|
12
|
+
* props: { required: true },
|
|
13
|
+
* })
|
|
14
|
+
* await unmount(component)
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
interface Props {
|
|
18
|
+
/** Schema 元数据;省略时使用默认的北京时间、分钟精度配置。 */
|
|
19
|
+
config?: ScheduleInputConfig;
|
|
20
|
+
/** 日期时间 canonical 值或 Cron 表达式。 */
|
|
21
|
+
value?: string;
|
|
22
|
+
/** 当前值是否通过组件边界校验。 */
|
|
23
|
+
valid?: boolean;
|
|
24
|
+
/** 是否必须填写。 */
|
|
25
|
+
required?: boolean;
|
|
26
|
+
/** 是否禁用交互。 */
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/** 自定义错误提示。 */
|
|
29
|
+
error?: FormText;
|
|
30
|
+
/** 表单字段名。 */
|
|
31
|
+
name?: string;
|
|
32
|
+
/** 控件 ID。 */
|
|
33
|
+
id?: string;
|
|
34
|
+
/** 控件尺寸。 */
|
|
35
|
+
size?: Size;
|
|
36
|
+
/** 自定义类名。 */
|
|
37
|
+
class?: string;
|
|
38
|
+
/** 值变化回调。 */
|
|
39
|
+
onchange?: (value: string) => void;
|
|
40
|
+
}
|
|
41
|
+
type $$ComponentProps = Props & DataAttributes;
|
|
42
|
+
/**
|
|
43
|
+
* ScheduleInput
|
|
44
|
+
* 日期时间与高级 Cron 的统一调度输入。
|
|
45
|
+
*
|
|
46
|
+
* 日期时间使用配置的 IANA 时区,默认 Asia/Shanghai。Cron 编辑由
|
|
47
|
+
* CronExpressionBuilder 提供。
|
|
48
|
+
*/
|
|
49
|
+
declare const ScheduleInput: import("svelte").Component<$$ComponentProps, {}, "value" | "valid">;
|
|
50
|
+
type ScheduleInput = ReturnType<typeof ScheduleInput>;
|
|
51
|
+
export default ScheduleInput;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cron builder 的可视化模式。
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import type { CronBuilderMode } from '@h-ai/ui'
|
|
7
|
+
* const mode: CronBuilderMode = 'week'
|
|
8
|
+
* ```
|
|
9
|
+
*/
|
|
10
|
+
export type CronBuilderMode = 'minute' | 'hour' | 'day' | 'week' | 'month' | 'custom';
|
|
11
|
+
/**
|
|
12
|
+
* Cron builder 支持的星期值,0 和 7 都表示星期日,内部统一为 0。
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import type { CronWeekdayValue } from '@h-ai/ui'
|
|
17
|
+
* const sunday: CronWeekdayValue = '0'
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export type CronWeekdayValue = '0' | '1' | '2' | '3' | '4' | '5' | '6';
|
|
21
|
+
/**
|
|
22
|
+
* 可视化 Cron builder 的内部状态。
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import type { CronBuilderState } from '@h-ai/ui'
|
|
27
|
+
* const state: CronBuilderState = {
|
|
28
|
+
* mode: 'day', customExpression: '', minuteInterval: 5,
|
|
29
|
+
* hour: 10, minute: 0, monthDay: 1, weekDays: ['1'],
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export interface CronBuilderState {
|
|
34
|
+
mode: CronBuilderMode;
|
|
35
|
+
customExpression: string;
|
|
36
|
+
minuteInterval: number;
|
|
37
|
+
hour: number;
|
|
38
|
+
minute: number;
|
|
39
|
+
monthDay: number;
|
|
40
|
+
weekDays: CronWeekdayValue[];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Cron builder 的快捷预设。
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import type { CronExpressionBuilderPreset } from '@h-ai/ui'
|
|
48
|
+
* const preset: CronExpressionBuilderPreset = { expression: '0 10 * * *', label: 'Daily' }
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export interface CronExpressionBuilderPreset {
|
|
52
|
+
expression: string;
|
|
53
|
+
label: string;
|
|
54
|
+
description?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Cron builder 的用户可见文案。
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* import type { CronExpressionBuilderLabels } from '@h-ai/ui'
|
|
62
|
+
* const labels: CronExpressionBuilderLabels = {
|
|
63
|
+
* presets: 'Presets', modeMinute: 'Every few minutes', modeHour: 'Hourly',
|
|
64
|
+
* modeDay: 'Daily', modeWeek: 'Weekly', modeMonth: 'Monthly', modeCustom: 'Custom',
|
|
65
|
+
* fieldInterval: 'Interval', fieldMinute: 'Minute', fieldTime: 'Time',
|
|
66
|
+
* fieldWeekdays: 'Weekdays', fieldMonthDay: 'Day of month', fieldExpression: 'Cron',
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export interface CronExpressionBuilderLabels {
|
|
71
|
+
presets: string;
|
|
72
|
+
modeMinute: string;
|
|
73
|
+
modeHour: string;
|
|
74
|
+
modeDay: string;
|
|
75
|
+
modeWeek: string;
|
|
76
|
+
modeMonth: string;
|
|
77
|
+
modeCustom: string;
|
|
78
|
+
fieldInterval: string;
|
|
79
|
+
fieldMinute: string;
|
|
80
|
+
fieldTime: string;
|
|
81
|
+
fieldWeekdays: string;
|
|
82
|
+
fieldMonthDay: string;
|
|
83
|
+
fieldExpression: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* 星期选项,宿主可用本地化文案替换默认选项。
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* import type { CronExpressionBuilderWeekdayOption } from '@h-ai/ui'
|
|
91
|
+
* const monday: CronExpressionBuilderWeekdayOption = { value: '1', label: 'Mon' }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export interface CronExpressionBuilderWeekdayOption {
|
|
95
|
+
value: CronWeekdayValue;
|
|
96
|
+
label: string;
|
|
97
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|