From eb79e54be24c3de42016aed0385c5c662eaa44fd Mon Sep 17 00:00:00 2001 From: yunji Date: Sun, 1 Dec 2024 17:18:31 +0800 Subject: [PATCH] fix: ssr render err for map --- .fatherrc.ts | 2 +- package.json | 4 ++++ src/export-map.browser.ts | 5 +++++ src/export-map.ts | 18 ++++++++++++++++++ src/export.ts | 16 ++++++++++------ 5 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 src/export-map.browser.ts create mode 100644 src/export-map.ts diff --git a/.fatherrc.ts b/.fatherrc.ts index e983fef..0b9d896 100644 --- a/.fatherrc.ts +++ b/.fatherrc.ts @@ -17,7 +17,7 @@ export default defineConfig({ }, platform: 'browser', targets: { - chrome: 51, + chrome: 80, }, externals: { lodash: '_', diff --git a/package.json b/package.json index 667b0d6..34a6396 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,10 @@ "typings": "dist/esm/index.d.ts", "jsdelivr": "dist/umd/index.min.js", "unpkg": "dist/umd/index.min.js", + "browser": { + "./src/export-map.ts": "./src/export-map.browser.ts", + "./dist/esm/export-map.js": "./dist/esm/export-map.browser.js" + }, "files": [ "dist", "README.md", diff --git a/src/export-map.browser.ts b/src/export-map.browser.ts new file mode 100644 index 0000000..a105ece --- /dev/null +++ b/src/export-map.browser.ts @@ -0,0 +1,5 @@ +// organize-imports-ignore +export { default as Map, type MapProps } from './Map'; +export { default as PinMap, type PinMapProps } from './PinMap'; +export { default as HeatMap, type HeatMapProps } from './HeatMap'; +export { default as PathMap, type PathMapProps } from './PathMap'; diff --git a/src/export-map.ts b/src/export-map.ts new file mode 100644 index 0000000..8da4e75 --- /dev/null +++ b/src/export-map.ts @@ -0,0 +1,18 @@ +// Map Components mock for use in environments without `document` / `window`, like ssr pre render +import type { FC } from 'react'; + +function MockMap() { + return null; +} + +import { type HeatMapProps } from './HeatMap'; +import { type MapProps } from './Map'; +import { type PathMapProps } from './PathMap'; +import { type PinMapProps } from './PinMap'; + +export const Map: FC = MockMap; +export const HeatMap: FC = MockMap; +export const PathMap: FC = MockMap; +export const PinMap: FC = MockMap; + +export type { HeatMapProps, MapProps, PathMapProps, PinMapProps }; diff --git a/src/export.ts b/src/export.ts index bacf3a0..f137f95 100644 --- a/src/export.ts +++ b/src/export.ts @@ -1,3 +1,4 @@ +// organize-imports-ignore import { ChartType } from './types'; /********** plot chart **********/ @@ -5,7 +6,6 @@ import { default as Area, type AreaProps } from './Area'; import { default as Bar, type BarProps } from './Bar'; import { default as Column, type ColumnProps } from './Column'; import { default as DualAxes, type DualAxesProps } from './DualAxes'; -import { default as HeatMap, type HeatMapProps } from './HeatMap'; import { default as Histogram, type HistogramProps } from './Histogram'; import { default as Line, type LineProps } from './Line'; import { default as Pie, type PieProps } from './Pie'; @@ -20,12 +20,18 @@ import { default as FlowDiagram, type FlowDiagramProps } from './FlowDiagram'; import { default as MindMap, type MindMapProps } from './MindMap'; import { default as NetworkGraph, type NetworkGraphProps } from './NetworkGraph'; export { default as IndentedTree, type IndentedTreeProps } from './IndentedTree'; -export { default as Map, type MapProps } from './Map'; export { default as OrganizationChart, type OrganizationChartProps } from './OrganizationChart'; /********** map chart **********/ -import { default as PathMap, type PathMapProps } from './PathMap'; -import { default as PinMap, type PinMapProps } from './PinMap'; +export { Map, type MapProps } from './export-map'; +import { + PinMap, + type PinMapProps, + HeatMap, + type HeatMapProps, + PathMap, + type PathMapProps, +} from './export-map'; /********** NTV **********/ export { VisText, type VisTextProps } from './Text'; @@ -77,10 +83,8 @@ export const DEFAULT_CHART_COMPONENTS: Record> = { [ChartType.Area]: Area, [ChartType.Scatter]: Scatter, [ChartType.PinMap]: PinMap, - [ChartType.PathMap]: PathMap, [ChartType.HeatMap]: HeatMap, [ChartType.MindMap]: MindMap, [ChartType.FlowDiagram]: FlowDiagram, [ChartType.NetworkGraph]: NetworkGraph, - [ChartType.FishboneDiagram]: FishboneDiagram, };