本文整理汇总了TypeScript中@ephox/alloy.NativeEvents.focusin方法的典型用法代码示例。如果您正苦于以下问题:TypeScript NativeEvents.focusin方法的具体用法?TypeScript NativeEvents.focusin怎么用?TypeScript NativeEvents.focusin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@ephox/alloy.NativeEvents
的用法示例。
在下文中一共展示了NativeEvents.focusin方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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
});
示例2:
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()))
];
};
示例3: renderLabel
export const renderCollection = (spec: Types.Collection.Collection, providersBackstage: UiFactoryBackstageProviders): SketchSpec => {
// DUPE with TextField.
const pLabel = spec.label.map((label) => renderLabel(label, providersBackstage));
const runOnItem = (f: (c: AlloyComponent, tgt: Element, itemValue: string) => void) => <T extends EventFormat>(comp: AlloyComponent, se: SimulatedEvent<T>) => {
SelectorFind.closest(se.event().target(), '[data-collection-item-value]').each((target) => {
f(comp, target, Attr.get(target, 'data-collection-item-value'));
});
};
const escapeAttribute = (ch) => {
if (ch === '"') { return '"'; }
return ch;
};
const setContents = (comp, items) => {
const htmlLines = Arr.map(items, (item) => {
const textContent = spec.columns === 1 ? `<div class="tox-collection__item-label">${item.text}</div>` : '';
const iconContent = `<div class="tox-collection__item-icon">${item.icon}</div>`;
// Replacing the hyphens and underscores in collection items with spaces
// to ensure the screen readers pronounce the words correctly.
// This is only for aria purposes. Emoticon and Special Character names will still use _ and - for autocompletion.
const mapItemName = {
'_': ' ',
' - ': ' ',
'-': ' '
};
// Title attribute is added here to provide tooltips which might be helpful to sighted users.
// Using aria-label here overrides the Apple description of emojis and special characters in Mac/ MS description in Windows.
// But if only the title attribute is used instead, the names are read out twice. i.e., the description followed by the item.text.
const ariaLabel = item.text.replace(/\_| \- |\-/g, (match) => {
return mapItemName[match];
});
return `<div class="tox-collection__item" tabindex="-1" data-collection-item-value="${escapeAttribute(item.value)}" title="${ariaLabel}" aria-label="${ariaLabel}">${iconContent}${textContent}</div>`;
});
const chunks = spec.columns > 1 && spec.columns !== 'auto' ? Arr.chunk(htmlLines, spec.columns) : [ htmlLines ];
const html = Arr.map(chunks, (ch) => {
return `<div class="tox-collection__group">${ch.join('')}</div>`;
});
Html.set(comp.element(), html.join(''));
};
const collectionEvents = [
AlloyEvents.run<SugarEvent>(NativeEvents.mouseover(), runOnItem((comp, tgt) => {
Focus.focus(tgt);
})),
AlloyEvents.run<SugarEvent>(SystemEvents.tapOrClick(), runOnItem((comp, tgt, itemValue) => {
AlloyTriggers.emitWith(comp, formActionEvent, {
name: spec.name,
value: itemValue
});
})),
AlloyEvents.run(NativeEvents.focusin(), runOnItem((comp, tgt, itemValue) => {
SelectorFind.descendant(comp.element(), '.' + ItemClasses.activeClass).each((currentActive) => {
Class.remove(currentActive, ItemClasses.activeClass);
});
Class.add(tgt, ItemClasses.activeClass);
})),
AlloyEvents.run(NativeEvents.focusout(), runOnItem((comp, tgt, itemValue) => {
SelectorFind.descendant(comp.element(), '.' + ItemClasses.activeClass).each((currentActive) => {
Class.remove(currentActive, ItemClasses.activeClass);
});
})),
AlloyEvents.runOnExecute(runOnItem((comp, tgt, itemValue) => {
AlloyTriggers.emitWith(comp, formActionEvent, {
name: spec.name,
value: itemValue
});
}))
];
const pField = AlloyFormField.parts().field({
dom: {
tag: 'div',
// FIX: Read from columns
classes: [ 'tox-collection' ].concat(spec.columns !== 1 ? [ 'tox-collection--grid' ] : [ 'tox-collection--list' ])
},
components: [ ],
factory: { sketch: Fun.identity },
behaviours: Behaviour.derive([
Replacing.config({ }),
Representing.config({
store: {
mode: 'memory',
initialValue: [ ]
},
onSetValue: (comp, items) => {
setContents(comp, items);
if (spec.columns === 'auto') {
detectSize(comp, 5, 'tox-collection__item').each(({ numRows, numColumns }) => {
Keying.setGridSize(comp, numRows, numColumns);
});
}
AlloyTriggers.emit(comp, formResizeEvent);
//.........这里部分代码省略.........
示例4: onEscape
const renderModalDialog = (spec: DialogSpec, initialData, dialogEvents: AlloyEvents.AlloyEventKeyAndHandler<any>[], backstage: UiFactoryBackstage) => {
const updateState = (_comp, incoming) => {
return Option.some(incoming);
};
return GuiFactory.build(
ModalDialog.sketch({
lazySink: backstage.shared.getSink,
// TODO: Disable while validating
onEscape(c) {
AlloyTriggers.emit(c, formCancelEvent);
return Option.some(true);
},
useTabstopAt: (elem) => {
return !NavigableObject.isPseudoStop(elem) && (
Node.name(elem) !== 'button' || Attr.get(elem, 'disabled') !== 'disabled'
);
},
modalBehaviours: Behaviour.derive([
Reflecting.config({
channel: dialogChannel,
updateState,
initialData
}),
RepresentingConfigs.memory({ }),
Focusing.config({}),
AddEventsBehaviour.config('execute-on-form', dialogEvents.concat([
AlloyEvents.runOnSource(NativeEvents.focusin(), (comp, se) => {
Keying.focusIn(comp);
})
])),
AddEventsBehaviour.config('scroll-lock', [
AlloyEvents.runOnAttached(() => {
Class.add(Body.body(), 'tox-dialog__disable-scroll');
}),
AlloyEvents.runOnDetached(() => {
Class.remove(Body.body(), 'tox-dialog__disable-scroll');
}),
]),
...spec.extraBehaviours
]),
eventOrder: {
[SystemEvents.execute()]: [ 'execute-on-form' ],
[SystemEvents.receive()]: [ 'reflecting', 'receiving' ],
[SystemEvents.attachedToDom()]: [ 'scroll-lock', 'reflecting', 'messages', 'execute-on-form', 'alloy.base.behaviour' ],
[SystemEvents.detachedFromDom()]: [ 'alloy.base.behaviour', 'execute-on-form', 'messages', 'reflecting', 'scroll-lock' ],
},
dom: {
tag: 'div',
classes: [ 'tox-dialog' ].concat(spec.extraClasses),
styles: {
position: 'relative',
...spec.extraStyles
}
},
components: [
spec.header,
spec.body,
...spec.footer.toArray()
],
dragBlockClass: 'tox-dialog-wrap',
parts: {
blocker: {
dom: DomFactory.fromHtml('<div class="tox-dialog-wrap"></div>'),
components: [
{
dom: {
tag: 'div',
classes: [ 'tox-dialog-wrap__backdrop' ]
}
}
]
}
}
})
);
};