gwchq-textjam 0.1.90 → 0.1.91

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 +29 -16
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -368547,15 +368547,16 @@ const Tooltip_1 = __importDefault(__webpack_require__(26982));
368547
368547
  const useHover_1 = __webpack_require__(78556);
368548
368548
  const HistoryButton = ({ className }) => {
368549
368549
  const project = (0, stores_1.useAppSelector)((state) => state.editor.project);
368550
+ const commits = (0, stores_1.useAppSelector)((state) => state.editor.commits);
368550
368551
  const ref = (0, react_1.useRef)(null);
368551
368552
  const { hovered, hoverProps } = (0, useHover_1.useHover)();
368552
368553
  const [isContextOpen, setIsContextOpen] = (0, react_1.useState)(false);
368553
368554
  const handleClick = () => {
368554
368555
  setIsContextOpen((prev) => !prev);
368555
368556
  };
368556
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.btnContainer, ...hoverProps, children: [(0, jsx_runtime_1.jsx)(Tooltip_1.default, { message: "Nothing here yet! Once you save your work, versions will appear here so you can restore them.", visible: hovered && !project.commits?.length, position: "bottom" }), (0, jsx_runtime_1.jsx)(Button_1.default, { buttonRef: ref, className: (0, classnames_1.default)(styles_module_scss_1.default.historyButton, className, {
368557
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.btnContainer, ...hoverProps, children: [(0, jsx_runtime_1.jsx)(Tooltip_1.default, { message: "Nothing here yet! Once you save your work, versions will appear here so you can restore them.", visible: hovered && !commits?.length, position: "bottom" }), (0, jsx_runtime_1.jsx)(Button_1.default, { buttonRef: ref, className: (0, classnames_1.default)(styles_module_scss_1.default.historyButton, className, {
368557
368558
  [styles_module_scss_1.default.historyActive]: isContextOpen,
368558
- }), variant: "tertiary", onClickHandler: handleClick, ButtonIcon: () => (0, SvgIcon_1.SvgIcon)({ SvgElement: history_svg_1.default, size: 24 }), disabled: !project.commits?.length })] }), (0, jsx_runtime_1.jsx)(CommitHistoryMenu_1.CommitHistoryMenu, { isOpen: isContextOpen, onClose: () => setIsContextOpen(false), commits: project.commits, btnRef: ref, activeCommitId: project.commitId ?? undefined })] }));
368559
+ }), variant: "tertiary", onClickHandler: handleClick, ButtonIcon: () => (0, SvgIcon_1.SvgIcon)({ SvgElement: history_svg_1.default, size: 24 }), disabled: !commits?.length })] }), (0, jsx_runtime_1.jsx)(CommitHistoryMenu_1.CommitHistoryMenu, { isOpen: isContextOpen, onClose: () => setIsContextOpen(false), commits: commits, btnRef: ref, activeCommitId: project.commitId ?? undefined })] }));
368559
368560
  };
368560
368561
  exports["default"] = HistoryButton;
368561
368562
 
@@ -370482,14 +370483,14 @@ const ContextMenu = (props) => {
370482
370483
  maxHeight: menuHeight ? `${menuHeight}px` : "fit-content",
370483
370484
  }, position: "anchor", viewScroll: "initial", overflow: "auto", portal: {
370484
370485
  target: portalTarget,
370485
- }, menuClassName: `${styles_module_scss_1.default.contextMenu} ${styles_module_scss_1.default.visibleScrollbar}`, menuItemFocus: { position: "first" }, state: opened ? "open" : "closed", anchorRef: anchorRef, onClose: onClose, anchorPoint: anchorPoint, gap: gap, children: [(0, jsx_runtime_1.jsx)(react_menu_1.MenuHeader, { className: styles_module_scss_1.default.contextHeader, children: title }), menuOptions.map((option, i) => ((0, jsx_runtime_1.jsxs)(react_menu_1.MenuItem, { className: (0, classnames_1.default)(styles_module_scss_1.default.contextItem, {
370486
- [styles_module_scss_1.default.contextItemActive]: option.id === activeItemId,
370486
+ }, menuClassName: `${styles_module_scss_1.default.contextMenu} ${styles_module_scss_1.default.visibleScrollbar}`, menuItemFocus: { position: "first" }, state: opened ? "open" : "closed", anchorRef: anchorRef, onClose: onClose, anchorPoint: anchorPoint, gap: gap, children: [title && ((0, jsx_runtime_1.jsx)(react_menu_1.MenuHeader, { className: styles_module_scss_1.default.contextHeader, children: title })), menuOptions.map((option, i) => ((0, jsx_runtime_1.jsxs)(react_menu_1.MenuItem, { className: (0, classnames_1.default)(styles_module_scss_1.default.contextItem, {
370487
+ [styles_module_scss_1.default.contextItemActive]: option.id && option.id === activeItemId,
370487
370488
  [styles_module_scss_1.default.withDivider]: showDivider && i !== menuOptions.length - 1,
370488
370489
  }), onClick: (e) => {
370489
370490
  e.stopPropagation = true;
370490
370491
  option.action?.();
370491
370492
  onClose();
370492
- }, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.optionContent, children: [option.icon ?? null, option.text] }), hoverElement && option.id !== activeItemId && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.hoverElement, children: hoverElement }))] }, option.id ?? i)))] }));
370493
+ }, children: [(0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.optionContent, children: [option.icon ?? null, option.text] }), hoverElement && ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.hoverElement, children: hoverElement }))] }, option.id ?? i)))] }));
370493
370494
  };
