ShareSheet.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name2 in all)
  7. __defProp(target, name2, { get: all[name2], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. default: () => stdin_default,
  21. shareSheetProps: () => shareSheetProps
  22. });
  23. module.exports = __toCommonJS(stdin_exports);
  24. var import_vue = require("vue");
  25. var import_utils = require("../utils");
  26. var import_shared = require("../popup/shared");
  27. var import_icon = require("../icon");
  28. var import_popup = require("../popup");
  29. const isImage = (name2) => name2 == null ? void 0 : name2.includes("/");
  30. const popupInheritKeys = [...import_shared.popupSharedPropKeys, "round", "closeOnPopstate", "safeAreaInsetBottom"];
  31. const iconMap = {
  32. qq: "qq",
  33. link: "link-o",
  34. weibo: "weibo",
  35. qrcode: "qr",
  36. poster: "photo-o",
  37. wechat: "wechat",
  38. "weapp-qrcode": "miniprogram-o",
  39. "wechat-moments": "wechat-moments"
  40. };
  41. const [name, bem, t] = (0, import_utils.createNamespace)("share-sheet");
  42. const shareSheetProps = (0, import_utils.extend)({}, import_shared.popupSharedProps, {
  43. title: String,
  44. round: import_utils.truthProp,
  45. options: (0, import_utils.makeArrayProp)(),
  46. cancelText: String,
  47. description: String,
  48. closeOnPopstate: import_utils.truthProp,
  49. safeAreaInsetBottom: import_utils.truthProp
  50. });
  51. var stdin_default = (0, import_vue.defineComponent)({
  52. name,
  53. props: shareSheetProps,
  54. emits: ["cancel", "select", "update:show"],
  55. setup(props, {
  56. emit,
  57. slots
  58. }) {
  59. const updateShow = (value) => emit("update:show", value);
  60. const onCancel = () => {
  61. updateShow(false);
  62. emit("cancel");
  63. };
  64. const onSelect = (option, index) => emit("select", option, index);
  65. const renderHeader = () => {
  66. const title = slots.title ? slots.title() : props.title;
  67. const description = slots.description ? slots.description() : props.description;
  68. if (title || description) {
  69. return (0, import_vue.createVNode)("div", {
  70. "class": bem("header")
  71. }, [title && (0, import_vue.createVNode)("h2", {
  72. "class": bem("title")
  73. }, [title]), description && (0, import_vue.createVNode)("span", {
  74. "class": bem("description")
  75. }, [description])]);
  76. }
  77. };
  78. const renderIcon = (icon) => {
  79. if (isImage(icon)) {
  80. return (0, import_vue.createVNode)("img", {
  81. "src": icon,
  82. "class": bem("image-icon")
  83. }, null);
  84. }
  85. return (0, import_vue.createVNode)("div", {
  86. "class": bem("icon", [icon])
  87. }, [(0, import_vue.createVNode)(import_icon.Icon, {
  88. "name": iconMap[icon] || icon
  89. }, null)]);
  90. };
  91. const renderOption = (option, index) => {
  92. const {
  93. name: name2,
  94. icon,
  95. className,
  96. description
  97. } = option;
  98. return (0, import_vue.createVNode)("div", {
  99. "role": "button",
  100. "tabindex": 0,
  101. "class": [bem("option"), className, import_utils.HAPTICS_FEEDBACK],
  102. "onClick": () => onSelect(option, index)
  103. }, [renderIcon(icon), name2 && (0, import_vue.createVNode)("span", {
  104. "class": bem("name")
  105. }, [name2]), description && (0, import_vue.createVNode)("span", {
  106. "class": bem("option-description")
  107. }, [description])]);
  108. };
  109. const renderOptions = (options, border) => (0, import_vue.createVNode)("div", {
  110. "class": bem("options", {
  111. border
  112. })
  113. }, [options.map(renderOption)]);
  114. const renderRows = () => {
  115. const {
  116. options
  117. } = props;
  118. if (Array.isArray(options[0])) {
  119. return options.map((item, index) => renderOptions(item, index !== 0));
  120. }
  121. return renderOptions(options);
  122. };
  123. const renderCancelButton = () => {
  124. var _a;
  125. const cancelText = (_a = props.cancelText) != null ? _a : t("cancel");
  126. if (slots.cancel || cancelText) {
  127. return (0, import_vue.createVNode)("button", {
  128. "type": "button",
  129. "class": bem("cancel"),
  130. "onClick": onCancel
  131. }, [slots.cancel ? slots.cancel() : cancelText]);
  132. }
  133. };
  134. return () => (0, import_vue.createVNode)(import_popup.Popup, (0, import_vue.mergeProps)({
  135. "class": bem(),
  136. "position": "bottom",
  137. "onUpdate:show": updateShow
  138. }, (0, import_utils.pick)(props, popupInheritKeys)), {
  139. default: () => [renderHeader(), renderRows(), renderCancelButton()]
  140. });
  141. }
  142. });