Skip to content

Commit

Permalink
feat: json editor
Browse files Browse the repository at this point in the history
  • Loading branch information
morlay committed Aug 7, 2024
1 parent ccc4d7a commit 4cf5364
Show file tree
Hide file tree
Showing 55 changed files with 2,315 additions and 568 deletions.
Binary file modified bun.lockb
Binary file not shown.
14 changes: 6 additions & 8 deletions nodedevpkg/vue-vite-presets/src/chunkCleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export const chunkCleanup = (
exclude?: string[];
include?: string[];
};
} = {}
} = {},
): Plugin => {
const isJSOrLike = createFilter([
/\.vue$/,
/\.mdx$/,
/\.tsx?$/,
/\.mjs$/,
/\.jsx?$/
/\.jsx?$/,
]);

return {
Expand Down Expand Up @@ -50,13 +50,13 @@ export const chunkCleanup = (
const result = await transform(code, {
filename: id,
env: opt.env ?? { targets: "defaults" },
minify: false
minify: false,
});

return (
result.code && {
code: result.code,
map: result.map || null
map: result.map || null,
}
);
},
Expand All @@ -65,11 +65,9 @@ export const chunkCleanup = (
return (
await transform(code, {
minify: opt.minify ?? false,
plugins: [
usePlugin({})
]
plugins: [usePlugin({})],
})
).code;
}
},
};
};
50 changes: 25 additions & 25 deletions nodedevpkg/vue-vite-presets/src/mdx/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,31 +43,31 @@ export const mdx = (): PluginOption => {
const rawCode = children[0].value;

const exportName = `CodeBlock${getHash(
`${metadata["filename"] ?? pos}`
`${metadata["filename"] ?? pos}`,
)}`;

const id = vc.store(`${mdxFile}~${exportName}.tsx`, rawCode);

additionalImports.set(mdxFile, {
...(additionalImports.get(mdxFile) ?? {}),
[id]: exportName
[id]: exportName,
});

tree.children[pos] = h(
"div",
{
"data-example": ""
"data-example": "",
},
[
h(
"div",
{
"data-example-container": ""
"data-example-container": "",
},
h(exportName)
h(exportName),
),
pre
]
pre,
],
);
}
}
Expand All @@ -80,7 +80,7 @@ export const mdx = (): PluginOption => {
include: [/\.mdx?$/],
jsxRuntime: "automatic",
jsxImportSource: "@innoai-tech/vuekit",
rehypePlugins: [rehypeRenderCodeBlock, rehypePrism]
rehypePlugins: [rehypeRenderCodeBlock, rehypePrism],
});

