@alifd/chat 0.3.32-beta.4 → 0.3.32-beta.5

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.
@@ -103,7 +103,7 @@ const HTMLRenderer = memo(function HTMLRenderer({ className, children, imagePrev
103
103
  const parserOptions = {
104
104
  // @ts-ignore
105
105
  replace: domNode => {
106
- var _a, _b, _c, _d, _e, _f;
106
+ var _a, _b, _c, _d, _e, _f, _g;
107
107
  // 处理文本节点
108
108
  if ((domNode.type === 'text' || domNode.nodeType === 3) && typewriterEffect) {
109
109
  return processTextNode(domNode);
@@ -112,10 +112,22 @@ const HTMLRenderer = memo(function HTMLRenderer({ className, children, imagePrev
112
112
  const { name } = domNode;
113
113
  if (name === 'link-reference') {
114
114
  const element = (domToReact([domNode]));
115
+ // 检查是否有子元素
116
+ if (!((_a = element.props) === null || _a === void 0 ? void 0 : _a.children)) {
117
+ return null;
118
+ }
115
119
  // link-reference 的子元素一定是 a 标签
116
- const aElement = (_a = element.props) === null || _a === void 0 ? void 0 : _a.children;
120
+ const aElement = (_b = element.props) === null || _b === void 0 ? void 0 : _b.children;
121
+ // 检查a标签是否存在
122
+ if (!aElement || !aElement.props) {
123
+ return null;
124
+ }
117
125
  // a 标签的子元素一定是 span 节点
118
- const spanElement = (_b = aElement === null || aElement === void 0 ? void 0 : aElement.props) === null || _b === void 0 ? void 0 : _b.children;
126
+ const spanElement = (_c = aElement === null || aElement === void 0 ? void 0 : aElement.props) === null || _c === void 0 ? void 0 : _c.children;
127
+ // 检查span元素是否存在
128
+ if (!spanElement || !spanElement.props) {
129
+ return null;
130
+ }
119
131
  const handleUrlClick = () => {
120
132
  var _a;
121
133
  if (!((_a = aElement === null || aElement === void 0 ? void 0 : aElement.props) === null || _a === void 0 ? void 0 : _a.href)) {
@@ -128,10 +140,10 @@ const HTMLRenderer = memo(function HTMLRenderer({ className, children, imagePrev
128
140
  defaultOpenLink(aElement.props.href);
129
141
  }
130
142
  };
131
- return (React.createElement(Balloon, { v2: true, align: "b", className: "link-reference-balloon", closable: false, offset: [0, -8], triggerType: ['hover'], trigger: React.createElement("span", { className: "link-reference-index", onClick: handleUrlClick }, (_c = spanElement === null || spanElement === void 0 ? void 0 : spanElement.props) === null || _c === void 0 ? void 0 : _c.children) },
143
+ return (React.createElement(Balloon, { v2: true, align: "b", className: "link-reference-balloon", closable: false, offset: [0, -8], triggerType: ['hover'], trigger: React.createElement("span", { className: "link-reference-index", onClick: handleUrlClick }, (_d = spanElement === null || spanElement === void 0 ? void 0 : spanElement.props) === null || _d === void 0 ? void 0 : _d.children) },
132
144
  React.createElement("div", { className: "link-reference-content" },
133
- React.createElement("img", { className: "link-reference-source-icon", src: ((_d = element.props) === null || _d === void 0 ? void 0 : _d['data-source-icon']) || '' }),
134
- React.createElement("a", { className: "link-reference-title", onClick: handleUrlClick }, ((_e = element.props) === null || _e === void 0 ? void 0 : _e['data-title']) || ''))));
145
+ React.createElement("img", { className: "link-reference-source-icon", src: ((_e = element.props) === null || _e === void 0 ? void 0 : _e['data-source-icon']) || '' }),
146
+ React.createElement("a", { className: "link-reference-title", onClick: handleUrlClick }, ((_f = element.props) === null || _f === void 0 ? void 0 : _f['data-title']) || ''))));
135
147
  }
136
148
  if (name === 'a') {
137
149
  const element = (domToReact([domNode]));
@@ -185,7 +197,7 @@ const HTMLRenderer = memo(function HTMLRenderer({ className, children, imagePrev
185
197
  return renderImage(element.props);
186
198
  }
187
199
  // 换成统一的图片渲染
188
- return React.createElement(Img, Object.assign({}, element.props, { imageClassName: (_f = element.props) === null || _f === void 0 ? void 0 : _f.className, enablePreview: imagePreview, onImageClick: () => {
200
+ return React.createElement(Img, Object.assign({}, element.props, { imageClassName: (_g = element.props) === null || _g === void 0 ? void 0 : _g.className, enablePreview: imagePreview, onImageClick: () => {
189
201
  handleImageClick === null || handleImageClick === void 0 ? void 0 : handleImageClick(element.props.src);
190
202
  } }));
191
203
  }
package/es/index.js CHANGED
@@ -31,4 +31,4 @@ export { default as RadioGroup } from './radio-group';
31
31
  export { default as CheckboxGroup } from './checkbox-group';
32
32
  export { default as Select } from './select';
33
33
  export { default as Flip } from './flip';
34
- export const version = '0.3.32-beta.4';
34
+ export const version = '0.3.32-beta.5';
@@ -106,7 +106,7 @@ const HTMLRenderer = (0, react_1.memo)(function HTMLRenderer({ className, childr
106
106
  const parserOptions = {
107
107
  // @ts-ignore
108
108
  replace: domNode => {
109
- var _a, _b, _c, _d, _e, _f;
109
+ var _a, _b, _c, _d, _e, _f, _g;
110
110
  // 处理文本节点
111
111
  if ((domNode.type === 'text' || domNode.nodeType === 3) && typewriterEffect) {
112
112
  return processTextNode(domNode);
@@ -115,10 +115,22 @@ const HTMLRenderer = (0, react_1.memo)(function HTMLRenderer({ className, childr
115
115
  const { name } = domNode;
116
116
  if (name === 'link-reference') {
117
117
  const element = ((0, html_react_parser_1.domToReact)([domNode]));
118
+ // 检查是否有子元素
119
+ if (!((_a = element.props) === null || _a === void 0 ? void 0 : _a.children)) {
120
+ return null;
121
+ }
118
122
  // link-reference 的子元素一定是 a 标签
119
- const aElement = (_a = element.props) === null || _a === void 0 ? void 0 : _a.children;
123
+ const aElement = (_b = element.props) === null || _b === void 0 ? void 0 : _b.children;
124
+ // 检查a标签是否存在
125
+ if (!aElement || !aElement.props) {
126
+ return null;
127
+ }
120
128
  // a 标签的子元素一定是 span 节点
121
- const spanElement = (_b = aElement === null || aElement === void 0 ? void 0 : aElement.props) === null || _b === void 0 ? void 0 : _b.children;
129
+ const spanElement = (_c = aElement === null || aElement === void 0 ? void 0 : aElement.props) === null || _c === void 0 ? void 0 : _c.children;
130
+ // 检查span元素是否存在
131
+ if (!spanElement || !spanElement.props) {
132
+ return null;
133
+ }
122
134
  const handleUrlClick = () => {
123
135
  var _a;
124
136
  if (!((_a = aElement === null || aElement === void 0 ? void 0 : aElement.props) === null || _a === void 0 ? void 0 : _a.href)) {
@@ -131,10 +143,10 @@ const HTMLRenderer = (0, react_1.memo)(function HTMLRenderer({ className, childr
131
143
  defaultOpenLink(aElement.props.href);
132
144
  }
133
145
  };
134
- return (react_1.default.createElement(balloon_1.default, { v2: true, align: "b", className: "link-reference-balloon", closable: false, offset: [0, -8], triggerType: ['hover'], trigger: react_1.default.createElement("span", { className: "link-reference-index", onClick: handleUrlClick }, (_c = spanElement === null || spanElement === void 0 ? void 0 : spanElement.props) === null || _c === void 0 ? void 0 : _c.children) },
146
+ return (react_1.default.createElement(balloon_1.default, { v2: true, align: "b", className: "link-reference-balloon", closable: false, offset: [0, -8], triggerType: ['hover'], trigger: react_1.default.createElement("span", { className: "link-reference-index", onClick: handleUrlClick }, (_d = spanElement === null || spanElement === void 0 ? void 0 : spanElement.props) === null || _d === void 0 ? void 0 : _d.children) },
135
147
  react_1.default.createElement("div", { className: "link-reference-content" },
136
- react_1.default.createElement("img", { className: "link-reference-source-icon", src: ((_d = element.props) === null || _d === void 0 ? void 0 : _d['data-source-icon']) || '' }),
137
- react_1.default.createElement("a", { className: "link-reference-title", onClick: handleUrlClick }, ((_e = element.props) === null || _e === void 0 ? void 0 : _e['data-title']) || ''))));
148
+ react_1.default.createElement("img", { className: "link-reference-source-icon", src: ((_e = element.props) === null || _e === void 0 ? void 0 : _e['data-source-icon']) || '' }),
149
+ react_1.default.createElement("a", { className: "link-reference-title", onClick: handleUrlClick }, ((_f = element.props) === null || _f === void 0 ? void 0 : _f['data-title']) || ''))));
138
150
  }
139
151
  if (name === 'a') {
140
152
  const element = ((0, html_react_parser_1.domToReact)([domNode]));
@@ -188,7 +200,7 @@ const HTMLRenderer = (0, react_1.memo)(function HTMLRenderer({ className, childr
188
200
  return renderImage(element.props);
189
201
  }
190
202
  // 换成统一的图片渲染
191
- return react_1.default.createElement(img_1.default, Object.assign({}, element.props, { imageClassName: (_f = element.props) === null || _f === void 0 ? void 0 : _f.className, enablePreview: imagePreview, onImageClick: () => {
203
+ return react_1.default.createElement(img_1.default, Object.assign({}, element.props, { imageClassName: (_g = element.props) === null || _g === void 0 ? void 0 : _g.className, enablePreview: imagePreview, onImageClick: () => {
192
204
  handleImageClick === null || handleImageClick === void 0 ? void 0 : handleImageClick(element.props.src);
193
205
  } }));
194
206
  }
package/lib/index.js CHANGED
@@ -68,4 +68,4 @@ var select_1 = require("./select");
68
68
  Object.defineProperty(exports, "Select", { enumerable: true, get: function () { return tslib_1.__importDefault(select_1).default; } });
69
69
  var flip_1 = require("./flip");
70
70
  Object.defineProperty(exports, "Flip", { enumerable: true, get: function () { return tslib_1.__importDefault(flip_1).default; } });
71
- exports.version = '0.3.32-beta.4';
71
+ exports.version = '0.3.32-beta.5';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alifd/chat",
3
- "version": "0.3.32-beta.4",
3
+ "version": "0.3.32-beta.5",
4
4
  "description": "A configurable component library for chat built on React.",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",