kempo-ui 0.3.8 → 0.3.10
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.
- package/dist/components/CodeEditor.js +96 -0
- package/dist/components/HtmlEditor.js +155 -30
- package/dist/components/codeEditorControls/CodeEditorControl.js +17 -0
- package/dist/components/codeEditorControls/ControlGroup.js +12 -0
- package/dist/components/codeEditorControls/ControlSpacer.js +6 -0
- package/dist/components/codeEditorControls/CopyCode.js +9 -0
- package/dist/components/codeEditorControls/EditorTheme.js +26 -0
- package/dist/components/codeEditorControls/FindReplace.js +7 -0
- package/dist/components/codeEditorControls/FoldAll.js +7 -0
- package/dist/components/codeEditorControls/FontSize.js +13 -0
- package/dist/components/codeEditorControls/FormatCode.js +9 -0
- package/dist/components/codeEditorControls/Fullscreen.js +12 -0
- package/dist/components/codeEditorControls/LanguageSelect.js +15 -0
- package/dist/components/codeEditorControls/Minimap.js +8 -0
- package/dist/components/codeEditorControls/Redo.js +7 -0
- package/dist/components/codeEditorControls/Undo.js +7 -0
- package/dist/components/codeEditorControls/WordWrap.js +8 -0
- package/dist/components/htmlEditorControls/AlignCenter.js +4 -4
- package/dist/components/htmlEditorControls/AlignJustify.js +4 -4
- package/dist/components/htmlEditorControls/AlignLeft.js +4 -4
- package/dist/components/htmlEditorControls/AlignRight.js +4 -4
- package/dist/components/htmlEditorControls/Bold.js +4 -4
- package/dist/components/htmlEditorControls/BulletList.js +4 -4
- package/dist/components/htmlEditorControls/ClearFormatting.js +4 -4
- package/dist/components/htmlEditorControls/CodeBlock.js +2 -2
- package/dist/components/htmlEditorControls/ControlGroup.js +2 -4
- package/dist/components/htmlEditorControls/CreateLink.js +3 -3
- package/dist/components/htmlEditorControls/FormatBlock.js +4 -4
- package/dist/components/htmlEditorControls/FormatCode.js +1 -0
- package/dist/components/htmlEditorControls/HtmlEditorControl.js +2 -2
- package/dist/components/htmlEditorControls/InlineCode.js +2 -2
- package/dist/components/htmlEditorControls/InsertTable.js +3 -3
- package/dist/components/htmlEditorControls/Italic.js +4 -4
- package/dist/components/htmlEditorControls/Mode.js +3 -3
- package/dist/components/htmlEditorControls/NumberList.js +4 -4
- package/dist/components/htmlEditorControls/Strikethrough.js +4 -4
- package/dist/components/htmlEditorControls/TextBackgroundColor.js +1 -1
- package/dist/components/htmlEditorControls/TextColor.js +1 -1
- package/dist/components/htmlEditorControls/Underline.js +4 -4
- package/docs/components/accordion.html +2 -0
- package/docs/components/aside.html +2 -0
- package/docs/components/card.html +2 -0
- package/docs/components/code-editor.html +491 -0
- package/docs/components/color-picker.html +2 -0
- package/docs/components/content-slider.html +2 -0
- package/docs/components/context.html +2 -0
- package/docs/components/dialog.html +2 -0
- package/docs/components/dropdown.html +2 -0
- package/docs/components/filter-list.html +2 -0
- package/docs/components/focus-capture.html +2 -0
- package/docs/components/html-editor.html +525 -212
- package/docs/components/hybrid-component.html +2 -0
- package/docs/components/icon.html +2 -0
- package/docs/components/import.html +2 -0
- package/docs/components/light-component.html +2 -0
- package/docs/components/nav-spacer.html +2 -0
- package/docs/components/nav.html +2 -0
- package/docs/components/photo-viewer.html +2 -0
- package/docs/components/resize.html +2 -0
- package/docs/components/shadow-component.html +2 -0
- package/docs/components/show-more.html +2 -0
- package/docs/components/sortable.html +2 -0
- package/docs/components/spinner.html +2 -0
- package/docs/components/split.html +2 -0
- package/docs/components/table.html +2 -0
- package/docs/components/tableControls.html +2 -0
- package/docs/components/tableCustomFields.html +2 -0
- package/docs/components/tableFetchRecords.html +2 -0
- package/docs/components/tableFieldSortHide.html +2 -0
- package/docs/components/tablePagination.html +2 -0
- package/docs/components/tablePlaceholder.html +2 -0
- package/docs/components/tableRecordEditing.html +2 -0
- package/docs/components/tableRecordFiltering.html +2 -0
- package/docs/components/tableRecordHiding.html +2 -0
- package/docs/components/tableRecordSearching.html +2 -0
- package/docs/components/tableRecordSelection.html +2 -0
- package/docs/components/tableRowControls.html +2 -0
- package/docs/components/tableServerSync.html +2 -0
- package/docs/components/tableSorting.html +2 -0
- package/docs/components/tabs.html +2 -0
- package/docs/components/tags.html +2 -0
- package/docs/components/theme-select.html +2 -0
- package/docs/components/theme-switcher.html +2 -0
- package/docs/components/timestamp.html +2 -0
- package/docs/components/toast.html +2 -0
- package/docs/components/toggle.html +2 -0
- package/docs/components/tree.html +2 -0
- package/docs/icons/auto_fix_high.svg +1 -0
- package/docs/icons/content_copy.svg +1 -0
- package/docs/icons/contrast.svg +1 -0
- package/docs/icons/frame_source.svg +1 -0
- package/docs/icons/fullscreen.svg +1 -0
- package/docs/icons/fullscreen_exit.svg +1 -0
- package/docs/icons/map.svg +1 -0
- package/docs/icons/redo.svg +1 -0
- package/docs/icons/text_decrease.svg +1 -0
- package/docs/icons/text_increase.svg +1 -0
- package/docs/icons/undo.svg +1 -0
- package/docs/icons/unfold_less.svg +1 -0
- package/docs/icons/unfold_more.svg +1 -0
- package/docs/icons/wrap_text.svg +1 -0
- package/docs/index.html +8 -0
- package/docs/src/components/CodeEditor.js +96 -0
- package/docs/src/components/HtmlEditor.js +155 -30
- package/docs/src/components/codeEditorControls/CodeEditorControl.js +17 -0
- package/docs/src/components/codeEditorControls/ControlGroup.js +12 -0
- package/docs/src/components/codeEditorControls/ControlSpacer.js +6 -0
- package/docs/src/components/codeEditorControls/CopyCode.js +9 -0
- package/docs/src/components/codeEditorControls/EditorTheme.js +26 -0
- package/docs/src/components/codeEditorControls/FindReplace.js +7 -0
- package/docs/src/components/codeEditorControls/FoldAll.js +7 -0
- package/docs/src/components/codeEditorControls/FontSize.js +13 -0
- package/docs/src/components/codeEditorControls/FormatCode.js +9 -0
- package/docs/src/components/codeEditorControls/Fullscreen.js +12 -0
- package/docs/src/components/codeEditorControls/LanguageSelect.js +15 -0
- package/docs/src/components/codeEditorControls/Minimap.js +8 -0
- package/docs/src/components/codeEditorControls/Redo.js +7 -0
- package/docs/src/components/codeEditorControls/Undo.js +7 -0
- package/docs/src/components/codeEditorControls/WordWrap.js +8 -0
- package/docs/src/components/htmlEditorControls/AlignCenter.js +4 -4
- package/docs/src/components/htmlEditorControls/AlignJustify.js +4 -4
- package/docs/src/components/htmlEditorControls/AlignLeft.js +4 -4
- package/docs/src/components/htmlEditorControls/AlignRight.js +4 -4
- package/docs/src/components/htmlEditorControls/Bold.js +4 -4
- package/docs/src/components/htmlEditorControls/BulletList.js +4 -4
- package/docs/src/components/htmlEditorControls/ClearFormatting.js +4 -4
- package/docs/src/components/htmlEditorControls/CodeBlock.js +2 -2
- package/docs/src/components/htmlEditorControls/ControlGroup.js +2 -4
- package/docs/src/components/htmlEditorControls/CreateLink.js +3 -3
- package/docs/src/components/htmlEditorControls/FormatBlock.js +4 -4
- package/docs/src/components/htmlEditorControls/FormatCode.js +1 -0
- package/docs/src/components/htmlEditorControls/HtmlEditorControl.js +2 -2
- package/docs/src/components/htmlEditorControls/InlineCode.js +2 -2
- package/docs/src/components/htmlEditorControls/InsertTable.js +3 -3
- package/docs/src/components/htmlEditorControls/Italic.js +4 -4
- package/docs/src/components/htmlEditorControls/Mode.js +3 -3
- package/docs/src/components/htmlEditorControls/NumberList.js +4 -4
- package/docs/src/components/htmlEditorControls/Strikethrough.js +4 -4
- package/docs/src/components/htmlEditorControls/TextBackgroundColor.js +1 -1
- package/docs/src/components/htmlEditorControls/TextColor.js +1 -1
- package/docs/src/components/htmlEditorControls/Underline.js +4 -4
- package/docs/utils/context.html +2 -0
- package/docs/utils/cookie.html +2 -0
- package/docs/utils/debounce.html +2 -0
- package/docs/utils/drag.html +2 -0
- package/docs/utils/elevation.html +2 -0
- package/docs/utils/formatTimestamp.html +2 -0
- package/docs/utils/object.html +2 -0
- package/docs/utils/propConverters.html +2 -0
- package/docs/utils/string.html +2 -0
- package/docs/utils/theme.html +2 -0
- package/docs/utils/toTitleCase.html +2 -0
- package/docs/utils/type.html +2 -0
- package/docs/utils/wait.html +2 -0
- package/docs-src/components/code-editor.page.html +235 -0
- package/docs-src/components/html-editor.page.html +528 -214
- package/docs-src/index.page.html +6 -0
- package/docs-src/nav.fragment.html +2 -0
- package/icons/auto_fix_high.svg +1 -0
- package/icons/content_copy.svg +1 -0
- package/icons/contrast.svg +1 -0
- package/icons/frame_source.svg +1 -0
- package/icons/fullscreen.svg +1 -0
- package/icons/fullscreen_exit.svg +1 -0
- package/icons/map.svg +1 -0
- package/icons/redo.svg +1 -0
- package/icons/text_decrease.svg +1 -0
- package/icons/text_increase.svg +1 -0
- package/icons/undo.svg +1 -0
- package/icons/unfold_less.svg +1 -0
- package/icons/unfold_more.svg +1 -0
- package/icons/wrap_text.svg +1 -0
- package/llm.txt +2 -1
- package/package.json +3 -3
- package/src/components/CodeEditor.js +495 -0
- package/src/components/HtmlEditor.js +527 -152
- package/src/components/codeEditorControls/CodeEditorControl.js +134 -0
- package/src/components/codeEditorControls/ControlGroup.js +70 -0
- package/src/components/codeEditorControls/ControlSpacer.js +23 -0
- package/src/components/codeEditorControls/CopyCode.js +37 -0
- package/src/components/codeEditorControls/EditorTheme.js +81 -0
- package/src/components/codeEditorControls/FindReplace.js +35 -0
- package/src/components/codeEditorControls/FoldAll.js +49 -0
- package/src/components/codeEditorControls/FontSize.js +45 -0
- package/src/components/codeEditorControls/FormatCode.js +37 -0
- package/src/components/codeEditorControls/Fullscreen.js +72 -0
- package/src/components/codeEditorControls/LanguageSelect.js +74 -0
- package/src/components/codeEditorControls/Minimap.js +60 -0
- package/src/components/codeEditorControls/Redo.js +35 -0
- package/src/components/codeEditorControls/Undo.js +35 -0
- package/src/components/codeEditorControls/WordWrap.js +60 -0
- package/src/components/htmlEditorControls/AlignCenter.js +2 -4
- package/src/components/htmlEditorControls/AlignJustify.js +2 -4
- package/src/components/htmlEditorControls/AlignLeft.js +2 -4
- package/src/components/htmlEditorControls/AlignRight.js +2 -4
- package/src/components/htmlEditorControls/Bold.js +2 -4
- package/src/components/htmlEditorControls/BulletList.js +2 -4
- package/src/components/htmlEditorControls/ClearFormatting.js +2 -4
- package/src/components/htmlEditorControls/CodeBlock.js +3 -19
- package/src/components/htmlEditorControls/ControlGroup.js +16 -41
- package/src/components/htmlEditorControls/CreateLink.js +3 -5
- package/src/components/htmlEditorControls/FormatBlock.js +2 -4
- package/src/components/htmlEditorControls/FormatCode.js +7 -0
- package/src/components/htmlEditorControls/HtmlEditorControl.js +43 -5
- package/src/components/htmlEditorControls/InlineCode.js +3 -5
- package/src/components/htmlEditorControls/InsertTable.js +9 -53
- package/src/components/htmlEditorControls/Italic.js +2 -4
- package/src/components/htmlEditorControls/Mode.js +2 -0
- package/src/components/htmlEditorControls/NumberList.js +2 -4
- package/src/components/htmlEditorControls/Strikethrough.js +2 -4
- package/src/components/htmlEditorControls/TextBackgroundColor.js +0 -6
- package/src/components/htmlEditorControls/TextColor.js +0 -6
- package/src/components/htmlEditorControls/Underline.js +2 -4
- package/tests/components/CodeEditor.browser-test.js +297 -0
- package/tests/components/HtmlEditor.browser-test.js +207 -0
- package/tests/components/codeEditorControls/CopyCode.browser-test.js +57 -0
- package/tests/components/codeEditorControls/EditorTheme.browser-test.js +70 -0
- package/tests/components/codeEditorControls/FindReplace.browser-test.js +57 -0
- package/tests/components/codeEditorControls/FoldAll.browser-test.js +92 -0
- package/tests/components/codeEditorControls/FontSize.browser-test.js +74 -0
- package/tests/components/codeEditorControls/Fullscreen.browser-test.js +152 -0
- package/tests/components/codeEditorControls/LanguageSelect.browser-test.js +82 -0
- package/tests/components/codeEditorControls/Minimap.browser-test.js +84 -0
- package/tests/components/codeEditorControls/ModeVisibility.browser-test.js +82 -0
- package/tests/components/codeEditorControls/UndoRedo.browser-test.js +85 -0
- package/tests/components/codeEditorControls/WordWrap.browser-test.js +95 -0
- package/tests/components/htmlEditorControls/Align.browser-test.js +203 -0
- package/tests/components/htmlEditorControls/Bold.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/BulletList.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/CharacterCount.browser-test.js +106 -0
- package/tests/components/htmlEditorControls/ClearFormatting.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/CodeBlock.browser-test.js +143 -0
- package/tests/components/htmlEditorControls/ControlGroup.browser-test.js +116 -0
- package/tests/components/htmlEditorControls/ControlSpacer.browser-test.js +69 -0
- package/tests/components/htmlEditorControls/CreateLink.browser-test.js +129 -0
- package/tests/components/htmlEditorControls/DropdownControl.browser-test.js +138 -0
- package/tests/components/htmlEditorControls/FormatBlock.browser-test.js +163 -0
- package/tests/components/htmlEditorControls/FormatCode.browser-test.js +155 -0
- package/tests/components/htmlEditorControls/InlineCode.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/InsertTable.browser-test.js +129 -0
- package/tests/components/htmlEditorControls/Italic.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/Mode.browser-test.js +138 -0
- package/tests/components/htmlEditorControls/NumberList.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/Strikethrough.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/TextBackgroundColor.browser-test.js +136 -0
- package/tests/components/htmlEditorControls/TextColor.browser-test.js +136 -0
- package/tests/components/htmlEditorControls/Underline.browser-test.js +127 -0
- package/tests/components/htmlEditorControls/WordCount.browser-test.js +106 -0
|
@@ -30,52 +30,16 @@ export default class InsertTable extends HtmlEditorControl {
|
|
|
30
30
|
/*
|
|
31
31
|
Event Handlers
|
|
32
32
|
*/
|
|
33
|
-
|
|
33
|
+
handleClick = () => {
|
|
34
34
|
if(!this.editor) return;
|
|
35
35
|
|
|
36
|
-
e.preventDefault();
|
|
37
|
-
e.stopPropagation();
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
let tableNodeKey = null;
|
|
46
|
-
|
|
47
|
-
if(this.editor.lexicalEditor){
|
|
48
|
-
const { lexical, table } = this.editor.lx;
|
|
49
|
-
this.editor.lexicalEditor.getEditorState().read(() => {
|
|
50
|
-
const sel = lexical.$getSelection();
|
|
51
|
-
if(!lexical.$isRangeSelection(sel)) return;
|
|
52
|
-
let node = sel.anchor.getNode();
|
|
53
|
-
while(node){
|
|
54
|
-
if(table.$isTableNode(node)){
|
|
55
|
-
isEditing = true;
|
|
56
|
-
tableNodeKey = node.getKey();
|
|
57
|
-
cellData = [];
|
|
58
|
-
const rows = node.getChildren();
|
|
59
|
-
let hasHeaders = false;
|
|
60
|
-
rows.forEach((row, rowIndex) => {
|
|
61
|
-
const rowData = [];
|
|
62
|
-
row.getChildren().forEach(cell => {
|
|
63
|
-
if(rowIndex === 0 && table.$isTableCellNode(cell) && cell.getHeaderStyles() === table.TableCellHeaderStates.ROW){
|
|
64
|
-
hasHeaders = true;
|
|
65
|
-
}
|
|
66
|
-
rowData.push(cell.getTextContent());
|
|
67
|
-
});
|
|
68
|
-
cellData.push(rowData);
|
|
69
|
-
if(rowData.length > defaultCols) defaultCols = rowData.length;
|
|
70
|
-
});
|
|
71
|
-
defaultHeaders = hasHeaders;
|
|
72
|
-
defaultRows = hasHeaders ? rows.length - 1 : rows.length;
|
|
73
|
-
break;
|
|
74
|
-
}
|
|
75
|
-
node = node.getParent();
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
}
|
|
37
|
+
const existing = this.editor.getTableAtSelection();
|
|
38
|
+
const isEditing = !!existing;
|
|
39
|
+
const defaultRows = existing?.rows ?? 3;
|
|
40
|
+
const defaultCols = existing?.cols ?? 3;
|
|
41
|
+
const defaultHeaders = existing?.hasHeaders ?? true;
|
|
42
|
+
const cellData = existing?.cellData ?? null;
|
|
79
43
|
|
|
80
44
|
// Create dialog inputs
|
|
81
45
|
const rowsInput = document.createElement('input');
|
|
@@ -124,15 +88,7 @@ export default class InsertTable extends HtmlEditorControl {
|
|
|
124
88
|
const rows = parseInt(rowsInput.value) || 3;
|
|
125
89
|
const cols = parseInt(colsInput.value) || 3;
|
|
126
90
|
const includeHeaders = headersCheckbox.checked;
|
|
127
|
-
|
|
128
|
-
if(isEditing && tableNodeKey){
|
|
129
|
-
const { lexical } = this.editor.lx;
|
|
130
|
-
this.editor.lexicalEditor.update(() => {
|
|
131
|
-
const tableNode = lexical.$getNodeByKey(tableNodeKey);
|
|
132
|
-
if(tableNode) tableNode.remove();
|
|
133
|
-
}, { discrete: true });
|
|
134
|
-
}
|
|
135
|
-
|
|
91
|
+
if(isEditing) this.editor.removeTableByKey(existing.key);
|
|
136
92
|
this.editor.insertTable(rows, cols, includeHeaders, cellData);
|
|
137
93
|
}
|
|
138
94
|
});
|
|
@@ -147,7 +103,7 @@ export default class InsertTable extends HtmlEditorControl {
|
|
|
147
103
|
return html`
|
|
148
104
|
<button
|
|
149
105
|
class="${this.buttonClasses}"
|
|
150
|
-
@
|
|
106
|
+
@click="${this.handleClick}"
|
|
151
107
|
>
|
|
152
108
|
<slot name="icon">
|
|
153
109
|
<k-icon name="table"></k-icon>
|
|
@@ -31,9 +31,7 @@ export default class Italic extends HtmlEditorControl {
|
|
|
31
31
|
/*
|
|
32
32
|
Event Handlers
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
e.preventDefault();
|
|
36
|
-
e.stopPropagation();
|
|
34
|
+
handleClick = () => {
|
|
37
35
|
if(this.editor) this.editor.italic();
|
|
38
36
|
};
|
|
39
37
|
|
|
@@ -52,7 +50,7 @@ export default class Italic extends HtmlEditorControl {
|
|
|
52
50
|
this.hidden = this.editorMode === 'code';
|
|
53
51
|
|
|
54
52
|
return html`
|
|
55
|
-
<button class="${this.buttonClasses}" @
|
|
53
|
+
<button class="${this.buttonClasses}" @click="${this.handleClick}">
|
|
56
54
|
<slot name="icon">
|
|
57
55
|
<k-icon name="format_italic"></k-icon>
|
|
58
56
|
</slot>
|
|
@@ -31,9 +31,7 @@ export default class NumberList extends HtmlEditorControl {
|
|
|
31
31
|
/*
|
|
32
32
|
Event Handlers
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
e.preventDefault();
|
|
36
|
-
e.stopPropagation();
|
|
34
|
+
handleClick = () => {
|
|
37
35
|
if(this.editor) this.editor.orderedList();
|
|
38
36
|
};
|
|
39
37
|
|
|
@@ -52,7 +50,7 @@ export default class NumberList extends HtmlEditorControl {
|
|
|
52
50
|
this.hidden = this.editorMode === 'code';
|
|
53
51
|
|
|
54
52
|
return html`
|
|
55
|
-
<button class="${this.buttonClasses}" @
|
|
53
|
+
<button class="${this.buttonClasses}" @click="${this.handleClick}">
|
|
56
54
|
<slot name="icon">
|
|
57
55
|
<k-icon name="format_list_numbered"></k-icon>
|
|
58
56
|
</slot>
|
|
@@ -31,9 +31,7 @@ export default class Strikethrough extends HtmlEditorControl {
|
|
|
31
31
|
/*
|
|
32
32
|
Event Handlers
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
e.preventDefault();
|
|
36
|
-
e.stopPropagation();
|
|
34
|
+
handleClick = () => {
|
|
37
35
|
if(this.editor) this.editor.strikethrough();
|
|
38
36
|
};
|
|
39
37
|
|
|
@@ -52,7 +50,7 @@ export default class Strikethrough extends HtmlEditorControl {
|
|
|
52
50
|
this.hidden = this.editorMode === 'code';
|
|
53
51
|
|
|
54
52
|
return html`
|
|
55
|
-
<button class="${this.buttonClasses}" @
|
|
53
|
+
<button class="${this.buttonClasses}" @click="${this.handleClick}">
|
|
56
54
|
<slot name="icon">
|
|
57
55
|
<k-icon name="strikethrough_s"></k-icon>
|
|
58
56
|
</slot>
|
|
@@ -97,8 +97,6 @@ export default class TextBackgroundColor extends DropdownControl {
|
|
|
97
97
|
Event Handlers
|
|
98
98
|
*/
|
|
99
99
|
handleRemove = (e) => {
|
|
100
|
-
e.preventDefault();
|
|
101
|
-
e.stopPropagation();
|
|
102
100
|
if(this.editor){
|
|
103
101
|
this.editor.removeTextBackgroundColor();
|
|
104
102
|
}
|
|
@@ -106,8 +104,6 @@ export default class TextBackgroundColor extends DropdownControl {
|
|
|
106
104
|
};
|
|
107
105
|
|
|
108
106
|
handleSwatchClick = (e) => {
|
|
109
|
-
e.preventDefault();
|
|
110
|
-
e.stopPropagation();
|
|
111
107
|
const color = e.target.style.backgroundColor;
|
|
112
108
|
if(this.editor && color){
|
|
113
109
|
const rgb = color.match(/\d+/g);
|
|
@@ -118,8 +114,6 @@ export default class TextBackgroundColor extends DropdownControl {
|
|
|
118
114
|
};
|
|
119
115
|
|
|
120
116
|
handlePickerChange = (e) => {
|
|
121
|
-
e.preventDefault();
|
|
122
|
-
e.stopPropagation();
|
|
123
117
|
const color = e.target.value;
|
|
124
118
|
if(this.editor && color){
|
|
125
119
|
this.editor.setTextBackgroundColor(color);
|
|
@@ -97,8 +97,6 @@ export default class TextColor extends DropdownControl {
|
|
|
97
97
|
Event Handlers
|
|
98
98
|
*/
|
|
99
99
|
handleRemove = (e) => {
|
|
100
|
-
e.preventDefault();
|
|
101
|
-
e.stopPropagation();
|
|
102
100
|
if(this.editor){
|
|
103
101
|
this.editor.removeTextColor();
|
|
104
102
|
}
|
|
@@ -106,8 +104,6 @@ export default class TextColor extends DropdownControl {
|
|
|
106
104
|
};
|
|
107
105
|
|
|
108
106
|
handleSwatchClick = (e) => {
|
|
109
|
-
e.preventDefault();
|
|
110
|
-
e.stopPropagation();
|
|
111
107
|
const color = e.target.style.backgroundColor;
|
|
112
108
|
if(this.editor && color){
|
|
113
109
|
const rgb = color.match(/\d+/g);
|
|
@@ -118,8 +114,6 @@ export default class TextColor extends DropdownControl {
|
|
|
118
114
|
};
|
|
119
115
|
|
|
120
116
|
handlePickerChange = (e) => {
|
|
121
|
-
e.preventDefault();
|
|
122
|
-
e.stopPropagation();
|
|
123
117
|
const color = e.target.value;
|
|
124
118
|
if(this.editor && color){
|
|
125
119
|
this.editor.setTextColor(color);
|
|
@@ -31,9 +31,7 @@ export default class Underline extends HtmlEditorControl {
|
|
|
31
31
|
/*
|
|
32
32
|
Event Handlers
|
|
33
33
|
*/
|
|
34
|
-
|
|
35
|
-
e.preventDefault();
|
|
36
|
-
e.stopPropagation();
|
|
34
|
+
handleClick = () => {
|
|
37
35
|
if(this.editor) this.editor.underline();
|
|
38
36
|
};
|
|
39
37
|
|
|
@@ -52,7 +50,7 @@ export default class Underline extends HtmlEditorControl {
|
|
|
52
50
|
this.hidden = this.editorMode === 'code';
|
|
53
51
|
|
|
54
52
|
return html`
|
|
55
|
-
<button class="${this.buttonClasses}" @
|
|
53
|
+
<button class="${this.buttonClasses}" @click="${this.handleClick}">
|
|
56
54
|
<slot name="icon">
|
|
57
55
|
<k-icon name="format_underlined"></k-icon>
|
|
58
56
|
</slot>
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
import '../../src/components/CodeEditor.js';
|
|
2
|
+
|
|
3
|
+
const createEditor = async (attrs = '') => {
|
|
4
|
+
const container = document.createElement('div');
|
|
5
|
+
container.innerHTML = `<k-code-editor language="javascript" ${attrs} style="height:200px"></k-code-editor>`;
|
|
6
|
+
document.body.appendChild(container);
|
|
7
|
+
const editor = container.querySelector('k-code-editor');
|
|
8
|
+
await new Promise(r => editor.addEventListener('ready', r, { once: true }));
|
|
9
|
+
return { container, editor };
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const cleanup = container => {
|
|
13
|
+
const editor = container.querySelector('k-code-editor');
|
|
14
|
+
if(editor?.fullscreen) editor.exitFullscreen();
|
|
15
|
+
if(container?.parentNode) container.parentNode.removeChild(container);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
/*
|
|
20
|
+
Fullscreen
|
|
21
|
+
*/
|
|
22
|
+
'fullscreen should default to false': async ({pass, fail}) => {
|
|
23
|
+
const { container, editor } = await createEditor();
|
|
24
|
+
if(editor.fullscreen !== false){
|
|
25
|
+
cleanup(container);
|
|
26
|
+
return fail('fullscreen should default to false');
|
|
27
|
+
}
|
|
28
|
+
cleanup(container);
|
|
29
|
+
pass();
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
'enterFullscreen should set fullscreen to true': async ({pass, fail}) => {
|
|
33
|
+
const { container, editor } = await createEditor();
|
|
34
|
+
editor.enterFullscreen();
|
|
35
|
+
if(!editor.fullscreen){
|
|
36
|
+
cleanup(container);
|
|
37
|
+
return fail('fullscreen should be true after enterFullscreen()');
|
|
38
|
+
}
|
|
39
|
+
cleanup(container);
|
|
40
|
+
pass();
|
|
41
|
+
},
|
|
42
|
+
|
|
43
|
+
'exitFullscreen should set fullscreen to false': async ({pass, fail}) => {
|
|
44
|
+
const { container, editor } = await createEditor();
|
|
45
|
+
editor.enterFullscreen();
|
|
46
|
+
editor.exitFullscreen();
|
|
47
|
+
if(editor.fullscreen){
|
|
48
|
+
cleanup(container);
|
|
49
|
+
return fail('fullscreen should be false after exitFullscreen()');
|
|
50
|
+
}
|
|
51
|
+
cleanup(container);
|
|
52
|
+
pass();
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
'toggleFullscreen should alternate fullscreen': async ({pass, fail}) => {
|
|
56
|
+
const { container, editor } = await createEditor();
|
|
57
|
+
editor.toggleFullscreen();
|
|
58
|
+
if(!editor.fullscreen){
|
|
59
|
+
cleanup(container);
|
|
60
|
+
return fail('First toggle should set fullscreen to true');
|
|
61
|
+
}
|
|
62
|
+
editor.toggleFullscreen();
|
|
63
|
+
if(editor.fullscreen){
|
|
64
|
+
cleanup(container);
|
|
65
|
+
return fail('Second toggle should set fullscreen to false');
|
|
66
|
+
}
|
|
67
|
+
cleanup(container);
|
|
68
|
+
pass();
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
'enterFullscreen should dispatch fullscreen-changed with true': async ({pass, fail}) => {
|
|
72
|
+
const { container, editor } = await createEditor();
|
|
73
|
+
let detail = null;
|
|
74
|
+
editor.addEventListener('fullscreen-changed', e => { detail = e.detail; }, { once: true });
|
|
75
|
+
editor.enterFullscreen();
|
|
76
|
+
if(!detail || detail.fullscreen !== true){
|
|
77
|
+
cleanup(container);
|
|
78
|
+
return fail('Should dispatch fullscreen-changed with fullscreen: true');
|
|
79
|
+
}
|
|
80
|
+
cleanup(container);
|
|
81
|
+
pass();
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
'exitFullscreen should dispatch fullscreen-changed with false': async ({pass, fail}) => {
|
|
85
|
+
const { container, editor } = await createEditor();
|
|
86
|
+
editor.enterFullscreen();
|
|
87
|
+
let detail = null;
|
|
88
|
+
editor.addEventListener('fullscreen-changed', e => { detail = e.detail; }, { once: true });
|
|
89
|
+
editor.exitFullscreen();
|
|
90
|
+
if(!detail || detail.fullscreen !== false){
|
|
91
|
+
cleanup(container);
|
|
92
|
+
return fail('Should dispatch fullscreen-changed with fullscreen: false');
|
|
93
|
+
}
|
|
94
|
+
cleanup(container);
|
|
95
|
+
pass();
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
'fullscreen should reflect as attribute': async ({pass, fail}) => {
|
|
99
|
+
const { container, editor } = await createEditor();
|
|
100
|
+
editor.enterFullscreen();
|
|
101
|
+
await editor.updateComplete;
|
|
102
|
+
if(!editor.hasAttribute('fullscreen')){
|
|
103
|
+
cleanup(container);
|
|
104
|
+
return fail('Should have fullscreen attribute when fullscreen=true');
|
|
105
|
+
}
|
|
106
|
+
editor.exitFullscreen();
|
|
107
|
+
await editor.updateComplete;
|
|
108
|
+
if(editor.hasAttribute('fullscreen')){
|
|
109
|
+
cleanup(container);
|
|
110
|
+
return fail('Should remove fullscreen attribute when fullscreen=false');
|
|
111
|
+
}
|
|
112
|
+
cleanup(container);
|
|
113
|
+
pass();
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/*
|
|
117
|
+
Word Wrap
|
|
118
|
+
*/
|
|
119
|
+
'wordWrap should default to true': async ({pass, fail}) => {
|
|
120
|
+
const { container, editor } = await createEditor();
|
|
121
|
+
if(editor.wordWrap !== true){
|
|
122
|
+
cleanup(container);
|
|
123
|
+
return fail('wordWrap should default to true');
|
|
124
|
+
}
|
|
125
|
+
cleanup(container);
|
|
126
|
+
pass();
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
'toggleWordWrap should alternate wordWrap': async ({pass, fail}) => {
|
|
130
|
+
const { container, editor } = await createEditor();
|
|
131
|
+
editor.toggleWordWrap();
|
|
132
|
+
if(editor.wordWrap !== false){
|
|
133
|
+
cleanup(container);
|
|
134
|
+
return fail('First toggle should set wordWrap to false');
|
|
135
|
+
}
|
|
136
|
+
editor.toggleWordWrap();
|
|
137
|
+
if(editor.wordWrap !== true){
|
|
138
|
+
cleanup(container);
|
|
139
|
+
return fail('Second toggle should set wordWrap to true');
|
|
140
|
+
}
|
|
141
|
+
cleanup(container);
|
|
142
|
+
pass();
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
'setWordWrap should dispatch word-wrap-changed': async ({pass, fail}) => {
|
|
146
|
+
const { container, editor } = await createEditor();
|
|
147
|
+
let detail = null;
|
|
148
|
+
editor.addEventListener('word-wrap-changed', e => { detail = e.detail; }, { once: true });
|
|
149
|
+
editor.setWordWrap(false);
|
|
150
|
+
await editor.updateComplete;
|
|
151
|
+
if(!detail || detail.wordWrap !== false){
|
|
152
|
+
cleanup(container);
|
|
153
|
+
return fail('Should dispatch word-wrap-changed with wordWrap: false');
|
|
154
|
+
}
|
|
155
|
+
cleanup(container);
|
|
156
|
+
pass();
|
|
157
|
+
},
|
|
158
|
+
|
|
159
|
+
/*
|
|
160
|
+
Minimap
|
|
161
|
+
*/
|
|
162
|
+
'minimapEnabled should default to false': async ({pass, fail}) => {
|
|
163
|
+
const { container, editor } = await createEditor();
|
|
164
|
+
if(editor.minimapEnabled !== false){
|
|
165
|
+
cleanup(container);
|
|
166
|
+
return fail('minimapEnabled should default to false');
|
|
167
|
+
}
|
|
168
|
+
cleanup(container);
|
|
169
|
+
pass();
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
'toggleMinimap should alternate minimapEnabled': async ({pass, fail}) => {
|
|
173
|
+
const { container, editor } = await createEditor();
|
|
174
|
+
editor.toggleMinimap();
|
|
175
|
+
if(editor.minimapEnabled !== true){
|
|
176
|
+
cleanup(container);
|
|
177
|
+
return fail('First toggle should set minimapEnabled to true');
|
|
178
|
+
}
|
|
179
|
+
editor.toggleMinimap();
|
|
180
|
+
if(editor.minimapEnabled !== false){
|
|
181
|
+
cleanup(container);
|
|
182
|
+
return fail('Second toggle should set minimapEnabled to false');
|
|
183
|
+
}
|
|
184
|
+
cleanup(container);
|
|
185
|
+
pass();
|
|
186
|
+
},
|
|
187
|
+
|
|
188
|
+
'setMinimap should dispatch minimap-changed': async ({pass, fail}) => {
|
|
189
|
+
const { container, editor } = await createEditor();
|
|
190
|
+
let detail = null;
|
|
191
|
+
editor.addEventListener('minimap-changed', e => { detail = e.detail; }, { once: true });
|
|
192
|
+
editor.setMinimap(true);
|
|
193
|
+
await editor.updateComplete;
|
|
194
|
+
if(!detail || detail.minimapEnabled !== true){
|
|
195
|
+
cleanup(container);
|
|
196
|
+
return fail('Should dispatch minimap-changed with minimapEnabled: true');
|
|
197
|
+
}
|
|
198
|
+
cleanup(container);
|
|
199
|
+
pass();
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
/*
|
|
203
|
+
Language
|
|
204
|
+
*/
|
|
205
|
+
'setLanguage should dispatch language-changed': async ({pass, fail}) => {
|
|
206
|
+
const { container, editor } = await createEditor();
|
|
207
|
+
let detail = null;
|
|
208
|
+
editor.addEventListener('language-changed', e => { detail = e.detail; }, { once: true });
|
|
209
|
+
editor.setLanguage('css');
|
|
210
|
+
await editor.updateComplete;
|
|
211
|
+
if(!detail || detail.language !== 'css'){
|
|
212
|
+
cleanup(container);
|
|
213
|
+
return fail('Should dispatch language-changed with language: css');
|
|
214
|
+
}
|
|
215
|
+
cleanup(container);
|
|
216
|
+
pass();
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
/*
|
|
220
|
+
Editor Theme
|
|
221
|
+
*/
|
|
222
|
+
'setEditorTheme should dispatch editor-theme-changed': async ({pass, fail}) => {
|
|
223
|
+
const { container, editor } = await createEditor();
|
|
224
|
+
let detail = null;
|
|
225
|
+
editor.addEventListener('editor-theme-changed', e => { detail = e.detail; }, { once: true });
|
|
226
|
+
editor.setEditorTheme('dark');
|
|
227
|
+
await editor.updateComplete;
|
|
228
|
+
if(!detail || detail.editorTheme !== 'dark'){
|
|
229
|
+
cleanup(container);
|
|
230
|
+
return fail('Should dispatch editor-theme-changed with editorTheme: dark');
|
|
231
|
+
}
|
|
232
|
+
cleanup(container);
|
|
233
|
+
pass();
|
|
234
|
+
},
|
|
235
|
+
|
|
236
|
+
'setEditorTheme should reject invalid values': async ({pass, fail}) => {
|
|
237
|
+
const { container, editor } = await createEditor();
|
|
238
|
+
editor.setEditorTheme('auto');
|
|
239
|
+
editor.setEditorTheme('invalid');
|
|
240
|
+
if(editor.editorTheme !== 'auto'){
|
|
241
|
+
cleanup(container);
|
|
242
|
+
return fail('Should not change editorTheme to invalid value');
|
|
243
|
+
}
|
|
244
|
+
cleanup(container);
|
|
245
|
+
pass();
|
|
246
|
+
},
|
|
247
|
+
|
|
248
|
+
/*
|
|
249
|
+
Public API
|
|
250
|
+
*/
|
|
251
|
+
'formatCode should not throw without monacoEditor': async ({pass, fail}) => {
|
|
252
|
+
const { container, editor } = await createEditor();
|
|
253
|
+
try {
|
|
254
|
+
editor.formatCode();
|
|
255
|
+
cleanup(container);
|
|
256
|
+
pass();
|
|
257
|
+
} catch(e) {
|
|
258
|
+
cleanup(container);
|
|
259
|
+
fail(`formatCode threw: ${e.message}`);
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
|
|
263
|
+
'getValue should return current value': async ({pass, fail}) => {
|
|
264
|
+
const { container, editor } = await createEditor();
|
|
265
|
+
const val = editor.getValue();
|
|
266
|
+
if(typeof val !== 'string'){
|
|
267
|
+
cleanup(container);
|
|
268
|
+
return fail('getValue should return a string');
|
|
269
|
+
}
|
|
270
|
+
cleanup(container);
|
|
271
|
+
pass();
|
|
272
|
+
},
|
|
273
|
+
|
|
274
|
+
'setValue should update value': async ({pass, fail}) => {
|
|
275
|
+
const { container, editor } = await createEditor();
|
|
276
|
+
editor.setValue('console.log("test");');
|
|
277
|
+
const val = editor.getValue();
|
|
278
|
+
if(val !== 'console.log("test");'){
|
|
279
|
+
cleanup(container);
|
|
280
|
+
return fail(`Expected "console.log("test");", got "${val}"`);
|
|
281
|
+
}
|
|
282
|
+
cleanup(container);
|
|
283
|
+
pass();
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
'clear should empty the editor': async ({pass, fail}) => {
|
|
287
|
+
const { container, editor } = await createEditor();
|
|
288
|
+
editor.setValue('some code');
|
|
289
|
+
editor.clear();
|
|
290
|
+
if(editor.getValue() !== ''){
|
|
291
|
+
cleanup(container);
|
|
292
|
+
return fail('clear should set value to empty string');
|
|
293
|
+
}
|
|
294
|
+
cleanup(container);
|
|
295
|
+
pass();
|
|
296
|
+
}
|
|
297
|
+
};
|