| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384 |
- import { m as mountComponent, u as usePopupState } from "./mount-component-2b0f7b23.js";
- 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";
- import { p as popupSharedProps, a as popupSharedPropKeys, P as Popup } from "./index-eef3af38.js";
- import { B as Button } from "./index-b1054607.js";
- 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";
- import { u as usePlaceholder } from "./use-placeholder-16d7c5d7.js";
- import { u as useExpose } from "./use-scope-id-0b5b8615.js";
- import { r as routeProps, u as useRoute } from "./use-route-726f0d0b.js";
- import { c as callInterceptor } from "./on-popup-reopen-c5ca1603.js";
- const [name$2, bem$2] = createNamespace("action-bar");
- const ACTION_BAR_KEY = Symbol(name$2);
- const actionBarProps = {
- placeholder: Boolean,
- safeAreaInsetBottom: truthProp
- };
- var stdin_default$2 = defineComponent({
- name: name$2,
- props: actionBarProps,
- setup(props, {
- slots
- }) {
- const root = ref();
- const renderPlaceholder = usePlaceholder(root, bem$2);
- const {
- linkChildren
- } = useChildren(ACTION_BAR_KEY);
- linkChildren();
- const renderActionBar = () => {
- var _a;
- return createVNode("div", {
- "ref": root,
- "class": [bem$2(), {
- "van-safe-area-bottom": props.safeAreaInsetBottom
- }]
- }, [(_a = slots.default) == null ? void 0 : _a.call(slots)]);
- };
- return () => {
- if (props.placeholder) {
- return renderPlaceholder(renderActionBar);
- }
- return renderActionBar();
- };
- }
- });
- const ActionBar = withInstall(stdin_default$2);
- const [name$1, bem$1] = createNamespace("action-bar-button");
- const actionBarButtonProps = extend({}, routeProps, {
- type: String,
- text: String,
- icon: String,
- color: String,
- loading: Boolean,
- disabled: Boolean
- });
- var stdin_default$1 = defineComponent({
- name: name$1,
- props: actionBarButtonProps,
- setup(props, {
- slots
- }) {
- const route = useRoute();
- const {
- parent,
- index: index2
- } = useParent(ACTION_BAR_KEY);
- const isFirst = computed(() => {
- if (parent) {
- const prev = parent.children[index2.value - 1];
- return !(prev && "isButton" in prev);
- }
- });
- const isLast = computed(() => {
- if (parent) {
- const next = parent.children[index2.value + 1];
- return !(next && "isButton" in next);
- }
- });
- useExpose({
- isButton: true
- });
- return () => {
- const {
- type,
- icon,
- text,
- color,
- loading,
- disabled
- } = props;
- return createVNode(Button, {
- "class": bem$1([type, {
- last: isLast.value,
- first: isFirst.value
- }]),
- "size": "large",
- "type": type,
- "icon": icon,
- "color": color,
- "loading": loading,
- "disabled": disabled,
- "onClick": route
- }, {
- default: () => [slots.default ? slots.default() : text]
- });
- };
- }
- });
- const ActionBarButton = withInstall(stdin_default$1);
- const [name, bem, t] = createNamespace("dialog");
- const dialogProps = extend({}, popupSharedProps, {
- title: String,
- theme: String,
- width: numericProp,
- message: [String, Function],
- callback: Function,
- allowHtml: Boolean,
- className: unknownProp,
- transition: makeStringProp("van-dialog-bounce"),
- messageAlign: String,
- closeOnPopstate: truthProp,
- showCancelButton: Boolean,
- cancelButtonText: String,
- cancelButtonColor: String,
- cancelButtonDisabled: Boolean,
- confirmButtonText: String,
- confirmButtonColor: String,
- confirmButtonDisabled: Boolean,
- showConfirmButton: truthProp,
- closeOnClickOverlay: Boolean
- });
- const popupInheritKeys = [...popupSharedPropKeys, "transition", "closeOnPopstate"];
- var stdin_default = defineComponent({
- name,
- props: dialogProps,
- emits: ["confirm", "cancel", "keydown", "update:show"],
- setup(props, {
- emit,
- slots
- }) {
- const root = ref();
- const loading = reactive({
- confirm: false,
- cancel: false
- });
- const updateShow = (value) => emit("update:show", value);
- const close = (action) => {
- var _a;
- updateShow(false);
- (_a = props.callback) == null ? void 0 : _a.call(props, action);
- };
- const getActionHandler = (action) => () => {
- if (!props.show) {
- return;
- }
- emit(action);
- if (props.beforeClose) {
- loading[action] = true;
- callInterceptor(props.beforeClose, {
- args: [action],
- done() {
- close(action);
- loading[action] = false;
- },
- canceled() {
- loading[action] = false;
- }
- });
- } else {
- close(action);
- }
- };
- const onCancel = getActionHandler("cancel");
- const onConfirm = getActionHandler("confirm");
- const onKeydown = withKeys((event) => {
- var _a, _b;
- if (event.target !== ((_b = (_a = root.value) == null ? void 0 : _a.popupRef) == null ? void 0 : _b.value)) {
- return;
- }
- const onEventType = {
- Enter: props.showConfirmButton ? onConfirm : noop,
- Escape: props.showCancelButton ? onCancel : noop
- };
- onEventType[event.key]();
- emit("keydown", event);
- }, ["enter", "esc"]);
- const renderTitle = () => {
- const title = slots.title ? slots.title() : props.title;
- if (title) {
- return createVNode("div", {
- "class": bem("header", {
- isolated: !props.message && !slots.default
- })
- }, [title]);
- }
- };
- const renderMessage = (hasTitle) => {
- const {
- message,
- allowHtml,
- messageAlign
- } = props;
- const classNames = bem("message", {
- "has-title": hasTitle,
- [messageAlign]: messageAlign
- });
- const content = isFunction(message) ? message() : message;
- if (allowHtml && typeof content === "string") {
- return createVNode("div", {
- "class": classNames,
- "innerHTML": content
- }, null);
- }
- return createVNode("div", {
- "class": classNames
- }, [content]);
- };
- const renderContent = () => {
- if (slots.default) {
- return createVNode("div", {
- "class": bem("content")
- }, [slots.default()]);
- }
- const {
- title,
- message,
- allowHtml
- } = props;
- if (message) {
- const hasTitle = !!(title || slots.title);
- return createVNode("div", {
- "key": allowHtml ? 1 : 0,
- "class": bem("content", {
- isolated: !hasTitle
- })
- }, [renderMessage(hasTitle)]);
- }
- };
- const renderButtons = () => createVNode("div", {
- "class": [BORDER_TOP, bem("footer")]
- }, [props.showCancelButton && createVNode(Button, {
- "size": "large",
- "text": props.cancelButtonText || t("cancel"),
- "class": bem("cancel"),
- "style": {
- color: props.cancelButtonColor
- },
- "loading": loading.cancel,
- "disabled": props.cancelButtonDisabled,
- "onClick": onCancel
- }, null), props.showConfirmButton && createVNode(Button, {
- "size": "large",
- "text": props.confirmButtonText || t("confirm"),
- "class": [bem("confirm"), {
- [BORDER_LEFT]: props.showCancelButton
- }],
- "style": {
- color: props.confirmButtonColor
- },
- "loading": loading.confirm,
- "disabled": props.confirmButtonDisabled,
- "onClick": onConfirm
- }, null)]);
- const renderRoundButtons = () => createVNode(ActionBar, {
- "class": bem("footer")
- }, {
- default: () => [props.showCancelButton && createVNode(ActionBarButton, {
- "type": "warning",
- "text": props.cancelButtonText || t("cancel"),
- "class": bem("cancel"),
- "color": props.cancelButtonColor,
- "loading": loading.cancel,
- "disabled": props.cancelButtonDisabled,
- "onClick": onCancel
- }, null), props.showConfirmButton && createVNode(ActionBarButton, {
- "type": "danger",
- "text": props.confirmButtonText || t("confirm"),
- "class": bem("confirm"),
- "color": props.confirmButtonColor,
- "loading": loading.confirm,
- "disabled": props.confirmButtonDisabled,
- "onClick": onConfirm
- }, null)]
- });
- const renderFooter = () => {
- if (slots.footer) {
- return slots.footer();
- }
- return props.theme === "round-button" ? renderRoundButtons() : renderButtons();
- };
- return () => {
- const {
- width,
- title,
- theme,
- message,
- className
- } = props;
- return createVNode(Popup, mergeProps({
- "ref": root,
- "role": "dialog",
- "class": [bem([theme]), className],
- "style": {
- width: addUnit(width)
- },
- "tabindex": 0,
- "aria-labelledby": title || message,
- "onKeydown": onKeydown,
- "onUpdate:show": updateShow
- }, pick(props, popupInheritKeys)), {
- default: () => [renderTitle(), renderContent(), renderFooter()]
- });
- };
- }
- });
- let instance;
- const DEFAULT_OPTIONS = {
- title: "",
- width: "",
- theme: null,
- message: "",
- overlay: true,
- callback: null,
- teleport: "body",
- className: "",
- allowHtml: false,
- lockScroll: true,
- transition: void 0,
- beforeClose: null,
- overlayClass: "",
- overlayStyle: void 0,
- messageAlign: "",
- cancelButtonText: "",
- cancelButtonColor: null,
- cancelButtonDisabled: false,
- confirmButtonText: "",
- confirmButtonColor: null,
- confirmButtonDisabled: false,
- showConfirmButton: true,
- showCancelButton: false,
- closeOnPopstate: true,
- closeOnClickOverlay: false
- };
- let currentOptions = extend({}, DEFAULT_OPTIONS);
- function initInstance() {
- const Wrapper = {
- setup() {
- const {
- state,
- toggle
- } = usePopupState();
- return () => createVNode(stdin_default, mergeProps(state, {
- "onUpdate:show": toggle
- }), null);
- }
- };
- ({
- instance
- } = mountComponent(Wrapper));
- }
- function showDialog(options) {
- if (!inBrowser) {
- return Promise.resolve(void 0);
- }
- return new Promise((resolve, reject) => {
- if (!instance) {
- initInstance();
- }
- instance.open(extend({}, currentOptions, options, {
- callback: (action) => {
- (action === "confirm" ? resolve : reject)(action);
- }
- }));
- });
- }
- const showConfirmDialog = (options) => showDialog(extend({
- showCancelButton: true
- }, options));
- const index$2 = "";
- const index$1 = "";
- const index = "";
- export {
- showConfirmDialog as a,
- stdin_default as s
- };
|