@antelopejs/dms-lang 0.0.7 → 0.1.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/README.md +12 -6
- package/dist/pages/actions.d.ts +7 -0
- package/dist/pages/actions.js +15 -0
- package/dist/pages/actions.js.map +1 -0
- package/dist/pages/component-action.d.ts +2 -0
- package/dist/pages/component-action.js +10 -0
- package/dist/pages/component-action.js.map +1 -0
- package/dist/pages/header-actions.d.ts +9 -0
- package/dist/pages/header-actions.js +146 -0
- package/dist/pages/header-actions.js.map +1 -0
- package/dist/pages/index.d.ts +6 -0
- package/dist/pages/index.js +6 -0
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/language.d.ts +10 -0
- package/dist/pages/language.js +89 -0
- package/dist/pages/language.js.map +1 -0
- package/dist/pages/languages-table.d.ts +2 -0
- package/dist/pages/languages-table.js +120 -0
- package/dist/pages/languages-table.js.map +1 -0
- package/dist/pages/module.d.ts +7 -1
- package/dist/pages/module.js +28 -2
- package/dist/pages/module.js.map +1 -1
- package/dist/pages/overview.d.ts +2 -1
- package/dist/pages/overview.js +83 -8
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/page-actions.d.ts +6 -0
- package/dist/pages/page-actions.js +10 -0
- package/dist/pages/page-actions.js.map +1 -0
- package/dist/pages/quick-actions.d.ts +1 -0
- package/dist/pages/quick-actions.js +56 -0
- package/dist/pages/quick-actions.js.map +1 -0
- package/dist/pages/translations.d.ts +7 -1
- package/dist/pages/translations.js +47 -10
- package/dist/pages/translations.js.map +1 -1
- package/dist/pages/workspace-guard.d.ts +1 -0
- package/dist/pages/workspace-guard.js +35 -0
- package/dist/pages/workspace-guard.js.map +1 -0
- package/dist/pages/workspace.d.ts +18 -0
- package/dist/pages/workspace.js +162 -0
- package/dist/pages/workspace.js.map +1 -0
- package/dist/pages/workspaces.d.ts +14 -0
- package/dist/pages/workspaces.js +88 -0
- package/dist/pages/workspaces.js.map +1 -0
- package/dist/routes/publicLocales.d.ts +3 -2
- package/dist/routes/publicLocales.js +39 -18
- package/dist/routes/publicLocales.js.map +1 -1
- package/dist/routes/translations.d.ts +59 -63
- package/dist/routes/translations.js +400 -119
- package/dist/routes/translations.js.map +1 -1
- package/dist/utils/announce.d.ts +9 -0
- package/dist/utils/announce.js +29 -0
- package/dist/utils/announce.js.map +1 -0
- package/dist/utils/blocks.d.ts +8 -0
- package/dist/utils/blocks.js +213 -0
- package/dist/utils/blocks.js.map +1 -0
- package/dist/utils/body.d.ts +1 -0
- package/dist/utils/body.js +21 -0
- package/dist/utils/body.js.map +1 -0
- package/dist/utils/cache.d.ts +3 -0
- package/dist/utils/cache.js +32 -0
- package/dist/utils/cache.js.map +1 -0
- package/dist/utils/catalog.d.ts +7 -0
- package/dist/utils/catalog.js +62 -0
- package/dist/utils/catalog.js.map +1 -0
- package/dist/utils/constants.d.ts +6 -0
- package/dist/utils/constants.js +10 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/coverage.d.ts +2 -0
- package/dist/utils/coverage.js +11 -0
- package/dist/utils/coverage.js.map +1 -0
- package/dist/utils/dialogs.d.ts +7 -0
- package/dist/utils/dialogs.js +103 -0
- package/dist/utils/dialogs.js.map +1 -0
- package/dist/utils/errors.d.ts +40 -0
- package/dist/utils/errors.js +60 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/export.d.ts +17 -0
- package/dist/utils/export.js +129 -0
- package/dist/utils/export.js.map +1 -0
- package/dist/utils/json.d.ts +10 -1
- package/dist/utils/json.js +127 -19
- package/dist/utils/json.js.map +1 -1
- package/dist/utils/key-stores.d.ts +3 -0
- package/dist/utils/key-stores.js +24 -0
- package/dist/utils/key-stores.js.map +1 -0
- package/dist/utils/keys.d.ts +23 -0
- package/dist/utils/keys.js +252 -0
- package/dist/utils/keys.js.map +1 -0
- package/dist/utils/languages.d.ts +27 -0
- package/dist/utils/languages.js +121 -0
- package/dist/utils/languages.js.map +1 -0
- package/dist/utils/locale-codes.d.ts +5 -0
- package/dist/utils/locale-codes.js +56 -0
- package/dist/utils/locale-codes.js.map +1 -0
- package/dist/utils/locale-discovery.d.ts +1 -0
- package/dist/utils/locale-discovery.js +19 -1
- package/dist/utils/locale-discovery.js.map +1 -1
- package/dist/utils/message-check.d.ts +1 -0
- package/dist/utils/message-check.js +93 -0
- package/dist/utils/message-check.js.map +1 -0
- package/dist/utils/message-syntax.d.ts +6 -0
- package/dist/utils/message-syntax.js +38 -0
- package/dist/utils/message-syntax.js.map +1 -0
- package/dist/utils/namespaces.d.ts +12 -0
- package/dist/utils/namespaces.js +52 -0
- package/dist/utils/namespaces.js.map +1 -0
- package/dist/utils/notices.d.ts +4 -0
- package/dist/utils/notices.js +60 -0
- package/dist/utils/notices.js.map +1 -0
- package/dist/utils/own.d.ts +2 -3
- package/dist/utils/own.js +17 -57
- package/dist/utils/own.js.map +1 -1
- package/dist/utils/public-url.d.ts +8 -0
- package/dist/utils/public-url.js +87 -0
- package/dist/utils/public-url.js.map +1 -0
- package/dist/utils/registry.d.ts +3 -1
- package/dist/utils/registry.js +26 -10
- package/dist/utils/registry.js.map +1 -1
- package/dist/utils/resolve.d.ts +18 -15
- package/dist/utils/resolve.js +98 -151
- package/dist/utils/resolve.js.map +1 -1
- package/dist/utils/review.d.ts +5 -0
- package/dist/utils/review.js +64 -0
- package/dist/utils/review.js.map +1 -0
- package/dist/utils/snippets.d.ts +7 -0
- package/dist/utils/snippets.js +129 -0
- package/dist/utils/snippets.js.map +1 -0
- package/dist/utils/summary.d.ts +23 -0
- package/dist/utils/summary.js +65 -0
- package/dist/utils/summary.js.map +1 -0
- package/dist/utils/tree.d.ts +2 -17
- package/dist/utils/tree.js +21 -126
- package/dist/utils/tree.js.map +1 -1
- package/dist/utils/workspaces.d.ts +45 -15
- package/dist/utils/workspaces.js +256 -164
- package/dist/utils/workspaces.js.map +1 -1
- package/dist/validation/key.schema.d.ts +71 -0
- package/dist/validation/key.schema.js +67 -0
- package/dist/validation/key.schema.js.map +1 -0
- package/dist/validation/query.schema.d.ts +17 -0
- package/dist/validation/query.schema.js +44 -0
- package/dist/validation/query.schema.js.map +1 -0
- package/dist/validation/validate.d.ts +2 -0
- package/dist/validation/validate.js +24 -0
- package/dist/validation/validate.js.map +1 -0
- package/dist/validation/workspace.schema.d.ts +145 -0
- package/dist/validation/workspace.schema.js +83 -0
- package/dist/validation/workspace.schema.js.map +1 -0
- package/frontend-vue/app/build/components/KeyAddModal.vue +340 -0
- package/frontend-vue/app/build/components/KeyEditorDrawer.vue +951 -0
- package/frontend-vue/app/build/components/KeyRenameModal.vue +172 -0
- package/frontend-vue/app/build/components/LanguageAddModal.vue +199 -0
- package/frontend-vue/app/build/components/LanguagePicker.vue +233 -0
- package/frontend-vue/app/build/components/LocaleTile.vue +52 -0
- package/frontend-vue/app/build/components/PlaceholderText.vue +42 -0
- package/frontend-vue/app/build/components/ShortcutKbds.vue +22 -0
- package/frontend-vue/app/build/components/WorkspaceCreateModal.vue +193 -0
- package/frontend-vue/app/build/components/WorkspaceRenameModal.vue +107 -0
- package/frontend-vue/app/build/components/form/FormFieldRow.vue +70 -0
- package/frontend-vue/app/build/components/form/FormRows.vue +25 -0
- package/frontend-vue/app/build/components/form/WorkspaceDetailsFields.vue +44 -0
- package/frontend-vue/app/build/components/matrix/MatrixCell.vue +488 -0
- package/frontend-vue/app/build/components/matrix/MatrixColumns.vue +177 -0
- package/frontend-vue/app/build/components/matrix/MatrixGroupHeader.vue +57 -0
- package/frontend-vue/app/build/components/matrix/MatrixKeyCell.vue +83 -0
- package/frontend-vue/app/build/components/matrix/MatrixToolbar.vue +167 -0
- package/frontend-vue/app/build/components/queue/QueueActions.vue +60 -0
- package/frontend-vue/app/build/components/queue/QueueDone.vue +185 -0
- package/frontend-vue/app/build/components/queue/QueueEditor.vue +374 -0
- package/frontend-vue/app/build/components/queue/QueueHeader.vue +162 -0
- package/frontend-vue/app/build/components/queue/QueueUpNext.vue +61 -0
- package/frontend-vue/app/build/composables/useCellEditor.ts +324 -0
- package/frontend-vue/app/build/composables/useCellMoves.ts +155 -0
- package/frontend-vue/app/build/composables/useCellSaves.ts +339 -0
- package/frontend-vue/app/build/composables/useKeyPanel.ts +284 -0
- package/frontend-vue/app/build/composables/useKeySaves.ts +280 -0
- package/frontend-vue/app/build/composables/useMatrixFilters.ts +213 -0
- package/frontend-vue/app/build/composables/useMatrixRows.ts +104 -0
- package/frontend-vue/app/build/composables/useMatrixView.ts +181 -0
- package/frontend-vue/app/build/composables/useQueueContext.ts +31 -0
- package/frontend-vue/app/build/composables/useQueueEditing.ts +53 -0
- package/frontend-vue/app/build/composables/useQueueOrphans.ts +54 -0
- package/frontend-vue/app/build/composables/useQueueSave.ts +290 -0
- package/frontend-vue/app/build/composables/useQueueShortcuts.ts +106 -0
- package/frontend-vue/app/build/composables/useQueueToasts.ts +99 -0
- package/frontend-vue/app/components/LanguageNamespaces.vue +77 -0
- package/frontend-vue/app/components/NamespaceCoverage.vue +222 -0
- package/frontend-vue/app/components/TranslationMatrix.vue +809 -0
- package/frontend-vue/app/components/TranslationQueue.vue +212 -0
- package/frontend-vue/app/components/WorkspaceDangerZone.vue +81 -0
- package/frontend-vue/app/components/WorkspaceGeneral.vue +232 -0
- package/frontend-vue/app/components/WorkspaceList.vue +454 -0
- package/frontend-vue/app/components/WorkspaceScope.vue +384 -0
- package/frontend-vue/app/composables/translation/useFirstRun.ts +8 -0
- package/frontend-vue/app/composables/translation/useI18nWorkspaces.ts +221 -133
- package/frontend-vue/app/composables/translation/useKeyActions.ts +224 -0
- package/frontend-vue/app/composables/translation/useLangFormat.ts +10 -0
- package/frontend-vue/app/composables/translation/useLangLinks.ts +80 -0
- package/frontend-vue/app/composables/translation/useLanguageActions.ts +159 -0
- package/frontend-vue/app/composables/translation/useLanguageQueue.ts +232 -0
- package/frontend-vue/app/composables/translation/useLocaleNames.ts +166 -0
- package/frontend-vue/app/composables/translation/useMutationToast.ts +51 -17
- package/frontend-vue/app/composables/translation/useQueueDrafts.ts +115 -0
- package/frontend-vue/app/composables/translation/useQueueSession.ts +182 -0
- package/frontend-vue/app/composables/translation/useServedConfirm.ts +152 -0
- package/frontend-vue/app/composables/translation/useWorkspaceActions.ts +259 -0
- package/frontend-vue/app/composables/translation/useWorkspaceContext.ts +46 -15
- package/frontend-vue/app/composables/translation/useWorkspaceFlat.ts +322 -70
- package/frontend-vue/app/composables/translation/useWorkspaceNameCheck.ts +55 -0
- package/frontend-vue/app/composables/translation/useWorkspaceRoute.ts +129 -0
- package/frontend-vue/app/config/shortcuts-registry.ts +72 -0
- package/frontend-vue/app/types/lang.ts +130 -0
- package/frontend-vue/app/utils/boundedCache.ts +22 -0
- package/frontend-vue/app/utils/download.ts +16 -0
- package/frontend-vue/app/utils/keySaveErrors.ts +61 -0
- package/frontend-vue/app/utils/keySaves.ts +108 -0
- package/frontend-vue/app/utils/languages.ts +272 -0
- package/frontend-vue/app/utils/matrixExport.ts +47 -0
- package/frontend-vue/app/utils/queueDrafts.ts +115 -0
- package/frontend-vue/app/utils/queuePass.ts +145 -0
- package/frontend-vue/app/utils/queueView.ts +22 -0
- package/frontend-vue/app/utils/shortcuts.ts +75 -0
- package/frontend-vue/app/utils/translations.ts +756 -0
- package/frontend-vue/app/utils/workspaceBackup.ts +119 -0
- package/frontend-vue/app/utils/workspaces.ts +45 -0
- package/frontend-vue/dms.frontend.build.ts +5 -0
- package/frontend-vue/dms.frontend.ts +9 -20
- package/frontend-vue/i18n/locales/lang-en-GB.json +792 -69
- package/frontend-vue/i18n/locales/lang-fr-FR.json +792 -69
- package/frontend-vue/package.json +8 -6
- package/package.json +11 -8
- package/dist/utils/mutations.d.ts +0 -3
- package/dist/utils/mutations.js +0 -35
- package/dist/utils/mutations.js.map +0 -1
- package/frontend-vue/app/build/components/pages/lang/TranslationMatrix.vue +0 -284
- package/frontend-vue/app/components/LanguageAddModal.vue +0 -78
- package/frontend-vue/app/components/WorkspaceEndpoint.vue +0 -29
- package/frontend-vue/app/components/WorkspaceSelector.vue +0 -180
- package/frontend-vue/app/components/WorkspaceStatus.vue +0 -24
- package/frontend-vue/app/composables/translation/useLanguageCatalog.ts +0 -90
- package/frontend-vue/app/composables/translation/useLocaleMeta.ts +0 -18
- package/frontend-vue/app/composables/translation/useTranslationProgress.ts +0 -73
- package/frontend-vue/app/custom-pages/lang/overview.vue +0 -397
- package/frontend-vue/app/custom-pages/lang/translations.vue +0 -498
- package/frontend-vue/app/plugins/workspace-sidebar-widget.ts +0 -12
|
@@ -1,81 +1,333 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import type { EffectScope, Ref } from 'vue'
|
|
2
|
+
import { useEventListener } from '@vueuse/core'
|
|
3
|
+
import { useDmsState } from '#dms/frontend-module'
|
|
4
|
+
import type {
|
|
5
|
+
FlatCounts,
|
|
6
|
+
FlatTranslationRow,
|
|
7
|
+
FlatTranslations,
|
|
8
|
+
KeyRowResponse,
|
|
9
|
+
} from '../../types/lang'
|
|
10
|
+
import { EMPTY_FLAT, withRow } from '../../utils/translations'
|
|
11
|
+
|
|
12
|
+
/** Realtime topic the backend publishes on after each write. */
|
|
13
|
+
export const LANG_REALTIME_TOPIC = 'dms-lang.translations'
|
|
14
|
+
|
|
15
|
+
/** Data older than this is fetched again when the tab comes back into view. */
|
|
16
|
+
const STALE_AFTER_MS = 5000
|
|
17
|
+
/** Realtime messages arriving together trigger a single reload. */
|
|
18
|
+
const REALTIME_DEBOUNCE_MS = 300
|
|
19
|
+
/** Longer than a page change: no page of the module listened meanwhile, its data may have moved. */
|
|
20
|
+
const UNTRACKED_GRACE_MS = 1000
|
|
21
|
+
|
|
22
|
+
/** What the backend says about a write: the workspace, the tab that made it, the keys it changed. */
|
|
23
|
+
interface ChangedPayload {
|
|
24
|
+
workspace?: string
|
|
25
|
+
session?: string
|
|
26
|
+
keys?: string[]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The changes heard since the last reload, by workspace: the keys, or `null` to read it all again. */
|
|
30
|
+
type PendingChanges = Map<string, Set<string> | null>
|
|
31
|
+
|
|
32
|
+
interface FlatStore {
|
|
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
|
+
}
|
|
38
|
+
|
|
39
|
+
interface FlatLoader {
|
|
40
|
+
store: FlatStore
|
|
41
|
+
selectedWorkspace: Ref<string>
|
|
42
|
+
fetchWorkspaces: () => Promise<unknown>
|
|
43
|
+
patchCounts: (workspace: string, counts: FlatCounts) => void
|
|
44
|
+
fetchFlat: (workspace: string) => Promise<FlatTranslations>
|
|
45
|
+
fetchRow: (workspace: string, key: string) => Promise<KeyRowResponse>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function useFlatStore(): FlatStore {
|
|
49
|
+
return {
|
|
50
|
+
entries: useDmsState<Record<string, FlatTranslations>>(
|
|
51
|
+
'dms-lang-flat',
|
|
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
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const requests = new Map<string, Promise<void>>()
|
|
70
|
+
const changes: PendingChanges = new Map()
|
|
71
|
+
let realtimeTimer: ReturnType<typeof setTimeout> | undefined
|
|
72
|
+
let syncScope: EffectScope | undefined
|
|
73
|
+
let syncUsers = 0
|
|
74
|
+
let stoppedAt: number | undefined
|
|
75
|
+
|
|
76
|
+
function setFlag(
|
|
77
|
+
flags: Ref<Record<string, boolean>>,
|
|
78
|
+
workspace: string,
|
|
79
|
+
value: boolean,
|
|
80
|
+
) {
|
|
81
|
+
flags.value = { ...flags.value, [workspace]: value }
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function setEntry(
|
|
85
|
+
store: FlatStore,
|
|
86
|
+
workspace: string,
|
|
87
|
+
flat: FlatTranslations,
|
|
88
|
+
): void {
|
|
89
|
+
store.entries.value = { ...store.entries.value, [workspace]: flat }
|
|
90
|
+
store.touchedAt.value = { ...store.touchedAt.value, [workspace]: Date.now() }
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function request(loader: FlatLoader, workspace: string): Promise<void> {
|
|
94
|
+
const { store } = loader
|
|
95
|
+
setFlag(store.pending, workspace, true)
|
|
96
|
+
try {
|
|
97
|
+
setEntry(store, workspace, await loader.fetchFlat(workspace))
|
|
98
|
+
setFlag(store.failed, workspace, false)
|
|
99
|
+
} catch {
|
|
100
|
+
setFlag(store.failed, workspace, true)
|
|
101
|
+
} finally {
|
|
102
|
+
setFlag(store.pending, workspace, false)
|
|
103
|
+
requests.delete(workspace)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function fetchOnce(loader: FlatLoader, workspace: string): Promise<void> {
|
|
108
|
+
const running = requests.get(workspace)
|
|
109
|
+
if (running) return running
|
|
110
|
+
const next = request(loader, workspace)
|
|
111
|
+
requests.set(workspace, next)
|
|
112
|
+
return next
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Puts a row as the server now has it (none once the key is gone), with the figures it changed. */
|
|
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> {
|
|
135
|
+
try {
|
|
136
|
+
for (const key of keys)
|
|
137
|
+
applyRow(loader, workspace, key, await loader.fetchRow(workspace, key))
|
|
138
|
+
} catch {
|
|
139
|
+
await fetchOnce(loader, workspace)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function readChanges(loader: FlatLoader): void {
|
|
144
|
+
const heard = [...changes]
|
|
145
|
+
changes.clear()
|
|
146
|
+
void loader.fetchWorkspaces()
|
|
147
|
+
for (const [workspace, keys] of heard) {
|
|
148
|
+
if (!loader.store.entries.value[workspace]) continue
|
|
149
|
+
void (keys ? readRows(loader, workspace, keys) : fetchOnce(loader, workspace))
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function recordChange(loader: FlatLoader, payload: ChangedPayload): void {
|
|
154
|
+
const workspace = payload.workspace || loader.selectedWorkspace.value
|
|
155
|
+
const known = changes.get(workspace)
|
|
156
|
+
const isWhole = !payload.keys?.length || known === null
|
|
157
|
+
changes.set(
|
|
158
|
+
workspace,
|
|
159
|
+
isWhole ? null : new Set([...(known ?? []), ...(payload.keys ?? [])]),
|
|
160
|
+
)
|
|
161
|
+
clearTimeout(realtimeTimer)
|
|
162
|
+
realtimeTimer = setTimeout(() => readChanges(loader), REALTIME_DEBOUNCE_MS)
|
|
163
|
+
}
|
|
5
164
|
|
|
6
165
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* rendering empty data, and refreshes the shared workspace list on mount.
|
|
166
|
+
* A change another tab or user made: the workspace list is read again, and
|
|
167
|
+
* the translations in memory follow, just the rows it names when it names
|
|
168
|
+
* keys. The tab that made the change already has its answer: its echo is
|
|
169
|
+
* skipped.
|
|
12
170
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
171
|
+
function onRealtimeChange(
|
|
172
|
+
loader: FlatLoader,
|
|
173
|
+
payload: ChangedPayload | undefined,
|
|
174
|
+
ownSession: string | undefined,
|
|
175
|
+
): void {
|
|
176
|
+
if (payload?.session && payload.session === ownSession) return
|
|
177
|
+
recordChange(loader, payload ?? {})
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/** Reads the selected workspace again when the tab comes back after a while. */
|
|
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)
|
|
199
|
+
const scope = effectScope(true)
|
|
200
|
+
const { sessionId } = useUserRealtime()
|
|
201
|
+
scope.run(() => {
|
|
202
|
+
useRealtimeTopic(LANG_REALTIME_TOPIC, (event) => {
|
|
203
|
+
if ('type' in event)
|
|
204
|
+
onRealtimeChange(
|
|
205
|
+
loader,
|
|
206
|
+
event.payload as ChangedPayload | undefined,
|
|
207
|
+
sessionId.value,
|
|
208
|
+
)
|
|
209
|
+
})
|
|
210
|
+
useEventListener(document, 'visibilitychange', () => {
|
|
211
|
+
if (document.visibilityState === 'visible') revalidate(loader)
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
return scope
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function useFlatLoader(): FlatLoader {
|
|
218
|
+
const workspaces = useI18nWorkspaces()
|
|
219
|
+
return {
|
|
220
|
+
store: useFlatStore(),
|
|
221
|
+
selectedWorkspace: workspaces.selectedWorkspace,
|
|
222
|
+
fetchWorkspaces: workspaces.fetchWorkspaces,
|
|
223
|
+
patchCounts: workspaces.patchCounts,
|
|
224
|
+
fetchFlat: workspaces.fetchFlat,
|
|
225
|
+
fetchRow: workspaces.fetchRow,
|
|
48
226
|
}
|
|
227
|
+
}
|
|
49
228
|
|
|
50
|
-
|
|
51
|
-
|
|
229
|
+
/**
|
|
230
|
+
* The flat translations of the selected workspace, shared by every component
|
|
231
|
+
* of the page: one request per workspace however many sections read it, and
|
|
232
|
+
* the row a write answers put in place so every section follows. Reading
|
|
233
|
+
* them has no side effect: the matrix and the queue load them with
|
|
234
|
+
* `useWorkspaceFlatSync`.
|
|
235
|
+
*/
|
|
236
|
+
export const useWorkspaceFlat = () => {
|
|
237
|
+
const loader = useFlatLoader()
|
|
238
|
+
const { store, selectedWorkspace } = loader
|
|
239
|
+
|
|
240
|
+
function flatOf(workspace: string): FlatTranslations {
|
|
241
|
+
return store.entries.value[workspace] ?? EMPTY_FLAT
|
|
52
242
|
}
|
|
53
243
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
confirmColor: "error",
|
|
63
|
-
});
|
|
64
|
-
if (!confirmed) return;
|
|
65
|
-
const ok = await tryMutate(() => removeLocale(workspace, code));
|
|
66
|
-
if (!ok) return;
|
|
67
|
-
await reload();
|
|
244
|
+
/** Puts a row in place without new figures: a text read from a refusal, a key gone elsewhere. */
|
|
245
|
+
function replaceRow(
|
|
246
|
+
workspace: string,
|
|
247
|
+
key: string,
|
|
248
|
+
row: FlatTranslationRow | undefined,
|
|
249
|
+
) {
|
|
250
|
+
const current = store.entries.value[workspace]
|
|
251
|
+
if (current) setEntry(store, workspace, withRow(current, key, row))
|
|
68
252
|
}
|
|
69
253
|
|
|
70
|
-
|
|
254
|
+
return {
|
|
255
|
+
flat: computed(() => flatOf(selectedWorkspace.value)),
|
|
256
|
+
flatOf,
|
|
257
|
+
isLoading: computed(
|
|
258
|
+
() => store.pending.value[selectedWorkspace.value] === true,
|
|
259
|
+
),
|
|
260
|
+
isLoaded: computed(
|
|
261
|
+
() => store.entries.value[selectedWorkspace.value] !== undefined,
|
|
262
|
+
),
|
|
263
|
+
hasError: computed(
|
|
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)
|
|
270
|
+
},
|
|
271
|
+
/** Reads the translations of the selected workspace and the workspace list again. */
|
|
272
|
+
reload: async () => {
|
|
273
|
+
const workspace = selectedWorkspace.value
|
|
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()])
|
|
283
|
+
},
|
|
284
|
+
/**
|
|
285
|
+
* Puts what a key write answered in place of `key`: its row (a new one
|
|
286
|
+
* before the `before` sibling) and the figures it changed.
|
|
287
|
+
*/
|
|
288
|
+
applyRow: (
|
|
289
|
+
workspace: string,
|
|
290
|
+
key: string,
|
|
291
|
+
response: KeyRowResponse,
|
|
292
|
+
before?: string,
|
|
293
|
+
) => applyRow(loader, workspace, key, response, before),
|
|
294
|
+
replaceRow,
|
|
295
|
+
}
|
|
296
|
+
}
|
|
71
297
|
|
|
72
|
-
|
|
298
|
+
/**
|
|
299
|
+
* Keeps the workspace data of the page in step with the other tabs and
|
|
300
|
+
* users, once per page however many of its blocks mount it: the workspace
|
|
301
|
+
* list and the translations in memory follow the module's realtime changes
|
|
302
|
+
* and are read again when the tab comes back into view.
|
|
303
|
+
*/
|
|
304
|
+
export function useLangChanges(): void {
|
|
305
|
+
if (import.meta.env.SSR) return
|
|
306
|
+
const loader = useFlatLoader()
|
|
307
|
+
if (syncUsers === 0) syncScope = startSync(loader)
|
|
308
|
+
syncUsers += 1
|
|
309
|
+
onBeforeUnmount(() => {
|
|
310
|
+
syncUsers -= 1
|
|
311
|
+
if (syncUsers > 0) return
|
|
312
|
+
syncScope?.stop()
|
|
313
|
+
syncScope = undefined
|
|
314
|
+
stoppedAt = Date.now()
|
|
315
|
+
})
|
|
316
|
+
}
|
|
73
317
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
318
|
+
/**
|
|
319
|
+
* Loads the translations of the selected workspace, for the pages that list
|
|
320
|
+
* them (the matrix, the queue), and follows the selected workspace.
|
|
321
|
+
*/
|
|
322
|
+
export function useWorkspaceFlatSync(): void {
|
|
323
|
+
if (import.meta.env.SSR) return
|
|
324
|
+
const loader = useFlatLoader()
|
|
325
|
+
const load = () => {
|
|
326
|
+
const workspace = loader.selectedWorkspace.value
|
|
327
|
+
if (workspace && !loader.store.entries.value[workspace])
|
|
328
|
+
void fetchOnce(loader, workspace)
|
|
329
|
+
}
|
|
330
|
+
useLangChanges()
|
|
331
|
+
onMounted(load)
|
|
332
|
+
watch(loader.selectedWorkspace, load)
|
|
333
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
export type WorkspaceNameState =
|
|
4
|
+
'empty' | 'invalid' | 'taken' | 'unchanged' | 'available'
|
|
5
|
+
|
|
6
|
+
const STATE_MESSAGES: Record<WorkspaceNameState, string> = {
|
|
7
|
+
empty: 'dms_lang.workspace_name.help',
|
|
8
|
+
invalid: 'dms_lang.workspace_name.invalid',
|
|
9
|
+
taken: 'dms_lang.workspace_name.taken',
|
|
10
|
+
unchanged: 'dms_lang.workspace_name.unchanged',
|
|
11
|
+
available: 'dms_lang.workspace_name.available',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Checks a workspace name as it is typed, before anything is sent. Ids are
|
|
16
|
+
* compared without case, as the server does. `freeze()` keeps the verdict
|
|
17
|
+
* once the name is sent: the list reloaded after a creation must not turn
|
|
18
|
+
* the closing dialog red with "already exists".
|
|
19
|
+
*/
|
|
20
|
+
export const useWorkspaceNameCheck = (name: Ref<string>, currentId = '') => {
|
|
21
|
+
const { t } = useI18n()
|
|
22
|
+
const { workspaces } = useI18nWorkspaces()
|
|
23
|
+
|
|
24
|
+
const normalized = computed(() => normalizeWorkspaceId(name.value))
|
|
25
|
+
const frozenState = ref<WorkspaceNameState | null>(null)
|
|
26
|
+
|
|
27
|
+
const liveState = computed<WorkspaceNameState>(() => {
|
|
28
|
+
const id = normalized.value
|
|
29
|
+
if (!id) return 'empty'
|
|
30
|
+
if (id === normalizeWorkspaceId(currentId)) return 'unchanged'
|
|
31
|
+
if (!isValidWorkspaceId(id)) return 'invalid'
|
|
32
|
+
if (workspaces.value.some((workspace) => workspace.id.toLowerCase() === id))
|
|
33
|
+
return 'taken'
|
|
34
|
+
return 'available'
|
|
35
|
+
})
|
|
36
|
+
const state = computed(() => frozenState.value ?? liveState.value)
|
|
37
|
+
|
|
38
|
+
function freeze(): void {
|
|
39
|
+
frozenState.value = liveState.value
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function thaw(): void {
|
|
43
|
+
frozenState.value = null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const message = computed(() =>
|
|
47
|
+
t(STATE_MESSAGES[state.value], { name: normalized.value }),
|
|
48
|
+
)
|
|
49
|
+
const isValid = computed(() => state.value === 'available')
|
|
50
|
+
const isError = computed(
|
|
51
|
+
() => state.value === 'invalid' || state.value === 'taken',
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
return { normalized, state, message, isValid, isError, freeze, thaw }
|
|
55
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { useDmsRoute, useDmsRouter } from '#dms/frontend-module'
|
|
2
|
+
|
|
3
|
+
export interface SelectWorkspaceOptions {
|
|
4
|
+
/** The page to land on; the current one by default. */
|
|
5
|
+
page?: LangPage
|
|
6
|
+
/** Query the target page keeps; everything else is left behind. */
|
|
7
|
+
query?: PageQuery
|
|
8
|
+
/** Replace the history entry (an id that no longer exists). */
|
|
9
|
+
replace?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const FALLBACK_PAGE: LangPage = 'overview'
|
|
13
|
+
const LOCALE_QUERY = 'locale'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Keeps the selected workspace in the page URL (`?workspace=`): a shared link
|
|
17
|
+
* or a refresh lands on the same workspace, and the page reacts when the
|
|
18
|
+
* query changes. `selectWorkspace` is the one way to change it. Also reads the
|
|
19
|
+
* dialog a page was asked to open on arrival.
|
|
20
|
+
*/
|
|
21
|
+
export const useWorkspaceRoute = () => {
|
|
22
|
+
const route = useDmsRoute()
|
|
23
|
+
const router = useDmsRouter()
|
|
24
|
+
const {
|
|
25
|
+
selectedWorkspace,
|
|
26
|
+
workspaces,
|
|
27
|
+
isLoaded,
|
|
28
|
+
isLoading,
|
|
29
|
+
fetchWorkspaces,
|
|
30
|
+
rememberWorkspace,
|
|
31
|
+
} = useI18nWorkspaces()
|
|
32
|
+
|
|
33
|
+
const queryWorkspace = computed(() => route.query.workspace || '')
|
|
34
|
+
const pageAction = computed(() => route.query[PAGE_ACTION_QUERY] || '')
|
|
35
|
+
const currentPage = computed(() => langPageOf(route.path) ?? FALLBACK_PAGE)
|
|
36
|
+
|
|
37
|
+
watch(
|
|
38
|
+
queryWorkspace,
|
|
39
|
+
(raw) => {
|
|
40
|
+
if (!raw) return
|
|
41
|
+
const workspace = normalizeWorkspaceId(raw)
|
|
42
|
+
selectedWorkspace.value = workspace
|
|
43
|
+
if (workspace !== raw && !import.meta.env.SSR) {
|
|
44
|
+
void router.replace(
|
|
45
|
+
linkWithQuery(route.path, { ...route.query, workspace }),
|
|
46
|
+
)
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{ immediate: true },
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
watch([selectedWorkspace, workspaces], ([workspace, list]) => {
|
|
53
|
+
if (list.some((entry) => entry.id === workspace)) {
|
|
54
|
+
rememberWorkspace(workspace)
|
|
55
|
+
}
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
onMounted(() => {
|
|
59
|
+
if (!isLoaded.value && !isLoading.value) fetchWorkspaces()
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
/** The language the queue opens on in a workspace: the current one when it is there, else its first translation. */
|
|
63
|
+
function queueLocaleOf(workspace: string, locale: string): string {
|
|
64
|
+
const target = workspaces.value.find((entry) => entry.id === workspace)
|
|
65
|
+
const codes = (target?.locales ?? [])
|
|
66
|
+
.map((entry) => entry.code)
|
|
67
|
+
.filter((code) => code !== target?.defaultLocale)
|
|
68
|
+
return codes.includes(locale) ? locale : (codes[0] ?? '')
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// The language page stays the language page: it keeps its language when the
|
|
72
|
+
// target workspace has it, else opens on one the target has (or asks for one).
|
|
73
|
+
function targetOf(workspace: string, options: SelectWorkspaceOptions) {
|
|
74
|
+
const page = options.page ?? currentPage.value
|
|
75
|
+
if (page !== 'language' || options.page || options.query?.[LOCALE_QUERY]) {
|
|
76
|
+
return { page, query: options.query ?? {} }
|
|
77
|
+
}
|
|
78
|
+
const locale = queueLocaleOf(workspace, route.query[LOCALE_QUERY] ?? '')
|
|
79
|
+
return { page, query: locale ? { [LOCALE_QUERY]: locale } : {} }
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** The URL `selectWorkspace` goes to, for a link (`to:`). */
|
|
83
|
+
function switchLink(
|
|
84
|
+
workspace: string,
|
|
85
|
+
options: SelectWorkspaceOptions = {},
|
|
86
|
+
): string {
|
|
87
|
+
const id = normalizeWorkspaceId(workspace)
|
|
88
|
+
const target = targetOf(id, options)
|
|
89
|
+
return linkWithQuery(LANG_PAGES[target.page], {
|
|
90
|
+
workspace: id,
|
|
91
|
+
...target.query,
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Selects a workspace: the state at once, then the URL. Filters, the open
|
|
97
|
+
* key and a pending dialog belong to the workspace left, so they are dropped.
|
|
98
|
+
*/
|
|
99
|
+
async function selectWorkspace(
|
|
100
|
+
workspace: string,
|
|
101
|
+
options: SelectWorkspaceOptions = {},
|
|
102
|
+
): Promise<void> {
|
|
103
|
+
const link = switchLink(workspace, options)
|
|
104
|
+
selectedWorkspace.value = normalizeWorkspaceId(workspace)
|
|
105
|
+
if (import.meta.env.SSR) return
|
|
106
|
+
await (options.replace ? router.replace(link) : router.push(link))
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function clearPageAction(): Promise<void> {
|
|
110
|
+
if (!pageAction.value) return
|
|
111
|
+
const params = new URLSearchParams(route.query)
|
|
112
|
+
params.delete(PAGE_ACTION_QUERY)
|
|
113
|
+
if (!params.get('workspace') && selectedWorkspace.value) {
|
|
114
|
+
params.set('workspace', selectedWorkspace.value)
|
|
115
|
+
}
|
|
116
|
+
const search = params.toString()
|
|
117
|
+
await router.replace(search ? `${route.path}?${search}` : route.path)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
route,
|
|
122
|
+
queryWorkspace,
|
|
123
|
+
pageAction,
|
|
124
|
+
currentPage,
|
|
125
|
+
switchLink,
|
|
126
|
+
selectWorkspace,
|
|
127
|
+
clearPageAction,
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
KEY_PANEL_KEYS,
|
|
3
|
+
MATRIX_KEYS,
|
|
4
|
+
QUEUE_KEYS,
|
|
5
|
+
shortcutGroup,
|
|
6
|
+
} from '../utils/shortcuts'
|
|
7
|
+
|
|
8
|
+
export default [
|
|
9
|
+
shortcutGroup('translation_queue', [
|
|
10
|
+
{ keys: QUEUE_KEYS.saveNext, description: 'queue.save_next' },
|
|
11
|
+
{ keys: QUEUE_KEYS.save, description: 'queue.save' },
|
|
12
|
+
{
|
|
13
|
+
keys: QUEUE_KEYS.leaveField,
|
|
14
|
+
description: 'queue.leave_field',
|
|
15
|
+
condition: 'queue.in_field',
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
keys: QUEUE_KEYS.skip,
|
|
19
|
+
description: 'queue.skip',
|
|
20
|
+
condition: 'queue.outside_field',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
keys: QUEUE_KEYS.previous,
|
|
24
|
+
description: 'queue.previous',
|
|
25
|
+
condition: 'queue.outside_field',
|
|
26
|
+
},
|
|
27
|
+
]),
|
|
28
|
+
shortcutGroup('translation_matrix', [
|
|
29
|
+
{
|
|
30
|
+
keys: MATRIX_KEYS.nextMissing,
|
|
31
|
+
description: 'matrix.next_missing',
|
|
32
|
+
condition: 'matrix.outside_field',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
keys: MATRIX_KEYS.previousMissing,
|
|
36
|
+
description: 'matrix.previous_missing',
|
|
37
|
+
condition: 'matrix.outside_field',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
keys: MATRIX_KEYS.saveDown,
|
|
41
|
+
description: 'matrix.save_down',
|
|
42
|
+
condition: 'matrix.in_cell',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
keys: MATRIX_KEYS.newLine,
|
|
46
|
+
description: 'matrix.new_line',
|
|
47
|
+
condition: 'matrix.in_cell',
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
keys: MATRIX_KEYS.nextCell,
|
|
51
|
+
description: 'matrix.next_cell',
|
|
52
|
+
condition: 'matrix.in_cell',
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
keys: MATRIX_KEYS.cancel,
|
|
56
|
+
description: 'matrix.cancel',
|
|
57
|
+
condition: 'matrix.in_cell',
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
keys: MATRIX_KEYS.openPanel,
|
|
61
|
+
description: 'matrix.open_panel',
|
|
62
|
+
condition: 'matrix.in_cell',
|
|
63
|
+
},
|
|
64
|
+
]),
|
|
65
|
+
shortcutGroup('key_panel', [
|
|
66
|
+
{
|
|
67
|
+
keys: KEY_PANEL_KEYS.saveNext,
|
|
68
|
+
description: 'key_panel.save_next',
|
|
69
|
+
condition: 'key_panel.in_field',
|
|
70
|
+
},
|
|
71
|
+
]),
|
|
72
|
+
] satisfies ComponentShortcuts[]
|