@antv/s2-react
Advanced tools
@@ -9,3 +9,3 @@ import { getIcon, S2_PREFIX_CLS } from '@antv/s2'; | ||
// fix: Uncaught TypeError: Cannot assign to read only property 'width' of object '#<Object>' | ||
const newStyle = { ...style }; | ||
const newStyle = Object.assign({}, style); | ||
/* | ||
@@ -12,0 +12,0 @@ * html-icon 和 gui-icon 的接口趋于一致,都有 width 和 height 的便携属性 |
@@ -12,3 +12,3 @@ import { S2_PREFIX_CLS } from '@antv/s2'; | ||
if (React.isValidElement(content)) { | ||
return (React.createElement("span", { ...commonProps }, | ||
return (React.createElement("span", Object.assign({}, commonProps), | ||
React.createElement(React.Fragment, null, content))); | ||
@@ -18,6 +18,6 @@ } | ||
const htmlNode = typeof content !== 'string' | ||
? content?.innerHTML | ||
? content === null || content === void 0 ? void 0 : content.innerHTML | ||
: content; | ||
return (React.createElement("span", { ...commonProps, dangerouslySetInnerHTML: { __html: htmlNode } })); | ||
return (React.createElement("span", Object.assign({}, commonProps, { dangerouslySetInnerHTML: { __html: htmlNode } }))); | ||
}; | ||
//# sourceMappingURL=react-element.js.map |
@@ -0,1 +1,2 @@ | ||
import { __rest } from "tslib"; | ||
import { customMerge } from '@antv/s2'; | ||
@@ -6,3 +7,3 @@ import { ChartDataCell } from '@antv/s2/extends'; | ||
export const ChartSheet = React.memo((props) => { | ||
const { options: defaultOptions, themeCfg: defaultThemeCfg, ...restProps } = props; | ||
const { options: defaultOptions, themeCfg: defaultThemeCfg } = props, restProps = __rest(props, ["options", "themeCfg"]); | ||
const s2Options = React.useMemo(() => { | ||
@@ -55,5 +56,5 @@ const options = { | ||
}, [defaultThemeCfg]); | ||
return React.createElement(BaseSheet, { ...restProps, options: s2Options, themeCfg: themeCfg }); | ||
return React.createElement(BaseSheet, Object.assign({}, restProps, { options: s2Options, themeCfg: themeCfg })); | ||
}); | ||
ChartSheet.displayName = 'ChartSheet'; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
import { __awaiter } from "tslib"; | ||
import { S2Event, S2_PREFIX_CLS, customMerge, } from '@antv/s2'; | ||
@@ -13,3 +14,4 @@ import { isNil, pick } from 'lodash'; | ||
const { left, top, width, height } = React.useMemo(() => { | ||
const rect = s2.getCanvasElement()?.getBoundingClientRect(); | ||
var _a; | ||
const rect = (_a = s2.getCanvasElement()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect(); | ||
return { | ||
@@ -24,3 +26,3 @@ left: window.scrollX + rect.left, | ||
const scroll = s2.facet.getScrollOffset(); | ||
const cellMeta = pick(cell?.getMeta(), ['x', 'y', 'width', 'height']); | ||
const cellMeta = pick(cell === null || cell === void 0 ? void 0 : cell.getMeta(), ['x', 'y', 'width', 'height']); | ||
if (isNil(cellMeta.x) || isNil(cellMeta.y)) { | ||
@@ -35,3 +37,3 @@ return { | ||
const sampleColNode = s2.facet.getColNodes()[0]; | ||
const sampleColNodeHeight = sampleColNode?.height || 0; | ||
const sampleColNodeHeight = (sampleColNode === null || sampleColNode === void 0 ? void 0 : sampleColNode.height) || 0; | ||
cellMeta.x -= scroll.scrollX || 0; | ||
@@ -44,3 +46,4 @@ cellMeta.y -= (scroll.scrollY || 0) - sampleColNodeHeight; | ||
const containerRef = React.useRef(null); | ||
const onSave = async () => { | ||
const onSave = () => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
const { rowIndex, valueField, id } = cell.getMeta(); | ||
@@ -50,4 +53,4 @@ const displayData = s2.dataSet.getDisplayDataSet(); | ||
// 编辑后的值作为格式化后的结果, formatter 不再触发, 避免二次格式化 | ||
s2.dataSet.displayFormattedValueMap?.set(id, inputVal); | ||
await s2.render(); | ||
(_a = s2.dataSet.displayFormattedValueMap) === null || _a === void 0 ? void 0 : _a.set(id, inputVal); | ||
yield s2.render(); | ||
const editedMeta = customMerge(cell.getMeta(), { | ||
@@ -59,5 +62,5 @@ fieldValue: inputVal, | ||
}); | ||
onDataCellEditEnd?.(editedMeta, cell); | ||
onDataCellEditEnd === null || onDataCellEditEnd === void 0 ? void 0 : onDataCellEditEnd(editedMeta, cell); | ||
resolver(true); | ||
}; | ||
}); | ||
const onKeyDown = (e) => { | ||
@@ -90,8 +93,9 @@ if (e.key === 'Enter') { | ||
React.useEffect(() => { | ||
onDataCellEditStart?.(cell.getMeta(), cell); | ||
onDataCellEditStart === null || onDataCellEditStart === void 0 ? void 0 : onDataCellEditStart(cell.getMeta(), cell); | ||
setTimeout(() => { | ||
var _a, _b; | ||
// 防止触发表格全选 | ||
containerRef.current?.click(); | ||
(_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.click(); | ||
// 开启 preventScroll, 防止页面有滚动条时触发滚动 | ||
inputRef.current?.focus({ preventScroll: true }); | ||
(_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus({ preventScroll: true }); | ||
}); | ||
@@ -98,0 +102,0 @@ }, []); |
@@ -0,1 +1,2 @@ | ||
import { __awaiter } from "tslib"; | ||
import { FrozenGroupArea, InteractionStateName, S2Event, S2_PREFIX_CLS, } from '@antv/s2'; | ||
@@ -21,7 +22,7 @@ import { get, pick, throttle } from 'lodash'; | ||
const sampleColNode = s2.facet.getColNodes()[0]; | ||
const sampleColNodeHeight = sampleColNode?.height || 0; | ||
const sampleColNodeHeight = (sampleColNode === null || sampleColNode === void 0 ? void 0 : sampleColNode.height) || 0; | ||
// 点位偏移 | ||
const pointX = point.x; | ||
const pointY = point.y; | ||
const scrollOffsetY = scrollOffset?.scrollY - sampleColNodeHeight; | ||
const scrollOffsetY = (scrollOffset === null || scrollOffset === void 0 ? void 0 : scrollOffset.scrollY) - sampleColNodeHeight; | ||
const cellMaxX = cellMeta.x - scrollOffset.scrollX + cellMeta.width + 4; | ||
@@ -57,3 +58,3 @@ const cellMinX = cellMeta.x - scrollOffset.scrollX; | ||
const startCellMeta = startCell.getMeta(); | ||
const endCellMeta = endCell?.getMeta(); | ||
const endCellMeta = endCell === null || endCell === void 0 ? void 0 : endCell.getMeta(); | ||
const minX = Math.min(startCellMeta.colIndex, endCellMeta.colIndex); | ||
@@ -100,3 +101,3 @@ const maxX = Math.max(startCellMeta.colIndex, endCellMeta.colIndex); | ||
}, 10); | ||
const dragMouseUp = async (event) => { | ||
const dragMouseUp = (event) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (!startCell) { | ||
@@ -124,3 +125,3 @@ return; | ||
}); | ||
await s2.render(true); | ||
yield s2.render(true); | ||
setMaskPosition({ right: 0, bottom: 0 }); | ||
@@ -130,4 +131,4 @@ s2.off(S2Event.GLOBAL_MOUSE_MOVE, dragMove); | ||
setStartCell(undefined); | ||
onCopyFinished?.(); | ||
}; | ||
onCopyFinished === null || onCopyFinished === void 0 ? void 0 : onCopyFinished(); | ||
}); | ||
useEffect(() => { | ||
@@ -156,3 +157,3 @@ if (startCell) { | ||
return () => { | ||
pointElement?.removeEventListener('mousedown', dragMouseDown); | ||
pointElement === null || pointElement === void 0 ? void 0 : pointElement.removeEventListener('mousedown', dragMouseDown); | ||
}; | ||
@@ -159,0 +160,0 @@ }, [s2]); |
@@ -24,3 +24,3 @@ import { FrozenGroupArea, S2Event, S2_PREFIX_CLS, } from '@antv/s2'; | ||
const rect = spreadsheet.getCanvasElement().getBoundingClientRect(); | ||
const cellMeta = cell?.getMeta(); | ||
const cellMeta = cell === null || cell === void 0 ? void 0 : cell.getMeta(); | ||
if (!isEqual(newScroll, scroll)) { | ||
@@ -50,7 +50,3 @@ // 超出可视区域隐藏point | ||
} | ||
setScroll({ | ||
...newScroll, | ||
overflow, | ||
width: 8 - (pointWidth > 0 ? pointWidth : 0), | ||
}); | ||
setScroll(Object.assign(Object.assign({}, newScroll), { overflow, width: 8 - (pointWidth > 0 ? pointWidth : 0) })); | ||
} | ||
@@ -81,3 +77,3 @@ else { | ||
return () => { | ||
spreadsheet?.off(S2Event.GLOBAL_SCROLL, handleScroll); | ||
spreadsheet === null || spreadsheet === void 0 ? void 0 : spreadsheet.off(S2Event.GLOBAL_SCROLL, handleScroll); | ||
}; | ||
@@ -90,5 +86,5 @@ }, [cell]); | ||
} | ||
}, [spreadsheet?.dataSet.sortParams, spreadsheet?.dataSet.filterParams]); | ||
}, [spreadsheet === null || spreadsheet === void 0 ? void 0 : spreadsheet.dataSet.sortParams, spreadsheet === null || spreadsheet === void 0 ? void 0 : spreadsheet.dataSet.filterParams]); | ||
React.useEffect(() => { | ||
if (!spreadsheet?.getCanvasElement()) { | ||
if (!(spreadsheet === null || spreadsheet === void 0 ? void 0 : spreadsheet.getCanvasElement())) { | ||
return; | ||
@@ -98,3 +94,3 @@ } | ||
const sampleColNode = spreadsheet.facet.getColNodes()[0]; | ||
const sampleColNodeHeight = sampleColNode?.height || 0; | ||
const sampleColNodeHeight = (sampleColNode === null || sampleColNode === void 0 ? void 0 : sampleColNode.height) || 0; | ||
const cellMeta = pick(cell.getMeta(), [ | ||
@@ -107,4 +103,4 @@ 'x', | ||
]); | ||
cellMeta.x -= scroll?.scrollX; | ||
cellMeta.y -= scroll?.scrollY - sampleColNodeHeight; | ||
cellMeta.x -= scroll === null || scroll === void 0 ? void 0 : scroll.scrollX; | ||
cellMeta.y -= (scroll === null || scroll === void 0 ? void 0 : scroll.scrollY) - sampleColNodeHeight; | ||
setPosition({ | ||
@@ -111,0 +107,0 @@ left: cellMeta.x + cellMeta.width - 4, |
@@ -6,3 +6,3 @@ import React from 'react'; | ||
export const EditableSheet = React.memo((props) => { | ||
return (React.createElement(BaseSheet, { ...props, sheetType: 'table' }, | ||
return (React.createElement(BaseSheet, Object.assign({}, props, { sheetType: 'table' }), | ||
React.createElement(EditCell, { onDataCellEditStart: props.onDataCellEditStart, onDataCellEditEnd: props.onDataCellEditEnd }), | ||
@@ -9,0 +9,0 @@ React.createElement(DragCopyPoint, null))); |
@@ -0,1 +1,2 @@ | ||
import { __rest } from "tslib"; | ||
import { customMerge } from '@antv/s2'; | ||
@@ -7,3 +8,3 @@ import React from 'react'; | ||
export const GridAnalysisSheet = React.memo((props) => { | ||
const { options: defaultOptions, themeCfg, ...restProps } = props; | ||
const { options: defaultOptions, themeCfg } = props, restProps = __rest(props, ["options", "themeCfg"]); | ||
const s2Options = React.useMemo(() => { | ||
@@ -22,5 +23,5 @@ const options = { | ||
const s2ThemeCfg = React.useMemo(() => customMerge(themeCfg, { theme: GridAnalysisTheme }), [themeCfg]); | ||
return (React.createElement(BaseSheet, { options: s2Options, themeCfg: s2ThemeCfg, ...restProps })); | ||
return (React.createElement(BaseSheet, Object.assign({ options: s2Options, themeCfg: s2ThemeCfg }, restProps))); | ||
}); | ||
GridAnalysisSheet.displayName = 'GridAnalysisSheet'; | ||
//# sourceMappingURL=index.js.map |
@@ -14,5 +14,4 @@ import React from 'react'; | ||
const sheetProps = React.useMemo(() => { | ||
return { | ||
...props, | ||
onMounted: (instance) => { | ||
return Object.assign(Object.assign({}, props), { onMounted: (instance) => { | ||
var _a; | ||
if (ref) { | ||
@@ -22,5 +21,4 @@ ref.current = instance; | ||
setS2Instance(instance); | ||
props.onMounted?.(instance); | ||
}, | ||
}; | ||
(_a = props.onMounted) === null || _a === void 0 ? void 0 : _a.call(props, instance); | ||
} }); | ||
}, [props, ref]); | ||
@@ -30,15 +28,15 @@ const CurrentSheet = React.useMemo(() => { | ||
case 'table': | ||
return React.createElement(TableSheet, { ...sheetProps }); | ||
return React.createElement(TableSheet, Object.assign({}, sheetProps)); | ||
case 'chart': | ||
return React.createElement(ChartSheet, { ...sheetProps }); | ||
return React.createElement(ChartSheet, Object.assign({}, sheetProps)); | ||
case 'pivotChart': | ||
return React.createElement(PivotChartSheet, { ...sheetProps }); | ||
return React.createElement(PivotChartSheet, Object.assign({}, sheetProps)); | ||
case 'gridAnalysis': | ||
return React.createElement(GridAnalysisSheet, { ...sheetProps }); | ||
return React.createElement(GridAnalysisSheet, Object.assign({}, sheetProps)); | ||
case 'strategy': | ||
return React.createElement(StrategySheet, { ...sheetProps }); | ||
return React.createElement(StrategySheet, Object.assign({}, sheetProps)); | ||
case 'editable': | ||
return React.createElement(EditableSheet, { ...sheetProps }); | ||
return React.createElement(EditableSheet, Object.assign({}, sheetProps)); | ||
default: | ||
return React.createElement(PivotSheet, { ...sheetProps }); | ||
return React.createElement(PivotSheet, Object.assign({}, sheetProps)); | ||
} | ||
@@ -45,0 +43,0 @@ }, [sheetType, sheetProps]); |
import React from 'react'; | ||
import { BaseSheet } from '../base-sheet'; | ||
export const PivotChartSheet = React.memo((props) => { | ||
return React.createElement(BaseSheet, { ...props }); | ||
return React.createElement(BaseSheet, Object.assign({}, props)); | ||
}); | ||
PivotChartSheet.displayName = 'PivotChartSheet'; | ||
//# sourceMappingURL=index.js.map |
@@ -0,1 +1,2 @@ | ||
import { __rest } from "tslib"; | ||
import { buildDrillDownOptions, getTooltipOptions, handleDrillDown, } from '@antv/s2'; | ||
@@ -9,3 +10,3 @@ import { useLatest } from 'ahooks'; | ||
export const PivotSheet = React.memo((props) => { | ||
const { options: pivotOptions, ...restProps } = props; | ||
const { options: pivotOptions } = props, restProps = __rest(props, ["options"]); | ||
const { dataCfg, partDrillDown } = restProps; | ||
@@ -15,9 +16,5 @@ const s2 = useSpreadSheetInstance(); | ||
const onDrillDownIconClick = useLatest(({ sheetInstance, cacheDrillFields, disabledFields, event }) => { | ||
const drillDownProps = { | ||
...partDrillDown?.drillConfig, | ||
setDrillFields, | ||
drillFields: cacheDrillFields, | ||
disabledFields, | ||
}; | ||
const content = partDrillDown?.render?.(drillDownProps); | ||
var _a; | ||
const drillDownProps = Object.assign(Object.assign({}, partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.drillConfig), { setDrillFields, drillFields: cacheDrillFields, disabledFields }); | ||
const content = (_a = partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.render) === null || _a === void 0 ? void 0 : _a.call(partDrillDown, drillDownProps); | ||
if (event && content) { | ||
@@ -44,3 +41,3 @@ const { enable: showTooltip } = getTooltipOptions(sheetInstance, event); | ||
const clearDrillDownInfo = (rowId) => { | ||
s2?.clearDrillDownData(rowId); | ||
s2 === null || s2 === void 0 ? void 0 : s2.clearDrillDownData(rowId); | ||
}; | ||
@@ -52,5 +49,6 @@ /** | ||
React.useEffect(() => { | ||
s2?.hideTooltip(); | ||
var _a; | ||
s2 === null || s2 === void 0 ? void 0 : s2.hideTooltip(); | ||
if (isEmpty(drillFields)) { | ||
clearDrillDownInfo(s2?.store.get('drillDownNode')?.id); | ||
clearDrillDownInfo((_a = s2 === null || s2 === void 0 ? void 0 : s2.store.get('drillDownNode')) === null || _a === void 0 ? void 0 : _a.id); | ||
} | ||
@@ -62,4 +60,4 @@ else { | ||
drillFields, | ||
fetchData: partDrillDown?.fetchData, | ||
drillItemsNum: partDrillDown?.drillItemsNum, | ||
fetchData: partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.fetchData, | ||
drillItemsNum: partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.drillItemsNum, | ||
spreadsheet: s2, | ||
@@ -71,7 +69,8 @@ }); | ||
React.useEffect(() => { | ||
if (!isObject(partDrillDown?.clearDrillDown)) { | ||
var _a; | ||
if (!isObject(partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.clearDrillDown)) { | ||
return; | ||
} | ||
clearDrillDownInfo(partDrillDown?.clearDrillDown?.rowId); | ||
}, [partDrillDown?.clearDrillDown]); | ||
clearDrillDownInfo((_a = partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.clearDrillDown) === null || _a === void 0 ? void 0 : _a.rowId); | ||
}, [partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.clearDrillDown]); | ||
/** | ||
@@ -81,5 +80,5 @@ * 控制交叉表 render | ||
const onUpdate = usePivotSheetUpdate(partDrillDown); | ||
return React.createElement(BaseSheet, { ...restProps, options: options, onUpdate: onUpdate }); | ||
return React.createElement(BaseSheet, Object.assign({}, restProps, { options: options, onUpdate: onUpdate })); | ||
}); | ||
PivotSheet.displayName = 'PivotSheet'; | ||
//# sourceMappingURL=index.js.map |
@@ -16,3 +16,3 @@ import { ColCell, drawCustomContent, safeJsonParse, } from '@antv/s2'; | ||
const meta = this.getMeta(); | ||
const value = safeJsonParse(meta?.value); | ||
const value = safeJsonParse(meta === null || meta === void 0 ? void 0 : meta.value); | ||
if (!isArray(value)) { | ||
@@ -22,3 +22,3 @@ return super.drawTextShape(); | ||
const { formattedValue } = this.getFormattedFieldValue(); | ||
const displayValues = formattedValue !== meta?.value ? [[formattedValue]] : [value]; | ||
const displayValues = formattedValue !== (meta === null || meta === void 0 ? void 0 : meta.value) ? [[formattedValue]] : [value]; | ||
drawCustomContent(this, { | ||
@@ -25,0 +25,0 @@ values: displayValues, |
@@ -12,17 +12,10 @@ import { CustomGridPivotDataSet, EMPTY_EXTRA_FIELD_PLACEHOLDER, EXTRA_FIELD, i18n, } from '@antv/s2'; | ||
processDataCfg(dataCfg) { | ||
var _a; | ||
const updatedDataCfg = super.processDataCfg(dataCfg); | ||
// 多指标数值挂行头,单指标挂列头 | ||
const valueInCols = size(updatedDataCfg?.fields?.values) <= 1; | ||
const valueInCols = size((_a = updatedDataCfg === null || updatedDataCfg === void 0 ? void 0 : updatedDataCfg.fields) === null || _a === void 0 ? void 0 : _a.values) <= 1; | ||
const newMeta = this.processMeta(dataCfg.meta, i18n('数值')); | ||
return { | ||
...updatedDataCfg, | ||
meta: newMeta, | ||
fields: { | ||
...updatedDataCfg.fields, | ||
rows: [...(dataCfg.fields.rows || []), EXTRA_FIELD], | ||
valueInCols, | ||
}, | ||
}; | ||
return Object.assign(Object.assign({}, updatedDataCfg), { meta: newMeta, fields: Object.assign(Object.assign({}, updatedDataCfg.fields), { rows: [...(dataCfg.fields.rows || []), EXTRA_FIELD], valueInCols }) }); | ||
} | ||
} | ||
//# sourceMappingURL=custom-data-set.js.map |
@@ -14,3 +14,3 @@ import { getStrategySheetTooltipClsName as tooltipCls } from '@antv/s2'; | ||
const customLabel = isFunction(label) ? label(cell, cellName) : label; | ||
const name = customLabel ?? cellName; | ||
const name = customLabel !== null && customLabel !== void 0 ? customLabel : cellName; | ||
return (React.createElement("div", { className: cls(tooltipCls(), tooltipCls('col')) }, | ||
@@ -17,0 +17,0 @@ React.createElement("span", { className: tooltipCls('name') }, name), |
@@ -7,31 +7,32 @@ import { getEmptyPlaceholder, i18n, isUnchangedValue, isUpDataValue, getStrategySheetTooltipClsName as tooltipCls, } from '@antv/s2'; | ||
export const StrategySheetDataCellTooltip = React.memo((props) => { | ||
var _a, _b; | ||
const { cell, label, showOriginalValue: showOriginalValueFromTooltip = false, renderDerivedValue, } = props; | ||
const meta = cell.getMeta(); | ||
const { spreadsheet } = meta; | ||
const metaFieldValue = meta?.fieldValue; | ||
const metaFieldValue = meta === null || meta === void 0 ? void 0 : meta.fieldValue; | ||
const rowDescription = spreadsheet.dataSet.getCustomFieldDescription(cell); | ||
const defaultRowName = spreadsheet.dataSet.getCustomRowFieldName(cell); | ||
const customLabel = isFunction(label) ? label(cell, defaultRowName) : label; | ||
const rowName = customLabel ?? defaultRowName; | ||
const rowName = customLabel !== null && customLabel !== void 0 ? customLabel : defaultRowName; | ||
const colLeafNode = spreadsheet.facet.getColLeafNodeByIndex(meta.colIndex); | ||
const [, ...derivedLabels] = React.useMemo(() => { | ||
try { | ||
return JSON.parse(colLeafNode?.value); | ||
return JSON.parse(colLeafNode === null || colLeafNode === void 0 ? void 0 : colLeafNode.value); | ||
} | ||
catch { | ||
catch (_a) { | ||
return []; | ||
} | ||
}, [colLeafNode?.value]); | ||
}, [colLeafNode === null || colLeafNode === void 0 ? void 0 : colLeafNode.value]); | ||
const { placeholder, style } = spreadsheet.options; | ||
const valuesCfg = style?.dataCell?.valuesCfg; | ||
const [value, ...derivedValues] = first(metaFieldValue?.values) || [ | ||
const valuesCfg = (_a = style === null || style === void 0 ? void 0 : style.dataCell) === null || _a === void 0 ? void 0 : _a.valuesCfg; | ||
const [value, ...derivedValues] = first(metaFieldValue === null || metaFieldValue === void 0 ? void 0 : metaFieldValue.values) || [ | ||
metaFieldValue, | ||
]; | ||
const [originalValue, ...derivedOriginalValues] = first(get(metaFieldValue, valuesCfg?.originalValueField)) || [value]; | ||
const [originalValue, ...derivedOriginalValues] = first(get(metaFieldValue, valuesCfg === null || valuesCfg === void 0 ? void 0 : valuesCfg.originalValueField)) || [value]; | ||
const emptyPlaceholder = getEmptyPlaceholder(meta, placeholder); | ||
const showOriginalValue = valuesCfg?.showOriginalValue || showOriginalValueFromTooltip; | ||
const showOriginalValue = (valuesCfg === null || valuesCfg === void 0 ? void 0 : valuesCfg.showOriginalValue) || showOriginalValueFromTooltip; | ||
return (React.createElement("div", { className: cls(tooltipCls(), tooltipCls('data')) }, | ||
React.createElement("div", { className: tooltipCls('header') }, | ||
React.createElement("span", { className: 'header-label' }, rowName), | ||
React.createElement("span", null, value ?? emptyPlaceholder)), | ||
React.createElement("span", null, (_b = value) !== null && _b !== void 0 ? _b : emptyPlaceholder)), | ||
showOriginalValue && (React.createElement("div", { className: tooltipCls('original-value') }, isNil(originalValue) | ||
@@ -43,2 +44,3 @@ ? emptyPlaceholder | ||
React.createElement("ul", { className: tooltipCls('derived-values') }, derivedValues.map((derivedValue, i) => { | ||
var _a; | ||
const isUnchanged = isUnchangedValue(derivedValue, value); | ||
@@ -54,4 +56,3 @@ const isUp = !isUnchanged && isUpDataValue(derivedValue); | ||
}) }, | ||
!isUnchanged && (React.createElement("span", { className: "derived-value-trend-icon" })), | ||
renderDerivedValue?.(derivedValue, originalDerivedValue, cell) ?? (React.createElement("span", { className: "derived-value-content" }, derivedValue ?? emptyPlaceholder))))); | ||
!isUnchanged && (React.createElement("span", { className: "derived-value-trend-icon" })), (_a = renderDerivedValue === null || renderDerivedValue === void 0 ? void 0 : renderDerivedValue(derivedValue, originalDerivedValue, cell)) !== null && _a !== void 0 ? _a : (React.createElement("span", { className: "derived-value-content" }, derivedValue !== null && derivedValue !== void 0 ? derivedValue : emptyPlaceholder))))); | ||
})))), | ||
@@ -58,0 +59,0 @@ rowDescription && (React.createElement("div", { className: tooltipCls('description') }, |
@@ -9,4 +9,4 @@ import { i18n, getStrategySheetTooltipClsName as tooltipCls, } from '@antv/s2'; | ||
const customLabel = isFunction(label) ? label(cell, value) : label; | ||
const rowName = customLabel ?? value; | ||
const description = spreadsheet.dataSet.getFieldDescription(field) || extra?.['description']; | ||
const rowName = customLabel !== null && customLabel !== void 0 ? customLabel : value; | ||
const description = spreadsheet.dataSet.getFieldDescription(field) || (extra === null || extra === void 0 ? void 0 : extra['description']); | ||
return (React.createElement("div", { className: cls(tooltipCls(), tooltipCls('row')) }, | ||
@@ -13,0 +13,0 @@ React.createElement("div", { className: tooltipCls('value') }, rowName), |
@@ -0,1 +1,2 @@ | ||
import { __rest } from "tslib"; | ||
import { customMerge } from '@antv/s2'; | ||
@@ -17,4 +18,5 @@ import { isEmpty, size } from 'lodash'; | ||
export const StrategySheet = React.memo((props) => { | ||
const { options, themeCfg, dataCfg, ...restProps } = props; | ||
const { options, themeCfg, dataCfg } = props, restProps = __rest(props, ["options", "themeCfg", "dataCfg"]); | ||
const strategySheetOptions = React.useMemo(() => { | ||
var _a; | ||
if (isEmpty(dataCfg)) { | ||
@@ -24,3 +26,3 @@ return null; | ||
// 单指标非自定义树结构隐藏指标列 | ||
const shouldHideValue = size(dataCfg?.fields?.values) === 1; | ||
const shouldHideValue = size((_a = dataCfg === null || dataCfg === void 0 ? void 0 : dataCfg.fields) === null || _a === void 0 ? void 0 : _a.values) === 1; | ||
return { | ||
@@ -62,5 +64,5 @@ hierarchyType: 'tree', | ||
const s2Options = React.useMemo(() => customMerge(strategySheetOptions, options), [options, strategySheetOptions]); | ||
return (React.createElement(BaseSheet, { options: s2Options, themeCfg: themeCfg, dataCfg: dataCfg, ...restProps })); | ||
return (React.createElement(BaseSheet, Object.assign({ options: s2Options, themeCfg: themeCfg, dataCfg: dataCfg }, restProps))); | ||
}); | ||
StrategySheet.displayName = 'StrategySheet'; | ||
//# sourceMappingURL=index.js.map |
import React from 'react'; | ||
import { BaseSheet } from '../base-sheet'; | ||
export const TableSheet = React.memo((props) => { | ||
return React.createElement(BaseSheet, { ...props }); | ||
return React.createElement(BaseSheet, Object.assign({}, props)); | ||
}); | ||
TableSheet.displayName = 'TableSheet'; | ||
//# sourceMappingURL=index.js.map |
@@ -6,3 +6,3 @@ import { TOOLTIP_PREFIX_CLS, } from '@antv/s2'; | ||
const { list = [] } = props; | ||
return (React.createElement("div", { className: `${TOOLTIP_PREFIX_CLS}-detail-list` }, list?.map((listItem, idx) => { | ||
return (React.createElement("div", { className: `${TOOLTIP_PREFIX_CLS}-detail-list` }, list === null || list === void 0 ? void 0 : list.map((listItem, idx) => { | ||
const { name, value, icon } = listItem; | ||
@@ -9,0 +9,0 @@ return (React.createElement("div", { key: `${value}-${idx}`, className: `${TOOLTIP_PREFIX_CLS}-detail-item` }, |
import { TOOLTIP_PREFIX_CLS, i18n, } from '@antv/s2'; | ||
import React from 'react'; | ||
export const TooltipHead = React.memo((props) => { | ||
var _a, _b; | ||
const { rows = [], cols = [] } = props; | ||
return (React.createElement("div", { className: `${TOOLTIP_PREFIX_CLS}-head-info-list` }, | ||
cols.map((item) => item.value)?.join('/'), | ||
cols.length > 0 && rows.length > 0 && i18n(','), | ||
rows.map((item) => item.value)?.join('/'))); | ||
return (React.createElement("div", { className: `${TOOLTIP_PREFIX_CLS}-head-info-list` }, (_a = cols.map((item) => item.value)) === null || _a === void 0 ? void 0 : | ||
_a.join('/'), | ||
cols.length > 0 && rows.length > 0 && i18n(','), (_b = rows.map((item) => item.value)) === null || _b === void 0 ? void 0 : | ||
_b.join('/'))); | ||
}); | ||
TooltipHead.displayName = 'TooltipHead'; | ||
//# sourceMappingURL=head-info.js.map |
@@ -0,1 +1,2 @@ | ||
import { __rest } from "tslib"; | ||
import { getIcon } from '@antv/s2'; | ||
@@ -6,3 +7,3 @@ import React from 'react'; | ||
export const TooltipIcon = React.memo((props) => { | ||
const { icon, ...attrs } = props; | ||
const { icon } = props, attrs = __rest(props, ["icon"]); | ||
if (!icon) { | ||
@@ -13,7 +14,7 @@ return null; | ||
const name = icon; | ||
return React.createElement(HtmlIcon, { name: name, ...attrs }); | ||
return React.createElement(HtmlIcon, Object.assign({ name: name }, attrs)); | ||
} | ||
return React.createElement(ReactElement, { content: icon, ...attrs }); | ||
return React.createElement(ReactElement, Object.assign({ content: icon }, attrs)); | ||
}); | ||
TooltipIcon.displayName = 'TooltipIcon'; | ||
//# sourceMappingURL=icon.js.map |
@@ -0,1 +1,2 @@ | ||
import { __rest } from "tslib"; | ||
import { TOOLTIP_PREFIX_CLS } from '@antv/s2'; | ||
@@ -7,3 +8,3 @@ import { isEmpty, map } from 'lodash'; | ||
export const TooltipOperator = (props) => { | ||
const { onlyShowOperator, cell, menu: { items: menus = [], onClick, selectedKeys = [], render, ...otherMenuProps }, } = props; | ||
const { onlyShowOperator, cell } = props, _a = props.menu, { items: menus = [], onClick, selectedKeys = [], render } = _a, otherMenuProps = __rest(_a, ["items", "onClick", "selectedKeys", "render"]); | ||
if (isEmpty(menus)) { | ||
@@ -13,5 +14,6 @@ return null; | ||
const onMenuClick = (info) => { | ||
var _a; | ||
const currentMenu = menus.find((menu) => menu.key === info.key); | ||
onClick?.(info, cell); | ||
currentMenu?.onClick?.(info, cell); | ||
onClick === null || onClick === void 0 ? void 0 : onClick(info, cell); | ||
(_a = currentMenu === null || currentMenu === void 0 ? void 0 : currentMenu.onClick) === null || _a === void 0 ? void 0 : _a.call(currentMenu, info, cell); | ||
}; | ||
@@ -27,4 +29,4 @@ const renderMenu = (menu) => { | ||
onTitleClick: (info) => { | ||
onTitleClick?.(info, cell); | ||
onClick?.(info, cell); | ||
onTitleClick === null || onTitleClick === void 0 ? void 0 : onTitleClick(info, cell); | ||
onClick === null || onClick === void 0 ? void 0 : onClick(info, cell); | ||
}, | ||
@@ -36,10 +38,4 @@ children: !isEmpty(subMenus) ? subMenus : undefined, | ||
const items = map(menus, renderMenu); | ||
return render?.({ | ||
mode: onlyShowOperator ? 'vertical' : 'horizontal', | ||
selectable: onlyShowOperator, | ||
onClick: onMenuClick, | ||
items, | ||
selectedKeys, | ||
...otherMenuProps, | ||
}); | ||
return render === null || render === void 0 ? void 0 : render(Object.assign({ mode: onlyShowOperator ? 'vertical' : 'horizontal', selectable: onlyShowOperator, onClick: onMenuClick, items, | ||
selectedKeys }, otherMenuProps)); | ||
}; | ||
@@ -46,0 +42,0 @@ return (React.createElement("div", { className: `${TOOLTIP_PREFIX_CLS}-operator` }, renderMenus())); |
@@ -7,7 +7,8 @@ import { TOOLTIP_PREFIX_CLS, i18n, isMobile, } from '@antv/s2'; | ||
export const TooltipSummary = React.memo((props) => { | ||
var _a; | ||
const { summaries = [] } = props; | ||
const s2 = useSpreadSheetInstance(); | ||
const isMobileDevice = isMobile(s2?.options?.device); | ||
const isMobileDevice = isMobile((_a = s2 === null || s2 === void 0 ? void 0 : s2.options) === null || _a === void 0 ? void 0 : _a.device); | ||
const renderSelected = () => { | ||
const count = sumBy(summaries, (item) => size(item?.selectedData)); | ||
const count = sumBy(summaries, (item) => size(item === null || item === void 0 ? void 0 : item.selectedData)); | ||
return (React.createElement("div", { className: `${TOOLTIP_PREFIX_CLS}-summary-item`, style: isMobileDevice ? { marginBottom: '6px' } : {} }, | ||
@@ -20,3 +21,3 @@ React.createElement("span", { className: `${TOOLTIP_PREFIX_CLS}-selected` }, | ||
}; | ||
const renderSummary = () => summaries?.map((item) => { | ||
const renderSummary = () => summaries === null || summaries === void 0 ? void 0 : summaries.map((item) => { | ||
const { name = '', value } = item || {}; | ||
@@ -30,3 +31,3 @@ if (!name && !value) { | ||
i18n('总和'))) : (React.createElement("span", { className: `${TOOLTIP_PREFIX_CLS}-summary-key` }, "\u00A0")), | ||
React.createElement("span", { className: cls(`${TOOLTIP_PREFIX_CLS}-summary-val`, `${TOOLTIP_PREFIX_CLS}-bold`) }, value ?? '-'))); | ||
React.createElement("span", { className: cls(`${TOOLTIP_PREFIX_CLS}-summary-val`, `${TOOLTIP_PREFIX_CLS}-bold`) }, value !== null && value !== void 0 ? value : '-'))); | ||
}); | ||
@@ -33,0 +34,0 @@ return (React.createElement("div", { className: `${TOOLTIP_PREFIX_CLS}-summary` }, |
@@ -18,5 +18,7 @@ /* eslint-disable import/order */ | ||
isMobileDevice() { | ||
return isMobile(this.spreadsheet.options?.device); | ||
var _a; | ||
return isMobile((_a = this.spreadsheet.options) === null || _a === void 0 ? void 0 : _a.device); | ||
} | ||
renderContent() { | ||
var _a, _b, _c; | ||
// 配置级 s2.options.tooltip.content = '' | ||
@@ -26,21 +28,17 @@ const { content: contentFromOptions, operation } = this.spreadsheet.options.tooltip; | ||
const showOptions = this.options; | ||
const cell = this.spreadsheet.getCell(showOptions?.event?.target); | ||
const cell = this.spreadsheet.getCell((_a = showOptions === null || showOptions === void 0 ? void 0 : showOptions.event) === null || _a === void 0 ? void 0 : _a.target); | ||
// 优先级: 方法级 > 配置级, 兼容 content 为空字符串的场景 | ||
const content = (showOptions?.content ?? | ||
contentFromOptions); | ||
const content = ((_b = showOptions === null || showOptions === void 0 ? void 0 : showOptions.content) !== null && _b !== void 0 ? _b : contentFromOptions); | ||
const tooltipProps = customMerge({ | ||
options: { | ||
operator: { | ||
menu: omit(operation?.menu, 'items'), | ||
menu: omit(operation === null || operation === void 0 ? void 0 : operation.menu, 'items'), | ||
}, | ||
}, | ||
}, { | ||
...showOptions, | ||
cell, | ||
content, | ||
}); | ||
if (showOptions?.options?.forceRender) { | ||
}, Object.assign(Object.assign({}, showOptions), { cell, | ||
content })); | ||
if ((_c = showOptions === null || showOptions === void 0 ? void 0 : showOptions.options) === null || _c === void 0 ? void 0 : _c.forceRender) { | ||
this.forceClearContent(); | ||
} | ||
const TooltipContent = (React.createElement(TooltipComponent, { ...tooltipProps, content: content })); | ||
const TooltipContent = (React.createElement(TooltipComponent, Object.assign({}, tooltipProps, { content: content }))); | ||
reactRender(TooltipContent, this.container); | ||
@@ -47,0 +45,0 @@ } |
@@ -19,3 +19,3 @@ import { getTooltipDefaultOptions } from '@antv/s2'; | ||
} | ||
return (React.createElement(TooltipOperator, { ...operator, menu: operator.menu, onlyShowOperator: onlyShowOperator, cell: cell })); | ||
return (React.createElement(TooltipOperator, Object.assign({}, operator, { menu: operator.menu, onlyShowOperator: onlyShowOperator, cell: cell }))); | ||
}; | ||
@@ -33,3 +33,3 @@ const renderNameTips = (nameTip) => { | ||
const renderInfos = (infos) => infos && React.createElement(TooltipInfos, { infos: infos }); | ||
const renderInterpretation = (interpretation) => interpretation && React.createElement(TooltipInterpretation, { ...interpretation }); | ||
const renderInterpretation = (interpretation) => interpretation && React.createElement(TooltipInterpretation, Object.assign({}, interpretation)); | ||
const renderDescription = (description) => (React.createElement(TooltipDescription, { description: description })); | ||
@@ -52,4 +52,3 @@ const renderContent = () => { | ||
return (React.createElement("span", { ref: onMounted }, | ||
renderOperation(operator), | ||
content ?? DefaultContent)); | ||
renderOperation(operator), content !== null && content !== void 0 ? content : DefaultContent)); | ||
}; | ||
@@ -56,0 +55,0 @@ return renderContent(); |
@@ -7,7 +7,7 @@ /* eslint-disable max-lines-per-function */ | ||
const handlerFn = (event) => { | ||
handler?.(getBaseCellData(event, s2)); | ||
handler === null || handler === void 0 ? void 0 : handler(getBaseCellData(event, s2)); | ||
}; | ||
s2?.on(eventName, handlerFn); | ||
s2 === null || s2 === void 0 ? void 0 : s2.on(eventName, handlerFn); | ||
return () => { | ||
s2?.off(eventName, handlerFn); | ||
s2 === null || s2 === void 0 ? void 0 : s2.off(eventName, handlerFn); | ||
}; | ||
@@ -19,10 +19,10 @@ }, [s2, handler, eventName]); | ||
const handlerFn = (...args) => { | ||
handler?.(...args); | ||
handler === null || handler === void 0 ? void 0 : handler(...args); | ||
}; | ||
s2?.on(eventName, handlerFn); | ||
s2 === null || s2 === void 0 ? void 0 : s2.on(eventName, handlerFn); | ||
return () => { | ||
if (emitBeforeOff) { | ||
s2?.emit(eventName); | ||
s2 === null || s2 === void 0 ? void 0 : s2.emit(eventName); | ||
} | ||
s2?.off(eventName, handlerFn); | ||
s2 === null || s2 === void 0 ? void 0 : s2.off(eventName, handlerFn); | ||
}; | ||
@@ -29,0 +29,0 @@ }, [s2, handler, eventName]); |
import { S2Event } from '@antv/s2'; | ||
import React from 'react'; | ||
export const useLoading = (s2, loadingFromProps) => { | ||
const [loading, setLoading] = React.useState(loadingFromProps ?? false); | ||
const [loading, setLoading] = React.useState(loadingFromProps !== null && loadingFromProps !== void 0 ? loadingFromProps : false); | ||
React.useEffect(() => { | ||
s2?.on(S2Event.LAYOUT_BEFORE_RENDER, () => { | ||
s2 === null || s2 === void 0 ? void 0 : s2.on(S2Event.LAYOUT_BEFORE_RENDER, () => { | ||
setLoading(true); | ||
}); | ||
s2?.on(S2Event.LAYOUT_AFTER_RENDER, () => { | ||
s2 === null || s2 === void 0 ? void 0 : s2.on(S2Event.LAYOUT_AFTER_RENDER, () => { | ||
setLoading(false); | ||
@@ -14,3 +14,3 @@ }); | ||
return { | ||
loading: loadingFromProps ?? loading, | ||
loading: loadingFromProps !== null && loadingFromProps !== void 0 ? loadingFromProps : loading, | ||
setLoading, | ||
@@ -17,0 +17,0 @@ }; |
@@ -0,1 +1,2 @@ | ||
import { __awaiter } from "tslib"; | ||
import { S2Event, } from '@antv/s2'; | ||
@@ -11,17 +12,18 @@ import { useUpdateEffect } from 'ahooks'; | ||
export const usePagination = (s2, options) => { | ||
const defaultPagination = options?.pagination; | ||
var _a; | ||
const defaultPagination = options === null || options === void 0 ? void 0 : options.pagination; | ||
const [pagination, setPagination] = React.useState({ | ||
total: s2?.facet?.viewCellHeights.getTotalLength() || 0, | ||
current: defaultPagination?.current || DEFAULT_PAGE_NUMBER, | ||
pageSize: defaultPagination?.pageSize || DEFAULT_PAGE_SIZE, | ||
total: ((_a = s2 === null || s2 === void 0 ? void 0 : s2.facet) === null || _a === void 0 ? void 0 : _a.viewCellHeights.getTotalLength()) || 0, | ||
current: (defaultPagination === null || defaultPagination === void 0 ? void 0 : defaultPagination.current) || DEFAULT_PAGE_NUMBER, | ||
pageSize: (defaultPagination === null || defaultPagination === void 0 ? void 0 : defaultPagination.pageSize) || DEFAULT_PAGE_SIZE, | ||
}); | ||
const onShowSizeChange = (current, pageSize) => { | ||
setPagination({ ...pagination, current, pageSize }); | ||
setPagination(Object.assign(Object.assign({}, pagination), { current, pageSize })); | ||
}; | ||
const onChange = (current, pageSize) => { | ||
setPagination({ ...pagination, current, pageSize }); | ||
setPagination(Object.assign(Object.assign({}, pagination), { current, pageSize })); | ||
}; | ||
// sync state.pagination -> s2.pagination | ||
useUpdateEffect(() => { | ||
const render = async () => { | ||
const render = () => __awaiter(void 0, void 0, void 0, function* () { | ||
if (!s2 || isEmpty(defaultPagination)) { | ||
@@ -34,4 +36,4 @@ return; | ||
}); | ||
await s2.render(false); | ||
}; | ||
yield s2.render(false); | ||
}); | ||
render(); | ||
@@ -42,6 +44,7 @@ // eslint-disable-next-line react-hooks/exhaustive-deps | ||
useUpdateEffect(() => { | ||
var _a; | ||
setPagination({ | ||
total: s2?.facet?.viewCellHeights.getTotalLength() || 0, | ||
current: defaultPagination?.current || DEFAULT_PAGE_NUMBER, | ||
pageSize: defaultPagination?.pageSize || DEFAULT_PAGE_SIZE, | ||
total: ((_a = s2 === null || s2 === void 0 ? void 0 : s2.facet) === null || _a === void 0 ? void 0 : _a.viewCellHeights.getTotalLength()) || 0, | ||
current: (defaultPagination === null || defaultPagination === void 0 ? void 0 : defaultPagination.current) || DEFAULT_PAGE_NUMBER, | ||
pageSize: (defaultPagination === null || defaultPagination === void 0 ? void 0 : defaultPagination.pageSize) || DEFAULT_PAGE_SIZE, | ||
}); | ||
@@ -56,3 +59,3 @@ }, [defaultPagination, s2]); | ||
setPagination((prev) => { | ||
return { ...prev, total: data.total }; | ||
return Object.assign(Object.assign({}, prev), { total: data.total }); | ||
}); | ||
@@ -65,9 +68,5 @@ }; | ||
}, [defaultPagination, s2]); | ||
return { | ||
...defaultPagination, | ||
...pagination, | ||
onShowSizeChange, | ||
onChange, | ||
}; | ||
return Object.assign(Object.assign(Object.assign({}, defaultPagination), pagination), { onShowSizeChange, | ||
onChange }); | ||
}; | ||
//# sourceMappingURL=usePagination.js.map |
@@ -0,1 +1,2 @@ | ||
import { __awaiter } from "tslib"; | ||
import { PivotSheet, TableSheet } from '@antv/s2'; | ||
@@ -21,3 +22,3 @@ import { PivotChartSheet } from '@antv/s2/extends'; | ||
} | ||
catch { | ||
catch (_a) { | ||
return false; | ||
@@ -45,7 +46,8 @@ } | ||
}, [sheetType, options, dataCfg, customSpreadSheet]); | ||
const buildSpreadSheet = React.useCallback(async () => { | ||
const buildSpreadSheet = React.useCallback(() => __awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
setLoading(true); | ||
const s2 = renderSpreadSheet(containerRef.current); | ||
s2.setThemeCfg(props.themeCfg); | ||
await s2.render(); | ||
yield s2.render(); | ||
setLoading(false); | ||
@@ -58,7 +60,7 @@ s2Ref.current = s2; | ||
forceUpdate(); | ||
props.onMounted?.(s2Ref.current); | ||
}, [props, renderSpreadSheet, setLoading, forceUpdate]); | ||
(_a = props.onMounted) === null || _a === void 0 ? void 0 : _a.call(props, s2Ref.current); | ||
}), [props, renderSpreadSheet, setLoading, forceUpdate]); | ||
// 适用于监听 loading 状态, 组件外部使用 <Spin /> 等场景 | ||
React.useEffect(() => { | ||
onLoading?.(loading); | ||
onLoading === null || onLoading === void 0 ? void 0 : onLoading(loading); | ||
}, [loading]); | ||
@@ -73,4 +75,5 @@ React.useEffect(() => { | ||
return () => { | ||
var _a, _b; | ||
setLoading(false); | ||
s2Ref.current?.destroy?.(); | ||
(_b = (_a = s2Ref.current) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a); | ||
}; | ||
@@ -80,3 +83,4 @@ }, [isDevMode]); | ||
useUpdateEffect(() => { | ||
const render = async () => { | ||
const render = () => __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; | ||
setLoading(true); | ||
@@ -90,23 +94,23 @@ const [prevDataCfg, prevOptions, prevThemeCfg] = updatePrevDepsRef.current; | ||
// 列头变化需要重新计算初始叶子节点 | ||
if (prevDataCfg?.fields?.columns?.length !== | ||
dataCfg?.fields?.columns?.length) { | ||
s2Ref.current?.facet?.clearInitColLeafNodes(); | ||
if (((_b = (_a = prevDataCfg === null || prevDataCfg === void 0 ? void 0 : prevDataCfg.fields) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.length) !== | ||
((_d = (_c = dataCfg === null || dataCfg === void 0 ? void 0 : dataCfg.fields) === null || _c === void 0 ? void 0 : _c.columns) === null || _d === void 0 ? void 0 : _d.length)) { | ||
(_f = (_e = s2Ref.current) === null || _e === void 0 ? void 0 : _e.facet) === null || _f === void 0 ? void 0 : _f.clearInitColLeafNodes(); | ||
} | ||
reloadData = true; | ||
rerender = true; | ||
s2Ref.current?.setDataCfg(dataCfg); | ||
(_g = s2Ref.current) === null || _g === void 0 ? void 0 : _g.setDataCfg(dataCfg); | ||
} | ||
if (!isEqual(prevOptions, options)) { | ||
if (prevOptions?.hierarchyType !== options?.hierarchyType) { | ||
if ((prevOptions === null || prevOptions === void 0 ? void 0 : prevOptions.hierarchyType) !== (options === null || options === void 0 ? void 0 : options.hierarchyType)) { | ||
rebuildDataSet = true; | ||
reloadData = true; | ||
s2Ref.current?.setDataCfg(dataCfg); | ||
(_h = s2Ref.current) === null || _h === void 0 ? void 0 : _h.setDataCfg(dataCfg); | ||
} | ||
rerender = true; | ||
s2Ref.current?.setOptions(options); | ||
s2Ref.current?.changeSheetSize(options.width, options.height); | ||
(_j = s2Ref.current) === null || _j === void 0 ? void 0 : _j.setOptions(options); | ||
(_k = s2Ref.current) === null || _k === void 0 ? void 0 : _k.changeSheetSize(options.width, options.height); | ||
} | ||
if (!isEqual(prevThemeCfg, themeCfg)) { | ||
rerender = true; | ||
s2Ref.current?.setThemeCfg(themeCfg); | ||
(_l = s2Ref.current) === null || _l === void 0 ? void 0 : _l.setThemeCfg(themeCfg); | ||
} | ||
@@ -125,7 +129,7 @@ if (!rerender) { | ||
}; | ||
const renderOptions = onUpdate?.(defaultRenderOptions) || defaultRenderOptions; | ||
await s2Ref.current?.render(renderOptions); | ||
const renderOptions = (onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(defaultRenderOptions)) || defaultRenderOptions; | ||
yield ((_m = s2Ref.current) === null || _m === void 0 ? void 0 : _m.render(renderOptions)); | ||
setLoading(false); | ||
onUpdateAfterRender?.(renderOptions); | ||
}; | ||
onUpdateAfterRender === null || onUpdateAfterRender === void 0 ? void 0 : onUpdateAfterRender(renderOptions); | ||
}); | ||
render(); | ||
@@ -132,0 +136,0 @@ }, [dataCfg, options, themeCfg, onUpdate]); |
import './utils/extendLocale'; | ||
export * from './components'; | ||
export declare const version = "@antv/s2-react-v2.1.2"; | ||
export declare const version = "@antv/s2-react-v2.1.3"; |
import './utils/extendLocale'; | ||
export * from './components'; | ||
export const version = '@antv/s2-react-v2.1.2'; | ||
export const version = '@antv/s2-react-v2.1.3'; | ||
//# sourceMappingURL=index.js.map |
@@ -8,5 +8,3 @@ /** | ||
export const S2_REACT_ROOT_SYMBOL_ID = `__s2_react_root__`; | ||
const ReactDOMClone = { | ||
...ReactDOM, | ||
}; | ||
const ReactDOMClone = Object.assign({}, ReactDOM); | ||
const { render: reactOriginalRender, unmountComponentAtNode } = ReactDOMClone; | ||
@@ -61,4 +59,5 @@ let createRoot; | ||
return Promise.resolve().then(() => { | ||
container?.[S2_REACT_ROOT_SYMBOL_ID]?.unmount(); | ||
delete container?.[S2_REACT_ROOT_SYMBOL_ID]; | ||
var _a; | ||
(_a = container === null || container === void 0 ? void 0 : container[S2_REACT_ROOT_SYMBOL_ID]) === null || _a === void 0 ? void 0 : _a.unmount(); | ||
container === null || container === void 0 ? true : delete container[S2_REACT_ROOT_SYMBOL_ID]; | ||
}); | ||
@@ -65,0 +64,0 @@ } |
@@ -13,3 +13,3 @@ "use strict"; | ||
// fix: Uncaught TypeError: Cannot assign to read only property 'width' of object '#<Object>' | ||
const newStyle = { ...style }; | ||
const newStyle = Object.assign({}, style); | ||
/* | ||
@@ -16,0 +16,0 @@ * html-icon 和 gui-icon 的接口趋于一致,都有 width 和 height 的便携属性 |
@@ -16,3 +16,3 @@ "use strict"; | ||
if (react_1.default.isValidElement(content)) { | ||
return (react_1.default.createElement("span", { ...commonProps }, | ||
return (react_1.default.createElement("span", Object.assign({}, commonProps), | ||
react_1.default.createElement(react_1.default.Fragment, null, content))); | ||
@@ -22,7 +22,7 @@ } | ||
const htmlNode = typeof content !== 'string' | ||
? content?.innerHTML | ||
? content === null || content === void 0 ? void 0 : content.innerHTML | ||
: content; | ||
return (react_1.default.createElement("span", { ...commonProps, dangerouslySetInnerHTML: { __html: htmlNode } })); | ||
return (react_1.default.createElement("span", Object.assign({}, commonProps, { dangerouslySetInnerHTML: { __html: htmlNode } }))); | ||
}; | ||
exports.ReactElement = ReactElement; | ||
//# sourceMappingURL=react-element.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
exports.ChartSheet = react_1.default.memo((props) => { | ||
const { options: defaultOptions, themeCfg: defaultThemeCfg, ...restProps } = props; | ||
const { options: defaultOptions, themeCfg: defaultThemeCfg } = props, restProps = tslib_1.__rest(props, ["options", "themeCfg"]); | ||
const s2Options = react_1.default.useMemo(() => { | ||
@@ -59,5 +59,5 @@ const options = { | ||
}, [defaultThemeCfg]); | ||
return react_1.default.createElement(base_sheet_1.BaseSheet, { ...restProps, options: s2Options, themeCfg: themeCfg }); | ||
return react_1.default.createElement(base_sheet_1.BaseSheet, Object.assign({}, restProps, { options: s2Options, themeCfg: themeCfg })); | ||
}); | ||
exports.ChartSheet.displayName = 'ChartSheet'; | ||
//# sourceMappingURL=index.js.map |
@@ -17,3 +17,4 @@ "use strict"; | ||
const { left, top, width, height } = react_1.default.useMemo(() => { | ||
const rect = s2.getCanvasElement()?.getBoundingClientRect(); | ||
var _a; | ||
const rect = (_a = s2.getCanvasElement()) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect(); | ||
return { | ||
@@ -28,3 +29,3 @@ left: window.scrollX + rect.left, | ||
const scroll = s2.facet.getScrollOffset(); | ||
const cellMeta = (0, lodash_1.pick)(cell?.getMeta(), ['x', 'y', 'width', 'height']); | ||
const cellMeta = (0, lodash_1.pick)(cell === null || cell === void 0 ? void 0 : cell.getMeta(), ['x', 'y', 'width', 'height']); | ||
if ((0, lodash_1.isNil)(cellMeta.x) || (0, lodash_1.isNil)(cellMeta.y)) { | ||
@@ -39,3 +40,3 @@ return { | ||
const sampleColNode = s2.facet.getColNodes()[0]; | ||
const sampleColNodeHeight = sampleColNode?.height || 0; | ||
const sampleColNodeHeight = (sampleColNode === null || sampleColNode === void 0 ? void 0 : sampleColNode.height) || 0; | ||
cellMeta.x -= scroll.scrollX || 0; | ||
@@ -48,3 +49,4 @@ cellMeta.y -= (scroll.scrollY || 0) - sampleColNodeHeight; | ||
const containerRef = react_1.default.useRef(null); | ||
const onSave = async () => { | ||
const onSave = () => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
const { rowIndex, valueField, id } = cell.getMeta(); | ||
@@ -54,4 +56,4 @@ const displayData = s2.dataSet.getDisplayDataSet(); | ||
// 编辑后的值作为格式化后的结果, formatter 不再触发, 避免二次格式化 | ||
s2.dataSet.displayFormattedValueMap?.set(id, inputVal); | ||
await s2.render(); | ||
(_a = s2.dataSet.displayFormattedValueMap) === null || _a === void 0 ? void 0 : _a.set(id, inputVal); | ||
yield s2.render(); | ||
const editedMeta = (0, s2_1.customMerge)(cell.getMeta(), { | ||
@@ -63,5 +65,5 @@ fieldValue: inputVal, | ||
}); | ||
onDataCellEditEnd?.(editedMeta, cell); | ||
onDataCellEditEnd === null || onDataCellEditEnd === void 0 ? void 0 : onDataCellEditEnd(editedMeta, cell); | ||
resolver(true); | ||
}; | ||
}); | ||
const onKeyDown = (e) => { | ||
@@ -94,8 +96,9 @@ if (e.key === 'Enter') { | ||
react_1.default.useEffect(() => { | ||
onDataCellEditStart?.(cell.getMeta(), cell); | ||
onDataCellEditStart === null || onDataCellEditStart === void 0 ? void 0 : onDataCellEditStart(cell.getMeta(), cell); | ||
setTimeout(() => { | ||
var _a, _b; | ||
// 防止触发表格全选 | ||
containerRef.current?.click(); | ||
(_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.click(); | ||
// 开启 preventScroll, 防止页面有滚动条时触发滚动 | ||
inputRef.current?.focus({ preventScroll: true }); | ||
(_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus({ preventScroll: true }); | ||
}); | ||
@@ -102,0 +105,0 @@ }, []); |
@@ -25,7 +25,7 @@ "use strict"; | ||
const sampleColNode = s2.facet.getColNodes()[0]; | ||
const sampleColNodeHeight = sampleColNode?.height || 0; | ||
const sampleColNodeHeight = (sampleColNode === null || sampleColNode === void 0 ? void 0 : sampleColNode.height) || 0; | ||
// 点位偏移 | ||
const pointX = point.x; | ||
const pointY = point.y; | ||
const scrollOffsetY = scrollOffset?.scrollY - sampleColNodeHeight; | ||
const scrollOffsetY = (scrollOffset === null || scrollOffset === void 0 ? void 0 : scrollOffset.scrollY) - sampleColNodeHeight; | ||
const cellMaxX = cellMeta.x - scrollOffset.scrollX + cellMeta.width + 4; | ||
@@ -61,3 +61,3 @@ const cellMinX = cellMeta.x - scrollOffset.scrollX; | ||
const startCellMeta = startCell.getMeta(); | ||
const endCellMeta = endCell?.getMeta(); | ||
const endCellMeta = endCell === null || endCell === void 0 ? void 0 : endCell.getMeta(); | ||
const minX = Math.min(startCellMeta.colIndex, endCellMeta.colIndex); | ||
@@ -104,3 +104,3 @@ const maxX = Math.max(startCellMeta.colIndex, endCellMeta.colIndex); | ||
}, 10); | ||
const dragMouseUp = async (event) => { | ||
const dragMouseUp = (event) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
if (!startCell) { | ||
@@ -128,3 +128,3 @@ return; | ||
}); | ||
await s2.render(true); | ||
yield s2.render(true); | ||
setMaskPosition({ right: 0, bottom: 0 }); | ||
@@ -134,4 +134,4 @@ s2.off(s2_1.S2Event.GLOBAL_MOUSE_MOVE, dragMove); | ||
setStartCell(undefined); | ||
onCopyFinished?.(); | ||
}; | ||
onCopyFinished === null || onCopyFinished === void 0 ? void 0 : onCopyFinished(); | ||
}); | ||
(0, react_1.useEffect)(() => { | ||
@@ -160,3 +160,3 @@ if (startCell) { | ||
return () => { | ||
pointElement?.removeEventListener('mousedown', dragMouseDown); | ||
pointElement === null || pointElement === void 0 ? void 0 : pointElement.removeEventListener('mousedown', dragMouseDown); | ||
}; | ||
@@ -163,0 +163,0 @@ }, [s2]); |
@@ -28,3 +28,3 @@ "use strict"; | ||
const rect = spreadsheet.getCanvasElement().getBoundingClientRect(); | ||
const cellMeta = cell?.getMeta(); | ||
const cellMeta = cell === null || cell === void 0 ? void 0 : cell.getMeta(); | ||
if (!(0, lodash_1.isEqual)(newScroll, scroll)) { | ||
@@ -54,7 +54,3 @@ // 超出可视区域隐藏point | ||
} | ||
setScroll({ | ||
...newScroll, | ||
overflow, | ||
width: 8 - (pointWidth > 0 ? pointWidth : 0), | ||
}); | ||
setScroll(Object.assign(Object.assign({}, newScroll), { overflow, width: 8 - (pointWidth > 0 ? pointWidth : 0) })); | ||
} | ||
@@ -85,3 +81,3 @@ else { | ||
return () => { | ||
spreadsheet?.off(s2_1.S2Event.GLOBAL_SCROLL, handleScroll); | ||
spreadsheet === null || spreadsheet === void 0 ? void 0 : spreadsheet.off(s2_1.S2Event.GLOBAL_SCROLL, handleScroll); | ||
}; | ||
@@ -94,5 +90,5 @@ }, [cell]); | ||
} | ||
}, [spreadsheet?.dataSet.sortParams, spreadsheet?.dataSet.filterParams]); | ||
}, [spreadsheet === null || spreadsheet === void 0 ? void 0 : spreadsheet.dataSet.sortParams, spreadsheet === null || spreadsheet === void 0 ? void 0 : spreadsheet.dataSet.filterParams]); | ||
react_1.default.useEffect(() => { | ||
if (!spreadsheet?.getCanvasElement()) { | ||
if (!(spreadsheet === null || spreadsheet === void 0 ? void 0 : spreadsheet.getCanvasElement())) { | ||
return; | ||
@@ -102,3 +98,3 @@ } | ||
const sampleColNode = spreadsheet.facet.getColNodes()[0]; | ||
const sampleColNodeHeight = sampleColNode?.height || 0; | ||
const sampleColNodeHeight = (sampleColNode === null || sampleColNode === void 0 ? void 0 : sampleColNode.height) || 0; | ||
const cellMeta = (0, lodash_1.pick)(cell.getMeta(), [ | ||
@@ -111,4 +107,4 @@ 'x', | ||
]); | ||
cellMeta.x -= scroll?.scrollX; | ||
cellMeta.y -= scroll?.scrollY - sampleColNodeHeight; | ||
cellMeta.x -= scroll === null || scroll === void 0 ? void 0 : scroll.scrollX; | ||
cellMeta.y -= (scroll === null || scroll === void 0 ? void 0 : scroll.scrollY) - sampleColNodeHeight; | ||
setPosition({ | ||
@@ -115,0 +111,0 @@ left: cellMeta.x + cellMeta.width - 4, |
@@ -10,3 +10,3 @@ "use strict"; | ||
exports.EditableSheet = react_1.default.memo((props) => { | ||
return (react_1.default.createElement(base_sheet_1.BaseSheet, { ...props, sheetType: 'table' }, | ||
return (react_1.default.createElement(base_sheet_1.BaseSheet, Object.assign({}, props, { sheetType: 'table' }), | ||
react_1.default.createElement(custom_cell_1.EditCell, { onDataCellEditStart: props.onDataCellEditStart, onDataCellEditEnd: props.onDataCellEditEnd }), | ||
@@ -13,0 +13,0 @@ react_1.default.createElement(drag_copy_1.DragCopyPoint, null))); |
@@ -11,3 +11,3 @@ "use strict"; | ||
exports.GridAnalysisSheet = react_1.default.memo((props) => { | ||
const { options: defaultOptions, themeCfg, ...restProps } = props; | ||
const { options: defaultOptions, themeCfg } = props, restProps = tslib_1.__rest(props, ["options", "themeCfg"]); | ||
const s2Options = react_1.default.useMemo(() => { | ||
@@ -26,5 +26,5 @@ const options = { | ||
const s2ThemeCfg = react_1.default.useMemo(() => (0, s2_1.customMerge)(themeCfg, { theme: theme_1.GridAnalysisTheme }), [themeCfg]); | ||
return (react_1.default.createElement(base_sheet_1.BaseSheet, { options: s2Options, themeCfg: s2ThemeCfg, ...restProps })); | ||
return (react_1.default.createElement(base_sheet_1.BaseSheet, Object.assign({ options: s2Options, themeCfg: s2ThemeCfg }, restProps))); | ||
}); | ||
exports.GridAnalysisSheet.displayName = 'GridAnalysisSheet'; | ||
//# sourceMappingURL=index.js.map |
@@ -18,5 +18,4 @@ "use strict"; | ||
const sheetProps = react_1.default.useMemo(() => { | ||
return { | ||
...props, | ||
onMounted: (instance) => { | ||
return Object.assign(Object.assign({}, props), { onMounted: (instance) => { | ||
var _a; | ||
if (ref) { | ||
@@ -26,5 +25,4 @@ ref.current = instance; | ||
setS2Instance(instance); | ||
props.onMounted?.(instance); | ||
}, | ||
}; | ||
(_a = props.onMounted) === null || _a === void 0 ? void 0 : _a.call(props, instance); | ||
} }); | ||
}, [props, ref]); | ||
@@ -34,15 +32,15 @@ const CurrentSheet = react_1.default.useMemo(() => { | ||
case 'table': | ||
return react_1.default.createElement(table_sheet_1.TableSheet, { ...sheetProps }); | ||
return react_1.default.createElement(table_sheet_1.TableSheet, Object.assign({}, sheetProps)); | ||
case 'chart': | ||
return react_1.default.createElement(chart_sheet_1.ChartSheet, { ...sheetProps }); | ||
return react_1.default.createElement(chart_sheet_1.ChartSheet, Object.assign({}, sheetProps)); | ||
case 'pivotChart': | ||
return react_1.default.createElement(pivot_chart_sheet_1.PivotChartSheet, { ...sheetProps }); | ||
return react_1.default.createElement(pivot_chart_sheet_1.PivotChartSheet, Object.assign({}, sheetProps)); | ||
case 'gridAnalysis': | ||
return react_1.default.createElement(grid_analysis_sheet_1.GridAnalysisSheet, { ...sheetProps }); | ||
return react_1.default.createElement(grid_analysis_sheet_1.GridAnalysisSheet, Object.assign({}, sheetProps)); | ||
case 'strategy': | ||
return react_1.default.createElement(strategy_sheet_1.StrategySheet, { ...sheetProps }); | ||
return react_1.default.createElement(strategy_sheet_1.StrategySheet, Object.assign({}, sheetProps)); | ||
case 'editable': | ||
return react_1.default.createElement(editable_sheet_1.EditableSheet, { ...sheetProps }); | ||
return react_1.default.createElement(editable_sheet_1.EditableSheet, Object.assign({}, sheetProps)); | ||
default: | ||
return react_1.default.createElement(pivot_sheet_1.PivotSheet, { ...sheetProps }); | ||
return react_1.default.createElement(pivot_sheet_1.PivotSheet, Object.assign({}, sheetProps)); | ||
} | ||
@@ -49,0 +47,0 @@ }, [sheetType, sheetProps]); |
@@ -8,5 +8,5 @@ "use strict"; | ||
exports.PivotChartSheet = react_1.default.memo((props) => { | ||
return react_1.default.createElement(base_sheet_1.BaseSheet, { ...props }); | ||
return react_1.default.createElement(base_sheet_1.BaseSheet, Object.assign({}, props)); | ||
}); | ||
exports.PivotChartSheet.displayName = 'PivotChartSheet'; | ||
//# sourceMappingURL=index.js.map |
@@ -13,3 +13,3 @@ "use strict"; | ||
exports.PivotSheet = react_1.default.memo((props) => { | ||
const { options: pivotOptions, ...restProps } = props; | ||
const { options: pivotOptions } = props, restProps = tslib_1.__rest(props, ["options"]); | ||
const { dataCfg, partDrillDown } = restProps; | ||
@@ -19,9 +19,5 @@ const s2 = (0, SpreadSheetContext_1.useSpreadSheetInstance)(); | ||
const onDrillDownIconClick = (0, ahooks_1.useLatest)(({ sheetInstance, cacheDrillFields, disabledFields, event }) => { | ||
const drillDownProps = { | ||
...partDrillDown?.drillConfig, | ||
setDrillFields, | ||
drillFields: cacheDrillFields, | ||
disabledFields, | ||
}; | ||
const content = partDrillDown?.render?.(drillDownProps); | ||
var _a; | ||
const drillDownProps = Object.assign(Object.assign({}, partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.drillConfig), { setDrillFields, drillFields: cacheDrillFields, disabledFields }); | ||
const content = (_a = partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.render) === null || _a === void 0 ? void 0 : _a.call(partDrillDown, drillDownProps); | ||
if (event && content) { | ||
@@ -48,3 +44,3 @@ const { enable: showTooltip } = (0, s2_1.getTooltipOptions)(sheetInstance, event); | ||
const clearDrillDownInfo = (rowId) => { | ||
s2?.clearDrillDownData(rowId); | ||
s2 === null || s2 === void 0 ? void 0 : s2.clearDrillDownData(rowId); | ||
}; | ||
@@ -56,5 +52,6 @@ /** | ||
react_1.default.useEffect(() => { | ||
s2?.hideTooltip(); | ||
var _a; | ||
s2 === null || s2 === void 0 ? void 0 : s2.hideTooltip(); | ||
if ((0, lodash_1.isEmpty)(drillFields)) { | ||
clearDrillDownInfo(s2?.store.get('drillDownNode')?.id); | ||
clearDrillDownInfo((_a = s2 === null || s2 === void 0 ? void 0 : s2.store.get('drillDownNode')) === null || _a === void 0 ? void 0 : _a.id); | ||
} | ||
@@ -66,4 +63,4 @@ else { | ||
drillFields, | ||
fetchData: partDrillDown?.fetchData, | ||
drillItemsNum: partDrillDown?.drillItemsNum, | ||
fetchData: partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.fetchData, | ||
drillItemsNum: partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.drillItemsNum, | ||
spreadsheet: s2, | ||
@@ -75,7 +72,8 @@ }); | ||
react_1.default.useEffect(() => { | ||
if (!(0, lodash_1.isObject)(partDrillDown?.clearDrillDown)) { | ||
var _a; | ||
if (!(0, lodash_1.isObject)(partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.clearDrillDown)) { | ||
return; | ||
} | ||
clearDrillDownInfo(partDrillDown?.clearDrillDown?.rowId); | ||
}, [partDrillDown?.clearDrillDown]); | ||
clearDrillDownInfo((_a = partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.clearDrillDown) === null || _a === void 0 ? void 0 : _a.rowId); | ||
}, [partDrillDown === null || partDrillDown === void 0 ? void 0 : partDrillDown.clearDrillDown]); | ||
/** | ||
@@ -85,5 +83,5 @@ * 控制交叉表 render | ||
const onUpdate = (0, hooks_1.usePivotSheetUpdate)(partDrillDown); | ||
return react_1.default.createElement(base_sheet_1.BaseSheet, { ...restProps, options: options, onUpdate: onUpdate }); | ||
return react_1.default.createElement(base_sheet_1.BaseSheet, Object.assign({}, restProps, { options: options, onUpdate: onUpdate })); | ||
}); | ||
exports.PivotSheet.displayName = 'PivotSheet'; | ||
//# sourceMappingURL=index.js.map |
@@ -19,3 +19,3 @@ "use strict"; | ||
const meta = this.getMeta(); | ||
const value = (0, s2_1.safeJsonParse)(meta?.value); | ||
const value = (0, s2_1.safeJsonParse)(meta === null || meta === void 0 ? void 0 : meta.value); | ||
if (!(0, lodash_1.isArray)(value)) { | ||
@@ -25,3 +25,3 @@ return super.drawTextShape(); | ||
const { formattedValue } = this.getFormattedFieldValue(); | ||
const displayValues = formattedValue !== meta?.value ? [[formattedValue]] : [value]; | ||
const displayValues = formattedValue !== (meta === null || meta === void 0 ? void 0 : meta.value) ? [[formattedValue]] : [value]; | ||
(0, s2_1.drawCustomContent)(this, { | ||
@@ -28,0 +28,0 @@ values: displayValues, |
@@ -15,15 +15,8 @@ "use strict"; | ||
processDataCfg(dataCfg) { | ||
var _a; | ||
const updatedDataCfg = super.processDataCfg(dataCfg); | ||
// 多指标数值挂行头,单指标挂列头 | ||
const valueInCols = (0, lodash_1.size)(updatedDataCfg?.fields?.values) <= 1; | ||
const valueInCols = (0, lodash_1.size)((_a = updatedDataCfg === null || updatedDataCfg === void 0 ? void 0 : updatedDataCfg.fields) === null || _a === void 0 ? void 0 : _a.values) <= 1; | ||
const newMeta = this.processMeta(dataCfg.meta, (0, s2_1.i18n)('数值')); | ||
return { | ||
...updatedDataCfg, | ||
meta: newMeta, | ||
fields: { | ||
...updatedDataCfg.fields, | ||
rows: [...(dataCfg.fields.rows || []), s2_1.EXTRA_FIELD], | ||
valueInCols, | ||
}, | ||
}; | ||
return Object.assign(Object.assign({}, updatedDataCfg), { meta: newMeta, fields: Object.assign(Object.assign({}, updatedDataCfg.fields), { rows: [...(dataCfg.fields.rows || []), s2_1.EXTRA_FIELD], valueInCols }) }); | ||
} | ||
@@ -30,0 +23,0 @@ } |
@@ -18,3 +18,3 @@ "use strict"; | ||
const customLabel = (0, lodash_1.isFunction)(label) ? label(cell, cellName) : label; | ||
const name = customLabel ?? cellName; | ||
const name = customLabel !== null && customLabel !== void 0 ? customLabel : cellName; | ||
return (react_1.default.createElement("div", { className: (0, classnames_1.default)((0, s2_1.getStrategySheetTooltipClsName)(), (0, s2_1.getStrategySheetTooltipClsName)('col')) }, | ||
@@ -21,0 +21,0 @@ react_1.default.createElement("span", { className: (0, s2_1.getStrategySheetTooltipClsName)('name') }, name), |
@@ -11,31 +11,32 @@ "use strict"; | ||
exports.StrategySheetDataCellTooltip = react_1.default.memo((props) => { | ||
var _a, _b; | ||
const { cell, label, showOriginalValue: showOriginalValueFromTooltip = false, renderDerivedValue, } = props; | ||
const meta = cell.getMeta(); | ||
const { spreadsheet } = meta; | ||
const metaFieldValue = meta?.fieldValue; | ||
const metaFieldValue = meta === null || meta === void 0 ? void 0 : meta.fieldValue; | ||
const rowDescription = spreadsheet.dataSet.getCustomFieldDescription(cell); | ||
const defaultRowName = spreadsheet.dataSet.getCustomRowFieldName(cell); | ||
const customLabel = (0, lodash_1.isFunction)(label) ? label(cell, defaultRowName) : label; | ||
const rowName = customLabel ?? defaultRowName; | ||
const rowName = customLabel !== null && customLabel !== void 0 ? customLabel : defaultRowName; | ||
const colLeafNode = spreadsheet.facet.getColLeafNodeByIndex(meta.colIndex); | ||
const [, ...derivedLabels] = react_1.default.useMemo(() => { | ||
try { | ||
return JSON.parse(colLeafNode?.value); | ||
return JSON.parse(colLeafNode === null || colLeafNode === void 0 ? void 0 : colLeafNode.value); | ||
} | ||
catch { | ||
catch (_a) { | ||
return []; | ||
} | ||
}, [colLeafNode?.value]); | ||
}, [colLeafNode === null || colLeafNode === void 0 ? void 0 : colLeafNode.value]); | ||
const { placeholder, style } = spreadsheet.options; | ||
const valuesCfg = style?.dataCell?.valuesCfg; | ||
const [value, ...derivedValues] = (0, lodash_1.first)(metaFieldValue?.values) || [ | ||
const valuesCfg = (_a = style === null || style === void 0 ? void 0 : style.dataCell) === null || _a === void 0 ? void 0 : _a.valuesCfg; | ||
const [value, ...derivedValues] = (0, lodash_1.first)(metaFieldValue === null || metaFieldValue === void 0 ? void 0 : metaFieldValue.values) || [ | ||
metaFieldValue, | ||
]; | ||
const [originalValue, ...derivedOriginalValues] = (0, lodash_1.first)((0, lodash_1.get)(metaFieldValue, valuesCfg?.originalValueField)) || [value]; | ||
const [originalValue, ...derivedOriginalValues] = (0, lodash_1.first)((0, lodash_1.get)(metaFieldValue, valuesCfg === null || valuesCfg === void 0 ? void 0 : valuesCfg.originalValueField)) || [value]; | ||
const emptyPlaceholder = (0, s2_1.getEmptyPlaceholder)(meta, placeholder); | ||
const showOriginalValue = valuesCfg?.showOriginalValue || showOriginalValueFromTooltip; | ||
const showOriginalValue = (valuesCfg === null || valuesCfg === void 0 ? void 0 : valuesCfg.showOriginalValue) || showOriginalValueFromTooltip; | ||
return (react_1.default.createElement("div", { className: (0, classnames_1.default)((0, s2_1.getStrategySheetTooltipClsName)(), (0, s2_1.getStrategySheetTooltipClsName)('data')) }, | ||
react_1.default.createElement("div", { className: (0, s2_1.getStrategySheetTooltipClsName)('header') }, | ||
react_1.default.createElement("span", { className: 'header-label' }, rowName), | ||
react_1.default.createElement("span", null, value ?? emptyPlaceholder)), | ||
react_1.default.createElement("span", null, (_b = value) !== null && _b !== void 0 ? _b : emptyPlaceholder)), | ||
showOriginalValue && (react_1.default.createElement("div", { className: (0, s2_1.getStrategySheetTooltipClsName)('original-value') }, (0, lodash_1.isNil)(originalValue) | ||
@@ -47,2 +48,3 @@ ? emptyPlaceholder | ||
react_1.default.createElement("ul", { className: (0, s2_1.getStrategySheetTooltipClsName)('derived-values') }, derivedValues.map((derivedValue, i) => { | ||
var _a; | ||
const isUnchanged = (0, s2_1.isUnchangedValue)(derivedValue, value); | ||
@@ -58,4 +60,3 @@ const isUp = !isUnchanged && (0, s2_1.isUpDataValue)(derivedValue); | ||
}) }, | ||
!isUnchanged && (react_1.default.createElement("span", { className: "derived-value-trend-icon" })), | ||
renderDerivedValue?.(derivedValue, originalDerivedValue, cell) ?? (react_1.default.createElement("span", { className: "derived-value-content" }, derivedValue ?? emptyPlaceholder))))); | ||
!isUnchanged && (react_1.default.createElement("span", { className: "derived-value-trend-icon" })), (_a = renderDerivedValue === null || renderDerivedValue === void 0 ? void 0 : renderDerivedValue(derivedValue, originalDerivedValue, cell)) !== null && _a !== void 0 ? _a : (react_1.default.createElement("span", { className: "derived-value-content" }, derivedValue !== null && derivedValue !== void 0 ? derivedValue : emptyPlaceholder))))); | ||
})))), | ||
@@ -62,0 +63,0 @@ rowDescription && (react_1.default.createElement("div", { className: (0, s2_1.getStrategySheetTooltipClsName)('description') }, |
@@ -13,4 +13,4 @@ "use strict"; | ||
const customLabel = (0, lodash_1.isFunction)(label) ? label(cell, value) : label; | ||
const rowName = customLabel ?? value; | ||
const description = spreadsheet.dataSet.getFieldDescription(field) || extra?.['description']; | ||
const rowName = customLabel !== null && customLabel !== void 0 ? customLabel : value; | ||
const description = spreadsheet.dataSet.getFieldDescription(field) || (extra === null || extra === void 0 ? void 0 : extra['description']); | ||
return (react_1.default.createElement("div", { className: (0, classnames_1.default)((0, s2_1.getStrategySheetTooltipClsName)(), (0, s2_1.getStrategySheetTooltipClsName)('row')) }, | ||
@@ -17,0 +17,0 @@ react_1.default.createElement("div", { className: (0, s2_1.getStrategySheetTooltipClsName)('value') }, rowName), |
@@ -21,4 +21,5 @@ "use strict"; | ||
exports.StrategySheet = react_1.default.memo((props) => { | ||
const { options, themeCfg, dataCfg, ...restProps } = props; | ||
const { options, themeCfg, dataCfg } = props, restProps = tslib_1.__rest(props, ["options", "themeCfg", "dataCfg"]); | ||
const strategySheetOptions = react_1.default.useMemo(() => { | ||
var _a; | ||
if ((0, lodash_1.isEmpty)(dataCfg)) { | ||
@@ -28,3 +29,3 @@ return null; | ||
// 单指标非自定义树结构隐藏指标列 | ||
const shouldHideValue = (0, lodash_1.size)(dataCfg?.fields?.values) === 1; | ||
const shouldHideValue = (0, lodash_1.size)((_a = dataCfg === null || dataCfg === void 0 ? void 0 : dataCfg.fields) === null || _a === void 0 ? void 0 : _a.values) === 1; | ||
return { | ||
@@ -66,5 +67,5 @@ hierarchyType: 'tree', | ||
const s2Options = react_1.default.useMemo(() => (0, s2_1.customMerge)(strategySheetOptions, options), [options, strategySheetOptions]); | ||
return (react_1.default.createElement(base_sheet_1.BaseSheet, { options: s2Options, themeCfg: themeCfg, dataCfg: dataCfg, ...restProps })); | ||
return (react_1.default.createElement(base_sheet_1.BaseSheet, Object.assign({ options: s2Options, themeCfg: themeCfg, dataCfg: dataCfg }, restProps))); | ||
}); | ||
exports.StrategySheet.displayName = 'StrategySheet'; | ||
//# sourceMappingURL=index.js.map |
@@ -8,5 +8,5 @@ "use strict"; | ||
exports.TableSheet = react_1.default.memo((props) => { | ||
return react_1.default.createElement(base_sheet_1.BaseSheet, { ...props }); | ||
return react_1.default.createElement(base_sheet_1.BaseSheet, Object.assign({}, props)); | ||
}); | ||
exports.TableSheet.displayName = 'TableSheet'; | ||
//# sourceMappingURL=index.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
const { list = [] } = props; | ||
return (react_1.default.createElement("div", { className: `${s2_1.TOOLTIP_PREFIX_CLS}-detail-list` }, list?.map((listItem, idx) => { | ||
return (react_1.default.createElement("div", { className: `${s2_1.TOOLTIP_PREFIX_CLS}-detail-list` }, list === null || list === void 0 ? void 0 : list.map((listItem, idx) => { | ||
const { name, value, icon } = listItem; | ||
@@ -13,0 +13,0 @@ return (react_1.default.createElement("div", { key: `${value}-${idx}`, className: `${s2_1.TOOLTIP_PREFIX_CLS}-detail-item` }, |
@@ -8,9 +8,10 @@ "use strict"; | ||
exports.TooltipHead = react_1.default.memo((props) => { | ||
var _a, _b; | ||
const { rows = [], cols = [] } = props; | ||
return (react_1.default.createElement("div", { className: `${s2_1.TOOLTIP_PREFIX_CLS}-head-info-list` }, | ||
cols.map((item) => item.value)?.join('/'), | ||
cols.length > 0 && rows.length > 0 && (0, s2_1.i18n)(','), | ||
rows.map((item) => item.value)?.join('/'))); | ||
return (react_1.default.createElement("div", { className: `${s2_1.TOOLTIP_PREFIX_CLS}-head-info-list` }, (_a = cols.map((item) => item.value)) === null || _a === void 0 ? void 0 : | ||
_a.join('/'), | ||
cols.length > 0 && rows.length > 0 && (0, s2_1.i18n)(','), (_b = rows.map((item) => item.value)) === null || _b === void 0 ? void 0 : | ||
_b.join('/'))); | ||
}); | ||
exports.TooltipHead.displayName = 'TooltipHead'; | ||
//# sourceMappingURL=head-info.js.map |
@@ -10,3 +10,3 @@ "use strict"; | ||
exports.TooltipIcon = react_1.default.memo((props) => { | ||
const { icon, ...attrs } = props; | ||
const { icon } = props, attrs = tslib_1.__rest(props, ["icon"]); | ||
if (!icon) { | ||
@@ -17,7 +17,7 @@ return null; | ||
const name = icon; | ||
return react_1.default.createElement(icons_1.HtmlIcon, { name: name, ...attrs }); | ||
return react_1.default.createElement(icons_1.HtmlIcon, Object.assign({ name: name }, attrs)); | ||
} | ||
return react_1.default.createElement(react_element_1.ReactElement, { content: icon, ...attrs }); | ||
return react_1.default.createElement(react_element_1.ReactElement, Object.assign({ content: icon }, attrs)); | ||
}); | ||
exports.TooltipIcon.displayName = 'TooltipIcon'; | ||
//# sourceMappingURL=icon.js.map |
@@ -11,3 +11,3 @@ "use strict"; | ||
const TooltipOperator = (props) => { | ||
const { onlyShowOperator, cell, menu: { items: menus = [], onClick, selectedKeys = [], render, ...otherMenuProps }, } = props; | ||
const { onlyShowOperator, cell } = props, _a = props.menu, { items: menus = [], onClick, selectedKeys = [], render } = _a, otherMenuProps = tslib_1.__rest(_a, ["items", "onClick", "selectedKeys", "render"]); | ||
if ((0, lodash_1.isEmpty)(menus)) { | ||
@@ -17,5 +17,6 @@ return null; | ||
const onMenuClick = (info) => { | ||
var _a; | ||
const currentMenu = menus.find((menu) => menu.key === info.key); | ||
onClick?.(info, cell); | ||
currentMenu?.onClick?.(info, cell); | ||
onClick === null || onClick === void 0 ? void 0 : onClick(info, cell); | ||
(_a = currentMenu === null || currentMenu === void 0 ? void 0 : currentMenu.onClick) === null || _a === void 0 ? void 0 : _a.call(currentMenu, info, cell); | ||
}; | ||
@@ -31,4 +32,4 @@ const renderMenu = (menu) => { | ||
onTitleClick: (info) => { | ||
onTitleClick?.(info, cell); | ||
onClick?.(info, cell); | ||
onTitleClick === null || onTitleClick === void 0 ? void 0 : onTitleClick(info, cell); | ||
onClick === null || onClick === void 0 ? void 0 : onClick(info, cell); | ||
}, | ||
@@ -40,10 +41,4 @@ children: !(0, lodash_1.isEmpty)(subMenus) ? subMenus : undefined, | ||
const items = (0, lodash_1.map)(menus, renderMenu); | ||
return render?.({ | ||
mode: onlyShowOperator ? 'vertical' : 'horizontal', | ||
selectable: onlyShowOperator, | ||
onClick: onMenuClick, | ||
items, | ||
selectedKeys, | ||
...otherMenuProps, | ||
}); | ||
return render === null || render === void 0 ? void 0 : render(Object.assign({ mode: onlyShowOperator ? 'vertical' : 'horizontal', selectable: onlyShowOperator, onClick: onMenuClick, items, | ||
selectedKeys }, otherMenuProps)); | ||
}; | ||
@@ -50,0 +45,0 @@ return (react_1.default.createElement("div", { className: `${s2_1.TOOLTIP_PREFIX_CLS}-operator` }, renderMenus())); |
@@ -11,7 +11,8 @@ "use strict"; | ||
exports.TooltipSummary = react_1.default.memo((props) => { | ||
var _a; | ||
const { summaries = [] } = props; | ||
const s2 = (0, SpreadSheetContext_1.useSpreadSheetInstance)(); | ||
const isMobileDevice = (0, s2_1.isMobile)(s2?.options?.device); | ||
const isMobileDevice = (0, s2_1.isMobile)((_a = s2 === null || s2 === void 0 ? void 0 : s2.options) === null || _a === void 0 ? void 0 : _a.device); | ||
const renderSelected = () => { | ||
const count = (0, lodash_1.sumBy)(summaries, (item) => (0, lodash_1.size)(item?.selectedData)); | ||
const count = (0, lodash_1.sumBy)(summaries, (item) => (0, lodash_1.size)(item === null || item === void 0 ? void 0 : item.selectedData)); | ||
return (react_1.default.createElement("div", { className: `${s2_1.TOOLTIP_PREFIX_CLS}-summary-item`, style: isMobileDevice ? { marginBottom: '6px' } : {} }, | ||
@@ -24,3 +25,3 @@ react_1.default.createElement("span", { className: `${s2_1.TOOLTIP_PREFIX_CLS}-selected` }, | ||
}; | ||
const renderSummary = () => summaries?.map((item) => { | ||
const renderSummary = () => summaries === null || summaries === void 0 ? void 0 : summaries.map((item) => { | ||
const { name = '', value } = item || {}; | ||
@@ -34,3 +35,3 @@ if (!name && !value) { | ||
(0, s2_1.i18n)('总和'))) : (react_1.default.createElement("span", { className: `${s2_1.TOOLTIP_PREFIX_CLS}-summary-key` }, "\u00A0")), | ||
react_1.default.createElement("span", { className: (0, classnames_1.default)(`${s2_1.TOOLTIP_PREFIX_CLS}-summary-val`, `${s2_1.TOOLTIP_PREFIX_CLS}-bold`) }, value ?? '-'))); | ||
react_1.default.createElement("span", { className: (0, classnames_1.default)(`${s2_1.TOOLTIP_PREFIX_CLS}-summary-val`, `${s2_1.TOOLTIP_PREFIX_CLS}-bold`) }, value !== null && value !== void 0 ? value : '-'))); | ||
}); | ||
@@ -37,0 +38,0 @@ return (react_1.default.createElement("div", { className: `${s2_1.TOOLTIP_PREFIX_CLS}-summary` }, |
@@ -22,5 +22,7 @@ "use strict"; | ||
isMobileDevice() { | ||
return (0, s2_1.isMobile)(this.spreadsheet.options?.device); | ||
var _a; | ||
return (0, s2_1.isMobile)((_a = this.spreadsheet.options) === null || _a === void 0 ? void 0 : _a.device); | ||
} | ||
renderContent() { | ||
var _a, _b, _c; | ||
// 配置级 s2.options.tooltip.content = '' | ||
@@ -30,21 +32,17 @@ const { content: contentFromOptions, operation } = this.spreadsheet.options.tooltip; | ||
const showOptions = this.options; | ||
const cell = this.spreadsheet.getCell(showOptions?.event?.target); | ||
const cell = this.spreadsheet.getCell((_a = showOptions === null || showOptions === void 0 ? void 0 : showOptions.event) === null || _a === void 0 ? void 0 : _a.target); | ||
// 优先级: 方法级 > 配置级, 兼容 content 为空字符串的场景 | ||
const content = (showOptions?.content ?? | ||
contentFromOptions); | ||
const content = ((_b = showOptions === null || showOptions === void 0 ? void 0 : showOptions.content) !== null && _b !== void 0 ? _b : contentFromOptions); | ||
const tooltipProps = (0, s2_1.customMerge)({ | ||
options: { | ||
operator: { | ||
menu: (0, lodash_1.omit)(operation?.menu, 'items'), | ||
menu: (0, lodash_1.omit)(operation === null || operation === void 0 ? void 0 : operation.menu, 'items'), | ||
}, | ||
}, | ||
}, { | ||
...showOptions, | ||
cell, | ||
content, | ||
}); | ||
if (showOptions?.options?.forceRender) { | ||
}, Object.assign(Object.assign({}, showOptions), { cell, | ||
content })); | ||
if ((_c = showOptions === null || showOptions === void 0 ? void 0 : showOptions.options) === null || _c === void 0 ? void 0 : _c.forceRender) { | ||
this.forceClearContent(); | ||
} | ||
const TooltipContent = (react_1.default.createElement(index_1.TooltipComponent, { ...tooltipProps, content: content })); | ||
const TooltipContent = (react_1.default.createElement(index_1.TooltipComponent, Object.assign({}, tooltipProps, { content: content }))); | ||
(0, reactRender_1.reactRender)(TooltipContent, this.container); | ||
@@ -51,0 +49,0 @@ } |
@@ -23,3 +23,3 @@ "use strict"; | ||
} | ||
return (react_1.default.createElement(operator_1.TooltipOperator, { ...operator, menu: operator.menu, onlyShowOperator: onlyShowOperator, cell: cell })); | ||
return (react_1.default.createElement(operator_1.TooltipOperator, Object.assign({}, operator, { menu: operator.menu, onlyShowOperator: onlyShowOperator, cell: cell }))); | ||
}; | ||
@@ -37,3 +37,3 @@ const renderNameTips = (nameTip) => { | ||
const renderInfos = (infos) => infos && react_1.default.createElement(infos_1.TooltipInfos, { infos: infos }); | ||
const renderInterpretation = (interpretation) => interpretation && react_1.default.createElement(interpretation_1.TooltipInterpretation, { ...interpretation }); | ||
const renderInterpretation = (interpretation) => interpretation && react_1.default.createElement(interpretation_1.TooltipInterpretation, Object.assign({}, interpretation)); | ||
const renderDescription = (description) => (react_1.default.createElement(description_1.TooltipDescription, { description: description })); | ||
@@ -56,4 +56,3 @@ const renderContent = () => { | ||
return (react_1.default.createElement("span", { ref: onMounted }, | ||
renderOperation(operator), | ||
content ?? DefaultContent)); | ||
renderOperation(operator), content !== null && content !== void 0 ? content : DefaultContent)); | ||
}; | ||
@@ -60,0 +59,0 @@ return renderContent(); |
@@ -11,7 +11,7 @@ "use strict"; | ||
const handlerFn = (event) => { | ||
handler?.((0, s2_1.getBaseCellData)(event, s2)); | ||
handler === null || handler === void 0 ? void 0 : handler((0, s2_1.getBaseCellData)(event, s2)); | ||
}; | ||
s2?.on(eventName, handlerFn); | ||
s2 === null || s2 === void 0 ? void 0 : s2.on(eventName, handlerFn); | ||
return () => { | ||
s2?.off(eventName, handlerFn); | ||
s2 === null || s2 === void 0 ? void 0 : s2.off(eventName, handlerFn); | ||
}; | ||
@@ -24,10 +24,10 @@ }, [s2, handler, eventName]); | ||
const handlerFn = (...args) => { | ||
handler?.(...args); | ||
handler === null || handler === void 0 ? void 0 : handler(...args); | ||
}; | ||
s2?.on(eventName, handlerFn); | ||
s2 === null || s2 === void 0 ? void 0 : s2.on(eventName, handlerFn); | ||
return () => { | ||
if (emitBeforeOff) { | ||
s2?.emit(eventName); | ||
s2 === null || s2 === void 0 ? void 0 : s2.emit(eventName); | ||
} | ||
s2?.off(eventName, handlerFn); | ||
s2 === null || s2 === void 0 ? void 0 : s2.off(eventName, handlerFn); | ||
}; | ||
@@ -34,0 +34,0 @@ }, [s2, handler, eventName]); |
@@ -8,8 +8,8 @@ "use strict"; | ||
const useLoading = (s2, loadingFromProps) => { | ||
const [loading, setLoading] = react_1.default.useState(loadingFromProps ?? false); | ||
const [loading, setLoading] = react_1.default.useState(loadingFromProps !== null && loadingFromProps !== void 0 ? loadingFromProps : false); | ||
react_1.default.useEffect(() => { | ||
s2?.on(s2_1.S2Event.LAYOUT_BEFORE_RENDER, () => { | ||
s2 === null || s2 === void 0 ? void 0 : s2.on(s2_1.S2Event.LAYOUT_BEFORE_RENDER, () => { | ||
setLoading(true); | ||
}); | ||
s2?.on(s2_1.S2Event.LAYOUT_AFTER_RENDER, () => { | ||
s2 === null || s2 === void 0 ? void 0 : s2.on(s2_1.S2Event.LAYOUT_AFTER_RENDER, () => { | ||
setLoading(false); | ||
@@ -19,3 +19,3 @@ }); | ||
return { | ||
loading: loadingFromProps ?? loading, | ||
loading: loadingFromProps !== null && loadingFromProps !== void 0 ? loadingFromProps : loading, | ||
setLoading, | ||
@@ -22,0 +22,0 @@ }; |
@@ -15,17 +15,18 @@ "use strict"; | ||
const usePagination = (s2, options) => { | ||
const defaultPagination = options?.pagination; | ||
var _a; | ||
const defaultPagination = options === null || options === void 0 ? void 0 : options.pagination; | ||
const [pagination, setPagination] = react_1.default.useState({ | ||
total: s2?.facet?.viewCellHeights.getTotalLength() || 0, | ||
current: defaultPagination?.current || DEFAULT_PAGE_NUMBER, | ||
pageSize: defaultPagination?.pageSize || DEFAULT_PAGE_SIZE, | ||
total: ((_a = s2 === null || s2 === void 0 ? void 0 : s2.facet) === null || _a === void 0 ? void 0 : _a.viewCellHeights.getTotalLength()) || 0, | ||
current: (defaultPagination === null || defaultPagination === void 0 ? void 0 : defaultPagination.current) || DEFAULT_PAGE_NUMBER, | ||
pageSize: (defaultPagination === null || defaultPagination === void 0 ? void 0 : defaultPagination.pageSize) || DEFAULT_PAGE_SIZE, | ||
}); | ||
const onShowSizeChange = (current, pageSize) => { | ||
setPagination({ ...pagination, current, pageSize }); | ||
setPagination(Object.assign(Object.assign({}, pagination), { current, pageSize })); | ||
}; | ||
const onChange = (current, pageSize) => { | ||
setPagination({ ...pagination, current, pageSize }); | ||
setPagination(Object.assign(Object.assign({}, pagination), { current, pageSize })); | ||
}; | ||
// sync state.pagination -> s2.pagination | ||
(0, ahooks_1.useUpdateEffect)(() => { | ||
const render = async () => { | ||
const render = () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
if (!s2 || (0, lodash_1.isEmpty)(defaultPagination)) { | ||
@@ -38,4 +39,4 @@ return; | ||
}); | ||
await s2.render(false); | ||
}; | ||
yield s2.render(false); | ||
}); | ||
render(); | ||
@@ -46,6 +47,7 @@ // eslint-disable-next-line react-hooks/exhaustive-deps | ||
(0, ahooks_1.useUpdateEffect)(() => { | ||
var _a; | ||
setPagination({ | ||
total: s2?.facet?.viewCellHeights.getTotalLength() || 0, | ||
current: defaultPagination?.current || DEFAULT_PAGE_NUMBER, | ||
pageSize: defaultPagination?.pageSize || DEFAULT_PAGE_SIZE, | ||
total: ((_a = s2 === null || s2 === void 0 ? void 0 : s2.facet) === null || _a === void 0 ? void 0 : _a.viewCellHeights.getTotalLength()) || 0, | ||
current: (defaultPagination === null || defaultPagination === void 0 ? void 0 : defaultPagination.current) || DEFAULT_PAGE_NUMBER, | ||
pageSize: (defaultPagination === null || defaultPagination === void 0 ? void 0 : defaultPagination.pageSize) || DEFAULT_PAGE_SIZE, | ||
}); | ||
@@ -60,3 +62,3 @@ }, [defaultPagination, s2]); | ||
setPagination((prev) => { | ||
return { ...prev, total: data.total }; | ||
return Object.assign(Object.assign({}, prev), { total: data.total }); | ||
}); | ||
@@ -69,10 +71,6 @@ }; | ||
}, [defaultPagination, s2]); | ||
return { | ||
...defaultPagination, | ||
...pagination, | ||
onShowSizeChange, | ||
onChange, | ||
}; | ||
return Object.assign(Object.assign(Object.assign({}, defaultPagination), pagination), { onShowSizeChange, | ||
onChange }); | ||
}; | ||
exports.usePagination = usePagination; | ||
//# sourceMappingURL=usePagination.js.map |
@@ -25,3 +25,3 @@ "use strict"; | ||
} | ||
catch { | ||
catch (_a) { | ||
return false; | ||
@@ -49,7 +49,8 @@ } | ||
}, [sheetType, options, dataCfg, customSpreadSheet]); | ||
const buildSpreadSheet = react_1.default.useCallback(async () => { | ||
const buildSpreadSheet = react_1.default.useCallback(() => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
var _a; | ||
setLoading(true); | ||
const s2 = renderSpreadSheet(containerRef.current); | ||
s2.setThemeCfg(props.themeCfg); | ||
await s2.render(); | ||
yield s2.render(); | ||
setLoading(false); | ||
@@ -62,7 +63,7 @@ s2Ref.current = s2; | ||
forceUpdate(); | ||
props.onMounted?.(s2Ref.current); | ||
}, [props, renderSpreadSheet, setLoading, forceUpdate]); | ||
(_a = props.onMounted) === null || _a === void 0 ? void 0 : _a.call(props, s2Ref.current); | ||
}), [props, renderSpreadSheet, setLoading, forceUpdate]); | ||
// 适用于监听 loading 状态, 组件外部使用 <Spin /> 等场景 | ||
react_1.default.useEffect(() => { | ||
onLoading?.(loading); | ||
onLoading === null || onLoading === void 0 ? void 0 : onLoading(loading); | ||
}, [loading]); | ||
@@ -77,4 +78,5 @@ react_1.default.useEffect(() => { | ||
return () => { | ||
var _a, _b; | ||
setLoading(false); | ||
s2Ref.current?.destroy?.(); | ||
(_b = (_a = s2Ref.current) === null || _a === void 0 ? void 0 : _a.destroy) === null || _b === void 0 ? void 0 : _b.call(_a); | ||
}; | ||
@@ -84,3 +86,4 @@ }, [isDevMode]); | ||
(0, ahooks_1.useUpdateEffect)(() => { | ||
const render = async () => { | ||
const render = () => tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; | ||
setLoading(true); | ||
@@ -94,23 +97,23 @@ const [prevDataCfg, prevOptions, prevThemeCfg] = updatePrevDepsRef.current; | ||
// 列头变化需要重新计算初始叶子节点 | ||
if (prevDataCfg?.fields?.columns?.length !== | ||
dataCfg?.fields?.columns?.length) { | ||
s2Ref.current?.facet?.clearInitColLeafNodes(); | ||
if (((_b = (_a = prevDataCfg === null || prevDataCfg === void 0 ? void 0 : prevDataCfg.fields) === null || _a === void 0 ? void 0 : _a.columns) === null || _b === void 0 ? void 0 : _b.length) !== | ||
((_d = (_c = dataCfg === null || dataCfg === void 0 ? void 0 : dataCfg.fields) === null || _c === void 0 ? void 0 : _c.columns) === null || _d === void 0 ? void 0 : _d.length)) { | ||
(_f = (_e = s2Ref.current) === null || _e === void 0 ? void 0 : _e.facet) === null || _f === void 0 ? void 0 : _f.clearInitColLeafNodes(); | ||
} | ||
reloadData = true; | ||
rerender = true; | ||
s2Ref.current?.setDataCfg(dataCfg); | ||
(_g = s2Ref.current) === null || _g === void 0 ? void 0 : _g.setDataCfg(dataCfg); | ||
} | ||
if (!(0, lodash_1.isEqual)(prevOptions, options)) { | ||
if (prevOptions?.hierarchyType !== options?.hierarchyType) { | ||
if ((prevOptions === null || prevOptions === void 0 ? void 0 : prevOptions.hierarchyType) !== (options === null || options === void 0 ? void 0 : options.hierarchyType)) { | ||
rebuildDataSet = true; | ||
reloadData = true; | ||
s2Ref.current?.setDataCfg(dataCfg); | ||
(_h = s2Ref.current) === null || _h === void 0 ? void 0 : _h.setDataCfg(dataCfg); | ||
} | ||
rerender = true; | ||
s2Ref.current?.setOptions(options); | ||
s2Ref.current?.changeSheetSize(options.width, options.height); | ||
(_j = s2Ref.current) === null || _j === void 0 ? void 0 : _j.setOptions(options); | ||
(_k = s2Ref.current) === null || _k === void 0 ? void 0 : _k.changeSheetSize(options.width, options.height); | ||
} | ||
if (!(0, lodash_1.isEqual)(prevThemeCfg, themeCfg)) { | ||
rerender = true; | ||
s2Ref.current?.setThemeCfg(themeCfg); | ||
(_l = s2Ref.current) === null || _l === void 0 ? void 0 : _l.setThemeCfg(themeCfg); | ||
} | ||
@@ -129,7 +132,7 @@ if (!rerender) { | ||
}; | ||
const renderOptions = onUpdate?.(defaultRenderOptions) || defaultRenderOptions; | ||
await s2Ref.current?.render(renderOptions); | ||
const renderOptions = (onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(defaultRenderOptions)) || defaultRenderOptions; | ||
yield ((_m = s2Ref.current) === null || _m === void 0 ? void 0 : _m.render(renderOptions)); | ||
setLoading(false); | ||
onUpdateAfterRender?.(renderOptions); | ||
}; | ||
onUpdateAfterRender === null || onUpdateAfterRender === void 0 ? void 0 : onUpdateAfterRender(renderOptions); | ||
}); | ||
render(); | ||
@@ -136,0 +139,0 @@ }, [dataCfg, options, themeCfg, onUpdate]); |
import './utils/extendLocale'; | ||
export * from './components'; | ||
export declare const version = "@antv/s2-react-v2.1.2"; | ||
export declare const version = "@antv/s2-react-v2.1.3"; |
@@ -7,3 +7,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./components"), exports); | ||
exports.version = '@antv/s2-react-v2.1.2'; | ||
exports.version = '@antv/s2-react-v2.1.3'; | ||
//# sourceMappingURL=index.js.map |
@@ -12,5 +12,3 @@ "use strict"; | ||
exports.S2_REACT_ROOT_SYMBOL_ID = `__s2_react_root__`; | ||
const ReactDOMClone = { | ||
...ReactDOM, | ||
}; | ||
const ReactDOMClone = Object.assign({}, ReactDOM); | ||
const { render: reactOriginalRender, unmountComponentAtNode } = ReactDOMClone; | ||
@@ -67,4 +65,5 @@ let createRoot; | ||
return Promise.resolve().then(() => { | ||
container?.[exports.S2_REACT_ROOT_SYMBOL_ID]?.unmount(); | ||
delete container?.[exports.S2_REACT_ROOT_SYMBOL_ID]; | ||
var _a; | ||
(_a = container === null || container === void 0 ? void 0 : container[exports.S2_REACT_ROOT_SYMBOL_ID]) === null || _a === void 0 ? void 0 : _a.unmount(); | ||
container === null || container === void 0 ? true : delete container[exports.S2_REACT_ROOT_SYMBOL_ID]; | ||
}); | ||
@@ -71,0 +70,0 @@ } |
{ | ||
"name": "@antv/s2-react", | ||
"version": "2.1.2", | ||
"version": "2.1.3", | ||
"private": false, | ||
@@ -49,5 +49,5 @@ "description": "use S2 with react", | ||
"start": "cross-env PLAYGROUND=true vite", | ||
"test": "jest --passWithNoTests", | ||
"test:ci": "pnpm test -- --maxWorkers=3", | ||
"test:ci-coverage": "pnpm test:coverage --maxWorkers=3", | ||
"test": "jest --passWithNoTests --detectOpenHandles", | ||
"test:ci": "pnpm test", | ||
"test:ci-coverage": "pnpm test:coverage", | ||
"test:coverage": "pnpm test -- --coverage", | ||
@@ -54,0 +54,0 @@ "test:live": "node ./scripts/test-live.mjs", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1392043
1.42%5147
-0.39%