toolcraft-openapi 0.0.166 → 0.0.168

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.
@@ -33,12 +33,12 @@
33
33
  },
34
34
  {
35
35
  "name": "toolcraft-openapi",
36
- "version": "0.0.166",
36
+ "version": "0.0.168",
37
37
  "license": "MIT"
38
38
  },
39
39
  {
40
40
  "name": "toolcraft-schema",
41
- "version": "0.0.166",
41
+ "version": "0.0.168",
42
42
  "license": "MIT"
43
43
  },
44
44
  {
@@ -28,17 +28,24 @@ function stripAnsi(value) {
28
28
  return value.replace(/\u001b\[[0-9;]*m/g, "");
29
29
  }
30
30
  function matchSubsequence(query, text) {
31
+ const queryCharacters = Array.from(query);
32
+ const textCharacters = Array.from(text);
31
33
  let previousStates = [];
32
- for (let queryIndex = 0; queryIndex < query.length; queryIndex += 1) {
34
+ for (let queryIndex = 0; queryIndex < queryCharacters.length; queryIndex += 1) {
33
35
  const states = [];
34
- for (let textIndex = 0; textIndex < text.length; textIndex += 1) {
35
- if (text[textIndex] !== query[queryIndex]) {
36
+ let offset = 0;
37
+ for (let textIndex = 0; textIndex < textCharacters.length; textIndex += 1) {
38
+ const character = textCharacters[textIndex];
39
+ const position = offset;
40
+ offset += character.length;
41
+ if (character !== queryCharacters[queryIndex]) {
36
42
  continue;
37
43
  }
44
+ const positions = character.length === 2 ? [position, position + 1] : [position];
38
45
  if (queryIndex === 0) {
39
46
  states[textIndex] = {
40
- score: characterScore(text, textIndex, undefined) + Math.max(0, EARLY_MATCH_BONUS - textIndex),
41
- positions: [textIndex]
47
+ score: characterScore(textCharacters, textIndex, undefined) + Math.max(0, EARLY_MATCH_BONUS - position),
48
+ positions
42
49
  };
43
50
  continue;
44
51
  }
@@ -48,8 +55,8 @@ function matchSubsequence(query, text) {
48
55
  continue;
49
56
  }
50
57
  const next = {
51
- score: previous.score + characterScore(text, textIndex, previousIndex),
52
- positions: [...previous.positions, textIndex]
58
+ score: previous.score + characterScore(textCharacters, textIndex, previousIndex),
59
+ positions: [...previous.positions, ...positions]
53
60
  };
54
61
  if (isBetterMatch(next, states[textIndex])) {
55
62
  states[textIndex] = next;
@@ -1,3 +1,4 @@
1
+ import { graphemes } from "../dashboard/terminal-width.js";
1
2
  import { buildActionContext, resolveAction } from "./actions.js";
2
3
  import { filterRows } from "./filter.js";
3
4
  import { REGION_ALL, REGION_DETAIL, REGION_FOOTER, REGION_HEADER, REGION_LIST, REGION_MODAL, resolveExplorerLayoutMode } from "./state.js";
@@ -47,6 +48,10 @@ export function step(state, event, runtimeHandles = DEFAULT_ACTION_HANDLES) {
47
48
  }
48
49
  function stepKey(state, key, runtimeHandles) {
49
50
  const target = state.bindings.resolve(key);
51
+ if (target?.type === "builtin" && target.id === "quit") {
52
+ const next = state.modal === null ? state : modalDismissed(state, null, runtimeHandles).state;
53
+ return { state: markDirty(next, 0), effects: [{ type: "exit", result: null }] };
54
+ }
50
55
  if (state.modal !== null) {
51
56
  return stepModalKey(state, key, target, runtimeHandles);
52
57
  }
@@ -66,8 +71,6 @@ function stepKey(state, key, runtimeHandles) {
66
71
  }
67
72
  if (target?.type === "builtin") {
68
73
  switch (target.id) {
69
- case "quit":
70
- return { state: markDirty(state, 0), effects: [{ type: "exit", result: null }] };
71
74
  case "filter":
72
75
  return focusFilter(state);
73
76
  case "help":
@@ -126,8 +129,8 @@ function stepKey(state, key, runtimeHandles) {
126
129
  }
127
130
  if (isBackspace(key)) {
128
131
  if (isSecondListFocused(state))
129
- return updateDetailFilter(state, (state.detail.filter ?? "").slice(0, -1));
130
- return updateFilter(state, state.filter.slice(0, -1));
132
+ return updateDetailFilter(state, graphemes(state.detail.filter ?? "").slice(0, -1).join(""));
133
+ return updateFilter(state, graphemes(state.filter).slice(0, -1).join(""));
131
134
  }
132
135
  if (!state.multiSelect && isSelectionSpace(key)) {
133
136
  return mark(state, 0);
@@ -150,7 +153,7 @@ function stepFilterKey(state, key, target, runtimeHandles) {
150
153
  };
151
154
  }
152
155
  if (isBackspace(key)) {
153
- return updateFilter(state, state.filter.slice(0, -1));
156
+ return updateFilter(state, graphemes(state.filter).slice(0, -1).join(""));
154
157
  }
155
158
  if (isPrintable(key)) {
156
159
  return updateFilter(state, `${state.filter}${key.ch}`);
@@ -166,7 +169,7 @@ function stepModalKey(state, key, target, runtimeHandles) {
166
169
  return modalDismissed(state, state.modal.value, runtimeHandles);
167
170
  }
168
171
  if (isBackspace(key)) {
169
- return setModal(state, { ...state.modal, value: state.modal.value.slice(0, -1) });
172
+ return setModal(state, { ...state.modal, value: graphemes(state.modal.value).slice(0, -1).join("") });
170
173
  }
171
174
  if (isPrintable(key)) {
172
175
  return setModal(state, { ...state.modal, value: `${state.modal.value}${key.ch}` });
@@ -726,7 +729,7 @@ function paletteInput(state, key) {
726
729
  return mark(state, 0);
727
730
  }
728
731
  if (isBackspace(key)) {
729
- return setPaletteQuery(state, state.modal.query.slice(0, -1));
732
+ return setPaletteQuery(state, graphemes(state.modal.query).slice(0, -1).join(""));
730
733
  }
731
734
  if (isPrintable(key)) {
732
735
  return setPaletteQuery(state, `${state.modal.query}${key.ch}`);
@@ -73,7 +73,19 @@ export class Prompt extends EventEmitter {
73
73
  return Promise.resolve(CANCEL);
74
74
  }
75
75
  if (this.input.isTTY !== true) {
76
- return this.promptNonTty();
76
+ return this.promptNonTty().then((value) => {
77
+ if (value === CANCEL || !this.trackValue) {
78
+ return value;
79
+ }
80
+ this.setValue(value);
81
+ const error = this.validate?.(this.value);
82
+ if (error) {
83
+ throw error instanceof Error ? error : new Error(error);
84
+ }
85
+ this.state = "submit";
86
+ this.emit("finalize");
87
+ return this.value;
88
+ });
77
89
  }
78
90
  if (this.input.destroyed || this.input.readableEnded) {
79
91
  this.state = "cancel";
@@ -116,7 +128,7 @@ export class Prompt extends EventEmitter {
116
128
  this.state = "cancel";
117
129
  return Promise.resolve(CANCEL);
118
130
  }
119
- return new Promise((resolve) => {
131
+ return new Promise((resolve, reject) => {
120
132
  let rl = null;
121
133
  let settled = false;
122
134
  const settle = (value) => {
@@ -126,21 +138,31 @@ export class Prompt extends EventEmitter {
126
138
  settled = true;
127
139
  this.input.removeListener("close", onCancel);
128
140
  this.signal?.removeEventListener("abort", onCancel);
141
+ rl?.removeListener("error", settle);
142
+ rl?.removeListener("line", settle);
143
+ rl?.removeListener("close", onClose);
129
144
  rl?.close();
130
- resolve(value);
145
+ if (value instanceof Error) {
146
+ reject(value);
147
+ }
148
+ else {
149
+ resolve(value);
150
+ }
131
151
  };
132
152
  const onCancel = () => {
133
153
  this.state = "cancel";
134
154
  settle(CANCEL);
135
155
  };
156
+ const onClose = () => settle(rl?.line ?? "");
136
157
  this.input.once("close", onCancel);
137
158
  rl = readline.createInterface({ input: this.input, terminal: false });
138
159
  if (settled) {
139
160
  rl.close();
140
161
  return;
141
162
  }
163
+ rl.once("error", settle);
142
164
  rl.once("line", settle);
143
- rl.once("close", () => settle(rl?.line ?? ""));
165
+ rl.once("close", onClose);
144
166
  this.signal?.addEventListener("abort", onCancel, { once: true });
145
167
  if (this.signal?.aborted) {
146
168
  onCancel();
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-schema",
3
- "version": "0.0.166",
3
+ "version": "0.0.168",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-openapi",
3
- "version": "0.0.166",
3
+ "version": "0.0.168",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "toolcraft-openapi-generate": "dist/bin/generate.js"
31
31
  },
32
32
  "dependencies": {
33
- "toolcraft": "0.0.166",
33
+ "toolcraft": "0.0.168",
34
34
  "fast-string-width": "^3.0.2",
35
35
  "fast-wrap-ansi": "^0.2.0",
36
36
  "sisteransi": "^1.0.5",
@@ -45,7 +45,7 @@
45
45
  "directory": "packages/toolcraft-openapi"
46
46
  },
47
47
  "optionalDependencies": {
48
- "toolcraft-schema": "0.0.166",
48
+ "toolcraft-schema": "0.0.168",
49
49
  "toolcraft-design": "*",
50
50
  "@poe-code/frontmatter": "*"
51
51
  },