370494
370495
  exports["default"] = ContextMenu;
370495
370496
 
@@ -371573,7 +371574,7 @@ const stores_1 = __webpack_require__(32132);
371573
371574
  const ProjectHistoryModal = () => {
371574
371575
  const dispatch = (0, react_redux_1.useDispatch)();
371575
371576
  const isModalOpen = (0, stores_1.useAppSelector)((state) => state.editor.modalWindowShowing === types_1.ModalType.RESTORE_VERSION);
371576
- const project = (0, stores_1.useAppSelector)((state) => state.editor.project);
371577
+ const commits = (0, stores_1.useAppSelector)((state) => state.editor.commits);
371577
371578
  const args = (0, stores_1.useAppSelector)((state) => state.editor.modalWindowArgs);
371578
371579
  const handleClose = () => dispatch((0, EditorSlice_1.closeModal)());
371579
371580
  const handleRevert = () => {
@@ -371584,7 +371585,7 @@ const ProjectHistoryModal = () => {
371584
371585
  dispatch((0, EditorSlice_1.closeModal)());
371585
371586
  };
371586
371587
  const commitTimestamp = args?.type === types_1.ModalType.RESTORE_VERSION
371587
- ? project.commits?.find((c) => c.id === args.commitId)?.createdAtFormatted
371588
+ ? commits?.find((c) => c.id === args.commitId)?.createdAtFormatted
371588
371589
  : undefined;
371589
371590
  return ((0, jsx_runtime_1.jsx)(BaseModal_1.default, { isOpen: isModalOpen, closeModal: handleClose, withCloseButton: true,
371590
371591
  // @ts-ignore
@@ -372128,7 +372129,7 @@ const createProjectArchive_1 = __webpack_require__(46514);
372128
372129
  const Loading_1 = __importDefault(__webpack_require__(34466));
372129
372130
  const stores_1 = __webpack_require__(32132);
372130
372131
  const WebComponentLoader = (props) => {
372131
- const { locale = "en", projectNameEditable = true, readOnly = false, sidebarOptions = [], project: projectData, saveProject, isSaving, loadProjectContent, projectContent = null, isLoading = false, packageApiUrl, user, isCodeVisible = true, isSharedProject = false, shareLinks, isContentLoaded = null, isSaveSuccess = null, } = props;
372132
+ const { locale = "en", projectNameEditable = true, readOnly = false, sidebarOptions = [], project: projectData, saveProject, isSaving, loadProjectContent, projectContent = null, isLoading = false, packageApiUrl, user, isCodeVisible = true, isSharedProject = false, shareLinks, isContentLoaded = null, isSaveSuccess = null, loadTemplateProjectData, isTemplateDataLoaded = false, } = props;
372132
372133
  const dispatch = (0, react_redux_1.useDispatch)();
372133
372134
  const { t } = (0, react_i18next_1.useTranslation)();
372134
372135
  const [searchParams] = (0, react_router_dom_1.useSearchParams)();
@@ -372190,6 +372191,8 @@ const WebComponentLoader = (props) => {
372190
372191
  isContentLoaded,
372191
372192
  projectContent,
372192
372193
  loadProjectContent,
372194
+ loadTemplateProjectData,
372195
+ isTemplateDataLoaded,
372193
372196
  });
372194
372197
  const onSave = async () => {
372195
372198
  if (!project?.components?.length)
@@ -372872,7 +372875,7 @@ const useIsMounted_1 = __webpack_require__(76314);
372872
372875
  const useProjectCache_1 = __webpack_require__(69557);
372873
372876
  const helpers_1 = __webpack_require__(59578);
372874
372877
  const isFinalLoadingState = (state) => state === types_1.LoadingState.SUCCESS || state === types_1.LoadingState.FAILED;
372875
- const useProject = ({ projectData, projectContent = null, isContentLoaded = null, isLoading = false, loadProjectContent, }) => {
372878
+ const useProject = ({ projectData, projectContent = null, isContentLoaded = null, isLoading = false, loadProjectContent, loadTemplateProjectData, isTemplateDataLoaded, }) => {
372876
372879
  const project = (0, stores_1.useAppSelector)((state) => state.editor.project);
372877
372880
  const loadingState = (0, stores_1.useAppSelector)((state) => state.editor.loading);
372878
372881
  const isPreview = (0, stores_1.useAppSelector)((state) => state.editor.isOutputOnly);
@@ -372926,14 +372929,20 @@ const useProject = ({ projectData, projectContent = null, isContentLoaded = null
372926
372929
  dispatch((0, EditorSlice_1.setCommitIdLoadTriggered)(projectData.commitId));
372927
372930
  return;
372928
372931
  }
372929
- // if no specific commitId provided and not preview, set default data
372930
- if (!projectData?.commitId && !isPreview) {
372931
- setProjectDataFromTemplate(projectData);
372932
- return;
372933
- }
372934
372932
  // if cached data found and it's not outdated, load from cache
372935
372933
  if (cachedProject && !isCurrentOutdated) {
372936
372934
  dispatch((0, EditorSlice_1.setProject)(cachedProject));
372935
+ dispatch((0, EditorSlice_1.setCommits)({ commits: projectData?.commits ?? [] }));
372936
+ return;
372937
+ }
372938
+ // if no specific commitId provided and not preview, set default data
372939
+ if (!projectData?.commitId && !isPreview) {
372940
+ if (!loadTemplateProjectData || isTemplateDataLoaded) {
372941
+ setProjectDataFromTemplate(projectData);
372942
+ }
372943
+ else {
372944
+ loadTemplateProjectData?.();
372945
+ }
372937
372946
  return;
372938
372947
  }
372939
372948
  // if no flows above applied, set failed loading status
@@ -372953,6 +372962,8 @@ const useProject = ({ projectData, projectContent = null, isContentLoaded = null
372953
372962
  isPreview,
372954
372963
  cacheKey,
372955
372964
  isContentLoaded,
372965
+ loadTemplateProjectData,
372966
+ isTemplateDataLoaded,
372956
372967
  ]);
372957
372968
  // Load commit data when commitIdLoadTriggered is set
372958
372969
  (0, react_1.useEffect)(() => {
@@ -372990,12 +373001,14 @@ const useProject = ({ projectData, projectContent = null, isContentLoaded = null
372990
373001
  // ensure this is the latest load call to avoid race conditions
372991
373002
  if (projectLoadCallIdRef.current !== callId)
372992
373003
  return;
373004
+ const { commits, ...rest } = projectData;
372993
373005
  dispatch((0, EditorSlice_1.setProject)({
372994
- ...projectData,
373006
+ ...rest,
372995
373007
  commitId: commitIdLoadTriggered,
372996
373008
  components: loadedProject.components,
372997
373009
  rootDirId: loadedProject.rootDirId,
372998
373010
  }));
373011
+ dispatch((0, EditorSlice_1.setCommits)({ commits: commits ?? [] }));
372999
373012
  })
373000
373013
  .catch((error) => {
373001
373014
  console.error("Error loading project from zip:", error);
@@ -373338,7 +373351,7 @@ exports.EditorSlice = (0, toolkit_1.createSlice)({
373338
373351
  },
373339
373352
  updateProjectCommits: (state, action) => {
373340
373353
  state.project.commitId = action.payload.commitId;
373341
- state.project.commits = action.payload.commits;
373354
+ state.commits = action.payload.commits;
373342
373355
  },
373343
373356
  updateProjectIdentifier: (state, action) => {
373344
373357
  state.project.identifier = action.payload;
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.90",
4
+ "version": "0.1.91",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/GirlsFirst/gwchq-textjam",
7
7
  "author": "Girls Who Code HQ",