index.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = Object.setPrototypeOf ||
  3. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  4. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  5. return function (d, b) {
  6. extendStatics(d, b);
  7. function __() { this.constructor = d; }
  8. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  9. };
  10. })();
  11. var __assign = (this && this.__assign) || Object.assign || function(t) {
  12. for (var s, i = 1, n = arguments.length; i < n; i++) {
  13. s = arguments[i];
  14. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
  15. t[p] = s[p];
  16. }
  17. return t;
  18. };
  19. import * as React from 'react';
  20. import { Dragact } from '../lib/dragact';
  21. import './index.css';
  22. var Words = [
  23. { content: 'You can do anything, but not everything.' },
  24. { content: 'Those who dare to fail miserably can achieve greatly.' },
  25. { content: 'You miss 100 percent of the shots you never take.' },
  26. { content: 'Those who believe in telekinetics, raise my hand.' },
  27. { content: 'I’d rather live with a good question than a bad answer.' }
  28. ];
  29. var fakeData = function () {
  30. var Y = 0;
  31. return Words.map(function (item, index) {
  32. if (index % 4 === 0)
  33. Y++;
  34. return __assign({}, item, { GridX: index % 4 * 4, GridY: Y * 4, w: 4, h: 2, key: index + '' });
  35. });
  36. };
  37. var Card = function (props) {
  38. var item = props.item;
  39. return (React.createElement("div", { className: 'layout-Item' },
  40. React.createElement("div", { style: { padding: 5, textAlign: 'center', color: '#595959' } }, item.content)));
  41. };
  42. var storeLayout = void 666;
  43. var LayoutRestore = /** @class */ (function (_super) {
  44. __extends(LayoutRestore, _super);
  45. function LayoutRestore() {
  46. var _this = _super !== null && _super.apply(this, arguments) || this;
  47. _this.handleOnDragEnd = function () {
  48. var newLayout = _this.dragactNode.getLayout();
  49. var parsedLayout = JSON.stringify(newLayout);
  50. localStorage.setItem('layout', parsedLayout);
  51. };
  52. _this.renderDragact = function () {
  53. var margin = [5, 5];
  54. var dragactInit = {
  55. width: 600,
  56. col: 12,
  57. rowHeight: 800 / 12,
  58. margin: margin,
  59. className: 'normal-layout',
  60. layout: storeLayout ? storeLayout : fakeData(),
  61. placeholder: true
  62. };
  63. return (React.createElement(Dragact, __assign({}, dragactInit, { ref: function (node) { return node ? _this.dragactNode = node : null; }, onDragEnd: _this.handleOnDragEnd }), function (item) {
  64. return React.createElement(Card, { item: item });
  65. }));
  66. };
  67. return _this;
  68. }
  69. LayoutRestore.prototype.componentWillMount = function () {
  70. var lastLayout = localStorage.getItem('layout');
  71. if (lastLayout) {
  72. storeLayout = JSON.parse(lastLayout);
  73. }
  74. };
  75. LayoutRestore.prototype.render = function () {
  76. return (React.createElement("div", { style: { display: 'flex', justifyContent: 'center' } },
  77. React.createElement("div", null,
  78. React.createElement("h1", { style: { textAlign: 'center' } }, "\u5B58\u50A8\u5E03\u5C40 Demo"),
  79. this.renderDragact())));
  80. };
  81. return LayoutRestore;
  82. }(React.Component));
  83. export { LayoutRestore };