@aglyn/plugins-crm 1.0.0-beta.149 → 1.0.0-beta.150
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aglyn/plugins-crm",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.150",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"homepage": "https://aglyn.com",
|
|
6
6
|
"repository": {
|
|
@@ -25,18 +25,18 @@
|
|
|
25
25
|
"./package.json": "./package.json"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@aglyn/aglyn": "1.0.0-beta.
|
|
29
|
-
"@aglyn/shared-data-enums": "1.0.0-beta.
|
|
30
|
-
"@aglyn/shared-data-mdi": "1.0.0-beta.
|
|
31
|
-
"@aglyn/shared-ui-email-campaigns": "1.0.0-beta.
|
|
32
|
-
"@aglyn/shared-ui-jsx": "1.0.0-beta.
|
|
33
|
-
"@aglyn/shared-ui-next": "1.0.0-beta.
|
|
34
|
-
"@aglyn/shared-ui-snackstack": "1.0.0-beta.
|
|
35
|
-
"@aglyn/shared-util-email": "1.0.0-beta.
|
|
36
|
-
"@aglyn/shared-util-http": "1.0.0-beta.
|
|
37
|
-
"@aglyn/tenant-data-admin": "1.0.0-beta.
|
|
38
|
-
"@aglyn/tenant-feature-instance": "1.0.0-beta.
|
|
39
|
-
"@aglyn/tenant-runtime": "1.0.0-beta.
|
|
28
|
+
"@aglyn/aglyn": "1.0.0-beta.150",
|
|
29
|
+
"@aglyn/shared-data-enums": "1.0.0-beta.150",
|
|
30
|
+
"@aglyn/shared-data-mdi": "1.0.0-beta.150",
|
|
31
|
+
"@aglyn/shared-ui-email-campaigns": "1.0.0-beta.150",
|
|
32
|
+
"@aglyn/shared-ui-jsx": "1.0.0-beta.150",
|
|
33
|
+
"@aglyn/shared-ui-next": "1.0.0-beta.150",
|
|
34
|
+
"@aglyn/shared-ui-snackstack": "1.0.0-beta.150",
|
|
35
|
+
"@aglyn/shared-util-email": "1.0.0-beta.150",
|
|
36
|
+
"@aglyn/shared-util-http": "1.0.0-beta.150",
|
|
37
|
+
"@aglyn/tenant-data-admin": "1.0.0-beta.150",
|
|
38
|
+
"@aglyn/tenant-feature-instance": "1.0.0-beta.150",
|
|
39
|
+
"@aglyn/tenant-runtime": "1.0.0-beta.150",
|
|
40
40
|
"@dnd-kit/core": "^6.3.1",
|
|
41
41
|
"@dnd-kit/utilities": "^3.2.2",
|
|
42
42
|
"@swc/helpers": "0.5.23",
|
|
@@ -47,7 +47,7 @@ function writeRememberedPick(orgId, hostId) {
|
|
|
47
47
|
* how a surface tells the two levels apart without a second prop.
|
|
48
48
|
*/ export function CrmOrgMountProvider(props) {
|
|
49
49
|
const { mount, children } = props;
|
|
50
|
-
const { orgId, hosts, hostsReady, hostsPath } = mount;
|
|
50
|
+
const { orgId, orgSlug, hosts, hostsReady, hostsPath } = mount;
|
|
51
51
|
const [picked, setPicked] = useState(null);
|
|
52
52
|
// Read after mount rather than in the initializer, so the server and the
|
|
53
53
|
// first client paint agree: the pick only ever affects a drawer somebody
|
|
@@ -109,6 +109,7 @@ function writeRememberedPick(orgId, hostId) {
|
|
|
109
109
|
]);
|
|
110
110
|
const value = useMemo(()=>({
|
|
111
111
|
orgId,
|
|
112
|
+
orgSlug,
|
|
112
113
|
hosts,
|
|
113
114
|
hostsReady,
|
|
114
115
|
hostsPath,
|
|
@@ -119,6 +120,7 @@ function writeRememberedPick(orgId, hostId) {
|
|
|
119
120
|
siteHubHref
|
|
120
121
|
}), [
|
|
121
122
|
orgId,
|
|
123
|
+
orgSlug,
|
|
122
124
|
hosts,
|
|
123
125
|
hostsReady,
|
|
124
126
|
hostsPath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/hooks/use-crm-org-mount.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport type { ConsolePluginOrgHost, ConsolePluginOrgMount } from '@aglyn/aglyn'\nimport {\n type ComponentType,\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'react'\n\n/**\n * The organization-level mount, as every CRM surface beneath the hub reads\n * it (AGL-2630).\n *\n * The shell hands the hub page an org and its sites; the hub publishes them\n * through this context so a drawer four components down — the one that has\n * to ask which site a new record is captured by — reaches them without four\n * components threading a prop they never read. `useCrmScope` reads it too:\n * a surface handed `hostId: null` learns from here which org it is under,\n * which is what lets every existing `useCrmScope({ hostId, org })` call\n * serve the org level unchanged.\n */\nexport interface CrmOrgMount extends ConsolePluginOrgMount {\n /**\n * The site the next create stamps from: the reader's last pick this\n * session, or the org's only site when it has exactly one, else `null`\n * until somebody picks. A record is always captured BY a site — its\n * `hostId`, its `visibleTo`, the consent group its profile lives on all\n * come from one — and at the org level nothing else can say which.\n */\n createHostId: string | null\n setCreateHostId: (hostId: string) => void\n /** How a site reads on screen — its name, or its id when the list cannot name it. */\n siteName: (hostId: string) => string\n /**\n * The subdomain a console URL under `/hosts/[host]` takes, or `null` for\n * a site the list did not answer for — named, never linked.\n */\n siteSubdomain: (hostId: string) => string | null\n /**\n * The site's own CRM hub — `${hostsPath}/${subdomain}/crm` — or `null`\n * for a site whose subdomain the list could not answer, which is named\n * and not linked.\n */\n siteHubHref: (hostId: string) => string | null\n}\n\nconst CrmOrgMountContext = createContext<CrmOrgMount | null>(null)\n\n/**\n * The session's memory of the picked site, per org. Session storage rather\n * than local: the pick is a working convenience for one sitting, and a\n * site remembered across weeks would stamp a record onto a site the reader\n * had forgotten choosing.\n */\nconst pickStorageKey = (orgId: string) => `aglyn.crm.createSite.${orgId}`\n\nfunction readRememberedPick(orgId: string): string | null {\n try {\n return window.sessionStorage.getItem(pickStorageKey(orgId))\n } catch {\n return null\n }\n}\n\nfunction writeRememberedPick(orgId: string, hostId: string): void {\n try {\n window.sessionStorage.setItem(pickStorageKey(orgId), hostId)\n } catch {\n // A browser that refuses storage still gets the pick for this page.\n }\n}\n\n/**\n * Publishes the org-level mount to every surface beneath it.\n *\n * Mounted by the hub page ONLY when the shell handed it an `orgMount`; under\n * a site there is no provider and `useCrmOrgMount` answers `null`, which is\n * how a surface tells the two levels apart without a second prop.\n */\nexport function CrmOrgMountProvider(props: {\n mount: ConsolePluginOrgMount\n children: ReactNode\n}) {\n const { mount, children } = props\n const { orgId, hosts, hostsReady, hostsPath } = mount\n const [picked, setPicked] = useState<string | null>(null)\n // Read after mount rather than in the initializer, so the server and the\n // first client paint agree: the pick only ever affects a drawer somebody\n // has since opened.\n useEffect(() => {\n setPicked(readRememberedPick(orgId))\n }, [orgId])\n\n const byId = useMemo(() => {\n const index = new Map<string, ConsolePluginOrgHost>()\n for (const host of hosts) index.set(host.id, host)\n return index\n }, [hosts])\n\n /*\n * A remembered site the list no longer carries is forgotten rather than\n * stamped — the reader may have lost the site, or the site may be gone.\n * An org with exactly one site needs no picker at all; nothing else is\n * picked silently, because a wrong guess files a person under a brand\n * that never met them.\n */\n const createHostId = useMemo(() => {\n if (picked && byId.has(picked)) return picked\n if (hostsReady && hosts.length === 1) return hosts[0].id\n return null\n }, [picked, byId, hostsReady, hosts])\n\n const setCreateHostId = useCallback(\n (hostId: string) => {\n setPicked(hostId)\n writeRememberedPick(orgId, hostId)\n },\n [orgId],\n )\n const siteName = useCallback(\n (hostId: string) => byId.get(hostId)?.name || hostId,\n [byId],\n )\n const siteSubdomain = useCallback(\n (hostId: string) => byId.get(hostId)?.subdomain ?? null,\n [byId],\n )\n const siteHubHref = useCallback(\n (hostId: string) => {\n const subdomain = byId.get(hostId)?.subdomain\n return subdomain ? `${hostsPath}/${encodeURIComponent(subdomain)}/crm` : null\n },\n [byId, hostsPath],\n )\n\n const value = useMemo<CrmOrgMount>(\n () => ({\n orgId,\n hosts,\n hostsReady,\n hostsPath,\n createHostId,\n setCreateHostId,\n siteName,\n siteSubdomain,\n siteHubHref,\n }),\n [\n orgId,\n hosts,\n hostsReady,\n hostsPath,\n createHostId,\n setCreateHostId,\n siteName,\n siteSubdomain,\n siteHubHref,\n ],\n )\n return (\n <CrmOrgMountContext.Provider value={value}>\n {children}\n </CrmOrgMountContext.Provider>\n )\n}\nCrmOrgMountProvider.displayName = 'CrmOrgMountProvider'\n\n/** The org-level mount, or `null` under a site. */\nexport function useCrmOrgMount(): CrmOrgMount | null {\n return useContext(CrmOrgMountContext)\n}\n\n/**\n * `Card` beneath the org-level mount the SHELL hands it as a prop (AGL-2636).\n *\n * The hub page mounts the provider itself, because the shell hands the hub\n * page an `orgMount` and the page owns everything under it. A widget on the\n * org's `orgDashboard` slot is dropped into a console page the CRM does not\n * own — the org's sites list — and the console never imports a plugin, so\n * the page cannot mount this plugin's provider around the slot. The slot\n * hands each widget the same `orgMount` instead, and this puts the provider\n * where the hub page puts it: around the surface, one level down. `Card`\n * then reads `useCrmOrgMount()` and `useCrmScope({ hostId: null })` exactly\n * as it does under the hub, and stays one component for both mounts.\n *\n * Handed no mount — a slot that names a site, or a shell older than the org\n * zone — the card renders as it is, and `useCrmOrgMount` answers `null` the\n * way it does under a site.\n */\nexport function withCrmOrgMount<P extends object>(\n Card: ComponentType<P>,\n): ComponentType<P & { orgMount?: ConsolePluginOrgMount }> {\n function CrmOrgMounted(props: P & { orgMount?: ConsolePluginOrgMount }) {\n const { orgMount, ...rest } = props\n const card = <Card {...(rest as P)} />\n return orgMount ? (\n <CrmOrgMountProvider mount={orgMount}>{card}</CrmOrgMountProvider>\n ) : (\n card\n )\n }\n CrmOrgMounted.displayName = `CrmOrgMounted(${\n Card.displayName ?? (Card as { name?: string }).name ?? 'Card'\n })`\n return CrmOrgMounted\n}\n\n/**\n * THE SITE A CREATE OPENED FROM A RECORD DEFAULTS TO (AGL-2630).\n *\n * A task, an activity or a deal filed from a contact's page belongs, nine\n * times in ten, with the site that captured the contact — not with the\n * site the reader last picked in a list's drawer. So a record page wraps\n * its cards in this, naming its record's own capturing site, and every\n * create under it defaults its Site picker there. A pick the reader makes\n * INSIDE such a create is held for that page alone; the session's pick,\n * which a create opened from a list keeps defaulting to, is untouched.\n *\n * Nothing under a site, nothing for a record no site has captured, and\n * nothing for a site the mount's list does not carry — the reader may not\n * have it: the children render as they are and the session's pick stands.\n */\nexport function CrmCreateSiteDefault(props: {\n hostId: string | null | undefined\n children: ReactNode\n}) {\n const { hostId, children } = props\n const mount = useContext(CrmOrgMountContext)\n const [picked, setPicked] = useState<string | null>(null)\n // Another record on the same page starts from its own site again.\n useEffect(() => {\n setPicked(null)\n }, [hostId])\n const value = useMemo<CrmOrgMount | null>(() => {\n if (!mount || !hostId) return mount\n if (!mount.hosts.some((host) => host.id === hostId)) return mount\n return {\n ...mount,\n createHostId: picked ?? hostId,\n setCreateHostId: setPicked,\n }\n }, [mount, hostId, picked])\n return (\n <CrmOrgMountContext.Provider value={value}>\n {children}\n </CrmOrgMountContext.Provider>\n )\n}\nCrmCreateSiteDefault.displayName = 'CrmCreateSiteDefault'\n\nexport default useCrmOrgMount\n"],"names":["createContext","useCallback","useContext","useEffect","useMemo","useState","CrmOrgMountContext","pickStorageKey","orgId","readRememberedPick","window","sessionStorage","getItem","writeRememberedPick","hostId","setItem","CrmOrgMountProvider","props","mount","children","hosts","hostsReady","hostsPath","picked","setPicked","byId","index","Map","host","set","id","createHostId","has","length","setCreateHostId","siteName","get","name","siteSubdomain","subdomain","siteHubHref","encodeURIComponent","value","Provider","displayName","useCrmOrgMount","withCrmOrgMount","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BE,OAAO+B;sBAAWE;aAEvCA;IAEJ;IACAH,cAAcJ,WAAW,GAAG,CAAC,cAAc,GACzCG,QAAAA,oBAAAA,KAAKH,WAAW,YAAhBG,oBAAoB,AAACA,KAA2BV,IAAI,YAApDU,OAAwD,OACzD,CAAC,CAAC;IACH,OAAOC;AACT;AAEA;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASI,qBAAqBnC,KAGpC;IACC,MAAM,EAAEH,MAAM,EAAEK,QAAQ,EAAE,GAAGF;IAC7B,MAAMC,QAAQhB,WAAWI;IACzB,MAAM,CAACiB,QAAQC,UAAU,GAAGnB,SAAwB;IACpD,kEAAkE;IAClEF,UAAU;QACRqB,UAAU;IACZ,GAAG;QAACV;KAAO;IACX,MAAM4B,QAAQtC,QAA4B;QACxC,IAAI,CAACc,SAAS,CAACJ,QAAQ,OAAOI;QAC9B,IAAI,CAACA,MAAME,KAAK,CAACiC,IAAI,CAAC,CAACzB,OAASA,KAAKE,EAAE,KAAKhB,SAAS,OAAOI;QAC5D,OAAO,aACFA;YACHa,YAAY,EAAER,iBAAAA,SAAUT;YACxBoB,iBAAiBV;;IAErB,GAAG;QAACN;QAAOJ;QAAQS;KAAO;IAC1B,qBACE,KAACjB,mBAAmBqC,QAAQ;QAACD,OAAOA;kBACjCvB;;AAGP;AACAiC,qBAAqBR,WAAW,GAAG;AAEnC,eAAeC,eAAc"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../libs/plugins/crm/src/lib/hooks/use-crm-org-mount.tsx"],"sourcesContent":["/**\n * @license\n * Copyright 2026 Aglyn LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n'use client'\n\nimport type { ConsolePluginOrgHost, ConsolePluginOrgMount } from '@aglyn/aglyn'\nimport {\n type ComponentType,\n createContext,\n type ReactNode,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'react'\n\n/**\n * The organization-level mount, as every CRM surface beneath the hub reads\n * it (AGL-2630).\n *\n * The shell hands the hub page an org and its sites; the hub publishes them\n * through this context so a drawer four components down — the one that has\n * to ask which site a new record is captured by — reaches them without four\n * components threading a prop they never read. `useCrmScope` reads it too:\n * a surface handed `hostId: null` learns from here which org it is under,\n * which is what lets every existing `useCrmScope({ hostId, org })` call\n * serve the org level unchanged.\n */\nexport interface CrmOrgMount extends ConsolePluginOrgMount {\n /**\n * The site the next create stamps from: the reader's last pick this\n * session, or the org's only site when it has exactly one, else `null`\n * until somebody picks. A record is always captured BY a site — its\n * `hostId`, its `visibleTo`, the consent group its profile lives on all\n * come from one — and at the org level nothing else can say which.\n */\n createHostId: string | null\n setCreateHostId: (hostId: string) => void\n /** How a site reads on screen — its name, or its id when the list cannot name it. */\n siteName: (hostId: string) => string\n /**\n * The subdomain a console URL under `/hosts/[host]` takes, or `null` for\n * a site the list did not answer for — named, never linked.\n */\n siteSubdomain: (hostId: string) => string | null\n /**\n * The site's own CRM hub — `${hostsPath}/${subdomain}/crm` — or `null`\n * for a site whose subdomain the list could not answer, which is named\n * and not linked.\n */\n siteHubHref: (hostId: string) => string | null\n}\n\nconst CrmOrgMountContext = createContext<CrmOrgMount | null>(null)\n\n/**\n * The session's memory of the picked site, per org. Session storage rather\n * than local: the pick is a working convenience for one sitting, and a\n * site remembered across weeks would stamp a record onto a site the reader\n * had forgotten choosing.\n */\nconst pickStorageKey = (orgId: string) => `aglyn.crm.createSite.${orgId}`\n\nfunction readRememberedPick(orgId: string): string | null {\n try {\n return window.sessionStorage.getItem(pickStorageKey(orgId))\n } catch {\n return null\n }\n}\n\nfunction writeRememberedPick(orgId: string, hostId: string): void {\n try {\n window.sessionStorage.setItem(pickStorageKey(orgId), hostId)\n } catch {\n // A browser that refuses storage still gets the pick for this page.\n }\n}\n\n/**\n * Publishes the org-level mount to every surface beneath it.\n *\n * Mounted by the hub page ONLY when the shell handed it an `orgMount`; under\n * a site there is no provider and `useCrmOrgMount` answers `null`, which is\n * how a surface tells the two levels apart without a second prop.\n */\nexport function CrmOrgMountProvider(props: {\n mount: ConsolePluginOrgMount\n children: ReactNode\n}) {\n const { mount, children } = props\n const { orgId, orgSlug, hosts, hostsReady, hostsPath } = mount\n const [picked, setPicked] = useState<string | null>(null)\n // Read after mount rather than in the initializer, so the server and the\n // first client paint agree: the pick only ever affects a drawer somebody\n // has since opened.\n useEffect(() => {\n setPicked(readRememberedPick(orgId))\n }, [orgId])\n\n const byId = useMemo(() => {\n const index = new Map<string, ConsolePluginOrgHost>()\n for (const host of hosts) index.set(host.id, host)\n return index\n }, [hosts])\n\n /*\n * A remembered site the list no longer carries is forgotten rather than\n * stamped — the reader may have lost the site, or the site may be gone.\n * An org with exactly one site needs no picker at all; nothing else is\n * picked silently, because a wrong guess files a person under a brand\n * that never met them.\n */\n const createHostId = useMemo(() => {\n if (picked && byId.has(picked)) return picked\n if (hostsReady && hosts.length === 1) return hosts[0].id\n return null\n }, [picked, byId, hostsReady, hosts])\n\n const setCreateHostId = useCallback(\n (hostId: string) => {\n setPicked(hostId)\n writeRememberedPick(orgId, hostId)\n },\n [orgId],\n )\n const siteName = useCallback(\n (hostId: string) => byId.get(hostId)?.name || hostId,\n [byId],\n )\n const siteSubdomain = useCallback(\n (hostId: string) => byId.get(hostId)?.subdomain ?? null,\n [byId],\n )\n const siteHubHref = useCallback(\n (hostId: string) => {\n const subdomain = byId.get(hostId)?.subdomain\n return subdomain ? `${hostsPath}/${encodeURIComponent(subdomain)}/crm` : null\n },\n [byId, hostsPath],\n )\n\n const value = useMemo<CrmOrgMount>(\n () => ({\n orgId,\n orgSlug,\n hosts,\n hostsReady,\n hostsPath,\n createHostId,\n setCreateHostId,\n siteName,\n siteSubdomain,\n siteHubHref,\n }),\n [\n orgId,\n orgSlug,\n hosts,\n hostsReady,\n hostsPath,\n createHostId,\n setCreateHostId,\n siteName,\n siteSubdomain,\n siteHubHref,\n ],\n )\n return (\n <CrmOrgMountContext.Provider value={value}>\n {children}\n </CrmOrgMountContext.Provider>\n )\n}\nCrmOrgMountProvider.displayName = 'CrmOrgMountProvider'\n\n/** The org-level mount, or `null` under a site. */\nexport function useCrmOrgMount(): CrmOrgMount | null {\n return useContext(CrmOrgMountContext)\n}\n\n/**\n * `Card` beneath the org-level mount the SHELL hands it as a prop (AGL-2636).\n *\n * The hub page mounts the provider itself, because the shell hands the hub\n * page an `orgMount` and the page owns everything under it. A widget on the\n * org's `orgDashboard` slot is dropped into a console page the CRM does not\n * own — the org's sites list — and the console never imports a plugin, so\n * the page cannot mount this plugin's provider around the slot. The slot\n * hands each widget the same `orgMount` instead, and this puts the provider\n * where the hub page puts it: around the surface, one level down. `Card`\n * then reads `useCrmOrgMount()` and `useCrmScope({ hostId: null })` exactly\n * as it does under the hub, and stays one component for both mounts.\n *\n * Handed no mount — a slot that names a site, or a shell older than the org\n * zone — the card renders as it is, and `useCrmOrgMount` answers `null` the\n * way it does under a site.\n */\nexport function withCrmOrgMount<P extends object>(\n Card: ComponentType<P>,\n): ComponentType<P & { orgMount?: ConsolePluginOrgMount }> {\n function CrmOrgMounted(props: P & { orgMount?: ConsolePluginOrgMount }) {\n const { orgMount, ...rest } = props\n const card = <Card {...(rest as P)} />\n return orgMount ? (\n <CrmOrgMountProvider mount={orgMount}>{card}</CrmOrgMountProvider>\n ) : (\n card\n )\n }\n CrmOrgMounted.displayName = `CrmOrgMounted(${\n Card.displayName ?? (Card as { name?: string }).name ?? 'Card'\n })`\n return CrmOrgMounted\n}\n\n/**\n * THE SITE A CREATE OPENED FROM A RECORD DEFAULTS TO (AGL-2630).\n *\n * A task, an activity or a deal filed from a contact's page belongs, nine\n * times in ten, with the site that captured the contact — not with the\n * site the reader last picked in a list's drawer. So a record page wraps\n * its cards in this, naming its record's own capturing site, and every\n * create under it defaults its Site picker there. A pick the reader makes\n * INSIDE such a create is held for that page alone; the session's pick,\n * which a create opened from a list keeps defaulting to, is untouched.\n *\n * Nothing under a site, nothing for a record no site has captured, and\n * nothing for a site the mount's list does not carry — the reader may not\n * have it: the children render as they are and the session's pick stands.\n */\nexport function CrmCreateSiteDefault(props: {\n hostId: string | null | undefined\n children: ReactNode\n}) {\n const { hostId, children } = props\n const mount = useContext(CrmOrgMountContext)\n const [picked, setPicked] = useState<string | null>(null)\n // Another record on the same page starts from its own site again.\n useEffect(() => {\n setPicked(null)\n }, [hostId])\n const value = useMemo<CrmOrgMount | null>(() => {\n if (!mount || !hostId) return mount\n if (!mount.hosts.some((host) => host.id === hostId)) return mount\n return {\n ...mount,\n createHostId: picked ?? hostId,\n setCreateHostId: setPicked,\n }\n }, [mount, hostId, picked])\n return (\n <CrmOrgMountContext.Provider value={value}>\n {children}\n </CrmOrgMountContext.Provider>\n )\n}\nCrmCreateSiteDefault.displayName = 'CrmCreateSiteDefault'\n\nexport default useCrmOrgMount\n"],"names":["createContext","useCallback","useContext","useEffect","useMemo","useState","CrmOrgMountContext","pickStorageKey","orgId","readRememberedPick","window","sessionStorage","getItem","writeRememberedPick","hostId","setItem","CrmOrgMountProvider","props","mount","children","orgSlug","hosts","hostsReady","hostsPath","picked","setPicked","byId","index","Map","host","set","id","createHostId","has","length","setCreateHostId","siteName","get","name","siteSubdomain","subdomain","siteHubHref","encodeURIComponent","value","Provider","displayName","useCrmOrgMount","withCrmOrgMount","Card","CrmOrgMounted","orgMount","rest","card","CrmCreateSiteDefault","some"],"mappings":"AAAA;;;;;;;;;;;;;;;CAeC,GACD;;;;AAGA,SAEEA,aAAa,EAEbC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,OAAO,EACPC,QAAQ,QACH,QAAO;AAuCd,MAAMC,mCAAqBN,cAAkC;AAE7D;;;;;CAKC,GACD,MAAMO,iBAAiB,CAACC,QAAkB,CA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