slidev-theme-gtlabo 1.0.1 → 1.0.3

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.
@@ -5,21 +5,17 @@
5
5
  [{{ citationNumber }}]
6
6
  </sup>
7
7
 
8
- <!-- 引用情報表示エリア(画面下部に常時表示) -->
8
+ <!-- このコンポーネント専用の引用情報表示エリア -->
9
9
  <div
10
- v-if="hasCurrentPageCitations"
10
+ v-if="shouldShowCitation"
11
11
  class="fixed bottom-0 left-0 right-0 bg-white border-t-2 border-gray-300 shadow-lg z-40 max-h-32 overflow-y-auto"
12
12
  style="pointer-events: none;"
13
13
  >
14
14
  <div class="max-w-7xl mx-auto px-4 py-2">
15
15
  <div class="space-y-1">
16
- <div
17
- v-for="citation in sortedCurrentPageCitations"
18
- :key="citation.id"
19
- class="text-xs text-gray-800"
20
- >
21
- <span class="font-semibold">[{{ citation.number }}]</span>
22
- {{ citation.formatted }}
16
+ <div class="text-xs text-gray-800">
17
+ <span class="font-semibold">[{{ citationNumber }}]</span>
18
+ {{ formattedCitation }}
23
19
  </div>
24
20
  </div>
25
21
  </div>
@@ -28,7 +24,7 @@
28
24
  </template>
29
25
 
30
26
  <script setup>
31
- import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
27
+ import { computed, onMounted, onUnmounted, ref } from 'vue'
32
28
  import { useSlideContext } from '@slidev/client'
33
29
 
34
30
  const { $slidev } = useSlideContext()
@@ -41,70 +37,74 @@ const props = defineProps({
41
37
  }
42
38
  })
43
39
 
44
- // グローバル引用管理の初期化
40
+ // グローバル引用管理の初期化(引用番号のみ管理)
45
41
  if (!window.citationManager) {
46
42
  window.citationManager = {
47
43
  counter: 1,
48
- citations: new Map(), // id -> { number, data, formatted }
49
- pageActiveCitations: new Map(), // pageNumber -> Set(citationIds)
50
- components: new Set()
44
+ citations: new Map() // id -> { number, data, formatted }
51
45
  }
52
46
  }
53
47
 
54
- const forceUpdate = ref(0)
48
+ const isMounted = ref(false)
55
49
 
56
50
  // 現在のページ番号を取得
57
51
  const currentPage = computed(() => {
58
- return $slidev.nav.currentPage
52
+ const page = $slidev.nav.currentPage
53
+ return page
59
54
  })
60
55
 
61
56
  // 引用データを取得
62
57
  const citationData = computed(() => {
63
- return citations[props.id] || null
58
+ const data = citations[props.id] || null
59
+ return data
64
60
  })
65
61
 
66
62
  // 引用番号を取得または生成
67
63
  const citationNumber = computed(() => {
68
- if (!citationData.value) return '?'
64
+ if (!citationData.value) {
65
+ return '?'
66
+ }
69
67
 
70
68
  if (!window.citationManager.citations.has(props.id)) {
71
- window.citationManager.citations.set(props.id, {
69
+ const newCitation = {
72
70
  number: window.citationManager.counter,
73
71
  data: citationData.value,
74
72
  formatted: formatCitation(citationData.value)
75
- })
73
+ }
74
+ window.citationManager.citations.set(props.id, newCitation)
76
75
  window.citationManager.counter++
77
76
  }
78
77
 
79
- return window.citationManager.citations.get(props.id).number
78
+ const citation = window.citationManager.citations.get(props.id)
79
+ return citation.number
80
80
  })
81
81
 
