@antelopejs/dms-lang 0.0.7 → 0.1.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 +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 +8 -6
- 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,339 @@
|
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
import { useDmsState } from '#dms/frontend-module'
|
|
3
|
+
import type { FlatTranslationRow } from '../../types/lang'
|
|
4
|
+
import {
|
|
5
|
+
saveIdOf,
|
|
6
|
+
saveIdPrefix,
|
|
7
|
+
savedText,
|
|
8
|
+
storedText,
|
|
9
|
+
withEntry,
|
|
10
|
+
type ExpectedText,
|
|
11
|
+
type SaveState,
|
|
12
|
+
} from '../../utils/keySaves'
|
|
13
|
+
import {
|
|
14
|
+
useEditStarts,
|
|
15
|
+
useKeySaves,
|
|
16
|
+
useSaveStates,
|
|
17
|
+
type KeyWriteFailed,
|
|
18
|
+
type KeyWriteOutcome,
|
|
19
|
+
} from './useKeySaves'
|
|
20
|
+
|
|
21
|
+
export interface CellFailure {
|
|
22
|
+
/** The text that could not be saved: kept until saved or discarded. */
|
|
23
|
+
draft: string
|
|
24
|
+
message: string
|
|
25
|
+
/** Someone changed the cell meanwhile: retrying overwrites their text. */
|
|
26
|
+
isConflict: boolean
|
|
27
|
+
/** What the next attempt expects: the value sent, or the other's text after a conflict. */
|
|
28
|
+
expected: ExpectedText
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** One cell of one workspace. */
|
|
32
|
+
export interface CellAddress {
|
|
33
|
+
workspace: string
|
|
34
|
+
key: string
|
|
35
|
+
code: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A text of a cell that could not be saved, handed over to its cell. */
|
|
39
|
+
export interface CellHold extends CellAddress, CellFailure {}
|
|
40
|
+
|
|
41
|
+
interface KeptText extends CellAddress {
|
|
42
|
+
draft: string
|
|
43
|
+
message: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface CellStore {
|
|
47
|
+
states: Ref<Record<string, SaveState>>
|
|
48
|
+
pending: Ref<Record<string, string>>
|
|
49
|
+
failures: Ref<Record<string, CellFailure>>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface CellContext {
|
|
53
|
+
store: CellStore
|
|
54
|
+
saves: ReturnType<typeof useKeySaves>
|
|
55
|
+
states: ReturnType<typeof useSaveStates>
|
|
56
|
+
report: ReturnType<typeof useCellReports>
|
|
57
|
+
onTouched: (address: CellAddress) => void
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function idOfCell(address: CellAddress): string {
|
|
61
|
+
return saveIdOf(address.workspace, address.key, address.code)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function useCellStore(): CellStore {
|
|
65
|
+
return {
|
|
66
|
+
states: useDmsState<Record<string, SaveState>>(
|
|
67
|
+
'dms-lang-matrix-cell-states',
|
|
68
|
+
() => ({}),
|
|
69
|
+
),
|
|
70
|
+
pending: useDmsState<Record<string, string>>(
|
|
71
|
+
'dms-lang-matrix-cell-pending',
|
|
72
|
+
() => ({}),
|
|
73
|
+
),
|
|
74
|
+
failures: useDmsState<Record<string, CellFailure>>(
|
|
75
|
+
'dms-lang-matrix-cell-failures',
|
|
76
|
+
() => ({}),
|
|
77
|
+
),
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function setPending(store: CellStore, id: string, value: string | undefined) {
|
|
82
|
+
store.pending.value = withEntry(store.pending.value, id, value)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function setFailure(
|
|
86
|
+
store: CellStore,
|
|
87
|
+
id: string,
|
|
88
|
+
failure: CellFailure | undefined,
|
|
89
|
+
) {
|
|
90
|
+
store.failures.value = withEntry(store.failures.value, id, failure)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function failureExpected(
|
|
94
|
+
address: CellAddress,
|
|
95
|
+
outcome: KeyWriteFailed,
|
|
96
|
+
): ExpectedText {
|
|
97
|
+
const { current, kind } = outcome.failure
|
|
98
|
+
const isOverwritable = kind === 'conflict' && address.code in current
|
|
99
|
+
return isOverwritable
|
|
100
|
+
? savedText(current[address.code])
|
|
101
|
+
: outcome.expected[address.code]
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function recordFailure(
|
|
105
|
+
context: CellContext,
|
|
106
|
+
address: CellAddress,
|
|
107
|
+
draft: string,
|
|
108
|
+
outcome: KeyWriteFailed,
|
|
109
|
+
) {
|
|
110
|
+
const id = idOfCell(address)
|
|
111
|
+
const isConflict = outcome.failure.kind === 'conflict'
|
|
112
|
+
setPending(context.store, id, undefined)
|
|
113
|
+
setFailure(context.store, id, {
|
|
114
|
+
draft,
|
|
115
|
+
message: outcome.message,
|
|
116
|
+
isConflict,
|
|
117
|
+
expected: failureExpected(address, outcome),
|
|
118
|
+
})
|
|
119
|
+
context.states.setState(id, 'error')
|
|
120
|
+
if (outcome.failure.kind === 'deleted') context.saves.dropRow(address)
|
|
121
|
+
if (isConflict) context.report.conflict(address, outcome.message)
|
|
122
|
+
else context.report.failure(address, outcome.error)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function settle(
|
|
126
|
+
context: CellContext,
|
|
127
|
+
address: CellAddress,
|
|
128
|
+
draft: string,
|
|
129
|
+
outcome: KeyWriteOutcome,
|
|
130
|
+
) {
|
|
131
|
+
const id = idOfCell(address)
|
|
132
|
+
if (context.store.pending.value[id] !== draft) return
|
|
133
|
+
if (outcome.status === 'failed')
|
|
134
|
+
return recordFailure(context, address, draft, outcome)
|
|
135
|
+
setPending(context.store, id, undefined)
|
|
136
|
+
context.states.flashSaved(id)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
async function queueSave(
|
|
140
|
+
context: CellContext,
|
|
141
|
+
address: CellAddress,
|
|
142
|
+
draft: string,
|
|
143
|
+
expected: ExpectedText,
|
|
144
|
+
) {
|
|
145
|
+
const id = idOfCell(address)
|
|
146
|
+
context.onTouched(address)
|
|
147
|
+
setFailure(context.store, id, undefined)
|
|
148
|
+
setPending(context.store, id, draft)
|
|
149
|
+
context.states.setState(id, 'saving')
|
|
150
|
+
const outcome = await context.saves.write({
|
|
151
|
+
workspace: address.workspace,
|
|
152
|
+
key: address.key,
|
|
153
|
+
values: { [address.code]: draft },
|
|
154
|
+
expected: { [address.code]: expected },
|
|
155
|
+
})
|
|
156
|
+
settle(context, address, draft, outcome)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function useCellReports(
|
|
160
|
+
retry: (address: CellAddress) => void,
|
|
161
|
+
discard: (address: CellAddress) => void,
|
|
162
|
+
) {
|
|
163
|
+
const { t } = useI18n()
|
|
164
|
+
const toast = useToast()
|
|
165
|
+
const { reportFailure } = useMutationToast()
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
conflict(address: CellAddress, message: string) {
|
|
169
|
+
toast.add({
|
|
170
|
+
title: t('dms_lang.matrix.conflict', { ...address }),
|
|
171
|
+
description: message,
|
|
172
|
+
color: 'error',
|
|
173
|
+
icon: 'i-ph-warning-circle',
|
|
174
|
+
actions: [
|
|
175
|
+
{
|
|
176
|
+
label: t('dms_lang.matrix.discard'),
|
|
177
|
+
color: 'neutral',
|
|
178
|
+
variant: 'outline',
|
|
179
|
+
onClick: () => discard(address),
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
label: t('dms_lang.matrix.overwrite'),
|
|
183
|
+
onClick: () => retry(address),
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
})
|
|
187
|
+
},
|
|
188
|
+
failure(address: CellAddress, error: unknown, canRetry = true) {
|
|
189
|
+
reportFailure(error, {
|
|
190
|
+
title: t('dms_lang.matrix.save_failed', { ...address }),
|
|
191
|
+
retry: canRetry ? () => retry(address) : undefined,
|
|
192
|
+
})
|
|
193
|
+
},
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function useCellView(
|
|
198
|
+
store: CellStore,
|
|
199
|
+
states: ReturnType<typeof useSaveStates>,
|
|
200
|
+
) {
|
|
201
|
+
return {
|
|
202
|
+
hasUnsaved: computed(
|
|
203
|
+
() =>
|
|
204
|
+
Object.keys(store.failures.value).length > 0 ||
|
|
205
|
+
Object.keys(store.pending.value).length > 0,
|
|
206
|
+
),
|
|
207
|
+
/** The text a cell shows: the one being saved, else the stored one. */
|
|
208
|
+
shownValue: (address: CellAddress, stored: string): string =>
|
|
209
|
+
store.pending.value[idOfCell(address)] ?? stored,
|
|
210
|
+
stateOf: (address: CellAddress) => states.stateOf(idOfCell(address)),
|
|
211
|
+
failureOf: (address: CellAddress): CellFailure | undefined =>
|
|
212
|
+
store.failures.value[idOfCell(address)],
|
|
213
|
+
isPending(address: CellAddress): boolean {
|
|
214
|
+
const id = idOfCell(address)
|
|
215
|
+
return id in store.pending.value || id in store.failures.value
|
|
216
|
+
},
|
|
217
|
+
/** A text of the row that could not be saved: the row is not done. */
|
|
218
|
+
hasRowFailure: (workspace: string, key: string): boolean =>
|
|
219
|
+
Object.keys(store.failures.value).some((id) =>
|
|
220
|
+
id.startsWith(saveIdPrefix(workspace, key)),
|
|
221
|
+
),
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function useCellStarts(
|
|
226
|
+
store: CellStore,
|
|
227
|
+
rowOf: (address: CellAddress) => FlatTranslationRow | undefined,
|
|
228
|
+
) {
|
|
229
|
+
const starts = useEditStarts()
|
|
230
|
+
|
|
231
|
+
function expectedNow(address: CellAddress): ExpectedText {
|
|
232
|
+
const id = idOfCell(address)
|
|
233
|
+
const failure = store.failures.value[id]
|
|
234
|
+
if (failure) return failure.expected
|
|
235
|
+
const typed = store.pending.value[id]
|
|
236
|
+
if (typed !== undefined) return storedText(typed)
|
|
237
|
+
const row = rowOf(address)
|
|
238
|
+
return row ? savedText(row.values[address.code]) : undefined
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function take(address: CellAddress): ExpectedText {
|
|
242
|
+
const id = idOfCell(address)
|
|
243
|
+
const expected = starts.has(id) ? starts.of(id) : expectedNow(address)
|
|
244
|
+
starts.end(id)
|
|
245
|
+
return expected
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return { starts, expectedNow, take }
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function changedElsewhere(
|
|
252
|
+
store: CellStore,
|
|
253
|
+
starts: ReturnType<typeof useEditStarts>,
|
|
254
|
+
address: CellAddress,
|
|
255
|
+
row: FlatTranslationRow | undefined,
|
|
256
|
+
): string | undefined {
|
|
257
|
+
const id = idOfCell(address)
|
|
258
|
+
if (!starts.has(id) || id in store.pending.value || !row) return undefined
|
|
259
|
+
const current = savedText(row.values[address.code])
|
|
260
|
+
return current === starts.of(id) ? undefined : (current ?? '')
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
function keepCell(
|
|
264
|
+
context: CellContext,
|
|
265
|
+
starts: ReturnType<typeof useEditStarts>,
|
|
266
|
+
kept: KeptText,
|
|
267
|
+
) {
|
|
268
|
+
const id = idOfCell(kept)
|
|
269
|
+
const expected = starts.has(id) ? starts.of(id) : undefined
|
|
270
|
+
starts.end(id)
|
|
271
|
+
const { draft, message } = kept
|
|
272
|
+
setFailure(context.store, id, { draft, message, isConflict: false, expected })
|
|
273
|
+
context.states.setState(id, 'error')
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function holdCell(context: CellContext, hold: CellHold) {
|
|
277
|
+
const { workspace, key, code, ...failure } = hold
|
|
278
|
+
const id = idOfCell({ workspace, key, code })
|
|
279
|
+
setFailure(context.store, id, failure)
|
|
280
|
+
context.states.setState(id, 'error')
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function retryCell(context: CellContext, address: CellAddress) {
|
|
284
|
+
const failure = context.store.failures.value[idOfCell(address)]
|
|
285
|
+
if (failure) void queueSave(context, address, failure.draft, failure.expected)
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function discardCell(context: CellContext, address: CellAddress) {
|
|
289
|
+
const id = idOfCell(address)
|
|
290
|
+
setFailure(context.store, id, undefined)
|
|
291
|
+
context.states.setState(id, 'idle')
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async function markCellReviewed(context: CellContext, address: CellAddress) {
|
|
295
|
+
const outcome = await context.saves.markReviewed(address, address.code)
|
|
296
|
+
if (outcome.status === 'failed')
|
|
297
|
+
context.report.failure(address, outcome.error, false)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Saves matrix cells one by one, as soon as they are left: the typed text
|
|
302
|
+
* shows at once with a "Saving" state, and a text that could not be saved
|
|
303
|
+
* stays on screen until it is saved or discarded, also after the page was
|
|
304
|
+
* left for another workspace and came back (the state outlives the page).
|
|
305
|
+
*/
|
|
306
|
+
export function useCellSaves(
|
|
307
|
+
rowOf: (address: CellAddress) => FlatTranslationRow | undefined,
|
|
308
|
+
onTouched: (address: CellAddress) => void,
|
|
309
|
+
) {
|
|
310
|
+
const store = useCellStore()
|
|
311
|
+
const states = useSaveStates(store.states)
|
|
312
|
+
const { starts, expectedNow, take } = useCellStarts(store, rowOf)
|
|
313
|
+
const saves = useKeySaves()
|
|
314
|
+
const report = useCellReports(
|
|
315
|
+
(address) => retryCell(context, address),
|
|
316
|
+
(address) => discardCell(context, address),
|
|
317
|
+
)
|
|
318
|
+
const context: CellContext = { store, saves, states, report, onTouched }
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
...useCellView(store, states),
|
|
322
|
+
begin: (address: CellAddress) =>
|
|
323
|
+
starts.begin(idOfCell(address), expectedNow(address)),
|
|
324
|
+
end: (address: CellAddress) => starts.end(idOfCell(address)),
|
|
325
|
+
originOf: (address: CellAddress) => starts.of(idOfCell(address)),
|
|
326
|
+
changedElsewhere: (address: CellAddress) =>
|
|
327
|
+
changedElsewhere(store, starts, address, rowOf(address)),
|
|
328
|
+
save: (address: CellAddress, draft: string) =>
|
|
329
|
+
queueSave(context, address, draft, take(address)),
|
|
330
|
+
keep: (address: CellAddress, draft: string, message: string) =>
|
|
331
|
+
keepCell(context, starts, { ...address, draft, message }),
|
|
332
|
+
hold: (holds: CellHold[]) =>
|
|
333
|
+
holds.forEach((hold) => holdCell(context, hold)),
|
|
334
|
+
retry: (address: CellAddress) => retryCell(context, address),
|
|
335
|
+
discard: (address: CellAddress) => discardCell(context, address),
|
|
336
|
+
markReviewed: (address: CellAddress) => markCellReviewed(context, address),
|
|
337
|
+
confirmClearBase: saves.confirmClearBase,
|
|
338
|
+
}
|
|
339
|
+
}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
import type { Ref } from 'vue'
|
|
2
|
+
import { useDmsRouter, useDmsState } from '#dms/frontend-module'
|
|
3
|
+
import type { FlatTranslationRow } from '../../types/lang'
|
|
4
|
+
import KeyEditorDrawer from '../components/KeyEditorDrawer.vue'
|
|
5
|
+
import type { CellHold } from './useCellSaves'
|
|
6
|
+
|
|
7
|
+
export interface PanelRequest {
|
|
8
|
+
key: string
|
|
9
|
+
/** The language to put the cursor in. */
|
|
10
|
+
focusLocale?: string
|
|
11
|
+
/** Text typed in a cell and not saved yet: the panel takes it over. */
|
|
12
|
+
initialDrafts?: Record<string, string>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface PanelOptions {
|
|
16
|
+
/** The keys the panel steps through with previous / next. */
|
|
17
|
+
keys: () => string[]
|
|
18
|
+
editable: () => boolean
|
|
19
|
+
manageKeys: () => boolean
|
|
20
|
+
/** Whether the panel offers to override a read-only module key. */
|
|
21
|
+
canOverride: () => boolean
|
|
22
|
+
/** A read-only module key the panel offers to override. */
|
|
23
|
+
onOverride: (key: string) => void
|
|
24
|
+
/** Texts the panel could not save as it closed: they wait in their cells. */
|
|
25
|
+
onKeep: (holds: CellHold[]) => void
|
|
26
|
+
/** Whether the workspace holds the key, in any of its languages. */
|
|
27
|
+
isKnown?: (key: string) => boolean
|
|
28
|
+
/** A link names a key the workspace does not hold: the panel stays closed. */
|
|
29
|
+
onUnknown?: (key: string) => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
type DrawerOverlay = ReturnType<ReturnType<typeof useOverlay>['create']>
|
|
33
|
+
|
|
34
|
+
interface PendingSwitch {
|
|
35
|
+
key: string
|
|
36
|
+
settle: (isShown: boolean) => void
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
interface PanelState {
|
|
40
|
+
shownWorkspace: string
|
|
41
|
+
drawer: DrawerOverlay | null
|
|
42
|
+
pushedFrom: string | null
|
|
43
|
+
pendingSwitch: PendingSwitch | null
|
|
44
|
+
isDisposed: boolean
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface PanelContext {
|
|
48
|
+
options: PanelOptions
|
|
49
|
+
overlay: ReturnType<typeof useOverlay>
|
|
50
|
+
router: ReturnType<typeof useDmsRouter>
|
|
51
|
+
route: ReturnType<typeof useWorkspaceRoute>['route']
|
|
52
|
+
seeds: Ref<Record<string, FlatTranslationRow>>
|
|
53
|
+
workspace: Ref<string>
|
|
54
|
+
shownKey: Ref<string>
|
|
55
|
+
state: PanelState
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const KEY_QUERY = 'key'
|
|
59
|
+
|
|
60
|
+
function linkWithKey(context: PanelContext, key: string | undefined): string {
|
|
61
|
+
const { route } = context
|
|
62
|
+
return linkWithQuery(route.path, { ...route.query, [KEY_QUERY]: key })
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function seed(
|
|
66
|
+
context: PanelContext,
|
|
67
|
+
key: string,
|
|
68
|
+
texts: FlatTranslationRow['values'],
|
|
69
|
+
) {
|
|
70
|
+
context.seeds.value = {
|
|
71
|
+
...context.seeds.value,
|
|
72
|
+
[key]: { key, values: { ...texts }, inherited: { ...texts } },
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function dropSeed(context: PanelContext, key: string) {
|
|
77
|
+
const { [key]: dropped, ...rest } = context.seeds.value
|
|
78
|
+
if (dropped) context.seeds.value = rest
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function propsFor(context: PanelContext, request: PanelRequest) {
|
|
82
|
+
const { options } = context
|
|
83
|
+
const keys = options.keys()
|
|
84
|
+
const index = keys.indexOf(request.key)
|
|
85
|
+
return {
|
|
86
|
+
keys: index < 0 ? [request.key] : keys,
|
|
87
|
+
startIndex: Math.max(index, 0),
|
|
88
|
+
workspace: context.workspace.value,
|
|
89
|
+
editable: options.editable(),
|
|
90
|
+
manageKeys: options.manageKeys(),
|
|
91
|
+
canOverride: options.canOverride(),
|
|
92
|
+
seed: context.seeds.value[request.key],
|
|
93
|
+
focusLocale: request.focusLocale,
|
|
94
|
+
initialDrafts: request.initialDrafts,
|
|
95
|
+
onNavigate: (key: string) => onNavigate(context, key),
|
|
96
|
+
onOverride: options.onOverride,
|
|
97
|
+
onKeep: options.onKeep,
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function settleSwitch(context: PanelContext, shown: string | null) {
|
|
102
|
+
const pending = context.state.pendingSwitch
|
|
103
|
+
context.state.pendingSwitch = null
|
|
104
|
+
pending?.settle(pending.key === shown)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function switchKey(
|
|
108
|
+
context: PanelContext,
|
|
109
|
+
drawer: DrawerOverlay,
|
|
110
|
+
request: PanelRequest,
|
|
111
|
+
): Promise<boolean> {
|
|
112
|
+
return new Promise((settle) => {
|
|
113
|
+
context.state.pendingSwitch = { key: request.key, settle }
|
|
114
|
+
drawer.patch(propsFor(context, request))
|
|
115
|
+
})
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function show(context: PanelContext, request: PanelRequest): Promise<boolean> {
|
|
119
|
+
const { state } = context
|
|
120
|
+
state.shownWorkspace = context.workspace.value
|
|
121
|
+
settleSwitch(context, null)
|
|
122
|
+
if (state.drawer && request.key === context.shownKey.value) {
|
|
123
|
+
state.drawer.patch(propsFor(context, request))
|
|
124
|
+
return Promise.resolve(true)
|
|
125
|
+
}
|
|
126
|
+
if (state.drawer) return switchKey(context, state.drawer, request)
|
|
127
|
+
context.shownKey.value = request.key
|
|
128
|
+
state.drawer = context.overlay.create(KeyEditorDrawer, {
|
|
129
|
+
destroyOnClose: true,
|
|
130
|
+
})
|
|
131
|
+
void state.drawer
|
|
132
|
+
.open(propsFor(context, request))
|
|
133
|
+
.then(() => onClosed(context))
|
|
134
|
+
return Promise.resolve(true)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function open(
|
|
138
|
+
context: PanelContext,
|
|
139
|
+
request: PanelRequest,
|
|
140
|
+
): Promise<boolean> {
|
|
141
|
+
if (context.state.drawer) return show(context, request)
|
|
142
|
+
void show(context, request)
|
|
143
|
+
if (context.route.query[KEY_QUERY] === request.key) return true
|
|
144
|
+
context.state.pushedFrom = linkWithKey(context, undefined)
|
|
145
|
+
await context.router.push(linkWithKey(context, request.key))
|
|
146
|
+
return true
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function onNavigate(context: PanelContext, key: string) {
|
|
150
|
+
context.shownKey.value = key
|
|
151
|
+
settleSwitch(context, key)
|
|
152
|
+
if (context.route.query[KEY_QUERY] !== key)
|
|
153
|
+
void context.router.replace(linkWithKey(context, key))
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function nextRoute(context: PanelContext): Promise<void> {
|
|
157
|
+
return new Promise((resolve) => {
|
|
158
|
+
const stop = watch(
|
|
159
|
+
() => context.route.fullPath,
|
|
160
|
+
() => {
|
|
161
|
+
stop()
|
|
162
|
+
resolve()
|
|
163
|
+
},
|
|
164
|
+
)
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
async function leaveKeyEntry(context: PanelContext, from: string | null) {
|
|
169
|
+
const without = linkWithKey(context, undefined)
|
|
170
|
+
if (from === null) return context.router.replace(without)
|
|
171
|
+
const isBack = nextRoute(context)
|
|
172
|
+
context.router.back()
|
|
173
|
+
await isBack
|
|
174
|
+
if (linkWithKey(context, undefined) !== without)
|
|
175
|
+
await context.router.replace(without)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function onClosed(context: PanelContext) {
|
|
179
|
+
const { state, route } = context
|
|
180
|
+
state.drawer = null
|
|
181
|
+
settleSwitch(context, null)
|
|
182
|
+
if (!state.isDisposed) dropSeed(context, context.shownKey.value)
|
|
183
|
+
context.shownKey.value = ''
|
|
184
|
+
const from = state.pushedFrom
|
|
185
|
+
state.pushedFrom = null
|
|
186
|
+
if (state.isDisposed || !route.query[KEY_QUERY]) return
|
|
187
|
+
void leaveKeyEntry(context, from)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function isOpenable(context: PanelContext, key: string): boolean {
|
|
191
|
+
const { options } = context
|
|
192
|
+
if (context.seeds.value[key] || options.isKnown?.(key) !== false) return true
|
|
193
|
+
options.onUnknown?.(key)
|
|
194
|
+
return false
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function followQuery(context: PanelContext, key: string) {
|
|
198
|
+
if (!key) return context.state.drawer?.close()
|
|
199
|
+
if (key === context.shownKey.value || !isOpenable(context, key)) return
|
|
200
|
+
void show(context, { key })
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function followWorkspace(context: PanelContext, workspace: string) {
|
|
204
|
+
const { drawer, shownWorkspace } = context.state
|
|
205
|
+
const shownKey = context.shownKey.value
|
|
206
|
+
if (!drawer || !shownKey || shownWorkspace === workspace) return
|
|
207
|
+
if (!isOpenable(context, shownKey)) return drawer.close()
|
|
208
|
+
void show(context, { key: shownKey })
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function patchRights(context: PanelContext) {
|
|
212
|
+
const { options } = context
|
|
213
|
+
context.state.drawer?.patch({
|
|
214
|
+
editable: options.editable(),
|
|
215
|
+
manageKeys: options.manageKeys(),
|
|
216
|
+
canOverride: options.canOverride(),
|
|
217
|
+
})
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function watchPanel(context: PanelContext) {
|
|
221
|
+
const { isLoaded, flat } = useWorkspaceFlat()
|
|
222
|
+
const { options, route } = context
|
|
223
|
+
watch(
|
|
224
|
+
[() => route.query[KEY_QUERY] ?? '', isLoaded],
|
|
225
|
+
([key, loaded]) => loaded && followQuery(context, key),
|
|
226
|
+
{ immediate: true },
|
|
227
|
+
)
|
|
228
|
+
watch(
|
|
229
|
+
[context.workspace, isLoaded],
|
|
230
|
+
([workspace, loaded]) => loaded && followWorkspace(context, workspace),
|
|
231
|
+
)
|
|
232
|
+
watch(
|
|
233
|
+
() =>
|
|
234
|
+
flat.value.rows.find((row) => row.key === context.shownKey.value)
|
|
235
|
+
?.inherited,
|
|
236
|
+
(inherited) => {
|
|
237
|
+
if (context.shownKey.value && inherited && Object.keys(inherited).length)
|
|
238
|
+
seed(context, context.shownKey.value, inherited)
|
|
239
|
+
},
|
|
240
|
+
)
|
|
241
|
+
watch([options.editable, options.manageKeys, options.canOverride], () =>
|
|
242
|
+
patchRights(context),
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* The key panel of the matrix: one panel at a time (opening another key
|
|
248
|
+
* moves the open panel to it), and the key it shows in the URL (`?key=`), so
|
|
249
|
+
* a link or a refresh opens it again and the browser's Back button closes it.
|
|
250
|
+
* The open panel may refuse another key (one of its fields waits for a
|
|
251
|
+
* choice): `open` tells whether it took the key, so nothing handed over is
|
|
252
|
+
* dropped before it did.
|
|
253
|
+
*/
|
|
254
|
+
export function useKeyPanel(options: PanelOptions) {
|
|
255
|
+
const context: PanelContext = {
|
|
256
|
+
options,
|
|
257
|
+
overlay: useOverlay(),
|
|
258
|
+
router: useDmsRouter(),
|
|
259
|
+
route: useWorkspaceRoute().route,
|
|
260
|
+
seeds: useDmsState<Record<string, FlatTranslationRow>>(
|
|
261
|
+
'dms-lang-override-seeds',
|
|
262
|
+
() => ({}),
|
|
263
|
+
),
|
|
264
|
+
workspace: useI18nWorkspaces().selectedWorkspace,
|
|
265
|
+
shownKey: ref(''),
|
|
266
|
+
state: {
|
|
267
|
+
shownWorkspace: '',
|
|
268
|
+
drawer: null,
|
|
269
|
+
pushedFrom: null,
|
|
270
|
+
pendingSwitch: null,
|
|
271
|
+
isDisposed: false,
|
|
272
|
+
},
|
|
273
|
+
}
|
|
274
|
+
watchPanel(context)
|
|
275
|
+
onBeforeUnmount(() => {
|
|
276
|
+
context.state.isDisposed = true
|
|
277
|
+
context.state.drawer?.close()
|
|
278
|
+
})
|
|
279
|
+
return {
|
|
280
|
+
open: (request: PanelRequest) => open(context, request),
|
|
281
|
+
seedOverride: (row: FlatTranslationRow) =>
|
|
282
|
+
seed(context, row.key, row.values),
|
|
283
|
+
}
|
|
284
|
+
}
|