Compare commits

...

2 Commits

Author SHA1 Message Date
zestack 4c91f0f4f7 refactor: 调整视图剪裁行为 1 year ago
zestack 3a5c29fe0d feat: 自动弹性布局 1 year ago
  1. 15
      src/engineer/render.ts
  2. 18
      src/engineer/types.ts
  3. 21
      src/engineer/utils/clip.ts
  4. 1
      src/engineer/utils/index.ts

@ -9,6 +9,7 @@ import type {
Axis, Axis,
Block, Block,
DataRefer, DataRefer,
Theme,
View, View,
ViewChildren, ViewChildren,
Widget, Widget,
@ -17,7 +18,7 @@ import { provideBlockId } from './context'
import { import {
align, align,
background, background,
bordering, bordering, clip,
gap, gap,
insets, insets,
radii, radii,
@ -55,6 +56,14 @@ function isRefer(s: any): s is DataRefer {
&& typeof s.key === 'string' && typeof s.key === 'string'
} }
export function isFlexible(theme: Theme) {
return theme.axis != null
|| theme.mainAlign != null
|| theme.crossAlign != null
|| theme.wrap != null
|| theme.gap != null
}
export function render(view?: ViewChildren, axis?: Axis): VNodeChild { export function render(view?: ViewChildren, axis?: Axis): VNodeChild {
if (view == null) if (view == null)
return null return null
@ -128,14 +137,14 @@ export function render(view?: ViewChildren, axis?: Axis): VNodeChild {
textAlign: theme?.textAlign, textAlign: theme?.textAlign,
lineHeight: theme?.lineHeight, lineHeight: theme?.lineHeight,
// clip // clip
overflow: theme?.clip, ...clip(theme?.clip),
} }
// note: 在前面初始化 css 时使用了参数 axis, // note: 在前面初始化 css 时使用了参数 axis,
// 所以在这里复用它用于子视图构建 // 所以在这里复用它用于子视图构建
axis = theme?.axis axis = theme?.axis
if (theme?.flexible) { if (theme?.flexible || (theme && theme.flexible == null && isFlexible(theme))) {
Object.assign(css, { Object.assign(css, {
display: 'flex', display: 'flex',
flexDirection: axis === 'y' ? 'column' : undefined, flexDirection: axis === 'y' ? 'column' : undefined,

@ -252,11 +252,15 @@ export interface Widget {
slots?: Omit<Slots, 'default'> slots?: Omit<Slots, 'default'>
} }
/**
*
*/
export type ClipBehavior = export type ClipBehavior =
| 'hidden' | 'hidden'
| 'visible' | 'visible'
| 'scroll'
| 'auto' | 'auto'
| 'autoX' // overflow-x: auto; overflow-y: hidden
| 'autoY' // overflow-x: hidden; overflow-y: auto
/** /**
* *
@ -264,9 +268,17 @@ export type ClipBehavior =
* *
*/ */
export interface Theme extends Textual, Flexible, Boxed, Decoration, Spatial, Flexible { export interface Theme extends Textual, Flexible, Boxed, Decoration, Spatial, Flexible {
/** 是否开启弹性布局,todo 删除改属性,根据属性判断是否启用 flex 布局 */ /**
*
*
* Flexible
*/
flexible?: boolean flexible?: boolean
/** 超出视图剪切方式,对应 overflow 属性 */ /**
*
*
* overflow
*/
clip?: ClipBehavior clip?: ClipBehavior
} }

@ -0,0 +1,21 @@
import type { CSSProperties } from 'vue'
import type { ClipBehavior } from '../types'
export function clip(clip: ClipBehavior | undefined): CSSProperties | undefined {
switch (clip) {
case 'autoX':
return {
overflowX: 'auto',
overflowY: 'hidden',
}
case 'autoY':
return {
overflowX: 'hidden',
overflowY: 'auto',
}
default:
return {
overflow: clip,
}
}
}

@ -1,6 +1,7 @@
export * from './align' export * from './align'
export * from './background' export * from './background'
export * from './border' export * from './border'
export * from './clip'
export * from './gap' export * from './gap'
export * from './hash' export * from './hash'
export * from './insets' export * from './insets'

Loading…
Cancel
Save