@antelopejs/dms-lang 0.1.0 → 0.2.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.
- package/README.md +2 -2
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/pages/languages-table.js +3 -3
- package/dist/pages/languages-table.js.map +1 -1
- package/dist/utils/dialogs.js +2 -2
- package/dist/utils/dialogs.js.map +1 -1
- package/frontend-vue/app/build/composables/useMatrixView.ts +12 -14
- package/frontend-vue/app/components/WorkspaceList.vue +15 -23
- package/frontend-vue/app/components/WorkspaceScope.vue +4 -42
- package/frontend-vue/app/composables/translation/useI18nWorkspaces.ts +58 -63
- package/frontend-vue/app/composables/translation/useKeyActions.ts +1 -1
- package/frontend-vue/app/composables/translation/useLanguageActions.ts +12 -9
- package/frontend-vue/app/composables/translation/useWorkspaceActions.ts +3 -5
- package/frontend-vue/app/composables/translation/useWorkspaceFill.ts +50 -0
- package/frontend-vue/app/composables/translation/useWorkspaceFlat.ts +182 -208
- package/frontend-vue/app/composables/translation/useWorkspaceRoute.ts +2 -12
- package/frontend-vue/package.json +2 -2
- package/package.json +7 -6
- package/frontend-vue/app/composables/translation/useServedConfirm.ts +0 -152
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { EffectScope, Ref } from 'vue'
|
|
1
|
+
import type { EffectScope, MaybeRefOrGetter, Ref } from 'vue'
|
|
2
2
|
import { useEventListener } from '@vueuse/core'
|
|
3
|
-
import {
|
|
3
|
+
import type { DmsAsyncDataResult } from '#dms/frontend-module'
|
|
4
4
|
import type {
|
|
5
|
-
FlatCounts,
|
|
6
5
|
FlatTranslationRow,
|
|
7
6
|
FlatTranslations,
|
|
8
7
|
KeyRowResponse,
|
|
@@ -12,12 +11,11 @@ import { EMPTY_FLAT, withRow } from '../../utils/translations'
|
|
|
12
11
|
/** Realtime topic the backend publishes on after each write. */
|
|
13
12
|
export const LANG_REALTIME_TOPIC = 'dms-lang.translations'
|
|
14
13
|
|
|
15
|
-
/** Data older than this is
|
|
14
|
+
/** Data older than this is read again when the tab comes back into view. */
|
|
16
15
|
const STALE_AFTER_MS = 5000
|
|
17
|
-
/** Realtime messages arriving together trigger a single
|
|
16
|
+
/** Realtime messages arriving together trigger a single read. */
|
|
18
17
|
const REALTIME_DEBOUNCE_MS = 300
|
|
19
|
-
|
|
20
|
-
const UNTRACKED_GRACE_MS = 1000
|
|
18
|
+
const FLAT_KEY_PREFIX = 'dms-lang-flat:'
|
|
21
19
|
|
|
22
20
|
/** What the backend says about a write: the workspace, the tab that made it, the keys it changed. */
|
|
23
21
|
interface ChangedPayload {
|
|
@@ -26,219 +24,194 @@ interface ChangedPayload {
|
|
|
26
24
|
keys?: string[]
|
|
27
25
|
}
|
|
28
26
|
|
|
29
|
-
/** The
|
|
30
|
-
type
|
|
27
|
+
/** The keys a realtime change named, or `null` to read the workspace whole. */
|
|
28
|
+
type ChangedKeys = Set<string> | null
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
entries: Ref<Record<string, FlatTranslations>>
|
|
34
|
-
pending: Ref<Record<string, boolean>>
|
|
35
|
-
failed: Ref<Record<string, boolean>>
|
|
36
|
-
touchedAt: Ref<Record<string, number>>
|
|
37
|
-
}
|
|
30
|
+
type AuthFetch = ReturnType<typeof useAuthFetch>['$authFetch']
|
|
38
31
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
fetchRow: (workspace: string, key: string) => Promise<KeyRowResponse>
|
|
32
|
+
/** What reading a workspace's translations needs. */
|
|
33
|
+
interface FlatReadContext {
|
|
34
|
+
workspace: string
|
|
35
|
+
current: FlatTranslations | null
|
|
36
|
+
authFetch: AuthFetch
|
|
37
|
+
signal: AbortSignal
|
|
46
38
|
}
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
pending: useDmsState<Record<string, boolean>>(
|
|
55
|
-
'dms-lang-flat-pending',
|
|
56
|
-
() => ({}),
|
|
57
|
-
),
|
|
58
|
-
failed: useDmsState<Record<string, boolean>>(
|
|
59
|
-
'dms-lang-flat-failed',
|
|
60
|
-
() => ({}),
|
|
61
|
-
),
|
|
62
|
-
touchedAt: useDmsState<Record<string, number>>(
|
|
63
|
-
'dms-lang-flat-touched',
|
|
64
|
-
() => ({}),
|
|
65
|
-
),
|
|
66
|
-
}
|
|
40
|
+
type FlatRead = DmsAsyncDataResult<FlatTranslations>
|
|
41
|
+
|
|
42
|
+
/** How a caller reads the translations of a workspace. */
|
|
43
|
+
interface FlatReadOptions {
|
|
44
|
+
/** `false` reads nothing until `execute()` or another caller reads the workspace. */
|
|
45
|
+
immediate?: boolean
|
|
67
46
|
}
|
|
68
47
|
|
|
69
|
-
|
|
70
|
-
const
|
|
48
|
+
/** The keys the realtime changes named since the last read, by workspace; read once. */
|
|
49
|
+
const changedKeys = new Map<string, ChangedKeys>()
|
|
50
|
+
/** Bumped once a burst of realtime changes is heard: the readers read again. */
|
|
51
|
+
const heardChanges = ref(0)
|
|
52
|
+
/** Bumped when the tab comes back into view after a while: the readers read again. */
|
|
53
|
+
const tabReturns = ref(0)
|
|
54
|
+
/** When each workspace was last read, for the read on the tab's return. */
|
|
55
|
+
const readAt = new Map<string, number>()
|
|
71
56
|
let realtimeTimer: ReturnType<typeof setTimeout> | undefined
|
|
72
57
|
let syncScope: EffectScope | undefined
|
|
73
58
|
let syncUsers = 0
|
|
74
|
-
let stoppedAt: number | undefined
|
|
75
59
|
|
|
76
|
-
|
|
77
|
-
flags: Ref<Record<string, boolean>>,
|
|
78
|
-
workspace: string,
|
|
79
|
-
value: boolean,
|
|
80
|
-
) {
|
|
81
|
-
flags.value = { ...flags.value, [workspace]: value }
|
|
82
|
-
}
|
|
60
|
+
const flatKey = (workspace: string) => `${FLAT_KEY_PREFIX}${workspace}`
|
|
83
61
|
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
)
|
|
89
|
-
store.entries.value = { ...store.entries.value, [workspace]: flat }
|
|
90
|
-
store.touchedAt.value = { ...store.touchedAt.value, [workspace]: Date.now() }
|
|
62
|
+
function fetchFlat(context: FlatReadContext): Promise<FlatTranslations> {
|
|
63
|
+
return context.authFetch<FlatTranslations>(ENDPOINTS.flat, {
|
|
64
|
+
query: { workspace: context.workspace },
|
|
65
|
+
signal: context.signal,
|
|
66
|
+
})
|
|
91
67
|
}
|
|
92
68
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
69
|
+
/** The rows the changes named, read one by one into the translations held. */
|
|
70
|
+
async function readRows(
|
|
71
|
+
context: FlatReadContext,
|
|
72
|
+
current: FlatTranslations,
|
|
73
|
+
keys: Set<string>,
|
|
74
|
+
): Promise<FlatTranslations> {
|
|
75
|
+
let flat = current
|
|
76
|
+
for (const key of keys) {
|
|
77
|
+
const response = await context.authFetch<KeyRowResponse>(ENDPOINTS.row, {
|
|
78
|
+
query: { workspace: context.workspace, key },
|
|
79
|
+
signal: context.signal,
|
|
80
|
+
})
|
|
81
|
+
flat = { ...withRow(flat, key, response.row), ...response.counts }
|
|
104
82
|
}
|
|
83
|
+
return flat
|
|
105
84
|
}
|
|
106
85
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
function applyRow(
|
|
117
|
-
loader: FlatLoader,
|
|
118
|
-
workspace: string,
|
|
119
|
-
key: string,
|
|
120
|
-
response: KeyRowResponse,
|
|
121
|
-
before?: string,
|
|
122
|
-
): void {
|
|
123
|
-
const current = loader.store.entries.value[workspace]
|
|
124
|
-
if (!current) return
|
|
125
|
-
const flat = withRow(current, key, response.row, before)
|
|
126
|
-
setEntry(loader.store, workspace, { ...flat, ...response.counts })
|
|
127
|
-
loader.patchCounts(workspace, response.counts)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async function readRows(
|
|
131
|
-
loader: FlatLoader,
|
|
132
|
-
workspace: string,
|
|
133
|
-
keys: Set<string>,
|
|
134
|
-
): Promise<void> {
|
|
86
|
+
/**
|
|
87
|
+
* Reads the translations of a workspace: just the rows a realtime change
|
|
88
|
+
* named when the workspace is held, else (or once a row fails) all of them.
|
|
89
|
+
*/
|
|
90
|
+
async function readFlat(context: FlatReadContext): Promise<FlatTranslations> {
|
|
91
|
+
const keys = changedKeys.get(context.workspace)
|
|
92
|
+
changedKeys.delete(context.workspace)
|
|
93
|
+
readAt.set(context.workspace, Date.now())
|
|
94
|
+
if (!keys || !context.current) return fetchFlat(context)
|
|
135
95
|
try {
|
|
136
|
-
|
|
137
|
-
applyRow(loader, workspace, key, await loader.fetchRow(workspace, key))
|
|
96
|
+
return await readRows(context, context.current, keys)
|
|
138
97
|
} catch {
|
|
139
|
-
|
|
98
|
+
return fetchFlat(context)
|
|
140
99
|
}
|
|
141
100
|
}
|
|
142
101
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
102
|
+
/**
|
|
103
|
+
* The translations of one workspace, shared by every caller of the
|
|
104
|
+
* workspace: one request however many sections read it. They follow the
|
|
105
|
+
* module's realtime changes on their own (`useLangChanges`), row by row,
|
|
106
|
+
* rather than the page's refreshes.
|
|
107
|
+
*/
|
|
108
|
+
function useFlatRead(
|
|
109
|
+
workspace: MaybeRefOrGetter<string>,
|
|
110
|
+
options: FlatReadOptions = {},
|
|
111
|
+
): FlatRead {
|
|
112
|
+
const key = () => {
|
|
113
|
+
const id = toValue(workspace)
|
|
114
|
+
return id ? flatKey(id) : null
|
|
150
115
|
}
|
|
116
|
+
// The first run starts within the call, before its result is returned.
|
|
117
|
+
let held: FlatRead | undefined
|
|
118
|
+
const read = useApiData<FlatTranslations>(
|
|
119
|
+
key,
|
|
120
|
+
({ $authFetch, signal }): Promise<FlatTranslations> =>
|
|
121
|
+
readFlat({
|
|
122
|
+
workspace: toValue(workspace),
|
|
123
|
+
current: held && !held.placeholder.value ? held.data.value : null,
|
|
124
|
+
authFetch: $authFetch,
|
|
125
|
+
signal,
|
|
126
|
+
}),
|
|
127
|
+
{ immediate: options.immediate, refreshOnPageRefresh: false },
|
|
128
|
+
)
|
|
129
|
+
held = read
|
|
130
|
+
return read
|
|
151
131
|
}
|
|
152
132
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const known =
|
|
133
|
+
|
|
134
|
+
function recordChange(workspace: string, payload: ChangedPayload): void {
|
|
135
|
+
const known = changedKeys.get(workspace)
|
|
156
136
|
const isWhole = !payload.keys?.length || known === null
|
|
157
|
-
|
|
137
|
+
changedKeys.set(
|
|
158
138
|
workspace,
|
|
159
139
|
isWhole ? null : new Set([...(known ?? []), ...(payload.keys ?? [])]),
|
|
160
140
|
)
|
|
161
141
|
clearTimeout(realtimeTimer)
|
|
162
|
-
realtimeTimer = setTimeout(() =>
|
|
142
|
+
realtimeTimer = setTimeout(() => {
|
|
143
|
+
heardChanges.value += 1
|
|
144
|
+
}, REALTIME_DEBOUNCE_MS)
|
|
163
145
|
}
|
|
164
146
|
|
|
165
147
|
/**
|
|
166
|
-
* A change another tab or user made
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
148
|
+
* A change another tab or user made to the workspace on screen: its
|
|
149
|
+
* translations follow, just the rows it names when it names keys. The tab
|
|
150
|
+
* that made the change already has its answer: its echo is skipped. The
|
|
151
|
+
* workspace list and the figures follow with the page, which the same
|
|
152
|
+
* topic refreshes.
|
|
170
153
|
*/
|
|
171
154
|
function onRealtimeChange(
|
|
172
|
-
|
|
155
|
+
selectedWorkspace: string,
|
|
173
156
|
payload: ChangedPayload | undefined,
|
|
174
157
|
ownSession: string | undefined,
|
|
175
158
|
): void {
|
|
176
159
|
if (payload?.session && payload.session === ownSession) return
|
|
177
|
-
|
|
160
|
+
const workspace = payload?.workspace || selectedWorkspace
|
|
161
|
+
if (workspace === selectedWorkspace) recordChange(workspace, payload ?? {})
|
|
178
162
|
}
|
|
179
163
|
|
|
180
|
-
|
|
181
|
-
function revalidate(loader: FlatLoader): void {
|
|
182
|
-
const workspace = loader.selectedWorkspace.value
|
|
183
|
-
const touchedAt = loader.store.touchedAt.value[workspace]
|
|
184
|
-
if (touchedAt !== undefined && Date.now() - touchedAt < STALE_AFTER_MS)
|
|
185
|
-
return
|
|
186
|
-
void loader.fetchWorkspaces()
|
|
187
|
-
if (loader.store.entries.value[workspace]) void fetchOnce(loader, workspace)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/** Forgets the translations kept while no page of the module was listening to its changes. */
|
|
191
|
-
function forgetUntracked(store: FlatStore): void {
|
|
192
|
-
if (stoppedAt === undefined || Date.now() - stoppedAt < UNTRACKED_GRACE_MS)
|
|
193
|
-
return
|
|
194
|
-
store.entries.value = {}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function startSync(loader: FlatLoader): EffectScope {
|
|
198
|
-
forgetUntracked(loader.store)
|
|
164
|
+
function startSync(selectedWorkspace: Ref<string>): EffectScope {
|
|
199
165
|
const scope = effectScope(true)
|
|
200
166
|
const { sessionId } = useUserRealtime()
|
|
201
167
|
scope.run(() => {
|
|
202
168
|
useRealtimeTopic(LANG_REALTIME_TOPIC, (event) => {
|
|
203
169
|
if ('type' in event)
|
|
204
170
|
onRealtimeChange(
|
|
205
|
-
|
|
171
|
+
selectedWorkspace.value,
|
|
206
172
|
event.payload as ChangedPayload | undefined,
|
|
207
173
|
sessionId.value,
|
|
208
174
|
)
|
|
209
175
|
})
|
|
176
|
+
watch(selectedWorkspace, () => changedKeys.clear())
|
|
210
177
|
useEventListener(document, 'visibilitychange', () => {
|
|
211
|
-
if (document.visibilityState
|
|
178
|
+
if (document.visibilityState !== 'visible') return
|
|
179
|
+
if (isStale(selectedWorkspace.value)) tabReturns.value += 1
|
|
212
180
|
})
|
|
213
181
|
})
|
|
214
182
|
return scope
|
|
215
183
|
}
|
|
216
184
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
selectedWorkspace: workspaces.selectedWorkspace,
|
|
222
|
-
fetchWorkspaces: workspaces.fetchWorkspaces,
|
|
223
|
-
patchCounts: workspaces.patchCounts,
|
|
224
|
-
fetchFlat: workspaces.fetchFlat,
|
|
225
|
-
fetchRow: workspaces.fetchRow,
|
|
226
|
-
}
|
|
185
|
+
/** Whether the workspace was read long enough ago to read it again on the tab's return. */
|
|
186
|
+
function isStale(workspace: string): boolean {
|
|
187
|
+
const at = readAt.get(workspace)
|
|
188
|
+
return at === undefined || Date.now() - at >= STALE_AFTER_MS
|
|
227
189
|
}
|
|
228
190
|
|
|
229
191
|
/**
|
|
230
192
|
* The flat translations of the selected workspace, shared by every component
|
|
231
|
-
* of the page
|
|
232
|
-
*
|
|
233
|
-
* them
|
|
234
|
-
* `useWorkspaceFlatSync`.
|
|
193
|
+
* of the page, and the row a write answers put in place so every section
|
|
194
|
+
* follows. Reading them has no side effect: the matrix and the queue load
|
|
195
|
+
* them with `useWorkspaceFlatSync`.
|
|
235
196
|
*/
|
|
236
197
|
export const useWorkspaceFlat = () => {
|
|
237
|
-
const
|
|
238
|
-
const {
|
|
198
|
+
const workspaces = useI18nWorkspaces()
|
|
199
|
+
const { selectedWorkspace } = workspaces
|
|
200
|
+
const selected = useFlatRead(selectedWorkspace, { immediate: false })
|
|
201
|
+
const modules = useFlatRead(MODULES_WORKSPACE, { immediate: false })
|
|
202
|
+
|
|
203
|
+
function readOf(workspace: string): FlatRead | undefined {
|
|
204
|
+
if (workspace === selectedWorkspace.value) return selected
|
|
205
|
+
return workspace === MODULES_WORKSPACE ? modules : undefined
|
|
206
|
+
}
|
|
239
207
|
|
|
240
208
|
function flatOf(workspace: string): FlatTranslations {
|
|
241
|
-
return
|
|
209
|
+
return readOf(workspace)?.data.value ?? EMPTY_FLAT
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function setFlat(workspace: string, flat: FlatTranslations): void {
|
|
213
|
+
const read = readOf(workspace)
|
|
214
|
+
if (read?.data.value) read.data.value = flat
|
|
242
215
|
}
|
|
243
216
|
|
|
244
217
|
/** Puts a row in place without new figures: a text read from a refusal, a key gone elsewhere. */
|
|
@@ -247,87 +220,88 @@ export const useWorkspaceFlat = () => {
|
|
|
247
220
|
key: string,
|
|
248
221
|
row: FlatTranslationRow | undefined,
|
|
249
222
|
) {
|
|
250
|
-
|
|
251
|
-
|
|
223
|
+
setFlat(workspace, withRow(flatOf(workspace), key, row))
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Puts what a key write answered in place of `key`: its row (a new one
|
|
228
|
+
* before the `before` sibling) and the figures it changed.
|
|
229
|
+
*/
|
|
230
|
+
function applyRow(
|
|
231
|
+
workspace: string,
|
|
232
|
+
key: string,
|
|
233
|
+
response: KeyRowResponse,
|
|
234
|
+
before?: string,
|
|
235
|
+
) {
|
|
236
|
+
const flat = withRow(flatOf(workspace), key, response.row, before)
|
|
237
|
+
setFlat(workspace, { ...flat, ...response.counts })
|
|
238
|
+
workspaces.patchCounts(workspace, response.counts)
|
|
252
239
|
}
|
|
253
240
|
|
|
254
241
|
return {
|
|
255
|
-
flat: computed(() =>
|
|
242
|
+
flat: computed(() => selected.data.value ?? EMPTY_FLAT),
|
|
256
243
|
flatOf,
|
|
257
|
-
isLoading: computed(
|
|
258
|
-
|
|
259
|
-
),
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
() => store.failed.value[selectedWorkspace.value] === true,
|
|
265
|
-
),
|
|
266
|
-
/** The translations of a workspace, read once and then kept in step. */
|
|
267
|
-
load: async (workspace: string) => {
|
|
268
|
-
if (!store.entries.value[workspace]) await fetchOnce(loader, workspace)
|
|
269
|
-
return flatOf(workspace)
|
|
244
|
+
isLoading: computed(() => selected.pending.value),
|
|
245
|
+
isLoaded: computed(() => selected.data.value !== null),
|
|
246
|
+
hasError: computed(() => selected.error.value != null),
|
|
247
|
+
/** The translations of the installed modules' workspace, read once and then kept. */
|
|
248
|
+
loadModules: async () => {
|
|
249
|
+
if (modules.data.value === null) await modules.execute()
|
|
250
|
+
return modules.data.value ?? EMPTY_FLAT
|
|
270
251
|
},
|
|
271
252
|
/** Reads the translations of the selected workspace and the workspace list again. */
|
|
272
253
|
reload: async () => {
|
|
273
|
-
|
|
274
|
-
await Promise.all([fetchOnce(loader, workspace), loader.fetchWorkspaces()])
|
|
275
|
-
},
|
|
276
|
-
/** After a write of this tab: the workspace list, and the translations when the page holds them. */
|
|
277
|
-
refresh: async () => {
|
|
278
|
-
const workspace = selectedWorkspace.value
|
|
279
|
-
const flat = store.entries.value[workspace]
|
|
280
|
-
? fetchOnce(loader, workspace)
|
|
281
|
-
: undefined
|
|
282
|
-
await Promise.all([flat, loader.fetchWorkspaces()])
|
|
254
|
+
await Promise.all([selected.refresh(), workspaces.fetchWorkspaces()])
|
|
283
255
|
},
|
|
284
256
|
/**
|
|
285
|
-
*
|
|
286
|
-
*
|
|
257
|
+
* After a write of this tab whose answer the next step reads (the
|
|
258
|
+
* language just added, the new base): the workspace list, and the
|
|
259
|
+
* translations when the page holds them, which the page's refresh leaves.
|
|
287
260
|
*/
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
) => applyRow(loader, workspace, key, response, before),
|
|
261
|
+
refresh: async () => {
|
|
262
|
+
const flat = selected.data.value === null ? undefined : selected.refresh()
|
|
263
|
+
await Promise.all([flat, workspaces.fetchWorkspaces()])
|
|
264
|
+
},
|
|
265
|
+
applyRow,
|
|
294
266
|
replaceRow,
|
|
295
267
|
}
|
|
296
268
|
}
|
|
297
269
|
|
|
298
270
|
/**
|
|
299
|
-
* Keeps the
|
|
300
|
-
* users, once per page however many of its blocks mount it: the
|
|
301
|
-
*
|
|
302
|
-
*
|
|
271
|
+
* Keeps the translations of the page in step with the other tabs and
|
|
272
|
+
* users, once per page however many of its blocks mount it: they follow the
|
|
273
|
+
* module's realtime changes and are read again when the tab comes back into
|
|
274
|
+
* view after a while.
|
|
303
275
|
*/
|
|
304
276
|
export function useLangChanges(): void {
|
|
305
277
|
if (import.meta.env.SSR) return
|
|
306
|
-
const
|
|
307
|
-
|
|
278
|
+
const { selectedWorkspace, fetchWorkspaces } = useI18nWorkspaces()
|
|
279
|
+
const selected = useFlatRead(selectedWorkspace, { immediate: false })
|
|
280
|
+
const readAgain = () => {
|
|
281
|
+
if (selected.data.value !== null) void selected.refresh({ dedupe: 'defer' })
|
|
282
|
+
}
|
|
283
|
+
watch(heardChanges, readAgain)
|
|
284
|
+
watch(tabReturns, () => {
|
|
285
|
+
void fetchWorkspaces()
|
|
286
|
+
readAgain()
|
|
287
|
+
})
|
|
288
|
+
if (syncUsers === 0) syncScope = startSync(selectedWorkspace)
|
|
308
289
|
syncUsers += 1
|
|
309
290
|
onBeforeUnmount(() => {
|
|
310
291
|
syncUsers -= 1
|
|
311
292
|
if (syncUsers > 0) return
|
|
312
293
|
syncScope?.stop()
|
|
313
294
|
syncScope = undefined
|
|
314
|
-
stoppedAt = Date.now()
|
|
315
295
|
})
|
|
316
296
|
}
|
|
317
297
|
|
|
318
298
|
/**
|
|
319
|
-
*
|
|
320
|
-
* them (the matrix, the queue)
|
|
299
|
+
* Reads the translations of the selected workspace, for the pages that list
|
|
300
|
+
* them (the matrix, the queue): a server render reads them and hands them to
|
|
301
|
+
* the browser. They follow the selected workspace.
|
|
321
302
|
*/
|
|
322
303
|
export function useWorkspaceFlatSync(): void {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
const load = () => {
|
|
326
|
-
const workspace = loader.selectedWorkspace.value
|
|
327
|
-
if (workspace && !loader.store.entries.value[workspace])
|
|
328
|
-
void fetchOnce(loader, workspace)
|
|
329
|
-
}
|
|
304
|
+
const { selectedWorkspace } = useI18nWorkspaces()
|
|
305
|
+
useFlatRead(selectedWorkspace)
|
|
330
306
|
useLangChanges()
|
|
331
|
-
onMounted(load)
|
|
332
|
-
watch(loader.selectedWorkspace, load)
|
|
333
307
|
}
|
|
@@ -21,14 +21,8 @@ const LOCALE_QUERY = 'locale'
|
|
|
21
21
|
export const useWorkspaceRoute = () => {
|
|
22
22
|
const route = useDmsRoute()
|
|
23
23
|
const router = useDmsRouter()
|
|
24
|
-
const {
|
|
25
|
-
|
|
26
|
-
workspaces,
|
|
27
|
-
isLoaded,
|
|
28
|
-
isLoading,
|
|
29
|
-
fetchWorkspaces,
|
|
30
|
-
rememberWorkspace,
|
|
31
|
-
} = useI18nWorkspaces()
|
|
24
|
+
const { selectedWorkspace, workspaces, rememberWorkspace } =
|
|
25
|
+
useI18nWorkspaces()
|
|
32
26
|
|
|
33
27
|
const queryWorkspace = computed(() => route.query.workspace || '')
|
|
34
28
|
const pageAction = computed(() => route.query[PAGE_ACTION_QUERY] || '')
|
|
@@ -55,10 +49,6 @@ export const useWorkspaceRoute = () => {
|
|
|
55
49
|
}
|
|
56
50
|
})
|
|
57
51
|
|
|
58
|
-
onMounted(() => {
|
|
59
|
-
if (!isLoaded.value && !isLoading.value) fetchWorkspaces()
|
|
60
|
-
})
|
|
61
|
-
|
|
62
52
|
/** The language the queue opens on in a workspace: the current one when it is there, else its first translation. */
|
|
63
53
|
function queueLocaleOf(workspace: string, locale: string): string {
|
|
64
54
|
const target = workspaces.value.find((entry) => entry.id === workspace)
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"packageManager": "pnpm@10.6.5",
|
|
9
9
|
"engines": {
|
|
10
|
-
"@antelopejs/dms-frontend": ">=0.
|
|
10
|
+
"@antelopejs/dms-frontend": ">=0.6.0 <0.7.0"
|
|
11
11
|
},
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "ajs dms build",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@antelopejs/core": "1.14.0",
|
|
22
|
-
"@antelopejs/dms-frontend": "0.
|
|
22
|
+
"@antelopejs/dms-frontend": "0.6.0",
|
|
23
23
|
"@eslint/js": "^9",
|
|
24
24
|
"@typescript-eslint/eslint-plugin": "^8",
|
|
25
25
|
"@typescript-eslint/parser": "^8",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/dms-lang",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,8 +35,9 @@
|
|
|
35
35
|
"lint": "oxlint && oxfmt --check . && pnpm --dir frontend-vue lint && antelopejs-check-interface-ranges",
|
|
36
36
|
"typecheck": "tsc --noEmit",
|
|
37
37
|
"format": "oxfmt . && pnpm --dir frontend-vue format",
|
|
38
|
-
"test": "pnpm run build && ajs module test .",
|
|
39
|
-
"test:unit": "pnpm build && mocha dist/test/locale-discovery.test.js && node --test tests/*.test.mjs",
|
|
38
|
+
"test": "[ -n \"$DMS_PREBUILT\" ] || pnpm run build && ajs module test .",
|
|
39
|
+
"test:unit": "[ -n \"$DMS_PREBUILT\" ] || pnpm run build && mocha dist/test/locale-discovery.test.js && node --test tests/*.test.mjs",
|
|
40
|
+
"test:node": "[ -n \"$DMS_PREBUILT\" ] || pnpm run build && node --test tests/*.test.mjs",
|
|
40
41
|
"test:frontend": "ajs dms verify-source --layer node_modules/@antelopejs/dms/frontend-vue --module frontend-vue",
|
|
41
42
|
"release": "pnpm run lint && release-it",
|
|
42
43
|
"prepack": "pnpm run build",
|
|
@@ -47,14 +48,14 @@
|
|
|
47
48
|
"@antelopejs/interface-api": ">=0.0.14 <1.0.0",
|
|
48
49
|
"@antelopejs/interface-api-util": ">=0.1.2 <1.0.0",
|
|
49
50
|
"@antelopejs/interface-core": ">=0.1.1 <1.0.0",
|
|
50
|
-
"@antelopejs/interface-dms": ">=0.
|
|
51
|
+
"@antelopejs/interface-dms": ">=0.7.0 <1.0.0",
|
|
51
52
|
"@intlify/message-compiler": "^11.1.12",
|
|
52
53
|
"zod": "~3.24.2"
|
|
53
54
|
},
|
|
54
55
|
"devDependencies": {
|
|
55
56
|
"@antelopejs/core": "1.14.0",
|
|
56
|
-
"@antelopejs/dms": ">=0.
|
|
57
|
-
"@antelopejs/dms-frontend": "0.
|
|
57
|
+
"@antelopejs/dms": ">=0.9.0 <1.0.0",
|
|
58
|
+
"@antelopejs/dms-frontend": "0.6.0",
|
|
58
59
|
"@antelopejs/tooling-configs": ">=0.0.7 <1.0.0",
|
|
59
60
|
"@types/chai": "^5.2.3",
|
|
60
61
|
"@types/mocha": "^10.0.10",
|