@dropins/tools 1.5.1-alpha003 → 1.6.0-alpha999
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/chunks/initializer.js +1 -1
- package/chunks/vcomponent.js +12 -12
- package/chunks/vcomponent.js.map +1 -1
- package/components.js +1 -1
- package/components.js.map +1 -1
- package/fetch-graphql.js +1 -1
- package/fetch-graphql.js.map +1 -1
- package/initializer.js +1 -1
- package/lib.js +1 -1
- package/lib.js.map +1 -1
- package/package.json +1 -1
- package/types/elsie/src/components/ProductItemCard/ProductItemCard.d.ts +0 -2
- package/types/elsie/src/lib/render.d.ts +6 -1
- package/types/elsie/src/lib/slot.d.ts +4 -3
- package/types/fetch-graphql/src/index.d.ts +9 -1
- package/types/recaptcha/src/index.d.ts +1 -0
package/lib.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lib.js","sources":["/@dropins/tools/src/lib/form-values.ts","/@dropins/tools/src/lib/deepmerge.ts","/@dropins/tools/src/lib/i18n.ts","/@dropins/tools/src/lib/slot.tsx","/@dropins/tools/src/lib/get-cookie.ts"],"sourcesContent":["/********************************************************************\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\nexport const getFormValues = (form: HTMLFormElement) => {\n const formData: any = new FormData(form);\n const result = Object.fromEntries(formData);\n return result;\n};\n\nexport const getFormErrors = (form: HTMLFormElement) => {\n const formData: any = new FormData(form);\n\n const data = Object.fromEntries(formData);\n\n const result = Object.entries(data).reduce((result, [key]) => {\n // @ts-ignore\n const field = form.elements[key];\n\n return field?.validationMessage\n ? { ...result, [key]: field.validationMessage }\n : { ...result };\n }, {});\n\n return result;\n};\n","/********************************************************************\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\nimport deepmerge from 'deepmerge';\n\nexport { default as deepmerge } from 'deepmerge';\n\nconst mergeOptions = {\n arrayMerge: (target: any, source: any, options: any) => {\n const destination = target.slice();\n\n source.forEach((item: any, index: number) => {\n if (typeof destination[index] === 'undefined') {\n destination[index] = options.cloneUnlessOtherwiseSpecified(\n item,\n options\n );\n } else if (options.isMergeableObject(item)) {\n destination[index] = deepmerge(target[index], item, options);\n } else if (target.indexOf(item) === -1) {\n destination.push(item);\n }\n });\n return destination;\n },\n};\n\nexport function merge<T>(\n prev: T,\n next?: { [key: string]: any }\n) {\n if (!next) return prev;\n\n return deepmerge<T, { [key: string]: any }>(\n prev,\n next,\n mergeOptions\n );\n}\n","/********************************************************************\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\n/**\n * Convert locale from Magento standard to react-intl BCP 47 language tag\n *\n * @param {string} locale - A locale (e.g. `fr_FR`).\n * @returns {string} A BCP 47 language tag (e.g. `fr-FR`).\n */\nexport const toLanguageTag = (locale: string) => {\n return locale.replace('_', '-');\n};\n","/********************************************************************\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\nimport { cloneElement, ComponentChildren, RefObject, VNode, createElement } from 'preact';\nimport {\n StateUpdater,\n useContext,\n useState,\n useRef,\n useEffect,\n useMemo,\n useCallback,\n} from 'preact/hooks';\nimport { IntlContext, Lang } from '@adobe-commerce/elsie/i18n';\nimport { HTMLAttributes } from 'preact/compat';\nimport { SlotQueueContext } from './render';\n\nimport '@adobe-commerce/elsie/components/UIProvider/debugger.css';\n\ntype MutateElement = (elem: HTMLElement) => void;\n\n\ninterface State {\n get: (key: string) => void;\n set: (key: string, value: any) => void;\n}\n\ninterface SlotElement {\n appendChild: MutateElement;\n prependChild: MutateElement;\n appendSibling: MutateElement;\n prependSibling: MutateElement;\n}\n\ninterface PrivateContext<T> {\n _setProps: (s: StateUpdater<{}>) => void;\n _registerMethod: (\n cb: (next: T & DefaultSlotContext<T>, state: State) => void\n ) => void;\n // eslint-disable-next-line no-undef\n _htmlElementToVNode: (element: HTMLElement, tag: keyof HTMLElementTagNameMap) => VNode;\n}\n\ninterface DefaultSlotContext<T> extends PrivateContext<T> {\n dictionary: Lang;\n getSlotElement: (key: string) => SlotElement;\n replaceWith: MutateElement;\n appendChild: MutateElement;\n prependChild: MutateElement;\n appendSibling: MutateElement;\n prependSibling: MutateElement;\n onRender: (cb: (next: T & DefaultSlotContext<T>) => void) => void;\n onChange: (cb: (next: T & DefaultSlotContext<T>) => void) => void;\n}\n\ntype Context<T> = T & ThisType<DefaultSlotContext<T>>; // NOSONAR\n\nexport type SlotProps<T = any> = (\n ctx: T & DefaultSlotContext<T>,\n element: HTMLDivElement | null\n) => Promise<void> | void;\n\nexport type SlotMethod<P = any> = (\n callback: (next: unknown, state: State) => P\n) => void;\n\n// Slot Hook\nexport function useSlot<K, V extends HTMLElement>(\n name: string,\n // @ts-ignore\n context: Context<K> = {},\n callback?: SlotProps<K>,\n children?: ComponentChildren,\n render?: Function,\n // eslint-disable-next-line no-undef\n contentTag: keyof HTMLElementTagNameMap = 'div'\n): [RefObject<V>, Record<string, any>] {\n const slotsQueue = useContext(SlotQueueContext);\n\n // HTML Element\n const elementRef = useRef<V>(null);\n\n const status = useRef<'pending' | 'ready' | 'loading'>('pending');\n\n // Methods\n const methodsRef = useRef<any>([]);\n\n // Children VNodes\n const [props, _setProps] = useState<Record<string, any>>({\n children: [children],\n });\n\n // Attributes\n const [_state, setState] = useState<any>({});\n\n const state = useMemo(\n () => ({\n get: (key: string) => _state[key],\n set: (key: string, value: any) => {\n setState({ ...state, [key]: value });\n },\n }),\n [_state]\n );\n\n /** Internationalization */\n // @ts-ignore\n const { intl }: any = useContext(IntlContext);\n\n // @ts-ignore\n context.dictionary = intl.dictionary;\n\n /** Privates */\n // @ts-ignore\n context._setProps = (next: State<any>) => {\n _setProps((prev) => {\n // next props\n const _next = typeof next === 'function' ? next(prev) : next;\n\n // On render method...\n if (render) {\n const renderNode = cloneElement(render(prev), { key: 'render' });\n\n // find index of existing render node\n const index = prev.children.findIndex((n: any) => n?.key === 'render');\n\n // replace existing render node\n prev.children[index] = renderNode;\n }\n\n return _next;\n });\n };\n\n const _registerMethod = useCallback((cb: Function) => {\n if (typeof cb === 'function') {\n methodsRef.current.push(cb);\n } else {\n console.warn('Skipped: Invalid _registerMethod', cb);\n }\n }, []);\n\n // @ts-ignore\n context._registerMethod = _registerMethod;\n\n const _htmlElementToVNode = useCallback((elem: HTMLElement) => {\n return createElement(\n contentTag,\n {\n 'data-slot-html-element': elem.tagName.toLowerCase(),\n ref: (refElem: HTMLElement | null): void => {\n refElem?.appendChild(elem);\n }\n },\n null\n );\n }, [contentTag]);\n\n // @ts-ignore\n context._htmlElementToVNode = _htmlElementToVNode;\n\n /** Prebuilt Methods */\n // @ts-ignore\n context.getSlotElement = useCallback(\n (key: string) => {\n const element = elementRef.current?.querySelector(\n `[data-slot-key=\"${key}\"]`\n );\n\n log(\n `🟦 \"${name}\" Slot getSlotElement: ${key}`,\n elementRef.current?.cloneNode(true),\n element?.cloneNode(true)\n );\n\n if (!element) return;\n\n return {\n appendChild: (elem: HTMLElement) => {\n element.appendChild(elem);\n },\n\n prependChild: (elem: HTMLElement) => {\n element.insertBefore(elem, element.firstChild);\n },\n\n appendSibling: (elem: HTMLElement) => {\n const parent = element.parentNode;\n parent?.insertBefore(elem, element.nextSibling);\n },\n\n prependSibling: (elem: HTMLElement) => {\n const parent = element.parentNode;\n parent?.insertBefore(elem, element);\n },\n };\n },\n [name]\n );\n\n // @ts-ignore\n context.onRender = useCallback((cb: Function) => {\n methodsRef.current.push(cb);\n }, []);\n\n /**\n * @deprecated Use `onRender` instead.\n */\n // @ts-ignore\n context.onChange = context.onRender;\n\n // @ts-ignore\n context.replaceWith = useCallback(\n (elem: HTMLElement) => {\n // @ts-ignore\n _registerMethod((next) => {\n // @ts-ignore\n const children = _htmlElementToVNode(elem);\n\n next._setProps({ children: [children] });\n });\n },\n [_htmlElementToVNode, _registerMethod]\n );\n\n // @ts-ignore\n context.appendChild = useCallback(\n (elem: HTMLElement) => {\n // @ts-ignore\n _registerMethod((next) => {\n // @ts-ignore\n const vnode = _htmlElementToVNode(elem);\n\n next._setProps((prev: any) => {\n return {\n ...prev,\n children: [...prev.children, vnode],\n };\n });\n });\n },\n [_htmlElementToVNode, _registerMethod]\n );\n\n // @ts-ignore\n context.prependChild = useCallback(\n (elem: HTMLElement) => {\n // @ts-ignore\n _registerMethod((next) => {\n // @ts-ignore\n const vnode = _htmlElementToVNode(elem);\n\n next._setProps((prev: any) => {\n return {\n ...prev,\n children: [vnode, ...prev.children],\n };\n });\n });\n },\n [_htmlElementToVNode, _registerMethod]\n );\n\n // @ts-ignore\n context.appendSibling = useCallback(\n (elem: HTMLElement) => {\n // @ts-ignore\n _registerMethod(() => {\n const parent = elementRef.current?.parentNode;\n\n parent?.insertBefore(elem, elementRef.current?.nextSibling ?? null);\n });\n },\n [_registerMethod]\n );\n\n // @ts-ignore\n context.prependSibling = useCallback(\n (elem: HTMLElement) => {\n // @ts-ignore\n _registerMethod(() => {\n const parent = elementRef.current?.parentNode;\n\n parent?.insertBefore(elem, elementRef.current);\n });\n },\n [_registerMethod]\n );\n\n const handleLifeCycleRender = useCallback(async () => {\n if (status.current === 'loading') return;\n\n status.current = 'loading';\n\n log(`🟨 \"${name}\" Slot Rendered`);\n\n // Reset\n const renderNode = render\n ? cloneElement(render(props), { key: 'render' })\n : null;\n _setProps({ children: [renderNode ?? children] });\n\n // Run all registered methods\n methodsRef.current.forEach((method: any) => {\n method(context, state);\n });\n\n status.current = 'ready';\n }, [children, context, name, props, render, state]);\n\n // Initialization\n const handleLifeCycleInit = useCallback(async () => {\n if (!callback) return;\n\n try {\n status.current = 'loading';\n\n log(`🟩 \"${name}\" Slot Initialized`);\n await callback(context as K & DefaultSlotContext<K>, elementRef.current as HTMLDivElement | null);\n } catch (error) {\n console.error(`Error in \"${callback.name}\" Slot callback`, error);\n } finally {\n status.current = 'ready';\n\n // first render\n await handleLifeCycleRender();\n }\n }, [callback, context, handleLifeCycleRender, name]);\n\n // Initialization\n useEffect(() => {\n handleLifeCycleInit().finally(() => {\n if (slotsQueue) {\n slotsQueue.value.delete(name);\n slotsQueue.value = new Set(slotsQueue.value);\n }\n });\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // Update\n useEffect(() => {\n handleLifeCycleRender();\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(context), JSON.stringify(_state)]);\n\n return [elementRef, props];\n}\n\n// Slot Component\ninterface SlotPropsComponent<T>\n extends Omit<HTMLAttributes<HTMLElement>, 'slot'> {\n name: string;\n slot?: SlotProps<T>;\n context?: Context<T>;\n render?: (props: Record<string, any>) => VNode | VNode[];\n // eslint-disable-next-line no-undef\n slotTag?: keyof HTMLElementTagNameMap; // The tag for the slot wrapper itself\n // eslint-disable-next-line no-undef\n contentTag?: keyof HTMLElementTagNameMap; // The tag for dynamically inserted content\n children?: ComponentChildren;\n}\n\nexport function Slot<T>({\n name,\n context,\n slot,\n children,\n render,\n slotTag = 'div',\n contentTag = 'div',\n ...props\n}: Readonly<SlotPropsComponent<T>>): VNode<{\n ref: RefObject<HTMLElement>;\n 'data-slot': string;\n [key: string]: any;\n}> {\n const slotsQueue = useContext(SlotQueueContext);\n\n const [elementRef, slotProps] = useSlot<T, HTMLElement>(\n name,\n context,\n slot,\n children,\n render,\n contentTag\n );\n\n useMemo(() => {\n if (!name) {\n return console.warn('Slot \"name\" is required');\n }\n\n // add slot to queue\n if (slotsQueue) {\n slotsQueue.value.add(name);\n slotsQueue.value = new Set(slotsQueue.value);\n }\n }, [name, slotsQueue]);\n\n return createElement(\n slotTag,\n {\n ...props,\n ref: elementRef,\n 'data-slot': name,\n },\n slotProps.children\n );\n}\n\n// Debugger\n\n// @ts-ignore\nwindow.DROPINS = window.DROPINS || {};\n\n// @ts-ignore\nwindow.DROPINS.showSlots = async (state) => {\n // cache state in session storage\n window.sessionStorage.setItem(\n 'dropin-debugger--show-slots',\n state.toString()\n );\n\n document.body.classList.toggle('dropin-debugger--show-slots', state);\n};\n\nlet log: (...attrs: any) => void = () => {};\n\n// @ts-ignore\nwindow.DROPINS.logSlots = async (state) => {\n // cache state in session storage\n window.sessionStorage.setItem('dropin-debugger--log-slots', state.toString());\n\n log = state ? (...attrs) => console.log(...attrs) : () => {};\n};\n\n/** Persistent Settings */\n\n// @ts-ignore\nwindow.DROPINS.showSlots(\n window.sessionStorage.getItem('dropin-debugger--show-slots') === 'true'\n);\n\n// @ts-ignore\nwindow.DROPINS.logSlots(\n window.sessionStorage.getItem('dropin-debugger--log-slots') === 'true'\n);\n","/**\n * Get cookie\n * @param {string} cookieName - The name of the cookie to get\n * @returns {string} - The value of the cookie\n */\nexport function getCookie(cookieName: string): string | undefined {\n const cookies = document.cookie.split(';');\n let foundValue;\n\n cookies.forEach((cookie) => {\n const [name, value] = cookie.trim().split('=');\n if (name === cookieName) {\n foundValue = decodeURIComponent(value);\n }\n });\n\n return foundValue;\n}\n"],"names":["getFormValues","form","formData","getFormErrors","data","result","key","field","mergeOptions","target","source","options","destination","item","index","deepmerge","merge","prev","next","toLanguageTag","locale","useSlot","name","context","callback","children","render","contentTag","slotsQueue","useContext","SlotQueueContext","elementRef","useRef","status","methodsRef","props","_setProps","useState","_state","setState","state","useMemo","value","intl","IntlContext","_next","renderNode","cloneElement","n","_registerMethod","useCallback","cb","_htmlElementToVNode","elem","createElement","refElem","element","_a","log","_b","parent","vnode","handleLifeCycleRender","method","handleLifeCycleInit","error","useEffect","Slot","slot","slotTag","slotProps","attrs","getCookie","cookieName","cookies","foundValue","cookie"],"mappings":"ymBASa,MAAAA,EAAiB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AEtEkB,EAAAlB,EAAQ,IAAI+B,IAAU,QAAQ,IAAI,GAAGA,CAAK,EAAI,IAAM,CAAC,CAC7D,EAKA,OAAO,QAAQ,UACb,OAAO,eAAe,QAAQ,6BAA6B,IAAM,MACnE,EAGA,OAAO,QAAQ,SACb,OAAO,eAAe,QAAQ,4BAA4B,IAAM,MAClE,EClcO,SAASC,EAAUC,EAAwC,CAChE,MAAMC,EAAU,SAAS,OAAO,MAAM,GAAG,EACrC,IAAAC,EAEI,OAAAD,EAAA,QAASE,GAAW,CACpB,KAAA,CAACtD,EAAMoB,CAAK,EAAIkC,EAAO,KAAK,EAAE,MAAM,GAAG,EACzCtD,IAASmD,IACXE,EAAa,mBAAmBjC,CAAK,EACvC,CACD,EAEMiC,CACT"}
|
|
1
|
+
{"version":3,"file":"lib.js","sources":["/@dropins/tools/src/lib/form-values.ts","/@dropins/tools/src/lib/deepmerge.ts","/@dropins/tools/src/lib/i18n.ts","/@dropins/tools/src/lib/slot.tsx","/@dropins/tools/src/lib/get-cookie.ts"],"sourcesContent":["/********************************************************************\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\nexport const getFormValues = (form: HTMLFormElement) => {\n const formData: any = new FormData(form);\n const result = Object.fromEntries(formData);\n return result;\n};\n\nexport const getFormErrors = (form: HTMLFormElement) => {\n const formData: any = new FormData(form);\n\n const data = Object.fromEntries(formData);\n\n const result = Object.entries(data).reduce((result, [key]) => {\n // @ts-ignore\n const field = form.elements[key];\n\n return field?.validationMessage\n ? { ...result, [key]: field.validationMessage }\n : { ...result };\n }, {});\n\n return result;\n};\n","/********************************************************************\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\nimport deepmerge from 'deepmerge';\n\nexport { default as deepmerge } from 'deepmerge';\n\nconst mergeOptions = {\n arrayMerge: (target: any, source: any, options: any) => {\n const destination = target.slice();\n\n source.forEach((item: any, index: number) => {\n if (typeof destination[index] === 'undefined') {\n destination[index] = options.cloneUnlessOtherwiseSpecified(\n item,\n options\n );\n } else if (options.isMergeableObject(item)) {\n destination[index] = deepmerge(target[index], item, options);\n } else if (target.indexOf(item) === -1) {\n destination.push(item);\n }\n });\n return destination;\n },\n};\n\nexport function merge<T>(\n prev: T,\n next?: { [key: string]: any }\n) {\n if (!next) return prev;\n\n return deepmerge<T, { [key: string]: any }>(\n prev,\n next,\n mergeOptions\n );\n}\n","/********************************************************************\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this \n * file in accordance with the terms of the Adobe license agreement \n * accompanying it. \n *******************************************************************/\n\n/**\n * Convert locale from Magento standard to react-intl BCP 47 language tag\n *\n * @param {string} locale - A locale (e.g. `fr_FR`).\n * @returns {string} A BCP 47 language tag (e.g. `fr-FR`).\n */\nexport const toLanguageTag = (locale: string) => {\n return locale.replace('_', '-');\n};\n","/********************************************************************\n * Copyright 2024 Adobe\n * All Rights Reserved.\n *\n * NOTICE: Adobe permits you to use, modify, and distribute this\n * file in accordance with the terms of the Adobe license agreement\n * accompanying it.\n *******************************************************************/\n\nimport { IntlContext, Lang } from '@adobe-commerce/elsie/i18n';\nimport {\n cloneElement,\n ComponentChildren,\n createElement,\n RefObject,\n VNode,\n} from 'preact';\nimport { HTMLAttributes } from 'preact/compat';\nimport {\n StateUpdater,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'preact/hooks';\nimport { SlotQueueContext } from './render';\n\nimport '@adobe-commerce/elsie/components/UIProvider/debugger.css';\n\ntype MutateElement = (elem: HTMLElement) => void;\n\ninterface State {\n get: (key: string) => void;\n set: (key: string, value: any) => void;\n}\n\ninterface SlotElement {\n appendChild: MutateElement;\n prependChild: MutateElement;\n appendSibling: MutateElement;\n prependSibling: MutateElement;\n}\n\ninterface PrivateContext<T> {\n _setProps: (s: StateUpdater<{}>) => void;\n _registerMethod: (\n cb: (next: T & DefaultSlotContext<T>, state: State) => void\n ) => void;\n // eslint-disable-next-line no-undef\n _htmlElementToVNode: (element: HTMLElement, tag: keyof HTMLElementTagNameMap) => VNode;\n}\n\ninterface DefaultSlotContext<T> extends PrivateContext<T> {\n dictionary: Lang;\n getSlotElement: (key: string) => SlotElement;\n replaceWith: MutateElement;\n appendChild: MutateElement;\n prependChild: MutateElement;\n appendSibling: MutateElement;\n prependSibling: MutateElement;\n onRender: (cb: (next: T & DefaultSlotContext<T>) => void) => void;\n onChange: (cb: (next: T & DefaultSlotContext<T>) => void) => void;\n}\n\ntype Context<T> = T & ThisType<DefaultSlotContext<T>>; // NOSONAR\n\nexport type SlotProps<T = any> = (\n ctx: T & DefaultSlotContext<T>,\n element: HTMLDivElement | null\n) => Promise<void> | void;\n\nexport type SlotMethod<P = any> = (\n callback: (next: unknown, state: State) => P\n) => void;\n\n// Slot Hook\nexport function useSlot<K, V extends HTMLElement>(\n name: string,\n // @ts-ignore\n context: Context<K> = {},\n callback?: SlotProps<K>,\n children?: ComponentChildren,\n render?: Function,\n // eslint-disable-next-line no-undef\n contentTag: keyof HTMLElementTagNameMap = 'div'\n): [RefObject<V>, Record<string, any>] {\n const slotsQueue = useContext(SlotQueueContext);\n\n // HTML Element\n const elementRef = useRef<V>(null);\n\n const status = useRef<'pending' | 'ready' | 'loading'>('pending');\n\n // Methods\n const methodsRef = useRef<any>([]);\n\n // Children VNodes\n const [props, _setProps] = useState<Record<string, any>>({\n children: [children],\n });\n\n // Attributes\n const [_state, setState] = useState<any>({});\n\n const state = useMemo(\n () => ({\n get: (key: string) => _state[key],\n set: (key: string, value: any) => {\n setState({ ...state, [key]: value });\n },\n }),\n [_state]\n );\n\n /** Internationalization */\n // @ts-ignore\n const { intl }: any = useContext(IntlContext);\n\n // @ts-ignore\n context.dictionary = intl.dictionary;\n\n /** Privates */\n // @ts-ignore\n context._setProps = (next: State<any>) => {\n _setProps((prev) => {\n // next props\n const _next = typeof next === 'function' ? next(prev) : next;\n\n // On render method...\n if (render) {\n const renderNode = cloneElement(render(prev), { key: 'render' });\n\n // find index of existing render node\n const index = prev.children.findIndex((n: any) => n?.key === 'render');\n\n // replace existing render node\n prev.children[index] = renderNode;\n }\n\n return _next;\n });\n };\n\n const _registerMethod = useCallback((cb: Function) => {\n if (typeof cb === 'function') {\n methodsRef.current.push(cb);\n } else {\n console.warn('Skipped: Invalid _registerMethod', cb);\n }\n }, []);\n\n // @ts-ignore\n context._registerMethod = _registerMethod;\n\n const _htmlElementToVNode = useCallback(\n (elem: HTMLElement) => {\n return createElement(\n contentTag,\n {\n 'data-slot-html-element': elem.tagName.toLowerCase(),\n ref: (refElem: HTMLElement | null): void => {\n refElem?.appendChild(elem);\n },\n },\n null\n );\n },\n [contentTag]\n );\n\n // @ts-ignore\n context._htmlElementToVNode = _htmlElementToVNode;\n\n /** Prebuilt Methods */\n // @ts-ignore\n context.getSlotElement = useCallback(\n (key: string) => {\n const element = elementRef.current?.querySelector(\n `[data-slot-key=\"${key}\"]`\n );\n\n log(\n `🟦 \"${name}\" Slot getSlotElement: ${key}`,\n elementRef.current?.cloneNode(true),\n element?.cloneNode(true)\n );\n\n if (!element) return;\n\n return {\n appendChild: (elem: HTMLElement) => {\n element.appendChild(elem);\n },\n\n prependChild: (elem: HTMLElement) => {\n element.insertBefore(elem, element.firstChild);\n },\n\n appendSibling: (elem: HTMLElement) => {\n const parent = element.parentNode;\n parent?.insertBefore(elem, element.nextSibling);\n },\n\n prependSibling: (elem: HTMLElement) => {\n const parent = element.parentNode;\n parent?.insertBefore(elem, element);\n },\n };\n },\n [name]\n );\n\n // @ts-ignore\n context.onRender = useCallback((cb: Function) => {\n methodsRef.current.push(cb);\n }, []);\n\n /**\n * @deprecated Use `onRender` instead.\n */\n // @ts-ignore\n context.onChange = context.onRender;\n\n // @ts-ignore\n context.replaceWith = useCallback(\n (elem: HTMLElement) => {\n // @ts-ignore\n _registerMethod((next) => {\n // @ts-ignore\n const children = _htmlElementToVNode(elem);\n\n next._setProps({ children: [children] });\n });\n },\n [_htmlElementToVNode, _registerMethod]\n );\n\n // @ts-ignore\n context.appendChild = useCallback(\n (elem: HTMLElement) => {\n // @ts-ignore\n _registerMethod((next) => {\n // @ts-ignore\n const vnode = _htmlElementToVNode(elem);\n\n next._setProps((prev: any) => {\n return {\n ...prev,\n children: [...prev.children, vnode],\n };\n });\n });\n },\n [_htmlElementToVNode, _registerMethod]\n );\n\n // @ts-ignore\n context.prependChild = useCallback(\n (elem: HTMLElement) => {\n // @ts-ignore\n _registerMethod((next) => {\n // @ts-ignore\n const vnode = _htmlElementToVNode(elem);\n\n next._setProps((prev: any) => {\n return {\n ...prev,\n children: [vnode, ...prev.children],\n };\n });\n });\n },\n [_htmlElementToVNode, _registerMethod]\n );\n\n // @ts-ignore\n context.appendSibling = useCallback(\n (elem: HTMLElement) => {\n // @ts-ignore\n _registerMethod(() => {\n const parent = elementRef.current?.parentNode;\n\n parent?.insertBefore(elem, elementRef.current?.nextSibling ?? null);\n });\n },\n [_registerMethod]\n );\n\n // @ts-ignore\n context.prependSibling = useCallback(\n (elem: HTMLElement) => {\n // @ts-ignore\n _registerMethod(() => {\n const parent = elementRef.current?.parentNode;\n\n parent?.insertBefore(elem, elementRef.current);\n });\n },\n [_registerMethod]\n );\n\n const handleLifeCycleRender = useCallback(async () => {\n if (status.current === 'loading') return;\n\n status.current = 'loading';\n\n log(`🟨 \"${name}\" Slot Rendered`);\n\n // Reset\n const renderNode = render\n ? cloneElement(render(props), { key: 'render' })\n : null;\n _setProps({ children: [renderNode ?? children] });\n\n // Run all registered methods\n methodsRef.current.forEach((method: any) => {\n method(context, state);\n });\n\n status.current = 'ready';\n }, [children, context, name, props, render, state]);\n\n // Initialization\n const handleLifeCycleInit = useCallback(async () => {\n if (!callback) return;\n\n try {\n status.current = 'loading';\n\n log(`🟩 \"${name}\" Slot Initialized`);\n await callback(\n context as K & DefaultSlotContext<K>,\n elementRef.current as HTMLDivElement | null\n );\n } catch (error) {\n console.error(`Error in \"${callback.name}\" Slot callback`, error);\n } finally {\n status.current = 'ready';\n\n // first render\n await handleLifeCycleRender();\n }\n }, [callback, context, handleLifeCycleRender, name]);\n\n // Initialization\n useEffect(() => {\n handleLifeCycleInit().finally(() => {\n if (slotsQueue && slotsQueue.value.has(name)) {\n slotsQueue.value.delete(name);\n slotsQueue.value = new Set(slotsQueue.value);\n }\n });\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n // Update\n useEffect(() => {\n handleLifeCycleRender();\n\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [JSON.stringify(context), JSON.stringify(_state)]);\n\n return [elementRef, props];\n}\n\n// Slot Component\ninterface SlotPropsComponent<T>\n extends Omit<HTMLAttributes<HTMLElement>, 'slot'> {\n name: string;\n lazy?: boolean;\n slot?: SlotProps<T>;\n context?: Context<T>;\n render?: (props: Record<string, any>) => VNode | VNode[];\n // eslint-disable-next-line no-undef\n slotTag?: keyof HTMLElementTagNameMap; // The tag for the slot wrapper itself\n // eslint-disable-next-line no-undef\n contentTag?: keyof HTMLElementTagNameMap; // The tag for dynamically inserted content\n children?: ComponentChildren;\n}\n\nexport function Slot<T>({\n name,\n lazy = false,\n context,\n slot,\n children,\n render,\n slotTag = 'div',\n contentTag = 'div',\n ...props\n}: Readonly<SlotPropsComponent<T>>): VNode<{\n ref: RefObject<HTMLElement>;\n 'data-slot': string;\n [key: string]: any;\n}> {\n const slotsQueue = useContext(SlotQueueContext);\n\n const [elementRef, slotProps] = useSlot<T, HTMLElement>(\n name,\n context,\n slot,\n children,\n render,\n contentTag\n );\n\n useMemo(() => {\n if (!name) {\n return console.warn('Slot \"name\" is required');\n }\n\n // add slot to queue\n if (slotsQueue && lazy === false) {\n slotsQueue.value.add(name);\n slotsQueue.value = new Set(slotsQueue.value);\n }\n }, [name, lazy, slotsQueue]);\n\n return createElement(\n slotTag,\n {\n ...props,\n ref: elementRef,\n 'data-slot': name,\n },\n slotProps.children\n );\n}\n\n// Debugger\n\n// @ts-ignore\nwindow.DROPINS = window.DROPINS || {};\n\n// @ts-ignore\nwindow.DROPINS.showSlots = async (state) => {\n // cache state in session storage\n window.sessionStorage.setItem(\n 'dropin-debugger--show-slots',\n state.toString()\n );\n\n document.body.classList.toggle('dropin-debugger--show-slots', state);\n};\n\nlet log: (...attrs: any) => void = () => {};\n\n// @ts-ignore\nwindow.DROPINS.logSlots = async (state) => {\n // cache state in session storage\n window.sessionStorage.setItem('dropin-debugger--log-slots', state.toString());\n\n log = state ? (...attrs) => console.log(...attrs) : () => {};\n};\n\n/** Persistent Settings */\n\n// @ts-ignore\nwindow.DROPINS.showSlots(\n window.sessionStorage.getItem('dropin-debugger--show-slots') === 'true'\n);\n\n// @ts-ignore\nwindow.DROPINS.logSlots(\n window.sessionStorage.getItem('dropin-debugger--log-slots') === 'true'\n);\n","/**\n * Get cookie\n * @param {string} cookieName - The name of the cookie to get\n * @returns {string} - The value of the cookie\n */\nexport function getCookie(cookieName: string): string | undefined {\n const cookies = document.cookie.split(';');\n let foundValue;\n\n cookies.forEach((cookie) => {\n const [name, value] = cookie.trim().split('=');\n if (name === cookieName) {\n foundValue = decodeURIComponent(value);\n }\n });\n\n return foundValue;\n}\n"],"names":["getFormValues","form","formData","getFormErrors","data","result","key","field","mergeOptions","target","source","options","destination","item","index","deepmerge","merge","prev","next","toLanguageTag","locale","useSlot","name","context","callback","children","render","contentTag","slotsQueue","useContext","SlotQueueContext","elementRef","useRef","status","methodsRef","props","_setProps","useState","_state","setState","state","useMemo","value","intl","IntlContext","_next","renderNode","cloneElement","n","_registerMethod","useCallback","cb","_htmlElementToVNode","elem","createElement","refElem","element","_a","log","_b","parent","vnode","handleLifeCycleRender","method","handleLifeCycleInit","error","useEffect","Slot","lazy","slot","slotTag","slotProps","attrs","getCookie","cookieName","cookies","foundValue","cookie"],"mappings":"ymBASa,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EAG1C,OAAO,QAAQ,SAAW,MAAOlB,GAAU,CAEzC,OAAO,eAAe,QAAQ,6BAA8BA,EAAM,UAAU,EAEtEkB,EAAAlB,EAAQ,IAAIgC,IAAU,QAAQ,IAAI,GAAGA,CAAK,EAAI,IAAM,CAAC,CAC7D,EAKA,OAAO,QAAQ,UACb,OAAO,eAAe,QAAQ,6BAA6B,IAAM,MACnE,EAGA,OAAO,QAAQ,SACb,OAAO,eAAe,QAAQ,4BAA4B,IAAM,MAClE,EC/cO,SAASC,EAAUC,EAAwC,CAChE,MAAMC,EAAU,SAAS,OAAO,MAAM,GAAG,EACrC,IAAAC,EAEI,OAAAD,EAAA,QAASE,GAAW,CACpB,KAAA,CAACvD,EAAMoB,CAAK,EAAImC,EAAO,KAAK,EAAE,MAAM,GAAG,EACzCvD,IAASoD,IACXE,EAAa,mBAAmBlC,CAAK,EACvC,CACD,EAEMkC,CACT"}
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@dropins/tools", "version": "1.
|
|
1
|
+
{"name": "@dropins/tools", "version": "1.6.0-alpha999", "license": "SEE LICENSE IN LICENSE.md"}
|
|
@@ -9,8 +9,6 @@ export interface ProductItemCardProps extends Omit<HTMLAttributes<HTMLDivElement
|
|
|
9
9
|
actionButton?: VNode;
|
|
10
10
|
swatches?: VNode;
|
|
11
11
|
initialized?: boolean;
|
|
12
|
-
imageHref?: string;
|
|
13
|
-
imageLinkLabel?: string;
|
|
14
12
|
}
|
|
15
13
|
export declare const ProductItemCard: FunctionComponent<ProductItemCardProps>;
|
|
16
14
|
//# sourceMappingURL=ProductItemCard.d.ts.map
|
|
@@ -24,10 +24,15 @@ export declare class Render {
|
|
|
24
24
|
* @returns A function to render the component to a root element.
|
|
25
25
|
*/
|
|
26
26
|
render<T>(Component: Container<T>, props: T): (rootElement: HTMLElement) => Promise<RenderAPI>;
|
|
27
|
+
/**
|
|
28
|
+
* Unmounts a container from a root element.
|
|
29
|
+
* @param rootElement - The root element to unmount the container from.
|
|
30
|
+
*/
|
|
31
|
+
static unmount(rootElement: HTMLElement): void;
|
|
27
32
|
/**
|
|
28
33
|
* UnRenders a component from a root element.
|
|
29
34
|
* @param rootElement - The root element to unmount the component from.
|
|
30
|
-
* @deprecated Use `remove` method from the returned object of the `mount` method instead.
|
|
35
|
+
* @deprecated Use `remove` method from the returned object of the `mount` method instead or `unmount` method from the `Render` class.
|
|
31
36
|
*/
|
|
32
37
|
unmount(rootElement: HTMLElement): void;
|
|
33
38
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ComponentChildren, RefObject, VNode } from 'preact';
|
|
2
|
-
import { StateUpdater } from 'preact/hooks';
|
|
3
1
|
import { Lang } from '../i18n';
|
|
2
|
+
import { ComponentChildren, RefObject, VNode } from 'preact';
|
|
4
3
|
import { HTMLAttributes } from 'preact/compat';
|
|
4
|
+
import { StateUpdater } from 'preact/hooks';
|
|
5
5
|
|
|
6
6
|
type MutateElement = (elem: HTMLElement) => void;
|
|
7
7
|
interface State {
|
|
@@ -36,6 +36,7 @@ export type SlotMethod<P = any> = (callback: (next: unknown, state: State) => P)
|
|
|
36
36
|
export declare function useSlot<K, V extends HTMLElement>(name: string, context?: Context<K>, callback?: SlotProps<K>, children?: ComponentChildren, render?: Function, contentTag?: keyof HTMLElementTagNameMap): [RefObject<V>, Record<string, any>];
|
|
37
37
|
interface SlotPropsComponent<T> extends Omit<HTMLAttributes<HTMLElement>, 'slot'> {
|
|
38
38
|
name: string;
|
|
39
|
+
lazy?: boolean;
|
|
39
40
|
slot?: SlotProps<T>;
|
|
40
41
|
context?: Context<T>;
|
|
41
42
|
render?: (props: Record<string, any>) => VNode | VNode[];
|
|
@@ -43,7 +44,7 @@ interface SlotPropsComponent<T> extends Omit<HTMLAttributes<HTMLElement>, 'slot'
|
|
|
43
44
|
contentTag?: keyof HTMLElementTagNameMap;
|
|
44
45
|
children?: ComponentChildren;
|
|
45
46
|
}
|
|
46
|
-
export declare function Slot<T>({ name, context, slot, children, render, slotTag, contentTag, ...props }: Readonly<SlotPropsComponent<T>>): VNode<{
|
|
47
|
+
export declare function Slot<T>({ name, lazy, context, slot, children, render, slotTag, contentTag, ...props }: Readonly<SlotPropsComponent<T>>): VNode<{
|
|
47
48
|
ref: RefObject<HTMLElement>;
|
|
48
49
|
'data-slot': string;
|
|
49
50
|
[key: string]: any;
|
|
@@ -54,6 +54,12 @@ declare class FetchGraphQLMesh {
|
|
|
54
54
|
* @param key - The key of the header.
|
|
55
55
|
*/
|
|
56
56
|
removeFetchGraphQlHeader(key: string): void;
|
|
57
|
+
/**
|
|
58
|
+
* Gets the value of a specific GraphQL header.
|
|
59
|
+
* @param key - The key of the header.
|
|
60
|
+
* @returns The value of the header, or undefined if not found.
|
|
61
|
+
*/
|
|
62
|
+
getFetchGraphQlHeader(key: string): string | null | undefined;
|
|
57
63
|
/**
|
|
58
64
|
* Sets the GraphQL headers.
|
|
59
65
|
* @param header - The header object or a function that returns a header object.
|
|
@@ -120,6 +126,7 @@ declare class FetchGraphQLMesh {
|
|
|
120
126
|
getMethods(): {
|
|
121
127
|
setEndpoint: (endpoint: string) => void;
|
|
122
128
|
setFetchGraphQlHeader: (key: string, value: string | null) => void;
|
|
129
|
+
getFetchGraphQlHeader: (key: string) => string | null | undefined;
|
|
123
130
|
removeFetchGraphQlHeader: (key: string) => void;
|
|
124
131
|
setFetchGraphQlHeaders: (header: Header | ((prev: Header) => Header)) => void;
|
|
125
132
|
fetchGraphQl: <T = any>(query: string, options?: FetchOptions | undefined) => Promise<{
|
|
@@ -151,11 +158,12 @@ export declare class FetchGraphQL extends FetchGraphQLMesh {
|
|
|
151
158
|
* @property {Function} setEndpoint - Sets the GraphQL endpoint.
|
|
152
159
|
* @property {Function} setFetchGraphQlHeaders - Sets the GraphQL headers.
|
|
153
160
|
* @property {Function} setFetchGraphQlHeader - Sets a specific GraphQL header.
|
|
161
|
+
* @property {Function} getFetchGraphQlHeader - Gets the value of a specific GraphQL header.
|
|
154
162
|
* @property {Function} removeFetchGraphQlHeader - Removes a specific GraphQL header.
|
|
155
163
|
* @property {Function} fetchGraphQl - Fetches GraphQL data.
|
|
156
164
|
* @property {Function} getConfig - Gets the configuration.
|
|
157
165
|
*/
|
|
158
|
-
export declare const setEndpoint: (endpoint: string) => void, setFetchGraphQlHeaders: (header: Header | ((prev: Header) => Header)) => void, setFetchGraphQlHeader: (key: string, value: string | null) => void, removeFetchGraphQlHeader: (key: string) => void, fetchGraphQl: <T = any>(query: string, options?: FetchOptions) => Promise<{
|
|
166
|
+
export declare const setEndpoint: (endpoint: string) => void, setFetchGraphQlHeaders: (header: Header | ((prev: Header) => Header)) => void, setFetchGraphQlHeader: (key: string, value: string | null) => void, getFetchGraphQlHeader: (key: string) => string | null | undefined, removeFetchGraphQlHeader: (key: string) => void, fetchGraphQl: <T = any>(query: string, options?: FetchOptions) => Promise<{
|
|
159
167
|
errors?: FetchQueryError | undefined;
|
|
160
168
|
data: T;
|
|
161
169
|
}>, getConfig: () => {
|
|
@@ -3,6 +3,7 @@ import { ReCaptchaV3Response, PropsFormTypes, ReCaptchaV3Model } from './types/r
|
|
|
3
3
|
export declare const recaptchaFetchApi: {
|
|
4
4
|
setEndpoint: (endpoint: string) => void;
|
|
5
5
|
setFetchGraphQlHeader: (key: string, value: string | null) => void;
|
|
6
|
+
getFetchGraphQlHeader: (key: string) => string | null | undefined;
|
|
6
7
|
removeFetchGraphQlHeader: (key: string) => void;
|
|
7
8
|
setFetchGraphQlHeaders: (header: import('@adobe-commerce/fetch-graphql').Header | ((prev: import('@adobe-commerce/fetch-graphql').Header) => import('@adobe-commerce/fetch-graphql').Header)) => void;
|
|
8
9
|
fetchGraphQl: <T = any>(query: string, options?: import('@adobe-commerce/fetch-graphql').FetchOptions | undefined) => Promise<{
|