Skip to content

Commit d24980e

Browse files
committed
feat: custom keyboard shortcuts
1 parent 6a1701f commit d24980e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+654
-593
lines changed

client/packages/create-openblocks-comps/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,22 @@ async function createProject(projectName, options) {
120120
const initialPackageJson = {
121121
name: projectName,
122122
version: "0.0.1",
123+
type: "module",
124+
license: "MIT",
123125
};
124126
writePackageJson(packageJsonFile, initialPackageJson);
125127
console.log("initial package.json generated");
126128

127-
await install([cliPackageName, sdkPackageName]);
129+
await install([
130+
cliPackageName,
131+
sdkPackageName,
132+
"openblocks-design",
133+
"openblocks-core",
134+
"react@17",
135+
"react-dom@17",
136+
"@types/react@17",
137+
"@types/react-dom@17",
138+
]);
128139

129140
await executeNodeScript(
130141
{
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "create-openblocks-comps",
3-
"version": "0.0.3",
3+
"version": "0.0.7",
44
"bin": "./index.js",
55
"type": "module",
66
"dependencies": {
77
"chalk": "4",
88
"commander": "^9.4.1",
99
"fs-extra": "^10.1.0",
10-
"openblocks-dev-utils": "0.0.1"
10+
"openblocks-dev-utils": "workspace:^"
1111
}
1212
}

client/packages/openblocks-cli/ide/index.html renamed to client/packages/openblocks-cli-template-typescript/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
<div id="root">
2222
<div id="root-loader">Loading...</div>
2323
</div>
24-
<script src="index.jsx" type="module"></script>
24+
<script src="index.tsx" type="module"></script>
2525
</body>
2626
</html>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import ReactDOM from "react-dom";
2+
import { CompIDE } from "openblocks-sdk";
3+
import { name, version, openblocks } from "./package.json";
4+
import compMap from "./src/index";
5+
6+
import "openblocks-sdk/dist/style.css";
7+
8+
function CompDevApp() {
9+
return (
10+
<CompIDE
11+
compMap={compMap}
12+
packageName={name}
13+
packageVersion={version}
14+
compMeta={openblocks.comps}
15+
/>
16+
);
17+
}
18+
19+
ReactDOM.render(<CompDevApp />, document.querySelector("#root"));
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"name": "openblocks-cli-template-typescript",
3-
"version": "0.0.2",
3+
"version": "0.0.9",
4+
"type": "module",
45
"scripts": {
5-
"start": "openblocks-cli start",
6+
"start": "vite",
67
"build": "openblocks-cli build"
78
},
89
"openblocks": {
@@ -14,11 +15,11 @@
1415
}
1516
}
1617
},
17-
"dependencies": {
18+
"devDependencies": {
1819
"openblocks-cli": "workspace:^",
19-
"openblocks-sdk": "workspace:^"
20+
"openblocks-sdk": "workspace:^",
21+
"typescript": "^4.8.4",
22+
"vite": "^3.2.4"
2023
},
21-
"devDependencies": {
22-
"typescript": "^4.8.4"
23-
}
24+
"license": "MIT"
2425
}

