Skip to content

Commit fa97a46

Browse files
committed
observable version
1 parent 6ded595 commit fa97a46

Some content is hidden

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

69 files changed

+2793
-438
lines changed

.npmrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Set default registry: npm config set registry https://registry.npmjs.com/
2+
# This project default install package by npm or yarn which will download from the below registry server.
3+
registry=http://registry.npm.dtstack.com/

.storybook/main.js

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const path = require('path');
2+
const webpack = require('webpack');
3+
24
module.exports = {
35
stories: ['../stories/**/*.stories.tsx'],
46
addons: ['@storybook/addon-actions', '@storybook/addon-links'],
@@ -14,15 +16,34 @@ module.exports = {
1416
loader: require.resolve('react-docgen-typescript-loader'),
1517
},
1618
],
19+
},
20+
{
21+
test: /\.worker\.js$/,
22+
use: { loader: 'worker-loader' }
1723
}, {
1824
test: /\.scss$/,
1925
use: ['style-loader', 'css-loader', 'sass-loader'],
2026
include: path.resolve(__dirname, '../'),
2127
});
28+
29+
config.node = {
30+
fs: 'empty',
31+
module: "empty",
32+
};
33+
34+
config.plugins.push(new webpack.ContextReplacementPlugin(
35+
/monaco-editor(\\|\/)esm(\\|\/)vs(\\|\/)editor(\\|\/)common(\\|\/)services/,
36+
__dirname
37+
))
38+
39+
2240
config.resolve.alias = {
23-
'@': path.resolve(__dirname, '../src')
41+
'@': path.resolve(__dirname, '../src'),
42+
'@stories': path.resolve(__dirname, '../stories'),
2443
}
25-
config.resolve.extensions.push('.ts', '.tsx');
44+
config.resolve.extensions.push('.ts', '.tsx', '.js', '.jsx');
45+
config.devtool = 'cheap-module-eval-source-map';
46+
2647
return config;
2748
},
2849
};

LICENSE

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MIT

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
# Molecule
22

33
A Web IDE UI library built by React.js, inspired by VSCode.
4+
5+
## vscode codicons online address
6+
7+
<https://microsoft.github.io/vscode-codicons/dist/codicon.html>
File renamed without changes.

