@raketa-builder/support 0.4.0 → 0.6.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/.turbo/turbo-build.log +3 -3
- package/dist/index.js +223 -0
- package/package.json +1 -1
- package/src/AdminPageRender/AdminWidgetMinimal.js +94 -0
- package/src/AdminPageRender/IconButton.js +31 -0
- package/src/AdminPageRender/index.js +64 -0
- package/src/index.js +2 -0
- package/src/lib/SelectedWidgetsToolbar.js +48 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @raketa-builder/support@0.
|
|
2
|
+
> @raketa-builder/support@0.6.0 build
|
|
3
3
|
> tsup src/index.js --format cjs --loader ".js=jsx"
|
|
4
4
|
|
|
5
5
|
CLI Building entry: src/index.js
|
|
@@ -7,5 +7,5 @@ CLI Using tsconfig: tsconfig.json
|
|
|
7
7
|
CLI tsup v6.5.0
|
|
8
8
|
CLI Target: es6
|
|
9
9
|
CJS Build start
|
|
10
|
-
CJS dist/index.js
|
|
11
|
-
CJS ⚡️ Build success in
|
|
10
|
+
CJS dist/index.js 19.97 KB
|
|
11
|
+
CJS ⚡️ Build success in 101ms
|
package/dist/index.js
CHANGED
|
@@ -52,6 +52,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
52
52
|
// src/index.js
|
|
53
53
|
var src_exports = {};
|
|
54
54
|
__export(src_exports, {
|
|
55
|
+
AdminPageRender: () => AdminPageRender_default,
|
|
55
56
|
Container: () => Container_default,
|
|
56
57
|
EmbeddedVideo: () => EmbeddedVideo_default,
|
|
57
58
|
Image: () => Image_default,
|
|
@@ -357,8 +358,230 @@ function isImagePresent(value) {
|
|
|
357
358
|
return !!value;
|
|
358
359
|
}
|
|
359
360
|
var isImagePresent_default = isImagePresent;
|
|
361
|
+
|
|
362
|
+
// src/AdminPageRender/index.js
|
|
363
|
+
var import_react6 = __toESM(require("react"));
|
|
364
|
+
|
|
365
|
+
// src/AdminPageRender/AdminWidgetMinimal.js
|
|
366
|
+
var import_react5 = __toESM(require("react"));
|
|
367
|
+
|
|
368
|
+
// src/AdminPageRender/IconButton.js
|
|
369
|
+
var import_react4 = __toESM(require("react"));
|
|
370
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
371
|
+
var ICON_COPY = "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItY29weSI+PHJlY3QgeD0iOSIgeT0iOSIgd2lkdGg9IjEzIiBoZWlnaHQ9IjEzIiByeD0iMiIgcnk9IjIiPjwvcmVjdD48cGF0aCBkPSJNNSAxNUg0YTIgMiAwIDAgMS0yLTJWNGEyIDIgMCAwIDEgMi0yaDlhMiAyIDAgMCAxIDIgMnYxIj48L3BhdGg+PC9zdmc+";
|
|
372
|
+
var IconButton = (props) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
373
|
+
"button",
|
|
374
|
+
__spreadValues({
|
|
375
|
+
type: "button",
|
|
376
|
+
style: {
|
|
377
|
+
display: "inline-block",
|
|
378
|
+
width: "32px",
|
|
379
|
+
height: "32px",
|
|
380
|
+
marginRight: "4px",
|
|
381
|
+
marginLeft: "0px",
|
|
382
|
+
appearance: "none",
|
|
383
|
+
outline: "0",
|
|
384
|
+
border: "0",
|
|
385
|
+
borderRadius: "3px",
|
|
386
|
+
background: "transparent",
|
|
387
|
+
backgroundColor: "#fff",
|
|
388
|
+
backgroundRepeat: "no-repeat",
|
|
389
|
+
backgroundPosition: "center",
|
|
390
|
+
backgroundSize: "50%",
|
|
391
|
+
backgroundImage: `url(${ICON_COPY})`,
|
|
392
|
+
cursor: "pointer"
|
|
393
|
+
}
|
|
394
|
+
}, props)
|
|
395
|
+
);
|
|
396
|
+
var IconButton_default = IconButton;
|
|
397
|
+
|
|
398
|
+
// src/AdminPageRender/AdminWidgetMinimal.js
|
|
399
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
400
|
+
function cn() {
|
|
401
|
+
return Array.from(arguments).filter(Boolean).map(String).join(" ");
|
|
402
|
+
}
|
|
403
|
+
var AdminWidgetWrapper = (_a) => {
|
|
404
|
+
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
405
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", __spreadValues({ className: cn("r-admin-widget-wrapper", className) }, rest));
|
|
406
|
+
};
|
|
407
|
+
var AdminWidgetToolbar = (_a) => {
|
|
408
|
+
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
409
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
410
|
+
"div",
|
|
411
|
+
__spreadValues({
|
|
412
|
+
className: cn("r-reset", "r-admin-widget-toolbar", className)
|
|
413
|
+
}, rest)
|
|
414
|
+
);
|
|
415
|
+
};
|
|
416
|
+
var AdminWidgetLabel = (_a) => {
|
|
417
|
+
var _b = _a, { className } = _b, rest = __objRest(_b, ["className"]);
|
|
418
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
419
|
+
"div",
|
|
420
|
+
__spreadValues({
|
|
421
|
+
className: cn("r-reset", "r-fs-small", "r-admin-widget-label", className)
|
|
422
|
+
}, rest)
|
|
423
|
+
);
|
|
424
|
+
};
|
|
425
|
+
var title = (widget) => {
|
|
426
|
+
return widget.Config.title;
|
|
427
|
+
};
|
|
428
|
+
var deprecated = (widget) => {
|
|
429
|
+
return widget.Config.deprecated;
|
|
430
|
+
};
|
|
431
|
+
var AdminWidgetMinimal = ({
|
|
432
|
+
library,
|
|
433
|
+
adminLibrary,
|
|
434
|
+
widget,
|
|
435
|
+
onCopy,
|
|
436
|
+
onSelectWidget,
|
|
437
|
+
selectedWidgets
|
|
438
|
+
}) => {
|
|
439
|
+
const currentWidget = library[widget.component];
|
|
440
|
+
const currentAdminWidget = adminLibrary[widget.component];
|
|
441
|
+
const isSelected = selectedWidgets.filter((w) => w === widget.widgetId).length > 0;
|
|
442
|
+
if (!currentWidget || !currentAdminWidget) {
|
|
443
|
+
console.error(`Unknown widget: ${widget.component}`);
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
const handleCopyWidget = () => {
|
|
447
|
+
const widgetsToCopy = [widget];
|
|
448
|
+
onCopy(widgetsToCopy);
|
|
449
|
+
};
|
|
450
|
+
const handleSelectWidget = () => onSelectWidget(widget.widgetId);
|
|
451
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(AdminWidgetWrapper, { "data-widget": widget.component, children: [
|
|
452
|
+
isSelected && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "r-selected-widget" }),
|
|
453
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(AdminWidgetToolbar, { "data-toolbar": true, children: [
|
|
454
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
455
|
+
"input",
|
|
456
|
+
{
|
|
457
|
+
type: "checkbox",
|
|
458
|
+
style: {
|
|
459
|
+
width: "32px",
|
|
460
|
+
aspectRatio: 1
|
|
461
|
+
},
|
|
462
|
+
onChange: handleSelectWidget,
|
|
463
|
+
checked: isSelected
|
|
464
|
+
}
|
|
465
|
+
),
|
|
466
|
+
!isSelected && !deprecated(currentAdminWidget) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(IconButton_default, { onClick: handleCopyWidget })
|
|
467
|
+
] }),
|
|
468
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AdminWidgetLabel, { "data-widget-label": true, children: title(currentAdminWidget) }),
|
|
469
|
+
import_react5.default.createElement(currentWidget, widget.settings)
|
|
470
|
+
] });
|
|
471
|
+
};
|
|
472
|
+
AdminWidgetMinimal.defaultProps = {
|
|
473
|
+
containerSettings: {}
|
|
474
|
+
};
|
|
475
|
+
var AdminWidgetMinimal_default = AdminWidgetMinimal;
|
|
476
|
+
|
|
477
|
+
// src/lib/SelectedWidgetsToolbar.js
|
|
478
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
479
|
+
var IconCopy = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
480
|
+
"svg",
|
|
481
|
+
{
|
|
482
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
483
|
+
width: "16",
|
|
484
|
+
height: "16",
|
|
485
|
+
viewBox: "0 0 16 16",
|
|
486
|
+
fill: "none",
|
|
487
|
+
children: [
|
|
488
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("g", { clipPath: "url(#clip0_2312_498)", children: [
|
|
489
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
490
|
+
"path",
|
|
491
|
+
{
|
|
492
|
+
d: "M13.3334 5.33331H6.66671C5.93033 5.33331 5.33337 5.93027 5.33337 6.66665V13.3333C5.33337 14.0697 5.93033 14.6666 6.66671 14.6666H13.3334C14.0698 14.6666 14.6667 14.0697 14.6667 13.3333V6.66665C14.6667 5.93027 14.0698 5.33331 13.3334 5.33331Z",
|
|
493
|
+
stroke: "white",
|
|
494
|
+
strokeWidth: "2",
|
|
495
|
+
strokeLinecap: "round",
|
|
496
|
+
strokeLinejoin: "round"
|
|
497
|
+
}
|
|
498
|
+
),
|
|
499
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
500
|
+
"path",
|
|
501
|
+
{
|
|
502
|
+
d: "M2.66671 10.6666C1.93337 10.6666 1.33337 10.0666 1.33337 9.33331V2.66665C1.33337 1.93331 1.93337 1.33331 2.66671 1.33331H9.33337C10.0667 1.33331 10.6667 1.93331 10.6667 2.66665",
|
|
503
|
+
stroke: "white",
|
|
504
|
+
strokeWidth: "2",
|
|
505
|
+
strokeLinecap: "round",
|
|
506
|
+
strokeLinejoin: "round"
|
|
507
|
+
}
|
|
508
|
+
)
|
|
509
|
+
] }),
|
|
510
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("clipPath", { id: "clip0_2312_498", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("rect", { width: "16", height: "16", fill: "white" }) }) })
|
|
511
|
+
]
|
|
512
|
+
}
|
|
513
|
+
);
|
|
514
|
+
var SelectedWidgetsToolbar = ({ length, onCopy }) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "r-selected-widgets-toolbar", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "r-toolbar-inner", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
515
|
+
"button",
|
|
516
|
+
{
|
|
517
|
+
type: "button",
|
|
518
|
+
className: "r-button-reset r-toolbar-button",
|
|
519
|
+
onClick: onCopy,
|
|
520
|
+
children: [
|
|
521
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)(IconCopy, {}),
|
|
522
|
+
"Copy selected (",
|
|
523
|
+
length,
|
|
524
|
+
")"
|
|
525
|
+
]
|
|
526
|
+
}
|
|
527
|
+
) }) });
|
|
528
|
+
var SelectedWidgetsToolbar_default = SelectedWidgetsToolbar;
|
|
529
|
+
|
|
530
|
+
// src/AdminPageRender/index.js
|
|
531
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
532
|
+
var saveToLocalStorage = (identifier, widgets) => window.localStorage.setItem(
|
|
533
|
+
`clipboard\u2013${identifier}`,
|
|
534
|
+
JSON.stringify(widgets)
|
|
535
|
+
);
|
|
536
|
+
var AdminPageRender = ({ page, library, adminLibrary, identifier }) => {
|
|
537
|
+
const [selectedWidgets, setSelectedWidgets] = import_react6.default.useState([]);
|
|
538
|
+
const handleSelectWidget = (newWidget) => {
|
|
539
|
+
setSelectedWidgets((oldList) => {
|
|
540
|
+
const isUnique = oldList.filter((w) => w === newWidget).length <= 0;
|
|
541
|
+
if (isUnique) {
|
|
542
|
+
return [...oldList, newWidget];
|
|
543
|
+
} else {
|
|
544
|
+
return oldList.filter((w) => w !== newWidget);
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
};
|
|
548
|
+
const handleCopyWidgets = (widgets, copyType) => {
|
|
549
|
+
if (copyType === "multiple") {
|
|
550
|
+
const filterSelected = page.widgets.filter(
|
|
551
|
+
(w) => widgets.some((c) => w.widgetId === c)
|
|
552
|
+
);
|
|
553
|
+
saveToLocalStorage(identifier, filterSelected);
|
|
554
|
+
setSelectedWidgets([]);
|
|
555
|
+
return;
|
|
556
|
+
}
|
|
557
|
+
saveToLocalStorage(identifier, widgets);
|
|
558
|
+
};
|
|
559
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_react6.default.Fragment, { children: [
|
|
560
|
+
selectedWidgets.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
561
|
+
SelectedWidgetsToolbar_default,
|
|
562
|
+
{
|
|
563
|
+
length: selectedWidgets.length,
|
|
564
|
+
onCopy: () => handleCopyWidgets(selectedWidgets, "multiple")
|
|
565
|
+
}
|
|
566
|
+
),
|
|
567
|
+
page.widgets.map(({ widgetId, component, settings }) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
568
|
+
AdminWidgetMinimal_default,
|
|
569
|
+
{
|
|
570
|
+
library,
|
|
571
|
+
adminLibrary,
|
|
572
|
+
widget: { widgetId, component, settings },
|
|
573
|
+
onCopy: handleCopyWidgets,
|
|
574
|
+
onSelectWidget: handleSelectWidget,
|
|
575
|
+
selectedWidgets
|
|
576
|
+
},
|
|
577
|
+
widgetId
|
|
578
|
+
))
|
|
579
|
+
] });
|
|
580
|
+
};
|
|
581
|
+
var AdminPageRender_default = AdminPageRender;
|
|
360
582
|
// Annotate the CommonJS export names for ESM import in node:
|
|
361
583
|
0 && (module.exports = {
|
|
584
|
+
AdminPageRender,
|
|
362
585
|
Container,
|
|
363
586
|
EmbeddedVideo,
|
|
364
587
|
Image,
|
package/package.json
CHANGED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/* eslint-disable no-undef */
|
|
2
|
+
import React from "react";
|
|
3
|
+
import IconButton from "./IconButton";
|
|
4
|
+
|
|
5
|
+
function cn() {
|
|
6
|
+
return Array.from(arguments).filter(Boolean).map(String).join(" ");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const AdminWidgetWrapper = ({ className, ...rest }) => (
|
|
10
|
+
<div className={cn("r-admin-widget-wrapper", className)} {...rest} />
|
|
11
|
+
);
|
|
12
|
+
|
|
13
|
+
const AdminWidgetToolbar = ({ className, ...rest }) => (
|
|
14
|
+
<div
|
|
15
|
+
className={cn("r-reset", "r-admin-widget-toolbar", className)}
|
|
16
|
+
{...rest}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const AdminWidgetLabel = ({ className, ...rest }) => (
|
|
21
|
+
<div
|
|
22
|
+
className={cn("r-reset", "r-fs-small", "r-admin-widget-label", className)}
|
|
23
|
+
{...rest}
|
|
24
|
+
/>
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const title = (widget) => {
|
|
28
|
+
return widget.Config.title;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const deprecated = (widget) => {
|
|
32
|
+
return widget.Config.deprecated;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const AdminWidgetMinimal = ({
|
|
36
|
+
library,
|
|
37
|
+
adminLibrary,
|
|
38
|
+
widget,
|
|
39
|
+
onCopy,
|
|
40
|
+
onSelectWidget,
|
|
41
|
+
selectedWidgets,
|
|
42
|
+
}) => {
|
|
43
|
+
const currentWidget = library[widget.component];
|
|
44
|
+
const currentAdminWidget = adminLibrary[widget.component];
|
|
45
|
+
|
|
46
|
+
const isSelected =
|
|
47
|
+
selectedWidgets.filter((w) => w === widget.widgetId).length > 0;
|
|
48
|
+
|
|
49
|
+
if (!currentWidget || !currentAdminWidget) {
|
|
50
|
+
console.error(`Unknown widget: ${widget.component}`);
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const handleCopyWidget = () => {
|
|
55
|
+
const widgetsToCopy = [widget];
|
|
56
|
+
onCopy(widgetsToCopy);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const handleSelectWidget = () => onSelectWidget(widget.widgetId);
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<AdminWidgetWrapper data-widget={widget.component}>
|
|
63
|
+
{isSelected && <div className="r-selected-widget" />}
|
|
64
|
+
|
|
65
|
+
<AdminWidgetToolbar data-toolbar>
|
|
66
|
+
<input
|
|
67
|
+
type="checkbox"
|
|
68
|
+
style={{
|
|
69
|
+
width: "32px",
|
|
70
|
+
aspectRatio: 1,
|
|
71
|
+
}}
|
|
72
|
+
onChange={handleSelectWidget}
|
|
73
|
+
checked={isSelected}
|
|
74
|
+
/>
|
|
75
|
+
|
|
76
|
+
{!isSelected && !deprecated(currentAdminWidget) && (
|
|
77
|
+
<IconButton onClick={handleCopyWidget} />
|
|
78
|
+
)}
|
|
79
|
+
</AdminWidgetToolbar>
|
|
80
|
+
|
|
81
|
+
<AdminWidgetLabel data-widget-label>
|
|
82
|
+
{title(currentAdminWidget)}
|
|
83
|
+
</AdminWidgetLabel>
|
|
84
|
+
|
|
85
|
+
{React.createElement(currentWidget, widget.settings)}
|
|
86
|
+
</AdminWidgetWrapper>
|
|
87
|
+
);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
AdminWidgetMinimal.defaultProps = {
|
|
91
|
+
containerSettings: {},
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export default AdminWidgetMinimal;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
|
|
3
|
+
const ICON_COPY =
|
|
4
|
+
"data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNCIgaGVpZ2h0PSIyNCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9ImN1cnJlbnRDb2xvciIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJmZWF0aGVyIGZlYXRoZXItY29weSI+PHJlY3QgeD0iOSIgeT0iOSIgd2lkdGg9IjEzIiBoZWlnaHQ9IjEzIiByeD0iMiIgcnk9IjIiPjwvcmVjdD48cGF0aCBkPSJNNSAxNUg0YTIgMiAwIDAgMS0yLTJWNGEyIDIgMCAwIDEgMi0yaDlhMiAyIDAgMCAxIDIgMnYxIj48L3BhdGg+PC9zdmc+";
|
|
5
|
+
|
|
6
|
+
const IconButton = (props) => (
|
|
7
|
+
<button
|
|
8
|
+
type="button"
|
|
9
|
+
style={{
|
|
10
|
+
display: "inline-block",
|
|
11
|
+
width: "32px",
|
|
12
|
+
height: "32px",
|
|
13
|
+
marginRight: "4px",
|
|
14
|
+
marginLeft: "0px",
|
|
15
|
+
appearance: "none",
|
|
16
|
+
outline: "0",
|
|
17
|
+
border: "0",
|
|
18
|
+
borderRadius: "3px",
|
|
19
|
+
background: "transparent",
|
|
20
|
+
backgroundColor: "#fff",
|
|
21
|
+
backgroundRepeat: "no-repeat",
|
|
22
|
+
backgroundPosition: "center",
|
|
23
|
+
backgroundSize: "50%",
|
|
24
|
+
backgroundImage: `url(${ICON_COPY})`,
|
|
25
|
+
cursor: "pointer",
|
|
26
|
+
}}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export default IconButton;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import AdminWidgetMinimal from "./AdminWidgetMinimal";
|
|
3
|
+
import SelectedWidgetsToolbar from "../lib/SelectedWidgetsToolbar";
|
|
4
|
+
|
|
5
|
+
const saveToLocalStorage = (identifier, widgets) =>
|
|
6
|
+
window.localStorage.setItem(
|
|
7
|
+
`clipboard–${identifier}`,
|
|
8
|
+
JSON.stringify(widgets)
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
const AdminPageRender = ({ page, library, adminLibrary, identifier }) => {
|
|
12
|
+
const [selectedWidgets, setSelectedWidgets] = React.useState([]);
|
|
13
|
+
|
|
14
|
+
const handleSelectWidget = (newWidget) => {
|
|
15
|
+
setSelectedWidgets((oldList) => {
|
|
16
|
+
const isUnique = oldList.filter((w) => w === newWidget).length <= 0;
|
|
17
|
+
|
|
18
|
+
if (isUnique) {
|
|
19
|
+
return [...oldList, newWidget];
|
|
20
|
+
} else {
|
|
21
|
+
return oldList.filter((w) => w !== newWidget);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const handleCopyWidgets = (widgets, copyType) => {
|
|
27
|
+
if (copyType === "multiple") {
|
|
28
|
+
const filterSelected = page.widgets.filter((w) =>
|
|
29
|
+
widgets.some((c) => w.widgetId === c)
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
saveToLocalStorage(identifier, filterSelected);
|
|
33
|
+
setSelectedWidgets([]);
|
|
34
|
+
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
saveToLocalStorage(identifier, widgets);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<React.Fragment>
|
|
43
|
+
{selectedWidgets.length > 0 && (
|
|
44
|
+
<SelectedWidgetsToolbar
|
|
45
|
+
length={selectedWidgets.length}
|
|
46
|
+
onCopy={() => handleCopyWidgets(selectedWidgets, "multiple")}
|
|
47
|
+
/>
|
|
48
|
+
)}
|
|
49
|
+
{page.widgets.map(({ widgetId, component, settings }) => (
|
|
50
|
+
<AdminWidgetMinimal
|
|
51
|
+
key={widgetId}
|
|
52
|
+
library={library}
|
|
53
|
+
adminLibrary={adminLibrary}
|
|
54
|
+
widget={{ widgetId, component, settings }}
|
|
55
|
+
onCopy={handleCopyWidgets}
|
|
56
|
+
onSelectWidget={handleSelectWidget}
|
|
57
|
+
selectedWidgets={selectedWidgets}
|
|
58
|
+
/>
|
|
59
|
+
))}
|
|
60
|
+
</React.Fragment>
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export default AdminPageRender;
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ import Container from "./Container";
|
|
|
5
5
|
import EmbeddedVideo from "./EmbeddedVideo";
|
|
6
6
|
import toHTML from "./toHTML";
|
|
7
7
|
import isImagePresent from "./isImagePresent";
|
|
8
|
+
import AdminPageRender from "./AdminPageRender";
|
|
8
9
|
|
|
9
10
|
export {
|
|
10
11
|
Image,
|
|
@@ -14,4 +15,5 @@ export {
|
|
|
14
15
|
Container,
|
|
15
16
|
EmbeddedVideo,
|
|
16
17
|
toHTML,
|
|
18
|
+
AdminPageRender,
|
|
17
19
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const IconCopy = () => (
|
|
2
|
+
<svg
|
|
3
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
4
|
+
width="16"
|
|
5
|
+
height="16"
|
|
6
|
+
viewBox="0 0 16 16"
|
|
7
|
+
fill="none"
|
|
8
|
+
>
|
|
9
|
+
<g clipPath="url(#clip0_2312_498)">
|
|
10
|
+
<path
|
|
11
|
+
d="M13.3334 5.33331H6.66671C5.93033 5.33331 5.33337 5.93027 5.33337 6.66665V13.3333C5.33337 14.0697 5.93033 14.6666 6.66671 14.6666H13.3334C14.0698 14.6666 14.6667 14.0697 14.6667 13.3333V6.66665C14.6667 5.93027 14.0698 5.33331 13.3334 5.33331Z"
|
|
12
|
+
stroke="white"
|
|
13
|
+
strokeWidth="2"
|
|
14
|
+
strokeLinecap="round"
|
|
15
|
+
strokeLinejoin="round"
|
|
16
|
+
/>
|
|
17
|
+
<path
|
|
18
|
+
d="M2.66671 10.6666C1.93337 10.6666 1.33337 10.0666 1.33337 9.33331V2.66665C1.33337 1.93331 1.93337 1.33331 2.66671 1.33331H9.33337C10.0667 1.33331 10.6667 1.93331 10.6667 2.66665"
|
|
19
|
+
stroke="white"
|
|
20
|
+
strokeWidth="2"
|
|
21
|
+
strokeLinecap="round"
|
|
22
|
+
strokeLinejoin="round"
|
|
23
|
+
/>
|
|
24
|
+
</g>
|
|
25
|
+
<defs>
|
|
26
|
+
<clipPath id="clip0_2312_498">
|
|
27
|
+
<rect width="16" height="16" fill="white" />
|
|
28
|
+
</clipPath>
|
|
29
|
+
</defs>
|
|
30
|
+
</svg>
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const SelectedWidgetsToolbar = ({ length, onCopy }) => (
|
|
34
|
+
<div className="r-selected-widgets-toolbar">
|
|
35
|
+
<div className="r-toolbar-inner">
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
className="r-button-reset r-toolbar-button"
|
|
39
|
+
onClick={onCopy}
|
|
40
|
+
>
|
|
41
|
+
<IconCopy />
|
|
42
|
+
Copy selected ({length})
|
|
43
|
+
</button>
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
export default SelectedWidgetsToolbar;
|