@khanacademy/perseus 0.0.1 → 0.2.1

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.
Files changed (507) hide show
  1. package/.babelrc.js +1 -1
  2. package/CHANGELOG.md +29 -0
  3. package/dist/es/index.css +4361 -0
  4. package/dist/es/index.js +7 -1
  5. package/dist/es/index.js.map +1 -1
  6. package/dist/index.css +4361 -0
  7. package/dist/index.js +7 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/strings.js +148 -46
  10. package/package.json +50 -4
  11. package/src/README.md +35 -0
  12. package/src/__stories__/item-renderer.stories.jsx +27 -0
  13. package/src/__stories__/server-item-renderer.stories.jsx +27 -0
  14. package/src/__testdata__/item-renderer_testdata.js +161 -0
  15. package/src/__testdata__/renderer_testdata.js +123 -0
  16. package/src/__tests__/__snapshots__/item-renderer_test.jsx.snap +233 -0
  17. package/src/__tests__/__snapshots__/perseus-markdown_test.jsx.snap +516 -0
  18. package/src/__tests__/__snapshots__/pure-markdown_test.js.snap +113 -0
  19. package/src/__tests__/__snapshots__/renderer_test.jsx.snap +576 -0
  20. package/src/__tests__/__snapshots__/server-item-renderer_test.jsx.snap +306 -0
  21. package/src/__tests__/a11y_test.jsx +304 -0
  22. package/src/__tests__/item-renderer_test.jsx +892 -0
  23. package/src/__tests__/mock-asset-loading-widget.jsx +57 -0
  24. package/src/__tests__/mock-widget.jsx +35 -0
  25. package/src/__tests__/perseus-markdown_test.jsx +747 -0
  26. package/src/__tests__/pure-markdown_test.js +552 -0
  27. package/src/__tests__/renderability_test.jsx +481 -0
  28. package/src/__tests__/renderer-api_test.jsx +333 -0
  29. package/src/__tests__/renderer_test.jsx +1792 -0
  30. package/src/__tests__/server-item-renderer_test.jsx +516 -0
  31. package/src/__tests__/test-items/image-item.js +25 -0
  32. package/src/__tests__/test-items/input-number-1-item.js +27 -0
  33. package/src/__tests__/test-items/input-number-2-item.js +39 -0
  34. package/src/__tests__/test-items/table-item.js +30 -0
  35. package/src/__tests__/tex-wrangler_test.js +83 -0
  36. package/src/__tests__/util_test.js +41 -0
  37. package/src/a11y.js +46 -0
  38. package/src/all-widgets.js +9 -0
  39. package/src/article-renderer.jsx +215 -0
  40. package/src/asset-context.js +30 -0
  41. package/src/basic-widgets.js +13 -0
  42. package/src/components/__stories__/button-group.stories.jsx +61 -0
  43. package/src/components/__stories__/fixed-to-responsive.stories.jsx +132 -0
  44. package/src/components/__stories__/graph.stories.jsx +27 -0
  45. package/src/components/__stories__/graphie.stories.jsx +28 -0
  46. package/src/components/__stories__/hud.stories.jsx +36 -0
  47. package/src/components/__stories__/icon.stories.jsx +56 -0
  48. package/src/components/__stories__/image-loader.stories.jsx +60 -0
  49. package/src/components/__stories__/info-tip.stories.jsx +33 -0
  50. package/src/components/__stories__/inline-icon.stories.jsx +39 -0
  51. package/src/components/__stories__/input-with-examples.stories.jsx +51 -0
  52. package/src/components/__stories__/lint.stories.jsx +40 -0
  53. package/src/components/__stories__/math-input.stories.jsx +29 -0
  54. package/src/components/__stories__/math-output.stories.jsx +24 -0
  55. package/src/components/__stories__/multi-button-group.stories.jsx +69 -0
  56. package/src/components/__stories__/number-input.stories.jsx +42 -0
  57. package/src/components/__stories__/possible-answers.stories.jsx +22 -0
  58. package/src/components/__stories__/prop-check-box.stories.jsx +62 -0
  59. package/src/components/__stories__/range-input.stories.jsx +28 -0
  60. package/src/components/__stories__/simple-keypad-input.stories.jsx +28 -0
  61. package/src/components/__stories__/sortable.stories.jsx +73 -0
  62. package/src/components/__stories__/stub-tag-editor.stories.jsx +44 -0
  63. package/src/components/__stories__/svg-image.stories.jsx +60 -0
  64. package/src/components/__stories__/tex.stories.jsx +18 -0
  65. package/src/components/__stories__/text-buttons.stories.jsx +51 -0
  66. package/src/components/__stories__/text-input.stories.jsx +34 -0
  67. package/src/components/__stories__/text-list-editor.stories.jsx +33 -0
  68. package/src/components/__stories__/zoomable-tex.stories.jsx +39 -0
  69. package/src/components/__stories__/zoomable.stories.jsx +40 -0
  70. package/src/components/__testdata__/sorter_testdata.js +20 -0
  71. package/src/components/__tests__/__snapshots__/sortable_test.jsx.snap +79 -0
  72. package/src/components/__tests__/__snapshots__/sorter_test.jsx.snap +297 -0
  73. package/src/components/__tests__/number-input_test.jsx +112 -0
  74. package/src/components/__tests__/sortable_test.jsx +234 -0
  75. package/src/components/__tests__/sorter_test.jsx +111 -0
  76. package/src/components/__tests__/zoomable_test.jsx +388 -0
  77. package/src/components/button-group.jsx +131 -0
  78. package/src/components/constants.js +15 -0
  79. package/src/components/fixed-to-responsive.jsx +164 -0
  80. package/src/components/graph.jsx +415 -0
  81. package/src/components/graphie-classes.jsx +148 -0
  82. package/src/components/graphie-movables.jsx +342 -0
  83. package/src/components/graphie.jsx +353 -0
  84. package/src/components/highlighting/highlightable-content.jsx +245 -0
  85. package/src/components/highlighting/highlights.js +208 -0
  86. package/src/components/highlighting/ranges.js +299 -0
  87. package/src/components/highlighting/types.js +73 -0
  88. package/src/components/highlighting/ui/highlight-renderer.jsx +179 -0
  89. package/src/components/highlighting/ui/highlight-set-renderer.jsx +190 -0
  90. package/src/components/highlighting/ui/highlight-tooltip.jsx +153 -0
  91. package/src/components/highlighting/ui/highlighting-ui.jsx +163 -0
  92. package/src/components/highlighting/ui/selection-tracker.jsx +195 -0
  93. package/src/components/highlighting/ui/types.js +21 -0
  94. package/src/components/highlighting/ui/util.js +166 -0
  95. package/src/components/highlighting/word-indexer.jsx +155 -0
  96. package/src/components/hud.jsx +179 -0
  97. package/src/components/icon.jsx +149 -0
  98. package/src/components/image-loader.jsx +175 -0
  99. package/src/components/info-tip/info-tip.jsx +146 -0
  100. package/src/components/info-tip.jsx +38 -0
  101. package/src/components/inline-icon.jsx +81 -0
  102. package/src/components/input-with-examples.jsx +231 -0
  103. package/src/components/lint.jsx +454 -0
  104. package/src/components/math-input.jsx +282 -0
  105. package/src/components/math-output.jsx +128 -0
  106. package/src/components/multi-button-group.jsx +137 -0
  107. package/src/components/new-tooltip/README.md +110 -0
  108. package/src/components/new-tooltip/__stories__/flexible-position.stories.jsx +437 -0
  109. package/src/components/new-tooltip/__stories__/new-tooltip.stories.jsx +665 -0
  110. package/src/components/new-tooltip/__stories__/tooltip-arrow.stories.jsx +70 -0
  111. package/src/components/new-tooltip/__stories__/tooltip-bubble.stories.jsx +98 -0
  112. package/src/components/new-tooltip/__tests__/style-constants_test.js +8 -0
  113. package/src/components/new-tooltip/__tests__/util_test.js +47 -0
  114. package/src/components/new-tooltip/flexible-position.jsx +182 -0
  115. package/src/components/new-tooltip/new-tooltip.jsx +399 -0
  116. package/src/components/new-tooltip/style-constants.js +13 -0
  117. package/src/components/new-tooltip/tooltip-arrow.jsx +184 -0
  118. package/src/components/new-tooltip/tooltip-bubble.jsx +223 -0
  119. package/src/components/new-tooltip/tooltip-portal.jsx +101 -0
  120. package/src/components/new-tooltip/tooltip-positioner.jsx +529 -0
  121. package/src/components/new-tooltip/types.js +183 -0
  122. package/src/components/new-tooltip/util.js +27 -0
  123. package/src/components/number-input.jsx +253 -0
  124. package/src/components/possible-answers.jsx +36 -0
  125. package/src/components/prop-check-box.jsx +80 -0
  126. package/src/components/range-input.jsx +61 -0
  127. package/src/components/simple-keypad-input.jsx +91 -0
  128. package/src/components/sortable.jsx +873 -0
  129. package/src/components/stub-tag-editor.jsx +54 -0
  130. package/src/components/svg-image.jsx +762 -0
  131. package/src/components/tex-buttons.jsx +322 -0
  132. package/src/components/tex.jsx +70 -0
  133. package/src/components/text-input.jsx +82 -0
  134. package/src/components/text-list-editor.jsx +157 -0
  135. package/src/components/tooltip.jsx +395 -0
  136. package/src/components/visibility-observer/__stories__/visibility-observer.stories.jsx +140 -0
  137. package/src/components/visibility-observer/get-scroll-parent.js +45 -0
  138. package/src/components/visibility-observer/visibility-observer.js +109 -0
  139. package/src/components/visibility-observer/visibility-observer.jsx +123 -0
  140. package/src/components/zoomable-tex.jsx +70 -0
  141. package/src/components/zoomable.jsx +304 -0
  142. package/src/components.js +17 -0
  143. package/src/dependencies.js +22 -0
  144. package/src/error-boundary.jsx +48 -0
  145. package/src/extra-widgets.js +75 -0
  146. package/src/gorgon/README +40 -0
  147. package/src/gorgon/__tests__/matcher_test.js +497 -0
  148. package/src/gorgon/__tests__/rule_test.js +101 -0
  149. package/src/gorgon/__tests__/rules_test.js +487 -0
  150. package/src/gorgon/__tests__/selector-parser_test.js +52 -0
  151. package/src/gorgon/__tests__/tree-transformer_test.js +446 -0
  152. package/src/gorgon/gorgon.js +290 -0
  153. package/src/gorgon/proptypes.js +29 -0
  154. package/src/gorgon/rule.js +413 -0
  155. package/src/gorgon/rules/absolute-url.js +24 -0
  156. package/src/gorgon/rules/all-rules.js +72 -0
  157. package/src/gorgon/rules/blockquoted-math.js +10 -0
  158. package/src/gorgon/rules/blockquoted-widget.js +10 -0
  159. package/src/gorgon/rules/double-spacing-after-terminal.js +12 -0
  160. package/src/gorgon/rules/extra-content-spacing.js +12 -0
  161. package/src/gorgon/rules/heading-level-1.js +14 -0
  162. package/src/gorgon/rules/heading-level-skip.js +20 -0
  163. package/src/gorgon/rules/heading-sentence-case.js +11 -0
  164. package/src/gorgon/rules/heading-title-case.js +63 -0
  165. package/src/gorgon/rules/image-alt-text.js +21 -0
  166. package/src/gorgon/rules/image-in-table.js +10 -0
  167. package/src/gorgon/rules/image-spaces-around-urls.js +35 -0
  168. package/src/gorgon/rules/image-widget.js +50 -0
  169. package/src/gorgon/rules/link-click-here.js +11 -0
  170. package/src/gorgon/rules/lint-utils.js +48 -0
  171. package/src/gorgon/rules/long-paragraph.js +14 -0
  172. package/src/gorgon/rules/math-adjacent.js +10 -0
  173. package/src/gorgon/rules/math-align-extra-break.js +11 -0
  174. package/src/gorgon/rules/math-align-linebreaks.js +43 -0
  175. package/src/gorgon/rules/math-empty.js +10 -0
  176. package/src/gorgon/rules/math-font-size.js +12 -0
  177. package/src/gorgon/rules/math-frac.js +10 -0
  178. package/src/gorgon/rules/math-nested.js +11 -0
  179. package/src/gorgon/rules/math-starts-with-space.js +12 -0
  180. package/src/gorgon/rules/math-text-empty.js +10 -0
  181. package/src/gorgon/rules/math-without-dollars.js +14 -0
  182. package/src/gorgon/rules/nested-lists.js +11 -0
  183. package/src/gorgon/rules/profanity.js +10 -0
  184. package/src/gorgon/rules/table-missing-cells.js +20 -0
  185. package/src/gorgon/rules/unbalanced-code-delimiters.js +14 -0
  186. package/src/gorgon/rules/unescaped-dollar.js +10 -0
  187. package/src/gorgon/rules/widget-in-table.js +10 -0
  188. package/src/gorgon/selector.js +506 -0
  189. package/src/gorgon/tree-transformer.js +588 -0
  190. package/src/hint-renderer.jsx +159 -0
  191. package/src/hints-renderer.jsx +359 -0
  192. package/src/icon-paths.js +120 -0
  193. package/src/index.js +149 -2
  194. package/src/init.js +49 -0
  195. package/src/interaction-tracker.js +60 -0
  196. package/src/interactive2/__tests__/movable-mock.js +48 -0
  197. package/src/interactive2/__tests__/movable-point_test.js +146 -0
  198. package/src/interactive2/interactive-util.js +152 -0
  199. package/src/interactive2/movable-helper-methods.js +160 -0
  200. package/src/interactive2/movable-line-options.js +392 -0
  201. package/src/interactive2/movable-line.js +322 -0
  202. package/src/interactive2/movable-point-options.js +190 -0
  203. package/src/interactive2/movable-point.jsx +603 -0
  204. package/src/interactive2/movable-polygon-options.js +351 -0
  205. package/src/interactive2/movable-polygon.js +368 -0
  206. package/src/interactive2/movable.js +273 -0
  207. package/src/interactive2/objective_.js +79 -0
  208. package/src/interactive2/types.js +3 -0
  209. package/src/interactive2/wrapped-defaults.js +86 -0
  210. package/src/interactive2/wrapped-ellipse.js +87 -0
  211. package/src/interactive2/wrapped-line.js +109 -0
  212. package/src/interactive2/wrapped-path.js +47 -0
  213. package/src/interactive2.js +91 -0
  214. package/src/item-renderer.jsx +518 -0
  215. package/src/item-version.js +12 -0
  216. package/src/jipt-paragraphs.js +44 -0
  217. package/src/jquery.mobile.vmouse.js +545 -0
  218. package/src/keypad-context.js +33 -0
  219. package/src/loading-context.js +20 -0
  220. package/src/logging/log.js +107 -0
  221. package/src/logging/log_test.js +41 -0
  222. package/src/mixins/changeable.jsx +115 -0
  223. package/src/mixins/editor-jsonify.jsx +13 -0
  224. package/src/mixins/provide-keypad.jsx +129 -0
  225. package/src/mixins/widget-jsonify-deprecated.jsx +23 -0
  226. package/src/mixins/widget-prop-blacklist.js +36 -0
  227. package/src/multi-items/__stories__/multi-renderer.stories.js +88 -0
  228. package/src/multi-items/__testdata__/multi-renderer_testdata.js +174 -0
  229. package/src/multi-items/__tests__/__snapshots__/multi-renderer_test.js.snap +994 -0
  230. package/src/multi-items/__tests__/items_test.js +245 -0
  231. package/src/multi-items/__tests__/multi-renderer_test.js +903 -0
  232. package/src/multi-items/__tests__/prop-type-builders_test.js +134 -0
  233. package/src/multi-items/__tests__/shapes_test.js +44 -0
  234. package/src/multi-items/__tests__/trees_test.js +316 -0
  235. package/src/multi-items/item-types.js +55 -0
  236. package/src/multi-items/items.js +176 -0
  237. package/src/multi-items/multi-renderer.jsx +543 -0
  238. package/src/multi-items/prop-type-builders.js +105 -0
  239. package/src/multi-items/shape-types.js +47 -0
  240. package/src/multi-items/shapes.js +53 -0
  241. package/src/multi-items/tree-types.js +42 -0
  242. package/src/multi-items/trees.js +345 -0
  243. package/src/multi-items.js +76 -0
  244. package/src/not-gorgon.js +129 -0
  245. package/src/perseus-api.jsx +270 -0
  246. package/src/perseus-env.js +26 -0
  247. package/src/perseus-error.js +19 -0
  248. package/src/perseus-markdown.jsx +433 -0
  249. package/src/perseus-types.js +1597 -0
  250. package/src/pure-markdown.js +347 -0
  251. package/src/question-paragraph.jsx +30 -0
  252. package/src/renderability.jsx +108 -0
  253. package/src/renderer.jsx +1932 -0
  254. package/src/server-item-renderer.jsx +467 -0
  255. package/src/sigfigs.jsx +492 -0
  256. package/src/styles/articles.less +748 -0
  257. package/src/styles/constants.js +119 -0
  258. package/src/styles/global-constants.js +350 -0
  259. package/src/styles/global-styles.js +307 -0
  260. package/src/styles/khan-exercise.css +1304 -0
  261. package/src/styles/media-queries.js +48 -0
  262. package/src/styles/perseus-renderer.less +1007 -0
  263. package/src/styles/shared.js +132 -0
  264. package/src/styles/util.less +47 -0
  265. package/src/styles/variables.boostrap.less +301 -0
  266. package/src/styles/variables.less +68 -0
  267. package/src/styles/variables.shared.less +356 -0
  268. package/src/styles/widgets/categorizer.less +39 -0
  269. package/src/styles/widgets/definition.less +86 -0
  270. package/src/styles/widgets/dropdown.less +3 -0
  271. package/src/styles/widgets/expression.less +147 -0
  272. package/src/styles/widgets/graded-group.less +36 -0
  273. package/src/styles/widgets/grapher.less +11 -0
  274. package/src/styles/widgets/group.less +19 -0
  275. package/src/styles/widgets/image.less +29 -0
  276. package/src/styles/widgets/interactive-graph.less +61 -0
  277. package/src/styles/widgets/label-image.less +41 -0
  278. package/src/styles/widgets/matcher.less +8 -0
  279. package/src/styles/widgets/matrix.less +120 -0
  280. package/src/styles/widgets/measurer.less +20 -0
  281. package/src/styles/widgets/orderer.less +97 -0
  282. package/src/styles/widgets/passage.less +151 -0
  283. package/src/styles/widgets/plotter.less +33 -0
  284. package/src/styles/widgets/radio.less +52 -0
  285. package/src/styles/widgets/reaction-diagram.less +35 -0
  286. package/src/styles/widgets/sequence.less +5 -0
  287. package/src/styles/widgets/sortable.less +127 -0
  288. package/src/styles/widgets/table.less +56 -0
  289. package/src/styles/widgets/transformer.less +28 -0
  290. package/src/styles/widgets/unit.less +14 -0
  291. package/src/tex-wrangler.js +176 -0
  292. package/src/traversal.jsx +141 -0
  293. package/src/types.js +538 -0
  294. package/src/util/a11y.js +24 -0
  295. package/src/util/answer-types.js +862 -0
  296. package/src/util/answer-types_test.js +115 -0
  297. package/src/util/colors.js +94 -0
  298. package/src/util/fix-passage-refs.jsx +122 -0
  299. package/src/util/graph-utils.js +16 -0
  300. package/src/util/graphie.js +1586 -0
  301. package/src/util/interactive.js +4078 -0
  302. package/src/util/katex-preprocess.js +16 -0
  303. package/src/util/math.js +296 -0
  304. package/src/util/mobile-native-utils.js +14 -0
  305. package/src/util/mobile-native-utils_test.js +24 -0
  306. package/src/util/register-all-widgets-for-testing.js +12 -0
  307. package/src/util/scroll-utils.js +162 -0
  308. package/src/util/sizing-utils.js +46 -0
  309. package/src/util/tex.js +203 -0
  310. package/src/util/url-utils.js +36 -0
  311. package/src/util.js +990 -0
  312. package/src/version.js +11 -0
  313. package/src/widget-container.jsx +174 -0
  314. package/src/widgets/__stories__/categorizer.stories.jsx +15 -0
  315. package/src/widgets/__stories__/cs-program.stories.jsx +15 -0
  316. package/src/widgets/__stories__/definition.stories.jsx +38 -0
  317. package/src/widgets/__stories__/dropdown.stories.jsx +15 -0
  318. package/src/widgets/__stories__/explanation.stories.jsx +19 -0
  319. package/src/widgets/__stories__/expression.stories.jsx +26 -0
  320. package/src/widgets/__stories__/graded-group-set.stories.jsx +32 -0
  321. package/src/widgets/__stories__/graded-group.stories.jsx +32 -0
  322. package/src/widgets/__stories__/grapher.stories.jsx +47 -0
  323. package/src/widgets/__stories__/group.stories.jsx +15 -0
  324. package/src/widgets/__stories__/iframe.stories.jsx +15 -0
  325. package/src/widgets/__stories__/image.stories.jsx +62 -0
  326. package/src/widgets/__stories__/input-number.stories.jsx +90 -0
  327. package/src/widgets/__stories__/interaction.stories.jsx +15 -0
  328. package/src/widgets/__stories__/interactive-graph.stories.jsx +61 -0
  329. package/src/widgets/__stories__/matcher.stories.jsx +15 -0
  330. package/src/widgets/__stories__/matrix.stories.jsx +15 -0
  331. package/src/widgets/__stories__/number-line.stories.jsx +15 -0
  332. package/src/widgets/__stories__/numeric-input.stories.jsx +19 -0
  333. package/src/widgets/__stories__/orderer.stories.jsx +15 -0
  334. package/src/widgets/__stories__/passage-ref.stories.jsx +19 -0
  335. package/src/widgets/__stories__/passage.stories.jsx +19 -0
  336. package/src/widgets/__stories__/radio.stories.jsx +82 -0
  337. package/src/widgets/__stories__/sorter.stories.jsx +15 -0
  338. package/src/widgets/__stories__/transformer.stories.jsx +15 -0
  339. package/src/widgets/__stories__/unit.stories.jsx +45 -0
  340. package/src/widgets/__stories__/video-transcript-link.stories.jsx +24 -0
  341. package/src/widgets/__stories__/video.stories.jsx +15 -0
  342. package/src/widgets/__testdata__/categorizer_testdata.js +50 -0
  343. package/src/widgets/__testdata__/cs-program_testdata.js +28 -0
  344. package/src/widgets/__testdata__/dropdown_testdata.js +34 -0
  345. package/src/widgets/__testdata__/explanation_testdata.js +56 -0
  346. package/src/widgets/__testdata__/expression_testdata.js +95 -0
  347. package/src/widgets/__testdata__/graded-group-set_testdata.js +358 -0
  348. package/src/widgets/__testdata__/graded-group_testdata.js +79 -0
  349. package/src/widgets/__testdata__/grapher_testdata.js +376 -0
  350. package/src/widgets/__testdata__/group_testdata.js +156 -0
  351. package/src/widgets/__testdata__/iframe_testdata.js +36 -0
  352. package/src/widgets/__testdata__/image_testdata.js +38 -0
  353. package/src/widgets/__testdata__/input-number_testdata.js +73 -0
  354. package/src/widgets/__testdata__/interaction_testdata.js +264 -0
  355. package/src/widgets/__testdata__/interactive-graph_testdata.js +646 -0
  356. package/src/widgets/__testdata__/matcher_testdata.js +34 -0
  357. package/src/widgets/__testdata__/matrix_testdata.js +29 -0
  358. package/src/widgets/__testdata__/number-line_testdata.js +31 -0
  359. package/src/widgets/__testdata__/numeric-input_testdata.js +266 -0
  360. package/src/widgets/__testdata__/orderer_testdata.js +58 -0
  361. package/src/widgets/__testdata__/passage-ref_testdata.js +41 -0
  362. package/src/widgets/__testdata__/passage_testdata.js +71 -0
  363. package/src/widgets/__testdata__/radio_testdata.js +210 -0
  364. package/src/widgets/__testdata__/sorter_testdata.js +20 -0
  365. package/src/widgets/__testdata__/transformer_testdata.js +109 -0
  366. package/src/widgets/__testdata__/video_testdata.js +22 -0
  367. package/src/widgets/__tests__/__snapshots__/categorizer_test.jsx.snap +928 -0
  368. package/src/widgets/__tests__/__snapshots__/cs-program_test.jsx.snap +75 -0
  369. package/src/widgets/__tests__/__snapshots__/definition_test.js.snap +99 -0
  370. package/src/widgets/__tests__/__snapshots__/dropdown_test.jsx.snap +143 -0
  371. package/src/widgets/__tests__/__snapshots__/explanation_test.js.snap +473 -0
  372. package/src/widgets/__tests__/__snapshots__/expression_test.jsx.snap +38 -0
  373. package/src/widgets/__tests__/__snapshots__/graded-group-set-jipt_test.jsx.snap +754 -0
  374. package/src/widgets/__tests__/__snapshots__/graded-group-set_test.jsx.snap +310 -0
  375. package/src/widgets/__tests__/__snapshots__/graded-group_test.jsx.snap +863 -0
  376. package/src/widgets/__tests__/__snapshots__/grapher_test.jsx.snap +2880 -0
  377. package/src/widgets/__tests__/__snapshots__/group_test.jsx.snap +1154 -0
  378. package/src/widgets/__tests__/__snapshots__/iframe_test.jsx.snap +69 -0
  379. package/src/widgets/__tests__/__snapshots__/image_test.jsx.snap +388 -0
  380. package/src/widgets/__tests__/__snapshots__/input-number_test.jsx.snap +978 -0
  381. package/src/widgets/__tests__/__snapshots__/interaction_test.jsx.snap +311 -0
  382. package/src/widgets/__tests__/__snapshots__/interactive-graph_test.jsx.snap +2915 -0
  383. package/src/widgets/__tests__/__snapshots__/matcher_test.jsx.snap +1039 -0
  384. package/src/widgets/__tests__/__snapshots__/matrix_test.jsx.snap +450 -0
  385. package/src/widgets/__tests__/__snapshots__/number-line_test.jsx.snap +888 -0
  386. package/src/widgets/__tests__/__snapshots__/numeric-input_test.jsx.snap +930 -0
  387. package/src/widgets/__tests__/__snapshots__/orderer_test.jsx.snap +275 -0
  388. package/src/widgets/__tests__/__snapshots__/passage-ref_test.jsx.snap +446 -0
  389. package/src/widgets/__tests__/__snapshots__/passage_test.jsx.snap +1988 -0
  390. package/src/widgets/__tests__/__snapshots__/radio_test.jsx.snap +7107 -0
  391. package/src/widgets/__tests__/__snapshots__/video_test.jsx.snap +163 -0
  392. package/src/widgets/__tests__/categorizer_test.jsx +205 -0
  393. package/src/widgets/__tests__/cs-program_test.jsx +45 -0
  394. package/src/widgets/__tests__/definition_test.js +152 -0
  395. package/src/widgets/__tests__/dropdown_test.jsx +106 -0
  396. package/src/widgets/__tests__/explanation_test.js +199 -0
  397. package/src/widgets/__tests__/expression_test.jsx +439 -0
  398. package/src/widgets/__tests__/graded-group-set-jipt_test.jsx +33 -0
  399. package/src/widgets/__tests__/graded-group-set_test.jsx +270 -0
  400. package/src/widgets/__tests__/graded-group_test.jsx +233 -0
  401. package/src/widgets/__tests__/grapher.cypress.jsx +486 -0
  402. package/src/widgets/__tests__/grapher_test.jsx +35 -0
  403. package/src/widgets/__tests__/group_test.jsx +512 -0
  404. package/src/widgets/__tests__/iframe_test.jsx +47 -0
  405. package/src/widgets/__tests__/image_test.jsx +65 -0
  406. package/src/widgets/__tests__/input-number_test.jsx +360 -0
  407. package/src/widgets/__tests__/interaction_test.jsx +33 -0
  408. package/src/widgets/__tests__/interactive-graph.cypress.jsx +697 -0
  409. package/src/widgets/__tests__/interactive-graph_test.jsx +105 -0
  410. package/src/widgets/__tests__/matcher_test.jsx +157 -0
  411. package/src/widgets/__tests__/matrix_test.jsx +84 -0
  412. package/src/widgets/__tests__/number-line_test.jsx +81 -0
  413. package/src/widgets/__tests__/numeric-input_test.jsx +574 -0
  414. package/src/widgets/__tests__/orderer_test.jsx +75 -0
  415. package/src/widgets/__tests__/passage-ref_test.jsx +166 -0
  416. package/src/widgets/__tests__/passage_test.jsx +133 -0
  417. package/src/widgets/__tests__/radio/base-radio_test.jsx +82 -0
  418. package/src/widgets/__tests__/radio_test.jsx +651 -0
  419. package/src/widgets/__tests__/renderQuestion.jsx +66 -0
  420. package/src/widgets/__tests__/unit_test.jsx +144 -0
  421. package/src/widgets/__tests__/video_test.jsx +55 -0
  422. package/src/widgets/categorizer.jsx +338 -0
  423. package/src/widgets/cs-program.jsx +227 -0
  424. package/src/widgets/definition.jsx +141 -0
  425. package/src/widgets/dropdown.jsx +143 -0
  426. package/src/widgets/explanation.jsx +315 -0
  427. package/src/widgets/expression.jsx +652 -0
  428. package/src/widgets/graded-group-answer-bar.jsx +152 -0
  429. package/src/widgets/graded-group-set.jsx +285 -0
  430. package/src/widgets/graded-group.jsx +448 -0
  431. package/src/widgets/grapher/util.jsx +806 -0
  432. package/src/widgets/grapher.jsx +663 -0
  433. package/src/widgets/group.jsx +213 -0
  434. package/src/widgets/iframe.jsx +198 -0
  435. package/src/widgets/image.jsx +310 -0
  436. package/src/widgets/input-number.jsx +411 -0
  437. package/src/widgets/interaction/arrow-picker.jsx +39 -0
  438. package/src/widgets/interaction/color-picker.jsx +69 -0
  439. package/src/widgets/interaction/dash-picker.jsx +46 -0
  440. package/src/widgets/interaction/element-container.jsx +97 -0
  441. package/src/widgets/interaction.jsx +742 -0
  442. package/src/widgets/interactive-graph.jsx +2820 -0
  443. package/src/widgets/label-image/__stories__/answer-choices.stories.jsx +93 -0
  444. package/src/widgets/label-image/__stories__/marker.stories.jsx +172 -0
  445. package/src/widgets/label-image/answer-choices.jsx +311 -0
  446. package/src/widgets/label-image/marker.jsx +365 -0
  447. package/src/widgets/label-image/types.js +33 -0
  448. package/src/widgets/label-image.jsx +841 -0
  449. package/src/widgets/label-image_test.js +840 -0
  450. package/src/widgets/lights-puzzle.jsx +356 -0
  451. package/src/widgets/matcher.jsx +271 -0
  452. package/src/widgets/matrix.jsx +616 -0
  453. package/src/widgets/measurer.jsx +215 -0
  454. package/src/widgets/molecule/__tests__/layout_test.jsx +159 -0
  455. package/src/widgets/molecule/__tests__/parser_test.jsx +142 -0
  456. package/src/widgets/molecule/molecule-drawing.jsx +175 -0
  457. package/src/widgets/molecule/molecule-layout.jsx +367 -0
  458. package/src/widgets/molecule/smiles-parser.jsx +300 -0
  459. package/src/widgets/molecule.jsx +172 -0
  460. package/src/widgets/number-line.jsx +858 -0
  461. package/src/widgets/numeric-input.jsx +622 -0
  462. package/src/widgets/orderer.jsx +753 -0
  463. package/src/widgets/passage/__tests__/passage-markdown_test.jsx +382 -0
  464. package/src/widgets/passage/get-line-height-for-node.js +10 -0
  465. package/src/widgets/passage/passage-markdown.jsx +416 -0
  466. package/src/widgets/passage-ref-target.jsx +70 -0
  467. package/src/widgets/passage-ref.jsx +198 -0
  468. package/src/widgets/passage.jsx +601 -0
  469. package/src/widgets/plotter.jsx +1198 -0
  470. package/src/widgets/radio/__stories__/base-radio.stories.jsx +40 -0
  471. package/src/widgets/radio/__stories__/choice-icon.stories.jsx +157 -0
  472. package/src/widgets/radio/__stories__/choice-none-above.stories.jsx +26 -0
  473. package/src/widgets/radio/__stories__/cross-out-button.stories.jsx +64 -0
  474. package/src/widgets/radio/__stories__/cross-out-menu.stories.jsx +59 -0
  475. package/src/widgets/radio/__stories__/cross-out-tooltip.stories.jsx +59 -0
  476. package/src/widgets/radio/__stories__/focus-ring.stories.jsx +38 -0
  477. package/src/widgets/radio/__stories__/option-status.stories.jsx +118 -0
  478. package/src/widgets/radio/__stories__/toggleable-radio-button.stories.jsx +28 -0
  479. package/src/widgets/radio/base-radio.jsx +642 -0
  480. package/src/widgets/radio/choice-icon.jsx +468 -0
  481. package/src/widgets/radio/choice-none-above.jsx +54 -0
  482. package/src/widgets/radio/choice.jsx +692 -0
  483. package/src/widgets/radio/choice.jsx.fixture.js +64 -0
  484. package/src/widgets/radio/cross-out-button.jsx +136 -0
  485. package/src/widgets/radio/cross-out-menu-wrapper.jsx +492 -0
  486. package/src/widgets/radio/cross-out-tooltip.jsx +129 -0
  487. package/src/widgets/radio/focus-ring.jsx +51 -0
  488. package/src/widgets/radio/option-status.jsx +89 -0
  489. package/src/widgets/radio/toggleable-radio-button.jsx +133 -0
  490. package/src/widgets/radio/util.js +32 -0
  491. package/src/widgets/radio/util_test.js +19 -0
  492. package/src/widgets/radio/widget.jsx +470 -0
  493. package/src/widgets/radio.jsx +156 -0
  494. package/src/widgets/reaction-diagram.jsx +137 -0
  495. package/src/widgets/sequence.jsx +140 -0
  496. package/src/widgets/simulator.jsx +808 -0
  497. package/src/widgets/sorter.jsx +146 -0
  498. package/src/widgets/table.jsx +394 -0
  499. package/src/widgets/transformer.jsx +2876 -0
  500. package/src/widgets/unit.jsx +372 -0
  501. package/src/widgets/video-transcript-link.jsx +84 -0
  502. package/src/widgets/video-transcript-link_test.js +211 -0
  503. package/src/widgets/video.jsx +126 -0
  504. package/src/widgets.js +431 -0
  505. package/src/zoom.js +539 -0
  506. package/README.md +0 -3
  507. package/src/__tests__/index.test.js +0 -14
