Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@udecode/plate-combobox

Package Overview
Dependencies
Maintainers
2
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@udecode/plate-combobox - npm Package Compare versions

Comparing version 21.5.0 to 22.0.0

dist/hooks/useComboboxContent.d.ts

11

dist/combobox.store.d.ts
import { StateActions, StoreApi } from '@udecode/plate-common';
import { UseVirtualFloatingOptions } from '@udecode/plate-floating';
import { Range } from 'slate';
import { ComboboxOnSelectItem, NoData, TComboboxItem } from './types';
export declare type ComboboxStateById<TData = NoData> = {
export type ComboboxStateById<TData = NoData> = {
/**

@@ -41,4 +40,4 @@ * Combobox id.

};
export declare type ComboboxStoreById<TData = NoData> = StoreApi<string, ComboboxStateById<TData>, StateActions<ComboboxStateById<TData>>>;
export declare type ComboboxState<TData = NoData> = {
export type ComboboxStoreById<TData = NoData> = StoreApi<string, ComboboxStateById<TData>, StateActions<ComboboxStateById<TData>>>;
export type ComboboxState<TData = NoData> = {
/**

@@ -66,6 +65,2 @@ * Active id (combobox id which is opened).

/**
* Overrides `useFloating` options.
*/
floatingOptions: Partial<UseVirtualFloatingOptions>;
/**
* Range from the trigger to the cursor.

@@ -72,0 +67,0 @@ */

/**
* @file Automatically generated by barrelsby.
*/
export * from './useComboboxContent';
export * from './useComboboxControls';
export * from './useComboboxItem';
//# sourceMappingURL=index.d.ts.map

@@ -0,1 +1,2 @@

export type ComboboxControls = ReturnType<typeof useComboboxControls>;
export declare const useComboboxControls: () => {

@@ -2,0 +3,0 @@ closeMenu: () => void;

@@ -1,12 +0,10 @@

import { createStore, escapeRegExp, getPointBefore, getRange, getEditorString, isCollapsed, Hotkeys, createPluginFactory } from '@udecode/plate-common';
import { createStore, escapeRegExp, getPointBefore, getRange, getEditorString, isCollapsed, Hotkeys, createPluginFactory, usePlateEditorRef } from '@udecode/plate-common';
import { Range } from 'slate';
import { useMemo } from 'react';
import { useEffect, useMemo } from 'react';
import { useCombobox } from 'downshift';
const createComboboxStore = state => createStore(`combobox-${state.id}`)(state);
const comboboxStore = createStore('combobox')({
activeId: null,
byId: {},
floatingOptions: {},
highlightedIndex: 0,

@@ -63,3 +61,2 @@ items: [],

let end;
while (true) {

@@ -71,3 +68,2 @@ end = start;

const charText = getEditorString(editor, charRange);
if (!charText.match(searchPattern)) {

@@ -77,5 +73,5 @@ start = end;

}
} // Range from start to cursor
}
// Range from start to cursor
const range = start && getRange(editor, start, at);

@@ -86,5 +82,7 @@ const text = getEditorString(editor, range);

range,
textAfterTrigger: text.substring(trigger.length)
textAfterTrigger: text.slice(trigger.length)
};
}; // export const matchesTriggerAndPattern = (
};
// export const matchesTriggerAndPattern = (
// editor: TEditor<V>,

@@ -135,3 +133,2 @@ // { at, trigger, pattern }: { at: Point; trigger: string; pattern: string }

*/
const onChangeCombobox = editor => () => {

@@ -141,9 +138,6 @@ const byId = comboboxSelectors.byId();

let shouldClose = true;
for (const store of Object.values(byId)) {
var _store$get$controlled, _store$get, _store$get$searchPatt, _store$get2;
const id = store.get.id();
const controlled = (_store$get$controlled = (_store$get = store.get).controlled) === null || _store$get$controlled === void 0 ? void 0 : _store$get$controlled.call(_store$get);
if (controlled) {

@@ -159,11 +153,8 @@ // do not close controlled comboboxes

}
const {
selection
} = editor;
if (!selection || !isCollapsed(selection)) {
continue;
}
const trigger = store.get.trigger();

@@ -176,7 +167,5 @@ const searchPattern = (_store$get$searchPatt = (_store$get2 = store.get).searchPattern) === null || _store$get$searchPatt === void 0 ? void 0 : _store$get$searchPatt.call(_store$get2);

});
if (!isCursorAfterTrigger) {
continue;
}
const {

@@ -194,3 +183,2 @@ range,

}
if (shouldClose && comboboxSelectors.isOpen()) {

@@ -479,7 +467,5 @@ comboboxActions.reset();

const currentElementNode = getItemNodeFromIndex(baseIndex);
if (!currentElementNode || !currentElementNode.hasAttribute('disabled')) {
return baseIndex;
}
if (moveAmount > 0) {

@@ -498,7 +484,5 @@ for (let index = baseIndex + 1; index < itemCount; index++) {

}
if (circular) {
return moveAmount > 0 ? getNextNonDisabledIndex(1, 0, itemCount, getItemNodeFromIndex, false) : getNextNonDisabledIndex(-1, itemCount - 1, itemCount, getItemNodeFromIndex, false);
}
return -1;

@@ -518,3 +502,2 @@ };

*/
const getNextWrappingIndex = (moveAmount, baseIndex, itemCount, getItemNodeFromIndex, circular = true) => {

@@ -524,11 +507,9 @@ if (itemCount === 0) {

}
const itemsLastIndex = itemCount - 1;
const itemsLastIndex = itemCount - 1; // noinspection SuspiciousTypeOfGuard
// noinspection SuspiciousTypeOfGuard
if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
}
let newIndex = baseIndex + moveAmount;
if (newIndex < 0) {

@@ -539,9 +520,6 @@ newIndex = circular ? itemsLastIndex : 0;

}
const nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
if (nonDisabledNewIndex === -1) {
return baseIndex >= itemCount ? -1 : baseIndex;
}
return nonDisabledNewIndex;

@@ -557,3 +535,2 @@ };

*/
const onKeyDownCombobox = editor => event => {

@@ -570,3 +547,2 @@ const {

const onSelectItem = store.get.onSelectItem();
if (isHotkey('down', event)) {

@@ -578,3 +554,2 @@ event.preventDefault();

}
if (isHotkey('up', event)) {

@@ -586,3 +561,2 @@ event.preventDefault();

}
if (isHotkey('escape', event)) {

@@ -593,7 +567,5 @@ event.preventDefault();

}
if (Hotkeys.isTab(editor, event) || isHotkey('enter', event)) {
event.preventDefault();
event.stopPropagation();
if (filteredItems[highlightedIndex]) {

@@ -614,2 +586,41 @@ onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem(editor, filteredItems[highlightedIndex]);

const useComboboxContentState = ({
items,
combobox
}) => {
var _useComboboxSelectors, _activeComboboxStore$, _activeComboboxStore$2, _activeComboboxStore$3, _activeComboboxStore$4, _activeComboboxStore$5, _activeComboboxStore$6, _activeComboboxStore$7;
const targetRange = useComboboxSelectors.targetRange();
const activeComboboxStore = useActiveComboboxStore();
const text = (_useComboboxSelectors = useComboboxSelectors.text()) !== null && _useComboboxSelectors !== void 0 ? _useComboboxSelectors : '';
const storeItems = useComboboxSelectors.items();
const filter = (_activeComboboxStore$ = (_activeComboboxStore$2 = activeComboboxStore.use).filter) === null || _activeComboboxStore$ === void 0 ? void 0 : _activeComboboxStore$.call(_activeComboboxStore$2);
const sort = (_activeComboboxStore$3 = (_activeComboboxStore$4 = activeComboboxStore.use).sort) === null || _activeComboboxStore$3 === void 0 ? void 0 : _activeComboboxStore$3.call(_activeComboboxStore$4);
const maxSuggestions = (_activeComboboxStore$5 = (_activeComboboxStore$6 = (_activeComboboxStore$7 = activeComboboxStore.use).maxSuggestions) === null || _activeComboboxStore$6 === void 0 ? void 0 : _activeComboboxStore$6.call(_activeComboboxStore$7)) !== null && _activeComboboxStore$5 !== void 0 ? _activeComboboxStore$5 : storeItems.length;
// Update items
useEffect(() => {
items && comboboxActions.items(items);
}, [items]);
// Filter items
useEffect(() => {
comboboxActions.filteredItems(storeItems.filter(filter ? filter(text) : value => value.text.toLowerCase().startsWith(text.toLowerCase())).sort(sort === null || sort === void 0 ? void 0 : sort(text)).slice(0, maxSuggestions));
}, [filter, sort, storeItems, maxSuggestions, text]);
return {
combobox,
targetRange
};
};
const useComboboxContent = state => {
const menuProps = state.combobox ? state.combobox.getMenuProps({}, {
suppressRefError: true
}) : {
ref: null
};
return {
menuProps,
targetRange: state.targetRange
};
};
const useComboboxControls = () => {

@@ -647,3 +658,36 @@ const isOpen = useComboboxSelectors.isOpen();

export { KEY_COMBOBOX, comboboxActions, comboboxSelectors, comboboxStore, createComboboxPlugin, getComboboxStoreById, getNextNonDisabledIndex, getNextWrappingIndex, getTextFromTrigger, onChangeCombobox, onKeyDownCombobox, useActiveComboboxStore, useComboboxControls, useComboboxSelectors };
const useComboboxItem = ({
index,
item,
onRenderItem,
combobox
}) => {
var _useComboboxSelectors;
const editor = usePlateEditorRef();
const text = (_useComboboxSelectors = useComboboxSelectors.text()) !== null && _useComboboxSelectors !== void 0 ? _useComboboxSelectors : '';
const highlightedIndex = useComboboxSelectors.highlightedIndex();
const Item = onRenderItem ? onRenderItem({
search: text,
item: item
}) : item.text;
const highlighted = index === highlightedIndex;
return {
props: {
'data-highlighted': highlighted,
...combobox.getItemProps({
item,
index
}),
onMouseDown: e => {
var _getComboboxStoreById;
e.preventDefault();
const onSelectItem = (_getComboboxStoreById = getComboboxStoreById(comboboxSelectors.activeId())) === null || _getComboboxStoreById === void 0 ? void 0 : _getComboboxStoreById.get.onSelectItem();
onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem(editor, item);
},
children: Item
}
};
};
export { KEY_COMBOBOX, comboboxActions, comboboxSelectors, comboboxStore, createComboboxPlugin, getComboboxStoreById, getNextNonDisabledIndex, getNextWrappingIndex, getTextFromTrigger, onChangeCombobox, onKeyDownCombobox, useActiveComboboxStore, useComboboxContent, useComboboxContentState, useComboboxControls, useComboboxItem, useComboboxSelectors };
//# sourceMappingURL=index.es.js.map
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var plateCommon = require('@udecode/plate-common');

@@ -11,7 +9,5 @@ var slate = require('slate');

const createComboboxStore = state => plateCommon.createStore(`combobox-${state.id}`)(state);
const comboboxStore = plateCommon.createStore('combobox')({
activeId: null,
byId: {},
floatingOptions: {},
highlightedIndex: 0,

@@ -68,3 +64,2 @@ items: [],

let end;
while (true) {

@@ -76,3 +71,2 @@ end = start;

const charText = plateCommon.getEditorString(editor, charRange);
if (!charText.match(searchPattern)) {

@@ -82,5 +76,5 @@ start = end;

}
} // Range from start to cursor
}
// Range from start to cursor
const range = start && plateCommon.getRange(editor, start, at);

@@ -91,5 +85,7 @@ const text = plateCommon.getEditorString(editor, range);

range,
textAfterTrigger: text.substring(trigger.length)
textAfterTrigger: text.slice(trigger.length)
};
}; // export const matchesTriggerAndPattern = (
};
// export const matchesTriggerAndPattern = (
// editor: TEditor<V>,

@@ -140,3 +136,2 @@ // { at, trigger, pattern }: { at: Point; trigger: string; pattern: string }

*/
const onChangeCombobox = editor => () => {

@@ -146,9 +141,6 @@ const byId = comboboxSelectors.byId();

let shouldClose = true;
for (const store of Object.values(byId)) {
var _store$get$controlled, _store$get, _store$get$searchPatt, _store$get2;
const id = store.get.id();
const controlled = (_store$get$controlled = (_store$get = store.get).controlled) === null || _store$get$controlled === void 0 ? void 0 : _store$get$controlled.call(_store$get);
if (controlled) {

@@ -164,11 +156,8 @@ // do not close controlled comboboxes

}
const {
selection
} = editor;
if (!selection || !plateCommon.isCollapsed(selection)) {
continue;
}
const trigger = store.get.trigger();

@@ -181,7 +170,5 @@ const searchPattern = (_store$get$searchPatt = (_store$get2 = store.get).searchPattern) === null || _store$get$searchPatt === void 0 ? void 0 : _store$get$searchPatt.call(_store$get2);

});
if (!isCursorAfterTrigger) {
continue;
}
const {

@@ -199,3 +186,2 @@ range,

}
if (shouldClose && comboboxSelectors.isOpen()) {

@@ -484,7 +470,5 @@ comboboxActions.reset();

const currentElementNode = getItemNodeFromIndex(baseIndex);
if (!currentElementNode || !currentElementNode.hasAttribute('disabled')) {
return baseIndex;
}
if (moveAmount > 0) {

@@ -503,7 +487,5 @@ for (let index = baseIndex + 1; index < itemCount; index++) {

}
if (circular) {
return moveAmount > 0 ? getNextNonDisabledIndex(1, 0, itemCount, getItemNodeFromIndex, false) : getNextNonDisabledIndex(-1, itemCount - 1, itemCount, getItemNodeFromIndex, false);
}
return -1;

@@ -523,3 +505,2 @@ };

*/
const getNextWrappingIndex = (moveAmount, baseIndex, itemCount, getItemNodeFromIndex, circular = true) => {

@@ -529,11 +510,9 @@ if (itemCount === 0) {

}
const itemsLastIndex = itemCount - 1;
const itemsLastIndex = itemCount - 1; // noinspection SuspiciousTypeOfGuard
// noinspection SuspiciousTypeOfGuard
if (typeof baseIndex !== 'number' || baseIndex < 0 || baseIndex >= itemCount) {
baseIndex = moveAmount > 0 ? -1 : itemsLastIndex + 1;
}
let newIndex = baseIndex + moveAmount;
if (newIndex < 0) {

@@ -544,9 +523,6 @@ newIndex = circular ? itemsLastIndex : 0;

}
const nonDisabledNewIndex = getNextNonDisabledIndex(moveAmount, newIndex, itemCount, getItemNodeFromIndex, circular);
if (nonDisabledNewIndex === -1) {
return baseIndex >= itemCount ? -1 : baseIndex;
}
return nonDisabledNewIndex;

@@ -562,3 +538,2 @@ };

*/
const onKeyDownCombobox = editor => event => {

@@ -575,3 +550,2 @@ const {

const onSelectItem = store.get.onSelectItem();
if (isHotkey('down', event)) {

@@ -583,3 +557,2 @@ event.preventDefault();

}
if (isHotkey('up', event)) {

@@ -591,3 +564,2 @@ event.preventDefault();

}
if (isHotkey('escape', event)) {

@@ -598,7 +570,5 @@ event.preventDefault();

}
if (plateCommon.Hotkeys.isTab(editor, event) || isHotkey('enter', event)) {
event.preventDefault();
event.stopPropagation();
if (filteredItems[highlightedIndex]) {

@@ -619,2 +589,41 @@ onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem(editor, filteredItems[highlightedIndex]);

const useComboboxContentState = ({
items,
combobox
}) => {
var _useComboboxSelectors, _activeComboboxStore$, _activeComboboxStore$2, _activeComboboxStore$3, _activeComboboxStore$4, _activeComboboxStore$5, _activeComboboxStore$6, _activeComboboxStore$7;
const targetRange = useComboboxSelectors.targetRange();
const activeComboboxStore = useActiveComboboxStore();
const text = (_useComboboxSelectors = useComboboxSelectors.text()) !== null && _useComboboxSelectors !== void 0 ? _useComboboxSelectors : '';
const storeItems = useComboboxSelectors.items();
const filter = (_activeComboboxStore$ = (_activeComboboxStore$2 = activeComboboxStore.use).filter) === null || _activeComboboxStore$ === void 0 ? void 0 : _activeComboboxStore$.call(_activeComboboxStore$2);
const sort = (_activeComboboxStore$3 = (_activeComboboxStore$4 = activeComboboxStore.use).sort) === null || _activeComboboxStore$3 === void 0 ? void 0 : _activeComboboxStore$3.call(_activeComboboxStore$4);
const maxSuggestions = (_activeComboboxStore$5 = (_activeComboboxStore$6 = (_activeComboboxStore$7 = activeComboboxStore.use).maxSuggestions) === null || _activeComboboxStore$6 === void 0 ? void 0 : _activeComboboxStore$6.call(_activeComboboxStore$7)) !== null && _activeComboboxStore$5 !== void 0 ? _activeComboboxStore$5 : storeItems.length;
// Update items
react.useEffect(() => {
items && comboboxActions.items(items);
}, [items]);
// Filter items
react.useEffect(() => {
comboboxActions.filteredItems(storeItems.filter(filter ? filter(text) : value => value.text.toLowerCase().startsWith(text.toLowerCase())).sort(sort === null || sort === void 0 ? void 0 : sort(text)).slice(0, maxSuggestions));
}, [filter, sort, storeItems, maxSuggestions, text]);
return {
combobox,
targetRange
};
};
const useComboboxContent = state => {
const menuProps = state.combobox ? state.combobox.getMenuProps({}, {
suppressRefError: true
}) : {
ref: null
};
return {
menuProps,
targetRange: state.targetRange
};
};
const useComboboxControls = () => {

@@ -652,2 +661,35 @@ const isOpen = useComboboxSelectors.isOpen();

const useComboboxItem = ({
index,
item,
onRenderItem,
combobox
}) => {
var _useComboboxSelectors;
const editor = plateCommon.usePlateEditorRef();
const text = (_useComboboxSelectors = useComboboxSelectors.text()) !== null && _useComboboxSelectors !== void 0 ? _useComboboxSelectors : '';
const highlightedIndex = useComboboxSelectors.highlightedIndex();
const Item = onRenderItem ? onRenderItem({
search: text,
item: item
}) : item.text;
const highlighted = index === highlightedIndex;
return {
props: {
'data-highlighted': highlighted,
...combobox.getItemProps({
item,
index
}),
onMouseDown: e => {
var _getComboboxStoreById;
e.preventDefault();
const onSelectItem = (_getComboboxStoreById = getComboboxStoreById(comboboxSelectors.activeId())) === null || _getComboboxStoreById === void 0 ? void 0 : _getComboboxStoreById.get.onSelectItem();
onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem(editor, item);
},
children: Item
}
};
};
exports.KEY_COMBOBOX = KEY_COMBOBOX;

@@ -665,4 +707,7 @@ exports.comboboxActions = comboboxActions;

exports.useActiveComboboxStore = useActiveComboboxStore;
exports.useComboboxContent = useComboboxContent;
exports.useComboboxContentState = useComboboxContentState;
exports.useComboboxControls = useComboboxControls;
exports.useComboboxItem = useComboboxItem;
exports.useComboboxSelectors = useComboboxSelectors;
//# sourceMappingURL=index.js.map

@@ -23,6 +23,6 @@ import { PlateEditor, Value } from '@udecode/plate-common';

}
export declare type NoData = undefined;
export declare type Data = unknown;
export declare type TComboboxItem<TData = NoData> = TData extends NoData ? TComboboxItemBase : TComboboxItemWithData<TData>;
export declare type ComboboxOnSelectItem<TData> = <V extends Value>(editor: PlateEditor<V>, item: TComboboxItem<TData>) => any;
export type NoData = undefined;
export type Data = unknown;
export type TComboboxItem<TData = NoData> = TData extends NoData ? TComboboxItemBase : TComboboxItemWithData<TData>;
export type ComboboxOnSelectItem<TData> = <V extends Value>(editor: PlateEditor<V>, item: TComboboxItem<TData>) => any;
//# sourceMappingURL=ComboboxOnSelectItem.d.ts.map

@@ -5,2 +5,3 @@ /**

export * from './ComboboxOnSelectItem';
export * from './ComboboxProps';
//# sourceMappingURL=index.d.ts.map
{
"name": "@udecode/plate-combobox",
"version": "21.5.0",
"version": "22.0.0",
"description": "Combobox for Plate",
"license": "MIT",
"homepage": "https://plate.udecode.io",
"homepage": "https://platejs.org",
"repository": {
"type": "git",
"url": "https://github.com/udecode/plate.git",
"directory": "packages/editor/combobox"
"directory": "packages/combobox"
},

@@ -21,6 +21,16 @@ "bugs": {

"types": "dist/index.d.ts",
"scripts": {
"build": "yarn p:build",
"build:watch": "yarn p:build:watch",
"brl": "yarn p:brl",
"clean": "yarn p:clean",
"lint": "yarn p:lint",
"lint:fix": "yarn p:lint:fix",
"test": "yarn p:test",
"test:watch": "yarn p:test:watch",
"typecheck": "yarn p:typecheck"
},
"dependencies": {
"@udecode/plate-common": "21.5.0",
"@udecode/plate-floating": "21.5.0",
"downshift": "^6.1.7"
"@udecode/plate-common": "22.0.0",
"downshift": "^6.1.12"
},

@@ -32,3 +42,3 @@ "peerDependencies": {

"slate-history": ">=0.93.0",
"slate-react": ">=0.94.0"
"slate-react": ">=0.95.0"
},

@@ -35,0 +45,0 @@ "keywords": [

@@ -7,11 +7,7 @@ # Plate combobox

Check out [Playground](https://plate.udecode.io/docs/playground) and
[Combobox](https://plate.udecode.io/docs/plugins/combobox).
Check out [Playground](https://platejs.org/docs/playground) and
[Combobox](https://platejs.org/docs/combobox).
## API
See the [API documentation](https://plate-api.udecode.io/globals.html).
## License
[MIT](../../../LICENSE)
[MIT](../../LICENSE)

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc