@threekit-tools/treble 0.0.36 → 0.0.39

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/README.md CHANGED
@@ -261,11 +261,10 @@ The `<Player />` component renders the **Threekit Player**.
261
261
 
262
262
  ```jsx
263
263
  import { ThreekitProvider, Player } from '@threekit-tools/treble';
264
- import threekitConfig from './threekit.config.js';
265
264
 
266
265
  const ThreekitApp = () => {
267
266
  return (
268
- <ThreekitProvider {...threekitConfig}>
267
+ <ThreekitProvider>
269
268
  <Player />
270
269
  </ThreekitProvider>
271
270
  );
@@ -278,7 +277,6 @@ The Player Component also comes with **widget containers** that can be used to p
278
277
 
279
278
  ```jsx
280
279
  import { ThreekitProvider, Player } from '@threekit-tools/treble';
281
- import threekitConfig from './threekit.config.js';
282
280
 
283
281
  // We can separate out the widget container component
284
282
  // or use the component directly from the Player component
@@ -311,7 +309,6 @@ The `<FlatForm>` component is used to render out the configurator for the initia
311
309
 
312
310
  ```jsx
313
311
  import { ThreekitProvider, FlatForm } from '@threekit-tools/treble';
314
- import threekitConfig from './threekit.config.js';
315
312
 
316
313
  const App = () => {
317
314
  return (
@@ -357,7 +354,6 @@ By default the Form will not render reserved attributes. This can be controlled/
357
354
 
358
355
  ```jsx
359
356
  import { ThreekitProvider, FlatForm } from '@threekit-tools/treble';
360
- import threekitConfig from './threekit.config.js';
361
357
 
