Skip to content

Commit

Permalink
feat(div): actions
Browse files Browse the repository at this point in the history
  • Loading branch information
johnlindquist committed Nov 30, 2024
1 parent 95fe7bb commit 31fdb4c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
33 changes: 18 additions & 15 deletions src/target/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import type {
ClipboardItem,
ChannelMap,
ScreenshotConfig,
DivConfig,
} from "../types/kitapp"

import {
Expand Down Expand Up @@ -1543,24 +1544,24 @@ let maybeWrapHtml = (html = "", containerClasses = "") => {
}

global.div = async (
htmlOrConfig = "",
containerClasses = ""
) => {
let config: {
html?: string
} =
typeof htmlOrConfig === "string"
? { html: htmlOrConfig }
: htmlOrConfig

if (config.html.trim() === "")
htmlOrConfig = md("⚠️ html string was empty")
htmlOrConfig: string | DivConfig = "",
actions: Action[] = []
): Promise<any> => {
let config: DivConfig = typeof htmlOrConfig === "string"
? { html: htmlOrConfig }
: htmlOrConfig

if (!config.html?.trim()) {
config.html = md("⚠️ html string was empty")
}

return await global.kitPrompt({
enter: `Continue`,
enter: 'Continue',
shortcuts: [escapeShortcut],
...config,
choices: maybeWrapHtml(config?.html, containerClasses),
choices: maybeWrapHtml(config.html, config.containerClasses),
ui: UI.div,
actions,
})
}

Expand All @@ -1570,7 +1571,9 @@ global.getCodeblocksFromSections =
let fileMarkdown = sections.find(
s => s.name === name
)?.raw
if (!fileMarkdown) return ""
if (!fileMarkdown) {
return ""
}
let lexer = new marked.Lexer()
let nodes = lexer.lex(fileMarkdown)
// Grab all of the code blocks
Expand Down
2 changes: 1 addition & 1 deletion src/target/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ global.getScriptsState = async () => ({
schedule: [],
})

global.div = async (html = "", containerClasses = "") => {
global.div = async (html = "") => {
if (global.flag?.log === false) return

// let { default: cliHtml } = await import("cli-html")
Expand Down
3 changes: 2 additions & 1 deletion src/types/kitapp.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,12 @@ export interface DivConfig extends PromptConfig {
placeholder?: string
hint?: string
footer?: string
containerClasses?: string
}

export type Div = (
html?: string | DivConfig,
containerClass?: string
actions?: Action[]
) => Promise<any>

export interface KeyData {
Expand Down

0 comments on commit 31fdb4c

Please sign in to comment.