How to use the @lwc/shared.ArrayIndexOf.call function in @lwc/shared

To help you get started, we’ve selected a few @lwc/shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github salesforce / lwc / packages / @lwc / synthetic-shadow / src / polyfills / mutation-observer / polyfill.ts View on Github external
}
                } else {
                    // In the case of removed nodes, climbing the tree is not an option as the nodes are disconnected
                    // We can only check if either the host or shadow root was observed and qualify the record
                    const shadowRoot = (target as Element).shadowRoot;
                    const sampleNode: Node = removedNodes[0];
                    if (
                        getNodeNearestOwnerKey(target) === getNodeNearestOwnerKey(sampleNode) && // trickery: sampleNode is slot content
                        isQualifiedObserver(observer, target) // use target as a close enough reference to climb up
                    ) {
                        ArrayPush.call(filteredSet, record);
                    } else if (
                        shadowRoot &&
                        shadowRoot[observerLookupField] &&
                        (shadowRoot[observerLookupField][0] === observer ||
                            ArrayIndexOf.call(shadowRoot[observerLookupField], observer) !== -1)
                    ) {
                        ArrayPush.call(filteredSet, retargetMutationRecord(record));
                    }
                }
            } else {
                // Mutation happened under a root node(shadow root or document) and the decision is straighforward
                // Ascend the tree starting from target and check if observer is qualified
                if (isQualifiedObserver(observer, target)) {
                    ArrayPush.call(filteredSet, record);
                }
            }
            return filteredSet;
        },
        []
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / polyfills / mutation-observer / polyfill.ts View on Github external
function isQualifiedObserver(observer: MutationObserver, target: Node): boolean {
    let parentNode: Node | null = target;
    while (!isNull(parentNode)) {
        const parentNodeObservers = parentNode[observerLookupField];
        if (
            !isUndefined(parentNodeObservers) &&
            (parentNodeObservers[0] === observer || // perf optimization to check for the first item is a match
                ArrayIndexOf.call(parentNodeObservers, observer) !== -1)
        ) {
            return true;
        }
        parentNode = parentNode.parentNode;
    }
    return false;
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / faux-shadow / focus.ts View on Github external
function getTabbableSegments(host: HTMLElement): QuerySegments {
    const doc = getOwnerDocument(host);
    const all = arrayFromCollection(documentQuerySelectorAll.call(doc, TabbableElementsQuery));
    const inner = arrayFromCollection(
        querySelectorAll.call(host, TabbableElementsQuery)
    ) as HTMLElement[];
    if (process.env.NODE_ENV !== 'production') {
        assert.invariant(
            getAttribute.call(host, 'tabindex') === '-1' || isDelegatingFocus(host),
            `The focusin event is only relevant when the tabIndex property is -1 on the host.`
        );
    }
    const firstChild = inner[0];
    const lastChild = inner[inner.length - 1];
    const hostIndex = ArrayIndexOf.call(all, host);

    // Host element can show up in our "previous" section if its tabindex is 0
    // We want to filter that out here
    const firstChildIndex = hostIndex > -1 ? hostIndex : ArrayIndexOf.call(all, firstChild);

    // Account for an empty inner list
    const lastChildIndex =
        inner.length === 0 ? firstChildIndex + 1 : ArrayIndexOf.call(all, lastChild) + 1;
    const prev = ArraySlice.call(all, 0, firstChildIndex);
    const next = ArraySlice.call(all, lastChildIndex);
    return {
        prev,
        inner,
        next,
    };
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / faux-shadow / focus.ts View on Github external
const inner = arrayFromCollection(
        querySelectorAll.call(host, TabbableElementsQuery)
    ) as HTMLElement[];
    if (process.env.NODE_ENV !== 'production') {
        assert.invariant(
            getAttribute.call(host, 'tabindex') === '-1' || isDelegatingFocus(host),
            `The focusin event is only relevant when the tabIndex property is -1 on the host.`
        );
    }
    const firstChild = inner[0];
    const lastChild = inner[inner.length - 1];
    const hostIndex = ArrayIndexOf.call(all, host);

    // Host element can show up in our "previous" section if its tabindex is 0
    // We want to filter that out here
    const firstChildIndex = hostIndex > -1 ? hostIndex : ArrayIndexOf.call(all, firstChild);

    // Account for an empty inner list
    const lastChildIndex =
        inner.length === 0 ? firstChildIndex + 1 : ArrayIndexOf.call(all, lastChild) + 1;
    const prev = ArraySlice.call(all, 0, firstChildIndex);
    const next = ArraySlice.call(all, lastChildIndex);
    return {
        prev,
        inner,
        next,
    };
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / faux-shadow / events.ts View on Github external
function detachDOMListener(elm: Element, type: string, wrappedListener: WrappedListener) {
    const listenerMap = getEventMap(elm);
    let p: number;
    let listeners: EventListener[] | undefined;
    if (
        !isUndefined((listeners = listenerMap[type])) &&
        (p = ArrayIndexOf.call(listeners, wrappedListener)) !== -1
    ) {
        ArraySplice.call(listeners, p, 1);
        // only remove from DOM if there is no other listener on the same placement
        if (listeners!.length === 0) {
            removeEventListener.call(elm, type, domListener);
        }
    }
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / faux-shadow / focus.ts View on Github external
assert.invariant(
            getAttribute.call(host, 'tabindex') === '-1' || isDelegatingFocus(host),
            `The focusin event is only relevant when the tabIndex property is -1 on the host.`
        );
    }
    const firstChild = inner[0];
    const lastChild = inner[inner.length - 1];
    const hostIndex = ArrayIndexOf.call(all, host);

    // Host element can show up in our "previous" section if its tabindex is 0
    // We want to filter that out here
    const firstChildIndex = hostIndex > -1 ? hostIndex : ArrayIndexOf.call(all, firstChild);

    // Account for an empty inner list
    const lastChildIndex =
        inner.length === 0 ? firstChildIndex + 1 : ArrayIndexOf.call(all, lastChild) + 1;
    const prev = ArraySlice.call(all, 0, firstChildIndex);
    const next = ArraySlice.call(all, lastChildIndex);
    return {
        prev,
        inner,
        next,
    };
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / polyfills / mutation-observer / polyfill.ts View on Github external
forEach.call(observedNodes, observedNode => {
            const observers = observedNode[observerLookupField];
            if (!isUndefined(observers)) {
                const index = ArrayIndexOf.call(observers, this);
                if (index !== -1) {
                    ArraySplice.call(observers, index, 1);
                }
            }
        });
        observedNodes.length = 0;