Merge pull request #129 from idrawjs/dev

fix: add try-catch to warn cross domain
This commit is contained in:
大深海 2022-01-05 22:58:18 +08:00 committed by GitHub
commit 8278c1fd58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 131 additions and 54 deletions

View file

@ -168,8 +168,24 @@ We appreciate your help!
To contribute, please follow the steps:
### Step 1: Prepare Project
- `git clone git@github.com:idrawjs/idraw.git`
- `cd idraw`
- `npm i`
- `npm run init`
- `npm run dev` to select and develop single package
### Step 2: Development
#### Simple Mode
- `npm run start` to select and develop single package
#### Complete Mode
- `npm run dev` for compiling all packages
- `npm run dev ${module}` for compiling single module such as `idraw`
- `npm run serve` for starting a server
- http://127.0.0.1:8080
- http://127.0.0.1:8080/packages/idraw/examples/features/
- http://127.0.0.1:8080/packages/core/examples/features/

View file

@ -7,5 +7,5 @@
"packages/core",
"packages/idraw"
],
"version": "0.2.0-alpha.24"
"version": "0.2.0-alpha.25"
}

View file

@ -2,10 +2,11 @@
"name": "root",
"private": false,
"scripts": {
"dev": "node ./scripts/dev-vite.js",
"dev:board": "node ./scripts/dev-rollup.js board",
"start": "node ./scripts/dev-vite.js",
"dev": "node ./scripts/dev-rollup.js",
"build": "npm run build:src && npm run build:min",
"build:src": "NODE_ENV=production BUILD_MODE=reset node ./scripts/build.js",
"build:src": "NODE_ENV=production BUILD_MODE=reset node ./scripts/build-bundle.js",
"build:mod": "node ./scripts/build-module.js",
"build:min": "node ./scripts/minify.js",
"snapshot": "node ./scripts/build.js && node ./scripts/snapshot.js",
"e2e": "mocha --exit ./__tests__/e2e.test.js",
@ -45,6 +46,7 @@
"eslint": "^7.27.0",
"execa": "^5.0.0",
"fs-extra": "^9.1.0",
"glob": "^7.2.0",
"http-server": "^0.12.3",
"husky": "^6.0.0",
"jest": "^26.6.3",
@ -66,8 +68,8 @@
"serve-handler": "^6.1.3",
"terser": "^5.9.0",
"ts-node": "^9.1.1",
"tslib": "^2.2.0",
"typescript": "^4.3.2",
"tslib": "^2.3.1",
"typescript": "^4.5.4",
"vite": "^2.7.10"
}
}

View file

