merge
This commit is contained in:
parent
598e29cf5a
commit
e4768b6360
10
package.json
10
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@kevisual/store",
|
"name": "@kevisual/store",
|
||||||
"version": "0.0.6",
|
"version": "0.0.7",
|
||||||
"main": "dist/store.js",
|
"main": "dist/store.js",
|
||||||
"module": "dist/store.js",
|
"module": "dist/store.js",
|
||||||
"types": "dist/store.d.ts",
|
"types": "dist/store.d.ts",
|
||||||
@ -70,14 +70,6 @@
|
|||||||
"./web-page.js": {
|
"./web-page.js": {
|
||||||
"import": "./dist/web-page.js",
|
"import": "./dist/web-page.js",
|
||||||
"require": "./dist/web-page.js"
|
"require": "./dist/web-page.js"
|
||||||
},
|
|
||||||
"./web": {
|
|
||||||
"import": "./dist/web.js",
|
|
||||||
"require": "./dist/web.js"
|
|
||||||
},
|
|
||||||
"./react": {
|
|
||||||
"import": "./dist-react/store-react.js",
|
|
||||||
"types": "./dist-react/index.d.ts"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {}
|
"dependencies": {}
|
||||||
|
@ -62,36 +62,4 @@ export default [
|
|||||||
},
|
},
|
||||||
plugins: [dts()],
|
plugins: [dts()],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
input: 'src/web.ts',
|
|
||||||
output: {
|
|
||||||
file: 'dist/web.js',
|
|
||||||
format: 'es',
|
|
||||||
},
|
|
||||||
plugins: [resolve({ browser: true }), commonjs(), typescript()],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
input: 'src/web.ts',
|
|
||||||
output: {
|
|
||||||
file: 'dist/web.d.ts',
|
|
||||||
format: 'es',
|
|
||||||
},
|
|
||||||
plugins: [dts()],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
input: 'src/app.ts',
|
|
||||||
output: {
|
|
||||||
file: 'dist/app.js',
|
|
||||||
format: 'iife',
|
|
||||||
},
|
|
||||||
plugins: [resolve({ browser: true }), commonjs(), typescript(), terser()],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
input: 'src/app.ts',
|
|
||||||
output: {
|
|
||||||
file: 'dist/app.d.ts',
|
|
||||||
format: 'es',
|
|
||||||
},
|
|
||||||
plugins: [dts()],
|
|
||||||
},
|
|
||||||
];
|
];
|
||||||
|
28
src/app.ts
28
src/app.ts
@ -1,28 +0,0 @@
|
|||||||
// 当前的功能,把所有的模块注入到windows对象当中
|
|
||||||
import * as WebEnv from './web-env.ts';
|
|
||||||
import * as Load from '@kevisual/load/browser';
|
|
||||||
import { Page } from './page.ts';
|
|
||||||
|
|
||||||
export class PageInit {
|
|
||||||
static isInit = false;
|
|
||||||
static init(opts?: { load?: boolean; page?: boolean }) {
|
|
||||||
if (PageInit.isInit) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const { load = true, page = false } = opts || {};
|
|
||||||
PageInit.isInit = true;
|
|
||||||
// bind to window, 必须要的获取全局的环境变量
|
|
||||||
const { useConfigKey, useContextKey } = WebEnv;
|
|
||||||
window.useConfigKey = useConfigKey;
|
|
||||||
window.useContextKey = useContextKey;
|
|
||||||
// @ts-ignore
|
|
||||||
window.webEnv = WebEnv;
|
|
||||||
// @ts-ignore
|
|
||||||
load && (window.Load = Load);
|
|
||||||
page &&
|
|
||||||
useContextKey('page', () => {
|
|
||||||
return new Page();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PageInit.init();
|
|
17
src/page.ts
17
src/page.ts
@ -277,7 +277,13 @@ export class Page {
|
|||||||
*/
|
*/
|
||||||
replace(path: string, state?: any, check?: boolean) {
|
replace(path: string, state?: any, check?: boolean) {
|
||||||
let _check = check ?? true;
|
let _check = check ?? true;
|
||||||
window.history.replaceState(state, '', this.basename + path);
|
let newPath = this.basename + path;
|
||||||
|
if (path.startsWith('http')) {
|
||||||
|
const url = new URL(path);
|
||||||
|
const origin = url.origin;
|
||||||
|
newPath = url.toString().replace(origin, '');
|
||||||
|
}
|
||||||
|
window.history.replaceState(state, '', newPath);
|
||||||
if (_check) {
|
if (_check) {
|
||||||
this.popstate({ state } as any, { type: 'all' });
|
this.popstate({ state } as any, { type: 'all' });
|
||||||
}
|
}
|
||||||
@ -317,17 +323,16 @@ export const getHistoryState = <T = Record<string, any>>() => {
|
|||||||
* 设置history state
|
* 设置history state
|
||||||
* @param state
|
* @param state
|
||||||
*/
|
*/
|
||||||
export const setHistoryState = (state: any) => {
|
export const setHistoryState = (state: any, url?: string) => {
|
||||||
const history = window.history;
|
const history = window.history;
|
||||||
const oldState = getHistoryState();
|
const oldState = getHistoryState();
|
||||||
// 只更新 state 而不改变 URL
|
history.replaceState({ ...oldState, ...state }, '', url || window.location.href);
|
||||||
history.replaceState({ ...oldState, ...state }, '', window.location.href);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清除history state
|
* 清除history state
|
||||||
*/
|
*/
|
||||||
export const clearHistoryState = () => {
|
export const clearHistoryState = (url?: string) => {
|
||||||
const history = window.history;
|
const history = window.history;
|
||||||
history.replaceState({}, '', window.location.href);
|
history.replaceState({}, '', url || window.location.href);
|
||||||
};
|
};
|
||||||
|
14
src/web.ts
14
src/web.ts
@ -1,14 +0,0 @@
|
|||||||
import { Page } from './page.ts';
|
|
||||||
import * as WebEnv from './web-env.ts';
|
|
||||||
|
|
||||||
import { nanoid } from 'nanoid';
|
|
||||||
import * as PathToREgexp from 'path-to-regexp';
|
|
||||||
import * as Load from '@kevisual/load/browser';
|
|
||||||
|
|
||||||
export const WebModule = {
|
|
||||||
Page,
|
|
||||||
WebEnv,
|
|
||||||
nanoid,
|
|
||||||
PathToREgexp,
|
|
||||||
Load,
|
|
||||||
};
|
|
Loading…
x
Reference in New Issue
Block a user