Skip to content

Commit

Permalink
Merge branch 'master' into fix-groupSelection-style
Browse files Browse the repository at this point in the history
  • Loading branch information
findreamer committed Jan 26, 2024
2 parents 68ef1c4 + 70c8d30 commit 931db9b
Show file tree
Hide file tree
Showing 25 changed files with 194 additions and 140 deletions.
7 changes: 3 additions & 4 deletions packages/amis-core/src/store/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1892,13 +1892,12 @@ export const TableStore = iRendererStore

function getPersistDataKey(columns: any[]) {
// 这里的columns使用除了__开头的所有列
// sort保证存储和读取的key值保持一致
return (
location.pathname +
self.path +
sortBy(
columns.map((item, index) => item.name || item.label || index)
).join('-')
// 不能 sort 因为原始列的顺序设计器是可能改变的,此时如果缓存了打开会失效
// 还是缓存的顺序,不符合用户调整列顺序的预期
columns.map((item, index) => item.name || item.label || index).join('-')
);
}

Expand Down
9 changes: 8 additions & 1 deletion packages/amis-editor/src/plugin/Form/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {defaultValue, getSchemaTpl} from 'amis-editor-core';
import find from 'lodash/find';
import {JSONDelete, JSONPipeIn, JSONUpdate} from 'amis-editor-core';
import {SUPPORT_STATIC_FORMITEM_CMPTS} from '../../renderer/event-control/helper';
import {isExpression, resolveVariableAndFilter} from 'amis-core';

export class ItemPlugin extends BasePlugin {
static id = 'ItemPlugin';
Expand Down Expand Up @@ -229,7 +230,13 @@ export class ItemPlugin extends BasePlugin {
.getNodeById(context.id)
?.getComponent();

component?.props.onChange(change?.rhs);
let value = change?.rhs;

if (typeof value === 'string' && isExpression(value)) {
const data = event.context.node?.getComponent()?.props.data || {};
value = resolveVariableAndFilter(value, data, '| raw');
}
component?.props.onChange(value);
}
}

Expand Down
9 changes: 4 additions & 5 deletions packages/amis-editor/src/plugin/Form/Switch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
RendererPluginAction,
RendererPluginEvent
} from 'amis-editor-core';
import {isExpression} from 'amis-core';

export class SwitchControlPlugin extends BasePlugin {
static id = 'SwitchControlPlugin';
Expand Down Expand Up @@ -202,12 +203,10 @@ export class SwitchControlPlugin extends BasePlugin {
: value;
},
pipeOut: (value: any, origin: any, data: any) => {
// 如果是表达式,直接返回
if (isExpression(value)) return value;
const {trueValue = true, falseValue = false} = data || {};
return value && value === trueValue
? trueValue
: value && value !== falseValue
? value
: falseValue;
return value ? trueValue : falseValue;
}
}),
getSchemaTpl('labelRemark'),
Expand Down
25 changes: 13 additions & 12 deletions packages/amis-editor/src/renderer/DateShortCutControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,24 @@ export class DateShortCutControl extends React.PureComponent<
}
// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

const options = this.state.options.concat();
options[e.oldIndex] = options.splice(
e.newIndex,
1,
options[e.oldIndex]
)[0];
// options[e.oldIndex] = options.splice(
// e.newIndex,
// 1,
// options[e.oldIndex]
// )[0];
options.splice(e.newIndex, 0, options.splice(e.oldIndex, 1)[0]);
this.setState({options}, () => this.onChangeOptions());
}
}
Expand Down
14 changes: 7 additions & 7 deletions packages/amis-editor/src/renderer/FeatureControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ export default class FeatureControl extends React.Component<
}
// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
Expand Down
14 changes: 7 additions & 7 deletions packages/amis-editor/src/renderer/ListItemControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ export default class ListItemControl extends React.Component<

// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
Expand Down
21 changes: 8 additions & 13 deletions packages/amis-editor/src/renderer/OptionControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -250,24 +250,19 @@ export default class OptionControl extends React.Component<

// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

const options = this.state.options.concat();

options[e.oldIndex] = options.splice(
e.newIndex,
1,
options[e.oldIndex]
)[0];
options.splice(e.newIndex, 0, options.splice(e.oldIndex, 1)[0]);

this.setState({options}, () => this.onChange());
}
Expand Down
14 changes: 7 additions & 7 deletions packages/amis-editor/src/renderer/TimelineItemControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,13 @@ export default class TimelineItemControl extends React.Component<

// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,24 @@ export class CRUDColumnControl extends React.Component<
const parent = e.to as HTMLElement;

