本文整理汇总了TypeScript中@ephox/alloy.NativeEvents类的典型用法代码示例。如果您正苦于以下问题:TypeScript NativeEvents类的具体用法?TypeScript NativeEvents怎么用?TypeScript NativeEvents使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NativeEvents类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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();
}
});
};
示例2: 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);
})
])
])
})
};
};
示例3: 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([ ]))
)
};
};
示例4: 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
});
示例5:
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})
])
});
};
示例6: function
const triggerTab = function (placeholder, shiftKey) {
AlloyTriggers.emitWith(placeholder, NativeEvents.keydown(), {
raw: {
which: 9,
shiftKey
}
});
};
示例7: 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]])
});
};
示例8: componentRenderPipeline
const renderCommonChoice = <T>(spec: CommonCollectionItemSpec, structure: ItemStructure, itemResponse: ItemResponse): AlloySpec => {
return Button.sketch({
dom: structure.dom,
components: componentRenderPipeline(structure.optComponents),
eventOrder: menuItemEventOrder,
buttonBehaviours: Behaviour.derive(
[
AddEventsBehaviour.config('item-events', [
AlloyEvents.run(NativeEvents.mouseover(), Focusing.focus)
]),
DisablingConfigs.item(spec.disabled)
]
),
action: spec.onAction
});
};
示例9:
const initCommonEvents = (fireApiEvent: <E extends CustomEvent>(name: string, f: Function) => any, extras: ExtraListeners) => {
return [
// When focus moves onto a tab-placeholder, skip to the next thing in the tab sequence
AlloyEvents.runWithTarget(NativeEvents.focusin(), NavigableObject.onFocus),
// TODO: Test if disabled first.
fireApiEvent<FormCloseEvent>(formCloseEvent, (api, spec) => {
extras.onClose();
spec.onClose();
}),
// TODO: Test if disabled first.
fireApiEvent<FormCancelEvent>(formCancelEvent, (api, spec, _event, self) => {
spec.onCancel(api);
AlloyTriggers.emit(self, formCloseEvent);
}),
AlloyEvents.run<FormUnblockEvent>(formUnblockEvent, (c, se) => extras.onUnblock()),
AlloyEvents.run<FormBlockEvent>(formBlockEvent, (c, se) => extras.onBlock(se.event()))
];
};
示例10: function
Form.sketch(function (parts) {
return {
dom: UiDomFactory.dom('<div class="${prefix}-serialised-dialog"></div>'),
components: [
Container.sketch({
dom: UiDomFactory.dom('<div class="${prefix}-serialised-dialog-chain" style="left: 0px; position: absolute;"></div>'),
components: Arr.map(spec.fields, function (field, i) {
return i <= spec.maxFieldIndex ? Container.sketch({
dom: UiDomFactory.dom('<div class="${prefix}-serialised-dialog-screen"></div>'),
components: [
navigationButton(-1, 'previous', (i > 0)),
parts.field(field.name, field.spec),
navigationButton(+1, 'next', (i < spec.maxFieldIndex))
]
}) : parts.field(field.name, field.spec);
})
})
],
formBehaviours: Behaviour.derive([
Receivers.orientation(function (dialog, message) {
reposition(dialog, message);
}),
Keying.config({
mode: 'special',
focusIn (dialog/*, specialInfo */) {
focusInput(dialog);
},
onTab (dialog/*, specialInfo */) {
navigate(dialog, +1);
return Option.some(true);
},
onShiftTab (dialog/*, specialInfo */) {
navigate(dialog, -1);
return Option.some(true);
}
}),
AddEventsBehaviour.config(formAdhocEvents, [
AlloyEvents.runOnAttached(function (dialog, simulatedEvent) {
// Reset state to first screen.
resetState();
const dotitems = memDots.get(dialog);
Highlighting.highlightFirst(dotitems);
spec.getInitialValue(dialog).each(function (v) {
Representing.setValue(dialog, v);
});
}),
AlloyEvents.runOnExecute(spec.onExecute),
AlloyEvents.run(NativeEvents.transitionend(), function (dialog, simulatedEvent) {
const event = simulatedEvent.event() as any;
if (event.raw().propertyName === 'left') {
focusInput(dialog);
}
}),
AlloyEvents.run(navigateEvent, function (dialog, simulatedEvent) {
const event = simulatedEvent.event() as any;
const direction = event.direction();
navigate(dialog, direction);
})
])
])
};
})