@opentiny/tiny-robot 0.3.0-alpha.8 → 0.3.0-rc.0

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,429 +0,0 @@
1
- import { ref as m, computed as H, watch as D, defineComponent as j, onMounted as Z, onBeforeUnmount as ne, createElementBlock as d, openBlock as i, normalizeClass as V, createElementVNode as t, withDirectives as le, Fragment as L, renderList as R, createVNode as T, unref as q, toDisplayString as S, vShow as ie, nextTick as ae, createCommentVNode as Y, withModifiers as ce, normalizeStyle as ue, renderSlot as B, createTextVNode as ee, createBlock as K, withCtx as N } from "vue";
2
- import { m as X, U as te, e as se, v as de, A as re } from "../tiny-robot-svgs.js";
3
- import { i as me } from "../close.js";
4
- import { B as ve } from "../index5.js";
5
- function he(v = m([])) {
6
- const w = m(""), y = m(!1), a = m(!1), r = m("light"), k = H(() => {
7
- if (!w.value && v.value.length > 0)
8
- return v.value[0].questions;
9
- const s = v.value.find((l) => l.id === w.value);
10
- return s ? s.questions : [];
11
- }), x = (s) => {
12
- w.value = s;
13
- }, p = () => {
14
- a.value = !0;
15
- }, _ = () => {
16
- a.value = !1;
17
- }, c = () => {
18
- y.value = !y.value;
19
- }, b = (s) => {
20
- const l = document.body;
21
- if (s) {
22
- const Q = window.scrollY || document.documentElement.scrollTop;
23
- l.style.position = "fixed", l.style.width = "100%", l.style.top = `-${Q}px`, l.style.overflowY = "scroll", l.classList.add("tr-modal-open");
24
- } else
25
- l.style.position = "", l.style.width = "", l.style.top = "", l.style.overflowY = "", l.classList.remove("tr-modal-open");
26
- };
27
- return D(a, (s) => {
28
- b(s);
29
- }), {
30
- activeCategory: w,
31
- isFloatingExpanded: y,
32
- modalVisible: a,
33
- currentTheme: r,
34
- activeQuestions: k,
35
- setActiveCategory: x,
36
- openModal: p,
37
- closeModal: _,
38
- toggleFloating: c,
39
- toggleTheme: () => {
40
- r.value = r.value === "light" ? "dark" : "light", document.documentElement.setAttribute("data-theme", r.value);
41
- },
42
- setTheme: (s) => {
43
- r.value = s, document.documentElement.setAttribute("data-theme", s);
44
- },
45
- refreshData: async () => Promise.resolve(),
46
- toggleBodyScroll: b
47
- };
48
- }
49
- const pe = { class: "tr-common-questions_content" }, fe = { class: "tr-common-questions_expanded-wrapper" }, ge = { class: "tr-common-questions_expanded-area" }, ye = ["onClick"], ke = { class: "tr-common-questions_item_icon" }, _e = { class: "tr-common-questions_item_text" }, Ce = { class: "tr-common-questions_container" }, qe = ["onClick"], $e = { class: "tr-common-questions_item_icon" }, we = { class: "tr-common-questions_item_text" }, xe = /* @__PURE__ */ j({
50
- __name: "CommonQuestions",
51
- props: {
52
- questions: {
53
- type: Array,
54
- required: !0
55
- },
56
- isExpanded: {
57
- type: Boolean,
58
- default: !1
59
- }
60
- },
61
- emits: ["question-click", "toggle-expand", "hover-change"],
62
- setup(v, { emit: w }) {
63
- const y = v, a = w, r = m(null), k = m(!1), x = m(!1), p = m(!1), _ = m([]), c = m([]), b = m(0), f = m(null), o = H(() => c.value.length > 0), u = H(() => {
64
- if (b.value <= 0 || c.value.length === 0) return [];
65
- const e = [], h = [...c.value];
66
- for (; h.length > 0; )
67
- e.push(h.splice(0, b.value));
68
- return e.reverse();
69
- }), s = (e, h, $ = 40) => {
70
- if (h.length === 0) return 0;
71
- const E = e.clientWidth, W = 8, g = document.createElement("div");
72
- g.className = "tr-common-questions_item", g.style.visibility = "hidden", g.style.position = "absolute", e.appendChild(g);
73
- let O = 0;
74
- const z = Math.min(3, h.length);
75
- for (let A = 0; A < z; A++) {
76
- g.innerHTML = `<span class="icon-placeholder"></span>${h[A].text}`;
77
- const G = g.offsetWidth + W + 24;
78
- O += G;
79
- }
80
- const M = O / z;
81
- return e.removeChild(g), {
82
- maxItemsCount: Math.max(1, Math.floor((E - $) / M))
83
- };
84
- }, l = (e, h, $, E = 40) => {
85
- const g = [], O = [];
86
- let z = 0;
87
- if (h.length === 0)
88
- return { visible: g, hidden: O };
89
- const M = document.createElement("div");
90
- M.className = "tr-common-questions_item", M.style.visibility = "hidden", M.style.position = "absolute", e.appendChild(M);
91
- for (let A = 0; A < h.length; A++) {
92
- const I = h[A];
93
- M.innerHTML = `<span class="icon-placeholder"></span>${I.text}`;
94
- const J = M.offsetWidth + 8 + 24, oe = $ - E;
95
- z + J <= oe ? (z += J, g.push(I)) : O.push(I);
96
- }
97
- return e.removeChild(M), { visible: g, hidden: O };
98
- };
99
- D(
100
- () => y.isExpanded,
101
- (e) => {
102
- p.value = e, e ? _.value.pop() : _.value.push(c.value[0]);
103
- }
104
- );
105
- const Q = async () => {
106
- if (await ae(), r.value) {
107
- const e = r.value, h = e.clientWidth, $ = 40;
108
- if (_.value = [], c.value = [], y.questions.length === 0) {
109
- x.value = !1;
110
- return;
111
- }
112
- const { maxItemsCount: E } = s(e, y.questions, $);
113
- b.value = E;
114
- const { visible: W, hidden: g } = l(e, y.questions, h, $);
115
- _.value = W, c.value = g, c.value.length > 0 && _.value.push(c.value[0]), x.value = c.value.length > 0, y.isExpanded || (p.value = !1);
116
- }
117
- }, P = () => {
118
- f.value && (clearTimeout(f.value), f.value = null), k.value = !0, a("hover-change", !0);
119
- }, U = () => {
120
- f.value = setTimeout(() => {
121
- k.value = !1, a("hover-change", !1), f.value = null;
122
- }, 500);
123
- }, n = (e) => {
124
- a("question-click", e);
125
- };
126
- D(
127
- () => y.questions,
128
- () => {
129
- Q();
130
- },
131
- { deep: !0 }
132
- );
133
- const C = () => {
134
- Q();
135
- };
136
- return Z(() => {
137
- Q(), window.addEventListener("resize", C);
138
- }), ne(() => {
139
- window.removeEventListener("resize", C), f.value && (window.clearTimeout(f.value), f.value = null);
140
- }), (e, h) => (i(), d("div", {
141
- class: V(["tr-common-questions", { expanded: p.value }]),
142
- ref_key: "commonQuestionsRef",
143
- ref: r,
144
- onMouseenter: P,
145
- onMouseleave: U
146
- }, [
147
- t("div", pe, [
148
- t("div", fe, [
149
- le(t("div", ge, [
150
- (i(!0), d(L, null, R(u.value, ($, E) => (i(), d("div", {
151
- key: `row-${E}`,
152
- class: "tr-common-questions_row"
153
- }, [
154
- (i(!0), d(L, null, R($, (W, g) => (i(), d("div", {
155
- key: `hidden-${W.id}-${g}`,
156
- class: "tr-common-questions_item",
157
- onClick: (O) => n(W)
158
- }, [
159
- t("div", ke, [
160
- T(q(X))
161
- ]),
162
- t("div", _e, S(W.text), 1)
163
- ], 8, ye))), 128))
164
- ]))), 128))
165
- ], 512), [
166
- [ie, p.value && c.value.length > 0]
167
- ])
168
- ]),
169
- t("div", Ce, [
170
- (i(!0), d(L, null, R(_.value, ($, E) => (i(), d("div", {
171
- key: `visible-${$.id}-${E}`,
172
- class: V(["tr-common-questions_item", { "last-item": !p.value && E === _.value.length - 1 && o.value }]),
173
- onClick: (W) => n($)
174
- }, [
175
- t("div", $e, [
176
- T(q(X))
177
- ]),
178
- t("div", we, S($.text), 1)
179
- ], 10, qe))), 128))
180
- ])
181
- ])
182
- ], 34));
183
- }
184
- }), be = { class: "tr-question-header" }, Ee = { style: { display: "flex", "align-items": "center", gap: "12px", "font-size": "36px" } }, Qe = {
185
- key: 0,
186
- class: "tr-question-categories"
187
- }, We = ["onClick"], Me = { class: "category-icon" }, Te = { class: "tr-question-content" }, Be = {
188
- key: 0,
189
- class: "tr-question-loading"
190
- }, Se = { key: 1 }, Oe = ["onClick"], Ae = {
191
- key: 2,
192
- class: "tr-question-empty"
193
- }, ze = /* @__PURE__ */ j({
194
- __name: "HotQuestions",
195
- props: {
196
- visible: {
197
- type: Boolean,
198
- default: !1
199
- },
200
- categories: {
201
- type: Array,
202
- default: () => []
203
- },
204
- modalWidth: {
205
- type: String,
206
- default: "640px"
207
- },
208
- loading: {
209
- type: Boolean,
210
- default: !1
211
- },
212
- closeOnClickOutside: {
213
- type: Boolean,
214
- default: !0
215
- }
216
- },
217
- emits: ["update:visible", "close", "select-category", "question-click"],
218
- setup(v, { emit: w }) {
219
- const y = me(), a = v, r = w, k = m(""), x = H(() => {
220
- if (!k.value && a.categories.length > 0)
221
- return a.categories[0].questions || [];
222
- const o = a.categories.find((u) => u.id === k.value);
223
- return o ? o.questions : [];
224
- });
225
- D(
226
- () => a.categories,
227
- (o) => {
228
- o.length > 0 && !k.value && (k.value = o[0].id);
229
- },
230
- { immediate: !0 }
231
- );
232
- const p = () => {
233
- r("update:visible", !1), r("close");
234
- }, _ = (o) => {
235
- k.value = o, r(
236
- "select-category",
237
- a.categories.find((u) => u.id === o)
238
- );
239
- }, c = (o) => {
240
- r("question-click", o);
241
- }, b = (o) => {
242
- a.closeOnClickOutside && !o.composedPath().includes(f.value) && p();
243
- }, f = m(null);
244
- return (o, u) => v.visible ? (i(), d("div", {
245
- key: 0,
246
- class: "tr-question-modal-backdrop",
247
- onMousedown: b
248
- }, [
249
- t("div", {
250
- ref_key: "modalRef",
251
- ref: f,
252
- class: "tr-question-panel",
253
- style: ue({ width: v.modalWidth }),
254
- onMousedown: u[0] || (u[0] = ce(() => {
255
- }, ["stop"]))
256
- }, [
257
- t("div", be, [
258
- t("div", Ee, [
259
- t("div", null, [
260
- T(q(te), { style: { color: "#1476ff", "font-size": "24px" } })
261
- ]),
262
- u[1] || (u[1] = t("div", { class: "tr-question-header-title" }, "热门问题", -1))
263
- ]),
264
- t("span", {
265
- class: "tr-question-close-btn",
266
- onClick: p
267
- }, [
268
- T(q(ve), {
269
- icon: q(y),
270
- type: "text"
271
- }, null, 8, ["icon"])
272
- ])
273
- ]),
274
- v.categories.length > 0 ? (i(), d("div", Qe, [
275
- (i(!0), d(L, null, R(v.categories, (s) => (i(), d("div", {
276
- key: s.id,
277
- class: V(["tr-question-categories-item", { active: k.value === s.id }]),
278
- onClick: (l) => _(s.id)
279
- }, [
280
- B(o.$slots, "category-label", { category: s }, () => [
281
- t("div", Me, [
282
- T(q(se))
283
- ]),
284
- t("span", null, S(s.label), 1)
285
- ])
286
- ], 10, We))), 128))
287
- ])) : Y("", !0),
288
- t("div", Te, [
289
- v.loading ? (i(), d("div", Be, [
290
- B(o.$slots, "loading-indicator", {}, () => [
291
- u[2] || (u[2] = t("div", { class: "tr-question-loading-spinner" }, null, -1))
292
- ])
293
- ])) : x.value.length > 0 ? (i(), d("ul", Se, [
294
- (i(!0), d(L, null, R(x.value, (s, l) => (i(), d("li", {
295
- key: s.id,
296
- class: "tr-question-list-item",
297
- onClick: (Q) => c(s)
298
- }, [
299
- B(o.$slots, "question-item", {
300
- question: s,
301
- index: l
302
- }, () => [
303
- t("span", null, S(l + 1) + ".", 1),
304
- ee(" " + S(s.text), 1)
305
- ])
306
- ], 8, Oe))), 128))
307
- ])) : (i(), d("div", Ae, [
308
- B(o.$slots, "empty-state", {}, () => [
309
- u[3] || (u[3] = t("p", null, "暂无相关问题", -1))
310
- ])
311
- ]))
312
- ])
313
- ], 36)
314
- ], 32)) : Y("", !0);
315
- }
316
- }), Le = ["data-theme"], Re = { class: "tr-question__header" }, He = { class: "category-icon" }, F = /* @__PURE__ */ j({
317
- __name: "index",
318
- props: {
319
- categories: { default: () => [] },
320
- commonQuestions: { default: () => [] },
321
- initialExpanded: { type: Boolean, default: !1 },
322
- modalWidth: { default: "640px" },
323
- theme: { default: "light" },
324
- closeOnClickOutside: { type: Boolean, default: !0 },
325
- loading: { type: Boolean, default: !1 }
326
- },
327
- emits: ["question-click", "select-category"],
328
- setup(v, { expose: w, emit: y }) {
329
- const a = v, r = () => {
330
- p.value = !p.value;
331
- }, k = y, x = H(() => a.categories), p = m(a.initialExpanded), _ = m(!1), { modalVisible: c, currentTheme: b, setActiveCategory: f, openModal: o, closeModal: u, setTheme: s, refreshData: l } = he(x);
332
- D(
333
- () => a.theme,
334
- (n) => {
335
- s(n);
336
- }
337
- );
338
- const Q = (n) => {
339
- u(), k("question-click", n);
340
- }, P = (n) => {
341
- _.value = n;
342
- }, U = (n) => {
343
- n && (f(n.id), k("select-category", n));
344
- };
345
- return Z(() => {
346
- document.documentElement.setAttribute("data-theme", b.value);
347
- }), w({
348
- openModal: o,
349
- closeModal: u,
350
- toggleFloating: r,
351
- setActiveCategory: f,
352
- refreshData: l
353
- }), (n, C) => (i(), d("div", {
354
- class: V(["tr-question-container", [`theme-${n.theme}`]]),
355
- "data-theme": n.theme
356
- }, [
357
- t("div", Re, [
358
- t("div", {
359
- class: "tr-question__trigger",
360
- onClick: C[0] || (C[0] = //@ts-ignore
361
- (...e) => q(o) && q(o)(...e))
362
- }, [
363
- T(q(te), { style: { color: "#1476ff" } })
364
- ]),
365
- T(xe, {
366
- questions: n.commonQuestions,
367
- isExpanded: p.value,
368
- onQuestionClick: Q,
369
- onHoverChange: P
370
- }, null, 8, ["questions", "isExpanded"]),
371
- _.value ? (i(), d("div", {
372
- key: 0,
373
- class: "tr-question__expand-button",
374
- onClick: r
375
- }, [
376
- p.value ? (i(), K(q(re), { key: 1 })) : (i(), K(q(de), { key: 0 }))
377
- ])) : Y("", !0)
378
- ]),
379
- T(ze, {
380
- visible: q(c),
381
- categories: x.value,
382
- "modal-width": n.modalWidth,
383
- loading: n.loading,
384
- "close-on-click-outside": n.closeOnClickOutside,
385
- "onUpdate:visible": C[1] || (C[1] = (e) => c.value = e),
386
- onClose: C[2] || (C[2] = (e) => c.value = !1),
387
- onQuestionClick: Q,
388
- onSelectCategory: U
389
- }, {
390
- "category-label": N(({ category: e }) => [
391
- B(n.$slots, "category-label", { category: e }, () => [
392
- t("div", He, [
393
- T(q(se))
394
- ]),
395
- t("span", null, S(e.label), 1)
396
- ])
397
- ]),
398
- "question-item": N(({ question: e, index: h }) => [
399
- B(n.$slots, "question-item", {
400
- question: e,
401
- index: h
402
- }, () => [
403
- t("span", null, S(h + 1) + ".", 1),
404
- ee(" " + S(e.text), 1)
405
- ])
406
- ]),
407
- "loading-indicator": N(() => [
408
- B(n.$slots, "loading-indicator", {}, () => [
409
- C[3] || (C[3] = t("div", { class: "tr-question-loading-spinner" }, null, -1))
410
- ])
411
- ]),
412
- "empty-state": N(() => [
413
- B(n.$slots, "empty-state", {}, () => [
414
- C[4] || (C[4] = t("p", null, "暂无相关问题", -1))
415
- ])
416
- ]),
417
- _: 3
418
- }, 8, ["visible", "categories", "modal-width", "loading", "close-on-click-outside"])
419
- ], 10, Le));
420
- }
421
- });
422
- F.name = "TrQuestion";
423
- const De = function(v) {
424
- v.component(F.name, F);
425
- };
426
- F.install = De;
427
- export {
428
- F as default
429
- };