Skip to content

Commit 5b3c3ce

Browse files
committed
commit chnages
1 parent 40f7df8 commit 5b3c3ce

File tree

11 files changed

+38273
-98
lines changed

11 files changed

+38273
-98
lines changed

package-lock.json

Lines changed: 38083 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"@microsoft/sp-office-ui-fabric-core": "1.13.1",
3434
"@microsoft/sp-property-pane": "1.13.1",
3535
"@microsoft/sp-webpart-base": "1.13.1",
36+
"@monaco-editor/loader": "^1.2.0",
3637
"@pnp/sp": "2.5.0",
3738
"@pnp/telemetry-js": "2.0.0",
3839
"@popperjs/core": "2.5.4",

src/controls/monacoEditor/Error.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
import { Stack } from "office-ui-fabric-react/lib/components/Stack";
3+
import { MessageBarType , MessageBar} from "office-ui-fabric-react/lib/MessageBar";
4+
import * as React from "react";
5+
6+
export interface IErrorProps {
7+
error: Error;
8+
show: boolean;
9+
}
10+
11+
export const Error: React.FunctionComponent<IErrorProps> = (props: React.PropsWithChildren<IErrorProps>) => {
12+
const { error, show } = props;
13+
return (
14+
<>
15+
(show && error) ?
16+
<Stack horizontal horizontalAlign="start">
17+
<MessageBar isMultiline messageBarType={MessageBarType.error}>
18+
{error.message}
19+
</MessageBar>
20+
</Stack>
21+
: null;
22+
</>
23+
);
24+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface IJscriptDiagnosticsOptions {
2+
noSemanticValidation?: boolean;
3+
noSyntaxValidation?: boolean;
4+
noSuggestionDiagnostics?: boolean;
5+
/**
6+
* Limit diagnostic computation to only visible files.
7+
* Defaults to false.
8+
*/
9+
onlyVisible?: boolean;
10+
diagnosticCodesToIgnore?: number[];
11+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
export type SeverityLevel = 'error' | 'warning' | 'ignore';
2+
export interface IJsonDiagnosticsOptions {
3+
/**
4+
* If set, the validator will be enabled and perform syntax and schema based validation,
5+
* unless `DiagnosticsOptions.schemaValidation` is set to `ignore`.
6+
*/
7+
readonly validate?: boolean;
8+
/**
9+
* If set, comments are tolerated. If set to false, syntax errors will be emitted for comments.
10+
* `DiagnosticsOptions.allowComments` will override this setting.
11+
*/
12+
readonly allowComments?: boolean;
13+
/**
14+
* A list of known schemas and/or associations of schemas to file names.
15+
*/
16+
readonly schemas?: {
17+
/**
18+
* The URI of the schema, which is also the identifier of the schema.
19+
*/
20+
readonly uri: string;
21+
/**
22+
* A list of glob patterns that describe for which file URIs the JSON schema will be used.
23+
* '*' and '**' wildcards are supported. Exclusion patterns start with '!'.
24+
* For example '*.schema.json', 'package.json', '!foo*.schema.json', 'foo/**\/BADRESP.json'.
25+
* A match succeeds when there is at least one pattern matching and last matching pattern does not start with '!'.
26+
*/
27+
readonly fileMatch?: string[];
28+
/**
29+
* The schema for the given URI.
30+
*/
31+
readonly schema?: any;
32+
}[];
33+
/**
34+
* If set, the schema service would load schema content on-demand with 'fetch' if available
35+
*/
36+
readonly enableSchemaRequest?: boolean;
37+
/**
38+
* The severity of problems from schema validation. If set to 'ignore', schema validation will be skipped. If not set, 'warning' is used.
39+
*/
40+
readonly schemaValidation?: SeverityLevel;
41+
/**
42+
* The severity of problems that occurred when resolving and loading schemas. If set to 'ignore', schema resolving problems are not reported. If not set, 'warning' is used.
43+
*/
44+
readonly schemaRequest?: SeverityLevel;
45+
/**
46+
* The severity of reported trailing commas. If not set, trailing commas will be reported as errors.
47+
*/
48+
readonly trailingCommas?: SeverityLevel;
49+
/**
50+
* The severity of reported comments. If not set, 'DiagnosticsOptions.allowComments' defines whether comments are ignored or reported as errors.
51+
*/
52+
readonly comments?: SeverityLevel;
53+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { IJscriptDiagnosticsOptions } from "./IJscriptDiagnosticsOptions";
2+
import { IJsonDiagnosticsOptions } from "./IJsonDiagnosticsOptions";
3+
import * as monaco from "monaco-editor";
4+
export enum Elanguages {
5+
typescript = 'typescript',
6+
javascript = 'javascript',
7+
css = 'css',
8+
html = 'html',
9+
json = 'json',
10+
xml = 'xml',
11+
markdown = 'markdown',
12+
less = 'less',
13+
scss = 'scss',
14+
handlebars = 'handlebars',
15+
16+
17+
}
18+
export interface IMonacoEditorProps {
19+
value: string;
20+
theme: string;
21+
readOnly: boolean;
22+
showLineNumbers: boolean;
23+
showMiniMap: boolean;
24+
onValueChange: (newValue:string, validationErrors:string[]) => void;
25+
language: Elanguages;
26+
jsonDiagnosticsOptions?: monaco.languages.json.DiagnosticsOptions;
27+
jscriptDiagnosticsOptions?: monaco.languages.typescript.DiagnosticsOptions;
28+
29+
}

src/controls/monacoEditor/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './IMonacoEditorProps';
2+
export * from './MonacoEditor';
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { useState, useEffect } from "react";
2+
import loader, { Monaco } from "@monaco-editor/loader";
3+
4+
const CDN_PATH_TO_MONACO_EDITOR = "https://cdn.jsdelivr.net/npm/[email protected]/min/vs";
5+
export enum EStatus {
6+
LOADING,
7+
LOADED,
8+
ERROR,
9+
}
10+
11+
export const useMonaco = () => {
12+
const [monaco, setMonaco] = useState<Monaco>(undefined);
13+
const [status, setStatus] = useState<EStatus>(EStatus.LOADING);
14+
const [error, setError] = useState<Error>(undefined);
15+
// you can change the source of the monaco files
16+
17+
useEffect(() => {
18+
(async () => {
19+
try {
20+
loader.config({ paths: { vs: CDN_PATH_TO_MONACO_EDITOR } });
21+
const monacoObj = await loader.init();
22+
setStatus(EStatus.LOADED);
23+
setMonaco(monacoObj);
24+
} catch (error) {
25+
setStatus(EStatus.ERROR);
26+
setMonaco(undefined);
27+
setError(error);
28+
}
29+
})();
30+
}, []);
31+
32+
return {
33+
monaco,
34+
status,
35+
error,
36+
};
37+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { mergeStyleSets } from "office-ui-fabric-react";
2+
import React from "react";
3+
4+
export const useMonacoEditorStyles = () => {
5+
const controlClasses = React.useMemo(() =>{
6+
return mergeStyleSets({
7+
containerStyles:{
8+
height: "800px",
9+
}
10+
});
11+
},[]);
12+
13+
return {controlClasses };
14+
};

src/webparts/controlsTest/ControlsTestWebPart.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ export default class ControlsTestWebPart extends BaseClientSideWebPart<IControls
6969
}
7070

7171
public render(): void {
72-
/* const element: React.ReactElement<ITestControlProps> = React.createElement(
72+
const element: React.ReactElement<ITestControlProps> = React.createElement(
7373

7474
TestControl,
7575
{
7676
context: this.context,
7777
}
78-
); */
78+
);
7979

80-
const element: React.ReactElement<IControlsTestProps> = React.createElement(
80+
/* const element: React.ReactElement<IControlsTestProps> = React.createElement(
8181
8282
ControlsTest,
8383
{
@@ -93,7 +93,7 @@ export default class ControlsTestWebPart extends BaseClientSideWebPart<IControls
9393
totalPages: this.properties.totalPages
9494
}
9595
);
96-
96+
*/
9797
ReactDom.render(element, this.domElement);
9898
}
9999

0 commit comments

Comments
 (0)