@salesforce/ui-bundle-template-feature-vue-language-switcher 0.0.0-stage → 13.2.0
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.txt +82 -0
- package/README.md +141 -2
- package/dist/.forceignore +15 -0
- package/dist/.husky/pre-commit +4 -0
- package/dist/.prettierignore +11 -0
- package/dist/.prettierrc +17 -0
- package/dist/CHANGELOG.md +5431 -0
- package/dist/README.md +83 -0
- package/dist/config/project-scratch-def.json +13 -0
- package/dist/eslint.config.js +7 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/.forceignore +15 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/.graphqlrc.yml +2 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/.prettierignore +9 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/.prettierrc +11 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/README.md +43 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/codegen.yml +95 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/components.json +19 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/e2e/app.spec.ts +17 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/eslint.config.js +124 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/feature-vue-language-switcher.uibundle-meta.xml +7 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/index.html +12 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/package.json +72 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/playwright.config.ts +24 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/scripts/get-graphql-schema.mjs +71 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/scripts/rewrite-e2e-assets.mjs +23 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/App.vue +5 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/api/graphqlClient.ts +44 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/appLayout.vue +80 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/alerts/status-alert.vue +59 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/layouts/card-layout.vue +30 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/alert/Alert.vue +21 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/alert/AlertAction.vue +17 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/alert/AlertDescription.vue +22 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/alert/AlertTitle.vue +22 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/alert/index.ts +25 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/avatar/Avatar.vue +23 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/avatar/AvatarFallback.vue +31 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/avatar/AvatarImage.vue +16 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/avatar/index.ts +3 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/button/Button.vue +33 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/button/index.ts +43 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/card/Card.vue +29 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/card/CardAction.vue +22 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/card/CardContent.vue +17 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/card/CardDescription.vue +17 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/card/CardFooter.vue +22 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/card/CardHeader.vue +22 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/card/CardTitle.vue +22 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/card/index.ts +7 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/checkbox/Checkbox.vue +43 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/checkbox/index.ts +1 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/collapsible/Collapsible.vue +19 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/collapsible/CollapsibleContent.vue +12 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/collapsible/CollapsibleTrigger.vue +12 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/collapsible/index.ts +3 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dialog/Dialog.vue +15 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dialog/DialogClose.vue +12 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dialog/DialogContent.vue +59 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dialog/DialogDescription.vue +31 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dialog/DialogFooter.vue +33 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dialog/DialogHeader.vue +17 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dialog/DialogOverlay.vue +31 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dialog/DialogPortal.vue +12 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dialog/DialogTitle.vue +26 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dialog/DialogTrigger.vue +12 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dialog/index.ts +10 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenu.vue +19 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuCheckboxItem.vue +51 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuContent.vue +47 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuGroup.vue +12 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuItem.vue +44 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuLabel.vue +30 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuPortal.vue +12 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuRadioGroup.vue +21 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuRadioItem.vue +52 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuSeparator.vue +26 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuShortcut.vue +19 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuSub.vue +19 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuSubContent.vue +37 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuSubTrigger.vue +38 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/DropdownMenuTrigger.vue +17 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/dropdown-menu/index.ts +15 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/field/Field.vue +27 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/field/FieldContent.vue +22 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/field/FieldDescription.vue +24 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/field/FieldError.vue +48 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/field/FieldGroup.vue +22 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/field/FieldLabel.vue +24 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/field/FieldLegend.vue +29 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/field/FieldSeparator.vue +31 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/field/FieldSet.vue +22 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/field/FieldTitle.vue +22 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/field/index.ts +33 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/index.ts +115 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/input/Input.vue +30 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/input/index.ts +1 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/label/Label.vue +29 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/label/index.ts +1 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/pagination/Pagination.vue +17 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/pagination/PaginationContent.vue +15 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/pagination/PaginationEllipsis.vue +23 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/pagination/PaginationItem.vue +7 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/pagination/PaginationLink.vue +31 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/pagination/PaginationNext.vue +29 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/pagination/PaginationPrevious.vue +29 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/pagination/index.ts +7 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/popover/Popover.vue +15 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/popover/PopoverAnchor.vue +12 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/popover/PopoverContent.vue +44 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/popover/PopoverDescription.vue +17 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/popover/PopoverHeader.vue +17 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/popover/PopoverTitle.vue +14 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/popover/PopoverTrigger.vue +12 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/popover/index.ts +7 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/select/Select.vue +15 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/select/SelectContent.vue +65 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/select/SelectGroup.vue +26 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/select/SelectItem.vue +41 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/select/SelectLabel.vue +26 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/select/SelectScrollDownButton.vue +32 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/select/SelectScrollUpButton.vue +32 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/select/SelectSeparator.vue +24 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/select/SelectTrigger.vue +45 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/select/SelectValue.vue +12 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/select/index.ts +10 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/separator/Separator.vue +33 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/separator/index.ts +1 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/skeleton/Skeleton.vue +15 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/skeleton/index.ts +1 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/sonner/Sonner.vue +29 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/sonner/index.ts +3 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/spinner/Spinner.vue +17 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/components/ui/spinner/index.ts +1 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/composables/useAsyncData.ts +69 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/LanguageSwitcher.vue +75 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/__examples__/language-switcher-example.vue +34 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/__examples__/vite-config-site-example.ts +44 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/buildLanguageUrl.ts +158 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/getCurrentLanguage.ts +59 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/index.ts +31 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/languages.ts +46 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/index.ts +8 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/lib/utils.ts +6 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/main.ts +6 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/pages/Home.vue +10 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/pages/NotFound.vue +18 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/router-utils.ts +32 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/router.ts +40 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/styles/global.css +134 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/test/setup.ts +1 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/src/types/globals.d.ts +23 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/tsconfig.json +45 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/tsconfig.node.json +13 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/tsconfig.tsbuildinfo +1 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/ui-bundle.json +7 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/vite-env.d.ts +14 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/vite.config.ts +106 -0
- package/dist/force-app/main/default/uiBundles/feature-vue-language-switcher/vitest-env.d.ts +2 -0
- package/dist/jest.config.js +6 -0
- package/dist/package-lock.json +12554 -0
- package/dist/package.json +46 -0
- package/dist/scripts/apex/hello.apex +10 -0
- package/dist/scripts/gitignore-templates.json +4 -0
- package/dist/scripts/graphql-search.sh +191 -0
- package/dist/scripts/network-senders.mjs +84 -0
- package/dist/scripts/org-setup-config-schema.mjs +132 -0
- package/dist/scripts/org-setup-dev.mjs +114 -0
- package/dist/scripts/org-setup-url.mjs +108 -0
- package/dist/scripts/org-setup-utils.mjs +569 -0
- package/dist/scripts/org-setup-xml.mjs +283 -0
- package/dist/scripts/org-setup.config.json +5 -0
- package/dist/scripts/org-setup.mjs +2545 -0
- package/dist/scripts/sf-project-setup.mjs +103 -0
- package/dist/scripts/soql/account.soql +6 -0
- package/dist/scripts/validate-org-setup-config.mjs +38 -0
- package/dist/sfdx-project.json +12 -0
- package/package.json +51 -4
- package/src/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/LanguageSwitcher.vue +75 -0
- package/src/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/__examples__/language-switcher-example.vue +34 -0
- package/src/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/__examples__/vite-config-site-example.ts +44 -0
- package/src/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/buildLanguageUrl.ts +158 -0
- package/src/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/getCurrentLanguage.ts +59 -0
- package/src/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/index.ts +31 -0
- package/src/force-app/main/default/uiBundles/feature-vue-language-switcher/src/features/language-switcher/languages.ts +46 -0
- package/src/force-app/main/default/uiBundles/feature-vue-language-switcher/src/index.ts +8 -0
- package/src/force-app/main/default/uiBundles/feature-vue-language-switcher/src/types/globals.d.ts +23 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { SelectTriggerProps } from 'reka-ui';
|
|
3
|
+
import type { HTMLAttributes } from 'vue';
|
|
4
|
+
import { computed } from 'vue';
|
|
5
|
+
import { ChevronDownIcon } from '@lucide/vue';
|
|
6
|
+
import { SelectIcon, SelectTrigger, useForwardProps } from 'reka-ui';
|
|
7
|
+
import { cn } from '@/lib/utils';
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(
|
|
10
|
+
defineProps<
|
|
11
|
+
SelectTriggerProps & {
|
|
12
|
+
class?: HTMLAttributes['class'];
|
|
13
|
+
size?: 'sm' | 'default';
|
|
14
|
+
}
|
|
15
|
+
>(),
|
|
16
|
+
{ size: 'default' }
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const delegatedProps = computed(() => {
|
|
20
|
+
const { class: _class, size: _size, ...rest } = props;
|
|
21
|
+
return rest;
|
|
22
|
+
});
|
|
23
|
+
const forwardedProps = useForwardProps(delegatedProps);
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
<template>
|
|
27
|
+
<SelectTrigger
|
|
28
|
+
data-slot="select-trigger"
|
|
29
|
+
:data-size="size"
|
|
30
|
+
v-bind="forwardedProps"
|
|
31
|
+
:class="
|
|
32
|
+
cn(
|
|
33
|
+
`border-input data-placeholder:text-muted-foreground dark:bg-input/30 dark:hover:bg-input/50 focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:aria-invalid:border-destructive/50 gap-1.5 rounded-lg border bg-transparent py-2 pr-2 pl-2.5 text-sm transition-colors select-none focus-visible:ring-3 aria-invalid:ring-3 data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:gap-1.5 [&_svg:not([class*='size-'])]:size-4 flex w-fit items-center justify-between whitespace-nowrap outline-none disabled:cursor-not-allowed disabled:opacity-50 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center [&_svg]:pointer-events-none [&_svg]:shrink-0`,
|
|
34
|
+
props.class
|
|
35
|
+
)
|
|
36
|
+
"
|
|
37
|
+
>
|
|
38
|
+
<slot />
|
|
39
|
+
<SelectIcon as-child>
|
|
40
|
+
<ChevronDownIcon
|
|
41
|
+
class="text-muted-foreground size-4 pointer-events-none"
|
|
42
|
+
/>
|
|
43
|
+
</SelectIcon>
|
|
44
|
+
</SelectTrigger>
|
|
45
|
+
</template>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { SelectValueProps } from 'reka-ui';
|
|
3
|
+
import { SelectValue } from 'reka-ui';
|
|
4
|
+
|
|
5
|
+
const props = defineProps<SelectValueProps>();
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
<template>
|
|
9
|
+
<SelectValue data-slot="select-value" v-bind="props">
|
|
10
|
+
<slot />
|
|
11
|
+
</SelectValue>
|
|
12
|
+
</template>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as Select } from './Select.vue';
|
|
2
|
+
export { default as SelectContent } from './SelectContent.vue';
|
|
3
|
+
export { default as SelectGroup } from './SelectGroup.vue';
|
|
4
|
+
export { default as SelectItem } from './SelectItem.vue';
|
|
5
|
+
export { default as SelectLabel } from './SelectLabel.vue';
|
|
6
|
+
export { default as SelectScrollDownButton } from './SelectScrollDownButton.vue';
|
|
7
|
+
export { default as SelectScrollUpButton } from './SelectScrollUpButton.vue';
|
|
8
|
+
export { default as SelectSeparator } from './SelectSeparator.vue';
|
|
9
|
+
export { default as SelectTrigger } from './SelectTrigger.vue';
|
|
10
|
+
export { default as SelectValue } from './SelectValue.vue';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { SeparatorProps } from 'reka-ui';
|
|
3
|
+
import type { HTMLAttributes } from 'vue';
|
|
4
|
+
import { computed } from 'vue';
|
|
5
|
+
import { Separator } from 'reka-ui';
|
|
6
|
+
import { cn } from '@/lib/utils';
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(
|
|
9
|
+
defineProps<SeparatorProps & { class?: HTMLAttributes['class'] }>(),
|
|
10
|
+
{
|
|
11
|
+
orientation: 'horizontal',
|
|
12
|
+
decorative: true,
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
const delegatedProps = computed(() => {
|
|
17
|
+
const { class: _class, ...rest } = props;
|
|
18
|
+
return rest;
|
|
19
|
+
});
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<Separator
|
|
24
|
+
data-slot="separator"
|
|
25
|
+
v-bind="delegatedProps"
|
|
26
|
+
:class="
|
|
27
|
+
cn(
|
|
28
|
+
'bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px',
|
|
29
|
+
props.class
|
|
30
|
+
)
|
|
31
|
+
"
|
|
32
|
+
/>
|
|
33
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Separator } from './Separator.vue';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'vue';
|
|
3
|
+
import { cn } from '@/lib/utils';
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{
|
|
6
|
+
class?: HTMLAttributes['class'];
|
|
7
|
+
}>();
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<div
|
|
12
|
+
data-slot="skeleton"
|
|
13
|
+
:class="cn('bg-accent animate-pulse rounded-md', props.class)"
|
|
14
|
+
/>
|
|
15
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Skeleton } from './Skeleton.vue';
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { Toaster as Sonner } from 'vue-sonner';
|
|
3
|
+
import type { ToasterProps } from 'vue-sonner';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Renders the toast container. Use with `toast()` from `vue-sonner` for
|
|
7
|
+
* messages with title, description, actions, and variants (success, error,
|
|
8
|
+
* warning).
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { toast } from 'vue-sonner';
|
|
12
|
+
* toast('Event has been created', {
|
|
13
|
+
* description: 'Sunday, December 03, 2023 at 9:00 AM',
|
|
14
|
+
* action: { label: 'Undo', onClick: () => {} },
|
|
15
|
+
* });
|
|
16
|
+
* toast.success('Saved!');
|
|
17
|
+
* toast.error('Something went wrong');
|
|
18
|
+
* toast.warning('Please review');
|
|
19
|
+
*/
|
|
20
|
+
// Defaults for position/richColors; callers can still override via props.
|
|
21
|
+
const props = withDefaults(defineProps<ToasterProps>(), {
|
|
22
|
+
position: 'top-right',
|
|
23
|
+
richColors: true,
|
|
24
|
+
});
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<Sonner v-bind="props" />
|
|
29
|
+
</template>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import type { HTMLAttributes } from 'vue';
|
|
3
|
+
import { Loader2Icon } from '@lucide/vue';
|
|
4
|
+
import { cn } from '@/lib/utils';
|
|
5
|
+
|
|
6
|
+
const props = defineProps<{
|
|
7
|
+
class?: HTMLAttributes['class'];
|
|
8
|
+
}>();
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<template>
|
|
12
|
+
<Loader2Icon
|
|
13
|
+
role="status"
|
|
14
|
+
aria-label="Loading"
|
|
15
|
+
:class="cn('size-4 animate-spin', props.class)"
|
|
16
|
+
/>
|
|
17
|
+
</template>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Spinner } from './Spinner.vue';
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Ref, WatchSource } from 'vue';
|
|
2
|
+
import { ref, shallowRef, watch } from 'vue';
|
|
3
|
+
|
|
4
|
+
/** Reactive async-data snapshot: current data, loading, and error. */
|
|
5
|
+
export interface AsyncData<T> {
|
|
6
|
+
/** Latest successful result. Kept visible during a refetch. */
|
|
7
|
+
data: Ref<T | null>;
|
|
8
|
+
/** True while a fetch for the current args is in flight. */
|
|
9
|
+
loading: Ref<boolean>;
|
|
10
|
+
/** Error message from the most recent failed fetch, else null. */
|
|
11
|
+
error: Ref<string | null>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Runs an async `fetcher` immediately and again whenever `source` changes,
|
|
16
|
+
* exposing the result as reactive refs. Stale responses (the source changed
|
|
17
|
+
* during a fetch, or the component unmounted) are dropped via a generation
|
|
18
|
+
* counter, so only the latest in-flight request can write state.
|
|
19
|
+
*
|
|
20
|
+
* The Vue analogue of the React `useAsyncData` hook and the Angular
|
|
21
|
+
* `createAsyncData` helper: the state shape (`data` / `loading` / `error`) is
|
|
22
|
+
* identical so pages port across frameworks unchanged.
|
|
23
|
+
*
|
|
24
|
+
* @typeParam TArgs - The reactive arguments passed to the fetcher.
|
|
25
|
+
* @typeParam T - The fetched result type.
|
|
26
|
+
* @param source - Reactive source (ref, getter, or array of them) whose value
|
|
27
|
+
* is forwarded to `fetcher`. Re-runs on change.
|
|
28
|
+
* @param fetcher - Async function producing the data for the current args.
|
|
29
|
+
* @returns Reactive `{ data, loading, error }` refs.
|
|
30
|
+
*/
|
|
31
|
+
export function useAsyncData<TArgs, T>(
|
|
32
|
+
source: WatchSource<TArgs>,
|
|
33
|
+
fetcher: (args: TArgs) => Promise<T>
|
|
34
|
+
): AsyncData<T> {
|
|
35
|
+
const data = shallowRef<T | null>(null);
|
|
36
|
+
const loading = ref<boolean>(true);
|
|
37
|
+
const error = ref<string | null>(null);
|
|
38
|
+
|
|
39
|
+
let generation = 0;
|
|
40
|
+
|
|
41
|
+
const run = (args: TArgs): void => {
|
|
42
|
+
const current = ++generation;
|
|
43
|
+
loading.value = true;
|
|
44
|
+
error.value = null;
|
|
45
|
+
|
|
46
|
+
fetcher(args)
|
|
47
|
+
.then(result => {
|
|
48
|
+
if (current === generation) {
|
|
49
|
+
data.value = result;
|
|
50
|
+
}
|
|
51
|
+
})
|
|
52
|
+
.catch((err: unknown) => {
|
|
53
|
+
console.error(err);
|
|
54
|
+
if (current === generation) {
|
|
55
|
+
error.value =
|
|
56
|
+
err instanceof Error ? err.message : 'An error occurred';
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
.finally(() => {
|
|
60
|
+
if (current === generation) {
|
|
61
|
+
loading.value = false;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
watch(source, args => run(args), { immediate: true, deep: true });
|
|
67
|
+
|
|
68
|
+
return { data, loading, error };
|
|
69
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* For full license text, see the LICENSE.txt file
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Drop-in language switcher for B2X (Experience) apps.
|
|
10
|
+
*
|
|
11
|
+
* Renders a labeled `<select>` of the site's supported {@link LANGUAGES}.
|
|
12
|
+
* Choosing a language rewrites the current URL so the chosen code becomes the
|
|
13
|
+
* first path segment after `basePath` (see {@link buildLanguageUrl}) and reloads
|
|
14
|
+
* the page via `window.location.assign`. A full reload lets the platform serve
|
|
15
|
+
* the correctly localized content — this component owns only the URL rewrite.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { computed } from "vue";
|
|
19
|
+
import { buildLanguageUrl } from "./buildLanguageUrl";
|
|
20
|
+
import { getBasePath, getCurrentLanguage } from "./getCurrentLanguage";
|
|
21
|
+
import { DEFAULT_LANGUAGE, LANGUAGE_CODES, LANGUAGES } from "./languages";
|
|
22
|
+
|
|
23
|
+
const props = withDefaults(
|
|
24
|
+
defineProps<{
|
|
25
|
+
/** Accessible label for the control. Defaults to "Language". */
|
|
26
|
+
label?: string;
|
|
27
|
+
/** Extra classes merged onto the `<select>`. */
|
|
28
|
+
className?: string;
|
|
29
|
+
}>(),
|
|
30
|
+
{ label: "Language" },
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
// Render nothing when there is no real choice to make. A single-option dropdown
|
|
34
|
+
// is an inert control: it can't change anything, yet it still takes a focus stop
|
|
35
|
+
// and is announced as a "1 of 1" menu, implying options that don't exist.
|
|
36
|
+
// Omitting it entirely keeps the accessibility tree honest.
|
|
37
|
+
const hasChoice = computed(() => LANGUAGES.length >= 2);
|
|
38
|
+
|
|
39
|
+
const current = getCurrentLanguage();
|
|
40
|
+
|
|
41
|
+
const selectClass = computed(
|
|
42
|
+
() =>
|
|
43
|
+
props.className ??
|
|
44
|
+
"rounded-md border border-border bg-card px-3 py-1.5 text-sm text-foreground",
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
function handleChange(event: Event) {
|
|
48
|
+
const next = (event.target as HTMLSelectElement).value;
|
|
49
|
+
// No-op when the selection already matches the active language.
|
|
50
|
+
if (next === current) return;
|
|
51
|
+
|
|
52
|
+
const nextUrl = buildLanguageUrl(
|
|
53
|
+
window.location.href,
|
|
54
|
+
getBasePath(),
|
|
55
|
+
next,
|
|
56
|
+
LANGUAGE_CODES,
|
|
57
|
+
DEFAULT_LANGUAGE,
|
|
58
|
+
);
|
|
59
|
+
window.location.assign(nextUrl);
|
|
60
|
+
}
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<template>
|
|
64
|
+
<select
|
|
65
|
+
v-if="hasChoice"
|
|
66
|
+
:aria-label="label"
|
|
67
|
+
:value="current"
|
|
68
|
+
:class="selectClass"
|
|
69
|
+
@change="handleChange"
|
|
70
|
+
>
|
|
71
|
+
<option v-for="language in LANGUAGES" :key="language.code" :value="language.code">
|
|
72
|
+
{{ language.label }}
|
|
73
|
+
</option>
|
|
74
|
+
</select>
|
|
75
|
+
</template>
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
* For full license text, see the LICENSE.txt file
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Example: mounting <LanguageSwitcher /> in an app layout/header.
|
|
10
|
+
*
|
|
11
|
+
* This file is illustrative — it is copied into the app as an example, not wired
|
|
12
|
+
* into routing. To adopt the switcher, render <LanguageSwitcher /> wherever your
|
|
13
|
+
* app's chrome lives (typically the nav/header in `appLayout.vue`). It manages
|
|
14
|
+
* its own state from the URL + SFDC_ENV, so no props are required.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { RouterView } from "vue-router";
|
|
18
|
+
import { LanguageSwitcher } from "../index";
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<nav class="bg-white border-b border-gray-200">
|
|
23
|
+
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
|
24
|
+
<div class="flex justify-between items-center h-16">
|
|
25
|
+
<span class="text-xl font-semibold text-gray-900">Vue App</span>
|
|
26
|
+
<div class="flex items-center gap-2">
|
|
27
|
+
<!-- Drop the switcher anywhere in your header/chrome. -->
|
|
28
|
+
<LanguageSwitcher />
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
</nav>
|
|
33
|
+
<RouterView />
|
|
34
|
+
</template>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Example: switching your app's `vite.config.ts` to the SITE entry of
|
|
9
|
+
* `@salesforce/vite-plugin-ui-bundle` so language switching works in local dev.
|
|
10
|
+
*
|
|
11
|
+
* This file is illustrative — it is copied into the app as an example, not used
|
|
12
|
+
* directly. Apply the two changes below to your real `vite.config.ts`.
|
|
13
|
+
*
|
|
14
|
+
* WHY: On a deployed Experience site the platform injects `SFDC_ENV.language`
|
|
15
|
+
* and folds the active language into `SFDC_ENV.basePath` (e.g. `/shop/fr`),
|
|
16
|
+
* recomputed from the URL on every load. The generic local Vite dev server does
|
|
17
|
+
* neither — `SFDC_ENV.language` is absent and `basePath` is always `/` — so the
|
|
18
|
+
* switcher can't route a non-default language locally (the reload 404s and the
|
|
19
|
+
* labels never flip). The SITE entry mirrors production for local dev only.
|
|
20
|
+
*
|
|
21
|
+
* HOW: change the import from the generic plugin to the `/site` subpath, and
|
|
22
|
+
* pass the feature's supported `LANGUAGES` (the single source of truth). The
|
|
23
|
+
* plugin needs the language CODES, so map the `{ code, label }` list to codes.
|
|
24
|
+
* The FIRST entry is the default, served un-prefixed at `/` — matching
|
|
25
|
+
* `DEFAULT_LANGUAGE` in `languages.ts`.
|
|
26
|
+
*
|
|
27
|
+
* This has NO effect on a deployed build; non-site bundles keep the generic
|
|
28
|
+
* `@salesforce/vite-plugin-ui-bundle` import unchanged.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
// 1. Replace the generic plugin import:
|
|
32
|
+
// import salesforce from "@salesforce/vite-plugin-ui-bundle";
|
|
33
|
+
// with the site entry + the feature's language list:
|
|
34
|
+
import siteUiBundlePlugin from "@salesforce/vite-plugin-ui-bundle/site";
|
|
35
|
+
import { LANGUAGES } from "../languages";
|
|
36
|
+
|
|
37
|
+
// 2. In your `defineConfig({ plugins: [...] })`, replace the `salesforce()`
|
|
38
|
+
// call with `siteUiBundlePlugin(...)`, passing the language codes:
|
|
39
|
+
export const examplePlugins = [
|
|
40
|
+
// tailwindcss(),
|
|
41
|
+
// vue(),
|
|
42
|
+
siteUiBundlePlugin({ languages: LANGUAGES.map((l) => l.code) }),
|
|
43
|
+
// ...codegen
|
|
44
|
+
];
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Strip leading and trailing slashes from a path fragment. */
|
|
8
|
+
function trimSlashes(value: string): string {
|
|
9
|
+
return value.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Convert a Salesforce locale code to the form used in the URL path.
|
|
14
|
+
*
|
|
15
|
+
* Locale codes use underscores (e.g. `en_US`), but URL path segments use hyphens
|
|
16
|
+
* (e.g. `en-US`). This maps a code to its URL segment.
|
|
17
|
+
*/
|
|
18
|
+
function codeToUrlSegment(code: string): string {
|
|
19
|
+
return code.replace(/_/g, "-");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Convert a hyphenated language token back to a Salesforce locale code — the
|
|
24
|
+
* inverse of {@link codeToUrlSegment} (e.g. `en-US` → `en_US`). Locale codes
|
|
25
|
+
* never contain hyphens, so this remapping is unambiguous. Used both for URL
|
|
26
|
+
* path segments and for the hyphenated `SFDC_ENV.language` value the platform
|
|
27
|
+
* injects (e.g. `"en-US"`), which share the same hyphen convention.
|
|
28
|
+
*/
|
|
29
|
+
export function urlSegmentToCode(segment: string): string {
|
|
30
|
+
return segment.replace(/-/g, "_");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Recover the true, language-free site root from `basePath`.
|
|
35
|
+
*
|
|
36
|
+
* When a non-default language is active, the platform folds the language segment
|
|
37
|
+
* into `SFDC_ENV.basePath` itself — `/shop` becomes `/shop/fr` — rather than
|
|
38
|
+
* leaving `basePath` as the stable site root with the language living in the path
|
|
39
|
+
* after it. If we took `basePath` at face value, the language segment would be
|
|
40
|
+
* treated as part of the base and never seen as a leading language segment, so
|
|
41
|
+
* switching to the default (which should remove the segment) and switching
|
|
42
|
+
* between non-default languages (which should replace it) would both fail.
|
|
43
|
+
*
|
|
44
|
+
* Strip a single trailing segment when it is a known language (remapped from its
|
|
45
|
+
* URL form back to a locale code), yielding the language-free site root so the
|
|
46
|
+
* rest of this module can treat the leading path segment after it as the language.
|
|
47
|
+
*/
|
|
48
|
+
function normalizeBasePath(basePath: string, knownCodes: ReadonlySet<string>): string {
|
|
49
|
+
const segments = trimSlashes(basePath).split("/").filter(Boolean);
|
|
50
|
+
const last = segments[segments.length - 1];
|
|
51
|
+
if (last && knownCodes.has(urlSegmentToCode(last))) {
|
|
52
|
+
segments.pop();
|
|
53
|
+
}
|
|
54
|
+
return segments.join("/");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Return the path segments that live AFTER `basePath` in `pathname`.
|
|
59
|
+
* Both are compared with leading/trailing slashes normalized.
|
|
60
|
+
*/
|
|
61
|
+
function segmentsAfterBase(pathname: string, basePath: string): string[] {
|
|
62
|
+
const base = trimSlashes(basePath);
|
|
63
|
+
const trimmedPath = trimSlashes(pathname);
|
|
64
|
+
|
|
65
|
+
let rest = trimmedPath;
|
|
66
|
+
if (base && (trimmedPath === base || trimmedPath.startsWith(`${base}/`))) {
|
|
67
|
+
rest = trimmedPath.slice(base.length);
|
|
68
|
+
}
|
|
69
|
+
return trimSlashes(rest).split("/").filter(Boolean);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Read the language encoded in a URL: the first path segment after `basePath`,
|
|
74
|
+
* remapped from its URL form (hyphens) back to a locale code (underscores) and
|
|
75
|
+
* returned only when it is one of `knownCodes`. Returns `undefined` when the
|
|
76
|
+
* leading segment is absent or is not a known language code.
|
|
77
|
+
*
|
|
78
|
+
* @param currentUrl Absolute URL to inspect (e.g. `window.location.href`).
|
|
79
|
+
* @param basePath Site root path (e.g. `SFDC_ENV.basePath`); may be `""`.
|
|
80
|
+
* @param knownCodes Language codes considered valid leading segments.
|
|
81
|
+
* @returns The matched locale code (e.g. `en_US`), or `undefined`.
|
|
82
|
+
*/
|
|
83
|
+
export function getLanguageFromUrl(
|
|
84
|
+
currentUrl: string,
|
|
85
|
+
basePath: string,
|
|
86
|
+
knownCodes: ReadonlySet<string>,
|
|
87
|
+
): string | undefined {
|
|
88
|
+
const { pathname } = new URL(currentUrl);
|
|
89
|
+
const siteRoot = normalizeBasePath(basePath, knownCodes);
|
|
90
|
+
const [first] = segmentsAfterBase(pathname, siteRoot);
|
|
91
|
+
if (!first) {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const code = urlSegmentToCode(first);
|
|
95
|
+
return knownCodes.has(code) ? code : undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Rewrite `currentUrl` so `language` is reflected in the first path segment after
|
|
100
|
+
* `basePath`. The rest of the path, the query string, and the hash are preserved.
|
|
101
|
+
*
|
|
102
|
+
* The leading segment after `basePath` is examined and remapped from its URL form
|
|
103
|
+
* (hyphens) back to a locale code before being compared against `knownCodes`:
|
|
104
|
+
*
|
|
105
|
+
* - **Default language** (`language === defaultLanguage`): the default is the
|
|
106
|
+
* implicit, un-prefixed language, so NO segment is written. An existing
|
|
107
|
+
* known-language leading segment is REMOVED (`/shop/fr/page` → `/shop/page`);
|
|
108
|
+
* if there is none, the path is left unchanged.
|
|
109
|
+
* - **Non-default language**: an existing known-language leading segment is
|
|
110
|
+
* REPLACED — so switching never stacks segments (`/en-US/fr/page`) — otherwise
|
|
111
|
+
* the language is INSERTED as a new first segment. The written segment uses the
|
|
112
|
+
* URL form of the code (underscores → hyphens, e.g. `en_US` → `en-US`).
|
|
113
|
+
*
|
|
114
|
+
* When a non-default language is active the platform folds that language into
|
|
115
|
+
* `basePath` itself (`/shop` → `/shop/fr`); a trailing known-language segment is
|
|
116
|
+
* stripped from `basePath` first (see {@link normalizeBasePath}) so the leading
|
|
117
|
+
* segment after the true site root is always what gets replaced/removed/inserted.
|
|
118
|
+
*
|
|
119
|
+
* `basePath` is matched with trailing slashes normalized, and the result never
|
|
120
|
+
* contains double slashes.
|
|
121
|
+
*
|
|
122
|
+
* @param currentUrl Absolute URL to rewrite (e.g. `window.location.href`).
|
|
123
|
+
* @param basePath Site root path (e.g. `SFDC_ENV.basePath`); may be `""`.
|
|
124
|
+
* @param language Locale code to reflect after `basePath` (e.g. `en_US`).
|
|
125
|
+
* @param knownCodes Language codes eligible for the leading-segment check.
|
|
126
|
+
* @param defaultLanguage Locale code that is served without a URL segment.
|
|
127
|
+
* @returns The rewritten absolute URL as a string.
|
|
128
|
+
*/
|
|
129
|
+
export function buildLanguageUrl(
|
|
130
|
+
currentUrl: string,
|
|
131
|
+
basePath: string,
|
|
132
|
+
language: string,
|
|
133
|
+
knownCodes: ReadonlySet<string>,
|
|
134
|
+
defaultLanguage: string,
|
|
135
|
+
): string {
|
|
136
|
+
const url = new URL(currentUrl);
|
|
137
|
+
|
|
138
|
+
const base = normalizeBasePath(basePath, knownCodes);
|
|
139
|
+
const segments = segmentsAfterBase(url.pathname, base);
|
|
140
|
+
const leadingIsLanguage = segments.length > 0 && knownCodes.has(urlSegmentToCode(segments[0]));
|
|
141
|
+
|
|
142
|
+
if (language === defaultLanguage) {
|
|
143
|
+
// The default language is served un-prefixed. Drop an existing language
|
|
144
|
+
// segment so switching back to default removes it, rather than writing one.
|
|
145
|
+
if (leadingIsLanguage) {
|
|
146
|
+
segments.shift();
|
|
147
|
+
}
|
|
148
|
+
} else if (leadingIsLanguage) {
|
|
149
|
+
segments[0] = codeToUrlSegment(language);
|
|
150
|
+
} else {
|
|
151
|
+
segments.unshift(codeToUrlSegment(language));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const rebuiltPath = [base, ...segments].filter(Boolean).join("/");
|
|
155
|
+
url.pathname = `/${rebuiltPath}`;
|
|
156
|
+
|
|
157
|
+
return url.toString();
|
|
158
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { getLanguageFromUrl, urlSegmentToCode } from "./buildLanguageUrl";
|
|
8
|
+
import { DEFAULT_LANGUAGE, LANGUAGE_CODES } from "./languages";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The subset of `SFDC_ENV` the switcher reads. We type it structurally here
|
|
12
|
+
* (rather than relying on the ambient `SfdcEnv`) so the feature type-checks in
|
|
13
|
+
* isolation: its ambient augmentation intentionally declares only `language?`,
|
|
14
|
+
* while `basePath` is provided by the platform types once composed into an app.
|
|
15
|
+
*/
|
|
16
|
+
interface SfdcEnvSubset {
|
|
17
|
+
basePath?: string;
|
|
18
|
+
/** Page locale in hyphenated form, e.g. "en-US" (the platform's injected form). */
|
|
19
|
+
language?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Read `SFDC_ENV` off the global scope without assuming it exists. */
|
|
23
|
+
function getSfdcEnv(): SfdcEnvSubset | undefined {
|
|
24
|
+
return (globalThis as { SFDC_ENV?: SfdcEnvSubset }).SFDC_ENV;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Resolve the active language, in precedence order:
|
|
29
|
+
*
|
|
30
|
+
* 1. `SFDC_ENV.language` — authoritative when the platform provides it. The
|
|
31
|
+
* platform injects this in hyphenated form (e.g. `"en-US"`), so it is
|
|
32
|
+
* remapped back to a locale code (`en_US`) before matching, mirroring how the
|
|
33
|
+
* URL segment is handled.
|
|
34
|
+
* 2. The leading URL path segment after `basePath`, when it is a supported
|
|
35
|
+
* language code — reflects the page the user is actually viewing (e.g. a
|
|
36
|
+
* direct hit on `/shop/fr/catalog`) even before the runtime populates
|
|
37
|
+
* `SFDC_ENV.language`.
|
|
38
|
+
* 3. {@link DEFAULT_LANGUAGE}.
|
|
39
|
+
*
|
|
40
|
+
* Only codes in {@link LANGUAGES} are honored; anything else falls through.
|
|
41
|
+
*/
|
|
42
|
+
export function getCurrentLanguage(): string {
|
|
43
|
+
const envLanguage = getSfdcEnv()?.language;
|
|
44
|
+
if (envLanguage) {
|
|
45
|
+
const envCode = urlSegmentToCode(envLanguage);
|
|
46
|
+
if (LANGUAGE_CODES.has(envCode)) {
|
|
47
|
+
return envCode;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const basePath = getSfdcEnv()?.basePath ?? "";
|
|
52
|
+
const urlLanguage = getLanguageFromUrl(window.location.href, basePath, LANGUAGE_CODES);
|
|
53
|
+
return urlLanguage ?? DEFAULT_LANGUAGE;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Read the active `basePath` from `SFDC_ENV`, defaulting to `""`. */
|
|
57
|
+
export function getBasePath(): string {
|
|
58
|
+
return getSfdcEnv()?.basePath ?? "";
|
|
59
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2026, Salesforce, Inc.,
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
* For full license text, see the LICENSE.txt file
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Public API for the language switcher feature.
|
|
9
|
+
*
|
|
10
|
+
* Most apps only need:
|
|
11
|
+
* ```vue
|
|
12
|
+
* <script setup lang="ts">
|
|
13
|
+
* import { LanguageSwitcher } from "@/features/language-switcher";
|
|
14
|
+
* </script>
|
|
15
|
+
* <template><LanguageSwitcher /></template>
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* Lower-level pieces are exported for custom UIs and testing:
|
|
19
|
+
* - {@link getCurrentLanguage} to read the active language
|
|
20
|
+
* - {@link buildLanguageUrl} to compute the rewritten URL yourself
|
|
21
|
+
* - {@link LANGUAGES} / {@link DEFAULT_LANGUAGE} for the supported set
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
export { default as LanguageSwitcher } from "./LanguageSwitcher.vue";
|
|
25
|
+
|
|
26
|
+
export { getCurrentLanguage } from "./getCurrentLanguage";
|
|
27
|
+
|
|
28
|
+
export { buildLanguageUrl, getLanguageFromUrl } from "./buildLanguageUrl";
|
|
29
|
+
|
|
30
|
+
export { LANGUAGES, DEFAULT_LANGUAGE, LANGUAGE_CODES } from "./languages";
|
|
31
|
+
export type { LanguageOption } from "./languages";
|