@squiz/resource-browser 3.0.1-pre-alpha.0 → 3.0.1-pre-alpha.2
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/.eslintrc +40 -0
- package/.storybook/main.ts +26 -0
- package/.storybook/preview-body.html +1 -0
- package/.storybook/preview-head.html +12 -0
- package/.storybook/preview.ts +16 -0
- package/CHANGELOG.md +281 -0
- package/README_DEVS.md +18 -0
- package/build.js +21 -0
- package/jest.config.ts +30 -0
- package/lib/BrowseToSource/BrowseToSource.js +52 -26
- package/lib/Hooks/useAuth.js +15 -11
- package/lib/Hooks/useSelectedState.js +7 -3
- package/lib/Hooks/useSources.js +7 -3
- package/lib/Icons/AdsClickIcon.js +11 -4
- package/lib/Icons/ArrowDownIcon.js +11 -4
- package/lib/Icons/CircledLoopIcon.js +11 -4
- package/lib/MainContainer/MainContainer.js +55 -27
- package/lib/Plugin/Plugin.js +14 -7
- package/lib/ResourceBrowserContext/AuthProvider.js +37 -9
- package/lib/ResourceBrowserContext/ResourceBrowserContext.js +39 -9
- package/lib/ResourceBrowserInput/ResourceBrowserInput.js +12 -5
- package/lib/ResourceLauncher/ResourceLauncher.js +13 -8
- package/lib/ResourcePicker/ResourcePicker.js +27 -20
- package/lib/ResourcePicker/States/Error.js +13 -6
- package/lib/ResourcePicker/States/Loading.js +11 -4
- package/lib/ResourcePicker/States/Selected.js +19 -12
- package/lib/SourceDropdown/SourceDropdown.js +48 -22
- package/lib/SourceDropdownContainer/SourceDropdownContainer.js +16 -10
- package/lib/SourceList/SourceList.js +16 -11
- package/lib/index.js +66 -26
- package/lib/types.js +5 -2
- package/lib/utils/authUtils.js +16 -9
- package/package.json +4 -16
- package/postcss.config.js +21 -0
- package/tailwind.config.cjs +99 -0
- package/tsconfig.json +22 -0
- package/tsconfig.storybook.json +4 -0
- package/tsconfig.test.json +12 -0
- package/vite.config.js +20 -0
- package/lib-esm/BrowseToSource/BrowseToSource.d.ts +0 -8
- package/lib-esm/BrowseToSource/BrowseToSource.js +0 -50
- package/lib-esm/Hooks/useAuth.d.ts +0 -7
- package/lib-esm/Hooks/useAuth.js +0 -54
- package/lib-esm/Hooks/useSelectedState.d.ts +0 -15
- package/lib-esm/Hooks/useSelectedState.js +0 -12
- package/lib-esm/Hooks/useSources.d.ts +0 -14
- package/lib-esm/Hooks/useSources.js +0 -44
- package/lib-esm/Icons/AdsClickIcon.d.ts +0 -4
- package/lib-esm/Icons/AdsClickIcon.js +0 -5
- package/lib-esm/Icons/ArrowDownIcon.d.ts +0 -4
- package/lib-esm/Icons/ArrowDownIcon.js +0 -5
- package/lib-esm/Icons/CircledLoopIcon.d.ts +0 -4
- package/lib-esm/Icons/CircledLoopIcon.js +0 -5
- package/lib-esm/MainContainer/MainContainer.d.ts +0 -19
- package/lib-esm/MainContainer/MainContainer.js +0 -43
- package/lib-esm/Plugin/Plugin.d.ts +0 -13
- package/lib-esm/Plugin/Plugin.js +0 -12
- package/lib-esm/ResourceBrowserContext/AuthProvider.d.ts +0 -16
- package/lib-esm/ResourceBrowserContext/AuthProvider.js +0 -18
- package/lib-esm/ResourceBrowserContext/ResourceBrowserContext.d.ts +0 -15
- package/lib-esm/ResourceBrowserContext/ResourceBrowserContext.js +0 -26
- package/lib-esm/ResourceBrowserInput/ResourceBrowserInput.d.ts +0 -26
- package/lib-esm/ResourceBrowserInput/ResourceBrowserInput.js +0 -9
- package/lib-esm/ResourceLauncher/ResourceLauncher.d.ts +0 -8
- package/lib-esm/ResourceLauncher/ResourceLauncher.js +0 -12
- package/lib-esm/ResourcePicker/ResourcePicker.d.ts +0 -16
- package/lib-esm/ResourcePicker/ResourcePicker.js +0 -25
- package/lib-esm/ResourcePicker/States/Error.d.ts +0 -7
- package/lib-esm/ResourcePicker/States/Error.js +0 -6
- package/lib-esm/ResourcePicker/States/Loading.d.ts +0 -2
- package/lib-esm/ResourcePicker/States/Loading.js +0 -4
- package/lib-esm/ResourcePicker/States/Selected.d.ts +0 -15
- package/lib-esm/ResourcePicker/States/Selected.js +0 -20
- package/lib-esm/SourceDropdown/SourceDropdown.d.ts +0 -7
- package/lib-esm/SourceDropdown/SourceDropdown.js +0 -46
- package/lib-esm/SourceDropdownContainer/SourceDropdownContainer.d.ts +0 -5
- package/lib-esm/SourceDropdownContainer/SourceDropdownContainer.js +0 -12
- package/lib-esm/SourceList/SourceList.d.ts +0 -8
- package/lib-esm/SourceList/SourceList.js +0 -16
- package/lib-esm/index.d.ts +0 -18
- package/lib-esm/index.js +0 -79
- package/lib-esm/types.d.ts +0 -97
- package/lib-esm/types.js +0 -5
- package/lib-esm/utils/authUtils.d.ts +0 -5
- package/lib-esm/utils/authUtils.js +0 -31
@@ -1,19 +1,44 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
const react_1 = __importStar(require("react"));
|
27
|
+
const generic_browser_lib_1 = require("@squiz/generic-browser-lib");
|
28
|
+
const react_aria_1 = require("react-aria");
|
29
|
+
const ArrowDownIcon_1 = require("../Icons/ArrowDownIcon");
|
30
|
+
function SourceDropdown({ sources, selectedSource, onSourceSelect, }) {
|
31
|
+
const [uniqueId] = (0, react_1.useState)((0, generic_browser_lib_1.uuid)());
|
32
|
+
const buttonRef = (0, react_1.useRef)(null);
|
33
|
+
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
9
34
|
// Watch the focus and blur on the menu and close if focus leaves the control
|
10
|
-
const { focusWithinProps } = useFocusWithin({
|
35
|
+
const { focusWithinProps } = (0, react_aria_1.useFocusWithin)({
|
11
36
|
onBlurWithin: () => {
|
12
37
|
setIsOpen(false);
|
13
38
|
},
|
14
39
|
});
|
15
40
|
// Listen for Esc key within this element
|
16
|
-
const { keyboardProps } = useKeyboard({
|
41
|
+
const { keyboardProps } = (0, react_aria_1.useKeyboard)({
|
17
42
|
onKeyDown: (e) => {
|
18
43
|
if (isOpen && e.key === 'Escape') {
|
19
44
|
setIsOpen(false);
|
@@ -27,20 +52,21 @@ export default function SourceDropdown({ sources, selectedSource, onSourceSelect
|
|
27
52
|
onSourceSelect(source);
|
28
53
|
};
|
29
54
|
if (!sources.length) {
|
30
|
-
return
|
55
|
+
return react_1.default.createElement(react_1.default.Fragment, null);
|
31
56
|
}
|
32
|
-
return (
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
57
|
+
return (react_1.default.createElement("div", { ...focusWithinProps, ...keyboardProps, className: "relative w-full " },
|
58
|
+
react_1.default.createElement("button", { ref: buttonRef, type: "button", "aria-label": "Source quick select", "aria-expanded": isOpen, "aria-controls": `${uniqueId}-button-menu`, onClick: () => setIsOpen(!isOpen), className: "relative flex items-center p-2 w-full rounded bg-blue-100 hover:bg-blue-150" },
|
59
|
+
react_1.default.createElement("span", { className: "sr-only" }, "current source "),
|
60
|
+
react_1.default.createElement("div", { className: "truncate max-w-[200px] text-md font-semibold text-blue-400" }, selectedSource.name),
|
61
|
+
react_1.default.createElement(ArrowDownIcon_1.ArrowDownIcon, { "aria-hidden": true, className: "absolute right-2 fill-blue-300" })),
|
62
|
+
react_1.default.createElement("ul", { id: `${uniqueId}-button-menu`, "aria-hidden": !isOpen, className: `absolute z-50 top-[calc(100%+8px)] w-[100%] bg-gray-100 border-1 shadow-md rounded border-gray-300 p-2 pb-0 overflow-y-scroll max-h-80 ${!isOpen ? 'hidden' : ''}` }, sources.map((source) => {
|
38
63
|
const { id, name, type } = source;
|
39
64
|
const isSelectedSource = id === selectedSource.id;
|
40
|
-
return (
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
isSelectedSource && (
|
65
|
+
return (react_1.default.createElement("li", { key: id, className: "flex items-center text-sm font-semibold mb-2 bg-white rounded" },
|
66
|
+
react_1.default.createElement("button", { type: "button", onClick: () => handleSourceClick(source), className: `relative grow flex items-center p-2 border-1 border-white rounded hover:bg-gray-50 hover:border-gray-300 focus:bg-gray-100` },
|
67
|
+
react_1.default.createElement(generic_browser_lib_1.Icon, { icon: type, "aria-label": type, className: "shrink-0 mr-2.5" }),
|
68
|
+
react_1.default.createElement("span", { className: "text-left mr-7" }, name),
|
69
|
+
isSelectedSource && (react_1.default.createElement(generic_browser_lib_1.Icon, { icon: 'selected', "aria-label": "selected", className: "absolute right-4" })))));
|
45
70
|
}))));
|
46
71
|
}
|
72
|
+
exports.default = SourceDropdown;
|
@@ -1,12 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const react_1 = __importDefault(require("react"));
|
7
|
+
const AdsClickIcon_1 = require("../Icons/AdsClickIcon");
|
8
|
+
function SourceDropdownContainer({ children, isCollapsed, onExpand, }) {
|
9
|
+
return (react_1.default.createElement("div", { className: "inline-flex rounded-lg p-1 bg-blue-100 min-h-[44px]" },
|
10
|
+
isCollapsed && (react_1.default.createElement("button", { "aria-label": "Expand browse options", onClick: onExpand, className: "flex items-center" },
|
11
|
+
react_1.default.createElement(AdsClickIcon_1.AdsClickIcon, { "aria-hidden": true, className: "mx-2 fill-blue-300" }))),
|
12
|
+
!isCollapsed && (react_1.default.createElement(react_1.default.Fragment, null,
|
13
|
+
react_1.default.createElement("div", { className: "flex items-center pr-1" },
|
14
|
+
react_1.default.createElement(AdsClickIcon_1.AdsClickIcon, { "aria-hidden": true, className: "mx-2 fill-blue-300" }),
|
15
|
+
react_1.default.createElement("span", { className: "sr-only" }, "Browse")),
|
11
16
|
children))));
|
12
17
|
}
|
18
|
+
exports.default = SourceDropdownContainer;
|
@@ -1,16 +1,21 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const react_1 = __importDefault(require("react"));
|
7
|
+
const generic_browser_lib_1 = require("@squiz/generic-browser-lib");
|
3
8
|
function SourceList({ sources, onSourceSelect }) {
|
4
|
-
return (
|
5
|
-
|
6
|
-
|
7
|
-
return (
|
8
|
-
|
9
|
+
return (react_1.default.createElement("div", { className: "overflow-y-scroll w-screen max-w-[400px] flex-1 grow-[3] border-r border-gray-300 bg-gray-100 pl-4.5 pr-4.5 pb-4.5 pt-3" },
|
10
|
+
react_1.default.createElement("div", { className: "text-md font-semibold" }, "Select an environment to use"),
|
11
|
+
react_1.default.createElement("ul", { tabIndex: -1, "aria-label": `environment list`, className: "flex flex-col bg-gray-100 min-h-full focus-visible:outline-0" }, sources.map((source, index) => {
|
12
|
+
return (react_1.default.createElement("li", { key: index, className: "flex items-stretch relative" },
|
13
|
+
react_1.default.createElement("button", { onClick: () => {
|
9
14
|
onSourceSelect(source);
|
10
15
|
}, className: "w-full p-1 mt-3 bg-white border-1 border-grey-200 min-h-[64px] rounded-lg flex items-center text-md font-semibold" },
|
11
|
-
|
12
|
-
|
13
|
-
|
16
|
+
react_1.default.createElement(generic_browser_lib_1.Icon, { icon: source.type, className: "ml-4" }),
|
17
|
+
react_1.default.createElement("span", { className: "line-clamp-2 text-left break-word ml-4" }, source.name || source.id),
|
18
|
+
react_1.default.createElement(generic_browser_lib_1.Icon, { icon: 'arrow-right', className: "absolute ml-1 right-4" }))));
|
14
19
|
}))));
|
15
20
|
}
|
16
|
-
|
21
|
+
exports.default = SourceList;
|
package/lib/index.js
CHANGED
@@ -1,29 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
15
|
+
}) : function(o, v) {
|
16
|
+
o["default"] = v;
|
17
|
+
});
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
19
|
+
if (mod && mod.__esModule) return mod;
|
20
|
+
var result = {};
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
+
__setModuleDefault(result, mod);
|
23
|
+
return result;
|
24
|
+
};
|
25
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
26
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
27
|
+
};
|
28
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
30
|
+
};
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
32
|
+
exports.ResourceBrowser = exports.SourceDropdownContainer = exports.SourceDropdown = exports.BrowseToSource = exports.AuthContext = exports.AuthProvider = exports.useAuthContext = exports.ResourceBrowserContextProvider = exports.ResourceBrowserContext = void 0;
|
33
|
+
const react_1 = __importStar(require("react"));
|
34
|
+
const ResourceBrowserContext_1 = require("./ResourceBrowserContext/ResourceBrowserContext");
|
35
|
+
Object.defineProperty(exports, "ResourceBrowserContext", { enumerable: true, get: function () { return ResourceBrowserContext_1.ResourceBrowserContext; } });
|
36
|
+
Object.defineProperty(exports, "ResourceBrowserContextProvider", { enumerable: true, get: function () { return ResourceBrowserContext_1.ResourceBrowserContextProvider; } });
|
37
|
+
const useSources_1 = require("./Hooks/useSources");
|
38
|
+
const Plugin_1 = require("./Plugin/Plugin");
|
39
|
+
const AuthProvider_1 = require("./ResourceBrowserContext/AuthProvider");
|
40
|
+
Object.defineProperty(exports, "AuthProvider", { enumerable: true, get: function () { return AuthProvider_1.AuthProvider; } });
|
41
|
+
Object.defineProperty(exports, "useAuthContext", { enumerable: true, get: function () { return AuthProvider_1.useAuthContext; } });
|
42
|
+
Object.defineProperty(exports, "AuthContext", { enumerable: true, get: function () { return AuthProvider_1.AuthContext; } });
|
43
|
+
const BrowseToSource_1 = __importDefault(require("./BrowseToSource/BrowseToSource"));
|
44
|
+
exports.BrowseToSource = BrowseToSource_1.default;
|
45
|
+
const SourceDropdown_1 = __importDefault(require("./SourceDropdown/SourceDropdown"));
|
46
|
+
exports.SourceDropdown = SourceDropdown_1.default;
|
47
|
+
const SourceDropdownContainer_1 = __importDefault(require("./SourceDropdownContainer/SourceDropdownContainer"));
|
48
|
+
exports.SourceDropdownContainer = SourceDropdownContainer_1.default;
|
49
|
+
__exportStar(require("./types"), exports);
|
50
|
+
const ResourceBrowser = (props) => {
|
12
51
|
const { value } = props;
|
13
|
-
const [error, setError] = useState(null);
|
14
|
-
const { onRequestSources, searchEnabled, plugins } = useContext(ResourceBrowserContext);
|
15
|
-
const [isModalOpen, setIsModalOpen] = useState(false);
|
16
|
-
const [source, setSource] = useState(null);
|
17
|
-
const [mode, setMode] = useState(null);
|
18
|
-
const { data: sources, isLoading, error: sourcesError } = useSources({ onRequestSources, plugins });
|
19
|
-
const [plugin, setPlugin] = useState(null);
|
52
|
+
const [error, setError] = (0, react_1.useState)(null);
|
53
|
+
const { onRequestSources, searchEnabled, plugins } = (0, react_1.useContext)(ResourceBrowserContext_1.ResourceBrowserContext);
|
54
|
+
const [isModalOpen, setIsModalOpen] = (0, react_1.useState)(false);
|
55
|
+
const [source, setSource] = (0, react_1.useState)(null);
|
56
|
+
const [mode, setMode] = (0, react_1.useState)(null);
|
57
|
+
const { data: sources, isLoading, error: sourcesError } = (0, useSources_1.useSources)({ onRequestSources, plugins });
|
58
|
+
const [plugin, setPlugin] = (0, react_1.useState)(null);
|
20
59
|
// MainContainer will render a list of sources of one is not provided to it, callback to allow it to set the source once a user selects
|
21
|
-
const handleSourceSelect = useCallback((source, mode) => {
|
60
|
+
const handleSourceSelect = (0, react_1.useCallback)((source, mode) => {
|
22
61
|
setSource(source);
|
23
62
|
setMode(mode || null);
|
24
63
|
}, [setSource, setMode]);
|
25
64
|
// If an existing resource is passed in auto select its source
|
26
|
-
useEffect(() => {
|
65
|
+
(0, react_1.useEffect)(() => {
|
27
66
|
let source = null;
|
28
67
|
setError(null);
|
29
68
|
// If there is a provided value try to use its source
|
@@ -45,7 +84,7 @@ export const ResourceBrowser = (props) => {
|
|
45
84
|
}, [value, isLoading, sources, setSource, setError]);
|
46
85
|
// When a source is selected update our plugin reference to match (legacy support)
|
47
86
|
// the plugin is now attached to the source directly when fetched from the context so use that instead when possible
|
48
|
-
useEffect(() => {
|
87
|
+
(0, react_1.useEffect)(() => {
|
49
88
|
if (source?.plugin) {
|
50
89
|
setPlugin(source.plugin);
|
51
90
|
}
|
@@ -54,19 +93,19 @@ export const ResourceBrowser = (props) => {
|
|
54
93
|
}
|
55
94
|
}, [plugins, source]);
|
56
95
|
// The modal has some control over it own open/closed state (for WCAG reasons) so keep this in sync with our state
|
57
|
-
const handleModalStateChange = useCallback((isOpen) => {
|
96
|
+
const handleModalStateChange = (0, react_1.useCallback)((isOpen) => {
|
58
97
|
setIsModalOpen(isOpen);
|
59
98
|
}, [setIsModalOpen]);
|
60
99
|
// If the modal closes and we dont have a value clear the source state so it goes back to the launcher on re-open
|
61
|
-
useEffect(() => {
|
100
|
+
(0, react_1.useEffect)(() => {
|
62
101
|
if (!isModalOpen && !value && (sources?.length > 1 || searchEnabled)) {
|
63
102
|
setSource(null);
|
64
103
|
setMode(null);
|
65
104
|
}
|
66
105
|
}, [sources, isModalOpen]);
|
67
106
|
// Render a default "plugin" and one for each item in the plugins array. They are conditionally rendered based on what is selected
|
68
|
-
return (
|
69
|
-
|
107
|
+
return (react_1.default.createElement("div", { className: "squiz-rb-scope" },
|
108
|
+
react_1.default.createElement(Plugin_1.PluginRender, { key: "default", render: plugin === null, ...props, source: source, sources: sources, setSource: handleSourceSelect, isLoading: isLoading, error: sourcesError || error, plugin: plugin, pluginMode: mode, searchEnabled: searchEnabled, useResource: () => {
|
70
109
|
return {
|
71
110
|
data: null,
|
72
111
|
error: null,
|
@@ -74,6 +113,7 @@ export const ResourceBrowser = (props) => {
|
|
74
113
|
};
|
75
114
|
}, isModalOpen: isModalOpen, onModalStateChange: handleModalStateChange }),
|
76
115
|
plugins.map((thisPlugin) => {
|
77
|
-
return (
|
116
|
+
return (react_1.default.createElement(Plugin_1.PluginRender, { key: thisPlugin.type, render: thisPlugin === plugin, ...props, source: source, sources: sources, setSource: handleSourceSelect, isLoading: isLoading, error: error, plugin: plugin, pluginMode: mode, searchEnabled: searchEnabled, useResource: thisPlugin.useResolveResource, isModalOpen: isModalOpen, onModalStateChange: handleModalStateChange }));
|
78
117
|
})));
|
79
118
|
};
|
119
|
+
exports.ResourceBrowser = ResourceBrowser;
|
package/lib/types.js
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.PluginLaunchModeType = void 0;
|
4
|
+
var PluginLaunchModeType;
|
2
5
|
(function (PluginLaunchModeType) {
|
3
6
|
PluginLaunchModeType["Browse"] = "browse";
|
4
7
|
PluginLaunchModeType["Search"] = "search";
|
5
|
-
})(PluginLaunchModeType || (PluginLaunchModeType = {}));
|
8
|
+
})(PluginLaunchModeType = exports.PluginLaunchModeType || (exports.PluginLaunchModeType = {}));
|
package/lib/utils/authUtils.js
CHANGED
@@ -1,19 +1,25 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.refreshAccessToken = exports.logout = exports.setCookieValue = exports.getCookieValue = void 0;
|
4
|
+
const getCookieValue = (name) => {
|
2
5
|
const match = document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)');
|
3
6
|
return match ? match.pop() : null;
|
4
7
|
};
|
5
|
-
|
8
|
+
exports.getCookieValue = getCookieValue;
|
9
|
+
const setCookieValue = (name, value) => {
|
6
10
|
document.cookie = `${name}=${value}; Path=/;`;
|
7
11
|
};
|
8
|
-
|
9
|
-
|
10
|
-
setCookieValue('
|
12
|
+
exports.setCookieValue = setCookieValue;
|
13
|
+
const logout = () => {
|
14
|
+
(0, exports.setCookieValue)('authToken', '');
|
15
|
+
(0, exports.setCookieValue)('refreshToken', '');
|
11
16
|
};
|
12
|
-
|
17
|
+
exports.logout = logout;
|
18
|
+
const refreshAccessToken = async (authConfig) => {
|
13
19
|
if (!authConfig) {
|
14
20
|
throw new Error('No auth configuration available');
|
15
21
|
}
|
16
|
-
const refreshToken = getCookieValue('refreshToken');
|
22
|
+
const refreshToken = (0, exports.getCookieValue)('refreshToken');
|
17
23
|
if (!refreshToken) {
|
18
24
|
throw new Error('You are not logged in');
|
19
25
|
}
|
@@ -22,10 +28,11 @@ export const refreshAccessToken = async (authConfig) => {
|
|
22
28
|
credentials: 'include',
|
23
29
|
});
|
24
30
|
if (!response.ok) {
|
25
|
-
logout();
|
31
|
+
(0, exports.logout)();
|
26
32
|
throw new Error('Failed to refresh token');
|
27
33
|
}
|
28
34
|
const data = await response.json();
|
29
|
-
setCookieValue('authToken', data.access_token);
|
35
|
+
(0, exports.setCookieValue)('authToken', data.access_token);
|
30
36
|
return data.access_token;
|
31
37
|
};
|
38
|
+
exports.refreshAccessToken = refreshAccessToken;
|
package/package.json
CHANGED
@@ -1,27 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "@squiz/resource-browser",
|
3
|
-
"version": "3.0.1-pre-alpha.
|
3
|
+
"version": "3.0.1-pre-alpha.2",
|
4
|
+
"main": "lib/index.js",
|
4
5
|
"types": "lib/index.d.ts",
|
5
|
-
"files": [
|
6
|
-
"lib/*",
|
7
|
-
"lib-esm/*",
|
8
|
-
"src/*"
|
9
|
-
],
|
10
|
-
"exports": {
|
11
|
-
".": {
|
12
|
-
"import": "./lib-esm/index.js",
|
13
|
-
"require": "./lib/index.js"
|
14
|
-
},
|
15
|
-
"./src/": "./src/",
|
16
|
-
"./lib/": "./lib/"
|
17
|
-
},
|
18
6
|
"private": false,
|
19
7
|
"publishConfig": {
|
20
8
|
"access": "public"
|
21
9
|
},
|
22
10
|
"scripts": {
|
23
11
|
"compile": "npm run compile:styles && npm run compile:code",
|
24
|
-
"compile:code": "tsc -b ./tsconfig.json
|
12
|
+
"compile:code": "tsc -b ./tsconfig.json",
|
25
13
|
"compile:styles": "node build.js",
|
26
14
|
"storybook": "storybook dev -p 6006",
|
27
15
|
"storybook:build": "storybook build",
|
@@ -38,7 +26,7 @@
|
|
38
26
|
"@react-types/shared": "^3.23.1",
|
39
27
|
"@squiz/dx-json-schema-lib": "^1.67.0",
|
40
28
|
"@squiz/generic-browser-lib": "1.67.2",
|
41
|
-
"@squiz/resource-browser-ui-lib": "^1.0.0-pre-alpha.
|
29
|
+
"@squiz/resource-browser-ui-lib": "^1.0.0-pre-alpha.1",
|
42
30
|
"clsx": "^2.1.0",
|
43
31
|
"expiry-map": "^2.0.0",
|
44
32
|
"p-memoize": "^4.0.4",
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module.exports = {
|
2
|
+
plugins: [
|
3
|
+
require('tailwindcss'),
|
4
|
+
require('autoprefixer'),
|
5
|
+
require('postcss-nested'),
|
6
|
+
require('postcss-prefix-selector')({
|
7
|
+
prefix: '.squiz-rb-scope',
|
8
|
+
transform(prefix, selector, prefixedSelector, filePath, rule) {
|
9
|
+
if (selector.match(/(squiz-gb-scope)/)) {
|
10
|
+
return selector;
|
11
|
+
}
|
12
|
+
if (selector.match(/(::)/)) {
|
13
|
+
const index = prefixedSelector.indexOf('::');
|
14
|
+
return `${prefixedSelector.slice(0, index)}:not(.squiz-rb-plugin *)${prefixedSelector.slice(index)}`;
|
15
|
+
}
|
16
|
+
return `${prefixedSelector}:not(.squiz-rb-plugin *)`;
|
17
|
+
},
|
18
|
+
includeFiles: ['./src/index.scss'],
|
19
|
+
}),
|
20
|
+
],
|
21
|
+
};
|
@@ -0,0 +1,99 @@
|
|
1
|
+
/** @type {import('tailwindcss').Config} */
|
2
|
+
module.exports = {
|
3
|
+
content: {
|
4
|
+
relative: true,
|
5
|
+
files: [
|
6
|
+
'../../node_modules/@squiz/generic-browser-lib/src/**/*.{js,ts,jsx,tsx,scss}',
|
7
|
+
'./index.html',
|
8
|
+
'./src/**/*.{js,ts,jsx,tsx}',
|
9
|
+
'./node_modules/flowbite/**/*.js',
|
10
|
+
],
|
11
|
+
},
|
12
|
+
theme: {
|
13
|
+
extend: {
|
14
|
+
borderWidth: {
|
15
|
+
// We shouldn't use ".border" class and instead use ".border-1".
|
16
|
+
// ".border" has !important styling defined in Matrix so overrides anything various border styling if used.
|
17
|
+
1: '1px',
|
18
|
+
},
|
19
|
+
borderRadius: {
|
20
|
+
DEFAULT: '4px',
|
21
|
+
md: '6px',
|
22
|
+
},
|
23
|
+
fontFamily: {
|
24
|
+
base: 'Open Sans, Arial, sans-serif',
|
25
|
+
},
|
26
|
+
fontWeight: {
|
27
|
+
normal: '400',
|
28
|
+
medium: '500',
|
29
|
+
semibold: '600',
|
30
|
+
bold: '700',
|
31
|
+
},
|
32
|
+
fontSize: {
|
33
|
+
xlg: '1.125rem',
|
34
|
+
lg: '1rem',
|
35
|
+
md: '0.875rem',
|
36
|
+
sm: '0.8125rem',
|
37
|
+
base: '1rem',
|
38
|
+
'heading-1': ['1.625rem', '2rem'],
|
39
|
+
'heading-2': ['1.25rem', '1.5rem'],
|
40
|
+
'heading-3': ['1.125rem', '1.375rem'],
|
41
|
+
'heading-4': ['1rem', '1.25rem'],
|
42
|
+
},
|
43
|
+
fontFamily: {
|
44
|
+
base: 'Open Sans, Arial, sans-serif',
|
45
|
+
},
|
46
|
+
boxShadow: {
|
47
|
+
outline: '0 0 0 1px rgba(0,0,0,0.10)',
|
48
|
+
sm: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 4px 2px rgba(0,0,0,0.08)',
|
49
|
+
DEFAULT: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 12px 4px rgba(0,0,0,0.12)',
|
50
|
+
md: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 12px 4px rgba(0,0,0,0.12)',
|
51
|
+
lg: '0 0 0 1px rgba(0,0,0,0.04), 0 1px 24px 12px rgba(0,0,0,0.12)',
|
52
|
+
inner: 'inset 0 2px 4px 0 rgb(0 0 0 / 0.05)',
|
53
|
+
none: 'none',
|
54
|
+
},
|
55
|
+
width: {
|
56
|
+
'modal-sm': '25rem',
|
57
|
+
'modal-md': '37.5rem',
|
58
|
+
'modal-lg': '50rem',
|
59
|
+
'modal-xl': '62.5rem',
|
60
|
+
},
|
61
|
+
spacing: {
|
62
|
+
1: '0.25rem', // 4px
|
63
|
+
2: '0.5rem', // 8px
|
64
|
+
3: '0.75rem', // 12px
|
65
|
+
4: '1rem', // 16px
|
66
|
+
4.5: '1.125rem', // 18px
|
67
|
+
5: '1.25rem', // 20px
|
68
|
+
6: '1.5rem', // 24px
|
69
|
+
7: '1.75rem', // 28px
|
70
|
+
8: '2rem', // 32px
|
71
|
+
169: '169px', // 169px
|
72
|
+
},
|
73
|
+
colors: {
|
74
|
+
gray: {
|
75
|
+
50: '#F7F7F7',
|
76
|
+
100: '#F5F5F5',
|
77
|
+
200: '#ededed',
|
78
|
+
300: '#e0e0e0',
|
79
|
+
400: '#BABABA',
|
80
|
+
500: '#949494',
|
81
|
+
600: '#707070',
|
82
|
+
700: '#4F4F4F',
|
83
|
+
800: '#3D3D3D',
|
84
|
+
900: '#2B2B2B',
|
85
|
+
},
|
86
|
+
blue: {
|
87
|
+
100: '#e6f1fa',
|
88
|
+
150: '#C7DFF5',
|
89
|
+
200: '#8FC0EB',
|
90
|
+
300: '#0774d2',
|
91
|
+
400: '#044985',
|
92
|
+
},
|
93
|
+
red: {
|
94
|
+
300: '#d72321',
|
95
|
+
},
|
96
|
+
},
|
97
|
+
},
|
98
|
+
},
|
99
|
+
};
|
package/tsconfig.json
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"compilerOptions": {
|
3
|
+
"target": "ESNext",
|
4
|
+
"useDefineForClassFields": true,
|
5
|
+
"experimentalDecorators": true,
|
6
|
+
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
7
|
+
"allowJs": false,
|
8
|
+
"skipLibCheck": true,
|
9
|
+
"esModuleInterop": true,
|
10
|
+
"allowSyntheticDefaultImports": true,
|
11
|
+
"strict": true,
|
12
|
+
"forceConsistentCasingInFileNames": true,
|
13
|
+
"module": "CommonJS",
|
14
|
+
"moduleResolution": "node",
|
15
|
+
"resolveJsonModule": true,
|
16
|
+
"isolatedModules": true,
|
17
|
+
"jsx": "react",
|
18
|
+
"declaration": true,
|
19
|
+
"outDir": "./lib"
|
20
|
+
},
|
21
|
+
"files": ["./src/index.tsx"]
|
22
|
+
}
|
package/vite.config.js
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
import { defineConfig } from 'vite';
|
2
|
+
import react from '@vitejs/plugin-react';
|
3
|
+
|
4
|
+
// https://vitejs.dev/config/
|
5
|
+
// Dependencies from within the monorepo need to be configured in a special way, relates to:
|
6
|
+
// https://github.com/vitejs/vite/issues/5668
|
7
|
+
export default defineConfig({
|
8
|
+
optimizeDeps: {
|
9
|
+
include: ['@squiz/resource-browser-ui-lib'],
|
10
|
+
},
|
11
|
+
plugins: [
|
12
|
+
react({
|
13
|
+
babel: {
|
14
|
+
parserOpts: {
|
15
|
+
plugins: ['decorators-legacy'],
|
16
|
+
},
|
17
|
+
},
|
18
|
+
}),
|
19
|
+
],
|
20
|
+
});
|
@@ -1,8 +0,0 @@
|
|
1
|
-
import React from 'react';
|
2
|
-
import { ResourceBrowserSource, PluginLaunchMode } from '../types';
|
3
|
-
export default function BrowseToSource({ sources, selectedSource, onSourceSelect, className, }: {
|
4
|
-
sources: ResourceBrowserSource[];
|
5
|
-
selectedSource: ResourceBrowserSource;
|
6
|
-
onSourceSelect(source: ResourceBrowserSource, mode?: PluginLaunchMode): void;
|
7
|
-
className?: string;
|
8
|
-
}): React.JSX.Element;
|