How to use the @lwc/shared.ArraySlice.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 / HTMLSlotElement / polyfill.ts View on Github external
value: function(
            this: Document,
            tagName: K,
            _options?: ElementCreationOptions
        ): HTMLElementTagNameMap[K] | HTMLElement {
            const elm = createElement.apply(
                this,
                ArraySlice.call(arguments) as [string, ElementCreationOptions?]
            );
            if (
                tagName.length === 4 &&
                StringCharCodeAt.call(tagName, 0) === CHAR_S &&
                StringCharCodeAt.call(tagName, 1) === CHAR_L &&
                StringCharCodeAt.call(tagName, 2) === CHAR_O &&
                StringCharCodeAt.call(tagName, 3) === CHAR_T
            ) {
                // the new element is the `slot`, resetting the proto chain
                // the new newly created global HTMLSlotElement.prototype
                setPrototypeOf(elm, HTMLSlotElement.prototype);
            }
            return elm;
        },
    });
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / polyfills / window-event-target / polyfill.ts View on Github external
function addEventListenerPatched(
    this: Window,
    _type: string,
    listener: EventListenerOrEventListenerObject | null,
    _options?: boolean | AddEventListenerOptions
) {
    if (listener == null) {
        return; /* nullish */
    }
    const args = ArraySlice.call(arguments);
    args[1] = getEventListenerWrapper(listener);
    windowAddEventListener.apply(this, args as [
        string,
        EventListener,
        (EventListenerOptions | boolean | undefined)?
    ]);
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / faux-shadow / focus.ts View on Github external
`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 / window-event-target / polyfill.ts View on Github external
function removeEventListenerPatched(
    this: Window,
    _type: string,
    listener: EventListenerOrEventListenerObject | null,
    _options?: EventListenerOptions | boolean
) {
    if (listener == null) {
        return; /* nullish */
    }
    const args = ArraySlice.call(arguments);
    args[1] = getEventListenerWrapper(listener);
    windowRemoveEventListener.apply(this, args as [
        string,
        EventListener,
        (EventListenerOptions | boolean | undefined)?
    ]);
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / polyfills / event-target / polyfill.ts View on Github external
function removeEventListenerPatched(
    this: Element,
    _type: string,
    listener: EventListenerOrEventListenerObject | null,
    _options?: EventListenerOptions | boolean
) {
    if (listener == null) {
        return; /* nullish */
    }
    const args = ArraySlice.call(arguments);
    args[1] = getEventListenerWrapper(listener);
    if (isHostElement(this)) {
        removeCustomElementEventListener.apply(this, args as [
            string,
            EventListener,
            (EventListenerOptions | boolean | undefined)?
        ]);
    } else {
        superRemoveEventListener.apply(this, args as [
            string,
            EventListener,
            (EventListenerOptions | boolean | undefined)?
        ]);
    }
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / faux-shadow / element.ts View on Github external
if (!isUndefined(ownerKey)) {
            // context is handled by lwc, using getNodeNearestOwnerKey to include manually inserted elements in the same shadow.
            filtered = ArrayFilter.call(
                unfilteredNodes,
                elm => getNodeNearestOwnerKey(elm) === ownerKey
            );
        } else if (shadowDomSemantic === ShadowDomSemantic.Enabled) {
            // context is inside a shadow, we dont know which one.
            const contextNearestOwnerKey = getNodeNearestOwnerKey(context);
            filtered = ArrayFilter.call(
                unfilteredNodes,
                elm => getNodeNearestOwnerKey(elm) === contextNearestOwnerKey
            );
        } else {
            // context is manually inserted without lwc:dom-manual and ShadowDomSemantics is off, return everything
            filtered = ArraySlice.call(unfilteredNodes);
        }
    } else {
        if (context instanceof HTMLBodyElement || shadowDomSemantic === ShadowDomSemantic.Enabled) {
            // `context` is document.body or element belonging to the document with the patch enabled
            filtered = ArrayFilter.call(
                unfilteredNodes,
                // TODO [#1222]: remove global bypass
                elm => isUndefined(getNodeOwnerKey(elm)) || isGlobalPatchingSkipped(context)
            );
        } else {
            // `context` is outside the lwc boundary and patch is not enabled.
            filtered = ArraySlice.call(unfilteredNodes);
        }
    }
    return filtered;
}
github salesforce / lwc / packages / @lwc / synthetic-shadow / src / faux-shadow / focus.ts View on Github external
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 / engine / src / framework / api.ts View on Github external
return function() {
        return invokeComponentCallback(vm, fn, ArraySlice.call(arguments));
    };
}
github salesforce / lwc / packages / @lwc / engine / src / framework / base-bridge-element.ts View on Github external
return function(this: HTMLElement): any {
        const vm = getAssociatedVM(this);
        const { callHook, component } = vm;
        const fn = component[methodName];
        return callHook(vm.component, fn, ArraySlice.call(arguments));
    };
}