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

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,286 @@
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 a, openBlock as l, createElementVNode as w, createVNode as T, 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 le, vShow as re } 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 b = 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
+ b++, b === 1 && ($ = ye());
28
+ }), ee(() => {
29
+ b = Math.max(0, b - 1), b === 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) => (l(), a("div", Ce, [
42
+ w("span", ke, [
43
+ T(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, _) => (l(), a("ul", {
80
+ class: "tr-history__menu-list",
81
+ ref_key: "menuRef",
82
+ ref: E,
83
+ style: ne(o.value)
84
+ }, [
85
+ (l(), a(B, null, H(h, (r) => w("li", {
86
+ class: "tr-history__menu-list__item",
87
+ key: r.id,
88
+ onClick: (K) => p(r)
89
+ }, [
90
+ (l(), J(oe(r.icon))),
91
+ w("span", null, D(r.text), 1)
92
+ ], 8, Re)), 64))
93
+ ], 4));
94
+ }
95
+ }), Me = /* @__PURE__ */ z(Ie, [["__scopeId", "data-v-67ba5dd7"]]), be = ({
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"), Te = {
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
+ } = be({
164
+ renameControlOnClickOutside: t.renameControlOnClickOutside,
165
+ onItemTitleChange: (i, e) => {
166
+ c("item-title-change", i, e);
167
+ }
168
+ }), { isTouchDevice: k } = he(), _ = g(null), r = g(null), K = (i, e) => {
169
+ if (i.currentTarget instanceof HTMLButtonElement) {
170
+ if (r.value === e) {
171
+ _.value = null, r.value = null;
172
+ return;
173
+ }
174
+ _.value = i.currentTarget, r.value = e;
175
+ } else
176
+ _.value = null, r.value = null;
177
+ }, X = (i) => {
178
+ i.id === "rename" && r.value && R(r.value), c("item-action", { id: i.id, text: i.text });
179
+ };
180
+ return (i, e) => (l(), a("div", {
181
+ class: U(["tr-history", { "touch-device": n(k) }])
182
+ }, [
183
+ E.value ? (l(), J(xe, { key: 1 })) : (l(), a(B, { key: 0 }, [
184
+ (l(!0), a(B, null, H(h.value, (f) => (l(), a("div", {
185
+ class: "tr-history__group",
186
+ key: f.group
143
187
  }, [
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)
188
+ f.group !== n(F) ? (l(), a("div", Te, D(f.group), 1)) : V("", !0),
189
+ w("div", $e, [
190
+ (l(!0), a(B, null, H(f.items, (u, Y) => (l(), a("div", {
191
+ class: U(["tr-history__item", {
192
+ selected: u.id && u.id === t.selected,
193
+ editing: n(v) === u,
194
+ active: r.value === u
195
+ }]),
196
+ key: u.id || Y,
197
+ onClick: (d) => c("item-click", u)
153
198
  }, [
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",
199
+ n(v) === u ? j((l(), a("input", {
200
+ key: 0,
201
+ class: "tr-history__item-editor",
202
+ type: "text",
203
+ onClick: e[0] || (e[0] = A(() => {
204
+ }, ["stop"])),
194
205
  ref_for: !0,
195
- ref: e(J),
196
- onKeydown: o[2] || (o[2] = //@ts-ignore
197
- (...f) => e(P) && e(P)(...f))
206
+ ref_key: "editorRefList",
207
+ ref: I,
208
+ "onUpdate:modelValue": e[1] || (e[1] = (d) => se(C) ? C.value = d : null),
209
+ onKeydown: [
210
+ e[2] || (e[2] = q(
211
+ //@ts-ignore
212
+ (...d) => n(p) && n(p)(...d),
213
+ ["enter"]
214
+ )),
215
+ e[3] || (e[3] = q(
216
+ //@ts-ignore
217
+ (...d) => n(o) && n(o)(...d),
218
+ ["escape"]
219
+ ))
220
+ ]
198
221
  }, null, 544)), [
199
- [re, e(x).title]
222
+ [le, n(C)]
223
+ ]) : (l(), a("span", {
224
+ key: 1,
225
+ class: "text",
226
+ title: u.title
227
+ }, D(u.title), 9, Be)),
228
+ w("span", {
229
+ class: "tr-history__item-actions",
230
+ onClick: e[6] || (e[6] = A(() => {
231
+ }, ["stop"]))
232
+ }, [
233
+ t.showRenameControls && n(v) === u ? (l(), a("button", {
234
+ key: 0,
235
+ class: "editor-confirm",
236
+ ref_for: !0,
237
+ ref_key: "editorConfirmRefList",
238
+ ref: y,
239
+ onClick: e[4] || (e[4] = //@ts-ignore
240
+ (...d) => n(p) && n(p)(...d))
241
+ }, [
242
+ T(n(de))
243
+ ], 512)) : V("", !0),
244
+ t.showRenameControls && n(v) === u ? (l(), a("button", {
245
+ key: 1,
246
+ class: "editor-cancel",
247
+ ref_for: !0,
248
+ ref_key: "editorCancelRefList",
249
+ ref: M,
250
+ onClick: e[5] || (e[5] = //@ts-ignore
251
+ (...d) => n(o) && n(o)(...d))
252
+ }, [
253
+ T(n(me))
254
+ ], 512)) : V("", !0),
255
+ w("button", {
256
+ class: U(["menu", { hidden: n(v) === u }]),
257
+ onClick: (d) => K(d, u)
258
+ }, [
259
+ T(n(fe))
260
+ ], 10, De)
200
261
  ])
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
- ]));
262
+ ], 10, Oe))), 128))
263
+ ])
264
+ ]))), 128)),
265
+ j(T(Me, {
266
+ trigger: _.value,
267
+ "onUpdate:trigger": e[7] || (e[7] = (f) => _.value = f),
268
+ data: r.value,
269
+ "onUpdate:data": e[8] || (e[8] = (f) => r.value = f),
270
+ onItemClick: X
271
+ }, null, 8, ["trigger", "data"]), [
272
+ [re, _.value]
273
+ ])
274
+ ], 64))
275
+ ], 2));
216
276
  }
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"
277
+ }), N = /* @__PURE__ */ z(Se, [["__scopeId", "data-v-f245b590"]]), Ue = function(s) {
278
+ s.component(N.name, N);
223
279
  };
280
+ Object.assign(N, {
281
+ name: "TrHistory",
282
+ install: Ue
283
+ });
224
284
  export {
225
- Se as default
285
+ N as default
226
286
  };