@easyv/biz-components 2.1.0 → 2.1.2
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.
- package/dist/lib/_virtual/index.es2.js +2 -2
- package/dist/lib/_virtual/index.es3.js +2 -2
- package/dist/lib/components/ai-components/mobile-voice-input/icon-button.es.js +2 -2
- package/dist/lib/components/ai-components/mobile-voice-input/icon-button.es.js.map +1 -1
- package/dist/lib/components/ai-components/mobile-voice-input/mobile-voice-input.es.js +8 -8
- package/dist/lib/components/ai-components/mobile-voice-input/mobile-voice-input.es.js.map +1 -1
- package/dist/lib/components/easyv-reactgrid/constants.d.ts +5 -0
- package/dist/lib/components/easyv-reactgrid/constants.es.js +9 -0
- package/dist/lib/components/easyv-reactgrid/constants.es.js.map +1 -0
- package/dist/lib/components/easyv-reactgrid/easyv-react-grid.d.ts +15 -0
- package/dist/lib/components/easyv-reactgrid/easyv-react-grid.es.js +293 -0
- package/dist/lib/components/easyv-reactgrid/easyv-react-grid.es.js.map +1 -0
- package/dist/lib/components/easyv-reactgrid/easyv-react-grid.module.less.es.js +7 -0
- package/dist/lib/components/easyv-reactgrid/easyv-react-grid.module.less.es.js.map +1 -0
- package/dist/lib/components/easyv-reactgrid/index.d.ts +1 -0
- package/dist/lib/components/easyv-reactgrid/utils.d.ts +1 -0
- package/dist/lib/components/easyv-reactgrid/utils.es.js +13 -0
- package/dist/lib/components/easyv-reactgrid/utils.es.js.map +1 -0
- package/dist/lib/{easyv-biz-components/src/components → components}/index.d.ts +1 -0
- package/dist/lib/hooks/use-tencent-sentence-recognition/use-tencent-sentence-recognition.es.js +2 -2
- package/dist/lib/hooks/use-tencent-sentence-recognition/use-tencent-sentence-recognition.es.js.map +1 -1
- package/dist/lib/index.d.ts +4 -1
- package/dist/lib/index.es.js +2 -0
- package/dist/lib/index.es.js.map +1 -1
- package/dist/lib/node_modules/.pnpm/co-web-worker@1.0.1/node_modules/co-web-worker/index.es.js +1 -1
- package/dist/lib/node_modules/.pnpm/prop-types@15.8.1/node_modules/prop-types/index.es.js +1 -1
- package/dist/lib/stats.html +1 -1
- package/dist/lib/style.pkg.css +1 -1
- package/dist/lib/utils/vosk-browser-manager/test/voskBrowserManager.cy.d.ts +1 -0
- package/dist/lib/utils/xun-fei-voice/test/RecorderManager.cy.d.ts +1 -0
- package/dist/lib/utils/xun-fei-voice/test/XunFeiVoiceManager.cy.d.ts +1 -0
- package/dist/tailwindcss.pkg.css +8 -0
- package/package.json +4 -3
- package/dist/lib/easyv-biz-components/src/components/ai-components/ai-message-render/test/ai-message-table.cy.d.ts +0 -1
- package/dist/lib/easyv-biz-components/src/index.d.ts +0 -4
- package/dist/lib/easyv-biz-components/src/utils/show-modal/test/show-modal.cy.d.ts +0 -1
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-components/ai-message-render/ai-message-render.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-components/ai-message-render/constants.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-components/ai-message-render/image-preview.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-components/ai-message-render/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-components/ai-message-render/render-utils.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components/ai-model-select/test/ai-model-select-panel.cy.d.ts → components/ai-components/ai-message-render/test/ai-message-render.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/components/circle-loading/test/circle-loading.cy.d.ts → components/ai-components/ai-message-render/test/ai-message-table.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-components/ai-message-render/types.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-components/ai-message-render/utils.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-components/mobile-voice-input/icon-button.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-components/mobile-voice-input/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-components/mobile-voice-input/mobile-voice-input.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-model-select/ai-model-select-panel.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-model-select/iconBtn.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-model-select/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components/code-mirror-editor/test/CodeEditor.cy.d.ts → components/ai-model-select/test/ai-model-select-panel.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/ai-model-select/types.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/circle-loading/circle-loading.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/circle-loading/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components/echarts-render/test/echarts.cy.d.ts → components/circle-loading/test/circle-loading.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/code-mirror-editor/code-mirror-editor.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/code-mirror-editor/constants.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/code-mirror-editor/format-utils.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/code-mirror-editor/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks/use-watch-value/playground.cy.d.ts → components/code-mirror-editor/test/CodeEditor.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/code-mirror-editor/theme.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/code-mirror-editor/types.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/code-mirror-editor/utils.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/easyv-monaco-editor/easyv-monaco-editor.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/easyv-monaco-editor/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/easyv-monaco-editor/test/easyv-monaco-editor.cy.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/easyv-monaco-editor/types.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components/ai-components/ai-message-render/test/ai-message-render.cy.d.ts → components/easyv-reactgrid/test/easyv-react-grid.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/echarts-render/constants.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/echarts-render/echarts-render.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/echarts-render/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks/use-watch-value/use-watch-value.cy.d.ts → components/echarts-render/test/echarts.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/echarts-render/types.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/error-boundary/error-boundary.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/error-boundary/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/scroll-controller/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/scroll-controller/scroll-controller.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/shadow-dom/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/shadow-dom/shadow-dom.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/voice-animation/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/voice-animation/test/voice-animation.cy.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/components → components}/voice-animation/voice-animation.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-ai-agent-message/constants.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-ai-agent-message/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-ai-agent-message/types.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-ai-agent-message/use-ai-agent-message.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-ai-agent-message/utils.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-div-auto-scroll.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-document-unmount/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-document-unmount/use-document-unmount.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-initialized.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-socket-events/constant.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-socket-events/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-socket-events/types.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-socket-events/use-socket-events.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-tencent-sentence-recognition/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-tencent-sentence-recognition/use-tencent-sentence-recognition.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils/easyv-gui-helper/test/get-config-value.cy.d.ts → hooks/use-watch-value/playground.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils/easyv-gui-helper/test/get-new-config-from-value.cy.d.ts → hooks/use-watch-value/use-watch-value.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/hooks → hooks}/use-watch-value/use-watch-value.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/types → types}/ai-agent.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/types → types}/common.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/types → types}/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/ai-agent-message-manager/ai-agent-message-manager.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/ai-agent-message-manager/constants.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/ai-agent-message-manager/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/ai-agent-message-manager/types.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/ai-agent-message-manager/utils.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/common/common.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/common/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/common/url.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/common/voice-helper-utils.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/easyv-gui-helper/common.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/easyv-gui-helper/component-dimension.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/easyv-gui-helper/constants.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/easyv-gui-helper/easyv-gui-helper.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/easyv-gui-helper/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils/easyv-gui-helper/test/update-gui-config-list.cy.d.ts → utils/easyv-gui-helper/test/get-config-value.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils/vosk-browser-manager/audio-manager/test/audio-manager.cy.d.ts → utils/easyv-gui-helper/test/get-new-config-from-value.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/easyv-gui-helper/test/test-data.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils/vosk-browser-manager/test/voskBrowserManager.cy.d.ts → utils/easyv-gui-helper/test/update-gui-config-list.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/easyv-gui-helper/types.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/fetch-knowledge/fetch-knowledge.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/fetch-knowledge/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/fun-ASR/fun-ASR-manager.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/fun-ASR/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/show-modal/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/show-modal/show-modal.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils/xun-fei-voice/test/RecorderManager.cy.d.ts → utils/show-modal/test/show-modal.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/voice-record-manager/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/voice-record-manager/voice-record-manager.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/vosk-browser-manager/audio-manager/audio-manager.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils/xun-fei-voice/test/XunFeiVoiceManager.cy.d.ts → utils/vosk-browser-manager/audio-manager/test/audio-manager.cy.d.ts} +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/vosk-browser-manager/audio-manager/types.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/vosk-browser-manager/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/vosk-browser-manager/vosk-browser-manager.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/wait-something/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/xun-fei-voice/XF-stream-voice-manager.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/xun-fei-voice/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/xun-fei-voice/recorder-manager/RecorderManager-draft.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/xun-fei-voice/recorder-manager/index.d.ts +0 -0
- /package/dist/lib/{easyv-biz-components/src/utils → utils}/xun-fei-voice/types.d.ts +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { j as jsxRuntimeExports } from "../../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.es.js";
|
|
2
|
-
import {
|
|
2
|
+
import { Button } from "@easyv/react-components";
|
|
3
3
|
import classNames from "../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.es.js";
|
|
4
4
|
const IconButton = (props) => {
|
|
5
5
|
const { className = "", icon, onClick } = props;
|
|
6
6
|
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
7
|
-
|
|
7
|
+
Button,
|
|
8
8
|
{
|
|
9
9
|
className: classNames(
|
|
10
10
|
"!biz-bg-bg-white biz-h-[4.25rem] biz-w-[4.25rem]",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"icon-button.es.js","sources":["../../../../../src/components/ai-components/mobile-voice-input/icon-button.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"icon-button.es.js","sources":["../../../../../src/components/ai-components/mobile-voice-input/icon-button.tsx"],"sourcesContent":["import { Button } from \"@easyv/react-components\";\nimport classNames from \"classnames\";\n\nexport interface IconButtonProps {\n className?: string;\n icon?: React.ReactNode;\n onClick?: (e: Event) => void;\n}\n\n/** 输入框右侧的 图标控制按钮 */\nexport const IconButton = (props: IconButtonProps) => {\n const { className = \"\", icon, onClick } = props;\n\n return (\n <Button\n className={classNames(\n \"!biz-bg-bg-white biz-h-[4.25rem] biz-w-[4.25rem]\",\n \"biz-flex biz-flex-center biz-rounded-2xl biz-border-none\",\n className,\n )}\n icon={icon}\n onClick={onClick}\n />\n );\n};\n"],"names":["jsx"],"mappings":";;;AAUa,MAAA,aAAa,CAAC,UAA2B;AACpD,QAAM,EAAE,YAAY,IAAI,MAAM,QAAY,IAAA;AAGxC,SAAAA,kCAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAW;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { j as jsxRuntimeExports } from "../../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.es.js";
|
|
2
2
|
import { forwardRef, useState, useRef, useImperativeHandle } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { message, Input, Button } from "@easyv/react-components";
|
|
4
4
|
import { MouseOutlined, TerminationSquareOutlined, AudioOutlined, KeyboardOutlined, CloseCircleOutlined } from "../../../node_modules/.pnpm/@easyv_react-icons@6.13.1/node_modules/@easyv/react-icons/dist/index.esm.es.js";
|
|
5
5
|
import useMemoizedFn from "../../../node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useMemoizedFn/index.es.js";
|
|
6
6
|
import classNames from "../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.es.js";
|
|
@@ -58,12 +58,12 @@ const MobileVoiceInputCpn = (props, ref) => {
|
|
|
58
58
|
if (recordTime < 500) {
|
|
59
59
|
setVoiceRecognizeRes("");
|
|
60
60
|
needRequestAsr = false;
|
|
61
|
-
|
|
61
|
+
message.error("录音时间过短");
|
|
62
62
|
}
|
|
63
63
|
if (recordTime > 59 * 1e3) {
|
|
64
64
|
setVoiceRecognizeRes("");
|
|
65
65
|
needRequestAsr = false;
|
|
66
|
-
|
|
66
|
+
message.error("录音时间最多支持一分钟");
|
|
67
67
|
}
|
|
68
68
|
stopVoiceRecord(needRequestAsr);
|
|
69
69
|
}
|
|
@@ -133,7 +133,7 @@ const MobileVoiceInputCpn = (props, ref) => {
|
|
|
133
133
|
),
|
|
134
134
|
children: [
|
|
135
135
|
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
136
|
-
|
|
136
|
+
Input,
|
|
137
137
|
{
|
|
138
138
|
ref: inputRef,
|
|
139
139
|
value,
|
|
@@ -208,9 +208,9 @@ const MobileVoiceInputCpn = (props, ref) => {
|
|
|
208
208
|
),
|
|
209
209
|
children: [
|
|
210
210
|
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
211
|
-
|
|
211
|
+
Button,
|
|
212
212
|
{
|
|
213
|
-
className: "biz-rounded-2xl biz-gap-4 biz-h-[5rem] biz-px-8 biz-flex biz-flex-center biz-text-[2rem] !biz-bg-bg-1 !biz-text-white",
|
|
213
|
+
className: "biz-rounded-2xl biz-gap-4 biz-h-[5rem] biz-px-8 biz-flex biz-flex-center biz-text-[2rem] !biz-bg-bg-1 !biz-text-white rp-[span]:!ml-0",
|
|
214
214
|
icon: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
215
215
|
CloseCircleOutlined,
|
|
216
216
|
{
|
|
@@ -225,9 +225,9 @@ const MobileVoiceInputCpn = (props, ref) => {
|
|
|
225
225
|
}
|
|
226
226
|
),
|
|
227
227
|
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
228
|
-
|
|
228
|
+
Button,
|
|
229
229
|
{
|
|
230
|
-
className: "biz-rounded-2xl biz-gap-4 biz-h-[5rem] biz-px-8 biz-flex biz-flex-center biz-text-[2rem]",
|
|
230
|
+
className: "biz-rounded-2xl biz-gap-4 biz-h-[5rem] biz-px-8 biz-flex biz-flex-center biz-text-[2rem] rp-[span]:!ml-0",
|
|
231
231
|
type: "primary",
|
|
232
232
|
disabled: !voiceRecognizeRes,
|
|
233
233
|
icon: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mobile-voice-input.es.js","sources":["../../../../../src/components/ai-components/mobile-voice-input/mobile-voice-input.tsx"],"sourcesContent":["import React, { forwardRef, Ref, useImperativeHandle, useRef, useState } from \"react\";\nimport { ArcoButton, ArcoInput, ArcoInputRef, ArcoMessage } from \"@easyv/arco\";\nimport {\n AudioOutlined,\n CloseCircleOutlined,\n KeyboardOutlined,\n MouseOutlined,\n TerminationSquareOutlined,\n} from \"@easyv/react-icons\";\nimport { useMemoizedFn } from \"ahooks\";\nimport classNames from \"classnames\";\nimport { VoiceAnimation } from \"@/components/voice-animation\";\nimport { useTencentSentenceRecognition } from \"@/hooks\";\nimport { getIsPrivateDeployEnv } from \"@/utils\";\nimport { IconButton } from \"./icon-button\";\n\nexport interface MobileVoiceInputProps {\n className?: string;\n isAiAnswering?: boolean;\n onClickStartRecord?: () => void;\n onClickStopRecord?: () => void;\n onSend?: (value?: string) => void;\n onStop?: () => void;\n value?: string;\n onChange?: (value?: string) => void;\n getSentenceRecognizeRes: (data: Blob) => Promise<string>;\n /** 这个是本地语音识别管理器,用于在移动端识别语音。\n * - workspace 和 screen 里的 class 不一样, 而且没有迁移到 biz-components 中 所以先写个 any。\n * - workspace 里的 class 是 LocalMobileVoiceRecognitionManager ,screen 里的 class 是 LocalVoiceRecognitionManager\n */\n // localManager?: any;\n renderSomethingOnVoiceInput?: () => React.ReactNode;\n}\n\nexport interface MobileVoiceInputRef {\n setVoiceRecognizeRes: (value: string) => void;\n}\n\nconst MobileVoiceInputCpn = (props: MobileVoiceInputProps, ref: Ref<MobileVoiceInputRef>) => {\n const {\n className = \"\",\n isAiAnswering,\n onClickStartRecord,\n onClickStopRecord,\n onSend,\n onStop,\n value,\n onChange,\n getSentenceRecognizeRes,\n renderSomethingOnVoiceInput,\n } = props;\n const [voiceRecognizeRes, setVoiceRecognizeRes] = useState(\"\");\n const [isVoiceInput, setIsVoiceInput] = useState(false); // 是否使用语音输入\n const [focused, setFocused] = useState(false); // 是否聚焦\n const [recordStatus, setRecordStatus] = useState<\"init\" | \"recording\" | \"afterRecord\">(\"init\");\n const isRecording = recordStatus === \"recording\";\n\n const startRecordTimeRef = useRef<number>(0); // 时间小于 500 ms 和 大于 59 秒都不发给后端\n const inputRef = useRef<ArcoInputRef>(null);\n\n /** 是否展示语音识别结果的预览 */\n const showPreviewVoiceRecognizeRes =\n isVoiceInput && !isAiAnswering && recordStatus === \"afterRecord\";\n /** 是否展示语音识别的提示信息 */\n const showVoiceRecognizeHintInfo = isVoiceInput && !isAiAnswering && isRecording;\n\n const { startVoiceRecord, stopVoiceRecord, recognizeStatus } = useTencentSentenceRecognition({\n getSentenceRecognizeRes,\n onAsrResult: (result) => {\n // 本地录音不使用这个结果,依赖外部去设置 voiceRecognizeRes\n if (!getIsPrivateDeployEnv()) {\n setVoiceRecognizeRes(result);\n }\n },\n });\n\n useImperativeHandle(ref, () => ({\n setVoiceRecognizeRes,\n }));\n\n const toggleVoiceRecord = useMemoizedFn(() => {\n if (isAiAnswering || showPreviewVoiceRecognizeRes) {\n return;\n }\n if (!isRecording) {\n setRecordStatus(\"recording\");\n onClickStartRecord?.();\n startVoiceRecord();\n startRecordTimeRef.current = Date.now();\n } else {\n setRecordStatus(\"afterRecord\");\n onClickStopRecord?.();\n let needRequestAsr = true;\n const recordTime = Date.now() - startRecordTimeRef.current;\n if (recordTime < 500) {\n setVoiceRecognizeRes(\"\");\n needRequestAsr = false;\n ArcoMessage.error(\"录音时间过短\");\n }\n if (recordTime > 59 * 1000) {\n setVoiceRecognizeRes(\"\");\n needRequestAsr = false;\n ArcoMessage.error(\"录音时间最多支持一分钟\");\n }\n stopVoiceRecord(needRequestAsr);\n }\n });\n\n const handleSend = useMemoizedFn((_value?: string) => {\n setVoiceRecognizeRes(\"\");\n onChange?.(\"\");\n onSend?.(_value || value);\n });\n\n const placeholder = isAiAnswering ? \"正在回答中...\" : \"问点什么\";\n\n const sendButton = (\n <IconButton\n className={classNames(\"!biz-bg-primary-6\")}\n onClick={() => {\n handleSend();\n }}\n icon={\n <MouseOutlined\n className={classNames(\n \"biz-h-10 biz-w-10 biz-text-[2.5rem] biz-text-white biz--scale-x-100 biz-scale-y-100\",\n )}\n />\n }\n />\n );\n const stopButton = (\n <IconButton\n className={classNames(\"biz-bg-primary-1\")}\n onClick={() => {\n onStop?.();\n }}\n icon={\n <TerminationSquareOutlined className=\"biz-h-10 biz-w-10 biz-text-[2.5rem] !biz-text-[#3A89FE]\" />\n }\n />\n );\n const voiceButton = (\n <IconButton\n className={classNames(\"!biz-bg-bg-white\")}\n onClick={(e) => {\n setIsVoiceInput(true);\n e.stopPropagation();\n }}\n icon={<AudioOutlined className=\"biz-text-text-2 biz-h-10 biz-w-10 biz-text-[2.5rem]\" />}\n />\n );\n const keyboardButton = (\n <IconButton\n className={classNames(\"!biz-bg-bg-white\")}\n onClick={(e) => {\n setIsVoiceInput(false);\n e.stopPropagation();\n }}\n icon={<KeyboardOutlined className=\"biz-text-text-2 biz-h-10 biz-w-10 biz-text-[2.5rem]\" />}\n />\n );\n\n const inputDom = (\n <div\n className={classNames(\n \"biz-flex-center biz-h-[6rem] biz-rounded-3xl biz-pl-8 biz-pr-[0.875rem]\",\n \"biz-border-one biz-bg-bg-white !biz-border-[0.125rem]\",\n focused && \"!biz-border-primary-6\",\n )}\n >\n <ArcoInput\n ref={inputRef}\n value={value}\n placeholder={placeholder}\n className={classNames(\n \"biz-text-text-1 biz-flex biz-w-0 biz-flex-1 biz-resize-none biz-items-center biz-border-none biz-bg-transparent biz-text-[2rem]\",\n \"!biz-p-0 biz-font-normal biz-leading-[3rem] !biz-bg-transparent !biz-shadow-none\",\n )}\n onChange={(_value) => {\n onChange?.(_value);\n }}\n onFocus={() => setFocused(true)}\n onBlur={() => setFocused(false)}\n />\n {/* 控制按钮 */}\n <div className=\"biz-flex-center biz-h-[4.25rem] biz-w-[4.25rem] biz-rounded-2xl\">\n {isAiAnswering ? stopButton : <>{value ? sendButton : voiceButton}</>}\n </div>\n </div>\n );\n\n const disableVoiceInput = isAiAnswering; // 允许录制时点击结束\n const renderVoiceRecordDom = () => {\n if (isRecording || recognizeStatus === \"translating\") {\n return (\n <div className=\"biz-w-full biz-px-8 biz-py-6\">\n <div className=\"biz-flex-center biz-h-10\">\n <VoiceAnimation\n className=\"biz-h-[2.5rem] !biz-w-[26.25rem]\"\n barClassName=\"!biz-bg-[#fff]\"\n />\n </div>\n </div>\n );\n }\n return <span className=\"!biz-select-none\">{`点击开始说话`}</span>;\n };\n const renderVoiceInputDom = () => {\n if (showPreviewVoiceRecognizeRes) {\n return (\n <div className=\"voice-input-place-holder-dom biz-relative biz-h-[9.5rem] biz-w-full\"></div>\n );\n }\n return (\n <div\n className={classNames(\n \"biz-flex-center biz-relative biz-h-[6rem] biz-rounded-3xl biz-py-5\",\n \"biz-border-one biz-bg-primary-1 !biz-select-none !biz-border-[0.125rem]\",\n )}\n onClick={toggleVoiceRecord}\n onContextMenu={(e) => {\n e.preventDefault();\n }}\n >\n <div\n className=\"biz-flex-center biz-text-primary-6 biz-w-full !biz-select-none biz-text-[2rem]\"\n style={{\n opacity: disableVoiceInput ? 0.5 : 1,\n }}\n >\n {renderVoiceRecordDom()}\n </div>\n <div className=\"absolute left-0 top-0 z-10 h-full w-full bg-transparent\"></div>\n {/* 控制按钮 */}\n {!isRecording && (\n <div className=\"biz-flex-center biz-absolute biz-right-[0.875rem] biz-top-[0.875rem] biz-z-20 biz-h-[4.25rem] biz-w-[4.25rem] biz-rounded-2xl\">\n {isAiAnswering ? stopButton : keyboardButton}\n </div>\n )}\n </div>\n );\n };\n\n const voiceRecognizeResDom = (\n <div className=\"biz-absolute biz-z-10 biz-w-full biz-bg-transparent biz-left-0 biz-bottom-0\">\n <div className=\"biz-flex biz-flex-col biz-gap-8\">\n <div\n className={classNames(\n \"biz-text-[2rem] biz-leading-[4rem] biz-text-text-2\",\n \"biz-w-full biz-flex biz-flex-center biz-gap-9\",\n )}\n >\n <ArcoButton\n className=\"biz-rounded-2xl biz-gap-4 biz-h-[5rem] biz-px-8 biz-flex biz-flex-center biz-text-[2rem] !biz-bg-bg-1 !biz-text-white\"\n icon={\n <CloseCircleOutlined\n className={classNames(\"biz-h-10 biz-w-10 biz-text-[2.5rem] biz-text-white\")}\n />\n }\n onClick={() => {\n setVoiceRecognizeRes(\"\");\n setRecordStatus(\"init\");\n }}\n >\n 取消\n </ArcoButton>\n <ArcoButton\n className=\"biz-rounded-2xl biz-gap-4 biz-h-[5rem] biz-px-8 biz-flex biz-flex-center biz-text-[2rem]\"\n type=\"primary\"\n disabled={!voiceRecognizeRes}\n icon={\n <MouseOutlined\n className={classNames(\n \"biz-h-10 biz-w-10 biz-text-[2.5rem] biz--scale-x-100 biz-scale-y-100 biz-text-inherit\",\n )}\n />\n }\n onClick={() => {\n if (!voiceRecognizeRes) {\n return;\n }\n setRecordStatus(\"init\");\n handleSend(voiceRecognizeRes);\n }}\n >\n 发送\n </ArcoButton>\n </div>\n <div className=\"voice-recognize-res-dom biz-w-full biz-pb-6 biz-px-8\">\n <textarea\n placeholder=\"未识别到内容\"\n value={voiceRecognizeRes}\n className={classNames(\n \"biz-w-full biz-px-8 biz-py-7 biz-rounded-3xl biz-text-text-1 biz-text-[2rem]\",\n \"biz-border-solid biz-border-[2px] biz-border-[rgba(58,137,254,0.1)]\",\n \"biz-bg-[rgba(58,137,254,0.1)] biz-h-[8rem]\",\n )}\n onClick={(e) => e.stopPropagation()}\n onChange={(e) => {\n e.stopPropagation();\n setVoiceRecognizeRes(e.target.value);\n }}\n />\n </div>\n </div>\n </div>\n );\n\n return (\n <div\n className={classNames(\n \"biz-w-full biz-px-8 biz-py-6 biz-relative biz-flex biz-flex-col biz-gap-6\",\n className,\n )}\n >\n {showPreviewVoiceRecognizeRes && voiceRecognizeResDom}\n\n {showVoiceRecognizeHintInfo && (\n <div\n className={classNames(\n \"biz-text-[2rem] biz-leading-[4rem] biz-text-text-2\",\n \"biz-w-full biz-flex biz-flex-center\",\n )}\n >\n 正在聆听,点击结束\n </div>\n )}\n {!showPreviewVoiceRecognizeRes && renderSomethingOnVoiceInput?.()}\n {isVoiceInput ? renderVoiceInputDom() : inputDom}\n </div>\n );\n};\n\nexport const MobileVoiceInput = forwardRef(MobileVoiceInputCpn);\n"],"names":["jsx","jsxs","Fragment"],"mappings":";;;;;;;;;;AAsCA,MAAM,sBAAsB,CAAC,OAA8B,QAAkC;AACrF,QAAA;AAAA,IACJ,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,IACE;AACJ,QAAM,CAAC,mBAAmB,oBAAoB,IAAI,SAAS,EAAE;AAC7D,QAAM,CAAC,cAAc,eAAe,IAAI,SAAS,KAAK;AACtD,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAC5C,QAAM,CAAC,cAAc,eAAe,IAAI,SAA+C,MAAM;AAC7F,QAAM,cAAc,iBAAiB;AAE/B,QAAA,qBAAqB,OAAe,CAAC;AACrC,QAAA,WAAW,OAAqB,IAAI;AAG1C,QAAM,+BACJ,gBAAgB,CAAC,iBAAiB,iBAAiB;AAE/C,QAAA,6BAA6B,gBAAgB,CAAC,iBAAiB;AAErE,QAAM,EAAE,kBAAkB,iBAAiB,gBAAA,IAAoB,8BAA8B;AAAA,IAC3F;AAAA,IACA,aAAa,CAAC,WAAW;AAEnB,UAAA,CAAC,yBAAyB;AAC5B,6BAAqB,MAAM;AAAA,MAAA;AAAA,IAC7B;AAAA,EACF,CACD;AAED,sBAAoB,KAAK,OAAO;AAAA,IAC9B;AAAA,EAAA,EACA;AAEI,QAAA,oBAAoB,cAAc,MAAM;AAC5C,QAAI,iBAAiB,8BAA8B;AACjD;AAAA,IAAA;AAEF,QAAI,CAAC,aAAa;AAChB,sBAAgB,WAAW;AACN;AACJ,uBAAA;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WAAU;AAAA,cACV,MAAK;AAAA,cACL,UAAU,CAAC;AAAA,cACX,MACEA,kCAAA;AAAA,gBAAC;AAAA,gBAAA;AAAA,kBACC,WAAW;AAAA,oBACT;AAAA,kBAAA;AAAA,gBACF;AAAA,cACF;AAAA,cAEF,SAAS,MAAM;AACb,oBAAI,CAAC,mBAAmB;AACtB;AAAA,gBAAA;AAEF,gCAAgB,MAAM;AACtB,2BAAW,iBAAiB;AAAA,cAC9B;AAAA,cACD,UAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QAED;AAAA,MAAA;AAAA,IACF;AAAA,IACAA,kCAAAA,IAAC,OAAI,EAAA,WAAU,wDACb,UAAAA,kCAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,aAAY;AAAA,QACZ,OAAO;AAAA,QACP,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,QACA,SAAS,CAAC,MAAM,EAAE,gBAAgB;AAAA,QAClC,UAAU,CAAC,MAAM;AACf,YAAE,gBAAgB;AACG,+BAAA,EAAE,OAAO,KAAK;AAAA,QAAA;AAAA,MACrC;AAAA,IAAA,EAEJ,CAAA;AAAA,EAAA,EAAA,CACF,EACF,CAAA;AAIA,SAAAC,kCAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAW;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,MAEC,UAAA;AAAA,QAAgC,gCAAA;AAAA,QAEhC,8BACCD,kCAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAW;AAAA,cACT;AAAA,cACA;AAAA,YACF;AAAA,YACD,UAAA;AAAA,UAAA;AAAA,QAED;AAAA,QAED,CAAC,iCAAgC;AAAA,QACjC,eAAe,wBAAwB;AAAA,MAAA;AAAA,IAAA;AAAA,EAC1C;AAEJ;AAEa,MAAA,mBAAmB,WAAW,mBAAmB;"}
|
|
1
|
+
{"version":3,"file":"mobile-voice-input.es.js","sources":["../../../../../src/components/ai-components/mobile-voice-input/mobile-voice-input.tsx"],"sourcesContent":["import React, { forwardRef, Ref, useImperativeHandle, useRef, useState } from \"react\";\nimport { Button, Input, message, RefInputType } from \"@easyv/react-components\";\nimport {\n AudioOutlined,\n CloseCircleOutlined,\n KeyboardOutlined,\n MouseOutlined,\n TerminationSquareOutlined,\n} from \"@easyv/react-icons\";\nimport { useMemoizedFn } from \"ahooks\";\nimport classNames from \"classnames\";\nimport { VoiceAnimation } from \"@/components/voice-animation\";\nimport { useTencentSentenceRecognition } from \"@/hooks\";\nimport { getIsPrivateDeployEnv } from \"@/utils\";\nimport { IconButton } from \"./icon-button\";\n\nexport interface MobileVoiceInputProps {\n className?: string;\n isAiAnswering?: boolean;\n onClickStartRecord?: () => void;\n onClickStopRecord?: () => void;\n onSend?: (value?: string) => void;\n onStop?: () => void;\n value?: string;\n onChange?: (value?: string) => void;\n getSentenceRecognizeRes: (data: Blob) => Promise<string>;\n /** 这个是本地语音识别管理器,用于在移动端识别语音。\n * - workspace 和 screen 里的 class 不一样, 而且没有迁移到 biz-components 中 所以先写个 any。\n * - workspace 里的 class 是 LocalMobileVoiceRecognitionManager ,screen 里的 class 是 LocalVoiceRecognitionManager\n */\n // localManager?: any;\n renderSomethingOnVoiceInput?: () => React.ReactNode;\n}\n\nexport interface MobileVoiceInputRef {\n setVoiceRecognizeRes: (value: string) => void;\n}\n\nconst MobileVoiceInputCpn = (props: MobileVoiceInputProps, ref: Ref<MobileVoiceInputRef>) => {\n const {\n className = \"\",\n isAiAnswering,\n onClickStartRecord,\n onClickStopRecord,\n onSend,\n onStop,\n value,\n onChange,\n getSentenceRecognizeRes,\n renderSomethingOnVoiceInput,\n } = props;\n const [voiceRecognizeRes, setVoiceRecognizeRes] = useState(\"\");\n const [isVoiceInput, setIsVoiceInput] = useState(false); // 是否使用语音输入\n const [focused, setFocused] = useState(false); // 是否聚焦\n const [recordStatus, setRecordStatus] = useState<\"init\" | \"recording\" | \"afterRecord\">(\"init\");\n const isRecording = recordStatus === \"recording\";\n\n const startRecordTimeRef = useRef<number>(0); // 时间小于 500 ms 和 大于 59 秒都不发给后端\n const inputRef = useRef<RefInputType>(null);\n\n /** 是否展示语音识别结果的预览 */\n const showPreviewVoiceRecognizeRes =\n isVoiceInput && !isAiAnswering && recordStatus === \"afterRecord\";\n /** 是否展示语音识别的提示信息 */\n const showVoiceRecognizeHintInfo = isVoiceInput && !isAiAnswering && isRecording;\n\n const { startVoiceRecord, stopVoiceRecord, recognizeStatus } = useTencentSentenceRecognition({\n getSentenceRecognizeRes,\n onAsrResult: (result) => {\n // 本地录音不使用这个结果,依赖外部去设置 voiceRecognizeRes\n if (!getIsPrivateDeployEnv()) {\n setVoiceRecognizeRes(result);\n }\n },\n });\n\n useImperativeHandle(ref, () => ({\n setVoiceRecognizeRes,\n }));\n\n const toggleVoiceRecord = useMemoizedFn(() => {\n if (isAiAnswering || showPreviewVoiceRecognizeRes) {\n return;\n }\n if (!isRecording) {\n setRecordStatus(\"recording\");\n onClickStartRecord?.();\n startVoiceRecord();\n startRecordTimeRef.current = Date.now();\n } else {\n setRecordStatus(\"afterRecord\");\n onClickStopRecord?.();\n let needRequestAsr = true;\n const recordTime = Date.now() - startRecordTimeRef.current;\n if (recordTime < 500) {\n setVoiceRecognizeRes(\"\");\n needRequestAsr = false;\n message.error(\"录音时间过短\");\n }\n if (recordTime > 59 * 1000) {\n setVoiceRecognizeRes(\"\");\n needRequestAsr = false;\n message.error(\"录音时间最多支持一分钟\");\n }\n stopVoiceRecord(needRequestAsr);\n }\n });\n\n const handleSend = useMemoizedFn((_value?: string) => {\n setVoiceRecognizeRes(\"\");\n onChange?.(\"\");\n onSend?.(_value || value);\n });\n\n const placeholder = isAiAnswering ? \"正在回答中...\" : \"问点什么\";\n\n const sendButton = (\n <IconButton\n className={classNames(\"!biz-bg-primary-6\")}\n onClick={() => {\n handleSend();\n }}\n icon={\n <MouseOutlined\n className={classNames(\n \"biz-h-10 biz-w-10 biz-text-[2.5rem] biz-text-white biz--scale-x-100 biz-scale-y-100\",\n )}\n />\n }\n />\n );\n const stopButton = (\n <IconButton\n className={classNames(\"biz-bg-primary-1\")}\n onClick={() => {\n onStop?.();\n }}\n icon={\n <TerminationSquareOutlined className=\"biz-h-10 biz-w-10 biz-text-[2.5rem] !biz-text-[#3A89FE]\" />\n }\n />\n );\n const voiceButton = (\n <IconButton\n className={classNames(\"!biz-bg-bg-white\")}\n onClick={(e) => {\n setIsVoiceInput(true);\n e.stopPropagation();\n }}\n icon={<AudioOutlined className=\"biz-text-text-2 biz-h-10 biz-w-10 biz-text-[2.5rem]\" />}\n />\n );\n const keyboardButton = (\n <IconButton\n className={classNames(\"!biz-bg-bg-white\")}\n onClick={(e) => {\n setIsVoiceInput(false);\n e.stopPropagation();\n }}\n icon={<KeyboardOutlined className=\"biz-text-text-2 biz-h-10 biz-w-10 biz-text-[2.5rem]\" />}\n />\n );\n\n const inputDom = (\n <div\n className={classNames(\n \"biz-flex-center biz-h-[6rem] biz-rounded-3xl biz-pl-8 biz-pr-[0.875rem]\",\n \"biz-border-one biz-bg-bg-white !biz-border-[0.125rem]\",\n focused && \"!biz-border-primary-6\",\n )}\n >\n <Input\n ref={inputRef}\n value={value}\n placeholder={placeholder}\n className={classNames(\n \"biz-text-text-1 biz-flex biz-w-0 biz-flex-1 biz-resize-none biz-items-center biz-border-none biz-bg-transparent biz-text-[2rem]\",\n \"!biz-p-0 biz-font-normal biz-leading-[3rem] !biz-bg-transparent !biz-shadow-none\",\n )}\n onChange={(_value) => {\n onChange?.(_value);\n }}\n onFocus={() => setFocused(true)}\n onBlur={() => setFocused(false)}\n />\n {/* 控制按钮 */}\n <div className=\"biz-flex-center biz-h-[4.25rem] biz-w-[4.25rem] biz-rounded-2xl\">\n {isAiAnswering ? stopButton : <>{value ? sendButton : voiceButton}</>}\n </div>\n </div>\n );\n\n const disableVoiceInput = isAiAnswering; // 允许录制时点击结束\n const renderVoiceRecordDom = () => {\n if (isRecording || recognizeStatus === \"translating\") {\n return (\n <div className=\"biz-w-full biz-px-8 biz-py-6\">\n <div className=\"biz-flex-center biz-h-10\">\n <VoiceAnimation\n className=\"biz-h-[2.5rem] !biz-w-[26.25rem]\"\n barClassName=\"!biz-bg-[#fff]\"\n />\n </div>\n </div>\n );\n }\n return <span className=\"!biz-select-none\">{`点击开始说话`}</span>;\n };\n const renderVoiceInputDom = () => {\n if (showPreviewVoiceRecognizeRes) {\n return (\n <div className=\"voice-input-place-holder-dom biz-relative biz-h-[9.5rem] biz-w-full\"></div>\n );\n }\n return (\n <div\n className={classNames(\n \"biz-flex-center biz-relative biz-h-[6rem] biz-rounded-3xl biz-py-5\",\n \"biz-border-one biz-bg-primary-1 !biz-select-none !biz-border-[0.125rem]\",\n )}\n onClick={toggleVoiceRecord}\n onContextMenu={(e) => {\n e.preventDefault();\n }}\n >\n <div\n className=\"biz-flex-center biz-text-primary-6 biz-w-full !biz-select-none biz-text-[2rem]\"\n style={{\n opacity: disableVoiceInput ? 0.5 : 1,\n }}\n >\n {renderVoiceRecordDom()}\n </div>\n <div className=\"absolute left-0 top-0 z-10 h-full w-full bg-transparent\"></div>\n {/* 控制按钮 */}\n {!isRecording && (\n <div className=\"biz-flex-center biz-absolute biz-right-[0.875rem] biz-top-[0.875rem] biz-z-20 biz-h-[4.25rem] biz-w-[4.25rem] biz-rounded-2xl\">\n {isAiAnswering ? stopButton : keyboardButton}\n </div>\n )}\n </div>\n );\n };\n\n const voiceRecognizeResDom = (\n <div className=\"biz-absolute biz-z-10 biz-w-full biz-bg-transparent biz-left-0 biz-bottom-0\">\n <div className=\"biz-flex biz-flex-col biz-gap-8\">\n <div\n className={classNames(\n \"biz-text-[2rem] biz-leading-[4rem] biz-text-text-2\",\n \"biz-w-full biz-flex biz-flex-center biz-gap-9\",\n )}\n >\n <Button\n className=\"biz-rounded-2xl biz-gap-4 biz-h-[5rem] biz-px-8 biz-flex biz-flex-center biz-text-[2rem] !biz-bg-bg-1 !biz-text-white rp-[span]:!ml-0\"\n icon={\n <CloseCircleOutlined\n className={classNames(\"biz-h-10 biz-w-10 biz-text-[2.5rem] biz-text-white\")}\n />\n }\n onClick={() => {\n setVoiceRecognizeRes(\"\");\n setRecordStatus(\"init\");\n }}\n >\n 取消\n </Button>\n <Button\n className=\"biz-rounded-2xl biz-gap-4 biz-h-[5rem] biz-px-8 biz-flex biz-flex-center biz-text-[2rem] rp-[span]:!ml-0\"\n type=\"primary\"\n disabled={!voiceRecognizeRes}\n icon={\n <MouseOutlined\n className={classNames(\n \"biz-h-10 biz-w-10 biz-text-[2.5rem] biz--scale-x-100 biz-scale-y-100 biz-text-inherit\",\n )}\n />\n }\n onClick={() => {\n if (!voiceRecognizeRes) {\n return;\n }\n setRecordStatus(\"init\");\n handleSend(voiceRecognizeRes);\n }}\n >\n 发送\n </Button>\n </div>\n <div className=\"voice-recognize-res-dom biz-w-full biz-pb-6 biz-px-8\">\n <textarea\n placeholder=\"未识别到内容\"\n value={voiceRecognizeRes}\n className={classNames(\n \"biz-w-full biz-px-8 biz-py-7 biz-rounded-3xl biz-text-text-1 biz-text-[2rem]\",\n \"biz-border-solid biz-border-[2px] biz-border-[rgba(58,137,254,0.1)]\",\n \"biz-bg-[rgba(58,137,254,0.1)] biz-h-[8rem]\",\n )}\n onClick={(e) => e.stopPropagation()}\n onChange={(e) => {\n e.stopPropagation();\n setVoiceRecognizeRes(e.target.value);\n }}\n />\n </div>\n </div>\n </div>\n );\n\n return (\n <div\n className={classNames(\n \"biz-w-full biz-px-8 biz-py-6 biz-relative biz-flex biz-flex-col biz-gap-6\",\n className,\n )}\n >\n {showPreviewVoiceRecognizeRes && voiceRecognizeResDom}\n\n {showVoiceRecognizeHintInfo && (\n <div\n className={classNames(\n \"biz-text-[2rem] biz-leading-[4rem] biz-text-text-2\",\n \"biz-w-full biz-flex biz-flex-center\",\n )}\n >\n 正在聆听,点击结束\n </div>\n )}\n {!showPreviewVoiceRecognizeRes && renderSomethingOnVoiceInput?.()}\n {isVoiceInput ? renderVoiceInputDom() : inputDom}\n </div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AA,cAEF,SAAS,MAAM;AACb,oBAAI,CAAC,mBAAmB;AACtB;AAAA,gBAAA;AAEF,gCAAgB,MAAM;AACtB,2BAAW,iBAAiB;AAAA,cAC9B;AAAA,cACD,UAAA;AAAA,YAAA;AAAA,UAAA;AAAA,QAED;AAAA,MAAA;AAAA,IACF;AAAA,IACAA,kCAAAA,IAAC,OAAI,EAAA,WAAU,wDACb,UAAAA,kCAAA;AAAA,MAAC;AAAA,MAAA;AAAA,QACC,aAAY;AAAA,QACZ,OAAO;AAAA,QACP,WAAW;AAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,QACA,SAAS,CAAC,MAAM,EAAE,gBAAgB;AAAA,QAClC,UAAU,CAAC,MAAM;AACf,YAAE,gBAAgB;AACG,+BAAA,EAAE,OAAO,KAAK;AAAA,QAAA;AAAA,MACrC;AAAA,IAAA,EAEJ,CAAA;AAAA,EAAA,EAAA,CACF,EACF,CAAA;AAIA,SAAAC,kCAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,WAAW;AAAA,QACT;AAAA,QACA;AAAA,MACF;AAAA,MAEC,UAAA;AAAA,QAAgC,gCAAA;AAAA,QAEhC,8BACCD,kCAAA;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,WAAW;AAAA,cACT;AAAA,cACA;AAAA,YACF;AAAA,YACD,UAAA;AAAA,UAAA;AAAA,QAED;AAAA,QAED,CAAC,iCAAgC;AAAA,QACjC,eAAe,wBAAwB;AAAA,MAAA;AAAA,IAAA;AAAA,EAC1C;AAEJ;AAEa,MAAA,mBAAmB,WAAW,mBAAmB;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.es.js","sources":["../../../../src/components/easyv-reactgrid/constants.ts"],"sourcesContent":["export const menuLabelMap = {\n copy: \"复制\",\n cut: \"剪切\",\n paste: \"粘贴\",\n};\n"],"names":[],"mappings":"AAAO,MAAM,eAAe;AAAA,EAC1B,MAAM;AAAA,EACN,KAAK;AAAA,EACL,OAAO;AACT;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { ReactGridProps } from '@silevis/reactgrid';
|
|
3
|
+
|
|
4
|
+
export interface EasyvReactGridProps extends Omit<ReactGridProps, "columns" | "rows"> {
|
|
5
|
+
columns?: ReactGridProps["columns"];
|
|
6
|
+
rows?: ReactGridProps["rows"];
|
|
7
|
+
wrapClassName?: string;
|
|
8
|
+
wrapStyle?: React.CSSProperties;
|
|
9
|
+
data?: (string | number)[][];
|
|
10
|
+
onDataChange?: (data: (string | number)[][]) => void;
|
|
11
|
+
expandMinGrid?: boolean;
|
|
12
|
+
minRows?: number;
|
|
13
|
+
minCols?: number;
|
|
14
|
+
}
|
|
15
|
+
export declare const EasyvReactGrid: (props: EasyvReactGridProps) => JSX.Element;
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { j as jsxRuntimeExports } from "../../node_modules/.pnpm/react@18.2.0/node_modules/react/jsx-runtime.es.js";
|
|
2
|
+
import { useState, useMemo } from "react";
|
|
3
|
+
import { ReactGrid } from "@silevis/reactgrid";
|
|
4
|
+
/* empty css */
|
|
5
|
+
import classNames from "../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.es.js";
|
|
6
|
+
import { produce } from "../../node_modules/.pnpm/immer@10.1.1/node_modules/immer/dist/immer.es.js";
|
|
7
|
+
import { menuLabelMap } from "./constants.es.js";
|
|
8
|
+
import styles from "./easyv-react-grid.module.less.es.js";
|
|
9
|
+
import { getColumnLabel } from "./utils.es.js";
|
|
10
|
+
const EasyvReactGrid = (props) => {
|
|
11
|
+
const {
|
|
12
|
+
wrapClassName = "",
|
|
13
|
+
wrapStyle,
|
|
14
|
+
data,
|
|
15
|
+
onDataChange,
|
|
16
|
+
columns: propsColumns,
|
|
17
|
+
rows: propsRows,
|
|
18
|
+
expandMinGrid = true,
|
|
19
|
+
disableVirtualScrolling = true,
|
|
20
|
+
...restProps
|
|
21
|
+
} = props;
|
|
22
|
+
const [columnWidths, setColumnWidths] = useState({});
|
|
23
|
+
const [rowHeights, setRowHeights] = useState({});
|
|
24
|
+
const [selectedCellKeys, setSelectedCellKeys] = useState(/* @__PURE__ */ new Set());
|
|
25
|
+
const dataProps = useMemo(() => {
|
|
26
|
+
var _a;
|
|
27
|
+
if (!data) return null;
|
|
28
|
+
const colsCount = ((_a = data[0]) == null ? void 0 : _a.length) || 0;
|
|
29
|
+
const rowsCount = data.length || 0;
|
|
30
|
+
const minRows = props.minRows ?? 50;
|
|
31
|
+
const minCols = props.minCols ?? 26;
|
|
32
|
+
const displayRowsCount = expandMinGrid ? Math.max(rowsCount, minRows) : rowsCount;
|
|
33
|
+
const displayColsCount = expandMinGrid ? Math.max(colsCount, minCols) : colsCount;
|
|
34
|
+
const columns = [
|
|
35
|
+
{ columnId: "header-col", width: columnWidths["header-col"] ?? 75, resizable: true },
|
|
36
|
+
// 行头列
|
|
37
|
+
...Array.from({ length: displayColsCount }).map((_, idx) => ({
|
|
38
|
+
columnId: String(idx),
|
|
39
|
+
width: columnWidths[String(idx)] ?? 100,
|
|
40
|
+
resizable: true
|
|
41
|
+
}))
|
|
42
|
+
];
|
|
43
|
+
const headerRowStyle = {
|
|
44
|
+
background: "#252830",
|
|
45
|
+
color: "#c9cbd3"
|
|
46
|
+
};
|
|
47
|
+
const headerRow = {
|
|
48
|
+
rowId: "header-row",
|
|
49
|
+
height: rowHeights["header-row"] ?? 32,
|
|
50
|
+
cells: [
|
|
51
|
+
{
|
|
52
|
+
type: "header",
|
|
53
|
+
text: "",
|
|
54
|
+
style: { ...headerRowStyle }
|
|
55
|
+
},
|
|
56
|
+
...Array.from({ length: displayColsCount }).map(
|
|
57
|
+
(_, idx) => ({
|
|
58
|
+
type: "header",
|
|
59
|
+
text: getColumnLabel(idx),
|
|
60
|
+
style: { ...headerRowStyle }
|
|
61
|
+
})
|
|
62
|
+
)
|
|
63
|
+
],
|
|
64
|
+
resizable: true
|
|
65
|
+
};
|
|
66
|
+
const dataRows = Array.from({ length: displayRowsCount }).map((_, rowIndex) => {
|
|
67
|
+
const rowArr = rowIndex < rowsCount ? data[rowIndex] : [];
|
|
68
|
+
const cells = [
|
|
69
|
+
{
|
|
70
|
+
type: "header",
|
|
71
|
+
text: String(rowIndex + 1),
|
|
72
|
+
style: {
|
|
73
|
+
background: "#252830",
|
|
74
|
+
borderColor: "#292c34",
|
|
75
|
+
color: "#c9cbd3",
|
|
76
|
+
borderRightColor: "#50535e"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
...Array.from({ length: displayColsCount }).map((_2, colIndex) => {
|
|
80
|
+
const cellKey = `${rowIndex}:${colIndex}`;
|
|
81
|
+
const isSelected = selectedCellKeys.has(cellKey);
|
|
82
|
+
const baseStyle = isSelected ? { background: "#1c2338", borderColor: "#337efe" } : void 0;
|
|
83
|
+
const hasValue = colIndex < colsCount && rowIndex < rowsCount;
|
|
84
|
+
const cellValue = hasValue ? rowArr[colIndex] : "";
|
|
85
|
+
return { type: "text", text: String(cellValue), style: baseStyle };
|
|
86
|
+
})
|
|
87
|
+
];
|
|
88
|
+
return {
|
|
89
|
+
rowId: String(rowIndex),
|
|
90
|
+
height: rowHeights[String(rowIndex)] ?? 32,
|
|
91
|
+
cells,
|
|
92
|
+
resizable: true
|
|
93
|
+
};
|
|
94
|
+
});
|
|
95
|
+
const rows = [headerRow, ...dataRows];
|
|
96
|
+
return { columns, rows };
|
|
97
|
+
}, [
|
|
98
|
+
data,
|
|
99
|
+
props.minRows,
|
|
100
|
+
props.minCols,
|
|
101
|
+
expandMinGrid,
|
|
102
|
+
columnWidths,
|
|
103
|
+
rowHeights,
|
|
104
|
+
selectedCellKeys
|
|
105
|
+
]);
|
|
106
|
+
const finalColumns = dataProps ? dataProps.columns : propsColumns;
|
|
107
|
+
const finalRows = dataProps ? dataProps.rows : propsRows;
|
|
108
|
+
const handleCellsChanged = (changes) => {
|
|
109
|
+
var _a;
|
|
110
|
+
if (!data || !onDataChange) {
|
|
111
|
+
(_a = restProps.onCellsChanged) == null ? void 0 : _a.call(restProps, changes);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const newData = produce(data, (draft) => {
|
|
115
|
+
changes.forEach((change) => {
|
|
116
|
+
var _a2, _b, _c;
|
|
117
|
+
const rowIndex = Number(change.rowId);
|
|
118
|
+
const colIndex = Number(change.columnId);
|
|
119
|
+
if (change.rowId === "header-row" || change.columnId === "header-col") return;
|
|
120
|
+
if (!Number.isNaN(rowIndex) && !Number.isNaN(colIndex)) {
|
|
121
|
+
const currentRows = draft.length;
|
|
122
|
+
const currentCols = ((_a2 = draft[0]) == null ? void 0 : _a2.length) || 0;
|
|
123
|
+
const requiredCols = Math.max(currentCols, colIndex + 1);
|
|
124
|
+
if (rowIndex >= currentRows) {
|
|
125
|
+
const toAdd = rowIndex + 1 - currentRows;
|
|
126
|
+
for (let i = 0; i < toAdd; i++) {
|
|
127
|
+
draft.push(new Array(requiredCols).fill(""));
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (requiredCols > currentCols) {
|
|
131
|
+
for (let r = 0; r < draft.length; r++) {
|
|
132
|
+
while ((((_b = draft[r]) == null ? void 0 : _b.length) || 0) < requiredCols) {
|
|
133
|
+
draft[r].push("");
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (change.newCell.type === "number") {
|
|
138
|
+
draft[rowIndex][colIndex] = change.newCell.value;
|
|
139
|
+
} else if (change.newCell.type === "text") {
|
|
140
|
+
draft[rowIndex][colIndex] = change.newCell.text;
|
|
141
|
+
} else {
|
|
142
|
+
draft[rowIndex][colIndex] = ((_c = change.newCell) == null ? void 0 : _c.text) ?? "";
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
onDataChange(newData);
|
|
148
|
+
};
|
|
149
|
+
const insertRow = (targetIndex, position) => {
|
|
150
|
+
if (!data || !onDataChange) return;
|
|
151
|
+
const newData = produce(data, (draft) => {
|
|
152
|
+
var _a;
|
|
153
|
+
const insertIdx = position === "above" ? targetIndex : targetIndex + 1;
|
|
154
|
+
const colsCount = ((_a = draft[0]) == null ? void 0 : _a.length) || 0;
|
|
155
|
+
const newRow = new Array(colsCount).fill("");
|
|
156
|
+
draft.splice(insertIdx, 0, newRow);
|
|
157
|
+
});
|
|
158
|
+
onDataChange(newData);
|
|
159
|
+
};
|
|
160
|
+
const insertColumn = (targetIndex, position) => {
|
|
161
|
+
if (!data || !onDataChange) return;
|
|
162
|
+
const newData = produce(data, (draft) => {
|
|
163
|
+
const insertIdx = position === "left" ? targetIndex : targetIndex + 1;
|
|
164
|
+
draft.forEach((row) => {
|
|
165
|
+
row.splice(insertIdx, 0, "");
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
onDataChange(newData);
|
|
169
|
+
};
|
|
170
|
+
const handleContextMenu = (selectedRowIds, selectedColIds, _selectionMode, menuOptions) => {
|
|
171
|
+
var _a;
|
|
172
|
+
const immediateHideMenu = () => {
|
|
173
|
+
const menu2 = document.querySelector(".rg-context-menu");
|
|
174
|
+
if (menu2) {
|
|
175
|
+
menu2.style.opacity = "0";
|
|
176
|
+
menu2.style.pointerEvents = "none";
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
if (menu2) {
|
|
179
|
+
menu2.style.opacity = "";
|
|
180
|
+
menu2.style.pointerEvents = "";
|
|
181
|
+
}
|
|
182
|
+
}, 300);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const menu = document.querySelector(".rg-context-menu");
|
|
186
|
+
if (((_a = menu == null ? void 0 : menu.style) == null ? void 0 : _a.visibility) === "visible") {
|
|
187
|
+
immediateHideMenu();
|
|
188
|
+
}
|
|
189
|
+
const rowIndices = selectedRowIds.map((id) => Number(id)).filter((idx) => !Number.isNaN(idx) && idx >= 0).sort((a, b) => a - b);
|
|
190
|
+
const colIndices = selectedColIds.map((id) => Number(id)).filter((idx) => !Number.isNaN(idx) && idx >= 0).sort((a, b) => a - b);
|
|
191
|
+
const options = [];
|
|
192
|
+
if (rowIndices.length > 0) {
|
|
193
|
+
options.push(
|
|
194
|
+
{
|
|
195
|
+
id: "insertRowAbove",
|
|
196
|
+
label: "向上插入一行",
|
|
197
|
+
handler: () => () => insertRow(rowIndices[0], "above")
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
id: "insertRowBelow",
|
|
201
|
+
label: "向下插入一行",
|
|
202
|
+
handler: () => () => insertRow(rowIndices[rowIndices.length - 1], "below")
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
if (colIndices.length > 0) {
|
|
207
|
+
options.push(
|
|
208
|
+
{
|
|
209
|
+
id: "insertColumnLeft",
|
|
210
|
+
label: "向左插入一列",
|
|
211
|
+
handler: () => () => insertColumn(colIndices[0], "left")
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
id: "insertColumnRight",
|
|
215
|
+
label: "向右插入一列",
|
|
216
|
+
handler: () => () => insertColumn(colIndices[colIndices.length - 1], "right")
|
|
217
|
+
}
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
const originMenuOptions = menuOptions.map((item) => ({
|
|
221
|
+
...item,
|
|
222
|
+
label: menuLabelMap[item.id] || item.label
|
|
223
|
+
}));
|
|
224
|
+
return [...originMenuOptions, ...options];
|
|
225
|
+
};
|
|
226
|
+
const handleColumnResized = (columnId, width, _selectedColIds) => {
|
|
227
|
+
setColumnWidths((prev) => ({
|
|
228
|
+
...prev,
|
|
229
|
+
[String(columnId)]: width
|
|
230
|
+
}));
|
|
231
|
+
};
|
|
232
|
+
const handleRowResized = (rowId, height, _selectedRowIds) => {
|
|
233
|
+
setRowHeights((prev) => ({
|
|
234
|
+
...prev,
|
|
235
|
+
[String(rowId)]: height
|
|
236
|
+
}));
|
|
237
|
+
};
|
|
238
|
+
const handleSelectionChanged = (selectedRanges) => {
|
|
239
|
+
const keys = /* @__PURE__ */ new Set();
|
|
240
|
+
(selectedRanges || []).forEach((range) => {
|
|
241
|
+
if (Array.isArray(range)) {
|
|
242
|
+
range.forEach((loc) => {
|
|
243
|
+
if (loc && loc.rowId !== void 0 && loc.columnId !== void 0) {
|
|
244
|
+
keys.add(`${String(loc.rowId)}:${String(loc.columnId)}`);
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
} else if (range && Array.isArray(range.rowIds) && Array.isArray(range.columnIds)) {
|
|
248
|
+
range.rowIds.forEach((r) => {
|
|
249
|
+
range.columnIds.forEach((c) => {
|
|
250
|
+
keys.add(`${String(r)}:${String(c)}`);
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
setSelectedCellKeys(keys);
|
|
256
|
+
};
|
|
257
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
258
|
+
"div",
|
|
259
|
+
{
|
|
260
|
+
className: classNames(
|
|
261
|
+
styles["easyv-react-grid"],
|
|
262
|
+
"easyv-react-grid",
|
|
263
|
+
"biz-w-full biz-h-full biz-min-h-[100px] biz-min-w-[200px]",
|
|
264
|
+
wrapClassName
|
|
265
|
+
),
|
|
266
|
+
style: wrapStyle,
|
|
267
|
+
children: finalColumns && finalRows ? /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
268
|
+
ReactGrid,
|
|
269
|
+
{
|
|
270
|
+
columns: finalColumns,
|
|
271
|
+
rows: finalRows,
|
|
272
|
+
stickyTopRows: 1,
|
|
273
|
+
stickyLeftColumns: 1,
|
|
274
|
+
enableRangeSelection: true,
|
|
275
|
+
enableFillHandle: true,
|
|
276
|
+
enableRowSelection: true,
|
|
277
|
+
enableColumnSelection: true,
|
|
278
|
+
onSelectionChanged: handleSelectionChanged,
|
|
279
|
+
disableVirtualScrolling,
|
|
280
|
+
...restProps,
|
|
281
|
+
onCellsChanged: handleCellsChanged,
|
|
282
|
+
onContextMenu: handleContextMenu,
|
|
283
|
+
onColumnResized: handleColumnResized,
|
|
284
|
+
onRowResized: handleRowResized
|
|
285
|
+
}
|
|
286
|
+
) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "biz-flex-center biz-w-full biz-h-full biz-text-text-3", children: "No data provided" })
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
};
|
|
290
|
+
export {
|
|
291
|
+
EasyvReactGrid
|
|
292
|
+
};
|
|
293
|
+
//# sourceMappingURL=easyv-react-grid.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easyv-react-grid.es.js","sources":["../../../../src/components/easyv-reactgrid/easyv-react-grid.tsx"],"sourcesContent":["import React, { useMemo, useState } from \"react\";\nimport {\n CellChange,\n Column,\n Id,\n MenuOption,\n Range,\n ReactGrid,\n ReactGridProps,\n Row,\n SelectionMode,\n} from \"@silevis/reactgrid\";\nimport \"@silevis/reactgrid/styles.css\";\nimport classNames from \"classnames\";\nimport { produce } from \"immer\";\nimport { menuLabelMap } from \"./constants\";\nimport styles from \"./easyv-react-grid.module.less\";\nimport { getColumnLabel } from \"./utils\";\n\nexport interface EasyvReactGridProps extends Omit<ReactGridProps, \"columns\" | \"rows\"> {\n columns?: ReactGridProps[\"columns\"];\n rows?: ReactGridProps[\"rows\"];\n wrapClassName?: string;\n wrapStyle?: React.CSSProperties;\n data?: (string | number)[][];\n onDataChange?: (data: (string | number)[][]) => void;\n expandMinGrid?: boolean;\n minRows?: number;\n minCols?: number;\n}\n\nexport const EasyvReactGrid = (props: EasyvReactGridProps) => {\n const {\n wrapClassName = \"\",\n wrapStyle,\n data,\n onDataChange,\n columns: propsColumns,\n rows: propsRows,\n expandMinGrid = true,\n disableVirtualScrolling = true,\n ...restProps\n } = props;\n\n const [columnWidths, setColumnWidths] = useState<Record<string, number>>({});\n const [rowHeights, setRowHeights] = useState<Record<string, number>>({});\n const [selectedCellKeys, setSelectedCellKeys] = useState<Set<string>>(new Set());\n\n const dataProps = useMemo(() => {\n if (!data) return null;\n const colsCount = data[0]?.length || 0;\n const rowsCount = data.length || 0;\n const minRows = props.minRows ?? 50;\n const minCols = props.minCols ?? 26;\n const displayRowsCount = expandMinGrid ? Math.max(rowsCount, minRows) : rowsCount;\n const displayColsCount = expandMinGrid ? Math.max(colsCount, minCols) : colsCount;\n\n // 添加 Header Column (Row Index)\n const columns: Column[] = [\n { columnId: \"header-col\", width: columnWidths[\"header-col\"] ?? 75, resizable: true }, // 行头列\n ...Array.from({ length: displayColsCount }).map((_, idx) => ({\n columnId: String(idx),\n width: columnWidths[String(idx)] ?? 100,\n resizable: true,\n })),\n ];\n\n // 添加 Header Row (Column Headers)\n const headerRowStyle: React.CSSProperties = {\n background: \"#252830\",\n color: \"#c9cbd3\",\n };\n const headerRow: Row = {\n rowId: \"header-row\",\n height: rowHeights[\"header-row\"] ?? 32,\n cells: [\n {\n type: \"header\",\n text: \"\",\n style: { ...headerRowStyle },\n },\n ...Array.from({ length: displayColsCount }).map(\n (_, idx) =>\n ({\n type: \"header\",\n text: getColumnLabel(idx),\n style: { ...headerRowStyle },\n }) as any,\n ),\n ],\n resizable: true,\n };\n\n const dataRows: Row[] = Array.from({ length: displayRowsCount }).map((_, rowIndex) => {\n const rowArr = rowIndex < rowsCount ? data[rowIndex] : [];\n const cells = [\n {\n type: \"header\",\n text: String(rowIndex + 1),\n style: {\n background: \"#252830\",\n borderColor: \"#292c34\",\n color: \"#c9cbd3\",\n borderRightColor: \"#50535e\",\n },\n } as any,\n ...Array.from({ length: displayColsCount }).map((_, colIndex) => {\n const cellKey = `${rowIndex}:${colIndex}`;\n const isSelected = selectedCellKeys.has(cellKey);\n const baseStyle = isSelected\n ? { background: \"#1c2338\", borderColor: \"#337efe\" }\n : undefined;\n const hasValue = colIndex < colsCount && rowIndex < rowsCount;\n const cellValue = hasValue ? rowArr[colIndex] : \"\";\n return { type: \"text\", text: String(cellValue), style: baseStyle } as any;\n }),\n ];\n return {\n rowId: String(rowIndex),\n height: rowHeights[String(rowIndex)] ?? 32,\n cells,\n resizable: true,\n };\n });\n\n const rows = [headerRow, ...dataRows];\n\n return { columns, rows };\n }, [\n data,\n props.minRows,\n props.minCols,\n expandMinGrid,\n columnWidths,\n rowHeights,\n selectedCellKeys,\n ]);\n\n const finalColumns = dataProps ? dataProps.columns : propsColumns;\n const finalRows = dataProps ? dataProps.rows : propsRows;\n\n const handleCellsChanged = (changes: CellChange<any>[]) => {\n if (!data || !onDataChange) {\n restProps.onCellsChanged?.(changes);\n return;\n }\n\n const newData = produce(data, (draft) => {\n changes.forEach((change) => {\n const rowIndex = Number(change.rowId);\n const colIndex = Number(change.columnId);\n\n // 过滤掉 header-row 和 header-col 的变更(虽然它们通常不可编辑)\n if (change.rowId === \"header-row\" || change.columnId === \"header-col\") return;\n\n if (!Number.isNaN(rowIndex) && !Number.isNaN(colIndex)) {\n const currentRows = draft.length;\n const currentCols = draft[0]?.length || 0;\n const requiredCols = Math.max(currentCols, colIndex + 1);\n\n if (rowIndex >= currentRows) {\n const toAdd = rowIndex + 1 - currentRows;\n for (let i = 0; i < toAdd; i++) {\n draft.push(new Array(requiredCols).fill(\"\"));\n }\n }\n\n if (requiredCols > currentCols) {\n for (let r = 0; r < draft.length; r++) {\n while ((draft[r]?.length || 0) < requiredCols) {\n draft[r].push(\"\");\n }\n }\n }\n\n if (change.newCell.type === \"number\") {\n draft[rowIndex][colIndex] = change.newCell.value;\n } else if (change.newCell.type === \"text\") {\n draft[rowIndex][colIndex] = change.newCell.text;\n } else {\n draft[rowIndex][colIndex] = (change as any).newCell?.text ?? \"\";\n }\n }\n });\n });\n\n onDataChange(newData);\n };\n\n const insertRow = (targetIndex: number, position: \"above\" | \"below\") => {\n if (!data || !onDataChange) return;\n const newData = produce(data, (draft) => {\n const insertIdx = position === \"above\" ? targetIndex : targetIndex + 1;\n const colsCount = draft[0]?.length || 0;\n const newRow = new Array(colsCount).fill(\"\");\n draft.splice(insertIdx, 0, newRow);\n });\n onDataChange(newData);\n };\n\n const insertColumn = (targetIndex: number, position: \"left\" | \"right\") => {\n if (!data || !onDataChange) return;\n const newData = produce(data, (draft) => {\n const insertIdx = position === \"left\" ? targetIndex : targetIndex + 1;\n draft.forEach((row) => {\n row.splice(insertIdx, 0, \"\");\n });\n });\n onDataChange(newData);\n };\n\n const handleContextMenu = (\n selectedRowIds: Id[],\n selectedColIds: Id[],\n _selectionMode: SelectionMode,\n menuOptions: MenuOption[],\n ): MenuOption[] => {\n const immediateHideMenu = () => {\n // 尝试强制隐藏菜单,避免闪烁\n const menu = document.querySelector(\".rg-context-menu\") as HTMLElement;\n if (menu) {\n menu.style.opacity = \"0\";\n menu.style.pointerEvents = \"none\";\n // 500ms 后恢复样式,确保下次打开时菜单可见\n setTimeout(() => {\n if (menu) {\n menu.style.opacity = \"\";\n menu.style.pointerEvents = \"\";\n }\n }, 300);\n }\n };\n const menu = document.querySelector(\".rg-context-menu\") as HTMLElement;\n if (menu?.style?.visibility === \"visible\") {\n immediateHideMenu();\n }\n const rowIndices = selectedRowIds\n .map((id) => Number(id))\n .filter((idx) => !Number.isNaN(idx) && idx >= 0)\n .sort((a, b) => a - b);\n\n const colIndices = selectedColIds\n .map((id) => Number(id))\n .filter((idx) => !Number.isNaN(idx) && idx >= 0)\n .sort((a, b) => a - b);\n\n const options: MenuOption[] = [];\n\n if (rowIndices.length > 0) {\n options.push(\n {\n id: \"insertRowAbove\",\n label: \"向上插入一行\",\n handler: () => () => insertRow(rowIndices[0], \"above\"),\n },\n {\n id: \"insertRowBelow\",\n label: \"向下插入一行\",\n handler: () => () => insertRow(rowIndices[rowIndices.length - 1], \"below\"),\n },\n );\n }\n\n if (colIndices.length > 0) {\n options.push(\n {\n id: \"insertColumnLeft\",\n label: \"向左插入一列\",\n handler: () => () => insertColumn(colIndices[0], \"left\"),\n },\n {\n id: \"insertColumnRight\",\n label: \"向右插入一列\",\n handler: () => () => insertColumn(colIndices[colIndices.length - 1], \"right\"),\n },\n );\n }\n\n const originMenuOptions = menuOptions.map((item) => ({\n ...item,\n label: menuLabelMap[item.id as keyof typeof menuLabelMap] || item.label,\n }));\n return [...originMenuOptions, ...options];\n };\n\n const handleColumnResized = (columnId: Id, width: number, _selectedColIds: Id[]) => {\n setColumnWidths((prev) => ({\n ...prev,\n [String(columnId)]: width,\n }));\n };\n\n const handleRowResized = (rowId: Id, height: number, _selectedRowIds: Id[]) => {\n setRowHeights((prev) => ({\n ...prev,\n [String(rowId)]: height,\n }));\n };\n\n const handleSelectionChanged = (selectedRanges: Range[]) => {\n const keys = new Set<string>();\n (selectedRanges || []).forEach((range: any) => {\n if (Array.isArray(range)) {\n range.forEach((loc: any) => {\n if (loc && loc.rowId !== undefined && loc.columnId !== undefined) {\n keys.add(`${String(loc.rowId)}:${String(loc.columnId)}`);\n }\n });\n } else if (range && Array.isArray(range.rowIds) && Array.isArray(range.columnIds)) {\n range.rowIds.forEach((r: any) => {\n range.columnIds.forEach((c: any) => {\n keys.add(`${String(r)}:${String(c)}`);\n });\n });\n }\n });\n setSelectedCellKeys(keys);\n };\n\n return (\n <div\n className={classNames(\n styles[\"easyv-react-grid\"],\n \"easyv-react-grid\",\n \"biz-w-full biz-h-full biz-min-h-[100px] biz-min-w-[200px]\",\n wrapClassName,\n )}\n style={wrapStyle}\n >\n {finalColumns && finalRows ? (\n <ReactGrid\n columns={finalColumns}\n rows={finalRows}\n stickyTopRows={1}\n stickyLeftColumns={1}\n enableRangeSelection\n enableFillHandle\n enableRowSelection\n enableColumnSelection\n onSelectionChanged={handleSelectionChanged}\n disableVirtualScrolling={disableVirtualScrolling}\n {...restProps}\n onCellsChanged={handleCellsChanged}\n onContextMenu={handleContextMenu}\n onColumnResized={handleColumnResized}\n onRowResized={handleRowResized}\n />\n ) : (\n <div className=\"biz-flex-center biz-w-full biz-h-full biz-text-text-3\">\n No data provided\n </div>\n )}\n </div>\n );\n};\n"],"names":["_","_a","menu","jsx"],"mappings":";;;;;;;;;AA+Ba,MAAA,iBAAiB,CAAC,UAA+B;AACtD,QAAA;AAAA,IACJ,gBAAgB;AAAA,IACh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A,QAAA;AAAA,UACC,SAAS;AAAA,UACT,MAAM;AAAA,UACN,eAAe;AAAA,UACf,mBAAmB;AAAA,UACnB,sBAAoB;AAAA,UACpB,kBAAgB;AAAA,UAChB,oBAAkB;AAAA,UAClB,uBAAqB;AAAA,UACrB,oBAAoB;AAAA,UACpB;AAAA,UACC,GAAG;AAAA,UACJ,gBAAgB;AAAA,UAChB,eAAe;AAAA,UACf,iBAAiB;AAAA,UACjB,cAAc;AAAA,QAAA;AAAA,MAAA,IAGhBA,kCAAAA,IAAC,OAAI,EAAA,WAAU,yDAAwD,UAEvE,mBAAA,CAAA;AAAA,IAAA;AAAA,EAEJ;AAEJ;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"easyv-react-grid.module.less.es.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { EasyvReactGrid } from './easyv-react-grid';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getColumnLabel: (index: number) => string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const getColumnLabel = (index) => {
|
|
2
|
+
let label = "";
|
|
3
|
+
let i = index;
|
|
4
|
+
while (i >= 0) {
|
|
5
|
+
label = String.fromCharCode(65 + i % 26) + label;
|
|
6
|
+
i = Math.floor(i / 26) - 1;
|
|
7
|
+
}
|
|
8
|
+
return label;
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
getColumnLabel
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=utils.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.es.js","sources":["../../../../src/components/easyv-reactgrid/utils.ts"],"sourcesContent":["// 辅助函数:将数字索引转换为 Excel 列头 (e.g. 0 -> A, 26 -> AA)\nexport const getColumnLabel = (index: number): string => {\n let label = \"\";\n let i = index;\n while (i >= 0) {\n label = String.fromCharCode(65 + (i % 26)) + label;\n i = Math.floor(i / 26) - 1;\n }\n return label;\n};\n"],"names":[],"mappings":"AACa,MAAA,iBAAiB,CAAC,UAA0B;AACvD,MAAI,QAAQ;AACZ,MAAI,IAAI;AACR,SAAO,KAAK,GAAG;AACb,YAAQ,OAAO,aAAa,KAAM,IAAI,EAAG,IAAI;AAC7C,QAAI,KAAK,MAAM,IAAI,EAAE,IAAI;AAAA,EAAA;AAEpB,SAAA;AACT;"}
|
package/dist/lib/hooks/use-tencent-sentence-recognition/use-tencent-sentence-recognition.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import { message } from "@easyv/react-components";
|
|
3
3
|
import useUnmount from "../../node_modules/.pnpm/ahooks@3.8.5_react@18.2.0/node_modules/ahooks/es/useUnmount/index.es.js";
|
|
4
4
|
import { VoiceRecordManager } from "../../utils/voice-record-manager/voice-record-manager.es.js";
|
|
5
5
|
import { getIsPrivateDeployEnv } from "../../utils/common/common.es.js";
|
|
@@ -13,7 +13,7 @@ const useTencentSentenceRecognition = (params) => {
|
|
|
13
13
|
await voiceRecordManager.start().then(() => {
|
|
14
14
|
setRecognizeStatus("listening");
|
|
15
15
|
}).catch(() => {
|
|
16
|
-
|
|
16
|
+
message.error("录音启动失败");
|
|
17
17
|
setRecognizeStatus("none");
|
|
18
18
|
});
|
|
19
19
|
};
|
package/dist/lib/hooks/use-tencent-sentence-recognition/use-tencent-sentence-recognition.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-tencent-sentence-recognition.es.js","sources":["../../../../src/hooks/use-tencent-sentence-recognition/use-tencent-sentence-recognition.ts"],"sourcesContent":["import { useState } from \"react\";\nimport {
|
|
1
|
+
{"version":3,"file":"use-tencent-sentence-recognition.es.js","sources":["../../../../src/hooks/use-tencent-sentence-recognition/use-tencent-sentence-recognition.ts"],"sourcesContent":["import { useState } from \"react\";\nimport { message } from \"@easyv/react-components\";\nimport { useUnmount } from \"ahooks\";\nimport { getIsPrivateDeployEnv, VoiceRecordManager } from \"@/utils\";\n\nexport interface UseTencentSentenceRecognitionParams {\n onAsrResult?: (value: string) => void;\n getSentenceRecognizeRes: (data: Blob) => Promise<string>;\n}\nexport const useTencentSentenceRecognition = (params: UseTencentSentenceRecognitionParams) => {\n const { onAsrResult, getSentenceRecognizeRes } = params;\n const [voiceRecordManager] = useState(new VoiceRecordManager());\n const [recognizeStatus, setRecognizeStatus] = useState<\"none\" | \"listening\" | \"translating\">(\n \"none\",\n );\n\n const startOneRecordFn = async () => {\n await voiceRecordManager\n .start()\n .then(() => {\n setRecognizeStatus(\"listening\");\n })\n .catch(() => {\n message.error(\"录音启动失败\");\n setRecognizeStatus(\"none\");\n });\n };\n\n // 停止录音\n const stopOneRecordFn: (needRequest?: boolean) => Promise<string | void> = async (\n needRequest = true,\n ) => {\n try {\n if (getIsPrivateDeployEnv()) {\n setRecognizeStatus(\"none\");\n return;\n }\n const wavBlob = await voiceRecordManager.stop();\n if (!wavBlob) {\n setRecognizeStatus(\"none\");\n return;\n }\n setRecognizeStatus(\"translating\");\n if (needRequest) {\n const res = await getSentenceRecognizeRes(wavBlob);\n onAsrResult?.(res);\n }\n } catch (error) {\n console.log(\"停止录音失败:\", error);\n } finally {\n setRecognizeStatus(\"none\");\n }\n };\n\n useUnmount(() => {\n voiceRecordManager.destroy();\n });\n\n return {\n recognizeStatus,\n startVoiceRecord: startOneRecordFn,\n stopVoiceRecord: stopOneRecordFn,\n };\n};\n"],"names":[],"mappings":";;;;;AASa,MAAA,gCAAgC,CAAC,WAAgD;AACtF,QAAA,EAAE,aAAa,wBAAA,IAA4B;AACjD,QAAM,CAAC,kBAAkB,IAAI,SAAS,IAAI,oBAAoB;AACxD,QAAA,CAAC,iBAAiB,kBAAkB,IAAI;AAAA,IAC5C;AAAA,EACF;AAEA,QAAM,mBAAmB,YAAY;AACnC,UAAM,mBACH,QACA,KAAK,MAAM;AACV,yBAAmB,WAAW;AAAA,IAAA,CAC/B,EACA,MAAM,MAAM;AACX,cAAQ,MAAM,QAAQ;AACtB,yBAAmB,MAAM;AAAA,IAAA,CAC1B;AAAA,EACL;AAGM,QAAA,kBAAqE,OACzE,cAAc,SACX;AACC,QAAA;AACF,UAAI,yBAAyB;AAC3B,2BAAmB,MAAM;AACzB;AAAA,MAAA;AAEI,YAAA,UAAU,MAAM,mBAAmB,KAAK;AAC9C,UAAI,CAAC,SAAS;AACZ,2BAAmB,MAAM;AACzB;AAAA,MAAA;AAEF,yBAAmB,aAAa;AAChC,UAAI,aAAa;AACT,cAAA,MAAM,MAAM,wBAAwB,OAAO;AACjD,mDAAc;AAAA,MAAG;AAAA,aAEZ,OAAO;AACN,cAAA,IAAI,WAAW,KAAK;AAAA,IAAA,UAC5B;AACA,yBAAmB,MAAM;AAAA,IAAA;AAAA,EAE7B;AAEA,aAAW,MAAM;AACf,uBAAmB,QAAQ;AAAA,EAAA,CAC5B;AAEM,SAAA;AAAA,IACL;AAAA,IACA,kBAAkB;AAAA,IAClB,iBAAiB;AAAA,EACnB;AACF;"}
|