UNPKG

superleap-code-editor

Version:

A flexible, reusable code editor component with multiple file handling modes

1,664 lines (1,662 loc) 2.27 MB
import "./index.css"; import * as O from "react"; import oe, { useState as ue, useRef as Ce, useCallback as me, useEffect as we, forwardRef as ee, createElement as ne, createContext as Ht, useId as El, useMemo as Je, Children as WA, isValidElement as iM, useImperativeHandle as Fd, useContext as at, cloneElement as FA, useLayoutEffect as aM, memo as J1, createRef as mi, Fragment as K1, Suspense as XA, Component as VA, PureComponent as wf } from "react"; import * as xf from "react-dom"; import GA from "react-dom"; import { IconCaretRightFilled as gv, IconX as Zi, IconDots as oM, IconArrowNarrowLeft as UA, IconArrowNarrowRight as qA, IconMinus as HA, IconCheck as ey, IconSearch as Sf, IconAlertCircle as Au, IconCircleCheck as Mf, IconEye as ty, IconEyeOff as sM, IconLock as JA, icons as Ml, IconChevronDown as Aa, IconChevronUp as lM, IconCalendar as Xd, IconCornerDownLeft as fM, IconCalendarDot as cM, IconCalendarUp as Cm, IconCalendarMinus as uM, IconChevronRight as Cf, IconLoader2 as KA, IconLayoutSidebarRightExpand as eE, IconBell as tE, IconCircle as dM, IconHelpSquareRounded as nE, IconInfoCircle as ul, IconPlaystationX as rE, IconLoader as hM, IconCircleDashed as iE, IconGraph as aE, IconDownload as oE, IconPhoneCall as sE, IconEyeEdit as lE, IconTransform as fE, IconUserCircle as cE, IconShare as uE, IconFileMinus as dE, IconTrash as pM, IconRegex as hE, IconUserBolt as pE, IconDatabaseMinus as mE, IconDatabaseShare as gE, IconCalendarPause as yE, IconFunction as bE, IconDatabaseSearch as OE, IconJson as vE, IconCalendarRepeat as wE, IconNumbers as xE, IconDatabaseEdit as SE, IconDatabasePlus as ME, IconRepeat as CE, IconClockExclamation as jE, IconArrowsSplit2 as kE, IconSwitch3 as LE, IconBrandMeta as TE, IconWebhook as NE, IconStackMiddle as IE, IconStackPop as PE, IconStackFront as DE, IconSquareRoundedPlus as QE, IconTable as AE, IconRelationOneToMany as EE, IconDatabase as ny, IconChecklist as $E, IconMoodConfuzed as RE, IconSubtask as zE, IconUserPentagon as _E, IconBox as ZE, IconPhoneOutgoing as YE, IconPhoneIncoming as BE, IconForms as WE, IconEdit as mM, IconMessage as FE, IconBrandWhatsapp as XE, IconListDetails as VE, IconActivity as GE, IconHeadset as UE, IconCode as ry, IconUser as gM, IconUsers as qE, IconShield as HE, IconCircleX as yM, IconStarFilled as JE, IconStar as KE, IconPhone as bM, IconNumber3Small as e9, IconNumber2Small as t9, IconList as OM, IconNumber1Small as n9, IconNumber123 as r9, IconMail as vM, IconLocation as i9, IconListCheck as a9, IconFileUpload as o9, IconExternalLink as s9, IconCoins as l9, IconClock as iy, IconCirclesRelation as f9, IconCheckbox as c9, IconCalendarClock as u9, IconAbc as d9, IconCancel as h9, IconChevronLeft as p9, IconFolderOpen as jm, IconHistory as m9, IconFlask as g9, IconKey as y9, IconLink as b9, IconTag as O9, IconFile as km, IconCurrency as v9, IconWorld as w9, IconHash as x9, IconLetterT as S9, IconSortAscending as yv, IconSortDescending as M9, IconRefresh as C9, IconFilePlus as j9, IconFolderPlus as k9, IconBook as L9, IconAlertTriangle as T9, IconSettings as N9, IconPlayerPlay as I9, IconRotate as P9 } from "@tabler/icons-react"; import D9 from "@monaco-editor/react"; import { Splitter as ta } from "antd"; function wM(t) { return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t; } var pc = { exports: {} }, Zs = {}; /** * @license React * react-jsx-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. */ var bv; function Q9() { if (bv) return Zs; bv = 1; var t = oe, e = Symbol.for("react.element"), n = Symbol.for("react.fragment"), r = Object.prototype.hasOwnProperty, i = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, a = { key: !0, ref: !0, __self: !0, __source: !0 }; function o(s, l, f) { var c, u = {}, h = null, p = null; f !== void 0 && (h = "" + f), l.key !== void 0 && (h = "" + l.key), l.ref !== void 0 && (p = l.ref); for (c in l) r.call(l, c) && !a.hasOwnProperty(c) && (u[c] = l[c]); if (s && s.defaultProps) for (c in l = s.defaultProps, l) u[c] === void 0 && (u[c] = l[c]); return { $$typeof: e, type: s, key: h, ref: p, props: u, _owner: i.current }; } return Zs.Fragment = n, Zs.jsx = o, Zs.jsxs = o, Zs; } var Ys = {}; /** * @license React * react-jsx-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. */ var Ov; function A9() { return Ov || (Ov = 1, process.env.NODE_ENV !== "production" && (function() { var t = oe, e = Symbol.for("react.element"), n = Symbol.for("react.portal"), r = Symbol.for("react.fragment"), i = Symbol.for("react.strict_mode"), a = Symbol.for("react.profiler"), o = Symbol.for("react.provider"), s = Symbol.for("react.context"), l = Symbol.for("react.forward_ref"), f = Symbol.for("react.suspense"), c = Symbol.for("react.suspense_list"), u = Symbol.for("react.memo"), h = Symbol.for("react.lazy"), p = Symbol.for("react.offscreen"), g = Symbol.iterator, m = "@@iterator"; function y(z) { if (z === null || typeof z != "object") return null; var ae = g && z[g] || z[m]; return typeof ae == "function" ? ae : null; } var b = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED; function v(z) { { for (var ae = arguments.length, he = new Array(ae > 1 ? ae - 1 : 0), Me = 1; Me < ae; Me++) he[Me - 1] = arguments[Me]; w("error", z, he); } } function w(z, ae, he) { { var Me = b.ReactDebugCurrentFrame, We = Me.getStackAddendum(); We !== "" && (ae += "%s", he = he.concat([We])); var tt = he.map(function(_e) { return String(_e); }); tt.unshift("Warning: " + ae), Function.prototype.apply.call(console[z], console, tt); } } var x = !1, M = !1, S = !1, C = !1, j = !1, N; N = Symbol.for("react.module.reference"); function L(z) { return !!(typeof z == "string" || typeof z == "function" || z === r || z === a || j || z === i || z === f || z === c || C || z === p || x || M || S || typeof z == "object" && z !== null && (z.$$typeof === h || z.$$typeof === u || z.$$typeof === o || z.$$typeof === s || z.$$typeof === l || // 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. z.$$typeof === N || z.getModuleId !== void 0)); } function D(z, ae, he) { var Me = z.displayName; if (Me) return Me; var We = ae.displayName || ae.name || ""; return We !== "" ? he + "(" + We + ")" : he; } function T(z) { return z.displayName || "Context"; } function _(z) { if (z == null) return null; if (typeof z.tag == "number" && v("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof z == "function") return z.displayName || z.name || null; if (typeof z == "string") return z; switch (z) { case r: return "Fragment"; case n: return "Portal"; case a: return "Profiler"; case i: return "StrictMode"; case f: return "Suspense"; case c: return "SuspenseList"; } if (typeof z == "object") switch (z.$$typeof) { case s: var ae = z; return T(ae) + ".Consumer"; case o: var he = z; return T(he._context) + ".Provider"; case l: return D(z, z.render, "ForwardRef"); case u: var Me = z.displayName || null; return Me !== null ? Me : _(z.type) || "Memo"; case h: { var We = z, tt = We._payload, _e = We._init; try { return _(_e(tt)); } catch { return null; } } } return null; } var k = Object.assign, Q = 0, E, $, I, P, F, B, A; function R() { } R.__reactDisabledLog = !0; function Z() { { if (Q === 0) { E = console.log, $ = console.info, I = console.warn, P = console.error, F = console.group, B = console.groupCollapsed, A = console.groupEnd; var z = { configurable: !0, enumerable: !0, value: R, writable: !0 }; Object.defineProperties(console, { info: z, log: z, warn: z, error: z, group: z, groupCollapsed: z, groupEnd: z }); } Q++; } } function Y() { { if (Q--, Q === 0) { var z = { configurable: !0, enumerable: !0, writable: !0 }; Object.defineProperties(console, { log: k({}, z, { value: E }), info: k({}, z, { value: $ }), warn: k({}, z, { value: I }), error: k({}, z, { value: P }), group: k({}, z, { value: F }), groupCollapsed: k({}, z, { value: B }), groupEnd: k({}, z, { value: A }) }); } Q < 0 && v("disabledDepth fell below zero. This is a bug in React. Please file an issue."); } } var G = b.ReactCurrentDispatcher, X; function q(z, ae, he) { { if (X === void 0) try { throw Error(); } catch (We) { var Me = We.stack.trim().match(/\n( *(at )?)/); X = Me && Me[1] || ""; } return ` ` + X + z; } } var H = !1, K; { var J = typeof WeakMap == "function" ? WeakMap : Map; K = new J(); } function ie(z, ae) { if (!z || H) return ""; { var he = K.get(z); if (he !== void 0) return he; } var Me; H = !0; var We = Error.prepareStackTrace; Error.prepareStackTrace = void 0; var tt; tt = G.current, G.current = null, Z(); try { if (ae) { var _e = function() { throw Error(); }; if (Object.defineProperty(_e.prototype, "props", { set: function() { throw Error(); } }), typeof Reflect == "object" && Reflect.construct) { try { Reflect.construct(_e, []); } catch (cn) { Me = cn; } Reflect.construct(z, [], _e); } else { try { _e.call(); } catch (cn) { Me = cn; } z.call(_e.prototype); } } else { try { throw Error(); } catch (cn) { Me = cn; } z(); } } catch (cn) { if (cn && Me && typeof cn.stack == "string") { for (var Ee = cn.stack.split(` `), en = Me.stack.split(` `), vt = Ee.length - 1, jt = en.length - 1; vt >= 1 && jt >= 0 && Ee[vt] !== en[jt]; ) jt--; for (; vt >= 1 && jt >= 0; vt--, jt--) if (Ee[vt] !== en[jt]) { if (vt !== 1 || jt !== 1) do if (vt--, jt--, jt < 0 || Ee[vt] !== en[jt]) { var Nn = ` ` + Ee[vt].replace(" at new ", " at "); return z.displayName && Nn.includes("<anonymous>") && (Nn = Nn.replace("<anonymous>", z.displayName)), typeof z == "function" && K.set(z, Nn), Nn; } while (vt >= 1 && jt >= 0); break; } } } finally { H = !1, G.current = tt, Y(), Error.prepareStackTrace = We; } var Ja = z ? z.displayName || z.name : "", ea = Ja ? q(Ja) : ""; return typeof z == "function" && K.set(z, ea), ea; } function de(z, ae, he) { return ie(z, !1); } function se(z) { var ae = z.prototype; return !!(ae && ae.isReactComponent); } function Re(z, ae, he) { if (z == null) return ""; if (typeof z == "function") return ie(z, se(z)); if (typeof z == "string") return q(z); switch (z) { case f: return q("Suspense"); case c: return q("SuspenseList"); } if (typeof z == "object") switch (z.$$typeof) { case l: return de(z.render); case u: return Re(z.type, ae, he); case h: { var Me = z, We = Me._payload, tt = Me._init; try { return Re(tt(We), ae, he); } catch { } } } return ""; } var Se = Object.prototype.hasOwnProperty, ke = {}, ht = b.ReactDebugCurrentFrame; function je(z) { if (z) { var ae = z._owner, he = Re(z.type, z._source, ae ? ae.type : null); ht.setExtraStackFrame(he); } else ht.setExtraStackFrame(null); } function Ie(z, ae, he, Me, We) { { var tt = Function.call.bind(Se); for (var _e in z) if (tt(z, _e)) { var Ee = void 0; try { if (typeof z[_e] != "function") { var en = Error((Me || "React class") + ": " + he + " type `" + _e + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof z[_e] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`."); throw en.name = "Invariant Violation", en; } Ee = z[_e](ae, _e, Me, he, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"); } catch (vt) { Ee = vt; } Ee && !(Ee instanceof Error) && (je(We), v("%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).", Me || "React class", he, _e, typeof Ee), je(null)), Ee instanceof Error && !(Ee.message in ke) && (ke[Ee.message] = !0, je(We), v("Failed %s type: %s", he, Ee.message), je(null)); } } } var Ae = Array.isArray; function ze(z) { return Ae(z); } function Kt(z) { { var ae = typeof Symbol == "function" && Symbol.toStringTag, he = ae && z[Symbol.toStringTag] || z.constructor.name || "Object"; return he; } } function Bt(z) { try { return Gr(z), !1; } catch { return !0; } } function Gr(z) { return "" + z; } function hi(z) { if (Bt(z)) return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", Kt(z)), Gr(z); } var Qs = b.ReactCurrentOwner, Qp = { key: !0, ref: !0, __self: !0, __source: !0 }, Ga, Ur; function As(z) { if (Se.call(z, "ref")) { var ae = Object.getOwnPropertyDescriptor(z, "ref").get; if (ae && ae.isReactWarning) return !1; } return z.ref !== void 0; } function Es(z) { if (Se.call(z, "key")) { var ae = Object.getOwnPropertyDescriptor(z, "key").get; if (ae && ae.isReactWarning) return !1; } return z.key !== void 0; } function Ua(z, ae) { typeof z.ref == "string" && Qs.current; } function Ap(z, ae) { { var he = function() { Ga || (Ga = !0, v("%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)", ae)); }; he.isReactWarning = !0, Object.defineProperty(z, "key", { get: he, configurable: !0 }); } } function Ep(z, ae) { { var he = function() { Ur || (Ur = !0, v("%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)", ae)); }; he.isReactWarning = !0, Object.defineProperty(z, "ref", { get: he, configurable: !0 }); } } var $p = function(z, ae, he, Me, We, tt, _e) { var Ee = { // This tag allows us to uniquely identify this as a React Element $$typeof: e, // Built-in properties that belong on the element type: z, key: ae, ref: he, props: _e, // Record the component responsible for creating this element. _owner: tt }; return Ee._store = {}, Object.defineProperty(Ee._store, "validated", { configurable: !1, enumerable: !1, writable: !0, value: !1 }), Object.defineProperty(Ee, "_self", { configurable: !1, enumerable: !1, writable: !1, value: Me }), Object.defineProperty(Ee, "_source", { configurable: !1, enumerable: !1, writable: !1, value: We }), Object.freeze && (Object.freeze(Ee.props), Object.freeze(Ee)), Ee; }; function Rp(z, ae, he, Me, We) { { var tt, _e = {}, Ee = null, en = null; he !== void 0 && (hi(he), Ee = "" + he), Es(ae) && (hi(ae.key), Ee = "" + ae.key), As(ae) && (en = ae.ref, Ua(ae, We)); for (tt in ae) Se.call(ae, tt) && !Qp.hasOwnProperty(tt) && (_e[tt] = ae[tt]); if (z && z.defaultProps) { var vt = z.defaultProps; for (tt in vt) _e[tt] === void 0 && (_e[tt] = vt[tt]); } if (Ee || en) { var jt = typeof z == "function" ? z.displayName || z.name || "Unknown" : z; Ee && Ap(_e, jt), en && Ep(_e, jt); } return $p(z, Ee, en, We, Me, Qs.current, _e); } } var $s = b.ReactCurrentOwner, Rs = b.ReactDebugCurrentFrame; function pi(z) { if (z) { var ae = z._owner, he = Re(z.type, z._source, ae ? ae.type : null); Rs.setExtraStackFrame(he); } else Rs.setExtraStackFrame(null); } var qa; qa = !1; function Ha(z) { return typeof z == "object" && z !== null && z.$$typeof === e; } function zs() { { if ($s.current) { var z = _($s.current.type); if (z) return ` Check the render method of \`` + z + "`."; } return ""; } } function zp(z) { return ""; } var _s = {}; function _p(z) { { var ae = zs(); if (!ae) { var he = typeof z == "string" ? z : z.displayName || z.name; he && (ae = ` Check the top-level render call using <` + he + ">."); } return ae; } } function dv(z, ae) { { if (!z._store || z._store.validated || z.key != null) return; z._store.validated = !0; var he = _p(ae); if (_s[he]) return; _s[he] = !0; var Me = ""; z && z._owner && z._owner !== $s.current && (Me = " It was passed a child from " + _(z._owner.type) + "."), pi(z), v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', he, Me), pi(null); } } function hv(z, ae) { { if (typeof z != "object") return; if (ze(z)) for (var he = 0; he < z.length; he++) { var Me = z[he]; Ha(Me) && dv(Me, ae); } else if (Ha(z)) z._store && (z._store.validated = !0); else if (z) { var We = y(z); if (typeof We == "function" && We !== z.entries) for (var tt = We.call(z), _e; !(_e = tt.next()).done; ) Ha(_e.value) && dv(_e.value, ae); } } } function EA(z) { { var ae = z.type; if (ae == null || typeof ae == "string") return; var he; if (typeof ae == "function") he = ae.propTypes; else if (typeof ae == "object" && (ae.$$typeof === l || // Note: Memo only checks outer props here. // Inner props are checked in the reconciler. ae.$$typeof === u)) he = ae.propTypes; else return; if (he) { var Me = _(ae); Ie(he, z.props, "prop", Me, z); } else if (ae.PropTypes !== void 0 && !qa) { qa = !0; var We = _(ae); v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", We || "Unknown"); } typeof ae.getDefaultProps == "function" && !ae.getDefaultProps.isReactClassApproved && v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead."); } } function $A(z) { { for (var ae = Object.keys(z.props), he = 0; he < ae.length; he++) { var Me = ae[he]; if (Me !== "children" && Me !== "key") { pi(z), v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", Me), pi(null); break; } } z.ref !== null && (pi(z), v("Invalid attribute `ref` supplied to `React.Fragment`."), pi(null)); } } var pv = {}; function mv(z, ae, he, Me, We, tt) { { var _e = L(z); if (!_e) { var Ee = ""; (z === void 0 || typeof z == "object" && z !== null && Object.keys(z).length === 0) && (Ee += " 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 en = zp(); en ? Ee += en : Ee += zs(); var vt; z === null ? vt = "null" : ze(z) ? vt = "array" : z !== void 0 && z.$$typeof === e ? (vt = "<" + (_(z.type) || "Unknown") + " />", Ee = " Did you accidentally export a JSX literal instead of a component?") : vt = typeof z, v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", vt, Ee); } var jt = Rp(z, ae, he, We, tt); if (jt == null) return jt; if (_e) { var Nn = ae.children; if (Nn !== void 0) if (Me) if (ze(Nn)) { for (var Ja = 0; Ja < Nn.length; Ja++) hv(Nn[Ja], z); Object.freeze && Object.freeze(Nn); } else v("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 hv(Nn, z); } if (Se.call(ae, "key")) { var ea = _(z), cn = Object.keys(ae).filter(function(BA) { return BA !== "key"; }), Zp = cn.length > 0 ? "{key: someKey, " + cn.join(": ..., ") + ": ...}" : "{key: someKey}"; if (!pv[ea + Zp]) { var YA = cn.length > 0 ? "{" + cn.join(": ..., ") + ": ...}" : "{}"; v(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`, Zp, ea, YA, ea), pv[ea + Zp] = !0; } } return z === r ? $A(jt) : EA(jt), jt; } } function RA(z, ae, he) { return mv(z, ae, he, !0); } function zA(z, ae, he) { return mv(z, ae, he, !1); } var _A = zA, ZA = RA; Ys.Fragment = r, Ys.jsx = _A, Ys.jsxs = ZA; })()), Ys; } var vv; function E9() { return vv || (vv = 1, process.env.NODE_ENV === "production" ? pc.exports = Q9() : pc.exports = A9()), pc.exports; } var d = E9(); function Eu(t) { return t ? t.type === "file" ? t.path : rr(t.path, t.name) : "/"; } function rr(t, e) { return t === "/" ? `/${e}` : `${t}/${e}`; } function wv(t) { const e = t.split("/"), n = e.pop() || "untitled", r = e.join("/") || "/"; return { name: n, parentPath: r }; } function fs(t, e) { for (const n of t) { if (n.id === e) return n; if (n.children) { const r = fs(n.children, e); if (r) return r; } } } function xM(t, e, n) { return e.length === 0 ? [...t, n] : t.map((r) => r.type === "folder" && r.name === e[0] ? { ...r, children: xM( r.children || [], e.slice(1), n ) } : r); } function Oo(t, e) { const n = t.path.split("/").filter((i) => i.length > 0); return fs(e, t.id) ? e : xM(e, n, t); } function da(t) { const e = []; for (const n of t) e.push(n), n.children && e.push(...da(n.children)); return e; } function SM(t) { const [e, n] = ue([]), [r, i] = ue(null), [a, o] = ue(""), [s, l] = ue({}), [f, c] = ue(!1), [u, h] = ue(null), [p, g] = ue(!1), m = Ce(!1); console.log({ files: e }); const y = da(e).filter( (P) => P.metadata?.isNew || P.metadata?.isDirty || P.metadata?.is_deleted ), b = me(async () => { if (!m.current) try { c(!0), h(null); const P = await t.getFiles(); n(P), m.current = !0; } catch (P) { h(P instanceof Error ? P.message : "Failed to load files"); } finally { c(!1); } }, [t]), v = me( async (P) => { try { c(!0), h(null); const F = nu(e, P); if (F && F.content !== void 0 && F.content !== null) { o(F.content); return; } const B = await t.getFileContent(P); o(B); } catch (F) { h( F instanceof Error ? F.message : "Failed to load file content" ), o(""); } finally { c(!1); } }, [t, e] ), w = me( async (P) => { if (r) try { h(null), await t.updateFileContent(r, P), o(P), n( (F) => ru(F, r, { content: P }) ), l((F) => ({ ...F, [r]: P })), g(!0); } catch (F) { h( F instanceof Error ? F.message : "Failed to update file content" ); } }, [r, t] ), x = me( (P) => { i(P), v(P); }, [v] ), M = me(async () => { try { h(null), c(!0); const P = await t.getFiles(); n(P), m.current = !0, g(!1); } catch (P) { h(P instanceof Error ? P.message : "Failed to refresh files"); } finally { c(!1); } }, [t]), S = me( (P) => nu(e, P), [e] ); we(() => { b(); }, [b]), we(() => { r && v(r); }, [r, v]); const C = me(async () => { n((P) => (P.length && (async () => { try { h(null); const F = {}, B = da(P); for (const A of B) if (A.type === "file") try { const R = await t.getFileContent(A.id), Z = rr(A.path, A.name); F[Z] = R; } catch (R) { console.warn( `Failed to load ${A.path}/${A.name} via fileProvider:`, R ); const Z = rr(A.path, A.name); F[Z] = `// Failed to load content for ${A.name}`; } l(F); } catch (F) { h( F instanceof Error ? F.message : "Failed to load file contents" ); } })(), P)); }, [t]); we(() => { e.length > 0 && (async () => { try { h(null); const P = {}, F = da(e); for (const B of F) if (B.type === "file") try { const A = await t.getFileContent(B.id), R = rr(B.path, B.name); P[R] = A; } catch (A) { console.warn( `Failed to load ${B.path}/${B.name} via fileProvider:`, A ); const R = rr(B.path, B.name); P[R] = `// Failed to load content for ${B.name}`; } l(P); } catch (P) { h( P instanceof Error ? P.message : "Failed to load file contents" ); } })(); }, [e, t]); const j = me( async (P, F = "") => { if (t.createFile) try { h(null); const B = await t.createFile(P, F); n((R) => { const Z = Oo(B, [...R]); return console.log({ updatedFiles: Z }), Z; }); const A = rr(B.path, B.name); l((R) => ({ ...R, [A]: F })), i(B.id), g(!0); } catch (B) { h(B instanceof Error ? B.message : "Failed to create file"); } }, [t] ), N = me( async (P) => { if (t.createFolder) try { h(null); const F = await t.createFolder(P); n((B) => Oo(F, [...B])), g(!0); } catch (F) { h( F instanceof Error ? F.message : "Failed to create folder" ); } }, [t] ), L = me( async (P) => { if (t.deleteFile) try { h(null), await t.deleteFile(P), n((F) => Lm(F, P)), l((F) => { const B = { ...F }, A = nu(e, P); return A && delete B[A.path], B; }), r === P && i(null), g(!0); } catch (F) { h(F instanceof Error ? F.message : "Failed to delete file"); } }, [t, e, r] ), D = me( async (P) => { if (t.deleteFolder) try { h(null), await t.deleteFolder(P), n((F) => Lm(F, P)), g(!0); } catch (F) { h( F instanceof Error ? F.message : "Failed to delete folder" ); } }, [t] ), T = me( async (P, F) => { if (t.renameFile) try { h(null), await t.renameFile(P, F), n( (B) => ru(B, P, { name: F }) ), g(!0); } catch (B) { h(B instanceof Error ? B.message : "Failed to rename file"); } }, [t] ), _ = me( async (P, F) => { if (t.moveFile) try { h(null), await t.moveFile(P, F), n( (B) => ru(B, P, { path: F }) ), g(!0); } catch (B) { h(B instanceof Error ? B.message : "Failed to move file"); } }, [t] ), k = me(() => t.getEditorData ? t.getEditorData() : null, [t]), Q = me( async (P) => { if (t.loadEditorData) try { h(null), c(!0), await t.loadEditorData(P); const F = await t.getFiles(); n(F), m.current = !0; } catch (F) { h( F instanceof Error ? F.message : "Failed to load editor data" ); } finally { c(!1); } }, [t] ), E = me(async () => { if (!t.saveAllChanges) return null; try { h(null), c(!0); const P = await t.saveAllChanges(); return g(!1), P; } catch (P) { return h(P instanceof Error ? P.message : "Failed to save changes"), null; } finally { c(!1); } }, [t]), $ = me(() => da(e).filter( (P) => P.metadata?.isNew || P.metadata?.isDirty || P.metadata?.is_deleted ), [e]), I = me(async () => { try { h(null), c(!0); const P = await t.getFiles(); n(P), m.current = !0, g(!1); } catch (P) { h( P instanceof Error ? P.message : "Failed to discard changes" ); } finally { c(!1); } }, [t]); return { files: e, activeFile: r, fileContent: a, allFileContents: s, loading: f, error: u, hasUnsavedChanges: p, stagedChanges: y, setActiveFile: x, updateFileContent: w, refreshFiles: M, getFileById: S, loadAllFileContents: C, createFile: j, createFolder: N, deleteFile: L, deleteFolder: D, renameFile: T, moveFile: _, getEditorData: k, loadEditorData: Q, saveAllChanges: E, getStagedChanges: $, discardChanges: I }; } function nu(t, e) { for (const n of t) { if (n.id === e) return n; if (n.children) { const r = nu(n.children, e); if (r) return r; } } } function ru(t, e, n) { return t.map((r) => r.id === e ? { ...r, ...n } : r.children ? { ...r, children: ru(r.children, e, n) } : r); } function Lm(t, e) { return t.filter((n) => n.id === e ? !1 : (n.children && (n.children = Lm(n.children, e)), !0)); } function Ye(t) { const e = Object.prototype.toString.call(t); return t instanceof Date || typeof t == "object" && e === "[object Date]" ? new t.constructor(+t) : typeof t == "number" || e === "[object Number]" || typeof t == "string" || e === "[object String]" ? new Date(t) : /* @__PURE__ */ new Date(NaN); } function ln(t, e) { return t instanceof Date ? new t.constructor(e) : new Date(e); } function zt(t, e) { const n = Ye(t); return isNaN(e) ? ln(t, NaN) : (e && n.setDate(n.getDate() + e), n); } function Xn(t, e) { const n = Ye(t); if (isNaN(e)) return ln(t, NaN); if (!e) return n; const r = n.getDate(), i = ln(t, n.getTime()); i.setMonth(n.getMonth() + e + 1, 0); const a = i.getDate(); return r >= a ? i : (n.setFullYear( i.getFullYear(), i.getMonth(), r ), n); } function ir(t, e) { const { years: n = 0, months: r = 0, weeks: i = 0, days: a = 0, hours: o = 0, minutes: s = 0, seconds: l = 0 } = e, f = Ye(t), c = r || n ? Xn(f, r + n * 12) : f, u = a || i ? zt(c, a + i * 7) : c, h = s + o * 60, g = (l + h * 60) * 1e3; return ln(t, u.getTime() + g); } const ay = 6048e5, $9 = 864e5; let R9 = {}; function jf() { return R9; } function Rr(t, e) { const n = jf(), r = e?.weekStartsOn ?? e?.locale?.options?.weekStartsOn ?? n.weekStartsOn ?? n.locale?.options?.weekStartsOn ?? 0, i = Ye(t), a = i.getDay(), o = (a < r ? 7 : 0) + a - r; return i.setDate(i.getDate() - o), i.setHours(0, 0, 0, 0), i; } function ya(t) { return Rr(t, { weekStartsOn: 1 }); } function MM(t) { const e = Ye(t), n = e.getFullYear(), r = ln(t, 0); r.setFullYear(n + 1, 0, 4), r.setHours(0, 0, 0, 0); const i = ya(r), a = ln(t, 0); a.setFullYear(n, 0, 4), a.setHours(0, 0, 0, 0); const o = ya(a); return e.getTime() >= i.getTime() ? n + 1 : e.getTime() >= o.getTime() ? n : n - 1; } function bt(t) { const e = Ye(t); return e.setHours(0, 0, 0, 0), e; } function $u(t) { const e = Ye(t), n = new Date( Date.UTC( e.getFullYear(), e.getMonth(), e.getDate(), e.getHours(), e.getMinutes(), e.getSeconds(), e.getMilliseconds() ) ); return n.setUTCFullYear(e.getFullYear()), +t - +n; } function Nr(t, e) { const n = bt(t), r = bt(e), i = +n - $u(n), a = +r - $u(r); return Math.round((i - a) / $9); } function z9(t) { const e = MM(t), n = ln(t, 0); return n.setFullYear(e, 0, 4), n.setHours(0, 0, 0, 0), ya(n); } function Tm(t, e) { const n = e * 7; return zt(t, n); } function _9(t, e) { return Xn(t, e * 12); } function Z9(t) { let e; return t.forEach(function(n) { const r = Ye(n); (e === void 0 || e < r || isNaN(Number(r))) && (e = r); }), e || /* @__PURE__ */ new Date(NaN); } function Y9(t) { let e; return t.forEach((n) => { const r = Ye(n); (!e || e > r || isNaN(+r)) && (e = r); }), e || /* @__PURE__ */ new Date(NaN); } function oy(t) { return ln(t, Date.now()); } function Yt(t, e) { const n = bt(t), r = bt(e); return +n == +r; } function sy(t) { return t instanceof Date || typeof t == "object" && Object.prototype.toString.call(t) === "[object Date]"; } function vo(t) { if (!sy(t) && typeof t != "number") return !1; const e = Ye(t); return !isNaN(Number(e)); } function $l(t, e) { const n = Ye(t), r = Ye(e), i = n.getFullYear() - r.getFullYear(), a = n.getMonth() - r.getMonth(); return i * 12 + a; } function B9(t, e, n) { const r = Rr(t, n), i = Rr(e, n), a = +r - $u(r), o = +i - $u(i); return Math.round((a - o) / ay); } function ly(t) { const e = Ye(t), n = e.getMonth(); return e.setFullYear(e.getFullYear(), n + 1, 0), e.setHours(23, 59, 59, 999), e; } function mn(t) { const e = Ye(t); return e.setDate(1), e.setHours(0, 0, 0, 0), e; } function CM(t) { const e = Ye(t), n = ln(t, 0); return n.setFullYear(e.getFullYear(), 0, 1), n.setHours(0, 0, 0, 0), n; } function fy(t, e) { const n = jf(), r = e?.weekStartsOn ?? e?.locale?.options?.weekStartsOn ?? n.weekStartsOn ?? n.locale?.options?.weekStartsOn ?? 0, i = Ye(t), a = i.getDay(), o = (a < r ? -7 : 0) + 6 - (a - r); return i.setDate(i.getDate() + o), i.setHours(23, 59, 59, 999), i; } function jM(t) { return fy(t, { weekStartsOn: 1 }); } const W9 = { lessThanXSeconds: { one: "less than a second", other: "less than {{count}} seconds" }, xSeconds: { one: "1 second", other: "{{count}} seconds" }, halfAMinute: "half a minute", lessThanXMinutes: { one: "less than a minute", other: "less than {{count}} minutes" }, xMinutes: { one: "1 minute", other: "{{count}} minutes" }, aboutXHours: { one: "about 1 hour", other: "about {{count}} hours" }, xHours: { one: "1 hour", other: "{{count}} hours" }, xDays: { one: "1 day", other: "{{count}} days" }, aboutXWeeks: { one: "about 1 week", other: "about {{count}} weeks" }, xWeeks: { one: "1 week", other: "{{count}} weeks" }, aboutXMonths: { one: "about 1 month", other: "about {{count}} months" }, xMonths: { one: "1 month", other: "{{count}} months" }, aboutXYears: { one: "about 1 year", other: "about {{count}} years" }, xYears: { one: "1 year", other: "{{count}} years" }, overXYears: { one: "over 1 year", other: "over {{count}} years" }, almostXYears: { one: "almost 1 year", other: "almost {{count}} years" } }, F9 = (t, e, n) => { let r; const i = W9[t]; return typeof i == "string" ? r = i : e === 1 ? r = i.one : r = i.other.replace("{{count}}", e.toString()), n?.addSuffix ? n.comparison && n.comparison > 0 ? "in " + r : r + " ago" : r; }; function Yp(t) { return (e = {}) => { const n = e.width ? String(e.width) : t.defaultWidth; return t.formats[n] || t.formats[t.defaultWidth]; }; } const X9 = { full: "EEEE, MMMM do, y", long: "MMMM do, y", medium: "MMM d, y", short: "MM/dd/yyyy" }, V9 = { full: "h:mm:ss a zzzz", long: "h:mm:ss a z", medium: "h:mm:ss a", short: "h:mm a" }, G9 = { full: "{{date}} 'at' {{time}}", long: "{{date}} 'at' {{time}}", medium: "{{date}}, {{time}}", short: "{{date}}, {{time}}" }, U9 = { date: Yp({ formats: X9, defaultWidth: "full" }), time: Yp({ formats: V9, defaultWidth: "full" }), dateTime: Yp({ formats: G9, defaultWidth: "full" }) }, q9 = { lastWeek: "'last' eeee 'at' p", yesterday: "'yesterday at' p", today: "'today at' p", tomorrow: "'tomorrow at' p", nextWeek: "eeee 'at' p", other: "P" }, H9 = (t, e, n, r) => q9[t]; function Bs(t) { return (e, n) => { const r = n?.context ? String(n.context) : "standalone"; let i; if (r === "formatting" && t.formattingValues) { const o = t.defaultFormattingWidth || t.defaultWidth, s = n?.width ? String(n.width) : o; i = t.formattingValues[s] || t.formattingValues[o]; } else { const o = t.defaultWidth, s = n?.width ? String(n.width) : t.defaultWidth; i = t.values[s] || t.values[o]; } const a = t.argumentCallback ? t.argumentCallback(e) : e; return i[a]; }; } const J9 = { narrow: ["B", "A"], abbreviated: ["BC", "AD"], wide: ["Before Christ", "Anno Domini"] }, K9 = { narrow: ["1", "2", "3", "4"], abbreviated: ["Q1", "Q2", "Q3", "Q4"], wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"] }, e$ = { narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"], abbreviated: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ], wide: [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ] }, t$ = { narrow: ["S", "M", "T", "W", "T", "F", "S"], short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], wide: [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ] }, n$ = { narrow: { am: "a", pm: "p", midnight: "mi", noon: "n", morning: "morning", afternoon: "afternoon", evening: "evening", night: "night" }, abbreviated: { am: "AM", pm: "PM", midnight: "midnight", noon: "noon", morning: "morning", afternoon: "afternoon", evening: "evening", night: "night" }, wide: { am: "a.m.", pm: "p.m.", midnight: "midnight", noon: "noon", morning: "morning", afternoon: "afternoon", evening: "evening", night: "night" } }, r$ = { narrow: { am: "a", pm: "p", midnight: "mi", noon: "n", morning: "in the morning", afternoon: "in the afternoon", evening: "in the evening", night: "at night" }, abbreviated: { am: "AM", pm: "PM", midnight: "midnight", noon: "noon", morning: "in the morning", afternoon: "in the afternoon", evening: "in the evening", night: "at night" }, wide: { am: "a.m.", pm: "p.m.", midnight: "midnight", noon: "noon", morning: "in the morning", afternoon: "in the afternoon", evening: "in the evening", night: "at night" } }, i$ = (t, e) => { const n = Number(t), r = n % 100; if (r > 20 || r < 10) switch (r % 10) { case 1: return n + "st"; case 2: return n + "nd"; case 3: return n + "rd"; } return n + "th"; }, a$ = { ordinalNumber: i$, era: Bs({ values: J9, defaultWidth: "wide" }), quarter: Bs({ values: K9, defaultWidth: "wide", argumentCallback: (t) => t - 1 }), month: Bs({ values: e$, defaultWidth: "wide" }), day: Bs({ values: t$, defaultWidth: "wide" }), dayPeriod: Bs({ values: n$, defaultWidth: "wide", formattingValues: r$, defaultFormattingWidth: "wide" }) }; function Ws(t) { return (e, n = {}) => { const r = n.width, i = r && t.matchPatterns[r] || t.matchPatterns[t.defaultMatchWidth], a = e.match(i); if (!a) return null; const o = a[0], s = r && t.parsePatterns[r] || t.parsePatterns[t.defaultParseWidth], l = Array.isArray(s) ? s$(s, (u) => u.test(o)) : ( // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type o$(s, (u) => u.test(o)) ); let f; f = t.valueCallback ? t.valueCallback(l) : l, f = n.valueCallback ? ( // eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type n.valueCallback(f) ) : f; const c = e.slice(o.length); return { value: f, rest: c }; }; } function o$(t, e) { for (const n in t) if (Object.prototype.hasOwnProperty.call(t, n) && e(t[n])) return n; } function s$(t, e) { for (let n = 0; n < t.length; n++) if (e(t[n])) return n; } function l$(t) { return (e, n = {}) => { const r = e.match(t.matchPattern); if (!r) return null; const i = r[0], a = e.match(t.parsePattern); if (!a) return null; let o = t.valueCallback ? t.valueCallback(a[0]) : a[0]; o = n.valueCallback ? n.valueCallback(o) : o; const s = e.slice(i.length); return { value: o, rest: s }; }; } const f$ = /^(\d+)(th|st|nd|rd)?/i, c$ = /\d+/i, u$ = { narrow: /^(b|a)/i, abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i, wide: /^(before christ|before common era|anno domini|common era)/i }, d$ = { any: [/^b/i, /^(a|c)/i] }, h$ = { narrow: /^[1234]/i, abbreviated: /^q[1234]/i, wide: /^[1234](th|st|nd|rd)? quarter/i }, p$ = { any: [/1/i, /2/i, /3/i, /4/i] }, m$ = { narrow: /^[jfmasond]/i, abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i, wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i }, g$ = { narrow: [ /^j/i, /^f/i, /^m/i, /^a/i, /^m/i, /^j/i, /^j/i, /^a/i, /^s/i, /^o/i, /^n/i, /^d/i ], any: [ /^ja/i, /^f/i, /^mar/i, /^ap/i, /^may/i, /^jun/i, /^jul/i, /^au/i, /^s/i, /^o/i, /^n/i, /^d/i ] }, y$ = { narrow: /^[smtwf]/i, short: /^(su|mo|tu|we|th|fr|sa)/i, abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i, wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i }, b$ = { narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i], any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i] }, O$ = { narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i, any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i }, v$ = { any: { am: /^a/i, pm: /^p/i, midnight: /^mi/i, noon: /^no/i, morning: /morning/i, afternoon: /afternoon/i, evening: /evening/i, night: /night/i } }, w$ = { ordinalNumber: l$({ matchPattern: f$, parsePattern: c$, valueCallback: (t) => parseInt(t, 10) }), era: Ws({ matchPatterns: u$, defaultMatchWidth: "wide", parsePatterns: d$, defaultParseWidth: "any" }), quarter: Ws({ matchPatterns: h$, defaultMatchWidth: "wide", parsePatterns: p$, defaultParseWidth: "any", valueCallback: (t) => t + 1 }), month: Ws({ matchPatterns: m$, defaultMatchWidth: "wide", parsePatterns: g$, defaultParseWidth: "any" }), day: Ws({ matchPatterns: y$, defaultMatchWidth: "wide", parsePatterns: b$, defaultParseWidth: "any" }), dayPeriod: Ws({ matchPatterns: O$, defaultMatchWidth: "any", parsePatterns: v$, defaultParseWidth: "any" }) }, x$ = { code: "en-US", formatDistance: F9, formatLong: U9, formatRelative: H9, localize: a$, match: w$, options: { weekStartsOn: 0, firstWeekContainsDate: 1 } }; function S$(t) { const e = Ye(t); return Nr(e, CM(e)) + 1; } function kM(t) { const e = Ye(t), n = +ya(e) - +z9(e); return Math.round(n / ay) + 1; } function LM(t, e) { const n = Ye(t), r = n.getFullYear(), i = jf(), a = e?.firstWeekContainsDate ?? e?.locale?.options?.firstWeekContainsDate ?? i.firstWeekContainsDate ?? i.locale?.options?.firstWeekContainsDate ?? 1, o = ln(t, 0); o.setFullYear(r + 1, 0, a), o.setHours(0, 0, 0, 0); const s = Rr(o, e), l = ln(t, 0); l.setFullYear(r, 0, a), l.setHours(0, 0, 0, 0); const f = Rr(l, e); return n.getTime() >= s.getTime() ? r + 1 : n.getTime() >= f.getTime() ? r : r - 1; } function M$(t, e) { const n = jf(), r = e?.firstWeekContainsDate ?? e?.locale?.options?.firstWeekContainsDate ?? n.firstWeekContainsDate ?? n.locale?.options?.firstWeekContainsDate ?? 1, i = LM(t, e), a = ln(t, 0); return a.setFullYear(i, 0, r), a.setHours(0, 0, 0, 0), Rr(a, e); } function TM(t, e) { const n = Ye(t), r = +Rr(n, e) - +M$(n, e); return Math.round(r / ay) + 1; } function Ue(t, e) { const n = t < 0 ? "-" : "", r = Math.abs(t).toString().padStart(e, "0"); return n + r; } const gi = { // Year y(t, e) { const n = t.getFullYear(), r = n > 0 ? n : 1 - n; return Ue(e === "yy" ? r % 100 : r, e.length); }, // Month M(t, e) { const n = t.getMonth(); return e === "M" ? String(n + 1) : Ue(n + 1, 2); }, // Day of the month d(t, e) { return Ue(t.getDate(), e.length); }, // AM or PM a(t, e) { const n = t.getHours() / 12 >= 1 ? "pm" : "am"; switch (e) { case "a": case "aa": return n.toUpperCase(); case "aaa": return n; case "aaaaa": return n[0]; case "aaaa": default: return n === "am" ? "a.m." : "p.m."; } }, // Hour [1-12] h(t, e) { return Ue(t.getHours() % 12 || 12, e.length); }, // Hour [0-23] H(t, e) { return Ue(t.getHours(), e.length); }, // Minute m(t, e) { return Ue(t.getMinutes(), e.length); }, // Second s(t, e) { return Ue(t.getSeconds(), e.length); }, // Fraction of second S(t, e) { const n = e.length, r = t.getMilliseconds(), i = Math.trunc( r * Math.pow(10, n - 3) ); return Ue(i, e.length); } }, Ka = { midnight: "midnight", noon: "noon", morning: "morning", afternoon: "afternoon", evening: "evening", night: "night" }, xv = { // Era G: function(t, e, n) { const r = t.getFullYear() > 0 ? 1 : 0; switch (e) { // AD, BC case "G": case "GG": case "GGG": return n.era(r, { width: "abbreviated" }); // A, B case "GGGGG": return n.era(r, { width: "narrow" }); // Anno Domini, Before Christ case "GGGG": default: return n.era(r, { width: