@opentiny/tiny-robot 0.3.0-alpha.22 → 0.3.0-alpha.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import { defineComponent as q, mergeModels as E, useModel as G, watch as g, ref as i, computed as $, createElementBlock as a, openBlock as l, createElementVNode as I, Fragment as C, renderList as D, createCommentVNode as _, normalizeClass as x, createBlock as B, resolveDynamicComponent as b, toDisplayString as S, nextTick as H } from "vue";
2
2
  import { IconArrowDown as X } from "@opentiny/tiny-robot-svgs";
3
- import { e as j, o as J } from "../index2.js";
3
+ import { d as j, o as J } from "../index2.js";
4
4
  import { _ as K } from "../_plugin-vue_export-helper.js";
5
5
  const P = ["onClick"], Q = {
6
6
  key: 0,
@@ -1,226 +1,287 @@
1
- import { defineComponent as V, createElementBlock as u, openBlock as a, normalizeStyle as X, normalizeClass as D, createElementVNode as p, toDisplayString as k, createVNode as y, unref as e, ref as S, watchEffect as Y, nextTick as Z, mergeModels as A, useCssVars as q, computed as h, useModel as G, createCommentVNode as w, Fragment as T, renderList as $, createBlock as N, withDirectives as ee, mergeProps as te, withCtx as R, withModifiers as H, vModelText as re } from "vue";
2
- import { IconEmptySearch as oe, IconSearch as se, IconEditPen as ne, IconDelete as ae, IconClose as ie } from "@opentiny/tiny-robot-svgs";
3
- import { TinyInput as le, TinyTooltip as U } from "@opentiny/vue";
4
- import B from "../icon-button/index.js";
5
- import { o as ce } from "../index2.js";
6
- import { _ as M } from "../_plugin-vue_export-helper.js";
7
- const ue = /* @__PURE__ */ V({
8
- __name: "item-tag",
9
- props: {
10
- text: {},
11
- type: { default: "default" },
12
- style: {}
13
- },
14
- setup(i) {
15
- const t = i;
16
- return (n, _) => (a(), u("div", {
17
- class: D(["tr-history__item-tag", t.type]),
18
- style: X(t.style)
19
- }, [
20
- p("span", null, k(t.text), 1)
21
- ], 6));
22
- }
23
- }), de = /* @__PURE__ */ M(ue, [["__scopeId", "data-v-346767bb"]]), _e = { class: "tr-history__empty" }, pe = { class: "tr-history__empty-icon" }, he = { class: "tr-history__empty-text" }, ye = /* @__PURE__ */ V({
24
- __name: "search-empty",
1
+ import { ref as g, onMounted as Z, onBeforeUnmount as ee, defineComponent as P, createElementBlock as l, openBlock as r, createElementVNode as w, createVNode as b, unref as n, toDisplayString as D, mergeModels as te, useModel as W, computed as L, normalizeStyle as ne, Fragment as B, renderList as H, createBlock as J, resolveDynamicComponent as oe, nextTick as ie, normalizeClass as U, withDirectives as j, createCommentVNode as V, withKeys as q, withModifiers as A, isRef as se, vModelText as re, vShow as le } from "vue";
2
+ import { IconEmptySearch as ae, IconEditPen as ue, IconDelete as ce, IconCheck as de, IconClose as me, IconMenu2 as fe } from "@opentiny/tiny-robot-svgs";
3
+ import { _ as z } from "../_plugin-vue_export-helper.js";
4
+ import { o as Q, a as ve, d as pe, c as _e } from "../index2.js";
5
+ import { t as O } from "../utils.js";
6
+ const S = g(!1);
7
+ let T = 0, $;
8
+ function ye() {
9
+ const s = window.matchMedia("(hover: none) and (pointer: coarse)"), m = () => {
10
+ S.value = s.matches;
11
+ };
12
+ m(), s.addEventListener("change", m);
13
+ const t = (c) => {
14
+ S.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 ge() {
21
+ $ == null || $(), $ = void 0;
22
+ }
23
+ function he() {
24
+ return typeof window > "u" ? {
25
+ isTouchDevice: S
26
+ } : (Z(() => {
27
+ T++, T === 1 && ($ = ye());
28
+ }), ee(() => {
29
+ T = Math.max(0, T - 1), T === 0 && ge();
30
+ }), {
31
+ isTouchDevice: S
32
+ });
33
+ }
34
+ const Ce = { class: "tr-history__empty" }, ke = { class: "tr-history__empty-icon" }, Ee = { class: "tr-history__empty-text" }, we = /* @__PURE__ */ P({
35
+ __name: "Empty",
25
36
  props: {
26
37
  text: { default: "暂无内容" }
27
38
  },
28
- setup(i) {
29
- const t = i;
30
- return (n, _) => (a(), u("div", _e, [
31
- p("span", pe, [
32
- y(e(oe))
39
+ setup(s) {
40
+ const m = s;
41
+ return (t, c) => (r(), l("div", Ce, [
42
+ w("span", ke, [
43
+ b(n(ae))
33
44
  ]),
34
- p("span", he, k(t.text), 1)
45
+ w("span", Ee, D(m.text), 1)
35
46
  ]));
36
47
  }
37
- }), me = /* @__PURE__ */ M(ye, [["__scopeId", "data-v-b21f5bc0"]]), ve = (i) => {
38
- const t = S(), n = (l) => {
39
- t.value = {
40
- id: l.id,
41
- title: l.title,
42
- rawData: l
48
+ }), xe = /* @__PURE__ */ z(we, [["__scopeId", "data-v-d0340c39"]]), Re = ["onClick"], Le = 12, G = 4, Ie = /* @__PURE__ */ P({
49
+ __name: "MenuList",
50
+ props: {
51
+ trigger: { default: null },
52
+ triggerModifiers: {},
53
+ data: { default: null },
54
+ dataModifiers: {}
55
+ },
56
+ emits: /* @__PURE__ */ te(["item-click"], ["update:trigger", "update:data"]),
57
+ setup(s, { emit: m }) {
58
+ const t = W(s, "trigger"), c = W(s, "data"), x = m, h = [
59
+ { id: "rename", text: "重命名", icon: ue },
60
+ { id: "delete", text: "删除", icon: ce }
61
+ ], E = g(null);
62
+ Q(
63
+ E,
64
+ () => {
65
+ t.value = null, c.value = null;
66
+ },
67
+ {
68
+ ignore: [t]
69
+ }
70
+ );
71
+ const { top: v, bottom: I, left: y } = ve(t), { width: M, height: C } = pe(E, void 0, { box: "border-box" }), { height: R } = _e(), o = L(() => {
72
+ const k = {
73
+ left: `min(${O(y.value)}, calc(100% - ${O(M.value + G)}))`
74
+ }, _ = I.value + Le;
75
+ return _ + C.value + G > R.value ? k.bottom = `calc(100% - ${O(v.value - G)})` : k.top = O(_), k;
76
+ }), p = (k) => {
77
+ x("item-click", k), t.value = null, c.value = null;
43
78
  };
44
- }, _ = S(null), m = (l) => {
45
- l && Z(() => {
46
- _.value = l, _.value.focus();
79
+ return (k, _) => (r(), l("ul", {
80
+ class: "tr-history__menu-list",
81
+ ref_key: "menuRef",
82
+ ref: E,
83
+ style: ne(o.value)
84
+ }, [
85
+ (r(), l(B, null, H(h, (a) => w("li", {
86
+ class: "tr-history__menu-list__item",
87
+ key: a.id,
88
+ onClick: (K) => p(a)
89
+ }, [
90
+ (r(), J(oe(a.icon))),
91
+ w("span", null, D(a.text), 1)
92
+ ], 8, Re)), 64))
93
+ ], 4));
94
+ }
95
+ }), Me = /* @__PURE__ */ z(Ie, [["__scopeId", "data-v-67ba5dd7"]]), Te = ({
96
+ renameControlOnClickOutside: s,
97
+ onItemTitleChange: m
98
+ }) => {
99
+ const t = g(void 0), c = g(null), x = L(() => {
100
+ var o;
101
+ return (o = c.value) == null ? void 0 : o.at(0);
102
+ }), h = g(null), E = L(() => {
103
+ var o;
104
+ return (o = h.value) == null ? void 0 : o.at(0);
105
+ }), v = g(null), I = L(() => {
106
+ var o;
107
+ return (o = v.value) == null ? void 0 : o.at(0);
108
+ }), y = g(""), M = (o) => {
109
+ t.value = o, y.value = o.title, ie(() => {
110
+ const p = x.value;
111
+ p && (p.focus(), p.select());
47
112
  });
113
+ }, C = () => {
114
+ t.value = void 0, y.value = "";
115
+ }, R = () => {
116
+ t.value && m(y.value, t.value), t.value = void 0, y.value = "";
48
117
  };
49
- let r;
50
- const v = () => {
51
- if (t.value) {
52
- if (t.value.title !== t.value.rawData.title) {
53
- const { title: l, rawData: I } = t.value;
54
- i("item-title-change", l, I);
55
- }
56
- t.value = void 0;
57
- }
58
- r == null || r(), r = void 0;
59
- }, g = () => {
60
- t.value = void 0, r == null || r(), r = void 0;
61
- }, b = (l) => {
62
- l.key === "Enter" ? v() : l.key === "Escape" && g();
63
- };
64
- return Y(() => {
65
- _.value && (r == null || r(), r = ce(_, () => {
66
- v();
67
- }));
68
- }), {
118
+ return (s === "confirm" || s === "cancel") && Q(
119
+ x,
120
+ () => {
121
+ s === "confirm" ? R() : C();
122
+ },
123
+ { ignore: [E, I] }
124
+ ), {
69
125
  editingItem: t,
70
- handleEdit: n,
71
- handleEditorInputRef: m,
72
- handleKeyDown: b
126
+ editorRefList: c,
127
+ editorConfirmRefList: h,
128
+ editorCancelRefList: v,
129
+ editorValue: y,
130
+ handleEdit: M,
131
+ handleEditCancel: C,
132
+ handleEditConfirm: R
73
133
  };
74
- }, fe = { class: "tr-history" }, ke = { class: "tr-history__tabs" }, ge = ["onClick"], be = {
75
- key: 0,
76
- class: "tr-history__search"
77
- }, Ce = { class: "tr-history__content" }, xe = {
134
+ }, F = Symbol("NO_GROUP"), be = {
78
135
  key: 0,
79
136
  class: "tr-history__group-title"
80
- }, Te = ["onClick"], Ie = { class: "tr-history__item-title" }, Ee = { class: "tr-history__item-actions" }, we = { class: "tr-history__close" }, $e = /* @__PURE__ */ V({
137
+ }, $e = { class: "tr-history__group-items" }, Oe = ["onClick"], Be = ["title"], De = ["onClick"], Se = /* @__PURE__ */ P({
81
138
  __name: "index",
82
- props: /* @__PURE__ */ A({
83
- tabTitle: {},
139
+ props: {
84
140
  data: {},
85
- activeTab: {},
86
- searchBar: { type: Boolean },
87
- searchQuery: {},
88
- searchPlaceholder: {},
89
- searchFn: { type: Function, default: (i, { title: t }) => i ? t.toLowerCase().includes(i.toLowerCase()) : !0 },
90
141
  selected: {},
91
- tabs: {}
92
- }, {
93
- activeTab: {},
94
- activeTabModifiers: {},
95
- searchQuery: {},
96
- searchQueryModifiers: {}
97
- }),
98
- emits: /* @__PURE__ */ A(["close", "item-click", "item-title-change", "item-delete"], ["update:activeTab", "update:searchQuery"]),
99
- setup(i, { emit: t }) {
100
- q((c) => ({
101
- "3a9ca538": b.value ? "1px solid rgb(240, 240, 240)" : "none",
102
- "0b9d3e32": b.value ? "2px solid rgb(25, 25, 25)" : "none"
103
- }));
104
- const n = i, _ = G(i, "activeTab"), m = G(i, "searchQuery"), r = t, v = h(() => Array.isArray(n.tabs) ? n.tabs : [{ title: n.tabTitle, id: "0" }]), g = h(() => _.value || v.value[0].id), b = h(() => v.value.length > 1), l = (c) => {
105
- var s;
106
- const o = typeof ((s = c[0]) == null ? void 0 : s.group);
107
- return o === "string" || o === "symbol";
108
- }, I = h(() => Array.isArray(n.data) ? n.data || [] : n.data[g.value] || []), E = Symbol("NO_GROUP"), O = h(() => {
109
- const c = I.value;
110
- return l(c) ? c : [{ group: E, items: c }];
111
- }), C = h(() => n.searchBar ? O.value.map((o) => ({
112
- ...o,
113
- items: o.items.filter((s) => n.searchFn(m.value || "", s))
114
- })).filter((o) => o.items.length > 0) : O.value), L = h(() => C.value.length === 0 ? !1 : C.value[0].group === E ? C.value[0].items.length > 0 : !0), z = (c) => {
115
- var o;
116
- c.id !== ((o = x.value) == null ? void 0 : o.id) && r("item-click", c);
117
- }, W = () => {
118
- r("close");
119
- }, F = (c) => {
120
- r("item-delete", c);
121
- }, { editingItem: x, handleEdit: j, handleEditorInputRef: J, handleKeyDown: P } = ve(r);
122
- return (c, o) => (a(), u("div", fe, [
123
- p("div", ke, [
124
- (a(!0), u(T, null, $(v.value, (s) => (a(), u("div", {
125
- key: s.id,
126
- class: D(["tr-history__tab", { active: g.value === s.id }]),
127
- onClick: (d) => _.value = s.id
128
- }, k(s.title), 11, ge))), 128))
129
- ]),
130
- n.searchBar ? (a(), u("div", be, [
131
- y(e(le), {
132
- modelValue: m.value,
133
- "onUpdate:modelValue": o[0] || (o[0] = (s) => m.value = s),
134
- placeholder: n.searchPlaceholder || "搜索对话名称",
135
- "prefix-icon": e(se),
136
- clearable: ""
137
- }, null, 8, ["modelValue", "placeholder", "prefix-icon"])
138
- ])) : w("", !0),
139
- p("div", Ce, [
140
- L.value ? (a(!0), u(T, { key: 0 }, $(C.value, (s) => (a(), u("div", {
141
- key: s.group,
142
- class: "tr-history__group"
142
+ showRenameControls: { type: Boolean, default: !1 },
143
+ renameControlOnClickOutside: { default: "confirm" }
144
+ },
145
+ emits: ["item-click", "item-title-change", "item-action"],
146
+ setup(s, { emit: m }) {
147
+ const t = s, c = m, x = (i) => {
148
+ var f;
149
+ const e = typeof ((f = i[0]) == null ? void 0 : f.group);
150
+ return e === "string" || e === "symbol";
151
+ }, h = L(() => {
152
+ const i = t.data;
153
+ return x(i) ? i : [{ group: F, items: i }];
154
+ }), E = L(() => h.value.length === 0 || h.value.every((i) => i.items.length === 0)), {
155
+ editingItem: v,
156
+ editorRefList: I,
157
+ editorConfirmRefList: y,
158
+ editorCancelRefList: M,
159
+ editorValue: C,
160
+ handleEdit: R,
161
+ handleEditCancel: o,
162
+ handleEditConfirm: p
163
+ } = Te({
164
+ renameControlOnClickOutside: t.renameControlOnClickOutside,
165
+ onItemTitleChange: (i, e) => {
166
+ c("item-title-change", i, e);
167
+ }
168
+ }), { isTouchDevice: k } = he(), _ = g(null), a = g(null), K = (i, e) => {
169
+ if (i.currentTarget instanceof HTMLButtonElement) {
170
+ if (a.value === e) {
171
+ _.value = null, a.value = null;
172
+ return;
173
+ }
174
+ _.value = i.currentTarget, a.value = e;
175
+ } else
176
+ _.value = null, a.value = null;
177
+ }, X = (i) => {
178
+ const e = a.value;
179
+ e && (i.id === "rename" && R(e), c("item-action", { id: i.id, text: i.text }, e));
180
+ };
181
+ return (i, e) => (r(), l("div", {
182
+ class: U(["tr-history", { "touch-device": n(k) }])
183
+ }, [
184
+ E.value ? (r(), J(xe, { key: 1 })) : (r(), l(B, { key: 0 }, [
185
+ (r(!0), l(B, null, H(h.value, (f) => (r(), l("div", {
186
+ class: "tr-history__group",
187
+ key: f.group
143
188
  }, [
144
- s.group !== e(E) ? (a(), u("div", xe, [
145
- p("span", null, k(s.group), 1)
146
- ])) : w("", !0),
147
- (a(!0), u(T, null, $(s.items, (d) => {
148
- var Q;
149
- return a(), u("div", {
150
- key: `${d.id}-${d.title}`,
151
- class: D(["tr-history__item", { selected: n.selected === d.id }]),
152
- onClick: (f) => z(d)
189
+ f.group !== n(F) ? (r(), l("div", be, D(f.group), 1)) : V("", !0),
190
+ w("div", $e, [
191
+ (r(!0), l(B, null, H(f.items, (u, Y) => (r(), l("div", {
192
+ class: U(["tr-history__item", {
193
+ selected: u.id && u.id === t.selected,
194
+ editing: n(v) === u,
195
+ active: a.value === u
196
+ }]),
197
+ key: u.id || Y,
198
+ onClick: (d) => c("item-click", u)
153
199
  }, [
154
- ((Q = e(x)) == null ? void 0 : Q.id) !== d.id ? (a(), u(T, { key: 0 }, [
155
- p("span", Ie, k(d.title), 1),
156
- d.tag ? (a(), N(e(de), te({
157
- key: 0,
158
- class: "tr-history__item-tag"
159
- }, { ref_for: !0 }, d.tag), null, 16)) : w("", !0),
160
- p("div", Ee, [
161
- y(e(U), {
162
- content: "编辑",
163
- effect: "dark",
164
- placement: "top",
165
- "open-delay": 500
166
- }, {
167
- default: R(() => [
168
- y(e(B), {
169
- icon: e(ne),
170
- onClick: H((f) => e(j)(d), ["stop"])
171
- }, null, 8, ["icon", "onClick"])
172
- ]),
173
- _: 2
174
- }, 1024),
175
- y(e(U), {
176
- content: "删除",
177
- effect: "dark",
178
- placement: "top",
179
- "open-delay": 500
180
- }, {
181
- default: R(() => [
182
- y(e(B), {
183
- icon: e(ae),
184
- onClick: H((f) => F(d), ["stop"])
185
- }, null, 8, ["icon", "onClick"])
186
- ]),
187
- _: 2
188
- }, 1024)
189
- ])
190
- ], 64)) : ee((a(), u("input", {
191
- key: 1,
192
- "onUpdate:modelValue": o[1] || (o[1] = (f) => e(x).title = f),
193
- class: "tr-history__item-edit",
200
+ n(v) === u ? j((r(), l("input", {
201
+ key: 0,
202
+ class: "tr-history__item-editor",
203
+ type: "text",
204
+ onClick: e[0] || (e[0] = A(() => {
205
+ }, ["stop"])),
194
206
  ref_for: !0,
195
- ref: e(J),
196
- onKeydown: o[2] || (o[2] = //@ts-ignore
197
- (...f) => e(P) && e(P)(...f))
207
+ ref_key: "editorRefList",
208
+ ref: I,
209
+ "onUpdate:modelValue": e[1] || (e[1] = (d) => se(C) ? C.value = d : null),
210
+ onKeydown: [
211
+ e[2] || (e[2] = q(
212
+ //@ts-ignore
213
+ (...d) => n(p) && n(p)(...d),
214
+ ["enter"]
215
+ )),
216
+ e[3] || (e[3] = q(
217
+ //@ts-ignore
218
+ (...d) => n(o) && n(o)(...d),
219
+ ["escape"]
220
+ ))
221
+ ]
198
222
  }, null, 544)), [
199
- [re, e(x).title]
223
+ [re, n(C)]
224
+ ]) : (r(), l("span", {
225
+ key: 1,
226
+ class: "text",
227
+ title: u.title
228
+ }, D(u.title), 9, Be)),
229
+ w("span", {
230
+ class: "tr-history__item-actions",
231
+ onClick: e[6] || (e[6] = A(() => {
232
+ }, ["stop"]))
233
+ }, [
234
+ t.showRenameControls && n(v) === u ? (r(), l("button", {
235
+ key: 0,
236
+ class: "editor-confirm",
237
+ ref_for: !0,
238
+ ref_key: "editorConfirmRefList",
239
+ ref: y,
240
+ onClick: e[4] || (e[4] = //@ts-ignore
241
+ (...d) => n(p) && n(p)(...d))
242
+ }, [
243
+ b(n(de))
244
+ ], 512)) : V("", !0),
245
+ t.showRenameControls && n(v) === u ? (r(), l("button", {
246
+ key: 1,
247
+ class: "editor-cancel",
248
+ ref_for: !0,
249
+ ref_key: "editorCancelRefList",
250
+ ref: M,
251
+ onClick: e[5] || (e[5] = //@ts-ignore
252
+ (...d) => n(o) && n(o)(...d))
253
+ }, [
254
+ b(n(me))
255
+ ], 512)) : V("", !0),
256
+ w("button", {
257
+ class: U(["menu", { hidden: n(v) === u }]),
258
+ onClick: (d) => K(d, u)
259
+ }, [
260
+ b(n(fe))
261
+ ], 10, De)
200
262
  ])
201
- ], 10, Te);
202
- }), 128))
203
- ]))), 128)) : (a(), N(e(me), {
204
- key: 1,
205
- text: m.value ? "暂无搜索结果" : "暂无内容"
206
- }, null, 8, ["text"]))
207
- ]),
208
- p("div", we, [
209
- y(e(B), {
210
- icon: e(ie),
211
- rounded: "",
212
- onClick: W
213
- }, null, 8, ["icon"])
214
- ])
215
- ]));
263
+ ], 10, Oe))), 128))
264
+ ])
265
+ ]))), 128)),
266
+ j(b(Me, {
267
+ trigger: _.value,
268
+ "onUpdate:trigger": e[7] || (e[7] = (f) => _.value = f),
269
+ data: a.value,
270
+ "onUpdate:data": e[8] || (e[8] = (f) => a.value = f),
271
+ onItemClick: X
272
+ }, null, 8, ["trigger", "data"]), [
273
+ [le, _.value]
274
+ ])
275
+ ], 64))
276
+ ], 2));
216
277
  }
217
- }), K = /* @__PURE__ */ M($e, [["__scopeId", "data-v-87ea1242"]]), Be = function(i) {
218
- i.component("TrHistory", K);
219
- }, Se = {
220
- ...K,
221
- install: Be,
222
- name: "TrHistory"
278
+ }), N = /* @__PURE__ */ z(Se, [["__scopeId", "data-v-56f0f617"]]), Ue = function(s) {
279
+ s.component(N.name, N);
223
280
  };
281
+ Object.assign(N, {
282
+ name: "TrHistory",
283
+ install: Ue
284
+ });
224
285
  export {
225
- Se as default
286
+ N as default
226
287
  };