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
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import '../../../src/components/CodeEditor.js';
|
|
2
|
+
import '../../../src/components/HtmlEditor.js';
|
|
3
|
+
import '../../../src/components/codeEditorControls/Fullscreen.js';
|
|
4
|
+
|
|
5
|
+
const createEditorWithControl = async () => {
|
|
6
|
+
const container = document.createElement('div');
|
|
7
|
+
container.innerHTML = `
|
|
8
|
+
<k-code-editor language="javascript" style="height:200px">
|
|
9
|
+
<k-cec-fullscreen slot="toolbar-top-right"></k-cec-fullscreen>
|
|
10
|
+
</k-code-editor>
|
|
11
|
+
`;
|
|
12
|
+
document.body.appendChild(container);
|
|
13
|
+
const editor = container.querySelector('k-code-editor');
|
|
14
|
+
await new Promise(r => editor.addEventListener('ready', r, { once: true }));
|
|
15
|
+
const control = container.querySelector('k-cec-fullscreen');
|
|
16
|
+
return { container, editor, control };
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const cleanup = container => {
|
|
20
|
+
if(container?.parentNode) container.parentNode.removeChild(container);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default {
|
|
24
|
+
'should create element with shadow root': async ({pass, fail}) => {
|
|
25
|
+
const { container, control } = await createEditorWithControl();
|
|
26
|
+
if(!control?.shadowRoot){
|
|
27
|
+
cleanup(container);
|
|
28
|
+
return fail('Should create element with shadow root');
|
|
29
|
+
}
|
|
30
|
+
cleanup(container);
|
|
31
|
+
pass();
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
'should render a button': async ({pass, fail}) => {
|
|
35
|
+
const { container, control } = await createEditorWithControl();
|
|
36
|
+
await control.updateComplete;
|
|
37
|
+
if(!control.shadowRoot.querySelector('button')){
|
|
38
|
+
cleanup(container);
|
|
39
|
+
return fail('Should render a button');
|
|
40
|
+
}
|
|
41
|
+
cleanup(container);
|
|
42
|
+
pass();
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
'should find parent editor': async ({pass, fail}) => {
|
|
46
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
47
|
+
if(control.editor !== editor){
|
|
48
|
+
cleanup(container);
|
|
49
|
+
return fail('Should find parent k-code-editor');
|
|
50
|
+
}
|
|
51
|
+
cleanup(container);
|
|
52
|
+
pass();
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
'should default to fullscreen false': async ({pass, fail}) => {
|
|
56
|
+
const { container, control } = await createEditorWithControl();
|
|
57
|
+
if(control.fullscreen !== false){
|
|
58
|
+
cleanup(container);
|
|
59
|
+
return fail('Should default to fullscreen=false');
|
|
60
|
+
}
|
|
61
|
+
cleanup(container);
|
|
62
|
+
pass();
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
'click should call toggleFullscreen on editor': async ({pass, fail}) => {
|
|
66
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
67
|
+
await control.updateComplete;
|
|
68
|
+
let called = false;
|
|
69
|
+
const orig = editor.toggleFullscreen.bind(editor);
|
|
70
|
+
editor.toggleFullscreen = () => { called = true; return orig(); };
|
|
71
|
+
control.shadowRoot.querySelector('button').click();
|
|
72
|
+
if(!called){
|
|
73
|
+
cleanup(container);
|
|
74
|
+
return fail('Should call toggleFullscreen on click');
|
|
75
|
+
}
|
|
76
|
+
cleanup(container);
|
|
77
|
+
pass();
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
'click should toggle control fullscreen state to true': async ({pass, fail}) => {
|
|
81
|
+
const { container, control } = await createEditorWithControl();
|
|
82
|
+
await control.updateComplete;
|
|
83
|
+
control.shadowRoot.querySelector('button').click();
|
|
84
|
+
await control.updateComplete;
|
|
85
|
+
if(!control.fullscreen){
|
|
86
|
+
cleanup(container);
|
|
87
|
+
return fail('Should set fullscreen to true after click');
|
|
88
|
+
}
|
|
89
|
+
cleanup(container);
|
|
90
|
+
pass();
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
'button title should update on fullscreen': async ({pass, fail}) => {
|
|
94
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
95
|
+
await control.updateComplete;
|
|
96
|
+
const btnBefore = control.shadowRoot.querySelector('button');
|
|
97
|
+
if(btnBefore.title !== 'Fullscreen'){
|
|
98
|
+
cleanup(container);
|
|
99
|
+
return fail(`Expected title "Fullscreen", got "${btnBefore.title}"`);
|
|
100
|
+
}
|
|
101
|
+
editor.enterFullscreen();
|
|
102
|
+
await control.updateComplete;
|
|
103
|
+
const btnAfter = control.shadowRoot.querySelector('button');
|
|
104
|
+
if(btnAfter.title !== 'Exit Fullscreen'){
|
|
105
|
+
cleanup(container);
|
|
106
|
+
editor.exitFullscreen();
|
|
107
|
+
return fail(`Expected title "Exit Fullscreen", got "${btnAfter.title}"`);
|
|
108
|
+
}
|
|
109
|
+
editor.exitFullscreen();
|
|
110
|
+
cleanup(container);
|
|
111
|
+
pass();
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
'control should sync state when editor dispatches fullscreen-changed': async ({pass, fail}) => {
|
|
115
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
116
|
+
editor.enterFullscreen();
|
|
117
|
+
await control.updateComplete;
|
|
118
|
+
if(!control.fullscreen){
|
|
119
|
+
editor.exitFullscreen();
|
|
120
|
+
cleanup(container);
|
|
121
|
+
return fail('Control should sync to fullscreen=true');
|
|
122
|
+
}
|
|
123
|
+
editor.exitFullscreen();
|
|
124
|
+
await control.updateComplete;
|
|
125
|
+
if(control.fullscreen){
|
|
126
|
+
cleanup(container);
|
|
127
|
+
return fail('Control should sync to fullscreen=false');
|
|
128
|
+
}
|
|
129
|
+
cleanup(container);
|
|
130
|
+
pass();
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
'should not be hidden in visual mode when in html editor': async ({pass, fail}) => {
|
|
134
|
+
const container = document.createElement('div');
|
|
135
|
+
container.innerHTML = `
|
|
136
|
+
<k-html-editor>
|
|
137
|
+
<k-cec-fullscreen slot="toolbar-top-right"></k-cec-fullscreen>
|
|
138
|
+
</k-html-editor>
|
|
139
|
+
`;
|
|
140
|
+
document.body.appendChild(container);
|
|
141
|
+
const editor = container.querySelector('k-html-editor');
|
|
142
|
+
await new Promise(r => editor.addEventListener('ready', r, { once: true }));
|
|
143
|
+
const control = container.querySelector('k-cec-fullscreen');
|
|
144
|
+
await control.updateComplete;
|
|
145
|
+
if(control.hidden){
|
|
146
|
+
cleanup(container);
|
|
147
|
+
return fail('Fullscreen control should not be hidden in visual mode');
|
|
148
|
+
}
|
|
149
|
+
cleanup(container);
|
|
150
|
+
pass();
|
|
151
|
+
}
|
|
152
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import '../../../src/components/CodeEditor.js';
|
|
2
|
+
import '../../../src/components/codeEditorControls/LanguageSelect.js';
|
|
3
|
+
|
|
4
|
+
const createEditorWithControl = async () => {
|
|
5
|
+
const container = document.createElement('div');
|
|
6
|
+
container.innerHTML = `
|
|
7
|
+
<k-code-editor language="javascript" style="height:200px">
|
|
8
|
+
<k-cec-language slot="toolbar-top-right"></k-cec-language>
|
|
9
|
+
</k-code-editor>
|
|
10
|
+
`;
|
|
11
|
+
document.body.appendChild(container);
|
|
12
|
+
const editor = container.querySelector('k-code-editor');
|
|
13
|
+
await new Promise(r => editor.addEventListener('ready', r, { once: true }));
|
|
14
|
+
const control = container.querySelector('k-cec-language');
|
|
15
|
+
return { container, editor, control };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const cleanup = container => {
|
|
19
|
+
if(container?.parentNode) container.parentNode.removeChild(container);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
'should create element with select': async ({pass, fail}) => {
|
|
24
|
+
const { container, control } = await createEditorWithControl();
|
|
25
|
+
await control.updateComplete;
|
|
26
|
+
if(!control.shadowRoot.querySelector('select')){
|
|
27
|
+
cleanup(container);
|
|
28
|
+
return fail('Should render a select');
|
|
29
|
+
}
|
|
30
|
+
cleanup(container);
|
|
31
|
+
pass();
|
|
32
|
+
},
|
|
33
|
+
|
|
34
|
+
'should find parent editor': async ({pass, fail}) => {
|
|
35
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
36
|
+
if(control.editor !== editor){
|
|
37
|
+
cleanup(container);
|
|
38
|
+
return fail('Should find parent k-code-editor');
|
|
39
|
+
}
|
|
40
|
+
cleanup(container);
|
|
41
|
+
pass();
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
'should sync initial value from editor language': async ({pass, fail}) => {
|
|
45
|
+
const { container, control } = await createEditorWithControl();
|
|
46
|
+
await control.updateComplete;
|
|
47
|
+
if(control.value !== 'javascript'){
|
|
48
|
+
cleanup(container);
|
|
49
|
+
return fail(`Expected 'javascript', got '${control.value}'`);
|
|
50
|
+
}
|
|
51
|
+
cleanup(container);
|
|
52
|
+
pass();
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
'should have multiple language options': async ({pass, fail}) => {
|
|
56
|
+
const { container, control } = await createEditorWithControl();
|
|
57
|
+
await control.updateComplete;
|
|
58
|
+
const options = control.shadowRoot.querySelectorAll('option');
|
|
59
|
+
if(options.length < 10){
|
|
60
|
+
cleanup(container);
|
|
61
|
+
return fail(`Expected at least 10 options, got ${options.length}`);
|
|
62
|
+
}
|
|
63
|
+
cleanup(container);
|
|
64
|
+
pass();
|
|
65
|
+
},
|
|
66
|
+
|
|
67
|
+
'change should call editor.setLanguage()': async ({pass, fail}) => {
|
|
68
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
69
|
+
await control.updateComplete;
|
|
70
|
+
let calledWith = null;
|
|
71
|
+
editor.setLanguage = lang => { calledWith = lang; return editor; };
|
|
72
|
+
const select = control.shadowRoot.querySelector('select');
|
|
73
|
+
select.value = 'html';
|
|
74
|
+
select.dispatchEvent(new Event('change'));
|
|
75
|
+
if(calledWith !== 'html'){
|
|
76
|
+
cleanup(container);
|
|
77
|
+
return fail(`Expected setLanguage('html'), got setLanguage('${calledWith}')`);
|
|
78
|
+
}
|
|
79
|
+
cleanup(container);
|
|
80
|
+
pass();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import '../../../src/components/CodeEditor.js';
|
|
2
|
+
import '../../../src/components/codeEditorControls/Minimap.js';
|
|
3
|
+
|
|
4
|
+
const createEditorWithControl = async () => {
|
|
5
|
+
const container = document.createElement('div');
|
|
6
|
+
container.innerHTML = `
|
|
7
|
+
<k-code-editor language="javascript" style="height:200px">
|
|
8
|
+
<k-cec-minimap slot="toolbar-top-left"></k-cec-minimap>
|
|
9
|
+
</k-code-editor>
|
|
10
|
+
`;
|
|
11
|
+
document.body.appendChild(container);
|
|
12
|
+
const editor = container.querySelector('k-code-editor');
|
|
13
|
+
await new Promise(r => editor.addEventListener('ready', r, { once: true }));
|
|
14
|
+
const control = container.querySelector('k-cec-minimap');
|
|
15
|
+
return { container, editor, control };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const cleanup = container => {
|
|
19
|
+
if(container?.parentNode) container.parentNode.removeChild(container);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
'should create element': async ({pass, fail}) => {
|
|
24
|
+
const { container, control } = await createEditorWithControl();
|
|
25
|
+
if(!control?.shadowRoot){
|
|
26
|
+
cleanup(container);
|
|
27
|
+
return fail('Should create element with shadow root');
|
|
28
|
+
}
|
|
29
|
+
cleanup(container);
|
|
30
|
+
pass();
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
'should render a button': async ({pass, fail}) => {
|
|
34
|
+
const { container, control } = await createEditorWithControl();
|
|
35
|
+
await control.updateComplete;
|
|
36
|
+
if(!control.shadowRoot.querySelector('button')){
|
|
37
|
+
cleanup(container);
|
|
38
|
+
return fail('Should render a button');
|
|
39
|
+
}
|
|
40
|
+
cleanup(container);
|
|
41
|
+
pass();
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
'should find parent editor': async ({pass, fail}) => {
|
|
45
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
46
|
+
if(control.editor !== editor){
|
|
47
|
+
cleanup(container);
|
|
48
|
+
return fail('Should find parent k-code-editor');
|
|
49
|
+
}
|
|
50
|
+
cleanup(container);
|
|
51
|
+
pass();
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
'should default to inactive (minimap off)': async ({pass, fail}) => {
|
|
55
|
+
const { container, control } = await createEditorWithControl();
|
|
56
|
+
if(control.active){
|
|
57
|
+
cleanup(container);
|
|
58
|
+
return fail('Should default to inactive');
|
|
59
|
+
}
|
|
60
|
+
cleanup(container);
|
|
61
|
+
pass();
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
'click should toggle minimap on': async ({pass, fail}) => {
|
|
65
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
66
|
+
await control.updateComplete;
|
|
67
|
+
let called = false;
|
|
68
|
+
const orig = editor.toggleMinimap.bind(editor);
|
|
69
|
+
editor.toggleMinimap = () => { called = true; return orig(); };
|
|
70
|
+
control.shadowRoot.querySelector('button').click();
|
|
71
|
+
await editor.updateComplete;
|
|
72
|
+
await control.updateComplete;
|
|
73
|
+
if(!called){
|
|
74
|
+
cleanup(container);
|
|
75
|
+
return fail('Should call toggleMinimap on click');
|
|
76
|
+
}
|
|
77
|
+
if(!control.active){
|
|
78
|
+
cleanup(container);
|
|
79
|
+
return fail('Should toggle active to true');
|
|
80
|
+
}
|
|
81
|
+
cleanup(container);
|
|
82
|
+
pass();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import '../../../src/components/HtmlEditor.js';
|
|
2
|
+
import '../../../src/components/codeEditorControls/CopyCode.js';
|
|
3
|
+
import '../../../src/components/codeEditorControls/WordWrap.js';
|
|
4
|
+
|
|
5
|
+
const createHtmlEditorWithControls = async () => {
|
|
6
|
+
const container = document.createElement('div');
|
|
7
|
+
container.innerHTML = `
|
|
8
|
+
<k-html-editor>
|
|
9
|
+
<k-cec-copy-code slot="toolbar-top-left"></k-cec-copy-code>
|
|
10
|
+
<k-cec-word-wrap slot="toolbar-top-left"></k-cec-word-wrap>
|
|
11
|
+
</k-html-editor>
|
|
12
|
+
`;
|
|
13
|
+
document.body.appendChild(container);
|
|
14
|
+
const editor = container.querySelector('k-html-editor');
|
|
15
|
+
await new Promise(r => editor.addEventListener('ready', r, { once: true }));
|
|
16
|
+
const copyCode = container.querySelector('k-cec-copy-code');
|
|
17
|
+
const wordWrap = container.querySelector('k-cec-word-wrap');
|
|
18
|
+
return { container, editor, copyCode, wordWrap };
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const cleanup = container => {
|
|
22
|
+
if(container?.parentNode) container.parentNode.removeChild(container);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
'controls should be hidden in HtmlEditor visual mode': async ({pass, fail}) => {
|
|
27
|
+
const { container, copyCode, wordWrap } = await createHtmlEditorWithControls();
|
|
28
|
+
await copyCode.updateComplete;
|
|
29
|
+
if(!copyCode.hidden){
|
|
30
|
+
cleanup(container);
|
|
31
|
+
return fail('CopyCode should be hidden in visual mode');
|
|
32
|
+
}
|
|
33
|
+
if(!wordWrap.hidden){
|
|
34
|
+
cleanup(container);
|
|
35
|
+
return fail('WordWrap should be hidden in visual mode');
|
|
36
|
+
}
|
|
37
|
+
cleanup(container);
|
|
38
|
+
pass();
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
'controls should be visible in HtmlEditor code mode': async ({pass, fail}) => {
|
|
42
|
+
const { container, editor, copyCode, wordWrap } = await createHtmlEditorWithControls();
|
|
43
|
+
editor.mode = 'code';
|
|
44
|
+
await new Promise(r => editor.addEventListener('mode-changed', r, { once: true }));
|
|
45
|
+
await copyCode.updateComplete;
|
|
46
|
+
if(copyCode.hidden){
|
|
47
|
+
cleanup(container);
|
|
48
|
+
return fail('CopyCode should be visible in code mode');
|
|
49
|
+
}
|
|
50
|
+
if(wordWrap.hidden){
|
|
51
|
+
cleanup(container);
|
|
52
|
+
return fail('WordWrap should be visible in code mode');
|
|
53
|
+
}
|
|
54
|
+
cleanup(container);
|
|
55
|
+
pass();
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
'controls should hide again when switching back to visual': async ({pass, fail}) => {
|
|
59
|
+
const { container, editor, copyCode } = await createHtmlEditorWithControls();
|
|
60
|
+
editor.mode = 'code';
|
|
61
|
+
await new Promise(r => editor.addEventListener('mode-changed', r, { once: true }));
|
|
62
|
+
editor.mode = 'visual';
|
|
63
|
+
await new Promise(r => editor.addEventListener('mode-changed', r, { once: true }));
|
|
64
|
+
await copyCode.updateComplete;
|
|
65
|
+
if(!copyCode.hidden){
|
|
66
|
+
cleanup(container);
|
|
67
|
+
return fail('CopyCode should be hidden after switching back to visual');
|
|
68
|
+
}
|
|
69
|
+
cleanup(container);
|
|
70
|
+
pass();
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
'controls should find HtmlEditor as parent': async ({pass, fail}) => {
|
|
74
|
+
const { container, editor, copyCode } = await createHtmlEditorWithControls();
|
|
75
|
+
if(copyCode.editor !== editor){
|
|
76
|
+
cleanup(container);
|
|
77
|
+
return fail('Should find k-html-editor as parent');
|
|
78
|
+
}
|
|
79
|
+
cleanup(container);
|
|
80
|
+
pass();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import '../../../src/components/CodeEditor.js';
|
|
2
|
+
import '../../../src/components/codeEditorControls/Undo.js';
|
|
3
|
+
import '../../../src/components/codeEditorControls/Redo.js';
|
|
4
|
+
|
|
5
|
+
const createEditorWithControls = async () => {
|
|
6
|
+
const container = document.createElement('div');
|
|
7
|
+
container.innerHTML = `
|
|
8
|
+
<k-code-editor language="javascript" style="height:200px">
|
|
9
|
+
<k-cec-undo slot="toolbar-top-left"></k-cec-undo>
|
|
10
|
+
<k-cec-redo slot="toolbar-top-left"></k-cec-redo>
|
|
11
|
+
</k-code-editor>
|
|
12
|
+
`;
|
|
13
|
+
document.body.appendChild(container);
|
|
14
|
+
const editor = container.querySelector('k-code-editor');
|
|
15
|
+
await new Promise(r => editor.addEventListener('ready', r, { once: true }));
|
|
16
|
+
const undo = container.querySelector('k-cec-undo');
|
|
17
|
+
const redo = container.querySelector('k-cec-redo');
|
|
18
|
+
return { container, editor, undo, redo };
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const cleanup = container => {
|
|
22
|
+
if(container?.parentNode) container.parentNode.removeChild(container);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
'undo should create element with button': async ({pass, fail}) => {
|
|
27
|
+
const { container, undo } = await createEditorWithControls();
|
|
28
|
+
await undo.updateComplete;
|
|
29
|
+
if(!undo.shadowRoot.querySelector('button')){
|
|
30
|
+
cleanup(container);
|
|
31
|
+
return fail('Undo should render a button');
|
|
32
|
+
}
|
|
33
|
+
cleanup(container);
|
|
34
|
+
pass();
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
'redo should create element with button': async ({pass, fail}) => {
|
|
38
|
+
const { container, redo } = await createEditorWithControls();
|
|
39
|
+
await redo.updateComplete;
|
|
40
|
+
if(!redo.shadowRoot.querySelector('button')){
|
|
41
|
+
cleanup(container);
|
|
42
|
+
return fail('Redo should render a button');
|
|
43
|
+
}
|
|
44
|
+
cleanup(container);
|
|
45
|
+
pass();
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
'undo should find parent editor': async ({pass, fail}) => {
|
|
49
|
+
const { container, editor, undo } = await createEditorWithControls();
|
|
50
|
+
if(undo.editor !== editor){
|
|
51
|
+
cleanup(container);
|
|
52
|
+
return fail('Undo should find parent k-code-editor');
|
|
53
|
+
}
|
|
54
|
+
cleanup(container);
|
|
55
|
+
pass();
|
|
56
|
+
},
|
|
57
|
+
|
|
58
|
+
'undo click should call editor.undo()': async ({pass, fail}) => {
|
|
59
|
+
const { container, editor, undo } = await createEditorWithControls();
|
|
60
|
+
await undo.updateComplete;
|
|
61
|
+
let called = false;
|
|
62
|
+
editor.undo = () => { called = true; };
|
|
63
|
+
undo.shadowRoot.querySelector('button').click();
|
|
64
|
+
if(!called){
|
|
65
|
+
cleanup(container);
|
|
66
|
+
return fail('Should call editor.undo() on click');
|
|
67
|
+
}
|
|
68
|
+
cleanup(container);
|
|
69
|
+
pass();
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
'redo click should call editor.redo()': async ({pass, fail}) => {
|
|
73
|
+
const { container, editor, redo } = await createEditorWithControls();
|
|
74
|
+
await redo.updateComplete;
|
|
75
|
+
let called = false;
|
|
76
|
+
editor.redo = () => { called = true; };
|
|
77
|
+
redo.shadowRoot.querySelector('button').click();
|
|
78
|
+
if(!called){
|
|
79
|
+
cleanup(container);
|
|
80
|
+
return fail('Should call editor.redo() on click');
|
|
81
|
+
}
|
|
82
|
+
cleanup(container);
|
|
83
|
+
pass();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import '../../../src/components/CodeEditor.js';
|
|
2
|
+
import '../../../src/components/codeEditorControls/WordWrap.js';
|
|
3
|
+
|
|
4
|
+
const createEditorWithControl = async () => {
|
|
5
|
+
const container = document.createElement('div');
|
|
6
|
+
container.innerHTML = `
|
|
7
|
+
<k-code-editor language="javascript" style="height:200px">
|
|
8
|
+
<k-cec-word-wrap slot="toolbar-top-left"></k-cec-word-wrap>
|
|
9
|
+
</k-code-editor>
|
|
10
|
+
`;
|
|
11
|
+
document.body.appendChild(container);
|
|
12
|
+
const editor = container.querySelector('k-code-editor');
|
|
13
|
+
await new Promise(r => editor.addEventListener('ready', r, { once: true }));
|
|
14
|
+
const control = container.querySelector('k-cec-word-wrap');
|
|
15
|
+
return { container, editor, control };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const cleanup = container => {
|
|
19
|
+
if(container?.parentNode) container.parentNode.removeChild(container);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default {
|
|
23
|
+
'should create element': async ({pass, fail}) => {
|
|
24
|
+
const { container, control } = await createEditorWithControl();
|
|
25
|
+
if(!control?.shadowRoot){
|
|
26
|
+
cleanup(container);
|
|
27
|
+
return fail('Should create element with shadow root');
|
|
28
|
+
}
|
|
29
|
+
cleanup(container);
|
|
30
|
+
pass();
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
'should render a button': async ({pass, fail}) => {
|
|
34
|
+
const { container, control } = await createEditorWithControl();
|
|
35
|
+
await control.updateComplete;
|
|
36
|
+
if(!control.shadowRoot.querySelector('button')){
|
|
37
|
+
cleanup(container);
|
|
38
|
+
return fail('Should render a button');
|
|
39
|
+
}
|
|
40
|
+
cleanup(container);
|
|
41
|
+
pass();
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
'should find parent editor': async ({pass, fail}) => {
|
|
45
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
46
|
+
if(control.editor !== editor){
|
|
47
|
+
cleanup(container);
|
|
48
|
+
return fail('Should find parent k-code-editor');
|
|
49
|
+
}
|
|
50
|
+
cleanup(container);
|
|
51
|
+
pass();
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
'should default to active (word wrap on)': async ({pass, fail}) => {
|
|
55
|
+
const { container, control } = await createEditorWithControl();
|
|
56
|
+
if(!control.active){
|
|
57
|
+
cleanup(container);
|
|
58
|
+
return fail('Should default to active');
|
|
59
|
+
}
|
|
60
|
+
cleanup(container);
|
|
61
|
+
pass();
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
'click should toggle word wrap off': async ({pass, fail}) => {
|
|
65
|
+
const { container, editor, control } = await createEditorWithControl();
|
|
66
|
+
await control.updateComplete;
|
|
67
|
+
let called = false;
|
|
68
|
+
const orig = editor.toggleWordWrap.bind(editor);
|
|
69
|
+
editor.toggleWordWrap = () => { called = true; return orig(); };
|
|
70
|
+
control.shadowRoot.querySelector('button').click();
|
|
71
|
+
await editor.updateComplete;
|
|
72
|
+
await control.updateComplete;
|
|
73
|
+
if(!called){
|
|
74
|
+
cleanup(container);
|
|
75
|
+
return fail('Should call toggleWordWrap on click');
|
|
76
|
+
}
|
|
77
|
+
if(control.active){
|
|
78
|
+
cleanup(container);
|
|
79
|
+
return fail('Should toggle active to false');
|
|
80
|
+
}
|
|
81
|
+
cleanup(container);
|
|
82
|
+
pass();
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
'should not be hidden in CodeEditor': async ({pass, fail}) => {
|
|
86
|
+
const { container, control } = await createEditorWithControl();
|
|
87
|
+
await control.updateComplete;
|
|
88
|
+
if(control.hidden){
|
|
89
|
+
cleanup(container);
|
|
90
|
+
return fail('Should not be hidden in CodeEditor');
|
|
91
|
+
}
|
|
92
|
+
cleanup(container);
|
|
93
|
+
pass();
|
|
94
|
+
}
|
|
95
|
+
};
|