memi-board 0.61.0 → 0.63.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.
Files changed (58) hide show
  1. package/README.md +2 -0
  2. package/dist/{ar-B6HWpN6c.js → ar-Dg9e1ruU.js} +27 -5
  3. package/dist/ar-Dg9e1ruU.js.map +1 -0
  4. package/dist/{commentImages-DZBDCMWH.js → commentImages-xb5Y4ySe.js} +174 -133
  5. package/dist/commentImages-xb5Y4ySe.js.map +1 -0
  6. package/dist/composables/useMemiBoardBannerGeneration.d.ts +1 -0
  7. package/dist/composables/useMemiBoardComments.d.ts +105 -1
  8. package/dist/composables/useMemiBoardPosts.d.ts +109 -1
  9. package/dist/composables/useMemiBoardStorage.d.ts +2 -1
  10. package/dist/{de-CDaEV4cd.js → de-CpGJ3KkZ.js} +27 -5
  11. package/dist/de-CpGJ3KkZ.js.map +1 -0
  12. package/dist/{en-lbbULqlq.js → en-I7auZHra.js} +36 -7
  13. package/dist/en-I7auZHra.js.map +1 -0
  14. package/dist/{es-D8LzeTe0.js → es-tMBUNff2.js} +27 -5
  15. package/dist/es-tMBUNff2.js.map +1 -0
  16. package/dist/{fr-CQDZqx5d.js → fr-BFXp_PeM.js} +27 -5
  17. package/dist/fr-BFXp_PeM.js.map +1 -0
  18. package/dist/{id-CIaQbTzK.js → id-B7lgKUHZ.js} +27 -5
  19. package/dist/id-B7lgKUHZ.js.map +1 -0
  20. package/dist/index.d.ts +5 -4
  21. package/dist/index.js +1223 -1085
  22. package/dist/index.js.map +1 -1
  23. package/dist/{ja-B2iAAzYv.js → ja-3SXam5Sk.js} +27 -5
  24. package/dist/ja-3SXam5Sk.js.map +1 -0
  25. package/dist/{pt-CXAWS0Km.js → pt-C2_VknPa.js} +27 -5
  26. package/dist/pt-C2_VknPa.js.map +1 -0
  27. package/dist/runtime/components/BannerEditor.vue +105 -52
  28. package/dist/runtime/components/CategorySettings.vue +10 -12
  29. package/dist/runtime/components/CommentItem.vue +61 -2
  30. package/dist/runtime/components/CommentRevisions.vue +87 -0
  31. package/dist/runtime/components/CustomFieldEditor.vue +85 -1
  32. package/dist/runtime/components/Detail.vue +62 -4
  33. package/dist/runtime/components/Editor.vue +5 -1
  34. package/dist/runtime/components/List.vue +19 -8
  35. package/dist/runtime/components/PostRevisions.vue +107 -0
  36. package/dist/runtime/components/Settings.vue +10 -11
  37. package/dist/storage.js +36 -27
  38. package/dist/storage.js.map +1 -1
  39. package/dist/types.d.ts +57 -0
  40. package/dist/utils/bannerGeneration.d.ts +1 -1
  41. package/dist/utils/boardPaths.d.ts +6 -0
  42. package/dist/utils/customFields.d.ts +1 -1
  43. package/dist/utils/editLimits.d.ts +6 -0
  44. package/dist/{zh-ByjHExJt.js → zh-CuOjIYyr.js} +27 -5
  45. package/dist/zh-CuOjIYyr.js.map +1 -0
  46. package/docs/firebase-setup.md +1 -1
  47. package/docs/firestore.rules.example +133 -2
  48. package/package.json +1 -1
  49. package/dist/ar-B6HWpN6c.js.map +0 -1
  50. package/dist/commentImages-DZBDCMWH.js.map +0 -1
  51. package/dist/de-CDaEV4cd.js.map +0 -1
  52. package/dist/en-lbbULqlq.js.map +0 -1
  53. package/dist/es-D8LzeTe0.js.map +0 -1
  54. package/dist/fr-CQDZqx5d.js.map +0 -1
  55. package/dist/id-CIaQbTzK.js.map +0 -1
  56. package/dist/ja-B2iAAzYv.js.map +0 -1
  57. package/dist/pt-CXAWS0Km.js.map +0 -1
  58. package/dist/zh-ByjHExJt.js.map +0 -1
@@ -1,47 +1,80 @@
1
1
  <script setup lang="ts">
2
- import { computed, onBeforeUnmount, ref, watch } from 'vue'
2
+ import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue'
3
3
  import { Cropper } from 'vue-advanced-cropper'
