@kazurolabs/psql-explorer 0.3.0 → 0.3.1
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.
- package/RELEASES.md +8 -0
- package/dist/explorer/explain.js +29 -12
- package/dist/explorer/rows.js +79 -6
- package/dist/explorer/session.js +8 -1
- package/dist/web/server.js +2 -2
- package/package.json +2 -1
- package/web/dist/assets/{button-ClA70PLR.js → button-BiFx4Lyw.js} +1 -1
- package/web/dist/assets/{code-xml-CXkpHeU9.js → code-xml-CPEjNFOw.js} +1 -1
- package/web/dist/assets/{compare-view-DKl5l_Jw.js → compare-view-COQ3yE76.js} +1 -1
- package/web/dist/assets/{copy-CCXzeW-s.js → copy-C2N9tUYJ.js} +1 -1
- package/web/dist/assets/{cypher-view-Pd0WFH8F.js → cypher-view-BzyL4mNU.js} +1 -1
- package/web/dist/assets/{design-view-CIHSmH4u.js → design-view-BPm7dSTY.js} +1 -1
- package/web/dist/assets/{erd-view-CV7mFGAN.js → erd-view-DqGDws2_.js} +1 -1
- package/web/dist/assets/{format-sql-BLj5_RDZ.js → format-sql-CoddYUOF.js} +1 -1
- package/web/dist/assets/{graph-force-yBLyErpS.js → graph-force-ChCGXQUt.js} +1 -1
- package/web/dist/assets/{graph-link-OCo_s0zO.js → graph-link-C8P9s_0W.js} +1 -1
- package/web/dist/assets/{graph-view-sM1OlByf.js → graph-view-BpoUrUCP.js} +1 -1
- package/web/dist/assets/{index-CDcnUacl.js → index-CpHnjRLv.js} +3 -3
- package/web/dist/assets/{key-round-Cv_7QeED.js → key-round-JiGCgCWS.js} +1 -1
- package/web/dist/assets/{loader-circle-BK_GMdvN.js → loader-circle-BxDJOoJO.js} +1 -1
- package/web/dist/assets/{query-builder-view-ChNFb51g.js → query-builder-view-CtRexMEX.js} +1 -1
- package/web/dist/assets/{rotate-ccw-CdCaf7Q6.js → rotate-ccw-CwdA-J3t.js} +1 -1
- package/web/dist/assets/{route-DO6IZ7of.js → route-7eu-iAqD.js} +1 -1
- package/web/dist/assets/{seed-view-DFNB8WHE.js → seed-view-BIkBTiU6.js} +1 -1
- package/web/dist/assets/{shield-alert-CMS-3j4U.js → shield-alert-keJIAND5.js} +1 -1
- package/web/dist/assets/{sliders-horizontal-Dg51yc-C.js → sliders-horizontal-DKtL_ql7.js} +1 -1
- package/web/dist/assets/sql-tabs-DUSXdYCr.js +2 -0
- package/web/dist/assets/{table-DfMz2f8M.js → table-Drc_n1gF.js} +1 -1
- package/web/dist/assets/{triangle-alert-COGnHCD1.js → triangle-alert-C5nF69rW.js} +1 -1
- package/web/dist/assets/{zone-D9dXk8tn.js → zone-CHDOrDBF.js} +1 -1
- package/web/dist/index.html +8 -8
- package/web/dist/assets/sql-tabs-B4jt6bQj.js +0 -2
package/RELEASES.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Release notes
|
|
2
2
|
|
|
3
|
+
## 0.3.1 (2026-11-02)
|
|
4
|
+
|
|
5
|
+
### 2026-11-02
|
|
6
|
+
|
|
7
|
+
- Fix: Send explain as one statement in a rolled-back transaction, so text after a `;` can no longer write to a read-only environment
|
|
8
|
+
- Fix: Make SQL page links wait for a click before running or explaining their statement
|
|
9
|
+
- Fix: Run a query that cannot be paged as written only when the person pressed Run on it, and page a query that ends in `; -- comment`
|
|
10
|
+
|
|
3
11
|
## 0.3.0 (2026-11-02)
|
|
4
12
|
|
|
5
13
|
### 2026-11-01
|
package/dist/explorer/explain.js
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
|
+
// The planner's plan for a statement, as the web UI's Explain button shows it.
|
|
2
|
+
import { trimStatement } from './rows.js';
|
|
3
|
+
// Statements that only read, so that measuring them in a read only session is allowed. WITH is
|
|
4
|
+
// among them because the transaction they run in is read only too, which refuses a CTE that writes.
|
|
5
|
+
const onlyReads = /^(?:select|with|values|table)\b/i;
|
|
6
|
+
/** Runs `work` in a transaction that is always rolled back, whatever it did. */
|
|
7
|
+
async function rolledBack(session, begin, work) {
|
|
8
|
+
await session.run(begin);
|
|
9
|
+
try {
|
|
10
|
+
return await work();
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
await session.run('ROLLBACK').catch(() => undefined);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
1
16
|
/**
|
|
2
17
|
* The plan for a statement, with schemas and qualified column names so that advice can name them.
|
|
3
18
|
* Without ANALYZE the statement is planned but never run, so explaining
|
|
4
|
-
* an UPDATE or DELETE changes nothing.
|
|
19
|
+
* an UPDATE or DELETE changes nothing. It is planned in a read only transaction that is rolled
|
|
20
|
+
* back, and sent as one statement, so text after a `;` is refused rather than run.
|
|
5
21
|
*/
|
|
6
22
|
export async function explainQuery(session, sql) {
|
|
7
|
-
const statement = sql
|
|
8
|
-
const [row] = await session.rows(`EXPLAIN (VERBOSE, FORMAT JSON) ${statement}`);
|
|
23
|
+
const statement = trimStatement(sql);
|
|
24
|
+
const [row] = await rolledBack(session, 'BEGIN READ ONLY', () => session.rows(`EXPLAIN (VERBOSE, FORMAT JSON) ${statement}`));
|
|
9
25
|
const plan = JSON.parse(row?.['QUERY PLAN'] ?? '[]');
|
|
10
26
|
if (!plan[0]?.Plan)
|
|
11
27
|
throw new Error('Postgres did not return a plan');
|
|
@@ -14,13 +30,17 @@ export async function explainQuery(session, sql) {
|
|
|
14
30
|
/**
|
|
15
31
|
* Runs the statement to measure it (EXPLAIN ANALYZE), so every step of the plan has its actual
|
|
16
32
|
* time, rows and buffers next to the planner's estimates. It runs inside a transaction that is
|
|
17
|
-
* always rolled back
|
|
18
|
-
*
|
|
33
|
+
* always rolled back (read only when the session is), and is sent as one statement so that no
|
|
34
|
+
* COMMIT can follow it; rows it inserts, updates or deletes are not kept, but what cannot be undone
|
|
35
|
+
* (a sequence's nextval, a NOTIFY sent by a trigger, ...) still happens. A read only session
|
|
36
|
+
* measures only queries.
|
|
19
37
|
*/
|
|
20
38
|
export async function explainAnalyze(session, sql) {
|
|
21
|
-
const statement = sql
|
|
22
|
-
|
|
23
|
-
|
|
39
|
+
const statement = trimStatement(sql);
|
|
40
|
+
if (session.readOnly && !onlyReads.test(statement)) {
|
|
41
|
+
throw new Error('Only a query can be measured: this environment is read only');
|
|
42
|
+
}
|
|
43
|
+
return rolledBack(session, session.readOnly ? 'BEGIN READ ONLY' : 'BEGIN', async () => {
|
|
24
44
|
const [row] = await session.rows(`EXPLAIN (ANALYZE, BUFFERS, VERBOSE, FORMAT JSON) ${statement}`);
|
|
25
45
|
const plan = JSON.parse(row?.['QUERY PLAN'] ?? '[]');
|
|
26
46
|
if (!plan[0]?.Plan)
|
|
@@ -30,8 +50,5 @@ export async function explainAnalyze(session, sql) {
|
|
|
30
50
|
planningMs: plan[0]['Planning Time'] ?? null,
|
|
31
51
|
executionMs: plan[0]['Execution Time'] ?? null,
|
|
32
52
|
};
|
|
33
|
-
}
|
|
34
|
-
finally {
|
|
35
|
-
await session.run('ROLLBACK').catch(() => undefined);
|
|
36
|
-
}
|
|
53
|
+
});
|
|
37
54
|
}
|
package/dist/explorer/rows.js
CHANGED
|
@@ -24,15 +24,88 @@ export async function countRows(session, table) {
|
|
|
24
24
|
const readsRows = /^(?:select|with|values|table)\b/i;
|
|
25
25
|
// SQLSTATE 42601 (syntax error) and 0A000 (not supported): the statement cannot be wrapped.
|
|
26
26
|
const cannotWrap = (error) => ['42601', '0A000'].includes(error?.code ?? '');
|
|
27
|
-
|
|
28
|
-
const
|
|
27
|
+
const identifierChar = /[\p{L}\p{N}_$]/u;
|
|
28
|
+
const dollarTag = /\$(?:[\p{L}_][\p{L}\p{N}_]*)?\$/uy;
|
|
29
|
+
/** Where the string, quoted name or dollar-quoted body that opens at `i` ends. */
|
|
30
|
+
function quotedEnd(sql, i) {
|
|
31
|
+
const quote = sql[i];
|
|
32
|
+
if (quote === '$') {
|
|
33
|
+
dollarTag.lastIndex = i;
|
|
34
|
+
const tag = dollarTag.exec(sql)[0];
|
|
35
|
+
const close = sql.indexOf(tag, i + tag.length);
|
|
36
|
+
return close < 0 ? sql.length : close + tag.length;
|
|
37
|
+
}
|
|
38
|
+
// E'...' takes backslash escapes; every string and quoted name doubles its quote.
|
|
39
|
+
const escapes = quote === "'" && /[eE]/.test(sql[i - 1] ?? '') && !identifierChar.test(sql[i - 2] ?? '');
|
|
40
|
+
for (let j = i + 1; j < sql.length; j++) {
|
|
41
|
+
if (escapes && sql[j] === '\\')
|
|
42
|
+
j++;
|
|
43
|
+
else if (sql[j] === quote && sql[j + 1] === quote)
|
|
44
|
+
j++;
|
|
45
|
+
else if (sql[j] === quote)
|
|
46
|
+
return j + 1;
|
|
47
|
+
}
|
|
48
|
+
return sql.length;
|
|
49
|
+
}
|
|
50
|
+
/** Where the comment that opens at `i` ends; block comments nest in Postgres. */
|
|
51
|
+
function commentEnd(sql, i) {
|
|
52
|
+
if (sql.startsWith('--', i)) {
|
|
53
|
+
const newline = sql.indexOf('\n', i);
|
|
54
|
+
return newline < 0 ? sql.length : newline + 1;
|
|
55
|
+
}
|
|
56
|
+
let depth = 0;
|
|
57
|
+
do {
|
|
58
|
+
if (sql.startsWith('/*', i))
|
|
59
|
+
depth++;
|
|
60
|
+
else if (sql.startsWith('*/', i))
|
|
61
|
+
depth--;
|
|
62
|
+
else {
|
|
63
|
+
i++;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
i += 2;
|
|
67
|
+
} while (depth > 0 && i < sql.length);
|
|
68
|
+
return i;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The statement without the whitespace, comments and semicolons around it. Strings are read the
|
|
72
|
+
* way Postgres reads them ('...', E'...', "...", $tag$...$tag$), so a `;` or `--` in one is kept.
|
|
73
|
+
*/
|
|
74
|
+
export function trimStatement(sql) {
|
|
75
|
+
let start = -1;
|
|
76
|
+
let end = 0;
|
|
77
|
+
for (let i = 0; i < sql.length;) {
|
|
78
|
+
const c = sql[i];
|
|
79
|
+
if (/[\s;]/.test(c)) {
|
|
80
|
+
i++;
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (sql.startsWith('--', i) || sql.startsWith('/*', i)) {
|
|
84
|
+
i = commentEnd(sql, i);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
dollarTag.lastIndex = i;
|
|
88
|
+
const quoted = c === "'" ||
|
|
89
|
+
c === '"' ||
|
|
90
|
+
(c === '$' && !identifierChar.test(sql[i - 1] ?? '') && dollarTag.test(sql));
|
|
91
|
+
const next = quoted ? quotedEnd(sql, i) : i + 1;
|
|
92
|
+
if (start < 0)
|
|
93
|
+
start = i;
|
|
94
|
+
end = next;
|
|
95
|
+
i = next;
|
|
96
|
+
}
|
|
97
|
+
return start < 0 ? '' : sql.slice(start, end);
|
|
98
|
+
}
|
|
29
99
|
/**
|
|
30
100
|
* One page of any statement's rows, without the statement needing a LIMIT of its own. A query is
|
|
31
101
|
* wrapped in `SELECT * FROM (...) LIMIT OFFSET`, so the planner knows that few rows are wanted and
|
|
32
|
-
* starts returning them early, as it does for an explicit LIMIT. Other statements
|
|
33
|
-
* cannot be wrapped
|
|
102
|
+
* starts returning them early, as it does for an explicit LIMIT. Other statements run as they are
|
|
103
|
+
* and give their first rows. A query that cannot be wrapped runs as it is only when `asWritten`
|
|
104
|
+
* says the person asked for exactly that text: Postgres refusing the wrapper often means the
|
|
105
|
+
* statement writes (SELECT ... INTO, a WITH that deletes), so a caller that only lets queries
|
|
106
|
+
* through (the Build page) can count on nothing else running.
|
|
34
107
|
*/
|
|
35
|
-
export async function runPage(session, sql, { limit, offset = 0 }) {
|
|
108
|
+
export async function runPage(session, sql, { limit, offset = 0, asWritten = false }) {
|
|
36
109
|
const statement = trimStatement(sql);
|
|
37
110
|
if (!readsRows.test(statement))
|
|
38
111
|
return session.run(sql, [], { maxRows: limit });
|
|
@@ -42,7 +115,7 @@ export async function runPage(session, sql, { limit, offset = 0 }) {
|
|
|
42
115
|
return await session.run(wrapped, [], { maxRows: limit });
|
|
43
116
|
}
|
|
44
117
|
catch (error) {
|
|
45
|
-
if (!cannotWrap(error))
|
|
118
|
+
if (!asWritten || !cannotWrap(error))
|
|
46
119
|
throw error;
|
|
47
120
|
return session.run(sql, [], { maxRows: limit });
|
|
48
121
|
}
|
package/dist/explorer/session.js
CHANGED
|
@@ -99,7 +99,14 @@ export const openSession = async (params, options = {}) => {
|
|
|
99
99
|
durationMs,
|
|
100
100
|
};
|
|
101
101
|
}),
|
|
102
|
-
|
|
102
|
+
// Always the extended protocol, which takes one statement: without values node-postgres
|
|
103
|
+
// would use the simple one, which runs every statement in the text, COMMIT and BEGIN
|
|
104
|
+
// READ WRITE included, and so gets around a read only session.
|
|
105
|
+
rows: (sql, values = []) => serial(async () => (await client.query({
|
|
106
|
+
text: sql,
|
|
107
|
+
values: [...values],
|
|
108
|
+
queryMode: 'extended',
|
|
109
|
+
})).rows),
|
|
103
110
|
// From a connection of its own, since this one is busy with the statement to stop.
|
|
104
111
|
cancel: async () => {
|
|
105
112
|
const pid = client.processID;
|
package/dist/web/server.js
CHANGED
|
@@ -482,7 +482,7 @@ export function createWebServer(options) {
|
|
|
482
482
|
if (resource === 'envs' && name && sub === 'query' && req.method === 'POST') {
|
|
483
483
|
const body = (await readJson(req));
|
|
484
484
|
if (typeof body?.sql !== 'string' || body.sql.trim() === '') {
|
|
485
|
-
throw new HttpError(400, 'send {"sql": "..."}');
|
|
485
|
+
throw new HttpError(400, 'send {"sql": "...", "asWritten"?: true}');
|
|
486
486
|
}
|
|
487
487
|
const sql = body.sql;
|
|
488
488
|
const limit = Math.min(Math.max(Number(body.limit) || 100, 1), 1000);
|
|
@@ -493,7 +493,7 @@ export function createWebServer(options) {
|
|
|
493
493
|
const gucs = parseGucs(body.settings);
|
|
494
494
|
const result = await withSessionFor(name, async (session) => {
|
|
495
495
|
await applyGucs(session, gucs);
|
|
496
|
-
return runPage(session, sql, { limit, offset });
|
|
496
|
+
return runPage(session, sql, { limit, offset, asWritten: body.asWritten === true });
|
|
497
497
|
});
|
|
498
498
|
// Later pages of a result are the same statement again, not a new one to remember.
|
|
499
499
|
if (offset === 0) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kazurolabs/psql-explorer",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Explore your Postgres databases from the terminal, with credentials from Vault",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"eslint-config-prettier": "^10.1.8",
|
|
61
61
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
62
62
|
"globals": "^17.13.0",
|
|
63
|
+
"happy-dom": "^21.0.4",
|
|
63
64
|
"ink-testing-library": "^4.0.0",
|
|
64
65
|
"prettier": "^3.9.10",
|
|
65
66
|
"tsx": "^4.23.15",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{at as e,ct as t,it as n,ot as r,rt as i}from"./route-DO6IZ7of.js";var a={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};a.node;var o=e(a);function s(e,t){if(e&&!t)return e;if(!e&&t)return t;if(e||t)return{...e,...t}}var c={};function l(e,t,n,r,i){if(!n&&!r&&!i&&!e)return d(t);let a=d(e);return t&&(a=f(a,t)),n&&(a=f(a,n)),r&&(a=f(a,r)),i&&(a=f(a,i)),a}function u(e){if(e.length===0)return c;if(e.length===1)return d(e[0]);let t=d(e[0]);for(let n=1;n<e.length;n+=1)t=f(t,e[n]);return t}function d(e){return h(e)?{...e(c)}:p(e)}function f(e,t){return h(t)?t(e):ee(e,t)}function p(e){let t={...e};for(let e in t){let n=t[e];m(e,n)&&(t[e]=g(n))}return t}function ee(e,t){if(!t)return e;for(let n in t){let r=t[n];switch(n){case`style`:e[n]=s(e.style,r);break;case`className`:e[n]=v(e.className,r);break;default:e[n]=m(n,r)?te(e[n],r):r}}return e}function m(e,t){let n=e.charCodeAt(0),r=e.charCodeAt(1),i=e.charCodeAt(2);return n===111&&r===110&&i>=65&&i<=90&&(typeof t==`function`||t===void 0)}function h(e){return typeof e==`function`}function te(e,t){return t?e?(...n)=>{let r=n[0];if(y(r)){let i=r;_(i);let a=t(...n);return i.baseUIHandlerPrevented||e?.(...n),a}let i=t(...n);return e?.(...n),i}:g(t):e}function g(e){return e&&((...t)=>{let n=t[0];return y(n)&&_(n),e(...t)})}function _(e){return e.preventBaseUIHandler=()=>{e.baseUIHandlerPrevented=!0},e}function v(e,t){return t?e?t+` `+e:t:e}function y(e){return typeof e==`object`&&!!e&&`nativeEvent`in e}var b=t(r(),1),x={};function S(e,t){let n=b.useRef(x);return n.current===x&&(n.current=e(t)),n}function C(e,t,n,r){let i=S(w).current;return re(i,e,t,n,r)&&ae(i,[e,t,n,r]),i.callback}function ne(e){let t=S(w).current;return ie(t,e)&&ae(t,e),t.callback}function w(){return{callback:null,cleanup:null,refs:[]}}function re(e,t,n,r,i){return e.refs[0]!==t||e.refs[1]!==n||e.refs[2]!==r||e.refs[3]!==i}function ie(e,t){return e.refs.length!==t.length||e.refs.some((e,n)=>e!==t[n])}function ae(e,t){e.refs=t,e.callback=t.every(e=>e==null)?null:n=>{if(e.cleanup&&=(e.cleanup(),null),n!=null){let r=Array(t.length).fill(null);for(let e=0;e<t.length;e+=1){let i=t[e];if(i!=null)switch(typeof i){case`function`:{let t=i(n);typeof t==`function`&&(r[e]=t);break}case`object`:i.current=n}}e.cleanup=()=>{for(let e=0;e<t.length;e+=1){let n=t[e];if(n!=null)switch(typeof n){case`function`:{let t=r[e];typeof t==`function`?t():n(null);break}case`object`:n.current=null}}}}}}var oe=19;function se(e){return oe>=e}function ce(e){if(!b.isValidElement(e))return null;let t=e,n=t.props;return(se(19)?n?.ref:t.ref)??null}function le(){}var ue=Object.freeze([]),T=Object.freeze({});function de(e,t){let n={};for(let r in e){let i=e[r];if(t?.hasOwnProperty(r)){let e=t[r](i);e!=null&&Object.assign(n,e)}else i===!0?n[`data-${r.toLowerCase()}`]=``:i&&(n[`data-${r.toLowerCase()}`]=i.toString())}return n}function fe(e,t){return typeof e==`function`?e(t):e}function pe(e,t){return typeof e==`function`?e(t):e}function E(e,t,n={}){let r=t.render;n.enabled!==!1&&(r=D(r));let i=me(t,n,r);if(n.enabled===!1)return null;let a=n.state??T;return _e(e,r,i,a)}function me(e,t,n){let{className:r,style:i}=e,{state:a=T,ref:o,props:c,stateAttributesMapping:l,enabled:u=!0}=t,d=u?fe(r,a):void 0,f=u?pe(i,a):void 0,p=u?de(a,l):T,ee=u&&c?he(c):void 0,m=u?s(p,ee)??{}:T;return typeof document<`u`&&(u?m.ref=Array.isArray(o)?ne([m.ref,ce(n),...o]):C(m.ref,ce(n),o):C(null,null)),u?(d!==void 0&&(m.className=v(m.className,d)),f!==void 0&&(m.style=s(m.style,f)),m):T}function he(e){return Array.isArray(e)?u(e):l(void 0,e)}var ge=Symbol.for(`react.lazy`);function D(e){if(e?.$$typeof!==ge)return e;let t=b.Children.toArray(e)[0];return b.isValidElement(t)?t:e}function _e(e,t,n,r){if(t){if(typeof t==`function`)return t(n,r);let e=l(n,t.props);return e.ref=n.ref,b.cloneElement(t,e)}return ve(e,n)}function ve(e,t){return e===`button`?(0,b.createElement)(`button`,{type:`button`,...t,key:t.key}):e===`img`?(0,b.createElement)(`img`,{alt:``,...t,key:t.key}):b.createElement(e,t)}function O(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`){if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=O(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n)}return r}function ye(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=O(e))&&(r&&(r+=` `),r+=t);return r}var k=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,A=ye,j=(e,t)=>n=>{if(t?.variants==null)return A(e,n?.class,n?.className);let{variants:r,defaultVariants:i}=t,a=Object.keys(r).map(e=>{let t=n?.[e],a=i?.[e];if(t===null)return null;let o=k(t)||k(a);return r[e][o]}),o=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return r===void 0||(e[n]=r),e},{});return A(e,a,t?.compoundVariants?.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...i,...o}[t]):{...i,...o}[t]===n})?[...e,n,r]:e},[]),n?.class,n?.className)};function M(){return typeof window<`u`}function N(e){return I(e)?(e.nodeName||``).toLowerCase():`#document`}function P(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function F(e){return((I(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function I(e){return M()?e instanceof Node||e instanceof P(e).Node:!1}function L(e){return M()?e instanceof Element||e instanceof P(e).Element:!1}function R(e){return M()?e instanceof HTMLElement||e instanceof P(e).HTMLElement:!1}function z(e){return!M()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof P(e).ShadowRoot}function B(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=K(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function be(e){return/^(table|td|th)$/.test(N(e))}function V(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var xe=/transform|translate|scale|rotate|perspective|filter/,Se=/paint|layout|strict|content/,H=e=>!!e&&e!==`none`,Ce;function U(e){let t=L(e)?K(e):e;return H(t.transform)||H(t.translate)||H(t.scale)||H(t.rotate)||H(t.perspective)||!W()&&(H(t.backdropFilter)||H(t.filter))||xe.test(t.willChange||``)||Se.test(t.contain||``)}function we(e){let t=q(e);for(;R(t)&&!G(t);){if(U(t))return t;if(V(t))return null;t=q(t)}return null}function W(){return Ce??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Ce}function G(e){return/^(html|body|#document)$/.test(N(e))}function K(e){return P(e).getComputedStyle(e)}function Te(e){return L(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function q(e){if(N(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||z(e)&&e.host||F(e);return z(t)?t.host:t}function Ee(e){let t=q(e);return G(t)?(e.ownerDocument||e).body:R(t)&&B(t)?t:Ee(t)}function J(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Ee(e),i=r===e.ownerDocument?.body,a=P(r);if(i){let e=De(a);return t.concat(a,a.visualViewport||[],B(r)?r:[],e&&n?J(e):[])}return t.concat(r,J(r,[],n))}function De(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}var Y={...b},X=Y.useInsertionEffect,Oe=X&&X!==Y.useLayoutEffect?X:e=>e();function ke(e){let t=S(Ae).current;return t.next=e,Oe(t.effect),t.trampoline}function Ae(){let e={next:void 0,callback:je,trampoline:(...t)=>e.callback?.(...t),effect:()=>{e.callback=e.next}};return e}function je(){}var Me=typeof document<`u`?b.useLayoutEffect:()=>{};function Ne(e,t){return function(n,...r){let i=new URL(e);return i.searchParams.set(`code`,n.toString()),r.forEach(e=>i.searchParams.append(`args[]`,e)),`${t} error #${n}; visit ${i} for the full message.`}}var Pe=Ne(`https://base-ui.com/production-error`,`Base UI`),Fe=b.createContext(void 0);function Ie(e=!1){let t=b.useContext(Fe);if(t===void 0&&!e)throw Error(Pe(16));return t}function Le(e){let{focusableWhenDisabled:t,disabled:n,composite:r=!1,tabIndex:i=0,isNativeButton:a}=e,o=r&&t!==!1,s=r&&t===!1;return{props:b.useMemo(()=>{let e={onKeyDown(e){n&&t&&e.key!==`Tab`&&e.preventDefault()}};return r||(e.tabIndex=i,!a&&n&&(e.tabIndex=t?i:-1)),(a&&(t||o)||!a&&n)&&(e[`aria-disabled`]=n),a&&(!t||s)&&(e.disabled=n),e},[r,n,t,o,s,a,i])}}function Z(e,t,{detail:n=0,pointerType:r=``}={}){e.dispatchEvent(new(P(e)).PointerEvent(`click`,{bubbles:!0,cancelable:!0,composed:!0,detail:n,pointerType:r,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey}))}function Q(e={}){let{disabled:t=!1,focusableWhenDisabled:n,tabIndex:r=0,native:i=!0,composite:a}=e,o=b.useRef(null),s=Ie(!0),c=a??s!==void 0,{props:u}=Le({focusableWhenDisabled:n,disabled:t,composite:c,tabIndex:r,isNativeButton:i}),d=b.useCallback(()=>{let e=o.current;$(e)&&c&&t&&u.disabled===void 0&&e.disabled&&(e.disabled=!1)},[t,u.disabled,c]);return Me(d,[d]),{getButtonProps:b.useCallback((e={})=>{let{onClick:n,onMouseDown:r,onKeyUp:a,onKeyDown:o,onPointerDown:s,...d}=e;return l({onClick(e){t?e.preventDefault():n?.(e)},onMouseDown(e){t||r?.(e)},onKeyDown(e){if(t||(_(e),o?.(e),e.baseUIHandlerPrevented))return;let n=e.target===e.currentTarget,r=e.currentTarget,a=$(r),s=!i&&Re(r),l=n&&(i?a:!s),u=e.key===`Enter`,d=e.key===` `,f=r.getAttribute(`role`),p=f?.startsWith(`menuitem`)||f===`option`||f===`gridcell`;if(n&&c&&d){if(e.defaultPrevented&&p)return;e.preventDefault(),(!i||a)&&(e.preventBaseUIHandler(),Z(r,e))}else!l||i||!d&&!u?n&&s&&d&&e.preventDefault():e.defaultPrevented||(e.preventDefault(),u&&(e.preventBaseUIHandler(),Z(r,e)))},onKeyUp(e){t||(_(e),a?.(e),e.target===e.currentTarget&&i&&c&&$(e.currentTarget)&&e.key===` `?e.preventDefault():e.baseUIHandlerPrevented||e.target!==e.currentTarget||i||c||e.defaultPrevented||e.key!==` `||(e.preventBaseUIHandler(),Z(e.currentTarget,e)))},onPointerDown(e){t?e.preventDefault():s?.(e)}},i?{type:`button`}:{role:`button`},u,d)},[t,u,c,i]),buttonRef:ke(e=>{o.current=e,d()})}}function $(e){return R(e)&&e.tagName===`BUTTON`}function Re(e){return R(e)&&e.tagName===`A`&&!!e.href}var ze=b.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,focusableWhenDisabled:a=!1,nativeButton:o=!0,style:s,...c}=e,{getButtonProps:l,buttonRef:u}=Q({disabled:i,focusableWhenDisabled:a,native:o});return E(`button`,e,{state:{disabled:i},ref:[t,u],props:[c,l]})}),Be=i(),Ve=j(`group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/80`,outline:`border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground`,ghost:`hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50`,destructive:`bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,xs:`h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5`,lg:`h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,icon:`size-8`,"icon-xs":`size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg`,"icon-lg":`size-9`}},defaultVariants:{variant:`default`,size:`default`}});function He({className:e,variant:t=`default`,size:r=`default`,...i}){return(0,Be.jsx)(ze,{"data-slot":`button`,"data-variant":t,className:n(Ve({variant:t,size:r,className:e})),...i})}export{D as A,I as C,V as D,be as E,se as F,C as I,S as L,ue as M,T as N,W as O,le as P,l as R,G as S,z as T,q as _,Ie as a,L as b,ke as c,we as d,F as f,J as g,Te as h,Fe as i,E as j,j as k,Y as l,N as m,Q as n,Pe as o,De as p,Z as r,Me as s,He as t,K as u,P as v,B as w,R as x,U as y,o as z};
|
|
1
|
+
import{at as e,ct as t,it as n,ot as r,rt as i}from"./route-7eu-iAqD.js";var a={name:`check`,size:24,node:[[`path`,{d:`M20 6 9 17l-5-5`,key:`1gmf2c`}]]};a.node;var o=e(a);function s(e,t){if(e&&!t)return e;if(!e&&t)return t;if(e||t)return{...e,...t}}var c={};function l(e,t,n,r,i){if(!n&&!r&&!i&&!e)return d(t);let a=d(e);return t&&(a=f(a,t)),n&&(a=f(a,n)),r&&(a=f(a,r)),i&&(a=f(a,i)),a}function u(e){if(e.length===0)return c;if(e.length===1)return d(e[0]);let t=d(e[0]);for(let n=1;n<e.length;n+=1)t=f(t,e[n]);return t}function d(e){return h(e)?{...e(c)}:p(e)}function f(e,t){return h(t)?t(e):ee(e,t)}function p(e){let t={...e};for(let e in t){let n=t[e];m(e,n)&&(t[e]=g(n))}return t}function ee(e,t){if(!t)return e;for(let n in t){let r=t[n];switch(n){case`style`:e[n]=s(e.style,r);break;case`className`:e[n]=v(e.className,r);break;default:e[n]=m(n,r)?te(e[n],r):r}}return e}function m(e,t){let n=e.charCodeAt(0),r=e.charCodeAt(1),i=e.charCodeAt(2);return n===111&&r===110&&i>=65&&i<=90&&(typeof t==`function`||t===void 0)}function h(e){return typeof e==`function`}function te(e,t){return t?e?(...n)=>{let r=n[0];if(y(r)){let i=r;_(i);let a=t(...n);return i.baseUIHandlerPrevented||e?.(...n),a}let i=t(...n);return e?.(...n),i}:g(t):e}function g(e){return e&&((...t)=>{let n=t[0];return y(n)&&_(n),e(...t)})}function _(e){return e.preventBaseUIHandler=()=>{e.baseUIHandlerPrevented=!0},e}function v(e,t){return t?e?t+` `+e:t:e}function y(e){return typeof e==`object`&&!!e&&`nativeEvent`in e}var b=t(r(),1),x={};function S(e,t){let n=b.useRef(x);return n.current===x&&(n.current=e(t)),n}function C(e,t,n,r){let i=S(w).current;return re(i,e,t,n,r)&&ae(i,[e,t,n,r]),i.callback}function ne(e){let t=S(w).current;return ie(t,e)&&ae(t,e),t.callback}function w(){return{callback:null,cleanup:null,refs:[]}}function re(e,t,n,r,i){return e.refs[0]!==t||e.refs[1]!==n||e.refs[2]!==r||e.refs[3]!==i}function ie(e,t){return e.refs.length!==t.length||e.refs.some((e,n)=>e!==t[n])}function ae(e,t){e.refs=t,e.callback=t.every(e=>e==null)?null:n=>{if(e.cleanup&&=(e.cleanup(),null),n!=null){let r=Array(t.length).fill(null);for(let e=0;e<t.length;e+=1){let i=t[e];if(i!=null)switch(typeof i){case`function`:{let t=i(n);typeof t==`function`&&(r[e]=t);break}case`object`:i.current=n}}e.cleanup=()=>{for(let e=0;e<t.length;e+=1){let n=t[e];if(n!=null)switch(typeof n){case`function`:{let t=r[e];typeof t==`function`?t():n(null);break}case`object`:n.current=null}}}}}}var oe=19;function se(e){return oe>=e}function ce(e){if(!b.isValidElement(e))return null;let t=e,n=t.props;return(se(19)?n?.ref:t.ref)??null}function le(){}var ue=Object.freeze([]),T=Object.freeze({});function de(e,t){let n={};for(let r in e){let i=e[r];if(t?.hasOwnProperty(r)){let e=t[r](i);e!=null&&Object.assign(n,e)}else i===!0?n[`data-${r.toLowerCase()}`]=``:i&&(n[`data-${r.toLowerCase()}`]=i.toString())}return n}function fe(e,t){return typeof e==`function`?e(t):e}function pe(e,t){return typeof e==`function`?e(t):e}function E(e,t,n={}){let r=t.render;n.enabled!==!1&&(r=D(r));let i=me(t,n,r);if(n.enabled===!1)return null;let a=n.state??T;return _e(e,r,i,a)}function me(e,t,n){let{className:r,style:i}=e,{state:a=T,ref:o,props:c,stateAttributesMapping:l,enabled:u=!0}=t,d=u?fe(r,a):void 0,f=u?pe(i,a):void 0,p=u?de(a,l):T,ee=u&&c?he(c):void 0,m=u?s(p,ee)??{}:T;return typeof document<`u`&&(u?m.ref=Array.isArray(o)?ne([m.ref,ce(n),...o]):C(m.ref,ce(n),o):C(null,null)),u?(d!==void 0&&(m.className=v(m.className,d)),f!==void 0&&(m.style=s(m.style,f)),m):T}function he(e){return Array.isArray(e)?u(e):l(void 0,e)}var ge=Symbol.for(`react.lazy`);function D(e){if(e?.$$typeof!==ge)return e;let t=b.Children.toArray(e)[0];return b.isValidElement(t)?t:e}function _e(e,t,n,r){if(t){if(typeof t==`function`)return t(n,r);let e=l(n,t.props);return e.ref=n.ref,b.cloneElement(t,e)}return ve(e,n)}function ve(e,t){return e===`button`?(0,b.createElement)(`button`,{type:`button`,...t,key:t.key}):e===`img`?(0,b.createElement)(`img`,{alt:``,...t,key:t.key}):b.createElement(e,t)}function O(e){var t,n,r=``;if(typeof e==`string`||typeof e==`number`)r+=e;else if(typeof e==`object`){if(Array.isArray(e)){var i=e.length;for(t=0;t<i;t++)e[t]&&(n=O(e[t]))&&(r&&(r+=` `),r+=n)}else for(n in e)e[n]&&(r&&(r+=` `),r+=n)}return r}function ye(){for(var e,t,n=0,r=``,i=arguments.length;n<i;n++)(e=arguments[n])&&(t=O(e))&&(r&&(r+=` `),r+=t);return r}var k=e=>typeof e==`boolean`?`${e}`:e===0?`0`:e,A=ye,j=(e,t)=>n=>{if(t?.variants==null)return A(e,n?.class,n?.className);let{variants:r,defaultVariants:i}=t,a=Object.keys(r).map(e=>{let t=n?.[e],a=i?.[e];if(t===null)return null;let o=k(t)||k(a);return r[e][o]}),o=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return r===void 0||(e[n]=r),e},{});return A(e,a,t?.compoundVariants?.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...i,...o}[t]):{...i,...o}[t]===n})?[...e,n,r]:e},[]),n?.class,n?.className)};function M(){return typeof window<`u`}function N(e){return I(e)?(e.nodeName||``).toLowerCase():`#document`}function P(e){var t;return(e==null||(t=e.ownerDocument)==null?void 0:t.defaultView)||window}function F(e){return((I(e)?e.ownerDocument:e.document)||window.document)?.documentElement}function I(e){return M()?e instanceof Node||e instanceof P(e).Node:!1}function L(e){return M()?e instanceof Element||e instanceof P(e).Element:!1}function R(e){return M()?e instanceof HTMLElement||e instanceof P(e).HTMLElement:!1}function z(e){return!M()||typeof ShadowRoot>`u`?!1:e instanceof ShadowRoot||e instanceof P(e).ShadowRoot}function B(e){let{overflow:t,overflowX:n,overflowY:r,display:i}=K(e);return/auto|scroll|overlay|hidden|clip/.test(t+r+n)&&i!==`inline`&&i!==`contents`}function be(e){return/^(table|td|th)$/.test(N(e))}function V(e){try{if(e.matches(`:popover-open`))return!0}catch{}try{return e.matches(`:modal`)}catch{return!1}}var xe=/transform|translate|scale|rotate|perspective|filter/,Se=/paint|layout|strict|content/,H=e=>!!e&&e!==`none`,Ce;function U(e){let t=L(e)?K(e):e;return H(t.transform)||H(t.translate)||H(t.scale)||H(t.rotate)||H(t.perspective)||!W()&&(H(t.backdropFilter)||H(t.filter))||xe.test(t.willChange||``)||Se.test(t.contain||``)}function we(e){let t=q(e);for(;R(t)&&!G(t);){if(U(t))return t;if(V(t))return null;t=q(t)}return null}function W(){return Ce??=typeof CSS<`u`&&CSS.supports&&CSS.supports(`-webkit-backdrop-filter`,`none`),Ce}function G(e){return/^(html|body|#document)$/.test(N(e))}function K(e){return P(e).getComputedStyle(e)}function Te(e){return L(e)?{scrollLeft:e.scrollLeft,scrollTop:e.scrollTop}:{scrollLeft:e.scrollX,scrollTop:e.scrollY}}function q(e){if(N(e)===`html`)return e;let t=e.assignedSlot||e.parentNode||z(e)&&e.host||F(e);return z(t)?t.host:t}function Ee(e){let t=q(e);return G(t)?(e.ownerDocument||e).body:R(t)&&B(t)?t:Ee(t)}function J(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!0);let r=Ee(e),i=r===e.ownerDocument?.body,a=P(r);if(i){let e=De(a);return t.concat(a,a.visualViewport||[],B(r)?r:[],e&&n?J(e):[])}return t.concat(r,J(r,[],n))}function De(e){return e.parent&&Object.getPrototypeOf(e.parent)?e.frameElement:null}var Y={...b},X=Y.useInsertionEffect,Oe=X&&X!==Y.useLayoutEffect?X:e=>e();function ke(e){let t=S(Ae).current;return t.next=e,Oe(t.effect),t.trampoline}function Ae(){let e={next:void 0,callback:je,trampoline:(...t)=>e.callback?.(...t),effect:()=>{e.callback=e.next}};return e}function je(){}var Me=typeof document<`u`?b.useLayoutEffect:()=>{};function Ne(e,t){return function(n,...r){let i=new URL(e);return i.searchParams.set(`code`,n.toString()),r.forEach(e=>i.searchParams.append(`args[]`,e)),`${t} error #${n}; visit ${i} for the full message.`}}var Pe=Ne(`https://base-ui.com/production-error`,`Base UI`),Fe=b.createContext(void 0);function Ie(e=!1){let t=b.useContext(Fe);if(t===void 0&&!e)throw Error(Pe(16));return t}function Le(e){let{focusableWhenDisabled:t,disabled:n,composite:r=!1,tabIndex:i=0,isNativeButton:a}=e,o=r&&t!==!1,s=r&&t===!1;return{props:b.useMemo(()=>{let e={onKeyDown(e){n&&t&&e.key!==`Tab`&&e.preventDefault()}};return r||(e.tabIndex=i,!a&&n&&(e.tabIndex=t?i:-1)),(a&&(t||o)||!a&&n)&&(e[`aria-disabled`]=n),a&&(!t||s)&&(e.disabled=n),e},[r,n,t,o,s,a,i])}}function Z(e,t,{detail:n=0,pointerType:r=``}={}){e.dispatchEvent(new(P(e)).PointerEvent(`click`,{bubbles:!0,cancelable:!0,composed:!0,detail:n,pointerType:r,shiftKey:t.shiftKey,ctrlKey:t.ctrlKey,altKey:t.altKey,metaKey:t.metaKey}))}function Q(e={}){let{disabled:t=!1,focusableWhenDisabled:n,tabIndex:r=0,native:i=!0,composite:a}=e,o=b.useRef(null),s=Ie(!0),c=a??s!==void 0,{props:u}=Le({focusableWhenDisabled:n,disabled:t,composite:c,tabIndex:r,isNativeButton:i}),d=b.useCallback(()=>{let e=o.current;$(e)&&c&&t&&u.disabled===void 0&&e.disabled&&(e.disabled=!1)},[t,u.disabled,c]);return Me(d,[d]),{getButtonProps:b.useCallback((e={})=>{let{onClick:n,onMouseDown:r,onKeyUp:a,onKeyDown:o,onPointerDown:s,...d}=e;return l({onClick(e){t?e.preventDefault():n?.(e)},onMouseDown(e){t||r?.(e)},onKeyDown(e){if(t||(_(e),o?.(e),e.baseUIHandlerPrevented))return;let n=e.target===e.currentTarget,r=e.currentTarget,a=$(r),s=!i&&Re(r),l=n&&(i?a:!s),u=e.key===`Enter`,d=e.key===` `,f=r.getAttribute(`role`),p=f?.startsWith(`menuitem`)||f===`option`||f===`gridcell`;if(n&&c&&d){if(e.defaultPrevented&&p)return;e.preventDefault(),(!i||a)&&(e.preventBaseUIHandler(),Z(r,e))}else!l||i||!d&&!u?n&&s&&d&&e.preventDefault():e.defaultPrevented||(e.preventDefault(),u&&(e.preventBaseUIHandler(),Z(r,e)))},onKeyUp(e){t||(_(e),a?.(e),e.target===e.currentTarget&&i&&c&&$(e.currentTarget)&&e.key===` `?e.preventDefault():e.baseUIHandlerPrevented||e.target!==e.currentTarget||i||c||e.defaultPrevented||e.key!==` `||(e.preventBaseUIHandler(),Z(e.currentTarget,e)))},onPointerDown(e){t?e.preventDefault():s?.(e)}},i?{type:`button`}:{role:`button`},u,d)},[t,u,c,i]),buttonRef:ke(e=>{o.current=e,d()})}}function $(e){return R(e)&&e.tagName===`BUTTON`}function Re(e){return R(e)&&e.tagName===`A`&&!!e.href}var ze=b.forwardRef(function(e,t){let{render:n,className:r,disabled:i=!1,focusableWhenDisabled:a=!1,nativeButton:o=!0,style:s,...c}=e,{getButtonProps:l,buttonRef:u}=Q({disabled:i,focusableWhenDisabled:a,native:o});return E(`button`,e,{state:{disabled:i},ref:[t,u],props:[c,l]})}),Be=i(),Ve=j(`group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/80`,outline:`border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground`,ghost:`hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50`,destructive:`bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,xs:`h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5`,lg:`h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,icon:`size-8`,"icon-xs":`size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg`,"icon-lg":`size-9`}},defaultVariants:{variant:`default`,size:`default`}});function He({className:e,variant:t=`default`,size:r=`default`,...i}){return(0,Be.jsx)(ze,{"data-slot":`button`,"data-variant":t,className:n(Ve({variant:t,size:r,className:e})),...i})}export{D as A,I as C,V as D,be as E,se as F,C as I,S as L,ue as M,T as N,W as O,le as P,l as R,G as S,z as T,q as _,Ie as a,L as b,ke as c,we as d,F as f,J as g,Te as h,Fe as i,E as j,j as k,Y as l,N as m,Q as n,Pe as o,De as p,Z as r,Me as s,He as t,K as u,P as v,B as w,R as x,U as y,o as z};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{at as e}from"./route-
|
|
1
|
+
import{at as e}from"./route-7eu-iAqD.js";var t={name:`arrow-down`,size:24,node:[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]};t.node;var n=e(t),r={name:`arrow-up`,size:24,node:[[`path`,{d:`m5 12 7-7 7 7`,key:`hav0vg`}],[`path`,{d:`M12 19V5`,key:`x0mq9r`}]]};r.node;var i=e(r),a={name:`code-xml`,size:24,node:[[`path`,{d:`m18 16 4-4-4-4`,key:`1inbqp`}],[`path`,{d:`m6 8-4 4 4 4`,key:`15zrgr`}],[`path`,{d:`m14.5 4-5 16`,key:`e7oirm`}]],aliases:[`code-2`]};a.node;var o=e(a);export{i as n,n as r,o as t};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{$ as e,at as t,ct as n,o as r,ot as i,rt as a}from"./route-
|
|
1
|
+
import{$ as e,at as t,ct as n,o as r,ot as i,rt as a}from"./route-7eu-iAqD.js";import{t as o}from"./button-BiFx4Lyw.js";import{G as s,Gt as c,Kt as l,Wt as u,rn as d}from"./index-CpHnjRLv.js";var f={name:`clipboard-copy`,size:24,node:[[`rect`,{width:`8`,height:`4`,x:`8`,y:`2`,rx:`1`,ry:`1`,key:`tgr4d6`}],[`path`,{d:`M8 4H6a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-2`,key:`4jdomd`}],[`path`,{d:`M16 4h2a2 2 0 0 1 2 2v4`,key:`3hqy98`}],[`path`,{d:`M21 14H11`,key:`1bme5i`}],[`path`,{d:`m15 10-4 4 4 4`,key:`5dvupr`}]]};f.node;var p=t(f),m=n(i(),1);function h(e){let t={changed:0,"only-a":0,"only-b":0,same:e.same};for(let n of e.changes)t[n.status]++;return t}function g(e,t,n=``){let r=n.trim().toLowerCase(),i=new Map;for(let n of e){if(!t.has(n.status)||r&&![n.schema,n.kind,n.name,`${n.schema}.${n.name}`,...n.parts.map(e=>e.part)].some(e=>e.toLowerCase().includes(r)))continue;let e=n.kind===`extension`?``:n.schema;i.set(e,[...i.get(e)??[],n])}return[...i]}function _(e,t=e.schema){let{kind:n,name:r}=e;if(n===`table`||n===`view`||n===`materialized view`||n===`foreign table`)return{kind:`table`,schema:t,name:r};if(n===`sequence`||n===`type`)return{kind:n,schema:t,name:r}}function v(e,t,n){let r=[];for(let i of e.changes){let e=i.kind===`schema`||i.kind===`extension`?i.name:`${i.schema}.${i.name}`,a=i.status===`only-a`?`only in ${t}`:i.status===`only-b`?`only in ${n}`:`differs`;r.push(`${i.kind} ${e}: ${a}`);for(let e of i.parts)if(i.status!==`changed`)r.push(` ${e.part}: ${e.a??e.b}`);else if(e.lines){r.push(` ${e.part} (- ${t}, + ${n})`);for(let t of e.lines)r.push(` ${t.side===`a`?`-`:t.side===`b`?`+`:` `} ${t.text}`)}else e.a===null||e.b===null?r.push(` ${e.part}, only in ${e.a===null?n:t}: ${e.a??e.b}`):r.push(` ${e.part}`,` ${t}: ${e.a}`,` ${n}: ${e.b}`);r.push(``)}return r.push(e.changes.length===0?`${t} and ${n} are the same (${e.same} objects).`:`${e.changes.length} ${e.changes.length===1?`object differs`:`objects differ`}, ${e.same} the same.`),`${r.join(`
|
|
2
2
|
`)}\n`}var y=a(),b=`border-input bg-background rounded-lg border px-2 py-1 text-sm`,x={a:`bg-chart-1/15`,b:`bg-chart-3/15`};function S(e,t){window.location.hash=r({environment:e,compare:t})}function C({environment:t,environments:n,compare:r}){let i=u(()=>e.schemas(t),t),a=(n??[]).filter(e=>e.name!==t),[s,c]=(0,m.useState)(r.with??a[0]?.name??``),[l,f]=(0,m.useState)(r.schema??``),[p,h]=(0,m.useState)(r.withSchema??``),g=s||a[0]?.name||``;return n&&a.length===0?(0,y.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`There is no other environment in your config to compare with.`}):(0,y.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),g&&S(t,{with:g,...l?{schema:l,...p.trim()&&p.trim()!==l?{withSchema:p.trim()}:{}}:{}})},className:`flex flex-wrap items-center gap-2 text-sm`,children:[(0,y.jsx)(`span`,{className:`text-muted-foreground`,children:`Compare`}),(0,y.jsx)(`strong`,{children:t}),(0,y.jsx)(`span`,{className:`text-muted-foreground`,children:`with`}),(0,y.jsx)(`select`,{"aria-label":`Environment to compare with`,className:b,value:g,onChange:e=>c(e.target.value),children:a.map(e=>(0,y.jsxs)(`option`,{value:e.name,children:[e.name,` (`,e.tier,`)`]},e.name))}),(0,y.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(`span`,{className:`text-muted-foreground`,children:`schema`}),(0,y.jsxs)(`select`,{"aria-label":`Schema`,className:b,value:l,onChange:e=>f(e.target.value),children:[(0,y.jsx)(`option`,{value:``,children:`all schemas`}),i.data?.map(e=>(0,y.jsx)(`option`,{value:e.name,children:e.name},e.name))]})]}),l&&(0,y.jsxs)(`label`,{className:`flex items-center gap-2`,children:[(0,y.jsx)(`span`,{className:`text-muted-foreground`,children:`against its schema`}),(0,y.jsx)(`input`,{"aria-label":`Schema in ${g}`,className:`${b} w-36`,placeholder:l,value:p,onChange:e=>h(e.target.value)})]}),(0,y.jsxs)(o,{type:`submit`,disabled:!g,children:[(0,y.jsx)(d,{className:`size-4`}),` Compare`]})]})}function w({text:e,side:t,name:n}){return(0,y.jsxs)(`div`,{className:`min-w-0`,children:[(0,y.jsx)(`span`,{className:`text-muted-foreground text-xs sm:hidden`,children:n}),e===null?(0,y.jsx)(`span`,{className:`text-muted-foreground block italic`,children:`missing`}):(0,y.jsx)(`pre`,{className:`${x[t]} overflow-x-auto rounded px-1.5 py-0.5 font-mono text-xs whitespace-pre-wrap break-all`,children:e})]})}function T({part:e,a:t,b:n}){return(0,y.jsx)(`div`,{className:`overflow-x-auto rounded border font-mono text-xs`,children:e.lines.map((e,r)=>(0,y.jsxs)(`div`,{className:`flex gap-2 px-1.5 whitespace-pre ${e.side===`both`?``:x[e.side]}`,title:e.side===`both`?void 0:`only in ${e.side===`a`?t:n}`,children:[(0,y.jsx)(`span`,{className:`text-muted-foreground w-3 shrink-0 select-none`,children:e.side===`a`?`-`:e.side===`b`?`+`:` `}),(0,y.jsx)(`span`,{children:e.text||` `})]},r))})}function E({status:e,a:t,b:n}){return e===`changed`?(0,y.jsx)(l,{variant:`outline`,children:`differs`}):(0,y.jsxs)(l,{className:`${x[e===`only-a`?`a`:`b`]} text-foreground`,children:[`only in `,e===`only-a`?t:n]})}function D({change:e,environment:t,compare:n}){let i=t,a=n.with,o=e.kind===`schema`||e.kind===`extension`?e.name:`${e.schema}.${e.name}`,s=e.status===`only-b`?void 0:_(e),c=e.status===`only-a`?void 0:_(e,n.withSchema??e.schema);return(0,y.jsxs)(`details`,{open:e.status===`changed`,className:`bg-card rounded-lg border`,children:[(0,y.jsxs)(`summary`,{className:`flex cursor-pointer flex-wrap items-center gap-2 px-3 py-2 text-sm`,children:[(0,y.jsx)(`span`,{className:`text-muted-foreground w-28 shrink-0 text-xs uppercase tracking-wider`,children:e.kind}),(0,y.jsx)(`span`,{className:`font-mono`,children:o}),(0,y.jsx)(E,{status:e.status,a:i,b:a}),e.status===`changed`&&(0,y.jsxs)(`span`,{className:`text-muted-foreground text-xs`,children:[e.parts.length,` `,e.parts.length===1?`part`:`parts`]}),(0,y.jsxs)(`span`,{className:`ml-auto flex gap-3 text-xs`,children:[s&&(0,y.jsxs)(`a`,{className:`text-accent-text hover:underline`,href:r({environment:i,object:s}),children:[`open in `,i]}),c&&(0,y.jsxs)(`a`,{className:`text-accent-text hover:underline`,href:r({environment:a,object:c}),children:[`open in `,a]})]})]}),e.parts.length>0&&(0,y.jsx)(`div`,{className:`border-t px-3 py-2`,children:e.status===`changed`?(0,y.jsxs)(`div`,{className:`grid gap-x-3 gap-y-1.5 text-sm sm:grid-cols-[minmax(8rem,max-content)_1fr_1fr]`,children:[(0,y.jsxs)(`div`,{className:`hidden sm:contents`,children:[(0,y.jsx)(`span`,{}),(0,y.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:i}),(0,y.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:a})]}),e.parts.map(e=>(0,y.jsxs)(`div`,{className:`contents`,children:[(0,y.jsx)(`span`,{className:`mt-2 font-mono text-xs sm:mt-0`,children:e.part}),e.lines?(0,y.jsx)(`div`,{className:`min-w-0 sm:col-span-2`,children:(0,y.jsx)(T,{part:e,a:i,b:a})}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(w,{text:e.a,side:`a`,name:i}),(0,y.jsx)(w,{text:e.b,side:`b`,name:a})]})]},e.part))]}):(0,y.jsx)(`dl`,{className:`grid gap-x-3 gap-y-1 text-sm sm:grid-cols-[minmax(8rem,max-content)_1fr]`,children:e.parts.map(e=>(0,y.jsxs)(`div`,{className:`contents`,children:[(0,y.jsx)(`dt`,{className:`font-mono text-xs`,children:e.part}),(0,y.jsx)(`dd`,{className:`min-w-0`,children:(0,y.jsx)(`pre`,{className:`overflow-x-auto font-mono text-xs whitespace-pre-wrap break-all`,children:e.a??e.b})})]},e.part))})})]})}function O({environment:t,compare:n}){let r=[t,n.with,n.schema??``,n.withSchema??``].join(`\0`),i=u(()=>e.schemaDiff(t,n.with,n.schema,n.withSchema),r),[a,o]=(0,m.useState)(new Set([`changed`,`only-a`,`only-b`])),[l,d]=(0,m.useState)(``),f=t,_=n.with,S=n.schema?n.withSchema?` (schema ${n.schema} against ${n.withSchema})`:` (schema ${n.schema})`:``;if(i.error)return(0,y.jsx)(`p`,{className:`text-destructive text-sm`,children:i.error});if(!i.data)return(0,y.jsxs)(`div`,{className:`space-y-2`,children:[(0,y.jsxs)(`p`,{className:`text-muted-foreground text-sm`,children:[`Reading the structure of `,f,` and `,_,`...`]}),(0,y.jsx)(c,{className:`h-10`}),(0,y.jsx)(c,{className:`h-10`}),(0,y.jsx)(c,{className:`h-10`})]});let C=h(i.data);if(i.data.changes.length===0)return(0,y.jsxs)(`p`,{className:`text-sm`,children:[f,` and `,_,` are the same`,S,`: `,C.same,` `,C.same===1?`object`:`objects`,` compared.`]});let w=e=>o(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),T=g(i.data.changes,a,l),E=[[`changed`,`${C.changed} differ`],[`only-a`,`${C[`only-a`]} only in ${f}`],[`only-b`,`${C[`only-b`]} only in ${_}`]];return(0,y.jsxs)(`div`,{className:`space-y-4`,children:[(0,y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm`,children:[E.map(([e,t])=>(0,y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 rounded-lg border px-2 py-1 ${e===`changed`?``:x[e===`only-a`?`a`:`b`]}`,children:[(0,y.jsx)(`input`,{type:`checkbox`,checked:a.has(e),onChange:()=>w(e)}),t]},e)),(0,y.jsxs)(`span`,{className:`text-muted-foreground`,children:[C.same,` the same`,S]}),(0,y.jsx)(`input`,{"aria-label":`Filter by name`,className:`${b} ml-auto w-48`,placeholder:`Filter by name...`,value:l,onChange:e=>d(e.target.value)}),(0,y.jsx)(s,{label:`Copy as text`,done:`Copied`,icon:p,text:()=>v(i.data,f,_),disabled:!1})]}),T.length===0&&(0,y.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Nothing matches.`}),T.map(([e,r])=>(0,y.jsxs)(`section`,{className:`space-y-1.5`,children:[(0,y.jsx)(`h3`,{className:`text-accent-text text-sm uppercase tracking-widest`,children:e?`schema ${e}`:`database`}),r.map(e=>(0,y.jsx)(D,{change:e,environment:t,compare:n},`${e.kind}\0${e.name}`))]},e))]})}function k({environment:e,environments:t,compare:n}){let r=n.with;return(0,y.jsxs)(`div`,{className:`space-y-6`,children:[(0,y.jsxs)(`div`,{children:[(0,y.jsxs)(`h2`,{className:`text-accent-text mb-1 flex items-center gap-2 text-2xl`,children:[(0,y.jsx)(d,{className:`size-6`}),` Compare schemas`]}),(0,y.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Tables and their columns, indexes, constraints, triggers and policies, views, functions, sequences, types and extensions, side by side with another environment. Owners, grants, comments and column order are not compared.`})]}),(0,y.jsx)(C,{environment:e,environments:t,compare:n},JSON.stringify(n)),r&&t&&!t.some(e=>e.name===r)?(0,y.jsxs)(`p`,{className:`text-destructive text-sm`,children:[`You do not have access to "`,r,`": it is not in your config.`]}):r&&(0,y.jsx)(O,{environment:e,compare:{...n,with:r}})]})}export{k as CompareView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{at as e}from"./route-
|
|
1
|
+
import{at as e}from"./route-7eu-iAqD.js";var t={name:`copy`,size:24,node:[[`rect`,{width:`14`,height:`14`,x:`8`,y:`8`,rx:`2`,ry:`2`,key:`17jyea`}],[`path`,{d:`M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2`,key:`zix9uf`}]]};t.node;var n=e(t);export{n as t};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{$ as e,a as t,ct as n,o as r,ot as i,r as a,rt as o}from"./route-
|
|
1
|
+
import{$ as e,a as t,ct as n,o as r,ot as i,r as a,rt as o}from"./route-7eu-iAqD.js";import{t as s,z as c}from"./button-BiFx4Lyw.js";import{t as l}from"./copy-C2N9tUYJ.js";import{t as u}from"./loader-circle-BxDJOoJO.js";import{d,i as f,l as p,o as m,p as h,r as g,s as _,u as v}from"./graph-force-ChCGXQUt.js";import{t as y}from"./shield-alert-keJIAND5.js";import{t as b}from"./triangle-alert-C5nF69rW.js";import{$t as x,an as S}from"./index-CpHnjRLv.js";var C=n(i(),1),w=o(),T=8,E=80,D=[[58,120,3],[140,410,2.5],[210,60,2],[260,300,3.5],[330,520,2.5],[380,150,2],[450,380,3],[520,90,2.5],[570,470,2],[90,580,2.5],[300,600,2],[610,260,3]],O=e=>`${e.schema}.${e.name}`,k=(e,t)=>e.length>t?`${e.slice(0,t-1)}…`:e,A={paintOrder:`stroke`};function j({nodes:e,edges:t,selected:n,onSelect:r}){let{frame:i,view:a,setView:o,dragged:s,startDrag:c,zoomBy:l}=v(),[u,y]=(0,C.useState)(),[b,x]=(0,C.useState)(),S=(0,C.useMemo)(()=>{let n=t.map(e=>({source:e.from,target:e.to})),r=new Map;for(let e of t)r.set(e.from,(r.get(e.from)??0)+1),r.set(e.to,(r.get(e.to)??0)+1);let i=m(e.map(e=>({id:e.id,r:T+Math.min(8,Math.sqrt(r.get(e.id)??0))})),n);return _(i,n,400),i},[e,t]),j=(0,C.useMemo)(()=>new Map(S.map(e=>[e.id,e])),[S]),M=(0,C.useCallback)(()=>{let e=i.current?.getBoundingClientRect();if(!e||S.length===0)return;let t=f(S),n=h(t,e);o({k:n.k,x:n.x-t.x*n.k,y:n.y-t.y*n.k})},[S,i,o]);(0,C.useLayoutEffect)(M,[M]);let N=t.map(e=>e.weight===null?NaN:Number(e.weight)),P=N.length>0&&N.every(Number.isFinite),[F,I]=P?[Math.min(...N),Math.max(...N)]:[0,0],L=e=>I>F?1+4*(e-F)/(I-F):2,R=(0,C.useMemo)(()=>{if(!u)return;let e=new Set([u]);for(let n of t)n.from===u&&e.add(n.to),n.to===u&&e.add(n.from);return e},[u,t]);return(0,w.jsxs)(`div`,{className:`relative`,children:[(0,w.jsx)(p,{zoomBy:l,fit:M}),(0,w.jsxs)(`div`,{ref:i,onPointerDown:c,className:`cypher-frame border-border relative h-[60vh] min-h-80 touch-none overflow-hidden border`,children:[(0,w.jsxs)(`svg`,{role:`img`,"aria-label":`Query graph`,width:`100%`,height:`100%`,className:`cursor-grab select-none active:cursor-grabbing`,onClick:()=>!s.current&&r(void 0),children:[(0,w.jsxs)(`defs`,{children:[(0,w.jsx)(`pattern`,{id:`star-chart-grid`,width:48,height:48,patternUnits:`userSpaceOnUse`,children:(0,w.jsx)(`path`,{d:`M48 0H0V48`,fill:`none`,className:`star-grid-line`,strokeWidth:1.4})}),(0,w.jsx)(`pattern`,{id:`star-chart-stars`,width:640,height:640,patternUnits:`userSpaceOnUse`,children:D.map(([e,t,n])=>(0,w.jsx)(`circle`,{cx:e,cy:t,r:n,className:`star-dot`},`${e}-${t}`))})]}),(0,w.jsxs)(`g`,{transform:`translate(${a.x},${a.y}) scale(${a.k})`,children:[(0,w.jsx)(`rect`,{className:`star-chart`,x:-6e3,y:-6e3,width:12e3,height:12e3,fill:`url(#star-chart-grid)`,pointerEvents:`none`}),(0,w.jsx)(`rect`,{className:`star-chart`,x:-6e3,y:-6e3,width:12e3,height:12e3,fill:`url(#star-chart-stars)`,pointerEvents:`none`}),t.map((e,n)=>{let[r,i]=[j.get(e.from),j.get(e.to)];if(!r||!i)return null;let a=g(r,i,!1),o=b===e.id||!!u&&(e.from===u||e.to===u),s=u&&!o?.1:o?.95:.5,c=e.weight!==null&&(t.length<=E||b===e.id||o);return(0,w.jsxs)(`g`,{"data-edge":e.id,children:[(0,w.jsx)(`line`,{...a,className:`cypher-edge stroke-accent-text`,strokeWidth:P?L(N[n]):1.4,opacity:s,strokeLinecap:`round`}),(0,w.jsx)(`line`,{...a,stroke:`transparent`,strokeWidth:12,pointerEvents:`stroke`,onPointerEnter:()=>x(e.id),onPointerLeave:()=>x(void 0),children:(0,w.jsx)(`title`,{children:e.weight??`linked`})}),c&&(0,w.jsx)(`text`,{x:(r.x+i.x)/2,y:(r.y+i.y)/2-3,textAnchor:`middle`,className:`cypher-weight fill-accent-text text-[11px] font-medium`,stroke:`var(--background)`,strokeWidth:3,strokeLinejoin:`round`,style:A,opacity:u&&!o?.15:1,children:e.weight})]},e.id)}),e.map(e=>{let t=j.get(e.id);if(!t)return null;let i=n===e.id;return(0,w.jsxs)(`g`,{transform:`translate(${t.x},${t.y})`,"data-node":e.id,role:`button`,"aria-label":`${O(e.table)} ${e.label}`,"aria-pressed":i,className:`cursor-pointer`,opacity:R&&!R.has(e.id)?.2:1,onPointerDown:e=>e.stopPropagation(),onClick:t=>{t.stopPropagation(),r(i?void 0:e.id)},onPointerEnter:()=>y(e.id),onPointerLeave:()=>y(void 0),children:[(0,w.jsx)(`title`,{children:`${O(e.table)}\n${Object.entries(e.key).map(([e,t])=>`${e} = ${t??`null`}`).join(`, `)}`}),(0,w.jsx)(`circle`,{r:t.r+6,fill:`transparent`}),(0,w.jsx)(`circle`,{className:`cypher-dot`,r:t.r,fill:d(O(e.table)),stroke:i?`var(--primary)`:`var(--background)`,strokeWidth:i?3:1.5}),(0,w.jsx)(`text`,{y:t.r+14,textAnchor:`middle`,className:`cypher-label fill-foreground text-[11px]`,stroke:`var(--background)`,strokeWidth:3,strokeLinejoin:`round`,style:A,children:k(e.label,24)}),(0,w.jsx)(`text`,{y:t.r+26,textAnchor:`middle`,className:`cypher-table fill-muted-foreground text-[9px]`,opacity:.75,stroke:`var(--background)`,strokeWidth:3,strokeLinejoin:`round`,style:A,children:O(e.table)})]},e.id)})]})]}),(0,w.jsxs)(`div`,{className:`cypher-readout`,"aria-hidden":!0,children:[(0,w.jsxs)(`span`,{children:[`Query net `,e.length]}),(0,w.jsxs)(`strong`,{children:[e.length,`.`,t.length]})]})]})]})}var M=[{title:`Products bought by the same customers`,query:`MATCH (a:Product)<-[]-(c:Customer)-[]->(b:Product)
|
|
2
2
|
WHERE a.id < b.id
|
|
3
3
|
RETURN a, b, count(DISTINCT c) AS customers
|
|
4
4
|
ORDER BY customers DESC
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,I as s,L as c,M as l,N as u,O as d,P as f,R as p,S as m,T as h,b as g,ct as _,j as ee,k as te,o as v,ot as y,r as ne,rt as b,w as re,x,z as S}from"./route-DO6IZ7of.js";import{n as C,r as ie,t as w}from"./code-xml-CXkpHeU9.js";import{t as T,z as ae}from"./button-ClA70PLR.js";import{t as E}from"./copy-CCXzeW-s.js";import{Gt as oe,Jt as D,Kt as O,Qt as k,U as se,Wt as A,Yt as ce,en as le,q as ue,qt as j}from"./index-CDcnUacl.js";import{n as M}from"./format-sql-BLj5_RDZ.js";var N=_(y(),1),P=b(),F=`border-input bg-background rounded-lg border px-2 py-1 text-sm`,I=`text-muted-foreground flex items-center gap-1 text-xs`,de=300,L=e=>e.map(e=>/^CREATE (UNLOGGED )?TABLE/.test(e)?e:M(e));function R({issues:e,row:t}){let n=e.filter(e=>e.row===t);return n.length===0?null:(0,P.jsx)(`ul`,{className:`mt-1 text-xs`,children:n.map((e,t)=>(0,P.jsx)(`li`,{className:e.level===`error`?`text-destructive`:e.level===`warning`?`text-amber-500`:`text-muted-foreground`,children:e.message},t))})}var fe=(e,t,n)=>{if(n<0||n>=e.length)return e;let r=[...e];return r.splice(n,0,...r.splice(t,1)),r};function z({label:e,onClick:t,disabled:n,children:r}){return(0,P.jsx)(`button`,{type:`button`,"aria-label":e,title:e,disabled:n,onClick:t,className:`hover:text-accent-text p-1 disabled:opacity-30`,children:r})}function B({label:e,columns:t,value:n,onChange:r}){return(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`group`,"aria-label":e,children:[n.map((i,a)=>(0,P.jsxs)(`span`,{className:`flex items-center`,children:[(0,P.jsxs)(`select`,{"aria-label":`${e} ${a+1}`,value:i,onChange:e=>r(n.map((t,n)=>n===a?e.target.value:t)),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`pick a column`}),t.map(e=>(0,P.jsx)(`option`,{value:e.id,children:e.name||`(no name)`},e.id))]}),(0,P.jsx)(z,{label:`Remove ${e} ${a+1}`,onClick:()=>r(n.filter((e,t)=>t!==a)),children:(0,P.jsx)(j,{className:`size-3.5`})})]},a)),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>r([...n,``]),className:`text-accent-text flex items-center gap-1 text-xs`,children:[(0,P.jsx)(k,{className:`size-3`}),` column`]})]})}function pe({type:e,databaseTypes:t,onChange:n}){let r=u(e),i=e=>e.trim()===``?void 0:Number(e),a=e.schema===void 0||t.some(t=>t.schema===e.schema&&t.name===e.name);return(0,P.jsxs)(`span`,{className:`flex flex-wrap items-center gap-1`,children:[(0,P.jsxs)(`select`,{"aria-label":`Type`,value:S(e),onChange:t=>n({...p(t.target.value),...e.array?{array:e.array}:{}}),className:F,children:[(0,P.jsx)(`optgroup`,{label:`Built in`,children:x.map(e=>(0,P.jsx)(`option`,{value:`b:${e.name}`,children:e.name},e.name))}),(t.length>0||!a)&&(0,P.jsxs)(`optgroup`,{label:`This database`,children:[!a&&(0,P.jsx)(`option`,{value:S(e),children:`${e.schema}.${e.name}`}),t.map(e=>(0,P.jsxs)(`option`,{value:`t:${e.schema}.${e.name}`,children:[e.schema,`.`,e.name,` (`,e.kind,`)`]},`${e.schema}.${e.name}`))]})]}),(r===`length`||r===`precision`)&&(0,P.jsx)(`input`,{"aria-label":r===`length`?`Length`:`Precision`,type:`number`,min:+(r===`length`),placeholder:r===`length`?`length`:`precision`,value:e.length??``,onChange:t=>n({...e,length:i(t.target.value)}),className:`${F} w-20`}),r===`numeric`&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`input`,{"aria-label":`Precision`,type:`number`,min:1,placeholder:`precision`,value:e.precision??``,onChange:t=>n({...e,precision:i(t.target.value)}),className:`${F} w-24`}),(0,P.jsx)(`input`,{"aria-label":`Scale`,type:`number`,min:0,placeholder:`scale`,value:e.scale??``,onChange:t=>n({...e,scale:i(t.target.value)}),className:`${F} w-20`})]}),(0,P.jsxs)(`label`,{className:I,title:`An array of this type`,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:!!e.array,onChange:t=>n({...e,array:t.target.checked?1:void 0})}),`array`]})]})}function me({column:e,at:t,count:n,issues:r,databaseTypes:i,onChange:a,onMove:o,onRemove:s}){let[c,l]=(0,N.useState)(!!(e.default||e.identity||e.generated||e.comment));return(0,P.jsxs)(`li`,{className:`border-border border-b py-2`,"aria-label":`Column ${e.name||t+1}`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`input`,{"aria-label":`Column name`,placeholder:`name`,value:e.name,onChange:t=>a({...e,name:t.target.value}),className:`${F} w-44 font-mono`}),(0,P.jsx)(pe,{type:e.type,databaseTypes:i,onChange:t=>a({...e,type:t})}),(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:e.notNull,onChange:t=>a({...e,notNull:t.target.checked})}),`NOT NULL`]}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>l(!c),"aria-expanded":c,className:`text-accent-text text-xs`,children:c?`less`:`default, identity, comment`}),(0,P.jsxs)(`span`,{className:`ml-auto flex`,children:[(0,P.jsx)(z,{label:`Move up`,disabled:t===0,onClick:()=>o(t-1),children:(0,P.jsx)(C,{className:`size-3.5`})}),(0,P.jsx)(z,{label:`Move down`,disabled:t===n-1,onClick:()=>o(t+1),children:(0,P.jsx)(ie,{className:`size-3.5`})}),(0,P.jsx)(z,{label:`Remove column`,onClick:s,children:(0,P.jsx)(D,{className:`text-destructive size-3.5`})})]})]}),c&&(0,P.jsxs)(`div`,{className:`mt-2 grid gap-2 pl-1 sm:grid-cols-2`,children:[(0,P.jsxs)(`label`,{className:I,children:[`Default`,(0,P.jsx)(`input`,{"aria-label":`Default`,list:`design-defaults`,placeholder:`an expression, or pick one`,value:e.default,onChange:t=>a({...e,default:t.target.value}),className:`${F} flex-1 font-mono`})]}),(0,P.jsxs)(`label`,{className:I,children:[`Identity`,(0,P.jsxs)(`select`,{"aria-label":`Identity`,value:e.identity,onChange:t=>a({...e,identity:t.target.value}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`none`}),(0,P.jsx)(`option`,{value:`always`,children:`GENERATED ALWAYS`}),(0,P.jsx)(`option`,{value:`by default`,children:`GENERATED BY DEFAULT`})]})]}),(0,P.jsxs)(`label`,{className:I,children:[`Generated`,(0,P.jsx)(`input`,{"aria-label":`Generated`,placeholder:`an expression: stored generated column`,value:e.generated,onChange:t=>a({...e,generated:t.target.value}),className:`${F} flex-1 font-mono`})]}),(0,P.jsxs)(`label`,{className:I,children:[`Comment`,(0,P.jsx)(`input`,{"aria-label":`Comment`,value:e.comment,onChange:t=>a({...e,comment:t.target.value}),className:`${F} flex-1`})]})]}),(0,P.jsx)(R,{issues:r,row:e.id})]})}function V({environment:t,form:n,constraint:r,schemas:i,onChange:a,onTarget:o}){let{schema:c,table:l,self:u}=r.target,d=A(()=>c&&!u?e.objects(t,c):Promise.resolve(void 0),`${t}/${c}/${u}`).data?.tables.filter(e=>e.kind===`table`||e.kind===`partitioned`)??[],f=A(()=>c&&l&&!u?e.relation(t,{kind:`table`,schema:c,name:l}):Promise.resolve(void 0),`${t}/${c}/${l}/${u}`).data;(0,N.useEffect)(()=>{f&&o(s(c,l),f.columns.map(e=>({name:e.name,type:e.type})))},[f,c,l,o]);let p=e=>a({...r,...e}),m=e=>p({target:{...r.target,...e},targetColumns:r.columns.map(()=>``)}),h=u?n.columns.map(e=>({value:e.id,label:e.name||`(no name)`})):(f?.columns??[]).map(e=>({value:e.name,label:`${e.name} (${e.type})`})),_=r.columns.length;return(0,P.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`span`,{className:I,children:`References`}),(0,P.jsxs)(`select`,{"aria-label":`Target`,value:u?`__self__`:``,onChange:e=>{e.target.value===`__self__`?m({self:!0,schema:``,table:``}):m({self:!1})},className:F,children:[(0,P.jsx)(`option`,{value:``,children:`a table of the database`}),(0,P.jsx)(`option`,{value:`__self__`,children:`this table`})]}),!u&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`select`,{"aria-label":`Target schema`,value:c,onChange:e=>m({schema:e.target.value,table:``}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`schema`}),i.map(e=>(0,P.jsx)(`option`,{children:e},e))]}),(0,P.jsxs)(`select`,{"aria-label":`Target table`,value:l,onChange:e=>m({table:e.target.value}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`table`}),d.map(e=>(0,P.jsx)(`option`,{children:e.name},e.name))]})]})]}),(0,P.jsx)(`ul`,{className:`flex flex-col gap-1`,"aria-label":`Columns`,children:r.columns.map((e,t)=>(0,P.jsxs)(`li`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,P.jsxs)(`select`,{"aria-label":`Column ${t+1}`,value:e,onChange:e=>p({columns:r.columns.map((n,r)=>r===t?e.target.value:n)}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`pick a column`}),n.columns.map(e=>(0,P.jsx)(`option`,{value:e.id,children:e.name||`(no name)`},e.id))]}),(0,P.jsx)(`span`,{className:`text-accent-text`,children:`→`}),(0,P.jsxs)(`select`,{"aria-label":`Referenced column ${t+1}`,value:r.targetColumns[t]??``,onChange:e=>p({targetColumns:r.columns.map((n,i)=>i===t?e.target.value:r.targetColumns[i]??``)}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`pick a column`}),h.map(e=>(0,P.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),(0,P.jsx)(z,{label:`Remove pair ${t+1}`,onClick:()=>p({columns:r.columns.filter((e,n)=>n!==t),targetColumns:r.targetColumns.filter((e,n)=>n!==t)}),children:(0,P.jsx)(j,{className:`size-3.5`})})]},t))}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>p({columns:[...r.columns,``],targetColumns:[...r.targetColumns.slice(0,_),``]}),className:`text-accent-text flex items-center gap-1 self-start text-xs`,children:[(0,P.jsx)(k,{className:`size-3`}),` column pair`]}),(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[[`onDelete`,`onUpdate`].map(e=>(0,P.jsxs)(`label`,{className:I,children:[e===`onDelete`?`ON DELETE`:`ON UPDATE`,(0,P.jsxs)(`select`,{"aria-label":e===`onDelete`?`On delete`:`On update`,value:r[e],onChange:t=>p({[e]:t.target.value}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`default (no action)`}),g.map(e=>(0,P.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]},e)),(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:r.matchFull,onChange:e=>p({matchFull:e.target.checked})}),`MATCH FULL`]}),(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:r.deferrable,onChange:e=>p({deferrable:e.target.checked,...e.target.checked?{}:{initiallyDeferred:!1}})}),`DEFERRABLE`]}),r.deferrable&&(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:r.initiallyDeferred,onChange:e=>p({initiallyDeferred:e.target.checked})}),`INITIALLY DEFERRED`]})]})]})}var H={primary:`Primary key`,unique:`Unique`,check:`Check`,foreign:`Foreign key`};function he({environment:e,form:t,constraint:n,issues:r,schemas:i,onChange:a,onRemove:s,onTarget:c}){return(0,P.jsxs)(`li`,{className:`border-border border-b py-2`,"aria-label":H[n.kind],children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`strong`,{className:`text-accent-text w-28 text-sm`,children:H[n.kind]}),(0,P.jsx)(`input`,{"aria-label":`Constraint name`,placeholder:o(t,n),value:n.name,onChange:e=>a({...n,name:e.target.value}),className:`${F} w-64 font-mono`}),n.kind===`unique`&&(0,P.jsxs)(`label`,{className:I,title:`PostgreSQL 15 and later`,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:n.nullsNotDistinct,onChange:e=>a({...n,nullsNotDistinct:e.target.checked})}),`NULLS NOT DISTINCT`]}),(0,P.jsx)(`span`,{className:`ml-auto`,children:(0,P.jsx)(z,{label:`Remove ${H[n.kind].toLowerCase()}`,onClick:s,children:(0,P.jsx)(D,{className:`text-destructive size-3.5`})})})]}),(0,P.jsxs)(`div`,{className:`mt-2`,children:[(n.kind===`primary`||n.kind===`unique`)&&(0,P.jsx)(B,{label:`Column`,columns:t.columns,value:n.columns,onChange:e=>a({...n,columns:e})}),n.kind===`check`&&(0,P.jsx)(`input`,{"aria-label":`Check expression`,placeholder:`e.g. total >= 0`,value:n.expression,onChange:e=>a({...n,expression:e.target.value}),className:`${F} w-full font-mono`}),n.kind===`foreign`&&(0,P.jsx)(V,{environment:e,form:t,constraint:n,schemas:i,onChange:a,onTarget:c})]}),(0,P.jsx)(R,{issues:r,row:n.id})]})}function ge({form:e,index:t,issues:n,onChange:i,onRemove:a}){return(0,P.jsxs)(`li`,{className:`border-border border-b py-2`,"aria-label":`Index`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`input`,{"aria-label":`Index name`,placeholder:f(e,t),value:t.name,onChange:e=>i({...t,name:e.target.value}),className:`${F} w-64 font-mono`}),(0,P.jsx)(`select`,{"aria-label":`Method`,value:t.method,onChange:e=>i({...t,method:e.target.value}),className:F,children:r.map(e=>(0,P.jsx)(`option`,{children:e},e))}),(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:t.unique,onChange:e=>i({...t,unique:e.target.checked})}),`UNIQUE`]}),(0,P.jsx)(`span`,{className:`ml-auto`,children:(0,P.jsx)(z,{label:`Remove index`,onClick:a,children:(0,P.jsx)(D,{className:`text-destructive size-3.5`})})})]}),(0,P.jsx)(`ul`,{className:`mt-2 flex flex-col gap-1`,"aria-label":`Index items`,children:t.items.map((n,r)=>{let a=e=>i({...t,items:t.items.map(t=>t.id===n.id?{...t,...e}:t)});return(0,P.jsxs)(`li`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,P.jsxs)(`select`,{"aria-label":`Item ${r+1}`,value:n.column||`__expr__`,onChange:e=>e.target.value===`__expr__`?a({column:``}):a({column:e.target.value}),className:F,children:[(0,P.jsx)(`option`,{value:`__expr__`,children:`an expression`}),e.columns.map(e=>(0,P.jsx)(`option`,{value:e.id,children:e.name||`(no name)`},e.id))]}),!n.column&&(0,P.jsx)(`input`,{"aria-label":`Expression ${r+1}`,placeholder:`e.g. lower(email)`,value:n.expression,onChange:e=>a({expression:e.target.value}),className:`${F} w-64 font-mono`}),(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:n.descending,onChange:e=>a({descending:e.target.checked})}),`DESC`]}),(0,P.jsx)(z,{label:`Remove item ${r+1}`,onClick:()=>i({...t,items:t.items.filter(e=>e.id!==n.id)}),children:(0,P.jsx)(j,{className:`size-3.5`})})]},n.id)})}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>i({...t,items:[...t.items,ee()]}),className:`text-accent-text mt-1 flex items-center gap-1 text-xs`,children:[(0,P.jsx)(k,{className:`size-3`}),` column or expression`]}),(0,P.jsxs)(`div`,{className:`mt-2 grid gap-2 sm:grid-cols-2`,children:[(0,P.jsxs)(`label`,{className:I,children:[`WHERE`,(0,P.jsx)(`input`,{"aria-label":`Where`,placeholder:`a partial index: an expression`,value:t.where,onChange:e=>i({...t,where:e.target.value}),className:`${F} flex-1 font-mono`})]}),(0,P.jsxs)(`div`,{className:I,children:[`INCLUDE`,(0,P.jsx)(B,{label:`Included column`,columns:e.columns,value:t.include,onChange:e=>i({...t,include:e})})]})]}),(0,P.jsx)(R,{issues:n,row:t.id})]})}function _e({statements:e,error:t,failed:n,failure:r,pending:i,onOpenInSql:a}){let[o,s]=(0,N.useState)(!1),c=e?L(e).map(e=>`${e};`).join(`
|
|
1
|
+
import{$ as e,A as t,B as n,C as r,D as i,E as a,F as o,I as s,L as c,M as l,N as u,O as d,P as f,R as p,S as m,T as h,b as g,ct as _,j as ee,k as te,o as v,ot as y,r as ne,rt as b,w as re,x,z as S}from"./route-7eu-iAqD.js";import{n as C,r as ie,t as w}from"./code-xml-CPEjNFOw.js";import{t as T,z as ae}from"./button-BiFx4Lyw.js";import{t as E}from"./copy-C2N9tUYJ.js";import{Gt as oe,Jt as D,Kt as O,Qt as k,U as se,Wt as A,Yt as ce,en as le,q as ue,qt as j}from"./index-CpHnjRLv.js";import{n as M}from"./format-sql-CoddYUOF.js";var N=_(y(),1),P=b(),F=`border-input bg-background rounded-lg border px-2 py-1 text-sm`,I=`text-muted-foreground flex items-center gap-1 text-xs`,de=300,L=e=>e.map(e=>/^CREATE (UNLOGGED )?TABLE/.test(e)?e:M(e));function R({issues:e,row:t}){let n=e.filter(e=>e.row===t);return n.length===0?null:(0,P.jsx)(`ul`,{className:`mt-1 text-xs`,children:n.map((e,t)=>(0,P.jsx)(`li`,{className:e.level===`error`?`text-destructive`:e.level===`warning`?`text-amber-500`:`text-muted-foreground`,children:e.message},t))})}var fe=(e,t,n)=>{if(n<0||n>=e.length)return e;let r=[...e];return r.splice(n,0,...r.splice(t,1)),r};function z({label:e,onClick:t,disabled:n,children:r}){return(0,P.jsx)(`button`,{type:`button`,"aria-label":e,title:e,disabled:n,onClick:t,className:`hover:text-accent-text p-1 disabled:opacity-30`,children:r})}function B({label:e,columns:t,value:n,onChange:r}){return(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,role:`group`,"aria-label":e,children:[n.map((i,a)=>(0,P.jsxs)(`span`,{className:`flex items-center`,children:[(0,P.jsxs)(`select`,{"aria-label":`${e} ${a+1}`,value:i,onChange:e=>r(n.map((t,n)=>n===a?e.target.value:t)),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`pick a column`}),t.map(e=>(0,P.jsx)(`option`,{value:e.id,children:e.name||`(no name)`},e.id))]}),(0,P.jsx)(z,{label:`Remove ${e} ${a+1}`,onClick:()=>r(n.filter((e,t)=>t!==a)),children:(0,P.jsx)(j,{className:`size-3.5`})})]},a)),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>r([...n,``]),className:`text-accent-text flex items-center gap-1 text-xs`,children:[(0,P.jsx)(k,{className:`size-3`}),` column`]})]})}function pe({type:e,databaseTypes:t,onChange:n}){let r=u(e),i=e=>e.trim()===``?void 0:Number(e),a=e.schema===void 0||t.some(t=>t.schema===e.schema&&t.name===e.name);return(0,P.jsxs)(`span`,{className:`flex flex-wrap items-center gap-1`,children:[(0,P.jsxs)(`select`,{"aria-label":`Type`,value:S(e),onChange:t=>n({...p(t.target.value),...e.array?{array:e.array}:{}}),className:F,children:[(0,P.jsx)(`optgroup`,{label:`Built in`,children:x.map(e=>(0,P.jsx)(`option`,{value:`b:${e.name}`,children:e.name},e.name))}),(t.length>0||!a)&&(0,P.jsxs)(`optgroup`,{label:`This database`,children:[!a&&(0,P.jsx)(`option`,{value:S(e),children:`${e.schema}.${e.name}`}),t.map(e=>(0,P.jsxs)(`option`,{value:`t:${e.schema}.${e.name}`,children:[e.schema,`.`,e.name,` (`,e.kind,`)`]},`${e.schema}.${e.name}`))]})]}),(r===`length`||r===`precision`)&&(0,P.jsx)(`input`,{"aria-label":r===`length`?`Length`:`Precision`,type:`number`,min:+(r===`length`),placeholder:r===`length`?`length`:`precision`,value:e.length??``,onChange:t=>n({...e,length:i(t.target.value)}),className:`${F} w-20`}),r===`numeric`&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`input`,{"aria-label":`Precision`,type:`number`,min:1,placeholder:`precision`,value:e.precision??``,onChange:t=>n({...e,precision:i(t.target.value)}),className:`${F} w-24`}),(0,P.jsx)(`input`,{"aria-label":`Scale`,type:`number`,min:0,placeholder:`scale`,value:e.scale??``,onChange:t=>n({...e,scale:i(t.target.value)}),className:`${F} w-20`})]}),(0,P.jsxs)(`label`,{className:I,title:`An array of this type`,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:!!e.array,onChange:t=>n({...e,array:t.target.checked?1:void 0})}),`array`]})]})}function me({column:e,at:t,count:n,issues:r,databaseTypes:i,onChange:a,onMove:o,onRemove:s}){let[c,l]=(0,N.useState)(!!(e.default||e.identity||e.generated||e.comment));return(0,P.jsxs)(`li`,{className:`border-border border-b py-2`,"aria-label":`Column ${e.name||t+1}`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`input`,{"aria-label":`Column name`,placeholder:`name`,value:e.name,onChange:t=>a({...e,name:t.target.value}),className:`${F} w-44 font-mono`}),(0,P.jsx)(pe,{type:e.type,databaseTypes:i,onChange:t=>a({...e,type:t})}),(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:e.notNull,onChange:t=>a({...e,notNull:t.target.checked})}),`NOT NULL`]}),(0,P.jsx)(`button`,{type:`button`,onClick:()=>l(!c),"aria-expanded":c,className:`text-accent-text text-xs`,children:c?`less`:`default, identity, comment`}),(0,P.jsxs)(`span`,{className:`ml-auto flex`,children:[(0,P.jsx)(z,{label:`Move up`,disabled:t===0,onClick:()=>o(t-1),children:(0,P.jsx)(C,{className:`size-3.5`})}),(0,P.jsx)(z,{label:`Move down`,disabled:t===n-1,onClick:()=>o(t+1),children:(0,P.jsx)(ie,{className:`size-3.5`})}),(0,P.jsx)(z,{label:`Remove column`,onClick:s,children:(0,P.jsx)(D,{className:`text-destructive size-3.5`})})]})]}),c&&(0,P.jsxs)(`div`,{className:`mt-2 grid gap-2 pl-1 sm:grid-cols-2`,children:[(0,P.jsxs)(`label`,{className:I,children:[`Default`,(0,P.jsx)(`input`,{"aria-label":`Default`,list:`design-defaults`,placeholder:`an expression, or pick one`,value:e.default,onChange:t=>a({...e,default:t.target.value}),className:`${F} flex-1 font-mono`})]}),(0,P.jsxs)(`label`,{className:I,children:[`Identity`,(0,P.jsxs)(`select`,{"aria-label":`Identity`,value:e.identity,onChange:t=>a({...e,identity:t.target.value}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`none`}),(0,P.jsx)(`option`,{value:`always`,children:`GENERATED ALWAYS`}),(0,P.jsx)(`option`,{value:`by default`,children:`GENERATED BY DEFAULT`})]})]}),(0,P.jsxs)(`label`,{className:I,children:[`Generated`,(0,P.jsx)(`input`,{"aria-label":`Generated`,placeholder:`an expression: stored generated column`,value:e.generated,onChange:t=>a({...e,generated:t.target.value}),className:`${F} flex-1 font-mono`})]}),(0,P.jsxs)(`label`,{className:I,children:[`Comment`,(0,P.jsx)(`input`,{"aria-label":`Comment`,value:e.comment,onChange:t=>a({...e,comment:t.target.value}),className:`${F} flex-1`})]})]}),(0,P.jsx)(R,{issues:r,row:e.id})]})}function V({environment:t,form:n,constraint:r,schemas:i,onChange:a,onTarget:o}){let{schema:c,table:l,self:u}=r.target,d=A(()=>c&&!u?e.objects(t,c):Promise.resolve(void 0),`${t}/${c}/${u}`).data?.tables.filter(e=>e.kind===`table`||e.kind===`partitioned`)??[],f=A(()=>c&&l&&!u?e.relation(t,{kind:`table`,schema:c,name:l}):Promise.resolve(void 0),`${t}/${c}/${l}/${u}`).data;(0,N.useEffect)(()=>{f&&o(s(c,l),f.columns.map(e=>({name:e.name,type:e.type})))},[f,c,l,o]);let p=e=>a({...r,...e}),m=e=>p({target:{...r.target,...e},targetColumns:r.columns.map(()=>``)}),h=u?n.columns.map(e=>({value:e.id,label:e.name||`(no name)`})):(f?.columns??[]).map(e=>({value:e.name,label:`${e.name} (${e.type})`})),_=r.columns.length;return(0,P.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`span`,{className:I,children:`References`}),(0,P.jsxs)(`select`,{"aria-label":`Target`,value:u?`__self__`:``,onChange:e=>{e.target.value===`__self__`?m({self:!0,schema:``,table:``}):m({self:!1})},className:F,children:[(0,P.jsx)(`option`,{value:``,children:`a table of the database`}),(0,P.jsx)(`option`,{value:`__self__`,children:`this table`})]}),!u&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)(`select`,{"aria-label":`Target schema`,value:c,onChange:e=>m({schema:e.target.value,table:``}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`schema`}),i.map(e=>(0,P.jsx)(`option`,{children:e},e))]}),(0,P.jsxs)(`select`,{"aria-label":`Target table`,value:l,onChange:e=>m({table:e.target.value}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`table`}),d.map(e=>(0,P.jsx)(`option`,{children:e.name},e.name))]})]})]}),(0,P.jsx)(`ul`,{className:`flex flex-col gap-1`,"aria-label":`Columns`,children:r.columns.map((e,t)=>(0,P.jsxs)(`li`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,P.jsxs)(`select`,{"aria-label":`Column ${t+1}`,value:e,onChange:e=>p({columns:r.columns.map((n,r)=>r===t?e.target.value:n)}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`pick a column`}),n.columns.map(e=>(0,P.jsx)(`option`,{value:e.id,children:e.name||`(no name)`},e.id))]}),(0,P.jsx)(`span`,{className:`text-accent-text`,children:`→`}),(0,P.jsxs)(`select`,{"aria-label":`Referenced column ${t+1}`,value:r.targetColumns[t]??``,onChange:e=>p({targetColumns:r.columns.map((n,i)=>i===t?e.target.value:r.targetColumns[i]??``)}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`pick a column`}),h.map(e=>(0,P.jsx)(`option`,{value:e.value,children:e.label},e.value))]}),(0,P.jsx)(z,{label:`Remove pair ${t+1}`,onClick:()=>p({columns:r.columns.filter((e,n)=>n!==t),targetColumns:r.targetColumns.filter((e,n)=>n!==t)}),children:(0,P.jsx)(j,{className:`size-3.5`})})]},t))}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>p({columns:[...r.columns,``],targetColumns:[...r.targetColumns.slice(0,_),``]}),className:`text-accent-text flex items-center gap-1 self-start text-xs`,children:[(0,P.jsx)(k,{className:`size-3`}),` column pair`]}),(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[[`onDelete`,`onUpdate`].map(e=>(0,P.jsxs)(`label`,{className:I,children:[e===`onDelete`?`ON DELETE`:`ON UPDATE`,(0,P.jsxs)(`select`,{"aria-label":e===`onDelete`?`On delete`:`On update`,value:r[e],onChange:t=>p({[e]:t.target.value}),className:F,children:[(0,P.jsx)(`option`,{value:``,children:`default (no action)`}),g.map(e=>(0,P.jsx)(`option`,{value:e,children:e.toUpperCase()},e))]})]},e)),(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:r.matchFull,onChange:e=>p({matchFull:e.target.checked})}),`MATCH FULL`]}),(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:r.deferrable,onChange:e=>p({deferrable:e.target.checked,...e.target.checked?{}:{initiallyDeferred:!1}})}),`DEFERRABLE`]}),r.deferrable&&(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:r.initiallyDeferred,onChange:e=>p({initiallyDeferred:e.target.checked})}),`INITIALLY DEFERRED`]})]})]})}var H={primary:`Primary key`,unique:`Unique`,check:`Check`,foreign:`Foreign key`};function he({environment:e,form:t,constraint:n,issues:r,schemas:i,onChange:a,onRemove:s,onTarget:c}){return(0,P.jsxs)(`li`,{className:`border-border border-b py-2`,"aria-label":H[n.kind],children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`strong`,{className:`text-accent-text w-28 text-sm`,children:H[n.kind]}),(0,P.jsx)(`input`,{"aria-label":`Constraint name`,placeholder:o(t,n),value:n.name,onChange:e=>a({...n,name:e.target.value}),className:`${F} w-64 font-mono`}),n.kind===`unique`&&(0,P.jsxs)(`label`,{className:I,title:`PostgreSQL 15 and later`,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:n.nullsNotDistinct,onChange:e=>a({...n,nullsNotDistinct:e.target.checked})}),`NULLS NOT DISTINCT`]}),(0,P.jsx)(`span`,{className:`ml-auto`,children:(0,P.jsx)(z,{label:`Remove ${H[n.kind].toLowerCase()}`,onClick:s,children:(0,P.jsx)(D,{className:`text-destructive size-3.5`})})})]}),(0,P.jsxs)(`div`,{className:`mt-2`,children:[(n.kind===`primary`||n.kind===`unique`)&&(0,P.jsx)(B,{label:`Column`,columns:t.columns,value:n.columns,onChange:e=>a({...n,columns:e})}),n.kind===`check`&&(0,P.jsx)(`input`,{"aria-label":`Check expression`,placeholder:`e.g. total >= 0`,value:n.expression,onChange:e=>a({...n,expression:e.target.value}),className:`${F} w-full font-mono`}),n.kind===`foreign`&&(0,P.jsx)(V,{environment:e,form:t,constraint:n,schemas:i,onChange:a,onTarget:c})]}),(0,P.jsx)(R,{issues:r,row:n.id})]})}function ge({form:e,index:t,issues:n,onChange:i,onRemove:a}){return(0,P.jsxs)(`li`,{className:`border-border border-b py-2`,"aria-label":`Index`,children:[(0,P.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`input`,{"aria-label":`Index name`,placeholder:f(e,t),value:t.name,onChange:e=>i({...t,name:e.target.value}),className:`${F} w-64 font-mono`}),(0,P.jsx)(`select`,{"aria-label":`Method`,value:t.method,onChange:e=>i({...t,method:e.target.value}),className:F,children:r.map(e=>(0,P.jsx)(`option`,{children:e},e))}),(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:t.unique,onChange:e=>i({...t,unique:e.target.checked})}),`UNIQUE`]}),(0,P.jsx)(`span`,{className:`ml-auto`,children:(0,P.jsx)(z,{label:`Remove index`,onClick:a,children:(0,P.jsx)(D,{className:`text-destructive size-3.5`})})})]}),(0,P.jsx)(`ul`,{className:`mt-2 flex flex-col gap-1`,"aria-label":`Index items`,children:t.items.map((n,r)=>{let a=e=>i({...t,items:t.items.map(t=>t.id===n.id?{...t,...e}:t)});return(0,P.jsxs)(`li`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,P.jsxs)(`select`,{"aria-label":`Item ${r+1}`,value:n.column||`__expr__`,onChange:e=>e.target.value===`__expr__`?a({column:``}):a({column:e.target.value}),className:F,children:[(0,P.jsx)(`option`,{value:`__expr__`,children:`an expression`}),e.columns.map(e=>(0,P.jsx)(`option`,{value:e.id,children:e.name||`(no name)`},e.id))]}),!n.column&&(0,P.jsx)(`input`,{"aria-label":`Expression ${r+1}`,placeholder:`e.g. lower(email)`,value:n.expression,onChange:e=>a({expression:e.target.value}),className:`${F} w-64 font-mono`}),(0,P.jsxs)(`label`,{className:I,children:[(0,P.jsx)(`input`,{type:`checkbox`,checked:n.descending,onChange:e=>a({descending:e.target.checked})}),`DESC`]}),(0,P.jsx)(z,{label:`Remove item ${r+1}`,onClick:()=>i({...t,items:t.items.filter(e=>e.id!==n.id)}),children:(0,P.jsx)(j,{className:`size-3.5`})})]},n.id)})}),(0,P.jsxs)(`button`,{type:`button`,onClick:()=>i({...t,items:[...t.items,ee()]}),className:`text-accent-text mt-1 flex items-center gap-1 text-xs`,children:[(0,P.jsx)(k,{className:`size-3`}),` column or expression`]}),(0,P.jsxs)(`div`,{className:`mt-2 grid gap-2 sm:grid-cols-2`,children:[(0,P.jsxs)(`label`,{className:I,children:[`WHERE`,(0,P.jsx)(`input`,{"aria-label":`Where`,placeholder:`a partial index: an expression`,value:t.where,onChange:e=>i({...t,where:e.target.value}),className:`${F} flex-1 font-mono`})]}),(0,P.jsxs)(`div`,{className:I,children:[`INCLUDE`,(0,P.jsx)(B,{label:`Included column`,columns:e.columns,value:t.include,onChange:e=>i({...t,include:e})})]})]}),(0,P.jsx)(R,{issues:n,row:t.id})]})}function _e({statements:e,error:t,failed:n,failure:r,pending:i,onOpenInSql:a}){let[o,s]=(0,N.useState)(!1),c=e?L(e).map(e=>`${e};`).join(`
|
|
2
2
|
|
|
3
3
|
`):``;return(0,P.jsxs)(`section`,{"aria-label":`SQL`,className:`border-input bg-card border p-3`,children:[(0,P.jsxs)(`div`,{className:`mb-2 flex flex-wrap items-center gap-2`,children:[(0,P.jsx)(`h3`,{className:`text-accent-text text-sm uppercase tracking-widest`,children:`SQL`}),i&&(0,P.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`updating...`}),(0,P.jsxs)(`span`,{className:`ml-auto flex gap-2`,children:[(0,P.jsxs)(T,{variant:`outline`,size:`sm`,onClick:()=>{navigator.clipboard.writeText(c).then(()=>{s(!0),window.setTimeout(()=>s(!1),1500)},()=>void 0)},disabled:!c,children:[o?(0,P.jsx)(ae,{}):(0,P.jsx)(E,{}),` `,o?`Copied`:`Copy`]}),(0,P.jsxs)(T,{variant:`outline`,size:`sm`,onClick:a,disabled:!c,children:[(0,P.jsx)(w,{}),` Open in SQL`]})]})]}),t&&(0,P.jsx)(`p`,{className:`text-muted-foreground mb-2 text-xs`,children:t}),e&&(0,P.jsx)(`ol`,{className:`flex flex-col gap-2`,children:L(e).map((e,t)=>(0,P.jsxs)(`li`,{className:n===t?`border-destructive border-l-2 pl-2`:``,children:[(0,P.jsxs)(`pre`,{className:`font-mono text-xs whitespace-pre-wrap`,children:[e,`;`]}),n===t&&r&&(0,P.jsx)(`p`,{role:`alert`,className:`text-destructive mt-1 text-xs whitespace-pre-wrap`,children:r})]},t))}),!e&&!t&&(0,P.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Nothing to show yet.`})]})}var ve={using:{},notValid:[],concurrently:[],cascade:[]},U=(e,t,n)=>n?[...e.filter(e=>e!==t),t]:e.filter(e=>e!==t);function W({environment:t,target:n,cascade:r}){let i=A(()=>e.dependentsOf(t,n),JSON.stringify(n));if(i.error)return(0,P.jsxs)(`p`,{className:`text-muted-foreground text-xs`,children:[`Could not list what depends on it: `,i.error]});if(!i.data)return(0,P.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Looking for what depends on it...`});let a=i.data.dependents.filter(e=>e.blocking),o=i.data.mentions;return a.length===0&&o.length===0?(0,P.jsx)(`p`,{className:`text-muted-foreground text-xs`,children:`Nothing else depends on it.`}):(0,P.jsxs)(`div`,{className:`mt-1 text-xs`,children:[a.length>0&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)(`p`,{className:r?`text-amber-500`:`text-destructive`,children:r?`CASCADE also drops ${a.length} dependent ${a.length===1?`object`:`objects`}:`:`A plain DROP refuses while ${a.length===1?`this exists`:`these exist`}:`}),(0,P.jsx)(`ul`,{"aria-label":`Dependents`,children:a.map(e=>(0,P.jsxs)(`li`,{className:`flex flex-wrap items-baseline gap-2`,children:[(0,P.jsx)(O,{variant:`outline`,children:e.type}),(0,P.jsx)(`span`,{className:`font-mono break-all`,children:e.identity})]},`${e.type}:${e.identity}`))})]}),o.length>0&&(0,P.jsxs)(`p`,{className:`text-muted-foreground`,children:[`Mentioned in function bodies, which only fail when next run:`,` `,o.map(e=>`${e.schema}.${e.name}`).join(`, `),`.`]})]})}var G=e=>e.kind===`column`||e.kind===`constraint`?{kind:e.kind,schema:e.schema,table:e.name,name:e.detail??``}:{kind:e.kind,schema:e.schema,name:e.name},ye=e=>{let t=e.statements.filter(e=>!e.concurrent),n=e.statements.filter(e=>e.concurrent);return{lockTimeout:t.length>0?e.lockTimeout:null,inside:t,apart:n,all:[...t.length>0&&e.lockTimeout?[e.lockTimeout]:[],...t.map(e=>e.sql),...n.map(e=>e.sql)]}};function be({environment:e,plan:t,error:n,options:r,onOptions:i,lockSeconds:a,onLockSeconds:o,failed:s,failure:c,pending:l,onOpenInSql:u}){let[d,f]=(0,N.useState)(!1),p=t?ye(t):void 0,m=p?p.all.map(e=>`${e};`).join(`
|
|
4
4
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{$ as e,ct as t,o as n,ot as r,rt as i}from"./route-
|
|
1
|
+
import{$ as e,ct as t,o as n,ot as r,rt as i}from"./route-7eu-iAqD.js";import{Gt as a,Wt as o,tn as s}from"./index-CpHnjRLv.js";var c=t(r(),1),l=i(),u=260,d=30,f=22,p=40,m=24,h=12,g=6,_=5;function v(e){let t=new Set(e.map(e=>e.name));return e.flatMap(e=>e.columns.flatMap(n=>{let r=n.references;return r&&r.schema===e.schema&&r.table!==e.name&&t.has(r.table)?[[e.name,r.table]]:[]}))}function y(e){let t=Math.max(1,Math.round(Math.sqrt(e.length))),n=Math.ceil(e.length/t)*t,r=v(e),i=e=>{let n=new Map;return e.forEach((e,t)=>e&&n.set(e.name,t)),r.reduce((e,[r,i])=>{let[a,o]=[n.get(r),n.get(i)],s=Math.abs(a%t-o%t),c=Math.abs(Math.floor(a/t)-Math.floor(o/t));return e+s+c+(s>1?3:0)+(s===0?.5:0)},0)},a=t=>{let r=t,a=i(r);for(let t=0;t<20&&e.length<=150;t++){let e=!1;for(let t=0;t<n;t++)for(let o=t+1;o<n;o++){if(!r[t]&&!r[o])continue;let n=[...r];[n[t],n[o]]=[n[o],n[t]];let s=i(n);s<a-1e-9&&(r=n,a=s,e=!0)}if(!e)break}return{cells:r,best:a}},o=new Map;for(let[e,t]of r)for(let n of[e,t])o.set(n,(o.get(n)??0)+1);let s=[...e].sort((e,t)=>(o.get(t.name)??0)-(o.get(e.name)??0)),c=[];for(;s.length>0;){c.push(s.shift());for(let e=0;e<c.length;e++)for(let[t,n]of r){let r=t===c[e].name?n:n===c[e].name?t:void 0,i=s.findIndex(e=>e.name===r);i>=0&&c.push(...s.splice(i,1))}}let l=e=>[...e,...Array(n-e.length).fill(void 0)],{cells:u}=[a(l(e)),a(l(c))].sort((e,t)=>e.best-t.best)[0],d=[];for(let e=0;e<n;e+=t)d.push(u.slice(e,e+t));let f=d.filter(e=>e.some(Boolean)),p=Array.from({length:t},(e,t)=>f.some(e=>e[t])).flatMap((e,t)=>e?[t]:[]);return f.map(e=>p.map(t=>e[t]))}function b(e,t,n){let r=new Map,i=[],a=m,o=m;return e.forEach((e,s)=>{let c=m,l=0;e.forEach((e,n)=>{if(e){let t=a+(n%2==1?f/2:0),i=d+f*Math.max(e.columns.length,1);r.set(e.name,{table:e,x:c,y:t,height:i,col:n,row:s}),l=Math.max(l,t+i-a)}c+=u+t}),o=Math.max(o,c-t/2+m),i.push(a+l+n/2),a+=l+n}),{boxes:r,width:o,height:a-n+m,channels:i}}function x(e,t,n,r){let i=e.y+d+f*t+f/2,a=n.y+d+f*r+f/2;if(n.col===e.col){let t=e.x+u;return{x1:t,y1:i,dir1:1,x2:t,y2:a,dir2:1,gaps:[e.col]}}let o=n.col>e.col,s={x1:o?e.x+u:e.x,y1:i,dir1:o?1:-1,x2:o?n.x:n.x+u,y2:a,dir2:o?-1:1};return Math.abs(n.col-e.col)===1?{...s,gaps:[Math.min(e.col,n.col)]}:{...s,gaps:o?[e.col,n.col-1]:[e.col-1,n.col],channel:n.row<e.row?e.row-1:e.row}}function S(e){let t=[...e.values()].flatMap(t=>t.table.columns.flatMap((n,r)=>{let i=n.references,a=i&&i.schema===t.table.schema?e.get(i.table):void 0,o=a?.table.columns.findIndex(e=>e.name===i?.column)??-1;return!a||o<0?[]:[{...x(t,r,a,o),key:`${t.table.name}.${n.name}`,unique:n.unique,optional:n.nullable}]})),n=new Map;for(let e of t)for(let[t,r]of[[1,e.y2],[2,e.y1]]){let i=`${e[`x${t}`]},${e[`y${t}`]}`;n.set(i,[...n.get(i)??[],{plan:e,end:t,other:r}])}for(let e of n.values()){if(e.length<2)continue;e.sort((e,t)=>e.other-t.other);let t=Math.min(5,14/(e.length-1));e.forEach(({plan:n,end:r},i)=>{n[`y${r}`]+=(i-(e.length-1)/2)*t})}return t}function C(e){let t=new Map,n=new Map;for(let r of e){for(let e of r.gaps)t.set(e,(t.get(e)??0)+1);r.channel!==void 0&&n.set(r.channel,(n.get(r.channel)??0)+1)}return{gap:Math.max(0,...t.values()),channel:Math.max(0,...n.values())}}function w(e,t,n){let r=new Map,i=new Map;for(let t of e)t.channel!==void 0&&i.set(t.channel,[...i.get(t.channel)??[],t]);for(let[e,n]of i)n.sort((e,t)=>e.x1+e.x2-(t.x1+t.x2)),n.forEach((i,a)=>{r.set(i.key,t.channels[e]+(a-(n.length-1)/2)*h)});let a=e.flatMap(e=>e.gaps.map((t,n)=>{let i=r.get(e.key),[a,o]=e.gaps.length===1?[e.y1,e.y2]:n===0?[e.y1,i]:[i,e.y2];return{key:e.key,index:n,gap:t,from:a,to:o}})),o=new Map,s=new Map;for(let e of a)s.set(e.gap,[...s.get(e.gap)??[],e]);for(let[e,t]of s){t.sort((e,t)=>e.from+e.to-(t.from+t.to));let r=m+e*(u+n)+u+n/2;t.forEach((e,n)=>{o.set(`${e.key}:${e.index}`,r+(n-(t.length-1)/2)*h)})}return new Map(e.map(e=>{let t=t=>o.get(`${e.key}:${t}`),n=r.get(e.key),i=e.gaps.length===1?[[e.x1,e.y1],[t(0),e.y1],[t(0),e.y2],[e.x2,e.y2]]:[[e.x1,e.y1],[t(0),e.y1],[t(0),n],[t(1),n],[t(1),e.y2],[e.x2,e.y2]];return[e.key,i]}))}function T(e,t,n){let r=(e,t)=>Math.hypot(t[0]-e[0],t[1]-e[1])||1,i=(e,t,n)=>[e[0]+(t[0]-e[0])/r(e,t)*n,e[1]+(t[1]-e[1])/r(e,t)*n],a=(t,r)=>{if(t[1]!==r[1])return`L${r[0]},${r[1]}`;let i=Math.sign(r[0]-t[0]),a=t[1],o=Math.min(t[0],r[0])+_+1,s=Math.max(t[0],r[0])-_-1,c=n.filter(t=>t.key!==e&&t.x>o&&t.x<s&&t.top<a&&a<t.bottom).map(e=>e.x).sort((e,t)=>i*(e-t)),l=``,u=-1/0;for(let e of c)i*e<u+10+2||(u=i*e,l+=`L${e-i*_},${a} A${_},${_} 0 0 ${+(i>0)} ${e+i*_},${a} `);return`${l}L${r[0]},${r[1]}`},o=`M${t[0][0]},${t[0][1]} `,s=t[0];for(let e=1;e<t.length-1;e++){let[n,c,l]=[t[e-1],t[e],t[e+1]],u=i(c,n,Math.min(g,r(n,c)/2)),d=i(c,l,Math.min(g,r(c,l)/2));o+=`${a(s,u)} Q${c[0]},${c[1]} ${d[0]},${d[1]} `,s=d}return o+a(s,t[t.length-1])}var E=(e,t)=>`M${e},${t-6} L${e},${t+6}`;function D({x:e,y:t,dir:n,unique:r}){let i={cx:e+n*18,cy:t,r:4};return{symbol:r?E(e+n*9,t):`M${e+n*12},${t} L${e},${t-6} M${e+n*12},${t} L${e},${t+6} M${e+n*12},${t} L${e},${t}`,ring:i}}function O({x:e,y:t,dir:n,optional:r}){return r?{symbol:E(e+n*8,t),ring:{cx:e+n*16,cy:t,r:4}}:{symbol:`${E(e+n*8,t)} ${E(e+n*14,t)}`,ring:void 0}}function k({symbol:e,ring:t}){return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(`path`,{d:e,fill:`none`,strokeWidth:1.5,className:`stroke-accent-text`}),t&&(0,l.jsx)(`circle`,{...t,strokeWidth:1.5,className:`fill-card stroke-accent-text`})]})}function A({environment:e,tables:t}){let{boxes:r,width:i,height:a,edges:o}=(0,c.useMemo)(()=>{let e=y(t),{gap:n,channel:r}=C(S(b(e,60,p).boxes)),i=48+h*(n+1),a=b(e,i,Math.max(p,h*(r+1))),o=S(a.boxes),s=w(o,a,i),c=[...s].flatMap(([e,t])=>t.slice(0,-1).flatMap(([n,r],i)=>{let[a,o]=t[i+1];return n===a&&r!==o?[{key:e,x:n,top:Math.min(r,o),bottom:Math.max(r,o)}]:[]})),l=o.map(e=>({key:e.key,d:T(e.key,s.get(e.key),c),child:{x:e.x1,y:e.y1,dir:e.dir1,unique:e.unique},parent:{x:e.x2,y:e.y2,dir:e.dir2,optional:e.optional}}));return{...a,edges:l}},[t]);return(0,l.jsx)(`div`,{className:`border-border overflow-auto border`,children:(0,l.jsxs)(`svg`,{role:`img`,"aria-label":`Entity relationship diagram`,width:i,height:a,className:`min-w-full`,children:[o.map(({key:e,d:t,child:n,parent:r})=>(0,l.jsxs)(`g`,{opacity:.85,children:[(0,l.jsx)(`path`,{d:t,fill:`none`,strokeWidth:1.5,className:`stroke-accent-text`}),(0,l.jsx)(k,{...D(n)}),(0,l.jsx)(k,{...O(r)})]},e)),[...r.values()].map(({table:t,x:r,y:i,height:a})=>(0,l.jsxs)(`g`,{transform:`translate(${r},${i})`,children:[(0,l.jsx)(`rect`,{width:u,height:a,className:`fill-card stroke-border`}),(0,l.jsx)(`rect`,{width:u,height:d,className:`fill-sidebar`}),(0,l.jsx)(`a`,{href:n({environment:e,object:{kind:`table`,schema:t.schema,name:t.name}}),children:(0,l.jsx)(`text`,{x:10,y:20,className:`fill-accent-text text-sm font-bold`,children:t.name})}),t.columns.map((e,n)=>{let r=e.references&&e.references.schema!==t.schema;return(0,l.jsxs)(`g`,{transform:`translate(0,${d+f*n})`,children:[(0,l.jsxs)(`text`,{x:10,y:15,className:`fill-foreground text-xs`,children:[e.primaryKey?`🔑 `:e.references?`↗ `:``,e.name]}),(0,l.jsx)(`text`,{x:250,y:15,textAnchor:`end`,className:`fill-muted-foreground text-xs`,children:r?`→ ${e.references.schema}.${e.references.table}`:e.type})]},e.name)})]},t.name))]})})}var j=[[`zero or many`,{x:0,y:0,dir:1,unique:!1},`child`],[`zero or one`,{x:0,y:0,dir:1,unique:!0},`child`],[`exactly one`,{x:0,y:0,dir:1,optional:!1},`parent`],[`zero or one (nullable key)`,{x:0,y:0,dir:1,optional:!0},`parent`]];function M(){return(0,l.jsx)(`ul`,{"aria-label":`Legend`,className:`text-muted-foreground mb-4 flex flex-wrap gap-x-6 gap-y-1 text-xs`,children:j.map(([e,t,n])=>(0,l.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,l.jsxs)(`svg`,{width:34,height:14,viewBox:`-2 -7 34 14`,"aria-hidden":!0,children:[(0,l.jsx)(`path`,{d:`M0,0 L30,0`,className:`stroke-accent-text`,strokeWidth:1.5}),(0,l.jsx)(k,{...n===`child`?D(t):O(t)})]}),e]},e))})}function N({environment:t,schema:n}){let{data:r,error:i}=o(()=>e.erd(t,n),`${t}/${n}`);return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)(`h2`,{className:`text-accent-text mb-1 flex items-center gap-2 text-2xl`,children:[(0,l.jsx)(s,{className:`size-6`}),n,(0,l.jsx)(`span`,{className:`text-muted-foreground text-sm`,children:`ERD`})]}),(0,l.jsx)(`p`,{className:`text-muted-foreground mb-4 text-sm`,children:`Tables of the schema in crow's foot notation, with a line from each foreign key to the column it references. Click a table name to open it.`}),(0,l.jsx)(M,{}),i?(0,l.jsx)(`p`,{className:`text-destructive text-sm`,children:i}):r?r.length===0?(0,l.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`This schema has no tables.`}):(0,l.jsx)(A,{environment:t,tables:r}):(0,l.jsx)(a,{className:`h-80`})]})}export{N as ErdView};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{G as e,U as t,p as n}from"./route-
|
|
1
|
+
import{G as e,U as t,p as n}from"./route-7eu-iAqD.js";var r=` `,i=[[`with`],[`select`],[`from`],[`where`],[`group`,`by`],[`order`,`by`],[`having`],[`limit`],[`offset`],[`union`],[`intersect`],[`except`],[`values`],[`insert`,`into`],[`update`],[`set`],[`delete`,`from`],[`returning`],[`window`],[`on`,`conflict`]],a=new Set([`join`,`inner`,`left`,`right`,`full`,`cross`,`natural`,`outer`]),o=new Set([`select`,`group by`,`order by`,`set`,`returning`]),s=new Set([`where`,`having`,`on`]),c=new Set([`cast`,`filter`,`over`,`left`,`right`]),l=(e,t)=>e?.kind===`word`&&e.text.toLowerCase()===t;function u(e){let u=t(e).filter(e=>e.kind!==`space`),d=[],f=``,p=0,m=[{base:0,clause:``,between:!1,depth:0}],h,g=!1,_=e=>{f.trim()!==``&&d.push(r.repeat(p)+f),f=``,p=e,h=void 0},v=(e,t)=>{let r=h!==void 0;if(h){let t=h.text;t===`(`||t===`[`||t===`.`||t===`::`||g&&h.kind===`operator`||[`)`,`]`,`,`,`;`,`.`,`::`].includes(e.text)?r=!1:e.text===`[`?r=h.kind!==`word`&&h.kind!==`quoted`:e.text===`(`&&(r=!(h.kind===`quoted`||h.kind===`word`&&t.toLowerCase()!==`conflict`&&(!n(t)||c.has(t.toLowerCase()))||t===`)`||t===`]`))}f+=(r?` `:``)+t,h=e},y=()=>m[m.length-1],b=e=>{let t=0;for(let n=e;n<u.length;n++){let e=u[n];if(e.text===`(`||e.text===`[`)t++;else if(e.text===`)`||e.text===`]`){if(--t<0)return!1}else if(t===0&&e.text===`,`)return!0;else if(t===0&&e.kind===`word`&&i.some(e=>e.every((e,t)=>l(u[n+t],e))))return!1}return!1};for(let e=0;e<u.length;e++){let t=u[e],r=t.text.toLowerCase(),c=y();if(t.kind===`comment`)v(t,t.text),t.text.startsWith(`--`)&&_(p);else if(t.kind===`word`){let d=c.depth===0&&!l(u[e-1],`distinct`)&&!l(u[e-1],`for`)?i.find(t=>t.every((t,n)=>l(u[e+n],t))):void 0;if(d){_(c.base),c.clause=d.join(` `),c.between=!1;for(let t=0;t<d.length;t++)v(u[e+t],d[t].toUpperCase());e+=d.length-1,g=!1,o.has(c.clause)&&b(e+1)&&(l(u[e+1],`distinct`)&&v(u[++e],`DISTINCT`),_(c.base+1));continue}let f=a.has(r)&&(u[e+1]?.text!==`(`||r!==`left`&&r!==`right`);c.depth===0&&f?a.has(h?.text.toLowerCase()??``)||(_(c.base),c.clause=`join`):c.depth===0&&r===`on`&&c.clause===`join`?(_(c.base+1),c.clause=`on`):c.depth===0&&(r===`and`||r===`or`)&&s.has(c.clause)?r===`and`&&c.between?c.between=!1:_(c.base+1):r===`between`&&c.depth===0&&(c.between=!0),v(t,n(t.text)?t.text.toUpperCase():t.text),g=!1}else{if(t.kind===`punct`){if(t.text===`(`){v(t,`(`),g=!0;let n=u[e+1];l(n,`select`)||l(n,`with`)?(m.push({base:p+1,clause:``,between:!1,depth:0}),_(p+1)):c.depth++;continue}if(t.text===`)`){c.depth>0?(c.depth--,v(t,`)`)):(m.length>1&&_(m.pop().base-1),v(t,`)`)),g=!1;continue}if(t.text===`,`){v(t,`,`),g=!0,c.depth===0&&(o.has(c.clause)||c.clause===`with`)&&_(c.clause===`with`?c.base:c.base+1);continue}}if(t.kind===`operator`&&t.text!==`::`){let e=h?.kind===`word`&&n(h.text),r=h===void 0||h.kind===`operator`||h.text===`(`||h.text===`,`||e,i=/^[+\-]$/.test(t.text)&&r;v(t,t.text),g=i}else v(t,t.text),g=!1}}return _(0),d.join(`
|
|
2
2
|
`)}function d(t){let n=e(t);return n.length===0?t:n.map(e=>`${u(e.text)};`).join(`
|
|
3
3
|
|
|
4
4
|
`)+`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{at as e,ct as t,ot as n,rt as r}from"./route-
|
|
1
|
+
import{at as e,ct as t,ot as n,rt as r}from"./route-7eu-iAqD.js";import{Qt as i}from"./index-CpHnjRLv.js";var a={name:`maximize`,size:24,node:[[`path`,{d:`M8 3H5a2 2 0 0 0-2 2v3`,key:`1dcmit`}],[`path`,{d:`M21 8V5a2 2 0 0 0-2-2h-3`,key:`1e4gt3`}],[`path`,{d:`M3 16v3a2 2 0 0 0 2 2h3`,key:`wsl5sc`}],[`path`,{d:`M16 21h3a2 2 0 0 0 2-2v-3`,key:`18trek`}]]};a.node;var o=e(a),s={name:`minus`,size:24,node:[[`path`,{d:`M5 12h14`,key:`1ays0h`}]]};s.node;var c=e(s),l=t(n(),1);function u(e,t){let n=e.y+e.height/2,r=t.y+t.height/2;if(e.id===t.id){let t=e.x+e.width,r=e.y+10;return{d:`M${t},${r} C${t+46},${r-22} ${t+46},${e.y+e.height-6} ${t},${e.y+e.height-10}`,mid:{x:t+40,y:n}}}if(Math.abs(e.x-t.x)<1){let t=e.x+e.width,i=40+Math.min(80,Math.abs(n-r)/4);return{d:`M${t},${n} C${t+i},${n} ${t+i},${r} ${t},${r}`,mid:{x:t+i*.75,y:(n+r)/2}}}let i=e.x<t.x,a=i?e.x+e.width:e.x,o=i?t.x:t.x+t.width,s=Math.max(30,Math.abs(o-a)/2),c=i?1:-1;return{d:`M${a},${n} C${a+c*s},${n} ${o-c*s},${r} ${o},${r}`,mid:{x:(a+o)/2,y:(n+r)/2}}}var d=.1;function f(e,t,n=32){if(e.width<=0||e.height<=0||t.width<=0||t.height<=0)return{x:0,y:0,k:1};let r=Math.min(1.5,Math.max(d,Math.min((t.width-2*n)/e.width,(t.height-2*n)/e.height)));return{k:r,x:(t.width-e.width*r)/2,y:(t.height-e.height*r)/2}}function p(e,t,n){let r=Math.min(3,Math.max(d,e.k*t)),i=r/e.k;return{k:r,x:n.x-(n.x-e.x)*i,y:n.y-(n.y-e.y)*i}}function m(e,t=38){let n=0;for(let t of e)n=n*31+t.charCodeAt(0)>>>0;return`hsl(${n*137%360} 55% ${t}%)`}var h=e=>m(e,55),g=r();function _(){let e=(0,l.useRef)(null),[t,n]=(0,l.useState)({x:0,y:0,k:1}),r=(0,l.useRef)(!1);return(0,l.useEffect)(()=>{let t=e.current;if(!t)return;let r=e=>{e.preventDefault();let r=t.getBoundingClientRect();if(!e.ctrlKey&&Math.abs(e.deltaX)>Math.abs(e.deltaY)){n(t=>({...t,x:t.x-e.deltaX,y:t.y-e.deltaY}));return}let i=Math.exp(-e.deltaY*(e.ctrlKey?.01:.0015));n(t=>p(t,i,{x:e.clientX-r.left,y:e.clientY-r.top}))};return t.addEventListener(`wheel`,r,{passive:!1}),()=>t.removeEventListener(`wheel`,r)},[]),{frame:e,view:t,setView:n,dragged:r,startDrag:e=>{if(e.button!==0)return;r.current=!1;let t={x:e.clientX,y:e.clientY},i=i=>{let a=i.clientX-t.x,o=i.clientY-t.y;!r.current&&Math.hypot(i.clientX-e.clientX,i.clientY-e.clientY)<4||(r.current=!0,t={x:i.clientX,y:i.clientY},n(e=>({...e,x:e.x+a,y:e.y+o})))},a=()=>{window.removeEventListener(`pointermove`,i),window.removeEventListener(`pointerup`,a)};window.addEventListener(`pointermove`,i),window.addEventListener(`pointerup`,a)},zoomBy:t=>{let r=e.current?.getBoundingClientRect();r&&n(e=>p(e,t,{x:r.width/2,y:r.height/2}))}}}function v({zoomBy:e,fit:t}){return(0,g.jsx)(`div`,{className:`absolute top-2 right-2 z-10 flex gap-1`,children:[{label:`Zoom in`,icon:i,run:()=>e(1.25)},{label:`Zoom out`,icon:c,run:()=>e(.8)},{label:`Fit to screen`,icon:o,run:t}].map(({label:e,icon:t,run:n})=>(0,g.jsx)(`button`,{type:`button`,"aria-label":e,title:e,onClick:n,className:`bg-card border-input hover:text-accent-text rounded-lg border p-1.5`,children:(0,g.jsx)(t,{className:`size-4`})},e))})}var y=7e3,b=.035,x=.55,S=34,C=12,w=.012,T=.0228;function E(e){let t=2166136261;for(let n of e)t=Math.imul(t^n.charCodeAt(0),16777619)>>>0;return t/4294967296}function D(e,t,n=new Map){let r=new Map;for(let t of e){let e=n.get(t.id);e&&r.set(t.id,{x:e.x,y:e.y})}let i=new Map;for(let{source:e,target:n}of t)i.set(e,[...i.get(e)??[],n]),i.set(n,[...i.get(n)??[],e]);let a=0,o=e.filter(e=>!r.has(e.id));for(;o.length>0;){let e=[];for(let t of o){let n=(i.get(t.id)??[]).find(e=>r.has(e));if(n){let e=r.get(n),i=E(t.id)*Math.PI*2;r.set(t.id,{x:e.x+Math.cos(i)*120*.6,y:e.y+Math.sin(i)*120*.6})}else e.push(t)}if(e.length===o.length){let t=e.shift(),n=a*2.399963,i=40*Math.sqrt(a+1);r.set(t.id,{x:Math.cos(n)*i,y:Math.sin(n)*i}),a++}o=e}return e.map(e=>({id:e.id,r:e.r,x:r.get(e.id).x,y:r.get(e.id).y,vx:0,vy:0,pinned:!1}))}function O(e,t){let n=new Map(e.map(e=>[e.id,e.id])),r=e=>{let t=e;for(;n.get(t)!==t;)t=n.get(t);return n.set(e,t),t};for(let{source:e,target:i}of t)n.has(e)&&n.has(i)&&n.set(r(e),r(i));return new Map(e.map(e=>[e.id,r(e.id)]))}function k(e,t,n){let r=new Map(e.map(e=>[e.id,e])),i=new Map;for(let{source:e,target:n}of t)i.set(e,(i.get(e)??0)+1),i.set(n,(i.get(n)??0)+1);let a=O(e,t);for(let t=0;t<e.length;t++){let r=e[t];for(let i=t+1;i<e.length;i++){let t=e[i],o=t.x-r.x,s=t.y-r.y,c=o*o+s*s;if(c<.01){let e=E(r.id+t.id)*Math.PI*2;o=Math.cos(e),s=Math.sin(e),c=1}let l=Math.sqrt(c),u=(a.get(r.id)===a.get(t.id)?1:C)*y*n/c,d=o/l*u,f=s/l*u,p=r.r+t.r+S;if(l<p){let e=(p-l)/l*.5;d+=o*e,f+=s*e}r.vx-=d,r.vy-=f,t.vx+=d,t.vy+=f}}for(let{source:e,target:a}of t){let t=r.get(e),o=r.get(a);if(!t||!o||t===o)continue;let s=o.x+o.vx-t.x-t.vx,c=o.y+o.vy-t.y-t.vy,l=Math.hypot(s,c)||1,u=(l-120)/l*n*.9;s*=u,c*=u;let d=i.get(e)??1,f=d/(d+(i.get(a)??1));o.vx-=s*f,o.vy-=c*f,t.vx+=s*(1-f),t.vy+=c*(1-f)}for(let t of e)t.pinned?(t.vx=0,t.vy=0):(t.vx-=t.x*b*n,t.vy-=t.y*b*n,t.vx*=x,t.vy*=x,t.x+=t.vx,t.y+=t.vy)}function A(e,t,n=300){let r=1;for(let i=0;i<n&&r>.012;i++)k(e,t,r),r*=.9772}function j(e,t=30,n=60){if(e.length===0)return{x:0,y:0,width:0,height:0};let[r,i,a,o]=[1/0,1/0,-1/0,-1/0];for(let s of e)r=Math.min(r,s.x-Math.max(s.r,n)),a=Math.max(a,s.x+Math.max(s.r,n)),i=Math.min(i,s.y-s.r),o=Math.max(o,s.y+s.r+t);return{x:r,y:i,width:a-r,height:o-i}}function M(e,t,n){let r=Math.hypot(t.x-e.x,t.y-e.y)||1,[i,a]=[(t.x-e.x)/r,(t.y-e.y)/r],o=t.r+(n?3:0);return{x1:e.x+i*e.r,y1:e.y+a*e.r,x2:t.x-i*o,y2:t.y-a*o}}function N(e,t,n){return`M${e-n*.6},${t-n*.8} C${e-n*4},${t-n*5} ${e+n*4},${t-n*5} ${e+n*.6},${t-n*.8}`}export{N as a,k as c,h as d,u as f,j as i,v as l,m,w as n,D as o,f as p,M as r,A as s,T as t,_ as u};
|