本文整理汇总了TypeScript中@interactjs/utils.is.string方法的典型用法代码示例。如果您正苦于以下问题:TypeScript is.string方法的具体用法?TypeScript is.string怎么用?TypeScript is.string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@interactjs/utils.is
的用法示例。
在下文中一共展示了is.string方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: collectDrops
function collectDrops ({ interactables }, draggableElement) {
const drops = []
// collect all dropzones and their elements which qualify for a drop
for (const dropzone of interactables.list) {
if (!dropzone.options.drop.enabled) { continue }
const accept = dropzone.options.drop.accept
// test the draggable draggableElement against the dropzone's accept setting
if ((utils.is.element(accept) && accept !== draggableElement) ||
(utils.is.string(accept) &&
!utils.dom.matchesSelector(draggableElement, accept)) ||
(utils.is.func(accept) && !accept({ dropzone, draggableElement }))) {
continue
}
// query for new elements if necessary
const dropElements = utils.is.string(dropzone.target)
? dropzone._context.querySelectorAll(dropzone.target)
: utils.is.array(dropzone.target) ? dropzone.target : [dropzone.target]
for (const dropzoneElement of dropElements) {
if (dropzoneElement !== draggableElement) {
drops.push({
dropzone,
element: dropzoneElement,
})
}
}
}
return drops
}
示例2: off
function off (type, listener, options) {
if (utils.is.string(type) && type.search(' ') !== -1) {
type = type.trim().split(/ +/)
}
if (utils.is.array(type)) {
for (const eventType of type) {
interact.off(eventType, listener, options)
}
return interact
}
if (utils.is.object(type)) {
for (const prop in type) {
interact.off(prop, type[prop], listener)
}
return interact
}
if (!utils.arr.contains(scope.actions.eventTypes, type)) {
events.remove(scope.document, type, listener, options)
}
else {
let index
if (type in globalEvents &&
(index = globalEvents[type].indexOf(listener)) !== -1) {
globalEvents[type].splice(index, 1)
}
}
return interact
}
示例3: resizable
function resizable (interactable: Interact.Interactable, options: Interact.OrBoolean<Interact.ResizableOptions> | boolean, scope: Scope) {
if (utils.is.object(options)) {
interactable.options.resize.enabled = options.enabled !== false
interactable.setPerAction('resize', options)
interactable.setOnEvents('resize', options)
if (utils.is.string(options.axis) && /^x$|^y$|^xy$/.test(options.axis)) {
interactable.options.resize.axis = options.axis
}
else if (options.axis === null) {
interactable.options.resize.axis = scope.defaults.actions.resize.axis
}
if (utils.is.bool(options.preserveAspectRatio)) {
interactable.options.resize.preserveAspectRatio = options.preserveAspectRatio
}
else if (utils.is.bool(options.square)) {
interactable.options.resize.square = options.square
}
return interactable
}
if (utils.is.bool(options)) {
interactable.options.resize.enabled = options
return interactable
}
return interactable.options.resize
}
示例4: reflow
function reflow (interactable: Interactable, action: ActionProps, scope: Scope): Promise<Interactable> {
const elements = is.string(interactable.target)
? arr.from(interactable._context.querySelectorAll(interactable.target))
: [interactable.target]
// tslint:disable-next-line variable-name
const Promise = (win.window as any).Promise
const promises: Array<Promise<null>> | null = Promise ? [] : null
for (const element of elements) {
const rect = interactable.getRect(element)
if (!rect) { break }
const runningInteraction = arr.find(
scope.interactions.list,
(interaction: Interaction) => {
return interaction.interacting() &&
interaction.interactable === interactable &&
interaction.element === element &&
interaction.prepared.name === action.name
})
let reflowPromise: Promise<null>
if (runningInteraction) {
runningInteraction.move()
if (promises) {
reflowPromise = runningInteraction._reflowPromise || new Promise((resolve: any) => {
runningInteraction._reflowResolve = resolve
})
}
}
else {
const xywh = rectUtils.tlbrToXywh(rect)
const coords = {
page : { x: xywh.x, y: xywh.y },
client : { x: xywh.x, y: xywh.y },
timeStamp: scope.now(),
}
const event = pointerUtils.coordsToEvent(coords)
reflowPromise = startReflow(scope, interactable, element, action, event)
}
if (promises) {
promises.push(reflowPromise)
}
}
return promises && Promise.all(promises).then(() => interactable)
}
示例5: on
function on (type: string | Interact.EventTypes, listener: Interact.ListenersArg, options?) {
if (utils.is.string(type) && type.search(' ') !== -1) {
type = type.trim().split(/ +/)
}
if (utils.is.array(type)) {
for (const eventType of (type as any[])) {
interact.on(eventType, listener, options)
}
return interact
}
if (utils.is.object(type)) {
for (const prop in type) {
interact.on(prop, (type as Interact.EventTypes)[prop], listener)
}
return interact
}
// if it is an InteractEvent type, add listener to globalEvents
if (utils.arr.contains(scope.actions.eventTypes, type)) {
// if this type of event was never bound
if (!globalEvents[type]) {
globalEvents[type] = [listener]
}
else {
globalEvents[type].push(listener)
}
}
// If non InteractEvent type, addEventListener to document
else {
events.add(scope.document, type, listener as Interact.Listener, { options })
}
return interact
}