@flatbiz/antd 4.2.28 → 4.2.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/form-grid/index.js +1 -1
- package/esm/form-grid/index.js.map +1 -1
- package/esm/form-item-wrapper/index.js +1 -1
- package/esm/form-item-wrapper/index.js.map +1 -1
- package/index.d.ts +12 -32
- package/package.json +1 -1
- package/esm/form-item-normalize/index.css +0 -0
- package/esm/form-item-normalize/index.js +0 -5
- package/esm/form-item-normalize/index.js.map +0 -1
package/esm/form-grid/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
import './index.css';
|
|
3
3
|
/*! @flatjs/forge MIT @flatbiz/antd */
|
|
4
|
-
import{_ as r,a as e}from"../_rollupPluginBabelHelpers-1f4d8910.js";import{Col as t,Form as n,Row as i,Space as o}from"antd";import{jsx as a,jsxs as l}from"react/jsx-runtime";import{classNames as u}from"@dimjs/utils/cjs/class-names";import{useMemo as
|
|
4
|
+
import{_ as r,a as e}from"../_rollupPluginBabelHelpers-1f4d8910.js";import{Col as t,Form as n,Row as i,Space as o}from"antd";import{jsx as a,jsxs as l}from"react/jsx-runtime";import{classNames as u}from"@dimjs/utils/cjs/class-names";import{useMemo as s,isValidElement as f,cloneElement as d}from"react";import{toArray as p,valueIsEqual as v}from"@flatbiz/utils";import{u as m}from"../use-responsive-point-21b8c601.js";var c=["forceAloneRow","hidden"];var h={xs:24,sm:24,md:24,lg:24,xl:24,xxl:24};var g=function n(i){var o=i.forceAloneRow,l=i.hidden,u=r(i,c);var s=o?h:u;if(l)return null;return a(t,e({},s,{children:i.children}))};g["domTypeName"]="FormCol";var x=["leftList","rightList","rowColTotal","justify","forceAloneRow","hidden","leftSpaceProps","rightSpaceProps"];var y={xs:24,sm:24,md:24,lg:24,xl:24,xxl:24};var L=function f(d){var p=d,v=p.leftList,m=p.rightList,c=p.rowColTotal,h=p.justify,g=p.forceAloneRow,L=p.hidden,w=p.leftSpaceProps,C=p.rightSpaceProps,j=r(p,x);var T=(v||[]).filter(Boolean);var N=(m||[]).filter(Boolean);var F=T.length>0&&N.length>0;var G=g||F?y:{};var O=s((function(){if(h)return h;if(F)return"space-between";if(g)return"end";if(c===1)return"start";return"end"}),[g,F,h,c]);var P=u(d.className,"v-form-col-operate");if(L)return null;return a(t,e({},j,G,{className:P,children:a(n.Item,{children:l(i,{justify:O,wrap:false,children:[a(o,e({},w,{children:T.map((function(r){return r}))})),a(o,e({},C,{style:e({overflowX:"auto"},C==null?void 0:C.style),children:N==null?void 0:N.map((function(r){return r}))}))]})})}))};L["domTypeName"]="FormOperateCol";var w=function r(e,t){try{var n=[];var i=function r(t){var n=e[t];return{index:t,value:n>24?24:n}};var o=true;var a=[];var l=0;var u=0;while(o){var s=e[l];a.push(i(l));if(s>=24){n.push(a);a=[];u=0}else if(l===e.length-1){n.push(a)}else{u+=s;if(u>=24){n.push(a);a=[];u=0}}l=l+1;if(l>=e.length){o=false}}var f=n.find((function(r){return!!r.find((function(r){return r.index===t}))}))||[];var d=0;var p=0;f.forEach((function(r,e){if(r.index===t)p=e;if(r.index<t){d=d+r.value}}));if(d===24||d===0){f[p].value=24}else{f[p].value=24-d}return{gridList:n.reduce((function(r,e){return r.concat(e)})).map((function(r){return r.value})),gridGroupList:n}}catch(r){return{gridList:e,gridGroupList:[]}}};var C={xs:24,sm:12,md:12,lg:8,xl:8,xxl:6};var j={xs:24,sm:12,md:12,lg:6,xl:6,xxl:6};var T=function r(t){var n=m()||"md";var o=p(t.children).filter((function(r){if(!r||!f(r))return false;return v(r.type["domTypeName"],["FormOperateCol","FormCol"])}));var l=t.gridSize==="small"?j:C;var u=s((function(){var r=o.findIndex((function(r){return r.type["domTypeName"]==="FormOperateCol"}));if(n===undefined){return{gridList:[],gridGroupList:[]}}var e=o.map((function(e,t){var i,o;if(t===r)return 0;var a=(i=e.props)==null?void 0:i.span;return((o=e.props)==null?void 0:o[n])||a||l[n]}));if(r<0){return{gridList:e,gridGroupList:[]}}return w(e,r)}),[o,l,n]),c=u.gridList,h=u.gridGroupList;return a(i,e({},t,{children:o.map((function(r,t){var i;var o=e({},l,r.props);var a=e({key:t},o,(i={},i[n]=c[t]||o[n],i));if(r.type["domTypeName"]==="FormOperateCol"){a["rowColTotal"]=h.length}return d(r,a)}))}))};var N={Row:T,Col:g,OperateCol:L};export{N as FormGrid};
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["@flatbiz/antd/src/form-grid/form-col.tsx","@flatbiz/antd/src/form-grid/form-operate-col.tsx","@flatbiz/antd/src/form-grid/utils.ts","@flatbiz/antd/src/form-grid/form-row.tsx","@flatbiz/antd/src/form-grid/index.ts"],"sourcesContent":["import { Col } from 'antd';\nimport { ReactNode } from 'react';\nconst forceAloneRowGrid = { xs: 24, sm: 24, md: 24, lg: 24, xl: 24, xxl: 24 };\nexport type FormColProps = {\n // 栅格占位格数,不考虑响应式\n span?: number;\n /** 屏幕 < 576px */\n xs?: number;\n /** 屏幕 ≥ 576px */\n sm?: number;\n /** 屏幕 ≥ 768px */\n md?: number;\n /** 屏幕 ≥ 992px */\n lg?: number;\n /** 屏幕 ≥ 1200px */\n xl?: number;\n /** 屏幕 ≥ 1600px */\n xxl?: number;\n /** 强制单独一行 */\n forceAloneRow?: boolean;\n children?: ReactNode | ReactNode[];\n hidden?: boolean;\n};\n\n/**\n * 网格响应式布局,默认值:{ xs: 24, sm: 12, md: 12, lg: 8, xl: 8, xxl: 6 }\n *```\n * 1. 设置 span 栅格占位格数,不考虑响应式\n * 2. grid 自定义响应式网格布局\n * xs: 屏幕 < 576px\n * sm: 屏幕 ≥ 576px\n * md: 屏幕 ≥ 768px\n * lg: 屏幕 ≥ 992px\n * xl: 屏幕 ≥ 1200px\n * xxl: 屏幕 ≥ 1600px\n * ```\n */\nexport const FormCol = (props: FormColProps) => {\n const { forceAloneRow, hidden, ...otherProps } = props;\n const forceGrid = forceAloneRow ? forceAloneRowGrid : otherProps;\n if (hidden) return null;\n return <Col {...forceGrid}>{props.children}</Col>;\n};\n\nFormCol['domTypeName'] = 'FormCol';\n","import { classNames } from '@dimjs/utils';\nimport { Col, Form, Row, RowProps, Space, SpaceProps } from 'antd';\nimport { ReactElement, useMemo } from 'react';\n\nconst fullGrid = { xs: 24, sm: 24, md: 24, lg: 24, xl: 24, xxl: 24 };\nexport type FormOperateColProps = {\n className?: string;\n leftList?: Array<ReactElement | null>;\n rightList?: Array<ReactElement | null>;\n // left、right 对齐方式,优先级最高\n justify?: RowProps['justify'];\n /** 强制单独一行 */\n forceAloneRow?: boolean;\n hidden?: boolean;\n leftSpaceProps?: SpaceProps;\n rightSpaceProps?: SpaceProps;\n};\n\n/**\n * FormOperateCol 布局说明\n * ```\n * 1. 网格数以及位置为动态计算,不支持 xs、sm、md等\n * 2. 如果FormRow只有一行col,则OperateCol会在当前行剩余网格内居左对齐\n * 3. 如果同时设置 leftList、rightList,则此cell会强制独占一行,并左右布局\n * 4. 如果只设置 leftList、rightList其中一个,则会在最后一行剩余网格内居右对齐\n * ```\n */\nexport const FormOperateCol = (props: FormOperateColProps) => {\n const {\n leftList,\n rightList,\n rowColTotal,\n justify,\n forceAloneRow,\n hidden,\n leftSpaceProps,\n rightSpaceProps,\n ...otherProps\n } = props as FormOperateColProps & {\n rowColTotal: number;\n };\n const _leftList = (leftList || []).filter(Boolean);\n const _rightList = (rightList || []).filter(Boolean);\n const hasAll = _leftList.length > 0 && _rightList.length > 0;\n const forceGrid = forceAloneRow || hasAll ? fullGrid : {};\n\n const colJustify = useMemo(() => {\n if (justify) return justify;\n if (hasAll) return 'space-between';\n if (forceAloneRow) return 'end';\n if (rowColTotal === 1) return 'start';\n return 'end';\n }, [forceAloneRow, hasAll, justify, rowColTotal]);\n\n const className = classNames(props.className, 'v-form-col-operate');\n\n if (hidden) return null;\n\n return (\n <Col {...otherProps} {...forceGrid} className={className}>\n <Form.Item>\n <Row justify={colJustify}>\n <Space {...leftSpaceProps}>{_leftList.map((item) => item)}</Space>\n <Space {...rightSpaceProps}>{_rightList?.map((item) => item)}</Space>\n </Row>\n </Form.Item>\n </Col>\n );\n};\n\nFormOperateCol['domTypeName'] = 'FormOperateCol';\n","/**\n * 用于计算 operateCol 所占用网格数\n * ```\n * col网格数据 [8,8,8,12,24,0,8] => [[8,8,8],[12],[24],[0,8]],分组后计算operateCol所在行中剩余网格数\n * ```\n * @returns\n */\nexport const calculateOperateGrid = (gridList: number[], operateColIndex: number) => {\n try {\n const groupList = [] as { index: number; value: number }[][];\n const getGroupItem = function (index) {\n const value = gridList[index];\n return { index, value: value > 24 ? 24 : value };\n };\n let condition = true;\n let groupItemList = [] as { index: number; value: number }[];\n let currentIndex = 0;\n let total = 0;\n while (condition) {\n const currentValue = gridList[currentIndex];\n groupItemList.push(getGroupItem(currentIndex));\n if (currentValue >= 24) {\n groupList.push(groupItemList);\n groupItemList = [];\n total = 0;\n } else if (currentIndex === gridList.length - 1) {\n groupList.push(groupItemList);\n } else {\n total += currentValue;\n if (total >= 24) {\n groupList.push(groupItemList);\n groupItemList = [];\n total = 0;\n }\n }\n currentIndex = currentIndex + 1;\n if (currentIndex >= gridList.length) {\n condition = false;\n }\n }\n const hasOperateList =\n groupList.find((item) => !!item.find((temp) => temp.index === operateColIndex)) || [];\n let hasOperateTotal = 0;\n let hasOperateIndex = 0;\n hasOperateList.forEach((item, index) => {\n if (item.index === operateColIndex) hasOperateIndex = index;\n if (item.index < operateColIndex) {\n hasOperateTotal = hasOperateTotal + item.value;\n }\n });\n if (hasOperateTotal === 24 || hasOperateTotal === 0) {\n hasOperateList[hasOperateIndex].value = 24;\n } else {\n hasOperateList[hasOperateIndex].value = 24 - hasOperateTotal;\n }\n\n return {\n gridList: groupList.reduce((a, b) => a.concat(b)).map((temp) => temp.value),\n gridGroupList: groupList,\n };\n } catch (error) {\n return {\n gridList,\n gridGroupList: [],\n };\n }\n};\n","import { toArray, valueIsEqual } from '@flatbiz/utils';\nimport { Row, RowProps } from 'antd';\nimport { cloneElement, isValidElement, ReactElement, ReactNode, useMemo } from 'react';\nimport { useResponsivePoint } from '../fba-hooks/use-responsive-point';\nimport { calculateOperateGrid } from './utils';\n\nexport type FormRowProps = RowProps & {\n children?: ReactNode | ReactNode[];\n /**\n * defaultGrid = { xs: 24, sm: 12, md: 12, lg: 8, xl: 8, xxl: 6 };\n * defaultSmallGrid = { xs: 24, sm: 8, md: 8, lg: 6, xl: 6, xxl: 6 };\n */\n gridSize?: 'default' | 'small';\n};\nconst defaultGrid = { xs: 24, sm: 12, md: 12, lg: 8, xl: 8, xxl: 6 };\nconst defaultSmallGrid = { xs: 24, sm: 12, md: 12, lg: 6, xl: 6, xxl: 6 };\n\n/**\n * FormItem网格响应式布局\n *```\n * 1. 应用场景:Form条件布局\n * 2. 子元素只能是 FormGrid.Col、FormGrid.OperateCol,其他会被忽略\n * 3. 所有子元素中只能存在一个 FormGrid.OperateCol\n */\nexport const FormRow = (props: FormRowProps) => {\n const screenType = useResponsivePoint() || 'md';\n const childrenList = toArray<ReactElement>(props.children).filter((item) => {\n if (!item || !isValidElement(item)) return false;\n return valueIsEqual(item.type['domTypeName'], ['FormOperateCol', 'FormCol']);\n });\n const defaultGridSize = props.gridSize === 'small' ? defaultSmallGrid : defaultGrid;\n const { gridList, gridGroupList } = useMemo(() => {\n const operateColIndex = childrenList.findIndex((item) => {\n return item.type['domTypeName'] === 'FormOperateCol';\n });\n if (screenType === undefined) {\n return { gridList: [] as number[], gridGroupList: [] };\n }\n const _currentGridList = childrenList.map((temp, index) => {\n if (index === operateColIndex) return 0;\n const span = temp.props?.span as number;\n return temp.props?.[screenType] || span || defaultGridSize[screenType];\n });\n if (operateColIndex < 0) {\n return { gridList: _currentGridList, gridGroupList: [] };\n }\n return calculateOperateGrid(_currentGridList, operateColIndex);\n }, [childrenList, defaultGridSize, screenType]);\n\n // if (!screenType) return <Fragment>{props.children}</Fragment>;\n return (\n <Row {...props}>\n {childrenList.map((item, index) => {\n const itemProps = { ...defaultGridSize, ...item.props };\n const newProps = {\n key: index,\n ...itemProps,\n [screenType]: gridList[index] || itemProps[screenType],\n };\n if (item.type['domTypeName'] === 'FormOperateCol') {\n newProps['rowColTotal'] = gridGroupList.length;\n }\n return cloneElement(item, newProps);\n })}\n </Row>\n );\n};\n","import { FormCol } from './form-col';\nimport { FormOperateCol } from './form-operate-col';\nimport { FormRow } from './form-row';\n\nexport const FormGrid = {\n /**\n * FormItem网格响应式布局\n *```\n * 1. 应用场景:Form条件布局\n * 2. 子元素只能是 FormCol、FormOperateCol,其他会被忽略\n * 3. 所有子元素中只能存在一个 FormOperateCol\n */\n Row: FormRow,\n /**\n * 网格响应式布局,默认值:{ xs: 24, sm: 12, md: 12, lg: 8, xl: 8, xxl: 6 }\n *```\n * 1. 设置 span 栅格占位格数,不考虑响应式\n * 2. grid 自定义响应式网格布局\n * xs: 屏幕 < 576px\n * sm: 屏幕 ≥ 576px\n * md: 屏幕 ≥ 768px\n * lg: 屏幕 ≥ 992px\n * xl: 屏幕 ≥ 1200px\n * xxl: 屏幕 ≥ 1600px\n * ```\n */\n Col: FormCol,\n /**\n * FormOperateCol 布局说明\n * ```\n * 1. 网格数以及位置为动态计算,不支持 xs、sm、md等\n * 2. 如果FormRow只有一行col,则OperateCol会在当前行剩余网格内居左对齐\n * 3. 如果同时设置 leftList、rightList,则此cell会强制独占一行,并左右布局\n * 4. 如果只设置 leftList、rightList其中一个,则会在最后一行剩余网格内居右对齐\n * ```\n */\n OperateCol: FormOperateCol,\n};\n"],"names":["forceAloneRowGrid","xs","sm","md","lg","xl","xxl","FormCol","props","forceAloneRow","hidden","otherProps","_objectWithoutPropertiesLoose","_excluded","forceGrid","_jsx","Col","_extends","children","fullGrid","FormOperateCol","_ref","leftList","rightList","rowColTotal","justify","leftSpaceProps","rightSpaceProps","_leftList","filter","Boolean","_rightList","hasAll","length","colJustify","useMemo","className","_classNames","Form","Item","_jsxs","Row","Space","map","item","calculateOperateGrid","gridList","operateColIndex","groupList","getGroupItem","index","value","condition","groupItemList","currentIndex","total","currentValue","push","hasOperateList","find","temp","hasOperateTotal","hasOperateIndex","forEach","reduce","a","b","concat","gridGroupList","error","defaultGrid","defaultSmallGrid","FormRow","screenType","useResponsivePoint","childrenList","toArray","isValidElement","valueIsEqual","type","defaultGridSize","gridSize","_useMemo","findIndex","undefined","_currentGridList","_temp$props","_temp$props2","span","_extends2","itemProps","newProps","key","cloneElement","FormGrid","OperateCol"],"mappings":";mcAEA,IAAMA,EAAoB,CAAEC,GAAI,GAAIC,GAAI,GAAIC,GAAI,GAAIC,GAAI,GAAIC,GAAI,GAAIC,IAAK,IAmClE,IAAMC,EAAU,SAAVA,EAAWC,GACtB,IAAQC,EAAyCD,EAAzCC,cAAeC,EAA0BF,EAA1BE,OAAWC,EAAUC,EAAKJ,EAAKK,GACtD,IAAMC,EAAYL,EAAgBT,EAAoBW,EACtD,GAAID,EAAQ,OAAO,KACnB,OAAOK,EAACC,EAAGC,KAAKH,EAAS,CAAAI,SAAGV,EAAMU,WACpC,EAEAX,EAAQ,eAAiB,6HCxCzB,IAAMY,EAAW,CAAElB,GAAI,GAAIC,GAAI,GAAIC,GAAI,GAAIC,GAAI,GAAIC,GAAI,GAAIC,IAAK,IAuBzD,IAAMc,EAAiB,SAAjBA,EAAkBZ,GAC7B,IAAAa,EAUIb,EATFc,EAAQD,EAARC,SACAC,EAASF,EAATE,UACAC,EAAWH,EAAXG,YACAC,EAAOJ,EAAPI,QACAhB,EAAaY,EAAbZ,cACAC,EAAMW,EAANX,OACAgB,EAAcL,EAAdK,eACAC,EAAeN,EAAfM,gBACGhB,EAAUC,EAAAS,EAAAR,GAIf,IAAMe,GAAaN,GAAY,IAAIO,OAAOC,SAC1C,IAAMC,GAAcR,GAAa,IAAIM,OAAOC,SAC5C,IAAME,EAASJ,EAAUK,OAAS,GAAKF,EAAWE,OAAS,EAC3D,IAAMnB,EAAYL,GAAiBuB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d/src/form-grid/form-operate-col.tsx","@flatbiz/antd/src/form-grid/utils.ts","@flatbiz/antd/src/form-grid/form-row.tsx","@flatbiz/antd/src/form-grid/index.ts"],"sourcesContent":["import { Col } from 'antd';\nimport { ReactNode } from 'react';\nconst forceAloneRowGrid = { xs: 24, sm: 24, md: 24, lg: 24, xl: 24, xxl: 24 };\nexport type FormColProps = {\n // 栅格占位格数,不考虑响应式\n span?: number;\n /** 屏幕 < 576px */\n xs?: number;\n /** 屏幕 ≥ 576px */\n sm?: number;\n /** 屏幕 ≥ 768px */\n md?: number;\n /** 屏幕 ≥ 992px */\n lg?: number;\n /** 屏幕 ≥ 1200px */\n xl?: number;\n /** 屏幕 ≥ 1600px */\n xxl?: number;\n /** 强制单独一行 */\n forceAloneRow?: boolean;\n children?: ReactNode | ReactNode[];\n hidden?: boolean;\n};\n\n/**\n * 网格响应式布局,默认值:{ xs: 24, sm: 12, md: 12, lg: 8, xl: 8, xxl: 6 }\n *```\n * 1. 设置 span 栅格占位格数,不考虑响应式\n * 2. grid 自定义响应式网格布局\n * xs: 屏幕 < 576px\n * sm: 屏幕 ≥ 576px\n * md: 屏幕 ≥ 768px\n * lg: 屏幕 ≥ 992px\n * xl: 屏幕 ≥ 1200px\n * xxl: 屏幕 ≥ 1600px\n * ```\n */\nexport const FormCol = (props: FormColProps) => {\n const { forceAloneRow, hidden, ...otherProps } = props;\n const forceGrid = forceAloneRow ? forceAloneRowGrid : otherProps;\n if (hidden) return null;\n return <Col {...forceGrid}>{props.children}</Col>;\n};\n\nFormCol['domTypeName'] = 'FormCol';\n","import { classNames } from '@dimjs/utils';\nimport { Col, Form, Row, RowProps, Space, SpaceProps } from 'antd';\nimport { ReactElement, useMemo } from 'react';\n\nconst fullGrid = { xs: 24, sm: 24, md: 24, lg: 24, xl: 24, xxl: 24 };\nexport type FormOperateColProps = {\n className?: string;\n leftList?: Array<ReactElement | null>;\n rightList?: Array<ReactElement | null>;\n // left、right 对齐方式,优先级最高\n justify?: RowProps['justify'];\n /** 强制单独一行 */\n forceAloneRow?: boolean;\n hidden?: boolean;\n leftSpaceProps?: SpaceProps;\n rightSpaceProps?: SpaceProps;\n};\n\n/**\n * FormOperateCol 布局说明\n * ```\n * 1. 网格数以及位置为动态计算,不支持 xs、sm、md等\n * 2. 如果FormRow只有一行col,则OperateCol会在当前行剩余网格内居左对齐\n * 3. 如果同时设置 leftList、rightList,则此cell会强制独占一行,并左右布局\n * 4. 如果只设置 leftList、rightList其中一个,则会在最后一行剩余网格内居右对齐\n * ```\n */\nexport const FormOperateCol = (props: FormOperateColProps) => {\n const {\n leftList,\n rightList,\n rowColTotal,\n justify,\n forceAloneRow,\n hidden,\n leftSpaceProps,\n rightSpaceProps,\n ...otherProps\n } = props as FormOperateColProps & {\n rowColTotal: number;\n };\n const _leftList = (leftList || []).filter(Boolean);\n const _rightList = (rightList || []).filter(Boolean);\n const hasAll = _leftList.length > 0 && _rightList.length > 0;\n const forceGrid = forceAloneRow || hasAll ? fullGrid : {};\n\n const colJustify = useMemo(() => {\n if (justify) return justify;\n if (hasAll) return 'space-between';\n if (forceAloneRow) return 'end';\n if (rowColTotal === 1) return 'start';\n return 'end';\n }, [forceAloneRow, hasAll, justify, rowColTotal]);\n\n const className = classNames(props.className, 'v-form-col-operate');\n\n if (hidden) return null;\n\n return (\n <Col {...otherProps} {...forceGrid} className={className}>\n <Form.Item>\n <Row justify={colJustify} wrap={false}>\n <Space {...leftSpaceProps}>{_leftList.map((item) => item)}</Space>\n <Space {...rightSpaceProps} style={{ overflowX: 'auto', ...rightSpaceProps?.style }}>\n {_rightList?.map((item) => item)}\n </Space>\n </Row>\n </Form.Item>\n </Col>\n );\n};\n\nFormOperateCol['domTypeName'] = 'FormOperateCol';\n","/**\n * 用于计算 operateCol 所占用网格数\n * ```\n * col网格数据 [8,8,8,12,24,0,8] => [[8,8,8],[12],[24],[0,8]],分组后计算operateCol所在行中剩余网格数\n * ```\n * @returns\n */\nexport const calculateOperateGrid = (gridList: number[], operateColIndex: number) => {\n try {\n const groupList = [] as { index: number; value: number }[][];\n const getGroupItem = function (index) {\n const value = gridList[index];\n return { index, value: value > 24 ? 24 : value };\n };\n let condition = true;\n let groupItemList = [] as { index: number; value: number }[];\n let currentIndex = 0;\n let total = 0;\n while (condition) {\n const currentValue = gridList[currentIndex];\n groupItemList.push(getGroupItem(currentIndex));\n if (currentValue >= 24) {\n groupList.push(groupItemList);\n groupItemList = [];\n total = 0;\n } else if (currentIndex === gridList.length - 1) {\n groupList.push(groupItemList);\n } else {\n total += currentValue;\n if (total >= 24) {\n groupList.push(groupItemList);\n groupItemList = [];\n total = 0;\n }\n }\n currentIndex = currentIndex + 1;\n if (currentIndex >= gridList.length) {\n condition = false;\n }\n }\n const hasOperateList =\n groupList.find((item) => !!item.find((temp) => temp.index === operateColIndex)) || [];\n let hasOperateTotal = 0;\n let hasOperateIndex = 0;\n hasOperateList.forEach((item, index) => {\n if (item.index === operateColIndex) hasOperateIndex = index;\n if (item.index < operateColIndex) {\n hasOperateTotal = hasOperateTotal + item.value;\n }\n });\n if (hasOperateTotal === 24 || hasOperateTotal === 0) {\n hasOperateList[hasOperateIndex].value = 24;\n } else {\n hasOperateList[hasOperateIndex].value = 24 - hasOperateTotal;\n }\n\n return {\n gridList: groupList.reduce((a, b) => a.concat(b)).map((temp) => temp.value),\n gridGroupList: groupList,\n };\n } catch (error) {\n return {\n gridList,\n gridGroupList: [],\n };\n }\n};\n","import { toArray, valueIsEqual } from '@flatbiz/utils';\nimport { Row, RowProps } from 'antd';\nimport { cloneElement, isValidElement, ReactElement, ReactNode, useMemo } from 'react';\nimport { useResponsivePoint } from '../fba-hooks/use-responsive-point';\nimport { calculateOperateGrid } from './utils';\n\nexport type FormRowProps = RowProps & {\n children?: ReactNode | ReactNode[];\n /**\n * defaultGrid = { xs: 24, sm: 12, md: 12, lg: 8, xl: 8, xxl: 6 };\n * defaultSmallGrid = { xs: 24, sm: 8, md: 8, lg: 6, xl: 6, xxl: 6 };\n */\n gridSize?: 'default' | 'small';\n};\nconst defaultGrid = { xs: 24, sm: 12, md: 12, lg: 8, xl: 8, xxl: 6 };\nconst defaultSmallGrid = { xs: 24, sm: 12, md: 12, lg: 6, xl: 6, xxl: 6 };\n\n/**\n * FormItem网格响应式布局\n *```\n * 1. 应用场景:Form条件布局\n * 2. 子元素只能是 FormGrid.Col、FormGrid.OperateCol,其他会被忽略\n * 3. 所有子元素中只能存在一个 FormGrid.OperateCol\n */\nexport const FormRow = (props: FormRowProps) => {\n const screenType = useResponsivePoint() || 'md';\n const childrenList = toArray<ReactElement>(props.children).filter((item) => {\n if (!item || !isValidElement(item)) return false;\n return valueIsEqual(item.type['domTypeName'], ['FormOperateCol', 'FormCol']);\n });\n const defaultGridSize = props.gridSize === 'small' ? defaultSmallGrid : defaultGrid;\n const { gridList, gridGroupList } = useMemo(() => {\n const operateColIndex = childrenList.findIndex((item) => {\n return item.type['domTypeName'] === 'FormOperateCol';\n });\n if (screenType === undefined) {\n return { gridList: [] as number[], gridGroupList: [] };\n }\n const _currentGridList = childrenList.map((temp, index) => {\n if (index === operateColIndex) return 0;\n const span = temp.props?.span as number;\n return temp.props?.[screenType] || span || defaultGridSize[screenType];\n });\n if (operateColIndex < 0) {\n return { gridList: _currentGridList, gridGroupList: [] };\n }\n return calculateOperateGrid(_currentGridList, operateColIndex);\n }, [childrenList, defaultGridSize, screenType]);\n\n // if (!screenType) return <Fragment>{props.children}</Fragment>;\n return (\n <Row {...props}>\n {childrenList.map((item, index) => {\n const itemProps = { ...defaultGridSize, ...item.props };\n const newProps = {\n key: index,\n ...itemProps,\n [screenType]: gridList[index] || itemProps[screenType],\n };\n if (item.type['domTypeName'] === 'FormOperateCol') {\n newProps['rowColTotal'] = gridGroupList.length;\n }\n return cloneElement(item, newProps);\n })}\n </Row>\n );\n};\n","import { FormCol } from './form-col';\nimport { FormOperateCol } from './form-operate-col';\nimport { FormRow } from './form-row';\n\nexport const FormGrid = {\n /**\n * FormItem网格响应式布局\n *```\n * 1. 应用场景:Form条件布局\n * 2. 子元素只能是 FormCol、FormOperateCol,其他会被忽略\n * 3. 所有子元素中只能存在一个 FormOperateCol\n */\n Row: FormRow,\n /**\n * 网格响应式布局,默认值:{ xs: 24, sm: 12, md: 12, lg: 8, xl: 8, xxl: 6 }\n *```\n * 1. 设置 span 栅格占位格数,不考虑响应式\n * 2. grid 自定义响应式网格布局\n * xs: 屏幕 < 576px\n * sm: 屏幕 ≥ 576px\n * md: 屏幕 ≥ 768px\n * lg: 屏幕 ≥ 992px\n * xl: 屏幕 ≥ 1200px\n * xxl: 屏幕 ≥ 1600px\n * ```\n */\n Col: FormCol,\n /**\n * FormOperateCol 布局说明\n * ```\n * 1. 网格数以及位置为动态计算,不支持 xs、sm、md等\n * 2. 如果FormRow只有一行col,则OperateCol会在当前行剩余网格内居左对齐\n * 3. 如果同时设置 leftList、rightList,则此cell会强制独占一行,并左右布局\n * 4. 如果只设置 leftList、rightList其中一个,则会在最后一行剩余网格内居右对齐\n * ```\n */\n OperateCol: FormOperateCol,\n};\n"],"names":["forceAloneRowGrid","xs","sm","md","lg","xl","xxl","FormCol","props","forceAloneRow","hidden","otherProps","_objectWithoutPropertiesLoose","_excluded","forceGrid","_jsx","Col","_extends","children","fullGrid","FormOperateCol","_ref","leftList","rightList","rowColTotal","justify","leftSpaceProps","rightSpaceProps","_leftList","filter","Boolean","_rightList","hasAll","length","colJustify","useMemo","className","_classNames","Form","Item","_jsxs","Row","wrap","Space","map","item","style","overflowX","calculateOperateGrid","gridList","operateColIndex","groupList","getGroupItem","index","value","condition","groupItemList","currentIndex","total","currentValue","push","hasOperateList","find","temp","hasOperateTotal","hasOperateIndex","forEach","reduce","a","b","concat","gridGroupList","error","defaultGrid","defaultSmallGrid","FormRow","screenType","useResponsivePoint","childrenList","toArray","isValidElement","valueIsEqual","type","defaultGridSize","gridSize","_useMemo","findIndex","undefined","_currentGridList","_temp$props","_temp$props2","span","_extends2","itemProps","newProps","key","cloneElement","FormGrid","OperateCol"],"m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cAAe,GACpD,CACA,IAAMiB,EAAmBV,EAAalC,KAAI,SAACmB,EAAMV,GAAU,IAAAoC,EAAAC,EACzD,GAAIrC,IAAUH,EAAiB,OAAO,EACtC,IAAMyC,GAAIF,EAAG1B,EAAKvD,QAAK,UAAA,EAAViF,EAAYE,KACzB,QAAOD,EAAA3B,EAAKvD,QAALkF,UAAAA,EAAAA,EAAad,KAAee,GAAQR,EAAgBP,EAC7D,IACA,GAAI1B,EAAkB,EAAG,CACvB,MAAO,CAAED,SAAUuC,EAAkBjB,cAAe,GACtD,CACA,OAAOvB,EAAqBwC,EAAkBtC,EAC/C,GAAE,CAAC4B,EAAcK,EAAiBP,IAhB3B3B,EAAQoC,EAARpC,SAAUsB,EAAac,EAAbd,cAmBlB,OACExD,EAAC0B,EAAGxB,KAAKT,EAAK,CAAAU,SACX4D,EAAalC,KAAI,SAACC,EAAMQ,GAAU,IAAAuC,EACjC,IAAMC,EAAS5E,EAAA,CAAA,EAAQkE,EAAoBtC,EAAKrC,OAChD,IAAMsF,EAAQ7E,EAAA,CACZ8E,IAAK1C,GACFwC,GAASD,KAAAA,EACXhB,GAAa3B,EAASI,IAAUwC,EAAUjB,GAAWgB,IAExD,GAAI/C,EAAKqC,KAAK,iBAAmB,iBAAkB,CACjDY,EAAS,eAAiBvB,EAActC,MAC1C,CACA,OAAO+D,EAAanD,EAAMiD,QAIlC,EC9DO,IAAMG,EAAW,CAQtBxD,IAAKkC,EAcL3D,IAAKT,EAUL2F,WAAY9E"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
import './index.css';
|
|
3
3
|
/*! @flatjs/forge MIT @flatbiz/antd */
|
|
4
|
-
import{_ as r,a as e}from"../_rollupPluginBabelHelpers-1f4d8910.js";import{composeProps as
|
|
4
|
+
import{_ as r,a as e}from"../_rollupPluginBabelHelpers-1f4d8910.js";import{composeProps as a}from"@flatbiz/utils";import{Form as i}from"antd";import{isValidElement as t,cloneElement as l}from"react";import{jsx as n,jsxs as o}from"react/jsx-runtime";var p=["wrapper","children"],f=["wrapper","children","before","after","inputNormalize","outputNormalize"];var u=function e(i){var t=i.wrapper,f=i.children,u=r(i,p);var m=u.hasOwnProperty("value");if(m&&i.inputNormalize){u["value"]=i.inputNormalize(u["value"])}var s=l(f,a(f.props,u,true));if(t){return t(s)}if(i.before||i.after){return o("div",{style:{display:"flex",alignItems:"center"},children:[i.before?n("span",{style:{marginRight:10},children:i.before}):null,n("div",{style:{flex:1},children:s}),i.after?n("span",{style:{marginLeft:10},children:i.after}):null]})}return s};var m=function a(l){var o=l.wrapper,p=l.children,m=l.before,s=l.after,c=l.inputNormalize,d=l.outputNormalize,h=r(l,f);return n(i.Item,e({normalize:d},h,{children:t(p)?n(u,{wrapper:o,before:m,after:s,inputNormalize:c,children:p}):p}))};export{m as FormItemWrapper};
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["@flatbiz/antd/src/form-item-wrapper/form-item-wrapper.tsx"],"sourcesContent":["import { composeProps } from '@flatbiz/utils';\nimport { Form, FormItemProps } from 'antd';\nimport { cloneElement, isValidElement, ReactElement, ReactNode } from 'react';\n\nexport interface FormItemWrapperProps extends FormItemProps {\n wrapper?: (children: ReactNode) => ReactElement;\n /** 设置wrapper后,before、after失效 */\n before?: ReactNode;\n /** 设置wrapper后,before、after失效 */\n after?: ReactNode;\n}\n\
|
|
1
|
+
{"version":3,"file":"index.js","sources":["@flatbiz/antd/src/form-item-wrapper/form-item-wrapper.tsx"],"sourcesContent":["import { composeProps, TAny } from '@flatbiz/utils';\nimport { Form, FormItemProps } from 'antd';\nimport { cloneElement, isValidElement, ReactElement, ReactNode } from 'react';\n\nexport interface FormItemWrapperProps extends FormItemProps {\n wrapper?: (children: ReactNode) => ReactElement;\n /** 设置wrapper后,before、after失效 */\n before?: ReactNode;\n /** 设置wrapper后,before、after失效 */\n after?: ReactNode;\n /** value 序列化处理 */\n inputNormalize?: (value?: TAny) => TAny;\n /**\n * onChange 参数序列化处理\n * 如果设置 normalize 属性,outputNormalize将失效\n */\n outputNormalize?: (value?: TAny) => TAny;\n}\n\ntype FormItemWrapperChildrenProps = Pick<\n FormItemWrapperProps,\n 'wrapper' | 'after' | 'before' | 'inputNormalize'\n> & {\n children: ReactElement;\n};\n\nconst FormItemWrapperChildren = (props: FormItemWrapperChildrenProps) => {\n const { wrapper, children, ...rest } = props;\n // composeProps 合并执行 Form.Item 传的 onChange 以及组件本身的方法\n const hasValue = rest.hasOwnProperty('value');\n if (hasValue && props.inputNormalize) {\n rest['value'] = props.inputNormalize(rest['value']);\n }\n const _children = cloneElement(children, composeProps(children.props, rest, true));\n if (wrapper) {\n return wrapper(_children);\n }\n if (props.before || props.after) {\n return (\n <div style={{ display: 'flex', alignItems: 'center' }}>\n {props.before ? <span style={{ marginRight: 10 }}>{props.before}</span> : null}\n <div style={{ flex: 1 }}>{_children}</div>\n {props.after ? <span style={{ marginLeft: 10 }}>{props.after}</span> : null}\n </div>\n );\n }\n return _children;\n};\n\n/**\n * 对 Form.Item 包装处理\n * ```\n * 1. 为 children 增加 before、after\n * 2. 对输入、输出数据进行序列化处理\n * ```\n */\nexport const FormItemWrapper = (props: FormItemWrapperProps) => {\n const { wrapper, children, before, after, inputNormalize, outputNormalize, ...rest } = props;\n\n return (\n <Form.Item normalize={outputNormalize} {...rest}>\n {isValidElement(children) ? (\n <FormItemWrapperChildren\n wrapper={wrapper}\n before={before}\n after={after}\n inputNormalize={inputNormalize}\n >\n {children}\n </FormItemWrapperChildren>\n ) : (\n children\n )}\n </Form.Item>\n );\n};\n"],"names":["FormItemWrapperChildren","props","wrapper","children","rest","_objectWithoutPropertiesLoose","_excluded","hasValue","hasOwnProperty","inputNormalize","_children","cloneElement","composeProps","before","after","_jsxs","style","display","alignItems","_jsx","marginRight","flex","marginLeft","FormItemWrapper","outputNormalize","_excluded2","Form","Item","_extends","normalize","isValidElement"],"mappings":";mW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300
|
name: string;
|
|
1301
1301
|
};
|
|
1302
1302
|
export declare const FormItemHidden: (props: FormItemHiddenProps) => JSX.Element;
|
|
1303
|
-
export type FormItemNormalizeProps = {
|
|
1304
|
-
value?: TAny;
|
|
1305
|
-
onChange?: (value?: TAny, ...other: any[]) => void;
|
|
1306
|
-
/** value 序列化处理 */
|
|
1307
|
-
inputNormalize?: (value?: TAny) => TAny;
|
|
1308
|
-
/** onChange 参数序列化处理 */
|
|
1309
|
-
outputNormalize?: (value?: TAny) => TAny;
|
|
1310
|
-
children: ReactElement | null;
|
|
1311
|
-
};
|
|
1312
|
-
/**
|
|
1313
|
-
* 解决 Form.Item 输入 与 输出 不同问题
|
|
1314
|
-
* @param props
|
|
1315
|
-
* ```
|
|
1316
|
-
* 例如:
|
|
1317
|
-
* <Form.Item name="abc">
|
|
1318
|
-
* <Select 多选 />
|
|
1319
|
-
* </Form.Item>
|
|
1320
|
-
* 1. 接口给的数据是'v1,v2',但Form.Item内部需要的是['v1', 'v2']
|
|
1321
|
-
* 2. Form.Item 内部返回是数据是['v1', 'v2'],但接口需要的是'v1,v2'
|
|
1322
|
-
*
|
|
1323
|
-
* 使用方法
|
|
1324
|
-
* <Form.Item name="abc">
|
|
1325
|
-
* <FormItemNormalize inputNormalize={} outputNormalize={}>
|
|
1326
|
-
* <Select 多选 />
|
|
1327
|
-
* </FormItemNormalize>
|
|
1328
|
-
* </Form.Item>
|
|
1329
|
-
* ```
|
|
1330
|
-
*/
|
|
1331
|
-
export declare const FormItemNormalize: (props: FormItemNormalizeProps) => JSX.Element | null;
|
|
1332
1303
|
export interface FormItemWrapperProps extends FormItemProps {
|
|
1333
1304
|
wrapper?: (children: ReactNode) => ReactElement;
|
|
1334
1305
|
/** 设置wrapper后,before、after失效 */
|
|
1335
1306
|
before?: ReactNode;
|
|
1336
1307
|
/** 设置wrapper后,before、after失效 */
|
|
1337
1308
|
after?: ReactNode;
|
|
1309
|
+
/** value 序列化处理 */
|
|
1310
|
+
inputNormalize?: (value?: TAny) => TAny;
|
|
1311
|
+
/**
|
|
1312
|
+
* onChange 参数序列化处理
|
|
1313
|
+
* 如果设置 normalize 属性,outputNormalize将失效
|
|
1314
|
+
*/
|
|
1315
|
+
outputNormalize?: (value?: TAny) => TAny;
|
|
1338
1316
|
}
|
|
1339
1317
|
/**
|
|
1340
|
-
* 对 Form.Item
|
|
1341
|
-
*
|
|
1342
|
-
*
|
|
1318
|
+
* 对 Form.Item 包装处理
|
|
1319
|
+
* ```
|
|
1320
|
+
* 1. 为 children 增加 before、after
|
|
1321
|
+
* 2. 对输入、输出数据进行序列化处理
|
|
1322
|
+
* ```
|
|
1343
1323
|
*/
|
|
1344
1324
|
export declare const FormItemWrapper: (props: FormItemWrapperProps) => JSX.Element;
|
|
1345
1325
|
export type GapProps = {
|
package/package.json
CHANGED
|
File without changes
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
/* eslint-disable */
|
|
2
|
-
import './index.css';
|
|
3
|
-
/*! @flatjs/forge MIT @flatbiz/antd */
|
|
4
|
-
import{a as r}from"../_rollupPluginBabelHelpers-1f4d8910.js";import{useMemo as e}from"react";import{jsx as n}from"react/jsx-runtime";var l=function l(o){var a=o.value,i=o.onChange,t=o.inputNormalize,u=o.outputNormalize;var p=e((function(){if(t){return t(a)}return a}),[t,a]);var v=function r(e){for(var n=arguments.length,l=new Array(n>1?n-1:0),o=1;o<n;o++){l[o-1]=arguments[o]}if(u){i==null?void 0:i(u(e),l)}else{i==null?void 0:i(e,l)}};if(!o.children)return null;var f=o.children.type;var m=o.children.props;return n(f,r({},m,{value:p,onChange:v}))};export{l as FormItemNormalize};
|
|
5
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["@flatbiz/antd/src/form-item-normalize/form-item-normalize.tsx"],"sourcesContent":["import { TAny } from '@flatbiz/utils';\nimport { ReactElement, useMemo } from 'react';\n\ntype FormItemNormalizeProps = {\n value?: TAny;\n onChange?: (value?: TAny, ...other) => void;\n /** value 序列化处理 */\n inputNormalize?: (value?: TAny) => TAny;\n /** onChange 参数序列化处理 */\n outputNormalize?: (value?: TAny) => TAny;\n children: ReactElement | null;\n};\n/**\n * 解决 Form.Item 输入 与 输出 不同问题\n * @param props\n * ```\n * 例如:\n * <Form.Item name=\"abc\">\n * <Select 多选 />\n * </Form.Item>\n * 1. 接口给的数据是'v1,v2',但Form.Item内部需要的是['v1', 'v2']\n * 2. Form.Item 内部返回是数据是['v1', 'v2'],但接口需要的是'v1,v2'\n *\n * 使用方法\n * <Form.Item name=\"abc\">\n * <FormItemNormalize inputNormalize={} outputNormalize={}>\n * <Select 多选 />\n * </FormItemNormalize>\n * </Form.Item>\n * ```\n */\nexport const FormItemNormalize = (props: FormItemNormalizeProps) => {\n const { value, onChange, inputNormalize, outputNormalize } = props;\n const valueNew = useMemo(() => {\n if (inputNormalize) {\n return inputNormalize(value);\n }\n return value;\n }, [inputNormalize, value]);\n\n const onChangeNew = (data, ...otherProps) => {\n if (outputNormalize) {\n onChange?.(outputNormalize(data), otherProps);\n } else {\n onChange?.(data, otherProps);\n }\n };\n\n if (!props.children) return null;\n\n const Node = props.children.type;\n const nodeProps = props.children.props;\n return <Node {...nodeProps} value={valueNew} onChange={onChangeNew} />;\n};\n"],"names":["FormItemNormalize","props","value","onChange","inputNormalize","outputNormalize","valueNew","useMemo","onChangeNew","data","_len","arguments","length","otherProps","Array","_key","children","Node","type","nodeProps","_jsx","_extends"],"mappings":";yIA+BaA,EAAoB,SAApBA,EAAqBC,GAChC,IAAQC,EAAqDD,EAArDC,MAAOC,EAA8CF,EAA9CE,SAAUC,EAAoCH,EAApCG,eAAgBC,EAAoBJ,EAApBI,gBACzC,IAAMC,EAAWC,GAAQ,WACvB,GAAIH,EAAgB,CAClB,OAAOA,EAAeF,EACxB,CACA,OAAOA,CACT,GAAG,CAACE,EAAgBF,IAEpB,IAAMM,EAAc,SAAdA,EAAeC,GAAwB,IAAAC,IAAAA,EAAAC,UAAAC,OAAfC,MAAUC,MAAAJ,EAAAA,EAAAA,OAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAAA,CAAVF,EAAUE,EAAAJ,GAAAA,UAAAI,EAAA,CACtC,GAAIV,EAAiB,CACnBF,GAAQ,UAAA,EAARA,EAAWE,EAAgBI,GAAOI,EACpC,KAAO,CACLV,eAAAA,EAAWM,EAAMI,EACnB,GAGF,IAAKZ,EAAMe,SAAU,OAAO,KAE5B,IAAMC,EAAOhB,EAAMe,SAASE,KAC5B,IAAMC,EAAYlB,EAAMe,SAASf,MACjC,OAAOmB,EAACH,EAAII,KAAKF,EAAS,CAAEjB,MAAOI,EAAUH,SAAUK,IACzD"}
|