@superblocksteam/library 2.0.41-next.1 → 2.0.41-next.11

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/index.js CHANGED
@@ -15,8 +15,8 @@ import { trace } from "@opentelemetry/api";
15
15
  import { observer } from "mobx-react-lite";
16
16
  import { compile, middleware, prefixer, serialize, stringify } from "stylis";
17
17
  import polyfill from "@oddbird/css-anchor-positioning/fn";
18
- import * as Popover from "@radix-ui/react-popover";
19
18
  import { DndContext, DragOverlay, PointerSensor, rectIntersection, useDndMonitor, useDraggable, useDroppable, useSensor, useSensors } from "@dnd-kit/core";
19
+ import * as Popover from "@radix-ui/react-popover";
20
20
  import { snapCenterToCursor } from "@dnd-kit/modifiers";
21
21
  import { Root, TooltipContent, TooltipPortal, TooltipProvider, TooltipTrigger } from "@radix-ui/react-tooltip";
22
22
  import tinycolor from "tinycolor2";
@@ -2200,6 +2200,97 @@ const CSS_CLASSES = {
2200
2200
  ANCHOR_NAME: "sb-anchor-name"
2201
2201
  };
2202
2202
 
2203
+ //#endregion
2204
+ //#region src/edit-mode/dnd/hooks/use-component-draggable.ts
2205
+ function useComponentDraggable({ instanceId, disableDrag }) {
2206
+ return useDraggable({
2207
+ id: instanceId,
2208
+ disabled: disableDrag,
2209
+ data: { instanceId }
2210
+ });
2211
+ }
2212
+
2213
+ //#endregion
2214
+ //#region src/edit-mode/dnd/use-draggable-widget.ts
2215
+ function useDraggableWidget(props) {
2216
+ const editStore = getEditStore();
2217
+ const disableDrag = props.disableDrag || editStore.ui.dnd.isDraggingNewComponent;
2218
+ const specificWidgetDragDisabled = !editStore.ui.dnd.canDragWidget(props.instanceId);
2219
+ const { setNodeRef, isDragging, listeners, attributes } = useComponentDraggable({
2220
+ instanceId: props.instanceId,
2221
+ disableDrag: disableDrag ?? false
2222
+ });
2223
+ const onPointerDown = useCallback((e) => {
2224
+ if (specificWidgetDragDisabled) e.stopPropagation();
2225
+ else listeners?.onPointerDown(e);
2226
+ }, [specificWidgetDragDisabled, listeners]);
2227
+ const onPointerMove = useCallback((e) => {
2228
+ if (specificWidgetDragDisabled) e.stopPropagation();
2229
+ else listeners?.onPointerMove(e);
2230
+ }, [specificWidgetDragDisabled, listeners]);
2231
+ return useMemo(() => {
2232
+ return {
2233
+ ...listeners,
2234
+ ...attributes,
2235
+ className: "sb-draggable-wrapper",
2236
+ "data-is-dragged": isDragging,
2237
+ onPointerDown,
2238
+ onPointerMove,
2239
+ setNodeRef
2240
+ };
2241
+ }, [
2242
+ listeners,
2243
+ attributes,
2244
+ isDragging,
2245
+ onPointerDown,
2246
+ onPointerMove,
2247
+ setNodeRef
2248
+ ]);
2249
+ }
2250
+
2251
+ //#endregion
2252
+ //#region src/lib/internal-details/draggable-context-provider.tsx
2253
+ const DraggablePropsContext = createContext({
2254
+ instanceId: void 0,
2255
+ props: {
2256
+ className: void 0,
2257
+ ref: null
2258
+ }
2259
+ });
2260
+ const DraggablePropsProvider = ({ identifier, disableDrag, children }) => {
2261
+ const draggableWidgetProps = useDraggableWidget({
2262
+ instanceId: identifier.instanceId,
2263
+ disableDrag
2264
+ });
2265
+ const setNodeRef = draggableWidgetProps.setNodeRef;
2266
+ const handleRef = useCallback((el) => {
2267
+ setNodeRef(el);
2268
+ }, [setNodeRef]);
2269
+ const value = useMemo(() => {
2270
+ return {
2271
+ instanceId: identifier.instanceId,
2272
+ props: {
2273
+ ...draggableWidgetProps,
2274
+ ref: handleRef
2275
+ }
2276
+ };
2277
+ }, [
2278
+ draggableWidgetProps,
2279
+ handleRef,
2280
+ identifier.instanceId
2281
+ ]);
2282
+ return /* @__PURE__ */ jsx(DraggablePropsContext.Provider, {
2283
+ value,
2284
+ children
2285
+ });
2286
+ };
2287
+ const EMPTY_PROPS = {};
2288
+ const useMyDraggableProps = (instanceId) => {
2289
+ const contextValue = useContext(DraggablePropsContext);
2290
+ if (contextValue.instanceId !== instanceId) return EMPTY_PROPS;
2291
+ return contextValue.props;
2292
+ };
2293
+
2203
2294
  //#endregion
