index.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { createVNode as _createVNode } from "vue";
  3. import { defineComponent, computed } from 'vue';
  4. import { initDefaultProps } from '../_util/props-util';
  5. import classNames from '../_util/classNames';
  6. import { objectType } from '../_util/type';
  7. import useConfigInject from '../config-provider/hooks/useConfigInject';
  8. import useMessage from '../message/useMessage';
  9. import useModal from '../modal/useModal';
  10. import useNotification from '../notification/useNotification';
  11. import { useProvideAppConfigContext, useInjectAppConfigContext, useProvideAppContext, useInjectAppContext } from './context';
  12. import useStyle from './style';
  13. export const AppProps = () => {
  14. return {
  15. rootClassName: String,
  16. message: objectType(),
  17. notification: objectType()
  18. };
  19. };
  20. const useApp = () => {
  21. return useInjectAppContext();
  22. };
  23. const App = defineComponent({
  24. name: 'AApp',
  25. props: initDefaultProps(AppProps(), {}),
  26. setup(props, _ref) {
  27. let {
  28. slots
  29. } = _ref;
  30. const {
  31. prefixCls
  32. } = useConfigInject('app', props);
  33. const [wrapSSR, hashId] = useStyle(prefixCls);
  34. const customClassName = computed(() => {
  35. return classNames(hashId.value, prefixCls.value, props.rootClassName);
  36. });
  37. const appConfig = useInjectAppConfigContext();
  38. const mergedAppConfig = computed(() => ({
  39. message: _extends(_extends({}, appConfig.message), props.message),
  40. notification: _extends(_extends({}, appConfig.notification), props.notification)
  41. }));
  42. useProvideAppConfigContext(mergedAppConfig.value);
  43. const [messageApi, messageContextHolder] = useMessage(mergedAppConfig.value.message);
  44. const [notificationApi, notificationContextHolder] = useNotification(mergedAppConfig.value.notification);
  45. const [ModalApi, ModalContextHolder] = useModal();
  46. const memoizedContextValue = computed(() => ({
  47. message: messageApi,
  48. notification: notificationApi,
  49. modal: ModalApi
  50. }));
  51. useProvideAppContext(memoizedContextValue.value);
  52. return () => {
  53. var _a;
  54. return wrapSSR(_createVNode("div", {
  55. "class": customClassName.value
  56. }, [ModalContextHolder(), messageContextHolder(), notificationContextHolder(), (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)]));
  57. };
  58. }
  59. });
  60. App.useApp = useApp;
  61. App.install = function (app) {
  62. app.component(App.name, App);
  63. };
  64. export default App;