refactor(core): remove slots patch
This commit is contained in:
@@ -54,9 +54,8 @@
|
|||||||
"dev": "pnpm types:watch & pnpm build:watch",
|
"dev": "pnpm types:watch & pnpm build:watch",
|
||||||
"build": "vite build && vite build -c vite.config.iife.ts",
|
"build": "vite build && vite build -c vite.config.iife.ts",
|
||||||
"build:watch": "vite build --watch & vite build -c vite.config.iife.ts --watch",
|
"build:watch": "vite build --watch & vite build -c vite.config.iife.ts --watch",
|
||||||
"types": "pnpm prepare && vue-tsc --declaration --emitDeclarationOnly && tsc -p ./tsconfig.build.json && shx rm -rf tmp && pnpm lint:dist && pnpm run patch",
|
"types": "pnpm prepare && vue-tsc --declaration --emitDeclarationOnly && tsc -p ./tsconfig.build.json && shx rm -rf tmp && pnpm lint:dist",
|
||||||
"types:watch": "pnpm prepare && vue-tsc --declaration --emitDeclarationOnly --watch & tsc -p ./tsconfig.build.json --watch",
|
"types:watch": "pnpm prepare && vue-tsc --declaration --emitDeclarationOnly --watch & tsc -p ./tsconfig.build.json --watch",
|
||||||
"patch": "node patch/slots.js",
|
|
||||||
"theme": "postcss src/style.css -o dist/style.css && postcss src/theme-default.css -o dist/theme-default.css",
|
"theme": "postcss src/style.css -o dist/style.css && postcss src/theme-default.css -o dist/theme-default.css",
|
||||||
"lint": "eslint --ext .js,.ts,.vue ./",
|
"lint": "eslint --ext .js,.ts,.vue ./",
|
||||||
"lint:dist": "eslint --ext \".ts,.tsx\" -c .eslintrc.js --fix --ignore-pattern !**/* ./dist",
|
"lint:dist": "eslint --ext \".ts,.tsx\" -c .eslintrc.js --fix --ignore-pattern !**/* ./dist",
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
const { readFile, writeFile } = require('node:fs/promises')
|
|
||||||
const { resolve } = require('node:path')
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a workaround until slots can be properly typed from inside the VueFlow component
|
|
||||||
* It will overwrite `{}` typings with the correct prop types and add slot types for dynamic node and edge slots
|
|
||||||
*/
|
|
||||||
|
|
||||||
async function content(path) {
|
|
||||||
return readFile(path, 'utf8')
|
|
||||||
}
|
|
||||||
|
|
||||||
const filePath = resolve(__dirname, '../dist/container/VueFlow/VueFlow.vue.d.ts')
|
|
||||||
|
|
||||||
const typeImportsString = /import type {\n(.*\n)+} from '\.\.\/\.\.\/types'/
|
|
||||||
|
|
||||||
const patchedTypeImports = `import type {
|
|
||||||
Connection,
|
|
||||||
ConnectionLineProps,
|
|
||||||
EdgeChange,
|
|
||||||
EdgeMouseEvent,
|
|
||||||
EdgeProps,
|
|
||||||
EdgeUpdateEvent,
|
|
||||||
GraphEdge,
|
|
||||||
GraphNode,
|
|
||||||
NodeChange,
|
|
||||||
NodeDragEvent,
|
|
||||||
NodeMouseEvent,
|
|
||||||
NodeProps,
|
|
||||||
OnConnectStartParams,
|
|
||||||
ViewportTransform,
|
|
||||||
VueFlowStore,
|
|
||||||
} from '../../types'`
|
|
||||||
|
|
||||||
const unpatchedSlots = `Partial<Record<string, (_: {}) => any>> &
|
|
||||||
Partial<Record<string, (_: {}) => any>> & {
|
|
||||||
'connection-line'?(_: {}): any
|
|
||||||
'zoom-pane'?(_: {}): any
|
|
||||||
default?(_: {}): any
|
|
||||||
}`
|
|
||||||
|
|
||||||
const patchedSlots = `Partial<Record<string, (_: any) => any>> & {
|
|
||||||
'connection-line': (connectionLineProps: ConnectionLineProps) => any
|
|
||||||
'zoom-pane': () => any
|
|
||||||
'default': () => any
|
|
||||||
} & {
|
|
||||||
[key: \`node-\${string}\`]: (nodeProps: NodeProps) => any
|
|
||||||
} & {
|
|
||||||
[key: \`edge-\${string}\`]: (edgeProps: EdgeProps) => any
|
|
||||||
}`
|
|
||||||
|
|
||||||
async function patchSlots() {
|
|
||||||
const fileContents = await content(filePath)
|
|
||||||
|
|
||||||
const patchedFileContents = fileContents.replace(typeImportsString, patchedTypeImports).replace(unpatchedSlots, patchedSlots)
|
|
||||||
|
|
||||||
await writeFile(filePath, patchedFileContents)
|
|
||||||
}
|
|
||||||
|
|
||||||
patchSlots()
|
|
||||||
// eslint-disable-next-line no-console
|
|
||||||
.then(() => console.log('slots patched'))
|
|
||||||
.catch(console.error)
|
|
||||||
Reference in New Issue
Block a user