2204
2295
  //#region src/lib/user-facing/assets/icons/close.svg
2205
2296
  var _path$4;
@@ -3172,6 +3263,33 @@ const WrappedReactiveComponent = (props) => {
3172
3263
  };
3173
3264
  var reactive_component_default = WrappedReactiveComponent;
3174
3265
 
3266
+ //#endregion
3267
+ //#region src/lib/internal-details/editor-reactive-component.tsx
3268
+ const mergeProps = (props1, props2) => {
3269
+ const mergedClassName = props1.className && props2.className ? `${props1.className} ${props2.className}` : props1.className || props2.className;
3270
+ const mergedStyle = {
3271
+ ...props1.style,
3272
+ ...props2.style
3273
+ };
3274
+ return {
3275
+ ...props1,
3276
+ ...props2,
3277
+ style: mergedStyle,
3278
+ className: mergedClassName
3279
+ };
3280
+ };
3281
+ const EditorReactiveComponent = (props) => {
3282
+ const { editorProps,...restProps } = props;
3283
+ const myDraggableProps = useMyDraggableProps(props.identifier.instanceId);
3284
+ const mergedEditorProps = useMemo(() => {
3285
+ return mergeProps(editorProps ?? {}, myDraggableProps);
3286
+ }, [editorProps, myDraggableProps]);
3287
+ return /* @__PURE__ */ jsx(reactive_component_default, {
3288
+ ...restProps,
3289
+ editorProps: mergedEditorProps
3290
+ });
3291
+ };
3292
+
3175
3293
  //#endregion
3176
3294
  //#region src/lib/utils/is-component-type-detached.ts