4
4
  import 'vue-advanced-cropper/dist/style.css'
5
5
  import { useMemiBoardBannerGeneration, useMemiBoardI18n } from 'memi-board/runtime'
6
- import type { BoardBanner } from 'memi-board/runtime'
6
+ import type { BoardBanner, BoardBannerKind } from 'memi-board/runtime'
7
7
 
8
- const props = defineProps<{ banner?: BoardBanner | null, disabled?: boolean, boardId: string, title: string, description?: string }>()
9
- const emit = defineEmits<{ change: [file: File | null], busy: [value: boolean] }>()
8
+ const props = defineProps<{
9
+ banner?: BoardBanner | null
10
+ mobileBanner?: BoardBanner | null
11
+ disabled?: boolean
12
+ boardId: string
13
+ title: string
14
+ description?: string
15
+ }>()
16
+ const emit = defineEmits<{ change: [kind: BoardBannerKind, file: File | null], busy: [value: boolean] }>()
10
17
  const { t, aiEnabled } = useMemiBoardI18n()
11
18
  const { generateBanner } = useMemiBoardBannerGeneration()
12
- const generating = ref(false)
19
+
20
+ /** Output size and crop ratio for each banner slot. */
21
+ const SLOTS: Record<BoardBannerKind, { width: number, height: number, aspect: string }> = {
22
+ desktop: { width: 2400, height: 300, aspect: 'aspect-[8/1]' },
23
+ mobile: { width: 1200, height: 400, aspect: 'aspect-[3/1]' },
24
+ }
25
+ const KINDS: BoardBannerKind[] = ['desktop', 'mobile']
26
+
27
+ const generating = ref<BoardBannerKind | null>(null)
13
28
  const additionalRequest = ref('')
14
29
  let disposed = false
15
- const busy = computed(() => props.disabled || generating.value)
30
+ const busy = computed(() => props.disabled || generating.value !== null)
16
31
  const input = ref<HTMLInputElement | null>(null)
17
32
  const cropper = ref<InstanceType<typeof Cropper> | null>(null)
18
33
  const open = ref(false)
34
+ const activeKind = ref<BoardBannerKind>('desktop')
19
35
  const source = ref('')
20
- const localPreview = ref<string | null>(null)
36
+ /** undefined = saved image, '' = removed, blob URL = staged image. */
37
+ const localPreview = reactive<Record<BoardBannerKind, string | undefined>>({ desktop: undefined, mobile: undefined })
21
38
  const cropPreview = ref('')
22
39
  const processing = ref(false)
23
40
  const error = ref('')
24
- const preview = computed(() => localPreview.value ?? props.banner?.url ?? '')
41
+ const activeSlot = computed(() => SLOTS[activeKind.value])
42
+
43
+ function savedUrl(kind: BoardBannerKind) {
44
+ return (kind === 'desktop' ? props.banner : props.mobileBanner)?.url ?? ''
45
+ }
46
+ function previewOf(kind: BoardBannerKind) {
47
+ return localPreview[kind] ?? savedUrl(kind)
48
+ }
25
49
 
26
50
  function releaseSource() {
27
51
  if (source.value) URL.revokeObjectURL(source.value)
28
52
  source.value = ''
29
53
  cropPreview.value = ''
30
54
  }
