@raketa-builder/support 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AdminPageRender/AdminWidgetMinimal.js +1 -1
- package/dist/AdminPageRender/IconButton.js +1 -1
- package/dist/AdminPageRender/index.js +13 -4
- package/dist/Container.js +1 -1
- package/dist/EmbeddedVideo.js +1 -1
- package/dist/Image.js +1 -1
- package/dist/WidgetRender/index.js +1 -1
- package/dist/{chunk-ORMEWXMH.js → chunk-BBZEL7EG.js} +21 -1
- package/dist/extractImageValue.js +1 -1
- package/dist/imagePlaceholder.js +1 -1
- package/dist/imageSrc.js +1 -1
- package/dist/index.js +3 -1
- package/dist/isImagePresent.js +1 -1
- package/dist/lib/SelectedWidgetsButtons.js +92 -0
- package/dist/lib/SelectedWidgetsToolbar.js +72 -11
- package/dist/toHTML.js +1 -1
- package/package.json +3 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __spreadProps, __spreadValues, __objRest } from '../chunk-
|
|
1
|
+
import { __spreadProps, __spreadValues, __objRest } from '../chunk-BBZEL7EG.js';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import IconButton from './IconButton';
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { __spreadProps, __spreadValues } from '../chunk-
|
|
1
|
+
import { __spreadProps, __spreadValues } from '../chunk-BBZEL7EG.js';
|
|
2
2
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import AdminWidgetMinimal from './AdminWidgetMinimal';
|
|
5
5
|
import SelectedWidgetsToolbar from '../lib/SelectedWidgetsToolbar';
|
|
6
|
+
import { validateButtons } from '../lib/SelectedWidgetsButtons';
|
|
6
7
|
|
|
7
8
|
const saveToLocalStorage = (identifier, widgets) => window.localStorage.setItem(
|
|
8
9
|
`clipboard\u2013${identifier}`,
|
|
@@ -18,8 +19,13 @@ const AdminPageRender = ({
|
|
|
18
19
|
detailPath,
|
|
19
20
|
canvasClassName = "",
|
|
20
21
|
layoutMessage = "",
|
|
21
|
-
wrapWidget = true
|
|
22
|
+
wrapWidget = true,
|
|
23
|
+
selectedWidgetsButtons = []
|
|
22
24
|
}) => {
|
|
25
|
+
React.useMemo(
|
|
26
|
+
() => validateButtons(selectedWidgetsButtons),
|
|
27
|
+
[selectedWidgetsButtons]
|
|
28
|
+
);
|
|
23
29
|
const [selectedWidgets, setSelectedWidgets] = React.useState([]);
|
|
24
30
|
const entity = __spreadProps(__spreadValues({}, page), {
|
|
25
31
|
widgets: page.widgets.map((w) => __spreadProps(__spreadValues({}, w), {
|
|
@@ -60,8 +66,11 @@ const AdminPageRender = ({
|
|
|
60
66
|
selectedWidgets.length > 0 && /* @__PURE__ */ jsx(
|
|
61
67
|
SelectedWidgetsToolbar,
|
|
62
68
|
{
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
selectedWidgets,
|
|
70
|
+
widgets: entity.widgets,
|
|
71
|
+
buttons: selectedWidgetsButtons,
|
|
72
|
+
onCopy: () => handleCopyWidgets(selectedWidgets, "multiple"),
|
|
73
|
+
onDeselect: () => setSelectedWidgets([])
|
|
65
74
|
}
|
|
66
75
|
),
|
|
67
76
|
entity.widgets.length > 0 && /* @__PURE__ */ jsx(
|
package/dist/Container.js
CHANGED
package/dist/EmbeddedVideo.js
CHANGED
package/dist/Image.js
CHANGED
|
@@ -29,5 +29,25 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
32
52
|
|
|
33
|
-
export { __objRest, __spreadProps, __spreadValues };
|
|
53
|
+
export { __async, __objRest, __spreadProps, __spreadValues };
|
package/dist/imagePlaceholder.js
CHANGED
package/dist/imageSrc.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import './chunk-
|
|
1
|
+
import './chunk-BBZEL7EG.js';
|
|
2
2
|
export { default as Image } from './Image';
|
|
3
3
|
export { default as imageSrc } from './imageSrc';
|
|
4
4
|
export { default as imagePlaceholder } from './imagePlaceholder';
|
|
@@ -9,3 +9,5 @@ export { default as isImagePresent } from './isImagePresent';
|
|
|
9
9
|
export { default as AdminPageRender } from './AdminPageRender';
|
|
10
10
|
export { default as WidgetRender } from './WidgetRender';
|
|
11
11
|
export { default as extractImageValue } from './extractImageValue';
|
|
12
|
+
export { default as SelectedWidgetsButtons, validateButtons } from './lib/SelectedWidgetsButtons';
|
|
13
|
+
export { default as SelectedWidgetsToolbar } from './lib/SelectedWidgetsToolbar';
|
package/dist/isImagePresent.js
CHANGED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { __async } from '../chunk-BBZEL7EG.js';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
|
|
5
|
+
const COUNT_PLACEHOLDER = /\{\{SELECTED_WIDGETS_COUNT\}\}/g;
|
|
6
|
+
const formatLabel = (label, count) => typeof label === "string" ? label.replace(COUNT_PLACEHOLDER, String(count)) : label;
|
|
7
|
+
const renderIcon = (icon) => {
|
|
8
|
+
if (icon === void 0 || icon === null) return null;
|
|
9
|
+
if (React.isValidElement(icon)) return icon;
|
|
10
|
+
if (typeof icon === "string") return /* @__PURE__ */ jsx("img", { src: icon, alt: "" });
|
|
11
|
+
throw new Error(
|
|
12
|
+
"Selected widgets button `icon` must be a React element or an image URL string"
|
|
13
|
+
);
|
|
14
|
+
};
|
|
15
|
+
const validateButton = (button) => {
|
|
16
|
+
if (!button || typeof button !== "object") {
|
|
17
|
+
throw new Error("Selected widgets button must be an object");
|
|
18
|
+
}
|
|
19
|
+
if (typeof button.id !== "string" || button.id === "") {
|
|
20
|
+
throw new Error("Selected widgets button requires a non-empty string `id`");
|
|
21
|
+
}
|
|
22
|
+
if (typeof button.onClick !== "function") {
|
|
23
|
+
throw new Error(
|
|
24
|
+
`Selected widgets button "${button.id}" requires an \`onClick\` function`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
if (button.onError !== void 0 && typeof button.onError !== "function") {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`Selected widgets button "${button.id}" \`onError\` must be a function`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const validateButtons = (buttons) => {
|
|
34
|
+
if (!Array.isArray(buttons)) {
|
|
35
|
+
throw new Error("`selectedWidgetsButtons` must be an array");
|
|
36
|
+
}
|
|
37
|
+
buttons.forEach(validateButton);
|
|
38
|
+
return buttons;
|
|
39
|
+
};
|
|
40
|
+
const joinClassNames = (...classNames) => classNames.filter(Boolean).join(" ");
|
|
41
|
+
const SelectedWidgetsButtons = ({
|
|
42
|
+
buttons = [],
|
|
43
|
+
selectedWidgets = [],
|
|
44
|
+
widgets = [],
|
|
45
|
+
buttonClassName,
|
|
46
|
+
showIcons = true,
|
|
47
|
+
onDeselect
|
|
48
|
+
}) => {
|
|
49
|
+
React.useMemo(() => validateButtons(buttons), [buttons]);
|
|
50
|
+
const [pendingId, setPendingId] = React.useState(null);
|
|
51
|
+
const latestSelectedWidgets = React.useRef(selectedWidgets);
|
|
52
|
+
React.useEffect(() => {
|
|
53
|
+
latestSelectedWidgets.current = selectedWidgets;
|
|
54
|
+
});
|
|
55
|
+
const count = selectedWidgets.length;
|
|
56
|
+
const handleClick = (button) => __async(null, null, function* () {
|
|
57
|
+
const snapshot = [...selectedWidgets];
|
|
58
|
+
const selected = widgets.filter((w) => snapshot.includes(w.widgetId));
|
|
59
|
+
setPendingId(button.id);
|
|
60
|
+
try {
|
|
61
|
+
yield button.onClick(selected);
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (button.onError) {
|
|
64
|
+
button.onError(error, selected);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
throw error;
|
|
68
|
+
} finally {
|
|
69
|
+
setPendingId(null);
|
|
70
|
+
}
|
|
71
|
+
const current = latestSelectedWidgets.current;
|
|
72
|
+
const unchanged = current.length === snapshot.length && snapshot.every((id) => current.includes(id));
|
|
73
|
+
if (onDeselect && unchanged) onDeselect();
|
|
74
|
+
});
|
|
75
|
+
return buttons.map((button) => /* @__PURE__ */ jsxs(
|
|
76
|
+
"button",
|
|
77
|
+
{
|
|
78
|
+
type: "button",
|
|
79
|
+
className: joinClassNames(buttonClassName, button.className),
|
|
80
|
+
disabled: pendingId !== null,
|
|
81
|
+
onClick: () => handleClick(button),
|
|
82
|
+
children: [
|
|
83
|
+
showIcons && renderIcon(button.icon),
|
|
84
|
+
formatLabel(button.label, count)
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
button.id
|
|
88
|
+
));
|
|
89
|
+
};
|
|
90
|
+
var SelectedWidgetsButtons_default = SelectedWidgetsButtons;
|
|
91
|
+
|
|
92
|
+
export { SelectedWidgetsButtons_default as default, formatLabel, renderIcon, validateButtons };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import '../chunk-
|
|
1
|
+
import '../chunk-BBZEL7EG.js';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import SelectedWidgetsButtons from './SelectedWidgetsButtons';
|
|
3
4
|
|
|
4
5
|
const IconCopy = () => /* @__PURE__ */ jsxs(
|
|
5
6
|
"svg",
|
|
6
7
|
{
|
|
8
|
+
"aria-hidden": "true",
|
|
7
9
|
xmlns: "http://www.w3.org/2000/svg",
|
|
8
10
|
width: "16",
|
|
9
11
|
height: "16",
|
|
@@ -36,20 +38,79 @@ const IconCopy = () => /* @__PURE__ */ jsxs(
|
|
|
36
38
|
]
|
|
37
39
|
}
|
|
38
40
|
);
|
|
39
|
-
const
|
|
40
|
-
"
|
|
41
|
+
const IconDelete = () => /* @__PURE__ */ jsxs(
|
|
42
|
+
"svg",
|
|
41
43
|
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
"aria-hidden": "true",
|
|
45
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
46
|
+
width: "16",
|
|
47
|
+
height: "16",
|
|
48
|
+
viewBox: "0 0 16 16",
|
|
49
|
+
fill: "none",
|
|
45
50
|
children: [
|
|
46
|
-
/* @__PURE__ */ jsx(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
/* @__PURE__ */ jsx(
|
|
52
|
+
"path",
|
|
53
|
+
{
|
|
54
|
+
d: "M2 4H14",
|
|
55
|
+
stroke: "white",
|
|
56
|
+
strokeWidth: "2",
|
|
57
|
+
strokeLinecap: "round",
|
|
58
|
+
strokeLinejoin: "round"
|
|
59
|
+
}
|
|
60
|
+
),
|
|
61
|
+
/* @__PURE__ */ jsx(
|
|
62
|
+
"path",
|
|
63
|
+
{
|
|
64
|
+
d: "M12.6667 4V13.3333C12.6667 14 12 14.6667 11.3334 14.6667H4.66671C4.00004 14.6667 3.33337 14 3.33337 13.3333V4",
|
|
65
|
+
stroke: "white",
|
|
66
|
+
strokeWidth: "2",
|
|
67
|
+
strokeLinecap: "round",
|
|
68
|
+
strokeLinejoin: "round"
|
|
69
|
+
}
|
|
70
|
+
),
|
|
71
|
+
/* @__PURE__ */ jsx(
|
|
72
|
+
"path",
|
|
73
|
+
{
|
|
74
|
+
d: "M5.33337 3.99998V2.66665C5.33337 1.99998 6.00004 1.33331 6.66671 1.33331H9.33337C10 1.33331 10.6667 1.99998 10.6667 2.66665V3.99998",
|
|
75
|
+
stroke: "white",
|
|
76
|
+
strokeWidth: "2",
|
|
77
|
+
strokeLinecap: "round",
|
|
78
|
+
strokeLinejoin: "round"
|
|
79
|
+
}
|
|
80
|
+
)
|
|
50
81
|
]
|
|
51
82
|
}
|
|
52
|
-
)
|
|
83
|
+
);
|
|
84
|
+
const BUTTON_CLASS_NAME = "r-button-reset r-toolbar-button";
|
|
85
|
+
const SelectedWidgetsToolbar = ({
|
|
86
|
+
selectedWidgets = [],
|
|
87
|
+
widgets = [],
|
|
88
|
+
buttons = [],
|
|
89
|
+
onCopy,
|
|
90
|
+
onRemove,
|
|
91
|
+
onDeselect
|
|
92
|
+
}) => /* @__PURE__ */ jsx("div", { className: "r-selected-widgets-toolbar", children: /* @__PURE__ */ jsxs("div", { className: "r-toolbar-inner", children: [
|
|
93
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: BUTTON_CLASS_NAME, onClick: onCopy, children: [
|
|
94
|
+
/* @__PURE__ */ jsx(IconCopy, {}),
|
|
95
|
+
"Copy selected (",
|
|
96
|
+
selectedWidgets.length,
|
|
97
|
+
")"
|
|
98
|
+
] }),
|
|
99
|
+
/* @__PURE__ */ jsx(
|
|
100
|
+
SelectedWidgetsButtons,
|
|
101
|
+
{
|
|
102
|
+
buttons,
|
|
103
|
+
selectedWidgets,
|
|
104
|
+
widgets,
|
|
105
|
+
buttonClassName: BUTTON_CLASS_NAME,
|
|
106
|
+
onDeselect
|
|
107
|
+
}
|
|
108
|
+
),
|
|
109
|
+
onRemove && /* @__PURE__ */ jsxs("button", { type: "button", className: BUTTON_CLASS_NAME, onClick: onRemove, children: [
|
|
110
|
+
/* @__PURE__ */ jsx(IconDelete, {}),
|
|
111
|
+
"Delete selected"
|
|
112
|
+
] })
|
|
113
|
+
] }) });
|
|
53
114
|
var SelectedWidgetsToolbar_default = SelectedWidgetsToolbar;
|
|
54
115
|
|
|
55
116
|
export { SelectedWidgetsToolbar_default as default };
|
package/dist/toHTML.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@raketa-builder/support",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "./dist/index.js",
|
|
5
6
|
"module": "./dist/index.mjs",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
|
@@ -8,7 +9,7 @@
|
|
|
8
9
|
"exports": {
|
|
9
10
|
".": {
|
|
10
11
|
"import": {
|
|
11
|
-
"types": "./dist/index.d.
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
12
13
|
"default": "./dist/index.js"
|
|
13
14
|
}
|
|
14
15
|
},
|