Skip to content

Commit 5abece5

Browse files
committed
[optimize] WebField's props & state
[refactor] replace Travis CI with GitHub Actions [add] GitHub Sponsor configuration
1 parent 08559d7 commit 5abece5

10 files changed

Lines changed: 91 additions & 57 deletions

File tree

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
custom:
2+
- https://paypal.me/TechQuery
3+
- https://tech-query.me/image/TechQuery-Alipay.jpg

.github/workflows/main.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: CI & CD
2+
on:
3+
push:
4+
branches:
5+
- v2
6+
jobs:
7+
Build-and-Deploy:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v2
12+
- name: Use Node.js
13+
uses: actions/setup-node@v2-beta
14+
with:
15+
node-version: '14'
16+
- name: Install & build
17+
run: |
18+
npm install
19+
npm run build
20+
- name: Deploy
21+
uses: peaceiris/actions-gh-pages@v3
22+
with:
23+
publish_dir: ./docs
24+
personal_token: ${{ secrets.GITHUB_TOKEN }}
25+
force_orphan: true

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ test/
33
.cache/
44
Contributing.md
55
docs/
6-
.travis.yml
6+
.github/
77
.vscode/
88
MobX/

.travis.yml

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

MobX/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobx-web-cell",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"license": "LGPL-3.0",
55
"author": "shiy2008@gmail.com",
66
"description": "MobX adaptor for WebCell v2",
@@ -24,7 +24,7 @@
2424
},
2525
"dependencies": {
2626
"mobx": ">4.0.0 <6.0.0",
27-
"web-cell": "^2.2.0"
27+
"web-cell": "^2.3.0-beta.4"
2828
},
2929
"devDependencies": {
3030
"@types/jest": "^26.0.19",

ReadMe.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ We recommend these libraries to use with WebCell:
213213

214214
## Roadmap
215215

216+
- [ ] [Extend **Build-in Elements** with Virtual DOM](https://github.com/snabbdom/snabbdom/pull/829)
216217
- [ ] [Server-side Render](https://web.dev/declarative-shadow-dom/)
217218

218219
Go to [contribute][21]!

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "web-cell",
3-
"version": "2.3.0-beta.1",
3+
"version": "2.3.0-beta.4",
44
"description": "Web Components engine based on JSX & TypeScript",
55
"keywords": [
66
"web",
@@ -23,7 +23,7 @@
2323
"source": "source/index.ts",
2424
"types": "dist/index.d.ts",
2525
"dependencies": {
26-
"web-utility": "^2.1.1"
26+
"web-utility": "^2.2.1"
2727
},
2828
"peerDependencies": {
2929
"@webcomponents/webcomponentsjs": "^2.5.0",
@@ -34,10 +34,10 @@
3434
"@types/core-js": "^2.5.4",
3535
"@types/jest": "^26.0.19",
3636
"@types/jsdom": "^16.2.5",
37-
"@typescript-eslint/parser": "^4.10.0",
37+
"@typescript-eslint/parser": "^4.11.0",
3838
"element-internals-polyfill": "0.1.1",
39-
"eslint": "^7.15.0",
40-
"eslint-config-prettier": "^7.0.0",
39+
"eslint": "^7.16.0",
40+
"eslint-config-prettier": "^7.1.0",
4141
"eslint-plugin-prettier": "^3.3.0",
4242
"husky": "^4.3.6",
4343
"jest": "^26.6.3",

source/WebCell.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export type WebCellFunction<P extends WebCellProps = WebCellProps> = (
1717

1818
export interface WebCellComponent<P extends WebCellProps = WebCellProps, S = {}>
1919
extends CustomElement {
20+
root: DocumentFragment | Element;
2021
update(): void;
2122
props: P;
2223
setProps(data: Partial<P>): Promise<any>;
@@ -54,7 +55,7 @@ export function mixin<P extends WebCellProps = WebCellProps, S = {}>(
5455
static attributes: string[] = [];
5556
static eventDelegaters: DOMEventDelegater[] = [];
5657

57-
private root: DocumentFragment | Element;
58+
readonly root: DocumentFragment | Element;
5859
private CSS?: VNode;
5960
private vTree: WebCellElement;
6061
private tick?: Promise<void>;

source/WebField.ts

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,83 @@
11
import type {} from 'element-internals-polyfill';
2+
import { ElementInternals } from 'element-internals-polyfill/dist/element-internals';
23
import { Constructor } from 'web-utility/source/data';
34
import { BaseFieldProps, CustomFormElement } from 'web-utility/source/DOM-type';
45

56
import { WebCellProps } from './utility';
67
import { mixin, WebCellComponent } from './WebCell';
7-
import { watch, attribute } from './decorator';
8+
import { attribute } from './decorator';
89

910
export interface WebFieldProps extends BaseFieldProps, WebCellProps {}
1011

11-
export type WebFieldComponent<
12+
export interface WebFieldState {
13+
disabled?: boolean;
14+
}
15+
16+
export interface WebFieldComponent<
1217
P extends WebFieldProps = WebFieldProps,
1318
S = {}
14-
> = CustomFormElement & WebCellComponent<P, S>;
19+
> extends CustomFormElement,
20+
WebCellComponent<P, S> {
21+
internals: ElementInternals;
22+
}
1523

1624
export type WebFieldClass<
1725
P extends WebFieldProps = WebFieldProps,
1826
S = {}
1927
> = Constructor<WebFieldComponent<P, S>>;
2028

21-
export function mixinForm<P extends WebFieldProps = WebFieldProps, S = {}>(
22-
superClass: Constructor<HTMLElement> = HTMLElement
23-
): WebFieldClass<P, S> {
24-
class WebField
25-
extends mixin<P, S>(superClass)
26-
implements WebFieldComponent<P, S> {
29+
export function mixinForm<
30+
P extends WebFieldProps = WebFieldProps,
31+
S extends WebFieldState = WebFieldState
32+
>(): WebFieldClass<P, S> {
33+
class WebField extends mixin<P, S>() implements WebFieldComponent<P, S> {
2734
static formAssociated = true;
2835

29-
@attribute
30-
@watch
31-
name: string;
36+
readonly internals = this.attachInternals();
3237

33-
@watch
34-
value: string;
38+
formDisabledCallback(disabled: boolean) {
39+
this.setState({ disabled } as Partial<S>);
40+
}
3541

3642
@attribute
37-
@watch
38-
required: boolean;
43+
set name(name: string) {
44+
this.setProps({ name } as Partial<P>);
45+
}
46+
get name() {
47+
return this.props.name;
48+
}
49+
50+
set value(value: string) {
51+
this.setProps({ value } as Partial<P>);
52+
this.internals.setFormValue(value);
53+
}
54+
get value() {
55+
return this.props.value;
56+
}
3957

4058
@attribute
41-
@watch
42-
disabled: boolean;
59+
set required(required: boolean) {
60+
this.setProps({ required } as Partial<P>);
61+
}
62+
get required() {
63+
return this.props.required;
64+
}
4365

4466
@attribute
45-
@watch
46-
placeholder: string;
67+
set disabled(disabled: boolean) {
68+
this.setProps({ disabled } as Partial<P>);
69+
}
70+
get disabled() {
71+
return this.props.disabled;
72+
}
4773

4874
@attribute
49-
@watch
50-
autofocus: boolean;
75+
set autofocus(autofocus: boolean) {
76+
this.setProps({ autofocus } as Partial<P>);
77+
}
78+
get autofocus() {
79+
return this.props.autofocus;
80+
}
5181

5282
set defaultValue(raw: string) {
5383
this.setAttribute('value', raw);
@@ -59,8 +89,6 @@ export function mixinForm<P extends WebFieldProps = WebFieldProps, S = {}>(
5989
return this.getAttribute('value');
6090
}
6191

62-
protected internals = this.attachInternals();
63-
6492
get form() {
6593
return this.internals.form;
6694
}

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"declaration": true,
77
"allowJs": true,
88
"noImplicitReturns": true,
9-
"noImplicitAny": true,
109
"downlevelIteration": true,
1110
"module": "ES6",
1211
"moduleResolution": "Node",

0 commit comments

Comments
 (0)