31
- function releasePreview() {
32
- if (localPreview.value) URL.revokeObjectURL(localPreview.value)
33
- localPreview.value = null
55
+ function releasePreview(kind: BoardBannerKind) {
56
+ const url = localPreview[kind]
57
+ if (url) URL.revokeObjectURL(url)
58
+ localPreview[kind] = undefined
34
59
  }
35
- watch(() => props.banner, releasePreview)
60
+ watch(() => props.banner, () => releasePreview('desktop'))
61
+ watch(() => props.mobileBanner, () => releasePreview('mobile'))
36
62
  watch(open, value => { if (!value) releaseSource() })
37
63
  onBeforeUnmount(() => {
38
64
  disposed = true
39
65
  if (generating.value) emit('busy', false)
40
66
  releaseSource()
41
- releasePreview()
67
+ KINDS.forEach(releasePreview)
42
68
  })
43
69
 
44
- async function generate() {
70
+ function openCrop(kind: BoardBannerKind, blob: Blob) {
71
+ releaseSource()
72
+ activeKind.value = kind
73
+ source.value = URL.createObjectURL(blob)
74
+ open.value = true
75
+ }
76
+
77
+ async function generate(kind: BoardBannerKind) {
45
78
  if (busy.value || !aiEnabled.value) return
46
79
  error.value = ''
47
80
  if (!props.title.trim()) {
@@ -49,17 +82,15 @@ async function generate() {
49
82
  return
50
83
  }
51
84
  const context = { boardId: props.boardId, title: props.title, description: props.description ?? '', additionalRequest: additionalRequest.value }
52
- generating.value = true
85
+ generating.value = kind
53
86
  emit('busy', true)
54
87
  try {
55
- const blob = await generateBanner(context)
88
+ const blob = await generateBanner({ ...context, kind })
56
89
  if (disposed) return
57
90
  if (props.boardId !== context.boardId || props.title !== context.title || (props.description ?? '') !== context.description || additionalRequest.value !== context.additionalRequest) {
58
91
  throw new Error(t('settings.banner.contextChanged'))
59
92
  }
60
- releaseSource()
61
- source.value = URL.createObjectURL(blob)
62
- open.value = true
93
+ openCrop(kind, blob)
63
94
  }
64
95
  catch (cause) {
65
96
  if (!disposed) {
@@ -69,11 +100,16 @@ async function generate() {
69
100
  }
70
101
  }
71
102
  finally {
72
- generating.value = false
103
+ generating.value = null
73
104
  if (!disposed) emit('busy', false)
74
105
  }
75
106
  }
76
107
 
108
+ function pick(kind: BoardBannerKind) {
109
+ activeKind.value = kind
110
+ input.value?.click()
111
+ }
112
+
77
113
  function select(event: Event) {
78
114
  const target = event.target as HTMLInputElement
79
115
  const file = target.files?.[0]
@@ -84,17 +120,16 @@ function select(event: Event) {
84
120
  error.value = t('settings.banner.invalid')
85
121
  return
86
122
  }
87
- releaseSource()
88
- source.value = URL.createObjectURL(file)
89
- open.value = true
123
+ openCrop(activeKind.value, file)
90
124
  }
91
125
 
92
126
  function updatePreview({ canvas }: { canvas?: HTMLCanvasElement | null }) {
93
127
  if (!canvas) return
128
+ const { width, height } = activeSlot.value
94
129
  const thumbnail = document.createElement('canvas')
95
- thumbnail.width = 960
96
- thumbnail.height = 120
97
- thumbnail.getContext('2d')?.drawImage(canvas, 0, 0, 960, 120)
130
+ thumbnail.width = width / 2.5
131
+ thumbnail.height = height / 2.5
132
+ thumbnail.getContext('2d')?.drawImage(canvas, 0, 0, thumbnail.width, thumbnail.height)
98
133
  cropPreview.value = thumbnail.toDataURL('image/jpeg', 0.8)
99
134
  }
100
135
 
@@ -102,23 +137,25 @@ async function confirm() {
102
137
  if (processing.value || props.disabled) return
103
138
  const { canvas } = cropper.value?.getResult() ?? {}
104
139
  if (!canvas) return
140
+ const kind = activeKind.value
141
+ const { width, height } = SLOTS[kind]
105
142
  processing.value = true
106
143
  error.value = ''
107
144
  try {
108
145
  const output = document.createElement('canvas')
109
- output.width = 2400
110
- output.height = 300
146
+ output.width = width
147
+ output.height = height
111
148
  const ctx = output.getContext('2d')
112
149
  if (!ctx) throw new Error('Canvas unavailable')
113
150
  ctx.fillStyle = '#fff'
114
- ctx.fillRect(0, 0, output.width, output.height)
115
- ctx.drawImage(canvas, 0, 0, output.width, output.height)
151
+ ctx.fillRect(0, 0, width, height)
152
+ ctx.drawImage(canvas, 0, 0, width, height)
116
153
  const blob = await new Promise<Blob | null>(resolve => output.toBlob(resolve, 'image/jpeg', 0.9))
117
154
  if (!blob) throw new Error('Image encoding failed')
118
- const file = new File([blob], 'banner.jpg', { type: 'image/jpeg' })
119
- releasePreview()
120
- localPreview.value = URL.createObjectURL(file)
121
- emit('change', file)
155
+ const file = new File([blob], `banner-${kind}.jpg`, { type: 'image/jpeg' })
156
+ releasePreview(kind)
157
+ localPreview[kind] = URL.createObjectURL(file)
158
+ emit('change', kind, file)
122
159
  open.value = false
123
160
  }
124
161
  catch {
@@ -127,23 +164,19 @@ async function confirm() {
127
164
  finally { processing.value = false }
128
165
  }
129
166
 
130
- function remove() {
131
- releasePreview()
132
- localPreview.value = ''
133
- emit('change', null)
167
+ function remove(kind: BoardBannerKind) {
168
+ releasePreview(kind)
169
+ localPreview[kind] = ''
170
+ emit('change', kind, null)
134
171
  }
135
172
  </script>
136
173
 
137
174
  <template>
138
- <section class="flex flex-col gap-3">
175
+ <section class="flex flex-col gap-4">
139
176
  <div>
140
177
  <p class="text-sm font-medium">{{ t('settings.banner.label') }}</p>
141
178
  <p class="mt-1 text-xs leading-relaxed text-muted">{{ t('settings.banner.help') }}</p>
142
179
  </div>
143
- <img v-if="preview" :src="preview" :alt="t('settings.banner.preview')" width="2400" height="300" class="aspect-[8/1] w-full rounded-xl border border-default object-cover">
144
- <div v-else class="flex aspect-[8/1] items-center justify-center rounded-xl border border-dashed border-default bg-elevated/40" aria-hidden="true">
145
- <UIcon name="i-lucide-image" class="size-6 text-dimmed" />
146
- </div>
147
180
  <UFormField v-if="aiEnabled" :label="t('settings.banner.requestLabel')" :description="t('settings.banner.requestHelp')">
148
181
  <UTextarea
149
182
  v-model="additionalRequest"
@@ -156,15 +189,35 @@ function remove() {
156
189
  autoresize
157
190
  />
158
191
  </UFormField>
159
- <div class="flex flex-wrap gap-2">
160
- <input ref="input" type="file" accept="image/jpeg,image/png,image/webp" class="hidden" :disabled="busy" :aria-label="t('settings.banner.select')" @change="select">
161
- <UButton icon="i-lucide-image-plus" color="neutral" variant="outline" size="sm" :disabled="busy" :label="t('settings.banner.select')" @click="input?.click()" />
162
- <UButton v-if="aiEnabled" icon="i-lucide-sparkles" color="primary" variant="soft" size="sm" :loading="generating" :disabled="busy || !title.trim()" :label="t('settings.banner.generate')" @click="generate" />
163
- <UButton v-if="preview" icon="i-lucide-trash-2" color="neutral" variant="ghost" size="sm" :disabled="busy" :label="t('settings.banner.remove')" @click="remove" />
192
+ <input ref="input" type="file" accept="image/jpeg,image/png,image/webp" class="hidden" :disabled="busy" :aria-label="t('settings.banner.select')" @change="select">
193
+ <div v-for="kind in KINDS" :key="kind" class="flex flex-col gap-2">
194
+ <div class="flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5">
195
+ <p class="text-sm font-medium">{{ t(`settings.banner.${kind}`) }}</p>
196
+ <p class="text-xs text-muted">{{ t(`settings.banner.${kind}Help`) }}</p>
197
+ </div>
198
+ <div :class="kind === 'mobile' ? 'w-full max-w-sm' : 'w-full'">
199
+ <img
200
+ v-if="previewOf(kind)"
201
+ :src="previewOf(kind)"
202
+ :alt="t('settings.banner.preview')"
203
+ :width="SLOTS[kind].width"
204
+ :height="SLOTS[kind].height"
205
+ class="w-full rounded-xl border border-default object-cover"
206
+ :class="SLOTS[kind].aspect"
207
+ >
208
+ <div v-else class="flex items-center justify-center rounded-xl border border-dashed border-default bg-elevated/40" :class="SLOTS[kind].aspect" aria-hidden="true">
209
+ <UIcon :name="kind === 'mobile' ? 'i-lucide-smartphone' : 'i-lucide-monitor'" class="size-6 text-dimmed" />
210
+ </div>
211
+ </div>
212
+ <div class="flex flex-wrap gap-2">
213
+ <UButton icon="i-lucide-image-plus" color="neutral" variant="outline" size="sm" :disabled="busy" :label="t('settings.banner.select')" @click="pick(kind)" />
214
+ <UButton v-if="aiEnabled" icon="i-lucide-sparkles" color="primary" variant="soft" size="sm" :loading="generating === kind" :disabled="busy || !title.trim()" :label="t('settings.banner.generate')" @click="generate(kind)" />
215
+ <UButton v-if="previewOf(kind)" icon="i-lucide-trash-2" color="neutral" variant="ghost" size="sm" :disabled="busy" :label="t('settings.banner.remove')" @click="remove(kind)" />
216
+ </div>
164
217
  </div>
165
218
  <p v-if="aiEnabled" class="text-xs text-muted">{{ generating ? t('settings.banner.generating') : t('settings.banner.generateHelp') }}</p>
166
219
  <p v-if="error" role="alert" class="text-sm text-error">{{ error }}</p>
167
- <UModal v-model:open="open" :title="t('settings.banner.crop')" :description="t('settings.banner.help')" :dismissible="!processing" :ui="{ content: 'sm:max-w-3xl' }">
220
+ <UModal v-model:open="open" :title="`${t('settings.banner.crop')} · ${t(`settings.banner.${activeKind}`)}`" :description="t(`settings.banner.${activeKind}Help`)" :dismissible="!processing" :ui="{ content: 'sm:max-w-3xl' }">
168
221
  <template #body>
169
222
  <ClientOnly>
170
223
  <Cropper
@@ -172,8 +225,8 @@ function remove() {
172
225
  ref="cropper"
173
226
  :src="source"
174
227
  class="h-72 w-full overflow-hidden rounded-xl bg-muted sm:h-96"
175
- :stencil-props="{ aspectRatio: 8 }"
176
- :canvas="{ maxWidth: 2400, maxHeight: 300 }"
228
+ :stencil-props="{ aspectRatio: activeSlot.width / activeSlot.height }"
229
+ :canvas="{ maxWidth: activeSlot.width, maxHeight: activeSlot.height }"
177
230
  image-restriction="stencil"
178
231
  @change="updatePreview"
179
232
  @error="error = t('settings.banner.failed')"
@@ -185,7 +238,7 @@ function remove() {
185
238
  </div>
186
239
  <p v-if="error" role="alert" class="mt-3 text-sm text-error">{{ error }}</p>
187
240
  <p class="mb-2 mt-4 text-xs font-medium text-muted">{{ t('settings.banner.preview') }}</p>
188
- <img v-if="cropPreview" :src="cropPreview" :alt="t('settings.banner.preview')" class="aspect-[8/1] w-full rounded-lg object-cover">
241
+ <img v-if="cropPreview" :src="cropPreview" :alt="t('settings.banner.preview')" class="w-full rounded-lg object-cover" :class="[activeSlot.aspect, activeKind === 'mobile' ? 'max-w-sm' : '']">
189
242
  </template>
190
243
  <template #footer>
191
244
  <div class="flex w-full justify-end gap-2">
@@ -3,7 +3,7 @@ import MemiBoardSurface from './BoardSurface.vue'
3
3
  import { useMemiBoardStorage } from 'memi-board/storage'
4
4
  import { computed, onMounted, ref, watch } from 'vue'
5
5
  import { boardCopyIsTranslated, boardTranslationLocales, MEMI_BOARD_LOCALES, memiBoardEnabledLocales, useMemiBoardAuth, useMemiBoardPostTranslations, useMemiBoardI18n, useMemiBoardSettings, useMemiBoardUsers } from 'memi-board/runtime'
6
- import type { BoardCategory, BoardEditorType, BoardListView, BoardVisibility, BoardWriteRole } from 'memi-board/runtime'
6
+ import type { BoardBannerFiles, BoardCategory, BoardEditorType, BoardListView, BoardVisibility, BoardWriteRole } from 'memi-board/runtime'
7
7
  import MemiBoardCustomFieldEditor from './CustomFieldEditor.vue'
8
8
  import MemiBoardOptionCards from './OptionCards.vue'
9
9
  import MemiBoardBannerEditor from './BannerEditor.vue'
@@ -107,8 +107,8 @@ const translatedDraft = ref(false)
107
107
  const saved = ref(false)
108
108
  const error = ref('')
109
109
  const bannerBusy = ref(false)
110
- const bannerFile = ref<File | null | undefined>()
111
- const { uploadBoardBanner, deleteAttachment } = useMemiBoardStorage()
110
+ const bannerFiles = ref<BoardBannerFiles>({})
111
+ const { applyBoardBannerFiles, deleteAttachment } = useMemiBoardStorage()
112
112
 
113
113
  function emptyDraft(id: string): BoardCategory {
114
114
  return {
@@ -159,7 +159,7 @@ function toDraft(category: BoardCategory): BoardCategory {
159
159
  // 카테고리 전환·최초 로드 시에만 draft를 서버 값으로 맞춘다.
160
160
  // 저장 직후 onSnapshot 갱신으로 draft.description 이 비워지거나 입력 중이던 값이 덮이지 않게 한다.
161
161
  watch(() => props.categoryId, (id) => {
162
- bannerFile.value = undefined
162
+ bannerFiles.value = {}
163
163
  translatedDraft.value = false
164
164
  if (source.value) draft.value = toDraft(source.value)
165
165
  else if (canCreate.value) draft.value = emptyDraft(id)
@@ -219,7 +219,7 @@ async function save() {
219
219
  saved.value = false
220
220
  error.value = ''
221
221
  const snapshot = { ...draft.value, autoTranslate: draft.value.autoTranslate === true }
222
- let uploadedPath: string | undefined
222
+ let uploadedPaths: string[] = []
223
223
  let translateFailed = false
224
224
  if (translationEnabled.value && snapshot.autoTranslate) {
225
225
  try {
@@ -236,12 +236,9 @@ async function save() {
236
236
  }
237
237
  try {
238
238
  const order = isNew.value ? categories.value.length : (snapshot.order ?? 0)
239
- if (bannerFile.value !== undefined) {
240
- snapshot.banner = bannerFile.value ? await uploadBoardBanner(snapshot.id, bannerFile.value) : null
241
- uploadedPath = snapshot.banner?.path
242
- }
239
+ uploadedPaths = await applyBoardBannerFiles(snapshot, bannerFiles.value)
243
240
  await saveCategory(snapshot, order)
244
- bannerFile.value = undefined
241
+ bannerFiles.value = {}
245
242
  snapshot.order = order
246
243
  snapshot.visibilityTransition = undefined
247
244
  // 저장 성공 직후 draft 유지 (스냅샷 오기 전에 watch가 비우지 않도록)
@@ -252,7 +249,7 @@ async function save() {
252
249
  if (translateFailed) error.value = t('settings.autoTranslate.failed', { count: translationCount(snapshot) })
253
250
  }
254
251
  catch (cause) {
255
- if (uploadedPath) await deleteAttachment({ path: uploadedPath }).catch(() => {})
252
+ await Promise.all(uploadedPaths.map(path => deleteAttachment({ path }).catch(() => {})))
256
253
  error.value = cause instanceof Error ? cause.message : t('settings.error.saveFailed')
257
254
  }
258
255
  finally {
@@ -278,12 +275,13 @@ async function save() {
278
275
  <MemiBoardBannerEditor
279
276
  :key="draft.id"
280
277
  :banner="draft.banner"
278
+ :mobile-banner="draft.mobileBanner"
281
279
  :board-id="draft.id"
282
280
  :title="draft.label"
283
281
  :description="draft.description"
284
282
  @busy="bannerBusy = $event"
285
283
  :disabled="saving || translating"
286
- @change="bannerFile = $event; saved = false"
284
+ @change="(kind, file) => { bannerFiles = { ...bannerFiles, [kind]: file }; saved = false }"
287
285
  />
288
286
  <div class="grid gap-2 sm:grid-cols-[9rem_1fr] sm:items-center">
289
287
  <div><p class="text-sm font-medium">{{ t('settings.id.label') }}</p><p class="text-xs text-muted">{{ t('settings.id.help') }}</p></div>
@@ -6,6 +6,7 @@ import type { Attachment, CommentModel, CommentTranslationSet } from 'memi-board
6
6
  import { useMemiBoardStorage } from 'memi-board/storage'
7
7
  import {
8
8
  COMMENT_BODY_MAX_LENGTH,
9
+ COMMENT_EDIT_LIMIT,
9
10
  displayCommentBody,
10
11
  memiBoardCommentLikesKey,
11
12
  useMemiBoardAuth,
@@ -18,6 +19,7 @@ import MemiBoardCommentAi from './CommentAi.vue'
18
19
  import MemiBoardCommentImageField from './CommentImageField.vue'
19
20
  import MemiBoardCommentReportButton from './CommentReportButton.vue'
20
21
  import MemiBoardImageLightbox from './ImageLightbox.vue'
22
+ import MemiBoardCommentRevisions from './CommentRevisions.vue'
21
23
 
22
24
  const props = defineProps<{
23
25
  comment: CommentModel
@@ -43,7 +45,7 @@ const { updateComment, setCommentBlinded } = useMemiBoardComments(
43
45
  )
44
46
  const { checkText } = useMemiBoardModeration()
45
47
  const { deleteAttachment } = useMemiBoardStorage()
46
- const { t, locale, formatRelativeDate, formatTimestampDetails } = useMemiBoardI18n()
48
+ const { t, locale, formatRelativeDate, formatTimestampDetails, formatFullDate } = useMemiBoardI18n()
47
49
  const commentLikes = inject(memiBoardCommentLikesKey, null)
48
50
 
49
51
  const editing = ref(false)
@@ -60,6 +62,11 @@ const imageField = ref<InstanceType<typeof MemiBoardCommentImageField> | null>(n
60
62
  const imageBusy = ref(false)
61
63
  const localUpdatedAt = ref(props.comment.updatedAt)
62
64
  const localBlinded = ref(props.comment.isBlinded ?? false)
65
+ // 본문·이미지 수정 횟수. 기존 댓글은 필드가 없어 0이다.
66
+ const localRevision = ref(props.comment.revision ?? 0)
67
+ const localEditedAt = ref(props.comment.editedAt)
68
+ const revisionsOpen = ref(false)
69
+ const editLimitOpen = ref(false)
63
70
  const saving = ref(false)
64
71
  const blindSaving = ref(false)
65
72
  const likeError = ref('')
@@ -82,6 +89,8 @@ watch(() => props.comment.images, (images) => {
82
89
  })
83
90
  watch(() => props.comment.updatedAt, (updatedAt) => { localUpdatedAt.value = updatedAt })
84
91
  watch(() => props.comment.isBlinded, (isBlinded) => { localBlinded.value = isBlinded ?? false })
92
+ watch(() => props.comment.revision, (revision) => { localRevision.value = revision ?? 0 })
93
+ watch(() => props.comment.editedAt, (editedAt) => { localEditedAt.value = editedAt })
85
94
  watch(() => props.comment.likeCount, (likeCount) => {
86
95
  if (likeCount != null) localLikeCount.value = likeCount
87
96
  })
@@ -92,6 +101,11 @@ const timestampDetails = computed(() => formatTimestampDetails(props.comment.cre
92
101
  const blindLines = computed(() => Math.min(3, Math.max(1, Math.ceil(localBody.value.length / 45))))
93
102
 
94
103
  function startEdit() {
104
+ // 작성자는 COMMENT_EDIT_LIMIT 번까지만 고칠 수 있다. 매니저는 제한 없음. rules 도 같은 숫자로 막는다.
105
+ if (localRevision.value >= COMMENT_EDIT_LIMIT && !canManageBoard(props.comment.boardId)) {
106
+ editLimitOpen.value = true
107
+ return
108
+ }
95
109
  editBody.value = localBody.value
96
110
  editImage.value = localImage.value
97
111
  editError.value = ''
@@ -133,12 +147,16 @@ async function saveEdit() {
133
147
  const previous = localImage.value
134
148
  const next = editImage.value
135
149
  await updateComment(props.comment.id, body, next ? [next] : [], translations.value)
150
+ if (body !== localBody.value || (previous?.path ?? '') !== (next?.path ?? '')) {
151
+ localRevision.value += 1
152
+ localEditedAt.value = Timestamp.now()
153
+ }
136
154
  localTranslations.value = translations.value
137
155
  localBody.value = body
138
156
  localImage.value = next
139
157
  localUpdatedAt.value = Timestamp.now()
140
158
  editing.value = false
141
- if (previous?.path && previous.path !== next?.path) await deleteAttachment(previous)
159
+ // 바뀌기 전 이미지는 수정 기록이 가리키므로 Storage에서 지우지 않는다.
142
160
  }
143
161
  catch (cause) {
144
162
  editError.value = cause instanceof Error ? cause.message : t('commentItem.editFailed')
@@ -220,6 +238,16 @@ async function toggleLike() {
220
238
  <span class="whitespace-pre-line">{{ timestampDetails }}</span>
221
239
  </template>
222
240
  </UTooltip>
241
+ <UTooltip
242
+ v-if="localRevision > 0"
243
+ :text="t('commentItem.editedTooltip', { count: localRevision, time: localEditedAt ? formatFullDate(localEditedAt) : '' })"
244
+ :delay-duration="200"
245
+ :content="{ side: 'top' }"
246
+ >
247
+ <UBadge variant="subtle" color="neutral" size="sm">
248
+ {{ t('commentItem.edited') }}
249
+ </UBadge>
250
+ </UTooltip>
223
251
  </div>
224
252
  <form
225
253
  v-if="editing"
@@ -361,6 +389,16 @@ async function toggleLike() {
361
389
  @click="toggleBlind"
362
390
  />
363
391
  </UTooltip>
392
+ <UTooltip v-if="localRevision > 0 && canManageBoard(comment.boardId) && comment.id" :text="t('commentItem.history')" :delay-duration="200">
393
+ <UButton
394
+ icon="i-lucide-history"
395
+ size="xs"
396
+ color="neutral"
397
+ variant="ghost"
398
+ :aria-label="t('commentItem.history')"
399
+ @click="revisionsOpen = true"
400
+ />
401
+ </UTooltip>
364
402
  <UTooltip :text="t('common.action.reply')" :delay-duration="200">
365
403
  <UButton
366
404
  icon="i-lucide-reply"
@@ -392,6 +430,27 @@ async function toggleLike() {
392
430
  />
393
431
  </UTooltip>
394
432
  </div>
433
+ <UModal v-model:open="editLimitOpen" :title="t('commentItem.editLimitTitle')">
434
+ <template #body>
435
+ <div class="space-y-4">
436
+ <UAlert
437
+ color="warning"
438
+ variant="subtle"
439
+ icon="i-lucide-triangle-alert"
440
+ :description="t('comments.editLimitReached', { max: COMMENT_EDIT_LIMIT })"
441
+ />
442
+ <div class="flex justify-end">
443
+ <UButton :label="t('common.action.confirm')" @click="editLimitOpen = false" />
444
+ </div>
445
+ </div>
446
+ </template>
447
+ </UModal>
448
+ <MemiBoardCommentRevisions
449
+ v-if="localRevision > 0 && canManageBoard(comment.boardId) && comment.id"
450
+ v-model:open="revisionsOpen"
451
+ :board-id="comment.boardId"
452
+ :comment-id="comment.id"
453
+ />
395
454
  <UModal v-model:open="blindConfirmOpen" :title="t(blindTarget ? 'commentItem.blind' : 'commentItem.unblind')" :dismissible="!blindSaving" :close="blindSaving ? false : undefined">
396
455
  <template #body>
397
456
  <div class="space-y-4">
@@ -0,0 +1,87 @@
1
+ <script setup lang="ts">
2
+ import { computed, watch } from 'vue'
3
+ import { useMemiBoardCommentRevisions, useMemiBoardI18n } from 'memi-board/runtime'
4
+
5
+ /** 댓글 수정 기록. 수정으로 덮어쓰인 이전 본문·이미지를 최신순으로 보여 준다. 보드 매니저 전용. */
6
+ const props = defineProps<{
7
+ boardId: string
8
+ commentId: string
9
+ }>()
10
+
11
+ const open = defineModel<boolean>('open', { default: false })
12
+
13
+ const { t, formatFullDate } = useMemiBoardI18n()
14
+ const { revisions, pending, error, load } = useMemiBoardCommentRevisions(() => props.boardId, () => props.commentId)
15
+
16
+ watch(open, (value) => {
17
+ if (value) void load()
18
+ })
19
+
20
+ const items = computed(() => revisions.value.map(item => ({
21
+ label: item.revision === 0 ? t('postRevisions.original') : t('postRevisions.version', { version: item.revision }),
22
+ value: item.id,
23
+ revision: item,
24
+ })))
25
+ </script>
26
+
27
+ <template>
28
+ <UModal
29
+ v-model:open="open"
30
+ :title="t('commentItem.history')"
31
+ :description="t('postRevisions.description')"
32
+ >
33
+ <template #body>
34
+ <div v-if="pending" class="space-y-3">
35
+ <USkeleton class="h-10 w-full" />
36
+ <USkeleton class="h-10 w-full" />
37
+ </div>
38
+ <UAlert
39
+ v-else-if="error"
40
+ color="error"
41
+ variant="subtle"
42
+ icon="i-lucide-circle-alert"
43
+ :title="t('postRevisions.loadFailed')"
44
+ />
45
+ <UEmpty
46
+ v-else-if="!revisions.length"
47
+ icon="i-lucide-history"
48
+ :title="t('postRevisions.empty')"
49
+ />
50
+ <UAccordion v-else :items="items" type="multiple">
51
+ <template #default="{ item }">
52
+ <div class="flex min-w-0 flex-1 flex-wrap items-center gap-x-2 gap-y-1 text-start">
53
+ <UBadge variant="subtle" color="neutral" size="sm">
54
+ {{ item.label }}
55
+ </UBadge>
56
+ <span class="text-sm text-muted">
57
+ {{ t('postRevisions.replacedAt', { time: formatFullDate(item.revision.createdAt) }) }}
58
+ </span>
59
+ <span class="text-sm text-muted">
60
+ {{ t('postRevisions.replacedBy', { name: item.revision.editedByName || item.revision.editedBy }) }}
61
+ </span>
62
+ </div>
63
+ </template>
64
+ <template #content="{ item }">
65
+ <div class="flex flex-col gap-2 pb-4">
66
+ <p class="whitespace-pre-wrap break-words text-sm">
67
+ {{ item.revision.body }}
68
+ </p>
69
+ <ULink
70
+ v-for="image in item.revision.images"
71
+ :key="image.path"
72
+ :to="image.url"
73
+ target="_blank"
74
+ class="inline-block"
75
+ >
76
+ <img
77
+ :src="image.url"
78
+ :alt="t('commentItem.attachedImage')"
79
+ class="max-h-60 max-w-full rounded-md border border-default object-contain"
80
+ >
81
+ </ULink>
82
+ </div>
83
+ </template>
84
+ </UAccordion>
85
+ </template>
86
+ </UModal>
87
+ </template>