Skip to content

Commit 487fdee

Browse files
committed
Removed extra subpackage 'types' ... plus minor changes
1 parent 15a5307 commit 487fdee

16 files changed

+315
-66
lines changed

.storybook/webpack.config.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ module.exports = ({ config }) => {
1818
__dirname,
1919
'../src/main/js-elements-hooks.ts'
2020
)
21-
alias['js-elements/types$'] = path.resolve(
22-
__dirname,
23-
'../src/main/js-elements-types.ts'
24-
)
2521
alias['js-elements/utils$'] = path.resolve(
2622
__dirname,
2723
'../src/main/js-elements-utils.ts'

package.json

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "js-elements",
3-
"version": "0.1.3",
3+
"version": "0.1.5",
44
"description": "",
55
"main": "./index.js",
66
"module": "./dist/js-elements.esm.production.js",
@@ -66,41 +66,20 @@
6666
"require": "./dist/js-elements-utils.cjs.production.js"
6767
}
6868
},
69-
"./types": {
70-
"development": {
71-
"browser": "./dist/js-elements-types.umd.development.js",
72-
"umd": "./dist/js-elements-types.umd.development.js",
73-
"import": "./dist/js-elements-types.esm.development.js",
74-
"require": "./dist/js-elements-types.cjs.development.js"
75-
},
76-
"production": {
77-
"browser": "./dist/js-elements-types.umd.production.js",
78-
"umd": "./dist/js-elements-types.umd.production.js",
79-
"import": "./dist/js-elements-types.esm.production.js",
80-
"require": "./dist/js-elements-types.cjs.production.js"
81-
},
82-
"default": {
83-
"browser": "./dist/js-elements-types.umd.production.js",
84-
"umd": "./dist/js-elements-types.umd.production.js",
85-
"import": "./dist/js-elements-types.esm.production.js",
86-
"require": "./dist/js-elements-types.cjs.production.js"
87-
}
88-
},
8969
"./package.json": "./package.json",
9070
"./": "./"
9171
},
9272
"files": [
9373
"dist",
9474
"hooks",
95-
"utils",
96-
"types"
75+
"utils"
9776
],
9877
"scripts": {
9978
"clean": "shx rm -rf ./build ./dist",
10079
"test": "echo \"Error: no test specified\" && exit 1",
10180
"storybook": "start-storybook -p 6006",
10281
"build-storybook": "build-storybook",
103-
"build": "npm run clean && cross-env NODE_OPTIONS=--max_old_space_size=4096 rollup --c rollup.config.js && tsc -p tsconfig.dist.json -d --emitDeclarationOnly --declarationDir dist/types",
82+
"build": "npm run clean && cross-env NODE_OPTIONS=--max_old_space_size=4096 rollup --c rollup.config.js && tsc -p tsconfig.dist.json -d --emitDeclarationOnly --declarationDir dist/types && shx cp ./src/main/jsx.d.ts ./dist/types",
10483
"dist": "npm run build && npm run zipsource",
10584
"zipsource": "shx rm -rf ./build/source && shx mkdir -p ./build/source && copyfiles -a ./* ./build/source && shx cp -r ./src ./build/source && shx mkdir -p ./dist/source && cd build && bestzip --force node ../dist/source/source.zip source && cd .."
10685
},
@@ -123,7 +102,7 @@
123102
"bestzip": "^2.1.7",
124103
"copyfiles": "^2.4.1",
125104
"cross-env": "^7.0.3",
126-
"eslint": "^7.16.0",
105+
"eslint": "^7.17.0",
127106
"htm": "^3.0.4",
128107
"html-webpack-plugin": "^5.0.0-alpha.17",
129108
"js-immutables": "^0.0.5",
@@ -140,7 +119,7 @@
140119
"rollup-plugin-typescript2": "^0.29.0",
141120
"rxjs": "^6.6.3",
142121
"shx": "^0.3.3",
143-
"ts-loader": "^8.0.12",
122+
"ts-loader": "^8.0.13",
144123
"ts-node": "^9.1.1",
145124
"typescript": "^4.1.3"
146125
}

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import gzip from 'rollup-plugin-gzip'
77

88
const configs = []
99

