Skip to content

Commit ed53732

Browse files
committed
fix: 修复当schmea中包含计算属性时不能激活关联计算的问题
1 parent 510bbf4 commit ed53732

File tree

10 files changed

+258
-50
lines changed

10 files changed

+258
-50
lines changed

docs/public/autoform.js

Lines changed: 19 additions & 19 deletions
Large diffs are not rendered by default.

docs/public/autostore.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/src/schema/manager.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,17 @@ export class SchemaManager<
6262

6363
this._descriptors[key] = finalDescriptor;
6464

65-
// if (this.shadow && descriptor.value !== undefined) {
66-
// this.shadow.update(
67-
// (state) => {
68-
// setVal(state, pathKey, descriptor.value);
69-
// },
70-
// {
71-
// validate: "pass",
72-
// silent: true,
73-
// },
74-
// );
75-
// }
65+
if (this.shadow && descriptor.value !== undefined) {
66+
this.shadow.update(
67+
(state) => {
68+
setVal(state, pathKey, descriptor.value);
69+
},
70+
{
71+
validate: "pass",
72+
silent: true,
73+
},
74+
);
75+
}
7676
return descriptor;
7777
}
7878
/**

packages/core/src/schema/schema.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@ function parseSchemaOptions(args: any[]): SchemaArgs {
9191
}
9292

9393
export const schema = function () {
94-
// const [initial, options] =
95-
// arguments.length === 1 && typeof arguments[0] === "object" && !Array.isArray(arguments[0])
96-
// ? [undefined, arguments[0]]
97-
// : [...arguments];
9894
const initial = arguments[0];
9995
const options = arguments[1];
10096
const args = parseSchemaOptions([initial, options]);

packages/core/src/store/store.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ export class AutoStore<State extends Dict> extends EventEmitter<StoreEvents> {
9191
private _batching = false; // 是否批量更新中
9292
private _batchOperates: StateOperate[] = []; // 暂存批量操作
9393
private _updateFlags: number = 0; // 额外的更新标识
94-
private _safeTraverse: boolean = false; // 安全遍历对象不触发可观察对象的创建
9594
private _peeping: boolean = false;
9695

9796
// biome-ignore lint/correctness/noUnusedPrivateClassMembers: <noUnusedPrivateClassMembers>
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
import { customElement, query } from "lit/decorators.js";
2+
import { LitElement, PropertyValues, html } from "lit";
3+
import { AutoStore, configurable } from "autostore";
4+
5+
@customElement("add-contact")
6+
class AddContacyForm extends LitElement {
7+
store = new AutoStore({
8+
type: configurable(2, {
9+
size: "small",
10+
label: "类型",
11+
required: true,
12+
widget: "radio",
13+
select: [
14+
{
15+
id: 1,
16+
label: "个人",
17+
value: 1,
18+
},
19+
{
20+
id: 2,
21+
label: "部门",
22+
value: 2,
23+
},
24+
],
25+
}),
26+
// name: configurable("", {
27+
// label: "姓名",
28+
// required: true,
29+
// placeholder: "请输入联系人姓名/部门名称",
30+
// onValidate: (value: string) => {
31+
// return value.length > 1;
32+
// },
33+
// invalidTips: "长度过短",
34+
// onFail: "throw",
35+
// }),
36+
// phone: configurable("", {
37+
// label: "号码",
38+
// widget: "phone",
39+
// placeholder: "请输入号码",
40+
// onValidate: (value: string) => {
41+
// return value.length > 1;
42+
// },
43+
// toState: (value: any) => {
44+
// return String(value);
45+
// },
46+
// invalidTips: "长度过短",
47+
// onFail: "throw",
48+
// }),
49+
// avatar: configurable("", {
50+
// label: "头像",
51+
// widget: "upload",
52+
// visible: (state: any) => state.type === 1,
53+
// }),
54+
// description: configurable("", {
55+
// label: "简介",
56+
// placeholder: "请输入简介",
57+
// visible: (state: any) => state.type === 2,
58+
// }),
59+
// post: configurable("", {
60+
// label: "职位",
61+
// placeholder: "请输入职位",
62+
// visible: (state: any) => state.type === 1,
63+
// }),
64+
// pid: configurable("a", {
65+
// label: "部门",
66+
// widget: "select",
67+
// select: ["a", "b", "c"],
68+
// placeholder: "请选择所属部门",
69+
// clearable: false,
70+
// }),
71+
migrateFollow: configurable(1, {
72+
label: "原属于该部门的用户",
73+
labelPos: "top",
74+
widget: "radio",
75+
select: [
76+
{
77+
id: 1,
78+
label: "仍归属于该部门",
79+
value: 1,
80+
},
81+
{
82+
id: 2,
83+
label: "迁移到",
84+
value: 2,
85+
},
86+
],
87+
visible: (state: any) => {
88+
if (state.type === 2) {
89+
return true;
90+
}
91+
return false;
92+
},
93+
}),
94+
// followDepartment: configurable("", {
95+
// label: "新的部门",
96+
// widget: "select",
97+
// clearable: false,
98+
// placeholder: "请选择将所属用户迁移到",
99+
// select: async () => {
100+
// return [];
101+
// },
102+
// visible: (state: any) => {
103+
// return state.migrateFollow === 2;
104+
// },
105+
// }),
106+
});
107+
//@ts-ignore
108+
@query("auto-form")
109+
formRef?: any;
110+
protected updated(_changedProperties: PropertyValues): void {
111+
this.formRef?.bind(this.store);
112+
}
113+
render() {
114+
return html`<div
115+
style="onsting: 1em; var(--auto-border); margin: 1em; position: relative"
116+
>
117+
<auto-form
118+
data-name="general"
119+
group="general"
120+
data-label="常规"
121+
data-icon="settings"
122+
data-actions="settings"
123+
>
124+
</auto-form>
125+
</div>`;
126+
}
127+
}
128+
129+
declare global {
130+
interface HTMLElementTagNameMap {
131+
"add-contact": AddContacyForm;
132+
}
133+
var store: AutoStore<any>;
134+
}

packages/form/examples/index.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
import './general';
2-
import './usepath';
3-
import './transform';
4-
import './group-tabs';
5-
import './group-tabs2';
6-
import './group-collapse';
7-
import './lazy-select';
8-
export * from './debuger';
9-
export * from './store';
1+
import "./general";
2+
import "./usepath";
3+
import "./transform";
4+
import "./group-tabs";
5+
import "./group-tabs2";
6+
import "./group-collapse";
7+
import "./lazy-select";
8+
import "./addContact";
9+
import "./ipConfig";
10+
export * from "./debuger";
11+
export * from "./store";

packages/form/examples/ipConfig.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { customElement, query } from "lit/decorators.js";
2+
import { LitElement, PropertyValues, html } from "lit";
3+
import { AutoStore, configurable } from "autostore";
4+
5+
@customElement("ip-config")
6+
class IPConfigForm extends LitElement {
7+
store = new AutoStore({
8+
network: {
9+
dhcp: configurable(false, {
10+
label: "自动获取IP地址",
11+
widget: "switch",
12+
}),
13+
ip: configurable("192.168.1.100", {
14+
label: "IP地址",
15+
widget: "ipaddress",
16+
enable: (state) => !state.network.dhcp,
17+
}),
18+
mask: configurable("255.255.255.0", {
19+
label: "子网掩码",
20+
widget: "ipaddress",
21+
visible: (state) => !state.network.dhcp,
22+
}),
23+
gateway: configurable("192.168.1.1", {
24+
label: "默认网关",
25+
widget: "ipaddress",
26+
enable: (state) => !state.network.dhcp,
27+
}),
28+
timeout: configurable(100000, {
29+
label: "连接超时(秒)",
30+
group: "api",
31+
widget: "number",
32+
toState: (value: any) => {
33+
return value * 1000;
34+
},
35+
toInput: (value: any) => {
36+
return value / 1000;
37+
},
38+
}),
39+
},
40+
});
41+
//@ts-ignore
42+
@query("auto-form")
43+
formRef?: any;
44+
protected updated(_changedProperties: PropertyValues): void {
45+
this.formRef?.bind(this.store);
46+
}
47+
render() {
48+
return html`<div
49+
style="onsting: 1em; var(--auto-border); margin: 1em; position: relative"
50+
>
51+
<auto-form
52+
data-name="general"
53+
data-label="常规"
54+
data-icon="settings"
55+
data-actions="settings"
56+
>
57+
</auto-form>
58+
</div>`;
59+
}
60+
}
61+
62+
declare global {
63+
interface HTMLElementTagNameMap {
64+
"ip-config": IPConfigForm;
65+
}
66+
var store: AutoStore<any>;
67+
}

packages/form/index.html

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@
2727
<sl-button variant="warning">Red</sl-button>
2828
</div>
2929
<sl-tab-group>
30+
<sl-tab slot="nav" panel="ip">网络配置</sl-tab>
31+
<sl-tab slot="nav" panel="addcontact">增加联系人</sl-tab>
32+
<!-- <sl-tab slot="nav" panel="general">默认</sl-tab> -->
3033
<!-- <sl-tab slot="nav" panel="tabs">tabs分组</sl-tab>-->
31-
<sl-tab slot="nav" panel="select">下拉选择</sl-tab>
32-
<sl-tab slot="nav" panel="general">默认</sl-tab>
34+
<!-- <sl-tab slot="nav" panel="select">下拉选择</sl-tab> -->
3335
<!-- <sl-tab slot="nav" panel="transform">状态转换</sl-tab>
3436
<sl-tab slot="nav" panel="usepath">绑定路径</sl-tab> -->
3537

@@ -88,9 +90,17 @@
8890
<sl-tab-panel name="usepath">
8991
<auto-form-example-path></auto-form-example-path>
9092
</sl-tab-panel> -->
91-
<sl-tab-panel name="select">
92-
<auto-form-lazy-select></auto-form-lazy-select>
93+
94+
<sl-tab-panel name="ip">
95+
<ip-config></ip-config>
96+
</sl-tab-panel>
97+
98+
<sl-tab-panel name="addcontact">
99+
<add-contact></add-contact>
93100
</sl-tab-panel>
101+
<!-- <sl-tab-panel name="select">
102+
<auto-form-lazy-select></auto-form-lazy-select>
103+
</sl-tab-panel> -->
94104
</sl-tab-group>
95105
<script type="module" src="./examples/index.ts"></script>
96106
<script>

packages/form/src/form/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class AutoForm extends LitElement {
5252
seq: number = ++AutoForm.seq;
5353

5454
@provide({ context })
55-
//@ts-ignore
55+
//@ts-expect-error
5656
context: AutoFormContext = {};
5757
schemas: SchemaOptions[] = [];
5858

0 commit comments

Comments
 (0)