@ -1,6 +1,6 @@
{
"name": "@idraw/board",
"version": "0.2.0-alpha.24",
"version": "0.2.0-alpha.25",
"description": "",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
@ -24,10 +24,10 @@
"author": "chenshenhai",
"license": "MIT",
"devDependencies": {
"@idraw/types": "^0.2.0-alpha.24"
"@idraw/types": "^0.2.0-alpha.25"
},
"dependencies": {
"@idraw/util": "^0.2.0-alpha.24"
"@idraw/util": "^0.2.0-alpha.25"
},
"publishConfig": {
"access": "public"

View file

@ -72,28 +72,33 @@ export class ScreenWatcher {
}
_initParentEvent() {
let target = window;
let targetOrigin = target.origin;
while (target.self !== target.top) {
// If in iframe
if (target.self !== target.parent) {
// If in same origin
if (target.origin === targetOrigin) {
// window.parent.window.addEventListener(
// 'mousemove',
// throttle(this._listSameOriginParentWindow.bind(this), 16),
// false);
target.parent.window.addEventListener(
'mousemove',
this._listSameOriginParentWindow.bind(this),
false);
try {
let target = window;
let targetOrigin = target.origin;
while (target.self !== target.top) {
// If in iframe
if (target.self !== target.parent) {
// If in same origin
if (target.origin === targetOrigin) {
// window.parent.window.addEventListener(
// 'mousemove',
// throttle(this._listSameOriginParentWindow.bind(this), 16),
// false);
target.parent.window.addEventListener(
'mousemove',
this._listSameOriginParentWindow.bind(this),
false);
}
}
// @ts-ignore
target = target.parent;
if (!target) {
break;
}
}
// @ts-ignore
target = target.parent;
if (!target) {
break;
}
} catch (err) {
console.warn(err);
}
}

View file

@ -1,6 +1,6 @@
{
"name": "@idraw/core",
"version": "0.2.0-alpha.24",
"version": "0.2.0-alpha.25",
"description": "",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
@ -24,12 +24,12 @@
"author": "chenshenhai",
"license": "MIT",
"devDependencies": {
"@idraw/types": "^0.2.0-alpha.24"
"@idraw/types": "^0.2.0-alpha.25"
},
"dependencies": {
"@idraw/board": "^0.2.0-alpha.24",
"@idraw/renderer": "^0.2.0-alpha.24",
"@idraw/util": "^0.2.0-alpha.24"
"@idraw/board": "^0.2.0-alpha.25",
"@idraw/renderer": "^0.2.0-alpha.25",
"@idraw/util": "^0.2.0-alpha.25"
},
"publishConfig": {
"access": "public"

View file

@ -1,6 +1,6 @@
{
"name": "idraw",
"version": "0.2.0-alpha.24",
"version": "0.2.0-alpha.25",
"description": "",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
@ -24,11 +24,11 @@
"author": "chenshenhai",
"license": "MIT",
"devDependencies": {
"@idraw/types": "^0.2.0-alpha.24"
"@idraw/types": "^0.2.0-alpha.25"
},
"dependencies": {
"@idraw/core": "^0.2.0-alpha.24",
"@idraw/util": "^0.2.0-alpha.24"
"@idraw/core": "^0.2.0-alpha.25",
"@idraw/util": "^0.2.0-alpha.25"
},
"publishConfig": {
"access": "public"

View file

@ -1,6 +1,6 @@
{
"name": "@idraw/renderer",
"version": "0.2.0-alpha.24",
"version": "0.2.0-alpha.25",
"description": "",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
@ -24,10 +24,10 @@
"author": "chenshenhai",
"license": "MIT",
"devDependencies": {
"@idraw/types": "^0.2.0-alpha.24"
"@idraw/types": "^0.2.0-alpha.25"
},
"dependencies": {
"@idraw/util": "^0.2.0-alpha.24"
"@idraw/util": "^0.2.0-alpha.25"
},
"publishConfig": {
"access": "public"

View file

@ -1,6 +1,6 @@
{
"name": "@idraw/types",
"version": "0.2.0-alpha.24",
"version": "0.2.0-alpha.25",
"description": "",
"main": "src/index.ts",
"types": "src/index.ts",

View file

@ -1,6 +1,6 @@
{
"name": "@idraw/util",
"version": "0.2.0-alpha.24",
"version": "0.2.0-alpha.25",
"description": "",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
@ -24,7 +24,7 @@
"author": "chenshenhai",
"license": "MIT",
"devDependencies": {
"@idraw/types": "^0.2.0-alpha.24"
"@idraw/types": "^0.2.0-alpha.25"
},
"publishConfig": {
"access": "public"

52
scripts/build-module.js Normal file
View file

@ -0,0 +1,52 @@
const ts = require('typescript');
const babel = require('@babel/core');
const glob = require("glob");
const { packages } = require('./config');
const { resolvePackagePath, getTsConfig } = require('./util/project');
build();
async function build() {
packages.forEach(async (pkg) => {
buildPackage(pkg.dirName);
});
}
function buildPackage(dirName) {
const pattern = '**/*.ts';
const cwd = resolvePackagePath(dirName, 'src');
const files = glob.sync(pattern, { cwd, });
const targetFiles = files.map((file) => {
return resolvePackagePath(dirName, 'src', file);
});
// build ts -> esm
{
const tsConfig = getTsConfig();
const compilerOptions = tsConfig.compilerOptions;
compilerOptions.target = ts.ScriptTarget.ES2015;
compilerOptions.moduleResolution = ts.ModuleResolutionKind.NodeJs;
compilerOptions.declaration = true;
compilerOptions.outDir = resolvePackagePath(dirName, 'dist', 'esm');
compilerOptions.rootDir = resolvePackagePath(dirName, 'src');
const program = ts.createProgram(targetFiles, compilerOptions);
program.emit();
}
// build ts -> cjs
{
const tsConfig = getTsConfig();
const compilerOptions = tsConfig.compilerOptions;
compilerOptions.target = ts.ScriptTarget.ES5;
compilerOptions.moduleResolution = ts.ModuleResolutionKind.NodeJs;
compilerOptions.declaration = true;
compilerOptions.outDir = resolvePackagePath(dirName, 'dist', 'cjs');
compilerOptions.rootDir = resolvePackagePath(dirName, 'src');
const program = ts.createProgram(targetFiles, compilerOptions);
program.emit();
}
// console.log('files ===', files);
}

View file

@ -1,4 +1,5 @@
const path = require('path');
const fs = require('fs');
function resolvePackagePath() {
const pathList = Array.from(arguments);
@ -12,8 +13,16 @@ function resolveProjectPath() {
return path.join(baseDir, ...pathList);
}
function getTsConfig() {
const configPath = resolveProjectPath('tsconfig.json')
const configStr = fs.readFileSync(configPath, { encoding: 'utf8' });
const config = JSON.parse(configStr);
return config;
}
module.exports = {
resolveProjectPath,
resolvePackagePath,
getTsConfig,
}

View file

@ -1,8 +1,6 @@
{
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"outDir": "dist",
"sourceMap": false,
"target": "es5",
"module": "ES2015",
@ -14,18 +12,13 @@
"resolveJsonModule": true,
"esModuleInterop": true,
"removeComments": true,
"jsx": "preserve",
"lib": ["ESNext", "dom"],
"rootDir": ".",
// "paths": {
// "idraw": ["packages/idraw/src1"]
// }
"lib": ["ESNext", "dom"]
},
"include": [
"packages/global.d.ts",
"packages/*/src",
"packages/*/__tests__",
"packages/*/dev",
"packages/*/dev"
],
"exclude": [
"packages/*/examples"