@h-ai/ui 1.0.0-beta.34 → 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
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
@component CronExpressionBuilder
|
|
3
|
+
可视化编辑常用的五段 Cron 表达式,并保留自定义表达式输入。
|
|
4
|
+
|
|
5
|
+
组件不负责 Cron 解析器校验或自然语言预览;宿主可通过 error 和回调接入自己的业务校验。
|
|
6
|
+
-->
|
|
7
|
+
<script lang='ts'>
|
|
8
|
+
import type { DataAttributes } from '../../types.js'
|
|
9
|
+
import type {
|
|
10
|
+
CronBuilderMode,
|
|
11
|
+
CronBuilderState,
|
|
12
|
+
CronExpressionBuilderLabels,
|
|
13
|
+
CronExpressionBuilderPreset,
|
|
14
|
+
CronExpressionBuilderWeekdayOption,
|
|
15
|
+
CronWeekdayValue,
|
|
16
|
+
} from './cron-expression-builder-types.js'
|
|
17
|
+
import { getDataAttributes } from '../../utils.js'
|
|
18
|
+
import {
|
|
19
|
+
createDefaultCronBuilderState,
|
|
20
|
+
cronBuilderStateToExpression,
|
|
21
|
+
cronExpressionToBuilderState,
|
|
22
|
+
} from './cron-expression-builder.js'
|
|
23
|
+
|
|
24
|
+
const DEFAULT_LABELS: CronExpressionBuilderLabels = {
|
|
25
|
+
presets: 'Presets',
|
|
26
|
+
modeMinute: 'Every few minutes',
|
|
27
|
+
modeHour: 'Hourly',
|
|
28
|
+
modeDay: 'Daily',
|
|
29
|
+
modeWeek: 'Weekly',
|
|
30
|
+
modeMonth: 'Monthly',
|
|
31
|
+
modeCustom: 'Custom',
|
|
32
|
+
fieldInterval: 'Interval (minutes)',
|
|
33
|
+
fieldMinute: 'Minute',
|
|
34
|
+
fieldTime: 'Time',
|
|
35
|
+
fieldWeekdays: 'Weekdays',
|
|
36
|
+
fieldMonthDay: 'Day of month',
|
|
37
|
+
fieldExpression: 'Cron expression',
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const DEFAULT_WEEKDAY_OPTIONS: CronExpressionBuilderWeekdayOption[] = [
|
|
41
|
+
{ value: '1', label: 'Mon' },
|
|
42
|
+
{ value: '2', label: 'Tue' },
|
|
43
|
+
{ value: '3', label: 'Wed' },
|
|
44
|
+
{ value: '4', label: 'Thu' },
|
|
45
|
+
{ value: '5', label: 'Fri' },
|
|
46
|
+
{ value: '6', label: 'Sat' },
|
|
47
|
+
{ value: '0', label: 'Sun' },
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* CronExpressionBuilder 组件的属性契约;通过公开组件配置使用。
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { mount, unmount } from 'svelte'
|
|
56
|
+
* import { CronExpressionBuilder } from '@h-ai/ui'
|
|
57
|
+
* const component = mount(CronExpressionBuilder, {
|
|
58
|
+
* target: document.body,
|
|
59
|
+
* props: { value: '0 10 * * *' },
|
|
60
|
+
* })
|
|
61
|
+
* await unmount(component)
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
interface Props {
|
|
65
|
+
id?: string
|
|
66
|
+
name?: string
|
|
67
|
+
value?: string
|
|
68
|
+
disabled?: boolean
|
|
69
|
+
required?: boolean
|
|
70
|
+
error?: string
|
|
71
|
+
/** 关联宿主提供的表单提示或错误文案 ID。 */
|
|
72
|
+
describedBy?: string
|
|
73
|
+
presets?: CronExpressionBuilderPreset[]
|
|
74
|
+
labels?: Partial<CronExpressionBuilderLabels>
|
|
75
|
+
weekdayOptions?: CronExpressionBuilderWeekdayOption[]
|
|
76
|
+
onchange?: (value: string) => void
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let {
|
|
80
|
+
id = 'cron-expression',
|
|
81
|
+
name = 'cronExpression',
|
|
82
|
+
value = $bindable(''),
|
|
83
|
+
disabled = false,
|
|
84
|
+
required = false,
|
|
85
|
+
error = '',
|
|
86
|
+
describedBy,
|
|
87
|
+
presets = [],
|
|
88
|
+
labels: labelOverrides = {},
|
|
89
|
+
weekdayOptions = DEFAULT_WEEKDAY_OPTIONS,
|
|
90
|
+
onchange,
|
|
91
|
+
...restProps
|
|
92
|
+
}: Props & DataAttributes = $props()
|
|
93
|
+
|
|
94
|
+
const dataAttributes = $derived(getDataAttributes(restProps))
|
|
95
|
+
let builderState = $state<CronBuilderState>(createDefaultCronBuilderState())
|
|
96
|
+
let lastSyncedValue = $state('')
|
|
97
|
+
let panelOpen = $state(false)
|
|
98
|
+
let rootElement = $state<HTMLDivElement | null>(null)
|
|
99
|
+
|
|
100
|
+
const labels = $derived<CronExpressionBuilderLabels>({
|
|
101
|
+
...DEFAULT_LABELS,
|
|
102
|
+
...labelOverrides,
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const modeOptions = $derived([
|
|
106
|
+
{ value: 'minute' as const, label: labels.modeMinute },
|
|
107
|
+
{ value: 'hour' as const, label: labels.modeHour },
|
|
108
|
+
{ value: 'day' as const, label: labels.modeDay },
|
|
109
|
+
{ value: 'week' as const, label: labels.modeWeek },
|
|
110
|
+
{ value: 'month' as const, label: labels.modeMonth },
|
|
111
|
+
{ value: 'custom' as const, label: labels.modeCustom },
|
|
112
|
+
])
|
|
113
|
+
|
|
114
|
+
const activeExpression = $derived(value.trim())
|
|
115
|
+
const manualExpressionValue = $derived(builderState.customExpression || activeExpression)
|
|
116
|
+
|
|
117
|
+
$effect(() => {
|
|
118
|
+
const normalized = value.trim()
|
|
119
|
+
if (normalized === lastSyncedValue) {
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
applyBuilderState(cronExpressionToBuilderState(normalized))
|
|
124
|
+
lastSyncedValue = normalized
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
function applyBuilderState(nextState: CronBuilderState): void {
|
|
128
|
+
builderState = {
|
|
129
|
+
...nextState,
|
|
130
|
+
weekDays: ensureWeekDays(nextState.weekDays),
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function syncValue(nextValue: string): void {
|
|
135
|
+
const normalized = nextValue.trim()
|
|
136
|
+
value = normalized
|
|
137
|
+
lastSyncedValue = normalized
|
|
138
|
+
onchange?.(normalized)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function buildCurrentState(mode: CronBuilderMode = builderState.mode): CronBuilderState {
|
|
142
|
+
return {
|
|
143
|
+
...builderState,
|
|
144
|
+
mode,
|
|
145
|
+
weekDays: ensureWeekDays(builderState.weekDays),
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function openConfigPanel(): void {
|
|
150
|
+
if (disabled) {
|
|
151
|
+
return
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
panelOpen = true
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function handleDocumentPointerDown(event: PointerEvent): void {
|
|
158
|
+
if (!panelOpen || !rootElement) {
|
|
159
|
+
return
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const target = event.target
|
|
163
|
+
if (!(target instanceof Node)) {
|
|
164
|
+
return
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (rootElement.contains(target)) {
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
panelOpen = false
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function handleDocumentFocusIn(event: FocusEvent): void {
|
|
175
|
+
if (!panelOpen || !rootElement) {
|
|
176
|
+
return
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const target = event.target
|
|
180
|
+
if (!(target instanceof Node)) {
|
|
181
|
+
panelOpen = false
|
|
182
|
+
return
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
if (rootElement.contains(target)) {
|
|
186
|
+
return
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
panelOpen = false
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function applyPreset(expression: string): void {
|
|
193
|
+
if (disabled) {
|
|
194
|
+
return
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
syncValue(expression)
|
|
198
|
+
applyBuilderState(cronExpressionToBuilderState(expression))
|
|
199
|
+
panelOpen = true
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function activateMode(mode: CronBuilderMode): void {
|
|
203
|
+
if (disabled) {
|
|
204
|
+
return
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (mode === 'custom') {
|
|
208
|
+
builderState = {
|
|
209
|
+
...builderState,
|
|
210
|
+
mode,
|
|
211
|
+
}
|
|
212
|
+
syncValue(builderState.customExpression || activeExpression)
|
|
213
|
+
return
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
builderState = buildCurrentState(mode)
|
|
217
|
+
syncVisualExpression(mode)
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function syncVisualExpression(mode: CronBuilderMode = builderState.mode): void {
|
|
221
|
+
const nextState = buildCurrentState(mode)
|
|
222
|
+
const nextExpression = cronBuilderStateToExpression(nextState)
|
|
223
|
+
syncValue(nextExpression)
|
|
224
|
+
applyBuilderState(cronExpressionToBuilderState(nextExpression))
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function updateMinuteInterval(nextValue: string): void {
|
|
228
|
+
builderState = {
|
|
229
|
+
...builderState,
|
|
230
|
+
minuteInterval: normalizeNumber(nextValue, 1, 59, builderState.minuteInterval),
|
|
231
|
+
}
|
|
232
|
+
syncVisualExpression('minute')
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function updateMinute(nextValue: string, mode: Extract<CronBuilderMode, 'hour' | 'day' | 'week' | 'month'>): void {
|
|
236
|
+
builderState = {
|
|
237
|
+
...builderState,
|
|
238
|
+
minute: normalizeNumber(nextValue, 0, 59, builderState.minute),
|
|
239
|
+
}
|
|
240
|
+
syncVisualExpression(mode)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function updateHour(nextValue: string, mode: Extract<CronBuilderMode, 'day' | 'week' | 'month'>): void {
|
|
244
|
+
builderState = {
|
|
245
|
+
...builderState,
|
|
246
|
+
hour: normalizeNumber(nextValue, 0, 23, builderState.hour),
|
|
247
|
+
}
|
|
248
|
+
syncVisualExpression(mode)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function updateMonthDay(nextValue: string): void {
|
|
252
|
+
builderState = {
|
|
253
|
+
...builderState,
|
|
254
|
+
monthDay: normalizeNumber(nextValue, 1, 31, builderState.monthDay),
|
|
255
|
+
}
|
|
256
|
+
syncVisualExpression('month')
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function toggleWeekDay(day: CronWeekdayValue): void {
|
|
260
|
+
const nextWeekDays = builderState.weekDays.includes(day)
|
|
261
|
+
? builderState.weekDays.filter(value => value !== day)
|
|
262
|
+
: [...builderState.weekDays, day]
|
|
263
|
+
|
|
264
|
+
builderState = {
|
|
265
|
+
...builderState,
|
|
266
|
+
weekDays: ensureWeekDays(nextWeekDays),
|
|
267
|
+
}
|
|
268
|
+
syncVisualExpression('week')
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function handleManualInput(event: Event): void {
|
|
272
|
+
const nextValue = (event.currentTarget as HTMLInputElement).value
|
|
273
|
+
syncValue(nextValue)
|
|
274
|
+
applyBuilderState(cronExpressionToBuilderState(nextValue))
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function isPresetActive(expression: string): boolean {
|
|
278
|
+
return activeExpression === expression
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function normalizeNumber(value: string, min: number, max: number, fallback: number): number {
|
|
282
|
+
const parsed = Number.parseInt(value, 10)
|
|
283
|
+
if (!Number.isFinite(parsed)) {
|
|
284
|
+
return fallback
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
return Math.min(max, Math.max(min, parsed))
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function ensureWeekDays(values: readonly CronWeekdayValue[]): CronWeekdayValue[] {
|
|
291
|
+
const uniqueValues = weekdayOptions
|
|
292
|
+
.map(option => option.value)
|
|
293
|
+
.filter((optionValue, index, source) => source.indexOf(optionValue) === index)
|
|
294
|
+
.filter(optionValue => values.includes(optionValue))
|
|
295
|
+
|
|
296
|
+
return uniqueValues.length > 0
|
|
297
|
+
? uniqueValues
|
|
298
|
+
: [weekdayOptions[0]?.value ?? '1']
|
|
299
|
+
}
|
|
300
|
+
</script>
|
|
301
|
+
|
|
302
|
+
<svelte:document
|
|
303
|
+
onpointerdown={handleDocumentPointerDown}
|
|
304
|
+
onfocusin={handleDocumentFocusIn}
|
|
305
|
+
/>
|
|
306
|
+
|
|
307
|
+
<div {...dataAttributes} bind:this={rootElement} class='task-cron-builder'>
|
|
308
|
+
<input type='hidden' {name} value={activeExpression} />
|
|
309
|
+
|
|
310
|
+
<div class='task-cron-builder__dropdown'>
|
|
311
|
+
<div class='task-cron-builder__field'>
|
|
312
|
+
<input
|
|
313
|
+
id={id}
|
|
314
|
+
type='text'
|
|
315
|
+
class='task-cron-builder__input'
|
|
316
|
+
class:has-error={Boolean(error)}
|
|
317
|
+
data-cron-manual-input
|
|
318
|
+
value={manualExpressionValue}
|
|
319
|
+
placeholder='0 10 * * *'
|
|
320
|
+
{required}
|
|
321
|
+
disabled={disabled}
|
|
322
|
+
aria-label={labels.fieldExpression}
|
|
323
|
+
aria-invalid={Boolean(error)}
|
|
324
|
+
aria-describedby={describedBy}
|
|
325
|
+
onfocus={openConfigPanel}
|
|
326
|
+
oninput={handleManualInput}
|
|
327
|
+
/>
|
|
328
|
+
</div>
|
|
329
|
+
|
|
330
|
+
{#if panelOpen}
|
|
331
|
+
<div class='task-cron-builder__config-panel' data-cron-config-panel>
|
|
332
|
+
{#if presets.length > 0}
|
|
333
|
+
<section class='task-cron-builder__section'>
|
|
334
|
+
<span class='task-cron-builder__caption'>{labels.presets}</span>
|
|
335
|
+
<div class='task-cron-builder__preset-list'>
|
|
336
|
+
{#each presets as preset (preset.expression)}
|
|
337
|
+
<button
|
|
338
|
+
type='button'
|
|
339
|
+
class='task-cron-builder__preset'
|
|
340
|
+
class:is-active={isPresetActive(preset.expression)}
|
|
341
|
+
data-cron-preset={preset.expression}
|
|
342
|
+
aria-pressed={isPresetActive(preset.expression)}
|
|
343
|
+
disabled={disabled}
|
|
344
|
+
title={preset.description || preset.label}
|
|
345
|
+
onclick={() => applyPreset(preset.expression)}
|
|
346
|
+
>
|
|
347
|
+
{preset.label}
|
|
348
|
+
</button>
|
|
349
|
+
{/each}
|
|
350
|
+
</div>
|
|
351
|
+
</section>
|
|
352
|
+
{/if}
|
|
353
|
+
|
|
354
|
+
<section class='task-cron-builder__section'>
|
|
355
|
+
<div class='task-cron-builder__mode-list' role='tablist' aria-label={labels.fieldExpression}>
|
|
356
|
+
{#each modeOptions as option (option.value)}
|
|
357
|
+
<button
|
|
358
|
+
type='button'
|
|
359
|
+
class='task-cron-builder__mode'
|
|
360
|
+
class:is-active={builderState.mode === option.value}
|
|
361
|
+
data-cron-mode={option.value}
|
|
362
|
+
role='tab'
|
|
363
|
+
aria-selected={builderState.mode === option.value}
|
|
364
|
+
disabled={disabled}
|
|
365
|
+
onclick={() => activateMode(option.value)}
|
|
366
|
+
>
|
|
367
|
+
{option.label}
|
|
368
|
+
</button>
|
|
369
|
+
{/each}
|
|
370
|
+
</div>
|
|
371
|
+
|
|
372
|
+
<div class='task-cron-builder__controls'>
|
|
373
|
+
{#if builderState.mode === 'week'}
|
|
374
|
+
<div class='task-cron-builder__field task-cron-builder__field--stacked'>
|
|
375
|
+
<span class='task-cron-builder__label'>{labels.fieldWeekdays}</span>
|
|
376
|
+
<div class='task-cron-builder__weekday-list'>
|
|
377
|
+
{#each weekdayOptions as option (option.value)}
|
|
378
|
+
<label class='task-cron-builder__weekday'>
|
|
379
|
+
<input
|
|
380
|
+
type='checkbox'
|
|
381
|
+
data-cron-weekday={option.value}
|
|
382
|
+
checked={builderState.weekDays.includes(option.value)}
|
|
383
|
+
disabled={disabled}
|
|
384
|
+
onchange={() => toggleWeekDay(option.value)}
|
|
385
|
+
/>
|
|
386
|
+
<span>{option.label}</span>
|
|
387
|
+
</label>
|
|
388
|
+
{/each}
|
|
389
|
+
</div>
|
|
390
|
+
</div>
|
|
391
|
+
{/if}
|
|
392
|
+
|
|
393
|
+
{#if builderState.mode === 'minute'}
|
|
394
|
+
<div class='task-cron-builder__field task-cron-builder__field--compact'>
|
|
395
|
+
<label class='task-cron-builder__label' for={`${id}-interval`}>{labels.fieldInterval}</label>
|
|
396
|
+
<input
|
|
397
|
+
id={`${id}-interval`}
|
|
398
|
+
type='number'
|
|
399
|
+
min='1'
|
|
400
|
+
max='59'
|
|
401
|
+
class='task-cron-builder__input'
|
|
402
|
+
value={builderState.minuteInterval}
|
|
403
|
+
disabled={disabled}
|
|
404
|
+
onchange={event => updateMinuteInterval((event.currentTarget as HTMLInputElement).value)}
|
|
405
|
+
/>
|
|
406
|
+
</div>
|
|
407
|
+
{/if}
|
|
408
|
+
|
|
409
|
+
{#if builderState.mode === 'hour'}
|
|
410
|
+
<div class='task-cron-builder__field task-cron-builder__field--compact'>
|
|
411
|
+
<label class='task-cron-builder__label' for={`${id}-hour-minute`}>{labels.fieldMinute}</label>
|
|
412
|
+
<input
|
|
413
|
+
id={`${id}-hour-minute`}
|
|
414
|
+
type='number'
|
|
415
|
+
min='0'
|
|
416
|
+
max='59'
|
|
417
|
+
class='task-cron-builder__input'
|
|
418
|
+
value={builderState.minute}
|
|
419
|
+
disabled={disabled}
|
|
420
|
+
onchange={event => updateMinute((event.currentTarget as HTMLInputElement).value, 'hour')}
|
|
421
|
+
/>
|
|
422
|
+
</div>
|
|
423
|
+
{/if}
|
|
424
|
+
|
|
425
|
+
{#if builderState.mode === 'day' || builderState.mode === 'week' || builderState.mode === 'month'}
|
|
426
|
+
<div class='task-cron-builder__field-grid'>
|
|
427
|
+
{#if builderState.mode === 'month'}
|
|
428
|
+
<div class='task-cron-builder__field task-cron-builder__field--compact'>
|
|
429
|
+
<label class='task-cron-builder__label' for={`${id}-month-day`}>{labels.fieldMonthDay}</label>
|
|
430
|
+
<input
|
|
431
|
+
id={`${id}-month-day`}
|
|
432
|
+
type='number'
|
|
433
|
+
min='1'
|
|
434
|
+
max='31'
|
|
435
|
+
class='task-cron-builder__input'
|
|
436
|
+
value={builderState.monthDay}
|
|
437
|
+
disabled={disabled}
|
|
438
|
+
onchange={event => updateMonthDay((event.currentTarget as HTMLInputElement).value)}
|
|
439
|
+
/>
|
|
440
|
+
</div>
|
|
441
|
+
{/if}
|
|
442
|
+
|
|
443
|
+
<div class='task-cron-builder__field task-cron-builder__field--compact'>
|
|
444
|
+
<label class='task-cron-builder__label' for={`${id}-hour`}>{labels.fieldTime}</label>
|
|
445
|
+
<div class='task-cron-builder__time-grid'>
|
|
446
|
+
<input
|
|
447
|
+
id={`${id}-hour`}
|
|
448
|
+
type='number'
|
|
449
|
+
min='0'
|
|
450
|
+
max='23'
|
|
451
|
+
class='task-cron-builder__input'
|
|
452
|
+
value={builderState.hour}
|
|
453
|
+
disabled={disabled}
|
|
454
|
+
onchange={event => updateHour(
|
|
455
|
+
(event.currentTarget as HTMLInputElement).value,
|
|
456
|
+
builderState.mode === 'day'
|
|
457
|
+
? 'day'
|
|
458
|
+
: builderState.mode === 'week'
|
|
459
|
+
? 'week'
|
|
460
|
+
: 'month',
|
|
461
|
+
)}
|
|
462
|
+
/>
|
|
463
|
+
<span class='task-cron-builder__time-separator'>:</span>
|
|
464
|
+
<input
|
|
465
|
+
id={`${id}-minute`}
|
|
466
|
+
type='number'
|
|
467
|
+
min='0'
|
|
468
|
+
max='59'
|
|
469
|
+
class='task-cron-builder__input'
|
|
470
|
+
value={builderState.minute}
|
|
471
|
+
disabled={disabled}
|
|
472
|
+
onchange={event => updateMinute(
|
|
473
|
+
(event.currentTarget as HTMLInputElement).value,
|
|
474
|
+
builderState.mode === 'day'
|
|
475
|
+
? 'day'
|
|
476
|
+
: builderState.mode === 'week'
|
|
477
|
+
? 'week'
|
|
478
|
+
: 'month',
|
|
479
|
+
)}
|
|
480
|
+
/>
|
|
481
|
+
</div>
|
|
482
|
+
</div>
|
|
483
|
+
</div>
|
|
484
|
+
{/if}
|
|
485
|
+
</div>
|
|
486
|
+
</section>
|
|
487
|
+
</div>
|
|
488
|
+
{/if}
|
|
489
|
+
</div>
|
|
490
|
+
</div>
|
|
491
|
+
|
|
492
|
+
<style>
|
|
493
|
+
.task-cron-builder {
|
|
494
|
+
position: relative;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
.task-cron-builder__dropdown {
|
|
498
|
+
position: relative;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
.task-cron-builder__field,
|
|
502
|
+
.task-cron-builder__section,
|
|
503
|
+
.task-cron-builder__controls,
|
|
504
|
+
.task-cron-builder__config-panel {
|
|
505
|
+
display: grid;
|
|
506
|
+
gap: 8px;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
.task-cron-builder__label,
|
|
510
|
+
.task-cron-builder__caption {
|
|
511
|
+
color: color-mix(in oklab, var(--color-base-content) 76%, transparent);
|
|
512
|
+
font-size: 12px;
|
|
513
|
+
font-weight: 600;
|
|
514
|
+
line-height: 1.4;
|
|
515
|
+
letter-spacing: 0.02em;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
.task-cron-builder__input {
|
|
519
|
+
width: 100%;
|
|
520
|
+
min-height: 32px;
|
|
521
|
+
padding: 0 10px;
|
|
522
|
+
border: 1px solid color-mix(in oklab, var(--color-base-content) 14%, transparent);
|
|
523
|
+
border-radius: 8px;
|
|
524
|
+
background: var(--color-base-100);
|
|
525
|
+
color: var(--color-base-content);
|
|
526
|
+
font-size: 13px;
|
|
527
|
+
line-height: 1.4;
|
|
528
|
+
transition:
|
|
529
|
+
border-color 0.18s ease,
|
|
530
|
+
box-shadow 0.18s ease;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
.task-cron-builder__input:focus {
|
|
534
|
+
outline: none;
|
|
535
|
+
border-color: color-mix(in oklab, var(--color-primary) 72%, transparent);
|
|
536
|
+
box-shadow: 0 0 0 3px color-mix(in oklab, var(--color-primary) 14%, transparent);
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
.task-cron-builder__input.has-error {
|
|
540
|
+
border-color: color-mix(in oklab, var(--color-error) 64%, transparent);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
.task-cron-builder__config-panel {
|
|
544
|
+
position: absolute;
|
|
545
|
+
top: calc(100% + 8px);
|
|
546
|
+
right: 0;
|
|
547
|
+
left: 0;
|
|
548
|
+
z-index: 30;
|
|
549
|
+
padding: 10px 12px 12px;
|
|
550
|
+
border: 1px solid color-mix(in oklab, var(--color-base-content) 10%, transparent);
|
|
551
|
+
border-radius: 10px;
|
|
552
|
+
background:
|
|
553
|
+
linear-gradient(
|
|
554
|
+
180deg,
|
|
555
|
+
color-mix(in oklab, var(--color-base-100) 94%, white) 0%,
|
|
556
|
+
var(--color-base-100) 100%
|
|
557
|
+
);
|
|
558
|
+
box-shadow: 0 10px 28px color-mix(in oklab, var(--color-base-content) 10%, transparent);
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
.task-cron-builder__preset-list,
|
|
562
|
+
.task-cron-builder__mode-list,
|
|
563
|
+
.task-cron-builder__weekday-list {
|
|
564
|
+
display: flex;
|
|
565
|
+
flex-wrap: nowrap;
|
|
566
|
+
gap: 6px;
|
|
567
|
+
overflow-x: auto;
|
|
568
|
+
scrollbar-width: thin;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
.task-cron-builder__preset,
|
|
572
|
+
.task-cron-builder__mode,
|
|
573
|
+
.task-cron-builder__weekday {
|
|
574
|
+
flex: 0 0 auto;
|
|
575
|
+
appearance: none;
|
|
576
|
+
border: 1px solid color-mix(in oklab, var(--color-base-content) 12%, transparent);
|
|
577
|
+
border-radius: 999px;
|
|
578
|
+
background: color-mix(in oklab, var(--color-base-100) 92%, white);
|
|
579
|
+
color: color-mix(in oklab, var(--color-base-content) 78%, transparent);
|
|
580
|
+
transition:
|
|
581
|
+
border-color 0.18s ease,
|
|
582
|
+
background-color 0.18s ease,
|
|
583
|
+
color 0.18s ease;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
.task-cron-builder__preset,
|
|
587
|
+
.task-cron-builder__mode {
|
|
588
|
+
padding: 5px 10px;
|
|
589
|
+
font-size: 12px;
|
|
590
|
+
font-weight: 500;
|
|
591
|
+
line-height: 1;
|
|
592
|
+
white-space: nowrap;
|
|
593
|
+
cursor: pointer;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
.task-cron-builder__preset:hover,
|
|
597
|
+
.task-cron-builder__mode:hover,
|
|
598
|
+
.task-cron-builder__weekday:hover {
|
|
599
|
+
border-color: color-mix(in oklab, var(--color-primary) 42%, transparent);
|
|
600
|
+
background: color-mix(in oklab, var(--color-primary) 7%, transparent);
|
|
601
|
+
color: var(--color-primary);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
.task-cron-builder__preset.is-active,
|
|
605
|
+
.task-cron-builder__mode.is-active {
|
|
606
|
+
border-color: color-mix(in oklab, var(--color-primary) 58%, transparent);
|
|
607
|
+
background: color-mix(in oklab, var(--color-primary) 11%, transparent);
|
|
608
|
+
color: var(--color-primary);
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
.task-cron-builder__field-grid {
|
|
612
|
+
display: grid;
|
|
613
|
+
gap: 10px;
|
|
614
|
+
grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
.task-cron-builder__field--compact,
|
|
618
|
+
.task-cron-builder__field--stacked {
|
|
619
|
+
gap: 6px;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
.task-cron-builder__time-grid {
|
|
623
|
+
display: grid;
|
|
624
|
+
grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
|
|
625
|
+
gap: 6px;
|
|
626
|
+
align-items: center;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
.task-cron-builder__time-separator {
|
|
630
|
+
color: color-mix(in oklab, var(--color-base-content) 54%, transparent);
|
|
631
|
+
font-weight: 600;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
.task-cron-builder__weekday-list {
|
|
635
|
+
width: 100%;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
.task-cron-builder__weekday {
|
|
639
|
+
display: inline-flex;
|
|
640
|
+
align-items: center;
|
|
641
|
+
gap: 4px;
|
|
642
|
+
min-height: 24px;
|
|
643
|
+
padding: 0 7px;
|
|
644
|
+
cursor: pointer;
|
|
645
|
+
white-space: nowrap;
|
|
646
|
+
font-size: 11px;
|
|
647
|
+
line-height: 1;
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
.task-cron-builder__weekday input {
|
|
651
|
+
margin: 0;
|
|
652
|
+
inline-size: 11px;
|
|
653
|
+
block-size: 11px;
|
|
654
|
+
}
|
|
655
|
+
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { DataAttributes } from '../../types.js';
|
|
2
|
+
import type { CronExpressionBuilderLabels, CronExpressionBuilderPreset, CronExpressionBuilderWeekdayOption } from './cron-expression-builder-types.js';
|
|
3
|
+
/**
|
|
4
|
+
* CronExpressionBuilder 组件的属性契约;通过公开组件配置使用。
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { mount, unmount } from 'svelte'
|
|
9
|
+
* import { CronExpressionBuilder } from '@h-ai/ui'
|
|
10
|
+
* const component = mount(CronExpressionBuilder, {
|
|
11
|
+
* target: document.body,
|
|
12
|
+
* props: { value: '0 10 * * *' },
|
|
13
|
+
* })
|
|
14
|
+
* await unmount(component)
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
interface Props {
|
|
18
|
+
id?: string;
|
|
19
|
+
name?: string;
|
|
20
|
+
value?: string;
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
required?: boolean;
|
|
23
|
+
error?: string;
|
|
24
|
+
/** 关联宿主提供的表单提示或错误文案 ID。 */
|
|
25
|
+
describedBy?: string;
|
|
26
|
+
presets?: CronExpressionBuilderPreset[];
|
|
27
|
+
labels?: Partial<CronExpressionBuilderLabels>;
|
|
28
|
+
weekdayOptions?: CronExpressionBuilderWeekdayOption[];
|
|
29
|
+
onchange?: (value: string) => void;
|
|
30
|
+
}
|
|
31
|
+
type $$ComponentProps = Props & DataAttributes;
|
|
32
|
+
/**
|
|
33
|
+
* CronExpressionBuilder
|
|
34
|
+
* 可视化编辑常用的五段 Cron 表达式,并保留自定义表达式输入。
|
|
35
|
+
*
|
|
36
|
+
* 组件不负责 Cron 解析器校验或自然语言预览;宿主可通过 error 和回调接入自己的业务校验。
|
|
37
|
+
*/
|
|
38
|
+
declare const CronExpressionBuilder: import("svelte").Component<$$ComponentProps, {}, "value">;
|
|
39
|
+
type CronExpressionBuilder = ReturnType<typeof CronExpressionBuilder>;
|
|
40
|
+
export default CronExpressionBuilder;
|