362
358
  const App = () => {
363
359
  const attributes = {
@@ -36,12 +36,16 @@ var Player = function (props) {
36
36
  width: '100%',
37
37
  }, props), height = _a.height, width = _a.width, minHeight = _a.minHeight, children = _a.children;
38
38
  var hasMoved = (0, react_1.useRef)(false);
39
- var portalPlayerTo = (0, usePlayerPortal_1.default)();
39
+ var _b = (0, usePlayerPortal_1.default)(), portalPlayerTo = _b[0], portalBack = _b[1];
40
40
  (0, react_1.useEffect)(function () {
41
41
  if (portalPlayerTo && !hasMoved.current) {
42
42
  portalPlayerTo(exports.PLAYER_DIV_ID);
43
43
  hasMoved.current = true;
44
44
  }
45
+ return function () {
46
+ if (portalBack)
47
+ portalBack();
48
+ };
45
49
  });
46
50
  return (react_1.default.createElement(player_styles_1.Wrapper, { height: height, width: width, minHeight: minHeight, className: className },
47
51
  react_1.default.createElement("div", { id: exports.PLAYER_DIV_ID }),
@@ -38,6 +38,12 @@ export declare const Swatch: {
38
38
  * Handles the user seletion by passing the value of the selected
39
39
  * option as the argument into the onClick callback.
40
40
  */
41
+ size: PropTypes.Requireable<string>;
42
+ /**
43
+ * The size of the for a swatch option. The size should be a valid CSS
44
+ * height/width property.
45
+ *
46
+ */
41
47
  onClick: PropTypes.Requireable<(...args: any[]) => any>;
42
48
  /**
43
49
  * The options set to be displayed for the user
@@ -24,10 +24,10 @@ var SwatchInfo = function (props) {
24
24
  react_1.default.createElement("div", null))));
25
25
  };
26
26
  var Thumbnail = function (props) {
27
- var imageUrl = props.imageUrl, color = props.color, name = props.name, shape = props.shape, className = props.className;
27
+ var imageUrl = props.imageUrl, color = props.color, name = props.name, shape = props.shape, size = props.size, className = props.className;
28
28
  if (!imageUrl && !color)
29
29
  return react_1.default.createElement("div", null);
30
- return (react_1.default.createElement(swatch_styles_1.OptionThumbnail, { className: "".concat(className, " option-thumbnail"), color: color, shape: shape }, imageUrl ? react_1.default.createElement("img", { src: imageUrl, alt: name || '' }) : react_1.default.createElement("span", null)));
30
+ return (react_1.default.createElement(swatch_styles_1.OptionThumbnail, { className: "".concat(className, " option-thumbnail"), color: color, shape: shape, size: size }, imageUrl ? react_1.default.createElement("img", { src: imageUrl, alt: name || '' }) : react_1.default.createElement("span", null)));
31
31
  };
32
32
  var Swatch = function (props) {
33
33
  var _a = Object.assign({ shape: 'round', size: '60px' }, props), title = _a.title, shape = _a.shape, description = _a.description, options = _a.options, value = _a.value, onClick = _a.onClick, customClassName = _a.className, showThumbnail = _a.showThumbnail, showPrice = _a.showPrice, showDescription = _a.showDescription, size = _a.size;
@@ -47,7 +47,7 @@ var Swatch = function (props) {
47
47
  var clsOpt = "".concat(cls, "-option option-").concat(i, " ").concat(optionValue).concat(selected ? ' selected' : '');
48
48
  return (react_1.default.createElement(swatch_styles_1.OptionWrapper, { key: i, onClick: function () { return onClick && onClick(optionValue); }, selected: selected, className: clsOpt, shape: shape, size: size },
49
49
  react_1.default.createElement("div", null,
50
- react_1.default.createElement(Thumbnail, { imageUrl: imageUrl, color: color, shape: shape, className: clsOpt })),
50
+ react_1.default.createElement(Thumbnail, { imageUrl: imageUrl, color: color, shape: shape, className: clsOpt, size: size })),
51
51
  react_1.default.createElement(SwatchInfo, { title: name, price: price, description: description })));
52
52
  }))));
53
53
  };
@@ -81,6 +81,12 @@ exports.Swatch.propTypes = {
81
81
  * Handles the user seletion by passing the value of the selected
82
82
  * option as the argument into the onClick callback.
83
83
  */
84
+ size: prop_types_1.default.string,
85
+ /**
86
+ * The size of the for a swatch option. The size should be a valid CSS
87
+ * height/width property.
88
+ *
89
+ */
84
90
  onClick: prop_types_1.default.func,
85
91
  /**
86
92
  * The options set to be displayed for the user
@@ -38,7 +38,7 @@ var App = function (props) {
38
38
  };
39
39
  init();
40
40
  return;
41
- }, [props.project, props.threekitEnv, , props.playerConfig]);
41
+ }, [props.project, props.threekitEnv, props.playerConfig]);
42
42
  return react_1.default.createElement(react_1.default.Fragment, null, props.children);
43
43
  };
44
44
  var ThreekitProvider = function (props) {
@@ -21,6 +21,7 @@ export declare const TK_SAVED_CONFIG_PARAM_KEY = "tkConfigId";
21
21
  /*****************************************************
22
22
  * Threekit Player Initialization Defaults
23
23
  ****************************************************/
24
+ export declare const TK_PLAYER_LOADER_DIV = "tk-ply-loader";
24
25
  export declare const TK_PLAYER_ROOT_DIV = "tk-ply-root";
25
26
  export declare const DEFAULT_PLAYER_CONFIG: {
26
27
  showConfigurator: boolean;
package/dist/constants.js CHANGED
@@ -4,7 +4,7 @@
4
4
  ****************************************************/
5
5
  var _a;
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.WISHLIST_LOCALSTORAGE_KEY = exports.SNAPSHOT_OUTPUTS = exports.SNAPSHOT_FORMATS = exports.METADATA_RESERVED = exports.ATTRIBUTES_RESERVED = exports.SORT_OPTIONS = exports.ATTRIBUTE_TYPES = exports.DEFAULT_PLAYER_CONFIG = exports.TK_PLAYER_ROOT_DIV = exports.TK_SAVED_CONFIG_PARAM_KEY = exports.TK_PRODUCT_ID_PARAM_KEY = exports.IS_TREBLE_SCRIPTS = exports.FORM_CLASS_NAME = exports.DISPLAY_CLASS_NAME = exports.TOOL_CLASS_NAME = exports.LAYOUT_CLASS_NAME = exports.WIDGET_CLASS_NAME = exports.INPUT_COMPONENT_CLASS_NAME = exports.CLASS_NAME_PREFIX = exports.DEFAULT_CLASS_NAME = void 0;
7
+ exports.WISHLIST_LOCALSTORAGE_KEY = exports.SNAPSHOT_OUTPUTS = exports.SNAPSHOT_FORMATS = exports.METADATA_RESERVED = exports.ATTRIBUTES_RESERVED = exports.SORT_OPTIONS = exports.ATTRIBUTE_TYPES = exports.DEFAULT_PLAYER_CONFIG = exports.TK_PLAYER_ROOT_DIV = exports.TK_PLAYER_LOADER_DIV = exports.TK_SAVED_CONFIG_PARAM_KEY = exports.TK_PRODUCT_ID_PARAM_KEY = exports.IS_TREBLE_SCRIPTS = exports.FORM_CLASS_NAME = exports.DISPLAY_CLASS_NAME = exports.TOOL_CLASS_NAME = exports.LAYOUT_CLASS_NAME = exports.WIDGET_CLASS_NAME = exports.INPUT_COMPONENT_CLASS_NAME = exports.CLASS_NAME_PREFIX = exports.DEFAULT_CLASS_NAME = void 0;
8
8
  exports.DEFAULT_CLASS_NAME = 'threekit-react';
9
9
  exports.CLASS_NAME_PREFIX = 'tk';
10
10
  exports.INPUT_COMPONENT_CLASS_NAME = "".concat(exports.DEFAULT_CLASS_NAME, " ").concat(exports.CLASS_NAME_PREFIX, "-input");
@@ -25,6 +25,7 @@ exports.TK_SAVED_CONFIG_PARAM_KEY = 'tkConfigId';
25
25
  /*****************************************************
26
26
  * Threekit Player Initialization Defaults
27
27
  ****************************************************/
28
+ exports.TK_PLAYER_LOADER_DIV = 'tk-ply-loader';
28
29
  exports.TK_PLAYER_ROOT_DIV = 'tk-ply-root';
29
30
  exports.DEFAULT_PLAYER_CONFIG = {
30
31
  // authToken: undefined,
@@ -1,2 +1,3 @@
1
- declare const usePlayerPortal: () => ((toEl: string) => void) | undefined;
1
+ declare type UsePlayerPortal = [undefined, undefined] | [(toEl: string) => void, () => void];
2
+ declare const usePlayerPortal: () => UsePlayerPortal;
2
3
  export default usePlayerPortal;
@@ -1,22 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ var react_1 = require("react");
3
4
  var react_redux_1 = require("react-redux");
4
5
  var threekit_1 = require("../../store/threekit");
6
+ var constants_1 = require("../../constants");
5
7
  var usePlayerPortal = function () {
8
+ var htmlElements = (0, react_1.useRef)({
9
+ player: null,
10
+ playerLoader: null,
11
+ playerWrapper: null,
12
+ });
6
13
  var playerElementId = (0, react_redux_1.useSelector)(threekit_1.getPlayerElementId);
7
14
  if (!playerElementId)
8
- return undefined;
15
+ return [undefined, undefined];
9
16
  var portalPlayerTo = function (toEl) {
10
17
  if (!toEl)
11
18
  return;
12
- var playerEl = document.getElementById(playerElementId);
13
- var playerWrapperEl = document.getElementById(toEl);
14
- if (!playerEl)
19
+ if (!htmlElements.current.player)
20
+ htmlElements.current.player = document.getElementById(playerElementId);
21
+ htmlElements.current.playerWrapper = document.getElementById(toEl);
22
+ if (!htmlElements.current.player)
15
23
  throw new Error('Move from element not found');
16
- if (!playerWrapperEl)
24
+ if (!htmlElements.current.playerWrapper)
17
25
  throw new Error('Move To element not found');
18
- playerWrapperEl.appendChild(playerEl);
26
+ htmlElements.current.playerWrapper.appendChild(htmlElements.current.player);
19
27
  };
20
- return portalPlayerTo;
28
+ var returnPlayer = function () {
29
+ constants_1.TK_PLAYER_LOADER_DIV;
30
+ if (!htmlElements.current.player)
31
+ htmlElements.current.player = document.getElementById(playerElementId);
32
+ if (!htmlElements.current.playerLoader)
33
+ htmlElements.current.playerLoader =
34
+ document.getElementById(constants_1.TK_PLAYER_LOADER_DIV);
35
+ if (!htmlElements.current.player)
36
+ throw new Error('Move from element not found');
37
+ if (!htmlElements.current.playerLoader)
38
+ throw new Error('Player Loader element not found');
39
+ htmlElements.current.playerLoader.appendChild(htmlElements.current.player);
40
+ };
41
+ return [portalPlayerTo, returnPlayer];
21
42
  };
22
43
  exports.default = usePlayerPortal;
@@ -1,2 +1,3 @@
1
- declare const useZoom: () => [(step: number) => void, (step: number) => void];
1
+ declare type UseZoom = [(step: number) => void, (step: number) => void];
2
+ declare const useZoom: () => UseZoom;
2
3
  export default useZoom;
@@ -75,7 +75,7 @@ var createPlayerLoaderEl = function (elementId) {
75
75
  playerElement.setAttribute('id', elementId);
76
76
  playerElement.style.height = '100%';
77
77
  var playerLoader = document.createElement('div');
78
- playerLoader.setAttribute('id', 'tk-player-loader');
78
+ playerLoader.setAttribute('id', constants_1.TK_PLAYER_LOADER_DIV);
79
79
  playerLoader.appendChild(playerElement);
80
80
  playerLoader.style.opacity = '0';
81
81
  playerLoader.style.height = '1px';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threekit-tools/treble",
3
- "version": "0.0.36",
3
+ "version": "0.0.39",
4
4
  "author": "Amaan Saeed",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -32,10 +32,6 @@
32
32
  "reselect": "^4.1.2",
33
33
  "styled-components": "^5.3.3"
34
34
  },
35
- "peerDependencies": {
36
- "react": "^17.0.2",
37
- "react-dom": "^17.0.2"
38
- },
39
35
  "devDependencies": {
40
36
  "@babel/core": "^7.15.8",
41
37
  "@storybook/addon-actions": "^6.3.12",
@@ -45,16 +41,18 @@
45
41
  "@storybook/addon-storysource": "^6.3.12",
46
42
  "@storybook/react": "^6.3.12",
47
43
  "@types/node": "^16.10.3",
48
- "@types/react": "^17.0.27",
49
- "@types/react-dom": "^17.0.9",
44
+ "@types/react": ">=17.0.27",
45
+ "@types/react-dom": ">=17.0.9",
50
46
  "@types/redux-logger": "^3.0.9",
51
47
  "@types/styled-components": "^5.1.15",
52
48
  "@types/webpack-env": "^1.16.3",
53
49
  "babel-loader": "^8.2.2",
50
+ "react": ">=17.0.2",
51
+ "react-dom": ">=17.0.2",
54
52
  "rimraf": "^3.0.2",
55
53
  "serve": "^12.0.1",
56
54
  "storybook-addon-styled-component-theme": "^2.0.0",
57
- "typescript": "^4.4.4"
55
+ "typescript": ">=4.4.4"
58
56
  },
59
57
  "gitHead": "2e16bcf98f81e16bb1768072fdb3968122e7966f"
60
58
  }