Skip to content

Commit

Permalink
- Version: 1.1.6 Build 20240115
Browse files Browse the repository at this point in the history
	- 优化构建脚本。
	- 加入自动移除class前后空格功能。
	- 当dom_tag为空时,为其指定默认tag。
	- 修复dom_attr参数为null或undefined时,会报错的bug。
	- 修复dom_attr参数为字符串时,无法输出html文本的bug。
  • Loading branch information
road0001 committed Jan 15, 2024
1 parent fec81be commit 1101043
Show file tree
Hide file tree
Showing 16 changed files with 177 additions and 156 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
react.html
react.test.js
dist/
npm/
npm/
node_modules/
18 changes: 18 additions & 0 deletions VERSION.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,54 @@
# JQuery DOM

- Version: 1.1.6 Build 20240115
- 优化构建脚本。
- 加入自动移除class前后空格功能。
- 当dom_tag为空时,为其指定默认tag。
- 修复dom_attr参数为null或undefined时,会报错的bug。
- 修复dom_attr参数为字符串时,无法输出html文本的bug。

- Version: 1.1.5 Build 20240112
- 更新文档。
- 加入NPM模块打包发布脚本。
- 修复传入的对象、子项为已被React.createElement封装的对象时报错的bug。

- Version: 1.1.4 Build 20240110
- 加入构建脚本。
- 加入ReactDOMHtml模块导出。
- 修复使用标准参数时无法输出html文本的bug。
- 修复ReactDOMHtml中class为数组时不生效的bug。

- Version: 1.1.3 Build 20240109
- 加入ReactDOMHtml。
- 整理项目资源。
- 优化vueDOMHtml结构,拆分DOMHtml和VueDOMHtml。

- Version: 1.1.2 Build 20240105
- 加入vueDOMHtml功能。

- Version: 1.1.1 Build 20240104
- 修复数组形式插入DOM时无法插入的bug。

- Version: 1.1.0 Build 20231229
- 加入attribute PascalCase→kebab-case转换。
- 优化DOM插入性能。

- Version: 1.0.9 Build 20231228
- 将$更名为jQuery以适配更多场合。
- 加入原生getDOMHtml功能。

- Version: 1.0.9 Build 20231227
- 将getHtml更名为getDOMHtml。
- 加入表格使用tr替代tbody功能。
- 加入dom_tag和dom_attr单层对象写法。
- 更新文档。

- Version: 1.0.8 Build 20231222
- 加入获取生成的HTML功能。

- Version: 1.0.7 Build 20230606
- 加入表格DOM的语法糖。
- 修复部分情况下,元素中children会出现重复内容的bug。

- Version: 1.0.6 Build 20210514
- 修复部分情况下,appendDOM中直接传递对象时无法添加元素的bug。
5 changes: 1 addition & 4 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
@echo off
mkdir dist
move /y *.min.js dist\
copy /y react.extensions.dom.module.js dist\react-extensions-dom-module.js
copy /y react.extensions.dom.module.js npm\index.js
node build.js
pause
93 changes: 93 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const fs=require(`fs`);
const UglifyJS = require(`uglify-js`);

String.prototype.replaceAll=function(org,tgt){
return this.split(org).join(tgt);
}

//创建文件夹
try{
fs.mkdirSync(`dist`);
fs.mkdirSync(`npm`);
}catch(e){}

// 压缩非模块脚本
const uglifyList=[
`jquery.extensions.dom`,
`html.dom`,
`vue.extensions.dom`,
`react.extensions.dom`,
]
for(let s of uglifyList){
try{
let origin=fs.readFileSync(`${s}.js`,`utf-8`);
let target=UglifyJS.minify(origin);
if (target.error) {
console.error(`Error in minifying JS file: ${target.error}`);
} else {
fs.writeFileSync(`dist/${s}.min.js`, target.code, {encoding:`utf-8`});
console.log(`Compression ${s} completed successfully!`);
}
}catch(e){
console.error(`An error occurred while compressing the JS file: ${e}`);
}
}

// 处理模块脚本
const moduleOriginTag=`/* --- FOR MODULE --- */`;
const moduleTargetTag=`/* MODULE INSERT */`;
const moduleList=[
{origin:`react.extensions.dom`,target:`react.extensions.dom.module`,output:`react-extensions-dom-module`},
]
for(let m of moduleList){
try{
let origin=fs.readFileSync(`${m.origin}.js`,`utf-8`);
let target=fs.readFileSync(`${m.target}.m`,`utf-8`);
let originCode=origin.split(moduleOriginTag)[1];
let targetCode=target.replaceAll(moduleTargetTag, originCode).trim();
fs.writeFileSync(`dist/${m.output}.js`, targetCode, {encoding:`utf-8`});
fs.writeFileSync(`npm/index.js`, targetCode, {encoding:`utf-8`});
console.log(`Output module ${m.output} completed successfully!`);
}catch(e){
console.error(`An error occurred while output the JS module file: ${e}`);
}
}

