@jswork/react-questkit 1.0.8 → 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 +132 -22
- 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 +132 -22
- 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,
|
|
@@ -2928,6 +2945,8 @@ function useLinkPairs({
|
|
|
2928
2945
|
onSubmit,
|
|
2929
2946
|
sound,
|
|
2930
2947
|
demoAttempt,
|
|
2948
|
+
initialPairs,
|
|
2949
|
+
initialCorrect,
|
|
2931
2950
|
speakNode
|
|
2932
2951
|
}) {
|
|
2933
2952
|
var _a;
|
|
@@ -2938,13 +2957,17 @@ function useLinkPairs({
|
|
|
2938
2957
|
() => new Set(data.pairs.map(([left, right]) => pairKey(left, right))),
|
|
2939
2958
|
[data.pairs]
|
|
2940
2959
|
);
|
|
2941
|
-
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);
|
|
2942
2964
|
const [selection, setSelection] = (0, import_react17.useState)(null);
|
|
2943
2965
|
const judge = useJudge({
|
|
2944
2966
|
evaluate: () => pairs.length === totalPairs && (!hasAnswer || pairs.every(([left, right]) => expected.has(pairKey(left, right)))),
|
|
2945
2967
|
onFirstWrong: () => setPairs((current) => current.filter(([left, right]) => expected.has(pairKey(left, right)))),
|
|
2946
2968
|
sound,
|
|
2947
|
-
demoAttempt
|
|
2969
|
+
demoAttempt,
|
|
2970
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
2948
2971
|
});
|
|
2949
2972
|
const frozen = readonly || judge.phase === "correct" || judge.phase === "locked";
|
|
2950
2973
|
const shownPairs = readonly ? data.pairs : pairs;
|
|
@@ -3022,6 +3045,8 @@ function LinkMatch({
|
|
|
3022
3045
|
onSubmit,
|
|
3023
3046
|
sound,
|
|
3024
3047
|
demoAttempt,
|
|
3048
|
+
initialPairs,
|
|
3049
|
+
initialCorrect,
|
|
3025
3050
|
className
|
|
3026
3051
|
}) {
|
|
3027
3052
|
const labels = useQuestLabels();
|
|
@@ -3035,6 +3060,8 @@ function LinkMatch({
|
|
|
3035
3060
|
onSubmit,
|
|
3036
3061
|
sound,
|
|
3037
3062
|
demoAttempt,
|
|
3063
|
+
initialPairs,
|
|
3064
|
+
initialCorrect,
|
|
3038
3065
|
speakNode: audio.speakNode
|
|
3039
3066
|
});
|
|
3040
3067
|
const geometry = useLinkGeometry({
|
|
@@ -3357,7 +3384,9 @@ function useRearrange({
|
|
|
3357
3384
|
mode,
|
|
3358
3385
|
onSubmit,
|
|
3359
3386
|
sound,
|
|
3360
|
-
demoAttempt
|
|
3387
|
+
demoAttempt,
|
|
3388
|
+
initialChars,
|
|
3389
|
+
initialCorrect
|
|
3361
3390
|
}) {
|
|
3362
3391
|
const labels = useQuestLabels();
|
|
3363
3392
|
const readonly = isReadonly(mode);
|
|
@@ -3365,9 +3394,12 @@ function useRearrange({
|
|
|
3365
3394
|
const bank = bankTiles(data, slots);
|
|
3366
3395
|
const words = targetWords(data);
|
|
3367
3396
|
const expected = expectedText(data);
|
|
3397
|
+
const restoredChars = initialChars != null ? initialChars : [];
|
|
3368
3398
|
const [filled, setFilled] = (0, import_react18.useState)(
|
|
3369
3399
|
() => slots.map((slot, slotIndex) => {
|
|
3370
3400
|
if (slot.holder) return null;
|
|
3401
|
+
const restored = restoredChars[slotIndex];
|
|
3402
|
+
if (typeof restored === "string" && restored) return restored;
|
|
3371
3403
|
if (demoAttempt === 2) {
|
|
3372
3404
|
const tile = bank[(slotIndex + 1) % Math.max(1, bank.length)];
|
|
3373
3405
|
return tile ? tile.char : null;
|
|
@@ -3404,7 +3436,8 @@ function useRearrange({
|
|
|
3404
3436
|
);
|
|
3405
3437
|
},
|
|
3406
3438
|
sound,
|
|
3407
|
-
demoAttempt
|
|
3439
|
+
demoAttempt,
|
|
3440
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
3408
3441
|
});
|
|
3409
3442
|
const frozen = readonly || judge.phase === "correct" || judge.phase === "locked";
|
|
3410
3443
|
(0, import_react18.useEffect)(() => {
|
|
@@ -3503,9 +3536,19 @@ function Rearrange({
|
|
|
3503
3536
|
onSubmit,
|
|
3504
3537
|
sound,
|
|
3505
3538
|
demoAttempt,
|
|
3539
|
+
initialChars,
|
|
3540
|
+
initialCorrect,
|
|
3506
3541
|
className
|
|
3507
3542
|
}) {
|
|
3508
|
-
const model = useRearrange({
|
|
3543
|
+
const model = useRearrange({
|
|
3544
|
+
data,
|
|
3545
|
+
mode,
|
|
3546
|
+
onSubmit,
|
|
3547
|
+
sound,
|
|
3548
|
+
demoAttempt,
|
|
3549
|
+
initialChars,
|
|
3550
|
+
initialCorrect
|
|
3551
|
+
});
|
|
3509
3552
|
const actions = rearrangeActions({
|
|
3510
3553
|
readonly: model.readonly,
|
|
3511
3554
|
phase: model.judge.phase,
|
|
@@ -4304,14 +4347,19 @@ function useFillBlank({
|
|
|
4304
4347
|
mode,
|
|
4305
4348
|
onSubmit,
|
|
4306
4349
|
sound,
|
|
4307
|
-
demoAttempt
|
|
4350
|
+
demoAttempt,
|
|
4351
|
+
initialValues,
|
|
4352
|
+
initialCorrect
|
|
4308
4353
|
}) {
|
|
4309
4354
|
const labels = useQuestLabels();
|
|
4310
4355
|
const readonly = isReadonly(mode);
|
|
4356
|
+
const restoredValues = initialValues != null ? initialValues : [];
|
|
4311
4357
|
const [values, setValues] = (0, import_react21.useState)(
|
|
4312
4358
|
() => data.blanks.map((blank, blankIndex) => {
|
|
4313
4359
|
var _a, _b;
|
|
4314
4360
|
if (readonly) return (_a = blank.answers[0]) != null ? _a : "";
|
|
4361
|
+
const restored = restoredValues[blankIndex];
|
|
4362
|
+
if (typeof restored === "string") return restored;
|
|
4315
4363
|
if (demoAttempt === 2) {
|
|
4316
4364
|
return blankIndex === 0 ? (_b = blank.answers[0]) != null ? _b : "" : "wrong";
|
|
4317
4365
|
}
|
|
@@ -4329,7 +4377,8 @@ function useFillBlank({
|
|
|
4329
4377
|
)
|
|
4330
4378
|
),
|
|
4331
4379
|
sound,
|
|
4332
|
-
demoAttempt
|
|
4380
|
+
demoAttempt,
|
|
4381
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
4333
4382
|
});
|
|
4334
4383
|
const graded = judge.phase === "correct" || judge.phase === "locked";
|
|
4335
4384
|
const filled = data.blanks.every((_, blankIndex) => {
|
|
@@ -4384,9 +4433,19 @@ function FillBlank({
|
|
|
4384
4433
|
onSubmit,
|
|
4385
4434
|
sound,
|
|
4386
4435
|
demoAttempt,
|
|
4436
|
+
initialValues,
|
|
4437
|
+
initialCorrect,
|
|
4387
4438
|
className
|
|
4388
4439
|
}) {
|
|
4389
|
-
const model = useFillBlank({
|
|
4440
|
+
const model = useFillBlank({
|
|
4441
|
+
data,
|
|
4442
|
+
mode,
|
|
4443
|
+
onSubmit,
|
|
4444
|
+
sound,
|
|
4445
|
+
demoAttempt,
|
|
4446
|
+
initialValues,
|
|
4447
|
+
initialCorrect
|
|
4448
|
+
});
|
|
4390
4449
|
const actions = fillBlankActions({
|
|
4391
4450
|
readonly: model.readonly,
|
|
4392
4451
|
phase: model.judge.phase,
|
|
@@ -4600,15 +4659,20 @@ function useWordSelect({
|
|
|
4600
4659
|
mode,
|
|
4601
4660
|
onSubmit,
|
|
4602
4661
|
sound,
|
|
4603
|
-
demoAttempt
|
|
4662
|
+
demoAttempt,
|
|
4663
|
+
initialFilled,
|
|
4664
|
+
initialCorrect
|
|
4604
4665
|
}) {
|
|
4605
4666
|
var _a;
|
|
4606
4667
|
const labels = useQuestLabels();
|
|
4607
4668
|
const readonly = isReadonly(mode);
|
|
4608
4669
|
const interaction = (_a = data.interaction) != null ? _a : "sequence";
|
|
4670
|
+
const restoredFilled = initialFilled != null ? initialFilled : [];
|
|
4609
4671
|
const [filled, setFilled] = (0, import_react22.useState)(
|
|
4610
4672
|
() => data.blanks.map((blank, blankIndex) => {
|
|
4611
4673
|
if (readonly) return blank.answer;
|
|
4674
|
+
const restored = restoredFilled[blankIndex];
|
|
4675
|
+
if (typeof restored === "string") return restored;
|
|
4612
4676
|
if (demoAttempt === 2) return blankIndex === 1 ? "banana" : blank.answer;
|
|
4613
4677
|
return null;
|
|
4614
4678
|
})
|
|
@@ -4633,7 +4697,8 @@ function useWordSelect({
|
|
|
4633
4697
|
)
|
|
4634
4698
|
),
|
|
4635
4699
|
sound,
|
|
4636
|
-
demoAttempt
|
|
4700
|
+
demoAttempt,
|
|
4701
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
4637
4702
|
});
|
|
4638
4703
|
const frozen = readonly || judge.phase === "correct" || judge.phase === "locked";
|
|
4639
4704
|
const bank = buildBank(data.bank);
|
|
@@ -4715,9 +4780,19 @@ function WordSelect({
|
|
|
4715
4780
|
onSubmit,
|
|
4716
4781
|
sound,
|
|
4717
4782
|
demoAttempt,
|
|
4783
|
+
initialFilled,
|
|
4784
|
+
initialCorrect,
|
|
4718
4785
|
className
|
|
4719
4786
|
}) {
|
|
4720
|
-
const model = useWordSelect({
|
|
4787
|
+
const model = useWordSelect({
|
|
4788
|
+
data,
|
|
4789
|
+
mode,
|
|
4790
|
+
onSubmit,
|
|
4791
|
+
sound,
|
|
4792
|
+
demoAttempt,
|
|
4793
|
+
initialFilled,
|
|
4794
|
+
initialCorrect
|
|
4795
|
+
});
|
|
4721
4796
|
const actions = wordSelectActions({
|
|
4722
4797
|
readonly: model.readonly,
|
|
4723
4798
|
phase: model.judge.phase,
|
|
@@ -4935,14 +5010,20 @@ function useSortSentences({
|
|
|
4935
5010
|
mode,
|
|
4936
5011
|
onSubmit,
|
|
4937
5012
|
sound,
|
|
4938
|
-
demoAttempt
|
|
5013
|
+
demoAttempt,
|
|
5014
|
+
initialRows,
|
|
5015
|
+
initialCorrect
|
|
4939
5016
|
}) {
|
|
4940
5017
|
const labels = useQuestLabels();
|
|
4941
5018
|
const readonly = isReadonly(mode);
|
|
5019
|
+
const restoredRows = initialRows != null ? initialRows : [];
|
|
4942
5020
|
const [rows, setRows] = (0, import_react23.useState)(
|
|
4943
5021
|
() => data.order.map((sentence, rowIndex) => {
|
|
4944
5022
|
var _a;
|
|
4945
5023
|
if (readonly) return sentence;
|
|
5024
|
+
const restored = restoredRows[rowIndex];
|
|
5025
|
+
if (typeof restored === "string") return restored;
|
|
5026
|
+
if (!demoAttempt) return null;
|
|
4946
5027
|
if (demoAttempt === 2) return rowIndex === 1 ? (_a = data.bank[0]) != null ? _a : sentence : sentence;
|
|
4947
5028
|
return null;
|
|
4948
5029
|
})
|
|
@@ -4954,7 +5035,8 @@ function useSortSentences({
|
|
|
4954
5035
|
(current) => current.map((sentence, rowIndex) => sentence === data.order[rowIndex] ? sentence : null)
|
|
4955
5036
|
),
|
|
4956
5037
|
sound,
|
|
4957
|
-
demoAttempt
|
|
5038
|
+
demoAttempt,
|
|
5039
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
4958
5040
|
});
|
|
4959
5041
|
const frozen = readonly || judge.phase === "correct" || judge.phase === "locked";
|
|
4960
5042
|
(0, import_react23.useEffect)(() => {
|
|
@@ -5025,9 +5107,19 @@ function SortSentences({
|
|
|
5025
5107
|
onSubmit,
|
|
5026
5108
|
sound,
|
|
5027
5109
|
demoAttempt,
|
|
5110
|
+
initialRows,
|
|
5111
|
+
initialCorrect,
|
|
5028
5112
|
className
|
|
5029
5113
|
}) {
|
|
5030
|
-
const model = useSortSentences({
|
|
5114
|
+
const model = useSortSentences({
|
|
5115
|
+
data,
|
|
5116
|
+
mode,
|
|
5117
|
+
onSubmit,
|
|
5118
|
+
sound,
|
|
5119
|
+
demoAttempt,
|
|
5120
|
+
initialRows,
|
|
5121
|
+
initialCorrect
|
|
5122
|
+
});
|
|
5031
5123
|
const actions = sortSentencesActions({
|
|
5032
5124
|
readonly: model.readonly,
|
|
5033
5125
|
phase: model.judge.phase,
|
|
@@ -5720,14 +5812,21 @@ function useReadingComprehension({
|
|
|
5720
5812
|
mode,
|
|
5721
5813
|
onSubmit,
|
|
5722
5814
|
sound,
|
|
5723
|
-
demoAttempt
|
|
5815
|
+
demoAttempt,
|
|
5816
|
+
initialAnswers,
|
|
5817
|
+
initialCorrect
|
|
5724
5818
|
}) {
|
|
5725
5819
|
var _a;
|
|
5726
5820
|
const labels = useQuestLabels();
|
|
5727
5821
|
const readonly = isReadonly(mode);
|
|
5822
|
+
const restoredAnswers = initialAnswers != null ? initialAnswers : [];
|
|
5728
5823
|
const [answers, setAnswers] = (0, import_react26.useState)(
|
|
5729
5824
|
() => data.questions.map((question, questionIndex) => {
|
|
5730
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
|
+
}
|
|
5731
5830
|
if (demoAttempt === 2) {
|
|
5732
5831
|
return questionIndex === 1 ? (question.answer + 1) % question.options.length : question.answer;
|
|
5733
5832
|
}
|
|
@@ -5760,7 +5859,8 @@ function useReadingComprehension({
|
|
|
5760
5859
|
if (wrong.length) setCurrent(wrong[0]);
|
|
5761
5860
|
},
|
|
5762
5861
|
sound,
|
|
5763
|
-
demoAttempt
|
|
5862
|
+
demoAttempt,
|
|
5863
|
+
initialPhase: initialCorrect === true ? "correct" : void 0
|
|
5764
5864
|
});
|
|
5765
5865
|
const judged = judge.phase === "correct" || judge.phase === "locked" || readonly;
|
|
5766
5866
|
(0, import_react26.useEffect)(() => {
|
|
@@ -5848,10 +5948,20 @@ function ReadingComprehension({
|
|
|
5848
5948
|
onSubmit,
|
|
5849
5949
|
sound,
|
|
5850
5950
|
demoAttempt,
|
|
5951
|
+
initialAnswers,
|
|
5952
|
+
initialCorrect,
|
|
5851
5953
|
className
|
|
5852
5954
|
}) {
|
|
5853
5955
|
var _a, _b;
|
|
5854
|
-
const model = useReadingComprehension({
|
|
5956
|
+
const model = useReadingComprehension({
|
|
5957
|
+
data,
|
|
5958
|
+
mode,
|
|
5959
|
+
onSubmit,
|
|
5960
|
+
sound,
|
|
5961
|
+
demoAttempt,
|
|
5962
|
+
initialAnswers,
|
|
5963
|
+
initialCorrect
|
|
5964
|
+
});
|
|
5855
5965
|
const collapsible = (_a = data.collapsible) != null ? _a : true;
|
|
5856
5966
|
const fold = usePassageFold({
|
|
5857
5967
|
passage: data.passage,
|
|
@@ -7014,7 +7124,7 @@ function BlankInput2({
|
|
|
7014
7124
|
}
|
|
7015
7125
|
|
|
7016
7126
|
// src/index.tsx
|
|
7017
|
-
var version = "1.0.
|
|
7127
|
+
var version = "1.0.9";
|
|
7018
7128
|
var questkit = {
|
|
7019
7129
|
version,
|
|
7020
7130
|
QuestShell,
|