Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const renderListbox = (spec: ListboxFoo, providersBackstage: UiFactoryBackstageProviders): SketchSpec => {
const pLabel = renderLabel(spec.label, providersBackstage);
const pField = AlloyFormField.parts().field({
factory: HtmlSelect,
dom: {
classes: [ 'mce-select-field' ]
},
selectBehaviours: Behaviour.derive([
Tabstopping.config({ })
]),
options: spec.values,
// FIX: Don't use undefined here.
data: spec.initialValue.getOr(undefined)
});
return renderFormField(Option.some(pLabel), pField);
};
value: item.value
};
});
// DUPE with TextField.
const pLabel = spec.label.map((label) => renderLabel(label, providersBackstage));
const pField = AlloyFormField.parts().field({
// TODO: Alloy should not allow dom changing of an HTML select!
dom: { },
selectAttributes: {
size: spec.size
},
options: translatedOptions,
factory: AlloyHtmlSelect,
selectBehaviours: Behaviour.derive([
Disabling.config({ disabled: spec.disabled }),
Tabstopping.config({ }),
AddEventsBehaviour.config('selectbox-change', [
AlloyEvents.run(NativeEvents.change(), (component, _) => {
AlloyTriggers.emitWith(component, formChangeEvent, { name: spec.name } );
})
])
])
});
const chevron: Option = spec.size > 1 ? Option.none() :
Option.some({
dom: {
tag: 'div',
classes: ['tox-selectfield__icon-js'],
innerHtml: Icons.get('chevron-down', providersBackstage.icons)
tabbarBehaviours: Behaviour.derive([
Tabstopping.config({ })
])
}),
AlloyTabSection.parts().tabview({
dom: {
tag: 'div',
classes: [ 'tox-dialog__body-content' ]
}
})
],
selectFirst: tabMode.selectFirst,
tabSectionBehaviours: Behaviour.derive([
AddEventsBehaviour.config('tabpanel', tabMode.extraEvents),
Keying.config({
mode: 'acyclic'
}),
// INVESTIGATE: Is this necessary? Probably used by getCompByName.
Composing.config({
// TODO: Think about this
find: (comp) => Arr.head(AlloyTabSection.getViewItems(comp))
}),
Representing.config({
store: {
mode: 'manual',
getValue: (tsection: AlloyComponent) => {
// NOTE: Assumes synchronous updating of store.
tsection.getSystem().broadcastOn([ SendDataToSectionChannel ], { });
role: 'presentation'
}
},
onValidHex,
onInvalidHex
})
);
return {
dom: {
tag: 'div'
},
components: [
memPicker.asSpec()
],
behaviours: Behaviour.derive([
// We'll allow invalid values
Representing.config({
store: {
mode: 'manual',
getValue: (comp) => {
const picker = memPicker.get(comp);
const optRgbForm = Composing.getCurrent(picker);
const optHex = optRgbForm.bind((rgbForm) => {
const formValues = Representing.getValue(rgbForm);
return formValues.hex as Option;
}) ;
return optHex.map((hex) => '#' + hex).getOr('');
},
setValue: (comp, newValue) => {
const pattern = /^#([a-fA-F0-9]{3}(?:[a-fA-F0-9]{3})?)/;
const m = pattern.exec(newValue);
memInvalidIcon.asSpec()
]
});
const optUrlPicker = urlBackstage.getUrlPicker(spec.filetype);
const browseUrlEvent = Id.generate('browser.url.event');
const memUrlBox = Memento.record(
{
dom: {
tag: 'div',
classes: ['tox-control-wrap']
},
components: [pField, memStatus.asSpec()],
behaviours: Behaviour.derive([
Disabling.config({ disabled: spec.disabled })
])
}
);
const memUrlPickerButton = Memento.record(renderButton({
name: spec.name,
icon: Option.some('browse'),
text: spec.label.getOr(''),
disabled: spec.disabled,
primary: false,
borderless: true
}, (component) => AlloyTriggers.emit(component, browseUrlEvent), providersBackstage, [], ['tox-browse-url']));
const controlHWrapper = (): AlloySpec => {
return {
tag: 'div',
classes: [ 'tox-form__group' ],
innerHtml: spec.html
}
});
} else {
return AlloyContainer.sketch({
dom: {
tag: 'div',
classes: [ 'tox-form__group' ],
innerHtml: spec.html,
attributes: {
role: 'document'
}
},
containerBehaviours: Behaviour.derive([
Tabstopping.config({ }),
Focusing.config({ })
])
});
}
};
AlloyForm.sketch((parts) => {
return {
dom: {
tag: 'div',
classes: [ 'tox-form' ]
},
components: Arr.map(tab.items, (item) => interpretInForm(parts, item, backstage)),
formBehaviours: Behaviour.derive([
Keying.config({
mode: 'acyclic',
useTabstopAt: Fun.not(NavigableObject.isPseudoStop)
}),
AddEventsBehaviour.config('TabView.form.events', [
AlloyEvents.runOnAttached(setDataOnForm),
AlloyEvents.runOnDetached(updateDataWithForm)
]),
Receiving.config({
channels: Objects.wrapAll([
{
key: SendDataToSectionChannel,
value: {
onReceive: updateDataWithForm
}
{
dom: {
tag: 'span',
classes: ['tox-icon', 'tox-lock-icon__lock'],
innerHtml: Icons.get('lock', providersBackstage.icons)
}
},
{
dom: {
tag: 'span',
classes: ['tox-icon', 'tox-lock-icon__unlock'],
innerHtml: Icons.get('unlock', providersBackstage.icons)
}
}
],
buttonBehaviours: Behaviour.derive([
DisablingConfigs.button(spec.disabled),
Tabstopping.config({})
])
});
const formGroup = (components) => {
return {
dom: {
tag: 'div',
classes: [ 'tox-form__group' ]
},
components
};
};
const getFieldPart = (isField1) => AlloyFormField.parts().field({
makeIcon('unchecked')
]
}
);
return AlloyFormField.sketch({
dom: {
tag: 'label',
classes: ['tox-checkbox'],
},
components: [
pField,
memIcons.asSpec(),
pLabel
],
fieldBehaviours: Behaviour.derive([
Disabling.config({
disabled: spec.disabled,
disableClass: 'tox-checkbox--disabled',
onDisabled: (comp) => {
AlloyFormField.getField(comp).each(Disabling.disable);
},
onEnabled: (comp) => {
AlloyFormField.getField(comp).each(Disabling.enable);
}
})
])
});
};
const result = vl.validator(v);
return Future.pure(result === true ? Result.value(v) : Result.error(result));
},
validateOnLoad: vl.validateOnLoad
}
});
}).toArray();
const pField = AlloyFormField.parts().field({
tag: spec.multiline === true ? 'textarea' : 'input',
inputAttributes: spec.placeholder.fold(
() => {},
(placeholder) => ({ placeholder: providersBackstage.translate(placeholder) })
),
inputClasses: [spec.classname],
inputBehaviours: Behaviour.derive(
Arr.flatten>([
baseInputBehaviours,
validatingBehaviours
])
),
selectOnFocus: false,
factory: AlloyInput
});
const extraClasses = spec.flex ? ['tox-form__group--stretched'] : [];
const extraClasses2 = extraClasses.concat(spec.maximized ? ['tox-form-group--maximize'] : []);
const extraBehaviours = [
Disabling.config({
disabled: spec.disabled,
onDisabled: (comp) => {