@difizen/libro-widget 0.0.2-alpha.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.
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/es/base/comm.d.ts +65 -0
- package/es/base/comm.d.ts.map +1 -0
- package/es/base/comm.js +151 -0
- package/es/base/index.d.ts +7 -0
- package/es/base/index.d.ts.map +1 -0
- package/es/base/index.js +6 -0
- package/es/base/libro-widgets.d.ts +79 -0
- package/es/base/libro-widgets.d.ts.map +1 -0
- package/es/base/libro-widgets.js +285 -0
- package/es/base/protocal.d.ts +171 -0
- package/es/base/protocal.d.ts.map +1 -0
- package/es/base/protocal.js +21 -0
- package/es/base/utils.d.ts +27 -0
- package/es/base/utils.d.ts.map +1 -0
- package/es/base/utils.js +59 -0
- package/es/base/version.d.ts +3 -0
- package/es/base/version.d.ts.map +1 -0
- package/es/base/version.js +2 -0
- package/es/base/widget-manager.d.ts +18 -0
- package/es/base/widget-manager.d.ts.map +1 -0
- package/es/base/widget-manager.js +68 -0
- package/es/base/widget-view-contribution.d.ts +10 -0
- package/es/base/widget-view-contribution.d.ts.map +1 -0
- package/es/base/widget-view-contribution.js +36 -0
- package/es/base/widget-view.d.ts +52 -0
- package/es/base/widget-view.d.ts.map +1 -0
- package/es/base/widget-view.js +137 -0
- package/es/components/index.d.ts +3 -0
- package/es/components/index.d.ts.map +1 -0
- package/es/components/index.js +2 -0
- package/es/components/progressBar.d.ts +15 -0
- package/es/components/progressBar.d.ts.map +1 -0
- package/es/components/progressBar.js +20 -0
- package/es/components/progressCircle.d.ts +11 -0
- package/es/components/progressCircle.d.ts.map +1 -0
- package/es/components/progressCircle.js +16 -0
- package/es/index.d.ts +5 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +4 -0
- package/es/widget-module.d.ts +3 -0
- package/es/widget-module.d.ts.map +1 -0
- package/es/widget-module.js +39 -0
- package/es/widgets/hbox-widget-view-contribution.d.ts +10 -0
- package/es/widgets/hbox-widget-view-contribution.d.ts.map +1 -0
- package/es/widgets/hbox-widget-view-contribution.js +39 -0
- package/es/widgets/hbox-widget-view.d.ts +17 -0
- package/es/widgets/hbox-widget-view.d.ts.map +1 -0
- package/es/widgets/hbox-widget-view.js +69 -0
- package/es/widgets/index.d.ts +9 -0
- package/es/widgets/index.d.ts.map +1 -0
- package/es/widgets/index.js +8 -0
- package/es/widgets/index.less +3 -0
- package/es/widgets/instances-progress-widget-view-contribution.d.ts +10 -0
- package/es/widgets/instances-progress-widget-view-contribution.d.ts.map +1 -0
- package/es/widgets/instances-progress-widget-view-contribution.js +39 -0
- package/es/widgets/instances-progress-widget-view.d.ts +31 -0
- package/es/widgets/instances-progress-widget-view.d.ts.map +1 -0
- package/es/widgets/instances-progress-widget-view.js +181 -0
- package/es/widgets/progress-widget-view-contribution.d.ts +10 -0
- package/es/widgets/progress-widget-view-contribution.d.ts.map +1 -0
- package/es/widgets/progress-widget-view-contribution.js +39 -0
- package/es/widgets/progress-widget-view.d.ts +25 -0
- package/es/widgets/progress-widget-view.d.ts.map +1 -0
- package/es/widgets/progress-widget-view.js +103 -0
- package/es/widgets/text-widget-view-contribution.d.ts +10 -0
- package/es/widgets/text-widget-view-contribution.d.ts.map +1 -0
- package/es/widgets/text-widget-view-contribution.js +39 -0
- package/es/widgets/text-widget-view.d.ts +19 -0
- package/es/widgets/text-widget-view.d.ts.map +1 -0
- package/es/widgets/text-widget-view.js +91 -0
- package/package.json +60 -0
- package/src/base/comm.ts +152 -0
- package/src/base/index.ts +6 -0
- package/src/base/libro-widgets.ts +207 -0
- package/src/base/protocal.ts +218 -0
- package/src/base/utils.ts +67 -0
- package/src/base/version.ts +2 -0
- package/src/base/widget-manager.ts +41 -0
- package/src/base/widget-view-contribution.ts +14 -0
- package/src/base/widget-view.tsx +146 -0
- package/src/components/index.ts +3 -0
- package/src/components/progressBar.tsx +29 -0
- package/src/components/progressCircle.tsx +18 -0
- package/src/index.ts +4 -0
- package/src/widget-module.ts +68 -0
- package/src/widgets/hbox-widget-view-contribution.ts +20 -0
- package/src/widgets/hbox-widget-view.tsx +64 -0
- package/src/widgets/index.less +3 -0
- package/src/widgets/index.ts +8 -0
- package/src/widgets/instances-progress-widget-view-contribution.ts +20 -0
- package/src/widgets/instances-progress-widget-view.tsx +160 -0
- package/src/widgets/progress-widget-view-contribution.ts +24 -0
- package/src/widgets/progress-widget-view.tsx +85 -0
- package/src/widgets/text-widget-view-contribution.ts +20 -0
- package/src/widgets/text-widget-view.tsx +83 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Progress } from 'antd';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Props for the ProgressBar.
|
|
5
|
+
*/
|
|
6
|
+
export interface IProgressBarProps {
|
|
7
|
+
/**
|
|
8
|
+
* The current progress percentage, from 0 to 100
|
|
9
|
+
*/
|
|
10
|
+
percent: number;
|
|
11
|
+
/**
|
|
12
|
+
* Width of progress bar in pixel.
|
|
13
|
+
*/
|
|
14
|
+
width?: number;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function ProgressBar(props: IProgressBarProps) {
|
|
18
|
+
return (
|
|
19
|
+
<>
|
|
20
|
+
<Progress
|
|
21
|
+
strokeLinecap="butt"
|
|
22
|
+
percent={props.percent}
|
|
23
|
+
strokeWidth={18}
|
|
24
|
+
showInfo={false}
|
|
25
|
+
style={{ width: '200px' }}
|
|
26
|
+
/>
|
|
27
|
+
</>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Progress } from 'antd';
|
|
2
|
+
/**
|
|
3
|
+
* Props for the ProgressBar.
|
|
4
|
+
*/
|
|
5
|
+
export interface IProgressCircleProps {
|
|
6
|
+
/**
|
|
7
|
+
* The current progress percentage, from 0 to 100
|
|
8
|
+
*/
|
|
9
|
+
percent: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function ProgressCircle(props: IProgressCircleProps) {
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
<Progress strokeLinecap="butt" type="circle" percent={props.percent} />;
|
|
16
|
+
</>
|
|
17
|
+
);
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { LibroKernelManageModule } from '@difizen/libro-kernel';
|
|
2
|
+
import { ManaModule } from '@difizen/mana-app';
|
|
3
|
+
|
|
4
|
+
import { Comm } from './base/comm.js';
|
|
5
|
+
import {
|
|
6
|
+
WidgetsOption,
|
|
7
|
+
LibroWidgetCommFactory,
|
|
8
|
+
WidgetCommOption,
|
|
9
|
+
LibroWidgets,
|
|
10
|
+
LibroWidgetsFactory,
|
|
11
|
+
WidgetView,
|
|
12
|
+
WidgetViewContribution,
|
|
13
|
+
} from './base/index.js';
|
|
14
|
+
import { LibroWidgetManager } from './base/widget-manager.js';
|
|
15
|
+
import { DefaultWidgetViewContribution } from './base/widget-view-contribution.js';
|
|
16
|
+
import { HBoxModelContribution } from './widgets/hbox-widget-view-contribution.js';
|
|
17
|
+
import { HBoxWidget } from './widgets/hbox-widget-view.js';
|
|
18
|
+
import { ProgressWidget } from './widgets/index.js';
|
|
19
|
+
import { InstancesProgressWidgetViewContribution } from './widgets/instances-progress-widget-view-contribution.js';
|
|
20
|
+
import { InstancesProgressWidget } from './widgets/instances-progress-widget-view.js';
|
|
21
|
+
import { ProgressWidgetViewContribution } from './widgets/progress-widget-view-contribution.js';
|
|
22
|
+
import { TextModelContribution } from './widgets/text-widget-view-contribution.js';
|
|
23
|
+
import { LibroTextWidget } from './widgets/text-widget-view.js';
|
|
24
|
+
|
|
25
|
+
export const WidgetModule = ManaModule.create()
|
|
26
|
+
.contribution(WidgetViewContribution)
|
|
27
|
+
.register(
|
|
28
|
+
Comm,
|
|
29
|
+
{
|
|
30
|
+
token: LibroWidgetCommFactory,
|
|
31
|
+
useFactory: (ctx) => {
|
|
32
|
+
return (options: WidgetCommOption) => {
|
|
33
|
+
const child = ctx.container.createChild();
|
|
34
|
+
child.register({
|
|
35
|
+
token: WidgetCommOption,
|
|
36
|
+
useValue: options,
|
|
37
|
+
});
|
|
38
|
+
return child.get(Comm);
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
LibroWidgets,
|
|
43
|
+
{
|
|
44
|
+
token: LibroWidgetsFactory,
|
|
45
|
+
useFactory: (ctx) => {
|
|
46
|
+
return (options: WidgetsOption) => {
|
|
47
|
+
const child = ctx.container.createChild();
|
|
48
|
+
child.register({
|
|
49
|
+
token: WidgetsOption,
|
|
50
|
+
useValue: options,
|
|
51
|
+
});
|
|
52
|
+
return child.get(LibroWidgets);
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
LibroWidgetManager,
|
|
57
|
+
WidgetView,
|
|
58
|
+
ProgressWidget,
|
|
59
|
+
DefaultWidgetViewContribution,
|
|
60
|
+
ProgressWidgetViewContribution,
|
|
61
|
+
InstancesProgressWidgetViewContribution,
|
|
62
|
+
InstancesProgressWidget,
|
|
63
|
+
HBoxModelContribution,
|
|
64
|
+
HBoxWidget,
|
|
65
|
+
LibroTextWidget,
|
|
66
|
+
TextModelContribution,
|
|
67
|
+
)
|
|
68
|
+
.dependOn(LibroKernelManageModule);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ViewManager, inject, singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
4
|
+
import { WidgetViewContribution } from '../base/protocal.js';
|
|
5
|
+
|
|
6
|
+
import { HBoxWidget } from './hbox-widget-view.js';
|
|
7
|
+
|
|
8
|
+
@singleton({ contrib: WidgetViewContribution })
|
|
9
|
+
export class HBoxModelContribution implements WidgetViewContribution {
|
|
10
|
+
@inject(ViewManager) viewManager: ViewManager;
|
|
11
|
+
canHandle = (attributes: any) => {
|
|
12
|
+
if (attributes._model_name === 'HBoxModel') {
|
|
13
|
+
return 100;
|
|
14
|
+
}
|
|
15
|
+
return 1;
|
|
16
|
+
};
|
|
17
|
+
factory(props: IWidgetViewProps) {
|
|
18
|
+
return this.viewManager.getOrCreateView(HBoxWidget, props);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
view,
|
|
3
|
+
ViewOption,
|
|
4
|
+
ViewRender,
|
|
5
|
+
transient,
|
|
6
|
+
useInject,
|
|
7
|
+
ViewInstance,
|
|
8
|
+
inject,
|
|
9
|
+
} from '@difizen/mana-app';
|
|
10
|
+
import { forwardRef } from 'react';
|
|
11
|
+
|
|
12
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
13
|
+
import { WidgetView } from '../base/widget-view.js';
|
|
14
|
+
import './index.less';
|
|
15
|
+
import { LibroWidgets } from '../base/libro-widgets.js';
|
|
16
|
+
import { LirboContextKey } from '@difizen/libro-core';
|
|
17
|
+
|
|
18
|
+
export const HBoxWidgetComponent = forwardRef<HTMLDivElement>(
|
|
19
|
+
function HBoxWidgetComponent() {
|
|
20
|
+
const widgetView = useInject<HBoxWidget>(ViewInstance);
|
|
21
|
+
if (widgetView.isCommClosed) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const hboxChildrenWidget = widgetView.get_child_model();
|
|
25
|
+
return (
|
|
26
|
+
<div className="libro-hbox-widget">
|
|
27
|
+
{hboxChildrenWidget.map((childrenWidgets) => (
|
|
28
|
+
<ViewRender view={childrenWidgets} key={childrenWidgets.id} />
|
|
29
|
+
))}
|
|
30
|
+
</div>
|
|
31
|
+
);
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
@transient()
|
|
35
|
+
@view('libro-hbox-widget-view')
|
|
36
|
+
export class HBoxWidget extends WidgetView {
|
|
37
|
+
override view = HBoxWidgetComponent;
|
|
38
|
+
children: string[];
|
|
39
|
+
layout: string;
|
|
40
|
+
box_style: string;
|
|
41
|
+
override libroWidgets: LibroWidgets;
|
|
42
|
+
constructor(
|
|
43
|
+
@inject(ViewOption) props: IWidgetViewProps,
|
|
44
|
+
@inject(LirboContextKey) lirboContextKey: LirboContextKey,
|
|
45
|
+
@inject(LibroWidgets) libroWidgets: LibroWidgets,
|
|
46
|
+
) {
|
|
47
|
+
super(props, lirboContextKey);
|
|
48
|
+
this.box_style = props.attributes.bar_style;
|
|
49
|
+
this.layout = props.attributes.layout;
|
|
50
|
+
this.children = props.attributes.children;
|
|
51
|
+
this.lirboContextKey = lirboContextKey;
|
|
52
|
+
this.libroWidgets = libroWidgets;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
get_child_model(): WidgetView[] {
|
|
56
|
+
const childrenWidgets: WidgetView[] = [];
|
|
57
|
+
this.children.forEach((child) => {
|
|
58
|
+
if (this.libroWidgets.hasModel(child.substring(10))) {
|
|
59
|
+
childrenWidgets.push(this.libroWidgets.getModel(child.substring(10)));
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return childrenWidgets;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './hbox-widget-view.js';
|
|
2
|
+
export * from './hbox-widget-view-contribution.js';
|
|
3
|
+
export * from './instances-progress-widget-view.js';
|
|
4
|
+
export * from './instances-progress-widget-view-contribution.js';
|
|
5
|
+
export * from './progress-widget-view.js';
|
|
6
|
+
export * from './progress-widget-view-contribution.js';
|
|
7
|
+
export * from './text-widget-view.js';
|
|
8
|
+
export * from './text-widget-view-contribution.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ViewManager, inject, singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
4
|
+
import { WidgetViewContribution } from '../base/protocal.js';
|
|
5
|
+
|
|
6
|
+
import { InstancesProgressWidget } from './instances-progress-widget-view.js';
|
|
7
|
+
|
|
8
|
+
@singleton({ contrib: WidgetViewContribution })
|
|
9
|
+
export class InstancesProgressWidgetViewContribution implements WidgetViewContribution {
|
|
10
|
+
@inject(ViewManager) viewManager: ViewManager;
|
|
11
|
+
canHandle = (attributes: any) => {
|
|
12
|
+
if (attributes._model_name === 'InstancesProgressModel') {
|
|
13
|
+
return 100;
|
|
14
|
+
}
|
|
15
|
+
return 1;
|
|
16
|
+
};
|
|
17
|
+
factory(props: IWidgetViewProps) {
|
|
18
|
+
return this.viewManager.getOrCreateView(InstancesProgressWidget, props);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { LirboContextKey } from '@difizen/libro-core';
|
|
2
|
+
import type { KernelMessage } from '@difizen/libro-kernel';
|
|
3
|
+
import {
|
|
4
|
+
useInject,
|
|
5
|
+
view,
|
|
6
|
+
ViewInstance,
|
|
7
|
+
ViewOption,
|
|
8
|
+
transient,
|
|
9
|
+
inject,
|
|
10
|
+
prop,
|
|
11
|
+
} from '@difizen/mana-app';
|
|
12
|
+
import { forwardRef } from 'react';
|
|
13
|
+
|
|
14
|
+
import type {
|
|
15
|
+
InstanceRecord,
|
|
16
|
+
InstancesRecords,
|
|
17
|
+
ProgressItem,
|
|
18
|
+
} from '../base/protocal.js';
|
|
19
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
20
|
+
import { WidgetView } from '../base/widget-view.js';
|
|
21
|
+
import './index.less';
|
|
22
|
+
|
|
23
|
+
export interface ProgressOverviewProps {
|
|
24
|
+
progressMap: Record<string, ProgressItem>;
|
|
25
|
+
workingProgressKeys: string[];
|
|
26
|
+
prefix: string;
|
|
27
|
+
suffix: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const LibroInstancesProgressWidgetViewComponent = forwardRef<HTMLDivElement>(
|
|
31
|
+
function LibroInstancesProgressWidgetViewComponent(_props, ref) {
|
|
32
|
+
const widgetView = useInject<InstancesProgressWidget>(ViewInstance);
|
|
33
|
+
if (widgetView.isCommClosed) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return (
|
|
37
|
+
<div ref={ref} className="libro-instances-progress-widget">
|
|
38
|
+
<span style={{ paddingRight: 5 }}>{widgetView.prefix}</span>
|
|
39
|
+
<span>
|
|
40
|
+
{widgetView.workingProgressKeys.map((progressKey) => {
|
|
41
|
+
const progressItem = widgetView.progressMap[progressKey];
|
|
42
|
+
return (
|
|
43
|
+
<a
|
|
44
|
+
className="pyodps-progress-launcher"
|
|
45
|
+
style={{ marginRight: 5 }}
|
|
46
|
+
key={progressKey}
|
|
47
|
+
>
|
|
48
|
+
{progressItem && progressItem.name}
|
|
49
|
+
</a>
|
|
50
|
+
);
|
|
51
|
+
})}
|
|
52
|
+
</span>
|
|
53
|
+
<span>{widgetView.suffix}</span>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
@transient()
|
|
59
|
+
@view('libro-widget-instances-progress-view')
|
|
60
|
+
export class InstancesProgressWidget extends WidgetView {
|
|
61
|
+
override view = LibroInstancesProgressWidgetViewComponent;
|
|
62
|
+
@prop()
|
|
63
|
+
prefix: string;
|
|
64
|
+
@prop()
|
|
65
|
+
suffix: string;
|
|
66
|
+
progressMap: Record<string, ProgressItem> = {};
|
|
67
|
+
workingProgressKeys: string[] = []; // Order of groups by time of insertion
|
|
68
|
+
instanceRecords: InstancesRecords = {};
|
|
69
|
+
modalVisible = false;
|
|
70
|
+
modalProgressItemKey = '';
|
|
71
|
+
constructor(
|
|
72
|
+
@inject(ViewOption) props: IWidgetViewProps,
|
|
73
|
+
@inject(LirboContextKey) lirboContextKey: LirboContextKey,
|
|
74
|
+
) {
|
|
75
|
+
super(props, lirboContextKey);
|
|
76
|
+
this.prefix = props.attributes.prefix;
|
|
77
|
+
this.suffix = props.attributes.suffix;
|
|
78
|
+
}
|
|
79
|
+
updateRecords(progressKey: string) {
|
|
80
|
+
const progressItem = this.progressMap[progressKey];
|
|
81
|
+
if (progressItem) {
|
|
82
|
+
const { instances = [] } = progressItem;
|
|
83
|
+
instances.forEach((instance) => {
|
|
84
|
+
const { id, status } = instance;
|
|
85
|
+
if (!this.instanceRecords[id]) {
|
|
86
|
+
this.instanceRecords[id] = {
|
|
87
|
+
startDate: Date.now(),
|
|
88
|
+
} as InstanceRecord;
|
|
89
|
+
}
|
|
90
|
+
if (status === 'Terminated') {
|
|
91
|
+
if (!this.instanceRecords[id].endDate) {
|
|
92
|
+
this.instanceRecords[id].endDate = Date.now();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Handle incoming comm msg.
|
|
100
|
+
*/
|
|
101
|
+
override handleCommMsg(msg: KernelMessage.ICommMsgMsg): Promise<void> {
|
|
102
|
+
const data = msg.content.data as any;
|
|
103
|
+
const method = data.method;
|
|
104
|
+
switch (method) {
|
|
105
|
+
case 'update':
|
|
106
|
+
if (data.state.prefix) {
|
|
107
|
+
this.prefix = data.state.prefix;
|
|
108
|
+
}
|
|
109
|
+
if (data.state.suffix) {
|
|
110
|
+
this.suffix = data.state.suffix;
|
|
111
|
+
}
|
|
112
|
+
// eslint-disable-next-line no-fallthrough
|
|
113
|
+
case 'custom':
|
|
114
|
+
// eslint-disable-next-line no-case-declarations
|
|
115
|
+
const customMsg = data.content;
|
|
116
|
+
if (customMsg) {
|
|
117
|
+
// message format: '{"action": "action", content: ["content1", "content2"]}'
|
|
118
|
+
const msgObj: { action: 'update' | 'delete' | 'clear'; content: string[] } =
|
|
119
|
+
JSON.parse(customMsg);
|
|
120
|
+
const action: string = msgObj.action;
|
|
121
|
+
const content: string[] = [];
|
|
122
|
+
if (msgObj.content) {
|
|
123
|
+
content.push(...msgObj.content);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
switch (action) {
|
|
127
|
+
case 'update':
|
|
128
|
+
content.forEach((groupJson) => {
|
|
129
|
+
const parsedProgressItem: ProgressItem = JSON.parse(groupJson);
|
|
130
|
+
if (!this.progressMap[parsedProgressItem.key]) {
|
|
131
|
+
this.workingProgressKeys.push(parsedProgressItem.key);
|
|
132
|
+
}
|
|
133
|
+
this.progressMap[parsedProgressItem.key] = parsedProgressItem;
|
|
134
|
+
this.updateRecords(parsedProgressItem.key);
|
|
135
|
+
});
|
|
136
|
+
// ? TODO: 发出一个更新 modal signal 的信号,这里需要取到之前的 key
|
|
137
|
+
break;
|
|
138
|
+
case 'delete':
|
|
139
|
+
content.forEach((groupKey: string) => {
|
|
140
|
+
if (!this.progressMap[groupKey]) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
const i = this.workingProgressKeys.indexOf(groupKey);
|
|
144
|
+
if (i >= 0) {
|
|
145
|
+
this.workingProgressKeys.splice(i, 1);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
break;
|
|
149
|
+
case 'clear':
|
|
150
|
+
this.progressMap = {};
|
|
151
|
+
this.workingProgressKeys = [];
|
|
152
|
+
// ? TODO: 发出更新 overview 以及 modal 的 signal
|
|
153
|
+
break;
|
|
154
|
+
default:
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return Promise.resolve();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ViewManager, inject, singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
4
|
+
import { WidgetViewContribution } from '../base/protocal.js';
|
|
5
|
+
|
|
6
|
+
import { ProgressWidget } from './progress-widget-view.js';
|
|
7
|
+
|
|
8
|
+
@singleton({ contrib: WidgetViewContribution })
|
|
9
|
+
export class ProgressWidgetViewContribution implements WidgetViewContribution {
|
|
10
|
+
@inject(ViewManager) viewManager: ViewManager;
|
|
11
|
+
canHandle = (attributes: any) => {
|
|
12
|
+
if (
|
|
13
|
+
attributes._model_name === 'FloatProgressModel' ||
|
|
14
|
+
attributes._model_name === 'IntProgressModel' ||
|
|
15
|
+
attributes._model_name === 'TransientProgressModel'
|
|
16
|
+
) {
|
|
17
|
+
return 100;
|
|
18
|
+
}
|
|
19
|
+
return 1;
|
|
20
|
+
};
|
|
21
|
+
factory(props: IWidgetViewProps) {
|
|
22
|
+
return this.viewManager.getOrCreateView(ProgressWidget, props);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LirboContextKey } from '@difizen/libro-core';
|
|
2
|
+
import type { KernelMessage } from '@difizen/libro-kernel';
|
|
3
|
+
import {
|
|
4
|
+
view,
|
|
5
|
+
ViewOption,
|
|
6
|
+
transient,
|
|
7
|
+
useInject,
|
|
8
|
+
ViewInstance,
|
|
9
|
+
inject,
|
|
10
|
+
prop,
|
|
11
|
+
} from '@difizen/mana-app';
|
|
12
|
+
import { forwardRef } from 'react';
|
|
13
|
+
|
|
14
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
15
|
+
import { WidgetView } from '../base/widget-view.js';
|
|
16
|
+
import { ProgressBar } from '../components/index.js';
|
|
17
|
+
import './index.less';
|
|
18
|
+
|
|
19
|
+
export const LibroProgressWidgetComponent = forwardRef<HTMLDivElement>(
|
|
20
|
+
function LibroProgressWidgetComponent() {
|
|
21
|
+
const widgetView = useInject<ProgressWidget>(ViewInstance);
|
|
22
|
+
const percent = widgetView.value / ((widgetView.max - widgetView.min) / 100);
|
|
23
|
+
if (widgetView.isCommClosed) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return (
|
|
27
|
+
<div className="libro-progress-widget">
|
|
28
|
+
<div className="libro-progress-widget-description">
|
|
29
|
+
{widgetView.description}
|
|
30
|
+
</div>
|
|
31
|
+
<ProgressBar percent={percent} />
|
|
32
|
+
</div>
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
@transient()
|
|
37
|
+
@view('libro-widget-progress-view')
|
|
38
|
+
export class ProgressWidget extends WidgetView {
|
|
39
|
+
override view = LibroProgressWidgetComponent;
|
|
40
|
+
bar_style: string;
|
|
41
|
+
description: string;
|
|
42
|
+
description_tooltip: null;
|
|
43
|
+
layout: string;
|
|
44
|
+
@prop()
|
|
45
|
+
max: number;
|
|
46
|
+
@prop()
|
|
47
|
+
min: number;
|
|
48
|
+
orientation: string;
|
|
49
|
+
style: string;
|
|
50
|
+
@prop()
|
|
51
|
+
value: number;
|
|
52
|
+
constructor(
|
|
53
|
+
@inject(ViewOption) props: IWidgetViewProps,
|
|
54
|
+
@inject(LirboContextKey) lirboContextKey: LirboContextKey,
|
|
55
|
+
) {
|
|
56
|
+
super(props, lirboContextKey);
|
|
57
|
+
this.bar_style = props.attributes.bar_style;
|
|
58
|
+
this.description = props.attributes.description;
|
|
59
|
+
this.description_tooltip = props.attributes.description_tooltip;
|
|
60
|
+
this.layout = props.attributes.layout;
|
|
61
|
+
this.max = props.attributes.max;
|
|
62
|
+
this.min = props.attributes.min;
|
|
63
|
+
this.orientation = props.attributes.orientation;
|
|
64
|
+
this.style = props.attributes.style;
|
|
65
|
+
this.value = props.attributes.value;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Handle incoming comm msg.
|
|
69
|
+
*/
|
|
70
|
+
override handleCommMsg(msg: KernelMessage.ICommMsgMsg): Promise<void> {
|
|
71
|
+
const data = msg.content.data as any;
|
|
72
|
+
const method = data.method;
|
|
73
|
+
switch (method) {
|
|
74
|
+
case 'update':
|
|
75
|
+
case 'echo_update':
|
|
76
|
+
if (data.state.value) {
|
|
77
|
+
this.value = data.state.value;
|
|
78
|
+
}
|
|
79
|
+
if (data.state.description) {
|
|
80
|
+
this.description = data.state.description;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return Promise.resolve();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ViewManager, inject, singleton } from '@difizen/mana-app';
|
|
2
|
+
|
|
3
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
4
|
+
import { WidgetViewContribution } from '../base/protocal.js';
|
|
5
|
+
|
|
6
|
+
import { LibroTextWidget } from './text-widget-view.js';
|
|
7
|
+
|
|
8
|
+
@singleton({ contrib: WidgetViewContribution })
|
|
9
|
+
export class TextModelContribution implements WidgetViewContribution {
|
|
10
|
+
@inject(ViewManager) viewManager: ViewManager;
|
|
11
|
+
canHandle = (attributes: any) => {
|
|
12
|
+
if (attributes._model_name === 'TextModel') {
|
|
13
|
+
return 100;
|
|
14
|
+
}
|
|
15
|
+
return 1;
|
|
16
|
+
};
|
|
17
|
+
factory(props: IWidgetViewProps) {
|
|
18
|
+
return this.viewManager.getOrCreateView(LibroTextWidget, props);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { LirboContextKey } from '@difizen/libro-core';
|
|
2
|
+
import {
|
|
3
|
+
view,
|
|
4
|
+
ViewOption,
|
|
5
|
+
transient,
|
|
6
|
+
useInject,
|
|
7
|
+
ViewInstance,
|
|
8
|
+
inject,
|
|
9
|
+
prop,
|
|
10
|
+
} from '@difizen/mana-app';
|
|
11
|
+
import { Input } from 'antd';
|
|
12
|
+
import { forwardRef } from 'react';
|
|
13
|
+
|
|
14
|
+
import type { IWidgetViewProps } from '../base/protocal.js';
|
|
15
|
+
import { WidgetView } from '../base/widget-view.js';
|
|
16
|
+
|
|
17
|
+
import './index.less';
|
|
18
|
+
|
|
19
|
+
export const LibroTextWidgetComponent = forwardRef<HTMLDivElement>(
|
|
20
|
+
function LibroTextWidgetComponent(_props, ref) {
|
|
21
|
+
const widgetView = useInject<LibroTextWidget>(ViewInstance);
|
|
22
|
+
if (widgetView.isCommClosed) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const handleChange = (e: any) => {
|
|
27
|
+
const data = {
|
|
28
|
+
buffer_paths: [],
|
|
29
|
+
method: 'update',
|
|
30
|
+
state: { value: e.target.value },
|
|
31
|
+
};
|
|
32
|
+
widgetView.send(data);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const handlePressEnter = () => {
|
|
36
|
+
const data = { method: 'custom', content: { event: 'submit' } };
|
|
37
|
+
widgetView.send(data);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<div className="libro-input-widget" ref={ref}>
|
|
42
|
+
<span className="libro-input-widget-description">
|
|
43
|
+
{' '}
|
|
44
|
+
{widgetView.description}
|
|
45
|
+
</span>
|
|
46
|
+
<Input
|
|
47
|
+
placeholder={widgetView.placeholder}
|
|
48
|
+
size="small"
|
|
49
|
+
onChange={handleChange}
|
|
50
|
+
onPressEnter={handlePressEnter}
|
|
51
|
+
/>
|
|
52
|
+
</div>
|
|
53
|
+
);
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
@transient()
|
|
57
|
+
@view('libro-widget-text-view')
|
|
58
|
+
export class LibroTextWidget extends WidgetView {
|
|
59
|
+
override view = LibroTextWidgetComponent;
|
|
60
|
+
bar_style: string;
|
|
61
|
+
description: string;
|
|
62
|
+
description_tooltip: null;
|
|
63
|
+
layout: string;
|
|
64
|
+
orientation: string;
|
|
65
|
+
style: string;
|
|
66
|
+
placeholder: string;
|
|
67
|
+
@prop()
|
|
68
|
+
value: number;
|
|
69
|
+
constructor(
|
|
70
|
+
@inject(ViewOption) props: IWidgetViewProps,
|
|
71
|
+
@inject(LirboContextKey) lirboContextKey: LirboContextKey,
|
|
72
|
+
) {
|
|
73
|
+
super(props, lirboContextKey);
|
|
74
|
+
this.bar_style = props.attributes.bar_style;
|
|
75
|
+
this.description = props.attributes.description;
|
|
76
|
+
this.description_tooltip = props.attributes.description_tooltip;
|
|
77
|
+
this.layout = props.attributes.layout;
|
|
78
|
+
this.orientation = props.attributes.orientation;
|
|
79
|
+
this.style = props.attributes.style;
|
|
80
|
+
this.value = props.attributes.value;
|
|
81
|
+
this.placeholder = props.attributes.placeholder;
|
|
82
|
+
}
|
|
83
|
+
}
|