{"id":224,"date":"2026-08-02T09:49:27","date_gmt":"2026-08-02T01:49:27","guid":{"rendered":"https:\/\/yykcj.com\/?p=224"},"modified":"2026-08-02T09:49:27","modified_gmt":"2026-08-02T01:49:27","slug":"%e5%89%8d%e7%ab%af%e4%bd%8e%e4%bb%a3%e7%a0%81%e5%b9%b3%e5%8f%b0%e6%9e%b6%e6%9e%84%e8%ae%be%e8%ae%a1%ef%bc%9a%e4%bb%8e%e9%9b%b6%e6%90%ad%e5%bb%ba%e5%8f%af%e8%a7%86%e5%8c%96%e6%90%ad%e5%bb%ba%e5%bc%95","status":"publish","type":"post","link":"https:\/\/yykcj.com\/?p=224","title":{"rendered":"\u524d\u7aef\u4f4e\u4ee3\u7801\u5e73\u53f0\u67b6\u6784\u8bbe\u8ba1\uff1a\u4ece\u96f6\u642d\u5efa\u53ef\u89c6\u5316\u642d\u5efa\u5f15\u64ce"},"content":{"rendered":"<h1>\u524d\u7aef\u4f4e\u4ee3\u7801\u5e73\u53f0\u67b6\u6784\u8bbe\u8ba1\uff1a\u4ece\u96f6\u642d\u5efa\u53ef\u89c6\u5316\u642d\u5efa\u5f15\u64ce<\/h1>\n<h2>\u5f15\u8a00<\/h2>\n<p>\u4f4e\u4ee3\u7801\u5e73\u53f0\u5df2\u6210\u4e3a\u73b0\u4ee3\u524d\u7aef\u5f00\u53d1\u7684\u70ed\u95e8\u65b9\u5411\uff0c\u5b83\u5141\u8bb8\u5f00\u53d1\u8005\u901a\u8fc7\u62d6\u62fd\u7ec4\u4ef6\u3001\u914d\u7f6e\u5c5e\u6027\u6765\u5feb\u901f\u751f\u6210\u9875\u9762\u3002\u7136\u800c\uff0c\u6784\u5efa\u4e00\u4e2a\u5065\u58ee\u7684\u4f4e\u4ee3\u7801\u5e73\u53f0\u5e76\u975e\u6613\u4e8b\uff0c\u5176\u6838\u5fc3\u5728\u4e8e\u67b6\u6784\u8bbe\u8ba1\u3002\u672c\u6587\u5c06\u5e26\u4f60\u4ece\u96f6\u5f00\u59cb\uff0c\u8bbe\u8ba1\u5e76\u5b9e\u73b0\u4e00\u4e2a\u7b80\u5316\u7248\u7684\u53ef\u89c6\u5316\u642d\u5efa\u5f15\u64ce\uff0c\u91cd\u70b9\u5256\u6790\u5176\u67b6\u6784\u5206\u5c42\u3001\u5173\u952e\u6a21\u5757\u7684\u5b9e\u73b0\uff0c\u4ee5\u53ca\u4e00\u4e9b\u5b9e\u7528\u7684\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<h2>1. \u4f4e\u4ee3\u7801\u5e73\u53f0\u7684\u6574\u4f53\u67b6\u6784<\/h2>\n<p>\u4e00\u4e2a\u5178\u578b\u7684\u524d\u7aef\u4f4e\u4ee3\u7801\u5e73\u53f0\u901a\u5e38\u5206\u4e3a\u4ee5\u4e0b\u51e0\u5c42\uff1a<\/p>\n<ul>\n<li><strong>\u7f16\u8f91\u5668\u5c42<\/strong>\uff1a\u63d0\u4f9b\u53ef\u89c6\u5316\u754c\u9762\uff0c\u5305\u62ec\u7ec4\u4ef6\u9762\u677f\u3001\u753b\u5e03\u3001\u5c5e\u6027\u9762\u677f\u7b49\u3002<\/li>\n<li><strong>\u8bbe\u8ba1\u5f15\u64ce\u5c42<\/strong>\uff1a\u6838\u5fc3\u903b\u8f91\u5c42\uff0c\u7ba1\u7406\u7ec4\u4ef6\u6811\u3001\u72b6\u6001\u3001\u62d6\u62fd\u4ea4\u4e92\u7b49\u3002<\/li>\n<li><strong>\u8fd0\u884c\u65f6\u5c42<\/strong>\uff1a\u8d1f\u8d23\u5c06\u8bbe\u8ba1\u7ed3\u679c\u6e32\u67d3\u6210\u771f\u5b9e\u9875\u9762\uff0c\u5305\u62ec\u7ec4\u4ef6\u52a0\u8f7d\u3001\u6570\u636e\u7ed1\u5b9a\u7b49\u3002<\/li>\n<li><strong>\u4ee3\u7801\u751f\u6210\u5c42<\/strong>\uff1a\u5c06\u8bbe\u8ba1\u7ed3\u679c\u8f6c\u5316\u4e3a\u53ef\u90e8\u7f72\u7684\u4ee3\u7801\uff08\u5982 React\/Vue \u7ec4\u4ef6\uff09\u3002<\/li>\n<\/ul>\n<p>\u672c\u6587\u805a\u7126\u4e8e\u8bbe\u8ba1\u5f15\u64ce\u5c42\uff0c\u56e0\u4e3a\u5b83\u662f\u4f4e\u4ee3\u7801\u5e73\u53f0\u7684\u5fc3\u810f\u3002\u6211\u4eec\u5c06\u7528 React + TypeScript \u5b9e\u73b0\u4e00\u4e2a\u8ff7\u4f60\u7248\u8bbe\u8ba1\u5f15\u64ce\uff0c\u4f46\u6838\u5fc3\u601d\u60f3\u9002\u7528\u4e8e\u4efb\u4f55\u6846\u67b6\u3002<\/p>\n<h2>2. \u67b6\u6784\u8bbe\u8ba1\u539f\u5219<\/h2>\n<p>\u5728\u52a8\u624b\u5199\u4ee3\u7801\u4e4b\u524d\uff0c\u6211\u4eec\u5148\u786e\u7acb\u51e0\u4e2a\u5173\u952e\u539f\u5219\uff1a<\/p>\n<ul>\n<li><strong>\u7ec4\u4ef6\u5316<\/strong>\uff1a\u6240\u6709 UI \u5143\u7d20\uff08\u5305\u62ec\u62d6\u62fd\u624b\u67c4\u3001\u9009\u4e2d\u6846\uff09\u90fd\u4f5c\u4e3a\u7ec4\u4ef6\uff0c\u4fbf\u4e8e\u590d\u7528\u3002<\/li>\n<li><strong>\u5355\u5411\u6570\u636e\u6d41<\/strong>\uff1a\u8bbe\u8ba1\u72b6\u6001\uff08\u5982\u7ec4\u4ef6\u6811\uff09\u7edf\u4e00\u7ba1\u7406\uff0c\u901a\u8fc7\u4e8b\u4ef6\u66f4\u65b0\uff0c\u907f\u514d\u72b6\u6001\u6df7\u4e71\u3002<\/li>\n<li><strong>\u53ef\u6269\u5c55\u6027<\/strong>\uff1a\u901a\u8fc7\u63d2\u4ef6\u673a\u5236\u652f\u6301\u65b0\u7ec4\u4ef6\u3001\u65b0\u4ea4\u4e92\uff0c\u6838\u5fc3\u5f15\u64ce\u4e0d\u4f9d\u8d56\u5177\u4f53\u7ec4\u4ef6\u3002<\/li>\n<li><strong>\u5173\u6ce8\u70b9\u5206\u79bb<\/strong>\uff1a\u8bbe\u8ba1\u5f15\u64ce\u4e0e\u7f16\u8f91\u5668 UI \u5206\u79bb\uff0c\u5f15\u64ce\u53ef\u72ec\u7acb\u6d4b\u8bd5\u3002<\/li>\n<\/ul>\n<h2>3. \u6838\u5fc3\u6a21\u5757\u8bbe\u8ba1\u4e0e\u5b9e\u73b0<\/h2>\n<h3>3.1 \u7ec4\u4ef6\u6811\u7ba1\u7406<\/h3>\n<p>\u7ec4\u4ef6\u6811\u662f\u4f4e\u4ee3\u7801\u5e73\u53f0\u7684\u6570\u636e\u6a21\u578b\uff0c\u901a\u5e38\u662f\u4e00\u68f5\u5d4c\u5957\u7684\u6811\u7ed3\u6784\u3002\u6211\u4eec\u5b9a\u4e49\u5982\u4e0b\u7c7b\u578b\uff1a<\/p>\n<pre><code class=\"language-typescript\">\n\/\/ types.ts\nexport interface ComponentNode {\n  id: string;\n  type: string; \/\/ \u7ec4\u4ef6\u7c7b\u578b\uff0c\u5982 &#x27;button&#x27;, &#x27;div&#x27;\n  props: Record&lt;string, any&gt;;\n  children: ComponentNode[];\n}\n<\/code><\/pre>\n<p>\u7ba1\u7406\u7ec4\u4ef6\u6811\u7684\u72b6\u6001\uff0c\u6211\u4eec\u4f7f\u7528 React \u7684 useReducer\uff0c\u4fbf\u4e8e\u8ffd\u8e2a\u53d8\u66f4\uff1a<\/p>\n<pre><code class=\"language-tsx\">\n\/\/ store.tsx\nimport React, { createContext, useContext, useReducer } from &#x27;react&#x27;;\nimport { ComponentNode } from &#x27;.\/types&#x27;;\n\ntype Action =\n  | { type: &#x27;ADD_NODE&#x27;; parentId: string | null; node: ComponentNode }\n  | { type: &#x27;REMOVE_NODE&#x27;; id: string }\n  | { type: &#x27;UPDATE_PROPS&#x27;; id: string; props: Record&lt;string, any&gt; };\n\nconst initialState: { tree: ComponentNode[] } = { tree: [] };\n\nfunction reducer(state: typeof initialState, action: Action) {\n  switch (action.type) {\n    case &#x27;ADD_NODE&#x27;: {\n      const newNode = { ...action.node };\n      if (action.parentId === null) {\n        return { tree: [...state.tree, newNode] };\n      }\n      \/\/ \u9012\u5f52\u6dfb\u52a0\u5b50\u8282\u70b9\n      const updateTree = (nodes: ComponentNode[]): ComponentNode[] =&gt; {\n        return nodes.map(node =&gt; {\n          if (node.id === action.parentId) {\n            return { ...node, children: [...node.children, newNode] };\n          }\n          if (node.children.length) {\n            return { ...node, children: updateTree(node.children) };\n          }\n          return node;\n        });\n      };\n      return { tree: updateTree(state.tree) };\n    }\n    \/\/ \u5176\u4ed6 action \u7c7b\u4f3c\uff0c\u7701\u7565\n    default:\n      return state;\n  }\n}\n\nconst StoreContext = createContext&lt;{ state: typeof initialState; dispatch: React.Dispatch&lt;Action&gt; } | null&gt;(null);\n\nexport const StoreProvider = ({ children }: { children: React.ReactNode }) =&gt; {\n  const [state, dispatch] = useReducer(reducer, initialState);\n  return &lt;StoreContext.Provider value={{ state, dispatch }}&gt;{children}&lt;\/StoreContext.Provider&gt;;\n};\n\nexport const useStore = () =&gt; {\n  const context = useContext(StoreContext);\n  if (!context) throw new Error(&#x27;useStore must be used within StoreProvider&#x27;);\n  return context;\n};\n<\/code><\/pre>\n<h3>3.2 \u62d6\u62fd\u4ea4\u4e92\u5b9e\u73b0<\/h3>\n<p>\u62d6\u62fd\u662f\u4f4e\u4ee3\u7801\u5e73\u53f0\u6700\u6838\u5fc3\u7684\u4ea4\u4e92\u3002\u6211\u4eec\u4f7f\u7528 HTML5 \u62d6\u653e API \u5b9e\u73b0\u4e00\u4e2a\u53ef\u590d\u7528\u7684\u62d6\u62fd\u7cfb\u7edf\u3002\u9996\u5148\uff0c\u5b9a\u4e49\u53ef\u62d6\u62fd\u7ec4\u4ef6\u5305\u88c5\u5668\uff1a<\/p>\n<pre><code class=\"language-tsx\">\n\/\/ Draggable.tsx\nimport React from &#x27;react&#x27;;\n\nexport const Draggable = ({ id, type, children, onDrop }: {\n  id: string;\n  type: string;\n  children: React.ReactNode;\n  onDrop: (e: React.DragEvent) =&gt; void;\n}) =&gt; {\n  const handleDragStart = (e: React.DragEvent) =&gt; {\n    e.dataTransfer.setData(&#x27;text\/plain&#x27;, JSON.stringify({ id, type }));\n    e.dataTransfer.effectAllowed = &#x27;move&#x27;;\n  };\n\n  return (\n    &lt;div\n      draggable\n      onDragStart={handleDragStart}\n      onDragOver={(e) =&gt; e.preventDefault()}\n      onDrop={onDrop}\n      style={{ padding: &#x27;8px&#x27;, border: &#x27;1px dashed #ccc&#x27; }}\n    &gt;\n      {children}\n    &lt;\/div&gt;\n  );\n};\n<\/code><\/pre>\n<p>\u5728\u753b\u5e03\u533a\u57df\uff0c\u6211\u4eec\u76d1\u542c drop \u4e8b\u4ef6\u6765\u6dfb\u52a0\u7ec4\u4ef6\uff1a<\/p>\n<pre><code class=\"language-tsx\">\n\/\/ Canvas.tsx\nimport React from &#x27;react&#x27;;\nimport { useStore } from &#x27;.\/store&#x27;;\nimport { Draggable } from &#x27;.\/Draggable&#x27;;\nimport { ComponentNode } from &#x27;.\/types&#x27;;\n\nexport const Canvas = () =&gt; {\n  const { state, dispatch } = useStore();\n\n  const handleDrop = (e: React.DragEvent, parentId: string | null) =&gt; {\n    e.preventDefault();\n    const data = JSON.parse(e.dataTransfer.getData(&#x27;text\/plain&#x27;));\n    const newNode: ComponentNode = {\n      id: `node_${Date.now()}`,\n      type: data.type,\n      props: {},\n      children: [],\n    };\n    dispatch({ type: &#x27;ADD_NODE&#x27;, parentId, node: newNode });\n  };\n\n  const renderNode = (node: ComponentNode) =&gt; {\n    return (\n      &lt;Draggable\n        key={node.id}\n        id={node.id}\n        type={node.type}\n        onDrop={(e) =&gt; handleDrop(e, node.id)}\n      &gt;\n        &lt;div&gt;{node.type}&lt;\/div&gt;\n        {node.children.map(child =&gt; renderNode(child))}\n      &lt;\/Draggable&gt;\n    );\n  };\n\n  return (\n    &lt;div\n      style={{ flex: 1, padding: &#x27;20px&#x27;, overflow: &#x27;auto&#x27; }}\n      onDragOver={(e) =&gt; e.preventDefault()}\n      onDrop={(e) =&gt; handleDrop(e, null)}\n    &gt;\n      {state.tree.map(node =&gt; renderNode(node))}\n    &lt;\/div&gt;\n  );\n};\n<\/code><\/pre>\n<p><strong>\u6ce8\u610f<\/strong>\uff1aHTML5 \u62d6\u653e API \u5728\u79fb\u52a8\u7aef\u652f\u6301\u4e0d\u4f73\uff0c\u751f\u4ea7\u73af\u5883\u5efa\u8bae\u4f7f\u7528 Pointer Events \u6216\u7b2c\u4e09\u65b9\u5e93\u5982 react-dnd\u3002\u4f46\u8fd9\u91cc\u4e3a\u4e86\u6559\u5b66\u7b80\u5355\uff0c\u6211\u4eec\u4f7f\u7528\u539f\u751f API\u3002<\/p>\n<h3>3.3 \u5c5e\u6027\u9762\u677f\u52a8\u6001\u751f\u6210<\/h3>\n<p>\u5c5e\u6027\u9762\u677f\u9700\u8981\u6839\u636e\u9009\u4e2d\u7ec4\u4ef6\u7684\u7c7b\u578b\u52a8\u6001\u6e32\u67d3\u8868\u5355\u3002\u6211\u4eec\u901a\u8fc7\u4e00\u4e2a\u7ec4\u4ef6\u6ce8\u518c\u8868\u6765\u6620\u5c04\u7ec4\u4ef6\u7c7b\u578b\u4e0e\u5c5e\u6027\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"language-typescript\">\n\/\/ componentRegistry.ts\nexport interface ComponentConfig {\n  type: string;\n  displayName: string;\n  propsSchema: Array&lt;{ name: string; label: string; type: &#x27;string&#x27; | &#x27;number&#x27; | &#x27;boolean&#x27; }&gt;;\n}\n\nexport const componentRegistry: Record&lt;string, ComponentConfig&gt; = {\n  button: {\n    type: &#x27;button&#x27;,\n    displayName: &#x27;\u6309\u94ae&#x27;,\n    propsSchema: [\n      { name: &#x27;text&#x27;, label: &#x27;\u6587\u672c&#x27;, type: &#x27;string&#x27; },\n      { name: &#x27;size&#x27;, label: &#x27;\u5c3a\u5bf8&#x27;, type: &#x27;string&#x27; },\n    ],\n  },\n  div: {\n    type: &#x27;div&#x27;,\n    displayName: &#x27;\u5bb9\u5668&#x27;,\n    propsSchema: [],\n  },\n};\n<\/code><\/pre>\n<p>\u5c5e\u6027\u9762\u677f\u7ec4\u4ef6\u6839\u636e schema \u751f\u6210\u8868\u5355\uff1a<\/p>\n<pre><code class=\"language-tsx\">\n\/\/ PropertyPanel.tsx\nimport React from &#x27;react&#x27;;\nimport { componentRegistry } from &#x27;.\/componentRegistry&#x27;;\nimport { useStore } from &#x27;.\/store&#x27;;\n\nexport const PropertyPanel = ({ selectedId }: { selectedId: string | null }) =&gt; {\n  const { state, dispatch } = useStore();\n  if (!selectedId) return &lt;div&gt;\u672a\u9009\u4e2d\u7ec4\u4ef6&lt;\/div&gt;;\n\n  \/\/ \u67e5\u627e\u9009\u4e2d\u8282\u70b9\uff08\u7b80\u5316\uff0c\u5b9e\u9645\u9700\u904d\u5386\u6811\uff09\n  const findNode = (nodes: ComponentNode[], id: string): ComponentNode | null =&gt; {\n    for (const node of nodes) {\n      if (node.id === id) return node;\n      if (node.children.length) {\n        const found = findNode(node.children, id);\n        if (found) return found;\n      }\n    }\n    return null;\n  };\n  const node = findNode(state.tree, selectedId);\n  if (!node) return null;\n\n  const config = componentRegistry[node.type];\n  if (!config) return &lt;div&gt;\u672a\u77e5\u7ec4\u4ef6\u7c7b\u578b&lt;\/div&gt;;\n\n  const handleChange = (name: string, value: any) =&gt; {\n    dispatch({ type: &#x27;UPDATE_PROPS&#x27;, id: node.id, props: { ...node.props, [name]: value } });\n  };\n\n  return (\n    &lt;div style={{ width: &#x27;300px&#x27;, padding: &#x27;16px&#x27; }}&gt;\n      &lt;h3&gt;{config.displayName} \u5c5e\u6027&lt;\/h3&gt;\n      {config.propsSchema.map(field =&gt; (\n        &lt;div key={field.name}&gt;\n          &lt;label&gt;{field.label}&lt;\/label&gt;\n          &lt;input\n            type={field.type === &#x27;number&#x27; ? &#x27;number&#x27; : &#x27;text&#x27;}\n            value={node.props[field.name] || &#x27;&#x27;}\n            onChange={(e) =&gt; handleChange(field.name, e.target.value)}\n          \/&gt;\n        &lt;\/div&gt;\n      ))}\n    &lt;\/div&gt;\n  );\n};\n<\/code><\/pre>\n<h3>3.4 \u4ee3\u7801\u751f\u6210\u4e0e\u9884\u89c8<\/h3>\n<p>\u5c06\u7ec4\u4ef6\u6811\u8f6c\u6362\u4e3a React \u4ee3\u7801\uff0c\u6211\u4eec\u91c7\u7528\u9012\u5f52\u751f\u6210 JSX \u5b57\u7b26\u4e32\uff1a<\/p>\n<pre><code class=\"language-typescript\">\n\/\/ codegen.ts\nimport { ComponentNode } from &#x27;.\/types&#x27;;\n\nexport function generateCode(nodes: ComponentNode[]): string {\n  return nodes.map(node =&gt; generateNode(node)).join(&#x27;\\n&#x27;);\n}\n\nfunction generateNode(node: ComponentNode): string {\n  const propsStr = Object.entries(node.props)\n    .map(([key, value]) =&gt; `${key}=&quot;${value}&quot;`)\n    .join(&#x27; &#x27;);\n  const childrenStr = node.children.length ? `\\n${generateCode(node.children)}\\n` : &#x27;&#x27;;\n  return `&lt;${node.type} ${propsStr}&gt;${childrenStr}&lt;\/${node.type}&gt;`;\n}\n<\/code><\/pre>\n<p>\u9884\u89c8\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 <code>react-dom<\/code> \u7684 <code>render<\/code> \u65b9\u6cd5\u52a8\u6001\u6e32\u67d3\u751f\u6210\u7684\u7ec4\u4ef6\u6811\u3002\u4e3a\u4e86\u7b80\u5316\uff0c\u6211\u4eec\u76f4\u63a5\u6e32\u67d3 JSON \u6811\uff1a<\/p>\n<pre><code class=\"language-tsx\">\n\/\/ Preview.tsx\nimport React from &#x27;react&#x27;;\nimport { useStore } from &#x27;.\/store&#x27;;\nimport { componentRegistry } from &#x27;.\/componentRegistry&#x27;;\n\nexport const Preview = () =&gt; {\n  const { state } = useStore();\n\n  const renderNode = (node: ComponentNode): React.ReactNode =&gt; {\n    const config = componentRegistry[node.type];\n    if (!config) return null;\n    \/\/ \u6839\u636e\u7c7b\u578b\u8fd4\u56de\u5b9e\u9645\u7ec4\u4ef6\uff0c\u8fd9\u91cc\u7b80\u5316\uff0c\u5b9e\u9645\u5e94\u6620\u5c04\u5230\u771f\u5b9e\u7ec4\u4ef6\n    const props = { ...node.props, key: node.id };\n    if (node.type === &#x27;button&#x27;) {\n      return &lt;button {...props}&gt;{node.props.text}&lt;\/button&gt;;\n    }\n    if (node.type === &#x27;div&#x27;) {\n      return &lt;div {...props}&gt;{node.children.map(child =&gt; renderNode(child))}&lt;\/div&gt;;\n    }\n    return null;\n  };\n\n  return (\n    &lt;div style={{ flex: 1, padding: &#x27;20px&#x27; }}&gt;\n      {state.tree.map(node =&gt; renderNode(node))}\n    &lt;\/div&gt;\n  );\n};\n<\/code><\/pre>\n<h2>4. \u96c6\u6210\u4e0e\u6d4b\u8bd5<\/h2>\n<p>\u6700\u540e\uff0c\u6211\u4eec\u5c06\u8fd9\u4e9b\u6a21\u5757\u7ec4\u5408\u6210\u4e00\u4e2a\u5b8c\u6574\u7684\u7f16\u8f91\u5668\u9875\u9762\uff1a<\/p>\n<pre><code class=\"language-tsx\">\n\/\/ App.tsx\nimport React, { useState } from &#x27;react&#x27;;\nimport { StoreProvider } from &#x27;.\/store&#x27;;\nimport { Canvas } from &#x27;.\/Canvas&#x27;;\nimport { PropertyPanel } from &#x27;.\/PropertyPanel&#x27;;\nimport { Preview } from &#x27;.\/Preview&#x27;;\n\nexport default function App() {\n  const [selectedId, setSelectedId] = useState&lt;string | null&gt;(null);\n\n  return (\n    &lt;StoreProvider&gt;\n      &lt;div style={{ display: &#x27;flex&#x27;, height: &#x27;100vh&#x27; }}&gt;\n        &lt;div style={{ width: &#x27;200px&#x27;, padding: &#x27;16px&#x27; }}&gt;\n          {\/* \u7ec4\u4ef6\u9762\u677f\uff1a\u62d6\u62fd\u6dfb\u52a0 *\/}\n          &lt;div draggable onDragStart={(e) =&gt; e.dataTransfer.setData(&#x27;text\/plain&#x27;, JSON.stringify({ type: &#x27;button&#x27; }))}&gt;\n            \u6309\u94ae\n          &lt;\/div&gt;\n          &lt;div draggable onDragStart={(e) =&gt; e.dataTransfer.setData(&#x27;text\/plain&#x27;, JSON.stringify({ type: &#x27;div&#x27; }))}&gt;\n            \u5bb9\u5668\n          &lt;\/div&gt;\n        &lt;\/div&gt;\n        &lt;Canvas \/&gt;\n        &lt;PropertyPanel selectedId={selectedId} \/&gt;\n        &lt;Preview \/&gt;\n      &lt;\/div&gt;\n    &lt;\/StoreProvider&gt;\n  );\n}\n<\/code><\/pre>\n<h2>5. \u8e29\u5751\u4e0e\u6700\u4f73\u5b9e\u8df5<\/h2>\n<ul>\n<li><strong>\u72b6\u6001\u7ba1\u7406<\/strong>\uff1a\u4e00\u5b9a\u8981\u4f7f\u7528\u4e0d\u53ef\u53d8\u6570\u636e\uff0c\u65b9\u4fbf\u64a4\u9500\/\u91cd\u505a\u3002<\/li>\n<li><strong>\u6027\u80fd\u4f18\u5316<\/strong>\uff1a\u5927\u7ec4\u4ef6\u6811\u65f6\uff0c\u62d6\u62fd\u4f1a\u9891\u7e41\u89e6\u53d1\u6e32\u67d3\uff0c\u53ef\u4f7f\u7528 <code>React.memo<\/code> \u548c <code>useCallback<\/code> \u4f18\u5316\u3002<\/li>\n<li><strong>\u6269\u5c55\u6027<\/strong>\uff1a\u901a\u8fc7\u6ce8\u518c\u8868\u6a21\u5f0f\u6dfb\u52a0\u65b0\u7ec4\u4ef6\uff0c\u907f\u514d\u4fee\u6539\u6838\u5fc3\u5f15\u64ce\u3002<\/li>\n<li><strong>\u4ee3\u7801\u751f\u6210<\/strong>\uff1a\u751f\u6210\u4ee3\u7801\u540e\uff0c\u53ef\u4f7f\u7528 Babel \u89e3\u6790\u4e3a AST \u518d\u751f\u6210\u53ef\u6267\u884c\u4ee3\u7801\uff0c\u4f46\u76f4\u63a5\u751f\u6210\u5b57\u7b26\u4e32\u7b80\u5355\u4e14\u8db3\u591f\u3002<\/li>\n<\/ul>\n<h2>6. \u603b\u7ed3\u4e0e\u5c55\u671b<\/h2>\n<p>\u672c\u6587\u5b9e\u73b0\u4e86\u4e00\u4e2a\u7b80\u5355\u7684\u4f4e\u4ee3\u7801\u642d\u5efa\u5f15\u64ce\uff0c\u6db5\u76d6\u4e86\u6838\u5fc3\u67b6\u6784\u3002\u5b9e\u9645\u751f\u4ea7\u7ea7\u5e73\u53f0\u8fd8\u9700\u8981\u8003\u8651\uff1a\u64a4\u9500\/\u91cd\u505a\u3001\u5feb\u6377\u952e\u3001\u591a\u9009\u3001\u5d4c\u5957\u7ea6\u675f\u3001\u6570\u636e\u7ed1\u5b9a\u3001\u8fdc\u7a0b\u7ec4\u4ef6\u52a0\u8f7d\u7b49\u3002\u5efa\u8bae\u8fdb\u4e00\u6b65\u7814\u7a76\u5f00\u6e90\u9879\u76ee\u5982 <code>react-page<\/code>\u3001<code>puck<\/code> \u7b49\uff0c\u6df1\u5165\u7406\u89e3\u5176\u67b6\u6784\u3002<\/p>\n<p>\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u4e3a\u4f60\u6784\u5efa\u81ea\u5df1\u7684\u4f4e\u4ee3\u7801\u5e73\u53f0\u63d0\u4f9b\u542f\u53d1\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u6df1\u5165\u63a2\u8ba8\u524d\u7aef\u4f4e\u4ee3\u7801\u5e73\u53f0\u7684\u6838\u5fc3\u67b6\u6784\uff0c\u4ece\u8bbe\u8ba1\u539f\u5219\u5230\u5177\u4f53\u5b9e\u73b0\uff0c\u624b\u628a\u624b\u6559\u4f60\u642d\u5efa\u4e00\u4e2a\u53ef\u6269\u5c55\u7684\u53ef\u89c6\u5316\u642d\u5efa\u5f15\u64ce\u3002\u6db5\u76d6\u7ec4\u4ef6\u6811\u7ba1\u7406\u3001\u62d6\u62fd\u4ea4\u4e92\u3001\u5c5e\u6027\u9762\u677f\u751f\u6210\u3001\u4ee3\u7801\u751f\u6210\u4e0e\u9884\u89c8\u7b49\u5173\u952e\u6a21\u5757\uff0c\u5e76\u63d0\u4f9b\u5b8c\u6574\u53ef\u8fd0\u884c\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,4],"tags":[11,170,171,172,173],"class_list":["post-224","post","type-post","status-publish","format-standard","hentry","category-3","category-4","tag-react","tag-170","tag-171","tag-172","tag-173"],"_links":{"self":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=224"}],"version-history":[{"count":0,"href":"https:\/\/yykcj.com\/index.php?rest_route=\/wp\/v2\/posts\/224\/revisions"}],"wp:attachment":[{"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/yykcj.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}