@doenet/doenetml 0.7.0-alpha53 → 0.7.0-alpha54

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 (98) hide show
  1. package/EditorViewer/EditorViewer.d.ts +2 -2
  2. package/EditorViewer/EditorViewer.d.ts.map +1 -1
  3. package/Viewer/DocViewer.d.ts +3 -3
  4. package/Viewer/DocViewer.d.ts.map +1 -1
  5. package/Viewer/renderers/answer.d.ts.map +1 -1
  6. package/Viewer/renderers/utils/{AnswerResponseMenu.d.ts → AnswerResponseButton.d.ts} +2 -2
  7. package/Viewer/renderers/utils/AnswerResponseButton.d.ts.map +1 -0
  8. package/{_error-GwDTi6rY.js → _error-C_-Cf-n2.js} +2 -2
  9. package/{alert-BtkPDkoA.js → alert-MJhKXjOS.js} +3 -3
  10. package/{angle-D8QNz00R.js → angle-BpYvF3te.js} +3 -3
  11. package/{answer-ciKskgNk.js → answer-CuS5aZTS.js} +10 -10
  12. package/{asList-Cb0lLe-w.js → asList-pFpAEmGs.js} +2 -2
  13. package/{blockQuote-DiHpuXuU.js → blockQuote-BwtSgf5T.js} +3 -3
  14. package/{boolean-CAhgqlsZ.js → boolean-DcKFD1Fy.js} +2 -2
  15. package/{booleanInput-Dtul5aLp.js → booleanInput-CwLNoidq.js} +4 -4
  16. package/{br-CU6brznZ.js → br-CWfv5Yfo.js} +2 -2
  17. package/{button-BlF6I46m.js → button-BLuW2QCj.js} +3 -3
  18. package/{c-CmlalQXF.js → c-BrtRcbB_.js} +3 -3
  19. package/{cell-DKuooRe3.js → cell-DlXycmel.js} +3 -3
  20. package/checkwork-DDY5Zou5.js +184 -0
  21. package/{choiceInput-DcDJOcx_.js → choiceInput-Dz1A3w9Z.js} +3 -3
  22. package/{circle-D-vdk68E.js → circle-DYkwnDWP.js} +3 -3
  23. package/{cobwebPolyline-H7MNGud_.js → cobwebPolyline-C6pbYMrH.js} +3 -3
  24. package/{codeEditor-BdcQ4cRu.js → codeEditor-DdBAcjIB.js} +2 -2
  25. package/{composites-ByHZA6ga.js → composites-DyD9mtrW.js} +1 -1
  26. package/{containerBlock-Zt0J_8qp.js → containerBlock-CJ1pBE7O.js} +3 -3
  27. package/{containerInline-J0ZA-hAw.js → containerInline-DhgYNACz.js} +3 -3
  28. package/{curve-CnVnG-gR.js → curve-ooDlQwfV.js} +3 -3
  29. package/{doenetml-BxYCfP3q.js → doenetml-C1a-oMqu.js} +15 -83
  30. package/doenetml-inline-worker.js +2 -2
  31. package/doenetml.d.ts +4 -4
  32. package/doenetml.d.ts.map +1 -1
  33. package/{ellipsis-BbY_75B9.js → ellipsis-B-ln6U7X.js} +2 -2
  34. package/{em-Bo1_u07q.js → em-CEObxn8A.js} +3 -3
  35. package/{embed-BYY0B6YL.js → embed-BAO0fW47.js} +2 -2
  36. package/{feedback-BEcqQSUv.js → feedback-BpBf5hFU.js} +4 -4
  37. package/{figure-9bZNx4iM.js → figure-BuslO32V.js} +3 -3
  38. package/{footnote-CbSZPnS_.js → footnote-Al4M2M0W.js} +2 -2
  39. package/{graph-BcgGZcap.js → graph-r49CFaUv.js} +2 -2
  40. package/{hint-DNBGmAUx.js → hint-BO406okN.js} +4 -4
  41. package/{hr-QPW8MOW9.js → hr-UwFvQ05W.js} +2 -2
  42. package/{image-RdgTJkyJ.js → image-D8EwdSwZ.js} +3 -3
  43. package/{index-BAm6ZYJS.js → index-Do6rFsPK.js} +1 -1
  44. package/{index.es-D22JmNgX.js → index.es-DwVEXQe4.js} +1 -1
  45. package/index.js +1 -1
  46. package/{label-Ch4ABCmv.js → label-B9hE5qQ5.js} +3 -3
  47. package/{legend-CxBwSOao.js → legend-Dao1VCWV.js} +3 -3
  48. package/{line-CST9KGTg.js → line-DpdAQLpf.js} +3 -3
  49. package/{lineSegment-DvuWsavN.js → lineSegment-BkMHiYwR.js} +3 -3
  50. package/{list-FfXRWagF.js → list-uhJLLQqN.js} +3 -3
  51. package/{lq-CMzJMKYu.js → lq-CI72iL-9.js} +2 -2
  52. package/{lsq-CJFVdiGq.js → lsq-DVFGTMD9.js} +2 -2
  53. package/{math-DLZM_qu3.js → math-D7d4dQ2-.js} +3 -3
  54. package/{mathInput-BRWecq0J.js → mathInput-CpZzH0MX.js} +3 -3
  55. package/{matrixInput-D9OSOupB.js → matrixInput-CpV6kMy_.js} +3 -3
  56. package/{mdash-NGpH8PbV.js → mdash-CRz-3iDH.js} +2 -2
  57. package/{nbsp-BkDcEEMd.js → nbsp-D-SLRemn.js} +2 -2
  58. package/{ndash-7uwZ0Vtv.js → ndash-B43H3bVO.js} +2 -2
  59. package/{number-BjW9vouS.js → number-De1SJm5e.js} +3 -3
  60. package/{orbitalDiagram-DVfWFW5p.js → orbitalDiagram-DnIYHZa8.js} +2 -2
  61. package/{orbitalDiagramInput-TI_kpwe2.js → orbitalDiagramInput-CLznCd5S.js} +2 -2
  62. package/{p-DIRk568L.js → p-75d6EEkg.js} +3 -3
  63. package/package.json +1 -1
  64. package/{paginatorControls-DtNpYi-3.js → paginatorControls--vMcNSXv.js} +2 -2
  65. package/{pegboard-Bd1SmP6c.js → pegboard-DT9abIL-.js} +3 -3
  66. package/{point-ajtgi6lk.js → point-BHZ4o6NX.js} +3 -3
  67. package/{polygon-DcXyS9Ph.js → polygon-BiEMEyjk.js} +3 -3
  68. package/{polyline-CRwTNWf5.js → polyline-noPFbzFC.js} +3 -3
  69. package/{pre-ISpysPrB.js → pre-YizZHsZJ.js} +3 -3
  70. package/{pretzel-C-W3KUtT.js → pretzel-DD2ytdMP.js} +10 -10
  71. package/{q-9YAZWbJW.js → q-CtoWDQGH.js} +3 -3
  72. package/{ray-DTvHO_-L.js → ray-BQF4PwFi.js} +3 -3
  73. package/{ref-D633sFJy.js → ref-DHfvHSCh.js} +2 -2
  74. package/{regionBetweenCurveXAxis-DNfFew93.js → regionBetweenCurveXAxis-CBl2mtC7.js} +3 -3
  75. package/{regionBetweenCurves-CLA-Zsiq.js → regionBetweenCurves-DrQ4AX6q.js} +3 -3
  76. package/{row-CV1QCTA0.js → row-DJbLSGc8.js} +2 -2
  77. package/{rq-BRPvlvjn.js → rq-BD3HFkhc.js} +2 -2
  78. package/{rsq-BQMfhXNb.js → rsq-DRn1_kFR.js} +2 -2
  79. package/{section-DT_Z-23R.js → section-Da_am71R.js} +4 -4
  80. package/{sideBySide-Dtp5c9BG.js → sideBySide-DpcQxkvw.js} +2 -2
  81. package/{slider-BFyzacAf.js → slider-DK8PUbd9.js} +2 -2
  82. package/{solution-1VBLNvz4.js → solution-O_NmIk_k.js} +4 -4
  83. package/{spreadsheet-MfSFcH3t.js → spreadsheet-Dy1dHEv0.js} +2 -2
  84. package/{sq-n0NGxzEy.js → sq-BCFfXZkj.js} +3 -3
  85. package/style.css +1 -18
  86. package/{subsetOfRealsInput-CkL6dCxk.js → subsetOfRealsInput-CdidOJbE.js} +2 -2
  87. package/{summaryStatistics-CWXqxbd3.js → summaryStatistics-Ce7TOEzD.js} +2 -2
  88. package/{table-CPAT4aYa.js → table-CGlfqr1L.js} +2 -2
  89. package/{tabular-smi1xfCS.js → tabular-piECKsrd.js} +2 -2
  90. package/{tag-DOduYdqv.js → tag-BDVE5gVz.js} +2 -2
  91. package/{text-Da5gA47C.js → text-D9bFKQGa.js} +3 -3
  92. package/{textInput-Ct1xd6qU.js → textInput-CNacHNm3.js} +4 -4
  93. package/useDoenetRenderer-CMXlgrx4.js +109 -0
  94. package/{vector-D_QrHdix.js → vector-6XLsqMaA.js} +3 -3
  95. package/{video-eWJTnq9V.js → video-aqnwoAr2.js} +2 -2
  96. package/Viewer/renderers/utils/AnswerResponseMenu.d.ts.map +0 -1
  97. package/checkwork-Bq0PLxIc.js +0 -1320
  98. package/useDoenetRenderer-CA8ny0Vp.js +0 -109
