Skip to content

Commit 897f6c1

Browse files
authored
Merge pull request #162 from ecomfe/dev-ts
santd 2.0
2 parents a14c561 + 19780cc commit 897f6c1

File tree

641 files changed

+14608
-8621
lines changed

Some content is hidden

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

641 files changed

+14608
-8621
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ output/
66
node_modules/
77
**/node_modules/
88
dest/
9+
dist/
10+
types/
911
build/
1012
npm-debug.log
1113
package-lock.json

package.json

+20-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "santd",
3-
"version": "1.1.3",
3+
"version": "2.0.0-alpha.0",
44
"description": "san UI design",
55
"scripts": {
66
"start": "cross-env NODE_ENV=development node scripts/preview.js",
@@ -13,14 +13,18 @@
1313
"dev:issue": "cross-env NODE_ENV=development node scripts/issue.js",
1414
"build:issue": "cross-env NODE_ENV=production webpack --config scripts/webpack.issue.conf.js",
1515
"lint:script": "fecs --type=js",
16-
"lint:style": "stylelint \"{site, src}/**/*.less\" --syntax less"
16+
"lint:style": "stylelint \"{site, src}/**/*.less\" --syntax less",
17+
"build:cjs": "tsc -p tsconfig.json",
18+
"build:esm": "tsc -p tsconfig.esm.json",
19+
"build:ts": "sh scripts/build.sh"
1720
},
18-
"main": "lib/index.js",
19-
"module": "es/index.js",
21+
"main": "dist/cjs/index.js",
22+
"module": "dist/esm/index.js",
23+
"types": "types",
2024
"files": [
21-
"lib",
22-
"es",
23-
"dist"
25+
"dist",
26+
"types",
27+
"src"
2428
],
2529
"dependencies": {
2630
"@ant-design/icons": "^4.0.0-alpha.19",
@@ -34,8 +38,11 @@
3438
"enquire.js": "^2.1.6",
3539
"lodash": "^4.17.15",
3640
"resize-observer-polyfill": "^1.5.1",
41+
"rollup-plugin-ts": "^3.2.0",
3742
"shallowequal": "^1.1.0",
38-
"tinycolor2": "^1.4.1"
43+
"tinycolor2": "^1.4.1",
44+
"ts-loader": "^8.2.0",
45+
"typescript": "^4.8.4"
3946
},
4047
"husky": {
4148
"hooks": {
@@ -60,6 +67,7 @@
6067
"@babel/traverse": "^7.4.4",
6168
"@babel/types": "^7.4.4",
6269
"@octokit/rest": "^16.35.2",
70+
"@types/lodash": "^4.14.195",
6371
"autoprefixer": "^9.5.1",
6472
"babel-cli": "^6.26.0",
6573
"babel-eslint": "^10.0.3",
@@ -115,17 +123,18 @@
115123
"querystring": "^0.2.0",
116124
"rd": "^2.0.1",
117125
"rimraf": "^2.6.3",
118-
"rollup": "^1.27.0",
119-
"rollup-plugin-babel": "^4.3.3",
126+
"rollup": "^2.60.0",
127+
"rollup-plugin-babel": "^4.4.0",
120128
"rollup-plugin-banner": "^0.2.1",
121129
"rollup-plugin-commonjs": "^10.1.0",
122130
"rollup-plugin-node-resolve": "^5.2.0",
123131
"rollup-plugin-peer-deps-external": "^2.2.0",
124132
"rollup-plugin-postcss": "^2.0.3",
125133
"rollup-plugin-svgo": "^1.1.0",
126134
"rollup-plugin-terser": "^5.1.2",
135+
"rollup-plugin-typescript2": "^0.35.0",
127136
"rucksack-css": "^1.0.2",
128-
"san": "^3.10.1",
137+
"san": "^3.12.2",
129138
"san-hot-reload-api": "^1.0.1",
130139
"san-loader": "^0.2.0",
131140
"san-router": "^1.2.0",

scripts/build.sh

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
# 清空编译产物
4+
rm -rf dist types
5+
6+
# 编译 ts
7+
pnpm build:esm
8+
pnpm build:cjs

scripts/lib/rollup.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const commonjs = require('rollup-plugin-commonjs');
1414
const {terser} = require('rollup-plugin-terser');
1515
const svgo = require('rollup-plugin-svgo');
1616
const cssnano = require('cssnano');
17+
const rpt = require('rollup-plugin-ts');
1718

1819
module.exports = async (dest, src) => {
1920
const inputOptions = {
@@ -25,16 +26,26 @@ module.exports = async (dest, src) => {
2526
extract: true,
2627
use: [['less', {javascriptEnabled: true}]]
2728
}),
29+
svgo(),
30+
rpt(),
2831
resolve(),
2932
commonjs(),
30-
svgo(),
3133
babel({
3234
presets: ['@babel/preset-env'],
3335
plugins: [
3436
'babel-plugin-transform-object-assign'
3537
]
3638
})
37-
]
39+
],
40+
onwarn: function(warning, handler) {
41+
// Skip certain warnings
42+
43+
// should intercept ... but doesn't in some rollup versions
44+
if ( warning.code === 'THIS_IS_UNDEFINED' ) { return; }
45+
46+
// console.warn everything else
47+
handler( warning );
48+
}
3849
};
3950

