本文整理匯總了TypeScript中@ephox/alloy.AlloyEvents.run方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript AlloyEvents.run方法的具體用法?TypeScript AlloyEvents.run怎麽用?TypeScript AlloyEvents.run使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ephox/alloy.AlloyEvents
的用法示例。
在下文中一共展示了AlloyEvents.run方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1:
const makeCell = (row, col, labelId) => {
const emitCellOver = (c) => AlloyTriggers.emitWith(c, cellOverEvent, {row, col} );
const emitExecute = (c) => AlloyTriggers.emitWith(c, cellExecuteEvent, {row, col} );
return GuiFactory.build({
dom: {
tag: 'div',
attributes: {
role: 'button',
['aria-labelledby']: labelId
}
},
behaviours: Behaviour.derive([
AddEventsBehaviour.config('insert-table-picker-cell', [
AlloyEvents.run(NativeEvents.mouseover(), Focusing.focus),
AlloyEvents.run(SystemEvents.execute(), emitExecute),
AlloyEvents.run(SystemEvents.tapOrClick(), emitExecute)
]),
Toggling.config({
toggleClass: 'tox-insert-table-picker__selected',
toggleOnExecute: false
}),
Focusing.config({onFocus: emitCellOver})
])
});
};
示例2:
const renderDialog = (spec: DialogFoo) => {
return ModalDialog.sketch(
{
lazySink: spec.lazySink,
onEscape: () => {
spec.onCancel();
// TODO: Make a strong type for Handled KeyEvent
return Option.some(true);
},
dom: {
tag: 'div',
classes: [ 'tox-dialog' ].concat(spec.extraClasses)
},
components: [
{
dom: {
tag: 'div',
classes: [ 'tox-dialog__header' ]
},
components: [
spec.partSpecs.title,
spec.partSpecs.close
]
},
spec.partSpecs.body,
spec.partSpecs.footer
],
parts: {
blocker: {
dom: DomFactory.fromHtml('<div class="tox-dialog-wrap"></div>'),
components: [
{
dom: {
tag: 'div',
classes: [ 'tox-dialog-wrap__backdrop' ]
}
}
]
}
},
modalBehaviours: Behaviour.derive([
// Dupe warning.
AddEventsBehaviour.config('basic-dialog-events', [
AlloyEvents.run<FormCancelEvent>(formCancelEvent, (comp, se) => {
spec.onCancel();
}),
AlloyEvents.run<FormSubmitEvent>(formSubmitEvent, (comp, se) => {
spec.onSubmit();
}),
])
])
}
);
};
示例3: withSpec
const fireApiEvent = <E extends CustomEvent>(eventName: string, f: (api: Types.Dialog.DialogInstanceApi<T>, spec: Types.Dialog.Dialog<T>, e: E, c: AlloyComponent) => void) => {
return AlloyEvents.run<E>(eventName, (c, se) => {
withSpec(c, (spec, _c) => {
f(getInstanceApi(), spec, se.event(), c);
});
});
};
示例4: function
const field = function (name, placeholder) {
const inputSpec = Memento.record(Input.sketch({
placeholder,
onSetValue (input, data) {
// If the value changes, inform the container so that it can update whether the "x" is visible
AlloyTriggers.emit(input, NativeEvents.input());
},
inputBehaviours: Behaviour.derive([
Composing.config({
find: Option.some
}),
Tabstopping.config({ }),
Keying.config({
mode: 'execution'
})
]),
selectOnFocus: false
}));
const buttonSpec = Memento.record(
Button.sketch({
dom: UiDomFactory.dom('<button class="${prefix}-input-container-x ${prefix}-icon-cancel-circle ${prefix}-icon"></button>'),
action (button) {
const input = inputSpec.get(button);
Representing.setValue(input, '');
}
})
);
return {
name,
spec: Container.sketch({
dom: UiDomFactory.dom('<div class="${prefix}-input-container"></div>'),
components: [
inputSpec.asSpec(),
buttonSpec.asSpec()
],
containerBehaviours: Behaviour.derive([
Toggling.config({
toggleClass: Styles.resolve('input-container-empty')
}),
Composing.config({
find (comp) {
return Option.some(inputSpec.get(comp));
}
}),
AddEventsBehaviour.config(clearInputBehaviour, [
// INVESTIGATE: Because this only happens on input,
// it won't reset unless it has an initial value
AlloyEvents.run(NativeEvents.input(), function (iContainer) {
const input = inputSpec.get(iContainer);
const val = Representing.getValue(input);
const f = val.length > 0 ? Toggling.off : Toggling.on;
f(iContainer);
})
])
])
})
};
};
示例5: function
const getFieldPart = (isField1) => AlloyFormField.parts().field({
factory: AlloyInput,
inputClasses: ['tox-textfield'],
inputBehaviours: Behaviour.derive([
Tabstopping.config({}),
AddEventsBehaviour.config('size-input-events', [
AlloyEvents.run(NativeEvents.focusin(), function (component, simulatedEvent) {
AlloyTriggers.emitWith(component, ratioEvent, { isField1 });
}),
AlloyEvents.run(NativeEvents.change(), function (component, simulatedEvent) {
AlloyTriggers.emitWith(component, formChangeEvent, { name: spec.name });
})
])
]),
selectOnFocus: false
});
示例6: function
const sketch = function (editor): SketchSpec {
const pickerDom = {
tag: 'input',
attributes: { accept: 'image/*', type: 'file', title: '' },
// Visibility hidden so that it cannot be seen, and position absolute so that it doesn't
// disrupt the layout
styles: { visibility: 'hidden', position: 'absolute' }
};
const memPicker = Memento.record({
dom: pickerDom,
events: AlloyEvents.derive([
// Stop the event firing again at the button level
AlloyEvents.cutter(NativeEvents.click()),
AlloyEvents.run(NativeEvents.change(), function (picker, simulatedEvent) {
extractBlob(simulatedEvent).each(function (blob) {
addImage(editor, blob);
});
})
])
});
return Button.sketch({
dom: Buttons.getToolbarIconButton('image', editor),
components: [
memPicker.asSpec()
],
action (button) {
const picker = memPicker.get(button);
// Trigger a dom click for the file input
picker.element().dom().click();
}
});
};
示例7: variableFilterPanelComponents
const createVariableFilterPanel = (label: string, transform: (ir: ImageResult, adjust: number) => Promise<ImageResult>, min: number, value: number, max: number) => {
const filterPanelComponents = variableFilterPanelComponents(label, transform, min, value, max);
return Container.sketch({
dom: panelDom,
components: filterPanelComponents.map((mem) => mem.asSpec()),
containerBehaviours: Behaviour.derive([
AddEventsBehaviour.config('image-tools-filter-panel-buttons-events', [
AlloyEvents.run(ImageToolsEvents.external.disable(), (comp, se) => {
disableAllComponents(filterPanelComponents, comp);
}),
AlloyEvents.run(ImageToolsEvents.external.enable(), (comp, se) => {
enableAllComponents(filterPanelComponents, comp);
})
])
])
});
};
示例8: getNodeAnchor
export const setup = (editor: Editor, lazySink: () => Result<AlloyComponent, Error>, backstage: UiFactoryBackstage) => {
const contextmenu = GuiFactory.build(
InlineView.sketch({
dom: {
tag: 'div',
},
lazySink,
onEscape: () => editor.focus(),
fireDismissalEventInstead: { },
inlineBehaviours: Behaviour.derive([
AddEventsBehaviour.config('dismissContextMenu', [
AlloyEvents.run(SystemEvents.dismissRequested(), (comp, se) => {
Sandboxing.close(comp);
editor.focus();
})
])
])
}),
);
editor.on('init', () => {
editor.on('contextmenu', (e) => {
if (isNativeOverrideKeyEvent(editor, e)) {
return;
}
// Different browsers trigger the context menu from keyboards differently, so need to check both the button and target here
// Chrome: button = 0 & target = the selection range node
// Firefox: button = 0 & target = body
// IE: button = 2 & target = body
// Safari: N/A (Mac's don't expose a contextmenu keyboard shortcut)
const isTriggeredByKeyboardEvent = e.button !== 2 || e.target === editor.getBody();
const anchorSpec = isTriggeredByKeyboardEvent ? getNodeAnchor(editor) : getPointAnchor(editor, e);
const registry = editor.ui.registry.getAll();
const menuConfig = Settings.getContextMenu(editor);
// Use the event target element for mouse clicks, otherwise fallback to the current selection
const selectedElement = isTriggeredByKeyboardEvent ? editor.selection.getStart(true) : e.target as Element;
const items = generateContextMenu(registry.contextMenus, menuConfig, selectedElement);
NestedMenus.build(items, ItemResponse.CLOSE_ON_EXECUTE, backstage).map((menuData) => {
e.preventDefault();
// show the context menu, with items set to close on click
InlineView.showMenuAt(contextmenu, anchorSpec, {
menu: {
markers: MenuParts.markers('normal')
},
data: menuData
});
});
});
});
};
示例9: renderLabel
export const renderSelectBox = (spec: Types.SelectBox.SelectBox, providersBackstage: UiFactoryBackstageProviders): SketchSpec => {
const translatedOptions = Arr.map(spec.items, (item) => {
return {
text: providersBackstage.translate(item.text),
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([
Tabstopping.config({ }),
AddEventsBehaviour.config('selectbox-change', [
AlloyEvents.run(NativeEvents.change(), (component, _) => {
AlloyTriggers.emitWith(component, formChangeEvent, { name: spec.name } );
})
])
])
});
const chevron = spec.size > 1 ? Option.none() :
Option.some({
dom: {
tag: 'div',
classes: ['tox-selectfield__icon-js'],
innerHtml: Icons.get('chevron-down', providersBackstage.icons)
}
});
const selectWrap: SimpleSpec = {
dom: {
tag: 'div',
classes: ['tox-selectfield']
},
components: Arr.flatten([[pField], chevron.toArray()])
};
return AlloyFormField.sketch({
dom: {
tag: 'div',
classes: ['tox-form__group']
},
components: Arr.flatten<AlloySpec>([pLabel.toArray(), [selectWrap]])
});
};
示例10: getTooltipAttributes
const renderCommonStructure = (icon: Option<string>, text: Option<string>, tooltip: Option<string>, receiver: Option<string>, behaviours: Option<Behaviour.NamedConfiguredBehaviour<Behaviour.BehaviourConfigSpec, Behaviour.BehaviourConfigDetail>[]>, providersBackstage: UiFactoryBackstageProviders) => {
// If RTL and icon is in whitelist, add RTL icon class for icons that don't have a `-rtl` icon available.
// Use `-rtl` icon suffix for icons that do.
const getIconName = (iconName: string): string => {
return I18n.isRtl() && Arr.contains(rtlIcon, iconName) ? iconName + '-rtl' : iconName;
};
const needsRtlClass = I18n.isRtl() && icon.exists((name) => Arr.contains(rtlTransform, name));
return {
dom: {
tag: 'button',
classes: [ ToolbarButtonClasses.Button ].concat(text.isSome() ? [ ToolbarButtonClasses.MatchWidth ] : []).concat(needsRtlClass ? [ ToolbarButtonClasses.IconRtl ] : []),
attributes: getTooltipAttributes(tooltip, providersBackstage)
},
components: componentRenderPipeline([
icon.map((iconName) => renderIconFromPack(getIconName(iconName), providersBackstage.icons)),
text.map((text) => renderLabel(text, ToolbarButtonClasses.Button, providersBackstage))
]),
eventOrder: {
[NativeEvents.mousedown()]: [
'focusing',
'alloy.base.behaviour',
'common-button-display-events'
]
},
buttonBehaviours: Behaviour.derive(
[
AddEventsBehaviour.config('common-button-display-events', [
AlloyEvents.run(NativeEvents.mousedown(), (button, se) => {
se.event().prevent();
AlloyTriggers.emit(button, focusButtonEvent);
})
])
].concat(
receiver.map((r) => {
return Reflecting.config({
channel: r,
initialData: { icon, text },
renderComponents: (data, _state) => {
return componentRenderPipeline([
data.icon.map((iconName) => renderIconFromPack(getIconName(iconName), providersBackstage.icons)),
data.text.map((text) => renderLabel(text, ToolbarButtonClasses.Button, providersBackstage))
]);
}
});
}).toArray()
).concat(behaviours.getOr([ ]))
)
};
};