3177
3295
  function isComponentTypeDetached(componentType) {
@@ -3399,45 +3517,6 @@ const DroppableWidget = observer((props) => {
3399
3517
  });
3400
3518
  var droppable_widget_default = DroppableWidget;
3401
3519
 
3402
- //#endregion
3403
- //#region src/edit-mode/dnd/hooks/use-component-draggable.ts
3404
- function useComponentDraggable({ instanceId, disableDrag }) {
3405
- return useDraggable({
3406
- id: instanceId,
3407
- disabled: disableDrag,
3408
- data: { instanceId }
3409
- });
3410
- }
3411
-
3412
- //#endregion
3413
- //#region src/edit-mode/dnd/use-draggable-widget.ts
3414
- function useDraggableWidget(props) {
3415
- const editStore = getEditStore();
3416
- const disableDrag = props.disableDrag || editStore.ui.dnd.isDraggingNewComponent;
3417
- const specificWidgetDragDisabled = !editStore.ui.dnd.canDragWidget(props.instanceId);
3418
- const { setNodeRef, isDragging, listeners, attributes } = useComponentDraggable({
3419
- instanceId: props.instanceId,
3420
- disableDrag: disableDrag ?? false
3421
- });
3422
- const onPointerDown = useCallback((e) => {
3423
- if (specificWidgetDragDisabled) e.stopPropagation();
3424
- else listeners?.onPointerDown(e);
3425
- }, [specificWidgetDragDisabled, listeners]);
3426
- const onPointerMove = useCallback((e) => {
3427
- if (specificWidgetDragDisabled) e.stopPropagation();
3428
- else listeners?.onPointerMove(e);
3429
- }, [specificWidgetDragDisabled, listeners]);
3430
- return {
3431
- ...listeners,
3432
- ...attributes,
3433
- className: "sb-draggable-wrapper",
3434
- "data-is-dragged": isDragging,
3435
- onPointerDown,
3436
- onPointerMove,
3437
- setNodeRef
3438
- };
3439
- }
3440
-
3441
3520
  //#endregion
3442
3521
  //#region src/edit-mode/hooks/use-right-click-menu.ts
3443
3522
  function useRightClickMenu({ sourceId }) {
@@ -4561,18 +4640,6 @@ const EditWrapper = observer(function EditWrapper$1(props) {
4561
4640
  });
4562
4641
  const isDroppable = isEntityDroppable({ type: props.type });
4563
4642
  const disableDrag = !isDraggable || !isContentDraggable(props.type);
4564
- const draggableWidgetProps = useDraggableWidget({
4565
- instanceId: props.identifier.instanceId,
4566
- disableDrag
4567
- });
4568
- const { setDraggableNodeRef, draggableClassName, draggableProps } = useMemo(() => {
4569
- const { setNodeRef: setDraggableNodeRef$1, className: draggableClassName$1,...draggableProps$1 } = draggableWidgetProps;
4570
- return {
4571
- setDraggableNodeRef: setDraggableNodeRef$1,
4572
- draggableClassName: draggableClassName$1,
4573
- draggableProps: draggableProps$1
4574
- };
4575
- }, [draggableWidgetProps]);
4576
4643
  const { onContextMenu } = useRightClickMenu({ sourceId: props.identifier.sourceId });
4577
4644
  const showVisibilityBackground = props.widgetProps.isVisible === false && !editStore.ui.getSelectedSourceIds().includes(props.identifier.sourceId);
4578
4645
  const handleClick = useCallback((ev) => {
@@ -4592,13 +4659,10 @@ const EditWrapper = observer(function EditWrapper$1(props) {
4592
4659
  stopPropagation();
4593
4660
  }, [props.identifier.sourceId, props.identifier.instanceId]);
4594
4661
  const [dropTargetElem, setDropTargetElem] = useState(null);
4595
- const handleRef = useCallback((el) => {
4596
- setDraggableNodeRef(el);
4597
- }, [setDraggableNodeRef]);
4598
4662
  const isEmpty$1 = React.Children.count(children) === 0;
4599
4663
  const editorProps = useMemo(() => {
4600
4664
  const testProps = identifier.name.isAnonymous ? {} : { "data-test": `component-${identifier.name.value}` };
4601
- const componentClassName = `${CSS_CLASSES.ANCHOR_NAME} ${draggableClassName}`;
4665
+ const componentClassName = `${CSS_CLASSES.ANCHOR_NAME}`;
4602
4666
  const componentStyle = createAnchorNameStyle({ instanceId: props.identifier.instanceId });
4603
4667
  return {
4604
4668
  [INSTANCE_ID_ATTRIBUTE$1]: identifier.instanceId,
@@ -4608,23 +4672,18 @@ const EditWrapper = observer(function EditWrapper$1(props) {
4608
4672
  "data-sb-selector": getEditWrapperId(props.identifier.instanceId),
4609
4673
  onClick: handleClick,
4610
4674
  onContextMenu,
4611
- ref: handleRef,
4612
- ...testProps,
4613
- ...draggableProps
4675
+ ...testProps
4614
4676
  };
4615
4677
  }, [
4616
4678
  identifier,
4617
- draggableProps,
4618
- draggableClassName,
4619
4679
  handleClick,
4620
- handleRef,
4621
4680
  onContextMenu,
4622
4681
  props.identifier.instanceId,
4623
4682
  isEmpty$1
4624
4683
  ]);
4625
4684
  const node = /* @__PURE__ */ jsx(ParentIdentifierProvider, {
4626
4685
  identifier,
4627
- children: /* @__PURE__ */ jsxs(reactive_component_default, {
4686
+ children: /* @__PURE__ */ jsxs(EditorReactiveComponent, {
4628
4687
  Component: props.component,
4629
4688
  identifier,
4630
4689
  widgetProps: props.widgetProps,
@@ -4646,6 +4705,11 @@ const EditWrapper = observer(function EditWrapper$1(props) {
4646
4705
  widgetProps: props.widgetProps,
4647
4706
  children: node
4648
4707
  }) : node;
4708
+ if (isDraggable) content = /* @__PURE__ */ jsx(DraggablePropsProvider, {
4709
+ identifier: props.identifier,
4710
+ disableDrag,
4711
+ children: content
4712
+ });
4649
4713
  if (isDroppable) content = /* @__PURE__ */ jsx(droppable_widget_default, {
4650
4714
  instanceId: props.identifier.instanceId,
4651
4715
  dropTargetElem,