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

piral-core

Package Overview
Dependencies
Maintainers
1
Versions
1027
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

piral-core - npm Package Compare versions

Comparing version 0.2.0-pre.366 to 0.2.0

lib/components/withForm.d.ts

1

lib/components/index.d.ts

@@ -7,1 +7,2 @@ export * from './extension';

export * from './withFeed';
export * from './withForm';

@@ -12,2 +12,3 @@ "use strict";

__export(require("./withFeed"));
__export(require("./withForm"));
//# sourceMappingURL=index.js.map

4

lib/components/withApi.d.ts
import * as React from 'react';
import { AnyComponent, PiralApi } from '../types';
export declare type ApiForward<TApi> = {
export interface ApiForward<TApi> {
piral: PiralApi<TApi>;
};
}
export declare function withApi<TApi, TProps>(component: AnyComponent<TProps & ApiForward<TApi>>, piral: PiralApi<TApi>): React.ComponentType<TProps>;
import * as React from 'react';
import { ConnectorDetails } from '../types';
export declare function withFeed<TData, TItem, TProps>(Component: React.ComponentType<TProps & {
data: TData;
}>, options: ConnectorDetails<TData, TItem>): React.FunctionComponent<TProps>;
import { ConnectorDetails, ConnectorProps } from '../types';
export declare function withFeed<TData, TItem, TProps>(Component: React.ComponentType<TProps & ConnectorProps<TData>>, options: ConnectorDetails<TData, TItem>): React.FunctionComponent<TProps>;
"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
t[p[i]] = s[p[i]];
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const react_1 = require("react");
const hooks_1 = require("../hooks");
function withFeed(Component, options) {
const FeedView = (_a) => {
var props = __rest(_a, []);
const { loaded, loading, error, data } = hooks_1.useGlobalState(s => s.feeds[options.id]);
const FeedView = props => {
const { Loader, ErrorInfo } = hooks_1.useGlobalState(s => s.app.components);
const load = hooks_1.useAction('loadFeed');
react_1.useEffect(() => {
if (!loaded && !loading) {
load(options);
}
}, []);
const [loaded, data, error] = hooks_1.useFeed(options);
if (!loaded) {

@@ -27,0 +10,0 @@ return React.createElement(Loader, null);

import { StateActions } from '../types';
/**
* Hook that gets an action for manipulating the global state.
* @param action The name of the action to retrieve.
*/
export declare function useAction<T extends keyof StateActions>(action: T): import("../types").GlobalStateContext[T];

@@ -5,2 +5,6 @@ "use strict";

const stateContext_1 = require("../state/stateContext");
/**
* Hook that gets an action for manipulating the global state.
* @param action The name of the action to retrieve.
*/
function useAction(action) {

@@ -7,0 +11,0 @@ const ctx = react_1.useContext(stateContext_1.StateContext);

@@ -0,1 +1,8 @@

/**
* Hook that returns the debounced (i.e., delayed) value.
* Useful when user input should not fire immediately, but rather
* only after a certain timespan without any changes passed.
* @param value The value to consider.
* @param delay The timespan to pass before applying the value.
*/
export declare function useDebounce<T>(value: T, delay?: number): T;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
/**
* Hook that returns the debounced (i.e., delayed) value.
* Useful when user input should not fire immediately, but rather
* only after a certain timespan without any changes passed.
* @param value The value to consider.
* @param delay The timespan to pass before applying the value.
*/
function useDebounce(value, delay = 300) {

@@ -5,0 +12,0 @@ const [debouncedValue, setDebouncedValue] = react_1.useState(value);

import { GlobalState } from '../types';
/**
* Hook that yields the full global state.
* Any change to the global state yields the new state.
*/
export declare function useGlobalState(): GlobalState;
/**
* Hook that yields the selected subset of the global state.
* Only changes to this subset will yield a new state.
* @param select The subset selection.
*/
export declare function useGlobalState<R>(select: (state: GlobalState) => R): R;
export * from './action';
export * from './actions';
export * from './debounce';
export * from './feed';
export * from './form';
export * from './globalState';

@@ -9,3 +11,5 @@ export * from './lockBodyScroll';

export * from './onScreenVisible';
export * from './promise';
export * from './prompt';
export * from './search';
export * from './sharedData';

@@ -9,2 +9,4 @@ "use strict";

__export(require("./debounce"));
__export(require("./feed"));
__export(require("./form"));
__export(require("./globalState"));

@@ -15,4 +17,6 @@ __export(require("./lockBodyScroll"));

__export(require("./onScreenVisible"));
__export(require("./promise"));
__export(require("./prompt"));
__export(require("./search"));
__export(require("./sharedData"));
//# sourceMappingURL=index.js.map

@@ -0,1 +1,6 @@

/**
* Hook that locks scrolling on the main document.
* Useful for preventing the standard scrolling in context of
* a modal dialog.
*/
export declare function useLockBodyScroll(): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
/**
* Hook that locks scrolling on the main document.
* Useful for preventing the standard scrolling in context of
* a modal dialog.
*/
function useLockBodyScroll() {

@@ -5,0 +10,0 @@ react_1.useLayoutEffect(() => {

@@ -0,1 +1,7 @@

/**
* Hook to detect layout changes (e.g., which UI breakpoint was hit).
* @param queries The available queries matching the breakpoints.
* @param values The values mapping to the breakpoints
* @param defaultValue The default value.
*/
export declare function useMedia<T>(queries: Array<string>, values: Array<T>, defaultValue: T): T;

@@ -5,2 +5,8 @@ "use strict";

const media_1 = require("../utils/media");
/**
* Hook to detect layout changes (e.g., which UI breakpoint was hit).
* @param queries The available queries matching the breakpoints.
* @param values The values mapping to the breakpoints
* @param defaultValue The default value.
*/
function useMedia(queries, values, defaultValue) {

@@ -7,0 +13,0 @@ const match = () => media_1.getCurrentLayout(queries, values, defaultValue);

import { RefObject } from 'react';
/**
* Hook that detects if a click outside the given reference
* has been performed.
* @param ref The reference to the element.
* @param handler The callback to invoke when an outside click happened.
*/
export declare function useOnClickOutside<T extends HTMLElement>(ref: RefObject<T>, handler: (event: MouseEvent) => void): void;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
/**
* Hook that detects if a click outside the given reference
* has been performed.
* @param ref The reference to the element.
* @param handler The callback to invoke when an outside click happened.
*/
function useOnClickOutside(ref, handler) {
react_1.useEffect(() => {
const listener = (event) => {
if (!ref.current || ref.current.contains(event.target)) {
return;
if (ref.current && !ref.current.contains(event.target)) {
handler(event);
}
handler(event);
};

@@ -18,5 +23,5 @@ document.addEventListener('mousedown', listener);

};
}, []);
}, [handler]);
}
exports.useOnClickOutside = useOnClickOutside;
//# sourceMappingURL=onClickOutside.js.map
import { RefObject } from 'react';
/**
* Hook that detects if a reference element within the main document is
* visible.
* Useful for performing some animation or triggering certain actions (e.g.,
* loading data for infinity scrolling) when an element appears or is close
* to appear on screen.
* @param ref The reference element to be visible.
* @param rootMargin The tolerance level to the reference element.
*/
export declare function useOnScreenVisible<T extends HTMLElement>(ref: RefObject<T>, rootMargin?: string): boolean;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const react_1 = require("react");
/**
* Hook that detects if a reference element within the main document is
* visible.
* Useful for performing some animation or triggering certain actions (e.g.,
* loading data for infinity scrolling) when an element appears or is close
* to appear on screen.
* @param ref The reference element to be visible.
* @param rootMargin The tolerance level to the reference element.
*/
function useOnScreenVisible(ref, rootMargin = '0px') {

@@ -5,0 +14,0 @@ const [isIntersecting, setIntersecting] = react_1.useState(false);

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

/**
* Hook that yields the possibility of searching in Piral.
* Returns the current (live, i.e., non-debounced) input value
* and the ability to change the input value.
* Changing the input value uses a debounce function to
* properly cancel any current search and start a new search.
* All registered search providers are used and search results
* will be integrated as they arrive.
*/
export declare function useSearch(): [string, (value: string) => void];

@@ -8,2 +8,11 @@ "use strict";

const actions_1 = require("./actions");
/**
* Hook that yields the possibility of searching in Piral.
* Returns the current (live, i.e., non-debounced) input value
* and the ability to change the input value.
* Changing the input value uses a debounce function to
* properly cancel any current search and start a new search.
* All registered search providers are used and search results
* will be integrated as they arrive.
*/
function useSearch() {

@@ -10,0 +19,0 @@ const { setSearchInput, resetSearchResults, appendSearchResults } = actions_1.useActions();

import { SharedDataItem, Dict } from '../types';
/**
* Hook that yields the full shared data.
* Any change to the shared data yields the new data.
*/
export declare function useSharedData(): Dict<SharedDataItem>;
/**
* Hook that yields the selected subset of the shared data.
* Only changes to this subset will yield a new data state.
* @param select The subset selection.
*/
export declare function useSharedData<R>(select: (source: Dict<SharedDataItem>) => R): R;

@@ -45,2 +45,5 @@ "use strict";

},
createForm(options) {
return component => components_1.withForm(component, options);
},
provideTranslations(messages) {

@@ -47,0 +50,0 @@ translations = messages;

@@ -11,8 +11,5 @@ "use strict";

function getLocalDependencies() {
return {
'react-arbiter': require('react-arbiter'),
'react-dom': require('react-dom'),
};
return Object.assign({}, exports.globalDependencies, { 'react-arbiter': require('react-arbiter'), 'react-dom': require('react-dom') });
}
exports.getLocalDependencies = getLocalDependencies;
//# sourceMappingURL=dependencies.js.map

@@ -21,8 +21,12 @@ "use strict";

function writeDataItem(key, value, owner, target, expires) {
react_atom_1.swap(this, state => (Object.assign({}, state, { app: Object.assign({}, state.app, { data: utils_1.withKey(state.app.data, key, {
value,
owner,
target,
expires,
}) }) })));
const isNull = !value && typeof value === 'object';
const data = isNull
? value
: {
value,
owner,
target,
expires,
};
react_atom_1.swap(this, state => (Object.assign({}, state, { app: Object.assign({}, state.app, { data: utils_1.updateKey(state.app.data, key, data) }) })));
}

@@ -29,0 +33,0 @@ exports.writeDataItem = writeDataItem;

@@ -5,2 +5,3 @@ export * from './app';

export * from './feeds';
export * from './forms';
export * from './modals';

@@ -7,0 +8,0 @@ export * from './notifications';

@@ -10,2 +10,3 @@ "use strict";

__export(require("./feeds"));
__export(require("./forms"));
__export(require("./modals"));

@@ -12,0 +13,0 @@ __export(require("./notifications"));

@@ -6,3 +6,3 @@ "use strict";

const newActions = Object.assign({}, actions);
Object.keys(newActions).map(actionName => {
Object.keys(newActions).forEach(actionName => {
newActions[actionName] = newActions[actionName].bind(globalState);

@@ -9,0 +9,0 @@ });

@@ -38,2 +38,3 @@ "use strict";

feeds: {},
forms: {},
user: {

@@ -40,0 +41,0 @@ current: undefined,

@@ -7,2 +7,3 @@ import { ReactNode, ComponentType } from 'react';

import { FeedResolver, FeedConnector, FeedConnectorOptions } from './feed';
import { InputFormOptions, FormCreator } from './form';
import { Dict, LocalizationMessages, Disposable, SeverityLevel, EventEmitter } from './utils';

@@ -52,2 +53,7 @@ import { SearchProvider } from './search';

/**
* Creates an input form for tracking user input intelligently.
* @param options The options for creating the form.
*/
createForm<TFormData, TProps = any>(options: InputFormOptions<TFormData, TProps>): FormCreator<TFormData, TProps>;
/**
* Gets a shared data value.

@@ -54,0 +60,0 @@ * @param name The name of the data to retrieve.

@@ -71,2 +71,12 @@ import { ComponentType } from 'react';

}
export interface FormErrorInfoProps {
/**
* The type of the error.
*/
type: 'form';
/**
* The provided error details.
*/
error: any;
}
export interface LoadingErrorInfoProps {

@@ -82,3 +92,3 @@ /**

}
export declare type ErrorInfoProps = NotFoundErrorInfoProps | PageErrorInfoProps | FeedErrorInfoProps | LoadingErrorInfoProps;
export declare type ErrorInfoProps = NotFoundErrorInfoProps | PageErrorInfoProps | FeedErrorInfoProps | LoadingErrorInfoProps | FormErrorInfoProps;
export interface LoaderProps {

@@ -85,0 +95,0 @@ }

import { ComponentType } from 'react';
import { Disposable } from './utils';
export interface ConnectorDetails<TData, TItem> extends FeedConnectorOptions<TData, TItem> {
export interface ConnectorProps<TData> {
/**
* The ID of the connector.
* The current data from the feed.
*/
id: string;
data: TData;
}
export interface FeedConnector<T> {
export interface FeedConnector<TData> {
/**
* Connector function for wrapping a component.
*/
<TProps>(component: ComponentType<TProps & {
data: T;
}>): ComponentType<TProps>;
<TProps>(component: ComponentType<TProps & ConnectorProps<TData>>): ComponentType<TProps>;
}

@@ -54,1 +52,7 @@ export interface FeedResolver<TData> {

}
export interface ConnectorDetails<TData, TItem> extends FeedConnectorOptions<TData, TItem> {
/**
* The ID of the connector.
*/
id: string;
}

@@ -6,2 +6,3 @@ export * from './api';

export * from './feed';
export * from './form';
export * from './layout';

@@ -8,0 +9,0 @@ export * from './menu';

@@ -138,22 +138,61 @@ import { ComponentType, ReactChild } from 'react';

}
export interface FeedDataState {
/**
* Determines if the feed data is currently loading.
*/
loading: boolean;
/**
* Indicates if the feed data was already loaded and is active.
*/
loaded: boolean;
/**
* Stores the potential error when initializing or loading the feed.
*/
error: any;
/**
* The currently stored feed data.
*/
data: any;
}
export interface FeedsState {
[id: string]: {
/**
* Determines if the feed is currently loading.
*/
loading: boolean;
/**
* Indicates if the feed was already loaded and is active.
*/
loaded: boolean;
/**
* Stores the potential error when initializing or loading the feed.
*/
error: any;
/**
* The currently stored feed data.
*/
data: any;
};
/**
* Gets the state of the available data feeds.
*/
[id: string]: FeedDataState;
}
export interface FormDataState {
/**
* Gets the usage status of the form - true means
* the form is actively being used, false is the
* status for forms that are not used any more.
*/
active: boolean;
/**
* Indicates that the form is currently submitting.
*/
submitting: boolean;
/**
* Stores the potential error of the form.
*/
error: any;
/**
* The initial data to use.
*/
initialData: any;
/**
* The current data that has been submitted.
*/
currentData: any;
/**
* Gets or sets if th current data is different from
* the initial data.
*/
changed: boolean;
}
export interface FormsState {
/**
* Gets the state of forms that are currently not actively used.
*/
[id: string]: FormDataState;
}
export interface UserState {

@@ -201,2 +240,6 @@ /**

/**
* The relevant state for the active forms.
*/
forms: FormsState;
/**
* The relevant state for the current user.

@@ -211,33 +254,176 @@ */

export interface StateActions {
/**
* Reads the value of a shared data item.
* @param name The name of the shared item.
*/
readDataValue(name: string): any;
/**
* Tries to write a shared data item. The write access is only
* possible if the name belongs to the provided owner or has not
* been taken yet.
* Setting the value to null will release it.
* @param name The name of the shared data item.
* @param value The value of the shared data item.
* @param owner The owner of the shared data item.
* @param target The target storage locatation.
* @param expiration The time for when to dispose the shared item.
*/
tryWriteDataItem(name: string, value: any, owner: string, target: DataStoreTarget, expiration: number): boolean;
/**
* Performs a layout change.
* @param current The layout to take.
*/
changeLayout(current: LayoutType): void;
/**
* Changes the selected language.
* @param selected The selected language.
*/
selectLanguage(selected: string): void;
/**
* Adds another language to the available languages.
* @param language The language to add.
*/
addLanguage(language: string): void;
/**
* Remnoves an existing language from the available languages.
* @param language The language to remove.
*/
removeLanguage(language: string): void;
/**
* Creates a new (empty) feed.
* @param id The id of the feed.
*/
createFeed(id: string): void;
/**
* Destroys an existing feed.
* @param id The id of the feed.
*/
destroyFeed(id: string): void;
/**
* Loads the feed via the provided details.
* @param feed The feed details to use for loading.
*/
loadFeed<TData, TItem>(feed: ConnectorDetails<TData, TItem>): void;
/**
* Opens the given notification.
* @param notification The notification to show.
*/
openNotification(notification: OpenNotification): void;
/**
* Closes the given notification.
* @param notification The notification to hide.
*/
closeNotification(notification: OpenNotification): void;
/**
* Opens the provided dialog.
* @param dialog The dialog to show.
*/
openModal(dialog: OpenModalDialog): void;
/**
* Closes the provided dialog.
* @param dialog The dialog to hide.
*/
closeModal(dialog: OpenModalDialog): void;
/**
* Registers a new route to be resolved.
* @param route The route to register.
* @param value The page to be rendered on the route.
*/
registerPage(route: string, value: PageRegistration): void;
/**
* Unregisters an existing route.
* @param route The route to be removed.
*/
unregisterPage(route: string): void;
/**
* Registers a new tile.
* @param name The name of the tile.
* @param value The tile registration.
*/
registerTile(name: string, value: TileRegistration): void;
/**
* Unregisters an existing tile.
* @param name The name of the tile to be removed.
*/
unregisterTile(name: string): void;
/**
* Registers a new extension.
* @param name The name of the extension category.
* @param value The extension registration.
*/
registerExtension(name: string, value: ExtensionRegistration): void;
/**
* Unregisters an existing extension.
* @param name The name of the extension category.
* @param value The extension that will be removed.
*/
unregisterExtension(name: string, reference: any): void;
/**
* Registers a new menu item.
* @param name The name of the menu item.
* @param value The menu registration.
*/
registerMenuItem(name: string, value: MenuItemRegistration): void;
/**
* Unregisters an existing menu item.
* @param name The name of the menu item to be removed.
*/
unregisterMenuItem(name: string): void;
/**
* Registers a new modal dialog.
* @param name The name of the modal.
* @param value The modal registration.
*/
registerModal(name: string, value: ModalRegistration): void;
/**
* Unregisters an existing modal dialog.
* @param name The name of the modal to be removed.
*/
unregisterModal(name: string): void;
/**
* Registers a new search provider.
* @param name The name of the search provider.
* @param value The value representing the provider.
*/
registerSearchProvider(name: string, value: SearchProviderRegistration): void;
/**
* Unregisters an existing search provider.
* @param name The name of the search provider.
*/
unregisterSearchProvider(name: string): void;
/**
* Sets the current search input.
* @param input The input to set.
*/
setSearchInput(input: string): void;
/**
* Sets the form data from the provided original state and patch data.
* @param id The id of the form.
* @param original The initial state of the form.
* @param patch The provided patch.
*/
updateFormState(id: string, original: FormDataState, patch: Partial<FormDataState>): void;
/**
* Resets the search results.
* @param loading Determines if further results are currently loading.
*/
resetSearchResults(loading: boolean): void;
/**
* Appends more results to the existing results.
* @param items The items to append.
* @param done Determines if more results are pending.
*/
appendSearchResults(items: Array<ReactChild>, done: boolean): void;
/**
* Prepends more results to the existing results.
* @param items The items to prepend.
* @param done Determines if more results are pending.
*/
prependSearchResults(items: Array<ReactChild>, done: boolean): void;
}
export interface GlobalStateContext extends StateActions {
/**
* The global state context atom.
*/
state: Atom<GlobalState>;
}
import { Dict } from '../types';
export declare const removeIndicator: any;
export declare function prependItem<T>(items: Array<T>, item: T): T[];

@@ -8,3 +9,4 @@ export declare function appendItem<T>(items: Array<T>, item: T): T[];

export declare function excludeOn<T>(items: Array<T>, predicate: (item: T) => boolean): T[];
export declare function updateKey<T>(obj: Dict<T>, key: string, value: T): Dict<T>;
export declare function withKey<T>(obj: Dict<T>, key: string, value: T): Dict<T>;
export declare function withoutKey<T>(obj: Dict<T>, key: string): Dict<T>;

@@ -12,2 +12,4 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
// tslint:disable-next-line
exports.removeIndicator = null;
function prependItem(items, item) {

@@ -37,2 +39,6 @@ return [item, ...(items || [])];

exports.excludeOn = excludeOn;
function updateKey(obj, key, value) {
return value === exports.removeIndicator ? withoutKey(obj, key) : withKey(obj, key, value);
}
exports.updateKey = updateKey;
function withKey(obj, key, value) {

@@ -39,0 +45,0 @@ return Object.assign({}, obj, { [key]: value });

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

export * from './compare';
export * from './data';
export * from './feed';
export * from './guid';
export * from './helpers';

@@ -4,0 +6,0 @@ export * from './media';

@@ -6,4 +6,6 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
__export(require("./compare"));
__export(require("./data"));
__export(require("./feed"));
__export(require("./guid"));
__export(require("./helpers"));

@@ -10,0 +12,0 @@ __export(require("./media"));

{
"name": "piral-core",
"version": "0.2.0-pre.366",
"version": "0.2.0",
"description": "The core library for creating a Piral instance.",

@@ -52,3 +52,3 @@ "keywords": [

},
"gitHead": "b91b5ecb547a84fed57df6cb4f0698cd6fdf91cd"
"gitHead": "5a74ac9aa1fedac3d897cb1790adb229a9a76ace"
}

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

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