@superblocksteam/library 2.0.41-next.3 → 2.0.41-next.30

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,98 @@ 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 (e.target instanceof HTMLElement && e.target.dataset.ignoreDnd) return;
2225
+ if (specificWidgetDragDisabled) e.stopPropagation();
2226
+ else listeners?.onPointerDown(e);
2227
+ }, [specificWidgetDragDisabled, listeners]);
2228
+ const onPointerMove = useCallback((e) => {
2229
+ if (specificWidgetDragDisabled) e.stopPropagation();
2230
+ else listeners?.onPointerMove(e);
2231
+ }, [specificWidgetDragDisabled, listeners]);
2232
+ return useMemo(() => {
2233
+ return {
2234
+ ...listeners,
2235
+ ...attributes,
2236
+ className: "sb-draggable-wrapper",
2237
+ "data-is-dragged": isDragging,
2238
+ onPointerDown,
2239
+ onPointerMove,
2240
+ setNodeRef
2241
+ };
2242
+ }, [
2243
+ listeners,
2244
+ attributes,
2245
+ isDragging,
2246
+ onPointerDown,
2247
+ onPointerMove,
2248
+ setNodeRef
2249
+ ]);
2250
+ }
2251
+
2252
+ //#endregion
2253
+ //#region src/lib/internal-details/draggable-context-provider.tsx
2254
+ const DraggablePropsContext = createContext({
2255
+ instanceId: void 0,
2256
+ props: {
2257
+ className: void 0,
2258
+ ref: null
2259
+ }
2260
+ });
2261
+ const DraggablePropsProvider = ({ identifier, disableDrag, children }) => {
2262
+ const draggableWidgetProps = useDraggableWidget({
2263
+ instanceId: identifier.instanceId,
2264
+ disableDrag
2265
+ });
2266
+ const setNodeRef = draggableWidgetProps.setNodeRef;
2267
+ const handleRef = useCallback((el) => {
2268
+ setNodeRef(el);
2269
+ }, [setNodeRef]);
2270
+ const value = useMemo(() => {
2271
+ return {
2272
+ instanceId: identifier.instanceId,
2273
+ props: {
2274
+ ...draggableWidgetProps,
2275
+ ref: handleRef
2276
+ }
2277
+ };
2278
+ }, [
2279
+ draggableWidgetProps,
2280
+ handleRef,
2281
+ identifier.instanceId
2282
+ ]);
2283
+ return /* @__PURE__ */ jsx(DraggablePropsContext.Provider, {
2284
+ value,
2285
+ children
2286
+ });
2287
+ };
2288
+ const EMPTY_PROPS = {};
2289
+ const useMyDraggableProps = (instanceId) => {
2290
+ const contextValue = useContext(DraggablePropsContext);
2291
+ if (contextValue.instanceId !== instanceId) return EMPTY_PROPS;
2292
+ return contextValue.props;
2293
+ };
2294
+
2203
2295
  //#endregion
2204
2296
  //#region src/lib/user-facing/assets/icons/close.svg
2205
2297
  var _path$4;
@@ -3172,6 +3264,33 @@ const WrappedReactiveComponent = (props) => {
3172
3264
  };
3173
3265
  var reactive_component_default = WrappedReactiveComponent;
3174
3266
 
3267
+ //#endregion
3268
+ //#region src/lib/internal-details/editor-reactive-component.tsx
3269
+ const mergeProps = (props1, props2) => {
3270
+ const mergedClassName = props1.className && props2.className ? `${props1.className} ${props2.className}` : props1.className || props2.className;
3271
+ const mergedStyle = {
3272
+ ...props1.style,
3273
+ ...props2.style
3274
+ };
3275
+ return {
3276
+ ...props1,
3277
+ ...props2,
3278
+ style: mergedStyle,
3279
+ className: mergedClassName
3280
+ };
3281
+ };
3282
+ const EditorReactiveComponent = (props) => {
3283
+ const { editorProps,...restProps } = props;
3284
+ const myDraggableProps = useMyDraggableProps(props.identifier.instanceId);
3285
+ const mergedEditorProps = useMemo(() => {
3286
+ return mergeProps(editorProps ?? {}, myDraggableProps);
3287
+ }, [editorProps, myDraggableProps]);
3288
+ return /* @__PURE__ */ jsx(reactive_component_default, {
3289
+ ...restProps,
3290
+ editorProps: mergedEditorProps
3291
+ });
3292
+ };
3293
+
3175
3294
  //#endregion
3176
3295
  //#region src/lib/utils/is-component-type-detached.ts
