piral-modals 1.0.0-pre.2217 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 - 2021 smapiot
3
+ Copyright (c) 2019 - 2023 smapiot
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- [![Piral Logo](https://github.com/smapiot/piral/raw/master/docs/assets/logo.png)](https://piral.io)
1
+ [![Piral Logo](https://github.com/smapiot/piral/raw/main/docs/assets/logo.png)](https://piral.io)
2
2
 
3
- # [Piral Modals](https://piral.io) · [![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/smapiot/piral/blob/master/LICENSE) [![npm version](https://img.shields.io/npm/v/piral-modals.svg?style=flat)](https://www.npmjs.com/package/piral-modals) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://jestjs.io) [![Gitter Chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/piral-io/community)
3
+ # [Piral Modals](https://piral.io) · [![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/smapiot/piral/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/piral-modals.svg?style=flat)](https://www.npmjs.com/package/piral-modals) [![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://jestjs.io) [![Gitter Chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/piral-io/community)
4
4
 
5
5
  This is a plugin that only has a peer dependency to `piral-core`. What `piral-modals` brings to the table is a set of Pilet API extensions that can be used with `piral` or `piral-core` to easily trigger the display of modal dialogs from pilets.
6
6
 
@@ -10,6 +10,12 @@ If you have modal dialogs on your page that `piral-modals` gives you a nice abst
10
10
 
11
11
  Alternative: You could simply use an event to trigger opening a dialog. The event could transport a React component which would then be globally used. Alternatively, each pilet would come up with its own dialog design and management system.
12
12
 
13
+ ## Video
14
+
15
+ We also have a video for this plugin:
16
+
17
+ @[youtube](https://youtu.be/gZt7Ic1BHNA)
18
+
13
19
  ## Documentation
14
20
 
15
21
  The following functions are brought to the Pilet API.
package/esm/Modals.js CHANGED
@@ -1,33 +1,33 @@
1
- import { __assign } from "tslib";
2
1
  import * as React from 'react';
3
2
  import { useGlobalState } from 'piral-core';
4
3
  import { PiralModalsDialog, PiralModalsHost } from './components';
5
4
  function closeAll(modals) {
6
- modals.forEach(function (m) { return m.close(); });
5
+ modals.forEach((m) => m.close());
7
6
  }
8
7
  function findModal(modals, name) {
9
8
  if (name) {
10
- var modal = Object.keys(modals)
11
- .filter(function (m) { return modals[m].name === name; })
12
- .map(function (m) { return modals[m]; })[0];
9
+ const [modal] = Object.keys(modals)
10
+ .filter((m) => modals[m].name === name)
11
+ .map((m) => modals[m]);
13
12
  return modal;
14
13
  }
15
14
  return undefined;
16
15
  }
17
- export var Modals = function () {
18
- var modals = useGlobalState(function (s) { return s.registry.modals; });
19
- var dialogs = useGlobalState(function (s) { return s.modals; });
20
- var close = function () { return closeAll(dialogs); };
21
- var children = dialogs
22
- .map(function (n) {
23
- var reg = modals[n.name] || findModal(modals, n.alternative);
24
- var Component = reg && reg.component;
25
- var defaults = reg && reg.defaults;
26
- return (Component && (React.createElement(PiralModalsDialog, __assign({}, n, { key: n.name }),
27
- React.createElement(Component, { onClose: n.close, options: __assign(__assign({}, defaults), n.options) }))));
16
+ export const Modals = () => {
17
+ const modals = useGlobalState((s) => s.registry.modals);
18
+ const dialogs = useGlobalState((s) => s.modals);
19
+ const close = () => closeAll(dialogs);
20
+ const children = dialogs
21
+ .map((n) => {
22
+ const reg = modals[n.name] || findModal(modals, n.alternative);
23
+ const Component = reg && reg.component;
24
+ const defaults = reg && reg.defaults;
25
+ const options = Object.assign(Object.assign({}, defaults), n.options);
26
+ return (Component && (React.createElement(PiralModalsDialog, Object.assign({}, n, { options: options, defaults: reg.defaults, layout: reg.layout, key: n.name }),
27
+ React.createElement(Component, { onClose: n.close, options: options }))));
28
28
  })
29
- .filter(function (m) { return !!m; });
30
- var open = children.length > 0;
29
+ .filter(Boolean);
30
+ const open = children.length > 0;
31
31
  return (React.createElement(PiralModalsHost, { open: open, close: close }, children));
32
32
  };
33
33
  Modals.displayName = 'Modals';
package/esm/Modals.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Modals.js","sourceRoot":"","sources":["../src/Modals.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGlE,SAAS,QAAQ,CAAC,MAA8B;IAC9C,MAAM,CAAC,OAAO,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,KAAK,EAAE,EAAT,CAAS,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,SAAS,CAAC,MAAyC,EAAE,IAAY;IACxE,IAAI,IAAI,EAAE;QACD,IAAA,KAAK,GAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;aAChC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,EAAvB,CAAuB,CAAC;aACtC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,MAAM,CAAC,CAAC,CAAC,EAAT,CAAS,CAAC,GAFZ,CAEa;QAEzB,OAAO,KAAK,CAAC;KACd;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,CAAC,IAAM,MAAM,GAAa;IAC9B,IAAM,MAAM,GAAG,cAAc,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAjB,CAAiB,CAAC,CAAC;IACxD,IAAM,OAAO,GAAG,cA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,CAAC,OAAO,CACb,CAAC;QACF,OAAO,CACL,SAAS,IAAI,CACX,oBAAC,iBAAiB,oBAAK,CAAC,IAAE,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI;YACjG,oBAAC,SAAS,IAAC,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAI,CAC/B,CACrB,CACF,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAEjC,OAAO,CACL,oBAAC,eAAe,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,IACtC,QAAQ,CACO,CACnB,CAAC;AACJ,CAAC,CAAC;AACF,MAAM,CAAC,WAAW,GAAG,QAAQ,CAAC"}
package/esm/actions.js CHANGED
@@ -1,15 +1,14 @@
1
- import { __assign } from "tslib";
2
- import { withKey, withoutKey, prependItem, excludeItem } from 'piral-core';
1
+ import { withKey, withoutKey, prependItem, excludeOn } from 'piral-core';
3
2
  export function openModal(ctx, dialog) {
4
- ctx.dispatch(function (state) { return (__assign(__assign({}, state), { modals: prependItem(state.modals, dialog) })); });
3
+ ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { modals: prependItem(state.modals, dialog) })));
5
4
  }
6
5
  export function closeModal(ctx, dialog) {
7
- ctx.dispatch(function (state) { return (__assign(__assign({}, state), { modals: excludeItem(state.modals, dialog) })); });
6
+ ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { modals: excludeOn(state.modals, (modal) => modal.id === dialog.id) })));
8
7
  }
9
8
  export function registerModal(ctx, name, value) {
10
- ctx.dispatch(function (state) { return (__assign(__assign({}, state), { registry: __assign(__assign({}, state.registry), { modals: withKey(state.registry.modals, name, value) }) })); });
9
+ ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { modals: withKey(state.registry.modals, name, value) }) })));
11
10
  }
