@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.
Files changed (245) hide show
  1. package/README.md +12 -6
  2. package/dist/pages/actions.d.ts +7 -0
  3. package/dist/pages/actions.js +15 -0
  4. package/dist/pages/actions.js.map +1 -0
  5. package/dist/pages/component-action.d.ts +2 -0
  6. package/dist/pages/component-action.js +10 -0
  7. package/dist/pages/component-action.js.map +1 -0
  8. package/dist/pages/header-actions.d.ts +9 -0
  9. package/dist/pages/header-actions.js +146 -0
  10. package/dist/pages/header-actions.js.map +1 -0
  11. package/dist/pages/index.d.ts +6 -0
  12. package/dist/pages/index.js +6 -0
  13. package/dist/pages/index.js.map +1 -1
  14. package/dist/pages/language.d.ts +10 -0
  15. package/dist/pages/language.js +89 -0
  16. package/dist/pages/language.js.map +1 -0
  17. package/dist/pages/languages-table.d.ts +2 -0
  18. package/dist/pages/languages-table.js +120 -0
  19. package/dist/pages/languages-table.js.map +1 -0
  20. package/dist/pages/module.d.ts +7 -1
  21. package/dist/pages/module.js +28 -2
  22. package/dist/pages/module.js.map +1 -1
  23. package/dist/pages/overview.d.ts +2 -1
  24. package/dist/pages/overview.js +83 -8
  25. package/dist/pages/overview.js.map +1 -1
  26. package/dist/pages/page-actions.d.ts +6 -0
  27. package/dist/pages/page-actions.js +10 -0
  28. package/dist/pages/page-actions.js.map +1 -0
  29. package/dist/pages/quick-actions.d.ts +1 -0
  30. package/dist/pages/quick-actions.js +56 -0
  31. package/dist/pages/quick-actions.js.map +1 -0
  32. package/dist/pages/translations.d.ts +7 -1
  33. package/dist/pages/translations.js +47 -10
  34. package/dist/pages/translations.js.map +1 -1
  35. package/dist/pages/workspace-guard.d.ts +1 -0
  36. package/dist/pages/workspace-guard.js +35 -0
  37. package/dist/pages/workspace-guard.js.map +1 -0
  38. package/dist/pages/workspace.d.ts +18 -0
  39. package/dist/pages/workspace.js +162 -0
  40. package/dist/pages/workspace.js.map +1 -0
  41. package/dist/pages/workspaces.d.ts +14 -0
  42. package/dist/pages/workspaces.js +88 -0
  43. package/dist/pages/workspaces.js.map +1 -0
  44. package/dist/routes/publicLocales.d.ts +3 -2
  45. package/dist/routes/publicLocales.js +39 -18
  46. package/dist/routes/publicLocales.js.map +1 -1
  47. package/dist/routes/translations.d.ts +59 -63
  48. package/dist/routes/translations.js +400 -119
  49. package/dist/routes/translations.js.map +1 -1
  50. package/dist/utils/announce.d.ts +9 -0
  51. package/dist/utils/announce.js +29 -0
  52. package/dist/utils/announce.js.map +1 -0
  53. package/dist/utils/blocks.d.ts +8 -0
  54. package/dist/utils/blocks.js +213 -0
  55. package/dist/utils/blocks.js.map +1 -0
  56. package/dist/utils/body.d.ts +1 -0
  57. package/dist/utils/body.js +21 -0
  58. package/dist/utils/body.js.map +1 -0
  59. package/dist/utils/cache.d.ts +3 -0
  60. package/dist/utils/cache.js +32 -0
  61. package/dist/utils/cache.js.map +1 -0
  62. package/dist/utils/catalog.d.ts +7 -0
  63. package/dist/utils/catalog.js +62 -0
  64. package/dist/utils/catalog.js.map +1 -0
  65. package/dist/utils/constants.d.ts +6 -0
  66. package/dist/utils/constants.js +10 -0
  67. package/dist/utils/constants.js.map +1 -0
  68. package/dist/utils/coverage.d.ts +2 -0
  69. package/dist/utils/coverage.js +11 -0
  70. package/dist/utils/coverage.js.map +1 -0
  71. package/dist/utils/dialogs.d.ts +7 -0
  72. package/dist/utils/dialogs.js +103 -0
  73. package/dist/utils/dialogs.js.map +1 -0
  74. package/dist/utils/errors.d.ts +40 -0
  75. package/dist/utils/errors.js +60 -0
  76. package/dist/utils/errors.js.map +1 -0
  77. package/dist/utils/export.d.ts +17 -0
  78. package/dist/utils/export.js +129 -0
  79. package/dist/utils/export.js.map +1 -0
  80. package/dist/utils/json.d.ts +10 -1
  81. package/dist/utils/json.js +127 -19
  82. package/dist/utils/json.js.map +1 -1
  83. package/dist/utils/key-stores.d.ts +3 -0
  84. package/dist/utils/key-stores.js +24 -0
  85. package/dist/utils/key-stores.js.map +1 -0
  86. package/dist/utils/keys.d.ts +23 -0
  87. package/dist/utils/keys.js +252 -0
  88. package/dist/utils/keys.js.map +1 -0
  89. package/dist/utils/languages.d.ts +27 -0
  90. package/dist/utils/languages.js +121 -0
  91. package/dist/utils/languages.js.map +1 -0
  92. package/dist/utils/locale-codes.d.ts +5 -0
  93. package/dist/utils/locale-codes.js +56 -0
  94. package/dist/utils/locale-codes.js.map +1 -0
  95. package/dist/utils/locale-discovery.d.ts +1 -0
  96. package/dist/utils/locale-discovery.js +19 -1
  97. package/dist/utils/locale-discovery.js.map +1 -1
  98. package/dist/utils/message-check.d.ts +1 -0
  99. package/dist/utils/message-check.js +93 -0
  100. package/dist/utils/message-check.js.map +1 -0
  101. package/dist/utils/message-syntax.d.ts +6 -0
  102. package/dist/utils/message-syntax.js +38 -0
  103. package/dist/utils/message-syntax.js.map +1 -0
  104. package/dist/utils/namespaces.d.ts +12 -0
  105. package/dist/utils/namespaces.js +52 -0
  106. package/dist/utils/namespaces.js.map +1 -0
  107. package/dist/utils/notices.d.ts +4 -0
  108. package/dist/utils/notices.js +60 -0
  109. package/dist/utils/notices.js.map +1 -0
  110. package/dist/utils/own.d.ts +2 -3
  111. package/dist/utils/own.js +17 -57
  112. package/dist/utils/own.js.map +1 -1
  113. package/dist/utils/public-url.d.ts +8 -0
  114. package/dist/utils/public-url.js +87 -0
  115. package/dist/utils/public-url.js.map +1 -0
  116. package/dist/utils/registry.d.ts +3 -1
  117. package/dist/utils/registry.js +26 -10
  118. package/dist/utils/registry.js.map +1 -1
  119. package/dist/utils/resolve.d.ts +18 -15
  120. package/dist/utils/resolve.js +98 -151
  121. package/dist/utils/resolve.js.map +1 -1
  122. package/dist/utils/review.d.ts +5 -0
  123. package/dist/utils/review.js +64 -0
  124. package/dist/utils/review.js.map +1 -0
  125. package/dist/utils/snippets.d.ts +7 -0
  126. package/dist/utils/snippets.js +129 -0
  127. package/dist/utils/snippets.js.map +1 -0
  128. package/dist/utils/summary.d.ts +23 -0
  129. package/dist/utils/summary.js +65 -0
  130. package/dist/utils/summary.js.map +1 -0
  131. package/dist/utils/tree.d.ts +2 -17
  132. package/dist/utils/tree.js +21 -126
  133. package/dist/utils/tree.js.map +1 -1
  134. package/dist/utils/workspaces.d.ts +45 -15
  135. package/dist/utils/workspaces.js +256 -164
  136. package/dist/utils/workspaces.js.map +1 -1
  137. package/dist/validation/key.schema.d.ts +71 -0
  138. package/dist/validation/key.schema.js +67 -0
  139. package/dist/validation/key.schema.js.map +1 -0
  140. package/dist/validation/query.schema.d.ts +17 -0
  141. package/dist/validation/query.schema.js +44 -0
  142. package/dist/validation/query.schema.js.map +1 -0
  143. package/dist/validation/validate.d.ts +2 -0
  144. package/dist/validation/validate.js +24 -0
  145. package/dist/validation/validate.js.map +1 -0
  146. package/dist/validation/workspace.schema.d.ts +145 -0
  147. package/dist/validation/workspace.schema.js +83 -0
  148. package/dist/validation/workspace.schema.js.map +1 -0
  149. package/frontend-vue/app/build/components/KeyAddModal.vue +340 -0
  150. package/frontend-vue/app/build/components/KeyEditorDrawer.vue +951 -0
  151. package/frontend-vue/app/build/components/KeyRenameModal.vue +172 -0
  152. package/frontend-vue/app/build/components/LanguageAddModal.vue +199 -0
  153. package/frontend-vue/app/build/components/LanguagePicker.vue +233 -0
  154. package/frontend-vue/app/build/components/LocaleTile.vue +52 -0
  155. package/frontend-vue/app/build/components/PlaceholderText.vue +42 -0
  156. package/frontend-vue/app/build/components/ShortcutKbds.vue +22 -0
  157. package/frontend-vue/app/build/components/WorkspaceCreateModal.vue +193 -0
  158. package/frontend-vue/app/build/components/WorkspaceRenameModal.vue +107 -0
  159. package/frontend-vue/app/build/components/form/FormFieldRow.vue +70 -0
  160. package/frontend-vue/app/build/components/form/FormRows.vue +25 -0
  161. package/frontend-vue/app/build/components/form/WorkspaceDetailsFields.vue +44 -0
  162. package/frontend-vue/app/build/components/matrix/MatrixCell.vue +488 -0
  163. package/frontend-vue/app/build/components/matrix/MatrixColumns.vue +177 -0
  164. package/frontend-vue/app/build/components/matrix/MatrixGroupHeader.vue +57 -0
  165. package/frontend-vue/app/build/components/matrix/MatrixKeyCell.vue +83 -0
  166. package/frontend-vue/app/build/components/matrix/MatrixToolbar.vue +167 -0
  167. package/frontend-vue/app/build/components/queue/QueueActions.vue +60 -0
  168. package/frontend-vue/app/build/components/queue/QueueDone.vue +185 -0
  169. package/frontend-vue/app/build/components/queue/QueueEditor.vue +374 -0
  170. package/frontend-vue/app/build/components/queue/QueueHeader.vue +162 -0
  171. package/frontend-vue/app/build/components/queue/QueueUpNext.vue +61 -0
  172. package/frontend-vue/app/build/composables/useCellEditor.ts +324 -0
  173. package/frontend-vue/app/build/composables/useCellMoves.ts +155 -0
  174. package/frontend-vue/app/build/composables/useCellSaves.ts +339 -0
  175. package/frontend-vue/app/build/composables/useKeyPanel.ts +284 -0
  176. package/frontend-vue/app/build/composables/useKeySaves.ts +280 -0
  177. package/frontend-vue/app/build/composables/useMatrixFilters.ts +213 -0
  178. package/frontend-vue/app/build/composables/useMatrixRows.ts +104 -0
  179. package/frontend-vue/app/build/composables/useMatrixView.ts +181 -0
  180. package/frontend-vue/app/build/composables/useQueueContext.ts +31 -0
  181. package/frontend-vue/app/build/composables/useQueueEditing.ts +53 -0
  182. package/frontend-vue/app/build/composables/useQueueOrphans.ts +54 -0
  183. package/frontend-vue/app/build/composables/useQueueSave.ts +290 -0
  184. package/frontend-vue/app/build/composables/useQueueShortcuts.ts +106 -0
  185. package/frontend-vue/app/build/composables/useQueueToasts.ts +99 -0
  186. package/frontend-vue/app/components/LanguageNamespaces.vue +77 -0
  187. package/frontend-vue/app/components/NamespaceCoverage.vue +222 -0
  188. package/frontend-vue/app/components/TranslationMatrix.vue +809 -0
  189. package/frontend-vue/app/components/TranslationQueue.vue +212 -0
  190. package/frontend-vue/app/components/WorkspaceDangerZone.vue +81 -0
  191. package/frontend-vue/app/components/WorkspaceGeneral.vue +232 -0
  192. package/frontend-vue/app/components/WorkspaceList.vue +454 -0
  193. package/frontend-vue/app/components/WorkspaceScope.vue +384 -0
  194. package/frontend-vue/app/composables/translation/useFirstRun.ts +8 -0
  195. package/frontend-vue/app/composables/translation/useI18nWorkspaces.ts +221 -133
  196. package/frontend-vue/app/composables/translation/useKeyActions.ts +224 -0
  197. package/frontend-vue/app/composables/translation/useLangFormat.ts +10 -0
  198. package/frontend-vue/app/composables/translation/useLangLinks.ts +80 -0
  199. package/frontend-vue/app/composables/translation/useLanguageActions.ts +159 -0
  200. package/frontend-vue/app/composables/translation/useLanguageQueue.ts +232 -0
  201. package/frontend-vue/app/composables/translation/useLocaleNames.ts +166 -0
  202. package/frontend-vue/app/composables/translation/useMutationToast.ts +51 -17
  203. package/frontend-vue/app/composables/translation/useQueueDrafts.ts +115 -0
  204. package/frontend-vue/app/composables/translation/useQueueSession.ts +182 -0
  205. package/frontend-vue/app/composables/translation/useServedConfirm.ts +152 -0
  206. package/frontend-vue/app/composables/translation/useWorkspaceActions.ts +259 -0
  207. package/frontend-vue/app/composables/translation/useWorkspaceContext.ts +46 -15
  208. package/frontend-vue/app/composables/translation/useWorkspaceFlat.ts +322 -70
  209. package/frontend-vue/app/composables/translation/useWorkspaceNameCheck.ts +55 -0
  210. package/frontend-vue/app/composables/translation/useWorkspaceRoute.ts +129 -0
  211. package/frontend-vue/app/config/shortcuts-registry.ts +72 -0
  212. package/frontend-vue/app/types/lang.ts +130 -0
  213. package/frontend-vue/app/utils/boundedCache.ts +22 -0
  214. package/frontend-vue/app/utils/download.ts +16 -0
  215. package/frontend-vue/app/utils/keySaveErrors.ts +61 -0
  216. package/frontend-vue/app/utils/keySaves.ts +108 -0
  217. package/frontend-vue/app/utils/languages.ts +272 -0
  218. package/frontend-vue/app/utils/matrixExport.ts +47 -0
  219. package/frontend-vue/app/utils/queueDrafts.ts +115 -0
  220. package/frontend-vue/app/utils/queuePass.ts +145 -0
  221. package/frontend-vue/app/utils/queueView.ts +22 -0
  222. package/frontend-vue/app/utils/shortcuts.ts +75 -0
  223. package/frontend-vue/app/utils/translations.ts +756 -0
  224. package/frontend-vue/app/utils/workspaceBackup.ts +119 -0
  225. package/frontend-vue/app/utils/workspaces.ts +45 -0
  226. package/frontend-vue/dms.frontend.build.ts +5 -0
  227. package/frontend-vue/dms.frontend.ts +9 -20
  228. package/frontend-vue/i18n/locales/lang-en-GB.json +792 -69
  229. package/frontend-vue/i18n/locales/lang-fr-FR.json +792 -69
  230. package/frontend-vue/package.json +8 -6
  231. package/package.json +8 -6
  232. package/dist/utils/mutations.d.ts +0 -3
  233. package/dist/utils/mutations.js +0 -35
  234. package/dist/utils/mutations.js.map +0 -1
  235. package/frontend-vue/app/build/components/pages/lang/TranslationMatrix.vue +0 -284
  236. package/frontend-vue/app/components/LanguageAddModal.vue +0 -78
  237. package/frontend-vue/app/components/WorkspaceEndpoint.vue +0 -29
  238. package/frontend-vue/app/components/WorkspaceSelector.vue +0 -180
  239. package/frontend-vue/app/components/WorkspaceStatus.vue +0 -24
  240. package/frontend-vue/app/composables/translation/useLanguageCatalog.ts +0 -90
  241. package/frontend-vue/app/composables/translation/useLocaleMeta.ts +0 -18
  242. package/frontend-vue/app/composables/translation/useTranslationProgress.ts +0 -73
  243. package/frontend-vue/app/custom-pages/lang/overview.vue +0 -397
  244. package/frontend-vue/app/custom-pages/lang/translations.vue +0 -498
  245. package/frontend-vue/app/plugins/workspace-sidebar-widget.ts +0 -12