// 创建NPM包
// 读取VERSION.md获取版本号
let versionMd=fs.readFileSync(`VERSION.md`,`utf-8`);
let versionSplit=versionMd.split(`\n`);
let version=``;
for(let v of versionSplit){
if(v.includes(`Version: `)){
version=v.split(` `)[2];
break;
}
}
//创建package.json
const packageJson={
name: `react-extensions-dom`,
version: version,
description: `A plugin for React, use object instead of JSX to manage React elements.`,
main: `index.js`,
scripts: {
test: `echo "Error: no test specified" && exit 1`,
},
repository: {
type: `git`,
url: `git+https://github.com/road0001/JQueryDOM.git`,
},
author: ``,
license: `MIT`,
bugs: {
url: `https://github.com/road0001/JQueryDOM/issues`,
},
homepage: `https://github.com/road0001/JQueryDOM#readme`,
}
//写入package.json
try{
fs.writeFileSync(`npm/package.json`, JSON.stringify(packageJson, null, `\t`), {encoding:`utf-8`});
console.log(`Output package.json completed successfully!`);
}catch(e){
console.error(`An error occurred while output the package.json file: ${e}`);
}
2 changes: 2 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
npm install uglify-js --save-dev
node build.js
2 changes: 1 addition & 1 deletion html.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ getDOMHtml=DOMHtml=function(dom_tag,dom_attr,dom_html,dom_fix={}){
dom_tag=dom_tag.toKebabCase();
if(typeof dom_attr==`object`){
if(typeof dom_attr.class==`object` && dom_attr.class.length){
dom_attr.class=dom_attr.class.join(` `);
dom_attr.class=dom_attr.class.join(` `).trim();
}
if(typeof dom_attr.style==`object`){
let styleList=[];
Expand Down
3 changes: 3 additions & 0 deletions install.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
call npm install uglify-js --save-dev
pause
1 change: 1 addition & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm install uglify-js --save-dev
2 changes: 1 addition & 1 deletion jquery.extensions.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if(typeof jQuery===`function`){
//Class数组化处理
case `class`:
if(typeof cur_dom_attr==`object`){
cur_dom_attr=cur_dom_attr.join(` `);
cur_dom_attr=cur_dom_attr.join(` `).trim();
}
break;

Expand Down
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"uglify-js": "^3.17.4"
}
}
1 change: 0 additions & 1 deletion publish_npm.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@echo off
mkdir npm
cd npm
npm login
npm publish
Expand Down
3 changes: 3 additions & 0 deletions publish_npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cd npm
npm login
npm publish
19 changes: 16 additions & 3 deletions react.extensions.dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ function reactDOMHtml(dom_tag,dom_attr,dom_html,dom_html_after){
}else{
return null;
}
/* --- FOR MODULE --- */
/* --- MODULE BEGIN --- */
//dom_tag为数组时,批量为母元素添加元素
const _fragment=Symbol.for('react.fragment');
if(typeof dom_tag==`object` && dom_tag.length!=undefined){
let domFullObject=[];
let default_children={
Expand All @@ -24,13 +27,21 @@ function reactDOMHtml(dom_tag,dom_attr,dom_html,dom_html_after){
domFullObject.push(reactDOMHtml(cur,undefined,undefined));
}
}
return rCreateEl(Symbol.for('react.fragment'),null,domFullObject);
return rCreateEl(_fragment,null,domFullObject); //顶层元素类似<></>形式
}
//dom_tag为对象时,和普通情况一样
if(typeof dom_tag==`object` && dom_tag.length==undefined){
dom_attr=dom_tag.attr || dom_tag;
dom_tag=dom_tag.tag;
}
if(!dom_tag){
dom_tag=_fragment;
}
if(!dom_attr){
dom_attr={};
}else if(typeof dom_attr==`string`){ // 例:rDOM(`div`, `This is Div`)
dom_attr={html:dom_attr};
}
if(dom_attr.$$typeof){
return dom_attr; // 已被React.createElement封装的情况下,直接返回此对象
}
Expand Down Expand Up @@ -58,7 +69,7 @@ function reactDOMHtml(dom_tag,dom_attr,dom_html,dom_html_after){
}
}
if(typeof dom_attr_fix.className==`object` && dom_attr_fix.className.length){
dom_attr_fix.className=dom_attr_fix.className.join(` `);
dom_attr_fix.className=dom_attr_fix.className.join(` `).trim();
}
dom_attr=dom_attr_fix;

Expand Down Expand Up @@ -143,4 +154,6 @@ function reactDOMHtml(dom_tag,dom_attr,dom_html,dom_html_after){
}
function rDOM(dom_tag,dom_attr,dom_html,dom_html_after){
return reactDOMHtml(dom_tag,dom_attr,dom_html,dom_html_after);
}
}
/* --- MODULE END --- */
/* --- FOR MODULE --- */
Loading

0 comments on commit 1101043

Please sign in to comment.