UNPKG

yanzhen-design-vue

Version:

61 lines (60 loc) 2.19 kB
import { isEmptyArray } from "@yanzhen-libs/utils"; import { createApp, withInstall } from "@yanzhen-lowcode/core"; import { isString, camelCase, omit } from "lodash-es"; import "./constants/index.mjs"; import { version } from "./version.mjs"; import "./components/index.mjs"; import { INSTALLED_KEY, INSTALLED_SCHEMA_KEY } from "./constants/key.mjs"; import { provideGlobalConfig } from "./components/config-provider/src/hooks/use-global-config.mjs"; import { FORM_SCHEMA_NAMES } from "./constants/schema.mjs"; import { defineTextPreviewComponent } from "./components/text-preview/schema.mjs"; function makeInstaller({ components = [], schemas }, extra) { const install = (app, inject, options) => { let flags; switch (inject) { case "component": case false: flags = ["component"]; break; case "schema": flags = ["schema"]; break; default: flags = ["component", "schema"]; } if (flags.includes("component") && !app[INSTALLED_KEY]) { app[INSTALLED_KEY] = true; components.forEach((c) => app.use(c)); if (options) provideGlobalConfig(options, app, true); } if (!isEmptyArray(schemas) && flags.includes("schema") && !app[INSTALLED_SCHEMA_KEY]) { app[INSTALLED_SCHEMA_KEY] = true; createApp(app, options); const _schemas = {}; schemas.forEach((schema) => { app.use(schema); const name = schema == null ? void 0 : schema.name; if (name && FORM_SCHEMA_NAMES.includes(name)) { const flag = Object.values(schema).some((value) => { return isString(value == null ? void 0 : value.name) ? camelCase(value == null ? void 0 : value.name) === camelCase(`preview-${name}`) : false; }); if (!flag) { const options2 = omit(schema, "name", "component", "install"); const _name = `preview-${name}`; const _schema = withInstall(defineTextPreviewComponent(_name, options2)); app.use(_schema); _schemas[_name] = _schema; } } }); } }; return { version, install, ...extra ?? {} }; } export { makeInstaller };