gwchq-textjam 0.1.74 → 0.1.76

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +90 -73
  2. package/package.json +11 -2
package/dist/index.js CHANGED
@@ -65649,6 +65649,35 @@ function SvgPythonFile(props) {
65649
65649
 
65650
65650
  /***/ }),
65651
65651
 
65652
+ /***/ 48268:
65653
+ /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
65654
+
65655
+ __webpack_require__.r(__webpack_exports__);
65656
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
65657
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
65658
+ /* harmony export */ });
65659
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(51649);
65660
+ var _path;
65661
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
65662
+
65663
+ function SvgShare(props) {
65664
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__.createElement("svg", _extends({
65665
+ width: 19,
65666
+ height: 20,
65667
+ fill: "none",
65668
+ xmlns: "http://www.w3.org/2000/svg"
65669
+ }, props), _path || (_path = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__.createElement("path", {
65670
+ d: "M6.031 11.359l6.147 3.582m-.009-9.882L6.031 8.641M17.2 3.7a2.7 2.7 0 11-5.4 0 2.7 2.7 0 015.4 0zM6.4 10A2.7 2.7 0 111 10a2.7 2.7 0 015.4 0zm10.8 6.3a2.7 2.7 0 11-5.4 0 2.7 2.7 0 015.4 0z",
65671
+ stroke: "#003046",
65672
+ strokeWidth: 2,
65673
+ strokeLinecap: "round",
65674
+ strokeLinejoin: "round"
65675
+ })));
65676
+ }
65677
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (SvgShare);
65678
+
65679
+ /***/ }),
65680
+
65652
65681
  /***/ 54275:
65653
65682
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
65654
65683
 
@@ -101698,7 +101727,7 @@ var EditorPanel = _ref => {
101698
101727
 
101699
101728
  /***/ }),
101700
101729
 
101701
- /***/ 6455:
101730
+ /***/ 68065:
101702
101731
  /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
101703
101732
 
101704
101733
  // ESM COMPAT FLAG
@@ -101908,55 +101937,9 @@ var SaveButton = props => {
101908
101937
  }, props));
101909
101938
  };
101910
101939
  /* harmony default export */ const SaveButton_SaveButton = (SaveButton);
101911
- ;// ./src/assets/icons/share.svg
101912
- var share_path;
101913
- function share_extends() { return share_extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, share_extends.apply(null, arguments); }
101914
-
101915
- function SvgShare(props) {
101916
- return /*#__PURE__*/external_react_.createElement("svg", share_extends({
101917
- width: 19,
101918
- height: 20,
101919
- fill: "none",
101920
- xmlns: "http://www.w3.org/2000/svg"
101921
- }, props), share_path || (share_path = /*#__PURE__*/external_react_.createElement("path", {
101922
- d: "M6.031 11.359l6.147 3.582m-.009-9.882L6.031 8.641M17.2 3.7a2.7 2.7 0 11-5.4 0 2.7 2.7 0 015.4 0zM6.4 10A2.7 2.7 0 111 10a2.7 2.7 0 015.4 0zm10.8 6.3a2.7 2.7 0 11-5.4 0 2.7 2.7 0 015.4 0z",
101923
- stroke: "#003046",
101924
- strokeWidth: 2,
101925
- strokeLinecap: "round",
101926
- strokeLinejoin: "round"
101927
- })));
101928
- }
101929
- /* harmony default export */ const share = (SvgShare);
101930
- ;// ./src/components/ShareButton/ShareButton.jsx
101931
-
101932
-
101933
-
101934
-
101935
-
101936
-
101937
-
101938
-
101939
-
101940
- var ShareButton = props => {
101941
- var dispatch = (0,external_react_redux_.useDispatch)();
101942
- var shareLinks = (0,external_react_redux_.useSelector)(state => state.editor.shareLinks);
101943
- var onClickShare = (0,external_react_.useCallback)(/*#__PURE__*/_asyncToGenerator(function* () {
101944
- dispatch((0,EditorSlice.showModal)({
101945
- modal: types.ModalType.SHARE_PROJECT,
101946
- args: {
101947
- canShareProject: true,
101948
- hideCodeUrl: shareLinks.hideCode,
101949
- showCodeUrl: shareLinks.showCode
101950
- }
101951
- }));
101952
- }), [dispatch, shareLinks]);
101953
- return /*#__PURE__*/(0,jsx_runtime.jsx)(Button["default"], (0,objectSpread2/* default */.A)({
101954
- variant: "tertiary",
101955
- ButtonIcon: share,
101956
- onClickHandler: onClickShare
101957
- }, props));
101958
- };
101959
- /* harmony default export */ const ShareButton_ShareButton = (ShareButton);
101940
+ // EXTERNAL MODULE: ./src/components/ShareButton/ShareButton.tsx
101941
+ var ShareButton = __webpack_require__(21422);
101942
+ var ShareButton_default = /*#__PURE__*/__webpack_require__.n(ShareButton);
101960
101943
  ;// ./src/assets/icons/history.svg
