@soonspacejs/plugin-flow 2.13.2 → 2.13.5

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.
@@ -1,8 +1,9 @@
1
+ import { EventDispatcher } from 'three';
1
2
  import SoonSpace from 'soonspacejs';
2
3
  import { Edge } from './edges';
3
4
  import { Node } from './nodes';
4
- import { FlowType, NodeGlobalType } from './types';
5
- declare class FlowParser {
5
+ import { FlowParserEventMap, FlowType, NodeGlobalType } from './types';
6
+ declare class FlowParser extends EventDispatcher<FlowParserEventMap> {
6
7
  ssp: SoonSpace;
7
8
  flow: FlowType;
8
9
  nodes: Node[];
@@ -27,6 +28,10 @@ declare class FlowParser {
27
28
  * @param ctx
28
29
  */
29
30
  run(global?: NodeGlobalType): Promise<void>;
31
+ /**
32
+ * 调试流程
33
+ */
34
+ debug(global?: NodeGlobalType, time?: number): Promise<void>;
30
35
  /**
31
36
  * 停止流程
32
37
  */
@@ -35,5 +40,6 @@ declare class FlowParser {
35
40
  * 清理流程
36
41
  */
37
42
  cleanup(): void;
43
+ dispose(): void;
38
44
  }
39
45
  export { FlowParser, };
@@ -1,3 +1,4 @@
1
1
  export { FlowParser, } from './FlowParser';
2
2
  export { ComponentFlowParser, } from './ComponentFlowParser';
3
3
  export * from './types';
4
+ export { Node, } from './nodes/Node';
@@ -21,7 +21,7 @@ declare class Node {
21
21
  init(): void;
22
22
  readContext<T = any>(key: string): T | undefined;
23
23
  writeContext(key: string, value: any): void;
24
- findProp(name: string, type: NodePropType['type']): NodePropType | undefined;
24
+ findProp(name: string, type: NodePropType['type'] | NodePropType['type'][]): undefined | NodePropType;
25
25
  /**
26
26
  * 等待前置节点执行完毕
27
27
  */
@@ -41,5 +41,6 @@ declare class Node {
41
41
  */
42
42
  run(global: NodeGlobalType): Promise<void>;
43
43
  cleanup(): void;
44
+ protected getValue(prop: NodePropType): any;
44
45
  }
45
46
  export { Node, };
@@ -89,3 +89,4 @@ export type NodeGlobalType = {
89
89
  getComponentAnimations?: (currentNode: Node, object: Object3D, animationId: string) => Promise<IComponentAnimation[] | null>;
90
90
  [s: symbol]: any;
91
91
  };
92
+ export type FlowParserEventMap = {};
@@ -1,12 +1,11 @@
1
1
  import { Object3D } from 'three';
2
- import SoonSpace, { Model } from 'soonspacejs';
2
+ import SoonSpace, { BaseObject3D } from 'soonspacejs';
3
3
  import { FlowParser } from './FlowParser';
4
4
  import { Node } from './nodes';
5
5
  import { NodeType } from './types';
6
6
  export declare function parseNodeByType(parser: FlowParser, node: NodeType): Node;
7
7
  export declare function parseValue<T = any>(value: string): T;
8
8
  export declare function waitFor(fn: () => Promise<void>, wait: boolean): Promise<void>;
9
- export declare function getModelByUuid(ssp: SoonSpace, uuid: string): Model | null;
10
- export declare function getModelByUuids(ssp: SoonSpace, uuids: string[]): Model[];
11
- export declare function getModelByFamilyId(ssp: SoonSpace, family: string): Model | null;
9
+ export declare function getObjectByIds(ssp: SoonSpace, ids: string[]): BaseObject3D[];
12
10
  export declare function getMeshByUserDataUuid(object: Object3D, uuid: string): Object3D | null;
11
+ export declare function filterNodes(prevNode: Node, result: Node[]): Node[];
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- import t from"soonspacejs";import{AnimationPlayer as s}from"umanager-animation-parser";class e{constructor(t){this.id=t.id,this.source=t.source,this.target=t.target}}let i=0;class n{constructor(t,s){this.prevNodes=[],this.postNodes=[],this.execOrder=0,this.cleanSets=new Set,this.onBefore=null,this.onAfter=null,this.parser=t,this.ssp=t.ssp,this.id=s.id,this.type=s.type,this.props=s.props,this.init()}init(){this.ctx={},this.promise=new Promise(((t,s)=>{this.resolve=t,this.reject=s}))}readContext(t){return this.ctx[t]}writeContext(t,s){this.ctx[t]=s}findProp(t,s){return this.props.find((e=>e.name===t&&e.type===s))}async waitForPrevNodes(){await Promise.all(this.prevNodes.map((t=>t.promise)))}mergeContext(){this.prevNodes.forEach((t=>{Object.assign(this.ctx,t.ctx)}))}async exec(t){}async run(t){var s,e,n,o;await(null===(e=null!==(s=this.onBefore)&&void 0!==s?s:this.parser.onNodeBefore)||void 0===e?void 0:e(this)),await this.waitForPrevNodes(),this.mergeContext();try{this.execOrder=++i,await this.exec(t).then(this.resolve)}catch(t){throw this.reject(t),t}await(null===(o=null!==(n=this.onAfter)&&void 0!==n?n:this.parser.onNodeAfter)||void 0===o?void 0:o(this))}cleanup(){this.cleanSets.forEach((t=>t())),this.cleanSets.clear()}}class o extends n{constructor(t,s){super(t,s)}}var a,c;!function(t){t.LOCAL="LOCAL",t.READ_CTX="READ_CTX",t.WRITE_CTX="WRITE_CTX"}(a||(a={})),function(t){t.START="START",t.COLOR="COLOR",t.NUMBER="NUMBER",t.HIGHLIGHT="HIGHLIGHT",t.UN_HIGHLIGHT="UN_HIGHLIGHT",t.OPACITY="OPACITY",t.UN_OPACITY="UN_OPACITY",t.EMISSIVE="EMISSIVE",t.UN_EMISSIVE="UN_EMISSIVE",t.MESH="MESH",t.MESHES="MESHES",t.MODEL="MODEL",t.MODELS="MODELS",t.DELAY="DELAY",t.SHOW="SHOW",t.HIDE="HIDE",t.CLIP_ANIMATION="CLIP_ANIMATION",t.UN_CLIP_ANIMATION="UN_CLIP_ANIMATION",t.TWEEN_ANIMATION="TWEEN_ANIMATION",t.UN_TWEEN_ANIMATION="UN_TWEEN_ANIMATION",t.COMPONENT_TWEEN_ANIMATION="COMPONENT_TWEEN_ANIMATION",t.UN_COMPONENT_TWEEN_ANIMATION="UN_COMPONENT_TWEEN_ANIMATION"}(c||(c={}));class r extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("color",a.LOCAL),s=this.findProp("out",a.WRITE_CTX);t&&s&&this.writeContext(k(s.value),k(t.value))}}class h extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("number",a.LOCAL),s=this.findProp("out",a.WRITE_CTX);t&&s&&this.writeContext(k(s.value),k(t.value))}}const{objectHandle:l}=t.utils;class d extends n{constructor(t,s){super(t,s)}filterHighlightObject(t){const s=[];return l(t,(t=>{this.ssp.viewport.scener.selectedObjects.highlight.has(t)||s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX),s=this.findProp("color",a.READ_CTX),e=this.findProp("opacity",a.READ_CTX);if(t&&s&&e){const i=this.readContext(k(t.value)),n=this.readContext(k(s.value)),o=this.readContext(k(e.value));if(i){const t=this.filterHighlightObject(i);this.ssp.highlightShow(t,{color:n,opacity:o}),this.cleanSets.add((()=>{this.ssp.unHighlightShow(t)}))}}}}const{objectHandle:u}=t.utils;class p extends n{constructor(t,s){super(t,s)}filterUnHighlightObject(t){const s=[];return u(t,(t=>{this.ssp.viewport.scener.selectedObjects.highlight.has(t)&&s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX);if(t){const s=this.readContext(k(t.value));if(s){const t=this.filterUnHighlightObject(s);this.ssp.unHighlightShow(t),this.cleanSets.add((()=>{this.ssp.highlightShow(t)}))}}}}const{objectHandle:f}=t.utils;class E extends n{constructor(t,s){super(t,s)}filterOpacityObject(t){const s=[];return f(t,(t=>{this.ssp.viewport.scener.selectedObjects.opacity.has(t)||s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX),s=this.findProp("color",a.READ_CTX),e=this.findProp("opacity",a.READ_CTX);if(t&&s&&e){const i=this.readContext(k(t.value)),n=this.readContext(k(s.value)),o=this.readContext(k(e.value));if(i){const t=this.filterOpacityObject(i);this.ssp.opacityShow(t,{color:n,opacity:o}),this.cleanSets.add((()=>{this.ssp.unOpacityShow(t)}))}}}}const{objectHandle:C}=t.utils;class O extends n{constructor(t,s){super(t,s)}filterUnOpacityObject(t){const s=[];return C(t,(t=>{this.ssp.viewport.scener.selectedObjects.opacity.has(t)&&s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX);if(t){const s=this.readContext(k(t.value));if(s){const t=this.filterUnOpacityObject(s);this.ssp.unOpacityShow(t),this.cleanSets.add((()=>{this.ssp.opacityShow(t)}))}}}}const{objectHandle:v}=t.utils;class T extends n{constructor(t,s){super(t,s)}filterEmissiveObject(t){const s=[];return v(t,(t=>{this.ssp.viewport.scener.selectedObjects.emissive.has(t)||s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX),s=this.findProp("color",a.READ_CTX),e=this.findProp("baseColor",a.READ_CTX),i=this.findProp("minOpacity",a.READ_CTX),n=this.findProp("maxOpacity",a.READ_CTX),o=this.findProp("duration",a.READ_CTX);if(t&&s&&e&&i&&n&&o){const a=this.readContext(k(t.value)),c=this.readContext(k(s.value)),r=this.readContext(k(e.value)),h=this.readContext(k(i.value)),l=this.readContext(k(n.value)),d=this.readContext(k(o.value));if(a){const t=this.filterEmissiveObject(a);this.ssp.emissiveShow(t,{color:c,baseColor:r,minOpacity:h,maxOpacity:l,duration:d}),this.cleanSets.add((()=>{this.ssp.unEmissiveShow(t)}))}}}}const{objectHandle:A}=t.utils;class N extends n{constructor(t,s){super(t,s)}filterUnEmissiveObject(t){const s=[];return A(t,(t=>{this.ssp.viewport.scener.selectedObjects.emissive.has(t)&&s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX);if(t){const s=this.readContext(k(t.value));if(s){const t=this.filterUnEmissiveObject(s);this.ssp.unEmissiveShow(t),this.cleanSets.add((()=>{this.ssp.emissiveShow(t)}))}}}}const I=Symbol("meshCache");class w extends n{constructor(t,s){super(t,s)}async exec(t){var s;const{viewport:{scene:e}}=this.ssp,i=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this))||e;t[I]||(t[I]={});const n=this.findProp("mesh",a.LOCAL),o=this.findProp("out",a.WRITE_CTX);if(n&&o){let s=null;const e=k(n.value),a=k(o.value),c=t[I][e];if(c)return void(s=c);const r=F(i,e);r&&(s=r,t[I][e]=r),this.writeContext(a,s)}}}const _=Symbol("meshesCache");class x extends n{constructor(t,s){super(t,s)}async exec(t){var s;const{viewport:{scene:e}}=this.ssp,i=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this))||e;t[_]||(t[_]={});const n=this.findProp("meshes",a.LOCAL),o=this.findProp("out",a.WRITE_CTX);if(n&&o){const s=[],e=k(n.value),a=k(o.value);e.forEach((e=>{const n=t[_][e];if(n)return void s.push(n);const o=F(i,e);o&&(s.push(o),t[_][e]=o)})),this.writeContext(a,s)}}}class g extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("model",a.LOCAL),s=this.findProp("out",a.WRITE_CTX);if(t&&s){const o=k(t.value),a=k(s.value);this.writeContext(a,(e=this.ssp,i=o,null!==(n=e.getAllModel().find((t=>t.userData.id===i||t.userData.uuid===i)))&&void 0!==n?n:null))}var e,i,n}}class L extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("models",a.LOCAL),s=this.findProp("out",a.WRITE_CTX);if(t&&s){const e=k(t.value),i=k(s.value);this.writeContext(i,function(t,s){const e=new Set(s);return t.getAllModel().filter((t=>e.has(t.userData.id)||e.has(t.userData.uuid)))}(this.ssp,e))}}}class M extends n{constructor(t,s){super(t,s)}async exec(){const s=this.findProp("delay",a.LOCAL);if(s){const e=k(s.value);await t.utils.sleep(e)}}}const{objectHandle:S}=t.utils;class m extends n{constructor(t,s){super(t,s)}filterShowObject(t){const s=[];return S(t,(t=>{!1===t.visible&&s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX);if(t){const s=this.readContext(k(t.value));if(s){const t=this.filterShowObject(s),e=s=>{S(t,(t=>{t.visible=s})),this.ssp.render()};e(!0),this.cleanSets.add((()=>e(!1)))}}}}const{objectHandle:y}=t.utils;class P extends n{constructor(t,s){super(t,s)}filterHideObject(t){const s=[];return y(t,(t=>{!0===t.visible&&s.push(t)})),s}async exec(){const t=this.findProp("objects",a.READ_CTX);if(t){const s=this.readContext(k(t.value));if(s){const t=this.filterHideObject(s),e=s=>{y(t,(t=>{t.visible=s})),this.ssp.render()};e(!1),this.cleanSets.add((()=>e(!0)))}}}}class b extends n{constructor(t,s){super(t,s)}async exec(t){var s;let e=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(!e){const t=this.findProp("object",a.READ_CTX);t&&(e=this.readContext(k(t.value)))}const i=this.findProp("animation",a.LOCAL);if(e&&i){const t=k(i.value),s=e.animations[t];s&&(this.ssp.playModelAnimation(e,s),this.cleanSets.add((()=>{this.ssp.stopModelAnimation(e,s)})))}}}class H extends n{constructor(t,s){super(t,s)}async exec(t){var s;let e=await(null===(s=t.getTarget)||void 0===s?void 0:s.call(t,this));if(!e){const t=this.findProp("object",a.READ_CTX);t&&(e=this.readContext(k(t.value)))}const i=this.findProp("animation",a.LOCAL);if(e&&i){const t=k(i.value),s=e.animations[t];s&&this.ssp.stopModelAnimation(e,s)}}}const D=new Map;function R(t){var s,e;null===(s=D.get(t))||void 0===s||s.forEach((t=>t.stop())),null===(e=D.get(t))||void 0===e||e.clear()}class j extends n{constructor(t,s){super(t,s)}async exec(t){var e;const i=this.findProp("object",a.READ_CTX),n=this.findProp("animation",a.LOCAL),o=this.findProp("wait",a.LOCAL);if(i&&n&&o){const a=this.readContext(k(i.value)),c=k(n.value),r=k(o.value);if(a){const i=await(null===(e=t.getAnimations)||void 0===e?void 0:e.call(t,this,a,c));if(i){const t=i.find((t=>t.id===c));t&&await Y((async()=>{const e=a.matrix.clone();await async function(t,e,i){var n;const{id:o,keyframes:a}=i,c=new s(t,e);D.has(o)||D.set(o,new Set),null===(n=D.get(o))||void 0===n||n.add(c),await c.play(a)}(this.ssp,a,t),this.cleanSets.add((()=>{R(t.id),a&&e.decompose(a.position,a.quaternion,a.scale)}))}),r)}}}}}class U extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("animation",a.LOCAL);if(t){R(k(t.value))}}}const X=new Map;function G(t){var s,e;null===(s=X.get(t))||void 0===s||s.forEach((t=>t.stop())),null===(e=X.get(t))||void 0===e||e.clear()}class W extends n{constructor(t,s){super(t,s)}async exec(t){var e;const i=this.findProp("object",a.READ_CTX),n=this.findProp("animation",a.LOCAL),o=this.findProp("wait",a.LOCAL);if(i&&n&&o){const a=this.readContext(k(i.value)),c=k(n.value),r=k(o.value);if(a){const n=await(null===(e=t.getComponentAnimations)||void 0===e?void 0:e.call(t,this,a,c));if(n){const t=n.find((t=>t.id===c));if(t){let e=null;"Mesh"===i.valueType?e=a:"Model"===i.valueType&&(e=F(a,t.refId)),e&&await Y((async()=>{if(e){const i=e.matrix.clone();await async function(t,e,i){var n;const{id:o,keyframes:a}=i,c=new s(t,e);X.has(o)||X.set(o,new Set),null===(n=X.get(o))||void 0===n||n.add(c),await c.play(a)}(this.ssp,e,t),this.cleanSets.add((()=>{G(t.id),e&&i.decompose(e.position,e.quaternion,e.scale)}))}}),r)}}}}}}class B extends n{constructor(t,s){super(t,s)}async exec(){const t=this.findProp("animation",a.LOCAL);if(t){G(k(t.value))}}}function k(t){return JSON.parse(t)}async function Y(t,s){s?await t():t()}function F(t,s){if(t.userData.key===s)return t;for(let e=0,i=t.children.length;e<i;e++){const i=F(t.children[e],s);if(null!==i)return i}return null}class K{constructor(t,s){this.onNodeBefore=null,this.onNodeAfter=null,this.ssp=t,this.flow=s,this.nodes=[],this.nodesMap=new Map,this.edges=[],this.edgesMap=new Map}addNode(t){this.nodes.push(t),this.nodesMap.set(t.id,t)}addEdge(t){this.edges.push(t),this.edgesMap.set(t.id,t)}getNodeById(t){return this.nodesMap.get(t)}getEdgeById(t){return this.edgesMap.get(t)}clear(){this.nodes.length=0,this.nodesMap.clear(),this.edges.length=0,this.edgesMap.clear()}parse(){this.clear();const{nodes:t,edges:s}=this.flow;t.forEach((t=>{const s=function(t,s){switch(s.type){case c.START:return new o(t,s);case c.COLOR:return new r(t,s);case c.NUMBER:return new h(t,s);case c.HIGHLIGHT:return new d(t,s);case c.UN_HIGHLIGHT:return new p(t,s);case c.OPACITY:return new E(t,s);case c.UN_OPACITY:return new O(t,s);case c.EMISSIVE:return new T(t,s);case c.UN_EMISSIVE:return new N(t,s);case c.MESH:return new w(t,s);case c.MESHES:return new x(t,s);case c.MODEL:return new g(t,s);case c.MODELS:return new L(t,s);case c.DELAY:return new M(t,s);case c.SHOW:return new m(t,s);case c.HIDE:return new P(t,s);case c.CLIP_ANIMATION:return new b(t,s);case c.UN_CLIP_ANIMATION:return new H(t,s);case c.TWEEN_ANIMATION:return new j(t,s);case c.UN_TWEEN_ANIMATION:return new U(t,s);case c.COMPONENT_TWEEN_ANIMATION:return new W(t,s);case c.UN_COMPONENT_TWEEN_ANIMATION:return new B(t,s);default:return new n(t,s)}}(this,t);this.addNode(s)})),s.forEach((t=>{const s=new e(t);this.addEdge(s);const i=this.getNodeById(t.source),n=this.getNodeById(t.target);i&&n&&(i.postNodes.push(n),n.prevNodes.push(i))}))}async run(t={}){const s=this.nodes.map((s=>s.run(t)));await Promise.all(s)}stop(){this.nodes.forEach((t=>t.reject(new Error("Flow stopped"))))}cleanup(){this.nodes.sort(((t,s)=>s.execOrder-t.execOrder)).forEach((t=>t.cleanup()))}}class V extends K{constructor(t,s){super(t,s),this.flow=s}}class q{constructor(t){this.disposables=[],this.ssp=t}dispose(){this.disposables.forEach((t=>t()))}}var J,z,Q,Z;!function(t){t.GLOBAL="GLOBAL",t.SELF="SELF",t.OTHER="OTHER"}(J||(J={})),function(t){t.FLOW="FLOW",t.ANIMATION="ANIMATION",t.DELAY="DELAY"}(z||(z={})),function(t){t.GLOBAL="GLOBAL",t.INSTANCE="INSTANCE",t.FAMILY="FAMILY"}(Q||(Q={})),function(t){t.MOUSE_CLICK="MOUSE_CLICK",t.MOUSE_DB_CLICK="MOUSE_DB_CLICK",t.MOUSE_RIGHT_CLICK="MOUSE_RIGHT_CLICK",t.THING_PROP_CHANGE="THING_PROP_CHANGE",t.THING_EVENT="THING_EVENT",t.LOADED="LOADED"}(Z||(Z={}));const{groupBy:$}=t.utils;class tt extends q{constructor(t,s,e,i){super(t),this.target=s,this.interaction=e,this.flows=i,this.flowsMap=$(i,"id"),this.init()}init(){switch(this.interaction.type){case Z.MOUSE_CLICK:this.initMouseClick();break;case Z.MOUSE_DB_CLICK:this.initMouseDbClick();break;case Z.MOUSE_RIGHT_CLICK:this.initMouseRightClick();break;case Z.LOADED:this.initLoaded();break;case Z.THING_PROP_CHANGE:this.initThingPropChange();break;case Z.THING_EVENT:this.initThingEvent()}}modelHandler(t){var s;const{currentTarget:e}=t;null===(s=this.interaction.obsTargets)||void 0===s||s.forEach((t=>{t===e.userData.key&&this.execBehavior()}))}runFlowByIds(t){t.forEach((t=>{const s=this.flowsMap.get(t);if(s){const t=new V(this.ssp,s[0]);t.parse(),t.run({getTarget:async()=>this.target})}}))}async execBehavior(){const{behaviors:t}=this.interaction;null==t||t.forEach((t=>{if(t.action===z.FLOW)t.actionRefs&&this.runFlowByIds(t.actionRefs)}))}initMouseClick(){this.ssp.signals.modelClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelClick.remove(this.modelHandler)))}initMouseDbClick(){this.ssp.signals.modelDblClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelDblClick.remove(this.modelHandler)))}initMouseRightClick(){this.ssp.signals.modelRightClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelRightClick.remove(this.modelHandler)))}initLoaded(){const t=()=>{this.execBehavior()};this.target.addEventListener("load",t),this.disposables.push((()=>this.target.removeEventListener("load",t)))}initThingPropChange(){}initThingEvent(){}}export{V as ComponentFlowParser,tt as ComponentTrigger,K as FlowParser,z as InteractionAction,J as InteractionActionType,Q as InteractionObsType,Z as InteractionType,a as NodePropTypeEnum,c as NodeTypeEnum,q as Trigger};
1
+ import{EventDispatcher as s}from"three";import t from"soonspacejs";import{AnimationPlayer as e}from"umanager-animation-parser";import{FlowParser as i,InteractionAction as n,InteractionType as o,InteractionObsType as r}from"@soonspacejs/plugin-flow";class a{constructor(s){this.id=s.id,this.source=s.source,this.target=s.target}}var c,h;!function(s){s.LOCAL="LOCAL",s.READ_CTX="READ_CTX",s.WRITE_CTX="WRITE_CTX"}(c||(c={})),function(s){s.START="START",s.COLOR="COLOR",s.NUMBER="NUMBER",s.HIGHLIGHT="HIGHLIGHT",s.UN_HIGHLIGHT="UN_HIGHLIGHT",s.OPACITY="OPACITY",s.UN_OPACITY="UN_OPACITY",s.EMISSIVE="EMISSIVE",s.UN_EMISSIVE="UN_EMISSIVE",s.MESH="MESH",s.MESHES="MESHES",s.MODEL="MODEL",s.MODELS="MODELS",s.DELAY="DELAY",s.SHOW="SHOW",s.HIDE="HIDE",s.CLIP_ANIMATION="CLIP_ANIMATION",s.UN_CLIP_ANIMATION="UN_CLIP_ANIMATION",s.TWEEN_ANIMATION="TWEEN_ANIMATION",s.UN_TWEEN_ANIMATION="UN_TWEEN_ANIMATION",s.COMPONENT_TWEEN_ANIMATION="COMPONENT_TWEEN_ANIMATION",s.UN_COMPONENT_TWEEN_ANIMATION="UN_COMPONENT_TWEEN_ANIMATION"}(h||(h={}));let l=0;class d{constructor(s,t){this.prevNodes=[],this.postNodes=[],this.execOrder=0,this.cleanSets=new Set,this.onBefore=null,this.onAfter=null,this.parser=s,this.ssp=s.ssp,this.id=t.id,this.type=t.type,this.props=t.props,this.init()}init(){this.ctx={},this.promise=new Promise(((s,t)=>{this.resolve=s,this.reject=t}))}readContext(s){return this.ctx[s]}writeContext(s,t){this.ctx[s]=t}findProp(s,t){if(!(t instanceof Array))return this.props.find((e=>e.name===s&&e.type===t));for(const e of t){const t=this.findProp(s,e);if(t)return t}}async waitForPrevNodes(){await Promise.all(this.prevNodes.map((s=>s.promise)))}mergeContext(){this.prevNodes.forEach((s=>{Object.assign(this.ctx,s.ctx)}))}async exec(s){}async run(s){var t,e,i,n;await this.waitForPrevNodes(),this.mergeContext(),await(null===(e=null!==(t=this.onBefore)&&void 0!==t?t:this.parser.onNodeBefore)||void 0===e?void 0:e(this));try{this.execOrder=++l,await this.exec(s)}catch(s){throw this.reject(s),s}await(null===(n=null!==(i=this.onAfter)&&void 0!==i?i:this.parser.onNodeAfter)||void 0===n?void 0:n(this)),this.resolve()}cleanup(){this.cleanSets.forEach((s=>s())),this.cleanSets.clear()}getValue(s){return s.type===c.READ_CTX?this.readContext(q(s.value).variableName):s.type===c.LOCAL?"objects"===s.name?z(this.ssp,q(s.value)):q(s.value):void 0}}class u extends d{constructor(s,t){super(s,t)}}class p extends d{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("color",c.LOCAL),t=this.findProp("out",c.WRITE_CTX);s&&t&&this.writeContext(q(t.value),q(s.value))}}class f extends d{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("number",c.LOCAL),t=this.findProp("out",c.WRITE_CTX);s&&t&&this.writeContext(q(t.value),q(s.value))}}const{objectHandle:E}=t.utils;class C extends d{constructor(s,t){super(s,t)}filterHighlightObject(s){const t=[];return E(s,(s=>{this.ssp.viewport.scener.selectedObjects.highlight.has(s)||t.push(s)})),t}async exec(){const s=this.findProp("objects",[c.READ_CTX,c.LOCAL]),t=this.findProp("color",[c.READ_CTX,c.LOCAL]),e=this.findProp("opacity",[c.READ_CTX,c.LOCAL]);if(s&&t&&e){const i=this.getValue(s),n=this.getValue(t),o=this.getValue(e);if(i){const s=this.filterHighlightObject(i);this.ssp.highlightShow(s,{color:n,opacity:o}),this.cleanSets.add((()=>{this.ssp.unHighlightShow(s)}))}}}}const{objectHandle:v}=t.utils;class O extends d{constructor(s,t){super(s,t)}filterUnHighlightObject(s){const t=[];return v(s,(s=>{this.ssp.viewport.scener.selectedObjects.highlight.has(s)&&t.push(s)})),t}async exec(){const s=this.findProp("objects",c.LOCAL);if(s){const t=z(this.ssp,q(s.value));if(t){const s=this.filterUnHighlightObject(t);this.ssp.unHighlightShow(s),this.cleanSets.add((()=>{this.ssp.highlightShow(s)}))}}}}const{objectHandle:g}=t.utils;class T extends d{constructor(s,t){super(s,t)}filterOpacityObject(s){const t=[];return g(s,(s=>{this.ssp.viewport.scener.selectedObjects.opacity.has(s)||t.push(s)})),t}async exec(){const s=this.findProp("objects",[c.READ_CTX,c.LOCAL]),t=this.findProp("color",[c.READ_CTX,c.LOCAL]),e=this.findProp("opacity",[c.READ_CTX,c.LOCAL]);if(s&&t&&e){const i=this.getValue(s),n=this.getValue(t),o=this.getValue(e);if(i){const s=this.filterOpacityObject(i);this.ssp.opacityShow(s,{color:n,opacity:o}),this.cleanSets.add((()=>{this.ssp.unOpacityShow(s)}))}}}}const{objectHandle:A}=t.utils;class I extends d{constructor(s,t){super(s,t)}filterUnOpacityObject(s){const t=[];return A(s,(s=>{this.ssp.viewport.scener.selectedObjects.opacity.has(s)&&t.push(s)})),t}async exec(){const s=this.findProp("objects",c.LOCAL);if(s){const t=z(this.ssp,q(s.value));if(t){const s=this.filterUnOpacityObject(t);this.ssp.unOpacityShow(s),this.cleanSets.add((()=>{this.ssp.opacityShow(s)}))}}}}const{objectHandle:N}=t.utils;class w extends d{constructor(s,t){super(s,t)}filterEmissiveObject(s){const t=[];return N(s,(s=>{this.ssp.viewport.scener.selectedObjects.emissive.has(s)||t.push(s)})),t}async exec(){const s=this.findProp("objects",c.READ_CTX),t=this.findProp("color",c.READ_CTX),e=this.findProp("baseColor",c.READ_CTX),i=this.findProp("minOpacity",c.READ_CTX),n=this.findProp("maxOpacity",c.READ_CTX),o=this.findProp("duration",c.READ_CTX);if(s&&t&&e&&i&&n&&o){const r=this.readContext(q(s.value)),a=this.readContext(q(t.value)),c=this.readContext(q(e.value)),h=this.readContext(q(i.value)),l=this.readContext(q(n.value)),d=this.readContext(q(o.value));if(r){const s=this.filterEmissiveObject(r);this.ssp.emissiveShow(s,{color:a,baseColor:c,minOpacity:h,maxOpacity:l,duration:d}),this.cleanSets.add((()=>{this.ssp.unEmissiveShow(s)}))}}}}const{objectHandle:L}=t.utils;class m extends d{constructor(s,t){super(s,t)}filterUnEmissiveObject(s){const t=[];return L(s,(s=>{this.ssp.viewport.scener.selectedObjects.emissive.has(s)&&t.push(s)})),t}async exec(){const s=this.findProp("objects",c.READ_CTX);if(s){const t=this.readContext(q(s.value));if(t){const s=this.filterUnEmissiveObject(t);this.ssp.unEmissiveShow(s),this.cleanSets.add((()=>{this.ssp.emissiveShow(s)}))}}}}const _=Symbol("meshCache");class b extends d{constructor(s,t){super(s,t)}async exec(s){var t;const{viewport:{scene:e}}=this.ssp,i=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this))||e;s[_]||(s[_]={});const n=this.findProp("mesh",c.LOCAL),o=this.findProp("out",c.WRITE_CTX);if(n&&o){let t=null;const e=q(n.value),r=q(o.value),a=s[_][e];if(a)return void(t=a);const c=Q(i,e);c&&(t=c,s[_][e]=c),this.writeContext(r,t)}}}const y=Symbol("meshesCache");class M extends d{constructor(s,t){super(s,t)}async exec(s){var t;const{viewport:{scene:e}}=this.ssp,i=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this))||e;s[y]||(s[y]={});const n=this.findProp("meshes",c.LOCAL),o=this.findProp("out",c.WRITE_CTX);if(n&&o){const t=[],e=q(n.value),r=q(o.value);e.forEach((e=>{const n=s[y][e];if(n)return void t.push(n);const o=Q(i,e);o&&(t.push(o),s[y][e]=o)})),this.writeContext(r,t)}}}class x extends d{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("model",c.LOCAL),t=this.findProp("out",c.WRITE_CTX);if(s&&t){const e=q(s.value),i=q(t.value);this.writeContext(i,this.ssp.getObjectById(e))}}}class P extends d{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("models",c.LOCAL),t=this.findProp("out",c.WRITE_CTX);if(s&&t){const e=q(s.value),i=q(t.value);this.writeContext(i,z(this.ssp,e))}}}class S extends d{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("delay",c.LOCAL);if(s){const e=q(s.value);await t.utils.sleep(e)}}}const{objectHandle:H}=t.utils;class R extends d{constructor(s,t){super(s,t)}filterShowObject(s){const t=[];return H(s,(s=>{!1===s.visible&&t.push(s)})),t}async exec(){const s=this.findProp("objects",c.READ_CTX);if(s){const t=this.readContext(q(s.value));if(t){const s=this.filterShowObject(t),e=t=>{H(s,(s=>{s.visible=t})),this.ssp.render()};e(!0),this.cleanSets.add((()=>e(!1)))}}}}const{objectHandle:D}=t.utils;class j extends d{constructor(s,t){super(s,t)}filterHideObject(s){const t=[];return D(s,(s=>{!0===s.visible&&t.push(s)})),t}async exec(){const s=this.findProp("objects",c.READ_CTX);if(s){const t=this.readContext(q(s.value));if(t){const s=this.filterHideObject(t),e=t=>{D(s,(s=>{s.visible=t})),this.ssp.render()};e(!1),this.cleanSets.add((()=>e(!0)))}}}}class k extends d{constructor(s,t){super(s,t)}async exec(s){var t;let e=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this));if(!e){const s=this.findProp("object",c.READ_CTX);s&&(e=this.readContext(q(s.value)))}const i=this.findProp("animation",c.LOCAL);if(e&&i){const s=q(i.value),t=e.animations[s];t&&(this.ssp.playModelAnimation(e,t),this.cleanSets.add((()=>{this.ssp.stopModelAnimation(e,t)})))}}}class B extends d{constructor(s,t){super(s,t)}async exec(s){var t;let e=await(null===(t=s.getTarget)||void 0===t?void 0:t.call(s,this));if(!e){const s=this.findProp("object",c.READ_CTX);s&&(e=this.readContext(q(s.value)))}const i=this.findProp("animation",c.LOCAL);if(e&&i){const s=q(i.value),t=e.animations[s];t&&this.ssp.stopModelAnimation(e,t)}}}const U=new Map;function G(s){var t,e;null===(t=U.get(s))||void 0===t||t.forEach((s=>s.stop())),null===(e=U.get(s))||void 0===e||e.clear()}class X extends d{constructor(s,t){super(s,t)}async exec(s){var t;const i=this.findProp("object",c.READ_CTX),n=this.findProp("animation",c.LOCAL),o=this.findProp("wait",c.LOCAL);if(i&&n&&o){const r=this.readContext(q(i.value)),a=q(n.value),c=q(o.value);if(r){const i=await(null===(t=s.getAnimations)||void 0===t?void 0:t.call(s,this,r,a));if(i){const s=i.find((s=>s.id===a));s&&await J((async()=>{const t=r.matrix.clone();await async function(s,t,i){var n;const{id:o,keyframes:r}=i,a=new e(s,t);U.has(o)||U.set(o,new Set),null===(n=U.get(o))||void 0===n||n.add(a),await a.play(r)}(this.ssp,r,s),this.cleanSets.add((()=>{G(s.id),r&&t.decompose(r.position,r.quaternion,r.scale)}))}),c)}}}}}class W extends d{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("animation",c.LOCAL);if(s){G(q(s.value))}}}const V=new Map;function F(s){var t,e;null===(t=V.get(s))||void 0===t||t.forEach((s=>s.stop())),null===(e=V.get(s))||void 0===e||e.clear()}class K extends d{constructor(s,t){super(s,t)}async exec(s){var t;const i=this.findProp("object",c.READ_CTX),n=this.findProp("animation",c.LOCAL),o=this.findProp("wait",c.LOCAL);if(i&&n&&o){const r=this.readContext(q(i.value)),a=q(n.value),c=q(o.value);if(r){const n=await(null===(t=s.getComponentAnimations)||void 0===t?void 0:t.call(s,this,r,a));if(n){const s=n.find((s=>s.id===a));if(s){let t=null;"Mesh"===i.valueType?t=r:"Model"===i.valueType&&(t=Q(r,s.refId)),t&&await J((async()=>{if(t){const i=t.matrix.clone();await async function(s,t,i){var n;const{id:o,keyframes:r}=i,a=new e(s,t);V.has(o)||V.set(o,new Set),null===(n=V.get(o))||void 0===n||n.add(a),await a.play(r)}(this.ssp,t,s),this.cleanSets.add((()=>{F(s.id),t&&i.decompose(t.position,t.quaternion,t.scale)}))}}),c)}}}}}}class Y extends d{constructor(s,t){super(s,t)}async exec(){const s=this.findProp("animation",c.LOCAL);if(s){F(q(s.value))}}}function q(s){return JSON.parse(s)}async function J(s,t){t?await s():s()}function z(s,t){return t.map((t=>s.getObjectById(t))).filter(Boolean)}function Q(s,t){if(s.userData.key===t)return s;for(let e=0,i=s.children.length;e<i;e++){const i=Q(s.children[e],t);if(null!==i)return i}return null}const{utils:{sleep:Z}}=t;class $ extends s{constructor(s,t){super(),this.onNodeBefore=null,this.onNodeAfter=null,this.ssp=s,this.flow=t,this.nodes=[],this.nodesMap=new Map,this.edges=[],this.edgesMap=new Map}addNode(s){this.nodes.push(s),this.nodesMap.set(s.id,s)}addEdge(s){this.edges.push(s),this.edgesMap.set(s.id,s)}getNodeById(s){return this.nodesMap.get(s)}getEdgeById(s){return this.edgesMap.get(s)}clear(){this.nodes.length=0,this.nodesMap.clear(),this.edges.length=0,this.edgesMap.clear()}parse(){this.clear();const{nodes:s,edges:t}=this.flow;s.forEach((s=>{const t=function(s,t){switch(t.type){case h.START:return new u(s,t);case h.COLOR:return new p(s,t);case h.NUMBER:return new f(s,t);case h.HIGHLIGHT:return new C(s,t);case h.UN_HIGHLIGHT:return new O(s,t);case h.OPACITY:return new T(s,t);case h.UN_OPACITY:return new I(s,t);case h.EMISSIVE:return new w(s,t);case h.UN_EMISSIVE:return new m(s,t);case h.MESH:return new b(s,t);case h.MESHES:return new M(s,t);case h.MODEL:return new x(s,t);case h.MODELS:return new P(s,t);case h.DELAY:return new S(s,t);case h.SHOW:return new R(s,t);case h.HIDE:return new j(s,t);case h.CLIP_ANIMATION:return new k(s,t);case h.UN_CLIP_ANIMATION:return new B(s,t);case h.TWEEN_ANIMATION:return new X(s,t);case h.UN_TWEEN_ANIMATION:return new W(s,t);case h.COMPONENT_TWEEN_ANIMATION:return new K(s,t);case h.UN_COMPONENT_TWEEN_ANIMATION:return new Y(s,t);default:return new d(s,t)}}(this,s);this.addNode(t)})),t.forEach((s=>{const t=new a(s);this.addEdge(t);const e=this.getNodeById(s.source),i=this.getNodeById(s.target);e&&i&&(e.postNodes.push(i),i.prevNodes.push(e))}))}async run(s={}){const t=this.nodes.filter((s=>s.prevNodes.length||s.postNodes.length)).map((t=>t.run(s)));await Promise.all(t)}async debug(s={},t=1500){const e=this.onNodeAfter;this.onNodeAfter=async s=>{await Z(t),null==e||e(s)},await this.run(s)}stop(){this.nodes.forEach((s=>s.reject(new Error("Flow stopped"))))}cleanup(){this.nodes.sort(((s,t)=>t.execOrder-s.execOrder)).forEach((s=>s.cleanup()))}dispose(){this.stop(),this.cleanup()}}class ss extends ${constructor(s,t){super(s,t),this.flow=t}}function ts(s,t,e,i){if("a"===e&&!i)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?s!==t||!i:!t.has(s))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===e?i:"a"===e?i.call(s):i?i.value:t.get(s)}var es,is,ns;"function"==typeof SuppressedError&&SuppressedError;const{groupBy:os}=t.utils;class rs{constructor(s,t,e,i){es.add(this),this.disposables=[],this.ssp=s,this.interaction=t,this.flows=e,this.flowsMap=os(e,"id"),this.options=i||{},ts(this,es,"m",is).call(this)}modelHandler(s){var t;const{target:e}=s;null===(t=this.interaction.obsTargets)||void 0===t||t.forEach((s=>{s===e.userData.sid&&this.execBehavior()}))}runFlowByIds(s){s.forEach((s=>{const t=this.flowsMap.get(s);if(t){const s=new i(this.ssp,t[0]);s.parse(),s.run({getTarget:ts(this,es,"m",ns)})}}))}async execBehavior(){var s,t,e,i;try{const{behaviors:e}=this.interaction;null==e||e.forEach((s=>{if(s.action===n.FLOW)s.actionRefs&&this.runFlowByIds(s.actionRefs)})),(null===(s=this.options)||void 0===s?void 0:s.onTrigger)&&(null===(t=this.options)||void 0===t||t.onTrigger(this.interaction))}catch(s){(null===(e=this.options)||void 0===e?void 0:e.onError)&&(null===(i=this.options)||void 0===i||i.onError(s))}}initMouseClick(){const s=this.modelHandler.bind(this);this.ssp.signals.modelClick.add(s),this.disposables.push((()=>this.ssp.signals.modelClick.remove(s)))}initMouseDbClick(){const s=this.modelHandler.bind(this);this.ssp.signals.modelDblClick.add(s),this.disposables.push((()=>this.ssp.signals.modelDblClick.remove(s)))}initMouseRightClick(){const s=this.modelHandler.bind(this);this.ssp.signals.modelRightClick.add(s),this.disposables.push((()=>this.ssp.signals.modelRightClick.remove(s)))}initLoaded(){(()=>{this.execBehavior()})()}initThingPropChange(){}initThingEvent(){}dispose(){this.disposables.forEach((s=>s()))}}var as,cs,hs,ls,ds,us,ps;es=new WeakSet,is=function(){switch(this.interaction.type){case o.MOUSE_CLICK:this.initMouseClick();break;case o.MOUSE_DB_CLICK:this.initMouseDbClick();break;case o.MOUSE_RIGHT_CLICK:this.initMouseRightClick();break;case o.LOADED:this.initLoaded();break;case o.THING_PROP_CHANGE:this.initThingPropChange();break;case o.THING_EVENT:this.initThingEvent()}},ns=async function(s){const{obsType:t,obsTargets:e}=this.interaction;if(t===r.GLOBAL)return null;if(t===r.INSTANCE){const s=null==e?void 0:e.map((s=>{const t=this.ssp.getModelById(s);return t||console.warn("Target not found:",s),t}));return s?s[0]:null}return null},function(s){s.GLOBAL="GLOBAL",s.SELF="SELF",s.OTHER="OTHER"}(as||(as={})),function(s){s.FLOW="FLOW",s.ANIMATION="ANIMATION",s.DELAY="DELAY"}(cs||(cs={})),function(s){s.GLOBAL="GLOBAL",s.INSTANCE="INSTANCE",s.FAMILY="FAMILY"}(hs||(hs={})),function(s){s.MOUSE_CLICK="MOUSE_CLICK",s.MOUSE_DB_CLICK="MOUSE_DB_CLICK",s.MOUSE_RIGHT_CLICK="MOUSE_RIGHT_CLICK",s.THING_PROP_CHANGE="THING_PROP_CHANGE",s.THING_EVENT="THING_EVENT",s.LOADED="LOADED"}(ls||(ls={}));const{groupBy:fs}=t.utils;class Es extends rs{constructor(s,t,e,i){super(s,t,e,i),ds.add(this),this.flows=e,this.flowsMap=fs(e,"id"),ts(this,ds,"m",us).call(this)}async getObsTarget(s){console.log("currentNode",s);const{obsType:t,obsTargets:e}=this.interaction;if(t===hs.GLOBAL)return null;if(t===hs.INSTANCE){const s=null==e?void 0:e.map((s=>{const t=this.ssp.getModelById(s);return t||console.warn("Target not found:",s),t}));return s?s[0]:null}return null}modelHandler(s){var t;const{currentTarget:e}=s;null===(t=this.interaction.obsTargets)||void 0===t||t.forEach((s=>{s===e.userData.key&&this.execBehavior()}))}runFlowByIds(s){s.forEach((s=>{const t=this.flowsMap.get(s);if(t){const s=new ss(this.ssp,t[0]);s.parse(),s.run({getTarget:this.getObsTarget})}}))}async execBehavior(){var s,t,e,i;try{const{behaviors:e}=this.interaction;null==e||e.forEach((s=>{if(s.action===cs.FLOW)s.actionRefs&&this.runFlowByIds(s.actionRefs)})),(null===(s=this.options)||void 0===s?void 0:s.onTrigger)&&(null===(t=this.options)||void 0===t||t.onTrigger(this.interaction))}catch(s){(null===(e=this.options)||void 0===e?void 0:e.onError)&&(null===(i=this.options)||void 0===i||i.onError(s))}}initMouseClick(){this.ssp.signals.modelClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelClick.remove(this.modelHandler)))}initMouseDbClick(){this.ssp.signals.modelDblClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelDblClick.remove(this.modelHandler)))}initMouseRightClick(){this.ssp.signals.modelRightClick.add(this.modelHandler),this.disposables.push((()=>this.ssp.signals.modelRightClick.remove(this.modelHandler)))}initLoaded(){const s=()=>{this.execBehavior()};this.getObsTarget().then((t=>{t&&(t.addEventListener("load",s),this.disposables.push((()=>t.removeEventListener("load",s))))}))}initThingPropChange(){this.ssp.signals.thingModelPropsChange.add(ts(this,ds,"m",ps)),this.disposables.push((()=>this.ssp.signals.thingModelPropsChange.remove(ts(this,ds,"m",ps))))}initThingEvent(){}onThingPropChange(s){this.ssp.signals.thingModelPropsChange.dispatch({propKey:s})}}ds=new WeakSet,us=function(){switch(this.interaction.type){case ls.MOUSE_CLICK:this.initMouseClick();break;case ls.MOUSE_DB_CLICK:this.initMouseDbClick();break;case ls.MOUSE_RIGHT_CLICK:this.initMouseRightClick();break;case ls.LOADED:this.initLoaded();break;case ls.THING_PROP_CHANGE:this.initThingPropChange();break;case ls.THING_EVENT:this.initThingEvent()}},ps=function(s){var t;const{propKey:e}=s;null===(t=this.interaction.obsProps)||void 0===t||t.forEach((s=>{s===e&&this.execBehavior()}))};export{ss as ComponentFlowParser,Es as ComponentTrigger,$ as FlowParser,cs as InteractionAction,as as InteractionActionType,hs as InteractionObsType,ls as InteractionType,d as Node,c as NodePropTypeEnum,h as NodeTypeEnum,rs as Trigger};
@@ -1,14 +1,14 @@
1
1
  import SoonSpace, { Model, ModelEventParams } from 'soonspacejs';
