@threekit-tools/treble 0.0.92 → 0.0.94-next-01
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/Treble/Treble.d.ts +2 -2
- package/dist/Treble/Treble.js +2 -2
- package/dist/Treble/index.d.ts +1 -1
- package/dist/Treble/index.js +1 -1
- package/dist/Treble/snapshot.d.ts +2 -2
- package/dist/Treble/snapshot.js +1 -1
- package/dist/hooks/useNestedConfigurator/index.js +1 -2
- package/dist/hooks/useSnapshot/index.d.ts +1 -1
- package/dist/hooks/useSpaces/SpacesState.d.ts +15 -2
- package/dist/hooks/useSpaces/SpacesState.js +85 -22
- package/dist/hooks/useSpaces/constants.d.ts +17 -2
- package/dist/hooks/useSpaces/constants.js +58 -37
- package/dist/hooks/useSpaces/dataHandlers.d.ts +22 -4
- package/dist/hooks/useSpaces/dataHandlers.js +197 -40
- package/dist/hooks/useSpaces/draw/drawDoors.js +1 -1
- package/dist/hooks/useSpaces/draw/drawGrid.d.ts +1 -1
- package/dist/hooks/useSpaces/draw/drawGrid.js +4 -1
- package/dist/hooks/useSpaces/draw/drawWalls.d.ts +3 -2
- package/dist/hooks/useSpaces/draw/drawWalls.js +6 -4
- package/dist/hooks/useSpaces/index.d.ts +13 -0
- package/dist/hooks/useSpaces/index.js +269 -126
- package/dist/hooks/useSpaces/types.d.ts +52 -13
- package/dist/icons/Boundary.d.ts +3 -0
- package/dist/icons/{Ruler copy.js → Boundary.js} +7 -8
- package/dist/icons/Draw.js +3 -3
- package/dist/icons/RulerBlank.js +2 -2
- package/dist/icons/RulerDetailed.js +2 -2
- package/dist/icons/Window.js +4 -4
- package/dist/icons/index.js +28 -0
- package/dist/index.d.ts +17 -2
- package/dist/index.js +35 -5
- package/dist/store/attributes.d.ts +2 -1
- package/dist/store/index.d.ts +41 -10
- package/dist/store/index.js +3 -1
- package/dist/store/product.js +4 -7
- package/dist/store/spaces.d.ts +32 -5
- package/dist/store/spaces.js +164 -7
- package/dist/store/treble.d.ts +1 -1
- package/dist/store/treble.js +14 -21
- package/dist/store/wishlist.d.ts +2 -20
- package/dist/types.d.ts +3 -1
- package/package.json +1 -2
- package/dist/Treble/snapshots.d.ts +0 -22
- package/dist/Treble/snapshots.js +0 -247
- package/dist/hooks/useRoomBuilder/RoomBuilderState.d.ts +0 -95
- package/dist/hooks/useRoomBuilder/RoomBuilderState.js +0 -1237
- package/dist/hooks/useRoomBuilder/constants.d.ts +0 -41
- package/dist/hooks/useRoomBuilder/constants.js +0 -48
- package/dist/hooks/useRoomBuilder/dataHandlers.d.ts +0 -18
- package/dist/hooks/useRoomBuilder/dataHandlers.js +0 -187
- package/dist/hooks/useRoomBuilder/draw.d.ts +0 -55
- package/dist/hooks/useRoomBuilder/draw.js +0 -573
- package/dist/hooks/useRoomBuilder/findLoops.d.ts +0 -5
- package/dist/hooks/useRoomBuilder/findLoops.js +0 -99
- package/dist/hooks/useRoomBuilder/geometry.d.ts +0 -33
- package/dist/hooks/useRoomBuilder/geometry.js +0 -325
- package/dist/hooks/useRoomBuilder/index.d.ts +0 -40
- package/dist/hooks/useRoomBuilder/index.js +0 -303
- package/dist/hooks/useRoomBuilder/messaging.d.ts +0 -8
- package/dist/hooks/useRoomBuilder/messaging.js +0 -18
- package/dist/hooks/useRoomBuilder/themes.d.ts +0 -12
- package/dist/hooks/useRoomBuilder/themes.js +0 -273
- package/dist/hooks/useRoomBuilder/types.d.ts +0 -238
- package/dist/hooks/useRoomBuilder/types.js +0 -36
- package/dist/hooks/useRoomBuilder/validators.d.ts +0 -36
- package/dist/hooks/useRoomBuilder/validators.js +0 -362
- package/dist/icons/Ruler copy.d.ts +0 -3
- package/dist/icons/RulerDetailed copy.d.ts +0 -3
- package/dist/icons/RulerDetailed copy.js +0 -27
|
@@ -10,28 +10,41 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (_) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
18
47
|
}
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}) : (function(o, m, k, k2) {
|
|
21
|
-
if (k2 === undefined) k2 = k;
|
|
22
|
-
o[k2] = m[k];
|
|
23
|
-
}));
|
|
24
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
-
}) : function(o, v) {
|
|
27
|
-
o["default"] = v;
|
|
28
|
-
});
|
|
29
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
-
if (mod && mod.__esModule) return mod;
|
|
31
|
-
var result = {};
|
|
32
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
-
__setModuleDefault(result, mod);
|
|
34
|
-
return result;
|
|
35
48
|
};
|
|
36
49
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
50
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
@@ -41,19 +54,27 @@ var react_1 = require("react");
|
|
|
41
54
|
var types_1 = require("./types");
|
|
42
55
|
var types_2 = require("./types");
|
|
43
56
|
var useConfigurator_1 = __importDefault(require("../useConfigurator"));
|
|
44
|
-
var SpacesState_1 = __importDefault(require("./SpacesState"));
|
|
45
57
|
var constants_1 = require("./constants");
|
|
46
|
-
var themes_1 =
|
|
58
|
+
var themes_1 = require("./themes");
|
|
47
59
|
var SpacesLayout_1 = __importDefault(require("./SpacesLayout"));
|
|
48
60
|
var store_1 = require("../../store");
|
|
49
61
|
var spaces_1 = require("../../store/spaces");
|
|
50
62
|
var useThreekitInitStatus_1 = __importDefault(require("../useThreekitInitStatus"));
|
|
63
|
+
var getLocalTouchPoint = function (touch, rect) {
|
|
64
|
+
if (touch.clientY < rect.top ||
|
|
65
|
+
rect.bottom < touch.clientY ||
|
|
66
|
+
touch.clientX < rect.left ||
|
|
67
|
+
rect.right < touch.clientX)
|
|
68
|
+
return undefined;
|
|
69
|
+
return [touch.clientX - rect.left, touch.clientY - rect.top];
|
|
70
|
+
};
|
|
51
71
|
var useSpaces = function (props) {
|
|
52
|
-
var _a;
|
|
72
|
+
var _a, _b, _c, _d, _e;
|
|
53
73
|
var attributesState = (0, useConfigurator_1.default)()[0];
|
|
54
74
|
var hasLoaded = (0, useThreekitInitStatus_1.default)();
|
|
55
75
|
var dispatch = (0, store_1.useThreekitDispatch)();
|
|
56
76
|
var layouts = (0, store_1.useThreekitSelector)(spaces_1.getLayouts);
|
|
77
|
+
var hasInitialized = (0, store_1.useThreekitSelector)(spaces_1.getInitialized);
|
|
57
78
|
var zoom = (0, store_1.useThreekitSelector)(spaces_1.getZoom);
|
|
58
79
|
var unit = (0, store_1.useThreekitSelector)(spaces_1.getUnit);
|
|
59
80
|
var translation = (0, store_1.useThreekitSelector)(spaces_1.getTranslation);
|
|
@@ -62,131 +83,176 @@ var useSpaces = function (props) {
|
|
|
62
83
|
var angleSnappingEnabled = (0, store_1.useThreekitSelector)(spaces_1.getAngleSnappingEnabled);
|
|
63
84
|
var guideSnappingEnabled = (0, store_1.useThreekitSelector)(spaces_1.getGuideSnappingEnabled);
|
|
64
85
|
var gridSnappingEnabled = (0, store_1.useThreekitSelector)(spaces_1.getGridSnappingEnabled);
|
|
65
|
-
var
|
|
86
|
+
var wallMode = (0, store_1.useThreekitSelector)(spaces_1.getWallMode);
|
|
87
|
+
var _f = (0, react_1.useState)(null), selectedElement = _f[0], setSelectedElement = _f[1];
|
|
88
|
+
var _g = (0, react_1.useState)(false), pendingStatus = _g[0], setPendingStatus = _g[1];
|
|
66
89
|
var canvasRef = (0, react_1.useRef)(null);
|
|
67
90
|
var selectElementPending = (0, react_1.useRef)(null);
|
|
68
91
|
var translationAnchorRef = (0, react_1.useRef)(null);
|
|
69
|
-
var
|
|
70
|
-
scale: constants_1.SCALE,
|
|
71
|
-
unit: types_2.IUnits.FEET,
|
|
72
|
-
snapProximity: constants_1.SNAP_PROXIMITY,
|
|
73
|
-
zoomDefault: zoom || constants_1.ZOOM_DEFAULT,
|
|
74
|
-
translateDefault: translation || constants_1.TRANSLATE_DEFAULT,
|
|
75
|
-
disableGuides: false,
|
|
76
|
-
styles: ((_a = props.config) === null || _a === void 0 ? void 0 : _a.theme) && themes_1.default[props.config.theme]
|
|
77
|
-
? themes_1.default[props.config.theme]
|
|
78
|
-
: themes_1.default[themes_1.IThemes.DEFAULT],
|
|
79
|
-
}, props.config);
|
|
92
|
+
var prevStateRef = (0, react_1.useRef)('');
|
|
80
93
|
var attributeNames = Object.assign(constants_1.ATTRIBUTE_NAME_DEFAULTS, props.attributes);
|
|
81
|
-
var spacesRef = (0, react_1.useRef)(
|
|
82
|
-
var drawSpaces = function () { return spacesRef.current.drawSpaces(canvasRef.current); };
|
|
83
|
-
(0, react_1.useEffect)(function () {
|
|
84
|
-
var attributesDelinked = JSON.parse(JSON.stringify(attributesState));
|
|
85
|
-
spacesRef.current.setAttributesToState(attributesDelinked);
|
|
86
|
-
drawSpaces();
|
|
87
|
-
}, [attributesState]);
|
|
94
|
+
var spacesRef = (0, react_1.useRef)(null);
|
|
95
|
+
var drawSpaces = function () { var _a; return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.drawSpaces(canvasRef.current); };
|
|
88
96
|
(0, react_1.useEffect)(function () {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
97
|
+
if (!hasLoaded)
|
|
98
|
+
return;
|
|
99
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
100
|
+
var parameters, _a;
|
|
101
|
+
var _b;
|
|
102
|
+
return __generator(this, function (_c) {
|
|
103
|
+
switch (_c.label) {
|
|
104
|
+
case 0:
|
|
105
|
+
parameters = props.config
|
|
106
|
+
? Object.assign({}, props.config.unit ? { unit: props.config.unit } : undefined, props.config.showDimensions
|
|
107
|
+
? { showDimensions: props.config.showDimensions }
|
|
108
|
+
: undefined, 'zoomDefault' in props.config
|
|
109
|
+
? { zoomDefault: props.config.zoomDefault }
|
|
110
|
+
: undefined, props.config.translateDefault
|
|
111
|
+
? { translateDefault: props.config.translateDefault }
|
|
112
|
+
: undefined, 'enableAngleSnapping' in props.config
|
|
113
|
+
? { enableAngleSnapping: props.config.enableAngleSnapping }
|
|
114
|
+
: undefined, 'enableGridSnapping' in props.config
|
|
115
|
+
? { enableGridSnapping: props.config.enableGridSnapping }
|
|
116
|
+
: undefined, 'enableGuideSnapping' in props.config
|
|
117
|
+
? { enableGridSnapping: props.config.enableGuideSnapping }
|
|
118
|
+
: undefined)
|
|
119
|
+
: {};
|
|
120
|
+
_a = spacesRef;
|
|
121
|
+
return [4, dispatch((0, spaces_1.initSpaces)({
|
|
122
|
+
parameters: __assign(__assign({}, parameters), { theme: (_b = props.config) === null || _b === void 0 ? void 0 : _b.theme }),
|
|
123
|
+
layoutIds: props.layouts || [],
|
|
124
|
+
attributeNames: attributeNames,
|
|
125
|
+
canvasDimensions: canvasRef.current
|
|
126
|
+
? [canvasRef.current.width, canvasRef.current.height]
|
|
127
|
+
: undefined,
|
|
128
|
+
setPendingStatus: setPendingStatus,
|
|
129
|
+
}))];
|
|
130
|
+
case 1:
|
|
131
|
+
_a.current = _c.sent();
|
|
132
|
+
drawSpaces();
|
|
133
|
+
return [2];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}); })();
|
|
137
|
+
}, [hasLoaded]);
|
|
138
|
+
if (spacesRef.current) {
|
|
139
|
+
var attributesDelinked = void 0;
|
|
140
|
+
if (JSON.stringify(attributesState) !== prevStateRef.current) {
|
|
141
|
+
prevStateRef.current = JSON.stringify(attributesState);
|
|
142
|
+
attributesDelinked = JSON.parse(JSON.stringify(attributesState));
|
|
143
|
+
}
|
|
144
|
+
(_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.sync({
|
|
145
|
+
attributesState: attributesDelinked,
|
|
146
|
+
canvasDimensions: canvasRef.current
|
|
147
|
+
? [canvasRef.current.width, canvasRef.current.height]
|
|
148
|
+
: undefined,
|
|
149
|
+
angleSnappingEnabled: angleSnappingEnabled,
|
|
150
|
+
gridSnappingEnabled: gridSnappingEnabled,
|
|
151
|
+
guideSnappingEnabled: guideSnappingEnabled,
|
|
152
|
+
showDimensions: showDimensions,
|
|
153
|
+
unit: unit,
|
|
154
|
+
zoom: spacesRef.current.zoom !== zoom ? zoom : undefined,
|
|
155
|
+
translate: translation,
|
|
156
|
+
wallMode: {
|
|
157
|
+
value: wallMode.value,
|
|
158
|
+
assetId: wallMode.assetId,
|
|
159
|
+
},
|
|
160
|
+
selectedElement: selectedElement
|
|
161
|
+
? {
|
|
162
|
+
type: selectedElement.path[0],
|
|
163
|
+
index: selectedElement.path[1],
|
|
164
|
+
}
|
|
165
|
+
: null,
|
|
166
|
+
});
|
|
167
|
+
}
|
|
94
168
|
(0, react_1.useEffect)(function () {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}, []);
|
|
169
|
+
if (!canvasRef.current)
|
|
170
|
+
return;
|
|
171
|
+
if (pendingStatus)
|
|
172
|
+
canvasRef.current.style.cursor = 'progress';
|
|
173
|
+
else
|
|
174
|
+
canvasRef.current.style.cursor = 'default';
|
|
175
|
+
}, [pendingStatus, canvasRef.current]);
|
|
103
176
|
(0, react_1.useEffect)(function () {
|
|
104
177
|
var _a, _b;
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
canvasRef.current.height,
|
|
109
|
-
];
|
|
178
|
+
if (pendingStatus)
|
|
179
|
+
return;
|
|
180
|
+
if (canvasRef.current) {
|
|
110
181
|
canvasRef.current.addEventListener('mousedown', handleDrawWallStart);
|
|
182
|
+
canvasRef.current.addEventListener('touchstart', handleDrawWallStart);
|
|
111
183
|
canvasRef.current.addEventListener('mousemove', handleDrawWallMouseMove);
|
|
184
|
+
canvasRef.current.addEventListener('touchmove', handleDrawWallMouseMove);
|
|
112
185
|
document.addEventListener('mouseup', handleDrawWallFinish);
|
|
186
|
+
document.addEventListener('touchend', handleDrawWallFinish);
|
|
113
187
|
canvasRef.current.addEventListener('mousemove', handleHover);
|
|
114
188
|
canvasRef.current.addEventListener('mousedown', handleSelectElement);
|
|
189
|
+
canvasRef.current.addEventListener('touchstart', handleSelectElement);
|
|
115
190
|
canvasRef.current.addEventListener('mousemove', handleMoveSelectedElement);
|
|
116
|
-
|
|
191
|
+
canvasRef.current.addEventListener('touchmove', handleMoveSelectedElement);
|
|
192
|
+
if (!((_a = props.config) === null || _a === void 0 ? void 0 : _a.translateDisabled)) {
|
|
117
193
|
canvasRef.current.addEventListener('mousemove', handleMoveCanvas);
|
|
118
|
-
|
|
194
|
+
canvasRef.current.addEventListener('touchmove', handleMoveCanvas);
|
|
195
|
+
}
|
|
196
|
+
document.addEventListener('mouseup', handleFinishMove);
|
|
197
|
+
document.addEventListener('touchend', handleFinishMove);
|
|
119
198
|
if (!((_b = props.config) === null || _b === void 0 ? void 0 : _b.zoomDisabled))
|
|
120
199
|
canvasRef.current.addEventListener('wheel', handleScrollToZoom);
|
|
121
200
|
}
|
|
122
201
|
return function () {
|
|
123
202
|
var _a, _b;
|
|
124
|
-
if (canvasRef
|
|
203
|
+
if (canvasRef.current) {
|
|
125
204
|
canvasRef.current.removeEventListener('mousedown', handleDrawWallStart);
|
|
205
|
+
canvasRef.current.removeEventListener('touchstart', handleDrawWallStart);
|
|
126
206
|
canvasRef.current.removeEventListener('mousemove', handleDrawWallMouseMove);
|
|
207
|
+
canvasRef.current.removeEventListener('touchmove', handleDrawWallMouseMove);
|
|
127
208
|
document.removeEventListener('mouseup', handleDrawWallFinish);
|
|
209
|
+
document.removeEventListener('touchend', handleDrawWallFinish);
|
|
128
210
|
canvasRef.current.removeEventListener('mousemove', handleHover);
|
|
129
211
|
canvasRef.current.removeEventListener('mousedown', handleSelectElement);
|
|
212
|
+
canvasRef.current.removeEventListener('touchstart', handleSelectElement);
|
|
130
213
|
canvasRef.current.removeEventListener('mousemove', handleMoveSelectedElement);
|
|
131
|
-
|
|
214
|
+
canvasRef.current.removeEventListener('touchmove', handleMoveSelectedElement);
|
|
215
|
+
if (!((_a = props.config) === null || _a === void 0 ? void 0 : _a.translateDisabled)) {
|
|
132
216
|
canvasRef.current.removeEventListener('mousemove', handleMoveCanvas);
|
|
133
|
-
|
|
217
|
+
canvasRef.current.removeEventListener('touchmove', handleMoveCanvas);
|
|
218
|
+
}
|
|
219
|
+
document.removeEventListener('mouseup', handleFinishMove);
|
|
220
|
+
document.removeEventListener('touchend', handleFinishMove);
|
|
134
221
|
if (!((_b = props.config) === null || _b === void 0 ? void 0 : _b.zoomDisabled))
|
|
135
222
|
canvasRef.current.removeEventListener('wheel', handleScrollToZoom);
|
|
136
223
|
}
|
|
137
224
|
};
|
|
138
225
|
});
|
|
139
226
|
(0, react_1.useEffect)(function () {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
spacesRef.current.gridSnappingEnabled = gridSnappingEnabled;
|
|
144
|
-
spacesRef.current.selectedElement = selectedElement
|
|
145
|
-
? {
|
|
146
|
-
type: selectedElement.path[0],
|
|
147
|
-
index: selectedElement.path[1],
|
|
148
|
-
}
|
|
149
|
-
: null;
|
|
150
|
-
drawSpaces();
|
|
151
|
-
}, [
|
|
152
|
-
selectedElement,
|
|
153
|
-
showDimensions,
|
|
154
|
-
angleSnappingEnabled,
|
|
155
|
-
guideSnappingEnabled,
|
|
156
|
-
gridSnappingEnabled,
|
|
157
|
-
]);
|
|
158
|
-
(0, react_1.useEffect)(function () {
|
|
159
|
-
if (!hasLoaded)
|
|
160
|
-
return;
|
|
161
|
-
var layoutIds = props.layouts || [];
|
|
162
|
-
dispatch((0, spaces_1.hydrateLayouts)(layoutIds, {
|
|
163
|
-
walls: attributeNames[types_2.IElements.WALL],
|
|
164
|
-
startX: attributeNames.wallStartX,
|
|
165
|
-
startZ: attributeNames.wallStartZ,
|
|
166
|
-
endX: attributeNames.wallEndX,
|
|
167
|
-
endZ: attributeNames.wallEndZ,
|
|
168
|
-
}));
|
|
169
|
-
}, [hasLoaded, JSON.stringify(props.layouts)]);
|
|
227
|
+
if (hasInitialized)
|
|
228
|
+
drawSpaces();
|
|
229
|
+
});
|
|
170
230
|
var updateZoom = function (value) {
|
|
231
|
+
if (!spacesRef.current)
|
|
232
|
+
return;
|
|
233
|
+
var prevZoom = spacesRef.current.zoom;
|
|
171
234
|
spacesRef.current.zoom = value;
|
|
172
|
-
if (
|
|
235
|
+
if (prevZoom === spacesRef.current.zoom)
|
|
173
236
|
return;
|
|
174
237
|
dispatch((0, spaces_1.setZoom)(spacesRef.current.zoom));
|
|
238
|
+
drawSpaces();
|
|
175
239
|
};
|
|
176
240
|
var updateUnit = function (unit) {
|
|
177
241
|
if (!spacesRef.current)
|
|
178
242
|
return;
|
|
179
243
|
spacesRef.current.unit = unit;
|
|
180
|
-
if (!spacesRef.current.unit)
|
|
181
|
-
return;
|
|
182
244
|
dispatch((0, spaces_1.setUnit)(spacesRef.current.unit));
|
|
183
|
-
spacesRef.current.drawSpaces(canvasRef.current);
|
|
184
245
|
};
|
|
185
246
|
var handleRecenter = function (zoomToFit) {
|
|
247
|
+
if (!spacesRef.current)
|
|
248
|
+
return;
|
|
186
249
|
spacesRef.current.centerSpace(canvasRef.current, zoomToFit);
|
|
187
250
|
dispatch((0, spaces_1.setZoom)(spacesRef.current.zoom));
|
|
251
|
+
dispatch((0, spaces_1.setTranslation)(spacesRef.current.translate));
|
|
188
252
|
};
|
|
189
253
|
var handleSelectModeHover = function (canvas, cursorPoint) {
|
|
254
|
+
if (!spacesRef.current)
|
|
255
|
+
return;
|
|
190
256
|
if (spacesRef.current.activeElement !== null)
|
|
191
257
|
return;
|
|
192
258
|
if (translationAnchorRef.current)
|
|
@@ -195,11 +261,21 @@ var useSpaces = function (props) {
|
|
|
195
261
|
};
|
|
196
262
|
var handleSelectElement = function (e) {
|
|
197
263
|
var _a;
|
|
264
|
+
if (!spacesRef.current)
|
|
265
|
+
return;
|
|
198
266
|
if (!canvasRef.current)
|
|
199
267
|
return;
|
|
200
268
|
if (modeValue !== types_2.IModes.SELECT)
|
|
201
269
|
return;
|
|
202
|
-
var cursorPoint
|
|
270
|
+
var cursorPoint;
|
|
271
|
+
if ('offsetX' in e && 'offsetY' in e)
|
|
272
|
+
cursorPoint = [e.offsetX, e.offsetY];
|
|
273
|
+
else {
|
|
274
|
+
var localTouchPoint = getLocalTouchPoint(e.touches[0], canvasRef.current.getBoundingClientRect());
|
|
275
|
+
if (!localTouchPoint)
|
|
276
|
+
return;
|
|
277
|
+
cursorPoint = localTouchPoint;
|
|
278
|
+
}
|
|
203
279
|
spacesRef.current.selectElementIfInProximity(canvasRef.current, cursorPoint);
|
|
204
280
|
var element = spacesRef.current.getElementUiAtPoint(cursorPoint);
|
|
205
281
|
if (!element) {
|
|
@@ -216,30 +292,57 @@ var useSpaces = function (props) {
|
|
|
216
292
|
selectElementPending.current = element;
|
|
217
293
|
};
|
|
218
294
|
var handleMoveSelectedElement = function (e) {
|
|
295
|
+
if (!spacesRef.current)
|
|
296
|
+
return;
|
|
219
297
|
if (modeValue !== types_2.IModes.SELECT)
|
|
220
298
|
return;
|
|
221
299
|
if (!canvasRef.current)
|
|
222
300
|
return;
|
|
223
|
-
var point
|
|
301
|
+
var point;
|
|
302
|
+
if ('offsetX' in e && 'offsetY' in e)
|
|
303
|
+
point = [e.offsetX, e.offsetY];
|
|
304
|
+
else {
|
|
305
|
+
var localTouchPoint = getLocalTouchPoint(e.touches[0], canvasRef.current.getBoundingClientRect());
|
|
306
|
+
if (!localTouchPoint)
|
|
307
|
+
return;
|
|
308
|
+
point = localTouchPoint;
|
|
309
|
+
}
|
|
224
310
|
spacesRef.current.moveActiveElement(canvasRef.current, point);
|
|
225
311
|
selectElementPending.current = null;
|
|
226
312
|
};
|
|
227
313
|
var handleMoveCanvas = function (e) {
|
|
314
|
+
if (!spacesRef.current)
|
|
315
|
+
return;
|
|
228
316
|
if (modeValue !== types_2.IModes.SELECT)
|
|
229
317
|
return;
|
|
230
318
|
if (!canvasRef.current)
|
|
231
319
|
return;
|
|
232
320
|
if (spacesRef.current.selectedElement || !translationAnchorRef.current)
|
|
233
321
|
return;
|
|
234
|
-
var
|
|
235
|
-
|
|
236
|
-
e.
|
|
322
|
+
var point;
|
|
323
|
+
if ('offsetX' in e && 'offsetY' in e)
|
|
324
|
+
point = [e.offsetX, e.offsetY];
|
|
325
|
+
else {
|
|
326
|
+
var localTouchPoint = getLocalTouchPoint(e.touches[0], canvasRef.current.getBoundingClientRect());
|
|
327
|
+
if (!localTouchPoint)
|
|
328
|
+
return;
|
|
329
|
+
point = localTouchPoint;
|
|
330
|
+
}
|
|
331
|
+
spacesRef.current.translate = [
|
|
332
|
+
spacesRef.current.translate[0] +
|
|
333
|
+
point[0] -
|
|
334
|
+
translationAnchorRef.current[0],
|
|
335
|
+
spacesRef.current.translate[1] +
|
|
336
|
+
point[1] -
|
|
337
|
+
translationAnchorRef.current[1],
|
|
237
338
|
];
|
|
238
|
-
|
|
239
|
-
|
|
339
|
+
translationAnchorRef.current = point;
|
|
340
|
+
drawSpaces();
|
|
240
341
|
};
|
|
241
|
-
var
|
|
342
|
+
var handleFinishMove = function (e) {
|
|
242
343
|
var _a;
|
|
344
|
+
if (!spacesRef.current)
|
|
345
|
+
return;
|
|
243
346
|
if (modeValue !== types_2.IModes.SELECT)
|
|
244
347
|
return;
|
|
245
348
|
if (!canvasRef.current)
|
|
@@ -254,34 +357,57 @@ var useSpaces = function (props) {
|
|
|
254
357
|
selectElementPending.current = null;
|
|
255
358
|
return;
|
|
256
359
|
}
|
|
257
|
-
if (translationAnchorRef.current)
|
|
360
|
+
if (translationAnchorRef.current) {
|
|
258
361
|
translationAnchorRef.current = null;
|
|
362
|
+
dispatch((0, spaces_1.setTranslation)(spacesRef.current.translate));
|
|
363
|
+
}
|
|
259
364
|
};
|
|
260
365
|
var handleDrawModeHover = function (canvas, cursorPoint) {
|
|
366
|
+
if (!spacesRef.current)
|
|
367
|
+
return;
|
|
261
368
|
if (spacesRef.current.isDrawWallActive)
|
|
262
369
|
return;
|
|
263
370
|
spacesRef.current.showGuideAtPoint(canvas, cursorPoint);
|
|
264
371
|
};
|
|
265
372
|
var handleDrawWallStart = function (e) {
|
|
373
|
+
if (!spacesRef.current || !canvasRef.current)
|
|
374
|
+
return;
|
|
266
375
|
if (modeValue !== types_2.IModes.DRAW)
|
|
267
376
|
return;
|
|
268
|
-
var
|
|
269
|
-
|
|
377
|
+
var startPoint;
|
|
378
|
+
if ('offsetX' in e && 'offsetY' in e)
|
|
379
|
+
startPoint = [e.offsetX, e.offsetY];
|
|
380
|
+
else {
|
|
381
|
+
var localTouchPoint = getLocalTouchPoint(e.touches[0], canvasRef.current.getBoundingClientRect());
|
|
382
|
+
if (!localTouchPoint)
|
|
383
|
+
return;
|
|
384
|
+
startPoint = localTouchPoint;
|
|
385
|
+
}
|
|
386
|
+
spacesRef.current.startDrawNewWall(startPoint);
|
|
270
387
|
};
|
|
271
388
|
var handleDrawWallMouseMove = function (e) {
|
|
389
|
+
if (!spacesRef.current || !canvasRef.current)
|
|
390
|
+
return;
|
|
272
391
|
if (modeValue !== types_2.IModes.DRAW)
|
|
273
392
|
return;
|
|
274
|
-
if (!
|
|
393
|
+
if (!spacesRef.current.isDrawWallActive)
|
|
275
394
|
return;
|
|
276
|
-
var
|
|
277
|
-
if (
|
|
278
|
-
|
|
395
|
+
var point;
|
|
396
|
+
if ('offsetX' in e && 'offsetY' in e)
|
|
397
|
+
point = [e.offsetX, e.offsetY];
|
|
398
|
+
else {
|
|
399
|
+
var localTouchPoint = getLocalTouchPoint(e.touches[0], canvasRef.current.getBoundingClientRect());
|
|
400
|
+
if (!localTouchPoint)
|
|
401
|
+
return;
|
|
402
|
+
point = localTouchPoint;
|
|
403
|
+
}
|
|
404
|
+
spacesRef.current.drawNewWall(canvasRef.current, point);
|
|
279
405
|
};
|
|
280
406
|
var handleDrawWallFinish = function (e) {
|
|
281
407
|
var _a;
|
|
282
|
-
if (
|
|
408
|
+
if (!spacesRef.current || !canvasRef.current)
|
|
283
409
|
return;
|
|
284
|
-
if (
|
|
410
|
+
if (modeValue !== types_2.IModes.DRAW)
|
|
285
411
|
return;
|
|
286
412
|
if (!((_a = canvasRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
|
|
287
413
|
spacesRef.current.cancelDrawNewWall(canvasRef.current);
|
|
@@ -310,9 +436,10 @@ var useSpaces = function (props) {
|
|
|
310
436
|
if (!attribute)
|
|
311
437
|
return undefined;
|
|
312
438
|
var values = attribute.values.map(function (val) { return (__assign(__assign({}, val), { add: function (addToWallIndex, feature) {
|
|
313
|
-
|
|
439
|
+
var _a;
|
|
440
|
+
return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.addFeature(type, addToWallIndex, __assign({ assetId: val.assetId }, (feature || {})));
|
|
314
441
|
} })); });
|
|
315
|
-
var value = attribute.value.map(function (val, i) { return (__assign(__assign({}, val), { delete: function () { return spacesRef.current.deleteFeature(type, i); } })); });
|
|
442
|
+
var value = attribute.value.map(function (val, i) { return (__assign(__assign({}, val), { delete: function () { var _a; return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.deleteFeature(type, i); } })); });
|
|
316
443
|
return __assign(__assign({}, attribute), { values: values, value: value });
|
|
317
444
|
};
|
|
318
445
|
var prepWallAttributeForOutput = function (attribute) {
|
|
@@ -334,7 +461,6 @@ var useSpaces = function (props) {
|
|
|
334
461
|
var handleSetMode = function (mode) {
|
|
335
462
|
if (mode === modeValue)
|
|
336
463
|
return;
|
|
337
|
-
drawSpaces();
|
|
338
464
|
dispatch((0, spaces_1.setMode)(mode));
|
|
339
465
|
setSelectedElement(null);
|
|
340
466
|
};
|
|
@@ -380,14 +506,16 @@ var useSpaces = function (props) {
|
|
|
380
506
|
setSelectedElement(null);
|
|
381
507
|
};
|
|
382
508
|
var handleChangeTranslate = function (delta) {
|
|
509
|
+
if (!spacesRef.current)
|
|
510
|
+
return;
|
|
383
511
|
spacesRef.current.translate = [
|
|
384
512
|
spacesRef.current.translate[0] + delta[0],
|
|
385
513
|
spacesRef.current.translate[1] + delta[1],
|
|
386
514
|
];
|
|
387
515
|
dispatch((0, spaces_1.setTranslation)(spacesRef.current.translate));
|
|
388
|
-
drawSpaces();
|
|
389
516
|
};
|
|
390
517
|
return {
|
|
518
|
+
hasLoaded: hasInitialized,
|
|
391
519
|
draw: drawSpaces,
|
|
392
520
|
canvasRef: canvasRef,
|
|
393
521
|
selectedElement: selectedElement === null
|
|
@@ -398,11 +526,13 @@ var useSpaces = function (props) {
|
|
|
398
526
|
], type: selectedElement.path[0], deleteElement: function () { return handleDeleteElement.apply(void 0, selectedElement.path); }, splitWall: selectedElement.path[0] !== types_2.IElements.WALL
|
|
399
527
|
? undefined
|
|
400
528
|
: function (offset) {
|
|
401
|
-
|
|
529
|
+
var _a;
|
|
530
|
+
return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.splitWallAtOffset(selectedElement.path[1], offset);
|
|
402
531
|
}, addFeature: selectedElement.path[0] !== types_2.IElements.WALL
|
|
403
532
|
? undefined
|
|
404
533
|
: function (type, feature) {
|
|
405
|
-
|
|
534
|
+
var _a;
|
|
535
|
+
return (_a = spacesRef.current) === null || _a === void 0 ? void 0 : _a.addFeature(type, selectedElement.path[1], feature);
|
|
406
536
|
} }),
|
|
407
537
|
mode: {
|
|
408
538
|
value: modeValue,
|
|
@@ -441,9 +571,9 @@ var useSpaces = function (props) {
|
|
|
441
571
|
handleToggle: handleToggleGridSnapping,
|
|
442
572
|
},
|
|
443
573
|
zoom: {
|
|
444
|
-
min: spacesRef.current.zoomMin,
|
|
445
|
-
max: spacesRef.current.zoomMax,
|
|
446
|
-
value: zoom
|
|
574
|
+
min: (_c = (_b = spacesRef.current) === null || _b === void 0 ? void 0 : _b.zoomMin) !== null && _c !== void 0 ? _c : constants_1.ZOOM_MIN,
|
|
575
|
+
max: (_e = (_d = spacesRef.current) === null || _d === void 0 ? void 0 : _d.zoomMax) !== null && _e !== void 0 ? _e : constants_1.ZOOM_MAX,
|
|
576
|
+
value: zoom,
|
|
447
577
|
handleChange: updateZoom,
|
|
448
578
|
},
|
|
449
579
|
unit: {
|
|
@@ -456,6 +586,18 @@ var useSpaces = function (props) {
|
|
|
456
586
|
}); }),
|
|
457
587
|
handleChange: updateUnit,
|
|
458
588
|
},
|
|
589
|
+
wallMode: {
|
|
590
|
+
value: wallMode.value,
|
|
591
|
+
options: wallMode.options.map(function (mode) { return ({
|
|
592
|
+
value: mode,
|
|
593
|
+
label: constants_1.wallModeLabels[mode],
|
|
594
|
+
selected: mode === wallMode.value,
|
|
595
|
+
handleSelect: function () { return dispatch((0, spaces_1.setWallModeValue)(mode)); },
|
|
596
|
+
}); }),
|
|
597
|
+
handleChange: function (wallMode) {
|
|
598
|
+
return dispatch((0, spaces_1.setWallModeValue)(wallMode));
|
|
599
|
+
},
|
|
600
|
+
},
|
|
459
601
|
translate: {
|
|
460
602
|
handleChange: handleChangeTranslate,
|
|
461
603
|
},
|
|
@@ -478,5 +620,6 @@ var useSpaces = function (props) {
|
|
|
478
620
|
useSpaces.themes = themes_1.IThemes;
|
|
479
621
|
useSpaces.units = types_2.IUnits;
|
|
480
622
|
useSpaces.modes = types_2.IModes;
|
|
623
|
+
useSpaces.wallModes = constants_1.WallModes;
|
|
481
624
|
useSpaces.LayoutIcon = SpacesLayout_1.default;
|
|
482
625
|
exports.default = useSpaces;
|