4051
const outputMin = {
@@ -50,7 +61,8 @@ module.exports = async (dest, src) => {
5061
file: path.join(dest, 'santd.js'),
5162
name: 'santd',
5263
exports: 'named',
53-
format: 'umd'
64+
format: 'umd',
65+
// sourcemap: true,
5466
};
5567
const bundle = await rollup(inputOptions);
5668
await bundle.write(outputMin);

scripts/preview.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ if (componentName && fs.pathExistsSync(resolve(`./src/${componentName}`))) {
5555

5656
function start(componentName) {
5757
return new Promise((resolve, reject) => {
58-
const entry = `src/${componentName}/docs/index.js`;
58+
const entry = `src/${componentName}/docs/index`;
5959
let config = merge(webpackConfig, {
6060
resolve: {
6161
alias: {

scripts/release.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ async function genFiles(dest, src, version, pkg) {
274274
}
275275

276276
console.log('starting package all in one file...');
277-
await rollup(path.join(dest, 'dist'), path.join(src, 'index.js'));
277+
await rollup(path.join(dest, 'dist'), path.join(src, 'index.ts'));
278278
}
279279

280280
main();

scripts/webpack.base.conf.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ module.exports = {
2020
filename: '[name].js'
2121
},
2222
resolve: {
23-
extensions: ['.js', '.san', '.less'],
23+
extensions: ['.js', '.san', '.less', '.ts', '.tsx'],
2424
alias: {
25-
san: isProduction ? 'san/dist/san.spa.min.js' : 'san/dist/san.spa.dev.js',
25+
'san': isProduction ? 'san/dist/san.spa.min.js' : 'san/dist/san.spa.dev.js',
2626
'santd/es': resolve('./src'),
27-
santd: resolve('./src')
27+
'santd': resolve('./src')
2828
}
2929
},
3030
module: {
@@ -114,7 +114,12 @@ module.exports = {
114114
use: {
115115
loader: 'file-loader'
116116
}
117-
}
117+
},
118+
{
119+
test: /\.tsx?$/,
120+
use: 'ts-loader',
121+
exclude: /node_modules/,
122+
},
118123
]
119124
},
120125
plugins: [

src/affix/docs/index.js src/affix/docs/index.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
* @file docs入口文件
33
*/
44

5-
import san from 'san';
5+
import Base from 'santd/base';
66
import Head from './head.md';
77
import Readme from '../README.md';
88
import Basic from './basic.md';
99
import OffsetTop from './offsetTop.md';
1010
import Target from './target.md';
1111

12-
export default san.defineComponent({
13-
components: {
12+
export default class extends Base {
13+
static components = {
1414
head: Head,
1515
basic: Basic,
1616
readme: Readme,
1717
offset: OffsetTop,
1818
target: Target
19-
},
20-
template: `
19+
}
20+
static template = `
2121
<div>
2222
<head/>
2323
<basic/>
@@ -26,4 +26,4 @@ export default san.defineComponent({
2626
<readme/>
2727
</div>
2828
`
29-
});
29+
};

src/affix/index.js src/affix/index.ts

+21-25
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,59 @@
33
* @author fuqiangqiang <[email protected]>
44
*/
55

6-
import san, {DataTypes} from 'san';
6+
import Base from 'santd/base';
77
import {classCreator} from '../core/util';
88
import {on, off, getScrollTop, getOffset} from '../core/util/dom';
99
import './style/index';
10+
import {State, Props, ObjectDetail, Scroller} from './interface'
1011

1112
const outerCls = classCreator('affix-outer')();
1213
const innerCls = classCreator('affix')();
1314

14-
export default san.defineComponent({
15-
dataTypes: {
16-
offsetTop: DataTypes.oneOfType([DataTypes.string, DataTypes.number]),
17-
offsetBottom: DataTypes.oneOfType([DataTypes.string, DataTypes.number]),
18-
target: DataTypes.func
19-
},
20-
21-
initData() {
15+
export default class Affix extends Base<State, Props> {
16+
_scroller: Scroller;
17+
initData(): State {
2218
return {
2319
affix: false,
2420
styles: {},
2521
offsetTop: 0,
22+
offsetBottom: 0,
2623
outerStyles: {}
2724
};
28-
},
25+
}
2926
attached() {
3027
if (!this._scroller) {
3128
this._scroller = this.handleScroll.bind(this);
3229

33-
const target = this.data.get('target');
30+
const target: any = this.data.get('target');
3431
const element = target ? target() : window;
3532
on(element, 'scroll', this._scroller);
3633
on(element, 'resize', this._scroller);
3734
}
38-
},
35+
}
3936

40-
disposed() {
37+
disposed(): void {
4138
if (this._scroller) {
4239
const target = this.data.get('target');
43-
const element = target ? target() : window;
40+
const element: any = target ? target() : window;
4441
off(element, 'scroll', this._scroller);
4542
off(element, 'resize', this._scroller);
46-
this._scroller = null;
43+
this._scroller = null as unknown as Scroller;
4744
}
48-
},
45+
}
4946

5047
handleScroll() {
51-
const target = this.data.get('target');
48+
const target: any = this.data.get('target');
5249
const targetOffset = target && getOffset(target());
5350
const elOffset = getOffset(this.el);
5451
const scrollTop = getScrollTop();
55-
const innerEl = this.ref('inner');
56-
57-
let offsetTop = +this.data.get('offsetTop');
58-
let offsetBottom = +this.data.get('offsetBottom');
52+
const innerEl: any = this.ref('inner');
53+
let offsetTop = this.data.get('offsetTop') || 0;
54+
let offsetBottom = this.data.get('offsetBottom') || 0;
5955
let isAffixBottom = offsetBottom >= 0;
6056

6157
let affixTo = null;
62-
let styles = {};
58+
let styles: ObjectDetail = {};
6359
let outerStyles = {};
6460

6561
if (isAffixBottom) {
@@ -106,13 +102,13 @@ export default san.defineComponent({
106102
this.data.set('affix', affixTo);
107103
this.fire('change', affixTo);
108104
}
109-
},
105+
}
110106

111-
template: `
107+
static template = `
112108
<div class="${outerCls}" style="{{outerStyles}}">
113109
<div class="{{affix ? '${innerCls}' : ''}}" style="{{styles}}" s-ref="inner">
114110
<slot></slot>
115111
</div>
116112
</div>
117113
`
118-
});
114+
};

src/affix/interface.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export type Target = () => HTMLElement | Window;
2+
3+
export type ObjectDetail = {[key: string]: string};
4+
5+
export type Scroller = (() => void) | null | undefined;
6+
7+
export interface State {
8+
offsetBottom?: number;
9+
offsetTop?: number;
10+
affix?: boolean;
11+
styles?: ObjectDetail;
12+
outerStyles?: ObjectDetail;
13+
14+
}
15+
16+
export interface Props {
17+
offsetBottom?: number;
18+
offsetTop?: number;
19+
target?: Target;
20+
styles?: ObjectDetail;
21+
}
File renamed without changes.

src/alert/docs/index.js src/alert/docs/index.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
/**
2-
* @file 组件 alert
3-
* @author baozhixin <[email protected]>
4-
*/
2+
* @file Santd backtop docs file
3+
**/
54

6-
import san from 'san';
75
import Head from './head.md';
86
import Basic from './basic.md';
97
import Style from './style.md';
@@ -15,10 +13,10 @@ import Banner from './banner.md';
1513
import Smooth from './smooth-closed.md';
1614
import Custom from './custom-icon.md';
1715
import Readme from '../README.md';
18-
import './index.less';
16+
import Base from 'santd/base';
1917

20-
export default san.defineComponent({
21-
template: `
18+
export default class extends Base {
19+
static template = `
2220
<div>
2321
<head/>
2422
<basic/>
@@ -32,8 +30,9 @@ export default san.defineComponent({
3230
<custom/>
3331
<readme/>
3432
</div>
35-
`,
36-
components: {
33+
`;
34+
35+
static components = {
3736
head: Head,
3837
basic: Basic,
3938
style: Style,
@@ -45,5 +44,5 @@ export default san.defineComponent({
4544
smooth: Smooth,
4645
custom: Custom,
4746
readme: Readme
48-
}
49-
});
47+
};
48+
};

0 commit comments

Comments
 (0)