Skip to content

Commit 87f5639

Browse files
committed
feat: add ui/vanilla-js
1 parent 4e5adf2 commit 87f5639

14 files changed

+1590
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ node_modules
1313
npm-debug.log*
1414
yarn-debug.log*
1515
yarn-error.log*
16+
17+
package-lock.json

docs/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ node_modules
33
.vitepress/cache
44
.vitepress/dist
55
.vercel
6+
7+
package-lock.json

ui/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ The UI components to integrate Documate into the framework of your choice. Packa
66
- `@documate/react` (Comming soon)
77
- `@documate/headless-vue` (Comming soon)
88
- `@documate/headless-react` (Comming soon)
9+
- [`@documate/ui`](./vanilla-js/)

ui/vanilla-js/.eslintrc.cjs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
module.exports = {
2+
"env": {
3+
"browser": true,
4+
"es2021": true,
5+
"node": true
6+
},
7+
"extends": "eslint:recommended",
8+
"overrides": [
9+
{
10+
"env": {
11+
"node": true
12+
},
13+
"files": [
14+
".eslintrc.{js,cjs}"
15+
],
16+
"parserOptions": {
17+
"sourceType": "script"
18+
}
19+
}
20+
],
21+
"parserOptions": {
22+
"ecmaVersion": "latest",
23+
"sourceType": "module"
24+
},
25+
"rules": {
26+
semi: 'error',
27+
complexity: ['warn', 25],
28+
'no-var': 'error',
29+
'no-unused-vars': 'warn',
30+
'no-restricted-globals': 'off',
31+
'max-params': ['warn', 7],
32+
'no-console': 'warn',
33+
'no-new-func': 'off',
34+
'import/no-named-as-default': 'off',
35+
'import/no-named-as-default-member': 'off',
36+
'no-return-await': 'off',
37+
}
38+
};

ui/vanilla-js/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
node_modules/
2+
npm-debug.log*
3+
.nyc_*/
4+
.dir-locals.el
5+
.DS_Store
6+
.test
7+
package-lock.json

ui/vanilla-js/LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 月影
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

ui/vanilla-js/README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Documate-UI
2+
3+
Build [Documate](https://github.com/aircodelabs/documate) UI using native JavaScript.
4+
5+
`@documate/ui` will automatically search for DOM elements with the ID `ask-ai` on the page, so you don't need to perform any manual initialization. The only thing you need to do is provide a button with the ID `ask-ai` on the page.
6+
7+
8+
## Usage
9+
10+
### Import from CDN:
11+
12+
```html
13+
<script src="https://unpkg.com/@documate/ui"></script>
14+
```
15+
16+
### Import from Node:
17+
18+
```bash
19+
npm install @documate/ui
20+
```
21+
22+
```js
23+
import 'documate-ui';
24+
```

ui/vanilla-js/build.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { buildSync } from "esbuild";
2+
3+
const options = {
4+
entryPoints: ['src/index.js'],
5+
outfile: 'dist/documate-ui.js',
6+
bundle: true,
7+
inject: ['./src/inject-css.js'],
8+
loader: {
9+
'.css': 'text',
10+
},
11+
minify: true,
12+
};
13+
14+
buildSync(options);

ui/vanilla-js/dist/documate-ui.js

+161
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/vanilla-js/package.json

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "@documate/ui",
3+
"version": "0.0.1",
4+
"description": "Building Documate UI using native JavaScript",
5+
"main": "dist/documate-ui.js",
6+
"type": "module",
7+
"scripts": {
8+
"build": "mode=production node build.js",
9+
"prepublishOnly": "npm run build",
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"keywords": [],
13+
"author": "",
14+
"license": "MIT",
15+
"devDependencies": {
16+
"esbuild": "^0.19.3",
17+
"eslint": "^8.49.0"
18+
}
19+
}

ui/vanilla-js/src/index.js

+126
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/vanilla-js/src/inject-css.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import style from './styles.css';
2+
3+
const headEl = document.head || document.getElementsByTagName('head')[0];
4+
const styleEl = document.createElement('style');
5+
if(styleEl.styleSheet) {
6+
styleEl.styleSheet.cssText = style;
7+
} else {
8+
styleEl.appendChild(document.createTextNode(style));
9+
}
10+
headEl.appendChild(styleEl);

0 commit comments

Comments
 (0)