@sheetxl/react 0.4.13 → 0.4.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,394 @@
1
+ import x, { memo as ce, useState as q, useRef as h, useCallback as ie, useEffect as M } from "react";
2
+ /**
3
+ * @license @sheetxl/react - React - React components needed to build advanced grid and spreadsheet UIs. - v0.4.15
4
+ *
5
+ * (C) 2025-present SheetXL Inc. & Michael T. Ford
6
+ * License: The license can be found at https://www.sheetxl.com/license.
7
+ */
8
+ function Me(e, t, r) {
9
+ return t in e ? Object.defineProperty(e, t, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = r, e;
10
+ }
11
+ function se(e, t) {
12
+ var r = Object.keys(e);
13
+ if (Object.getOwnPropertySymbols) {
14
+ var n = Object.getOwnPropertySymbols(e);
15
+ t && (n = n.filter(function(o) {
16
+ return Object.getOwnPropertyDescriptor(e, o).enumerable;
17
+ })), r.push.apply(r, n);
18
+ }
19
+ return r;
20
+ }
21
+ function de(e) {
22
+ for (var t = 1; t < arguments.length; t++) {
23
+ var r = arguments[t] != null ? arguments[t] : {};
24
+ t % 2 ? se(Object(r), !0).forEach(function(n) {
25
+ Me(e, n, r[n]);
26
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : se(Object(r)).forEach(function(n) {
27
+ Object.defineProperty(e, n, Object.getOwnPropertyDescriptor(r, n));
28
+ });
29
+ }
30
+ return e;
31
+ }
32
+ function Ee(e, t) {
33
+ if (e == null) return {};
34
+ var r, n, o = function(c, a) {
35
+ if (c == null) return {};
36
+ var s, g, j = {}, v = Object.keys(c);
37
+ for (g = 0; g < v.length; g++) s = v[g], a.indexOf(s) >= 0 || (j[s] = c[s]);
38
+ return j;
39
+ }(e, t);
40
+ if (Object.getOwnPropertySymbols) {
41
+ var i = Object.getOwnPropertySymbols(e);
42
+ for (n = 0; n < i.length; n++) r = i[n], t.indexOf(r) >= 0 || Object.prototype.propertyIsEnumerable.call(e, r) && (o[r] = e[r]);
43
+ }
44
+ return o;
45
+ }
46
+ function fe(e, t) {
47
+ (t == null || t > e.length) && (t = e.length);
48
+ for (var r = 0, n = new Array(t); r < t; r++) n[r] = e[r];
49
+ return n;
50
+ }
51
+ function Pe(e, t, r) {
52
+ return t in e ? Object.defineProperty(e, t, { value: r, enumerable: !0, configurable: !0, writable: !0 }) : e[t] = r, e;
53
+ }
54
+ function ge(e, t) {
55
+ var r = Object.keys(e);
56
+ if (Object.getOwnPropertySymbols) {
57
+ var n = Object.getOwnPropertySymbols(e);
58
+ t && (n = n.filter(function(o) {
59
+ return Object.getOwnPropertyDescriptor(e, o).enumerable;
60
+ })), r.push.apply(r, n);
61
+ }
62
+ return r;
63
+ }
64
+ function pe(e) {
65
+ for (var t = 1; t < arguments.length; t++) {
66
+ var r = arguments[t] != null ? arguments[t] : {};
67
+ t % 2 ? ge(Object(r), !0).forEach(function(n) {
68
+ Pe(e, n, r[n]);
69
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(r)) : ge(Object(r)).forEach(function(n) {
70
+ Object.defineProperty(e, n, Object.getOwnPropertyDescriptor(r, n));
71
+ });
72
+ }
73
+ return e;
74
+ }
75
+ function V(e) {
76
+ return function t() {
77
+ for (var r = this, n = arguments.length, o = new Array(n), i = 0; i < n; i++) o[i] = arguments[i];
78
+ return o.length >= e.length ? e.apply(this, o) : function() {
79
+ for (var c = arguments.length, a = new Array(c), s = 0; s < c; s++) a[s] = arguments[s];
80
+ return t.apply(r, [].concat(o, a));
81
+ };
82
+ };
83
+ }
84
+ function F(e) {
85
+ return {}.toString.call(e).includes("Object");
86
+ }
87
+ function L(e) {
88
+ return typeof e == "function";
89
+ }
90
+ var P = V(function(e, t) {
91
+ throw new Error(e[t] || e.default);
92
+ })({ 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" }), U = { changes: function(e, t) {
93
+ return F(t) || P("changeType"), Object.keys(t).some(function(r) {
94
+ return n = e, o = r, !Object.prototype.hasOwnProperty.call(n, o);
95
+ var n, o;
96
+ }) && P("changeField"), t;
97
+ }, selector: function(e) {
98
+ L(e) || P("selectorType");
99
+ }, handler: function(e) {
100
+ L(e) || F(e) || P("handlerType"), F(e) && Object.values(e).some(function(t) {
101
+ return !L(t);
102
+ }) && P("handlersType");
103
+ }, initial: function(e) {
104
+ var t;
105
+ e || P("initialIsRequired"), F(e) || P("initialType"), t = e, Object.keys(t).length || P("initialContent");
106
+ } };
107
+ function Se(e, t) {
108
+ return L(t) ? t(e.current) : t;
109
+ }
110
+ function ke(e, t) {
111
+ return e.current = pe(pe({}, e.current), t), t;
112
+ }
113
+ function xe(e, t, r) {
114
+ return L(t) ? t(e.current) : Object.keys(r).forEach(function(n) {
115
+ var o;
116
+ return (o = t[n]) === null || o === void 0 ? void 0 : o.call(t, e.current[n]);
117
+ }), r;
118
+ }
119
+ var Ie = { create: function(e) {
120
+ var t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
121
+ U.initial(e), U.handler(t);
122
+ var r = { current: e }, n = V(xe)(r, t), o = V(ke)(r), i = V(U.changes)(e), c = V(Se)(r);
123
+ return [function() {
124
+ var a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : function(s) {
125
+ return s;
126
+ };
127
+ return U.selector(a), a(r.current);
128
+ }, function(a) {
129
+ (function() {
130
+ for (var s = arguments.length, g = new Array(s), j = 0; j < s; j++) g[j] = arguments[j];
131
+ return function(v) {
132
+ return g.reduceRight(function(I, T) {
133
+ return T(I);
134
+ }, v);
135
+ };
136
+ })(n, o, i, c)(a);
137
+ }];
138
+ } }, Z, ve = { 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!
139
+ You are using deprecated way of configuration.
140
+
141
+ Instead of using
142
+ monaco.config({ urls: { monacoBase: '...' } })
143
+ use
144
+ monaco.config({ paths: { vs: '...' } })
145
+
146
+ For more please check the link https://github.com/suren-atoyan/monaco-loader#config
147
+ ` }, he = (Z = function(e, t) {
148
+ throw new Error(e[t] || e.default);
149
+ }, function e() {
150
+ for (var t = this, r = arguments.length, n = new Array(r), o = 0; o < r; o++) n[o] = arguments[o];
151
+ return n.length >= Z.length ? Z.apply(this, n) : function() {
152
+ for (var i = arguments.length, c = new Array(i), a = 0; a < i; a++) c[a] = arguments[a];
153
+ return e.apply(t, [].concat(n, c));
154
+ };
155
+ })(ve), Te = { config: function(e) {
156
+ var t;
157
+ return e || he("configIsRequired"), t = e, {}.toString.call(t).includes("Object") || he("configType"), e.urls ? (console.warn(ve.deprecation), { paths: { vs: e.urls.monacoBase } }) : e;
158
+ } };
159
+ function ye(e, t) {
160
+ return Object.keys(t).forEach(function(r) {
161
+ t[r] instanceof Object && e[r] && Object.assign(t[r], ye(e[r], t[r]));
162
+ }), de(de({}, e), t);
163
+ }
164
+ var Ae = { type: "cancelation", msg: "operation is manually canceled" };
165
+ function ee(e) {
166
+ var t = !1, r = new Promise(function(n, o) {
167
+ e.then(function(i) {
168
+ return t ? o(Ae) : n(i);
169
+ }), e.catch(o);
170
+ });
171
+ return r.cancel = function() {
172
+ return t = !0;
173
+ }, r;
174
+ }
175
+ var te, re, Ce = Ie.create({ config: { paths: { vs: "https://cdn.jsdelivr.net/npm/monaco-editor@0.52.2/min/vs" } }, isInitialized: !1, resolve: null, reject: null, monaco: null }), be = (re = 2, function(e) {
176
+ if (Array.isArray(e)) return e;
177
+ }(te = Ce) || function(e, t) {
178
+ if (typeof Symbol < "u" && Symbol.iterator in Object(e)) {
179
+ var r = [], n = !0, o = !1, i = void 0;
180
+ try {
181
+ for (var c, a = e[Symbol.iterator](); !(n = (c = a.next()).done) && (r.push(c.value), !t || r.length !== t); n = !0) ;
182
+ } catch (s) {
183
+ o = !0, i = s;
184
+ } finally {
185
+ try {
186
+ n || a.return == null || a.return();
187
+ } finally {
188
+ if (o) throw i;
189
+ }
190
+ }
191
+ return r;
192
+ }
193
+ }(te, re) || function(e, t) {
194
+ if (e) {
195
+ if (typeof e == "string") return fe(e, t);
196
+ var r = Object.prototype.toString.call(e).slice(8, -1);
197
+ return r === "Object" && e.constructor && (r = e.constructor.name), r === "Map" || r === "Set" ? Array.from(e) : r === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r) ? fe(e, t) : void 0;
198
+ }
199
+ }(te, re) || function() {
200
+ throw new TypeError(`Invalid attempt to destructure non-iterable instance.
201
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`);
202
+ }()), z = be[0], W = be[1];
203
+ function De(e) {
204
+ return document.body.appendChild(e);
205
+ }
206
+ function Ve(e) {
207
+ var t, r, n = z(function(i) {
208
+ return { config: i.config, reject: i.reject };
209
+ }), o = (t = "".concat(n.config.paths.vs, "/loader.js"), r = document.createElement("script"), t && (r.src = t), r);
210
+ return o.onload = function() {
211
+ return e();
212
+ }, o.onerror = n.reject, o;
213
+ }
214
+ function Le() {
215
+ var e = z(function(r) {
216
+ return { config: r.config, resolve: r.resolve, reject: r.reject };
217
+ }), t = window.require;
218
+ t.config(e.config), t(["vs/editor/editor.main"], function(r) {
219
+ we(r), e.resolve(r);
220
+ }, function(r) {
221
+ e.reject(r);
222
+ });
223
+ }
224
+ function we(e) {
225
+ z().monaco || W({ monaco: e });
226
+ }
227
+ var ne = new Promise(function(e, t) {
228
+ return W({ resolve: e, reject: t });
229
+ }), Y = { config: function(e) {
230
+ var t = Te.config(e), r = t.monaco, n = Ee(t, ["monaco"]);
231
+ W(function(o) {
232
+ return { config: ye(o.config, n), monaco: r };
233
+ });
234
+ }, init: function() {
235
+ var e = z(function(t) {
236
+ return { monaco: t.monaco, isInitialized: t.isInitialized, resolve: t.resolve };
237
+ });
238
+ if (!e.isInitialized) {
239
+ if (W({ isInitialized: !0 }), e.monaco) return e.resolve(e.monaco), ee(ne);
240
+ if (window.monaco && window.monaco.editor) return we(window.monaco), e.resolve(window.monaco), ee(ne);
241
+ (function() {
242
+ for (var t = arguments.length, r = new Array(t), n = 0; n < t; n++) r[n] = arguments[n];
243
+ return function(o) {
244
+ return r.reduceRight(function(i, c) {
245
+ return c(i);
246
+ }, o);
247
+ };
248
+ })(De, Ve)(Le);
249
+ }
250
+ return ee(ne);
251
+ }, __getMonacoInstance: function() {
252
+ return z(function(e) {
253
+ return e.monaco;
254
+ });
255
+ } }, oe = { wrapper: { display: "flex", position: "relative", textAlign: "initial" }, fullWidth: { width: "100%" }, hide: { display: "none" } }, Re = { container: { display: "flex", height: "100%", width: "100%", justifyContent: "center", alignItems: "center" } }, qe = function({ children: e }) {
256
+ return x.createElement("div", { style: Re.container }, e);
257
+ }, Oe = ce(function({ width: e, height: t, isEditorReady: r, loading: n, _ref: o, className: i, wrapperProps: c }) {
258
+ return x.createElement("section", { style: { ...oe.wrapper, width: e, height: t }, ...c }, !r && x.createElement(qe, null, n), x.createElement("div", { ref: o, style: { ...oe.fullWidth, ...!r && oe.hide }, className: i }));
259
+ }), ae = function(e) {
260
+ M(e, []);
261
+ }, O = function(e, t, r = !0) {
262
+ let n = h(!0);
263
+ M(n.current || !r ? () => {
264
+ n.current = !1;
265
+ } : e, t);
266
+ };
267
+ function R() {
268
+ }
269
+ function k(e, t, r, n) {
270
+ return function(o, i) {
271
+ return o.editor.getModel(me(o, i));
272
+ }(e, n) || function(o, i, c, a) {
273
+ return o.editor.createModel(i, c, a ? me(o, a) : void 0);
274
+ }(e, t, r, n);
275
+ }
276
+ function me(e, t) {
277
+ return e.Uri.parse(t);
278
+ }
279
+ var ze = function({ original: e, modified: t, language: r, originalLanguage: n, modifiedLanguage: o, originalModelPath: i, modifiedModelPath: c, keepCurrentOriginalModel: a = !1, keepCurrentModifiedModel: s = !1, theme: g = "light", loading: j = "Loading...", options: v = {}, height: I = "100%", width: T = "100%", className: $, wrapperProps: G = {}, beforeMount: H = R, onMount: J = R }) {
280
+ let [w, A] = q(!1), [C, p] = q(!0), m = h(null), d = h(null), D = h(null), y = h(J), u = h(H), S = h(!1);
281
+ ae(() => {
282
+ let l = Y.init();
283
+ return l.then((f) => (d.current = f) && p(!1)).catch((f) => f?.type !== "cancelation" && console.error("Monaco initialization: error:", f)), () => m.current ? function() {
284
+ let f = m.current?.getModel();
285
+ a || f?.original?.dispose(), s || f?.modified?.dispose(), m.current?.dispose();
286
+ }() : l.cancel();
287
+ }), O(() => {
288
+ if (m.current && d.current) {
289
+ let l = m.current.getOriginalEditor(), f = k(d.current, e || "", n || r || "text", i || "");
290
+ f !== l.getModel() && l.setModel(f);
291
+ }
292
+ }, [i], w), O(() => {
293
+ if (m.current && d.current) {
294
+ let l = m.current.getModifiedEditor(), f = k(d.current, t || "", o || r || "text", c || "");
295
+ f !== l.getModel() && l.setModel(f);
296
+ }
297
+ }, [c], w), O(() => {
298
+ let l = m.current.getModifiedEditor();
299
+ l.getOption(d.current.editor.EditorOption.readOnly) ? l.setValue(t || "") : t !== l.getValue() && (l.executeEdits("", [{ range: l.getModel().getFullModelRange(), text: t || "", forceMoveMarkers: !0 }]), l.pushUndoStop());
300
+ }, [t], w), O(() => {
301
+ m.current?.getModel()?.original.setValue(e || "");
302
+ }, [e], w), O(() => {
303
+ let { original: l, modified: f } = m.current.getModel();
304
+ d.current.editor.setModelLanguage(l, n || r || "text"), d.current.editor.setModelLanguage(f, o || r || "text");
305
+ }, [r, n, o], w), O(() => {
306
+ d.current?.editor.setTheme(g);
307
+ }, [g], w), O(() => {
308
+ m.current?.updateOptions(v);
309
+ }, [v], w);
310
+ let _ = ie(() => {
311
+ if (!d.current) return;
312
+ u.current(d.current);
313
+ let l = k(d.current, e || "", n || r || "text", i || ""), f = k(d.current, t || "", o || r || "text", c || "");
314
+ m.current?.setModel({ original: l, modified: f });
315
+ }, [r, t, o, e, n, i, c]), N = ie(() => {
316
+ !S.current && D.current && (m.current = d.current.editor.createDiffEditor(D.current, { automaticLayout: !0, ...v }), _(), d.current?.editor.setTheme(g), A(!0), S.current = !0);
317
+ }, [v, g, _]);
318
+ return M(() => {
319
+ w && y.current(m.current, d.current);
320
+ }, [w]), M(() => {
321
+ !C && !w && N();
322
+ }, [C, w, N]), x.createElement(Oe, { width: T, height: I, isEditorReady: w, loading: j, _ref: D, className: $, wrapperProps: G });
323
+ }, Be = ce(ze), We = function() {
324
+ let [e, t] = q(Y.__getMonacoInstance());
325
+ return ae(() => {
326
+ let r;
327
+ return e || (r = Y.init(), r.then((n) => {
328
+ t(n);
329
+ })), () => r?.cancel();
330
+ }), e;
331
+ }, _e = function(e) {
332
+ let t = h();
333
+ return M(() => {
334
+ t.current = e;
335
+ }, [e]), t.current;
336
+ }, B = /* @__PURE__ */ new Map(), Ne = function({ defaultValue: e, defaultLanguage: t, defaultPath: r, value: n, language: o, path: i, theme: c = "light", line: a, loading: s = "Loading...", options: g = {}, overrideServices: j = {}, saveViewState: v = !0, keepCurrentModel: I = !1, width: T = "100%", height: $ = "100%", className: G, wrapperProps: H = {}, beforeMount: J = R, onMount: w = R, onChange: A, onValidate: C = R }) {
337
+ let [p, m] = q(!1), [d, D] = q(!0), y = h(null), u = h(null), S = h(null), _ = h(w), N = h(J), l = h(), f = h(n), je = _e(i), ue = h(!1), K = h(!1);
338
+ ae(() => {
339
+ let b = Y.init();
340
+ return b.then((E) => (y.current = E) && D(!1)).catch((E) => E?.type !== "cancelation" && console.error("Monaco initialization: error:", E)), () => u.current ? (l.current?.dispose(), I ? v && B.set(i, u.current.saveViewState()) : u.current.getModel()?.dispose(), void u.current.dispose()) : b.cancel();
341
+ }), O(() => {
342
+ let b = k(y.current, e || n || "", t || o || "", i || r || "");
343
+ b !== u.current?.getModel() && (v && B.set(je, u.current?.saveViewState()), u.current?.setModel(b), v && u.current?.restoreViewState(B.get(i)));
344
+ }, [i], p), O(() => {
345
+ u.current?.updateOptions(g);
346
+ }, [g], p), O(() => {
347
+ !u.current || n === void 0 || (u.current.getOption(y.current.editor.EditorOption.readOnly) ? u.current.setValue(n) : n !== u.current.getValue() && (K.current = !0, u.current.executeEdits("", [{ range: u.current.getModel().getFullModelRange(), text: n, forceMoveMarkers: !0 }]), u.current.pushUndoStop(), K.current = !1));
348
+ }, [n], p), O(() => {
349
+ let b = u.current?.getModel();
350
+ b && o && y.current?.editor.setModelLanguage(b, o);
351
+ }, [o], p), O(() => {
352
+ a !== void 0 && u.current?.revealLine(a);
353
+ }, [a], p), O(() => {
354
+ y.current?.editor.setTheme(c);
355
+ }, [c], p);
356
+ let le = ie(() => {
357
+ if (S.current && y.current && !ue.current) {
358
+ N.current(y.current);
359
+ let b = i || r, E = k(y.current, n || e || "", t || o || "", b || "");
360
+ u.current = y.current?.editor.create(S.current, { model: E, automaticLayout: !0, ...g }, j), v && u.current.restoreViewState(B.get(b)), y.current.editor.setTheme(c), a !== void 0 && u.current.revealLine(a), m(!0), ue.current = !0;
361
+ }
362
+ }, [e, t, r, n, o, i, g, j, v, c, a]);
363
+ return M(() => {
364
+ p && _.current(u.current, y.current);
365
+ }, [p]), M(() => {
366
+ !d && !p && le();
367
+ }, [d, p, le]), f.current = n, M(() => {
368
+ p && A && (l.current?.dispose(), l.current = u.current?.onDidChangeModelContent((b) => {
369
+ K.current || A(u.current.getValue(), b);
370
+ }));
371
+ }, [p, A]), M(() => {
372
+ if (p) {
373
+ let b = y.current.editor.onDidChangeMarkers((E) => {
374
+ let Q = u.current.getModel()?.uri;
375
+ if (Q && E.find((X) => X.path === Q.path)) {
376
+ let X = y.current.editor.getModelMarkers({ resource: Q });
377
+ C?.(X);
378
+ }
379
+ });
380
+ return () => {
381
+ b?.dispose();
382
+ };
383
+ }
384
+ return () => {
385
+ };
386
+ }, [p, C]), x.createElement(Oe, { width: T, height: $, isEditorReady: p, loading: s, _ref: S, className: G, wrapperProps: H });
387
+ }, Fe = ce(Ne), Ye = Fe;
388
+ export {
389
+ Be as DiffEditor,
390
+ Fe as Editor,
391
+ Ye as default,
392
+ Y as loader,
393
+ We as useMonaco
394
+ };