@superblocksteam/library 2.0.37-next.49 → 2.0.37-next.5
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.d.ts +55 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +651 -516
- package/dist/index.js.map +1 -1
- package/dist/{root-store-D7IuNpKE.js → root-store-OkumbU1B.js} +12 -4
- package/dist/root-store-OkumbU1B.js.map +1 -0
- package/dist/root-store-Z42RSY5l.js +4 -0
- package/package.json +5 -3
- package/dist/root-store-C8Wjgal-.js +0 -4
- package/dist/root-store-D7IuNpKE.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { early_console_buffer_default } from "./early-console-buffer-DWTLgla0.js";
|
|
2
|
-
import { CLASS_NAMES, DEFAULT_ANONYMOUS_SOURCE_ID, DevTools, EventFlow, GLOBAL_SCOPE_ID, LazyFunction, NavigationEvent, Prop, PropsPanelCategory, RecordProp, Section, VALIDATORS, addNewPromise, colors, createInternalPropsList, createManagedPropsList, createPropertiesPanelDefinition, editorBridge, generateId, getEditStore, getName, iframeMessageHandler, isEditMode, isEmbeddedBySuperblocksFirstParty, isLocalLink, isName, isNameEqual, navigation, rejectById, resolveById, root_store_default, run_event_handlers_default, sendNotification, startEditorSync, system_error_default } from "./root-store-
|
|
2
|
+
import { CLASS_NAMES, DEFAULT_ANONYMOUS_SOURCE_ID, DevTools, EventFlow, GLOBAL_SCOPE_ID, LazyFunction, NavigationEvent, Prop, PropsPanelCategory, RecordProp, Section, VALIDATORS, addNewPromise, colors, createInternalPropsList, createManagedPropsList, createPropertiesPanelDefinition, editorBridge, generateId, getEditStore, getName, iframeMessageHandler, isEditMode, isEmbeddedBySuperblocksFirstParty, isLocalLink, isName, isNameEqual, navigation, rejectById, resolveById, root_store_default, run_event_handlers_default, sendNotification, startEditorSync, system_error_default } from "./root-store-OkumbU1B.js";
|
|
3
3
|
import "./utils-CCBWAYIM.js";
|
|
4
4
|
import { AiContextMode, AiGenerationState, BindingMetaSymbol, SbEntityType, StateVarPersistence, StateVarPersistence as StateVarPersistence$1, ThemeMode, TriggerStepType, ViteMessageKind, isValidStepDef, sbEntitySymbol } from "@superblocksteam/library-shared/types";
|
|
5
5
|
import _, { get, isEmpty, isEqual, isNumber, isObject, merge, set, throttle } from "lodash";
|
|
@@ -1241,6 +1241,20 @@ const createMemoizedClassGenerator = (generator) => {
|
|
|
1241
1241
|
function getDefaultTypographies(themeVersion) {
|
|
1242
1242
|
return DEFAULT_TYPOGRAPHIES_BY_VERSION[themeVersion || 2];
|
|
1243
1243
|
}
|
|
1244
|
+
function dimToCSS(dim, dimension, primary = true) {
|
|
1245
|
+
switch (dim.mode) {
|
|
1246
|
+
case "fit": return { [dimension]: "fit-content" };
|
|
1247
|
+
case "fill":
|
|
1248
|
+
if (!primary) return {
|
|
1249
|
+
alignSelf: "stretch",
|
|
1250
|
+
[dimension]: "unset"
|
|
1251
|
+
};
|
|
1252
|
+
return { flex: dim.value ?? 1 };
|
|
1253
|
+
case "px": return { [dimension]: `${dim.value}px` };
|
|
1254
|
+
case "%": return { [dimension]: `${dim.value}%` };
|
|
1255
|
+
default: return {};
|
|
1256
|
+
}
|
|
1257
|
+
}
|
|
1244
1258
|
const Classes = {
|
|
1245
1259
|
minHeightZero: styleWithPrefix("sb-min-height-zero")`
|
|
1246
1260
|
@layer components {
|
|
@@ -1426,6 +1440,9 @@ const getWidthHeightInfo = (dim, dimension, instanceId) => {
|
|
|
1426
1440
|
default: return { classnames: [] };
|
|
1427
1441
|
}
|
|
1428
1442
|
};
|
|
1443
|
+
const getMinMaxCss = (dim, dimension) => {
|
|
1444
|
+
return dim ? dim.mode === "fill" ? { [dimension]: "100%" } : dimToCSS(dim, dimension) : {};
|
|
1445
|
+
};
|
|
1429
1446
|
|
|
1430
1447
|
//#endregion
|
|
1431
1448
|
//#region src/lib/user-facing/properties-panel/mixins/appearance-properties.ts
|
|
@@ -1501,11 +1518,74 @@ const borderRadius = (propertiesPanelConfig = {}) => {
|
|
|
1501
1518
|
|
|
1502
1519
|
//#endregion
|
|
1503
1520
|
//#region src/lib/user-facing/properties-panel/mixins/layout-section.ts
|
|
1521
|
+
const getSizeProp = ({ label, controlType, defaultValue, defaultOnAdd, isVisible }) => {
|
|
1522
|
+
let sizeProp = Prop.dimension().readAndWrite().propertiesPanel({
|
|
1523
|
+
label,
|
|
1524
|
+
controlType
|
|
1525
|
+
});
|
|
1526
|
+
if (defaultValue !== void 0 || defaultOnAdd !== void 0) {
|
|
1527
|
+
sizeProp = sizeProp.propertiesPanel({
|
|
1528
|
+
label,
|
|
1529
|
+
controlType,
|
|
1530
|
+
isRemovable: true,
|
|
1531
|
+
visibility: "SHOW_NAME",
|
|
1532
|
+
defaultOnAdd,
|
|
1533
|
+
isVisible
|
|
1534
|
+
});
|
|
1535
|
+
if (defaultValue) sizeProp = sizeProp.default(defaultValue);
|
|
1536
|
+
}
|
|
1537
|
+
return sizeProp.docs({ description: `Controls the ${label.toLowerCase()} dimension of the component` });
|
|
1538
|
+
};
|
|
1504
1539
|
/**
|
|
1505
1540
|
* Sets width default to `fill` if no default width config provided.
|
|
1506
1541
|
* Sets height default to `fit` if no default height config provided.
|
|
1507
1542
|
*/
|
|
1508
|
-
const size = ({ defaults,
|
|
1543
|
+
const size = ({ defaults, defaultsOnAdd = {
|
|
1544
|
+
minWidth: Dim$1.px(0),
|
|
1545
|
+
minHeight: Dim$1.px(0),
|
|
1546
|
+
maxWidth: Dim$1.px(200),
|
|
1547
|
+
maxHeight: Dim$1.px(120)
|
|
1548
|
+
}, hasMinWidth = true, hasMaxWidth = true, hasMinHeight = true, hasMaxHeight = true, showMinWidth, showMinHeight, showMaxWidth, showMaxHeight, showWidth, showHeight } = {}) => {
|
|
1549
|
+
const minWidthProperty = getSizeProp({
|
|
1550
|
+
label: "Min width",
|
|
1551
|
+
controlType: "WIDTH_DROPDOWN",
|
|
1552
|
+
defaultValue: defaults?.minWidth,
|
|
1553
|
+
defaultOnAdd: defaultsOnAdd?.minWidth,
|
|
1554
|
+
isVisible: function(s) {
|
|
1555
|
+
const hideWidth = this?.width?.mode === "px";
|
|
1556
|
+
return Boolean((showMinWidth ? showMinWidth?.call(this, s) : true) && !hideWidth);
|
|
1557
|
+
}
|
|
1558
|
+
});
|
|
1559
|
+
const maxWidthProperty = getSizeProp({
|
|
1560
|
+
label: "Max width",
|
|
1561
|
+
controlType: "WIDTH_DROPDOWN",
|
|
1562
|
+
defaultValue: defaults?.maxWidth,
|
|
1563
|
+
defaultOnAdd: defaultsOnAdd?.maxWidth,
|
|
1564
|
+
isVisible: function(s) {
|
|
1565
|
+
const hideWidth = this?.width?.mode === "px";
|
|
1566
|
+
return Boolean((showMaxWidth ? showMaxWidth?.call(this, s) : true) && !hideWidth);
|
|
1567
|
+
}
|
|
1568
|
+
});
|
|
1569
|
+
const minHeightProperty = getSizeProp({
|
|
1570
|
+
label: "Min height",
|
|
1571
|
+
controlType: "HEIGHT_DROPDOWN",
|
|
1572
|
+
defaultValue: defaults?.minHeight,
|
|
1573
|
+
defaultOnAdd: defaultsOnAdd?.minHeight,
|
|
1574
|
+
isVisible: function(s) {
|
|
1575
|
+
const hideHeight = this?.height?.mode === "px";
|
|
1576
|
+
return Boolean((showMinHeight ? showMinHeight?.call(this, s) : true) && !hideHeight);
|
|
1577
|
+
}
|
|
1578
|
+
});
|
|
1579
|
+
const maxHeightProperty = getSizeProp({
|
|
1580
|
+
label: "Max height",
|
|
1581
|
+
controlType: "HEIGHT_DROPDOWN",
|
|
1582
|
+
defaultValue: defaults?.maxHeight,
|
|
1583
|
+
defaultOnAdd: defaultsOnAdd?.maxHeight,
|
|
1584
|
+
isVisible: function(s) {
|
|
1585
|
+
const hideHeight = this?.height?.mode === "px";
|
|
1586
|
+
return Boolean((showMaxHeight ? showMaxHeight?.call(this, s) : true) && !hideHeight);
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1509
1589
|
let heightProperty = Prop.dimension().readAndWrite().propertiesPanel({
|
|
1510
1590
|
label: "Height",
|
|
1511
1591
|
controlType: "HEIGHT_DROPDOWN",
|
|
@@ -1524,7 +1604,11 @@ const size = ({ defaults, showWidth, showHeight } = {}) => {
|
|
|
1524
1604
|
widthProperty = widthProperty.docs({ description: "Sets the width of the component" });
|
|
1525
1605
|
return {
|
|
1526
1606
|
width: widthProperty,
|
|
1527
|
-
height: heightProperty
|
|
1607
|
+
height: heightProperty,
|
|
1608
|
+
...hasMinWidth ? { minWidth: minWidthProperty } : {},
|
|
1609
|
+
...hasMaxWidth ? { maxWidth: maxWidthProperty } : {},
|
|
1610
|
+
...hasMinHeight ? { minHeight: minHeightProperty } : {},
|
|
1611
|
+
...hasMaxHeight ? { maxHeight: maxHeightProperty } : {}
|
|
1528
1612
|
};
|
|
1529
1613
|
};
|
|
1530
1614
|
/** @deprecated Using it will override the defaults values defined in size() for width */
|
|
@@ -1740,69 +1824,69 @@ const loading = () => Prop.boolean().default(void 0).readAndWrite().propertiesPa
|
|
|
1740
1824
|
//#endregion
|
|
1741
1825
|
//#region src/lib/user-facing/components/stack/stack-classes.ts
|
|
1742
1826
|
const STACK_CLASSES = {
|
|
1743
|
-
base:
|
|
1827
|
+
base: styleAsClass`
|
|
1744
1828
|
@layer components {
|
|
1745
1829
|
display: flex;
|
|
1746
1830
|
position: relative;
|
|
1747
1831
|
box-sizing: border-box;
|
|
1748
1832
|
}
|
|
1749
1833
|
`,
|
|
1750
|
-
directionColumn:
|
|
1834
|
+
directionColumn: styleAsClass`
|
|
1751
1835
|
@layer components {
|
|
1752
1836
|
flex-direction: column;
|
|
1753
1837
|
}
|
|
1754
1838
|
`,
|
|
1755
|
-
directionRow:
|
|
1839
|
+
directionRow: styleAsClass`
|
|
1756
1840
|
@layer components {
|
|
1757
1841
|
flex-direction: row;
|
|
1758
1842
|
}
|
|
1759
1843
|
`,
|
|
1760
|
-
justifyStart:
|
|
1844
|
+
justifyStart: styleAsClass`
|
|
1761
1845
|
@layer components {
|
|
1762
1846
|
justify-content: flex-start;
|
|
1763
1847
|
}
|
|
1764
1848
|
`,
|
|
1765
|
-
justifyCenter:
|
|
1849
|
+
justifyCenter: styleAsClass`
|
|
1766
1850
|
@layer components {
|
|
1767
1851
|
justify-content: center;
|
|
1768
1852
|
}
|
|
1769
1853
|
`,
|
|
1770
|
-
justifyEnd:
|
|
1854
|
+
justifyEnd: styleAsClass`
|
|
1771
1855
|
@layer components {
|
|
1772
1856
|
justify-content: flex-end;
|
|
1773
1857
|
}
|
|
1774
1858
|
`,
|
|
1775
|
-
justifySpaceBetween:
|
|
1859
|
+
justifySpaceBetween: styleAsClass`
|
|
1776
1860
|
@layer components {
|
|
1777
1861
|
justify-content: space-between;
|
|
1778
1862
|
}
|
|
1779
1863
|
`,
|
|
1780
|
-
justifySpaceAround:
|
|
1864
|
+
justifySpaceAround: styleAsClass`
|
|
1781
1865
|
@layer components {
|
|
1782
1866
|
justify-content: space-around;
|
|
1783
1867
|
}
|
|
1784
1868
|
`,
|
|
1785
|
-
alignStart:
|
|
1869
|
+
alignStart: styleAsClass`
|
|
1786
1870
|
@layer components {
|
|
1787
1871
|
align-items: flex-start;
|
|
1788
1872
|
}
|
|
1789
1873
|
`,
|
|
1790
|
-
alignCenter:
|
|
1874
|
+
alignCenter: styleAsClass`
|
|
1791
1875
|
@layer components {
|
|
1792
1876
|
align-items: center;
|
|
1793
1877
|
}
|
|
1794
1878
|
`,
|
|
1795
|
-
alignEnd:
|
|
1879
|
+
alignEnd: styleAsClass`
|
|
1796
1880
|
@layer components {
|
|
1797
1881
|
align-items: flex-end;
|
|
1798
1882
|
}
|
|
1799
1883
|
`,
|
|
1800
|
-
alignStretch:
|
|
1884
|
+
alignStretch: styleAsClass`
|
|
1801
1885
|
@layer components {
|
|
1802
1886
|
align-items: stretch;
|
|
1803
1887
|
}
|
|
1804
1888
|
`,
|
|
1805
|
-
overflowAuto:
|
|
1889
|
+
overflowAuto: styleAsClass`
|
|
1806
1890
|
@layer components {
|
|
1807
1891
|
overflow: auto;
|
|
1808
1892
|
}
|
|
@@ -2061,12 +2145,11 @@ const InternalStack = observer(({ direction = "column", spacing: spacing$1, chil
|
|
|
2061
2145
|
return /* @__PURE__ */ jsx("div", {
|
|
2062
2146
|
className: combinedClassName,
|
|
2063
2147
|
...rest,
|
|
2064
|
-
ref: props.dropTargetRef,
|
|
2065
2148
|
children
|
|
2066
2149
|
});
|
|
2067
2150
|
});
|
|
2068
2151
|
const InternalVStack = (props) => {
|
|
2069
|
-
const { verticalAlign,...rest } = props;
|
|
2152
|
+
const { verticalAlign, horizontalAlign,...rest } = props;
|
|
2070
2153
|
return /* @__PURE__ */ jsx(InternalStack, {
|
|
2071
2154
|
direction: "column",
|
|
2072
2155
|
...rest,
|
|
@@ -2153,7 +2236,7 @@ const InternalContainer = (props) => {
|
|
|
2153
2236
|
height: "100%",
|
|
2154
2237
|
width: "100%"
|
|
2155
2238
|
}), [alignmentStyles]);
|
|
2156
|
-
const shouldApplyEmptyContainerMinHeight = isEditing && props.height?.mode !== "px" && isEmpty(props.children);
|
|
2239
|
+
const shouldApplyEmptyContainerMinHeight = isEditing && props.height?.mode !== "px" && props.minHeight?.mode !== "px" && props.maxHeight?.mode !== "px" && isEmpty(props.children);
|
|
2157
2240
|
const containerStyle = useMemo(() => ({
|
|
2158
2241
|
display: "grid",
|
|
2159
2242
|
gridTemplate: "minmax(0px, 1fr) / minmax(0px, 1fr)",
|
|
@@ -3036,12 +3119,26 @@ const useStyleWithSize = (props, instanceId) => {
|
|
|
3036
3119
|
use_stable_effect_default(() => {
|
|
3037
3120
|
const widthInfo = props.width ? getWidthHeightInfo(props.width, "width", instanceId) : { classnames: [] };
|
|
3038
3121
|
const heightInfo = props.height ? getWidthHeightInfo(props.height, "height", instanceId) : { classnames: [] };
|
|
3039
|
-
|
|
3122
|
+
const minWidthCss = getMinMaxCss(props.minWidth, "minWidth");
|
|
3123
|
+
const maxWidthCss = getMinMaxCss(props.maxWidth, "maxWidth");
|
|
3124
|
+
const minHeightCss = getMinMaxCss(props.minHeight, "minHeight");
|
|
3125
|
+
const maxHeightCss = getMinMaxCss(props.maxHeight, "maxHeight");
|
|
3126
|
+
setStyle({
|
|
3127
|
+
...minWidthCss,
|
|
3128
|
+
...maxWidthCss,
|
|
3129
|
+
...minHeightCss,
|
|
3130
|
+
...maxHeightCss,
|
|
3131
|
+
...props.style
|
|
3132
|
+
});
|
|
3040
3133
|
setClassNames([...widthInfo.classnames, ...heightInfo.classnames]);
|
|
3041
3134
|
}, {
|
|
3042
3135
|
instanceId,
|
|
3043
3136
|
width: props.width,
|
|
3044
3137
|
height: props.height,
|
|
3138
|
+
minHeight: props.minHeight,
|
|
3139
|
+
minWidth: props.minWidth,
|
|
3140
|
+
maxHeight: props.maxHeight,
|
|
3141
|
+
maxWidth: props.maxWidth,
|
|
3045
3142
|
style: props.style
|
|
3046
3143
|
}, {
|
|
3047
3144
|
cold: true,
|
|
@@ -3099,12 +3196,8 @@ const ReactiveComponent = observer(function Component$1({ Component: Component$2
|
|
|
3099
3196
|
const editorClickHandler = editorProps?.onClick;
|
|
3100
3197
|
const handleClick = useCallback(async (e, ...rest) => {
|
|
3101
3198
|
if (typeof realClickHandler === "function") realClickHandler(e, ...rest);
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
if (typeof extraClickHandler === "function") extraClickHandler(e);
|
|
3105
|
-
} catch (error) {
|
|
3106
|
-
console.error("Editor click handler error", error);
|
|
3107
|
-
}
|
|
3199
|
+
const extraClickHandler = editorClickHandler;
|
|
3200
|
+
if (typeof extraClickHandler === "function") extraClickHandler(e);
|
|
3108
3201
|
}, [editorClickHandler, realClickHandler]);
|
|
3109
3202
|
const hide = shouldHideComponent(reactiveProps?.isVisible);
|
|
3110
3203
|
const fallbackPassthroughProps = useMemo(() => {
|
|
@@ -3243,13 +3336,10 @@ const getWidgetNode = (instanceId) => {
|
|
|
3243
3336
|
const type = root_store_default.nameManager.getExistingIdentifier(instanceId)?.type;
|
|
3244
3337
|
return document?.querySelector(`[data-sb-selector="${getEditWrapperIdWithType(instanceId, type)}"]`);
|
|
3245
3338
|
};
|
|
3246
|
-
const
|
|
3247
|
-
if (!possibleParent || !possibleChild) return false;
|
|
3339
|
+
const getIsComponentInInteractionLayer = (instanceId) => {
|
|
3248
3340
|
const editStore = getEditStore();
|
|
3249
|
-
const
|
|
3250
|
-
|
|
3251
|
-
if (editStore.interactionLayerManager.interactionLayerInstanceIds.has(possibleParent)) return possibleChild === possibleParent || childMeta?.interactionLayerInstanceId === possibleParent;
|
|
3252
|
-
return parentMeta?.interactionLayerInstanceId === childMeta?.interactionLayerInstanceId;
|
|
3341
|
+
const activeRootInstanceId = editStore.interactionLayerManager.activeRootInstanceId;
|
|
3342
|
+
return !activeRootInstanceId || instanceId && (instanceId === activeRootInstanceId || editStore.runtimeEntitiesManager.isChildOf(instanceId, activeRootInstanceId));
|
|
3253
3343
|
};
|
|
3254
3344
|
|
|
3255
3345
|
//#endregion
|
|
@@ -3271,29 +3361,7 @@ function rule(description, restriction) {
|
|
|
3271
3361
|
restriction
|
|
3272
3362
|
};
|
|
3273
3363
|
}
|
|
3274
|
-
const
|
|
3275
|
-
rule("Drop target and dragged instance must be in the same interaction layer", ({ dropTargetInstanceId, draggedInstanceId, isDraggingNewComponent }) => {
|
|
3276
|
-
if (isDraggingNewComponent || !draggedInstanceId) return false;
|
|
3277
|
-
return !doesInteractionLayerContainInstance(dropTargetInstanceId, draggedInstanceId);
|
|
3278
|
-
}),
|
|
3279
|
-
rule("Dragged instance must not be a child of the drop target", ({ dropTargetInstanceId, draggedInstanceId }) => {
|
|
3280
|
-
if (!dropTargetInstanceId || !draggedInstanceId) return false;
|
|
3281
|
-
return getEditStore().runtimeEntitiesManager.isChildOf(dropTargetInstanceId, draggedInstanceId);
|
|
3282
|
-
}),
|
|
3283
|
-
rule("If the dragged instance has local bindings, it must share its root instance with the drop target", ({ dropTargetInstanceId, draggedInstanceId }) => {
|
|
3284
|
-
if (!dropTargetInstanceId || !draggedInstanceId) return false;
|
|
3285
|
-
const editStore = getEditStore();
|
|
3286
|
-
if (!(draggedInstanceId && editStore.runtimeEntitiesManager.doesEntityHaveLocalBindings(draggedInstanceId))) return false;
|
|
3287
|
-
const dropTargetMeta = editStore.runtimeEntitiesManager.getEditorWidgetMeta(dropTargetInstanceId);
|
|
3288
|
-
const draggedMeta = editStore.runtimeEntitiesManager.getEditorWidgetMeta(draggedInstanceId);
|
|
3289
|
-
if (dropTargetMeta?.isRoot) return dropTargetMeta.instanceId !== draggedMeta?.rootInstanceId;
|
|
3290
|
-
else return dropTargetMeta?.rootInstanceId !== draggedMeta?.rootInstanceId;
|
|
3291
|
-
})
|
|
3292
|
-
];
|
|
3293
|
-
const areDragAndDropInstancesValid = (params) => {
|
|
3294
|
-
return instanceRestrictions.find((restriction) => restriction.restriction(params)) == null;
|
|
3295
|
-
};
|
|
3296
|
-
const typeRestrictions = [
|
|
3364
|
+
const restrictions = [
|
|
3297
3365
|
rule("Draggable type must be draggable", ({ draggedType, isDraggingNewComponent }) => !isDraggingNewComponent && !isTypeDraggable(draggedType)),
|
|
3298
3366
|
rule("Drop target type must be droppable", ({ dropTargetType }) => !isTypeDroppable(dropTargetType)),
|
|
3299
3367
|
rule("Only containers can be dropped on non empty pages", ({ draggedType, dropTargetType, dropTargetEmpty }) => {
|
|
@@ -3301,7 +3369,7 @@ const typeRestrictions = [
|
|
|
3301
3369
|
})
|
|
3302
3370
|
];
|
|
3303
3371
|
const isDragAndDropTypeValid = ({ draggedType, dropTargetType, dropTargetEmpty, isDraggingNewComponent }) => {
|
|
3304
|
-
return
|
|
3372
|
+
return restrictions.find((restriction) => restriction.restriction({
|
|
3305
3373
|
draggedType,
|
|
3306
3374
|
dropTargetType,
|
|
3307
3375
|
dropTargetEmpty,
|
|
@@ -3324,6 +3392,23 @@ const isContentDraggable = (type) => {
|
|
|
3324
3392
|
if (!isTypeDraggable(type)) return false;
|
|
3325
3393
|
return root_store_default.componentRegistry.getEditorConfig(type)?.isContentDraggable !== false;
|
|
3326
3394
|
};
|
|
3395
|
+
/**
|
|
3396
|
+
* TODO - should use the EditorConfig to determine if the created/dropped component should be wrapped.
|
|
3397
|
+
* @param type - the type of the component being created
|
|
3398
|
+
* @param parentType - the type of the parent component
|
|
3399
|
+
* @returns
|
|
3400
|
+
* - [false] if the component should not be wrapped
|
|
3401
|
+
* - [true, wrapInType] if the component should be wrapped in the given type
|
|
3402
|
+
*/
|
|
3403
|
+
function shouldWrapComponent(type, parentType) {
|
|
3404
|
+
if (isComponentTypeDetached(type)) return [false];
|
|
3405
|
+
if (!parentType) return [false];
|
|
3406
|
+
if (parentType.includes("Modal") || parentType.includes("Slideout") || parentType.includes("Sheet") || parentType.includes("Dialog") || parentType === NATIVE_COMPONENT_TYPES.Page) {
|
|
3407
|
+
if (root_store_default.componentRegistry.containerTypes.has(type)) return [false];
|
|
3408
|
+
return [true, root_store_default.componentRegistry.defaultTagNames.container];
|
|
3409
|
+
}
|
|
3410
|
+
return [false];
|
|
3411
|
+
}
|
|
3327
3412
|
const filterSafeStackDimensionProperties = (existingProps) => {
|
|
3328
3413
|
const { width, height, size: size$1 } = existingProps;
|
|
3329
3414
|
const safeDimensions = {};
|
|
@@ -3377,13 +3462,13 @@ const DroppableWidget = observer((props) => {
|
|
|
3377
3462
|
const widgetNode = useWidgetNodeRef(props.instanceId);
|
|
3378
3463
|
useEffect(() => {
|
|
3379
3464
|
let targetNode = null;
|
|
3380
|
-
if (props.
|
|
3465
|
+
if (props.dropTargetRef?.current) targetNode = props.dropTargetRef.current;
|
|
3381
3466
|
else if (widgetNode) targetNode = widgetNode;
|
|
3382
3467
|
if (targetNode) setDroppableNodeRef(targetNode);
|
|
3383
3468
|
}, [
|
|
3384
3469
|
widgetNode,
|
|
3385
3470
|
setDroppableNodeRef,
|
|
3386
|
-
props.
|
|
3471
|
+
props.dropTargetRef
|
|
3387
3472
|
]);
|
|
3388
3473
|
return /* @__PURE__ */ jsx(React.Fragment, { children: props.children });
|
|
3389
3474
|
});
|
|
@@ -3451,28 +3536,6 @@ function ParentIdentifierProvider({ identifier, children }) {
|
|
|
3451
3536
|
});
|
|
3452
3537
|
}
|
|
3453
3538
|
|
|
3454
|
-
//#endregion
|
|
3455
|
-
//#region src/edit-mode/interaction-layer/interaction-context.tsx
|
|
3456
|
-
const defaultContext = { rootInstanceId: void 0 };
|
|
3457
|
-
const InteractionLayerContext = createContext(void 0);
|
|
3458
|
-
const useInteractionLayerContext = () => {
|
|
3459
|
-
return useContext(InteractionLayerContext) ?? defaultContext;
|
|
3460
|
-
};
|
|
3461
|
-
const InteractionLayerProvider = (props) => {
|
|
3462
|
-
const context$1 = useMemo(() => ({ rootInstanceId: props.instanceId }), [props.instanceId]);
|
|
3463
|
-
useEffect(() => {
|
|
3464
|
-
const editStore = getEditStore();
|
|
3465
|
-
editStore.interactionLayerManager.addInteractionLayerInstanceId(props.instanceId);
|
|
3466
|
-
return () => {
|
|
3467
|
-
editStore.interactionLayerManager.removeInteractionLayerInstanceId(props.instanceId);
|
|
3468
|
-
};
|
|
3469
|
-
}, [props.instanceId]);
|
|
3470
|
-
return /* @__PURE__ */ jsx(InteractionLayerContext.Provider, {
|
|
3471
|
-
value: context$1,
|
|
3472
|
-
children: props.children
|
|
3473
|
-
});
|
|
3474
|
-
};
|
|
3475
|
-
|
|
3476
3539
|
//#endregion
|
|
3477
3540
|
//#region src/lib/internal-details/lib/throttle.ts
|
|
3478
3541
|
function throttle$1(func, delay) {
|
|
@@ -3498,13 +3561,420 @@ function throttle$1(func, delay) {
|
|
|
3498
3561
|
}
|
|
3499
3562
|
|
|
3500
3563
|
//#endregion
|
|
3501
|
-
//#region src/lib/user-facing/constants.ts
|
|
3502
|
-
const CANVAS_ROOT_ID = "canvas-root";
|
|
3564
|
+
//#region src/lib/user-facing/constants.ts
|
|
3565
|
+
const CANVAS_ROOT_ID = "canvas-root";
|
|
3566
|
+
/**
|
|
3567
|
+
* The ID of the element used to target detached components (e.g: modals, slideouts) when they are opened in the app.
|
|
3568
|
+
*/
|
|
3569
|
+
const PORTAL_ROOT_ID = "portal-root";
|
|
3570
|
+
const POPOVER_ROOT_ID = "sb-popover-root";
|
|
3571
|
+
|
|
3572
|
+
//#endregion
|
|
3573
|
+
//#region src/edit-mode/dnd/is-nestable.ts
|
|
3574
|
+
function isNestable(componentType, _parentType) {
|
|
3575
|
+
if (componentType === PAGE_COMPONENT_TYPE) return false;
|
|
3576
|
+
return true;
|
|
3577
|
+
}
|
|
3578
|
+
|
|
3579
|
+
//#endregion
|
|
3580
|
+
//#region src/edit-mode/create-component.ts
|
|
3581
|
+
function getParentInfo(parent) {
|
|
3582
|
+
return { type: getEditStore().runtimeEntitiesManager.getAnyEditorWidgetMeta(parent.id)?.type };
|
|
3583
|
+
}
|
|
3584
|
+
const generateUniqueName = (componentType) => {
|
|
3585
|
+
const baseName = componentType;
|
|
3586
|
+
let counter = 1;
|
|
3587
|
+
let name = `${baseName}${counter}`;
|
|
3588
|
+
while (root_store_default.nameManager.hasEntityWithName(name)) {
|
|
3589
|
+
counter++;
|
|
3590
|
+
name = `${baseName}${counter}`;
|
|
3591
|
+
}
|
|
3592
|
+
return name;
|
|
3593
|
+
};
|
|
3594
|
+
function getBinding({ componentType, editorTemplateCreateRequest }) {
|
|
3595
|
+
if (editorTemplateCreateRequest?.generateBinding === true) return Property$1.Static(generateUniqueName(componentType));
|
|
3596
|
+
else if (typeof editorTemplateCreateRequest?.generateBinding === "string") return Property$1.Static(editorTemplateCreateRequest.generateBinding);
|
|
3597
|
+
else return;
|
|
3598
|
+
}
|
|
3599
|
+
function getComponentBaseProperties(componentType, _parentInfo, editorTemplateCreateRequest) {
|
|
3600
|
+
let properties = {};
|
|
3601
|
+
const editorTemplates = root_store_default.componentRegistry.getEditorTemplates(componentType);
|
|
3602
|
+
if (editorTemplates && editorTemplates.length > 1) throw new Error(`Multiple editor templates are not supported yet. Found ${editorTemplates.length} for component type: ${componentType}.`);
|
|
3603
|
+
if (editorTemplateCreateRequest?.properties) properties = {
|
|
3604
|
+
...properties,
|
|
3605
|
+
...editorTemplateCreateRequest.properties
|
|
3606
|
+
};
|
|
3607
|
+
const binding = getBinding({
|
|
3608
|
+
componentType,
|
|
3609
|
+
editorTemplateCreateRequest
|
|
3610
|
+
});
|
|
3611
|
+
if (binding) properties.name = binding;
|
|
3612
|
+
const { width, height, size: size$1 } = properties;
|
|
3613
|
+
const safeDimensions = filterSafeStackDimensionProperties({
|
|
3614
|
+
width: width?.value,
|
|
3615
|
+
height: height?.value,
|
|
3616
|
+
size: size$1?.value
|
|
3617
|
+
});
|
|
3618
|
+
return {
|
|
3619
|
+
properties: {
|
|
3620
|
+
...properties,
|
|
3621
|
+
...safeDimensions
|
|
3622
|
+
},
|
|
3623
|
+
children: editorTemplateCreateRequest?.children ?? []
|
|
3624
|
+
};
|
|
3625
|
+
}
|
|
3626
|
+
function getCreateAtParentElement(relativeParent, createAt) {
|
|
3627
|
+
if (createAt === "root") {
|
|
3628
|
+
const parentInstanceId = getEditStore().runtimeEntitiesManager.widgets.getAnyInstanceIdForSourceId(relativeParent.id);
|
|
3629
|
+
const pageComponent = getEditStore().runtimeEntitiesManager.getClosestAncestorByType(parentInstanceId, "Page");
|
|
3630
|
+
if (!pageComponent) throw new Error(`Page component not found for parent: ${relativeParent.id}`);
|
|
3631
|
+
return { source: { id: pageComponent.sourceId } };
|
|
3632
|
+
} else return { source: relativeParent };
|
|
3633
|
+
}
|
|
3634
|
+
async function createComponent({ componentType, parent, scopeName, baseProperties = {}, skipSecondaryComponentsCreation, otherComponentsUpdates }) {
|
|
3635
|
+
const parentInfo = getParentInfo(parent);
|
|
3636
|
+
if (!isNestable(componentType, parentInfo.type)) {
|
|
3637
|
+
console.error(`${componentType} cannot be nested under ${parentInfo.type}`);
|
|
3638
|
+
return;
|
|
3639
|
+
}
|
|
3640
|
+
const editorTemplates = root_store_default.componentRegistry.getEditorTemplates(componentType);
|
|
3641
|
+
if (editorTemplates && editorTemplates.length > 1) throw new Error(`Multiple editor templates are not supported yet. Found ${editorTemplates.length} for component type: ${componentType}.`);
|
|
3642
|
+
const context$1 = {
|
|
3643
|
+
generateUniqueName,
|
|
3644
|
+
parentInfo,
|
|
3645
|
+
defaultTagNames: root_store_default.componentRegistry.defaultTagNames,
|
|
3646
|
+
selfTagName: componentType
|
|
3647
|
+
};
|
|
3648
|
+
const editorTemplateCreateRequest = editorTemplates?.[0]?.create?.(context$1);
|
|
3649
|
+
const primaryEditorTemplateCreateRequest = Array.isArray(editorTemplateCreateRequest) ? editorTemplateCreateRequest[0] : editorTemplateCreateRequest;
|
|
3650
|
+
if (editorTemplateCreateRequest && primaryEditorTemplateCreateRequest?.type !== componentType) throw new Error(`When defining a ${Array.isArray(editorTemplateCreateRequest) ? "multiple" : "single"} component to be created on an EditorTemplate, the type must match with the component being created. got: ${primaryEditorTemplateCreateRequest?.type} when it should have been ${componentType}`);
|
|
3651
|
+
const editorTemplateCreateRequests = Array.isArray(editorTemplateCreateRequest) ? editorTemplateCreateRequest : [editorTemplateCreateRequest];
|
|
3652
|
+
const editStore = getEditStore();
|
|
3653
|
+
function editorTemplateCreateRequestToInternalCreateRequest({ editorTemplateCreateRequest: editorTemplateCreateRequest$1, baseProperties: baseProperties$1 }) {
|
|
3654
|
+
const type = editorTemplateCreateRequest$1?.type ?? componentType;
|
|
3655
|
+
const [shouldWrap, wrapInType] = shouldWrapComponent(type, parentInfo.type);
|
|
3656
|
+
const { properties: propertiesFromType, children } = getComponentBaseProperties(type, parentInfo, editorTemplateCreateRequest$1);
|
|
3657
|
+
const properties = {
|
|
3658
|
+
...propertiesFromType,
|
|
3659
|
+
...baseProperties$1
|
|
3660
|
+
};
|
|
3661
|
+
let primaryComponent = {
|
|
3662
|
+
parentElement: getCreateAtParentElement(parent, editorTemplateCreateRequest$1?.createAt),
|
|
3663
|
+
tagName: type,
|
|
3664
|
+
properties,
|
|
3665
|
+
children,
|
|
3666
|
+
scopeName,
|
|
3667
|
+
id: editStore.operationManager.generateSourceId()
|
|
3668
|
+
};
|
|
3669
|
+
if (shouldWrap) primaryComponent = wrapComponentIfNecessary(primaryComponent, wrapInType);
|
|
3670
|
+
return primaryComponent;
|
|
3671
|
+
}
|
|
3672
|
+
const createRequests = editorTemplateCreateRequests.map((editorTemplateCreateRequest$1, index) => editorTemplateCreateRequestToInternalCreateRequest({
|
|
3673
|
+
editorTemplateCreateRequest: editorTemplateCreateRequest$1,
|
|
3674
|
+
baseProperties: index === 0 ? baseProperties : {}
|
|
3675
|
+
}));
|
|
3676
|
+
const hasOtherComponentsUpdates = otherComponentsUpdates && Object.keys(otherComponentsUpdates).length > 0;
|
|
3677
|
+
const hasMultipleCreateComponents = editorTemplateCreateRequests.length > 1 && !skipSecondaryComponentsCreation;
|
|
3678
|
+
if (hasOtherComponentsUpdates || hasMultipleCreateComponents) {
|
|
3679
|
+
const performOtherComponentsUpdates = (otherComponentsUpdates$1) => {
|
|
3680
|
+
Object.entries(otherComponentsUpdates$1).forEach(([sourceId, updates]) => {
|
|
3681
|
+
editStore.operationManager.setWidgetProperties({
|
|
3682
|
+
sourceId,
|
|
3683
|
+
properties: updates
|
|
3684
|
+
});
|
|
3685
|
+
});
|
|
3686
|
+
};
|
|
3687
|
+
editStore.operationManager.batchUpdate(() => {
|
|
3688
|
+
if (skipSecondaryComponentsCreation) editStore.operationManager.createComponent(createRequests[0]);
|
|
3689
|
+
else createRequests.forEach((createRequest) => {
|
|
3690
|
+
editStore.operationManager.createComponent(createRequest);
|
|
3691
|
+
});
|
|
3692
|
+
if (hasOtherComponentsUpdates) performOtherComponentsUpdates(otherComponentsUpdates);
|
|
3693
|
+
});
|
|
3694
|
+
} else editStore.operationManager.createComponent(createRequests[0]);
|
|
3695
|
+
/**
|
|
3696
|
+
* Returns the single id, or the the last component if there are multiple.
|
|
3697
|
+
* See EditorTemplate's definition to understand why.
|
|
3698
|
+
*/
|
|
3699
|
+
return createRequests.at(-1).id;
|
|
3700
|
+
}
|
|
3701
|
+
function wrapComponentIfNecessary(primaryComponent, wrapInType) {
|
|
3702
|
+
if (!wrapInType) return primaryComponent;
|
|
3703
|
+
const { properties } = getComponentBaseProperties(wrapInType, { type: "Page" });
|
|
3704
|
+
const [_$1, continueWrappingInType] = shouldWrapComponent(primaryComponent.tagName, wrapInType);
|
|
3705
|
+
return {
|
|
3706
|
+
parentElement: primaryComponent.parentElement,
|
|
3707
|
+
tagName: wrapInType,
|
|
3708
|
+
id: getEditStore().operationManager.generateSourceId(),
|
|
3709
|
+
properties,
|
|
3710
|
+
children: [wrapComponentIfNecessary(primaryComponent, continueWrappingInType)]
|
|
3711
|
+
};
|
|
3712
|
+
}
|
|
3713
|
+
|
|
3714
|
+
//#endregion
|
|
3715
|
+
//#region src/edit-mode/dnd/handle-stack-drop.ts
|
|
3716
|
+
const mergeDroppedDimensions = (draggedType, draggedProps, activeDragRect) => {
|
|
3717
|
+
const safeExistingDimensions = filterSafeStackDimensionProperties({
|
|
3718
|
+
width: draggedProps?.width,
|
|
3719
|
+
height: draggedProps?.height,
|
|
3720
|
+
size: draggedProps?.size
|
|
3721
|
+
});
|
|
3722
|
+
const width = safeExistingDimensions.width;
|
|
3723
|
+
const height = safeExistingDimensions.height;
|
|
3724
|
+
if (draggedType === "Icon") return { size: safeExistingDimensions.size ?? (activeDragRect?.height ? Property$1.Dimension(Dim$1.px(activeDragRect.height)) : Property$1.Static("")) };
|
|
3725
|
+
return {
|
|
3726
|
+
width,
|
|
3727
|
+
height
|
|
3728
|
+
};
|
|
3729
|
+
};
|
|
3730
|
+
const handleStackDropWithinCanvas = (params) => {
|
|
3731
|
+
const { dropInfo, draggedId, dropTargetId } = params;
|
|
3732
|
+
const editStore = getEditStore();
|
|
3733
|
+
const dropSourceId = editStore.runtimeEntitiesManager.getEditorWidgetSourceId(dropTargetId);
|
|
3734
|
+
const draggedSourceId = editStore.runtimeEntitiesManager.getEditorWidgetSourceId(draggedId);
|
|
3735
|
+
if (!dropSourceId || !draggedSourceId) throw new Error(`Missing IDs: dragging ${draggedId} to ${dropTargetId}`);
|
|
3736
|
+
console.log(`Dragged ${draggedSourceId} to ${dropSourceId}`, {
|
|
3737
|
+
dropInfo,
|
|
3738
|
+
index: dropInfo.insertionIndex
|
|
3739
|
+
});
|
|
3740
|
+
if (dropInfo.noopDrop) return;
|
|
3741
|
+
const draggedType = editStore.runtimeEntitiesManager.getEditorWidgetType(draggedId);
|
|
3742
|
+
const dropTargetType = editStore.runtimeEntitiesManager.getEditorWidgetType(dropTargetId);
|
|
3743
|
+
if (!draggedType) throw new Error(`Missing dragged type: ${draggedId}`);
|
|
3744
|
+
const [shouldWrap, wrapInType] = shouldWrapComponent(draggedType, dropTargetType);
|
|
3745
|
+
const activeDragRect = editStore.ui.dnd.activeDragRect;
|
|
3746
|
+
if (shouldWrap) dropComponentAndWrap({
|
|
3747
|
+
draggedId,
|
|
3748
|
+
draggedSourceId,
|
|
3749
|
+
dropTargetId,
|
|
3750
|
+
dropSourceId,
|
|
3751
|
+
dropInfo,
|
|
3752
|
+
dropTargetType,
|
|
3753
|
+
activeDragRect,
|
|
3754
|
+
wrapInType
|
|
3755
|
+
});
|
|
3756
|
+
else {
|
|
3757
|
+
const draggedProps = editStore.runtimeEntitiesManager.getEditorWidgetMeta(draggedId)?.props;
|
|
3758
|
+
editStore.operationManager.dropComponent({
|
|
3759
|
+
from: { source: { id: draggedSourceId } },
|
|
3760
|
+
to: { source: {
|
|
3761
|
+
id: dropSourceId,
|
|
3762
|
+
index: dropInfo.insertionIndex
|
|
3763
|
+
} },
|
|
3764
|
+
propsToChange: { ...mergeDroppedDimensions(draggedType, draggedProps, activeDragRect) }
|
|
3765
|
+
});
|
|
3766
|
+
}
|
|
3767
|
+
};
|
|
3768
|
+
const dropComponentAndWrap = async (params) => {
|
|
3769
|
+
const { draggedId, draggedSourceId, dropSourceId, dropTargetId, dropInfo, dropTargetType, activeDragRect, wrapInType } = params;
|
|
3770
|
+
const editStore = getEditStore();
|
|
3771
|
+
const dropScopeId = editStore.runtimeEntitiesManager.getEditorWidgetScopeId(dropTargetId);
|
|
3772
|
+
if (!dropScopeId) throw new Error(`Missing drop scope id: ${dropTargetId}`);
|
|
3773
|
+
const scopeName = root_store_default.entityManager.getScopeName(dropScopeId);
|
|
3774
|
+
const newComponentSourceId = await createComponent({
|
|
3775
|
+
componentType: wrapInType,
|
|
3776
|
+
parent: {
|
|
3777
|
+
index: dropInfo.insertionIndex,
|
|
3778
|
+
id: dropSourceId
|
|
3779
|
+
},
|
|
3780
|
+
scopeName
|
|
3781
|
+
});
|
|
3782
|
+
if (!newComponentSourceId) throw new Error("Missing new component source id");
|
|
3783
|
+
const draggedProps = editStore.runtimeEntitiesManager.getEditorWidgetMeta(draggedId)?.props;
|
|
3784
|
+
editStore.operationManager.dropComponent({
|
|
3785
|
+
from: { source: { id: draggedSourceId } },
|
|
3786
|
+
to: { source: {
|
|
3787
|
+
id: newComponentSourceId,
|
|
3788
|
+
index: 0
|
|
3789
|
+
} },
|
|
3790
|
+
propsToChange: { ...mergeDroppedDimensions(dropTargetType, draggedProps, activeDragRect) }
|
|
3791
|
+
});
|
|
3792
|
+
};
|
|
3793
|
+
const handleStackDropForNewComponent = ({ componentType, dropInfo, dropTargetId }) => {
|
|
3794
|
+
const editStore = getEditStore();
|
|
3795
|
+
const dropSourceId = editStore.runtimeEntitiesManager.getEditorWidgetSourceId(dropTargetId);
|
|
3796
|
+
const dropScopeId = editStore.runtimeEntitiesManager.getEditorWidgetScopeId(dropTargetId);
|
|
3797
|
+
if (!dropSourceId || !dropScopeId) throw new Error("Missing drop source id");
|
|
3798
|
+
const scopeName = root_store_default.entityManager.getScopeName(dropScopeId);
|
|
3799
|
+
return createComponent({
|
|
3800
|
+
componentType,
|
|
3801
|
+
parent: {
|
|
3802
|
+
index: dropInfo.insertionIndex,
|
|
3803
|
+
id: dropSourceId
|
|
3804
|
+
},
|
|
3805
|
+
scopeName
|
|
3806
|
+
});
|
|
3807
|
+
};
|
|
3808
|
+
const handleStackDrop = async ({ dropInfo, draggedId, dropTargetId, isDraggingNewComponent, newComponentType }) => {
|
|
3809
|
+
if (dropInfo.insertionIndex == null) throw new Error("No insertion index found");
|
|
3810
|
+
if (isDraggingNewComponent) {
|
|
3811
|
+
if (!newComponentType) throw new Error("Missing componentType to create new component");
|
|
3812
|
+
return handleStackDropForNewComponent({
|
|
3813
|
+
componentType: newComponentType,
|
|
3814
|
+
dropTargetId,
|
|
3815
|
+
dropInfo
|
|
3816
|
+
});
|
|
3817
|
+
} else {
|
|
3818
|
+
if (!draggedId) throw new Error("Missing dragged id");
|
|
3819
|
+
handleStackDropWithinCanvas({
|
|
3820
|
+
dropInfo,
|
|
3821
|
+
draggedId,
|
|
3822
|
+
dropTargetId
|
|
3823
|
+
});
|
|
3824
|
+
}
|
|
3825
|
+
};
|
|
3826
|
+
|
|
3827
|
+
//#endregion
|
|
3828
|
+
//#region src/edit-mode/dnd/hooks/use-handle-dnd-events.ts
|
|
3829
|
+
const measureRect = (id) => {
|
|
3830
|
+
const rect = id ? getBoundingBoxForWidget(id) : null;
|
|
3831
|
+
if (!rect) return null;
|
|
3832
|
+
return {
|
|
3833
|
+
left: rect.left,
|
|
3834
|
+
top: rect.top,
|
|
3835
|
+
right: rect.right,
|
|
3836
|
+
bottom: rect.bottom,
|
|
3837
|
+
width: rect.width,
|
|
3838
|
+
height: rect.height
|
|
3839
|
+
};
|
|
3840
|
+
};
|
|
3503
3841
|
/**
|
|
3504
|
-
*
|
|
3842
|
+
* We have to follow a few rules while drag and dropping:
|
|
3843
|
+
* 1. You can drag and drop within your own function component/scope
|
|
3844
|
+
* 2. You can drag to another function component, but only if it doesn't break references to local variables in the current function component
|
|
3845
|
+
* > a. If the reference is to some SB state, and you are in the same scope, you can drag to another function component and we will update the reference to the SB state
|
|
3846
|
+
* @param overSourceId the widget ID we are currently dragging over
|
|
3847
|
+
* @param overRootId the root ID (which could be the same as the widget ID) that we are dragging over, for example dragging over a container in another function component
|
|
3848
|
+
* @returns true if the drop target is invalid
|
|
3505
3849
|
*/
|
|
3506
|
-
const
|
|
3507
|
-
const
|
|
3850
|
+
const isInvalidDropTarget = (overInstanceId, overRootInstanceId) => {
|
|
3851
|
+
const activeRootInstanceIds = getEditStore().ui.dnd.validRootIds;
|
|
3852
|
+
return Boolean(activeRootInstanceIds && !activeRootInstanceIds.includes(overInstanceId) && !activeRootInstanceIds.includes(overRootInstanceId)) || isDroppingOnAncestor(overInstanceId);
|
|
3853
|
+
};
|
|
3854
|
+
const isDroppingOnAncestor = (overInstanceId) => {
|
|
3855
|
+
if (overInstanceId) {
|
|
3856
|
+
const editStore = getEditStore();
|
|
3857
|
+
const ancestorIds = /* @__PURE__ */ new Set();
|
|
3858
|
+
let currentId = overInstanceId;
|
|
3859
|
+
let iterations = 0;
|
|
3860
|
+
const MAX_ITERATIONS$1 = 1e3;
|
|
3861
|
+
while (currentId && iterations < MAX_ITERATIONS$1) {
|
|
3862
|
+
const entity = editStore.runtimeEntitiesManager.getEditorWidgetMeta(currentId);
|
|
3863
|
+
if (entity?.parentInstanceId) {
|
|
3864
|
+
ancestorIds.add(entity.parentInstanceId);
|
|
3865
|
+
currentId = entity.parentInstanceId;
|
|
3866
|
+
} else break;
|
|
3867
|
+
iterations++;
|
|
3868
|
+
}
|
|
3869
|
+
return Array.from(ancestorIds).some((id) => editStore.ui.isInstanceSelected(id));
|
|
3870
|
+
}
|
|
3871
|
+
return false;
|
|
3872
|
+
};
|
|
3873
|
+
const useHandleDnDEvents = () => {
|
|
3874
|
+
const setActiveDragRect = useMemo(() => {
|
|
3875
|
+
const editStore = getEditStore();
|
|
3876
|
+
const throttled = throttle((rect) => {
|
|
3877
|
+
editStore.ui.dnd.setActiveDragRect(rect);
|
|
3878
|
+
}, 10, {
|
|
3879
|
+
leading: true,
|
|
3880
|
+
trailing: true
|
|
3881
|
+
});
|
|
3882
|
+
return (val) => {
|
|
3883
|
+
throttled(val);
|
|
3884
|
+
};
|
|
3885
|
+
}, []);
|
|
3886
|
+
const setActiveTargetInfo = useMemo(() => {
|
|
3887
|
+
const editStore = getEditStore();
|
|
3888
|
+
const throttled = throttle((id, rect) => {
|
|
3889
|
+
editStore.ui.dnd.setDropTargetId(id);
|
|
3890
|
+
editStore.ui.dnd.setActiveTargetRect(rect);
|
|
3891
|
+
}, 10, {
|
|
3892
|
+
leading: true,
|
|
3893
|
+
trailing: true
|
|
3894
|
+
});
|
|
3895
|
+
return (id, val) => {
|
|
3896
|
+
throttled(id, val);
|
|
3897
|
+
};
|
|
3898
|
+
}, []);
|
|
3899
|
+
useDndMonitor({
|
|
3900
|
+
onDragStart: useCallback((event) => {
|
|
3901
|
+
const editStore = getEditStore();
|
|
3902
|
+
const activeData = event.active?.data.current;
|
|
3903
|
+
if (!activeData && !editStore.ui.dnd.isDraggingNewComponent) {
|
|
3904
|
+
console.error("No active widget data");
|
|
3905
|
+
return;
|
|
3906
|
+
}
|
|
3907
|
+
const activeRootInstanceId = (activeData?.instanceId && editStore.runtimeEntitiesManager.getEditorWidgetMeta(activeData?.instanceId))?.rootInstanceId;
|
|
3908
|
+
const hasLocalBinding = activeData?.instanceId && editStore.runtimeEntitiesManager.doesEntityHaveLocalBindings(activeData?.instanceId);
|
|
3909
|
+
if (activeRootInstanceId && hasLocalBinding) editStore.ui.dnd.setValidRootIds([activeRootInstanceId]);
|
|
3910
|
+
editStore.ui.dnd.setDropTargetId(null);
|
|
3911
|
+
editStore.ui.dnd.setIsDragging(true);
|
|
3912
|
+
if (editStore.ui.dnd.isDraggingNewComponent) {
|
|
3913
|
+
editStore.ui.selectWidget(null);
|
|
3914
|
+
editStore.ui.dnd.resizePageIfNeeded();
|
|
3915
|
+
} else editStore.ui.selectWidget(event.active?.id ? event.active.id : null, event.activatorEvent?.shiftKey);
|
|
3916
|
+
}, []),
|
|
3917
|
+
onDragMove: useCallback((event) => {
|
|
3918
|
+
const editStore = getEditStore();
|
|
3919
|
+
const overData = event.over?.data.current;
|
|
3920
|
+
const overRootId = overData?.rootInstanceId ?? null;
|
|
3921
|
+
const overInstanceId = overData?.instanceId ?? null;
|
|
3922
|
+
editStore.ui.dnd.setInvalidDropTarget(isInvalidDropTarget(overInstanceId, overRootId));
|
|
3923
|
+
setActiveTargetInfo(event.over?.id ?? null, event.over?.rect ?? null);
|
|
3924
|
+
const collisionRect = event.collisions?.[0]?.data?.injectedCollisionRect;
|
|
3925
|
+
if (collisionRect) setActiveDragRect(collisionRect);
|
|
3926
|
+
else setActiveDragRect(null);
|
|
3927
|
+
}, [setActiveDragRect, setActiveTargetInfo]),
|
|
3928
|
+
onDragOver: useCallback((event) => {
|
|
3929
|
+
const editStore = getEditStore();
|
|
3930
|
+
const overData = event.over?.data.current;
|
|
3931
|
+
const overRootId = overData?.rootInstanceId ?? null;
|
|
3932
|
+
const overInstanceId = overData?.instanceId ?? null;
|
|
3933
|
+
editStore.ui.dnd.setInvalidDropTarget(isInvalidDropTarget(overInstanceId, overRootId));
|
|
3934
|
+
const overId = event.over?.id ? String(event.over?.id) : null;
|
|
3935
|
+
setActiveTargetInfo(overId, measureRect(overId));
|
|
3936
|
+
}, [setActiveTargetInfo]),
|
|
3937
|
+
onDragCancel: useCallback((_event) => {
|
|
3938
|
+
const editStore = getEditStore();
|
|
3939
|
+
editStore.ui.dnd.setIsDragging(false);
|
|
3940
|
+
editStore.ui.dnd.cancelNewComponentDrag();
|
|
3941
|
+
}, []),
|
|
3942
|
+
onDragEnd: useCallback(async (event) => {
|
|
3943
|
+
const editStore = getEditStore();
|
|
3944
|
+
let possibleNewComponentId;
|
|
3945
|
+
try {
|
|
3946
|
+
if (editStore.ui.dnd.invalidDropTarget) {
|
|
3947
|
+
editorBridge.sendNotification("error", "You cannot drop a component here.");
|
|
3948
|
+
return;
|
|
3949
|
+
}
|
|
3950
|
+
const dropTargetId = event.over?.id ? String(event.over.id) : null;
|
|
3951
|
+
const draggedId = event.active?.id ? String(event.active?.id) : null;
|
|
3952
|
+
const activeRootInstanceId = editStore.interactionLayerManager.activeRootInstanceId;
|
|
3953
|
+
if (dropTargetId && activeRootInstanceId && !(editStore.runtimeEntitiesManager.isChildOf(dropTargetId, activeRootInstanceId) || dropTargetId === activeRootInstanceId)) return;
|
|
3954
|
+
if (dropTargetId !== editStore.ui.dnd.dropTargetId) throw new Error("Drop target id and drag over id do not match");
|
|
3955
|
+
if (!dropTargetId) throw new Error("No drop target id");
|
|
3956
|
+
if (editStore.ui.dnd.isDropTargetStackLike) {
|
|
3957
|
+
const dropInfo = editStore.ui.dnd.stack.refreshPositionsAndGetDropIndex();
|
|
3958
|
+
possibleNewComponentId = await handleStackDrop({
|
|
3959
|
+
dropInfo,
|
|
3960
|
+
isDraggingNewComponent: editStore.ui.dnd.isDraggingNewComponent,
|
|
3961
|
+
newComponentType: editStore.ui.dnd.dragToCanvasComponentType,
|
|
3962
|
+
dropTargetId,
|
|
3963
|
+
draggedId
|
|
3964
|
+
});
|
|
3965
|
+
} else throw new Error("Grid is no longer supported");
|
|
3966
|
+
} catch (e) {
|
|
3967
|
+
console.error("Error dropping item", e);
|
|
3968
|
+
} finally {
|
|
3969
|
+
runInAction(() => {
|
|
3970
|
+
editStore.ui.dnd.setIsDragging(false);
|
|
3971
|
+
editStore.ui.dnd.cancelNewComponentDrag();
|
|
3972
|
+
if (possibleNewComponentId) editStore.ui.selectNewComponentBySourceId(possibleNewComponentId);
|
|
3973
|
+
});
|
|
3974
|
+
}
|
|
3975
|
+
}, [])
|
|
3976
|
+
});
|
|
3977
|
+
};
|
|
3508
3978
|
|
|
3509
3979
|
//#endregion
|
|
3510
3980
|
//#region src/edit-mode/dnd/stack-drop.tsx
|
|
@@ -3522,7 +3992,7 @@ const StackDropPreview = observer(() => {
|
|
|
3522
3992
|
bottom: "anchor(bottom)",
|
|
3523
3993
|
positionAnchor: getWidgetDropAreaAnchorName(dropTargetId, dropTargetWidgetType)
|
|
3524
3994
|
},
|
|
3525
|
-
children: [editStore.ui.dnd.
|
|
3995
|
+
children: [!editStore.ui.dnd.invalidDropTarget && placeholders ? /* @__PURE__ */ jsx(Fragment, { children: placeholders.map((placeholder) => /* @__PURE__ */ jsx("div", {
|
|
3526
3996
|
className: "sb-edit-drop-placeholder",
|
|
3527
3997
|
style: {
|
|
3528
3998
|
top: placeholder.top,
|
|
@@ -3535,24 +4005,36 @@ const StackDropPreview = observer(() => {
|
|
|
3535
4005
|
"data-is-valid-drop": true
|
|
3536
4006
|
}, placeholder.top + placeholder.left)) }) : null, /* @__PURE__ */ jsx("div", {
|
|
3537
4007
|
className: "sb-edit-drop-target-outline",
|
|
3538
|
-
"data-invalid-target":
|
|
4008
|
+
"data-invalid-target": editStore.ui.dnd.invalidDropTarget
|
|
3539
4009
|
})]
|
|
3540
4010
|
});
|
|
3541
4011
|
});
|
|
3542
4012
|
|
|
3543
4013
|
//#endregion
|
|
3544
4014
|
//#region src/edit-mode/dnd/drop-layer.tsx
|
|
3545
|
-
const DropLayer = observer((
|
|
4015
|
+
const DropLayer = observer(() => {
|
|
4016
|
+
useHandleDnDEvents();
|
|
3546
4017
|
const editStore = getEditStore();
|
|
3547
4018
|
const draggedWidgetType = editStore.ui.dnd.draggedWidgetType;
|
|
3548
4019
|
const dropTargetWidgetType = editStore.ui.dnd.dropTargetWidgetType;
|
|
3549
4020
|
const isDropTargetStackLike = editStore.ui.dnd.isDropTargetStackLike;
|
|
3550
4021
|
const dropTargetId = editStore.ui.dnd.dropTargetId;
|
|
3551
|
-
const isDropTargetInInteractionLayer =
|
|
3552
|
-
const
|
|
3553
|
-
|
|
4022
|
+
const isDropTargetInInteractionLayer = getIsComponentInInteractionLayer(dropTargetId);
|
|
4023
|
+
const isDragging = editStore.ui.dnd.isDragging;
|
|
4024
|
+
const validStackDrop = isDropTargetInInteractionLayer && isDragging && Boolean(draggedWidgetType && dropTargetWidgetType) && isDropTargetStackLike;
|
|
4025
|
+
const isValidDrop = validStackDrop;
|
|
4026
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [validStackDrop && /* @__PURE__ */ jsx(StackDropPreview, {}), /* @__PURE__ */ jsx(DragOverlay, {
|
|
3554
4027
|
modifiers: [snapCenterToCursor],
|
|
3555
|
-
dropAnimation: null
|
|
4028
|
+
dropAnimation: null,
|
|
4029
|
+
children: editStore.ui.dnd.isDraggingNewComponent && /* @__PURE__ */ jsx("div", {
|
|
4030
|
+
className: "sb-edit-drag-preview",
|
|
4031
|
+
"data-is-valid-drop": isValidDrop,
|
|
4032
|
+
style: {
|
|
4033
|
+
visibility: "visible",
|
|
4034
|
+
height: `${editStore.ui.dnd.draggingWidgetSize.height * 12}px`,
|
|
4035
|
+
width: `${editStore.ui.dnd.draggingWidgetSize.width * 12}px`
|
|
4036
|
+
}
|
|
4037
|
+
})
|
|
3556
4038
|
})] });
|
|
3557
4039
|
});
|
|
3558
4040
|
var drop_layer_default = DropLayer;
|
|
@@ -4005,18 +4487,18 @@ const useWidgetErrors = (params) => {
|
|
|
4005
4487
|
]);
|
|
4006
4488
|
};
|
|
4007
4489
|
const useSelectionElements = (params) => {
|
|
4008
|
-
const { focusedInstanceId, selectedInstanceIds, targetedSourceIds, aiContextMode
|
|
4490
|
+
const { focusedInstanceId, selectedInstanceIds, targetedSourceIds, aiContextMode } = params;
|
|
4009
4491
|
const allTargetedComponents = useMemo(() => {
|
|
4010
4492
|
const components = [];
|
|
4011
4493
|
targetedSourceIds.forEach((sourceId) => {
|
|
4012
4494
|
const sourceInstanceIds = getEditStore().runtimeEntitiesManager.widgets.getAllInstanceIdsForSourceId(sourceId);
|
|
4013
|
-
components.push(...sourceInstanceIds.
|
|
4495
|
+
components.push(...sourceInstanceIds.map((instanceId) => ({
|
|
4014
4496
|
instanceId,
|
|
4015
4497
|
sourceId
|
|
4016
4498
|
})));
|
|
4017
4499
|
});
|
|
4018
4500
|
return components;
|
|
4019
|
-
}, [targetedSourceIds
|
|
4501
|
+
}, [targetedSourceIds]);
|
|
4020
4502
|
const visibleTargetedComponents = useViewportIntersection(allTargetedComponents);
|
|
4021
4503
|
return useObserverMemo(() => {
|
|
4022
4504
|
const selectedRects = [];
|
|
@@ -4031,7 +4513,7 @@ const useSelectionElements = (params) => {
|
|
|
4031
4513
|
isVisible
|
|
4032
4514
|
});
|
|
4033
4515
|
});
|
|
4034
|
-
selectedInstanceIds.
|
|
4516
|
+
selectedInstanceIds.forEach((instanceId) => {
|
|
4035
4517
|
const { type, displayName, sourceId, isVisible } = selectDisplayNameAndVisibility(instanceId);
|
|
4036
4518
|
if (sourceId && !targetedSourceIds.includes(sourceId)) selectedRects.push({
|
|
4037
4519
|
instanceId,
|
|
@@ -4042,7 +4524,7 @@ const useSelectionElements = (params) => {
|
|
|
4042
4524
|
isVisible
|
|
4043
4525
|
});
|
|
4044
4526
|
});
|
|
4045
|
-
if (focusedInstanceId &&
|
|
4527
|
+
if (focusedInstanceId && (aiContextMode === AiContextMode.AUTO_SELECT || !selectedInstanceIds.includes(focusedInstanceId))) {
|
|
4046
4528
|
const { type, displayName, sourceId, isVisible } = selectDisplayNameAndVisibility(focusedInstanceId);
|
|
4047
4529
|
if (sourceId) selectedRects.push({
|
|
4048
4530
|
instanceId: focusedInstanceId,
|
|
@@ -4059,8 +4541,7 @@ const useSelectionElements = (params) => {
|
|
|
4059
4541
|
selectedInstanceIds,
|
|
4060
4542
|
targetedSourceIds,
|
|
4061
4543
|
aiContextMode,
|
|
4062
|
-
visibleTargetedComponents
|
|
4063
|
-
rootId
|
|
4544
|
+
visibleTargetedComponents
|
|
4064
4545
|
]);
|
|
4065
4546
|
};
|
|
4066
4547
|
const InteractionRectTargetBorder = ({ instanceId }) => {
|
|
@@ -4292,7 +4773,7 @@ const InteractionLayer = observer((props) => {
|
|
|
4292
4773
|
displayName: props.rootName ?? "Unknown",
|
|
4293
4774
|
hideRectBorder: false
|
|
4294
4775
|
}, props.rootInstanceId) : null;
|
|
4295
|
-
return /* @__PURE__ */
|
|
4776
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
4296
4777
|
className: "sb-interaction-layer-wrapper",
|
|
4297
4778
|
children: [
|
|
4298
4779
|
interactionRectsForSelectedElements,
|
|
@@ -4303,9 +4784,9 @@ const InteractionLayer = observer((props) => {
|
|
|
4303
4784
|
displayName: name,
|
|
4304
4785
|
instanceId: id
|
|
4305
4786
|
}, id)),
|
|
4306
|
-
/* @__PURE__ */ jsx(drop_layer_default, {
|
|
4787
|
+
props.rootType !== "App" && /* @__PURE__ */ jsx(drop_layer_default, {})
|
|
4307
4788
|
]
|
|
4308
|
-
})
|
|
4789
|
+
});
|
|
4309
4790
|
});
|
|
4310
4791
|
var interaction_layer_default = InteractionLayer;
|
|
4311
4792
|
|
|
@@ -4400,7 +4881,7 @@ const stableEffectOptions$1 = {
|
|
|
4400
4881
|
cold: true
|
|
4401
4882
|
};
|
|
4402
4883
|
function useRuntimeEditTracking(props) {
|
|
4403
|
-
const { parentInstanceId, directParentInstanceId, identifier, type, children, widgetProps, rootInstanceId,
|
|
4884
|
+
const { parentInstanceId, directParentInstanceId, identifier, type, children, widgetProps, rootInstanceId, indexWithinParent, isRoot, isInsideRoot } = props;
|
|
4404
4885
|
const { children: _children,...rest } = widgetProps;
|
|
4405
4886
|
use_stable_effect_default(() => {
|
|
4406
4887
|
const widgetMeta = {
|
|
@@ -4415,7 +4896,6 @@ function useRuntimeEditTracking(props) {
|
|
|
4415
4896
|
directParentInstanceId,
|
|
4416
4897
|
sourceId: identifier.sourceId,
|
|
4417
4898
|
rootInstanceId,
|
|
4418
|
-
interactionLayerInstanceId,
|
|
4419
4899
|
isRoot,
|
|
4420
4900
|
isInsideRoot
|
|
4421
4901
|
};
|
|
@@ -4428,7 +4908,6 @@ function useRuntimeEditTracking(props) {
|
|
|
4428
4908
|
parentInstanceId,
|
|
4429
4909
|
directParentInstanceId,
|
|
4430
4910
|
rootInstanceId,
|
|
4431
|
-
interactionLayerInstanceId,
|
|
4432
4911
|
type,
|
|
4433
4912
|
rest
|
|
4434
4913
|
}, stableEffectOptions$1);
|
|
@@ -4528,7 +5007,6 @@ const EditWrapper = observer(function EditWrapper$1(props) {
|
|
|
4528
5007
|
const rootInstanceId = editorRootContext?.instanceId;
|
|
4529
5008
|
const parentIdentifier = useParentIdentifier();
|
|
4530
5009
|
const isRoot = ROOT_WIDGET_ATTRIBUTE in props.widgetProps;
|
|
4531
|
-
const { rootInstanceId: interactionLayerInstanceId } = useInteractionLayerContext();
|
|
4532
5010
|
const children = useRuntimeEditTracking({
|
|
4533
5011
|
parentInstanceId: parentIdentifier?.instanceId,
|
|
4534
5012
|
directParentInstanceId: props.directParentInstanceId,
|
|
@@ -4537,7 +5015,6 @@ const EditWrapper = observer(function EditWrapper$1(props) {
|
|
|
4537
5015
|
children: props.children,
|
|
4538
5016
|
widgetProps: props.widgetProps,
|
|
4539
5017
|
rootInstanceId,
|
|
4540
|
-
interactionLayerInstanceId,
|
|
4541
5018
|
indexWithinParent: props.indexWithinParent,
|
|
4542
5019
|
isRoot,
|
|
4543
5020
|
isInsideRoot
|
|
@@ -4566,21 +5043,18 @@ const EditWrapper = observer(function EditWrapper$1(props) {
|
|
|
4566
5043
|
const { onContextMenu } = useRightClickMenu({ sourceId: props.identifier.sourceId });
|
|
4567
5044
|
const showVisibilityBackground = props.widgetProps.isVisible === false && !editStore.ui.getSelectedSourceIds().includes(props.identifier.sourceId);
|
|
4568
5045
|
const handleClick = useCallback((ev) => {
|
|
4569
|
-
const stopPropagation = () => {
|
|
4570
|
-
if (ev.stopPropagation) ev.stopPropagation();
|
|
4571
|
-
};
|
|
4572
5046
|
const editStore$1 = getEditStore();
|
|
4573
5047
|
if (ev.altKey || editStore$1.ai.getIsTaggingEnabled() && editStore$1.ai.shouldToggleComponentInAiContext()) {
|
|
4574
5048
|
const sourceId = props.identifier.sourceId;
|
|
4575
5049
|
const instanceId = props.identifier.instanceId;
|
|
4576
5050
|
editorBridge.toggleComponentInAiContext(sourceId, instanceId);
|
|
4577
|
-
stopPropagation();
|
|
5051
|
+
ev.stopPropagation();
|
|
4578
5052
|
return;
|
|
4579
5053
|
}
|
|
4580
5054
|
editStore$1.ui.selectWidget(props.identifier.instanceId, ev.shiftKey === true);
|
|
4581
|
-
stopPropagation();
|
|
5055
|
+
ev.stopPropagation();
|
|
4582
5056
|
}, [props.identifier.sourceId, props.identifier.instanceId]);
|
|
4583
|
-
const
|
|
5057
|
+
const dropTargetRef = useRef(null);
|
|
4584
5058
|
const handleRef = useCallback((el) => {
|
|
4585
5059
|
setDraggableNodeRef(el);
|
|
4586
5060
|
}, [setDraggableNodeRef]);
|
|
@@ -4618,7 +5092,7 @@ const EditWrapper = observer(function EditWrapper$1(props) {
|
|
|
4618
5092
|
identifier,
|
|
4619
5093
|
widgetProps: props.widgetProps,
|
|
4620
5094
|
editorProps,
|
|
4621
|
-
dropTargetRef
|
|
5095
|
+
dropTargetRef,
|
|
4622
5096
|
showErrors: true,
|
|
4623
5097
|
children: [showVisibilityBackground && /* @__PURE__ */ jsx("div", {
|
|
4624
5098
|
className: VisibilityOverlayClass,
|
|
@@ -4637,13 +5111,10 @@ const EditWrapper = observer(function EditWrapper$1(props) {
|
|
|
4637
5111
|
}) : node;
|
|
4638
5112
|
if (isDroppable) content = /* @__PURE__ */ jsx(droppable_widget_default, {
|
|
4639
5113
|
instanceId: props.identifier.instanceId,
|
|
4640
|
-
|
|
5114
|
+
dropTargetRef,
|
|
4641
5115
|
children: content
|
|
4642
5116
|
});
|
|
4643
|
-
if (props.type === "App" || props.type === "Page") return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(
|
|
4644
|
-
instanceId: props.identifier.instanceId,
|
|
4645
|
-
children: content
|
|
4646
|
-
}), /* @__PURE__ */ jsx(interaction_layer_default, {
|
|
5117
|
+
if (props.type === "App" || props.type === "Page") return /* @__PURE__ */ jsxs(Fragment, { children: [content, /* @__PURE__ */ jsx(interaction_layer_default, {
|
|
4647
5118
|
rootType: props.type,
|
|
4648
5119
|
rootInstanceId: props.identifier.instanceId,
|
|
4649
5120
|
rootName: identifier.name.value
|
|
@@ -5758,7 +6229,7 @@ var AsyncSocket = class {
|
|
|
5758
6229
|
|
|
5759
6230
|
//#endregion
|
|
5760
6231
|
//#region src/edit-mode/source-update-api.ts
|
|
5761
|
-
const PING_INTERVAL_MS =
|
|
6232
|
+
const PING_INTERVAL_MS = 3e4;
|
|
5762
6233
|
var OperationAPI = class {
|
|
5763
6234
|
retryAttempts = 0;
|
|
5764
6235
|
asyncSocket = new AsyncSocket();
|
|
@@ -5914,9 +6385,6 @@ async function connectSocket(serverUrl, { peerId, userId, applicationId, onClose
|
|
|
5914
6385
|
removeRegisteredComponent: [async (payload) => {
|
|
5915
6386
|
root_store_default.componentRegistry.deleteCustomComponent(payload.name);
|
|
5916
6387
|
}],
|
|
5917
|
-
loadComponents: [async (payload) => {
|
|
5918
|
-
import(payload.componentFilePath);
|
|
5919
|
-
}],
|
|
5920
6388
|
deleteEntities: [async (payload) => {
|
|
5921
6389
|
payload.forEach((entity) => {
|
|
5922
6390
|
if (entity.entityName) root_store_default.entityManager.deleteEntity({
|
|
@@ -6160,6 +6628,7 @@ const registerComponentInternal = (type, config, Component$1) => {
|
|
|
6160
6628
|
widgetProps,
|
|
6161
6629
|
component: Component$1,
|
|
6162
6630
|
identifier: identifier.current,
|
|
6631
|
+
isDroppable,
|
|
6163
6632
|
directParentInstanceId: props[WIDGET_PARENT_INSTANCE_ID_ATTRIBUTE],
|
|
6164
6633
|
indexWithinParent: props[WIDGET_INDEX_WITHIN_PARENT],
|
|
6165
6634
|
children: props.children
|
|
@@ -6236,7 +6705,10 @@ const propertiesDefinition$4 = {
|
|
|
6236
6705
|
height: Dim$1.fill()
|
|
6237
6706
|
},
|
|
6238
6707
|
showWidth: () => false,
|
|
6239
|
-
|
|
6708
|
+
hasMinWidth: false,
|
|
6709
|
+
hasMinHeight: false,
|
|
6710
|
+
hasMaxWidth: false,
|
|
6711
|
+
hasMaxHeight: false
|
|
6240
6712
|
})),
|
|
6241
6713
|
appearance: Section.category(PropsPanelCategory.Appearance).children({ loading: loading() }),
|
|
6242
6714
|
events: Section.category(PropsPanelCategory.EventHandlers).children({ onLoad: Prop.event().propertiesPanel({ label: "onPageLoad" }) })
|
|
@@ -6245,7 +6717,7 @@ const propertiesDefinition$4 = {
|
|
|
6245
6717
|
//#endregion
|
|
6246
6718
|
//#region src/lib/user-facing/components/page/index.tsx
|
|
6247
6719
|
const Page = registerComponentInternal(NATIVE_COMPONENT_TYPES.Page, { propertiesDefinition: propertiesDefinition$4 }, (props) => {
|
|
6248
|
-
const { name, isAnonymous, style, onLoad
|
|
6720
|
+
const { name, isAnonymous, style, onLoad,...other } = props;
|
|
6249
6721
|
const { scopeId } = useScope();
|
|
6250
6722
|
useEffect(() => {
|
|
6251
6723
|
return root_store_default.onPageLoaded(scopeId, () => {
|
|
@@ -6259,13 +6731,13 @@ const Page = registerComponentInternal(NATIVE_COMPONENT_TYPES.Page, { properties
|
|
|
6259
6731
|
overflow: "auto"
|
|
6260
6732
|
},
|
|
6261
6733
|
children: /* @__PURE__ */ jsx(InternalVStack, {
|
|
6262
|
-
...editorProps,
|
|
6263
6734
|
isVisible: true,
|
|
6264
6735
|
style: {
|
|
6265
6736
|
height: "100%",
|
|
6266
6737
|
width: "100%",
|
|
6267
6738
|
...style
|
|
6268
6739
|
},
|
|
6740
|
+
direction: "none",
|
|
6269
6741
|
...other,
|
|
6270
6742
|
children: props.children
|
|
6271
6743
|
})
|
|
@@ -6581,171 +7053,44 @@ const SbApi = registerEntity(SbEntityType.API, { propertiesDefinition }, ({ onSu
|
|
|
6581
7053
|
const Spinner = styled.span`
|
|
6582
7054
|
width: 50px;
|
|
6583
7055
|
height: 50px;
|
|
6584
|
-
border: 4px solid #e0e1e5;
|
|
6585
|
-
border-bottom-color: #8c95a1;
|
|
6586
|
-
border-radius: 50%;
|
|
6587
|
-
display: inline-block;
|
|
6588
|
-
box-sizing: border-box;
|
|
6589
|
-
animation: rotation 0.5s linear infinite;
|
|
6590
|
-
|
|
6591
|
-
@keyframes rotation {
|
|
6592
|
-
0% {
|
|
6593
|
-
transform: rotate(0deg);
|
|
6594
|
-
}
|
|
6595
|
-
100% {
|
|
6596
|
-
transform: rotate(360deg);
|
|
6597
|
-
}
|
|
6598
|
-
}
|
|
6599
|
-
`;
|
|
6600
|
-
const FullPageSpinner = () => {
|
|
6601
|
-
return /* @__PURE__ */ jsx("div", {
|
|
6602
|
-
style: {
|
|
6603
|
-
display: "flex",
|
|
6604
|
-
justifyContent: "center",
|
|
6605
|
-
alignItems: "center",
|
|
6606
|
-
height: "100svh",
|
|
6607
|
-
width: "100%"
|
|
6608
|
-
},
|
|
6609
|
-
children: /* @__PURE__ */ jsx(Spinner, {})
|
|
6610
|
-
});
|
|
6611
|
-
};
|
|
6612
|
-
|
|
6613
|
-
//#endregion
|
|
6614
|
-
//#region src/lib/internal-details/lib/features/injected-features.ts
|
|
6615
|
-
function useGetCurrentUserQuery() {
|
|
6616
|
-
return useMemo(() => {
|
|
6617
|
-
return {
|
|
6618
|
-
isLoading: false,
|
|
6619
|
-
data: { user: { name: "Test User" } }
|
|
6620
|
-
};
|
|
6621
|
-
}, []);
|
|
6622
|
-
}
|
|
6623
|
-
|
|
6624
|
-
//#endregion
|
|
6625
|
-
//#region src/edit-mode/dnd/is-nestable.ts
|
|
6626
|
-
function isNestable(componentType, _parentType) {
|
|
6627
|
-
if (componentType === PAGE_COMPONENT_TYPE) return false;
|
|
6628
|
-
return true;
|
|
6629
|
-
}
|
|
6630
|
-
|
|
6631
|
-
//#endregion
|
|
6632
|
-
//#region src/edit-mode/create-component.ts
|
|
6633
|
-
function getParentInfo(parent) {
|
|
6634
|
-
return { type: getEditStore().runtimeEntitiesManager.getAnyEditorWidgetMeta(parent.id)?.type };
|
|
6635
|
-
}
|
|
6636
|
-
const generateUniqueName = (componentType) => {
|
|
6637
|
-
const baseName = componentType;
|
|
6638
|
-
let counter = 1;
|
|
6639
|
-
let name = `${baseName}${counter}`;
|
|
6640
|
-
while (root_store_default.nameManager.hasEntityWithName(name)) {
|
|
6641
|
-
counter++;
|
|
6642
|
-
name = `${baseName}${counter}`;
|
|
6643
|
-
}
|
|
6644
|
-
return name;
|
|
6645
|
-
};
|
|
6646
|
-
function getBinding({ componentType, editorTemplateCreateRequest }) {
|
|
6647
|
-
if (editorTemplateCreateRequest?.generateBinding === true) return Property$1.Static(generateUniqueName(componentType));
|
|
6648
|
-
else if (typeof editorTemplateCreateRequest?.generateBinding === "string") return Property$1.Static(editorTemplateCreateRequest.generateBinding);
|
|
6649
|
-
else return;
|
|
6650
|
-
}
|
|
6651
|
-
function getComponentBaseProperties(componentType, _parentInfo, editorTemplateCreateRequest) {
|
|
6652
|
-
let properties = {};
|
|
6653
|
-
const editorTemplates = root_store_default.componentRegistry.getEditorTemplates(componentType);
|
|
6654
|
-
if (editorTemplates && editorTemplates.length > 1) throw new Error(`Multiple editor templates are not supported yet. Found ${editorTemplates.length} for component type: ${componentType}.`);
|
|
6655
|
-
if (editorTemplateCreateRequest?.properties) properties = {
|
|
6656
|
-
...properties,
|
|
6657
|
-
...editorTemplateCreateRequest.properties
|
|
6658
|
-
};
|
|
6659
|
-
const binding = getBinding({
|
|
6660
|
-
componentType,
|
|
6661
|
-
editorTemplateCreateRequest
|
|
6662
|
-
});
|
|
6663
|
-
if (binding) properties.name = binding;
|
|
6664
|
-
const { width, height, size: size$1 } = properties;
|
|
6665
|
-
const safeDimensions = filterSafeStackDimensionProperties({
|
|
6666
|
-
width: width?.value,
|
|
6667
|
-
height: height?.value,
|
|
6668
|
-
size: size$1?.value
|
|
6669
|
-
});
|
|
6670
|
-
return {
|
|
6671
|
-
properties: {
|
|
6672
|
-
...properties,
|
|
6673
|
-
...safeDimensions
|
|
6674
|
-
},
|
|
6675
|
-
children: editorTemplateCreateRequest?.children ?? []
|
|
6676
|
-
};
|
|
6677
|
-
}
|
|
6678
|
-
function getCreateAtParentElement(relativeParent, createAt) {
|
|
6679
|
-
if (createAt === "root") {
|
|
6680
|
-
const parentInstanceId = getEditStore().runtimeEntitiesManager.widgets.getAnyInstanceIdForSourceId(relativeParent.id);
|
|
6681
|
-
const pageComponent = getEditStore().runtimeEntitiesManager.getClosestAncestorByType(parentInstanceId, "Page");
|
|
6682
|
-
if (!pageComponent) throw new Error(`Page component not found for parent: ${relativeParent.id}`);
|
|
6683
|
-
return { source: { id: pageComponent.sourceId } };
|
|
6684
|
-
} else return { source: relativeParent };
|
|
6685
|
-
}
|
|
6686
|
-
async function createComponent({ componentType, parent, scopeName, baseProperties = {}, skipSecondaryComponentsCreation, otherComponentsUpdates }) {
|
|
6687
|
-
const parentInfo = getParentInfo(parent);
|
|
6688
|
-
if (!isNestable(componentType, parentInfo.type)) {
|
|
6689
|
-
console.error(`${componentType} cannot be nested under ${parentInfo.type}`);
|
|
6690
|
-
return;
|
|
6691
|
-
}
|
|
6692
|
-
const editorTemplates = root_store_default.componentRegistry.getEditorTemplates(componentType);
|
|
6693
|
-
if (editorTemplates && editorTemplates.length > 1) throw new Error(`Multiple editor templates are not supported yet. Found ${editorTemplates.length} for component type: ${componentType}.`);
|
|
6694
|
-
const context$1 = {
|
|
6695
|
-
generateUniqueName,
|
|
6696
|
-
parentInfo,
|
|
6697
|
-
defaultTagNames: root_store_default.componentRegistry.defaultTagNames,
|
|
6698
|
-
selfTagName: componentType
|
|
6699
|
-
};
|
|
6700
|
-
const editorTemplateCreateRequest = editorTemplates?.[0]?.create?.(context$1);
|
|
6701
|
-
const primaryEditorTemplateCreateRequest = Array.isArray(editorTemplateCreateRequest) ? editorTemplateCreateRequest[0] : editorTemplateCreateRequest;
|
|
6702
|
-
if (editorTemplateCreateRequest && primaryEditorTemplateCreateRequest?.type !== componentType) throw new Error(`When defining a ${Array.isArray(editorTemplateCreateRequest) ? "multiple" : "single"} component to be created on an EditorTemplate, the type must match with the component being created. got: ${primaryEditorTemplateCreateRequest?.type} when it should have been ${componentType}`);
|
|
6703
|
-
const editorTemplateCreateRequests = Array.isArray(editorTemplateCreateRequest) ? editorTemplateCreateRequest : [editorTemplateCreateRequest];
|
|
6704
|
-
const editStore = getEditStore();
|
|
6705
|
-
function editorTemplateCreateRequestToInternalCreateRequest({ editorTemplateCreateRequest: editorTemplateCreateRequest$1, baseProperties: baseProperties$1 }) {
|
|
6706
|
-
const type = editorTemplateCreateRequest$1?.type ?? componentType;
|
|
6707
|
-
const { properties: propertiesFromType, children } = getComponentBaseProperties(type, parentInfo, editorTemplateCreateRequest$1);
|
|
6708
|
-
const properties = {
|
|
6709
|
-
...propertiesFromType,
|
|
6710
|
-
...baseProperties$1
|
|
6711
|
-
};
|
|
7056
|
+
border: 4px solid #e0e1e5;
|
|
7057
|
+
border-bottom-color: #8c95a1;
|
|
7058
|
+
border-radius: 50%;
|
|
7059
|
+
display: inline-block;
|
|
7060
|
+
box-sizing: border-box;
|
|
7061
|
+
animation: rotation 0.5s linear infinite;
|
|
7062
|
+
|
|
7063
|
+
@keyframes rotation {
|
|
7064
|
+
0% {
|
|
7065
|
+
transform: rotate(0deg);
|
|
7066
|
+
}
|
|
7067
|
+
100% {
|
|
7068
|
+
transform: rotate(360deg);
|
|
7069
|
+
}
|
|
7070
|
+
}
|
|
7071
|
+
`;
|
|
7072
|
+
const FullPageSpinner = () => {
|
|
7073
|
+
return /* @__PURE__ */ jsx("div", {
|
|
7074
|
+
style: {
|
|
7075
|
+
display: "flex",
|
|
7076
|
+
justifyContent: "center",
|
|
7077
|
+
alignItems: "center",
|
|
7078
|
+
height: "100svh",
|
|
7079
|
+
width: "100%"
|
|
7080
|
+
},
|
|
7081
|
+
children: /* @__PURE__ */ jsx(Spinner, {})
|
|
7082
|
+
});
|
|
7083
|
+
};
|
|
7084
|
+
|
|
7085
|
+
//#endregion
|
|
7086
|
+
//#region src/lib/internal-details/lib/features/injected-features.ts
|
|
7087
|
+
function useGetCurrentUserQuery() {
|
|
7088
|
+
return useMemo(() => {
|
|
6712
7089
|
return {
|
|
6713
|
-
|
|
6714
|
-
|
|
6715
|
-
properties,
|
|
6716
|
-
children,
|
|
6717
|
-
scopeName,
|
|
6718
|
-
id: editStore.operationManager.generateSourceId()
|
|
6719
|
-
};
|
|
6720
|
-
}
|
|
6721
|
-
const createRequests = editorTemplateCreateRequests.map((editorTemplateCreateRequest$1, index) => editorTemplateCreateRequestToInternalCreateRequest({
|
|
6722
|
-
editorTemplateCreateRequest: editorTemplateCreateRequest$1,
|
|
6723
|
-
baseProperties: index === 0 ? baseProperties : {}
|
|
6724
|
-
}));
|
|
6725
|
-
const hasOtherComponentsUpdates = otherComponentsUpdates && Object.keys(otherComponentsUpdates).length > 0;
|
|
6726
|
-
const hasMultipleCreateComponents = editorTemplateCreateRequests.length > 1 && !skipSecondaryComponentsCreation;
|
|
6727
|
-
if (hasOtherComponentsUpdates || hasMultipleCreateComponents) {
|
|
6728
|
-
const performOtherComponentsUpdates = (otherComponentsUpdates$1) => {
|
|
6729
|
-
Object.entries(otherComponentsUpdates$1).forEach(([sourceId, updates]) => {
|
|
6730
|
-
editStore.operationManager.setWidgetProperties({
|
|
6731
|
-
sourceId,
|
|
6732
|
-
properties: updates
|
|
6733
|
-
});
|
|
6734
|
-
});
|
|
7090
|
+
isLoading: false,
|
|
7091
|
+
data: { user: { name: "Test User" } }
|
|
6735
7092
|
};
|
|
6736
|
-
|
|
6737
|
-
if (skipSecondaryComponentsCreation) editStore.operationManager.createComponent(createRequests[0]);
|
|
6738
|
-
else createRequests.forEach((createRequest) => {
|
|
6739
|
-
editStore.operationManager.createComponent(createRequest);
|
|
6740
|
-
});
|
|
6741
|
-
if (hasOtherComponentsUpdates) performOtherComponentsUpdates(otherComponentsUpdates);
|
|
6742
|
-
});
|
|
6743
|
-
} else editStore.operationManager.createComponent(createRequests[0]);
|
|
6744
|
-
/**
|
|
6745
|
-
* Returns the single id, or the the last component if there are multiple.
|
|
6746
|
-
* See EditorTemplate's definition to understand why.
|
|
6747
|
-
*/
|
|
6748
|
-
return createRequests.at(-1).id;
|
|
7093
|
+
}, []);
|
|
6749
7094
|
}
|
|
6750
7095
|
|
|
6751
7096
|
//#endregion
|
|
@@ -6769,7 +7114,7 @@ const fixCursorSnapOffset = (args) => {
|
|
|
6769
7114
|
const sortedCollisions = rectIntersection(updated).filter((collision) => {
|
|
6770
7115
|
const activeRootInstanceId = editStore.interactionLayerManager.activeRootInstanceId;
|
|
6771
7116
|
if (!activeRootInstanceId) return true;
|
|
6772
|
-
return collision.id === activeRootInstanceId ||
|
|
7117
|
+
return collision.id === activeRootInstanceId || editStore.runtimeEntitiesManager.isChildOf(collision.id, activeRootInstanceId);
|
|
6773
7118
|
}).map((collision) => {
|
|
6774
7119
|
const rect = collision.data?.droppableContainer?.rect.current;
|
|
6775
7120
|
const pointerInside = rect && x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
|
|
@@ -6824,184 +7169,6 @@ const bubblingToParentIfFar = (args) => {
|
|
|
6824
7169
|
};
|
|
6825
7170
|
var collision_detection_default = fixCursorSnapOffset;
|
|
6826
7171
|
|
|
6827
|
-
//#endregion
|
|
6828
|
-
//#region src/edit-mode/dnd/handle-stack-drop.ts
|
|
6829
|
-
const mergeDroppedDimensions = (draggedType, draggedProps, activeDragRect) => {
|
|
6830
|
-
const safeExistingDimensions = filterSafeStackDimensionProperties({
|
|
6831
|
-
width: draggedProps?.width,
|
|
6832
|
-
height: draggedProps?.height,
|
|
6833
|
-
size: draggedProps?.size
|
|
6834
|
-
});
|
|
6835
|
-
const width = safeExistingDimensions.width;
|
|
6836
|
-
const height = safeExistingDimensions.height;
|
|
6837
|
-
if (draggedType === "Icon") return { size: safeExistingDimensions.size ?? (activeDragRect?.height ? Property$1.Dimension(Dim$1.px(activeDragRect.height)) : Property$1.Static("")) };
|
|
6838
|
-
return {
|
|
6839
|
-
width,
|
|
6840
|
-
height
|
|
6841
|
-
};
|
|
6842
|
-
};
|
|
6843
|
-
const handleStackDropWithinCanvas = (params) => {
|
|
6844
|
-
const { dropInfo, draggedId, dropTargetId } = params;
|
|
6845
|
-
const editStore = getEditStore();
|
|
6846
|
-
const dropSourceId = editStore.runtimeEntitiesManager.getEditorWidgetSourceId(dropTargetId);
|
|
6847
|
-
const draggedSourceId = editStore.runtimeEntitiesManager.getEditorWidgetSourceId(draggedId);
|
|
6848
|
-
if (!dropSourceId || !draggedSourceId) throw new Error(`Missing IDs: dragging ${draggedId} to ${dropTargetId}`);
|
|
6849
|
-
console.log(`Dragged ${draggedSourceId} to ${dropSourceId}`, {
|
|
6850
|
-
dropInfo,
|
|
6851
|
-
index: dropInfo.insertionIndex
|
|
6852
|
-
});
|
|
6853
|
-
if (dropInfo.noopDrop) return;
|
|
6854
|
-
const draggedType = editStore.runtimeEntitiesManager.getEditorWidgetType(draggedId);
|
|
6855
|
-
if (!draggedType) throw new Error(`Missing dragged type: ${draggedId}`);
|
|
6856
|
-
const activeDragRect = editStore.ui.dnd.activeDragRect;
|
|
6857
|
-
const draggedProps = editStore.runtimeEntitiesManager.getEditorWidgetMeta(draggedId)?.props;
|
|
6858
|
-
editStore.operationManager.dropComponent({
|
|
6859
|
-
from: { source: { id: draggedSourceId } },
|
|
6860
|
-
to: { source: {
|
|
6861
|
-
id: dropSourceId,
|
|
6862
|
-
index: dropInfo.insertionIndex
|
|
6863
|
-
} },
|
|
6864
|
-
propsToChange: { ...mergeDroppedDimensions(draggedType, draggedProps, activeDragRect) }
|
|
6865
|
-
});
|
|
6866
|
-
};
|
|
6867
|
-
const handleStackDropForNewComponent = ({ componentType, dropInfo, dropTargetId }) => {
|
|
6868
|
-
const editStore = getEditStore();
|
|
6869
|
-
const dropSourceId = editStore.runtimeEntitiesManager.getEditorWidgetSourceId(dropTargetId);
|
|
6870
|
-
const dropScopeId = editStore.runtimeEntitiesManager.getEditorWidgetScopeId(dropTargetId);
|
|
6871
|
-
if (!dropSourceId || !dropScopeId) throw new Error("Missing drop source id");
|
|
6872
|
-
const scopeName = root_store_default.entityManager.getScopeName(dropScopeId);
|
|
6873
|
-
return createComponent({
|
|
6874
|
-
componentType,
|
|
6875
|
-
parent: {
|
|
6876
|
-
index: dropInfo.insertionIndex,
|
|
6877
|
-
id: dropSourceId
|
|
6878
|
-
},
|
|
6879
|
-
scopeName
|
|
6880
|
-
});
|
|
6881
|
-
};
|
|
6882
|
-
const handleStackDrop = async ({ dropInfo, draggedId, dropTargetId, isDraggingNewComponent, newComponentType }) => {
|
|
6883
|
-
if (dropInfo.insertionIndex == null) throw new Error("No insertion index found");
|
|
6884
|
-
if (isDraggingNewComponent) {
|
|
6885
|
-
if (!newComponentType) throw new Error("Missing componentType to create new component");
|
|
6886
|
-
return handleStackDropForNewComponent({
|
|
6887
|
-
componentType: newComponentType,
|
|
6888
|
-
dropTargetId,
|
|
6889
|
-
dropInfo
|
|
6890
|
-
});
|
|
6891
|
-
} else {
|
|
6892
|
-
if (!draggedId) throw new Error("Missing dragged id");
|
|
6893
|
-
handleStackDropWithinCanvas({
|
|
6894
|
-
dropInfo,
|
|
6895
|
-
draggedId,
|
|
6896
|
-
dropTargetId
|
|
6897
|
-
});
|
|
6898
|
-
}
|
|
6899
|
-
};
|
|
6900
|
-
|
|
6901
|
-
//#endregion
|
|
6902
|
-
//#region src/edit-mode/dnd/hooks/use-handle-dnd-events.ts
|
|
6903
|
-
const measureRect = (id) => {
|
|
6904
|
-
const rect = id ? getBoundingBoxForWidget(id) : null;
|
|
6905
|
-
if (!rect) return null;
|
|
6906
|
-
return {
|
|
6907
|
-
left: rect.left,
|
|
6908
|
-
top: rect.top,
|
|
6909
|
-
right: rect.right,
|
|
6910
|
-
bottom: rect.bottom,
|
|
6911
|
-
width: rect.width,
|
|
6912
|
-
height: rect.height
|
|
6913
|
-
};
|
|
6914
|
-
};
|
|
6915
|
-
const useHandleDnDEvents = () => {
|
|
6916
|
-
const setActiveDragRect = useMemo(() => {
|
|
6917
|
-
const editStore = getEditStore();
|
|
6918
|
-
const throttled = throttle((rect) => {
|
|
6919
|
-
editStore.ui.dnd.setActiveDragRect(rect);
|
|
6920
|
-
}, 10, {
|
|
6921
|
-
leading: true,
|
|
6922
|
-
trailing: true
|
|
6923
|
-
});
|
|
6924
|
-
return (val) => {
|
|
6925
|
-
throttled(val);
|
|
6926
|
-
};
|
|
6927
|
-
}, []);
|
|
6928
|
-
const setActiveTargetInfo = useMemo(() => {
|
|
6929
|
-
const editStore = getEditStore();
|
|
6930
|
-
const throttled = throttle((id, rect) => {
|
|
6931
|
-
editStore.ui.dnd.setDropTargetId(id);
|
|
6932
|
-
editStore.ui.dnd.setActiveTargetRect(rect);
|
|
6933
|
-
}, 10, {
|
|
6934
|
-
leading: true,
|
|
6935
|
-
trailing: true
|
|
6936
|
-
});
|
|
6937
|
-
return (id, val) => {
|
|
6938
|
-
throttled(id, val);
|
|
6939
|
-
};
|
|
6940
|
-
}, []);
|
|
6941
|
-
useDndMonitor({
|
|
6942
|
-
onDragStart: useCallback((event) => {
|
|
6943
|
-
const editStore = getEditStore();
|
|
6944
|
-
if (!event.active?.data.current && !editStore.ui.dnd.isDraggingNewComponent) {
|
|
6945
|
-
console.error("No active widget data");
|
|
6946
|
-
return;
|
|
6947
|
-
}
|
|
6948
|
-
editStore.ui.dnd.setDropTargetId(null);
|
|
6949
|
-
editStore.ui.dnd.setIsDragging(true);
|
|
6950
|
-
if (editStore.ui.dnd.isDraggingNewComponent) {
|
|
6951
|
-
editStore.ui.selectWidget(null);
|
|
6952
|
-
editStore.ui.dnd.resizePageIfNeeded();
|
|
6953
|
-
} else editStore.ui.selectWidget(event.active?.id ? event.active.id : null, event.activatorEvent?.shiftKey);
|
|
6954
|
-
}, []),
|
|
6955
|
-
onDragMove: useCallback((event) => {
|
|
6956
|
-
setActiveTargetInfo(event.over?.id ?? null, event.over?.rect ?? null);
|
|
6957
|
-
const collisionRect = event.collisions?.[0]?.data?.injectedCollisionRect;
|
|
6958
|
-
if (collisionRect) setActiveDragRect(collisionRect);
|
|
6959
|
-
else setActiveDragRect(null);
|
|
6960
|
-
}, [setActiveDragRect, setActiveTargetInfo]),
|
|
6961
|
-
onDragOver: useCallback((event) => {
|
|
6962
|
-
const overId = event.over?.id ? String(event.over?.id) : null;
|
|
6963
|
-
setActiveTargetInfo(overId, measureRect(overId));
|
|
6964
|
-
}, [setActiveTargetInfo]),
|
|
6965
|
-
onDragCancel: useCallback((_event) => {
|
|
6966
|
-
const editStore = getEditStore();
|
|
6967
|
-
editStore.ui.dnd.setIsDragging(false);
|
|
6968
|
-
editStore.ui.dnd.cancelNewComponentDrag();
|
|
6969
|
-
}, []),
|
|
6970
|
-
onDragEnd: useCallback(async (event) => {
|
|
6971
|
-
const editStore = getEditStore();
|
|
6972
|
-
let possibleNewComponentId;
|
|
6973
|
-
try {
|
|
6974
|
-
if (!editStore.ui.dnd.isProspectiveDropValid) {
|
|
6975
|
-
editorBridge.sendNotification("error", "You cannot drop a component here.");
|
|
6976
|
-
return;
|
|
6977
|
-
}
|
|
6978
|
-
const dropTargetId = event.over?.id ? String(event.over.id) : null;
|
|
6979
|
-
const draggedId = event.active?.id ? String(event.active?.id) : null;
|
|
6980
|
-
if (dropTargetId !== editStore.ui.dnd.dropTargetId) throw new Error("Drop target id and drag over id do not match");
|
|
6981
|
-
if (!dropTargetId) throw new Error("No drop target id");
|
|
6982
|
-
if (editStore.ui.dnd.isDropTargetStackLike) {
|
|
6983
|
-
const dropInfo = editStore.ui.dnd.stack.refreshPositionsAndGetDropIndex();
|
|
6984
|
-
possibleNewComponentId = await handleStackDrop({
|
|
6985
|
-
dropInfo,
|
|
6986
|
-
isDraggingNewComponent: editStore.ui.dnd.isDraggingNewComponent,
|
|
6987
|
-
newComponentType: editStore.ui.dnd.dragToCanvasComponentType,
|
|
6988
|
-
dropTargetId,
|
|
6989
|
-
draggedId
|
|
6990
|
-
});
|
|
6991
|
-
} else throw new Error("Grid is no longer supported");
|
|
6992
|
-
} catch (e) {
|
|
6993
|
-
console.error("Error dropping item", e);
|
|
6994
|
-
} finally {
|
|
6995
|
-
runInAction(() => {
|
|
6996
|
-
editStore.ui.dnd.setIsDragging(false);
|
|
6997
|
-
editStore.ui.dnd.cancelNewComponentDrag();
|
|
6998
|
-
if (possibleNewComponentId) editStore.ui.selectNewComponentBySourceId(possibleNewComponentId);
|
|
6999
|
-
});
|
|
7000
|
-
}
|
|
7001
|
-
}, [])
|
|
7002
|
-
});
|
|
7003
|
-
};
|
|
7004
|
-
|
|
7005
7172
|
//#endregion
|
|
7006
7173
|
//#region src/edit-mode/dnd/dnd-provider.tsx
|
|
7007
7174
|
const pointerConfig = { activationConstraint: { distance: 10 } };
|
|
@@ -7016,18 +7183,14 @@ var CustomPointerSensor = class extends PointerSensor {
|
|
|
7016
7183
|
}
|
|
7017
7184
|
}];
|
|
7018
7185
|
};
|
|
7019
|
-
const DragHandlerComponent = () => {
|
|
7020
|
-
useHandleDnDEvents();
|
|
7021
|
-
return null;
|
|
7022
|
-
};
|
|
7023
7186
|
const DnDProvider = (props) => {
|
|
7024
7187
|
const pointerSensor = useSensor(PointerSensor, pointerConfig);
|
|
7025
7188
|
const customPointerSensor = useSensor(CustomPointerSensor);
|
|
7026
7189
|
const sensors = useSensors(pointerSensor, customPointerSensor);
|
|
7027
|
-
return /* @__PURE__ */
|
|
7190
|
+
return /* @__PURE__ */ jsx(DndContext, {
|
|
7028
7191
|
sensors,
|
|
7029
7192
|
collisionDetection: collision_detection_default,
|
|
7030
|
-
children:
|
|
7193
|
+
children: props.children
|
|
7031
7194
|
});
|
|
7032
7195
|
};
|
|
7033
7196
|
|
|
@@ -7169,16 +7332,9 @@ var InteractionLayerManager = class {
|
|
|
7169
7332
|
* if set to the detached component id, the interaction layer will be disabled on the page
|
|
7170
7333
|
*/
|
|
7171
7334
|
activeRootInstanceId = void 0;
|
|
7172
|
-
interactionLayerInstanceIds = /* @__PURE__ */ new Set();
|
|
7173
7335
|
constructor() {
|
|
7174
7336
|
makeAutoObservable(this);
|
|
7175
7337
|
}
|
|
7176
|
-
@action addInteractionLayerInstanceId(instanceId) {
|
|
7177
|
-
this.interactionLayerInstanceIds.add(instanceId);
|
|
7178
|
-
}
|
|
7179
|
-
@action removeInteractionLayerInstanceId(instanceId) {
|
|
7180
|
-
this.interactionLayerInstanceIds.delete(instanceId);
|
|
7181
|
-
}
|
|
7182
7338
|
@action setActiveRootInstanceId(rootInstanceId) {
|
|
7183
7339
|
this.activeRootInstanceId = rootInstanceId;
|
|
7184
7340
|
}
|
|
@@ -8069,8 +8225,7 @@ var RuntimeEntitiesManager = class {
|
|
|
8069
8225
|
this.entitiesWithLocalBindings = new Set(entities);
|
|
8070
8226
|
}
|
|
8071
8227
|
doesEntityHaveLocalBindings(entity) {
|
|
8072
|
-
|
|
8073
|
-
return entitySourceId && this.entitiesWithLocalBindings.has(entitySourceId);
|
|
8228
|
+
return this.entitiesWithLocalBindings.has(entity);
|
|
8074
8229
|
}
|
|
8075
8230
|
getOptimisticWidgetChildrenIds(instanceId) {
|
|
8076
8231
|
return this.getChildrenWithOptimisticUpdates(instanceId).reduce((acc, child) => {
|
|
@@ -8552,36 +8707,14 @@ var DragAndDropManager = class {
|
|
|
8552
8707
|
const draggedInstanceId = this.root.editStore.ui.getSelectedInstanceIds()[0];
|
|
8553
8708
|
return draggedInstanceId ? getEditStore().runtimeEntitiesManager.getEditorWidgetType(draggedInstanceId) : void 0;
|
|
8554
8709
|
}
|
|
8555
|
-
get draggedWidgetInstanceId() {
|
|
8556
|
-
if (this.isDraggingNewComponent) return;
|
|
8557
|
-
return this.root.editStore.ui.getSelectedInstanceIds()[0];
|
|
8558
|
-
}
|
|
8559
8710
|
get dragToCanvasComponentType() {
|
|
8560
8711
|
return this._dragToCanvasComponentType;
|
|
8561
8712
|
}
|
|
8562
8713
|
get validRootIds() {
|
|
8563
8714
|
return this._validRootIds;
|
|
8564
8715
|
}
|
|
8565
|
-
get
|
|
8566
|
-
|
|
8567
|
-
const draggedInstanceId = this.draggedWidgetInstanceId;
|
|
8568
|
-
if (!dropTargetInstanceId) return false;
|
|
8569
|
-
const isDraggingNewComponent = this.isDraggingNewComponent;
|
|
8570
|
-
if (!areDragAndDropInstancesValid({
|
|
8571
|
-
dropTargetInstanceId,
|
|
8572
|
-
draggedInstanceId,
|
|
8573
|
-
isDraggingNewComponent
|
|
8574
|
-
})) return false;
|
|
8575
|
-
const draggedType = this.draggedWidgetType;
|
|
8576
|
-
const dropTargetType = this.dropTargetWidgetType;
|
|
8577
|
-
if (!draggedType || !dropTargetType) return false;
|
|
8578
|
-
const dropTargetEmpty = (dropTargetInstanceId && getEditStore().runtimeEntitiesManager.getEditorWidgetMeta(dropTargetInstanceId)?.children?.length === 0) ?? true;
|
|
8579
|
-
return isDragAndDropTypeValid({
|
|
8580
|
-
draggedType,
|
|
8581
|
-
dropTargetType,
|
|
8582
|
-
isDraggingNewComponent,
|
|
8583
|
-
dropTargetEmpty
|
|
8584
|
-
});
|
|
8716
|
+
get invalidDropTarget() {
|
|
8717
|
+
return this._invalidDropTarget;
|
|
8585
8718
|
}
|
|
8586
8719
|
canDragWidget(instanceId) {
|
|
8587
8720
|
const editStore = getEditStore();
|
|
@@ -8610,6 +8743,7 @@ var DragAndDropManager = class {
|
|
|
8610
8743
|
this._activeDragRect = null;
|
|
8611
8744
|
this._activeTargetRect = null;
|
|
8612
8745
|
this._validRootIds = null;
|
|
8746
|
+
this._invalidDropTarget = false;
|
|
8613
8747
|
}
|
|
8614
8748
|
}
|
|
8615
8749
|
/**
|
|
@@ -8652,6 +8786,9 @@ var DragAndDropManager = class {
|
|
|
8652
8786
|
@action setValidRootIds(ids) {
|
|
8653
8787
|
this._validRootIds = ids;
|
|
8654
8788
|
}
|
|
8789
|
+
@action setInvalidDropTarget(invalid) {
|
|
8790
|
+
this._invalidDropTarget = invalid;
|
|
8791
|
+
}
|
|
8655
8792
|
@action setDropTargetId(id) {
|
|
8656
8793
|
this._dropTargetInstanceId = id;
|
|
8657
8794
|
if (id == null) this._activeTargetRect = null;
|
|
@@ -9925,8 +10062,9 @@ const SbProvider = function SbProvider$1({ name = "codemode", settings, children
|
|
|
9925
10062
|
}, [runApiInitialization]);
|
|
9926
10063
|
useEffect(() => {
|
|
9927
10064
|
const mergedTheme = merge(BASE_THEME_V5, settings?.theme);
|
|
9928
|
-
const
|
|
9929
|
-
|
|
10065
|
+
const generatedTheme = generateTheme(mergedTheme, settings?.themeOverrides);
|
|
10066
|
+
editorBridge.updateTheme(mergedTheme, generatedTheme);
|
|
10067
|
+
setUserAccessibleTheme(generatedTheme);
|
|
9930
10068
|
}, [settings?.theme, settings?.themeOverrides]);
|
|
9931
10069
|
useEffect(() => {
|
|
9932
10070
|
const resolvePromiseListener = (event) => {
|
|
@@ -10245,7 +10383,7 @@ function useDialogEditing(props) {
|
|
|
10245
10383
|
const selectedInstanceId = features.selectWidget.value;
|
|
10246
10384
|
useEffect(() => {
|
|
10247
10385
|
if (isEditing && instanceId) if (isOpen) {
|
|
10248
|
-
if (!selectedInstanceId || selectedInstanceId !== instanceId && !
|
|
10386
|
+
if (!selectedInstanceId || selectedInstanceId !== instanceId && !getEditStore().runtimeEntitiesManager.isChildOf(selectedInstanceId, instanceId))
|
|
10249
10387
|
/**
|
|
10250
10388
|
* If the dialog is open and the dialog or its children are not selected, then select it.
|
|
10251
10389
|
* This happens when an event handler changes the open state of the dialog.
|
|
@@ -10261,10 +10399,10 @@ function useDialogEditing(props) {
|
|
|
10261
10399
|
if (isEditing && instanceId) {
|
|
10262
10400
|
if (prevIsOpenRef.current !== isOpen && !(prevIsOpenRef.current === void 0 && isOpen === false)) return;
|
|
10263
10401
|
if (isOpen) {
|
|
10264
|
-
if (selectedInstanceId && selectedInstanceId !== instanceId && !
|
|
10402
|
+
if (selectedInstanceId && selectedInstanceId !== instanceId && !getEditStore().runtimeEntitiesManager.isChildOf(selectedInstanceId, instanceId)) update((entity) => {
|
|
10265
10403
|
set(entity, isOpenPropertyName, false);
|
|
10266
10404
|
});
|
|
10267
|
-
} else if (selectedInstanceId === instanceId || selectedInstanceId &&
|
|
10405
|
+
} else if (selectedInstanceId === instanceId || selectedInstanceId && getEditStore().runtimeEntitiesManager.isChildOf(selectedInstanceId, instanceId)) update((entity) => {
|
|
10268
10406
|
set(entity, isOpenPropertyName, true);
|
|
10269
10407
|
});
|
|
10270
10408
|
}
|
|
@@ -11287,10 +11425,7 @@ function DroppableContainer({ name, componentType, isOpen, children, layout, cla
|
|
|
11287
11425
|
ref: dropTargetRef,
|
|
11288
11426
|
id: getEditWrapperIdWithType(instanceId, componentType),
|
|
11289
11427
|
style: EXPANDED,
|
|
11290
|
-
children: [/* @__PURE__ */ jsx(
|
|
11291
|
-
instanceId,
|
|
11292
|
-
children: internalContainer
|
|
11293
|
-
}), isOpen && /* @__PURE__ */ jsx(interaction_layer_default, {
|
|
11428
|
+
children: [internalContainer, isOpen && /* @__PURE__ */ jsx(interaction_layer_default, {
|
|
11294
11429
|
rootType: componentType,
|
|
11295
11430
|
rootInstanceId: instanceId,
|
|
11296
11431
|
rootName: name
|