@plasmicapp/cli 0.1.162
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/.eslintrc.js +61 -0
- package/.idea/cli.iml +11 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/vcs.xml +6 -0
- package/README +16 -0
- package/README.internal +46 -0
- package/README.md +17 -0
- package/build.sh +8 -0
- package/dist/__mocks__/api.d.ts +16 -0
- package/dist/__mocks__/api.js +297 -0
- package/dist/__tests__/code-utils-spec.d.ts +1 -0
- package/dist/__tests__/code-utils-spec.js +838 -0
- package/dist/__tests__/ftue-spec.d.ts +1 -0
- package/dist/__tests__/ftue-spec.js +39 -0
- package/dist/__tests__/project-api-token-spec.d.ts +1 -0
- package/dist/__tests__/project-api-token-spec.js +147 -0
- package/dist/__tests__/versioned-sync-spec.d.ts +1 -0
- package/dist/__tests__/versioned-sync-spec.js +145 -0
- package/dist/actions/auth.d.ts +8 -0
- package/dist/actions/auth.js +47 -0
- package/dist/actions/fix-imports.d.ts +4 -0
- package/dist/actions/fix-imports.js +25 -0
- package/dist/actions/init.d.ts +62 -0
- package/dist/actions/init.js +460 -0
- package/dist/actions/project-token.d.ts +6 -0
- package/dist/actions/project-token.js +42 -0
- package/dist/actions/sync-components.d.ts +10 -0
- package/dist/actions/sync-components.js +242 -0
- package/dist/actions/sync-global-variants.d.ts +3 -0
- package/dist/actions/sync-global-variants.js +89 -0
- package/dist/actions/sync-icons.d.ts +7 -0
- package/dist/actions/sync-icons.js +92 -0
- package/dist/actions/sync-images.d.ts +6 -0
- package/dist/actions/sync-images.js +137 -0
- package/dist/actions/sync-styles.d.ts +3 -0
- package/dist/actions/sync-styles.js +58 -0
- package/dist/actions/sync.d.ts +25 -0
- package/dist/actions/sync.js +417 -0
- package/dist/actions/upload-bundle.d.ts +15 -0
- package/dist/actions/upload-bundle.js +28 -0
- package/dist/actions/watch.d.ts +14 -0
- package/dist/actions/watch.js +90 -0
- package/dist/api.d.ts +182 -0
- package/dist/api.js +202 -0
- package/dist/deps.d.ts +2 -0
- package/dist/deps.js +20 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +247 -0
- package/dist/lib.d.ts +10 -0
- package/dist/lib.js +23 -0
- package/dist/migrations/0.1.110-fileLocks.d.ts +2 -0
- package/dist/migrations/0.1.110-fileLocks.js +15 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.d.ts +2 -0
- package/dist/migrations/0.1.143-ensureImportModuleType.js +12 -0
- package/dist/migrations/0.1.146-addReactRuntime.d.ts +2 -0
- package/dist/migrations/0.1.146-addReactRuntime.js +10 -0
- package/dist/migrations/0.1.27-migrateInit.d.ts +1 -0
- package/dist/migrations/0.1.27-migrateInit.js +8 -0
- package/dist/migrations/0.1.28-tsToTsx.d.ts +3 -0
- package/dist/migrations/0.1.28-tsToTsx.js +33 -0
- package/dist/migrations/0.1.31-ensureProjectIcons.d.ts +2 -0
- package/dist/migrations/0.1.31-ensureProjectIcons.js +12 -0
- package/dist/migrations/0.1.42-ensureVersion.d.ts +2 -0
- package/dist/migrations/0.1.42-ensureVersion.js +12 -0
- package/dist/migrations/0.1.57-ensureJsBundleThemes.d.ts +2 -0
- package/dist/migrations/0.1.57-ensureJsBundleThemes.js +12 -0
- package/dist/migrations/0.1.64-imageFiles.d.ts +2 -0
- package/dist/migrations/0.1.64-imageFiles.js +17 -0
- package/dist/migrations/0.1.95-componentType.d.ts +2 -0
- package/dist/migrations/0.1.95-componentType.js +16 -0
- package/dist/migrations/migrations.d.ts +10 -0
- package/dist/migrations/migrations.js +119 -0
- package/dist/plasmic.schema.json +463 -0
- package/dist/test-common/fixtures.d.ts +13 -0
- package/dist/test-common/fixtures.js +165 -0
- package/dist/tsconfig-transform.json +68 -0
- package/dist/utils/auth-utils.d.ts +31 -0
- package/dist/utils/auth-utils.js +236 -0
- package/dist/utils/checksum.d.ts +4 -0
- package/dist/utils/checksum.js +63 -0
- package/dist/utils/code-utils.d.ts +46 -0
- package/dist/utils/code-utils.js +457 -0
- package/dist/utils/config-utils.d.ts +271 -0
- package/dist/utils/config-utils.js +178 -0
- package/dist/utils/envdetect.d.ts +4 -0
- package/dist/utils/envdetect.js +42 -0
- package/dist/utils/error.d.ts +14 -0
- package/dist/utils/error.js +42 -0
- package/dist/utils/file-utils.d.ts +71 -0
- package/dist/utils/file-utils.js +433 -0
- package/dist/utils/get-context.d.ts +40 -0
- package/dist/utils/get-context.js +339 -0
- package/dist/utils/help.d.ts +2 -0
- package/dist/utils/help.js +56 -0
- package/dist/utils/lang-utils.d.ts +10 -0
- package/dist/utils/lang-utils.js +52 -0
- package/dist/utils/npm-utils.d.ts +28 -0
- package/dist/utils/npm-utils.js +215 -0
- package/dist/utils/prompts.d.ts +6 -0
- package/dist/utils/prompts.js +23 -0
- package/dist/utils/resolve-utils.d.ts +13 -0
- package/dist/utils/resolve-utils.js +198 -0
- package/dist/utils/semver.d.ts +34 -0
- package/dist/utils/semver.js +61 -0
- package/dist/utils/test-utils.d.ts +22 -0
- package/dist/utils/test-utils.js +106 -0
- package/dist/utils/user-utils.d.ts +7 -0
- package/dist/utils/user-utils.js +48 -0
- package/jest.config.js +6 -0
- package/package.json +80 -0
- package/src/__mocks__/api.ts +394 -0
- package/src/__tests__/code-utils-spec.ts +881 -0
- package/src/__tests__/ftue-spec.ts +43 -0
- package/src/__tests__/project-api-token-spec.ts +208 -0
- package/src/__tests__/versioned-sync-spec.ts +176 -0
- package/src/actions/auth.ts +43 -0
- package/src/actions/fix-imports.ts +13 -0
- package/src/actions/init.ts +638 -0
- package/src/actions/project-token.ts +36 -0
- package/src/actions/sync-components.ts +405 -0
- package/src/actions/sync-global-variants.ts +129 -0
- package/src/actions/sync-icons.ts +135 -0
- package/src/actions/sync-images.ts +191 -0
- package/src/actions/sync-styles.ts +71 -0
- package/src/actions/sync.ts +747 -0
- package/src/actions/upload-bundle.ts +38 -0
- package/src/actions/watch.ts +95 -0
- package/src/api.ts +407 -0
- package/src/deps.ts +18 -0
- package/src/index.ts +300 -0
- package/src/lib.ts +10 -0
- package/src/migrations/0.1.110-fileLocks.ts +16 -0
- package/src/migrations/0.1.146-addReactRuntime.ts +8 -0
- package/src/migrations/0.1.27-migrateInit.ts +4 -0
- package/src/migrations/0.1.28-tsToTsx.ts +37 -0
- package/src/migrations/0.1.31-ensureProjectIcons.ts +10 -0
- package/src/migrations/0.1.42-ensureVersion.ts +10 -0
- package/src/migrations/0.1.57-ensureJsBundleThemes.ts +10 -0
- package/src/migrations/0.1.64-imageFiles.ts +15 -0
- package/src/migrations/0.1.95-componentType.ts +14 -0
- package/src/migrations/migrations.ts +147 -0
- package/src/test-common/fixtures.ts +178 -0
- package/src/utils/auth-utils.ts +276 -0
- package/src/utils/checksum.ts +106 -0
- package/src/utils/code-utils.ts +656 -0
- package/src/utils/config-utils.ts +551 -0
- package/src/utils/envdetect.ts +39 -0
- package/src/utils/error.ts +36 -0
- package/src/utils/file-utils.ts +526 -0
- package/src/utils/get-context.ts +451 -0
- package/src/utils/help.ts +75 -0
- package/src/utils/lang-utils.ts +52 -0
- package/src/utils/npm-utils.ts +223 -0
- package/src/utils/prompts.ts +22 -0
- package/src/utils/resolve-utils.ts +245 -0
- package/src/utils/semver.ts +67 -0
- package/src/utils/test-utils.ts +116 -0
- package/src/utils/user-utils.ts +37 -0
- package/testData/fixImports_plasmic.json +66 -0
- package/tsconfig-transform.json +68 -0
- package/tsconfig.json +67 -0
|
@@ -0,0 +1,838 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const code_utils_1 = require("../utils/code-utils");
|
|
4
|
+
const file_utils_1 = require("../utils/file-utils");
|
|
5
|
+
describe("code-utils", function () {
|
|
6
|
+
it("typescript to javascript should work", function () {
|
|
7
|
+
const code = `
|
|
8
|
+
// This is a skeleton starter React component generated by Plasmic.
|
|
9
|
+
// @jsx helper
|
|
10
|
+
import React, { ReactNode } from "react";
|
|
11
|
+
import {
|
|
12
|
+
PlasmicCodeSandboxDialogContent__RenderHelper,
|
|
13
|
+
PlasmicCodeSandboxDialogContent__VariantsArgs,
|
|
14
|
+
PlasmicCodeSandboxDialogContent__ArgsType,
|
|
15
|
+
PlasmicCodeSandboxDialogContent__VariantsType,
|
|
16
|
+
PlasmicCodeSandboxDialogContent__TriggerStateType,
|
|
17
|
+
} from "./PP__CodeSandboxDialogContent"; // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/render
|
|
18
|
+
|
|
19
|
+
import Button from "../Button"; // plasmic-import: 4SYnkOQLd5/component
|
|
20
|
+
import { PlasmicButton__VariantsArgs } from "../../../plasmic/PlasmicButton"; // plasmic-import: 4SYnkOQLd5/renderer
|
|
21
|
+
import Dropdown from "./Dropdown"; // plasmic-import: a200b79f-288d-4306-be99-e5fd221b8ba6/component
|
|
22
|
+
import { PlasmicDropdown__VariantsArgs } from "./PP__Dropdown"; // plasmic-import: a200b79f-288d-4306-be99-e5fd221b8ba6/renderer
|
|
23
|
+
import DropdownItem from "./DropdownItem"; // plasmic-import: f4c2f0bb-8dce-49c7-a106-65abe9e70e51/component
|
|
24
|
+
import { PlasmicDropdownItem__VariantsArgs } from "./PP__DropdownItem"; // plasmic-import: f4c2f0bb-8dce-49c7-a106-65abe9e70e51/renderer
|
|
25
|
+
import IconButton from "../../IconButton"; // plasmic-import: cfe92-5RW/component
|
|
26
|
+
import { PlasmicIconButton__VariantsArgs } from "../../../plasmic/PlasmicIconButton"; // plasmic-import: cfe92-5RW/renderer
|
|
27
|
+
import { hasVariant, DefaultFlexStack, FlexStack } from "@plasmicapp/react-web";
|
|
28
|
+
import { StudioCtx } from "../../../StudioCtx";
|
|
29
|
+
import { ensure, asOne, isValidEmail } from "../../../../common";
|
|
30
|
+
import { CodeSandboxInfo } from "../../../../shared/db-json-blobs";
|
|
31
|
+
import { createSandboxUrl } from "../../../../codesandbox/url";
|
|
32
|
+
import { Tooltip } from "antd";
|
|
33
|
+
import { observer } from "mobx-react-lite";
|
|
34
|
+
|
|
35
|
+
interface CodeSandboxDialogContentProps {
|
|
36
|
+
sc: StudioCtx;
|
|
37
|
+
onClose: () => void;
|
|
38
|
+
|
|
39
|
+
// Required className prop is used for positioning this component
|
|
40
|
+
className?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function _CodeSandboxDialogContent(props: CodeSandboxDialogContentProps) {
|
|
44
|
+
const sc = props.sc;
|
|
45
|
+
const [inviting, setInviting] = React.useState(false);
|
|
46
|
+
const [submitting, setSubmitting] = React.useState(false);
|
|
47
|
+
const [email, setEmail] = React.useState("");
|
|
48
|
+
const [sandboxInfo, setSandboxInfo] = React.useState<
|
|
49
|
+
CodeSandboxInfo | undefined
|
|
50
|
+
>(asOne(sc.siteInfo.codeSandboxInfos));
|
|
51
|
+
const [codeScheme, setCodeScheme] = React.useState<"blackbox" | "direct">(
|
|
52
|
+
sandboxInfo ? sandboxInfo.code.scheme : "blackbox"
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
const openSandboxPopup = (sandboxId: string) => {
|
|
56
|
+
const url = createSandboxUrl({ id: sandboxId });
|
|
57
|
+
if (sc.popupCodesandboxWindow && !sc.popupCodesandboxWindow.closed) {
|
|
58
|
+
sc.popupCodesandboxWindow.location.href = url;
|
|
59
|
+
sc.popupCodesandboxWindow.focus();
|
|
60
|
+
} else {
|
|
61
|
+
sc.popupCodesandboxWindow = window.open(url);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const onCreateOrUpdateSandbox = async () => {
|
|
66
|
+
setSubmitting(true);
|
|
67
|
+
const { id } = await sc.appCtx.api.publishCodeSandbox(
|
|
68
|
+
sc.siteInfo.id,
|
|
69
|
+
sandboxInfo
|
|
70
|
+
? { ...sandboxInfo }
|
|
71
|
+
: { code: { lang: "ts", scheme: codeScheme } }
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
await sc.refreshSiteInfo();
|
|
75
|
+
setSubmitting(false);
|
|
76
|
+
setSandboxInfo((sc.siteInfo.codeSandboxInfos || []).find(x => x.id === id));
|
|
77
|
+
openSandboxPopup(id);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const onInvite = () => {
|
|
81
|
+
setInviting(true);
|
|
82
|
+
sc.appCtx.api
|
|
83
|
+
.shareCodeSandbox(sc.siteInfo.id, ensure(sandboxInfo).id, email)
|
|
84
|
+
.then(() => {
|
|
85
|
+
setInviting(false);
|
|
86
|
+
});
|
|
87
|
+
setEmail("");
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const onSwitchCodeScheme = (scheme: "blackbox" | "direct") => {
|
|
91
|
+
setCodeScheme(scheme);
|
|
92
|
+
setSandboxInfo(
|
|
93
|
+
(sc.siteInfo.codeSandboxInfos || []).find(x => x.code.scheme === scheme)
|
|
94
|
+
);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const onDeleteSandbox = async () => {
|
|
98
|
+
setSubmitting(true);
|
|
99
|
+
await sc.appCtx.api.detachCodeSandbox(
|
|
100
|
+
sc.siteInfo.id,
|
|
101
|
+
ensure(sandboxInfo).id
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
await sc.refreshSiteInfo();
|
|
105
|
+
setSubmitting(false);
|
|
106
|
+
setSandboxInfo(undefined);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const variants: PlasmicCodeSandboxDialogContent__VariantsArgs = {
|
|
110
|
+
state: inviting ? "inviting" : submitting ? "submitting" : undefined,
|
|
111
|
+
hasSandbox: !!sandboxInfo ? "yes" : "no",
|
|
112
|
+
invalidEmail: !isValidEmail(email) ? "yes" : undefined,
|
|
113
|
+
canEdit: !sc.canEditProject() ? "no" : undefined,
|
|
114
|
+
scheme: codeScheme === "direct" ? "direct" : "blackbox"
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const args: PlasmicCodeSandboxDialogContent__ArgsType = {};
|
|
118
|
+
|
|
119
|
+
// The following code block is fully managed by Plasmic. Don't edit - it will
|
|
120
|
+
// be overwritten after every "plasmic sync".
|
|
121
|
+
// plasmic-managed-start
|
|
122
|
+
|
|
123
|
+
const rh = new PlasmicCodeSandboxDialogContent__RenderHelper(
|
|
124
|
+
variants,
|
|
125
|
+
args,
|
|
126
|
+
props.className
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// plasmic-managed-end
|
|
130
|
+
|
|
131
|
+
// plasmic-managed-jsx/5487
|
|
132
|
+
return (
|
|
133
|
+
<div className={rh.clsRoot()}>
|
|
134
|
+
<div className={rh.clsF7050e55$eea1$41ab$9682$db9ad8d08cb1()}>
|
|
135
|
+
<div className={rh.cls70032be2$1620$48b3$ba29$c027e30b7907()}>
|
|
136
|
+
CodeSandbox
|
|
137
|
+
</div>
|
|
138
|
+
<DefaultFlexStack className={rh.cls8oFaZaiIX()}>
|
|
139
|
+
{rh.showOpenButton() && (
|
|
140
|
+
<Button
|
|
141
|
+
startIcon={
|
|
142
|
+
<img className={rh.cls$qzB2zcT8()} {...rh.props$qzB2zcT8()} />
|
|
143
|
+
}
|
|
144
|
+
{...rh.propsOpenButton()}
|
|
145
|
+
onClick={() => openSandboxPopup(ensure(sandboxInfo).id)}
|
|
146
|
+
>
|
|
147
|
+
Open in new tab
|
|
148
|
+
</Button>
|
|
149
|
+
)}
|
|
150
|
+
|
|
151
|
+
<img
|
|
152
|
+
className={rh.clsCloseButton()}
|
|
153
|
+
{...rh.propsCloseButton()}
|
|
154
|
+
onClick={props.onClose}
|
|
155
|
+
/>
|
|
156
|
+
</DefaultFlexStack>
|
|
157
|
+
</div>
|
|
158
|
+
<div className={rh.cls43fcb29a$5286$4b5a$8593$49b737cdd7b0()} />
|
|
159
|
+
<DefaultFlexStack className={rh.clsWL8ypAgbq()}>
|
|
160
|
+
<div className={rh.clsTmQlfUKwS()}>Code scheme</div>
|
|
161
|
+
<Dropdown
|
|
162
|
+
{...rh.propsCodeSchemeDropdown()}
|
|
163
|
+
selectedValue={rh.childStrCodeSchemeDropdown()}
|
|
164
|
+
items={
|
|
165
|
+
<>
|
|
166
|
+
<DropdownItem
|
|
167
|
+
{...rh.propsBlackBoxOption()}
|
|
168
|
+
value={"Blackbox Library"}
|
|
169
|
+
selected={codeScheme === "blackbox"}
|
|
170
|
+
onSelected={() => onSwitchCodeScheme("blackbox")}
|
|
171
|
+
/>
|
|
172
|
+
|
|
173
|
+
<DropdownItem
|
|
174
|
+
{...rh.propsPlainReactOption()}
|
|
175
|
+
value={"Direct Edit"}
|
|
176
|
+
selected={codeScheme === "direct"}
|
|
177
|
+
onSelected={() => onSwitchCodeScheme("direct")}
|
|
178
|
+
/>
|
|
179
|
+
</>
|
|
180
|
+
}
|
|
181
|
+
/>
|
|
182
|
+
</DefaultFlexStack>
|
|
183
|
+
<div className={rh.clsH1u3gI8vG()}>{rh.childStrH1u3gI8vG()}</div>
|
|
184
|
+
{rh.showCreateHint() && (
|
|
185
|
+
<div className={rh.clsCreateHint()}>
|
|
186
|
+
{rh.showCreateHint2() && (
|
|
187
|
+
<div className={rh.clsCreateHint2()}>
|
|
188
|
+
{rh.childStrCreateHint2()}
|
|
189
|
+
</div>
|
|
190
|
+
)}
|
|
191
|
+
</div>
|
|
192
|
+
)}
|
|
193
|
+
|
|
194
|
+
{rh.showCreateButton() && (
|
|
195
|
+
<Button
|
|
196
|
+
startIcon={
|
|
197
|
+
<img className={rh.clsGvtJoBerl()} {...rh.propsGvtJoBerl()} />
|
|
198
|
+
}
|
|
199
|
+
{...rh.propsCreateButton()}
|
|
200
|
+
onClick={onCreateOrUpdateSandbox}
|
|
201
|
+
>
|
|
202
|
+
{rh.childStrCreateButton()}
|
|
203
|
+
</Button>
|
|
204
|
+
)}
|
|
205
|
+
|
|
206
|
+
{rh.showUpdateHint() && (
|
|
207
|
+
<div className={rh.clsUpdateHint()}>
|
|
208
|
+
<div className={rh.clsCreateHint22()}>
|
|
209
|
+
{rh.childStrCreateHint22()}
|
|
210
|
+
</div>
|
|
211
|
+
</div>
|
|
212
|
+
)}
|
|
213
|
+
|
|
214
|
+
{rh.showNmdHeAjEx() && (
|
|
215
|
+
<DefaultFlexStack className={rh.clsNmdHeAjEx()}>
|
|
216
|
+
<input
|
|
217
|
+
className={rh.clsEmail()}
|
|
218
|
+
{...rh.propsEmail()}
|
|
219
|
+
onChange={e => setEmail(e.target.value)}
|
|
220
|
+
value={email}
|
|
221
|
+
/>
|
|
222
|
+
|
|
223
|
+
<Button {...rh.propsInviteButton()} onClick={onInvite}>
|
|
224
|
+
{rh.childStrInviteButton()}
|
|
225
|
+
</Button>
|
|
226
|
+
<div className={rh.clsZG$NA1rCh()} />
|
|
227
|
+
{rh.show$kdxH_yN6() && (
|
|
228
|
+
<div className={rh.cls$kdxH_yN6()}>
|
|
229
|
+
{rh.showUpdateButton() && (
|
|
230
|
+
<Button
|
|
231
|
+
startIcon={
|
|
232
|
+
rh.showL4QcXYzNZ() && (
|
|
233
|
+
<img
|
|
234
|
+
className={rh.clsL4QcXYzNZ()}
|
|
235
|
+
{...rh.propsL4QcXYzNZ()}
|
|
236
|
+
/>
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
{...rh.propsUpdateButton()}
|
|
240
|
+
onClick={onCreateOrUpdateSandbox}
|
|
241
|
+
>
|
|
242
|
+
{rh.childStrUpdateButton()}
|
|
243
|
+
</Button>
|
|
244
|
+
)}
|
|
245
|
+
|
|
246
|
+
{rh.showDeleteButton() && (
|
|
247
|
+
<Tooltip title="Detach this code sandbox. You can still access it via codesandbox.io, but Plasmic will start using a new sandbox instead.">
|
|
248
|
+
<IconButton
|
|
249
|
+
{...rh.propsDeleteButton()}
|
|
250
|
+
onClick={onDeleteSandbox}
|
|
251
|
+
/>
|
|
252
|
+
</Tooltip>
|
|
253
|
+
)}
|
|
254
|
+
</div>
|
|
255
|
+
)}
|
|
256
|
+
</DefaultFlexStack>
|
|
257
|
+
)}
|
|
258
|
+
</div>
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export const CodeSandboxDialogContent = observer(
|
|
263
|
+
_CodeSandboxDialogContent as React.FunctionComponent<
|
|
264
|
+
CodeSandboxDialogContentProps
|
|
265
|
+
>
|
|
266
|
+
);`;
|
|
267
|
+
expect(code_utils_1.formatScript(code_utils_1.tsxToJsx(code), process.cwd()).trim()).toEqual(`
|
|
268
|
+
// This is a skeleton starter React component generated by Plasmic.
|
|
269
|
+
// @jsx helper
|
|
270
|
+
import React from "react";
|
|
271
|
+
import { PlasmicCodeSandboxDialogContent__RenderHelper } from "./PP__CodeSandboxDialogContent"; // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/render
|
|
272
|
+
import Button from "../Button"; // plasmic-import: 4SYnkOQLd5/component
|
|
273
|
+
import Dropdown from "./Dropdown"; // plasmic-import: a200b79f-288d-4306-be99-e5fd221b8ba6/component
|
|
274
|
+
import DropdownItem from "./DropdownItem"; // plasmic-import: f4c2f0bb-8dce-49c7-a106-65abe9e70e51/component
|
|
275
|
+
import IconButton from "../../IconButton"; // plasmic-import: cfe92-5RW/component
|
|
276
|
+
import { DefaultFlexStack } from "@plasmicapp/react-web";
|
|
277
|
+
import { ensure, asOne, isValidEmail } from "../../../../common";
|
|
278
|
+
import { createSandboxUrl } from "../../../../codesandbox/url";
|
|
279
|
+
import { Tooltip } from "antd";
|
|
280
|
+
import { observer } from "mobx-react-lite";
|
|
281
|
+
|
|
282
|
+
function _CodeSandboxDialogContent(props) {
|
|
283
|
+
const sc = props.sc;
|
|
284
|
+
const [inviting, setInviting] = React.useState(false);
|
|
285
|
+
const [submitting, setSubmitting] = React.useState(false);
|
|
286
|
+
const [email, setEmail] = React.useState("");
|
|
287
|
+
const [sandboxInfo, setSandboxInfo] = React.useState(
|
|
288
|
+
asOne(sc.siteInfo.codeSandboxInfos)
|
|
289
|
+
);
|
|
290
|
+
const [codeScheme, setCodeScheme] = React.useState(
|
|
291
|
+
sandboxInfo ? sandboxInfo.code.scheme : "blackbox"
|
|
292
|
+
);
|
|
293
|
+
const openSandboxPopup = (sandboxId) => {
|
|
294
|
+
const url = createSandboxUrl({ id: sandboxId });
|
|
295
|
+
if (sc.popupCodesandboxWindow && !sc.popupCodesandboxWindow.closed) {
|
|
296
|
+
sc.popupCodesandboxWindow.location.href = url;
|
|
297
|
+
sc.popupCodesandboxWindow.focus();
|
|
298
|
+
} else {
|
|
299
|
+
sc.popupCodesandboxWindow = window.open(url);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
const onCreateOrUpdateSandbox = async () => {
|
|
303
|
+
setSubmitting(true);
|
|
304
|
+
const { id } = await sc.appCtx.api.publishCodeSandbox(
|
|
305
|
+
sc.siteInfo.id,
|
|
306
|
+
sandboxInfo
|
|
307
|
+
? { ...sandboxInfo }
|
|
308
|
+
: { code: { lang: "ts", scheme: codeScheme } }
|
|
309
|
+
);
|
|
310
|
+
await sc.refreshSiteInfo();
|
|
311
|
+
setSubmitting(false);
|
|
312
|
+
setSandboxInfo(
|
|
313
|
+
(sc.siteInfo.codeSandboxInfos || []).find((x) => x.id === id)
|
|
314
|
+
);
|
|
315
|
+
openSandboxPopup(id);
|
|
316
|
+
};
|
|
317
|
+
const onInvite = () => {
|
|
318
|
+
setInviting(true);
|
|
319
|
+
sc.appCtx.api
|
|
320
|
+
.shareCodeSandbox(sc.siteInfo.id, ensure(sandboxInfo).id, email)
|
|
321
|
+
.then(() => {
|
|
322
|
+
setInviting(false);
|
|
323
|
+
});
|
|
324
|
+
setEmail("");
|
|
325
|
+
};
|
|
326
|
+
const onSwitchCodeScheme = (scheme) => {
|
|
327
|
+
setCodeScheme(scheme);
|
|
328
|
+
setSandboxInfo(
|
|
329
|
+
(sc.siteInfo.codeSandboxInfos || []).find((x) => x.code.scheme === scheme)
|
|
330
|
+
);
|
|
331
|
+
};
|
|
332
|
+
const onDeleteSandbox = async () => {
|
|
333
|
+
setSubmitting(true);
|
|
334
|
+
await sc.appCtx.api.detachCodeSandbox(
|
|
335
|
+
sc.siteInfo.id,
|
|
336
|
+
ensure(sandboxInfo).id
|
|
337
|
+
);
|
|
338
|
+
await sc.refreshSiteInfo();
|
|
339
|
+
setSubmitting(false);
|
|
340
|
+
setSandboxInfo(undefined);
|
|
341
|
+
};
|
|
342
|
+
const variants = {
|
|
343
|
+
state: inviting ? "inviting" : submitting ? "submitting" : undefined,
|
|
344
|
+
hasSandbox: !!sandboxInfo ? "yes" : "no",
|
|
345
|
+
invalidEmail: !isValidEmail(email) ? "yes" : undefined,
|
|
346
|
+
canEdit: !sc.canEditProject() ? "no" : undefined,
|
|
347
|
+
scheme: codeScheme === "direct" ? "direct" : "blackbox",
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
const args = {};
|
|
351
|
+
// The following code block is fully managed by Plasmic. Don't edit - it will
|
|
352
|
+
// be overwritten after every "plasmic sync".
|
|
353
|
+
// plasmic-managed-start
|
|
354
|
+
const rh = new PlasmicCodeSandboxDialogContent__RenderHelper(
|
|
355
|
+
variants,
|
|
356
|
+
args,
|
|
357
|
+
props.className
|
|
358
|
+
);
|
|
359
|
+
// plasmic-managed-end
|
|
360
|
+
// plasmic-managed-jsx/5487
|
|
361
|
+
return (
|
|
362
|
+
<div className={rh.clsRoot()}>
|
|
363
|
+
<div className={rh.clsF7050e55$eea1$41ab$9682$db9ad8d08cb1()}>
|
|
364
|
+
<div className={rh.cls70032be2$1620$48b3$ba29$c027e30b7907()}>
|
|
365
|
+
CodeSandbox
|
|
366
|
+
</div>
|
|
367
|
+
<DefaultFlexStack className={rh.cls8oFaZaiIX()}>
|
|
368
|
+
{rh.showOpenButton() && (
|
|
369
|
+
<Button
|
|
370
|
+
startIcon={
|
|
371
|
+
<img className={rh.cls$qzB2zcT8()} {...rh.props$qzB2zcT8()} />
|
|
372
|
+
}
|
|
373
|
+
{...rh.propsOpenButton()}
|
|
374
|
+
onClick={() => openSandboxPopup(ensure(sandboxInfo).id)}
|
|
375
|
+
>
|
|
376
|
+
Open in new tab
|
|
377
|
+
</Button>
|
|
378
|
+
)}
|
|
379
|
+
|
|
380
|
+
<img
|
|
381
|
+
className={rh.clsCloseButton()}
|
|
382
|
+
{...rh.propsCloseButton()}
|
|
383
|
+
onClick={props.onClose}
|
|
384
|
+
/>
|
|
385
|
+
</DefaultFlexStack>
|
|
386
|
+
</div>
|
|
387
|
+
<div className={rh.cls43fcb29a$5286$4b5a$8593$49b737cdd7b0()} />
|
|
388
|
+
<DefaultFlexStack className={rh.clsWL8ypAgbq()}>
|
|
389
|
+
<div className={rh.clsTmQlfUKwS()}>Code scheme</div>
|
|
390
|
+
<Dropdown
|
|
391
|
+
{...rh.propsCodeSchemeDropdown()}
|
|
392
|
+
selectedValue={rh.childStrCodeSchemeDropdown()}
|
|
393
|
+
items={
|
|
394
|
+
<>
|
|
395
|
+
<DropdownItem
|
|
396
|
+
{...rh.propsBlackBoxOption()}
|
|
397
|
+
value={"Blackbox Library"}
|
|
398
|
+
selected={codeScheme === "blackbox"}
|
|
399
|
+
onSelected={() => onSwitchCodeScheme("blackbox")}
|
|
400
|
+
/>
|
|
401
|
+
|
|
402
|
+
<DropdownItem
|
|
403
|
+
{...rh.propsPlainReactOption()}
|
|
404
|
+
value={"Direct Edit"}
|
|
405
|
+
selected={codeScheme === "direct"}
|
|
406
|
+
onSelected={() => onSwitchCodeScheme("direct")}
|
|
407
|
+
/>
|
|
408
|
+
</>
|
|
409
|
+
}
|
|
410
|
+
/>
|
|
411
|
+
</DefaultFlexStack>
|
|
412
|
+
<div className={rh.clsH1u3gI8vG()}>{rh.childStrH1u3gI8vG()}</div>
|
|
413
|
+
{rh.showCreateHint() && (
|
|
414
|
+
<div className={rh.clsCreateHint()}>
|
|
415
|
+
{rh.showCreateHint2() && (
|
|
416
|
+
<div className={rh.clsCreateHint2()}>
|
|
417
|
+
{rh.childStrCreateHint2()}
|
|
418
|
+
</div>
|
|
419
|
+
)}
|
|
420
|
+
</div>
|
|
421
|
+
)}
|
|
422
|
+
|
|
423
|
+
{rh.showCreateButton() && (
|
|
424
|
+
<Button
|
|
425
|
+
startIcon={
|
|
426
|
+
<img className={rh.clsGvtJoBerl()} {...rh.propsGvtJoBerl()} />
|
|
427
|
+
}
|
|
428
|
+
{...rh.propsCreateButton()}
|
|
429
|
+
onClick={onCreateOrUpdateSandbox}
|
|
430
|
+
>
|
|
431
|
+
{rh.childStrCreateButton()}
|
|
432
|
+
</Button>
|
|
433
|
+
)}
|
|
434
|
+
|
|
435
|
+
{rh.showUpdateHint() && (
|
|
436
|
+
<div className={rh.clsUpdateHint()}>
|
|
437
|
+
<div className={rh.clsCreateHint22()}>
|
|
438
|
+
{rh.childStrCreateHint22()}
|
|
439
|
+
</div>
|
|
440
|
+
</div>
|
|
441
|
+
)}
|
|
442
|
+
|
|
443
|
+
{rh.showNmdHeAjEx() && (
|
|
444
|
+
<DefaultFlexStack className={rh.clsNmdHeAjEx()}>
|
|
445
|
+
<input
|
|
446
|
+
className={rh.clsEmail()}
|
|
447
|
+
{...rh.propsEmail()}
|
|
448
|
+
onChange={(e) => setEmail(e.target.value)}
|
|
449
|
+
value={email}
|
|
450
|
+
/>
|
|
451
|
+
|
|
452
|
+
<Button {...rh.propsInviteButton()} onClick={onInvite}>
|
|
453
|
+
{rh.childStrInviteButton()}
|
|
454
|
+
</Button>
|
|
455
|
+
<div className={rh.clsZG$NA1rCh()} />
|
|
456
|
+
{rh.show$kdxH_yN6() && (
|
|
457
|
+
<div className={rh.cls$kdxH_yN6()}>
|
|
458
|
+
{rh.showUpdateButton() && (
|
|
459
|
+
<Button
|
|
460
|
+
startIcon={
|
|
461
|
+
rh.showL4QcXYzNZ() && (
|
|
462
|
+
<img
|
|
463
|
+
className={rh.clsL4QcXYzNZ()}
|
|
464
|
+
{...rh.propsL4QcXYzNZ()}
|
|
465
|
+
/>
|
|
466
|
+
)
|
|
467
|
+
}
|
|
468
|
+
{...rh.propsUpdateButton()}
|
|
469
|
+
onClick={onCreateOrUpdateSandbox}
|
|
470
|
+
>
|
|
471
|
+
{rh.childStrUpdateButton()}
|
|
472
|
+
</Button>
|
|
473
|
+
)}
|
|
474
|
+
|
|
475
|
+
{rh.showDeleteButton() && (
|
|
476
|
+
<Tooltip title="Detach this code sandbox. You can still access it via codesandbox.io, but Plasmic will start using a new sandbox instead.">
|
|
477
|
+
<IconButton
|
|
478
|
+
{...rh.propsDeleteButton()}
|
|
479
|
+
onClick={onDeleteSandbox}
|
|
480
|
+
/>
|
|
481
|
+
</Tooltip>
|
|
482
|
+
)}
|
|
483
|
+
</div>
|
|
484
|
+
)}
|
|
485
|
+
</DefaultFlexStack>
|
|
486
|
+
)}
|
|
487
|
+
</div>
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
export const CodeSandboxDialogContent = observer(_CodeSandboxDialogContent);
|
|
492
|
+
`.trim());
|
|
493
|
+
});
|
|
494
|
+
it("fix imports for file should work", function () {
|
|
495
|
+
const code = `// This is a skeleton starter React component generated by Plasmic.
|
|
496
|
+
import React, { ReactNode } from "react";
|
|
497
|
+
import {
|
|
498
|
+
PlasmicCodeSandboxDialogContent__RenderHelper,
|
|
499
|
+
PlasmicCodeSandboxDialogContent__VariantsArgs,
|
|
500
|
+
PlasmicCodeSandboxDialogContent__ArgsType,
|
|
501
|
+
PlasmicCodeSandboxDialogContent__TriggerStateType,
|
|
502
|
+
} from "./PP__CodeSandboxDialogContent"; // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/render
|
|
503
|
+
import Button from "./Button"; // plasmic-import: 4SYnkOQLd5/component
|
|
504
|
+
import CloseIcon from "./PlasmicIcon__Close"; // plasmic-import: rFn9Vj2p9/icon
|
|
505
|
+
|
|
506
|
+
import "@plasmicapp/react-web/lib/plasmic.css";
|
|
507
|
+
import "./PP__plasmic__default_style.css"; // plasmic-import: global/defaultcss
|
|
508
|
+
import "./PP__plasmic_kit.css"; // plasmic-import: aBwbYpvCqht4V3F8CJNJX3/projectcss
|
|
509
|
+
import "./PP__CodeSandboxDialogContent.css"; // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/css
|
|
510
|
+
|
|
511
|
+
import {
|
|
512
|
+
hasVariant,
|
|
513
|
+
DefaultFlexStack,
|
|
514
|
+
Stack,
|
|
515
|
+
PlasmicIcon,
|
|
516
|
+
} from "@plasmicapp/react-web";
|
|
517
|
+
import { StudioCtx } from "../../../StudioCtx";
|
|
518
|
+
import { observer } from "mobx-react-lite";
|
|
519
|
+
|
|
520
|
+
function _CodeSandboxDialogContent(props) {
|
|
521
|
+
return null;
|
|
522
|
+
}
|
|
523
|
+
`;
|
|
524
|
+
const configJson = file_utils_1.readFileText("./testData/fixImports_plasmic.json").toString();
|
|
525
|
+
const config = JSON.parse(configJson);
|
|
526
|
+
const context = {
|
|
527
|
+
config,
|
|
528
|
+
cliArgs: {},
|
|
529
|
+
};
|
|
530
|
+
const fixImportContext = code_utils_1.mkFixImportContext(config);
|
|
531
|
+
const replaced = code_utils_1.replaceImports(context, code, "/tmp/CodeSandbox.tsx", fixImportContext, false, process.cwd());
|
|
532
|
+
const expectedCode = `// This is a skeleton starter React component generated by Plasmic.
|
|
533
|
+
import React, { ReactNode } from "react";
|
|
534
|
+
import {
|
|
535
|
+
PlasmicCodeSandboxDialogContent__RenderHelper,
|
|
536
|
+
PlasmicCodeSandboxDialogContent__VariantsArgs,
|
|
537
|
+
PlasmicCodeSandboxDialogContent__ArgsType,
|
|
538
|
+
PlasmicCodeSandboxDialogContent__TriggerStateType,
|
|
539
|
+
} from "./newDir/PP__CodeSandboxDialogContent"; // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/render
|
|
540
|
+
import Button from "./newDir/Button"; // plasmic-import: 4SYnkOQLd5/component
|
|
541
|
+
import CloseIcon from "./newDir/PlasmicIcon__Close"; // plasmic-import: rFn9Vj2p9/icon
|
|
542
|
+
|
|
543
|
+
import "@plasmicapp/react-web/lib/plasmic.css";
|
|
544
|
+
import "./newDir/PP__plasmic__default_style.css"; // plasmic-import: global/defaultcss
|
|
545
|
+
import "./newDir/PP__plasmic_kit.css"; // plasmic-import: aBwbYpvCqht4V3F8CJNJX3/projectcss
|
|
546
|
+
import "./newDir/PP__CodeSandboxDialogContent.css"; // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/css
|
|
547
|
+
|
|
548
|
+
import {
|
|
549
|
+
hasVariant,
|
|
550
|
+
DefaultFlexStack,
|
|
551
|
+
Stack,
|
|
552
|
+
PlasmicIcon,
|
|
553
|
+
} from "@plasmicapp/react-web";
|
|
554
|
+
import { StudioCtx } from "../../../StudioCtx";
|
|
555
|
+
import { observer } from "mobx-react-lite";
|
|
556
|
+
|
|
557
|
+
function _CodeSandboxDialogContent(props) {
|
|
558
|
+
return null;
|
|
559
|
+
}
|
|
560
|
+
`;
|
|
561
|
+
expect(replaced).toEqual(expectedCode);
|
|
562
|
+
});
|
|
563
|
+
it("fix imports should remove directives", function () {
|
|
564
|
+
const code = `// This is a skeleton starter React component generated by Plasmic.
|
|
565
|
+
import React, { ReactNode } from "react";
|
|
566
|
+
import {
|
|
567
|
+
PlasmicCodeSandboxDialogContent__RenderHelper,
|
|
568
|
+
PlasmicCodeSandboxDialogContent__VariantsArgs,
|
|
569
|
+
PlasmicCodeSandboxDialogContent__ArgsType,
|
|
570
|
+
PlasmicCodeSandboxDialogContent__TriggerStateType,
|
|
571
|
+
} from "./PP__CodeSandboxDialogContent"; // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/render
|
|
572
|
+
import Button from "./Button"; // plasmic-import: 4SYnkOQLd5/component
|
|
573
|
+
import CloseIcon from "./PlasmicIcon__Close"; // plasmic-import: rFn9Vj2p9/icon
|
|
574
|
+
|
|
575
|
+
import "@plasmicapp/react-web/lib/plasmic.css";
|
|
576
|
+
import "./PP__plasmic__default_style.css"; // plasmic-import: global/defaultcss
|
|
577
|
+
import "./PP__plasmic_kit.css"; // plasmic-import: aBwbYpvCqht4V3F8CJNJX3/projectcss
|
|
578
|
+
import "./PP__CodeSandboxDialogContent.css"; // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/css
|
|
579
|
+
|
|
580
|
+
import {
|
|
581
|
+
hasVariant,
|
|
582
|
+
DefaultFlexStack,
|
|
583
|
+
Stack,
|
|
584
|
+
PlasmicIcon,
|
|
585
|
+
} from "@plasmicapp/react-web";
|
|
586
|
+
import { StudioCtx } from "../../../StudioCtx";
|
|
587
|
+
import { observer } from "mobx-react-lite";
|
|
588
|
+
|
|
589
|
+
function _CodeSandboxDialogContent(props) {
|
|
590
|
+
return null;
|
|
591
|
+
}
|
|
592
|
+
`;
|
|
593
|
+
const configJson = file_utils_1.readFileText("./testData/fixImports_plasmic.json").toString();
|
|
594
|
+
const config = JSON.parse(configJson);
|
|
595
|
+
const fixImportContext = code_utils_1.mkFixImportContext(config);
|
|
596
|
+
const context = {
|
|
597
|
+
config,
|
|
598
|
+
cliArgs: {},
|
|
599
|
+
};
|
|
600
|
+
const replaced = code_utils_1.replaceImports(context, code, "/tmp/CodeSandbox.tsx", fixImportContext, true, process.cwd());
|
|
601
|
+
const expectedCode = `// This is a skeleton starter React component generated by Plasmic.
|
|
602
|
+
import React, { ReactNode } from "react";
|
|
603
|
+
import {
|
|
604
|
+
PlasmicCodeSandboxDialogContent__RenderHelper,
|
|
605
|
+
PlasmicCodeSandboxDialogContent__VariantsArgs,
|
|
606
|
+
PlasmicCodeSandboxDialogContent__ArgsType,
|
|
607
|
+
PlasmicCodeSandboxDialogContent__TriggerStateType,
|
|
608
|
+
} from "./newDir/PP__CodeSandboxDialogContent";
|
|
609
|
+
import Button from "./newDir/Button";
|
|
610
|
+
import CloseIcon from "./newDir/PlasmicIcon__Close";
|
|
611
|
+
|
|
612
|
+
import "@plasmicapp/react-web/lib/plasmic.css";
|
|
613
|
+
import "./newDir/PP__plasmic__default_style.css";
|
|
614
|
+
import "./newDir/PP__plasmic_kit.css";
|
|
615
|
+
import "./newDir/PP__CodeSandboxDialogContent.css";
|
|
616
|
+
|
|
617
|
+
import {
|
|
618
|
+
hasVariant,
|
|
619
|
+
DefaultFlexStack,
|
|
620
|
+
Stack,
|
|
621
|
+
PlasmicIcon,
|
|
622
|
+
} from "@plasmicapp/react-web";
|
|
623
|
+
import { StudioCtx } from "../../../StudioCtx";
|
|
624
|
+
import { observer } from "mobx-react-lite";
|
|
625
|
+
|
|
626
|
+
function _CodeSandboxDialogContent(props) {
|
|
627
|
+
return null;
|
|
628
|
+
}
|
|
629
|
+
`;
|
|
630
|
+
expect(replaced).toEqual(expectedCode);
|
|
631
|
+
});
|
|
632
|
+
it("fix imports for file should work when the code has no semicolon", function () {
|
|
633
|
+
const code = `// This is a skeleton starter React component generated by Plasmic.
|
|
634
|
+
import React, { ReactNode } from "react";
|
|
635
|
+
import {
|
|
636
|
+
PlasmicCodeSandboxDialogContent__RenderHelper,
|
|
637
|
+
PlasmicCodeSandboxDialogContent__VariantsArgs,
|
|
638
|
+
PlasmicCodeSandboxDialogContent__ArgsType,
|
|
639
|
+
PlasmicCodeSandboxDialogContent__TriggerStateType,
|
|
640
|
+
} from "./PP__CodeSandboxDialogContent" // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/render
|
|
641
|
+
import Button from "./Button" // plasmic-import: 4SYnkOQLd5/component
|
|
642
|
+
import CloseIcon from "./PlasmicIcon__Close" // plasmic-import: rFn9Vj2p9/icon
|
|
643
|
+
|
|
644
|
+
import "@plasmicapp/react-web/lib/plasmic.css"
|
|
645
|
+
import "./PP__plasmic__default_style.css" // plasmic-import: global/defaultcss
|
|
646
|
+
import "./PP__plasmic_kit.css" // plasmic-import: aBwbYpvCqht4V3F8CJNJX3/projectcss
|
|
647
|
+
import "./PP__CodeSandboxDialogContent.css" // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/css
|
|
648
|
+
|
|
649
|
+
import {
|
|
650
|
+
hasVariant,
|
|
651
|
+
DefaultFlexStack,
|
|
652
|
+
Stack,
|
|
653
|
+
PlasmicIcon,
|
|
654
|
+
} from "@plasmicapp/react-web";
|
|
655
|
+
import { StudioCtx } from "../../../StudioCtx"
|
|
656
|
+
import { observer } from "mobx-react-lite"
|
|
657
|
+
|
|
658
|
+
function _CodeSandboxDialogContent(props) {
|
|
659
|
+
return null
|
|
660
|
+
}
|
|
661
|
+
`;
|
|
662
|
+
const configJson = file_utils_1.readFileText("./testData/fixImports_plasmic.json").toString();
|
|
663
|
+
const config = JSON.parse(configJson);
|
|
664
|
+
const fixImportContext = code_utils_1.mkFixImportContext(config);
|
|
665
|
+
const context = {
|
|
666
|
+
config,
|
|
667
|
+
cliArgs: {},
|
|
668
|
+
};
|
|
669
|
+
const replaced = code_utils_1.replaceImports(context, code, "/tmp/CodeSandbox.tsx", fixImportContext, false, process.cwd());
|
|
670
|
+
const expectedCode = `// This is a skeleton starter React component generated by Plasmic.
|
|
671
|
+
import React, { ReactNode } from "react";
|
|
672
|
+
import {
|
|
673
|
+
PlasmicCodeSandboxDialogContent__RenderHelper,
|
|
674
|
+
PlasmicCodeSandboxDialogContent__VariantsArgs,
|
|
675
|
+
PlasmicCodeSandboxDialogContent__ArgsType,
|
|
676
|
+
PlasmicCodeSandboxDialogContent__TriggerStateType,
|
|
677
|
+
} from "./newDir/PP__CodeSandboxDialogContent"; // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/render
|
|
678
|
+
import Button from "./newDir/Button"; // plasmic-import: 4SYnkOQLd5/component
|
|
679
|
+
import CloseIcon from "./newDir/PlasmicIcon__Close"; // plasmic-import: rFn9Vj2p9/icon
|
|
680
|
+
|
|
681
|
+
import "@plasmicapp/react-web/lib/plasmic.css";
|
|
682
|
+
import "./newDir/PP__plasmic__default_style.css"; // plasmic-import: global/defaultcss
|
|
683
|
+
import "./newDir/PP__plasmic_kit.css"; // plasmic-import: aBwbYpvCqht4V3F8CJNJX3/projectcss
|
|
684
|
+
import "./newDir/PP__CodeSandboxDialogContent.css"; // plasmic-import: f68b061e-0f85-41c1-8707-3ba9f634f1af/css
|
|
685
|
+
|
|
686
|
+
import {
|
|
687
|
+
hasVariant,
|
|
688
|
+
DefaultFlexStack,
|
|
689
|
+
Stack,
|
|
690
|
+
PlasmicIcon,
|
|
691
|
+
} from "@plasmicapp/react-web";
|
|
692
|
+
import { StudioCtx } from "../../../StudioCtx";
|
|
693
|
+
import { observer } from "mobx-react-lite";
|
|
694
|
+
|
|
695
|
+
function _CodeSandboxDialogContent(props) {
|
|
696
|
+
return null;
|
|
697
|
+
}
|
|
698
|
+
`;
|
|
699
|
+
expect(replaced).toEqual(expectedCode);
|
|
700
|
+
});
|
|
701
|
+
it("Ts to js should not remove unused React", function () {
|
|
702
|
+
const input = `
|
|
703
|
+
/* eslint-disable */
|
|
704
|
+
/* tslint:disable */
|
|
705
|
+
/* prettier-ignore-start */
|
|
706
|
+
/** @jsx createPlasmicElementProxy */
|
|
707
|
+
// This class is auto-generated by Plasmic; please do not edit!
|
|
708
|
+
// Plasmic Project: aBwbYpvCqht4V3F8CJNJX3
|
|
709
|
+
// Component: 4SYnkOQLd5
|
|
710
|
+
import React, { ReactNode } from "react";
|
|
711
|
+
import {
|
|
712
|
+
hasVariant,
|
|
713
|
+
createPlasmicElement,
|
|
714
|
+
RenderOpts,
|
|
715
|
+
Override,
|
|
716
|
+
classNames,
|
|
717
|
+
Flex,
|
|
718
|
+
RenderFunc,
|
|
719
|
+
RenderFuncOverrides,
|
|
720
|
+
wrapWithClassName,
|
|
721
|
+
Renderer,
|
|
722
|
+
NodeRenderer,
|
|
723
|
+
createPlasmicElementProxy,
|
|
724
|
+
makeFragment,
|
|
725
|
+
PlasmicIcon,
|
|
726
|
+
PlasmicSlot,
|
|
727
|
+
MultiChoiceArg,
|
|
728
|
+
SingleBooleanChoiceArg,
|
|
729
|
+
SingleChoiceArg
|
|
730
|
+
} from "@plasmicapp/react-web";
|
|
731
|
+
|
|
732
|
+
import "@plasmicapp/react-web/lib/plasmic.css";
|
|
733
|
+
import "../plasmic__default_style.css"; // plasmic-import: global/defaultcss
|
|
734
|
+
import "./plasmic_plasmic_kit.css"; // plasmic-import: aBwbYpvCqht4V3F8CJNJX3/projectcss
|
|
735
|
+
import "./PlasmicButton.css"; // plasmic-import: 4SYnkOQLd5/css
|
|
736
|
+
import TrashIcon from "./PlasmicIcon__Trash"; // plasmic-import: wibhDXsBy/icon
|
|
737
|
+
|
|
738
|
+
export type PlasmicButton__VariantsArgs = {
|
|
739
|
+
type?: SingleChoiceArg<
|
|
740
|
+
| "primary"
|
|
741
|
+
| "secondary"
|
|
742
|
+
| "link"
|
|
743
|
+
| "backlitError"
|
|
744
|
+
| "backlitInfo"
|
|
745
|
+
| "chip"
|
|
746
|
+
| "toggleOn"
|
|
747
|
+
| "toggleOff"
|
|
748
|
+
| "clear"
|
|
749
|
+
>;
|
|
750
|
+
size?: SingleChoiceArg<"small" | "stretch" | "wide">;
|
|
751
|
+
withIcons?: SingleChoiceArg<"startIcon">;
|
|
752
|
+
disabled?: SingleBooleanChoiceArg<"disabled">;
|
|
753
|
+
font?: SingleChoiceArg<"bold">;
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
export type PlasmicButton__ArgsType = {
|
|
757
|
+
children?: ReactNode;
|
|
758
|
+
startIcon?: ReactNode;
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
function PlasmicButton(props: {}): ReactNode {
|
|
762
|
+
return <button></button>;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
function PlasmicButton2(props: {}): React.ReactNode {
|
|
766
|
+
return <button></button>;
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
export default PlasmicButton;
|
|
770
|
+
/* prettier-ignore-end */
|
|
771
|
+
`;
|
|
772
|
+
expect(code_utils_1.tsxToJsx(input).trim()).toEqual(`
|
|
773
|
+
/* eslint-disable */
|
|
774
|
+
/* tslint:disable */
|
|
775
|
+
/* prettier-ignore-start */
|
|
776
|
+
/** @jsx createPlasmicElementProxy */
|
|
777
|
+
// This class is auto-generated by Plasmic; please do not edit!
|
|
778
|
+
// Plasmic Project: aBwbYpvCqht4V3F8CJNJX3
|
|
779
|
+
// Component: 4SYnkOQLd5
|
|
780
|
+
import React from \"react\";
|
|
781
|
+
import { createPlasmicElementProxy } from "@plasmicapp/react-web";
|
|
782
|
+
import "@plasmicapp/react-web/lib/plasmic.css";
|
|
783
|
+
import "../plasmic__default_style.css"; // plasmic-import: global/defaultcss
|
|
784
|
+
import "./plasmic_plasmic_kit.css"; // plasmic-import: aBwbYpvCqht4V3F8CJNJX3/projectcss
|
|
785
|
+
import "./PlasmicButton.css"; // plasmic-import: 4SYnkOQLd5/css
|
|
786
|
+
function PlasmicButton(props) {
|
|
787
|
+
return <button></button>;
|
|
788
|
+
}
|
|
789
|
+
function PlasmicButton2(props) {
|
|
790
|
+
return <button></button>;
|
|
791
|
+
}
|
|
792
|
+
export default PlasmicButton;
|
|
793
|
+
/* prettier-ignore-end */`.trim());
|
|
794
|
+
});
|
|
795
|
+
it("formatJs should not add spaces to comment block", function () {
|
|
796
|
+
const input = `
|
|
797
|
+
import React, { ReactNode } from "react";
|
|
798
|
+
import "@plasmicapp/react-web/lib/plasmic.css";
|
|
799
|
+
|
|
800
|
+
function PlasmicButton(props: {}): React.ReactNode {
|
|
801
|
+
return <button></button>;
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
function forNode(name: keyof typeof PlasmicButton) {
|
|
805
|
+
const x = [1, 2].map(v => v > 1);
|
|
806
|
+
return null;
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
export default PlasmicButton;
|
|
810
|
+
|
|
811
|
+
// For debugging
|
|
812
|
+
/* plasmic-nameInIdToUuid/123
|
|
813
|
+
[{"1": 1""},
|
|
814
|
+
{"2" : "2}]
|
|
815
|
+
*/
|
|
816
|
+
`;
|
|
817
|
+
expect(code_utils_1.formatScript(input, process.cwd())).toEqual(`import React, { ReactNode } from "react";
|
|
818
|
+
import "@plasmicapp/react-web/lib/plasmic.css";
|
|
819
|
+
|
|
820
|
+
function PlasmicButton(props: {}): React.ReactNode {
|
|
821
|
+
return <button></button>;
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
function forNode(name: keyof typeof PlasmicButton) {
|
|
825
|
+
const x = [1, 2].map((v) => v > 1);
|
|
826
|
+
return null;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
export default PlasmicButton;
|
|
830
|
+
|
|
831
|
+
// For debugging
|
|
832
|
+
/* plasmic-nameInIdToUuid/123
|
|
833
|
+
[{"1": 1""},
|
|
834
|
+
{"2" : "2}]
|
|
835
|
+
*/
|
|
836
|
+
`);
|
|
837
|
+
});
|
|
838
|
+
});
|