10-
for (const pkg of ['root', 'hooks', 'utils', 'types']) {
10+
for (const pkg of ['root', 'hooks', 'utils']) {
1111
for (const format of ['esm', 'umd', 'cjs']) {
1212
for (const productive of [false, true]) {
1313
configs.push(createConfig(pkg, format, productive))

src/main/js-elements-types.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/main/js-elements.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
export { define, attr } from './core/base'
22
export { h, html, render } from './core/vdom'
3+
4+
export {
5+
Component,
6+
EventHandler,
7+
MethodsOf,
8+
Ref,
9+
UIEvent,
10+
VNode,
11+
VElement
12+
} from './core/types'

src/main/jsx.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Props, VElement } from './core/types'
1+
export type Props = Record<string, any> // TODO
2+
export type VElement<T extends Props = Props> = Record<any, any> // TODO
23

34
export = JSX
45

src/stories/demos/button-demo.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { attr, define, h } from 'js-elements'
1+
import { attr, define, h, EventHandler, UIEvent } from 'js-elements'
22
import { useEmitter, useStyles } from 'js-elements/hooks'
3-
import { EventHandler, UIEvent } from 'js-elements/types'
43
import { createEvent } from 'js-elements/utils'
54

65
const buttonDemoStyles = `

src/stories/demos/complex-counter-demo.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { define, h } from 'js-elements'
1+
import { define, h, MethodsOf, EventHandler, Ref, UIEvent } from 'js-elements'
22
import { createEvent, createRef } from 'js-elements/utils'
3-
import { EventHandler, MethodsOf, Ref, UIEvent } from 'js-elements/types'
43

54
import {
65
useEffect,
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { define, h, VNode } from 'js-elements'
2+
import { useRefresher, useInterval, useStyles } from 'js-elements/hooks'
3+
4+
export default define('data-table-demo', () => {
5+
return () => <DataTable />
6+
})
7+
8+
type DataTableViewModel = {
9+
columns: {
10+
title: string
11+
}[]
12+
}
13+
14+
const DataTable = define('jsc-data-table', () => {
15+
const refresh = useRefresher()
16+
17+
const viewModel: DataTableViewModel = {
18+
columns: [
19+
{ title: 'Column 1' },
20+
{ title: 'Column 2' },
21+
{ title: 'Column 3' },
22+
{ title: 'Column 4' },
23+
{ title: 'Column 5' },
24+
{ title: 'Column 6' },
25+
{ title: 'Column 7' },
26+
{ title: 'Column 8' }
27+
]
28+
}
29+
30+
useStyles(dataTableStyles)
31+
useInterval(refresh, 1000)
32+
33+
return () => {
34+
return renderTable(viewModel)
35+
}
36+
})
37+
38+
function renderTable(viewModel: DataTableViewModel): VNode {
39+
const tableHeader = renderTableHeader(viewModel)
40+
const tableBody = renderTableBody(viewModel)
41+
42+
return (
43+
<table>
44+
{tableHeader}
45+
{tableBody}
46+
</table>
47+
)
48+
}
49+
50+
function renderTableHeader(viewModel: DataTableViewModel): VNode {
51+
const headerColumns: VNode[] = []
52+
53+
for (const column of viewModel.columns) {
54+
headerColumns.push(<th>{column.title}</th>)
55+
}
56+
57+
return (
58+
<thead>
59+
<tr>{headerColumns}</tr>
60+
</thead>
61+
)
62+
}
63+
64+
function renderTableBody(viewModel: DataTableViewModel) {
65+
const rows: VNode[] = []
66+
67+
for (let i = 0; i < 100; ++i) {
68+
const cols: VNode[] = []
69+
70+
rows.push(<tr>{cols}</tr>)
71+
72+
for (let j = 0; j < viewModel.columns.length; ++j) {
73+
cols.push(<td>{Math.floor(Math.random() * 10000)}</td>)
74+
}
75+
}
76+
77+
return <tbody>{rows}</tbody>
78+
}
79+
80+
// === styles ========================================================
81+
82+
const dataTableStyles = `
83+
table {
84+
border: 1px solid black;
85+
}
86+
87+
table tbody tr td {
88+
border-width: 0 0 1px 0;
89+
border-color: gray;
90+
border-width: 1px;
91+
}
92+
`

src/stories/demos/date-picker.tsx

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { attr, define, h, VNode } from 'js-elements'
2+
import { useState, useStyles } from 'js-elements/hooks'
3+
4+
export default define('date-picker-demo', () => {
5+
return () => <DatePicker />
6+
})
7+
8+
// === types ========================================================
9+
10+
type DatePickerViewModel = {
11+
firstDayOfWeek: number
12+
showWeekNumbers: boolean
13+
shownYear: number
14+
shownMonth: number
15+
}
16+
17+
// === DatePicker ====================================================
18+
19+
class DatePickerProps {}
20+
21+
const DatePicker = define('jsc-date-picker', DatePickerProps, (p) => {
22+
const [s, set] = useState({
23+
selectedDate: new Date()
24+
})
25+
26+
useStyles(datePickerStyles)
27+
28+
return () => {
29+
const model: DatePickerViewModel = {
30+
firstDayOfWeek: 0,
31+
showWeekNumbers: true,
32+
shownMonth: 11,
33+
shownYear: 2020
34+
}
35+
36+
return renderCalendar(model)
37+
}
38+
})
39+
40+
function renderCalendar(model: DatePickerViewModel): VNode {
41+
const rows: VNode[] = []
42+
43+
const ret = (
44+
<table>
45+
<tbody>{rows}</tbody>
46+
</table>
47+
)
48+
49+
for (let weekIdx = 0; weekIdx < 5; ++weekIdx) {
50+
const cols: VNode[] = []
51+
52+
rows.push(<tr>{cols}</tr>)
53+
54+
for (let dayIdx = 0; dayIdx < 7; ++dayIdx) {
55+
const dayOfMonth = new Date(model.shownYear, model.shownMonth, 1)
56+
57+
cols.push(<td>{dayOfMonth}</td>)
58+
}
59+
}
60+
61+
return ret
62+
}
63+
64+
const datePickerStyles = `
65+
66+
`

0 commit comments

Comments
 (0)