@rivm-loculus-tools/sequence-editor 0.0.0-stage → 0.1.3
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/.gitkeep +0 -0
- package/CHANGELOG.md +30 -0
- package/LICENSE +288 -0
- package/eslint.config.js +16 -0
- package/package.json +144 -3
- package/scripts/update-exports.js +9 -0
- package/src/classes/services/EditorWorkerService/EditorWorkerService.ts +163 -0
- package/src/classes/services/EditorWorkerService/index.ts +1 -0
- package/src/classes/services/SequenceEditorEventBusService/SequenceEditorEventBusService.ts +37 -0
- package/src/classes/services/SequenceEditorEventBusService/index.ts +1 -0
- package/src/classes/workers/EngineWorker/EngineWorker.ts +196 -0
- package/src/classes/workers/EngineWorker/index.ts +1 -0
- package/src/components/app/App/App.tsx +22 -0
- package/src/components/app/App/index.ts +1 -0
- package/src/components/pages/EmptyWorkspace.tsx +43 -0
- package/src/components/pages/SequenceEditorErrorPage/SequenceEditorErrorPage.tsx +16 -0
- package/src/components/pages/SequenceEditorErrorPage/index.ts +1 -0
- package/src/components/pages/SequenceEditorMainPage/SequenceEditorMainPage.tsx +76 -0
- package/src/components/pages/SequenceEditorMainPage/index.ts +1 -0
- package/src/components/ui/SequenceEditor/SequenceEditor.tsx +896 -0
- package/src/components/ui/SequenceEditor/SequenceEditorGotoPositionDialog.tsx +108 -0
- package/src/components/ui/SequenceEditor/SequenceEditorStatusBar.tsx +72 -0
- package/src/components/ui/SequenceEditor/index.ts +1 -0
- package/src/components/ui/SequenceEditorPage/SequenceEditorPage.tsx +23 -0
- package/src/components/ui/SequenceEditorPage/index.ts +1 -0
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawer.tsx +234 -0
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawerColorForm.tsx +73 -0
- package/src/components/ui/SequenceEditorPageDrawer/SequenceEditorPageDrawerKeyboardShortcuts.tsx +230 -0
- package/src/components/ui/SequenceEditorPageDrawer/index.ts +1 -0
- package/src/components/ui/SequenceEditorPageHeader/SequenceEditorPageHeader.tsx +71 -0
- package/src/components/ui/SequenceEditorPageHeader/index.ts +1 -0
- package/src/components/ui/SequenceEditorSearchBar/SequenceEditorSearchBar.tsx +35 -0
- package/src/components/ui/SequenceEditorSearchBar/index.ts +1 -0
- package/src/constants/editor.ts +15 -0
- package/src/constants/index.ts +3 -0
- package/src/constants/keyboard.ts +154 -0
- package/src/constants/palette.ts +227 -0
- package/src/models/editor.ts +6 -0
- package/src/models/index.ts +3 -0
- package/src/models/model.ts +295 -0
- package/src/models/palette.ts +68 -0
- package/src/stores/sequenceEditorStore/index.ts +1 -0
- package/src/stores/sequenceEditorStore/sequenceEditorStore.ts +103 -0
- package/src/utils/EditorUtil/EditorUtil.ts +892 -0
- package/src/utils/EditorUtil/index.ts +1 -0
- package/src/utils/EngineErrorUtil/EngineErrorUtil.ts +25 -0
- package/src/utils/PaletteUtil/PaletteUtil.ts +31 -0
- package/src/utils/PaletteUtil/index.ts +1 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +32 -0
- package/vite.config.ts +177 -0
- package/README.md +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './EditorUtil';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const ENGINE_ERROR_MESSAGES = new Map<string, string>([
|
|
2
|
+
['DeleteNotGap', 'Delete failed: the selected position is not a gap.'],
|
|
3
|
+
['MoveNoGapTarget', 'Move failed: the target position must be a gap.'],
|
|
4
|
+
['MoveNotIupac', 'Move failed: only nucleotide or gap characters can move.'],
|
|
5
|
+
['MutateNotIupac', 'Edit failed: use a nucleotide, IUPAC ambiguity code, or gap.'],
|
|
6
|
+
]);
|
|
7
|
+
|
|
8
|
+
export class EngineErrorUtil {
|
|
9
|
+
public static getEngineErrorMessage(error: unknown): string {
|
|
10
|
+
const code = EngineErrorUtil.getEngineErrorCode(error);
|
|
11
|
+
const mappedMessage = code ? ENGINE_ERROR_MESSAGES.get(code) : undefined;
|
|
12
|
+
if (mappedMessage) {
|
|
13
|
+
return mappedMessage;
|
|
14
|
+
}
|
|
15
|
+
return error instanceof Error ? error.message : 'The sequence-editor command failed.';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private static getEngineErrorCode(error: unknown): null | string {
|
|
19
|
+
if (typeof error === 'object' && error !== null && 'message' in error) {
|
|
20
|
+
const code = (error as { message?: unknown }).message;
|
|
21
|
+
return typeof code === 'string' ? code : null;
|
|
22
|
+
}
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AminoAcidPalette,
|
|
3
|
+
NucleotidePalette,
|
|
4
|
+
PaletteEntry,
|
|
5
|
+
} from '../../models/palette';
|
|
6
|
+
|
|
7
|
+
export const HEX_COLOR_REGEX = /^#[0-9a-f]{6}$/i;
|
|
8
|
+
|
|
9
|
+
export class PaletteUtil {
|
|
10
|
+
public static createEntry(
|
|
11
|
+
background: string,
|
|
12
|
+
foreground: string,
|
|
13
|
+
backgroundSelected: string = background,
|
|
14
|
+
foregroundSelected: string = foreground,
|
|
15
|
+
): PaletteEntry {
|
|
16
|
+
return {
|
|
17
|
+
background,
|
|
18
|
+
backgroundSelected,
|
|
19
|
+
foreground,
|
|
20
|
+
foregroundSelected,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public static paletteEntryFor(
|
|
25
|
+
palette: AminoAcidPalette | NucleotidePalette,
|
|
26
|
+
cellValue: string,
|
|
27
|
+
): PaletteEntry {
|
|
28
|
+
const paletteColors = palette.paletteColors as Record<string, PaletteEntry>;
|
|
29
|
+
return paletteColors[cellValue] ?? paletteColors.X;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './PaletteUtil';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"extends": "./tsconfig.json",
|
|
4
|
+
"include": [
|
|
5
|
+
"src/**/*"
|
|
6
|
+
],
|
|
7
|
+
"exclude": [
|
|
8
|
+
"src/**/*.test.*",
|
|
9
|
+
"src/**/*.spec.*",
|
|
10
|
+
"src/**/__tests__/**",
|
|
11
|
+
"src/**/tests/**",
|
|
12
|
+
"src/test/setup/**"
|
|
13
|
+
]
|
|
14
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "esnext",
|
|
5
|
+
"useDefineForClassFields": true,
|
|
6
|
+
"lib": [
|
|
7
|
+
"ESNext",
|
|
8
|
+
"DOM",
|
|
9
|
+
"DOM.Iterable",
|
|
10
|
+
"WebWorker"
|
|
11
|
+
],
|
|
12
|
+
"module": "ESNext",
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"moduleResolution": "bundler",
|
|
15
|
+
"allowImportingTsExtensions": true,
|
|
16
|
+
"isolatedModules": true,
|
|
17
|
+
"moduleDetection": "force",
|
|
18
|
+
"noEmit": true,
|
|
19
|
+
"jsx": "react-jsx",
|
|
20
|
+
"strict": true,
|
|
21
|
+
"noUnusedLocals": true,
|
|
22
|
+
"noUnusedParameters": true,
|
|
23
|
+
"noFallthroughCasesInSwitch": true,
|
|
24
|
+
"types": [
|
|
25
|
+
"vite/client"
|
|
26
|
+
]
|
|
27
|
+
},
|
|
28
|
+
"include": [
|
|
29
|
+
"src",
|
|
30
|
+
"vite.config.ts"
|
|
31
|
+
]
|
|
32
|
+
}
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/// <reference types="vitest" />
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
globSync,
|
|
5
|
+
readFileSync,
|
|
6
|
+
} from 'fs';
|
|
7
|
+
import {
|
|
8
|
+
dirname,
|
|
9
|
+
join,
|
|
10
|
+
} from 'path';
|
|
11
|
+
|
|
12
|
+
import react from '@vitejs/plugin-react';
|
|
13
|
+
import svgr from 'vite-plugin-svgr';
|
|
14
|
+
import dts from 'vite-plugin-dts';
|
|
15
|
+
import { libInjectCss } from 'vite-plugin-lib-inject-css';
|
|
16
|
+
import { defineConfig } from 'vitest/config';
|
|
17
|
+
import type { Target } from 'vite-plugin-static-copy';
|
|
18
|
+
import { viteStaticCopy } from 'vite-plugin-static-copy';
|
|
19
|
+
import { esmExternalRequirePlugin } from 'vite';
|
|
20
|
+
|
|
21
|
+
type PackageManifest = {
|
|
22
|
+
peerDependencies?: Record<string, string>;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const createPeerDependencyExternalPatterns = () => {
|
|
26
|
+
const packageJson = JSON.parse(
|
|
27
|
+
readFileSync(join(import.meta.dirname, 'package.json'), 'utf8'),
|
|
28
|
+
) as PackageManifest;
|
|
29
|
+
|
|
30
|
+
return Object.keys(packageJson.peerDependencies ?? {}).map((dependency) => {
|
|
31
|
+
const escapedDependency = dependency.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
32
|
+
return new RegExp(`^${escapedDependency}(?:/.+)?$`);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const peerDependencyExternalPatterns = createPeerDependencyExternalPatterns();
|
|
37
|
+
|
|
38
|
+
const discoverEntries = (): { entries: Record<string, string>; flatKeys: Set<string> } => {
|
|
39
|
+
const entries: Record<string, string> = {};
|
|
40
|
+
const flatKeys = new Set<string>();
|
|
41
|
+
|
|
42
|
+
const srcDir = join(import.meta.dirname, 'src');
|
|
43
|
+
|
|
44
|
+
// index.ts-based entries (classes, utils): key = component directory
|
|
45
|
+
globSync([
|
|
46
|
+
join(srcDir, 'classes', '**', 'index.ts'),
|
|
47
|
+
join(srcDir, 'components', '**', 'index.ts'),
|
|
48
|
+
join(srcDir, 'constants', '**', 'index.ts'),
|
|
49
|
+
join(srcDir, 'dataHooks', '**', 'index.ts'),
|
|
50
|
+
join(srcDir, 'hoc', '**', 'index.ts'),
|
|
51
|
+
join(srcDir, 'hooks', '**', 'index.ts'),
|
|
52
|
+
join(srcDir, 'hooks', '**', 'index.ts'),
|
|
53
|
+
join(srcDir, 'locale', '**', 'index.ts'),
|
|
54
|
+
join(srcDir, 'pages', '**', 'index.ts'),
|
|
55
|
+
join(srcDir, 'routes', '**', 'index.ts'),
|
|
56
|
+
join(srcDir, 'stores', '**', 'index.ts'),
|
|
57
|
+
join(srcDir, 'theme', '**', 'index.ts'),
|
|
58
|
+
join(srcDir, 'utils', '**', 'index.ts'),
|
|
59
|
+
join(srcDir, 'utils', '**', 'index.ts'),
|
|
60
|
+
]).forEach((file) => {
|
|
61
|
+
const relKey = dirname(file).replace(`${srcDir}/`, '');
|
|
62
|
+
entries[relKey] = `./${file.replace(`${import.meta.dirname}/`, '')}`;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// flat .ts entries (models): key = file path without extension
|
|
66
|
+
globSync([join(srcDir, 'models', '*.ts'), join(srcDir, 'constants', '*.ts'), join(srcDir, 'setup', '*.ts'), join(srcDir, 'types', '*.ts')])
|
|
67
|
+
.filter((file) => !file.endsWith('/index.ts'))
|
|
68
|
+
.forEach((file) => {
|
|
69
|
+
const relKey = file.replace(`${srcDir}/`, '').replace(/\.ts$/, '');
|
|
70
|
+
entries[relKey] = `./${file.replace(`${import.meta.dirname}/`, '')}`;
|
|
71
|
+
flatKeys.add(relKey);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return { entries, flatKeys };
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const { entries: libEntries, flatKeys } = discoverEntries();
|
|
78
|
+
|
|
79
|
+
// https://vitejs.dev/config/
|
|
80
|
+
// eslint-disable-next-line import-x/no-default-export
|
|
81
|
+
export default defineConfig({
|
|
82
|
+
build: {
|
|
83
|
+
copyPublicDir: false,
|
|
84
|
+
lib: {
|
|
85
|
+
entry: libEntries,
|
|
86
|
+
fileName: (_, entryAlias) => {
|
|
87
|
+
if (entryAlias === 'index') {
|
|
88
|
+
return 'index.js';
|
|
89
|
+
}
|
|
90
|
+
// flat .ts entries output alongside their .d.ts; index.ts entries output in a subdirectory
|
|
91
|
+
return flatKeys.has(entryAlias) ? `${entryAlias}.js` : `${entryAlias}/index.js`;
|
|
92
|
+
},
|
|
93
|
+
formats: ['es'],
|
|
94
|
+
},
|
|
95
|
+
rolldownOptions: {
|
|
96
|
+
output: {
|
|
97
|
+
chunkFileNames: '_chunks/[name].js',
|
|
98
|
+
},
|
|
99
|
+
plugins: [
|
|
100
|
+
esmExternalRequirePlugin({
|
|
101
|
+
external: peerDependencyExternalPatterns,
|
|
102
|
+
}),
|
|
103
|
+
],
|
|
104
|
+
treeshake: true,
|
|
105
|
+
},
|
|
106
|
+
sourcemap: true,
|
|
107
|
+
},
|
|
108
|
+
plugins: [
|
|
109
|
+
react(),
|
|
110
|
+
svgr(),
|
|
111
|
+
libInjectCss(),
|
|
112
|
+
dts({
|
|
113
|
+
entryRoot: './src',
|
|
114
|
+
insertTypesEntry: false,
|
|
115
|
+
tsconfigPath: './tsconfig.build.json',
|
|
116
|
+
}),
|
|
117
|
+
viteStaticCopy({
|
|
118
|
+
targets: ([
|
|
119
|
+
{
|
|
120
|
+
dest: '@types',
|
|
121
|
+
rename: { stripBase: true },
|
|
122
|
+
src: [
|
|
123
|
+
'./src/@types/**/*.d.ts',
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
dest: './locale',
|
|
128
|
+
rename: { stripBase: true },
|
|
129
|
+
src: [
|
|
130
|
+
'./src/locale',
|
|
131
|
+
],
|
|
132
|
+
},
|
|
133
|
+
] satisfies Target[]).filter((target) => {
|
|
134
|
+
const sources = Array.isArray(target.src) ? target.src : [target.src];
|
|
135
|
+
return sources.some((pattern) => globSync(pattern).length > 0);
|
|
136
|
+
}),
|
|
137
|
+
}),
|
|
138
|
+
],
|
|
139
|
+
test: {
|
|
140
|
+
coverage: {
|
|
141
|
+
exclude: [
|
|
142
|
+
'node_modules/',
|
|
143
|
+
'dist/',
|
|
144
|
+
'.next/',
|
|
145
|
+
'build/',
|
|
146
|
+
'src/api/**/*',
|
|
147
|
+
'**/*.config.{js,ts}',
|
|
148
|
+
'**/*.test.{js,ts,jsx,tsx}',
|
|
149
|
+
'**/*.spec.{js,ts,jsx,tsx}',
|
|
150
|
+
'**/test/**',
|
|
151
|
+
'**/tests/**',
|
|
152
|
+
],
|
|
153
|
+
provider: 'v8',
|
|
154
|
+
reporter: ['text', 'json', 'html'],
|
|
155
|
+
reportsDirectory: './coverage',
|
|
156
|
+
},
|
|
157
|
+
projects: [
|
|
158
|
+
{
|
|
159
|
+
test: {
|
|
160
|
+
environment: 'jsdom',
|
|
161
|
+
globals: true,
|
|
162
|
+
include: [
|
|
163
|
+
'src/**/*.test.ts',
|
|
164
|
+
],
|
|
165
|
+
name: 'unit',
|
|
166
|
+
server: {
|
|
167
|
+
deps: {
|
|
168
|
+
inline: ['@mui/material', 'react-transition-group'],
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
setupFiles: ['./src/test/setup/setup-jsdom.ts'],
|
|
172
|
+
testTimeout: 5000,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
],
|
|
176
|
+
},
|
|
177
|
+
});
|
package/README.md
DELETED