@sanity/block-insert-picker
1.0.71.0.8
dist/index.js~
dist/index.jsModified+37−37
Index: package/dist/index.js
===================================================================
--- package/dist/index.js
+++ package/dist/index.js
@@ -265,18 +265,18 @@
$[0] = arrayTypeName, $[1] = memberSchemaTypes, $[2] = schema, $[3] = t0;
} else t0 = $[3];
return t0;
}
+function _temp$1(member) {
+ return member.jsonType === "object" && !isTextBlockMember(member);
+}
/**
* Whether a member resolves to the built-in text block: walk the compiled
* `type` chain to its root and compare the root's name — the same algorithm
* Studio's schema bridge uses to bucketize `of`. A literal `name === 'block'`
* check would miss aliased text blocks (`{name: 'myBlock', type: 'block'}`)
* and wrongly offer them as object inserts.
*/
-function _temp$1(member) {
- return member.jsonType === "object" && !isTextBlockMember(member);
-}
function isTextBlockMember(memberType) {
let current = memberType;
for (; current.type && typeof current.type == "object" && "name" in current.type;) current = current.type;
return current.name === "block";
@@ -738,10 +738,10 @@
editor
});
return;
}
- let blockType = chosen.action.blockType, initialValue, schemaType_0 = memberTypeFor(itemsContext, schema, blockType);
- schemaType_0 && (initialValue = await resolveInitialValueForType(schemaType_0, {}) ?? void 0);
+ let blockType = chosen.action.blockType, initialValue, schemaType = memberTypeFor(itemsContext, schema, blockType);
+ schemaType && (initialValue = await resolveInitialValueForType(schemaType, {}) ?? void 0);
let snapshot = editor.getSnapshot();
if (!snapshot.context.value.some((b) => b._key === current.anchorBlockKey)) {
toast.push({
closable: !0,
@@ -778,16 +778,16 @@
});
} finally {
insertInFlightRef.current = !1;
}
- }, selectItemAtIndex = (idx_0) => {
- let current_0 = stateRef.current;
- current_0.mode !== "closed" && insertItemAtIndex(current_0, idx_0);
+ }, selectItemAtIndex = (idx) => {
+ let current = stateRef.current;
+ current.mode !== "closed" && insertItemAtIndex(current, idx);
}, handleIntent = (intent) => {
if (intent.type === "navigate") {
- let current_1 = stateRef.current;
- if (current_1.mode === "closed") return;
- let lastIndex = filtered.length - 1, base = Math.max(0, Math.min(lastIndex, current_1.highlightedIndex)), next = Math.max(0, Math.min(lastIndex, base + intent.delta));
+ let current = stateRef.current;
+ if (current.mode === "closed") return;
+ let lastIndex = filtered.length - 1, base = Math.max(0, Math.min(lastIndex, current.highlightedIndex)), next = Math.max(0, Math.min(lastIndex, base + intent.delta));
dispatch({
index: next,
type: "setHighlightedIndex"
});
@@ -796,19 +796,19 @@
if (intent.type !== "select") {
dispatch(intent);
return;
}
- let current_2 = stateRef.current;
- current_2.mode !== "closed" && insertItemAtIndex(current_2, current_2.highlightedIndex);
+ let current = stateRef.current;
+ current.mode !== "closed" && insertItemAtIndex(current, current.highlightedIndex);
}, handleIntentRef = useRef(handleIntent);
useLayoutEffect(() => {
handleIntentRef.current = handleIntent;
}), useEffect(() => {
if (!hasItems) return;
let behavior = createPickerBehavior({
getState: () => stateRef.current,
isShortcutEnabled: () => shortcutRef.current,
- onIntent: (intent_0) => handleIntentRef.current(intent_0)
+ onIntent: (intent) => handleIntentRef.current(intent)
}), unregisterPicker = editor.registerBehavior({ behavior }), unregisterInsert = editor.registerBehavior({ behavior: createInsertBehavior() }), unregisterCleanup = editor.registerBehavior({ behavior: createCleanupQueryBehavior() });
return () => {
unregisterPicker(), unregisterInsert(), unregisterCleanup();
};
@@ -824,39 +824,39 @@
if (!open) {
setCursorRect(null);
return;
}
- let snapshot_0 = editor.getSnapshot(), rect = editor.dom.getSelectionRect(snapshot_0);
+ let snapshot = editor.getSnapshot(), rect = editor.dom.getSelectionRect(snapshot);
if (rect && (rect.x || rect.y || rect.width || rect.height)) {
setCursorRect(rect);
return;
}
- let blockRect = editor.dom.getStartBlockElement(snapshot_0)?.getBoundingClientRect();
+ let blockRect = editor.dom.getStartBlockElement(snapshot)?.getBoundingClientRect();
blockRect && setCursorRect(blockRect);
}, [editor, open]);
let popoverContentRef = useRef(null);
useEffect(() => {
if (!open) return;
let handlePointerDown = (event) => {
let target = event.target;
target instanceof Node && popoverContentRef.current?.contains(target) || dispatch({ type: "close" });
- }, editorElement = editor.dom.getEditorElement(), handleFocusOut = (event_0) => {
- let next_0 = event_0 instanceof FocusEvent ? event_0.relatedTarget : null;
- next_0 instanceof Node && (editorElement?.contains(next_0) || popoverContentRef.current?.contains(next_0)) || dispatch({ type: "close" });
+ }, editorElement = editor.dom.getEditorElement(), handleFocusOut = (event) => {
+ let next = event instanceof FocusEvent ? event.relatedTarget : null;
+ next instanceof Node && (editorElement?.contains(next) || popoverContentRef.current?.contains(next)) || dispatch({ type: "close" });
};
return document.addEventListener("pointerdown", handlePointerDown, !0), editorElement?.addEventListener("focusout", handleFocusOut), () => {
document.removeEventListener("pointerdown", handlePointerDown, !0), editorElement?.removeEventListener("focusout", handleFocusOut);
};
}, [editor, open]);
- let highlightedRowRef = useRef(null), lastPointerRef = useRef(null), highlightOnPointerMove = (idx_1, x, y) => {
+ let highlightedRowRef = useRef(null), lastPointerRef = useRef(null), highlightOnPointerMove = (idx, x, y) => {
let last = lastPointerRef.current;
if (lastPointerRef.current = {
x,
y
}, !last || last.x === x && last.y === y) return;
- let current_3 = stateRef.current;
- current_3.mode !== "closed" && idx_1 !== current_3.highlightedIndex && dispatch({
- index: idx_1,
+ let current = stateRef.current;
+ current.mode !== "closed" && idx !== current.highlightedIndex && dispatch({
+ index: idx,
type: "setHighlightedIndex"
});
};
useEffect(() => {
@@ -936,16 +936,16 @@
maxHeight: 320,
minHeight: 0,
overflowY: "auto"
},
- children: sections.map((section_0, sectionIndex) => {
- let sectionLabel = section_0.group ?? labels.ungroupedSection, sectionKey = section_0.group === null ? "ungrouped" : `group:${section_0.group}`, rows = section_0.items.map((item_0, rowIndex) => {
- let idx_2 = (sectionOffsets[sectionIndex] ?? 0) + rowIndex, Icon = item_0.icon, isHighlighted = idx_2 === highlightedIndex;
+ children: sections.map((section, sectionIndex) => {
+ let sectionLabel = section.group ?? labels.ungroupedSection, sectionKey = section.group === null ? "ungrouped" : `group:${section.group}`, rows = section.items.map((item, rowIndex) => {
+ let idx = (sectionOffsets[sectionIndex] ?? 0) + rowIndex, Icon = item.icon, isHighlighted = idx === highlightedIndex;
return /* @__PURE__ */ jsx(Card, {
"aria-selected": isHighlighted,
- id: optionId(String(idx_2)),
- onClick: () => selectItemAtIndex(idx_2),
- onMouseMove: (event_1) => highlightOnPointerMove(idx_2, event_1.clientX, event_1.clientY),
+ id: optionId(String(idx)),
+ onClick: () => selectItemAtIndex(idx),
+ onMouseMove: (event) => highlightOnPointerMove(idx, event.clientX, event.clientY),
padding: 2,
radius: 1,
ref: isHighlighted ? highlightedRowRef : void 0,
role: "option",
@@ -971,34 +971,34 @@
gap: 2,
children: [/* @__PURE__ */ jsx(Text, {
size: 1,
textOverflow: "ellipsis",
- children: item_0.title
- }), item_0.description ? /* @__PURE__ */ jsx(Text, {
+ children: item.title
+ }), item.description ? /* @__PURE__ */ jsx(Text, {
muted: !0,
size: 0,
textOverflow: "ellipsis",
- children: item_0.description
+ children: item.description
}) : null]
}),
- item_0.badge ? /* @__PURE__ */ jsx(Box, {
+ item.badge ? /* @__PURE__ */ jsx(Box, {
flex: "none",
children: /* @__PURE__ */ jsx(Text, {
muted: !0,
size: 0,
- children: item_0.badge
+ children: item.badge
})
}) : null,
- item_0.trigger ? /* @__PURE__ */ jsx(Box, {
+ item.trigger ? /* @__PURE__ */ jsx(Box, {
flex: "none",
children: /* @__PURE__ */ jsx(Hotkeys, {
fontSize: 0,
- keys: [item_0.trigger]
+ keys: [item.trigger]
})
}) : null
]
})
- }, `${item_0.id}-${idx_2}`);
+ }, `${item.id}-${idx}`);
});
return showGroupHeaders ? /* @__PURE__ */ jsxs(Box, {
"aria-label": sectionLabel,
paddingTop: sectionIndex === 0 ? 0 : 2,