@nocobase/client-v2 2.1.0-beta.23 → 2.1.0-beta.25
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/es/BaseApplication.d.ts +1 -0
- package/es/flow/actions/dataScopeFilter.d.ts +9 -0
- package/es/flow/components/Grid/index.d.ts +5 -3
- package/es/flow/internal/utils/rebuildFieldSubModel.d.ts +2 -1
- package/es/flow/models/base/GridModel.d.ts +19 -2
- package/es/flow/models/blocks/filter-form/FilterFormGridModel.d.ts +1 -0
- package/es/flow/models/fields/JSFieldModel.d.ts +5 -0
- package/es/index.mjs +100 -100
- package/lib/index.js +100 -100
- package/package.json +6 -5
- package/src/BaseApplication.tsx +4 -0
- package/src/__tests__/globalDeps.test.ts +1 -0
- package/src/__tests__/remotePlugins.test.ts +27 -0
- package/src/flow/actions/__tests__/dataScopeFilter.test.ts +158 -0
- package/src/flow/actions/dataScope.tsx +6 -4
- package/src/flow/actions/dataScopeFilter.ts +70 -0
- package/src/flow/actions/setTargetDataScope.tsx +6 -5
- package/src/flow/components/Grid/index.tsx +66 -20
- package/src/flow/internal/utils/__tests__/rebuildFieldSubModel.test.ts +77 -2
- package/src/flow/internal/utils/rebuildFieldSubModel.ts +21 -5
- package/src/flow/models/base/BlockGridModel.tsx +2 -2
- package/src/flow/models/base/GridModel.tsx +428 -195
- package/src/flow/models/base/__tests__/BlockGridModel.dragOverlayConfig.test.ts +44 -0
- package/src/flow/models/base/__tests__/GridModel.computeOverlayRect.test.ts +29 -0
- package/src/flow/models/base/__tests__/GridModel.dragSnapshotContainer.test.ts +181 -2
- package/src/flow/models/base/__tests__/GridModel.resizeLayout.test.ts +124 -0
- package/src/flow/models/base/__tests__/GridModel.visibleLayout.test.ts +55 -15
- package/src/flow/models/blocks/details/DetailsGridModel.tsx +6 -6
- package/src/flow/models/blocks/filter-form/FilterFormBlockModel.tsx +9 -5
- package/src/flow/models/blocks/filter-form/FilterFormGridModel.tsx +54 -14
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormBlockModel.cleanup.test.ts +138 -0
- package/src/flow/models/blocks/filter-form/__tests__/FilterFormGridModel.toggleFormFieldsCollapse.test.ts +45 -0
- package/src/flow/models/blocks/form/FormGridModel.tsx +6 -6
- package/src/flow/models/blocks/form/__tests__/FormBlockModel.test.tsx +22 -0
- package/src/flow/models/blocks/table/JSColumnModel.tsx +30 -2
- package/src/flow/models/blocks/table/TableBlockModel.tsx +8 -1
- package/src/flow/models/blocks/table/TableColumnModel.tsx +1 -0
- package/src/flow/models/blocks/table/__tests__/JSColumnModel.test.tsx +51 -0
- package/src/flow/models/blocks/table/__tests__/TableBlockModel.quickEditRefresh.test.ts +49 -0
- package/src/flow/models/fields/JSFieldModel.tsx +54 -14
- package/src/utils/globalDeps.ts +4 -0
- package/src/utils/requirejs.ts +1 -1
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { ElementProxy, tExpr, createSafeWindow, createSafeDocument, createSafeNavigator } from '@nocobase/flow-engine';
|
|
11
|
-
import React, { useEffect
|
|
11
|
+
import React, { useEffect } from 'react';
|
|
12
12
|
import { FieldModel } from '../base/FieldModel';
|
|
13
13
|
import { resolveRunJsParams } from '../utils/resolveRunJsParams';
|
|
14
14
|
import { CodeEditor } from '../../components/code-editor';
|
|
@@ -41,6 +41,10 @@ ctx.render(<JsReadonlyField />);
|
|
|
41
41
|
*/
|
|
42
42
|
export class JSFieldModel extends FieldModel {
|
|
43
43
|
private _mountedOnce = false; // prevent first-mount double-run
|
|
44
|
+
private _lastRenderedElement?: HTMLSpanElement | null;
|
|
45
|
+
private _pendingRenderedElement?: HTMLSpanElement | null;
|
|
46
|
+
private _lastRunJs?: { code: string; value: any; element: HTMLSpanElement | null };
|
|
47
|
+
|
|
44
48
|
getInputArgs() {
|
|
45
49
|
const field = this.context.collectionField;
|
|
46
50
|
if (field?.isAssociationField?.()) {
|
|
@@ -75,19 +79,10 @@ export class JSFieldModel extends FieldModel {
|
|
|
75
79
|
* 说明:fork 实例在表格逐行渲染时会复用该逻辑,确保按值更新。
|
|
76
80
|
*/
|
|
77
81
|
useHooksBeforeRender() {
|
|
78
|
-
// 单一副作用:当 code 或 value 变化,且二者都已就绪时执行一次
|
|
79
|
-
// 通过记忆上次运行的输入,避免相同输入导致的重复执行
|
|
80
82
|
const codeParam = this.getStepParams('jsSettings', 'runJs')?.code as string | undefined;
|
|
81
83
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
82
|
-
const lastRunRef = useRef<{ code: string; value: any } | null>(null);
|
|
83
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
84
84
|
useEffect(() => {
|
|
85
|
-
|
|
86
|
-
const codeNow = (typeof codeParam === 'string' && codeParam.trim().length ? codeParam : DEFAULT_CODE).trim();
|
|
87
|
-
const last = lastRunRef.current;
|
|
88
|
-
if (last && last.code === codeNow && last.value === valueNow) return;
|
|
89
|
-
lastRunRef.current = { code: codeNow, value: valueNow };
|
|
90
|
-
this.applyFlow('jsSettings');
|
|
85
|
+
this.refreshRenderedElement(this.context.ref?.current as HTMLSpanElement | null);
|
|
91
86
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
92
87
|
}, [codeParam, this.props.value]);
|
|
93
88
|
}
|
|
@@ -95,8 +90,52 @@ export class JSFieldModel extends FieldModel {
|
|
|
95
90
|
/**
|
|
96
91
|
* 渲染一个占位容器,供 JS 脚本写入内容
|
|
97
92
|
*/
|
|
93
|
+
private getRunJsCode() {
|
|
94
|
+
const codeParam = this.getStepParams('jsSettings', 'runJs')?.code as string | undefined;
|
|
95
|
+
return (typeof codeParam === 'string' && codeParam.trim().length ? codeParam : DEFAULT_CODE).trim();
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private refreshRenderedElement(element: HTMLSpanElement | null) {
|
|
99
|
+
if (!element || this._pendingRenderedElement === element) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
this._pendingRenderedElement = element;
|
|
104
|
+
const ref = this.context.ref as React.MutableRefObject<HTMLSpanElement | null>;
|
|
105
|
+
|
|
106
|
+
queueMicrotask(() => {
|
|
107
|
+
if (this._pendingRenderedElement === element) {
|
|
108
|
+
this._pendingRenderedElement = null;
|
|
109
|
+
}
|
|
110
|
+
if (ref.current !== element) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const code = this.getRunJsCode();
|
|
114
|
+
const value = this.props.value;
|
|
115
|
+
const last = this._lastRunJs;
|
|
116
|
+
if (last && last.element === element && last.code === code && Object.is(last.value, value)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this._lastRunJs = { code, value, element };
|
|
120
|
+
void this.applyFlow('jsSettings');
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
98
124
|
render() {
|
|
99
|
-
|
|
125
|
+
const ref = this.context.ref as React.MutableRefObject<HTMLSpanElement | null>;
|
|
126
|
+
const assignRef = (element: HTMLSpanElement | null) => {
|
|
127
|
+
ref.current = element;
|
|
128
|
+
if (!element) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const elementChanged = this._lastRenderedElement && this._lastRenderedElement !== element;
|
|
133
|
+
this._lastRenderedElement = element;
|
|
134
|
+
if (elementChanged || !this._mountedOnce) {
|
|
135
|
+
this.refreshRenderedElement(element);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
return <span ref={assignRef} style={{ display: 'inline-block', maxWidth: '100%' }} />;
|
|
100
139
|
}
|
|
101
140
|
|
|
102
141
|
/**
|
|
@@ -106,7 +145,7 @@ export class JSFieldModel extends FieldModel {
|
|
|
106
145
|
protected onMount() {
|
|
107
146
|
if (this._mountedOnce) {
|
|
108
147
|
if (this.context.ref?.current) {
|
|
109
|
-
this.
|
|
148
|
+
this.refreshRenderedElement(this.context.ref.current as HTMLSpanElement);
|
|
110
149
|
}
|
|
111
150
|
}
|
|
112
151
|
this._mountedOnce = true;
|
|
@@ -165,7 +204,8 @@ JSFieldModel.registerFlow({
|
|
|
165
204
|
// 暴露 element 与 value 到运行上下文
|
|
166
205
|
ctx.onRefReady(ctx.ref, async (element) => {
|
|
167
206
|
ctx.defineProperty('element', {
|
|
168
|
-
get: () => new ElementProxy(element),
|
|
207
|
+
get: () => new ElementProxy((ctx.ref?.current as HTMLElement | null) || element),
|
|
208
|
+
cache: false,
|
|
169
209
|
});
|
|
170
210
|
ctx.defineProperty('value', {
|
|
171
211
|
get: () => ctx.model.props?.value,
|
package/src/utils/globalDeps.ts
CHANGED
|
@@ -15,6 +15,7 @@ import * as formilyReactive from '@formily/reactive';
|
|
|
15
15
|
import * as formilyShared from '@formily/shared';
|
|
16
16
|
import * as nocobaseClientUtils from '@nocobase/utils/client';
|
|
17
17
|
import * as nocobaseFlowEngine from '@nocobase/flow-engine';
|
|
18
|
+
import * as ahooks from 'ahooks';
|
|
18
19
|
import * as antd from 'antd';
|
|
19
20
|
import * as i18next from 'i18next';
|
|
20
21
|
import React from 'react';
|
|
@@ -61,4 +62,7 @@ export function defineGlobalDeps(requirejs: RequireJS) {
|
|
|
61
62
|
requirejs.define('@nocobase/client-v2', () => nocobaseClientV2);
|
|
62
63
|
requirejs.define('@nocobase/client-v2/client-v2', () => nocobaseClientV2);
|
|
63
64
|
requirejs.define('@nocobase/flow-engine', () => nocobaseFlowEngine);
|
|
65
|
+
|
|
66
|
+
// utils
|
|
67
|
+
requirejs.define('ahooks', () => ahooks);
|
|
64
68
|
}
|
package/src/utils/requirejs.ts
CHANGED
|
@@ -1686,7 +1686,7 @@ export function getRequireJs(): RequireJS {
|
|
|
1686
1686
|
|
|
1687
1687
|
//Join the path parts together, then figure out if baseUrl is needed.
|
|
1688
1688
|
url = syms.join('/');
|
|
1689
|
-
url += (ext || (/^data\:|^blob\:|\?/.test(url) || skipExt ? '' : '.js'));
|
|
1689
|
+
url += (ext || (/^data\:|^blob\:|\?/.test(url) || /\.js(?:$|[?#])/.test(url) || skipExt ? '' : '.js'));
|
|
1690
1690
|
url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
|
|
1691
1691
|
}
|
|
1692
1692
|
|