@flowgram-vue/test-run-plugin 0.2.0

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.
Files changed (46) hide show
  1. package/LICENSE +22 -0
  2. package/dist/index.cjs +765 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +408 -0
  5. package/dist/index.js +759 -0
  6. package/dist/index.js.map +1 -0
  7. package/package.json +63 -0
  8. package/src/create-test-run-plugin.ts +39 -0
  9. package/src/env.d.ts +10 -0
  10. package/src/form-engine/contexts.ts +16 -0
  11. package/src/form-engine/fields/create-field.ts +41 -0
  12. package/src/form-engine/fields/general-field.ts +42 -0
  13. package/src/form-engine/fields/index.ts +9 -0
  14. package/src/form-engine/fields/object-field.ts +25 -0
  15. package/src/form-engine/fields/reactive-field.ts +55 -0
  16. package/src/form-engine/fields/recursion-field.ts +28 -0
  17. package/src/form-engine/fields/schema-field.ts +29 -0
  18. package/src/form-engine/form/form.ts +57 -0
  19. package/src/form-engine/form/index.ts +6 -0
  20. package/src/form-engine/hooks/index.ts +8 -0
  21. package/src/form-engine/hooks/use-create-form.ts +63 -0
  22. package/src/form-engine/hooks/use-field.ts +19 -0
  23. package/src/form-engine/hooks/use-form.ts +19 -0
  24. package/src/form-engine/index.ts +19 -0
  25. package/src/form-engine/model/index.ts +89 -0
  26. package/src/form-engine/types.ts +56 -0
  27. package/src/form-engine/utils.ts +69 -0
  28. package/src/index.ts +23 -0
  29. package/src/reactive/hooks/index.ts +7 -0
  30. package/src/reactive/hooks/use-create-form.ts +101 -0
  31. package/src/reactive/hooks/use-test-run-service.ts +10 -0
  32. package/src/reactive/index.ts +6 -0
  33. package/src/services/config.ts +42 -0
  34. package/src/services/form/factory.ts +9 -0
  35. package/src/services/form/form.ts +77 -0
  36. package/src/services/form/index.ts +8 -0
  37. package/src/services/form/manager.ts +43 -0
  38. package/src/services/index.ts +14 -0
  39. package/src/services/pipeline/factory.ts +9 -0
  40. package/src/services/pipeline/index.ts +12 -0
  41. package/src/services/pipeline/pipeline.ts +155 -0
  42. package/src/services/pipeline/plugin.ts +13 -0
  43. package/src/services/pipeline/tap.ts +34 -0
  44. package/src/services/store.ts +27 -0
  45. package/src/services/test-run.ts +108 -0
  46. package/src/types.ts +29 -0
