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

Convert to ESM #880

Merged
merged 13 commits into from
Sep 12, 2022
2 changes: 1 addition & 1 deletion __tests__/console-utils.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const consoleUtils = require("../editor/js/editor-libs/console-utils");
import * as consoleUtils from "../editor/js/editor-libs/console-utils";

describe("console utils", () => {
describe("formatOutput", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/processor.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const processor = require("../lib/processor");
import * as processor from "../lib/processor";

describe("processor", () => {
describe("preprocessHTML", () => {
Expand Down
2 changes: 1 addition & 1 deletion editor/js/css-examples-libs.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
const Prism = require("prismjs");
import Prism from "prismjs";
10 changes: 4 additions & 6 deletions editor/js/editable-css.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
(function () {
"use strict";

var clippy = require("./editor-libs/clippy");
var mceEvents = require("./editor-libs/events");
var mceUtils = require("./editor-libs/mce-utils");
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";

(function () {
var exampleChoiceList = document.getElementById("example-choice-list");
var exampleChoices = exampleChoiceList.querySelectorAll(".example-choice");
var editorWrapper = document.getElementById("editor-wrapper");
Expand Down
12 changes: 5 additions & 7 deletions editor/js/editable-js.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
(function () {
"use strict";

var featureDetector = require("./editor-libs/feature-detector.js");
var mceConsole = require("./editor-libs/console");
var mceEvents = require("./editor-libs/events.js");
var mceUtils = require("./editor-libs/mce-utils");
import * as featureDetector from "./editor-libs/feature-detector.js";
import mceConsole from "./editor-libs/console.js";
import * as mceEvents from "./editor-libs/events.js";
import * as mceUtils from "./editor-libs/mce-utils.js";

(function () {
var codeBlock = document.getElementById("static-js");
var exampleFeature = codeBlock.dataset["feature"];
var execute = document.getElementById("execute");
Expand Down
15 changes: 7 additions & 8 deletions editor/js/editable-wat.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
(function () {
"use strict";

var featureDetector = require("./editor-libs/feature-detector.js");
var mceConsole = require("./editor-libs/console");
var mceEvents = require("./editor-libs/events.js");
var mceUtils = require("./editor-libs/mce-utils");
import * as featureDetector from "./editor-libs/feature-detector.js";
import mceConsole from "./editor-libs/console.js";
import * as mceEvents from "./editor-libs/events.js";
import * as mceUtils from "./editor-libs/mce-utils.js";
import wabtConstructor from "wabt";
caugner marked this conversation as resolved.
Show resolved Hide resolved

(function () {
var watCodeBlock = document.getElementById("static-wat");
var jsCodeBlock = document.getElementById("static-js");
var exampleFeature = watCodeBlock.dataset["feature"];
var execute = document.getElementById("execute");
var liveContainer = "";
var output = document.querySelector("#console code");
var reset = document.getElementById("reset");
var wabtInitialized = require("wabt")();
var wabtInitialized = wabtConstructor();

var tabContainer = document.getElementById("tab-container");
var tabs = tabContainer.querySelectorAll("button[role='tab']");
Expand Down
102 changes: 49 additions & 53 deletions editor/js/editor-libs/clippy.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var mceUtils = require("./mce-utils");
var Clipboard = require("clipboard");
import * as mceUtils from "./mce-utils.js";
import Clipboard from "clipboard";

/**
* Positions the copy to clipboard success message based on the
Expand All @@ -8,7 +8,6 @@ var Clipboard = require("clipboard");
* @param {Object} msgContainer - The feedback message container
*/
function setClippyPosition(clippyEvent, msgContainer) {
"use strict";
var trigger = clippyEvent.trigger;
var triggerParent = trigger.offsetParent;
/* calculate the base top offset by combining the top
Expand All @@ -23,60 +22,57 @@ function setClippyPosition(clippyEvent, msgContainer) {
msgContainer.style.left = positionLeft;
}

module.exports = {
/**
* Initialise clipboard.js, and setup success handler
*/
addClippy: function () {
"use strict";
var clipboard = new Clipboard(".copy", {
target: function (clippyButton) {
var targetAttr = clippyButton.dataset.clipboardTarget;
if (targetAttr) {
// The attribute will override the automated target selection
return document.querySelector(targetAttr);
} else {
// Get its parent until it finds an example choice
var choiceElem = mceUtils.findParentChoiceElem(clippyButton);
// Use the first code element to prevent extra text
var firstCodeElem = choiceElem.getElementsByTagName("code")[0];
return firstCodeElem;
}
},
});
/**
* Initialise clipboard.js, and setup success handler
*/
export function addClippy() {
var clipboard = new Clipboard(".copy", {
target: function (clippyButton) {
var targetAttr = clippyButton.dataset.clipboardTarget;
if (targetAttr) {
// The attribute will override the automated target selection
return document.querySelector(targetAttr);
} else {
// Get its parent until it finds an example choice
var choiceElem = mceUtils.findParentChoiceElem(clippyButton);
// Use the first code element to prevent extra text
var firstCodeElem = choiceElem.getElementsByTagName("code")[0];
return firstCodeElem;
}
},
});

clipboard.on("success", function (event) {
var msgContainer = document.getElementById("user-message");
clipboard.on("success", function (event) {
var msgContainer = document.getElementById("user-message");

msgContainer.classList.add("show");
msgContainer.setAttribute("aria-hidden", false);
msgContainer.classList.add("show");
msgContainer.setAttribute("aria-hidden", false);

setClippyPosition(event, msgContainer);
setClippyPosition(event, msgContainer);

window.setTimeout(function () {
msgContainer.classList.remove("show");
msgContainer.setAttribute("aria-hidden", true);
}, 1000);
window.setTimeout(function () {
msgContainer.classList.remove("show");
msgContainer.setAttribute("aria-hidden", true);
}, 1000);

event.clearSelection();
});
},
/**
* Hides all instances of the clippy button, then shows
* the button in the container element passed in
* @param {Object} container - The container containing the button to show
*/
toggleClippy: function (container) {
"use strict";
var activeClippy = container.querySelector(".copy");
var clippyButtons = document.querySelectorAll(".copy");
event.clearSelection();
});
}

for (var i = 0, l = clippyButtons.length; i < l; i++) {
clippyButtons[i].classList.add("hidden");
clippyButtons[i].setAttribute("aria-hidden", true);
}
/**
* Hides all instances of the clippy button, then shows
* the button in the container element passed in
* @param {Object} container - The container containing the button to show
*/
export function toggleClippy(container) {
var activeClippy = container.querySelector(".copy");
var clippyButtons = document.querySelectorAll(".copy");

for (var i = 0, l = clippyButtons.length; i < l; i++) {
clippyButtons[i].classList.add("hidden");
clippyButtons[i].setAttribute("aria-hidden", true);
}

activeClippy.classList.remove("hidden");
activeClippy.setAttribute("aria-hidden", false);
},
};
activeClippy.classList.remove("hidden");
activeClippy.setAttribute("aria-hidden", false);
}
Loading