Skip to content

Commit

Permalink
feat: support setNpmCDNRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Dec 20, 2021
1 parent ffba7ec commit 4c38484
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
7 changes: 6 additions & 1 deletion formily/antd/playground/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import {
SettingsPanel,
ComponentTreeWidget,
} from '@designable/react'
import { SettingsForm } from '@designable/react-settings-form'
import {
SettingsForm,
setNpmCDNRegistry,
} from '@designable/react-settings-form'
import {
createDesigner,
GlobalRegistry,
Expand Down Expand Up @@ -63,6 +66,8 @@ import {
FormGrid,
} from '../src'

setNpmCDNRegistry('//unpkg.com')

GlobalRegistry.registerDesignerLocales({
'zh-CN': {
sources: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MonacoInput } from '@designable/react-settings-form'
import { MonacoInput, getNpmCDNRegistry } from '@designable/react-settings-form'

export interface IDependency {
name: string
Expand All @@ -10,7 +10,7 @@ const loadDependencies = async (deps: IDependency[]) => {
deps.map(async ({ name, path }) => ({
name,
path,
library: await fetch(`//cdn.jsdelivr.net/npm/${name}/${path}`).then(
library: await fetch(`${getNpmCDNRegistry()}/${name}/${path}`).then(
(res) => res.text()
),
}))
Expand Down
2 changes: 1 addition & 1 deletion formily/setters/src/components/ReactionsSetter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ export const ReactionsSetter: React.FC<IReactionsSetterProps> = (props) => {
const property = field
.query('.property')
.get('inputValues')
property[0] = property[0] ?? 'value'
property[0] = property[0] || 'value'
field.query('.source').take((source) => {
if (isVoidField(source)) return
if (source.value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse } from '@babel/parser'

import { getNpmCDNRegistry } from '../../registry'
interface IPrettierModule {
default: {
format(
Expand All @@ -13,7 +13,7 @@ interface IPrettierModule {
}

const prettier: Promise<IPrettierModule> = new Function(
'return import("https://cdn.jsdelivr.net/npm/[email protected]/esm/standalone.mjs")'
`return import("${getNpmCDNRegistry()}/[email protected]/esm/standalone.mjs")`
)()

export const format = async (language: string, source: string) => {
Expand Down
1 change: 1 addition & 0 deletions packages/react-settings-form/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import './locales'
export * from './registry'
export * from './components'
export * from './SchemaField'
export * from './SettingsForm'
16 changes: 16 additions & 0 deletions packages/react-settings-form/src/registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import loader from '@monaco-editor/loader'

const Registry = {
cdn: '//cdn.jsdelivr.net/npm',
}

export const setNpmCDNRegistry = (registry: string) => {
Registry.cdn = registry
loader.config({
paths: {
vs: `${registry}/[email protected]/min/vs`,
},
})
}

export const getNpmCDNRegistry = () => String(Registry.cdn).replace(/\/$/, '')
3 changes: 2 additions & 1 deletion packages/react-settings-form/src/shared/loadScript.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getNpmCDNRegistry } from '../registry'
export interface ILoadScriptProps {
package: string
entry: string
Expand All @@ -7,7 +8,7 @@ export interface ILoadScriptProps {

export const loadScript = async (props: ILoadScriptProps) => {
const options: ILoadScriptProps = {
base: '//cdn.jsdelivr.net/npm',
base: getNpmCDNRegistry(),
...props,
}
if (window[props.root]) return window[options.root]
Expand Down

0 comments on commit 4c38484

Please sign in to comment.