12
11
  export function unregisterModal(ctx, name) {
13
- ctx.dispatch(function (state) { return (__assign(__assign({}, state), { registry: __assign(__assign({}, state.registry), { modals: withoutKey(state.registry.modals, name) }) })); });
12
+ ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { modals: withoutKey(state.registry.modals, name) }) })));
14
13
  }
15
14
  //# sourceMappingURL=actions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAsB,MAAM,YAAY,CAAC;AAG/F,MAAM,UAAU,SAAS,CAAC,GAAuB,EAAE,MAAuB;IACxE,GAAG,CAAC,QAAQ,CAAC,UAAC,KAAK,IAAK,OAAA,uBACnB,KAAK,KACR,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,IACzC,EAHsB,CAGtB,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,GAAuB,EAAE,MAAuB;IACzE,GAAG,CAAC,QAAQ,CAAC,UAAC,KAAK,IAAK,OAAA,uBACnB,KAAK,KACR,MAAM,EAAE,WAAW,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,IACzC,EAHsB,CAGtB,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,GAAuB,EAAE,IAAY,EAAE,KAAwB;IAC3F,GAAG,CAAC,QAAQ,CAAC,UAAC,KAAK,IAAK,OAAA,uBACnB,KAAK,KACR,QAAQ,wBACH,KAAK,CAAC,QAAQ,KACjB,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,OAErD,EANsB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ErD,CAAC,CAAC;AACN,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,GAAuB,EAAE,IAAY;IACnE,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCACnB,KAAK,KACR,QAAQ,kCACH,KAAK,CAAC,QAAQ,KACjB,MAAM,EAAE,UAAU,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,OAEjD,CAAC,CAAC;AACN,CAAC"}
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
- import { ModalsHostProps, ModalsDialogProps } from './types';
3
- export declare const PiralModalsHost: React.ComponentType<ModalsHostProps>;
4
- export declare const PiralModalsDialog: React.ComponentType<ModalsDialogProps>;
1
+ /// <reference types="react" />
2
+ export declare const PiralModalsHost: import("react").ComponentType<import("./types").ModalsHostProps>;
3
+ export declare const PiralModalsDialog: import("react").ComponentType<import("./types").ModalsDialogProps>;
package/esm/components.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { getPiralComponent } from 'piral-core';
2
- export var PiralModalsHost = getPiralComponent('ModalsHost');
3
- export var PiralModalsDialog = getPiralComponent('ModalsDialog');
2
+ export const PiralModalsHost = getPiralComponent('ModalsHost');
3
+ export const PiralModalsDialog = getPiralComponent('ModalsDialog');
4
4
  //# sourceMappingURL=components.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAG/C,MAAM,CAAC,IAAM,eAAe,GAAyC,iBAAiB,CAAC,YAAY,CAAC,CAAC;AACrG,MAAM,CAAC,IAAM,iBAAiB,GAA2C,iBAAiB,CAAC,cAAc,CAAC,CAAC"}
