-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): Response tag implemented - use response data from other req…
…uests in any request input without using env vars
- Loading branch information
1 parent
472047b
commit c167d21
Showing
29 changed files
with
978 additions
and
204 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { ViewPlugin, Decoration, EditorView, ViewUpdate, MatchDecorator, WidgetType, DecorationSet } from '@codemirror/view' | ||
import { parseFunction } from '@/parsers/tag' | ||
import type { ParsedResult } from '@/parsers/tag' | ||
|
||
type OnClickType = (parsedFunc: ParsedResult, updateFunc: (updatedTag: string) => void) => void | ||
|
||
class PlaceholderWidget extends WidgetType { | ||
readonly #onClick: () => void | ||
#parsed: ParsedResult | ||
readonly #view: EditorView | ||
readonly #pos: number | ||
|
||
constructor(readonly placeholder: string, readonly onClick: OnClickType, readonly view: EditorView, readonly pos: number) { | ||
super() | ||
this.#parsed = parseFunction(placeholder) | ||
this.#onClick = () => { | ||
onClick(this.#parsed, this.updateTag) | ||
} | ||
this.#view = view | ||
this.#pos = pos | ||
} | ||
|
||
eq(other: PlaceholderWidget) { | ||
return this.placeholder === other.placeholder | ||
} | ||
|
||
toDOM() { | ||
const span = document.createElement('span') | ||
span.className = 'tag' | ||
span.textContent = `${this.#parsed.functionName}(...)` | ||
span.title = this.placeholder | ||
span.addEventListener('click', this.#onClick) | ||
return span | ||
} | ||
|
||
ignoreEvent(): boolean { | ||
return false | ||
} | ||
|
||
destroy(dom: HTMLElement): void { | ||
dom.removeEventListener('click', this.#onClick) | ||
} | ||
|
||
updateTag = (updatedTag: string) => { | ||
this.#parsed = parseFunction(updatedTag) | ||
this.#view.dispatch({ | ||
changes: { from: this.#pos + 3, to: this.#pos + this.placeholder.length + 3, insert: updatedTag } | ||
}) | ||
} | ||
} | ||
|
||
export function tags(onClick: OnClickType) { | ||
const placeholderMatcher = new MatchDecorator({ | ||
regexp: /{% (.+?) %}/g, | ||
decoration: (match, view, pos) => Decoration.replace({ | ||
widget: new PlaceholderWidget(match[1], onClick, view, pos), | ||
}) | ||
}) | ||
|
||
const tags = ViewPlugin.fromClass( | ||
class { | ||
placeholders: DecorationSet | ||
constructor(view: EditorView) { | ||
this.placeholders = placeholderMatcher.createDeco(view) | ||
} | ||
update(update: ViewUpdate) { | ||
this.placeholders = placeholderMatcher.updateDeco(update, this.placeholders) | ||
} | ||
}, | ||
{ | ||
decorations: instance => instance.placeholders, | ||
provide: plugin => EditorView.atomicRanges.of(view => { | ||
return view.plugin(plugin)?.placeholders || Decoration.none | ||
}) | ||
} | ||
) | ||
|
||
return tags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.