Skip to content

Commit

Permalink
Merge remote-tracking branch 'baidu/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
2betop committed Dec 4, 2024
2 parents e13a22a + 690a124 commit bd41fff
Show file tree
Hide file tree
Showing 32 changed files with 489 additions and 298 deletions.
1 change: 1 addition & 0 deletions docs/zh-CN/components/form/picker.md
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,7 @@ order: 35
| pickerSchema | `string` | `{mode: 'list', listItem: {title: '${label}'}}` | 即用 List 类型的渲染,来展示列表信息。更多配置参考 [CRUD](../crud) |
| embed | `boolean` | `false` | 是否使用内嵌模式 |
| overflowConfig | `OverflowConfig` | 参考[OverflowConfig](./#overflowconfig) | 开启最大标签展示数量的相关配置 `3.4.0` |
| removable | `removable` | `true` | 用于控制是否显示选中项的删除图标,默认值为 `true` | `6.10.0` |

### OverflowConfig

Expand Down
21 changes: 16 additions & 5 deletions packages/amis-core/src/renderers/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1814,22 +1814,33 @@ export default class Form extends React.Component<FormProps, object> {

return (
<div className={cx('Form-row')}>
{children.map((control, key) =>
~['hidden', 'formula'].indexOf((control as any).type) ||
(control as any).mode === 'inline' ? (
{children.map((control, key) => {
const split = control.colSize?.split('/');
const colSize =
split?.[0] && split?.[1]
? (split[0] / split[1]) * 100 + '%'
: control.colSize;
return ~['hidden', 'formula'].indexOf((control as any).type) ||
(control as any).mode === 'inline' ? (
this.renderChild(control, key, otherProps)
) : (
<div
key={key}
className={cx(`Form-col`, (control as Schema).columnClassName)}
style={{
flex:
colSize && !['1', 'auto'].includes(colSize)
? `0 0 ${colSize}`
: '1'
}}
>
{this.renderChild(control, '', {
...otherProps,
mode: 'row'
})}
</div>
)
)}
);
})}
</div>
);
}
Expand Down
21 changes: 19 additions & 2 deletions packages/amis-core/src/utils/debug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ const AMISDebug = observer(({store}: {store: AMISDebugStore}) => {
}
}

const panelRef = useRef(null);
const panelRef = useRef<HTMLDivElement>(null);

const [isResizing, setResizing] = useState(false);

Expand Down Expand Up @@ -220,6 +220,19 @@ const AMISDebug = observer(({store}: {store: AMISDebugStore}) => {
};
}, [isResizing]);

// 避免触发 modal 的 closeOnOutside 逻辑
useEffect(() => {
const handlePanelMouseUp = (e: Event) => {
e.preventDefault();
};

panelRef.current!.addEventListener('mouseup', handlePanelMouseUp);

return () => {
panelRef.current!.removeEventListener('mouseup', handlePanelMouseUp);
};
}, []);

const handleInputKeyUp = React.useCallback((e: React.KeyboardEvent<any>) => {
if (e.key === 'Enter') {
const input = e.target as HTMLInputElement;
Expand Down Expand Up @@ -290,7 +303,7 @@ const AMISDebug = observer(({store}: {store: AMISDebugStore}) => {
store.tab = 'log';
}}
>
Log
Log({store.logs.length})
</button>
<button
className={cx({active: store.tab === 'inspect'})}
Expand Down Expand Up @@ -609,6 +622,10 @@ export function debug(cat: Category, msg: string, ext?: any) {
ext: ext
};
store.logs.push(log);
// 不要超过 200 条,担心性能问题
if (store.logs.length > 200) {
store.logs.splice(0, store.logs.length - 200);
}
}

/**
Expand Down
4 changes: 4 additions & 0 deletions packages/amis-core/src/utils/labelToString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import isPlainObject from 'lodash/isPlainObject';

export function labelToString(label: any): string {
const type = typeof label;
if (type === 'undefined' || label === null) {
// render placeholder
return '-';
}
if (type === 'string') {
return label;
} else if (type === 'number') {
Expand Down
12 changes: 12 additions & 0 deletions packages/amis-editor-core/src/component/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ export default class Editor extends Component<EditorProps> {

this.manager = new EditorManager(config, this.store, hostManager);

this.store.setGlobalEvents(
config.actionOptions?.globalEventGetter?.(this.manager) || []
);

// 子编辑器不再重新设置 editorStore
if (!(props.isSubEditor && (window as any).editorStore)) {
(window as any).editorStore = this.store;
Expand Down Expand Up @@ -274,6 +278,14 @@ export default class Editor extends Component<EditorProps> {
if (props?.amisEnv?.replaceText !== prevProps?.amisEnv?.replaceText) {
this.store.setAppCorpusData(props?.amisEnv?.replaceText);
}
if (
props.actionOptions?.globalEventGetter?.(this.manager) !==
prevProps.actionOptions?.globalEventGetter?.(this.manager)
) {
this.store.setGlobalEvents(
props.actionOptions?.globalEventGetter?.(this.manager) || []
);
}
}

componentWillUnmount() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {EditorManager} from '../../manager';
import {diff, getThemeConfig} from '../../util';
import {
createObjectFromChain,
createObject,
extractObjectChain,
IFormStore,
render,
Expand Down
11 changes: 9 additions & 2 deletions packages/amis-editor-core/src/store/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ import {
ScaffoldForm,
PopOverForm,
DeleteEventContext,
BaseEventContext
BaseEventContext,
IGlobalEvent
} from '../plugin';
import {
JSONDuplicate,
Expand Down Expand Up @@ -265,7 +266,9 @@ export const MainStore = types
/** 应用语料 */
appCorpusData: types.optional(types.frozen(), {}),
/** 应用多语言状态,用于其它组件进行订阅 */
appLocaleState: types.optional(types.number, 0)
appLocaleState: types.optional(types.number, 0),
/** 全局广播事件 */
globalEvents: types.optional(types.frozen<Array<IGlobalEvent>>(), [])
})
.views(self => {
return {
Expand Down Expand Up @@ -2348,6 +2351,10 @@ export const MainStore = types
this.updateAppLocaleState();
},

setGlobalEvents(events: IGlobalEvent[]) {
self.globalEvents = events;
},

beforeDestroy() {
lazyUpdateTargetName.cancel();
}
Expand Down
1 change: 0 additions & 1 deletion packages/amis-editor/src/plugin/Form/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ export class CheckboxControlPlugin extends BasePlugin {
body: [
getSchemaTpl('collapseGroup', [
getSchemaTpl('theme:formItem', {
hidSize: true,
schema: [
{
type: 'select',
Expand Down
1 change: 0 additions & 1 deletion packages/amis-editor/src/plugin/Form/Checkboxes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ export class CheckboxesControlPlugin extends BasePlugin {
body: [
getSchemaTpl('collapseGroup', [
getSchemaTpl('theme:formItem', {
hidSize: true,
schema: [
getSchemaTpl('switch', {
label: '一行选项显示',
Expand Down
Loading

0 comments on commit bd41fff

Please sign in to comment.