@pie-element/ebsr 10.7.3-next.9 → 12.0.1-esmbeta.0
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/CHANGELOG.md +44 -0
- package/configure/CHANGELOG.md +16 -0
- package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.json +1972 -0
- package/configure/node_modules/@pie-element/multiple-choice/CHANGELOG.md +4186 -0
- package/configure/node_modules/@pie-element/multiple-choice/LICENSE.md +5 -0
- package/configure/node_modules/@pie-element/multiple-choice/PRINT.md +35 -0
- package/configure/node_modules/@pie-element/multiple-choice/README.md +56 -0
- package/configure/node_modules/@pie-element/multiple-choice/choice.png +0 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.json +1387 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/CHANGELOG.md +3332 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js +202 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/defaults.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js +248 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js +597 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/lib/utils.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/configure/package.json +20 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.json +527 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/CHANGELOG.md +2297 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js +34 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/defaults.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js +346 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js +28 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/lib/utils.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/controller/package.json +15 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json +2993 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/config-schema.json.md +2217 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/config.js +8 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/generate.js +61 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/index.html +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/demo/session.js +7 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json +1332 -0
- package/configure/node_modules/@pie-element/multiple-choice/docs/pie-schema.json.md +1015 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/configure.css +847 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/configure.js +1218 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/configure.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/controller.css +847 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/controller.js +324 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/controller.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/element.css +847 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/element.js +3287 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/element.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/print.css +847 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/print.js +3017 -0
- package/configure/node_modules/@pie-element/multiple-choice/esm/print.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js +427 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice-input.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js +252 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/choice.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js +174 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/feedback-tick.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/index.js +388 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/main.js +108 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/main.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js +469 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/multiple-choice.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/print.js +129 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/print.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js +48 -0
- package/configure/node_modules/@pie-element/multiple-choice/lib/session-updater.js.map +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/configure.js +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/controller.js +3472 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/demo.js +86 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/element.js +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/index.html +21 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/index.js +2 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/manifest.json +10 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/print-demo.js +124 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/print.html +18 -0
- package/configure/node_modules/@pie-element/multiple-choice/module/print.js +1 -0
- package/configure/node_modules/@pie-element/multiple-choice/package.json +53 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/CHANGELOG.md +898 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/NEXT.CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/esm/index.js +262 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/esm/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/lib/expander.js +88 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/lib/expander.js.map +1 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/lib/index.js +181 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/lib/styles.js +66 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/lib/styles.js.map +1 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/package.json +44 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/src/__tests__/index.test.jsx +99 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/src/expander.jsx +61 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/src/index.jsx +98 -0
- package/configure/node_modules/@pie-lib/correct-answer-toggle/src/styles.js +61 -0
- package/configure/node_modules/@pie-lib/icons/CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/icons/CHANGELOG.md +539 -0
- package/configure/node_modules/@pie-lib/icons/NEXT.CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/icons/esm/index.js +1153 -0
- package/configure/node_modules/@pie-lib/icons/esm/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/correct-icon.js +89 -0
- package/configure/node_modules/@pie-lib/icons/lib/correct-icon.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/correct-response-icon.js +153 -0
- package/configure/node_modules/@pie-lib/icons/lib/correct-response-icon.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/icon-base.js +206 -0
- package/configure/node_modules/@pie-lib/icons/lib/icon-base.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/icon-root.js +130 -0
- package/configure/node_modules/@pie-lib/icons/lib/icon-root.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/incorrect-icon.js +92 -0
- package/configure/node_modules/@pie-lib/icons/lib/incorrect-icon.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/index.js +72 -0
- package/configure/node_modules/@pie-lib/icons/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/instructions-icon.js +229 -0
- package/configure/node_modules/@pie-lib/icons/lib/instructions-icon.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/learn-more-icon.js +145 -0
- package/configure/node_modules/@pie-lib/icons/lib/learn-more-icon.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/nothing-submitted-icon.js +183 -0
- package/configure/node_modules/@pie-lib/icons/lib/nothing-submitted-icon.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/partially-correct-icon.js +82 -0
- package/configure/node_modules/@pie-lib/icons/lib/partially-correct-icon.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/show-rationale-icon.js +206 -0
- package/configure/node_modules/@pie-lib/icons/lib/show-rationale-icon.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/lib/sized.js +41 -0
- package/configure/node_modules/@pie-lib/icons/lib/sized.js.map +1 -0
- package/configure/node_modules/@pie-lib/icons/package.json +35 -0
- package/configure/node_modules/@pie-lib/icons/src/__tests__/index.test.js +3 -0
- package/configure/node_modules/@pie-lib/icons/src/correct-icon.jsx +64 -0
- package/configure/node_modules/@pie-lib/icons/src/correct-response-icon.jsx +121 -0
- package/configure/node_modules/@pie-lib/icons/src/icon-base.jsx +158 -0
- package/configure/node_modules/@pie-lib/icons/src/icon-root.jsx +76 -0
- package/configure/node_modules/@pie-lib/icons/src/incorrect-icon.jsx +61 -0
- package/configure/node_modules/@pie-lib/icons/src/index.js +19 -0
- package/configure/node_modules/@pie-lib/icons/src/instructions-icon.jsx +189 -0
- package/configure/node_modules/@pie-lib/icons/src/learn-more-icon.jsx +107 -0
- package/configure/node_modules/@pie-lib/icons/src/nothing-submitted-icon.jsx +130 -0
- package/configure/node_modules/@pie-lib/icons/src/partially-correct-icon.jsx +49 -0
- package/configure/node_modules/@pie-lib/icons/src/show-rationale-icon.jsx +152 -0
- package/configure/node_modules/@pie-lib/icons/src/sized.jsx +25 -0
- package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/CHANGELOG.md +775 -0
- package/configure/node_modules/@pie-lib/math-rendering/NEXT.CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/esm/index.js +690 -0
- package/configure/node_modules/@pie-lib/math-rendering/esm/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/index.js +38 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mml-to-latex.js +15 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mml-to-latex.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js +296 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/chtml.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js +23 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js +109 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/mstack/mml.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js +95 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/normalization.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js +438 -0
- package/configure/node_modules/@pie-lib/math-rendering/lib/render-math.js.map +1 -0
- package/configure/node_modules/@pie-lib/math-rendering/package.json +28 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/__tests__/mml-to-latex.test.js +14 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/__tests__/normalization.test.js +50 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/__tests__/render-math.test.js +155 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/index.js +5 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mml-to-latex.js +2 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mstack/__tests__/__snapshots__/chtml.test.js.snap +9 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mstack/__tests__/chtml.test.js +104 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mstack/chtml.js +220 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mstack/index.js +13 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/mstack/mml.js +24 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/normalization.js +69 -0
- package/configure/node_modules/@pie-lib/math-rendering/src/render-math.js +387 -0
- package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/render-ui/CHANGELOG.md +1026 -0
- package/configure/node_modules/@pie-lib/render-ui/NEXT.CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/render-ui/esm/index.js +1616 -0
- package/configure/node_modules/@pie-lib/render-ui/esm/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/append-css-rules.js +88 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/append-css-rules.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/assets/enableAudioAutoplayImage.js +9 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/assets/enableAudioAutoplayImage.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js +135 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/collapsible/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/color.js +344 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/color.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js +150 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/feedback.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/has-media.js +27 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/has-media.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js +28 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/has-text.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js +74 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/html-and-math.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/index.js +136 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js +60 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/input-container.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js +145 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-layout.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js +321 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/preview-prompt.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js +28 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/purpose.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/readable.js +28 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/readable.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js +151 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/response-indicators.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/ui-layout.js +122 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/ui-layout.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js +181 -0
- package/configure/node_modules/@pie-lib/render-ui/lib/withUndoReset.js.map +1 -0
- package/configure/node_modules/@pie-lib/render-ui/package.json +40 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/__snapshots__/html-and-math.test.js.snap +11 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/__snapshots__/preview-prompt.test.jsx.snap +37 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/__snapshots__/purpose.test.jsx.snap +42 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/__snapshots__/readable.test.jsx.snap +64 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/__snapshots__/response-indicators.test.jsx.snap +27 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/color.test.js +12 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/has-media.test.js +20 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/has-text.test.js +21 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/html-and-math.test.js +24 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/preview-prompt.test.jsx +56 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/purpose.test.jsx +47 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/readable.test.jsx +64 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/response-indicators.test.jsx +16 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/ui-layout.test.jsx +34 -0
- package/configure/node_modules/@pie-lib/render-ui/src/__tests__/withUndoReset.test.jsx +254 -0
- package/configure/node_modules/@pie-lib/render-ui/src/append-css-rules.js +51 -0
- package/configure/node_modules/@pie-lib/render-ui/src/assets/enableAudioAutoplayImage.js +1 -0
- package/configure/node_modules/@pie-lib/render-ui/src/collapsible/__tests__/__snapshots__/index.test.jsx.snap +18 -0
- package/configure/node_modules/@pie-lib/render-ui/src/collapsible/__tests__/index.test.jsx +13 -0
- package/configure/node_modules/@pie-lib/render-ui/src/collapsible/index.jsx +64 -0
- package/configure/node_modules/@pie-lib/render-ui/src/color.js +121 -0
- package/configure/node_modules/@pie-lib/render-ui/src/feedback.jsx +99 -0
- package/configure/node_modules/@pie-lib/render-ui/src/has-media.js +16 -0
- package/configure/node_modules/@pie-lib/render-ui/src/has-text.js +18 -0
- package/configure/node_modules/@pie-lib/render-ui/src/html-and-math.js +21 -0
- package/configure/node_modules/@pie-lib/render-ui/src/index.js +35 -0
- package/configure/node_modules/@pie-lib/render-ui/src/input-container.jsx +41 -0
- package/configure/node_modules/@pie-lib/render-ui/src/preview-layout.jsx +95 -0
- package/configure/node_modules/@pie-lib/render-ui/src/preview-prompt.jsx +254 -0
- package/configure/node_modules/@pie-lib/render-ui/src/purpose.jsx +17 -0
- package/configure/node_modules/@pie-lib/render-ui/src/readable.jsx +19 -0
- package/configure/node_modules/@pie-lib/render-ui/src/response-indicators.jsx +89 -0
- package/configure/node_modules/@pie-lib/render-ui/src/ui-layout.jsx +66 -0
- package/configure/node_modules/@pie-lib/render-ui/src/withUndoReset.jsx +116 -0
- package/configure/node_modules/@pie-lib/test-utils/CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/test-utils/CHANGELOG.md +410 -0
- package/configure/node_modules/@pie-lib/test-utils/NEXT.CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/test-utils/esm/index.js +39 -0
- package/configure/node_modules/@pie-lib/test-utils/esm/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/test-utils/lib/index.js +40 -0
- package/configure/node_modules/@pie-lib/test-utils/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/test-utils/package.json +25 -0
- package/configure/node_modules/@pie-lib/test-utils/src/__tests__/index.test.js +45 -0
- package/configure/node_modules/@pie-lib/test-utils/src/index.js +18 -0
- package/configure/node_modules/@pie-lib/translator/CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/translator/CHANGELOG.md +282 -0
- package/configure/node_modules/@pie-lib/translator/NEXT.CHANGELOG.json +1 -0
- package/configure/node_modules/@pie-lib/translator/esm/index.js +257 -0
- package/configure/node_modules/@pie-lib/translator/esm/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/translator/lib/en.js +102 -0
- package/configure/node_modules/@pie-lib/translator/lib/en.js.map +1 -0
- package/configure/node_modules/@pie-lib/translator/lib/es.js +102 -0
- package/configure/node_modules/@pie-lib/translator/lib/es.js.map +1 -0
- package/configure/node_modules/@pie-lib/translator/lib/index.js +69 -0
- package/configure/node_modules/@pie-lib/translator/lib/index.js.map +1 -0
- package/configure/node_modules/@pie-lib/translator/package.json +25 -0
- package/configure/node_modules/@pie-lib/translator/src/en.js +99 -0
- package/configure/node_modules/@pie-lib/translator/src/es.js +99 -0
- package/configure/node_modules/@pie-lib/translator/src/index.js +43 -0
- package/configure/package.json +3 -3
- package/controller/CHANGELOG.md +16 -0
- package/controller/package.json +3 -3
- package/esm/configure.js +38602 -0
- package/esm/configure.js.map +1 -0
- package/esm/controller.js +3358 -0
- package/esm/controller.js.map +1 -0
- package/esm/element.js +2203 -0
- package/esm/element.js.map +1 -0
- package/esm/package.json +4 -0
- package/esm/print.js +4090 -0
- package/esm/print.js.map +1 -0
- package/module/controller.js +4973 -2252
- package/module/element.js +1 -1
- package/module/index.html +1 -1
- package/module/manifest.json +1 -1
- package/module/print.html +1 -1
- package/module/print.js +1 -1
- package/package.json +24 -6
|
@@ -0,0 +1,3287 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import PropTypes$2 from 'prop-types';
|
|
3
|
+
import { withStyles, createMuiTheme, MuiThemeProvider } from '@material-ui/core/styles';
|
|
4
|
+
import { color, PreviewPrompt, Feedback, Collapsible, PreviewLayout, EnableAudioAutoplayImage } from '@pie-lib/render-ui';
|
|
5
|
+
import CorrectAnswerToggle from '@pie-lib/correct-answer-toggle';
|
|
6
|
+
import classNames from 'classnames';
|
|
7
|
+
import Translator from '@pie-lib/translator';
|
|
8
|
+
import FormControlLabel from '@material-ui/core/FormControlLabel';
|
|
9
|
+
import Checkbox from '@material-ui/core/Checkbox';
|
|
10
|
+
import Radio from '@material-ui/core/Radio';
|
|
11
|
+
import require$$2$1 from 'react-dom';
|
|
12
|
+
import debounce from 'lodash/debounce';
|
|
13
|
+
import debug from 'debug';
|
|
14
|
+
import { SessionChangedEvent, ModelSetEvent } from '@pie-framework/pie-player-events';
|
|
15
|
+
import { renderMath } from '@pie-lib/math-rendering';
|
|
16
|
+
|
|
17
|
+
function _extends() {
|
|
18
|
+
_extends = Object.assign || function (target) {
|
|
19
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
20
|
+
var source = arguments[i];
|
|
21
|
+
|
|
22
|
+
for (var key in source) {
|
|
23
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
24
|
+
target[key] = source[key];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return target;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
return _extends.apply(this, arguments);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getAugmentedNamespace(n) {
|
|
36
|
+
if (n.__esModule) return n;
|
|
37
|
+
var a = Object.defineProperty({}, '__esModule', {value: true});
|
|
38
|
+
Object.keys(n).forEach(function (k) {
|
|
39
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
40
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
41
|
+
enumerable: true,
|
|
42
|
+
get: function () {
|
|
43
|
+
return n[k];
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
return a;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
var CSSTransition = {exports: {}};
|
|
51
|
+
|
|
52
|
+
var addClass = {exports: {}};
|
|
53
|
+
|
|
54
|
+
var interopRequireDefault = {exports: {}};
|
|
55
|
+
|
|
56
|
+
(function (module) {
|
|
57
|
+
function _interopRequireDefault(obj) {
|
|
58
|
+
return obj && obj.__esModule ? obj : {
|
|
59
|
+
"default": obj
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = _interopRequireDefault, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
64
|
+
}(interopRequireDefault));
|
|
65
|
+
|
|
66
|
+
var hasClass = {exports: {}};
|
|
67
|
+
|
|
68
|
+
(function (module, exports) {
|
|
69
|
+
|
|
70
|
+
exports.__esModule = true;
|
|
71
|
+
exports.default = hasClass;
|
|
72
|
+
|
|
73
|
+
function hasClass(element, className) {
|
|
74
|
+
if (element.classList) return !!className && element.classList.contains(className);else return (" " + (element.className.baseVal || element.className) + " ").indexOf(" " + className + " ") !== -1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
module.exports = exports["default"];
|
|
78
|
+
}(hasClass, hasClass.exports));
|
|
79
|
+
|
|
80
|
+
(function (module, exports) {
|
|
81
|
+
|
|
82
|
+
var _interopRequireDefault = interopRequireDefault.exports;
|
|
83
|
+
|
|
84
|
+
exports.__esModule = true;
|
|
85
|
+
exports.default = addClass;
|
|
86
|
+
|
|
87
|
+
var _hasClass = _interopRequireDefault(hasClass.exports);
|
|
88
|
+
|
|
89
|
+
function addClass(element, className) {
|
|
90
|
+
if (element.classList) element.classList.add(className);else if (!(0, _hasClass.default)(element, className)) if (typeof element.className === 'string') element.className = element.className + ' ' + className;else element.setAttribute('class', (element.className && element.className.baseVal || '') + ' ' + className);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = exports["default"];
|
|
94
|
+
}(addClass, addClass.exports));
|
|
95
|
+
|
|
96
|
+
function replaceClassName(origClass, classToRemove) {
|
|
97
|
+
return origClass.replace(new RegExp('(^|\\s)' + classToRemove + '(?:\\s|$)', 'g'), '$1').replace(/\s+/g, ' ').replace(/^\s*|\s*$/g, '');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
var removeClass = function removeClass(element, className) {
|
|
101
|
+
if (element.classList) element.classList.remove(className);else if (typeof element.className === 'string') element.className = replaceClassName(element.className, className);else element.setAttribute('class', replaceClassName(element.className && element.className.baseVal || '', className));
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
var Transition$1 = {};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
108
|
+
*
|
|
109
|
+
* This source code is licensed under the MIT license found in the
|
|
110
|
+
* LICENSE file in the root directory of this source tree.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
function componentWillMount() {
|
|
114
|
+
// Call this.constructor.gDSFP to support sub-classes.
|
|
115
|
+
var state = this.constructor.getDerivedStateFromProps(this.props, this.state);
|
|
116
|
+
if (state !== null && state !== undefined) {
|
|
117
|
+
this.setState(state);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function componentWillReceiveProps(nextProps) {
|
|
122
|
+
// Call this.constructor.gDSFP to support sub-classes.
|
|
123
|
+
// Use the setState() updater to ensure state isn't stale in certain edge cases.
|
|
124
|
+
function updater(prevState) {
|
|
125
|
+
var state = this.constructor.getDerivedStateFromProps(nextProps, prevState);
|
|
126
|
+
return state !== null && state !== undefined ? state : null;
|
|
127
|
+
}
|
|
128
|
+
// Binding "this" is important for shallow renderer support.
|
|
129
|
+
this.setState(updater.bind(this));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function componentWillUpdate(nextProps, nextState) {
|
|
133
|
+
try {
|
|
134
|
+
var prevProps = this.props;
|
|
135
|
+
var prevState = this.state;
|
|
136
|
+
this.props = nextProps;
|
|
137
|
+
this.state = nextState;
|
|
138
|
+
this.__reactInternalSnapshotFlag = true;
|
|
139
|
+
this.__reactInternalSnapshot = this.getSnapshotBeforeUpdate(
|
|
140
|
+
prevProps,
|
|
141
|
+
prevState
|
|
142
|
+
);
|
|
143
|
+
} finally {
|
|
144
|
+
this.props = prevProps;
|
|
145
|
+
this.state = prevState;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// React may warn about cWM/cWRP/cWU methods being deprecated.
|
|
150
|
+
// Add a flag to suppress these warnings for this special case.
|
|
151
|
+
componentWillMount.__suppressDeprecationWarning = true;
|
|
152
|
+
componentWillReceiveProps.__suppressDeprecationWarning = true;
|
|
153
|
+
componentWillUpdate.__suppressDeprecationWarning = true;
|
|
154
|
+
|
|
155
|
+
function polyfill(Component) {
|
|
156
|
+
var prototype = Component.prototype;
|
|
157
|
+
|
|
158
|
+
if (!prototype || !prototype.isReactComponent) {
|
|
159
|
+
throw new Error('Can only polyfill class components');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (
|
|
163
|
+
typeof Component.getDerivedStateFromProps !== 'function' &&
|
|
164
|
+
typeof prototype.getSnapshotBeforeUpdate !== 'function'
|
|
165
|
+
) {
|
|
166
|
+
return Component;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// If new component APIs are defined, "unsafe" lifecycles won't be called.
|
|
170
|
+
// Error if any of these lifecycles are present,
|
|
171
|
+
// Because they would work differently between older and newer (16.3+) versions of React.
|
|
172
|
+
var foundWillMountName = null;
|
|
173
|
+
var foundWillReceivePropsName = null;
|
|
174
|
+
var foundWillUpdateName = null;
|
|
175
|
+
if (typeof prototype.componentWillMount === 'function') {
|
|
176
|
+
foundWillMountName = 'componentWillMount';
|
|
177
|
+
} else if (typeof prototype.UNSAFE_componentWillMount === 'function') {
|
|
178
|
+
foundWillMountName = 'UNSAFE_componentWillMount';
|
|
179
|
+
}
|
|
180
|
+
if (typeof prototype.componentWillReceiveProps === 'function') {
|
|
181
|
+
foundWillReceivePropsName = 'componentWillReceiveProps';
|
|
182
|
+
} else if (typeof prototype.UNSAFE_componentWillReceiveProps === 'function') {
|
|
183
|
+
foundWillReceivePropsName = 'UNSAFE_componentWillReceiveProps';
|
|
184
|
+
}
|
|
185
|
+
if (typeof prototype.componentWillUpdate === 'function') {
|
|
186
|
+
foundWillUpdateName = 'componentWillUpdate';
|
|
187
|
+
} else if (typeof prototype.UNSAFE_componentWillUpdate === 'function') {
|
|
188
|
+
foundWillUpdateName = 'UNSAFE_componentWillUpdate';
|
|
189
|
+
}
|
|
190
|
+
if (
|
|
191
|
+
foundWillMountName !== null ||
|
|
192
|
+
foundWillReceivePropsName !== null ||
|
|
193
|
+
foundWillUpdateName !== null
|
|
194
|
+
) {
|
|
195
|
+
var componentName = Component.displayName || Component.name;
|
|
196
|
+
var newApiName =
|
|
197
|
+
typeof Component.getDerivedStateFromProps === 'function'
|
|
198
|
+
? 'getDerivedStateFromProps()'
|
|
199
|
+
: 'getSnapshotBeforeUpdate()';
|
|
200
|
+
|
|
201
|
+
throw Error(
|
|
202
|
+
'Unsafe legacy lifecycles will not be called for components using new component APIs.\n\n' +
|
|
203
|
+
componentName +
|
|
204
|
+
' uses ' +
|
|
205
|
+
newApiName +
|
|
206
|
+
' but also contains the following legacy lifecycles:' +
|
|
207
|
+
(foundWillMountName !== null ? '\n ' + foundWillMountName : '') +
|
|
208
|
+
(foundWillReceivePropsName !== null
|
|
209
|
+
? '\n ' + foundWillReceivePropsName
|
|
210
|
+
: '') +
|
|
211
|
+
(foundWillUpdateName !== null ? '\n ' + foundWillUpdateName : '') +
|
|
212
|
+
'\n\nThe above lifecycles should be removed. Learn more about this warning here:\n' +
|
|
213
|
+
'https://fb.me/react-async-component-lifecycle-hooks'
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// React <= 16.2 does not support static getDerivedStateFromProps.
|
|
218
|
+
// As a workaround, use cWM and cWRP to invoke the new static lifecycle.
|
|
219
|
+
// Newer versions of React will ignore these lifecycles if gDSFP exists.
|
|
220
|
+
if (typeof Component.getDerivedStateFromProps === 'function') {
|
|
221
|
+
prototype.componentWillMount = componentWillMount;
|
|
222
|
+
prototype.componentWillReceiveProps = componentWillReceiveProps;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// React <= 16.2 does not support getSnapshotBeforeUpdate.
|
|
226
|
+
// As a workaround, use cWU to invoke the new lifecycle.
|
|
227
|
+
// Newer versions of React will ignore that lifecycle if gSBU exists.
|
|
228
|
+
if (typeof prototype.getSnapshotBeforeUpdate === 'function') {
|
|
229
|
+
if (typeof prototype.componentDidUpdate !== 'function') {
|
|
230
|
+
throw new Error(
|
|
231
|
+
'Cannot polyfill getSnapshotBeforeUpdate() for components that do not define componentDidUpdate() on the prototype'
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
prototype.componentWillUpdate = componentWillUpdate;
|
|
236
|
+
|
|
237
|
+
var componentDidUpdate = prototype.componentDidUpdate;
|
|
238
|
+
|
|
239
|
+
prototype.componentDidUpdate = function componentDidUpdatePolyfill(
|
|
240
|
+
prevProps,
|
|
241
|
+
prevState,
|
|
242
|
+
maybeSnapshot
|
|
243
|
+
) {
|
|
244
|
+
// 16.3+ will not execute our will-update method;
|
|
245
|
+
// It will pass a snapshot value to did-update though.
|
|
246
|
+
// Older versions will require our polyfilled will-update value.
|
|
247
|
+
// We need to handle both cases, but can't just check for the presence of "maybeSnapshot",
|
|
248
|
+
// Because for <= 15.x versions this might be a "prevContext" object.
|
|
249
|
+
// We also can't just check "__reactInternalSnapshot",
|
|
250
|
+
// Because get-snapshot might return a falsy value.
|
|
251
|
+
// So check for the explicit __reactInternalSnapshotFlag flag to determine behavior.
|
|
252
|
+
var snapshot = this.__reactInternalSnapshotFlag
|
|
253
|
+
? this.__reactInternalSnapshot
|
|
254
|
+
: maybeSnapshot;
|
|
255
|
+
|
|
256
|
+
componentDidUpdate.call(this, prevProps, prevState, snapshot);
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return Component;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
var reactLifecyclesCompat_es = /*#__PURE__*/Object.freeze({
|
|
264
|
+
__proto__: null,
|
|
265
|
+
polyfill: polyfill
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
var require$$2 = /*@__PURE__*/getAugmentedNamespace(reactLifecyclesCompat_es);
|
|
269
|
+
|
|
270
|
+
var PropTypes$1 = {};
|
|
271
|
+
|
|
272
|
+
PropTypes$1.__esModule = true;
|
|
273
|
+
PropTypes$1.classNamesShape = PropTypes$1.timeoutsShape = void 0;
|
|
274
|
+
|
|
275
|
+
var _propTypes = _interopRequireDefault$2(PropTypes$2);
|
|
276
|
+
|
|
277
|
+
function _interopRequireDefault$2(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
278
|
+
|
|
279
|
+
var timeoutsShape = process.env.NODE_ENV !== 'production' ? _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.shape({
|
|
280
|
+
enter: _propTypes.default.number,
|
|
281
|
+
exit: _propTypes.default.number,
|
|
282
|
+
appear: _propTypes.default.number
|
|
283
|
+
}).isRequired]) : null;
|
|
284
|
+
PropTypes$1.timeoutsShape = timeoutsShape;
|
|
285
|
+
var classNamesShape = process.env.NODE_ENV !== 'production' ? _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({
|
|
286
|
+
enter: _propTypes.default.string,
|
|
287
|
+
exit: _propTypes.default.string,
|
|
288
|
+
active: _propTypes.default.string
|
|
289
|
+
}), _propTypes.default.shape({
|
|
290
|
+
enter: _propTypes.default.string,
|
|
291
|
+
enterDone: _propTypes.default.string,
|
|
292
|
+
enterActive: _propTypes.default.string,
|
|
293
|
+
exit: _propTypes.default.string,
|
|
294
|
+
exitDone: _propTypes.default.string,
|
|
295
|
+
exitActive: _propTypes.default.string
|
|
296
|
+
})]) : null;
|
|
297
|
+
PropTypes$1.classNamesShape = classNamesShape;
|
|
298
|
+
|
|
299
|
+
Transition$1.__esModule = true;
|
|
300
|
+
Transition$1.default = Transition$1.EXITING = Transition$1.ENTERED = Transition$1.ENTERING = Transition$1.EXITED = Transition$1.UNMOUNTED = void 0;
|
|
301
|
+
|
|
302
|
+
var PropTypes = _interopRequireWildcard(PropTypes$2);
|
|
303
|
+
|
|
304
|
+
var _react$1 = _interopRequireDefault$1(React);
|
|
305
|
+
|
|
306
|
+
var _reactDom = _interopRequireDefault$1(require$$2$1);
|
|
307
|
+
|
|
308
|
+
var _reactLifecyclesCompat = require$$2;
|
|
309
|
+
|
|
310
|
+
var _PropTypes = PropTypes$1;
|
|
311
|
+
|
|
312
|
+
function _interopRequireDefault$1(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
313
|
+
|
|
314
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
315
|
+
|
|
316
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
317
|
+
|
|
318
|
+
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
|
319
|
+
|
|
320
|
+
var UNMOUNTED = 'unmounted';
|
|
321
|
+
Transition$1.UNMOUNTED = UNMOUNTED;
|
|
322
|
+
var EXITED = 'exited';
|
|
323
|
+
Transition$1.EXITED = EXITED;
|
|
324
|
+
var ENTERING = 'entering';
|
|
325
|
+
Transition$1.ENTERING = ENTERING;
|
|
326
|
+
var ENTERED = 'entered';
|
|
327
|
+
Transition$1.ENTERED = ENTERED;
|
|
328
|
+
var EXITING = 'exiting';
|
|
329
|
+
/**
|
|
330
|
+
* The Transition component lets you describe a transition from one component
|
|
331
|
+
* state to another _over time_ with a simple declarative API. Most commonly
|
|
332
|
+
* it's used to animate the mounting and unmounting of a component, but can also
|
|
333
|
+
* be used to describe in-place transition states as well.
|
|
334
|
+
*
|
|
335
|
+
* ---
|
|
336
|
+
*
|
|
337
|
+
* **Note**: `Transition` is a platform-agnostic base component. If you're using
|
|
338
|
+
* transitions in CSS, you'll probably want to use
|
|
339
|
+
* [`CSSTransition`](https://reactcommunity.org/react-transition-group/css-transition)
|
|
340
|
+
* instead. It inherits all the features of `Transition`, but contains
|
|
341
|
+
* additional features necessary to play nice with CSS transitions (hence the
|
|
342
|
+
* name of the component).
|
|
343
|
+
*
|
|
344
|
+
* ---
|
|
345
|
+
*
|
|
346
|
+
* By default the `Transition` component does not alter the behavior of the
|
|
347
|
+
* component it renders, it only tracks "enter" and "exit" states for the
|
|
348
|
+
* components. It's up to you to give meaning and effect to those states. For
|
|
349
|
+
* example we can add styles to a component when it enters or exits:
|
|
350
|
+
*
|
|
351
|
+
* ```jsx
|
|
352
|
+
* import { Transition } from 'react-transition-group';
|
|
353
|
+
*
|
|
354
|
+
* const duration = 300;
|
|
355
|
+
*
|
|
356
|
+
* const defaultStyle = {
|
|
357
|
+
* transition: `opacity ${duration}ms ease-in-out`,
|
|
358
|
+
* opacity: 0,
|
|
359
|
+
* }
|
|
360
|
+
*
|
|
361
|
+
* const transitionStyles = {
|
|
362
|
+
* entering: { opacity: 0 },
|
|
363
|
+
* entered: { opacity: 1 },
|
|
364
|
+
* };
|
|
365
|
+
*
|
|
366
|
+
* const Fade = ({ in: inProp }) => (
|
|
367
|
+
* <Transition in={inProp} timeout={duration}>
|
|
368
|
+
* {state => (
|
|
369
|
+
* <div style={{
|
|
370
|
+
* ...defaultStyle,
|
|
371
|
+
* ...transitionStyles[state]
|
|
372
|
+
* }}>
|
|
373
|
+
* I'm a fade Transition!
|
|
374
|
+
* </div>
|
|
375
|
+
* )}
|
|
376
|
+
* </Transition>
|
|
377
|
+
* );
|
|
378
|
+
* ```
|
|
379
|
+
*
|
|
380
|
+
* There are 4 main states a Transition can be in:
|
|
381
|
+
* - `'entering'`
|
|
382
|
+
* - `'entered'`
|
|
383
|
+
* - `'exiting'`
|
|
384
|
+
* - `'exited'`
|
|
385
|
+
*
|
|
386
|
+
* Transition state is toggled via the `in` prop. When `true` the component
|
|
387
|
+
* begins the "Enter" stage. During this stage, the component will shift from
|
|
388
|
+
* its current transition state, to `'entering'` for the duration of the
|
|
389
|
+
* transition and then to the `'entered'` stage once it's complete. Let's take
|
|
390
|
+
* the following example (we'll use the
|
|
391
|
+
* [useState](https://reactjs.org/docs/hooks-reference.html#usestate) hook):
|
|
392
|
+
*
|
|
393
|
+
* ```jsx
|
|
394
|
+
* function App() {
|
|
395
|
+
* const [inProp, setInProp] = useState(false);
|
|
396
|
+
* return (
|
|
397
|
+
* <div>
|
|
398
|
+
* <Transition in={inProp} timeout={500}>
|
|
399
|
+
* {state => (
|
|
400
|
+
* // ...
|
|
401
|
+
* )}
|
|
402
|
+
* </Transition>
|
|
403
|
+
* <button onClick={() => setInProp(true)}>
|
|
404
|
+
* Click to Enter
|
|
405
|
+
* </button>
|
|
406
|
+
* </div>
|
|
407
|
+
* );
|
|
408
|
+
* }
|
|
409
|
+
* ```
|
|
410
|
+
*
|
|
411
|
+
* When the button is clicked the component will shift to the `'entering'` state
|
|
412
|
+
* and stay there for 500ms (the value of `timeout`) before it finally switches
|
|
413
|
+
* to `'entered'`.
|
|
414
|
+
*
|
|
415
|
+
* When `in` is `false` the same thing happens except the state moves from
|
|
416
|
+
* `'exiting'` to `'exited'`.
|
|
417
|
+
*/
|
|
418
|
+
|
|
419
|
+
Transition$1.EXITING = EXITING;
|
|
420
|
+
|
|
421
|
+
var Transition =
|
|
422
|
+
/*#__PURE__*/
|
|
423
|
+
function (_React$Component) {
|
|
424
|
+
_inheritsLoose(Transition, _React$Component);
|
|
425
|
+
|
|
426
|
+
function Transition(props, context) {
|
|
427
|
+
var _this;
|
|
428
|
+
|
|
429
|
+
_this = _React$Component.call(this, props, context) || this;
|
|
430
|
+
var parentGroup = context.transitionGroup; // In the context of a TransitionGroup all enters are really appears
|
|
431
|
+
|
|
432
|
+
var appear = parentGroup && !parentGroup.isMounting ? props.enter : props.appear;
|
|
433
|
+
var initialStatus;
|
|
434
|
+
_this.appearStatus = null;
|
|
435
|
+
|
|
436
|
+
if (props.in) {
|
|
437
|
+
if (appear) {
|
|
438
|
+
initialStatus = EXITED;
|
|
439
|
+
_this.appearStatus = ENTERING;
|
|
440
|
+
} else {
|
|
441
|
+
initialStatus = ENTERED;
|
|
442
|
+
}
|
|
443
|
+
} else {
|
|
444
|
+
if (props.unmountOnExit || props.mountOnEnter) {
|
|
445
|
+
initialStatus = UNMOUNTED;
|
|
446
|
+
} else {
|
|
447
|
+
initialStatus = EXITED;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
_this.state = {
|
|
452
|
+
status: initialStatus
|
|
453
|
+
};
|
|
454
|
+
_this.nextCallback = null;
|
|
455
|
+
return _this;
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
var _proto = Transition.prototype;
|
|
459
|
+
|
|
460
|
+
_proto.getChildContext = function getChildContext() {
|
|
461
|
+
return {
|
|
462
|
+
transitionGroup: null // allows for nested Transitions
|
|
463
|
+
|
|
464
|
+
};
|
|
465
|
+
};
|
|
466
|
+
|
|
467
|
+
Transition.getDerivedStateFromProps = function getDerivedStateFromProps(_ref, prevState) {
|
|
468
|
+
var nextIn = _ref.in;
|
|
469
|
+
|
|
470
|
+
if (nextIn && prevState.status === UNMOUNTED) {
|
|
471
|
+
return {
|
|
472
|
+
status: EXITED
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
return null;
|
|
477
|
+
}; // getSnapshotBeforeUpdate(prevProps) {
|
|
478
|
+
// let nextStatus = null
|
|
479
|
+
// if (prevProps !== this.props) {
|
|
480
|
+
// const { status } = this.state
|
|
481
|
+
// if (this.props.in) {
|
|
482
|
+
// if (status !== ENTERING && status !== ENTERED) {
|
|
483
|
+
// nextStatus = ENTERING
|
|
484
|
+
// }
|
|
485
|
+
// } else {
|
|
486
|
+
// if (status === ENTERING || status === ENTERED) {
|
|
487
|
+
// nextStatus = EXITING
|
|
488
|
+
// }
|
|
489
|
+
// }
|
|
490
|
+
// }
|
|
491
|
+
// return { nextStatus }
|
|
492
|
+
// }
|
|
493
|
+
|
|
494
|
+
|
|
495
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
496
|
+
this.updateStatus(true, this.appearStatus);
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
_proto.componentDidUpdate = function componentDidUpdate(prevProps) {
|
|
500
|
+
var nextStatus = null;
|
|
501
|
+
|
|
502
|
+
if (prevProps !== this.props) {
|
|
503
|
+
var status = this.state.status;
|
|
504
|
+
|
|
505
|
+
if (this.props.in) {
|
|
506
|
+
if (status !== ENTERING && status !== ENTERED) {
|
|
507
|
+
nextStatus = ENTERING;
|
|
508
|
+
}
|
|
509
|
+
} else {
|
|
510
|
+
if (status === ENTERING || status === ENTERED) {
|
|
511
|
+
nextStatus = EXITING;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
this.updateStatus(false, nextStatus);
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
520
|
+
this.cancelNextCallback();
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
_proto.getTimeouts = function getTimeouts() {
|
|
524
|
+
var timeout = this.props.timeout;
|
|
525
|
+
var exit, enter, appear;
|
|
526
|
+
exit = enter = appear = timeout;
|
|
527
|
+
|
|
528
|
+
if (timeout != null && typeof timeout !== 'number') {
|
|
529
|
+
exit = timeout.exit;
|
|
530
|
+
enter = timeout.enter; // TODO: remove fallback for next major
|
|
531
|
+
|
|
532
|
+
appear = timeout.appear !== undefined ? timeout.appear : enter;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
return {
|
|
536
|
+
exit: exit,
|
|
537
|
+
enter: enter,
|
|
538
|
+
appear: appear
|
|
539
|
+
};
|
|
540
|
+
};
|
|
541
|
+
|
|
542
|
+
_proto.updateStatus = function updateStatus(mounting, nextStatus) {
|
|
543
|
+
if (mounting === void 0) {
|
|
544
|
+
mounting = false;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (nextStatus !== null) {
|
|
548
|
+
// nextStatus will always be ENTERING or EXITING.
|
|
549
|
+
this.cancelNextCallback();
|
|
550
|
+
|
|
551
|
+
var node = _reactDom.default.findDOMNode(this);
|
|
552
|
+
|
|
553
|
+
if (nextStatus === ENTERING) {
|
|
554
|
+
this.performEnter(node, mounting);
|
|
555
|
+
} else {
|
|
556
|
+
this.performExit(node);
|
|
557
|
+
}
|
|
558
|
+
} else if (this.props.unmountOnExit && this.state.status === EXITED) {
|
|
559
|
+
this.setState({
|
|
560
|
+
status: UNMOUNTED
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
_proto.performEnter = function performEnter(node, mounting) {
|
|
566
|
+
var _this2 = this;
|
|
567
|
+
|
|
568
|
+
var enter = this.props.enter;
|
|
569
|
+
var appearing = this.context.transitionGroup ? this.context.transitionGroup.isMounting : mounting;
|
|
570
|
+
var timeouts = this.getTimeouts();
|
|
571
|
+
var enterTimeout = appearing ? timeouts.appear : timeouts.enter; // no enter animation skip right to ENTERED
|
|
572
|
+
// if we are mounting and running this it means appear _must_ be set
|
|
573
|
+
|
|
574
|
+
if (!mounting && !enter) {
|
|
575
|
+
this.safeSetState({
|
|
576
|
+
status: ENTERED
|
|
577
|
+
}, function () {
|
|
578
|
+
_this2.props.onEntered(node);
|
|
579
|
+
});
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
this.props.onEnter(node, appearing);
|
|
584
|
+
this.safeSetState({
|
|
585
|
+
status: ENTERING
|
|
586
|
+
}, function () {
|
|
587
|
+
_this2.props.onEntering(node, appearing);
|
|
588
|
+
|
|
589
|
+
_this2.onTransitionEnd(node, enterTimeout, function () {
|
|
590
|
+
_this2.safeSetState({
|
|
591
|
+
status: ENTERED
|
|
592
|
+
}, function () {
|
|
593
|
+
_this2.props.onEntered(node, appearing);
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
});
|
|
597
|
+
};
|
|
598
|
+
|
|
599
|
+
_proto.performExit = function performExit(node) {
|
|
600
|
+
var _this3 = this;
|
|
601
|
+
|
|
602
|
+
var exit = this.props.exit;
|
|
603
|
+
var timeouts = this.getTimeouts(); // no exit animation skip right to EXITED
|
|
604
|
+
|
|
605
|
+
if (!exit) {
|
|
606
|
+
this.safeSetState({
|
|
607
|
+
status: EXITED
|
|
608
|
+
}, function () {
|
|
609
|
+
_this3.props.onExited(node);
|
|
610
|
+
});
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
this.props.onExit(node);
|
|
615
|
+
this.safeSetState({
|
|
616
|
+
status: EXITING
|
|
617
|
+
}, function () {
|
|
618
|
+
_this3.props.onExiting(node);
|
|
619
|
+
|
|
620
|
+
_this3.onTransitionEnd(node, timeouts.exit, function () {
|
|
621
|
+
_this3.safeSetState({
|
|
622
|
+
status: EXITED
|
|
623
|
+
}, function () {
|
|
624
|
+
_this3.props.onExited(node);
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
};
|
|
629
|
+
|
|
630
|
+
_proto.cancelNextCallback = function cancelNextCallback() {
|
|
631
|
+
if (this.nextCallback !== null) {
|
|
632
|
+
this.nextCallback.cancel();
|
|
633
|
+
this.nextCallback = null;
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
_proto.safeSetState = function safeSetState(nextState, callback) {
|
|
638
|
+
// This shouldn't be necessary, but there are weird race conditions with
|
|
639
|
+
// setState callbacks and unmounting in testing, so always make sure that
|
|
640
|
+
// we can cancel any pending setState callbacks after we unmount.
|
|
641
|
+
callback = this.setNextCallback(callback);
|
|
642
|
+
this.setState(nextState, callback);
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
_proto.setNextCallback = function setNextCallback(callback) {
|
|
646
|
+
var _this4 = this;
|
|
647
|
+
|
|
648
|
+
var active = true;
|
|
649
|
+
|
|
650
|
+
this.nextCallback = function (event) {
|
|
651
|
+
if (active) {
|
|
652
|
+
active = false;
|
|
653
|
+
_this4.nextCallback = null;
|
|
654
|
+
callback(event);
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
this.nextCallback.cancel = function () {
|
|
659
|
+
active = false;
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
return this.nextCallback;
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
_proto.onTransitionEnd = function onTransitionEnd(node, timeout, handler) {
|
|
666
|
+
this.setNextCallback(handler);
|
|
667
|
+
var doesNotHaveTimeoutOrListener = timeout == null && !this.props.addEndListener;
|
|
668
|
+
|
|
669
|
+
if (!node || doesNotHaveTimeoutOrListener) {
|
|
670
|
+
setTimeout(this.nextCallback, 0);
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
if (this.props.addEndListener) {
|
|
675
|
+
this.props.addEndListener(node, this.nextCallback);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
if (timeout != null) {
|
|
679
|
+
setTimeout(this.nextCallback, timeout);
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
_proto.render = function render() {
|
|
684
|
+
var status = this.state.status;
|
|
685
|
+
|
|
686
|
+
if (status === UNMOUNTED) {
|
|
687
|
+
return null;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
var _this$props = this.props,
|
|
691
|
+
children = _this$props.children,
|
|
692
|
+
childProps = _objectWithoutPropertiesLoose(_this$props, ["children"]); // filter props for Transtition
|
|
693
|
+
|
|
694
|
+
|
|
695
|
+
delete childProps.in;
|
|
696
|
+
delete childProps.mountOnEnter;
|
|
697
|
+
delete childProps.unmountOnExit;
|
|
698
|
+
delete childProps.appear;
|
|
699
|
+
delete childProps.enter;
|
|
700
|
+
delete childProps.exit;
|
|
701
|
+
delete childProps.timeout;
|
|
702
|
+
delete childProps.addEndListener;
|
|
703
|
+
delete childProps.onEnter;
|
|
704
|
+
delete childProps.onEntering;
|
|
705
|
+
delete childProps.onEntered;
|
|
706
|
+
delete childProps.onExit;
|
|
707
|
+
delete childProps.onExiting;
|
|
708
|
+
delete childProps.onExited;
|
|
709
|
+
|
|
710
|
+
if (typeof children === 'function') {
|
|
711
|
+
return children(status, childProps);
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
var child = _react$1.default.Children.only(children);
|
|
715
|
+
|
|
716
|
+
return _react$1.default.cloneElement(child, childProps);
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
return Transition;
|
|
720
|
+
}(_react$1.default.Component);
|
|
721
|
+
|
|
722
|
+
Transition.contextTypes = {
|
|
723
|
+
transitionGroup: PropTypes.object
|
|
724
|
+
};
|
|
725
|
+
Transition.childContextTypes = {
|
|
726
|
+
transitionGroup: function transitionGroup() {}
|
|
727
|
+
};
|
|
728
|
+
Transition.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
729
|
+
/**
|
|
730
|
+
* A `function` child can be used instead of a React element. This function is
|
|
731
|
+
* called with the current transition status (`'entering'`, `'entered'`,
|
|
732
|
+
* `'exiting'`, `'exited'`, `'unmounted'`), which can be used to apply context
|
|
733
|
+
* specific props to a component.
|
|
734
|
+
*
|
|
735
|
+
* ```jsx
|
|
736
|
+
* <Transition in={this.state.in} timeout={150}>
|
|
737
|
+
* {state => (
|
|
738
|
+
* <MyComponent className={`fade fade-${state}`} />
|
|
739
|
+
* )}
|
|
740
|
+
* </Transition>
|
|
741
|
+
* ```
|
|
742
|
+
*/
|
|
743
|
+
children: PropTypes.oneOfType([PropTypes.func.isRequired, PropTypes.element.isRequired]).isRequired,
|
|
744
|
+
|
|
745
|
+
/**
|
|
746
|
+
* Show the component; triggers the enter or exit states
|
|
747
|
+
*/
|
|
748
|
+
in: PropTypes.bool,
|
|
749
|
+
|
|
750
|
+
/**
|
|
751
|
+
* By default the child component is mounted immediately along with
|
|
752
|
+
* the parent `Transition` component. If you want to "lazy mount" the component on the
|
|
753
|
+
* first `in={true}` you can set `mountOnEnter`. After the first enter transition the component will stay
|
|
754
|
+
* mounted, even on "exited", unless you also specify `unmountOnExit`.
|
|
755
|
+
*/
|
|
756
|
+
mountOnEnter: PropTypes.bool,
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* By default the child component stays mounted after it reaches the `'exited'` state.
|
|
760
|
+
* Set `unmountOnExit` if you'd prefer to unmount the component after it finishes exiting.
|
|
761
|
+
*/
|
|
762
|
+
unmountOnExit: PropTypes.bool,
|
|
763
|
+
|
|
764
|
+
/**
|
|
765
|
+
* Normally a component is not transitioned if it is shown when the `<Transition>` component mounts.
|
|
766
|
+
* If you want to transition on the first mount set `appear` to `true`, and the
|
|
767
|
+
* component will transition in as soon as the `<Transition>` mounts.
|
|
768
|
+
*
|
|
769
|
+
* > Note: there are no specific "appear" states. `appear` only adds an additional `enter` transition.
|
|
770
|
+
*/
|
|
771
|
+
appear: PropTypes.bool,
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Enable or disable enter transitions.
|
|
775
|
+
*/
|
|
776
|
+
enter: PropTypes.bool,
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* Enable or disable exit transitions.
|
|
780
|
+
*/
|
|
781
|
+
exit: PropTypes.bool,
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* The duration of the transition, in milliseconds.
|
|
785
|
+
* Required unless `addEndListener` is provided.
|
|
786
|
+
*
|
|
787
|
+
* You may specify a single timeout for all transitions:
|
|
788
|
+
*
|
|
789
|
+
* ```jsx
|
|
790
|
+
* timeout={500}
|
|
791
|
+
* ```
|
|
792
|
+
*
|
|
793
|
+
* or individually:
|
|
794
|
+
*
|
|
795
|
+
* ```jsx
|
|
796
|
+
* timeout={{
|
|
797
|
+
* appear: 500,
|
|
798
|
+
* enter: 300,
|
|
799
|
+
* exit: 500,
|
|
800
|
+
* }}
|
|
801
|
+
* ```
|
|
802
|
+
*
|
|
803
|
+
* - `appear` defaults to the value of `enter`
|
|
804
|
+
* - `enter` defaults to `0`
|
|
805
|
+
* - `exit` defaults to `0`
|
|
806
|
+
*
|
|
807
|
+
* @type {number | { enter?: number, exit?: number, appear?: number }}
|
|
808
|
+
*/
|
|
809
|
+
timeout: function timeout(props) {
|
|
810
|
+
var pt = _PropTypes.timeoutsShape;
|
|
811
|
+
if (!props.addEndListener) pt = pt.isRequired;
|
|
812
|
+
|
|
813
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
814
|
+
args[_key - 1] = arguments[_key];
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
return pt.apply(void 0, [props].concat(args));
|
|
818
|
+
},
|
|
819
|
+
|
|
820
|
+
/**
|
|
821
|
+
* Add a custom transition end trigger. Called with the transitioning
|
|
822
|
+
* DOM node and a `done` callback. Allows for more fine grained transition end
|
|
823
|
+
* logic. **Note:** Timeouts are still used as a fallback if provided.
|
|
824
|
+
*
|
|
825
|
+
* ```jsx
|
|
826
|
+
* addEndListener={(node, done) => {
|
|
827
|
+
* // use the css transitionend event to mark the finish of a transition
|
|
828
|
+
* node.addEventListener('transitionend', done, false);
|
|
829
|
+
* }}
|
|
830
|
+
* ```
|
|
831
|
+
*/
|
|
832
|
+
addEndListener: PropTypes.func,
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Callback fired before the "entering" status is applied. An extra parameter
|
|
836
|
+
* `isAppearing` is supplied to indicate if the enter stage is occurring on the initial mount
|
|
837
|
+
*
|
|
838
|
+
* @type Function(node: HtmlElement, isAppearing: bool) -> void
|
|
839
|
+
*/
|
|
840
|
+
onEnter: PropTypes.func,
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Callback fired after the "entering" status is applied. An extra parameter
|
|
844
|
+
* `isAppearing` is supplied to indicate if the enter stage is occurring on the initial mount
|
|
845
|
+
*
|
|
846
|
+
* @type Function(node: HtmlElement, isAppearing: bool)
|
|
847
|
+
*/
|
|
848
|
+
onEntering: PropTypes.func,
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* Callback fired after the "entered" status is applied. An extra parameter
|
|
852
|
+
* `isAppearing` is supplied to indicate if the enter stage is occurring on the initial mount
|
|
853
|
+
*
|
|
854
|
+
* @type Function(node: HtmlElement, isAppearing: bool) -> void
|
|
855
|
+
*/
|
|
856
|
+
onEntered: PropTypes.func,
|
|
857
|
+
|
|
858
|
+
/**
|
|
859
|
+
* Callback fired before the "exiting" status is applied.
|
|
860
|
+
*
|
|
861
|
+
* @type Function(node: HtmlElement) -> void
|
|
862
|
+
*/
|
|
863
|
+
onExit: PropTypes.func,
|
|
864
|
+
|
|
865
|
+
/**
|
|
866
|
+
* Callback fired after the "exiting" status is applied.
|
|
867
|
+
*
|
|
868
|
+
* @type Function(node: HtmlElement) -> void
|
|
869
|
+
*/
|
|
870
|
+
onExiting: PropTypes.func,
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* Callback fired after the "exited" status is applied.
|
|
874
|
+
*
|
|
875
|
+
* @type Function(node: HtmlElement) -> void
|
|
876
|
+
*/
|
|
877
|
+
onExited: PropTypes.func // Name the function so it is clearer in the documentation
|
|
878
|
+
|
|
879
|
+
} : {};
|
|
880
|
+
|
|
881
|
+
function noop() {}
|
|
882
|
+
|
|
883
|
+
Transition.defaultProps = {
|
|
884
|
+
in: false,
|
|
885
|
+
mountOnEnter: false,
|
|
886
|
+
unmountOnExit: false,
|
|
887
|
+
appear: false,
|
|
888
|
+
enter: true,
|
|
889
|
+
exit: true,
|
|
890
|
+
onEnter: noop,
|
|
891
|
+
onEntering: noop,
|
|
892
|
+
onEntered: noop,
|
|
893
|
+
onExit: noop,
|
|
894
|
+
onExiting: noop,
|
|
895
|
+
onExited: noop
|
|
896
|
+
};
|
|
897
|
+
Transition.UNMOUNTED = 0;
|
|
898
|
+
Transition.EXITED = 1;
|
|
899
|
+
Transition.ENTERING = 2;
|
|
900
|
+
Transition.ENTERED = 3;
|
|
901
|
+
Transition.EXITING = 4;
|
|
902
|
+
|
|
903
|
+
var _default = (0, _reactLifecyclesCompat.polyfill)(Transition);
|
|
904
|
+
|
|
905
|
+
Transition$1.default = _default;
|
|
906
|
+
|
|
907
|
+
(function (module, exports) {
|
|
908
|
+
|
|
909
|
+
exports.__esModule = true;
|
|
910
|
+
exports.default = void 0;
|
|
911
|
+
|
|
912
|
+
var PropTypes = _interopRequireWildcard(PropTypes$2);
|
|
913
|
+
|
|
914
|
+
var _addClass = _interopRequireDefault(addClass.exports);
|
|
915
|
+
|
|
916
|
+
var _removeClass = _interopRequireDefault(removeClass);
|
|
917
|
+
|
|
918
|
+
var _react = _interopRequireDefault(React);
|
|
919
|
+
|
|
920
|
+
var _Transition = _interopRequireDefault(Transition$1);
|
|
921
|
+
|
|
922
|
+
var _PropTypes = PropTypes$1;
|
|
923
|
+
|
|
924
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
925
|
+
|
|
926
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
|
927
|
+
|
|
928
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
929
|
+
|
|
930
|
+
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
|
931
|
+
|
|
932
|
+
var addClass$1 = function addClass(node, classes) {
|
|
933
|
+
return node && classes && classes.split(' ').forEach(function (c) {
|
|
934
|
+
return (0, _addClass.default)(node, c);
|
|
935
|
+
});
|
|
936
|
+
};
|
|
937
|
+
|
|
938
|
+
var removeClass$1 = function removeClass(node, classes) {
|
|
939
|
+
return node && classes && classes.split(' ').forEach(function (c) {
|
|
940
|
+
return (0, _removeClass.default)(node, c);
|
|
941
|
+
});
|
|
942
|
+
};
|
|
943
|
+
/**
|
|
944
|
+
* A transition component inspired by the excellent
|
|
945
|
+
* [ng-animate](http://www.nganimate.org/) library, you should use it if you're
|
|
946
|
+
* using CSS transitions or animations. It's built upon the
|
|
947
|
+
* [`Transition`](https://reactcommunity.org/react-transition-group/transition)
|
|
948
|
+
* component, so it inherits all of its props.
|
|
949
|
+
*
|
|
950
|
+
* `CSSTransition` applies a pair of class names during the `appear`, `enter`,
|
|
951
|
+
* and `exit` states of the transition. The first class is applied and then a
|
|
952
|
+
* second `*-active` class in order to activate the CSSS transition. After the
|
|
953
|
+
* transition, matching `*-done` class names are applied to persist the
|
|
954
|
+
* transition state.
|
|
955
|
+
*
|
|
956
|
+
* ```jsx
|
|
957
|
+
* function App() {
|
|
958
|
+
* const [inProp, setInProp] = useState(false);
|
|
959
|
+
* return (
|
|
960
|
+
* <div>
|
|
961
|
+
* <CSSTransition in={inProp} timeout={200} classNames="my-node">
|
|
962
|
+
* <div>
|
|
963
|
+
* {"I'll receive my-node-* classes"}
|
|
964
|
+
* </div>
|
|
965
|
+
* </CSSTransition>
|
|
966
|
+
* <button type="button" onClick={() => setInProp(true)}>
|
|
967
|
+
* Click to Enter
|
|
968
|
+
* </button>
|
|
969
|
+
* </div>
|
|
970
|
+
* );
|
|
971
|
+
* }
|
|
972
|
+
* ```
|
|
973
|
+
*
|
|
974
|
+
* When the `in` prop is set to `true`, the child component will first receive
|
|
975
|
+
* the class `example-enter`, then the `example-enter-active` will be added in
|
|
976
|
+
* the next tick. `CSSTransition` [forces a
|
|
977
|
+
* reflow](https://github.com/reactjs/react-transition-group/blob/5007303e729a74be66a21c3e2205e4916821524b/src/CSSTransition.js#L208-L215)
|
|
978
|
+
* between before adding the `example-enter-active`. This is an important trick
|
|
979
|
+
* because it allows us to transition between `example-enter` and
|
|
980
|
+
* `example-enter-active` even though they were added immediately one after
|
|
981
|
+
* another. Most notably, this is what makes it possible for us to animate
|
|
982
|
+
* _appearance_.
|
|
983
|
+
*
|
|
984
|
+
* ```css
|
|
985
|
+
* .my-node-enter {
|
|
986
|
+
* opacity: 0;
|
|
987
|
+
* }
|
|
988
|
+
* .my-node-enter-active {
|
|
989
|
+
* opacity: 1;
|
|
990
|
+
* transition: opacity 200ms;
|
|
991
|
+
* }
|
|
992
|
+
* .my-node-exit {
|
|
993
|
+
* opacity: 1;
|
|
994
|
+
* }
|
|
995
|
+
* .my-node-exit-active {
|
|
996
|
+
* opacity: 0;
|
|
997
|
+
* transition: opacity: 200ms;
|
|
998
|
+
* }
|
|
999
|
+
* ```
|
|
1000
|
+
*
|
|
1001
|
+
* `*-active` classes represent which styles you want to animate **to**.
|
|
1002
|
+
*/
|
|
1003
|
+
|
|
1004
|
+
|
|
1005
|
+
var CSSTransition =
|
|
1006
|
+
/*#__PURE__*/
|
|
1007
|
+
function (_React$Component) {
|
|
1008
|
+
_inheritsLoose(CSSTransition, _React$Component);
|
|
1009
|
+
|
|
1010
|
+
function CSSTransition() {
|
|
1011
|
+
var _this;
|
|
1012
|
+
|
|
1013
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1014
|
+
args[_key] = arguments[_key];
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
_this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
|
|
1018
|
+
|
|
1019
|
+
_this.onEnter = function (node, appearing) {
|
|
1020
|
+
var _this$getClassNames = _this.getClassNames(appearing ? 'appear' : 'enter'),
|
|
1021
|
+
className = _this$getClassNames.className;
|
|
1022
|
+
|
|
1023
|
+
_this.removeClasses(node, 'exit');
|
|
1024
|
+
|
|
1025
|
+
addClass$1(node, className);
|
|
1026
|
+
|
|
1027
|
+
if (_this.props.onEnter) {
|
|
1028
|
+
_this.props.onEnter(node, appearing);
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
_this.onEntering = function (node, appearing) {
|
|
1033
|
+
var _this$getClassNames2 = _this.getClassNames(appearing ? 'appear' : 'enter'),
|
|
1034
|
+
activeClassName = _this$getClassNames2.activeClassName;
|
|
1035
|
+
|
|
1036
|
+
_this.reflowAndAddClass(node, activeClassName);
|
|
1037
|
+
|
|
1038
|
+
if (_this.props.onEntering) {
|
|
1039
|
+
_this.props.onEntering(node, appearing);
|
|
1040
|
+
}
|
|
1041
|
+
};
|
|
1042
|
+
|
|
1043
|
+
_this.onEntered = function (node, appearing) {
|
|
1044
|
+
var appearClassName = _this.getClassNames('appear').doneClassName;
|
|
1045
|
+
|
|
1046
|
+
var enterClassName = _this.getClassNames('enter').doneClassName;
|
|
1047
|
+
|
|
1048
|
+
var doneClassName = appearing ? appearClassName + " " + enterClassName : enterClassName;
|
|
1049
|
+
|
|
1050
|
+
_this.removeClasses(node, appearing ? 'appear' : 'enter');
|
|
1051
|
+
|
|
1052
|
+
addClass$1(node, doneClassName);
|
|
1053
|
+
|
|
1054
|
+
if (_this.props.onEntered) {
|
|
1055
|
+
_this.props.onEntered(node, appearing);
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
|
|
1059
|
+
_this.onExit = function (node) {
|
|
1060
|
+
var _this$getClassNames3 = _this.getClassNames('exit'),
|
|
1061
|
+
className = _this$getClassNames3.className;
|
|
1062
|
+
|
|
1063
|
+
_this.removeClasses(node, 'appear');
|
|
1064
|
+
|
|
1065
|
+
_this.removeClasses(node, 'enter');
|
|
1066
|
+
|
|
1067
|
+
addClass$1(node, className);
|
|
1068
|
+
|
|
1069
|
+
if (_this.props.onExit) {
|
|
1070
|
+
_this.props.onExit(node);
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
_this.onExiting = function (node) {
|
|
1075
|
+
var _this$getClassNames4 = _this.getClassNames('exit'),
|
|
1076
|
+
activeClassName = _this$getClassNames4.activeClassName;
|
|
1077
|
+
|
|
1078
|
+
_this.reflowAndAddClass(node, activeClassName);
|
|
1079
|
+
|
|
1080
|
+
if (_this.props.onExiting) {
|
|
1081
|
+
_this.props.onExiting(node);
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
|
|
1085
|
+
_this.onExited = function (node) {
|
|
1086
|
+
var _this$getClassNames5 = _this.getClassNames('exit'),
|
|
1087
|
+
doneClassName = _this$getClassNames5.doneClassName;
|
|
1088
|
+
|
|
1089
|
+
_this.removeClasses(node, 'exit');
|
|
1090
|
+
|
|
1091
|
+
addClass$1(node, doneClassName);
|
|
1092
|
+
|
|
1093
|
+
if (_this.props.onExited) {
|
|
1094
|
+
_this.props.onExited(node);
|
|
1095
|
+
}
|
|
1096
|
+
};
|
|
1097
|
+
|
|
1098
|
+
_this.getClassNames = function (type) {
|
|
1099
|
+
var classNames = _this.props.classNames;
|
|
1100
|
+
var isStringClassNames = typeof classNames === 'string';
|
|
1101
|
+
var prefix = isStringClassNames && classNames ? classNames + '-' : '';
|
|
1102
|
+
var className = isStringClassNames ? prefix + type : classNames[type];
|
|
1103
|
+
var activeClassName = isStringClassNames ? className + '-active' : classNames[type + 'Active'];
|
|
1104
|
+
var doneClassName = isStringClassNames ? className + '-done' : classNames[type + 'Done'];
|
|
1105
|
+
return {
|
|
1106
|
+
className: className,
|
|
1107
|
+
activeClassName: activeClassName,
|
|
1108
|
+
doneClassName: doneClassName
|
|
1109
|
+
};
|
|
1110
|
+
};
|
|
1111
|
+
|
|
1112
|
+
return _this;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
var _proto = CSSTransition.prototype;
|
|
1116
|
+
|
|
1117
|
+
_proto.removeClasses = function removeClasses(node, type) {
|
|
1118
|
+
var _this$getClassNames6 = this.getClassNames(type),
|
|
1119
|
+
className = _this$getClassNames6.className,
|
|
1120
|
+
activeClassName = _this$getClassNames6.activeClassName,
|
|
1121
|
+
doneClassName = _this$getClassNames6.doneClassName;
|
|
1122
|
+
|
|
1123
|
+
className && removeClass$1(node, className);
|
|
1124
|
+
activeClassName && removeClass$1(node, activeClassName);
|
|
1125
|
+
doneClassName && removeClass$1(node, doneClassName);
|
|
1126
|
+
};
|
|
1127
|
+
|
|
1128
|
+
_proto.reflowAndAddClass = function reflowAndAddClass(node, className) {
|
|
1129
|
+
// This is for to force a repaint,
|
|
1130
|
+
// which is necessary in order to transition styles when adding a class name.
|
|
1131
|
+
if (className) {
|
|
1132
|
+
/* eslint-disable no-unused-expressions */
|
|
1133
|
+
node && node.scrollTop;
|
|
1134
|
+
/* eslint-enable no-unused-expressions */
|
|
1135
|
+
|
|
1136
|
+
addClass$1(node, className);
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
|
|
1140
|
+
_proto.render = function render() {
|
|
1141
|
+
var props = _extends({}, this.props);
|
|
1142
|
+
|
|
1143
|
+
delete props.classNames;
|
|
1144
|
+
return _react.default.createElement(_Transition.default, _extends({}, props, {
|
|
1145
|
+
onEnter: this.onEnter,
|
|
1146
|
+
onEntered: this.onEntered,
|
|
1147
|
+
onEntering: this.onEntering,
|
|
1148
|
+
onExit: this.onExit,
|
|
1149
|
+
onExiting: this.onExiting,
|
|
1150
|
+
onExited: this.onExited
|
|
1151
|
+
}));
|
|
1152
|
+
};
|
|
1153
|
+
|
|
1154
|
+
return CSSTransition;
|
|
1155
|
+
}(_react.default.Component);
|
|
1156
|
+
|
|
1157
|
+
CSSTransition.defaultProps = {
|
|
1158
|
+
classNames: ''
|
|
1159
|
+
};
|
|
1160
|
+
CSSTransition.propTypes = process.env.NODE_ENV !== "production" ? _extends({}, _Transition.default.propTypes, {
|
|
1161
|
+
/**
|
|
1162
|
+
* The animation classNames applied to the component as it enters, exits or
|
|
1163
|
+
* has finished the transition. A single name can be provided and it will be
|
|
1164
|
+
* suffixed for each stage: e.g.
|
|
1165
|
+
*
|
|
1166
|
+
* `classNames="fade"` applies `fade-enter`, `fade-enter-active`,
|
|
1167
|
+
* `fade-enter-done`, `fade-exit`, `fade-exit-active`, `fade-exit-done`,
|
|
1168
|
+
* `fade-appear`, `fade-appear-active`, and `fade-appear-done`.
|
|
1169
|
+
*
|
|
1170
|
+
* **Note**: `fade-appear-done` and `fade-enter-done` will _both_ be applied.
|
|
1171
|
+
* This allows you to define different behavior for when appearing is done and
|
|
1172
|
+
* when regular entering is done, using selectors like
|
|
1173
|
+
* `.fade-enter-done:not(.fade-appear-done)`. For example, you could apply an
|
|
1174
|
+
* epic entrance animation when element first appears in the DOM using
|
|
1175
|
+
* [Animate.css](https://daneden.github.io/animate.css/). Otherwise you can
|
|
1176
|
+
* simply use `fade-enter-done` for defining both cases.
|
|
1177
|
+
*
|
|
1178
|
+
* Each individual classNames can also be specified independently like:
|
|
1179
|
+
*
|
|
1180
|
+
* ```js
|
|
1181
|
+
* classNames={{
|
|
1182
|
+
* appear: 'my-appear',
|
|
1183
|
+
* appearActive: 'my-active-appear',
|
|
1184
|
+
* appearDone: 'my-done-appear',
|
|
1185
|
+
* enter: 'my-enter',
|
|
1186
|
+
* enterActive: 'my-active-enter',
|
|
1187
|
+
* enterDone: 'my-done-enter',
|
|
1188
|
+
* exit: 'my-exit',
|
|
1189
|
+
* exitActive: 'my-active-exit',
|
|
1190
|
+
* exitDone: 'my-done-exit',
|
|
1191
|
+
* }}
|
|
1192
|
+
* ```
|
|
1193
|
+
*
|
|
1194
|
+
* If you want to set these classes using CSS Modules:
|
|
1195
|
+
*
|
|
1196
|
+
* ```js
|
|
1197
|
+
* import styles from './styles.css';
|
|
1198
|
+
* ```
|
|
1199
|
+
*
|
|
1200
|
+
* you might want to use camelCase in your CSS file, that way could simply
|
|
1201
|
+
* spread them instead of listing them one by one:
|
|
1202
|
+
*
|
|
1203
|
+
* ```js
|
|
1204
|
+
* classNames={{ ...styles }}
|
|
1205
|
+
* ```
|
|
1206
|
+
*
|
|
1207
|
+
* @type {string | {
|
|
1208
|
+
* appear?: string,
|
|
1209
|
+
* appearActive?: string,
|
|
1210
|
+
* appearDone?: string,
|
|
1211
|
+
* enter?: string,
|
|
1212
|
+
* enterActive?: string,
|
|
1213
|
+
* enterDone?: string,
|
|
1214
|
+
* exit?: string,
|
|
1215
|
+
* exitActive?: string,
|
|
1216
|
+
* exitDone?: string,
|
|
1217
|
+
* }}
|
|
1218
|
+
*/
|
|
1219
|
+
classNames: _PropTypes.classNamesShape,
|
|
1220
|
+
|
|
1221
|
+
/**
|
|
1222
|
+
* A `<Transition>` callback fired immediately after the 'enter' or 'appear' class is
|
|
1223
|
+
* applied.
|
|
1224
|
+
*
|
|
1225
|
+
* @type Function(node: HtmlElement, isAppearing: bool)
|
|
1226
|
+
*/
|
|
1227
|
+
onEnter: PropTypes.func,
|
|
1228
|
+
|
|
1229
|
+
/**
|
|
1230
|
+
* A `<Transition>` callback fired immediately after the 'enter-active' or
|
|
1231
|
+
* 'appear-active' class is applied.
|
|
1232
|
+
*
|
|
1233
|
+
* @type Function(node: HtmlElement, isAppearing: bool)
|
|
1234
|
+
*/
|
|
1235
|
+
onEntering: PropTypes.func,
|
|
1236
|
+
|
|
1237
|
+
/**
|
|
1238
|
+
* A `<Transition>` callback fired immediately after the 'enter' or
|
|
1239
|
+
* 'appear' classes are **removed** and the `done` class is added to the DOM node.
|
|
1240
|
+
*
|
|
1241
|
+
* @type Function(node: HtmlElement, isAppearing: bool)
|
|
1242
|
+
*/
|
|
1243
|
+
onEntered: PropTypes.func,
|
|
1244
|
+
|
|
1245
|
+
/**
|
|
1246
|
+
* A `<Transition>` callback fired immediately after the 'exit' class is
|
|
1247
|
+
* applied.
|
|
1248
|
+
*
|
|
1249
|
+
* @type Function(node: HtmlElement)
|
|
1250
|
+
*/
|
|
1251
|
+
onExit: PropTypes.func,
|
|
1252
|
+
|
|
1253
|
+
/**
|
|
1254
|
+
* A `<Transition>` callback fired immediately after the 'exit-active' is applied.
|
|
1255
|
+
*
|
|
1256
|
+
* @type Function(node: HtmlElement)
|
|
1257
|
+
*/
|
|
1258
|
+
onExiting: PropTypes.func,
|
|
1259
|
+
|
|
1260
|
+
/**
|
|
1261
|
+
* A `<Transition>` callback fired immediately after the 'exit' classes
|
|
1262
|
+
* are **removed** and the `exit-done` class is added to the DOM node.
|
|
1263
|
+
*
|
|
1264
|
+
* @type Function(node: HtmlElement)
|
|
1265
|
+
*/
|
|
1266
|
+
onExited: PropTypes.func
|
|
1267
|
+
}) : {};
|
|
1268
|
+
var _default = CSSTransition;
|
|
1269
|
+
exports.default = _default;
|
|
1270
|
+
module.exports = exports["default"];
|
|
1271
|
+
}(CSSTransition, CSSTransition.exports));
|
|
1272
|
+
|
|
1273
|
+
var ReplaceTransition = {exports: {}};
|
|
1274
|
+
|
|
1275
|
+
var TransitionGroup = {exports: {}};
|
|
1276
|
+
|
|
1277
|
+
var ChildMapping = {};
|
|
1278
|
+
|
|
1279
|
+
ChildMapping.__esModule = true;
|
|
1280
|
+
ChildMapping.getChildMapping = getChildMapping;
|
|
1281
|
+
ChildMapping.mergeChildMappings = mergeChildMappings;
|
|
1282
|
+
ChildMapping.getInitialChildMapping = getInitialChildMapping;
|
|
1283
|
+
ChildMapping.getNextChildMapping = getNextChildMapping;
|
|
1284
|
+
|
|
1285
|
+
var _react = React;
|
|
1286
|
+
|
|
1287
|
+
/**
|
|
1288
|
+
* Given `this.props.children`, return an object mapping key to child.
|
|
1289
|
+
*
|
|
1290
|
+
* @param {*} children `this.props.children`
|
|
1291
|
+
* @return {object} Mapping of key to child
|
|
1292
|
+
*/
|
|
1293
|
+
function getChildMapping(children, mapFn) {
|
|
1294
|
+
var mapper = function mapper(child) {
|
|
1295
|
+
return mapFn && (0, _react.isValidElement)(child) ? mapFn(child) : child;
|
|
1296
|
+
};
|
|
1297
|
+
|
|
1298
|
+
var result = Object.create(null);
|
|
1299
|
+
if (children) _react.Children.map(children, function (c) {
|
|
1300
|
+
return c;
|
|
1301
|
+
}).forEach(function (child) {
|
|
1302
|
+
// run the map function here instead so that the key is the computed one
|
|
1303
|
+
result[child.key] = mapper(child);
|
|
1304
|
+
});
|
|
1305
|
+
return result;
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* When you're adding or removing children some may be added or removed in the
|
|
1309
|
+
* same render pass. We want to show *both* since we want to simultaneously
|
|
1310
|
+
* animate elements in and out. This function takes a previous set of keys
|
|
1311
|
+
* and a new set of keys and merges them with its best guess of the correct
|
|
1312
|
+
* ordering. In the future we may expose some of the utilities in
|
|
1313
|
+
* ReactMultiChild to make this easy, but for now React itself does not
|
|
1314
|
+
* directly have this concept of the union of prevChildren and nextChildren
|
|
1315
|
+
* so we implement it here.
|
|
1316
|
+
*
|
|
1317
|
+
* @param {object} prev prev children as returned from
|
|
1318
|
+
* `ReactTransitionChildMapping.getChildMapping()`.
|
|
1319
|
+
* @param {object} next next children as returned from
|
|
1320
|
+
* `ReactTransitionChildMapping.getChildMapping()`.
|
|
1321
|
+
* @return {object} a key set that contains all keys in `prev` and all keys
|
|
1322
|
+
* in `next` in a reasonable order.
|
|
1323
|
+
*/
|
|
1324
|
+
|
|
1325
|
+
|
|
1326
|
+
function mergeChildMappings(prev, next) {
|
|
1327
|
+
prev = prev || {};
|
|
1328
|
+
next = next || {};
|
|
1329
|
+
|
|
1330
|
+
function getValueForKey(key) {
|
|
1331
|
+
return key in next ? next[key] : prev[key];
|
|
1332
|
+
} // For each key of `next`, the list of keys to insert before that key in
|
|
1333
|
+
// the combined list
|
|
1334
|
+
|
|
1335
|
+
|
|
1336
|
+
var nextKeysPending = Object.create(null);
|
|
1337
|
+
var pendingKeys = [];
|
|
1338
|
+
|
|
1339
|
+
for (var prevKey in prev) {
|
|
1340
|
+
if (prevKey in next) {
|
|
1341
|
+
if (pendingKeys.length) {
|
|
1342
|
+
nextKeysPending[prevKey] = pendingKeys;
|
|
1343
|
+
pendingKeys = [];
|
|
1344
|
+
}
|
|
1345
|
+
} else {
|
|
1346
|
+
pendingKeys.push(prevKey);
|
|
1347
|
+
}
|
|
1348
|
+
}
|
|
1349
|
+
|
|
1350
|
+
var i;
|
|
1351
|
+
var childMapping = {};
|
|
1352
|
+
|
|
1353
|
+
for (var nextKey in next) {
|
|
1354
|
+
if (nextKeysPending[nextKey]) {
|
|
1355
|
+
for (i = 0; i < nextKeysPending[nextKey].length; i++) {
|
|
1356
|
+
var pendingNextKey = nextKeysPending[nextKey][i];
|
|
1357
|
+
childMapping[nextKeysPending[nextKey][i]] = getValueForKey(pendingNextKey);
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
childMapping[nextKey] = getValueForKey(nextKey);
|
|
1362
|
+
} // Finally, add the keys which didn't appear before any key in `next`
|
|
1363
|
+
|
|
1364
|
+
|
|
1365
|
+
for (i = 0; i < pendingKeys.length; i++) {
|
|
1366
|
+
childMapping[pendingKeys[i]] = getValueForKey(pendingKeys[i]);
|
|
1367
|
+
}
|
|
1368
|
+
|
|
1369
|
+
return childMapping;
|
|
1370
|
+
}
|
|
1371
|
+
|
|
1372
|
+
function getProp(child, prop, props) {
|
|
1373
|
+
return props[prop] != null ? props[prop] : child.props[prop];
|
|
1374
|
+
}
|
|
1375
|
+
|
|
1376
|
+
function getInitialChildMapping(props, onExited) {
|
|
1377
|
+
return getChildMapping(props.children, function (child) {
|
|
1378
|
+
return (0, _react.cloneElement)(child, {
|
|
1379
|
+
onExited: onExited.bind(null, child),
|
|
1380
|
+
in: true,
|
|
1381
|
+
appear: getProp(child, 'appear', props),
|
|
1382
|
+
enter: getProp(child, 'enter', props),
|
|
1383
|
+
exit: getProp(child, 'exit', props)
|
|
1384
|
+
});
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
|
|
1388
|
+
function getNextChildMapping(nextProps, prevChildMapping, onExited) {
|
|
1389
|
+
var nextChildMapping = getChildMapping(nextProps.children);
|
|
1390
|
+
var children = mergeChildMappings(prevChildMapping, nextChildMapping);
|
|
1391
|
+
Object.keys(children).forEach(function (key) {
|
|
1392
|
+
var child = children[key];
|
|
1393
|
+
if (!(0, _react.isValidElement)(child)) return;
|
|
1394
|
+
var hasPrev = key in prevChildMapping;
|
|
1395
|
+
var hasNext = key in nextChildMapping;
|
|
1396
|
+
var prevChild = prevChildMapping[key];
|
|
1397
|
+
var isLeaving = (0, _react.isValidElement)(prevChild) && !prevChild.props.in; // item is new (entering)
|
|
1398
|
+
|
|
1399
|
+
if (hasNext && (!hasPrev || isLeaving)) {
|
|
1400
|
+
// console.log('entering', key)
|
|
1401
|
+
children[key] = (0, _react.cloneElement)(child, {
|
|
1402
|
+
onExited: onExited.bind(null, child),
|
|
1403
|
+
in: true,
|
|
1404
|
+
exit: getProp(child, 'exit', nextProps),
|
|
1405
|
+
enter: getProp(child, 'enter', nextProps)
|
|
1406
|
+
});
|
|
1407
|
+
} else if (!hasNext && hasPrev && !isLeaving) {
|
|
1408
|
+
// item is old (exiting)
|
|
1409
|
+
// console.log('leaving', key)
|
|
1410
|
+
children[key] = (0, _react.cloneElement)(child, {
|
|
1411
|
+
in: false
|
|
1412
|
+
});
|
|
1413
|
+
} else if (hasNext && hasPrev && (0, _react.isValidElement)(prevChild)) {
|
|
1414
|
+
// item hasn't changed transition states
|
|
1415
|
+
// copy over the last transition props;
|
|
1416
|
+
// console.log('unchanged', key)
|
|
1417
|
+
children[key] = (0, _react.cloneElement)(child, {
|
|
1418
|
+
onExited: onExited.bind(null, child),
|
|
1419
|
+
in: prevChild.props.in,
|
|
1420
|
+
exit: getProp(child, 'exit', nextProps),
|
|
1421
|
+
enter: getProp(child, 'enter', nextProps)
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
});
|
|
1425
|
+
return children;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
(function (module, exports) {
|
|
1429
|
+
|
|
1430
|
+
exports.__esModule = true;
|
|
1431
|
+
exports.default = void 0;
|
|
1432
|
+
|
|
1433
|
+
var _propTypes = _interopRequireDefault(PropTypes$2);
|
|
1434
|
+
|
|
1435
|
+
var _react = _interopRequireDefault(React);
|
|
1436
|
+
|
|
1437
|
+
var _reactLifecyclesCompat = require$$2;
|
|
1438
|
+
|
|
1439
|
+
var _ChildMapping = ChildMapping;
|
|
1440
|
+
|
|
1441
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1442
|
+
|
|
1443
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
1444
|
+
|
|
1445
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
1446
|
+
|
|
1447
|
+
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
|
1448
|
+
|
|
1449
|
+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
1450
|
+
|
|
1451
|
+
var values = Object.values || function (obj) {
|
|
1452
|
+
return Object.keys(obj).map(function (k) {
|
|
1453
|
+
return obj[k];
|
|
1454
|
+
});
|
|
1455
|
+
};
|
|
1456
|
+
|
|
1457
|
+
var defaultProps = {
|
|
1458
|
+
component: 'div',
|
|
1459
|
+
childFactory: function childFactory(child) {
|
|
1460
|
+
return child;
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* The `<TransitionGroup>` component manages a set of transition components
|
|
1464
|
+
* (`<Transition>` and `<CSSTransition>`) in a list. Like with the transition
|
|
1465
|
+
* components, `<TransitionGroup>` is a state machine for managing the mounting
|
|
1466
|
+
* and unmounting of components over time.
|
|
1467
|
+
*
|
|
1468
|
+
* Consider the example below. As items are removed or added to the TodoList the
|
|
1469
|
+
* `in` prop is toggled automatically by the `<TransitionGroup>`.
|
|
1470
|
+
*
|
|
1471
|
+
* Note that `<TransitionGroup>` does not define any animation behavior!
|
|
1472
|
+
* Exactly _how_ a list item animates is up to the individual transition
|
|
1473
|
+
* component. This means you can mix and match animations across different list
|
|
1474
|
+
* items.
|
|
1475
|
+
*/
|
|
1476
|
+
|
|
1477
|
+
};
|
|
1478
|
+
|
|
1479
|
+
var TransitionGroup =
|
|
1480
|
+
/*#__PURE__*/
|
|
1481
|
+
function (_React$Component) {
|
|
1482
|
+
_inheritsLoose(TransitionGroup, _React$Component);
|
|
1483
|
+
|
|
1484
|
+
function TransitionGroup(props, context) {
|
|
1485
|
+
var _this;
|
|
1486
|
+
|
|
1487
|
+
_this = _React$Component.call(this, props, context) || this;
|
|
1488
|
+
|
|
1489
|
+
var handleExited = _this.handleExited.bind(_assertThisInitialized(_assertThisInitialized(_this))); // Initial children should all be entering, dependent on appear
|
|
1490
|
+
|
|
1491
|
+
|
|
1492
|
+
_this.state = {
|
|
1493
|
+
handleExited: handleExited,
|
|
1494
|
+
firstRender: true
|
|
1495
|
+
};
|
|
1496
|
+
return _this;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
var _proto = TransitionGroup.prototype;
|
|
1500
|
+
|
|
1501
|
+
_proto.getChildContext = function getChildContext() {
|
|
1502
|
+
return {
|
|
1503
|
+
transitionGroup: {
|
|
1504
|
+
isMounting: !this.appeared
|
|
1505
|
+
}
|
|
1506
|
+
};
|
|
1507
|
+
};
|
|
1508
|
+
|
|
1509
|
+
_proto.componentDidMount = function componentDidMount() {
|
|
1510
|
+
this.appeared = true;
|
|
1511
|
+
this.mounted = true;
|
|
1512
|
+
};
|
|
1513
|
+
|
|
1514
|
+
_proto.componentWillUnmount = function componentWillUnmount() {
|
|
1515
|
+
this.mounted = false;
|
|
1516
|
+
};
|
|
1517
|
+
|
|
1518
|
+
TransitionGroup.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, _ref) {
|
|
1519
|
+
var prevChildMapping = _ref.children,
|
|
1520
|
+
handleExited = _ref.handleExited,
|
|
1521
|
+
firstRender = _ref.firstRender;
|
|
1522
|
+
return {
|
|
1523
|
+
children: firstRender ? (0, _ChildMapping.getInitialChildMapping)(nextProps, handleExited) : (0, _ChildMapping.getNextChildMapping)(nextProps, prevChildMapping, handleExited),
|
|
1524
|
+
firstRender: false
|
|
1525
|
+
};
|
|
1526
|
+
};
|
|
1527
|
+
|
|
1528
|
+
_proto.handleExited = function handleExited(child, node) {
|
|
1529
|
+
var currentChildMapping = (0, _ChildMapping.getChildMapping)(this.props.children);
|
|
1530
|
+
if (child.key in currentChildMapping) return;
|
|
1531
|
+
|
|
1532
|
+
if (child.props.onExited) {
|
|
1533
|
+
child.props.onExited(node);
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
if (this.mounted) {
|
|
1537
|
+
this.setState(function (state) {
|
|
1538
|
+
var children = _extends({}, state.children);
|
|
1539
|
+
|
|
1540
|
+
delete children[child.key];
|
|
1541
|
+
return {
|
|
1542
|
+
children: children
|
|
1543
|
+
};
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
};
|
|
1547
|
+
|
|
1548
|
+
_proto.render = function render() {
|
|
1549
|
+
var _this$props = this.props,
|
|
1550
|
+
Component = _this$props.component,
|
|
1551
|
+
childFactory = _this$props.childFactory,
|
|
1552
|
+
props = _objectWithoutPropertiesLoose(_this$props, ["component", "childFactory"]);
|
|
1553
|
+
|
|
1554
|
+
var children = values(this.state.children).map(childFactory);
|
|
1555
|
+
delete props.appear;
|
|
1556
|
+
delete props.enter;
|
|
1557
|
+
delete props.exit;
|
|
1558
|
+
|
|
1559
|
+
if (Component === null) {
|
|
1560
|
+
return children;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
return _react.default.createElement(Component, props, children);
|
|
1564
|
+
};
|
|
1565
|
+
|
|
1566
|
+
return TransitionGroup;
|
|
1567
|
+
}(_react.default.Component);
|
|
1568
|
+
|
|
1569
|
+
TransitionGroup.childContextTypes = {
|
|
1570
|
+
transitionGroup: _propTypes.default.object.isRequired
|
|
1571
|
+
};
|
|
1572
|
+
TransitionGroup.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
1573
|
+
/**
|
|
1574
|
+
* `<TransitionGroup>` renders a `<div>` by default. You can change this
|
|
1575
|
+
* behavior by providing a `component` prop.
|
|
1576
|
+
* If you use React v16+ and would like to avoid a wrapping `<div>` element
|
|
1577
|
+
* you can pass in `component={null}`. This is useful if the wrapping div
|
|
1578
|
+
* borks your css styles.
|
|
1579
|
+
*/
|
|
1580
|
+
component: _propTypes.default.any,
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* A set of `<Transition>` components, that are toggled `in` and out as they
|
|
1584
|
+
* leave. the `<TransitionGroup>` will inject specific transition props, so
|
|
1585
|
+
* remember to spread them through if you are wrapping the `<Transition>` as
|
|
1586
|
+
* with our `<Fade>` example.
|
|
1587
|
+
*
|
|
1588
|
+
* While this component is meant for multiple `Transition` or `CSSTransition`
|
|
1589
|
+
* children, sometimes you may want to have a single transition child with
|
|
1590
|
+
* content that you want to be transitioned out and in when you change it
|
|
1591
|
+
* (e.g. routes, images etc.) In that case you can change the `key` prop of
|
|
1592
|
+
* the transition child as you change its content, this will cause
|
|
1593
|
+
* `TransitionGroup` to transition the child out and back in.
|
|
1594
|
+
*/
|
|
1595
|
+
children: _propTypes.default.node,
|
|
1596
|
+
|
|
1597
|
+
/**
|
|
1598
|
+
* A convenience prop that enables or disables appear animations
|
|
1599
|
+
* for all children. Note that specifying this will override any defaults set
|
|
1600
|
+
* on individual children Transitions.
|
|
1601
|
+
*/
|
|
1602
|
+
appear: _propTypes.default.bool,
|
|
1603
|
+
|
|
1604
|
+
/**
|
|
1605
|
+
* A convenience prop that enables or disables enter animations
|
|
1606
|
+
* for all children. Note that specifying this will override any defaults set
|
|
1607
|
+
* on individual children Transitions.
|
|
1608
|
+
*/
|
|
1609
|
+
enter: _propTypes.default.bool,
|
|
1610
|
+
|
|
1611
|
+
/**
|
|
1612
|
+
* A convenience prop that enables or disables exit animations
|
|
1613
|
+
* for all children. Note that specifying this will override any defaults set
|
|
1614
|
+
* on individual children Transitions.
|
|
1615
|
+
*/
|
|
1616
|
+
exit: _propTypes.default.bool,
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* You may need to apply reactive updates to a child as it is exiting.
|
|
1620
|
+
* This is generally done by using `cloneElement` however in the case of an exiting
|
|
1621
|
+
* child the element has already been removed and not accessible to the consumer.
|
|
1622
|
+
*
|
|
1623
|
+
* If you do need to update a child as it leaves you can provide a `childFactory`
|
|
1624
|
+
* to wrap every child, even the ones that are leaving.
|
|
1625
|
+
*
|
|
1626
|
+
* @type Function(child: ReactElement) -> ReactElement
|
|
1627
|
+
*/
|
|
1628
|
+
childFactory: _propTypes.default.func
|
|
1629
|
+
} : {};
|
|
1630
|
+
TransitionGroup.defaultProps = defaultProps;
|
|
1631
|
+
|
|
1632
|
+
var _default = (0, _reactLifecyclesCompat.polyfill)(TransitionGroup);
|
|
1633
|
+
|
|
1634
|
+
exports.default = _default;
|
|
1635
|
+
module.exports = exports["default"];
|
|
1636
|
+
}(TransitionGroup, TransitionGroup.exports));
|
|
1637
|
+
|
|
1638
|
+
(function (module, exports) {
|
|
1639
|
+
|
|
1640
|
+
exports.__esModule = true;
|
|
1641
|
+
exports.default = void 0;
|
|
1642
|
+
|
|
1643
|
+
var _propTypes = _interopRequireDefault(PropTypes$2);
|
|
1644
|
+
|
|
1645
|
+
var _react = _interopRequireDefault(React);
|
|
1646
|
+
|
|
1647
|
+
var _reactDom = require$$2$1;
|
|
1648
|
+
|
|
1649
|
+
var _TransitionGroup = _interopRequireDefault(TransitionGroup.exports);
|
|
1650
|
+
|
|
1651
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1652
|
+
|
|
1653
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
1654
|
+
|
|
1655
|
+
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
|
|
1656
|
+
|
|
1657
|
+
/**
|
|
1658
|
+
* The `<ReplaceTransition>` component is a specialized `Transition` component
|
|
1659
|
+
* that animates between two children.
|
|
1660
|
+
*
|
|
1661
|
+
* ```jsx
|
|
1662
|
+
* <ReplaceTransition in>
|
|
1663
|
+
* <Fade><div>I appear first</div></Fade>
|
|
1664
|
+
* <Fade><div>I replace the above</div></Fade>
|
|
1665
|
+
* </ReplaceTransition>
|
|
1666
|
+
* ```
|
|
1667
|
+
*/
|
|
1668
|
+
var ReplaceTransition =
|
|
1669
|
+
/*#__PURE__*/
|
|
1670
|
+
function (_React$Component) {
|
|
1671
|
+
_inheritsLoose(ReplaceTransition, _React$Component);
|
|
1672
|
+
|
|
1673
|
+
function ReplaceTransition() {
|
|
1674
|
+
var _this;
|
|
1675
|
+
|
|
1676
|
+
for (var _len = arguments.length, _args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
1677
|
+
_args[_key] = arguments[_key];
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
_this = _React$Component.call.apply(_React$Component, [this].concat(_args)) || this;
|
|
1681
|
+
|
|
1682
|
+
_this.handleEnter = function () {
|
|
1683
|
+
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
1684
|
+
args[_key2] = arguments[_key2];
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
return _this.handleLifecycle('onEnter', 0, args);
|
|
1688
|
+
};
|
|
1689
|
+
|
|
1690
|
+
_this.handleEntering = function () {
|
|
1691
|
+
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
|
|
1692
|
+
args[_key3] = arguments[_key3];
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
return _this.handleLifecycle('onEntering', 0, args);
|
|
1696
|
+
};
|
|
1697
|
+
|
|
1698
|
+
_this.handleEntered = function () {
|
|
1699
|
+
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
|
|
1700
|
+
args[_key4] = arguments[_key4];
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
return _this.handleLifecycle('onEntered', 0, args);
|
|
1704
|
+
};
|
|
1705
|
+
|
|
1706
|
+
_this.handleExit = function () {
|
|
1707
|
+
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
|
|
1708
|
+
args[_key5] = arguments[_key5];
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
return _this.handleLifecycle('onExit', 1, args);
|
|
1712
|
+
};
|
|
1713
|
+
|
|
1714
|
+
_this.handleExiting = function () {
|
|
1715
|
+
for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) {
|
|
1716
|
+
args[_key6] = arguments[_key6];
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
return _this.handleLifecycle('onExiting', 1, args);
|
|
1720
|
+
};
|
|
1721
|
+
|
|
1722
|
+
_this.handleExited = function () {
|
|
1723
|
+
for (var _len7 = arguments.length, args = new Array(_len7), _key7 = 0; _key7 < _len7; _key7++) {
|
|
1724
|
+
args[_key7] = arguments[_key7];
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
return _this.handleLifecycle('onExited', 1, args);
|
|
1728
|
+
};
|
|
1729
|
+
|
|
1730
|
+
return _this;
|
|
1731
|
+
}
|
|
1732
|
+
|
|
1733
|
+
var _proto = ReplaceTransition.prototype;
|
|
1734
|
+
|
|
1735
|
+
_proto.handleLifecycle = function handleLifecycle(handler, idx, originalArgs) {
|
|
1736
|
+
var _child$props;
|
|
1737
|
+
|
|
1738
|
+
var children = this.props.children;
|
|
1739
|
+
|
|
1740
|
+
var child = _react.default.Children.toArray(children)[idx];
|
|
1741
|
+
|
|
1742
|
+
if (child.props[handler]) (_child$props = child.props)[handler].apply(_child$props, originalArgs);
|
|
1743
|
+
if (this.props[handler]) this.props[handler]((0, _reactDom.findDOMNode)(this));
|
|
1744
|
+
};
|
|
1745
|
+
|
|
1746
|
+
_proto.render = function render() {
|
|
1747
|
+
var _this$props = this.props,
|
|
1748
|
+
children = _this$props.children,
|
|
1749
|
+
inProp = _this$props.in,
|
|
1750
|
+
props = _objectWithoutPropertiesLoose(_this$props, ["children", "in"]);
|
|
1751
|
+
|
|
1752
|
+
var _React$Children$toArr = _react.default.Children.toArray(children),
|
|
1753
|
+
first = _React$Children$toArr[0],
|
|
1754
|
+
second = _React$Children$toArr[1];
|
|
1755
|
+
|
|
1756
|
+
delete props.onEnter;
|
|
1757
|
+
delete props.onEntering;
|
|
1758
|
+
delete props.onEntered;
|
|
1759
|
+
delete props.onExit;
|
|
1760
|
+
delete props.onExiting;
|
|
1761
|
+
delete props.onExited;
|
|
1762
|
+
return _react.default.createElement(_TransitionGroup.default, props, inProp ? _react.default.cloneElement(first, {
|
|
1763
|
+
key: 'first',
|
|
1764
|
+
onEnter: this.handleEnter,
|
|
1765
|
+
onEntering: this.handleEntering,
|
|
1766
|
+
onEntered: this.handleEntered
|
|
1767
|
+
}) : _react.default.cloneElement(second, {
|
|
1768
|
+
key: 'second',
|
|
1769
|
+
onEnter: this.handleExit,
|
|
1770
|
+
onEntering: this.handleExiting,
|
|
1771
|
+
onEntered: this.handleExited
|
|
1772
|
+
}));
|
|
1773
|
+
};
|
|
1774
|
+
|
|
1775
|
+
return ReplaceTransition;
|
|
1776
|
+
}(_react.default.Component);
|
|
1777
|
+
|
|
1778
|
+
ReplaceTransition.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
1779
|
+
in: _propTypes.default.bool.isRequired,
|
|
1780
|
+
children: function children(props, propName) {
|
|
1781
|
+
if (_react.default.Children.count(props[propName]) !== 2) return new Error("\"" + propName + "\" must be exactly two transition components.");
|
|
1782
|
+
return null;
|
|
1783
|
+
}
|
|
1784
|
+
} : {};
|
|
1785
|
+
var _default = ReplaceTransition;
|
|
1786
|
+
exports.default = _default;
|
|
1787
|
+
module.exports = exports["default"];
|
|
1788
|
+
}(ReplaceTransition, ReplaceTransition.exports));
|
|
1789
|
+
|
|
1790
|
+
var _CSSTransition = _interopRequireDefault(CSSTransition.exports);
|
|
1791
|
+
|
|
1792
|
+
var _ReplaceTransition = _interopRequireDefault(ReplaceTransition.exports);
|
|
1793
|
+
|
|
1794
|
+
var _TransitionGroup = _interopRequireDefault(TransitionGroup.exports);
|
|
1795
|
+
|
|
1796
|
+
var _Transition = _interopRequireDefault(Transition$1);
|
|
1797
|
+
|
|
1798
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1799
|
+
|
|
1800
|
+
var reactTransitionGroup = {
|
|
1801
|
+
Transition: _Transition.default,
|
|
1802
|
+
TransitionGroup: _TransitionGroup.default,
|
|
1803
|
+
ReplaceTransition: _ReplaceTransition.default,
|
|
1804
|
+
CSSTransition: _CSSTransition.default
|
|
1805
|
+
};
|
|
1806
|
+
|
|
1807
|
+
const stylesheet = {
|
|
1808
|
+
incorrect: {
|
|
1809
|
+
fill: `var(--feedback-incorrect-bg-color, ${color.incorrect()})`
|
|
1810
|
+
},
|
|
1811
|
+
correct: {
|
|
1812
|
+
fill: `var(--feedback-correct-bg-color, ${color.correct()})`
|
|
1813
|
+
},
|
|
1814
|
+
feedbackTick: {
|
|
1815
|
+
width: '33px',
|
|
1816
|
+
height: '33px',
|
|
1817
|
+
'& svg': {
|
|
1818
|
+
position: 'absolute',
|
|
1819
|
+
display: 'inline-block',
|
|
1820
|
+
width: '33px',
|
|
1821
|
+
height: '33px',
|
|
1822
|
+
verticalAlign: 'middle',
|
|
1823
|
+
'& hide': {
|
|
1824
|
+
display: 'none'
|
|
1825
|
+
}
|
|
1826
|
+
}
|
|
1827
|
+
},
|
|
1828
|
+
feedbackTickEnter: {
|
|
1829
|
+
opacity: '0',
|
|
1830
|
+
left: '-50px'
|
|
1831
|
+
},
|
|
1832
|
+
feedbackTickEnterActive: {
|
|
1833
|
+
opacity: '1',
|
|
1834
|
+
left: '0px',
|
|
1835
|
+
transition: 'left 500ms ease-in 200ms, opacity 500ms linear 200ms'
|
|
1836
|
+
},
|
|
1837
|
+
feedbackTickLeave: {
|
|
1838
|
+
opacity: '1',
|
|
1839
|
+
left: '0px'
|
|
1840
|
+
},
|
|
1841
|
+
feedbackTickLeaveActive: {
|
|
1842
|
+
opacity: '0',
|
|
1843
|
+
left: '-50px',
|
|
1844
|
+
transition: 'left 300ms ease-in, opacity 300ms'
|
|
1845
|
+
}
|
|
1846
|
+
};
|
|
1847
|
+
|
|
1848
|
+
class FeedbackTick extends React.Component {
|
|
1849
|
+
constructor(props) {
|
|
1850
|
+
super(props);
|
|
1851
|
+
this.incorrectIcon = /*#__PURE__*/React.createElement("svg", {
|
|
1852
|
+
key: "1",
|
|
1853
|
+
preserveAspectRatio: "xMinYMin meet",
|
|
1854
|
+
x: "0px",
|
|
1855
|
+
y: "0px",
|
|
1856
|
+
viewBox: "0 0 44 40",
|
|
1857
|
+
style: {
|
|
1858
|
+
enableBackground: 'new 0 0 44 40'
|
|
1859
|
+
}
|
|
1860
|
+
}, /*#__PURE__*/React.createElement("g", null, /*#__PURE__*/React.createElement("rect", {
|
|
1861
|
+
x: "11",
|
|
1862
|
+
y: "17.3",
|
|
1863
|
+
transform: "matrix(0.7071 -0.7071 0.7071 0.7071 -7.852 19.2507)",
|
|
1864
|
+
className: this.props.classes.incorrect,
|
|
1865
|
+
width: "16.6",
|
|
1866
|
+
height: "3.7"
|
|
1867
|
+
}), /*#__PURE__*/React.createElement("rect", {
|
|
1868
|
+
x: "17.4",
|
|
1869
|
+
y: "10.7",
|
|
1870
|
+
transform: "matrix(0.7071 -0.7071 0.7071 0.7071 -7.8175 19.209)",
|
|
1871
|
+
className: this.props.classes.incorrect,
|
|
1872
|
+
width: "3.7",
|
|
1873
|
+
height: "16.6"
|
|
1874
|
+
})));
|
|
1875
|
+
this.correctIcon = /*#__PURE__*/React.createElement("svg", {
|
|
1876
|
+
key: "2",
|
|
1877
|
+
preserveAspectRatio: "xMinYMin meet",
|
|
1878
|
+
version: "1.1",
|
|
1879
|
+
x: "0px",
|
|
1880
|
+
y: "0px",
|
|
1881
|
+
viewBox: "0 0 44 40",
|
|
1882
|
+
style: {
|
|
1883
|
+
enableBackground: 'new 0 0 44 40'
|
|
1884
|
+
}
|
|
1885
|
+
}, /*#__PURE__*/React.createElement("polygon", {
|
|
1886
|
+
className: this.props.classes.correct,
|
|
1887
|
+
points: "19.1,28.6 11.8,22.3 14.4,19.2 17.9,22.1 23.9,11.4 27.5,13.4"
|
|
1888
|
+
}));
|
|
1889
|
+
}
|
|
1890
|
+
|
|
1891
|
+
render() {
|
|
1892
|
+
const {
|
|
1893
|
+
correctness,
|
|
1894
|
+
classes
|
|
1895
|
+
} = this.props;
|
|
1896
|
+
|
|
1897
|
+
const icon = (() => {
|
|
1898
|
+
if (correctness === 'incorrect') {
|
|
1899
|
+
return this.incorrectIcon;
|
|
1900
|
+
} else if (correctness === 'correct') {
|
|
1901
|
+
return this.correctIcon;
|
|
1902
|
+
}
|
|
1903
|
+
})();
|
|
1904
|
+
|
|
1905
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
1906
|
+
className: classes.feedbackTick
|
|
1907
|
+
}, /*#__PURE__*/React.createElement(reactTransitionGroup.TransitionGroup, null, correctness && /*#__PURE__*/React.createElement(reactTransitionGroup.CSSTransition, {
|
|
1908
|
+
classNames: {
|
|
1909
|
+
enter: classes.feedbackTickEnter,
|
|
1910
|
+
enterActive: classes.feedbackTickEnterActive,
|
|
1911
|
+
exit: classes.feedbackTickLeave,
|
|
1912
|
+
exitActive: classes.feedbackTickLeaveActive
|
|
1913
|
+
},
|
|
1914
|
+
timeout: {
|
|
1915
|
+
enter: 700,
|
|
1916
|
+
exit: 300
|
|
1917
|
+
}
|
|
1918
|
+
}, icon)));
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
}
|
|
1922
|
+
|
|
1923
|
+
FeedbackTick.propTypes = {
|
|
1924
|
+
classes: PropTypes$2.object.isRequired,
|
|
1925
|
+
correctness: PropTypes$2.string
|
|
1926
|
+
};
|
|
1927
|
+
var FeedbackTick$1 = withStyles(stylesheet, {
|
|
1928
|
+
name: 'FeedbackTick'
|
|
1929
|
+
})(FeedbackTick);
|
|
1930
|
+
|
|
1931
|
+
const CLASS_NAME = 'multiple-choice-component';
|
|
1932
|
+
|
|
1933
|
+
const styleSheet = theme => ({
|
|
1934
|
+
row: {
|
|
1935
|
+
display: 'flex',
|
|
1936
|
+
alignItems: 'center',
|
|
1937
|
+
backgroundColor: color.background()
|
|
1938
|
+
},
|
|
1939
|
+
checkboxHolder: {
|
|
1940
|
+
display: 'flex',
|
|
1941
|
+
alignItems: 'center',
|
|
1942
|
+
backgroundColor: color.background(),
|
|
1943
|
+
flex: 1,
|
|
1944
|
+
'& label': {
|
|
1945
|
+
color: color.text(),
|
|
1946
|
+
'& > span': {
|
|
1947
|
+
fontSize: 'inherit'
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1950
|
+
},
|
|
1951
|
+
horizontalLayout: {
|
|
1952
|
+
[`& .${CLASS_NAME}`]: {
|
|
1953
|
+
// visually reduce right padding, but maintain accessibility padding for checkbox indicators to be circles
|
|
1954
|
+
// add margin to the top, left and bottom of the checkbox to keep the same spacing as before
|
|
1955
|
+
padding: theme.spacing.unit,
|
|
1956
|
+
margin: `${theme.spacing.unit / 2}px 0 ${theme.spacing.unit / 2}px ${theme.spacing.unit / 2}px`
|
|
1957
|
+
}
|
|
1958
|
+
},
|
|
1959
|
+
belowLayout: {
|
|
1960
|
+
'& > label': {
|
|
1961
|
+
alignItems: 'flex-start'
|
|
1962
|
+
}
|
|
1963
|
+
},
|
|
1964
|
+
belowLayoutCenter: {
|
|
1965
|
+
justifyContent: 'center',
|
|
1966
|
+
'& > label': {
|
|
1967
|
+
alignItems: 'center'
|
|
1968
|
+
}
|
|
1969
|
+
},
|
|
1970
|
+
belowSelectionComponent: {
|
|
1971
|
+
display: 'flex',
|
|
1972
|
+
alignItems: 'center',
|
|
1973
|
+
'& > span': {
|
|
1974
|
+
// visually reduce right padding, but maintain accessibility padding for checkbox indicators to be circles
|
|
1975
|
+
marginLeft: `-${theme.spacing.unit}px`
|
|
1976
|
+
}
|
|
1977
|
+
},
|
|
1978
|
+
srOnly: {
|
|
1979
|
+
position: 'absolute',
|
|
1980
|
+
left: '-10000px',
|
|
1981
|
+
top: 'auto',
|
|
1982
|
+
width: '1px',
|
|
1983
|
+
height: '1px',
|
|
1984
|
+
overflow: 'hidden'
|
|
1985
|
+
}
|
|
1986
|
+
});
|
|
1987
|
+
|
|
1988
|
+
const formStyleSheet = {
|
|
1989
|
+
label: {
|
|
1990
|
+
color: `${color.text()} !important`,
|
|
1991
|
+
//'var(--choice-input-color, black)'
|
|
1992
|
+
backgroundColor: color.background(),
|
|
1993
|
+
letterSpacing: 'normal'
|
|
1994
|
+
},
|
|
1995
|
+
disabled: {
|
|
1996
|
+
// apply to all children
|
|
1997
|
+
'& *': {
|
|
1998
|
+
cursor: 'not-allowed !important'
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
const StyledFormControlLabel = withStyles(formStyleSheet, {
|
|
2003
|
+
name: 'FormControlLabel'
|
|
2004
|
+
})(props => /*#__PURE__*/React.createElement(FormControlLabel, _extends({}, props, {
|
|
2005
|
+
classes: {
|
|
2006
|
+
label: props.classes.label,
|
|
2007
|
+
disabled: props.classes.disabled
|
|
2008
|
+
}
|
|
2009
|
+
})));
|
|
2010
|
+
|
|
2011
|
+
const colorStyle = (varName, fallback) => ({
|
|
2012
|
+
[`&.${CLASS_NAME}`]: {
|
|
2013
|
+
color: `var(--choice-input-${varName}, ${fallback}) !important`
|
|
2014
|
+
}
|
|
2015
|
+
});
|
|
2016
|
+
|
|
2017
|
+
const inputStyles = {
|
|
2018
|
+
'correct-root': colorStyle('correct-color', color.text()),
|
|
2019
|
+
'correct-checked': colorStyle('correct-selected-color', color.correct()),
|
|
2020
|
+
//green[500]),
|
|
2021
|
+
'correct-disabled': colorStyle('correct-disabled-color', color.disabled()),
|
|
2022
|
+
//'grey'),
|
|
2023
|
+
'incorrect-root': colorStyle('incorrect-color', color.incorrect()),
|
|
2024
|
+
'incorrect-checked': colorStyle('incorrect-checked', color.incorrect()),
|
|
2025
|
+
//orange[500]),
|
|
2026
|
+
'incorrect-disabled': colorStyle('incorrect-disabled-color', color.disabled()),
|
|
2027
|
+
root: _extends({}, colorStyle('color', color.text()), {
|
|
2028
|
+
'&:hover': {
|
|
2029
|
+
color: `${color.primaryLight()} !important`
|
|
2030
|
+
}
|
|
2031
|
+
}),
|
|
2032
|
+
checked: colorStyle('selected-color', color.primary()),
|
|
2033
|
+
disabled: _extends({}, colorStyle('disabled-color', color.text()), {
|
|
2034
|
+
opacity: 0.6,
|
|
2035
|
+
cursor: 'not-allowed !important',
|
|
2036
|
+
pointerEvents: 'initial !important'
|
|
2037
|
+
}),
|
|
2038
|
+
focusVisibleUnchecked: {
|
|
2039
|
+
outline: `2px solid ${color.focusUncheckedBorder()}`,
|
|
2040
|
+
backgroundColor: color.focusUnchecked()
|
|
2041
|
+
},
|
|
2042
|
+
focusVisibleChecked: {
|
|
2043
|
+
outline: `2px solid ${color.focusCheckedBorder()}`,
|
|
2044
|
+
backgroundColor: color.focusChecked()
|
|
2045
|
+
}
|
|
2046
|
+
};
|
|
2047
|
+
const StyledCheckbox = withStyles(inputStyles)(props => {
|
|
2048
|
+
const {
|
|
2049
|
+
correctness,
|
|
2050
|
+
classes,
|
|
2051
|
+
checked,
|
|
2052
|
+
onChange,
|
|
2053
|
+
disabled,
|
|
2054
|
+
value,
|
|
2055
|
+
id,
|
|
2056
|
+
onKeyDown,
|
|
2057
|
+
inputRef
|
|
2058
|
+
} = props;
|
|
2059
|
+
|
|
2060
|
+
const key = k => correctness ? `${correctness}-${k}` : k;
|
|
2061
|
+
|
|
2062
|
+
const resolved = {
|
|
2063
|
+
root: classes[key('root')],
|
|
2064
|
+
checked: classes[key('checked')],
|
|
2065
|
+
disabled: classes[key('disabled')]
|
|
2066
|
+
};
|
|
2067
|
+
const miniProps = {
|
|
2068
|
+
checked,
|
|
2069
|
+
onChange,
|
|
2070
|
+
disabled,
|
|
2071
|
+
value
|
|
2072
|
+
};
|
|
2073
|
+
return /*#__PURE__*/React.createElement(Checkbox, _extends({
|
|
2074
|
+
id: id,
|
|
2075
|
+
inputRef: inputRef,
|
|
2076
|
+
"aria-checked": checked,
|
|
2077
|
+
onKeyDown: onKeyDown,
|
|
2078
|
+
focusVisibleClassName: checked ? classes.focusVisibleChecked : classes.focusVisibleUnchecked,
|
|
2079
|
+
disableRipple: true
|
|
2080
|
+
}, miniProps, {
|
|
2081
|
+
className: CLASS_NAME,
|
|
2082
|
+
classes: {
|
|
2083
|
+
root: resolved.root,
|
|
2084
|
+
checked: resolved.checked,
|
|
2085
|
+
disabled: `${correctness ? '' : resolved.disabled}`
|
|
2086
|
+
}
|
|
2087
|
+
}));
|
|
2088
|
+
});
|
|
2089
|
+
const StyledRadio = withStyles(inputStyles)(props => {
|
|
2090
|
+
const {
|
|
2091
|
+
correctness,
|
|
2092
|
+
classes,
|
|
2093
|
+
checked,
|
|
2094
|
+
onChange,
|
|
2095
|
+
disabled,
|
|
2096
|
+
value,
|
|
2097
|
+
id,
|
|
2098
|
+
tagName,
|
|
2099
|
+
inputRef
|
|
2100
|
+
} = props;
|
|
2101
|
+
|
|
2102
|
+
const key = k => correctness ? `${correctness}-${k}` : k;
|
|
2103
|
+
|
|
2104
|
+
const resolved = {
|
|
2105
|
+
root: classes[key('root')],
|
|
2106
|
+
checked: classes[key('checked')],
|
|
2107
|
+
disabled: classes[key('disabled')]
|
|
2108
|
+
};
|
|
2109
|
+
const miniProps = {
|
|
2110
|
+
checked,
|
|
2111
|
+
onChange,
|
|
2112
|
+
disabled,
|
|
2113
|
+
value
|
|
2114
|
+
};
|
|
2115
|
+
return /*#__PURE__*/React.createElement(Radio, _extends({
|
|
2116
|
+
id: id,
|
|
2117
|
+
inputRef: inputRef,
|
|
2118
|
+
"aria-checked": checked,
|
|
2119
|
+
focusVisibleClassName: checked ? classes.focusVisibleChecked : classes.focusVisibleUnchecked,
|
|
2120
|
+
disableRipple: true
|
|
2121
|
+
}, miniProps, {
|
|
2122
|
+
className: CLASS_NAME,
|
|
2123
|
+
name: tagName,
|
|
2124
|
+
classes: {
|
|
2125
|
+
root: resolved.root,
|
|
2126
|
+
checked: resolved.checked,
|
|
2127
|
+
disabled: `${correctness ? '' : resolved.disabled}`
|
|
2128
|
+
}
|
|
2129
|
+
}));
|
|
2130
|
+
});
|
|
2131
|
+
class ChoiceInput extends React.Component {
|
|
2132
|
+
constructor(props) {
|
|
2133
|
+
super(props);
|
|
2134
|
+
|
|
2135
|
+
this.handleKeyDown = event => {
|
|
2136
|
+
const {
|
|
2137
|
+
choiceMode
|
|
2138
|
+
} = this.props;
|
|
2139
|
+
if (choiceMode !== 'checkbox') return;
|
|
2140
|
+
const isArrowDown = event.key === 'ArrowDown';
|
|
2141
|
+
const isArrowUp = event.key === 'ArrowUp';
|
|
2142
|
+
if (!isArrowDown && !isArrowUp) return;
|
|
2143
|
+
event.preventDefault();
|
|
2144
|
+
const currentEl = document.getElementById(this.choiceId);
|
|
2145
|
+
if (!currentEl) return;
|
|
2146
|
+
const fieldset = currentEl.closest('fieldset');
|
|
2147
|
+
if (!fieldset) return;
|
|
2148
|
+
const groupCheckboxes = Array.from(fieldset.querySelectorAll('input[type="checkbox"]'));
|
|
2149
|
+
const currentIndex = groupCheckboxes.findIndex(el => el === currentEl);
|
|
2150
|
+
if (currentIndex === -1) return;
|
|
2151
|
+
const nextIndex = isArrowDown ? currentIndex + 1 : currentIndex - 1;
|
|
2152
|
+
const nextEl = groupCheckboxes[nextIndex];
|
|
2153
|
+
|
|
2154
|
+
if (nextEl) {
|
|
2155
|
+
nextEl.focus();
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2158
|
+
|
|
2159
|
+
this.onToggleChoice = this.onToggleChoice.bind(this);
|
|
2160
|
+
this.choiceId = this.generateChoiceId();
|
|
2161
|
+
this.descId = `${this.choiceId}-desc`;
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
onToggleChoice(event) {
|
|
2165
|
+
this.props.onChange(event);
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2168
|
+
generateChoiceId() {
|
|
2169
|
+
return 'choice-' + (Math.random() * 10000).toFixed();
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
render() {
|
|
2173
|
+
const {
|
|
2174
|
+
choiceMode,
|
|
2175
|
+
disabled,
|
|
2176
|
+
displayKey,
|
|
2177
|
+
feedback,
|
|
2178
|
+
label,
|
|
2179
|
+
correctness,
|
|
2180
|
+
classes,
|
|
2181
|
+
className,
|
|
2182
|
+
rationale,
|
|
2183
|
+
hideTick,
|
|
2184
|
+
isEvaluateMode,
|
|
2185
|
+
choicesLayout,
|
|
2186
|
+
value,
|
|
2187
|
+
checked,
|
|
2188
|
+
tagName,
|
|
2189
|
+
isSelectionButtonBelow
|
|
2190
|
+
} = this.props;
|
|
2191
|
+
const Tag = choiceMode === 'checkbox' ? StyledCheckbox : StyledRadio;
|
|
2192
|
+
const classSuffix = choiceMode === 'checkbox' ? 'checkbox' : 'radio-button';
|
|
2193
|
+
const holderClassNames = classNames(classes.checkboxHolder, {
|
|
2194
|
+
[classes.horizontalLayout]: choicesLayout === 'horizontal',
|
|
2195
|
+
[classes.belowLayout]: isSelectionButtonBelow && choicesLayout !== 'grid',
|
|
2196
|
+
[classes.belowLayoutCenter]: isSelectionButtonBelow && choicesLayout === 'grid'
|
|
2197
|
+
});
|
|
2198
|
+
const choicelabel = /*#__PURE__*/React.createElement(React.Fragment, null, displayKey && !isSelectionButtonBelow ? /*#__PURE__*/React.createElement("span", {
|
|
2199
|
+
className: classes.row
|
|
2200
|
+
}, displayKey, ".", '\u00A0', /*#__PURE__*/React.createElement(PreviewPrompt, {
|
|
2201
|
+
className: "label",
|
|
2202
|
+
prompt: label,
|
|
2203
|
+
tagName: "span"
|
|
2204
|
+
})) : /*#__PURE__*/React.createElement(PreviewPrompt, {
|
|
2205
|
+
className: "label",
|
|
2206
|
+
prompt: label,
|
|
2207
|
+
tagName: "span"
|
|
2208
|
+
}));
|
|
2209
|
+
const screenReaderLabel = /*#__PURE__*/React.createElement("span", {
|
|
2210
|
+
id: this.descId,
|
|
2211
|
+
className: classes.srOnly
|
|
2212
|
+
}, choiceMode === 'checkbox' ? 'Checkbox to select the answer below' : 'Radio button to select the answer below');
|
|
2213
|
+
const tagProps = {
|
|
2214
|
+
disabled,
|
|
2215
|
+
checked,
|
|
2216
|
+
correctness,
|
|
2217
|
+
tagName,
|
|
2218
|
+
value,
|
|
2219
|
+
id: this.choiceId,
|
|
2220
|
+
onChange: this.onToggleChoice,
|
|
2221
|
+
onKeyDown: this.handleKeyDown,
|
|
2222
|
+
'aria-describedby': this.descId
|
|
2223
|
+
};
|
|
2224
|
+
const hasMathOrImage = typeof label === 'string' && (label.includes('<math') || label.includes('\\(') || label.includes('\\[') || label.includes('<img') || label.includes('data-latex') || label.includes('data-raw') || label.includes('<mjx-container'));
|
|
2225
|
+
const control = isSelectionButtonBelow ? /*#__PURE__*/React.createElement("span", {
|
|
2226
|
+
className: classes.belowSelectionComponent
|
|
2227
|
+
}, hasMathOrImage && screenReaderLabel, /*#__PURE__*/React.createElement(Tag, _extends({}, tagProps, {
|
|
2228
|
+
style: {
|
|
2229
|
+
padding: 0
|
|
2230
|
+
}
|
|
2231
|
+
})), displayKey ? `${displayKey}.` : '') : /*#__PURE__*/React.createElement(React.Fragment, null, hasMathOrImage && screenReaderLabel, /*#__PURE__*/React.createElement(Tag, _extends({}, tagProps, {
|
|
2232
|
+
inputRef: this.props.autoFocusRef
|
|
2233
|
+
})));
|
|
2234
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
2235
|
+
className: classNames(className, 'corespring-' + classSuffix, 'choice-input')
|
|
2236
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
2237
|
+
className: classes.row
|
|
2238
|
+
}, !hideTick && isEvaluateMode && /*#__PURE__*/React.createElement(FeedbackTick$1, {
|
|
2239
|
+
correctness: correctness
|
|
2240
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
2241
|
+
className: classNames(holderClassNames, 'checkbox-holder')
|
|
2242
|
+
}, /*#__PURE__*/React.createElement(StyledFormControlLabel, {
|
|
2243
|
+
label: choicelabel,
|
|
2244
|
+
value: value,
|
|
2245
|
+
htmlFor: this.choiceId,
|
|
2246
|
+
labelPlacement: isSelectionButtonBelow ? 'top' : undefined,
|
|
2247
|
+
control: control
|
|
2248
|
+
}))), rationale && /*#__PURE__*/React.createElement(PreviewPrompt, {
|
|
2249
|
+
className: "rationale",
|
|
2250
|
+
defaultClassName: "rationale",
|
|
2251
|
+
prompt: rationale
|
|
2252
|
+
}), /*#__PURE__*/React.createElement(Feedback, {
|
|
2253
|
+
feedback: feedback,
|
|
2254
|
+
correctness: correctness
|
|
2255
|
+
}));
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2258
|
+
}
|
|
2259
|
+
ChoiceInput.propTypes = {
|
|
2260
|
+
choiceMode: PropTypes$2.oneOf(['radio', 'checkbox']),
|
|
2261
|
+
displayKey: PropTypes$2.string,
|
|
2262
|
+
checked: PropTypes$2.bool.isRequired,
|
|
2263
|
+
correctness: PropTypes$2.string,
|
|
2264
|
+
disabled: PropTypes$2.bool.isRequired,
|
|
2265
|
+
feedback: PropTypes$2.string,
|
|
2266
|
+
label: PropTypes$2.string.isRequired,
|
|
2267
|
+
rationale: PropTypes$2.string,
|
|
2268
|
+
onChange: PropTypes$2.func.isRequired,
|
|
2269
|
+
value: PropTypes$2.string.isRequired,
|
|
2270
|
+
classes: PropTypes$2.object,
|
|
2271
|
+
className: PropTypes$2.string,
|
|
2272
|
+
tagName: PropTypes$2.string,
|
|
2273
|
+
hideTick: PropTypes$2.bool,
|
|
2274
|
+
isEvaluateMode: PropTypes$2.bool,
|
|
2275
|
+
choicesLayout: PropTypes$2.oneOf(['vertical', 'grid', 'horizontal']),
|
|
2276
|
+
isSelectionButtonBelow: PropTypes$2.bool
|
|
2277
|
+
};
|
|
2278
|
+
ChoiceInput.defaultProps = {
|
|
2279
|
+
rationale: null,
|
|
2280
|
+
checked: false,
|
|
2281
|
+
isEvaluateMode: false
|
|
2282
|
+
};
|
|
2283
|
+
var ChoiceInput$1 = withStyles(styleSheet)(ChoiceInput);
|
|
2284
|
+
|
|
2285
|
+
class Choice extends React.Component {
|
|
2286
|
+
constructor(...args) {
|
|
2287
|
+
super(...args);
|
|
2288
|
+
this.state = {
|
|
2289
|
+
isHovered: false
|
|
2290
|
+
};
|
|
2291
|
+
|
|
2292
|
+
this.handleMouseEnter = () => {
|
|
2293
|
+
const {
|
|
2294
|
+
disabled,
|
|
2295
|
+
checked
|
|
2296
|
+
} = this.props;
|
|
2297
|
+
|
|
2298
|
+
if (!disabled && !checked) {
|
|
2299
|
+
this.setState({
|
|
2300
|
+
isHovered: true
|
|
2301
|
+
});
|
|
2302
|
+
}
|
|
2303
|
+
};
|
|
2304
|
+
|
|
2305
|
+
this.handleMouseLeave = () => {
|
|
2306
|
+
this.setState({
|
|
2307
|
+
isHovered: false
|
|
2308
|
+
});
|
|
2309
|
+
};
|
|
2310
|
+
|
|
2311
|
+
this.onChange = choice => {
|
|
2312
|
+
const {
|
|
2313
|
+
disabled,
|
|
2314
|
+
onChoiceChanged
|
|
2315
|
+
} = this.props;
|
|
2316
|
+
|
|
2317
|
+
if (!disabled) {
|
|
2318
|
+
onChoiceChanged(choice);
|
|
2319
|
+
}
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
render() {
|
|
2324
|
+
const {
|
|
2325
|
+
choice,
|
|
2326
|
+
index,
|
|
2327
|
+
choicesLength,
|
|
2328
|
+
showCorrect,
|
|
2329
|
+
isEvaluateMode,
|
|
2330
|
+
choiceMode,
|
|
2331
|
+
disabled,
|
|
2332
|
+
checked,
|
|
2333
|
+
correctness,
|
|
2334
|
+
displayKey,
|
|
2335
|
+
classes,
|
|
2336
|
+
choicesLayout,
|
|
2337
|
+
gridColumns,
|
|
2338
|
+
isSelectionButtonBelow,
|
|
2339
|
+
selectedAnswerBackgroundColor,
|
|
2340
|
+
selectedAnswerStrokeColor,
|
|
2341
|
+
selectedAnswerStrokeWidth,
|
|
2342
|
+
hoverAnswerBackgroundColor,
|
|
2343
|
+
hoverAnswerStrokeColor,
|
|
2344
|
+
hoverAnswerStrokeWidth,
|
|
2345
|
+
autoFocusRef,
|
|
2346
|
+
tagName
|
|
2347
|
+
} = this.props;
|
|
2348
|
+
const {
|
|
2349
|
+
isHovered
|
|
2350
|
+
} = this.state;
|
|
2351
|
+
const choiceClass = 'choice' + (index === choicesLength - 1 ? ' last' : '');
|
|
2352
|
+
const feedback = !isEvaluateMode || showCorrect ? '' : choice.feedback;
|
|
2353
|
+
|
|
2354
|
+
const choiceProps = _extends({}, choice, {
|
|
2355
|
+
checked,
|
|
2356
|
+
choiceMode,
|
|
2357
|
+
disabled,
|
|
2358
|
+
feedback,
|
|
2359
|
+
correctness,
|
|
2360
|
+
displayKey,
|
|
2361
|
+
index,
|
|
2362
|
+
choicesLayout,
|
|
2363
|
+
gridColumns,
|
|
2364
|
+
onChange: this.onChange,
|
|
2365
|
+
isEvaluateMode,
|
|
2366
|
+
isSelectionButtonBelow,
|
|
2367
|
+
selectedAnswerStrokeColor,
|
|
2368
|
+
selectedAnswerStrokeWidth,
|
|
2369
|
+
tagName
|
|
2370
|
+
});
|
|
2371
|
+
|
|
2372
|
+
const normalizeStrokeWidth = width => {
|
|
2373
|
+
if (!width) return '2px'; // default
|
|
2374
|
+
|
|
2375
|
+
const trimmed = String(width).trim(); // add 'px' if the value is a number
|
|
2376
|
+
|
|
2377
|
+
if (/^\d+(\.\d+)?$/.test(trimmed)) {
|
|
2378
|
+
return `${trimmed}px`;
|
|
2379
|
+
}
|
|
2380
|
+
|
|
2381
|
+
return trimmed;
|
|
2382
|
+
};
|
|
2383
|
+
|
|
2384
|
+
const hasSelectedStroke = selectedAnswerStrokeColor && selectedAnswerStrokeColor !== 'initial';
|
|
2385
|
+
const hasHoverStroke = hoverAnswerStrokeColor && hoverAnswerStrokeColor !== 'initial';
|
|
2386
|
+
let currentStrokeColor = 'transparent';
|
|
2387
|
+
let currentStrokeWidth = '2px';
|
|
2388
|
+
let currentBackgroundColor = 'initial';
|
|
2389
|
+
|
|
2390
|
+
if (hasSelectedStroke || hasHoverStroke) {
|
|
2391
|
+
if (checked && hasSelectedStroke) {
|
|
2392
|
+
// selected state takes priority when selected stroke is configured
|
|
2393
|
+
currentStrokeColor = selectedAnswerStrokeColor;
|
|
2394
|
+
currentStrokeWidth = selectedAnswerStrokeWidth;
|
|
2395
|
+
} else if (isHovered && !disabled && hasHoverStroke) {
|
|
2396
|
+
// hover state when not selected and not disabled, and hover stroke is configured
|
|
2397
|
+
currentStrokeColor = hoverAnswerStrokeColor;
|
|
2398
|
+
currentStrokeWidth = hoverAnswerStrokeWidth;
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
if (checked && selectedAnswerBackgroundColor && selectedAnswerBackgroundColor !== 'initial') {
|
|
2403
|
+
currentBackgroundColor = selectedAnswerBackgroundColor;
|
|
2404
|
+
} else if (isHovered && !disabled && hoverAnswerBackgroundColor && hoverAnswerBackgroundColor !== 'initial') {
|
|
2405
|
+
currentBackgroundColor = hoverAnswerBackgroundColor;
|
|
2406
|
+
}
|
|
2407
|
+
|
|
2408
|
+
const strokeStyle = hasSelectedStroke || hasHoverStroke ? {
|
|
2409
|
+
border: `${normalizeStrokeWidth(currentStrokeWidth)} solid ${currentStrokeColor}`,
|
|
2410
|
+
borderRadius: '8px'
|
|
2411
|
+
} : {};
|
|
2412
|
+
const names = classNames(classes.choice, {
|
|
2413
|
+
[classes.noBorder]: index === choicesLength - 1 || choicesLayout !== 'vertical' || strokeStyle,
|
|
2414
|
+
[classes.horizontalLayout]: choicesLayout === 'horizontal'
|
|
2415
|
+
});
|
|
2416
|
+
const choiceBackground = currentBackgroundColor !== 'initial' ? currentBackgroundColor : 'initial';
|
|
2417
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
2418
|
+
className: choiceClass,
|
|
2419
|
+
key: index,
|
|
2420
|
+
style: _extends({
|
|
2421
|
+
backgroundColor: choiceBackground
|
|
2422
|
+
}, strokeStyle),
|
|
2423
|
+
onMouseEnter: this.handleMouseEnter,
|
|
2424
|
+
onMouseLeave: this.handleMouseLeave
|
|
2425
|
+
}, /*#__PURE__*/React.createElement(ChoiceInput$1, _extends({}, choiceProps, {
|
|
2426
|
+
className: names,
|
|
2427
|
+
autoFocusRef: autoFocusRef
|
|
2428
|
+
})));
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
}
|
|
2432
|
+
Choice.propTypes = {};
|
|
2433
|
+
Choice.propTypes = {
|
|
2434
|
+
choiceMode: PropTypes$2.oneOf(['radio', 'checkbox']),
|
|
2435
|
+
choice: PropTypes$2.object,
|
|
2436
|
+
disabled: PropTypes$2.bool.isRequired,
|
|
2437
|
+
onChoiceChanged: PropTypes$2.func,
|
|
2438
|
+
classes: PropTypes$2.object.isRequired,
|
|
2439
|
+
index: PropTypes$2.number,
|
|
2440
|
+
choicesLength: PropTypes$2.number,
|
|
2441
|
+
showCorrect: PropTypes$2.bool,
|
|
2442
|
+
isEvaluateMode: PropTypes$2.bool,
|
|
2443
|
+
checked: PropTypes$2.bool,
|
|
2444
|
+
correctness: PropTypes$2.string,
|
|
2445
|
+
displayKey: PropTypes$2.string,
|
|
2446
|
+
choicesLayout: PropTypes$2.oneOf(['vertical', 'grid', 'horizontal']),
|
|
2447
|
+
gridColumns: PropTypes$2.string,
|
|
2448
|
+
selectedAnswerBackgroundColor: PropTypes$2.string,
|
|
2449
|
+
selectedAnswerStrokeColor: PropTypes$2.string,
|
|
2450
|
+
selectedAnswerStrokeWidth: PropTypes$2.string,
|
|
2451
|
+
hoverAnswerBackgroundColor: PropTypes$2.string,
|
|
2452
|
+
hoverAnswerStrokeColor: PropTypes$2.string,
|
|
2453
|
+
hoverAnswerStrokeWidth: PropTypes$2.string,
|
|
2454
|
+
tagName: PropTypes$2.string,
|
|
2455
|
+
isSelectionButtonBelow: PropTypes$2.bool,
|
|
2456
|
+
autoFocusRef: PropTypes$2.object
|
|
2457
|
+
};
|
|
2458
|
+
var StyledChoice = withStyles(theme => ({
|
|
2459
|
+
choice: {
|
|
2460
|
+
paddingTop: theme.spacing.unit * 2.5,
|
|
2461
|
+
paddingBottom: theme.spacing.unit + 2,
|
|
2462
|
+
paddingLeft: theme.spacing.unit + 2,
|
|
2463
|
+
paddingRight: theme.spacing.unit + 2,
|
|
2464
|
+
borderBottom: `1px solid ${theme.palette.grey[300]}`
|
|
2465
|
+
},
|
|
2466
|
+
noBorder: {
|
|
2467
|
+
borderBottom: 'none'
|
|
2468
|
+
},
|
|
2469
|
+
horizontalLayout: {
|
|
2470
|
+
paddingRight: theme.spacing.unit * 2.5,
|
|
2471
|
+
'& label': {
|
|
2472
|
+
marginRight: theme.spacing.unit // '& span:first-child': {
|
|
2473
|
+
// paddingRight: 0
|
|
2474
|
+
// }
|
|
2475
|
+
|
|
2476
|
+
}
|
|
2477
|
+
}
|
|
2478
|
+
}))(Choice);
|
|
2479
|
+
|
|
2480
|
+
const {
|
|
2481
|
+
translator
|
|
2482
|
+
} = Translator;
|
|
2483
|
+
|
|
2484
|
+
const styles$1 = theme => ({
|
|
2485
|
+
main: {
|
|
2486
|
+
color: color.text(),
|
|
2487
|
+
backgroundColor: color.background(),
|
|
2488
|
+
'& *': {
|
|
2489
|
+
'-webkit-font-smoothing': 'antialiased'
|
|
2490
|
+
},
|
|
2491
|
+
position: 'relative',
|
|
2492
|
+
// remove border from legend tags inside main to override the OT default styles
|
|
2493
|
+
'& legend': {
|
|
2494
|
+
border: 'none !important'
|
|
2495
|
+
}
|
|
2496
|
+
},
|
|
2497
|
+
partLabel: {
|
|
2498
|
+
display: 'block',
|
|
2499
|
+
fontSize: 'inherit',
|
|
2500
|
+
margin: '0',
|
|
2501
|
+
fontWeight: 'normal',
|
|
2502
|
+
paddingBottom: theme.spacing.unit * 2
|
|
2503
|
+
},
|
|
2504
|
+
teacherInstructions: {
|
|
2505
|
+
marginBottom: theme.spacing.unit * 2
|
|
2506
|
+
},
|
|
2507
|
+
horizontalLayout: {
|
|
2508
|
+
display: 'flex',
|
|
2509
|
+
flexDirection: 'row',
|
|
2510
|
+
flexWrap: 'wrap'
|
|
2511
|
+
},
|
|
2512
|
+
gridLayout: {
|
|
2513
|
+
display: 'grid'
|
|
2514
|
+
},
|
|
2515
|
+
fieldset: {
|
|
2516
|
+
border: '0px',
|
|
2517
|
+
padding: '0.01em 0 0 0',
|
|
2518
|
+
margin: '0px',
|
|
2519
|
+
minWidth: '0px',
|
|
2520
|
+
'&:focus': {
|
|
2521
|
+
outline: 'none'
|
|
2522
|
+
}
|
|
2523
|
+
},
|
|
2524
|
+
srOnly: {
|
|
2525
|
+
position: 'absolute',
|
|
2526
|
+
left: '-10000px',
|
|
2527
|
+
top: 'auto',
|
|
2528
|
+
width: '1px',
|
|
2529
|
+
height: '1px',
|
|
2530
|
+
overflow: 'hidden'
|
|
2531
|
+
},
|
|
2532
|
+
errorText: {
|
|
2533
|
+
fontSize: theme.typography.fontSize - 2,
|
|
2534
|
+
color: theme.palette.error.main,
|
|
2535
|
+
paddingTop: theme.spacing.unit
|
|
2536
|
+
}
|
|
2537
|
+
});
|
|
2538
|
+
|
|
2539
|
+
class MultipleChoice$1 extends React.Component {
|
|
2540
|
+
constructor(props) {
|
|
2541
|
+
super(props);
|
|
2542
|
+
|
|
2543
|
+
this.handleChange = event => {
|
|
2544
|
+
const {
|
|
2545
|
+
value,
|
|
2546
|
+
checked
|
|
2547
|
+
} = event.target;
|
|
2548
|
+
const {
|
|
2549
|
+
maxSelections,
|
|
2550
|
+
onChoiceChanged,
|
|
2551
|
+
session
|
|
2552
|
+
} = this.props;
|
|
2553
|
+
|
|
2554
|
+
if (session.value && session.value.length >= maxSelections) {
|
|
2555
|
+
// show/hide max selections error when user select/deselect an answer
|
|
2556
|
+
this.setState({
|
|
2557
|
+
maxSelectionsErrorState: checked
|
|
2558
|
+
});
|
|
2559
|
+
|
|
2560
|
+
if (checked) {
|
|
2561
|
+
// prevent selecting more answers
|
|
2562
|
+
return;
|
|
2563
|
+
}
|
|
2564
|
+
}
|
|
2565
|
+
|
|
2566
|
+
onChoiceChanged({
|
|
2567
|
+
value,
|
|
2568
|
+
selected: checked,
|
|
2569
|
+
selector: 'Mouse'
|
|
2570
|
+
});
|
|
2571
|
+
};
|
|
2572
|
+
|
|
2573
|
+
this.onToggle = () => {
|
|
2574
|
+
if (this.props.mode === 'evaluate') {
|
|
2575
|
+
this.setState({
|
|
2576
|
+
showCorrect: !this.state.showCorrect
|
|
2577
|
+
}, () => {
|
|
2578
|
+
if (this.props.onShowCorrectToggle) {
|
|
2579
|
+
this.props.onShowCorrectToggle();
|
|
2580
|
+
}
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
};
|
|
2584
|
+
|
|
2585
|
+
this.getCorrectness = (choice = {}) => {
|
|
2586
|
+
const isCorrect = choice.correct;
|
|
2587
|
+
const isChecked = this.isSelected(choice.value);
|
|
2588
|
+
|
|
2589
|
+
if (this.state.showCorrect) {
|
|
2590
|
+
return isCorrect ? 'correct' : undefined;
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
if (isCorrect) {
|
|
2594
|
+
if (isChecked) {
|
|
2595
|
+
// A correct answer is selected: marked with a green checkmark
|
|
2596
|
+
return 'correct';
|
|
2597
|
+
} else {
|
|
2598
|
+
// A correct answer is NOT selected: marked with an orange X
|
|
2599
|
+
return 'incorrect';
|
|
2600
|
+
}
|
|
2601
|
+
} else {
|
|
2602
|
+
if (isChecked) {
|
|
2603
|
+
// An incorrect answer is selected: marked with an orange X
|
|
2604
|
+
return 'incorrect';
|
|
2605
|
+
} else {
|
|
2606
|
+
// An incorrect answer is NOT selected: not marked
|
|
2607
|
+
return undefined;
|
|
2608
|
+
}
|
|
2609
|
+
}
|
|
2610
|
+
};
|
|
2611
|
+
|
|
2612
|
+
this.handleGroupFocus = e => {
|
|
2613
|
+
const fieldset = e.currentTarget;
|
|
2614
|
+
const activeEl = document.activeElement;
|
|
2615
|
+
|
|
2616
|
+
if (fieldset.contains(activeEl) && activeEl !== fieldset) {
|
|
2617
|
+
return;
|
|
2618
|
+
} // Only focus the first input if user is tabbing forward
|
|
2619
|
+
|
|
2620
|
+
|
|
2621
|
+
if (!e.relatedTarget || fieldset.compareDocumentPosition(e.relatedTarget) & Node.DOCUMENT_POSITION_PRECEDING) {
|
|
2622
|
+
var _this$firstInputRef;
|
|
2623
|
+
|
|
2624
|
+
if ((_this$firstInputRef = this.firstInputRef) != null && _this$firstInputRef.current) {
|
|
2625
|
+
this.firstInputRef.current.focus();
|
|
2626
|
+
}
|
|
2627
|
+
}
|
|
2628
|
+
};
|
|
2629
|
+
|
|
2630
|
+
this.state = {
|
|
2631
|
+
showCorrect: this.props.alwaysShowCorrect || false,
|
|
2632
|
+
maxSelectionsErrorState: false
|
|
2633
|
+
};
|
|
2634
|
+
this.onToggle = this.onToggle.bind(this);
|
|
2635
|
+
this.firstInputRef = /*#__PURE__*/React.createRef();
|
|
2636
|
+
}
|
|
2637
|
+
|
|
2638
|
+
isSelected(value) {
|
|
2639
|
+
const sessionValue = this.props.session && this.props.session.value;
|
|
2640
|
+
return sessionValue && sessionValue.indexOf && sessionValue.indexOf(value) >= 0;
|
|
2641
|
+
} // handleChange was added for accessibility. Please see comments and videos from PD-2441.
|
|
2642
|
+
|
|
2643
|
+
|
|
2644
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
2645
|
+
if (!nextProps.correctResponse && this.state.showCorrect !== false) {
|
|
2646
|
+
this.setState({
|
|
2647
|
+
showCorrect: false
|
|
2648
|
+
}, () => {
|
|
2649
|
+
if (this.props.onShowCorrectToggle) {
|
|
2650
|
+
this.props.onShowCorrectToggle();
|
|
2651
|
+
}
|
|
2652
|
+
});
|
|
2653
|
+
}
|
|
2654
|
+
|
|
2655
|
+
if (nextProps.alwaysShowCorrect && this.state.showCorrect !== true) {
|
|
2656
|
+
this.setState({
|
|
2657
|
+
showCorrect: true
|
|
2658
|
+
}, () => {
|
|
2659
|
+
if (this.props.onShowCorrectToggle) {
|
|
2660
|
+
this.props.onShowCorrectToggle();
|
|
2661
|
+
}
|
|
2662
|
+
});
|
|
2663
|
+
}
|
|
2664
|
+
}
|
|
2665
|
+
|
|
2666
|
+
indexToSymbol(index) {
|
|
2667
|
+
if (this.props.keyMode === 'numbers') {
|
|
2668
|
+
return `${index + 1}`;
|
|
2669
|
+
}
|
|
2670
|
+
|
|
2671
|
+
if (this.props.keyMode === 'letters') {
|
|
2672
|
+
return String.fromCharCode(97 + index).toUpperCase();
|
|
2673
|
+
}
|
|
2674
|
+
|
|
2675
|
+
return '';
|
|
2676
|
+
}
|
|
2677
|
+
|
|
2678
|
+
getChecked(choice) {
|
|
2679
|
+
// to determine if we are in evaluate mode or print mode
|
|
2680
|
+
// since both modes have showCorrect but it interferes with "browse mode" in IBX if the print props are set
|
|
2681
|
+
const isEvaluateMode = this.state.showCorrect && this.props.mode === 'evaluate';
|
|
2682
|
+
const isPrintMode = this.props.alwaysShowCorrect && (!this.props.session || !this.props.session.value || this.props.session.value.length === 0);
|
|
2683
|
+
|
|
2684
|
+
if (isEvaluateMode || isPrintMode) {
|
|
2685
|
+
return choice.correct || false;
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
return this.isSelected(choice.value);
|
|
2689
|
+
} // renderHeading function was added for accessibility.
|
|
2690
|
+
|
|
2691
|
+
|
|
2692
|
+
renderHeading() {
|
|
2693
|
+
const {
|
|
2694
|
+
mode,
|
|
2695
|
+
choiceMode,
|
|
2696
|
+
classes
|
|
2697
|
+
} = this.props;
|
|
2698
|
+
|
|
2699
|
+
if (mode !== 'gather') {
|
|
2700
|
+
return null;
|
|
2701
|
+
}
|
|
2702
|
+
|
|
2703
|
+
return choiceMode === 'radio' ? /*#__PURE__*/React.createElement("h3", {
|
|
2704
|
+
className: classes.srOnly
|
|
2705
|
+
}, "Multiple Choice Question") : /*#__PURE__*/React.createElement("h3", {
|
|
2706
|
+
className: classes.srOnly
|
|
2707
|
+
}, "Multiple Select Question");
|
|
2708
|
+
}
|
|
2709
|
+
|
|
2710
|
+
render() {
|
|
2711
|
+
const {
|
|
2712
|
+
mode,
|
|
2713
|
+
disabled,
|
|
2714
|
+
className,
|
|
2715
|
+
choices = [],
|
|
2716
|
+
choiceMode,
|
|
2717
|
+
gridColumns,
|
|
2718
|
+
partLabel,
|
|
2719
|
+
prompt,
|
|
2720
|
+
responseCorrect,
|
|
2721
|
+
teacherInstructions,
|
|
2722
|
+
classes,
|
|
2723
|
+
alwaysShowCorrect,
|
|
2724
|
+
animationsDisabled,
|
|
2725
|
+
language,
|
|
2726
|
+
isSelectionButtonBelow,
|
|
2727
|
+
minSelections,
|
|
2728
|
+
maxSelections,
|
|
2729
|
+
autoplayAudioEnabled,
|
|
2730
|
+
session,
|
|
2731
|
+
customAudioButton
|
|
2732
|
+
} = this.props;
|
|
2733
|
+
const {
|
|
2734
|
+
showCorrect,
|
|
2735
|
+
maxSelectionsErrorState
|
|
2736
|
+
} = this.state;
|
|
2737
|
+
const isEvaluateMode = mode === 'evaluate';
|
|
2738
|
+
const showCorrectAnswerToggle = isEvaluateMode && !responseCorrect;
|
|
2739
|
+
const columnsStyle = gridColumns > 1 ? {
|
|
2740
|
+
gridTemplateColumns: `repeat(${gridColumns}, 1fr)`
|
|
2741
|
+
} : undefined;
|
|
2742
|
+
const selections = session.value && session.value.length || 0;
|
|
2743
|
+
const teacherInstructionsDiv = /*#__PURE__*/React.createElement(PreviewPrompt, {
|
|
2744
|
+
tagName: "div",
|
|
2745
|
+
className: "prompt",
|
|
2746
|
+
defaultClassName: "teacher-instructions",
|
|
2747
|
+
prompt: teacherInstructions
|
|
2748
|
+
});
|
|
2749
|
+
|
|
2750
|
+
const getMultipleChoiceMinSelectionErrorMessage = () => {
|
|
2751
|
+
if (minSelections && maxSelections) {
|
|
2752
|
+
return minSelections === maxSelections ? translator.t('translation:multipleChoice:minmaxSelections_equal', {
|
|
2753
|
+
lng: language,
|
|
2754
|
+
minSelections
|
|
2755
|
+
}) : translator.t('translation:multipleChoice:minmaxSelections_range', {
|
|
2756
|
+
lng: language,
|
|
2757
|
+
minSelections,
|
|
2758
|
+
maxSelections
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2762
|
+
if (minSelections) {
|
|
2763
|
+
return translator.t('translation:multipleChoice:minSelections', {
|
|
2764
|
+
lng: language,
|
|
2765
|
+
minSelections
|
|
2766
|
+
});
|
|
2767
|
+
}
|
|
2768
|
+
|
|
2769
|
+
return '';
|
|
2770
|
+
};
|
|
2771
|
+
|
|
2772
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
2773
|
+
id: 'main-container',
|
|
2774
|
+
className: classNames(classes.main, className, 'multiple-choice')
|
|
2775
|
+
}, partLabel && /*#__PURE__*/React.createElement("h2", {
|
|
2776
|
+
className: classes.partLabel
|
|
2777
|
+
}, partLabel), this.renderHeading(), teacherInstructions && /*#__PURE__*/React.createElement("div", {
|
|
2778
|
+
className: classes.teacherInstructions
|
|
2779
|
+
}, !animationsDisabled ? /*#__PURE__*/React.createElement(Collapsible, {
|
|
2780
|
+
labels: {
|
|
2781
|
+
hidden: 'Show Teacher Instructions',
|
|
2782
|
+
visible: 'Hide Teacher Instructions'
|
|
2783
|
+
}
|
|
2784
|
+
}, teacherInstructionsDiv) : teacherInstructionsDiv), /*#__PURE__*/React.createElement("fieldset", {
|
|
2785
|
+
tabIndex: 0,
|
|
2786
|
+
className: classes.fieldset,
|
|
2787
|
+
onFocus: this.handleGroupFocus,
|
|
2788
|
+
role: choiceMode === 'radio' ? 'radiogroup' : 'group'
|
|
2789
|
+
}, /*#__PURE__*/React.createElement(PreviewPrompt, {
|
|
2790
|
+
className: "prompt",
|
|
2791
|
+
defaultClassName: "prompt",
|
|
2792
|
+
prompt: prompt,
|
|
2793
|
+
tagName: 'legend',
|
|
2794
|
+
autoplayAudioEnabled: autoplayAudioEnabled,
|
|
2795
|
+
customAudioButton: customAudioButton
|
|
2796
|
+
}), !alwaysShowCorrect && /*#__PURE__*/React.createElement(CorrectAnswerToggle, {
|
|
2797
|
+
show: showCorrectAnswerToggle,
|
|
2798
|
+
toggled: showCorrect,
|
|
2799
|
+
onToggle: this.onToggle.bind(this),
|
|
2800
|
+
language: language
|
|
2801
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
2802
|
+
className: classNames({
|
|
2803
|
+
[classes.gridLayout]: this.props.choicesLayout === 'grid',
|
|
2804
|
+
[classes.horizontalLayout]: this.props.choicesLayout === 'horizontal'
|
|
2805
|
+
}),
|
|
2806
|
+
style: columnsStyle
|
|
2807
|
+
}, choices.map((choice, index) => /*#__PURE__*/React.createElement(StyledChoice, {
|
|
2808
|
+
autoFocusRef: index === 0 ? this.firstInputRef : null,
|
|
2809
|
+
choicesLayout: this.props.choicesLayout,
|
|
2810
|
+
selectedAnswerBackgroundColor: this.props.selectedAnswerBackgroundColor,
|
|
2811
|
+
selectedAnswerStrokeColor: this.props.selectedAnswerStrokeColor,
|
|
2812
|
+
selectedAnswerStrokeWidth: this.props.selectedAnswerStrokeWidth,
|
|
2813
|
+
hoverAnswerBackgroundColor: this.props.hoverAnswerBackgroundColor,
|
|
2814
|
+
hoverAnswerStrokeColor: this.props.hoverAnswerStrokeColor,
|
|
2815
|
+
hoverAnswerStrokeWidth: this.props.hoverAnswerStrokeWidth,
|
|
2816
|
+
gridColumns: gridColumns,
|
|
2817
|
+
key: `choice-${index}`,
|
|
2818
|
+
choice: choice,
|
|
2819
|
+
index: index,
|
|
2820
|
+
choicesLength: choices.length,
|
|
2821
|
+
showCorrect: showCorrect,
|
|
2822
|
+
isEvaluateMode: isEvaluateMode,
|
|
2823
|
+
choiceMode: choiceMode,
|
|
2824
|
+
disabled: disabled,
|
|
2825
|
+
tagName: partLabel ? `group-${partLabel}` : 'group',
|
|
2826
|
+
onChoiceChanged: this.handleChange,
|
|
2827
|
+
hideTick: choice.hideTick,
|
|
2828
|
+
checked: this.getChecked(choice),
|
|
2829
|
+
correctness: isEvaluateMode ? this.getCorrectness(choice) : undefined,
|
|
2830
|
+
displayKey: this.indexToSymbol(index),
|
|
2831
|
+
isSelectionButtonBelow: isSelectionButtonBelow
|
|
2832
|
+
})))), choiceMode === 'checkbox' && selections < minSelections && /*#__PURE__*/React.createElement("div", {
|
|
2833
|
+
className: classes.errorText
|
|
2834
|
+
}, getMultipleChoiceMinSelectionErrorMessage()), choiceMode === 'checkbox' && maxSelectionsErrorState && /*#__PURE__*/React.createElement("div", {
|
|
2835
|
+
className: classes.errorText
|
|
2836
|
+
}, translator.t(`translation:multipleChoice:maxSelections_${maxSelections === 1 ? 'one' : 'other'}`, {
|
|
2837
|
+
lng: language,
|
|
2838
|
+
maxSelections
|
|
2839
|
+
})));
|
|
2840
|
+
}
|
|
2841
|
+
|
|
2842
|
+
}
|
|
2843
|
+
MultipleChoice$1.propTypes = {
|
|
2844
|
+
className: PropTypes$2.string,
|
|
2845
|
+
mode: PropTypes$2.oneOf(['gather', 'view', 'evaluate']),
|
|
2846
|
+
choiceMode: PropTypes$2.oneOf(['radio', 'checkbox']),
|
|
2847
|
+
keyMode: PropTypes$2.oneOf(['numbers', 'letters', 'none']),
|
|
2848
|
+
choices: PropTypes$2.array,
|
|
2849
|
+
partLabel: PropTypes$2.string,
|
|
2850
|
+
prompt: PropTypes$2.string,
|
|
2851
|
+
teacherInstructions: PropTypes$2.string,
|
|
2852
|
+
session: PropTypes$2.object,
|
|
2853
|
+
disabled: PropTypes$2.bool,
|
|
2854
|
+
onChoiceChanged: PropTypes$2.func,
|
|
2855
|
+
responseCorrect: PropTypes$2.bool,
|
|
2856
|
+
classes: PropTypes$2.object.isRequired,
|
|
2857
|
+
correctResponse: PropTypes$2.array,
|
|
2858
|
+
choicesLayout: PropTypes$2.oneOf(['vertical', 'grid', 'horizontal']),
|
|
2859
|
+
gridColumns: PropTypes$2.string,
|
|
2860
|
+
alwaysShowCorrect: PropTypes$2.bool,
|
|
2861
|
+
animationsDisabled: PropTypes$2.bool,
|
|
2862
|
+
language: PropTypes$2.string,
|
|
2863
|
+
selectedAnswerBackgroundColor: PropTypes$2.string,
|
|
2864
|
+
selectedAnswerStrokeColor: PropTypes$2.string,
|
|
2865
|
+
selectedAnswerStrokeWidth: PropTypes$2.string,
|
|
2866
|
+
hoverAnswerBackgroundColor: PropTypes$2.string,
|
|
2867
|
+
hoverAnswerStrokeColor: PropTypes$2.string,
|
|
2868
|
+
hoverAnswerStrokeWidth: PropTypes$2.string,
|
|
2869
|
+
onShowCorrectToggle: PropTypes$2.func,
|
|
2870
|
+
isSelectionButtonBelow: PropTypes$2.bool,
|
|
2871
|
+
minSelections: PropTypes$2.number,
|
|
2872
|
+
maxSelections: PropTypes$2.number,
|
|
2873
|
+
autoplayAudioEnabled: PropTypes$2.bool,
|
|
2874
|
+
customAudioButton: {
|
|
2875
|
+
playImage: PropTypes$2.string,
|
|
2876
|
+
pauseImage: PropTypes$2.string
|
|
2877
|
+
}
|
|
2878
|
+
};
|
|
2879
|
+
MultipleChoice$1.defaultProps = {
|
|
2880
|
+
session: {
|
|
2881
|
+
value: []
|
|
2882
|
+
}
|
|
2883
|
+
};
|
|
2884
|
+
var MultipleChoice$2 = withStyles(styles$1)(MultipleChoice$1);
|
|
2885
|
+
|
|
2886
|
+
const styles = () => ({});
|
|
2887
|
+
|
|
2888
|
+
class Main extends React.Component {
|
|
2889
|
+
constructor(props) {
|
|
2890
|
+
super(props);
|
|
2891
|
+
}
|
|
2892
|
+
|
|
2893
|
+
render() {
|
|
2894
|
+
const {
|
|
2895
|
+
model,
|
|
2896
|
+
onChoiceChanged,
|
|
2897
|
+
session,
|
|
2898
|
+
onShowCorrectToggle
|
|
2899
|
+
} = this.props;
|
|
2900
|
+
const {
|
|
2901
|
+
extraCSSRules,
|
|
2902
|
+
fontSizeFactor
|
|
2903
|
+
} = model; // model.partLabel is a property used for ebsr
|
|
2904
|
+
|
|
2905
|
+
return /*#__PURE__*/React.createElement(PreviewLayout, {
|
|
2906
|
+
extraCSSRules: extraCSSRules,
|
|
2907
|
+
fontSizeFactor: fontSizeFactor
|
|
2908
|
+
}, /*#__PURE__*/React.createElement(MultipleChoice$2, _extends({}, model, {
|
|
2909
|
+
session: session,
|
|
2910
|
+
onChoiceChanged: onChoiceChanged,
|
|
2911
|
+
onShowCorrectToggle: onShowCorrectToggle
|
|
2912
|
+
})));
|
|
2913
|
+
}
|
|
2914
|
+
|
|
2915
|
+
}
|
|
2916
|
+
|
|
2917
|
+
Main.propTypes = {
|
|
2918
|
+
model: PropTypes$2.object,
|
|
2919
|
+
session: PropTypes$2.object,
|
|
2920
|
+
onChoiceChanged: PropTypes$2.func,
|
|
2921
|
+
classes: PropTypes$2.object.isRequired,
|
|
2922
|
+
onShowCorrectToggle: PropTypes$2.func,
|
|
2923
|
+
extraCSSRules: PropTypes$2.shape({
|
|
2924
|
+
names: PropTypes$2.arrayOf(PropTypes$2.string),
|
|
2925
|
+
rules: PropTypes$2.string
|
|
2926
|
+
})
|
|
2927
|
+
};
|
|
2928
|
+
Main.defaultProps = {
|
|
2929
|
+
model: {},
|
|
2930
|
+
session: {}
|
|
2931
|
+
};
|
|
2932
|
+
const Styled = withStyles(styles, {
|
|
2933
|
+
name: 'Main'
|
|
2934
|
+
})(Main);
|
|
2935
|
+
const theme = createMuiTheme({
|
|
2936
|
+
typography: {
|
|
2937
|
+
useNextVariants: true
|
|
2938
|
+
}
|
|
2939
|
+
});
|
|
2940
|
+
|
|
2941
|
+
const Root = props => /*#__PURE__*/React.createElement(MuiThemeProvider, {
|
|
2942
|
+
theme: theme
|
|
2943
|
+
}, /*#__PURE__*/React.createElement(Styled, props));
|
|
2944
|
+
|
|
2945
|
+
function updateSessionValue(session, choiceMode, data) {
|
|
2946
|
+
session.value = session.value || [];
|
|
2947
|
+
|
|
2948
|
+
if (choiceMode === 'checkbox') {
|
|
2949
|
+
if (data.selected) {
|
|
2950
|
+
session.value = Array.from(new Set([...session.value, data.value]));
|
|
2951
|
+
} else {
|
|
2952
|
+
session.value = session.value.filter(v => v !== data.value);
|
|
2953
|
+
}
|
|
2954
|
+
}
|
|
2955
|
+
|
|
2956
|
+
if (choiceMode === 'radio') {
|
|
2957
|
+
if (data.selected) {
|
|
2958
|
+
session.value = [data.value];
|
|
2959
|
+
} else {
|
|
2960
|
+
session.value = [];
|
|
2961
|
+
}
|
|
2962
|
+
} //update session value metadata
|
|
2963
|
+
|
|
2964
|
+
|
|
2965
|
+
session.selector = data.selector; //the input method used to select the choice (e.g. mouse, keyboard)
|
|
2966
|
+
}
|
|
2967
|
+
function updateSessionMetadata(session, metadata) {
|
|
2968
|
+
session.audioStartTime = session.audioStartTime || metadata.audioStartTime; //timestamp when auto-played audio started playing
|
|
2969
|
+
|
|
2970
|
+
session.audioEndTime = session.audioEndTime || metadata.audioEndTime; //timestamp when auto-played audio completed playing
|
|
2971
|
+
|
|
2972
|
+
if (!session.waitTime && session.audioStartTime && session.audioEndTime) {
|
|
2973
|
+
// waitTime is elapsed time the user waited for auto-played audio to finish
|
|
2974
|
+
session.waitTime = session.audioEndTime - session.audioStartTime;
|
|
2975
|
+
}
|
|
2976
|
+
}
|
|
2977
|
+
|
|
2978
|
+
const log = debug('pie-ui:multiple-choice');
|
|
2979
|
+
const isComplete = (session, model, audioComplete, elementContext) => {
|
|
2980
|
+
const {
|
|
2981
|
+
autoplayAudioEnabled,
|
|
2982
|
+
completeAudioEnabled
|
|
2983
|
+
} = model || {}; // check audio completion if audio settings are enabled and audio actually exists
|
|
2984
|
+
|
|
2985
|
+
if (autoplayAudioEnabled && completeAudioEnabled && !audioComplete) {
|
|
2986
|
+
if (elementContext) {
|
|
2987
|
+
const audio = elementContext.querySelector('audio');
|
|
2988
|
+
const isInsidePrompt = audio && audio.closest('#preview-prompt'); // only require audio completion if audio exists and is inside the prompt
|
|
2989
|
+
|
|
2990
|
+
if (audio && isInsidePrompt) {
|
|
2991
|
+
return false;
|
|
2992
|
+
}
|
|
2993
|
+
}
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
if (!session || !session.value) {
|
|
2997
|
+
return false;
|
|
2998
|
+
}
|
|
2999
|
+
|
|
3000
|
+
const {
|
|
3001
|
+
choiceMode,
|
|
3002
|
+
minSelections = 1,
|
|
3003
|
+
maxSelections
|
|
3004
|
+
} = model || {};
|
|
3005
|
+
const selections = session.value.length || 0;
|
|
3006
|
+
|
|
3007
|
+
if (choiceMode === 'radio') {
|
|
3008
|
+
return !!selections;
|
|
3009
|
+
}
|
|
3010
|
+
|
|
3011
|
+
if (selections < minSelections || selections > maxSelections) {
|
|
3012
|
+
return false;
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
return true;
|
|
3016
|
+
};
|
|
3017
|
+
class MultipleChoice extends HTMLElement {
|
|
3018
|
+
constructor() {
|
|
3019
|
+
super();
|
|
3020
|
+
this._model = null;
|
|
3021
|
+
this._session = null;
|
|
3022
|
+
this.audioComplete = false;
|
|
3023
|
+
this._boundHandleKeyDown = this.handleKeyDown.bind(this);
|
|
3024
|
+
this._keyboardEventsEnabled = false;
|
|
3025
|
+
this._audioInitialized = false;
|
|
3026
|
+
this._rerender = debounce(() => {
|
|
3027
|
+
if (this._model && this._session) {
|
|
3028
|
+
var element = /*#__PURE__*/React.createElement(Root, {
|
|
3029
|
+
model: this._model,
|
|
3030
|
+
session: this._session,
|
|
3031
|
+
onChoiceChanged: this._onChange.bind(this),
|
|
3032
|
+
onShowCorrectToggle: this.onShowCorrectToggle.bind(this)
|
|
3033
|
+
}); //TODO: aria-label is set in the _rerender because we need to change it when the model.choiceMode is updated. Consider revisiting the placement of the aria-label setting in the _rerender
|
|
3034
|
+
|
|
3035
|
+
this.setAttribute('aria-label', this._model.choiceMode === 'radio' ? 'Multiple Choice Question' : 'Multiple Correct Answer Question');
|
|
3036
|
+
this.setAttribute('role', 'region');
|
|
3037
|
+
this.setLangAttribute();
|
|
3038
|
+
require$$2$1.render(element, this, () => {
|
|
3039
|
+
log('render complete - render math');
|
|
3040
|
+
renderMath(this);
|
|
3041
|
+
});
|
|
3042
|
+
|
|
3043
|
+
if (this._model.keyboardEventsEnabled === true && !this._keyboardEventsEnabled) {
|
|
3044
|
+
this.enableKeyboardEvents();
|
|
3045
|
+
}
|
|
3046
|
+
} else {
|
|
3047
|
+
log('skip');
|
|
3048
|
+
}
|
|
3049
|
+
}, 50, {
|
|
3050
|
+
leading: false,
|
|
3051
|
+
trailing: true
|
|
3052
|
+
});
|
|
3053
|
+
this._dispatchResponseChanged = debounce(() => {
|
|
3054
|
+
this.dispatchEvent(new SessionChangedEvent(this.tagName.toLowerCase(), isComplete(this._session, this._model, this.audioComplete, this)));
|
|
3055
|
+
});
|
|
3056
|
+
this._dispatchModelSet = debounce(() => {
|
|
3057
|
+
this.dispatchEvent(new ModelSetEvent(this.tagName.toLowerCase(), isComplete(this._session, this._model, this.audioComplete, this), this._model !== undefined));
|
|
3058
|
+
}, 50, {
|
|
3059
|
+
leading: false,
|
|
3060
|
+
trailing: true
|
|
3061
|
+
});
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
onShowCorrectToggle() {
|
|
3065
|
+
renderMath(this);
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
setLangAttribute() {
|
|
3069
|
+
const language = this._model && typeof this._model.language ? this._model.language : '';
|
|
3070
|
+
const lang = language ? language.slice(0, 2) : 'en';
|
|
3071
|
+
this.setAttribute('lang', lang);
|
|
3072
|
+
}
|
|
3073
|
+
|
|
3074
|
+
set model(s) {
|
|
3075
|
+
this._model = s;
|
|
3076
|
+
|
|
3077
|
+
this._rerender(); // reset the audioInitialized to false since the model changed, and we might need to reinitialize the audio
|
|
3078
|
+
|
|
3079
|
+
|
|
3080
|
+
this._audioInitialized = false;
|
|
3081
|
+
|
|
3082
|
+
this._dispatchModelSet();
|
|
3083
|
+
}
|
|
3084
|
+
|
|
3085
|
+
get session() {
|
|
3086
|
+
return this._session;
|
|
3087
|
+
}
|
|
3088
|
+
|
|
3089
|
+
set session(s) {
|
|
3090
|
+
this._session = s;
|
|
3091
|
+
|
|
3092
|
+
this._rerender(); //TODO: remove this session-changed should only be emit on user change
|
|
3093
|
+
|
|
3094
|
+
|
|
3095
|
+
this._dispatchResponseChanged();
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
_onChange(data) {
|
|
3099
|
+
updateSessionValue(this._session, this._model.choiceMode, data);
|
|
3100
|
+
|
|
3101
|
+
this._dispatchResponseChanged();
|
|
3102
|
+
|
|
3103
|
+
this._rerender();
|
|
3104
|
+
}
|
|
3105
|
+
|
|
3106
|
+
_createAudioInfoToast() {
|
|
3107
|
+
const info = document.createElement('div');
|
|
3108
|
+
info.id = 'play-audio-info';
|
|
3109
|
+
Object.assign(info.style, {
|
|
3110
|
+
position: 'absolute',
|
|
3111
|
+
top: 0,
|
|
3112
|
+
width: '100%',
|
|
3113
|
+
height: '100%',
|
|
3114
|
+
display: 'flex',
|
|
3115
|
+
justifyContent: 'center',
|
|
3116
|
+
alignItems: 'center',
|
|
3117
|
+
background: 'white',
|
|
3118
|
+
zIndex: '1000',
|
|
3119
|
+
cursor: 'pointer'
|
|
3120
|
+
});
|
|
3121
|
+
const img = document.createElement('img');
|
|
3122
|
+
img.src = EnableAudioAutoplayImage;
|
|
3123
|
+
img.alt = 'Click anywhere to enable audio autoplay';
|
|
3124
|
+
img.width = 500;
|
|
3125
|
+
img.height = 300;
|
|
3126
|
+
info.appendChild(img);
|
|
3127
|
+
return info;
|
|
3128
|
+
}
|
|
3129
|
+
|
|
3130
|
+
connectedCallback() {
|
|
3131
|
+
this._rerender(); // Observation: audio in Chrome will have the autoplay attribute,
|
|
3132
|
+
// while other browsers will not have the autoplay attribute and will need a user interaction to play the audio
|
|
3133
|
+
// This workaround fixes the issue of audio being cached and played on any user interaction in Safari and Firefox
|
|
3134
|
+
|
|
3135
|
+
|
|
3136
|
+
const observer = new MutationObserver((mutationsList, observer) => {
|
|
3137
|
+
mutationsList.forEach(mutation => {
|
|
3138
|
+
if (mutation.type === 'childList') {
|
|
3139
|
+
if (this._audioInitialized) return;
|
|
3140
|
+
const audio = this.querySelector('audio');
|
|
3141
|
+
const isInsidePrompt = audio && audio.closest('#preview-prompt');
|
|
3142
|
+
if (!this._model) return;
|
|
3143
|
+
if (!this._model.autoplayAudioEnabled) return;
|
|
3144
|
+
if (audio && !isInsidePrompt) return;
|
|
3145
|
+
if (!audio) return;
|
|
3146
|
+
|
|
3147
|
+
const info = this._createAudioInfoToast();
|
|
3148
|
+
|
|
3149
|
+
const container = this.querySelector('#main-container');
|
|
3150
|
+
|
|
3151
|
+
const enableAudio = () => {
|
|
3152
|
+
if (this.querySelector('#play-audio-info')) {
|
|
3153
|
+
audio.play();
|
|
3154
|
+
container.removeChild(info);
|
|
3155
|
+
}
|
|
3156
|
+
|
|
3157
|
+
document.removeEventListener('click', enableAudio);
|
|
3158
|
+
}; // if the audio is paused, it means the user has not interacted with the page yet and the audio will not play
|
|
3159
|
+
// FIX FOR SAFARI: play with a slight delay to check if autoplay was blocked
|
|
3160
|
+
|
|
3161
|
+
|
|
3162
|
+
setTimeout(() => {
|
|
3163
|
+
if (audio.paused && !this.querySelector('#play-audio-info')) {
|
|
3164
|
+
// add info message as a toast to enable audio playback
|
|
3165
|
+
container.appendChild(info);
|
|
3166
|
+
document.addEventListener('click', enableAudio);
|
|
3167
|
+
} else {
|
|
3168
|
+
document.removeEventListener('click', enableAudio);
|
|
3169
|
+
}
|
|
3170
|
+
}, 500); // we need to listen for the playing event to remove the toast in case the audio plays because of re-rendering
|
|
3171
|
+
|
|
3172
|
+
const handlePlaying = () => {
|
|
3173
|
+
updateSessionMetadata(this._session, {
|
|
3174
|
+
audioStartTime: new Date().getTime()
|
|
3175
|
+
});
|
|
3176
|
+
const info = this.querySelector('#play-audio-info');
|
|
3177
|
+
|
|
3178
|
+
if (info) {
|
|
3179
|
+
container.removeChild(info);
|
|
3180
|
+
}
|
|
3181
|
+
|
|
3182
|
+
audio.removeEventListener('playing', handlePlaying);
|
|
3183
|
+
};
|
|
3184
|
+
|
|
3185
|
+
audio.addEventListener('playing', handlePlaying); // we need to listen for the ended event to update the isComplete state
|
|
3186
|
+
|
|
3187
|
+
const handleEnded = () => {
|
|
3188
|
+
updateSessionMetadata(this._session, {
|
|
3189
|
+
audioEndTime: new Date().getTime()
|
|
3190
|
+
});
|
|
3191
|
+
this.audioComplete = true;
|
|
3192
|
+
|
|
3193
|
+
this._dispatchResponseChanged();
|
|
3194
|
+
|
|
3195
|
+
audio.removeEventListener('ended', handleEnded);
|
|
3196
|
+
};
|
|
3197
|
+
|
|
3198
|
+
audio.addEventListener('ended', handleEnded); // store references to remove later
|
|
3199
|
+
|
|
3200
|
+
this._audio = audio;
|
|
3201
|
+
this._handlePlaying = handlePlaying;
|
|
3202
|
+
this._handleEnded = handleEnded;
|
|
3203
|
+
this._enableAudio = enableAudio; // set to true to prevent multiple initializations
|
|
3204
|
+
|
|
3205
|
+
this._audioInitialized = true;
|
|
3206
|
+
observer.disconnect();
|
|
3207
|
+
}
|
|
3208
|
+
});
|
|
3209
|
+
});
|
|
3210
|
+
observer.observe(this, {
|
|
3211
|
+
childList: true,
|
|
3212
|
+
subtree: true
|
|
3213
|
+
});
|
|
3214
|
+
}
|
|
3215
|
+
|
|
3216
|
+
enableKeyboardEvents() {
|
|
3217
|
+
if (!this._keyboardEventsEnabled) {
|
|
3218
|
+
window.addEventListener('keydown', this._boundHandleKeyDown);
|
|
3219
|
+
this._keyboardEventsEnabled = true;
|
|
3220
|
+
}
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3223
|
+
disconnectedCallback() {
|
|
3224
|
+
if (this._keyboardEventsEnabled) {
|
|
3225
|
+
window.removeEventListener('keydown', this._boundHandleKeyDown);
|
|
3226
|
+
this._keyboardEventsEnabled = false;
|
|
3227
|
+
}
|
|
3228
|
+
|
|
3229
|
+
document.removeEventListener('click', this._enableAudio);
|
|
3230
|
+
|
|
3231
|
+
if (this._audio) {
|
|
3232
|
+
this._audio.removeEventListener('playing', this._handlePlaying);
|
|
3233
|
+
|
|
3234
|
+
this._audio.removeEventListener('ended', this._handleEnded);
|
|
3235
|
+
|
|
3236
|
+
this._audio = null;
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
/**
|
|
3240
|
+
* Handles global keyboard events for selecting or toggling multiple-choice answers.
|
|
3241
|
+
* Maps keys (1-9, 0, a-j, A-J) to choices and updates the session state accordingly.
|
|
3242
|
+
* Ensures valid key presses toggle or select the appropriate choice based on the model.
|
|
3243
|
+
*/
|
|
3244
|
+
|
|
3245
|
+
|
|
3246
|
+
handleKeyDown(event) {
|
|
3247
|
+
var _this$_model$choices;
|
|
3248
|
+
|
|
3249
|
+
if (!this._model || !this._session) {
|
|
3250
|
+
return;
|
|
3251
|
+
}
|
|
3252
|
+
|
|
3253
|
+
const {
|
|
3254
|
+
mode
|
|
3255
|
+
} = this._model;
|
|
3256
|
+
|
|
3257
|
+
if (mode !== 'gather') {
|
|
3258
|
+
return;
|
|
3259
|
+
}
|
|
3260
|
+
|
|
3261
|
+
const keyToIndex = key => {
|
|
3262
|
+
const numOffset = key >= '1' && key <= '9' ? key - '1' : key === '0' ? 9 : -1;
|
|
3263
|
+
const letterOffset = /^[a-jA-J]$/.test(key) ? key.toLowerCase().charCodeAt(0) - 'a'.charCodeAt(0) : -1;
|
|
3264
|
+
return numOffset >= 0 ? numOffset : letterOffset;
|
|
3265
|
+
};
|
|
3266
|
+
|
|
3267
|
+
const choiceIndex = keyToIndex(event.key);
|
|
3268
|
+
|
|
3269
|
+
if (choiceIndex === undefined || choiceIndex <= -1 || choiceIndex >= ((_this$_model$choices = this._model.choices) == null ? void 0 : _this$_model$choices.length)) {
|
|
3270
|
+
return;
|
|
3271
|
+
}
|
|
3272
|
+
|
|
3273
|
+
const currentValue = this._session.value || [];
|
|
3274
|
+
const choiceId = this._model.choices[choiceIndex].value;
|
|
3275
|
+
const newValue = {
|
|
3276
|
+
value: choiceId,
|
|
3277
|
+
selected: !currentValue.includes(choiceId),
|
|
3278
|
+
selector: 'Keyboard'
|
|
3279
|
+
};
|
|
3280
|
+
|
|
3281
|
+
this._onChange(newValue);
|
|
3282
|
+
}
|
|
3283
|
+
|
|
3284
|
+
}
|
|
3285
|
+
|
|
3286
|
+
export { MultipleChoice as default, isComplete };
|
|
3287
|
+
//# sourceMappingURL=element.js.map
|