client/packages/openblocks-cli-template-typescript/src/HelloWorldComp.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Button } from "antd";
21
import {
2+
antd,
33
UICompBuilder,
44
numberExposingStateControl,
55
Section,
@@ -11,6 +11,8 @@ import {
1111
withMethodExposing,
1212
} from "openblocks-sdk";
1313

14+
const { Button } = antd;
15+
1416
const childrenMap = {
1517
value: numberExposingStateControl("value", 10),
1618
step: withDefault(NumberControl, 1),

client/packages/openblocks-cli-template-typescript/tsconfig.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,17 @@
1818
"jsx": "react-jsx",
1919
"baseUrl": "src",
2020
"paths": {
21+
"openblocks-sdk": [
22+
"../../openblocks/src/index.sdk.ts",
23+
"../node_modules/openblocks-sdk/src/openblocks/index.sdk.ts"
24+
],
2125
"*": [
2226
"*",
2327
"../../openblocks/src/*",
2428
"../../openblocks-sdk/src/*",
25-
"../node_modules/openblocks-sdk/src/*"
29+
"../node_modules/openblocks-sdk/src/openblocks/*"
2630
]
2731
}
2832
},
29-
"include": ["src"]
33+
"include": ["src", "index.tsx"]
3034
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import config from "openblocks-cli/config/vite.config";
2+
export default {
3+
...config,
4+
server: {
5+
open: true,
6+
port: 9000,
7+
},
8+
};

client/packages/openblocks-cli/actions/build.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { build } from "vite";
44
import { writeFileSync, existsSync, readFileSync } from "fs";
55
import { resolve } from "path";
66
import paths from "../config/paths.js";
7-
import viteConfig from "../config/vite.config.js";
8-
import { logBug } from "../util/log.js";
7+
import "../util/log.js";
98

109
const { copySync } = fsExtra;
1110
const packageJSON = JSON.parse(readFileSync(paths.appPackageJson).toString());
@@ -74,8 +73,8 @@ export default async function buildAction(options) {
7473
console.log("");
7574
console.cyan("Building...");
7675

77-
const output = await build(viteConfig);
78-
console.log(output);
76+
const viteConfig = await import(paths.appViteConfigJs).default;
77+
await build(viteConfig);
7978

8079
// write package.json
8180
packageJSON.openblocks.entry = "index.js";

client/packages/openblocks-cli/actions/init.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ export default async function initAction(options) {
7676

7777
appPackageJson.openblocks = templatePackageJson.openblocks || {};
7878
appPackageJson.scripts = {
79-
start: "openblocks-cli start",
79+
start: "vite",
8080
build: "openblocks-cli build",
8181
};
8282
fs.writeFileSync(paths.appPackageJson, JSON.stringify(appPackageJson, null, 2));
8383
console.log("package.json updated");
8484

85-
const notCopiedFiles = ["package.json", "README.md", "README-template.md"];
85+
const notCopiedFiles = ["package.json", "README.md", "README-template.md", "node_modules"];
8686
fs.copySync(templateDir, "./", {
87-
filter: (src) => notCopiedFiles.every((i) => !src.endsWith(i)),
87+
filter: (src) => notCopiedFiles.every((i) => !src.startsWith(`${templateDir}/${i}`)),
8888
});
8989
fs.copyFile(`${templateDir}/README-template.md`, "./README.md");
9090
console.log("template files copied");

client/packages/openblocks-cli/actions/start.js

Lines changed: 0 additions & 15 deletions
This file was deleted.

client/packages/openblocks-cli/client.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ declare var REACT_APP_ENV: string;
3434
declare var REACT_APP_BUILD_ID: string;
3535
declare var REACT_APP_LOG_LEVEL: string;
3636
declare var REACT_APP_IMPORT_MAP: string;
37+
declare var REACT_APP_SERVER_IPS: string;

client/packages/openblocks-cli/config/paths.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ const paths = {
4545
appPackageJson: resolveApp("package.json"),
4646
appSrc: resolveApp("src"),
4747
appLocales: resolveApp("locales"),
48-
appIndexJs: resolveModule(resolveOwn, "ide/index"),
4948
compsIndexJs: resolveModule(resolveApp, "src/index"),
49+
appViteConfigJs: resolveModule(resolveApp, "vite.config"),
5050
appTsConfig: resolveApp("tsconfig.json"),
5151
yarnLockFile: resolveApp("yarn.lock"),
5252
appNodeModules: resolveApp("node_modules"),

client/packages/openblocks-cli/config/vite.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ buildVars.forEach(({ name, defaultValue }) => {
1212

1313
export default defineConfig({
1414
define,
15-
root: paths.appRoot,
1615
assetsInclude: ["**/*.md"],
1716
resolve: {
1817
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"],

client/packages/openblocks-cli/ide/index.jsx

Lines changed: 0 additions & 8 deletions
This file was deleted.

client/packages/openblocks-cli/index.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import("./util/log.js");
44
import fs from "node:fs";
55
import { Command } from "commander";
6-
import startAction from "./actions/start.js";
76
import initAction from "./actions/init.js";
87
import buildAction from "./actions/build.js";
98

@@ -19,13 +18,6 @@ program
1918
.option("--registry [addr]", "npm registry")
2019
.action(initAction);
2120

22-
program
23-
.command("start")
24-
.description("start dev server to preview")
25-
.option("--port", "server port", "9000")
26-
.option("--host", "server host", "127.0.0.1")
27-
.action(startAction);
28-
2921
program
3022
.command("build")
3123
.description("build component lib")
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
"name": "openblocks-cli",
33
"description": "CLI tool used to start build publish openblocks components",
4-
"version": "0.0.5",
4+
"version": "0.0.14",
55
"bin": "./index.js",
66
"type": "module",
77
"exports": {
88
".": {
99
"import": "./index.js",
1010
"require": "./index.js"
1111
},
12+
"./config/vite.config": {
13+
"import": "./config/vite.config.js",
14+
"require": "./config/vite.config.js"
15+
},
1216
"./client": {
1317
"types": "./client.d.ts"
1418
},
@@ -18,24 +22,23 @@
1822
}
1923
},
2024
"dependencies": {
21-
"@svgr/webpack": "^6.5.0",
25+
"@vitejs/plugin-react": "^2.2.0",
2226
"axios": "^1.1.3",
2327
"chalk": "4",
2428
"commander": "^9.4.1",
25-
"file-loader": "^6.2.0",
2629
"fs-extra": "^10.1.0",
27-
"html-webpack-plugin": "^5.5.0",
2830
"openblocks-dev-utils": "workspace:^",
31+
"react": "^17",
32+
"react-dom": "^17",
2933
"react-json-view": "^1.21.3",
30-
"vite": "^3.2.3"
34+
"vite": "^3.2.4",
35+
"vite-plugin-svgr": "^2.2.2"
3136
},
3237
"devDependencies": {
3338
"@types/axios": "^0.14.0",
3439
"typescript": "^4.8.4"
3540
},
3641
"peerDependencies": {
37-
"openblocks-sdk": "*",
38-
"react": "^17.0.2",
39-
"react-dom": "^17.0.2"
42+
"openblocks-sdk": "*"
4043
}
4144
}

client/packages/openblocks-core/lib/index.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ function changeDependName(unevaledValue, oldName, name, isFunction) {
546546
}
547547
function rename(segment, oldName, name) {
548548
var accessors = [".", "["];
549-
var regStrList = ["[a-zA-Z_$][a-zA-Z_$0-9.[\\]]*", "(?<=\\[)[a-zA-Z_][a-zA-Z_0-9.]*"];
549+
var regStrList = ["[a-zA-Z_$][a-zA-Z_$0-9.[\\]]*", "\\[[a-zA-Z_][a-zA-Z_0-9.]*"];
550550
var ret = segment;
551551
for (var _i = 0, regStrList_1 = regStrList; _i < regStrList_1.length; _i++) {
552552
var regStr = regStrList_1[_i];
@@ -555,12 +555,25 @@ function rename(segment, oldName, name) {
555555
if (s === oldName) {
556556
return name;
557557
}
558+
var origin = oldName;
559+
var target = name;
560+
var matched = false;
561+
if (s.startsWith("[".concat(origin))) {
562+
origin = "[".concat(origin);
563+
target = "[".concat(name);
564+
matched = true;
565+
}
558566
for (var _i = 0, accessors_1 = accessors; _i < accessors_1.length; _i++) {
559567
var accessor = accessors_1[_i];
560-
if (s.startsWith(oldName + accessor)) {
561-
return name + accessor + s.substring(oldName.length + accessor.length);
568+
if (s.startsWith(origin + accessor)) {
569+
matched = true;
570+
target = target + accessor + s.substring(origin.length + accessor.length);
571+
break;
562572
}
563573
}
574+
if (matched) {
575+
return target;
576+
}
564577
return s;
565578
});
566579
}

client/packages/openblocks-core/src/eval/utils/evaluate.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function changeDependName(
8686

8787
function rename(segment: string, oldName: string, name: string) {
8888
const accessors = [".", "["];
89-
const regStrList = ["[a-zA-Z_$][a-zA-Z_$0-9.[\\]]*", "(?<=\\[)[a-zA-Z_][a-zA-Z_0-9.]*"];
89+
const regStrList = ["[a-zA-Z_$][a-zA-Z_$0-9.[\\]]*", "\\[[a-zA-Z_][a-zA-Z_0-9.]*"];
9090

9191
let ret = segment;
9292
for (const regStr of regStrList) {
@@ -95,11 +95,28 @@ function rename(segment: string, oldName: string, name: string) {
9595
if (s === oldName) {
9696
return name;
9797
}
98+
let origin = oldName;
99+
let target = name;
100+
let matched = false;
101+
102+
if (s.startsWith(`[${origin}`)) {
103+
origin = `[${origin}`;
104+
target = `[${name}`;
105+
matched = true;
106+
}
107+
98108
for (const accessor of accessors) {
99-
if (s.startsWith(oldName + accessor)) {
100-
return name + accessor + s.substring(oldName.length + accessor.length);
109+
if (s.startsWith(origin + accessor)) {
110+
matched = true;
111+
target = target + accessor + s.substring(origin.length + accessor.length);
112+
break;
101113
}
102114
}
115+
116+
if (matched) {
117+
return target;
118+
}
119+
103120
return s;
104121
});
105122
}

client/packages/openblocks-design/src/components/Input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import _ from "lodash";
66
import React from "react";
77
import { INPUT_DEFAULT_ONCHANGE_DEBOUNCE } from "constants/perf";
88

9-
const StyledInput = styled(AntdInput)`
9+
export const StyledInput = styled(AntdInput)`
1010
width: ${(props) => (props.width ? props.width : "100%")};
1111
background: #fdfdfd;
1212
border: 1px solid ${BorderColor};

0 commit comments

Comments
 (0)