mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-26 11:21:30 +01:00
Run oxfmt across repo, add format script and docs
Add .oxfmtignore to skip generated bindings and wasm-pack output. Add npm format script, update DEVELOPMENT.md for Vite+ toolchain, and format all non-generated files with oxfmt. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,37 +1,37 @@
|
||||
import type { EditorView } from '@codemirror/view';
|
||||
import type { EditorView } from "@codemirror/view";
|
||||
import type {
|
||||
Folder,
|
||||
GrpcRequest,
|
||||
HttpRequest,
|
||||
WebsocketRequest,
|
||||
Workspace,
|
||||
} from '@yaakapp-internal/models';
|
||||
import type { TemplateFunction } from '@yaakapp-internal/plugins';
|
||||
import type { FnArg, Tokens } from '@yaakapp-internal/templates';
|
||||
import { parseTemplate } from '@yaakapp-internal/templates';
|
||||
import classNames from 'classnames';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { activeWorkspaceAtom } from '../hooks/useActiveWorkspace';
|
||||
import { useDebouncedValue } from '../hooks/useDebouncedValue';
|
||||
import { useRenderTemplate } from '../hooks/useRenderTemplate';
|
||||
import { useTemplateFunctionConfig } from '../hooks/useTemplateFunctionConfig';
|
||||
} from "@yaakapp-internal/models";
|
||||
import type { TemplateFunction } from "@yaakapp-internal/plugins";
|
||||
import type { FnArg, Tokens } from "@yaakapp-internal/templates";
|
||||
import { parseTemplate } from "@yaakapp-internal/templates";
|
||||
import classNames from "classnames";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { activeWorkspaceAtom } from "../hooks/useActiveWorkspace";
|
||||
import { useDebouncedValue } from "../hooks/useDebouncedValue";
|
||||
import { useRenderTemplate } from "../hooks/useRenderTemplate";
|
||||
import { useTemplateFunctionConfig } from "../hooks/useTemplateFunctionConfig";
|
||||
import {
|
||||
templateTokensToString,
|
||||
useTemplateTokensToString,
|
||||
} from '../hooks/useTemplateTokensToString';
|
||||
import { useToggle } from '../hooks/useToggle';
|
||||
import { showDialog } from '../lib/dialog';
|
||||
import { convertTemplateToInsecure } from '../lib/encryption';
|
||||
import { jotaiStore } from '../lib/jotai';
|
||||
import { setupOrConfigureEncryption } from '../lib/setupOrConfigureEncryption';
|
||||
import { Button } from './core/Button';
|
||||
import { collectArgumentValues } from './core/Editor/twig/util';
|
||||
import { IconButton } from './core/IconButton';
|
||||
import { InlineCode } from './core/InlineCode';
|
||||
import { LoadingIcon } from './core/LoadingIcon';
|
||||
import { PlainInput } from './core/PlainInput';
|
||||
import { HStack } from './core/Stacks';
|
||||
import { DYNAMIC_FORM_NULL_ARG, DynamicForm } from './DynamicForm';
|
||||
} from "../hooks/useTemplateTokensToString";
|
||||
import { useToggle } from "../hooks/useToggle";
|
||||
import { showDialog } from "../lib/dialog";
|
||||
import { convertTemplateToInsecure } from "../lib/encryption";
|
||||
import { jotaiStore } from "../lib/jotai";
|
||||
import { setupOrConfigureEncryption } from "../lib/setupOrConfigureEncryption";
|
||||
import { Button } from "./core/Button";
|
||||
import { collectArgumentValues } from "./core/Editor/twig/util";
|
||||
import { IconButton } from "./core/IconButton";
|
||||
import { InlineCode } from "./core/InlineCode";
|
||||
import { LoadingIcon } from "./core/LoadingIcon";
|
||||
import { PlainInput } from "./core/PlainInput";
|
||||
import { HStack } from "./core/Stacks";
|
||||
import { DYNAMIC_FORM_NULL_ARG, DynamicForm } from "./DynamicForm";
|
||||
|
||||
interface Props {
|
||||
templateFunction: TemplateFunction;
|
||||
@@ -55,7 +55,7 @@ export function TemplateFunctionDialog({ initialTokens, templateFunction, ...pro
|
||||
|
||||
// HACK: Replace the secure() function's encrypted `value` arg with the decrypted version so
|
||||
// we can display it in the editor input.
|
||||
if (templateFunction.name === 'secure') {
|
||||
if (templateFunction.name === "secure") {
|
||||
const template = await templateTokensToString(initialTokens);
|
||||
initial.value = await convertTemplateToInsecure(template);
|
||||
}
|
||||
@@ -88,10 +88,10 @@ function InitializedTemplateFunctionDialog({
|
||||
hide,
|
||||
onChange,
|
||||
model,
|
||||
}: Omit<Props, 'initialTokens'> & {
|
||||
}: Omit<Props, "initialTokens"> & {
|
||||
initialArgValues: Record<string, string | boolean>;
|
||||
}) {
|
||||
const previewType = ogPreviewType == null ? 'live' : ogPreviewType;
|
||||
const previewType = ogPreviewType == null ? "live" : ogPreviewType;
|
||||
const [showSecretsInPreview, toggleShowSecretsInPreview] = useToggle(false);
|
||||
const [argValues, setArgValues] = useState<Record<string, string | boolean>>(initialArgValues);
|
||||
|
||||
@@ -100,18 +100,18 @@ function InitializedTemplateFunctionDialog({
|
||||
name,
|
||||
value:
|
||||
argValues[name] === DYNAMIC_FORM_NULL_ARG
|
||||
? { type: 'null' }
|
||||
: typeof argValues[name] === 'boolean'
|
||||
? { type: 'bool', value: argValues[name] === true }
|
||||
: { type: 'str', text: String(argValues[name] ?? '') },
|
||||
? { type: "null" }
|
||||
: typeof argValues[name] === "boolean"
|
||||
? { type: "bool", value: argValues[name] === true }
|
||||
: { type: "str", text: String(argValues[name] ?? "") },
|
||||
}));
|
||||
|
||||
return {
|
||||
tokens: [
|
||||
{
|
||||
type: 'tag',
|
||||
type: "tag",
|
||||
val: {
|
||||
type: 'fn',
|
||||
type: "fn",
|
||||
name,
|
||||
args: argTokens,
|
||||
},
|
||||
@@ -130,13 +130,13 @@ function InitializedTemplateFunctionDialog({
|
||||
hide();
|
||||
};
|
||||
|
||||
const debouncedTagText = useDebouncedValue(tagText.data ?? '', 400);
|
||||
const debouncedTagText = useDebouncedValue(tagText.data ?? "", 400);
|
||||
const [renderKey, setRenderKey] = useState<string | null>(null);
|
||||
const rendered = useRenderTemplate({
|
||||
template: debouncedTagText,
|
||||
enabled: previewType !== 'none',
|
||||
purpose: previewType === 'click' ? 'send' : 'preview',
|
||||
refreshKey: previewType === 'live' ? renderKey + debouncedTagText : renderKey,
|
||||
enabled: previewType !== "none",
|
||||
purpose: previewType === "click" ? "send" : "preview",
|
||||
refreshKey: previewType === "live" ? renderKey + debouncedTagText : renderKey,
|
||||
ignoreError: false,
|
||||
});
|
||||
|
||||
@@ -144,9 +144,9 @@ function InitializedTemplateFunctionDialog({
|
||||
// oxlint-disable-next-line react-hooks/exhaustive-deps -- Only update this on rendered data change to keep secrets hidden on input change
|
||||
const dataContainsSecrets = useMemo(() => {
|
||||
for (const [name, value] of Object.entries(argValues)) {
|
||||
const arg = templateFunction.data?.args.find((a) => 'name' in a && a.name === name);
|
||||
const isTextPassword = arg?.type === 'text' && arg.password;
|
||||
if (isTextPassword && typeof value === 'string' && value && rendered.data?.includes(value)) {
|
||||
const arg = templateFunction.data?.args.find((a) => "name" in a && a.name === name);
|
||||
const isTextPassword = arg?.type === "text" && arg.password;
|
||||
if (isTextPassword && typeof value === "string" && value && rendered.data?.includes(value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -170,14 +170,14 @@ function InitializedTemplateFunctionDialog({
|
||||
}}
|
||||
>
|
||||
<div className="overflow-y-auto h-full px-6">
|
||||
{name === 'secure' ? (
|
||||
{name === "secure" ? (
|
||||
<PlainInput
|
||||
required
|
||||
label="Value"
|
||||
name="value"
|
||||
type="password"
|
||||
placeholder="••••••••••••"
|
||||
defaultValue={String(argValues.value ?? '')}
|
||||
defaultValue={String(argValues.value ?? "")}
|
||||
onChange={(value) => setArgValues({ ...argValues, value })}
|
||||
/>
|
||||
) : (
|
||||
@@ -192,7 +192,7 @@ function InitializedTemplateFunctionDialog({
|
||||
)}
|
||||
</div>
|
||||
<div className="px-6 border-t border-t-border pt-3 pb-6 bg-surface-highlight w-full flex flex-col gap-4">
|
||||
{previewType !== 'none' ? (
|
||||
{previewType !== "none" ? (
|
||||
<div className="w-full grid grid-cols-1 grid-rows-[auto_auto]">
|
||||
<HStack space={0.5}>
|
||||
<HStack className="text-sm text-text-subtle" space={1.5}>
|
||||
@@ -202,32 +202,32 @@ function InitializedTemplateFunctionDialog({
|
||||
<IconButton
|
||||
size="xs"
|
||||
iconSize="sm"
|
||||
icon={showSecretsInPreview ? 'lock' : 'lock_open'}
|
||||
title={showSecretsInPreview ? 'Show preview' : 'Hide preview'}
|
||||
icon={showSecretsInPreview ? "lock" : "lock_open"}
|
||||
title={showSecretsInPreview ? "Show preview" : "Hide preview"}
|
||||
onClick={toggleShowSecretsInPreview}
|
||||
className={classNames(
|
||||
'ml-auto text-text-subtlest',
|
||||
!dataContainsSecrets && 'invisible',
|
||||
"ml-auto text-text-subtlest",
|
||||
!dataContainsSecrets && "invisible",
|
||||
)}
|
||||
/>
|
||||
</HStack>
|
||||
<div className="relative w-full max-h-[10rem]">
|
||||
<InlineCode
|
||||
className={classNames(
|
||||
'block whitespace-pre-wrap !select-text cursor-text max-h-[10rem] overflow-auto hide-scrollbars !border-text-subtlest',
|
||||
tooLarge && 'italic text-danger',
|
||||
"block whitespace-pre-wrap !select-text cursor-text max-h-[10rem] overflow-auto hide-scrollbars !border-text-subtlest",
|
||||
tooLarge && "italic text-danger",
|
||||
)}
|
||||
>
|
||||
{rendered.error || tagText.error ? (
|
||||
<em className="text-danger">
|
||||
{`${rendered.error || tagText.error}`.replace(/^Render Error: /, '')}
|
||||
{`${rendered.error || tagText.error}`.replace(/^Render Error: /, "")}
|
||||
</em>
|
||||
) : dataContainsSecrets && !showSecretsInPreview ? (
|
||||
<span className="italic text-text-subtle">
|
||||
------ sensitive values hidden ------
|
||||
</span>
|
||||
) : tooLarge ? (
|
||||
'too large to preview'
|
||||
"too large to preview"
|
||||
) : (
|
||||
rendered.data || <> </>
|
||||
)}
|
||||
@@ -250,7 +250,7 @@ function InitializedTemplateFunctionDialog({
|
||||
<span />
|
||||
)}
|
||||
<div className="flex justify-stretch w-full flex-grow gap-2 [&>*]:flex-1">
|
||||
{templateFunction.data.name === 'secure' && (
|
||||
{templateFunction.data.name === "secure" && (
|
||||
<Button variant="border" color="secondary" onClick={setupOrConfigureEncryption}>
|
||||
Reveal Encryption Key
|
||||
</Button>
|
||||
@@ -273,8 +273,8 @@ TemplateFunctionDialog.show = (
|
||||
const initialTokens = parseTemplate(tagValue);
|
||||
showDialog({
|
||||
id: `template-function-${Math.random()}`, // Allow multiple at once
|
||||
size: 'md',
|
||||
className: 'h-[60rem]',
|
||||
size: "md",
|
||||
className: "h-[60rem]",
|
||||
noPadding: true,
|
||||
title: <InlineCode>{fn.name}(…)</InlineCode>,
|
||||
description: fn.description,
|
||||
|
||||
Reference in New Issue
Block a user