@chamn/engine 0.0.2 → 0.0.4

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/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.0.4](https://github.com/ByteCrazy/chameleon/compare/v0.0.3...v0.0.4) (2023-03-27)
7
+
8
+ ### 🐛 Bug Fixes | Bug 修复
9
+
10
+ * **engine:** 🐛 fixed engine d.ts path not correct problem ([fb20ca6](https://github.com/ByteCrazy/chameleon/commit/fb20ca604fff4e85b0264eff6383154ecfefd437))
11
+
6
12
  ## [0.0.2](https://github.com/ByteCrazy/chameleon/compare/v0.0.1...v0.0.2) (2023-03-27)
7
13
 
8
14
  ### 🐛 Bug Fixes | Bug 修复
package/build.config.js CHANGED
@@ -21,8 +21,9 @@ if (process.env.ANALYZE) {
21
21
 
22
22
  const mainConfig = {
23
23
  libMode: process.env.BUILD_TYPE !== 'APP',
24
- entry: './src/Engine.tsx',
24
+ entry: './src/index.tsx',
25
25
  libName: 'CEngine',
26
+ fileName: 'index',
26
27
  external: ['react', 'react-dom'],
27
28
  global: {
28
29
  react: 'React',
@@ -210,4 +210,4 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho
210
210
  originData: ${JSON.stringify(t)}`):new Error(`${JSON.stringify(t)}
211
211
  data struct format is invalidate`);return i},Jo=e=>{const{data:t,message:r,throwError:n,dataStruct:i}=e;return eC(({data:a})=>{try{return $f(a,i),{isValidate:!0}}catch(o){let s=o;return o instanceof Af&&(s=o.failures().map(u=>`\u3010${u.path.join(".")}\u3011: ${u.message}
212
212
  `)),{isValidate:!1,message:s,error:o}}})({data:t,message:r,throwError:n})};var Ei=(e=>(e.ROOT_CONTAINER="RootContainer",e))(Ei||{});const tC=se({type:Ge(St.FUNCTION),value:D()}),rC=Go(Lf(Er,["componentName"]),se({componentName:Ge("RootContainer")}));function nC(e){return{all:e=e||new Map,on:function(t,r){var n=e.get(t);n?n.push(r):e.set(t,[r])},off:function(t,r){var n=e.get(t);n&&(r?n.splice(n.indexOf(r)>>>0,1):e.set(t,[]))},emit:function(t,r){var n=e.get(t);n&&n.slice().map(function(i){i(r)}),(n=e.get("*"))&&n.slice().map(function(i){i(t,r)})}}}const gn=nC(),iC=(e,t)=>{const r={...e,value:[]},n=e.value;let i=new Zt([]);return t&&(i=t.materialsMode||new Zt([])),n&&(xe(n)?r.value=n.map(a=>new ge(a,{parent:t,materials:i})):Ke(n)&&r.value.push(new ge(n,{parent:t,materials:i}))),r};class Pr{constructor(t,r){q(this,"nodeType","SLOT"),q(this,"rawData"),q(this,"parent"),q(this,"emitter",gn),q(this,"data"),q(this,"id"),q(this,"materialsMode"),this.parent=(r==null?void 0:r.parent)||null,this.rawData=t;const n=(r==null?void 0:r.materials)||new Zt([]);this.materialsMode=n,this.id=or(),this.data=iC(t,this)}get value(){return this.data}export(t){const r=this.data,n=i=>{if(i instanceof ge)return i.export(t);if(Ke(i)){const a={};return Object.keys(i||{}).forEach(o=>{a[o]=n(i[o])}),a}return xe(i)?i.map(a=>n(a)):(t==="design"&&delete i.id,i)};return n(r)}}const zf=e=>{let t=[];return e.forEach(r=>{const n=r;n.type?n.type===eo.SINGLE?t.push(n.content):n.type===eo.GROUP&&(t=[...t,...zf(n.content)]):t.push(r)}),t},to=(e,t,r)=>{if(e.type)return e.type===St.SLOT?new Pr(e,{parent:t,materials:r}):e;if(Ke(e)){const n={};return Object.keys(e).forEach(i=>{n[i]=ro(e[i],t,r)}),n}else return Array.isArray(e)?e.map(n=>to(n,t,r)):e},ro=(e,t,r)=>Ke(e)?to(e,t,r):xe(e)?e.map(n=>to(n,t,r)):e;class zt{constructor(t,r,n){q(this,"nodeType","PROP"),q(this,"rawData"),q(this,"parent"),q(this,"emitter",gn),q(this,"data"),q(this,"name"),q(this,"materialsMode");const i=(n==null?void 0:n.materials)||new Zt([]);this.materialsMode=i,this.parent=n==null?void 0:n.parent,this.rawData=r,this.name=t,this.data=ro(r,this,i)}isIncludeSlot(){return!1}isIncludeExpression(){return!1}get value(){return this.data}updateValue(t){const r=this.data;this.data=ro(t!=null?t:r,this,this.materialsMode),this.emitter.emit("onPropChange",{value:this.data,preValue:r,node:this}),this.parent&&!(this.parent instanceof Pr)&&this.emitter.emit("onNodeChange",{value:this.parent.value,preValue:this.parent.value,node:this.parent})}get material(){const t=this.parent;if(t instanceof ge){const r=t.material;return zf((r==null?void 0:r.value.props)||[]).find(n=>n.name===this.name)}else return null}export(t){const r=this.data,n=i=>{if(i instanceof zt||i instanceof Pr||i instanceof ge)return i.export(t);if(xe(i))return i.map(a=>n(a));if(Ke(i)){const a={};return Object.keys(i||{}).forEach(o=>{a[o]=n(i[o])}),a}return i};return n(r)}}const aC=e=>{if(typeof e=="string")return!0;Jo({data:e,dataStruct:Er,throwError:!0})},gc=(e,t,r=new Zt([]))=>{var n;if(typeof e=="string")return e;const i={...e,id:(n=e.id)!=null?n:or(),children:[],props:{},configure:Ff(e.configure||{},{propsSetter:{},advanceSetter:{}})},a=Object.keys(e.props||{});return a.length&&a.forEach(o=>{var s;const u=(s=e.props)==null?void 0:s[o];if(u instanceof zt){i.props[o]=u;return}i.props[o]=new zt(o,u||"",{parent:t,materials:r})}),e.children&&(Array.isArray(e.children)?i.children=e.children.map(o=>{if(o instanceof ge)return o;if(Ke(o)){const s=o;return new ge(s,{parent:t,materials:r})}else return o}):(e.children instanceof ge&&(i.children=[e.children]),i.children=[new ge(e.children,{parent:t,materials:r})])),i};class ge{constructor(t,r){q(this,"nodeType","NODE"),q(this,"rawData"),q(this,"data"),q(this,"emitter",gn),q(this,"parent"),q(this,"materialsModel"),q(this,"listenerHandle"),q(this,"onChangeCbQueue"),this.rawData=JSON.parse(JSON.stringify(t)),aC(t);const n=(r==null?void 0:r.materials)||new Zt([]);this.parent=(r==null?void 0:r.parent)||null,this.materialsModel=n,this.data=gc(t,this,n),this.listenerHandle=[],this.onChangeCbQueue=[],this.registerListener()}registerListener(){const t=r=>{const{node:n}=r;n===this&&n.id===this.id&&this.onChangeCbQueue.forEach(i=>i(r))};this.emitter.on("onNodeChange",t),this.listenerHandle.push(()=>{this.emitter.off("onNodeChange",t)})}onChange(t){return this.onChangeCbQueue.push(t),()=>{this.onChangeCbQueue=this.onChangeCbQueue.filter(r=>r!==t)}}destroy(){this.listenerHandle.forEach(t=>t())}get id(){return this.data.id}get value(){return this.data}clone(t){const r={...this.export("design"),id:t||or()};return new ge(r,{materials:this.materialsModel})}updateValue(t){const r=this.data,n={...this.data,...t};this.data=gc(n,this),this.emitter.emit("onNodeChange",{value:n,preValue:r,node:this})}contains(t){return Zo(this,t)}get props(){return this.data.props}get material(){const t=this.materialsModel;return t==null?void 0:t.findByComponentName(this.data.componentName)}getPlainProps(){const t=this.data,r={};return Object.keys(t.props||{}).forEach(n=>{r[n]=t.props[n].export("design")}),r}export(t){var r;const n=this.data;if(typeof n=="string")return n;const i={};Object.keys(n.props||{}).forEach(l=>{i[l]=n.props[l].export(t)});const a=(r=n.children)==null?void 0:r.map(l=>l instanceof ge?l.export(t):l),o=n.configure||{},s=o.propsSetter||{},u={};Object.keys(s).forEach(l=>{const f=hf(s,l,!1);f&&(u[l]=f)}),o.propsSetter=u,this.material&&this.materialsModel.usedMaterials.push(this.material);let c={...n,configure:o,props:i,children:a};return t==="design"&&delete c.id,c=Qo(c),c}}const vc=(e,t,r)=>{const n={...e,id:or(),props:{},componentName:Ei.ROOT_CONTAINER,children:[],configure:Ff(e.configure||{},{propsSetter:{},advanceSetter:{}})};let i=[];xe(e.children)?i=e.children.map(o=>o instanceof ge?o:Ke(o)?new ge(o,{parent:t,materials:r}):o):e.children instanceof ge?i.push(e.children):e.children&&Ke(e.children)&&i.push(new ge(e.children,{parent:t,materials:r}));const a=Object.keys(e.props||{});return a.length&&a.forEach(o=>{var s;const u=(s=e.props)==null?void 0:s[o];u instanceof zt?n.props[o]=u:n.props[o]=new zt(o,u||"",{parent:t,materials:r})}),n.children=i,n};class cn{constructor(t,{parent:r,materials:n}){q(this,"rawData"),q(this,"data"),q(this,"nodeType",Ei.ROOT_CONTAINER),q(this,"emitter",gn),q(this,"materialsModel"),q(this,"listenerHandle"),q(this,"onChangeCbQueue"),q(this,"parent"),this.materialsModel=n,this.rawData=JSON.parse(JSON.stringify(t)),this.data=vc(t,this,n),this.listenerHandle=[],this.onChangeCbQueue=[],this.registerListener(),this.parent=r}registerListener(){const t=r=>{const{node:n}=r;n===this&&n.id===this.id&&this.onChangeCbQueue.forEach(i=>i(r))};this.emitter.on("onNodeChange",t),this.listenerHandle.push(()=>{this.emitter.off("onNodeChange",t)})}onChange(t){return this.onChangeCbQueue.push(t),()=>{this.onChangeCbQueue=this.onChangeCbQueue.filter(r=>r!==t)}}get id(){return this.data.id}get value(){return this.data}get props(){return this.data.props}get material(){const t=this.materialsModel;return t==null?void 0:t.findByComponentName(this.data.componentName)}updateValue(t){const r=this.data,n={...this.data,...t};this.data=vc(n,this,this.materialsModel),this.emitter.emit("onNodeChange",{value:this.data,preValue:r,node:this})}contains(t){return Zo(this,t)}export(t=Yo.SAVE){var r;const n=this.data,i={};Object.keys(n.props||{}).forEach(u=>{i[u]=n.props[u].export(t)});const a=((r=n.children)==null?void 0:r.map(u=>{var c;return(c=u==null?void 0:u.export)==null?void 0:c.call(u,t)}))||[],o={...n,props:i,children:a.filter(u=>u)};let s=kf(o,["id"]);return s=Qo(s),s}getPlainProps(){const t=this.data,r={};return Object.keys(t.props||{}).forEach(n=>{r[n]=t.props[n].export("design")}),r}destroy(){this.listenerHandle.forEach(t=>t())}clone(t){const r={...this.export("design"),id:t||or()};return new cn(r,{materials:this.materialsModel,parent:null})}}const or=()=>Math.random().toString(32).slice(3,9),Qo=e=>Tx(e,t=>Ke(t)?!Object.keys(t).length:xe(t)?!t.length:!t);function Zo(e,t){const r=[e];for(;r.length;){const n=r.shift();if((n==null?void 0:n.id)===t)return n;const i=(n==null?void 0:n.props)||{},a=s=>{if(s instanceof ge){r.push(s);return}if(s instanceof Pr&&a(s.value.value),s instanceof zt){a(s.value);return}if(Ke(s)){const u=s;Object.keys(u).map(c=>{a(u[c])});return}if(xe(s)){s.forEach(u=>{a(u)});return}};a(i);const o=(n==null?void 0:n.value.children.filter(s=>s instanceof ge))||[];r.push(...o)}return null}const oC=e=>{const t=Ef(e),r=t.snippets;return delete t.snippets,t.snippets=r.map(n=>({...t,...n,id:n.id||`${e.componentName}-${or()}`,title:n.title||e.title,category:n.category||e.category,tags:[...n.tags||[],...e.tags||[]],groupName:n.groupName||e.groupName,snapshot:n.snapshot||e.icon,snapshotText:n.snapshotText,schema:{...n.schema,componentName:n.schema.componentName||e.componentName}})),t};class sC{constructor(t){q(this,"rawData"),q(this,"data"),this.rawData=t,this.data=oC(t)}get value(){return this.data}get rawValue(){return this.rawData}get componentName(){return this.data.componentName}get snippets(){return this.data.snippets}getSnippetById(t){return this.data.snippets.find(r=>r.id===t)}}const uC=e=>{if(!xe(e))throw new Error("Materials must be a array");return e.map(t=>new sC(t))},cC=e=>{e==null||e.forEach(t=>{Jo({data:t,dataStruct:Zx,throwError:!0})})};class Zt{constructor(t){q(this,"rawData"),q(this,"data"),q(this,"usedMaterials",[]),this.rawData=t,cC(t),this.data=uC(t)}findByComponentName(t){return this.data.find(r=>r.componentName===t)}findSnippetById(t){const r=[...this.data];let n=null;for(;!n&&r.length;){const i=r.pop();n=i==null?void 0:i.getSnippetById(t)}return n}getAllSnippets(){let t=this.data.reduce((a,o)=>(a.push(...o.snippets),a),[]);const r=[],n={default:[]};t=t.sort((a,o)=>(a.category||"")>(o.category||"")?1:-1),t.forEach(a=>{const o=a.groupName||"default";r.includes(o)||(r.push(o),n[o]=[]),n[o].push(a)});const i=[];return r.forEach(a=>{const o=["default"],s={default:[]},u=n[a];if(u.length!==0){u.forEach(f=>{const d=f.category||"default";o.includes(d)||(o.push(d),s[d]=[]),s[d].push(f)});const c=[];o.forEach(f=>{s[f].length&&c.push({name:f,list:s[f]})});const l={name:a,list:c};i.push(l)}}),i}get value(){return this.data}get rawValue(){return this.rawData}}const lC=se({version:D(),name:D(),css:V(D()),renderType:V(Ue([Ge("COMPONENT"),Ge("PAGE")])),methods:V(we(tC)),componentsMeta:we(Go(se({componentName:D()}),Ko)),thirdLibs:V(Ux),componentsTree:rC,assets:V(we(Re()))}),fC=e=>(Jo({data:e,dataStruct:lC,throwError:!0}),e),aa=(e,t,r)=>({...e,componentsTree:new cn(e.componentsTree,{parent:t,materials:r})});class ri{constructor(t,r){q(this,"nodeType","PAGE"),q(this,"rawData"),q(this,"emitter",gn),q(this,"data"),q(this,"parent"),q(this,"materialsModel"),q(this,"assetPackagesList"),fC(t),this.assetPackagesList=(r==null?void 0:r.assetPackagesList)||[],this.rawData=JSON.parse(JSON.stringify(t)),this.materialsModel=new Zt((r==null?void 0:r.materials)||[]),this.data=aa(t,this,this.materialsModel)}updatePage(t){const r=this.data;this.rawData=JSON.parse(JSON.stringify(t)),this.data=aa(t,this,this.materialsModel),this.emitter.emit("onPageChange",{value:this.data,preValue:r,node:this})}reloadPage(t){const r=this.data;this.rawData=JSON.parse(JSON.stringify(t)),this.data=aa(t,this,this.materialsModel),this.emitter.emit("onReloadPage",{value:this.data,preValue:r,node:this})}get value(){return this.data}getNode(t){const r=this.data.componentsTree;return Zo(r,t)}addNode(t,r,n="AFTER"){var i,a,o;if(n==="AFTER"||n==="BEFORE"){const s=r.parent;if(s===null&&r instanceof cn)return console.warn("Not found parent node"),!1;if(s instanceof zt)return console.warn("CProp can not add node"),!1;if(s instanceof Pr){const c=s.value.value,l=(i=c.findIndex(f=>f===r))!=null?i:-1;return l>=0?(n==="BEFORE"?c.splice(l,0,t):c.splice(l+1,0,t),t.parent=s,(a=s.parent)==null||a.updateValue(),!0):!1}if(s instanceof ri)return!1;const u=(o=s==null?void 0:s.value.children.findIndex(c=>c===r))!=null?o:-1;return u>=0?(n==="BEFORE"?s==null||s.value.children.splice(u,0,t):s==null||s.value.children.splice(u+1,0,t),t.parent=s,s==null||s.updateValue(),!0):(console.warn("Not found target node"),!1)}if(n==="CHILD_START")return r.value.children.unshift(t),t.parent=r,r.updateValue(),!0;if(n==="CHILD_END")return r.value.children.push(t),t.parent=r,r.updateValue(),!0;if(Ke(n)){const s=n;if(s.type==="CHILD"){const u=s.pos,c=s.index||0;return u==="BEFORE"?r==null||r.value.children.splice(c,0,t):r==null||r.value.children.splice(c+1,0,t),t.parent=r,r.updateValue(),!0}else console.warn("Can not parse pos obj")}return!1}createNode(t){return delete t.id,new ge(t,{parent:null,materials:this.materialsModel})}addNodeById(t,r,n="AFTER"){const i=this.getNode(r);return i?this.addNode(t,i,n):(console.warn(`Not find a node by ${r}, pls check it`),!1)}copyNode(t){const r=t.export("design");r.id=or();const n=new ge(r,{parent:t.parent,materials:this.materialsModel});return this.addNode(n,t,"AFTER"),n}copyNodeById(t){const r=this.getNode(t);return r&&r instanceof ge?this.copyNode(r):!1}moveNode(t,r,n){this.deleteNode(t);let i=r;return["AFTER","BEFORE"].includes(n)&&(i=r.parent),t.parent=i,this.addNode(t,r,n)}moveNodeById(t,r,n){const i=this.getNode(t),a=this.getNode(r);return i&&a&&i instanceof ge&&a instanceof ge?this.moveNode(i,a,n):!1}deleteNode(t){var r;const n=t.parent;if(!n)throw new Error("parent node is null or undefined, pls check it");if(n instanceof Pr){const i=n.value.value,a=i.findIndex(s=>s===t),o=i[a];return i.splice(a,1),(r=n.parent)==null||r.updateValue(),o}if(n instanceof ge||n instanceof cn){const i=n.value.children,a=i.findIndex(s=>s===t),o=i[a];return i.splice(a,1),n.updateValue(),o}}deleteNodeById(t){const r=this.getNode(t);if(r)return this.deleteNode(r)}export(t=Yo.SAVE){var r;const n=this.data.componentsTree.export(t),i=this.assetPackagesList,a=[],o=this.materialsModel.usedMaterials.map(u=>{const c=i.find(l=>{var f;return l.package===((f=u.value.npm)==null?void 0:f.package)});return c&&a.push(c),{componentName:u.componentName,...Ef(u.value.npm||{})}}).filter(u=>{if(u.componentName&&u.package&&u.version)return!0});this.materialsModel.usedMaterials=[];let s={...this.data,componentsTree:Qo(n),componentsMeta:o,thirdLibs:this.data.thirdLibs,assets:[]};return(r=this.data.thirdLibs)==null||r.forEach(u=>{const c=i.find(l=>{l.package,l.package});c&&a.push(c)}),s.assets=Lx(a,u=>u.package),s=kf(s,["id"]),JSON.parse(JSON.stringify(s))}}const dC={version:"1.0.0",name:"EmptyPage",componentsMeta:[],componentsTree:{componentName:Ei.ROOT_CONTAINER,props:{},children:[]}};class hC extends ke.default.Component{constructor(r){super(r);K(this,"currentSelectNode");K(this,"pluginManager");K(this,"workbenchRef",ke.default.createRef());K(this,"pageSchema");K(this,"pageModel");K(this,"material");K(this,"emitter");K(this,"updatePage",r=>{this.emitter.emit("updatePage"),console.log(r)});K(this,"updateDesignerAssets",r=>{console.log("updateDesignerAssets",r)});K(this,"updateMaterial",r=>{this.emitter.emit("updateMaterial"),console.log(r)});K(this,"refresh",()=>{this.emitter.emit("refresh"),console.log("refresh engine")});K(this,"getWorkbench",()=>this.workbenchRef.current);this.pageSchema=r.schema,this.material=r.material,this.currentSelectNode=null,window.__CHAMELEON_ENG__=this;try{this.pageModel=new ri(this.pageSchema,{materials:this.material||[],assetPackagesList:r.assetPackagesList||[]})}catch(n){console.error(n),this.pageModel=new ri(dC)}this.emitter=Yn()}updateCurrentSelectNode(r){this.currentSelectNode=r,this.emitter.emit("onSelectNodeChange",{node:r})}async componentDidMount(){var i,a,o,s;window.__C_ENGINE__=this;const r=this.props.plugins;this.pluginManager=new Wy({engine:this,getWorkbench:()=>this.workbenchRef.current,emitter:this.emitter,pageModel:this.pageModel,i18n:Zl,assets:this.props.assets||[]}),(a=(i=this.props).beforePluginRun)==null||a.call(i,{pluginManager:this.pluginManager});const n=r.map(u=>this.pluginManager.add(u));await Promise.all(n),this.pageModel.emitter.on("onReloadPage",()=>{var c;if(!this.currentSelectNode)return;const u=this.pageModel.getNode((c=this.currentSelectNode)==null?void 0:c.id);u&&this.updateCurrentSelectNode(u)}),(s=(o=this.props).onReady)==null||s.call(o,{pluginManager:this.pluginManager,engine:this})}getActiveNode(){var n;if(!((n=this.currentSelectNode)!=null&&n.id))return null;const r=this.pageModel.getNode(this.currentSelectNode.id);return this.currentSelectNode=r,r}render(){return I("div",{className:ay.engineContainer,children:I(ny,{ref:this.workbenchRef,emitter:this.emitter})})}}module.exports=hC;
213
- //# sourceMappingURL=CEngine.cjs.js.map
213
+ //# sourceMappingURL=index.cjs.js.map