@moneko/core 3.0.0-beta.12 → 3.0.0-beta.13
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.
- package/lib/index.js +1 -8
- package/lib/normalize.css +254 -0
- package/lib/packages/library/bootstrap.tsx +39 -0
- package/lib/packages/library/index.d.ts +1 -1
- package/lib/packages/library/index.js +1 -4
- package/lib/refresh-rem.js +1 -49
- package/lib/router/index.js +1 -0
- package/package.json +4 -4
- package/lib/packages/library/bootstrap.jsx +0 -30
- package/lib/router/index.jsx +0 -266
package/lib/index.js
CHANGED
|
@@ -1,8 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
/** 一些项目基本信息 */
|
|
3
|
-
export const projectBasicInfo = {
|
|
4
|
-
projectName,
|
|
5
|
-
providerConfig,
|
|
6
|
-
programInfo,
|
|
7
|
-
coverage: projectCoverage,
|
|
8
|
-
};
|
|
1
|
+
export{pathToRegexp}from"path-to-regexp";export var projectBasicInfo={projectName:projectName,providerConfig:providerConfig,programInfo:programInfo,coverage:projectCoverage};
|
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/* @import url('tailwindcss/utilities'); */
|
|
2
|
+
|
|
3
|
+
html,
|
|
4
|
+
body {
|
|
5
|
+
margin: 0;
|
|
6
|
+
padding: 0;
|
|
7
|
+
inline-size: 100vi;
|
|
8
|
+
font-size: var(--font-size, 14px);
|
|
9
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
|
|
10
|
+
Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
|
|
11
|
+
'Noto Color Emoji', Helvetica, Oxygen, Ubuntu, Cantarell, 'Fira Sans', 'Droid Sans';
|
|
12
|
+
color: var(--text-color, rgb(0 0 0 / 65%));
|
|
13
|
+
line-height: 1.8;
|
|
14
|
+
transition-duration: var(--transition-duration, 0.3s);
|
|
15
|
+
transition-property: background-color, color;
|
|
16
|
+
transition-timing-function: var(--transition-timing-function, cubic-bezier(0.94, -0.1, 0.1, 1.2));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
#root {
|
|
20
|
+
display: flex;
|
|
21
|
+
-webkit-overflow-scrolling: touch;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#root > main {
|
|
25
|
+
animation: route-in var(--transition-duration, 0.3s);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
input,
|
|
29
|
+
textarea {
|
|
30
|
+
caret-color: inherit;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
h1 {
|
|
34
|
+
margin: 0.67em 0;
|
|
35
|
+
font-size: 2em;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
hr {
|
|
39
|
+
overflow: visible;
|
|
40
|
+
block-size: 0;
|
|
41
|
+
box-sizing: content-box;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
pre {
|
|
45
|
+
font-size: 1em;
|
|
46
|
+
font-family: monospace;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
a {
|
|
50
|
+
text-decoration: none;
|
|
51
|
+
background-color: transparent;
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
abbr[title] {
|
|
56
|
+
border-block-end: none;
|
|
57
|
+
text-decoration: underline;
|
|
58
|
+
text-decoration: underline dotted;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
b,
|
|
62
|
+
strong {
|
|
63
|
+
font-weight: bolder;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
code,
|
|
67
|
+
kbd,
|
|
68
|
+
samp {
|
|
69
|
+
font-size: 1em;
|
|
70
|
+
font-family: monospace;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
small {
|
|
74
|
+
font-size: 80%;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
sub,
|
|
78
|
+
sup {
|
|
79
|
+
position: relative;
|
|
80
|
+
font-size: 75%;
|
|
81
|
+
line-height: 0;
|
|
82
|
+
vertical-align: baseline;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
sub {
|
|
86
|
+
inset-block-end: -0.25em;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
sup {
|
|
90
|
+
inset-block-start: -0.5em;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
img {
|
|
94
|
+
border-style: none;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
img,
|
|
98
|
+
button {
|
|
99
|
+
outline: 1px solid transparent;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
button,
|
|
103
|
+
input,
|
|
104
|
+
optgroup,
|
|
105
|
+
select,
|
|
106
|
+
textarea {
|
|
107
|
+
margin: 0;
|
|
108
|
+
font-size: 100%;
|
|
109
|
+
font-family: inherit;
|
|
110
|
+
line-height: 1.15;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
button,
|
|
114
|
+
input {
|
|
115
|
+
overflow: visible;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
button,
|
|
119
|
+
select {
|
|
120
|
+
text-transform: none;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
button,
|
|
124
|
+
[type='button'],
|
|
125
|
+
[type='reset'],
|
|
126
|
+
[type='submit'] {
|
|
127
|
+
appearance: button;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
button::-moz-focus-inner,
|
|
131
|
+
[type='button']::-moz-focus-inner,
|
|
132
|
+
[type='reset']::-moz-focus-inner,
|
|
133
|
+
[type='submit']::-moz-focus-inner {
|
|
134
|
+
border-style: none;
|
|
135
|
+
padding: 0;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
button:-moz-focusring,
|
|
139
|
+
[type='button']:-moz-focusring,
|
|
140
|
+
[type='reset']:-moz-focusring,
|
|
141
|
+
[type='submit']:-moz-focusring {
|
|
142
|
+
outline: 1px dotted var(--primary-outline);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
fieldset {
|
|
146
|
+
padding: 0.35em 0.75em 0.625em;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
legend {
|
|
150
|
+
display: table;
|
|
151
|
+
padding: 0;
|
|
152
|
+
max-inline-size: 100%;
|
|
153
|
+
white-space: normal;
|
|
154
|
+
color: inherit;
|
|
155
|
+
box-sizing: border-box;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
progress {
|
|
159
|
+
vertical-align: baseline;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
textarea {
|
|
163
|
+
overflow: auto;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
details {
|
|
167
|
+
display: block;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
summary {
|
|
171
|
+
display: list-item;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
template,
|
|
175
|
+
[hidden] {
|
|
176
|
+
display: none;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
[type='checkbox'],
|
|
180
|
+
[type='radio'] {
|
|
181
|
+
box-sizing: border-box;
|
|
182
|
+
padding: 0;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
[type='number']::-webkit-inner-spin-button,
|
|
186
|
+
[type='number']::-webkit-outer-spin-button {
|
|
187
|
+
block-size: auto;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
[type='search'] {
|
|
191
|
+
appearance: textfield;
|
|
192
|
+
outline-offset: -2px;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
[type='search']::-webkit-search-decoration {
|
|
196
|
+
appearance: none;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
::-webkit-file-upload-button {
|
|
200
|
+
appearance: button;
|
|
201
|
+
font: inherit;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
::-webkit-scrollbar {
|
|
205
|
+
inline-size: 4px;
|
|
206
|
+
block-size: 4px;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
::-webkit-scrollbar-track,
|
|
210
|
+
::-webkit-scrollbar-thumb {
|
|
211
|
+
border-radius: 5px;
|
|
212
|
+
background-color: transparent;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
:hover::-webkit-scrollbar-thumb {
|
|
216
|
+
background-color: var(--primary-selection);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
::-webkit-scrollbar-thumb:hover {
|
|
220
|
+
background-color: var(--primary-hover);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
::-webkit-scrollbar-thumb:active {
|
|
224
|
+
background-color: var(--primary-active);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
::-webkit-scrollbar-button {
|
|
228
|
+
display: none;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
@keyframes route-in {
|
|
232
|
+
from {
|
|
233
|
+
transform: translate3d(0, 16px, 0);
|
|
234
|
+
opacity: 0;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
to {
|
|
238
|
+
transform: translate3d(0, 0, 0);
|
|
239
|
+
opacity: 1;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
@keyframes route-out {
|
|
244
|
+
from {
|
|
245
|
+
transform: translate3d(0, 0, 0);
|
|
246
|
+
opacity: 1;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
to {
|
|
250
|
+
z-index: -1;
|
|
251
|
+
transform: translate3d(0, 1rem, 0);
|
|
252
|
+
opacity: 0;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
}
|
package/lib/refresh-rem.js
CHANGED
|
@@ -1,49 +1 @@
|
|
|
1
|
-
"
|
|
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
|
+
!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);
|
|
@@ -0,0 +1 @@
|
|
|
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}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneko/core",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.13",
|
|
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:types",
|
|
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
|
|
10
|
-
"build-src": "swc src -d lib -C module.type=es6 -C jsc.loose=true -C jsc.minify.mangle=true -C jsc.minify.compress=true -C minify=true
|
|
8
|
+
"build": "npm run build-conf && npm run build-src && npm run build:types",
|
|
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
|
+
"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",
|
|
12
12
|
"postbuild": "node ./copy.js ./prefix ./lib",
|
|
13
13
|
"prebuild": "rm -rf ./build && rm -rf ./lib"
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Router } from '@solidjs/router';
|
|
2
|
-
import { render } from 'solid-js/web';
|
|
3
|
-
import App from '@/index';
|
|
4
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any, no-unused-vars
|
|
5
|
-
function isFunction(target) {
|
|
6
|
-
return [
|
|
7
|
-
'[object Function]',
|
|
8
|
-
'[object AsyncFunction]',
|
|
9
|
-
'[object GeneratorFunction]',
|
|
10
|
-
'[object Proxy]',
|
|
11
|
-
].includes(Object.prototype.toString.call(target));
|
|
12
|
-
}
|
|
13
|
-
const appEntry = APPENTRY ? await import(APPENTRY) : null;
|
|
14
|
-
const container = document.getElementById('root');
|
|
15
|
-
if (appEntry && isFunction(appEntry.bootstrap)) {
|
|
16
|
-
appEntry.bootstrap?.();
|
|
17
|
-
}
|
|
18
|
-
const Main = () => (<Router>
|
|
19
|
-
<App />
|
|
20
|
-
</Router>);
|
|
21
|
-
window.rootInstance = {
|
|
22
|
-
unmount: () => null,
|
|
23
|
-
render(ele) {
|
|
24
|
-
window.rootInstance.unmount = render(ele, container);
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
window.rootInstance.render(Main);
|
|
28
|
-
if (appEntry && isFunction(appEntry.mount)) {
|
|
29
|
-
appEntry.mount?.();
|
|
30
|
-
}
|
package/lib/router/index.jsx
DELETED
|
@@ -1,266 +0,0 @@
|
|
|
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 = require.context('@pkg/', true, /README\.mdx?$/);
|
|
39
|
-
let overrideComps = {};
|
|
40
|
-
try {
|
|
41
|
-
overrideComps = await import('@/components/components');
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
/* empty */
|
|
45
|
-
}
|
|
46
|
-
Object.assign(mdxComponents, {
|
|
47
|
-
// h1: function (p: Any) {
|
|
48
|
-
// return heading(p, 1);
|
|
49
|
-
// },
|
|
50
|
-
// h2: function (p: Any) {
|
|
51
|
-
// return heading(p, 2);
|
|
52
|
-
// },
|
|
53
|
-
// h3: function (p: Any) {
|
|
54
|
-
// return heading(p, 3);
|
|
55
|
-
// },
|
|
56
|
-
// h4: function (p: Any) {
|
|
57
|
-
// return heading(p, 4);
|
|
58
|
-
// },
|
|
59
|
-
// h5: function (p: Any) {
|
|
60
|
-
// return heading(p, 5);
|
|
61
|
-
// },
|
|
62
|
-
// h6: function (p: Any) {
|
|
63
|
-
// return heading(p, 6);
|
|
64
|
-
// },
|
|
65
|
-
// pre: pre,
|
|
66
|
-
...overrideComps,
|
|
67
|
-
});
|
|
68
|
-
models.keys()?.forEach(function (item) {
|
|
69
|
-
const key = item.substring(2).split('/').slice(0, -1).join('/');
|
|
70
|
-
const { basic, default: Child } = models(item);
|
|
71
|
-
myPkgs.push({
|
|
72
|
-
key: key,
|
|
73
|
-
path: key,
|
|
74
|
-
element: Child,
|
|
75
|
-
...basic,
|
|
76
|
-
props: {
|
|
77
|
-
components: mdxComponents,
|
|
78
|
-
path: key,
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
const allDemo = require.context('@pkg/', true, /\/examples\/(.+)\.mdx$/);
|
|
83
|
-
allDemo.keys()?.forEach(function (e) {
|
|
84
|
-
const k = e.substring(2), arr = k.split('/'), name = arr[0];
|
|
85
|
-
if (!Array.isArray(myDemoKv[name])) {
|
|
86
|
-
myDemoKv[name] = [];
|
|
87
|
-
}
|
|
88
|
-
const exampleStr = allDemo(e);
|
|
89
|
-
const m = exampleStr.matchAll(/```([^\r\n]+)?\r?\n([\s\S]*?)\r?\n```/g);
|
|
90
|
-
let code = '', language = '';
|
|
91
|
-
let description = null;
|
|
92
|
-
for (const match of m) {
|
|
93
|
-
language = match[1] || 'tsx';
|
|
94
|
-
code = match[2];
|
|
95
|
-
description = exampleStr.replace(match[0], '');
|
|
96
|
-
}
|
|
97
|
-
myDemoKv[name].push({
|
|
98
|
-
language: language,
|
|
99
|
-
code: code,
|
|
100
|
-
description: description,
|
|
101
|
-
title: arr.pop()?.replace(/\.mdx$/, ''),
|
|
102
|
-
noInline: /render\([^\\)]*\);?(?=\s*$)/.test(code),
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
let list = [];
|
|
107
|
-
try {
|
|
108
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
109
|
-
list = require('@/router').default;
|
|
110
|
-
}
|
|
111
|
-
catch (error) {
|
|
112
|
-
// eslint-disable-next-line no-console
|
|
113
|
-
console.info('自定义路由请在 router 目录下新建 index.ts, 类型: RouterProps[]', error);
|
|
114
|
-
}
|
|
115
|
-
function prefixKey(path, prev) {
|
|
116
|
-
// eslint-disable-next-line no-undefined
|
|
117
|
-
return [prev === '*' && path !== '*' ? undefined : prev, path].filter(Boolean).join('/');
|
|
118
|
-
}
|
|
119
|
-
const models = require.context('@/pages/', true, /\.(t|j)sx$/, 'lazy');
|
|
120
|
-
function pathToTree(input) {
|
|
121
|
-
const root = [];
|
|
122
|
-
for (let i = 0; i < input.length; i++) {
|
|
123
|
-
const chain = input[i].split('/').slice(0, -1);
|
|
124
|
-
let curr = root;
|
|
125
|
-
for (let j = 0; j < chain.length; j++) {
|
|
126
|
-
let pathRule = chain[j];
|
|
127
|
-
if (pathRule === '') {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
if (pathRule === '.') {
|
|
131
|
-
pathRule = '*';
|
|
132
|
-
}
|
|
133
|
-
const lastHierarchy = curr;
|
|
134
|
-
// 遍历root是否已有该层级
|
|
135
|
-
if (Array.isArray(curr)) {
|
|
136
|
-
for (let k = 0; k < curr.length; k++) {
|
|
137
|
-
if (curr[k].path === pathRule) {
|
|
138
|
-
curr = curr[k].children;
|
|
139
|
-
break;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
if (lastHierarchy === curr) {
|
|
144
|
-
let key = j === chain.length - 1 ? input[i] : chain.slice(0, j + 1).join('/') + '/';
|
|
145
|
-
// 截取最后一个 / 前面的数据
|
|
146
|
-
key = key.substring(2, key.lastIndexOf('/'));
|
|
147
|
-
const node = {
|
|
148
|
-
key: key,
|
|
149
|
-
path: pathRule,
|
|
150
|
-
i18n: 'route-' + key,
|
|
151
|
-
children: [],
|
|
152
|
-
alive: false,
|
|
153
|
-
element: lazyImport(key),
|
|
154
|
-
hideMenu: key.includes(':'),
|
|
155
|
-
props: { path: key },
|
|
156
|
-
};
|
|
157
|
-
// 文件,最后一个字符不是"/“符号
|
|
158
|
-
// if (j === chain.length - 1) delete node.children;
|
|
159
|
-
if (Array.isArray(curr)) {
|
|
160
|
-
curr.push(node);
|
|
161
|
-
}
|
|
162
|
-
curr = node.children;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return root;
|
|
167
|
-
}
|
|
168
|
-
const routers = pathToTree(models.keys().map(function (item) {
|
|
169
|
-
return item.replace(/\$/g, ':');
|
|
170
|
-
}));
|
|
171
|
-
function merge(source, child, prev) {
|
|
172
|
-
const _ = source.find(function (item) {
|
|
173
|
-
return item.path === child.path;
|
|
174
|
-
});
|
|
175
|
-
if (!_) {
|
|
176
|
-
source.push(child);
|
|
177
|
-
}
|
|
178
|
-
else {
|
|
179
|
-
// 处理key
|
|
180
|
-
_.key = prefixKey(_.path, prev);
|
|
181
|
-
if (typeof _.i18n === 'undefined') {
|
|
182
|
-
_.i18n = 'route-' + _.key;
|
|
183
|
-
}
|
|
184
|
-
if (typeof _.alive === 'undefined') {
|
|
185
|
-
_.alive = false;
|
|
186
|
-
}
|
|
187
|
-
if (typeof _.element === 'undefined' && child.element) {
|
|
188
|
-
_.element = child.element;
|
|
189
|
-
_.props = child.props;
|
|
190
|
-
}
|
|
191
|
-
if (typeof _.hideMenu === 'undefined') {
|
|
192
|
-
_.hideMenu = _.path === '*' ? true : _.key.includes(':');
|
|
193
|
-
}
|
|
194
|
-
Object.assign(_, {
|
|
195
|
-
...child,
|
|
196
|
-
..._,
|
|
197
|
-
});
|
|
198
|
-
if (child.children) {
|
|
199
|
-
if (!_.children && Array.isArray(child.children)) {
|
|
200
|
-
_.children = child.children;
|
|
201
|
-
}
|
|
202
|
-
child.children?.forEach(function (childData) {
|
|
203
|
-
merge(_?.children, childData, _?.key);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
function findLogin(rs = [], onlyLogin, prevKey) {
|
|
209
|
-
return rs
|
|
210
|
-
.map(function (e) {
|
|
211
|
-
const _ = { ...e };
|
|
212
|
-
if (typeof _.key === 'undefined') {
|
|
213
|
-
_.key = prefixKey(e.path, prevKey);
|
|
214
|
-
}
|
|
215
|
-
if (typeof _.i18n === 'undefined') {
|
|
216
|
-
_.i18n = 'route-' + _.key;
|
|
217
|
-
}
|
|
218
|
-
if (typeof _.alive === 'undefined') {
|
|
219
|
-
_.alive = false;
|
|
220
|
-
}
|
|
221
|
-
if (_.path === '*' && typeof _.hideMenu === 'undefined') {
|
|
222
|
-
_.hideMenu = true;
|
|
223
|
-
}
|
|
224
|
-
if (Array.isArray(_.children)) {
|
|
225
|
-
// eslint-disable-next-line no-undefined
|
|
226
|
-
_.children = _.children.length ? findLogin(_.children, onlyLogin, _.key) : undefined;
|
|
227
|
-
}
|
|
228
|
-
if (!_.element) {
|
|
229
|
-
_.element = lazyImport(_.key);
|
|
230
|
-
_.props = { path: _.key };
|
|
231
|
-
}
|
|
232
|
-
return !!_.onlyLogin === onlyLogin && !_.root ? null : _;
|
|
233
|
-
})
|
|
234
|
-
.filter(Boolean);
|
|
235
|
-
}
|
|
236
|
-
const _router = [...list];
|
|
237
|
-
for (let i = 0, len = routers.length; i < len; i++) {
|
|
238
|
-
merge(_router, routers[i]);
|
|
239
|
-
}
|
|
240
|
-
/* 登录前注册的路由 */
|
|
241
|
-
export const onlyLoginRouter = findLogin(_router, false);
|
|
242
|
-
/* 登录后注册的路由 */
|
|
243
|
-
export const router = findLogin(_router, true);
|
|
244
|
-
export function matchUtil(pathname) {
|
|
245
|
-
let p = { key: '' };
|
|
246
|
-
function findPath(rs) {
|
|
247
|
-
for (let i = 0, len = rs.length; i < len; i++) {
|
|
248
|
-
if (rs[i].path && rs[i].path !== '*' && rs[i].key) {
|
|
249
|
-
try {
|
|
250
|
-
if (pathToRegexp(rs[i].key).exec(pathname.substring(1))) {
|
|
251
|
-
p = rs[i];
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
catch (error) {
|
|
256
|
-
/* empty */
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
if (Array.isArray(rs[i].children)) {
|
|
260
|
-
findPath(rs[i].children);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
findPath(router);
|
|
265
|
-
return p;
|
|
266
|
-
}
|