mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-07 17:04:58 +01:00
use special attribute 'initializeBySelection' for initializing new operations based on selection
This commit is contained in:
parent
59db24d4bc
commit
a638f45d6e
16 changed files with 29 additions and 37 deletions
|
|
@ -2,11 +2,11 @@ export default {
|
||||||
operandA: {
|
operandA: {
|
||||||
type: 'shell',
|
type: 'shell',
|
||||||
markColor: 0xC9FFBC,
|
markColor: 0xC9FFBC,
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
},
|
},
|
||||||
operandB: {
|
operandB: {
|
||||||
type: 'shell',
|
type: 'shell',
|
||||||
markColor: 0xFFBEB4,
|
markColor: 0xFFBEB4,
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 1
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ export default {
|
||||||
},
|
},
|
||||||
face: {
|
face: {
|
||||||
type: 'face',
|
type: 'face',
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
},
|
},
|
||||||
datumAxisVector: {
|
datumAxisVector: {
|
||||||
type: 'datumAxis',
|
type: 'datumAxis',
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
export default {
|
export default {
|
||||||
originatingFace: {
|
originatingFace: {
|
||||||
type: 'face',
|
type: 'face',
|
||||||
defaultValue: {type: 'selection'},
|
initializeBySelection: 0,
|
||||||
optional: true
|
optional: true
|
||||||
},
|
},
|
||||||
x: {
|
x: {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
export default {
|
export default {
|
||||||
datum: {
|
datum: {
|
||||||
type: 'datum',
|
type: 'datum',
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
},
|
},
|
||||||
x: {
|
x: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
export default {
|
export default {
|
||||||
datum: {
|
datum: {
|
||||||
type: 'datum',
|
type: 'datum',
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
},
|
},
|
||||||
axis: {
|
axis: {
|
||||||
type: 'enum',
|
type: 'enum',
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ export default {
|
||||||
edges: {
|
edges: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
itemType: 'edge',
|
itemType: 'edge',
|
||||||
defaultValue: {
|
initializeBySelection: true
|
||||||
type: 'selection',
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
thickness: {
|
thickness: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
|
|
||||||
|
|
@ -9,21 +9,19 @@ export default function initializeBySchema(schema, context) {
|
||||||
if (md.type === 'array') {
|
if (md.type === 'array') {
|
||||||
if (md.itemType === 'object') {
|
if (md.itemType === 'object') {
|
||||||
if (md.defaultValue) {
|
if (md.defaultValue) {
|
||||||
if (md.defaultValue.type === 'selection') {
|
val = md.defaultValue;
|
||||||
|
} else if (md.initializeBySelection === true) {
|
||||||
let {itemField, entity} = md.defaultValue;
|
let {itemField, entity} = md.defaultValue;
|
||||||
val = context.streams.selection[entity].value.map(s => {
|
val = context.streams.selection[entity].value.map(s => {
|
||||||
let item = initializeBySchema(md.schema, context);
|
let item = initializeBySchema(md.schema, context);
|
||||||
item[itemField] = s;
|
item[itemField] = s;
|
||||||
return item;
|
return item;
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
val = md.defaultValue;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
val = [];
|
val = [];
|
||||||
}
|
}
|
||||||
} else if (isEntityType(md.itemType)) {
|
} else if (isEntityType(md.itemType)) {
|
||||||
if (md.defaultValue && md.defaultValue.type === 'selection') {
|
if (md.initializeBySelection === true) {
|
||||||
let entityContext = context.streams.selection[md.itemType];
|
let entityContext = context.streams.selection[md.itemType];
|
||||||
if (entityContext) {
|
if (entityContext) {
|
||||||
val = [...entityContext.value];
|
val = [...entityContext.value];
|
||||||
|
|
@ -32,17 +30,15 @@ export default function initializeBySchema(schema, context) {
|
||||||
val = []
|
val = []
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw 'unsupport';
|
throw 'unsupported';
|
||||||
}
|
}
|
||||||
} else if (isEntityType(md.type) && md.defaultValue && md.defaultValue.type === 'selection') {
|
} else if (isEntityType(md.type) && md.initializeBySelection !== undefined) {
|
||||||
const entityContext = context.streams.selection[md.type];
|
const entityContext = context.streams.selection[md.type];
|
||||||
if (entityContext) {
|
if (entityContext) {
|
||||||
val = entityContext.value[0];
|
val = entityContext.value[md.initializeBySelection];
|
||||||
}
|
}
|
||||||
} else if (md.type === 'object') {
|
} else if (md.type === 'object') {
|
||||||
val = initializeBySchema(md.schema, context);
|
val = initializeBySchema(md.schema, context);
|
||||||
} else if (md.type === 'number') {
|
|
||||||
val = md.defaultValue;
|
|
||||||
} else {
|
} else {
|
||||||
val = md.defaultValue;
|
val = md.defaultValue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ export default {
|
||||||
sections: {
|
sections: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
itemType: 'loop',
|
itemType: 'loop',
|
||||||
defaultValue: {
|
initializeBySelection: true
|
||||||
type: 'selection',
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
boolean: {
|
boolean: {
|
||||||
type: 'enum',
|
type: 'enum',
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export default function materializeParams(services, params, schema, result, erro
|
||||||
}
|
}
|
||||||
let value = params[field];
|
let value = params[field];
|
||||||
if (value === undefined || value === null || value === '') {
|
if (value === undefined || value === null || value === '') {
|
||||||
if (!md.optional && !md.hasOwnProperty('defaultValue')) {
|
if (!md.optional) {
|
||||||
errors.push({path: [...parentPath, field], message: 'required'});
|
errors.push({path: [...parentPath, field], message: 'required'});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ export default {
|
||||||
datum: {
|
datum: {
|
||||||
type: 'datum',
|
type: 'datum',
|
||||||
optional: true,
|
optional: true,
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
},
|
},
|
||||||
width: {
|
width: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ export default {
|
||||||
datum: {
|
datum: {
|
||||||
type: 'datum',
|
type: 'datum',
|
||||||
optional: true,
|
optional: true,
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
},
|
},
|
||||||
radius: {
|
radius: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ export default {
|
||||||
datum: {
|
datum: {
|
||||||
type: 'datum',
|
type: 'datum',
|
||||||
optional: true,
|
optional: true,
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
},
|
},
|
||||||
radius: {
|
radius: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
export default {
|
export default {
|
||||||
datum: {
|
datum: {
|
||||||
type: 'datum',
|
type: 'datum',
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,7 +4,7 @@ export default {
|
||||||
datum: {
|
datum: {
|
||||||
type: 'datum',
|
type: 'datum',
|
||||||
optional: true,
|
optional: true,
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
},
|
},
|
||||||
radius: {
|
radius: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ export default {
|
||||||
datum: {
|
datum: {
|
||||||
type: 'datum',
|
type: 'datum',
|
||||||
optional: true,
|
optional: true,
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
},
|
},
|
||||||
radius: {
|
radius: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,11 @@ export default {
|
||||||
},
|
},
|
||||||
face: {
|
face: {
|
||||||
type: 'face',
|
type: 'face',
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
},
|
},
|
||||||
axis: {
|
axis: {
|
||||||
type: 'sketchObject',
|
type: 'sketchObject',
|
||||||
defaultValue: {type: 'selection'}
|
initializeBySelection: 0
|
||||||
},
|
},
|
||||||
boolean: {
|
boolean: {
|
||||||
type: 'enum',
|
type: 'enum',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue