@simmalugnt-se/payload-editor-assistant 0.11.1 → 0.11.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.11.3
4
+
5
+ - Clicking "Fix N with the assistant" again after closing the panel opens it on the batch that is
6
+ still there. The link was remembered as taken and did nothing.
7
+
8
+ ## 0.11.2
9
+
10
+ - Translating a page whose text is all inside blocks or rows now works. The assistant left the
11
+ source language out of its context when it compared it with nothing, so it answered that there
12
+ was no English text to translate from. It now compares with the open form.
13
+ - A batch link from the work list starts again after Cancel. It was remembered as taken for the
14
+ whole session, so the second click did nothing until the page was reloaded.
15
+
3
16
  ## 0.11.1
4
17
 
5
18
  - The batch panel shows Start and Cancel right under the text that explains the batch, instead of
@@ -8,6 +8,7 @@ import { parseAdminView } from "../view.js";
8
8
  import { assistantRequest, assistantStream } from "./assistant-api.js";
9
9
  import { useAssistantState, } from "./assistant-context.js";
10
10
  import { BatchPanel } from "./BatchPanel.js";
11
+ import { releaseTakenBatches } from "./batch-link.js";
11
12
  import { COPY, translateAction, uiLanguage } from "./copy.js";
12
13
  import { isFormProposal, proposalSteps, refineProposal, replaceLatestStep, } from "./proposal-chain.js";
13
14
  import { ReplyText } from "./ReplyText.js";
