@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,115 @@
1
+ /** A text typed in the queue and not saved yet. */
2
+ export interface QueueDraft {
3
+ value: string
4
+ /**
5
+ * The saved value it was started on (`null`: no text), sent as the value
6
+ * expected by the server: a change made elsewhere meanwhile is a conflict.
7
+ */
8
+ start: string | null
9
+ }
10
+
11
+ /** The drafts of the queue, by draft id. */
12
+ export type QueueDrafts = Record<string, QueueDraft>
13
+
14
+ /** Where a draft was typed: a key of a language of a workspace. */
15
+ export interface DraftId {
16
+ workspace: string
17
+ locale: string
18
+ key: string
19
+ }
20
+
21
+ /** A draft taken out, with where it was typed. */
22
+ export interface DraftEntry extends DraftId {
23
+ value: string
24
+ }
25
+
26
+ /** Drafts of one workspace and language, for the links back to them. */
27
+ export interface DraftGroup {
28
+ workspace: string
29
+ locale: string
30
+ count: number
31
+ }
32
+
33
+ /** Whether a draft must go: its key, language or workspace no longer exists. */
34
+ export type DraftCheck = (id: DraftId) => boolean
35
+
36
+ /** Drafts split between the ones kept and the ones taken out. */
37
+ export interface DraftSplit {
38
+ kept: QueueDrafts
39
+ taken: DraftEntry[]
40
+ }
41
+
42
+ /** A line break: neither a workspace id, a language code nor a key holds one. */
43
+ export const DRAFT_SEPARATOR = '\n'
44
+
45
+ export function draftIdOf(id: DraftId): string {
46
+ return [id.workspace, id.locale, id.key].join(DRAFT_SEPARATOR)
47
+ }
48
+
49
+ export function parseDraftId(id: string): DraftId {
50
+ const [workspace = '', locale = '', ...key] = id.split(DRAFT_SEPARATOR)
51
+ return { workspace, locale, key: key.join(DRAFT_SEPARATOR) }
52
+ }
53
+
54
+ /** The drafts without one. */
55
+ export function withoutDraft(drafts: QueueDrafts, id: string): QueueDrafts {
56
+ const { [id]: _dropped, ...rest } = drafts
57
+ return rest
58
+ }
59
+
60
+ /** The drafts with one set; a text back to the one it started on is no draft. */
61
+ export function withDraft(
62
+ drafts: QueueDrafts,
63
+ id: string,
64
+ draft: QueueDraft,
65
+ ): QueueDrafts {
66
+ const rest = withoutDraft(drafts, id)
67
+ return draft.value === (draft.start ?? '') ? rest : { ...rest, [id]: draft }
68
+ }
69
+
70
+ /** A text sent for a draft: as it was typed, and as the server stores it. */
71
+ export interface SentDraft {
72
+ typed: string
73
+ stored: string | null
74
+ }
75
+
76
+ /**
77
+ * The drafts once a draft was saved: gone when it is still the text typed
78
+ * when it was sent, else kept (typed during the save) and started on the
79
+ * text the server now stores.
80
+ */
81
+ export function settledDrafts(
82
+ drafts: QueueDrafts,
83
+ id: string,
84
+ sent: SentDraft,
85
+ ): QueueDrafts {
86
+ const draft = drafts[id]
87
+ if (!draft || draft.value === sent.typed) return withoutDraft(drafts, id)
88
+ return withDraft(drafts, id, { value: draft.value, start: sent.stored })
89
+ }
90
+
91
+ /** The drafts, grouped per workspace and language. */
92
+ export function draftGroups(drafts: QueueDrafts): DraftGroup[] {
93
+ const found = new Map<string, DraftGroup>()
94
+ for (const id of Object.keys(drafts)) {
95
+ const { workspace, locale } = parseDraftId(id)
96
+ const name = [workspace, locale].join(DRAFT_SEPARATOR)
97
+ const group = found.get(name) ?? { workspace, locale, count: 0 }
98
+ found.set(name, { ...group, count: group.count + 1 })
99
+ }
100
+ return [...found.values()]
101
+ }
102
+
103
+ /** Takes out the drafts `isGone` names. */
104
+ export function takeDrafts(
105
+ drafts: QueueDrafts,
106
+ isGone: DraftCheck,
107
+ ): DraftSplit {
108
+ const split: DraftSplit = { kept: {}, taken: [] }
109
+ for (const [id, draft] of Object.entries(drafts)) {
110
+ const parsed = parseDraftId(id)
111
+ if (isGone(parsed)) split.taken.push({ ...parsed, value: draft.value })
112
+ else split.kept[id] = draft
113
+ }
114
+ return split
115
+ }
@@ -0,0 +1,145 @@
1
+ /** Where a key of a pass stands once acted on: saved or skipped. */
2
+ export type KeyStatus = 'done' | 'skipped'
3
+
4
+ /** What advancing the queue did: moved on, went back to skipped keys, stayed on the last key, or ran out of keys. */
5
+ export type QueueStep = 'moved' | 'wrapped' | 'last' | 'finished'
6
+
7
+ /**
8
+ * One pass through the queue: the keys it holds, fixed when it starts (a
9
+ * saved key stays in it, so Previous goes back to it), each one done, skipped
10
+ * or still to do, the key shown and the keys shown before it.
11
+ */
12
+ export interface QueuePass {
13
+ order: string[]
14
+ status: Record<string, KeyStatus>
15
+ cursor: number
16
+ history: number[]
17
+ isFinished: boolean
18
+ }
19
+
20
+ /** A pass after a move, and what the move did. */
21
+ export interface QueueMove {
22
+ pass: QueuePass
23
+ step: QueueStep
24
+ }
25
+
26
+ /** A pass after a change, and what it did when the change moved the queue. */
27
+ export interface QueueChange {
28
+ pass: QueuePass
29
+ step?: QueueStep
30
+ }
31
+
32
+ /** Whether a key still has something to do in its own right: it fits the mode or holds a draft. */
33
+ export type KeyIsOpen = (key: string) => boolean
34
+
35
+ /** A pass with no key. */
36
+ export const EMPTY_PASS: QueuePass = {
37
+ order: [],
38
+ status: {},
39
+ cursor: 0,
40
+ history: [],
41
+ isFinished: false,
42
+ }
43
+
44
+ /** Whether a key of the pass is still to do: open, and not saved in this pass. */
45
+ export function isPendingKey(
46
+ pass: QueuePass,
47
+ key: string | undefined,
48
+ isOpen: KeyIsOpen,
49
+ ): boolean {
50
+ if (key === undefined || pass.status[key] === 'done') return false
51
+ return isOpen(key)
52
+ }
53
+
54
+ /** The keys still to do, in the order of the pass. */
55
+ export function pendingKeys(pass: QueuePass, isOpen: KeyIsOpen): string[] {
56
+ return pass.order.filter((key) => isPendingKey(pass, key, isOpen))
57
+ }
58
+
59
+ /** The key shown; none once the pass is finished. */
60
+ export function currentKey(pass: QueuePass): string | undefined {
61
+ return pass.isFinished ? undefined : pass.order[pass.cursor]
62
+ }
63
+
64
+ /** Starts a pass over `order`, on `key` when it is in it, else on its first key. */
65
+ export function startPass(
66
+ order: string[],
67
+ key: string,
68
+ isOpen: KeyIsOpen,
69
+ ): QueuePass {
70
+ const pass = { ...EMPTY_PASS, order, cursor: Math.max(order.indexOf(key), 0) }
71
+ return { ...pass, isFinished: pendingKeys(pass, isOpen).length === 0 }
72
+ }
73
+
74
+ /** The positions of the keys still to do after `from`, going round to the start. */
75
+ export function pendingAfter(
76
+ pass: QueuePass,
77
+ from: number,
78
+ isOpen: KeyIsOpen,
79
+ ): number[] {
80
+ const size = pass.order.length
81
+ return Array.from(
82
+ { length: Math.max(size - 1, 0) },
83
+ (_, step) => (from + step + 1) % size,
84
+ ).filter((index) => isPendingKey(pass, pass.order[index], isOpen))
85
+ }
86
+
87
+ /** Shows the key at `index`, remembering the one shown for Previous. */
88
+ export function goToIndex(pass: QueuePass, index: number): QueuePass {
89
+ const history = pass.isFinished
90
+ ? pass.history
91
+ : [...pass.history, pass.cursor]
92
+ return { ...pass, history, cursor: index, isFinished: false }
93
+ }
94
+
95
+ /**
96
+ * Moves to the next key still to do, going round to the skipped ones; stays
97
+ * when the key shown is the last one to do, and finishes when none is left.
98
+ */
99
+ export function advancePass(pass: QueuePass, isOpen: KeyIsOpen): QueueMove {
100
+ const [next] = pendingAfter(pass, pass.cursor, isOpen)
101
+ if (next !== undefined) {
102
+ const step = next < pass.cursor ? 'wrapped' : 'moved'
103
+ return { pass: goToIndex(pass, next), step }
104
+ }
105
+ if (isPendingKey(pass, pass.order[pass.cursor], isOpen))
106
+ return { pass, step: 'last' }
107
+ const history = [...pass.history, pass.cursor]
108
+ return { pass: { ...pass, history, isFinished: true }, step: 'finished' }
109
+ }
110
+
111
+ function marked(pass: QueuePass, key: string, status: KeyStatus): QueuePass {
112
+ return { ...pass, status: { ...pass.status, [key]: status } }
113
+ }
114
+
115
+ /** Skips the key shown (it comes back once the others are done) and moves on. */
116
+ export function skipCurrent(pass: QueuePass, isOpen: KeyIsOpen): QueueMove {
117
+ const key = currentKey(pass)
118
+ const isSkippable = key !== undefined && isPendingKey(pass, key, isOpen)
119
+ return advancePass(isSkippable ? marked(pass, key, 'skipped') : pass, isOpen)
120
+ }
121
+
122
+ /** Marks a key saved; moves on when it is the one shown and `shouldAdvance`. */
123
+ export function completeKey(
124
+ pass: QueuePass,
125
+ key: string,
126
+ shouldAdvance: boolean,
127
+ isOpen: KeyIsOpen,
128
+ ): QueueChange {
129
+ const done = marked(pass, key, 'done')
130
+ if (shouldAdvance && currentKey(pass) === key)
131
+ return advancePass(done, isOpen)
132
+ return { pass: done }
133
+ }
134
+
135
+ /** Goes back to the key shown before; the same pass when there is none. */
136
+ export function previousKey(pass: QueuePass): QueuePass {
137
+ const index = pass.history.at(-1)
138
+ if (index === undefined) return pass
139
+ return {
140
+ ...pass,
141
+ history: pass.history.slice(0, -1),
142
+ cursor: index,
143
+ isFinished: false,
144
+ }
145
+ }
@@ -0,0 +1,22 @@
1
+ /** What the translation queue card shows. */
2
+ export type QueueView = 'loading' | 'unknown' | 'base' | 'queue'
3
+
4
+ /** What the queue card is chosen from. */
5
+ export interface QueueViewFacts {
6
+ /** The workspace and its translations are both in. */
7
+ isResolved: boolean
8
+ /** The language asked for is one of the workspace. */
9
+ exists: boolean
10
+ isBase: boolean
11
+ }
12
+
13
+ /**
14
+ * The state the queue card shows. It waits for the workspace as well as its
15
+ * translations: until the workspace list is in, nothing says whether its
16
+ * texts can be edited, and an editor shown meanwhile would start read-only.
17
+ */
18
+ export function queueViewOf(facts: QueueViewFacts): QueueView {
19
+ if (!facts.isResolved) return 'loading'
20
+ if (!facts.exists) return 'unknown'
21
+ return facts.isBase ? 'base' : 'queue'
22
+ }
@@ -0,0 +1,75 @@
1
+ /** A key combination, each key named as `defineShortcuts` names it (`meta`, `enter`, `s`). */
2
+ export type ShortcutKeys = readonly string[]
3
+
4
+ /** The description and the condition of a shortcut, as i18n keys of the module. */
5
+ interface ShortcutText {
6
+ keys: ShortcutKeys
7
+ description: string
8
+ condition?: string
9
+ }
10
+
11
+ const KEYBOARD_TEXTS = '$keyboard.'
12
+ const TEXTS = '$dms_lang.shortcuts'
13
+ const COMBINATION_SEPARATOR = '_'
14
+ /** Named keys the DMS keyboard texts do not cover. */
15
+ const OWN_KEY_TEXTS: Record<string, string> = {
16
+ tab: `${TEXTS}.keys.tab`,
17
+ }
18
+
19
+ /** The keys of the translation queue. */
20
+ export const QUEUE_KEYS = {
21
+ saveNext: ['meta', 'enter'],
22
+ save: ['meta', 's'],
23
+ leaveField: ['escape'],
24
+ skip: ['s'],
25
+ previous: ['p'],
26
+ } as const satisfies Record<string, ShortcutKeys>
27
+
28
+ /** The keys of the translation matrix. */
29
+ export const MATRIX_KEYS = {
30
+ nextMissing: ['n'],
31
+ previousMissing: ['shift', 'n'],
32
+ saveDown: ['enter'],
33
+ newLine: ['shift', 'enter'],
34
+ nextCell: ['tab'],
35
+ cancel: ['escape'],
36
+ openPanel: ['meta', 'shift', 'enter'],
37
+ } as const satisfies Record<string, ShortcutKeys>
38
+
39
+ /** The keys of the key side panel. */
40
+ export const KEY_PANEL_KEYS = {
41
+ saveNext: ['meta', 'enter'],
42
+ } as const satisfies Record<string, ShortcutKeys>
43
+
44
+ /** The name `defineShortcuts` binds a combination under (`meta_enter`). */
45
+ export function shortcutName(keys: ShortcutKeys): string {
46
+ return keys.join(COMBINATION_SEPARATOR)
47
+ }
48
+
49
+ /** A key as the Shortcuts settings page prints it: named keys through the DMS keyboard texts. */
50
+ function registryKey(key: string): string {
51
+ if (key.length === 1) return key
52
+ return Object.hasOwn(OWN_KEY_TEXTS, key)
53
+ ? OWN_KEY_TEXTS[key]
54
+ : `${KEYBOARD_TEXTS}${key}`
55
+ }
56
+
57
+ function metadataOf(component: string, text: ShortcutText): ShortcutMetadata {
58
+ return {
59
+ key: text.keys.map(registryKey),
60
+ descriptionKey: `${TEXTS}.${text.description}`,
61
+ component,
62
+ ...(text.condition
63
+ ? { condition: { descriptionKey: `${TEXTS}.${text.condition}` } }
64
+ : {}),
65
+ }
66
+ }
67
+
68
+ /** The shortcuts of a component, as the DMS shortcuts registry lists them. */
69
+ export function shortcutGroup(component: string, texts: ShortcutText[]) {
70
+ const name = `${TEXTS}.groups.${component}`
71
+ return {
72
+ component: name,
73
+ shortcuts: texts.map((text) => metadataOf(name, text)),
74
+ }
75
+ }