@@ -0,0 +1,488 @@
1
+ <script setup lang="ts">
2
+ import PlaceholderText from '../PlaceholderText.vue'
3
+ import ShortcutKbds from '../ShortcutKbds.vue'
4
+ import { MATRIX_KEYS } from '../../../utils/shortcuts'
5
+ import {
6
+ checkMessage,
7
+ escapeMessage,
8
+ formatTokens,
9
+ hasBlockingIssue,
10
+ messageIssueText,
11
+ PLURAL_SEPARATOR,
12
+ type MessageIssue,
13
+ } from '../../../utils/translations'
14
+ import type { SaveState } from '../../../utils/keySaves'
15
+ import type { CellFailure } from '../../composables/useCellSaves'
16
+ import type { CellMove } from '../../composables/useCellEditor'
17
+
18
+ interface Props {
19
+ value: string
20
+ baseValue: string
21
+ inherited?: string
22
+ /** In the modules workspace, the project's text that replaces the module's. */
23
+ override?: string
24
+ isBase: boolean
25
+ editable: boolean
26
+ isEditing: boolean
27
+ state: SaveState
28
+ failure?: CellFailure
29
+ rowKey: string
30
+ languageName: string
31
+ /** Translated from an older base text. */
32
+ isOutdated?: boolean
33
+ /** The server found an issue in the stored text. */
34
+ hasIssue?: boolean
35
+ code: string
36
+ /** The text the editor opens with. */
37
+ initialDraft?: string
38
+ /** The other's text when the cell changed elsewhere while being edited ('': removed). */
39
+ changedElsewhere?: string
40
+ }
41
+
42
+ interface Emits {
43
+ edit: [key: string, code: string]
44
+ commit: [key: string, code: string, move: CellMove, draft: string]
45
+ cancel: []
46
+ retry: [key: string, code: string]
47
+ discard: [key: string, code: string]
48
+ /** Write the bare `@` and lone braces of the unsaved text as literals. */
49
+ escape: [key: string, code: string]
50
+ openPanel: [key: string, code: string, draft: string]
51
+ review: [key: string, code: string]
52
+ /** The text typed so far, each time it changes. */
53
+ draft: [key: string, code: string, draft: string]
54
+ }
55
+
56
+ interface TextareaHandle {
57
+ textareaRef?: HTMLTextAreaElement
58
+ }
59
+
60
+ type KeyHandler = (event: KeyboardEvent) => (() => void) | undefined
61
+
62
+ type FailureAction = 'fix' | 'overwrite' | 'retry'
63
+
64
+ const LONG_TEXT = 150
65
+ const MULTILINE = '\n'
66
+ const SYNTAX_KINDS = new Set(['bareAt', 'unclosedBrace', 'strayBrace'])
67
+ const FAILURE_ACTION_LABELS: Record<FailureAction, string> = {
68
+ fix: 'dms_lang.matrix.fix',
69
+ overwrite: 'dms_lang.matrix.overwrite',
70
+ retry: 'dms_lang.actions.retry',
71
+ }
72
+
73
+ const props = withDefaults(defineProps<Props>(), {
74
+ inherited: undefined,
75
+ override: undefined,
76
+ failure: undefined,
77
+ isOutdated: false,
78
+ hasIssue: false,
79
+ changedElsewhere: undefined,
80
+ initialDraft: '',
81
+ })
82
+ const emit = defineEmits<Emits>()
83
+ const draft = ref(props.initialDraft)
84
+
85
+ const { t } = useI18n()
86
+ const isCommitted = ref(false)
87
+ const textarea = useTemplateRef<TextareaHandle>('textarea')
88
+
89
+ const isMissing = computed(() => props.value === '')
90
+ const shown = computed(() => (props.isEditing ? draft.value : props.value))
91
+ /** Checked here only while it is typed or not stored yet; a stored text, only when the server flagged it. */
92
+ const isChecked = computed(
93
+ () => props.isEditing || props.hasIssue || props.state !== 'idle',
94
+ )
95
+ const issues = computed<MessageIssue[]>(() =>
96
+ isChecked.value
97
+ ? checkMessage(props.isBase ? '' : props.baseValue, shown.value)
98
+ : [],
99
+ )
100
+ const missingTokens = computed(() =>
101
+ issues.value
102
+ .filter((issue) => issue.kind === 'missing')
103
+ .flatMap((issue) => issue.tokens),
104
+ )
105
+ const canEscape = computed(() => isEscapable(issues.value))
106
+ const failureIssues = computed<MessageIssue[]>(() =>
107
+ props.failure ? checkMessage('', props.failure.draft) : [],
108
+ )
109
+ const isFailureInvalid = computed(() => hasBlockingIssue(failureIssues.value))
110
+ const failureAction = computed<FailureAction>(() => {
111
+ if (isFailureInvalid.value) return 'fix'
112
+ return props.failure?.isConflict ? 'overwrite' : 'retry'
113
+ })
114
+ const hasError = computed(() =>
115
+ issues.value.some((issue) => issue.severity === 'error'),
116
+ )
117
+ const suggestsPanel = computed(
118
+ () =>
119
+ props.baseValue.length > LONG_TEXT ||
120
+ props.baseValue.includes(MULTILINE) ||
121
+ props.baseValue.includes(PLURAL_SEPARATOR),
122
+ )
123
+ const ariaLabel = computed(() =>
124
+ t(
125
+ isMissing.value
126
+ ? 'dms_lang.matrix.aria_translate'
127
+ : 'dms_lang.matrix.aria_edit',
128
+ { key: props.rowKey, language: props.languageName },
129
+ ),
130
+ )
131
+
132
+ watch(draft, (text) => emit('draft', props.rowKey, props.code, text))
133
+
134
+ watch(
135
+ () => props.isEditing,
136
+ (editing) => {
137
+ if (!editing) return
138
+ draft.value = props.initialDraft
139
+ isCommitted.value = false
140
+ nextTick(() => {
141
+ const element = textarea.value?.textareaRef
142
+ element?.focus()
143
+ element?.setSelectionRange(element.value.length, element.value.length)
144
+ })
145
+ },
146
+ { immediate: true },
147
+ )
148
+
149
+ function isEscapable(list: MessageIssue[]): boolean {
150
+ return list.some((issue) => SYNTAX_KINDS.has(issue.kind))
151
+ }
152
+
153
+ function commit(move: CellMove) {
154
+ if (isCommitted.value) return
155
+ isCommitted.value = true
156
+ emit('commit', props.rowKey, props.code, move, draft.value)
157
+ }
158
+
159
+ function onBlur() {
160
+ if (document.hasFocus()) commit('stay')
161
+ }
162
+
163
+ function cancel() {
164
+ isCommitted.value = true
165
+ emit('cancel')
166
+ }
167
+
168
+ function openPanel() {
169
+ isCommitted.value = true
170
+ emit('openPanel', props.rowKey, props.code, draft.value)
171
+ }
172
+
173
+ const KEY_HANDLERS: Record<string, KeyHandler> = {
174
+ Escape: () => cancel,
175
+ Tab: (event) => () => commit(event.shiftKey ? 'previous' : 'next'),
176
+ Enter: (event) => {
177
+ if (event.altKey) return undefined
178
+ const hasModifier = event.ctrlKey || event.metaKey
179
+ if (hasModifier && event.shiftKey) return openPanel
180
+ if (hasModifier) return () => commit('stay')
181
+ return event.shiftKey ? undefined : () => commit('down')
182
+ },
183
+ }
184
+
185
+ function onKeydown(event: KeyboardEvent) {
186
+ if (event.isComposing) return
187
+ const action = KEY_HANDLERS[event.key]?.(event)
188
+ if (!action) return
189
+ event.preventDefault()
190
+ event.stopPropagation()
191
+ action()
192
+ }
193
+
194
+ function insertToken(token: string) {
195
+ const separator = draft.value && !draft.value.endsWith(' ') ? ' ' : ''
196
+ draft.value = `${draft.value}${separator}{${token}}`
197
+ textarea.value?.textareaRef?.focus()
198
+ }
199
+
200
+ function escapeDraft() {
201
+ draft.value = escapeMessage(draft.value)
202
+ textarea.value?.textareaRef?.focus()
203
+ }
204
+ </script>
205
+
206
+ <template>
207
+ <div v-if="isEditing" class="space-y-1">
208
+ <p
209
+ v-if="!props.isBase && props.baseValue"
210
+ class="text-dimmed line-clamp-2 px-1 text-xs"
211
+ :title="props.baseValue"
212
+ >
213
+ <PlaceholderText :text="props.baseValue" />
214
+ </p>
215
+ <UTextarea
216
+ ref="textarea"
217
+ v-model="draft"
218
+ autoresize
219
+ :rows="1"
220
+ :maxrows="8"
221
+ :placeholder="props.inherited || props.baseValue"
222
+ :color="hasError ? 'error' : undefined"
223
+ :highlight="hasError"
224
+ :aria-label="ariaLabel"
225
+ class="w-full"
226
+ :ui="{ base: 'text-sm' }"
227
+ @keydown="onKeydown"
228
+ @blur="onBlur"
229
+ />
230
+ <p
231
+ v-if="props.changedElsewhere !== undefined"
232
+ class="text-warning flex items-start gap-1 px-1 text-[10.5px]"
233
+ role="status"
234
+ >
235
+ <UIcon name="i-ph-arrows-clockwise" class="mt-px size-3 shrink-0" />
236
+ <span class="min-w-0">
237
+ {{ $t('dms_lang.matrix.changed_elsewhere') }}
238
+ <PlaceholderText
239
+ v-if="props.changedElsewhere"
240
+ :text="props.changedElsewhere"
241
+ class="text-default"
242
+ />
243
+ <span v-else class="italic">
244
+ {{ $t('dms_lang.matrix.current_none') }}
245
+ </span>
246
+ </span>
247
+ </p>
248
+ <ul v-if="issues.length" class="space-y-0.5 px-1">
249
+ <li
250
+ v-for="issue in issues"
251
+ :key="issue.kind"
252
+ class="flex items-start gap-1 text-[10.5px]"
253
+ :class="issue.severity === 'error' ? 'text-error' : 'text-warning'"
254
+ >
255
+ <UIcon name="i-ph-warning" class="mt-px size-3 shrink-0" />
256
+ {{ messageIssueText(issue, t) }}
257
+ </li>
258
+ </ul>
259
+ <div
260
+ v-if="missingTokens.length || canEscape"
261
+ class="flex flex-wrap gap-1 px-1"
262
+ >
263
+ <UButton
264
+ v-for="token in missingTokens"
265
+ :key="token"
266
+ size="xs"
267
+ color="warning"
268
+ variant="soft"
269
+ :label="$t('dms_lang.drawer.insert', { token: formatTokens([token]) })"
270
+ @mousedown.prevent
271
+ @click="insertToken(token)"
272
+ />
273
+ <UButton
274
+ v-if="canEscape"
275
+ size="xs"
276
+ color="error"
277
+ variant="soft"
278
+ :label="$t('dms_lang.message_issue.escape')"
279
+ @mousedown.prevent
280
+ @click="escapeDraft"
281
+ />
282
+ </div>
283
+ <div
284
+ class="text-dimmed flex flex-wrap items-center gap-x-2 gap-y-1 px-1 text-[10.5px]"
285
+ >
286
+ <span class="inline-flex items-center gap-1">
287
+ <ShortcutKbds :keys="MATRIX_KEYS.saveDown" />
288
+ {{ $t('dms_lang.matrix.shortcut_save_down') }}
289
+ </span>
290
+ <span class="inline-flex items-center gap-1">
291
+ <ShortcutKbds :keys="MATRIX_KEYS.newLine" />
292
+ {{ $t('dms_lang.matrix.shortcut_newline') }}
293
+ </span>
294
+ <span class="inline-flex items-center gap-1">
295
+ <ShortcutKbds :keys="MATRIX_KEYS.cancel" />
296
+ {{ $t('dms_lang.matrix.shortcut_cancel') }}
297
+ </span>
298
+ <span v-if="!props.isBase && props.baseValue" class="font-mono">
299
+ {{
300
+ $t('dms_lang.matrix.length', {
301
+ count: draft.length,
302
+ base: props.baseValue.length,
303
+ })
304
+ }}
305
+ </span>
306
+ <UButton
307
+ v-if="props.isOutdated && !isMissing"
308
+ size="xs"
309
+ color="info"
310
+ variant="soft"
311
+ icon="i-ph-check"
312
+ class="ml-auto"
313
+ :label="$t('dms_lang.drawer.mark_reviewed')"
314
+ :title="$t('dms_lang.drawer.outdated')"
315
+ @mousedown.prevent
316
+ @click="emit('review', props.rowKey, props.code)"
317
+ />
318
+ <UButton
319
+ size="xs"
320
+ :color="suggestsPanel ? 'primary' : 'neutral'"
321
+ :variant="suggestsPanel ? 'soft' : 'ghost'"
322
+ icon="i-ph-arrows-out-simple"
323
+ :class="props.isOutdated && !isMissing ? undefined : 'ml-auto'"
324
+ :label="
325
+ suggestsPanel
326
+ ? $t('dms_lang.matrix.panel_suggested')
327
+ : $t('dms_lang.matrix.open_panel')
328
+ "
329
+ :title="$t('dms_lang.matrix.open_panel')"
330
+ @mousedown.prevent
331
+ @click="openPanel"
332
+ />
333
+ </div>
334
+ </div>
335
+
336
+ <div v-else-if="props.failure" class="space-y-1">
337
+ <button
338
+ type="button"
339
+ data-matrix-cell
340
+ :data-key="props.rowKey"
341
+ :data-code="props.code"
342
+ class="border-error/40 bg-error/5 text-default line-clamp-3 w-full rounded-md border px-2.5 py-1.5 text-left text-sm"
343
+ :aria-label="ariaLabel"
344
+ :disabled="!props.editable"
345
+ @click="emit('edit', props.rowKey, props.code)"
346
+ >
347
+ <PlaceholderText v-if="props.failure.draft" :text="props.failure.draft" />
348
+ <span v-else class="text-dimmed italic">—</span>
349
+ </button>
350
+ <p class="text-error flex items-start gap-1 text-xs">
351
+ <UIcon name="i-ph-warning-circle" class="mt-0.5 size-3.5 shrink-0" />
352
+ <span>
353
+ {{ $t('dms_lang.matrix.not_saved') }} · {{ props.failure.message }}
354
+ </span>
355
+ </p>
356
+ <p
357
+ v-if="props.failure.isConflict"
358
+ class="border-default text-dimmed line-clamp-3 rounded-md border border-dashed px-2.5 py-1.5 text-xs"
359
+ >
360
+ {{ $t('dms_lang.matrix.current_label') }}
361
+ <PlaceholderText
362
+ v-if="props.value"
363
+ :text="props.value"
364
+ class="text-default"
365
+ />
366
+ <span v-else class="italic">
367
+ {{ $t('dms_lang.matrix.current_none') }}
368
+ </span>
369
+ </p>
370
+ <div class="flex flex-wrap justify-end gap-1">
371
+ <UButton
372
+ size="xs"
373
+ color="neutral"
374
+ variant="ghost"
375
+ :label="$t('dms_lang.matrix.discard')"
376
+ @click="emit('discard', props.rowKey, props.code)"
377
+ />
378
+ <UButton
379
+ v-if="isFailureInvalid && isEscapable(failureIssues)"
380
+ size="xs"
381
+ color="error"
382
+ variant="soft"
383
+ :label="$t('dms_lang.message_issue.escape')"
384
+ @click="emit('escape', props.rowKey, props.code)"
385
+ />
386
+ <UButton
387
+ size="xs"
388
+ color="error"
389
+ variant="soft"
390
+ :label="$t(FAILURE_ACTION_LABELS[failureAction])"
391
+ @click="emit('retry', props.rowKey, props.code)"
392
+ />
393
+ </div>
394
+ </div>
395
+
396
+ <component
397
+ :is="props.editable ? 'button' : 'div'"
398
+ v-else
399
+ :type="props.editable ? 'button' : undefined"
400
+ :aria-label="props.editable && isMissing ? ariaLabel : undefined"
401
+ data-matrix-cell
402
+ :data-key="props.rowKey"
403
+ :data-code="props.code"
404
+ class="group/cell block w-full rounded-md px-2.5 py-1.5 text-left text-sm"
405
+ :class="[
406
+ props.editable
407
+ ? 'hover:bg-elevated/70 cursor-text transition-colors'
408
+ : '',
409
+ issues.length ? 'ring-warning/50 bg-warning/5 ring-1 ring-inset' : '',
410
+ isMissing && !props.inherited && props.editable
411
+ ? 'border-warning/40 bg-warning/5 hover:bg-warning/10 border border-dashed'
412
+ : '',
413
+ ]"
414
+ @click="props.editable && emit('edit', props.rowKey, props.code)"
415
+ >
416
+ <span v-if="isMissing && props.inherited" class="block space-y-0.5">
417
+ <span class="text-dimmed line-clamp-3 italic">
418
+ {{ props.inherited }}
419
+ </span>
420
+ <span
421
+ class="text-dimmed flex items-center gap-1 font-mono text-[10px] uppercase"
422
+ >
423
+ <UIcon name="i-ph-puzzle-piece" class="size-3" />
424
+ {{ $t('dms_lang.matrix.inherited') }}
425
+ </span>
426
+ </span>
427
+ <span
428
+ v-else-if="isMissing && (props.editable || props.isBase)"
429
+ class="flex items-center gap-2"
430
+ >
431
+ <span
432
+ class="text-warning font-mono text-[10px] font-bold tracking-wider uppercase"
433
+ >
434
+ {{
435
+ props.isBase
436
+ ? $t('dms_lang.matrix.source_missing')
437
+ : $t('dms_lang.matrix.missing')
438
+ }}
439
+ </span>
440
+ <span
441
+ v-if="props.editable"
442
+ class="text-dimmed min-w-0 truncate text-xs italic"
443
+ >
444
+ {{ $t('dms_lang.matrix.translate') }}
445
+ </span>
446
+ </span>
447
+ <span v-else-if="isMissing" class="text-dimmed italic">—</span>
448
+ <span v-else-if="props.override" class="block space-y-0.5">
449
+ <PlaceholderText
450
+ :text="props.override"
451
+ class="text-default line-clamp-3"
452
+ />
453
+ <span
454
+ class="text-dimmed line-clamp-2 text-xs line-through"
455
+ :title="$t('dms_lang.matrix.module_text')"
456
+ >
457
+ {{ props.value }}
458
+ </span>
459
+ </span>
460
+ <span
461
+ v-else
462
+ class="line-clamp-3"
463
+ :title="props.value.length > LONG_TEXT ? props.value : undefined"
464
+ >
465
+ <PlaceholderText :text="props.value" class="text-default" />
466
+ </span>
467
+ <span
468
+ v-for="issue in issues"
469
+ :key="issue.kind"
470
+ class="mt-1 flex items-start gap-1 font-mono text-[10.5px]"
471
+ :class="issue.severity === 'error' ? 'text-error' : 'text-warning'"
472
+ >
473
+ <UIcon name="i-ph-warning" class="mt-px size-3 shrink-0" />
474
+ {{ messageIssueText(issue, t) }}
475
+ </span>
476
+ <span
477
+ v-if="props.isOutdated && !isMissing"
478
+ class="text-info mt-1 flex items-center gap-1 font-mono text-[10.5px]"
479
+ :title="$t('dms_lang.drawer.outdated')"
480
+ >
481
+ <UIcon name="i-ph-clock-counter-clockwise" class="size-3" />
482
+ {{ $t('dms_lang.matrix.outdated') }}
483
+ </span>
484
+ <span v-if="props.state !== 'idle'" class="mt-1 flex">
485
+ <DmsSaveStatus :state="props.state" />
486
+ </span>
487
+ </component>
488
+ </template>
@@ -0,0 +1,177 @@
1
+ <script setup lang="ts">
2
+ import type { LanguageCoverage } from '../../../types/lang'
3
+ import LocaleTile from '../LocaleTile.vue'
4
+ import {
5
+ COVERAGE_TEXT_CLASSES,
6
+ coverageTone,
7
+ } from '../../../utils/translations'
8
+
9
+ interface Props {
10
+ languages: LanguageCoverage[]
11
+ canManage: boolean
12
+ /** The workspace settings page, where languages are added and removed. */
13
+ settingsLink: string
14
+ }
15
+
16
+ interface Emits {
17
+ add: []
18
+ }
19
+
20
+ type MoveDirection = -1 | 1
21
+
22
+ const props = defineProps<Props>()
23
+ const emit = defineEmits<Emits>()
24
+ const order = defineModel<string[]>('order', { required: true })
25
+
26
+ const dragged = ref<string | null>(null)
27
+
28
+ const rows = computed(() => {
29
+ const byCode = new Map(props.languages.map((entry) => [entry.code, entry]))
30
+ const shown = order.value
31
+ .map((code) => byCode.get(code))
32
+ .filter((entry): entry is LanguageCoverage => Boolean(entry))
33
+ const hidden = props.languages.filter(
34
+ (entry) => !order.value.includes(entry.code),
35
+ )
36
+ return [
37
+ ...shown.map((entry) => ({ ...entry, shown: true })),
38
+ ...hidden.map((entry) => ({ ...entry, shown: false })),
39
+ ]
40
+ })
41
+
42
+ const codes = computed(() => props.languages.map((entry) => entry.code))
43
+
44
+ function toggle(code: string) {
45
+ if (order.value.includes(code)) {
46
+ order.value = order.value.filter((entry) => entry !== code)
47
+ return
48
+ }
49
+ const isBase = props.languages.some(
50
+ (entry) => entry.code === code && entry.isBase,
51
+ )
52
+ order.value = isBase ? [code, ...order.value] : [...order.value, code]
53
+ }
54
+
55
+ /** Dropped on a row, a column takes that row's place: after it when moving down. */
56
+ function moveTo(code: string, target: string) {
57
+ const isMovingDown = order.value.indexOf(code) < order.value.indexOf(target)
58
+ const next = order.value.filter((entry) => entry !== code)
59
+ next.splice(next.indexOf(target) + (isMovingDown ? 1 : 0), 0, code)
60
+ order.value = next
61
+ }
62
+
63
+ function move(code: string, direction: MoveDirection) {
64
+ const index = order.value.indexOf(code)
65
+ const target = index + direction
66
+ if (index < 0 || target < 0 || target >= order.value.length) return
67
+ const next = [...order.value]
68
+ ;[next[index], next[target]] = [next[target], next[index]]
69
+ order.value = next
70
+ }
71
+
72
+ function onDrop(target: string) {
73
+ if (
74
+ dragged.value &&
75
+ dragged.value !== target &&
76
+ order.value.includes(target)
77
+ ) {
78
+ moveTo(dragged.value, target)
79
+ }
80
+ dragged.value = null
81
+ }
82
+ </script>
83
+
84
+ <template>
85
+ <UPopover :content="{ align: 'end' }">
86
+ <UButton
87
+ icon="i-ph-columns"
88
+ color="neutral"
89
+ variant="outline"
90
+ size="sm"
91
+ :label="
92
+ $t('dms_lang.matrix.languages', {
93
+ shown: order.length,
94
+ total: props.languages.length,
95
+ })
96
+ "
97
+ />
98
+ <template #content>
99
+ <div class="w-80 p-1.5">
100
+ <DmsEyebrow
101
+ :label="$t('dms_lang.matrix.columns_hint')"
102
+ size="xs"
103
+ class="px-2 pt-1.5 pb-2"
104
+ />
105
+ <ul class="space-y-0.5">
106
+ <li
107
+ v-for="row in rows"
108
+ :key="row.code"
109
+ class="hover:bg-elevated/50 flex items-center gap-2 rounded-md px-2 py-1.5"
110
+ :class="dragged === row.code ? 'opacity-50' : undefined"
111
+ :draggable="row.shown"
112
+ @dragstart="dragged = row.code"
113
+ @dragend="dragged = null"
114
+ @dragover.prevent
115
+ @drop.prevent="onDrop(row.code)"
116
+ >
117
+ <button
118
+ type="button"
119
+ class="text-dimmed cursor-grab rounded focus-visible:outline"
120
+ :class="row.shown ? undefined : 'invisible'"
121
+ :aria-label="$t('dms_lang.matrix.reorder', { name: row.name })"
122
+ @keydown.up.prevent="move(row.code, -1)"
123
+ @keydown.down.prevent="move(row.code, 1)"
124
+ >
125
+ <UIcon name="i-ph-dots-six-vertical" class="size-4" />
126
+ </button>
127
+ <UCheckbox
128
+ :model-value="row.shown"
129
+ :aria-label="row.name"
130
+ @update:model-value="toggle(row.code)"
131
+ />
132
+ <LocaleTile
133
+ :code="row.code"
134
+ size="sm"
135
+ :is-base="row.isBase"
136
+ :siblings="codes"
137
+ />
138
+ <span class="min-w-0 flex-1 truncate text-sm">{{ row.name }}</span>
139
+ <span
140
+ class="font-mono text-[10.5px]"
141
+ :class="
142
+ row.isBase
143
+ ? 'text-dimmed'
144
+ : COVERAGE_TEXT_CLASSES[coverageTone(row.coverage)]
145
+ "
146
+ >
147
+ {{ row.isBase ? $t('dms_lang.common.base') : `${row.coverage}%` }}
148
+ </span>
149
+ </li>
150
+ </ul>
151
+ <template v-if="props.canManage">
152
+ <USeparator class="my-1.5" />
153
+ <div class="flex gap-1">
154
+ <UButton
155
+ icon="i-ph-plus"
156
+ color="neutral"
157
+ variant="ghost"
158
+ size="sm"
159
+ class="flex-1 justify-center"
160
+ :label="$t('dms_lang.languages.add')"
161
+ @click="emit('add')"
162
+ />
163
+ <UButton
164
+ icon="i-ph-gear-six"
165
+ color="neutral"
166
+ variant="ghost"
167
+ size="sm"
168
+ class="flex-1 justify-center"
169
+ :to="props.settingsLink"
170
+ :label="$t('dms_lang.matrix.manage_languages')"
171
+ />
172
+ </div>
173
+ </template>
174
+ </div>
175
+ </template>
176
+ </UPopover>
177
+ </template>