@jswork/react-questkit 1.0.7 → 1.0.9
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/dist/index.cjs +137 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +37 -7
- package/dist/index.d.ts +37 -7
- package/dist/index.mjs +137 -24
- package/dist/index.mjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -218,7 +218,8 @@ var questSfx = {
|
|
|
218
218
|
|
|
219
219
|
// src/core/use-judge.ts
|
|
220
220
|
var import_react = require("react");
|
|
221
|
-
function resolveInitial(demoAttempt) {
|
|
221
|
+
function resolveInitial(demoAttempt, initialPhase) {
|
|
222
|
+
if (initialPhase) return { phase: initialPhase, attempts: 0 };
|
|
222
223
|
if (demoAttempt === 2) return { phase: "locked", attempts: 2 };
|
|
223
224
|
if (demoAttempt === 1) return { phase: "retry", attempts: 1 };
|
|
224
225
|
return { phase: "idle", attempts: 0 };
|
|
@@ -227,7 +228,7 @@ function useJudge(options) {
|
|
|
227
228
|
const latest = (0, import_react.useRef)(options);
|
|
228
229
|
latest.current = options;
|
|
229
230
|
const [state, setState] = (0, import_react.useState)(
|
|
230
|
-
() => resolveInitial(options.demoAttempt)
|
|
231
|
+
() => resolveInitial(options.demoAttempt, options.initialPhase)
|
|
231
232
|
);
|
|
232
233
|
const stateRef = (0, import_react.useRef)(state);
|
|
233
234
|
const commit = (0, import_react.useCallback)((next) => {
|
|
@@ -1574,10 +1575,15 @@ function useSingleChoice({
|
|
|
1574
1575
|
mode,
|
|
1575
1576
|
sound,
|
|
1576
1577
|
demoAttempt,
|
|
1578
|
+
initialSelected,
|
|
1579
|
+
initialCorrect,
|
|
1577
1580
|
onSubmit
|
|
1578
1581
|
}) {
|
|
1579
1582
|
var _a, _b;
|
|
1580
1583
|
const [selected, setSelected] = (0, import_react9.useState)(() => {
|
|
1584
|
+
if (initialSelected != null && initialSelected >= 0 && initialSelected < data.options.length) {
|
|
1585
|
+
return initialSelected;
|
|
1586
|
+
}
|
|
1581
1587
|
if (!demoAttempt) return null;
|
|
1582
1588
|
const wrong = data.options.findIndex((_, index) => index !== data.answer);
|
|
1583
1589
|
return wrong >= 0 ? wrong : null;
|
|
@@ -1588,7 +1594,8 @@ function useSingleChoice({
|
|
|
1588
1594
|
const judge = useJudge({
|
|
1589
1595
|
evaluate: () => selected === data.answer,
|
|
1590
1596
|
sound,
|
|
1591
|
-
demoAttempt
|
|
1597
|
+
demoAttempt,
|
|
1598
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
1592
1599
|
});
|
|
1593
1600
|
const canPick = !readonly && judge.phase === "idle";
|
|
1594
1601
|
const handlePick = (next) => {
|
|
@@ -1669,9 +1676,19 @@ function SingleChoice({
|
|
|
1669
1676
|
onSubmit,
|
|
1670
1677
|
sound,
|
|
1671
1678
|
demoAttempt,
|
|
1679
|
+
initialSelected,
|
|
1680
|
+
initialCorrect,
|
|
1672
1681
|
className
|
|
1673
1682
|
}) {
|
|
1674
|
-
const model = useSingleChoice({
|
|
1683
|
+
const model = useSingleChoice({
|
|
1684
|
+
data,
|
|
1685
|
+
mode,
|
|
1686
|
+
sound,
|
|
1687
|
+
demoAttempt,
|
|
1688
|
+
initialSelected,
|
|
1689
|
+
initialCorrect,
|
|
1690
|
+
onSubmit
|
|
1691
|
+
});
|
|
1675
1692
|
const actions = singleChoiceActions({
|
|
1676
1693
|
readonly: model.readonly,
|
|
1677
1694
|
phase: model.judge.phase,
|
|
@@ -1724,11 +1741,13 @@ function followReadActions({
|
|
|
1724
1741
|
readonly,
|
|
1725
1742
|
stage,
|
|
1726
1743
|
grade,
|
|
1744
|
+
attemptsLeft,
|
|
1727
1745
|
labels,
|
|
1728
1746
|
onNext
|
|
1729
1747
|
}) {
|
|
1730
1748
|
if (readonly) return onNext ? [{ key: "next", label: labels.next, onClick: onNext }] : [];
|
|
1731
|
-
|
|
1749
|
+
const finished = stage === "result" && grade && grade !== "noise" || attemptsLeft === 0;
|
|
1750
|
+
if (finished) {
|
|
1732
1751
|
return [{ key: "next", label: labels.next, onClick: onNext }];
|
|
1733
1752
|
}
|
|
1734
1753
|
return [];
|
|
@@ -2166,7 +2185,7 @@ function detailHint({
|
|
|
2166
2185
|
if (readonly) return mode === "lookup" ? labels.submitted : void 0;
|
|
2167
2186
|
if (noise) return labels.noiseHint;
|
|
2168
2187
|
if (grade === "again") return labels.againHint;
|
|
2169
|
-
if (
|
|
2188
|
+
if (attemptsLeft === 0) {
|
|
2170
2189
|
return `${maxAttempts} \u6B21${labels.attemptsUsedUp} \xB7 \u53D6\u6700\u540E\u4E00\u6B21\u6709\u6548\u5206`;
|
|
2171
2190
|
}
|
|
2172
2191
|
if (stage === "result") return labels.submitted;
|
|
@@ -2457,6 +2476,7 @@ function FollowRead({
|
|
|
2457
2476
|
readonly: model.readonly,
|
|
2458
2477
|
stage: model.stage,
|
|
2459
2478
|
grade: model.grade,
|
|
2479
|
+
attemptsLeft: model.attemptsLeft,
|
|
2460
2480
|
labels: model.labels,
|
|
2461
2481
|
onNext
|
|
2462
2482
|
});
|
|
@@ -2925,6 +2945,8 @@ function useLinkPairs({
|
|
|
2925
2945
|
onSubmit,
|
|
2926
2946
|
sound,
|
|
2927
2947
|
demoAttempt,
|
|
2948
|
+
initialPairs,
|
|
2949
|
+
initialCorrect,
|
|
2928
2950
|
speakNode
|
|
2929
2951
|
}) {
|
|
2930
2952
|
var _a;
|
|
@@ -2935,13 +2957,17 @@ function useLinkPairs({
|
|
|
2935
2957
|
() => new Set(data.pairs.map(([left, right]) => pairKey(left, right))),
|
|
2936
2958
|
[data.pairs]
|
|
2937
2959
|
);
|
|
2938
|
-
const
|
|
2960
|
+
const restoredPairs = (initialPairs != null ? initialPairs : []).filter(
|
|
2961
|
+
(pair) => Array.isArray(pair) && typeof pair[0] === "number" && typeof pair[1] === "number"
|
|
2962
|
+
);
|
|
2963
|
+
const [pairs, setPairs] = (0, import_react17.useState)(restoredPairs);
|
|
2939
2964
|
const [selection, setSelection] = (0, import_react17.useState)(null);
|
|
2940
2965
|
const judge = useJudge({
|
|
2941
2966
|
evaluate: () => pairs.length === totalPairs && (!hasAnswer || pairs.every(([left, right]) => expected.has(pairKey(left, right)))),
|
|
2942
2967
|
onFirstWrong: () => setPairs((current) => current.filter(([left, right]) => expected.has(pairKey(left, right)))),
|
|
2943
2968
|
sound,
|
|
2944
|
-
demoAttempt
|
|
2969
|
+
demoAttempt,
|
|
2970
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
2945
2971
|
});
|
|
2946
2972
|
const frozen = readonly || judge.phase === "correct" || judge.phase === "locked";
|
|
2947
2973
|
const shownPairs = readonly ? data.pairs : pairs;
|
|
@@ -3019,6 +3045,8 @@ function LinkMatch({
|
|
|
3019
3045
|
onSubmit,
|
|
3020
3046
|
sound,
|
|
3021
3047
|
demoAttempt,
|
|
3048
|
+
initialPairs,
|
|
3049
|
+
initialCorrect,
|
|
3022
3050
|
className
|
|
3023
3051
|
}) {
|
|
3024
3052
|
const labels = useQuestLabels();
|
|
@@ -3032,6 +3060,8 @@ function LinkMatch({
|
|
|
3032
3060
|
onSubmit,
|
|
3033
3061
|
sound,
|
|
3034
3062
|
demoAttempt,
|
|
3063
|
+
initialPairs,
|
|
3064
|
+
initialCorrect,
|
|
3035
3065
|
speakNode: audio.speakNode
|
|
3036
3066
|
});
|
|
3037
3067
|
const geometry = useLinkGeometry({
|
|
@@ -3354,7 +3384,9 @@ function useRearrange({
|
|
|
3354
3384
|
mode,
|
|
3355
3385
|
onSubmit,
|
|
3356
3386
|
sound,
|
|
3357
|
-
demoAttempt
|
|
3387
|
+
demoAttempt,
|
|
3388
|
+
initialChars,
|
|
3389
|
+
initialCorrect
|
|
3358
3390
|
}) {
|
|
3359
3391
|
const labels = useQuestLabels();
|
|
3360
3392
|
const readonly = isReadonly(mode);
|
|
@@ -3362,9 +3394,12 @@ function useRearrange({
|
|
|
3362
3394
|
const bank = bankTiles(data, slots);
|
|
3363
3395
|
const words = targetWords(data);
|
|
3364
3396
|
const expected = expectedText(data);
|
|
3397
|
+
const restoredChars = initialChars != null ? initialChars : [];
|
|
3365
3398
|
const [filled, setFilled] = (0, import_react18.useState)(
|
|
3366
3399
|
() => slots.map((slot, slotIndex) => {
|
|
3367
3400
|
if (slot.holder) return null;
|
|
3401
|
+
const restored = restoredChars[slotIndex];
|
|
3402
|
+
if (typeof restored === "string" && restored) return restored;
|
|
3368
3403
|
if (demoAttempt === 2) {
|
|
3369
3404
|
const tile = bank[(slotIndex + 1) % Math.max(1, bank.length)];
|
|
3370
3405
|
return tile ? tile.char : null;
|
|
@@ -3401,7 +3436,8 @@ function useRearrange({
|
|
|
3401
3436
|
);
|
|
3402
3437
|
},
|
|
3403
3438
|
sound,
|
|
3404
|
-
demoAttempt
|
|
3439
|
+
demoAttempt,
|
|
3440
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
3405
3441
|
});
|
|
3406
3442
|
const frozen = readonly || judge.phase === "correct" || judge.phase === "locked";
|
|
3407
3443
|
(0, import_react18.useEffect)(() => {
|
|
@@ -3500,9 +3536,19 @@ function Rearrange({
|
|
|
3500
3536
|
onSubmit,
|
|
3501
3537
|
sound,
|
|
3502
3538
|
demoAttempt,
|
|
3539
|
+
initialChars,
|
|
3540
|
+
initialCorrect,
|
|
3503
3541
|
className
|
|
3504
3542
|
}) {
|
|
3505
|
-
const model = useRearrange({
|
|
3543
|
+
const model = useRearrange({
|
|
3544
|
+
data,
|
|
3545
|
+
mode,
|
|
3546
|
+
onSubmit,
|
|
3547
|
+
sound,
|
|
3548
|
+
demoAttempt,
|
|
3549
|
+
initialChars,
|
|
3550
|
+
initialCorrect
|
|
3551
|
+
});
|
|
3506
3552
|
const actions = rearrangeActions({
|
|
3507
3553
|
readonly: model.readonly,
|
|
3508
3554
|
phase: model.judge.phase,
|
|
@@ -4301,14 +4347,19 @@ function useFillBlank({
|
|
|
4301
4347
|
mode,
|
|
4302
4348
|
onSubmit,
|
|
4303
4349
|
sound,
|
|
4304
|
-
demoAttempt
|
|
4350
|
+
demoAttempt,
|
|
4351
|
+
initialValues,
|
|
4352
|
+
initialCorrect
|
|
4305
4353
|
}) {
|
|
4306
4354
|
const labels = useQuestLabels();
|
|
4307
4355
|
const readonly = isReadonly(mode);
|
|
4356
|
+
const restoredValues = initialValues != null ? initialValues : [];
|
|
4308
4357
|
const [values, setValues] = (0, import_react21.useState)(
|
|
4309
4358
|
() => data.blanks.map((blank, blankIndex) => {
|
|
4310
4359
|
var _a, _b;
|
|
4311
4360
|
if (readonly) return (_a = blank.answers[0]) != null ? _a : "";
|
|
4361
|
+
const restored = restoredValues[blankIndex];
|
|
4362
|
+
if (typeof restored === "string") return restored;
|
|
4312
4363
|
if (demoAttempt === 2) {
|
|
4313
4364
|
return blankIndex === 0 ? (_b = blank.answers[0]) != null ? _b : "" : "wrong";
|
|
4314
4365
|
}
|
|
@@ -4326,7 +4377,8 @@ function useFillBlank({
|
|
|
4326
4377
|
)
|
|
4327
4378
|
),
|
|
4328
4379
|
sound,
|
|
4329
|
-
demoAttempt
|
|
4380
|
+
demoAttempt,
|
|
4381
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
4330
4382
|
});
|
|
4331
4383
|
const graded = judge.phase === "correct" || judge.phase === "locked";
|
|
4332
4384
|
const filled = data.blanks.every((_, blankIndex) => {
|
|
@@ -4381,9 +4433,19 @@ function FillBlank({
|
|
|
4381
4433
|
onSubmit,
|
|
4382
4434
|
sound,
|
|
4383
4435
|
demoAttempt,
|
|
4436
|
+
initialValues,
|
|
4437
|
+
initialCorrect,
|
|
4384
4438
|
className
|
|
4385
4439
|
}) {
|
|
4386
|
-
const model = useFillBlank({
|
|
4440
|
+
const model = useFillBlank({
|
|
4441
|
+
data,
|
|
4442
|
+
mode,
|
|
4443
|
+
onSubmit,
|
|
4444
|
+
sound,
|
|
4445
|
+
demoAttempt,
|
|
4446
|
+
initialValues,
|
|
4447
|
+
initialCorrect
|
|
4448
|
+
});
|
|
4387
4449
|
const actions = fillBlankActions({
|
|
4388
4450
|
readonly: model.readonly,
|
|
4389
4451
|
phase: model.judge.phase,
|
|
@@ -4597,15 +4659,20 @@ function useWordSelect({
|
|
|
4597
4659
|
mode,
|
|
4598
4660
|
onSubmit,
|
|
4599
4661
|
sound,
|
|
4600
|
-
demoAttempt
|
|
4662
|
+
demoAttempt,
|
|
4663
|
+
initialFilled,
|
|
4664
|
+
initialCorrect
|
|
4601
4665
|
}) {
|
|
4602
4666
|
var _a;
|
|
4603
4667
|
const labels = useQuestLabels();
|
|
4604
4668
|
const readonly = isReadonly(mode);
|
|
4605
4669
|
const interaction = (_a = data.interaction) != null ? _a : "sequence";
|
|
4670
|
+
const restoredFilled = initialFilled != null ? initialFilled : [];
|
|
4606
4671
|
const [filled, setFilled] = (0, import_react22.useState)(
|
|
4607
4672
|
() => data.blanks.map((blank, blankIndex) => {
|
|
4608
4673
|
if (readonly) return blank.answer;
|
|
4674
|
+
const restored = restoredFilled[blankIndex];
|
|
4675
|
+
if (typeof restored === "string") return restored;
|
|
4609
4676
|
if (demoAttempt === 2) return blankIndex === 1 ? "banana" : blank.answer;
|
|
4610
4677
|
return null;
|
|
4611
4678
|
})
|
|
@@ -4630,7 +4697,8 @@ function useWordSelect({
|
|
|
4630
4697
|
)
|
|
4631
4698
|
),
|
|
4632
4699
|
sound,
|
|
4633
|
-
demoAttempt
|
|
4700
|
+
demoAttempt,
|
|
4701
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
4634
4702
|
});
|
|
4635
4703
|
const frozen = readonly || judge.phase === "correct" || judge.phase === "locked";
|
|
4636
4704
|
const bank = buildBank(data.bank);
|
|
@@ -4712,9 +4780,19 @@ function WordSelect({
|
|
|
4712
4780
|
onSubmit,
|
|
4713
4781
|
sound,
|
|
4714
4782
|
demoAttempt,
|
|
4783
|
+
initialFilled,
|
|
4784
|
+
initialCorrect,
|
|
4715
4785
|
className
|
|
4716
4786
|
}) {
|
|
4717
|
-
const model = useWordSelect({
|
|
4787
|
+
const model = useWordSelect({
|
|
4788
|
+
data,
|
|
4789
|
+
mode,
|
|
4790
|
+
onSubmit,
|
|
4791
|
+
sound,
|
|
4792
|
+
demoAttempt,
|
|
4793
|
+
initialFilled,
|
|
4794
|
+
initialCorrect
|
|
4795
|
+
});
|
|
4718
4796
|
const actions = wordSelectActions({
|
|
4719
4797
|
readonly: model.readonly,
|
|
4720
4798
|
phase: model.judge.phase,
|
|
@@ -4932,14 +5010,20 @@ function useSortSentences({
|
|
|
4932
5010
|
mode,
|
|
4933
5011
|
onSubmit,
|
|
4934
5012
|
sound,
|
|
4935
|
-
demoAttempt
|
|
5013
|
+
demoAttempt,
|
|
5014
|
+
initialRows,
|
|
5015
|
+
initialCorrect
|
|
4936
5016
|
}) {
|
|
4937
5017
|
const labels = useQuestLabels();
|
|
4938
5018
|
const readonly = isReadonly(mode);
|
|
5019
|
+
const restoredRows = initialRows != null ? initialRows : [];
|
|
4939
5020
|
const [rows, setRows] = (0, import_react23.useState)(
|
|
4940
5021
|
() => data.order.map((sentence, rowIndex) => {
|
|
4941
5022
|
var _a;
|
|
4942
5023
|
if (readonly) return sentence;
|
|
5024
|
+
const restored = restoredRows[rowIndex];
|
|
5025
|
+
if (typeof restored === "string") return restored;
|
|
5026
|
+
if (!demoAttempt) return null;
|
|
4943
5027
|
if (demoAttempt === 2) return rowIndex === 1 ? (_a = data.bank[0]) != null ? _a : sentence : sentence;
|
|
4944
5028
|
return null;
|
|
4945
5029
|
})
|
|
@@ -4951,7 +5035,8 @@ function useSortSentences({
|
|
|
4951
5035
|
(current) => current.map((sentence, rowIndex) => sentence === data.order[rowIndex] ? sentence : null)
|
|
4952
5036
|
),
|
|
4953
5037
|
sound,
|
|
4954
|
-
demoAttempt
|
|
5038
|
+
demoAttempt,
|
|
5039
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
4955
5040
|
});
|
|
4956
5041
|
const frozen = readonly || judge.phase === "correct" || judge.phase === "locked";
|
|
4957
5042
|
(0, import_react23.useEffect)(() => {
|
|
@@ -5022,9 +5107,19 @@ function SortSentences({
|
|
|
5022
5107
|
onSubmit,
|
|
5023
5108
|
sound,
|
|
5024
5109
|
demoAttempt,
|
|
5110
|
+
initialRows,
|
|
5111
|
+
initialCorrect,
|
|
5025
5112
|
className
|
|
5026
5113
|
}) {
|
|
5027
|
-
const model = useSortSentences({
|
|
5114
|
+
const model = useSortSentences({
|
|
5115
|
+
data,
|
|
5116
|
+
mode,
|
|
5117
|
+
onSubmit,
|
|
5118
|
+
sound,
|
|
5119
|
+
demoAttempt,
|
|
5120
|
+
initialRows,
|
|
5121
|
+
initialCorrect
|
|
5122
|
+
});
|
|
5028
5123
|
const actions = sortSentencesActions({
|
|
5029
5124
|
readonly: model.readonly,
|
|
5030
5125
|
phase: model.judge.phase,
|
|
@@ -5717,14 +5812,21 @@ function useReadingComprehension({
|
|
|
5717
5812
|
mode,
|
|
5718
5813
|
onSubmit,
|
|
5719
5814
|
sound,
|
|
5720
|
-
demoAttempt
|
|
5815
|
+
demoAttempt,
|
|
5816
|
+
initialAnswers,
|
|
5817
|
+
initialCorrect
|
|
5721
5818
|
}) {
|
|
5722
5819
|
var _a;
|
|
5723
5820
|
const labels = useQuestLabels();
|
|
5724
5821
|
const readonly = isReadonly(mode);
|
|
5822
|
+
const restoredAnswers = initialAnswers != null ? initialAnswers : [];
|
|
5725
5823
|
const [answers, setAnswers] = (0, import_react26.useState)(
|
|
5726
5824
|
() => data.questions.map((question, questionIndex) => {
|
|
5727
5825
|
if (readonly) return question.answer;
|
|
5826
|
+
const restored = restoredAnswers[questionIndex];
|
|
5827
|
+
if (typeof restored === "number" && restored >= 0 && restored < question.options.length) {
|
|
5828
|
+
return restored;
|
|
5829
|
+
}
|
|
5728
5830
|
if (demoAttempt === 2) {
|
|
5729
5831
|
return questionIndex === 1 ? (question.answer + 1) % question.options.length : question.answer;
|
|
5730
5832
|
}
|
|
@@ -5757,7 +5859,8 @@ function useReadingComprehension({
|
|
|
5757
5859
|
if (wrong.length) setCurrent(wrong[0]);
|
|
5758
5860
|
},
|
|
5759
5861
|
sound,
|
|
5760
|
-
demoAttempt
|
|
5862
|
+
demoAttempt,
|
|
5863
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
5761
5864
|
});
|
|
5762
5865
|
const judged = judge.phase === "correct" || judge.phase === "locked" || readonly;
|
|
5763
5866
|
(0, import_react26.useEffect)(() => {
|
|
@@ -5845,10 +5948,20 @@ function ReadingComprehension({
|
|
|
5845
5948
|
onSubmit,
|
|
5846
5949
|
sound,
|
|
5847
5950
|
demoAttempt,
|
|
5951
|
+
initialAnswers,
|
|
5952
|
+
initialCorrect,
|
|
5848
5953
|
className
|
|
5849
5954
|
}) {
|
|
5850
5955
|
var _a, _b;
|
|
5851
|
-
const model = useReadingComprehension({
|
|
5956
|
+
const model = useReadingComprehension({
|
|
5957
|
+
data,
|
|
5958
|
+
mode,
|
|
5959
|
+
onSubmit,
|
|
5960
|
+
sound,
|
|
5961
|
+
demoAttempt,
|
|
5962
|
+
initialAnswers,
|
|
5963
|
+
initialCorrect
|
|
5964
|
+
});
|
|
5852
5965
|
const collapsible = (_a = data.collapsible) != null ? _a : true;
|
|
5853
5966
|
const fold = usePassageFold({
|
|
5854
5967
|
passage: data.passage,
|
|
@@ -7011,7 +7124,7 @@ function BlankInput2({
|
|
|
7011
7124
|
}
|
|
7012
7125
|
|
|
7013
7126
|
// src/index.tsx
|
|
7014
|
-
var version = "1.0.
|
|
7127
|
+
var version = "1.0.9";
|
|
7015
7128
|
var questkit = {
|
|
7016
7129
|
version,
|
|
7017
7130
|
QuestShell,
|