@cloudbase/weda-ui 3.4.11 → 3.4.12

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.
Files changed (150) hide show
  1. package/dist/configs/components/common/form-input-required.js +3 -3
  2. package/dist/configs/components/customer-service.js +3 -0
  3. package/dist/configs/components/dataView.js +20 -10
  4. package/dist/configs/components/form-checkbox.js +15 -2
  5. package/dist/configs/components/form-email.js +17 -2
  6. package/dist/configs/components/form-input.js +17 -2
  7. package/dist/configs/components/form-phone.js +17 -2
  8. package/dist/configs/components/form-radio.js +15 -2
  9. package/dist/configs/components/form-select-multiple.js +362 -0
  10. package/dist/configs/components/form-switch.js +15 -2
  11. package/dist/configs/components/form-text-area.js +15 -2
  12. package/dist/configs/components/form-url.js +17 -2
  13. package/dist/configs/components/form-user-tree-select.js +13 -0
  14. package/dist/configs/components/listView.js +32 -49
  15. package/dist/configs/components/table.json +1 -54
  16. package/dist/configs/components/wd-bubble.js +46 -8
  17. package/dist/configs/components/wd-button.js +3 -0
  18. package/dist/configs/components/wd-checkbox.js +464 -0
  19. package/dist/configs/components/wd-form.js +66 -10
  20. package/dist/configs/components/wd-input-email.js +37 -0
  21. package/dist/configs/components/wd-input-phone.js +43 -0
  22. package/dist/configs/components/wd-input-url.js +37 -0
  23. package/dist/configs/components/wd-input.js +94 -0
  24. package/dist/configs/components/wd-official-account.js +87 -0
  25. package/dist/configs/components/wd-radio.js +443 -0
  26. package/dist/configs/components/wd-switch.js +315 -0
  27. package/dist/configs/components/wd-table.js +8 -56
  28. package/dist/configs/components/wd-textarea.js +82 -0
  29. package/dist/configs/components/wd-tree.js +443 -0
  30. package/dist/configs/components/web-view.js +3 -0
  31. package/dist/configs/index.js +24 -1
  32. package/dist/configs/type-utils/type-form.js +681 -0
  33. package/dist/docs/common/components/json-schema-view.js +1 -1
  34. package/dist/docs/common/components/methods-view.js +1 -1
  35. package/dist/docs/common/components/properties-view.js +3 -1
  36. package/dist/docs/common/format.js +7 -7
  37. package/dist/docs/common/tableView.js +3 -1
  38. package/dist/enum/index.js +196 -0
  39. package/dist/style/index.scss +1 -1
  40. package/dist/web/actions/showMessage/index.js +4 -1
  41. package/dist/web/components/carousel/index.js +1 -1
  42. package/dist/web/components/customer-service/customer-service.js +19 -2
  43. package/dist/web/components/dataView/index.js +16 -3
  44. package/dist/web/components/flow/common/hooks/useCommonFlowData/flow-get.js +5 -1
  45. package/dist/web/components/flow/common/request.js +5 -5
  46. package/dist/web/components/flow/modules/operations/controls-items/flow-task-info-modal.js +90 -0
  47. package/dist/web/components/form/formcell/index.css +13 -1
  48. package/dist/web/components/form/formcell/index.js +1 -1
  49. package/dist/web/components/form/location/components/LocationH5/location.h5.js +1 -1
  50. package/dist/web/components/form/select/dropdown-select/index.js +7 -1
  51. package/dist/web/components/form/select/h5.js +18 -8
  52. package/dist/web/components/form/select/index.js +9 -9
  53. package/dist/web/components/form/select/region/index.js +1 -1
  54. package/dist/web/components/form/selectMultiple/dropdown-select/h5.js +111 -0
  55. package/dist/web/components/form/selectMultiple/dropdown-select/index.css +270 -0
  56. package/dist/web/components/form/selectMultiple/dropdown-select/index.js +206 -0
  57. package/dist/web/components/form/selectMultiple/dropdown-select/pc.js +115 -0
  58. package/dist/web/components/form/selectMultiple/dropdown-select/ui.js +113 -0
  59. package/dist/web/components/form/selectMultiple/h5.js +40 -0
  60. package/dist/web/components/form/selectMultiple/index.js +94 -0
  61. package/dist/web/components/form/selectMultiple/request.js +76 -0
  62. package/dist/web/components/form/selectMultiple/status/allEmpty.js +5 -0
  63. package/dist/web/components/form/selectMultiple/status/empty.js +19 -0
  64. package/dist/web/components/form/selectMultiple/status/index.css +63 -0
  65. package/dist/web/components/form/selectMultiple/status/index.js +7 -0
  66. package/dist/web/components/form/selectMultiple/status/loading.js +19 -0
  67. package/dist/web/components/form/selectMultiple/status/propsType.js +1 -0
  68. package/dist/web/components/form/selectMultiple/status/retry.js +19 -0
  69. package/dist/web/components/form/tips/index.css +9 -3
  70. package/dist/web/components/form/uploader/index.css +10 -0
  71. package/dist/web/components/form/uploader/uploader.h5.js +60 -62
  72. package/dist/web/components/form/uploader/uploader.pc.js +48 -41
  73. package/dist/web/components/form/uploaderFile/uploadFile.h5.js +8 -33
  74. package/dist/web/components/form/uploaderFile/uploadFile.pc.js +8 -37
  75. package/dist/web/components/form/userOrgSelect/common/fetch-data-service.js +76 -50
  76. package/dist/web/components/form/userOrgSelect/common/utils.js +24 -8
  77. package/dist/web/components/form/userOrgSelect/component/depart-select/depart-select-pc.js +3 -8
  78. package/dist/web/components/form/userOrgSelect/component/depart-select/index.js +14 -18
  79. package/dist/web/components/form/userOrgSelect/component/depart-select/org-modal-pc.js +20 -14
  80. package/dist/web/components/form/userOrgSelect/component/modal-select-h5.js +1 -1
  81. package/dist/web/components/form/userOrgSelect/component/org-tree.js +21 -9
  82. package/dist/web/components/form/userOrgSelect/component/user-select-h5/index.js +57 -10
  83. package/dist/web/components/form/userOrgSelect/component/user-select-pc/user-model.js +2 -7
  84. package/dist/web/components/form/userOrgSelect/component/user-select-pc/user-select-pc.js +6 -4
  85. package/dist/web/components/form/userOrgSelect/component/userOrgSelect.css +8 -2
  86. package/dist/web/components/form/userOrgSelect/departTreeSelect/departTreeSelect.h5.js +25 -51
  87. package/dist/web/components/form/userOrgSelect/hooks/use-depart-data.js +3 -3
  88. package/dist/web/components/form-input-hooks/index.js +39 -14
  89. package/dist/web/components/form-select-multiple/index.js +26 -0
  90. package/dist/web/components/form-user-tree-select/index.js +2 -2
  91. package/dist/web/components/formdetail/index.css +31 -1
  92. package/dist/web/components/formdetail/index.js +30 -0
  93. package/dist/web/components/index.js +17 -1
  94. package/dist/web/components/listView/index.js +20 -5
  95. package/dist/web/components/phone/index.js +26 -1
  96. package/dist/web/components/phoneCode/index.js +3 -1
  97. package/dist/web/components/richText/index.css +70 -67
  98. package/dist/web/components/richText/index.js +311 -251
  99. package/dist/web/components/richText/richtext.module.css +1 -0
  100. package/dist/web/components/richTextView/index.css +39 -0
  101. package/dist/web/components/richTextView/index.js +1 -1
  102. package/dist/web/components/share/index.js +26 -1
  103. package/dist/web/components/wd-checkbox/checkbox.js +34 -0
  104. package/dist/web/components/wd-checkbox/index.js +3 -0
  105. package/dist/web/components/wd-checkbox-list/checkboxList.js +140 -0
  106. package/dist/web/components/wd-checkbox-list/index.js +3 -0
  107. package/dist/web/components/wd-form/index.js +25 -12
  108. package/dist/web/components/wd-form/wd-form.js +42 -0
  109. package/dist/web/components/wd-form-cell/index.js +3 -0
  110. package/dist/web/components/wd-form-cell/wd-form-cell.js +42 -0
  111. package/dist/web/components/wd-form-item/index.js +4 -0
  112. package/dist/web/components/wd-form-item/wd-form-item.js +55 -0
  113. package/dist/web/components/wd-form-item/wd-input-group.js +24 -0
  114. package/dist/web/components/wd-input/index.js +3 -0
  115. package/dist/web/components/wd-input/wd-input.js +155 -0
  116. package/dist/web/components/wd-input-email/index.js +3 -0
  117. package/dist/web/components/wd-input-email/wd-input-email.js +13 -0
  118. package/dist/web/components/wd-input-group/index.js +3 -0
  119. package/dist/web/components/wd-input-group/wd-input-group.js +10 -0
  120. package/dist/web/components/wd-input-phone/index.js +3 -0
  121. package/dist/web/components/wd-input-phone/wd-input-phone.js +14 -0
  122. package/dist/web/components/wd-input-url/index.js +3 -0
  123. package/dist/web/components/wd-input-url/wd-input-url.js +13 -0
  124. package/dist/web/components/wd-input-wrap/index.js +3 -0
  125. package/dist/web/components/wd-input-wrap/wd-input-wrap.js +18 -0
  126. package/dist/web/components/wd-official-account/index.css +29 -0
  127. package/dist/web/components/wd-official-account/index.js +36 -0
  128. package/dist/web/components/wd-radio/index.js +3 -0
  129. package/dist/web/components/wd-radio/wd-radio.js +30 -0
  130. package/dist/web/components/wd-radio-list/index.js +3 -0
  131. package/dist/web/components/wd-radio-list/wd-radio-list.js +104 -0
  132. package/dist/web/components/wd-switch/index.js +3 -0
  133. package/dist/web/components/wd-switch/wd-switch.js +52 -0
  134. package/dist/web/components/wd-table/components/FieldRender/index.js +5 -4
  135. package/dist/web/components/wd-table/components/Table/index.js +12 -2
  136. package/dist/web/components/wd-table/hooks/useQueryParams.js +4 -1
  137. package/dist/web/components/wd-table/utils/index.js +6 -2
  138. package/dist/web/components/wd-table/wd-table.js +70 -57
  139. package/dist/web/components/wd-textarea/index.js +3 -0
  140. package/dist/web/components/wd-textarea/wd-textarea.js +78 -0
  141. package/dist/web/components/wd-tree/index.js +3 -0
  142. package/dist/web/components/wd-tree/utils.js +291 -0
  143. package/dist/web/components/wd-tree/wd-tree.js +193 -0
  144. package/dist/web/utils/constant.js +16 -0
  145. package/dist/web/utils/datasource.js +2 -2
  146. package/dist/web/utils/date.js +3 -3
  147. package/dist/web/utils/hooks/useFormLegacy.js +111 -0
  148. package/dist/web/utils/tool.js +12 -2
  149. package/dist/web/weda-ui.css +193 -3
  150. package/package.json +6 -5
