Skip to content

Commit

Permalink
refactor: rename folder name
Browse files Browse the repository at this point in the history
  • Loading branch information
Jocs committed Jan 14, 2024
1 parent 0d76482 commit 21996df
Show file tree
Hide file tree
Showing 373 changed files with 131 additions and 129 deletions.
77 changes: 40 additions & 37 deletions src/main.ts → examples/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Muya from "../lib/index";
import zh from "../lib/locales/zh";
import MD2Html from "../lib/state/markdownToHtml";
import { TState } from "../lib/state/types";
import Muya from '../packages/index';
import zh from '../packages/locales/zh';
import MD2Html from '../packages/state/markdownToHtml';
import { TState } from '../packages/state/types';
import {
CodeBlockLanguageSelector,
EmojiSelector,
Expand All @@ -16,29 +16,31 @@ import {
TableColumnToolbar,
TableDragBar,
TableRowColumMenu,
} from "../lib/ui/index";
import { DEFAULT_MARKDOWN } from "./mock";
} from '../packages/ui/index';
import { DEFAULT_MARKDOWN } from './mock';

import "./style.css";
import './style.css';

// import "../lib/assets/style.css";
// import "../packages/assets/style.css";

// Fix Intl.Segmenter is not work on firefox.
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (!(Intl as any).Segmenter) {
const polyfill = await import("intl-segmenter-polyfill/dist/bundled");
const polyfill = await import('intl-segmenter-polyfill/dist/bundled');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(Intl as any).Segmenter = await polyfill.createIntlSegmenterPolyfill();
}

const imagePathPicker = async () => {
return "https://pics.ettoday.net/images/2253/d2253152.jpg";
return 'https://pics.ettoday.net/images/2253/d2253152.jpg';
};

const imageAction = async () => {
return new Promise((resolve) => {
setTimeout(() => {
resolve("https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg");
resolve(
'https://gw.alipayobjects.com/zos/rmsportal/KDpgvguMpGfqaHPjicRK.svg'
);
}, 3000);
});
};
Expand All @@ -61,19 +63,18 @@ Muya.use(TableDragBar);
Muya.use(TableRowColumMenu);
Muya.use(PreviewToolBar);

const container: HTMLElement = document.querySelector("#editor")!;
const undoBtn: HTMLButtonElement = document.querySelector("#undo")!;
const redoBtn: HTMLButtonElement = document.querySelector("#redo")!;
const searchInput: HTMLInputElement = document.querySelector("#search")!;
const previousBtn: HTMLButtonElement = document.querySelector("#previous")!;
const nextBtn: HTMLButtonElement = document.querySelector("#next")!;
const replaceInput: HTMLInputElement = document.querySelector("#replace")!;
const singleBtn: HTMLButtonElement = document.querySelector("#single")!;
const allBtn: HTMLButtonElement = document.querySelector("#all")!;
const container: HTMLElement = document.querySelector('#editor')!;
const undoBtn: HTMLButtonElement = document.querySelector('#undo')!;
const redoBtn: HTMLButtonElement = document.querySelector('#redo')!;
const searchInput: HTMLInputElement = document.querySelector('#search')!;
const previousBtn: HTMLButtonElement = document.querySelector('#previous')!;
const nextBtn: HTMLButtonElement = document.querySelector('#next')!;
const replaceInput: HTMLInputElement = document.querySelector('#replace')!;
const singleBtn: HTMLButtonElement = document.querySelector('#single')!;
const allBtn: HTMLButtonElement = document.querySelector('#all')!;
const setContentBtn: HTMLButtonElement =
document.querySelector("#set-content")!;
const selectAllBtn: HTMLButtonElement = document.querySelector("#select-all")!;

document.querySelector('#set-content')!;
const selectAllBtn: HTMLButtonElement = document.querySelector('#select-all')!;

const muya = new Muya(container, {
markdown: DEFAULT_MARKDOWN,
Expand All @@ -83,52 +84,53 @@ muya.locale(zh);

muya.init();

undoBtn.addEventListener("click", () => {
undoBtn.addEventListener('click', () => {
muya.undo();
});

redoBtn.addEventListener("click", () => {
redoBtn.addEventListener('click', () => {
muya.redo();
});

searchInput.addEventListener("input", (event) => {
searchInput.addEventListener('input', (event) => {
const value = (event.target as HTMLInputElement).value;

muya.search(value, { isRegexp: true });
});

previousBtn.addEventListener("click", () => {
muya.find("previous");
previousBtn.addEventListener('click', () => {
muya.find('previous');
});

nextBtn.addEventListener("click", () => {
muya.find("next");
nextBtn.addEventListener('click', () => {
muya.find('next');
});

singleBtn.addEventListener("click", () => {
singleBtn.addEventListener('click', () => {
muya.replace(replaceInput.value, { isSingle: true, isRegexp: true });
});

allBtn.addEventListener("click", () => {
allBtn.addEventListener('click', () => {
muya.replace(replaceInput.value, { isSingle: false, isRegexp: false });
});

selectAllBtn.addEventListener("click", () => {
selectAllBtn.addEventListener('click', () => {
muya.selectAll();
});

const content = [
{
name: "paragraph",
text: "foo bar",
name: 'paragraph',
text: 'foo bar',
},
];

setContentBtn.addEventListener("click", () => {
setContentBtn.addEventListener('click', () => {
muya.setContent(content as TState[]);
});

muya.on("json-change", (_changes) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
muya.on('json-change', (_changes) => {
// console.log(JSON.stringify(muya.getState(), null, 2))
// console.log(muya.getMarkdown())
// console.log(JSON.stringify(_changes, null, 2));
Expand All @@ -140,6 +142,7 @@ muya.on("json-change", (_changes) => {
// })

const md2Html = new MD2Html(DEFAULT_MARKDOWN);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
md2Html.generate().then((_html) => {
// const container = document.createElement("div");
// container.innerHTML = _html;
Expand Down
Loading

0 comments on commit 21996df

Please sign in to comment.