Skip to content

Commit 5ce8c97

Browse files
committed
Redo modules-lib animations
1 parent 9c02cca commit 5ce8c97

File tree

72 files changed

+1188
-1143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1188
-1143
lines changed

devserver/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
"@types/react-dom": "^18.3.1",
3131
"@vitest/browser": "^3.2.3",
3232
"eslint": "^9.31.0",
33-
"playwright": "^1.52.0",
33+
"playwright": "^1.54.1",
3434
"sass": "^1.85.0",
3535
"typescript": "^5.8.2",
3636
"vitest": "^3.2.3",
37-
"vitest-browser-react": "^0.2.0"
37+
"vitest-browser-react": "^1.0.0"
3838
},
3939
"scripts": {
4040
"dev": "vite",
Binary file not shown.

devserver/src/components/sideContent/SideContent.tsx

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Card, Icon, Tab, Tabs, Tooltip, type TabProps } from '@blueprintjs/core';
1+
import { Card, Icon, Tab, Tabs, Tooltip, type IconName, type TabProps } from '@blueprintjs/core';
22
import React from 'react';
33
import type { SideContentTab } from './types';
44

@@ -28,23 +28,29 @@ export type SideContentProps = {
2828
onChange?: (newId: string, oldId: string) => void
2929
};
3030