@@ -1,20 +1,15 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import React, { useMemo, useRef, useState } from 'react';
3
- import { useSetState } from '../../utils/hooks/useSetState';
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from 'react';
4
3
  import classNames from '../../utils/classnames';
5
- import Editor, { EditorState, convertEditorStateToHTML } from 'kedao';
6
- import { insertMedias, handleKeyCommand } from 'kedao/lib/utils';
7
- import { createStateFromContent } from 'kedao/lib/editor';
8
- import { getCloudInstance } from '../../utils/tcb';
9
- import { message, Button, Input, Modal, Progress, Upload, Text, } from 'tea-component';
10
- import { v4 as uuidv4 } from 'uuid';
11
- import { defaultBase64 } from './const';
12
- import { renderDecorator } from '../form/renderDecorator';
13
4
  import { usePlatform } from '../../utils/platform';
14
- import './index.css';
5
+ import { getTempFileURL } from '../../utils/tcb';
6
+ import { v4 as uuidv4 } from 'uuid';
15
7
  import styleM from './richtext.module.css';
16
- import { useDeepCompareEffect, useSyncedRef } from '@react-hookz/web';
17
- import { useTempUrl } from '../../utils/hooks/use-cloud-id-temp-url';
8
+ import { LOAD_ERR_IMG_BASE64, RICH_TEXT_ICON_PACK } from '../../utils/constant';
9
+ import { message } from 'tea-component';
10
+ import './index.css';
11
+ import { useEventListener, useResizeObserver } from '@react-hookz/web';
12
+ import { renderDecorator } from '../form/renderDecorator';
18
13
  // 默认图片类型
