Skip to content

Commit cb7d0ed

Browse files
committed
Update build script.
1 parent d7cdefa commit cb7d0ed

File tree

4 files changed

+239
-1
lines changed

4 files changed

+239
-1
lines changed

build-dir/index.js

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
"use strict";
2+
3+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4+
5+
Object.defineProperty(exports, "__esModule", {
6+
value: true
7+
});
8+
exports.default = void 0;
9+
10+
var _react = _interopRequireDefault(require("react"));
11+
12+
require("./retool.css");
13+
14+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15+
16+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
17+
18+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19+
20+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
21+
22+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
23+
24+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
25+
26+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
27+
28+
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
29+
30+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
31+
32+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
33+
34+
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
35+
36+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
37+
38+
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
39+
40+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
41+
42+
var Retool = /*#__PURE__*/function (_React$Component) {
43+
_inherits(Retool, _React$Component);
44+
45+
var _super = _createSuper(Retool);
46+
47+
function Retool(props) {
48+
var _this;
49+
50+
_classCallCheck(this, Retool);
51+
52+
_this = _super.call(this, props);
53+
54+
_defineProperty(_assertThisInitialized(_this), "startListening", function () {
55+
window.addEventListener('message', function (e) {
56+
return _this.handle(e);
57+
});
58+
});
59+
60+
_defineProperty(_assertThisInitialized(_this), "startWatchers", function () {
61+
var watcherKeys = Object.keys(_this.state.elementWatchers);
62+
63+
for (var i = 0; i < watcherKeys.length; i++) {
64+
var key = watcherKeys[i];
65+
var watcher = _this.state.elementWatchers[key];
66+
var selector = watcher.selector;
67+
var node = document.querySelector(selector);
68+
var value = node === null || node === void 0 ? void 0 : node.textContent;
69+
70+
if (value !== watcher.prevValue) {
71+
watcher.prevValue = value;
72+
watcher.iframe.contentWindow.postMessage({
73+
type: 'PARENT_WINDOW_RESULT',
74+
result: value,
75+
id: watcher.queryId,
76+
pageName: watcher.pageName
77+
}, '*');
78+
}
79+
}
80+
81+
setTimeout(_this.startWatchers, 100);
82+
});
83+
84+
_defineProperty(_assertThisInitialized(_this), "createOrReplaceWatcher", function (selector, pageName, queryId) {
85+
var watcherId = pageName + '-' + queryId;
86+
87+
var watchers = _objectSpread({}, _this.state.elementWatchers);
88+
89+
watchers[watcherId] = {
90+
iframe: _this.iframe,
91+
selector: selector,
92+
pageName: pageName,
93+
queryId: queryId,
94+
prevValue: null
95+
};
96+
97+
_this.setState({
98+
elementWatchers: watchers
99+
});
100+
});
101+
102+
_defineProperty(_assertThisInitialized(_this), "handle", function (event) {
103+
if (!_this.iframe.contentWindow) return;
104+
var node;
105+
106+
if (event.data.type === 'PARENT_WINDOW_QUERY') {
107+
var _node;
108+
109+
node = document.querySelector(event.data.selector);
110+
111+
_this.createOrReplaceWatcher(event.data.selector, event.data.pageName, event.data.id);
112+
113+
_this.iframe.contentWindow.postMessage({
114+
type: 'PARENT_WINDOW_RESULT',
115+
result: (_node = node) === null || _node === void 0 ? void 0 : _node.textContent,
116+
id: event.data.id,
117+
pageName: event.data.pageName
118+
}, '*');
119+
}
120+
121+
if (event.data.type === 'PARENT_WINDOW_PREVIEW_QUERY') {
122+
var _node2;
123+
124+
node = document.querySelector(event.data.selector);
125+
126+
_this.iframe.contentWindow.postMessage({
127+
type: 'PARENT_WINDOW_PREVIEW_RESULT',
128+
result: (_node2 = node) === null || _node2 === void 0 ? void 0 : _node2.textContent,
129+
id: event.data.id
130+
}, '*');
131+
}
132+
});
133+
134+
_this.state = {
135+
url: props.url,
136+
elementWatchers: {}
137+
};
138+
return _this;
139+
}
140+
141+
_createClass(Retool, [{
142+
key: "componentDidMount",
143+
value: function componentDidMount() {
144+
this.startListening();
145+
this.startWatchers();
146+
}
147+
}, {
148+
key: "render",
149+
value: function render() {
150+
var _this2 = this;
151+
152+
return /*#__PURE__*/_react.default.createElement("iframe", {
153+
frameBorder: "none",
154+
src: this.state.url,
155+
ref: function ref(e) {
156+
_this2.iframe = e;
157+
}
158+
});
159+
}
160+
}]);
161+
162+
return Retool;
163+
}(_react.default.Component);
164+
165+
var _default = Retool;
166+
exports.default = _default;

