通用评论

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. "use strict";
  2. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  3. var _react = require("react");
  4. var _react2 = _interopRequireDefault(_react);
  5. var _reactDom = require("react-dom");
  6. var _reactDom2 = _interopRequireDefault(_reactDom);
  7. var _App = require("./App");
  8. var _App2 = _interopRequireDefault(_App);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. // import registerServiceWorker from "./registerServiceWorker";
  11. var Index = function Index(props) {
  12. return _react2.default.createElement(
  13. _App2.default,
  14. _extends({ showAlertComment: true, showAlertReply: true, showAlertFavor: true, showError: true }, props),
  15. _react2.default.createElement(_App.Editor, _extends({ maxUpload: 9, autoFocus: true }, props.editorProps))
  16. );
  17. };
  18. /**
  19. * 渲染评论组件
  20. * @param {object} config 编辑器配置
  21. * - {string} id 渲染评论的DOM的 ID
  22. * - {number} type 评论的 type
  23. * - {string} businessId 评论的 businessId
  24. * - {string} API, API 前缀, 默认 http://api.links123.net/comment/v1
  25. */
  26. function renderComment(config) {
  27. if (!config.id) {
  28. throw new Error("id is required");
  29. }
  30. if (!config.type) {
  31. throw new Error("type is required");
  32. }
  33. if (!config.businessId) {
  34. // throw new Error("businessId is required");
  35. config.businessId = "test";
  36. console.warn("没有传入 businessId 参数,默认使用: test");
  37. }
  38. if (!config.API) {
  39. // throw new Error("API is required");
  40. config.API = "http://api.links123.net/comment/v1";
  41. console.warn("没有传入 API 参数,默认使用: http://api.links123.net/comment/v1");
  42. }
  43. _reactDom2.default.render(_react2.default.createElement(Index, config), document.getElementById(config.id));
  44. // registerServiceWorker();
  45. }
  46. window.renderComment = renderComment;
  47. if (process.env.NODE_ENV !== "production") {
  48. renderComment({
  49. id: "root-comment",
  50. type: 1,
  51. businessId: "test",
  52. businessUserId: 4,
  53. userId: 71299,
  54. onCountChange: function onCountChange(c) {
  55. console.log(c);
  56. },
  57. editorProps: {
  58. // emojiPopoverPlacement: "bottom",
  59. // uploadPopoverPlacement: "top"
  60. }
  61. });
  62. }
  63. // renderComment({
  64. // id: "root-comment",
  65. // type: 1,
  66. // businessId: "test",
  67. // API: 'http://api.links123.net/comment/v1',
  68. // });
  69. //# sourceMappingURL=index.js.map