@opentiny/tiny-robot 0.3.1-alpha.7 → 0.3.1-alpha.8

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/index3.js CHANGED
@@ -1,301 +1,282 @@
1
- import { ref as _, onMounted as ne, onBeforeUnmount as oe, defineComponent as P, createElementBlock as a, openBlock as r, createElementVNode as w, createVNode as $, unref as n, toDisplayString as B, mergeModels as W, useModel as j, computed as I, normalizeStyle as ie, Fragment as S, renderList as V, createBlock as H, resolveDynamicComponent as Y, nextTick as se, normalizeClass as U, withDirectives as q, createCommentVNode as G, renderSlot as A, withKeys as F, withModifiers as J, isRef as le, vModelText as re, vShow as ae } from "vue";
2
- import { IconEmptySearch as ue, IconEditPen as ce, IconDelete as de, IconCheck as me, IconClose as fe, IconMenu2 as pe } from "@opentiny/tiny-robot-svgs";
3
- import { _ as z } from "./_plugin-vue_export-helper.js";
4
- import { o as Z, c as ve, e as ge, d as ye } from "./index4.js";
5
- import { t as O } from "./utils.js";
6
- const D = _(!1);
7
- let T = 0, b;
8
- function _e() {
9
- const s = window.matchMedia("(hover: none) and (pointer: coarse)"), m = () => {
10
- D.value = s.matches;
11
- };
12
- m(), s.addEventListener("change", m);
13
- const t = (c) => {
14
- D.value = c.pointerType !== "mouse";
15
- };
16
- return window.addEventListener("pointerdown", t, !0), () => {
17
- s.removeEventListener("change", m), window.removeEventListener("pointerdown", t, !0);
18
- };
19
- }
20
- function he() {
21
- b == null || b(), b = void 0;
22
- }
23
- function Ce() {
24
- return typeof window > "u" ? {
25
- isTouchDevice: D
26
- } : (ne(() => {
27
- T++, T === 1 && (b = _e());
28
- }), oe(() => {
29
- T = Math.max(0, T - 1), T === 0 && he();
30
- }), {
31
- isTouchDevice: D
32
- });
33
- }
34
- const ke = { class: "tr-history__empty" }, Le = { class: "tr-history__empty-icon" }, Ee = { class: "tr-history__empty-text" }, we = /* @__PURE__ */ P({
35
- __name: "Empty",
1
+ var $ = Object.defineProperty;
2
+ var D = (i, o, e) => o in i ? $(i, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[o] = e;
3
+ var C = (i, o, e) => D(i, typeof o != "symbol" ? o + "" : o, e);
4
+ import { defineComponent as B, toRefs as H, computed as R, watch as F, openBlock as S, createBlock as x, unref as p, ref as V, reactive as A, onUnmounted as P, createElementBlock as j, Fragment as U, normalizeClass as W, createSlots as L, withCtx as y, renderSlot as z, resolveDynamicComponent as M, createCommentVNode as N } from "vue";
5
+ import { e as O } from "./index4.js";
6
+ import { u as I, A as b } from "./index2.js";
7
+ import { IconUpload as T, IconVoice as _, IconRecordingWave as q } from "@opentiny/tiny-robot-svgs";
8
+ import { _ as G } from "./_plugin-vue_export-helper.js";
9
+ const te = /* @__PURE__ */ B({
10
+ __name: "index",
36
11
  props: {
37
- text: { default: "暂无内容" }
12
+ disabled: { type: Boolean },
13
+ accept: { default: "*" },
14
+ multiple: { type: Boolean, default: !0 },
15
+ reset: { type: Boolean, default: !0 },
16
+ maxSize: {},
17
+ maxCount: {},
18
+ tooltip: {},
19
+ size: {},
20
+ icon: {},
21
+ tooltipPlacement: { default: "top" }
38
22
  },
39
- setup(s) {
40
- const m = s;
41
- return (t, c) => (r(), a("div", ke, [
42
- w("span", Le, [
43
- $(n(ue))
44
- ]),
45
- w("span", Ee, B(m.text), 1)
46
- ]));
47
- }
48
- }), Re = /* @__PURE__ */ z(we, [["__scopeId", "data-v-d0340c39"]]), Ie = ["onClick"], Q = 4, xe = /* @__PURE__ */ P({
49
- __name: "MenuList",
50
- props: /* @__PURE__ */ W({
51
- items: {},
52
- menuListGap: { default: 8 }
53
- }, {
54
- trigger: { default: null },
55
- triggerModifiers: {},
56
- data: { default: null },
57
- dataModifiers: {}
58
- }),
59
- emits: /* @__PURE__ */ W(["item-click"], ["update:trigger", "update:data"]),
60
- setup(s, { emit: m }) {
61
- const t = j(s, "trigger"), c = j(s, "data"), h = s, C = m, E = _(null);
62
- Z(
63
- E,
64
- () => {
65
- t.value = null, c.value = null;
66
- },
67
- {
68
- ignore: [t]
23
+ emits: ["select", "error"],
24
+ setup(i, { expose: o, emit: e }) {
25
+ const n = i, l = e, { accept: c, multiple: h, reset: m } = H(n), { disabled: a } = I(), t = R(() => n.disabled || a.value), { open: r, files: d } = O({
26
+ accept: c,
27
+ multiple: h,
28
+ reset: m
29
+ });
30
+ F(d, (f) => {
31
+ if (!f || f.length === 0) return;
32
+ const g = Array.from(f);
33
+ if (n.maxCount && g.length > n.maxCount) {
34
+ const s = new Error(`最多只能选择 ${n.maxCount} 个文件`);
35
+ l("error", s);
36
+ return;
69
37
  }
70
- );
71
- const { top: p, bottom: x, left: y } = ve(t), { width: M, height: k } = ge(E, void 0, { box: "border-box" }), { height: R } = ye(), o = I(() => {
72
- const L = {
73
- left: `min(${O(y.value)}, calc(100% - ${O(M.value + Q)}))`
74
- }, g = x.value + h.menuListGap;
75
- return g + k.value + Q > R.value ? L.bottom = `calc(100% - ${O(p.value - h.menuListGap)})` : L.top = O(g), L;
76
- }), v = (L) => {
77
- C("item-click", L), t.value = null, c.value = null;
38
+ if (n.maxSize) {
39
+ const s = n.maxSize * 1024 * 1024, v = g.filter((E) => E.size > s);
40
+ if (v.length > 0) {
41
+ const E = new Error(`以下文件超过 ${n.maxSize}MB 限制: ${v.map((k) => k.name).join(", ")}`);
42
+ l("error", E, v);
43
+ return;
44
+ }
45
+ }
46
+ l("select", g);
47
+ });
48
+ const u = () => {
49
+ t.value || r();
78
50
  };
79
- return (L, g) => (r(), a("ul", {
80
- class: "tr-history__menu-list",
81
- ref_key: "menuRef",
82
- ref: E,
83
- style: ie(o.value)
84
- }, [
85
- (r(!0), a(S, null, V(h.items, (u) => (r(), a("li", {
86
- class: "tr-history__menu-list__item",
87
- key: u.id,
88
- onClick: (K) => v(u)
89
- }, [
90
- (r(), H(Y(u.icon))),
91
- w("span", null, B(u.text), 1)
92
- ], 8, Ie))), 128))
93
- ], 4));
51
+ return o({
52
+ open: r
53
+ }), (f, g) => (S(), x(b, {
54
+ icon: i.icon ?? p(T),
55
+ disabled: t.value,
56
+ size: i.size,
57
+ tooltip: i.tooltip,
58
+ "tooltip-placement": i.tooltipPlacement,
59
+ onClick: u
60
+ }, null, 8, ["icon", "disabled", "size", "tooltip", "tooltip-placement"]));
61
+ }
62
+ });
63
+ class w {
64
+ constructor(o) {
65
+ C(this, "recognition");
66
+ C(this, "options");
67
+ this.options = o, this.initialize();
68
+ }
69
+ /**
70
+ * 初始化语音识别实例
71
+ */
72
+ initialize() {
73
+ this.recognition = new (window.webkitSpeechRecognition || window.SpeechRecognition)(), this.recognition.continuous = this.options.continuous ?? !1, this.recognition.interimResults = this.options.interimResults ?? !0, this.recognition.lang = this.options.lang ?? navigator.language;
74
+ }
75
+ /**
76
+ * 检查浏览器是否支持 Web Speech API
77
+ */
78
+ static isSupported() {
79
+ return typeof window < "u" && ("webkitSpeechRecognition" in window || "SpeechRecognition" in window);
94
80
  }
95
- }), Me = /* @__PURE__ */ z(xe, [["__scopeId", "data-v-89fdb41c"]]), Te = ({
96
- renameControlOnClickOutside: s,
97
- onItemTitleChange: m
98
- }) => {
99
- const t = _(void 0), c = _(null), h = I(() => {
100
- var o;
101
- return (o = c.value) == null ? void 0 : o.at(0);
102
- }), C = _(null), E = I(() => {
103
- var o;
104
- return (o = C.value) == null ? void 0 : o.at(0);
105
- }), p = _(null), x = I(() => {
106
- var o;
107
- return (o = p.value) == null ? void 0 : o.at(0);
108
- }), y = _(""), M = (o) => {
109
- t.value = o, y.value = o.title, se(() => {
110
- const v = h.value;
111
- v && (v.focus(), v.select());
81
+ /**
82
+ * 检查浏览器是否支持 Web Speech API(实例方法)
83
+ */
84
+ isSupported() {
85
+ return w.isSupported();
86
+ }
87
+ /**
88
+ * 设置语音识别事件处理器
89
+ * @param callbacks 语音识别回调函数集合
90
+ */
91
+ setupEventHandlers(o) {
92
+ !this.recognition || !o || (this.recognition.onstart = () => {
93
+ o.onStart();
94
+ }, this.recognition.onend = () => {
95
+ o.onEnd();
96
+ }, this.recognition.onresult = (e) => {
97
+ const n = Array.from(e.results).map((c) => c[0].transcript).join(""), l = e.results[e.resultIndex];
98
+ l != null && l.isFinal ? o.onFinal(n) : o.onInterim(n);
99
+ }, this.recognition.onerror = (e) => {
100
+ o.onError(new Error(e.error)), this.cleanup();
112
101
  });
113
- }, k = () => {
114
- t.value = void 0, y.value = "";
115
- }, R = () => {
116
- t.value && m(y.value, t.value), t.value = void 0, y.value = "";
117
- };
118
- return (s === "confirm" || s === "cancel") && Z(
119
- h,
120
- () => {
121
- s === "confirm" ? R() : k();
102
+ }
103
+ /**
104
+ * 清理事件监听器
105
+ */
106
+ cleanup() {
107
+ this.recognition && (this.recognition.onstart = null, this.recognition.onend = null, this.recognition.onresult = null, this.recognition.onerror = null);
108
+ }
109
+ /**
110
+ * 开始语音识别
111
+ * @param callbacks 语音识别回调函数集合
112
+ */
113
+ start(o) {
114
+ if (!this.recognition) {
115
+ o.onError(new Error("浏览器不支持语音识别"));
116
+ return;
117
+ }
118
+ this.setupEventHandlers(o);
119
+ try {
120
+ this.recognition.start();
121
+ } catch (e) {
122
+ o.onError(e instanceof Error ? e : new Error("语音识别启动失败"));
123
+ }
124
+ }
125
+ /**
126
+ * 停止语音识别并清理资源
127
+ */
128
+ stop() {
129
+ if (this.recognition) {
130
+ this.cleanup();
131
+ try {
132
+ this.recognition.stop();
133
+ } catch (o) {
134
+ console.warn("停止语音识别时发生错误:", o);
135
+ }
136
+ }
137
+ }
138
+ }
139
+ function J(i) {
140
+ const o = V(i), e = A({
141
+ isRecording: !1,
142
+ isSupported: !1,
143
+ error: void 0
144
+ }), n = {
145
+ onStart: () => {
146
+ var a, t;
147
+ e.isRecording = !0, e.error = void 0, (t = (a = o.value).onStart) == null || t.call(a);
122
148
  },
123
- { ignore: [E, x] }
124
- ), {
125
- editingItem: t,
126
- editorRefList: c,
127
- editorConfirmRefList: C,
128
- editorCancelRefList: p,
129
- editorValue: y,
130
- handleEdit: M,
131
- handleEditCancel: k,
132
- handleEditConfirm: R
149
+ onInterim: (a) => {
150
+ var t, r;
151
+ (r = (t = o.value).onInterim) == null || r.call(t, a);
152
+ },
153
+ onFinal: (a) => {
154
+ var t, r;
155
+ (r = (t = o.value).onFinal) == null || r.call(t, a);
156
+ },
157
+ onEnd: (a) => {
158
+ var t, r;
159
+ e.isRecording && (e.isRecording = !1, (r = (t = o.value).onEnd) == null || r.call(t, a));
160
+ },
161
+ onError: (a) => {
162
+ var t, r;
163
+ e.error = a, e.isRecording = !1, (r = (t = o.value).onError) == null || r.call(t, a);
164
+ }
165
+ }, l = w.isSupported();
166
+ e.isSupported = i.customHandler ? i.customHandler.isSupported() : l;
167
+ const c = i.customHandler ?? (l ? new w(i) : null), h = () => {
168
+ var a, t, r, d;
169
+ if (!e.isSupported || !c) {
170
+ const u = new Error("语音识别不受支持");
171
+ e.error = u, (t = (a = o.value).onError) == null || t.call(a, u);
172
+ return;
173
+ }
174
+ if (e.isRecording) {
175
+ c.stop(), e.isRecording = !1, setTimeout(() => {
176
+ c.start(n);
177
+ }, 200);
178
+ return;
179
+ }
180
+ try {
181
+ c.start(n);
182
+ } catch (u) {
183
+ e.error = u instanceof Error ? u : new Error("启动失败"), (d = (r = o.value).onError) == null || d.call(r, e.error);
184
+ }
185
+ }, m = () => {
186
+ !e.isRecording || !c || (c.stop(), n.onEnd());
187
+ };
188
+ return P(() => {
189
+ e.isRecording && c && (c.stop(), e.isRecording = !1);
190
+ }), {
191
+ speechState: e,
192
+ start: h,
193
+ stop: m
133
194
  };
134
- }, X = Symbol("NO_GROUP"), $e = {
135
- key: 0,
136
- class: "tr-history__group-title"
137
- }, be = { class: "tr-history__group-items" }, Ge = ["onClick"], Oe = ["title"], Se = ["onClick"], Be = /* @__PURE__ */ P({
195
+ }
196
+ const K = /* @__PURE__ */ B({
138
197
  __name: "index",
139
198
  props: {
140
- data: {},
141
- selected: {},
142
- showRenameControls: { type: Boolean, default: !1 },
143
- renameControlOnClickOutside: { default: "confirm" },
144
- menuItems: { default: () => [
145
- { id: "rename", text: "重命名", icon: ce },
146
- { id: "delete", text: "删除", icon: de }
147
- ] },
148
- menuListGap: { default: 8 }
199
+ icon: {},
200
+ recordingIcon: {},
201
+ disabled: { type: Boolean },
202
+ size: {},
203
+ tooltip: {},
204
+ tooltipPlacement: { default: "top" },
205
+ speechConfig: {},
206
+ autoInsert: { type: Boolean, default: !0 },
207
+ onButtonClick: {}
149
208
  },
150
- emits: ["item-click", "item-title-change", "item-action"],
151
- setup(s, { emit: m }) {
152
- const t = s, c = m, h = (i) => {
153
- var f;
154
- const e = typeof ((f = i[0]) == null ? void 0 : f.group);
155
- return e === "string" || e === "symbol";
156
- }, C = I(() => {
157
- const i = t.data;
158
- return h(i) ? i : [{ group: X, items: i }];
159
- }), E = I(() => C.value.length === 0 || C.value.every((i) => i.items.length === 0)), {
160
- editingItem: p,
161
- editorRefList: x,
162
- editorConfirmRefList: y,
163
- editorCancelRefList: M,
164
- editorValue: k,
165
- handleEdit: R,
166
- handleEditCancel: o,
167
- handleEditConfirm: v
168
- } = Te({
169
- renameControlOnClickOutside: t.renameControlOnClickOutside,
170
- onItemTitleChange: (i, e) => {
171
- c("item-title-change", i, e);
209
+ emits: ["speech-start", "speech-interim", "speech-final", "speech-end", "speech-error"],
210
+ setup(i, { expose: o, emit: e }) {
211
+ const n = i, l = e, { editor: c, disabled: h } = I(), m = R(() => n.disabled || h.value), a = {
212
+ ...n.speechConfig,
213
+ onStart: () => {
214
+ l("speech-start");
215
+ },
216
+ onInterim: (s) => {
217
+ l("speech-interim", s);
218
+ },
219
+ onFinal: (s) => {
220
+ n.autoInsert && c.value && (c.value.commands.insertContent(s + " "), c.value.commands.focus("end")), l("speech-final", s);
221
+ },
222
+ onEnd: (s) => {
223
+ c.value && c.value.commands.focus("end"), l("speech-end", s);
224
+ },
225
+ onError: (s) => {
226
+ l("speech-error", s);
172
227
  }
173
- }), { isTouchDevice: L } = Ce(), g = _(null), u = _(null), K = (i, e) => {
174
- if (i.currentTarget instanceof HTMLButtonElement) {
175
- if (u.value === e) {
176
- g.value = null, u.value = null;
177
- return;
228
+ }, { speechState: t, start: r, stop: d } = J(a), u = async () => {
229
+ if (!m.value) {
230
+ if (n.onButtonClick) {
231
+ let s = !1;
232
+ if (await n.onButtonClick(t.isRecording, () => {
233
+ s = !0;
234
+ }), s) return;
178
235
  }
179
- g.value = i.currentTarget, u.value = e;
180
- } else
181
- g.value = null, u.value = null;
182
- }, ee = (i) => {
183
- const e = u.value;
184
- e && (i.id === "rename" && R(e), c("item-action", i, e));
185
- };
186
- return (i, e) => (r(), a("div", {
187
- class: U(["tr-history", { "touch-device": n(L) }])
188
- }, [
189
- E.value ? (r(), H(Re, { key: 1 })) : (r(), a(S, { key: 0 }, [
190
- (r(!0), a(S, null, V(C.value, (f) => (r(), a("div", {
191
- class: "tr-history__group",
192
- key: f.group
193
- }, [
194
- f.group !== n(X) ? (r(), a("div", $e, B(f.group), 1)) : G("", !0),
195
- w("div", be, [
196
- (r(!0), a(S, null, V(f.items, (l, te) => (r(), a("div", {
197
- class: U(["tr-history__item", {
198
- selected: l.id && l.id === t.selected,
199
- editing: n(p) === l,
200
- active: u.value === l
201
- }]),
202
- key: l.id || te,
203
- onClick: (d) => c("item-click", l)
204
- }, [
205
- A(i.$slots, "item-prefix", { item: l }, void 0, !0),
206
- l.icon ? (r(), H(Y(l.icon), { key: 0 })) : G("", !0),
207
- n(p) === l ? q((r(), a("input", {
208
- key: 1,
209
- class: "tr-history__item-editor",
210
- type: "text",
211
- onClick: e[0] || (e[0] = J(() => {
212
- }, ["stop"])),
213
- ref_for: !0,
214
- ref_key: "editorRefList",
215
- ref: x,
216
- "onUpdate:modelValue": e[1] || (e[1] = (d) => le(k) ? k.value = d : null),
217
- onKeydown: [
218
- e[2] || (e[2] = F(
219
- //@ts-ignore
220
- (...d) => n(v) && n(v)(...d),
221
- ["enter"]
222
- )),
223
- e[3] || (e[3] = F(
224
- //@ts-ignore
225
- (...d) => n(o) && n(o)(...d),
226
- ["escape"]
227
- ))
228
- ]
229
- }, null, 544)), [
230
- [re, n(k)]
231
- ]) : A(i.$slots, "item-title", {
232
- key: 2,
233
- item: l
234
- }, () => [
235
- w("span", {
236
- class: "text",
237
- title: l.title
238
- }, B(l.title), 9, Oe)
239
- ], !0),
240
- w("span", {
241
- class: "tr-history__item-actions",
242
- onClick: e[6] || (e[6] = J(() => {
243
- }, ["stop"]))
244
- }, [
245
- t.showRenameControls && n(p) === l ? (r(), a("button", {
246
- key: 0,
247
- class: "editor-confirm",
248
- ref_for: !0,
249
- ref_key: "editorConfirmRefList",
250
- ref: y,
251
- onClick: e[4] || (e[4] = //@ts-ignore
252
- (...d) => n(v) && n(v)(...d))
253
- }, [
254
- $(n(me))
255
- ], 512)) : G("", !0),
256
- t.showRenameControls && n(p) === l ? (r(), a("button", {
257
- key: 1,
258
- class: "editor-cancel",
259
- ref_for: !0,
260
- ref_key: "editorCancelRefList",
261
- ref: M,
262
- onClick: e[5] || (e[5] = //@ts-ignore
263
- (...d) => n(o) && n(o)(...d))
264
- }, [
265
- $(n(fe))
266
- ], 512)) : G("", !0),
267
- w("button", {
268
- class: U(["menu", { hidden: n(p) === l }]),
269
- onClick: (d) => K(d, l)
270
- }, [
271
- $(n(pe))
272
- ], 10, Se)
273
- ])
274
- ], 10, Ge))), 128))
275
- ])
276
- ]))), 128)),
277
- q($(Me, {
278
- trigger: g.value,
279
- "onUpdate:trigger": e[7] || (e[7] = (f) => g.value = f),
280
- data: u.value,
281
- "onUpdate:data": e[8] || (e[8] = (f) => u.value = f),
282
- items: t.menuItems,
283
- "menu-list-gap": t.menuListGap,
284
- onItemClick: ee
285
- }, null, 8, ["trigger", "data", "items", "menu-list-gap"]), [
286
- [ae, g.value]
287
- ])
288
- ], 64))
289
- ], 2));
236
+ t.isRecording ? d() : r();
237
+ }
238
+ }, f = R(() => n.icon ?? _), g = R(() => n.recordingIcon ?? q);
239
+ return o({
240
+ start: r,
241
+ stop: d,
242
+ speechState: t
243
+ }), (s, v) => (S(), j(U, null, [
244
+ p(t).isSupported ? (S(), x(b, {
245
+ key: 0,
246
+ icon: f.value,
247
+ disabled: m.value,
248
+ size: i.size,
249
+ tooltip: i.tooltip,
250
+ "tooltip-placement": i.tooltipPlacement,
251
+ class: W({ "is-recording": p(t).isRecording }),
252
+ onClick: u
253
+ }, L({ _: 2 }, [
254
+ s.$slots.icon ? {
255
+ name: "icon",
256
+ fn: y(() => [
257
+ z(s.$slots, "icon", {
258
+ isRecording: p(t).isRecording
259
+ }, void 0, !0)
260
+ ]),
261
+ key: "0"
262
+ } : p(t).isRecording ? {
263
+ name: "icon",
264
+ fn: y(() => [
265
+ (S(), x(M(g.value)))
266
+ ]),
267
+ key: "1"
268
+ } : void 0
269
+ ]), 1032, ["icon", "disabled", "size", "tooltip", "tooltip-placement", "class"])) : N("", !0),
270
+ z(s.$slots, "recording-overlay", {
271
+ isRecording: p(t).isRecording,
272
+ stop: p(d)
273
+ }, void 0, !0)
274
+ ], 64));
290
275
  }
291
- }), N = /* @__PURE__ */ z(Be, [["__scopeId", "data-v-97a7e8a2"]]), De = function(s) {
292
- s.component(N.name, N);
293
- };
294
- Object.assign(N, {
295
- name: "TrHistory",
296
- install: De
297
- });
276
+ }), ne = /* @__PURE__ */ G(K, [["__scopeId", "data-v-2a013fc9"]]);
298
277
  export {
299
- N as H,
300
- Ce as u
278
+ ne as V,
279
+ w as W,
280
+ te as _,
281
+ J as u
301
282
  };