TANSTACK QUERY V5 CODE GENERATOR
${en?'Query keys and options,
generated from TypeScript.':'쿼리 키와 옵션을
TypeScript 함수에서 생성합니다.'}
${esc(desc)}
${en?'Try it in the browser':'브라우저에서 써 보기'} ↓${en?'Quick start guide':'시작 가이드'} ↗TanStack Query v5 · TypeScript · React 18 / 19 · MIT
01 / PLAYGROUND
${en?'Paste a function, get the query layer':'함수를 붙여 넣으면 쿼리 코드가 나옵니다'}
${en?'This runs the package’s own analyzer and generator in your browser, so the output is what generate would write. Your code stays on this page.':'패키지의 실제 분석기와 생성기를 브라우저에서 돌립니다. 오른쪽 결과는 generate 명령이 쓰는 파일과 같습니다. 입력한 코드는 이 페이지 밖으로 나가지 않습니다.'}
${en?'Keys come from the path under libs/ and the function name.':'키는 libs/ 아래 경로와 함수 이름으로 만들어집니다.'}
${esc(initialOutput)}02 / SETUP AND CI
${en?'Install, generate, watch and check':'설치, 생성, watch, 검사'}
${en?'Generate once, watch during development and check generated output in CI. Reuse factories with useQuery, prefetchQuery and cache reads.':'한 번 생성하고, 개발 중에는 watch로 갱신하고, CI에서는 생성 결과를 검사하세요. useQuery·prefetchQuery·캐시 조회에 동일한 팩토리를 재사용합니다.'}
npm install @uiwwsw/react-query-helper@^2 @tanstack/react-query react + const page=`${esc(title)} ${en?'Skip to the playground':'플레이그라운드로 건너뛰기'}react query helper
TANSTACK QUERY V5 CODE GENERATOR
${en?'Query keys and options,
generated from TypeScript.':'쿼리 키와 옵션을
TypeScript 함수에서 생성합니다.'}${esc(desc)}
${en?'Try it in the browser':'브라우저에서 써 보기'} ↓${en?'Quick start guide':'시작 가이드'} ↗TanStack Query v5 · TypeScript · React 18 / 19 · MIT
01 / PLAYGROUND
${en?'Paste a function, get the query layer':'함수를 붙여 넣으면 쿼리 코드가 나옵니다'}
${en?'This runs the package’s own analyzer and generator in your browser, so the output is what
generatewould write. Your code stays on this page.':'패키지의 실제 분석기와 생성기를 브라우저에서 돌립니다. 오른쪽 결과는generate명령이 쓰는 파일과 같습니다. 입력한 코드는 이 페이지 밖으로 나가지 않습니다.'}${en?'Keys come from the path under
libs/and the function name.':'키는libs/아래 경로와 함수 이름으로 만들어집니다.'} src/options/users/apiOptions.ts${esc(initialOutput)}02 / SETUP AND CI
${en?'Install, generate, watch and check':'설치, 생성, watch, 검사'}
${en?'Generate once, watch during development and check generated output in CI. Reuse factories with useQuery, prefetchQuery and cache reads.':'한 번 생성하고, 개발 중에는 watch로 갱신하고, CI에서는 생성 결과를 검사하세요. useQuery·prefetchQuery·캐시 조회에 동일한 팩토리를 재사용합니다.'}
npm install @uiwwsw/react-query-helper@^2 @tanstack/react-query react npx @uiwwsw/react-query-helper init npx @uiwwsw/react-query-helper generate npx @uiwwsw/react-query-helper watch diff --git a/site/public/usage-analytics.css b/site/public/usage-analytics.css deleted file mode 100644 index 579ebc4..0000000 --- a/site/public/usage-analytics.css +++ /dev/null @@ -1,56 +0,0 @@ -#movv-usage-choice { - position: fixed; - z-index: 90; - bottom: calc(16px + env(safe-area-inset-bottom, 0px)); - right: 16px; - max-width: min(440px, calc(100vw - 32px)); - max-height: calc(100dvh - 48px); - overflow: auto; - font: inherit; - color: CanvasText; -} -#movv-usage-choice.usage-above-nav { - bottom: calc(80px + env(safe-area-inset-bottom, 0px)); - max-height: calc(100dvh - 112px); -} -#movv-usage-choice .usage-panel { - background: Canvas; - border: 1px solid #888; - border-radius: 16px; - padding: 20px; - box-shadow: 0 8px 32px #0003; -} -#movv-usage-choice p { - font: inherit; - line-height: 1.6; - margin: 0 0 16px; -} -#movv-usage-choice button { - font: inherit; - cursor: pointer; - border: 1px solid #888; - border-radius: 8px; - background: Canvas; - color: CanvasText; - padding: 8px 12px; - min-height: 40px; -} -#movv-usage-choice .usage-allow { - margin-left: 8px; - background: #193f36; - color: #fff; -} -#movv-usage-choice .usage-preference { - font-size: 12px; - box-shadow: 0 2px 8px #0002; -} -#movv-usage-choice a { - font: inherit; - color: inherit; - text-decoration: underline; -} -#movv-usage-choice .usage-detail { - font-size: 12px; - margin-top: 16px; - margin-bottom: 0; -} diff --git a/site/public/usage-analytics.js b/site/public/usage-analytics.js deleted file mode 100644 index a29e791..0000000 --- a/site/public/usage-analytics.js +++ /dev/null @@ -1,181 +0,0 @@ -// Google Tag Manager loads only after an explicit, browser-local choice. -export function screenForPath(config, input) { - const path = String(input).split(/[?#]/, 1)[0] || '/'; - return config.routes.find(route => new RegExp(route.match).test(path)) ?? null; -} - -export function usagePayload(config, screen, event, destination, placement) { - if (!screen || !config.routes.includes(screen)) return null; - return { - event, - service_name: config.service, - screen_name: screen.name, - page_location: config.origin + screen.path, - page_title: `${config.service} | ${screen.name}`, - page_referrer: '', - navigation_target: destination ?? '', - navigation_location: placement ?? '', - }; -} - -export function navigationDestination(config, url, currentPath, currentOrigin = config.origin) { - if (url.origin !== currentOrigin) return config.outbound?.find(link => link.url === url.href)?.name ?? null; - const screen = screenForPath(config, url.pathname); - const section = url.pathname === currentPath && url.hash ? config.sections?.[url.hash.slice(1)] : undefined; - if (!screen || (url.hash && !section && url.pathname === currentPath)) return null; - return section ?? screen.name; -} - -export function controlDestination(config, value) { - return config.controls?.includes(value) ? value : null; -} - -function start(config) { - if (!config.hosts.includes(location.hostname) || navigator.doNotTrack === '1') return; - const key = `${config.service}.usage-consent.v1`; - const container = 'GTM-5Q34H7QJ'; - let lastPath = ''; - let historyPath = location.pathname; - let currentScreen = screenForPath(config, location.pathname); - const consent = () => { - try { return localStorage.getItem(key); } catch { return 'denied'; } - }; - const choose = value => { - try { - localStorage.setItem(key, value); - applyConsent(); - host.querySelector('button')?.focus({preventScroll:true}); - } catch { /* Collection remains off. */ } - }; - const track = (screen = screenForPath(config, location.pathname), path = location.pathname) => { - currentScreen = screen; - const allowed = consent() === 'granted' && !!screen; - window['ga-disable-G-TRYJR3PLGB'] = !allowed; - if (!allowed) { lastPath = ''; return; } - if (lastPath === path) return; - const payload = usagePayload(config, screen, 'page_view'); - window.dataLayer ??= []; - if (!document.getElementById('movv-usage-gtm')) { - const { event, ...context } = payload; - window.dataLayer.push(context, { 'gtm.start': Date.now(), event: 'gtm.js' }); - const script = document.createElement('script'); - script.id = 'movv-usage-gtm'; - script.async = true; - script.src = `https://www.googletagmanager.com/gtm.js?id=${container}`; - document.head.append(script); - } - lastPath = path; - window.dataLayer.push(payload); - }; - - document.addEventListener('click', event => { - if (consent() !== 'granted' || !currentScreen || event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return; - const control = event.target instanceof Element ? event.target.closest('[data-usage-target]') : null; - const target = controlDestination(config, control?.getAttribute('data-usage-target')); - if (target) { - window.dataLayer?.push(usagePayload(config, currentScreen, 'navigation_select', target, 'control')); - return; - } - const anchor = event.target instanceof Element ? event.target.closest('a[href]') : null; - if (!anchor) return; - const url = new URL(anchor.href, location.href); - const destination = navigationDestination(config, url, location.pathname, location.origin); - if (!destination) return; - const placement = anchor.closest('header') ? 'header' : anchor.closest('footer') ? 'footer' : anchor.closest('nav,[role="navigation"]') ? 'navigation' : 'content'; - window.dataLayer?.push(usagePayload(config, currentScreen, 'navigation_select', destination, placement)); - }, true); - - const routeChanged = () => { - if (historyPath === location.pathname) return; - historyPath = location.pathname; - track(); - }; - for (const method of ['pushState', 'replaceState']) { - const original = history[method]; - history[method] = function (...args) { - const result = original.apply(this, args); - queueMicrotask(routeChanged); - return result; - }; - } - window.addEventListener('popstate', routeChanged); - window.addEventListener('storage', event => { - if (event.key === key || event.key === null) applyConsent(); - }); - // Canvas-based web apps may select a registered screen without sending route IDs. - window.movvUsage = { - screen(name) { - const screen = config.routes.find(route => route.name === name); - if (screen) track(screen, `screen:${name}`); - }, - }; - - const english = document.documentElement.lang.startsWith('en'); - const host = document.createElement('aside'); - host.id = 'movv-usage-choice'; - host.setAttribute('aria-label', english ? 'Usage statistics' : '이용 통계'); - if (Number(config.bottom) >= 64) host.className = 'usage-above-nav'; - const stylesheet = document.createElement('link'); - stylesheet.rel = 'stylesheet'; - stylesheet.href = config.stylesheet || '/usage-analytics.css'; - host.hidden = true; - stylesheet.onload = stylesheet.onerror = () => { host.hidden = false; }; - document.head.append(stylesheet); - const panel = () => { - host.replaceChildren(); - const box = document.createElement('div'); - box.className = 'usage-panel'; - const text = document.createElement('p'); - text.textContent = english ? 'Allow Google Analytics to measure page visits, navigation and engagement time? Names, email addresses, search terms and form values are excluded from event parameters.' : '페이지 방문·메뉴 이동과 참여시간을 Google Analytics로 집계해도 될까요? 이름·이메일·검색어·입력 내용은 이벤트에 담지 않습니다.'; - const deny = document.createElement('button'); - deny.type = 'button'; - deny.textContent = english ? 'Do not allow' : '허용 안 함'; - deny.onclick = () => choose('denied'); - const allow = document.createElement('button'); - allow.type = 'button'; - allow.className = 'usage-allow'; - allow.textContent = english ? 'Allow' : '허용'; - allow.onclick = () => choose('granted'); - const detail = document.createElement('p'); - detail.className = 'usage-detail'; - detail.append(english ? 'Google processes visitor cookies and device information. Change this choice using Usage stats. ' : '방문 구분 쿠키와 기기 정보가 처리됩니다. 이용 통계 버튼에서 선택을 바꿀 수 있습니다. '); - const policy = document.createElement('a'); - policy.href = 'https://policies.google.com/privacy'; - policy.target = '_blank'; - policy.rel = 'noopener noreferrer'; - policy.textContent = english ? 'Google privacy policy' : 'Google 개인정보처리방침'; - detail.append(policy); - box.append(text, deny, allow, detail); - host.append(box); - }; - const renderChoice = () => { - if (consent() === null) { panel(); return; } - host.replaceChildren(); - const button = document.createElement('button'); - button.type = 'button'; - button.className = 'usage-preference'; - button.textContent = english ? 'Usage stats' : '이용 통계'; - button.onclick = panel; - host.append(button); - }; - function applyConsent() { - const allowed = consent() === 'granted' && !!currentScreen; - window['ga-disable-G-TRYJR3PLGB'] = !allowed; - renderChoice(); - if (allowed) { - const path = lastPath || location.pathname; - lastPath = ''; - track(currentScreen, path); - } - } - document.body.append(host); - applyConsent(); - window.dispatchEvent(new Event('movv-usage-ready')); -} - -if (typeof document !== 'undefined') { - const script = document.querySelector('script[data-usage-config]'); - if (script) { - try { start(JSON.parse(script.dataset.usageConfig)); } catch { /* Invalid configuration never enables collection. */ } - } -}