eslint omi-native
This commit is contained in:
parent
7be527b1a2
commit
f5c15f11f5
|
@ -0,0 +1,145 @@
|
|||
{
|
||||
"name": "omi",
|
||||
"version": "4.0.15",
|
||||
"description": "Next generation web framework.",
|
||||
"main": "dist/omi.js",
|
||||
"jsnext:main": "dist/omi.esm.js",
|
||||
"module": "dist/omi.esm.js",
|
||||
"dev:main": "dist/omi.dev.js",
|
||||
"minified:main": "dist/omi.min.js",
|
||||
"types": "dist/omi.d.ts",
|
||||
"scripts": {
|
||||
"clean": "rimraf test/ts/**/*.js",
|
||||
"copy-typescript-definition": "copyfiles -f src/omi.d.ts dist",
|
||||
"build": "npm-run-all --silent clean transpile copy-typescript-definition strip optimize minify size",
|
||||
"slot": "rollup -c config/rollup.example.js --watch",
|
||||
"use": "rollup -c config/rollup.example.js --watch",
|
||||
"decorators": "rollup -c config/rollup.example.js --watch",
|
||||
"mobx": "rollup -c config/rollup.example.js --watch",
|
||||
"todo-app": "rollup -c config/rollup.example.js --watch",
|
||||
"observe": "rollup -c config/rollup.example.js --watch",
|
||||
"store": "rollup -c config/rollup.example.js --watch",
|
||||
"counter": "rollup -c config/rollup.example.js --watch",
|
||||
"render-array": "rollup -c config/rollup.example.js --watch",
|
||||
"css3transform": "rollup -c config/rollup.example.js --watch",
|
||||
"tap": "rollup -c config/rollup.example.js --watch",
|
||||
"simple": "rollup -c config/rollup.example.js --watch",
|
||||
"transpile:main": "rollup -c config/rollup.config.js",
|
||||
"transpile:esm": "rollup -c config/rollup.config.esm.js",
|
||||
"transpile": "npm-run-all transpile:main transpile:esm",
|
||||
"optimize": "uglifyjs dist/omi.dev.js -c conditionals=false,sequences=false,loops=false,join_vars=false,collapse_vars=false --pure-funcs=Object.defineProperty --mangle-props --mangle-regex=\"/^(_|normalizedNodeName|nextBase|prev[CPS]|_parentC)/\" --name-cache config/properties.json -b width=120,quote_style=3 -o dist/omi.js -p relative --in-source-map dist/omi.dev.js.map --source-map dist/omi.js.map",
|
||||
"minify": "uglifyjs dist/omi.js -c collapse_vars,evaluate,screw_ie8,unsafe,loops=false,keep_fargs=false,pure_getters,unused,dead_code -m -o dist/omi.min.js -p relative --in-source-map dist/omi.js.map --source-map dist/omi.min.js.map",
|
||||
"strip:main": "jscodeshift --run-in-band -s -t config/codemod-strip-tdz.js dist/omi.dev.js && jscodeshift --run-in-band -s -t config/codemod-const.js dist/omi.dev.js && jscodeshift --run-in-band -s -t config/codemod-let-name.js dist/omi.dev.js",
|
||||
"strip:esm": "jscodeshift --run-in-band -s -t config/codemod-strip-tdz.js dist/omi.esm.js && jscodeshift --run-in-band -s -t config/codemod-const.js dist/omi.esm.js && jscodeshift --run-in-band -s -t config/codemod-let-name.js dist/omi.esm.js",
|
||||
"strip": "npm-run-all strip:main strip:esm",
|
||||
"size": "node -e \"process.stdout.write('gzip size: ')\" && gzip-size --raw dist/omi.min.js",
|
||||
"test": "jest",
|
||||
"fix": "eslint src --fix",
|
||||
"fix-e": "eslint examples --fix",
|
||||
"lint": "eslint src test",
|
||||
"smart-release": "npm run build && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish",
|
||||
"release": "cross-env npm run smart-release"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "./config/eslint-config.js"
|
||||
},
|
||||
"typings": "./dist/omi.d.ts",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Tencent/omi.git"
|
||||
},
|
||||
"files": [
|
||||
"src",
|
||||
"dist",
|
||||
"typings.json"
|
||||
],
|
||||
"keywords": [
|
||||
"omi",
|
||||
"webcomponents",
|
||||
"jsx",
|
||||
"proxy",
|
||||
"preact",
|
||||
"react",
|
||||
"virtual dom",
|
||||
"vdom",
|
||||
"components",
|
||||
"virtual",
|
||||
"dom"
|
||||
],
|
||||
"author": "dntzhang <dntzhang@qq.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/Tencent/omi/issues"
|
||||
},
|
||||
"homepage": "https://github.com/Tencent/omi",
|
||||
"devDependencies": {
|
||||
"@types/chai": "^4.1.2",
|
||||
"@types/mocha": "^5.0.0",
|
||||
"@types/node": "^9.4.7",
|
||||
"babel-cli": "^6.24.1",
|
||||
"babel-core": "^6.24.1",
|
||||
"babel-eslint": "^8.2.2",
|
||||
"babel-loader": "^7.0.0",
|
||||
"babel-plugin-transform-class-properties": "^6.24.1",
|
||||
"babel-plugin-transform-decorators-legacy": "^1.3.5",
|
||||
"babel-plugin-transform-object-rest-spread": "^6.23.0",
|
||||
"babel-plugin-transform-react-jsx": "^6.24.1",
|
||||
"babel-preset-env": "^1.6.1",
|
||||
"bundlesize": "^0.17.0",
|
||||
"chai": "^4.1.2",
|
||||
"copyfiles": "^2.0.0",
|
||||
"core-js": "^2.4.1",
|
||||
"coveralls": "^3.0.0",
|
||||
"cross-env": "^5.1.4",
|
||||
"diff": "^3.0.0",
|
||||
"eslint": "^4.18.2",
|
||||
"eslint-config-prettier": "^3.1.0",
|
||||
"eslint-plugin-prettier": "^3.0.0",
|
||||
"eslint-plugin-react": "^7.7.0",
|
||||
"flow-bin": "^0.67.1",
|
||||
"gzip-size-cli": "^2.0.0",
|
||||
"istanbul-instrumenter-loader": "^3.0.0",
|
||||
"jest": "^23.6.0",
|
||||
"jscodeshift": "^0.5.0",
|
||||
"mobx": "^4.5.1",
|
||||
"mocha": "^5.0.4",
|
||||
"npm-run-all": "^4.0.0",
|
||||
"omi-mobx": "^0.2.2",
|
||||
"omi-tap": "^2.0.2",
|
||||
"omi-transform": "^2.0.1",
|
||||
"prettier": "^1.14.3",
|
||||
"rimraf": "^2.5.3",
|
||||
"rollup": "^0.57.1",
|
||||
"rollup-plugin-babel": "^3.0.2",
|
||||
"rollup-plugin-license": "^0.6.0",
|
||||
"rollup-plugin-memory": "^3.0.0",
|
||||
"rollup-plugin-node-resolve": "^3.0.0",
|
||||
"sinon": "^4.4.2",
|
||||
"sinon-chai": "^3.0.0",
|
||||
"typescript": "^2.8.1",
|
||||
"uglify-js": "^2.7.5",
|
||||
"webpack": "^4.3.0"
|
||||
},
|
||||
"greenkeeper": {
|
||||
"ignore": [
|
||||
"babel-cli",
|
||||
"babel-core",
|
||||
"babel-eslint",
|
||||
"babel-loader",
|
||||
"jscodeshift",
|
||||
"rollup-plugin-babel"
|
||||
]
|
||||
},
|
||||
"bundlesize": [
|
||||
{
|
||||
"path": "./dist/omi.min.js",
|
||||
"threshold": "4Kb"
|
||||
}
|
||||
],
|
||||
"prettier": {
|
||||
"singleQuote": true,
|
||||
"semi": false,
|
||||
"tabWidth": 2,
|
||||
"useTabs": false
|
||||
}
|
||||
}
|
|
@ -1,98 +1,97 @@
|
|||
|
||||
import Element from './element';
|
||||
import { addDoc, removeDoc } from './util';
|
||||
import Element from './element'
|
||||
import { addDoc, removeDoc } from './util'
|
||||
|
||||
//get document module from global bridge
|
||||
const { document } = global.bridge;
|
||||
const { document } = global.bridge
|
||||
|
||||
export default class Document {
|
||||
constructor(id) {
|
||||
this.id = id;
|
||||
addDoc(id, this);
|
||||
this.nodeMap = {};
|
||||
this._isMockDocument = true;
|
||||
this.keyframes = {};
|
||||
}
|
||||
constructor(id) {
|
||||
this.id = id
|
||||
addDoc(id, this)
|
||||
this.nodeMap = {}
|
||||
this._isMockDocument = true
|
||||
this.keyframes = {}
|
||||
}
|
||||
|
||||
createBody(type, props) {
|
||||
if (!this.body) {
|
||||
const el = new Element(type, props);
|
||||
el.didMount = true;
|
||||
el.ownerDocument = this;
|
||||
el.docId = this.id;
|
||||
el.style.alignItems = 'flex-start';
|
||||
this.body = el;
|
||||
}
|
||||
createBody(type, props) {
|
||||
if (!this.body) {
|
||||
const el = new Element(type, props)
|
||||
el.didMount = true
|
||||
el.ownerDocument = this
|
||||
el.docId = this.id
|
||||
el.style.alignItems = 'flex-start'
|
||||
this.body = el
|
||||
}
|
||||
|
||||
return this.body;
|
||||
}
|
||||
return this.body
|
||||
}
|
||||
|
||||
createElement(tagName, props) {
|
||||
let el = new Element(tagName, props);
|
||||
el.ownerDocument = this;
|
||||
el.docId = this.id;
|
||||
return el;
|
||||
}
|
||||
createElement(tagName, props) {
|
||||
let el = new Element(tagName, props)
|
||||
el.ownerDocument = this
|
||||
el.docId = this.id
|
||||
return el
|
||||
}
|
||||
|
||||
destroy() {
|
||||
delete this.listener;
|
||||
delete this.nodeMap;
|
||||
removeDoc(this.id);
|
||||
}
|
||||
destroy() {
|
||||
delete this.listener
|
||||
delete this.nodeMap
|
||||
removeDoc(this.id)
|
||||
}
|
||||
|
||||
createFinish() {
|
||||
document.createFinish(this.id, this.body.toJSON());
|
||||
}
|
||||
createFinish() {
|
||||
document.createFinish(this.id, this.body.toJSON())
|
||||
}
|
||||
|
||||
updateFinish() {
|
||||
document.updateFinish(this.id);
|
||||
}
|
||||
updateFinish() {
|
||||
document.updateFinish(this.id)
|
||||
}
|
||||
|
||||
addElement(ref, element, index) {
|
||||
document.addElement(this.id, ref, element, index);
|
||||
}
|
||||
addElement(ref, element, index) {
|
||||
document.addElement(this.id, ref, element, index)
|
||||
}
|
||||
|
||||
moveElement(ref, parentRef, index) {
|
||||
document.moveElement(this.id, ref, parentRef, index);
|
||||
}
|
||||
moveElement(ref, parentRef, index) {
|
||||
document.moveElement(this.id, ref, parentRef, index)
|
||||
}
|
||||
|
||||
removeElement(ref) {
|
||||
document.removeElement(this.id, ref);
|
||||
}
|
||||
removeElement(ref) {
|
||||
document.removeElement(this.id, ref)
|
||||
}
|
||||
|
||||
setStyles(ref, result) {
|
||||
document.setStyles(this.id, ref, result);
|
||||
}
|
||||
setStyles(ref, result) {
|
||||
document.setStyles(this.id, ref, result)
|
||||
}
|
||||
|
||||
setAttr(ref, result) {
|
||||
document.setAttr(this.id, ref, result);
|
||||
}
|
||||
setAttr(ref, result) {
|
||||
document.setAttr(this.id, ref, result)
|
||||
}
|
||||
|
||||
removeAttr(ref, key) {
|
||||
document.removeAttr(this.id, ref, key);
|
||||
}
|
||||
removeAttr(ref, key) {
|
||||
document.removeAttr(this.id, ref, key)
|
||||
}
|
||||
|
||||
addEvent(ref, type) {
|
||||
document.addEvent(this.id, ref, type);
|
||||
}
|
||||
addEvent(ref, type) {
|
||||
document.addEvent(this.id, ref, type)
|
||||
}
|
||||
|
||||
removeEvent(ref, type) {
|
||||
document.removeEvent(this.id, ref, type);
|
||||
}
|
||||
removeEvent(ref, type) {
|
||||
document.removeEvent(this.id, ref, type)
|
||||
}
|
||||
|
||||
addKeyframe(frame) {
|
||||
document.addKeyframe(this.id, frame);
|
||||
}
|
||||
addKeyframe(frame) {
|
||||
document.addKeyframe(this.id, frame)
|
||||
}
|
||||
|
||||
addKeyframeMap(frames) {
|
||||
document.addKeyframeMap(this.id, frames);
|
||||
}
|
||||
addKeyframeMap(frames) {
|
||||
document.addKeyframeMap(this.id, frames)
|
||||
}
|
||||
|
||||
scrollTo(ref, x, y, animated) {
|
||||
document.scrollTo(this.id, ref, x, y, animated);
|
||||
}
|
||||
scrollTo(ref, x, y, animated) {
|
||||
document.scrollTo(this.id, ref, x, y, animated)
|
||||
}
|
||||
|
||||
getComputedStyle(ref, func) {
|
||||
document.getComputedStyle(this.id, ref, func);
|
||||
}
|
||||
}
|
||||
getComputedStyle(ref, func) {
|
||||
document.getComputedStyle(this.id, ref, func)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,286 +1,273 @@
|
|||
|
||||
import {
|
||||
getDoc,
|
||||
uniqueId,
|
||||
linkParent,
|
||||
insertIndex,
|
||||
moveIndex,
|
||||
removeIndex
|
||||
} from './util';
|
||||
getDoc,
|
||||
uniqueId,
|
||||
linkParent,
|
||||
insertIndex,
|
||||
moveIndex,
|
||||
removeIndex
|
||||
} from './util'
|
||||
|
||||
import { getSendBridgeFlag } from './util';
|
||||
import { getSendBridgeFlag } from './util'
|
||||
|
||||
const sendBridgeFlag = getSendBridgeFlag();
|
||||
const sendBridgeFlag = getSendBridgeFlag()
|
||||
|
||||
function registerNode(docId, node) {
|
||||
const doc = getDoc(docId);
|
||||
doc.nodeMap[node.nodeId] = node;
|
||||
const doc = getDoc(docId)
|
||||
doc.nodeMap[node.nodeId] = node
|
||||
}
|
||||
|
||||
export default class Element {
|
||||
constructor(type) {
|
||||
this.nodeType = 1;
|
||||
this.nodeId = uniqueId();
|
||||
this.ref = this.nodeId;
|
||||
this.type = type;
|
||||
this.attributes = {};
|
||||
this.style = {};
|
||||
this.classStyle = {};
|
||||
this.event = {};
|
||||
this.childNodes = [];
|
||||
constructor(type) {
|
||||
this.nodeType = 1
|
||||
this.nodeId = uniqueId()
|
||||
this.ref = this.nodeId
|
||||
this.type = type
|
||||
this.attributes = {}
|
||||
this.style = {}
|
||||
this.classStyle = {}
|
||||
this.event = {}
|
||||
this.childNodes = []
|
||||
|
||||
this.nodeName = this.type;
|
||||
this.didMount = false;
|
||||
this.parentNode = null;
|
||||
this.nextSibling = null;
|
||||
this.previousSibling = null;
|
||||
this.firstChild = null;
|
||||
}
|
||||
this.nodeName = this.type
|
||||
this.didMount = false
|
||||
this.parentNode = null
|
||||
this.nextSibling = null
|
||||
this.previousSibling = null
|
||||
this.firstChild = null
|
||||
}
|
||||
|
||||
appendChild(node) {
|
||||
appendChild(node) {
|
||||
if (!node.parentNode) {
|
||||
linkParent(node, this)
|
||||
insertIndex(node, this.childNodes, this.childNodes.length, true)
|
||||
|
||||
if (!node.parentNode) {
|
||||
linkParent(node, this);
|
||||
insertIndex(node, this.childNodes, this.childNodes.length, true);
|
||||
if (this.docId != undefined) {
|
||||
registerNode(this.docId, node)
|
||||
}
|
||||
|
||||
if (this.docId != undefined) {
|
||||
registerNode(this.docId, node);
|
||||
}
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.addElement(this.ref, node.toJSON(), -1)
|
||||
}
|
||||
} else {
|
||||
node.parentNode.removeChild(node)
|
||||
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.addElement(this.ref, node.toJSON(), -1);
|
||||
}
|
||||
this.appendChild(node)
|
||||
|
||||
}
|
||||
else {
|
||||
node.parentNode.removeChild(node);
|
||||
return;
|
||||
}
|
||||
|
||||
this.appendChild(node);
|
||||
this.firstChild = this.childNodes[0]
|
||||
|
||||
return;
|
||||
if (this.didMount) {
|
||||
this._setDidMount(node, true)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
_setDidMount(node, mount) {
|
||||
node.didMount = mount
|
||||
node.childNodes.forEach(child => {
|
||||
this._setDidMount(child, mount)
|
||||
})
|
||||
}
|
||||
|
||||
this.firstChild = this.childNodes[0];
|
||||
insertBefore(node, before) {
|
||||
if (!node.parentNode) {
|
||||
linkParent(node, this)
|
||||
const index = insertIndex(node, this.childNodes, this.childNodes.indexOf(before), true)
|
||||
if (this.docId != undefined) {
|
||||
registerNode(this.docId, node)
|
||||
}
|
||||
|
||||
if (this.didMount) {
|
||||
this._setDidMount(node, true);
|
||||
}
|
||||
}
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.addElement(this.ref, node.toJSON(), index)
|
||||
}
|
||||
} else {
|
||||
node.parentNode.removeChild(node)
|
||||
this.insertBefore(node, before)
|
||||
return;
|
||||
}
|
||||
if (this.didMount) {
|
||||
this._setDidMount(node, true)
|
||||
}
|
||||
this.firstChild = this.childNodes[0]
|
||||
}
|
||||
|
||||
insertAfter(node, after) {
|
||||
if (node.parentNode && node.parentNode !== this) {
|
||||
return
|
||||
}
|
||||
if (
|
||||
node === after ||
|
||||
(node.previousSibling && node.previousSibling === after)
|
||||
) {
|
||||
return
|
||||
}
|
||||
if (!node.parentNode) {
|
||||
linkParent(node, this)
|
||||
const index = insertIndex(node, this.childNodes, this.childNodes.indexOf(after) + 1, true)
|
||||
)
|
||||
|
||||
if (this.docId != undefined) {
|
||||
registerNode(this.docId, node)
|
||||
}
|
||||
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.addElement(this.ref, node.toJSON(), index)
|
||||
}
|
||||
} else {
|
||||
const index = moveIndex(
|
||||
node,
|
||||
this.childNodes,
|
||||
this.childNodes.indexOf(after) + 1
|
||||
)
|
||||
|
||||
if (this.didMount) {
|
||||
this.ownerDocument.moveElement(node.ref, this.ref, index)
|
||||
}
|
||||
}
|
||||
if (this.didMount) {
|
||||
this._setDidMount(node, true)
|
||||
}
|
||||
this.firstChild = this.childNodes[0]
|
||||
}
|
||||
|
||||
removeChild(node) {
|
||||
if (node.parentNode) {
|
||||
removeIndex(node, this.childNodes, true)
|
||||
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.removeElement(node.ref)
|
||||
}
|
||||
}
|
||||
|
||||
node.parentNode = null
|
||||
|
||||
this._setDidMount(node, false)
|
||||
|
||||
this.firstChild = this.childNodes[0]
|
||||
}
|
||||
|
||||
|
||||
_setDidMount(node, mount) {
|
||||
node.didMount = mount;
|
||||
node.childNodes.forEach(child => {
|
||||
this._setDidMount(child, mount);
|
||||
});
|
||||
}
|
||||
setAttribute(key, value, silent) {
|
||||
if (this.attributes[key] === value && silent !== false) {
|
||||
return
|
||||
}
|
||||
this.attributes[key] = value
|
||||
if (!silent) {
|
||||
const result = {}
|
||||
result[key] = value
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.setAttr(this.ref, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
insertBefore(node, before) {
|
||||
removeAttribute(key) {
|
||||
if (this.attributes[key]) {
|
||||
delete this.attributes[key]
|
||||
}
|
||||
}
|
||||
|
||||
if (!node.parentNode) {
|
||||
linkParent(node, this);
|
||||
const index = insertIndex(node, this.childNodes, this.childNodes.indexOf(before), true);
|
||||
if (this.docId != undefined) {
|
||||
registerNode(this.docId, node);
|
||||
}
|
||||
setStyle(key, value, silent) {
|
||||
if (this.style[key] === value && silent !== false) {
|
||||
return
|
||||
}
|
||||
this.style[key] = value
|
||||
if (!silent && this.ownerDocument) {
|
||||
const result = {}
|
||||
result[key] = value
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.setStyles(this.ref, result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.addElement(this.ref, node.toJSON(), index);
|
||||
}
|
||||
setStyles(styles) {
|
||||
Object.assign(this.style, styles)
|
||||
if (this.ownerDocument) {
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.setStyles(this.ref, styles)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
node.parentNode.removeChild(node);
|
||||
this.insertBefore(node, before);
|
||||
return;
|
||||
}
|
||||
if (this.didMount) {
|
||||
this._setDidMount(node, true);
|
||||
}
|
||||
this.firstChild = this.childNodes[0];
|
||||
}
|
||||
setClassStyle(classStyle) {
|
||||
for (const key in this.classStyle) {
|
||||
this.classStyle[key] = ''
|
||||
}
|
||||
|
||||
insertAfter(node, after) {
|
||||
if (node.parentNode && node.parentNode !== this) {
|
||||
return;
|
||||
}
|
||||
if (node === after || (node.previousSibling && node.previousSibling === after)) {
|
||||
return;
|
||||
}
|
||||
if (!node.parentNode) {
|
||||
linkParent(node, this);
|
||||
const index = insertIndex(node, this.childNodes, this.childNodes.indexOf(after) + 1, true);
|
||||
|
||||
if (this.docId != undefined) {
|
||||
registerNode(this.docId, node);
|
||||
}
|
||||
Object.assign(this.classStyle, classStyle)
|
||||
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.addElement(this.ref, node.toJSON(), index);
|
||||
}
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.setStyles(this.ref, this.toStyle())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
const index = moveIndex(node, this.childNodes, this.childNodes.indexOf(after) + 1);
|
||||
addEventListener(type, handler) {
|
||||
if (!this.event[type]) {
|
||||
this.event[type] = handler
|
||||
|
||||
if (this.didMount) {
|
||||
this.ownerDocument.moveElement(node.ref, this.ref, index);
|
||||
}
|
||||
}
|
||||
if (this.didMount) {
|
||||
this._setDidMount(node, true);
|
||||
}
|
||||
this.firstChild = this.childNodes[0];
|
||||
}
|
||||
sendBridgeFlag[this.docId] && this.didMount && this.ownerDocument.addEvent(this.ref, type)
|
||||
}
|
||||
}
|
||||
|
||||
removeChild(node) {
|
||||
if (node.parentNode) {
|
||||
removeIndex(node, this.childNodes, true);
|
||||
removeEventListener(type) {
|
||||
if (this.event[type]) {
|
||||
delete this.event[type]
|
||||
let doc = getDoc(this.docId)
|
||||
doc.nodeMap[this.ref] && doc.nodeMap[this.ref].event && doc.nodeMap[this.ref].event[type] ? doc.nodeMap[this.ref].event[type] = null : ''
|
||||
sendBridgeFlag[this.docId] && this.didMount && this.ownerDocument.removeEvent(this.ref, type)
|
||||
}
|
||||
}
|
||||
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.removeElement(node.ref);
|
||||
}
|
||||
fireEvent(type, e) {
|
||||
const handler = this.event[type]
|
||||
if (handler) {
|
||||
return handler.call(this, e)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
toStyle() {
|
||||
return Object.assign({}, this.classStyle, this.style)
|
||||
}
|
||||
|
||||
node.parentNode = null;
|
||||
getComputedStyle() {}
|
||||
|
||||
this._setDidMount(node, false);
|
||||
toJSON() {
|
||||
let result = {
|
||||
id: this.ref,
|
||||
type: this.type,
|
||||
docId: this.docId || -10000,
|
||||
attributes: this.attributes ? this.attributes : {}
|
||||
}
|
||||
result.attributes.style = this.toStyle()
|
||||
|
||||
this.firstChild = this.childNodes[0];
|
||||
}
|
||||
const event = Object.keys(this.event)
|
||||
if (event.length) {
|
||||
result.event = event
|
||||
}
|
||||
|
||||
if (this.childNodes.length) {
|
||||
result.children = this.childNodes.map(child => child.toJSON())
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
replaceChild(newChild, oldChild) {
|
||||
this.insertBefore(newChild, oldChild)
|
||||
this.removeChild(oldChild)
|
||||
}
|
||||
|
||||
setAttribute(key, value, silent) {
|
||||
if (this.attributes[key] === value && silent !== false) {
|
||||
return;
|
||||
}
|
||||
this.attributes[key] = value;
|
||||
if (!silent) {
|
||||
const result = {};
|
||||
result[key] = value;
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.setAttr(this.ref, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
destroy() {
|
||||
const doc = getDoc(this.docId)
|
||||
|
||||
removeAttribute(key) {
|
||||
if (this.attributes[key]) {
|
||||
delete this.attributes[key];
|
||||
}
|
||||
if (doc) {
|
||||
delete doc.nodeMap[this.nodeId]
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
setStyle(key, value, silent) {
|
||||
if (this.style[key] === value && silent !== false) {
|
||||
return;
|
||||
}
|
||||
this.style[key] = value;
|
||||
if (!silent && this.ownerDocument) {
|
||||
const result = {};
|
||||
result[key] = value;
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.setStyles(this.ref, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setStyles(styles) {
|
||||
Object.assign(this.style, styles);
|
||||
if (this.ownerDocument) {
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.setStyles(this.ref, styles);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setClassStyle(classStyle) {
|
||||
for (const key in this.classStyle) {
|
||||
this.classStyle[key] = '';
|
||||
}
|
||||
|
||||
Object.assign(this.classStyle, classStyle);
|
||||
|
||||
if (this.didMount && sendBridgeFlag[this.docId]) {
|
||||
this.ownerDocument.setStyles(this.ref, this.toStyle());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
addEventListener(type, handler) {
|
||||
if (!this.event[type]) {
|
||||
this.event[type] = handler;
|
||||
|
||||
sendBridgeFlag[this.docId] && this.didMount && this.ownerDocument.addEvent(this.ref, type);
|
||||
}
|
||||
}
|
||||
|
||||
removeEventListener(type) {
|
||||
if (this.event[type]) {
|
||||
delete this.event[type];
|
||||
let doc = getDoc(this.docId);
|
||||
doc.nodeMap[this.ref] && doc.nodeMap[this.ref].event && doc.nodeMap[this.ref].event[type] ? doc.nodeMap[this.ref].event[type] = null : '';
|
||||
sendBridgeFlag[this.docId] && this.didMount && this.ownerDocument.removeEvent(this.ref, type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fireEvent(type, e) {
|
||||
const handler = this.event[type];
|
||||
if (handler) {
|
||||
return handler.call(this, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
toStyle() {
|
||||
return Object.assign({}, this.classStyle, this.style);
|
||||
}
|
||||
|
||||
getComputedStyle() {
|
||||
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
let result = {
|
||||
id: this.ref,
|
||||
type: this.type,
|
||||
docId: this.docId || -10000,
|
||||
attributes: this.attributes ? this.attributes : {}
|
||||
};
|
||||
result.attributes.style = this.toStyle();
|
||||
|
||||
const event = Object.keys(this.event);
|
||||
if (event.length) {
|
||||
result.event = event;
|
||||
}
|
||||
|
||||
if (this.childNodes.length) {
|
||||
result.children = this.childNodes.map((child) => child.toJSON());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
replaceChild(newChild, oldChild) {
|
||||
this.insertBefore(newChild, oldChild);
|
||||
this.removeChild(oldChild);
|
||||
}
|
||||
|
||||
destroy() {
|
||||
const doc = getDoc(this.docId);
|
||||
|
||||
if (doc) {
|
||||
delete doc.nodeMap[this.nodeId];
|
||||
}
|
||||
|
||||
this.parentNode = null;
|
||||
this.childNodes.forEach(child => {
|
||||
child.destroy();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
this.parentNode = null
|
||||
this.childNodes.forEach(child => {
|
||||
child.destroy()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import Element from './element'
|
||||
|
||||
export default class HTMLElement extends Element {
|
||||
constructor( ) {
|
||||
|
||||
}
|
||||
constructor() {}
|
||||
}
|
||||
|
|
|
@ -1,144 +1,137 @@
|
|||
let nodeId = 1;
|
||||
let nodeId = 1
|
||||
export function uniqueId() {
|
||||
return nodeId++;
|
||||
return nodeId++
|
||||
}
|
||||
|
||||
|
||||
let docMap = {};
|
||||
let docMap = {}
|
||||
|
||||
export function addDoc(id, doc) {
|
||||
|
||||
docMap[id] = doc;
|
||||
docMap[id] = doc
|
||||
}
|
||||
|
||||
export function getDoc(id) {
|
||||
return docMap[id];
|
||||
return docMap[id]
|
||||
}
|
||||
|
||||
export function removeDoc(id) {
|
||||
delete docMap[id];
|
||||
delete docMap[id]
|
||||
}
|
||||
|
||||
let sendBridgeFlag = {};
|
||||
let sendBridgeFlag = {}
|
||||
|
||||
export function getSendBridgeFlag(){
|
||||
return sendBridgeFlag;
|
||||
export function getSendBridgeFlag() {
|
||||
return sendBridgeFlag
|
||||
}
|
||||
|
||||
export function setSendBridgeFlag(docId, flag){
|
||||
return sendBridgeFlag[docId] = flag;
|
||||
export function setSendBridgeFlag(docId, flag) {
|
||||
return (sendBridgeFlag[docId] = flag)
|
||||
}
|
||||
|
||||
export function insertIndex(target, list, newIndex) {
|
||||
if (newIndex < 0) {
|
||||
newIndex = 0
|
||||
}
|
||||
const before = list[newIndex - 1]
|
||||
const after = list[newIndex]
|
||||
list.splice(newIndex, 0, target)
|
||||
|
||||
if (newIndex < 0) {
|
||||
newIndex = 0;
|
||||
}
|
||||
const before = list[newIndex - 1];
|
||||
const after = list[newIndex];
|
||||
list.splice(newIndex, 0, target);
|
||||
before && (before.nextSibling = target)
|
||||
target.previousSibling = before
|
||||
target.nextSibling = after
|
||||
after && (after.previousSibling = target)
|
||||
|
||||
before && (before.nextSibling = target);
|
||||
target.previousSibling = before;
|
||||
target.nextSibling = after;
|
||||
after && (after.previousSibling = target);
|
||||
|
||||
return newIndex;
|
||||
return newIndex
|
||||
}
|
||||
|
||||
|
||||
export function moveIndex(target, list, newIndex) {
|
||||
const index = list.indexOf(target);
|
||||
const index = list.indexOf(target)
|
||||
|
||||
if (index < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (index < 0) {
|
||||
return -1
|
||||
}
|
||||
|
||||
const before = list[index - 1];
|
||||
const after = list[index + 1];
|
||||
before && (before.nextSibling = after);
|
||||
after && (after.previousSibling = before);
|
||||
const before = list[index - 1]
|
||||
const after = list[index + 1]
|
||||
before && (before.nextSibling = after)
|
||||
after && (after.previousSibling = before)
|
||||
|
||||
list.splice(index, 1);
|
||||
let newIndexAfter = newIndex;
|
||||
if (index <= newIndex) {
|
||||
newIndexAfter = newIndex - 1;
|
||||
}
|
||||
const beforeNew = list[newIndexAfter - 1];
|
||||
const afterNew = list[newIndexAfter];
|
||||
list.splice(newIndexAfter, 0, target);
|
||||
list.splice(index, 1)
|
||||
let newIndexAfter = newIndex
|
||||
if (index <= newIndex) {
|
||||
newIndexAfter = newIndex - 1
|
||||
}
|
||||
const beforeNew = list[newIndexAfter - 1]
|
||||
const afterNew = list[newIndexAfter]
|
||||
list.splice(newIndexAfter, 0, target)
|
||||
|
||||
beforeNew && (beforeNew.nextSibling = target);
|
||||
target.previousSibling = beforeNew;
|
||||
target.nextSibling = afterNew;
|
||||
afterNew && (afterNew.previousSibling = target);
|
||||
beforeNew && (beforeNew.nextSibling = target)
|
||||
target.previousSibling = beforeNew
|
||||
target.nextSibling = afterNew
|
||||
afterNew && (afterNew.previousSibling = target)
|
||||
|
||||
if (index === newIndexAfter) {
|
||||
return -1;
|
||||
}
|
||||
return newIndex;
|
||||
if (index === newIndexAfter) {
|
||||
return -1
|
||||
}
|
||||
return newIndex
|
||||
}
|
||||
|
||||
export function removeIndex(target, list, changeSibling) {
|
||||
const index = list.indexOf(target);
|
||||
const index = list.indexOf(target)
|
||||
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
if (changeSibling) {
|
||||
const before = list[index - 1];
|
||||
const after = list[index + 1];
|
||||
before && (before.nextSibling = after);
|
||||
after && (after.previousSibling = before);
|
||||
}
|
||||
list.splice(index, 1);
|
||||
if (index < 0) {
|
||||
return
|
||||
}
|
||||
if (changeSibling) {
|
||||
const before = list[index - 1]
|
||||
const after = list[index + 1]
|
||||
before && (before.nextSibling = after)
|
||||
after && (after.previousSibling = before)
|
||||
}
|
||||
list.splice(index, 1)
|
||||
}
|
||||
|
||||
|
||||
export function remove(target, list) {
|
||||
const index = list.indexOf(target);
|
||||
const index = list.indexOf(target)
|
||||
|
||||
if (index < 0) {
|
||||
return;
|
||||
}
|
||||
if (index < 0) {
|
||||
return
|
||||
}
|
||||
|
||||
const before = list[index - 1];
|
||||
const after = list[index + 1];
|
||||
before && (before.nextSibling = after);
|
||||
after && (after.previousSibling = before);
|
||||
const before = list[index - 1]
|
||||
const after = list[index + 1]
|
||||
before && (before.nextSibling = after)
|
||||
after && (after.previousSibling = before)
|
||||
|
||||
list.splice(index, 1);
|
||||
list.splice(index, 1)
|
||||
}
|
||||
|
||||
export function linkParent(node, parent) {
|
||||
node.parentNode = parent;
|
||||
if (parent.docId) {
|
||||
node.docId = parent.docId;
|
||||
node.ownerDocument = parent.ownerDocument;
|
||||
node.ownerDocument.nodeMap[node.nodeId] = node;
|
||||
node.depth = parent.depth + 1;
|
||||
}
|
||||
node.childNodes.forEach(child => {
|
||||
linkParent(child, node);
|
||||
});
|
||||
node.parentNode = parent
|
||||
if (parent.docId) {
|
||||
node.docId = parent.docId
|
||||
node.ownerDocument = parent.ownerDocument
|
||||
node.ownerDocument.nodeMap[node.nodeId] = node
|
||||
node.depth = parent.depth + 1
|
||||
}
|
||||
node.childNodes.forEach(child => {
|
||||
linkParent(child, node)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
export function nextElement(node) {
|
||||
while (node) {
|
||||
if (node.nodeType === 1) {
|
||||
return node;
|
||||
}
|
||||
node = node.nextSibling;
|
||||
}
|
||||
while (node) {
|
||||
if (node.nodeType === 1) {
|
||||
return node
|
||||
}
|
||||
node = node.nextSibling
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function previousElement(node) {
|
||||
while (node) {
|
||||
if (node.nodeType === 1) {
|
||||
return node;
|
||||
}
|
||||
node = node.previousSibling;
|
||||
}
|
||||
}
|
||||
while (node) {
|
||||
if (node.nodeType === 1) {
|
||||
return node
|
||||
}
|
||||
node = node.previousSibling
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"name": "omi",
|
||||
"main": "src/omi.d.ts",
|
||||
"version": false
|
||||
}
|
Loading…
Reference in New Issue