@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
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { StorageSerializers, useStorage } from '@vueuse/core'
|
|
2
|
+
import { useDmsRouter } from '#dms/frontend-module'
|
|
3
|
+
import type { FlatTranslations } from '../../types/lang'
|
|
4
|
+
import {
|
|
5
|
+
EMPTY_FILTERS,
|
|
6
|
+
parseFilter,
|
|
7
|
+
type MatrixFilterState,
|
|
8
|
+
} from './useMatrixFilters'
|
|
9
|
+
|
|
10
|
+
type FilterQuery = Record<keyof MatrixFilterState, string>
|
|
11
|
+
|
|
12
|
+
const QUERY_NAMES: FilterQuery = {
|
|
13
|
+
filter: 'filter',
|
|
14
|
+
missingIn: 'missingIn',
|
|
15
|
+
namespace: 'namespace',
|
|
16
|
+
search: 'q',
|
|
17
|
+
}
|
|
18
|
+
const DEFAULT_FILTER = 'all'
|
|
19
|
+
const COLUMNS_STORAGE = 'dms-lang:matrix-columns:'
|
|
20
|
+
|
|
21
|
+
function filtersOf(
|
|
22
|
+
query: Record<string, string | undefined>,
|
|
23
|
+
): MatrixFilterState {
|
|
24
|
+
return {
|
|
25
|
+
filter: parseFilter(query[QUERY_NAMES.filter]),
|
|
26
|
+
missingIn: query[QUERY_NAMES.missingIn] ?? '',
|
|
27
|
+
namespace: query[QUERY_NAMES.namespace] ?? '',
|
|
28
|
+
search: query[QUERY_NAMES.search] ?? '',
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function queryOf(
|
|
33
|
+
filters: MatrixFilterState,
|
|
34
|
+
): Record<string, string | undefined> {
|
|
35
|
+
return {
|
|
36
|
+
[QUERY_NAMES.filter]:
|
|
37
|
+
filters.filter === DEFAULT_FILTER ? undefined : filters.filter,
|
|
38
|
+
[QUERY_NAMES.missingIn]: filters.missingIn || undefined,
|
|
39
|
+
[QUERY_NAMES.namespace]: filters.namespace || undefined,
|
|
40
|
+
[QUERY_NAMES.search]: filters.search.trim() || undefined,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function sameFilters(a: MatrixFilterState, b: MatrixFilterState): boolean {
|
|
45
|
+
return (Object.keys(QUERY_NAMES) as (keyof MatrixFilterState)[]).every(
|
|
46
|
+
(name) => a[name] === b[name],
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface StoredColumns {
|
|
51
|
+
shown: string[]
|
|
52
|
+
hidden: string[]
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function columnsOf(
|
|
56
|
+
stored: Partial<StoredColumns> | null,
|
|
57
|
+
): StoredColumns | null {
|
|
58
|
+
if (!Array.isArray(stored?.shown)) return null
|
|
59
|
+
return {
|
|
60
|
+
shown: stored.shown.map(String),
|
|
61
|
+
hidden: Array.isArray(stored.hidden) ? stored.hidden.map(String) : [],
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function defaultOrder(codes: string[], base: string): string[] {
|
|
66
|
+
return [...codes].sort((a, b) => Number(b === base) - Number(a === base))
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function restoredOrder(
|
|
70
|
+
codes: string[],
|
|
71
|
+
base: string,
|
|
72
|
+
stored: StoredColumns | null,
|
|
73
|
+
): string[] {
|
|
74
|
+
if (!stored) return defaultOrder(codes, base)
|
|
75
|
+
const known = new Set([...stored.shown, ...stored.hidden])
|
|
76
|
+
return [
|
|
77
|
+
...stored.shown.filter((code) => codes.includes(code)),
|
|
78
|
+
...codes.filter((code) => !known.has(code)),
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function sanitizedFilters(
|
|
83
|
+
filters: MatrixFilterState,
|
|
84
|
+
flat: FlatTranslations,
|
|
85
|
+
namespaces: string[],
|
|
86
|
+
): MatrixFilterState | null {
|
|
87
|
+
const { missingIn, namespace } = filters
|
|
88
|
+
const keepsLanguage =
|
|
89
|
+
!missingIn ||
|
|
90
|
+
(flat.locales.includes(missingIn) && missingIn !== flat.defaultLocale)
|
|
91
|
+
const keepsNamespace = !namespace || namespaces.includes(namespace)
|
|
92
|
+
if (keepsLanguage && keepsNamespace) return null
|
|
93
|
+
return {
|
|
94
|
+
...filters,
|
|
95
|
+
missingIn: keepsLanguage ? missingIn : '',
|
|
96
|
+
namespace: keepsNamespace ? namespace : '',
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function useFilterQuery() {
|
|
101
|
+
const { route } = useWorkspaceRoute()
|
|
102
|
+
const router = useDmsRouter()
|
|
103
|
+
const filters = ref<MatrixFilterState>(filtersOf(route.query))
|
|
104
|
+
watch(
|
|
105
|
+
() => route.query,
|
|
106
|
+
(query) => {
|
|
107
|
+
const next = filtersOf(query)
|
|
108
|
+
if (!sameFilters(next, filters.value)) filters.value = next
|
|
109
|
+
},
|
|
110
|
+
)
|
|
111
|
+
watch(
|
|
112
|
+
filters,
|
|
113
|
+
(next) => {
|
|
114
|
+
const link = linkWithQuery(route.path, {
|
|
115
|
+
...route.query,
|
|
116
|
+
...queryOf(next),
|
|
117
|
+
})
|
|
118
|
+
if (link !== linkWithQuery(route.path, route.query))
|
|
119
|
+
void router.replace(link)
|
|
120
|
+
},
|
|
121
|
+
{ deep: true },
|
|
122
|
+
)
|
|
123
|
+
return filters
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function useColumnOrder() {
|
|
127
|
+
const { selectedWorkspace } = useI18nWorkspaces()
|
|
128
|
+
const { flat } = useWorkspaceFlat()
|
|
129
|
+
const order = ref<string[]>([])
|
|
130
|
+
const stored = useStorage<Partial<StoredColumns> | null>(
|
|
131
|
+
() => `${COLUMNS_STORAGE}${selectedWorkspace.value}`,
|
|
132
|
+
null,
|
|
133
|
+
undefined,
|
|
134
|
+
{ serializer: StorageSerializers.object },
|
|
135
|
+
)
|
|
136
|
+
watch(
|
|
137
|
+
() => `${selectedWorkspace.value}|${flat.value.locales.join(',')}`,
|
|
138
|
+
() => {
|
|
139
|
+
const { locales, defaultLocale } = flat.value
|
|
140
|
+
order.value = restoredOrder(
|
|
141
|
+
locales,
|
|
142
|
+
defaultLocale,
|
|
143
|
+
columnsOf(stored.value),
|
|
144
|
+
)
|
|
145
|
+
},
|
|
146
|
+
{ immediate: true },
|
|
147
|
+
)
|
|
148
|
+
function saveOrder(next: string[]) {
|
|
149
|
+
order.value = next
|
|
150
|
+
stored.value = {
|
|
151
|
+
shown: next,
|
|
152
|
+
hidden: flat.value.locales.filter((code) => !next.includes(code)),
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return { order, saveOrder }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* The view of the matrix a user chose: the filters live in the URL (a link
|
|
160
|
+
* or a refresh shows the same keys, Back undoes a filter change made by a
|
|
161
|
+
* link) and the columns shown, in their order, are remembered per workspace
|
|
162
|
+
* in this browser.
|
|
163
|
+
*/
|
|
164
|
+
export function useMatrixView() {
|
|
165
|
+
const { flat } = useWorkspaceFlat()
|
|
166
|
+
const filters = useFilterQuery()
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
filters,
|
|
170
|
+
...useColumnOrder(),
|
|
171
|
+
/** Drops filters the workspace cannot have (a language or a namespace it lacks). */
|
|
172
|
+
sanitize(namespaces: string[]) {
|
|
173
|
+
if (!flat.value.locales.length) return
|
|
174
|
+
const next = sanitizedFilters(filters.value, flat.value, namespaces)
|
|
175
|
+
if (next) filters.value = next
|
|
176
|
+
},
|
|
177
|
+
resetFilters() {
|
|
178
|
+
filters.value = { ...EMPTY_FILTERS }
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ComputedRef, InjectionKey } from 'vue'
|
|
2
|
+
import type { QueueSession } from '../../composables/translation/useQueueSession'
|
|
3
|
+
import type { QueueEditing } from './useQueueEditing'
|
|
4
|
+
import type { QueueSave } from './useQueueSave'
|
|
5
|
+
|
|
6
|
+
/** What the parts of the translation queue share: its pass, its draft and its save. */
|
|
7
|
+
export interface QueueContext {
|
|
8
|
+
session: QueueSession
|
|
9
|
+
editing: QueueEditing
|
|
10
|
+
save: QueueSave
|
|
11
|
+
/** The name of the language shown, with its region when another language here shares it. */
|
|
12
|
+
languageName: ComputedRef<string>
|
|
13
|
+
/** A language name, with its region when another language here shares it. */
|
|
14
|
+
nameOf: (code: string) => string
|
|
15
|
+
/** Skips the key shown, saying when the queue went round. */
|
|
16
|
+
skip: () => void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const QUEUE_CONTEXT: InjectionKey<QueueContext> = Symbol('dms-lang-queue')
|
|
20
|
+
|
|
21
|
+
/** Shares the queue with the parts the queue card renders. */
|
|
22
|
+
export function provideQueue(context: QueueContext): void {
|
|
23
|
+
provide(QUEUE_CONTEXT, context)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The queue of the card a part is rendered in. */
|
|
27
|
+
export function useQueue(): QueueContext {
|
|
28
|
+
const context = inject(QUEUE_CONTEXT)
|
|
29
|
+
if (!context) throw new Error('A queue part renders inside TranslationQueue')
|
|
30
|
+
return context
|
|
31
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { QueueSession } from '../../composables/translation/useQueueSession'
|
|
2
|
+
import {
|
|
3
|
+
checkMessage,
|
|
4
|
+
hasBlockingIssue,
|
|
5
|
+
stringValue,
|
|
6
|
+
} from '../../utils/translations'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The text of the key shown in the queue: its base text, the saved text, the
|
|
10
|
+
* draft typed over it and what is wrong with that draft.
|
|
11
|
+
*/
|
|
12
|
+
export function useQueueEditing(session: QueueSession) {
|
|
13
|
+
const { current, locale, baseLocale, drafts } = session
|
|
14
|
+
const baseText = computed(() =>
|
|
15
|
+
stringValue(current.value?.values[baseLocale.value]),
|
|
16
|
+
)
|
|
17
|
+
const savedText = computed(() =>
|
|
18
|
+
stringValue(current.value?.values[locale.value]),
|
|
19
|
+
)
|
|
20
|
+
const draft = computed<string>({
|
|
21
|
+
get: () => {
|
|
22
|
+
const stored = current.value ? drafts.read(current.value.key) : undefined
|
|
23
|
+
return stored ?? savedText.value
|
|
24
|
+
},
|
|
25
|
+
set: (value) => {
|
|
26
|
+
if (!current.value) return
|
|
27
|
+
drafts.write(current.value.key, value, current.value.values[locale.value])
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
const issues = computed(() => checkMessage(baseText.value, draft.value))
|
|
31
|
+
return {
|
|
32
|
+
baseText,
|
|
33
|
+
savedText,
|
|
34
|
+
draft,
|
|
35
|
+
issues,
|
|
36
|
+
isBlocked: computed(() => hasBlockingIssue(issues.value)),
|
|
37
|
+
/**
|
|
38
|
+
* The value saved elsewhere since the draft was started (a conflict):
|
|
39
|
+
* shown with the choice to keep it or to save the draft over it.
|
|
40
|
+
*/
|
|
41
|
+
conflict: computed(() =>
|
|
42
|
+
current.value && session.isStale(current.value)
|
|
43
|
+
? savedText.value
|
|
44
|
+
: undefined,
|
|
45
|
+
),
|
|
46
|
+
/** The base text changed since this translation was written. */
|
|
47
|
+
isOutdated: computed(
|
|
48
|
+
() => !!current.value && session.isOutdated(current.value),
|
|
49
|
+
),
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export type QueueEditing = ReturnType<typeof useQueueEditing>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { FlatTranslations } from '../../types/lang'
|
|
2
|
+
import type { QueueSession } from '../../composables/translation/useQueueSession'
|
|
3
|
+
import type { DraftCheck, DraftId } from '../../utils/queueDrafts'
|
|
4
|
+
import { useQueueToasts } from './useQueueToasts'
|
|
5
|
+
|
|
6
|
+
/** What is known to exist, for telling which drafts lost their key. */
|
|
7
|
+
interface LiveTargets {
|
|
8
|
+
/** The workspaces of the module; none while the list is not in. */
|
|
9
|
+
workspaces: Set<string> | null
|
|
10
|
+
/** The translations of the workspace shown; none while they are not in. */
|
|
11
|
+
flat: FlatTranslations | null
|
|
12
|
+
selected: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function goneCheck(targets: LiveTargets): DraftCheck {
|
|
16
|
+
const keys = new Set(targets.flat?.rows.map((row) => row.key))
|
|
17
|
+
const languages = new Set(targets.flat?.locales)
|
|
18
|
+
const isKeyGone = (id: DraftId) =>
|
|
19
|
+
!!targets.flat && (!languages.has(id.locale) || !keys.has(id.key))
|
|
20
|
+
return (id) => {
|
|
21
|
+
if (targets.workspaces && !targets.workspaces.has(id.workspace)) return true
|
|
22
|
+
return id.workspace === targets.selected && isKeyGone(id)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Takes out the drafts whose key, language or workspace was deleted or
|
|
28
|
+
* renamed elsewhere, each with a toast that offers to copy it: nothing asks
|
|
29
|
+
* to discard them later, and no link leads to a workspace that is gone.
|
|
30
|
+
*/
|
|
31
|
+
export function useQueueOrphans(session: QueueSession) {
|
|
32
|
+
const { flat, isLoaded } = useWorkspaceFlat()
|
|
33
|
+
const {
|
|
34
|
+
workspaces,
|
|
35
|
+
isLoaded: hasWorkspaces,
|
|
36
|
+
selectedWorkspace,
|
|
37
|
+
} = useI18nWorkspaces()
|
|
38
|
+
const { announceDeleted } = useQueueToasts()
|
|
39
|
+
watch(
|
|
40
|
+
[flat, isLoaded, workspaces, hasWorkspaces],
|
|
41
|
+
() => {
|
|
42
|
+
const isGone = goneCheck({
|
|
43
|
+
workspaces: hasWorkspaces.value
|
|
44
|
+
? new Set(workspaces.value.map((workspace) => workspace.id))
|
|
45
|
+
: null,
|
|
46
|
+
flat: isLoaded.value ? flat.value : null,
|
|
47
|
+
selected: selectedWorkspace.value,
|
|
48
|
+
})
|
|
49
|
+
for (const orphan of session.drafts.take(isGone))
|
|
50
|
+
announceDeleted(orphan.key, orphan.value)
|
|
51
|
+
},
|
|
52
|
+
{ immediate: true },
|
|
53
|
+
)
|
|
54
|
+
}
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import type { ComputedRef, Ref } from 'vue'
|
|
2
|
+
import type { FlatTranslationRow } from '../../types/lang'
|
|
3
|
+
import type { QueueSession } from '../../composables/translation/useQueueSession'
|
|
4
|
+
import type { KeySaveFailureKind } from '../../utils/keySaveErrors'
|
|
5
|
+
import { savedText as expectedTextOf, storedText } from '../../utils/keySaves'
|
|
6
|
+
import { DRAFT_SEPARATOR } from '../../utils/queueDrafts'
|
|
7
|
+
import type { QueueEditing } from './useQueueEditing'
|
|
8
|
+
import { useKeySaves, type KeyWriteFailed } from './useKeySaves'
|
|
9
|
+
import { useQueueToasts } from './useQueueToasts'
|
|
10
|
+
|
|
11
|
+
/** A text the server refused, with its problems. */
|
|
12
|
+
interface Rejection {
|
|
13
|
+
key: string
|
|
14
|
+
value: string
|
|
15
|
+
problems: string[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A save on its way: the text typed and the text it stores. */
|
|
19
|
+
interface QueueWrite {
|
|
20
|
+
row: FlatTranslationRow
|
|
21
|
+
typed: string
|
|
22
|
+
value: string
|
|
23
|
+
shouldAdvance: boolean
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface QueueSaveState {
|
|
27
|
+
isSaving: Ref<boolean>
|
|
28
|
+
isReviewing: Ref<boolean>
|
|
29
|
+
armed: Ref<string>
|
|
30
|
+
rejection: Ref<Rejection | null>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
interface QueueSaveContext {
|
|
34
|
+
session: QueueSession
|
|
35
|
+
editing: QueueEditing
|
|
36
|
+
state: QueueSaveState
|
|
37
|
+
saves: ReturnType<typeof useKeySaves>
|
|
38
|
+
toasts: ReturnType<typeof useQueueToasts>
|
|
39
|
+
failures: ReturnType<typeof useMutationToast>
|
|
40
|
+
workspace: Ref<string>
|
|
41
|
+
canEdit: Ref<boolean>
|
|
42
|
+
languageName: ComputedRef<string>
|
|
43
|
+
t: ReturnType<typeof useI18n>['t']
|
|
44
|
+
confirm: ReturnType<typeof useConfirm>['confirm']
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type SaveFailureHandler = (
|
|
48
|
+
context: QueueSaveContext,
|
|
49
|
+
write: QueueWrite,
|
|
50
|
+
outcome: KeyWriteFailed,
|
|
51
|
+
) => void
|
|
52
|
+
|
|
53
|
+
function armId(key: string, value: string): string {
|
|
54
|
+
return [key, value].join(DRAFT_SEPARATOR)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function isArmedFor(context: QueueSaveContext, key: string): boolean {
|
|
58
|
+
return context.state.armed.value === armId(key, context.editing.draft.value)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Drops a key deleted elsewhere, its draft offered in a toast. */
|
|
62
|
+
function onDeleted(context: QueueSaveContext, row: FlatTranslationRow) {
|
|
63
|
+
const { session, saves, toasts, workspace } = context
|
|
64
|
+
const draftText = session.drafts.read(row.key)
|
|
65
|
+
session.drafts.drop(row.key)
|
|
66
|
+
saves.dropRow({ workspace: workspace.value, key: row.key })
|
|
67
|
+
toasts.announceDeleted(row.key, draftText)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function onInvalid(
|
|
71
|
+
context: QueueSaveContext,
|
|
72
|
+
write: QueueWrite,
|
|
73
|
+
outcome: KeyWriteFailed,
|
|
74
|
+
) {
|
|
75
|
+
const { details } = outcome.failure
|
|
76
|
+
context.state.rejection.value = {
|
|
77
|
+
key: write.row.key,
|
|
78
|
+
value: context.session.drafts.read(write.row.key) ?? write.typed,
|
|
79
|
+
problems: details.length ? details : [outcome.message],
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const SAVE_FAILURES: Record<KeySaveFailureKind, SaveFailureHandler> = {
|
|
84
|
+
conflict: (context, write) => context.toasts.warnConflict(write.row.key),
|
|
85
|
+
deleted: (context, write) => onDeleted(context, write.row),
|
|
86
|
+
invalid: onInvalid,
|
|
87
|
+
other: (context, write, outcome) =>
|
|
88
|
+
context.failures.reportFailure(outcome.error, {
|
|
89
|
+
title: context.t('dms_lang.matrix.save_failed', {
|
|
90
|
+
key: write.row.key,
|
|
91
|
+
code: context.session.locale.value,
|
|
92
|
+
}),
|
|
93
|
+
retry: () => void send(context, write),
|
|
94
|
+
}),
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Sends a text, expecting the one its draft started on. Once saved, a text
|
|
99
|
+
* typed during the save stays as a draft, and the queue stays on its key.
|
|
100
|
+
*/
|
|
101
|
+
async function send(context: QueueSaveContext, write: QueueWrite) {
|
|
102
|
+
const { session, state, saves, workspace } = context
|
|
103
|
+
const { row, typed, value } = write
|
|
104
|
+
const code = session.locale.value
|
|
105
|
+
const start = session.drafts.startOf(row.key)
|
|
106
|
+
state.isSaving.value = true
|
|
107
|
+
const outcome = await saves.write({
|
|
108
|
+
workspace: workspace.value,
|
|
109
|
+
key: row.key,
|
|
110
|
+
values: { [code]: value },
|
|
111
|
+
expected: {
|
|
112
|
+
[code]: start === undefined ? expectedTextOf(row.values[code]) : start,
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
state.isSaving.value = false
|
|
116
|
+
if (outcome.status === 'failed')
|
|
117
|
+
return SAVE_FAILURES[outcome.failure.kind](context, write, outcome)
|
|
118
|
+
const isTypedMeanwhile =
|
|
119
|
+
session.drafts.read(row.key) !== undefined &&
|
|
120
|
+
session.drafts.read(row.key) !== typed
|
|
121
|
+
session.drafts.settle(row.key, { typed, stored: storedText(value) })
|
|
122
|
+
const step = session.complete(
|
|
123
|
+
row.key,
|
|
124
|
+
write.shouldAdvance && !isTypedMeanwhile,
|
|
125
|
+
)
|
|
126
|
+
context.toasts.showStep(step)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function confirmClear(context: QueueSaveContext, row: FlatTranslationRow) {
|
|
130
|
+
const { t } = context
|
|
131
|
+
const name = context.languageName.value
|
|
132
|
+
return context.confirm({
|
|
133
|
+
title: t('dms_lang.queue.clear_title', { name, key: row.key }),
|
|
134
|
+
description: t('dms_lang.queue.clear_description', { name }),
|
|
135
|
+
color: 'warning',
|
|
136
|
+
icon: 'i-ph-eraser',
|
|
137
|
+
confirmLabel: t('dms_lang.queue.clear_submit'),
|
|
138
|
+
initialFocus: 'cancel',
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Why the draft cannot be saved yet, said in a toast; none when it can. */
|
|
143
|
+
function holdBack(context: QueueSaveContext, key: string): boolean {
|
|
144
|
+
const { editing, toasts, state } = context
|
|
145
|
+
if (editing.conflict.value !== undefined) {
|
|
146
|
+
toasts.warnConflict(key)
|
|
147
|
+
return true
|
|
148
|
+
}
|
|
149
|
+
if (editing.isBlocked.value) {
|
|
150
|
+
toasts.warnBlocked()
|
|
151
|
+
return true
|
|
152
|
+
}
|
|
153
|
+
if (!editing.issues.value.length || isArmedFor(context, key)) return false
|
|
154
|
+
state.armed.value = armId(key, editing.draft.value)
|
|
155
|
+
return true
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** A draft back to the saved text: nothing to send, the key is done (or skipped when empty). */
|
|
159
|
+
function settleUnchanged(
|
|
160
|
+
context: QueueSaveContext,
|
|
161
|
+
row: FlatTranslationRow,
|
|
162
|
+
value: string,
|
|
163
|
+
shouldAdvance: boolean,
|
|
164
|
+
) {
|
|
165
|
+
const { session, toasts } = context
|
|
166
|
+
session.drafts.drop(row.key)
|
|
167
|
+
if (value) return toasts.showStep(session.complete(row.key, shouldAdvance))
|
|
168
|
+
if (shouldAdvance) toasts.showStep(session.skip())
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Saves the draft of the key shown, then moves on unless `shouldAdvance` is
|
|
173
|
+
* false. A draft with issues asks for a second press; an empty one asks
|
|
174
|
+
* before clearing the text.
|
|
175
|
+
*/
|
|
176
|
+
async function save(context: QueueSaveContext, shouldAdvance: boolean) {
|
|
177
|
+
const { session, editing, state } = context
|
|
178
|
+
const row = session.current.value
|
|
179
|
+
if (!row || state.isSaving.value || !context.canEdit.value) return
|
|
180
|
+
const typed = editing.draft.value
|
|
181
|
+
const value = normalizeDraft(typed)
|
|
182
|
+
if (value === editing.savedText.value)
|
|
183
|
+
return settleUnchanged(context, row, value, shouldAdvance)
|
|
184
|
+
if (holdBack(context, row.key)) return
|
|
185
|
+
if (!value && !(await confirmClear(context, row))) return
|
|
186
|
+
await send(context, { row, typed, value, shouldAdvance })
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Acknowledges "To review" without changing the text, then moves on. */
|
|
190
|
+
async function markReviewed(context: QueueSaveContext) {
|
|
191
|
+
const { session, state, saves, workspace, t } = context
|
|
192
|
+
const row = session.current.value
|
|
193
|
+
if (!row || state.isReviewing.value) return
|
|
194
|
+
state.isReviewing.value = true
|
|
195
|
+
const code = session.locale.value
|
|
196
|
+
const outcome = await saves.markReviewed(
|
|
197
|
+
{ workspace: workspace.value, key: row.key },
|
|
198
|
+
code,
|
|
199
|
+
)
|
|
200
|
+
state.isReviewing.value = false
|
|
201
|
+
if (outcome.status === 'failed') {
|
|
202
|
+
if (outcome.failure.kind === 'deleted') return onDeleted(context, row)
|
|
203
|
+
return context.failures.reportFailure(outcome.error)
|
|
204
|
+
}
|
|
205
|
+
context.toasts.notify(t('dms_lang.drawer.reviewed', { code, key: row.key }))
|
|
206
|
+
context.toasts.showStep(session.complete(row.key))
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function saveState(): QueueSaveState {
|
|
210
|
+
return {
|
|
211
|
+
isSaving: ref(false),
|
|
212
|
+
isReviewing: ref(false),
|
|
213
|
+
armed: ref(''),
|
|
214
|
+
rejection: ref<Rejection | null>(null),
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function rejectedProblems(context: QueueSaveContext): string[] {
|
|
219
|
+
const rejected = context.state.rejection.value
|
|
220
|
+
const row = context.session.current.value
|
|
221
|
+
if (!rejected || rejected.key !== row?.key) return []
|
|
222
|
+
return rejected.value === context.editing.draft.value ? rejected.problems : []
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** What the queue's save offers its editor: the state and the actions. */
|
|
226
|
+
function saveActions(context: QueueSaveContext) {
|
|
227
|
+
const { session, state } = context
|
|
228
|
+
const current = () => session.current.value
|
|
229
|
+
return {
|
|
230
|
+
...state,
|
|
231
|
+
isArmed: computed(() => {
|
|
232
|
+
const row = current()
|
|
233
|
+
return !!row && isArmedFor(context, row.key)
|
|
234
|
+
}),
|
|
235
|
+
rejectedProblems: computed(() => rejectedProblems(context)),
|
|
236
|
+
save: () => save(context, true),
|
|
237
|
+
/** Saves the draft and stays on its key (nothing to do without a draft). */
|
|
238
|
+
saveInPlace: () => {
|
|
239
|
+
const row = current()
|
|
240
|
+
if (row && session.drafts.has(row.key)) void save(context, false)
|
|
241
|
+
},
|
|
242
|
+
/** Keeps the value saved elsewhere: the draft goes. */
|
|
243
|
+
useTheirs: () => {
|
|
244
|
+
const row = current()
|
|
245
|
+
if (row) session.drafts.drop(row.key)
|
|
246
|
+
},
|
|
247
|
+
/** Saves the draft over the value saved elsewhere meanwhile. */
|
|
248
|
+
overwrite: () => {
|
|
249
|
+
const row = current()
|
|
250
|
+
if (!row) return
|
|
251
|
+
session.drafts.rebase(row.key, row.values[session.locale.value])
|
|
252
|
+
void save(context, true)
|
|
253
|
+
},
|
|
254
|
+
markReviewed: () => markReviewed(context),
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The save protocol of the translation queue, on the module's one save
|
|
260
|
+
* engine (`useKeySaves`): a draft expects the text it started on, a refused
|
|
261
|
+
* write says why (conflict, deleted key, invalid message) and a text typed
|
|
262
|
+
* during a save is kept.
|
|
263
|
+
*/
|
|
264
|
+
export function useQueueSave(
|
|
265
|
+
session: QueueSession,
|
|
266
|
+
editing: QueueEditing,
|
|
267
|
+
languageName: ComputedRef<string>,
|
|
268
|
+
) {
|
|
269
|
+
const { selectedWorkspace } = useI18nWorkspaces()
|
|
270
|
+
const { canEditValues } = useWorkspaceContext()
|
|
271
|
+
const context: QueueSaveContext = {
|
|
272
|
+
session,
|
|
273
|
+
editing,
|
|
274
|
+
languageName,
|
|
275
|
+
state: saveState(),
|
|
276
|
+
saves: useKeySaves(),
|
|
277
|
+
toasts: useQueueToasts(),
|
|
278
|
+
failures: useMutationToast(),
|
|
279
|
+
workspace: selectedWorkspace,
|
|
280
|
+
canEdit: canEditValues,
|
|
281
|
+
t: useI18n().t,
|
|
282
|
+
confirm: useConfirm().confirm,
|
|
283
|
+
}
|
|
284
|
+
watch([selectedWorkspace, session.locale], () => {
|
|
285
|
+
context.state.armed.value = ''
|
|
286
|
+
})
|
|
287
|
+
return saveActions(context)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export type QueueSave = ReturnType<typeof useQueueSave>
|