@soonspacejs/plugin-flow 2.14.29 → 2.14.30

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/dist/index.esm.js CHANGED
@@ -314,7 +314,7 @@ class ht extends f {
314
314
  }
315
315
  }
316
316
  }
317
- const y = Symbol("meshCache");
317
+ const y = /* @__PURE__ */ Symbol("meshCache");
318
318
  class ut extends f {
319
319
  constructor(t, s) {
320
320
  super(t, s);
@@ -335,7 +335,7 @@ class ut extends f {
335
335
  }
336
336
  }
337
337
  }
338
- const M = Symbol("meshesCache");
338
+ const M = /* @__PURE__ */ Symbol("meshesCache");
339
339
  class dt extends f {
340
340
  constructor(t, s) {
341
341
  super(t, s);
@@ -1187,11 +1187,7 @@ class Yt {
1187
1187
  this.status = "running";
1188
1188
  const { behaviors: s } = this.interaction;
1189
1189
  s?.forEach((i) => {
1190
- switch (i.action) {
1191
- case $.FLOW:
1192
- i.actionRefs && this.runFlowByIds(i.actionRefs);
1193
- break;
1194
- }
1190
+ i.action === $.FLOW && i.actionRefs && this.runFlowByIds(i.actionRefs);
1195
1191
  }), this.options?.onTrigger && this.options?.onTrigger(this.interaction);
1196
1192
  } catch (s) {
1197
1193
  this.status = "error", this.options?.onError && this.options?.onError(s);
@@ -1210,9 +1206,7 @@ class Yt {
1210
1206
  this.ssp.signals.modelRightClick.add(t), this.disposables.push(() => this.ssp.signals.modelRightClick.remove(t));
1211
1207
  }
1212
1208
  initLoaded() {
1213
- (() => {
1214
- this.execBehavior();
1215
- })();
1209
+ this.execBehavior();
1216
1210
  }
1217
1211
  modelPropChangeHandler(t) {
1218
1212
  if (t?.target?.refId && this.ssp.utils.propertiesCtx.source !== "code") {
@@ -1324,11 +1318,7 @@ class is extends Yt {
1324
1318
  try {
1325
1319
  const { behaviors: t } = this.interaction;
1326
1320
  t?.forEach((s) => {
1327
- switch (s.action) {
1328
- case F.FLOW:
1329
- s.actionRefs && this.runFlowByIds(s.actionRefs);
1330
- break;
1331
- }
1321
+ s.action === F.FLOW && s.actionRefs && this.runFlowByIds(s.actionRefs);
1332
1322
  }), this.options?.onTrigger && this.options?.onTrigger(this.interaction);
1333
1323
  } catch (t) {
1334
1324
  this.options?.onError && this.options?.onError(t);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@soonspacejs/plugin-flow",
3
3
  "pluginName": "FlowPlugin",
4
- "version": "2.14.29",
4
+ "version": "2.14.30",
5
5
  "description": "FlowPlugin plugin for SoonSpace.js",
6
6
  "main": "dist/index.esm.js",
7
7
  "module": "dist/index.esm.js",
@@ -15,7 +15,7 @@
15
15
  "license": "UNLICENSED",
16
16
  "gitHead": "4a87dd85050651088e11c3da777c49fab3db7e5d",
17
17
  "peerDependencies": {
18
- "soonspacejs": "2.14.29",
18
+ "soonspacejs": "2.14.30",
19
19
  "umanager-animation-parser": "^0.0.6"
20
20
  }
21
21
  }
package/test/test.ts CHANGED
@@ -1,39 +1,42 @@
1
- import componentThingJson from '../example/scene-test/db/component_thing.json'
1
+ import componentThingJson from '../example/scene-test/db/component_thing.json';
2
2
 
3
3
  function generateMockData ( schema: any ): any {
4
4
 
5
- const result: Record<string, any> = {}
5
+ const result: Record<string, any> = {};
6
6
 
7
7
  // 遍历schema的properties属性
8
8
  for ( const prop of schema.thing.properties ) {
9
9
 
10
- const identifier = prop.identifier
11
- const defineType = prop.define.type
10
+ const identifier = prop.identifier;
11
+ const defineType = prop.define.type;
12
12
 
13
13
  switch ( defineType ) {
14
14
 
15
15
  case 'string':
16
- result[ identifier ] = `模拟${prop.name}`
17
- break
16
+ result[ identifier ] = `模拟${prop.name}`;
17
+ break;
18
18
  case 'int':
19
- result[ identifier ] = Math.floor( Math.random() * 10000 )
20
- break
21
- case 'enum':
22
- const keys = Object.keys( prop.define.mapping )
19
+ result[ identifier ] = Math.floor( Math.random() * 10000 );
20
+ break;
21
+ case 'enum': {
23
22
 
24
- result[ identifier ] = keys[ Math.floor( Math.random() * keys.length ) ]
25
- break
23
+ const keys = Object.keys( prop.define.mapping );
24
+
25
+ result[ identifier ] = keys[ Math.floor( Math.random() * keys.length ) ];
26
+ break;
27
+
28
+ }
26
29
  case 'struct':
27
- result[ identifier ] = generateMockData( { thing: { properties: prop.define.properties, }, } )
28
- break
30
+ result[ identifier ] = generateMockData( { thing: { properties: prop.define.properties, }, } );
31
+ break;
29
32
  default:
30
- result[ identifier ] = null
33
+ result[ identifier ] = null;
31
34
 
32
35
  }
33
36
 
34
37
  }
35
38
 
36
- return result
39
+ return result;
37
40
 
38
41
  }
39
42
 
@@ -43,77 +46,75 @@ interface SchemaMapping {
43
46
  transform?: ( value: any ) => any;
44
47
  }
45
48
 
46
- function transformData (
47
- sourceData: any,
48
- mappings: SchemaMapping[],
49
- defaultValues: Record<string, any> = {}
50
- ): any {
49
+ function transformData ( sourceData: any, mappings: SchemaMapping[], defaultValues: Record<string, any> = {} ): any {
51
50
 
52
- const result: Record<string, any> = { ...defaultValues, }
51
+ const result: Record<string, any> = { ...defaultValues, };
53
52
 
54
53
  for ( const mapping of mappings ) {
55
54
 
56
- const { sourceField, targetField, transform, } = mapping
55
+ const { sourceField, targetField, transform, } = mapping;
57
56
 
58
57
  // 获取源数据的值
59
- const value = sourceField.split( '.' ).reduce( ( obj, key ) =>
60
- obj && obj[ key ] !== undefined ? obj[ key ] : undefined, sourceData )
58
+ const value = sourceField
59
+ .split( '.' )
60
+ .reduce( ( obj, key ) => ( obj && obj[ key ] !== undefined ? obj[ key ] : undefined ), sourceData );
61
61
 
62
62
  // 如果存在值并且有transform函数,则应用transform
63
63
  if ( value !== undefined ) {
64
64
 
65
- const transformedValue = transform ? transform( value ) : value
65
+ const transformedValue = transform ? transform( value ) : value;
66
66
 
67
67
  // 将转换后的值设置到目标字段
68
- const fieldParts = targetField.split( '.' )
69
- let current = result
68
+ const fieldParts = targetField.split( '.' );
69
+ let current = result;
70
70
 
71
71
  for ( let i = 0; i < fieldParts.length - 1; i++ ) {
72
72
 
73
- const part = fieldParts[ i ]
73
+ const part = fieldParts[ i ];
74
74
 
75
75
  if ( !current[ part ] ) {
76
76
 
77
- current[ part ] = {}
77
+ current[ part ] = {};
78
78
 
79
79
  }
80
- current = current[ part ]
80
+ current = current[ part ];
81
81
 
82
82
  }
83
83
 
84
- current[ fieldParts[ fieldParts.length - 1 ] ] = transformedValue
84
+ current[ fieldParts[ fieldParts.length - 1 ] ] = transformedValue;
85
85
 
86
86
  }
87
87
 
88
88
  }
89
89
 
90
- return result
90
+ return result;
91
91
 
92
92
  }
93
93
 
94
-
95
94
  // 1. 生成模拟数据
96
- const schema = componentThingJson[ 0 ] // 你的JSON文件中的第一个元素
97
- const mockData = generateMockData( schema )
95
+ const schema = componentThingJson[ 0 ]; // 你的JSON文件中的第一个元素
96
+ const mockData = generateMockData( schema );
98
97
 
99
- console.log( '生成的模拟数据:', mockData )
98
+ console.log( '生成的模拟数据:', mockData );
100
99
 
101
100
  // 2. 定义映射(从一种模式到另一种模式)
102
101
  const mappings: SchemaMapping[] = [
103
102
  { sourceField: 'name', targetField: 'user.basicInfo.fullName', },
104
103
  { sourceField: 'id', targetField: 'user.basicInfo.idNumber', },
105
- { sourceField: 'gender', targetField: 'user.basicInfo.gender',
106
- transform: ( value ) => value === 'male' ? '男' : ( value === 'female' ? '女' : '未知' ), },
104
+ {
105
+ sourceField: 'gender',
106
+ targetField: 'user.basicInfo.gender',
107
+ transform: ( value ) => ( value === 'male' ? '男' : value === 'female' ? '女' : '未知' ),
108
+ },
107
109
  { sourceField: 'phoneNumber', targetField: 'user.contact.mobile', },
108
110
  { sourceField: 'address', targetField: 'user.contact.address', },
109
- { sourceField: 'image.data', targetField: 'user.avatar',
110
- transform: ( value ) => ( { url: value, } ), }
111
- ]
111
+ { sourceField: 'image.data', targetField: 'user.avatar', transform: ( value ) => ( { url: value, } ), }
112
+ ];
112
113
 
113
114
  // 3. 转换数据
114
115
  const transformedData = transformData( mockData, mappings, {
115
116
  version: '1.0',
116
117
  createdAt: new Date().toISOString(),
117
- } )
118
+ } );
118
119
 
119
- console.log( '转换后的数据:', transformedData )
120
+ console.log( '转换后的数据:', transformedData );