@alifd/chat 0.3.8-beta.4 → 0.3.9-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,14 +1,15 @@
1
- import type { BalloonProps } from '../types';
1
+ import type { BalloonProps, Margin } from '../types';
2
2
  /**
3
3
  * 自动调整弹层 align 位置逻辑,设置Balloon 组件中的align参数
4
4
  * defaultMaxHeight 用户传的初始希望的面板高度
5
5
  */
6
6
  export declare function useAutoAlign(_dom: HTMLElement | null | undefined, // 弹层dom
7
7
  trigger: HTMLElement | null, // 触发器dom
8
- { enable, defaultAlign, defaultMaxHeight }: {
8
+ { enable, defaultAlign, defaultMaxHeight, safeAreaMargin }: {
9
9
  enable?: boolean;
10
10
  defaultAlign: BalloonProps['align'];
11
11
  defaultMaxHeight?: number;
12
+ safeAreaMargin?: Margin;
12
13
  }): {
13
14
  align: "b" | "br" | "rt" | "tr" | "t" | "r" | "l" | "tl" | "bl" | "lt" | "lb" | "rb" | undefined;
14
15
  update: (dom?: HTMLElement | null | undefined) => void;
@@ -1,7 +1,6 @@
1
1
  import { useState, useEffect } from 'react';
2
2
  import { getNearlyEdge, isInScreen, getScreenSize } from '../util';
3
3
  import { useThrottle, useDebounce } from '../../utils';
4
- const DEFAULT_PANE_OFFSET = 20;
5
4
  const DEFAULT_EDGE_OFFSET = 10;
6
5
  /**
7
6
  * 自动调整弹层 align 位置逻辑,设置Balloon 组件中的align参数
@@ -9,7 +8,7 @@ const DEFAULT_EDGE_OFFSET = 10;
9
8
  */
10
9
  export function useAutoAlign(_dom, // 弹层dom
11
10
  trigger, // 触发器dom
12
- { enable, defaultAlign, defaultMaxHeight }) {
11
+ { enable, defaultAlign, defaultMaxHeight, safeAreaMargin }) {
13
12
  var _a;
14
13
  const [align, setAlign] = useState(defaultAlign);
15
14
  const [maxHeight, setMaxHeight] = useState(defaultMaxHeight || ((_a = getScreenSize()) === null || _a === void 0 ? void 0 : _a.height));
@@ -33,26 +32,28 @@ trigger, // 触发器dom
33
32
  const { left, top, width, height } = trigger.getBoundingClientRect();
34
33
  let newAlign = align;
35
34
  let newMaxHeight = maxHeight;
35
+ const safeTopMargin = (safeAreaMargin === null || safeAreaMargin === void 0 ? void 0 : safeAreaMargin[0]) || DEFAULT_EDGE_OFFSET;
36
+ const safeBottomMargin = (safeAreaMargin === null || safeAreaMargin === void 0 ? void 0 : safeAreaMargin[2]) || DEFAULT_EDGE_OFFSET;
36
37
  // 去除bl/br/tl/tr的支持,因为会导致弹层面板高度变矮,所以目前只用了'rt'|'lt'|'rb'|'lb'4种布局
37
38
  switch (edge) {
38
39
  case 'top': {
39
40
  newAlign = subEdge === 'left' ? 'rt' : 'lt';
40
- newMaxHeight = screenHeight - top - DEFAULT_EDGE_OFFSET;
41
+ newMaxHeight = screenHeight - top - safeBottomMargin;
41
42
  break;
42
43
  }
43
44
  case 'right': {
44
45
  newAlign = subEdge === 'top' ? 'lt' : 'lb';
45
- newMaxHeight = subEdge === 'top' ? screenHeight - top - DEFAULT_EDGE_OFFSET : top + height - DEFAULT_EDGE_OFFSET;
46
+ newMaxHeight = subEdge === 'top' ? screenHeight - top - safeBottomMargin : top + height - safeTopMargin;
46
47
  break;
47
48
  }
48
49
  case 'bottom': {
49
50
  newAlign = subEdge === 'left' ? 'rb' : 'lb';
50
- newMaxHeight = top + height - DEFAULT_EDGE_OFFSET;
51
+ newMaxHeight = top + height - safeTopMargin;
51
52
  break;
52
53
  }
53
54
  case 'left': {
54
55
  newAlign = subEdge === 'top' ? 'rt' : 'rb';
55
- newMaxHeight = subEdge === 'top' ? screenHeight - top - DEFAULT_EDGE_OFFSET : top + height - DEFAULT_EDGE_OFFSET;
56
+ newMaxHeight = subEdge === 'top' ? screenHeight - top - safeBottomMargin : top + height - safeTopMargin;
56
57
  break;
57
58
  }
58
59
  }
@@ -60,7 +61,9 @@ trigger, // 触发器dom
60
61
  setAlign(newAlign);
61
62
  }
62
63
  if (newMaxHeight !== maxHeight) {
63
- setMaxHeight(newMaxHeight);
64
+ // 最大高度不能超过屏幕高度减去上下的安全距离
65
+ const limitHeight = Math.max(0, screenHeight - safeTopMargin - safeBottomMargin);
66
+ setMaxHeight(Math.min(newMaxHeight, limitHeight));
64
67
  }
65
68
  };
66
69
  const debounceUpdate = useDebounce(() => update(), 200);
@@ -46,7 +46,8 @@ const FloatButton = forwardRef((props, ref) => {
46
46
  const { align: currentAlign, update: _updateAlign, maxHeight: currentMaxHeight } = useAutoAlign(el === null || el === void 0 ? void 0 : el.querySelector(`.${cls}-popup`), triggerEl, {
47
47
  enable: autoAlign,
48
48
  defaultAlign: align,
49
- defaultMaxHeight: parseInt(((_a = balloonProps === null || balloonProps === void 0 ? void 0 : balloonProps.popupStyle) === null || _a === void 0 ? void 0 : _a.height) ? ((_b = balloonProps === null || balloonProps === void 0 ? void 0 : balloonProps.popupStyle) === null || _b === void 0 ? void 0 : _b.height) + '' : '600px')
49
+ defaultMaxHeight: parseInt(((_a = balloonProps === null || balloonProps === void 0 ? void 0 : balloonProps.popupStyle) === null || _a === void 0 ? void 0 : _a.height) ? ((_b = balloonProps === null || balloonProps === void 0 ? void 0 : balloonProps.popupStyle) === null || _b === void 0 ? void 0 : _b.height) + '' : '600px'),
50
+ safeAreaMargin,
50
51
  });
51
52
  const updateAlign = () => {
52
53
  _updateAlign(el === null || el === void 0 ? void 0 : el.querySelector(`.${cls}-popup`));
package/es/index.js CHANGED
@@ -20,4 +20,4 @@ export { default as CardLoading } from './card-loading';
20
20
  export { default as Origin } from './origin';
21
21
  export { default as Loading } from './loading';
22
22
  export { default as Drawer } from './drawer';
23
- export const version = '0.3.8-beta.4';
23
+ export const version = '0.3.9-beta.1';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @component svg-render
3
+ * @en svg-render
4
+ * @type 通用 - svg 渲染组件
5
+ * @when svg 渲染
6
+ */
7
+ import React from 'react';
8
+ import type { SvgRenderProps } from './types';
9
+ export * from './types';
10
+ declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<SvgRenderProps & React.RefAttributes<HTMLDivElement>, "key" | keyof SvgRenderProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, HTMLDivElement, {}>;
11
+ export default _default;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @component svg-render
3
+ * @en svg-render
4
+ * @type 通用 - svg 渲染组件
5
+ * @when svg 渲染
6
+ */
7
+ import React, { forwardRef } from 'react';
8
+ import { ConfigProvider } from '@alifd/next';
9
+ import cs from 'classnames';
10
+ import { PREFIX_DEFAULT, assignSubComponent } from '../utils';
11
+ import { ReactSVG } from 'react-svg';
12
+ const SvgRender = forwardRef(({ className, svgClassName, src, options }) => {
13
+ return (React.createElement(ReactSVG, { className: cs(`${PREFIX_DEFAULT}svg-render`, className), src: src, beforeInjection: (svg) => {
14
+ if (options === null || options === void 0 ? void 0 : options.clearColor) {
15
+ // 去除 svg 下面 g 标签的 fill 属性
16
+ svg.querySelectorAll('*').forEach(dom => {
17
+ dom.removeAttribute('fill');
18
+ });
19
+ }
20
+ svgClassName && svg.classList.add(svgClassName);
21
+ } }));
22
+ });
23
+ const SvgRenderWithSub = assignSubComponent(SvgRender, {
24
+ displayName: 'SvgRender',
25
+ });
26
+ export * from './types';
27
+ export default ConfigProvider.config(SvgRenderWithSub);
File without changes
@@ -0,0 +1 @@
1
+ import './main.scss';
@@ -0,0 +1 @@
1
+ import './main.scss';
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { type CommonProps } from '@alifd/next';
3
+ /**
4
+ * @api svg-render
5
+ */
6
+ export interface SvgRenderProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
7
+ className?: string;
8
+ svgClassName?: string;
9
+ src: string;
10
+ options?: {
11
+ clearColor?: boolean;
12
+ };
13
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,14 +1,15 @@
1
- import type { BalloonProps } from '../types';
1
+ import type { BalloonProps, Margin } from '../types';
2
2
  /**
3
3
  * 自动调整弹层 align 位置逻辑,设置Balloon 组件中的align参数
4
4
  * defaultMaxHeight 用户传的初始希望的面板高度
5
5
  */
6
6
  export declare function useAutoAlign(_dom: HTMLElement | null | undefined, // 弹层dom
7
7
  trigger: HTMLElement | null, // 触发器dom
8
- { enable, defaultAlign, defaultMaxHeight }: {
8
+ { enable, defaultAlign, defaultMaxHeight, safeAreaMargin }: {
9
9
  enable?: boolean;
10
10
  defaultAlign: BalloonProps['align'];
11
11
  defaultMaxHeight?: number;
12
+ safeAreaMargin?: Margin;
12
13
  }): {
13
14
  align: "b" | "br" | "rt" | "tr" | "t" | "r" | "l" | "tl" | "bl" | "lt" | "lb" | "rb" | undefined;
14
15
  update: (dom?: HTMLElement | null | undefined) => void;
@@ -4,7 +4,6 @@ exports.useAutoAlign = useAutoAlign;
4
4
  const react_1 = require("react");
5
5
  const util_1 = require("../util");
6
6
  const utils_1 = require("../../utils");
7
- const DEFAULT_PANE_OFFSET = 20;
8
7
  const DEFAULT_EDGE_OFFSET = 10;
9
8
  /**
10
9
  * 自动调整弹层 align 位置逻辑,设置Balloon 组件中的align参数
@@ -12,7 +11,7 @@ const DEFAULT_EDGE_OFFSET = 10;
12
11
  */
13
12
  function useAutoAlign(_dom, // 弹层dom
14
13
  trigger, // 触发器dom
15
- { enable, defaultAlign, defaultMaxHeight }) {
14
+ { enable, defaultAlign, defaultMaxHeight, safeAreaMargin }) {
16
15
  var _a;
17
16
  const [align, setAlign] = (0, react_1.useState)(defaultAlign);
18
17
  const [maxHeight, setMaxHeight] = (0, react_1.useState)(defaultMaxHeight || ((_a = (0, util_1.getScreenSize)()) === null || _a === void 0 ? void 0 : _a.height));
@@ -36,26 +35,28 @@ trigger, // 触发器dom
36
35
  const { left, top, width, height } = trigger.getBoundingClientRect();
37
36
  let newAlign = align;
38
37
  let newMaxHeight = maxHeight;
38
+ const safeTopMargin = (safeAreaMargin === null || safeAreaMargin === void 0 ? void 0 : safeAreaMargin[0]) || DEFAULT_EDGE_OFFSET;
39
+ const safeBottomMargin = (safeAreaMargin === null || safeAreaMargin === void 0 ? void 0 : safeAreaMargin[2]) || DEFAULT_EDGE_OFFSET;
39
40
  // 去除bl/br/tl/tr的支持,因为会导致弹层面板高度变矮,所以目前只用了'rt'|'lt'|'rb'|'lb'4种布局
40
41
  switch (edge) {
41
42
  case 'top': {
42
43
  newAlign = subEdge === 'left' ? 'rt' : 'lt';
43
- newMaxHeight = screenHeight - top - DEFAULT_EDGE_OFFSET;
44
+ newMaxHeight = screenHeight - top - safeBottomMargin;
44
45
  break;
45
46
  }
46
47
  case 'right': {
47
48
  newAlign = subEdge === 'top' ? 'lt' : 'lb';
48
- newMaxHeight = subEdge === 'top' ? screenHeight - top - DEFAULT_EDGE_OFFSET : top + height - DEFAULT_EDGE_OFFSET;
49
+ newMaxHeight = subEdge === 'top' ? screenHeight - top - safeBottomMargin : top + height - safeTopMargin;
49
50
  break;
50
51
  }
51
52
  case 'bottom': {
52
53
  newAlign = subEdge === 'left' ? 'rb' : 'lb';
53
- newMaxHeight = top + height - DEFAULT_EDGE_OFFSET;
54
+ newMaxHeight = top + height - safeTopMargin;
54
55
  break;
55
56
  }
56
57
  case 'left': {
57
58
  newAlign = subEdge === 'top' ? 'rt' : 'rb';
58
- newMaxHeight = subEdge === 'top' ? screenHeight - top - DEFAULT_EDGE_OFFSET : top + height - DEFAULT_EDGE_OFFSET;
59
+ newMaxHeight = subEdge === 'top' ? screenHeight - top - safeBottomMargin : top + height - safeTopMargin;
59
60
  break;
60
61
  }
61
62
  }
@@ -63,7 +64,9 @@ trigger, // 触发器dom
63
64
  setAlign(newAlign);
64
65
  }
65
66
  if (newMaxHeight !== maxHeight) {
66
- setMaxHeight(newMaxHeight);
67
+ // 最大高度不能超过屏幕高度减去上下的安全距离
68
+ const limitHeight = Math.max(0, screenHeight - safeTopMargin - safeBottomMargin);
69
+ setMaxHeight(Math.min(newMaxHeight, limitHeight));
67
70
  }
68
71
  };
69
72
  const debounceUpdate = (0, utils_1.useDebounce)(() => update(), 200);
@@ -48,7 +48,8 @@ const FloatButton = (0, react_1.forwardRef)((props, ref) => {
48
48
  const { align: currentAlign, update: _updateAlign, maxHeight: currentMaxHeight } = (0, useAutoAlign_1.useAutoAlign)(el === null || el === void 0 ? void 0 : el.querySelector(`.${cls}-popup`), triggerEl, {
49
49
  enable: autoAlign,
50
50
  defaultAlign: align,
51
- defaultMaxHeight: parseInt(((_a = balloonProps === null || balloonProps === void 0 ? void 0 : balloonProps.popupStyle) === null || _a === void 0 ? void 0 : _a.height) ? ((_b = balloonProps === null || balloonProps === void 0 ? void 0 : balloonProps.popupStyle) === null || _b === void 0 ? void 0 : _b.height) + '' : '600px')
51
+ defaultMaxHeight: parseInt(((_a = balloonProps === null || balloonProps === void 0 ? void 0 : balloonProps.popupStyle) === null || _a === void 0 ? void 0 : _a.height) ? ((_b = balloonProps === null || balloonProps === void 0 ? void 0 : balloonProps.popupStyle) === null || _b === void 0 ? void 0 : _b.height) + '' : '600px'),
52
+ safeAreaMargin,
52
53
  });
53
54
  const updateAlign = () => {
54
55
  _updateAlign(el === null || el === void 0 ? void 0 : el.querySelector(`.${cls}-popup`));
package/lib/index.js CHANGED
@@ -46,4 +46,4 @@ var loading_1 = require("./loading");
46
46
  Object.defineProperty(exports, "Loading", { enumerable: true, get: function () { return tslib_1.__importDefault(loading_1).default; } });
47
47
  var drawer_1 = require("./drawer");
48
48
  Object.defineProperty(exports, "Drawer", { enumerable: true, get: function () { return tslib_1.__importDefault(drawer_1).default; } });
49
- exports.version = '0.3.8-beta.4';
49
+ exports.version = '0.3.9-beta.1';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @component svg-render
3
+ * @en svg-render
4
+ * @type 通用 - svg 渲染组件
5
+ * @when svg 渲染
6
+ */
7
+ import React from 'react';
8
+ import type { SvgRenderProps } from './types';
9
+ export * from './types';
10
+ declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<SvgRenderProps & React.RefAttributes<HTMLDivElement>, "key" | keyof SvgRenderProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, HTMLDivElement, {}>;
11
+ export default _default;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ /**
3
+ * @component svg-render
4
+ * @en svg-render
5
+ * @type 通用 - svg 渲染组件
6
+ * @when svg 渲染
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const tslib_1 = require("tslib");
10
+ const react_1 = tslib_1.__importStar(require("react"));
11
+ const next_1 = require("@alifd/next");
12
+ const classnames_1 = tslib_1.__importDefault(require("classnames"));
13
+ const utils_1 = require("../utils");
14
+ const react_svg_1 = require("react-svg");
15
+ const SvgRender = (0, react_1.forwardRef)(({ className, svgClassName, src, options }) => {
16
+ return (react_1.default.createElement(react_svg_1.ReactSVG, { className: (0, classnames_1.default)(`${utils_1.PREFIX_DEFAULT}svg-render`, className), src: src, beforeInjection: (svg) => {
17
+ if (options === null || options === void 0 ? void 0 : options.clearColor) {
18
+ // 去除 svg 下面 g 标签的 fill 属性
19
+ svg.querySelectorAll('*').forEach(dom => {
20
+ dom.removeAttribute('fill');
21
+ });
22
+ }
23
+ svgClassName && svg.classList.add(svgClassName);
24
+ } }));
25
+ });
26
+ const SvgRenderWithSub = (0, utils_1.assignSubComponent)(SvgRender, {
27
+ displayName: 'SvgRender',
28
+ });
29
+ tslib_1.__exportStar(require("./types"), exports);
30
+ exports.default = next_1.ConfigProvider.config(SvgRenderWithSub);
File without changes
@@ -0,0 +1 @@
1
+ import './main.scss';
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ require("./main.scss");
@@ -0,0 +1,13 @@
1
+ import React from 'react';
2
+ import { type CommonProps } from '@alifd/next';
3
+ /**
4
+ * @api svg-render
5
+ */
6
+ export interface SvgRenderProps extends React.HTMLAttributes<HTMLElement>, CommonProps {
7
+ className?: string;
8
+ svgClassName?: string;
9
+ src: string;
10
+ options?: {
11
+ clearColor?: boolean;
12
+ };
13
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alifd/chat",
3
- "version": "0.3.8-beta.4",
3
+ "version": "0.3.9-beta.1",
4
4
  "description": "A configurable component library for chat built on React.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -325,6 +325,18 @@
325
325
  "./drawer/style.js": {
326
326
  "import": "./es/drawer/style.js",
327
327
  "require": "./lib/drawer/style.js"
328
+ },
329
+ "./svg-render": {
330
+ "import": "./es/svg-render/index.js",
331
+ "require": "./lib/svg-render/index.js"
332
+ },
333
+ "./svg-render/style": {
334
+ "import": "./es/svg-render/style.js",
335
+ "require": "./lib/svg-render/style.js"
336
+ },
337
+ "./svg-render/style.js": {
338
+ "import": "./es/svg-render/style.js",
339
+ "require": "./lib/svg-render/style.js"
328
340
  }
329
341
  },
330
342
  "files": [
@@ -393,7 +405,7 @@
393
405
  "rehype-slug": "^6.0.0",
394
406
  "remark-gfm": "^4.0.0",
395
407
  "sass": "^1.70.0",
396
- "sass-loader": "^14.0.0",
408
+ "sass-loader": "^16.0.0",
397
409
  "ts-morph": "^21.0.1",
398
410
  "tsconfck": "^3.1.1",
399
411
  "tsx": "^4.7.0",
@@ -422,7 +434,8 @@
422
434
  "react-copy-to-clipboard": "^5.1.0",
423
435
  "react-photo-view": "^1.2.6",
424
436
  "sanitize-html": "~2.7.3",
425
- "tslib": "^2.6.2"
437
+ "tslib": "^2.6.2",
438
+ "react-svg": "^16.1.34"
426
439
  },
427
440
  "sideEffects": [
428
441
  "es/**/style.js",