Skip to content

Commit 669b379

Browse files
author
FalkWolsky
committed
plugin creator fix dependencies
1 parent 756b294 commit 669b379

File tree

4 files changed

+47
-23
lines changed

4 files changed

+47
-23
lines changed

client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"lint-staged": "^13.0.1",
5353
"lowcoder-dev-utils": "workspace:^",
5454
"mq-polyfill": "^1.1.8",
55-
"prettier": "3.1.0",
55+
"prettier": "^3.1.0",
5656
"rimraf": "^3.0.2",
5757
"rollup": "^2.79.0",
5858
"shelljs": "^0.8.5",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
// Comments are supported, like tsconfig.json
3+
"entryPoints": ["src/index.ts"],
4+
"out": "docs"
5+
}

client/packages/lowcoder/src/base/codeEditor/autoFormat.tsx

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@ import { Language } from "./codeEditorTypes";
66

77
export async function cssFormatter(text: string) {
88
const prettier = await import("prettier/standalone");
9-
const parserPlugin = await import("prettier/parser-postcss");
10-
return prettier.format(text, { parser: "css", plugins: [parserPlugin], semi: false }).trim();
9+
const parserPlugin = await require("prettier/parser-postcss");
10+
return (await prettier.format(text, { parser: "css", plugins: [parserPlugin], semi: false })).trim();
1111
}
1212

1313
export async function htmlFormatter(text: string) {
1414
const prettier = await import("prettier/standalone");
15-
const parserPlugin = await import("prettier/parser-html");
16-
return prettier.format(text, { parser: "html", plugins: [parserPlugin], semi: false }).trim();
15+
const parserPlugin = await require("prettier/parser-html");
16+
return (await prettier.format(text, { parser: "html", plugins: [parserPlugin], semi: false })).trim();
1717
}
1818

1919
async function getJavascriptFormatter() {
2020
const prettier = await import("prettier/standalone");
21-
const parserBabel = await import("prettier/parser-babel");
22-
return (text: string) =>
23-
prettier.format(text, { parser: "babel", plugins: [parserBabel], semi: false }).trim();
21+
const parserBabel = await require("prettier/parser-babel");
22+
return async (text: string) =>
23+
(await prettier.format(text, { parser: "babel", plugins: [parserBabel], semi: false })).trim();
2424
}
2525

2626
export async function getJsonFormatter() {
2727
const prettier = await import("prettier/standalone");
28-
const parserBabel = await import("prettier/parser-babel");
29-
return (text: string) => prettier.format(text, { parser: "json", plugins: [parserBabel] }).trim();
28+
const parserBabel = await require("prettier/parser-babel");
29+
return async (text: string) => (await prettier.format(text, { parser: "json", plugins: [parserBabel] })).trim();
3030
}
3131

32-
function formatJsSegment(formatter: (text: string) => string, script: string) {
32+
async function formatJsSegment(formatter: (text: string) => Promise<string>, script: string): Promise<string> {
3333
try {
34-
const s = formatter(script);
34+
const s = await formatter(script);
3535
return s.startsWith(";") ? s.slice(1) : s;
3636
} catch (e1) {
3737
try {
38-
const s = formatter(`return (${script}\n);`); // same as evalScript()
38+
const s = await formatter(`return (${script}\n);`); // same as evalScript()
3939
return s.startsWith("return ") ? s.slice(7) : s;
4040
} catch (e2) {
4141
throw e1;
@@ -45,7 +45,9 @@ function formatJsSegment(formatter: (text: string) => string, script: string) {
4545

4646
async function getJsSegmentFormatter() {
4747
const formatter = await getJavascriptFormatter();
48-
return (segment: string) => "{{" + formatJsSegment(formatter, segment.slice(2, -2)) + "}}";
48+
return async (segment: string) => {
49+
return "{{" + formatJsSegment(formatter, segment.slice(2, -2)) + "}}";
50+
};
4951
}
5052

5153
export async function formatStringWithJsSnippets(text: string): Promise<string> {
@@ -75,15 +77,27 @@ export async function formatSqlWithJsSnippets(text: string) {
7577
if (jsSegments.length === 0) {
7678
return newText;
7779
}
78-
return newText.replace(/{ { \d+ } }/g, (s) => {
80+
const replacements: Promise<string>[] = [];
81+
const replacedText = newText.replace(/{ { \d+ } }/g, (s) => {
7982
const index = parseInt(s.slice(4, -4));
8083
if (index >= 0 && index < jsSegments.length) {
81-
return jsSegmentFormatter(jsSegments[index]);
84+
const replacement = jsSegmentFormatter(jsSegments[index]);
85+
replacements.push(replacement);
86+
return s; // Return the original placeholder for now
8287
}
8388
return s;
8489
});
90+
91+
const formattedSegments = await Promise.all(replacements);
92+
let finalText = replacedText;
93+
formattedSegments.forEach((formattedSegment, index) => {
94+
finalText = finalText.replace(`{ { ${index} } }`, formattedSegment);
95+
});
96+
97+
return finalText;
8598
}
8699

100+
87101
async function formatJsonWithJsSnippetsImpl(text: string) {
88102
if (!text || text.trim().length === 0) {
89103
return "";
@@ -108,15 +122,20 @@ async function formatJsonWithJsSnippetsImpl(text: string) {
108122
// here are 3 cases.
109123
// - when the original "{{}}" is not in quotes as the single key or value, the whole "{{ index }}" should be replaced.
110124
// - when the original "{{}}" is for concatenating strings, "{{ index }}" or "\\{\\{ index \\}\\}" should be replaced.
111-
return formattedJSON.replace(/("{{\d+}}")|({{\d+}})|(\\\\{\\\\{\d+\\\\}\\\\})/g, (s) => {
125+
const formattedSegments = await Promise.all(segments.map(async (segment) => {
126+
if (isDynamicSegment(segment)) {
127+
const formattedSegment = await jsSegmentFormatter(segment);
128+
return formattedSegment;
129+
}
130+
return segment;
131+
}));
132+
133+
return (await formattedJSON).replace(/("{{\d+}}")|({{\d+}})|(\\\\{\\\\{\d+\\\\}\\\\})/g, (s) => {
112134
const index = parseInt(
113135
s.startsWith('"{{') ? s.slice(3, -3) : s.startsWith("{{") ? s.slice(2, -2) : s.slice(6, -6)
114136
);
115-
if (index >= 0 && index < segments.length) {
116-
const segment = segments[index];
117-
if (isDynamicSegment(segment)) {
118-
return jsSegmentFormatter(segment);
119-
}
137+
if (index >= 0 && index < formattedSegments.length) {
138+
return formattedSegments[index];
120139
}
121140
return s;
122141
});

client/packages/lowcoder/src/pages/tutorials/tutorialsConstant.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const editorContentClassName = "joyride-editor-content";
88
export const tableDataDivClassName = "joyride-table-data-div";
99
export const editorBottomClassName = "joyride-editor-bottom";
1010

11-
export const defaultJoyrideStyles: Styles = {
11+
export const defaultJoyrideStyles: Partial<Styles> = {
1212
options: {
1313
arrowColor: "#4965F2",
1414
overlayColor: "rgba(0, 0, 0, 0.4)",

0 commit comments

Comments
 (0)