1
1
import { CodeEditor , IEditorServices } from '@jupyterlab/codeeditor' ;
2
- // import { ICodeSnippet } from './CodeSnippetContentsService';
3
2
import {
4
3
ReactWidget ,
5
4
showDialog ,
6
5
Dialog ,
7
6
WidgetTracker
8
7
} from '@jupyterlab/apputils' ;
9
- import React from 'react' ;
10
- import { Message } from '@lumino/messaging' ;
11
8
import { Button } from '@jupyterlab/ui-components' ;
9
+ import { Contents } from '@jupyterlab/services' ;
10
+
11
+ import { Message } from '@lumino/messaging' ;
12
+
13
+ import React from 'react' ;
14
+
12
15
import { CodeSnippetContentsService } from './CodeSnippetContentsService' ;
13
16
import { CodeSnippetWidget } from './CodeSnippetWidget' ;
14
17
import { SUPPORTED_LANGUAGES } from './index' ;
15
18
import { CodeSnippetEditorTags } from './CodeSnippetEditorTags' ;
16
- import { Contents } from '@jupyterlab/services' ;
17
19
18
20
/**
19
21
* CSS style classes
20
22
*/
21
23
const CODE_SNIPPET_EDITOR = 'jp-codeSnippet-editor' ;
22
- const CODE_SNIPPET_EDITOR_NAME_LABEL = 'jp-snippet-editor-name-label' ;
23
- const CODE_SNIPPET_EDITOR_LABEL_ACTIVE = 'jp-snippet-editor-label-active' ;
24
- const CODE_SNIPPET_EDITOR_INPUT_ACTIVE = 'jp-snippet-editor-active' ;
25
- const CODE_SNIPPET_EDITOR_NAME_INPUT = 'jp-snippet-editor-name' ;
26
- const CODE_SNIPPET_EDITOR_DESC_LABEL = 'jp-snippet-editor-description-label' ;
27
- const CODE_SNIPPET_EDITOR_DESC_INPUT = 'jp-snippet-editor-description' ;
28
- const CODE_SNIPPET_EDITOR_LANG_INPUT = 'jp-snippet-editor-language' ;
24
+ const CODE_SNIPPET_EDITOR_TITLE = 'jp-codeSnippet-editor-title' ;
25
+ const CODE_SNIPPET_EDITOR_METADATA = 'jp-codeSnippet-editor-metadata' ;
26
+ const CODE_SNIPPET_EDITOR_NAME_LABEL = 'jp-codeSnippet-editor-name-label' ;
27
+ const CODE_SNIPPET_EDITOR_LABEL_ACTIVE = 'jp-codeSnippet-editor-label-active' ;
28
+ const CODE_SNIPPET_EDITOR_INPUT_ACTIVE = 'jp-codeSnippet-editor-active' ;
29
+ const CODE_SNIPPET_EDITOR_NAME_INPUT = 'jp-codeSnippet-editor-name' ;
30
+ const CODE_SNIPPET_EDITOR_DESC_LABEL =
31
+ 'jp-codeSnippet-editor-description-label' ;
32
+ const CODE_SNIPPET_EDITOR_DESC_INPUT = 'jp-codeSnippet-editor-description' ;
33
+ const CODE_SNIPPET_EDITOR_LANG_INPUT = 'jp-codeSnippet-editor-language' ;
29
34
const CODE_SNIPPET_EDITOR_MIRROR = 'jp-codeSnippetInput-editor' ;
30
-
35
+ const CODE_SNIPPET_EDITOR_INPUTAREA = 'jp-codeSnippetInputArea' ;
36
+ const CODE_SNIPPET_EDITOR_INPUTAREA_MIRROR = 'jp-codeSnippetInputArea-editor' ;
37
+
38
+ const CODE_SNIPPET_EDITOR_INPUTNAME_VALIDITY =
39
+ 'jp-codeSnippet-inputName-validity' ;
40
+ const CODE_SNIPPET_EDITOR_INPUTDESC_VALIDITY =
41
+ 'jp-codeSnippet-inputDesc-validity' ;
42
+ const CODE_SNIPPET_EDITOR_TAGS_LABEL = 'jp-codeSnippet-editor-tags-label' ;
43
+ const CODE_SNIPPET_EDITOR_MIRROR_LABEL = 'jp-codeSnippetInputArea-editorTitle' ;
31
44
const EDITOR_DIRTY_CLASS = 'jp-mod-dirty' ;
32
45
33
46
export interface ICodeSnippetEditorMetadata {
@@ -488,7 +501,7 @@ export class CodeSnippetEditor extends ReactWidget {
488
501
renderCodeInput ( ) : React . ReactElement {
489
502
return (
490
503
< section
491
- className = "jp-codeSnippetInputArea-editor"
504
+ className = { CODE_SNIPPET_EDITOR_INPUTAREA_MIRROR }
492
505
onMouseDown = { this . activateCodeMirror }
493
506
>
494
507
< div
@@ -527,21 +540,21 @@ export class CodeSnippetEditor extends ReactWidget {
527
540
const fromScratch = this . _codeSnippetEditorMetaData . fromScratch ;
528
541
return (
529
542
< div
530
- className = "jp-codeSnippetInputArea"
543
+ className = { CODE_SNIPPET_EDITOR_INPUTAREA }
531
544
onMouseDown = { (
532
545
event : React . MouseEvent < HTMLDivElement , MouseEvent >
533
546
) : void => {
534
547
// this.deactivateEditor(event);
535
548
this . deactivateEditor ( event ) ;
536
549
} }
537
550
>
538
- < span className = "jp-snippet-editor-title" >
551
+ < span className = { CODE_SNIPPET_EDITOR_TITLE } >
539
552
{ fromScratch ? 'Add New Code Snippet' : 'Edit Code Snippet' }
540
553
</ span >
541
- < section className = "jp-snippet-editor-metadata" >
542
- < label className = "jp-snippet-editor-name-label" > Name</ label >
554
+ < section className = { CODE_SNIPPET_EDITOR_METADATA } >
555
+ < label className = { CODE_SNIPPET_EDITOR_NAME_LABEL } > Name</ label >
543
556
< input
544
- className = "jp-snippet-editor-name"
557
+ className = { CODE_SNIPPET_EDITOR_NAME_INPUT }
545
558
defaultValue = { this . _codeSnippetEditorMetaData . name }
546
559
placeholder = { 'Ex. starter_code' }
547
560
type = "text"
@@ -554,16 +567,14 @@ export class CodeSnippetEditor extends ReactWidget {
554
567
this . handleInputFieldChange ( event ) ;
555
568
} }
556
569
> </ input >
557
- < p className = "jp-inputName-validity" >
570
+ < p className = { CODE_SNIPPET_EDITOR_INPUTNAME_VALIDITY } >
558
571
{
559
- 'Name of the code snippet MUST be alphanumeric or composed of underscore(_)'
572
+ 'Name of the code snippet MUST be lowercased, alphanumeric or composed of underscore(_)'
560
573
}
561
574
</ p >
562
- < label className = "jp-snippet-editor-description-label" >
563
- Description
564
- </ label >
575
+ < label className = { CODE_SNIPPET_EDITOR_DESC_LABEL } > Description</ label >
565
576
< input
566
- className = "jp-snippet-editor-description"
577
+ className = { CODE_SNIPPET_EDITOR_DESC_INPUT }
567
578
defaultValue = { this . _codeSnippetEditorMetaData . description }
568
579
placeholder = { 'Description' }
569
580
type = "text"
@@ -576,20 +587,20 @@ export class CodeSnippetEditor extends ReactWidget {
576
587
this . handleInputFieldChange ( event ) ;
577
588
} }
578
589
> </ input >
579
- < p className = "jp-inputDesc-validity" >
590
+ < p className = { CODE_SNIPPET_EDITOR_INPUTDESC_VALIDITY } >
580
591
{
581
- 'Description of the code snippet MUST be alphanumeric or composed of underscore(_) or space '
592
+ 'Description of the code snippet MUST be alphanumeric but can include space or punctuation '
582
593
}
583
594
</ p >
584
595
{ this . renderLanguages ( ) }
585
- < label className = "jp-snippet-editor-tags-label" > Tags</ label >
596
+ < label className = { CODE_SNIPPET_EDITOR_TAGS_LABEL } > Tags</ label >
586
597
< CodeSnippetEditorTags
587
598
selectedTags = { this . codeSnippetEditorMetadata . selectedTags }
588
599
tags = { this . codeSnippetEditorMetadata . allTags }
589
600
handleChange = { this . handleChangeOnTag }
590
601
/>
591
602
</ section >
592
- < span className = "jp-codeSnippetInputArea-editorTitle" > Code</ span >
603
+ < span className = { CODE_SNIPPET_EDITOR_MIRROR_LABEL } > Code</ span >
593
604
{ this . renderCodeInput ( ) }
594
605
< Button className = "saveBtn" onClick = { this . saveChange } >
595
606
{ fromScratch ? 'Create' : 'Save' }
0 commit comments