Skip to content

Commit 295a69e

Browse files
ggbond2077QIQI03
authored andcommitted
1. feat: select expose selectedIndex/selectedLabel
2. feat: modal and drawer add showMask 3. fix: run libs seqly 4. refactor(table): refactor withContext to withParams in table
1 parent a05b625 commit 295a69e

File tree

12 files changed

+153
-33
lines changed

12 files changed

+153
-33
lines changed

client/packages/openblocks-core/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3431,7 +3431,7 @@ var MultiBaseComp = /** @class */ (function (_super) {
34313431
if (shallowEqual(children, this.children) && containFields(this, extraFields)) {
34323432
return this;
34333433
}
3434-
return setFieldsNoTypeCheck(this, __assign((_b = { children: children }, _b[cacheKey] = value_1, _b), extraFields), { keepCache: true });
3434+
return setFieldsNoTypeCheck(this, __assign((_b = { children: children }, _b[cacheKey] = value_1, _b), extraFields));
34353435
}
34363436
case CompActionTypes.CHANGE_VALUE: {
34373437
return this.setChildren(this.parseChildrenFromValue({

client/packages/openblocks-core/src/baseComps/multiBaseComp.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ export abstract class MultiBaseComp<
153153
children: children,
154154
[cacheKey]: value,
155155
...extraFields,
156-
},
157-
{ keepCache: true }
156+
}
157+
// { keepCache: true }
158158
);
159159
}
160160
case CompActionTypes.CHANGE_VALUE: {

client/packages/openblocks/src/comps/comps/preLoadComp.tsx

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { CodeTextControl } from "comps/controls/codeTextControl";
66
import SimpleStringControl from "comps/controls/simpleStringControl";
77
import { MultiCompBuilder } from "comps/generators";
88
import { list } from "comps/generators/list";
9-
import { CustomModal, TacoButton } from "openblocks-design";
9+
import { CustomModal, DocLink, TacoButton } from "openblocks-design";
1010
import { clearMockWindow, evalFunc } from "openblocks-core";
1111
import { clearStyleEval, evalStyle } from "openblocks-core";
1212
import { useContext, useEffect, useState } from "react";
@@ -39,6 +39,15 @@ const LibListWrapper = styled.div`
3939
flex: 1;
4040
margin-right: 8px;
4141
}
42+
.lib-list-add-btn-wrapper {
43+
display: flex;
44+
flex-direction: row;
45+
align-items: center;
46+
47+
.lib-list-add-btn {
48+
margin-right: 8px;
49+
}
50+
}
4251
`;
4352

4453
function runScript(code: string, inHost?: boolean) {
@@ -64,30 +73,42 @@ class LibsComp extends list(SimpleStringControl) implements RunAndClearable<stri
6473
runInHost: boolean = false;
6574
async loadScript(url: string) {
6675
if (this.success[url]) {
67-
return;
76+
return async () => {};
6877
}
6978
if (this.runInHost) {
70-
await loadScript(url);
79+
return async () => {
80+
await loadScript(url);
81+
this.success[url] = true;
82+
};
7183
} else {
7284
const res = await fetch(url);
7385
const code = await res.text();
74-
runScript(code);
86+
return async () => {
87+
runScript(code);
88+
this.success[url] = true;
89+
};
7590
}
76-
this.success[url] = true;
7791
}
7892

7993
async loadAllLibs() {
80-
const scripts: Promise<void>[] = [];
94+
const scriptRunners: Promise<() => Promise<void>>[] = [];
8195
const appLibs = this.getView().map((i) => i.getView());
8296
this.externalLibs.concat(appLibs).forEach((url) => {
8397
const trimUrl = url.trim();
8498
if (!/^https?.+\.js$/.test(trimUrl)) {
8599
return;
86100
}
87-
scripts.push(this.loadScript(trimUrl));
101+
scriptRunners.push(this.loadScript(trimUrl));
88102
});
89103

90-
return Promise.allSettled(scripts);
104+
try {
105+
const runners = await Promise.all(scriptRunners);
106+
for await (const runner of runners) {
107+
await runner();
108+
}
109+
} catch (e) {
110+
log.warn("load preload libs error:", e);
111+
}
91112
}
92113

93114
async run(id: string, externalLibs: string[] = [], runInHost: boolean = false) {
@@ -183,16 +204,20 @@ function LibsTabPane(props: { libsComp: ChildrenInstance["libs"] }) {
183204
);
184205
})}
185206
</div>
186-
<div>
207+
<div className="lib-list-add-btn-wrapper">
187208
<TacoButton
188209
ghost
210+
className="lib-list-add-btn"
189211
buttonType="primary"
190212
onClick={() => {
191213
props.libsComp.dispatch(props.libsComp.pushAction(""));
192214
}}
193215
>
194216
{trans("preLoad.add")}
195217
</TacoButton>
218+
{trans("docUrls.thirdLib") && (
219+
<DocLink href={trans("docUrls.thirdLib")}>{trans("docUrls.thirdLibUrlText")}</DocLink>
220+
)}
196221
</div>
197222
</LibListWrapper>
198223
);

