Skip to content

Commit

Permalink
feat: base functional
Browse files Browse the repository at this point in the history
  • Loading branch information
zzxming committed Dec 18, 2024
1 parent 9a28a91 commit 802d371
Show file tree
Hide file tree
Showing 25 changed files with 7,015 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/autofix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: autofix.ci

on:
push:
branches:
- master

pull_request:
branches:
- master

merge_group: {}

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install pnpm
uses: pnpm/action-setup@v4

- name: Set node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install
run: pnpm i

- name: Lint
run: pnpm lint --fix

- uses: autofix-ci/[email protected]
37 changes: 37 additions & 0 deletions .github/workflows/deploy-doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: GitHub Pages
on:
push:
branches:
- master
workflow_dispatch: {}

permissions:
contents: write

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install pnpm
uses: pnpm/action-setup@v4

- name: Set node
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install deps
run: pnpm install

- name: Build
run: pnpm build

- name: Deploy to GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: ./docs
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Release

permissions:
contents: write

on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set node
uses: actions/setup-node@v4
with:
registry-url: https://registry.npmjs.org/
node-version: lts/*

- run: npx changelogithub
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
dist
/docs/**/*

!/docs/index.js
!/docs/index.html
.eslintcache
43 changes: 43 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit",
"source.organizeImports": "never"
},
"prettier.enable": false,
"eslint.enable": true,
"eslint.runtime": "node",
"eslint.format.enable": true,
"eslint.useFlatConfig": true,
"eslint.rules.customizations": [
{ "rule": "style/*", "severity": "off" },
{ "rule": "format/*", "severity": "off" },
{ "rule": "*-indent", "severity": "off" },
{ "rule": "*-spacing", "severity": "off" },
{ "rule": "*-spaces", "severity": "off" },
{ "rule": "*-order", "severity": "off" },
{ "rule": "*-dangle", "severity": "off" },
{ "rule": "*-newline", "severity": "off" },
{ "rule": "*quotes", "severity": "off" },
{ "rule": "*semi", "severity": "off" }
],
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html",
"markdown",
"json",
"json5",
"jsonc",
"yaml",
"xml",
"css",
"less",
"scss",
"postcss"
]
}
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# quill-header-list

## options

| name | type | description | default | required |
| --------------- | ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------- | ----------- | -------- |
| container | `string \| HTMLElement` | the list container. string must be the element id | - | `true` |
| scrollContainer | `string \| HTMLElement` | editor scroll container. default is `quill.root` | - | `false` |
| hideClass | `number` | the class name when list hidden | `is-hidden` | `false` |
| topOffset | `number \| () => number` | the offset from the top | `0` | `false` |
| headerHeight | `number` | the header height in editor. this is for calculate header scroll highligh. don't make the height difference between h1 and h6 too much | `36` | `false` |
| onBeforeShow | `() => boolean` | trigger before display. return `true` will cancel display | - | `false` |
| onBeforeHide | `() => boolean` | trigger before hidden. return `true` will cancel hidden | - | `false` |
| onItemClick | `(id: string) => void` | trigger when click list item. id is the header element id | - | `false` |
67 changes: 67 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css"
integrity="sha384-nB0miv6/jRmo5UMMR1wu3Gz6NLsoTkbqJghGIsx//Rlm+ZU03BU6SQNC66uf4l5+"
crossorigin="anonymous"
/>
<script
defer
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.js"
integrity="sha384-7zkQWkzuo3B5mTepMUcHkMB5jZaolc2xDwL6VFqjFALcbeS9Ggm/Yr2r3Dy4lfFg"
crossorigin="anonymous"
></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill.bubble.css" rel="stylesheet" />
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/quill.snow.css" rel="stylesheet" />
<link rel="stylesheet" href="./index.css" />
<script src="./dev.js"></script>
<style>
.main {
position: relative;
display: flex;
flex-direction: column;
max-width: 1200px;
margin: auto;
}
.directory {
position: absolute;
top: 0px;
right: 0px;
z-index: 1;
transform: translateX(100%);
width: 300px;
background-color: #fff;
box-shadow: 0 0 6px rgba(0, 0, 0, 0.5);
}
.directory#directory2 {
position: fixed;
transform: none;
}
</style>
</head>
<body>
<div class="main">
<div>
<button id="btn1">console</button>
<div id="editor1" style="height: 600px"></div>
<div id="output1"></div>
</div>
<div id="directory1" class="directory"></div>

<div>
<div id="directory2" class="directory"></div>
<button id="btn2">console</button>
<div id="editor2"></div>
<div id="output2"></div>
</div>
</div>

