@rpldy/shared-ui
Advanced tools
Comparing version 1.7.1 to 1.8.0-rc.0
@@ -13,51 +13,36 @@ "use strict"; | ||
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
const createRequestUpdateHoc = _ref => { | ||
let { | ||
eventType, | ||
getIsValidEventData, | ||
getRequestData | ||
} = _ref; | ||
return Component => props => { | ||
const context = (0, _useUploadyContext.default)(); | ||
const [updater, setUpdater] = (0, _react.useState)({ | ||
updateRequest: null, | ||
requestData: null | ||
}); | ||
const { | ||
id | ||
} = props; | ||
//need layout effect to register to event in time (block) | ||
(0, _react.useLayoutEffect)(() => { | ||
const handleEvent = function () { | ||
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) { | ||
params[_key] = arguments[_key]; | ||
} | ||
return getIsValidEventData(id, ...params) === true ? | ||
//returning a promise to event dispatcher so it will await until its resolved by user-land code | ||
new Promise(resolve => { | ||
setUpdater({ | ||
updateRequest: data => { | ||
//unregister handler so this instance doesnt continue listening unnecessarily | ||
context.off(eventType, handleEvent); | ||
resolve(data); | ||
}, | ||
requestData: getRequestData(...params) | ||
}); | ||
}) : | ||
//returning false for invalid data will cancel the request so must return undefined! | ||
undefined; | ||
}; | ||
const createRequestUpdateHoc = ({ | ||
eventType, | ||
getIsValidEventData, | ||
getRequestData | ||
}) => Component => props => { | ||
const context = (0, _useUploadyContext.default)(); | ||
const [updater, setUpdater] = (0, _react.useState)({ | ||
updateRequest: null, | ||
requestData: null | ||
}); | ||
const { | ||
id | ||
} = props; | ||
(0, _react.useLayoutEffect)(() => { | ||
const handleEvent = (...params) => getIsValidEventData(id, ...params) === true ? new Promise(resolve => { | ||
setUpdater({ | ||
updateRequest: data => { | ||
context.off(eventType, handleEvent); | ||
resolve(data); | ||
}, | ||
requestData: getRequestData(...params) | ||
}); | ||
}) : undefined; | ||
if (id) { | ||
context.on(eventType, handleEvent); | ||
} | ||
return () => { | ||
if (id) { | ||
context.on(eventType, handleEvent); | ||
context.off(eventType, handleEvent); | ||
} | ||
return () => { | ||
if (id) { | ||
context.off(eventType, handleEvent); | ||
} | ||
}; | ||
}, [context, id]); | ||
return /*#__PURE__*/_react.default.createElement(Component, _extends({}, props, updater)); | ||
}; | ||
}; | ||
}, [context, id]); | ||
return /*#__PURE__*/_react.default.createElement(Component, _extends({}, props, updater)); | ||
}; | ||
exports.createRequestUpdateHoc = createRequestUpdateHoc; |
@@ -11,19 +11,13 @@ "use strict"; | ||
eventType: _uploader.UPLOADER_EVENTS.REQUEST_PRE_SEND, | ||
getIsValidEventData: (id, _ref) => { | ||
let { | ||
items | ||
} = _ref; | ||
return !!items.find(item => item.id === id); | ||
}, | ||
getRequestData: _ref2 => { | ||
let { | ||
items, | ||
options | ||
} = _ref2; | ||
return { | ||
items, | ||
options | ||
}; | ||
} | ||
getIsValidEventData: (id, { | ||
items | ||
}) => !!items.find(item => item.id === id), | ||
getRequestData: ({ | ||
items, | ||
options | ||
}) => ({ | ||
items, | ||
options | ||
}) | ||
}); | ||
var _default = exports.default = withRequestPreSendUpdate; |
@@ -32,7 +32,4 @@ "use strict"; | ||
} | ||
const eventCallback = (0, _react.useCallback)(function (eventObj) { | ||
const eventCallback = (0, _react.useCallback)((eventObj, ...args) => { | ||
if (!usedId || eventObj.id === usedId) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
setEventState(stateCalculator(eventObj, ...args)); | ||
@@ -48,14 +45,8 @@ if ((0, _shared.isFunction)(cbFn)) { | ||
exports.generateUploaderEventHookWithState = generateUploaderEventHookWithState; | ||
const generateUploaderEventHook = function (event) { | ||
let canScope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
return (fn, id) => { | ||
const eventCallback = (0, _react.useCallback)(function (eventObj) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
return fn && (!canScope || !id || eventObj.id === id) ? fn(eventObj, ...args) : undefined; | ||
}, [fn, id]); | ||
useEventEffect(event, eventCallback); | ||
}; | ||
const generateUploaderEventHook = (event, canScope = true) => (fn, id) => { | ||
const eventCallback = (0, _react.useCallback)((eventObj, ...args) => { | ||
return fn && (!canScope || !id || eventObj.id === id) ? fn(eventObj, ...args) : undefined; | ||
}, [fn, id]); | ||
useEventEffect(event, eventCallback); | ||
}; | ||
exports.generateUploaderEventHook = generateUploaderEventHook; |
@@ -12,12 +12,6 @@ "use strict"; | ||
const useUploader = (options, listeners) => { | ||
//avoid creating new instance of uploader (unless enhancer method changed) | ||
const uploader = (0, _react.useMemo)(() => { | ||
_shared.logger.debugLog("Uploady creating a new uploader instance", options); | ||
return (0, _uploader.default)(options); | ||
}, | ||
//dont recreate the uploader when options changed - we do update later | ||
//eslint-disable-next-line react-hooks/exhaustive-deps | ||
[options.enhancer]); | ||
//Forgoing any kind of memoization. Probably not worth the comparison work to save on the options merge | ||
}, [options.enhancer]); | ||
uploader.update(options); | ||
@@ -27,4 +21,3 @@ (0, _react.useEffect)(() => { | ||
_shared.logger.debugLog("Uploady setting event listeners", listeners); | ||
Object.entries(listeners).forEach(_ref => { | ||
let [name, m] = _ref; | ||
Object.entries(listeners).forEach(([name, m]) => { | ||
uploader.on(name, m); | ||
@@ -36,6 +29,3 @@ }); | ||
_shared.logger.debugLog("Uploady removing event listeners", listeners); | ||
Object.entries(listeners).forEach(_ref2 => { | ||
let [name, m] = _ref2; | ||
return uploader.off(name, m); | ||
}); | ||
Object.entries(listeners).forEach(([name, m]) => uploader.off(name, m)); | ||
} | ||
@@ -42,0 +32,0 @@ }; |
@@ -23,3 +23,2 @@ "use strict"; | ||
const getInternalFileInput = () => { | ||
//retrieving the internal file input in userland means Uploady considers the input as custom from now on | ||
if (fileInputRef) { | ||
@@ -42,4 +41,2 @@ isUsingExternalInput = true; | ||
}; | ||
//We register the version on the global object to be able to warn devs when they're using packages from different uploady versions | ||
//causing the context not to be available | ||
(0, _uploadyVersion.registerUploadyContextVersion)(); | ||
@@ -57,9 +54,5 @@ return { | ||
(0, _shared.invariant)(input, NO_INPUT_ERROR_MSG); | ||
//allow components like upload button to override options | ||
showFileUploadOptions = addOptions; | ||
input.removeEventListener("change", onFileInputChange); | ||
input.addEventListener("change", onFileInputChange); | ||
//clear the input value so same file can be uploaded again | ||
input.value = ""; | ||
@@ -66,0 +59,0 @@ input.click(); |
@@ -9,7 +9,5 @@ "use strict"; | ||
const GLOBAL_VERSION_SYM = exports.GLOBAL_VERSION_SYM = Symbol.for("_rpldy-version_"); | ||
const getVersion = () => "1.7.1" || ""; | ||
const getVersion = () => "1.8.0-rc.0" || ""; | ||
exports.getVersion = getVersion; | ||
const getGlobal = () => /* istanbul ignore next */ | ||
// $FlowIgnore | ||
(0, _shared.hasWindow)() ? window : globalThis || process; | ||
const getGlobal = () => (0, _shared.hasWindow)() ? window : globalThis || process; | ||
const getRegisteredVersion = () => { | ||
@@ -16,0 +14,0 @@ return getGlobal()[GLOBAL_VERSION_SYM]; |
@@ -11,3 +11,2 @@ "use strict"; | ||
if (!(0, _shared.isProduction)() && !condition) { | ||
// eslint-disable-next-line no-console | ||
console.warn(msg); | ||
@@ -14,0 +13,0 @@ } |
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
import React, { useLayoutEffect, useState } from "react"; | ||
import useUploadyContext from "../hooks/useUploadyContext"; | ||
const createRequestUpdateHoc = _ref => { | ||
let { | ||
eventType, | ||
getIsValidEventData, | ||
getRequestData | ||
} = _ref; | ||
return Component => props => { | ||
const context = useUploadyContext(); | ||
const [updater, setUpdater] = useState({ | ||
updateRequest: null, | ||
requestData: null | ||
}); | ||
const { | ||
id | ||
} = props; | ||
//need layout effect to register to event in time (block) | ||
useLayoutEffect(() => { | ||
const handleEvent = function () { | ||
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) { | ||
params[_key] = arguments[_key]; | ||
} | ||
return getIsValidEventData(id, ...params) === true ? | ||
//returning a promise to event dispatcher so it will await until its resolved by user-land code | ||
new Promise(resolve => { | ||
setUpdater({ | ||
updateRequest: data => { | ||
//unregister handler so this instance doesnt continue listening unnecessarily | ||
context.off(eventType, handleEvent); | ||
resolve(data); | ||
}, | ||
requestData: getRequestData(...params) | ||
}); | ||
}) : | ||
//returning false for invalid data will cancel the request so must return undefined! | ||
undefined; | ||
}; | ||
const createRequestUpdateHoc = ({ | ||
eventType, | ||
getIsValidEventData, | ||
getRequestData | ||
}) => Component => props => { | ||
const context = useUploadyContext(); | ||
const [updater, setUpdater] = useState({ | ||
updateRequest: null, | ||
requestData: null | ||
}); | ||
const { | ||
id | ||
} = props; | ||
useLayoutEffect(() => { | ||
const handleEvent = (...params) => getIsValidEventData(id, ...params) === true ? new Promise(resolve => { | ||
setUpdater({ | ||
updateRequest: data => { | ||
context.off(eventType, handleEvent); | ||
resolve(data); | ||
}, | ||
requestData: getRequestData(...params) | ||
}); | ||
}) : undefined; | ||
if (id) { | ||
context.on(eventType, handleEvent); | ||
} | ||
return () => { | ||
if (id) { | ||
context.on(eventType, handleEvent); | ||
context.off(eventType, handleEvent); | ||
} | ||
return () => { | ||
if (id) { | ||
context.off(eventType, handleEvent); | ||
} | ||
}; | ||
}, [context, id]); | ||
return /*#__PURE__*/React.createElement(Component, _extends({}, props, updater)); | ||
}; | ||
}; | ||
}, [context, id]); | ||
return /*#__PURE__*/React.createElement(Component, _extends({}, props, updater)); | ||
}; | ||
export { createRequestUpdateHoc }; |
@@ -5,19 +5,13 @@ import { UPLOADER_EVENTS } from "@rpldy/uploader"; | ||
eventType: UPLOADER_EVENTS.REQUEST_PRE_SEND, | ||
getIsValidEventData: (id, _ref) => { | ||
let { | ||
items | ||
} = _ref; | ||
return !!items.find(item => item.id === id); | ||
}, | ||
getRequestData: _ref2 => { | ||
let { | ||
items, | ||
options | ||
} = _ref2; | ||
return { | ||
items, | ||
options | ||
}; | ||
} | ||
getIsValidEventData: (id, { | ||
items | ||
}) => !!items.find(item => item.id === id), | ||
getRequestData: ({ | ||
items, | ||
options | ||
}) => ({ | ||
items, | ||
options | ||
}) | ||
}); | ||
export default withRequestPreSendUpdate; |
@@ -25,7 +25,4 @@ import { useState, useCallback, useEffect } from "react"; | ||
} | ||
const eventCallback = useCallback(function (eventObj) { | ||
const eventCallback = useCallback((eventObj, ...args) => { | ||
if (!usedId || eventObj.id === usedId) { | ||
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
args[_key - 1] = arguments[_key]; | ||
} | ||
setEventState(stateCalculator(eventObj, ...args)); | ||
@@ -40,14 +37,8 @@ if (isFunction(cbFn)) { | ||
}; | ||
const generateUploaderEventHook = function (event) { | ||
let canScope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; | ||
return (fn, id) => { | ||
const eventCallback = useCallback(function (eventObj) { | ||
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { | ||
args[_key2 - 1] = arguments[_key2]; | ||
} | ||
return fn && (!canScope || !id || eventObj.id === id) ? fn(eventObj, ...args) : undefined; | ||
}, [fn, id]); | ||
useEventEffect(event, eventCallback); | ||
}; | ||
const generateUploaderEventHook = (event, canScope = true) => (fn, id) => { | ||
const eventCallback = useCallback((eventObj, ...args) => { | ||
return fn && (!canScope || !id || eventObj.id === id) ? fn(eventObj, ...args) : undefined; | ||
}, [fn, id]); | ||
useEventEffect(event, eventCallback); | ||
}; | ||
export { generateUploaderEventHook, generateUploaderEventHookWithState }; |
@@ -5,12 +5,6 @@ import { useEffect, useMemo } from "react"; | ||
const useUploader = (options, listeners) => { | ||
//avoid creating new instance of uploader (unless enhancer method changed) | ||
const uploader = useMemo(() => { | ||
logger.debugLog("Uploady creating a new uploader instance", options); | ||
return createUploader(options); | ||
}, | ||
//dont recreate the uploader when options changed - we do update later | ||
//eslint-disable-next-line react-hooks/exhaustive-deps | ||
[options.enhancer]); | ||
//Forgoing any kind of memoization. Probably not worth the comparison work to save on the options merge | ||
}, [options.enhancer]); | ||
uploader.update(options); | ||
@@ -20,4 +14,3 @@ useEffect(() => { | ||
logger.debugLog("Uploady setting event listeners", listeners); | ||
Object.entries(listeners).forEach(_ref => { | ||
let [name, m] = _ref; | ||
Object.entries(listeners).forEach(([name, m]) => { | ||
uploader.on(name, m); | ||
@@ -29,6 +22,3 @@ }); | ||
logger.debugLog("Uploady removing event listeners", listeners); | ||
Object.entries(listeners).forEach(_ref2 => { | ||
let [name, m] = _ref2; | ||
return uploader.off(name, m); | ||
}); | ||
Object.entries(listeners).forEach(([name, m]) => uploader.off(name, m)); | ||
} | ||
@@ -35,0 +25,0 @@ }; |
@@ -16,3 +16,2 @@ import React from "react"; | ||
const getInternalFileInput = () => { | ||
//retrieving the internal file input in userland means Uploady considers the input as custom from now on | ||
if (fileInputRef) { | ||
@@ -35,4 +34,2 @@ isUsingExternalInput = true; | ||
}; | ||
//We register the version on the global object to be able to warn devs when they're using packages from different uploady versions | ||
//causing the context not to be available | ||
registerUploadyContextVersion(); | ||
@@ -50,9 +47,5 @@ return { | ||
invariant(input, NO_INPUT_ERROR_MSG); | ||
//allow components like upload button to override options | ||
showFileUploadOptions = addOptions; | ||
input.removeEventListener("change", onFileInputChange); | ||
input.addEventListener("change", onFileInputChange); | ||
//clear the input value so same file can be uploaded again | ||
input.value = ""; | ||
@@ -59,0 +52,0 @@ input.click(); |
import { hasWindow } from "@rpldy/shared"; | ||
export const GLOBAL_VERSION_SYM = Symbol.for("_rpldy-version_"); | ||
const getVersion = () => "1.7.1" || ""; | ||
const getGlobal = () => /* istanbul ignore next */ | ||
// $FlowIgnore | ||
hasWindow() ? window : globalThis || process; | ||
const getVersion = () => "1.8.0-rc.0" || ""; | ||
const getGlobal = () => hasWindow() ? window : globalThis || process; | ||
const getRegisteredVersion = () => { | ||
@@ -8,0 +6,0 @@ return getGlobal()[GLOBAL_VERSION_SYM]; |
@@ -5,3 +5,2 @@ import { isProduction } from "@rpldy/shared"; | ||
if (!isProduction() && !condition) { | ||
// eslint-disable-next-line no-console | ||
console.warn(msg); | ||
@@ -8,0 +7,0 @@ } |
MIT License | ||
Copyright (c) 2023-2024 Yoav Niran | ||
Copyright (c) 2024 Yoav Niran | ||
@@ -5,0 +5,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
{ | ||
"version": "1.7.1", | ||
"version": "1.8.0-rc.0", | ||
"name": "@rpldy/shared-ui", | ||
@@ -25,8 +25,8 @@ "description": "internal set of utils+types for react-uploady UI", | ||
"dependencies": { | ||
"@rpldy/shared": "1.7.1", | ||
"@rpldy/uploader": "1.7.1" | ||
"@rpldy/shared": "1.8.0-rc.0", | ||
"@rpldy/uploader": "1.8.0-rc.0" | ||
}, | ||
"devDependencies": { | ||
"@rpldy/life-events": "1.7.1", | ||
"flow-bin": "^0.223.2", | ||
"@rpldy/life-events": "1.8.0-rc.0", | ||
"flow-bin": "^0.229.0", | ||
"react": "^18.2.0", | ||
@@ -41,3 +41,3 @@ "react-dom": "^18.2.0" | ||
}, | ||
"gitHead": "7833f3aee74341e82620699a536ba2554819a0bf" | ||
"gitHead": "2e8e5b171dd02388932ce44e6a7c5ed8e987dbe5" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59074
1344
1
+ Added@rpldy/shared@1.8.0-rc.0(transitive)
+ Added@rpldy/uploader@1.8.0-rc.0(transitive)
- Removed@rpldy/shared@1.7.1(transitive)
- Removed@rpldy/uploader@1.7.1(transitive)
Updated@rpldy/shared@1.8.0-rc.0
Updated@rpldy/uploader@1.8.0-rc.0