@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,63 @@
|
|
|
1
|
+
import type { CronBuilderState, CronWeekdayValue } from './cron-expression-builder-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* builder 输出星期的固定顺序,从周一到周日。
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { CRON_BUILDER_WEEKDAY_ORDER } from '@h-ai/ui'
|
|
8
|
+
* const weekdays = [...CRON_BUILDER_WEEKDAY_ORDER]
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare const CRON_BUILDER_WEEKDAY_ORDER: readonly CronWeekdayValue[];
|
|
12
|
+
/**
|
|
13
|
+
* 创建可视化 Cron builder 的默认状态。
|
|
14
|
+
*
|
|
15
|
+
* @returns 可直接交给 CronExpressionBuilder 的初始状态。
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import { createDefaultCronBuilderState } from '@h-ai/ui'
|
|
20
|
+
* const state = createDefaultCronBuilderState()
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function createDefaultCronBuilderState(): CronBuilderState;
|
|
24
|
+
/**
|
|
25
|
+
* 将 Cron 表达式映射为 builder 状态。
|
|
26
|
+
* 仅对常见五段表达式和前导秒为 0 的六段表达式启用可视化模式,其余回退到自定义模式。
|
|
27
|
+
*
|
|
28
|
+
* @param expression 要解析的 Cron 表达式。
|
|
29
|
+
* @returns 可视化或自定义模式状态。
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { cronExpressionToBuilderState } from '@h-ai/ui'
|
|
34
|
+
* const state = cronExpressionToBuilderState('0 10 * * *')
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
export declare function cronExpressionToBuilderState(expression: string): CronBuilderState;
|
|
38
|
+
/**
|
|
39
|
+
* 将 builder 状态序列化为标准五段 Cron 表达式。
|
|
40
|
+
*
|
|
41
|
+
* @param state 要序列化的 builder 状态。
|
|
42
|
+
* @returns 标准五段 Cron 表达式;自定义模式返回清理后的原文。
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* import { createDefaultCronBuilderState, cronBuilderStateToExpression } from '@h-ai/ui'
|
|
47
|
+
* const expression = cronBuilderStateToExpression({ ...createDefaultCronBuilderState(), mode: 'day' })
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function cronBuilderStateToExpression(state: CronBuilderState): string;
|
|
51
|
+
/**
|
|
52
|
+
* 使用 cron-parser 校验 Cron 表达式;业务调用方可在此基础上限制字段数量。
|
|
53
|
+
*
|
|
54
|
+
* @param expression 要校验的 Cron 表达式。
|
|
55
|
+
* @returns 表达式可被 cron-parser 解析时为 true。
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* import { isCronExpressionValid } from '@h-ai/ui'
|
|
60
|
+
* const valid = isCronExpressionValid('0 10 * * *')
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function isCronExpressionValid(expression: string): boolean;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { CronExpressionParser } from 'cron-parser';
|
|
2
|
+
/** 拆分 Cron 字段的空白分隔符。 */
|
|
3
|
+
const CRON_WHITESPACE_RE = /\s+/;
|
|
4
|
+
/** 验证是否为纯整数字符串。 */
|
|
5
|
+
const INTEGER_RE = /^\d+$/;
|
|
6
|
+
/** 验证是否为合法的步进分钟表达式。 */
|
|
7
|
+
const MINUTE_INTERVAL_RE = /^\*\/(\d+)$/;
|
|
8
|
+
/** 可视化 builder 支持的标准五段表达式。 */
|
|
9
|
+
const STANDARD_FIVE_SEGMENT_LENGTH = 5;
|
|
10
|
+
/** 支持把前导秒字段为 0 的六段表达式映射到可视化 builder。 */
|
|
11
|
+
const STANDARD_SIX_SEGMENT_LENGTH = 6;
|
|
12
|
+
/**
|
|
13
|
+
* builder 输出星期的固定顺序,从周一到周日。
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* import { CRON_BUILDER_WEEKDAY_ORDER } from '@h-ai/ui'
|
|
18
|
+
* const weekdays = [...CRON_BUILDER_WEEKDAY_ORDER]
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const CRON_BUILDER_WEEKDAY_ORDER = ['1', '2', '3', '4', '5', '6', '0'];
|
|
22
|
+
/**
|
|
23
|
+
* 创建可视化 Cron builder 的默认状态。
|
|
24
|
+
*
|
|
25
|
+
* @returns 可直接交给 CronExpressionBuilder 的初始状态。
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* import { createDefaultCronBuilderState } from '@h-ai/ui'
|
|
30
|
+
* const state = createDefaultCronBuilderState()
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function createDefaultCronBuilderState() {
|
|
34
|
+
return {
|
|
35
|
+
mode: 'day',
|
|
36
|
+
customExpression: '',
|
|
37
|
+
minuteInterval: 5,
|
|
38
|
+
hour: 10,
|
|
39
|
+
minute: 0,
|
|
40
|
+
monthDay: 1,
|
|
41
|
+
weekDays: ['1'],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 将 Cron 表达式映射为 builder 状态。
|
|
46
|
+
* 仅对常见五段表达式和前导秒为 0 的六段表达式启用可视化模式,其余回退到自定义模式。
|
|
47
|
+
*
|
|
48
|
+
* @param expression 要解析的 Cron 表达式。
|
|
49
|
+
* @returns 可视化或自定义模式状态。
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* import { cronExpressionToBuilderState } from '@h-ai/ui'
|
|
54
|
+
* const state = cronExpressionToBuilderState('0 10 * * *')
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export function cronExpressionToBuilderState(expression) {
|
|
58
|
+
const normalized = expression.trim();
|
|
59
|
+
if (!normalized) {
|
|
60
|
+
return createDefaultCronBuilderState();
|
|
61
|
+
}
|
|
62
|
+
const builderExpression = normalizeCronExpressionForBuilder(normalized);
|
|
63
|
+
if (!builderExpression) {
|
|
64
|
+
return {
|
|
65
|
+
...createDefaultCronBuilderState(),
|
|
66
|
+
mode: 'custom',
|
|
67
|
+
customExpression: normalized,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const segments = builderExpression.split(CRON_WHITESPACE_RE);
|
|
71
|
+
const [minutePart, hourPart, dayOfMonth, month, dayOfWeek] = segments;
|
|
72
|
+
const defaults = createDefaultCronBuilderState();
|
|
73
|
+
const baseState = {
|
|
74
|
+
...defaults,
|
|
75
|
+
customExpression: builderExpression,
|
|
76
|
+
};
|
|
77
|
+
const minuteInterval = parseMinuteInterval(minutePart);
|
|
78
|
+
if (minuteInterval && hourPart === '*' && dayOfMonth === '*' && month === '*' && dayOfWeek === '*') {
|
|
79
|
+
return {
|
|
80
|
+
...baseState,
|
|
81
|
+
mode: 'minute',
|
|
82
|
+
minuteInterval,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const minute = parseSegment(minutePart, 0, 59);
|
|
86
|
+
if (minute === undefined)
|
|
87
|
+
return { ...baseState, mode: 'custom', customExpression: normalized };
|
|
88
|
+
if (hourPart === '*' && dayOfMonth === '*' && month === '*' && dayOfWeek === '*') {
|
|
89
|
+
return {
|
|
90
|
+
...baseState,
|
|
91
|
+
mode: 'hour',
|
|
92
|
+
minute,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
const hour = parseSegment(hourPart, 0, 23);
|
|
96
|
+
if (hour === undefined) {
|
|
97
|
+
return {
|
|
98
|
+
...baseState,
|
|
99
|
+
mode: 'custom',
|
|
100
|
+
customExpression: normalized,
|
|
101
|
+
minute,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
if (dayOfMonth === '*' && month === '*' && dayOfWeek === '*') {
|
|
105
|
+
return {
|
|
106
|
+
...baseState,
|
|
107
|
+
mode: 'day',
|
|
108
|
+
hour,
|
|
109
|
+
minute,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (dayOfMonth === '*' && month === '*') {
|
|
113
|
+
const weekDays = expandCronWeekDays(dayOfWeek);
|
|
114
|
+
if (weekDays.length > 0) {
|
|
115
|
+
return {
|
|
116
|
+
...baseState,
|
|
117
|
+
mode: 'week',
|
|
118
|
+
hour,
|
|
119
|
+
minute,
|
|
120
|
+
weekDays,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
const monthDay = parseSegment(dayOfMonth, 1, 31);
|
|
125
|
+
if (month === '*' && dayOfWeek === '*' && monthDay !== undefined) {
|
|
126
|
+
return {
|
|
127
|
+
...baseState,
|
|
128
|
+
mode: 'month',
|
|
129
|
+
hour,
|
|
130
|
+
minute,
|
|
131
|
+
monthDay,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
...baseState,
|
|
136
|
+
mode: 'custom',
|
|
137
|
+
customExpression: normalized,
|
|
138
|
+
hour,
|
|
139
|
+
minute,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 将 builder 状态序列化为标准五段 Cron 表达式。
|
|
144
|
+
*
|
|
145
|
+
* @param state 要序列化的 builder 状态。
|
|
146
|
+
* @returns 标准五段 Cron 表达式;自定义模式返回清理后的原文。
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* import { createDefaultCronBuilderState, cronBuilderStateToExpression } from '@h-ai/ui'
|
|
151
|
+
* const expression = cronBuilderStateToExpression({ ...createDefaultCronBuilderState(), mode: 'day' })
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export function cronBuilderStateToExpression(state) {
|
|
155
|
+
if (state.mode === 'custom') {
|
|
156
|
+
return state.customExpression.trim();
|
|
157
|
+
}
|
|
158
|
+
const minute = clampNumber(state.minute, 0, 59, 0);
|
|
159
|
+
const hour = clampNumber(state.hour, 0, 23, 0);
|
|
160
|
+
switch (state.mode) {
|
|
161
|
+
case 'minute':
|
|
162
|
+
return `*/${clampNumber(state.minuteInterval, 1, 59, 5)} * * * *`;
|
|
163
|
+
case 'hour':
|
|
164
|
+
return `${minute} * * * *`;
|
|
165
|
+
case 'day':
|
|
166
|
+
return `${minute} ${hour} * * *`;
|
|
167
|
+
case 'week':
|
|
168
|
+
return `${minute} ${hour} * * ${serializeWeekDays(state.weekDays)}`;
|
|
169
|
+
case 'month':
|
|
170
|
+
return `${minute} ${hour} ${clampNumber(state.monthDay, 1, 31, 1)} * *`;
|
|
171
|
+
default:
|
|
172
|
+
return '';
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* 使用 cron-parser 校验 Cron 表达式;业务调用方可在此基础上限制字段数量。
|
|
177
|
+
*
|
|
178
|
+
* @param expression 要校验的 Cron 表达式。
|
|
179
|
+
* @returns 表达式可被 cron-parser 解析时为 true。
|
|
180
|
+
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```ts
|
|
183
|
+
* import { isCronExpressionValid } from '@h-ai/ui'
|
|
184
|
+
* const valid = isCronExpressionValid('0 10 * * *')
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
export function isCronExpressionValid(expression) {
|
|
188
|
+
const normalized = expression.trim();
|
|
189
|
+
if (!normalized) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
void CronExpressionParser.parse(normalized);
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function isIntegerSegment(value) {
|
|
201
|
+
return value !== undefined && INTEGER_RE.test(value);
|
|
202
|
+
}
|
|
203
|
+
function parseSegment(value, min, max) {
|
|
204
|
+
if (!isIntegerSegment(value))
|
|
205
|
+
return undefined;
|
|
206
|
+
const number = Number.parseInt(value, 10);
|
|
207
|
+
return number >= min && number <= max
|
|
208
|
+
? number
|
|
209
|
+
: undefined;
|
|
210
|
+
}
|
|
211
|
+
function parseMinuteInterval(value) {
|
|
212
|
+
if (value === undefined) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
const match = MINUTE_INTERVAL_RE.exec(value);
|
|
216
|
+
if (!match) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
const parsed = Number.parseInt(match[1] ?? '', 10);
|
|
220
|
+
if (!Number.isFinite(parsed) || parsed < 1 || parsed > 59) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
return parsed;
|
|
224
|
+
}
|
|
225
|
+
function clampNumber(value, min, max, fallback) {
|
|
226
|
+
if (!Number.isFinite(value)) {
|
|
227
|
+
return fallback;
|
|
228
|
+
}
|
|
229
|
+
return Math.min(max, Math.max(min, Math.trunc(value)));
|
|
230
|
+
}
|
|
231
|
+
function normalizeCronExpressionForBuilder(expression) {
|
|
232
|
+
const segments = expression.split(CRON_WHITESPACE_RE).filter(Boolean);
|
|
233
|
+
if (segments.length === STANDARD_FIVE_SEGMENT_LENGTH) {
|
|
234
|
+
return segments.join(' ');
|
|
235
|
+
}
|
|
236
|
+
if (segments.length === STANDARD_SIX_SEGMENT_LENGTH && segments[0] === '0') {
|
|
237
|
+
return segments.slice(1).join(' ');
|
|
238
|
+
}
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
function expandCronWeekDays(dayOfWeek) {
|
|
242
|
+
const normalized = dayOfWeek?.trim() ?? '';
|
|
243
|
+
if (!normalized || normalized === '*') {
|
|
244
|
+
return [];
|
|
245
|
+
}
|
|
246
|
+
const expanded = new Set();
|
|
247
|
+
for (const part of normalized.split(',')) {
|
|
248
|
+
const token = part.trim();
|
|
249
|
+
if (!token) {
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
if (token.includes('-')) {
|
|
253
|
+
const parts = token.split('-');
|
|
254
|
+
const [startToken, endToken] = parts;
|
|
255
|
+
if (parts.length !== 2 || !isIntegerSegment(startToken) || !isIntegerSegment(endToken)) {
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
const start = Number.parseInt(startToken, 10);
|
|
259
|
+
const end = Number.parseInt(endToken, 10);
|
|
260
|
+
if (!isCronWeekDayInRange(start) || !isCronWeekDayInRange(end) || start > end) {
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
for (let current = start; current <= end; current += 1) {
|
|
264
|
+
expanded.add(normalizeCronWeekDayValue(current));
|
|
265
|
+
}
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
if (!isIntegerSegment(token)) {
|
|
269
|
+
return [];
|
|
270
|
+
}
|
|
271
|
+
const value = Number.parseInt(token, 10);
|
|
272
|
+
if (!isCronWeekDayInRange(value)) {
|
|
273
|
+
return [];
|
|
274
|
+
}
|
|
275
|
+
expanded.add(normalizeCronWeekDayValue(value));
|
|
276
|
+
}
|
|
277
|
+
return CRON_BUILDER_WEEKDAY_ORDER.filter(value => expanded.has(value));
|
|
278
|
+
}
|
|
279
|
+
function serializeWeekDays(weekDays) {
|
|
280
|
+
const normalized = CRON_BUILDER_WEEKDAY_ORDER.filter(value => weekDays.includes(value));
|
|
281
|
+
if (normalized.length === 0) {
|
|
282
|
+
return '1';
|
|
283
|
+
}
|
|
284
|
+
return normalized.join(',');
|
|
285
|
+
}
|
|
286
|
+
function isCronWeekDayInRange(value) {
|
|
287
|
+
return value >= 0 && value <= 7;
|
|
288
|
+
}
|
|
289
|
+
function normalizeCronWeekDayValue(value) {
|
|
290
|
+
return value === 7
|
|
291
|
+
? '0'
|
|
292
|
+
: String(value);
|
|
293
|
+
}
|
|
@@ -17,6 +17,9 @@ export { default as Calendar } from './Calendar.svelte';
|
|
|
17
17
|
export { default as Card } from './Card.svelte';
|
|
18
18
|
export { default as Combobox } from './Combobox.svelte';
|
|
19
19
|
export { default as Confirm } from './Confirm.svelte';
|
|
20
|
+
export type { CronBuilderMode, CronBuilderState, CronExpressionBuilderLabels, CronExpressionBuilderPreset, CronExpressionBuilderWeekdayOption, CronWeekdayValue, } from './cron-expression-builder-types.js';
|
|
21
|
+
export { createDefaultCronBuilderState, CRON_BUILDER_WEEKDAY_ORDER, cronBuilderStateToExpression, cronExpressionToBuilderState, isCronExpressionValid, } from './cron-expression-builder.js';
|
|
22
|
+
export { default as CronExpressionBuilder } from './CronExpressionBuilder.svelte';
|
|
20
23
|
export { default as DataTable } from './DataTable.svelte';
|
|
21
24
|
export { default as DatePicker } from './DatePicker.svelte';
|
|
22
25
|
export { default as Drawer } from './Drawer.svelte';
|
|
@@ -38,6 +41,9 @@ export { default as Popover } from './Popover.svelte';
|
|
|
38
41
|
export { default as PullRefresh } from './PullRefresh.svelte';
|
|
39
42
|
export { default as Result } from './Result.svelte';
|
|
40
43
|
export { default as SafeArea } from './SafeArea.svelte';
|
|
44
|
+
export { normalizeScheduleInputConfig } from './schedule-input-config.js';
|
|
45
|
+
export type { ScheduleInputConfig } from './schedule-input-config.js';
|
|
46
|
+
export { default as ScheduleInput } from './ScheduleInput.svelte';
|
|
41
47
|
export { default as Skeleton } from './Skeleton.svelte';
|
|
42
48
|
export { default as Steps } from './Steps.svelte';
|
|
43
49
|
export type { SwipeCellAction } from './swipe-cell-types.js';
|
|
@@ -20,6 +20,8 @@ export { default as Card } from './Card.svelte';
|
|
|
20
20
|
// 可搜索下拉选择(Bits UI headless + DaisyUI 样式)
|
|
21
21
|
export { default as Combobox } from './Combobox.svelte';
|
|
22
22
|
export { default as Confirm } from './Confirm.svelte';
|
|
23
|
+
export { createDefaultCronBuilderState, CRON_BUILDER_WEEKDAY_ORDER, cronBuilderStateToExpression, cronExpressionToBuilderState, isCronExpressionValid, } from './cron-expression-builder.js';
|
|
24
|
+
export { default as CronExpressionBuilder } from './CronExpressionBuilder.svelte';
|
|
23
25
|
export { default as DataTable } from './DataTable.svelte';
|
|
24
26
|
// 日期选择器(Bits UI headless + DaisyUI 样式)
|
|
25
27
|
export { default as DatePicker } from './DatePicker.svelte';
|
|
@@ -52,6 +54,9 @@ export { default as PullRefresh } from './PullRefresh.svelte';
|
|
|
52
54
|
export { default as Result } from './Result.svelte';
|
|
53
55
|
// 安全区域包裹
|
|
54
56
|
export { default as SafeArea } from './SafeArea.svelte';
|
|
57
|
+
export { normalizeScheduleInputConfig } from './schedule-input-config.js';
|
|
58
|
+
// 日期时间与高级 Cron 调度输入
|
|
59
|
+
export { default as ScheduleInput } from './ScheduleInput.svelte';
|
|
55
60
|
export { default as Skeleton } from './Skeleton.svelte';
|
|
56
61
|
export { default as Steps } from './Steps.svelte';
|
|
57
62
|
export { default as SwipeCell } from './SwipeCell.svelte';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScheduleInput schema metadata 的公开入口。
|
|
3
|
+
*
|
|
4
|
+
* 日期时间草稿和 canonical 值工具只供 ScheduleInput 内部使用;这个模块
|
|
5
|
+
* 保持工作流 schema 消费者所需的最小公开 API。
|
|
6
|
+
*/
|
|
7
|
+
export { normalizeScheduleInputConfig } from './schedule-input.js';
|
|
8
|
+
export type { ScheduleInputConfig } from './schedule-input.js';
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ScheduleInput 的 schema 配置和分钟级日期时间工具。
|
|
3
|
+
* 计算使用配置的 IANA 时区,并保留有效回填值的显式 UTC 偏移。
|
|
4
|
+
*/
|
|
5
|
+
declare const SCHEDULE_INPUT_PRECISION: "minute";
|
|
6
|
+
/**
|
|
7
|
+
* `ScheduleInput` 当前支持的值精度。
|
|
8
|
+
*
|
|
9
|
+
* @example 模块内部上下文
|
|
10
|
+
* ```ts
|
|
11
|
+
* const precision: ScheduleInputPrecision = 'minute'
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
type ScheduleInputPrecision = typeof SCHEDULE_INPUT_PRECISION;
|
|
15
|
+
/**
|
|
16
|
+
* `ScheduleInput` 的 schema 元数据。
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import type { ScheduleInputConfig } from '@h-ai/ui'
|
|
21
|
+
* const config: ScheduleInputConfig = {
|
|
22
|
+
* kind: 'schedule', timezone: 'Asia/Shanghai', precision: 'minute', allowCron: true,
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export interface ScheduleInputConfig {
|
|
27
|
+
/** 输入类型标识。 */
|
|
28
|
+
kind: 'schedule';
|
|
29
|
+
/** IANA 时区,例如 `Asia/Shanghai` 或 `America/Los_Angeles`。 */
|
|
30
|
+
timezone: string;
|
|
31
|
+
/** 输出值精度。 */
|
|
32
|
+
precision: ScheduleInputPrecision;
|
|
33
|
+
/** 是否允许切换到高级 Cron 模式;省略时由规范化结果默认为 false。 */
|
|
34
|
+
allowCron?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* ScheduleInput 的默认 schema 配置。
|
|
38
|
+
*
|
|
39
|
+
* @example 模块内部上下文
|
|
40
|
+
* ```ts
|
|
41
|
+
* const config = { ...DEFAULT_SCHEDULE_INPUT_CONFIG, allowCron: true }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const DEFAULT_SCHEDULE_INPUT_CONFIG: ScheduleInputConfig;
|
|
45
|
+
/**
|
|
46
|
+
* 归一化 schema 元数据;未知值和不支持的配置不会被静默降级。
|
|
47
|
+
*
|
|
48
|
+
* `allowCron` 是唯一可省略的字段,省略时统一归一化为 `false`。
|
|
49
|
+
*
|
|
50
|
+
* @param value 待校验的 schema 元数据。
|
|
51
|
+
* @returns 归一化后的配置;不支持或格式错误时返回 undefined。
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { normalizeScheduleInputConfig } from '@h-ai/ui'
|
|
56
|
+
* const config = normalizeScheduleInputConfig({
|
|
57
|
+
* kind: 'schedule', timezone: 'Asia/Shanghai', precision: 'minute',
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare function normalizeScheduleInputConfig(value: unknown): ScheduleInputConfig | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* ScheduleInput 日期时间编辑草稿。
|
|
64
|
+
*
|
|
65
|
+
* @example 模块内部上下文
|
|
66
|
+
* ```ts
|
|
67
|
+
* const draft: ScheduleDateTimeDraft = { date: '2026-11-22', hour: '10', minute: '05' }
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
export interface ScheduleDateTimeDraft {
|
|
71
|
+
date: string;
|
|
72
|
+
hour: string;
|
|
73
|
+
minute: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* ScheduleInput 日期时间校验状态。
|
|
77
|
+
*
|
|
78
|
+
* @example 模块内部上下文
|
|
79
|
+
* ```ts
|
|
80
|
+
* const status: ScheduleDateTimeStatus = 'valid'
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
export type ScheduleDateTimeStatus = 'empty' | 'partial' | 'invalid' | 'past' | 'valid';
|
|
84
|
+
/**
|
|
85
|
+
* 已解析的 ScheduleInput canonical 日期时间值。
|
|
86
|
+
*
|
|
87
|
+
* @example 模块内部上下文
|
|
88
|
+
* ```ts
|
|
89
|
+
* const parsed: ParsedScheduleDateTimeValue = {
|
|
90
|
+
* date: '2026-11-22', hour: '10', minute: '05', seconds: '00', offset: '+08:00',
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export interface ParsedScheduleDateTimeValue extends ScheduleDateTimeDraft {
|
|
95
|
+
seconds: string;
|
|
96
|
+
offset: string;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* 将公开的 canonical 日期时间值拆成可编辑字段;非 canonical 值也会保留其精度信息。
|
|
100
|
+
*
|
|
101
|
+
* @param value 待解析的日期时间值。
|
|
102
|
+
* @returns 解析后的字段和精度信息;格式不匹配时返回 undefined。
|
|
103
|
+
*
|
|
104
|
+
* @example 模块内部上下文
|
|
105
|
+
* ```ts
|
|
106
|
+
* const parsed = parseScheduleDateTimeValue('2026-11-22T10:05:00+08:00')
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export declare function parseScheduleDateTimeValue(value: unknown): ParsedScheduleDateTimeValue | undefined;
|
|
110
|
+
/**
|
|
111
|
+
* 将分钟级草稿转换为带 UTC 偏移的 ISO 日期时间。
|
|
112
|
+
* 缺失的夏令时分钟会返回 undefined。重叠分钟默认取较早的一次,回填值可指定实际偏移。
|
|
113
|
+
*
|
|
114
|
+
* @param draft 日期时间编辑草稿。
|
|
115
|
+
* @param timezone IANA 时区,默认 `Asia/Shanghai`。
|
|
116
|
+
* @param offset 回填值已有的偏移,传入时核对该偏移与时区、日期和分钟一致。
|
|
117
|
+
* @returns ISO 日期时间;草稿、时区或偏移不合法时返回 undefined。
|
|
118
|
+
*
|
|
119
|
+
* @example 模块内部上下文
|
|
120
|
+
* ```ts
|
|
121
|
+
* const value = serializeScheduleDateTime({ date: '2030-01-22', hour: '10', minute: '05' }, 'America/Los_Angeles')
|
|
122
|
+
* // '2030-01-22T10:05:00-08:00'
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function serializeScheduleDateTime(draft: ScheduleDateTimeDraft, timezone?: string, offset?: string): string | undefined;
|
|
126
|
+
/**
|
|
127
|
+
* 校验 canonical 日期时间值,当前时刻比较使用绝对时间戳而非浏览器本地时区。
|
|
128
|
+
*
|
|
129
|
+
* @param value 待校验的 canonical 值。
|
|
130
|
+
* @param now 用于未来时间比较的当前时间。
|
|
131
|
+
* @param timezone IANA 时区,默认北京时间。
|
|
132
|
+
* @returns 日期时间的结构和未来性状态。
|
|
133
|
+
*
|
|
134
|
+
* @example 模块内部上下文
|
|
135
|
+
* ```ts
|
|
136
|
+
* const status = inspectScheduleDateTimeValue('2026-11-22T10:05:00+08:00')
|
|
137
|
+
* ```
|
|
138
|
+
*/
|
|
139
|
+
export declare function inspectScheduleDateTimeValue(value: unknown, now?: Date, timezone?: string): ScheduleDateTimeStatus;
|
|
140
|
+
/**
|
|
141
|
+
* 校验可编辑草稿;空草稿只在 required 层决定是否报错。
|
|
142
|
+
*
|
|
143
|
+
* @param draft 日期时间编辑草稿。
|
|
144
|
+
* @param now 用于未来时间比较的当前时间。
|
|
145
|
+
* @param timezone IANA 时区,默认北京时间。
|
|
146
|
+
* @param offset 回填的显式偏移。
|
|
147
|
+
* @returns 草稿的结构和未来性状态。
|
|
148
|
+
*
|
|
149
|
+
* @example 模块内部上下文
|
|
150
|
+
* ```ts
|
|
151
|
+
* const status = inspectScheduleDateTimeDraft({ date: '2026-11-22', hour: '10', minute: '05' })
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export declare function inspectScheduleDateTimeDraft(draft: ScheduleDateTimeDraft, now?: Date, timezone?: string, offset?: string): ScheduleDateTimeStatus;
|
|
155
|
+
/**
|
|
156
|
+
* 判断日期时间值是否满足可选/必填字段的有效性。
|
|
157
|
+
*
|
|
158
|
+
* @param value 待校验的 canonical 值。
|
|
159
|
+
* @param required 是否要求非空值。
|
|
160
|
+
* @param now 用于未来时间比较的当前时间。
|
|
161
|
+
* @param timezone IANA 时区,默认北京时间。
|
|
162
|
+
* @returns 值满足字段约束时为 true。
|
|
163
|
+
*
|
|
164
|
+
* @example 模块内部上下文
|
|
165
|
+
* ```ts
|
|
166
|
+
* const valid = isScheduleDateTimeValid('2026-11-22T10:05:00+08:00')
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
export declare function isScheduleDateTimeValid(value: unknown, required?: boolean, now?: Date, timezone?: string): boolean;
|
|
170
|
+
export {};
|