@replit/clui-input
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -100,6 +100,6 @@ "use strict"; | ||
var processUpdates = function () { return __awaiter(void 0, void 0, void 0, function () { | ||
var valueStart, current, ast, atWhitespace, previousNode, search, result, search, result, currentNode, astCommands, last, args, parsedArgKeys, options, nodeStart, commonParams, getOptions, rootCommands, search, ref, argOptions, previousNode, search, ref, argOptions, ref, argOptions, run, commandsList, refRun_1; | ||
var _a, _b, _c, _d, _e; | ||
return __generator(this, function (_f) { | ||
switch (_f.label) { | ||
var valueStart, current, ast, atWhitespace, previousNode, search, result, search, result, currentNode, astCommands, last, args, parsedArgKeys, options, nodeStart, commonParams, getOptions, rootCommands, search, ref, argOptions, previousNode, search, optionsFn, token, prefix_1, suffix, searchValue_1, results, ref, argOptions, ref, argOptions, run, commandsList, refRun_1; | ||
var _a, _b, _c, _d, _e, _f; | ||
return __generator(this, function (_g) { | ||
switch (_g.label) { | ||
case 0: | ||
@@ -114,3 +114,3 @@ valueStart = value.slice(0, index); | ||
case 1: | ||
ast = _f.sent(); | ||
ast = _g.sent(); | ||
atWhitespace = value[index - 1] === ' '; | ||
@@ -125,3 +125,3 @@ if (!(value.length > index || atWhitespace)) return [3, 5]; | ||
case 2: | ||
result = _f.sent(); | ||
result = _g.sent(); | ||
if (result) { | ||
@@ -138,7 +138,7 @@ commandsCache[valueStart] = result; | ||
case 4: | ||
result = _f.sent(); | ||
result = _g.sent(); | ||
if (result) { | ||
commandsCache[valueStart] = result; | ||
} | ||
_f.label = 5; | ||
_g.label = 5; | ||
case 5: | ||
@@ -175,7 +175,7 @@ if (current !== updatedAt) { | ||
case 6: | ||
rootCommands = _f.sent(); | ||
rootCommands = _g.sent(); | ||
if (rootCommands) { | ||
commandsCache[''] = rootCommands; | ||
} | ||
_f.label = 7; | ||
_g.label = 7; | ||
case 7: | ||
@@ -192,3 +192,3 @@ if (current !== updatedAt) { | ||
} | ||
return [3, 16]; | ||
return [3, 18]; | ||
case 8: | ||
@@ -202,3 +202,3 @@ if (!currentNode) return [3, 11]; | ||
case 9: | ||
argOptions = _f.sent(); | ||
argOptions = _g.sent(); | ||
if (argOptions) { | ||
@@ -210,6 +210,6 @@ optionsCache[valueStart] = argOptions; | ||
} | ||
_f.label = 10; | ||
_g.label = 10; | ||
case 10: | ||
options.push.apply(options, __spread(getOptions(__assign({ currentNode: currentNode }, commonParams)))); | ||
return [3, 16]; | ||
return [3, 18]; | ||
case 11: | ||
@@ -226,9 +226,34 @@ previousNode = ast_1.closestPrevious(ast, index); | ||
: undefined; | ||
if (!previousNode) return [3, 16]; | ||
if (!(previousNode.kind === 'ARG_VALUE')) return [3, 13]; | ||
if (!previousNode) return [3, 18]; | ||
if (!('cmdNodeCtx' in previousNode && | ||
typeof ((_d = previousNode.cmdNodeCtx) === null || _d === void 0 ? void 0 : _d.ref.options) === 'function')) return [3, 13]; | ||
optionsFn = previousNode.cmdNodeCtx.ref.options; | ||
token = previousNode.cmdNodeCtx.token; | ||
prefix_1 = ast.source.slice(0, token.end); | ||
suffix = ast.source.slice(token.end); | ||
searchValue_1 = suffix.trimLeft(); | ||
return [4, optionsFn(searchValue_1)]; | ||
case 12: | ||
results = _g.sent(); | ||
if (current !== updatedAt) { | ||
return [2]; | ||
} | ||
options.push.apply(options, __spread(results.map(function (result) { | ||
var inputValue = prefix_1 + " " + result.value; | ||
return { | ||
value: result.value, | ||
inputValue: inputValue, | ||
cursorTarget: inputValue.length, | ||
searchValue: searchValue_1, | ||
data: result, | ||
}; | ||
}))); | ||
_g.label = 13; | ||
case 13: | ||
if (!(previousNode.kind === 'ARG_VALUE')) return [3, 15]; | ||
ref = previousNode.parent.ref; | ||
if (!(typeof ref.options === 'function' && !optionsCache[valueStart])) return [3, 13]; | ||
if (!(typeof ref.options === 'function' && !optionsCache[valueStart])) return [3, 15]; | ||
return [4, ref.options(search || undefined)]; | ||
case 12: | ||
argOptions = _f.sent(); | ||
case 14: | ||
argOptions = _g.sent(); | ||
if (current !== updatedAt) { | ||
@@ -240,10 +265,10 @@ return [2]; | ||
} | ||
_f.label = 13; | ||
case 13: | ||
if (!(previousNode.kind === 'ARG_KEY')) return [3, 15]; | ||
_g.label = 15; | ||
case 15: | ||
if (!(previousNode.kind === 'ARG_KEY')) return [3, 17]; | ||
ref = previousNode.parent.ref; | ||
if (!(typeof ref.options === 'function' && !optionsCache[valueStart])) return [3, 15]; | ||
if (!(typeof ref.options === 'function' && !optionsCache[valueStart])) return [3, 17]; | ||
return [4, ref.options(search || undefined)]; | ||
case 14: | ||
argOptions = _f.sent(); | ||
case 16: | ||
argOptions = _g.sent(); | ||
if (current !== updatedAt) { | ||
@@ -255,7 +280,7 @@ return [2]; | ||
} | ||
_f.label = 15; | ||
case 15: | ||
_g.label = 17; | ||
case 17: | ||
options.push.apply(options, __spread(getOptions(__assign({ previousNode: previousNode }, commonParams)))); | ||
_f.label = 16; | ||
case 16: | ||
_g.label = 18; | ||
case 18: | ||
commandsList = astCommands.map(function (c) { | ||
@@ -283,5 +308,5 @@ var cargs = ast_1.toArgs(c); | ||
ast: ast, | ||
args: (_d = args) === null || _d === void 0 ? void 0 : _d.parsed, | ||
args: (_e = args) === null || _e === void 0 ? void 0 : _e.parsed, | ||
nodeStart: nodeStart, | ||
exhausted: !!((_e = args) === null || _e === void 0 ? void 0 : _e.exhausted) && !last.ref.commands, | ||
exhausted: !!((_f = args) === null || _f === void 0 ? void 0 : _f.exhausted) && !last.ref.commands, | ||
commands: commandsList, | ||
@@ -288,0 +313,0 @@ options: options, |
@@ -47,2 +47,5 @@ export interface IOption<D = any> { | ||
commands?: Thunk<ICommands<ICommand>>; | ||
options?: (search?: string) => Promise<Array<{ | ||
value: string; | ||
}>>; | ||
run?: RunFn<O, R>; | ||
@@ -49,0 +52,0 @@ } |
{ | ||
"name": "@replit/clui-input", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "A utility library for building CLI style interfaces with autocomplete", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93489
1487