repoweaver
Version:
A GitHub App that skillfully weaves multiple templates together to create and update repositories with intelligent merge strategies
1 lines • 7.2 kB
JSON
{"ast":null,"code":"'use client';\n\nimport _objectWithoutPropertiesLoose from \"@babel/runtime/helpers/objectWithoutPropertiesLoose\";\nconst _excluded = [\"get\", \"request\"];\nimport { useCallback, useEffect, useRef, useState } from 'react';\nfunction usePermission(methods, options) {\n const isMounted = useRef(true);\n const [status, setStatus] = useState(null);\n const _ref = options || {},\n {\n get = true,\n request = false\n } = _ref,\n permissionOptions = _objectWithoutPropertiesLoose(_ref, _excluded);\n const getPermission = useCallback(async () => {\n const response = await methods.getMethod(Object.keys(permissionOptions).length > 0 ? permissionOptions : undefined);\n if (isMounted.current) setStatus(response);\n return response;\n }, [methods.getMethod]);\n const requestPermission = useCallback(async () => {\n const response = await methods.requestMethod(Object.keys(permissionOptions).length > 0 ? permissionOptions : undefined);\n if (isMounted.current) setStatus(response);\n return response;\n }, [methods.requestMethod]);\n useEffect(function runMethods() {\n if (request) requestPermission();\n if (!request && get) getPermission();\n }, [get, request, requestPermission, getPermission]);\n useEffect(function didMount() {\n isMounted.current = true;\n return () => {\n isMounted.current = false;\n };\n }, []);\n return [status, requestPermission, getPermission];\n}\nexport function createPermissionHook(methods) {\n return options => usePermission(methods, options);\n}","map":{"version":3,"names":["_objectWithoutPropertiesLoose","_excluded","useCallback","useEffect","useRef","useState","usePermission","methods","options","isMounted","status","setStatus","_ref","get","request","permissionOptions","getPermission","response","getMethod","Object","keys","length","undefined","current","requestPermission","requestMethod","runMethods","didMount","createPermissionHook"],"sources":["/Users/pmouli/Documents/GitHub.nosync/boots-strapper/mobile/node_modules/expo-modules-core/src/PermissionsHook.ts"],"sourcesContent":["// Copyright © 2024 650 Industries.\n\n'use client';\n\nimport { useCallback, useEffect, useRef, useState } from 'react';\n\nimport { PermissionResponse } from './PermissionsInterface';\n\n// These types are identical, but improves the readability for suggestions in editors\ntype RequestPermissionMethod<Permission extends PermissionResponse> = () => Promise<Permission>;\ntype GetPermissionMethod<Permission extends PermissionResponse> = () => Promise<Permission>;\n\ntype PermissionHookMethods<Permission extends PermissionResponse, Options = never> = {\n /** The permission method that requests the user to grant permission. */\n requestMethod: (options?: Options) => Promise<Permission>;\n /** The permission method that only fetches the current permission status. */\n getMethod: (options?: Options) => Promise<Permission>;\n};\n\ntype PermissionHookBehavior = {\n /** If the hook should automatically fetch the current permission status, without asking the user. */\n get?: boolean;\n /** If the hook should automatically request the user to grant permission. */\n request?: boolean;\n};\n\nexport type PermissionHookOptions<Options extends object> = PermissionHookBehavior & Options;\n\n/**\n * Get or request permission for protected functionality within the app.\n * It uses separate permission requesters to interact with a single permission.\n * By default, the hook will only retrieve the permission status.\n */\nfunction usePermission<Permission extends PermissionResponse, Options extends object>(\n methods: PermissionHookMethods<Permission, Options>,\n options?: PermissionHookOptions<Options>\n): [Permission | null, RequestPermissionMethod<Permission>, GetPermissionMethod<Permission>] {\n const isMounted = useRef(true);\n const [status, setStatus] = useState<Permission | null>(null);\n const { get = true, request = false, ...permissionOptions } = options || {};\n\n const getPermission = useCallback(async () => {\n const response = await methods.getMethod(\n Object.keys(permissionOptions).length > 0 ? (permissionOptions as Options) : undefined\n );\n if (isMounted.current) setStatus(response);\n return response;\n }, [methods.getMethod]);\n\n const requestPermission = useCallback(async () => {\n const response = await methods.requestMethod(\n Object.keys(permissionOptions).length > 0 ? (permissionOptions as Options) : undefined\n );\n if (isMounted.current) setStatus(response);\n return response;\n }, [methods.requestMethod]);\n\n useEffect(\n function runMethods() {\n if (request) requestPermission();\n if (!request && get) getPermission();\n },\n [get, request, requestPermission, getPermission]\n );\n\n // Workaround for unmounting components receiving state updates\n useEffect(function didMount() {\n isMounted.current = true;\n return () => {\n isMounted.current = false;\n };\n }, []);\n\n return [status, requestPermission, getPermission];\n}\n\n/**\n * Create a new permission hook with the permission methods built-in.\n * This can be used to quickly create specific permission hooks in every module.\n */\nexport function createPermissionHook<Permission extends PermissionResponse, Options extends object>(\n methods: PermissionHookMethods<Permission, Options>\n) {\n return (options?: PermissionHookOptions<Options>) =>\n usePermission<Permission, Options>(methods, options);\n}\n"],"mappings":"AAEA,YAAY;;AAAC,OAAAA,6BAAA;AAAA,MAAAC,SAAA;AAEb,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AA6BhE,SAASC,aAAaA,CACpBC,OAAmD,EACnDC,OAAwC,EACmD;EAC3F,MAAMC,SAAS,GAAGL,MAAM,CAAC,IAAI,CAAC;EAC9B,MAAM,CAACM,MAAM,EAAEC,SAAS,CAAC,GAAGN,QAAQ,CAAoB,IAAI,CAAC;EAC7D,MAAAO,IAAA,GAA8DJ,OAAO,IAAI,CAAC,CAAC;IAArE;MAAEK,GAAG,GAAG,IAAI;MAAEC,OAAO,GAAG;IAA4B,CAAC,GAAAF,IAAA;IAAnBG,iBAAiB,GAAAf,6BAAA,CAAAY,IAAA,EAAAX,SAAA;EAEzD,MAAMe,aAAa,GAAGd,WAAW,CAAC,YAAY;IAC5C,MAAMe,QAAQ,GAAG,MAAMV,OAAO,CAACW,SAAS,CACtCC,MAAM,CAACC,IAAI,CAACL,iBAAiB,CAAC,CAACM,MAAM,GAAG,CAAC,GAAIN,iBAAiB,GAAeO,SAC/E,CAAC;IACD,IAAIb,SAAS,CAACc,OAAO,EAAEZ,SAAS,CAACM,QAAQ,CAAC;IAC1C,OAAOA,QAAQ;EACjB,CAAC,EAAE,CAACV,OAAO,CAACW,SAAS,CAAC,CAAC;EAEvB,MAAMM,iBAAiB,GAAGtB,WAAW,CAAC,YAAY;IAChD,MAAMe,QAAQ,GAAG,MAAMV,OAAO,CAACkB,aAAa,CAC1CN,MAAM,CAACC,IAAI,CAACL,iBAAiB,CAAC,CAACM,MAAM,GAAG,CAAC,GAAIN,iBAAiB,GAAeO,SAC/E,CAAC;IACD,IAAIb,SAAS,CAACc,OAAO,EAAEZ,SAAS,CAACM,QAAQ,CAAC;IAC1C,OAAOA,QAAQ;EACjB,CAAC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