@opentiny/tiny-robot 0.1.0 → 0.2.0-alpha.1
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/action-group/ActionGroup.vue.d.ts +26 -0
- package/dist/action-group/ActionGroupItem.vue.d.ts +18 -0
- package/dist/action-group/index.d.ts +12 -0
- package/dist/action-group/index.type.d.ts +16 -0
- package/dist/bubble/index.type.d.ts +1 -1
- package/dist/container/index.d.ts +7 -0
- package/dist/container/index.type.d.ts +16 -0
- package/dist/container/index.vue.d.ts +26 -0
- package/dist/feedback/components/SourceList.vue.d.ts +11 -0
- package/dist/feedback/components/index.d.ts +1 -0
- package/dist/feedback/index.d.ts +7 -0
- package/dist/feedback/index.type.d.ts +25 -0
- package/dist/feedback/index.vue.d.ts +13 -0
- package/dist/history/components/index.d.ts +2 -0
- package/dist/history/components/item-tag.vue.d.ts +5 -0
- package/dist/history/components/search-empty.vue.d.ts +7 -0
- package/dist/history/composables/index.d.ts +1 -0
- package/dist/history/composables/useEditItemTitle.d.ts +12 -0
- package/dist/history/index.d.ts +6 -0
- package/dist/history/index.type.d.ts +43 -0
- package/dist/history/index.vue.d.ts +2 -0
- package/dist/icon-button/index.d.ts +7 -0
- package/dist/icon-button/index.type.d.ts +7 -0
- package/dist/icon-button/index.vue.d.ts +6 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.js +56 -22
- package/dist/node_modules/.pnpm/@opentiny_utils@3.22.0/node_modules/@opentiny/utils/dist/index.es.js +1335 -884
- package/dist/node_modules/.pnpm/@opentiny_vue-common@3.22.0/node_modules/@opentiny/vue-common/lib/index.js +660 -144
- package/dist/node_modules/.pnpm/@opentiny_vue-hooks@3.22.0/node_modules/@opentiny/vue-hooks/dist/src/vue-popper.js +85 -0
- package/dist/node_modules/.pnpm/@opentiny_vue-locale@3.22.0/node_modules/@opentiny/vue-locale/lib/index.js +1783 -0
- package/dist/node_modules/.pnpm/@opentiny_vue-renderless@3.22.0/node_modules/@opentiny/vue-renderless/tooltip/index.js +77 -0
- package/dist/node_modules/.pnpm/@opentiny_vue-renderless@3.22.0/node_modules/@opentiny/vue-renderless/tooltip/vue.js +90 -0
- package/dist/node_modules/.pnpm/@opentiny_vue-tooltip@3.22.0/node_modules/@opentiny/vue-tooltip/lib/index.js +176 -0
- package/dist/node_modules/.pnpm/@opentiny_vue-tooltip@3.22.0/node_modules/@opentiny/vue-tooltip/lib/pc.js +248 -0
- package/dist/node_modules/.pnpm/@vueuse_core@13.1.0_vue@3.5.13/node_modules/@vueuse/core/index.js +190 -0
- package/dist/node_modules/.pnpm/@vueuse_shared@13.1.0_vue@3.5.13/node_modules/@vueuse/shared/index.js +53 -0
- package/dist/packages/components/src/action-group/ActionGroup.vue.js +7 -0
- package/dist/packages/components/src/action-group/ActionGroup.vue2.js +97 -0
- package/dist/packages/components/src/action-group/ActionGroupItem.vue.js +14 -0
- package/dist/packages/components/src/action-group/ActionGroupItem.vue2.js +4 -0
- package/dist/packages/components/src/action-group/index.js +17 -0
- package/dist/packages/components/src/bubble/bubble-list.vue.js +2 -2
- package/dist/packages/components/src/bubble/bubble-list.vue2.js +18 -19
- package/dist/packages/components/src/bubble/bubble.vue.js +2 -2
- package/dist/packages/components/src/bubble/bubble.vue2.js +46 -46
- package/dist/packages/components/src/container/index.js +9 -0
- package/dist/packages/components/src/container/index.vue.js +7 -0
- package/dist/packages/components/src/container/index.vue2.js +55 -0
- package/dist/packages/components/src/feedback/components/SourceList.vue.js +7 -0
- package/dist/packages/components/src/feedback/components/SourceList.vue2.js +52 -0
- package/dist/packages/components/src/feedback/index.js +9 -0
- package/dist/packages/components/src/feedback/index.vue.js +7 -0
- package/dist/packages/components/src/feedback/index.vue2.js +142 -0
- package/dist/packages/components/src/history/components/item-tag.vue.js +7 -0
- package/dist/packages/components/src/history/components/item-tag.vue2.js +21 -0
- package/dist/packages/components/src/history/components/search-empty.vue.js +7 -0
- package/dist/packages/components/src/history/components/search-empty.vue2.js +20 -0
- package/dist/packages/components/src/history/composables/useEditItemTitle.js +43 -0
- package/dist/packages/components/src/history/index.js +11 -0
- package/dist/packages/components/src/history/index.vue.js +7 -0
- package/dist/packages/components/src/history/index.vue2.js +130 -0
- package/dist/packages/components/src/icon-button/index.js +9 -0
- package/dist/packages/components/src/icon-button/index.vue.js +7 -0
- package/dist/packages/components/src/icon-button/index.vue2.js +40 -0
- package/dist/packages/components/src/prompts/prompt.vue.js +2 -2
- package/dist/packages/components/src/prompts/prompt.vue2.js +17 -15
- package/dist/packages/components/src/question/components/HotQuestions.vue.js +22 -22
- package/dist/packages/components/src/question/index.vue.js +7 -7
- package/dist/packages/components/src/sender/components/TemplateEditor.vue.js +7 -0
- package/dist/packages/components/src/sender/components/TemplateEditor.vue2.js +121 -0
- package/dist/packages/components/src/sender/index.vue.js +149 -128
- package/dist/packages/components/src/suggestion/components/CategoryNav.vue.js +38 -0
- package/dist/packages/components/src/suggestion/components/CategoryNav.vue2.js +4 -0
- package/dist/packages/components/src/suggestion/components/SuggestionCapsule.vue.js +107 -0
- package/dist/packages/components/src/suggestion/components/SuggestionCapsule.vue2.js +4 -0
- package/dist/packages/components/src/suggestion/components/SuggestionPanel.vue.js +123 -0
- package/dist/packages/components/src/suggestion/components/SuggestionPanel.vue2.js +4 -0
- package/dist/packages/components/src/suggestion/composables/useKeyboardNavigation.js +45 -0
- package/dist/packages/components/src/suggestion/composables/useTriggerDetection.js +17 -0
- package/dist/packages/components/src/suggestion/index.js +9 -0
- package/dist/packages/components/src/suggestion/index.vue.js +179 -0
- package/dist/packages/components/src/suggestion/index.vue2.js +4 -0
- package/dist/packages/components/src/suggestion/utils/dom.js +18 -0
- package/dist/packages/svgs/dist/tiny-robot-svgs.js +364 -69
- package/dist/question/components/HotQuestions.vue.d.ts +2 -2
- package/dist/question/index.vue.d.ts +1 -1
- package/dist/sender/components/ActionButtons.vue.d.ts +2 -2
- package/dist/sender/components/TemplateEditor.vue.d.ts +18 -0
- package/dist/sender/index.type.d.ts +47 -0
- package/dist/sender/index.vue.d.ts +70 -5
- package/dist/style.css +1 -1
- package/dist/suggestion/components/CategoryNav.vue.d.ts +45 -0
- package/dist/suggestion/components/SuggestionCapsule.vue.d.ts +32 -0
- package/dist/suggestion/components/SuggestionPanel.vue.d.ts +84 -0
- package/dist/suggestion/composables/useKeyboardNavigation.d.ts +18 -0
- package/dist/suggestion/composables/useSuggestionFilter.d.ts +10 -0
- package/dist/suggestion/composables/useTriggerDetection.d.ts +11 -0
- package/dist/suggestion/index.d.ts +7 -0
- package/dist/suggestion/index.type.d.ts +94 -0
- package/dist/suggestion/index.vue.d.ts +343 -0
- package/dist/suggestion/utils/dom.d.ts +20 -0
- package/package.json +5 -5
- package/src/action-group/ActionGroup.vue +232 -0
- package/src/action-group/ActionGroupItem.vue +9 -0
- package/src/action-group/index.ts +25 -0
- package/src/action-group/index.type.ts +20 -0
- package/src/bubble/bubble-list.vue +1 -3
- package/src/bubble/bubble.vue +4 -14
- package/src/bubble/index.type.ts +1 -1
- package/src/container/index.ts +12 -0
- package/src/container/index.type.ts +17 -0
- package/src/container/index.vue +134 -0
- package/src/feedback/components/SourceList.vue +112 -0
- package/src/feedback/components/index.ts +1 -0
- package/src/feedback/index.ts +12 -0
- package/src/feedback/index.type.ts +27 -0
- package/src/feedback/index.vue +166 -0
- package/src/history/components/index.ts +2 -0
- package/src/history/components/item-tag.vue +49 -0
- package/src/history/components/search-empty.vue +38 -0
- package/src/history/composables/index.ts +1 -0
- package/src/history/composables/useEditItemTitle.ts +75 -0
- package/src/history/index.ts +12 -0
- package/src/history/index.type.ts +50 -0
- package/src/history/index.vue +292 -0
- package/src/icon-button/index.ts +12 -0
- package/src/icon-button/index.type.ts +8 -0
- package/src/icon-button/index.vue +52 -0
- package/src/index.ts +37 -2
- package/src/prompts/prompt.vue +7 -21
- package/src/question/components/HotQuestions.vue +1 -1
- package/src/question/index.less +9 -10
- package/src/sender/components/TemplateEditor.vue +274 -0
- package/src/sender/index.less +17 -7
- package/src/sender/index.type.ts +51 -0
- package/src/sender/index.vue +56 -8
- package/src/sender/vars.less +3 -3
- package/src/suggestion/components/CategoryNav.vue +38 -0
- package/src/suggestion/components/SuggestionCapsule.vue +183 -0
- package/src/suggestion/components/SuggestionPanel.vue +147 -0
- package/src/suggestion/composables/useKeyboardNavigation.ts +101 -0
- package/src/suggestion/composables/useSuggestionFilter.ts +34 -0
- package/src/suggestion/composables/useTriggerDetection.ts +46 -0
- package/src/suggestion/index.less +497 -0
- package/src/suggestion/index.ts +12 -0
- package/src/suggestion/index.type.ts +101 -0
- package/src/suggestion/index.vue +338 -0
- package/src/suggestion/utils/dom.ts +66 -0
- package/src/suggestion/vars.less +141 -0
- package/.vscode/extensions.json +0 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Component, VNode } from 'vue'
|
|
2
|
+
|
|
3
|
+
export interface FeedbackProps {
|
|
4
|
+
operations?: {
|
|
5
|
+
name: string
|
|
6
|
+
label: string
|
|
7
|
+
onClick?: () => void
|
|
8
|
+
}[]
|
|
9
|
+
operationsLimit?: number
|
|
10
|
+
actions?: {
|
|
11
|
+
name: string
|
|
12
|
+
label: string
|
|
13
|
+
icon?: 'copy' | 'refresh' | 'like' | 'dislike' | VNode | Component
|
|
14
|
+
onClick?: () => void
|
|
15
|
+
}[]
|
|
16
|
+
actionsLimit?: number
|
|
17
|
+
sources?: {
|
|
18
|
+
label: string
|
|
19
|
+
link: string
|
|
20
|
+
}[]
|
|
21
|
+
sourcesLinesLimit?: number
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface FeedbackEvents {
|
|
25
|
+
(e: 'operation', name: string): void
|
|
26
|
+
(e: 'action', name: string): void
|
|
27
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
<script lang="ts" setup>
|
|
2
|
+
import { IconArrowDown, IconArrowUp, IconCopy, IconDislike, IconLike, IconRefresh } from '@opentiny/tiny-robot-svgs'
|
|
3
|
+
import TinyButton from '@opentiny/vue-button'
|
|
4
|
+
import { ref } from 'vue'
|
|
5
|
+
import ActionGroup, { ActionGroupItem } from '../action-group'
|
|
6
|
+
import IconButton from '../icon-button'
|
|
7
|
+
import { SourceList } from './components'
|
|
8
|
+
import type { FeedbackEvents, FeedbackProps } from './index.type'
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<FeedbackProps>(), {
|
|
11
|
+
operationsLimit: Number.MAX_SAFE_INTEGER,
|
|
12
|
+
actionsLimit: Number.MAX_SAFE_INTEGER,
|
|
13
|
+
sourcesLinesLimit: Number.MAX_SAFE_INTEGER,
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const iconMap = {
|
|
17
|
+
copy: IconCopy,
|
|
18
|
+
refresh: IconRefresh,
|
|
19
|
+
like: IconLike,
|
|
20
|
+
dislike: IconDislike,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const emit = defineEmits<FeedbackEvents>()
|
|
24
|
+
|
|
25
|
+
const handleOperation = (name: string) => {
|
|
26
|
+
props.operations?.find((operation) => operation.name === name)?.onClick?.()
|
|
27
|
+
emit('operation', name)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const handleAction = (name: string) => {
|
|
31
|
+
props.actions?.find((action) => action.name === name)?.onClick?.()
|
|
32
|
+
emit('action', name)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const showSourceList = ref(false)
|
|
36
|
+
|
|
37
|
+
const handleSourceList = () => {
|
|
38
|
+
showSourceList.value = !showSourceList.value
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<template>
|
|
43
|
+
<div class="tr-feedback">
|
|
44
|
+
<div class="tr-feedback__operations">
|
|
45
|
+
<div v-if="props.operations?.length" class="tr-feedback__operations-left">
|
|
46
|
+
<action-group
|
|
47
|
+
:max-num="props.operationsLimit"
|
|
48
|
+
:drop-down-show-label-only="true"
|
|
49
|
+
@item-click="handleOperation"
|
|
50
|
+
class="tr-feedback__operations-left-action-group"
|
|
51
|
+
>
|
|
52
|
+
<action-group-item
|
|
53
|
+
v-for="operation in props.operations"
|
|
54
|
+
:key="operation.name"
|
|
55
|
+
:name="operation.name"
|
|
56
|
+
:label="operation.label"
|
|
57
|
+
>
|
|
58
|
+
<tiny-button round :reset-time="0" size="mini">
|
|
59
|
+
{{ operation.label }}
|
|
60
|
+
</tiny-button>
|
|
61
|
+
</action-group-item>
|
|
62
|
+
<template #moreBtn>
|
|
63
|
+
<tiny-button round size="mini" :reset-time="0" class="tr-feedback__operations-more-btn">
|
|
64
|
+
<span>更多</span>
|
|
65
|
+
<icon-arrow-down />
|
|
66
|
+
</tiny-button>
|
|
67
|
+
</template>
|
|
68
|
+
</action-group>
|
|
69
|
+
</div>
|
|
70
|
+
<div v-else-if="props.sources?.length">
|
|
71
|
+
<span class="tr-feedback__source" @click="handleSourceList">
|
|
72
|
+
<span>{{ props.sources?.length }}条来源</span>
|
|
73
|
+
<component :is="showSourceList ? IconArrowUp : IconArrowDown" />
|
|
74
|
+
</span>
|
|
75
|
+
</div>
|
|
76
|
+
<div class="tr-feedback__operations-right">
|
|
77
|
+
<action-group :max-num="props.actionsLimit" @item-click="handleAction">
|
|
78
|
+
<action-group-item
|
|
79
|
+
v-for="action in props.actions"
|
|
80
|
+
:key="action.name"
|
|
81
|
+
:name="action.name"
|
|
82
|
+
:label="action.label"
|
|
83
|
+
>
|
|
84
|
+
<icon-button
|
|
85
|
+
v-if="typeof action.icon === 'string'"
|
|
86
|
+
:icon="iconMap[action.icon]"
|
|
87
|
+
:tooltip="action.label"
|
|
88
|
+
></icon-button>
|
|
89
|
+
<component v-else :is="action.icon"></component>
|
|
90
|
+
</action-group-item>
|
|
91
|
+
</action-group>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
<div class="tr-feedback__footer">
|
|
95
|
+
<div v-if="props.operations?.length && props.sources?.length">
|
|
96
|
+
<span class="tr-feedback__source" @click="handleSourceList">
|
|
97
|
+
<span>{{ props.sources?.length }}条来源</span>
|
|
98
|
+
<component :is="showSourceList ? IconArrowUp : IconArrowDown" />
|
|
99
|
+
</span>
|
|
100
|
+
</div>
|
|
101
|
+
<source-list
|
|
102
|
+
v-if="showSourceList && props.sources"
|
|
103
|
+
:sources="props.sources"
|
|
104
|
+
:lines-limit="props.sourcesLinesLimit"
|
|
105
|
+
/>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
</template>
|
|
109
|
+
|
|
110
|
+
<style lang="less" scoped>
|
|
111
|
+
.tr-feedback {
|
|
112
|
+
.tr-feedback__operations {
|
|
113
|
+
display: flex;
|
|
114
|
+
justify-content: space-between;
|
|
115
|
+
align-items: center;
|
|
116
|
+
gap: 8px;
|
|
117
|
+
|
|
118
|
+
.tr-feedback__operations-left {
|
|
119
|
+
.tr-feedback__operations-left-action-group {
|
|
120
|
+
gap: 8px;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.tr-feedback__operations-more-btn {
|
|
124
|
+
display: inline-flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
gap: 4px;
|
|
127
|
+
|
|
128
|
+
svg {
|
|
129
|
+
font-size: 12px;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.tr-feedback__operations-right {
|
|
135
|
+
display: flex;
|
|
136
|
+
align-items: center;
|
|
137
|
+
gap: 4px;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
.tr-feedback__footer {
|
|
141
|
+
margin-top: 8px;
|
|
142
|
+
display: flex;
|
|
143
|
+
flex-direction: column;
|
|
144
|
+
gap: 8px;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.tr-feedback__source {
|
|
148
|
+
height: 24px;
|
|
149
|
+
display: inline-flex;
|
|
150
|
+
align-items: center;
|
|
151
|
+
font-size: 12px;
|
|
152
|
+
line-height: 20px;
|
|
153
|
+
color: rgb(128, 128, 128);
|
|
154
|
+
cursor: pointer;
|
|
155
|
+
gap: 2px;
|
|
156
|
+
|
|
157
|
+
&:hover {
|
|
158
|
+
text-decoration: underline;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
svg {
|
|
162
|
+
font-size: 16px;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
</style>
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { HistoryItemTagProps } from '../index.type'
|
|
3
|
+
|
|
4
|
+
const props = withDefaults(defineProps<HistoryItemTagProps>(), {
|
|
5
|
+
type: 'default',
|
|
6
|
+
})
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<div :class="['tr-history__item-tag', props.type]" :style="props.style">
|
|
11
|
+
<span>{{ props.text }}</span>
|
|
12
|
+
</div>
|
|
13
|
+
</template>
|
|
14
|
+
|
|
15
|
+
<style lang="less" scoped>
|
|
16
|
+
.tr-history__item-tag {
|
|
17
|
+
padding: 0 4px;
|
|
18
|
+
font-size: 12px;
|
|
19
|
+
line-height: 18px;
|
|
20
|
+
border-radius: 2px;
|
|
21
|
+
|
|
22
|
+
&.default {
|
|
23
|
+
color: rgb(25, 25, 25);
|
|
24
|
+
background-color: rgb(245, 245, 245);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
&.success {
|
|
28
|
+
// TODO 成功
|
|
29
|
+
color: rgb(25, 25, 25);
|
|
30
|
+
background-color: rgb(245, 245, 245);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
&.warning {
|
|
34
|
+
// TODO 警告
|
|
35
|
+
color: rgb(25, 25, 25);
|
|
36
|
+
background-color: rgb(245, 245, 245);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
&.error {
|
|
40
|
+
color: rgb(242, 48, 48);
|
|
41
|
+
background-color: rgb(252, 227, 224);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
&.info {
|
|
45
|
+
color: rgb(20, 118, 255);
|
|
46
|
+
background-color: rgb(222, 236, 255);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
</style>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="tr-history__empty">
|
|
3
|
+
<span class="tr-history__empty-icon">
|
|
4
|
+
<IconEmptySearch />
|
|
5
|
+
</span>
|
|
6
|
+
<span class="tr-history__empty-text">{{ props.text }}</span>
|
|
7
|
+
</div>
|
|
8
|
+
</template>
|
|
9
|
+
|
|
10
|
+
<script setup lang="ts">
|
|
11
|
+
import { IconEmptySearch } from '@opentiny/tiny-robot-svgs'
|
|
12
|
+
|
|
13
|
+
const props = withDefaults(defineProps<{ text: string }>(), {
|
|
14
|
+
text: '暂无内容',
|
|
15
|
+
})
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<style lang="less" scoped>
|
|
19
|
+
.tr-history__empty {
|
|
20
|
+
display: flex;
|
|
21
|
+
flex-direction: column;
|
|
22
|
+
align-items: center;
|
|
23
|
+
justify-content: center;
|
|
24
|
+
gap: 12px;
|
|
25
|
+
padding: 84px;
|
|
26
|
+
padding-bottom: 0;
|
|
27
|
+
|
|
28
|
+
.tr-history__empty-icon {
|
|
29
|
+
font-size: 16px;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.tr-history__empty-text {
|
|
33
|
+
font-size: 12px;
|
|
34
|
+
line-height: 24px;
|
|
35
|
+
color: rgb(25, 25, 25);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
</style>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useEditItemTitle'
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { onClickOutside } from '@vueuse/core'
|
|
2
|
+
import { ComponentPublicInstance, nextTick, ref, watchEffect } from 'vue'
|
|
3
|
+
import { HistoryEvents, HistoryItem } from '../index.type'
|
|
4
|
+
|
|
5
|
+
export const useEditItemTitle = (emit: HistoryEvents) => {
|
|
6
|
+
const editingItem = ref<Pick<HistoryItem, 'id' | 'title'> & { rawData: HistoryItem }>()
|
|
7
|
+
|
|
8
|
+
const handleEdit = (item: HistoryItem) => {
|
|
9
|
+
editingItem.value = {
|
|
10
|
+
id: item.id,
|
|
11
|
+
title: item.title,
|
|
12
|
+
rawData: item,
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const inputRef = ref<HTMLInputElement | null>(null)
|
|
17
|
+
|
|
18
|
+
const handleEditorInputRef = (el: Element | ComponentPublicInstance | null) => {
|
|
19
|
+
if (!el) {
|
|
20
|
+
return
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
nextTick(() => {
|
|
24
|
+
inputRef.value = el as HTMLInputElement
|
|
25
|
+
inputRef.value.focus()
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let stopFn: (() => void) | undefined = undefined
|
|
30
|
+
|
|
31
|
+
const handleConfirm = () => {
|
|
32
|
+
if (editingItem.value) {
|
|
33
|
+
if (editingItem.value.title !== editingItem.value.rawData.title) {
|
|
34
|
+
const { title, rawData } = editingItem.value
|
|
35
|
+
emit('item-title-change', title, rawData)
|
|
36
|
+
}
|
|
37
|
+
editingItem.value = undefined
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
stopFn?.()
|
|
41
|
+
stopFn = undefined
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const handleCancel = () => {
|
|
45
|
+
editingItem.value = undefined
|
|
46
|
+
stopFn?.()
|
|
47
|
+
stopFn = undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const handleKeyDown = (e: KeyboardEvent) => {
|
|
51
|
+
if (e.key === 'Enter') {
|
|
52
|
+
handleConfirm()
|
|
53
|
+
} else if (e.key === 'Escape') {
|
|
54
|
+
handleCancel()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
watchEffect(() => {
|
|
59
|
+
if (!inputRef.value) {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
stopFn?.()
|
|
64
|
+
stopFn = onClickOutside(inputRef, () => {
|
|
65
|
+
handleConfirm()
|
|
66
|
+
})
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
editingItem,
|
|
71
|
+
handleEdit,
|
|
72
|
+
handleEditorInputRef,
|
|
73
|
+
handleKeyDown,
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { CSSProperties } from 'vue'
|
|
2
|
+
|
|
3
|
+
interface BaseHistoryProps {
|
|
4
|
+
activeTab?: string
|
|
5
|
+
searchBar?: boolean
|
|
6
|
+
searchQuery?: string
|
|
7
|
+
searchPlaceholder?: string
|
|
8
|
+
searchFn?: (query: string, item: HistoryItem) => boolean
|
|
9
|
+
selected?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type SingleTabHistoryProps = {
|
|
13
|
+
tabTitle: string
|
|
14
|
+
data: HistoryGroup[]
|
|
15
|
+
} & BaseHistoryProps
|
|
16
|
+
|
|
17
|
+
export type MultiTabHistoryProps = {
|
|
18
|
+
tabs: {
|
|
19
|
+
title: string
|
|
20
|
+
id: string
|
|
21
|
+
}[]
|
|
22
|
+
data: Record<string, HistoryGroup[]>
|
|
23
|
+
} & BaseHistoryProps
|
|
24
|
+
|
|
25
|
+
export type HistoryProps = SingleTabHistoryProps | MultiTabHistoryProps
|
|
26
|
+
|
|
27
|
+
export interface HistoryGroup<T = Record<string, unknown>> {
|
|
28
|
+
date: string
|
|
29
|
+
items: HistoryItem<T>[]
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface HistoryItemTagProps {
|
|
33
|
+
text: string
|
|
34
|
+
type?: 'success' | 'warning' | 'error' | 'info' | 'default'
|
|
35
|
+
style?: CSSProperties
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface HistoryItem<T = Record<string, unknown>> {
|
|
39
|
+
id: string
|
|
40
|
+
title: string
|
|
41
|
+
tag?: HistoryItemTagProps
|
|
42
|
+
data?: T
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface HistoryEvents {
|
|
46
|
+
(e: 'close'): void
|
|
47
|
+
(e: 'item-click', item: HistoryItem): void
|
|
48
|
+
(e: 'item-title-change', newTitle: string, rawData: HistoryItem): void
|
|
49
|
+
(e: 'item-delete', item: HistoryItem): void
|
|
50
|
+
}
|