82
- // 現在のページにアクティブな引用があるかチェック
83
- const hasCurrentPageCitations = computed(() => {
84
- forceUpdate.value // 依存関係を強制的に更新
85
- const pageSet = window.citationManager.pageActiveCitations.get(currentPage.value)
86
- return pageSet && pageSet.size > 0
82
+ // フォーマットされた引用テキスト
83
+ const formattedCitation = computed(() => {
84
+ if (!citationData.value) {
85
+ return '引用情報が見つかりません'
86
+ }
87
+
88
+ const citation = window.citationManager.citations.get(props.id)
89
+ if (citation && citation.formatted) {
90
+ return citation.formatted
91
+ }
92
+
93
+ return formatCitation(citationData.value)
87
94
  })
88
95
 
89
- // 現在のページのソートされた引用一覧
90
- const sortedCurrentPageCitations = computed(() => {
91
- forceUpdate.value // 依存関係を強制的に更新
92
- const pageSet = window.citationManager.pageActiveCitations.get(currentPage.value)
93
-
94
- if (!pageSet) return []
96
+ // 引用を表示すべきかどうか
97
+ const shouldShowCitation = computed(() => {
98
+ const shouldShow = isMounted.value && citationData.value !== null
95
99
 
96
- return Array.from(pageSet)
97
- .map(id => ({
98
- id,
99
- ...window.citationManager.citations.get(id)
100
- }))
101
- .filter(citation => citation.data) // dataが存在するもののみ
102
- .sort((a, b) => a.number - b.number)
100
+ return shouldShow
103
101
  })
104
102
 
105
103
  // 引用をフォーマット
106
104
  const formatCitation = (data) => {
107
- if (!data) return '引用情報が見つかりません'
105
+ if (!data) {
106
+ return '引用情報が見つかりません'
107
+ }
108
108
 
109
109
  let citation = ''
110
110
 
@@ -157,79 +157,39 @@ const formatCitation = (data) => {
157
157
  citation += `, ISSN: ${data.issn}`
158
158
  }
159
159
 
160
- return citation || '引用情報が不完全です'
161
- }
162
-
163
- // 全コンポーネントの再描画をトリガー
164
- const triggerGlobalUpdate = () => {
165
- window.citationManager.components.forEach(component => {
166
- if (component.updateForceUpdate) {
167
- component.updateForceUpdate()
168
- }
169
- })
170
- }
171
-
172
- // 強制更新関数
173
- const updateForceUpdate = () => {
174
- forceUpdate.value++
175
- }
176
-
177
- // 現在のページに引用を追加
178
- const addToCurrentPage = () => {
179
- if (!citationData.value) return
160
+ const formatted = citation || '引用情報が不完全です'
180
161
 
181
- const page = currentPage.value
182
- if (!window.citationManager.pageActiveCitations.has(page)) {
183
- window.citationManager.pageActiveCitations.set(page, new Set())
184
- }
185
- window.citationManager.pageActiveCitations.get(page).add(props.id)
162
+ return formatted
186
163
  }
187
164
 
188
- // 現在のページから引用を削除
189
- const removeFromCurrentPage = () => {
190
- const page = currentPage.value
191
- const pageSet = window.citationManager.pageActiveCitations.get(page)
192
- if (pageSet) {
193
- pageSet.delete(props.id)
194
- if (pageSet.size === 0) {
195
- window.citationManager.pageActiveCitations.delete(page)
196
- }
197
- }
165
+ // 全体のグローバル状態をデバッグ出力
166
+ const debugGlobalState = () => {
198
167
  }
199
168
 
200
- // ページ変更を監視
201
- watch(currentPage, (newPage, oldPage) => {
202
- if (oldPage !== undefined) {
203
- // 前のページから削除
204
- const oldPageSet = window.citationManager.pageActiveCitations.get(oldPage)
205
- if (oldPageSet) {
206
- oldPageSet.delete(props.id)
207
- if (oldPageSet.size === 0) {
208
- window.citationManager.pageActiveCitations.delete(oldPage)
209
- }
210
- }
211
- }
212
-
213
- // 新しいページに追加
214
- addToCurrentPage()
215
- triggerGlobalUpdate()
216
- })
217
-
218
169
  // コンポーネントのマウント時
219
170
  onMounted(() => {
171
+
172
+ isMounted.value = true
173
+
220
174
  if (citationData.value) {
221
- addToCurrentPage()
222
- window.citationManager.components.add({ updateForceUpdate })
223
- triggerGlobalUpdate()
175
+ // 引用番号を生成(副作用でglobal stateに保存される)
176
+ const _ = citationNumber.value
177
+ debugGlobalState()
178
+ } else {
224
179
  }
225
180
  })
226
181
 
227
182
  // コンポーネントのアンマウント時
228
183
  onUnmounted(() => {
229
- removeFromCurrentPage()
230
- window.citationManager.components.delete({ updateForceUpdate })
231
- triggerGlobalUpdate()
184
+
185
+ isMounted.value = false
186
+ debugGlobalState()
232
187
  })
188
+
189
+ // 開発用:グローバル状態確認用の関数をwindowに追加
190
+ if (typeof window !== 'undefined') {
191
+ window.debugCitationState = debugGlobalState
192
+ }
233
193
  </script>
234
194
 
235
195
  <style scoped>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "slidev-theme-gtlabo",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "A Slidev theme for laboratory presentations with customizable components",
5
5
  "author": "mksmkss",
6
6
  "license": "MIT",