install.js 1.8 KB

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