Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
e0862d4
nextjs12
softmarshmallow Nov 2, 2021
db05e58
monaco extension with worker - wip
softmarshmallow Dec 28, 2021
af47fe7
add osm view tokenizer, webview placeholding file
softmarshmallow Apr 2, 2022
48744a1
wip
softmarshmallow Apr 5, 2022
820838a
add name matcher & test
softmarshmallow Apr 5, 2022
971f0cd
update name matcher to return matched name for sampling
softmarshmallow Apr 5, 2022
9af5166
bump base-sdk
softmarshmallow Apr 5, 2022
05a6ba5
add tests
softmarshmallow Apr 5, 2022
ae6830d
add vanilla preview build framework config - dedicated only for previ…
softmarshmallow Apr 5, 2022
27dff4b
cleanups
softmarshmallow Apr 5, 2022
c4a6cf1
move styled components building to sep file with new optimization dirs
softmarshmallow Apr 5, 2022
15c189d
add css duplication checker with name and style obj
softmarshmallow Apr 5, 2022
818642f
fix colu jsx attrs
softmarshmallow Apr 5, 2022
083a883
organized vanilla html builder with dups reduction support for non pr…
softmarshmallow Apr 5, 2022
d4053d8
add styles repository with proxy styles handling for optimization (du…
softmarshmallow Apr 5, 2022
e6b0899
add dups reduction support for styled-components (both react & rn), r…
softmarshmallow Apr 5, 2022
e20b2d7
add vanilla preview build to main d2c func
softmarshmallow Apr 5, 2022
6de36fc
swap preview users to use framework from `vanilla` to `preview`
softmarshmallow Apr 5, 2022
a6ea763
bumo!
softmarshmallow Apr 5, 2022
6d432fd
prereserve attributes even for proxied styled els
softmarshmallow Apr 5, 2022
cfbd0c8
Merge branch 'staging' of https://github.com/gridaco/designto-code in…
softmarshmallow Apr 5, 2022
d2b3152
Merge pull request #133 from gridaco/optimize-style/on-post-build
softmarshmallow Apr 5, 2022
ce33b09
Merge branch 'staging' of https://github.com/gridaco/designto-code in…
softmarshmallow Apr 5, 2022
6faa69f
update p-queue
softmarshmallow Apr 6, 2022
3398fdd
Merge branch 'staging' of https://github.com/gridaco/designto-code in…
softmarshmallow Apr 6, 2022
ce5d4b9
bump nextjs to 12x
softmarshmallow Apr 6, 2022
a19f628
Merge branch 'bump/editor-nextjs12' of https://github.com/gridaco/des…
softmarshmallow Apr 6, 2022
73a8e41
yarn
softmarshmallow Apr 6, 2022
57df4ed
bump webworkers
softmarshmallow Apr 6, 2022
f34db9d
Merge pull request #62 from gridaco/bump/editor-nextjs12
softmarshmallow Apr 6, 2022
65ef370
Merge branch 'staging' of https://github.com/gridaco/designto-code in…
softmarshmallow Apr 6, 2022
2f40dc6
bump monaco ver
softmarshmallow Apr 6, 2022
d1a0278
add prettier support & init monaco extended
softmarshmallow Apr 6, 2022
657bc93
clear logs
softmarshmallow Apr 6, 2022
5a07c61
init esbuild pkg
softmarshmallow Apr 6, 2022
886c5e0
add format on save
softmarshmallow Apr 6, 2022
54a93e5
Merge branch 'monaco-extended' of https://github.com/gridaco/designto…
softmarshmallow Apr 6, 2022
3544b4e
Merge pull request #104 from gridaco/monaco-extended
softmarshmallow Apr 6, 2022
a830883
Merge branch 'staging' of https://github.com/gridaco/designto-code in…
softmarshmallow Apr 6, 2022
68c22a5
yarn
softmarshmallow Apr 6, 2022
2b50ccb
rename pkg, add dev sandbox page
softmarshmallow Apr 6, 2022
4b11eb7
add runner loading indicator
softmarshmallow Apr 6, 2022
7236b29
dev: add realtime compiler - on each change
softmarshmallow Apr 6, 2022
66901e7
complete dev sandbox
softmarshmallow Apr 6, 2022
0cae61a
fix cb
softmarshmallow Apr 6, 2022
2079f11
add vanilla esbuild runner comp
softmarshmallow Apr 6, 2022
98514b6
add null safety
softmarshmallow Apr 6, 2022
849907e
quick & dirty implementation of interactive scripting - react esbuild
softmarshmallow Apr 6, 2022
19ab72b
small improvements
softmarshmallow Apr 6, 2022
5b21005
fix play button pointer issue
softmarshmallow Apr 6, 2022
74f52e9
rm obsolete scripts & packages
softmarshmallow Apr 6, 2022
c888ba7
Merge branch 'staging' of https://github.com/gridaco/designto-code in…
softmarshmallow Apr 6, 2022
7c0e92c
add default style to esbuild vanilla runner
softmarshmallow Apr 6, 2022
38d19f4
add rename on cmdcrl+r
softmarshmallow Apr 8, 2022
ca3eee0
add dartlang formatting support for monaco (without webworkers)
softmarshmallow Apr 8, 2022
67190fd
rm dart formatting from ui side
softmarshmallow Apr 8, 2022
3baf2d4
made editor panels resizable
softmarshmallow Apr 8, 2022
eb65a77
made editor panels size dynamic
softmarshmallow Apr 8, 2022
95c72e3
add minwidth to codeview
softmarshmallow Apr 8, 2022
e808d1d
rm dart format package
softmarshmallow Apr 8, 2022
ffa4d39
move prettier service to external package
softmarshmallow Apr 8, 2022
8d2428e
qf
softmarshmallow Apr 8, 2022
1a8f2a2
Merge pull request #135 from gridaco/support-local-esbuild
softmarshmallow Apr 8, 2022
463578d
extract jsx-syntax-highlight to editor-packages
softmarshmallow Apr 8, 2022
a7e5afc
mv p-queue dependency map
softmarshmallow Apr 8, 2022
e89be4f
exact match esbuild wasm version
softmarshmallow Apr 8, 2022
3e7f97f
disable user-select on sidebar, canvas
softmarshmallow Apr 9, 2022
0f69ab8
fix dependency version mapping
softmarshmallow Apr 9, 2022
4a0b8d5
add esbuild error logging
softmarshmallow Apr 9, 2022
95660a8
clean warning loggings
softmarshmallow Apr 9, 2022
858f26a
fix partof component tree - react invalid hook call issue
softmarshmallow Apr 9, 2022
10c1339
disabled experimental components support
softmarshmallow Apr 9, 2022
75e9e9f
cleanup editor state tree
softmarshmallow Apr 9, 2022
3bb01e3
extract d2c main function input as type
softmarshmallow Apr 10, 2022
544c956
extract get target container func from hook
softmarshmallow Apr 10, 2022
4ec6d32
add preview actions
softmarshmallow Apr 10, 2022
1c4c2be
add preview reducers
softmarshmallow Apr 10, 2022
535fce9
add dynamic vanilla preview renderer
softmarshmallow Apr 10, 2022
e293e0e
update editor state with global preview data
softmarshmallow Apr 10, 2022
2cc5cf0
add editor preview provider
softmarshmallow Apr 10, 2022
794250d
update preview user (isolated mode, fullscreen view) with use editor …
softmarshmallow Apr 10, 2022
290717c
yarn & cleanup
softmarshmallow Apr 10, 2022
3b9ec5f
dangerously prevent change event from formatter
softmarshmallow Apr 10, 2022
2de0c93
add reason meta to preview data
softmarshmallow Apr 10, 2022
2dd397a
add query routing for exit full screen
softmarshmallow Apr 10, 2022
32f889a
prevent isolated view canvas from redrawing when exit full screen (ch…
softmarshmallow Apr 10, 2022
3b9232b
update initial sizing issue on esbuild result dispatch
softmarshmallow Apr 10, 2022
6155b95
disabled inspection in fullscreen mode
softmarshmallow Apr 10, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ export function CanvasEventTarget({
overflow: "hidden",
touchAction: "none",
cursor: isSpacebarPressed ? "grab" : "default",
userSelect: "none",
WebkitUserSelect: "none",
}}
id="gesture-event-listener"
ref={interactionEventTargetRef}
Expand Down
6 changes: 6 additions & 0 deletions editor-packages/editor-services-dart/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@code-editor/dart-services",
"description": "dart build services for flutter framework",
"version": "0.0.0",
"private": false
}
5 changes: 5 additions & 0 deletions editor-packages/editor-services-esbuild/contributing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# About esbuild-wasm version.

The wasm file downloaded over network must match the locally installed esbuild-wasm package, so always use exact version. (not ^v, ^v0.0.0, etc.)

currently using `0.14.34`
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.out.js
78 changes: 78 additions & 0 deletions editor-packages/editor-services-esbuild/fetch.plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { OnLoadResult, PluginBuild } from "esbuild-wasm";
import axios from "axios";
import localforage from "localforage";
import { normalizeCss } from ".";

const fileCache = localforage.createInstance({
name: "filecache",
});

export const fetchPlugin = (
inputCode: string,
lang: OnLoadResult["loader"]
) => ({
name: "fetch-plugin",

setup(build: PluginBuild) {
build.onLoad({ filter: /^index\.js$/ }, () => {
return {
loader: lang,
contents: inputCode,
};
});

build.onLoad({ filter: /.*/ }, async (args: any) => {
/**
* Check if module is already in filecache
* if yes? return it immediately
*
* if not, fetch it from unpkg and cache it
* and return the result
*/
const cachedResult = await fileCache.getItem<OnLoadResult>(args.path);

if (cachedResult) {
return cachedResult;
}

return null;
});

build.onLoad({ filter: /.css$/ }, async (args: any) => {
const { data, request } = await axios.get(args.path);

const contents = normalizeCss(data);

const result: OnLoadResult = {
loader: "jsx",
contents,
resolveDir: new URL("./", request.responseURL).pathname,
};

await fileCache.setItem(args.path, result);

return result;
});

build.onLoad({ filter: /.*/ }, async (args: any) => {
const { data, request } = await axios.get(args.path);

const result: OnLoadResult = {
loader: "jsx",
contents: data,
resolveDir: new URL("./", request.responseURL).pathname,
};

await fileCache.setItem(args.path, result);

return result;
});
},
});

// const libSource = ReactTypes.toString()

// const libUri = "ts:filename/facts.d.ts";
// monaco.languages.typescript.javascriptDefaults.addExtraLib(libSource, libUri);

// monaco.editor.createModel(libSource, "typescript", monaco.Uri.parse(libUri));
120 changes: 120 additions & 0 deletions editor-packages/editor-services-esbuild/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { Monaco } from "@monaco-editor/react";
import { nanoid } from "nanoid";
import { build, initialize, Loader } from "esbuild-wasm";
import { fetchPlugin } from "./fetch.plugin";
import { unpkgPathPlugin } from "./unpkg-path.plugin";

declare const window: {
monaco: Monaco;
};

let serviceLoaded: boolean | null = null;

const bundler = async (rawCode: string, lang: Loader) => {
if (!serviceLoaded) {
await initialize({
wasmURL: "https://unpkg.com/esbuild-wasm@0.14.34/esbuild.wasm",
worker: true,
});
console.log("esbuild-wasm initialized");
serviceLoaded = true;
}

try {
const result = await build({
entryPoints: ["index.js"],
bundle: true,
write: false,
metafile: true,
legalComments: "none",
plugins: [unpkgPathPlugin(), fetchPlugin(rawCode, lang)],
define: {
"process.env.NODE_ENV": `"production"`,
global: "window",
},
});

const imports = result.metafile?.inputs["a:index.js"].imports
.map((el) => el.path.replace("a:https://unpkg.com/", ""))
.filter((e) => !e.includes("/"));

loadTypes(imports);

// console.log("esbuild result: ", result);

return { code: result.outputFiles[0].text, err: null };
} catch (error: any) {
console.error("esbuild error: ", error);
return {
code: null,
err: { method: "error", data: [error.message], id: nanoid() },
};
}
};

export const normalizeCss = (data: string) => {
/**
* Function to remove any new lines, quotes from imported css packages.
*/
const escaped = data
.replace(/\n/g, "")
.replace(/"/g, '\\"')
.replace(/'/g, "\\'");
return `const style = document.createElement('style')
style.innerText = '${escaped}';
document.head.appendChild(style)`;
};

export default bundler;

let typesWorker;

const loadTypes = (types) => {
const disposables: any = [];
const monaco = window && window.monaco;

const dependencies = types.map((e) => ({ name: e, version: "latest" })) || [];

if (!typesWorker) {
typesWorker = new Worker(
new URL("./workers/fetch-types.worker.js", import.meta.url)
);
}

dependencies.forEach((dep) => {
typesWorker.postMessage({
name: dep.name,
version: dep.version,
});
});

typesWorker.addEventListener("message", (event) => {
// name,
// version,
// typings: result,
const key = `node_modules/${event.data.name}/index.d.ts`;
const source = event.data.typings[key];

// const path = `${MONACO_LIB_PREFIX}${event.data.name}`;
const libUri = `file:///node_modules/@types/${event.data.name}/index.d.ts`;

disposables.push(
monaco.languages.typescript.javascriptDefaults.addExtraLib(source, libUri)
);
disposables.push(
monaco.languages.typescript.typescriptDefaults.addExtraLib(source, libUri)
);

// When resolving definitions and references, the editor will try to use created models.
// Creating a model for the library allows "peek definition/references" commands to work with the library.
});

return {
dispose() {
disposables.forEach((d) => d.dispose());
if (typesWorker) {
typesWorker.terminate();
}
},
};
};
14 changes: 14 additions & 0 deletions editor-packages/editor-services-esbuild/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "@code-editor/esbuild-services",
"version": "0.0.0",
"private": false,
"dependencies": {
"esbuild-wasm": "0.14.34",
"localforage": "^1.10.0"
},
"peerDependencies": {
"@monaco-editor/react": "^4.4.1",
"axios": "^0.26.1",
"nanoid": "^3.3.2"
}
}
36 changes: 36 additions & 0 deletions editor-packages/editor-services-esbuild/unpkg-path.plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { PluginBuild } from "esbuild-wasm";

const unpkg_path = "https://unpkg.com";

export const unpkgPathPlugin = () => ({
name: "unpkg-path-plugin",
setup(build: PluginBuild) {
/**
* Resolve the entry file eg. `index.js`
*/
build.onResolve({ filter: /^index\.js$/ }, (args: any) => {
return { path: args.path, namespace: "a" };
});

/**
* Resolve relative modules imports
*/
build.onResolve({ filter: /^\.+\// }, (args: any) => {
const url = new URL(args.path, unpkg_path + args.resolveDir + "/").href;
return {
namespace: "a",
path: url,
};
});

/**
* Resolve main module files
*/
build.onResolve({ filter: /.*/ }, async (args: any) => {
return {
namespace: "a",
path: new URL(args.path, unpkg_path + "/").href,
};
});
},
});
Loading