mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-07-16 01:32:57 +02:00
Merge branch 'main' into wip/yaak-proxy-foundation
# Conflicts: # apps/yaak-client/components/JsonBodyEditor.tsx # apps/yaak-client/lib/jsonComments.ts # package-lock.json # packages/theme/src/window.ts # packages/ui/src/components/HeaderSize.tsx
This commit is contained in:
@@ -20,6 +20,18 @@ export async function tryFormatJson(text: string): Promise<string> {
|
||||
return text;
|
||||
}
|
||||
|
||||
export async function tryFormatGraphql(text: string): Promise<string> {
|
||||
if (text === '') return text;
|
||||
|
||||
try {
|
||||
return await invokeCmd<string>('cmd_format_graphql', { text });
|
||||
} catch (err) {
|
||||
console.warn('Failed to format GraphQL', err);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
export async function tryFormatXml(text: string): Promise<string> {
|
||||
if (text === '') return text;
|
||||
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* Simple heuristic to detect if a string likely contains JSON/JSONC comments.
|
||||
* Checks for // and /* patterns that are NOT inside double-quoted strings.
|
||||
* Used for UI hints only — doesn't need to be perfect.
|
||||
*/
|
||||
export function textLikelyContainsJsonComments(text: string): boolean {
|
||||
let inString = false;
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const ch = text[i];
|
||||
if (inString) {
|
||||
if (ch === '"') {
|
||||
inString = false;
|
||||
} else if (ch === '\\') {
|
||||
i++; // skip escaped char
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (ch === '"') {
|
||||
inString = true;
|
||||
continue;
|
||||
}
|
||||
if (ch === '/' && i + 1 < text.length) {
|
||||
const next = text[i + 1];
|
||||
if (next === '/' || next === '*') {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -17,6 +17,7 @@ type TauriCmd =
|
||||
| 'cmd_delete_send_history'
|
||||
| 'cmd_dismiss_notification'
|
||||
| 'cmd_export_data'
|
||||
| 'cmd_format_graphql'
|
||||
| 'cmd_format_json'
|
||||
| 'cmd_get_http_authentication_config'
|
||||
| 'cmd_get_http_authentication_summaries'
|
||||
|
||||
Reference in New Issue
Block a user