chore: rework js imports (#766)

This commit is contained in:
Robert Kaussow 2024-01-09 14:29:53 +01:00 committed by GitHub
parent ff6e9ed824
commit 7fa94f3033
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 44 additions and 58 deletions

View File

@ -1,22 +1,13 @@
{ {
"env": { "env": {
"browser": true, "browser": true,
"es6": true, "es2017": true
"amd": true
}, },
"extends": ["plugin:prettier/recommended"], "extends": ["plugin:prettier/recommended"],
"parser": "@babel/eslint-parser", "parser": "@babel/eslint-parser",
"parserOptions": { "parserOptions": {
"sourceType": "module", "sourceType": "module",
"requireConfigFile": false, "requireConfigFile": false
"allowImportExportEverywhere": true
}, },
"plugins": ["prettier"], "plugins": ["prettier"]
"rules": {
"require-await": "warn"
},
"globals": {
"require": false,
"requirejs": false
}
} }

View File

@ -1,26 +0,0 @@
const { createCopyButton } = require("./copycode.js")
const Clipboard = require("clipboard")
document.addEventListener("DOMContentLoaded", function (event) {
let clipboard = new Clipboard(".clip")
clipboard.on("success", function (e) {
const trigger = e.trigger
if (trigger.hasAttribute("data-copy-feedback")) {
trigger.classList.add("gdoc-post__codecopy--success", "gdoc-post__codecopy--out")
trigger.querySelector(".gdoc-icon.copy").classList.add("hidden")
trigger.querySelector(".gdoc-icon.check").classList.remove("hidden")
setTimeout(function () {
trigger.classList.remove("gdoc-post__codecopy--success", "gdoc-post__codecopy--out")
trigger.querySelector(".gdoc-icon.copy").classList.remove("hidden")
trigger.querySelector(".gdoc-icon.check").classList.add("hidden")
}, 3000)
}
e.clearSelection()
})
document.querySelectorAll(".highlight").forEach((highlightDiv) => createCopyButton(highlightDiv))
})

View File

@ -1,6 +1,5 @@
const Storage = require("store2") import Storage from "store2"
const { TOGGLE_COLOR_THEMES, THEME, COLOR_THEME_AUTO } = require("./config.js") import { TOGGLE_COLOR_THEMES, THEME, COLOR_THEME_AUTO } from "./config.js"
;(() => { ;(() => {
applyTheme() applyTheme()
})() })()

View File

@ -1,4 +1,30 @@
export function createCopyButton(highlightDiv) { import Clipboard from "clipboard"
document.addEventListener("DOMContentLoaded", function (event) {
let clipboard = new Clipboard(".clip")
clipboard.on("success", function (e) {
const trigger = e.trigger
if (trigger.hasAttribute("data-copy-feedback")) {
trigger.classList.add("gdoc-post__codecopy--success", "gdoc-post__codecopy--out")
trigger.querySelector(".gdoc-icon.copy").classList.add("hidden")
trigger.querySelector(".gdoc-icon.check").classList.remove("hidden")
setTimeout(function () {
trigger.classList.remove("gdoc-post__codecopy--success", "gdoc-post__codecopy--out")
trigger.querySelector(".gdoc-icon.copy").classList.remove("hidden")
trigger.querySelector(".gdoc-icon.check").classList.add("hidden")
}, 3000)
}
e.clearSelection()
})
document.querySelectorAll(".highlight").forEach((highlightDiv) => createCopyButton(highlightDiv))
})
function createCopyButton(highlightDiv) {
const button = document.createElement("span") const button = document.createElement("span")
let codeSelector = "pre > code" let codeSelector = "pre > code"

View File

@ -1,9 +1,4 @@
import "katex/dist/katex.css" import "katex/dist/katex.css"
import renderMathInElement from "katex/dist/contrib/auto-render.mjs"
document.addEventListener("DOMContentLoaded", function () {
import("katex/dist/contrib/auto-render")
.then(({ default: renderMathInElement }) => {
renderMathInElement(document.body) renderMathInElement(document.body)
})
.catch((error) => console.error(error))
})

View File

@ -1,6 +1,6 @@
const Storage = require("store2") import Storage from "store2"
const { v4: uuidv4 } = require("uuid") import { v4 as uuidv4 } from "uuid"
const { COLOR_THEME_DARK, THEME, COLOR_THEME_AUTO } = require("./config.js") import { COLOR_THEME_DARK, THEME, COLOR_THEME_AUTO } from "./config.js"
import mermaid from "mermaid" import mermaid from "mermaid"

View File

@ -1,7 +1,7 @@
const groupBy = require("lodash/groupBy") import groupBy from "lodash/groupBy"
const truncate = require("lodash/truncate") import truncate from "lodash/truncate"
const { FlexSearch } = require("flexsearch/dist/flexsearch.compact.min") import Document from "flexsearch/dist/module/document"
const { Validator } = require("@cfworker/json-schema") import { Validator } from "@cfworker/json-schema"
document.addEventListener("DOMContentLoaded", function (event) { document.addEventListener("DOMContentLoaded", function (event) {
const input = document.querySelector("#gdoc-search-input") const input = document.querySelector("#gdoc-search-input")
@ -66,7 +66,7 @@ function init(input, searchConfig) {
store: ["title", "href", "parent", "description"] store: ["title", "href", "parent", "description"]
} }
const index = new FlexSearch.Document(indexCfg) const index = new Document(indexCfg)
window.geekdocSearchIndex = index window.geekdocSearchIndex = index
getJson(dataUrl, function (data) { getJson(dataUrl, function (data) {

View File

@ -17,7 +17,7 @@ var config = {
path.resolve("src", "sass", "mobile.scss"), path.resolve("src", "sass", "mobile.scss"),
path.resolve("src", "sass", "print.scss") path.resolve("src", "sass", "print.scss")
], ],
main: path.resolve("src", "js", "app.js"), main: path.resolve("src", "js", "index.js"),
colortheme: path.resolve("src", "js", "colorTheme.js"), colortheme: path.resolve("src", "js", "colorTheme.js"),
mermaid: path.resolve("src", "js", "mermaid.js"), mermaid: path.resolve("src", "js", "mermaid.js"),
katex: [path.resolve("src", "js", "katex.js")].concat( katex: [path.resolve("src", "js", "katex.js")].concat(
@ -34,6 +34,7 @@ var config = {
watchOptions: { watchOptions: {
ignored: ["/exampleSite/", "/node_modules/"] ignored: ["/exampleSite/", "/node_modules/"]
}, },
target: ["web", "es2017"],
plugins: [ plugins: [
new CopyPlugin({ new CopyPlugin({
patterns: [ patterns: [