Summary: Bumps [antd](https://github.com/ant-design/ant-design) from 4.16.8 to 4.18.0. <details> <summary>Release notes</summary> <p><em>Sourced from <a href="https://github.com/ant-design/ant-design/releases">antd's releases</a>.</em></p> <blockquote> <h2>4.18.0</h2> <ul> <li>🐞 Fix Skeleton missing <code>style</code> prop. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33405">#33405</a></li> <li>🐞 Fix Descriptions overflow style cause other components being cut. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33392">#33392</a></li> <li>🆕 Unique Select-like component generic as OptionType to support FieldNames type. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33364">#33364</a></li> <li>🐞 Fix Slider rail hover color when it is disabled. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33369">#33369</a> <a href="https://github.com/chen-jingjie"><code>@chen-jingjie</code></a></li> <li>Table <ul> <li>🆕 Table <code>colSpan</code> & <code>rowSpan</code> move to <code>onCell</code> function to optimize performance. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33114">#33114</a></li> <li>🆕 Table support Table.EXPAND_COLUMN & Table.SELECTION_COLUMN to customize column order. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33026">#33026</a></li> </ul> </li> <li>Form <ul> <li>🔥 Form.List nest Form.Item no longer need pass <code>fieldKey</code> anymore. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32689">#32689</a></li> <li>🆕 Form <code>label</code> can wrap via setting <code>labelWrap</code> now. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33048">#33048</a></li> </ul> </li> <li>🆕 ConfigProvider support Form <code>colon</code>. <a href="https://github.com/ant-design/ant-design/commit/9bc148a">9bc148a</a> <a href="https://github.com/seaSuper"><code>@seaSuper</code></a></li> <li>🆕 add <code>prefix</code> to <code>InputNumber</code>. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32600">#32600</a> <a href="https://github.com/Austaras"><code>@Austaras</code></a></li> <li>🆕 Modal static function support <code>wrapClassName</code> prop. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32676">#32676</a> <a href="https://github.com/cwjTerrace"><code>@cwjTerrace</code></a></li> <li>🆕 Popconfirm add <code>showCancel</code> prop. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32620">#32620</a> <a href="https://github.com/cwjTerrace"><code>@cwjTerrace</code></a></li> <li>🆕 Dropdown.Button supports <code>loading</code> property now. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32467">#32467</a> <a href="https://github.com/kaysonwu"><code>@kaysonwu</code></a></li> <li>🆕 Input adds <code>showCount</code> property. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32522">#32522</a> <a href="https://github.com/cwjTerrace"><code>@cwjTerrace</code></a></li> <li>🆕 Alert supports <code>closeIcon</code> now. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32345">#32345</a> <a href="https://github.com/chen-jingjie"><code>@chen-jingjie</code></a></li> <li>Typography <ul> <li>🆕 for editable Paragraph, edit can be triggered by clicking the icon or the value itself (or both) with <code>triggerType</code>. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32219">#32219</a> <a href="https://github.com/kachanovskiy"><code>@kachanovskiy</code></a></li> <li>🆕 Typography support <code>enterIcon</code> to config confirm icon. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32220">#32220</a> <a href="https://github.com/kachanovskiy"><code>@kachanovskiy</code></a></li> </ul> </li> <li>🆕 Divider added <code>orientationMargin</code> APIs for customizing <code>margin-left/right</code> of title. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32084">#32084</a> <a href="https://github.com/neotan"><code>@neotan</code></a></li> <li>🆕 Avatar add <code>maxPopoverTrigger</code> to support configuration of popover trigger. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32197">#32197</a> <a href="https://github.com/RiteshMakan"><code>@RiteshMakan</code></a></li> <li>🆕 Upload supports <code>showUploadList.previewIcon</code> now. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32059">#32059</a> <a href="https://github.com/1040961807"><code>@1040961807</code></a></li> <li>🏴 Fix Catalan (ca_ES) missing translation key with <code>Form</code>. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33377">#33377</a> <a href="https://github.com/ZzGGitter"><code>@ZzGGitter</code></a></li> <li>🇫🇮 Fix Finland (fi_FI) missing translation key with <code>Table</code>. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33372">#33372</a> <a href="https://github.com/ZakarFin"><code>@ZakarFin</code></a></li> <li>🇰🇭 Added locales for Khmer (km_KH) translation. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32853">#32853</a> <a href="https://github.com/vireakkeosokvibol"><code>@vireakkeosokvibol</code></a></li> <li>TypeScript <ul> <li>� Add Upload <code>capture</code> definition. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33370">#33370</a> <a href="https://github.com/MichalPodeszwa"><code>@MichalPodeszwa</code></a></li> </ul> </li> </ul> <hr /> <ul> <li>🐞 修复 Skeleton 不支持 <code>style</code> 的问题。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33405">#33405</a></li> <li>🐞 修复 Descriptions 内使用其他组件会被切割的问题。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33392">#33392</a></li> <li>🆕 统一类 Select 组件泛型定义为 OptionType 以支持自定义 FieldNames 匹配。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33364">#33364</a></li> <li>🐞 修复 Slider 禁用时 <code>hover</code> 色彩的问题。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33369">#33369</a> <a href="https://github.com/chen-jingjie"><code>@chen-jingjie</code></a></li> <li>Table <ul> <li>🆕 Table <code>colSpan</code> 与 <code>rowSpan</code> 迁移至 <code>onCell</code> 方法中,以优化渲染性能。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33114">#33114</a></li> <li>🆕 Table 支持 Table.EXPAND_COLUMN 和 Table.SELECTION_COLUMN 以实现自定义列排序。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33026">#33026</a></li> </ul> </li> <li>Form <ul> <li>🔥 Form.List 嵌套使用 Form.Item 时不再需要手工指定 <code>fieldKey</code>。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32689">#32689</a></li> <li>🆕 Form 现在支持通过 <code>labelWrap</code> 开启标签可换行。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33048">#33048</a></li> </ul> </li> <li>🆕 ConfigProvider 支持 Form 的 colon 配置。<a href="https://github.com/ant-design/ant-design/commit/9bc148a">9bc148a</a> <a href="https://github.com/seaSuper"><code>@seaSuper</code></a></li> <li>🆕 <code>InputNumber</code> 增加 <code>prefix</code> 属性支持。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32600">#32600</a> <a href="https://github.com/Austaras"><code>@Austaras</code></a></li> <li>🆕 Modal 静态方法支持 <code>wrapClassName</code> 属性。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32676">#32676</a> <a href="https://github.com/cwjTerrace"><code>@cwjTerrace</code></a></li> <li>🆕 Popconfirm 新增是否显示取消按钮。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32620">#32620</a> <a href="https://github.com/cwjTerrace"><code>@cwjTerrace</code></a></li> <li>🆕 Dropdown.Button 新增 <code>loading</code> 属性。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32467">#32467</a> <a href="https://github.com/kaysonwu"><code>@kaysonwu</code></a></li> <li>🆕 Input 新增 <code>showCount</code> 属性。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32522">#32522</a> <a href="https://github.com/cwjTerrace"><code>@cwjTerrace</code></a></li> <li>🆕 Alert 支持 <code>closeIcon</code> 自定义关闭图标。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32345">#32345</a> <a href="https://github.com/chen-jingjie"><code>@chen-jingjie</code></a></li> <li>Typography <ul> <li>🆕 对于可编辑段落,可以通过配置 <code>triggerType</code> 配置触发编辑状态。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32219">#32219</a> <a href="https://github.com/kachanovskiy"><code>@kachanovskiy</code></a></li> <li>🆕 Typography 支持 <code>enterIcon</code> 以设置编辑确认图标。<a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32220">#32220</a> <a href="https://github.com/kachanovskiy"><code>@kachanovskiy</code></a></li> </ul> </li> </ul> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/ant-design/ant-design/blob/master/CHANGELOG.en-US.md">antd's changelog</a>.</em></p> <blockquote> <h2>4.18.0</h2> <p><code>2021-12-27</code></p> <ul> <li>🐞 Fix Skeleton missing <code>style</code> prop. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33405">#33405</a></li> <li>🐞 Fix Descriptions overflow style cause other components being cut. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33392">#33392</a></li> <li>🆕 Unique Select-like component generic as OptionType to support FieldNames type. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33364">#33364</a></li> <li>🐞 Fix Slider rail hover color when it is disabled. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33369">#33369</a> <a href="https://github.com/chen-jingjie"><code>@chen-jingjie</code></a></li> <li>Table <ul> <li>🆕 Table <code>colSpan</code> & <code>rowSpan</code> move to <code>onCell</code> function to optimize performance. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33114">#33114</a></li> <li>🆕 Table support Table.EXPAND_COLUMN & Table.SELECTION_COLUMN to customize column order. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33026">#33026</a></li> </ul> </li> <li>Form <ul> <li>🔥 Form.List nest Form.Item no longer need pass <code>fieldKey</code> anymore. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32689">#32689</a></li> <li>🆕 Form <code>label</code> can wrap via setting <code>labelWrap</code> now. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33048">#33048</a></li> </ul> </li> <li>🆕 ConfigProvider support Form <code>colon</code>. <a href="https://github.com/ant-design/ant-design/commit/9bc148a">9bc148a</a> <a href="https://github.com/seaSuper"><code>@seaSuper</code></a></li> <li>🆕 add <code>prefix</code> to <code>InputNumber</code>. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32600">#32600</a> <a href="https://github.com/Austaras"><code>@Austaras</code></a></li> <li>🆕 Modal static function support <code>wrapClassName</code> prop. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32676">#32676</a> <a href="https://github.com/cwjTerrace"><code>@cwjTerrace</code></a></li> <li>🆕 Popconfirm add <code>showCancel</code> prop. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32620">#32620</a> <a href="https://github.com/cwjTerrace"><code>@cwjTerrace</code></a></li> <li>🆕 Dropdown.Button supports <code>loading</code> property now. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32467">#32467</a> <a href="https://github.com/kaysonwu"><code>@kaysonwu</code></a></li> <li>🆕 Input adds <code>showCount</code> property. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32522">#32522</a> <a href="https://github.com/cwjTerrace"><code>@cwjTerrace</code></a></li> <li>🆕 Alert supports <code>closeIcon</code> now. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32345">#32345</a> <a href="https://github.com/chen-jingjie"><code>@chen-jingjie</code></a></li> <li>Typography <ul> <li>🆕 for editable Paragraph, edit can be triggered by clicking the icon or the value itself (or both) with <code>triggerType</code>. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32219">#32219</a> <a href="https://github.com/kachanovskiy"><code>@kachanovskiy</code></a></li> <li>🆕 Typography support <code>enterIcon</code> to config confirm icon. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32220">#32220</a> <a href="https://github.com/kachanovskiy"><code>@kachanovskiy</code></a></li> </ul> </li> <li>🆕 Divider added <code>orientationMargin</code> APIs for customizing <code>margin-left/right</code> of title. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32084">#32084</a> <a href="https://github.com/neotan"><code>@neotan</code></a></li> <li>🆕 Avatar add <code>maxPopoverTrigger</code> to support configuration of popover trigger. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32197">#32197</a> <a href="https://github.com/RiteshMakan"><code>@RiteshMakan</code></a></li> <li>🆕 Upload supports <code>showUploadList.previewIcon</code> now. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32059">#32059</a> <a href="https://github.com/1040961807"><code>@1040961807</code></a></li> <li>🏴 Fix Catalan (ca_ES) missing translation key with <code>Form</code>. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33377">#33377</a> <a href="https://github.com/ZzGGitter"><code>@ZzGGitter</code></a></li> <li>🇫🇮 Fix Finland (fi_FI) missing translation key with <code>Table</code>. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33372">#33372</a> <a href="https://github.com/ZakarFin"><code>@ZakarFin</code></a></li> <li>🇰🇭 Added locales for Khmer (km_KH) translation. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32853">#32853</a> <a href="https://github.com/vireakkeosokvibol"><code>@vireakkeosokvibol</code></a></li> <li>TypeScript <ul> <li>� Add Upload <code>capture</code> definition. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33370">#33370</a> <a href="https://github.com/MichalPodeszwa"><code>@MichalPodeszwa</code></a></li> </ul> </li> </ul> <h2>4.17.4</h2> <p><code>2021-12-19</code></p> <ul> <li>🐞 Fix a bug that Form.Item name is "parentNode" casue endless loop and memory leak. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/31846">#31846</a> <a href="https://github.com/DaoxingHuang"><code>@DaoxingHuang</code></a></li> <li>🐞 Revert <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32448">#32448</a> to fix emoji input at Input.TextArea. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33312">#33312</a></li> </ul> <h2>4.17.3</h2> <p><code>2021-12-08</code></p> <ul> <li>🐞 Fix Drawer broken style caused by title width. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33205">#33205</a></li> <li>🐞 Fix Badge flash style when switch from <code>display:none</code>. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33083">#33083</a> <a href="https://github.com/songlinn"><code>@songlinn</code></a></li> <li>💄 Change Anchor className form <code>.fixed</code> to <code>.ant-anchor-fixed</code>. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33085">#33085</a> <a href="https://github.com/tangjinzhou"><code>@tangjinzhou</code></a></li> <li>💄 Fix Button loading style missing in Firefox. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/33199">#33199</a></li> <li>Select <ul> <li>🐞 Fix Select width became small when searching. <a href="https://github-redirect.dependabot.com/ant-design/ant-design/pull/32988">#32988</a></li> </ul> </li> </ul> </blockquote> <p>... (truncated)</p> </details> <details> <summary>Commits</summary> <ul> <li><a href="41ac1f0c1a"><code>41ac1f0</code></a> chore: 4.18.0 changelog (<a href="https://github-redirect.dependabot.com/ant-design/ant-design/issues/33424">#33424</a>)</li> <li><a href="24458eb54e"><code>24458eb</code></a> chore: auto merge branchs (<a href="https://github-redirect.dependabot.com/ant-design/ant-design/issues/33423">#33423</a>)</li> <li><a href="b3cc1e5276"><code>b3cc1e5</code></a> chore: auto merge branchs (<a href="https://github-redirect.dependabot.com/ant-design/ant-design/issues/33422">#33422</a>)</li> <li><a href="7ae451729f"><code>7ae4517</code></a> test: update snapshot</li> <li><a href="6ed4d855b1"><code>6ed4d85</code></a> Merge remote-tracking branch 'origin/master' into feature-merge-master</li> <li><a href="73ac1b1aaa"><code>73ac1b1</code></a> docs: Update practical-projects.zh-CN.md (<a href="https://github-redirect.dependabot.com/ant-design/ant-design/issues/33419">#33419</a>)</li> <li><a href="7f09f0a604"><code>7f09f0a</code></a> chore(deps): update dependency scrollama to v3 (<a href="https://github-redirect.dependabot.com/ant-design/ant-design/issues/33418">#33418</a>)</li> <li><a href="9c086c5328"><code>9c086c5</code></a> fix: Skeleton missing style (<a href="https://github-redirect.dependabot.com/ant-design/ant-design/issues/33405">#33405</a>)</li> <li><a href="f1e0c9c1d2"><code>f1e0c9c</code></a> chore: Internal Menu interface for ProLayout usage (<a href="https://github-redirect.dependabot.com/ant-design/ant-design/issues/33399">#33399</a>)</li> <li><a href="0edf04253e"><code>0edf042</code></a> fix: Descriptions default overflow value (<a href="https://github-redirect.dependabot.com/ant-design/ant-design/issues/33392">#33392</a>)</li> <li>Additional commits viewable in <a href="https://github.com/ant-design/ant-design/compare/4.16.8...4.18.0">compare view</a></li> </ul> </details> <br /> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `dependabot rebase` will rebase this PR - `dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `dependabot merge` will merge this PR after your CI passes on it - `dependabot squash and merge` will squash and merge this PR after your CI passes on it - `dependabot cancel merge` will cancel a previously requested merge and block automerging - `dependabot reopen` will reopen this PR if it is closed - `dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Pull Request resolved: https://github.com/facebook/flipper/pull/3222 Reviewed By: timur-valiev Differential Revision: D33348265 Pulled By: nikoant fbshipit-source-id: e219049791c8341b4795fc8b742edaa61ee7559d
465 lines
14 KiB
TypeScript
465 lines
14 KiB
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import type ReactDevToolsStandaloneType from 'react-devtools-core/standalone';
|
|
import {
|
|
Layout,
|
|
usePlugin,
|
|
DevicePluginClient,
|
|
createState,
|
|
useValue,
|
|
sleep,
|
|
Toolbar,
|
|
path,
|
|
getFlipperLib,
|
|
} from 'flipper-plugin';
|
|
import React from 'react';
|
|
import getPort from 'get-port';
|
|
import {Button, message, Switch, Typography, Select} from 'antd';
|
|
import fs from 'fs';
|
|
import {DevToolsEmbedder} from './DevToolsEmbedder';
|
|
import {getInternalDevToolsModule} from './fb-stubs/getInternalDevToolsModule';
|
|
|
|
const DEV_TOOLS_NODE_ID = 'reactdevtools-out-of-react-node';
|
|
const CONNECTED = 'DevTools connected';
|
|
const DEV_TOOLS_PORT = 8097; // hardcoded in RN
|
|
|
|
async function findGlobalDevTools(): Promise<string | undefined> {
|
|
try {
|
|
const {stdout: basePath} =
|
|
await getFlipperLib().remoteServerContext.childProcess.exec(
|
|
'npm root -g',
|
|
);
|
|
const devToolsPath = path.join(
|
|
basePath.trim(),
|
|
'react-devtools',
|
|
'node_modules',
|
|
'react-devtools-core',
|
|
);
|
|
await fs.promises.stat(devToolsPath);
|
|
return devToolsPath;
|
|
} catch (error) {
|
|
console.warn('Failed to find globally installed React DevTools: ' + error);
|
|
return undefined;
|
|
}
|
|
}
|
|
|
|
enum ConnectionStatus {
|
|
Initializing = 'Initializing...',
|
|
WaitingForReload = 'Waiting for connection from device...',
|
|
WaitingForMetroReload = 'Waiting for Metro to reload...',
|
|
Connected = 'Connected',
|
|
Error = 'Error',
|
|
}
|
|
|
|
type DevToolsInstanceType = 'global' | 'internal' | 'oss';
|
|
type DevToolsInstance = {
|
|
type: DevToolsInstanceType;
|
|
module: ReactDevToolsStandaloneType;
|
|
};
|
|
|
|
export function devicePlugin(client: DevicePluginClient) {
|
|
const metroDevice = client.device;
|
|
|
|
const statusMessage = createState('initializing');
|
|
const connectionStatus = createState<ConnectionStatus>(
|
|
ConnectionStatus.Initializing,
|
|
);
|
|
const globalDevToolsPath = createState<string>();
|
|
const useGlobalDevTools = createState(false, {
|
|
persist: 'useGlobalDevTools',
|
|
persistToLocalStorage: true,
|
|
});
|
|
|
|
let devToolsInstance = getDefaultDevToolsInstance();
|
|
const selectedDevToolsInstanceType = createState<DevToolsInstanceType>(
|
|
devToolsInstance.type,
|
|
);
|
|
|
|
let startResult: {close(): void} | undefined = undefined;
|
|
|
|
let pollHandle: NodeJS.Timeout | undefined = undefined;
|
|
|
|
let metroReloadAttempts = 0;
|
|
|
|
function getGlobalDevToolsModule(): ReactDevToolsStandaloneType {
|
|
const required = (global as any).electronRequire(
|
|
globalDevToolsPath.get()!,
|
|
).default;
|
|
return required.default ?? required;
|
|
}
|
|
|
|
function getOSSDevToolsModule(): ReactDevToolsStandaloneType {
|
|
const required = require('react-devtools-core/standalone').default;
|
|
return required.default ?? required;
|
|
}
|
|
|
|
async function maybeGetInitialGlobalDevTools(): Promise<DevToolsInstance> {
|
|
const path = await findGlobalDevTools();
|
|
let instance = devToolsInstance;
|
|
if (path) {
|
|
globalDevToolsPath.set(path + '/standalone');
|
|
console.log('Found global React DevTools: ', path);
|
|
// load global devtools instance if the flag is set and
|
|
// we're running a non-FB version of Flipper
|
|
if (useGlobalDevTools.get() && !client.isFB) {
|
|
selectedDevToolsInstanceType.set('global');
|
|
|
|
instance = {
|
|
type: 'global',
|
|
module: getGlobalDevToolsModule(),
|
|
};
|
|
}
|
|
} else {
|
|
useGlobalDevTools.set(false); // disable in case it was enabled
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
function getDefaultDevToolsInstance(): DevToolsInstance {
|
|
const type = client.isFB ? 'internal' : 'oss';
|
|
const module = client.isFB
|
|
? getInternalDevToolsModule<ReactDevToolsStandaloneType>()
|
|
: getOSSDevToolsModule();
|
|
return {type, module};
|
|
}
|
|
|
|
function getDevToolsInstance(
|
|
instanceType: DevToolsInstanceType,
|
|
): DevToolsInstance {
|
|
let module;
|
|
switch (instanceType) {
|
|
case 'global':
|
|
module = getGlobalDevToolsModule();
|
|
break;
|
|
case 'internal':
|
|
module = getInternalDevToolsModule<ReactDevToolsStandaloneType>();
|
|
break;
|
|
case 'oss':
|
|
module = getOSSDevToolsModule();
|
|
break;
|
|
}
|
|
return {
|
|
type: instanceType,
|
|
module,
|
|
};
|
|
}
|
|
|
|
async function setDevToolsInstance(instanceType: DevToolsInstanceType) {
|
|
selectedDevToolsInstanceType.set(instanceType);
|
|
|
|
if (instanceType === 'global') {
|
|
if (!globalDevToolsPath.get()) {
|
|
message.warn(
|
|
"No globally installed react-devtools package found. Run 'npm install -g react-devtools'.",
|
|
);
|
|
return;
|
|
}
|
|
useGlobalDevTools.set(true);
|
|
} else {
|
|
useGlobalDevTools.set(false);
|
|
}
|
|
|
|
devToolsInstance = getDevToolsInstance(instanceType);
|
|
|
|
await rebootDevTools();
|
|
}
|
|
|
|
async function toggleUseGlobalDevTools() {
|
|
if (!globalDevToolsPath.get()) {
|
|
message.warn(
|
|
"No globally installed react-devtools package found. Run 'npm install -g react-devtools'.",
|
|
);
|
|
return;
|
|
}
|
|
selectedDevToolsInstanceType.update((prev: DevToolsInstanceType) => {
|
|
if (prev === 'global') {
|
|
devToolsInstance = getDefaultDevToolsInstance();
|
|
return devToolsInstance.type;
|
|
} else {
|
|
devToolsInstance = getDevToolsInstance('global');
|
|
return devToolsInstance.type;
|
|
}
|
|
});
|
|
useGlobalDevTools.update((v) => !v);
|
|
|
|
await rebootDevTools();
|
|
}
|
|
|
|
async function rebootDevTools() {
|
|
metroReloadAttempts = 0;
|
|
setStatus(ConnectionStatus.Initializing, 'Loading DevTools...');
|
|
// clean old instance
|
|
if (pollHandle) {
|
|
clearTimeout(pollHandle);
|
|
}
|
|
startResult?.close();
|
|
await sleep(5000); // wait for port to close
|
|
startResult = undefined;
|
|
await bootDevTools();
|
|
}
|
|
|
|
async function bootDevTools() {
|
|
const devToolsNode = document.getElementById(DEV_TOOLS_NODE_ID);
|
|
if (!devToolsNode) {
|
|
setStatus(ConnectionStatus.Error, 'Failed to find target DOM Node');
|
|
return;
|
|
}
|
|
|
|
// React DevTools were initilized before
|
|
if (startResult) {
|
|
if (devtoolsHaveStarted()) {
|
|
setStatus(ConnectionStatus.Connected, CONNECTED);
|
|
} else {
|
|
startPollForConnection();
|
|
}
|
|
return;
|
|
}
|
|
|
|
// They're new!
|
|
try {
|
|
setStatus(
|
|
ConnectionStatus.Initializing,
|
|
'Waiting for port ' + DEV_TOOLS_PORT,
|
|
);
|
|
const port = await getPort({port: DEV_TOOLS_PORT}); // default port for dev tools
|
|
if (port !== DEV_TOOLS_PORT) {
|
|
setStatus(
|
|
ConnectionStatus.Error,
|
|
`Port ${DEV_TOOLS_PORT} is already taken`,
|
|
);
|
|
return;
|
|
}
|
|
setStatus(
|
|
ConnectionStatus.Initializing,
|
|
'Starting DevTools server on ' + DEV_TOOLS_PORT,
|
|
);
|
|
startResult = devToolsInstance.module
|
|
.setContentDOMNode(devToolsNode)
|
|
.setStatusListener((message: string, status: string) => {
|
|
// TODO: since devToolsInstance is an instance, we are probably leaking memory here
|
|
if (typeof status === 'undefined') {
|
|
// Preserves old behavior in case DevTools doesn't provide status,
|
|
// which may happen if loading an older version of DevTools.
|
|
setStatus(ConnectionStatus.Initializing, message);
|
|
return;
|
|
}
|
|
|
|
switch (status) {
|
|
case 'server-connected': {
|
|
setStatus(ConnectionStatus.Initializing, message);
|
|
break;
|
|
}
|
|
case 'devtools-connected': {
|
|
if (pollHandle) {
|
|
clearTimeout(pollHandle);
|
|
}
|
|
setStatus(ConnectionStatus.Connected, message);
|
|
break;
|
|
}
|
|
case 'error': {
|
|
if (pollHandle) {
|
|
clearTimeout(pollHandle);
|
|
}
|
|
setStatus(ConnectionStatus.Error, message);
|
|
break;
|
|
}
|
|
}
|
|
})
|
|
.startServer(DEV_TOOLS_PORT, 'localhost', undefined, {
|
|
surface: 'flipper',
|
|
});
|
|
setStatus(ConnectionStatus.Initializing, 'Waiting for device...');
|
|
} catch (e) {
|
|
console.error('Failed to initalize React DevTools' + e);
|
|
setStatus(ConnectionStatus.Error, 'Failed to initialize DevTools: ' + e);
|
|
}
|
|
|
|
setStatus(
|
|
ConnectionStatus.Initializing,
|
|
'DevTools initialized, waiting for connection...',
|
|
);
|
|
if (devtoolsHaveStarted()) {
|
|
setStatus(ConnectionStatus.Connected, CONNECTED);
|
|
} else {
|
|
startPollForConnection();
|
|
}
|
|
}
|
|
|
|
function setStatus(cs: ConnectionStatus, status: string) {
|
|
connectionStatus.set(cs);
|
|
if (status.startsWith('The server is listening on')) {
|
|
statusMessage.set(status + ' Waiting for connection...');
|
|
} else {
|
|
statusMessage.set(status);
|
|
}
|
|
}
|
|
|
|
function startPollForConnection(delay = 3000) {
|
|
pollHandle = setTimeout(async () => {
|
|
switch (true) {
|
|
// Found DevTools!
|
|
case devtoolsHaveStarted():
|
|
setStatus(ConnectionStatus.Connected, CONNECTED);
|
|
return;
|
|
// Waiting for connection, but we do have an active Metro connection, lets force a reload to enter Dev Mode on app
|
|
// prettier-ignore
|
|
case connectionStatus.get() === ConnectionStatus.Initializing: {
|
|
if (metroDevice) {
|
|
const nextConnectionStatus = metroReloadAttempts === 0 ? ConnectionStatus.Initializing : ConnectionStatus.WaitingForMetroReload;
|
|
metroReloadAttempts++;
|
|
setStatus(
|
|
nextConnectionStatus,
|
|
"Sending 'reload' to Metro to force DevTools to connect...",
|
|
);
|
|
metroDevice.sendMetroCommand('reload');
|
|
startPollForConnection(3000);
|
|
return;
|
|
}
|
|
|
|
// Waiting for initial connection, but no WS bridge available
|
|
setStatus(
|
|
ConnectionStatus.WaitingForReload,
|
|
"DevTools is unable to connect yet. Please trigger the DevMenu in the RN app, or reload it to connect.",
|
|
);
|
|
startPollForConnection(10000);
|
|
return;
|
|
}
|
|
// Still nothing? Users might not have done manual action, or some other tools have picked it up?
|
|
case connectionStatus.get() === ConnectionStatus.WaitingForReload:
|
|
case connectionStatus.get() === ConnectionStatus.WaitingForMetroReload:
|
|
setStatus(
|
|
ConnectionStatus.WaitingForReload,
|
|
'DevTools is unable to connect yet. Check for other instances, trigger the DevMenu in the RN app, or reload it to connect.',
|
|
);
|
|
startPollForConnection();
|
|
return;
|
|
}
|
|
}, delay);
|
|
}
|
|
|
|
function devtoolsHaveStarted() {
|
|
return (
|
|
(document.getElementById(DEV_TOOLS_NODE_ID)?.childElementCount ?? 0) > 0
|
|
);
|
|
}
|
|
|
|
client.onReady(async () => {
|
|
devToolsInstance = await maybeGetInitialGlobalDevTools();
|
|
});
|
|
|
|
client.onDestroy(() => {
|
|
startResult?.close();
|
|
});
|
|
|
|
client.onActivate(() => {
|
|
bootDevTools();
|
|
});
|
|
|
|
client.onDeactivate(() => {
|
|
if (pollHandle) {
|
|
clearTimeout(pollHandle);
|
|
}
|
|
});
|
|
|
|
return {
|
|
isFB: client.isFB,
|
|
devtoolsHaveStarted,
|
|
connectionStatus,
|
|
statusMessage,
|
|
bootDevTools,
|
|
rebootDevTools,
|
|
metroDevice,
|
|
globalDevToolsPath,
|
|
useGlobalDevTools,
|
|
selectedDevToolsInstanceType,
|
|
setDevToolsInstance,
|
|
toggleUseGlobalDevTools,
|
|
};
|
|
}
|
|
|
|
export function Component() {
|
|
return (
|
|
<Layout.Container grow>
|
|
<DevToolsInstanceToolbar />
|
|
<DevToolsEmbedder offset={40} nodeId={DEV_TOOLS_NODE_ID} />
|
|
</Layout.Container>
|
|
);
|
|
}
|
|
|
|
function DevToolsInstanceToolbar() {
|
|
const instance = usePlugin(devicePlugin);
|
|
const globalDevToolsPath = useValue(instance.globalDevToolsPath);
|
|
const connectionStatus = useValue(instance.connectionStatus);
|
|
const statusMessage = useValue(instance.statusMessage);
|
|
const useGlobalDevTools = useValue(instance.useGlobalDevTools);
|
|
const selectedDevToolsInstanceType = useValue(
|
|
instance.selectedDevToolsInstanceType,
|
|
);
|
|
|
|
if (!globalDevToolsPath && !instance.isFB) {
|
|
return null;
|
|
}
|
|
|
|
let selectionControl;
|
|
if (instance.isFB) {
|
|
const devToolsInstanceOptions = [{value: 'internal'}, {value: 'oss'}];
|
|
if (globalDevToolsPath) {
|
|
devToolsInstanceOptions.push({value: 'global'});
|
|
}
|
|
selectionControl = (
|
|
<>
|
|
Select preferred DevTools version:
|
|
<Select
|
|
options={devToolsInstanceOptions}
|
|
value={selectedDevToolsInstanceType}
|
|
onChange={instance.setDevToolsInstance}
|
|
style={{width: 90}}
|
|
size="small"
|
|
/>
|
|
</>
|
|
);
|
|
} else if (globalDevToolsPath) {
|
|
selectionControl = (
|
|
<>
|
|
<Switch
|
|
checked={useGlobalDevTools}
|
|
onChange={instance.toggleUseGlobalDevTools}
|
|
size="small"
|
|
/>
|
|
Use globally installed DevTools
|
|
</>
|
|
);
|
|
} else {
|
|
throw new Error(
|
|
'Should not render Toolbar if not FB build or a global DevTools install not available.',
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Toolbar right={selectionControl} wash>
|
|
{connectionStatus !== ConnectionStatus.Connected ? (
|
|
<Typography.Text type="secondary">{statusMessage}</Typography.Text>
|
|
) : null}
|
|
{connectionStatus === ConnectionStatus.WaitingForReload ||
|
|
connectionStatus === ConnectionStatus.WaitingForMetroReload ||
|
|
connectionStatus === ConnectionStatus.Error ? (
|
|
<Button
|
|
size="small"
|
|
onClick={() => {
|
|
instance.metroDevice?.sendMetroCommand('reload');
|
|
instance.rebootDevTools();
|
|
}}>
|
|
Retry
|
|
</Button>
|
|
) : null}
|
|
</Toolbar>
|
|
);
|
|
}
|