@flanksource/clicky-ui 0.3.87 → 0.3.88
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/dist/data/version-info.cjs +3 -3
- package/dist/data/version-info.js +3 -3
- package/dist/expressions/lang/attributes.cjs.map +1 -1
- package/dist/expressions/lang/attributes.d.ts.map +1 -1
- package/dist/expressions/lang/attributes.js.map +1 -1
- package/dist/expressions/lang/completion.cjs.map +1 -1
- package/dist/expressions/lang/completion.d.ts.map +1 -1
- package/dist/expressions/lang/completion.js.map +1 -1
- package/dist/expressions/lang/generated/conformance.json.d.ts +280 -0
- package/dist/expressions/lang/generated/index.cjs.map +1 -1
- package/dist/expressions/lang/generated/index.d.ts.map +1 -1
- package/dist/expressions/lang/generated/index.js.map +1 -1
- package/dist/expressions/lang/generated/languages.cjs +2 -0
- package/dist/expressions/lang/generated/languages.cjs.map +1 -1
- package/dist/expressions/lang/generated/languages.js +2 -0
- package/dist/expressions/lang/generated/languages.js.map +1 -1
- package/dist/expressions/lang/generated/languages.json.d.ts +2 -0
- package/dist/expressions/lang/generated/spec.cjs +2 -2
- package/dist/expressions/lang/generated/spec.cjs.map +1 -1
- package/dist/expressions/lang/generated/spec.js +2 -2
- package/dist/expressions/lang/generated/spec.js.map +1 -1
- package/dist/expressions/lang/generated/spec.json.d.ts +81 -26
- package/dist/expressions/lang/hover.cjs +3 -1
- package/dist/expressions/lang/hover.cjs.map +1 -1
- package/dist/expressions/lang/hover.d.ts.map +1 -1
- package/dist/expressions/lang/hover.js +3 -1
- package/dist/expressions/lang/hover.js.map +1 -1
- package/dist/expressions/lang/index.cjs.map +1 -1
- package/dist/expressions/lang/index.d.ts.map +1 -1
- package/dist/expressions/lang/index.js.map +1 -1
- package/dist/expressions/lang/merge.cjs +5 -0
- package/dist/expressions/lang/merge.cjs.map +1 -1
- package/dist/expressions/lang/merge.d.ts +4 -0
- package/dist/expressions/lang/merge.d.ts.map +1 -1
- package/dist/expressions/lang/merge.js +5 -0
- package/dist/expressions/lang/merge.js.map +1 -1
- package/dist/expressions/lang/prefix.cjs.map +1 -1
- package/dist/expressions/lang/prefix.d.ts.map +1 -1
- package/dist/expressions/lang/prefix.js.map +1 -1
- package/dist/expressions/lang/spec.d.ts.map +1 -1
- package/dist/expressions/lang/theme.cjs.map +1 -1
- package/dist/expressions/lang/theme.d.ts.map +1 -1
- package/dist/expressions/lang/theme.js.map +1 -1
- package/dist/expressions/lang/types.d.ts +12 -0
- package/dist/expressions/lang/types.d.ts.map +1 -1
- package/dist/expressions/playground/EmbeddedPlayground.cjs +6 -5
- package/dist/expressions/playground/EmbeddedPlayground.cjs.map +1 -1
- package/dist/expressions/playground/EmbeddedPlayground.d.ts +12 -4
- package/dist/expressions/playground/EmbeddedPlayground.d.ts.map +1 -1
- package/dist/expressions/playground/EmbeddedPlayground.js +6 -5
- package/dist/expressions/playground/EmbeddedPlayground.js.map +1 -1
- package/dist/expressions/playground/ExpressionPlayground.cjs +14 -4
- package/dist/expressions/playground/ExpressionPlayground.cjs.map +1 -1
- package/dist/expressions/playground/ExpressionPlayground.d.ts +7 -1
- package/dist/expressions/playground/ExpressionPlayground.d.ts.map +1 -1
- package/dist/expressions/playground/ExpressionPlayground.js +14 -4
- package/dist/expressions/playground/ExpressionPlayground.js.map +1 -1
- package/dist/expressions/playground/panels/ReferencePanel.cjs +34 -0
- package/dist/expressions/playground/panels/ReferencePanel.cjs.map +1 -0
- package/dist/expressions/playground/panels/ReferencePanel.d.ts +22 -0
- package/dist/expressions/playground/panels/ReferencePanel.d.ts.map +1 -0
- package/dist/expressions/playground/panels/ReferencePanel.js +33 -0
- package/dist/expressions/playground/panels/ReferencePanel.js.map +1 -0
- package/dist/expressions/playground/panels/SpecPanel.cjs +10 -2
- package/dist/expressions/playground/panels/SpecPanel.cjs.map +1 -1
- package/dist/expressions/playground/panels/SpecPanel.d.ts.map +1 -1
- package/dist/expressions/playground/panels/SpecPanel.js +10 -2
- package/dist/expressions/playground/panels/SpecPanel.js.map +1 -1
- package/dist/runtime/barrels.json +1574 -1574
- package/dist/runtime/importmap.json +2185 -2184
- package/package.json +1 -1
|
@@ -9,6 +9,7 @@ import { DEFAULT_API_BASE, fetchExamples, fetchSpec } from "./api.js";
|
|
|
9
9
|
import { LANGUAGES, languageById } from "./languages.js";
|
|
10
10
|
import { GraphPanel } from "./panels/GraphPanel.js";
|
|
11
11
|
import { ResultView } from "./panels/ResultView.js";
|
|
12
|
+
import { ReferencePanel } from "./panels/ReferencePanel.js";
|
|
12
13
|
import { SpecPanel } from "./panels/SpecPanel.js";
|
|
13
14
|
import { TokensPanel } from "./panels/TokensPanel.js";
|
|
14
15
|
import { RunControls } from "./RunControls.js";
|
|
@@ -44,7 +45,7 @@ var NO_EXAMPLES = [];
|
|
|
44
45
|
* reports, so a host's own functions are first-class here without this
|
|
45
46
|
* component knowing anything about them.
|
|
46
47
|
*/
|
|
47
|
-
function ExpressionPlayground({ apiBase = DEFAULT_API_BASE, languages: offered = LANGUAGES, examples, spec, evaluate, samples = NO_SAMPLES, expectation, executionMode, formatPath, pathInsertion = "caret", value, onChange, defaultValue, className }) {
|
|
48
|
+
function ExpressionPlayground({ apiBase = DEFAULT_API_BASE, languages: offered = LANGUAGES, examples, spec, reference, evaluate, samples = NO_SAMPLES, expectation, executionMode, formatPath, pathInsertion = "caret", value, onChange, defaultValue, className }) {
|
|
48
49
|
const { state, update } = usePlaygroundState({
|
|
49
50
|
value,
|
|
50
51
|
onChange,
|
|
@@ -146,6 +147,7 @@ function ExpressionPlayground({ apiBase = DEFAULT_API_BASE, languages: offered =
|
|
|
146
147
|
source: state.source,
|
|
147
148
|
onInsert: insertExpression,
|
|
148
149
|
formatPath,
|
|
150
|
+
reference,
|
|
149
151
|
result: {
|
|
150
152
|
view: resultView,
|
|
151
153
|
onViewChange: setResultView,
|
|
@@ -176,8 +178,9 @@ function ExamplePicker({ examples, onPick }) {
|
|
|
176
178
|
}
|
|
177
179
|
});
|
|
178
180
|
}
|
|
179
|
-
function PlaygroundOutput({ tab, onTabChange, language, spec, document, source, onInsert, formatPath, result }) {
|
|
181
|
+
function PlaygroundOutput({ tab, onTabChange, language, spec, document, source, onInsert, formatPath, reference, result }) {
|
|
180
182
|
const { catalogue, editorLanguage } = language;
|
|
183
|
+
const referenceUrl = catalogue ? reference?.[catalogue] : void 0;
|
|
181
184
|
return /* @__PURE__ */ jsxs("div", {
|
|
182
185
|
className: "flex min-h-0 w-1/2 flex-col",
|
|
183
186
|
children: [/* @__PURE__ */ jsx("div", {
|
|
@@ -196,7 +199,10 @@ function PlaygroundOutput({ tab, onTabChange, language, spec, document, source,
|
|
|
196
199
|
id: "tokens",
|
|
197
200
|
label: "Tokens"
|
|
198
201
|
},
|
|
199
|
-
...
|
|
202
|
+
...referenceUrl ? [{
|
|
203
|
+
id: "spec",
|
|
204
|
+
label: "Reference"
|
|
205
|
+
}] : catalogue ? [{
|
|
200
206
|
id: "spec",
|
|
201
207
|
label: "Functions",
|
|
202
208
|
count: spec[catalogue].functions.length
|
|
@@ -219,7 +225,11 @@ function PlaygroundOutput({ tab, onTabChange, language, spec, document, source,
|
|
|
219
225
|
source,
|
|
220
226
|
languageId: editorLanguage
|
|
221
227
|
}),
|
|
222
|
-
tab === "spec" &&
|
|
228
|
+
tab === "spec" && referenceUrl && /* @__PURE__ */ jsx(ReferencePanel, {
|
|
229
|
+
url: referenceUrl,
|
|
230
|
+
title: `${language.label} reference`
|
|
231
|
+
}),
|
|
232
|
+
tab === "spec" && catalogue && !referenceUrl && /* @__PURE__ */ jsx(SpecPanel, {
|
|
223
233
|
flavour: catalogue,
|
|
224
234
|
spec
|
|
225
235
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpressionPlayground.js","names":["spec","packagedSpec"],"sources":["../../../src/expressions/playground/ExpressionPlayground.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Combobox } from \"../../components/Combobox\";\nimport { useLatest } from \"../../hooks/use-latest\";\nimport { Tabs } from \"../../layout/Tabs\";\nimport { MonacoEditor } from \"../../monaco/MonacoEditor\";\nimport type { Monaco } from \"@monaco-editor/react\";\nimport * as monacoEditor from \"monaco-editor\";\n\nimport {\n mergeSpec,\n registerGomplateLanguages,\n spec as packagedSpec,\n} from \"../lang/index.ts\";\nimport type { GomplateSpec, RegisteredLanguages } from \"../lang/index.ts\";\nimport { DEFAULT_API_BASE, fetchExamples, fetchSpec } from \"./api.ts\";\nimport type { EvalRequest, EvalResponse, Example, FormatPath, PlaygroundSample, ResultExpectation } from \"./api.ts\";\nimport { LANGUAGES, languageById } from \"./languages.ts\";\nimport type { PlaygroundLanguage } from \"./languages.ts\";\nimport { GraphPanel } from \"./panels/GraphPanel.tsx\";\nimport { ResultView, type ResultViewId } from \"./panels/ResultView.tsx\";\nimport { SpecPanel } from \"./panels/SpecPanel.tsx\";\nimport { TokensPanel } from \"./panels/TokensPanel.tsx\";\nimport { RunControls } from \"./RunControls.tsx\";\nimport { registerRunAction } from \"./runAction.ts\";\nimport { useEditorTheme } from \"./useEditorTheme.ts\";\nimport { useEvaluator, type Evaluator } from \"./useEvaluator.ts\";\nimport { useParsedInput } from \"./useParsedInput.ts\";\nimport { useSampleRuns } from \"./useSampleRuns.ts\";\nimport { VerticalSplit } from \"./VerticalSplit.tsx\";\nimport { rowsToPaneHeight } from \"./verticalSplitModel\";\n\n/** What the author is editing. Hosts persist this wherever suits them. */\nexport interface PlaygroundState {\n language: string;\n source: string;\n input: string;\n}\n\nexport interface ExpressionPlaygroundProps {\n /**\n * Where the host mounted the playground API. Defaults to `/api`; a host\n * serving it behind a prefix passes that instead.\n */\n apiBase?: string;\n /** Languages offered. Defaults to everything gomplate evaluates. */\n languages?: PlaygroundLanguage[];\n /**\n * Samples to offer. Fetched from the server when omitted, so a host that\n * configured `Options.Examples` needs no prop at all.\n */\n examples?: Example[];\n /** Host catalogue. When supplied, the playground does not fetch /spec. */\n spec?: GomplateSpec;\n /** Host evaluator for runtimes beyond the packaged playground API. */\n evaluate?: (request: EvalRequest, signal: AbortSignal) => Promise<EvalResponse>;\n /**\n * Inputs the expression should hold for. With two or more, the Result tab\n * offers \"All samples\", which evaluates the expression against each in turn.\n */\n samples?: PlaygroundSample[];\n /** What the result is going into: allowed values, rules and a validator. */\n expectation?: ResultExpectation;\n /** Explicit mode disables evaluation on mount and edits. */\n executionMode?: \"automatic\" | \"explicit\";\n /** Host syntax for paths inserted from the object graph. */\n formatPath?: FormatPath;\n /**\n * Where a path picked in the object graph lands. `caret` (the default) writes\n * it at the cursor, which completes an expression half-written around it;\n * `replace` overwrites the whole expression, for a language whose expression\n * is a path — a JSONPath picked over `$.old` should be `$.new`, not both.\n */\n pathInsertion?: \"caret\" | \"replace\";\n /** Controlled state. Pair with `onChange`. */\n value?: PlaygroundState;\n onChange?: (state: PlaygroundState) => void;\n /** Starting state when uncontrolled. */\n defaultValue?: PlaygroundState;\n className?: string;\n}\n\nconst SOURCE_MODEL_PATH = \"inmemory://expressions/source\";\nconst INPUT_MODEL_PATH = \"inmemory://expressions/input.yaml\";\n\nconst EMPTY_STATE: PlaygroundState = { language: \"cel\", source: \"\", input: \"\" };\nconst NO_SAMPLES: PlaygroundSample[] = [];\nconst NO_EXAMPLES: Example[] = [];\n\n/**\n * An editor for one expression, the document it runs against, and its result.\n *\n * Deliberately shell-less: it renders the editors and the output panels and\n * nothing around them, so a host frames it with its own navigation. gomplate's\n * playground wraps it in an AppShell with a language rail; an app embedding it\n * in a drawer wraps it in nothing at all.\n *\n * Highlighting, completion and hover come from the catalogue the *server*\n * reports, so a host's own functions are first-class here without this\n * component knowing anything about them.\n */\nexport function ExpressionPlayground({\n apiBase = DEFAULT_API_BASE,\n languages: offered = LANGUAGES,\n examples,\n spec,\n evaluate,\n samples = NO_SAMPLES,\n expectation,\n executionMode,\n formatPath,\n pathInsertion = \"caret\",\n value,\n onChange,\n defaultValue,\n className,\n}: ExpressionPlaygroundProps) {\n const { state, update } = usePlaygroundState({ value, onChange, defaultValue, offered });\n const language = useMemo(\n () => languageById(state.language, offered),\n [state.language, offered],\n );\n const [selectedTab, setOutputTab] = useState(\"result\");\n const outputTab = selectedTab === \"spec\" && !language.catalogue ? \"result\" : selectedTab;\n if (outputTab !== selectedTab) setOutputTab(outputTab);\n\n const evaluator = useEvaluator(apiBase, {\n language: language.evalLanguage,\n source: state.source,\n input: state.input,\n }, {\n ...(executionMode ? { mode: executionMode } : {}),\n ...(evaluate ? { evaluate } : {}),\n });\n\n const [resultView, setResultView] = useState<ResultViewId>(\"input\");\n const sampleRuns = useSampleRuns(\n apiBase,\n { language: language.evalLanguage, source: state.source, samples },\n evaluate ? { evaluate } : undefined,\n );\n // Run, its shortcut and the Monaco action all drive whichever result view is\n // showing, so \"run\" never means evaluating something the author cannot see.\n const showingSamples = samples.length > 1 && outputTab === \"result\" && resultView === \"samples\";\n const runner: Evaluator = showingSamples\n ? { ...evaluator, explicit: true, autoRun: false, run: sampleRuns.run, pending: sampleRuns.pending, stale: sampleRuns.stale }\n : evaluator;\n\n const parsedInput = useParsedInput(state.input);\n const { activeSpec, registerLanguages } = usePlaygroundCatalogue({ apiBase, spec, environment: parsedInput.value });\n const forLanguage = usePlaygroundExamples(apiBase, examples).filter(\n (example) => example.language === language.evalLanguage,\n );\n const { onEditorMount, insertExpression } = usePlaygroundEditors({ run: runner.run, pathInsertion });\n useMarkers(evaluator.response);\n\n return (\n <div className={`flex h-full min-h-0 ${className ?? \"\"}`}>\n <div className=\"flex min-h-0 w-1/2 flex-col border-r border-border\">\n <VerticalSplit\n storageKey=\"expressions:editor-split\"\n defaultTopHeight={rowsToPaneHeight(language.editorRows)}\n top={\n <EditorPane\n label=\"Expression\"\n actions={<RunControls evaluator={runner} label={showingSamples ? \"Run all\" : \"Run\"} />}\n hint={\n <ExamplePicker examples={forLanguage} onPick={({ source, input }) => update({ source, input })} />\n }\n >\n <MonacoEditor\n value={state.source}\n onChange={(source) => update({ source: source ?? \"\" })}\n language={language.editorLanguage}\n path={SOURCE_MODEL_PATH}\n height=\"100%\"\n beforeMount={registerLanguages}\n onMount={onEditorMount}\n />\n </EditorPane>\n }\n bottom={\n <EditorPane\n label=\"Input\"\n hint={\n <span\n className={`truncate text-[11px] ${\n parsedInput.error\n ? \"text-destructive\"\n : \"text-muted-foreground/70\"\n }`}\n title={parsedInput.error ?? undefined}\n >\n {parsedInput.error ?? \"YAML or JSON\"}\n </span>\n }\n >\n <MonacoEditor\n value={state.input}\n onChange={(input) => update({ input: input ?? \"\" })}\n language=\"yaml\"\n path={INPUT_MODEL_PATH}\n height=\"100%\"\n onMount={onEditorMount}\n />\n </EditorPane>\n }\n />\n </div>\n\n <PlaygroundOutput\n tab={outputTab}\n onTabChange={setOutputTab}\n language={language}\n spec={activeSpec}\n document={parsedInput.value}\n source={state.source}\n onInsert={insertExpression}\n formatPath={formatPath}\n result={{\n view: resultView,\n onViewChange: setResultView,\n evaluator,\n sampleRuns,\n samples,\n expectation,\n onUseInput: (input) => update({ input }),\n }}\n />\n </div>\n );\n}\n\nfunction ExamplePicker({ examples, onPick }: { examples: Example[]; onPick: (example: Example) => void }) {\n if (examples.length === 0) return null;\n return (\n <Combobox\n options={examples.map(({ name }) => ({ value: name, label: name }))}\n value=\"\"\n allowCustomValue={false}\n placeholder=\"Load an example…\"\n ariaLabel=\"Load an example\"\n className=\"w-56\"\n onChange={(name) => {\n const example = examples.find((candidate) => candidate.name === name);\n if (example) onPick(example);\n }}\n />\n );\n}\n\nfunction PlaygroundOutput({\n tab,\n onTabChange,\n language,\n spec,\n document,\n source,\n onInsert,\n formatPath,\n result,\n}: {\n tab: string;\n onTabChange: (tab: string) => void;\n language: PlaygroundLanguage;\n spec: GomplateSpec;\n document: unknown;\n source: string;\n onInsert: (expression: string) => void;\n formatPath: FormatPath | undefined;\n result: ComponentProps<typeof ResultView>;\n}) {\n const { catalogue, editorLanguage } = language;\n return (\n <div className=\"flex min-h-0 w-1/2 flex-col\">\n <div className=\"border-b border-border px-4\">\n <Tabs\n tabs={[\n { id: \"result\", label: \"Result\" },\n { id: \"graph\", label: \"Object graph\" },\n { id: \"tokens\", label: \"Tokens\" },\n ...(catalogue\n ? [{ id: \"spec\", label: \"Functions\", count: spec[catalogue].functions.length }]\n : []),\n ]}\n value={tab}\n onChange={onTabChange}\n />\n </div>\n\n <div className=\"min-h-0 flex-1\">\n {tab === \"result\" && <ResultView {...result} />}\n {tab === \"graph\" && (\n <GraphPanel\n document={document}\n languageId={editorLanguage}\n onInsert={onInsert}\n {...(formatPath ? { formatPath } : {})}\n />\n )}\n {tab === \"tokens\" && <TokensPanel source={source} languageId={editorLanguage} />}\n {tab === \"spec\" && catalogue && <SpecPanel flavour={catalogue} spec={spec} />}\n </div>\n </div>\n );\n}\n\nfunction usePlaygroundState({ value, onChange, defaultValue, offered }: {\n value: PlaygroundState | undefined;\n onChange: ExpressionPlaygroundProps[\"onChange\"];\n defaultValue: PlaygroundState | undefined;\n offered: PlaygroundLanguage[];\n}) {\n const [uncontrolled, setUncontrolled] = useState<PlaygroundState>(\n () => defaultValue ?? { ...EMPTY_STATE, language: offered[0]?.id ?? \"cel\" },\n );\n const state = value ?? uncontrolled;\n const update = useCallback((patch: Partial<PlaygroundState>) => {\n const next = { ...state, ...patch };\n if (!value) setUncontrolled(next);\n onChange?.(next);\n }, [state, value, onChange]);\n return { state, update };\n}\n\nfunction usePlaygroundCatalogue({ apiBase, spec, environment }: {\n apiBase: string;\n spec: GomplateSpec | undefined;\n environment: unknown;\n}) {\n const [served, setServed] = useState<GomplateSpec>();\n const catalogue = spec ?? served;\n const activeSpec = useMemo(() => mergeSpec(packagedSpec, catalogue), [catalogue]);\n const latest = useLatest({ environment, catalogue });\n\n // Monaco registers languages before creating the first model. The catalogue\n // fetch and editor mount can finish in either order.\n const registered = useRef<RegisteredLanguages | null>(null);\n const registerLanguages = useCallback((monaco: Monaco) => {\n const current = latest.current.catalogue;\n registered.current = registerGomplateLanguages(monaco, {\n environment: () => latest.current.environment,\n ...(current ? { spec: current } : {}),\n });\n }, [latest]);\n\n useEffect(() => {\n if (spec) return;\n const controller = new AbortController();\n void fetchSpec(apiBase, controller.signal).then((next) => {\n if (!controller.signal.aborted) setServed(next);\n });\n return () => controller.abort();\n }, [apiBase, spec]);\n\n useEffect(() => {\n if (catalogue) registered.current?.setSpec(catalogue);\n }, [catalogue]);\n\n return { activeSpec, registerLanguages };\n}\n\nfunction usePlaygroundExamples(apiBase: string, examples: Example[] | undefined) {\n const [fetched, setFetched] = useState<Example[]>();\n useEffect(() => {\n if (examples) return;\n const controller = new AbortController();\n void fetchExamples(apiBase, controller.signal).then((next) => {\n if (!controller.signal.aborted && next) setFetched(next);\n });\n return () => controller.abort();\n }, [apiBase, examples]);\n return examples ?? fetched ?? NO_EXAMPLES;\n}\n\nfunction usePlaygroundEditors({ run, pathInsertion }: { run: Evaluator[\"run\"]; pathInsertion: \"caret\" | \"replace\" }) {\n const applyTheme = useEditorTheme();\n const runRef = useLatest(run);\n const sourceEditor = useRef<Parameters<typeof registerRunAction>[0] | null>(null);\n const onEditorMount = useCallback(\n (editor: Parameters<typeof registerRunAction>[0], monaco: Monaco) => {\n applyTheme();\n registerRunAction(editor, monaco, () => runRef.current());\n if (editor.getModel()?.uri.toString() === SOURCE_MODEL_PATH)\n sourceEditor.current = editor;\n },\n [applyTheme, runRef],\n );\n\n const insertExpression = useCallback((expression: string) => {\n const editor = sourceEditor.current;\n if (!editor) return;\n const range = pathInsertion === \"replace\" ? editor.getModel()?.getFullModelRange() : editor.getSelection();\n if (!range) return;\n editor.executeEdits(\"object-graph\", [\n { range, text: expression, forceMoveMarkers: true },\n ]);\n editor.focus();\n }, [pathInsertion]);\n return { onEditorMount, insertExpression };\n}\n\nfunction EditorPane({\n label,\n hint,\n actions,\n children,\n}: {\n label: string;\n hint?: React.ReactNode;\n actions?: React.ReactNode;\n children: React.ReactNode;\n}) {\n return (\n <section className=\"flex h-full min-h-0 flex-col bg-background\">\n <header className=\"flex h-[33px] shrink-0 items-center justify-between gap-2 px-4 py-2\">\n <div className=\"flex items-baseline gap-2\">\n <h2 className=\"text-xs font-medium uppercase tracking-wide text-muted-foreground\">\n {label}\n </h2>\n {hint}\n </div>\n {actions}\n </header>\n <div className=\"min-h-0 flex-1 [&_[data-slot=monaco-editor]]:h-full [&_[data-slot=monaco-editor]]:rounded-none [&_[data-slot=monaco-editor]]:border-0 [&_[data-slot=monaco-editor]]:border-t\">\n {children}\n </div>\n </section>\n );\n}\n\n/**\n * Mirrors a compile error onto the editor as a marker, so the position the\n * server reported is visible where the mistake is rather than only in the\n * result panel.\n */\nfunction useMarkers(response: EvalResponse | null) {\n useEffect(() => {\n const model = monacoEditor.editor\n .getModels()\n .find((candidate) => candidate.uri.toString() === SOURCE_MODEL_PATH);\n if (!model) return;\n\n const error = response?.error;\n if (!error?.line) {\n monacoEditor.editor.setModelMarkers(model, \"expressions\", []);\n return;\n }\n\n const column = error.column ?? 1;\n monacoEditor.editor.setModelMarkers(model, \"expressions\", [\n {\n severity: monacoEditor.MarkerSeverity.Error,\n message: error.message,\n startLineNumber: error.line,\n startColumn: column,\n endLineNumber: error.line,\n endColumn: column + 1,\n },\n ]);\n }, [response]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AAEzB,IAAM,cAA+B;CAAE,UAAU;CAAO,QAAQ;CAAI,OAAO;AAAG;AAC9E,IAAM,aAAiC,CAAC;AACxC,IAAM,cAAyB,CAAC;;;;;;;;;;;;;AAchC,SAAgB,qBAAqB,EACnC,UAAU,kBACV,WAAW,UAAU,WACrB,UACA,MACA,UACA,UAAU,YACV,aACA,eACA,YACA,gBAAgB,SAChB,OACA,UACA,cACA,aAC4B;CAC5B,MAAM,EAAE,OAAO,WAAW,mBAAmB;EAAE;EAAO;EAAU;EAAc;CAAQ,CAAC;CACvF,MAAM,WAAW,cACT,aAAa,MAAM,UAAU,OAAO,GAC1C,CAAC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AAI,CAAC,OAAO,MAAM;GAChB,aAAa,OAAO,gBAAgB,OAAO,eAAe,CAAC,CAAC;GAC5D;EACF;EAEA,MAAM,SAAS,MAAM,UAAU;EAC/B,aAAa,OAAO,gBAAgB,OAAO,eAAe,CACxD;GACE,UAAU,aAAa,eAAe;GACtC,SAAS,MAAM;GACf,iBAAiB,MAAM;GACvB,aAAa;GACb,eAAe,MAAM;GACrB,WAAW,SAAS;EACtB,CACF,CAAC;CACH,GAAG,CAAC,QAAQ,CAAC;AACf"}
|
|
1
|
+
{"version":3,"file":"ExpressionPlayground.js","names":["spec","packagedSpec"],"sources":["../../../src/expressions/playground/ExpressionPlayground.tsx"],"sourcesContent":["import { useCallback, useEffect, useMemo, useRef, useState, type ComponentProps } from \"react\";\nimport { Combobox } from \"../../components/Combobox\";\nimport { useLatest } from \"../../hooks/use-latest\";\nimport { Tabs } from \"../../layout/Tabs\";\nimport { MonacoEditor } from \"../../monaco/MonacoEditor\";\nimport type { Monaco } from \"@monaco-editor/react\";\nimport * as monacoEditor from \"monaco-editor\";\n\nimport {\n mergeSpec,\n registerGomplateLanguages,\n spec as packagedSpec,\n} from \"../lang/index.ts\";\nimport type { GomplateSpec, RegisteredLanguages } from \"../lang/index.ts\";\nimport { DEFAULT_API_BASE, fetchExamples, fetchSpec } from \"./api.ts\";\nimport type { EvalRequest, EvalResponse, Example, FormatPath, PlaygroundSample, ResultExpectation } from \"./api.ts\";\nimport { LANGUAGES, languageById } from \"./languages.ts\";\nimport type { PlaygroundLanguage } from \"./languages.ts\";\nimport { GraphPanel } from \"./panels/GraphPanel.tsx\";\nimport { ResultView, type ResultViewId } from \"./panels/ResultView.tsx\";\nimport { ReferencePanel } from \"./panels/ReferencePanel.tsx\";\nimport { SpecPanel } from \"./panels/SpecPanel.tsx\";\nimport { TokensPanel } from \"./panels/TokensPanel.tsx\";\nimport { RunControls } from \"./RunControls.tsx\";\nimport { registerRunAction } from \"./runAction.ts\";\nimport { useEditorTheme } from \"./useEditorTheme.ts\";\nimport { useEvaluator, type Evaluator } from \"./useEvaluator.ts\";\nimport { useParsedInput } from \"./useParsedInput.ts\";\nimport { useSampleRuns } from \"./useSampleRuns.ts\";\nimport { VerticalSplit } from \"./VerticalSplit.tsx\";\nimport { rowsToPaneHeight } from \"./verticalSplitModel\";\n\n/** What the author is editing. Hosts persist this wherever suits them. */\nexport interface PlaygroundState {\n language: string;\n source: string;\n input: string;\n}\n\nexport interface ExpressionPlaygroundProps {\n /**\n * Where the host mounted the playground API. Defaults to `/api`; a host\n * serving it behind a prefix passes that instead.\n */\n apiBase?: string;\n /** Languages offered. Defaults to everything gomplate evaluates. */\n languages?: PlaygroundLanguage[];\n /**\n * Samples to offer. Fetched from the server when omitted, so a host that\n * configured `Options.Examples` needs no prop at all.\n */\n examples?: Example[];\n /** Host catalogue. When supplied, the playground does not fetch /spec. */\n spec?: GomplateSpec;\n /**\n * The host's reference page per catalogue. A language with one shows it as\n * its Reference tab instead of the Functions table; the page is embedded with\n * `?embed&theme=<light|dark>` so it can drop its own navigation.\n */\n reference?: Partial<Record<\"cel\" | \"gotemplate\", string>>;\n /** Host evaluator for runtimes beyond the packaged playground API. */\n evaluate?: (request: EvalRequest, signal: AbortSignal) => Promise<EvalResponse>;\n /**\n * Inputs the expression should hold for. With two or more, the Result tab\n * offers \"All samples\", which evaluates the expression against each in turn.\n */\n samples?: PlaygroundSample[];\n /** What the result is going into: allowed values, rules and a validator. */\n expectation?: ResultExpectation;\n /** Explicit mode disables evaluation on mount and edits. */\n executionMode?: \"automatic\" | \"explicit\";\n /** Host syntax for paths inserted from the object graph. */\n formatPath?: FormatPath;\n /**\n * Where a path picked in the object graph lands. `caret` (the default) writes\n * it at the cursor, which completes an expression half-written around it;\n * `replace` overwrites the whole expression, for a language whose expression\n * is a path — a JSONPath picked over `$.old` should be `$.new`, not both.\n */\n pathInsertion?: \"caret\" | \"replace\";\n /** Controlled state. Pair with `onChange`. */\n value?: PlaygroundState;\n onChange?: (state: PlaygroundState) => void;\n /** Starting state when uncontrolled. */\n defaultValue?: PlaygroundState;\n className?: string;\n}\n\nconst SOURCE_MODEL_PATH = \"inmemory://expressions/source\";\nconst INPUT_MODEL_PATH = \"inmemory://expressions/input.yaml\";\n\nconst EMPTY_STATE: PlaygroundState = { language: \"cel\", source: \"\", input: \"\" };\nconst NO_SAMPLES: PlaygroundSample[] = [];\nconst NO_EXAMPLES: Example[] = [];\n\n/**\n * An editor for one expression, the document it runs against, and its result.\n *\n * Deliberately shell-less: it renders the editors and the output panels and\n * nothing around them, so a host frames it with its own navigation. gomplate's\n * playground wraps it in an AppShell with a language rail; an app embedding it\n * in a drawer wraps it in nothing at all.\n *\n * Highlighting, completion and hover come from the catalogue the *server*\n * reports, so a host's own functions are first-class here without this\n * component knowing anything about them.\n */\nexport function ExpressionPlayground({\n apiBase = DEFAULT_API_BASE,\n languages: offered = LANGUAGES,\n examples,\n spec,\n reference,\n evaluate,\n samples = NO_SAMPLES,\n expectation,\n executionMode,\n formatPath,\n pathInsertion = \"caret\",\n value,\n onChange,\n defaultValue,\n className,\n}: ExpressionPlaygroundProps) {\n const { state, update } = usePlaygroundState({ value, onChange, defaultValue, offered });\n const language = useMemo(\n () => languageById(state.language, offered),\n [state.language, offered],\n );\n const [selectedTab, setOutputTab] = useState(\"result\");\n const outputTab = selectedTab === \"spec\" && !language.catalogue ? \"result\" : selectedTab;\n if (outputTab !== selectedTab) setOutputTab(outputTab);\n\n const evaluator = useEvaluator(apiBase, {\n language: language.evalLanguage,\n source: state.source,\n input: state.input,\n }, {\n ...(executionMode ? { mode: executionMode } : {}),\n ...(evaluate ? { evaluate } : {}),\n });\n\n const [resultView, setResultView] = useState<ResultViewId>(\"input\");\n const sampleRuns = useSampleRuns(\n apiBase,\n { language: language.evalLanguage, source: state.source, samples },\n evaluate ? { evaluate } : undefined,\n );\n // Run, its shortcut and the Monaco action all drive whichever result view is\n // showing, so \"run\" never means evaluating something the author cannot see.\n const showingSamples = samples.length > 1 && outputTab === \"result\" && resultView === \"samples\";\n const runner: Evaluator = showingSamples\n ? { ...evaluator, explicit: true, autoRun: false, run: sampleRuns.run, pending: sampleRuns.pending, stale: sampleRuns.stale }\n : evaluator;\n\n const parsedInput = useParsedInput(state.input);\n const { activeSpec, registerLanguages } = usePlaygroundCatalogue({ apiBase, spec, environment: parsedInput.value });\n const forLanguage = usePlaygroundExamples(apiBase, examples).filter(\n (example) => example.language === language.evalLanguage,\n );\n const { onEditorMount, insertExpression } = usePlaygroundEditors({ run: runner.run, pathInsertion });\n useMarkers(evaluator.response);\n\n return (\n <div className={`flex h-full min-h-0 ${className ?? \"\"}`}>\n <div className=\"flex min-h-0 w-1/2 flex-col border-r border-border\">\n <VerticalSplit\n storageKey=\"expressions:editor-split\"\n defaultTopHeight={rowsToPaneHeight(language.editorRows)}\n top={\n <EditorPane\n label=\"Expression\"\n actions={<RunControls evaluator={runner} label={showingSamples ? \"Run all\" : \"Run\"} />}\n hint={\n <ExamplePicker examples={forLanguage} onPick={({ source, input }) => update({ source, input })} />\n }\n >\n <MonacoEditor\n value={state.source}\n onChange={(source) => update({ source: source ?? \"\" })}\n language={language.editorLanguage}\n path={SOURCE_MODEL_PATH}\n height=\"100%\"\n beforeMount={registerLanguages}\n onMount={onEditorMount}\n />\n </EditorPane>\n }\n bottom={\n <EditorPane\n label=\"Input\"\n hint={\n <span\n className={`truncate text-[11px] ${\n parsedInput.error\n ? \"text-destructive\"\n : \"text-muted-foreground/70\"\n }`}\n title={parsedInput.error ?? undefined}\n >\n {parsedInput.error ?? \"YAML or JSON\"}\n </span>\n }\n >\n <MonacoEditor\n value={state.input}\n onChange={(input) => update({ input: input ?? \"\" })}\n language=\"yaml\"\n path={INPUT_MODEL_PATH}\n height=\"100%\"\n onMount={onEditorMount}\n />\n </EditorPane>\n }\n />\n </div>\n\n <PlaygroundOutput\n tab={outputTab}\n onTabChange={setOutputTab}\n language={language}\n spec={activeSpec}\n document={parsedInput.value}\n source={state.source}\n onInsert={insertExpression}\n formatPath={formatPath}\n reference={reference}\n result={{\n view: resultView,\n onViewChange: setResultView,\n evaluator,\n sampleRuns,\n samples,\n expectation,\n onUseInput: (input) => update({ input }),\n }}\n />\n </div>\n );\n}\n\nfunction ExamplePicker({ examples, onPick }: { examples: Example[]; onPick: (example: Example) => void }) {\n if (examples.length === 0) return null;\n return (\n <Combobox\n options={examples.map(({ name }) => ({ value: name, label: name }))}\n value=\"\"\n allowCustomValue={false}\n placeholder=\"Load an example…\"\n ariaLabel=\"Load an example\"\n className=\"w-56\"\n onChange={(name) => {\n const example = examples.find((candidate) => candidate.name === name);\n if (example) onPick(example);\n }}\n />\n );\n}\n\nfunction PlaygroundOutput({\n tab,\n onTabChange,\n language,\n spec,\n document,\n source,\n onInsert,\n formatPath,\n reference,\n result,\n}: {\n tab: string;\n onTabChange: (tab: string) => void;\n language: PlaygroundLanguage;\n spec: GomplateSpec;\n document: unknown;\n source: string;\n onInsert: (expression: string) => void;\n formatPath: FormatPath | undefined;\n reference: ExpressionPlaygroundProps[\"reference\"];\n result: ComponentProps<typeof ResultView>;\n}) {\n const { catalogue, editorLanguage } = language;\n const referenceUrl = catalogue ? reference?.[catalogue] : undefined;\n return (\n <div className=\"flex min-h-0 w-1/2 flex-col\">\n <div className=\"border-b border-border px-4\">\n <Tabs\n tabs={[\n { id: \"result\", label: \"Result\" },\n { id: \"graph\", label: \"Object graph\" },\n { id: \"tokens\", label: \"Tokens\" },\n ...(referenceUrl\n ? [{ id: \"spec\", label: \"Reference\" }]\n : catalogue\n ? [{ id: \"spec\", label: \"Functions\", count: spec[catalogue].functions.length }]\n : []),\n ]}\n value={tab}\n onChange={onTabChange}\n />\n </div>\n\n <div className=\"min-h-0 flex-1\">\n {tab === \"result\" && <ResultView {...result} />}\n {tab === \"graph\" && (\n <GraphPanel\n document={document}\n languageId={editorLanguage}\n onInsert={onInsert}\n {...(formatPath ? { formatPath } : {})}\n />\n )}\n {tab === \"tokens\" && <TokensPanel source={source} languageId={editorLanguage} />}\n {tab === \"spec\" && referenceUrl && <ReferencePanel url={referenceUrl} title={`${language.label} reference`} />}\n {tab === \"spec\" && catalogue && !referenceUrl && <SpecPanel flavour={catalogue} spec={spec} />}\n </div>\n </div>\n );\n}\n\nfunction usePlaygroundState({ value, onChange, defaultValue, offered }: {\n value: PlaygroundState | undefined;\n onChange: ExpressionPlaygroundProps[\"onChange\"];\n defaultValue: PlaygroundState | undefined;\n offered: PlaygroundLanguage[];\n}) {\n const [uncontrolled, setUncontrolled] = useState<PlaygroundState>(\n () => defaultValue ?? { ...EMPTY_STATE, language: offered[0]?.id ?? \"cel\" },\n );\n const state = value ?? uncontrolled;\n const update = useCallback((patch: Partial<PlaygroundState>) => {\n const next = { ...state, ...patch };\n if (!value) setUncontrolled(next);\n onChange?.(next);\n }, [state, value, onChange]);\n return { state, update };\n}\n\nfunction usePlaygroundCatalogue({ apiBase, spec, environment }: {\n apiBase: string;\n spec: GomplateSpec | undefined;\n environment: unknown;\n}) {\n const [served, setServed] = useState<GomplateSpec>();\n const catalogue = spec ?? served;\n const activeSpec = useMemo(() => mergeSpec(packagedSpec, catalogue), [catalogue]);\n const latest = useLatest({ environment, catalogue });\n\n // Monaco registers languages before creating the first model. The catalogue\n // fetch and editor mount can finish in either order.\n const registered = useRef<RegisteredLanguages | null>(null);\n const registerLanguages = useCallback((monaco: Monaco) => {\n const current = latest.current.catalogue;\n registered.current = registerGomplateLanguages(monaco, {\n environment: () => latest.current.environment,\n ...(current ? { spec: current } : {}),\n });\n }, [latest]);\n\n useEffect(() => {\n if (spec) return;\n const controller = new AbortController();\n void fetchSpec(apiBase, controller.signal).then((next) => {\n if (!controller.signal.aborted) setServed(next);\n });\n return () => controller.abort();\n }, [apiBase, spec]);\n\n useEffect(() => {\n if (catalogue) registered.current?.setSpec(catalogue);\n }, [catalogue]);\n\n return { activeSpec, registerLanguages };\n}\n\nfunction usePlaygroundExamples(apiBase: string, examples: Example[] | undefined) {\n const [fetched, setFetched] = useState<Example[]>();\n useEffect(() => {\n if (examples) return;\n const controller = new AbortController();\n void fetchExamples(apiBase, controller.signal).then((next) => {\n if (!controller.signal.aborted && next) setFetched(next);\n });\n return () => controller.abort();\n }, [apiBase, examples]);\n return examples ?? fetched ?? NO_EXAMPLES;\n}\n\nfunction usePlaygroundEditors({ run, pathInsertion }: { run: Evaluator[\"run\"]; pathInsertion: \"caret\" | \"replace\" }) {\n const applyTheme = useEditorTheme();\n const runRef = useLatest(run);\n const sourceEditor = useRef<Parameters<typeof registerRunAction>[0] | null>(null);\n const onEditorMount = useCallback(\n (editor: Parameters<typeof registerRunAction>[0], monaco: Monaco) => {\n applyTheme();\n registerRunAction(editor, monaco, () => runRef.current());\n if (editor.getModel()?.uri.toString() === SOURCE_MODEL_PATH)\n sourceEditor.current = editor;\n },\n [applyTheme, runRef],\n );\n\n const insertExpression = useCallback((expression: string) => {\n const editor = sourceEditor.current;\n if (!editor) return;\n const range = pathInsertion === \"replace\" ? editor.getModel()?.getFullModelRange() : editor.getSelection();\n if (!range) return;\n editor.executeEdits(\"object-graph\", [\n { range, text: expression, forceMoveMarkers: true },\n ]);\n editor.focus();\n }, [pathInsertion]);\n return { onEditorMount, insertExpression };\n}\n\nfunction EditorPane({\n label,\n hint,\n actions,\n children,\n}: {\n label: string;\n hint?: React.ReactNode;\n actions?: React.ReactNode;\n children: React.ReactNode;\n}) {\n return (\n <section className=\"flex h-full min-h-0 flex-col bg-background\">\n <header className=\"flex h-[33px] shrink-0 items-center justify-between gap-2 px-4 py-2\">\n <div className=\"flex items-baseline gap-2\">\n <h2 className=\"text-xs font-medium uppercase tracking-wide text-muted-foreground\">\n {label}\n </h2>\n {hint}\n </div>\n {actions}\n </header>\n <div className=\"min-h-0 flex-1 [&_[data-slot=monaco-editor]]:h-full [&_[data-slot=monaco-editor]]:rounded-none [&_[data-slot=monaco-editor]]:border-0 [&_[data-slot=monaco-editor]]:border-t\">\n {children}\n </div>\n </section>\n );\n}\n\n/**\n * Mirrors a compile error onto the editor as a marker, so the position the\n * server reported is visible where the mistake is rather than only in the\n * result panel.\n */\nfunction useMarkers(response: EvalResponse | null) {\n useEffect(() => {\n const model = monacoEditor.editor\n .getModels()\n .find((candidate) => candidate.uri.toString() === SOURCE_MODEL_PATH);\n if (!model) return;\n\n const error = response?.error;\n if (!error?.line) {\n monacoEditor.editor.setModelMarkers(model, \"expressions\", []);\n return;\n }\n\n const column = error.column ?? 1;\n monacoEditor.editor.setModelMarkers(model, \"expressions\", [\n {\n severity: monacoEditor.MarkerSeverity.Error,\n message: error.message,\n startLineNumber: error.line,\n startColumn: column,\n endLineNumber: error.line,\n endColumn: column + 1,\n },\n ]);\n }, [response]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAwFA,IAAM,oBAAoB;AAC1B,IAAM,mBAAmB;AAEzB,IAAM,cAA+B;CAAE,UAAU;CAAO,QAAQ;CAAI,OAAO;AAAG;AAC9E,IAAM,aAAiC,CAAC;AACxC,IAAM,cAAyB,CAAC;;;;;;;;;;;;;AAchC,SAAgB,qBAAqB,EACnC,UAAU,kBACV,WAAW,UAAU,WACrB,UACA,MACA,WACA,UACA,UAAU,YACV,aACA,eACA,YACA,gBAAgB,SAChB,OACA,UACA,cACA,aAC4B;CAC5B,MAAM,EAAE,OAAO,WAAW,mBAAmB;EAAE;EAAO;EAAU;EAAc;CAAQ,CAAC;CACvF,MAAM,WAAW,cACT,aAAa,MAAM,UAAU,OAAO,GAC1C,CAAC,MAAM,UAAU,OAAO,CAC1B;CACA,MAAM,CAAC,aAAa,gBAAgB,SAAS,QAAQ;CACrD,MAAM,YAAY,gBAAgB,UAAU,CAAC,SAAS,YAAY,WAAW;CAC7E,IAAI,cAAc,aAAa,aAAa,SAAS;CAErD,MAAM,YAAY,aAAa,SAAS;EACtC,UAAU,SAAS;EACnB,QAAQ,MAAM;EACd,OAAO,MAAM;CACf,GAAG;EACD,GAAI,gBAAgB,EAAE,MAAM,cAAc,IAAI,CAAC;EAC/C,GAAI,WAAW,EAAE,SAAS,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B,aAAa,OAAO,gBAAgB,OAAO,eAAe,CACxD;GACE,UAAU,aAAa,eAAe;GACtC,SAAS,MAAM;GACf,iBAAiB,MAAM;GACvB,aAAa;GACb,eAAe,MAAM;GACrB,WAAW,SAAS;EACtB,CACF,CAAC;CACH,GAAG,CAAC,QAAQ,CAAC;AACf"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const require_use_theme = require("../../../hooks/use-theme.cjs");
|
|
2
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
3
|
+
// src/expressions/playground/panels/ReferencePanel.tsx
|
|
4
|
+
var RELATIVE_BASE = "http://relative.invalid";
|
|
5
|
+
/**
|
|
6
|
+
* The URL of a reference page in its embedded form: `embed` asks the page to
|
|
7
|
+
* drop its own navigation, and `theme` matches it to the playground's.
|
|
8
|
+
*/
|
|
9
|
+
function referencePageUrl(url, theme) {
|
|
10
|
+
const parsed = new URL(url, RELATIVE_BASE);
|
|
11
|
+
parsed.searchParams.set("embed", "");
|
|
12
|
+
parsed.searchParams.set("theme", theme);
|
|
13
|
+
const out = parsed.toString();
|
|
14
|
+
return parsed.origin === RELATIVE_BASE ? out.slice(23) : out;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Shows a host's function reference in place of the generated catalogue table.
|
|
18
|
+
*
|
|
19
|
+
* A host with its own documentation of the languages (prose, examples and the
|
|
20
|
+
* functions it registers on top of gomplate's) supplies a page; the page keeps
|
|
21
|
+
* its own highlighting and in-page anchors because it is shown as served.
|
|
22
|
+
*/
|
|
23
|
+
function ReferencePanel({ url, title }) {
|
|
24
|
+
const theme = require_use_theme.useResolvedTheme();
|
|
25
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("iframe", {
|
|
26
|
+
src: referencePageUrl(url, theme),
|
|
27
|
+
title,
|
|
28
|
+
className: "h-full w-full border-0 bg-background"
|
|
29
|
+
}, theme);
|
|
30
|
+
}
|
|
31
|
+
exports.ReferencePanel = ReferencePanel;
|
|
32
|
+
exports.referencePageUrl = referencePageUrl;
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=ReferencePanel.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReferencePanel.cjs","names":["useResolvedTheme"],"sources":["../../../../src/expressions/playground/panels/ReferencePanel.tsx"],"sourcesContent":["import { useResolvedTheme, type ResolvedTheme } from \"../../../hooks/use-theme\";\n\ninterface ReferencePanelProps {\n /** The host's reference page for the language, e.g. its CEL function docs. */\n url: string;\n /** Accessible name of the embedded page. */\n title: string;\n}\n\n// Resolves a relative host URL without a document, then drops this origin again.\nconst RELATIVE_BASE = \"http://relative.invalid\";\n\n/**\n * The URL of a reference page in its embedded form: `embed` asks the page to\n * drop its own navigation, and `theme` matches it to the playground's.\n */\nexport function referencePageUrl(url: string, theme: ResolvedTheme): string {\n const parsed = new URL(url, RELATIVE_BASE);\n parsed.searchParams.set(\"embed\", \"\");\n parsed.searchParams.set(\"theme\", theme);\n const out = parsed.toString();\n return parsed.origin === RELATIVE_BASE ? out.slice(RELATIVE_BASE.length) : out;\n}\n\n/**\n * Shows a host's function reference in place of the generated catalogue table.\n *\n * A host with its own documentation of the languages (prose, examples and the\n * functions it registers on top of gomplate's) supplies a page; the page keeps\n * its own highlighting and in-page anchors because it is shown as served.\n */\nexport function ReferencePanel({ url, title }: ReferencePanelProps) {\n const theme = useResolvedTheme();\n return (\n <iframe\n key={theme}\n src={referencePageUrl(url, theme)}\n title={title}\n className=\"h-full w-full border-0 bg-background\"\n />\n );\n}\n"],"mappings":";;;AAUA,IAAM,gBAAgB;;;;;AAMtB,SAAgB,iBAAiB,KAAa,OAA8B;CAC1E,MAAM,SAAS,IAAI,IAAI,KAAK,aAAa;CACzC,OAAO,aAAa,IAAI,SAAS,EAAE;CACnC,OAAO,aAAa,IAAI,SAAS,KAAK;CACtC,MAAM,MAAM,OAAO,SAAS;CAC5B,OAAO,OAAO,WAAW,gBAAgB,IAAI,MAAM,EAAoB,IAAI;AAC7E;;;;;;;;AASA,SAAgB,eAAe,EAAE,KAAK,SAA8B;CAClE,MAAM,QAAQA,kBAAAA,iBAAiB;CAC/B,OACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;EAEE,KAAK,iBAAiB,KAAK,KAAK;EACzB;EACP,WAAU;CACX,GAJM,KAIN;AAEL"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ResolvedTheme } from '../../../hooks/use-theme.js';
|
|
2
|
+
interface ReferencePanelProps {
|
|
3
|
+
/** The host's reference page for the language, e.g. its CEL function docs. */
|
|
4
|
+
url: string;
|
|
5
|
+
/** Accessible name of the embedded page. */
|
|
6
|
+
title: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The URL of a reference page in its embedded form: `embed` asks the page to
|
|
10
|
+
* drop its own navigation, and `theme` matches it to the playground's.
|
|
11
|
+
*/
|
|
12
|
+
export declare function referencePageUrl(url: string, theme: ResolvedTheme): string;
|
|
13
|
+
/**
|
|
14
|
+
* Shows a host's function reference in place of the generated catalogue table.
|
|
15
|
+
*
|
|
16
|
+
* A host with its own documentation of the languages (prose, examples and the
|
|
17
|
+
* functions it registers on top of gomplate's) supplies a page; the page keeps
|
|
18
|
+
* its own highlighting and in-page anchors because it is shown as served.
|
|
19
|
+
*/
|
|
20
|
+
export declare function ReferencePanel({ url, title }: ReferencePanelProps): import("react").JSX.Element;
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=ReferencePanel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReferencePanel.d.ts","sourceRoot":"","sources":["../../../../src/expressions/playground/panels/ReferencePanel.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAoB,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEhF,UAAU,mBAAmB;IAC3B,8EAA8E;IAC9E,GAAG,EAAE,MAAM,CAAC;IACZ,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;CACf;AAKD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,GAAG,MAAM,CAM1E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,mBAAmB,+BAUjE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useResolvedTheme } from "../../../hooks/use-theme.js";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
// src/expressions/playground/panels/ReferencePanel.tsx
|
|
4
|
+
var RELATIVE_BASE = "http://relative.invalid";
|
|
5
|
+
/**
|
|
6
|
+
* The URL of a reference page in its embedded form: `embed` asks the page to
|
|
7
|
+
* drop its own navigation, and `theme` matches it to the playground's.
|
|
8
|
+
*/
|
|
9
|
+
function referencePageUrl(url, theme) {
|
|
10
|
+
const parsed = new URL(url, RELATIVE_BASE);
|
|
11
|
+
parsed.searchParams.set("embed", "");
|
|
12
|
+
parsed.searchParams.set("theme", theme);
|
|
13
|
+
const out = parsed.toString();
|
|
14
|
+
return parsed.origin === RELATIVE_BASE ? out.slice(23) : out;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Shows a host's function reference in place of the generated catalogue table.
|
|
18
|
+
*
|
|
19
|
+
* A host with its own documentation of the languages (prose, examples and the
|
|
20
|
+
* functions it registers on top of gomplate's) supplies a page; the page keeps
|
|
21
|
+
* its own highlighting and in-page anchors because it is shown as served.
|
|
22
|
+
*/
|
|
23
|
+
function ReferencePanel({ url, title }) {
|
|
24
|
+
const theme = useResolvedTheme();
|
|
25
|
+
return /* @__PURE__ */ jsx("iframe", {
|
|
26
|
+
src: referencePageUrl(url, theme),
|
|
27
|
+
title,
|
|
28
|
+
className: "h-full w-full border-0 bg-background"
|
|
29
|
+
}, theme);
|
|
30
|
+
}
|
|
31
|
+
export { ReferencePanel, referencePageUrl };
|
|
32
|
+
|
|
33
|
+
//# sourceMappingURL=ReferencePanel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReferencePanel.js","names":[],"sources":["../../../../src/expressions/playground/panels/ReferencePanel.tsx"],"sourcesContent":["import { useResolvedTheme, type ResolvedTheme } from \"../../../hooks/use-theme\";\n\ninterface ReferencePanelProps {\n /** The host's reference page for the language, e.g. its CEL function docs. */\n url: string;\n /** Accessible name of the embedded page. */\n title: string;\n}\n\n// Resolves a relative host URL without a document, then drops this origin again.\nconst RELATIVE_BASE = \"http://relative.invalid\";\n\n/**\n * The URL of a reference page in its embedded form: `embed` asks the page to\n * drop its own navigation, and `theme` matches it to the playground's.\n */\nexport function referencePageUrl(url: string, theme: ResolvedTheme): string {\n const parsed = new URL(url, RELATIVE_BASE);\n parsed.searchParams.set(\"embed\", \"\");\n parsed.searchParams.set(\"theme\", theme);\n const out = parsed.toString();\n return parsed.origin === RELATIVE_BASE ? out.slice(RELATIVE_BASE.length) : out;\n}\n\n/**\n * Shows a host's function reference in place of the generated catalogue table.\n *\n * A host with its own documentation of the languages (prose, examples and the\n * functions it registers on top of gomplate's) supplies a page; the page keeps\n * its own highlighting and in-page anchors because it is shown as served.\n */\nexport function ReferencePanel({ url, title }: ReferencePanelProps) {\n const theme = useResolvedTheme();\n return (\n <iframe\n key={theme}\n src={referencePageUrl(url, theme)}\n title={title}\n className=\"h-full w-full border-0 bg-background\"\n />\n );\n}\n"],"mappings":";;;AAUA,IAAM,gBAAgB;;;;;AAMtB,SAAgB,iBAAiB,KAAa,OAA8B;CAC1E,MAAM,SAAS,IAAI,IAAI,KAAK,aAAa;CACzC,OAAO,aAAa,IAAI,SAAS,EAAE;CACnC,OAAO,aAAa,IAAI,SAAS,KAAK;CACtC,MAAM,MAAM,OAAO,SAAS;CAC5B,OAAO,OAAO,WAAW,gBAAgB,IAAI,MAAM,EAAoB,IAAI;AAC7E;;;;;;;;AASA,SAAgB,eAAe,EAAE,KAAK,SAA8B;CAClE,MAAM,QAAQ,iBAAiB;CAC/B,OACE,oBAAC,UAAD;EAEE,KAAK,iBAAiB,KAAK,KAAK;EACzB;EACP,WAAU;CACX,GAJM,KAIN;AAEL"}
|
|
@@ -23,7 +23,14 @@ function SpecPanel({ flavour, spec }) {
|
|
|
23
23
|
label: "Name",
|
|
24
24
|
sortable: true,
|
|
25
25
|
grow: true,
|
|
26
|
-
cellClassName: "font-mono"
|
|
26
|
+
cellClassName: "font-mono",
|
|
27
|
+
render: (value, row) => row.docsUrl ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("a", {
|
|
28
|
+
href: row.docsUrl,
|
|
29
|
+
target: "_blank",
|
|
30
|
+
rel: "noreferrer",
|
|
31
|
+
className: "text-primary hover:underline",
|
|
32
|
+
children: String(value)
|
|
33
|
+
}) : String(value)
|
|
27
34
|
},
|
|
28
35
|
{
|
|
29
36
|
key: "namespace",
|
|
@@ -78,7 +85,8 @@ function toRow(fn) {
|
|
|
78
85
|
namespace: fn.namespace ?? "",
|
|
79
86
|
signature: signatureOf(fn),
|
|
80
87
|
kind: fn.memberOnly ? "member" : "global",
|
|
81
|
-
doc: fn.doc ?? ""
|
|
88
|
+
doc: fn.doc ?? "",
|
|
89
|
+
docsUrl: fn.docsUrl ?? ""
|
|
82
90
|
};
|
|
83
91
|
}
|
|
84
92
|
function signatureOf(fn) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpecPanel.cjs","names":["useMemo","DataTable","Badge"],"sources":["../../../../src/expressions/playground/panels/SpecPanel.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport { Badge } from \"../../../data/Badge\";\nimport { DataTable, type DataTableColumn } from \"../../../data/DataTable\";\nimport type { GomplateSpec, SpecFunction } from \"../../lang/index.ts\";\n\ninterface SpecPanelProps {\n /** Which catalogue to browse. */\n flavour: \"cel\" | \"gotemplate\";\n /** The catalogue itself — the server's when it has one, gomplate's otherwise. */\n spec: GomplateSpec;\n}\n\ninterface FunctionRow extends Record<string, unknown> {\n name: string;\n namespace: string;\n signature: string;\n kind: string;\n doc: string;\n}\n\n/**\n * Browses the generated function catalogue.\n *\n * This is the first accurate reference that exists for this fork: CEL.md\n * documents functions that live in `duty` and omits whole namespaces, while\n * docs-src carries the upstream list. What is shown here is read out of the\n * live registries, so it is what the evaluator will actually accept.\n */\nexport function SpecPanel({ flavour, spec }: SpecPanelProps) {\n const rows = useMemo(() => {\n const functions =\n flavour === \"cel\" ? spec.cel.functions : spec.gotemplate.functions;\n return functions.map(toRow);\n }, [flavour, spec]);\n\n const columns: DataTableColumn<FunctionRow>[] = [\n {\n key: \"name\",\n label: \"Name\",\n sortable: true,\n grow: true,\n cellClassName: \"font-mono\",\n },\n {\n key: \"namespace\",\n label: \"Namespace\",\n sortable: true,\n filterable: true,\n shrink: true,\n render: (value) =>\n value ? (\n String(value)\n ) : (\n <span className=\"text-muted-foreground\">—</span>\n ),\n },\n {\n key: \"kind\",\n label: \"Call\",\n filterable: true,\n shrink: true,\n // `x.sum()` is legal where a bare `sum(x)` is not, and nothing else in\n // the catalogue records that -- so it is worth a column of its own.\n render: (value) =>\n value === \"member\" ? (\n <Badge variant=\"outline\">member only</Badge>\n ) : (\n <span className=\"text-muted-foreground\">global</span>\n ),\n },\n {\n key: \"signature\",\n label: \"Signature\",\n grow: true,\n cellClassName: \"font-mono text-muted-foreground\",\n },\n { key: \"doc\", label: \"Description\", grow: true },\n ];\n\n return (\n <DataTable\n data={rows}\n columns={columns}\n autoFilter\n showGlobalFilter\n globalFilterPlaceholder=\"Filter functions…\"\n defaultSort={{ key: \"name\", dir: \"asc\" }}\n emptyMessage=\"No functions in this catalogue.\"\n className=\"h-full\"\n />\n );\n}\n\nfunction toRow(fn: SpecFunction): FunctionRow {\n return {\n name: fn.name,\n namespace: fn.namespace ?? \"\",\n signature: signatureOf(fn),\n kind: fn.memberOnly ? \"member\" : \"global\",\n doc: fn.doc ?? \"\",\n };\n}\n\nfunction signatureOf(fn: SpecFunction): string {\n if (fn.signature) return fn.signature;\n\n const [overload] = fn.overloads ?? [];\n if (!overload) return \"\";\n\n // A member overload carries its receiver as the first argument; an author\n // writes it before the dot, not inside the parentheses.\n const args = overload.member ? overload.args.slice(1) : overload.args;\n return `(${args.join(\", \")}) -> ${overload.result}`;\n}\n"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"SpecPanel.cjs","names":["useMemo","DataTable","Badge"],"sources":["../../../../src/expressions/playground/panels/SpecPanel.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport { Badge } from \"../../../data/Badge\";\nimport { DataTable, type DataTableColumn } from \"../../../data/DataTable\";\nimport type { GomplateSpec, SpecFunction } from \"../../lang/index.ts\";\n\ninterface SpecPanelProps {\n /** Which catalogue to browse. */\n flavour: \"cel\" | \"gotemplate\";\n /** The catalogue itself — the server's when it has one, gomplate's otherwise. */\n spec: GomplateSpec;\n}\n\ninterface FunctionRow extends Record<string, unknown> {\n name: string;\n namespace: string;\n signature: string;\n kind: string;\n doc: string;\n /** The function's section in the host's reference page, when it publishes one. */\n docsUrl: string;\n}\n\n/**\n * Browses the generated function catalogue.\n *\n * This is the first accurate reference that exists for this fork: CEL.md\n * documents functions that live in `duty` and omits whole namespaces, while\n * docs-src carries the upstream list. What is shown here is read out of the\n * live registries, so it is what the evaluator will actually accept.\n */\nexport function SpecPanel({ flavour, spec }: SpecPanelProps) {\n const rows = useMemo(() => {\n const functions =\n flavour === \"cel\" ? spec.cel.functions : spec.gotemplate.functions;\n return functions.map(toRow);\n }, [flavour, spec]);\n\n const columns: DataTableColumn<FunctionRow>[] = [\n {\n key: \"name\",\n label: \"Name\",\n sortable: true,\n grow: true,\n cellClassName: \"font-mono\",\n render: (value, row) =>\n row.docsUrl ? (\n <a href={row.docsUrl} target=\"_blank\" rel=\"noreferrer\" className=\"text-primary hover:underline\">\n {String(value)}\n </a>\n ) : (\n String(value)\n ),\n },\n {\n key: \"namespace\",\n label: \"Namespace\",\n sortable: true,\n filterable: true,\n shrink: true,\n render: (value) =>\n value ? (\n String(value)\n ) : (\n <span className=\"text-muted-foreground\">—</span>\n ),\n },\n {\n key: \"kind\",\n label: \"Call\",\n filterable: true,\n shrink: true,\n // `x.sum()` is legal where a bare `sum(x)` is not, and nothing else in\n // the catalogue records that -- so it is worth a column of its own.\n render: (value) =>\n value === \"member\" ? (\n <Badge variant=\"outline\">member only</Badge>\n ) : (\n <span className=\"text-muted-foreground\">global</span>\n ),\n },\n {\n key: \"signature\",\n label: \"Signature\",\n grow: true,\n cellClassName: \"font-mono text-muted-foreground\",\n },\n { key: \"doc\", label: \"Description\", grow: true },\n ];\n\n return (\n <DataTable\n data={rows}\n columns={columns}\n autoFilter\n showGlobalFilter\n globalFilterPlaceholder=\"Filter functions…\"\n defaultSort={{ key: \"name\", dir: \"asc\" }}\n emptyMessage=\"No functions in this catalogue.\"\n className=\"h-full\"\n />\n );\n}\n\nfunction toRow(fn: SpecFunction): FunctionRow {\n return {\n name: fn.name,\n namespace: fn.namespace ?? \"\",\n signature: signatureOf(fn),\n kind: fn.memberOnly ? \"member\" : \"global\",\n doc: fn.doc ?? \"\",\n docsUrl: fn.docsUrl ?? \"\",\n };\n}\n\nfunction signatureOf(fn: SpecFunction): string {\n if (fn.signature) return fn.signature;\n\n const [overload] = fn.overloads ?? [];\n if (!overload) return \"\";\n\n // A member overload carries its receiver as the first argument; an author\n // writes it before the dot, not inside the parentheses.\n const args = overload.member ? overload.args.slice(1) : overload.args;\n return `(${args.join(\", \")}) -> ${overload.result}`;\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgB,UAAU,EAAE,SAAS,QAAwB;CAC3D,MAAM,QAAA,GAAOA,MAAAA,QAAAA,OAAc;EAGzB,QADE,YAAY,QAAQ,KAAK,IAAI,YAAY,KAAK,WAAW,UAAA,CAC1C,IAAI,KAAK;CAC5B,GAAG,CAAC,SAAS,IAAI,CAAC;CAsDlB,OACE,iBAAA,GAAA,kBAAA,IAAA,CAACC,kBAAAA,WAAD;EACE,MAAM;EACG,SAAA;GAtD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;CAKtB,OAAO,KADM,SAAS,SAAS,SAAS,KAAK,MAAM,CAAC,IAAI,SAAS,KAAA,CACjD,KAAK,IAAI,EAAE,OAAO,SAAS;AAC7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpecPanel.d.ts","sourceRoot":"","sources":["../../../../src/expressions/playground/panels/SpecPanel.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,qBAAqB,CAAC;AAEtE,UAAU,cAAc;IACtB,iCAAiC;IACjC,OAAO,EAAE,KAAK,GAAG,YAAY,CAAC;IAC9B,iFAAiF;IACjF,IAAI,EAAE,YAAY,CAAC;CACpB;
|
|
1
|
+
{"version":3,"file":"SpecPanel.d.ts","sourceRoot":"","sources":["../../../../src/expressions/playground/panels/SpecPanel.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAgB,MAAM,qBAAqB,CAAC;AAEtE,UAAU,cAAc;IACtB,iCAAiC;IACjC,OAAO,EAAE,KAAK,GAAG,YAAY,CAAC;IAC9B,iFAAiF;IACjF,IAAI,EAAE,YAAY,CAAC;CACpB;AAYD;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,cAAc,+BAuE1D"}
|
|
@@ -23,7 +23,14 @@ function SpecPanel({ flavour, spec }) {
|
|
|
23
23
|
label: "Name",
|
|
24
24
|
sortable: true,
|
|
25
25
|
grow: true,
|
|
26
|
-
cellClassName: "font-mono"
|
|
26
|
+
cellClassName: "font-mono",
|
|
27
|
+
render: (value, row) => row.docsUrl ? /* @__PURE__ */ jsx("a", {
|
|
28
|
+
href: row.docsUrl,
|
|
29
|
+
target: "_blank",
|
|
30
|
+
rel: "noreferrer",
|
|
31
|
+
className: "text-primary hover:underline",
|
|
32
|
+
children: String(value)
|
|
33
|
+
}) : String(value)
|
|
27
34
|
},
|
|
28
35
|
{
|
|
29
36
|
key: "namespace",
|
|
@@ -78,7 +85,8 @@ function toRow(fn) {
|
|
|
78
85
|
namespace: fn.namespace ?? "",
|
|
79
86
|
signature: signatureOf(fn),
|
|
80
87
|
kind: fn.memberOnly ? "member" : "global",
|
|
81
|
-
doc: fn.doc ?? ""
|
|
88
|
+
doc: fn.doc ?? "",
|
|
89
|
+
docsUrl: fn.docsUrl ?? ""
|
|
82
90
|
};
|
|
83
91
|
}
|
|
84
92
|
function signatureOf(fn) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpecPanel.js","names":[],"sources":["../../../../src/expressions/playground/panels/SpecPanel.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport { Badge } from \"../../../data/Badge\";\nimport { DataTable, type DataTableColumn } from \"../../../data/DataTable\";\nimport type { GomplateSpec, SpecFunction } from \"../../lang/index.ts\";\n\ninterface SpecPanelProps {\n /** Which catalogue to browse. */\n flavour: \"cel\" | \"gotemplate\";\n /** The catalogue itself — the server's when it has one, gomplate's otherwise. */\n spec: GomplateSpec;\n}\n\ninterface FunctionRow extends Record<string, unknown> {\n name: string;\n namespace: string;\n signature: string;\n kind: string;\n doc: string;\n}\n\n/**\n * Browses the generated function catalogue.\n *\n * This is the first accurate reference that exists for this fork: CEL.md\n * documents functions that live in `duty` and omits whole namespaces, while\n * docs-src carries the upstream list. What is shown here is read out of the\n * live registries, so it is what the evaluator will actually accept.\n */\nexport function SpecPanel({ flavour, spec }: SpecPanelProps) {\n const rows = useMemo(() => {\n const functions =\n flavour === \"cel\" ? spec.cel.functions : spec.gotemplate.functions;\n return functions.map(toRow);\n }, [flavour, spec]);\n\n const columns: DataTableColumn<FunctionRow>[] = [\n {\n key: \"name\",\n label: \"Name\",\n sortable: true,\n grow: true,\n cellClassName: \"font-mono\",\n },\n {\n key: \"namespace\",\n label: \"Namespace\",\n sortable: true,\n filterable: true,\n shrink: true,\n render: (value) =>\n value ? (\n String(value)\n ) : (\n <span className=\"text-muted-foreground\">—</span>\n ),\n },\n {\n key: \"kind\",\n label: \"Call\",\n filterable: true,\n shrink: true,\n // `x.sum()` is legal where a bare `sum(x)` is not, and nothing else in\n // the catalogue records that -- so it is worth a column of its own.\n render: (value) =>\n value === \"member\" ? (\n <Badge variant=\"outline\">member only</Badge>\n ) : (\n <span className=\"text-muted-foreground\">global</span>\n ),\n },\n {\n key: \"signature\",\n label: \"Signature\",\n grow: true,\n cellClassName: \"font-mono text-muted-foreground\",\n },\n { key: \"doc\", label: \"Description\", grow: true },\n ];\n\n return (\n <DataTable\n data={rows}\n columns={columns}\n autoFilter\n showGlobalFilter\n globalFilterPlaceholder=\"Filter functions…\"\n defaultSort={{ key: \"name\", dir: \"asc\" }}\n emptyMessage=\"No functions in this catalogue.\"\n className=\"h-full\"\n />\n );\n}\n\nfunction toRow(fn: SpecFunction): FunctionRow {\n return {\n name: fn.name,\n namespace: fn.namespace ?? \"\",\n signature: signatureOf(fn),\n kind: fn.memberOnly ? \"member\" : \"global\",\n doc: fn.doc ?? \"\",\n };\n}\n\nfunction signatureOf(fn: SpecFunction): string {\n if (fn.signature) return fn.signature;\n\n const [overload] = fn.overloads ?? [];\n if (!overload) return \"\";\n\n // A member overload carries its receiver as the first argument; an author\n // writes it before the dot, not inside the parentheses.\n const args = overload.member ? overload.args.slice(1) : overload.args;\n return `(${args.join(\", \")}) -> ${overload.result}`;\n}\n"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"SpecPanel.js","names":[],"sources":["../../../../src/expressions/playground/panels/SpecPanel.tsx"],"sourcesContent":["import { useMemo } from \"react\";\nimport { Badge } from \"../../../data/Badge\";\nimport { DataTable, type DataTableColumn } from \"../../../data/DataTable\";\nimport type { GomplateSpec, SpecFunction } from \"../../lang/index.ts\";\n\ninterface SpecPanelProps {\n /** Which catalogue to browse. */\n flavour: \"cel\" | \"gotemplate\";\n /** The catalogue itself — the server's when it has one, gomplate's otherwise. */\n spec: GomplateSpec;\n}\n\ninterface FunctionRow extends Record<string, unknown> {\n name: string;\n namespace: string;\n signature: string;\n kind: string;\n doc: string;\n /** The function's section in the host's reference page, when it publishes one. */\n docsUrl: string;\n}\n\n/**\n * Browses the generated function catalogue.\n *\n * This is the first accurate reference that exists for this fork: CEL.md\n * documents functions that live in `duty` and omits whole namespaces, while\n * docs-src carries the upstream list. What is shown here is read out of the\n * live registries, so it is what the evaluator will actually accept.\n */\nexport function SpecPanel({ flavour, spec }: SpecPanelProps) {\n const rows = useMemo(() => {\n const functions =\n flavour === \"cel\" ? spec.cel.functions : spec.gotemplate.functions;\n return functions.map(toRow);\n }, [flavour, spec]);\n\n const columns: DataTableColumn<FunctionRow>[] = [\n {\n key: \"name\",\n label: \"Name\",\n sortable: true,\n grow: true,\n cellClassName: \"font-mono\",\n render: (value, row) =>\n row.docsUrl ? (\n <a href={row.docsUrl} target=\"_blank\" rel=\"noreferrer\" className=\"text-primary hover:underline\">\n {String(value)}\n </a>\n ) : (\n String(value)\n ),\n },\n {\n key: \"namespace\",\n label: \"Namespace\",\n sortable: true,\n filterable: true,\n shrink: true,\n render: (value) =>\n value ? (\n String(value)\n ) : (\n <span className=\"text-muted-foreground\">—</span>\n ),\n },\n {\n key: \"kind\",\n label: \"Call\",\n filterable: true,\n shrink: true,\n // `x.sum()` is legal where a bare `sum(x)` is not, and nothing else in\n // the catalogue records that -- so it is worth a column of its own.\n render: (value) =>\n value === \"member\" ? (\n <Badge variant=\"outline\">member only</Badge>\n ) : (\n <span className=\"text-muted-foreground\">global</span>\n ),\n },\n {\n key: \"signature\",\n label: \"Signature\",\n grow: true,\n cellClassName: \"font-mono text-muted-foreground\",\n },\n { key: \"doc\", label: \"Description\", grow: true },\n ];\n\n return (\n <DataTable\n data={rows}\n columns={columns}\n autoFilter\n showGlobalFilter\n globalFilterPlaceholder=\"Filter functions…\"\n defaultSort={{ key: \"name\", dir: \"asc\" }}\n emptyMessage=\"No functions in this catalogue.\"\n className=\"h-full\"\n />\n );\n}\n\nfunction toRow(fn: SpecFunction): FunctionRow {\n return {\n name: fn.name,\n namespace: fn.namespace ?? \"\",\n signature: signatureOf(fn),\n kind: fn.memberOnly ? \"member\" : \"global\",\n doc: fn.doc ?? \"\",\n docsUrl: fn.docsUrl ?? \"\",\n };\n}\n\nfunction signatureOf(fn: SpecFunction): string {\n if (fn.signature) return fn.signature;\n\n const [overload] = fn.overloads ?? [];\n if (!overload) return \"\";\n\n // A member overload carries its receiver as the first argument; an author\n // writes it before the dot, not inside the parentheses.\n const args = overload.member ? overload.args.slice(1) : overload.args;\n return `(${args.join(\", \")}) -> ${overload.result}`;\n}\n"],"mappings":";;;;;;;;;;;;;AA8BA,SAAgB,UAAU,EAAE,SAAS,QAAwB;CAC3D,MAAM,OAAO,cAAc;EAGzB,QADE,YAAY,QAAQ,KAAK,IAAI,YAAY,KAAK,WAAW,UAAA,CAC1C,IAAI,KAAK;CAC5B,GAAG,CAAC,SAAS,IAAI,CAAC;CAsDlB,OACE,oBAAC,WAAD;EACE,MAAM;EACG,SAAA;GAtDX;IACE,KAAK;IACL,OAAO;IACP,UAAU;IACV,MAAM;IACN,eAAe;IACf,SAAS,OAAO,QACd,IAAI,UACF,oBAAC,KAAD;KAAG,MAAM,IAAI;KAAS,QAAO;KAAS,KAAI;KAAa,WAAU;KAC9D,UAAA,OAAO,KAAK;IACZ,CAAA,IAEH,OAAO,KAAK;GAElB;GACA;IACE,KAAK;IACL,OAAO;IACP,UAAU;IACV,YAAY;IACZ,QAAQ;IACR,SAAS,UACP,QACE,OAAO,KAAK,IAEZ,oBAAC,QAAD;KAAM,WAAU;KAAwB,UAAA;IAAO,CAAA;GAErD;GACA;IACE,KAAK;IACL,OAAO;IACP,YAAY;IACZ,QAAQ;IAGR,SAAS,UACP,UAAU,WACR,oBAAC,OAAD;KAAO,SAAQ;KAAU,UAAA;IAAkB,CAAA,IAE3C,oBAAC,QAAD;KAAM,WAAU;KAAwB,UAAA;IAAY,CAAA;GAE1D;GACA;IACE,KAAK;IACL,OAAO;IACP,MAAM;IACN,eAAe;GACjB;G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