client/packages/openblocks/src/comps/comps/selectInputComp/selectComp.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import { stringExposingStateControl } from "../../controls/codeStateControl";
55
import { UICompBuilder } from "../../generators";
66
import { CommonNameConfig, NameConfig, withExposingConfigs } from "../../generators/withExposing";
77
import { SelectChildrenMap, SelectPropertyView, SelectUIView } from "./selectCompConstants";
8-
import { SelectInputInvalidConfig, useSelectInputValidate } from "./selectInputConstants";
8+
import {
9+
SelectInputCommonConfig,
10+
SelectInputInvalidConfig,
11+
useSelectInputValidate,
12+
} from "./selectInputConstants";
913

1014
export const SelectBasicComp = (function () {
1115
const childrenMap = {
@@ -42,5 +46,6 @@ export const SelectComp = withExposingConfigs(SelectBasicComp, [
4246
new NameConfig("value", trans("selectInput.valueDesc")),
4347
new NameConfig("inputValue", trans("select.inputValueDesc")),
4448
SelectInputInvalidConfig,
49+
...SelectInputCommonConfig,
4550
...CommonNameConfig,
4651
]);

client/packages/openblocks/src/comps/comps/selectInputComp/selectCompConstants.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
import { DispatchType, RecordConstructorToComp, RecordConstructorToView } from "openblocks-core";
1+
import {
2+
changeChildAction,
3+
DispatchType,
4+
RecordConstructorToComp,
5+
RecordConstructorToView,
6+
} from "openblocks-core";
27
import { BoolControl, BoolPureControl } from "../../controls/boolControl";
38
import { LabelControl } from "../../controls/labelControl";
49
import { BoolCodeControl, StringControl } from "../../controls/codeControl";
5-
import { Section, sectionNames } from "openblocks-design";
10+
import {
11+
isDarkColor,
12+
lightenColor,
13+
MultiselectTagIcon,
14+
Section,
15+
sectionNames,
16+
} from "openblocks-design";
617
import { SelectInputOptionControl } from "../../controls/optionsControl";
718
import { SelectEventHandlerControl } from "../../controls/eventHandlerControl";
819
import { Select as AntdSelect } from "antd";
@@ -20,14 +31,11 @@ import {
2031
SelectStyleType,
2132
TreeSelectStyleType,
2233
} from "comps/controls/styleControlConstants";
23-
import { MultiselectTagIcon } from "openblocks-design";
24-
import { isDarkColor, lightenColor } from "openblocks-design";
25-
import { changeChildAction } from "openblocks-core";
2634
import { stateComp, withDefault } from "../../generators";
2735
import {
2836
allowClearPropertyView,
29-
hiddenPropertyView,
3037
disabledPropertyView,
38+
hiddenPropertyView,
3139
placeholderPropertyView,
3240
showSearchPropertyView,
3341
} from "comps/utils/propertyUtils";

client/packages/openblocks/src/comps/comps/selectInputComp/selectInputConstants.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
import { requiredPropertyView } from "comps/utils/propertyUtils";
1313
import { trans } from "i18n";
1414
import { useState } from "react";
15+
import { SelectInputOptionControl } from "../../controls/optionsControl";
1516

1617
export const SelectInputValidationChildren = {
1718
required: BoolControl,
@@ -84,3 +85,22 @@ export const SelectInputValidationSection = (children: ValidationComp) => (
8485
{children.customRule.propertyView({})}
8586
</Section>
8687
);
88+
89+
type ChildrenType = RecordConstructorToComp<{
90+
value: ReturnType<typeof stringExposingStateControl>;
91+
options: typeof SelectInputOptionControl;
92+
}>;
93+
export const SelectInputCommonConfig = [
94+
depsConfig<ChildrenType, ChildrenTypeToDepsKeys<ChildrenType>>({
95+
name: "selectedIndex",
96+
desc: trans("selectInput.selectedIndexDesc"),
97+
depKeys: ["value", "options"],
98+
func: (input) => input.options.findIndex?.((o: any) => o.value === input.value),
99+
}),
100+
depsConfig<ChildrenType, ChildrenTypeToDepsKeys<ChildrenType>>({
101+
name: "selectedLabel",
102+
desc: trans("selectInput.selectedLabelDesc"),
103+
depKeys: ["value", "options"],
104+
func: (input) => input.options.find?.((o: any) => o.value === input.value)?.label,
105+
}),
106+
];

client/packages/openblocks/src/comps/controls/optionsControl.tsx

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@ import {
55
CompParams,
66
ConstructorToDataType,
77
ConstructorToView,
8+
fromRecord,
89
MultiBaseComp,
10+
withFunction,
911
} from "openblocks-core";
10-
import { ArrayControl, BoolCodeControl, StringControl } from "comps/controls/codeControl";
12+
import {
13+
ArrayControl,
14+
BoolCodeControl,
15+
codeControl,
16+
CodeControlType,
17+
StringControl,
18+
} from "comps/controls/codeControl";
1119
import { dropdownControl, LeftRightControl } from "comps/controls/dropdownControl";
1220
import { MultiCompBuilder, valueComp, withContext, withDefault } from "comps/generators";
1321
import { list } from "comps/generators/list";
@@ -16,13 +24,13 @@ import { genRandomKey } from "comps/utils/idGenerator";
1624
import { AutoArea, Option } from "openblocks-design";
1725
import { getNextEntityName } from "util/stringUtils";
1826
import { ButtonEventHandlerControl } from "./eventHandlerControl";
19-
import _ from "lodash";
20-
import { JSONValue } from "util/jsonTypes";
27+
import _, { mapValues } from "lodash";
2128
import { disabledPropertyView, hiddenPropertyView } from "comps/utils/propertyUtils";
2229
import { trans } from "i18n";
2330
import styled from "styled-components";
2431
import { ViewDocIcon } from "assets/icons";
2532
import { IconControl } from "comps/controls/iconControl";
33+
import { JSONValue } from "../../util/jsonTypes";
2634

2735
const OptionTypes = [
2836
{
@@ -36,7 +44,7 @@ const OptionTypes = [
3644
] as const;
3745

3846
// All options must contain label
39-
type OptionChildType = { label: Comp<string> };
47+
type OptionChildType = { label: InstanceType<typeof StringControl> };
4048
type OptionsControlType = new (params: CompParams<any>) => MultiBaseComp<
4149
OptionChildType,
4250
any,
@@ -131,6 +139,17 @@ export function manualOptionsControl<T extends OptionsControlType>(
131139
.build();
132140

133141
class ManualOptionControl extends TmpManualOptionControl {
142+
exposingNode() {
143+
return withFunction(
144+
fromRecord(
145+
mapValues(this.children.manual.children, (c1) =>
146+
fromRecord(mapValues(c1.children, (c2) => c2.exposingNode()))
147+
)
148+
),
149+
(params) => Object.values(params)
150+
);
151+
}
152+
134153
private getNewId(): number {
135154
const { autoIncField } = config;
136155
if (!autoIncField) return 0;
@@ -260,6 +279,17 @@ export function mapOptionsControl<T extends OptionsControlType>(
260279
return class extends TmpOptionControl {
261280
private lastDataExample: any = {};
262281

282+
exposingNode() {
283+
return withFunction(
284+
fromRecord({
285+
data: this.children.data.exposingNode(),
286+
mapData: this.children.mapData.node(),
287+
}),
288+
(params) =>
289+
params.data.map((d: any, i) => mapValues((params.mapData as any)(d), (v) => v.value))
290+
);
291+
}
292+
263293
override reduce(action: CompAction) {
264294
const comp = super.reduce(action);
265295
if (action.type === CompActionTypes.UPDATE_NODES_V2) {
@@ -325,6 +355,12 @@ export function optionsControl<T extends OptionsControlType>(
325355
.build();
326356

327357
return class extends TmpOptionControl {
358+
exposingNode() {
359+
return this.children.optionType.getView() === "manual"
360+
? this.children.manual.exposingNode()
361+
: this.children.mapData.exposingNode();
362+
}
363+
328364
propertyView(param: OptionControlParam) {
329365
return (
330366
<>

client/packages/openblocks/src/comps/hooks/drawerComp.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import styled from "styled-components";
2222
import { useUserViewMode } from "util/hooks";
2323
import { isNumeric } from "util/stringUtils";
2424
import { NameConfig, withExposingConfigs } from "../generators/withExposing";
25+
import { BoolControl } from "comps/controls/boolControl";
26+
import { withDefault } from "comps/generators";
2527

2628
const EventOptions = [closeEvent] as const;
2729

@@ -96,6 +98,8 @@ let TmpDrawerComp = (function () {
9698
autoHeight: AutoHeightControl,
9799
style: styleControl(DrawerStyle),
98100
placement: PositionControl,
101+
maskClosable: withDefault(BoolControl, true),
102+
showMask: withDefault(BoolControl, true),
99103
},
100104
(props, dispatch) => {
101105
const isTopBom = ["top", "bottom"].includes(props.placement);
@@ -140,6 +144,8 @@ let TmpDrawerComp = (function () {
140144
}
141145
}}
142146
zIndex={Layers.drawer}
147+
maskClosable={props.maskClosable}
148+
mask={props.showMask}
143149
>
144150
<ButtonStyle
145151
onClick={() => {
@@ -182,6 +188,12 @@ let TmpDrawerComp = (function () {
182188
tooltip: trans("drawer.heightTooltip"),
183189
placeholder: DEFAULT_SIZE + "",
184190
})}
191+
{children.maskClosable.propertyView({
192+
label: trans("prop.maskClosable"),
193+
})}
194+
{children.showMask.propertyView({
195+
label: trans("prop.showMask"),
196+
})}
185197
</Section>
186198
<Section name={sectionNames.interaction}>{children.onEvent.getPropertyView()}</Section>
187199
<Section name={sectionNames.style}>{children.style.getPropertyView()}</Section>

client/packages/openblocks/src/comps/hooks/modalComp.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ let TmpModalComp = (function () {
7373
autoHeight: AutoHeightControl,
7474
style: styleControl(ModalStyle),
7575
maskClosable: withDefault(BoolControl, true),
76+
showMask: withDefault(BoolControl, true),
7677
},
7778
(props, dispatch) => {
7879
const userViewMode = useUserViewMode();
@@ -126,6 +127,7 @@ let TmpModalComp = (function () {
126127
}}
127128
zIndex={Layers.modal}
128129
modalRender={(node) => <ModalStyled $style={props.style}>{node}</ModalStyled>}
130+
mask={props.showMask}
129131
>
130132
<InnerGrid
131133
{...otherContainerProps}
@@ -157,7 +159,10 @@ let TmpModalComp = (function () {
157159
placeholder: DEFAULT_WIDTH,
158160
})}
159161
{children.maskClosable.propertyView({
160-
label: trans("modalComp.maskClosable"),
162+
label: trans("prop.maskClosable"),
163+
})}
164+
{children.showMask.propertyView({
165+
label: trans("prop.showMask"),
161166
})}
162167
</Section>
163168
<Section name={sectionNames.interaction}>{children.onEvent.getPropertyView()}</Section>

0 commit comments

Comments
 (0)