@moneko/core 3.0.0-beta.13 → 3.0.0-beta.14

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.
@@ -1 +1 @@
1
- import e from"mini-css-extract-plugin";import s from"mini-svg-data-uri";import{CONFIG as o,PUBLICPATH as t}from"./common.js";import{hasPkg as r}from"./has-pkg.js";import l from"./modifyVars.js";import{APPTYPE as a,DEV as i,pkgName as c}from"./process-env.js";import n from"./swcrc.js";import p from"./tsloader.config.js";import{resolveNodeModulesPath as m,resolveProgramPath as d}from"./utils.js";let u="single-spa"===a?t:"../",f={loader:e.loader,options:{publicPath:"/"!==u?u:"../"}},y=r("@moneko/postcss")&&{loader:"postcss-loader",options:{postcssOptions:await import("@moneko/postcss")}};i&&(f="style-loader");let x=[...o.cssModules,c,"neko-ui"].map(m),g=[m(`${c}/lib/styles/eval/*.less`),...["src/styles/variables/*.less","src/styles/mixins/*.less","site/styles/variables/*.less","site/styles/mixins/*.less"].map(d)],j=["components","example","mock","site","src"].map(d),$=[f,{loader:"css-loader",options:{modules:{auto:e=>{for(let s=0,o=x.length;s<o;s++)if(e&&e?.includes(x[s]))return/(.*(?<!\.global\.(le|c)ss)$)/i.test(e);return/(^(?!.*node_modules))(.*(?<!\.global\.(le|c)ss)$)/i.test(e)},localIdentName:"[path][name]__[local]",exportLocalsConvention:"dashesOnly"},importLoaders:2}},y,"css-unicode-loader",{loader:"less-loader",options:{sourceMap:!!o.sourceMap,lessOptions:{modifyVars:l,javascriptEnabled:!0}}},{loader:"style-resources-loader",options:{patterns:g}}].filter(Boolean),b={loader:"tsc"===o.compiler?"ts-loader":"swc-loader",options:"tsc"===o.compiler?p:n(i)},h={rules:[{oneOf:[{resourceQuery:/raw/,type:"asset/source"},{resourceQuery:/\.wasm$/,type:"webassembly/async"},{test:/\.less$/,use:$,include:j.concat(o.rulesInclude?.less?.map(m)||[])},{test:/\.css$/,use:[f,"css-loader",y,"css-unicode-loader"].filter(Boolean),include:j.concat(o.rulesInclude?.css?.map(m)||[])},{test:/\.(gif|png|jpe?g|ico|mp4)$/i,type:"asset",generator:{filename:"assets/images/[name][ext][query]"},include:j.concat(o.rulesInclude?.media?.map(m)||[])},{test:/\.(eot|ttf|otf|woff(|2))$/,type:"asset",generator:{filename:"assets/fonts/[name][ext][query]"},include:j.concat(o.rulesInclude?.fonts?.map(m)||[])},{test:/\.svg$/,type:"asset/inline",generator:{dataUrl:e=>s("string"!=typeof e?e.toString():e)}},{test:/\.txt$/,type:"asset/source"},{test:/\.(cj|mj|t|j)s(|x)$/,use:[...o.prefixJsLoader,b].filter(Boolean),include:j.concat(o.rulesInclude?.js?.map(m)||[])},{test:/\.mdx?$/,use:[...o.prefixJsLoader,b,{loader:"@mdx-js/loader",options:{jsxImportSource:"solid-js/h",rehypePlugins:[[await import("@mapbox/rehype-prism"),{ignore:!0}],(await import("rehype-accessible-emojis")).rehypeAccessibleEmojis,await import("rehype-figure")],remarkPlugins:[]}}].filter(Boolean),include:j,exclude:[/(.+)\/examples\/(.+).mdx?$/i]},{test:/\.mdx?$/,type:"asset/source",include:[/(.+)\/examples\/(.+).mdx?$/i]},{type:"asset/source",include:[/(.+)\/examples\/(.+).*?$/i]}]},...o.moduleRules]};export default h;
1
+ import e from"mini-css-extract-plugin";import s from"mini-svg-data-uri";import o from"remark-frontmatter";import t from"remark-gfm";import r from"remark-mdx-frontmatter";import{CONFIG as a,PUBLICPATH as l}from"./common.js";import{hasPkg as i}from"./has-pkg.js";import m from"./modifyVars.js";import{APPTYPE as n,DEV as c,pkgName as p}from"./process-env.js";import d from"./swcrc.js";import u from"./tsloader.config.js";import{resolveNodeModulesPath as f,resolveProgramPath as y}from"./utils.js";let x="single-spa"===n?l:"../",g={loader:e.loader,options:{publicPath:"/"!==x?x:"../"}},j=i("@moneko/postcss")&&{loader:"postcss-loader",options:{postcssOptions:await import("@moneko/postcss")}};c&&(g="style-loader");let $=[...a.cssModules,p,"neko-ui"].map(f),b=[f(`${p}/lib/styles/eval/*.less`),...["src/styles/variables/*.less","src/styles/mixins/*.less","site/styles/variables/*.less","site/styles/mixins/*.less"].map(y)],h=["components","example","mock","site","src"].map(y),w=[g,{loader:"css-loader",options:{modules:{auto:e=>{for(let s=0,o=$.length;s<o;s++)if(e&&e?.includes($[s]))return/(.*(?<!\.global\.(le|c)ss)$)/i.test(e);return/(^(?!.*node_modules))(.*(?<!\.global\.(le|c)ss)$)/i.test(e)},localIdentName:"[path][name]__[local]",exportLocalsConvention:"dashesOnly"},importLoaders:2}},j,"css-unicode-loader",{loader:"less-loader",options:{sourceMap:!!a.sourceMap,lessOptions:{modifyVars:m,javascriptEnabled:!0}}},{loader:"style-resources-loader",options:{patterns:b}}].filter(Boolean),k={loader:"tsc"===a.compiler?"ts-loader":"swc-loader",options:"tsc"===a.compiler?u:d(c)},v={rules:[{oneOf:[{resourceQuery:/raw/,type:"asset/source"},{resourceQuery:/\.wasm$/,type:"webassembly/async"},{test:/\.less$/,use:w,include:h.concat(a.rulesInclude?.less?.map(f)||[])},{test:/\.css$/,use:[g,"css-loader",j,"css-unicode-loader"].filter(Boolean),include:h.concat(a.rulesInclude?.css?.map(f)||[])},{test:/\.(gif|png|jpe?g|ico|mp4)$/i,type:"asset",generator:{filename:"assets/images/[name][ext][query]"},include:h.concat(a.rulesInclude?.media?.map(f)||[])},{test:/\.(eot|ttf|otf|woff(|2))$/,type:"asset",generator:{filename:"assets/fonts/[name][ext][query]"},include:h.concat(a.rulesInclude?.fonts?.map(f)||[])},{test:/\.svg$/,type:"asset/inline",generator:{dataUrl:e=>s("string"!=typeof e?e.toString():e)}},{test:/\.txt$/,type:"asset/source"},{test:/\.(cj|mj|t|j)s(|x)$/,use:[...a.prefixJsLoader,k].filter(Boolean),include:h.concat(a.rulesInclude?.js?.map(f)||[])},{test:/\.mdx?$/,use:[...a.prefixJsLoader,k,{loader:"@mdx-js/loader",options:{jsxImportSource:"solid-js/h",rehypePlugins:[[(await import("@mapbox/rehype-prism")).default,{ignore:!0}],(await import("rehype-accessible-emojis")).rehypeAccessibleEmojis,(await import("rehype-figure")).default],remarkPlugins:[o,[r,{name:"matter"}],t]}}].filter(Boolean),include:h,exclude:[/(.+)\/examples\/(.+).mdx?$/i]},{test:/\.mdx?$/,type:"asset/source",include:[/(.+)\/examples\/(.+).mdx?$/i]},{type:"asset/source",include:[/(.+)\/examples\/(.+).*?$/i]}]},...a.moduleRules]};export default v;
package/lib/index.js CHANGED
@@ -1 +1,8 @@
1
- export{pathToRegexp}from"path-to-regexp";export var projectBasicInfo={projectName:projectName,providerConfig:providerConfig,programInfo:programInfo,coverage:projectCoverage};
1
+ export { pathToRegexp } from 'path-to-regexp';
2
+ /** 一些项目基本信息 */
3
+ export const projectBasicInfo = {
4
+ projectName,
5
+ providerConfig,
6
+ programInfo,
7
+ coverage: projectCoverage,
8
+ };
@@ -0,0 +1,28 @@
1
+ import { Router } from '@solidjs/router';
2
+ import { render } from 'solid-js/web';
3
+ import App from '@/index';
4
+ function isFunction(target) {
5
+ return [
6
+ '[object Function]',
7
+ '[object AsyncFunction]',
8
+ '[object GeneratorFunction]',
9
+ '[object Proxy]',
10
+ ].includes(Object.prototype.toString.call(target));
11
+ }
12
+ const appEntry = APPENTRY ? await import(APPENTRY) : null;
13
+ const container = document.getElementById('root');
14
+ if (appEntry && isFunction(appEntry.bootstrap)) {
15
+ appEntry.bootstrap();
16
+ }
17
+ window.rootInstance = {
18
+ unmount: () => null,
19
+ render() {
20
+ window.rootInstance.unmount = render(() => (<Router>
21
+ <App />
22
+ </Router>), container);
23
+ },
24
+ };
25
+ window.rootInstance.render();
26
+ if (appEntry && isFunction(appEntry.mount)) {
27
+ appEntry.mount();
28
+ }
@@ -1,4 +1,4 @@
1
1
  import '../../refresh-rem.js';
