@tomino/dynamic-form-semantic-ui
Version:
Semantic UI form renderer based on dynamic form generation
81 lines • 3.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const helpers_1 = require("../../helpers");
const controlVisibility = (controls) => ({ owner }) => {
return controls.indexOf(owner.control) >= 0;
};
const controlInvisibility = (controls) => ({ owner }) => {
return controls.indexOf(owner.control) === -1;
};
const parentControlVisibility = (controls) => ({ owner }) => {
return controls.indexOf(owner.parent.control) >= 0;
};
exports.elementWithSource = ({ owner, context }) => {
const editorElement = context.editorCatalogue.components[owner.control];
return editorElement ? editorElement.bound : false;
};
exports.readonlyElements = controlInvisibility(['Text', 'Image', 'Value']);
exports.textVisibleHandler = controlVisibility(['Text', 'Link']);
exports.gridVisibleHandler = controlVisibility(['Grid']);
exports.verticalVisibleHandler = controlVisibility(['Radio', 'Checkbox']);
exports.parentGridVisibleHandler = parentControlVisibility(['Grid']);
exports.parentStackVisibleHandler = parentControlVisibility(['Stack']);
function clickApproveHandler() {
}
exports.clickApproveHandler = clickApproveHandler;
function buildDatasetPaths(element, parent = '', parentPaths = '') {
let result = [];
let adjustedPath = parentPaths + '.';
for (let key of Object.keys(element.properties || {})) {
let current = element.properties[key];
let parentPath = (parent ? parent + '.' : '') + key;
if (parentPaths) {
if (parentPath.substring(0, adjustedPath.length) === adjustedPath) {
result.push(parentPath.replace(adjustedPath, ''));
}
}
else {
result.push(parentPath);
}
if (current.type === 'object') {
result.push(...buildDatasetPaths(current, parentPath, parentPaths));
}
else if (parentPaths &&
current.type === 'array' &&
current.items &&
current.items.type === 'object') {
result.push(...buildDatasetPaths(current.items, parentPath, parentPaths));
}
}
return result;
}
exports.datasetSource = ({ owner, context }) => {
let parent = owner.parent;
let parentPath = '';
while (parent.parent != null) {
parent = parent.parent;
const control = context.editorCatalogue.components[parent.control];
if (control &&
control.valueProvider &&
parent.props &&
parent.props.value &&
parent.props.value.source) {
parentPath = parent.props.value.source + (parentPath ? '.' : '') + parentPath;
}
}
let schema = helpers_1.schemaDatasetToJS(context.schema);
let paths = buildDatasetPaths(schema, '', parentPath);
let all = buildDatasetPaths(schema);
let array = [{ text: 'Item', value: '__item', disabled: false }];
const values = [{ text: 'None', value: '', disabled: false }]
.concat(array)
.concat(paths.sort().map(p => ({ text: p, value: p, disabled: false })))
.concat(parentPath !== ''
? [{ text: 'GLOBAL', value: '__global', disabled: true }].concat(all.sort().map(p => ({ text: p, value: '/' + p, disabled: false })))
: []);
return values;
};
exports.optionsHandlers = ({ context }) => {
return [{ text: 'None', value: '' }].concat(context.projectHandlers.filter(h => h !== '__esModule').map(h => ({ value: h, text: h })));
};
//# sourceMappingURL=property_panel.handlers.js.map