index.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return function (d, b) {
  7. extendStatics(d, b);
  8. function __() { this.constructor = d; }
  9. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  10. };
  11. })();
  12. var __assign = (this && this.__assign) || Object.assign || function(t) {
  13. for (var s, i = 1, n = arguments.length; i < n; i++) {
  14. s = arguments[i];
  15. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  16. t[p] = s[p];
  17. }
  18. return t;
  19. };
  20. Object.defineProperty(exports, "__esModule", { value: true });
  21. var React = require("react");
  22. var dragact_1 = require("../../src/lib/dragact");
  23. var Words = [
  24. { content: 'You can do anything, but not everything.' },
  25. { content: 'Those who dare to fail miserably can achieve greatly.' },
  26. { content: 'You miss 100 percent of the shots you never take.' },
  27. { content: 'Those who believe in telekinetics, raise my hand.' },
  28. { content: 'I’d rather live with a good question than a bad answer.' }
  29. ];
  30. var Card = function (_a) {
  31. var item = _a.item, provided = _a.provided, onDelete = _a.onDelete;
  32. return (React.createElement("div", __assign({ className: "layout-Item" }, provided.props, provided.dragHandle),
  33. React.createElement("div", { style: {
  34. position: 'absolute',
  35. width: 10,
  36. height: 10,
  37. right: 15,
  38. top: 5,
  39. cursor: 'pointer'
  40. }, onClick: function () { return onDelete(item.key); } }, "\u274C"),
  41. React.createElement("div", { style: { padding: 5, textAlign: 'center', color: '#595959' } }, item.content)));
  42. };
  43. var fakeData = function () {
  44. var Y = 0;
  45. return Words.map(function (item, index) {
  46. if (index % 4 === 0)
  47. Y++;
  48. return __assign({}, item, { GridX: (index % 4) * 4, GridY: Y * 4, w: 4, h: 3, key: index });
  49. });
  50. };
  51. var makeOne = function () {
  52. return { content: 'added', GridX: 0, GridY: 0, w: 4, h: 3, key: Date.now() };
  53. };
  54. var AddRemove = /** @class */ (function (_super) {
  55. __extends(AddRemove, _super);
  56. function AddRemove() {
  57. var _this = _super !== null && _super.apply(this, arguments) || this;
  58. _this.state = {
  59. layout: fakeData()
  60. };
  61. _this.handleClick = function () {
  62. var change = _this.state.layout.map(function (item) {
  63. return __assign({}, item, { content: '21312' });
  64. });
  65. _this.setState({
  66. layout: change.concat([makeOne()])
  67. });
  68. };
  69. _this.hanldeOnDelete = function (key) {
  70. var layout = _this.state.layout.filter(function (item) {
  71. if (item.key !== key) {
  72. return item;
  73. }
  74. });
  75. _this.setState({
  76. layout: layout
  77. });
  78. };
  79. return _this;
  80. }
  81. AddRemove.prototype.componentDidMount = function () { };
  82. AddRemove.prototype.render = function () {
  83. var _this = this;
  84. var margin = [5, 5];
  85. var dragactInit = {
  86. width: 600,
  87. col: 12,
  88. rowHeight: 800 / 12,
  89. margin: margin,
  90. className: 'normal-layout',
  91. layout: this.state.layout,
  92. placeholder: true
  93. };
  94. return (React.createElement("div", null,
  95. React.createElement("div", { style: { display: 'flex', justifyContent: 'center' } },
  96. React.createElement("div", null,
  97. React.createElement("h1", { style: { textAlign: 'center' } }, "AddRemove Demo"),
  98. React.createElement("h3", { style: { textAlign: 'center' } }, "\u5728\u8FD9\u4E2A\u5E03\u5C40\u4E2D\uFF0C\u65B0\u589E\u4E00\u4E2A\u5E03\u5C40\uFF0C\u4F1A\u65B0\u52A0\u5165\u4E00\u4E2A\u5E03\u5C40"),
  99. React.createElement("button", { onClick: this.handleClick }, "\u65B0\u589E"),
  100. React.createElement(dragact_1.Dragact, __assign({}, dragactInit), function (item, provided) {
  101. return (React.createElement(Card, { item: item, provided: provided, onDelete: _this.hanldeOnDelete }));
  102. })))));
  103. };
  104. return AddRemove;
  105. }(React.Component));
  106. exports.AddRemove = AddRemove;