Socket
Socket
Sign inDemoInstall

piral-search

Package Overview
Dependencies
Maintainers
1
Versions
921
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

piral-search - npm Package Compare versions

Comparing version 0.9.0-pre.763 to 0.9.0-pre.765

2

lib/actions.d.ts

@@ -0,3 +1,3 @@

import { Atom } from '@dbeining/react-atom';
import { ReactChild } from 'react';
import { Atom } from '@dbeining/react-atom';
import { GlobalState, Disposable } from 'piral-core';

@@ -4,0 +4,0 @@ import { SearchProviderRegistration } from './types';

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_arbiter_1 = require("react-arbiter");
const react_atom_1 = require("@dbeining/react-atom");

@@ -30,8 +29,11 @@ const piral_core_1 = require("piral-core");

};
providerKeys.forEach(key => providers[key].search(opts).then(results => {
active && appendSearchResults(ctx, results.map(m => react_arbiter_1.wrapElement(m)), --searchCount === 0);
}, ex => {
console.warn(ex);
active && --searchCount === 0 && appendSearchResults(ctx, [], true);
}));
providerKeys.forEach(key => {
const provider = providers[key];
provider.search(opts).then(results => {
active && appendSearchResults(ctx, results, --searchCount === 0);
}, ex => {
console.warn(ex);
active && --searchCount === 0 && appendSearchResults(ctx, [], true);
});
});
return () => {

@@ -38,0 +40,0 @@ active = false;

@@ -15,3 +15,3 @@ import { ReactChild } from 'react';

/**
* Available configuration options for the search extension.
* Available configuration options for the search plugin.
*/

@@ -36,4 +36,4 @@ export interface SearchConfig {

/**
* Creates a new set of Piral API extensions for search and filtering.
* Creates new Pilet API extensions for search and filtering.
*/
export declare function createSearchApi(config?: SearchConfig): Extend<PiletSearchApi>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const actions = require("./actions");
const react_1 = require("react");
const react_atom_1 = require("@dbeining/react-atom");

@@ -27,4 +28,17 @@ const react_arbiter_1 = require("react-arbiter");

}
function toChild(content, api, context) {
if (typeof content === 'string' || react_1.isValidElement(content)) {
return content;
}
else {
const component = piral_core_1.withApi(context.converters, content, api, 'extension');
return react_1.createElement(component);
}
}
function wrapResults(result, api, context) {
const results = Array.isArray(result) ? result : [result];
return results.map(item => toChild(item, api, context));
}
/**
* Creates a new set of Piral API extensions for search and filtering.
* Creates new Pilet API extensions for search and filtering.
*/

@@ -53,3 +67,3 @@ function createSearchApi(config = {}) {

const id = piral_core_1.buildName(pilet, name);
context.registerSearchProvider(id, createSearchRegistration(pilet, q => provider(q, api), settings));
context.registerSearchProvider(id, createSearchRegistration(pilet, q => Promise.resolve(provider(q, api)).then(results => wrapResults(results, api, context), () => []), settings));
},

@@ -56,0 +70,0 @@ unregisterSearchProvider(name) {

@@ -1,3 +0,3 @@

import { ReactNode, ReactChild, ComponentType } from 'react';
import { Dict, Disposable, PiletApi, BaseRegistration } from 'piral-core';
import { ReactChild, ComponentType, ReactElement } from 'react';
import { Dict, Disposable, PiletApi, BaseRegistration, AnyComponent, BaseComponentProps } from 'piral-core';
declare module 'piral-core/lib/types/custom' {

@@ -85,6 +85,9 @@ interface PiletCustomApi extends PiletSearchApi {

}
export interface SearchResultComponentProps extends BaseComponentProps {
}
export interface SearchResultProps {
}
export declare type SearchResultType = string | ReactElement<any> | AnyComponent<SearchResultComponentProps>;
export interface SearchProvider {
(options: SearchOptions, api: PiletApi): Promise<Array<ReactNode | HTMLElement>>;
(options: SearchOptions, api: PiletApi): Promise<SearchResultType | Array<SearchResultType>>;
}

@@ -137,4 +140,7 @@ export interface SearchState {

export interface SearchHandler {
(options: SearchOptions): Promise<Array<ReactNode | HTMLElement>>;
(options: SearchOptions): Promise<Array<ReactChild>>;
}
export interface SearchWrapper {
(component: AnyComponent<SearchResultComponentProps>): ComponentType;
}
export interface SearchProviderRegistration extends BaseRegistration {

@@ -141,0 +147,0 @@ search: SearchHandler;

{
"name": "piral-search",
"version": "0.9.0-pre.763",
"description": "Extensions for centralizing search in Piral.",
"version": "0.9.0-pre.765",
"description": "Plugin for centralizing search in Piral.",
"keywords": [

@@ -12,3 +12,3 @@ "piral",

"api",
"extension",
"plugin",
"search",

@@ -40,3 +40,3 @@ "filter"

"devDependencies": {
"piral-core": "^0.9.0-pre.763"
"piral-core": "^0.9.0-pre.765"
},

@@ -46,3 +46,3 @@ "peerDependencies": {

},
"gitHead": "244d493ecf0c7986e549b0ee2fe48feb20c52cd9"
"gitHead": "81e14b202558d9c3bcf2f8bfdf0b758d0b4b1043"
}

@@ -5,5 +5,5 @@ [![Piral Logo](https://github.com/smapiot/piral/raw/master/docs/assets/logo.png)](https://piral.io)

This is an extension library that only has a peer dependency to `piral-core`. What `piral-search` brings to the table is a set of API extensions that can be used with `piral` or `piral-core` to bring enhanced search capabilities to pilets via your Piral instance.
This is a plugin that only has a peer dependency to `piral-core`. What `piral-search` brings to the table is a set of Pilet API extensions that can be used with `piral` or `piral-core` to bring enhanced search capabilities to pilets via your Piral instance.
By default, these extensions are not integrated in `piral`, so you'd need to add them to your Piral instance.
By default, these API extensions are not integrated in `piral`, so you'd need to add them to your Piral instance.

@@ -14,4 +14,12 @@ ## Documentation

(tbd)
### `registerSearchProvider`
Adds a search provider to be used in the app shell. The search provider will always be invoked when the global search is triggered.
If the first argument is a string a named search provider is registered. A named search provider can also be removed.
### `unregisterSearchProvider`
Removes a search provider from the app shell. This requires a named search provider.
## Setup and Bootstrapping

@@ -18,0 +26,0 @@

@@ -0,4 +1,3 @@

import { swap, Atom, deref } from '@dbeining/react-atom';
import { ReactChild } from 'react';
import { wrapElement } from 'react-arbiter';
import { swap, Atom, deref } from '@dbeining/react-atom';
import { GlobalState, Disposable, appendItems, prependItems, withKey, withoutKey } from 'piral-core';

@@ -41,6 +40,7 @@ import { SearchOptions, SearchProviderRegistration } from './types';

providerKeys.forEach(key =>
providers[key].search(opts).then(
providerKeys.forEach(key => {
const provider = providers[key];
provider.search(opts).then(
results => {
active && appendSearchResults(ctx, results.map(m => wrapElement(m)), --searchCount === 0);
active && appendSearchResults(ctx, results, --searchCount === 0);
},

@@ -51,4 +51,4 @@ ex => {

},
),
);
);
});

@@ -55,0 +55,0 @@ return () => {

import * as actions from './actions';
import { ReactChild } from 'react';
import { ReactChild, isValidElement, createElement } from 'react';
import { swap } from '@dbeining/react-atom';
import { isfunc } from 'react-arbiter';
import { buildName, Extend, Dict } from 'piral-core';
import { buildName, Extend, Dict, withApi, PiletApi, GlobalStateContext } from 'piral-core';
import { DefaultContainer, DefaultInput, DefaultResult } from './default';
import { PiletSearchApi, SearchSettings, SearchHandler, SearchProviderRegistration } from './types';
import { PiletSearchApi, SearchSettings, SearchHandler, SearchProviderRegistration, SearchResultType } from './types';

@@ -21,3 +21,3 @@ export interface InitialSearchProvider {

/**
* Available configuration options for the search extension.
* Available configuration options for the search plugin.
*/

@@ -44,3 +44,7 @@ export interface SearchConfig {

function createSearchRegistration(pilet: string, search: SearchHandler, settings: SearchSettings = {}): SearchProviderRegistration {
function createSearchRegistration(
pilet: string,
search: SearchHandler,
settings: SearchSettings = {},
): SearchProviderRegistration {
const { onlyImmediate = false, onCancel = noop, onClear = noop } = settings;

@@ -67,4 +71,22 @@ return {

function toChild(content: SearchResultType, api: PiletApi, context: GlobalStateContext): ReactChild {
if (typeof content === 'string' || isValidElement(content)) {
return content;
} else {
const component = withApi(context.converters, content, api, 'extension');
return createElement(component);
}
}
function wrapResults(
result: SearchResultType | Array<SearchResultType>,
api: PiletApi,
context: GlobalStateContext,
): Array<ReactChild> {
const results = Array.isArray(result) ? result : [result];
return results.map(item => toChild(item, api, context));
}
/**
* Creates a new set of Piral API extensions for search and filtering.
* Creates new Pilet API extensions for search and filtering.
*/

@@ -111,3 +133,10 @@ export function createSearchApi(config: SearchConfig = {}): Extend<PiletSearchApi> {

const id = buildName(pilet, name);
context.registerSearchProvider(id, createSearchRegistration(pilet, q => provider(q, api), settings));
context.registerSearchProvider(
id,
createSearchRegistration(
pilet,
q => Promise.resolve(provider(q, api)).then(results => wrapResults(results, api, context), () => []),
settings,
),
);
},

@@ -114,0 +143,0 @@ unregisterSearchProvider(name) {

@@ -1,3 +0,3 @@

import { ReactNode, ReactChild, ComponentType } from 'react';
import { Dict, Disposable, PiletApi, BaseRegistration } from 'piral-core';
import { ReactChild, ComponentType, ReactElement } from 'react';
import { Dict, Disposable, PiletApi, BaseRegistration, AnyComponent, BaseComponentProps } from 'piral-core';

@@ -92,6 +92,10 @@ declare module 'piral-core/lib/types/custom' {

export interface SearchResultComponentProps extends BaseComponentProps {}
export interface SearchResultProps {}
export type SearchResultType = string | ReactElement<any> | AnyComponent<SearchResultComponentProps>;
export interface SearchProvider {
(options: SearchOptions, api: PiletApi): Promise<Array<ReactNode | HTMLElement>>;
(options: SearchOptions, api: PiletApi): Promise<SearchResultType | Array<SearchResultType>>;
}

@@ -148,5 +152,9 @@

export interface SearchHandler {
(options: SearchOptions): Promise<Array<ReactNode | HTMLElement>>;
(options: SearchOptions): Promise<Array<ReactChild>>;
}
export interface SearchWrapper {
(component: AnyComponent<SearchResultComponentProps>): ComponentType;
}
export interface SearchProviderRegistration extends BaseRegistration {

@@ -153,0 +161,0 @@ search: SearchHandler;

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