2
2
  import '../../normalize.css';
3
- declare const bootstrap: typeof import("./bootstrap.tsx");
3
+ declare const bootstrap: typeof import("./bootstrap.jsx");
4
4
  export default bootstrap;
@@ -1 +1,4 @@
1
- import"../../refresh-rem.js";import"../../normalize.css";var r=await import("./bootstrap.tsx");export default r;
1
+ import '../../refresh-rem.js';
2
+ import '../../normalize.css';
3
+ const bootstrap = await import('./bootstrap.jsx');
4
+ export default bootstrap;
@@ -1 +1,49 @@
1
- !function(o,n){var t=function(){var n=o.documentElement,t=n.clientWidth||o.body.clientWidth,e=t<=375?375:programInfo.designSize,i=t;i=t<=375?t:t<=programInfo.designSize?e:t;var l=16/e*i+"px";l!==n.style.fontSize&&(n.style.fontSize=l)};t(),"addEventListener"in o&&n.addEventListener("orientationchange"in n?"orientationchange":"resize",t,!1),window.scrollTo||(window.scrollTo=function(o){window.scrollLeft=o.left,window.scrollTop=o.top}),document.body.scrollTo||(Element.prototype.scrollTo=function(o){this.scrollLeft=o.left,this.scrollTop=o.top})}(document,window);
1
+ "use strict";
2
+ (function (doc, win) {
3
+ function refreshRem() {
4
+ const docEl = doc.documentElement;
5
+ const clientWidth = docEl.clientWidth || doc.body.clientWidth;
6
+ const _designSize = clientWidth <= 375 ? 375 : programInfo.designSize;
7
+ let unitSize = clientWidth;
8
+ if (clientWidth <= 375) {
9
+ unitSize = clientWidth;
10
+ }
11
+ else if (clientWidth <= programInfo.designSize) {
12
+ unitSize = _designSize;
13
+ }
14
+ else {
15
+ unitSize = clientWidth;
16
+ }
17
+ // 窗口大于设计尺寸的时候,使用窗口大小
18
+ // const unitSize = clientWidth > designSize ? designSize : clientWidth;
19
+ // const rootSize = (16 / designSize) * unitSize + 'px';
20
+ // 保持设计比例
21
+ const rootSize = (16 / _designSize) * unitSize + 'px';
22
+ if (rootSize !== docEl.style.fontSize) {
23
+ docEl.style.fontSize = rootSize;
24
+ }
25
+ }
26
+ refreshRem();
27
+ if ('addEventListener' in doc) {
28
+ const resizeEvt = 'orientationchange' in win ? 'orientationchange' : 'resize';
29
+ win.addEventListener(resizeEvt, refreshRem, false);
30
+ }
31
+ /**
32
+ * 判断 window 及元素节点对象下是否存在 scrollTo 属性,
33
+ * 不存在则自定义,这样就可以解决 IE 下不兼容 scrollTo 的问题
34
+ */
35
+ if (!window.scrollTo) {
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ window.scrollTo = function (option) {
38
+ window.scrollLeft = option.left;
39
+ window.scrollTop = option.top;
40
+ };
41
+ }
42
+ if (!document.body.scrollTo) {
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ Element.prototype.scrollTo = function (option) {
45
+ this.scrollLeft = option.left;
46
+ this.scrollTop = option.top;
47
+ };
48
+ }
49
+ })(document, window);
@@ -1 +1,277 @@
1
- function e(e,r){(null==r||r>e.length)&&(r=e.length);for(var n=0,t=Array(r);n<r;n++)t[n]=e[n];return t}function r(){return(r=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e}).apply(this,arguments)}import{pathToRegexp as n}from"path-to-regexp";export function lazyImport(e){return new Promise(function(r){return import("@/pages/"+e.replace(/:/g,"$").replace(/^\//,"")).then(r).catch(function(){return Promise.resolve({default:null})})})}export var myPkgs=[];export var myDemoKv={};export var mdxComponents={};if("library"===APPTYPE){var t,o,i=require.context("@pkg/",!0,/README\.mdx?$/),a={};try{a=await import("@/components/components")}catch(e){}Object.assign(mdxComponents,r({},a)),null==(t=i.keys())||t.forEach(function(e){var n=e.substring(2).split("/").slice(0,-1).join("/"),t=i(e),o=t.basic,a=t.default;myPkgs.push(r({key:n,path:n,element:a},o,{props:{components:mdxComponents,path:n}}))});var l=require.context("@pkg/",!0,/\/examples\/(.+)\.mdx$/);null==(o=l.keys())||o.forEach(function(r){var n=r.substring(2).split("/"),t=n[0];Array.isArray(myDemoKv[t])||(myDemoKv[t]=[]);for(var o,i,a=l(r),u=a.matchAll(/```([^\r\n]+)?\r?\n([\s\S]*?)\r?\n```/g),c="",p="",s=null,h=function(r,n){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return(t=t.call(r)).next.bind(t);if(Array.isArray(r)||(t=function(r,n){if(r){if("string"==typeof r)return e(r,n);var t=Object.prototype.toString.call(r).slice(8,-1);if("Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t)return Array.from(t);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return e(r,n)}}(r))){t&&(r=t);var o=0;return function(){return o>=r.length?{done:!0}:{done:!1,value:r[o++]}}}throw TypeError("Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(u);!(i=h()).done;){var d=i.value;p=d[1]||"tsx",c=d[2],s=a.replace(d[0],"")}myDemoKv[t].push({language:p,code:c,description:s,title:null==(o=n.pop())?void 0:o.replace(/\.mdx$/,""),noInline:/render\([^\\)]*\);?(?=\s*$)/.test(c)})})}var u=[];try{u=require("@/router").default}catch(e){console.info("自定义路由请在 router 目录下新建 index.ts, 类型: RouterProps[]",e)}function c(e,r){return["*"===r&&"*"!==e?void 0:r,e].filter(Boolean).join("/")}var p=function(e){for(var r=[],n=0;n<e.length;n++)for(var t=e[n].split("/").slice(0,-1),o=r,i=0;i<t.length;i++){var a=t[i];if(""!==a){"."===a&&(a="*");var l=o;if(Array.isArray(o)){for(var u=0;u<o.length;u++)if(o[u].path===a){o=o[u].children;break}}if(l===o){var c=i===t.length-1?e[n]:t.slice(0,i+1).join("/")+"/",p={key:c=c.substring(2,c.lastIndexOf("/")),path:a,i18n:"route-"+c,children:[],alive:!1,element:lazyImport(c),hideMenu:c.includes(":"),props:{path:c}};Array.isArray(o)&&o.push(p),o=p.children}}}return r}(require.context("@/pages/",!0,/\.(t|j)sx$/,"lazy").keys().map(function(e){return e.replace(/\$/g,":")}));function s(e,n,t){return void 0===e&&(e=[]),e.map(function(e){var o=r({},e);return void 0===o.key&&(o.key=c(e.path,t)),void 0===o.i18n&&(o.i18n="route-"+o.key),void 0===o.alive&&(o.alive=!1),"*"===o.path&&void 0===o.hideMenu&&(o.hideMenu=!0),Array.isArray(o.children)&&(o.children=o.children.length?s(o.children,n,o.key):void 0),o.element||(o.element=lazyImport(o.key),o.props={path:o.key}),!!o.onlyLogin!==n||o.root?o:null}).filter(Boolean)}for(var h=[].concat(u),d=0,y=p.length;d<y;d++)!function e(n,t,o){var i,a=n.find(function(e){return e.path===t.path});a?(a.key=c(a.path,o),void 0===a.i18n&&(a.i18n="route-"+a.key),void 0===a.alive&&(a.alive=!1),void 0===a.element&&t.element&&(a.element=t.element,a.props=t.props),void 0===a.hideMenu&&(a.hideMenu="*"===a.path||a.key.includes(":")),Object.assign(a,r({},t,a)),t.children&&(!a.children&&Array.isArray(t.children)&&(a.children=t.children),null==(i=t.children)||i.forEach(function(r){e(null==a?void 0:a.children,r,null==a?void 0:a.key)}))):n.push(t)}(h,p[d]);export var onlyLoginRouter=s(h,!1);export var router=s(h,!0);export function matchUtil(e){var r={key:""};return!function t(o){for(var i=0,a=o.length;i<a;i++){if(o[i].path&&"*"!==o[i].path&&o[i].key)try{if(n(o[i].key).exec(e.substring(1))){r=o[i];return}}catch(e){}Array.isArray(o[i].children)&&t(o[i].children)}}(router),r}
1
+ import { pathToRegexp } from 'path-to-regexp';
2
+ export function lazyImport(filePath) {
3
+ return new Promise(function (resolve) {
4
+ return import(
5
+ /* webpackChunkName: "[request]" */
6
+ '@/pages/' + filePath.replace(/:/g, '$').replace(/^\//, ''))
7
+ .then(resolve)
8
+ .catch(function () {
9
+ return Promise.resolve({
10
+ default: null,
11
+ });
12
+ });
13
+ });
14
+ }
15
+ export const myPkgs = [];
16
+ export const myDemoKv = {};
17
+ export const mdxComponents = {};
18
+ // function heading(p: Any, level: number) {
19
+ // return createElement(`h${level}`, {
20
+ // 'data-prefix': '# ',
21
+ // role: 'heading',
22
+ // 'aria-level': level,
23
+ // ...p,
24
+ // });
25
+ // }
26
+ // function pre(p: Any) {
27
+ // const c = createElement('code', p);
28
+ // if (p.className) {
29
+ // return createElement(
30
+ // mdxComponents.CodeBlock || 'pre',
31
+ // { lang: p.className.replace('language-', '').replace(/ .*$/, '') },
32
+ // c
33
+ // );
34
+ // }
35
+ // return c;
36
+ // }
37
+ if (APPTYPE === 'library') {
38
+ const models = import.meta.webpackContext?.('@pkg/', {
39
+ recursive: true,
40
+ regExp: /README\.mdx?$/,
41
+ mode: 'sync',
42
+ });
43
+ let overrideComps = {};
44
+ try {
45
+ overrideComps = (await import('@/components/components')).default;
46
+ }
47
+ catch (error) {
48
+ /* empty */
49
+ }
50
+ Object.assign(mdxComponents, {
51
+ // h1: function (p: Any) {
52
+ // return heading(p, 1);
53
+ // },
54
+ // h2: function (p: Any) {
55
+ // return heading(p, 2);
56
+ // },
57
+ // h3: function (p: Any) {
58
+ // return heading(p, 3);
59
+ // },
60
+ // h4: function (p: Any) {
61
+ // return heading(p, 4);
62
+ // },
63
+ // h5: function (p: Any) {
64
+ // return heading(p, 5);
65
+ // },
66
+ // h6: function (p: Any) {
67
+ // return heading(p, 6);
68
+ // },
69
+ // pre: pre,
70
+ ...overrideComps,
71
+ });
72
+ models?.keys()?.forEach(function (item) {
73
+ const key = item.substring(2).split('/').slice(0, -1).join('/');
74
+ const { basic, default: Child } = models(item);
75
+ myPkgs.push({
76
+ key: key,
77
+ path: key,
78
+ element: Child,
79
+ ...basic,
80
+ props: {
81
+ components: mdxComponents,
82
+ path: key,
83
+ },
84
+ });
85
+ });
86
+ const allDemo = import.meta.webpackContext?.('@pkg/', {
87
+ recursive: true,
88
+ regExp: /\/examples\/(.+)\.mdx$/,
89
+ mode: 'sync',
90
+ });
91
+ allDemo?.keys()?.forEach(function (e) {
92
+ const k = e.substring(2), arr = k.split('/'), name = arr[0];
93
+ if (!Array.isArray(myDemoKv[name])) {
94
+ myDemoKv[name] = [];
95
+ }
96
+ const exampleStr = allDemo(e);
97
+ const m = exampleStr.matchAll(/```([^\r\n]+)?\r?\n([\s\S]*?)\r?\n```/g);
98
+ let code = '', language = '';
99
+ let description = null;
100
+ for (const match of m) {
101
+ language = match[1] || 'tsx';
102
+ code = match[2];
103
+ description = exampleStr.replace(match[0], '');
104
+ }
105
+ myDemoKv[name].push({
106
+ language: language,
107
+ code: code,
108
+ description: description,
109
+ title: arr.pop()?.replace(/\.mdx$/, ''),
110
+ noInline: /render\([^\\)]*\);?(?=\s*$)/.test(code),
111
+ });
112
+ });
113
+ }
114
+ let list = [];
115
+ try {
116
+ list = (await import('@/router')).default;
117
+ }
118
+ catch (error) {
119
+ // eslint-disable-next-line no-console
120
+ console.info('自定义路由请在 router 目录下新建 index.ts, 类型: RouterProps[]', error);
121
+ }
122
+ function prefixKey(path, prev) {
123
+ // eslint-disable-next-line no-undefined
124
+ return [prev === '*' && path !== '*' ? undefined : prev, path].filter(Boolean).join('/');
125
+ }
126
+ const models = import.meta.webpackContext?.('@/pages/', {
127
+ recursive: true,
128
+ regExp: /\.(t|j)sx$/,
129
+ mode: 'lazy',
130
+ });
131
+ function pathToTree(input) {
132
+ const root = [];
133
+ for (let i = 0; i < input.length; i++) {
134
+ const chain = input[i].split('/').slice(0, -1);
135
+ let curr = root;
136
+ for (let j = 0; j < chain.length; j++) {
137
+ let pathRule = chain[j];
138
+ if (pathRule === '') {
139
+ continue;
140
+ }
141
+ if (pathRule === '.') {
142
+ pathRule = '*';
143
+ }
144
+ const lastHierarchy = curr;
145
+ // 遍历root是否已有该层级
146
+ if (Array.isArray(curr)) {
147
+ for (let k = 0; k < curr.length; k++) {
148
+ if (curr[k].path === pathRule) {
149
+ curr = curr[k].children;
150
+ break;
151
+ }
152
+ }
153
+ }
154
+ if (lastHierarchy === curr) {
155
+ let key = j === chain.length - 1 ? input[i] : chain.slice(0, j + 1).join('/') + '/';
156
+ // 截取最后一个 / 前面的数据
157
+ key = key.substring(2, key.lastIndexOf('/'));
158
+ const node = {
159
+ key: key,
160
+ path: pathRule,
161
+ i18n: 'route-' + key,
162
+ children: [],
163
+ alive: false,
164
+ element: lazyImport(key),
165
+ hideMenu: key.includes(':'),
166
+ props: { path: key },
167
+ };
168
+ // 文件,最后一个字符不是"/“符号
169
+ // if (j === chain.length - 1) delete node.children;
170
+ if (Array.isArray(curr)) {
171
+ curr.push(node);
172
+ }
173
+ curr = node.children;
174
+ }
175
+ }
176
+ }
177
+ return root;
178
+ }
179
+ const routers = pathToTree(models?.keys().map(function (item) {
180
+ return item.replace(/\$/g, ':');
181
+ }) || []);
182
+ function merge(source, child, prev) {
183
+ const _ = source.find(function (item) {
184
+ return item.path === child.path;
185
+ });
186
+ if (!_) {
187
+ source.push(child);
188
+ }
189
+ else {
190
+ // 处理key
191
+ _.key = prefixKey(_.path, prev);
192
+ if (typeof _.i18n === 'undefined') {
193
+ _.i18n = 'route-' + _.key;
194
+ }
195
+ if (typeof _.alive === 'undefined') {
196
+ _.alive = false;
197
+ }
198
+ if (typeof _.element === 'undefined' && child.element) {
199
+ _.element = child.element;
200
+ _.props = child.props;
201
+ }
202
+ if (typeof _.hideMenu === 'undefined') {
203
+ _.hideMenu = _.path === '*' ? true : _.key.includes(':');
204
+ }
205
+ Object.assign(_, {
206
+ ...child,
207
+ ..._,
208
+ });
209
+ if (child.children) {
210
+ if (!_.children && Array.isArray(child.children)) {
211
+ _.children = child.children;
212
+ }
213
+ child.children?.forEach(function (childData) {
214
+ merge(_?.children, childData, _?.key);
215
+ });
216
+ }
217
+ }
218
+ }
219
+ function findLogin(rs = [], onlyLogin, prevKey) {
220
+ return rs
221
+ .map(function (e) {
222
+ const _ = { ...e };
223
+ if (typeof _.key === 'undefined') {
224
+ _.key = prefixKey(e.path, prevKey);
225
+ }
226
+ if (typeof _.i18n === 'undefined') {
227
+ _.i18n = 'route-' + _.key;
228
+ }
229
+ if (typeof _.alive === 'undefined') {
230
+ _.alive = false;
231
+ }
232
+ if (_.path === '*' && typeof _.hideMenu === 'undefined') {
233
+ _.hideMenu = true;
234
+ }
235
+ if (Array.isArray(_.children)) {
236
+ // eslint-disable-next-line no-undefined
237
+ _.children = _.children.length ? findLogin(_.children, onlyLogin, _.key) : undefined;
238
+ }
239
+ if (!_.element) {
240
+ _.element = lazyImport(_.key);
241
+ _.props = { path: _.key };
242
+ }
243
+ return !!_.onlyLogin === onlyLogin && !_.root ? null : _;
244
+ })
245
+ .filter(Boolean);
246
+ }
247
+ const _router = [...list];
248
+ for (let i = 0, len = routers.length; i < len; i++) {
249
+ merge(_router, routers[i]);
250
+ }
251
+ /* 登录前注册的路由 */
252
+ export const onlyLoginRouter = findLogin(_router, false);
253
+ /* 登录后注册的路由 */
254
+ export const router = findLogin(_router, true);
255
+ export function matchUtil(pathname) {
256
+ let p = { key: '' };
257
+ function findPath(rs) {
258
+ for (let i = 0, len = rs.length; i < len; i++) {
259
+ if (rs[i].path && rs[i].path !== '*' && rs[i].key) {
260
+ try {
261
+ if (pathToRegexp(rs[i].key).exec(pathname.substring(1))) {
262
+ p = rs[i];
263
+ return;
264
+ }
265
+ }
266
+ catch (error) {
267
+ /* empty */
268
+ }
269
+ }
270
+ if (Array.isArray(rs[i].children)) {
271
+ findPath(rs[i].children);
272
+ }
273
+ }
274
+ }
275
+ findPath(router);
276
+ return p;
277
+ }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@moneko/core",
3
- "version": "3.0.0-beta.13",
3
+ "version": "3.0.0-beta.14",
4
4
  "description": "core",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
7
7
  "scripts": {
8
- "build": "npm run build-conf && npm run build-src && npm run build:types",
8
+ "build": "npm run build-conf && npm run build:types",
9
9
  "build-conf": "swc config -d build -C module.type=nodenext -C jsc.target=esnext -C jsc.loose=true -C jsc.minify.mangle=true -C jsc.minify.compress=true -C minify=true -D",
10
10
  "build-src": "swc src -d lib --extensions=.ts --ignore=src/packages/library/*.tsx -C module.type=es6 -C jsc.loose=true -C jsc.minify.mangle=true -C jsc.minify.compress=true -C minify=true -D",
11
11
  "build:types": "tsc && tsc --project cli.json",
@@ -40,6 +40,9 @@
40
40
  "portfinder": "1.0.32",
41
41
  "rehype-accessible-emojis": "0.3.2",
42
42
  "rehype-figure": "1.0.1",
43
+ "remark-frontmatter": "^4.0.1",
44
+ "remark-gfm": "^3.0.1",
45
+ "remark-mdx-frontmatter": "^3.0.0",
43
46
  "style-loader": "3.3.2",
44
47
  "style-resources-loader": "1.5.0",
45
48
  "swc-loader": "0.2.3",
@@ -1,39 +0,0 @@
1
- import { Router } from '@solidjs/router';
2
- import { render } from 'solid-js/web';
3
- import type { JSX } from 'solid-js';
4
- import App from '@/index';
5
-
6
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, no-unused-vars
7
- function isFunction(target: any): target is VoidFunction & ((...v: any[]) => any) {
8
- return [
9
- '[object Function]',
10
- '[object AsyncFunction]',
11
- '[object GeneratorFunction]',
12
- '[object Proxy]',
13
- ].includes(Object.prototype.toString.call(target));
14
- }
15
-
16
- const appEntry: AppEntryMethods | null = APPENTRY ? await import(APPENTRY) : null;
17
- const container = document.getElementById('root') as HTMLElement;
18
-
19
- if (appEntry && isFunction(appEntry.bootstrap)) {
20
- appEntry.bootstrap?.();
21
- }
22
- const Main = () => (
23
- <Router>
24
- <App />
25
- </Router>
26
- );
27
-
28
- window.rootInstance = {
29
- unmount: () => null,
30
- render(ele: () => JSX.Element) {
31
- window.rootInstance.unmount = render(ele, container);
32
- },
33
- };
34
-
35
- window.rootInstance.render(Main);
36
-
37
- if (appEntry && isFunction(appEntry.mount)) {
38
- appEntry.mount?.();
39
- }