31+
interface TabIconProps {
32+
iconName: IconName
33+
tooltip: string
34+
shouldAlert?: boolean
35+
}
36+
37+
function TabIcon({ iconName, tooltip, shouldAlert }: TabIconProps) {
38+
return <Tooltip content={tooltip}>
39+
<div className={!shouldAlert ? 'side-content-tooltip' : 'side-content-tooltip side-content-tab-alert'}>
40+
<Icon icon={iconName} iconSize={20} />
41+
</div>
42+
</Tooltip>;
43+
}
44+
3145
const renderTab = (
3246
tab: SideContentTab,
3347
shouldAlert: boolean,
3448
_editorWidth?: string,
3549
_sideContentHeight?: number
3650
) => {
37-
const iconSize = 20;
38-
const tabTitle = (
39-
<Tooltip content={tab.label}>
40-
<div className={!shouldAlert ? 'side-content-tooltip' : 'side-content-tooltip side-content-tab-alert'}>
41-
<Icon icon={tab.iconName} iconSize={iconSize} />
42-
</div>
43-
</Tooltip>
44-
);
4551
const tabProps: TabProps = {
4652
id: tab.id,
47-
title: tabTitle,
53+
title: <TabIcon iconName={tab.iconName} tooltip={tab.label} shouldAlert={shouldAlert} />,
4854
// disabled: tab.disabled,
4955
className: 'side-content-tab'
5056
};
@@ -53,17 +59,6 @@ const renderTab = (
5359
return <Tab key={tab.id} {...tabProps} />;
5460
}
5561

56-
// const tabBody: JSX.Element = workspaceLocation
57-
// ? {
58-
// ...tab.body,
59-
// props: {
60-
// ...tab.body.props,
61-
// workspaceLocation,
62-
// editorWidth,
63-
// sideContentHeight
64-
// }
65-
// }
66-
// : tab.body;
6762
const tabPanel: React.JSX.Element = <div className="side-content-text">{tab.body}</div>;
6863

6964
return <Tab key={tab.id} {...tabProps} panel={tabPanel} />;

devserver/vite.config.ts

Lines changed: 54 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Devserver Vite Config
22
/// <reference types="@vitest/browser/providers/playwright" />
33

4+
import fs from 'fs/promises';
45
import pathlib from 'path';
56
import react from '@vitejs/plugin-react';
67
import { nodePolyfills } from 'vite-plugin-node-polyfills';
7-
import { loadEnv, defineConfig } from 'vite'
8+
import { loadEnv, defineConfig, type UserConfig, type ResolverFunction } from 'vite'
89
import { mergeConfig } from 'vitest/config';
910
import type { BrowserCommand } from 'vitest/node';
1011
import rootConfig from '../vitest.config';
@@ -17,62 +18,63 @@ const setLocalStorage: BrowserCommand<[key: string, value: any]> = async (ctx, k
1718

1819
export default defineConfig(({ mode }) => {
1920
const env = loadEnv(mode, process.cwd());
20-
// const modulesDir = pathlib.resolve(import.meta.dirname, '..', 'build')
2121

22-
return mergeConfig(
23-
rootConfig, {
24-
root: import.meta.dirname,
25-
plugins: [
26-
nodePolyfills({
27-
include: ['path']
28-
}),
29-
react(),
30-
],
31-
resolve: {
32-
preserveSymlinks: true,
33-
alias:[{
34-
find: /^js-slang\/context/,
35-
replacement: pathlib.resolve(import.meta.dirname, 'src', 'mockModuleContext.ts')
36-
}]
37-
},
38-
/* Experimental for serving modules using the dev server
39-
server: {
40-
port: 8022,
41-
strictPort: true,
42-
proxy: {
43-
'/modules': {
44-
target: 'http://localhost:8022',
45-
rewrite(path) {
46-
const finalPath = path.replace('/modules', modulesDir)
47-
return `/@fs/${finalPath}`
48-
}
22+
const viteConfig: UserConfig = {
23+
root: import.meta.dirname,
24+
plugins: [
25+
nodePolyfills({
26+
include: ['path']
27+
}),
28+
react(),
29+
],
30+
resolve: {
31+
preserveSymlinks: true,
32+
alias: [{
33+
find: /^js-slang\/context/,
34+
replacement: pathlib.resolve(import.meta.dirname, 'src', 'mockModuleContext.ts')
35+
}, {
36+
// This alias configuration allows us to edit the modules library and the changes
37+
// be reflected in real time when in hot-reload mode
38+
find: /^@sourceacademy\/modules-lib\/tabs/,
39+
replacement: '.',
40+
async customResolver(source) {
41+
const newSource = pathlib.resolve(import.meta.dirname, '../lib/modules-lib/src/tabs', source)
42+
const extensions = ['.tsx', '.ts', '/index.ts']
43+
44+
for (const each of extensions) {
45+
try {
46+
await fs.access(`${newSource}${each}`, fs.constants.R_OK)
47+
return `${newSource}${each}`
48+
} catch {}
4949
}
50+
51+
return undefined;
5052
},
51-
fs: {
52-
allow: [
53-
searchForWorkspaceRoot(import.meta.dirname),
54-
modulesDir
55-
]
53+
}],
54+
},
55+
define: {
56+
'process.env': env
57+
},
58+
optimizeDeps: {
59+
esbuildOptions: {
60+
// Node.js global to browser globalThis
61+
define: {
62+
global: 'globalThis'
5663
}
5764
},
58-
*/
59-
define: {
60-
'process.env': env
61-
},
62-
optimizeDeps: {
63-
esbuildOptions: {
64-
// Node.js global to browser globalThis
65-
define: {
66-
global: 'globalThis'
67-
}
68-
},
69-
include: [
70-
"vite-plugin-node-polyfills/shims/buffer",
71-
"vite-plugin-node-polyfills/shims/global",
72-
"vite-plugin-node-polyfills/shims/process",
73-
'../build/tabs/*.js'
74-
],
75-
},
65+
include: [
66+
"vite-plugin-node-polyfills/shims/buffer",
67+
"vite-plugin-node-polyfills/shims/global",
68+
"vite-plugin-node-polyfills/shims/process",
69+
'../build/tabs/*.js',
70+
// '@sourceacademy/modules-lib/tabs'
71+
],
72+
},
73+
}
74+
75+
return mergeConfig(
76+
rootConfig, {
77+
...viteConfig,
7678
test: {
7779
name: 'Dev Server',
7880
include: [

lib/buildtools/src/__tests__/utils.test.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { describe, expect, test } from 'vitest';
2-
import { Severity } from '../types.js';
2+
import type { Severity } from '../types.js';
33
import { compareSeverity, filterAsync, findSeverity } from '../utils.js';
44

55
describe('test findSeverity', () => {
66
const cases: Severity[][] = [
7-
[Severity.SUCCESS, Severity.SUCCESS, Severity.SUCCESS],
8-
[Severity.WARN, Severity.SUCCESS, Severity.WARN],
9-
[Severity.WARN, Severity.WARN, Severity.WARN],
10-
[Severity.ERROR, Severity.ERROR, Severity.WARN],
11-
[Severity.ERROR, Severity.ERROR, Severity.SUCCESS]
7+
['success', 'success', 'success'],
8+
['warn', 'success', 'warn'],
9+
['warn', 'warn', 'warn'],
10+
['error', 'error', 'warn'],
11+
['error', 'error', 'success']
1212
];
1313

1414
test.each(cases)('Expecting %s', (expected, ...args) => {
@@ -18,15 +18,15 @@ describe('test findSeverity', () => {
1818

1919
describe('test compareSeverity', () => {
2020
const cases: [Severity, Severity, Severity][] = [
21-
[Severity.SUCCESS, Severity.SUCCESS, Severity.SUCCESS],
22-
[Severity.WARN, Severity.SUCCESS, Severity.WARN],
23-
[Severity.WARN, Severity.WARN, Severity.SUCCESS],
24-
[Severity.WARN, Severity.WARN, Severity.WARN],
25-
[Severity.ERROR, Severity.SUCCESS, Severity.ERROR],
26-
[Severity.ERROR, Severity.WARN, Severity.ERROR],
27-
[Severity.ERROR, Severity.ERROR, Severity.ERROR],
28-
[Severity.ERROR, Severity.ERROR, Severity.WARN],
29-
[Severity.ERROR, Severity.ERROR, Severity.SUCCESS],
21+
['success', 'success', 'success'],
22+
['warn', 'success', 'warn'],
23+
['warn', 'warn', 'success'],
24+
['warn', 'warn', 'warn'],
25+
['error', 'success', 'error'],
26+
['error', 'warn', 'error'],
27+
['error', 'error', 'error'],
28+
['error', 'error', 'warn'],
29+
['error', 'error', 'success'],
3030
];
3131

3232
test.each(cases)('Expecting %s', (expected, lhs, rhs) => {

0 commit comments

Comments
 (0)