package.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "molecule",
33
"version": "0.9.0",
4-
"description": "A Web IDE UI library built by React.js, inspired by VSCode. ",
4+
"description": "A Web IDE UI Framework built by React.js, inspired by VSCode.",
55
"main": "lib/core/index.js",
66
"scripts": {
77
"test": "jest --coverage",
8-
"dev": "start-storybook -p 6006",
8+
"dev": "start-storybook -s ./public -p 6006",
99
"build-storybook": "build-storybook",
1010
"check-types": "tsc --skipLibCheck",
1111
"eslint": "npx eslint ./src/**/*.ts ./src/**/*.tsx",
@@ -21,10 +21,17 @@
2121
"license": "ISC",
2222
"dependencies": {
2323
"@types/react": "^16.9.35",
24+
"classnames": "^2.2.6",
25+
"dt-react-monaco-editor": "^0.0.6",
26+
"dt-utils": "^1.0.1",
27+
"loadsh": "^0.0.4",
28+
"rc-collapse": "^2.0.1",
29+
"rc-tree": "^3.10.0",
2430
"react": "^16.13.1",
2531
"react-dom": "^16.13.1",
2632
"react-split-pane": "^0.1.92",
27-
"tsyringe": "^4.3.0"
33+
"tsyringe": "^4.3.0",
34+
"vscode-codicons": "^0.0.10"
2835
},
2936
"devDependencies": {
3037
"@babel/core": "7.8.7",

src/common/error.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const ErrorMsg = {
2+
LoadExtensionFail: 'Load Extension failed',
3+
NotFoundActivate: 'Not found activate function, the extension must export an activate function as entry.',
4+
};
5+

src/common/observable.ts

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
export interface IObservable<T = any> {
2+
observe: (handler: (nextObject: T) => void) => void;
3+
}
4+
5+
export function observable<T>(object, callback?): IObservable & T {
6+
object.handlers = [];
7+
object.observe = function(handler: Function) {
8+
object.handlers.push(handler);
9+
};
10+
11+
const handler = {
12+
get(target, property, receiver) {
13+
if (target.hasOwnProperty(property)) {
14+
try {
15+
return new Proxy(target[property], handler);
16+
} catch (err) {
17+
return Reflect.get(target, property, receiver);
18+
}
19+
}
20+
return Reflect.get(target, property, receiver);
21+
},
22+
set: function(target, property, value, receiver) {
23+
console.log('set value:', target, property, value, receiver);
24+
let nextTarget = target;
25+
if (target.hasOwnProperty(property)) {
26+
try {
27+
Reflect.set(target, property, value, receiver);
28+
nextTarget = new Proxy(target[property], handler);
29+
} catch (err) {
30+
nextTarget = Reflect.set(target, property, value, receiver);
31+
}
32+
} else {
33+
nextTarget = Reflect.set(target, property, value, receiver);
34+
}
35+
if (callback) {
36+
callback(target, property, value);
37+
}
38+
if (object.handlers) {
39+
object.handlers.forEach((handler) => handler(nextTarget));
40+
}
41+
return nextTarget;
42+
},
43+
};
44+
return new Proxy(object, handler);
45+
}

src/components/collapse/index.tsx

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as React from 'react';
2+
import RcCollapse from 'rc-collapse';
3+
import classNames from 'classnames';
4+
5+
import './style.scss';
6+
import { prefixClaName } from '@/common/className';
7+
8+
interface ICollapseProps {
9+
className?: string;
10+
}
11+
12+
export const Collapse: React.FunctionComponent<ICollapseProps> = (props: ICollapseProps) => {
13+
return (
14+
<RcCollapse
15+
className={classNames(prefixClaName('collapse'), props.className)}
16+
{...props}
17+
/>
18+
);
19+
};
20+
21+
export const Panel = RcCollapse.Panel;
22+
export default Collapse;

src/components/collapse/style.scss

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import '@/style/const.scss';
2+
3+
.#{prefix}-collapse {
4+
font-size: 13px;
5+
}

src/components/tabs/index.tsx

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import * as React from 'react';
2+
3+
import { prefixClaName } from '@/common/className';
4+
5+
export interface ITab<T = any, K = any> {
6+
id?: number;
7+
name?: string;
8+
mode?: string;
9+
data?: T;
10+
options?: K;
11+
value?: string;
12+
renderPane?: () => React.ReactElement;
13+
}
14+
15+
interface ITabsProps {
16+
data: ITab[];
17+
}
18+
19+
const Tabs: React.FunctionComponent<ITabsProps> = (props: ITabsProps) => {
20+
const { data } = props;
21+
const tabs = data.map((tab: ITab) => {
22+
return (<a key={tab.id}>{tab.name}</a>);
23+
});
24+
return (
25+
<div className={prefixClaName('tabs')}>
26+
{tabs}
27+
</div>
28+
);
29+
};
30+
31+
export default Tabs;

src/components/tabs/style.scss

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.scroll {
2+
width: 10px;
3+
pointer-events: none;
4+
}

src/components/tree/index.tsx

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as React from 'react';
2+
import RcTree from 'rc-tree';
3+
import classNames from 'classnames';
4+
5+
import './style.scss';
6+
import { prefixClaName } from '@/common/className';
7+
8+
export interface ITree {
9+
10+
}
11+
12+
interface ITreeProps {
13+
className?: string;
14+
data?: ITree;
15+
}
16+
17+
export const Tree: React.FunctionComponent<ITreeProps> = (props: ITreeProps) => {
18+
return (
19+
<RcTree
20+
className={classNames(prefixClaName('tree'), props.className)}
21+
{...props}
22+
/>
23+
);
24+
};
25+
26+
export default Tree;

src/components/tree/style.scss

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@import '@/style/const.scss';
2+
3+
.#{prefix}-tree {
4+
font-size: 13px;
5+
}

src/core/activityBar.ts

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
// import { ReactType } from '@/typings';
22
import * as React from 'react';
33

4-
export interface IActivityBarData {
5-
id: string;
4+
export interface IActivityBarItem {
5+
id?: string;
66
name?: string;
77
data?: any;
8+
iconName?: string;
9+
checked?: boolean;
810
// render?: <T>() => T;
911
render?: () => any;
12+
onClick?:(e: React.MouseEvent, option: IActivityBarItem) => any;
1013
}
1114

1215
export interface IActivityBar {
13-
readonly data: IActivityBarData[];
14-
onSelect: (key: string, item: IActivityBarData) => void;
15-
onClick: (event: React.MouseEvent, item: IActivityBarData) => void;
16-
push: (data: IActivityBarData) => void;
16+
data: IActivityBarItem[];
17+
selected: string;
18+
onSelect: (key: string, item?: IActivityBarItem) => void;
19+
onClick: (event: React.MouseEvent, item: IActivityBarItem) => void;
20+
push: (data: IActivityBarItem | IActivityBarItem []) => void;
1721
remove: (index: number) => void;
1822
update: () => void;
1923
get: (id: string) => void;

src/core/editor.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1-
export interface IEditor {
2-
value: string;
1+
import { ITab } from '@/components/tabs';
2+
3+
export interface IEditorInstance<E = any> {
4+
id: number;
5+
activeTab: ITab;
6+
tabs: ITab[];
7+
breadcrumb: any[];
8+
actions: any[];
9+
menu: any[];
10+
editorInstance?: E | null;
11+
}
12+
13+
export interface IEditor<T = any> {
14+
current: IEditorInstance | null;
15+
group: IEditorInstance [];
16+
open: (tab: ITab<T>, instanceId: number) => void;
17+
close?: (index: number, callback: () => void) => void;
18+
closeAll?: () => void;
19+
onClose?: () => void;
20+
render?:() => React.ReactElement;
321
}

0 commit comments

Comments
 (0)