return {
Expand Down Expand Up @@ -114,36 +114,36 @@ export const mdx = (): PluginOption => {
...ret,
code: `
${Object.keys(codeBlockImports)
.map(
(importPath) => `
import ${codeBlockImports[importPath]} from ${JSON.stringify(importPath)}`
)
.join(";\n")}
.map(
(importPath) => `
import ${codeBlockImports[importPath]} from ${JSON.stringify(importPath)}`,
)
.join(";\n")}
import { defineComponent, h } from "vue"
${ret.code.replace(
"export default function MDXContent(",
"function MDXContent("
)}
"export default function MDXContent(",
"function MDXContent(",
)}
export default defineComponent(() => {
return () => h(MDXContent, {
components: {
${Object.keys(codeBlockImports)
.map(
(importPath) =>
`${codeBlockImports[importPath]?.toLowerCase()}: ${
codeBlockImports[importPath]
}`
)
.join(",\n")}
.map(
(importPath) =>
`${codeBlockImports[importPath]?.toLowerCase()}: ${
codeBlockImports[importPath]
}`,
)
.join(",\n")}
}
})
})
`
`,
};
}
}
},
};
};
14 changes: 9 additions & 5 deletions nodedevpkg/vue-vite-presets/src/viteVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import vue from "@vitejs/plugin-vue";
import type { PluginOption } from "vite";
import vitePages, {
type PageResolver,
type PageOptions
type PageOptions,
} from "vite-plugin-pages";
import { mdx } from "./mdx";
import { createPageMetaResolver, viteVueComponentCompleter, viteVueComponentHMR } from "./vue";
import {
createPageMetaResolver,
viteVueComponentCompleter,
viteVueComponentHMR,
} from "./vue";

export interface ViteReactOptions {
pagesDirs?: string | (string | PageOptions)[];
Expand All @@ -27,8 +31,8 @@ export const viteVue = (options: ViteReactOptions = {}): PluginOption[] => {
onRoutesGenerated: r.onRoutesGenerated,
resolver: {
...r.pagesResolver,
...options.pagesResolver
}
}) as PluginOption
...options.pagesResolver,
},
}) as PluginOption,
];
};
17 changes: 8 additions & 9 deletions nodedevpkg/vue-vite-presets/src/vue/componentCompleter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ import { type Plugin, createFilter } from "vite";
import { usePlugin } from "@innoai-tech/vuecomponentcompleter";
import { transform } from "@swc/core";


export interface ComponentCompleterOptions {
include?: string[];
exclude?: string[];
}

export const viteVueComponentCompleter = (
options: ComponentCompleterOptions = {}
options: ComponentCompleterOptions = {},
): Plugin => {
const filter = createFilter(
options.include || [/\.tsx$/, /\.mdx?$/],
options.exclude
options.exclude,
);

return {
Expand All @@ -34,24 +33,24 @@ export const viteVueComponentCompleter = (
externalHelpers: false,
parser: {
syntax: "typescript",
tsx: true
tsx: true,
},
experimental: {
disableBuiltinTransformsForInternalTesting: true,
plugins: [usePlugin({})]
}
}
plugins: [usePlugin({})],
},
},
});

return (
result.code && {
code: result.code,
map: result.map || null
map: result.map || null,
}
);
}

return null;
}
},
};
};
19 changes: 9 additions & 10 deletions nodedevpkg/vue-vite-presets/src/vue/componentHMR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@ export interface Module {
exports: Map<string, ModuleExport>;
}

export const viteVueComponentHMR = (
options: VueJsxHmrOptions = {}
): Plugin => {
export const viteVueComponentHMR = (options: VueJsxHmrOptions = {}): Plugin => {
const filter = createFilter(
options.include || [/\.tsx$/, /\.mdx?$/],
options.exclude
options.exclude,
);

let hmrEnabled = false;
Expand All @@ -50,7 +48,7 @@ export const viteVueComponentHMR = (
}

return null;
}
},
};
};

Expand Down Expand Up @@ -80,7 +78,6 @@ ${callbackBlock}
return code;
}


export const exportScanner = (id: string, filename = id) => {
const re =
/export (const (?<name>\w+) =|default) (?<defStart>(styled|component\$?)\()/;
Expand All @@ -89,7 +86,7 @@ export const exportScanner = (id: string, filename = id) => {
scan(code: string): Module {
const ret = {
code: "",
exports: new Map<string, ModuleExport>()
exports: new Map<string, ModuleExport>(),
};
let src = code;
let m: RegExpMatchArray | null = null;
Expand All @@ -108,11 +105,13 @@ export const exportScanner = (id: string, filename = id) => {
const local =
exported !== "default"
? exported
: upperFirst(camelCase(`${basename(filename, extname(filename))}Default`));
: upperFirst(
camelCase(`${basename(filename, extname(filename))}Default`),
);

const range = {
start: m.index ?? 0,
length: m[0].length
length: m[0].length,
};

ret.exports.set(local, { exported, id: getHash(`${id}#${exported}`) });
Expand Down Expand Up @@ -143,6 +142,6 @@ export { ${nonDefaultExports.join(", ")} }
}

return ret;
}
},
};
};
2 changes: 1 addition & 1 deletion nodepkg/csstype/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"sideEffects": false,
"type": "module",
"types": "index.d.ts"
}
}
4 changes: 2 additions & 2 deletions nodepkg/gents/src/__tests__/client/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ manifest = "manifest"

export const displayKubepkgV1Alpha1DigestMetaType = (v: KubepkgV1Alpha1DigestMetaType) => {
return ({
blob: "Blob",
manifest: "Manifest"
"blob": "Blob",
"manifest": "Manifest"
})[v] ?? v
}

Expand Down
51 changes: 51 additions & 0 deletions nodepkg/jsoneditor/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "@innoai-tech/jsoneditor",
"version": "0.1.4",
"monobundle": {
"build": {
"clean": true
},
"exports": {
".": "./src/index.ts"
}
},
"dependencies": {
"@innoai-tech/vuekit": "workspace:^",
"@innoai-tech/vuemarkdown": "workspace:^",
"@innoai-tech/vuematerial": "workspace:^",
"@innoai-tech/vueuikit": "workspace:^",
"@mdi/js": "^7.4.47",
"copy-to-clipboard": "^3.3.3"
},
"peerDependencies": {},
"exports": {
".": {
"bun": "./src/index.ts",
"import": {
"types": "./src/index.ts",
"default": "./dist/index.mjs"
}
}
},
"files": [
"dist/*",
"src/*",
"!/**/__tests__"
],
"license": "MIT",
"publishConfig": {
"registry": "https://npm.pkg.github.com",
"access": "public"
},
"repository": {
"type": "git",
"url": "ssh://[email protected]:innoai-tech/vuekit.git",
"directory": "nodepkg/jsoneditor"
},
"scripts": {
"lint": "bunx --bun prettier --write . ",
"build": "bunx --bun monobundle",
"prepublishOnly": "bun run build"
},
"type": "module"
}
Loading

0 comments on commit 4cf5364

Please sign in to comment.