@tachybase/schema 0.23.41 → 0.23.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/core/effects/index.d.ts +2 -0
- package/lib/core/effects/index.js +23 -0
- package/lib/core/effects/onFieldEffects.d.ts +27 -0
- package/lib/core/effects/onFieldEffects.js +158 -0
- package/lib/core/effects/onFormEffects.d.ts +24 -0
- package/lib/core/effects/onFormEffects.js +117 -0
- package/lib/core/global.d.js +0 -0
- package/lib/core/index.d.ts +4 -0
- package/lib/core/index.js +27 -0
- package/lib/core/models/ArrayField.d.ts +17 -0
- package/lib/core/models/ArrayField.js +145 -0
- package/lib/core/models/BaseField.d.ts +72 -0
- package/lib/core/models/BaseField.js +285 -0
- package/lib/core/models/Field.d.ts +70 -0
- package/lib/core/models/Field.js +426 -0
- package/lib/core/models/Form.d.ts +102 -0
- package/lib/core/models/Form.js +483 -0
- package/lib/core/models/Graph.d.ts +8 -0
- package/lib/core/models/Graph.js +77 -0
- package/lib/core/models/Heart.d.ts +16 -0
- package/lib/core/models/Heart.js +91 -0
- package/lib/core/models/LifeCycle.d.ts +14 -0
- package/lib/core/models/LifeCycle.js +64 -0
- package/lib/core/models/ObjectField.d.ts +12 -0
- package/lib/core/models/ObjectField.js +64 -0
- package/lib/core/models/Query.d.ts +18 -0
- package/lib/core/models/Query.js +105 -0
- package/lib/core/models/VoidField.d.ts +14 -0
- package/lib/core/models/VoidField.js +117 -0
- package/lib/core/models/index.d.ts +9 -0
- package/lib/core/models/index.js +37 -0
- package/lib/core/models/types.d.ts +9 -0
- package/lib/core/models/types.js +15 -0
- package/lib/core/shared/checkers.d.ts +117 -0
- package/lib/core/shared/checkers.js +109 -0
- package/lib/core/shared/constants.d.ts +48 -0
- package/lib/core/shared/constants.js +86 -0
- package/lib/core/shared/effective.d.ts +9 -0
- package/lib/core/shared/effective.js +91 -0
- package/lib/core/shared/externals.d.ts +8 -0
- package/lib/core/shared/externals.js +87 -0
- package/lib/core/shared/internals.d.ts +54 -0
- package/lib/core/shared/internals.js +956 -0
- package/lib/core/types.d.ts +275 -0
- package/lib/core/types.js +76 -0
- package/lib/grid/index.d.ts +67 -0
- package/lib/grid/index.js +378 -0
- package/lib/grid/observer.d.ts +19 -0
- package/lib/grid/observer.js +107 -0
- package/lib/index.d.ts +12 -24
- package/lib/index.js +27 -244
- package/lib/json-schema/compiler.d.ts +8 -0
- package/lib/json-schema/compiler.js +129 -0
- package/lib/json-schema/global.d.js +0 -0
- package/lib/json-schema/index.d.ts +2 -0
- package/lib/json-schema/index.js +23 -0
- package/lib/json-schema/patches.d.ts +5 -0
- package/lib/json-schema/patches.js +68 -0
- package/lib/json-schema/polyfills/SPECIFICATION_1_0.d.ts +2 -0
- package/lib/json-schema/polyfills/SPECIFICATION_1_0.js +132 -0
- package/lib/json-schema/polyfills/index.d.ts +1 -0
- package/lib/json-schema/polyfills/index.js +21 -0
- package/lib/json-schema/schema.d.ts +88 -0
- package/lib/json-schema/schema.js +231 -0
- package/lib/json-schema/shared.d.ts +62 -0
- package/lib/json-schema/shared.js +232 -0
- package/lib/json-schema/transformer.d.ts +4 -0
- package/lib/json-schema/transformer.js +238 -0
- package/lib/json-schema/types.d.ts +119 -0
- package/lib/json-schema/types.js +15 -0
- package/lib/path/contexts.d.ts +10 -0
- package/lib/path/contexts.js +49 -0
- package/lib/path/destructor.d.ts +15 -0
- package/lib/path/destructor.js +151 -0
- package/lib/path/index.d.ts +51 -0
- package/lib/path/index.js +513 -0
- package/lib/path/matcher.d.ts +33 -0
- package/lib/path/matcher.js +197 -0
- package/lib/path/parser.d.ts +33 -0
- package/lib/path/parser.js +379 -0
- package/lib/path/shared.d.ts +13 -0
- package/lib/path/shared.js +121 -0
- package/lib/path/tokenizer.d.ts +27 -0
- package/lib/path/tokenizer.js +269 -0
- package/lib/path/tokens.d.ts +27 -0
- package/lib/path/tokens.js +216 -0
- package/lib/path/types.d.ts +88 -0
- package/lib/path/types.js +63 -0
- package/lib/react/components/ArrayField.d.ts +6 -0
- package/lib/react/components/ArrayField.js +44 -0
- package/lib/react/components/ExpressionScope.d.ts +2 -0
- package/lib/react/components/ExpressionScope.js +35 -0
- package/lib/react/components/Field.d.ts +5 -0
- package/lib/react/components/Field.js +45 -0
- package/lib/react/components/FormConsumer.d.ts +2 -0
- package/lib/react/components/FormConsumer.js +36 -0
- package/lib/react/components/FormProvider.d.ts +2 -0
- package/lib/react/components/FormProvider.js +35 -0
- package/lib/react/components/ObjectField.d.ts +6 -0
- package/lib/react/components/ObjectField.js +39 -0
- package/lib/react/components/ReactiveField.d.ts +11 -0
- package/lib/react/components/ReactiveField.js +115 -0
- package/lib/react/components/RecordScope.d.ts +2 -0
- package/lib/react/components/RecordScope.js +65 -0
- package/lib/react/components/RecordsScope.d.ts +2 -0
- package/lib/react/components/RecordsScope.js +43 -0
- package/lib/react/components/RecursionField.d.ts +2 -0
- package/lib/react/components/RecursionField.js +105 -0
- package/lib/react/components/SchemaField.d.ts +41 -0
- package/lib/react/components/SchemaField.js +154 -0
- package/lib/react/components/VoidField.d.ts +5 -0
- package/lib/react/components/VoidField.js +39 -0
- package/lib/react/components/index.d.ts +11 -0
- package/lib/react/components/index.js +41 -0
- package/lib/react/global.d.js +0 -0
- package/lib/react/hooks/index.d.ts +6 -0
- package/lib/react/hooks/index.js +31 -0
- package/lib/react/hooks/useAttach.d.ts +6 -0
- package/lib/react/hooks/useAttach.js +35 -0
- package/lib/react/hooks/useExpressionScope.d.ts +1 -0
- package/lib/react/hooks/useExpressionScope.js +30 -0
- package/lib/react/hooks/useField.d.ts +2 -0
- package/lib/react/hooks/useField.js +32 -0
- package/lib/react/hooks/useFieldSchema.d.ts +2 -0
- package/lib/react/hooks/useFieldSchema.js +32 -0
- package/lib/react/hooks/useForm.d.ts +2 -0
- package/lib/react/hooks/useForm.js +32 -0
- package/lib/react/hooks/useFormEffects.d.ts +2 -0
- package/lib/react/hooks/useFormEffects.js +42 -0
- package/lib/react/hooks/useParentForm.d.ts +2 -0
- package/lib/react/hooks/useParentForm.js +40 -0
- package/lib/react/index.d.ts +5 -0
- package/lib/react/index.js +29 -0
- package/lib/react/shared/connect.d.ts +9 -0
- package/lib/react/shared/connect.js +118 -0
- package/lib/react/shared/context.d.ts +14 -0
- package/lib/react/shared/context.js +74 -0
- package/lib/react/shared/index.d.ts +2 -0
- package/lib/react/shared/index.js +23 -0
- package/lib/react/shared/render.d.ts +2 -0
- package/lib/react/shared/render.js +69 -0
- package/lib/react/types.d.ts +84 -0
- package/lib/react/types.js +15 -0
- package/lib/reactive/action.d.ts +2 -0
- package/lib/reactive/action.js +48 -0
- package/lib/reactive/annotations/box.d.ts +7 -0
- package/lib/reactive/annotations/box.js +76 -0
- package/lib/reactive/annotations/computed.d.ts +12 -0
- package/lib/reactive/annotations/computed.js +154 -0
- package/lib/reactive/annotations/index.d.ts +5 -0
- package/lib/reactive/annotations/index.js +29 -0
- package/lib/reactive/annotations/observable.d.ts +4 -0
- package/lib/reactive/annotations/observable.js +67 -0
- package/lib/reactive/annotations/ref.d.ts +6 -0
- package/lib/reactive/annotations/ref.js +78 -0
- package/lib/reactive/annotations/shallow.d.ts +2 -0
- package/lib/reactive/annotations/shallow.js +67 -0
- package/lib/reactive/array.d.ts +12 -0
- package/lib/reactive/array.js +83 -0
- package/lib/reactive/autorun.d.ts +7 -0
- package/lib/reactive/autorun.js +155 -0
- package/lib/reactive/batch.d.ts +2 -0
- package/lib/reactive/batch.js +40 -0
- package/lib/reactive/checkers.d.ts +10 -0
- package/lib/reactive/checkers.js +60 -0
- package/lib/reactive/environment.d.ts +28 -0
- package/lib/reactive/environment.js +76 -0
- package/lib/reactive/externals.d.ts +10 -0
- package/lib/reactive/externals.js +156 -0
- package/lib/reactive/global.d.js +0 -0
- package/lib/reactive/handlers.d.ts +4 -0
- package/lib/reactive/handlers.js +246 -0
- package/lib/reactive/index.d.ts +10 -0
- package/lib/reactive/index.js +39 -0
- package/lib/reactive/internals.d.ts +17 -0
- package/lib/reactive/internals.js +139 -0
- package/lib/reactive/model.d.ts +3 -0
- package/lib/reactive/model.js +68 -0
- package/lib/reactive/observable.d.ts +9 -0
- package/lib/reactive/observable.js +50 -0
- package/lib/reactive/observe.d.ts +2 -0
- package/lib/reactive/observe.js +58 -0
- package/lib/reactive/reaction.d.ts +21 -0
- package/lib/reactive/reaction.js +278 -0
- package/lib/reactive/tracker.d.ts +7 -0
- package/lib/reactive/tracker.js +63 -0
- package/lib/reactive/tree.d.ts +25 -0
- package/lib/reactive/tree.js +106 -0
- package/lib/reactive/types.d.ts +79 -0
- package/lib/reactive/types.js +21 -0
- package/lib/reactive/untracked.d.ts +4 -0
- package/lib/reactive/untracked.js +29 -0
- package/lib/reactive-react/hooks/index.d.ts +9 -0
- package/lib/reactive-react/hooks/index.js +48 -0
- package/lib/reactive-react/hooks/useCompatEffect.d.ts +2 -0
- package/lib/reactive-react/hooks/useCompatEffect.js +60 -0
- package/lib/reactive-react/hooks/useCompatFactory.d.ts +3 -0
- package/lib/reactive-react/hooks/useCompatFactory.js +74 -0
- package/lib/reactive-react/hooks/useDidUpdate.d.ts +1 -0
- package/lib/reactive-react/hooks/useDidUpdate.js +38 -0
- package/lib/reactive-react/hooks/useForceUpdate.d.ts +1 -0
- package/lib/reactive-react/hooks/useForceUpdate.js +76 -0
- package/lib/reactive-react/hooks/useLayoutEffect.d.ts +2 -0
- package/lib/reactive-react/hooks/useLayoutEffect.js +28 -0
- package/lib/reactive-react/hooks/useObserver.d.ts +2 -0
- package/lib/reactive-react/hooks/useObserver.js +43 -0
- package/lib/reactive-react/index.d.ts +3 -0
- package/lib/reactive-react/index.js +25 -0
- package/lib/reactive-react/observer.d.ts +8 -0
- package/lib/reactive-react/observer.js +64 -0
- package/lib/reactive-react/shared/gc.d.ts +8 -0
- package/lib/reactive-react/shared/gc.js +59 -0
- package/lib/reactive-react/shared/global.d.ts +1 -0
- package/lib/reactive-react/shared/global.js +50 -0
- package/lib/reactive-react/shared/immediate.d.ts +1 -0
- package/lib/reactive-react/shared/immediate.js +40 -0
- package/lib/reactive-react/shared/index.d.ts +2 -0
- package/lib/reactive-react/shared/index.js +23 -0
- package/lib/reactive-react/types.d.ts +14 -0
- package/lib/reactive-react/types.js +15 -0
- package/lib/shared/array.d.ts +35 -0
- package/lib/shared/array.js +189 -0
- package/lib/shared/case.d.ts +6 -0
- package/lib/shared/case.js +39 -0
- package/lib/shared/checkers.d.ts +21 -0
- package/lib/shared/checkers.js +77 -0
- package/lib/shared/clone.d.ts +2 -0
- package/lib/shared/clone.js +97 -0
- package/lib/shared/compare.d.ts +1 -0
- package/lib/shared/compare.js +129 -0
- package/lib/shared/defaults.d.ts +6 -0
- package/lib/shared/defaults.js +63 -0
- package/lib/shared/deprecate.d.ts +1 -0
- package/lib/shared/deprecate.js +42 -0
- package/lib/shared/global.d.ts +1 -0
- package/lib/shared/global.js +50 -0
- package/lib/shared/index.d.ts +16 -0
- package/lib/shared/index.js +51 -0
- package/lib/shared/instanceof.d.ts +1 -0
- package/lib/shared/instanceof.js +36 -0
- package/lib/shared/isEmpty.d.ts +3 -0
- package/lib/shared/isEmpty.js +94 -0
- package/lib/shared/merge.d.ts +12 -0
- package/lib/shared/merge.js +214 -0
- package/lib/shared/middleware.d.ts +4 -0
- package/lib/shared/middleware.js +41 -0
- package/lib/shared/path.d.ts +3 -0
- package/lib/shared/path.js +27 -0
- package/lib/shared/string.d.ts +1 -0
- package/lib/shared/string.js +38 -0
- package/lib/shared/subscribable.d.ts +11 -0
- package/lib/shared/subscribable.js +74 -0
- package/lib/shared/uid.d.ts +1 -0
- package/lib/shared/uid.js +35 -0
- package/lib/validator/formats.d.ts +16 -0
- package/lib/validator/formats.js +40 -0
- package/lib/validator/index.d.ts +4 -0
- package/lib/validator/index.js +27 -0
- package/lib/validator/locale.d.ts +219 -0
- package/lib/validator/locale.js +240 -0
- package/lib/validator/parser.d.ts +5 -0
- package/lib/validator/parser.js +153 -0
- package/lib/validator/registry.d.ts +15 -0
- package/lib/validator/registry.js +116 -0
- package/lib/validator/rules.d.ts +3 -0
- package/lib/validator/rules.js +154 -0
- package/lib/validator/template.d.ts +2 -0
- package/lib/validator/template.js +42 -0
- package/lib/validator/types.d.ts +62 -0
- package/lib/validator/types.js +28 -0
- package/lib/validator/validator.d.ts +2 -0
- package/lib/validator/validator.js +63 -0
- package/package.json +16 -10
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Form_exports = {};
|
|
20
|
+
__export(Form_exports, {
|
|
21
|
+
Form: () => Form
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(Form_exports);
|
|
24
|
+
var import_reactive = require("../../reactive");
|
|
25
|
+
var import_shared = require("../../shared");
|
|
26
|
+
var import_checkers = require("../shared/checkers");
|
|
27
|
+
var import_effective = require("../shared/effective");
|
|
28
|
+
var import_internals = require("../shared/internals");
|
|
29
|
+
var import_types = require("../types");
|
|
30
|
+
var import_ArrayField = require("./ArrayField");
|
|
31
|
+
var import_Field = require("./Field");
|
|
32
|
+
var import_Graph = require("./Graph");
|
|
33
|
+
var import_Heart = require("./Heart");
|
|
34
|
+
var import_ObjectField = require("./ObjectField");
|
|
35
|
+
var import_Query = require("./Query");
|
|
36
|
+
var import_VoidField = require("./VoidField");
|
|
37
|
+
const DEV_TOOLS_HOOK = "__FORMILY_DEV_TOOLS_HOOK__";
|
|
38
|
+
const _Form = class _Form {
|
|
39
|
+
constructor(props) {
|
|
40
|
+
this.displayName = "Form";
|
|
41
|
+
this.fields = {};
|
|
42
|
+
this.requests = {};
|
|
43
|
+
this.indexes = {};
|
|
44
|
+
this.disposers = [];
|
|
45
|
+
/** 创建字段 **/
|
|
46
|
+
this.createField = /* @__PURE__ */ __name((props) => {
|
|
47
|
+
const address = import_shared.FormPath.parse(props.basePath).concat(props.name);
|
|
48
|
+
const identifier = address.toString();
|
|
49
|
+
if (!identifier) return;
|
|
50
|
+
if (!this.fields[identifier] || this.props.designable) {
|
|
51
|
+
(0, import_reactive.batch)(() => {
|
|
52
|
+
new import_Field.Field(address, props, this, this.props.designable);
|
|
53
|
+
});
|
|
54
|
+
this.notify(import_types.LifeCycleTypes.ON_FORM_GRAPH_CHANGE);
|
|
55
|
+
}
|
|
56
|
+
return this.fields[identifier];
|
|
57
|
+
}, "createField");
|
|
58
|
+
this.createArrayField = /* @__PURE__ */ __name((props) => {
|
|
59
|
+
const address = import_shared.FormPath.parse(props.basePath).concat(props.name);
|
|
60
|
+
const identifier = address.toString();
|
|
61
|
+
if (!identifier) return;
|
|
62
|
+
if (!this.fields[identifier] || this.props.designable) {
|
|
63
|
+
(0, import_reactive.batch)(() => {
|
|
64
|
+
new import_ArrayField.ArrayField(
|
|
65
|
+
address,
|
|
66
|
+
{
|
|
67
|
+
...props,
|
|
68
|
+
value: (0, import_shared.isArr)(props.value) ? props.value : []
|
|
69
|
+
},
|
|
70
|
+
this,
|
|
71
|
+
this.props.designable
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
this.notify(import_types.LifeCycleTypes.ON_FORM_GRAPH_CHANGE);
|
|
75
|
+
}
|
|
76
|
+
return this.fields[identifier];
|
|
77
|
+
}, "createArrayField");
|
|
78
|
+
this.createObjectField = /* @__PURE__ */ __name((props) => {
|
|
79
|
+
const address = import_shared.FormPath.parse(props.basePath).concat(props.name);
|
|
80
|
+
const identifier = address.toString();
|
|
81
|
+
if (!identifier) return;
|
|
82
|
+
if (!this.fields[identifier] || this.props.designable) {
|
|
83
|
+
(0, import_reactive.batch)(() => {
|
|
84
|
+
new import_ObjectField.ObjectField(
|
|
85
|
+
address,
|
|
86
|
+
{
|
|
87
|
+
...props,
|
|
88
|
+
value: (0, import_shared.isObj)(props.value) ? props.value : {}
|
|
89
|
+
},
|
|
90
|
+
this,
|
|
91
|
+
this.props.designable
|
|
92
|
+
);
|
|
93
|
+
});
|
|
94
|
+
this.notify(import_types.LifeCycleTypes.ON_FORM_GRAPH_CHANGE);
|
|
95
|
+
}
|
|
96
|
+
return this.fields[identifier];
|
|
97
|
+
}, "createObjectField");
|
|
98
|
+
this.createVoidField = /* @__PURE__ */ __name((props) => {
|
|
99
|
+
const address = import_shared.FormPath.parse(props.basePath).concat(props.name);
|
|
100
|
+
const identifier = address.toString();
|
|
101
|
+
if (!identifier) return;
|
|
102
|
+
if (!this.fields[identifier] || this.props.designable) {
|
|
103
|
+
(0, import_reactive.batch)(() => {
|
|
104
|
+
new import_VoidField.VoidField(address, props, this, this.props.designable);
|
|
105
|
+
});
|
|
106
|
+
this.notify(import_types.LifeCycleTypes.ON_FORM_GRAPH_CHANGE);
|
|
107
|
+
}
|
|
108
|
+
return this.fields[identifier];
|
|
109
|
+
}, "createVoidField");
|
|
110
|
+
/** 状态操作模型 **/
|
|
111
|
+
this.setValues = /* @__PURE__ */ __name((values, strategy = "merge") => {
|
|
112
|
+
if (!(0, import_shared.isPlainObj)(values)) return;
|
|
113
|
+
if (strategy === "merge" || strategy === "deepMerge") {
|
|
114
|
+
(0, import_shared.merge)(this.values, values, {
|
|
115
|
+
// never reach
|
|
116
|
+
arrayMerge: /* @__PURE__ */ __name((target, source) => source, "arrayMerge"),
|
|
117
|
+
assign: true
|
|
118
|
+
});
|
|
119
|
+
} else if (strategy === "shallowMerge") {
|
|
120
|
+
Object.assign(this.values, values);
|
|
121
|
+
} else {
|
|
122
|
+
this.values = values;
|
|
123
|
+
}
|
|
124
|
+
}, "setValues");
|
|
125
|
+
this.setInitialValues = /* @__PURE__ */ __name((initialValues, strategy = "merge") => {
|
|
126
|
+
if (!(0, import_shared.isPlainObj)(initialValues)) return;
|
|
127
|
+
if (strategy === "merge" || strategy === "deepMerge") {
|
|
128
|
+
(0, import_shared.merge)(this.initialValues, initialValues, {
|
|
129
|
+
// never reach
|
|
130
|
+
arrayMerge: /* @__PURE__ */ __name((target, source) => source, "arrayMerge"),
|
|
131
|
+
assign: true
|
|
132
|
+
});
|
|
133
|
+
} else if (strategy === "shallowMerge") {
|
|
134
|
+
Object.assign(this.initialValues, initialValues);
|
|
135
|
+
} else {
|
|
136
|
+
this.initialValues = initialValues;
|
|
137
|
+
}
|
|
138
|
+
}, "setInitialValues");
|
|
139
|
+
this.setValuesIn = /* @__PURE__ */ __name((pattern, value) => {
|
|
140
|
+
import_shared.FormPath.setIn(this.values, pattern, value);
|
|
141
|
+
}, "setValuesIn");
|
|
142
|
+
this.deleteValuesIn = /* @__PURE__ */ __name((pattern) => {
|
|
143
|
+
import_shared.FormPath.deleteIn(this.values, pattern);
|
|
144
|
+
}, "deleteValuesIn");
|
|
145
|
+
this.existValuesIn = /* @__PURE__ */ __name((pattern) => {
|
|
146
|
+
return import_shared.FormPath.existIn(this.values, pattern);
|
|
147
|
+
}, "existValuesIn");
|
|
148
|
+
this.getValuesIn = /* @__PURE__ */ __name((pattern) => {
|
|
149
|
+
return import_shared.FormPath.getIn(this.values, pattern);
|
|
150
|
+
}, "getValuesIn");
|
|
151
|
+
this.setInitialValuesIn = /* @__PURE__ */ __name((pattern, initialValue) => {
|
|
152
|
+
import_shared.FormPath.setIn(this.initialValues, pattern, initialValue);
|
|
153
|
+
}, "setInitialValuesIn");
|
|
154
|
+
this.deleteInitialValuesIn = /* @__PURE__ */ __name((pattern) => {
|
|
155
|
+
import_shared.FormPath.deleteIn(this.initialValues, pattern);
|
|
156
|
+
}, "deleteInitialValuesIn");
|
|
157
|
+
this.existInitialValuesIn = /* @__PURE__ */ __name((pattern) => {
|
|
158
|
+
return import_shared.FormPath.existIn(this.initialValues, pattern);
|
|
159
|
+
}, "existInitialValuesIn");
|
|
160
|
+
this.getInitialValuesIn = /* @__PURE__ */ __name((pattern) => {
|
|
161
|
+
return import_shared.FormPath.getIn(this.initialValues, pattern);
|
|
162
|
+
}, "getInitialValuesIn");
|
|
163
|
+
this.setLoading = /* @__PURE__ */ __name((loading) => {
|
|
164
|
+
(0, import_internals.setLoading)(this, loading);
|
|
165
|
+
}, "setLoading");
|
|
166
|
+
this.setSubmitting = /* @__PURE__ */ __name((submitting) => {
|
|
167
|
+
(0, import_internals.setSubmitting)(this, submitting);
|
|
168
|
+
}, "setSubmitting");
|
|
169
|
+
this.setValidating = /* @__PURE__ */ __name((validating) => {
|
|
170
|
+
(0, import_internals.setValidating)(this, validating);
|
|
171
|
+
}, "setValidating");
|
|
172
|
+
this.setDisplay = /* @__PURE__ */ __name((display) => {
|
|
173
|
+
this.display = display;
|
|
174
|
+
}, "setDisplay");
|
|
175
|
+
this.setPattern = /* @__PURE__ */ __name((pattern) => {
|
|
176
|
+
this.pattern = pattern;
|
|
177
|
+
}, "setPattern");
|
|
178
|
+
this.addEffects = /* @__PURE__ */ __name((id, effects) => {
|
|
179
|
+
if (!this.heart.hasLifeCycles(id)) {
|
|
180
|
+
this.heart.addLifeCycles(id, (0, import_effective.runEffects)(this, effects));
|
|
181
|
+
}
|
|
182
|
+
}, "addEffects");
|
|
183
|
+
this.removeEffects = /* @__PURE__ */ __name((id) => {
|
|
184
|
+
this.heart.removeLifeCycles(id);
|
|
185
|
+
}, "removeEffects");
|
|
186
|
+
this.setEffects = /* @__PURE__ */ __name((effects) => {
|
|
187
|
+
this.heart.setLifeCycles((0, import_effective.runEffects)(this, effects));
|
|
188
|
+
}, "setEffects");
|
|
189
|
+
this.clearErrors = /* @__PURE__ */ __name((pattern = "*") => {
|
|
190
|
+
this.query(pattern).forEach((field) => {
|
|
191
|
+
if (!(0, import_checkers.isVoidField)(field)) {
|
|
192
|
+
field.setFeedback({
|
|
193
|
+
type: "error",
|
|
194
|
+
messages: []
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
}, "clearErrors");
|
|
199
|
+
this.clearWarnings = /* @__PURE__ */ __name((pattern = "*") => {
|
|
200
|
+
this.query(pattern).forEach((field) => {
|
|
201
|
+
if (!(0, import_checkers.isVoidField)(field)) {
|
|
202
|
+
field.setFeedback({
|
|
203
|
+
type: "warning",
|
|
204
|
+
messages: []
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
}, "clearWarnings");
|
|
209
|
+
this.clearSuccesses = /* @__PURE__ */ __name((pattern = "*") => {
|
|
210
|
+
this.query(pattern).forEach((field) => {
|
|
211
|
+
if (!(0, import_checkers.isVoidField)(field)) {
|
|
212
|
+
field.setFeedback({
|
|
213
|
+
type: "success",
|
|
214
|
+
messages: []
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}, "clearSuccesses");
|
|
219
|
+
this.query = /* @__PURE__ */ __name((pattern) => {
|
|
220
|
+
return new import_Query.Query({
|
|
221
|
+
pattern,
|
|
222
|
+
base: "",
|
|
223
|
+
form: this
|
|
224
|
+
});
|
|
225
|
+
}, "query");
|
|
226
|
+
this.queryFeedbacks = /* @__PURE__ */ __name((search) => {
|
|
227
|
+
return this.query(search.address || search.path || "*").reduce((messages, field) => {
|
|
228
|
+
if ((0, import_checkers.isVoidField)(field)) return messages;
|
|
229
|
+
return messages.concat(
|
|
230
|
+
field.queryFeedbacks(search).map((feedback) => ({
|
|
231
|
+
...feedback,
|
|
232
|
+
address: field.address.toString(),
|
|
233
|
+
path: field.path.toString()
|
|
234
|
+
})).filter((feedback) => feedback.messages.length > 0)
|
|
235
|
+
);
|
|
236
|
+
}, []);
|
|
237
|
+
}, "queryFeedbacks");
|
|
238
|
+
this.notify = /* @__PURE__ */ __name((type, payload) => {
|
|
239
|
+
this.heart.publish(type, payload ?? this);
|
|
240
|
+
}, "notify");
|
|
241
|
+
this.subscribe = /* @__PURE__ */ __name((subscriber) => {
|
|
242
|
+
return this.heart.subscribe(subscriber);
|
|
243
|
+
}, "subscribe");
|
|
244
|
+
this.unsubscribe = /* @__PURE__ */ __name((id) => {
|
|
245
|
+
this.heart.unsubscribe(id);
|
|
246
|
+
}, "unsubscribe");
|
|
247
|
+
/**事件钩子**/
|
|
248
|
+
this.onInit = /* @__PURE__ */ __name(() => {
|
|
249
|
+
this.initialized = true;
|
|
250
|
+
this.notify(import_types.LifeCycleTypes.ON_FORM_INIT);
|
|
251
|
+
}, "onInit");
|
|
252
|
+
this.onMount = /* @__PURE__ */ __name(() => {
|
|
253
|
+
this.mounted = true;
|
|
254
|
+
this.notify(import_types.LifeCycleTypes.ON_FORM_MOUNT);
|
|
255
|
+
if (import_shared.globalThisPolyfill[DEV_TOOLS_HOOK] && !this.props.designable) {
|
|
256
|
+
import_shared.globalThisPolyfill[DEV_TOOLS_HOOK].inject(this.id, this);
|
|
257
|
+
}
|
|
258
|
+
}, "onMount");
|
|
259
|
+
this.onUnmount = /* @__PURE__ */ __name(() => {
|
|
260
|
+
this.notify(import_types.LifeCycleTypes.ON_FORM_UNMOUNT);
|
|
261
|
+
this.query("*").forEach((field) => field.destroy(false));
|
|
262
|
+
this.disposers.forEach((dispose) => dispose());
|
|
263
|
+
this.unmounted = true;
|
|
264
|
+
this.indexes = {};
|
|
265
|
+
this.heart.clear();
|
|
266
|
+
if (import_shared.globalThisPolyfill[DEV_TOOLS_HOOK] && !this.props.designable) {
|
|
267
|
+
import_shared.globalThisPolyfill[DEV_TOOLS_HOOK].unmount(this.id);
|
|
268
|
+
}
|
|
269
|
+
}, "onUnmount");
|
|
270
|
+
this.setState = (0, import_internals.createStateSetter)(this);
|
|
271
|
+
this.getState = (0, import_internals.createStateGetter)(this);
|
|
272
|
+
this.setFormState = (0, import_internals.createStateSetter)(this);
|
|
273
|
+
this.getFormState = (0, import_internals.createStateGetter)(this);
|
|
274
|
+
this.setFieldState = (0, import_internals.createBatchStateSetter)(this);
|
|
275
|
+
this.getFieldState = (0, import_internals.createBatchStateGetter)(this);
|
|
276
|
+
this.getFormGraph = /* @__PURE__ */ __name(() => {
|
|
277
|
+
return this.graph.getGraph();
|
|
278
|
+
}, "getFormGraph");
|
|
279
|
+
this.setFormGraph = /* @__PURE__ */ __name((graph) => {
|
|
280
|
+
this.graph.setGraph(graph);
|
|
281
|
+
}, "setFormGraph");
|
|
282
|
+
this.clearFormGraph = /* @__PURE__ */ __name((pattern = "*", forceClear = true) => {
|
|
283
|
+
this.query(pattern).forEach((field) => {
|
|
284
|
+
field.destroy(forceClear);
|
|
285
|
+
});
|
|
286
|
+
}, "clearFormGraph");
|
|
287
|
+
this.validate = /* @__PURE__ */ __name((pattern = "*") => {
|
|
288
|
+
return (0, import_internals.batchValidate)(this, pattern);
|
|
289
|
+
}, "validate");
|
|
290
|
+
this.submit = /* @__PURE__ */ __name((onSubmit) => {
|
|
291
|
+
return (0, import_internals.batchSubmit)(this, onSubmit);
|
|
292
|
+
}, "submit");
|
|
293
|
+
this.reset = /* @__PURE__ */ __name((pattern = "*", options) => {
|
|
294
|
+
return (0, import_internals.batchReset)(this, pattern, options);
|
|
295
|
+
}, "reset");
|
|
296
|
+
this.initialize(props);
|
|
297
|
+
this.makeObservable();
|
|
298
|
+
this.makeReactive();
|
|
299
|
+
this.makeValues();
|
|
300
|
+
this.onInit();
|
|
301
|
+
}
|
|
302
|
+
initialize(props) {
|
|
303
|
+
this.id = (0, import_shared.uid)();
|
|
304
|
+
this.props = { ...props };
|
|
305
|
+
this.initialized = false;
|
|
306
|
+
this.submitting = false;
|
|
307
|
+
this.validating = false;
|
|
308
|
+
this.loading = false;
|
|
309
|
+
this.modified = false;
|
|
310
|
+
this.mounted = false;
|
|
311
|
+
this.unmounted = false;
|
|
312
|
+
this.display = this.props.display || "visible";
|
|
313
|
+
this.pattern = this.props.pattern || "editable";
|
|
314
|
+
this.editable = this.props.editable;
|
|
315
|
+
this.disabled = this.props.disabled;
|
|
316
|
+
this.readOnly = this.props.readOnly;
|
|
317
|
+
this.readPretty = this.props.readPretty;
|
|
318
|
+
this.visible = this.props.visible;
|
|
319
|
+
this.hidden = this.props.hidden;
|
|
320
|
+
this.graph = new import_Graph.Graph(this);
|
|
321
|
+
this.heart = new import_Heart.Heart({
|
|
322
|
+
lifecycles: this.lifecycles,
|
|
323
|
+
context: this
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
makeValues() {
|
|
327
|
+
this.values = (0, import_internals.getValidFormValues)(this.props.values);
|
|
328
|
+
this.initialValues = (0, import_internals.getValidFormValues)(this.props.initialValues);
|
|
329
|
+
}
|
|
330
|
+
makeObservable() {
|
|
331
|
+
(0, import_reactive.define)(this, {
|
|
332
|
+
fields: import_reactive.observable.shallow,
|
|
333
|
+
indexes: import_reactive.observable.shallow,
|
|
334
|
+
initialized: import_reactive.observable.ref,
|
|
335
|
+
validating: import_reactive.observable.ref,
|
|
336
|
+
submitting: import_reactive.observable.ref,
|
|
337
|
+
loading: import_reactive.observable.ref,
|
|
338
|
+
modified: import_reactive.observable.ref,
|
|
339
|
+
pattern: import_reactive.observable.ref,
|
|
340
|
+
display: import_reactive.observable.ref,
|
|
341
|
+
mounted: import_reactive.observable.ref,
|
|
342
|
+
unmounted: import_reactive.observable.ref,
|
|
343
|
+
values: import_reactive.observable,
|
|
344
|
+
initialValues: import_reactive.observable,
|
|
345
|
+
valid: import_reactive.observable.computed,
|
|
346
|
+
invalid: import_reactive.observable.computed,
|
|
347
|
+
errors: import_reactive.observable.computed,
|
|
348
|
+
warnings: import_reactive.observable.computed,
|
|
349
|
+
successes: import_reactive.observable.computed,
|
|
350
|
+
hidden: import_reactive.observable.computed,
|
|
351
|
+
visible: import_reactive.observable.computed,
|
|
352
|
+
editable: import_reactive.observable.computed,
|
|
353
|
+
readOnly: import_reactive.observable.computed,
|
|
354
|
+
readPretty: import_reactive.observable.computed,
|
|
355
|
+
disabled: import_reactive.observable.computed,
|
|
356
|
+
setValues: import_reactive.action,
|
|
357
|
+
setValuesIn: import_reactive.action,
|
|
358
|
+
setInitialValues: import_reactive.action,
|
|
359
|
+
setInitialValuesIn: import_reactive.action,
|
|
360
|
+
setPattern: import_reactive.action,
|
|
361
|
+
setDisplay: import_reactive.action,
|
|
362
|
+
setState: import_reactive.action,
|
|
363
|
+
deleteInitialValuesIn: import_reactive.action,
|
|
364
|
+
deleteValuesIn: import_reactive.action,
|
|
365
|
+
setSubmitting: import_reactive.action,
|
|
366
|
+
setValidating: import_reactive.action,
|
|
367
|
+
reset: import_reactive.action,
|
|
368
|
+
submit: import_reactive.action,
|
|
369
|
+
validate: import_reactive.action,
|
|
370
|
+
onMount: import_reactive.batch,
|
|
371
|
+
onUnmount: import_reactive.batch,
|
|
372
|
+
onInit: import_reactive.batch
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
makeReactive() {
|
|
376
|
+
this.disposers.push(
|
|
377
|
+
(0, import_reactive.observe)(
|
|
378
|
+
this,
|
|
379
|
+
(change) => {
|
|
380
|
+
(0, import_internals.triggerFormInitialValuesChange)(this, change);
|
|
381
|
+
(0, import_internals.triggerFormValuesChange)(this, change);
|
|
382
|
+
},
|
|
383
|
+
true
|
|
384
|
+
)
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
get valid() {
|
|
388
|
+
return !this.invalid;
|
|
389
|
+
}
|
|
390
|
+
get invalid() {
|
|
391
|
+
return this.errors.length > 0;
|
|
392
|
+
}
|
|
393
|
+
get errors() {
|
|
394
|
+
return this.queryFeedbacks({
|
|
395
|
+
type: "error"
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
get warnings() {
|
|
399
|
+
return this.queryFeedbacks({
|
|
400
|
+
type: "warning"
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
get successes() {
|
|
404
|
+
return this.queryFeedbacks({
|
|
405
|
+
type: "success"
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
get lifecycles() {
|
|
409
|
+
return (0, import_effective.runEffects)(this, this.props.effects);
|
|
410
|
+
}
|
|
411
|
+
get hidden() {
|
|
412
|
+
return this.display === "hidden";
|
|
413
|
+
}
|
|
414
|
+
get visible() {
|
|
415
|
+
return this.display === "visible";
|
|
416
|
+
}
|
|
417
|
+
set hidden(hidden) {
|
|
418
|
+
if (!(0, import_shared.isValid)(hidden)) return;
|
|
419
|
+
if (hidden) {
|
|
420
|
+
this.display = "hidden";
|
|
421
|
+
} else {
|
|
422
|
+
this.display = "visible";
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
set visible(visible) {
|
|
426
|
+
if (!(0, import_shared.isValid)(visible)) return;
|
|
427
|
+
if (visible) {
|
|
428
|
+
this.display = "visible";
|
|
429
|
+
} else {
|
|
430
|
+
this.display = "none";
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
get editable() {
|
|
434
|
+
return this.pattern === "editable";
|
|
435
|
+
}
|
|
436
|
+
set editable(editable) {
|
|
437
|
+
if (!(0, import_shared.isValid)(editable)) return;
|
|
438
|
+
if (editable) {
|
|
439
|
+
this.pattern = "editable";
|
|
440
|
+
} else {
|
|
441
|
+
this.pattern = "readPretty";
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
get readOnly() {
|
|
445
|
+
return this.pattern === "readOnly";
|
|
446
|
+
}
|
|
447
|
+
set readOnly(readOnly) {
|
|
448
|
+
if (!(0, import_shared.isValid)(readOnly)) return;
|
|
449
|
+
if (readOnly) {
|
|
450
|
+
this.pattern = "readOnly";
|
|
451
|
+
} else {
|
|
452
|
+
this.pattern = "editable";
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
get disabled() {
|
|
456
|
+
return this.pattern === "disabled";
|
|
457
|
+
}
|
|
458
|
+
set disabled(disabled) {
|
|
459
|
+
if (!(0, import_shared.isValid)(disabled)) return;
|
|
460
|
+
if (disabled) {
|
|
461
|
+
this.pattern = "disabled";
|
|
462
|
+
} else {
|
|
463
|
+
this.pattern = "editable";
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
get readPretty() {
|
|
467
|
+
return this.pattern === "readPretty";
|
|
468
|
+
}
|
|
469
|
+
set readPretty(readPretty) {
|
|
470
|
+
if (!(0, import_shared.isValid)(readPretty)) return;
|
|
471
|
+
if (readPretty) {
|
|
472
|
+
this.pattern = "readPretty";
|
|
473
|
+
} else {
|
|
474
|
+
this.pattern = "editable";
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
__name(_Form, "Form");
|
|
479
|
+
let Form = _Form;
|
|
480
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
481
|
+
0 && (module.exports = {
|
|
482
|
+
Form
|
|
483
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Graph_exports = {};
|
|
20
|
+
__export(Graph_exports, {
|
|
21
|
+
Graph: () => Graph
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(Graph_exports);
|
|
24
|
+
var import_reactive = require("../../reactive");
|
|
25
|
+
var import_shared = require("../../shared");
|
|
26
|
+
var import_checkers = require("../shared/checkers");
|
|
27
|
+
const _Graph = class _Graph {
|
|
28
|
+
constructor(form) {
|
|
29
|
+
this.getGraph = /* @__PURE__ */ __name(() => {
|
|
30
|
+
const graph = {};
|
|
31
|
+
graph[""] = this.form.getState();
|
|
32
|
+
(0, import_shared.each)(this.form.fields, (field, identifier) => {
|
|
33
|
+
graph[identifier] = field.getState();
|
|
34
|
+
});
|
|
35
|
+
return graph;
|
|
36
|
+
}, "getGraph");
|
|
37
|
+
this.setGraph = /* @__PURE__ */ __name((graph) => {
|
|
38
|
+
const form = this.form;
|
|
39
|
+
const createField = /* @__PURE__ */ __name((identifier, state) => {
|
|
40
|
+
const address = import_shared.FormPath.parse(identifier);
|
|
41
|
+
const name = address.segments[address.segments.length - 1];
|
|
42
|
+
const basePath = address.parent();
|
|
43
|
+
if ((0, import_checkers.isFieldState)(state)) {
|
|
44
|
+
return this.form.createField({ name, basePath });
|
|
45
|
+
} else if ((0, import_checkers.isArrayFieldState)(state)) {
|
|
46
|
+
return this.form.createArrayField({ name, basePath });
|
|
47
|
+
} else if ((0, import_checkers.isObjectFieldState)(state)) {
|
|
48
|
+
return this.form.createObjectField({ name, basePath });
|
|
49
|
+
} else {
|
|
50
|
+
return this.form.createVoidField({ name, basePath });
|
|
51
|
+
}
|
|
52
|
+
}, "createField");
|
|
53
|
+
(0, import_shared.each)(graph, (state, address) => {
|
|
54
|
+
if ((0, import_checkers.isFormState)(state)) {
|
|
55
|
+
form.setState(state);
|
|
56
|
+
} else {
|
|
57
|
+
const field = form.fields[address];
|
|
58
|
+
if (field) {
|
|
59
|
+
field.setState(state);
|
|
60
|
+
} else {
|
|
61
|
+
createField(address, state).setState(state);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}, "setGraph");
|
|
66
|
+
this.form = form;
|
|
67
|
+
(0, import_reactive.define)(this, {
|
|
68
|
+
setGraph: import_reactive.batch
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
__name(_Graph, "Graph");
|
|
73
|
+
let Graph = _Graph;
|
|
74
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
75
|
+
0 && (module.exports = {
|
|
76
|
+
Graph
|
|
77
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Subscribable } from '../../shared';
|
|
2
|
+
import { IHeartProps } from '../types';
|
|
3
|
+
import { LifeCycle } from './LifeCycle';
|
|
4
|
+
export declare class Heart<Payload = any, Context = any> extends Subscribable {
|
|
5
|
+
lifecycles: LifeCycle<Payload>[];
|
|
6
|
+
outerLifecycles: Map<any, LifeCycle<Payload>[]>;
|
|
7
|
+
context: Context;
|
|
8
|
+
constructor({ lifecycles, context }?: IHeartProps<Context>);
|
|
9
|
+
buildLifeCycles: (lifecycles: LifeCycle[]) => any;
|
|
10
|
+
addLifeCycles: (id: any, lifecycles?: LifeCycle[]) => void;
|
|
11
|
+
hasLifeCycles: (id: any) => boolean;
|
|
12
|
+
removeLifeCycles: (id: any) => void;
|
|
13
|
+
setLifeCycles: (lifecycles?: LifeCycle[]) => void;
|
|
14
|
+
publish: <P, C>(type: any, payload?: P, context?: C) => void;
|
|
15
|
+
clear: () => void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var Heart_exports = {};
|
|
20
|
+
__export(Heart_exports, {
|
|
21
|
+
Heart: () => Heart
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(Heart_exports);
|
|
24
|
+
var import_shared = require("../../shared");
|
|
25
|
+
var import_LifeCycle = require("./LifeCycle");
|
|
26
|
+
const _Heart = class _Heart extends import_shared.Subscribable {
|
|
27
|
+
constructor({ lifecycles, context } = {}) {
|
|
28
|
+
super();
|
|
29
|
+
this.lifecycles = [];
|
|
30
|
+
this.outerLifecycles = /* @__PURE__ */ new Map();
|
|
31
|
+
this.buildLifeCycles = /* @__PURE__ */ __name((lifecycles) => {
|
|
32
|
+
return lifecycles.reduce((buf, item) => {
|
|
33
|
+
if (item instanceof import_LifeCycle.LifeCycle) {
|
|
34
|
+
return buf.concat(item);
|
|
35
|
+
} else {
|
|
36
|
+
if ((0, import_shared.isArr)(item)) {
|
|
37
|
+
return this.buildLifeCycles(item);
|
|
38
|
+
} else if (typeof item === "object") {
|
|
39
|
+
this.context = item;
|
|
40
|
+
return buf;
|
|
41
|
+
}
|
|
42
|
+
return buf;
|
|
43
|
+
}
|
|
44
|
+
}, []);
|
|
45
|
+
}, "buildLifeCycles");
|
|
46
|
+
this.addLifeCycles = /* @__PURE__ */ __name((id, lifecycles = []) => {
|
|
47
|
+
const observers = this.buildLifeCycles(lifecycles);
|
|
48
|
+
if (observers.length) {
|
|
49
|
+
this.outerLifecycles.set(id, observers);
|
|
50
|
+
}
|
|
51
|
+
}, "addLifeCycles");
|
|
52
|
+
this.hasLifeCycles = /* @__PURE__ */ __name((id) => {
|
|
53
|
+
return this.outerLifecycles.has(id);
|
|
54
|
+
}, "hasLifeCycles");
|
|
55
|
+
this.removeLifeCycles = /* @__PURE__ */ __name((id) => {
|
|
56
|
+
this.outerLifecycles.delete(id);
|
|
57
|
+
}, "removeLifeCycles");
|
|
58
|
+
this.setLifeCycles = /* @__PURE__ */ __name((lifecycles = []) => {
|
|
59
|
+
this.lifecycles = this.buildLifeCycles(lifecycles);
|
|
60
|
+
}, "setLifeCycles");
|
|
61
|
+
this.publish = /* @__PURE__ */ __name((type, payload, context) => {
|
|
62
|
+
if ((0, import_shared.isStr)(type)) {
|
|
63
|
+
this.lifecycles.forEach((lifecycle) => {
|
|
64
|
+
lifecycle.notify(type, payload, context || this.context);
|
|
65
|
+
});
|
|
66
|
+
this.outerLifecycles.forEach((lifecycles) => {
|
|
67
|
+
lifecycles.forEach((lifecycle) => {
|
|
68
|
+
lifecycle.notify(type, payload, context || this.context);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
this.notify({
|
|
72
|
+
type,
|
|
73
|
+
payload
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}, "publish");
|
|
77
|
+
this.clear = /* @__PURE__ */ __name(() => {
|
|
78
|
+
this.lifecycles = [];
|
|
79
|
+
this.outerLifecycles.clear();
|
|
80
|
+
this.unsubscribe();
|
|
81
|
+
}, "clear");
|
|
82
|
+
this.lifecycles = this.buildLifeCycles(lifecycles || []);
|
|
83
|
+
this.context = context;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
__name(_Heart, "Heart");
|
|
87
|
+
let Heart = _Heart;
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
Heart
|
|
91
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LifeCycleHandler } from '../types';
|
|
2
|
+
type LifeCycleParams<Payload> = Array<string | LifeCycleHandler<Payload> | {
|
|
3
|
+
[key: string]: LifeCycleHandler<Payload>;
|
|
4
|
+
}>;
|
|
5
|
+
export declare class LifeCycle<Payload = any> {
|
|
6
|
+
private listener;
|
|
7
|
+
constructor(...params: LifeCycleParams<Payload>);
|
|
8
|
+
buildListener: (params: any[]) => (payload: {
|
|
9
|
+
type: string;
|
|
10
|
+
payload: Payload;
|
|
11
|
+
}, ctx: any) => void;
|
|
12
|
+
notify: <Payload_1>(type: any, payload?: Payload_1, ctx?: any) => void;
|
|
13
|
+
}
|
|
14
|
+
export {};
|