build-dir/package.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
{
2+
"name": "react-retool",
3+
"version": "0.1.8",
4+
"private": false,
5+
"repository": {
6+
"type": "git",
7+
"url": "[email protected]:tryretool/react-retool.git"
8+
},
9+
"keywords": [
10+
"react",
11+
"react-component",
12+
"component",
13+
"retool",
14+
"embed-retool"
15+
],
16+
"babel": {
17+
"presets": [
18+
"@babel/preset-react",
19+
"@babel/preset-env"
20+
],
21+
"plugins": [
22+
[
23+
"@babel/plugin-proposal-class-properties"
24+
]
25+
]
26+
},
27+
"dependencies": {
28+
"@testing-library/jest-dom": "^5.11.4",
29+
"@testing-library/react": "^11.1.0",
30+
"@testing-library/user-event": "^12.1.10",
31+
"react": "^17.0.2",
32+
"react-dom": "^17.0.2",
33+
"react-scripts": "4.0.3",
34+
"web-vitals": "^1.0.1"
35+
},
36+
"scripts": {
37+
"start": "react-scripts start",
38+
"build": "react-scripts build",
39+
"test": "react-scripts test",
40+
"eject": "react-scripts eject",
41+
"publish:npm": "rm -rf dist && mkdir dist && babel src/components -d dist --copy-files",
42+
"test:publish": "rm -rf build-dir && mkdir build-dir && babel src/components -d build-dir --copy-files && mv ./build-dir/Retool.js ./build-dir/index.js && cp ./package.json ./build-dir/package.json && npm publish ./build-dir"
43+
},
44+
"eslintConfig": {
45+
"extends": [
46+
"react-app",
47+
"react-app/jest"
48+
]
49+
},
50+
"browserslist": {
51+
"production": [
52+
">0.2%",
53+
"not dead",
54+
"not op_mini all"
55+
],
56+
"development": [
57+
"last 1 chrome version",
58+
"last 1 firefox version",
59+
"last 1 safari version"
60+
]
61+
},
62+
"devDependencies": {
63+
"@babel/cli": "^7.13.16",
64+
"@babel/plugin-proposal-class-properties": "^7.13.0",
65+
"@babel/preset-react": "^7.13.13"
66+
}
67+
}

build-dir/retool.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
iframe {
2+
width: 100%;
3+
height: 100%
4+
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"build": "react-scripts build",
3939
"test": "react-scripts test",
4040
"eject": "react-scripts eject",
41-
"publish:npm": "rm -rf dist && mkdir dist && babel src/components -d dist --copy-files"
41+
"publish:npm": "rm -rf dist && mkdir dist && babel src/components -d dist --copy-files",
42+
"test:publish": "rm -rf build-dir && mkdir build-dir && babel src/components -d build-dir --copy-files && mv ./build-dir/Retool.js ./build-dir/index.js && cp ./package.json ./build-dir/package.json && npm publish ./build-dir"
4243
},
4344
"eslintConfig": {
4445
"extends": [

0 commit comments

Comments
 (0)