@oclif/table
Advanced tools
Comparing version 0.1.10 to 0.1.11
@@ -1,2 +0,2 @@ | ||
export declare const BORDER_STYLES: readonly ["all", "headers-only-with-outline", "headers-only-with-underline", "headers-only", "horizontal-with-outline", "horizontal", "none", "outline", "vertical-with-outline", "vertical"]; | ||
export declare const BORDER_STYLES: readonly ["all", "headers-only-with-outline", "headers-only-with-underline", "headers-only", "horizontal-with-outline", "horizontal", "none", "outline", "vertical-with-outline", "vertical-rows-with-outline", "vertical"]; | ||
export type BorderStyle = (typeof BORDER_STYLES)[number]; | ||
@@ -3,0 +3,0 @@ type Skeleton = { |
@@ -11,2 +11,3 @@ export const BORDER_STYLES = [ | ||
'vertical-with-outline', | ||
'vertical-rows-with-outline', | ||
'vertical', | ||
@@ -321,2 +322,40 @@ ]; | ||
}, | ||
'vertical-rows-with-outline': { | ||
data: { | ||
cross: '│', | ||
left: '│', | ||
line: ' ', | ||
right: '│', | ||
}, | ||
footer: { | ||
cross: '┴', | ||
left: '└', | ||
line: '─', | ||
right: '┘', | ||
}, | ||
header: { | ||
cross: '─', | ||
left: '┌', | ||
line: '─', | ||
right: '┐', | ||
}, | ||
headerFooter: { | ||
cross: '┬', | ||
left: '├', | ||
line: '─', | ||
right: '┤', | ||
}, | ||
heading: { | ||
cross: ' ', | ||
left: '│', | ||
line: ' ', | ||
right: '│', | ||
}, | ||
separator: { | ||
cross: '', | ||
left: '', | ||
line: '', | ||
right: '', | ||
}, | ||
}, | ||
'vertical-with-outline': { | ||
@@ -323,0 +362,0 @@ data: { |
@@ -85,3 +85,3 @@ /* eslint-disable react/prop-types */ | ||
const spaceForText = width - padding * 2; | ||
if (stripAnsi(valueWithNoZeroWidthChars).length < spaceForText) { | ||
if (stripAnsi(valueWithNoZeroWidthChars).length <= spaceForText) { | ||
const spaces = width - stripAnsi(valueWithNoZeroWidthChars).length; | ||
@@ -96,7 +96,30 @@ return { | ||
const { marginLeft, marginRight } = calculateMargins(width - determineWidthOfWrappedText(stripAnsi(wrappedText))); | ||
const text = wrappedText.replaceAll('\n', `${' '.repeat(marginRight)}\n${' '.repeat(marginLeft)}`); | ||
const lines = wrappedText.split('\n').map((line, idx) => { | ||
const { marginLeft: lineSpecificLeftMargin } = calculateMargins(width - stripAnsi(line).length); | ||
if (horizontalAlignment === 'left') { | ||
if (idx === 0) { | ||
// if it's the first line, only add margin to the right side (The left margin will be applied later) | ||
return `${line}${' '.repeat(marginRight)}`; | ||
} | ||
// if left alignment, add the overall margin to the left side and right sides | ||
return `${' '.repeat(marginLeft)}${line}${' '.repeat(marginRight)}`; | ||
} | ||
if (horizontalAlignment === 'center') { | ||
if (idx === 0) { | ||
// if it's the first line, only add margin to the right side (The left margin will be applied later) | ||
return `${line}${' '.repeat(marginRight)}`; | ||
} | ||
// if center alignment, add line specific margin to the left side and the overall margin to the right side | ||
return `${' '.repeat(lineSpecificLeftMargin)}${line}${' '.repeat(marginRight)}`; | ||
} | ||
// right alignment | ||
if (idx === 0) { | ||
return `${' '.repeat(Math.max(0, lineSpecificLeftMargin - marginLeft))}${line}${' '.repeat(marginRight)}`; | ||
} | ||
return `${' '.repeat(lineSpecificLeftMargin)}${line}${' '.repeat(marginRight)}`; | ||
}); | ||
return { | ||
marginLeft, | ||
marginRight, | ||
text, | ||
text: lines.join('\n'), | ||
}; | ||
@@ -112,3 +135,3 @@ } | ||
export function Table(props) { | ||
const { data, filter, horizontalAlignment = 'left', maxWidth, noStyle = false, orientation = 'horizontal', overflow = 'truncate', padding = 1, sort, title, verticalAlignment = 'top', } = props; | ||
const { data, filter, horizontalAlignment = 'left', maxWidth, noStyle = false, overflow = 'truncate', padding = 1, sort, title, verticalAlignment = 'top', } = props; | ||
const headerOptions = noStyle ? {} : { bold: true, color: 'blue', ...props.headerOptions }; | ||
@@ -171,22 +194,2 @@ const borderStyle = noStyle ? 'none' : (props.borderStyle ?? 'all'); | ||
}); | ||
if (orientation === 'vertical') { | ||
return (React.createElement(Box, { flexDirection: "column", width: determineWidthToUse(columns, config.maxWidth), paddingBottom: 1 }, | ||
title && React.createElement(Text, { ...titleOptions }, title), | ||
processedData.map((row, index) => { | ||
// Calculate the hash of the row based on its value and position | ||
const key = `row-${sha1(row)}-${index}`; | ||
const maxKeyLength = Math.max(...Object.values(headings).map((c) => c.length)); | ||
// Construct a row. | ||
return (React.createElement(Box, { key: key, borderTop: true, borderBottom: false, borderLeft: false, borderRight: false, flexDirection: "column", borderStyle: noStyle ? undefined : 'single', borderColor: borderColor }, columns.map((column) => { | ||
const value = (row[column.column] ?? '').toString(); | ||
const keyName = (headings[column.key] ?? column.key).toString(); | ||
const keyPadding = ' '.repeat(maxKeyLength - keyName.length + padding); | ||
return (React.createElement(Box, { key: `${key}-cell-${column.key}`, flexWrap: "wrap" }, | ||
React.createElement(Text, { ...config.headerOptions }, | ||
keyName, | ||
keyPadding), | ||
React.createElement(Text, { wrap: overflow }, value))); | ||
}))); | ||
}))); | ||
} | ||
return (React.createElement(Box, { flexDirection: "column", width: determineWidthToUse(columns, config.maxWidth) }, | ||
@@ -285,4 +288,4 @@ title && React.createElement(Text, { ...titleOptions }, title), | ||
...table, | ||
// adjust maxWidth to account for margin | ||
maxWidth: determineConfiguredWidth(table.maxWidth, columns), | ||
// adjust maxWidth to account for margin and columnGap | ||
maxWidth: determineConfiguredWidth(table.maxWidth, columns) - (options?.columnGap ?? 0) * tables.length, | ||
})); | ||
@@ -289,0 +292,0 @@ const instance = render(React.createElement(Container, { ...options }, processed.map((table) => (React.createElement(Table, { key: sha1(table), ...table }))))); |
@@ -79,3 +79,3 @@ import { BorderStyle } from './skeletons.js'; | ||
* | ||
* If you provide a number or percentage that is too small to fit the table, it will default to the width of the table. | ||
* If you provide a number or percentage that is too small to fit the table, it will default to the minimum width of the table. | ||
*/ | ||
@@ -92,3 +92,3 @@ maxWidth?: Percentage | number; | ||
/** | ||
* Border style for the table. Defaults to 'all'. Only applies to horizontal orientation. | ||
* Border style for the table. Defaults to 'all'. | ||
*/ | ||
@@ -101,3 +101,3 @@ borderStyle?: BorderStyle; | ||
/** | ||
* Align data in columns. Defaults to 'left'. Only applies to horizontal orientation. | ||
* Align data in columns. Defaults to 'left'. | ||
*/ | ||
@@ -139,23 +139,4 @@ horizontalAlignment?: HorizontalAlignment; | ||
/** | ||
* The orientation of the table. Defaults to 'horizontal'. | ||
* | ||
* If 'vertical', individual records will be displayed vertically in key:value pairs. | ||
* | ||
* @example | ||
* ``` | ||
* ───────────── | ||
* Name Alice | ||
* Id 36329 | ||
* Age 20 | ||
* ───────────── | ||
* Name Bob | ||
* Id 49032 | ||
* Age 21 | ||
* ───────────── | ||
* ``` | ||
* Vertical alignment of cell content. Defaults to 'top'. | ||
*/ | ||
orientation?: 'horizontal' | 'vertical'; | ||
/** | ||
* Vertical alignment of cell content. Defaults to 'top'. Only applies to horizontal orientation. | ||
*/ | ||
verticalAlignment?: VerticalAlignment; | ||
@@ -162,0 +143,0 @@ /** |
{ | ||
"name": "@oclif/table", | ||
"description": "Display table in terminal", | ||
"version": "0.1.10", | ||
"version": "0.1.11", | ||
"author": "Salesforce", | ||
"bugs": "https://github.com/oclif/multi-stage-output/issues", | ||
"bugs": "https://github.com/oclif/table/issues", | ||
"dependencies": { | ||
"@oclif/core": "^4", | ||
"@types/react": "^18.3.10", | ||
"change-case": "^5.4.4", | ||
@@ -23,5 +22,6 @@ "cli-truncate": "^4.0.0", | ||
"@types/chai": "^4.3.16", | ||
"@types/mocha": "^10.0.7", | ||
"@types/mocha": "^10.0.8", | ||
"@types/node": "^18", | ||
"@types/object-hash": "^3.0.6", | ||
"@types/react": "^18.3.10", | ||
"@types/sinon": "^17.0.3", | ||
@@ -56,3 +56,3 @@ "ansis": "^3.3.2", | ||
], | ||
"homepage": "https://github.com/oclif/core", | ||
"homepage": "https://github.com/oclif/table", | ||
"keywords": [ | ||
@@ -67,3 +67,3 @@ "oclif", | ||
}, | ||
"repository": "oclif/core", | ||
"repository": "oclif/table", | ||
"publishConfig": { | ||
@@ -70,0 +70,0 @@ "access": "public" |
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
39859
9
1103
29
- Removed@types/react@^18.3.10
- Removed@types/prop-types@15.7.14(transitive)
- Removed@types/react@18.3.18(transitive)
- Removedcsstype@3.1.3(transitive)