@vitrailweb/payload-plugin-home-nav 0.1.1 → 0.1.2
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/README.md +2 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,8 @@ Both are **server components** resolved against the admin language. The label
|
|
|
13
13
|
defaults to the plugin's bundled translations ("Home" / "Accueil") and can be
|
|
14
14
|
overridden with a plain string or a per-language record. A custom icon the
|
|
15
15
|
project already configured through `admin.components.graphics.Icon` is kept
|
|
16
|
-
and rendered next to the label
|
|
16
|
+
and rendered next to the label — the plugin re-registers it under
|
|
17
|
+
`admin.dependencies` so it stays in the import map.
|
|
17
18
|
|
|
18
19
|
## Usage
|
|
19
20
|
|
package/dist/index.js
CHANGED
|
@@ -18,6 +18,17 @@ var VWPayloadPluginHomeNav = (pluginOptions = {}) => (config) => {
|
|
|
18
18
|
if (pluginOptions.iconLabel !== false) {
|
|
19
19
|
if (!config.admin.components.graphics) config.admin.components.graphics = {};
|
|
20
20
|
const existingIcon = config.admin.components.graphics.Icon;
|
|
21
|
+
if (existingIcon) {
|
|
22
|
+
const pathAndExport = typeof existingIcon === "string" ? existingIcon : existingIcon.path;
|
|
23
|
+
let [path, exportName] = pathAndExport.includes("#") ? pathAndExport.split("#", 2) : [pathAndExport, "default"];
|
|
24
|
+
if (typeof existingIcon === "object" && existingIcon.exportName) {
|
|
25
|
+
exportName = existingIcon.exportName;
|
|
26
|
+
}
|
|
27
|
+
config.admin.dependencies = {
|
|
28
|
+
...config.admin.dependencies,
|
|
29
|
+
"home-nav-icon": { type: "component", path: `${path}#${exportName}` }
|
|
30
|
+
};
|
|
31
|
+
}
|
|
21
32
|
config.admin.components.graphics.Icon = {
|
|
22
33
|
path: COMPONENT_PATH,
|
|
23
34
|
exportName: "HomeNavIcon",
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/localized.ts","../src/index.ts"],"sourcesContent":["/**\n * A plain string, or a per-language record keyed by admin language code\n * (e.g. `{ en: 'Home', fr: 'Accueil' }`).\n */\nexport type LocalizedText = string | Record<string, string>\n\n/**\n * Resolves a `LocalizedText` for the current admin language: exact language\n * match first, then `en`, then the first value in the record.\n */\nexport const resolveLocalizedText = (\n text: LocalizedText | undefined,\n language: string,\n): string | undefined => {\n if (text === undefined || typeof text === 'string') {\n return text\n }\n\n return text[language] ?? text.en ?? Object.values(text)[0]\n}\n","import type { Config } from 'payload'\n\nimport type { LocalizedText } from './localized.js'\n\nexport { resolveLocalizedText } from './localized.js'\nexport type { LocalizedText } from './localized.js'\n\nexport type VWPayloadPluginHomeNavConfig = {\n /**\n * Where \"Home\" links to.\n * @default the admin dashboard (`routes.admin`)\n */\n href?: string\n /**\n * The label, plain or per-language. Default: \"Home\" / \"Accueil\" from the\n * plugin's bundled translations, resolved against the admin language.\n */\n label?: LocalizedText\n /**\n * Show the label next to the icon in the app header (the\n * `admin.components.graphics.Icon` slot). A custom icon configured before\n * the plugin runs is kept and rendered next to the label.\n * @default true\n */\n iconLabel?: boolean\n /**\n * Add a \"Home\" link at the top of the nav sidebar (prepended to\n * `admin.components.beforeNavLinks`, above the collection links).\n * @default true\n */\n navLink?: boolean\n /** Leaves the config untouched. */\n disabled?: boolean\n}\n\nconst COMPONENT_PATH = '@vitrailweb/payload-plugin-home-nav/rsc'\n\n/**\n * Makes the admin's way home obvious: a translated \"Home\" label next to the\n * icon in the app header (which already links to the dashboard), and a\n * matching \"Home\" link at the top of the collapsible nav sidebar. Both are\n * server components resolved against the admin language.\n */\nexport const VWPayloadPluginHomeNav =\n (pluginOptions: VWPayloadPluginHomeNavConfig = {}) =>\n (config: Config): Config => {\n if (pluginOptions.disabled) {\n return config\n }\n\n const { href, label } = pluginOptions\n\n if (!config.admin) config.admin = {}\n if (!config.admin.components) config.admin.components = {}\n\n if (pluginOptions.iconLabel !== false) {\n if (!config.admin.components.graphics) config.admin.components.graphics = {}\n\n // The slot is taken over, but a custom icon the project configured is\n // handed to the component and rendered next to the label.\n const existingIcon = config.admin.components.graphics.Icon\n config.admin.components.graphics.Icon = {\n path: COMPONENT_PATH,\n exportName: 'HomeNavIcon',\n // Server component — serverProps never reach the client, so they can\n // safely carry the existing icon's component config.\n serverProps: {\n icon: existingIcon,\n label,\n },\n }\n }\n\n if (pluginOptions.navLink !== false) {\n // Prepended so \"Home\" stays on top even when other plugins add links.\n config.admin.components.beforeNavLinks = [\n {\n path: COMPONENT_PATH,\n exportName: 'HomeNavLink',\n serverProps: {\n href,\n label,\n },\n },\n ...(config.admin.components.beforeNavLinks ?? []),\n ]\n }\n\n return config\n }\n"],"mappings":";AAUO,IAAM,uBAAuB,CAClC,MACA,aACuB;AACvB,MAAI,SAAS,UAAa,OAAO,SAAS,UAAU;AAClD,WAAO;AAAA,EACT;AAEA,SAAO,KAAK,QAAQ,KAAK,KAAK,MAAM,OAAO,OAAO,IAAI,EAAE,CAAC;AAC3D;;;ACgBA,IAAM,iBAAiB;AAQhB,IAAM,yBACX,CAAC,gBAA8C,CAAC,MAChD,CAAC,WAA2B;AAC1B,MAAI,cAAc,UAAU;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,MAAM,MAAM,IAAI;AAExB,MAAI,CAAC,OAAO,MAAO,QAAO,QAAQ,CAAC;AACnC,MAAI,CAAC,OAAO,MAAM,WAAY,QAAO,MAAM,aAAa,CAAC;AAEzD,MAAI,cAAc,cAAc,OAAO;AACrC,QAAI,CAAC,OAAO,MAAM,WAAW,SAAU,QAAO,MAAM,WAAW,WAAW,CAAC;AAI3E,UAAM,eAAe,OAAO,MAAM,WAAW,SAAS;
|
|
1
|
+
{"version":3,"sources":["../src/localized.ts","../src/index.ts"],"sourcesContent":["/**\n * A plain string, or a per-language record keyed by admin language code\n * (e.g. `{ en: 'Home', fr: 'Accueil' }`).\n */\nexport type LocalizedText = string | Record<string, string>\n\n/**\n * Resolves a `LocalizedText` for the current admin language: exact language\n * match first, then `en`, then the first value in the record.\n */\nexport const resolveLocalizedText = (\n text: LocalizedText | undefined,\n language: string,\n): string | undefined => {\n if (text === undefined || typeof text === 'string') {\n return text\n }\n\n return text[language] ?? text.en ?? Object.values(text)[0]\n}\n","import type { Config } from 'payload'\n\nimport type { LocalizedText } from './localized.js'\n\nexport { resolveLocalizedText } from './localized.js'\nexport type { LocalizedText } from './localized.js'\n\nexport type VWPayloadPluginHomeNavConfig = {\n /**\n * Where \"Home\" links to.\n * @default the admin dashboard (`routes.admin`)\n */\n href?: string\n /**\n * The label, plain or per-language. Default: \"Home\" / \"Accueil\" from the\n * plugin's bundled translations, resolved against the admin language.\n */\n label?: LocalizedText\n /**\n * Show the label next to the icon in the app header (the\n * `admin.components.graphics.Icon` slot). A custom icon configured before\n * the plugin runs is kept and rendered next to the label.\n * @default true\n */\n iconLabel?: boolean\n /**\n * Add a \"Home\" link at the top of the nav sidebar (prepended to\n * `admin.components.beforeNavLinks`, above the collection links).\n * @default true\n */\n navLink?: boolean\n /** Leaves the config untouched. */\n disabled?: boolean\n}\n\nconst COMPONENT_PATH = '@vitrailweb/payload-plugin-home-nav/rsc'\n\n/**\n * Makes the admin's way home obvious: a translated \"Home\" label next to the\n * icon in the app header (which already links to the dashboard), and a\n * matching \"Home\" link at the top of the collapsible nav sidebar. Both are\n * server components resolved against the admin language.\n */\nexport const VWPayloadPluginHomeNav =\n (pluginOptions: VWPayloadPluginHomeNavConfig = {}) =>\n (config: Config): Config => {\n if (pluginOptions.disabled) {\n return config\n }\n\n const { href, label } = pluginOptions\n\n if (!config.admin) config.admin = {}\n if (!config.admin.components) config.admin.components = {}\n\n if (pluginOptions.iconLabel !== false) {\n if (!config.admin.components.graphics) config.admin.components.graphics = {}\n\n // The slot is taken over, but a custom icon the project configured is\n // handed to the component and rendered next to the label.\n const existingIcon = config.admin.components.graphics.Icon\n\n if (existingIcon) {\n // `generate:importmap` only scans the known component slots (plus\n // `admin.dependencies`) — the previous icon now lives in serverProps,\n // invisible to the scanner, so register it as an explicit dependency.\n // The key must match the runtime lookup: `path#exportName`, with\n // `default` when no export name is given.\n const pathAndExport =\n typeof existingIcon === 'string' ? existingIcon : existingIcon.path\n let [path, exportName] = pathAndExport.includes('#')\n ? pathAndExport.split('#', 2)\n : [pathAndExport, 'default']\n if (typeof existingIcon === 'object' && existingIcon.exportName) {\n exportName = existingIcon.exportName\n }\n\n config.admin.dependencies = {\n ...config.admin.dependencies,\n 'home-nav-icon': { type: 'component', path: `${path}#${exportName}` },\n }\n }\n\n config.admin.components.graphics.Icon = {\n path: COMPONENT_PATH,\n exportName: 'HomeNavIcon',\n // Server component — serverProps never reach the client, so they can\n // safely carry the existing icon's component config.\n serverProps: {\n icon: existingIcon,\n label,\n },\n }\n }\n\n if (pluginOptions.navLink !== false) {\n // Prepended so \"Home\" stays on top even when other plugins add links.\n config.admin.components.beforeNavLinks = [\n {\n path: COMPONENT_PATH,\n exportName: 'HomeNavLink',\n serverProps: {\n href,\n label,\n },\n },\n ...(config.admin.components.beforeNavLinks ?? []),\n ]\n }\n\n return config\n }\n"],"mappings":";AAUO,IAAM,uBAAuB,CAClC,MACA,aACuB;AACvB,MAAI,SAAS,UAAa,OAAO,SAAS,UAAU;AAClD,WAAO;AAAA,EACT;AAEA,SAAO,KAAK,QAAQ,KAAK,KAAK,MAAM,OAAO,OAAO,IAAI,EAAE,CAAC;AAC3D;;;ACgBA,IAAM,iBAAiB;AAQhB,IAAM,yBACX,CAAC,gBAA8C,CAAC,MAChD,CAAC,WAA2B;AAC1B,MAAI,cAAc,UAAU;AAC1B,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,MAAM,MAAM,IAAI;AAExB,MAAI,CAAC,OAAO,MAAO,QAAO,QAAQ,CAAC;AACnC,MAAI,CAAC,OAAO,MAAM,WAAY,QAAO,MAAM,aAAa,CAAC;AAEzD,MAAI,cAAc,cAAc,OAAO;AACrC,QAAI,CAAC,OAAO,MAAM,WAAW,SAAU,QAAO,MAAM,WAAW,WAAW,CAAC;AAI3E,UAAM,eAAe,OAAO,MAAM,WAAW,SAAS;AAEtD,QAAI,cAAc;AAMhB,YAAM,gBACJ,OAAO,iBAAiB,WAAW,eAAe,aAAa;AACjE,UAAI,CAAC,MAAM,UAAU,IAAI,cAAc,SAAS,GAAG,IAC/C,cAAc,MAAM,KAAK,CAAC,IAC1B,CAAC,eAAe,SAAS;AAC7B,UAAI,OAAO,iBAAiB,YAAY,aAAa,YAAY;AAC/D,qBAAa,aAAa;AAAA,MAC5B;AAEA,aAAO,MAAM,eAAe;AAAA,QAC1B,GAAG,OAAO,MAAM;AAAA,QAChB,iBAAiB,EAAE,MAAM,aAAa,MAAM,GAAG,IAAI,IAAI,UAAU,GAAG;AAAA,MACtE;AAAA,IACF;AAEA,WAAO,MAAM,WAAW,SAAS,OAAO;AAAA,MACtC,MAAM;AAAA,MACN,YAAY;AAAA;AAAA;AAAA,MAGZ,aAAa;AAAA,QACX,MAAM;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,MAAI,cAAc,YAAY,OAAO;AAEnC,WAAO,MAAM,WAAW,iBAAiB;AAAA,MACvC;AAAA,QACE,MAAM;AAAA,QACN,YAAY;AAAA,QACZ,aAAa;AAAA,UACX;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA,GAAI,OAAO,MAAM,WAAW,kBAAkB,CAAC;AAAA,IACjD;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitrailweb/payload-plugin-home-nav",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Payload plugin that labels the admin navbar icon with a translated “Home” and adds a Home link at the top of the nav sidebar",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": {
|