ranui 0.1.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/.vitepress/config.ts +26 -0
  2. package/.vitepress/theme/index.ts +9 -0
  3. package/assets/image/failImage.ts +4 -0
  4. package/assets/svgs/check-circle.svg +4 -0
  5. package/assets/svgs/close-circle.svg +4 -0
  6. package/assets/svgs/eye-close.svg +4 -0
  7. package/assets/svgs/eye.svg +4 -0
  8. package/assets/svgs/info-circle.svg +5 -0
  9. package/assets/svgs/lock.svg +4 -0
  10. package/assets/svgs/unlock.svg +4 -0
  11. package/assets/svgs/user.svg +3 -0
  12. package/components/button/index.less +95 -0
  13. package/components/button/index.ts +64 -0
  14. package/components/form/index.less +0 -0
  15. package/components/form/index.ts +36 -0
  16. package/components/image/index.less +0 -0
  17. package/components/image/index.ts +62 -0
  18. package/components/input/index.less +114 -0
  19. package/components/input/index.ts +367 -0
  20. package/components/modal/index.less +0 -0
  21. package/components/modal/index.ts +118 -0
  22. package/components/tabPane/index.less +0 -0
  23. package/components/tabPane/index.ts +71 -0
  24. package/components/tabs/index.less +47 -0
  25. package/components/tabs/index.ts +207 -0
  26. package/dist/assets/image/failImage.d.ts +2 -0
  27. package/dist/components/button/index.d.ts +2 -0
  28. package/dist/components/image/index.d.ts +2 -0
  29. package/dist/components/input/index.d.ts +2 -0
  30. package/dist/components/modal/index.d.ts +2 -0
  31. package/dist/components/tabPane/index.d.ts +2 -0
  32. package/dist/components/tabs/index.d.ts +2 -0
  33. package/dist/index.d.ts +0 -0
  34. package/dist/index.js +677 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/index.umd.cjs +2 -0
  37. package/dist/index.umd.cjs.map +1 -0
  38. package/dist/style.css +1 -0
  39. package/dist/typings.d.ts +4 -0
  40. package/dist/utils/index.d.ts +7 -0
  41. package/docs/button/index.md +25 -0
  42. package/docs/image/index.md +9 -0
  43. package/docs/input/index.md +146 -0
  44. package/docs/tabs/index.md +121 -0
  45. package/index.html +67 -0
  46. package/index.md +1 -0
  47. package/index.ts +6 -0
  48. package/package.json +33 -0
  49. package/plugins/auto-import-file.ts +59 -0
  50. package/plugins/load-style.ts +31 -0
  51. package/tsconfig.json +31 -0
  52. package/typings.d.ts +4 -0
  53. package/utils/index.ts +12 -0
  54. package/vite.config.ts +58 -0
