Skip to content

Commit 92ad49d

Browse files
committed
feat(platform): add Marker. MarkerCluster and InfoWindow
1 parent 2c0d85b commit 92ad49d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+914
-315
lines changed

packages/hooks/src/useForkRef.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { isFunction, isObject } from 'lodash';
22
import { useCallback } from 'react';
33

4-
export function setRef(ref: any, value: any): void {
4+
function setRef(ref: any, value: any): void {
55
if (isFunction(ref)) {
66
ref(value);
77
} else if (isObject(ref) && 'current' in ref) {

packages/icons/src/CustomIcon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import type { DIconBaseProps } from './useIconDefinition';
22

33
import React from 'react';
44

5+
import { useIconProps } from './hooks';
56
import { useIconDefinition } from './useIconDefinition';
6-
import { useIconProps } from './useIconProps';
77

88
export type DCustomIconeProps = DIconBaseProps;
99

packages/icons/src/Icon.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { DIconBaseProps } from './useIconDefinition';
22
import type { AbstractNode, IconDefinition } from '@ant-design/icons-svg/es/types';
33

4-
import React, { useContext } from 'react';
4+
import React from 'react';
55

6+
import { useIconContext, useIconProps } from './hooks';
67
import { useIconDefinition } from './useIconDefinition';
7-
import { useIconProps } from './useIconProps';
88

99
interface DRenderIconOptions {
1010
placeholders: {
@@ -33,16 +33,10 @@ function renderAbstractNode(node: AbstractNode, options: DRenderIconOptions): JS
3333

3434
export interface DIconContextData {
3535
props?: Omit<DIconProps, 'dIcon'>;
36-
namespace: string;
37-
twoToneColor: (theme?: DIconProps['dTheme']) => [string, string];
36+
className: (theme: DIconProps['dTheme']) => string;
37+
twoToneColor: (theme: DIconProps['dTheme']) => [string, string];
3838
}
39-
export const DIconContext = React.createContext<DIconContextData>({
40-
namespace: 'd',
41-
twoToneColor: (theme) => [
42-
theme ? `var(--d-color-${theme})` : `var(--d-text-color)`,
43-
theme ? `var(--d-background-color-${theme})` : `rgb(var(--d-text-color-rgb) / 10%)`,
44-
],
45-
});
39+
export const DIconContext = React.createContext<DIconContextData | null>(null);
4640

4741
export interface DIconProps extends Omit<DIconBaseProps, 'children'> {
4842
dTwoToneColor?: [string, string];
@@ -58,7 +52,9 @@ function Icon(props: DIconProps, ref: React.ForwardedRef<SVGSVGElement>): JSX.El
5852
...restProps
5953
} = useIconProps(props);
6054

61-
const twoToneColorByTheme = useContext(DIconContext).twoToneColor;
55+
const context = useIconContext();
56+
57+
const twoToneColorByTheme = context.twoToneColor;
6258
const twoToneColor = dTwoToneColor ?? twoToneColorByTheme(dTheme);
6359

6460
const svgProps = useIconDefinition({ ...restProps, dTheme });

packages/icons/src/useIconProps.ts renamed to packages/icons/src/hooks.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
import { isUndefined } from 'lodash';
1+
import type { DIconContextData } from './Icon';
2+
3+
import { isNull, isUndefined } from 'lodash';
24
import { useContext } from 'react';
35

46
import { DIconContext } from './Icon';
57

6-
export function useIconProps<T extends object>(props: T): T {
8+
export function useIconContext(): DIconContextData {
79
const context = useContext(DIconContext);
10+
if (isNull(context)) {
11+
throw new Error('Please provide `DIconContext`!');
12+
}
13+
14+
return context;
15+
}
16+
17+
export function useIconProps<T extends object>(props: T): T {
18+
const context = useIconContext();
19+
820
const gProps = context.props ?? {};
921
const noUndefinedProps: any = {};
1022
Object.keys(props).forEach((key) => {

packages/icons/src/useIconDefinition.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { isUndefined, isNumber, isArray } from 'lodash';
2-
import { useContext } from 'react';
32

43
import { getClassName } from '@react-devui/utils';
54

6-
import { DIconContext } from './Icon';
5+
import { useIconContext } from './hooks';
76

87
export interface DIconBaseProps extends React.SVGAttributes<SVGElement> {
98
dSize?: number | string | [number | string, number | string];
@@ -24,15 +23,13 @@ export function useIconDefinition(props: DIconBaseProps) {
2423
...restProps
2524
} = props;
2625

27-
const prefix = `${useContext(DIconContext).namespace}-`;
26+
const context = useIconContext();
2827

2928
const [width, height] = isArray(dSize) ? dSize : [dSize, dSize];
3029

3130
const svgProps: React.SVGAttributes<SVGElement> = {
3231
...restProps,
33-
className: getClassName(restProps.className, `${prefix}icon`, {
34-
[`t-${dTheme}`]: dTheme,
35-
}),
32+
className: getClassName(restProps.className, context.className(dTheme)),
3633
style: {
3734
...restProps.style,
3835
transform: isUndefined(dRotate) ? undefined : `rotate(${dRotate}deg)`,

packages/platform/src/app/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { UserState } from '../config/state';
1+
import type { UserState } from '../core/state';
22
import type { DRootProps } from '@react-devui/ui';
33
import type { DLang } from '@react-devui/ui/utils/types';
44

packages/platform/src/app/Routes.guard.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { isNull, isObject } from 'lodash';
44
import { Navigate, useLocation } from 'react-router-dom';
55

66
import { LOGIN_PATH, PREV_ROUTE_KEY } from '../config/other';
7-
import { TOKEN, TOKEN_EXPIRATION_OFFSET } from '../config/token';
8-
import { useACL } from '../core';
7+
import { TOKEN, useACL } from '../core';
98

109
export function useACLGuard(): CanActivateFn {
1110
const acl = useACL();
@@ -35,11 +34,8 @@ export function useTokenGuard(): CanActivateFn {
3534
return <Navigate to={LOGIN_PATH} state={{ [PREV_ROUTE_KEY]: location }} replace />;
3635
}
3736

38-
const expiration = TOKEN.expiration;
39-
if (!isNull(expiration)) {
40-
if (expiration - TOKEN_EXPIRATION_OFFSET <= Date.now()) {
41-
return <Navigate to={LOGIN_PATH} state={{ [PREV_ROUTE_KEY]: location }} replace />;
42-
}
37+
if (TOKEN.expired) {
38+
return <Navigate to={LOGIN_PATH} state={{ [PREV_ROUTE_KEY]: location }} replace />;
4339
}
4440

4541
return true;

packages/platform/src/app/components/amap/AMap.tsx

Lines changed: 0 additions & 83 deletions
This file was deleted.

packages/platform/src/app/components/amap/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/platform/src/app/components/echarts/ECharts.tsx renamed to packages/platform/src/app/components/chart/Chart.tsx

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import type { AppTheme } from '../../App';
22

33
import * as echarts from 'echarts';
44
import { cloneDeep, merge } from 'lodash';
5-
import React, { useCallback, useEffect, useRef, useState } from 'react';
5+
import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
66

77
import { useAsync, useResize, useStorage } from '@react-devui/hooks';
8-
import { setRef } from '@react-devui/hooks/useForkRef';
98
import { getClassName } from '@react-devui/utils';
109

1110
import { STORAGE_KEY } from '../../../config/storage';
@@ -14,11 +13,11 @@ import chartTheme from './theme.json';
1413
echarts.registerTheme('light', chartTheme.light);
1514
echarts.registerTheme('dark', merge(cloneDeep(chartTheme.light), chartTheme.dark));
1615

17-
export interface AppEChartsProps<O extends echarts.EChartsOption> extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
16+
export interface AppChartProps<O extends echarts.EChartsOption> extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> {
1817
aOption: O | null;
1918
}
2019

21-
function ECharts<O extends echarts.EChartsOption>(props: AppEChartsProps<O>, ref: React.ForwardedRef<echarts.ECharts>): JSX.Element | null {
20+
function Chart<O extends echarts.EChartsOption>(props: AppChartProps<O>, ref: React.ForwardedRef<echarts.ECharts>): JSX.Element | null {
2221
const {
2322
aOption,
2423

@@ -27,6 +26,7 @@ function ECharts<O extends echarts.EChartsOption>(props: AppEChartsProps<O>, ref
2726

2827
//#region Ref
2928
const elRef = useRef<HTMLDivElement>(null);
29+
const containerRef = useRef<HTMLDivElement>(null);
3030
//#endregion
3131

3232
const dataRef = useRef<{
@@ -38,17 +38,14 @@ function ECharts<O extends echarts.EChartsOption>(props: AppEChartsProps<O>, ref
3838
const themeStorage = useStorage<AppTheme>(...STORAGE_KEY.theme);
3939

4040
const [instance, setInstance] = useState<echarts.ECharts | null>(null);
41-
const containerRef = useCallback(
42-
(el: HTMLElement | null) => {
43-
setInstance((draft) => {
44-
draft?.dispose();
45-
const instance = el ? echarts.init(el, themeStorage.value, { renderer: 'svg' }) : null;
46-
setRef(ref, instance);
47-
return instance;
48-
});
49-
},
50-
[ref, themeStorage.value]
51-
);
41+
42+
useEffect(() => {
43+
const instance = containerRef.current ? echarts.init(containerRef.current, themeStorage.value, { renderer: 'svg' }) : null;
44+
setInstance(instance);
45+
return () => {
46+
instance?.dispose();
47+
};
48+
}, [themeStorage.value]);
5249

5350
useEffect(() => {
5451
if (instance && aOption) {
@@ -66,11 +63,13 @@ function ECharts<O extends echarts.EChartsOption>(props: AppEChartsProps<O>, ref
6663
}
6764
});
6865

66+
useImperativeHandle<echarts.ECharts | null, echarts.ECharts | null>(ref, () => instance, [instance]);
67+
6968
return (
70-
<div {...restProps} ref={elRef} className={getClassName(restProps.className, 'app-echarts')}>
71-
<div ref={containerRef} className="app-echarts__container"></div>
69+
<div {...restProps} ref={elRef} className={getClassName(restProps.className, 'app-chart')}>
70+
<div ref={containerRef} className="app-chart__container"></div>
7271
</div>
7372
);
7473
}
7574

76-
export const AppECharts = React.forwardRef(ECharts);
75+
export const AppChart = React.forwardRef(Chart);

0 commit comments

Comments
 (0)