lone-format 0.14.0 → 0.16.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.
@@ -1,1006 +0,0 @@
1
- import { defineComponent as H, computed as q, resolveComponent as Q, createElementBlock as S, openBlock as N, createElementVNode as _, createCommentVNode as G, normalizeClass as $, Fragment as A, renderList as P, createBlock as W, useCssVars as z, ref as R, watch as V, toDisplayString as Y } from "vue";
2
- import { format as D } from "sql-formatter";
3
- import { _ as F } from "./_plugin-vue_export-helper-CHgC5LLL.js";
4
- const X = {
5
- name: "github-light",
6
- colors: {
7
- // 背景色
8
- background: "#ffffff",
9
- surfaceBackground: "#f6f8fa",
10
- hoverBackground: "#f3f4f6",
11
- // 边框色
12
- border: "#d0d7de",
13
- // 文本色
14
- text: "#24292f",
15
- textSecondary: "#57606a",
16
- // 按钮样式
17
- buttonBackground: "#f6f8fa",
18
- buttonBackgroundHover: "#f3f4f6",
19
- buttonBorder: "#d0d7de",
20
- buttonText: "#24292f",
21
- buttonPrimary: "#1f883d",
22
- buttonPrimaryHover: "#1a7f37",
23
- // 状态指示
24
- success: "#1f883d",
25
- successBackground: "#dafbe1",
26
- error: "#cf222e",
27
- errorBackground: "#ffebe9",
28
- // SQL 语法高亮
29
- sqlKeyword: "#cf222e",
30
- // 关键字 - 红色
31
- sqlFunction: "#8250df",
32
- // 函数 - 紫色
33
- sqlString: "#0a3069",
34
- // 字符串 - 深蓝
35
- sqlNumber: "#0550ae",
36
- // 数字 - 蓝色
37
- sqlComment: "#6e7781",
38
- // 注释 - 灰色
39
- sqlOperator: "#cf222e",
40
- // 操作符 - 红色
41
- sqlIdentifier: "#24292f",
42
- // 标识符 - 黑色
43
- sqlPunctuation: "#24292f",
44
- // 标点 - 黑色
45
- // 折叠效果
46
- collapsedBackground: "#ddf4ff",
47
- // 折叠信息背景色 - 浅蓝
48
- collapsedText: "#0969da",
49
- // 折叠信息文本色 - 蓝色
50
- // 缩进指示线
51
- indentLine: "#d0d7de"
52
- // 对齐线 - 灰色
53
- }
54
- }, Z = {
55
- name: "github-dark",
56
- colors: {
57
- // 背景色
58
- background: "#0d1117",
59
- surfaceBackground: "#161b22",
60
- hoverBackground: "#30363d",
61
- // 边框色
62
- border: "#30363d",
63
- // 文本色
64
- text: "#c9d1d9",
65
- textSecondary: "#8b949e",
66
- // 按钮样式
67
- buttonBackground: "#21262d",
68
- buttonBackgroundHover: "#30363d",
69
- buttonBorder: "#30363d",
70
- buttonText: "#c9d1d9",
71
- buttonPrimary: "#238636",
72
- buttonPrimaryHover: "#2ea043",
73
- // 状态指示
74
- success: "#3fb950",
75
- successBackground: "#0f2e1c",
76
- error: "#f85149",
77
- errorBackground: "#3d1319",
78
- // SQL 语法高亮
79
- sqlKeyword: "#ff7b72",
80
- // 关键字 - 红色
81
- sqlFunction: "#d2a8ff",
82
- // 函数 - 紫色
83
- sqlString: "#a5d6ff",
84
- // 字符串 - 淡蓝色
85
- sqlNumber: "#79c0ff",
86
- // 数字 - 亮蓝色
87
- sqlComment: "#8b949e",
88
- // 注释 - 灰色
89
- sqlOperator: "#ff7b72",
90
- // 操作符 - 红色
91
- sqlIdentifier: "#c9d1d9",
92
- // 标识符 - 白色
93
- sqlPunctuation: "#c9d1d9",
94
- // 标点 - 白色
95
- // 折叠效果
96
- collapsedBackground: "#1c2d41",
97
- // 折叠信息背景色 - 深蓝
98
- collapsedText: "#58a6ff",
99
- // 折叠信息文本色 - 蓝色
100
- // 缩进指示线
101
- indentLine: "#30363d"
102
- // 对齐线 - 灰色
103
- }
104
- }, ee = {
105
- name: "min-light",
106
- colors: {
107
- // 背景色 - 纯白简洁
108
- background: "#ffffff",
109
- surfaceBackground: "#fafafa",
110
- hoverBackground: "#f9f9f9",
111
- // 边框色 - 极浅灰
112
- border: "#e5e5e5",
113
- // 文本色 - 深灰而非纯黑
114
- text: "#333333",
115
- textSecondary: "#888888",
116
- // 按钮样式 - 简约设计
117
- buttonBackground: "#f8f8f8",
118
- buttonBackgroundHover: "#eeeeee",
119
- buttonBorder: "#e0e0e0",
120
- buttonText: "#333333",
121
- buttonPrimary: "#007acc",
122
- buttonPrimaryHover: "#005a9e",
123
- // 状态指示 - 柔和色彩
124
- success: "#22c55e",
125
- successBackground: "#f0fdf4",
126
- error: "#ef4444",
127
- errorBackground: "#fef2f2",
128
- // SQL 语法高亮 - 简约配色(与 JSON 对应)
129
- sqlKeyword: "#22c55e",
130
- // 关键字 - 对应 Boolean 红色系
131
- sqlFunction: "#8b5cf6",
132
- // 函数 - 对应 Boolean 紫色
133
- sqlString: "#ef4444",
134
- // 字符串 - 对应 String 绿色
135
- sqlNumber: "#3b82f6",
136
- // 数字 - 对应 Number 蓝色
137
- sqlComment: "#6b7280",
138
- // 注释 - 对应 Null 灰色
139
- sqlOperator: "#ef4444",
140
- // 操作符 - 红色
141
- sqlIdentifier: "#1f2937",
142
- // 标识符 - 对应 Key 深灰
143
- sqlPunctuation: "#374151",
144
- // 标点 - 对应 Bracket 灰色
145
- // 折叠效果
146
- collapsedBackground: "#e0f2fe",
147
- // 折叠信息背景色 - 浅蓝
148
- collapsedText: "#0284c7",
149
- // 折叠信息文本色 - 蓝色
150
- // 缩进指示线
151
- indentLine: "#e5e7eb"
152
- // 对齐线 - 灰色
153
- }
154
- }, te = {
155
- name: "slack-ochin",
156
- colors: {
157
- // 背景色
158
- background: "#fef5ed",
159
- surfaceBackground: "#fef9f3",
160
- hoverBackground: "#f9f0e5",
161
- // 边框色
162
- border: "#e9dcc9",
163
- // 文本色
164
- text: "#3d3c40",
165
- textSecondary: "#616061",
166
- // 按钮样式
167
- buttonBackground: "#fef9f3",
168
- buttonBackgroundHover: "#f9f0e5",
169
- buttonBorder: "#e9dcc9",
170
- buttonText: "#3d3c40",
171
- buttonPrimary: "#007a5a",
172
- buttonPrimaryHover: "#006644",
173
- // 状态指示
174
- success: "#007a5a",
175
- successBackground: "#d1f4e0",
176
- error: "#e01e5a",
177
- errorBackground: "#ffdbea",
178
- // SQL 语法高亮
179
- sqlKeyword: "#e01e5a",
180
- // 关键字 - 红色
181
- sqlFunction: "#8b2eff",
182
- // 函数 - 紫色
183
- sqlString: "#0b4c8c",
184
- // 字符串 - 深蓝
185
- sqlNumber: "#1264a3",
186
- // 数字 - 蓝色
187
- sqlComment: "#616061",
188
- // 注释 - 灰色
189
- sqlOperator: "#e01e5a",
190
- // 操作符 - 红色
191
- sqlIdentifier: "#3d3c40",
192
- // 标识符 - 深色
193
- sqlPunctuation: "#3d3c40",
194
- // 标点 - 深色
195
- // 折叠效果
196
- collapsedBackground: "#d8eaf5",
197
- // 折叠信息背景色 - 浅蓝
198
- collapsedText: "#0b4c8c",
199
- // 折叠信息文本色 - 深蓝
200
- // 缩进指示线
201
- indentLine: "#3e4348"
202
- // 对齐线 - 灰色
203
- }
204
- }, M = {
205
- "github-light": X,
206
- "github-dark": Z,
207
- "min-light": ee,
208
- "slack-ochin": te
209
- }, se = (o) => M[o] || M["github-light"], K = [
210
- "SELECT",
211
- "FROM",
212
- "WHERE",
213
- "JOIN",
214
- "INNER",
215
- "LEFT",
216
- "RIGHT",
217
- "FULL",
218
- "OUTER",
219
- "ON",
220
- "GROUP",
221
- "BY",
222
- "HAVING",
223
- "ORDER",
224
- "LIMIT",
225
- "OFFSET",
226
- "INSERT",
227
- "INTO",
228
- "VALUES",
229
- "UPDATE",
230
- "SET",
231
- "DELETE",
232
- "CREATE",
233
- "ALTER",
234
- "DROP",
235
- "TABLE",
236
- "DATABASE",
237
- "INDEX",
238
- "VIEW",
239
- "AND",
240
- "OR",
241
- "NOT",
242
- "IN",
243
- "BETWEEN",
244
- "LIKE",
245
- "IS",
246
- "NULL",
247
- "AS",
248
- "DISTINCT",
249
- "UNION",
250
- "ALL",
251
- "EXISTS",
252
- "CASE",
253
- "WHEN",
254
- "THEN",
255
- "ELSE",
256
- "END"
257
- ], ne = [
258
- "WITH",
259
- "SELECT",
260
- "FROM",
261
- "WHERE",
262
- "GROUP BY",
263
- "HAVING",
264
- "ORDER BY",
265
- "LIMIT",
266
- "INSERT INTO",
267
- "UPDATE",
268
- "SET",
269
- "DELETE FROM",
270
- "CREATE",
271
- "ALTER",
272
- "DROP",
273
- "INNER JOIN",
274
- "LEFT JOIN",
275
- "RIGHT JOIN",
276
- "FULL JOIN",
277
- "CROSS JOIN",
278
- "OUTER JOIN",
279
- "JOIN",
280
- "UNION ALL",
281
- "UNION",
282
- "INTERSECT",
283
- "EXCEPT"
284
- ], re = (o) => {
285
- try {
286
- if (!o || !o.trim())
287
- return { valid: !1, error: "SQL string is empty" };
288
- const s = o.toUpperCase().trim();
289
- if (!K.some((t) => new RegExp(`\\b${t}\\b`).test(s)))
290
- return { valid: !1, error: "No valid SQL keywords found" };
291
- let d = 0, n = !1, u = "";
292
- for (let t = 0; t < o.length; t++) {
293
- const i = o[t], m = t > 0 ? o[t - 1] : "";
294
- if ((i === "'" || i === '"') && m !== "\\" && (n ? i === u && (n = !1, u = "") : (n = !0, u = i)), !n && (i === "(" && d++, i === ")" && d--, d < 0))
295
- return { valid: !1, error: "Mismatched parentheses: unexpected closing parenthesis" };
296
- }
297
- if (d !== 0)
298
- return { valid: !1, error: `Mismatched parentheses: ${d} unclosed opening parenthesis` };
299
- try {
300
- return D(o, { language: "sql" }), { valid: !0 };
301
- } catch (t) {
302
- return {
303
- valid: !1,
304
- error: t instanceof Error ? t.message : "SQL syntax error"
305
- };
306
- }
307
- } catch (s) {
308
- return {
309
- valid: !1,
310
- error: s instanceof Error ? s.message : "Unknown validation error"
311
- };
312
- }
313
- }, le = (o, s) => {
314
- const e = o.match(/\bVALUES\s*/i);
315
- if (!e || e.index === void 0) return o;
316
- const d = o.slice(0, e.index + e[0].length), n = o.slice(e.index + e[0].length), u = [];
317
- let t = 0, i = "", m = !1, r = "", f = 0;
318
- for (; f < n.length; ) {
319
- const l = n[f], y = f > 0 ? n[f - 1] : "";
320
- if ((l === "'" || l === '"') && y !== "\\" && (m ? l === r && (m = !1) : (m = !0, r = l)), m)
321
- t > 0 && (i += l);
322
- else if (l === "(")
323
- t === 0 ? i = l : i += l, t++;
324
- else if (l === ")")
325
- i += l, t--, t === 0 && i.trim() && (u.push(i.trim()), i = "");
326
- else {
327
- if (l === ";" && t === 0)
328
- break;
329
- t > 0 && (i += l);
330
- }
331
- f++;
332
- }
333
- if (u.length === 0)
334
- return o;
335
- const g = " ".repeat(s), v = u.map((l) => {
336
- const y = l.slice(1, -1), E = [];
337
- let T = "", I = 0, O = !1, x = "";
338
- for (let c = 0; c < y.length; c++) {
339
- const b = y[c], k = c > 0 ? y[c - 1] : "";
340
- if ((b === "'" || b === '"') && k !== "\\" && (O ? b === x && (O = !1) : (O = !0, x = b)), !O && (b === "(" && I++, b === ")" && I--, b === "," && I === 0)) {
341
- E.push(T.trim()), T = "";
342
- continue;
343
- }
344
- T += b;
345
- }
346
- T.trim() && E.push(T.trim());
347
- const L = E.map((c, b) => {
348
- const k = b < E.length - 1 ? "," : "";
349
- return `${g}${g}${c}${k}`;
350
- }).join(`
351
- `);
352
- return `${g}(
353
- ${L}
354
- ${g})`;
355
- }), h = v.map((l, y) => {
356
- const E = y < v.length - 1 ? "," : ";";
357
- return l + E;
358
- }).join(`
359
- `);
360
- let a = f;
361
- a < n.length && n[a] === ";" && a++;
362
- const p = n.slice(a);
363
- return d.trimEnd() + `
364
- ` + h + p;
365
- }, U = (o, s) => {
366
- try {
367
- const e = s?.dialect || "sql", d = s?.tabWidth || 2, n = s?.keywordCase || "upper", u = s?.useTabs || !1, t = s?.linesBetweenQueries || 1, m = {
368
- sql: "sql",
369
- mysql: "mysql",
370
- postgresql: "postgresql",
371
- sqlite: "sqlite",
372
- plsql: "plsql",
373
- tsql: "tsql"
374
- }[e] || "sql";
375
- let r = D(o, {
376
- language: m,
377
- tabWidth: d,
378
- keywordCase: n,
379
- useTabs: u,
380
- linesBetweenQueries: t,
381
- // 其他默认配置
382
- indentStyle: "standard"
383
- });
384
- return /\bINSERT\s+INTO\b/i.test(r) && /\bVALUES\b/i.test(r) && (r = le(r, d)), r;
385
- } catch (e) {
386
- return console.error("SQL formatting error:", e), o;
387
- }
388
- }, oe = (o) => {
389
- try {
390
- const s = [];
391
- let e = o.replace(/(["'])(?:(?=(\\?))\2.)*?\1/g, (d) => (s.push(d), `__STR_${s.length - 1}__`));
392
- return e = e.replace(/--[^\n]*/g, "").replace(/\/\*[\s\S]*?\*\//g, ""), e = e.replace(/\s+/g, " ").trim(), s.forEach((d, n) => {
393
- e = e.replace(`__STR_${n}__`, d);
394
- }), e;
395
- } catch (s) {
396
- return console.error("SQL compression error:", s), o;
397
- }
398
- }, ae = (o, s) => {
399
- const e = [], d = o.match(/^(.*?\bVALUES\b)/is);
400
- if (!d) return [];
401
- const n = d[1].trim();
402
- e.push({
403
- type: "VALUES",
404
- content: n,
405
- raw: n,
406
- collapsible: !1,
407
- path: `clause-${s}`
408
- });
409
- let t = o.slice(d[1].length).trim(), i = 0, m = 0, r = "", f = !1, g = "";
410
- for (let v = 0; v < t.length; v++) {
411
- const h = t[v], a = v > 0 ? t[v - 1] : "";
412
- if ((h === "'" || h === '"') && a !== "\\" && (f ? h === g && (f = !1) : (f = !0, g = h)), f)
413
- m > 0 && (r += h);
414
- else if (h === "(" && m === 0)
415
- m++, r = h;
416
- else if (h === "(")
417
- m++, r += h;
418
- else if (h === ")") {
419
- if (r += h, m--, m === 0) {
420
- let p = v + 1, l = "";
421
- for (; p < t.length; ) {
422
- const E = t[p];
423
- if (E === "," || E === ";") {
424
- l = E;
425
- break;
426
- } else if (!/\s/.test(E))
427
- break;
428
- p++;
429
- }
430
- const y = r.trim();
431
- y && (e.push({
432
- type: "VALUE_TUPLE",
433
- content: y + l,
434
- raw: y + l,
435
- collapsible: !0,
436
- path: `clause-${s}-value-${i}`
437
- }), i++), r = "", l && (v = p);
438
- }
439
- } else m > 0 && (r += h);
440
- }
441
- return e;
442
- }, ce = (o, s) => /\n\s*ON\b/i.test(s) ? s : s.replace(
443
- /^(\s*)((?:INNER|LEFT|RIGHT|FULL|CROSS|OUTER)?\s*JOIN\b[^\n]*?)\s+ON\b\s*/gim,
444
- `$1$2
445
- $1ON `
446
- ), ie = (o) => {
447
- let s = 0, e = !1, d = "";
448
- for (let n = 0; n < o.length; n++) {
449
- const u = o[n], t = n > 0 ? o[n - 1] : "";
450
- if ((u === "'" || u === '"') && t !== "\\") {
451
- e ? u === d && (e = !1, d = "") : (e = !0, d = u);
452
- continue;
453
- }
454
- e || (u === "(" && s++, u === ")" && s--);
455
- }
456
- return s;
457
- }, ue = (o) => {
458
- const s = [];
459
- let e = 0, d = -1, n = !1, u = "";
460
- for (let t = 0; t < o.length; t++) {
461
- const i = o[t], m = t > 0 ? o[t - 1] : "";
462
- if ((i === "'" || i === '"') && m !== "\\") {
463
- n ? i === u && (n = !1, u = "") : (n = !0, u = i);
464
- continue;
465
- }
466
- n || (i === "(" ? (e === 0 && (d = t), e++) : i === ")" && (e--, e === 0 && d >= 0 && (s.push({ open: d, close: t }), d = -1)));
467
- }
468
- return s;
469
- }, de = (o) => {
470
- const s = o.trim();
471
- return s ? /^(SELECT|WITH)\b/i.test(s) ? !0 : /\n\s*(SELECT|FROM|WHERE|JOIN|UNION|INTERSECT|EXCEPT)\b/i.test(o) : !1;
472
- }, fe = (o) => {
473
- const s = o.content.split(`
474
- `);
475
- let e = -1;
476
- for (let r = 0; r < s.length; r++)
477
- if (s[r].trim()) {
478
- e = r;
479
- break;
480
- }
481
- if (e < 0) return;
482
- const d = s.slice(e + 1).join(`
483
- `);
484
- if (!d) return;
485
- const u = ue(d).filter(
486
- (r) => de(d.slice(r.open + 1, r.close))
487
- );
488
- if (u.length === 0) return;
489
- const t = [];
490
- let i = 0;
491
- const m = o.path || "clause";
492
- u.forEach((r, f) => {
493
- r.open + 1 > i && t.push({ kind: "text", text: d.slice(i, r.open + 1) });
494
- const g = d.lastIndexOf(`
495
- `, r.close - 1) + 1, v = g > r.open, h = v ? g - 1 : r.close, a = d.slice(r.open + 1, h), p = j(a, `${m}-sub${f}-`);
496
- for (const l of p)
497
- t.push({ kind: "clause", clause: l });
498
- i = v ? g : r.close;
499
- }), i < d.length && t.push({ kind: "text", text: d.slice(i) }), o.body = t;
500
- }, j = (o, s) => {
501
- const e = [], d = o.split(`
502
- `);
503
- let n = null, u = [], t = [], i = 0;
504
- const m = [...ne].sort((f, g) => g.length - f.length), r = () => {
505
- if (!n || u.length === 0) return;
506
- let f = u.join(`
507
- `);
508
- if (f = ce(n.type, f), n.content = f, n.raw = f, n.type === "INSERT INTO" && /\bVALUES\b/i.test(f)) {
509
- const g = f.match(/^(.*?\bINSERT\s+INTO\s+[^(]+\s*\([^)]+\))/is);
510
- if (g) {
511
- const v = {
512
- type: "INSERT INTO",
513
- content: g[1].trim(),
514
- raw: g[1].trim(),
515
- collapsible: !0,
516
- path: `${s}clause-${e.length}`
517
- };
518
- e.push(v);
519
- const h = f.slice(g[1].length).trim(), a = e.length, p = ae(h, a);
520
- for (let l = 0; l < p.length; l++)
521
- p[l].path = `${s}clause-${a + l}`;
522
- e.push(...p);
523
- return;
524
- }
525
- }
526
- fe(n), e.push(n);
527
- };
528
- for (const f of d) {
529
- const g = f.trim();
530
- if (!g) {
531
- n && u.push(f);
532
- continue;
533
- }
534
- if (g.startsWith("--") || g.startsWith("/*")) {
535
- n ? u.push(f) : t.push(f);
536
- continue;
537
- }
538
- let h = !1, a = "UNKNOWN";
539
- if (i === 0) {
540
- for (const p of m)
541
- if (new RegExp(`^${p}\\b`, "i").test(g)) {
542
- h = !0, a = p.toUpperCase();
543
- break;
544
- }
545
- }
546
- h ? (r(), t.length > 0 && (e.push({
547
- type: "UNKNOWN",
548
- content: t.join(`
549
- `),
550
- raw: t.join(`
551
- `),
552
- collapsible: !1,
553
- path: `${s}clause-${e.length}`
554
- }), t = []), u = [f], n = {
555
- type: a,
556
- content: "",
557
- raw: "",
558
- collapsible: !0,
559
- path: `${s}clause-${e.length}`
560
- }) : n ? u.push(f) : (u = [...t, f], t = [], n = {
561
- type: "UNKNOWN",
562
- content: "",
563
- raw: "",
564
- collapsible: !1,
565
- path: `${s}clause-${e.length}`
566
- }), i = Math.max(0, i + ie(f));
567
- }
568
- return r(), t.length > 0 && e.push({
569
- type: "UNKNOWN",
570
- content: t.join(`
571
- `),
572
- raw: t.join(`
573
- `),
574
- collapsible: !1,
575
- path: `${s}clause-${e.length}`
576
- }), e;
577
- }, pe = (o) => {
578
- try {
579
- const s = U(o, { keywordCase: "upper" });
580
- return { clauses: j(s, ""), raw: o };
581
- } catch {
582
- return {
583
- clauses: [
584
- {
585
- type: "UNKNOWN",
586
- content: o,
587
- raw: o,
588
- collapsible: !1,
589
- path: "clause-0"
590
- }
591
- ],
592
- raw: o
593
- };
594
- }
595
- }, J = (o) => {
596
- const s = [];
597
- let e = o;
598
- const d = [
599
- "COUNT",
600
- "SUM",
601
- "AVG",
602
- "MAX",
603
- "MIN",
604
- "UPPER",
605
- "LOWER",
606
- "SUBSTRING",
607
- "CONCAT",
608
- "LENGTH",
609
- "TRIM",
610
- "NOW",
611
- "DATE",
612
- "YEAR",
613
- "MONTH",
614
- "DAY",
615
- "COALESCE",
616
- "CAST",
617
- "CONVERT",
618
- "ROUND",
619
- "ABS",
620
- "FLOOR",
621
- "CEIL"
622
- ], n = ["=", "!=", "<>", "<", ">", "<=", ">=", "+", "-", "*", "/", "%", "||"], u = ["(", ")", ",", ";", "."];
623
- for (; e.length > 0; ) {
624
- let t = !1;
625
- const i = e.match(/^(\s+)/);
626
- if (i) {
627
- s.push({ type: "whitespace", value: i[1] }), e = e.slice(i[1].length);
628
- continue;
629
- }
630
- const m = e.match(/^(--[^\n]*)/);
631
- if (m) {
632
- s.push({ type: "comment", value: m[1] }), e = e.slice(m[1].length);
633
- continue;
634
- }
635
- const r = e.match(/^(\/\*[\s\S]*?\*\/)/);
636
- if (r) {
637
- s.push({ type: "comment", value: r[1] }), e = e.slice(r[1].length);
638
- continue;
639
- }
640
- const f = e.match(/^(["'])(?:(?=(\\?))\2.)*?\1/);
641
- if (f) {
642
- s.push({ type: "string", value: f[0] }), e = e.slice(f[0].length);
643
- continue;
644
- }
645
- const g = e.match(/^(\d+\.?\d*|\.\d+)/);
646
- if (g) {
647
- s.push({ type: "number", value: g[1] }), e = e.slice(g[1].length);
648
- continue;
649
- }
650
- for (const h of n)
651
- if (e.startsWith(h)) {
652
- s.push({ type: "operator", value: h }), e = e.slice(h.length), t = !0;
653
- break;
654
- }
655
- if (t) continue;
656
- for (const h of u)
657
- if (e.startsWith(h)) {
658
- s.push({ type: "punctuation", value: h }), e = e.slice(h.length), t = !0;
659
- break;
660
- }
661
- if (t) continue;
662
- const v = e.match(/^([a-zA-Z_][a-zA-Z0-9_]*)/);
663
- if (v) {
664
- const h = v[1], a = h.toUpperCase();
665
- K.includes(a) ? s.push({ type: "keyword", value: h }) : d.includes(a) ? s.push({ type: "function", value: h }) : s.push({ type: "identifier", value: h }), e = e.slice(h.length);
666
- continue;
667
- }
668
- s.push({ type: "punctuation", value: e[0] }), e = e.slice(1);
669
- }
670
- return s;
671
- }, he = { class: "sql-clause-node" }, me = ["title"], ge = { class: "sql-clause-node__code" }, be = ["innerHTML"], ve = {
672
- key: 0,
673
- class: "sql-clause-node__body"
674
- }, ye = ["title"], Ee = ["innerHTML"], ke = ["title"], Te = ["innerHTML"], Ce = /* @__PURE__ */ H({
675
- __name: "SqlClauseNode",
676
- props: {
677
- clause: {},
678
- expandedClauses: {},
679
- theme: {}
680
- },
681
- emits: ["toggle"],
682
- setup(o, { emit: s }) {
683
- const e = o, d = s, n = q(() => e.clause.path || ""), u = q(() => e.expandedClauses.has(n.value)), t = q(() => {
684
- const a = e.clause.content.split(`
685
- `);
686
- for (const p of a)
687
- if (p.trim()) return p;
688
- return "";
689
- }), i = q(() => {
690
- const a = e.clause.content.split(`
691
- `);
692
- if (a.length <= 1) return "";
693
- let p = 0;
694
- for (let l = 0; l < a.length; l++)
695
- if (a[l].trim()) {
696
- p = l;
697
- break;
698
- }
699
- return a.slice(p + 1).join(`
700
- `);
701
- }), m = q(() => e.clause.body && e.clause.body.length > 0 ? !0 : !!i.value), r = (a) => {
702
- const p = J(a), l = e.theme.colors;
703
- return p.map((y) => {
704
- let E = l.text;
705
- switch (y.type) {
706
- case "keyword":
707
- E = l.sqlKeyword;
708
- break;
709
- case "function":
710
- E = l.sqlFunction;
711
- break;
712
- case "string":
713
- E = l.sqlString;
714
- break;
715
- case "number":
716
- E = l.sqlNumber;
717
- break;
718
- case "comment":
719
- E = l.sqlComment;
720
- break;
721
- case "operator":
722
- E = l.sqlOperator;
723
- break;
724
- case "identifier":
725
- E = l.sqlIdentifier;
726
- break;
727
- case "punctuation":
728
- E = l.sqlPunctuation;
729
- break;
730
- case "whitespace":
731
- return y.value.replace(/ /g, "&nbsp;").replace(/\n/g, `
732
- `);
733
- }
734
- const T = y.value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
735
- return `<span style="color: ${E}">${T}</span>`;
736
- }).join("");
737
- }, f = q(() => {
738
- const a = e.clause.body;
739
- if (!a || a.length === 0) return null;
740
- let p = "", l = !1;
741
- for (const c of a)
742
- if (c.kind === "text") {
743
- const b = c.text.indexOf("(");
744
- if (b >= 0) {
745
- p += c.text.slice(0, b), l = !0;
746
- break;
747
- }
748
- p += c.text;
749
- } else
750
- return null;
751
- if (!l) return null;
752
- let y = "";
753
- for (let c = a.length - 1; c >= 0; c--) {
754
- const b = a[c];
755
- if (b.kind === "text") {
756
- const k = b.text.lastIndexOf(")");
757
- if (k >= 0) {
758
- y = b.text.slice(k + 1) + y;
759
- break;
760
- }
761
- y = b.text + y;
762
- } else
763
- break;
764
- }
765
- const E = p.replace(/\s+/g, " ").trim(), T = y.replace(/\s+/g, " ").trim(), I = t.value, O = (I.match(/^\s*/) || [""])[0], L = [I.trimStart()];
766
- return E && L.push(E), L.push("(...)"), T && L.push(T), `${O}${L.join(" ")}`;
767
- }), g = q(() => {
768
- if (e.clause.collapsible && !u.value && m.value) {
769
- const a = f.value;
770
- if (a)
771
- return r(a);
772
- const p = r(t.value), l = e.theme.colors.textSecondary;
773
- return `${p}<span style="color: ${l}; opacity: 0.6; font-style: italic; margin-left: 4px;"> ...</span>`;
774
- }
775
- return r(t.value);
776
- }), v = () => {
777
- e.clause.collapsible && d("toggle", n.value);
778
- }, h = (a) => {
779
- if (!e.clause.collapsible) return;
780
- const p = a.target;
781
- if (!p) return;
782
- const l = (p.textContent || "").trim();
783
- (l === "(" || l === ")") && d("toggle", n.value);
784
- };
785
- return (a, p) => {
786
- const l = Q("SqlClauseNode", !0);
787
- return N(), S("div", he, [
788
- _("div", {
789
- class: $(["sql-clause-node__header", { "sql-clause-node__header--collapsible": a.clause.collapsible }]),
790
- title: a.clause.collapsible ? u.value ? "Click to collapse" : "Click to expand" : "",
791
- onClick: v
792
- }, [
793
- _("pre", ge, [
794
- _("code", { innerHTML: g.value }, null, 8, be)
795
- ])
796
- ], 10, me),
797
- u.value && m.value ? (N(), S("div", ve, [
798
- a.clause.body && a.clause.body.length > 0 ? (N(!0), S(A, { key: 0 }, P(a.clause.body, (y, E) => (N(), S(A, { key: E }, [
799
- y.kind === "text" ? (N(), S("pre", {
800
- key: 0,
801
- class: $(["sql-clause-node__code sql-clause-node__text-segment", { "sql-clause-node__text-segment--clickable": a.clause.collapsible }]),
802
- title: a.clause.collapsible ? "Click ( or ) to collapse" : "",
803
- onClick: p[0] || (p[0] = (T) => h(T))
804
- }, [
805
- _("code", {
806
- innerHTML: r(y.text)
807
- }, null, 8, Ee)
808
- ], 10, ye)) : (N(), W(l, {
809
- key: 1,
810
- clause: y.clause,
811
- "expanded-clauses": a.expandedClauses,
812
- theme: a.theme,
813
- onToggle: p[1] || (p[1] = (T) => a.$emit("toggle", T))
814
- }, null, 8, ["clause", "expanded-clauses", "theme"]))
815
- ], 64))), 128)) : (N(), S("pre", {
816
- key: 1,
817
- class: $(["sql-clause-node__code sql-clause-node__rest", { "sql-clause-node__rest--clickable": a.clause.collapsible }]),
818
- title: a.clause.collapsible ? "Click ( or ) to collapse" : "",
819
- onClick: p[2] || (p[2] = (y) => h(y))
820
- }, [
821
- _("code", {
822
- innerHTML: r(i.value)
823
- }, null, 8, Te)
824
- ], 10, ke))
825
- ])) : G("", !0)
826
- ]);
827
- };
828
- }
829
- }), Ne = /* @__PURE__ */ F(Ce, [["__scopeId", "data-v-8b9383dc"]]), Se = { class: "sql-format__content" }, qe = {
830
- key: 0,
831
- class: "sql-format__error"
832
- }, _e = {
833
- key: 1,
834
- class: "sql-format__viewer"
835
- }, Ie = {
836
- key: 0,
837
- class: "sql-format__clauses"
838
- }, Oe = {
839
- key: 1,
840
- class: "sql-format__code"
841
- }, Le = ["innerHTML"], xe = /* @__PURE__ */ H({
842
- __name: "index",
843
- props: {
844
- modelValue: { default: "" },
845
- readonly: { type: Boolean, default: !1 },
846
- theme: { default: "github-light" },
847
- dialect: { default: "sql" },
848
- tabWidth: { default: 2 }
849
- },
850
- emits: ["update:modelValue", "copy-success", "copy-error", "expand-all", "collapse-all", "compress", "format"],
851
- setup(o, { expose: s, emit: e }) {
852
- z((c) => ({
853
- "45d5acb0": v.value.colors.background,
854
- "4623e62f": v.value.colors.text,
855
- f365b9d8: v.value.colors.errorBackground,
856
- "7d8b5146": v.value.colors.error
857
- }));
858
- const d = (c) => {
859
- const b = [], k = (w) => {
860
- for (const C of w)
861
- if (C.path && b.push(C.path), C.body)
862
- for (const B of C.body)
863
- B.kind === "clause" && k([B.clause]);
864
- };
865
- return k(c), b;
866
- }, n = o, u = e, t = R(""), i = R(n.dialect), m = R([]), r = R(/* @__PURE__ */ new Set()), f = R(""), g = q(() => t.value === ""), v = q(() => se(n.theme)), h = (c) => {
867
- if (!c || !c.trim()) {
868
- t.value = "", m.value = [], r.value.clear();
869
- return;
870
- }
871
- try {
872
- const b = re(c);
873
- if (!b.valid) {
874
- t.value = b.error || "Invalid SQL", m.value = [], f.value = "";
875
- return;
876
- }
877
- const k = pe(c);
878
- m.value = k.clauses, f.value = U(c, {
879
- dialect: i.value,
880
- tabWidth: n.tabWidth
881
- }), r.value = new Set(d(k.clauses)), t.value = "";
882
- } catch (b) {
883
- t.value = b instanceof Error ? b.message : "Unknown parse error", m.value = [], f.value = "";
884
- }
885
- }, a = (c) => {
886
- const b = J(c), k = v.value.colors;
887
- return b.map((w) => {
888
- let C = k.text;
889
- switch (w.type) {
890
- case "keyword":
891
- C = k.sqlKeyword;
892
- break;
893
- case "function":
894
- C = k.sqlFunction;
895
- break;
896
- case "string":
897
- C = k.sqlString;
898
- break;
899
- case "number":
900
- C = k.sqlNumber;
901
- break;
902
- case "comment":
903
- C = k.sqlComment;
904
- break;
905
- case "operator":
906
- C = k.sqlOperator;
907
- break;
908
- case "identifier":
909
- C = k.sqlIdentifier;
910
- break;
911
- case "punctuation":
912
- C = k.sqlPunctuation;
913
- break;
914
- case "whitespace":
915
- return w.value.replace(/ /g, "&nbsp;").replace(/\n/g, `
916
- `);
917
- }
918
- const B = w.value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
919
- return `<span style="color: ${C}">${B}</span>`;
920
- }).join("");
921
- }, p = (c) => {
922
- r.value.has(c) ? r.value.delete(c) : r.value.add(c), r.value = new Set(r.value);
923
- }, l = () => {
924
- r.value = new Set(d(m.value)), u("expand-all");
925
- }, y = () => {
926
- r.value = /* @__PURE__ */ new Set(), u("collapse-all");
927
- }, E = () => f.value || n.modelValue, T = async () => {
928
- if (g.value)
929
- try {
930
- const c = E();
931
- await navigator.clipboard.writeText(c), u("copy-success", c);
932
- } catch (c) {
933
- const b = c instanceof Error ? c : new Error("Failed to copy");
934
- u("copy-error", b);
935
- }
936
- }, I = () => {
937
- if (g.value)
938
- try {
939
- const c = U(n.modelValue, {
940
- dialect: i.value,
941
- tabWidth: n.tabWidth
942
- });
943
- u("update:modelValue", c), u("format", c);
944
- } catch (c) {
945
- console.error("Format error:", c);
946
- }
947
- }, O = () => {
948
- if (g.value)
949
- try {
950
- const c = oe(n.modelValue);
951
- u("update:modelValue", c), u("compress", c);
952
- } catch (c) {
953
- console.error("Compress error:", c);
954
- }
955
- }, x = () => null, L = () => t.value;
956
- return V(
957
- () => n.modelValue,
958
- (c) => {
959
- h(c);
960
- },
961
- { immediate: !0 }
962
- ), V(
963
- () => n.dialect,
964
- (c) => {
965
- i.value = c;
966
- }
967
- ), s({
968
- copySql: T,
969
- formatSource: I,
970
- compressSource: O,
971
- expandAll: l,
972
- collapseAll: y,
973
- toggleExpand: p,
974
- isValidSql: () => g.value,
975
- getParsedSql: x,
976
- getParseError: L,
977
- getValue: E
978
- }), (c, b) => (N(), S("div", {
979
- class: $(["sql-format", `sql-format--${v.value.name}`])
980
- }, [
981
- _("div", Se, [
982
- g.value ? (N(), S("div", _e, [
983
- m.value.length > 0 ? (N(), S("div", Ie, [
984
- (N(!0), S(A, null, P(m.value, (k) => (N(), W(Ne, {
985
- key: k.path,
986
- clause: k,
987
- "expanded-clauses": r.value,
988
- theme: v.value,
989
- onToggle: p
990
- }, null, 8, ["clause", "expanded-clauses", "theme"]))), 128))
991
- ])) : (N(), S("pre", Oe, [
992
- _("code", {
993
- innerHTML: a(n.modelValue)
994
- }, null, 8, Le)
995
- ]))
996
- ])) : (N(), S("div", qe, [
997
- b[0] || (b[0] = _("h4", null, "SQL Parse Error:", -1)),
998
- _("pre", null, Y(t.value), 1)
999
- ]))
1000
- ])
1001
- ], 2));
1002
- }
1003
- }), $e = /* @__PURE__ */ F(xe, [["__scopeId", "data-v-8445135b"]]);
1004
- export {
1005
- $e as S
1006
- };