@onehat/ui 0.2.12 → 0.2.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/ui",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
4
4
  "description": "Base UI for OneHat apps",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -6,14 +6,20 @@ import {
6
6
  import {
7
7
  UI_MODE_WEB,
8
8
  UI_MODE_REACT_NATIVE,
9
+ CURRENT_MODE,
9
10
  } from '../../Constants/UiModes.js';
10
- import UiGlobals from '../../UiGlobals.js';
11
- import Draggable from 'react-draggable'; // https://github.com/react-grid-layout/react-draggable
12
11
  import useBlocking from '../../Hooks/useBlocking.js';
13
12
  import {
14
13
  v4 as uuid,
15
14
  } from 'uuid';
16
15
 
16
+ let Draggable;
17
+ if (CURRENT_MODE === UI_MODE_WEB) {
18
+ Draggable = await import('react-draggable'); // https://github.com/react-grid-layout/react-draggable
19
+ } else if (CURRENT_MODE === UI_MODE_REACT_NATIVE) {
20
+ Draggable = await import('react-native-draggable'); // https://github.com/tongyy/react-native-draggable
21
+ }
22
+
17
23
  // Note on modes:
18
24
  // HORIZONTAL means the component moves along the X axis.
19
25
  // VERTICAL means the component moves along the Y axis.
@@ -21,9 +27,6 @@ import {
21
27
  export default function withDraggable(WrappedComponent) {
22
28
  return (props) => {
23
29
 
24
- if (UiGlobals.mode === UI_MODE_REACT_NATIVE) {
25
- throw new Error('Not yet implemented for RN.');
26
- }
27
30
  const {
28
31
  // extract and pass
29
32
  onDragStart,
@@ -216,44 +219,54 @@ export default function withDraggable(WrappedComponent) {
216
219
  };
217
220
  propsToPass.isDragging = isDragging;
218
221
 
219
- if (mode === VERTICAL) {
220
- return <Draggable
221
- axis="x"
222
- onStart={handleStart}
223
- onDrag={handleDrag}
224
- onStop={handleStop}
225
- position={{ x: 0, y: 0, /* reset to dropped position */ }}
226
- // bounds={bounds}
227
- >
228
- <div className="nsResize" style={{ width: '100%', }}>
229
- <WrappedComponent {...propsToPass} />
230
- </div>
231
- </Draggable>;
232
- } else if (mode === HORIZONTAL) {
222
+
223
+ if (CURRENT_MODE === UI_MODE_WEB) {
224
+ if (mode === VERTICAL) {
225
+ return <Draggable
226
+ axis="x"
227
+ onStart={handleStart}
228
+ onDrag={handleDrag}
229
+ onStop={handleStop}
230
+ position={{ x: 0, y: 0, /* reset to dropped position */ }}
231
+ // bounds={bounds}
232
+ >
233
+ <div className="nsResize" style={{ width: '100%', }}>
234
+ <WrappedComponent {...propsToPass} />
235
+ </div>
236
+ </Draggable>;
237
+ } else if (mode === HORIZONTAL) {
238
+ return <Draggable
239
+ axis="y"
240
+ onStart={handleStart}
241
+ onDrag={handleDrag}
242
+ onStop={handleStop}
243
+ position={{ x: 0, y: 0, /* reset to dropped position */ }}
244
+ // bounds={bounds}
245
+ >
246
+ <div className="ewResize" style={{ height: '100%', }}>
247
+ <WrappedComponent {...propsToPass} />
248
+ </div>
249
+ </Draggable>;
250
+ }
251
+
252
+ // can drag in all directions
233
253
  return <Draggable
234
- axis="y"
254
+ axis="both"
235
255
  onStart={handleStart}
236
256
  onDrag={handleDrag}
237
257
  onStop={handleStop}
238
- position={{ x: 0, y: 0, /* reset to dropped position */ }}
239
- // bounds={bounds}
258
+ // position={{ x: 0, y: 0, /* reset to dropped position */ }}
259
+ handle={handle}
240
260
  >
241
- <div className="ewResize" style={{ height: '100%', }}>
242
- <WrappedComponent {...propsToPass} />
243
- </div>
261
+ <WrappedComponent {...propsToPass} />
244
262
  </Draggable>;
245
- }
263
+ } else if (CURRENT_MODE === UI_MODE_REACT_NATIVE) {
246
264
 
247
- // can drag in all directions
248
- return <Draggable
249
- axis="both"
250
- onStart={handleStart}
251
- onDrag={handleDrag}
252
- onStop={handleStop}
253
- // position={{ x: 0, y: 0, /* reset to dropped position */ }}
254
- handle={handle}
255
- >
256
- <WrappedComponent {...propsToPass} />
257
- </Draggable>;
265
+ // NOT YET IMPLEMENTED
266
+ // Really need to replace most of this, as much of it is web-centric.
267
+
268
+ return <WrappedComponent {...propsToPass} />; // TEMP
269
+
270
+ }
258
271
  };
259
272
  }
@@ -1,2 +1,12 @@
1
+ import { isBrowser, isNode, isWebWorker, isJsDom, isDeno } from "browser-or-node";
2
+
3
+
1
4
  export const UI_MODE_WEB = 'UI_MODE_WEB';
2
5
  export const UI_MODE_REACT_NATIVE = 'UI_MODE_REACT_NATIVE';
6
+
7
+ export let CURRENT_MODE;
8
+ if (isBrowser || isWebWorker) {
9
+ CURRENT_MODE = UI_MODE_WEB;
10
+ } else if (isNode) {
11
+ CURRENT_MODE = UI_MODE_REACT_NATIVE;
12
+ }
package/src/UiGlobals.js CHANGED
@@ -1,18 +1,8 @@
1
- import { isBrowser, isNode, isWebWorker, isJsDom, isDeno } from "browser-or-node";
2
- import {
3
- UI_MODE_WEB,
4
- UI_MODE_REACT_NATIVE,
5
- } from './Constants/UiModes.js';
1
+ import { CURRENT_MODE } from './Constants/UiModes.js';
6
2
 
7
3
 
8
4
  const Globals = {
9
- mode: null,
5
+ mode: CURRENT_MODE,
10
6
  };
11
7
 
12
- if (isBrowser || isWebWorker) {
13
- Globals.mode = UI_MODE_WEB;
14
- } else if (isNode) {
15
- Globals.mode = UI_MODE_REACT_NATIVE;
16
- }
17
-
18
8
  export default Globals;