package/dist/index.cjs ADDED
@@ -0,0 +1,765 @@
1
+ 'use strict';
2
+
3
+ var core = require('@flowgram-vue/core');
4
+ var vue = require('vue');
5
+ var nanoid = require('nanoid');
6
+ var inversify = require('inversify');
7
+ var utils = require('@flowgram-vue/utils');
8
+ var form = require('@flowgram-vue/form');
9
+ var reactive = require('@flowgram-vue/reactive');
10
+ var vanilla = require('zustand/vanilla');
11
+
12
+ var __defProp = Object.defineProperty;
13
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
14
+ var __decorateClass = (decorators, target, key, kind) => {
15
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
16
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
17
+ if (decorator = decorators[i])
18
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
19
+ if (kind && result) __defProp(target, key, result);
20
+ return result;
21
+ };
22
+ var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
23
+
24
+ // src/services/config.ts
25
+ var TestRunConfig = /* @__PURE__ */ Symbol("TestRunConfig");
26
+ var defineConfig = (config) => {
27
+ const defaultConfig = {
28
+ components: {},
29
+ nodes: {},
30
+ plugins: []
31
+ };
32
+ return {
33
+ ...defaultConfig,
34
+ ...config
35
+ };
36
+ };
37
+ var getUniqueFieldName = (...args) => args.filter((path) => path).join(".");
38
+ var mergeFieldPath = (path, name) => [...path || [], name].filter((i) => Boolean(i));
39
+ var createValidate = (schema) => {
40
+ const rules = {};
41
+ visit(schema);
42
+ return rules;
43
+ function visit(current, name) {
44
+ if (name && current["x-validator"]) {
45
+ rules[name] = current["x-validator"];
46
+ }
47
+ if (current.type === "object" && current.properties) {
48
+ Object.entries(current.properties).forEach(([key, value]) => {
49
+ visit(value, getUniqueFieldName(name, key));
50
+ });
51
+ }
52
+ }
53
+ };
54
+ var connect = (Comp, mapProps) => {
55
+ const Connected = vue.defineComponent({
56
+ name: "ConnectedFormComponent",
57
+ setup(props, { slots }) {
58
+ return () => {
59
+ const mappedProps = mapProps(props);
60
+ return vue.h(Comp, mappedProps, () => slots.default?.() ?? mappedProps.children);
61
+ };
62
+ }
63
+ });
64
+ return Connected;
65
+ };
66
+ var isFormEmpty = (schema) => {
67
+ const isEmpty = (s) => {
68
+ if (!s.type || s.type === "object" || !s.name) {
69
+ return Object.entries(schema.properties || {}).map(([key, value]) => ({
70
+ name: key,
71
+ ...value
72
+ })).every(isFormEmpty);
73
+ }
74
+ return false;
75
+ };
76
+ return isEmpty(schema);
77
+ };
78
+ var FormSchemaModel = class _FormSchemaModel {
79
+ constructor(json, path = []) {
80
+ this.path = [];
81
+ this.state = new reactive.ReactiveState({ disabled: false });
82
+ this.fromJSON(json);
83
+ this.path = path;
84
+ }
85
+ get componentType() {
86
+ return this["x-component"];
87
+ }
88
+ get componentProps() {
89
+ return this["x-component-props"];
90
+ }
91
+ get decoratorType() {
92
+ return this["x-decorator"];
93
+ }
94
+ get decoratorProps() {
95
+ return this["x-decorator-props"];
96
+ }
97
+ get uniqueName() {
98
+ return getUniqueFieldName(...this.path);
99
+ }
100
+ fromJSON(json) {
101
+ Object.entries(json).forEach(([key, value]) => {
102
+ this[key] = value;
103
+ });
104
+ }
105
+ getPropertyList() {
106
+ const orderProperties = [];
107
+ const unOrderProperties = [];
108
+ Object.entries(this.properties || {}).forEach(([key, item]) => {
109
+ const index = item["x-index"];
110
+ const defaultValues = this.defaultValue;
111
+ if (typeof defaultValues === "object" && defaultValues !== null && key in defaultValues) {
112
+ item.defaultValue = defaultValues[key];
113
+ }
114
+ const current = new _FormSchemaModel(item, mergeFieldPath(this.path, key));
115
+ if (index !== void 0 && !isNaN(index)) {
116
+ orderProperties[index] = current;
117
+ } else {
118
+ unOrderProperties.push(current);
119
+ }
120
+ });
121
+ return orderProperties.concat(unOrderProperties).filter((item) => !!item);
122
+ }
123
+ };
124
+
125
+ // src/form-engine/hooks/use-create-form.ts
126
+ var useCreateForm = (schema, options = {}) => {
127
+ const { form: form$1, control } = form.createForm({
128
+ validate: {
129
+ ...createValidate(schema),
130
+ ...options.validate
131
+ },
132
+ validateTrigger: options.validateTrigger ?? form.ValidateTrigger.onBlur
133
+ });
134
+ const model = new FormSchemaModel({
135
+ type: "object",
136
+ ...schema,
137
+ defaultValue: options.defaultValues
138
+ });
139
+ if (options.onMounted) {
140
+ options.onMounted({ model, form: form$1 });
141
+ }
142
+ const disposable = control._formModel.onFormValuesChange((payload) => {
143
+ if (options.onFormValuesChange) {
144
+ options.onFormValuesChange(payload);
145
+ }
146
+ });
147
+ vue.onBeforeUnmount(() => {
148
+ disposable.dispose();
149
+ if (options.onUnmounted) {
150
+ options.onUnmounted();
151
+ }
152
+ });
153
+ return {
154
+ form: form$1,
155
+ control,
156
+ model
157
+ };
158
+ };
159
+
160
+ // src/form-engine/contexts.ts
161
+ var FieldModelKey = /* @__PURE__ */ Symbol("FieldModelContext");
162
+ var FormModelKey = /* @__PURE__ */ Symbol("FormModelContext");
163
+ var ComponentsKey = /* @__PURE__ */ Symbol("ComponentsContext");
164
+
165
+ // src/form-engine/hooks/use-field.ts
166
+ var useFieldModel = () => {
167
+ const model = vue.inject(FieldModelKey);
168
+ if (!model) {
169
+ throw new Error("useFieldModel must be used within FieldModelKey provider");
170
+ }
171
+ return model;
172
+ };
173
+ var useFieldState = () => reactive.useObserve(useFieldModel().state.value);
174
+ var useFormModel = () => {
175
+ const model = vue.inject(FormModelKey);
176
+ if (!model) {
177
+ throw new Error("useFormModel must be used within FormModelKey provider");
178
+ }
179
+ return model;
180
+ };
181
+ var useFormState = () => reactive.useObserve(useFormModel().state.value);
182
+ var ReactiveField = vue.defineComponent({
183
+ name: "ReactiveField",
184
+ props: {
185
+ componentProps: { type: Object, default: void 0 },
186
+ decoratorProps: { type: Object, default: void 0 }
187
+ },
188
+ setup(props, { slots }) {
189
+ const formState = useFormState();
190
+ const model = useFieldModel();
191
+ const modelState = useFieldState();
192
+ const components = vue.inject(ComponentsKey, {});
193
+ return () => {
194
+ const disabled = modelState.disabled || formState.disabled;
195
+ let children = slots.default?.();
196
+ if (model.componentType && components[model.componentType]) {
197
+ children = [
198
+ vue.h(
199
+ components[model.componentType],
200
+ {
201
+ disabled,
202
+ ...model.componentProps,
203
+ ...props.componentProps
204
+ },
205
+ () => slots.default?.()
206
+ )
207
+ ];
208
+ }
209
+ if (!model.decoratorType || !components[model.decoratorType]) {
210
+ return children;
211
+ }
212
+ return vue.h(
213
+ components[model.decoratorType],
214
+ {
215
+ type: model.type,
216
+ required: model.required,
217
+ ...model.decoratorProps,
218
+ ...props.decoratorProps
219
+ },
220
+ () => children
221
+ );
222
+ };
223
+ }
224
+ });
225
+
226
+ // src/form-engine/fields/object-field.ts
227
+ var ObjectField = vue.defineComponent({
228
+ name: "ObjectField",
229
+ props: {
230
+ model: { type: Object, required: true }
231
+ },
232
+ setup(props, { slots }) {
233
+ vue.provide(FieldModelKey, props.model);
234
+ return () => vue.h(ReactiveField, null, () => slots.default?.());
235
+ }
236
+ });
237
+ var GeneralField = vue.defineComponent({
238
+ name: "GeneralField",
239
+ props: {
240
+ model: { type: Object, required: true }
241
+ },
242
+ setup(props) {
243
+ vue.provide(FieldModelKey, props.model);
244
+ return () => vue.h(form.Field, {
245
+ name: props.model.uniqueName,
246
+ defaultValue: props.model.defaultValue,
247
+ render: ({ field, fieldState }) => vue.h(ReactiveField, {
248
+ componentProps: {
249
+ value: field.value,
250
+ onChange: field.onChange,
251
+ onFocus: field.onFocus,
252
+ onBlur: field.onBlur,
253
+ ...fieldState
254
+ },
255
+ decoratorProps: fieldState
256
+ })
257
+ });
258
+ }
259
+ });
260
+
261
+ // src/form-engine/fields/recursion-field.ts
262
+ var RecursionField = vue.defineComponent({
263
+ name: "RecursionField",
264
+ props: {
265
+ model: { type: Object, required: true }
266
+ },
267
+ setup(props) {
268
+ return () => {
269
+ const properties = props.model.getPropertyList();
270
+ if (props.model.type !== "object") {
271
+ return vue.h(GeneralField, { model: props.model });
272
+ }
273
+ return vue.h(
274
+ ObjectField,
275
+ { model: props.model },
276
+ () => properties.map((item) => vue.h(RecursionField, { key: item.uniqueName, model: item }))
277
+ );
278
+ };
279
+ }
280
+ });
281
+
282
+ // src/form-engine/fields/schema-field.ts
283
+ var SchemaField = vue.defineComponent({
284
+ name: "SchemaField",
285
+ props: {
286
+ model: { type: Object, required: true },
287
+ components: { type: Object, default: () => ({}) }
288
+ },
289
+ setup(props, { slots }) {
290
+ vue.provide(ComponentsKey, props.components || {});
291
+ vue.provide(FormModelKey, props.model);
292
+ return () => [vue.h(RecursionField, { model: props.model }), slots.default?.()];
293
+ }
294
+ });
295
+ var createSchemaField = (options) => {
296
+ const InnerSchemaField = vue.defineComponent({
297
+ name: "InnerSchemaField",
298
+ props: {
299
+ model: { type: Object, required: true },
300
+ components: { type: Object, default: void 0 }
301
+ },
302
+ setup(props, { slots }) {
303
+ return () => vue.h(
304
+ SchemaField,
305
+ {
306
+ model: props.model,
307
+ components: {
308
+ ...options.components,
309
+ ...props.components
310
+ }
311
+ },
312
+ () => slots.default?.()
313
+ );
314
+ }
315
+ });
316
+ return InnerSchemaField;
317
+ };
318
+
319
+ // src/form-engine/form/form.ts
320
+ var SchemaField2 = createSchemaField({});
321
+ var FormEngine = vue.defineComponent({
322
+ name: "FormEngine",
323
+ props: {
324
+ schema: { type: Object, required: true },
325
+ components: { type: Object, default: void 0 },
326
+ defaultValues: { default: void 0 },
327
+ validate: { type: Object, default: void 0 },
328
+ validateTrigger: { default: void 0 },
329
+ onMounted: { type: Function, default: void 0 },
330
+ onFormValuesChange: {
331
+ type: Function,
332
+ default: void 0
333
+ },
334
+ onUnmounted: {
335
+ type: Function,
336
+ default: void 0
337
+ }
338
+ },
339
+ setup(props, { slots }) {
340
+ const { model, control } = useCreateForm(props.schema, {
341
+ defaultValues: props.defaultValues,
342
+ validate: props.validate,
343
+ validateTrigger: props.validateTrigger,
344
+ onMounted: props.onMounted,
345
+ onFormValuesChange: props.onFormValuesChange,
346
+ onUnmounted: props.onUnmounted
347
+ });
348
+ return () => vue.h(
349
+ form.Form,
350
+ { control },
351
+ () => vue.h(SchemaField2, { model, components: props.components }, () => slots.default?.())
352
+ );
353
+ }
354
+ });
355
+
356
+ // src/services/form/form.ts
357
+ var TestRunFormEntity = class {
358
+ constructor() {
359
+ this.initialized = false;
360
+ this.id = nanoid.nanoid();
361
+ this.form = null;
362
+ this.onFormMountedEmitter = new utils.Emitter();
363
+ this.onFormMounted = this.onFormMountedEmitter.event;
364
+ this.onFormUnmountedEmitter = new utils.Emitter();
365
+ this.onFormUnmounted = this.onFormUnmountedEmitter.event;
366
+ }
367
+ get schema() {
368
+ return this._schema;
369
+ }
370
+ init(options) {
371
+ if (this.initialized) return;
372
+ this._schema = options.schema;
373
+ this.initialized = true;
374
+ }
375
+ render(props) {
376
+ if (!this.initialized) {
377
+ return null;
378
+ }
379
+ const { children, ...restProps } = props || {};
380
+ return vue.h(
381
+ FormEngine,
382
+ {
383
+ schema: this.schema,
384
+ components: this.config.components,
385
+ onMounted: (instance) => {
386
+ this.form = instance;
387
+ this.onFormMountedEmitter.fire(instance);
388
+ },
389
+ onUnmounted: this.onFormUnmountedEmitter.fire.bind(this.onFormUnmountedEmitter),
390
+ ...restProps
391
+ },
392
+ () => children
393
+ );
394
+ }
395
+ dispose() {
396
+ this._schema = {};
397
+ this.form = null;
398
+ this.onFormMountedEmitter.dispose();
399
+ this.onFormUnmountedEmitter.dispose();
400
+ }
401
+ };
402
+ __decorateClass([
403
+ inversify.inject(TestRunConfig)
404
+ ], TestRunFormEntity.prototype, "config", 2);
405
+ TestRunFormEntity = __decorateClass([
406
+ inversify.injectable()
407
+ ], TestRunFormEntity);
408
+
409
+ // src/services/form/factory.ts
410
+ var TestRunFormFactory = /* @__PURE__ */ Symbol("TestRunFormFactory");
411
+ var TestRunFormManager = class {
412
+ constructor() {
413
+ this.entities = /* @__PURE__ */ new Map();
414
+ }
415
+ createForm() {
416
+ return this.factory();
417
+ }
418
+ getForm(id) {
419
+ return this.entities.get(id);
420
+ }
421
+ getAllForm() {
422
+ return Array.from(this.entities);
423
+ }
424
+ disposeForm(id) {
425
+ const form = this.entities.get(id);
426
+ if (!form) {
427
+ return;
428
+ }
429
+ form.dispose();
430
+ this.entities.delete(id);
431
+ }
432
+ disposeAllForm() {
433
+ for (const id of this.entities.keys()) {
434
+ this.disposeForm(id);
435
+ }
436
+ }
437
+ };
438
+ __decorateClass([
439
+ inversify.inject(TestRunFormFactory)
440
+ ], TestRunFormManager.prototype, "factory", 2);
441
+ TestRunFormManager = __decorateClass([
442
+ inversify.injectable()
443
+ ], TestRunFormManager);
444
+
445
+ // src/services/pipeline/factory.ts
446
+ var TestRunPipelineFactory = /* @__PURE__ */ Symbol("TestRunPipelineFactory");
447
+
448
+ // src/services/test-run.ts
449
+ var TestRunService = class {
450
+ constructor() {
451
+ this.pipelineEntities = /* @__PURE__ */ new Map();
452
+ this.pipelineBindings = /* @__PURE__ */ new Map();
453
+ this.onPipelineProgressEmitter = new utils.Emitter();
454
+ this.onPipelineProgress = this.onPipelineProgressEmitter.event;
455
+ this.onPipelineFinishedEmitter = new utils.Emitter();
456
+ this.onPipelineFinished = this.onPipelineFinishedEmitter.event;
457
+ }
458
+ isEnabled(nodeType) {
459
+ const config = this.config.nodes[nodeType];
460
+ return config && config?.enabled !== false;
461
+ }
462
+ async toSchema(node) {
463
+ const nodeType = node.flowNodeType;
464
+ const config = this.config.nodes[nodeType];
465
+ if (!this.isEnabled(nodeType)) {
466
+ return {};
467
+ }
468
+ const properties = typeof config.properties === "function" ? await config.properties({ node }) : config.properties;
469
+ return {
470
+ type: "object",
471
+ properties
472
+ };
473
+ }
474
+ createFormWithSchema(schema) {
475
+ const form = this.formManager.createForm();
476
+ form.init({ schema });
477
+ return form;
478
+ }
479
+ async createForm(node) {
480
+ const schema = await this.toSchema(node);
481
+ return this.createFormWithSchema(schema);
482
+ }
483
+ createPipeline(options) {
484
+ const pipeline = this.pipelineFactory();
485
+ this.pipelineEntities.set(pipeline.id, pipeline);
486
+ pipeline.init(options);
487
+ return pipeline;
488
+ }
489
+ disposePipeline(id) {
490
+ const pipeline = this.pipelineEntities.get(id);
491
+ if (pipeline) {
492
+ this.pipelineEntities.delete(id);
493
+ pipeline.dispose();
494
+ }
495
+ }
496
+ connectPipeline(pipeline) {
497
+ if (this.pipelineBindings.get(pipeline.id)) {
498
+ return;
499
+ }
500
+ const disposable = new utils.DisposableCollection(
501
+ pipeline.onProgress(this.onPipelineProgressEmitter.fire.bind(this.onPipelineProgressEmitter)),
502
+ pipeline.onFinished(this.onPipelineFinishedEmitter.fire.bind(this.onPipelineFinishedEmitter))
503
+ );
504
+ this.pipelineBindings.set(pipeline.id, disposable);
505
+ }
506
+ disconnectPipeline(id) {
507
+ if (this.pipelineBindings.has(id)) {
508
+ const disposable = this.pipelineBindings.get(id);
509
+ disposable?.dispose();
510
+ this.pipelineBindings.delete(id);
511
+ }
512
+ }
513
+ disconnectAllPipeline() {
514
+ for (const id of this.pipelineBindings.keys()) {
515
+ this.disconnectPipeline(id);
516
+ }
517
+ }
518
+ };
519
+ __decorateClass([
520
+ inversify.inject(TestRunConfig)
521
+ ], TestRunService.prototype, "config", 2);
522
+ __decorateClass([
523
+ inversify.inject(TestRunPipelineFactory)
524
+ ], TestRunService.prototype, "pipelineFactory", 2);
525
+ __decorateClass([
526
+ inversify.inject(TestRunFormManager)
527
+ ], TestRunService.prototype, "formManager", 2);
528
+ TestRunService = __decorateClass([
529
+ inversify.injectable()
530
+ ], TestRunService);
531
+
532
+ // src/services/pipeline/tap.ts
533
+ var Tap = class {
534
+ constructor() {
535
+ this.taps = [];
536
+ this.frozen = false;
537
+ }
538
+ tap(name, fn) {
539
+ this.taps.push({ name, fn });
540
+ }
541
+ async call(ctx) {
542
+ for (const tap of this.taps) {
543
+ if (this.frozen) {
544
+ return;
545
+ }
546
+ await tap.fn(ctx);
547
+ }
548
+ }
549
+ freeze() {
550
+ this.frozen = true;
551
+ }
552
+ };
553
+ var StoreService = class {
554
+ get getState() {
555
+ return this.store.getState.bind(this.store);
556
+ }
557
+ get setState() {
558
+ return this.store.setState.bind(this.store);
559
+ }
560
+ constructor(stateCreator) {
561
+ this.store = vanilla.createStore(stateCreator);
562
+ }
563
+ };
564
+ StoreService = __decorateClass([
565
+ inversify.injectable(),
566
+ __decorateParam(0, inversify.unmanaged())
567
+ ], StoreService);
568
+
569
+ // src/services/pipeline/pipeline.ts
570
+ var initialState = {
571
+ status: "idle",
572
+ data: {}
573
+ };
574
+ exports.TestRunPipelineEntity = class TestRunPipelineEntity extends StoreService {
575
+ constructor() {
576
+ super((set, get) => ({
577
+ ...initialState,
578
+ getData: () => get().data || {},
579
+ setData: (next) => set((state) => ({ ...state, data: { ...state.data, ...next } }))
580
+ }));
581
+ this.id = nanoid.nanoid();
582
+ this.plugins = [];
583
+ this.prepare = new Tap();
584
+ this.onProgressEmitter = new utils.Emitter();
585
+ this.onProgress = this.onProgressEmitter.event;
586
+ this.onFinishedEmitter = new utils.Emitter();
587
+ this.onFinished = this.onFinishedEmitter.event;
588
+ }
589
+ get status() {
590
+ return this.getState().status;
591
+ }
592
+ set status(next) {
593
+ this.setState({ status: next });
594
+ }
595
+ init(options) {
596
+ if (!this.container) {
597
+ return;
598
+ }
599
+ const { plugins } = options;
600
+ for (const PluginClass of plugins) {
601
+ const plugin = this.container.resolve(PluginClass);
602
+ plugin.apply(this);
603
+ this.plugins.push(plugin);
604
+ }
605
+ }
606
+ registerExecute(fn) {
607
+ this.execute = fn;
608
+ }
609
+ registerProgress(fn) {
610
+ this.progress = fn;
611
+ }
612
+ async start(options) {
613
+ const { data } = options || {};
614
+ if (this.status !== "idle") {
615
+ return;
616
+ }
617
+ this.setState({ data });
618
+ const ctx = {
619
+ id: this.id,
620
+ store: this.store,
621
+ operate: {
622
+ update: this.update.bind(this),
623
+ cancel: this.cancel.bind(this)
624
+ }
625
+ };
626
+ this.status = "preparing";
627
+ await this.prepare.call(ctx);
628
+ if (this.status !== "preparing") {
629
+ return;
630
+ }
631
+ this.status = "executing";
632
+ if (this.execute) {
633
+ await this.execute(ctx);
634
+ }
635
+ if (this.progress) {
636
+ await this.progress(ctx);
637
+ }
638
+ if (this.status === "executing") {
639
+ this.status = "finished";
640
+ this.onFinishedEmitter.fire(this.getState().result);
641
+ }
642
+ }
643
+ update(result) {
644
+ this.setState({ result });
645
+ this.onProgressEmitter.fire(result);
646
+ }
647
+ cancel() {
648
+ if (this.status = "preparing") {
649
+ this.prepare.freeze();
650
+ }
651
+ this.status = "canceled";
652
+ }
653
+ dispose() {
654
+ this.status = "disposed";
655
+ this.plugins.forEach((p) => {
656
+ if (p.dispose) {
657
+ p.dispose();
658
+ }
659
+ });
660
+ this.onProgressEmitter.dispose();
661
+ this.onFinishedEmitter.dispose();
662
+ }
663
+ };
664
+ exports.TestRunPipelineEntity = __decorateClass([
665
+ inversify.injectable()
666
+ ], exports.TestRunPipelineEntity);
667
+
668
+ // src/create-test-run-plugin.ts
669
+ var createTestRunPlugin = core.definePluginCreator({
670
+ onBind: ({ bind }, opt) => {
671
+ bind(TestRunService).toSelf().inSingletonScope();
672
+ bind(TestRunConfig).toConstantValue(defineConfig(opt));
673
+ bind(TestRunFormManager).toSelf().inSingletonScope();
674
+ bind(TestRunFormFactory).toFactory((context) => () => {
675
+ const e = context.container.resolve(TestRunFormEntity);
676
+ return e;
677
+ });
678
+ bind(TestRunPipelineFactory).toFactory(
679
+ (context) => () => {
680
+ const e = context.container.resolve(exports.TestRunPipelineEntity);
681
+ e.container = context.container.createChild();
682
+ return e;
683
+ }
684
+ );
685
+ }
686
+ });
687
+ var useTestRunService = () => core.useService(TestRunService);
688
+
689
+ // src/reactive/hooks/use-create-form.ts
690
+ var useCreateForm2 = ({
691
+ node,
692
+ loadingRenderer,
693
+ emptyRenderer,
694
+ defaultValues,
695
+ onMounted,
696
+ onUnmounted,
697
+ onFormValuesChange
698
+ }) => {
699
+ const testRun = useTestRunService();
700
+ const loading = vue.ref(false);
701
+ const form = vue.shallowRef(null);
702
+ const renderer = vue.computed(() => {
703
+ if (loading.value || !form.value) {
704
+ return loadingRenderer;
705
+ }
706
+ const isEmpty = isFormEmpty(form.value.schema);
707
+ return form.value.render({
708
+ defaultValues,
709
+ onFormValuesChange,
710
+ children: isEmpty ? emptyRenderer : null
711
+ });
712
+ });
713
+ const compute = async () => {
714
+ if (!node) {
715
+ return;
716
+ }
717
+ try {
718
+ loading.value = true;
719
+ const formEntity = await testRun.createForm(node);
720
+ form.value = formEntity;
721
+ } finally {
722
+ loading.value = false;
723
+ }
724
+ };
725
+ vue.watch(
726
+ () => node,
727
+ () => {
728
+ void compute();
729
+ },
730
+ { immediate: true }
731
+ );
732
+ vue.watch(
733
+ form,
734
+ (next, _prev, onCleanup) => {
735
+ if (!next) {
736
+ return;
737
+ }
738
+ const disposable = new utils.DisposableCollection(
739
+ next.onFormMounted((data) => {
740
+ onMounted?.(data);
741
+ }),
742
+ next.onFormUnmounted(() => {
743
+ onUnmounted?.();
744
+ })
745
+ );
746
+ onCleanup(() => disposable.dispose());
747
+ }
748
+ );
749
+ vue.onBeforeUnmount(() => {
750
+ form.value = null;
751
+ });
752
+ return {
753
+ renderer,
754
+ loading,
755
+ form
756
+ };
757
+ };
758
+
759
+ exports.FormEngine = FormEngine;
760
+ exports.connect = connect;
761
+ exports.createTestRunPlugin = createTestRunPlugin;
762
+ exports.useCreateForm = useCreateForm2;
763
+ exports.useTestRunService = useTestRunService;
764
+ //# sourceMappingURL=index.cjs.map
765
+ //# sourceMappingURL=index.cjs.map