MCPcopy
hub / github.com/baidu/amis / addSchema2Toolbar

Function addSchema2Toolbar

packages/amis-editor/src/plugin/CRUD2/utils.ts:122–194  ·  view source on GitHub ↗
(
  schema: any,
  content: any,
  position: 'header' | 'footer',
  align: 'left' | 'right'
)

Source from the content-addressed store, hash-verified

120
121/** headerToolbar 和 footerToolbar 布局换成 flex 包裹 container */
122export const addSchema2Toolbar = (
123 schema: any,
124 content: any,
125 position: 'header' | 'footer',
126 align: 'left' | 'right'
127) => {
128 const region = `${position}Toolbar`;
129 const buildFlex = (items: any[] = []) => ({
130 type: 'flex',
131 items,
132 style: {
133 position: 'static'
134 },
135 direction: 'row',
136 justify: 'flex-start',
137 alignItems: 'stretch'
138 });
139 const buildContainer = (align?: 'left' | 'right', body: any[] = []) => ({
140 type: 'container',
141 body,
142 wrapperBody: false,
143 style: {
144 flexGrow: 1,
145 flex: '1 1 auto',
146 position: 'static',
147 display: 'flex',
148 flexBasis: 'auto',
149 flexDirection: 'row',
150 flexWrap: 'nowrap',
151 alignItems: 'stretch',
152 ...(align
153 ? {
154 justifyContent: align === 'left' ? 'flex-start' : 'flex-end'
155 }
156 : {})
157 }
158 });
159
160 if (
161 !schema[region] ||
162 isEmpty(schema[region]) ||
163 !Array.isArray(schema[region])
164 ) {
165 const isArr = Array.isArray(schema[region]);
166 const newSchema = buildFlex([
167 buildContainer('left', isArr || !schema[region] ? [] : [schema[region]]),
168 buildContainer('right')
169 ]);
170
171 (isArr && schema[region].push(newSchema)) || (schema[region] = [newSchema]);
172 }
173
174 // 尝试放到左面第一个,否则只能放外头了
175 try {
176 // 优先判断没有右边列的情况,避免都走到catch里造成嵌套层数过多的问题
177 if (align === 'right' && schema[region][0].items.length < 2) {
178 schema[region][0].items.push(buildContainer('right'));
179 }

Callers 2

Table2PluginClass · 0.90
handleAddActionMethod · 0.90

Calls 4

buildFlexFunction · 0.85
buildContainerFunction · 0.85
pushMethod · 0.65
isEmptyFunction · 0.50

Tested by

no test coverage detected