@velastack/patterns 0.1.8 → 0.1.10

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/dist/index.js CHANGED
@@ -28,7 +28,7 @@ var de = Object.create, fe = Object.defineProperty, pe = Object.getOwnPropertyDe
28
28
  throw Error("Calling `require` for \"" + e + "\" in an environment that doesn't expose the `require` function. See https://rolldown.rs/in-depth/bundling-cjs#require-external-modules for more details.");
29
29
  }), xe = {
30
30
  name: "@velastack/patterns",
31
- version: "0.1.8",
31
+ version: "0.1.10",
32
32
  description: "Registry of VelaStack patterns: generators and modifications applied to SvelteKit projects by the VelaStack CLI.",
33
33
  type: "module",
34
34
  private: !1,
@@ -4828,8 +4828,8 @@ var tl = {
4828
4828
  baseline: "velastack",
4829
4829
  generate: el
4830
4830
  }, nl = /* #__PURE__ */ Object.assign({
4831
- "./preview-modifies/src/routes/+layout.server.ts": "import { loadFlash } from 'sveltekit-flash-message/server';\nimport { defineBaseMetaTags } from 'svelte-meta-tags';\nimport { error, redirect } from '@sveltejs/kit';\nimport { loadCms } from '$lib/cms';\n\nexport const load = loadFlash(async (event) => {\n const { locals, url } = event;\n const canonical = new URL(url.pathname, url.origin).href;\n\n const baseTags = defineBaseMetaTags({\n title: '',\n titleTemplate: `%s | ${locals.meta.appName}`,\n description: '',\n canonical,\n openGraph: {\n type: 'website',\n url: canonical,\n images: [\n {\n url: `${locals.meta.appURL}/og.jpg`,\n alt: locals.meta.appName,\n width: 1200,\n height: 630\n }\n ]\n }\n });\n\n // [!code highlight:4]\n const { cms, notFound, gone, redirectTo } = await loadCms(event, { locale: 'en' });\n if (redirectTo) redirect(308, redirectTo);\n if (gone) error(410, 'Gone');\n if (notFound) error(404, 'Not found');\n\n return {\n meta: locals.meta,\n cms,\n ...baseTags\n };\n});\n",
4832
- "./preview-modifies/src/routes/+layout.svelte": "<script lang=\"ts\">\n import '../app.css';\n\n import favicon from '$lib/assets/favicon.svg';\n\n import { ModeWatcher } from 'mode-watcher';\n import { getFlash } from 'sveltekit-flash-message';\n import { toast } from 'svelte-sonner';\n import { page } from '$app/state';\n import { Toaster } from '$lib/components/ui/sonner';\n import { MetaTags, deepMerge } from 'svelte-meta-tags';\n import { AdminBar } from '@velastack/cms';\n\n let { data, children } = $props();\n const flash = getFlash(page);\n\n $effect(() => {\n if (!$flash || $flash.type !== 'toast') {\n return;\n }\n\n toast.message($flash.message);\n\n $flash = undefined;\n });\n\n let metaTags = $derived(deepMerge(data.baseMetaTags, page.data.pageMetaTags));\n<\/script>\n\n<svelte:head>\n <title>{data.meta.appName}</title>\n <link rel=\"icon\" href={favicon} />\n</svelte:head>\n\n<MetaTags {...metaTags} />\n<ModeWatcher />\n<Toaster />\n\n{@render children?.()}\n\n<!-- [!code highlight:1] -->\n<AdminBar />\n",
4831
+ "./preview-modifies/src/routes/+layout.server.ts": "import { loadFlash } from 'sveltekit-flash-message/server';\nimport { defineBaseMetaTags } from 'svelte-meta-tags';\nimport { error, redirect } from '@sveltejs/kit';\nimport { loadCms } from '$lib/cms';\n\nexport const load = loadFlash(async (event) => {\n const { locals, url } = event;\n const canonical = new URL(url.pathname, url.origin).href;\n\n const baseTags = defineBaseMetaTags({\n title: '',\n titleTemplate: `%s | ${locals.meta.appName}`,\n description: '',\n canonical,\n openGraph: {\n type: 'website',\n url: canonical,\n images: [\n {\n url: `${locals.meta.appURL}/og.jpg`,\n alt: locals.meta.appName,\n width: 1200,\n height: 630\n }\n ]\n }\n });\n\n // [!code highlight:6]\n const { cms, notFound, gone, redirectTo } = await loadCms(event, {\n locale: 'en'\n });\n if (redirectTo) redirect(308, redirectTo);\n if (gone) error(410, 'Gone');\n if (notFound) error(404, 'Not found');\n\n return {\n meta: locals.meta,\n cms,\n ...baseTags\n };\n});\n",
4832
+ "./preview-modifies/src/routes/+layout.svelte": "<script lang=\"ts\">\n import '../app.css';\n\n import favicon from '$lib/assets/favicon.svg';\n\n import { ModeWatcher } from 'mode-watcher';\n import { getFlash } from 'sveltekit-flash-message';\n import { toast } from 'svelte-sonner';\n import { page } from '$app/state';\n import { Toaster } from '$lib/components/ui/sonner';\n import { MetaTags, deepMerge } from 'svelte-meta-tags';\n // [!code highlight:1]\n import { AdminBar } from '@velastack/cms';\n\n let { data, children } = $props();\n const flash = getFlash(page);\n\n $effect(() => {\n if (!$flash || $flash.type !== 'toast') {\n return;\n }\n\n toast.message($flash.message);\n\n $flash = undefined;\n });\n\n let metaTags = $derived(deepMerge(data.baseMetaTags, page.data.pageMetaTags));\n<\/script>\n\n<svelte:head>\n <title>{data.meta.appName}</title>\n <link rel=\"icon\" href={favicon} />\n</svelte:head>\n\n<MetaTags {...metaTags} />\n<ModeWatcher />\n<Toaster />\n\n{@render children?.()}\n\n<!-- [!code highlight:1] -->\n<AdminBar />\n",
4833
4833
  "./preview-modifies/vite.config.ts": "// [!code highlight:1]\nimport { cms } from '@velastack/cms/vite';\nimport { defineConfig } from 'vite';\nimport tailwindcss from '@tailwindcss/vite';\nimport { sveltekit } from '@sveltejs/kit/vite';\nimport adapter from '@sveltejs/adapter-auto';\n\nexport default defineConfig({\n plugins: [\n tailwindcss(),\n // [!code highlight:1]\n cms(),\n sveltekit({\n compilerOptions: {\n runes: ({ filename }) =>\n filename.split(/[/\\\\]/).includes('node_modules') ? undefined : true\n },\n adapter: adapter(),\n // Prerendering has no request to take an origin from, so without this\n // every canonical link and `og:url` on a prerendered page would be built\n // from SvelteKit's placeholder host. `vela build` sets it from the domain\n // the target is deployed on; unset, SvelteKit's default stands.\n ...(process.env.VELA_ORIGIN\n ? { prerender: { origin: process.env.VELA_ORIGIN } }\n : {})\n })\n ]\n});\n"
4834
4834
  }), rl = "./preview-modifies/";
4835
4835
  async function il(e) {
@@ -5019,7 +5019,7 @@ var Al = {
5019
5019
  tests: 0,
5020
5020
  baseline: "velastack",
5021
5021
  generate: kl
5022
- }, jl = "import { deLocalizeDefault } from \"wuchale/url\";\nimport { matchUrl } from \"$locales/main.url\";\nimport { locales } from \"$locales/data\";\n\nconst rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n};\n\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n", Ml = "<script lang=\"ts\">\n import * as Select from \"$lib/components/ui/select/index.js\";\n import { locales, type Locale } from \"$locales/data.js\";\n import { page } from \"$app/state\";\n import { goto } from \"$app/navigation\";\n import { deLocalizeDefault } from \"wuchale/url\";\n import { defaultLocale, translateUrl } from \"$lib/url\";\n\n let locale: Locale = $derived.by(() => {\n const [_, locale] = deLocalizeDefault(page.url.pathname, locales);\n return locale ?? defaultLocale;\n });\n\n function localeDisplayName(code: Locale): string {\n const names = new Intl.DisplayNames([code], { type: \"language\" });\n const raw = names.of(code);\n if (!raw) return code;\n return raw.charAt(0).toLocaleUpperCase(code) + raw.slice(1);\n }\n\n const localeNames: Record<string, string> = locales.reduce(\n (acc, loc) => {\n acc[loc] = localeDisplayName(loc);\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const handleValueChange = (value: string) => {\n const translatedUrl = translateUrl(\n page.url.pathname,\n locale,\n value as Locale,\n );\n goto(translatedUrl, { invalidateAll: true });\n };\n\n let { class: className }: { class?: string } = $props();\n<\/script>\n\n<Select.Root type=\"single\" value={locale} onValueChange={handleValueChange}>\n <Select.Trigger class={className}>{localeNames[locale]}</Select.Trigger>\n <Select.Content>\n {#each locales as locale}\n <Select.Item value={locale}>{localeNames[locale]}</Select.Item>\n {/each}\n </Select.Content>\n</Select.Root>\n", Nl = "import { deLocalizeDefault, stringifyPattern } from \"wuchale/url\";\nimport type { Locale } from \"../locales/data\";\nimport { matchUrl } from \"../locales/main.url\";\nimport { locales } from \"../locales/data\";\n\n// wuchale treats locales[0] as the source locale, so it is the one served unprefixed\nexport const defaultLocale: Locale = locales[0];\n\n/**\n * Localizer for wuchale's `url.localize` config. Compiled URLs in components\n * are passed through this, so the default locale stays unprefixed.\n */\nexport function localize(path: string, locale: Locale) {\n if (locale === defaultLocale) {\n return path;\n }\n\n // matches wuchale's localizeDefault, which drops the trailing slash\n const localized = `/${locale}${path}`;\n return localized.endsWith(\"/\") ? localized.slice(0, -1) : localized;\n}\n\nexport function translateUrl(\n url: string,\n fromLocale: Locale,\n toLocale: Locale,\n) {\n const [pathOnly] = deLocalizeDefault(url, locales);\n const result = matchUrl(pathOnly, fromLocale);\n if (result.path !== null) {\n const targetPath = stringifyPattern(\n result.altPatterns[toLocale],\n result.params,\n );\n return localize(targetPath, toLocale);\n }\n return localize(pathOnly, toLocale);\n}\n", Pl = "// @ts-check\nimport { adapter as svelte } from \"@wuchale/svelte\";\nimport { adapter as js } from \"wuchale/adapter-vanilla\";\nimport { defineConfig } from \"wuchale\";\n\nexport default defineConfig({\n locales: [\"en\", \"es\"],\n adapters: {\n main: svelte({\n loader: \"sveltekit\",\n url: { localize: \"src/lib/url.ts\", patterns: [\"/\"] },\n }),\n js: js({\n loader: \"vite\",\n files: [\n \"src/**/+{page,layout}.{js,ts}\",\n \"src/**/+{page,layout}.server.{js,ts}\",\n ],\n }),\n },\n});\n", Fl = /* #__PURE__ */ Object.assign({
5022
+ }, jl = "import { deLocalizeDefault } from \"wuchale/url\";\nimport { matchUrl } from \"$locales/main.url\";\nimport { locales } from \"$locales/data\";\n\nconst rerouteDeLocalize = (url: string) => {\n const [upath, locale] = deLocalizeDefault(url, locales);\n const { path } = matchUrl(upath, locale);\n return path ?? url;\n};\n\nexport const reroute = ({ url }) => rerouteDeLocalize(url.pathname);\n", Ml = "<script lang=\"ts\">\n import * as Select from \"$lib/components/ui/select/index.js\";\n import { locales, type Locale } from \"$locales/data.js\";\n import { page } from \"$app/state\";\n import { goto } from \"$app/navigation\";\n import { deLocalizeDefault } from \"wuchale/url\";\n import { defaultLocale, translateUrl } from \"$lib/url\";\n\n let locale: Locale = $derived.by(() => {\n const [_, locale] = deLocalizeDefault(page.url.pathname, locales);\n return locale ?? defaultLocale;\n });\n\n function localeDisplayName(code: Locale): string {\n const names = new Intl.DisplayNames([code], { type: \"language\" });\n const raw = names.of(code);\n if (!raw) return code;\n return raw.charAt(0).toLocaleUpperCase(code) + raw.slice(1);\n }\n\n const localeNames: Record<string, string> = locales.reduce(\n (acc, loc) => {\n acc[loc] = localeDisplayName(loc);\n return acc;\n },\n {} as Record<string, string>,\n );\n\n const handleValueChange = (value: string) => {\n const translatedUrl = translateUrl(\n page.url.pathname,\n locale,\n value as Locale,\n );\n goto(translatedUrl, { invalidateAll: true });\n };\n\n let { class: className }: { class?: string } = $props();\n<\/script>\n\n<Select.Root type=\"single\" value={locale} onValueChange={handleValueChange}>\n <Select.Trigger class={className}>{localeNames[locale]}</Select.Trigger>\n <Select.Content>\n {#each locales as locale}\n <Select.Item value={locale}>{localeNames[locale]}</Select.Item>\n {/each}\n </Select.Content>\n</Select.Root>\n", Nl = "import { deLocalizeDefault, stringifyPattern } from \"wuchale/url\";\nimport type { Locale } from \"../locales/data\";\nimport { matchUrl } from \"../locales/main.url\";\nimport { locales } from \"../locales/data\";\n\n// wuchale treats locales[0] as the source locale, so it is the one served unprefixed\nexport const defaultLocale: Locale = locales[0];\n\n/**\n * Localizer for wuchale's `url.localize` config. Compiled URLs in components\n * are passed through this, so the default locale stays unprefixed.\n */\nexport function localize(path: string, locale: Locale) {\n if (locale === defaultLocale) {\n return path;\n }\n\n // matches wuchale's localizeDefault, which drops the trailing slash\n const localized = `/${locale}${path}`;\n return localized.endsWith(\"/\") ? localized.slice(0, -1) : localized;\n}\n\nexport function translateUrl(\n url: string,\n fromLocale: Locale,\n toLocale: Locale,\n) {\n const [pathOnly] = deLocalizeDefault(url, locales);\n const result = matchUrl(pathOnly, fromLocale);\n if (result.path !== null) {\n const targetPath = stringifyPattern(\n result.altPatterns[toLocale],\n result.params,\n );\n return localize(targetPath, toLocale);\n }\n return localize(pathOnly, toLocale);\n}\n", Pl = "// @ts-check\nimport { adapter as svelte } from \"@wuchale/svelte\";\nimport { adapter as js } from \"wuchale/adapter-vanilla\";\nimport { defineConfig } from \"wuchale\";\n\nexport default defineConfig({\n locales: [\"en\", \"es\"],\n // `vela test:server` stubs every +page.svelte. In the default `refs` dev mode\n // the extractor would take those stubs at face value, drop the pages'\n // references from the .po files and recompile the catalogs while requests\n // are in flight. Under TEST wuchale neither transforms nor writes anything.\n ...(process.env.TEST === \"true\" ? { dev: false } : {}),\n adapters: {\n main: svelte({\n loader: \"sveltekit\",\n url: { localize: \"src/lib/url.ts\", patterns: [\"/\"] },\n }),\n js: js({\n loader: \"vite\",\n files: [\n \"src/**/+{page,layout}.{js,ts}\",\n \"src/**/+{page,layout}.server.{js,ts}\",\n ],\n }),\n },\n});\n", Fl = /* #__PURE__ */ Object.assign({
5023
5023
  "./creates/src/hooks.ts": jl,
5024
5024
  "./creates/src/lib/components/language-select.svelte": Ml,
5025
5025
  "./creates/src/lib/url.ts": Nl,