<script src="./index.js"></script>
</body>
</html>
116 changes: 116 additions & 0 deletions docs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
const Quill = window.Quill;
const { default: HeaderList } = window.bundle;

Quill.register({
[`modules/${HeaderList.moduleName}`]: HeaderList,
}, true);

const toolbarConfig = [
[HeaderList.toolName, 'clean'],
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'code-block', 'code'],
['link', 'image', 'video', 'formula'],
[{ list: 'ordered' }, { list: 'bullet' }, { list: 'check' }],
[{ script: 'sub' }, { script: 'super' }],
[{ indent: '-1' }, { indent: '+1' }],
[{ direction: 'rtl' }],
[{ size: ['small', false, 'large', 'huge'] }],
[{ header: [1, 2, 3, 4, 5, 6, false] }],
[{ color: [] }, { background: [] }],
[{ font: [] }],
[{ align: [] }],
];

const quill1 = new Quill('#editor1', {
// debug: 'info',
theme: 'snow',
modules: {
toolbar: {
container: toolbarConfig,
handlers: {
[HeaderList.toolName]: HeaderList.toolbarHandle,
},
},
[HeaderList.moduleName]: {
topOffset: 0,
// scrollContainer,
container: document.getElementById('directory1'),
},
},
});

const quill2 = new Quill('#editor2', {
// debug: 'info',
theme: 'snow',
modules: {
toolbar: {
container: toolbarConfig,
handlers: {
[HeaderList.toolName]: HeaderList.toolbarHandle,
},
},
[HeaderList.moduleName]: {
topOffset: 0,
scrollContainer: window,
container: document.getElementById('directory2'),
},
},
});

const quill = [
quill1,
quill2,
];
window.quill = quill;

const output = [document.getElementById('output1'), document.getElementById('output2')];

for (const [i, btn] of [document.getElementById('btn1'), document.getElementById('btn2')].entries()) {
btn.addEventListener('click', () => {
const content = quill[i].getContents();
console.log(content);
output[i].innerHTML = '';
// eslint-disable-next-line unicorn/no-array-for-each
content.forEach((content) => {
const item = document.createElement('li');
item.textContent = `${JSON.stringify(content)},`;
output[i].appendChild(item);
});
});
}

for (const q of quill) {
q.setContents([
{ insert: 'header1' },
{ attributes: { header: 1 }, insert: '\n' },
{ insert: '\n\n\n\n\n\n\n\n\nheader1.1' },
{ attributes: { header: 2 }, insert: '\n' },
{ insert: '\n\n\n\n\n\n\n\n\n\n\n\n\n\nheader1.2' },
{ attributes: { header: 2 }, insert: '\n' },
{ insert: '\n\n\n\n\n\n\n\n\n\n\n\n\nheader1.2.1' },
{ attributes: { header: 3 }, insert: '\n' },
{ insert: '\n\n\n\n\n\nheader1.2.2' },
{ attributes: { header: 3 }, insert: '\n' },
{ insert: '\n\n\n\n\n\n\n\n\n\nheader2' },
{ attributes: { header: 2 }, insert: '\n' },
{ insert: '\n\n\nheader2.1' },
{ attributes: { header: 2 }, insert: '\n' },
{ insert: '\n\nheader2.1.1' },
{ attributes: { header: 3 }, insert: '\n' },
{ insert: '\n\n\n\n\n\n\n\n\n\n\n\n\n\nheader2.1.2' },
{ attributes: { header: 3 }, insert: '\n' },
{ insert: '\n\nheader2.1.2.1' },
{ attributes: { header: 4 }, insert: '\n' },
{ insert: '\n\n\n\n\n\n\n\n\n\n\nheader2.1.2.1.1' },
{ attributes: { header: 5 }, insert: '\n' },
{ insert: '\n\nheader2.1.2.1.1.1' },
{ attributes: { header: 6 }, insert: '\n' },
{ insert: '\n\n\n\n\n\n\n\nheader3' },
{ attributes: { header: 2 }, insert: '\n' },
{ insert: '\n\n\n\nheader3.1' },
{ attributes: { header: 3 }, insert: '\n' },
{ insert: '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nheader4' },
{ attributes: { header: 2 }, insert: '\n' },
{ insert: '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n' },
]);
}
11 changes: 11 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { factory } from '@zzxming/eslint-config';

export default factory({
overrides: [
{
rules: {
'ts/ban-ts-comment': 'off',
},
},
],
});
Loading

0 comments on commit 802d371

Please sign in to comment.