Skip to content

Commit ccd6d82

Browse files
Copilotmikebarkmin
andcommitted
Remove sharing functionality and add browser support for VS Code extension
- Add disableSharing prop to LearningMapEditor and EditorToolbar components - Conditionally hide share button when disableSharing is true - Enable disableSharing in VS Code webview - Replace Node.js crypto module with Web Crypto API for browser compatibility - Add "browser" field to package.json for github.dev support - Use crypto.getRandomValues() which works in both Node.js and browser environments Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
1 parent 29b2023 commit ccd6d82

5 files changed

Lines changed: 25 additions & 7 deletions

File tree

packages/learningmap/src/EditorToolbar.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import { getZIndexForNodeType } from "./zIndexHelper";
1313

1414
interface EditorToolbarProps {
1515
defaultLanguage?: string;
16+
disableSharing?: boolean;
1617
}
1718

1819
export const EditorToolbar: React.FC<EditorToolbarProps> = ({
1920
defaultLanguage = "en",
21+
disableSharing = false,
2022
}) => {
2123
const { screenToFlowPosition } = useReactFlow();
2224

@@ -118,9 +120,11 @@ export const EditorToolbar: React.FC<EditorToolbarProps> = ({
118120
<MenuItem onClick={downloadRoadmap}>
119121
<Download size={16} /> <span>{t.download}</span>
120122
</MenuItem>
121-
<MenuItem onClick={postToJsonStore}>
122-
<Share2 size={16} /> <span>{t.share}</span>
123-
</MenuItem>
123+
{!disableSharing && (
124+
<MenuItem onClick={postToJsonStore}>
125+
<Share2 size={16} /> <span>{t.share}</span>
126+
</MenuItem>
127+
)}
124128
<MenuDivider />
125129
<MenuItem onClick={onReset}>
126130
<RotateCcw size={16} /> <span>{t.reset}</span>

packages/learningmap/src/LearningMapEditor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ export interface LearningMapEditorProps {
1515
roadmapData?: string | RoadmapData;
1616
language?: string;
1717
jsonStore?: string;
18+
disableSharing?: boolean;
1819
}
1920

2021
export function LearningMapEditor({
2122
roadmapData,
2223
language = "en",
2324
jsonStore = "https://json.openpatch.org",
25+
disableSharing = false,
2426
}: LearningMapEditorProps) {
2527
// Only get minimal state needed in this component
2628
const nodes = useEditorStore(state => state.nodes);
@@ -64,7 +66,7 @@ export function LearningMapEditor({
6466
<KeyboardShortcuts jsonStore={jsonStore} />
6567

6668
{/* Toolbar */}
67-
<EditorToolbar defaultLanguage={language} />
69+
<EditorToolbar defaultLanguage={language} disableSharing={disableSharing} />
6870

6971
{/* Preview or Edit mode */}
7072
{previewMode && <LearningMap roadmapData={getRoadmapData()} language={effectiveLanguage} />}

platforms/vscode/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
],
2929
"activationEvents": [],
3030
"main": "./dist/extension.js",
31+
"browser": "./dist/extension.js",
3132
"contributes": {
3233
"customEditors": [
3334
{

platforms/vscode/src/LearningmapEditorProvider.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as vscode from 'vscode';
2-
import * as crypto from 'crypto';
32

43
/**
54
* Provider for learningmap custom editor.
@@ -139,5 +138,17 @@ export class LearningmapEditorProvider implements vscode.CustomTextEditorProvide
139138
}
140139

141140
function getNonce() {
142-
return crypto.randomBytes(16).toString('hex');
141+
// Generate a cryptographically secure random string
142+
// This works in both Node.js and browser environments
143+
const array = new Uint32Array(8);
144+
if (typeof crypto !== 'undefined' && crypto.getRandomValues) {
145+
// Browser or modern Node.js with Web Crypto API
146+
crypto.getRandomValues(array);
147+
} else {
148+
// Fallback for older environments
149+
for (let i = 0; i < array.length; i++) {
150+
array[i] = Math.floor(Math.random() * 0xffffffff);
151+
}
152+
}
153+
return Array.from(array, num => num.toString(16).padStart(8, '0')).join('');
143154
}

platforms/vscode/src/webview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function WebviewEditor() {
127127
return <div style={{ padding: '20px' }}>Loading editor...</div>;
128128
}
129129

130-
return <LearningMapEditor />;
130+
return <LearningMapEditor disableSharing={true} />;
131131
}
132132

133133
// Mount the React component

0 commit comments

Comments
 (0)