@talend/react-cmf-cqrs
Version:
@talend/react-cmf plugin for CQRS backend architecture
1,301 lines (1,146 loc) • 205 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["TalendReactCmfCqrs"] = factory();
else
root["TalendReactCmfCqrs"] = factory();
})(this, () => {
return /******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/actions/ack.js":
/*!****************************!*\
!*** ./src/actions/ack.js ***!
\****************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ addContext: () => (/* binding */ addContext),
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
/* harmony export */ deleteACK: () => (/* binding */ deleteACK),
/* harmony export */ receiveMessage: () => (/* binding */ receiveMessage)
/* harmony export */ });
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../constants */ "./src/constants/index.js");
function addContext(event, data) {
return {
type: _constants__WEBPACK_IMPORTED_MODULE_0__.ACK_ADD_CONTEXT,
...data
};
}
function receiveMessage(event, data) {
return {
type: _constants__WEBPACK_IMPORTED_MODULE_0__.ACK_RECEIVE_MESSAGE,
...data
};
}
function deleteACK(event, data) {
return {
type: _constants__WEBPACK_IMPORTED_MODULE_0__.ACK_DELETE,
...data
};
}
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
addContext,
receiveMessage
});
/***/ }),
/***/ "./src/actions/index.js":
/*!******************************!*\
!*** ./src/actions/index.js ***!
\******************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _ack__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ack */ "./src/actions/ack.js");
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
ack: _ack__WEBPACK_IMPORTED_MODULE_0__["default"]
});
/***/ }),
/***/ "./src/components/ACKDispatcher/ACKDispatcher.connect.js":
/*!***************************************************************!*\
!*** ./src/components/ACKDispatcher/ACKDispatcher.connect.js ***!
\***************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
/* harmony export */ mapStateToProps: () => (/* binding */ mapStateToProps)
/* harmony export */ });
/* harmony import */ var _talend_react_cmf__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @talend/react-cmf */ "@talend/react-cmf");
/* harmony import */ var _talend_react_cmf__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_talend_react_cmf__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _ACKDispatcher_container__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./ACKDispatcher.container */ "./src/components/ACKDispatcher/ACKDispatcher.container.js");
function mapStateToProps(state) {
return {
acks: state.ack
};
}
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_talend_react_cmf__WEBPACK_IMPORTED_MODULE_0__.cmfConnect)({
componentId: 'ACKDispatcher',
// can be a function
defaultState: _ACKDispatcher_container__WEBPACK_IMPORTED_MODULE_1__.DEFAULT_STATE,
mapStateToProps
})(_ACKDispatcher_container__WEBPACK_IMPORTED_MODULE_1__["default"]));
/***/ }),
/***/ "./src/components/ACKDispatcher/ACKDispatcher.container.js":
/*!*****************************************************************!*\
!*** ./src/components/ACKDispatcher/ACKDispatcher.container.js ***!
\*****************************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ DEFAULT_STATE: () => (/* binding */ DEFAULT_STATE),
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! prop-types */ "prop-types");
/* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(prop_types__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var immutable__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! immutable */ "immutable");
/* harmony import */ var immutable__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(immutable__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var _talend_react_cmf__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @talend/react-cmf */ "@talend/react-cmf");
/* harmony import */ var _talend_react_cmf__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_talend_react_cmf__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var _talend_utils__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @talend/utils */ "../utils/lib-esm/index.js");
/* harmony import */ var _actions_ack__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../../actions/ack */ "./src/actions/ack.js");
const DEFAULT_STATE = new immutable__WEBPACK_IMPORTED_MODULE_2__.Map({});
/**
* {
type: 'ACK_ADD_CONTEXT',
requestId: '123',
data: { foo: 'bar' },
actionCreator: 'dataset:fetchAll'
}
{
type: 'ACK_RECEIVE_MESSAGE',
requestId: '123',
}
*/
const cache = {};
function ACKDispatcher(props) {
const context = (0,_talend_react_cmf__WEBPACK_IMPORTED_MODULE_3__.useCMFContext)();
const [uuid] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)((0,_talend_utils__WEBPACK_IMPORTED_MODULE_4__.randomUUID)());
if (!cache[uuid]) {
cache[uuid] = [];
}
const dispatchedAck = cache[uuid];
function dispatchAndUpdateAck(actionCreator, data, requestId) {
const action = _talend_react_cmf__WEBPACK_IMPORTED_MODULE_3___default().actionCreator.get(context, actionCreator)({}, data, context);
action.ack = (0,_actions_ack__WEBPACK_IMPORTED_MODULE_5__.deleteACK)(null, {
requestId
});
props.dispatch(action);
if (!dispatchedAck.includes(requestId)) {
cache[uuid].push(requestId);
}
}
(props.acks || []).filter(ack => ack.get('received') === true && ack.get('actionCreator')).forEach((ack, requestId) => {
let data = ack.get('data');
if (data === undefined) {
data = {};
}
dispatchAndUpdateAck(ack.get('actionCreator'), data, requestId);
});
return null;
}
ACKDispatcher.propTypes = {
acks: (prop_types__WEBPACK_IMPORTED_MODULE_1___default().object),
// eslint-disable-line react/forbid-prop-types
..._talend_react_cmf__WEBPACK_IMPORTED_MODULE_3__.cmfConnect.propTypes
};
ACKDispatcher.displayName = 'Container(ACKDispatcher)';
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (ACKDispatcher);
/***/ }),
/***/ "./src/components/ACKDispatcher/index.js":
/*!***********************************************!*\
!*** ./src/components/ACKDispatcher/index.js ***!
\***********************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _ACKDispatcher_connect__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ACKDispatcher.connect */ "./src/components/ACKDispatcher/ACKDispatcher.connect.js");
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_ACKDispatcher_connect__WEBPACK_IMPORTED_MODULE_0__["default"]);
/***/ }),
/***/ "./src/constants/ack.js":
/*!******************************!*\
!*** ./src/constants/ack.js ***!
\******************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ ACK_ADD_CONTEXT: () => (/* binding */ ACK_ADD_CONTEXT),
/* harmony export */ ACK_DELETE: () => (/* binding */ ACK_DELETE),
/* harmony export */ ACK_RECEIVE_MESSAGE: () => (/* binding */ ACK_RECEIVE_MESSAGE)
/* harmony export */ });
const ACK_ADD_CONTEXT = 'ACK_ADD_CONTEXT';
const ACK_RECEIVE_MESSAGE = 'ACK_RECEIVE_MESSAGE';
const ACK_DELETE = 'ACK_DELETE';
/***/ }),
/***/ "./src/constants/index.js":
/*!********************************!*\
!*** ./src/constants/index.js ***!
\********************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ ACK_ADD_CONTEXT: () => (/* reexport safe */ _ack__WEBPACK_IMPORTED_MODULE_0__.ACK_ADD_CONTEXT),
/* harmony export */ ACK_DELETE: () => (/* reexport safe */ _ack__WEBPACK_IMPORTED_MODULE_0__.ACK_DELETE),
/* harmony export */ ACK_RECEIVE_MESSAGE: () => (/* reexport safe */ _ack__WEBPACK_IMPORTED_MODULE_0__.ACK_RECEIVE_MESSAGE),
/* harmony export */ SOCKET_ON_CLOSE: () => (/* reexport safe */ _socketMiddleware__WEBPACK_IMPORTED_MODULE_1__.SOCKET_ON_CLOSE),
/* harmony export */ SOCKET_ON_ERROR: () => (/* reexport safe */ _socketMiddleware__WEBPACK_IMPORTED_MODULE_1__.SOCKET_ON_ERROR),
/* harmony export */ SOCKET_ON_OPEN: () => (/* reexport safe */ _socketMiddleware__WEBPACK_IMPORTED_MODULE_1__.SOCKET_ON_OPEN),
/* harmony export */ SOCKET_ON_PING_TIMEOUT: () => (/* reexport safe */ _socketMiddleware__WEBPACK_IMPORTED_MODULE_1__.SOCKET_ON_PING_TIMEOUT),
/* harmony export */ WEBSOCKET_READY_STATE: () => (/* reexport safe */ _status__WEBPACK_IMPORTED_MODULE_2__.WEBSOCKET_READY_STATE)
/* harmony export */ });
/* harmony import */ var _ack__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ack */ "./src/constants/ack.js");
/* harmony import */ var _socketMiddleware__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./socketMiddleware */ "./src/constants/socketMiddleware.js");
/* harmony import */ var _status__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./status */ "./src/constants/status.js");
/***/ }),
/***/ "./src/constants/socketMiddleware.js":
/*!*******************************************!*\
!*** ./src/constants/socketMiddleware.js ***!
\*******************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ SOCKET_ON_CLOSE: () => (/* binding */ SOCKET_ON_CLOSE),
/* harmony export */ SOCKET_ON_ERROR: () => (/* binding */ SOCKET_ON_ERROR),
/* harmony export */ SOCKET_ON_OPEN: () => (/* binding */ SOCKET_ON_OPEN),
/* harmony export */ SOCKET_ON_PING_TIMEOUT: () => (/* binding */ SOCKET_ON_PING_TIMEOUT)
/* harmony export */ });
const SOCKET_ON_OPEN = '@@SOCKET.ON_OPEN';
const SOCKET_ON_CLOSE = '@@SOCKET.ON_CLOSE';
const SOCKET_ON_ERROR = '@@SOCKET.ON_ERROR';
const SOCKET_ON_PING_TIMEOUT = '@@SOCKET.ON_PING_TIMEOUT';
/***/ }),
/***/ "./src/constants/status.js":
/*!*********************************!*\
!*** ./src/constants/status.js ***!
\*********************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ WEBSOCKET_READY_STATE: () => (/* binding */ WEBSOCKET_READY_STATE)
/* harmony export */ });
const WEBSOCKET_READY_STATE = {
UNINSTANTIATED: -1,
CONNECTING: 0,
OPEN: 1,
CLOSING: 2,
CLOSED: 3
};
/***/ }),
/***/ "./src/middleware/index.js":
/*!*********************************!*\
!*** ./src/middleware/index.js ***!
\*********************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _smartWebsocket__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./smartWebsocket */ "./src/middleware/smartWebsocket.js");
/* harmony import */ var _socketMiddleware__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./socketMiddleware */ "./src/middleware/socketMiddleware.js");
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
smartWebsocket: _smartWebsocket__WEBPACK_IMPORTED_MODULE_0__["default"],
createWebsocketMiddleware: _socketMiddleware__WEBPACK_IMPORTED_MODULE_1__["default"]
});
/***/ }),
/***/ "./src/middleware/smartWebsocket.js":
/*!******************************************!*\
!*** ./src/middleware/smartWebsocket.js ***!
\******************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ SmartWebsocket),
/* harmony export */ startWebsocket: () => (/* binding */ startWebsocket),
/* harmony export */ wsIsClosed: () => (/* binding */ wsIsClosed),
/* harmony export */ wsSend: () => (/* binding */ wsSend)
/* harmony export */ });
/* harmony import */ var _registry__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../registry */ "./src/registry.js");
/**
* Send message on ws if available.
* feed the offlineBuffer if it is not
*/
function wsSend(ws, message, callback, offlinebuffer) {
if (ws.readyState === WebSocket.OPEN) {
ws.send(message);
if (typeof callback === 'function') {
callback();
}
} else {
offlinebuffer.push({
message,
callback
});
}
}
/**
* if is closed or not defined start a new ws
*/
function wsIsClosed(ws) {
return !ws || ws.readyState === WebSocket.CLOSED;
}
/**
* initialise a websocket
* on open connection, try to send messages stored in offline buffer
*/
function startWebsocket(url, offlinebuffer, options) {
const {
onMessage,
onOpen,
onClose,
onError,
onPing,
onPingTimeout
} = options;
const ws = new WebSocket(url);
let pingIntervalId;
let pingTimeoutId;
ws.onopen = function onopen(event) {
if (typeof onOpen === 'function') {
onOpen(event);
}
// copy data in local array since offline buffer may be used in this process
// in case we loose again ou connection
const localBuffer = offlinebuffer.slice(0);
offlinebuffer.reset();
if (localBuffer.length > 0) {
localBuffer.forEach(msg => wsSend(ws, msg.message, msg.callback, offlinebuffer));
}
ws.ping();
pingIntervalId = setInterval(ws.ping, options.pingInterval || 50000);
};
ws.onmessage = function onmessage(messageEvent) {
if (typeof onMessage === 'function') {
onMessage(messageEvent);
}
};
ws.onclose = function onclose(closeEvent) {
if (typeof onClose === 'function') {
onClose(closeEvent);
}
if (pingIntervalId) {
clearInterval(pingIntervalId);
}
if (pingTimeoutId) {
clearTimeout(pingTimeoutId);
}
};
ws.onerror = function onerror(event) {
if (typeof onError === 'function') {
onError(event);
}
};
ws.ping = function ping() {
if (typeof onPing === 'function') {
if (!isNaN(options.pingTimeoutDelay)) {
pingTimeoutId = setTimeout(ws.onpingtimeout, options.pingTimeoutDelay);
}
onPing({
pingTimeoutId
});
}
ws.send('{"type":"PING"}');
};
ws.onpingtimeout = function onpingtimeout() {
if (typeof onPingTimeout === 'function') {
onPingTimeout();
}
ws.close();
};
function wsStillNotYetOpened() {
if (ws.readyState === WebSocket.CONNECTING) {
ws.onpingtimeout();
}
}
if (!isNaN(options.pingTimeoutDelay)) {
setTimeout(wsStillNotYetOpened, options.pingTimeoutDelay);
}
return ws;
}
/**
* create a new smart websocket featuring
* automatic reconnection
* message pooling in case of connection loss
* @param url
* @param options
*/
function SmartWebsocket(url, options = {}, id = 'default') {
let ws;
const offlinebuffer = [];
offlinebuffer.reset = () => {
offlinebuffer.length = 0;
};
const send = (message, callback) => wsSend(ws, message, callback, offlinebuffer);
const start = () => {
ws = startWebsocket(url, offlinebuffer, options);
(0,_registry__WEBPACK_IMPORTED_MODULE_0__.addWebsocketToRegistry)(ws, id);
};
start();
const restartIfClosed = () => {
if (wsIsClosed(ws)) {
start();
}
};
const stop = setInterval(restartIfClosed, options.checkInterval || 5000);
return {
send,
close() {
clearInterval(stop);
return ws.close();
},
getBufferedAmount() {
return ws.bufferedAmount;
},
getReadyState() {
return ws.readyState;
},
getUrl() {
return ws.url;
}
};
}
/***/ }),
/***/ "./src/middleware/socketMiddleware.js":
/*!********************************************!*\
!*** ./src/middleware/socketMiddleware.js ***!
\********************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
/* harmony export */ isAbsoluteWebSocketUrl: () => (/* binding */ isAbsoluteWebSocketUrl)
/* harmony export */ });
/* harmony import */ var _smartWebsocket__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./smartWebsocket */ "./src/middleware/smartWebsocket.js");
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants */ "./src/constants/index.js");
// if host is localhost connect directly to the localhost backend
// else connect to the actual host
const host = window.location.host;
let protocol = 'ws';
if (window.location.protocol === 'https:') {
protocol = 'wss';
}
/**
* @param socketUrl
* @returns {boolean} true if it starts with a WS protocol
*/
function isAbsoluteWebSocketUrl(socketUrl) {
return typeof socketUrl === 'string' && (socketUrl.startsWith('ws://') || socketUrl.startsWith('wss://'));
}
/**
* select part of the state to create patch between two state
*
* @param socketUrl {string} url to web socket relay
* @param actionListeners {array<function>} function exectuted
* on each action going trought this middleware
* @param socketListener {array<function>} function executed
* on each message send to this ws listenner
*
* @return {object} result
*
*/
function createWebsocketMiddleware(socketUrl, actionListeners = [], socketListener = [], socketOptions = {}) {
const buffer = [];
let ws;
let url;
if (isAbsoluteWebSocketUrl(socketUrl)) {
url = socketUrl;
} else {
url = `${protocol}://${host}${socketUrl}`;
}
function send() {
actionListeners.forEach(actionListener => {
buffer.forEach((entrie, key) => {
const {
previousState,
action
} = entrie;
let nextState = entrie.nextState;
const nextEntry = buffer[key + 1];
if (nextEntry) {
nextState = nextEntry.previousState;
}
const message = actionListener(previousState, action, nextState);
if (message) {
ws.send(message);
}
});
});
buffer.length = 0;
}
return ({
getState,
dispatch
}) => next => action => {
if (!ws) {
ws = new _smartWebsocket__WEBPACK_IMPORTED_MODULE_0__["default"](url, {
onOpen: () => dispatch({
type: _constants__WEBPACK_IMPORTED_MODULE_1__.SOCKET_ON_OPEN
}),
onClose: event => dispatch({
type: _constants__WEBPACK_IMPORTED_MODULE_1__.SOCKET_ON_CLOSE,
event
}),
onMessage: messageEvent => {
socketListener.forEach(func => func(messageEvent, dispatch, getState, ws));
},
onError: event => {
dispatch({
type: _constants__WEBPACK_IMPORTED_MODULE_1__.SOCKET_ON_ERROR,
event
});
},
onPing: event => {
ws.pingTimeoutId = event.pingTimeoutId;
},
onPingTimeout: () => {
dispatch({
type: _constants__WEBPACK_IMPORTED_MODULE_1__.SOCKET_ON_PING_TIMEOUT
});
},
...socketOptions
});
}
const entrie = {};
buffer.push(entrie);
entrie.action = action;
entrie.previousState = getState();
const result = next(action);
entrie.nextState = getState();
send();
return result;
};
}
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (createWebsocketMiddleware);
/***/ }),
/***/ "./src/reducers/ack.js":
/*!*****************************!*\
!*** ./src/reducers/ack.js ***!
\*****************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ ackProcessed: () => (/* binding */ ackProcessed),
/* harmony export */ "default": () => (/* binding */ ackReducer)
/* harmony export */ });
/* harmony import */ var immutable__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! immutable */ "immutable");
/* harmony import */ var immutable__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(immutable__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _constants_index__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants/index */ "./src/constants/index.js");
const DEFAULT_STATE = new immutable__WEBPACK_IMPORTED_MODULE_0__.Map({});
/**
* ackReducer
* @param {Object} state redux
* @param {Object} action redux
* @return {Object} new state
*/
function ackReducer(state = DEFAULT_STATE, action) {
switch (action.type) {
case _constants_index__WEBPACK_IMPORTED_MODULE_1__.ACK_ADD_CONTEXT:
return state.setIn([action.requestId, 'data'], action.data).setIn([action.requestId, 'actionCreator'], action.actionCreator);
case _constants_index__WEBPACK_IMPORTED_MODULE_1__.ACK_RECEIVE_MESSAGE:
return state.setIn([action.requestId, 'received'], true);
case _constants_index__WEBPACK_IMPORTED_MODULE_1__.ACK_DELETE:
return state.remove(action.requestId);
default:
return state;
}
}
function ackProcessed(state, action) {
if (action.ack) {
const newState = {
...state,
ack: ackReducer(state.ack, action.ack)
};
return newState;
}
return state;
}
/***/ }),
/***/ "./src/reducers/index.js":
/*!*******************************!*\
!*** ./src/reducers/index.js ***!
\*******************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _ack__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ack */ "./src/reducers/ack.js");
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
ack: _ack__WEBPACK_IMPORTED_MODULE_0__["default"]
});
/***/ }),
/***/ "./src/registry.js":
/*!*************************!*\
!*** ./src/registry.js ***!
\*************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ addWebsocketToRegistry: () => (/* binding */ addWebsocketToRegistry),
/* harmony export */ getWebSocketFromRegistry: () => (/* binding */ getWebSocketFromRegistry),
/* harmony export */ removeWebSocketFromRegistry: () => (/* binding */ removeWebSocketFromRegistry)
/* harmony export */ });
const websockets = {};
const addWebsocketToRegistry = (ws, id = 'default') => {
websockets[id] = ws;
};
const getWebSocketFromRegistry = (id = 'default') => {
return websockets[id];
};
const removeWebSocketFromRegistry = (id = 'default') => {
delete websockets[id];
};
/***/ }),
/***/ "./src/sagas/ack.js":
/*!**************************!*\
!*** ./src/sagas/ack.js ***!
\**************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var redux_saga_effects__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! redux-saga/effects */ "redux-saga/effects");
/* harmony import */ var redux_saga_effects__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(redux_saga_effects__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../constants */ "./src/constants/index.js");
/**
* this module define a high level API to handle ack in sagas
* @module react-cmf-cqrs/lib/sagas/ack
* @example
import { channel } from 'redux-saga';
import { fork, take, put, race, call, select } from 'redux-saga/effects';
import { sagas } from '@talend/react-cmf-cqrs';
function* onMyButtonClicked() {
const requestId = objectID().toString();
const chan = yield call(channel);
yield fork(ack.listen, chan);
const action = ... //action with ack and requestId
yield put(action);
yield call(ack.check, chan, requestId);
}
*/
/**
* this function let you listen a channel ACK_RECEIVE_MESSAGE
* @param {Object} channel redux-saga channel
*/
function* listen(chan) {
// eslint-disable-next-line no-constant-condition
while (true) {
const action = yield (0,redux_saga_effects__WEBPACK_IMPORTED_MODULE_0__.take)(_constants__WEBPACK_IMPORTED_MODULE_1__.ACK_RECEIVE_MESSAGE);
yield (0,redux_saga_effects__WEBPACK_IMPORTED_MODULE_0__.put)(chan, action.requestId);
}
}
/**
* this function will wait for the ack to be filled.
* @param {Object} channel redux-saga channel instance
* @param {string} requestId the requestId to check in the channel
*/
function* check(chan, requestId) {
let ackRequestId;
do {
ackRequestId = yield (0,redux_saga_effects__WEBPACK_IMPORTED_MODULE_0__.take)(chan);
} while (ackRequestId !== requestId);
return true;
}
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
listen,
check
});
/***/ }),
/***/ "./src/sagas/index.js":
/*!****************************!*\
!*** ./src/sagas/index.js ***!
\****************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _ack__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./ack */ "./src/sagas/ack.js");
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
ack: _ack__WEBPACK_IMPORTED_MODULE_0__["default"]
});
/***/ }),
/***/ "./src/useWebSocket.hook.ts":
/*!**********************************!*\
!*** ./src/useWebSocket.hook.ts ***!
\**********************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ useWebSocket: () => (/* binding */ useWebSocket)
/* harmony export */ });
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react");
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _constants__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./constants */ "./src/constants/index.js");
/* harmony import */ var _registry__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./registry */ "./src/registry.js");
const useWebSocket = (messageFilterFunction = () => true, id = 'default') => {
var _websocketRef$current2;
const websocketRef = (0,react__WEBPACK_IMPORTED_MODULE_0__.useRef)();
const [lastMessage, setLastMessage] = (0,react__WEBPACK_IMPORTED_MODULE_0__.useState)();
const sendMessage = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(message => {
var _websocketRef$current;
if (((_websocketRef$current = websocketRef.current) === null || _websocketRef$current === void 0 ? void 0 : _websocketRef$current.readyState) === _constants__WEBPACK_IMPORTED_MODULE_1__.WEBSOCKET_READY_STATE.OPEN) {
websocketRef.current.send(message);
}
}, []);
const sendJsonMessage = (0,react__WEBPACK_IMPORTED_MODULE_0__.useCallback)(message => {
sendMessage(JSON.stringify(message));
}, [sendMessage]);
const onMessage = messageEvent => {
const data = JSON.parse(messageEvent.data);
if (messageFilterFunction(data)) {
setLastMessage({
message: messageEvent,
jsonData: data
});
}
};
(0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(() => {
const ws = (0,_registry__WEBPACK_IMPORTED_MODULE_2__.getWebSocketFromRegistry)(id);
websocketRef.current = ws;
if (ws) {
ws.addEventListener('message', onMessage);
}
return () => {
if (ws) {
ws.removeEventListener('message', onMessage);
}
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
return {
lastJsonMessage: lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.jsonData,
lastMessage: lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.message,
readyState: (_websocketRef$current2 = websocketRef.current) === null || _websocketRef$current2 === void 0 ? void 0 : _websocketRef$current2.readyState,
sendMessage,
sendJsonMessage
};
};
/***/ }),
/***/ "../utils/lib-esm/date/generator.js":
/*!******************************************!*\
!*** ../utils/lib-esm/date/generator.js ***!
\******************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ buildWeeks: () => (/* binding */ buildWeeks)
/* harmony export */ });
/* harmony import */ var date_fns_addDays__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! date-fns/addDays */ "../../node_modules/date-fns/addDays.mjs");
/* harmony import */ var date_fns_startOfWeek__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! date-fns/startOfWeek */ "../../node_modules/date-fns/startOfWeek.mjs");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "lodash");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
/**
* Generate the set of weeks for a specific month
*/
function buildWeeks(year, monthIndex, firstDayOfWeek = 1) {
const firstDateOfMonth = new Date(year, monthIndex);
const firstDateOfCalendar = (0,date_fns_startOfWeek__WEBPACK_IMPORTED_MODULE_1__.startOfWeek)(firstDateOfMonth, {
weekStartsOn: firstDayOfWeek
});
const dates = new Array(7 * 6).fill(0).map((_, i) => (0,date_fns_addDays__WEBPACK_IMPORTED_MODULE_2__.addDays)(firstDateOfCalendar, i));
return (0,lodash__WEBPACK_IMPORTED_MODULE_0__.chunk)(dates, 7);
}
/***/ }),
/***/ "../utils/lib-esm/date/index.js":
/*!**************************************!*\
!*** ../utils/lib-esm/date/index.js ***!
\**************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ FORMAT: () => (/* binding */ FORMAT),
/* harmony export */ buildWeeks: () => (/* binding */ buildWeeks),
/* harmony export */ convertToLocalTime: () => (/* binding */ convertToLocalTime),
/* harmony export */ convertToTimeZone: () => (/* binding */ convertToTimeZone),
/* harmony export */ convertToUTC: () => (/* binding */ convertToUTC),
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__),
/* harmony export */ format: () => (/* binding */ format),
/* harmony export */ formatReadableUTCOffset: () => (/* binding */ formatReadableUTCOffset),
/* harmony export */ formatToTimeZone: () => (/* binding */ formatToTimeZone),
/* harmony export */ formatToUnicode: () => (/* binding */ formatToUnicode),
/* harmony export */ getUTCOffset: () => (/* binding */ getUTCOffset),
/* harmony export */ timeZoneExists: () => (/* binding */ timeZoneExists)
/* harmony export */ });
/* harmony import */ var date_fns_format__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! date-fns/format */ "../../node_modules/date-fns/format.mjs");
/* harmony import */ var date_fns_parseISO__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! date-fns/parseISO */ "../../node_modules/date-fns/parseISO.mjs");
/* harmony import */ var _generator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./generator */ "../utils/lib-esm/date/generator.js");
/**
* Get the offset between a timezone and the UTC time (in minutes)
* @param {string} timeZone Timezone IANA name
* @param {Date} date (optional) When specified, will be instead of default current time
* @returns {Number}
*
* @see https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
*/
function getUTCOffset(timeZone, date) {
// Build localized formats for UTC and the target timezone
const formatOptions = {
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric'
};
const locale = 'en-US';
const utcFormat = new Intl.DateTimeFormat(locale, {
...formatOptions,
timeZone: 'Etc/UTC'
});
const timezoneFormat = new Intl.DateTimeFormat(locale, {
...formatOptions,
timeZone
});
// Create the same date in UTC timezone and the target timezone
const dateObj = date || new Date();
const utcDate = new Date(utcFormat.format(dateObj));
const timezoneDate = new Date(timezoneFormat.format(dateObj));
// Compute delta between dates
return (timezoneDate.getTime() - utcDate.getTime()) / (1000 * 60);
}
/**
* Format an UTC offset from minutes to [+/-][HH][separator][mm]
* @param {Number} offset UTC offset
* @param {string} separator Separator between hours and minutes
* @returns {string} Formatted UTC offset
*/
function formatUTCOffset(offset, separator) {
const sign = offset >= 0 ? '+' : '-';
const absoluteOffset = Math.abs(offset);
const min = absoluteOffset % 60;
const hours = (absoluteOffset - min) / 60;
const paddedHours = hours.toString().padStart(2, '0');
const paddedMin = min.toString().padStart(2, '0');
return `${sign}${paddedHours}${separator}${paddedMin}`;
}
/**
* Format a human-readable UTC offset
* @param offset Timezone offset to UTC expressed in minutes
* @returns The human readable offset (+03:00, -06:00 ...)
*/
function formatReadableUTCOffset(offset) {
return formatUTCOffset(offset, ':');
}
/**
* Replace timezone token(s) in the date format pattern to a specific timezone's value(s).
* This should be maintained along with the date-fns formats (see linked API doc).
* @param {string} dateFormat
* @param {string} timeZone
* @returns {string}
*
* @see https://date-fns.org/v1.27.2/docs/format
* @see https://github.com/prantlf/date-fns-timezone/blob/master/src/formatToTimeZone.js#L131
*/
function formatTimeZoneTokens(dateFormat, timeZone) {
return dateFormat.replace(/(z|ZZ?)(?!\])/g, match => {
const offset = getUTCOffset(timeZone);
const separator = match === 'Z' ? ':' : '';
return formatUTCOffset(offset, separator);
});
}
/**
* Converts the given date from the given time zone to the local time and returns a new Date object.
* @param {DateFnsFormatInput} date Date to format
* @param {ConversionOptions} options
* @returns {Date}
*
* @see https://github.com/prantlf/date-fns-timezone/blob/HEAD/docs/API.md#converttolocaltime
*/
function convertToLocalTime(date, options) {
const parsedDate = (0,date_fns_parseISO__WEBPACK_IMPORTED_MODULE_1__.parseISO)(new Date(date).toISOString());
const offset = getUTCOffset(options.timeZone) + parsedDate.getTimezoneOffset();
return new Date(parsedDate.getTime() - offset * 60 * 1000);
}
/**
* Converts the given date from the local time (or from specified source timezone) to
* the given timezone and returns a new Date object.
* @param {DateFnsFormatInput} date Date to format
* @param {ConversionOptions} options
* @returns {Date}
*
* @see https://github.com/prantlf/date-fns-timezone/blob/master/src/convertToTimeZone.js
*/
function convertToTimeZone(date, options) {
const {
timeZone,
sourceTimeZone
} = options;
const parsedDate = (0,date_fns_parseISO__WEBPACK_IMPORTED_MODULE_1__.parseISO)(new Date(date).toISOString());
let offset = getUTCOffset(timeZone, parsedDate) + parsedDate.getTimezoneOffset();
if (sourceTimeZone) {
offset -= parsedDate.getTimezoneOffset();
offset -= getUTCOffset(sourceTimeZone, parsedDate);
}
return new Date(parsedDate.getTime() + offset * 60 * 1000);
}
function formatToUnicode(formatString) {
// See: https://date-fns.org/v2.16.1/docs/format
return formatString
// Characters are now escaped using single quote symbols (') instead of square brackets.
.replace(/\[T\]/g, () => "'T'")
// See: https://date-fns.org/docs/Unicode-Tokens
// Replace years YYYY to yyyy
.replace(/YYYY/g, () => 'yyyy')
// Replace days of the month DD to dd
.replace(/DD/g, () => 'dd')
// Replace days of the week ddd to EEE
.replace(/ddd/g, () => 'EEE');
}
/**
* Returns the formatted date string in the given format, after converting it to the given time zone.
* @param {DateFnsFormatInput} date Date to format
* @param {string} formatString Output format (see date-fns supported formats)
* @param {ConversionOptions} options
* @returns {string}
*
* @see https://github.com/prantlf/date-fns-timezone/blob/master/src/formatToTimeZone.js
*/
function formatToTimeZone(date, formatString, options) {
const dateConvertedToTimezone = convertToTimeZone(date, options);
const unicodeFormatedString = formatToUnicode(formatString);
// Replace timezone token(s) in the string format with timezone values, since format() will use local timezone
const dateFnsFormatWithTimeZoneValue = formatTimeZoneTokens(unicodeFormatedString, options.timeZone)
// Avoid error: "Format string contains an unescaped latin alphabet character `Z`"
.replace(/\[Z\]/g, () => "'Z'");
return (0,date_fns_format__WEBPACK_IMPORTED_MODULE_2__.format)(dateConvertedToTimezone, dateFnsFormatWithTimeZoneValue, options);
}
/**
* Convert a date in local TZ to UTC
* 20:00 in local TZ become 20:00 in UTC
* @param {Date} date
* @returns {Date}
*/
function convertToUTC(date) {
return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
}
/**
* Check wether a timezone exists or not.
* @param timeZone {string}
* @returns {boolean}
*/
function timeZoneExists(timeZone) {
try {
// eslint-disable-next-line no-new
new Intl.DateTimeFormat(undefined, {
timeZone
});
return true;
} catch (e) {
return false;
}
}
/**
* Date format options
* @enum string
*/
const FORMAT = {
/** en: June 29, 2021 / fr: 29 juin 2020 / ja: 2020年6月29日 / de 29. Juni 2020 */
MDY_LONG: 'MDY_LONG',
/** en: June 2020 / fr: juin 2020 / ja: 2020年6月 / Juni 2020 */
MY_LONG: 'MY_LONG',
/** en: 06/29/2020 / fr: 29/06/2020 / ja: 2020/06/29 / de: 29.06.2020 */
MDY: 'MDY',
/** en: 6/29 / fr: 29/06 / ja: 06/29 / de: 29.06 */
MD: 'MD',
/** en: 6/29/20, 10:00 PM / fr: 29/06/2020 22:00 / ja: 2020/06/29 22:00 / de: 29.06.20, 22:00 */
MDYHM: 'MDYHM'
};
const options = {
[FORMAT.MDY_LONG]: {
year: 'numeric',
month: 'long',
day: 'numeric'
},
[FORMAT.MY_LONG]: {
year: 'numeric',
month: 'long'
},
[FORMAT.MDY]: {
year: 'numeric',
month: '2-digit',
day: '2-digit'
},
[FORMAT.MD]: {
month: 'numeric',
day: 'numeric'
},
[FORMAT.MDYHM]: {
dateStyle: 'short',
timeStyle: 'short'
}
};
/**
* Format a date using Intl.
* @param date {DateFnsFormatInput} A date: Date, string or Number
* @param dateOption {string} Comes from `FORMAT` enum
* @param lang {string} language
* @returns The formated date
*/
function format(date, dateOption, lang) {
const parsedDate = (0,date_fns_parseISO__WEBPACK_IMPORTED_MODULE_1__.parseISO)(new Date(date).toISOString());
return new Intl.DateTimeFormat(lang, options[dateOption]).format(parsedDate);
}
const buildWeeks = _generator__WEBPACK_IMPORTED_MODULE_0__.buildWeeks;
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
convertToLocalTime,
convertToTimeZone,
convertToUTC,
format,
FORMAT,
formatReadableUTCOffset,
formatToTimeZone,
getUTCOffset,
timeZoneExists
});
/***/ }),
/***/ "../utils/lib-esm/filters/filters.js":
/*!*******************************************!*\
!*** ../utils/lib-esm/filters/filters.js ***!
\*******************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ valued: () => (/* binding */ valued)
/* harmony export */ });
/**
* This allows Typescript to understand our array doesn't contain undefined or null values.
* So result is typed without "| null" nor "| undefined".
* This is not possible with a simple function like ".filter(v => !!v)" or ".filter(Boolean)"
*/
const valued = val => val !== undefined && val !== null;
/***/ }),
/***/ "../utils/lib-esm/filters/index.js":
/*!*****************************************!*\
!*** ../utils/lib-esm/filters/index.js ***!
\*****************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ valued: () => (/* reexport safe */ _filters__WEBPACK_IMPORTED_MODULE_0__.valued)
/* harmony export */ });
/* harmony import */ var _filters__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./filters */ "../utils/lib-esm/filters/filters.js");
/***/ }),
/***/ "../utils/lib-esm/getDataAttrFromProps.js":
/*!************************************************!*\
!*** ../utils/lib-esm/getDataAttrFromProps.js ***!
\************************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (/* binding */ getDataAttrFromProps)
/* harmony export */ });
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! lodash */ "lodash");
/* harmony import */ var lodash__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(lodash__WEBPACK_IMPORTED_MODULE_0__);
/**
* get data attributes from props
* @param {object} props
* @returns {object}
*/
function getDataAttrFromProps(props) {
const dataAttributesKeys = Object.keys(props).filter(objectKey => objectKey.startsWith('data-'));
return (0,lodash__WEBPACK_IMPORTED_MODULE_0__.pick)(props, dataAttributesKeys);
}
/***/ }),
/***/ "../utils/lib-esm/index.js":
/*!*********************************!*\
!*** ../utils/lib-esm/index.js ***!
\*********************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ date: () => (/* reexport module object */ _date__WEBPACK_IMPORTED_MODULE_0__),
/* harmony export */ filters: () => (/* reexport module object */ _filters__WEBPACK_IMPORTED_MODULE_1__),
/* harmony export */ getDataAttrFromProps: () => (/* reexport safe */ _getDataAttrFromProps__WEBPACK_IMPORTED_MODULE_2__["default"]),
/* harmony export */ randomUUID: () => (/* reexport safe */ _uuid__WEBPACK_IMPORTED_MODULE_3__.randomUUID),
/* harmony export */ validation: () => (/* reexport safe */ _validation__WEBPACK_IMPORTED_MODULE_4__["default"])
/* harmony export */ });
/* harmony import */ var _date__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./date */ "../utils/lib-esm/date/index.js");
/* harmony import */ var _filters__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./filters */ "../utils/lib-esm/filters/index.js");
/* harmony import */ var _getDataAttrFromProps__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./getDataAttrFromProps */ "../utils/lib-esm/getDataAttrFromProps.js");
/* harmony import */ var _uuid__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./uuid */ "../utils/lib-esm/uuid.js");
/* harmony import */ var _validation__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./validation */ "../utils/lib-esm/validation/index.js");
/***/ }),
/***/ "../utils/lib-esm/uuid.js":
/*!********************************!*\
!*** ../utils/lib-esm/uuid.js ***!
\********************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ randomUUID: () => (/* binding */ randomUUID)
/* harmony export */ });
function randomUUID() {
// works only on https so need backport if the app is run on unsecure env
if (crypto && crypto.randomUUID) {
return crypto.randomUUID();
}
function h(n) {
return (n | 0).toString(16);
}
// backport using Math.random and Date
function s(n) {
return h(Math.random() * (1 << (n << 2)) ^ Date.now()).slice(-n);
}
return [s(4) + s(4), s(4), '4' + s(3),
// UUID version 4
h(8 | Math.random() * 4) + s(3),
// {8|9|A|B}xxx
// s(4) + s(4) + s(4),
Date.now().toString(16).slice(-10) + s(2) // Use timestamp to avoid collisions
].join('-');
}
/***/ }),
/***/ "../utils/lib-esm/validation/index.js":
/*!********************************************!*\
!*** ../utils/lib-esm/validation/index.js ***!
\********************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
/* harmony export */ });
/* harmony import */ var _regexp__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./regexp */ "../utils/lib-esm/validation/regexp.js");
/* harmony import */ var _methods__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./methods */ "../utils/lib-esm/validation/methods.js");
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({
REGEXP: _regexp__WEBPACK_IMPORTED_MODULE_0__,
..._methods__WEBPACK_IMPORTED_MODULE_1__
});
/***/ }),
/***/ "../utils/lib-esm/validation/methods.js":
/*!**********************************************!*\
!*** ../utils/lib-esm/validation/methods.js ***!
\**********************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ validDomain: () => (/* binding */ validDomain),
/* harmony export */ validEmail: () => (/* binding */ validEmail),
/* harmony export */ validFirstName: () => (/* binding */ validFirstName),
/* harmony export */ validLastName: () => (/* binding */ validLastName)
/* harmony export */ });
/* harmony import */ var _regexp__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./regexp */ "../utils/lib-esm/validation/regexp.js");
/**
* Build a validation method along a given regular expression
* @param {RegExp} regexp Regular expression to test values against
* @returns {Function}
*/
function getValidationMethod(regexp) {
return value => regexp.test(value);
}
/**
* Check that a given value is a valid first name
* @param {string} value
* @returns {boolean}
*/
const validFirstName = getValidationMethod(_regexp__WEBPACK_IMPORTED_MODULE_0__.NAME);
/**
* Check th