@@ -0,0 +1,545 @@
1
+ // @noflow
2
+ /* eslint-disable */
3
+ /*
4
+ * jQuery Mobile Framework : "mouse" plugin
5
+ * Copyright (c) jQuery Project
6
+ * Dual licensed under the MIT or GPL Version 2 licenses.
7
+ * http://jquery.org/license
8
+ */
9
+
10
+ // This plugin is an experiment for abstracting away the touch and mouse
11
+ // events so that developers don't have to worry about which method of input
12
+ // the device their document is loaded on supports.
13
+ //
14
+ // The idea here is to allow the developer to register listeners for the
15
+ // basic mouse events, such as mousedown, mousemove, mouseup, and click,
16
+ // and the plugin will take care of registering the correct listeners
17
+ // behind the scenes to invoke the listener at the fastest possible time
18
+ // for that device, while still retaining the order of event firing in
19
+ // the traditional mouse environment, should multiple handlers be registered
20
+ // on the same element for different events.
21
+ //
22
+ // The current version exposes the following virtual events to jQuery bind methods:
23
+ // "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel"
24
+
25
+ (function ($, window, document, undefined) {
26
+ if (typeof $ === "undefined") {
27
+ return;
28
+ }
29
+
30
+ var dataPropertyName = "virtualMouseBindings",
31
+ touchTargetPropertyName = "virtualTouchID",
32
+ virtualEventNames =
33
+ "vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split(
34
+ " ",
35
+ ),
36
+ touchEventProps = "clientX clientY pageX pageY screenX screenY".split(
37
+ " ",
38
+ ),
39
+ mouseHookProps = $.event.mouseHooks ? $.event.mouseHooks.props : [],
40
+ mouseEventProps = $.event.props.concat(mouseHookProps),
41
+ activeDocHandlers = {},
42
+ resetTimerID = 0,
43
+ startX = 0,
44
+ startY = 0,
45
+ didScroll = false,
46
+ clickBlockList = [],
47
+ blockMouseTriggers = false,
48
+ blockTouchTriggers = false,
49
+ eventCaptureSupported = "addEventListener" in document,
50
+ $document = $(document),
51
+ nextTouchID = 1,
52
+ lastTouchID = 0;
53
+
54
+ $.vmouse = {
55
+ moveDistanceThreshold: 10,
56
+ clickDistanceThreshold: 10,
57
+ resetTimerDuration: 1500,
58
+ };
59
+
60
+ function getNativeEvent(event) {
61
+ while (event && typeof event.originalEvent !== "undefined") {
62
+ event = event.originalEvent;
63
+ }
64
+ return event;
65
+ }
66
+
67
+ function createVirtualEvent(event, eventType) {
68
+ var t = event.type,
69
+ oe,
70
+ props,
71
+ ne,
72
+ prop,
73
+ ct,
74
+ touch,
75
+ i,
76
+ j,
77
+ len;
78
+
79
+ event = $.Event(event);
80
+ event.type = eventType;
81
+
82
+ oe = event.originalEvent;
83
+ props = $.event.props;
84
+
85
+ // addresses separation of $.event.props in to $.event.mouseHook.props and Issue 3280
86
+ // https://github.com/jquery/jquery-mobile/issues/3280
87
+ if (t.search(/mouse/) > -1) {
88
+ props = mouseEventProps;
89
+ }
90
+
91
+ // copy original event properties over to the new event
92
+ // this would happen if we could call $.event.fix instead of $.Event
93
+ // but we don't have a way to force an event to be fixed multiple times
94
+ if (oe) {
95
+ for (i = props.length, prop; i; ) {
96
+ prop = props[--i];
97
+ event[prop] = oe[prop];
98
+ }
99
+ }
100
+
101
+ // make sure that if the mouse and click virtual events are generated
102
+ // without a .which one is defined
103
+ if (t.search(/mouse(down|up)|click/) > -1 && !event.which) {
104
+ event.which = 1;
105
+ }
106
+
107
+ if (t.search(/^touch/) !== -1) {
108
+ ne = getNativeEvent(oe);
109
+ t = ne.touches;
110
+ ct = ne.changedTouches;
111
+ touch = t && t.length ? t[0] : ct && ct.length ? ct[0] : undefined;
112
+
113
+ if (touch) {
114
+ for (j = 0, len = touchEventProps.length; j < len; j++) {
115
+ prop = touchEventProps[j];
116
+ event[prop] = touch[prop];
117
+ }
118
+ }
119
+ }
120
+
121
+ return event;
122
+ }
123
+
124
+ function getVirtualBindingFlags(element) {
125
+ var flags = {},
126
+ b,
127
+ k;
128
+
129
+ while (element) {
130
+ b = $.data(element, dataPropertyName);
131
+
132
+ for (k in b) {
133
+ if (b[k]) {
134
+ flags[k] = flags.hasVirtualBinding = true;
135
+ }
136
+ }
137
+ element = element.parentNode;
138
+ }
139
+ return flags;
140
+ }
141
+
142
+ function getClosestElementWithVirtualBinding(element, eventType) {
143
+ var b;
144
+ while (element) {
145
+ b = $.data(element, dataPropertyName);
146
+
147
+ if (b && (!eventType || b[eventType])) {
148
+ return element;
149
+ }
150
+ element = element.parentNode;
151
+ }
152
+ return null;
153
+ }
154
+
155
+ function enableTouchBindings() {
156
+ blockTouchTriggers = false;
157
+ }
158
+
159
+ function disableTouchBindings() {
160
+ blockTouchTriggers = true;
161
+ }
162
+
163
+ function enableMouseBindings() {
164
+ lastTouchID = 0;
165
+ clickBlockList.length = 0;
166
+ blockMouseTriggers = false;
167
+
168
+ // When mouse bindings are enabled, our
169
+ // touch bindings are disabled.
170
+ disableTouchBindings();
171
+ }
172
+
173
+ function disableMouseBindings() {
174
+ // When mouse bindings are disabled, our
175
+ // touch bindings are enabled.
176
+ enableTouchBindings();
177
+ }
178
+
179
+ function startResetTimer() {
180
+ clearResetTimer();
181
+ resetTimerID = setTimeout(function () {
182
+ resetTimerID = 0;
183
+ enableMouseBindings();
184
+ }, $.vmouse.resetTimerDuration);
185
+ }
186
+
187
+ function clearResetTimer() {
188
+ if (resetTimerID) {
189
+ clearTimeout(resetTimerID);
190
+ resetTimerID = 0;
191
+ }
192
+ }
193
+
194
+ function triggerVirtualEvent(eventType, event, flags) {
195
+ var ve;
196
+
197
+ if (
198
+ (flags && flags[eventType]) ||
199
+ (!flags &&
200
+ getClosestElementWithVirtualBinding(event.target, eventType))
201
+ ) {
202
+ ve = createVirtualEvent(event, eventType);
203
+
204
+ $(event.target).trigger(ve);
205
+ }
206
+
207
+ return ve;
208
+ }
209
+
210
+ function mouseEventCallback(event) {
211
+ var touchID = $.data(event.target, touchTargetPropertyName);
212
+
213
+ if (!blockMouseTriggers && (!lastTouchID || lastTouchID !== touchID)) {
214
+ var ve = triggerVirtualEvent("v" + event.type, event);
215
+ if (ve) {
216
+ if (ve.isDefaultPrevented()) {
217
+ event.preventDefault();
218
+ }
219
+ if (ve.isPropagationStopped()) {
220
+ event.stopPropagation();
221
+ }
222
+ if (ve.isImmediatePropagationStopped()) {
223
+ event.stopImmediatePropagation();
224
+ }
225
+ }
226
+ }
227
+ }
228
+
229
+ function handleTouchStart(event) {
230
+ var touches = getNativeEvent(event).touches,
231
+ target,
232
+ flags;
233
+
234
+ if (touches && touches.length === 1) {
235
+ target = event.target;
236
+ flags = getVirtualBindingFlags(target);
237
+
238
+ if (flags.hasVirtualBinding) {
239
+ lastTouchID = nextTouchID++;
240
+ $.data(target, touchTargetPropertyName, lastTouchID);
241
+
242
+ clearResetTimer();
243
+
244
+ disableMouseBindings();
245
+ didScroll = false;
246
+
247
+ var t = getNativeEvent(event).touches[0];
248
+ startX = t.pageX;
249
+ startY = t.pageY;
250
+
251
+ triggerVirtualEvent("vmouseover", event, flags);
252
+ triggerVirtualEvent("vmousedown", event, flags);
253
+ }
254
+ }
255
+ }
256
+
257
+ function handleScroll(event) {
258
+ if (blockTouchTriggers) {
259
+ return;
260
+ }
261
+
262
+ if (!didScroll) {
263
+ triggerVirtualEvent(
264
+ "vmousecancel",
265
+ event,
266
+ getVirtualBindingFlags(event.target),
267
+ );
268
+ }
269
+
270
+ didScroll = true;
271
+ startResetTimer();
272
+ }
273
+
274
+ function handleTouchMove(event) {
275
+ if (blockTouchTriggers) {
276
+ return;
277
+ }
278
+
279
+ var t = getNativeEvent(event).touches[0],
280
+ didCancel = didScroll,
281
+ moveThreshold = $.vmouse.moveDistanceThreshold,
282
+ didScroll =
283
+ didScroll ||
284
+ Math.abs(t.pageX - startX) > moveThreshold ||
285
+ Math.abs(t.pageY - startY) > moveThreshold,
286
+ flags = getVirtualBindingFlags(event.target);
287
+
288
+ if (didScroll && !didCancel) {
289
+ triggerVirtualEvent("vmousecancel", event, flags);
290
+ }
291
+
292
+ triggerVirtualEvent("vmousemove", event, flags);
293
+ startResetTimer();
294
+ }
295
+
296
+ function handleTouchEnd(event) {
297
+ if (blockTouchTriggers) {
298
+ return;
299
+ }
300
+
301
+ disableTouchBindings();
302
+
303
+ var flags = getVirtualBindingFlags(event.target),
304
+ t;
305
+ triggerVirtualEvent("vmouseup", event, flags);
306
+
307
+ if (!didScroll) {
308
+ var ve = triggerVirtualEvent("vclick", event, flags);
309
+ if (ve && ve.isDefaultPrevented()) {
310
+ // The target of the mouse events that follow the touchend
311
+ // event don't necessarily match the target used during the
312
+ // touch. This means we need to rely on coordinates for blocking
313
+ // any click that is generated.
314
+ t = getNativeEvent(event).changedTouches[0];
315
+ clickBlockList.push({
316
+ touchID: lastTouchID,
317
+ x: t.clientX,
318
+ y: t.clientY,
319
+ });
320
+
321
+ // Prevent any mouse events that follow from triggering
322
+ // virtual event notifications.
323
+ blockMouseTriggers = true;
324
+ }
325
+ }
326
+ triggerVirtualEvent("vmouseout", event, flags);
327
+ didScroll = false;
328
+
329
+ startResetTimer();
330
+ }
331
+
332
+ function hasVirtualBindings(ele) {
333
+ var bindings = $.data(ele, dataPropertyName),
334
+ k;
335
+
336
+ if (bindings) {
337
+ for (k in bindings) {
338
+ if (bindings[k]) {
339
+ return true;
340
+ }
341
+ }
342
+ }
343
+ return false;
344
+ }
345
+
346
+ function dummyMouseHandler() {}
347
+
348
+ function getSpecialEventObject(eventType) {
349
+ var realType = eventType.substr(1);
350
+
351
+ return {
352
+ setup: function (data, namespace) {
353
+ // If this is the first virtual mouse binding for this element,
354
+ // add a bindings object to its data.
355
+
356
+ if (!hasVirtualBindings(this)) {
357
+ $.data(this, dataPropertyName, {});
358
+ }
359
+
360
+ // If setup is called, we know it is the first binding for this
361
+ // eventType, so initialize the count for the eventType to zero.
362
+ var bindings = $.data(this, dataPropertyName);
363
+ bindings[eventType] = true;
364
+
365
+ // If this is the first virtual mouse event for this type,
366
+ // register a global handler on the document.
367
+
368
+ activeDocHandlers[eventType] =
369
+ (activeDocHandlers[eventType] || 0) + 1;
370
+
371
+ if (activeDocHandlers[eventType] === 1) {
372
+ $document.bind(realType, mouseEventCallback);
373
+ }
374
+
375
+ // Some browsers, like Opera Mini, won't dispatch mouse/click events
376
+ // for elements unless they actually have handlers registered on them.
377
+ // To get around this, we register dummy handlers on the elements.
378
+
379
+ $(this).bind(realType, dummyMouseHandler);
380
+
381
+ // For now, if event capture is not supported, we rely on mouse handlers.
382
+ if (eventCaptureSupported) {
383
+ // If this is the first virtual mouse binding for the document,
384
+ // register our touchstart handler on the document.
385
+
386
+ activeDocHandlers["touchstart"] =
387
+ (activeDocHandlers["touchstart"] || 0) + 1;
388
+
389
+ if (activeDocHandlers["touchstart"] === 1) {
390
+ $document
391
+ .bind("touchstart", handleTouchStart)
392
+ .bind("touchend", handleTouchEnd)
393
+
394
+ // On touch platforms, touching the screen and then dragging your finger
395
+ // causes the window content to scroll after some distance threshold is
396
+ // exceeded. On these platforms, a scroll prevents a click event from being
397
+ // dispatched, and on some platforms, even the touchend is suppressed. To
398
+ // mimic the suppression of the click event, we need to watch for a scroll
399
+ // event. Unfortunately, some platforms like iOS don't dispatch scroll
400
+ // events until *AFTER* the user lifts their finger (touchend). This means
401
+ // we need to watch both scroll and touchmove events to figure out whether
402
+ // or not a scroll happenens before the touchend event is fired.
403
+
404
+ .bind("touchmove", handleTouchMove)
405
+ .bind("scroll", handleScroll);
406
+ }
407
+ }
408
+ },
409
+
410
+ teardown: function (data, namespace) {
411
+ // If this is the last virtual binding for this eventType,
412
+ // remove its global handler from the document.
413
+
414
+ --activeDocHandlers[eventType];
415
+
416
+ if (!activeDocHandlers[eventType]) {
417
+ $document.unbind(realType, mouseEventCallback);
418
+ }
419
+
420
+ if (eventCaptureSupported) {
421
+ // If this is the last virtual mouse binding in existence,
422
+ // remove our document touchstart listener.
423
+
424
+ --activeDocHandlers["touchstart"];
425
+
426
+ if (!activeDocHandlers["touchstart"]) {
427
+ $document
428
+ .unbind("touchstart", handleTouchStart)
429
+ .unbind("touchmove", handleTouchMove)
430
+ .unbind("touchend", handleTouchEnd)
431
+ .unbind("scroll", handleScroll);
432
+ }
433
+ }
434
+
435
+ var $this = $(this),
436
+ bindings = $.data(this, dataPropertyName);
437
+
438
+ // teardown may be called when an element was
439
+ // removed from the DOM. If this is the case,
440
+ // jQuery core may have already stripped the element
441
+ // of any data bindings so we need to check it before
442
+ // using it.
443
+ if (bindings) {
444
+ bindings[eventType] = false;
445
+ }
446
+
447
+ // Unregister the dummy event handler.
448
+
449
+ $this.unbind(realType, dummyMouseHandler);
450
+
451
+ // If this is the last virtual mouse binding on the
452
+ // element, remove the binding data from the element.
453
+
454
+ if (!hasVirtualBindings(this)) {
455
+ $this.removeData(dataPropertyName);
456
+ }
457
+ },
458
+ };
459
+ }
460
+
461
+ // Expose our custom events to the jQuery bind/unbind mechanism.
462
+
463
+ for (var i = 0; i < virtualEventNames.length; i++) {
464
+ $.event.special[virtualEventNames[i]] = getSpecialEventObject(
465
+ virtualEventNames[i],
466
+ );
467
+ }
468
+
469
+ // Add a capture click handler to block clicks.
470
+ // Note that we require event capture support for this so if the device
471
+ // doesn't support it, we punt for now and rely solely on mouse events.
472
+ if (eventCaptureSupported) {
473
+ document.addEventListener(
474
+ "click",
475
+ function (e) {
476
+ var cnt = clickBlockList.length,
477
+ target = e.target,
478
+ x,
479
+ y,
480
+ ele,
481
+ i,
482
+ o,
483
+ touchID;
484
+
485
+ if (cnt) {
486
+ x = e.clientX;
487
+ y = e.clientY;
488
+ threshold = $.vmouse.clickDistanceThreshold;
489
+
490
+ // The idea here is to run through the clickBlockList to see if
491
+ // the current click event is in the proximity of one of our
492
+ // vclick events that had preventDefault() called on it. If we find
493
+ // one, then we block the click.
494
+ //
495
+ // Why do we have to rely on proximity?
496
+ //
497
+ // Because the target of the touch event that triggered the vclick
498
+ // can be different from the target of the click event synthesized
499
+ // by the browser. The target of a mouse/click event that is syntehsized
500
+ // from a touch event seems to be implementation specific. For example,
501
+ // some browsers will fire mouse/click events for a link that is near
502
+ // a touch event, even though the target of the touchstart/touchend event
503
+ // says the user touched outside the link. Also, it seems that with most
504
+ // browsers, the target of the mouse/click event is not calculated until the
505
+ // time it is dispatched, so if you replace an element that you touched
506
+ // with another element, the target of the mouse/click will be the new
507
+ // element underneath that point.
508
+ //
509
+ // Aside from proximity, we also check to see if the target and any
510
+ // of its ancestors were the ones that blocked a click. This is necessary
511
+ // because of the strange mouse/click target calculation done in the
512
+ // Android 2.1 browser, where if you click on an element, and there is a
513
+ // mouse/click handler on one of its ancestors, the target will be the
514
+ // innermost child of the touched element, even if that child is no where
515
+ // near the point of touch.
516
+
517
+ ele = target;
518
+
519
+ while (ele) {
520
+ for (i = 0; i < cnt; i++) {
521
+ o = clickBlockList[i];
522
+ touchID = 0;
523
+
524
+ if (
525
+ (ele === target &&
526
+ Math.abs(o.x - x) < threshold &&
527
+ Math.abs(o.y - y) < threshold) ||
528
+ $.data(ele, touchTargetPropertyName) ===
529
+ o.touchID
530
+ ) {
531
+ // XXX: We may want to consider removing matches from the block list
532
+ // instead of waiting for the reset timer to fire.
533
+ e.preventDefault();
534
+ e.stopPropagation();
535
+ return;
536
+ }
537
+ }
538
+ ele = ele.parentNode;
539
+ }
540
+ }
541
+ },
542
+ true,
543
+ );
544
+ }
545
+ })(window.jQuery, window, document);
@@ -0,0 +1,33 @@
1
+ // @flow
2
+ /**
3
+ * KeypadContext provides a way to the Keypad and (Server)ItemRenderer to
4
+ * communicate.
5
+ *
6
+ * The KeypadContext.Provider wraps the ExerciseFooter while KeypadContext.Consumer
7
+ * wraps each (Server)ItemRenderer render site and the Keypad rendered in the
8
+ * ExerciseFooter.
9
+ */
10
+ import * as React from "react";
11
+
12
+ import type {RendererInterface} from "./types.js";
13
+
14
+ type KeypadContext = {
15
+ setKeypadElement: (keypadElement: ?HTMLElement) => void,
16
+ keypadElement: ?HTMLElement,
17
+ setRenderer: (renderer: ?RendererInterface) => void,
18
+ renderer: ?RendererInterface,
19
+ setScrollableElement: (scrollableElement: ?HTMLElement) => void,
20
+ scrollableElement: ?HTMLElement,
21
+ ...
22
+ };
23
+
24
+ const context: React.Context<KeypadContext> = React.createContext({
25
+ setKeypadElement: (keypadElement) => {},
26
+ keypadElement: null,
27
+ setRenderer: (renderer) => {},
28
+ renderer: null,
29
+ setScrollableElement: (scrollableElement) => {},
30
+ scrollableElement: null,
31
+ });
32
+
33
+ export default context;
@@ -0,0 +1,20 @@
1
+ // @flow
2
+ /**
3
+ * A React context for signaling when all of the components in a Perseus
4
+ * renderer is fully rendered. This means that all images and math have
5
+ * finished loading/rendering.
6
+ *
7
+ * Currently only used by ServerItemRender to indicate when the question
8
+ * renderer is fully rendered.
9
+ */
10
+ import * as React from "react";
11
+
12
+ type Context = {onRendered: (isRendered: boolean) => void, ...};
13
+
14
+ const defaultContext: Context = {
15
+ onRendered: (isRendered: boolean) => {},
16
+ };
17
+
18
+ const context: React.Context<Context> = React.createContext(defaultContext);
19
+
20
+ export default context;
@@ -0,0 +1,107 @@
1
+ // @flow
2
+
3
+ import {getDependencies} from "../dependencies.js";
4
+
5
+ import type {Metadata} from "@khanacademy/wonder-stuff-core";
6
+
7
+ // TODO(LP-11481): Change the primary API we use for logging in Perseus to use
8
+ // getDependencies() internally... simplify usage to just using a "singleton"
9
+ // which get's the injected logger.
10
+
11
+ /**
12
+ * @typedef {Object} Errors utility for referencing the Perseus error taxonomy.
13
+ */
14
+ export const Errors = Object.freeze({
15
+ /**
16
+ * @property {ErrorKind} Unknown The kind of error is not known.
17
+ */
18
+ Unknown: "Unknown",
19
+ /**
20
+ * @property {ErrorKind} Internal The error is internal to the executing code.
21
+ */
22
+ Internal: "Internal",
23
+ /**
24
+ * @property {ErrorKind} InvalidInput There was a problem with the provided
25
+ * input, such as the wrong format or a null value.
26
+ */
27
+ InvalidInput: "InvalidInput",
28
+ /**
29
+ * @property {ErrorKind} NotAllowed There was a problem due to the state of
30
+ * the system not matching the requested operation or input. For example,
31
+ * trying to create a username that is valid, but is already taken by
32
+ * another user. Use {@link InvalidInput} instead when the input isn't
33
+ * valid regardless of the state of the system. Use {@link NotFound} when
34
+ * the failure is due to not being able to find a resource.
35
+ */
36
+ NotAllowed: "NotAllowed",
37
+ /**
38
+ * @property {ErrorKind} TransientService There was a problem when making a
39
+ * request to a service.
40
+ */
41
+ TransientService: "TransientService",
42
+ /**
43
+ * @property {ErrorKind} Service There was a non-transient problem when
44
+ * making a request to service.
45
+ */
46
+ Service: "Service",
47
+ });
48
+
49
+ /**
50
+ * @type {ErrorKind} The kind of error being reported
51
+ */
52
+ export type ErrorKind = $Values<typeof Errors>;
53
+
54
+ export type LogErrorOptions = {|
55
+ // The cause of the error.
56
+ cause?: ?Error,
57
+ // Extra metadata about the error that is safe and small enough to send to
58
+ // external log systems (think Sentry).
59
+ loggedMetadata?: ?Metadata,
60
+ // Extra metadata about the error. Any data included in this key is
61
+ // explicitly marked to _not_ be delivered to any configured logging
62
+ // systems.
63
+ metadata?: ?Metadata,
64
+ |};
65
+
66
+ /**
67
+ * Provides logging infrastructure for Perseus
68
+ */
69
+ export interface ILogger {
70
+ // Logs a message
71
+ log(
72
+ // NOTE: Prefer including any data that varies in the `extra` parameter
73
+ // instead of including it in the message. This makes it easier for error
74
+ // logging platforms to group like errors together.
75
+ message: string,
76
+ extra?: ?Metadata,
77
+ ): void;
78
+
79
+ // Logs an error with a message
80
+ error(
81
+ // NOTE: Prefer including any data that varies in the `extra` parameter
82
+ // instead of including it in the message. This makes it easier for error
83
+ // logging platforms to group like errors together.
84
+ message: string,
85
+ kind: ErrorKind,
86
+ extra?: LogErrorOptions,
87
+ ): void;
88
+ }
89
+
90
+ export const Log: ILogger = {
91
+ // Logs a message
92
+ log: (message: string, extra?: ?Metadata) => {
93
+ getDependencies().Log.log(message, extra);
94
+ },
95
+
96
+ // Logs an error with a message
97
+ error: (
98
+ // NOTE: Prefer including any data that varies in the `extra` parameter
99
+ // instead of including it in the message. This makes it easier for error
100
+ // logging platforms to group like errors together.
101
+ message: string,
102
+ kind: ErrorKind,
103
+ extra?: LogErrorOptions,
104
+ ) => {
105
+ getDependencies().Log.error(message, kind, extra);
106
+ },
107
+ };