package/index.html ADDED
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta http-equiv="X-UA-Compatible" content="IE=edge" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>Document</title>
8
+ <script src="./index.ts" type="module"></script>
9
+ </head>
10
+
11
+ <body>
12
+ <!-- <h1>Hello RanUI</h1> -->
13
+ <div style="margin: 20px">
14
+ <!-- <div>按钮</div>
15
+ <r-button type="primary">主要按钮</r-button>
16
+ <r-button type="warning">警告按钮</r-button>
17
+ <r-button type="default">默认按钮</r-button>
18
+ <r-button type="primary" disabled="true">disable按钮</r-button>
19
+ <div style="margin:20px">输入框</div>
20
+ <r-input label="user" type="password"></r-input>
21
+ <div>图片</div> -->
22
+ <!-- <r-button type="text" disabled>默认按钮</r-button> -->
23
+ <span>加载失败</span>
24
+ <r-img fallback=""></r-img>
25
+ <div>表单</div>
26
+ <r-tabs>
27
+ <r-tab label="tab1" >11111</r-tab>
28
+ <r-tab label="tab2" type="line">22222</r-tab>
29
+ <r-tab label="tab3" >33333</r-tab>
30
+ </r-tabs>
31
+ <!-- <iframe name="hidden" style="display:none;"></iframe> -->
32
+ <form id="form">
33
+ <fieldset>
34
+ <legend>Choose your favorite monster</legend>
35
+
36
+ <input type="radio" id="kraken" name="monster" value="K">
37
+ <label for="kraken">Kraken</label><br>
38
+
39
+ <input type="radio" id="sasquatch" name="monster" value="S">
40
+ <label for="sasquatch">Sasquatch</label><br>
41
+
42
+ <input type="radio" id="mothman" name="monster" value="M" />
43
+ <label for="mothman">Mothman</label>
44
+ <button type="submit">提交按钮</button>
45
+ </fieldset>
46
+ </form>
47
+ </div>
48
+ <script>
49
+ const form = document.getElementById("form");
50
+ const onFinish = (e) => {
51
+ e.preventDefault();
52
+ const jsonData = {};
53
+ const formData = new FormData(form);
54
+ formData.forEach((value, key) => {
55
+ if (!jsonData[key]) {
56
+ jsonData[key] =
57
+ formData.getAll(key).length > 1
58
+ ? formData.getAll(key)
59
+ : formData.get(key);
60
+ }
61
+ });
62
+ console.log("e---->", jsonData);
63
+ };
64
+ form.addEventListener("submit", onFinish);
65
+ </script>
66
+ </body>
67
+ </html>
package/index.md ADDED
@@ -0,0 +1 @@
1
+ # RanUI
package/index.ts ADDED
@@ -0,0 +1,6 @@
1
+ import './components/button/index.ts';
2
+ import './components/image/index.ts';
3
+ import './components/input/index.ts';
4
+ import './components/modal/index.ts';
5
+ import './components/tabPane/index.ts';
6
+ import './components/tabs/index.ts';
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "ranui",
3
+ "version": "0.1.0-alpha",
4
+ "description": "基于web components的组件库",
5
+ "main": "dist/index.umd.cjs",
6
+ "module": "dist/index.js",
7
+ "type": "module",
8
+ "types": "./dist/index.d.ts",
9
+ "engines": {
10
+ "node": "^14.18.0 || >=16.0.0"
11
+ },
12
+ "homepage": "https://github.com/chaxus/ran/tree/main/packages/ranui/docs",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/chaxus/ran",
16
+ "directory": "packages/ranui"
17
+ },
18
+ "scripts": {
19
+ "dev": "vitepress dev",
20
+ "start": "vite",
21
+ "build": "vite build",
22
+ "build:docs": "vitepress build",
23
+ "serve:docs": "vitepress serve"
24
+ },
25
+ "keywords": [],
26
+ "author": "",
27
+ "license": "ISC",
28
+ "devDependencies": {
29
+ "less": "^4.1.3",
30
+ "ranuts": "workspace:^0.1.0",
31
+ "vitepress": "0.22.4"
32
+ }
33
+ }
@@ -0,0 +1,59 @@
1
+ import { Plugin } from 'vite';
2
+ import fs from "fs";
3
+ import ranuts from 'ranuts';
4
+ const { writeFile, readFile, queryFileInfo } = ranuts;
5
+
6
+ interface Options {
7
+ ignore?: Array<string>,
8
+ path: Array<string>,
9
+ extensions: Array<string>
10
+ }
11
+
12
+ const createIndex = async (options: Options, entry: string) => {
13
+ let content = ''
14
+ const { path = [], extensions = [], ignore = [] } = options
15
+ /**
16
+ * @description: 递归查找目录
17
+ * @param {Array} path
18
+ */
19
+ const recurveFile = async (path: Array<string>) => {
20
+ for (const item of path) {
21
+ const { status, data } = await queryFileInfo(item)
22
+ const extension = item.substring(item.lastIndexOf('.'))
23
+ if (status && data.isFile() && extensions.includes(extension) && !ignore.includes(item)) {
24
+ content += `import '${item}';\n`
25
+ }
26
+ if (status && data.isDirectory() && !ignore.includes(item)) {
27
+ const fileList = fs.readdirSync(item)
28
+ const list = fileList.map(children => `${item}/${children}`)
29
+ await recurveFile(list)
30
+ }
31
+ }
32
+ }
33
+ try {
34
+ await recurveFile(path)
35
+ const currContent = await readFile(entry)
36
+ if (currContent.status && currContent.data !== content) return await writeFile(entry, content)
37
+ return { status: false }
38
+ } catch (error) {
39
+ throw error
40
+ }
41
+
42
+ }
43
+ // 当初始目录中没有index的时候,不会主动生成,需要至少增加一个空index.js
44
+ export default function autoImportFilePlugin(options: Options): Plugin {
45
+ return {
46
+ name: 'vite-plugin-auto-import-file',
47
+ enforce: 'pre',
48
+ async config(context) {
49
+ const { entry = '' } = context.build?.lib || {};
50
+ // const { alias = {} } = context.resolve || {}
51
+ // const aliasList = Object.keys(alias)
52
+ if (entry) await createIndex(options, entry)
53
+ },
54
+ async handleHotUpdate(context) {
55
+ const { entry = '' } = context.server.config.build.lib || {}
56
+ if (entry) await createIndex(options, entry)
57
+ }
58
+ }
59
+ }
@@ -0,0 +1,31 @@
1
+ import { Plugin } from 'vite';
2
+ interface Options {
3
+ ignore?: Array<string>
4
+ }
5
+
6
+ export default function loadStylePlugin(options?: Options): Plugin {
7
+ return {
8
+ name: 'vite-plugin-load-style',
9
+ transform(code, id) {
10
+ const path = new RegExp('ranui\/components\/[a-zA-z0-9]+\/index\.ts')
11
+ const stylePath = new RegExp(/((this\.)?[a-zA-Z0-9]+)\s*=\s*this\.attachShadow\(\{.*\}\)/)
12
+ const front = `import f7170ee498e0dd32cbdcb63fba8f75cc from './index.less';`
13
+ const { ignore = [] } = options ?? {}
14
+ const [fragment, statement] = code.match(stylePath) ?? []
15
+ let result = code
16
+ if (path.test(id) && !ignore.some(item => new RegExp(item).test(id)) && fragment && statement) {
17
+ result = result.replace(
18
+ stylePath,
19
+ `${fragment};
20
+ const F7170EE498E0DD32CBDCB63FBA8F75CC = document.createElement('style');
21
+ F7170EE498E0DD32CBDCB63FBA8F75CC.textContent = f7170ee498e0dd32cbdcb63fba8f75cc;
22
+ ${statement}.appendChild(F7170EE498E0DD32CBDCB63FBA8F75CC);`)
23
+ result = front + result;
24
+ }
25
+ return {
26
+ code: result,
27
+ map: null // TODO
28
+ };
29
+ }
30
+ }
31
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "compilerOptions": {
3
+ "jsx": "react",
4
+ "module": "ESNext",
5
+ "esModuleInterop": true,
6
+ "target": "ESNext",
7
+ "moduleResolution": "node",
8
+ "outDir": "dist",
9
+ "forceConsistentCasingInFileNames": true,
10
+ "noFallthroughCasesInSwitch": true,
11
+ "isolatedModules": false,
12
+ "strict": true,
13
+ "noImplicitAny": true,
14
+ "useUnknownInCatchVariables": false,
15
+ "inlineSourceMap": true,
16
+ "baseUrl": ".",
17
+ "experimentalDecorators":true,
18
+ "paths": {
19
+ "@/assets/*": ["assets/*"],
20
+ "@/components/*": ["components/*"],
21
+ "@/plugins/*": ["plugins/*"],
22
+ "@/utils/*": ["utils/*"],
23
+ },
24
+ },
25
+ "ts-node": {
26
+ "esm": true,
27
+ "experimentalSpecifierResolution":"node",
28
+ },
29
+ "include": ["**/*.ts", "**/*.tsx"],
30
+ "exclude": ["node_modules"]
31
+ }
package/typings.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare module "*.less"
2
+ declare module '@/assets'
3
+ declare module '@/components'
4
+ declare module '@/plugins'
package/utils/index.ts ADDED
@@ -0,0 +1,12 @@
1
+ export const falseList = [false, "false", null, undefined];
2
+ /**
3
+ * @description: 判断这个元素上是否有disabled属性
4
+ * @param {Element} element
5
+ * @return {*}
6
+ */
7
+ export const isDisabled = (element: Element) => {
8
+ const status = element.hasAttribute('disabled')
9
+ const value = element.getAttribute('disabled')
10
+ if (status && !falseList.includes(value)) return true
11
+ return false
12
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { defineConfig } from "vite";
2
+ import path, { resolve } from "path";
3
+ import { fileURLToPath } from "url";
4
+ import dts from 'vite-plugin-dts'
5
+ import loadStyle from './plugins/load-style'
6
+ import autoImportFile from './plugins/auto-import-file'
7
+
8
+ // const __filename = fileURLToPath(import.meta.url);
9
+
10
+ // const __dirname = path.dirname(__filename);
11
+
12
+ export default defineConfig({
13
+ build: {
14
+ minify: 'terser',
15
+ sourcemap: true,
16
+ lib: {
17
+ entry: resolve(__dirname, "index.ts"),
18
+ name: "ranui",
19
+ fileName: "index",
20
+ formats: ["es", "umd"],
21
+ },
22
+ },
23
+ plugins: [
24
+ dts({
25
+ tsConfigFilePath: './tsconfig.json'
26
+ }),
27
+ loadStyle({
28
+ ignore: ['ranui/components/modal/index.ts']
29
+ }),
30
+ autoImportFile({
31
+ path: [
32
+ './components',
33
+ // resolve(__dirname, "components/")
34
+ ],
35
+ extensions: [".ts"],
36
+ ignore: ['./components/form/index.ts']
37
+ })
38
+ ],
39
+ resolve: {
40
+ alias: {
41
+ '@/components': resolve(__dirname, "components/"),
42
+ '@/assets': resolve(__dirname, "assets/"),
43
+ '@/utils': resolve(__dirname, "utils/"),
44
+ },
45
+ extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json"],
46
+ },
47
+ css: {
48
+ // preprocessorOptions: {
49
+ // less: {
50
+ // javascriptEnabled: true,
51
+ // additionalData: `@import "client/assets/base.css";`
52
+ // }
53
+ // },
54
+ modules: {
55
+ generateScopedName: "[name--[local]--[hash:base64:5]]",
56
+ },
57
+ },
58
+ });