@clack/core
Advanced tools
+6
-0
| # @clack/core | ||
| ## 1.4.3 | ||
| ### Patch Changes | ||
| - [#582](https://github.com/bombshell-dev/clack/pull/582) [`4b24953`](https://github.com/bombshell-dev/clack/commit/4b249539e28eecc16c13b3a1bd0ba447e9f38d06) Thanks [@43081j](https://github.com/43081j)! - Handle empty arrays in various prompts and utilities. | ||
| ## 1.4.2 | ||
@@ -4,0 +10,0 @@ |
+45
-43
@@ -13,3 +13,3 @@ import { styleText } from 'node:util'; | ||
| const t = s + o, n = Math.max(l.length - 1, 0), e = t < 0 ? n : t > n ? 0 : t; | ||
| return l[e].disabled ? findCursor(e, o < 0 ? -1 : 1, l) : e; | ||
| return l[e]?.disabled ? findCursor(e, o < 0 ? -1 : 1, l) : e; | ||
| } | ||
@@ -36,3 +36,3 @@ function findTextCursor(s, o, l, i) { | ||
| const a$2 = ["up", "down", "left", "right", "space", "enter", "cancel"], t = [ | ||
| const a$1 = ["up", "down", "left", "right", "space", "enter", "cancel"], t = [ | ||
| "January", | ||
@@ -52,3 +52,3 @@ "February", | ||
| const settings = { | ||
| actions: new Set(a$2), | ||
| actions: new Set(a$1), | ||
| aliases: /* @__PURE__ */ new Map([ | ||
@@ -86,3 +86,3 @@ // vim support | ||
| const i = e[s]; | ||
| settings.actions.has(i) && (settings.aliases.has(s) || settings.aliases.set(s, i)); | ||
| i === void 0 || !settings.actions.has(i) || settings.aliases.has(s) || settings.aliases.set(s, i); | ||
| } | ||
@@ -387,4 +387,4 @@ } | ||
| return `${this.userInput}\u2588`; | ||
| const e = this.userInput.slice(0, this._cursor), [t, ...i] = this.userInput.slice(this._cursor); | ||
| return `${e}${styleText("inverse", t)}${i.join("")}`; | ||
| const e = this.userInput.slice(0, this.cursor), t = this.userInput.slice(this.cursor, this.cursor + 1), i = this.userInput.slice(this.cursor + 1); | ||
| return `${e}${styleText("inverse", t)}${i}`; | ||
| } | ||
@@ -399,3 +399,3 @@ get options() { | ||
| let i; | ||
| if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0].value]), i) | ||
| if (e.initialValue && Array.isArray(e.initialValue) ? this.multiple ? i = e.initialValue : i = e.initialValue.slice(0, 1) : !this.multiple && this.options.length > 0 && (i = [this.options[0]?.value]), i) | ||
| for (const s of i) { | ||
@@ -411,3 +411,3 @@ const n = t.findIndex((o) => o.value === s); | ||
| #l(e, t) { | ||
| const i = t.name === "up", s = t.name === "down", n = t.name === "return", o = this.userInput === "" || this.userInput === " ", u = this.#n, h = this.options, f = u !== void 0 && u !== "" && h.some( | ||
| const i = t.name === "up", s = t.name === "down", n = t.name === "return", o = this.userInput === "" || this.userInput === " ", u = this.#n, a = this.options, f = u !== void 0 && u !== "" && a.some( | ||
| (r) => !r.disabled && (this.#t ? this.#t(u, r) : true) | ||
@@ -685,3 +685,3 @@ ); | ||
| let u$1 = class u extends V { | ||
| let u$2 = class u extends V { | ||
| options; | ||
@@ -699,11 +699,12 @@ cursor = 0; | ||
| const t = this.options[this.cursor]; | ||
| if (this.value === void 0 && (this.value = []), t.group === true) { | ||
| const r = t.value, e = this.getGroupItems(r); | ||
| this.isGroupSelected(r) ? this.value = this.value.filter( | ||
| (s) => e.findIndex((i) => i.value === s) === -1 | ||
| ) : this.value = [...this.value, ...e.map((s) => s.value)], this.value = Array.from(new Set(this.value)); | ||
| } else { | ||
| const r = this.value.includes(t.value); | ||
| this.value = r ? this.value.filter((e) => e !== t.value) : [...this.value, t.value]; | ||
| } | ||
| if (t !== void 0) | ||
| if (this.value === void 0 && (this.value = []), t.group === true) { | ||
| const r = t.value, e = this.getGroupItems(r); | ||
| this.isGroupSelected(r) ? this.value = this.value.filter( | ||
| (s) => e.findIndex((i) => i.value === s) === -1 | ||
| ) : this.value = [...this.value, ...e.map((s) => s.value)], this.value = Array.from(new Set(this.value)); | ||
| } else { | ||
| const r = this.value.includes(t.value); | ||
| this.value = r ? this.value.filter((e) => e !== t.value) : [...this.value, t.value]; | ||
| } | ||
| } | ||
@@ -743,3 +744,3 @@ constructor(t) { | ||
| const o$1 = /* @__PURE__ */ new Set(["up", "down", "left", "right"]); | ||
| const o = /* @__PURE__ */ new Set(["up", "down", "left", "right"]); | ||
| class h extends V { | ||
@@ -755,3 +756,3 @@ #t = false; | ||
| return `${t}\u2588`; | ||
| const s = t.slice(0, this.cursor), r = t[this.cursor], i = t.slice(this.cursor + 1); | ||
| const s = t.slice(0, this.cursor), r = t.slice(this.cursor, this.cursor + 1), i = t.slice(this.cursor + 1); | ||
| return r === ` | ||
@@ -810,3 +811,3 @@ ` ? `${s}\u2588 | ||
| ), s !== void 0 && (this._cursor = s.length), this.#s = t.showSubmit ?? false, this.on("key", (r, i) => { | ||
| if (i?.name && o$1.has(i.name)) { | ||
| if (i?.name && o.has(i.name)) { | ||
| this.#t = false, this.#i(i.name); | ||
@@ -842,7 +843,7 @@ return; | ||
| let a$1 = class a extends V { | ||
| class a extends V { | ||
| options; | ||
| cursor = 0; | ||
| get _value() { | ||
| return this.options[this.cursor].value; | ||
| return this.options[this.cursor]?.value; | ||
| } | ||
@@ -874,3 +875,3 @@ get _enabledOptions() { | ||
| ); | ||
| this.cursor = this.options[i].disabled ? findCursor(i, 1, this.options) : i, this.on("key", (t, l) => { | ||
| this.cursor = this.options[i]?.disabled ? findCursor(i, 1, this.options) : i, this.on("key", (t, l) => { | ||
| l.name === "a" && this.toggleAll(), l.name === "i" && this.toggleInvert(); | ||
@@ -893,5 +894,5 @@ }), this.on("cursor", (t) => { | ||
| } | ||
| }; | ||
| } | ||
| class o extends V { | ||
| let u$1 = class u extends V { | ||
| _mask = "\u2022"; | ||
@@ -910,4 +911,4 @@ get cursor() { | ||
| return `${this.masked}${styleText(["inverse", "hidden"], "_")}`; | ||
| const s = this.masked, e = s.slice(0, this.cursor), r = s.slice(this.cursor); | ||
| return `${e}${styleText("inverse", r[0])}${r.slice(1)}`; | ||
| const s = this.masked, r = s.slice(0, this.cursor), i = s.slice(this.cursor, this.cursor + 1), o = s.slice(this.cursor + 1); | ||
| return `${r}${styleText("inverse", i)}${o}`; | ||
| } | ||
@@ -918,4 +919,4 @@ clear() { | ||
| constructor({ mask: t, ...s }) { | ||
| super(s), this._mask = t ?? "\u2022", this.on("userInput", (e) => { | ||
| this._setValue(e); | ||
| super(s), this._mask = t ?? "\u2022", this.on("userInput", (r) => { | ||
| this._setValue(r); | ||
| }), this.on("finalize", () => { | ||
@@ -925,5 +926,5 @@ this.value === void 0 && (this.value = ""); | ||
| } | ||
| } | ||
| }; | ||
| class a extends V { | ||
| let n$1 = class n extends V { | ||
| options; | ||
@@ -935,8 +936,9 @@ cursor = 0; | ||
| changeValue() { | ||
| this.value = this._selectedValue.value; | ||
| const e = this._selectedValue; | ||
| this.value = e === void 0 ? void 0 : e.value; | ||
| } | ||
| constructor(t) { | ||
| super(t, false), this.options = t.options; | ||
| const i = this.options.findIndex(({ value: s }) => s === t.initialValue), e = i === -1 ? 0 : i; | ||
| this.cursor = this.options[e].disabled ? findCursor(e, 1, this.options) : e, this.changeValue(), this.on("cursor", (s) => { | ||
| constructor(e) { | ||
| super(e, false), this.options = e.options; | ||
| const o = this.options.findIndex(({ value: s }) => s === e.initialValue), t = o === -1 ? 0 : o; | ||
| this.cursor = this.options[t]?.disabled ? findCursor(t, 1, this.options) : t, this.changeValue(), this.on("cursor", (s) => { | ||
| switch (s) { | ||
@@ -955,3 +957,3 @@ case "left": | ||
| } | ||
| } | ||
| }; | ||
@@ -983,4 +985,4 @@ class u extends V { | ||
| return `${this.userInput}\u2588`; | ||
| const e = t.slice(0, this.cursor), [s, ...r] = t.slice(this.cursor); | ||
| return `${e}${styleText("inverse", s)}${r.join("")}`; | ||
| const r = t.slice(0, this.cursor), s = t.slice(this.cursor, this.cursor + 1), e = t.slice(this.cursor + 1); | ||
| return `${r}${styleText("inverse", s)}${e}`; | ||
| } | ||
@@ -994,4 +996,4 @@ get cursor() { | ||
| initialUserInput: t.initialUserInput ?? t.initialValue | ||
| }), this.on("userInput", (e) => { | ||
| this._setValue(e); | ||
| }), this.on("userInput", (r) => { | ||
| this._setValue(r); | ||
| }), this.on("finalize", () => { | ||
@@ -1003,2 +1005,2 @@ this.value || (this.value = t.defaultValue), this.value === void 0 && (this.value = ""); | ||
| export { T$1 as AutocompletePrompt, r as ConfirmPrompt, U as DatePrompt, u$1 as GroupMultiSelectPrompt, h as MultiLinePrompt, a$1 as MultiSelectPrompt, o as PasswordPrompt, V as Prompt, u as SelectKeyPrompt, a as SelectPrompt, n as TextPrompt, block, getColumns, getRows, isCancel, runValidation, settings, updateSettings, wrapTextWithPrefix }; | ||
| export { T$1 as AutocompletePrompt, r as ConfirmPrompt, U as DatePrompt, u$2 as GroupMultiSelectPrompt, h as MultiLinePrompt, a as MultiSelectPrompt, u$1 as PasswordPrompt, V as Prompt, u as SelectKeyPrompt, n$1 as SelectPrompt, n as TextPrompt, block, getColumns, getRows, isCancel, runValidation, settings, updateSettings, wrapTextWithPrefix }; |
+1
-1
| MIT License | ||
| Copyright (c) Nate Moore | ||
| MIT License Copyright (c) 2025-Present [Bombshell contributors](https://bomb.sh/team) | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
+1
-1
| { | ||
| "name": "@clack/core", | ||
| "version": "1.4.2", | ||
| "version": "1.4.3", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.mjs", |
65914
0.9%972
0.21%