install.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  2. const require_runtime = require('../../_virtual/_rolldown/runtime.js');
  3. let _vue_shared = require("@vue/shared");
  4. let lodash_unified = require("lodash-unified");
  5. //#region ../../packages/utils/vue/install.ts
  6. const withPropsDefaultsSetter = (target) => {
  7. const _p = target.props;
  8. const props = (0, _vue_shared.isArray)(_p) ? (0, lodash_unified.fromPairs)(_p.map((key) => [key, {}])) : _p;
  9. target.setPropsDefaults = (defaults) => {
  10. if (!props) return;
  11. for (const [key, value] of Object.entries(defaults)) {
  12. const prop = props[key];
  13. if (!(0, _vue_shared.hasOwn)(props, key)) continue;
  14. if ((0, lodash_unified.isPlainObject)(prop)) {
  15. props[key] = {
  16. ...prop,
  17. default: value
  18. };
  19. continue;
  20. }
  21. props[key] = {
  22. type: prop,
  23. default: value
  24. };
  25. }
  26. target.props = props;
  27. };
  28. };
  29. const withInstall = (main, extra) => {
  30. main.install = (app) => {
  31. for (const comp of [main, ...Object.values(extra ?? {})]) app.component(comp.name, comp);
  32. };
  33. if (extra) for (const [key, comp] of Object.entries(extra)) main[key] = comp;
  34. withPropsDefaultsSetter(main);
  35. return main;
  36. };
  37. const withInstallFunction = (fn, name) => {
  38. fn.install = (app) => {
  39. fn._context = app._context;
  40. app.config.globalProperties[name] = fn;
  41. };
  42. return fn;
  43. };
  44. const withInstallDirective = (directive, name) => {
  45. directive.install = (app) => {
  46. app.directive(name, directive);
  47. };
  48. return directive;
  49. };
  50. const withNoopInstall = (component) => {
  51. component.install = _vue_shared.NOOP;
  52. withPropsDefaultsSetter(component);
  53. return component;
  54. };
  55. //#endregion
  56. exports.withInstall = withInstall;
  57. exports.withInstallDirective = withInstallDirective;
  58. exports.withInstallFunction = withInstallFunction;
  59. exports.withNoopInstall = withNoopInstall;
  60. exports.withPropsDefaultsSetter = withPropsDefaultsSetter;
  61. //# sourceMappingURL=install.js.map