mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-07 00:45:08 +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: {
|
||||
type: 'shell',
|
||||
markColor: 0xC9FFBC,
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
},
|
||||
operandB: {
|
||||
type: 'shell',
|
||||
markColor: 0xFFBEB4,
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 1
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export default {
|
|||
},
|
||||
face: {
|
||||
type: 'face',
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
},
|
||||
datumAxisVector: {
|
||||
type: 'datumAxis',
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
export default {
|
||||
originatingFace: {
|
||||
type: 'face',
|
||||
defaultValue: {type: 'selection'},
|
||||
initializeBySelection: 0,
|
||||
optional: true
|
||||
},
|
||||
x: {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
export default {
|
||||
datum: {
|
||||
type: 'datum',
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
},
|
||||
x: {
|
||||
type: 'number',
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
export default {
|
||||
datum: {
|
||||
type: 'datum',
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
},
|
||||
axis: {
|
||||
type: 'enum',
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@ export default {
|
|||
edges: {
|
||||
type: 'array',
|
||||
itemType: 'edge',
|
||||
defaultValue: {
|
||||
type: 'selection',
|
||||
}
|
||||
initializeBySelection: true
|
||||
},
|
||||
thickness: {
|
||||
type: 'number',
|
||||
|
|
|
|||
|
|
@ -9,21 +9,19 @@ export default function initializeBySchema(schema, context) {
|
|||
if (md.type === 'array') {
|
||||
if (md.itemType === 'object') {
|
||||
if (md.defaultValue) {
|
||||
if (md.defaultValue.type === 'selection') {
|
||||
let {itemField, entity} = md.defaultValue;
|
||||
val = context.streams.selection[entity].value.map(s => {
|
||||
let item = initializeBySchema(md.schema, context);
|
||||
item[itemField] = s;
|
||||
return item;
|
||||
});
|
||||
} else {
|
||||
val = md.defaultValue;
|
||||
}
|
||||
val = md.defaultValue;
|
||||
} else if (md.initializeBySelection === true) {
|
||||
let {itemField, entity} = md.defaultValue;
|
||||
val = context.streams.selection[entity].value.map(s => {
|
||||
let item = initializeBySchema(md.schema, context);
|
||||
item[itemField] = s;
|
||||
return item;
|
||||
});
|
||||
} else {
|
||||
val = [];
|
||||
}
|
||||
} else if (isEntityType(md.itemType)) {
|
||||
if (md.defaultValue && md.defaultValue.type === 'selection') {
|
||||
if (md.initializeBySelection === true) {
|
||||
let entityContext = context.streams.selection[md.itemType];
|
||||
if (entityContext) {
|
||||
val = [...entityContext.value];
|
||||
|
|
@ -32,17 +30,15 @@ export default function initializeBySchema(schema, context) {
|
|||
val = []
|
||||
}
|
||||
} 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];
|
||||
if (entityContext) {
|
||||
val = entityContext.value[0];
|
||||
val = entityContext.value[md.initializeBySelection];
|
||||
}
|
||||
} else if (md.type === 'object') {
|
||||
val = initializeBySchema(md.schema, context);
|
||||
} else if (md.type === 'number') {
|
||||
val = md.defaultValue;
|
||||
} else {
|
||||
val = md.defaultValue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,7 @@ export default {
|
|||
sections: {
|
||||
type: 'array',
|
||||
itemType: 'loop',
|
||||
defaultValue: {
|
||||
type: 'selection',
|
||||
}
|
||||
initializeBySelection: true
|
||||
},
|
||||
boolean: {
|
||||
type: 'enum',
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ export default function materializeParams(services, params, schema, result, erro
|
|||
}
|
||||
let value = params[field];
|
||||
if (value === undefined || value === null || value === '') {
|
||||
if (!md.optional && !md.hasOwnProperty('defaultValue')) {
|
||||
if (!md.optional) {
|
||||
errors.push({path: [...parentPath, field], message: 'required'});
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ export default {
|
|||
datum: {
|
||||
type: 'datum',
|
||||
optional: true,
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
},
|
||||
width: {
|
||||
type: 'number',
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ export default {
|
|||
datum: {
|
||||
type: 'datum',
|
||||
optional: true,
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
},
|
||||
radius: {
|
||||
type: 'number',
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ export default {
|
|||
datum: {
|
||||
type: 'datum',
|
||||
optional: true,
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
},
|
||||
radius: {
|
||||
type: 'number',
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
export default {
|
||||
datum: {
|
||||
type: 'datum',
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
}
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ export default {
|
|||
datum: {
|
||||
type: 'datum',
|
||||
optional: true,
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
},
|
||||
radius: {
|
||||
type: 'number',
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ export default {
|
|||
datum: {
|
||||
type: 'datum',
|
||||
optional: true,
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
},
|
||||
radius: {
|
||||
type: 'number',
|
||||
|
|
|
|||
|
|
@ -5,11 +5,11 @@ export default {
|
|||
},
|
||||
face: {
|
||||
type: 'face',
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
},
|
||||
axis: {
|
||||
type: 'sketchObject',
|
||||
defaultValue: {type: 'selection'}
|
||||
initializeBySelection: 0
|
||||
},
|
||||
boolean: {
|
||||
type: 'enum',
|
||||
|
|
|
|||
Loading…
Reference in a new issue