2
2
  import { Trigger } from './Trigger';
3
- import { Interaction } from './types';
3
+ import { Interaction, TriggerOptions } from './types';
4
4
  import { ComponentFlowType } from '../flows/types';
5
+ import { Node } from '../flows';
5
6
  declare class ComponentTrigger extends Trigger {
6
- target: Model;
7
- interaction: Interaction;
7
+ #private;
8
8
  flows: ComponentFlowType[];
9
9
  flowsMap: Map<string, ComponentFlowType[]>;
10
- constructor(ssp: SoonSpace, target: Model, interaction: Interaction, flows: ComponentFlowType[]);
11
- init(): void;
10
+ constructor(ssp: SoonSpace, interaction: Interaction, flows: ComponentFlowType[], options: TriggerOptions);
11
+ getObsTarget(currentNode?: Node): Promise<Model | null>;
12
12
  modelHandler(params: ModelEventParams): void;
13
13
  runFlowByIds(flowIds: string[]): void;
14
14
  execBehavior(): Promise<void>;
@@ -18,5 +18,6 @@ declare class ComponentTrigger extends Trigger {
18
18
  initLoaded(): void;
19
19
  initThingPropChange(): void;
20
20
  initThingEvent(): void;
21
+ onThingPropChange(newProps: string): void;
21
22
  }
22
23
  export { ComponentTrigger, };
@@ -1,8 +1,23 @@
1
- import SoonSpace from 'soonspacejs';
1
+ import SoonSpace, { ModelEventParams } from 'soonspacejs';
2
+ import { FlowType, Interaction, TriggerOptions } from '@soonspacejs/plugin-flow';
2
3
  declare class Trigger {
4
+ #private;
3
5
  ssp: SoonSpace;
6
+ interaction: Interaction;
7
+ flows: FlowType[];
8
+ flowsMap: Map<string, FlowType[]>;
9
+ options: TriggerOptions;
4
10
  disposables: (() => void)[];
5
- constructor(ssp: SoonSpace);
11
+ constructor(ssp: SoonSpace, interaction: Interaction, flows: FlowType[], options: TriggerOptions);
12
+ modelHandler(params: ModelEventParams): void;
13
+ runFlowByIds(flowIds: string[]): void;
14
+ execBehavior(): Promise<void>;
15
+ initMouseClick(): void;
16
+ initMouseDbClick(): void;
17
+ initMouseRightClick(): void;
18
+ initLoaded(): void;
19
+ initThingPropChange(): void;
20
+ initThingEvent(): void;
6
21
  dispose(): void;
7
22
  }
8
23
  export { Trigger, };
@@ -39,3 +39,7 @@ export type Interaction = {
39
39
  obsProps: string[] | null;
40
40
  behaviors: InteractionBehavior[] | null;
41
41
  };
42
+ export type TriggerOptions = {
43
+ onError?: (e: Error) => void;
44
+ onTrigger?: (interaction: Interaction) => void;
45
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soonspacejs/plugin-flow",
3
3
  "pluginName": "FlowPlugin",
4
- "version": "2.13.2",
4
+ "version": "2.13.5",
5
5
  "description": "FlowPlugin plugin for SoonSpace.js",
6
6
  "main": "dist/index.esm.js",
7
7
  "module": "dist/index.esm.js",
@@ -13,9 +13,9 @@
13
13
  ],
14
14
  "author": "xunwei",
15
15
  "license": "UNLICENSED",
16
- "gitHead": "31d61cfb34a7879b1cff3a955663415672ef2ef7",
16
+ "gitHead": "e19da4dc04255f2374645aa083e0116668894874",
17
17
  "peerDependencies": {
18
- "soonspacejs": "2.13.2",
18
+ "soonspacejs": "2.13.5",
19
19
  "umanager-animation-parser": "^0.0.6"
20
20
  }
21
21
  }