UNPKG

@gdquest/gd-school-mdx-components

Version:

Components specially made to work with GDSchool MDX lesson files.

1,590 lines (1,561 loc) 49 kB
// src/components/Callout.tsx import { useState, useEffect } from "react"; import PropTypes from "prop-types"; // ../../node_modules/.pnpm/clsx@2.0.0/node_modules/clsx/dist/clsx.mjs function r(e) { var t, f, n = ""; if ("string" == typeof e || "number" == typeof e) n += e; else if ("object" == typeof e) if (Array.isArray(e)) for (t = 0; t < e.length; t++) e[t] && (f = r(e[t])) && (n && (n += " "), n += f); else for (t in e) e[t] && (n && (n += " "), n += t); return n; } function clsx() { for (var e, t, f = 0, n = ""; f < arguments.length; ) (e = arguments[f++]) && (t = r(e)) && (n && (n += " "), n += t); return n; } // src/components/Callout.tsx import { css } from "@emotion/react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { jsx, jsxs } from "@emotion/react/jsx-runtime"; function Callout({ type, hidden, title, description }) { const [state, setState] = useState({ isReady: false }); useEffect(() => { const localState = { ...state }; localState.isReady = true; setState(localState); }, []); return /* @__PURE__ */ jsxs( "div", { className: clsx([ "gd-school-mdx-component-callout", { "gd-school-mdx-component-callout--note": type === "note", "gd-school-mdx-component-callout--info": type === "info", "gd-school-mdx-component-callout--error": type === "error", "gd-school-mdx-component-callout--question": type === "question", "gd-school-mdx-component-callout--see-also": type === "see-also" } ]), css: css` & { display: grid; grid-template-areas: "icon title" "icon description"; grid-template-columns: 50px minmax(0, 1fr); margin: var(--size-8) 0; padding: var(--size-4); border-radius: var(--radius-lg); background: linear-gradient( 0.123turn, var(--callout-background-color-start), var(--callout-background-color-end) ); gap: var(--size-4); color: var(--callout-content-color); box-shadow: 0px 5px 10px rgba(0, 0, 0, 0.05); } &[hidden] { display: none; } `, hidden: hidden === true, children: [ /* @__PURE__ */ jsx( "div", { css: css` & { grid-area: icon; display: flex; align-items: start; justify-content: center; color: var(--callout-background-color); } `, // Hack: "isReady" fixes some weird issue // https://github.com/FortAwesome/Font-Awesome/issues/19348 children: state.isReady && (type === "info" ? /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: ["fas", "lightbulb"], size: "2x" }) : type === "question" ? /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: ["fas", "question"], size: "2x" }) : type === "error" ? /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: ["fas", "bug"], size: "2x" }) : type === "see-also" ? /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: ["fas", "eye"], size: "2x" }) : /* @__PURE__ */ jsx(FontAwesomeIcon, { icon: ["fas", "note-sticky"], size: "2x" })) } ), /* @__PURE__ */ jsx( "p", { css: css` && { grid-area: title; display: flex; align-items: center; justify-content: start; font-weight: bold; font-size: var(--size-4); margin: 0; } && code { display: inline-block; } `, children: /* @__PURE__ */ jsx("span", { children: title != null ? title : "NO TITLE GIVEN" }) } ), description !== "" && /* @__PURE__ */ jsx( "div", { css: css` & { grid-area: description; } & p:first-of-type { margin-top: 0; } `, children: description } ) ] } ); } Callout.propTypes = { children: PropTypes.oneOfType([ PropTypes.node, PropTypes.arrayOf(PropTypes.node) ]), type: PropTypes.string, hidden: PropTypes.bool, title: PropTypes.node, description: PropTypes.node }; // src/components/Description.tsx import PropTypes2 from "prop-types"; import { Fragment, jsx as jsx2 } from "@emotion/react/jsx-runtime"; function Description({ children }) { return /* @__PURE__ */ jsx2(Fragment, { children }); } Description.propTypes = { children: PropTypes2.oneOfType([ PropTypes2.node, PropTypes2.arrayOf(PropTypes2.node) ]) }; // src/components/Explanation.tsx import PropTypes3 from "prop-types"; import { Fragment as Fragment2, jsx as jsx3 } from "@emotion/react/jsx-runtime"; function Explanation({ children }) { return /* @__PURE__ */ jsx3(Fragment2, { children }); } Explanation.propTypes = { children: PropTypes3.oneOfType([ PropTypes3.node, PropTypes3.arrayOf(PropTypes3.node) ]) }; // src/components/GdExercise.tsx import PropTypes4 from "prop-types"; import { Fragment as Fragment3, jsx as jsx4 } from "@emotion/react/jsx-runtime"; function GdExercise({ children }) { return /* @__PURE__ */ jsx4(Fragment3, { children }); } GdExercise.propTypes = { children: PropTypes4.oneOfType([ PropTypes4.node, PropTypes4.arrayOf(PropTypes4.node) ]) }; // src/components/GdLearnToCode.tsx import PropTypes5 from "prop-types"; import { css as css2 } from "@emotion/react"; import { Fragment as Fragment4, jsx as jsx5, jsxs as jsxs2 } from "@emotion/react/jsx-runtime"; function GdLearnToCode({ children, scene, type, title, description, goal, hints }) { return /* @__PURE__ */ jsxs2( "section", { css: css2` background-color: yellow; padding: 1em; `, children: [ /* @__PURE__ */ jsx5("p", { children: title }), /* @__PURE__ */ jsx5("div", { children: description }), goal != null && /* @__PURE__ */ jsx5("div", { children: goal }), /* @__PURE__ */ jsx5("div", { children }), /* @__PURE__ */ jsxs2("div", { children: [ "TODO: show the gdExercise here with the scene ", scene, " and the type", " ", type ] }), hints != null && /* @__PURE__ */ jsx5("div", { children: hints.map((hint) => { return /* @__PURE__ */ jsx5(Fragment4, { children: /* @__PURE__ */ jsx5("div", { children: hint }) }); }) }) ] } ); } GdLearnToCode.propTypes = { children: PropTypes5.node, scene: PropTypes5.string.isRequired, type: PropTypes5.string, // TODO: limit the types of types that can be set instead of "string", title: PropTypes5.node.isRequired, description: PropTypes5.node.isRequired, goal: PropTypes5.node, hints: PropTypes5.arrayOf(PropTypes5.node) }; // src/components/GdSnippet.tsx import { useState as useState2, useEffect as useEffect2 } from "react"; import PropTypes6 from "prop-types"; import { css as css3 } from "@emotion/react"; // ../gd-exercise-wrapper/dist/gdexercise-wrapper.es.js import ir, { useState as or, useEffect as Oe, useRef as Te } from "react"; var ee = { exports: {} }; var G = {}; var Pe; function ur() { return Pe || (Pe = 1, function() { var m = ir, y = Symbol.for("react.element"), g = Symbol.for("react.portal"), d = Symbol.for("react.fragment"), x = Symbol.for("react.strict_mode"), c = Symbol.for("react.profiler"), b = Symbol.for("react.provider"), w = Symbol.for("react.context"), R = Symbol.for("react.forward_ref"), p = Symbol.for("react.suspense"), u = Symbol.for("react.suspense_list"), v = Symbol.for("react.memo"), P = Symbol.for("react.lazy"), A = Symbol.for("react.offscreen"), I = Symbol.iterator, T = "@@iterator"; function S(e) { if (e === null || typeof e != "object") return null; var r2 = I && e[I] || e[T]; return typeof r2 == "function" ? r2 : null; } var j = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function h(e) { { for (var r2 = arguments.length, n = new Array(r2 > 1 ? r2 - 1 : 0), t = 1; t < r2; t++) n[t - 1] = arguments[t]; Ce("error", e, n); } } function Ce(e, r2, n) { { var t = j.ReactDebugCurrentFrame, o = t.getStackAddendum(); o !== "" && (r2 += "%s", n = n.concat([o])); var s = n.map(function(i) { return String(i); }); s.unshift("Warning: " + r2), Function.prototype.apply.call(console[e], console, s); } } var Se = false, je = false, De = false, ke = false, Fe = false, re; re = Symbol.for("react.module.reference"); function Ae(e) { return !!(typeof e == "string" || typeof e == "function" || e === d || e === c || Fe || e === x || e === p || e === u || ke || e === A || Se || je || De || typeof e == "object" && e !== null && (e.$$typeof === P || e.$$typeof === v || e.$$typeof === b || e.$$typeof === w || e.$$typeof === R || // This needs to include all possible module reference object // types supported by any Flight configuration anywhere since // we don't know which Flight build this will end up being used // with. e.$$typeof === re || e.getModuleId !== void 0)); } function Ie(e, r2, n) { var t = e.displayName; if (t) return t; var o = r2.displayName || r2.name || ""; return o !== "" ? n + "(" + o + ")" : n; } function ne(e) { return e.displayName || "Context"; } function O(e) { if (e == null) return null; if (typeof e.tag == "number" && h("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function") return e.displayName || e.name || null; if (typeof e == "string") return e; switch (e) { case d: return "Fragment"; case g: return "Portal"; case c: return "Profiler"; case x: return "StrictMode"; case p: return "Suspense"; case u: return "SuspenseList"; } if (typeof e == "object") switch (e.$$typeof) { case w: var r2 = e; return ne(r2) + ".Consumer"; case b: var n = e; return ne(n._context) + ".Provider"; case R: return Ie(e, e.render, "ForwardRef"); case v: var t = e.displayName || null; return t !== null ? t : O(e.type) || "Memo"; case P: { var o = e, s = o._payload, i = o._init; try { return O(i(s)); } catch { return null; } } } return null; } var D = Object.assign, N = 0, te, ae, ie, oe, se, ue, ce; function le() { } le.__reactDisabledLog = true; function Ne() { { if (N === 0) { te = console.log, ae = console.info, ie = console.warn, oe = console.error, se = console.group, ue = console.groupCollapsed, ce = console.groupEnd; var e = { configurable: true, enumerable: true, value: le, writable: true }; Object.defineProperties(console, { info: e, log: e, warn: e, error: e, group: e, groupCollapsed: e, groupEnd: e }); } N++; } } function We() { { if (N--, N === 0) { var e = { configurable: true, enumerable: true, writable: true }; Object.defineProperties(console, { log: D({}, e, { value: te }), info: D({}, e, { value: ae }), warn: D({}, e, { value: ie }), error: D({}, e, { value: oe }), group: D({}, e, { value: se }), groupCollapsed: D({}, e, { value: ue }), groupEnd: D({}, e, { value: ce }) }); } N < 0 && h("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var J = j.ReactCurrentDispatcher, q; function $(e, r2, n) { { if (q === void 0) try { throw Error(); } catch (o) { var t = o.stack.trim().match(/\n( *(at )?)/); q = t && t[1] || ""; } return ` ` + q + e; } } var z = false, V; { var $e = typeof WeakMap == "function" ? WeakMap : Map; V = new $e(); } function fe(e, r2) { if (!e || z) return ""; { var n = V.get(e); if (n !== void 0) return n; } var t; z = true; var o = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var s; s = J.current, J.current = null, Ne(); try { if (r2) { var i = function() { throw Error(); }; if (Object.defineProperty(i.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(i, []); } catch (C) { t = C; } Reflect.construct(e, [], i); } else { try { i.call(); } catch (C) { t = C; } e.call(i.prototype); } } else { try { throw Error(); } catch (C) { t = C; } e(); } } catch (C) { if (C && t && typeof C.stack == "string") { for (var a = C.stack.split(` `), E = t.stack.split(` `), l = a.length - 1, f = E.length - 1; l >= 1 && f >= 0 && a[l] !== E[f]; ) f--; for (; l >= 1 && f >= 0; l--, f--) if (a[l] !== E[f]) { if (l !== 1 || f !== 1) do if (l--, f--, f < 0 || a[l] !== E[f]) { var _ = ` ` + a[l].replace(" at new ", " at "); return e.displayName && _.includes("<anonymous>") && (_ = _.replace("<anonymous>", e.displayName)), typeof e == "function" && V.set(e, _), _; } while (l >= 1 && f >= 0); break; } } } finally { z = false, J.current = s, We(), Error.prepareStackTrace = o; } var F = e ? e.displayName || e.name : "", we = F ? $(F) : ""; return typeof e == "function" && V.set(e, we), we; } function Ve(e, r2, n) { return fe(e, false); } function Ye(e) { var r2 = e.prototype; return !!(r2 && r2.isReactComponent); } function Y(e, r2, n) { if (e == null) return ""; if (typeof e == "function") return fe(e, Ye(e)); if (typeof e == "string") return $(e); switch (e) { case p: return $("Suspense"); case u: return $("SuspenseList"); } if (typeof e == "object") switch (e.$$typeof) { case R: return Ve(e.render); case v: return Y(e.type, r2, n); case P: { var t = e, o = t._payload, s = t._init; try { return Y(s(o), r2, n); } catch { } } } return ""; } var L = Object.prototype.hasOwnProperty, de = {}, ve = j.ReactDebugCurrentFrame; function U(e) { if (e) { var r2 = e._owner, n = Y(e.type, e._source, r2 ? r2.type : null); ve.setExtraStackFrame(n); } else ve.setExtraStackFrame(null); } function Le(e, r2, n, t, o) { { var s = Function.call.bind(L); for (var i in e) if (s(e, i)) { var a = void 0; try { if (typeof e[i] != "function") { var E = Error((t || "React class") + ": " + n + " type `" + i + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[i] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw E.name = "Invariant Violation", E; } a = e[i](r2, i, t, n, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (l) { a = l; } a && !(a instanceof Error) && (U(o), h("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", t || "React class", n, i, typeof a), U(null)), a instanceof Error && !(a.message in de) && (de[a.message] = true, U(o), h("Failed %s type: %s", n, a.message), U(null)); } } } var Ue = Array.isArray; function H(e) { return Ue(e); } function Me(e) { { var r2 = typeof Symbol == "function" && Symbol.toStringTag, n = r2 && e[Symbol.toStringTag] || e.constructor.name || "Object"; return n; } } function Ge(e) { try { return pe(e), false; } catch { return true; } } function pe(e) { return "" + e; } function he(e) { if (Ge(e)) return h("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Me(e)), pe(e); } var W = j.ReactCurrentOwner, Be = { key: true, ref: true, __self: true, __source: true }, me, ge, K; K = {}; function Je(e) { if (L.call(e, "ref")) { var r2 = Object.getOwnPropertyDescriptor(e, "ref").get; if (r2 && r2.isReactWarning) return false; } return e.ref !== void 0; } function qe(e) { if (L.call(e, "key")) { var r2 = Object.getOwnPropertyDescriptor(e, "key").get; if (r2 && r2.isReactWarning) return false; } return e.key !== void 0; } function ze(e, r2) { if (typeof e.ref == "string" && W.current && r2 && W.current.stateNode !== r2) { var n = O(W.current.type); K[n] || (h('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', O(W.current.type), e.ref), K[n] = true); } } function He(e, r2) { { var n = function() { me || (me = true, h("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r2)); }; n.isReactWarning = true, Object.defineProperty(e, "key", { get: n, configurable: true }); } } function Ke(e, r2) { { var n = function() { ge || (ge = true, h("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r2)); }; n.isReactWarning = true, Object.defineProperty(e, "ref", { get: n, configurable: true }); } } var Xe = function(e, r2, n, t, o, s, i) { var a = { // This tag allows us to uniquely identify this as a React Element $$typeof: y, // Built-in properties that belong on the element type: e, key: r2, ref: n, props: i, // Record the component responsible for creating this element. _owner: s }; return a._store = {}, Object.defineProperty(a._store, "validated", { configurable: false, enumerable: false, writable: true, value: false }), Object.defineProperty(a, "_self", { configurable: false, enumerable: false, writable: false, value: t }), Object.defineProperty(a, "_source", { configurable: false, enumerable: false, writable: false, value: o }), Object.freeze && (Object.freeze(a.props), Object.freeze(a)), a; }; function Ze(e, r2, n, t, o) { { var s, i = {}, a = null, E = null; n !== void 0 && (he(n), a = "" + n), qe(r2) && (he(r2.key), a = "" + r2.key), Je(r2) && (E = r2.ref, ze(r2, o)); for (s in r2) L.call(r2, s) && !Be.hasOwnProperty(s) && (i[s] = r2[s]); if (e && e.defaultProps) { var l = e.defaultProps; for (s in l) i[s] === void 0 && (i[s] = l[s]); } if (a || E) { var f = typeof e == "function" ? e.displayName || e.name || "Unknown" : e; a && He(i, f), E && Ke(i, f); } return Xe(e, a, E, o, t, W.current, i); } } var X = j.ReactCurrentOwner, be = j.ReactDebugCurrentFrame; function k(e) { if (e) { var r2 = e._owner, n = Y(e.type, e._source, r2 ? r2.type : null); be.setExtraStackFrame(n); } else be.setExtraStackFrame(null); } var Z; Z = false; function Q(e) { return typeof e == "object" && e !== null && e.$$typeof === y; } function Ee() { { if (X.current) { var e = O(X.current.type); if (e) return ` Check the render method of \`` + e + "`."; } return ""; } } function Qe(e) { { if (e !== void 0) { var r2 = e.fileName.replace(/^.*[\\\/]/, ""), n = e.lineNumber; return ` Check your code at ` + r2 + ":" + n + "."; } return ""; } } var ye = {}; function er(e) { { var r2 = Ee(); if (!r2) { var n = typeof e == "string" ? e : e.displayName || e.name; n && (r2 = ` Check the top-level render call using <` + n + ">."); } return r2; } } function Re(e, r2) { { if (!e._store || e._store.validated || e.key != null) return; e._store.validated = true; var n = er(r2); if (ye[n]) return; ye[n] = true; var t = ""; e && e._owner && e._owner !== X.current && (t = " It was passed a child from " + O(e._owner.type) + "."), k(e), h('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', n, t), k(null); } } function _e(e, r2) { { if (typeof e != "object") return; if (H(e)) for (var n = 0; n < e.length; n++) { var t = e[n]; Q(t) && Re(t, r2); } else if (Q(e)) e._store && (e._store.validated = true); else if (e) { var o = S(e); if (typeof o == "function" && o !== e.entries) for (var s = o.call(e), i; !(i = s.next()).done; ) Q(i.value) && Re(i.value, r2); } } } function rr(e) { { var r2 = e.type; if (r2 == null || typeof r2 == "string") return; var n; if (typeof r2 == "function") n = r2.propTypes; else if (typeof r2 == "object" && (r2.$$typeof === R || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. r2.$$typeof === v)) n = r2.propTypes; else return; if (n) { var t = O(r2); Le(n, e.props, "prop", t, e); } else if (r2.PropTypes !== void 0 && !Z) { Z = true; var o = O(r2); h("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", o || "Unknown"); } typeof r2.getDefaultProps == "function" && !r2.getDefaultProps.isReactClassApproved && h("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function nr(e) { { for (var r2 = Object.keys(e.props), n = 0; n < r2.length; n++) { var t = r2[n]; if (t !== "children" && t !== "key") { k(e), h("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", t), k(null); break; } } e.ref !== null && (k(e), h("Invalid attribute `ref` supplied to `React.Fragment`."), k(null)); } } function tr(e, r2, n, t, o, s) { { var i = Ae(e); if (!i) { var a = ""; (e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (a += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports."); var E = Qe(o); E ? a += E : a += Ee(); var l; e === null ? l = "null" : H(e) ? l = "array" : e !== void 0 && e.$$typeof === y ? (l = "<" + (O(e.type) || "Unknown") + " />", a = " Did you accidentally export a JSX literal instead of a component?") : l = typeof e, h("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", l, a); } var f = Ze(e, r2, n, o, s); if (f == null) return f; if (i) { var _ = r2.children; if (_ !== void 0) if (t) if (H(_)) { for (var F = 0; F < _.length; F++) _e(_[F], e); Object.freeze && Object.freeze(_); } else h("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead."); else _e(_, e); } return e === d ? nr(f) : rr(f), f; } } var ar = tr; G.Fragment = d, G.jsxDEV = ar; }()), G; } false ? ee.exports = sr() : ee.exports = ur(); var B = ee.exports; globalThis && globalThis.__awaiter; globalThis && globalThis.__awaiter; function cr(m, { threshold: y = 0, root: g = null, rootMargin: d = "0%", freezeOnceVisible: x = false }) { const [c, b] = or(), w = (c == null ? void 0 : c.isIntersecting) && x, R = ([p]) => { b(p); }; return Oe(() => { const p = m == null ? void 0 : m.current; if (!!!window.IntersectionObserver || w || !p) return; const v = { threshold: y, root: g, rootMargin: d }, P = new IntersectionObserver(R, v); return P.observe(p), () => P.disconnect(); }, [m == null ? void 0 : m.current, JSON.stringify(y), g, d, w]), c; } var lr = "/loader.html"; function vr(m) { const { loader: y = new URL(lr, window.location.origin).href, dataPath: g, mainScene: d, openFiles: x = [], height: c, hideCode: b = false, hideConsole: w = false, hidePlayer: R = false, hideTest: p = false, snippet: u = "" } = m, v = Te(null), P = Te(null), A = cr(P, {}), I = (A == null ? void 0 : A.isIntersecting) === true, T = new URL(y); T.searchParams.append("dataPath", g), T.searchParams.append("mainScene", d); for (const S of x) { const j = () => S.focus === true ? "focus" : "nofocus"; T.searchParams.append( "open", [S.path, j(), S.override].filter((h) => h != null).join(":") ); } return b && T.searchParams.append("hide", "code"), w && T.searchParams.append("hide", "console"), R && T.searchParams.append("hide", "player"), p && T.searchParams.append("hide", "test"), u.length > 0 && T.searchParams.append("snippet", u), Oe(() => { var S; v.current != null && ((S = v.current.contentWindow) == null || S.postMessage({ from: "gd-exercise", type: "low-processor-usage-mode", value: !I })); }, [I, v.current]), /* @__PURE__ */ B.jsxDEV(B.Fragment, { children: /* @__PURE__ */ B.jsxDEV("div", { className: "gdexercise-wrapper", ref: P, children: /* @__PURE__ */ B.jsxDEV( "iframe", { allow: "fullscreen", src: T.href, style: { height: c }, ref: v }, void 0, false, { fileName: "/home/adamscott/dev/builds/gd-web/packages/gd-exercise-wrapper/src/components/GdExerciseWrapper.tsx", lineNumber: 97, columnNumber: 9 }, this ) }, void 0, false, { fileName: "/home/adamscott/dev/builds/gd-web/packages/gd-exercise-wrapper/src/components/GdExerciseWrapper.tsx", lineNumber: 96, columnNumber: 7 }, this) }, void 0, false, { fileName: "/home/adamscott/dev/builds/gd-web/packages/gd-exercise-wrapper/src/components/GdExerciseWrapper.tsx", lineNumber: 95, columnNumber: 5 }, this); } // src/components/GdSnippet.tsx import { jsx as jsx6, jsxs as jsxs3 } from "@emotion/react/jsx-runtime"; function GdSnippet({ title, code, hidePlayer = true }) { const [state, setState] = useState2({ hasSharedArrayBufferSupport: false }); useEffect2(() => { const localState = { ...state }; localState.hasSharedArrayBufferSupport = typeof window.SharedArrayBuffer !== "undefined"; setState(localState); }, []); return /* @__PURE__ */ jsxs3( "div", { css: css3` & { margin: var(--size-8) 0; } `, children: [ title != null && /* @__PURE__ */ jsx6("h3", { children: title }), state.hasSharedArrayBufferSupport ? /* @__PURE__ */ jsx6( vr, { loader: (() => { const url = new URL( "/gdexercise/loader.html", window.location.href ); return url.href; })(), dataPath: (() => { const url = new URL( "/gdexercise/projects/snippet.zip", window.location.href ); return url.href; })(), mainScene: "main.tscn", height: "500px", hidePlayer: hidePlayer ?? false, snippet: code } ) : /* @__PURE__ */ jsx6("pre", { children: /* @__PURE__ */ jsx6("code", { children: code }) }) ] } ); } GdSnippet.propTypes = { title: PropTypes6.string, code: PropTypes6.string.isRequired, hidePlayer: PropTypes6.bool }; // src/components/Glossary.tsx import PropTypes7 from "prop-types"; import { Fragment as Fragment5, jsx as jsx7 } from "@emotion/react/jsx-runtime"; function Glossary({ children }) { return /* @__PURE__ */ jsx7(Fragment5, { children }); } Glossary.propTypes = { children: PropTypes7.oneOfType([ PropTypes7.node, PropTypes7.arrayOf(PropTypes7.node) ]) }; // src/components/Goal.tsx import PropTypes8 from "prop-types"; import { Fragment as Fragment6, jsx as jsx8 } from "@emotion/react/jsx-runtime"; function Goal({ children }) { return /* @__PURE__ */ jsx8(Fragment6, { children }); } Goal.propTypes = { children: PropTypes8.oneOfType([ PropTypes8.node, PropTypes8.arrayOf(PropTypes8.node) ]) }; // src/components/Hints.tsx import PropTypes9 from "prop-types"; import { Fragment as Fragment7, jsx as jsx9 } from "@emotion/react/jsx-runtime"; function Hints({ children }) { return /* @__PURE__ */ jsx9(Fragment7, { children }); } Hints.propTypes = { children: PropTypes9.oneOfType([ PropTypes9.node, PropTypes9.arrayOf(PropTypes9.node) ]) }; // src/components/Item.tsx import PropTypes10 from "prop-types"; import { Fragment as Fragment8, jsx as jsx10 } from "@emotion/react/jsx-runtime"; function Item({ children }) { return /* @__PURE__ */ jsx10(Fragment8, { children }); } Item.propTypes = { children: PropTypes10.oneOfType([ PropTypes10.node, PropTypes10.arrayOf(PropTypes10.node) ]) }; // src/components/Option.tsx import PropTypes11 from "prop-types"; import { Fragment as Fragment9, jsx as jsx11 } from "@emotion/react/jsx-runtime"; function Option({ children, correct = false }) { return /* @__PURE__ */ jsx11(Fragment9, { children }); } Option.propTypes = { children: PropTypes11.oneOfType([ PropTypes11.node, PropTypes11.arrayOf(PropTypes11.node) ]), correct: PropTypes11.bool }; // src/components/Question.tsx import { useRef as useRef2, useState as useState4, useEffect as useEffect4 } from "react"; import PropTypes13 from "prop-types"; import { css as css4 } from "@emotion/react"; // ../../node_modules/.pnpm/@react-hooks-library+core@0.5.1_react@18.2.0/node_modules/@react-hooks-library/core/index.esm.js import { useEffect as useEffect3, useState as useState3, useRef, useCallback, useLayoutEffect } from "react"; var isClient = typeof window !== "undefined"; var isRef = (obj) => obj !== null && typeof obj === "object" && Object.prototype.hasOwnProperty.call(obj, "current"); var isString = (val) => typeof val === "string"; var noop = () => { }; function unRef(target) { const element = isRef(target) ? target.current : target; return element; } var _window = isClient ? window : void 0; var _document = isClient ? window.document : void 0; var _navigator = isClient ? window.navigator : void 0; function useEventListener(...args) { let target = _window; let event; let listener; let options; isString(args[0]) ? [event, listener, options] = args : [target, event, listener, options] = args; const savedListener = useRef(listener); const cleanup = useRef(noop); useEffect3(() => { savedListener.current = listener; }, [listener]); useEffect3(() => { const el = unRef(target); if (!isClient || !el) return; el.addEventListener(event, savedListener.current, options); cleanup.current = () => { el.removeEventListener(event, savedListener.current, options); }; return cleanup.current; }, [event, target, options]); return cleanup.current; } // src/components/Button.tsx import PropTypes12 from "prop-types"; import { Fragment as Fragment10, jsx as jsx12 } from "@emotion/react/jsx-runtime"; function Button({ children, onClick, disabled }) { return /* @__PURE__ */ jsx12(Fragment10, { children: /* @__PURE__ */ jsx12( "button", { className: "gd-school-mdx-component-button", onClick: (event) => onClick?.(event), disabled: disabled ?? false, children } ) }); } Button.propTypes = { children: PropTypes12.node, onClick: PropTypes12.func, disabled: PropTypes12.bool }; // src/components/Question.tsx import { Fragment as Fragment11, jsx as jsx13, jsxs as jsxs4 } from "@emotion/react/jsx-runtime"; var sequentialId = 0; function getSequentialId() { const returnValue = sequentialId; sequentialId += 1; return returnValue; } function Question({ hidden, randomize, multipleChoice, skip, onSubmit, title, explanation, options, onRightAnswer, onWrongAnswer }) { randomize = randomize ?? false; skip = skip ?? false; const rootRef = useRef2(null); const optionsName = `gd-school-mdx-component-question-options-${getSequentialId().toString()}`; const [state, setState] = useState4({ title: title ?? "NO TITLE GIVEN", explanation: explanation ?? "NO EXPLANATION GIVEN", options: (options ?? []).map((option, index) => { return { index: option.index ?? index, label: option.label, correct: option.correct ?? false }; }), correctAnswer: null, submitted: false, skip: skip ?? false, isReady: false }); useEventListener(rootRef, "questionupdate", () => { }); useEffect4(() => { if (rootRef.current == null) { return; } const localState = { ...state }; if (randomize === true) { localState.options = localState.options.map((option) => { return { option, sort: Math.random() }; }).sort((a, b) => a.sort - b.sort).map(({ option }) => option); } localState.isReady = true; setState(localState); }, []); const onQuestionChange = (event) => { const localState = { ...state }; if (localState.submitted) { return; } const correctOption = localState.options?.find( (option) => option?.correct === true ); if (correctOption == null) { return; } if (multipleChoice === true) { validateForm(localState); } else { localState.correctAnswer = // @ts-expect-error value doesn't exist on event.target event.target.value === correctOption.index.toString(); } setState(localState); }; const validateForm = (state2) => { let hasError = false; const htmlOptions = document.getElementsByName( optionsName ); for (const htmlOption of Array.from(htmlOptions)) { for (const option of state2.options) { if (option.index?.toString() !== htmlOption.value) { continue; } if (htmlOption.checked && option.correct === true) { hasError = true; break; } } if (hasError) { break; } } state2.correctAnswer = !hasError; }; const onSubmitButtonClick = () => { if (rootRef.current == null) { return; } setState({ ...state, submitted: true }); onSubmit?.(state.correctAnswer); if (state.correctAnswer === true) { onRightAnswer?.(); } else if (state.correctAnswer === false) { onWrongAnswer?.(); } }; return /* @__PURE__ */ jsx13(Fragment11, { children: /* @__PURE__ */ jsxs4( "div", { className: clsx("gd-school-mdx-component-question"), css: css4` & { border: 1px solid var(--border); border-radius: var(--radius); margin: var(--size-16) 0; padding: var(--size-4); } &[hidden] { display: none; } `, ref: rootRef, hidden: hidden ?? false, children: [ /* @__PURE__ */ jsx13( "p", { css: css4` && { font-size: var(--font-size-2); line-height: var(--font-lineheight-4); margin-top: 0; } `, children: /* @__PURE__ */ jsx13("span", { children: "Question" }) } ), /* @__PURE__ */ jsx13("p", { css: css4``, // Title children: state.title }), /* @__PURE__ */ jsxs4( "fieldset", { css: css4` display: grid; grid-template-areas: "entries" "submit"; grid-template-columns: auto; `, onChangeCapture: onQuestionChange, children: [ /* @__PURE__ */ jsx13( "div", { css: css4` grid-area: entries; `, children: state.isReady && state.options.map((option) => { if (option == null) { return /* @__PURE__ */ jsx13(Fragment11, {}); } return /* @__PURE__ */ jsxs4( "label", { css: css4` display: grid; grid-template-areas: "input content"; grid-template-columns: 50px 1fr; `, children: [ /* @__PURE__ */ jsx13( "div", { css: css4` grid-area: "input"; `, children: /* @__PURE__ */ jsx13( "input", { type: multipleChoice === true ? "checkbox" : "radio", name: optionsName, value: option.index, disabled: state.submitted || state.skip } ) } ), /* @__PURE__ */ jsx13( "span", { css: css4` grid-area: content; `, children: /* @__PURE__ */ jsx13("span", { children: option.label }) } ) ] }, option.index ); }) } ), /* @__PURE__ */ jsx13( "div", { css: css4` grid-area: submit; display: flex; align-items: center; justify-content: center; margin-top: var(--size-4); `, children: !state.submitted && !state.skip && state.isReady && /* @__PURE__ */ jsx13( Button, { onClick: onSubmitButtonClick, disabled: state.correctAnswer === null, children: /* @__PURE__ */ jsx13("span", { children: "Submit" }) } ) } ) ] } ), (state.submitted || state.skip) && /* @__PURE__ */ jsxs4( "div", { className: clsx([ "gd-school-mdx-component-question-answer", { "gd-school-mdx-component-question-answer--correct": state.correctAnswer === true, "gd-school-mdx-component-question-answer--incorrect": state.correctAnswer === false } ]), css: css4` border-radius: var(--radius-lg); padding: var(--size-4); margin-top: var(--size-2); background: linear-gradient( 0.123turn, var(--question-answer-background-color-start), var(--question-answer-background-color-end) ); `, children: [ !state.skip && /* @__PURE__ */ jsx13( "p", { css: css4` && { margin: 0; font-weight: bold; } `, children: state.correctAnswer === true ? "Correct" : "Incorrect" } ), /* @__PURE__ */ jsx13("p", { children: state.explanation }) ] } ) ] } ) }); } Question.propTypes = { children: PropTypes13.node, randomize: PropTypes13.bool, multipleChoice: PropTypes13.bool, skip: PropTypes13.bool, hidden: PropTypes13.bool, title: PropTypes13.node, options: PropTypes13.arrayOf( PropTypes13.shape({ index: PropTypes13.number, label: PropTypes13.node.isRequired, correct: PropTypes13.bool }) ), explanation: PropTypes13.node, onSubmit: PropTypes13.func, onRightAnswer: PropTypes13.func, onWrongAnswer: PropTypes13.func }; // src/components/Small.tsx import PropTypes14 from "prop-types"; import { jsx as jsx14 } from "@emotion/react/jsx-runtime"; function Small({ children }) { return /* @__PURE__ */ jsx14("small", { children }); } Small.propTypes = { children: PropTypes14.oneOfType([ PropTypes14.node, PropTypes14.arrayOf(PropTypes14.node) ]) }; // src/components/Title.tsx import PropTypes15 from "prop-types"; import { Fragment as Fragment12, jsx as jsx15 } from "@emotion/react/jsx-runtime"; function Title({ children }) { return /* @__PURE__ */ jsx15(Fragment12, { children }); } Title.propTypes = { children: PropTypes15.oneOfType([ PropTypes15.node, PropTypes15.arrayOf(PropTypes15.node) ]) }; // src/components/WithPoints.tsx import { Children, isValidElement, cloneElement, useState as useState5, useEffect as useEffect5, useRef as useRef3 } from "react"; import PropTypes16 from "prop-types"; import { Fragment as Fragment13, jsx as jsx16 } from "@emotion/react/jsx-runtime"; var DEFAULT_RIGHT_ANSWER_POINTS = 1; function WithPoints({ children, id, points, hidden, usePoints }) { if (id == null || id.length === 0) { throw new Error("WithPoints id is null or empty"); } if (id.match(/^\s$/g) != null) { throw new Error("WithPoints id has whitespace in it"); } const rightAnswerPoints = points ?? DEFAULT_RIGHT_ANSWER_POINTS; const rootRef = useRef3(null); const [state, setState] = useState5({ submitted: false }); let registerAnswer = null; if (usePoints != null) { ({ registerAnswer } = usePoints()); } useEffect5(() => { if (rootRef.current == null) { return; } let foundPrevious = false; let previousSibling = rootRef.current.previousElementSibling; while (previousSibling != null) { if (previousSibling instanceof HTMLElement && previousSibling.dataset.exercise != null) { foundPrevious = true; break; } previousSibling = previousSibling.previousElementSibling; } if (!foundPrevious) { let nextSibling = rootRef.current.nextElementSibling; while (nextSibling != null) { if (nextSibling instanceof HTMLElement) { nextSibling.hidden = true; } nextSibling = nextSibling.nextElementSibling; } } }, []); useEffect5(() => { if (rootRef.current == null) { return; } rootRef.current.dataset.exercise = ""; if (state.submitted) { rootRef.current.dataset.exerciseSubmitted = ""; } else { delete rootRef.current.dataset.exerciseSubmitted; } }, [state, rootRef.current]); const onSubmit = () => { const localState = { ...state }; localState.submitted = true; setState(localState); if (rootRef.current == null) { return; } let nextSibling = rootRef.current.nextElementSibling; while (nextSibling != null) { if (nextSibling instanceof HTMLElement) { nextSibling.hidden = false; if (nextSibling.dataset.exercise != null) { nextSibling.dispatchEvent(new CustomEvent("exerciseupdate")); break; } } nextSibling = nextSibling.nextElementSibling; } }; const onRightAnswer = () => { registerAnswer?.(id, rightAnswerPoints); }; const onWrongAnswer = () => { registerAnswer?.(id, 0); }; const childrenWithProps = Children.map(children, (child) => { if (isValidElement(child)) { return cloneElement(child, { onSubmit, onRightAnswer, onWrongAnswer }); } return child; }); return /* @__PURE__ */ jsx16("div", { ref: rootRef, "data-exercise-id": id, hidden: hidden ?? false, children: /* @__PURE__ */ jsx16(Fragment13, { children: childrenWithProps }) }); } WithPoints.propTypes = { children: PropTypes16.node.isRequired, id: PropTypes16.string.isRequired, points: PropTypes16.number, hidden: PropTypes16.bool, usePoints: PropTypes16.func }; export { Callout, Description, Explanation, GdExercise, GdLearnToCode, GdSnippet, Glossary, Goal, Hints, Item, Option, Question, Small, Title, WithPoints }; /** * @license React * react-jsx-dev-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ /** * @license React * react-jsx-dev-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ //# sourceMappingURL=index.mjs.map