ShareSheet.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. });
  22. module.exports = __toCommonJS(stdin_exports);
  23. var import_vue = require("vue");
  24. var import_vue2 = 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 popupInheritKeys = [...import_shared.popupSharedPropKeys, "round", "closeOnPopstate", "safeAreaInsetBottom"];
  30. const iconMap = {
  31. qq: "qq",
  32. link: "link-o",
  33. weibo: "weibo",
  34. qrcode: "qr",
  35. poster: "photo-o",
  36. wechat: "wechat",
  37. "weapp-qrcode": "miniprogram-o",
  38. "wechat-moments": "wechat-moments"
  39. };
  40. const [name, bem, t] = (0, import_utils.createNamespace)("share-sheet");
  41. const shareSheetProps = (0, import_utils.extend)({}, import_shared.popupSharedProps, {
  42. title: String,
  43. round: import_utils.truthProp,
  44. options: (0, import_utils.makeArrayProp)(),
  45. cancelText: String,
  46. description: String,
  47. closeOnPopstate: import_utils.truthProp,
  48. safeAreaInsetBottom: import_utils.truthProp
  49. });
  50. var stdin_default = (0, import_vue2.defineComponent)({
  51. name,
  52. props: shareSheetProps,
  53. emits: ["cancel", "select", "update:show"],
  54. setup(props, {
  55. emit,
  56. slots
  57. }) {
  58. const updateShow = (value) => emit("update:show", value);
  59. const onCancel = () => {
  60. updateShow(false);
  61. emit("cancel");
  62. };
  63. const onSelect = (option, index) => emit("select", option, index);
  64. const renderHeader = () => {
  65. const title = slots.title ? slots.title() : props.title;
  66. const description = slots.description ? slots.description() : props.description;
  67. if (title || description) {
  68. return (0, import_vue.createVNode)("div", {
  69. "class": bem("header")
  70. }, [title && (0, import_vue.createVNode)("h2", {
  71. "class": bem("title")
  72. }, [title]), description && (0, import_vue.createVNode)("span", {
  73. "class": bem("description")
  74. }, [description])]);
  75. }
  76. };
  77. const renderIcon = (icon) => {
  78. if (iconMap[icon]) {
  79. return (0, import_vue.createVNode)("div", {
  80. "class": bem("icon", [icon])
  81. }, [(0, import_vue.createVNode)(import_icon.Icon, {
  82. "name": iconMap[icon] || icon
  83. }, null)]);
  84. }
  85. return (0, import_vue.createVNode)("img", {
  86. "src": icon,
  87. "class": bem("image-icon")
  88. }, null);
  89. };
  90. const renderOption = (option, index) => {
  91. const {
  92. name: name2,
  93. icon,
  94. className,
  95. description
  96. } = option;
  97. return (0, import_vue.createVNode)("div", {
  98. "role": "button",
  99. "tabindex": 0,
  100. "class": [bem("option"), className, import_utils.HAPTICS_FEEDBACK],
  101. "onClick": () => onSelect(option, index)
  102. }, [renderIcon(icon), name2 && (0, import_vue.createVNode)("span", {
  103. "class": bem("name")
  104. }, [name2]), description && (0, import_vue.createVNode)("span", {
  105. "class": bem("option-description")
  106. }, [description])]);
  107. };
  108. const renderOptions = (options, border) => (0, import_vue.createVNode)("div", {
  109. "class": bem("options", {
  110. border
  111. })
  112. }, [options.map(renderOption)]);
  113. const renderRows = () => {
  114. const {
  115. options
  116. } = props;
  117. if (Array.isArray(options[0])) {
  118. return options.map((item, index) => renderOptions(item, index !== 0));
  119. }
  120. return renderOptions(options);
  121. };
  122. const renderCancelButton = () => {
  123. var _a;
  124. const cancelText = (_a = props.cancelText) != null ? _a : t("cancel");
  125. if (slots.cancel || cancelText) {
  126. return (0, import_vue.createVNode)("button", {
  127. "type": "button",
  128. "class": bem("cancel"),
  129. "onClick": onCancel
  130. }, [slots.cancel ? slots.cancel() : cancelText]);
  131. }
  132. };
  133. return () => (0, import_vue.createVNode)(import_popup.Popup, (0, import_vue.mergeProps)({
  134. "class": bem(),
  135. "position": "bottom",
  136. "onUpdate:show": updateShow
  137. }, (0, import_utils.pick)(props, popupInheritKeys)), {
  138. default: () => [renderHeader(), renderRows(), renderCancelButton()]
  139. });
  140. }
  141. });