1
+ {"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAC,YAAY,CAAC,CAAC;AAC/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,cAAc,CAAC,CAAC"}
package/esm/create.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ComponentType } from 'react';
2
2
  import { PiralPlugin } from 'piral-core';
3
- import { PiletModalsApi, BareModalComponentProps } from './types';
3
+ import { PiletModalsApi, BareModalComponentProps, ModalLayoutOptions } from './types';
4
4
  export interface InitialModalDialog {
5
5
  /**
6
6
  * The name of the modal dialog.
@@ -13,7 +13,11 @@ export interface InitialModalDialog {
13
13
  /**
14
14
  * The default options for the modal dialog.
15
15
  */
16
- defaults: any;
16
+ defaults?: any;
17
+ /**
18
+ * The layout options for the modal dialog.
19
+ */
20
+ layout?: ModalLayoutOptions;
17
21
  }
18
22
  /**
19
23
  * Available configuration options for the modals plugin.
@@ -23,6 +27,13 @@ export interface ModalsConfig {
23
27
  * The initial modal dialogs.
24
28
  */
25
29
  dialogs?: Array<InitialModalDialog>;
30
+ /**
31
+ * Defines how the next ID for the key is selected.
32
+ * By default a random number is used.
33
+ *
34
+ * @param name The name of the modal dialog.
35
+ */
36
+ selectId?(name: string): string;
26
37
  }
27
38
  /**
28
39
  * Creates new Pilet API extensions for support modal dialogs.
package/esm/create.js CHANGED
@@ -1,56 +1,61 @@
1
- import { __assign } from "tslib";
2
1
  import * as actions from './actions';
3
- import { withApi, buildName } from 'piral-core';
2
+ import { withApi, buildName, withRootExtension, withAll } from 'piral-core';
4
3
  import { DefaultHost, DefaultDialog } from './default';
4
+ import { Modals } from './Modals';
5
5
  function getModalDialogs(dialogs) {
6
- var modals = {};
7
- for (var _i = 0, dialogs_1 = dialogs; _i < dialogs_1.length; _i++) {
8
- var _a = dialogs_1[_i], name_1 = _a.name, component = _a.component, defaults = _a.defaults;
9
- modals["global-" + name_1] = {
6
+ const modals = {};
7
+ for (const { name, component, defaults, layout = {} } of dialogs) {
8
+ modals[`global-${name}`] = {
10
9
  pilet: undefined,
11
- name: name_1,
12
- component: component,
13
- defaults: defaults,
10
+ name,
11
+ component,
12
+ defaults,
13
+ layout,
14
14
  };
15
15
  }
16
16
  return modals;
17
17
  }
18
+ function withModals(modals) {
19
+ return (state) => (Object.assign(Object.assign({}, state), { components: Object.assign({ ModalsHost: DefaultHost, ModalsDialog: DefaultDialog }, state.components), registry: Object.assign(Object.assign({}, state.registry), { modals }), modals: [] }));
20
+ }
18
21
  /**
19
22
  * Creates new Pilet API extensions for support modal dialogs.
20
23
  */