if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}

const options = this.state.options.concat();

options[e.oldIndex] = options.splice(
e.newIndex,
1,
options[e.oldIndex]
)[0];
// options[e.oldIndex] = options.splice(
// e.newIndex,
// 1,
// options[e.oldIndex]
// )[0];
options.splice(e.newIndex, 0, options.splice(e.oldIndex, 1)[0]);

this.setState({options}, () => this.handleSort());
}
Expand Down
31 changes: 8 additions & 23 deletions packages/amis-editor/src/renderer/event-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -543,36 +543,21 @@ export class EventControl extends React.Component<
}
// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
let onEventConfig = cloneDeep(this.state.onEvent);
const newEvent = onEventConfig[eventKey];
let options = newEvent?.actions.concat();
// 从后往前移
if (e.oldIndex > e.newIndex) {
options = [
...options.slice(0, e.newIndex),
options[e.oldIndex],
...options.slice(e.newIndex, e.oldIndex),
...options.slice(e.oldIndex + 1, options.length)
];
} else if (e.oldIndex < e.newIndex) {
// 从前往后
options = [
...(e.oldIndex === 0 ? [] : options.slice(0, e.oldIndex)),
...options.slice(e.oldIndex + 1, e.newIndex),
options[e.oldIndex],
...options.slice(e.newIndex, options.length)
];
}
options.splice(e.newIndex, 0, options.splice(e.oldIndex, 1)[0]);
onEventConfig[eventKey] = {
...onEventConfig[eventKey],
actions: options
Expand Down
14 changes: 7 additions & 7 deletions packages/amis-ui/src/components/ArrayInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ export class ArrayInput extends React.Component<ArrayInputProps> {

// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
Expand Down
14 changes: 7 additions & 7 deletions packages/amis-ui/src/components/ResultList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ export class ResultList extends React.Component<

// 换回来
const parent = e.to as HTMLElement;
if (
e.newIndex < e.oldIndex &&
e.oldIndex < parent.childNodes.length - 1
) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex + 1]);
} else if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
Expand Down
7 changes: 6 additions & 1 deletion packages/amis-ui/src/components/UserSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,12 @@ export class UserSelect extends React.Component<
}
const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/amis/src/renderers/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ export class CardRenderer extends React.Component<CardProps> {
),
rowIndex: itemIndex,
colIndex: key,
value: field.name ? resolveVariable(field.name, data) : undefined,
// 同 cell 里面逻辑一样,不要下发 value
// value: field.name ? resolveVariable(field.name, data) : undefined,
popOverContainer: this.getPopOverContainer,
onAction: this.handleAction,
onQuickChange: this.handleQuickChange
Expand Down
14 changes: 10 additions & 4 deletions packages/amis/src/renderers/Cards.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import {findDOMNode} from 'react-dom';
import {Renderer, RendererProps, buildStyle} from 'amis-core';
import {Renderer, RendererProps, buildStyle, getPropValue} from 'amis-core';
import {SchemaNode, Schema, ActionObject} from 'amis-core';
import {Button, Spinner, SpinnerExtraProps} from 'amis-ui';
import {ListStore, IListStore} from 'amis-core';
Expand Down Expand Up @@ -266,13 +266,14 @@ export default class Cards extends React.Component<GridProps, object> {

static syncItems(store: IListStore, props: GridProps, prevProps?: GridProps) {
const source = props.source;
const value = props.value || props.items;
const value = getPropValue(props, (props: GridProps) => props.items);
let items: Array<object> = [];
let updateItems = false;

if (
Array.isArray(value) &&
(!prevProps || (prevProps.value || prevProps.items) !== value)
(!prevProps ||
getPropValue(prevProps, (props: GridProps) => props.items) !== value)
) {
items = value;
updateItems = true;
Expand Down Expand Up @@ -560,7 +561,12 @@ export default class Cards extends React.Component<GridProps, object> {

const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
Expand Down
7 changes: 6 additions & 1 deletion packages/amis/src/renderers/Form/Combo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,12 @@ export default class ComboControl extends React.Component<ComboProps> {
// 换回来
const parent = e.to as HTMLElement;
if (e.oldIndex < parent.childNodes.length - 1) {
parent.insertBefore(e.item, parent.childNodes[e.oldIndex]);
parent.insertBefore(
e.item,
parent.childNodes[
e.oldIndex > e.newIndex ? e.oldIndex + 1 : e.oldIndex
]
);
} else {
parent.appendChild(e.item);
}
Expand Down

0 comments on commit 931db9b

Please sign in to comment.