@focus-reactive/payload-plugin-seo 1.11.0 → 1.12.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/README.md +106 -7
- package/dist/admin.css +28 -1
- package/dist/components/SeoButton/RemoteKeyphrasesGate.d.ts +7 -0
- package/dist/components/SeoButton/RemoteKeyphrasesGate.d.ts.map +1 -0
- package/dist/components/SeoButton/RemoteKeyphrasesGate.js +23 -0
- package/dist/components/SeoButton/RemoteKeyphrasesGate.js.map +1 -0
- package/dist/components/SeoButton/SeoButtonInner.d.ts +7 -1
- package/dist/components/SeoButton/SeoButtonInner.d.ts.map +1 -1
- package/dist/components/SeoButton/SeoButtonInner.js +20 -26
- package/dist/components/SeoButton/SeoButtonInner.js.map +1 -1
- package/dist/components/SeoButton/SeoTriggerButton.d.ts +9 -0
- package/dist/components/SeoButton/SeoTriggerButton.d.ts.map +1 -0
- package/dist/components/SeoButton/SeoTriggerButton.js +31 -0
- package/dist/components/SeoButton/SeoTriggerButton.js.map +1 -0
- package/dist/components/SeoButton/index.d.ts.map +1 -1
- package/dist/components/SeoButton/index.js +6 -1
- package/dist/components/SeoButton/index.js.map +1 -1
- package/dist/components/SeoDrawer/TabsNav/constants.d.ts +2 -1
- package/dist/components/SeoDrawer/TabsNav/constants.d.ts.map +1 -1
- package/dist/components/SeoDrawer/TabsNav/constants.js +7 -2
- package/dist/components/SeoDrawer/TabsNav/constants.js.map +1 -1
- package/dist/components/SeoDrawer/TabsNav/index.d.ts +4 -2
- package/dist/components/SeoDrawer/TabsNav/index.d.ts.map +1 -1
- package/dist/components/SeoDrawer/TabsNav/index.js +5 -3
- package/dist/components/SeoDrawer/TabsNav/index.js.map +1 -1
- package/dist/components/SeoDrawer/TabsNav/types.d.ts +1 -1
- package/dist/components/SeoDrawer/TabsNav/types.d.ts.map +1 -1
- package/dist/components/SeoDrawer/index.d.ts +5 -0
- package/dist/components/SeoDrawer/index.d.ts.map +1 -1
- package/dist/components/SeoDrawer/index.js +15 -5
- package/dist/components/SeoDrawer/index.js.map +1 -1
- package/dist/components/SeoDrawer/keyphraseStorage.d.ts +7 -1
- package/dist/components/SeoDrawer/keyphraseStorage.d.ts.map +1 -1
- package/dist/components/SeoDrawer/keyphraseStorage.js +41 -24
- package/dist/components/SeoDrawer/keyphraseStorage.js.map +1 -1
- package/dist/components/SeoDrawer/links/readContent.d.ts +7 -0
- package/dist/components/SeoDrawer/links/readContent.d.ts.map +1 -0
- package/dist/components/SeoDrawer/links/readContent.js +21 -0
- package/dist/components/SeoDrawer/links/readContent.js.map +1 -0
- package/dist/components/SeoDrawer/links/readInternalLinks.d.ts +3 -0
- package/dist/components/SeoDrawer/links/readInternalLinks.d.ts.map +1 -0
- package/dist/components/SeoDrawer/links/readInternalLinks.js +35 -0
- package/dist/components/SeoDrawer/links/readInternalLinks.js.map +1 -0
- package/dist/components/SeoDrawer/links/useLinkSuggestions.d.ts +27 -0
- package/dist/components/SeoDrawer/links/useLinkSuggestions.d.ts.map +1 -0
- package/dist/components/SeoDrawer/links/useLinkSuggestions.js +65 -0
- package/dist/components/SeoDrawer/links/useLinkSuggestions.js.map +1 -0
- package/dist/components/SeoDrawer/remoteSaver.d.ts +30 -0
- package/dist/components/SeoDrawer/remoteSaver.d.ts.map +1 -0
- package/dist/components/SeoDrawer/remoteSaver.js +81 -0
- package/dist/components/SeoDrawer/remoteSaver.js.map +1 -0
- package/dist/components/SeoDrawer/tabs/KeyphraseTab.d.ts +4 -1
- package/dist/components/SeoDrawer/tabs/KeyphraseTab.d.ts.map +1 -1
- package/dist/components/SeoDrawer/tabs/KeyphraseTab.js +10 -2
- package/dist/components/SeoDrawer/tabs/KeyphraseTab.js.map +1 -1
- package/dist/components/SeoDrawer/tabs/LinksTab.d.ts +7 -0
- package/dist/components/SeoDrawer/tabs/LinksTab.d.ts.map +1 -0
- package/dist/components/SeoDrawer/tabs/LinksTab.js +66 -0
- package/dist/components/SeoDrawer/tabs/LinksTab.js.map +1 -0
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseDetail.d.ts +4 -1
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseDetail.d.ts.map +1 -1
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseDetail.js +19 -16
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseDetail.js.map +1 -1
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseRail.d.ts +3 -1
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseRail.d.ts.map +1 -1
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseRail.js +7 -3
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseRail.js.map +1 -1
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseUsageNotice.d.ts +8 -0
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseUsageNotice.d.ts.map +1 -0
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseUsageNotice.js +53 -0
- package/dist/components/SeoDrawer/tabs/keyphrase/KeyphraseUsageNotice.js.map +1 -0
- package/dist/components/SeoDrawer/tabs/keyphrase/SynonymsField.d.ts +2 -1
- package/dist/components/SeoDrawer/tabs/keyphrase/SynonymsField.d.ts.map +1 -1
- package/dist/components/SeoDrawer/tabs/keyphrase/SynonymsField.js +4 -3
- package/dist/components/SeoDrawer/tabs/keyphrase/SynonymsField.js.map +1 -1
- package/dist/components/SeoDrawer/tabs/links/LinkSuggestionRow.d.ts +8 -0
- package/dist/components/SeoDrawer/tabs/links/LinkSuggestionRow.d.ts.map +1 -0
- package/dist/components/SeoDrawer/tabs/links/LinkSuggestionRow.js +94 -0
- package/dist/components/SeoDrawer/tabs/links/LinkSuggestionRow.js.map +1 -0
- package/dist/components/SeoDrawer/useFlushOnHide.d.ts +3 -0
- package/dist/components/SeoDrawer/useFlushOnHide.d.ts.map +1 -0
- package/dist/components/SeoDrawer/useFlushOnHide.js +24 -0
- package/dist/components/SeoDrawer/useFlushOnHide.js.map +1 -0
- package/dist/components/SeoDrawer/useKeyphrases.d.ts +12 -1
- package/dist/components/SeoDrawer/useKeyphrases.d.ts.map +1 -1
- package/dist/components/SeoDrawer/useKeyphrases.js +85 -22
- package/dist/components/SeoDrawer/useKeyphrases.js.map +1 -1
- package/dist/components/SeoDrawer/useRemoteSync.d.ts +18 -0
- package/dist/components/SeoDrawer/useRemoteSync.d.ts.map +1 -0
- package/dist/components/SeoDrawer/useRemoteSync.js +42 -0
- package/dist/components/SeoDrawer/useRemoteSync.js.map +1 -0
- package/dist/components/SeoField/index.d.ts.map +1 -1
- package/dist/components/SeoField/index.js +2 -5
- package/dist/components/SeoField/index.js.map +1 -1
- package/dist/constants/index.d.ts +2 -0
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +2 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/constants/keyphrases.d.ts +8 -0
- package/dist/constants/keyphrases.d.ts.map +1 -0
- package/dist/constants/keyphrases.js +17 -0
- package/dist/constants/keyphrases.js.map +1 -0
- package/dist/constants/links.d.ts +11 -0
- package/dist/constants/links.d.ts.map +1 -0
- package/dist/constants/links.js +23 -0
- package/dist/constants/links.js.map +1 -0
- package/dist/content/resolve/resolve-docs.d.ts.map +1 -1
- package/dist/content/resolve/resolve-docs.js +3 -5
- package/dist/content/resolve/resolve-docs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/keyphrases/docTarget.d.ts +7 -0
- package/dist/keyphrases/docTarget.d.ts.map +1 -0
- package/dist/keyphrases/docTarget.js +15 -0
- package/dist/keyphrases/docTarget.js.map +1 -0
- package/dist/keyphrases/stored.d.ts +6 -0
- package/dist/keyphrases/stored.d.ts.map +1 -0
- package/dist/keyphrases/stored.js +29 -0
- package/dist/keyphrases/stored.js.map +1 -0
- package/dist/keyphrases/text.d.ts +10 -0
- package/dist/keyphrases/text.d.ts.map +1 -0
- package/dist/keyphrases/text.js +38 -0
- package/dist/keyphrases/text.js.map +1 -0
- package/dist/keyphrases/usage.d.ts +7 -0
- package/dist/keyphrases/usage.d.ts.map +1 -0
- package/dist/keyphrases/usage.js +10 -0
- package/dist/keyphrases/usage.js.map +1 -0
- package/dist/links/toPath.d.ts +3 -0
- package/dist/links/toPath.d.ts.map +1 -0
- package/dist/links/toPath.js +39 -0
- package/dist/links/toPath.js.map +1 -0
- package/dist/links/types.d.ts +15 -0
- package/dist/links/types.d.ts.map +1 -0
- package/dist/links/types.js +1 -0
- package/dist/links/types.js.map +1 -0
- package/dist/plugin.d.ts.map +1 -1
- package/dist/plugin.js +2 -1
- package/dist/plugin.js.map +1 -1
- package/dist/server/docTargets.d.ts +16 -0
- package/dist/server/docTargets.d.ts.map +1 -0
- package/dist/server/docTargets.js +42 -0
- package/dist/server/docTargets.js.map +1 -0
- package/dist/server/findDocsByIds.d.ts +17 -0
- package/dist/server/findDocsByIds.d.ts.map +1 -0
- package/dist/server/findDocsByIds.js +24 -0
- package/dist/server/findDocsByIds.js.map +1 -0
- package/dist/server/generate/endpoint.d.ts.map +1 -1
- package/dist/server/generate/endpoint.js +5 -11
- package/dist/server/generate/endpoint.js.map +1 -1
- package/dist/server/generate/serverResolveDocs.d.ts.map +1 -1
- package/dist/server/generate/serverResolveDocs.js +9 -18
- package/dist/server/generate/serverResolveDocs.js.map +1 -1
- package/dist/server/http.d.ts +3 -0
- package/dist/server/http.d.ts.map +1 -0
- package/dist/server/http.js +11 -0
- package/dist/server/http.js.map +1 -0
- package/dist/server/keyphrases/authorize.d.ts +8 -0
- package/dist/server/keyphrases/authorize.d.ts.map +1 -0
- package/dist/server/keyphrases/authorize.js +81 -0
- package/dist/server/keyphrases/authorize.js.map +1 -0
- package/dist/server/keyphrases/cleanupHook.d.ts +3 -0
- package/dist/server/keyphrases/cleanupHook.d.ts.map +1 -0
- package/dist/server/keyphrases/cleanupHook.js +16 -0
- package/dist/server/keyphrases/cleanupHook.js.map +1 -0
- package/dist/server/keyphrases/collection.d.ts +3 -0
- package/dist/server/keyphrases/collection.d.ts.map +1 -0
- package/dist/server/keyphrases/collection.js +27 -0
- package/dist/server/keyphrases/collection.js.map +1 -0
- package/dist/server/keyphrases/docRef.d.ts +3 -0
- package/dist/server/keyphrases/docRef.d.ts.map +1 -0
- package/dist/server/keyphrases/docRef.js +16 -0
- package/dist/server/keyphrases/docRef.js.map +1 -0
- package/dist/server/keyphrases/endpoints.d.ts +4 -0
- package/dist/server/keyphrases/endpoints.d.ts.map +1 -0
- package/dist/server/keyphrases/endpoints.js +111 -0
- package/dist/server/keyphrases/endpoints.js.map +1 -0
- package/dist/server/keyphrases/rows.d.ts +8 -0
- package/dist/server/keyphrases/rows.d.ts.map +1 -0
- package/dist/server/keyphrases/rows.js +50 -0
- package/dist/server/keyphrases/rows.js.map +1 -0
- package/dist/server/keyphrases/types.d.ts +16 -0
- package/dist/server/keyphrases/types.d.ts.map +1 -0
- package/dist/server/keyphrases/types.js +1 -0
- package/dist/server/keyphrases/types.js.map +1 -0
- package/dist/server/keyphrases/withKeyphraseIndex.d.ts +4 -0
- package/dist/server/keyphrases/withKeyphraseIndex.d.ts.map +1 -0
- package/dist/server/keyphrases/withKeyphraseIndex.js +41 -0
- package/dist/server/keyphrases/withKeyphraseIndex.js.map +1 -0
- package/dist/server/links/endpoint.d.ts +4 -0
- package/dist/server/links/endpoint.d.ts.map +1 -0
- package/dist/server/links/endpoint.js +85 -0
- package/dist/server/links/endpoint.js.map +1 -0
- package/dist/server/links/findLinkCandidates.d.ts +10 -0
- package/dist/server/links/findLinkCandidates.d.ts.map +1 -0
- package/dist/server/links/findLinkCandidates.js +121 -0
- package/dist/server/links/findLinkCandidates.js.map +1 -0
- package/dist/server/links/request.d.ts +11 -0
- package/dist/server/links/request.d.ts.map +1 -0
- package/dist/server/links/request.js +54 -0
- package/dist/server/links/request.js.map +1 -0
- package/dist/server/links/resolveLinkTargets.d.ts +5 -0
- package/dist/server/links/resolveLinkTargets.d.ts.map +1 -0
- package/dist/server/links/resolveLinkTargets.js +35 -0
- package/dist/server/links/resolveLinkTargets.js.map +1 -0
- package/dist/server/links/snippet.d.ts +10 -0
- package/dist/server/links/snippet.d.ts.map +1 -0
- package/dist/server/links/snippet.js +38 -0
- package/dist/server/links/snippet.js.map +1 -0
- package/dist/server/links/sourceRows.d.ts +5 -0
- package/dist/server/links/sourceRows.d.ts.map +1 -0
- package/dist/server/links/sourceRows.js +24 -0
- package/dist/server/links/sourceRows.js.map +1 -0
- package/dist/server/links/toLinkSources.d.ts +4 -0
- package/dist/server/links/toLinkSources.d.ts.map +1 -0
- package/dist/server/links/toLinkSources.js +11 -0
- package/dist/server/links/toLinkSources.js.map +1 -0
- package/dist/translations/messages/cs.d.ts.map +1 -1
- package/dist/translations/messages/cs.js +20 -0
- package/dist/translations/messages/cs.js.map +1 -1
- package/dist/translations/messages/en.d.ts +19 -0
- package/dist/translations/messages/en.d.ts.map +1 -1
- package/dist/translations/messages/en.js +19 -0
- package/dist/translations/messages/en.js.map +1 -1
- package/dist/types/config.d.ts +9 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/ui/Notice.d.ts +7 -0
- package/dist/ui/Notice.d.ts.map +1 -0
- package/dist/ui/Notice.js +26 -0
- package/dist/ui/Notice.js.map +1 -0
- package/dist/utils/config/overrideAdmin.d.ts.map +1 -1
- package/dist/utils/config/overrideAdmin.js +2 -1
- package/dist/utils/config/overrideAdmin.js.map +1 -1
- package/dist/utils/style.d.ts +1 -0
- package/dist/utils/style.d.ts.map +1 -1
- package/dist/utils/style.js +4 -0
- package/dist/utils/style.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,14 +1,49 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
2
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import * as ops from "./keyphraseState";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
entriesOrBlank,
|
|
6
|
+
loadKeyphrases,
|
|
7
|
+
loadUnsavedKeyphrases,
|
|
8
|
+
saveKeyphrases,
|
|
9
|
+
storageKey,
|
|
10
|
+
unsavedStorageKey
|
|
11
|
+
} from "./keyphraseStorage";
|
|
12
|
+
import { createRemoteSaver } from "./remoteSaver";
|
|
13
|
+
import { useFlushOnHide } from "./useFlushOnHide";
|
|
14
|
+
import { useRemoteSync } from "./useRemoteSync";
|
|
15
|
+
function initialList(key, remote) {
|
|
16
|
+
return remote?.indexed ? entriesOrBlank(remote.initial) : loadKeyphrases(key);
|
|
17
|
+
}
|
|
18
|
+
function initialState(key, unsavedKey, remote) {
|
|
19
|
+
const unsaved = remote?.canUpdate ? loadUnsavedKeyphrases(unsavedKey) : null;
|
|
20
|
+
if (unsaved)
|
|
21
|
+
return { entries: unsaved, sync: "retry" };
|
|
22
|
+
const entries = initialList(key, remote);
|
|
23
|
+
const hasBrowserCopy = remote?.canUpdate && !remote.indexed && ops.pruneEmpties(entries).length;
|
|
24
|
+
return { entries, sync: hasBrowserCopy ? "upload" : null };
|
|
25
|
+
}
|
|
5
26
|
function useKeyphrases({
|
|
6
27
|
collectionSlug,
|
|
7
28
|
docId,
|
|
8
|
-
localeCode
|
|
29
|
+
localeCode,
|
|
30
|
+
remote
|
|
9
31
|
}) {
|
|
10
32
|
const key = storageKey(collectionSlug, docId, localeCode);
|
|
11
|
-
const [
|
|
33
|
+
const [initial] = useState(
|
|
34
|
+
() => initialState(key, unsavedStorageKey(collectionSlug, docId, localeCode), remote)
|
|
35
|
+
);
|
|
36
|
+
const [list, setList] = useState(initial.entries);
|
|
37
|
+
const [saveFailed, setSaveFailed] = useState(false);
|
|
38
|
+
const persistLocally = !remote;
|
|
39
|
+
const apiRoute = remote?.canUpdate ? remote.apiRoute : void 0;
|
|
40
|
+
const saver = useMemo(
|
|
41
|
+
() => apiRoute ? createRemoteSaver(
|
|
42
|
+
{ apiRoute, collection: collectionSlug, docId, locale: localeCode },
|
|
43
|
+
{ onOutcome: (outcome) => setSaveFailed(outcome.status === "failed") }
|
|
44
|
+
) : null,
|
|
45
|
+
[apiRoute, collectionSlug, docId, localeCode]
|
|
46
|
+
);
|
|
12
47
|
const keyRef = useRef(key);
|
|
13
48
|
useEffect(() => {
|
|
14
49
|
if (keyRef.current !== key) {
|
|
@@ -17,40 +52,65 @@ function useKeyphrases({
|
|
|
17
52
|
}
|
|
18
53
|
}, [key]);
|
|
19
54
|
useEffect(() => {
|
|
20
|
-
|
|
21
|
-
|
|
55
|
+
if (persistLocally)
|
|
56
|
+
saveKeyphrases(key, list);
|
|
57
|
+
}, [key, list, persistLocally]);
|
|
58
|
+
useFlushOnHide(saver);
|
|
22
59
|
const listRef = useRef(list);
|
|
23
60
|
listRef.current = list;
|
|
24
61
|
useEffect(
|
|
25
62
|
() => () => {
|
|
63
|
+
if (!persistLocally)
|
|
64
|
+
return;
|
|
26
65
|
const pruned = ops.pruneEmpties(listRef.current);
|
|
27
66
|
if (pruned.length !== listRef.current.length)
|
|
28
67
|
saveKeyphrases(keyRef.current, pruned);
|
|
29
68
|
},
|
|
30
|
-
[]
|
|
69
|
+
[persistLocally]
|
|
31
70
|
);
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const next = ops.addRelated(current);
|
|
35
|
-
if (next === current)
|
|
36
|
-
return void 0;
|
|
71
|
+
const replaceList = useCallback((next) => {
|
|
72
|
+
listRef.current = next;
|
|
37
73
|
setList(next);
|
|
38
|
-
return next.at(-1)?.id;
|
|
39
74
|
}, []);
|
|
75
|
+
const { syncOnOpen, cancelSync } = useRemoteSync({
|
|
76
|
+
saver,
|
|
77
|
+
pending: initial.sync,
|
|
78
|
+
browserKey: key,
|
|
79
|
+
listRef,
|
|
80
|
+
replaceList
|
|
81
|
+
});
|
|
82
|
+
const apply = useCallback(
|
|
83
|
+
(op) => {
|
|
84
|
+
const current = listRef.current;
|
|
85
|
+
const next = op(current);
|
|
86
|
+
if (next === current)
|
|
87
|
+
return current;
|
|
88
|
+
replaceList(next);
|
|
89
|
+
saver?.schedule(next);
|
|
90
|
+
cancelSync();
|
|
91
|
+
return next;
|
|
92
|
+
},
|
|
93
|
+
[cancelSync, replaceList, saver]
|
|
94
|
+
);
|
|
95
|
+
const addRelated = useCallback(() => {
|
|
96
|
+
const current = listRef.current;
|
|
97
|
+
const next = apply(ops.addRelated);
|
|
98
|
+
return next === current ? void 0 : next.at(-1)?.id;
|
|
99
|
+
}, [apply]);
|
|
40
100
|
const updateText = useCallback(
|
|
41
|
-
(id, text) =>
|
|
42
|
-
[]
|
|
101
|
+
(id, text) => apply((l) => ops.updateText(l, id, text)),
|
|
102
|
+
[apply]
|
|
43
103
|
);
|
|
44
104
|
const addSynonym = useCallback(
|
|
45
|
-
(id, syn) =>
|
|
46
|
-
[]
|
|
105
|
+
(id, syn) => apply((l) => ops.addSynonym(l, id, syn)),
|
|
106
|
+
[apply]
|
|
47
107
|
);
|
|
48
108
|
const removeSynonym = useCallback(
|
|
49
|
-
(id, index) =>
|
|
50
|
-
[]
|
|
109
|
+
(id, index) => apply((l) => ops.removeSynonym(l, id, index)),
|
|
110
|
+
[apply]
|
|
51
111
|
);
|
|
52
|
-
const remove = useCallback((id) =>
|
|
53
|
-
const setFocus = useCallback((id) =>
|
|
112
|
+
const remove = useCallback((id) => apply((l) => ops.remove(l, id)), [apply]);
|
|
113
|
+
const setFocus = useCallback((id) => apply((l) => ops.setFocus(l, id)), [apply]);
|
|
54
114
|
const isDuplicate = useCallback(
|
|
55
115
|
(id, text) => ops.isDuplicate(listRef.current, id, text),
|
|
56
116
|
[]
|
|
@@ -63,7 +123,10 @@ function useKeyphrases({
|
|
|
63
123
|
removeSynonym,
|
|
64
124
|
remove,
|
|
65
125
|
setFocus,
|
|
66
|
-
isDuplicate
|
|
126
|
+
isDuplicate,
|
|
127
|
+
syncOnOpen,
|
|
128
|
+
readOnly: Boolean(remote && !remote.canUpdate),
|
|
129
|
+
saveFailed
|
|
67
130
|
};
|
|
68
131
|
}
|
|
69
132
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/SeoDrawer/useKeyphrases.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, useRef, useState } from \"react\";\nimport * as ops from \"./keyphraseState\";\nimport type { KeyphraseEntry } from \"./keyphraseState\";\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SeoDrawer/useKeyphrases.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport type { StoredKeyphrase } from \"../../keyphrases/stored\";\nimport * as ops from \"./keyphraseState\";\nimport type { KeyphraseEntry } from \"./keyphraseState\";\nimport {\n entriesOrBlank,\n loadKeyphrases,\n loadUnsavedKeyphrases,\n saveKeyphrases,\n storageKey,\n unsavedStorageKey,\n} from \"./keyphraseStorage\";\nimport { createRemoteSaver } from \"./remoteSaver\";\nimport { useFlushOnHide } from \"./useFlushOnHide\";\nimport { useRemoteSync } from \"./useRemoteSync\";\nimport type { PendingSync } from \"./useRemoteSync\";\n\nexport interface RemoteKeyphrases {\n apiRoute: string;\n initial: StoredKeyphrase[];\n indexed: boolean;\n canUpdate: boolean;\n}\n\nexport interface UseKeyphrasesArgs {\n collectionSlug: string;\n docId: string;\n localeCode: string;\n remote?: RemoteKeyphrases;\n}\n\nexport interface UseKeyphrasesApi {\n keyphrases: KeyphraseEntry[];\n addRelated: () => string | undefined;\n updateText: (id: string, text: string) => void;\n addSynonym: (id: string, syn: string) => void;\n removeSynonym: (id: string, index: number) => void;\n remove: (id: string) => void;\n setFocus: (id: string) => void;\n isDuplicate: (id: string, text: string) => boolean;\n syncOnOpen: () => void;\n readOnly: boolean;\n saveFailed: boolean;\n}\n\ninterface InitialState {\n entries: KeyphraseEntry[];\n sync: PendingSync;\n}\n\nfunction initialList(key: string, remote?: RemoteKeyphrases): KeyphraseEntry[] {\n return remote?.indexed ? entriesOrBlank(remote.initial) : loadKeyphrases(key);\n}\n\nfunction initialState(key: string, unsavedKey: string, remote?: RemoteKeyphrases): InitialState {\n const unsaved = remote?.canUpdate ? loadUnsavedKeyphrases(unsavedKey) : null;\n if (unsaved) return { entries: unsaved, sync: \"retry\" };\n\n const entries = initialList(key, remote);\n const hasBrowserCopy = remote?.canUpdate && !remote.indexed && ops.pruneEmpties(entries).length;\n\n return { entries, sync: hasBrowserCopy ? \"upload\" : null };\n}\n\nexport function useKeyphrases({\n collectionSlug,\n docId,\n localeCode,\n remote,\n}: UseKeyphrasesArgs): UseKeyphrasesApi {\n const key = storageKey(collectionSlug, docId, localeCode);\n const [initial] = useState(() =>\n initialState(key, unsavedStorageKey(collectionSlug, docId, localeCode), remote)\n );\n const [list, setList] = useState<KeyphraseEntry[]>(initial.entries);\n const [saveFailed, setSaveFailed] = useState(false);\n\n const persistLocally = !remote;\n const apiRoute = remote?.canUpdate ? remote.apiRoute : undefined;\n const saver = useMemo(\n () =>\n apiRoute\n ? createRemoteSaver(\n { apiRoute, collection: collectionSlug, docId, locale: localeCode },\n { onOutcome: (outcome) => setSaveFailed(outcome.status === \"failed\") }\n )\n : null,\n [apiRoute, collectionSlug, docId, localeCode]\n );\n\n const keyRef = useRef(key);\n\n useEffect(() => {\n if (keyRef.current !== key) {\n keyRef.current = key;\n setList(loadKeyphrases(key));\n }\n }, [key]);\n\n useEffect(() => {\n if (persistLocally) saveKeyphrases(key, list);\n }, [key, list, persistLocally]);\n\n useFlushOnHide(saver);\n\n const listRef = useRef(list);\n listRef.current = list;\n useEffect(\n () => () => {\n if (!persistLocally) return;\n\n const pruned = ops.pruneEmpties(listRef.current);\n if (pruned.length !== listRef.current.length) saveKeyphrases(keyRef.current, pruned);\n },\n [persistLocally]\n );\n\n const replaceList = useCallback((next: KeyphraseEntry[]) => {\n listRef.current = next;\n setList(next);\n }, []);\n\n const { syncOnOpen, cancelSync } = useRemoteSync({\n saver,\n pending: initial.sync,\n browserKey: key,\n listRef,\n replaceList,\n });\n\n const apply = useCallback(\n (op: (current: KeyphraseEntry[]) => KeyphraseEntry[]): KeyphraseEntry[] => {\n const current = listRef.current;\n const next = op(current);\n if (next === current) return current;\n\n replaceList(next);\n saver?.schedule(next);\n cancelSync();\n\n return next;\n },\n [cancelSync, replaceList, saver]\n );\n\n const addRelated = useCallback((): string | undefined => {\n const current = listRef.current;\n const next = apply(ops.addRelated);\n\n return next === current ? undefined : next.at(-1)?.id;\n }, [apply]);\n const updateText = useCallback(\n (id: string, text: string) => apply((l) => ops.updateText(l, id, text)),\n [apply]\n );\n const addSynonym = useCallback(\n (id: string, syn: string) => apply((l) => ops.addSynonym(l, id, syn)),\n [apply]\n );\n const removeSynonym = useCallback(\n (id: string, index: number) => apply((l) => ops.removeSynonym(l, id, index)),\n [apply]\n );\n const remove = useCallback((id: string) => apply((l) => ops.remove(l, id)), [apply]);\n const setFocus = useCallback((id: string) => apply((l) => ops.setFocus(l, id)), [apply]);\n const isDuplicate = useCallback(\n (id: string, text: string) => ops.isDuplicate(listRef.current, id, text),\n []\n );\n\n return {\n keyphrases: list,\n addRelated,\n updateText,\n addSynonym,\n removeSynonym,\n remove,\n setFocus,\n isDuplicate,\n syncOnOpen,\n readOnly: Boolean(remote && !remote.canUpdate),\n saveFailed,\n };\n}\n"],"mappings":";AAEA,SAAS,aAAa,WAAW,SAAS,QAAQ,gBAAgB;AAElE,YAAY,SAAS;AAErB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAClC,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAoC9B,SAAS,YAAY,KAAa,QAA6C;AAC7E,SAAO,QAAQ,UAAU,eAAe,OAAO,OAAO,IAAI,eAAe,GAAG;AAC9E;AAEA,SAAS,aAAa,KAAa,YAAoB,QAAyC;AAC9F,QAAM,UAAU,QAAQ,YAAY,sBAAsB,UAAU,IAAI;AACxE,MAAI;AAAS,WAAO,EAAE,SAAS,SAAS,MAAM,QAAQ;AAEtD,QAA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AAA,EACR;AACA,QAAM,SAAS,YAAY,CAAC,OAAe,MAAM,CAAC,MAAM,IAAI,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;AACnF,QAAM,WAAW,YAAY,CAAC,OAAe,MAAM,CAAC,MAAM,IAAI,SAAS,GAAG,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;AACvF,QAAM,cAAc;AAAA,IAClB,CAAC,IAAY,SAAiB,IAAI,YAAY,QAAQ,SAAS,IAAI,IAAI;AAAA,IACvE,CAAC;AAAA,EACH;AAEA,SAAO;AAAA,IACL,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,QAAQ,UAAU,CAAC,OAAO,SAAS;AAAA,IAC7C;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RefObject } from "react";
|
|
2
|
+
import type { KeyphraseEntry } from "./keyphraseState";
|
|
3
|
+
import type { RemoteSaver } from "./remoteSaver";
|
|
4
|
+
export type PendingSync = "upload" | "retry" | null;
|
|
5
|
+
interface RemoteSyncArgs {
|
|
6
|
+
saver: RemoteSaver | null;
|
|
7
|
+
pending: PendingSync;
|
|
8
|
+
browserKey: string;
|
|
9
|
+
listRef: RefObject<KeyphraseEntry[]>;
|
|
10
|
+
replaceList: (next: KeyphraseEntry[]) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface RemoteSync {
|
|
13
|
+
syncOnOpen: () => void;
|
|
14
|
+
cancelSync: () => void;
|
|
15
|
+
}
|
|
16
|
+
export declare function useRemoteSync({ saver, pending, browserKey, listRef, replaceList, }: RemoteSyncArgs): RemoteSync;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=useRemoteSync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRemoteSync.d.ts","sourceRoot":"","sources":["../../../src/components/SeoDrawer/useRemoteSync.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC;AAEpD,UAAU,cAAc;IACtB,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;IAC1B,OAAO,EAAE,WAAW,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,SAAS,CAAC,cAAc,EAAE,CAAC,CAAC;IACrC,WAAW,EAAE,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;CAC/C;AAED,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,OAAO,EACP,UAAU,EACV,OAAO,EACP,WAAW,GACZ,EAAE,cAAc,GAAG,UAAU,CAgC7B"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback, useRef } from "react";
|
|
3
|
+
import { clearKeyphrases, entriesOrBlank } from "./keyphraseStorage";
|
|
4
|
+
function useRemoteSync({
|
|
5
|
+
saver,
|
|
6
|
+
pending,
|
|
7
|
+
browserKey,
|
|
8
|
+
listRef,
|
|
9
|
+
replaceList
|
|
10
|
+
}) {
|
|
11
|
+
const pendingRef = useRef(pending);
|
|
12
|
+
const cancelSync = useCallback(() => {
|
|
13
|
+
pendingRef.current = null;
|
|
14
|
+
}, []);
|
|
15
|
+
const uploadBrowserCopy = useCallback(async () => {
|
|
16
|
+
const uploaded = listRef.current;
|
|
17
|
+
const outcome = await saver?.save(uploaded, { ifAbsent: true });
|
|
18
|
+
if (!outcome || outcome.status === "failed")
|
|
19
|
+
return;
|
|
20
|
+
clearKeyphrases(browserKey);
|
|
21
|
+
if (outcome.status === "exists" && listRef.current === uploaded) {
|
|
22
|
+
replaceList(entriesOrBlank(outcome.keyphrases));
|
|
23
|
+
}
|
|
24
|
+
}, [browserKey, listRef, replaceList, saver]);
|
|
25
|
+
const retryUnsaved = useCallback(() => {
|
|
26
|
+
saver?.schedule(listRef.current);
|
|
27
|
+
void saver?.flush();
|
|
28
|
+
}, [listRef, saver]);
|
|
29
|
+
const syncOnOpen = useCallback(() => {
|
|
30
|
+
const sync = pendingRef.current;
|
|
31
|
+
pendingRef.current = null;
|
|
32
|
+
if (sync === "upload")
|
|
33
|
+
void uploadBrowserCopy();
|
|
34
|
+
if (sync === "retry")
|
|
35
|
+
retryUnsaved();
|
|
36
|
+
}, [retryUnsaved, uploadBrowserCopy]);
|
|
37
|
+
return { syncOnOpen, cancelSync };
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
useRemoteSync
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=useRemoteSync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SeoDrawer/useRemoteSync.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useRef } from \"react\";\nimport type { RefObject } from \"react\";\nimport type { KeyphraseEntry } from \"./keyphraseState\";\nimport { clearKeyphrases, entriesOrBlank } from \"./keyphraseStorage\";\nimport type { RemoteSaver } from \"./remoteSaver\";\n\nexport type PendingSync = \"upload\" | \"retry\" | null;\n\ninterface RemoteSyncArgs {\n saver: RemoteSaver | null;\n pending: PendingSync;\n browserKey: string;\n listRef: RefObject<KeyphraseEntry[]>;\n replaceList: (next: KeyphraseEntry[]) => void;\n}\n\nexport interface RemoteSync {\n syncOnOpen: () => void;\n cancelSync: () => void;\n}\n\nexport function useRemoteSync({\n saver,\n pending,\n browserKey,\n listRef,\n replaceList,\n}: RemoteSyncArgs): RemoteSync {\n const pendingRef = useRef(pending);\n\n const cancelSync = useCallback(() => {\n pendingRef.current = null;\n }, []);\n\n const uploadBrowserCopy = useCallback(async () => {\n const uploaded = listRef.current;\n const outcome = await saver?.save(uploaded, { ifAbsent: true });\n if (!outcome || outcome.status === \"failed\") return;\n\n clearKeyphrases(browserKey);\n if (outcome.status === \"exists\" && listRef.current === uploaded) {\n replaceList(entriesOrBlank(outcome.keyphrases));\n }\n }, [browserKey, listRef, replaceList, saver]);\n\n const retryUnsaved = useCallback(() => {\n saver?.schedule(listRef.current);\n void saver?.flush();\n }, [listRef, saver]);\n\n const syncOnOpen = useCallback(() => {\n const sync = pendingRef.current;\n pendingRef.current = null;\n\n if (sync === \"upload\") void uploadBrowserCopy();\n if (sync === \"retry\") retryUnsaved();\n }, [retryUnsaved, uploadBrowserCopy]);\n\n return { syncOnOpen, cancelSync };\n}\n"],"mappings":";AAEA,SAAS,aAAa,cAAc;AAGpC,SAAS,iBAAiB,sBAAsB;AAkBzC,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAA+B;AAC7B,QAAM,aAAa,OAAO,OAAO;AAEjC,QAAM,aAAa,YAAY,MAAM;AACnC,eAAW,UAAU;AAAA,EACvB,GAAG,CAAC,CAAC;AAEL,QAAM,oBAAoB,YAAY,YAAY;AAChD,UAAM,WAAW,QAAQ;AACzB,UAAM,UAAU,MAAM,OAAO,KAAK,UAAU,EAAE,UAAU,KAAK,CAAC;AAC9D,QAAI,CAAC,WAAW,QAAQ,WAAW;AAAU;AAE7C,oBAAgB,UAAU;AAC1B,QAAI,QAAQ,WAAW,YAAY,QAAQ,YAAY,UAAU;AAC/D,kBAAY,eAAe,QAAQ,UAAU,CAAC;AAAA,IAChD;AAAA,EACF,GAAG,CAAC,YAAY,SAAS,aAAa,KAAK,CAAC;AAE5C,QAAM,eAAe,YAAY,MAAM;AACrC,WAAO,SAAS,QAAQ,OAAO;AAC/B,SAAK,OAAO,MAAM;AAAA,EACpB,GAAG,CAAC,SAAS,KAAK,CAAC;AAEnB,QAAM,aAAa,YAAY,MAAM;AACnC,UAAM,OAAO,WAAW;AACxB,eAAW,UAAU;AAErB,QAAI,SAAS;AAAU,WAAK,kBAAkB;AAC9C,QAAI,SAAS;AAAS,mBAAa;AAAA,EACrC,GAAG,CAAC,cAAc,iBAAiB,CAAC;AAEpC,SAAO,EAAE,YAAY,WAAW;AAClC;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SeoField/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAQlE,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE;QACN,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;QACxC,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,KAAK,CAAC,EAAE;YAAE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;SAAE,CAAC;KAC3D,CAAC;IACF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/SeoField/index.tsx"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAQlE,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE;QACN,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC;QACxC,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,KAAK,CAAC,EAAE;YAAE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;SAAE,CAAC;KAC3D,CAAC;IACF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB;AAUD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,2CAgH5C;AAED,eAAe,QAAQ,CAAC"}
|
|
@@ -4,14 +4,11 @@ import { FieldLabel, TextareaInput, TextInput, useField } from "@payloadcms/ui";
|
|
|
4
4
|
import { getSeoClientConfig } from "../../client-config/registry";
|
|
5
5
|
import { measureDescription, measureTitle } from "../../measure/measure";
|
|
6
6
|
import { Tooltip, TooltipText, TooltipTitle } from "../../ui/Tooltip";
|
|
7
|
-
import { cn } from "../../utils/style";
|
|
7
|
+
import { cn, OUTLINE_BUTTON_CLASS } from "../../utils/style";
|
|
8
8
|
import { AutoPublishIcon, ErrorIcon, GenerateIcon, SpinnerIcon } from "./icons";
|
|
9
9
|
import { Meter } from "./Meter";
|
|
10
10
|
import { useGenerate } from "./useGenerate";
|
|
11
11
|
import { useSeoTranslation } from "../../translations/useSeoTranslation";
|
|
12
|
-
const GEN_BTN_CLASS = cn(
|
|
13
|
-
"frseo:inline-flex frseo:items-center frseo:gap-[6px] frseo:rounded-rs frseo:border frseo:border-neutral-200 frseo:bg-transparent frseo:px-[9px] frseo:py-[4px] frseo:text-[12px] frseo:font-semibold frseo:text-neutral-800 frseo:transition-colors frseo:hover:border-neutral-300 frseo:hover:bg-neutral-100 frseo:disabled:cursor-default frseo:disabled:text-neutral-400 frseo:cursor-pointer"
|
|
14
|
-
);
|
|
15
12
|
function SeoField(props) {
|
|
16
13
|
const { path, field, readOnly, kind, showButton, generateOnPublish, range } = props;
|
|
17
14
|
const { t } = useSeoTranslation();
|
|
@@ -65,7 +62,7 @@ function SeoField(props) {
|
|
|
65
62
|
showButton && enabled && /* @__PURE__ */ jsxs(
|
|
66
63
|
"button",
|
|
67
64
|
{
|
|
68
|
-
className:
|
|
65
|
+
className: OUTLINE_BUTTON_CLASS,
|
|
69
66
|
disabled: loading || readOnly,
|
|
70
67
|
onClick: generate,
|
|
71
68
|
type: "button",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/SeoField/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { FieldLabel, TextareaInput, TextInput, useField } from \"@payloadcms/ui\";\nimport type { ChangeEvent, ReactNode } from \"react\";\nimport { getSeoClientConfig } from \"../../client-config/registry\";\nimport { measureDescription, measureTitle } from \"../../measure/measure\";\nimport type { RangeOverride } from \"../../measure/measure\";\nimport type { SeoFieldKind } from \"../../server/generate/prompts\";\nimport { Tooltip, TooltipText, TooltipTitle } from \"../../ui/Tooltip\";\nimport { cn } from \"../../utils/style\";\nimport { AutoPublishIcon, ErrorIcon, GenerateIcon, SpinnerIcon } from \"./icons\";\nimport { Meter } from \"./Meter\";\nimport { useGenerate } from \"./useGenerate\";\nimport { useSeoTranslation } from \"../../translations/useSeoTranslation\";\n\ninterface SeoFieldProps {\n path: string;\n field?: {\n label?: Record<string, string> | string;\n required?: boolean;\n admin?: { description?: Record<string, string> | string };\n };\n readOnly?: boolean;\n kind: SeoFieldKind;\n showButton?: boolean;\n generateOnPublish?: boolean;\n range?: RangeOverride;\n}\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SeoField/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { FieldLabel, TextareaInput, TextInput, useField } from \"@payloadcms/ui\";\nimport type { ChangeEvent, ReactNode } from \"react\";\nimport { getSeoClientConfig } from \"../../client-config/registry\";\nimport { measureDescription, measureTitle } from \"../../measure/measure\";\nimport type { RangeOverride } from \"../../measure/measure\";\nimport type { SeoFieldKind } from \"../../server/generate/prompts\";\nimport { Tooltip, TooltipText, TooltipTitle } from \"../../ui/Tooltip\";\nimport { cn, OUTLINE_BUTTON_CLASS } from \"../../utils/style\";\nimport { AutoPublishIcon, ErrorIcon, GenerateIcon, SpinnerIcon } from \"./icons\";\nimport { Meter } from \"./Meter\";\nimport { useGenerate } from \"./useGenerate\";\nimport { useSeoTranslation } from \"../../translations/useSeoTranslation\";\n\ninterface SeoFieldProps {\n path: string;\n field?: {\n label?: Record<string, string> | string;\n required?: boolean;\n admin?: { description?: Record<string, string> | string };\n };\n readOnly?: boolean;\n kind: SeoFieldKind;\n showButton?: boolean;\n generateOnPublish?: boolean;\n range?: RangeOverride;\n}\n\ninterface InjectedComponents {\n Label?: ReactNode;\n Description?: ReactNode;\n BeforeInput?: ReactNode;\n AfterInput?: ReactNode;\n Error?: ReactNode;\n}\n\nexport function SeoField(props: SeoFieldProps) {\n const { path, field, readOnly, kind, showButton, generateOnPublish, range } = props;\n const { t } = useSeoTranslation();\n const fieldState = useField<string>({ path });\n const { value, setValue, showError } = fieldState;\n const injected: InjectedComponents =\n (fieldState as { customComponents?: InjectedComponents }).customComponents ?? {};\n const text = value ?? \"\";\n const measurement =\n kind === \"title\" ? measureTitle(text, range) : measureDescription(text, range);\n\n const { generate, status, error } = useGenerate({ kind, measurement, setValue });\n const enabled = getSeoClientConfig().enabled;\n const loading = status === \"loading\";\n\n const labelRow = (\n <div className=\"flex min-h-[26px] items-center justify-between gap-[12px] pb-[5px] [&_.field-label]:pb-0!\">\n {injected.Label ?? <FieldLabel label={field?.label} path={path} required={field?.required} />}\n\n <span className=\"inline-flex items-center gap-[8px]\">\n {status === \"error\" && (\n <Tooltip\n align=\"end\"\n content={\n <>\n <TooltipTitle>{t(\"field.generationFailed\")}</TooltipTitle>\n <TooltipText>{error ?? t(\"field.unchanged\")}</TooltipText>\n </>\n }\n side=\"bottom\"\n >\n <ErrorIcon\n aria-label={t(\"field.generationFailed\")}\n className=\"size-[14px] text-seo-bad\"\n />\n </Tooltip>\n )}\n\n {generateOnPublish && enabled && (\n <Tooltip\n align=\"end\"\n content={\n <>\n <TooltipTitle>{t(\"field.auto.title\")}</TooltipTitle>\n <TooltipText>{t(`field.auto.body.${kind}`)}</TooltipText>\n </>\n }\n side=\"bottom\"\n >\n <AutoPublishIcon\n aria-label={t(\"field.auto.label\")}\n className=\"size-[14px] text-neutral-500\"\n />\n </Tooltip>\n )}\n\n {showButton && enabled && (\n <button\n className={OUTLINE_BUTTON_CLASS}\n disabled={loading || readOnly}\n onClick={generate}\n type=\"button\"\n >\n {loading ? (\n <SpinnerIcon className=\"size-[14px] animate-spin\" />\n ) : (\n <GenerateIcon className=\"size-[14px]\" />\n )}\n\n {t(loading ? \"field.generating\" : \"field.generate\")}\n </button>\n )}\n </span>\n </div>\n );\n\n const commonInputProps = {\n AfterInput: injected.AfterInput,\n BeforeInput: injected.BeforeInput,\n Description: injected.Description,\n Error: injected.Error,\n Label: labelRow,\n description: injected.Description ? undefined : field?.admin?.description,\n path,\n readOnly: loading || readOnly,\n showError,\n value: text,\n };\n\n return (\n <div className={cn(\"seo-generated-field mb-[20px] last:mb-0\", showError && \"error\")}>\n {kind === \"description\" ? (\n <TextareaInput\n {...commonInputProps}\n onChange={(e: ChangeEvent<HTMLTextAreaElement>) => setValue(e.target.value)}\n rows={3}\n />\n ) : (\n <TextInput\n {...commonInputProps}\n onChange={(e: ChangeEvent<HTMLInputElement>) => setValue(e.target.value)}\n />\n )}\n\n <Meter\n hasText={text.trim().length > 0}\n kind={kind}\n loading={loading}\n measurement={measurement}\n />\n </div>\n );\n}\n\nexport default SeoField;\n"],"mappings":";AAsDyB,SAOX,UAPW,KAOX,YAPW;AApDzB,SAAS,YAAY,eAAe,WAAW,gBAAgB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9B;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACF;AAAA,KACF;AAEJ;AAEA,IAAO,mBAAQ;","names":[]}
|
|
@@ -3,4 +3,6 @@ export declare const PKG = "@focus-reactive/payload-plugin-seo";
|
|
|
3
3
|
export declare const DEFAULT_LOCALES: readonly ["en"];
|
|
4
4
|
export declare const MAX_KEYPHRASES = 5;
|
|
5
5
|
export * from "./statuses";
|
|
6
|
+
export * from "./keyphrases";
|
|
7
|
+
export * from "./links";
|
|
6
8
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,uBAAuB,CAAC;AAChD,eAAO,MAAM,GAAG,uCAAuC,CAAC;AAExD,eAAO,MAAM,eAAe,iBAAkB,CAAC;AAE/C,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW,uBAAuB,CAAC;AAChD,eAAO,MAAM,GAAG,uCAAuC,CAAC;AAExD,eAAO,MAAM,eAAe,iBAAkB,CAAC;AAE/C,eAAO,MAAM,cAAc,IAAI,CAAC;AAEhC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|
package/dist/constants/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/constants/index.ts"],"sourcesContent":["export const PLUGIN_NAME = \"payload-plugin-seo\";\nexport const PKG = \"@focus-reactive/payload-plugin-seo\";\n\nexport const DEFAULT_LOCALES = [\"en\"] as const;\n\nexport const MAX_KEYPHRASES = 5;\n\nexport * from \"./statuses\";\n"],"mappings":"AAAO,MAAM,cAAc;AACpB,MAAM,MAAM;AAEZ,MAAM,kBAAkB,CAAC,IAAI;AAE7B,MAAM,iBAAiB;AAE9B,cAAc;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/constants/index.ts"],"sourcesContent":["export const PLUGIN_NAME = \"payload-plugin-seo\";\nexport const PKG = \"@focus-reactive/payload-plugin-seo\";\n\nexport const DEFAULT_LOCALES = [\"en\"] as const;\n\nexport const MAX_KEYPHRASES = 5;\n\nexport * from \"./statuses\";\nexport * from \"./keyphrases\";\nexport * from \"./links\";\n"],"mappings":"AAAO,MAAM,cAAc;AACpB,MAAM,MAAM;AAEZ,MAAM,kBAAkB,CAAC,IAAI;AAE7B,MAAM,iBAAiB;AAE9B,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const KEYPHRASES_COLLECTION_SLUG = "seo-keyphrases";
|
|
2
|
+
export declare const KEYPHRASES_ENDPOINT_PATH = "/seo/keyphrases";
|
|
3
|
+
export declare const KEYPHRASE_USAGE_ENDPOINT_PATH = "/seo/keyphrase-usage";
|
|
4
|
+
export declare const KEYPHRASE_SAVE_DELAY_MS = 800;
|
|
5
|
+
export declare const MAX_KEYPHRASE_LENGTH = 100;
|
|
6
|
+
export declare const MAX_SYNONYMS = 10;
|
|
7
|
+
export declare const MAX_SYNONYM_LENGTH = 100;
|
|
8
|
+
//# sourceMappingURL=keyphrases.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyphrases.d.ts","sourceRoot":"","sources":["../../src/constants/keyphrases.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,mBAAmB,CAAC;AAC3D,eAAO,MAAM,wBAAwB,oBAAoB,CAAC;AAC1D,eAAO,MAAM,6BAA6B,yBAAyB,CAAC;AACpE,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,kBAAkB,MAAM,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const KEYPHRASES_COLLECTION_SLUG = "seo-keyphrases";
|
|
2
|
+
const KEYPHRASES_ENDPOINT_PATH = "/seo/keyphrases";
|
|
3
|
+
const KEYPHRASE_USAGE_ENDPOINT_PATH = "/seo/keyphrase-usage";
|
|
4
|
+
const KEYPHRASE_SAVE_DELAY_MS = 800;
|
|
5
|
+
const MAX_KEYPHRASE_LENGTH = 100;
|
|
6
|
+
const MAX_SYNONYMS = 10;
|
|
7
|
+
const MAX_SYNONYM_LENGTH = 100;
|
|
8
|
+
export {
|
|
9
|
+
KEYPHRASES_COLLECTION_SLUG,
|
|
10
|
+
KEYPHRASES_ENDPOINT_PATH,
|
|
11
|
+
KEYPHRASE_SAVE_DELAY_MS,
|
|
12
|
+
KEYPHRASE_USAGE_ENDPOINT_PATH,
|
|
13
|
+
MAX_KEYPHRASE_LENGTH,
|
|
14
|
+
MAX_SYNONYMS,
|
|
15
|
+
MAX_SYNONYM_LENGTH
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=keyphrases.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants/keyphrases.ts"],"sourcesContent":["export const KEYPHRASES_COLLECTION_SLUG = \"seo-keyphrases\";\nexport const KEYPHRASES_ENDPOINT_PATH = \"/seo/keyphrases\";\nexport const KEYPHRASE_USAGE_ENDPOINT_PATH = \"/seo/keyphrase-usage\";\nexport const KEYPHRASE_SAVE_DELAY_MS = 800;\nexport const MAX_KEYPHRASE_LENGTH = 100;\nexport const MAX_SYNONYMS = 10;\nexport const MAX_SYNONYM_LENGTH = 100;\n"],"mappings":"AAAO,MAAM,6BAA6B;AACnC,MAAM,2BAA2B;AACjC,MAAM,gCAAgC;AACtC,MAAM,0BAA0B;AAChC,MAAM,uBAAuB;AAC7B,MAAM,eAAe;AACrB,MAAM,qBAAqB;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const LINK_SUGGESTIONS_ENDPOINT_PATH = "/seo/link-suggestions";
|
|
2
|
+
export declare const MAX_LINK_SUGGESTIONS = 10;
|
|
3
|
+
export declare const LINK_SNIPPET_RADIUS = 60;
|
|
4
|
+
export declare const MAX_LINK_TEXT_CHARS = 100000;
|
|
5
|
+
export declare const MAX_LINKED_HREFS = 500;
|
|
6
|
+
export declare const MAX_LINKED_DOCS = 500;
|
|
7
|
+
export declare const MAX_LINKED_HREF_LENGTH = 2048;
|
|
8
|
+
export declare const LINK_RESOLVE_BATCH_SIZE: number;
|
|
9
|
+
export declare const MAX_RESOLVED_LINK_CANDIDATES = 300;
|
|
10
|
+
export declare const LINK_SOURCE_PAGE_SIZE = 500;
|
|
11
|
+
//# sourceMappingURL=links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../../src/constants/links.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,8BAA8B,0BAA0B,CAAC;AACtE,eAAO,MAAM,oBAAoB,KAAK,CAAC;AACvC,eAAO,MAAM,mBAAmB,KAAK,CAAC;AACtC,eAAO,MAAM,mBAAmB,SAAU,CAAC;AAC3C,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,eAAO,MAAM,eAAe,MAAM,CAAC;AACnC,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,uBAAuB,QAA2B,CAAC;AAChE,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAChD,eAAO,MAAM,qBAAqB,MAAM,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const LINK_SUGGESTIONS_ENDPOINT_PATH = "/seo/link-suggestions";
|
|
2
|
+
const MAX_LINK_SUGGESTIONS = 10;
|
|
3
|
+
const LINK_SNIPPET_RADIUS = 60;
|
|
4
|
+
const MAX_LINK_TEXT_CHARS = 1e5;
|
|
5
|
+
const MAX_LINKED_HREFS = 500;
|
|
6
|
+
const MAX_LINKED_DOCS = 500;
|
|
7
|
+
const MAX_LINKED_HREF_LENGTH = 2048;
|
|
8
|
+
const LINK_RESOLVE_BATCH_SIZE = MAX_LINK_SUGGESTIONS * 2;
|
|
9
|
+
const MAX_RESOLVED_LINK_CANDIDATES = 300;
|
|
10
|
+
const LINK_SOURCE_PAGE_SIZE = 500;
|
|
11
|
+
export {
|
|
12
|
+
LINK_RESOLVE_BATCH_SIZE,
|
|
13
|
+
LINK_SNIPPET_RADIUS,
|
|
14
|
+
LINK_SOURCE_PAGE_SIZE,
|
|
15
|
+
LINK_SUGGESTIONS_ENDPOINT_PATH,
|
|
16
|
+
MAX_LINKED_DOCS,
|
|
17
|
+
MAX_LINKED_HREFS,
|
|
18
|
+
MAX_LINKED_HREF_LENGTH,
|
|
19
|
+
MAX_LINK_SUGGESTIONS,
|
|
20
|
+
MAX_LINK_TEXT_CHARS,
|
|
21
|
+
MAX_RESOLVED_LINK_CANDIDATES
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/constants/links.ts"],"sourcesContent":["export const LINK_SUGGESTIONS_ENDPOINT_PATH = \"/seo/link-suggestions\";\nexport const MAX_LINK_SUGGESTIONS = 10;\nexport const LINK_SNIPPET_RADIUS = 60;\nexport const MAX_LINK_TEXT_CHARS = 100_000;\nexport const MAX_LINKED_HREFS = 500;\nexport const MAX_LINKED_DOCS = 500;\nexport const MAX_LINKED_HREF_LENGTH = 2048;\nexport const LINK_RESOLVE_BATCH_SIZE = MAX_LINK_SUGGESTIONS * 2;\nexport const MAX_RESOLVED_LINK_CANDIDATES = 300;\nexport const LINK_SOURCE_PAGE_SIZE = 500;\n"],"mappings":"AAAO,MAAM,iCAAiC;AACvC,MAAM,uBAAuB;AAC7B,MAAM,sBAAsB;AAC5B,MAAM,sBAAsB;AAC5B,MAAM,mBAAmB;AACzB,MAAM,kBAAkB;AACxB,MAAM,yBAAyB;AAC/B,MAAM,0BAA0B,uBAAuB;AACvD,MAAM,+BAA+B;AACrC,MAAM,wBAAwB;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-docs.d.ts","sourceRoot":"","sources":["../../../src/content/resolve/resolve-docs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"resolve-docs.d.ts","sourceRoot":"","sources":["../../../src/content/resolve/resolve-docs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AA+C7D,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,GAAG,SAAS,EAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,GACzB,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,OAAO,CAAC,QAAQ,CAAC,CAc5C"}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
return `${collection}:${id}`;
|
|
3
|
-
}
|
|
1
|
+
import { docTargetKey } from "../../keyphrases/docTarget";
|
|
4
2
|
async function fetchQuery(apiRoute, query, locale) {
|
|
5
3
|
const ids = [...new Set(query.ids.map(String))];
|
|
6
4
|
if (ids.length === 0)
|
|
@@ -23,7 +21,7 @@ async function fetchQuery(apiRoute, query, locale) {
|
|
|
23
21
|
const body = await res.json();
|
|
24
22
|
return (body.docs ?? []).filter(
|
|
25
23
|
(d) => typeof d.id === "string" || typeof d.id === "number"
|
|
26
|
-
).map((d) => [
|
|
24
|
+
).map((d) => [docTargetKey(query.collection, d.id), d]);
|
|
27
25
|
} catch {
|
|
28
26
|
return [];
|
|
29
27
|
}
|
|
@@ -38,7 +36,7 @@ function createResolveDocs(apiRoute, locale) {
|
|
|
38
36
|
store.set(k, doc);
|
|
39
37
|
}
|
|
40
38
|
return {
|
|
41
|
-
get: (collection, id) => store.get(
|
|
39
|
+
get: (collection, id) => store.get(docTargetKey(collection, id))
|
|
42
40
|
};
|
|
43
41
|
};
|
|
44
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/content/resolve/resolve-docs.ts"],"sourcesContent":["import type { DocQuery, DocStore } from \"../../types/config\";\n\ntype Doc = Record<string, unknown>;\n\ninterface FindResponse {\n docs?: Array<Doc & { id?: unknown }>;\n}\n\
|
|
1
|
+
{"version":3,"sources":["../../../src/content/resolve/resolve-docs.ts"],"sourcesContent":["import type { DocQuery, DocStore } from \"../../types/config\";\nimport { docTargetKey } from \"../../keyphrases/docTarget\";\n\ntype Doc = Record<string, unknown>;\n\ninterface FindResponse {\n docs?: Array<Doc & { id?: unknown }>;\n}\n\nasync function fetchQuery(\n apiRoute: string,\n query: DocQuery,\n locale: string | undefined\n): Promise<Array<[string, Doc]>> {\n const ids = [...new Set(query.ids.map(String))];\n if (ids.length === 0) return [];\n\n const params = new URLSearchParams({\n depth: String(query.depth ?? 0),\n limit: String(ids.length),\n });\n\n if (locale) params.set(\"locale\", locale);\n\n ids.forEach((id, i) => params.set(`where[id][in][${i}]`, id));\n\n for (const field of query.select ?? []) params.set(`select[${field}]`, \"true\");\n\n try {\n const res = await fetch(`${apiRoute}/${query.collection}?${params.toString()}`, {\n credentials: \"include\",\n });\n if (!res.ok) return [];\n\n const body = (await res.json()) as FindResponse;\n\n return (body.docs ?? [])\n .filter(\n (d): d is Doc & { id: string | number } =>\n typeof d.id === \"string\" || typeof d.id === \"number\"\n )\n .map((d) => [docTargetKey(query.collection, d.id), d] as [string, Doc]);\n } catch {\n return [];\n }\n}\n\nexport function createResolveDocs(\n apiRoute: string | undefined,\n locale: string | undefined\n): (queries: DocQuery[]) => Promise<DocStore> {\n return async function resolveDocs(queries: DocQuery[]): Promise<DocStore> {\n const store = new Map<string, Doc>();\n\n if (apiRoute) {\n const results = await Promise.all(queries.map((q) => fetchQuery(apiRoute, q, locale)));\n\n for (const entries of results) for (const [k, doc] of entries) store.set(k, doc);\n }\n\n return {\n get: (collection, id) => store.get(docTargetKey(collection, id)),\n };\n };\n}\n"],"mappings":"AACA,SAAS,oBAAoB;AAQ7B,eAAe,WACb,UACA,OACA,QAC+B;AAC/B,QAAM,MAAM,CAAC,GAAG,IAAI,IAAI,MAAM,IAAI,IAAI,MAAM,CAAC,CAAC;AAC9C,MAAI,IAAI,WAAW;AAAG,WAAO,CAAC;AAE9B,QAAM,SAAS,IAAI,gBAAgB;AAAA,IACjC,OAAO,OAAO,MAAM,SAAS,CAAC;AAAA,IAC9B,OAAO,OAAO,IAAI,MAAM;AAAA,EAC1B,CAAC;AAED,MAAI;AAAQ,WAAO,IAAI,UAAU,MAAM;AAEvC,MAAI,QAAQ,CAAC,IAAI,MAAM,OAAO,IAAI,iBAAiB,CAAC,KAAK,EAAE,CAAC;AAE5D,aAAW,SAAS,MAAM,UAAU,CAAC;AAAG,WAAO,IAAI,UAAU,KAAK,KAAK,MAAM;AAE7E,MAAI;AACF,UAAM,MAAM,MAAM,MAAM,GAAG,QAAQ,IAAI,MAAM,UAAU,IAAI,OAAO,SAAS,CAAC,IAAI;AAAA,MAC9E,aAAa;AAAA,IACf,CAAC;AACD,QAAI,CAAC,IAAI;AAAI,aAAO,CAAC;AAErB,UAAM,OAAQ,MAAM,IAAI,KAAK;AAE7B,YAAQ,KAAK,QAAQ,CAAC,GACnB;AAAA,MACC,CAAC,MACC,OAAO,EAAE,OAAO,YAAY,OAAO,EAAE,OAAO;AAAA,IAChD,EACC,IAAI,CAAC,MAAM,CAAC,aAAa,MAAM,YAAY,EAAE,EAAE,GAAG,CAAC,CAAkB;AAAA,EAC1E,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;AAEO,SAAS,kBACd,UACA,QAC4C;AAC5C,SAAO,eAAe,YAAY,SAAwC;AACxE,UAAM,QAAQ,oBAAI,IAAiB;AAEnC,QAAI,UAAU;AACZ,YAAM,UAAU,MAAM,QAAQ,IAAI,QAAQ,IAAI,CAAC,MAAM,WAAW,UAAU,GAAG,MAAM,CAAC,CAAC;AAErF,iBAAW,WAAW;AAAS,mBAAW,CAAC,GAAG,GAAG,KAAK;AAAS,gBAAM,IAAI,GAAG,GAAG;AAAA,IACjF;AAEA,WAAO;AAAA,MACL,KAAK,CAAC,YAAY,OAAO,MAAM,IAAI,aAAa,YAAY,EAAE,CAAC;AAAA,IACjE;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { seoPlugin } from "./plugin";
|
|
2
2
|
export { seoTextField } from "./fields/seoTextField";
|
|
3
3
|
export type { SeoTextFieldOptions } from "./fields/seoTextField";
|
|
4
|
-
export type { ContentExtractor, SeoPluginConfig, SeoCollectionConfig, SeoFieldPaths, SeoSiteConfig, SeoGenerationConfig, } from "./types/config";
|
|
4
|
+
export type { ContentExtractor, SeoPluginConfig, SeoCollectionConfig, SeoFieldPaths, SeoSiteConfig, SeoGenerationConfig, ResolveUrl, ResolveUrlArgs, } from "./types/config";
|
|
5
5
|
export type { MessageKey, Translations } from "./translations/types";
|
|
6
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,YAAY,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,YAAY,EACV,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,cAAc,GACf,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { seoPlugin } from \"./plugin\";\nexport { seoTextField } from \"./fields/seoTextField\";\nexport type { SeoTextFieldOptions } from \"./fields/seoTextField\";\nexport type {\n ContentExtractor,\n SeoPluginConfig,\n SeoCollectionConfig,\n SeoFieldPaths,\n SeoSiteConfig,\n SeoGenerationConfig,\n} from \"./types/config\";\nexport type { MessageKey, Translations } from \"./translations/types\";\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { seoPlugin } from \"./plugin\";\nexport { seoTextField } from \"./fields/seoTextField\";\nexport type { SeoTextFieldOptions } from \"./fields/seoTextField\";\nexport type {\n ContentExtractor,\n SeoPluginConfig,\n SeoCollectionConfig,\n SeoFieldPaths,\n SeoSiteConfig,\n SeoGenerationConfig,\n ResolveUrl,\n ResolveUrlArgs,\n} from \"./types/config\";\nexport type { MessageKey, Translations } from \"./translations/types\";\n"],"mappings":"AAAA,SAAS,iBAAiB;AAC1B,SAAS,oBAAoB;","names":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export interface DocTarget {
|
|
2
|
+
collection: string;
|
|
3
|
+
docId: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function docTargetKey(collection: string, id: string | number): string;
|
|
6
|
+
export declare function readDocId(value: unknown): string | null;
|
|
7
|
+
//# sourceMappingURL=docTarget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docTarget.d.ts","sourceRoot":"","sources":["../../src/keyphrases/docTarget.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAE5E;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAKvD"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function docTargetKey(collection, id) {
|
|
2
|
+
return `${collection}:${id}`;
|
|
3
|
+
}
|
|
4
|
+
function readDocId(value) {
|
|
5
|
+
if (typeof value === "number" && Number.isFinite(value))
|
|
6
|
+
return String(value);
|
|
7
|
+
if (typeof value === "string" && value.trim())
|
|
8
|
+
return value.trim();
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
docTargetKey,
|
|
13
|
+
readDocId
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=docTarget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/keyphrases/docTarget.ts"],"sourcesContent":["export interface DocTarget {\n collection: string;\n docId: string;\n}\n\nexport function docTargetKey(collection: string, id: string | number): string {\n return `${collection}:${id}`;\n}\n\nexport function readDocId(value: unknown): string | null {\n if (typeof value === \"number\" && Number.isFinite(value)) return String(value);\n if (typeof value === \"string\" && value.trim()) return value.trim();\n\n return null;\n}\n"],"mappings":"AAKO,SAAS,aAAa,YAAoB,IAA6B;AAC5E,SAAO,GAAG,UAAU,IAAI,EAAE;AAC5B;AAEO,SAAS,UAAU,OAA+B;AACvD,MAAI,OAAO,UAAU,YAAY,OAAO,SAAS,KAAK;AAAG,WAAO,OAAO,KAAK;AAC5E,MAAI,OAAO,UAAU,YAAY,MAAM,KAAK;AAAG,WAAO,MAAM,KAAK;AAEjE,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stored.d.ts","sourceRoot":"","sources":["../../src/keyphrases/stored.ts"],"names":[],"mappings":"AAOA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAmBD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,EAAE,CAU1E"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MAX_KEYPHRASES,
|
|
3
|
+
MAX_KEYPHRASE_LENGTH,
|
|
4
|
+
MAX_SYNONYMS,
|
|
5
|
+
MAX_SYNONYM_LENGTH
|
|
6
|
+
} from "../constants";
|
|
7
|
+
function hasText(value) {
|
|
8
|
+
if (typeof value !== "object" || value === null)
|
|
9
|
+
return false;
|
|
10
|
+
const { text } = value;
|
|
11
|
+
return typeof text === "string" && text.trim() !== "";
|
|
12
|
+
}
|
|
13
|
+
function sanitizeSynonyms(input) {
|
|
14
|
+
if (!Array.isArray(input))
|
|
15
|
+
return [];
|
|
16
|
+
return input.filter((s) => typeof s === "string").slice(0, MAX_SYNONYMS).map((s) => s.slice(0, MAX_SYNONYM_LENGTH));
|
|
17
|
+
}
|
|
18
|
+
function sanitizeStoredKeyphrases(input) {
|
|
19
|
+
if (!Array.isArray(input))
|
|
20
|
+
return [];
|
|
21
|
+
return input.filter(hasText).slice(0, MAX_KEYPHRASES).map((entry) => ({
|
|
22
|
+
text: entry.text.trim().slice(0, MAX_KEYPHRASE_LENGTH),
|
|
23
|
+
synonyms: sanitizeSynonyms(entry.synonyms)
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
sanitizeStoredKeyphrases
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=stored.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/keyphrases/stored.ts"],"sourcesContent":["import {\n MAX_KEYPHRASES,\n MAX_KEYPHRASE_LENGTH,\n MAX_SYNONYMS,\n MAX_SYNONYM_LENGTH,\n} from \"../constants\";\n\nexport interface StoredKeyphrase {\n text: string;\n synonyms: string[];\n}\n\nfunction hasText(value: unknown): value is { text: string; synonyms?: unknown } {\n if (typeof value !== \"object\" || value === null) return false;\n\n const { text } = value as { text?: unknown };\n\n return typeof text === \"string\" && text.trim() !== \"\";\n}\n\nfunction sanitizeSynonyms(input: unknown): string[] {\n if (!Array.isArray(input)) return [];\n\n return input\n .filter((s): s is string => typeof s === \"string\")\n .slice(0, MAX_SYNONYMS)\n .map((s) => s.slice(0, MAX_SYNONYM_LENGTH));\n}\n\nexport function sanitizeStoredKeyphrases(input: unknown): StoredKeyphrase[] {\n if (!Array.isArray(input)) return [];\n\n return input\n .filter(hasText)\n .slice(0, MAX_KEYPHRASES)\n .map((entry) => ({\n text: entry.text.trim().slice(0, MAX_KEYPHRASE_LENGTH),\n synonyms: sanitizeSynonyms(entry.synonyms),\n }));\n}\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAOP,SAAS,QAAQ,OAA+D;AAC9E,MAAI,OAAO,UAAU,YAAY,UAAU;AAAM,WAAO;AAExD,QAAM,EAAE,KAAK,IAAI;AAEjB,SAAO,OAAO,SAAS,YAAY,KAAK,KAAK,MAAM;AACrD;AAEA,SAAS,iBAAiB,OAA0B;AAClD,MAAI,CAAC,MAAM,QAAQ,KAAK;AAAG,WAAO,CAAC;AAEnC,SAAO,MACJ,OAAO,CAAC,MAAmB,OAAO,MAAM,QAAQ,EAChD,MAAM,GAAG,YAAY,EACrB,IAAI,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAAC;AAC9C;AAEO,SAAS,yBAAyB,OAAmC;AAC1E,MAAI,CAAC,MAAM,QAAQ,KAAK;AAAG,WAAO,CAAC;AAEnC,SAAO,MACJ,OAAO,OAAO,EACd,MAAM,GAAG,cAAc,EACvB,IAAI,CAAC,WAAW;AAAA,IACf,MAAM,MAAM,KAAK,KAAK,EAAE,MAAM,GAAG,oBAAoB;AAAA,IACrD,UAAU,iBAAiB,MAAM,QAAQ;AAAA,EAC3C,EAAE;AACN;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface WordToken {
|
|
2
|
+
word: string;
|
|
3
|
+
start: number;
|
|
4
|
+
end: number;
|
|
5
|
+
}
|
|
6
|
+
export declare function foldText(value: string): string;
|
|
7
|
+
export declare function tokenizeWords(text: string): WordToken[];
|
|
8
|
+
export declare function foldedWords(text: string): string[];
|
|
9
|
+
export declare function canonicalIntent(phrase: string): string;
|
|
10
|
+
//# sourceMappingURL=text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../../src/keyphrases/text.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAUD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAM9C;AAqBD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,EAAE,CAEvD;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAIlD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEtD"}
|