index.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 index_1 = require("../NormalLayout/index");
  24. require("./index.css");
  25. var Words = [
  26. { content: 'You can do anything, but not everything.' },
  27. { content: 'Those who dare to fail miserably can achieve greatly.' },
  28. { content: 'You miss 100 percent of the shots you never take.' },
  29. { content: 'Those who believe in telekinetics, raise my hand.' },
  30. { content: 'I’d rather live with a good question than a bad answer.' }
  31. ];
  32. var fakeData = function () {
  33. var Y = 0;
  34. return Words.map(function (item, index) {
  35. if (index % 4 === 0)
  36. Y++;
  37. return __assign({}, item, { GridX: index % 4 * 4, GridY: Y * 4, w: 4, h: 2, key: index + '' });
  38. });
  39. };
  40. var storeLayout = void 666;
  41. var LayoutRestore = /** @class */ (function (_super) {
  42. __extends(LayoutRestore, _super);
  43. function LayoutRestore() {
  44. var _this = _super !== null && _super.apply(this, arguments) || this;
  45. _this.handleOnDragEnd = function () {
  46. var newLayout = _this.dragactNode.getLayout();
  47. var parsedLayout = JSON.stringify(newLayout);
  48. localStorage.setItem('layout', parsedLayout);
  49. };
  50. _this.renderDragact = function () {
  51. var margin = [5, 5];
  52. var dragactInit = {
  53. width: 600,
  54. col: 12,
  55. rowHeight: 800 / 12,
  56. margin: margin,
  57. className: 'normal-layout',
  58. layout: storeLayout ? storeLayout : fakeData(),
  59. placeholder: true
  60. };
  61. return (React.createElement(dragact_1.Dragact, __assign({}, dragactInit, { ref: function (node) { return node ? _this.dragactNode = node : null; }, onDragEnd: _this.handleOnDragEnd }), function (item, provided) {
  62. return React.createElement(index_1.Card, { item: item, provided: provided });
  63. }));
  64. };
  65. return _this;
  66. }
  67. LayoutRestore.prototype.componentWillMount = function () {
  68. var lastLayout = localStorage.getItem('layout');
  69. if (lastLayout) {
  70. storeLayout = JSON.parse(lastLayout);
  71. }
  72. };
  73. LayoutRestore.prototype.render = function () {
  74. return (React.createElement("div", { style: { display: 'flex', justifyContent: 'center' } },
  75. React.createElement("div", null,
  76. React.createElement("h1", { style: { textAlign: 'center' } }, "\u5B58\u50A8\u5E03\u5C40 Demo"),
  77. this.renderDragact())));
  78. };
  79. return LayoutRestore;
  80. }(React.Component));
  81. exports.LayoutRestore = LayoutRestore;