huanpenguin-tippy-react 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +420 -0
- package/dist/tippy-react.esm.js +533 -0
- package/dist/tippy-react.esm.js.map +1 -0
- package/dist/tippy-react.umd.js +542 -0
- package/dist/tippy-react.umd.js.map +1 -0
- package/dist/tippy-react.umd.min.js +2 -0
- package/dist/tippy-react.umd.min.js.map +1 -0
- package/headless/dist/tippy-react-headless.esm.js +537 -0
- package/headless/dist/tippy-react-headless.esm.js.map +1 -0
- package/headless/dist/tippy-react-headless.umd.js +546 -0
- package/headless/dist/tippy-react-headless.umd.js.map +1 -0
- package/headless/dist/tippy-react-headless.umd.min.js +2 -0
- package/headless/dist/tippy-react-headless.umd.min.js.map +1 -0
- package/headless/index.d.ts +49 -0
- package/index.d.ts +49 -0
- package/package.json +124 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tippy-react-headless.umd.min.js","sources":["../../src/utils.js","../../src/forwardRef.js","../../src/className-plugin.js","../../src/util-hooks.js","../../src/Tippy.js","../../src/useSingleton.js","../../src/headless.js"],"sourcesContent":["export const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'\n\nexport function preserveRef(ref, node) {\n if (ref) {\n if (typeof ref === 'function') {\n ref(node)\n }\n if ({}.hasOwnProperty.call(ref, 'current')) {\n ref.current = node\n }\n }\n}\n\nexport function ssrSafeCreateDiv() {\n return isBrowser && document.createElement('div')\n}\n\nexport function toDataAttributes(attrs) {\n const dataAttrs = {\n 'data-placement': attrs.placement,\n }\n\n if (attrs.referenceHidden) {\n dataAttrs['data-reference-hidden'] = ''\n }\n\n if (attrs.escaped) {\n dataAttrs['data-escaped'] = ''\n }\n\n return dataAttrs\n}\n\nfunction deepEqual(x, y) {\n if (x === y) {\n return true\n } else if (typeof x === 'object' && x != null && typeof y === 'object' && y != null) {\n if (Object.keys(x).length !== Object.keys(y).length) {\n return false\n }\n\n for (const prop in x) {\n if (y.hasOwnProperty(prop)) {\n if (!deepEqual(x[prop], y[prop])) {\n return false\n }\n } else {\n return false\n }\n }\n\n return true\n } else {\n return false\n }\n}\n\nexport function uniqueByShape(arr) {\n const output = []\n\n arr.forEach((item) => {\n if (!output.find((outputItem) => deepEqual(item, outputItem))) {\n output.push(item)\n }\n })\n\n return output\n}\n\nexport function deepPreserveProps(instanceProps, componentProps) {\n return {\n ...componentProps,\n popperOptions: {\n ...instanceProps.popperOptions,\n ...componentProps.popperOptions,\n modifiers: uniqueByShape([\n ...(instanceProps.popperOptions?.modifiers || []),\n ...(componentProps.popperOptions?.modifiers || []),\n ]),\n },\n }\n}\n","import React, { cloneElement, forwardRef } from 'react'\n\nimport { preserveRef } from './utils'\n\nconst createTippyWrapper = (Tippy, defaultProps) =>\n forwardRef(function TippyWrapper({ children, ...props }, ref) {\n return (\n // If I spread them separately here, Babel adds the _extends ponyfill for\n // some reason\n <Tippy {...{ ...defaultProps, ...props }}>\n {children\n ? cloneElement(children, {\n ref(node) {\n preserveRef(ref, node)\n preserveRef(children.props?.ref, node)\n },\n })\n : null}\n </Tippy>\n )\n })\n\nexport default createTippyWrapper\n","function updateClassName(box, action, classNames) {\n classNames.split(/\\s+/).forEach((name) => {\n if (name) {\n box.classList[action](name)\n }\n })\n}\n\nexport const classNamePlugin = {\n name: 'className',\n defaultValue: '',\n fn(instance) {\n const box = instance.popper.firstElementChild\n const isDefaultRenderFn = () => !!instance.props.render?.$$tippy\n\n function add() {\n if (instance.props.className && !isDefaultRenderFn()) {\n if (process.env.NODE_ENV !== 'production') {\n console.warn(\n [\n '@tippyjs/react: Cannot use `className` prop in conjunction with',\n '`render` prop. Place the className on the element you are',\n 'rendering.',\n ].join(' '),\n )\n }\n\n return\n }\n\n updateClassName(box, 'add', instance.props.className)\n }\n\n function remove() {\n if (isDefaultRenderFn()) {\n updateClassName(box, 'remove', instance.props.className)\n }\n }\n\n return {\n onCreate: add,\n onBeforeUpdate: remove,\n onAfterUpdate: add,\n }\n },\n}\n","import { useEffect, useLayoutEffect, useRef } from 'react'\n\nimport { isBrowser } from './utils'\n\nexport const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect\n\nexport function useMutableBox(initialValue) {\n // Using refs instead of state as it's recommended to not store imperative\n // values in state due to memory problems in React(?)\n const ref = useRef()\n\n if (!ref.current) {\n ref.current = typeof initialValue === 'function' ? initialValue() : initialValue\n }\n\n return ref.current\n}\n","import React, { cloneElement, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { classNamePlugin } from './className-plugin'\nimport { useIsomorphicLayoutEffect, useMutableBox } from './util-hooks'\nimport { deepPreserveProps, preserveRef, ssrSafeCreateDiv, toDataAttributes } from './utils'\n\nexport default function TippyGenerator(tippy) {\n function Tippy({\n children,\n content,\n visible,\n singleton,\n render,\n reference,\n disabled = false,\n ignoreAttributes = true,\n // Filter React development reserved props\n // added by babel-preset-react dev plugins:\n // transform-react-jsx-self and transform-react-jsx-source\n __source,\n __self,\n ...restOfNativeProps\n }) {\n const isControlledMode = visible !== undefined\n const isSingletonMode = singleton !== undefined\n\n const [mounted, setMounted] = useState(false)\n const [attrs, setAttrs] = useState({})\n const [singletonContent, setSingletonContent] = useState()\n const mutableBox = useMutableBox(() => ({\n container: ssrSafeCreateDiv(),\n renders: 1,\n }))\n\n const props = {\n ignoreAttributes,\n ...restOfNativeProps,\n content: mutableBox.container,\n }\n\n if (isControlledMode) {\n if (process.env.NODE_ENV !== 'production') {\n ;['trigger', 'hideOnClick', 'showOnCreate'].forEach((nativeStateProp) => {\n if (props[nativeStateProp] !== undefined) {\n console.warn(\n [\n `@tippyjs/react: Cannot specify \\`${nativeStateProp}\\` prop in`,\n `controlled mode (\\`visible\\` prop)`,\n ].join(' '),\n )\n }\n })\n }\n\n props.trigger = 'manual'\n props.hideOnClick = false\n }\n\n if (isSingletonMode) {\n disabled = true\n }\n\n let computedProps = props\n const plugins = props.plugins || []\n\n if (render) {\n computedProps = {\n ...props,\n plugins:\n isSingletonMode && singleton.data != null\n ? [\n ...plugins,\n {\n fn() {\n return {\n onTrigger(instance, event) {\n const node = singleton.data.children.find(\n ({ instance }) => instance.reference === event.currentTarget,\n )\n instance.state.$$activeSingletonInstance = node.instance\n setSingletonContent(node.content)\n },\n }\n },\n },\n ]\n : plugins,\n render: () => ({ popper: mutableBox.container }),\n }\n }\n\n const deps = [reference].concat(children ? [children.type] : [])\n\n // CREATE\n useIsomorphicLayoutEffect(() => {\n let element = reference\n if (reference && reference.hasOwnProperty('current')) {\n element = reference.current\n }\n\n const instance = tippy(element || mutableBox.ref || ssrSafeCreateDiv(), {\n ...computedProps,\n plugins: [classNamePlugin, ...(props.plugins || [])],\n })\n\n mutableBox.instance = instance\n\n if (disabled) {\n instance.disable()\n }\n\n if (visible) {\n instance.show()\n }\n\n if (isSingletonMode) {\n singleton.hook({\n instance,\n content,\n props: computedProps,\n setSingletonContent,\n })\n }\n\n setMounted(true)\n\n return () => {\n instance.destroy()\n singleton?.cleanup(instance)\n }\n }, deps)\n\n // UPDATE\n useIsomorphicLayoutEffect(() => {\n // Prevent this effect from running on 1st render\n if (mutableBox.renders === 1) {\n mutableBox.renders++\n return\n }\n\n const { instance } = mutableBox\n\n instance.setProps(deepPreserveProps(instance.props, computedProps))\n\n // Fixes #264\n instance.popperInstance?.forceUpdate()\n\n if (disabled) {\n instance.disable()\n } else {\n instance.enable()\n }\n\n if (isControlledMode) {\n if (visible) {\n instance.show()\n } else {\n instance.hide()\n }\n }\n\n if (isSingletonMode) {\n singleton.hook({\n instance,\n content,\n props: computedProps,\n setSingletonContent,\n })\n }\n })\n\n useIsomorphicLayoutEffect(() => {\n if (!render) {\n return\n }\n\n const { instance } = mutableBox\n\n instance.setProps({\n popperOptions: {\n ...instance.props.popperOptions,\n modifiers: [\n ...(instance.props.popperOptions?.modifiers || []).filter(\n ({ name }) => name !== '$$tippyReact',\n ),\n {\n name: '$$tippyReact',\n enabled: true,\n phase: 'beforeWrite',\n requires: ['computeStyles'],\n fn({ state }) {\n const hideData = state.modifiersData?.hide\n\n // WARNING: this is a high-risk path that can cause an infinite\n // loop. This expression _must_ evaluate to false when required\n if (\n attrs.placement !== state.placement ||\n attrs.referenceHidden !== hideData?.isReferenceHidden ||\n attrs.escaped !== hideData?.hasPopperEscaped\n ) {\n setAttrs({\n placement: state.placement,\n referenceHidden: hideData?.isReferenceHidden,\n escaped: hideData?.hasPopperEscaped,\n })\n }\n\n state.attributes.popper = {}\n },\n },\n ],\n },\n })\n }, [attrs.placement, attrs.referenceHidden, attrs.escaped, ...deps])\n\n return (\n <>\n {children\n ? cloneElement(children, {\n ref(node) {\n mutableBox.ref = node\n preserveRef(children.props?.ref, node)\n },\n })\n : null}\n {mounted &&\n createPortal(\n render ? render(toDataAttributes(attrs), singletonContent, mutableBox.instance) : content,\n mutableBox.container,\n )}\n </>\n )\n }\n\n return Tippy\n}\n","import { useMemo, useState } from 'react'\n\nimport { classNamePlugin } from './className-plugin'\nimport { useIsomorphicLayoutEffect, useMutableBox } from './util-hooks'\nimport { deepPreserveProps } from './utils'\n\nexport default function useSingletonGenerator(createSingleton) {\n return function useSingleton({ disabled = false, overrides = [] } = {}) {\n const [mounted, setMounted] = useState(false)\n const mutableBox = useMutableBox({\n children: [],\n renders: 1,\n })\n\n useIsomorphicLayoutEffect(() => {\n if (!mounted) {\n setMounted(true)\n return\n }\n\n const { children, sourceData } = mutableBox\n\n if (!sourceData) {\n if (process.env.NODE_ENV !== 'production') {\n console.error(\n [\n '@tippyjs/react: The `source` variable from `useSingleton()` has',\n 'not been passed to a <Tippy /> component.',\n ].join(' '),\n )\n }\n\n return\n }\n\n const instance = createSingleton(\n children.map((child) => child.instance),\n {\n ...sourceData.props,\n popperOptions: sourceData.instance.props.popperOptions,\n overrides,\n plugins: [classNamePlugin, ...(sourceData.props.plugins || [])],\n },\n )\n\n mutableBox.instance = instance\n\n if (disabled) {\n instance.disable()\n }\n\n return () => {\n instance.destroy()\n mutableBox.children = children.filter(({ instance }) => !instance.state.isDestroyed)\n }\n }, [mounted])\n\n useIsomorphicLayoutEffect(() => {\n if (!mounted) {\n return\n }\n\n if (mutableBox.renders === 1) {\n mutableBox.renders++\n return\n }\n\n const { children, instance, sourceData } = mutableBox\n\n if (!(instance && sourceData)) {\n return\n }\n\n const { content, ...props } = sourceData.props\n\n instance.setProps(\n deepPreserveProps(instance.props, {\n ...props,\n overrides,\n }),\n )\n\n instance.setInstances(children.map((child) => child.instance))\n\n if (disabled) {\n instance.disable()\n } else {\n instance.enable()\n }\n })\n\n return useMemo(() => {\n const source = {\n data: mutableBox,\n hook(data) {\n mutableBox.sourceData = data\n mutableBox.setSingletonContent = data.setSingletonContent\n },\n cleanup() {\n mutableBox.sourceData = null\n },\n }\n\n const target = {\n hook(data) {\n mutableBox.children = mutableBox.children.filter(({ instance }) => data.instance !== instance)\n mutableBox.children.push(data)\n\n if (\n mutableBox.instance?.state.isMounted &&\n mutableBox.instance?.state.$$activeSingletonInstance === data.instance\n ) {\n mutableBox.setSingletonContent?.(data.content)\n }\n\n if (mutableBox.instance && !mutableBox.instance.state.isDestroyed) {\n mutableBox.instance.setInstances(mutableBox.children.map((child) => child.instance))\n }\n },\n cleanup(instance) {\n mutableBox.children = mutableBox.children.filter((data) => data.instance !== instance)\n\n if (mutableBox.instance && !mutableBox.instance.state.isDestroyed) {\n mutableBox.instance.setInstances(mutableBox.children.map((child) => child.instance))\n }\n },\n }\n\n return [source, target]\n }, [])\n }\n}\n","import tippy, { createSingleton } from 'tippy.js/headless'\n\nimport forwardRef from './forwardRef'\nimport TippyGenerator from './Tippy'\nimport useSingletonGenerator from './useSingleton'\n\nconst useSingleton = useSingletonGenerator(createSingleton)\n\nexport default forwardRef(TippyGenerator(tippy), { render: () => '' })\nexport { tippy, useSingleton }\n"],"names":["isBrowser","window","document","preserveRef","ref","node","hasOwnProperty","call","current","ssrSafeCreateDiv","createElement","uniqueByShape","arr","output","forEach","item","find","outputItem","deepEqual","x","y","Object","keys","length","prop","push","deepPreserveProps","instanceProps","componentProps","popperOptions","modifiers","createTippyWrapper","Tippy","defaultProps","forwardRef","children","props","cloneElement","_children$props","updateClassName","box","action","classNames","split","name","classList","classNamePlugin","defaultValue","fn","instance","popper","firstElementChild","isDefaultRenderFn","render","_instance$props$rende","$$tippy","add","className","onCreate","onBeforeUpdate","onAfterUpdate","useIsomorphicLayoutEffect","useLayoutEffect","useEffect","useMutableBox","initialValue","useRef","TippyGenerator","tippy","content","visible","singleton","reference","disabled","ignoreAttributes","restOfNativeProps","__source","__self","isControlledMode","undefined","isSingletonMode","useState","mounted","setMounted","attrs","setAttrs","singletonContent","setSingletonContent","mutableBox","container","renders","trigger","hideOnClick","computedProps","plugins","data","onTrigger","event","currentTarget","state","$$activeSingletonInstance","deps","concat","type","element","disable","show","hook","destroy","cleanup","setProps","popperInstance","forceUpdate","enable","hide","filter","enabled","phase","requires","hideData","modifiersData","_state$modifiersData","placement","referenceHidden","isReferenceHidden","escaped","hasPopperEscaped","attributes","React","createPortal","dataAttrs","toDataAttributes","useSingletonGenerator","createSingleton","overrides","sourceData","map","child","isDestroyed","setInstances","useMemo","isMounted","useSingleton"],"mappings":"ihBAAO,IAAMA,EAA8B,oBAAXC,QAA8C,oBAAbC,SAE1D,SAASC,EAAYC,EAAKC,GACzBD,IACmB,mBAARA,GACPA,EAAIC,GAEJ,GAAGC,eAAeC,KAAKH,EAAK,aAC5BA,EAAII,QAAUH,IAKnB,SAASI,WACLT,GAAaE,SAASQ,cAAc,OA2CxC,SAASC,EAAcC,OACpBC,EAAS,UAEfD,EAAIE,SAAQ,SAACC,GACJF,EAAOG,MAAK,SAACC,UA5B1B,SAASC,EAAUC,EAAGC,MACdD,IAAMC,SACC,EACJ,GAAiB,iBAAND,GAAuB,MAALA,GAA0B,iBAANC,GAAuB,MAALA,EAAW,IAC7EC,OAAOC,KAAKH,GAAGI,SAAWF,OAAOC,KAAKF,GAAGG,cAClC,MAGN,IAAMC,KAAQ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AAaA,KACrFuC,EAAWrD,SAASV,KAAKsE,aAGrBP,EAAWvC,mBAAUkD,MAAM0C,sBAC3BrD,EAAWvC,mBAAUkD,MAAMC,6BAA8BL,EAAK9C,iBAE9DuC,EAAWD,qBAAXC,EAAWD,oBAAsBQ,EAAK1B,UAGtCmB,EAAWvC,WAAauC,EAAWvC,SAASkD,MAAMuC,aAClDlD,EAAWvC,SAAS0F,aAAanD,EAAWrD,SAASqG,KAAI,SAACC,UAAUA,EAAMxF,cAGlF4D,iBAAQ5D,GACJuC,EAAWrD,SAAWqD,EAAWrD,SAASgF,QAAO,SAACpB,UAASA,EAAK9C,WAAaA,KAEzEuC,EAAWvC,WAAauC,EAAWvC,SAASkD,MAAMuC,aAClDlD,EAAWvC,SAAS0F,aAAanD,EAAWrD,SAASqG,KAAI,SAACC,UAAUA,EAAMxF,kBAMvF,SC3HL6F,EAAeV,EAAsBC,qBAE5BnG,EAAWiC,EAAeC,GAAQ,CAAEf,OAAQ,iBAAM"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {default as tippyCore, Instance, Placement, Props} from 'tippy.js';
|
|
3
|
+
|
|
4
|
+
type Content = React.ReactNode;
|
|
5
|
+
|
|
6
|
+
export interface TippyProps extends Partial<Omit<Props, 'content' | 'render'>> {
|
|
7
|
+
children?: React.ReactElement<any>;
|
|
8
|
+
content?: Content;
|
|
9
|
+
visible?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
className?: string;
|
|
12
|
+
singleton?: SingletonObject;
|
|
13
|
+
reference?: React.RefObject<Element> | Element | null;
|
|
14
|
+
ref?: React.Ref<Element>;
|
|
15
|
+
render?: (
|
|
16
|
+
attrs: {
|
|
17
|
+
'data-placement': Placement;
|
|
18
|
+
'data-reference-hidden'?: string;
|
|
19
|
+
'data-escaped'?: string;
|
|
20
|
+
},
|
|
21
|
+
content?: Content,
|
|
22
|
+
instance?: Instance,
|
|
23
|
+
) => React.ReactNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare const Tippy: React.ForwardRefExoticComponent<TippyProps>;
|
|
27
|
+
export default Tippy;
|
|
28
|
+
|
|
29
|
+
export const tippy: typeof tippyCore;
|
|
30
|
+
|
|
31
|
+
type SingletonHookArgs = {
|
|
32
|
+
instance: Instance;
|
|
33
|
+
content: Content;
|
|
34
|
+
props: Props;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type SingletonObject = {
|
|
38
|
+
data?: any;
|
|
39
|
+
hook(args: SingletonHookArgs): void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface UseSingletonProps {
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
overrides?: Array<keyof Props>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const useSingleton: (
|
|
48
|
+
props?: UseSingletonProps,
|
|
49
|
+
) => [SingletonObject, SingletonObject];
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {default as tippyCore, Instance, Props, Placement} from 'tippy.js';
|
|
3
|
+
|
|
4
|
+
type Content = React.ReactNode;
|
|
5
|
+
|
|
6
|
+
export interface TippyProps extends Partial<Omit<Props, 'content' | 'render'>> {
|
|
7
|
+
children?: React.ReactElement<any>;
|
|
8
|
+
content?: Content;
|
|
9
|
+
visible?: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
className?: string;
|
|
12
|
+
singleton?: SingletonObject;
|
|
13
|
+
reference?: React.RefObject<Element> | Element | null;
|
|
14
|
+
ref?: React.Ref<Element>;
|
|
15
|
+
render?: (
|
|
16
|
+
attrs: {
|
|
17
|
+
'data-placement': Placement;
|
|
18
|
+
'data-reference-hidden'?: string;
|
|
19
|
+
'data-escaped'?: string;
|
|
20
|
+
},
|
|
21
|
+
content?: Content,
|
|
22
|
+
instance?: Instance
|
|
23
|
+
) => React.ReactNode;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare const Tippy: React.ForwardRefExoticComponent<TippyProps>;
|
|
27
|
+
export default Tippy;
|
|
28
|
+
|
|
29
|
+
export const tippy: typeof tippyCore;
|
|
30
|
+
|
|
31
|
+
type SingletonHookArgs = {
|
|
32
|
+
instance: Instance;
|
|
33
|
+
content: Content;
|
|
34
|
+
props: Props;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type SingletonObject = {
|
|
38
|
+
data?: any;
|
|
39
|
+
hook(args: SingletonHookArgs): void;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface UseSingletonProps {
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
overrides?: Array<keyof Props>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const useSingleton: (
|
|
48
|
+
props?: UseSingletonProps,
|
|
49
|
+
) => [SingletonObject, SingletonObject];
|
package/package.json
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "huanpenguin-tippy-react",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "React component for Tippy.js",
|
|
5
|
+
"main": "dist/tippy-react.umd.js",
|
|
6
|
+
"module": "dist/tippy-react.esm.js",
|
|
7
|
+
"unpkg": "dist/tippy-react.umd.min.js",
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"sideEffects": false,
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "parcel demo/index.html -d .devserver --no-cache",
|
|
12
|
+
"build": "rollup --config",
|
|
13
|
+
"test": "jest --coverage",
|
|
14
|
+
"lint": "eslint \"{src,test}/**/*.js\"",
|
|
15
|
+
"format": "prettier --write \"{src,test,demo}/**/*.{js,ts,json,css,md}\""
|
|
16
|
+
},
|
|
17
|
+
"author": "HuanCanhCut",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"keywords": [
|
|
20
|
+
"tooltip",
|
|
21
|
+
"popover",
|
|
22
|
+
"tippy",
|
|
23
|
+
"react"
|
|
24
|
+
],
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./index.d.ts",
|
|
28
|
+
"import": "./dist/tippy-react.esm.js",
|
|
29
|
+
"require": "./dist/tippy-react.umd.js"
|
|
30
|
+
},
|
|
31
|
+
"./headless": {
|
|
32
|
+
"types": "./headless/index.d.ts",
|
|
33
|
+
"import": "./headless/dist/tippy-react-headless.esm.js",
|
|
34
|
+
"require": "./headless/dist/tippy-react-headless.umd.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"typesVersions": {
|
|
38
|
+
"*": {
|
|
39
|
+
"headless": [
|
|
40
|
+
"headless/index.d.ts"
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist",
|
|
46
|
+
"headless/dist",
|
|
47
|
+
"index.d.ts",
|
|
48
|
+
"headless/index.d.ts"
|
|
49
|
+
],
|
|
50
|
+
"jest": {
|
|
51
|
+
"setupFilesAfterEnv": [
|
|
52
|
+
"<rootDir>test/setup.js",
|
|
53
|
+
"@testing-library/jest-dom/extend-expect"
|
|
54
|
+
],
|
|
55
|
+
"coveragePathIgnorePatterns": [
|
|
56
|
+
"test/setup.js"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"husky": {
|
|
60
|
+
"hooks": {
|
|
61
|
+
"pre-commit": "lint-staged"
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"lint-staged": {
|
|
65
|
+
"{src,test,demo}/**/*.{js,ts,json,css,md}": [
|
|
66
|
+
"prettier --write",
|
|
67
|
+
"git add"
|
|
68
|
+
],
|
|
69
|
+
"{src,test}/**/*.js": [
|
|
70
|
+
"eslint --fix",
|
|
71
|
+
"git add"
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"tippy.js": "^6.3.1"
|
|
76
|
+
},
|
|
77
|
+
"peerDependencies": {
|
|
78
|
+
"react": ">=18",
|
|
79
|
+
"react-dom": ">=18"
|
|
80
|
+
},
|
|
81
|
+
"devDependencies": {
|
|
82
|
+
"@babel/core": "^7.8.7",
|
|
83
|
+
"@babel/preset-env": "^7.8.7",
|
|
84
|
+
"@babel/preset-react": "^7.0.0",
|
|
85
|
+
"@testing-library/jest-dom": "^5.12.0",
|
|
86
|
+
"@testing-library/react": "^11.2.7",
|
|
87
|
+
"@types/react": "^16.8.2",
|
|
88
|
+
"babel-eslint": "^10.0.1",
|
|
89
|
+
"babel-jest": "^25.1.0",
|
|
90
|
+
"babel-plugin-annotate-pure-calls": "^0.4.0",
|
|
91
|
+
"core-js": "^3.6.4",
|
|
92
|
+
"eslint": "^5.14.1",
|
|
93
|
+
"eslint-config-prettier": "^3.6.0",
|
|
94
|
+
"eslint-plugin-react": "^7.12.4",
|
|
95
|
+
"eslint-plugin-react-hooks": "^1.7.0",
|
|
96
|
+
"framer-motion": "^1.10.3",
|
|
97
|
+
"husky": "^1.3.1",
|
|
98
|
+
"jest": "^24.1.0",
|
|
99
|
+
"lint-staged": "^8.1.0",
|
|
100
|
+
"parcel": "^1.12.3",
|
|
101
|
+
"prettier": "^1.16.1",
|
|
102
|
+
"react": "^16.8.1",
|
|
103
|
+
"react-dom": "^16.8.1",
|
|
104
|
+
"react-spring": "^8.0.27",
|
|
105
|
+
"rollup": "^1.14.3",
|
|
106
|
+
"rollup-plugin-babel": "^4.3.2",
|
|
107
|
+
"rollup-plugin-node-resolve": "^5.2.0",
|
|
108
|
+
"rollup-plugin-replace": "^2.2.0",
|
|
109
|
+
"rollup-plugin-terser": "^5.2.0",
|
|
110
|
+
"styled-components": "^5.0.1",
|
|
111
|
+
"typescript": "^3.6.3"
|
|
112
|
+
},
|
|
113
|
+
"directories": {
|
|
114
|
+
"test": "test"
|
|
115
|
+
},
|
|
116
|
+
"repository": {
|
|
117
|
+
"type": "git",
|
|
118
|
+
"url": "git+https://github.com/atomiks/tippyjs-react.git"
|
|
119
|
+
},
|
|
120
|
+
"bugs": {
|
|
121
|
+
"url": "https://github.com/atomiks/tippyjs-react/issues"
|
|
122
|
+
},
|
|
123
|
+
"homepage": "https://github.com/atomiks/tippyjs-react#readme"
|
|
124
|
+
}
|