@@ -443,7 +444,10 @@ export function EditorAssistantAside() {
443
444
  if (!open) {
444
445
  return null;
445
446
  }
446
- return (_jsxs("aside", { className: "ea-aside", "aria-label": copy.assistant, [KEEP_SELECTION_ATTR]: "", children: [_jsxs("div", { className: "ea-aside__head", children: [_jsxs("div", { className: "ea-aside__title", children: [_jsx("h2", { children: copy.assistant }), bridge ? _jsx("p", { className: "ea-aside__context", children: contextLine(bridge, config) }) : null] }), !batch && (messages.length > 0 || pendingApproval) && !pendingApproval?.applied ? (_jsx(Button, { buttonStyle: "subtle", margin: false, onClick: () => resetConversation(), size: "medium", children: copy.newChat })) : null, _jsx(Button, { "aria-label": copy.collapseLabel, buttonStyle: "icon-label", className: "ea-aside__collapse", icon: _jsx(ChevronIcon, { direction: "right" }), margin: false, onClick: () => setOpen(false), tooltip: copy.collapse })] }), batch ? (_jsx("div", { className: "ea-aside__body", children: _jsx(BatchPanel, { batch: batch, onClose: () => setBatch(null) }, batch.id) })) : (_jsxs("div", { className: "ea-aside__body", children: [_jsxs("div", { className: "ea-messages", ref: threadRef, onScroll: onThreadScroll, children: [messages.length === 0 ? (_jsx("div", { className: "ea-msg ea-msg--assistant", children: introText(view, bridge, collections, config, copy) })) : null, messages.map((message) => (_jsxs("div", { className: `ea-msg ea-msg--${message.role}`, children: [message.role === "assistant" ? _jsx(ReplyText, { text: message.text }) : message.text, message.candidates?.length ? (_jsx("div", { className: "ea-actions", children: message.candidates.map((candidate) => (_jsx(Button, { buttonStyle: "pill", margin: false, onClick: () => {
447
+ return (_jsxs("aside", { className: "ea-aside", "aria-label": copy.assistant, [KEEP_SELECTION_ATTR]: "", children: [_jsxs("div", { className: "ea-aside__head", children: [_jsxs("div", { className: "ea-aside__title", children: [_jsx("h2", { children: copy.assistant }), bridge ? _jsx("p", { className: "ea-aside__context", children: contextLine(bridge, config) }) : null] }), !batch && (messages.length > 0 || pendingApproval) && !pendingApproval?.applied ? (_jsx(Button, { buttonStyle: "subtle", margin: false, onClick: () => resetConversation(), size: "medium", children: copy.newChat })) : null, _jsx(Button, { "aria-label": copy.collapseLabel, buttonStyle: "icon-label", className: "ea-aside__collapse", icon: _jsx(ChevronIcon, { direction: "right" }), margin: false, onClick: () => setOpen(false), tooltip: copy.collapse })] }), batch ? (_jsx("div", { className: "ea-aside__body", children: _jsx(BatchPanel, { batch: batch, onClose: () => {
448
+ releaseTakenBatches();
449
+ setBatch(null);
450
+ } }, batch.id) })) : (_jsxs("div", { className: "ea-aside__body", children: [_jsxs("div", { className: "ea-messages", ref: threadRef, onScroll: onThreadScroll, children: [messages.length === 0 ? (_jsx("div", { className: "ea-msg ea-msg--assistant", children: introText(view, bridge, collections, config, copy) })) : null, messages.map((message) => (_jsxs("div", { className: `ea-msg ea-msg--${message.role}`, children: [message.role === "assistant" ? _jsx(ReplyText, { text: message.text }) : message.text, message.candidates?.length ? (_jsx("div", { className: "ea-actions", children: message.candidates.map((candidate) => (_jsx(Button, { buttonStyle: "pill", margin: false, onClick: () => {
447
451
  router.push(candidate.href);
448
452
  }, size: "small", children: candidate.label }, candidate.href))) })) : null] }, message.id))), status === "streaming" ? (_jsxs("div", { className: "ea-msg ea-msg--working", children: [_jsxs("span", { className: "ea-dots", "aria-hidden": "true", children: [_jsx("span", {}), _jsx("span", {}), _jsx("span", {})] }), _jsx("span", { children: step ? talk.steps[step] : talk.working })] })) : null] }), pendingApproval ? (_jsxs("div", { className: "ea-approval", children: [_jsx("h3", { children: pendingApproval.title }), pendingApproval.applied ? (_jsxs("p", { className: "ea-approval__hint", children: [autosave ? copy.previewHintAutosave : copy.previewHint, pendingApproval.earlier?.length ? ` ${copy.refinedHint}` : ""] })) : null, _jsx("ul", { className: "ea-approval__diff", children: pendingApproval.summary.split("\n").map((line, index) => line.startsWith(" ") ? (
449
453
  // biome-ignore lint/suspicious/noArrayIndexKey: lines are static for one approval
@@ -1,3 +1,5 @@
1
+ /** Once the editor leaves a batch, the same link may start it again. */
2
+ export declare function releaseTakenBatches(): void;
1
3
  /**
2
4
  * Opens the panel in batch mode when the address carries a batch from content health's work list,
3
5
  * and takes the parameters out of it, so a reload does not start the batch again.
@@ -6,6 +6,10 @@ import { useAssistantState } from "./assistant-context.js";
6
6
  import { ASK_PARAM } from "./selection-dom.js";
7
7
  /** Batches already taken this session: a view that writes its old address back must not repeat one. */
8
8
  const taken = new Set();
9
+ /** Once the editor leaves a batch, the same link may start it again. */
10
+ export function releaseTakenBatches() {
11
+ taken.clear();
12
+ }
9
13
  /**
10
14
  * Opens the panel in batch mode when the address carries a batch from content health's work list,
11
15
  * and takes the parameters out of it, so a reload does not start the batch again.
@@ -13,11 +17,13 @@ const taken = new Set();
13
17
  export function useBatchLink() {
14
18
  const params = useSearchParams();
15
19
  const { setBatch, setOpen } = useAssistantState();
16
- const value = params?.get(BATCH_PARAM);
20
+ // Depends on `params`, not the value: the same batch clicked twice leaves the value unchanged.
17
21
  useEffect(() => {
18
- if (!value || taken.has(value)) {
22
+ const value = params?.get(BATCH_PARAM);
23
+ if (!value) {
19
24
  return;
20
25
  }
26
+ const repeated = taken.has(value);
21
27
  taken.add(value);
22
28
  const url = new URL(window.location.href);
23
29
  const targets = parseBatchTargets(url.searchParams.get(BATCH_PARAM));
@@ -27,9 +33,14 @@ export function useBatchLink() {
27
33
  url.searchParams.delete(name);
28
34
  }
29
35
  window.history.replaceState(window.history.state, "", url.toString());
36
+ if (repeated) {
37
+ // The batch is still in the panel, which the editor closed: show it again.
38
+ setOpen(true);
39
+ return;
40
+ }
30
41
  if (targets.length > 0 && prompt) {
31
42
  setBatch({ id: crypto.randomUUID(), targets, scope, prompt });
32
43
  setOpen(true);
33
44
  }
34
- }, [value, setBatch, setOpen]);
45
+ }, [params, setBatch, setOpen]);
35
46
  }
@@ -28,7 +28,9 @@ export async function loadTurnContext(req, options, bridge, formData) {
28
28
  query: "",
29
29
  locale: bridge.locale,
30
30
  });
31
- const otherLanguages = open ? await readOtherLanguages(req, options, bridge, fields) : undefined;
31
+ const otherLanguages = open
32
+ ? await readOtherLanguages(req, options, bridge, fields, form)
33
+ : undefined;
32
34
  const translation = form ? translationFor(req, bridge, fields, form, otherLanguages) : undefined;
33
35
  return {
34
36
  allowlist: schema.map(compactEntity),
@@ -62,7 +64,7 @@ async function readSavedDocument(req, options, bridge) {
62
64
  }
63
65
  return result.data;
64
66
  }
65
- async function readOtherLanguages(req, options, bridge, fields) {
67
+ async function readOtherLanguages(req, options, bridge, fields, form) {
66
68
  const locales = configuredLocales(req).filter((code) => code !== bridge.locale);
67
69
  if (locales.length === 0) {
68
70
  return undefined;
@@ -75,9 +77,13 @@ async function readOtherLanguages(req, options, bridge, fields) {
75
77
  documentId: bridge.documentId,
76
78
  locale,
77
79
  });
78
- // A language nobody wrote in yet is left out: it has nothing to translate from.
79
- if (result.ok && translationPaths(fields, {}, result.data).empty.length > 0) {
80
- otherLanguages[locale] = result.data;
80
+ // A language nobody wrote in yet is left out: it has nothing to translate from. Compared with
81
+ // the open form, since blocks and rows are matched one by one and never against nothing.
82
+ if (result.ok) {
83
+ const paths = translationPaths(fields, form ?? {}, result.data);
84
+ if (paths.empty.length + paths.translated.length > 0) {
85
+ otherLanguages[locale] = result.data;
86
+ }
81
87
  }
82
88
  }
83
89
  return Object.keys(otherLanguages).length > 0 ? otherLanguages : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simmalugnt-se/payload-editor-assistant",
3
- "version": "0.11.1",
3
+ "version": "0.11.3",
4
4
  "description": "Context-aware editor assistant plugin for Payload Admin",
5
5
  "keywords": [
6
6
  "payload",