toolcraft-openapi 0.0.170 → 0.0.171

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.170",
36
+ "version": "0.0.171",
37
37
  "license": "MIT"
38
38
  },
39
39
  {
40
40
  "name": "toolcraft-schema",
41
- "version": "0.0.170",
41
+ "version": "0.0.171",
42
42
  "license": "MIT"
43
43
  },
44
44
  {
@@ -652,7 +652,7 @@ function detailContentLineCount(item) {
652
652
  return (item.renderedContent ?? "").split("\n").length;
653
653
  }
654
654
  function detailBodyHeight(state) {
655
- if (state.layout === "too-narrow" || state.layout === "narrow-list-only") {
655
+ if (state.layout === "too-narrow" || (state.layout === "narrow-list-only" && state.focused !== "detail")) {
656
656
  return 0;
657
657
  }
658
658
  const rows = normalizeSize(state.size.rows);
@@ -14,38 +14,33 @@ export function renderDetail(state, screen, layout) {
14
14
  const row = state.rows.find((r) => r.id === state.detail.rowId) ?? null;
15
15
  const pane = state.paneDefinitions[1];
16
16
  const title = pane?.titleForRow?.(row ?? undefined) ?? pane?.title ?? "Preview";
17
- if (layout.mode === "narrow-vertical") {
18
- drawPaneFrame(screen, rect, title, state.focused === "detail" ? styles.borderFocused : styles.border, { focused: state.focused === "detail", indicator: scrollIndicator(state) });
19
- renderDetailBody(state, screen, paneBodyRect(rect), row);
20
- return;
21
- }
22
- drawPaneFrame(screen, rect, title, state.focused === "detail" ? styles.borderFocused : styles.border, { focused: state.focused === "detail", indicator: scrollIndicator(state) });
23
- renderDetailBody(state, screen, paneBodyRect(rect), row);
17
+ const { start, max } = renderDetailBody(state, screen, paneBodyRect(rect), row);
18
+ drawPaneFrame(screen, rect, title, state.focused === "detail" ? styles.borderFocused : styles.border, { focused: state.focused === "detail", indicator: scrollIndicator(state, start, max) });
24
19
  }
25
20
  function renderDetailBody(state, screen, rect, row) {
26
21
  const styles = getExplorerStyles();
27
22
  const items = state.detail.items;
28
23
  if (rect.width <= 0 || rect.height <= 0) {
29
- return;
24
+ return { start: 0, max: 0 };
30
25
  }
31
26
  if (items === null) {
32
27
  writeLine(screen, rect, 0, row === null ? state.emptyHint : "Loading detail...", styles.muted);
33
- return;
28
+ return { start: 0, max: 0 };
34
29
  }
35
30
  if (items.length === 0) {
36
31
  writeLine(screen, rect, 0, state.emptyHint, styles.muted);
37
- return;
32
+ return { start: 0, max: 0 };
38
33
  }
39
34
  if (items.length === 1 && items[0]?.title === undefined) {
40
- renderBlob(screen, rect, renderItemMarkdown(items[0], rect, row), state.detail.scroll);
41
- return;
35
+ return renderBlob(screen, rect, renderItemMarkdown(items[0], rect, row), state.detail.scroll);
42
36
  }
43
- renderListMode(state, screen, rect, items, row);
37
+ return renderListMode(state, screen, rect, items, row);
44
38
  }
45
39
  function renderListMode(state, screen, rect, items, row) {
46
40
  const styles = getExplorerStyles();
47
41
  let y = 0;
48
- const start = clamp(state.detail.scroll, 0, Math.max(0, items.length - 1));
42
+ const max = Math.max(0, items.length - 1);
43
+ const start = clamp(state.detail.scroll, 0, max);
49
44
  for (let index = start; index < items.length && y < rect.height; index += 1) {
50
45
  const item = items[index];
51
46
  const cursor = index === state.detail.cursor;
@@ -70,6 +65,7 @@ function renderListMode(state, screen, rect, items, row) {
70
65
  y += 1;
71
66
  }
72
67
  }
68
+ return { start, max };
73
69
  }
74
70
  function renderBlob(screen, rect, text, scroll) {
75
71
  const allLines = [[]];
@@ -79,7 +75,8 @@ function renderBlob(screen, rect, text, scroll) {
79
75
  else
80
76
  allLines.at(-1).push(cell);
81
77
  }
82
- const start = clamp(scroll, 0, Math.max(0, allLines.length - rect.height));
78
+ const max = Math.max(0, allLines.length - rect.height);
79
+ const start = clamp(scroll, 0, max);
83
80
  const lines = allLines.slice(start);
84
81
  for (let row = 0; row < rect.height; row += 1) {
85
82
  let x = rect.x;
@@ -90,6 +87,7 @@ function renderBlob(screen, rect, text, scroll) {
90
87
  x += cell.width;
91
88
  }
92
89
  }
90
+ return { start, max };
93
91
  }
94
92
  function renderItemMarkdown(item, rect, row) {
95
93
  const content = renderItem(item, rect, row);
@@ -131,12 +129,10 @@ function writeLine(screen, rect, row, text, style = {}) {
131
129
  function clamp(value, min, max) {
132
130
  return Math.min(max, Math.max(min, value));
133
131
  }
134
- function scrollIndicator(state) {
132
+ function scrollIndicator(state, start, max) {
135
133
  if (state.detail.loading)
136
134
  return "⠋";
137
- const content = state.detail.items?.[state.detail.cursor]?.renderedContent ?? "";
138
- const total = Math.max(1, content.split("\n").length);
139
- return `${Math.min(100, Math.round((state.detail.scroll / Math.max(1, total - 1)) * 100))}%`;
135
+ return `${max === 0 ? 0 : Math.round((start / max) * 100)}%`;
140
136
  }
141
137
  function contentHash(content) {
142
138
  let hash = 2166136261;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "toolcraft-schema",
3
- "version": "0.0.170",
3
+ "version": "0.0.171",
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.170",
3
+ "version": "0.0.171",
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.170",
33
+ "toolcraft": "0.0.171",
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.170",
48
+ "toolcraft-schema": "0.0.171",
49
49
  "toolcraft-design": "*",
50
50
  "@poe-code/frontmatter": "*"
51
51
  },