one-design-next 0.0.49 → 0.0.50
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.
|
@@ -18,6 +18,7 @@ import * as React from 'react';
|
|
|
18
18
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
19
19
|
import Button from "../button";
|
|
20
20
|
import DatePicker from "../date-picker";
|
|
21
|
+
import DateRangePicker from "../date-range-picker";
|
|
21
22
|
import HoverFill from "../hover-fill";
|
|
22
23
|
import Icon from "../icon";
|
|
23
24
|
import Input from "../input";
|
|
@@ -176,11 +177,15 @@ export function ClarifyDockPanel(_ref2) {
|
|
|
176
177
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
177
178
|
dateDraft = _useState12[0],
|
|
178
179
|
setDateDraft = _useState12[1];
|
|
180
|
+
var _useState13 = useState(null),
|
|
181
|
+
_useState14 = _slicedToArray(_useState13, 2),
|
|
182
|
+
dateRangeDraft = _useState14[0],
|
|
183
|
+
setDateRangeDraft = _useState14[1];
|
|
179
184
|
var question = spec.questions[page];
|
|
180
185
|
var answer = answers[page];
|
|
181
186
|
var input = question.input;
|
|
182
187
|
|
|
183
|
-
/* 切页:回显 other / date 草稿 */
|
|
188
|
+
/* 切页:回显 other / date / date-range 草稿 */
|
|
184
189
|
useEffect(function () {
|
|
185
190
|
if ((answer === null || answer === void 0 ? void 0 : answer.kind) === 'options' || (answer === null || answer === void 0 ? void 0 : answer.kind) === 'options-multi') {
|
|
186
191
|
var _answer$otherText;
|
|
@@ -193,6 +198,11 @@ export function ClarifyDockPanel(_ref2) {
|
|
|
193
198
|
} else {
|
|
194
199
|
setDateDraft(null);
|
|
195
200
|
}
|
|
201
|
+
if ((answer === null || answer === void 0 ? void 0 : answer.kind) === 'date-range') {
|
|
202
|
+
setDateRangeDraft(answer.start && answer.end ? [new Date("".concat(answer.start, "T00:00:00")), new Date("".concat(answer.end, "T00:00:00"))] : null);
|
|
203
|
+
} else {
|
|
204
|
+
setDateRangeDraft(null);
|
|
205
|
+
}
|
|
196
206
|
}, [page, answer]);
|
|
197
207
|
var setAnswerForPage = function setAnswerForPage(next) {
|
|
198
208
|
setAnswers(function (prev) {
|
|
@@ -217,8 +227,9 @@ export function ClarifyDockPanel(_ref2) {
|
|
|
217
227
|
return hasRegular || hasOther;
|
|
218
228
|
}
|
|
219
229
|
case 'date':
|
|
220
|
-
case 'text':
|
|
221
230
|
return answer.value.trim().length > 0;
|
|
231
|
+
case 'date-range':
|
|
232
|
+
return answer.start.trim().length > 0 && answer.end.trim().length > 0;
|
|
222
233
|
default:
|
|
223
234
|
return false;
|
|
224
235
|
}
|
|
@@ -258,8 +269,9 @@ export function ClarifyDockPanel(_ref2) {
|
|
|
258
269
|
return labels.join('、');
|
|
259
270
|
}
|
|
260
271
|
case 'date':
|
|
261
|
-
case 'text':
|
|
262
272
|
return ans.value;
|
|
273
|
+
case 'date-range':
|
|
274
|
+
return "".concat(ans.start, " \u81F3 ").concat(ans.end);
|
|
263
275
|
default:
|
|
264
276
|
return '(未答)';
|
|
265
277
|
}
|
|
@@ -283,6 +295,13 @@ export function ClarifyDockPanel(_ref2) {
|
|
|
283
295
|
value: toISODate(dateDraft)
|
|
284
296
|
};
|
|
285
297
|
}
|
|
298
|
+
if (a.kind === 'date-range' && dateRangeDraft) {
|
|
299
|
+
return {
|
|
300
|
+
kind: 'date-range',
|
|
301
|
+
start: toISODate(dateRangeDraft[0]),
|
|
302
|
+
end: toISODate(dateRangeDraft[1])
|
|
303
|
+
};
|
|
304
|
+
}
|
|
286
305
|
return a;
|
|
287
306
|
});
|
|
288
307
|
};
|
|
@@ -310,9 +329,11 @@ export function ClarifyDockPanel(_ref2) {
|
|
|
310
329
|
break;
|
|
311
330
|
}
|
|
312
331
|
case 'date':
|
|
313
|
-
case 'text':
|
|
314
332
|
data[q.key] = a.value;
|
|
315
333
|
break;
|
|
334
|
+
case 'date-range':
|
|
335
|
+
data[q.key] = "".concat(a.start, "~").concat(a.end);
|
|
336
|
+
break;
|
|
316
337
|
}
|
|
317
338
|
});
|
|
318
339
|
var items = spec.questions.map(function (q, i) {
|
|
@@ -374,6 +395,7 @@ export function ClarifyDockPanel(_ref2) {
|
|
|
374
395
|
answer: answer,
|
|
375
396
|
otherDraft: otherDraft,
|
|
376
397
|
dateDraft: dateDraft,
|
|
398
|
+
dateRangeDraft: dateRangeDraft,
|
|
377
399
|
onOtherDraftChange: function onOtherDraftChange(v) {
|
|
378
400
|
setOtherDraft(v);
|
|
379
401
|
if ((answer === null || answer === void 0 ? void 0 : answer.kind) === 'options' && answer.value === OTHER_VALUE) {
|
|
@@ -397,6 +419,14 @@ export function ClarifyDockPanel(_ref2) {
|
|
|
397
419
|
value: toISODate(d)
|
|
398
420
|
} : undefined);
|
|
399
421
|
},
|
|
422
|
+
onDateRangeChange: function onDateRangeChange(range) {
|
|
423
|
+
setDateRangeDraft(range);
|
|
424
|
+
setAnswerForPage(range ? {
|
|
425
|
+
kind: 'date-range',
|
|
426
|
+
start: toISODate(range[0]),
|
|
427
|
+
end: toISODate(range[1])
|
|
428
|
+
} : undefined);
|
|
429
|
+
},
|
|
400
430
|
onPickSingle: function onPickSingle(opt) {
|
|
401
431
|
if (opt.value === OTHER_VALUE) {
|
|
402
432
|
setAnswerForPage({
|
|
@@ -469,13 +499,21 @@ function withOtherOption(options, allowOther) {
|
|
|
469
499
|
}
|
|
470
500
|
return options.slice(0, CLARIFY_DOCK_MAX_OPTIONS);
|
|
471
501
|
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* 按 input.kind 适配录入组件:
|
|
505
|
+
* options / options-multi → 选项列表;date → DatePicker;
|
|
506
|
+
* date-range → DateRangePicker。自由文本走自然语言 + Composer,不在此渲染。
|
|
507
|
+
*/
|
|
472
508
|
function QuestionInput(_ref3) {
|
|
473
509
|
var input = _ref3.input,
|
|
474
510
|
answer = _ref3.answer,
|
|
475
511
|
otherDraft = _ref3.otherDraft,
|
|
476
512
|
dateDraft = _ref3.dateDraft,
|
|
513
|
+
dateRangeDraft = _ref3.dateRangeDraft,
|
|
477
514
|
onOtherDraftChange = _ref3.onOtherDraftChange,
|
|
478
515
|
onDateChange = _ref3.onDateChange,
|
|
516
|
+
onDateRangeChange = _ref3.onDateRangeChange,
|
|
479
517
|
onPickSingle = _ref3.onPickSingle,
|
|
480
518
|
onToggleMulti = _ref3.onToggleMulti;
|
|
481
519
|
if (input.kind === 'options' || input.kind === 'options-multi') {
|
|
@@ -500,6 +538,16 @@ function QuestionInput(_ref3) {
|
|
|
500
538
|
}
|
|
501
539
|
}));
|
|
502
540
|
}
|
|
541
|
+
if (input.kind === 'date-range') {
|
|
542
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
543
|
+
"data-odn-clarify-dock-input-row": true
|
|
544
|
+
}, /*#__PURE__*/React.createElement(DateRangePicker, {
|
|
545
|
+
value: dateRangeDraft,
|
|
546
|
+
onChange: function onChange(range) {
|
|
547
|
+
return onDateRangeChange(range);
|
|
548
|
+
}
|
|
549
|
+
}));
|
|
550
|
+
}
|
|
503
551
|
return /*#__PURE__*/React.createElement("div", {
|
|
504
552
|
"data-odn-clarify-dock-hint": true
|
|
505
553
|
}, "\u6682\u4E0D\u652F\u6301\u7684\u8F93\u5165\u7C7B\u578B\uFF1A", input.kind);
|
|
@@ -706,10 +754,10 @@ function OptionsList(_ref4) {
|
|
|
706
754
|
* - recordAnswer 后 Panel 消失,Trigger 切 Approval 式锁态卡
|
|
707
755
|
*/
|
|
708
756
|
export function useClarifyDockState(messages, sessionKey, resetVer) {
|
|
709
|
-
var
|
|
710
|
-
|
|
711
|
-
answers =
|
|
712
|
-
setAnswers =
|
|
757
|
+
var _useState15 = useState({}),
|
|
758
|
+
_useState16 = _slicedToArray(_useState15, 2),
|
|
759
|
+
answers = _useState16[0],
|
|
760
|
+
setAnswers = _useState16[1];
|
|
713
761
|
|
|
714
762
|
/* 切换会话或点「重置」时清空已答标记,避免 Panel / Trigger 状态脱节 */
|
|
715
763
|
useEffect(function () {
|