101961
101944
  var history_path;
101962
101945
  function history_extends() { return history_extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, history_extends.apply(null, arguments); }
@@ -102049,7 +102032,7 @@ var ProjectBar = _ref => {
102049
102032
  className: ProjectBar_styles_module["default"].wrapper,
102050
102033
  children: [/*#__PURE__*/(0,jsx_runtime.jsx)(RunBar["default"], {}), loading === "success" && /*#__PURE__*/(0,jsx_runtime.jsx)((DownloadButton_default()), {
102051
102034
  className: ProjectBar_styles_module["default"].btnSvg
102052
- }), /*#__PURE__*/(0,jsx_runtime.jsx)(ShareButton_ShareButton, {
102035
+ }), /*#__PURE__*/(0,jsx_runtime.jsx)((ShareButton_default()), {
102053
102036
  className: ProjectBar_styles_module["default"].btnSvg
102054
102037
  })]
102055
102038
  })]
@@ -368455,7 +368438,7 @@ const TextJamEditor = ({ onLogoutClick = () => { }, onViewProfileClick = () => {
368455
368438
  isLoading: false,
368456
368439
  error: null,
368457
368440
  data: null,
368458
- }, shareLinks = { shareCode: "", hideCode: "" }, ...componentProps }) => {
368441
+ }, shareLinks = null, ...componentProps }) => {
368459
368442
  // Default props that match the previous web-component defaults
368460
368443
  const defaultProps = {
368461
368444
  sidebarOptions: [
@@ -368916,7 +368899,6 @@ function HtmlRunner() {
368916
368899
  const readOnly = (0, stores_1.useAppSelector)((state) => state.editor.readOnly);
368917
368900
  const outputOnly = (0, stores_1.useAppSelector)((state) => state.editor.isOutputOnly);
368918
368901
  const dispatch = (0, react_redux_1.useDispatch)();
368919
- const location = (0, react_router_dom_1.useLocation)();
368920
368902
  const output = (0, react_1.useRef)(null);
368921
368903
  const [searchParams, setSearchParams] = (0, react_router_dom_1.useSearchParams)();
368922
368904
  // Using BroadcastChannel to communicate between the main app and the preview tab
@@ -368940,13 +368922,17 @@ function HtmlRunner() {
368940
368922
  defaultPreviewFilePath = page;
368941
368923
  }
368942
368924
  const [runningFilePath, setRunningFilePath] = (0, react_1.useState)(defaultPreviewFilePath);
368943
- const isPreviewMode = location.pathname.includes("/preview");
368925
+ const isPreviewMode = searchParams.get("preview") === "1";
368944
368926
  (0, react_1.useEffect)(() => {
368945
368927
  if (isPreviewMode) {
368946
368928
  dispatch((0, EditorSlice_1.setIsOutputOnly)(true));
368947
368929
  dispatch((0, EditorSlice_2.triggerCodeRun)());
368948
- if (page) {
368949
- setSearchParams({ page }, { replace: true });
368930
+ if (page && isPreviewMode) {
368931
+ setSearchParams((prevParams) => {
368932
+ const updatedParams = new URLSearchParams(prevParams);
368933
+ updatedParams.set("page", page);
368934
+ return updatedParams;
368935
+ }, { replace: true });
368950
368936
  }
368951
368937
  }
368952
368938
  }, [isPreviewMode, page, setSearchParams]);
@@ -369077,7 +369063,7 @@ function HtmlRunner() {
369077
369063
  return () => window.removeEventListener("message", handler);
369078
369064
  }, []);
369079
369065
  const openPreview = () => {
369080
- window.open(`${window.location.href}/preview`, "_blank", "noopener,noreferrer");
369066
+ window.open(`${window.location.href}?preview=1&page=${runningFilePath}`, "_blank", "noopener,noreferrer");
369081
369067
  };
369082
369068
  const openInNewTabLink = ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.previewLink, onClick: openPreview, children: (0, jsx_runtime_1.jsx)(SvgIcon_1.SvgIcon, { SvgElement: open_in_new_tab_svg_1.default, size: 16 }) }));
369083
369069
  const iframeClasses = (0, classnames_1.default)(styles_module_scss_1.default.iframe, {
@@ -371596,6 +371582,44 @@ const SharedProjectName = () => {
371596
371582
  exports["default"] = SharedProjectName;
371597
371583
 
371598
371584
 
371585
+ /***/ }),
371586
+
371587
+ /***/ 21422:
371588
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
371589
+
371590
+
371591
+ var __importDefault = (this && this.__importDefault) || function (mod) {
371592
+ return (mod && mod.__esModule) ? mod : { "default": mod };
371593
+ };
371594
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
371595
+ const jsx_runtime_1 = __webpack_require__(74848);
371596
+ const react_1 = __webpack_require__(51649);
371597
+ const share_svg_1 = __importDefault(__webpack_require__(48268));
371598
+ const Button_1 = __importDefault(__webpack_require__(60232));
371599
+ const react_redux_1 = __webpack_require__(14062);
371600
+ const EditorSlice_1 = __webpack_require__(68512);
371601
+ const types_1 = __webpack_require__(92932);
371602
+ const stores_1 = __webpack_require__(32132);
371603
+ const ShareButton = (props) => {
371604
+ const dispatch = (0, react_redux_1.useDispatch)();
371605
+ const shareLinks = (0, stores_1.useAppSelector)((state) => state.editor.shareLinks);
371606
+ const onClickShare = (0, react_1.useCallback)(async () => {
371607
+ dispatch((0, EditorSlice_1.showModal)({
371608
+ modal: types_1.ModalType.SHARE_PROJECT,
371609
+ args: {
371610
+ type: types_1.ModalType.SHARE_PROJECT,
371611
+ canShareProject: true,
371612
+ hideCodeUrl: shareLinks?.hideCode ?? null,
371613
+ showCodeUrl: shareLinks?.showCode ?? null,
371614
+ },
371615
+ }));
371616
+ }, [dispatch, shareLinks]);
371617
+ const canShare = Boolean(shareLinks);
371618
+ return ((0, jsx_runtime_1.jsx)(Button_1.default, { disabled: !canShare, variant: "tertiary", ButtonIcon: share_svg_1.default, onClickHandler: onClickShare, ...props }));
371619
+ };
371620
+ exports["default"] = ShareButton;
371621
+
371622
+
371599
371623
  /***/ }),
