@nakamura-123/pages 1.4.4 → 1.4.5

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.
@@ -26,40 +26,54 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.ExampleText = exports.ClozeText = exports.RUBY_LINE_EM = exports.ClozeBar = exports.useLessonSearch = exports.ClozeProvider = void 0;
27
27
  const react_1 = __importStar(require("react"));
28
28
  const react_native_1 = require("react-native");
29
+ const react_redux_1 = require("react-redux");
29
30
  const lib_1 = require("@nakamura-123/lib");
30
31
  const common_1 = require("@nakamura-123/common");
32
+ const stores_1 = require("@nakamura-123/stores");
31
33
  const MyTextqqyy_1 = require("../../quiz/common/MyTextqqyy");
32
34
  const RefLink_1 = require("./RefLink");
33
35
  const articleContentFnc_1 = require("../../functions/articleContentFnc");
34
36
  const MathView = require("react-native-math-view").default;
35
37
  const ClozeContext = (0, react_1.createContext)(null);
36
38
  // 開いたかどうかは保存しない(10/24の決定)。LESSONではページごと、名札の無い記事では記事全体で1つ持つ。
37
- // 開いた答えは押しても閉じない(押すのは検索に使う)。隠し直すのはページの上の「全部隠す」で行う
39
+ // 開いた答えは押しても閉じない(押すのは検索に使う)。隠し直すのはページの上の「全部隠す」で行う。
40
+ // 「常に表示」にチェックがあれば、どのページ・記事でも全部開いた形で出す(設定に保存する。2026-11-18、本人)
38
41
  const ClozeProvider = ({ blocks, searchEnabled, children }) => {
39
42
  const groups = (0, react_1.useMemo)(() => (0, articleContentFnc_1.clozeGroups)(blocks), [blocks]);
40
43
  const pageImages = (0, react_1.useMemo)(() => blocks.flatMap((b) => (b.type === "image" ? [b.name] : [])), [blocks]);
41
44
  const [opened, setOpened] = (0, react_1.useState)(new Set());
45
+ const isLocked = (0, react_redux_1.useSelector)((state) => { var _a; return (_a = state.quizCfg.inQuizOption.isClozeOpenLock) !== null && _a !== void 0 ? _a : false; });
42
46
  const value = (0, react_1.useMemo)(() => ({
43
47
  groups,
44
- opened,
48
+ opened: isLocked ? new Set(groups) : opened,
45
49
  open: (group) => setOpened((prev) => prev.has(group) ? prev : new Set(prev).add(group)),
46
50
  setAll: (open) => setOpened(open ? new Set(groups) : new Set()),
47
51
  searchEnabled,
48
52
  pageImages,
49
- }), [groups, opened, searchEnabled, pageImages]);
53
+ isLocked,
54
+ }), [groups, opened, searchEnabled, pageImages, isLocked]);
50
55
  return (<ClozeContext.Provider value={value}>{children}</ClozeContext.Provider>);
51
56
  };
52
57
  exports.ClozeProvider = ClozeProvider;
53
58
  const useLessonSearch = () => { var _a, _b; return (_b = (_a = (0, react_1.useContext)(ClozeContext)) === null || _a === void 0 ? void 0 : _a.searchEnabled) !== null && _b !== void 0 ? _b : false; };
54
59
  exports.useLessonSearch = useLessonSearch;
55
60
  // 穴の数と、全部を開ける・隠すボタン。穴の無いページには出さない。
