1
0
mirror of synced 2026-04-03 06:28:35 +08:00

feat(core,editor,ui): 新增页面片

This commit is contained in:
roymondchen
2023-12-18 19:51:41 +08:00
parent 698c3451ff
commit 7b6dcedfad
58 changed files with 1415 additions and 234 deletions

View File

@@ -21,6 +21,8 @@ import Container from './container';
import Img from './img';
import Overlay from './overlay';
import Page from './page';
import pageFragment from './page-fragment';
import pageFragmentContainer from './page-fragment-container';
import Qrcode from './qrcode';
import Text from './text';
export { default as AppContent } from './AppContent';
@@ -36,6 +38,8 @@ const ui: Record<string, any> = {
text: Text,
qrcode: Qrcode,
overlay: Overlay,
'page-fragment': pageFragment,
'page-fragment-container': pageFragmentContainer,
};
export default ui;

View File

@@ -0,0 +1,24 @@
/*
* Tencent is pleased to support the open source community by making TMagicEditor available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import PageFragmentContainer from './src/PageFragmentContainer';
export { default as config } from './src/formConfig';
export { default as value } from './src/initValue';
export default PageFragmentContainer;

View File

@@ -0,0 +1,55 @@
import React, { constructor, useEffect, useMemo, useState } from 'react';
import type { MComponent, MContainer, MNode, MPage, MPageFragment } from '@tmagic/schema';
import useApp from '../../useApp';
interface PageFragmentContainerProps {
config: MComponent;
}
const PageFragmentContainer: React.FC<PageFragmentContainerProps> = ({ config }) => {
const { app } = useApp({
config,
methods: {},
});
if (!app) return null;
const MagicUiContainer = app.resolveComponent('container');
let containerConfig = {}
const fragment = app?.dsl?.items?.find((page) => page.id === config.pageFragmentId)
if(fragment) {
const { id, type, items, ...others } = fragment;
const itemsWithoutId = items.map((item: MNode) => {
const { id, ...otherConfig } = item;
return otherConfig;
});
if (app?.platform === 'editor') {
containerConfig ={
...others,
items: itemsWithoutId,
};
}else {
containerConfig = {
...others,
items
}
}
}
return (
<div
id={`${config.id || ''}`}
className="magic-ui-page-fragment-container"
style={app.transformStyle(config.style || {})}
>
<MagicUiContainer
config={containerConfig}
></MagicUiContainer>
</div>
);
};
PageFragmentContainer.displayName = 'magic-ui-page-fragment-container';
export default PageFragmentContainer;

View File

@@ -0,0 +1,25 @@
/*
* Tencent is pleased to support the open source community by making TMagicEditor available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default [
{
name: 'pageFragmentId',
text: '页面片ID',
type: 'page-fragment-select',
},
];

View File

@@ -0,0 +1,24 @@
/*
* Tencent is pleased to support the open source community by making TMagicEditor available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default {
style: {
width: '',
height: '',
},
};

View File

@@ -0,0 +1,24 @@
/*
* Tencent is pleased to support the open source community by making TMagicEditor available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import PageFragment from './src/PageFragment';
export { default as config } from './src/formConfig';
export { default as value } from './src/initValue';
export default PageFragment;

View File

@@ -0,0 +1,51 @@
import React from 'react';
import type { MComponent, MContainer, MPageFragment } from '@tmagic/schema';
import useApp from '../../useApp';
interface PageFragmentProps {
config: MPageFragment;
}
const PageFragment: React.FC<PageFragmentProps> = ({ config }) => {
const { app } = useApp({
config,
methods: {},
});
if (!app) return null;
return (
<div
id={`${config.id || ''}`}
className={`magic-ui-page-fragment magic-ui-container magic-layout-${config.layout}${
config.className ? ` ${config.className}` : ''
}`}
style={app.transformStyle(config.style || {})}
>
{config.items?.map((item: MComponent | MContainer) => {
const MagicUiComp = app.resolveComponent(item.type || 'container');
if (!MagicUiComp) return null;
if (item.visible === false) return null;
if (item.condResult === false) return null;
return (
<MagicUiComp
id={`${item.id || ''}`}
key={item.id}
config={item}
className={`magic-ui-component${config.className ? ` ${config.className}` : ''}`}
style={app.transformStyle(item.style || {})}
></MagicUiComp>
);
})}
</div>
);
};
PageFragment.displayName = 'magic-ui-page-fragment';
export default PageFragment;

View File

@@ -0,0 +1,50 @@
/*
* Tencent is pleased to support the open source community by making TMagicEditor available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default [
{
text: '页面片标识',
name: 'name',
disabled: true,
},
{
text: '页面片标题',
name: 'title',
},
{
name: 'layout',
text: '容器布局',
type: 'select',
defaultValue: 'absolute',
options: [
{ value: 'absolute', text: '绝对定位' },
{ value: 'relative', text: '流式布局' },
],
onChange: (formState: any, v: string, { model }: any) => {
if (!model.style) return v;
if (v === 'relative') {
model.style.height = 'auto';
} else {
const el = formState.stage?.renderer?.contentWindow.document.getElementById(model.id);
if (el) {
model.style.height = el.getBoundingClientRect().height;
}
}
},
},
];

View File

@@ -0,0 +1,25 @@
/*
* Tencent is pleased to support the open source community by making TMagicEditor available.
*
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export default {
items: [],
style: {
width: '375',
height: '950',
},
};