framework.mjs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Composables
  2. import { createDefaults, DefaultsSymbol } from "./composables/defaults.mjs";
  3. import { createDisplay, DisplaySymbol } from "./composables/display.mjs";
  4. import { createIcons, IconSymbol } from "./composables/icons.mjs";
  5. import { createLocale, LocaleSymbol } from "./composables/locale.mjs";
  6. import { createTheme, ThemeSymbol } from "./composables/theme.mjs";
  7. import { createDate, DateAdapterSymbol } from "./labs/date/date.mjs"; // Utilities
  8. import { nextTick, reactive } from 'vue';
  9. import { defineComponent, getUid, IN_BROWSER, mergeDeep } from "./util/index.mjs"; // Types
  10. export * from "./composables/index.mjs";
  11. export function createVuetify() {
  12. let vuetify = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  13. const {
  14. blueprint,
  15. ...rest
  16. } = vuetify;
  17. const options = mergeDeep(blueprint, rest);
  18. const {
  19. aliases = {},
  20. components = {},
  21. directives = {}
  22. } = options;
  23. const defaults = createDefaults(options.defaults);
  24. const display = createDisplay(options.display, options.ssr);
  25. const theme = createTheme(options.theme);
  26. const icons = createIcons(options.icons);
  27. const locale = createLocale(options.locale);
  28. const date = createDate(options.date);
  29. const install = app => {
  30. for (const key in directives) {
  31. app.directive(key, directives[key]);
  32. }
  33. for (const key in components) {
  34. app.component(key, components[key]);
  35. }
  36. for (const key in aliases) {
  37. app.component(key, defineComponent({
  38. ...aliases[key],
  39. name: key,
  40. aliasName: aliases[key].name
  41. }));
  42. }
  43. theme.install(app);
  44. app.provide(DefaultsSymbol, defaults);
  45. app.provide(DisplaySymbol, display);
  46. app.provide(ThemeSymbol, theme);
  47. app.provide(IconSymbol, icons);
  48. app.provide(LocaleSymbol, locale);
  49. app.provide(DateAdapterSymbol, date);
  50. if (IN_BROWSER && options.ssr) {
  51. if (app.$nuxt) {
  52. app.$nuxt.hook('app:suspense:resolve', () => {
  53. display.update();
  54. });
  55. } else {
  56. const {
  57. mount
  58. } = app;
  59. app.mount = function () {
  60. const vm = mount(...arguments);
  61. nextTick(() => display.update());
  62. app.mount = mount;
  63. return vm;
  64. };
  65. }
  66. }
  67. getUid.reset();
  68. if (typeof __VUE_OPTIONS_API__ !== 'boolean' || __VUE_OPTIONS_API__) {
  69. app.mixin({
  70. computed: {
  71. $vuetify() {
  72. return reactive({
  73. defaults: inject.call(this, DefaultsSymbol),
  74. display: inject.call(this, DisplaySymbol),
  75. theme: inject.call(this, ThemeSymbol),
  76. icons: inject.call(this, IconSymbol),
  77. locale: inject.call(this, LocaleSymbol),
  78. date: inject.call(this, DateAdapterSymbol)
  79. });
  80. }
  81. }
  82. });
  83. }
  84. };
  85. return {
  86. install,
  87. defaults,
  88. display,
  89. theme,
  90. icons,
  91. locale,
  92. date
  93. };
  94. }
  95. export const version = "3.3.11";
  96. createVuetify.version = version;
  97. // Vue's inject() can only be used in setup
  98. function inject(key) {
  99. const vm = this.$;
  100. const provides = vm.parent?.provides ?? vm.vnode.appContext?.provides;
  101. if (provides && key in provides) {
  102. return provides[key];
  103. }
  104. }
  105. //# sourceMappingURL=framework.mjs.map