56
- // 1つでも閉じていれば「全部見る」、1つでも開いていれば「全部隠す」を出す(途中までは両方)
61
+ // 1つでも閉じていれば「全部見る」、1つでも開いていれば「全部隠す」を出す(途中までは両方)。
62
+ // 「常に表示」にチェックがある間は全部開いているので、開ける・隠すボタンは出さない
57
63
  const ClozeBar = () => {
58
64
  const cloze = (0, react_1.useContext)(ClozeContext);
59
65
  const { t } = (0, common_1.useDrillTranslation)();
66
+ const dispatch = (0, react_redux_1.useDispatch)();
60
67
  if (!cloze || cloze.groups.length === 0)
61
68
  return null;
62
69
  const openCount = cloze.groups.filter((g) => cloze.opened.has(g)).length;
70
+ const toggleLock = () => {
71
+ dispatch(stores_1.cfgAction.selectInQuizOption({
72
+ key: "isClozeOpenLock",
73
+ value: !cloze.isLocked,
74
+ }));
75
+ dispatch(stores_1.cfgStorage.saveCfgOption());
76
+ };
63
77
  return (<react_native_1.View style={styles.bar}>
64
78
  <common_1.MyText fsize="xs" weight={700} color="ltBlack">
65
79
  {t("article.clozeCount", {
@@ -68,12 +82,18 @@ const ClozeBar = () => {
68
82
  })}
69
83
  </common_1.MyText>
70
84
  <react_native_1.View style={styles.barButtons}>
71
- {openCount > 0 && (<common_1.PressAnimatedWrap onPress={() => cloze.setAll(false)} style={styles.barButton}>
85
+ <common_1.PressAnimatedWrap onPress={toggleLock} style={styles.lockButton}>
86
+ <common_1.Icon5 name={cloze.isLocked ? "check-square" : "square"} size={14} color={cloze.isLocked ? "red" : "ltBlack"} solid={cloze.isLocked} style={styles.lockIcon}/>
87
+ <common_1.MyText fsize="xs" weight={700} color="text">
88
+ {t("article.keepAnswersShown")}
89
+ </common_1.MyText>
90
+ </common_1.PressAnimatedWrap>
91
+ {!cloze.isLocked && openCount > 0 && (<common_1.PressAnimatedWrap onPress={() => cloze.setAll(false)} style={styles.barButton}>
72
92
  <common_1.MyText fsize="xs" weight={700} color="text">
73
93
  {t("article.hideAllAnswers")}
74
94
  </common_1.MyText>
75
95
  </common_1.PressAnimatedWrap>)}
76
- {openCount < cloze.groups.length && (<common_1.PressAnimatedWrap onPress={() => cloze.setAll(true)} style={styles.barButton}>
96
+ {!cloze.isLocked && openCount < cloze.groups.length && (<common_1.PressAnimatedWrap onPress={() => cloze.setAll(true)} style={styles.barButton}>
77
97
  <common_1.MyText fsize="xs" weight={700} color="text">
78
98
  {t("article.showAllAnswers")}
79
99
  </common_1.MyText>
@@ -285,8 +305,14 @@ const styles = react_native_1.StyleSheet.create({
285
305
  justifyContent: "space-between",
286
306
  marginBottom: 10,
287
307
  },
308
+ // 途中まで開くと「常に表示」と2つのボタンが並ぶ。狭い画面や長い訳では折り返す
288
309
  barButtons: {
289
310
  flexDirection: "row",
311
+ flexWrap: "wrap",
312
+ justifyContent: "flex-end",
313
+ alignItems: "center",
314
+ flexShrink: 1,
315
+ marginLeft: 8,
290
316
  gap: 6,
291
317
  },
292
318
  barButton: {
@@ -297,6 +323,16 @@ const styles = react_native_1.StyleSheet.create({
297
323
  borderColor: lib_1.colors.light,
298
324
  backgroundColor: lib_1.colors.white,
299
325
  },
326
+ // ボタンと違って押しても消えない切り替えなので、枠を付けずにチェックの印と文字だけにする
327
+ lockButton: {
328
+ flexDirection: "row",
329
+ alignItems: "center",
330
+ paddingHorizontal: 4,
331
+ paddingVertical: 4,
332
+ },
333
+ lockIcon: {
334
+ marginRight: 5,
335
+ },
300
336
  hole: {
301
337
  borderRadius: 4,
302
338
  backgroundColor: lib_1.colors.beige,