371600
371624
 
371601
371625
  /***/ 82803:
@@ -371692,7 +371716,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
371692
371716
  const jsx_runtime_1 = __webpack_require__(74848);
371693
371717
  const react_1 = __webpack_require__(51649);
371694
371718
  const marked_1 = __webpack_require__(6709);
371695
- const Project_1 = __importDefault(__webpack_require__(6455));
371719
+ const Project_1 = __importDefault(__webpack_require__(68065));
371696
371720
  const Output_1 = __importDefault(__webpack_require__(95148));
371697
371721
  const DefaultMZCriteria_1 = __webpack_require__(98748);
371698
371722
  const WebComponentCustomEvents_1 = __webpack_require__(30272);
@@ -372711,25 +372735,18 @@ const useProjectPersistence = ({ user, project, justLoaded, hasShownSavePrompt,
372711
372735
  // Autosave
372712
372736
  (0, react_1.useEffect)(() => {
372713
372737
  const debouncer = setTimeout(() => {
372714
- if (!project)
372738
+ if (!project || Object.keys(project).length === 0)
372715
372739
  return;
372716
- if ((0, projectHelpers_1.isOwner)(user, project) && project.identifier) {
372717
- if (justLoaded) {
372718
- dispatch((0, EditorSlice_1.expireJustLoaded)());
372719
- }
372720
- saveToIndexedDB(project).catch(console.error);
372740
+ if (justLoaded) {
372741
+ dispatch((0, EditorSlice_1.expireJustLoaded)());
372721
372742
  }
372722
372743
  else {
372723
- if (justLoaded) {
372724
- dispatch((0, EditorSlice_1.expireJustLoaded)());
372725
- }
372726
- else {
372727
- if (!hasShownSavePrompt && user && (0, projectHelpers_1.isOwner)(user, project)) {
372728
- (0, Notifications_1.showSavePrompt)();
372729
- dispatch((0, EditorSlice_1.setHasShownSavePrompt)());
372730
- }
372744
+ if (!hasShownSavePrompt && user && (0, projectHelpers_1.isOwner)(user, project)) {
372745
+ (0, Notifications_1.showSavePrompt)();
372746
+ dispatch((0, EditorSlice_1.setHasShownSavePrompt)());
372731
372747
  }
372732
372748
  }
372749
+ saveToIndexedDB(project).catch(console.error);
372733
372750
  }, autoSaveInterval);
372734
372751
  return () => clearTimeout(debouncer);
372735
372752
  }, [dispatch, project, user, hasShownSavePrompt, onSave]); // eslint-disable-line react-hooks/exhaustive-deps
@@ -372790,7 +372807,7 @@ exports.editorInitialState = {
372790
372807
  error: null,
372791
372808
  isCodeVisible: true,
372792
372809
  isSharedProject: false,
372793
- shareLinks: { shareCode: "", hideCode: "" },
372810
+ shareLinks: null,
372794
372811
  };
372795
372812
  exports.EditorSlice = (0, toolkit_1.createSlice)({
372796
372813
  name: "editor",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gwchq-textjam",
3
3
  "description": "Embeddable React editor used in Raspberry Pi text-based projects.",
4
- "version": "0.1.74",
4
+ "version": "0.1.76",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/GirlsFirst/gwchq-textjam",
7
7
  "author": "Girls Who Code HQ",
@@ -20,7 +20,8 @@
20
20
  "lint": "eslint \"src/**/*.{js,jsx,json}\"",
21
21
  "lint:fix": "eslint --fix \"src/**/*.{js,jsx,json}\"",
22
22
  "stylelint": "stylelint src/**/*.scss",
23
- "test": "jest"
23
+ "test": "jest",
24
+ "prepare": "husky"
24
25
  },
25
26
  "module": "./dist/index.js",
26
27
  "exports": {
@@ -162,6 +163,7 @@
162
163
  "eslint-webpack-plugin": "^2.5.2",
163
164
  "file-loader": "6.1.1",
164
165
  "html-webpack-plugin": "5.6.0",
166
+ "husky": "^9.1.7",
165
167
  "jest": "^29.1.2",
166
168
  "jest-circus": "^29.1.2",
167
169
  "jest-css-modules-transform": "^4.4.2",
@@ -173,6 +175,7 @@
173
175
  "jest-transform-stub": "^2.0.0",
174
176
  "jest-transformer-svg": "^2.0.0",
175
177
  "jest-watch-typeahead": "^2.2.0",
178
+ "lint-staged": "^16.3.2",
176
179
  "mini-css-extract-plugin": "^2.9.4",
177
180
  "mock-match-media": "^0.4.3",
178
181
  "optimize-css-assets-webpack-plugin": "5.0.4",
@@ -216,6 +219,12 @@
216
219
  "workbox-webpack-plugin": "5.1.4",
217
220
  "worker-plugin": "5.0.1"
218
221
  },
222
+ "lint-staged": {
223
+ "*.{js,jsx,ts,tsx,css,scss,md}": [
224
+ "eslint --fix",
225
+ "git add"
226
+ ]
227
+ },
219
228
  "jest": {
220
229
  "roots": [
221
230
  "<rootDir>/src"