-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(setters): support declaration to ReactionsSetter (#1805)
- Loading branch information
Showing
13 changed files
with
788 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
designable/setters/src/components/ReactionsSetter/declarations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { MonacoInput } from '@designable/react-settings-form' | ||
|
||
export interface IDependency { | ||
name: string | ||
path: string | ||
} | ||
|
||
const loadDependencies = async (deps: IDependency[]) => { | ||
return Promise.all( | ||
deps.map(async ({ name, path }) => ({ | ||
name, | ||
path, | ||
library: await fetch(`//cdn.jsdelivr.net/npm/${name}/${path}`).then( | ||
(res) => res.text() | ||
), | ||
})) | ||
) | ||
} | ||
|
||
MonacoInput.loader.init().then(async (monaco) => { | ||
const deps = await loadDependencies([ | ||
{ name: '@formily/core', path: 'dist/formily.core.all.d.ts' }, | ||
]) | ||
deps?.forEach(({ name, library }) => { | ||
monaco.languages.typescript.typescriptDefaults.addExtraLib( | ||
`declare module '${name}'{ ${library} }`, | ||
`file:///node_modules/${name}/index.d.ts` | ||
) | ||
}) | ||
monaco.languages.typescript.typescriptDefaults.addExtraLib( | ||
` | ||
import { Form, Field } from '@formily/core' | ||
declare global { | ||
declare var $form : Form | ||
declare var $self : Field | ||
} | ||
`, | ||
`file:///node_modules/formily_global.d.ts` | ||
) | ||
}) |
Oops, something went wrong.