@writedocs/generator 0.4.5 → 0.4.6
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
|
@@ -34,10 +34,23 @@ const askAiId = process.env.WRITEDOCS_ASK_AI_ID || config.integrations.askAi?.id
|
|
|
34
34
|
const askAiInitScript = askAiId
|
|
35
35
|
? `DocsBotAI.init(${JSON.stringify({ id: askAiId })});`
|
|
36
36
|
: null;
|
|
37
|
+
// O ClientRouter (BaseLayout.astro) troca o <body> inteiro a cada navegação,
|
|
38
|
+
// e o DocsBot monta o widget num #docsbotai-root que ele mesmo anexa ao
|
|
39
|
+
// <body> - então o widget ia embora junto com o body antigo. Rodar o init de
|
|
40
|
+
// novo não resolve: o router não reexecuta script inline de conteúdo
|
|
41
|
+
// idêntico, e o mount() do DocsBot recusa montar duas vezes sem unmount().
|
|
42
|
+
// Aqui o root vivo é marcado com o mesmo atributo de `transition:persist`
|
|
43
|
+
// que o Astro já sabe mover, e o documento novo ganha um slot com o mesmo
|
|
44
|
+
// nome - o swap do Astro leva o elemento inteiro (shadow root com os
|
|
45
|
+
// estilos, estado do React, chat aberto) para a página nova. Roda uma vez
|
|
46
|
+
// só pelo mesmo motivo acima, e o listener no `document` sobrevive às
|
|
47
|
+
// navegações.
|
|
48
|
+
const askAiPersistScript = `document.addEventListener("astro:before-swap",function(e){var r=document.getElementById("docsbotai-root");if(!r)return;r.setAttribute("data-astro-transition-persist","wd-ask-ai");var s=e.newDocument.createElement("div");s.setAttribute("data-astro-transition-persist","wd-ask-ai");e.newDocument.body.appendChild(s);});`;
|
|
37
49
|
---
|
|
38
50
|
{askAiId && (
|
|
39
51
|
<>
|
|
40
52
|
<script is:inline set:html={askAiLoaderScript} />
|
|
41
53
|
{askAiInitScript && <script is:inline set:html={askAiInitScript} />}
|
|
54
|
+
<script is:inline set:html={askAiPersistScript} />
|
|
42
55
|
</>
|
|
43
56
|
)}
|