@industry-theme/markdown-panels 0.2.22 → 0.2.24

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.
@@ -8,6 +8,11 @@ export interface MarkdownPanelProps extends PanelComponentProps {
8
8
  * This allows the host to control panel state via props instead of context.
9
9
  */
10
10
  filePath?: string | null;
11
+ /**
12
+ * Optional width to pass to DocumentView for layout calculations.
13
+ * Useful when embedding in panels that need responsive width handling.
14
+ */
15
+ width?: number;
11
16
  }
12
17
  /**
13
18
  * MarkdownPanel - A panel for rendering markdown documents with industry theming
@@ -1 +1 @@
1
- {"version":3,"file":"MarkdownPanel.d.ts","sourceRoot":"","sources":["../../src/panels/MarkdownPanel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAS5D,OAAO,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,mBAAmB,EAAmB,MAAM,UAAU,CAAC;AAmBrE,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC7D;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAmatD,CAAC"}
1
+ {"version":3,"file":"MarkdownPanel.d.ts","sourceRoot":"","sources":["../../src/panels/MarkdownPanel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAS5D,OAAO,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,mBAAmB,EAAmB,MAAM,UAAU,CAAC;AAmBrE,MAAM,WAAW,kBAAmB,SAAQ,mBAAmB;IAC7D;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAoetD,CAAC"}
@@ -46751,7 +46751,8 @@ var SlidePresentationBook = ({
46751
46751
  handlePromptCopy,
46752
46752
  fontSizeScale,
46753
46753
  theme: theme2,
46754
- repositoryInfo
46754
+ repositoryInfo,
46755
+ width
46755
46756
  }) => {
46756
46757
  const [isMobile, setIsMobile] = useState(false);
46757
46758
  useEffect(() => {
@@ -47150,7 +47151,8 @@ var SlidePresentationBook = ({
47150
47151
  handlePromptCopy,
47151
47152
  fontSizeScale,
47152
47153
  searchQuery: showSearch ? searchQuery : void 0,
47153
- repositoryInfo
47154
+ repositoryInfo,
47155
+ containerWidth: width
47154
47156
  }) : /* @__PURE__ */ React2__default.createElement("div", {
47155
47157
  style: {
47156
47158
  height: "100%",
@@ -47273,7 +47275,8 @@ var SlidePresentationBook = ({
47273
47275
  handlePromptCopy,
47274
47276
  fontSizeScale,
47275
47277
  searchQuery: showSearch ? searchQuery : void 0,
47276
- repositoryInfo
47278
+ repositoryInfo,
47279
+ containerWidth: width
47277
47280
  }) : /* @__PURE__ */ React2__default.createElement("div", {
47278
47281
  style: {
47279
47282
  height: "100%",
@@ -47465,6 +47468,7 @@ var SlidePresentationBook = ({
47465
47468
  fontSizeScale,
47466
47469
  searchQuery: showSearch ? searchQuery : void 0,
47467
47470
  repositoryInfo,
47471
+ containerWidth: width,
47468
47472
  transparentBackground: true,
47469
47473
  additionalPadding: {
47470
47474
  left: `${theme2.space[4]}px`,
@@ -47511,6 +47515,7 @@ var SlidePresentationBook = ({
47511
47515
  fontSizeScale,
47512
47516
  searchQuery: showSearch ? searchQuery : void 0,
47513
47517
  repositoryInfo,
47518
+ containerWidth: width,
47514
47519
  transparentBackground: true,
47515
47520
  additionalPadding: {
47516
47521
  left: `${theme2.space[2]}px`,
@@ -47581,6 +47586,7 @@ var SlidePresentationBook = ({
47581
47586
  fontSizeScale,
47582
47587
  searchQuery: showSearch ? searchQuery : void 0,
47583
47588
  repositoryInfo,
47589
+ containerWidth: width,
47584
47590
  transparentBackground: false,
47585
47591
  disableScroll: false
47586
47592
  }))) : /* @__PURE__ */ React2__default.createElement("div", {
@@ -47649,6 +47655,7 @@ var DocumentView = ({
47649
47655
  content: content2,
47650
47656
  onCheckboxChange,
47651
47657
  maxWidth = "900px",
47658
+ width,
47652
47659
  slideIdPrefix = "document",
47653
47660
  enableHtmlPopout = true,
47654
47661
  enableKeyboardScrolling = true,
@@ -47693,7 +47700,8 @@ var DocumentView = ({
47693
47700
  handlePromptCopy,
47694
47701
  repositoryInfo,
47695
47702
  transparentBackground,
47696
- editable
47703
+ editable,
47704
+ containerWidth: width
47697
47705
  })));
47698
47706
  };
47699
47707
  function parseMarkdownIntoPresentation2(markdownContent, repositoryInfo) {
@@ -47712,24 +47720,55 @@ const MarkdownPanel = ({
47712
47720
  context,
47713
47721
  actions,
47714
47722
  events,
47715
- filePath: filePathProp
47723
+ filePath: filePathProp,
47724
+ width
47716
47725
  }) => {
47717
- var _a, _b, _c, _d, _e2, _f, _g;
47726
+ var _a, _b, _c, _d, _e2, _f;
47718
47727
  const { theme: theme2 } = useTheme();
47719
47728
  const [viewMode, setViewMode] = useState("document");
47720
47729
  const [currentSlide, setCurrentSlide] = useState(0);
47721
47730
  const [fontSizeScale, setFontSizeScale] = useState(1);
47722
47731
  const [isMobile, setIsMobile] = useState(false);
47723
47732
  const [preferencesLoaded, setPreferencesLoaded] = useState(false);
47733
+ const [propBasedContent, setPropBasedContent] = useState(null);
47724
47734
  useEffect(() => {
47725
- if (filePathProp) {
47735
+ if (!filePathProp) {
47736
+ setPropBasedContent(null);
47737
+ return;
47738
+ }
47739
+ if ((propBasedContent == null ? void 0 : propBasedContent.path) === filePathProp && !propBasedContent.loading) {
47740
+ return;
47741
+ }
47742
+ const loadContent = async () => {
47743
+ var _a2;
47726
47744
  console.log("[MarkdownPanel] Loading file from prop:", filePathProp);
47727
- const setActiveFile = actions == null ? void 0 : actions.setActiveFile;
47728
- if (typeof setActiveFile === "function") {
47729
- setActiveFile(filePathProp);
47745
+ setPropBasedContent({ path: filePathProp, content: "", loading: true, error: null });
47746
+ try {
47747
+ const fileSystem = (_a2 = context.adapters) == null ? void 0 : _a2.fileSystem;
47748
+ if (fileSystem == null ? void 0 : fileSystem.readFile) {
47749
+ const content2 = await fileSystem.readFile(filePathProp);
47750
+ setPropBasedContent({ path: filePathProp, content: content2, loading: false, error: null });
47751
+ } else {
47752
+ const setActiveFile = actions == null ? void 0 : actions.setActiveFile;
47753
+ if (typeof setActiveFile === "function") {
47754
+ await setActiveFile(filePathProp);
47755
+ setPropBasedContent(null);
47756
+ } else {
47757
+ throw new Error("No file reading capability available");
47758
+ }
47759
+ }
47760
+ } catch (err) {
47761
+ console.error("[MarkdownPanel] Failed to load file:", err);
47762
+ setPropBasedContent({
47763
+ path: filePathProp,
47764
+ content: "",
47765
+ loading: false,
47766
+ error: err instanceof Error ? err : new Error(String(err))
47767
+ });
47730
47768
  }
47731
- }
47732
- }, [filePathProp, actions]);
47769
+ };
47770
+ loadContent();
47771
+ }, [filePathProp, (_a = context.adapters) == null ? void 0 : _a.fileSystem, actions]);
47733
47772
  useEffect(() => {
47734
47773
  const checkMobile = () => {
47735
47774
  setIsMobile(window.innerWidth < 768);
@@ -47766,9 +47805,19 @@ const MarkdownPanel = ({
47766
47805
  });
47767
47806
  return unsubscribe;
47768
47807
  }, [events]);
47769
- const activeFile = context.getSlice("active-file");
47770
- const isMarkdown = ((_a = activeFile == null ? void 0 : activeFile.data) == null ? void 0 : _a.type) === "markdown" || ((_c = (_b = activeFile == null ? void 0 : activeFile.data) == null ? void 0 : _b.path) == null ? void 0 : _c.match(/\.(md|mdx|markdown)$/i));
47771
- const markdownContent = ((_d = activeFile == null ? void 0 : activeFile.data) == null ? void 0 : _d.content) || "";
47808
+ const activeFileSlice = context.getSlice("active-file");
47809
+ const usePropBasedContent = filePathProp && (propBasedContent == null ? void 0 : propBasedContent.path) === filePathProp;
47810
+ const activeFile = usePropBasedContent ? {
47811
+ data: {
47812
+ path: propBasedContent.path,
47813
+ content: propBasedContent.content,
47814
+ type: "markdown"
47815
+ },
47816
+ loading: propBasedContent.loading,
47817
+ error: propBasedContent.error
47818
+ } : activeFileSlice;
47819
+ const isMarkdown = ((_b = activeFile == null ? void 0 : activeFile.data) == null ? void 0 : _b.type) === "markdown" || ((_d = (_c = activeFile == null ? void 0 : activeFile.data) == null ? void 0 : _c.path) == null ? void 0 : _d.match(/\.(md|mdx|markdown)$/i));
47820
+ const markdownContent = ((_e2 = activeFile == null ? void 0 : activeFile.data) == null ? void 0 : _e2.content) || "";
47772
47821
  const presentation = useMemo(
47773
47822
  () => parseMarkdownIntoPresentation2(markdownContent),
47774
47823
  [markdownContent]
@@ -47776,17 +47825,18 @@ const MarkdownPanel = ({
47776
47825
  const slides = presentation.slides.map((slide) => slide.location.content);
47777
47826
  const hasSlides = slides.length > 1;
47778
47827
  const repositoryInfo = useMemo(() => {
47779
- var _a2, _b2, _c2;
47780
- const source2 = (_a2 = activeFile == null ? void 0 : activeFile.data) == null ? void 0 : _a2.source;
47828
+ var _a2, _b2;
47829
+ if (usePropBasedContent || !(activeFileSlice == null ? void 0 : activeFileSlice.data)) return void 0;
47830
+ const source2 = "source" in activeFileSlice.data ? activeFileSlice.data.source : void 0;
47781
47831
  if (!source2) return void 0;
47782
- const branch = source2.locationType === "branch" ? source2.location : ((_b2 = source2.metadata) == null ? void 0 : _b2.currentBranch) || "main";
47832
+ const branch = source2.locationType === "branch" ? source2.location : ((_a2 = source2.metadata) == null ? void 0 : _a2.currentBranch) || "main";
47783
47833
  return {
47784
47834
  owner: source2.owner,
47785
47835
  repo: source2.name,
47786
47836
  branch,
47787
- basePath: getBasePath(((_c2 = activeFile == null ? void 0 : activeFile.data) == null ? void 0 : _c2.path) || "")
47837
+ basePath: getBasePath(((_b2 = activeFileSlice == null ? void 0 : activeFileSlice.data) == null ? void 0 : _b2.path) || "")
47788
47838
  };
47789
- }, [(_e2 = activeFile == null ? void 0 : activeFile.data) == null ? void 0 : _e2.source, (_f = activeFile == null ? void 0 : activeFile.data) == null ? void 0 : _f.path]);
47839
+ }, [usePropBasedContent, activeFileSlice == null ? void 0 : activeFileSlice.data]);
47790
47840
  const handleFontSizeIncrease = () => {
47791
47841
  setFontSizeScale((prev) => {
47792
47842
  const newScale = Math.min(prev + 0.1, 3);
@@ -47835,7 +47885,7 @@ const MarkdownPanel = ({
47835
47885
  },
47836
47886
  children: /* @__PURE__ */ jsx("div", { style: { textAlign: "center" }, children: /* @__PURE__ */ jsxs("p", { style: { color: theme2.colors.textSecondary }, children: [
47837
47887
  "Loading ",
47838
- ((_g = activeFile.data) == null ? void 0 : _g.path) || "file",
47888
+ ((_f = activeFile.data) == null ? void 0 : _f.path) || "file",
47839
47889
  "..."
47840
47890
  ] }) })
47841
47891
  }
@@ -48057,7 +48107,8 @@ const MarkdownPanel = ({
48057
48107
  },
48058
48108
  slideIdPrefix: "markdown-panel",
48059
48109
  maxWidth: "100%",
48060
- repositoryInfo
48110
+ repositoryInfo,
48111
+ width
48061
48112
  }
48062
48113
  ) : /* @__PURE__ */ jsx(
48063
48114
  SlidePresentationBook,
@@ -48079,7 +48130,8 @@ const MarkdownPanel = ({
48079
48130
  tocDisplayMode: "sidebar",
48080
48131
  tocSidebarPosition: "left",
48081
48132
  initialTocOpen: false,
48082
- repositoryInfo
48133
+ repositoryInfo,
48134
+ width
48083
48135
  }
48084
48136
  )
48085
48137
  }