Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Prismjs and manual code editing system with CodeMirror #888

Merged
merged 16 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions .babelrc

This file was deleted.

18 changes: 16 additions & 2 deletions editor/css/editable-css.css
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,22 @@
background-color: var(--background-secondary);
}

.live .example-choice code {
padding: 10px 0;
.live .example-choice pre {
width: 100%;
}

.live .example-choice pre .cm-editor {
width: 100%;
height: auto;
text-align: left;
padding: 4px 0;
padding-right: 1rem;
background: none;
border: none;
}

.live .example-choice .ͼ1.cm-editor.cm-focused {
outline: none;
}

.example-choice-list .example-choice:first-child {
Expand Down
57 changes: 0 additions & 57 deletions editor/css/editor-libs/prism-override.css

This file was deleted.

1 change: 0 additions & 1 deletion editor/js/css-examples-libs.js

This file was deleted.

42 changes: 29 additions & 13 deletions editor/js/editable-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import * as clippy from "./editor-libs/clippy.js";
import * as mceEvents from "./editor-libs/events.js";
import * as mceUtils from "./editor-libs/mce-utils.js";
import * as cssEditorUtils from "./editor-libs/css-editor-utils.js";
import {
initCodeEditor,
languageCSS,
} from "./editor-libs/codemirror-editor.js";

import "../css/editor-libs/ui-fonts.css";
import "../css/editor-libs/common.css";
import "../css/editor-libs/prism-override.css";
import "../css/editable-css.css";

(function () {
Expand All @@ -17,6 +20,12 @@ import "../css/editable-css.css";
var output = document.getElementById("output");
var warningNoSupport = document.getElementById("warning-no-support");

function applyCodeMirror(target, code) {
var codeMirror = initCodeEditor(target, code, languageCSS(), {
lineNumbers: false,
});
}

/**
* Enables and initializes the live code editor
*/
Expand All @@ -29,6 +38,14 @@ import "../css/editable-css.css";
var exampleChoice = exampleChoices[i];
var choiceButton = document.createElement("button");
var choiceButtonText = document.createElement("span");
var choiceCode = exampleChoice.querySelector("code");

originalChoices.push(choiceCode.textContent);

applyCodeMirror(
exampleChoice.querySelector("pre"),
choiceCode.textContent
);

choiceButton.setAttribute("type", "button");
choiceButton.classList.add("example-choice-button");
Expand All @@ -38,11 +55,11 @@ import "../css/editable-css.css";
choiceButton.append(choiceButtonText);
exampleChoice.append(choiceButton);

originalChoices.push(exampleChoice.querySelector("code").textContent);

if (exampleChoice.getAttribute("initial-choice")) {
initialChoice = indexOf(exampleChoices, exampleChoice);
}

choiceCode.remove();
}

mceEvents.register();
Expand All @@ -62,16 +79,15 @@ import "../css/editable-css.css";
var resetButton = document.getElementById("reset");

resetButton.addEventListener("click", function () {
for (var i = 0, l = exampleChoices.length; i < l; i++) {
var highlighted = Prism.highlight(
originalChoices[i],
Prism.languages.css
);
// IE11 does not support multiple selectors in `remove`
exampleChoices[i].classList.remove("invalid");
exampleChoices[i].classList.remove("selected");
exampleChoices[i].querySelector("code").innerHTML = highlighted;
}
exampleChoices.forEach(function (e, i) {
var preEl = e.querySelector("pre");
// Remove original codemirror
for (const e of preEl.children) {
e.remove();
}
e.classList.remove("invalid", "selected");
applyCodeMirror(preEl, originalChoices[i]);
});

// Adding or removing class "invalid"
cssEditorUtils.applyInitialSupportWarningState(exampleChoices);
Expand Down
Loading