UNPKG

@sheetxl/studio-vanilla

Version:

SheetXL Studio - Vanilla entry point for integrating SheetXL UI.

393 lines (390 loc) 17.3 kB
import { r as u, m as T } from "./EFJ5klSL3OL5aq6z.mjs"; /** * @license @sheetxl/studio-vanilla - SheetXL Studio - Vanilla entry point for integrating SheetXL UI. - v0.6.4 * * (C) 2025-present SheetXL Inc. & Michael T. Ford * License: The license can be found at https://www.sheetxl.com/license. */ function me(e, t, r) { return t in e ? Object.defineProperty(e, t, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = r, e; } function ne(e, t) { var r = Object.keys(e); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); t && (n = n.filter(function(o) { return Object.getOwnPropertyDescriptor(e, o).enumerable; })), r.push.apply(r, n); } return r; } function oe(e) { for (var t = 1; t < arguments.length; t++) { var r = arguments[t] != null ? arguments[t] : {}; t % 2 ? ne(Object(r), !0).forEach(function(n) { me(e, n, r[n]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : ne(Object(r)).forEach(function(n) { Object.defineProperty(e, n, Object.getOwnPropertyDescriptor(r, n)); }); } return e; } function ie(e, t) { (t == null || t > e.length) && (t = e.length); for (var r = 0, n = new Array(t); r < t; r++) n[r] = e[r]; return n; } function ye(e, t, r) { return t in e ? Object.defineProperty(e, t, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = r, e; } function ue(e, t) { var r = Object.keys(e); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); t && (n = n.filter(function(o) { return Object.getOwnPropertyDescriptor(e, o).enumerable; })), r.push.apply(r, n); } return r; } function ce(e) { for (var t = 1; t < arguments.length; t++) { var r = arguments[t] != null ? arguments[t] : {}; t % 2 ? ue(Object(r), !0).forEach(function(n) { ye(e, n, r[n]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : ue(Object(r)).forEach(function(n) { Object.defineProperty(e, n, Object.getOwnPropertyDescriptor(r, n)); }); } return e; } function V(e) { return function t() { for (var r = this, n = arguments.length, o = new Array(n), i = 0; i < n; i++) o[i] = arguments[i]; return o.length >= e.length ? e.apply(this, o) : function() { for (var c = arguments.length, a = new Array(c), g = 0; g < c; g++) a[g] = arguments[g]; return t.apply(r, [].concat(o, a)); }; }; } function U(e) { return {}.toString.call(e).includes("Object"); } function z(e) { return typeof e == "function"; } var R = V(function(e, t) { throw new Error(e[t] || e.default); })({ initialIsRequired: "initial state is required", initialType: "initial state should be an object", initialContent: "initial state shouldn't be an empty object", handlerType: "handler should be an object or a function", handlersType: "all handlers should be a functions", selectorType: "selector should be a function", changeType: "provided value of changes should be an object", changeField: 'it seams you want to change a field in the state which is not specified in the "initial" state', default: "an unknown error accured in `state-local` package" }), ve = function(e, t) { return U(t) || R("changeType"), Object.keys(t).some(function(r) { return n = e, o = r, !Object.prototype.hasOwnProperty.call(n, o); var n, o; }) && R("changeField"), t; }, be = function(e) { z(e) || R("selectorType"); }, we = function(e) { z(e) || U(e) || R("handlerType"), U(e) && Object.values(e).some(function(t) { return !z(t); }) && R("handlersType"); }, Oe = function(e) { var t; e || R("initialIsRequired"), U(e) || R("initialType"), t = e, Object.keys(t).length || R("initialContent"); }; function je(e, t) { return z(t) ? t(e.current) : t; } function Me(e, t) { return e.current = ce(ce({}, e.current), t), t; } function Ee(e, t, r) { return z(t) ? t(e.current) : Object.keys(r).forEach(function(n) { var o; return (o = t[n]) === null || o === void 0 ? void 0 : o.call(t, e.current[n]); }), r; } var Q, Pe = function(e) { var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; Oe(e), we(t); var r = { current: e }, n = V(Ee)(r, t), o = V(Me)(r), i = V(ve)(e), c = V(je)(r); return [function() { var a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : function(g) { return g; }; return be(a), a(r.current); }, function(a) { (function() { for (var g = arguments.length, p = new Array(g), O = 0; O < g; O++) p[O] = arguments[O]; return function(b) { return p.reduceRight(function(E, P) { return P(E); }, b); }; })(n, o, i, c)(a); }]; }, se = { configIsRequired: "the configuration object is required", configType: "the configuration object should be an object", default: "an unknown error accured in `@monaco-editor/loader` package", deprecation: `Deprecation warning! You are using deprecated way of configuration. Instead of using monaco.config({ urls: { monacoBase: '...' } }) use monaco.config({ paths: { vs: '...' } }) For more please check the link https://github.com/suren-atoyan/monaco-loader#config ` }, ae = (Q = function(e, t) { throw new Error(e[t] || e.default); }, function e() { for (var t = this, r = arguments.length, n = new Array(r), o = 0; o < r; o++) n[o] = arguments[o]; return n.length >= Q.length ? Q.apply(this, n) : function() { for (var i = arguments.length, c = new Array(i), a = 0; a < i; a++) c[a] = arguments[a]; return e.apply(t, [].concat(n, c)); }; })(se), Re = function(e) { var t; return e || ae("configIsRequired"), t = e, {}.toString.call(t).includes("Object") || ae("configType"), e.urls ? (console.warn(se.deprecation), { paths: { vs: e.urls.monacoBase } }) : e; }; function fe(e, t) { return Object.keys(t).forEach(function(r) { t[r] instanceof Object && e[r] && Object.assign(t[r], fe(e[r], t[r])); }), oe(oe({}, e), t); } var Se = { type: "cancelation", msg: "operation is manually canceled" }; function W(e) { var t = !1, r = new Promise(function(n, o) { e.then(function(i) { return t ? o(Se) : n(i); }), e.catch(o); }); return r.cancel = function() { return t = !0; }, r; } var X, de = function(e) { if (Array.isArray(e)) return e; }(X = Pe({ config: { paths: { vs: "https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min/vs" } }, isInitialized: !1, resolve: null, reject: null, monaco: null })) || function(e) { if (typeof Symbol < "u" && Symbol.iterator in Object(e)) { var t = [], r = !0, n = !1, o = void 0; try { for (var i, c = e[Symbol.iterator](); !(r = (i = c.next()).done) && (t.push(i.value), t.length !== 2); r = !0) ; } catch (a) { n = !0, o = a; } finally { try { r || c.return == null || c.return(); } finally { if (n) throw o; } } return t; } }(X) || function(e) { if (e) { if (typeof e == "string") return ie(e, 2); var t = Object.prototype.toString.call(e).slice(8, -1); return t === "Object" && e.constructor && (t = e.constructor.name), t === "Map" || t === "Set" ? Array.from(e) : t === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? ie(e, 2) : void 0; } }(X) || function() { throw new TypeError(`Invalid attempt to destructure non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`); }(), q = de[0], B = de[1]; function ke(e) { return document.body.appendChild(e); } function xe(e) { var t, r, n = q(function(i) { return { config: i.config, reject: i.reject }; }), o = (t = "".concat(n.config.paths.vs, "/loader.js"), r = document.createElement("script"), t && (r.src = t), r); return o.onload = function() { return e(); }, o.onerror = n.reject, o; } function Ie() { var e = q(function(r) { return { config: r.config, resolve: r.resolve, reject: r.reject }; }), t = window.require; t.config(e.config), t(["vs/editor/editor.main"], function(r) { ge(r), e.resolve(r); }, function(r) { e.reject(r); }); } function ge(e) { q().monaco || B({ monaco: e }); } var Z = new Promise(function(e, t) { return B({ resolve: e, reject: t }); }), Y = { config: function(e) { var t = Re(e), r = t.monaco, n = function(o, i) { if (o == null) return {}; var c, a, g = function(O, b) { if (O == null) return {}; var E, P, S = {}, k = Object.keys(O); for (P = 0; P < k.length; P++) E = k[P], b.indexOf(E) >= 0 || (S[E] = O[E]); return S; }(o, i); if (Object.getOwnPropertySymbols) { var p = Object.getOwnPropertySymbols(o); for (a = 0; a < p.length; a++) c = p[a], i.indexOf(c) >= 0 || Object.prototype.propertyIsEnumerable.call(o, c) && (g[c] = o[c]); } return g; }(t, ["monaco"]); B(function(o) { return { config: fe(o.config, n), monaco: r }; }); }, init: function() { var e = q(function(t) { return { monaco: t.monaco, isInitialized: t.isInitialized, resolve: t.resolve }; }); if (!e.isInitialized) { if (B({ isInitialized: !0 }), e.monaco) return e.resolve(e.monaco), W(Z); if (window.monaco && window.monaco.editor) return ge(window.monaco), e.resolve(window.monaco), W(Z); (function() { for (var t = arguments.length, r = new Array(t), n = 0; n < t; n++) r[n] = arguments[n]; return function(o) { return r.reduceRight(function(i, c) { return c(i); }, o); }; })(ke, xe)(Ie); } return W(Z); }, __getMonacoInstance: function() { return q(function(e) { return e.monaco; }); } }, Te = { display: "flex", position: "relative", textAlign: "initial" }, Ce = { width: "100%" }, Ae = { display: "none" }, De = { container: { display: "flex", height: "100%", width: "100%", justifyContent: "center", alignItems: "center" } }, Ve = function({ children: e }) { return T.createElement("div", { style: De.container }, e); }, pe = u.memo(function({ width: e, height: t, isEditorReady: r, loading: n, _ref: o, className: i, wrapperProps: c }) { return T.createElement("section", { style: { ...Te, width: e, height: t }, ...c }, !r && T.createElement(Ve, null, n), T.createElement("div", { ref: o, style: { ...Ce, ...!r && Ae }, className: i })); }), ee = function(e) { u.useEffect(e, []); }, j = function(e, t, r = !0) { let n = u.useRef(!0); u.useEffect(n.current || !r ? () => { n.current = !1; } : e, t); }; function L() { } function I(e, t, r, n) { return i = n, (o = e).editor.getModel(le(o, i)) || function(c, a, g, p) { return c.editor.createModel(a, g, p ? le(c, p) : void 0); }(e, t, r, n); var o, i; } function le(e, t) { return e.Uri.parse(t); } var qe = u.memo(function({ original: e, modified: t, language: r, originalLanguage: n, modifiedLanguage: o, originalModelPath: i, modifiedModelPath: c, keepCurrentOriginalModel: a = !1, keepCurrentModifiedModel: g = !1, theme: p = "light", loading: O = "Loading...", options: b = {}, height: E = "100%", width: P = "100%", className: S, wrapperProps: k = {}, beforeMount: $ = L, onMount: G = L }) { let [w, C] = u.useState(!1), [A, m] = u.useState(!0), y = u.useRef(null), f = u.useRef(null), D = u.useRef(null), v = u.useRef(G), l = u.useRef($), x = u.useRef(!1); ee(() => { let s = Y.init(); return s.then((d) => (f.current = d) && m(!1)).catch((d) => d?.type !== "cancelation" && console.error("Monaco initialization: error:", d)), () => y.current ? function() { let d = y.current?.getModel(); a || d?.original?.dispose(), g || d?.modified?.dispose(), y.current?.dispose(); }() : s.cancel(); }), j(() => { if (y.current && f.current) { let s = y.current.getOriginalEditor(), d = I(f.current, e || "", n || r || "text", i || ""); d !== s.getModel() && s.setModel(d); } }, [i], w), j(() => { if (y.current && f.current) { let s = y.current.getModifiedEditor(), d = I(f.current, t || "", o || r || "text", c || ""); d !== s.getModel() && s.setModel(d); } }, [c], w), j(() => { let s = y.current.getModifiedEditor(); s.getOption(f.current.editor.EditorOption.readOnly) ? s.setValue(t || "") : t !== s.getValue() && (s.executeEdits("", [{ range: s.getModel().getFullModelRange(), text: t || "", forceMoveMarkers: !0 }]), s.pushUndoStop()); }, [t], w), j(() => { y.current?.getModel()?.original.setValue(e || ""); }, [e], w), j(() => { let { original: s, modified: d } = y.current.getModel(); f.current.editor.setModelLanguage(s, n || r || "text"), f.current.editor.setModelLanguage(d, o || r || "text"); }, [r, n, o], w), j(() => { f.current?.editor.setTheme(p); }, [p], w), j(() => { y.current?.updateOptions(b); }, [b], w); let _ = u.useCallback(() => { if (!f.current) return; l.current(f.current); let s = I(f.current, e || "", n || r || "text", i || ""), d = I(f.current, t || "", o || r || "text", c || ""); y.current?.setModel({ original: s, modified: d }); }, [r, t, o, e, n, i, c]), N = u.useCallback(() => { !x.current && D.current && (y.current = f.current.editor.createDiffEditor(D.current, { automaticLayout: !0, ...b }), _(), f.current?.editor.setTheme(p), C(!0), x.current = !0); }, [b, p, _]); return u.useEffect(() => { w && v.current(y.current, f.current); }, [w]), u.useEffect(() => { !A && !w && N(); }, [A, w, N]), T.createElement(pe, { width: P, height: E, isEditorReady: w, loading: O, _ref: D, className: S, wrapperProps: k }); }), _e = function() { let [e, t] = u.useState(Y.__getMonacoInstance()); return ee(() => { let r; return e || (r = Y.init(), r.then((n) => { t(n); })), () => r?.cancel(); }), e; }, F = /* @__PURE__ */ new Map(), Le = u.memo(function({ defaultValue: e, defaultLanguage: t, defaultPath: r, value: n, language: o, path: i, theme: c = "light", line: a, loading: g = "Loading...", options: p = {}, overrideServices: O = {}, saveViewState: b = !0, keepCurrentModel: E = !1, width: P = "100%", height: S = "100%", className: k, wrapperProps: $ = {}, beforeMount: G = L, onMount: w = L, onChange: C, onValidate: A = L }) { let [m, y] = u.useState(!1), [f, D] = u.useState(!0), v = u.useRef(null), l = u.useRef(null), x = u.useRef(null), _ = u.useRef(w), N = u.useRef(G), s = u.useRef(), d = u.useRef(n), he = function(h) { let M = u.useRef(); return u.useEffect(() => { M.current = h; }, [h]), M.current; }(i), te = u.useRef(!1), H = u.useRef(!1); ee(() => { let h = Y.init(); return h.then((M) => (v.current = M) && D(!1)).catch((M) => M?.type !== "cancelation" && console.error("Monaco initialization: error:", M)), () => l.current ? (s.current?.dispose(), E ? b && F.set(i, l.current.saveViewState()) : l.current.getModel()?.dispose(), void l.current.dispose()) : h.cancel(); }), j(() => { let h = I(v.current, e || n || "", t || o || "", i || r || ""); h !== l.current?.getModel() && (b && F.set(he, l.current?.saveViewState()), l.current?.setModel(h), b && l.current?.restoreViewState(F.get(i))); }, [i], m), j(() => { l.current?.updateOptions(p); }, [p], m), j(() => { !l.current || n === void 0 || (l.current.getOption(v.current.editor.EditorOption.readOnly) ? l.current.setValue(n) : n !== l.current.getValue() && (H.current = !0, l.current.executeEdits("", [{ range: l.current.getModel().getFullModelRange(), text: n, forceMoveMarkers: !0 }]), l.current.pushUndoStop(), H.current = !1)); }, [n], m), j(() => { let h = l.current?.getModel(); h && o && v.current?.editor.setModelLanguage(h, o); }, [o], m), j(() => { a !== void 0 && l.current?.revealLine(a); }, [a], m), j(() => { v.current?.editor.setTheme(c); }, [c], m); let re = u.useCallback(() => { if (x.current && v.current && !te.current) { N.current(v.current); let h = i || r, M = I(v.current, n || e || "", t || o || "", h || ""); l.current = v.current?.editor.create(x.current, { model: M, automaticLayout: !0, ...p }, O), b && l.current.restoreViewState(F.get(h)), v.current.editor.setTheme(c), a !== void 0 && l.current.revealLine(a), y(!0), te.current = !0; } }, [e, t, r, n, o, i, p, O, b, c, a]); return u.useEffect(() => { m && _.current(l.current, v.current); }, [m]), u.useEffect(() => { !f && !m && re(); }, [f, m, re]), d.current = n, u.useEffect(() => { m && C && (s.current?.dispose(), s.current = l.current?.onDidChangeModelContent((h) => { H.current || C(l.current.getValue(), h); })); }, [m, C]), u.useEffect(() => { if (m) { let h = v.current.editor.onDidChangeMarkers((M) => { let J = l.current.getModel()?.uri; if (J && M.find((K) => K.path === J.path)) { let K = v.current.editor.getModelMarkers({ resource: J }); A?.(K); } }); return () => { h?.dispose(); }; } return () => { }; }, [m, A]), T.createElement(pe, { width: P, height: S, isEditorReady: m, loading: g, _ref: x, className: k, wrapperProps: $ }); }), Ne = Le; export { qe as DiffEditor, Le as Editor, Ne as default, Y as loader, _e as useMonaco };