19
14
  const IMAGE_TYPES = [
20
15
  'image/jpeg',
@@ -24,44 +19,51 @@ const IMAGE_TYPES = [
24
19
  'image/tiff',
25
20
  'image/svg+xml',
26
21
  ];
27
- const defaultControls = [
22
+ // 默认音频类型
23
+ const AUDIO_TYPES = [
24
+ 'audio/*',
25
+ '.mp3',
26
+ '.wma',
27
+ '.aac',
28
+ '.flac',
29
+ '.wav',
30
+ '.amr',
31
+ '.m4a',
32
+ ];
33
+ const toolbarArrayH5 = [
34
+ 'fullscreen',
28
35
  'undo',
29
36
  'redo',
30
- 'separator',
31
- 'headings',
32
- 'separator',
33
- 'font-size',
34
- 'separator',
35
- 'line-height',
36
- 'letter-spacing',
37
- 'text-color',
37
+ 'heading',
38
+ 'color',
39
+ 'backgroundColor',
40
+ 'fontFamily',
41
+ 'fontSize',
38
42
  'bold',
39
43
  'italic',
40
44
  'underline',
41
- 'strike-through',
42
- 'superscript',
43
- 'subscript',
44
- 'remove-styles',
45
- 'emoji',
46
- 'text-indent',
47
- 'text-align',
48
- 'list-ul',
49
- 'list-ol',
50
- 'blockquote',
51
- 'code',
52
- 'link',
45
+ 'strikethrough',
53
46
  'hr',
54
- 'media',
55
- 'clear',
47
+ 'textAlign',
48
+ 'orderList',
49
+ 'bulletList',
56
50
  ];
51
+ const toolbarPC = 'fullscreen clearFormat paintFormat | heading headingNumbering fontFamily fontSize bold italic underline strikethrough superScript subScript color backgroundColor link quote bulletList orderList hr picture table textAlign textIndent marginTop marginBottom marginSide lineSpace wordSpace paragraphCheck | undo redo';
52
+ const popover = 'clearFormat bold italic underline color backgroundColor';
53
+ //加载组件
54
+ let loadEditorPromise;
55
+ // 默认视频类型
56
+ const VIDEO_TYPES = ['video/*'];
57
57
  export default React.memo(RichText);
58
58
  function RichText({
59
59
  // 系统属性
60
60
  id, style, className, events,
61
61
  // 组件属性
62
- label, labelVisible, value, readOnly, layout, requiredFlag, onChange, maxSize, acceptTypes, cloudPath, disabled, decorator = undefined, }) {
63
- const [editorState, setEditorState] = useState();
64
- const latestEditorState = useSyncedRef(editorState);
62
+ label, labelVisible, value, readOnly, layout, disabled, requiredFlag, onChange, decorator = undefined, acceptTypes,
63
+ // acceptAudioTypes,
64
+ // acceptVideoTypes,
65
+ initialContent, placeholder, iconPack, maxSize, cloudPath, visible, }) {
66
+ var _a, _b, _c, _d, _e, _f, _g, _h;
65
67
  const cls = classNames({
66
68
  'weda-ui': true,
67
69
  'weda-richText': true,
@@ -75,11 +77,23 @@ label, labelVisible, value, readOnly, layout, requiredFlag, onChange, maxSize, a
75
77
  'weui-cell_form': isH5,
76
78
  'weui-cell_disabled': isH5 && disabled,
77
79
  });
78
- const previousValueRef = useRef();
80
+ const [, setRandomId] = React.useState('');
81
+ const [editorHeight, setEditorHeight] = React.useState(0);
82
+ const [editorWidth, setEditorWidth] = React.useState(0);
83
+ const [defaultValue, setDefaultValue] = React.useState('');
84
+ const [currentMap, setCurrentMap] = React.useState({});
85
+ const [toolbar, setToolbar] = React.useState(platform === 'h5' ? toolbarArrayH5.join(' ') : toolbarPC);
86
+ const ref = React.useRef({});
87
+ const editorDomRef = React.useRef(null);
88
+ const toolbarDomRef = React.useRef(null);
89
+ const cloudRef = React.useRef({
90
+ cloudToHttpsMap: {},
91
+ });
92
+ const previousValueRef = React.useRef();
79
93
  const onDataChange = function (value) {
80
94
  if (previousValueRef.current !== value) {
81
- events.change &&
82
- events.change({ value: value === '<p></p>' ? '' : value });
95
+ previousValueRef.current = value;
96
+ events === null || events === void 0 ? void 0 : events.change({ value: value === '<p></p>' ? '' : value });
83
97
  if (onChange) {
84
98
  if (value === '<p></p>') {
85
99
  onChange('');
@@ -89,96 +103,259 @@ label, labelVisible, value, readOnly, layout, requiredFlag, onChange, maxSize, a
89
103
  }
90
104
  }
91
105
  }
92
- previousValueRef.current = value;
93
106
  };
94
- useDeepCompareEffect(() => {
95
- if (previousValueRef.current !== value) {
96
- const state = createStateFromContent(value, {});
97
- setEditorState(state);
107
+ const isSizeAccept = (file) => {
108
+ if (file.size > maxSize * 1024 * 1024) {
109
+ message.error({
110
+ content: `文件大小超过上限${maxSize}M`,
111
+ });
112
+ return false;
98
113
  }
99
- }, [value]);
100
- const excludeControls = useMemo(() => {
101
- const result = [
102
- 'media',
103
- 'fullscreen',
104
- 'line-height',
105
- 'letter-spacing',
106
- 'emoji',
107
- 'superscript',
108
- 'subscript',
109
- ];
110
- if (isH5) {
111
- result.push('separator', 'undo', 'redo', 'blockquote', 'code', 'link', 'hr', 'list-ul', 'list-ol', 'hr', 'clear', 'text-indent',
112
- // 'font-size',
113
- 'headings', 'remove-styles', 'text-align');
114
+ return true;
115
+ };
116
+ const upload = async (file) => {
117
+ var _a, _b, _c, _d, _e;
118
+ const tcb = await ((_b = (_a = window === null || window === void 0 ? void 0 : window.app) === null || _a === void 0 ? void 0 : _a.cloud) === null || _b === void 0 ? void 0 : _b.getCloudInstance());
119
+ try {
120
+ const fileType = (_e = (_d = (_c = file === null || file === void 0 ? void 0 : file.name) === null || _c === void 0 ? void 0 : _c.split('.')) === null || _d === void 0 ? void 0 : _d.pop()) === null || _e === void 0 ? void 0 : _e.toLowerCase();
121
+ const path = `${cloudPath}/uploader-${uuidv4()}.${fileType}`;
122
+ const { fileID } = await tcb.uploadFile({
123
+ cloudPath: path,
124
+ filePath: file,
125
+ });
126
+ setCurrentMap({ ...cloudRef.current.cloudToHttpsMap, [fileID]: '' });
127
+ const src = await getTempFileURL(fileID);
128
+ src && (cloudRef.current.cloudToHttpsMap[fileID] = src);
129
+ setCurrentMap(cloudRef.current.cloudToHttpsMap);
130
+ if (!ref.current.editor.hasFocus()) {
131
+ ref.current.editor.focus();
132
+ }
133
+ return src;
114
134
  }
115
- return result;
116
- }, [isH5]);
117
- const extendControls = useMemo(() => {
118
- if (!isH5) {
119
- return [
120
- {
121
- key: 'richtext-uploader',
122
- type: 'component',
123
- component: (_jsx(CustomUploader, { acceptTypes: acceptTypes, maxSize: maxSize, cloudPath: cloudPath, onChange: (url) => {
124
- const state = insertMedias(latestEditorState.current, [
125
- { type: 'IMAGE', url },
126
- ]);
127
- setEditorState((curState) => {
128
- const currentSelection = curState.getSelection();
129
- EditorState.forceSelection(state, currentSelection);
130
- return state;
135
+ catch (e) {
136
+ message.error({
137
+ content: '上传图片失败' + e.message,
138
+ });
139
+ }
140
+ };
141
+ React.useEffect(() => {
142
+ if (!(window === null || window === void 0 ? void 0 : window.ExEditor3) && !loadEditorPromise) {
143
+ loadEditorPromise = new Promise((resolve) => {
144
+ const script = document.createElement('script');
145
+ script.src =
146
+ 'https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_files/static/richtext/exeditor3.min.js';
147
+ script.onload = () => {
148
+ resolve('');
149
+ };
150
+ document.body.appendChild(script);
151
+ const link = document.createElement('link');
152
+ link.setAttribute('rel', 'stylesheet');
153
+ link.setAttribute('href', 'https://qbase.cdn-go.cn/lcap/lcap-resource-cdngo/-/release/_files/static/richtext/exeditor3.min.css');
154
+ const head = document.getElementsByTagName('head');
155
+ if (head.length) {
156
+ head[0].appendChild(link);
157
+ }
158
+ else {
159
+ document.body.appendChild(link);
160
+ }
161
+ });
162
+ }
163
+ if (loadEditorPromise) {
164
+ loadEditorPromise.then(() => {
165
+ setRandomId(`${new Date().getTime()}`);
166
+ });
167
+ }
168
+ }, []);
169
+ React.useEffect(() => {
170
+ if (window === null || window === void 0 ? void 0 : window.ExEditor3) {
171
+ const editor = window === null || window === void 0 ? void 0 : window.ExEditor3({
172
+ root: editorDomRef.current,
173
+ toolbarRoot: toolbarDomRef.current,
174
+ toolbar: {
175
+ static: toolbar,
176
+ popover,
177
+ },
178
+ initialContent: defaultValue || initialContent,
179
+ placeholder: placeholder,
180
+ onCopy: (isSuccess) => {
181
+ if (isSuccess) {
182
+ message.success({
183
+ content: '复制成功',
184
+ });
185
+ }
186
+ },
187
+ iconPack: iconPack,
188
+ }, {
189
+ HeadingPlugin: {
190
+ levels: [1, 2, 3, 4, 5, 6],
191
+ options: [
192
+ { label: '标题H1', value: '1' },
193
+ { label: '标题H2', value: '2' },
194
+ { label: '标题H3', value: '3' },
195
+ { label: '标题H4', value: '4' },
196
+ { label: '标题H5', value: '5' },
197
+ { label: '标题H6', value: '6' },
198
+ { label: '常规', value: '' },
199
+ ],
200
+ },
201
+ PicturePlugin: {
202
+ upload,
203
+ accept: acceptTypes.join(),
204
+ inline: true,
205
+ acceptFile: (file) => {
206
+ let typeRegex = new RegExp(`^((${acceptTypes.join(')|(').replace('+', '\\+')}))$`);
207
+ if (acceptTypes.join().includes('*')) {
208
+ typeRegex = new RegExp(`^image/.+$`);
209
+ }
210
+ if (!typeRegex.test(file.type)) {
211
+ message.error({
212
+ content: '文件格式不支持',
131
213
  });
132
- } })),
214
+ return false;
215
+ }
216
+ return isSizeAccept(file);
217
+ },
218
+ },
219
+ FontFamilyPlugin: {
220
+ default: 'initial',
221
+ options: [
222
+ {
223
+ label: '思源黑体',
224
+ value: 'Source Han Sans SC, 思源黑体, sans-serif',
225
+ },
226
+ ],
133
227
  },
134
- ];
228
+ });
229
+ editor.on('blur', () => {
230
+ let html = editor.getHTML();
231
+ const map = cloudRef.current.cloudToHttpsMap || {};
232
+ Object.keys(map).forEach((key) => {
233
+ if (map[key]) {
234
+ html = html.replace(`${map[key]}`.replace('&', '&amp;'), `${key}`);
235
+ }
236
+ });
237
+ onDataChange(html);
238
+ if (html.length > 32768) {
239
+ console.warn('富文本长度过长,可能导致保存失败,当前', html.length);
240
+ }
241
+ });
242
+ editor.on('resize', () => {
243
+ var _a, _b;
244
+ setEditorHeight(((_a = toolbarDomRef === null || toolbarDomRef === void 0 ? void 0 : toolbarDomRef.current) === null || _a === void 0 ? void 0 : _a.clientHeight) || 0);
245
+ setEditorWidth(((_b = toolbarDomRef === null || toolbarDomRef === void 0 ? void 0 : toolbarDomRef.current) === null || _b === void 0 ? void 0 : _b.clientWidth) || 0);
246
+ });
247
+ ref.current.editor = editor;
248
+ return () => {
249
+ editor.destroy();
250
+ };
135
251
  }
136
- }, [
137
- acceptTypes,
138
- maxSize,
139
- cloudPath,
140
- latestEditorState,
141
- insertMedias,
142
- setEditorState,
143
- isH5,
144
- ]);
145
- // 修改img显示逻辑
146
- const blockRenderFn = (contentBlock, { editor, editorState }) => {
147
- var _a;
148
- if (contentBlock.getType() === 'atomic') {
149
- const entityKey = contentBlock.getEntityAt(0);
150
- if (!entityKey) {
151
- return null;
252
+ // eslint-disable-next-line react-hooks/exhaustive-deps
253
+ }, [window === null || window === void 0 ? void 0 : window.ExEditor3, toolbar]);
254
+ React.useEffect(() => {
255
+ if (ref.current.editor) {
256
+ if (readOnly || disabled) {
257
+ ref.current.editor.setReadOnly(true);
152
258
  }
153
- const entity = (_a = editorState === null || editorState === void 0 ? void 0 : editorState.getCurrentContent()) === null || _a === void 0 ? void 0 : _a.getEntity(entityKey);
154
- if (entity.getType() === 'IMAGE') {
155
- return {
156
- component: RichTextImg,
157
- editable: false,
158
- props: { editor, editorState }, // 传入的内容可以在组件中通过this.props.blockProps获取到
159
- };
259
+ else {
260
+ ref.current.editor.setReadOnly(false);
261
+ }
262
+ }
263
+ }, [readOnly, disabled, ref.current.editor]);
264
+ const iferror = `javascript:this.width='80';this.src='${LOAD_ERR_IMG_BASE64}';this.onerror=null`;
265
+ const regex = new RegExp(/<img [^>]*src=\\*"([^"]*?)\\*"/g);
266
+ let tempValue = (_b = (_a = (defaultValue || '')) === null || _a === void 0 ? void 0 : _a.toString()) === null || _b === void 0 ? void 0 : _b.replace(/<img /g, `<img onerror=${iferror} style="max-width:100%" `);
267
+ const getSrc = async (img, startSetHtml) => {
268
+ const url = img.replace(regex, '$1');
269
+ if (img.includes('cloud://')) {
270
+ const newURL = await getTempFileURL(url);
271
+ if (newURL) {
272
+ tempValue = tempValue.replace(new RegExp(url, 'g'), newURL);
273
+ cloudRef.current.cloudToHttpsMap[url] = newURL;
160
274
  }
161
275
  }
276
+ if (startSetHtml) {
277
+ ref.current.editor.setHTML(tempValue);
278
+ }
162
279
  };
163
- const richTextEl = (_jsx("div", { className: subCls, children: _jsx("div", { style: style, className: styleM.richtextInner, children: _jsx(Editor, { value: editorState, readOnly: readOnly, disabled: disabled, language: "zh", blockRendererFn: blockRenderFn, onBlur: (s) => {
164
- setEditorState(s);
165
- const html = convertEditorStateToHTML(s, {});
166
- onDataChange(html);
167
- if (html.length > 32768) {
168
- message.warning({
169
- content: '富文本长度过长,可能导致保存失败',
170
- });
171
- }
172
- }, controls: defaultControls, excludeControls: excludeControls,
173
- /** @ts-ignore jsx */
174
- extendControls: extendControls, handleKeyCommand: (command, editState) => {
175
- const newState = handleKeyCommand(editState, command);
176
- if (newState) {
177
- setEditorState(newState);
178
- return true;
179
- }
180
- return false;
181
- } }, id) }) }));
280
+ React.useEffect(() => {
281
+ if (ref.current.editor) {
282
+ cloudRef.current.cloudToHttpsMap = {};
283
+ const imgs = defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.match(regex);
284
+ if (imgs && imgs.length > 0) {
285
+ imgs.forEach((img, index) => {
286
+ const startSetHtml = index === imgs.length - 1;
287
+ getSrc(img, startSetHtml);
288
+ });
289
+ }
290
+ else {
291
+ ref.current.editor.setHTML(tempValue);
292
+ }
293
+ }
294
+ }, [defaultValue, ref.current.editor]);
295
+ React.useEffect(() => {
296
+ var _a;
297
+ setEditorWidth(((_a = toolbarDomRef === null || toolbarDomRef === void 0 ? void 0 : toolbarDomRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) || 0);
298
+ }, [style === null || style === void 0 ? void 0 : style.width, (_c = toolbarDomRef === null || toolbarDomRef === void 0 ? void 0 : toolbarDomRef.current) === null || _c === void 0 ? void 0 : _c.clientWidth]);
299
+ React.useEffect(() => {
300
+ var _a;
301
+ setEditorHeight(((_a = toolbarDomRef === null || toolbarDomRef === void 0 ? void 0 : toolbarDomRef.current) === null || _a === void 0 ? void 0 : _a.clientHeight) || 0);
302
+ }, [style === null || style === void 0 ? void 0 : style.height, (_d = toolbarDomRef === null || toolbarDomRef === void 0 ? void 0 : toolbarDomRef.current) === null || _d === void 0 ? void 0 : _d.clientHeight]);
303
+ React.useEffect(() => {
304
+ if (value && previousValueRef.current !== value) {
305
+ setDefaultValue(value);
306
+ }
307
+ if (!value) {
308
+ setDefaultValue('');
309
+ }
310
+ }, [value]);
311
+ React.useEffect(() => {
312
+ const map = currentMap;
313
+ if (map && Object.keys(map).length > 0) {
314
+ Object.keys(map).every((key) => map[key]) &&
315
+ (events === null || events === void 0 ? void 0 : events.finishUploadAll({ value: map }));
316
+ }
317
+ }, [currentMap]);
318
+ const children = (_g = (_f = (_e = toolbarDomRef === null || toolbarDomRef === void 0 ? void 0 : toolbarDomRef.current) === null || _e === void 0 ? void 0 : _e.children) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.children;
319
+ React.useEffect(() => {
320
+ var _a;
321
+ if (platform === 'h5' && children && children.length > 0) {
322
+ for (let i = children.length - 1; i >= 0; i--) {
323
+ if (((_a = toolbarDomRef === null || toolbarDomRef === void 0 ? void 0 : toolbarDomRef.current) === null || _a === void 0 ? void 0 : _a.clientHeight) > 70) {
324
+ children[i].remove();
325
+ }
326
+ else {
327
+ setToolbar(`${toolbarArrayH5.slice(0, i).join(' ')} fold(${toolbarArrayH5
328
+ .slice(i)
329
+ .join(' ')})`);
330
+ break;
331
+ }
332
+ }
333
+ }
334
+ }, [platform, children, labelVisible, layout, visible]);
335
+ React.useEffect(() => {
336
+ var _a;
337
+ // pc表单输入类的组件采用的是table布局,需要重新计算max高度
338
+ if (platform !== 'h5') {
339
+ const basicDiv = (_a = editorDomRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('.ExEditor-basic');
340
+ if (basicDiv && (style === null || style === void 0 ? void 0 : style.height) && editorHeight) {
341
+ basicDiv.style.maxHeight = `calc(${style === null || style === void 0 ? void 0 : style.height} - ${editorHeight}px)`;
342
+ }
343
+ }
344
+ }, [style === null || style === void 0 ? void 0 : style.height, editorHeight, (_h = toolbarDomRef === null || toolbarDomRef === void 0 ? void 0 : toolbarDomRef.current) === null || _h === void 0 ? void 0 : _h.clientHeight]);
345
+ useEventListener(window, 'resize', () => {
346
+ var _a;
347
+ setEditorWidth(((_a = toolbarDomRef === null || toolbarDomRef === void 0 ? void 0 : toolbarDomRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) || 0);
348
+ });
349
+ useResizeObserver(toolbarDomRef, () => {
350
+ var _a;
351
+ setEditorWidth(((_a = toolbarDomRef === null || toolbarDomRef === void 0 ? void 0 : toolbarDomRef.current) === null || _a === void 0 ? void 0 : _a.clientWidth) || 0);
352
+ });
353
+ const richTextEl = (_jsx("div", { className: subCls, style: { height: '100%' }, children: _jsx("div", { className: styleM.richtextInner, style: { height: '100%' }, children: _jsxs("div", { className: "weda-richtext-container", id: id, children: [_jsx("div", { ref: toolbarDomRef, className: "weda-richtext-toolbar", role: "richtext" }), _jsx("div", { ref: editorDomRef, className: "weda-richtext-editor", style: {
354
+ height: editorHeight
355
+ ? `calc(100% - ${editorHeight + 1}px)`
356
+ : '100%',
357
+ width: editorWidth ? `${editorWidth}px` : '100%',
358
+ } })] }) }) }));
182
359
  return renderDecorator(richTextEl, decorator)({
183
360
  id,
184
361
  className: cls,
@@ -189,127 +366,6 @@ label, labelVisible, value, readOnly, layout, requiredFlag, onChange, maxSize, a
189
366
  requiredFlag,
190
367
  });
191
368
  }
192
- export const CustomUploader = (props) => {
193
- const { onChange = () => { }, acceptTypes, maxSize, cloudPath } = props;
194
- const [{ fileList, percent, visible, uploading, inputUrl, previewImg }, setState,] = useSetState({
195
- fileList: [],
196
- percent: 0,
197
- visible: false,
198
- uploading: false,
199
- inputUrl: '',
200
- previewImg: defaultBase64,
201
- });
202
- // 获取base64
203
- const getBase64 = (file) => {
204
- const reader = new FileReader();
205
- reader.onloadend = () => {
206
- /** @ts-ignore jsx */
207
- setState({ previewImg: reader.result });
208
- };
209
- reader.readAsDataURL(file);
210
- };
211
- // 计算上传进度
212
- const onProgress = (progressEvent) => {
213
- let percentCompleted = 0;
214
- try {
215
- percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
216
- percentCompleted < 100 ? percentCompleted : 100;
217
- }
218
- catch (e) {
219
- console.error(e);
220
- message.error({
221
- content: '上传图片失败',
222
- });
223
- }
224
- setState({ uploading: true, percent: percentCompleted });
225
- };
226
- return (_jsxs(_Fragment, { children: [_jsx("button", { role: "richtext", type: "button", "data-title": "\u5A92\u4F53\u4E0A\u4F20", className: "control-item button", onClick: () => setState({ visible: true }), children: _jsx("svg", { width: "17", height: "16", viewBox: "0 0 17 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M13.6205 1.61428V3.60631L15.6105 3.6063L15.6105 5.1063L13.6205 5.10631V7.08572H12.1205V5.10633L10.1391 5.10635L10.139 3.60635L12.1205 3.60633V1.61428H13.6205ZM8.84998 2.38572H2.49536C1.94308 2.38572 1.49536 2.83343 1.49536 3.38572V11.6761V13.3857C1.49536 13.403 1.4958 13.4201 1.49666 13.4372C1.5019 13.5405 1.52282 13.6397 1.5571 13.7324C1.69808 14.1138 2.06497 14.3857 2.49536 14.3857H4.49757H4.76178H12.4954C13.0476 14.3857 13.4954 13.938 13.4954 13.3857V13.2088L13.4954 13.2088V11.0909L13.4954 11.0909V8.38572H11.9954V9.59579L10.2484 7.85452L9.71895 7.32678L9.18948 7.85452L6.4372 10.5979L5.03662 9.20183L4.50715 8.67408L3.97769 9.20183L2.99536 10.181V3.88572H8.84998V2.38572ZM2.99536 12.8857V12.2988L4.50715 10.792L5.37481 11.6568L4.14188 12.8857H2.99536ZM11.9954 12.8857H6.26667L9.71895 9.44465L11.9954 11.7137V12.8857Z", fill: "#6A6F7B" }) }) }), _jsxs(Modal, { onClose: () => {
227
- setState({ visible: false });
228
- }, visible: visible, maskClosable: true, children: [_jsx("p", { children: "\u8F93\u5165\u94FE\u63A5\u63D2\u5165\u56FE\u7247" }), _jsxs("div", { className: "richText-upload-link", children: [_jsx(Input, { value: inputUrl, placeholder: "\u8F93\u5165\u56FE\u7247\u5730\u5740", onChange: (value) => setState({ inputUrl: value }) }), "\u00A0", _jsx(Button, { type: "primary", onClick: () => {
229
- onChange(inputUrl);
230
- setState({ visible: false });
231
- }, children: "\u786E\u8BA4" })] }), _jsx("p", { style: { marginBottom: '16px' }, children: "\u6216\u62D6\u62FD\u4E0A\u4F20\u63D2\u5165\u56FE\u7247" }), _jsx(Upload, { accept: acceptTypes.join(), maxSize: 1024 * 1024, beforeUpload: (file) => {
232
- getBase64(file);
233
- let typeRegex = new RegExp(`^((${acceptTypes.join(')|(').replace('+', '\\+')}))$`);
234
- if (acceptTypes.join().includes('*')) {
235
- typeRegex = new RegExp(`^image/.+$`);
236
- }
237
- if (!typeRegex.test(file.type)) {
238
- message.error({
239
- content: '文件格式不支持',
240
- });
241
- return false;
242
- }
243
- if (file.size > maxSize * 1024 * 1024) {
244
- message.error({
245
- content: `文件大小超过上限${maxSize}M`,
246
- });
247
- return false;
248
- }
249
- setState({
250
- uploading: true,
251
- percent: 0,
252
- fileList: [
253
- {
254
- name: file.name,
255
- },
256
- ],
257
- });
258
- getCloudInstance().then(async (tcb) => {
259
- try {
260
- const fileType = file.name.split('.').pop().toLowerCase();
261
- const path = `${cloudPath}/uploader-${uuidv4()}.${fileType}`;
262
- const { fileID } = await tcb.uploadFile({
263
- cloudPath: path,
264
- filePath: file,
265
- onUploadProgress: onProgress,
266
- });
267
- onChange(fileID);
268
- setState({
269
- visible: false,
270
- fileList: [],
271
- });
272
- }
273
- catch (e) {
274
- setState({
275
- fileList: [],
276
- });
277
- console.error(e);
278
- message.error({
279
- content: '上传图片失败' + e.message,
280
- });
281
- }
282
- finally {
283
- setState({ uploading: false, percent: 100 });
284
- }
285
- });
286
- return false;
287
- }, children: ({ open, isDragging }) => (_jsx(Upload.Dragger, { filename: fileList[0] && fileList[0].name, percent: percent, image: previewImg, className: "richtext_upload_dragger", children: isDragging ? ('释放鼠标') : (_jsxs(_Fragment, { children: [_jsx("a", { onClick: open, children: "\u70B9\u51FB\u4E0A\u4F20" }), _jsx(Text, { theme: "weak", children: "/\u62D6\u62FD\u5230\u6B64\u533A\u57DF" })] })) })) }), uploading && (_jsx(Progress, { style: { marginTop: '10px' }, percent: percent }))] })] }));
288
- };
289
- const Img = React.memo(function Img(props) {
290
- const { src, style, onError } = props;
291
- const { data: realSrc, error } = useTempUrl(src);
292
- const realstyle = useMemo(() => {
293
- if (error) {
294
- return { ...style, width: '80px' };
295
- }
296
- return style;
297
- }, [error, style]);
298
- return (_jsx("img", { src: error ? defaultBase64 : realSrc, style: realstyle, onError: () => {
299
- onError === null || onError === void 0 ? void 0 : onError();
300
- } }));
301
- });
302
- const imgStyle = { maxWidth: '100%' };
303
- export const RichTextImg = ({ contentState, block }) => {
304
- const blockData = contentState.getEntity(block.getEntityAt(0)).getData();
305
- const { url } = blockData || {};
306
- return (url && (_jsx(_Fragment, { children: _jsxs("div", { className: "bf-media", children: [_jsx("div", { draggable: "true", className: "bf-image", style: { float: 'left' }, children: _jsxs("div", { style: { position: 'relative', display: 'inline-block' }, children: [_jsx(Img, { src: url, style: imgStyle }), _jsx("div", { className: "bf-pre-csize" })] }) }), _jsx("div", { style: {
307
- clear: 'both',
308
- height: '0px',
309
- lineHeight: 0,
310
- float: 'none',
311
- } })] }) })));
312
- };
313
369
  RichText.whyDidYouRender = true;
314
370
  RichText.defaultProps = {
315
371
  // 系统属性
@@ -320,16 +376,20 @@ RichText.defaultProps = {
320
376
  labelVisible: true,
321
377
  name: 'formRichText',
322
378
  value: '',
323
- readOnly: true,
324
- disabled: true,
325
379
  layout: 'vertical',
326
380
  requiredFlag: false,
327
381
  maxSize: 10,
328
382
  acceptTypes: IMAGE_TYPES,
383
+ acceptAudioTypes: AUDIO_TYPES,
384
+ acceptVideoTypes: VIDEO_TYPES,
329
385
  cloudPath: 'weda-richtext-upload',
330
- };
331
- CustomUploader.defaultProps = {
332
- maxSize: 10,
333
- acceptTypes: IMAGE_TYPES,
334
- cloudPath: 'weda-richtext-upload',
386
+ initialContent: '',
387
+ placeholder: '请输入',
388
+ iconPack: RICH_TEXT_ICON_PACK,
389
+ toolbar: {
390
+ static:
391
+ // 'fullscreen clearFormat paintFormat | heading headingNumbering fontFamily fontSize bold italic underline strikethrough superScript subScript color backgroundColor link quote bulletList orderList hr codeBlock mathFormula picture video audio attachment table unsafeHtml textAlign textIndent fold(marginTop marginBottom marginSide lineSpace wordSpace paragraphCheck) | undo redo',
392
+ 'fullscreen clearFormat paintFormat | heading headingNumbering fontFamily fontSize bold italic underline strikethrough superScript subScript color backgroundColor link quote bulletList orderList hr picture table textAlign textIndent marginTop marginBottom marginSide lineSpace wordSpace paragraphCheck | undo redo',
393
+ popover: 'clearFormat bold italic underline color backgroundColor',
394
+ },
335
395
  };
@@ -1,5 +1,6 @@
1
1
  .richtext_richtextInner__-9STf {
2
2
  border: 1px solid #d1d1d1;
3
+ border-radius: 3px;
3
4
  background-color: inherit;
4
5
  width: 100%;
5
6
  }