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C;CACF,CAAC,CACH,CAAA;AAEU,QAAA,mBAAmB,GAAG,IAAA,2BAAa,EAAC,oCAA4B,EAAE;IAC7E,WAAW,EAAE,qBAAqB;CACnC,CAAC,CAAA","sourcesContent":["import { VueComponent } from '@formily/vue'\nimport { useTree, usePrefix, useDesigner, useComponents } from '../../hooks'\nimport { TreeNodeSymbol, DesignerComponentsSymbol } from '../../context'\nimport { IDesignerComponents } from '../../types'\nimport { TreeNode, GlobalRegistry } from '@designable/core'\nimport { observer } from '@formily/reactive-vue'\nimport cls from 'classnames'\nimport './styles.less'\nimport { defineComponent, PropType, provide, ref, toRef } from 'vue-demi'\nimport { composeExport } from '@jeamn/formily-components/src/__builtins__'\nimport { VNode } from 'vue'\n\nexport interface IComponentTreeWidgetProps {\n  components: IDesignerComponents\n}\n\nexport interface ITreeNodeWidgetProps {\n  node: TreeNode\n  // children?: React.ReactChild\n}\n\nexport const TreeNodeWidgetComponent =\n  defineComponent({\n    name: 'DnTreeNodeWidget',\n    props: {\n      node: Object as PropType<TreeNode>,\n    },\n    setup(props) {\n      const designerRef = useDesigner(props.node?.designerProps?.effects)\n      const componentsRef = useComponents()\n\n      provide(TreeNodeSymbol, toRef(props, 'node'))\n\n      return () => {\n        const node = props.node!\n\n        // default slot\n        const renderChildren = () => {\n          if (node?.designerProps?.selfRenderChildren) return []\n          return node?.children?.filter(child => {\n            const slot = child.props?.['x-slot']\n            return !slot || slot === 'default'\n          })?.map((child) => {\n            return <TreeNodeWidget {...{ node: child }} key={child.id} />\n          })\n        }\n\n        // 支持 x-slot\n        const renderSlots = () => {\n          if (node?.designerProps?.selfRenderChildren) return []\n          const result = node?.children?.reduce((buffer, child) => {\n            const slot = child.props?.['x-slot']\n            if (slot) {\n              if (!buffer[slot]) buffer[slot] = []\n              buffer[slot].push(<TreeNodeWidget node={child} key={child.id} />)\n            }\n            return buffer\n          }, {} as Record<string, VNode[]>)\n          return Object.entries(result).reduce((buffer, [key, value]) => {\n            buffer[key] = () => value\n            return buffer\n          }, {} as Record<string, () => VNode[]>)\n        }\n        const renderProps = (extendsProps: any = {}) => {\n          const props = {\n            ...node.designerProps?.defaultProps,\n            ...extendsProps,\n            ...node.props,\n            ...node.designerProps?.getComponentProps?.(node),\n          }\n          if (node.depth === 0) {\n            delete props.style\n          }\n          return props\n        }\n\n        const renderComponent = () => {\n          const componentName = node.componentName\n          const Component = componentsRef.value?.[componentName]\n\n          const dataId = {}\n          if (Component) {\n            if (designerRef.value) {\n              dataId[designerRef.value?.props?.nodeIdAttrName] = node.id\n            }\n            const { style, ...attrs } = renderProps(dataId)\n            return (\n              <Component {...attrs} key={node.id} style={style} v-slots={renderSlots()}>\n                {renderChildren()}\n              </Component>\n            )\n          } else {\n            if (node?.children?.length) {\n              return <>{renderChildren()}</>\n            }\n          }\n        }\n        if (!node) return null\n        if (node.hidden) return null\n        return renderComponent()\n      }\n    },\n  })\n\nexport const TreeNodeWidget = observer(TreeNodeWidgetComponent)\n\nexport const ComponentTreeWidgetComponent =\n  observer(\n    defineComponent({\n      name: 'DnComponentTreeWidget',\n      props: { components: [Object] },\n      setup(props) {\n        const treeRef = useTree()\n        const prefixRef = usePrefix('component-tree')\n        const designerRef = useDesigner()\n\n        GlobalRegistry.registerDesignerBehaviors(props.components!)\n        provide(DesignerComponentsSymbol, toRef(props, 'components'))\n\n        return () => {\n          const dataId: Record<string, string> = {}\n          if (designerRef.value && treeRef.value && designerRef.value?.props?.nodeIdAttrName) {\n            dataId[designerRef.value.props.nodeIdAttrName!] = treeRef.value.id\n          }\n          return (\n            <div class={cls(prefixRef.value)} {...dataId}>\n              <TreeNodeWidget {...{ node: treeRef.value }} />\n            </div>\n          )\n        }\n      },\n    })\n  )\n\nexport const ComponentTreeWidget = composeExport(ComponentTreeWidgetComponent, {\n  displayName: 'ComponentTreeWidget',\n})\n"]}