3177
3296
  function isComponentTypeDetached(componentType) {
@@ -3399,45 +3518,6 @@ const DroppableWidget = observer((props) => {
3399
3518
  });
3400
3519
  var droppable_widget_default = DroppableWidget;
3401
3520
 
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
3521
  //#endregion
3442
3522
  //#region src/edit-mode/hooks/use-right-click-menu.ts
3443
3523
  function useRightClickMenu({ sourceId }) {
@@ -4561,18 +4641,6 @@ const EditWrapper = observer(function EditWrapper$1(props) {
4561
4641
  });
4562
4642
  const isDroppable = isEntityDroppable({ type: props.type });
4563
4643
  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
4644
  const { onContextMenu } = useRightClickMenu({ sourceId: props.identifier.sourceId });
4577
4645
  const showVisibilityBackground = props.widgetProps.isVisible === false && !editStore.ui.getSelectedSourceIds().includes(props.identifier.sourceId);
4578
4646
  const handleClick = useCallback((ev) => {
@@ -4592,13 +4660,10 @@ const EditWrapper = observer(function EditWrapper$1(props) {
4592
4660
  stopPropagation();
4593
4661
  }, [props.identifier.sourceId, props.identifier.instanceId]);
4594
4662
  const [dropTargetElem, setDropTargetElem] = useState(null);
4595
- const handleRef = useCallback((el) => {
4596
- setDraggableNodeRef(el);
4597
- }, [setDraggableNodeRef]);
4598
4663
  const isEmpty$1 = React.Children.count(children) === 0;
4599
4664
  const editorProps = useMemo(() => {
4600
4665
  const testProps = identifier.name.isAnonymous ? {} : { "data-test": `component-${identifier.name.value}` };
4601
- const componentClassName = `${CSS_CLASSES.ANCHOR_NAME} ${draggableClassName}`;
4666
+ const componentClassName = `${CSS_CLASSES.ANCHOR_NAME}`;
4602
4667
  const componentStyle = createAnchorNameStyle({ instanceId: props.identifier.instanceId });
4603
4668
  return {
4604
4669
  [INSTANCE_ID_ATTRIBUTE$1]: identifier.instanceId,
@@ -4608,23 +4673,18 @@ const EditWrapper = observer(function EditWrapper$1(props) {
4608
4673
  "data-sb-selector": getEditWrapperId(props.identifier.instanceId),
4609
4674
  onClick: handleClick,
4610
4675
  onContextMenu,
4611
- ref: handleRef,
4612
- ...testProps,
4613
- ...draggableProps
4676
+ ...testProps
4614
4677
  };
4615
4678
  }, [
4616
4679
  identifier,
4617
- draggableProps,
4618
- draggableClassName,
4619
4680
  handleClick,
4620
- handleRef,
4621
4681
  onContextMenu,
4622
4682
  props.identifier.instanceId,
4623
4683
  isEmpty$1
4624
4684
  ]);
4625
4685
  const node = /* @__PURE__ */ jsx(ParentIdentifierProvider, {
4626
4686
  identifier,
4627
- children: /* @__PURE__ */ jsxs(reactive_component_default, {
4687
+ children: /* @__PURE__ */ jsxs(EditorReactiveComponent, {
4628
4688
  Component: props.component,
4629
4689
  identifier,
4630
4690
  widgetProps: props.widgetProps,
@@ -4646,6 +4706,11 @@ const EditWrapper = observer(function EditWrapper$1(props) {
4646
4706
  widgetProps: props.widgetProps,
4647
4707
  children: node
4648
4708
  }) : node;
4709
+ if (isDraggable) content = /* @__PURE__ */ jsx(DraggablePropsProvider, {
4710
+ identifier: props.identifier,
4711
+ disableDrag,
4712
+ children: content
4713
+ });
4649
4714
  if (isDroppable) content = /* @__PURE__ */ jsx(droppable_widget_default, {
4650
4715
  instanceId: props.identifier.instanceId,
4651
4716
  dropTargetElem,
@@ -5949,7 +6014,10 @@ async function connectSocket(serverUrl, { peerId, userId, applicationId, onClose
5949
6014
  clientImport: [async (payload) => {
5950
6015
  const { importPath } = payload;
5951
6016
  try {
5952
- await import(`${importPath}?v=${Date.now()}`);
6017
+ await import(
6018
+ /* @vite-ignore */
6019
+ `${importPath}?v=${Date.now()}`
6020
+ );
5953
6021
  return;
5954
6022
  } catch (error) {
5955
6023
  const err = error;
@@ -6389,11 +6457,11 @@ const propertiesDefinition$2 = {
6389
6457
  })
6390
6458
  }),
6391
6459
  functions: Section.category(PropsPanelCategory.Functions).children({
6392
- set: Prop.function(function(_s, value) {
6460
+ set: Prop.function(function(value) {
6393
6461
  const widget = this;
6394
6462
  widget.value = value;
6395
6463
  }),
6396
- reset: Prop.function(function(_s) {
6464
+ reset: Prop.function(function() {
6397
6465
  const widget = this;
6398
6466
  widget.value = widget.defaultValue;
6399
6467
  })
@@ -6540,7 +6608,7 @@ const propertiesDefinition = {
6540
6608
  }).readable()
6541
6609
  }),
6542
6610
  functions: Section.category("Derived").children({
6543
- run: Prop.function(async function(_s, traceHeaders) {
6611
+ run: Prop.function(async function(traceHeaders) {
6544
6612
  const api = this;
6545
6613
  try {
6546
6614
  const result = await api._suspensibleApi.run(traceHeaders);
@@ -6551,7 +6619,7 @@ const propertiesDefinition = {
6551
6619
  throw error;
6552
6620
  }
6553
6621
  }),
6554
- cancel: Prop.function(async function(_s) {
6622
+ cancel: Prop.function(async function() {
6555
6623
  await this._suspensibleApi.cancel();
6556
6624
  })
6557
6625
  }),