index-fefbbdb7.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. import { m as mountComponent, u as usePopupState } from "./mount-component-2b0f7b23.js";
  2. import { d as defineComponent, r as ref, c as createVNode, a as computed, n as reactive, R as withKeys, m as mergeProps } from "./index-5e4623ce.js";
  3. import { p as popupSharedProps, a as popupSharedPropKeys, P as Popup } from "./index-eef3af38.js";
  4. import { B as Button } from "./index-b1054607.js";
  5. import { c as createNamespace, u as useChildren, t as truthProp, w as withInstall, e as extend, a as useParent, n as numericProp, G as unknownProp, z as makeStringProp, y as pick, d as addUnit, Q as noop, R as isFunction, S as BORDER_LEFT, T as BORDER_TOP, N as inBrowser } from "./index-487cde8c.js";
  6. import { u as usePlaceholder } from "./use-placeholder-16d7c5d7.js";
  7. import { u as useExpose } from "./use-scope-id-0b5b8615.js";
  8. import { r as routeProps, u as useRoute } from "./use-route-726f0d0b.js";
  9. import { c as callInterceptor } from "./on-popup-reopen-c5ca1603.js";
  10. const [name$2, bem$2] = createNamespace("action-bar");
  11. const ACTION_BAR_KEY = Symbol(name$2);
  12. const actionBarProps = {
  13. placeholder: Boolean,
  14. safeAreaInsetBottom: truthProp
  15. };
  16. var stdin_default$2 = defineComponent({
  17. name: name$2,
  18. props: actionBarProps,
  19. setup(props, {
  20. slots
  21. }) {
  22. const root = ref();
  23. const renderPlaceholder = usePlaceholder(root, bem$2);
  24. const {
  25. linkChildren
  26. } = useChildren(ACTION_BAR_KEY);
  27. linkChildren();
  28. const renderActionBar = () => {
  29. var _a;
  30. return createVNode("div", {
  31. "ref": root,
  32. "class": [bem$2(), {
  33. "van-safe-area-bottom": props.safeAreaInsetBottom
  34. }]
  35. }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
  36. };
  37. return () => {
  38. if (props.placeholder) {
  39. return renderPlaceholder(renderActionBar);
  40. }
  41. return renderActionBar();
  42. };
  43. }
  44. });
  45. const ActionBar = withInstall(stdin_default$2);
  46. const [name$1, bem$1] = createNamespace("action-bar-button");
  47. const actionBarButtonProps = extend({}, routeProps, {
  48. type: String,
  49. text: String,
  50. icon: String,
  51. color: String,
  52. loading: Boolean,
  53. disabled: Boolean
  54. });
  55. var stdin_default$1 = defineComponent({
  56. name: name$1,
  57. props: actionBarButtonProps,
  58. setup(props, {
  59. slots
  60. }) {
  61. const route = useRoute();
  62. const {
  63. parent,
  64. index: index2
  65. } = useParent(ACTION_BAR_KEY);
  66. const isFirst = computed(() => {
  67. if (parent) {
  68. const prev = parent.children[index2.value - 1];
  69. return !(prev && "isButton" in prev);
  70. }
  71. });
  72. const isLast = computed(() => {
  73. if (parent) {
  74. const next = parent.children[index2.value + 1];
  75. return !(next && "isButton" in next);
  76. }
  77. });
  78. useExpose({
  79. isButton: true
  80. });
  81. return () => {
  82. const {
  83. type,
  84. icon,
  85. text,
  86. color,
  87. loading,
  88. disabled
  89. } = props;
  90. return createVNode(Button, {
  91. "class": bem$1([type, {
  92. last: isLast.value,
  93. first: isFirst.value
  94. }]),
  95. "size": "large",
  96. "type": type,
  97. "icon": icon,
  98. "color": color,
  99. "loading": loading,
  100. "disabled": disabled,
  101. "onClick": route
  102. }, {
  103. default: () => [slots.default ? slots.default() : text]
  104. });
  105. };
  106. }
  107. });
  108. const ActionBarButton = withInstall(stdin_default$1);
  109. const [name, bem, t] = createNamespace("dialog");
  110. const dialogProps = extend({}, popupSharedProps, {
  111. title: String,
  112. theme: String,
  113. width: numericProp,
  114. message: [String, Function],
  115. callback: Function,
  116. allowHtml: Boolean,
  117. className: unknownProp,
  118. transition: makeStringProp("van-dialog-bounce"),
  119. messageAlign: String,
  120. closeOnPopstate: truthProp,
  121. showCancelButton: Boolean,
  122. cancelButtonText: String,
  123. cancelButtonColor: String,
  124. cancelButtonDisabled: Boolean,
  125. confirmButtonText: String,
  126. confirmButtonColor: String,
  127. confirmButtonDisabled: Boolean,
  128. showConfirmButton: truthProp,
  129. closeOnClickOverlay: Boolean
  130. });
  131. const popupInheritKeys = [...popupSharedPropKeys, "transition", "closeOnPopstate"];
  132. var stdin_default = defineComponent({
  133. name,
  134. props: dialogProps,
  135. emits: ["confirm", "cancel", "keydown", "update:show"],
  136. setup(props, {
  137. emit,
  138. slots
  139. }) {
  140. const root = ref();
  141. const loading = reactive({
  142. confirm: false,
  143. cancel: false
  144. });
  145. const updateShow = (value) => emit("update:show", value);
  146. const close = (action) => {
  147. var _a;
  148. updateShow(false);
  149. (_a = props.callback) == null ? void 0 : _a.call(props, action);
  150. };
  151. const getActionHandler = (action) => () => {
  152. if (!props.show) {
  153. return;
  154. }
  155. emit(action);
  156. if (props.beforeClose) {
  157. loading[action] = true;
  158. callInterceptor(props.beforeClose, {
  159. args: [action],
  160. done() {
  161. close(action);
  162. loading[action] = false;
  163. },
  164. canceled() {
  165. loading[action] = false;
  166. }
  167. });
  168. } else {
  169. close(action);
  170. }
  171. };
  172. const onCancel = getActionHandler("cancel");
  173. const onConfirm = getActionHandler("confirm");
  174. const onKeydown = withKeys((event) => {
  175. var _a, _b;
  176. if (event.target !== ((_b = (_a = root.value) == null ? void 0 : _a.popupRef) == null ? void 0 : _b.value)) {
  177. return;
  178. }
  179. const onEventType = {
  180. Enter: props.showConfirmButton ? onConfirm : noop,
  181. Escape: props.showCancelButton ? onCancel : noop
  182. };
  183. onEventType[event.key]();
  184. emit("keydown", event);
  185. }, ["enter", "esc"]);
  186. const renderTitle = () => {
  187. const title = slots.title ? slots.title() : props.title;
  188. if (title) {
  189. return createVNode("div", {
  190. "class": bem("header", {
  191. isolated: !props.message && !slots.default
  192. })
  193. }, [title]);
  194. }
  195. };
  196. const renderMessage = (hasTitle) => {
  197. const {
  198. message,
  199. allowHtml,
  200. messageAlign
  201. } = props;
  202. const classNames = bem("message", {
  203. "has-title": hasTitle,
  204. [messageAlign]: messageAlign
  205. });
  206. const content = isFunction(message) ? message() : message;
  207. if (allowHtml && typeof content === "string") {
  208. return createVNode("div", {
  209. "class": classNames,
  210. "innerHTML": content
  211. }, null);
  212. }
  213. return createVNode("div", {
  214. "class": classNames
  215. }, [content]);
  216. };
  217. const renderContent = () => {
  218. if (slots.default) {
  219. return createVNode("div", {
  220. "class": bem("content")
  221. }, [slots.default()]);
  222. }
  223. const {
  224. title,
  225. message,
  226. allowHtml
  227. } = props;
  228. if (message) {
  229. const hasTitle = !!(title || slots.title);
  230. return createVNode("div", {
  231. "key": allowHtml ? 1 : 0,
  232. "class": bem("content", {
  233. isolated: !hasTitle
  234. })
  235. }, [renderMessage(hasTitle)]);
  236. }
  237. };
  238. const renderButtons = () => createVNode("div", {
  239. "class": [BORDER_TOP, bem("footer")]
  240. }, [props.showCancelButton && createVNode(Button, {
  241. "size": "large",
  242. "text": props.cancelButtonText || t("cancel"),
  243. "class": bem("cancel"),
  244. "style": {
  245. color: props.cancelButtonColor
  246. },
  247. "loading": loading.cancel,
  248. "disabled": props.cancelButtonDisabled,
  249. "onClick": onCancel
  250. }, null), props.showConfirmButton && createVNode(Button, {
  251. "size": "large",
  252. "text": props.confirmButtonText || t("confirm"),
  253. "class": [bem("confirm"), {
  254. [BORDER_LEFT]: props.showCancelButton
  255. }],
  256. "style": {
  257. color: props.confirmButtonColor
  258. },
  259. "loading": loading.confirm,
  260. "disabled": props.confirmButtonDisabled,
  261. "onClick": onConfirm
  262. }, null)]);
  263. const renderRoundButtons = () => createVNode(ActionBar, {
  264. "class": bem("footer")
  265. }, {
  266. default: () => [props.showCancelButton && createVNode(ActionBarButton, {
  267. "type": "warning",
  268. "text": props.cancelButtonText || t("cancel"),
  269. "class": bem("cancel"),
  270. "color": props.cancelButtonColor,
  271. "loading": loading.cancel,
  272. "disabled": props.cancelButtonDisabled,
  273. "onClick": onCancel
  274. }, null), props.showConfirmButton && createVNode(ActionBarButton, {
  275. "type": "danger",
  276. "text": props.confirmButtonText || t("confirm"),
  277. "class": bem("confirm"),
  278. "color": props.confirmButtonColor,
  279. "loading": loading.confirm,
  280. "disabled": props.confirmButtonDisabled,
  281. "onClick": onConfirm
  282. }, null)]
  283. });
  284. const renderFooter = () => {
  285. if (slots.footer) {
  286. return slots.footer();
  287. }
  288. return props.theme === "round-button" ? renderRoundButtons() : renderButtons();
  289. };
  290. return () => {
  291. const {
  292. width,
  293. title,
  294. theme,
  295. message,
  296. className
  297. } = props;
  298. return createVNode(Popup, mergeProps({
  299. "ref": root,
  300. "role": "dialog",
  301. "class": [bem([theme]), className],
  302. "style": {
  303. width: addUnit(width)
  304. },
  305. "tabindex": 0,
  306. "aria-labelledby": title || message,
  307. "onKeydown": onKeydown,
  308. "onUpdate:show": updateShow
  309. }, pick(props, popupInheritKeys)), {
  310. default: () => [renderTitle(), renderContent(), renderFooter()]
  311. });
  312. };
  313. }
  314. });
  315. let instance;
  316. const DEFAULT_OPTIONS = {
  317. title: "",
  318. width: "",
  319. theme: null,
  320. message: "",
  321. overlay: true,
  322. callback: null,
  323. teleport: "body",
  324. className: "",
  325. allowHtml: false,
  326. lockScroll: true,
  327. transition: void 0,
  328. beforeClose: null,
  329. overlayClass: "",
  330. overlayStyle: void 0,
  331. messageAlign: "",
  332. cancelButtonText: "",
  333. cancelButtonColor: null,
  334. cancelButtonDisabled: false,
  335. confirmButtonText: "",
  336. confirmButtonColor: null,
  337. confirmButtonDisabled: false,
  338. showConfirmButton: true,
  339. showCancelButton: false,
  340. closeOnPopstate: true,
  341. closeOnClickOverlay: false
  342. };
  343. let currentOptions = extend({}, DEFAULT_OPTIONS);
  344. function initInstance() {
  345. const Wrapper = {
  346. setup() {
  347. const {
  348. state,
  349. toggle
  350. } = usePopupState();
  351. return () => createVNode(stdin_default, mergeProps(state, {
  352. "onUpdate:show": toggle
  353. }), null);
  354. }
  355. };
  356. ({
  357. instance
  358. } = mountComponent(Wrapper));
  359. }
  360. function showDialog(options) {
  361. if (!inBrowser) {
  362. return Promise.resolve(void 0);
  363. }
  364. return new Promise((resolve, reject) => {
  365. if (!instance) {
  366. initInstance();
  367. }
  368. instance.open(extend({}, currentOptions, options, {
  369. callback: (action) => {
  370. (action === "confirm" ? resolve : reject)(action);
  371. }
  372. }));
  373. });
  374. }
  375. const showConfirmDialog = (options) => showDialog(extend({
  376. showCancelButton: true
  377. }, options));
  378. const index$2 = "";
  379. const index$1 = "";
  380. const index = "";
  381. export {
  382. showConfirmDialog as a,
  383. stdin_default as s
  384. };