Skip to content

Commit 52948a4

Browse files
authored
[docs-theme]: Replace codesandbox dependency with lz-string (#7547)
1 parent 7d1784d commit 52948a4

File tree

4 files changed

+59
-1824
lines changed

4 files changed

+59
-1824
lines changed

packages/docs-theme/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
"@blueprintjs/select": "workspace:^",
3838
"@documentalist/client": "^5.0.0",
3939
"classnames": "^2.3.1",
40-
"codesandbox": "^2.2.3",
4140
"fuzzaldrin-plus": "^0.6.0",
41+
"lz-string": "^1.5.0",
4242
"tslib": "~2.6.2"
4343
},
4444
"peerDependencies": {

packages/docs-theme/src/common/sandbox.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@
44

55
/* eslint-disable sort-keys */
66

7+
import LZString from "lz-string";
8+
9+
export interface Files {
10+
[key: string]: {
11+
content: string;
12+
isBinary: boolean;
13+
};
14+
}
15+
16+
function compress(input: string) {
17+
return LZString.compressToBase64(input)
18+
.replace(/\+/g, `-`) // Convert '+' to '-'
19+
.replace(/\//g, `_`) // Convert '/' to '_'
20+
.replace(/=+$/, ``); // Remove ending '='
21+
}
22+
23+
// source: https://github.com/codesandbox/codesandbox-importers/blob/d077bdf/packages/import-utils/src/api/define.ts
24+
export function getParameters(parameters: { files: Files }) {
25+
return compress(JSON.stringify(parameters));
26+
}
27+
728
const BLUEPRINT_PACKAGE_MAP: Record<string, { package: string; css?: string[] }> = {
829
"@blueprintjs/core": {
930
package: "@blueprintjs/core",

packages/docs-theme/src/components/codeExample.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@
33
*/
44

55
import classNames from "classnames";
6-
import { getParameters } from "codesandbox/lib/api/define";
76
import { useCallback, useState } from "react";
87

98
import { Button, Classes, Pre, Tooltip } from "@blueprintjs/core";
109

1110
import { useTheme } from "../common";
1211
import { DOCS_CODE_BLOCK } from "../common/classes";
13-
import { analyzeCode, getHtml, getIndex, getpackageJson, getStyles, getTsconfig } from "../common/sandbox";
12+
import {
13+
analyzeCode,
14+
getHtml,
15+
getIndex,
16+
getpackageJson,
17+
getParameters,
18+
getStyles,
19+
getTsconfig,
20+
} from "../common/sandbox";
1421

1522
export interface CodeExampleProps {
1623
children?: React.ReactNode;

0 commit comments

Comments
 (0)