21
- export function createModalsApi(config) {
22
- if (config === void 0) { config = {}; }
23
- var _a = config.dialogs, dialogs = _a === void 0 ? [] : _a;
24
- return function (context) {
24
+ export function createModalsApi(config = {}) {
25
+ const { dialogs = [], selectId = (name) => `${name}-${~~(Math.random() * 10000)}` } = config;
26
+ return (context) => {
25
27
  context.defineActions(actions);
26
- context.dispatch(function (state) { return (__assign(__assign({}, state), { components: __assign({ ModalsHost: DefaultHost, ModalsDialog: DefaultDialog }, state.components), registry: __assign(__assign({}, state.registry), { modals: getModalDialogs(dialogs) }), modals: [] })); });
27
- return function (api, target) {
28
- var pilet = target.name;
28
+ context.dispatch(withAll(withModals(getModalDialogs(dialogs)), withRootExtension('piral-modals', Modals)));
29
+ return (api, target) => {
30
+ const pilet = target.name;
29
31
  return {
30
- showModal: function (name, options) {
31
- var dialog = {
32
- name: buildName(pilet, name),
33
- alternative: name,
34
- options: options,
35
- close: function () {
36
- setTimeout(function () { return context.closeModal(dialog); }, 0);
32
+ showModal(simpleName, options) {
33
+ const name = buildName(pilet, simpleName);
34
+ const dialog = {
35
+ id: selectId(name),
36
+ name,
37
+ alternative: simpleName,
38
+ options,
39
+ close() {
40
+ context.closeModal(dialog);
37
41
  },
38
42
  };
39
43
  context.openModal(dialog);
40
44
  return dialog.close;
41
45
  },
42
- registerModal: function (name, arg, defaults) {
43
- var id = buildName(pilet, name);
46
+ registerModal(name, arg, defaults, layout = {}) {
47
+ const id = buildName(pilet, name);
44
48
  context.registerModal(id, {
45
- pilet: pilet,
46
- name: name,
49
+ pilet,
50
+ name,
47
51
  component: withApi(context, arg, api, 'modal'),
48
- defaults: defaults,
52
+ defaults,
53
+ layout,
49
54
  });
50
- return function () { return api.unregisterModal(name); };
55
+ return () => api.unregisterModal(name);
51
56
  },
52
- unregisterModal: function (name) {
53
- var id = buildName(pilet, name);
57
+ unregisterModal(name) {
58
+ const id = buildName(pilet, name);
54
59
  context.unregisterModal(id);
55
60
  },
56
61
  };
package/esm/create.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../src/create.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAqB,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AA4BvD,SAAS,eAAe,CAAC,OAAkC;IACzD,IAAM,MAAM,GAA4B,EAAE,CAAC;IAE3C,KAA4C,UAAO,EAAP,mBAAO,EAAP,qBAAO,EAAP,IAAO,EAAE;QAA1C,IAAA,kBAA6B,EAA3B,MAAI,UAAA,EAAE,SAAS,eAAA,EAAE,QAAQ,cAAA;QACpC,MAAM,CAAC,YAAU,MAAM,CAAC,GAAG;YACzB,KAAK,EAAE,SAAS;YAChB,IAAI,QAAA;YACJ,SAAS,WAAA;YACT,QAAQ,UAAA;SACT,CAAC;KACH;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,MAAyB;IAAzB,uBAAA,EAAA,WAAyB;IAC/C,IAAA,KAAiB,MAAM,QAAX,EAAZ,OAAO,mBAAG,EAAE,KAAA,CAAY;IAEhC,OAAO,UAAC,OAAO;QACb,OAAO,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAE/B,OAAO,CAAC,QAAQ,CAAC,UAAC,KAAK,IAAK,OAAA,uBACv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ACD,eAAe,CAAC,IAAI;oBAClB,MAAM,EAAE,GAAG,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;oBAClC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;gBAC9B,CAAC;aACF,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
package/esm/default.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
2
  import { defaultRender } from 'piral-core';
3
- export var DefaultHost = function (props) { return (React.createElement("div", { className: "piral-modals-host", key: "default_modals" }, props.open && React.createElement("div", { className: "piral-modals-overlay" }, props.children))); };
4
- export var DefaultDialog = function (props) { return defaultRender(props.children); };
3
+ export const DefaultHost = (props) => (React.createElement("div", { className: "piral-modals-host" }, props.open && React.createElement("div", { className: "piral-modals-overlay" }, props.children)));
4
+ export const DefaultDialog = (props) => defaultRender(props.children);
5
5
  //# sourceMappingURL=default.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,MAAM,CAAC,IAAM,WAAW,GAA8B,UAAC,KAAK,IAAK,OAAA,CAC/D,6BAAK,SAAS,EAAC,mBAAmB,EAAC,GAAG,EAAC,gBAAgB,IACpD,KAAK,CAAC,IAAI,IAAI,6BAAK,SAAS,EAAC,sBAAsB,IAAE,KAAK,CAAC,QAAQ,CAAO,CACvE,CACP,EAJgE,CAIhE,CAAC;AAEF,MAAM,CAAC,IAAM,aAAa,GAAgC,UAAC,KAAK,IAAK,OAAA,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,EAA7B,CAA6B,CAAC"}
1
+ {"version":3,"file":"default.js","sourceRoot":"","sources":["../src/default.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAG3C,MAAM,CAAC,MAAM,WAAW,GAA8B,CAAC,KAAK,EAAE,EAAE,CAAC,CAC/D,6BAAK,SAAS,EAAC,mBAAmB,IAC/B,KAAK,CAAC,IAAI,IAAI,6BAAK,SAAS,EAAC,sBAAsB,IAAE,KAAK,CAAC,QAAQ,CAAO,CACvE,CACP,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAgC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC"}
package/esm/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ComponentType } from 'react';
2
- import { Dict, WrappedComponent, BaseComponentProps, BaseRegistration, Disposable, AnyComponent, RegistrationDisposer } from 'piral-core';
1
+ import type { ComponentType, ReactNode } from 'react';
2
+ import type { Dict, WrappedComponent, BaseComponentProps, BaseRegistration, Disposable, AnyComponent, RegistrationDisposer } from 'piral-core';
3
3
  declare module 'piral-core/lib/types/custom' {
4
4
  interface PiletCustomApi extends PiletModalsApi {
5
5
  }
@@ -61,8 +61,29 @@ export interface ModalsHostProps {
61
61
  * Callback to invoke closing the modal dialog.
62
62
  */
63
63
  close(): void;
64
+ /**
65
+ * The dialogs to display.
66
+ */
67
+ children?: ReactNode;
64
68
  }
65
69
  export interface ModalsDialogProps extends OpenModalDialog {
70
+ /**
71
+ * The layout options given for the current dialog.
72
+ */
73
+ layout: ModalLayoutOptions;
74
+ /**
75
+ * The provided default options.
76
+ */
77
+ defaults: any;
78
+ /**
79
+ * The content of the dialog to display.
80
+ */
81
+ children?: ReactNode;
82
+ }
83
+ /**
84
+ * The options provided for the dialog layout.
85
+ */
86
+ export interface ModalLayoutOptions {
66
87
  }
67
88
  /**
68
89
  * The error used when a registered modal dialog crashed.
@@ -80,8 +101,16 @@ export interface ModalErrorInfoProps {
80
101
  * Callback for closing the modal programmatically.
81
102
  */
82
103
  onClose(): void;
104
+ /**
105
+ * The name of the pilet emitting the error.
106
+ */
107
+ pilet?: string;
83
108
  }
84
109
  export interface OpenModalDialog {
110
+ /**
111
+ * Gets the ID of the modal to open. For tracking its state.
112
+ */
113
+ id: string;
85
114
  /**
86
115
  * Specifies the fully qualified name of the dialog to show.
87
116
  */
@@ -113,6 +142,7 @@ export interface ModalRegistration extends BaseRegistration {
113
142
  name: string;
114
143
  component: WrappedComponent<ModalComponentProps<any>>;
115
144
  defaults: any;
145
+ layout: ModalLayoutOptions;
116
146
  }
117
147
  export interface BaseModalOptions {
118
148
  }
@@ -120,8 +150,8 @@ export interface PiralCustomModalsMap {
120
150
  }
121
151
  export interface PiralModalsMap extends PiralCustomModalsMap {
122
152
  }
123
- export declare type ModalOptions<T> = T extends keyof PiralModalsMap ? PiralModalsMap[T] & BaseModalOptions : T extends string ? BaseModalOptions : T;
124
- export declare type ModalComponentProps<T> = BaseComponentProps & BareModalComponentProps<ModalOptions<T>>;
153
+ export type ModalOptions<T> = T extends keyof PiralModalsMap ? PiralModalsMap[T] & BaseModalOptions : T extends string ? BaseModalOptions : T;
154
+ export type ModalComponentProps<T> = BaseComponentProps & BareModalComponentProps<ModalOptions<T>>;
125
155
  export interface PiletModalsApi {
126
156
  /**
127
157
  * Shows a modal dialog with the given name.
@@ -137,8 +167,9 @@ export interface PiletModalsApi {
137
167
  * @param name The name of the modal to register.
138
168
  * @param Component The component to render the page.
139
169
  * @param defaults Optionally, sets the default values for the inserted options.
170
+ * @param layout Optionally, sets the layout options for the dialog wrapper.
140
171
  */
141
- registerModal<T>(name: T extends string ? T : string, Component: AnyComponent<ModalComponentProps<T>>, defaults?: ModalOptions<T>): RegistrationDisposer;
172
+ registerModal<T>(name: T extends string ? T : string, Component: AnyComponent<ModalComponentProps<T>>, defaults?: ModalOptions<T>, layout?: ModalLayoutOptions): RegistrationDisposer;
142
173
  /**
143
174
  * Unregisters a modal by its name.
144
175
  * @param name The name that was previously registered.
package/lib/Modals.js CHANGED
@@ -1,37 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Modals = void 0;
4
- var tslib_1 = require("tslib");
5
- var React = require("react");
6
- var piral_core_1 = require("piral-core");
7
- var components_1 = require("./components");
4
+ const React = require("react");
5
+ const piral_core_1 = require("piral-core");
6
+ const components_1 = require("./components");
8
7
  function closeAll(modals) {
9
- modals.forEach(function (m) { return m.close(); });
8
+ modals.forEach((m) => m.close());
10
9
  }
11
10
  function findModal(modals, name) {
12
11
  if (name) {
13
- var modal = Object.keys(modals)
14
- .filter(function (m) { return modals[m].name === name; })
15
- .map(function (m) { return modals[m]; })[0];
12
+ const [modal] = Object.keys(modals)
13
+ .filter((m) => modals[m].name === name)
14
+ .map((m) => modals[m]);
16
15
  return modal;
17
16
  }
18
17
  return undefined;
19
18
  }
20
- exports.Modals = function () {
21
- var modals = piral_core_1.useGlobalState(function (s) { return s.registry.modals; });
22
- var dialogs = piral_core_1.useGlobalState(function (s) { return s.modals; });
23
- var close = function () { return closeAll(dialogs); };
24
- var children = dialogs
25
- .map(function (n) {
26
- var reg = modals[n.name] || findModal(modals, n.alternative);
27
- var Component = reg && reg.component;
28
- var defaults = reg && reg.defaults;
29
- return (Component && (React.createElement(components_1.PiralModalsDialog, tslib_1.__assign({}, n, { key: n.name }),
30
- React.createElement(Component, { onClose: n.close, options: tslib_1.__assign(tslib_1.__assign({}, defaults), n.options) }))));
19
+ const Modals = () => {
20
+ const modals = (0, piral_core_1.useGlobalState)((s) => s.registry.modals);
21
+ const dialogs = (0, piral_core_1.useGlobalState)((s) => s.modals);
22
+ const close = () => closeAll(dialogs);
23
+ const children = dialogs
24
+ .map((n) => {
25
+ const reg = modals[n.name] || findModal(modals, n.alternative);
26
+ const Component = reg && reg.component;
27
+ const defaults = reg && reg.defaults;
28
+ const options = Object.assign(Object.assign({}, defaults), n.options);
29
+ return (Component && (React.createElement(components_1.PiralModalsDialog, Object.assign({}, n, { options: options, defaults: reg.defaults, layout: reg.layout, key: n.name }),
30
+ React.createElement(Component, { onClose: n.close, options: options }))));
31
31
  })
32
- .filter(function (m) { return !!m; });
33
- var open = children.length > 0;
32
+ .filter(Boolean);
33
+ const open = children.length > 0;
34
34
  return (React.createElement(components_1.PiralModalsHost, { open: open, close: close }, children));
35
35
  };
36
+ exports.Modals = Modals;
36
37
  exports.Modals.displayName = 'Modals';
37
38
  //# sourceMappingURL=Modals.js.map
package/lib/Modals.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"Modals.js","sourceRoot":"","sources":["../src/Modals.tsx"],"names":[],"mappings":";;;;AAAA,6BAA+B;AAC/B,yCAA4C;AAC5C,2CAAkE;AAGlE,SAAS,QAAQ,CAAC,MAA8B;IAC9C,MAAM,CAAC,OAAO,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,KAAK,EAAE,EAAT,CAAS,CAAC,CAAC;AACnC,CAAC;AAED,SAAS,SAAS,CAAC,MAAyC,EAAE,IAAY;IACxE,IAAI,IAAI,EAAE;QACD,IAAA,KAAK,GAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;aAChC,MAAM,CAAC,UAAC,CAAC,IAAK,OAAA,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,EAAvB,CAAuB,CAAC;aACtC,GAAG,CAAC,UAAC,CAAC,IAAK,OAAA,MAAM,CAAC,CAAC,CAAC,EAAT,CAAS,CAAC,GAFZ,CAEa;QAEzB,OAAO,KAAK,CAAC;KACd;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAEY,QAAA,MAAM,GAAa;IAC9B,IAAM,MAAM,GAAG,2BAAc,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAjB,CAAiB,CAAC,CAAC;IACxD,IAAM,OAAO,GAAG,2BAAc,CAAC,UAAC,CAAC,IAAK,OAAA,CAAC,CAAC,MAAM,EAAR,CAAQ,CAAC,CAAC;IAChD,IAAM,KAAK,GAAG,cAAM,OAAA,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IAAI;YACjG,oBAAC,SAAS,IAAC,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAI,CAC/B,CACrB,CACF,CAAC;IACJ,CAAC,CAAC;SACD,MAAM,CAAC,OAAO,CAAC,CAAC;IACnB,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC;IAEjC,OAAO,CACL,oBAAC,4BAAe,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,IACtC,QAAQ,CACO,CACnB,CAAC;AACJ,CAAC,CAAC;AA7BW,QAAA,MAAM,UA6BjB;AACF,cAAM,CAAC,WAAW,GAAG,QAAQ,CAAC"}
package/lib/actions.js CHANGED
@@ -1,22 +1,21 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.unregisterModal = exports.registerModal = exports.closeModal = exports.openModal = void 0;
4
- var tslib_1 = require("tslib");
5
- var piral_core_1 = require("piral-core");
4
+ const piral_core_1 = require("piral-core");
6
5
  function openModal(ctx, dialog) {
7
- ctx.dispatch(function (state) { return (tslib_1.__assign(tslib_1.__assign({}, state), { modals: piral_core_1.prependItem(state.modals, dialog) })); });
6
+ ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { modals: (0, piral_core_1.prependItem)(state.modals, dialog) })));
8
7
  }
9
8
  exports.openModal = openModal;
10
9
  function closeModal(ctx, dialog) {
11
- ctx.dispatch(function (state) { return (tslib_1.__assign(tslib_1.__assign({}, state), { modals: piral_core_1.excludeItem(state.modals, dialog) })); });
10
+ ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { modals: (0, piral_core_1.excludeOn)(state.modals, (modal) => modal.id === dialog.id) })));
12
11
  }
13
12
  exports.closeModal = closeModal;
14
13
  function registerModal(ctx, name, value) {
15
- ctx.dispatch(function (state) { return (tslib_1.__assign(tslib_1.__assign({}, state), { registry: tslib_1.__assign(tslib_1.__assign({}, state.registry), { modals: piral_core_1.withKey(state.registry.modals, name, value) }) })); });
14
+ ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { modals: (0, piral_core_1.withKey)(state.registry.modals, name, value) }) })));
16
15
  }
17
16
  exports.registerModal = registerModal;
18
17
  function unregisterModal(ctx, name) {
19
- ctx.dispatch(function (state) { return (tslib_1.__assign(tslib_1.__assign({}, state), { registry: tslib_1.__assign(tslib_1.__assign({}, state.registry), { modals: piral_core_1.withoutKey(state.registry.modals, name) }) })); });
18
+ ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { registry: Object.assign(Object.assign({}, state.registry), { modals: (0, piral_core_1.withoutKey)(state.registry.modals, name) }) })));
20
19
  }
21
20
  exports.unregisterModal = unregisterModal;
22
21
  //# sourceMappingURL=actions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"actions.js","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":";;;;AAAA,yCAA+F;AAG/F,SAAgB,SAAS,CAAC,GAAuB,EAAE,MAAuB;IACxE,GAAG,CAAC,QAAQ,CAAC,UAAC,KAAK,IAAK,OAAA,uCACnB,KAAK,KACR,MAAM,EAAE,wBAAW,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,IACzC,EAHsB,CAGtB,CAAC,CAAC;AACN,CAAC;AALD,8BAKC;AAED,SAAgB,UAAU,CAAC,GAAuB,EAAE,MAAuB;IACzE,GAAG,CAAC,QAAQ,CAAC,UAAC,KAAK,IAAK,OAAA,uCACnB,KAAK,KACR,MAAM,EAAE,wBAAW,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,IACzC,EAHsB,CAGtB,CAAC,CAAC;AACN,CAAC;AALD,gCAKC;AAED,SAAgB,aAAa,CAAC,GAAuB,EAAE,IAAY,EAAE,KAAwB;IAC3F,GAAG,CAAC,QAAQ,CAAC,UAAC,KAAK,IAAK,OAAA,uCACnB,KAAK,KACR,QAAQ,wCACH,KAAK,CAAC,QAAQ,KACjB,MAAM,EA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O,EAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,CAAC,OAErD,CAAC,CAAC;AACN,CAAC;AARD,sCAQC;AAED,SAAgB,eAAe,CAAC,GAAuB,EAAE,IAAY;IACnE,GAAG,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCACnB,KAAK,KACR,QAAQ,kCACH,KAAK,CAAC,QAAQ,KACjB,MAAM,EAAE,IAAA,uBAAU,EAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,OAEjD,CAAC,CAAC;AACN,CAAC;AARD,0CAQC"}
@@ -1,4 +1,3 @@
1
- import * as React from 'react';
2
- import { ModalsHostProps, ModalsDialogProps } from './types';
3
- export declare const PiralModalsHost: React.ComponentType<ModalsHostProps>;
4
- export declare const PiralModalsDialog: React.ComponentType<ModalsDialogProps>;
1
+ /// <reference types="react" />
2
+ export declare const PiralModalsHost: import("react").ComponentType<import("./types").ModalsHostProps>;
3
+ export declare const PiralModalsDialog: import("react").ComponentType<import("./types").ModalsDialogProps>;
package/lib/components.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PiralModalsDialog = exports.PiralModalsHost = void 0;
4
- var piral_core_1 = require("piral-core");
5
- exports.PiralModalsHost = piral_core_1.getPiralComponent('ModalsHost');
6
- exports.PiralModalsDialog = piral_core_1.getPiralComponent('ModalsDialog');
4
+ const piral_core_1 = require("piral-core");
5
+ exports.PiralModalsHost = (0, piral_core_1.getPiralComponent)('ModalsHost');
6
+ exports.PiralModalsDialog = (0, piral_core_1.getPiralComponent)('ModalsDialog');
7
7
  //# sourceMappingURL=components.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":";;;AACA,yCAA+C;AAGlC,QAAA,eAAe,GAAyC,8BAAiB,CAAC,YAAY,CAAC,CAAC;AACxF,QAAA,iBAAiB,GAA2C,8BAAiB,CAAC,cAAc,CAAC,CAAC"}
1
+ {"version":3,"file":"components.js","sourceRoot":"","sources":["../src/components.tsx"],"names":[],"mappings":";;;AAAA,2CAA+C;AAElC,QAAA,eAAe,GAAG,IAAA,8BAAiB,EAAC,YAAY,CAAC,CAAC;AAClD,QAAA,iBAAiB,GAAG,IAAA,8BAAiB,EAAC,cAAc,CAAC,CAAC"}
package/lib/create.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ComponentType } from 'react';
2
2
  import { PiralPlugin } from 'piral-core';
3
- import { PiletModalsApi, BareModalComponentProps } from './types';
3
+ import { PiletModalsApi, BareModalComponentProps, ModalLayoutOptions } from './types';
4
4
  export interface InitialModalDialog {
5
5
  /**
6
6
  * The name of the modal dialog.
@@ -13,7 +13,11 @@ export interface InitialModalDialog {
13
13
  /**
14
14
  * The default options for the modal dialog.
15
15
  */
16
- defaults: any;
16
+ defaults?: any;
17
+ /**
18
+ * The layout options for the modal dialog.
19
+ */
20
+ layout?: ModalLayoutOptions;
17
21
  }
18
22
  /**
19
23
  * Available configuration options for the modals plugin.
@@ -23,6 +27,13 @@ export interface ModalsConfig {
23
27
  * The initial modal dialogs.
24
28
  */
25
29
  dialogs?: Array<InitialModalDialog>;
30
+ /**
31
+ * Defines how the next ID for the key is selected.
32
+ * By default a random number is used.
33
+ *
34
+ * @param name The name of the modal dialog.
35
+ */
36
+ selectId?(name: string): string;
26
37
  }
27
38
  /**
28
39
  * Creates new Pilet API extensions for support modal dialogs.