@oinone/kunlun-vue-widget 6.3.8 → 6.4.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/dist/oinone-kunlun-vue-widget.esm.js +2 -2
- package/dist/types/src/basic/Widget.d.ts +25 -2
- package/dist/types/src/data/ActiveRecordsWidget.d.ts +18 -3
- package/dist/types/src/dsl/DslDefinitionWidget.d.ts +6 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/state/context.d.ts +41 -0
- package/dist/types/src/state/global.d.ts +4 -0
- package/dist/types/src/state/index.d.ts +3 -0
- package/dist/types/src/state/method/action.d.ts +18 -0
- package/dist/types/src/state/method/field.d.ts +3 -0
- package/dist/types/src/state/method/index.d.ts +2 -0
- package/dist/types/src/state/typing.d.ts +105 -0
- package/dist/types/src/state/use-state.d.ts +16 -0
- package/dist/types/src/state/view.d.ts +5 -0
- package/package.json +11 -11
- package/src/basic/VueWidget.ts +2 -2
- package/src/basic/Widget.ts +137 -23
- package/src/data/ActiveRecordsWidget.ts +72 -20
- package/src/dsl/DslDefinitionWidget.ts +27 -7
- package/src/index.ts +1 -0
- package/src/state/context.ts +57 -0
- package/src/state/global.ts +13 -0
- package/src/state/index.ts +3 -0
- package/src/state/method/action.ts +83 -0
- package/src/state/method/field.ts +56 -0
- package/src/state/method/index.ts +2 -0
- package/src/state/typing.ts +169 -0
- package/src/state/use-state.ts +44 -0
- package/src/state/view.ts +58 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ViewType } from '@oinone/kunlun-meta';
|
|
2
|
+
import { ButtonBizStyle, ButtonType } from '@oinone/kunlun-vue-ui-common';
|
|
3
|
+
declare type StateEntity = {
|
|
4
|
+
readonly handle: string;
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
};
|
|
7
|
+
export interface RenderPosition {
|
|
8
|
+
handle: string;
|
|
9
|
+
slotName?: string;
|
|
10
|
+
rowIndex?: number;
|
|
11
|
+
}
|
|
12
|
+
export interface OioViewState extends StateEntity {
|
|
13
|
+
/**
|
|
14
|
+
* Vue生命周期时可能有值,用于获取渲染参数处理属性多态的问题
|
|
15
|
+
*/
|
|
16
|
+
__position: RenderPosition[];
|
|
17
|
+
fullscreen: boolean;
|
|
18
|
+
viewType?: ViewType;
|
|
19
|
+
popupScene?: string;
|
|
20
|
+
createActionBarState(options: {
|
|
21
|
+
handle: string;
|
|
22
|
+
} & Partial<Omit<OioActionBarState, 'handle'>>): OioActionBarState;
|
|
23
|
+
/**
|
|
24
|
+
* 此获取方法仅能用在Vue生命周期,否则无法准确获取真实的ActionBar状态变量
|
|
25
|
+
*/
|
|
26
|
+
getActionBarState(rowIndex?: number): OioActionBarState | undefined;
|
|
27
|
+
pushField(handle: string, rowIndex?: number): void;
|
|
28
|
+
popField(handle: string, rowIndex?: number): void;
|
|
29
|
+
pushAction(handle: string, rowIndex?: number): void;
|
|
30
|
+
popAction(handle: string, rowIndex?: number): void;
|
|
31
|
+
}
|
|
32
|
+
export interface OioActionBarState extends StateEntity {
|
|
33
|
+
inline?: boolean;
|
|
34
|
+
actions: string[];
|
|
35
|
+
visibleActions: string[];
|
|
36
|
+
bizStyle?: string;
|
|
37
|
+
getActionBarBizStyle?(actionHandle: string): {
|
|
38
|
+
type: ButtonType;
|
|
39
|
+
bizStyle: ButtonBizStyle;
|
|
40
|
+
} | undefined;
|
|
41
|
+
}
|
|
42
|
+
export interface OioTableViewState extends OioViewState {
|
|
43
|
+
searchView?: string;
|
|
44
|
+
actionBar?: OioActionBarState;
|
|
45
|
+
actionBars?: Record<string, OioActionBarState>;
|
|
46
|
+
inlineActionBars?: OioActionBarState[];
|
|
47
|
+
table?: string;
|
|
48
|
+
fields?: string[];
|
|
49
|
+
fieldWidgets?: Record<string, string>;
|
|
50
|
+
}
|
|
51
|
+
export interface OioSearchViewState extends OioViewState {
|
|
52
|
+
search?: string;
|
|
53
|
+
fields?: string[];
|
|
54
|
+
fieldWidgets?: Record<string, string>;
|
|
55
|
+
}
|
|
56
|
+
export interface OioFormViewState extends OioViewState {
|
|
57
|
+
draftCode?: string;
|
|
58
|
+
actionBar?: OioActionBarState;
|
|
59
|
+
actionBars?: Record<string, OioActionBarState>;
|
|
60
|
+
form?: string;
|
|
61
|
+
fields?: string[];
|
|
62
|
+
fieldWidgets?: Record<string, string>;
|
|
63
|
+
}
|
|
64
|
+
export interface OioDetailViewState extends OioViewState {
|
|
65
|
+
actionBar?: OioActionBarState;
|
|
66
|
+
actionBars?: Record<string, OioActionBarState>;
|
|
67
|
+
detail?: string;
|
|
68
|
+
fields?: string[];
|
|
69
|
+
fieldWidgets?: Record<string, string>;
|
|
70
|
+
}
|
|
71
|
+
export interface OioCardState extends StateEntity {
|
|
72
|
+
titleProps?: Record<string, unknown>;
|
|
73
|
+
contentProps?: Record<string, unknown>;
|
|
74
|
+
fields?: string[];
|
|
75
|
+
fieldWidgets?: Record<string, string>;
|
|
76
|
+
}
|
|
77
|
+
export interface OioGalleryViewState extends OioViewState {
|
|
78
|
+
searchView?: string;
|
|
79
|
+
actionBar?: OioActionBarState;
|
|
80
|
+
inlineActionBars?: OioActionBarState[];
|
|
81
|
+
gallery?: string;
|
|
82
|
+
cards?: OioCardState[];
|
|
83
|
+
}
|
|
84
|
+
export interface OioTreeViewState extends OioViewState {
|
|
85
|
+
searchView?: string;
|
|
86
|
+
actionBar?: OioActionBarState;
|
|
87
|
+
tree?: string;
|
|
88
|
+
fields?: string[];
|
|
89
|
+
fieldWidgets?: Record<string, string>;
|
|
90
|
+
}
|
|
91
|
+
export declare type OioAnyViewState = OioTableViewState | OioSearchViewState | OioFormViewState | OioDetailViewState | OioGalleryViewState | OioTreeViewState;
|
|
92
|
+
export declare type OioListViewState = OioTableViewState | OioGalleryViewState;
|
|
93
|
+
export declare type OioObjectViewState = OioFormViewState | OioDetailViewState | OioSearchViewState;
|
|
94
|
+
export declare function isTableViewState(state: OioAnyViewState): state is OioTableViewState;
|
|
95
|
+
export declare function isSearchViewState(state: OioAnyViewState): state is OioSearchViewState;
|
|
96
|
+
export declare function isFormViewState(state: OioAnyViewState): state is OioFormViewState;
|
|
97
|
+
export declare function isDetailViewState(state: OioAnyViewState): state is OioDetailViewState;
|
|
98
|
+
export declare function isGalleryViewState(state: OioAnyViewState): state is OioGalleryViewState;
|
|
99
|
+
export declare function isTreeViewState(state: OioAnyViewState): state is OioTreeViewState;
|
|
100
|
+
export declare function isListViewState(state: OioAnyViewState): state is OioListViewState;
|
|
101
|
+
export declare function isObjectViewState(state: OioAnyViewState): state is OioObjectViewState;
|
|
102
|
+
export declare function hasFieldsViewState(state: OioAnyViewState): state is OioTableViewState | OioFormViewState | OioDetailViewState;
|
|
103
|
+
export declare function hasActionBarViewState(state: OioAnyViewState): state is OioTableViewState | OioFormViewState | OioDetailViewState | OioGalleryViewState | OioTreeViewState;
|
|
104
|
+
export declare function hasRowActionBarViewState(state: OioAnyViewState): state is OioTableViewState | OioGalleryViewState;
|
|
105
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { OioGlobalState } from './global';
|
|
2
|
+
import { OioAnyViewState } from './typing';
|
|
3
|
+
export declare function useOioState(): {
|
|
4
|
+
globalState: OioGlobalState;
|
|
5
|
+
viewState: OioAnyViewState | undefined;
|
|
6
|
+
createViewState: (handle: string) => OioAnyViewState;
|
|
7
|
+
getViewState: (handle: string) => OioAnyViewState | undefined;
|
|
8
|
+
clearViewState: (handle: string) => OioAnyViewState | undefined;
|
|
9
|
+
};
|
|
10
|
+
export declare function useOioState(handle: string): {
|
|
11
|
+
globalState: OioGlobalState;
|
|
12
|
+
viewState: OioAnyViewState | undefined;
|
|
13
|
+
createViewState: () => OioAnyViewState;
|
|
14
|
+
getViewState: () => OioAnyViewState | undefined;
|
|
15
|
+
clearViewState: () => OioAnyViewState | undefined;
|
|
16
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OioAnyViewState } from './typing';
|
|
2
|
+
export declare function createViewState(handle: string): OioAnyViewState;
|
|
3
|
+
export declare function getViewState(handle?: string): OioAnyViewState | undefined;
|
|
4
|
+
export declare function setViewState(state: OioAnyViewState): void;
|
|
5
|
+
export declare function clearViewState(handle?: string): OioAnyViewState | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oinone/kunlun-vue-widget",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"main": "index.ts",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prebuild": "rimraf dist",
|
|
@@ -11,18 +11,18 @@
|
|
|
11
11
|
"x-postpublish": "node ../../scripts/postpublish.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@oinone/kunlun-
|
|
15
|
-
"@oinone/kunlun-vue-ui-common": "6.3.8"
|
|
14
|
+
"@oinone/kunlun-vue-ui-common": "6.4.0"
|
|
16
15
|
},
|
|
17
16
|
"devDependencies": {
|
|
18
|
-
"@oinone/kunlun-
|
|
19
|
-
"@oinone/kunlun-
|
|
20
|
-
"@oinone/kunlun-
|
|
21
|
-
"@oinone/kunlun-
|
|
22
|
-
"@oinone/kunlun-
|
|
23
|
-
"@oinone/kunlun-
|
|
24
|
-
"@oinone/kunlun-
|
|
25
|
-
"@oinone/kunlun-
|
|
17
|
+
"@oinone/kunlun-config": "~6.4.0",
|
|
18
|
+
"@oinone/kunlun-dsl": "~6.4.0",
|
|
19
|
+
"@oinone/kunlun-engine": "~6.4.0",
|
|
20
|
+
"@oinone/kunlun-event": "~6.4.0",
|
|
21
|
+
"@oinone/kunlun-meta": "~6.4.0",
|
|
22
|
+
"@oinone/kunlun-router": "~6.4.0",
|
|
23
|
+
"@oinone/kunlun-shared": "~6.4.0",
|
|
24
|
+
"@oinone/kunlun-spi": "~6.4.0",
|
|
25
|
+
"@oinone/kunlun-state": "~6.4.0",
|
|
26
26
|
"@types/lodash": "4.14.182",
|
|
27
27
|
"@types/lodash-es": "4.17.6",
|
|
28
28
|
"lodash": "4.17.21",
|
package/src/basic/VueWidget.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { genStaticPath, translateValueByKey, WidgetConstructor, WidgetProps } from '@oinone/kunlun-engine';
|
|
2
|
-
import {
|
|
3
|
-
import { ComponentPublicInstance
|
|
2
|
+
import { uniqueKeyGenerator } from '@oinone/kunlun-shared';
|
|
3
|
+
import { ComponentPublicInstance } from '@vue/runtime-core';
|
|
4
4
|
import {
|
|
5
5
|
Component,
|
|
6
6
|
ComponentOptions,
|
package/src/basic/Widget.ts
CHANGED
|
@@ -3,10 +3,17 @@ import { instantiate } from '@oinone/kunlun-shared';
|
|
|
3
3
|
import { BehaviorSubject, Subject, Subscription } from '@oinone/kunlun-state';
|
|
4
4
|
import { InnerWidgetType } from '../typing/typing';
|
|
5
5
|
|
|
6
|
+
type WidgetTypeKey = keyof typeof InnerWidgetType;
|
|
7
|
+
|
|
8
|
+
type AnySubject<T = unknown> = Subject<T> | BehaviorSubject<T>;
|
|
9
|
+
|
|
6
10
|
interface NameContextMap<T> {
|
|
7
11
|
paramName_NameMap: Map<string, Symbol>;
|
|
8
12
|
subject: BehaviorSubject<T> | Subject<T>;
|
|
9
13
|
value?: T;
|
|
14
|
+
option?: {
|
|
15
|
+
scope?: WidgetTypeKey;
|
|
16
|
+
};
|
|
10
17
|
}
|
|
11
18
|
|
|
12
19
|
interface BaseWidgetSubjection<T> {
|
|
@@ -46,6 +53,8 @@ export abstract class Widget<Props extends WidgetProps = WidgetProps, R = unknow
|
|
|
46
53
|
|
|
47
54
|
private $$props?: string[];
|
|
48
55
|
|
|
56
|
+
private $$subNames?: string[];
|
|
57
|
+
|
|
49
58
|
private static Attribute(params?: { displayName?: string; render?: boolean }) {
|
|
50
59
|
return <T extends Widget, K>(target: T, nativeName: string, description?: TypedPropertyDescriptor<K>) => {
|
|
51
60
|
const widgetType = target.constructor;
|
|
@@ -98,21 +107,35 @@ export abstract class Widget<Props extends WidgetProps = WidgetProps, R = unknow
|
|
|
98
107
|
};
|
|
99
108
|
}
|
|
100
109
|
|
|
101
|
-
private static Sub<T>(
|
|
110
|
+
private static Sub<T>(
|
|
111
|
+
name: Symbol,
|
|
112
|
+
SubjectType: { new (T): Subject<T> | BehaviorSubject<T> },
|
|
113
|
+
value?: T,
|
|
114
|
+
option?: { scope?: WidgetTypeKey }
|
|
115
|
+
) {
|
|
102
116
|
return <K extends Widget>(target: K, paramName: string) => {
|
|
103
117
|
const nameContextMap = this.nameContextMap.get(name);
|
|
104
118
|
if (!nameContextMap) {
|
|
105
119
|
const subject = new SubjectType(value);
|
|
106
120
|
const paramName_NameMap = new Map<string, Symbol>();
|
|
107
121
|
paramName_NameMap.set(paramName, name);
|
|
122
|
+
|
|
108
123
|
this.nameContextMap.set(name, {
|
|
109
124
|
paramName_NameMap,
|
|
110
125
|
subject,
|
|
111
|
-
value
|
|
126
|
+
value,
|
|
127
|
+
option
|
|
112
128
|
} as NameContextMap<unknown>);
|
|
113
129
|
} else if (nameContextMap && !nameContextMap.paramName_NameMap.get(paramName)) {
|
|
114
130
|
nameContextMap.paramName_NameMap.set(paramName, name);
|
|
115
131
|
}
|
|
132
|
+
|
|
133
|
+
const widgetType = target.constructor;
|
|
134
|
+
const $$subNames = widgetType.prototype.$$subNames || [];
|
|
135
|
+
if (!$$subNames.includes(paramName)) {
|
|
136
|
+
$$subNames.push(paramName);
|
|
137
|
+
}
|
|
138
|
+
target.$$subNames = $$subNames;
|
|
116
139
|
};
|
|
117
140
|
}
|
|
118
141
|
|
|
@@ -121,6 +144,7 @@ export abstract class Widget<Props extends WidgetProps = WidgetProps, R = unknow
|
|
|
121
144
|
*
|
|
122
145
|
* @param {Symbol} name 唯一标示
|
|
123
146
|
* @param {unknown} value? 默认值
|
|
147
|
+
* @param {scope?: WidgetTypeKey} option? 作用域检查,如果设置了该值,那么发布的时候会携带发布者的widget实例,订阅的时候会检查发布者的widget实例是否和订阅者在同一个作用域下,如果是,那么才会触发订阅函数
|
|
124
148
|
*
|
|
125
149
|
* @example
|
|
126
150
|
*
|
|
@@ -146,8 +170,8 @@ export abstract class Widget<Props extends WidgetProps = WidgetProps, R = unknow
|
|
|
146
170
|
* }
|
|
147
171
|
*
|
|
148
172
|
*/
|
|
149
|
-
protected static BehaviorSubContext(name: Symbol, value?: unknown) {
|
|
150
|
-
return Widget.Sub(name, BehaviorSubject, value);
|
|
173
|
+
protected static BehaviorSubContext(name: Symbol, value?: unknown, option?: { scope?: WidgetTypeKey }) {
|
|
174
|
+
return Widget.Sub(name, BehaviorSubject, value, option);
|
|
151
175
|
}
|
|
152
176
|
|
|
153
177
|
/**
|
|
@@ -155,9 +179,10 @@ export abstract class Widget<Props extends WidgetProps = WidgetProps, R = unknow
|
|
|
155
179
|
*
|
|
156
180
|
* @param {Symbol} name 唯一标示
|
|
157
181
|
* @param {unknown} value? 默认值
|
|
182
|
+
* @param {scope?: WidgetTypeKey} option? 作用域检查,如果设置了该值,那么发布订阅只会在同一个作用域下的widget之间进行
|
|
158
183
|
*/
|
|
159
|
-
protected static SubContext(name: Symbol, value?: unknown) {
|
|
160
|
-
return Widget.Sub(name, Subject, value);
|
|
184
|
+
protected static SubContext(name: Symbol, value?: unknown, option?: { scope?: WidgetTypeKey }) {
|
|
185
|
+
return Widget.Sub(name, Subject, value, option);
|
|
161
186
|
}
|
|
162
187
|
|
|
163
188
|
/**
|
|
@@ -320,23 +345,6 @@ export abstract class Widget<Props extends WidgetProps = WidgetProps, R = unknow
|
|
|
320
345
|
this.config = config;
|
|
321
346
|
Widget.widgetMap.set(this.getHandle(), this);
|
|
322
347
|
|
|
323
|
-
Widget.nameContextMap.forEach((contextMap) => {
|
|
324
|
-
const { subject, paramName_NameMap } = contextMap;
|
|
325
|
-
const d: BaseWidgetSubjection<unknown> = {
|
|
326
|
-
subscribe: (func) => {
|
|
327
|
-
const subscription = subject.subscribe((data) => {
|
|
328
|
-
func(data);
|
|
329
|
-
});
|
|
330
|
-
this.subscriptionMap.set(Symbol('random'), subscription);
|
|
331
|
-
return subscription;
|
|
332
|
-
},
|
|
333
|
-
subject
|
|
334
|
-
};
|
|
335
|
-
paramName_NameMap.forEach((_name, paramName) => {
|
|
336
|
-
this[paramName] = d;
|
|
337
|
-
});
|
|
338
|
-
});
|
|
339
|
-
|
|
340
348
|
if (this.$$innerWidgetType) {
|
|
341
349
|
const parentWidget = this.getParentWidget();
|
|
342
350
|
if (parentWidget && parentWidget.$$innerWidgetType) {
|
|
@@ -344,9 +352,104 @@ export abstract class Widget<Props extends WidgetProps = WidgetProps, R = unknow
|
|
|
344
352
|
}
|
|
345
353
|
}
|
|
346
354
|
|
|
355
|
+
this.startSubscription();
|
|
356
|
+
|
|
347
357
|
return this;
|
|
348
358
|
}
|
|
349
359
|
|
|
360
|
+
/**
|
|
361
|
+
* 启动订阅
|
|
362
|
+
*/
|
|
363
|
+
private startSubscription() {
|
|
364
|
+
if (!this.$$subNames?.length) {
|
|
365
|
+
return;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
for (const [, contextMap] of Widget.nameContextMap) {
|
|
369
|
+
for (const [paramName] of contextMap.paramName_NameMap) {
|
|
370
|
+
if (this.$$subNames?.includes(paramName)) {
|
|
371
|
+
this[paramName] = this.createWidgetSubjection(contextMap);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* 包装发布者事件
|
|
379
|
+
* 如果启动了作用域检查,那么发布的时候会携带发布者的widget实例
|
|
380
|
+
**/
|
|
381
|
+
private wrapSubjectWithScope(subject: AnySubject, scope?: WidgetTypeKey): AnySubject {
|
|
382
|
+
if (!scope) {
|
|
383
|
+
return subject;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const next = subject.next;
|
|
387
|
+
const self = this;
|
|
388
|
+
|
|
389
|
+
subject.next = function (payload) {
|
|
390
|
+
next.call(
|
|
391
|
+
subject,
|
|
392
|
+
payload.__publisherWidget
|
|
393
|
+
? payload
|
|
394
|
+
: {
|
|
395
|
+
payload,
|
|
396
|
+
__publisherWidget: self
|
|
397
|
+
}
|
|
398
|
+
);
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
const behaviorSubject = subject as BehaviorSubject<any>;
|
|
402
|
+
|
|
403
|
+
if (behaviorSubject.getValue) {
|
|
404
|
+
const getValue = behaviorSubject.getValue;
|
|
405
|
+
behaviorSubject.getValue = function () {
|
|
406
|
+
const value = getValue.call(behaviorSubject);
|
|
407
|
+
if (value.__publisherWidget) {
|
|
408
|
+
return value.payload;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
return value;
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return subject as AnySubject;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* 创建发布订阅对象
|
|
420
|
+
*/
|
|
421
|
+
private createWidgetSubjection(contextMap: NameContextMap<unknown>): BaseWidgetSubjection<unknown> {
|
|
422
|
+
const { subject, option } = contextMap;
|
|
423
|
+
|
|
424
|
+
return {
|
|
425
|
+
subscribe: (func) => {
|
|
426
|
+
const subscription = subject.subscribe((data: any) => {
|
|
427
|
+
/**
|
|
428
|
+
* 订阅
|
|
429
|
+
* 如果启动了作用域检查,那么订阅的时候会检查发布者的widget实例是否和订阅者在同一个作用域下
|
|
430
|
+
*/
|
|
431
|
+
if (option?.scope && data?.__publisherWidget) {
|
|
432
|
+
if (this.isSameScopeWidget(data.__publisherWidget, option?.scope)) {
|
|
433
|
+
func(data.payload);
|
|
434
|
+
}
|
|
435
|
+
} else {
|
|
436
|
+
func(option?.scope && data?.__publisherWidget ? data.payload : data);
|
|
437
|
+
}
|
|
438
|
+
});
|
|
439
|
+
this.subscriptionMap.set(Symbol('random'), subscription);
|
|
440
|
+
return subscription;
|
|
441
|
+
},
|
|
442
|
+
subject: this.wrapSubjectWithScope(subject, option?.scope)
|
|
443
|
+
} as BaseWidgetSubjection<unknown>;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
private isSameScopeWidget(otherWidget: Widget, widgetType: WidgetTypeKey): boolean {
|
|
447
|
+
const selfWidget = this.getParentWidgetByType(widgetType);
|
|
448
|
+
const otherOther = otherWidget.getParentWidgetByType(widgetType);
|
|
449
|
+
|
|
450
|
+
return (selfWidget === otherOther && selfWidget !== null) || this.getHandle() === otherOther?.getHandle();
|
|
451
|
+
}
|
|
452
|
+
|
|
350
453
|
/**
|
|
351
454
|
* 销毁widget
|
|
352
455
|
*
|
|
@@ -527,6 +630,17 @@ export abstract class Widget<Props extends WidgetProps = WidgetProps, R = unknow
|
|
|
527
630
|
return this.parent;
|
|
528
631
|
}
|
|
529
632
|
|
|
633
|
+
private getParentWidgetByType(type: WidgetTypeKey) {
|
|
634
|
+
let current = this.parent;
|
|
635
|
+
while (current) {
|
|
636
|
+
if (current.$$innerWidgetType === type) {
|
|
637
|
+
return current;
|
|
638
|
+
}
|
|
639
|
+
current = current.parent;
|
|
640
|
+
}
|
|
641
|
+
return null;
|
|
642
|
+
}
|
|
643
|
+
|
|
530
644
|
/**
|
|
531
645
|
* 获取子元素
|
|
532
646
|
*/
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
UpdateEntity
|
|
18
18
|
} from '@oinone/kunlun-engine';
|
|
19
19
|
import { Widget } from '../basic';
|
|
20
|
+
import { OioAnyViewState, useOioState } from '../state';
|
|
20
21
|
import { PathWidget, PathWidgetProps } from './PathWidget';
|
|
21
22
|
|
|
22
23
|
export interface ActiveRecordsWidgetProps extends PathWidgetProps {
|
|
@@ -30,6 +31,20 @@ export interface ActiveRecordsWidgetProps extends PathWidgetProps {
|
|
|
30
31
|
export class ActiveRecordsWidget<
|
|
31
32
|
Props extends ActiveRecordsWidgetProps = ActiveRecordsWidgetProps
|
|
32
33
|
> extends PathWidget<Props> {
|
|
34
|
+
/**
|
|
35
|
+
* 视图级别状态, 在 beforeMounted 后可获取到有效值
|
|
36
|
+
* @protected
|
|
37
|
+
*/
|
|
38
|
+
protected viewState: OioAnyViewState | undefined;
|
|
39
|
+
|
|
40
|
+
public getViewState(): OioAnyViewState | undefined {
|
|
41
|
+
return this.viewState;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public setViewState(state: OioAnyViewState) {
|
|
45
|
+
this.viewState = state;
|
|
46
|
+
}
|
|
47
|
+
|
|
33
48
|
public initialize(props: Props) {
|
|
34
49
|
super.initialize(props);
|
|
35
50
|
const { dataSource, activeRecords } = props;
|
|
@@ -175,10 +190,11 @@ export class ActiveRecordsWidget<
|
|
|
175
190
|
*
|
|
176
191
|
* @param records 数据
|
|
177
192
|
* @param predict 推送判定
|
|
193
|
+
* @param index 推送到指定位置; 0 表示插入到数组头; 未传入或-1 表示插入到数组尾;
|
|
178
194
|
*/
|
|
179
195
|
@Widget.Method()
|
|
180
196
|
@Widget.Provide()
|
|
181
|
-
public pushDataSource(records: ActiveRecords, predict?: PushActiveRecordsPredict) {
|
|
197
|
+
public pushDataSource(records: ActiveRecords, predict?: PushActiveRecordsPredict, index?: number) {
|
|
182
198
|
if (this.parentPushDataSource && this.getCurrentDataSource() === undefined) {
|
|
183
199
|
this.parentPushDataSource(records, predict);
|
|
184
200
|
} else {
|
|
@@ -188,7 +204,7 @@ export class ActiveRecordsWidget<
|
|
|
188
204
|
pushPredict = ActiveRecordsOperator.defaultPushPredict.bind(submitCache);
|
|
189
205
|
}
|
|
190
206
|
const nextDataSource = ActiveRecordsOperator.operator(this.getCurrentDataSource() || undefined, this.submitCache)
|
|
191
|
-
.push(records, pushPredict)
|
|
207
|
+
.push(records, pushPredict, index)
|
|
192
208
|
.get();
|
|
193
209
|
if (!submitCache) {
|
|
194
210
|
this.setCurrentDataSource(nextDataSource);
|
|
@@ -314,24 +330,6 @@ export class ActiveRecordsWidget<
|
|
|
314
330
|
}
|
|
315
331
|
}
|
|
316
332
|
|
|
317
|
-
|
|
318
|
-
@Widget.Method()
|
|
319
|
-
@Widget.Inject('createDataSourceByEntity')
|
|
320
|
-
protected parentCreateDataSourceByEntity: PushActiveRecordsFunction | undefined;
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
@Widget.Method()
|
|
324
|
-
@Widget.Provide()
|
|
325
|
-
public createDataSourceByEntity(records:ActiveRecords,predict?:PushActiveRecordsPredict){
|
|
326
|
-
if (this.parentCreateDataSourceByEntity && this.getCurrentDataSource() === undefined) {
|
|
327
|
-
this.parentCreateDataSourceByEntity(records, predict);
|
|
328
|
-
} else {
|
|
329
|
-
const nextDataSource = Array.isArray(records) ? records : [records];
|
|
330
|
-
const oldDataSource = this.getCurrentDataSource() || [];
|
|
331
|
-
this.setCurrentDataSource([...nextDataSource, ...oldDataSource]);
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
|
|
335
333
|
@Widget.Method()
|
|
336
334
|
@Widget.Inject('flushDataSource')
|
|
337
335
|
protected parentFlushDataSource: FlushActiveRecordsFunction | undefined;
|
|
@@ -569,4 +567,58 @@ export class ActiveRecordsWidget<
|
|
|
569
567
|
this.currentActiveRecords = [];
|
|
570
568
|
}
|
|
571
569
|
}
|
|
570
|
+
|
|
571
|
+
protected $$initViewStatePosition(state: OioAnyViewState): void {
|
|
572
|
+
// do nothing.
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
protected $$clearViewStatePosition(state: OioAnyViewState): void {
|
|
576
|
+
// do nothing.
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
protected $$initViewState(state: OioAnyViewState): void {
|
|
580
|
+
// do nothing.
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
protected $$clearViewState(state: OioAnyViewState): void {
|
|
584
|
+
// do nothing.
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
protected $$beforeMount() {
|
|
588
|
+
super.$$beforeMount();
|
|
589
|
+
let isInitStatePosition = false;
|
|
590
|
+
if (!this.viewState) {
|
|
591
|
+
this.viewState = useOioState().viewState;
|
|
592
|
+
if (this.viewState) {
|
|
593
|
+
isInitStatePosition = true;
|
|
594
|
+
this.$$initViewStatePosition(this.viewState);
|
|
595
|
+
this.$$initViewState(this.viewState);
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
if (this.viewState && !isInitStatePosition) {
|
|
599
|
+
this.$$initViewStatePosition(this.viewState);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
protected $$mounted() {
|
|
604
|
+
super.$$mounted();
|
|
605
|
+
if (this.viewState) {
|
|
606
|
+
this.$$clearViewStatePosition(this.viewState);
|
|
607
|
+
this.$$clearViewState(this.viewState);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
protected $$beforeUnmount() {
|
|
612
|
+
super.$$beforeUnmount();
|
|
613
|
+
if (this.viewState) {
|
|
614
|
+
this.$$initViewStatePosition(this.viewState);
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
protected $$unmounted() {
|
|
619
|
+
super.$$unmounted();
|
|
620
|
+
if (this.viewState) {
|
|
621
|
+
this.$$clearViewStatePosition(this.viewState);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
572
624
|
}
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
RuntimeContextManager,
|
|
8
8
|
RuntimeModelField
|
|
9
9
|
} from '@oinone/kunlun-engine';
|
|
10
|
-
import { BooleanHelper } from '@oinone/kunlun-shared';
|
|
10
|
+
import { BooleanHelper, CSSClass, CSSStyle } from '@oinone/kunlun-shared';
|
|
11
11
|
import { isNil } from 'lodash-es';
|
|
12
12
|
import { Widget } from '../basic';
|
|
13
13
|
import { InvisibleSupported, isAllInvisible } from '../feature';
|
|
@@ -30,7 +30,7 @@ export interface DslDefinitionWidgetProps extends DslRenderWidgetProps {
|
|
|
30
30
|
*/
|
|
31
31
|
inline?: boolean;
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* 自动渲染组件
|
|
34
34
|
*/
|
|
35
35
|
automatic?: boolean;
|
|
36
36
|
}
|
|
@@ -52,6 +52,16 @@ export class DslDefinitionWidget<Props extends DslDefinitionWidgetProps = DslDef
|
|
|
52
52
|
return this.metadataHandle;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
@Widget.Reactive()
|
|
56
|
+
protected get class(): CSSClass | undefined {
|
|
57
|
+
return this.getDsl().class;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@Widget.Reactive()
|
|
61
|
+
protected get style(): string | Partial<CSSStyle> | undefined {
|
|
62
|
+
return this.getDsl().style;
|
|
63
|
+
}
|
|
64
|
+
|
|
55
65
|
@Widget.Reactive()
|
|
56
66
|
protected rootHandle: string | undefined;
|
|
57
67
|
|
|
@@ -128,26 +138,36 @@ export class DslDefinitionWidget<Props extends DslDefinitionWidgetProps = DslDef
|
|
|
128
138
|
}
|
|
129
139
|
|
|
130
140
|
public get metadataRuntimeContext(): RuntimeContext {
|
|
141
|
+
const runtimeContext = this.metadataRuntimeContextNullable;
|
|
142
|
+
if (!runtimeContext) {
|
|
143
|
+
throw new Error('Invalid metadata runtime context.');
|
|
144
|
+
}
|
|
145
|
+
return runtimeContext;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public get metadataRuntimeContextNullable(): RuntimeContext | undefined {
|
|
131
149
|
const { metadataHandle } = this;
|
|
132
150
|
let runtimeContext: RuntimeContext | undefined;
|
|
133
151
|
if (metadataHandle) {
|
|
134
152
|
runtimeContext = RuntimeContextManager.get(metadataHandle);
|
|
135
153
|
}
|
|
154
|
+
return runtimeContext;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public get rootRuntimeContext(): RuntimeContext {
|
|
158
|
+
const runtimeContext = this.rootRuntimeContextNullable;
|
|
136
159
|
if (!runtimeContext) {
|
|
137
|
-
throw new Error('Invalid
|
|
160
|
+
throw new Error('Invalid root runtime context.');
|
|
138
161
|
}
|
|
139
162
|
return runtimeContext;
|
|
140
163
|
}
|
|
141
164
|
|
|
142
|
-
public get
|
|
165
|
+
public get rootRuntimeContextNullable(): RuntimeContext | undefined {
|
|
143
166
|
const { rootHandle } = this;
|
|
144
167
|
let runtimeContext: RuntimeContext | undefined;
|
|
145
168
|
if (rootHandle) {
|
|
146
169
|
runtimeContext = RuntimeContextManager.get(rootHandle);
|
|
147
170
|
}
|
|
148
|
-
if (!runtimeContext) {
|
|
149
|
-
throw new Error('Invalid root runtime context.');
|
|
150
|
-
}
|
|
151
171
|
return runtimeContext;
|
|
152
172
|
}
|
|
153
173
|
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ViewType } from '@oinone/kunlun-meta';
|
|
2
|
+
import { computed, ComputedRef, inject, InjectionKey, provide } from 'vue';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 元数据上下文
|
|
6
|
+
*/
|
|
7
|
+
export interface MetaContext {
|
|
8
|
+
viewType: ComputedRef<ViewType>;
|
|
9
|
+
model: ComputedRef<string>;
|
|
10
|
+
modelName: ComputedRef<string>;
|
|
11
|
+
module: ComputedRef<string>;
|
|
12
|
+
moduleName: ComputedRef<string>;
|
|
13
|
+
metadataHandle: ComputedRef<string>;
|
|
14
|
+
rootHandle: ComputedRef<string>;
|
|
15
|
+
parentHandle: ComputedRef<string>;
|
|
16
|
+
slotName: ComputedRef<string | undefined>;
|
|
17
|
+
inline: ComputedRef<boolean>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 默认元数据上下文
|
|
22
|
+
*/
|
|
23
|
+
export const defaultMetaContext = {
|
|
24
|
+
viewType: computed(() => ViewType.Form),
|
|
25
|
+
model: computed(() => ''),
|
|
26
|
+
modelName: computed(() => ''),
|
|
27
|
+
module: computed(() => ''),
|
|
28
|
+
moduleName: computed(() => ''),
|
|
29
|
+
metadataHandle: computed(() => ''),
|
|
30
|
+
rootHandle: computed(() => ''),
|
|
31
|
+
parentHandle: computed(() => ''),
|
|
32
|
+
slotName: computed(() => undefined),
|
|
33
|
+
inline: computed(() => false)
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 元数据Provider/Inject键
|
|
38
|
+
*/
|
|
39
|
+
const MetaContextKey: InjectionKey<MetaContext> = Symbol('MetaContext');
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 提供元数据上下文
|
|
43
|
+
* @param state 元数据可选项
|
|
44
|
+
*/
|
|
45
|
+
export const useProviderMetaContext = (state: Partial<MetaContext>): void => {
|
|
46
|
+
provide(MetaContextKey, {
|
|
47
|
+
...defaultMetaContext,
|
|
48
|
+
...state
|
|
49
|
+
});
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 获取元数据上下文
|
|
54
|
+
*/
|
|
55
|
+
export const useInjectMetaContext = (): MetaContext => {
|
|
56
|
+
return inject(MetaContextKey, defaultMetaContext);
|
|
57
|
+
};
|