@@ -1,1320 +0,0 @@
1
- import { x as createPopoverStore, y as __spreadProps, z as defaultValue, G as __spreadValues, H as createStore, I as useStoreProps, J as usePopoverStoreProps, K as createStoreContext, P as PopoverScopedContextProvider, L as PopoverContextProvider, N as createHook, O as __objRest, Q as invariant, R as usePortalRef, S as useIsMouseMoving, U as useBooleanEvent, V as chain, W as addGlobalEventListener, X as useLiveRef, Y as useSafeLayoutEffect, Z as useWrapElement, j as jsxRuntimeExports, $ as __spreadProps$1, a0 as useMergeRefs, a1 as __spreadValues$1, a2 as usePopover, a3 as isFalsyBooleanCallback, a4 as contains, a5 as useEvent, a6 as sync, a7 as hasFocusWithin, a8 as createDialogComponent, a9 as forwardRef2, aa as createElement, ab as disabledFromProps, ac as useFocusable, ad as CompositeScopedContextProvider, ae as CompositeContextProvider, af as __objRest$1, ag as mergeStore, ah as omit2, ai as pick2, aj as throwOnConflictingProps, ak as createCompositeStore, al as setup, am as applyState, an as useComboboxProviderContext, ao as useStore, ap as useUpdateEffect, aq as useCompositeStoreProps, ar as useId, as as useStoreState, at as isHidden, au as useComposite, av as useCompositeTypeahead, aw as fireEvent, ax as Role, ay as getPopupItemRole, az as getPopupRole, aA as usePopoverDisclosure, aB as memo2, aC as isDownloading, aD as isOpeningInNewTab, aE as useCompositeItem, aF as useCompositeHover, aG as getDocument } from "./doenetml-BxYCfP3q.js";
2
- import { useRef, useState, useEffect, useContext, createContext, useCallback, createRef, useMemo } from "react";
3
- import { F as FontAwesomeIcon } from "./index.es-D22JmNgX.js";
4
- import { a as faLevelDownAlt, b as faCheck, c as faTimes, d as faCloud } from "./index-CS9Bi7Fd.js";
5
- import styled from "styled-components";
6
- function createHovercardStore(props = {}) {
7
- var _a;
8
- const syncState = (_a = props.store) == null ? void 0 : _a.getState();
9
- const popover = createPopoverStore(__spreadProps(__spreadValues({}, props), {
10
- placement: defaultValue(
11
- props.placement,
12
- syncState == null ? void 0 : syncState.placement,
13
- "bottom"
14
- )
15
- }));
16
- const timeout = defaultValue(props.timeout, syncState == null ? void 0 : syncState.timeout, 500);
17
- const initialState = __spreadProps(__spreadValues({}, popover.getState()), {
18
- timeout,
19
- showTimeout: defaultValue(props.showTimeout, syncState == null ? void 0 : syncState.showTimeout),
20
- hideTimeout: defaultValue(props.hideTimeout, syncState == null ? void 0 : syncState.hideTimeout),
21
- autoFocusOnShow: defaultValue(syncState == null ? void 0 : syncState.autoFocusOnShow, false)
22
- });
23
- const hovercard = createStore(initialState, popover, props.store);
24
- return __spreadProps(__spreadValues(__spreadValues({}, popover), hovercard), {
25
- setAutoFocusOnShow: (value) => hovercard.setState("autoFocusOnShow", value)
26
- });
27
- }
28
- function useHovercardStoreProps(store, update, props) {
29
- useStoreProps(store, props, "timeout");
30
- useStoreProps(store, props, "showTimeout");
31
- useStoreProps(store, props, "hideTimeout");
32
- return usePopoverStoreProps(store, update, props);
33
- }
34
- var ctx = createStoreContext(
35
- [PopoverContextProvider],
36
- [PopoverScopedContextProvider]
37
- );
38
- ctx.useContext;
39
- ctx.useScopedContext;
40
- var useHovercardProviderContext = ctx.useProviderContext;
41
- var HovercardContextProvider = ctx.ContextProvider;
42
- var HovercardScopedContextProvider = ctx.ScopedContextProvider;
43
- function getEventPoint(event) {
44
- return [event.clientX, event.clientY];
45
- }
46
- function isPointInPolygon(point, polygon) {
47
- const [x, y] = point;
48
- let inside = false;
49
- const length = polygon.length;
50
- for (let l = length, i = 0, j = l - 1; i < l; j = i++) {
51
- const [xi, yi] = polygon[i];
52
- const [xj, yj] = polygon[j];
53
- const [, vy] = polygon[j === 0 ? l - 1 : j - 1] || [0, 0];
54
- const where = (yi - yj) * (x - xi) - (xi - xj) * (y - yi);
55
- if (yj < yi) {
56
- if (y >= yj && y < yi) {
57
- if (where === 0) return true;
58
- if (where > 0) {
59
- if (y === yj) {
60
- if (y > vy) {
61
- inside = !inside;
62
- }
63
- } else {
64
- inside = !inside;
65
- }
66
- }
67
- }
68
- } else if (yi < yj) {
69
- if (y > yi && y <= yj) {
70
- if (where === 0) return true;
71
- if (where < 0) {
72
- if (y === yj) {
73
- if (y < vy) {
74
- inside = !inside;
75
- }
76
- } else {
77
- inside = !inside;
78
- }
79
- }
80
- }
81
- } else if (y === yi && (x >= xj && x <= xi || x >= xi && x <= xj)) {
82
- return true;
83
- }
84
- }
85
- return inside;
86
- }
87
- function getEnterPointPlacement(enterPoint, rect) {
88
- const { top, right, bottom, left } = rect;
89
- const [x, y] = enterPoint;
90
- const placementX = x < left ? "left" : x > right ? "right" : null;
91
- const placementY = y < top ? "top" : y > bottom ? "bottom" : null;
92
- return [placementX, placementY];
93
- }
94
- function getElementPolygon(element, enterPoint) {
95
- const rect = element.getBoundingClientRect();
96
- const { top, right, bottom, left } = rect;
97
- const [x, y] = getEnterPointPlacement(enterPoint, rect);
98
- const polygon = [enterPoint];
99
- if (x) {
100
- if (y !== "top") {
101
- polygon.push([x === "left" ? left : right, top]);
102
- }
103
- polygon.push([x === "left" ? right : left, top]);
104
- polygon.push([x === "left" ? right : left, bottom]);
105
- if (y !== "bottom") {
106
- polygon.push([x === "left" ? left : right, bottom]);
107
- }
108
- } else if (y === "top") {
109
- polygon.push([left, top]);
110
- polygon.push([left, bottom]);
111
- polygon.push([right, bottom]);
112
- polygon.push([right, top]);
113
- } else {
114
- polygon.push([left, bottom]);
115
- polygon.push([left, top]);
116
- polygon.push([right, top]);
117
- polygon.push([right, bottom]);
118
- }
119
- return polygon;
120
- }
121
- var TagName$5 = "div";
122
- function isMovingOnHovercard(target, card, anchor, nested) {
123
- if (hasFocusWithin(card)) return true;
124
- if (!target) return false;
125
- if (contains(card, target)) return true;
126
- if (anchor && contains(anchor, target)) return true;
127
- if (nested == null ? void 0 : nested.some((card2) => isMovingOnHovercard(target, card2, anchor))) {
128
- return true;
129
- }
130
- return false;
131
- }
132
- function useAutoFocusOnHide(_a) {
133
- var _b = _a, {
134
- store
135
- } = _b, props = __objRest(_b, [
136
- "store"
137
- ]);
138
- const [autoFocusOnHide, setAutoFocusOnHide] = useState(false);
139
- const mounted = store.useState("mounted");
140
- useEffect(() => {
141
- if (!mounted) {
142
- setAutoFocusOnHide(false);
143
- }
144
- }, [mounted]);
145
- const onFocusProp = props.onFocus;
146
- const onFocus = useEvent((event) => {
147
- onFocusProp == null ? void 0 : onFocusProp(event);
148
- if (event.defaultPrevented) return;
149
- setAutoFocusOnHide(true);
150
- });
151
- const finalFocusRef = useRef(null);
152
- useEffect(() => {
153
- return sync(store, ["anchorElement"], (state) => {
154
- finalFocusRef.current = state.anchorElement;
155
- });
156
- }, []);
157
- props = __spreadProps$1(__spreadValues$1({
158
- autoFocusOnHide,
159
- finalFocus: finalFocusRef
160
- }, props), {
161
- onFocus
162
- });
163
- return props;
164
- }
165
- var NestedHovercardContext = createContext(null);
166
- var useHovercard = createHook(
167
- function useHovercard2(_a) {
168
- var _b = _a, {
169
- store,
170
- modal = false,
171
- portal = !!modal,
172
- hideOnEscape = true,
173
- hideOnHoverOutside = true,
174
- disablePointerEventsOnApproach = !!hideOnHoverOutside
175
- } = _b, props = __objRest(_b, [
176
- "store",
177
- "modal",
178
- "portal",
179
- "hideOnEscape",
180
- "hideOnHoverOutside",
181
- "disablePointerEventsOnApproach"
182
- ]);
183
- const context = useHovercardProviderContext();
184
- store = store || context;
185
- invariant(
186
- store,
187
- process.env.NODE_ENV !== "production" && "Hovercard must receive a `store` prop or be wrapped in a HovercardProvider component."
188
- );
189
- const ref = useRef(null);
190
- const [nestedHovercards, setNestedHovercards] = useState([]);
191
- const hideTimeoutRef = useRef(0);
192
- const enterPointRef = useRef(null);
193
- const { portalRef, domReady } = usePortalRef(portal, props.portalRef);
194
- const isMouseMoving = useIsMouseMoving();
195
- const mayHideOnHoverOutside = !!hideOnHoverOutside;
196
- const hideOnHoverOutsideProp = useBooleanEvent(hideOnHoverOutside);
197
- const mayDisablePointerEvents = !!disablePointerEventsOnApproach;
198
- const disablePointerEventsProp = useBooleanEvent(
199
- disablePointerEventsOnApproach
200
- );
201
- const open = store.useState("open");
202
- const mounted = store.useState("mounted");
203
- useEffect(() => {
204
- if (!domReady) return;
205
- if (!mounted) return;
206
- if (!mayHideOnHoverOutside && !mayDisablePointerEvents) return;
207
- const element = ref.current;
208
- if (!element) return;
209
- const onMouseMove = (event) => {
210
- if (!store) return;
211
- if (!isMouseMoving()) return;
212
- const { anchorElement, hideTimeout, timeout } = store.getState();
213
- const enterPoint = enterPointRef.current;
214
- const [target] = event.composedPath();
215
- const anchor = anchorElement;
216
- if (isMovingOnHovercard(target, element, anchor, nestedHovercards)) {
217
- enterPointRef.current = target && anchor && contains(anchor, target) ? getEventPoint(event) : null;
218
- window.clearTimeout(hideTimeoutRef.current);
219
- hideTimeoutRef.current = 0;
220
- return;
221
- }
222
- if (hideTimeoutRef.current) return;
223
- if (enterPoint) {
224
- const currentPoint = getEventPoint(event);
225
- const polygon = getElementPolygon(element, enterPoint);
226
- if (isPointInPolygon(currentPoint, polygon)) {
227
- enterPointRef.current = currentPoint;
228
- if (!disablePointerEventsProp(event)) return;
229
- event.preventDefault();
230
- event.stopPropagation();
231
- return;
232
- }
233
- }
234
- if (!hideOnHoverOutsideProp(event)) return;
235
- hideTimeoutRef.current = window.setTimeout(() => {
236
- hideTimeoutRef.current = 0;
237
- store == null ? void 0 : store.hide();
238
- }, hideTimeout != null ? hideTimeout : timeout);
239
- };
240
- return chain(
241
- addGlobalEventListener("mousemove", onMouseMove, true),
242
- () => clearTimeout(hideTimeoutRef.current)
243
- );
244
- }, [
245
- store,
246
- isMouseMoving,
247
- domReady,
248
- mounted,
249
- mayHideOnHoverOutside,
250
- mayDisablePointerEvents,
251
- nestedHovercards,
252
- disablePointerEventsProp,
253
- hideOnHoverOutsideProp
254
- ]);
255
- useEffect(() => {
256
- if (!domReady) return;
257
- if (!mounted) return;
258
- if (!mayDisablePointerEvents) return;
259
- const disableEvent = (event) => {
260
- const element = ref.current;
261
- if (!element) return;
262
- const enterPoint = enterPointRef.current;
263
- if (!enterPoint) return;
264
- const polygon = getElementPolygon(element, enterPoint);
265
- if (isPointInPolygon(getEventPoint(event), polygon)) {
266
- if (!disablePointerEventsProp(event)) return;
267
- event.preventDefault();
268
- event.stopPropagation();
269
- }
270
- };
271
- return chain(
272
- // Note: we may need to add pointer events here in the future.
273
- addGlobalEventListener("mouseenter", disableEvent, true),
274
- addGlobalEventListener("mouseover", disableEvent, true),
275
- addGlobalEventListener("mouseout", disableEvent, true),
276
- addGlobalEventListener("mouseleave", disableEvent, true)
277
- );
278
- }, [domReady, mounted, mayDisablePointerEvents, disablePointerEventsProp]);
279
- useEffect(() => {
280
- if (!domReady) return;
281
- if (open) return;
282
- store == null ? void 0 : store.setAutoFocusOnShow(false);
283
- }, [store, domReady, open]);
284
- const openRef = useLiveRef(open);
285
- useEffect(() => {
286
- if (!domReady) return;
287
- return () => {
288
- if (!openRef.current) {
289
- store == null ? void 0 : store.setAutoFocusOnShow(false);
290
- }
291
- };
292
- }, [store, domReady]);
293
- const registerOnParent = useContext(NestedHovercardContext);
294
- useSafeLayoutEffect(() => {
295
- if (modal) return;
296
- if (!portal) return;
297
- if (!mounted) return;
298
- if (!domReady) return;
299
- const element = ref.current;
300
- if (!element) return;
301
- return registerOnParent == null ? void 0 : registerOnParent(element);
302
- }, [modal, portal, mounted, domReady]);
303
- const registerNestedHovercard = useCallback(
304
- (element) => {
305
- setNestedHovercards((prevElements) => [...prevElements, element]);
306
- const parentUnregister = registerOnParent == null ? void 0 : registerOnParent(element);
307
- return () => {
308
- setNestedHovercards(
309
- (prevElements) => prevElements.filter((item) => item !== element)
310
- );
311
- parentUnregister == null ? void 0 : parentUnregister();
312
- };
313
- },
314
- [registerOnParent]
315
- );
316
- props = useWrapElement(
317
- props,
318
- (element) => /* @__PURE__ */ jsxRuntimeExports.jsx(HovercardScopedContextProvider, { value: store, children: /* @__PURE__ */ jsxRuntimeExports.jsx(NestedHovercardContext.Provider, { value: registerNestedHovercard, children: element }) }),
319
- [store, registerNestedHovercard]
320
- );
321
- props = __spreadProps$1(__spreadValues$1({}, props), {
322
- ref: useMergeRefs(ref, props.ref)
323
- });
324
- props = useAutoFocusOnHide(__spreadValues$1({ store }, props));
325
- const autoFocusOnShow = store.useState(
326
- (state) => modal || state.autoFocusOnShow
327
- );
328
- props = usePopover(__spreadProps$1(__spreadValues$1({
329
- store,
330
- modal,
331
- portal,
332
- autoFocusOnShow
333
- }, props), {
334
- portalRef,
335
- hideOnEscape(event) {
336
- if (isFalsyBooleanCallback(hideOnEscape, event)) return false;
337
- requestAnimationFrame(() => {
338
- requestAnimationFrame(() => {
339
- store == null ? void 0 : store.hide();
340
- });
341
- });
342
- return true;
343
- }
344
- }));
345
- return props;
346
- }
347
- );
348
- createDialogComponent(
349
- forwardRef2(function Hovercard2(props) {
350
- const htmlProps = useHovercard(props);
351
- return createElement(TagName$5, htmlProps);
352
- }),
353
- useHovercardProviderContext
354
- );
355
- var TagName$4 = "a";
356
- var useHovercardAnchor = createHook(
357
- function useHovercardAnchor2(_a) {
358
- var _b = _a, { store, showOnHover = true } = _b, props = __objRest(_b, ["store", "showOnHover"]);
359
- const context = useHovercardProviderContext();
360
- store = store || context;
361
- invariant(
362
- store,
363
- process.env.NODE_ENV !== "production" && "HovercardAnchor must receive a `store` prop or be wrapped in a HovercardProvider component."
364
- );
365
- const disabled = disabledFromProps(props);
366
- const showTimeoutRef = useRef(0);
367
- useEffect(() => () => window.clearTimeout(showTimeoutRef.current), []);
368
- useEffect(() => {
369
- const onMouseLeave = (event) => {
370
- if (!store) return;
371
- const { anchorElement } = store.getState();
372
- if (!anchorElement) return;
373
- if (event.target !== anchorElement) return;
374
- window.clearTimeout(showTimeoutRef.current);
375
- showTimeoutRef.current = 0;
376
- };
377
- return addGlobalEventListener("mouseleave", onMouseLeave, true);
378
- }, [store]);
379
- const onMouseMoveProp = props.onMouseMove;
380
- const showOnHoverProp = useBooleanEvent(showOnHover);
381
- const isMouseMoving = useIsMouseMoving();
382
- const onMouseMove = useEvent((event) => {
383
- onMouseMoveProp == null ? void 0 : onMouseMoveProp(event);
384
- if (disabled) return;
385
- if (!store) return;
386
- if (event.defaultPrevented) return;
387
- if (showTimeoutRef.current) return;
388
- if (!isMouseMoving()) return;
389
- if (!showOnHoverProp(event)) return;
390
- const element = event.currentTarget;
391
- store.setAnchorElement(element);
392
- store.setDisclosureElement(element);
393
- const { showTimeout, timeout } = store.getState();
394
- const showHovercard = () => {
395
- showTimeoutRef.current = 0;
396
- if (!isMouseMoving()) return;
397
- store == null ? void 0 : store.setAnchorElement(element);
398
- store == null ? void 0 : store.show();
399
- queueMicrotask(() => {
400
- store == null ? void 0 : store.setDisclosureElement(element);
401
- });
402
- };
403
- const timeoutMs = showTimeout != null ? showTimeout : timeout;
404
- if (timeoutMs === 0) {
405
- showHovercard();
406
- } else {
407
- showTimeoutRef.current = window.setTimeout(showHovercard, timeoutMs);
408
- }
409
- });
410
- const onClickProp = props.onClick;
411
- const onClick = useEvent((event) => {
412
- onClickProp == null ? void 0 : onClickProp(event);
413
- if (!store) return;
414
- window.clearTimeout(showTimeoutRef.current);
415
- showTimeoutRef.current = 0;
416
- });
417
- const ref = useCallback(
418
- (element) => {
419
- if (!store) return;
420
- const { anchorElement } = store.getState();
421
- if (anchorElement == null ? void 0 : anchorElement.isConnected) return;
422
- store.setAnchorElement(element);
423
- },
424
- [store]
425
- );
426
- props = __spreadProps$1(__spreadValues$1({}, props), {
427
- ref: useMergeRefs(ref, props.ref),
428
- onMouseMove,
429
- onClick
430
- });
431
- props = useFocusable(props);
432
- return props;
433
- }
434
- );
435
- forwardRef2(function HovercardAnchor2(props) {
436
- const htmlProps = useHovercardAnchor(props);
437
- return createElement(TagName$4, htmlProps);
438
- });
439
- var menubar = createStoreContext(
440
- [CompositeContextProvider],
441
- [CompositeScopedContextProvider]
442
- );
443
- var useMenubarContext = menubar.useContext;
444
- var useMenubarScopedContext = menubar.useScopedContext;
445
- createContext(
446
- void 0
447
- );
448
- var menu = createStoreContext(
449
- [CompositeContextProvider, HovercardContextProvider],
450
- [CompositeScopedContextProvider, HovercardScopedContextProvider]
451
- );
452
- var useMenuContext = menu.useContext;
453
- var useMenuScopedContext = menu.useScopedContext;
454
- var useMenuProviderContext = menu.useProviderContext;
455
- var MenuContextProvider = menu.ContextProvider;
456
- var MenuScopedContextProvider = menu.ScopedContextProvider;
457
- createContext(
458
- void 0
459
- );
460
- function createMenuStore(_a = {}) {
461
- var _b = _a, {
462
- combobox,
463
- parent,
464
- menubar: menubar2
465
- } = _b, props = __objRest$1(_b, [
466
- "combobox",
467
- "parent",
468
- "menubar"
469
- ]);
470
- const parentIsMenubar = !!menubar2 && !parent;
471
- const store = mergeStore(
472
- props.store,
473
- pick2(parent, ["values"]),
474
- omit2(combobox, [
475
- "arrowElement",
476
- "anchorElement",
477
- "contentElement",
478
- "popoverElement",
479
- "disclosureElement"
480
- ])
481
- );
482
- throwOnConflictingProps(props, store);
483
- const syncState = store.getState();
484
- const composite = createCompositeStore(__spreadProps(__spreadValues({}, props), {
485
- store,
486
- orientation: defaultValue(
487
- props.orientation,
488
- syncState.orientation,
489
- "vertical"
490
- )
491
- }));
492
- const hovercard = createHovercardStore(__spreadProps(__spreadValues({}, props), {
493
- store,
494
- placement: defaultValue(
495
- props.placement,
496
- syncState.placement,
497
- "bottom-start"
498
- ),
499
- timeout: defaultValue(
500
- props.timeout,
501
- syncState.timeout,
502
- parentIsMenubar ? 0 : 150
503
- ),
504
- hideTimeout: defaultValue(props.hideTimeout, syncState.hideTimeout, 0)
505
- }));
506
- const initialState = __spreadProps(__spreadValues(__spreadValues({}, composite.getState()), hovercard.getState()), {
507
- initialFocus: defaultValue(syncState.initialFocus, "container"),
508
- values: defaultValue(
509
- props.values,
510
- syncState.values,
511
- props.defaultValues,
512
- {}
513
- )
514
- });
515
- const menu2 = createStore(initialState, composite, hovercard, store);
516
- setup(
517
- menu2,
518
- () => sync(menu2, ["mounted"], (state) => {
519
- if (state.mounted) return;
520
- menu2.setState("activeId", null);
521
- })
522
- );
523
- setup(
524
- menu2,
525
- () => sync(parent, ["orientation"], (state) => {
526
- menu2.setState(
527
- "placement",
528
- state.orientation === "vertical" ? "right-start" : "bottom-start"
529
- );
530
- })
531
- );
532
- return __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, composite), hovercard), menu2), {
533
- combobox,
534
- parent,
535
- menubar: menubar2,
536
- hideAll: () => {
537
- hovercard.hide();
538
- parent == null ? void 0 : parent.hideAll();
539
- },
540
- setInitialFocus: (value) => menu2.setState("initialFocus", value),
541
- setValues: (values) => menu2.setState("values", values),
542
- setValue: (name, value) => {
543
- if (name === "__proto__") return;
544
- if (name === "constructor") return;
545
- if (Array.isArray(name)) return;
546
- menu2.setState("values", (values) => {
547
- const prevValue = values[name];
548
- const nextValue = applyState(value, prevValue);
549
- if (nextValue === prevValue) return values;
550
- return __spreadProps(__spreadValues({}, values), {
551
- [name]: nextValue !== void 0 && nextValue
552
- });
553
- });
554
- }
555
- });
556
- }
557
- function useMenuStoreProps(store, update, props) {
558
- useUpdateEffect(update, [props.combobox, props.parent, props.menubar]);
559
- useStoreProps(store, props, "values", "setValues");
560
- return Object.assign(
561
- useHovercardStoreProps(
562
- useCompositeStoreProps(store, update, props),
563
- update,
564
- props
565
- ),
566
- {
567
- combobox: props.combobox,
568
- parent: props.parent,
569
- menubar: props.menubar
570
- }
571
- );
572
- }
573
- function useMenuStore(props = {}) {
574
- const parent = useMenuContext();
575
- const menubar2 = useMenubarContext();
576
- const combobox = useComboboxProviderContext();
577
- props = __spreadProps$1(__spreadValues$1({}, props), {
578
- parent: props.parent !== void 0 ? props.parent : parent,
579
- menubar: props.menubar !== void 0 ? props.menubar : menubar2,
580
- combobox: props.combobox !== void 0 ? props.combobox : combobox
581
- });
582
- const [store, update] = useStore(createMenuStore, props);
583
- return useMenuStoreProps(store, update, props);
584
- }
585
- var TagName$3 = "div";
586
- function useAriaLabelledBy(_a) {
587
- var _b = _a, { store } = _b, props = __objRest(_b, ["store"]);
588
- const [id, setId] = useState(void 0);
589
- const label = props["aria-label"];
590
- const disclosureElement = useStoreState(store, "disclosureElement");
591
- const contentElement = useStoreState(store, "contentElement");
592
- useEffect(() => {
593
- const disclosure = disclosureElement;
594
- if (!disclosure) return;
595
- const menu2 = contentElement;
596
- if (!menu2) return;
597
- const menuLabel = label || menu2.hasAttribute("aria-label");
598
- if (menuLabel) {
599
- setId(void 0);
600
- } else if (disclosure.id) {
601
- setId(disclosure.id);
602
- }
603
- }, [label, disclosureElement, contentElement]);
604
- return id;
605
- }
606
- var useMenuList = createHook(
607
- function useMenuList2(_a) {
608
- var _b = _a, { store, alwaysVisible, composite } = _b, props = __objRest(_b, ["store", "alwaysVisible", "composite"]);
609
- const context = useMenuProviderContext();
610
- store = store || context;
611
- invariant(
612
- store,
613
- process.env.NODE_ENV !== "production" && "MenuList must receive a `store` prop or be wrapped in a MenuProvider component."
614
- );
615
- const parentMenu = store.parent;
616
- const parentMenubar = store.menubar;
617
- const hasParentMenu = !!parentMenu;
618
- const id = useId(props.id);
619
- const onKeyDownProp = props.onKeyDown;
620
- const dir = store.useState(
621
- (state) => state.placement.split("-")[0]
622
- );
623
- const orientation = store.useState(
624
- (state) => state.orientation === "both" ? void 0 : state.orientation
625
- );
626
- const isHorizontal = orientation !== "vertical";
627
- const isMenubarHorizontal = useStoreState(
628
- parentMenubar,
629
- (state) => !!state && state.orientation !== "vertical"
630
- );
631
- const onKeyDown = useEvent((event) => {
632
- onKeyDownProp == null ? void 0 : onKeyDownProp(event);
633
- if (event.defaultPrevented) return;
634
- if (hasParentMenu || parentMenubar && !isHorizontal) {
635
- const hideMap = {
636
- ArrowRight: () => dir === "left" && !isHorizontal,
637
- ArrowLeft: () => dir === "right" && !isHorizontal,
638
- ArrowUp: () => dir === "bottom" && isHorizontal,
639
- ArrowDown: () => dir === "top" && isHorizontal
640
- };
641
- const action = hideMap[event.key];
642
- if (action == null ? void 0 : action()) {
643
- event.stopPropagation();
644
- event.preventDefault();
645
- return store == null ? void 0 : store.hide();
646
- }
647
- }
648
- if (parentMenubar) {
649
- const keyMap = {
650
- ArrowRight: () => {
651
- if (!isMenubarHorizontal) return;
652
- return parentMenubar.next();
653
- },
654
- ArrowLeft: () => {
655
- if (!isMenubarHorizontal) return;
656
- return parentMenubar.previous();
657
- },
658
- ArrowDown: () => {
659
- if (isMenubarHorizontal) return;
660
- return parentMenubar.next();
661
- },
662
- ArrowUp: () => {
663
- if (isMenubarHorizontal) return;
664
- return parentMenubar.previous();
665
- }
666
- };
667
- const action = keyMap[event.key];
668
- const id2 = action == null ? void 0 : action();
669
- if (id2 !== void 0) {
670
- event.stopPropagation();
671
- event.preventDefault();
672
- parentMenubar.move(id2);
673
- }
674
- }
675
- });
676
- props = useWrapElement(
677
- props,
678
- (element) => /* @__PURE__ */ jsxRuntimeExports.jsx(MenuScopedContextProvider, { value: store, children: element }),
679
- [store]
680
- );
681
- const ariaLabelledBy = useAriaLabelledBy(__spreadValues$1({ store }, props));
682
- const mounted = store.useState("mounted");
683
- const hidden = isHidden(mounted, props.hidden, alwaysVisible);
684
- const style = hidden ? __spreadProps$1(__spreadValues$1({}, props.style), { display: "none" }) : props.style;
685
- props = __spreadProps$1(__spreadValues$1({
686
- id,
687
- "aria-labelledby": ariaLabelledBy,
688
- hidden
689
- }, props), {
690
- ref: useMergeRefs(id ? store.setContentElement : null, props.ref),
691
- style,
692
- onKeyDown
693
- });
694
- const hasCombobox = !!store.combobox;
695
- composite = composite != null ? composite : !hasCombobox;
696
- if (composite) {
697
- props = __spreadValues$1({
698
- role: "menu",
699
- "aria-orientation": orientation
700
- }, props);
701
- }
702
- props = useComposite(__spreadValues$1({ store, composite }, props));
703
- props = useCompositeTypeahead(__spreadValues$1({ store, typeahead: !hasCombobox }, props));
704
- return props;
705
- }
706
- );
707
- forwardRef2(function MenuList2(props) {
708
- const htmlProps = useMenuList(props);
709
- return createElement(TagName$3, htmlProps);
710
- });
711
- var TagName$2 = "div";
712
- var useMenu = createHook(function useMenu2(_a) {
713
- var _b = _a, {
714
- store,
715
- modal: modalProp = false,
716
- portal = !!modalProp,
717
- hideOnEscape = true,
718
- autoFocusOnShow = true,
719
- hideOnHoverOutside,
720
- alwaysVisible
721
- } = _b, props = __objRest(_b, [
722
- "store",
723
- "modal",
724
- "portal",
725
- "hideOnEscape",
726
- "autoFocusOnShow",
727
- "hideOnHoverOutside",
728
- "alwaysVisible"
729
- ]);
730
- const context = useMenuProviderContext();
731
- store = store || context;
732
- invariant(
733
- store,
734
- process.env.NODE_ENV !== "production" && "Menu must receive a `store` prop or be wrapped in a MenuProvider component."
735
- );
736
- const ref = useRef(null);
737
- const parentMenu = store.parent;
738
- const parentMenubar = store.menubar;
739
- const hasParentMenu = !!parentMenu;
740
- const parentIsMenubar = !!parentMenubar && !hasParentMenu;
741
- props = __spreadProps$1(__spreadValues$1({}, props), {
742
- ref: useMergeRefs(ref, props.ref)
743
- });
744
- const _a2 = useMenuList(__spreadValues$1({
745
- store,
746
- alwaysVisible
747
- }, props)), { "aria-labelledby": ariaLabelledBy } = _a2, menuListProps = __objRest(_a2, ["aria-labelledby"]);
748
- props = menuListProps;
749
- const [initialFocusRef, setInitialFocusRef] = useState();
750
- const autoFocusOnShowState = store.useState("autoFocusOnShow");
751
- const initialFocus = store.useState("initialFocus");
752
- const baseElement = store.useState("baseElement");
753
- const items = store.useState("renderedItems");
754
- useEffect(() => {
755
- let cleaning = false;
756
- setInitialFocusRef((prevInitialFocusRef) => {
757
- var _a3, _b2, _c;
758
- if (cleaning) return;
759
- if (!autoFocusOnShowState) return;
760
- if ((_a3 = prevInitialFocusRef == null ? void 0 : prevInitialFocusRef.current) == null ? void 0 : _a3.isConnected) return prevInitialFocusRef;
761
- const ref2 = createRef();
762
- switch (initialFocus) {
763
- // TODO: Refactor
764
- case "first":
765
- ref2.current = ((_b2 = items.find((item) => !item.disabled && item.element)) == null ? void 0 : _b2.element) || null;
766
- break;
767
- case "last":
768
- ref2.current = ((_c = [...items].reverse().find((item) => !item.disabled && item.element)) == null ? void 0 : _c.element) || null;
769
- break;
770
- default:
771
- ref2.current = baseElement;
772
- }
773
- return ref2;
774
- });
775
- return () => {
776
- cleaning = true;
777
- };
778
- }, [store, autoFocusOnShowState, initialFocus, items, baseElement]);
779
- const modal = hasParentMenu ? false : modalProp;
780
- const mayAutoFocusOnShow = !!autoFocusOnShow;
781
- const canAutoFocusOnShow = !!initialFocusRef || !!props.initialFocus || !!modal;
782
- const contentElement = useStoreState(
783
- store.combobox || store,
784
- "contentElement"
785
- );
786
- const parentContentElement = useStoreState(
787
- (parentMenu == null ? void 0 : parentMenu.combobox) || parentMenu,
788
- "contentElement"
789
- );
790
- const preserveTabOrderAnchor = useMemo(() => {
791
- if (!parentContentElement) return;
792
- if (!contentElement) return;
793
- const role = contentElement.getAttribute("role");
794
- const parentRole = parentContentElement.getAttribute("role");
795
- const parentIsMenuOrMenubar = parentRole === "menu" || parentRole === "menubar";
796
- if (parentIsMenuOrMenubar && role === "menu") return;
797
- return parentContentElement;
798
- }, [contentElement, parentContentElement]);
799
- if (preserveTabOrderAnchor !== void 0) {
800
- props = __spreadValues$1({
801
- preserveTabOrderAnchor
802
- }, props);
803
- }
804
- props = useHovercard(__spreadProps$1(__spreadValues$1({
805
- store,
806
- alwaysVisible,
807
- initialFocus: initialFocusRef,
808
- autoFocusOnShow: mayAutoFocusOnShow ? canAutoFocusOnShow && autoFocusOnShow : autoFocusOnShowState || !!modal
809
- }, props), {
810
- hideOnEscape(event) {
811
- if (isFalsyBooleanCallback(hideOnEscape, event)) return false;
812
- store == null ? void 0 : store.hideAll();
813
- return true;
814
- },
815
- hideOnHoverOutside(event) {
816
- const disclosureElement = store == null ? void 0 : store.getState().disclosureElement;
817
- const getHideOnHoverOutside = () => {
818
- if (typeof hideOnHoverOutside === "function") {
819
- return hideOnHoverOutside(event);
820
- }
821
- if (hideOnHoverOutside != null) return hideOnHoverOutside;
822
- if (hasParentMenu) return true;
823
- if (!parentIsMenubar) return false;
824
- if (!disclosureElement) return true;
825
- if (hasFocusWithin(disclosureElement)) return false;
826
- return true;
827
- };
828
- if (!getHideOnHoverOutside()) return false;
829
- if (event.defaultPrevented) return true;
830
- if (!hasParentMenu) return true;
831
- if (!disclosureElement) return true;
832
- fireEvent(disclosureElement, "mouseout", event);
833
- if (!hasFocusWithin(disclosureElement)) return true;
834
- requestAnimationFrame(() => {
835
- if (hasFocusWithin(disclosureElement)) return;
836
- store == null ? void 0 : store.hide();
837
- });
838
- return false;
839
- },
840
- modal,
841
- portal,
842
- backdrop: hasParentMenu ? false : props.backdrop
843
- }));
844
- props = __spreadValues$1({
845
- "aria-labelledby": ariaLabelledBy
846
- }, props);
847
- return props;
848
- });
849
- var Menu = createDialogComponent(
850
- forwardRef2(function Menu2(props) {
851
- const htmlProps = useMenu(props);
852
- return createElement(TagName$2, htmlProps);
853
- }),
854
- useMenuProviderContext
855
- );
856
- function MenuProvider(props = {}) {
857
- const store = useMenuStore(props);
858
- return /* @__PURE__ */ jsxRuntimeExports.jsx(MenuContextProvider, { value: store, children: props.children });
859
- }
860
- var TagName$1 = "button";
861
- function getInitialFocus(event, dir) {
862
- const keyMap = {
863
- ArrowDown: dir === "bottom" || dir === "top" ? "first" : false,
864
- ArrowUp: dir === "bottom" || dir === "top" ? "last" : false,
865
- ArrowRight: dir === "right" ? "first" : false,
866
- ArrowLeft: dir === "left" ? "first" : false
867
- };
868
- return keyMap[event.key];
869
- }
870
- function hasActiveItem(items, excludeElement) {
871
- return !!(items == null ? void 0 : items.some((item) => {
872
- if (!item.element) return false;
873
- if (item.element === excludeElement) return false;
874
- return item.element.getAttribute("aria-expanded") === "true";
875
- }));
876
- }
877
- var useMenuButton = createHook(
878
- function useMenuButton2(_a) {
879
- var _b = _a, {
880
- store,
881
- focusable,
882
- accessibleWhenDisabled,
883
- showOnHover
884
- } = _b, props = __objRest(_b, [
885
- "store",
886
- "focusable",
887
- "accessibleWhenDisabled",
888
- "showOnHover"
889
- ]);
890
- const context = useMenuProviderContext();
891
- store = store || context;
892
- invariant(
893
- store,
894
- process.env.NODE_ENV !== "production" && "MenuButton must receive a `store` prop or be wrapped in a MenuProvider component."
895
- );
896
- const ref = useRef(null);
897
- const parentMenu = store.parent;
898
- const parentMenubar = store.menubar;
899
- const hasParentMenu = !!parentMenu;
900
- const parentIsMenubar = !!parentMenubar && !hasParentMenu;
901
- const disabled = disabledFromProps(props);
902
- const showMenu = () => {
903
- const trigger = ref.current;
904
- if (!trigger) return;
905
- store == null ? void 0 : store.setDisclosureElement(trigger);
906
- store == null ? void 0 : store.setAnchorElement(trigger);
907
- store == null ? void 0 : store.show();
908
- };
909
- const onFocusProp = props.onFocus;
910
- const onFocus = useEvent((event) => {
911
- onFocusProp == null ? void 0 : onFocusProp(event);
912
- if (disabled) return;
913
- if (event.defaultPrevented) return;
914
- store == null ? void 0 : store.setAutoFocusOnShow(false);
915
- store == null ? void 0 : store.setActiveId(null);
916
- if (!parentMenubar) return;
917
- if (!parentIsMenubar) return;
918
- const { items } = parentMenubar.getState();
919
- if (hasActiveItem(items, event.currentTarget)) {
920
- showMenu();
921
- }
922
- });
923
- const dir = useStoreState(
924
- store,
925
- (state) => state.placement.split("-")[0]
926
- );
927
- const onKeyDownProp = props.onKeyDown;
928
- const onKeyDown = useEvent((event) => {
929
- onKeyDownProp == null ? void 0 : onKeyDownProp(event);
930
- if (disabled) return;
931
- if (event.defaultPrevented) return;
932
- const initialFocus = getInitialFocus(event, dir);
933
- if (initialFocus) {
934
- event.preventDefault();
935
- showMenu();
936
- store == null ? void 0 : store.setAutoFocusOnShow(true);
937
- store == null ? void 0 : store.setInitialFocus(initialFocus);
938
- }
939
- });
940
- const onClickProp = props.onClick;
941
- const onClick = useEvent((event) => {
942
- onClickProp == null ? void 0 : onClickProp(event);
943
- if (event.defaultPrevented) return;
944
- if (!store) return;
945
- const isKeyboardClick = !event.detail;
946
- const { open } = store.getState();
947
- if (!open || isKeyboardClick) {
948
- if (!hasParentMenu || isKeyboardClick) {
949
- store.setAutoFocusOnShow(true);
950
- }
951
- store.setInitialFocus(isKeyboardClick ? "first" : "container");
952
- }
953
- if (hasParentMenu) {
954
- showMenu();
955
- }
956
- });
957
- props = useWrapElement(
958
- props,
959
- (element) => /* @__PURE__ */ jsxRuntimeExports.jsx(MenuContextProvider, { value: store, children: element }),
960
- [store]
961
- );
962
- if (hasParentMenu) {
963
- props = __spreadProps$1(__spreadValues$1({}, props), {
964
- render: /* @__PURE__ */ jsxRuntimeExports.jsx(Role.div, { render: props.render })
965
- });
966
- }
967
- const id = useId(props.id);
968
- const parentContentElement = useStoreState(
969
- (parentMenu == null ? void 0 : parentMenu.combobox) || parentMenu,
970
- "contentElement"
971
- );
972
- const role = hasParentMenu || parentIsMenubar ? getPopupItemRole(parentContentElement, "menuitem") : void 0;
973
- const contentElement = store.useState("contentElement");
974
- props = __spreadProps$1(__spreadValues$1({
975
- id,
976
- role,
977
- "aria-haspopup": getPopupRole(contentElement, "menu")
978
- }, props), {
979
- ref: useMergeRefs(ref, props.ref),
980
- onFocus,
981
- onKeyDown,
982
- onClick
983
- });
984
- props = useHovercardAnchor(__spreadProps$1(__spreadValues$1({
985
- store,
986
- focusable,
987
- accessibleWhenDisabled
988
- }, props), {
989
- showOnHover: (event) => {
990
- const getShowOnHover = () => {
991
- if (typeof showOnHover === "function") return showOnHover(event);
992
- if (showOnHover != null) return showOnHover;
993
- if (hasParentMenu) return true;
994
- if (!parentMenubar) return false;
995
- const { items } = parentMenubar.getState();
996
- return parentIsMenubar && hasActiveItem(items);
997
- };
998
- const canShowOnHover = getShowOnHover();
999
- if (!canShowOnHover) return false;
1000
- const parent = parentIsMenubar ? parentMenubar : parentMenu;
1001
- if (!parent) return true;
1002
- parent.setActiveId(event.currentTarget.id);
1003
- return true;
1004
- }
1005
- }));
1006
- props = usePopoverDisclosure(__spreadValues$1({
1007
- store,
1008
- toggleOnClick: !hasParentMenu,
1009
- focusable,
1010
- accessibleWhenDisabled
1011
- }, props));
1012
- props = useCompositeTypeahead(__spreadValues$1({
1013
- store,
1014
- typeahead: parentIsMenubar
1015
- }, props));
1016
- return props;
1017
- }
1018
- );
1019
- var MenuButton = forwardRef2(function MenuButton2(props) {
1020
- const htmlProps = useMenuButton(props);
1021
- return createElement(TagName$1, htmlProps);
1022
- });
1023
- var TagName = "div";
1024
- function menuHasFocus(baseElement, items, currentTarget) {
1025
- var _a;
1026
- if (!baseElement) return false;
1027
- if (hasFocusWithin(baseElement)) return true;
1028
- const expandedItem = items == null ? void 0 : items.find((item) => {
1029
- var _a2;
1030
- if (item.element === currentTarget) return false;
1031
- return ((_a2 = item.element) == null ? void 0 : _a2.getAttribute("aria-expanded")) === "true";
1032
- });
1033
- const expandedMenuId = (_a = expandedItem == null ? void 0 : expandedItem.element) == null ? void 0 : _a.getAttribute("aria-controls");
1034
- if (!expandedMenuId) return false;
1035
- const doc = getDocument(baseElement);
1036
- const expandedMenu = doc.getElementById(expandedMenuId);
1037
- if (!expandedMenu) return false;
1038
- if (hasFocusWithin(expandedMenu)) return true;
1039
- return !!expandedMenu.querySelector("[role=menuitem][aria-expanded=true]");
1040
- }
1041
- var useMenuItem = createHook(
1042
- function useMenuItem2(_a) {
1043
- var _b = _a, {
1044
- store,
1045
- hideOnClick = true,
1046
- preventScrollOnKeyDown = true,
1047
- focusOnHover,
1048
- blurOnHoverEnd
1049
- } = _b, props = __objRest(_b, [
1050
- "store",
1051
- "hideOnClick",
1052
- "preventScrollOnKeyDown",
1053
- "focusOnHover",
1054
- "blurOnHoverEnd"
1055
- ]);
1056
- const menuContext = useMenuScopedContext(true);
1057
- const menubarContext = useMenubarScopedContext();
1058
- store = store || menuContext || menubarContext;
1059
- invariant(
1060
- store,
1061
- process.env.NODE_ENV !== "production" && "MenuItem must be wrapped in a MenuList, Menu or Menubar component"
1062
- );
1063
- const onClickProp = props.onClick;
1064
- const hideOnClickProp = useBooleanEvent(hideOnClick);
1065
- const hideMenu = "hideAll" in store ? store.hideAll : void 0;
1066
- const isWithinMenu = !!hideMenu;
1067
- const onClick = useEvent((event) => {
1068
- onClickProp == null ? void 0 : onClickProp(event);
1069
- if (event.defaultPrevented) return;
1070
- if (isDownloading(event)) return;
1071
- if (isOpeningInNewTab(event)) return;
1072
- if (!hideMenu) return;
1073
- const popupType = event.currentTarget.getAttribute("aria-haspopup");
1074
- if (popupType === "menu") return;
1075
- if (!hideOnClickProp(event)) return;
1076
- hideMenu();
1077
- });
1078
- const contentElement = useStoreState(
1079
- store,
1080
- (state) => "contentElement" in state ? state.contentElement : null
1081
- );
1082
- const role = getPopupItemRole(contentElement, "menuitem");
1083
- props = __spreadProps$1(__spreadValues$1({
1084
- role
1085
- }, props), {
1086
- onClick
1087
- });
1088
- props = useCompositeItem(__spreadValues$1({
1089
- store,
1090
- preventScrollOnKeyDown
1091
- }, props));
1092
- props = useCompositeHover(__spreadProps$1(__spreadValues$1({
1093
- store
1094
- }, props), {
1095
- focusOnHover(event) {
1096
- const getFocusOnHover = () => {
1097
- if (typeof focusOnHover === "function") return focusOnHover(event);
1098
- if (focusOnHover != null) return focusOnHover;
1099
- return true;
1100
- };
1101
- if (!store) return false;
1102
- if (!getFocusOnHover()) return false;
1103
- const { baseElement, items } = store.getState();
1104
- if (isWithinMenu) {
1105
- if (event.currentTarget.hasAttribute("aria-expanded")) {
1106
- event.currentTarget.focus();
1107
- }
1108
- return true;
1109
- }
1110
- if (menuHasFocus(baseElement, items, event.currentTarget)) {
1111
- event.currentTarget.focus();
1112
- return true;
1113
- }
1114
- return false;
1115
- },
1116
- blurOnHoverEnd(event) {
1117
- if (typeof blurOnHoverEnd === "function") return blurOnHoverEnd(event);
1118
- if (blurOnHoverEnd != null) return blurOnHoverEnd;
1119
- return isWithinMenu;
1120
- }
1121
- }));
1122
- return props;
1123
- }
1124
- );
1125
- var MenuItem = memo2(
1126
- forwardRef2(function MenuItem2(props) {
1127
- const htmlProps = useMenuItem(props);
1128
- return createElement(TagName, htmlProps);
1129
- })
1130
- );
1131
- function AnswerResponseMenu({
1132
- answerId,
1133
- answerComponentIdx,
1134
- activityId,
1135
- docId,
1136
- numResponses = 0
1137
- }) {
1138
- return /* @__PURE__ */ jsxRuntimeExports.jsxs(MenuProvider, { children: [
1139
- /* @__PURE__ */ jsxRuntimeExports.jsx(MenuButton, { className: "doenet-button action-button answer-response-menu-trigger", children: numResponses }),
1140
- /* @__PURE__ */ jsxRuntimeExports.jsx(Menu, { className: "answer-response-menu", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
1141
- MenuItem,
1142
- {
1143
- className: "answer-response-menu-item",
1144
- onClick: () => {
1145
- window.postMessage({
1146
- subject: "requestAnswerResponses",
1147
- answerComponentIdx,
1148
- answerId,
1149
- activityId,
1150
- docId
1151
- });
1152
- },
1153
- children: [
1154
- "Show ",
1155
- numResponses,
1156
- " response",
1157
- numResponses === 1 ? "" : "s",
1158
- " to ",
1159
- answerId
1160
- ]
1161
- }
1162
- ) })
1163
- ] });
1164
- }
1165
- const Button = styled.button`
1166
- position: relative;
1167
- height: 24px;
1168
- display: inline-block;
1169
- color: white;
1170
- background-color: var(--mainBlue);
1171
- padding: 2px;
1172
- /* border: var(--mainBorder); */
1173
- border: none;
1174
- border-radius: var(--mainBorderRadius);
1175
- margin: 0px 4px 4px 0px;
1176
-
1177
- &:hover {
1178
- background-color: var(--lightBlue);
1179
- color: black;
1180
- }
1181
- `;
1182
- function createCheckworkComponent(SVs, disabled, id, submitAnswer) {
1183
- let validationState = "unvalidated";
1184
- if (SVs.justSubmitted || SVs.numAttemptsLeft < 1) {
1185
- if (SVs.creditAchieved === 1) {
1186
- validationState = "correct";
1187
- } else if (SVs.creditAchieved === 0) {
1188
- validationState = "incorrect";
1189
- } else {
1190
- validationState = "partialcorrect";
1191
- }
1192
- }
1193
- let checkWorkStyle = {
1194
- cursor: "pointer",
1195
- padding: "1px 6px 1px 6px"
1196
- };
1197
- let checkWorkTabIndex = "0";
1198
- if (disabled) {
1199
- checkWorkStyle.backgroundColor = getComputedStyle(
1200
- document.documentElement
1201
- ).getPropertyValue("--mainGray");
1202
- checkWorkStyle.color = "black";
1203
- checkWorkStyle.cursor = "not-allowed";
1204
- checkWorkTabIndex = "-1";
1205
- }
1206
- let checkWorkText = SVs.submitLabel;
1207
- if (!SVs.showCorrectness) {
1208
- checkWorkText = SVs.submitLabelNoCorrectness;
1209
- }
1210
- let checkworkComponent = /* @__PURE__ */ jsxRuntimeExports.jsxs(
1211
- Button,
1212
- {
1213
- id: id + "_submit",
1214
- tabIndex: +checkWorkTabIndex,
1215
- disabled,
1216
- style: checkWorkStyle,
1217
- onClick: submitAnswer,
1218
- children: [
1219
- /* @__PURE__ */ jsxRuntimeExports.jsx(
1220
- FontAwesomeIcon,
1221
- {
1222
- icon: faLevelDownAlt,
1223
- transform: { rotate: 90 }
1224
- }
1225
- ),
1226
- " ",
1227
- checkWorkText
1228
- ]
1229
- }
1230
- );
1231
- if (SVs.showCorrectness) {
1232
- if (validationState === "correct") {
1233
- checkWorkStyle.backgroundColor = getComputedStyle(
1234
- document.documentElement
1235
- ).getPropertyValue("--mainGreen");
1236
- checkworkComponent = /* @__PURE__ */ jsxRuntimeExports.jsxs(
1237
- Button,
1238
- {
1239
- id: id + "_correct",
1240
- style: checkWorkStyle,
1241
- tabIndex: +checkWorkTabIndex,
1242
- children: [
1243
- /* @__PURE__ */ jsxRuntimeExports.jsx(FontAwesomeIcon, { icon: faCheck }),
1244
- "  Correct"
1245
- ]
1246
- }
1247
- );
1248
- } else if (validationState === "incorrect") {
1249
- checkWorkStyle.backgroundColor = getComputedStyle(
1250
- document.documentElement
1251
- ).getPropertyValue("--mainRed");
1252
- checkworkComponent = /* @__PURE__ */ jsxRuntimeExports.jsxs(
1253
- Button,
1254
- {
1255
- id: id + "_incorrect",
1256
- style: checkWorkStyle,
1257
- tabIndex: +checkWorkTabIndex,
1258
- children: [
1259
- /* @__PURE__ */ jsxRuntimeExports.jsx(FontAwesomeIcon, { icon: faTimes }),
1260
- "  Incorrect"
1261
- ]
1262
- }
1263
- );
1264
- } else if (validationState === "partialcorrect") {
1265
- checkWorkStyle.backgroundColor = "#efab34";
1266
- let percent = Math.round(SVs.creditAchieved * 100);
1267
- let partialCreditContents = `${percent}% Correct`;
1268
- checkworkComponent = /* @__PURE__ */ jsxRuntimeExports.jsx(
1269
- Button,
1270
- {
1271
- id: id + "_partial",
1272
- style: checkWorkStyle,
1273
- tabIndex: +checkWorkTabIndex,
1274
- children: partialCreditContents
1275
- }
1276
- );
1277
- }
1278
- } else {
1279
- if (validationState !== "unvalidated") {
1280
- checkWorkStyle.backgroundColor = "rgb(74, 3, 217)";
1281
- checkworkComponent = /* @__PURE__ */ jsxRuntimeExports.jsxs(
1282
- Button,
1283
- {
1284
- id: id + "_saved",
1285
- style: checkWorkStyle,
1286
- tabIndex: +checkWorkTabIndex,
1287
- children: [
1288
- /* @__PURE__ */ jsxRuntimeExports.jsx(FontAwesomeIcon, { icon: faCloud }),
1289
- "  Response Saved"
1290
- ]
1291
- }
1292
- );
1293
- }
1294
- }
1295
- if (SVs.numAttemptsLeft < 0) {
1296
- checkworkComponent = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
1297
- checkworkComponent,
1298
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "(no attempts remaining)" })
1299
- ] });
1300
- } else if (SVs.numAttemptsLeft == 1) {
1301
- checkworkComponent = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
1302
- checkworkComponent,
1303
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "(1 attempt remaining)" })
1304
- ] });
1305
- } else if (Number.isFinite(SVs.numAttemptsLeft)) {
1306
- checkworkComponent = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
1307
- checkworkComponent,
1308
- /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
1309
- "(",
1310
- SVs.numAttemptsLeft,
1311
- " attempts remaining)"
1312
- ] })
1313
- ] });
1314
- }
1315
- return checkworkComponent;
1316
- }
1317
- export {
1318
- AnswerResponseMenu as A,
1319
- createCheckworkComponent as c
1320
- };