@sanity/assist
6.1.106.1.11
dist/index.js~
dist/index.jsModified+22−17
Index: package/dist/index.js
===================================================================
--- package/dist/index.js
+++ package/dist/index.js
@@ -327,9 +327,9 @@
function isSchemaAssistEnabled(type) {
return !type.options?.aiAssist?.exclude;
}
function isAssistSupported(type) {
- return !isSchemaAssistEnabled(type) || isDisabled(type) ? !1 : type.jsonType === "array" ? !type.of.every((t) => isDisabled(t)) : type.jsonType === "object" ? !type.fields.every((field) => isDisabled(field.type)) || isType(type, "image") : !0;
+ return !isSchemaAssistEnabled(type) || isDisabled(type) ? !1 : type.jsonType === "array" ? !type.of.every((t) => isDisabled(t)) : type.jsonType !== "object" || !type.fields.every((field) => isDisabled(field.type)) || isType(type, "image");
}
function isDisabled(type) {
return !isSchemaAssistEnabled(type) || isUnsupportedType(type);
}
@@ -1179,18 +1179,18 @@
displayName: "IconDisc",
componentId: "sc-6srsjv-2"
})`background:var(--ai-avatar-disc-color);color:white;width:21px;height:21px;display:flex;align-items:center;justify-content:center;border-radius:10.5px;position:absolute;top:2px;left:2px;`;
function AssistAvatar(props) {
- let { state = "present" } = props, scheme = useColorSchemeValue();
+ let { state = "present" } = props, scheme = useColorSchemeValue(), style = useMemo(() => scheme === "dark" ? {
+ "--ai-avatar-stroke-color": purple[400].hex,
+ "--ai-avatar-disc-color": purple[600].hex
+ } : {
+ "--ai-avatar-stroke-color": purple[500].hex,
+ "--ai-avatar-disc-color": purple[600].hex
+ }, [scheme]);
return /* @__PURE__ */ jsxs(Root, {
"data-state": state,
- style: useMemo(() => scheme === "dark" ? {
- "--ai-avatar-stroke-color": purple[400].hex,
- "--ai-avatar-disc-color": purple[600].hex
- } : {
- "--ai-avatar-stroke-color": purple[500].hex,
- "--ai-avatar-disc-color": purple[600].hex
- }, [scheme]),
+ style,
children: [/* @__PURE__ */ jsx(Outline, {
width: "25",
height: "25",
viewBox: "0 0 25 25",
@@ -1772,9 +1772,9 @@
} else t1 = $[8];
let currentField = t1, t2;
if ($[11] !== fieldRefs || $[12] !== filter) {
let t3;
- $[14] === filter ? t3 = $[15] : (t3 = (field) => filter ? filter(field) : !0, $[14] = filter, $[15] = t3), t2 = fieldRefs.filter(t3).filter(_temp$8).map(_temp2$4), $[11] = fieldRefs, $[12] = filter, $[13] = t2;
+ $[14] === filter ? t3 = $[15] : (t3 = (field) => !filter || filter(field), $[14] = filter, $[15] = t3), t2 = fieldRefs.filter(t3).filter(_temp$8).map(_temp2$4), $[11] = fieldRefs, $[12] = filter, $[13] = t2;
} else t2 = $[13];
let autocompleteOptions = t2, renderOption = _temp3$2, renderValue = _temp4$1, filterOption = _temp5, t3 = currentField ? currentField.icon : SearchIcon, t4 = currentField?.key, t5;
return $[16] !== autocompleteOptions || $[17] !== id || $[18] !== onSelect || $[19] !== t3 || $[20] !== t4 ? (t5 = /* @__PURE__ */ jsx(Autocomplete, {
fontSize: 1,
@@ -2614,9 +2614,9 @@
if (!select || !document) return {};
let selection = select || {}, selectedValue = {};
for (let [key, path] of Object.entries(selection)) {
let value = get(document, path);
- Array.isArray(value) && (value = value.filter((item) => typeof item == "object" ? item?._type !== "reference" || "_ref" in item : !0)), selectedValue[key] = value;
+ Array.isArray(value) && (value = value.filter((item) => typeof item != "object" || item?._type !== "reference" || "_ref" in item)), selectedValue[key] = value;
}
return selectedValue;
}, toFieldLanguagesKeyPrefix = "sanityStudio:assist:field-languages:from:";
function getPreferredToFieldLanguages(fromLanguageId) {
@@ -2758,12 +2758,15 @@
if (setFromLanguage(from), !document || !documentSchema || !params || !languages_0) {
setFieldLanguageMaps(void 0);
return;
}
- let preferred = getPreferredToFieldLanguages(from.id), allToLanguages = languages_0.filter((l) => l.id !== from?.id);
- setToLanguages(allToLanguages.filter((l_0) => !preferred.length || preferred.includes(l_0.id)));
+ let preferred = getPreferredToFieldLanguages(from.id), allToLanguages = languages_0.filter((l) => l.id !== from?.id), filteredToLanguages = allToLanguages.filter((l_0) => !preferred.length || preferred.includes(l_0.id));
+ setToLanguages(filteredToLanguages);
let fromId = from?.id, allToIds = allToLanguages?.map(_temp$4) ?? [], docMembers = getDocumentMembersFlat(document, documentSchema, config?.maxPathDepth);
- fromId && allToIds?.length ? setFieldLanguageMaps(getFieldLanguageMap(documentSchema, docMembers, fromId, allToIds.filter((toId) => fromId !== toId), config?.translationOutputs ?? defaultLanguageOutputs)) : setFieldLanguageMaps(void 0);
+ if (fromId && allToIds?.length) {
+ let transMap = getFieldLanguageMap(documentSchema, docMembers, fromId, allToIds.filter((toId) => fromId !== toId), config?.translationOutputs ?? defaultLanguageOutputs);
+ setFieldLanguageMaps(transMap);
+ } else setFieldLanguageMaps(void 0);
}, $[3] = config?.maxPathDepth, $[4] = config?.translationOutputs, $[5] = t3) : t3 = $[5];
let selectFromLanguage = t3, t4;
$[6] === fromLanguage ? t4 = $[7] : (t4 = (toggledLang, toLanguages_0, languages_1) => {
if (!languages_1 || !fromLanguage) return;
@@ -3081,9 +3084,11 @@
let t3;
$[5] !== getInstructStatus || $[6] !== initInstruct ? (t3 = async () => {
setError(void 0);
try {
- await initInstruct(), setStatus(await getInstructStatus());
+ await initInstruct();
+ let status_0 = await getInstructStatus();
+ setStatus(status_0);
} catch (t4) {
let e_0 = t4;
console.error("Failed to init ai assistance", e_0), setError(e_0);
}
@@ -3648,9 +3653,9 @@
runInstructionsGroup,
translateAction,
...customActions,
assistSupported && manageInstructionsItem
- ].filter((c) => !!c).filter((c) => c.type === "group" ? c.children.length : !0),
+ ].filter((c) => !!c).filter((c) => c.type !== "group" || c.children.length),
expanded: !1,
renderAsButton: !0,
hidden: !assistSupported && !imageCaptionAction && !translateAction && !imageGenAction
}), [
@@ -4985,9 +4990,9 @@
}
/** @internal */
const listenQuery = (client, query, params = {}, options = {}) => {
let fetchQuery = typeof query == "string" ? query : query.fetch, listenerQuery = typeof query == "string" ? query : query.listen, fetchOnce$ = fetch(client, fetchQuery, params, options), [welcome$, mutationAndReconnect$] = partition(listen(client, listenerQuery, params, options).pipe(mergeMap((ev, i) => i === 0 && !isWelcomeEvent(ev) ? throwError(/* @__PURE__ */ Error(ev.type === "reconnect" ? "Could not establish EventSource connection" : `Received unexpected type of first event "${ev.type}"`)) : of(ev)), share()), isWelcomeEvent);
- return merge(welcome$.pipe(take(1)), mutationAndReconnect$.pipe(filter((event) => !options.transitions || event.type !== "mutation" ? !0 : options.transitions.includes(event.transition)), switchMap((event) => merge(of(event), of(event).pipe(delay(options.throttleTime || 1e3)))))).pipe(exhaustMapToWithTrailing(fetchOnce$));
+ return merge(welcome$.pipe(take(1)), mutationAndReconnect$.pipe(filter((event) => !options.transitions || event.type !== "mutation" || options.transitions.includes(event.transition)), switchMap((event) => merge(of(event), of(event).pipe(delay(options.throttleTime || 1e3)))))).pipe(exhaustMapToWithTrailing(fetchOnce$));
}, DEFAULT_PARAMS = {}, DEFAULT_OPTIONS = { apiVersion: "v2022-05-09" };
function useListeningQuery(query, t0, t1) {
let $ = c(11), params = t0 === void 0 ? DEFAULT_PARAMS : t0, options = t1 === void 0 ? DEFAULT_OPTIONS : t1, [loading, setLoading] = useState(!0), [error, setError] = useState(!1), [data, setData] = useState(null), subscription = useRef(null), t2;
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t2 = { apiVersion: "v2022-05-09" }, $[0] = t2) : t2 = $[0];