@electric-sql/pglite-repl 0.0.1-alpha.0

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,720 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("react/jsx-runtime"), require("react"), require("@uiw/react-codemirror"), require("@codemirror/commands"), require("@codemirror/view"), require("@codemirror/lang-sql"), require("@codemirror/language"), require("psql-describe"), require("@uiw/codemirror-theme-xcode")) : typeof define === "function" && define.amd ? define(["exports", "react/jsx-runtime", "react", "@uiw/react-codemirror", "@codemirror/commands", "@codemirror/view", "@codemirror/lang-sql", "@codemirror/language", "psql-describe", "@uiw/codemirror-theme-xcode"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.PGliteREPL = {}, global.jsxRuntime, global.react, global.CodeMirror, global.commands, global.view, global.langSql, global.language, global.psqlDescribe, global.codemirrorThemeXcode));
3
+ })(this, function(exports2, jsxRuntime, react, CodeMirror, commands, view, langSql, language, psqlDescribe, codemirrorThemeXcode) {
4
+ "use strict";
5
+ const describeCompletions = [
6
+ {
7
+ label: "\\d",
8
+ type: "function",
9
+ displayLabel: "\\d[S+] [ pattern ]",
10
+ detail: "PSQL Describe"
11
+ },
12
+ {
13
+ label: "\\da",
14
+ type: "function",
15
+ displayLabel: "\\da[S] [ pattern ]",
16
+ detail: "Lists aggregate functions"
17
+ },
18
+ {
19
+ label: "\\dA",
20
+ type: "function",
21
+ displayLabel: "\\dA[+] [ pattern ]",
22
+ detail: "Lists access methods"
23
+ },
24
+ {
25
+ label: "\\dAc",
26
+ type: "function",
27
+ displayLabel: "\\dAc[+] [access-method-pattern [input-type-pattern]]",
28
+ detail: "Lists operator classes"
29
+ },
30
+ {
31
+ label: "\\dAf",
32
+ type: "function",
33
+ displayLabel: "\\dAf[+] [access-method-pattern [input-type-pattern]]",
34
+ detail: "Lists operator families"
35
+ },
36
+ {
37
+ label: "\\dAo",
38
+ type: "function",
39
+ displayLabel: "\\dAo[+] [access-method-pattern [operator-family-pattern]]",
40
+ detail: "Lists operators associated with operator families"
41
+ },
42
+ {
43
+ label: "\\dAp",
44
+ type: "function",
45
+ displayLabel: "\\dAp[+] [access-method-pattern [operator-family-pattern]]",
46
+ detail: "Lists support functions associated with operator families"
47
+ },
48
+ {
49
+ label: "\\db",
50
+ type: "function",
51
+ displayLabel: "\\db[+] [ pattern ]",
52
+ detail: "Lists tablespaces"
53
+ },
54
+ {
55
+ label: "\\dc",
56
+ type: "function",
57
+ displayLabel: "\\dc[S+] [ pattern ]",
58
+ detail: "Lists conversions between character-set encodings"
59
+ },
60
+ {
61
+ label: "\\dconfig",
62
+ type: "function",
63
+ displayLabel: "\\dconfig[+] [ pattern ]",
64
+ detail: "Lists server configuration parameters and their values"
65
+ },
66
+ {
67
+ label: "\\dC",
68
+ type: "function",
69
+ displayLabel: "\\dC[+] [ pattern ]",
70
+ detail: "Lists type casts"
71
+ },
72
+ {
73
+ label: "\\dd",
74
+ type: "function",
75
+ displayLabel: "\\dd[S] [ pattern ]",
76
+ detail: "Shows the descriptions of objects of type constraint, operator class, operator family, rule, and trigger"
77
+ },
78
+ {
79
+ label: "\\dD",
80
+ type: "function",
81
+ displayLabel: "\\dD[S+] [ pattern ]",
82
+ detail: "Lists domains"
83
+ },
84
+ {
85
+ label: "\\ddp",
86
+ type: "function",
87
+ displayLabel: "\\ddp [ pattern ]",
88
+ detail: "Lists default access privilege settings"
89
+ },
90
+ {
91
+ label: "\\dE",
92
+ type: "function",
93
+ displayLabel: "\\dE[S+] [ pattern ]",
94
+ detail: "Lists foreign tables"
95
+ },
96
+ {
97
+ label: "\\di",
98
+ type: "function",
99
+ displayLabel: "\\di[S+] [ pattern ]",
100
+ detail: "Lists indexes"
101
+ },
102
+ {
103
+ label: "\\dm",
104
+ type: "function",
105
+ displayLabel: "\\dm[S+] [ pattern ]",
106
+ detail: "Lists materialized views"
107
+ },
108
+ {
109
+ label: "\\ds",
110
+ type: "function",
111
+ displayLabel: "\\ds[S+] [ pattern ]",
112
+ detail: "Lists sequences"
113
+ },
114
+ {
115
+ label: "\\dt",
116
+ type: "function",
117
+ displayLabel: "\\dt[S+] [ pattern ]",
118
+ detail: "Lists tables"
119
+ },
120
+ {
121
+ label: "\\dv",
122
+ type: "function",
123
+ displayLabel: "\\dv[S+] [ pattern ]",
124
+ detail: "Lists views"
125
+ },
126
+ {
127
+ label: "\\des",
128
+ type: "function",
129
+ displayLabel: "\\des[+] [ pattern ]",
130
+ detail: "Lists foreign servers"
131
+ },
132
+ {
133
+ label: "\\det",
134
+ type: "function",
135
+ displayLabel: "\\det[+] [ pattern ]",
136
+ detail: "Lists foreign tables"
137
+ },
138
+ {
139
+ label: "\\deu",
140
+ type: "function",
141
+ displayLabel: "\\deu[+] [ pattern ]",
142
+ detail: "Lists user mappings"
143
+ },
144
+ {
145
+ label: "\\dew",
146
+ type: "function",
147
+ displayLabel: "\\dew[+] [ pattern ]",
148
+ detail: "Lists foreign-data wrappers"
149
+ },
150
+ {
151
+ label: "\\df",
152
+ type: "function",
153
+ displayLabel: "\\df[anptwS+] [ pattern [ arg_pattern ... ] ]",
154
+ detail: "Lists functions"
155
+ },
156
+ {
157
+ label: "\\dF",
158
+ type: "function",
159
+ displayLabel: "\\dF[+] [ pattern ]",
160
+ detail: "Lists text search configurations"
161
+ },
162
+ {
163
+ label: "\\dFd",
164
+ type: "function",
165
+ displayLabel: "\\dFd[+] [ pattern ]",
166
+ detail: "Lists text search dictionaries"
167
+ },
168
+ {
169
+ label: "\\dFp",
170
+ type: "function",
171
+ displayLabel: "\\dFp[+] [ pattern ]",
172
+ detail: "Lists text search parsers"
173
+ },
174
+ {
175
+ label: "\\dFt",
176
+ type: "function",
177
+ displayLabel: "\\dFt[+] [ pattern ]",
178
+ detail: "Lists text search templates"
179
+ },
180
+ {
181
+ label: "\\dg",
182
+ type: "function",
183
+ displayLabel: "\\dg[S+] [ pattern ]",
184
+ detail: "Lists database roles"
185
+ },
186
+ {
187
+ label: "\\dl",
188
+ type: "function",
189
+ displayLabel: "\\dl[+] ",
190
+ detail: "List large objects"
191
+ },
192
+ {
193
+ label: "\\dL",
194
+ type: "function",
195
+ displayLabel: "\\dL[S+] [ pattern ]",
196
+ detail: "Lists procedural languages"
197
+ },
198
+ {
199
+ label: "\\dn",
200
+ type: "function",
201
+ displayLabel: "\\dn[S+] [ pattern ]",
202
+ detail: "Lists schemas"
203
+ },
204
+ {
205
+ label: "\\do",
206
+ type: "function",
207
+ displayLabel: "\\do[S+] [ pattern [ arg_pattern [ arg_pattern ] ] ]",
208
+ detail: "Lists operators with their operand and result types"
209
+ },
210
+ {
211
+ label: "\\dO",
212
+ type: "function",
213
+ displayLabel: "\\dO[S+] [ pattern ]",
214
+ detail: "Lists collations"
215
+ },
216
+ {
217
+ label: "\\dp",
218
+ type: "function",
219
+ displayLabel: "\\dp[S] [ pattern ]",
220
+ detail: "Lists tables, views and sequences with their associated access privileges"
221
+ },
222
+ {
223
+ label: "\\dP",
224
+ type: "function",
225
+ displayLabel: "\\dP[itn+] [ pattern ]",
226
+ detail: "Lists partitioned relations"
227
+ },
228
+ {
229
+ label: "\\drds",
230
+ type: "function",
231
+ displayLabel: "\\drds [ role-pattern [ database-pattern ] ]",
232
+ detail: "Lists defined configuration settings"
233
+ },
234
+ {
235
+ label: "\\drg",
236
+ type: "function",
237
+ displayLabel: "\\drg[S] [ pattern ]",
238
+ detail: "Lists information about each granted role membership"
239
+ },
240
+ {
241
+ label: "\\dRp",
242
+ type: "function",
243
+ displayLabel: "\\dRp[+] [ pattern ]",
244
+ detail: "Lists replication publications"
245
+ },
246
+ {
247
+ label: "\\dRs",
248
+ type: "function",
249
+ displayLabel: "\\dRs[+] [ pattern ]",
250
+ detail: "Lists replication subscriptions"
251
+ },
252
+ {
253
+ label: "\\dT",
254
+ type: "function",
255
+ displayLabel: "\\dT[S+] [ pattern ]",
256
+ detail: "Lists data types"
257
+ },
258
+ {
259
+ label: "\\du",
260
+ type: "function",
261
+ displayLabel: "\\du[S+] [ pattern ]",
262
+ detail: "Lists database roles"
263
+ },
264
+ {
265
+ label: "\\dx",
266
+ type: "function",
267
+ displayLabel: "\\dx[+] [ pattern ]",
268
+ detail: "Lists installed extensions"
269
+ },
270
+ {
271
+ label: "\\dX",
272
+ type: "function",
273
+ displayLabel: "\\dX [ pattern ]",
274
+ detail: "Lists extended statistics"
275
+ },
276
+ {
277
+ label: "\\dy",
278
+ type: "function",
279
+ displayLabel: "\\dy[+] [ pattern ]",
280
+ detail: "Lists event triggers"
281
+ }
282
+ ];
283
+ function describeCompletionsAutoComplete(context) {
284
+ const word = context.matchBefore(/\\\w*/);
285
+ if (!word || word.from === word.to) return null;
286
+ return {
287
+ from: word.from,
288
+ options: describeCompletions
289
+ };
290
+ }
291
+ function makeSqlExt(config = {}) {
292
+ let lang = config.dialect || langSql.PostgreSQL;
293
+ return new language.LanguageSupport(lang.language, [
294
+ // schemaCompletion(config),
295
+ config.schema ? lang.language.data.of({
296
+ autocomplete: langSql.schemaCompletionSource(config)
297
+ }) : [],
298
+ // keywordCompletion(lang, !!config.upperCaseKeywords)
299
+ lang.language.data.of({
300
+ autocomplete: langSql.keywordCompletionSource(lang, !!config.upperCaseKeywords)
301
+ }),
302
+ lang.language.data.of({
303
+ autocomplete: describeCompletionsAutoComplete
304
+ })
305
+ ]);
306
+ }
307
+ async function runQuery(query, pg) {
308
+ if (query.trim().toLowerCase().startsWith("\\")) {
309
+ return runDescribe(query, pg);
310
+ }
311
+ const start = performance.now();
312
+ try {
313
+ const result = await pg.exec(query, {
314
+ rowMode: "array"
315
+ });
316
+ const elapsed = performance.now() - start;
317
+ return {
318
+ query,
319
+ results: result,
320
+ time: elapsed
321
+ };
322
+ } catch (err) {
323
+ return {
324
+ query,
325
+ error: err.message,
326
+ time: performance.now() - start
327
+ };
328
+ }
329
+ }
330
+ async function runDescribe(query, pg) {
331
+ const start = performance.now();
332
+ let out;
333
+ let ret;
334
+ const { promise, cancel: _cancel } = psqlDescribe.describe(
335
+ query,
336
+ "postgres",
337
+ async (sql) => {
338
+ ret = (await pg.exec(sql, { rowMode: "array" }))[0];
339
+ return {
340
+ rows: ret.rows,
341
+ fields: ret.fields,
342
+ rowCount: ret.rows.length
343
+ };
344
+ },
345
+ (output) => {
346
+ out = output;
347
+ }
348
+ );
349
+ await promise;
350
+ const elapsed = performance.now() - start;
351
+ if (!out) {
352
+ return {
353
+ query,
354
+ error: "No output",
355
+ time: elapsed
356
+ };
357
+ } else if (typeof out === "string") {
358
+ if (out.startsWith("ERROR:")) {
359
+ return {
360
+ query,
361
+ error: out,
362
+ time: elapsed
363
+ };
364
+ } else {
365
+ return {
366
+ query,
367
+ text: out,
368
+ time: elapsed
369
+ };
370
+ }
371
+ } else {
372
+ return {
373
+ query,
374
+ text: out.title,
375
+ results: [ret],
376
+ time: elapsed
377
+ };
378
+ }
379
+ }
380
+ async function getSchema(pg) {
381
+ const ret = await pg.query(`
382
+ SELECT
383
+ table_schema AS schema,
384
+ table_name AS table,
385
+ array_agg(column_name) AS columns
386
+ FROM
387
+ information_schema.columns
388
+ GROUP BY
389
+ table_schema, table_name
390
+ ORDER BY
391
+ table_schema, table_name;
392
+ `);
393
+ const schema = {};
394
+ for (const row of ret.rows) {
395
+ schema[`${row.schema}.${row.table}`] = Array.isArray(row.columns) ? row.columns : row.columns.slice(1, -1).split(",");
396
+ }
397
+ return schema;
398
+ }
399
+ const tableRowIncrement = 100;
400
+ const maxCellLength = 200;
401
+ function cellClass(value) {
402
+ if (value === null) {
403
+ return "PGliteRepl-null";
404
+ } else if (typeof value === "number") {
405
+ return "PGliteRepl-number";
406
+ } else if (typeof value === "boolean") {
407
+ return "PGliteRepl-boolean";
408
+ } else {
409
+ return "";
410
+ }
411
+ }
412
+ function cellValue(value) {
413
+ let str;
414
+ if (value === null) {
415
+ str = "null";
416
+ } else if (typeof value === "number") {
417
+ str = value.toString();
418
+ } else if (typeof value === "boolean") {
419
+ str = value ? "true" : "false";
420
+ } else if (value instanceof Date) {
421
+ str = value.toISOString();
422
+ } else if (Array.isArray(value)) {
423
+ str = `[${value.map(cellValue).join(", ")}]`;
424
+ } else if (typeof value === "object") {
425
+ str = JSON.stringify(value);
426
+ } else if (ArrayBuffer.isView(value)) {
427
+ str = `${value.byteLength} bytes`;
428
+ } else {
429
+ str = value.toString();
430
+ }
431
+ return str.length > maxCellLength ? str.slice(0, maxCellLength) + "…" : str;
432
+ }
433
+ function ReplTable({ result }) {
434
+ const [maxRows, setMaxRows] = react.useState(tableRowIncrement);
435
+ const rows = result.rows.slice(0, maxRows);
436
+ react.useEffect(() => {
437
+ setMaxRows(tableRowIncrement);
438
+ }, [result]);
439
+ const showMore = () => {
440
+ setMaxRows((prev) => prev + tableRowIncrement);
441
+ };
442
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
443
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "PGliteRepl-table-scroll", children: /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "PGliteRepl-table", children: [
444
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsx("tr", { children: result.fields.map((col, i) => /* @__PURE__ */ jsxRuntime.jsx("th", { children: col.name }, i)) }) }),
445
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: rows.map((row, i) => /* @__PURE__ */ jsxRuntime.jsx("tr", { children: row.map((col, j) => /* @__PURE__ */ jsxRuntime.jsx("td", { className: cellClass(col), children: cellValue(col) }, j)) }, i)) })
446
+ ] }) }),
447
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "PGliteRepl-table-row-count", children: [
448
+ result.rows.length > maxRows ? `${maxRows} of ` : "",
449
+ result.rows.length,
450
+ " rows",
451
+ " ",
452
+ result.rows.length > maxRows && /* @__PURE__ */ jsxRuntime.jsx(
453
+ "a",
454
+ {
455
+ href: "",
456
+ onClick: (e) => {
457
+ e.preventDefault();
458
+ showMore();
459
+ },
460
+ children: "Show more"
461
+ }
462
+ )
463
+ ] })
464
+ ] });
465
+ }
466
+ function OutLine({ result }) {
467
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "PGliteRepl-line", children: result.fields.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(ReplTable, { result }) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "PGliteRepl-null", children: "null" }) });
468
+ }
469
+ function ReplResponse({
470
+ response,
471
+ showTime
472
+ }) {
473
+ var _a;
474
+ let out;
475
+ if (response.error) {
476
+ out = /* @__PURE__ */ jsxRuntime.jsx("div", { className: "PGliteRepl-line PGliteRepl-error", children: response.error });
477
+ } else {
478
+ out = /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: (_a = response.results) == null ? void 0 : _a.map((result, i) => /* @__PURE__ */ jsxRuntime.jsx(OutLine, { result }, i)) });
479
+ }
480
+ return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
481
+ /* @__PURE__ */ jsxRuntime.jsx("pre", { className: "PGliteRepl-line PGliteRepl-query", children: response.query }),
482
+ response.text && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "PGliteRepl-line PGliteRepl-text", children: response.text }),
483
+ out,
484
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "PGliteRepl-divider", children: [
485
+ /* @__PURE__ */ jsxRuntime.jsx("hr", {}),
486
+ showTime && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "PGliteRepl-time", children: [
487
+ response.time.toFixed(1),
488
+ "ms"
489
+ ] })
490
+ ] })
491
+ ] });
492
+ }
493
+ const baseKeymap = commands.defaultKeymap.filter((key) => key.key !== "Enter");
494
+ function Repl({
495
+ pg,
496
+ border = false,
497
+ lightTheme = codemirrorThemeXcode.xcodeLight,
498
+ darkTheme = codemirrorThemeXcode.xcodeDark,
499
+ theme = "auto",
500
+ showTime = false,
501
+ disableUpdateSchema = false
502
+ }) {
503
+ const [value, setValue] = react.useState("");
504
+ const valueNoHistory = react.useRef("");
505
+ const [loading, setLoading] = react.useState(true);
506
+ const [output, setOutput] = react.useState([]);
507
+ const outputRef = react.useRef(null);
508
+ const [schema, setSchema] = react.useState({});
509
+ const historyPos = react.useRef(-1);
510
+ const rcm = react.useRef(null);
511
+ const [themeToUse, setThemeToUse] = react.useState(
512
+ theme === "dark" ? darkTheme : lightTheme
513
+ );
514
+ const [styles, setStyles] = react.useState({});
515
+ react.useEffect(() => {
516
+ let ignore = false;
517
+ const init = async () => {
518
+ await pg.waitReady;
519
+ if (ignore) return;
520
+ setLoading(false);
521
+ };
522
+ setLoading(true);
523
+ init();
524
+ return () => {
525
+ ignore = true;
526
+ };
527
+ }, [pg]);
528
+ react.useEffect(() => {
529
+ if (theme === "auto") {
530
+ const systemTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
531
+ setThemeToUse(systemTheme === "dark" ? darkTheme : lightTheme);
532
+ const listener = (e) => {
533
+ setThemeToUse(e.matches ? darkTheme : lightTheme);
534
+ setTimeout(() => {
535
+ extractStyles();
536
+ }, 0);
537
+ };
538
+ window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", listener);
539
+ return () => {
540
+ window.matchMedia("(prefers-color-scheme: dark)").removeEventListener("change", listener);
541
+ };
542
+ } else {
543
+ setThemeToUse(theme === "dark" ? darkTheme : lightTheme);
544
+ setTimeout(() => {
545
+ extractStyles();
546
+ }, 0);
547
+ }
548
+ }, [theme, lightTheme, darkTheme]);
549
+ const onChange = react.useCallback((val, _viewUpdate) => {
550
+ extractStyles();
551
+ setValue(val);
552
+ if (historyPos.current === -1) {
553
+ valueNoHistory.current = val;
554
+ }
555
+ }, []);
556
+ const extensions = react.useMemo(
557
+ () => [
558
+ view.keymap.of([
559
+ {
560
+ key: "Enter",
561
+ preventDefault: true,
562
+ run: () => {
563
+ if (value.trim() === "") return false;
564
+ runQuery(value, pg).then((response) => {
565
+ setOutput((prev) => [...prev, response]);
566
+ if (outputRef.current) {
567
+ setTimeout(() => {
568
+ outputRef.current.scrollTop = outputRef.current.scrollHeight;
569
+ }, 0);
570
+ }
571
+ if (!disableUpdateSchema) {
572
+ getSchema(pg).then(setSchema);
573
+ }
574
+ });
575
+ historyPos.current = -1;
576
+ valueNoHistory.current = "";
577
+ setValue("");
578
+ return true;
579
+ }
580
+ },
581
+ {
582
+ key: "ArrowUp",
583
+ run: (view2) => {
584
+ const state = view2.state;
585
+ const cursorLine = state.doc.lineAt(
586
+ state.selection.main.head
587
+ ).number;
588
+ if (cursorLine === 1) {
589
+ const currentPos = historyPos.current;
590
+ historyPos.current++;
591
+ if (historyPos.current >= output.length) {
592
+ historyPos.current = output.length - 1;
593
+ }
594
+ if (historyPos.current < -1) {
595
+ historyPos.current = -1;
596
+ }
597
+ if (historyPos.current === currentPos) return true;
598
+ if (historyPos.current === -1) {
599
+ setValue(valueNoHistory.current);
600
+ } else {
601
+ setValue(output[output.length - historyPos.current - 1].query);
602
+ }
603
+ return true;
604
+ }
605
+ return false;
606
+ }
607
+ },
608
+ {
609
+ key: "ArrowDown",
610
+ run: (view2) => {
611
+ const state = view2.state;
612
+ const cursorLine = state.doc.lineAt(
613
+ state.selection.main.head
614
+ ).number;
615
+ const lastLine = state.doc.lines;
616
+ if (cursorLine === lastLine) {
617
+ const currentPos = historyPos.current;
618
+ historyPos.current--;
619
+ if (historyPos.current >= output.length) {
620
+ historyPos.current = output.length - 1;
621
+ }
622
+ if (historyPos.current < -1) {
623
+ historyPos.current = -1;
624
+ }
625
+ if (historyPos.current === currentPos) return true;
626
+ if (historyPos.current === -1) {
627
+ setValue(valueNoHistory.current);
628
+ } else {
629
+ setValue(output[output.length - historyPos.current - 1].query);
630
+ }
631
+ return true;
632
+ }
633
+ return false;
634
+ }
635
+ },
636
+ ...baseKeymap
637
+ ]),
638
+ makeSqlExt({
639
+ dialect: langSql.PostgreSQL,
640
+ schema,
641
+ tables: [
642
+ {
643
+ label: "d",
644
+ displayLabel: "\\d"
645
+ }
646
+ ],
647
+ defaultSchema: "public"
648
+ })
649
+ ],
650
+ [pg, schema, value, output]
651
+ );
652
+ const extractStyles = () => {
653
+ var _a;
654
+ const cmEditorEl = (_a = rcm.current) == null ? void 0 : _a.editor.querySelector(".cm-editor");
655
+ const gutterEl = cmEditorEl.querySelector(".cm-gutters");
656
+ const cmEditorElComputedStyles = window.getComputedStyle(cmEditorEl);
657
+ const foregroundColor = cmEditorElComputedStyles.color;
658
+ const backgroundColor = cmEditorElComputedStyles.backgroundColor;
659
+ const gutterElComputedStyles = window.getComputedStyle(gutterEl);
660
+ const gutterBorder = gutterElComputedStyles.borderRight;
661
+ const borderWidth = parseInt(gutterElComputedStyles.borderRightWidth) || 0;
662
+ const borderColor = borderWidth ? gutterElComputedStyles.borderRightColor : foregroundColor.replace("rgb", "rgba").replace(")", ", 0.15)");
663
+ const border2 = borderWidth ? gutterElComputedStyles.borderRight : `1px solid ${borderColor}`;
664
+ setStyles({
665
+ "--PGliteRepl-foreground-color": foregroundColor,
666
+ "--PGliteRepl-background-color": backgroundColor,
667
+ "--PGliteRepl-border": border2,
668
+ "--PGliteRepl-gutter-border": gutterBorder,
669
+ "--PGliteRepl-border-color": borderColor
670
+ });
671
+ };
672
+ return /* @__PURE__ */ jsxRuntime.jsxs(
673
+ "div",
674
+ {
675
+ className: `
676
+ PGliteRepl-root
677
+ ${border ? "PGliteRepl-root-border" : ""}
678
+ `,
679
+ style: styles,
680
+ children: [
681
+ /* @__PURE__ */ jsxRuntime.jsxs(
682
+ "div",
683
+ {
684
+ className: "PGliteRepl-output",
685
+ ref: (ref) => outputRef.current = ref,
686
+ children: [
687
+ loading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "PGliteRepl-loading-msg", children: "Loading..." }),
688
+ output.map((response, i) => /* @__PURE__ */ jsxRuntime.jsx("div", { children: /* @__PURE__ */ jsxRuntime.jsx(ReplResponse, { response: response || [], showTime }) }, i))
689
+ ]
690
+ }
691
+ ),
692
+ /* @__PURE__ */ jsxRuntime.jsx(
693
+ CodeMirror,
694
+ {
695
+ ref: rcm,
696
+ className: `PGliteRepl-input ${loading ? "PGliteRepl-input-loading" : ""}`,
697
+ width: "100%",
698
+ value,
699
+ basicSetup: {
700
+ defaultKeymap: false
701
+ },
702
+ extensions,
703
+ theme: themeToUse,
704
+ onChange,
705
+ editable: !loading,
706
+ onCreateEditor: () => {
707
+ extractStyles();
708
+ setTimeout(extractStyles, 0);
709
+ getSchema(pg).then(setSchema);
710
+ }
711
+ }
712
+ )
713
+ ]
714
+ }
715
+ );
716
+ }
717
+ exports2.Repl = Repl;
718
+ Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
719
+ });
720
+ //# sourceMappingURL=Repl.umd.cjs.map