You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 lines
15 KiB

{"ast":null,"code":"import { isVNode, render, createVNode } from 'vue';\nimport MessageConstructor from './message2.mjs';\nimport { messageTypes, messageDefaults } from './message.mjs';\nimport { instances } from './instance.mjs';\nimport { messageConfig } from '../../config-provider/src/config-provider.mjs';\nimport { isClient } from '@vueuse/core';\nimport { isNumber, isElement, isBoolean } from '../../../utils/types.mjs';\nimport { isString, isFunction } from '@vue/shared';\nimport { debugWarn } from '../../../utils/error.mjs';\nlet seed = 1;\nconst normalizeOptions = params => {\n const options = !params || isString(params) || isVNode(params) || isFunction(params) ? {\n message: params\n } : params;\n const normalized = {\n ...messageDefaults,\n ...options\n };\n if (!normalized.appendTo) {\n normalized.appendTo = document.body;\n } else if (isString(normalized.appendTo)) {\n let appendTo = document.querySelector(normalized.appendTo);\n if (!isElement(appendTo)) {\n debugWarn(\"ElMessage\", \"the appendTo option is not an HTMLElement. Falling back to document.body.\");\n appendTo = document.body;\n }\n normalized.appendTo = appendTo;\n }\n if (isBoolean(messageConfig.grouping) && !normalized.grouping) {\n normalized.grouping = messageConfig.grouping;\n }\n if (isNumber(messageConfig.duration) && normalized.duration === 3e3) {\n normalized.duration = messageConfig.duration;\n }\n if (isNumber(messageConfig.offset) && normalized.offset === 16) {\n normalized.offset = messageConfig.offset;\n }\n if (isBoolean(messageConfig.showClose) && !normalized.showClose) {\n normalized.showClose = messageConfig.showClose;\n }\n return normalized;\n};\nconst closeMessage = instance => {\n const idx = instances.indexOf(instance);\n if (idx === -1) return;\n instances.splice(idx, 1);\n const {\n handler\n } = instance;\n handler.close();\n};\nconst createMessage = ({\n appendTo,\n ...options\n}, context) => {\n const id = `message_${seed++}`;\n const userOnClose = options.onClose;\n const container = document.createElement(\"div\");\n const props = {\n ...options,\n id,\n onClose: () => {\n userOnClose == null ? void 0 : userOnClose();\n closeMessage(instance);\n },\n onDestroy: () => {\n render(null, container);\n }\n };\n const vnode = createVNode(MessageConstructor, props, isFunction(props.message) || isVNode(props.message) ? {\n default: isFunction(props.message) ? props.message : () => props.message\n } : null);\n vnode.appContext = context || message._context;\n render(vnode, container);\n appendTo.appendChild(container.firstElementChild);\n const vm = vnode.component;\n const handler = {\n close: () => {\n vm.exposed.visible.value = false;\n }\n };\n const instance = {\n id,\n vnode,\n vm,\n handler,\n props: vnode.component.props\n };\n return instance;\n};\nconst message = (options = {}, context) => {\n if (!isClient) return {\n close: () => void 0\n };\n const normalized = normalizeOptions(options);\n if (normalized.grouping && instances.length) {\n const instance2 = instances.find(({\n vnode: vm\n }) => {\n var _a;\n return ((_a = vm.props) == null ? void 0 : _a.message) === normalized.message;\n });\n if (instance2) {\n instance2.props.repeatNum += 1;\n instance2.props.type = normalized.type;\n return instance2.handler;\n }\n }\n if (isNumber(messageConfig.max) && instances.length >= messageConfig.max) {\n return {\n close: () => void 0\n };\n }\n const instance = createMessage(normalized, context);\n instances.push(instance);\n return instance.handler;\n};\nmessageTypes.forEach(type => {\n message[type] = (options = {}, appContext) => {\n const normalized = normalizeOptions(options);\n return message({\n ...normalized,\n type\n }, appContext);\n };\n});\nfunction closeAll(type) {\n for (const instance of instances) {\n if (!type || type === instance.props.type) {\n instance.handler.close();\n }\n }\n}\nmessage.closeAll = closeAll;\nmessage._context = null;\nexport { closeAll, message as default };","map":{"version":3,"names":["seed","normalizeOptions","params","options","isString","isVNode","isFunction","message","normalized","messageDefaults","appendTo","document","body","querySelector","isElement","debugWarn","isBoolean","messageConfig","grouping","isNumber","duration","offset","showClose","closeMessage","instance","idx","instances","indexOf","splice","handler","close","createMessage","context","id","userOnClose","onClose","container","createElement","props","onDestroy","render","vnode","createVNode","MessageConstructor","default","appContext","_context","appendChild","firstElementChild","vm","component","exposed","visible","value","isClient","length","instance2","find","_a","repeatNum","type","max","push","messageTypes","forEach","closeAll"],"sources":["../../../../../../packages/components/message/src/method.ts"],"sourcesContent":["import { createVNode, isVNode, render } from 'vue'\nimport {\n debugWarn,\n isBoolean,\n isClient,\n isElement,\n isFunction,\n isNumber,\n isString,\n} from '@element-plus/utils'\nimport { messageConfig } from '@element-plus/components/config-provider'\nimport MessageConstructor from './message.vue'\nimport { messageDefaults, messageTypes } from './message'\nimport { instances } from './instance'\n\nimport type { MessageContext } from './instance'\nimport type { AppContext } from 'vue'\nimport type {\n Message,\n MessageFn,\n MessageHandler,\n MessageOptions,\n MessageParams,\n MessageParamsNormalized,\n messageType,\n} from './message'\n\nlet seed = 1\n\n// TODO: Since Notify.ts is basically the same like this file. So we could do some encapsulation against them to reduce code duplication.\n\nconst normalizeOptions = (params?: MessageParams) => {\n const options: MessageOptions =\n !params || isString(params) || isVNode(params) || isFunction(params)\n ? { message: params }\n : params\n\n const normalized = {\n ...messageDefaults,\n ...options,\n }\n\n if (!normalized.appendTo) {\n normalized.appendTo = document.body\n } else if (isString(normalized.appendTo)) {\n let appendTo = document.querySelector<HTMLElement>(normalized.appendTo)\n\n // should fallback to default value with a warning\n if (!isElement(appendTo)) {\n debugWarn(\n 'ElMessage',\n 'the appendTo option is not an HTMLElement. Falling back to document.body.'\n )\n appendTo = document.body\n }\n\n normalized.appendTo = appendTo\n }\n\n // When grouping is configured globally,\n // if grouping is manually set when calling message individually and it is not equal to the default value,\n // the global configuration cannot override the current setting. default => false\n if (isBoolean(messageConfig.grouping) && !normalized.grouping) {\n normalized.grouping = messageConfig.grouping\n }\n if (isNumber(messageConfig.duration) && normalized.duration === 3000) {\n normalized.duration = messageConfig.duration\n }\n if (isNumber(messageConfig.offset) && normalized.offset === 16) {\n normalized.offset = messageConfig.offset\n }\n if (isBoolean(messageConfig.showClose) && !normalized.showClose) {\n normalized.showClose = messageConfig.showClose\n }\n\n return normalized as MessageParamsNormalized\n}\n\nconst closeMessage = (instance: MessageContext) => {\n const idx = instances.indexOf(instance)\n if (idx === -1) return\n\n instances.splice(idx, 1)\n const { handler } = instance\n handler.close()\n}\n\nconst createMessage = (\n { appendTo, ...options }: MessageParamsNormalized,\n context?: AppContext | null\n): MessageContext => {\n const id = `message_${seed++}`\n const userOnClose = options.onClose\n\n const container = document.createElement('div')\n\n const props = {\n ...options,\n // now the zIndex will be used inside the message.vue component instead of here.\n // zIndex: nextIndex() + options.zIndex\n id,\n onClose: () => {\n userOnClose?.()\n closeMessage(instance)\n },\n\n // clean message element preventing mem leak\n onDestroy: () => {\n // since the element is destroy, then the VNode should be collected by GC as well\n // we do not want cause any mem leak because we have returned vm as a reference to users\n // so that we manually set it to false.\n render(null, container)\n },\n }\n const vnode = createVNode(\n MessageConstructor,\n props,\n isFunction(props.message) || isVNode(props.message)\n ? {\n default: isFunction(props.message)\n ? props.message\n : () => props.message,\n }\n : null\n )\n vnode.appContext = context || message._context\n\n render(vnode, container)\n // instances will remove this item when close function gets called. So we do not need to worry about it.\n appendTo.appendChild(container.firstElementChild!)\n\n const vm = vnode.component!\n\n const handler: MessageHandler = {\n // instead of calling the onClose function directly, setting this value so that we can have the full lifecycle\n // for out component, so that all closing steps will not be skipped.\n close: () => {\n vm.exposed!.visible.value = false\n },\n }\n\n const instance: MessageContext = {\n id,\n vnode,\n vm,\n handler,\n props: (vnode.component as any).props,\n }\n\n return instance\n}\n\nconst message: MessageFn &\n Partial<Message> & { _context: AppContext | null } = (\n options = {},\n context\n) => {\n if (!isClient) return { close: () => undefined }\n\n const normalized = normalizeOptions(options)\n\n if (normalized.grouping && instances.length) {\n const instance = instances.find(\n ({ vnode: vm }) => vm.props?.message === normalized.message\n )\n if (instance) {\n instance.props.repeatNum += 1\n instance.props.type = normalized.type\n return instance.handler\n }\n }\n\n if (isNumber(messageConfig.max) && instances.length >= messageConfig.max) {\n return { close: () => undefined }\n }\n\n const instance = createMessage(normalized, context)\n\n instances.push(instance)\n return instance.handler\n}\n\nmessageTypes.forEach((type) => {\n message[type] = (options = {}, appContext) => {\n const normalized = normalizeOptions(options)\n return message({ ...normalized, type }, appContext)\n }\n})\n\nexport function closeAll(type?: messageType): void {\n for (const instance of instances) {\n if (!type || type === instance.props.type) {\n instance.handler.close()\n }\n }\n}\n\nmessage.closeAll = closeAll\nmessage._context = null\n\nexport default message as Message\n"],"mappings":";;;;;;;;;AAcA,IAAIA,IAAI,GAAG,CAAC;AACZ,MAAMC,gBAAgB,GAAIC,MAAM,IAAK;EACnC,MAAMC,OAAO,GAAG,CAACD,MAAM,IAAIE,QAAQ,CAACF,MAAM,CAAC,IAAIG,OAAO,CAACH,MAAM,CAAC,IAAII,UAAU,CAACJ,MAAM,CAAC,GAAG;IAAEK,OAAO,EAAEL;EAAM,CAAE,GAAGA,MAAM;EACnH,MAAMM,UAAU,GAAG;IACjB,GAAGC,eAAe;IAClB,GAAGN;EACP,CAAG;EACD,IAAI,CAACK,UAAU,CAACE,QAAQ,EAAE;IACxBF,UAAU,CAACE,QAAQ,GAAGC,QAAQ,CAACC,IAAI;EACvC,CAAG,MAAM,IAAIR,QAAQ,CAACI,UAAU,CAACE,QAAQ,CAAC,EAAE;IACxC,IAAIA,QAAQ,GAAGC,QAAQ,CAACE,aAAa,CAACL,UAAU,CAACE,QAAQ,CAAC;IAC1D,IAAI,CAACI,SAAS,CAACJ,QAAQ,CAAC,EAAE;MACxBK,SAAS,CAAC,WAAW,EAAE,2EAA2E,CAAC;MACnGL,QAAQ,GAAGC,QAAQ,CAACC,IAAI;IAC9B;IACIJ,UAAU,CAACE,QAAQ,GAAGA,QAAQ;EAClC;EACE,IAAIM,SAAS,CAACC,aAAa,CAACC,QAAQ,CAAC,IAAI,CAACV,UAAU,CAACU,QAAQ,EAAE;IAC7DV,UAAU,CAACU,QAAQ,GAAGD,aAAa,CAACC,QAAQ;EAChD;EACE,IAAIC,QAAQ,CAACF,aAAa,CAACG,QAAQ,CAAC,IAAIZ,UAAU,CAACY,QAAQ,KAAK,GAAG,EAAE;IACnEZ,UAAU,CAACY,QAAQ,GAAGH,aAAa,CAACG,QAAQ;EAChD;EACE,IAAID,QAAQ,CAACF,aAAa,CAACI,MAAM,CAAC,IAAIb,UAAU,CAACa,MAAM,KAAK,E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