@antelopejs/dms-lang 0.0.6 → 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 +10 -5
- package/package.json +10 -8
- package/dist/utils/mutations.d.ts +0 -3
- package/dist/utils/mutations.js +0 -35
- package/dist/utils/mutations.js.map +0 -1
- package/frontend-vue/app/build/components/pages/lang/TranslationMatrix.vue +0 -284
- package/frontend-vue/app/components/LanguageAddModal.vue +0 -78
- package/frontend-vue/app/components/WorkspaceEndpoint.vue +0 -29
- package/frontend-vue/app/components/WorkspaceSelector.vue +0 -180
- package/frontend-vue/app/components/WorkspaceStatus.vue +0 -24
- package/frontend-vue/app/composables/translation/useLanguageCatalog.ts +0 -90
- package/frontend-vue/app/composables/translation/useLocaleMeta.ts +0 -18
- package/frontend-vue/app/composables/translation/useTranslationProgress.ts +0 -73
- package/frontend-vue/app/custom-pages/lang/overview.vue +0 -397
- package/frontend-vue/app/custom-pages/lang/translations.vue +0 -498
- package/frontend-vue/app/plugins/workspace-sidebar-widget.ts +0 -12
|
@@ -0,0 +1,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
|
+
}
|