toolcraft-openapi 0.0.171 → 0.0.173
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.
- package/dist/composition.json +2 -2
- package/node_modules/toolcraft-design/dist/explorer/detail-content.d.ts +6 -0
- package/node_modules/toolcraft-design/dist/explorer/detail-content.js +32 -0
- package/node_modules/toolcraft-design/dist/explorer/layout.d.ts +1 -0
- package/node_modules/toolcraft-design/dist/explorer/layout.js +8 -0
- package/node_modules/toolcraft-design/dist/explorer/reducer.js +8 -19
- package/node_modules/toolcraft-design/dist/explorer/render/detail.d.ts +1 -1
- package/node_modules/toolcraft-design/dist/explorer/render/detail.js +8 -36
- package/node_modules/toolcraft-design/dist/explorer/render/pane.d.ts +1 -1
- package/node_modules/toolcraft-design/dist/explorer/render/pane.js +1 -8
- package/node_modules/toolcraft-schema/package.json +1 -1
- package/package.json +3 -3
package/dist/composition.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ansiToCells } from "../screen/ansi-text.js";
|
|
2
|
+
import { renderMarkdown } from "../terminal-markdown/index.js";
|
|
3
|
+
const markdownCache = new Map();
|
|
4
|
+
export function prepareDetailContent(content, width) {
|
|
5
|
+
if (content.trim().length === 0) {
|
|
6
|
+
return { text: "", lines: [[]] };
|
|
7
|
+
}
|
|
8
|
+
width = Math.max(1, width);
|
|
9
|
+
const key = `${contentHash(content)}:${width}`;
|
|
10
|
+
const cached = markdownCache.get(key);
|
|
11
|
+
if (cached !== undefined)
|
|
12
|
+
return cached;
|
|
13
|
+
const text = renderMarkdown(content, { width }).trimEnd();
|
|
14
|
+
const lines = [[]];
|
|
15
|
+
for (const cell of ansiToCells(text)) {
|
|
16
|
+
if (cell.ch === "\n")
|
|
17
|
+
lines.push([]);
|
|
18
|
+
else
|
|
19
|
+
lines.at(-1).push(cell);
|
|
20
|
+
}
|
|
21
|
+
const prepared = { text, lines };
|
|
22
|
+
markdownCache.set(key, prepared);
|
|
23
|
+
return prepared;
|
|
24
|
+
}
|
|
25
|
+
function contentHash(content) {
|
|
26
|
+
let hash = 2166136261;
|
|
27
|
+
for (let index = 0; index < content.length; index += 1) {
|
|
28
|
+
hash ^= content.charCodeAt(index);
|
|
29
|
+
hash = Math.imul(hash, 16777619);
|
|
30
|
+
}
|
|
31
|
+
return hash >>> 0;
|
|
32
|
+
}
|
|
@@ -62,6 +62,14 @@ export function computeExplorerLayout(opts) {
|
|
|
62
62
|
footer
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
+
export function paneBodyRect(rect) {
|
|
66
|
+
return {
|
|
67
|
+
x: rect.x + 2,
|
|
68
|
+
y: rect.y + 1,
|
|
69
|
+
width: Math.max(0, rect.width - 4),
|
|
70
|
+
height: Math.max(0, rect.height - 2)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
65
73
|
function resolveMode(cols, rows) {
|
|
66
74
|
if (cols < 60 || rows < 8) {
|
|
67
75
|
return "too-narrow";
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { graphemes } from "../dashboard/terminal-width.js";
|
|
2
2
|
import { buildActionContext, resolveAction } from "./actions.js";
|
|
3
|
+
import { prepareDetailContent } from "./detail-content.js";
|
|
3
4
|
import { filterRows } from "./filter.js";
|
|
5
|
+
import { computeExplorerLayout, paneBodyRect } from "./layout.js";
|
|
4
6
|
import { REGION_ALL, REGION_DETAIL, REGION_FOOTER, REGION_HEADER, REGION_LIST, REGION_MODAL, resolveExplorerLayoutMode } from "./state.js";
|
|
5
7
|
const NO_EFFECTS = [];
|
|
6
8
|
const DEFAULT_ACTION_HANDLES = {
|
|
@@ -640,31 +642,18 @@ function maxDetailScroll(state) {
|
|
|
640
642
|
return 0;
|
|
641
643
|
}
|
|
642
644
|
if (items.length === 1 && items[0]?.title === undefined) {
|
|
643
|
-
const
|
|
644
|
-
|
|
645
|
+
const body = paneBodyRect(computeExplorerLayout({ ...state.size, focused: state.focused }).detail);
|
|
646
|
+
const content = items[0]?.renderedContent;
|
|
647
|
+
if (body.width <= 0 || body.height <= 0 || content === undefined) {
|
|
645
648
|
return 0;
|
|
646
649
|
}
|
|
647
|
-
return Math.max(0,
|
|
650
|
+
return Math.max(0, prepareDetailContent(content, body.width).lines.length - body.height);
|
|
648
651
|
}
|
|
649
652
|
return Math.max(0, items.length - 1);
|
|
650
653
|
}
|
|
651
|
-
function detailContentLineCount(item) {
|
|
652
|
-
return (item.renderedContent ?? "").split("\n").length;
|
|
653
|
-
}
|
|
654
654
|
function detailBodyHeight(state) {
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
}
|
|
658
|
-
const rows = normalizeSize(state.size.rows);
|
|
659
|
-
const footerHeight = rows > 0 ? Math.min(1, rows) : 0;
|
|
660
|
-
const headerHeight = Math.min(3, Math.max(0, rows - footerHeight));
|
|
661
|
-
const contentHeight = Math.max(0, rows - headerHeight - footerHeight);
|
|
662
|
-
if (state.layout === "narrow-vertical") {
|
|
663
|
-
const listHeight = Math.ceil(contentHeight / 2);
|
|
664
|
-
const detailHeight = contentHeight - listHeight;
|
|
665
|
-
return Math.max(0, detailHeight - 2);
|
|
666
|
-
}
|
|
667
|
-
return Math.max(0, contentHeight - 2);
|
|
655
|
+
const body = paneBodyRect(computeExplorerLayout({ ...state.size, focused: state.focused }).detail);
|
|
656
|
+
return body.width > 0 ? body.height : 0;
|
|
668
657
|
}
|
|
669
658
|
function extendSelection(state, delta) {
|
|
670
659
|
if (!state.multiSelect) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { ScreenSurface as ScreenBuffer } from "../../screen/screen.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type ExplorerLayout } from "../layout.js";
|
|
3
3
|
import type { ExplorerState } from "../state.js";
|
|
4
4
|
export declare function renderDetail(state: ExplorerState, screen: ScreenBuffer, layout: ExplorerLayout): void;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { prepareDetailContent } from "../detail-content.js";
|
|
2
|
+
import { paneBodyRect } from "../layout.js";
|
|
3
3
|
import { getExplorerStyles } from "../theme.js";
|
|
4
|
-
import { drawPaneFrame
|
|
4
|
+
import { drawPaneFrame } from "./pane.js";
|
|
5
5
|
import { fitToWidth } from "./text.js";
|
|
6
|
-
const markdownCache = new Map();
|
|
7
6
|
export function renderDetail(state, screen, layout) {
|
|
8
7
|
const rect = layout.detail;
|
|
9
8
|
const styles = getExplorerStyles();
|
|
@@ -32,7 +31,8 @@ function renderDetailBody(state, screen, rect, row) {
|
|
|
32
31
|
return { start: 0, max: 0 };
|
|
33
32
|
}
|
|
34
33
|
if (items.length === 1 && items[0]?.title === undefined) {
|
|
35
|
-
|
|
34
|
+
const content = prepareDetailContent(renderItem(items[0], rect, row), rect.width);
|
|
35
|
+
return renderBlob(screen, rect, content.lines, state.detail.scroll);
|
|
36
36
|
}
|
|
37
37
|
return renderListMode(state, screen, rect, items, row);
|
|
38
38
|
}
|
|
@@ -54,7 +54,8 @@ function renderListMode(state, screen, rect, items, row) {
|
|
|
54
54
|
writeLine(screen, rect, y, ` ${item.subtitle}`, styles.muted);
|
|
55
55
|
y += 1;
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
const content = prepareDetailContent(renderItem(item, rect, row), rect.width);
|
|
58
|
+
for (const line of content.text.split("\n")) {
|
|
58
59
|
if (y >= rect.height) {
|
|
59
60
|
break;
|
|
60
61
|
}
|
|
@@ -67,14 +68,7 @@ function renderListMode(state, screen, rect, items, row) {
|
|
|
67
68
|
}
|
|
68
69
|
return { start, max };
|
|
69
70
|
}
|
|
70
|
-
function renderBlob(screen, rect,
|
|
71
|
-
const allLines = [[]];
|
|
72
|
-
for (const cell of ansiToCells(text)) {
|
|
73
|
-
if (cell.ch === "\n")
|
|
74
|
-
allLines.push([]);
|
|
75
|
-
else
|
|
76
|
-
allLines.at(-1).push(cell);
|
|
77
|
-
}
|
|
71
|
+
function renderBlob(screen, rect, allLines, scroll) {
|
|
78
72
|
const max = Math.max(0, allLines.length - rect.height);
|
|
79
73
|
const start = clamp(scroll, 0, max);
|
|
80
74
|
const lines = allLines.slice(start);
|
|
@@ -89,20 +83,6 @@ function renderBlob(screen, rect, text, scroll) {
|
|
|
89
83
|
}
|
|
90
84
|
return { start, max };
|
|
91
85
|
}
|
|
92
|
-
function renderItemMarkdown(item, rect, row) {
|
|
93
|
-
const content = renderItem(item, rect, row);
|
|
94
|
-
if (content.trim().length === 0) {
|
|
95
|
-
return "";
|
|
96
|
-
}
|
|
97
|
-
const width = Math.max(1, rect.width);
|
|
98
|
-
const key = `${contentHash(content)}:${width}`;
|
|
99
|
-
const cached = markdownCache.get(key);
|
|
100
|
-
if (cached !== undefined)
|
|
101
|
-
return cached;
|
|
102
|
-
const rendered = renderMarkdown(content, { width }).trimEnd();
|
|
103
|
-
markdownCache.set(key, rendered);
|
|
104
|
-
return rendered;
|
|
105
|
-
}
|
|
106
86
|
function renderItem(item, rect, row) {
|
|
107
87
|
if (item.renderedContent !== undefined) {
|
|
108
88
|
return item.renderedContent;
|
|
@@ -134,11 +114,3 @@ function scrollIndicator(state, start, max) {
|
|
|
134
114
|
return "⠋";
|
|
135
115
|
return `${max === 0 ? 0 : Math.round((start / max) * 100)}%`;
|
|
136
116
|
}
|
|
137
|
-
function contentHash(content) {
|
|
138
|
-
let hash = 2166136261;
|
|
139
|
-
for (let index = 0; index < content.length; index += 1) {
|
|
140
|
-
hash ^= content.charCodeAt(index);
|
|
141
|
-
hash = Math.imul(hash, 16777619);
|
|
142
|
-
}
|
|
143
|
-
return hash >>> 0;
|
|
144
|
-
}
|
|
@@ -23,11 +23,4 @@ export function drawPaneFrame(screen, rect, title, style = {}, options = {}) {
|
|
|
23
23
|
screen.put(rect.x, rect.y + rect.height - 1, `${options.focused ? "┗" : "└"}${horizontal.repeat(innerWidth)}${options.focused ? "┛" : "┘"}`, style);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
export
|
|
27
|
-
return {
|
|
28
|
-
x: rect.x + 2,
|
|
29
|
-
y: rect.y + 1,
|
|
30
|
-
width: Math.max(0, rect.width - 4),
|
|
31
|
-
height: Math.max(0, rect.height - 2)
|
|
32
|
-
};
|
|
33
|
-
}
|
|
26
|
+
export { paneBodyRect } from "../layout.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "toolcraft-openapi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.173",
|
|
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.
|
|
33
|
+
"toolcraft": "0.0.173",
|
|
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.
|
|
48
|
+
"toolcraft-schema": "0.0.173",
|
|
49
49
|
"toolcraft-design": "*",
|
|
50
50
|
"@poe-code/frontmatter": "*"
|
|
51
51
|
},
|