@threekit-tools/treble 0.0.64 → 0.0.67

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.
@@ -1,4 +1,4 @@
1
- import { IThreekitPlayer, IConfiguration, ISetConfiguration, IThreekitPrivateConfigurator } from '../threekit';
1
+ import { IThreekitPlayer, IConfiguration, ISetConfiguration, IThreekitPrivateConfigurator } from '../types';
2
2
  import { IWishlist } from './Wishlist';
3
3
  import Snapshots from './Snapshots';
4
4
  import { ISaveConfiguration } from '../api/configurations';
@@ -1,5 +1,5 @@
1
1
  import { IConfigurationResponse } from '../http/configurations';
2
- import { IConfiguration, IMetadata } from '../threekit';
2
+ import { IConfiguration, IMetadata } from '../types';
3
3
  export interface ISaveConfiguration {
4
4
  assetId: string;
5
5
  customerId?: string;
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ export declare const PortalToArOverlay: React.FC;
3
+ export default PortalToArOverlay;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
21
+ var __importDefault = (this && this.__importDefault) || function (mod) {
22
+ return (mod && mod.__esModule) ? mod : { "default": mod };
23
+ };
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.PortalToArOverlay = void 0;
26
+ var react_1 = __importStar(require("react"));
27
+ var react_dom_1 = require("react-dom");
28
+ var useThreekitInitStatus_1 = __importDefault(require("../../hooks/useThreekitInitStatus"));
29
+ var store_1 = require("../../store");
30
+ var treble_1 = require("../../store/treble");
31
+ var PortalToArOverlay = function (props) {
32
+ var children = props.children;
33
+ var isLoaded = (0, useThreekitInitStatus_1.default)();
34
+ var playerEl = (0, store_1.useThreekitSelector)(treble_1.getPlayerElementId);
35
+ var _a = (0, react_1.useState)(false), isAvailable = _a[0], setIsAvailable = _a[1];
36
+ (0, react_1.useEffect)(function () {
37
+ (function () {
38
+ if (!isLoaded || !playerEl)
39
+ return;
40
+ if (!isAvailable)
41
+ return;
42
+ var observer = new MutationObserver(function () {
43
+ if (document.getElementById('threekitArOverlay')) {
44
+ setIsAvailable(true);
45
+ observer.disconnect();
46
+ }
47
+ });
48
+ var playerHtmlEl = document.getElementById(playerEl);
49
+ if (!playerHtmlEl)
50
+ return;
51
+ observer.observe(playerHtmlEl, {
52
+ attributes: false,
53
+ childList: true,
54
+ characterData: false,
55
+ subtree: true,
56
+ });
57
+ })();
58
+ }, []);
59
+ if (!isLoaded || !playerEl)
60
+ return react_1.default.createElement(react_1.default.Fragment, null);
61
+ var htmlEl = document.getElementById('threekitArOverlay');
62
+ if (!htmlEl)
63
+ return react_1.default.createElement(react_1.default.Fragment, null);
64
+ return (0, react_dom_1.createPortal)(children, htmlEl);
65
+ };
66
+ exports.PortalToArOverlay = PortalToArOverlay;
67
+ exports.default = exports.PortalToArOverlay;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { IProducts } from '../../threekit';
2
+ import { IProducts } from '../../types';
3
3
  export interface ProductLayoutProps {
4
4
  products: Record<string, IProducts>;
5
5
  }
@@ -1,5 +1,5 @@
1
1
  /// <reference types="react" />
2
- import { IMetadata } from '../../threekit';
2
+ import { IMetadata } from '../../types';
3
3
  interface WishlistItemProps {
4
4
  thumbnail?: string;
5
5
  metadata?: IMetadata;
@@ -1,6 +1,6 @@
1
1
  import { FunctionComponent } from 'react';
2
2
  import { RawAttributeValue } from '../../hooks/useAttribute';
3
- import { IHydratedAttribute, IHydratedAttributeAssetValue } from '../../threekit';
3
+ import { IHydratedAttribute, IHydratedAttributeAssetValue } from '../../types';
4
4
  export interface IOptionShared {
5
5
  name: string;
6
6
  value: string;
@@ -41,7 +41,7 @@ interface IHydrateAttributeConfig {
41
41
  sort?: string;
42
42
  }
43
43
  export declare const hydrateAttributeForComponent: (attribute: IHydratedAttribute, config: IHydrateAttributeConfig) => {
44
- selected: string | number | boolean | import("../../threekit").IConfigurationAsset | import("../../threekit").IConfigurationColor;
44
+ selected: string | number | boolean | import("../../types").IConfigurationAsset | import("../../types").IConfigurationColor;
45
45
  options: {
46
46
  name: string;
47
47
  handleSelect: () => Promise<void>;
@@ -104,7 +104,7 @@ function formComponentContainer(FormComponent) {
104
104
  var preppedProps = __assign({}, props);
105
105
  if (!hideAttributeTitle && !preppedProps.title)
106
106
  preppedProps.title = attributeData.label;
107
- return (react_1.default.createElement(FormComponent, __assign({}, preppedProps, { title: props.title || attribute, value: selected, onClick: handleSetAttribute, onChange: handleSetAttribute, options: options, isPlayerLoading: isLoading })));
107
+ return (react_1.default.createElement(FormComponent, __assign({}, preppedProps, { value: selected, onClick: handleSetAttribute, onChange: handleSetAttribute, options: options, isPlayerLoading: isLoading })));
108
108
  };
109
109
  }
110
110
  exports.default = formComponentContainer;
@@ -1,4 +1,4 @@
1
- import { IHydratedAttribute, IConfigurationColor } from '../../threekit';
1
+ import { IHydratedAttribute, IConfigurationColor } from '../../types';
2
2
  export declare type RawAttributeValue = string | number | boolean | IConfigurationColor | File | undefined;
3
3
  declare type UseAttributeError = [undefined, undefined];
4
4
  declare type UseAttributeSuccess = [
@@ -1,4 +1,4 @@
1
- import { ISetConfiguration, IHydratedAttribute } from '../../threekit';
1
+ import { ISetConfiguration, IHydratedAttribute } from '../../types';
2
2
  declare type UseConfiguratorError = [undefined, undefined];
3
3
  declare type UseConfiguratorSuccess = [
4
4
  Record<string, IHydratedAttribute>,
@@ -1,3 +1,3 @@
1
- import { IMetadata } from '../../threekit';
1
+ import { IMetadata } from '../../types';
2
2
  declare const useMetadata: () => IMetadata | undefined;
3
3
  export default useMetadata;
@@ -1,8 +1,9 @@
1
- import { IHydratedAttribute, ISetConfiguration } from '../../threekit';
2
- declare type UseNestedConfiguratorError = [undefined, undefined];
1
+ import { IHydratedAttribute, IMetadata, ISetConfiguration } from '../../types';
2
+ declare type UseNestedConfiguratorError = [undefined, undefined, undefined];
3
3
  declare type UseNestedConfiguratorSuccess = [
4
4
  Record<string, IHydratedAttribute>,
5
- (val: ISetConfiguration) => Promise<void>
5
+ (val: ISetConfiguration) => Promise<void>,
6
+ IMetadata
6
7
  ];
7
8
  declare const useNestedConfigurator: (address: string | Array<string>) => UseNestedConfiguratorError | UseNestedConfiguratorSuccess;
8
9
  export default useNestedConfigurator;
@@ -47,10 +47,10 @@ var useNestedConfigurator = function (address) {
47
47
  var playerLoading = (0, store_1.useThreekitSelector)(treble_1.isPlayerLoading);
48
48
  var _a = (0, store_1.useThreekitSelector)(attributes_1.getHydrationData), _ = _a[0], translations = _a[1], language = _a[2];
49
49
  var _b = (0, react_1.useState)(), attributes = _b[0], setAttributes = _b[1];
50
+ var metadataRef = (0, react_1.useRef)({});
50
51
  var configurator = (0, react_1.useRef)();
51
52
  (0, react_1.useEffect)(function () {
52
53
  (function () {
53
- var _a;
54
54
  if (!hasInitialized)
55
55
  return;
56
56
  if (playerLoading)
@@ -59,12 +59,13 @@ var useNestedConfigurator = function (address) {
59
59
  window.threekit.treble.getNestedConfigurator(address);
60
60
  if (!configurator.current)
61
61
  return;
62
- var updatedAttrs = (_a = configurator.current) === null || _a === void 0 ? void 0 : _a.getDisplayAttributes();
62
+ var updatedAttrs = configurator.current.getDisplayAttributes();
63
63
  setAttributes(updatedAttrs);
64
+ metadataRef.current = configurator.current.getMetadata();
64
65
  })();
65
66
  }, [hasInitialized, address, playerLoading]);
66
67
  if (!hasInitialized || !configurator.current || !attributes)
67
- return [undefined, undefined];
68
+ return [undefined, undefined, undefined];
68
69
  var handleSelect = function (config) { return __awaiter(void 0, void 0, void 0, function () {
69
70
  var updatedAttrs;
70
71
  var _a, _b;
@@ -88,6 +89,6 @@ var useNestedConfigurator = function (address) {
88
89
  return Object.assign(output, (_a = {}, _a[attr.name] = attr, _a));
89
90
  }, {});
90
91
  var preppedAttributes = (0, utils_1.hydrateAttribute)([attributeObj, translations, language], handleSelect);
91
- return [preppedAttributes, handleSelect];
92
+ return [preppedAttributes, handleSelect, metadataRef.current];
92
93
  };
93
94
  exports.default = useNestedConfigurator;
@@ -1,4 +1,4 @@
1
- import { ICoordinates } from '../../threekit';
1
+ import { ICoordinates } from '../../types';
2
2
  interface NodeConfig {
3
3
  nodeId: string;
4
4
  paddingStart: number;
@@ -1,5 +1,5 @@
1
1
  import { IMultiPageResponse } from './request';
2
- import { IConfiguration } from '../threekit';
2
+ import { IConfiguration } from '../types';
3
3
  export interface IConfigurationResponse {
4
4
  createdAt: string;
5
5
  customerId: null | string;
package/dist/index.d.ts CHANGED
@@ -33,6 +33,7 @@ import Modal from './components/Modal';
33
33
  import Drawer from './components/Drawer';
34
34
  import Accordion from './components/Accordion';
35
35
  import Tabs from './components/Tabs';
36
+ import PortalToArOverlay from './components/PortalToArOverlay';
36
37
  import PortalToElement from './components/PortalToElement';
37
38
  import AwaitThreekitLoad from './components/AwaitThreekitLoad';
38
39
  import FlatForm from './components/FlatForm';
@@ -44,4 +45,4 @@ import icons from './icons';
44
45
  export * from './icons';
45
46
  import TrebleApp from './components/TrebleApp';
46
47
  import ProductLayout from './components/ProductLayout';
47
- export { useAttribute, useConfigurator, useMetadata, useName, usePlayerLoadingStatus, usePrice, useThreekitInitStatus, useZoom, useSnapshot, useWishlist, useShare, usePlayerPortal, useProductCache, useNestedConfigurator, ThreekitProvider, Player, Button, Cards, Dropdown, Strips, Swatch, Tiles, TilesGroup, Upload, Switch, ProductName, ProductDescription, AttributeTitle, AttributeValue, TotalPrice, message, Modal, Drawer, Accordion, Tabs, PortalToElement, AwaitThreekitLoad, FlatForm, Zoom, Snapshots, Wishlist, Share, icons, TrebleApp, ProductLayout, };
48
+ export { useAttribute, useConfigurator, useMetadata, useName, usePlayerLoadingStatus, usePrice, useThreekitInitStatus, useZoom, useSnapshot, useWishlist, useShare, usePlayerPortal, useProductCache, useNestedConfigurator, ThreekitProvider, Player, Button, Cards, Dropdown, Strips, Swatch, Tiles, TilesGroup, Upload, Switch, ProductName, ProductDescription, AttributeTitle, AttributeValue, TotalPrice, message, Modal, Drawer, Accordion, Tabs, PortalToArOverlay, PortalToElement, AwaitThreekitLoad, FlatForm, Zoom, Snapshots, Wishlist, Share, icons, TrebleApp, ProductLayout, };
package/dist/index.js CHANGED
@@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  return (mod && mod.__esModule) ? mod : { "default": mod };
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.ProductLayout = exports.TrebleApp = exports.icons = exports.Share = exports.Wishlist = exports.Snapshots = exports.Zoom = exports.FlatForm = exports.AwaitThreekitLoad = exports.PortalToElement = exports.Tabs = exports.Accordion = exports.Drawer = exports.Modal = exports.message = exports.TotalPrice = exports.AttributeValue = exports.AttributeTitle = exports.ProductDescription = exports.ProductName = exports.Switch = exports.Upload = exports.TilesGroup = exports.Tiles = exports.Swatch = exports.Strips = exports.Dropdown = exports.Cards = exports.Button = exports.Player = exports.ThreekitProvider = exports.useNestedConfigurator = exports.useProductCache = exports.usePlayerPortal = exports.useShare = exports.useWishlist = exports.useSnapshot = exports.useZoom = exports.useThreekitInitStatus = exports.usePrice = exports.usePlayerLoadingStatus = exports.useName = exports.useMetadata = exports.useConfigurator = exports.useAttribute = void 0;
16
+ exports.ProductLayout = exports.TrebleApp = exports.icons = exports.Share = exports.Wishlist = exports.Snapshots = exports.Zoom = exports.FlatForm = exports.AwaitThreekitLoad = exports.PortalToElement = exports.PortalToArOverlay = exports.Tabs = exports.Accordion = exports.Drawer = exports.Modal = exports.message = exports.TotalPrice = exports.AttributeValue = exports.AttributeTitle = exports.ProductDescription = exports.ProductName = exports.Switch = exports.Upload = exports.TilesGroup = exports.Tiles = exports.Swatch = exports.Strips = exports.Dropdown = exports.Cards = exports.Button = exports.Player = exports.ThreekitProvider = exports.useNestedConfigurator = exports.useProductCache = exports.usePlayerPortal = exports.useShare = exports.useWishlist = exports.useSnapshot = exports.useZoom = exports.useThreekitInitStatus = exports.usePrice = exports.usePlayerLoadingStatus = exports.useName = exports.useMetadata = exports.useConfigurator = exports.useAttribute = void 0;
17
17
  // Hooks
18
18
  var useAttribute_1 = __importDefault(require("./hooks/useAttribute"));
19
19
  exports.useAttribute = useAttribute_1.default;
@@ -92,6 +92,8 @@ exports.Accordion = Accordion_1.default;
92
92
  var Tabs_1 = __importDefault(require("./components/Tabs"));
93
93
  exports.Tabs = Tabs_1.default;
94
94
  // Wrappers
95
+ var PortalToArOverlay_1 = __importDefault(require("./components/PortalToArOverlay"));
96
+ exports.PortalToArOverlay = PortalToArOverlay_1.default;
95
97
  var PortalToElement_1 = __importDefault(require("./components/PortalToElement"));
96
98
  exports.PortalToElement = PortalToElement_1.default;
97
99
  var AwaitThreekitLoad_1 = __importDefault(require("./components/AwaitThreekitLoad"));
@@ -1,5 +1,5 @@
1
1
  import { RootState, ThreekitDispatch } from './index';
2
- import { ISetConfiguration, IThreekitDisplayAttribute } from '../threekit';
2
+ import { ISetConfiguration, IThreekitDisplayAttribute } from '../types';
3
3
  import { ITranslationMap } from '../api/products';
4
4
  /*****************************************************
5
5
  * Types and Interfaces
@@ -1,5 +1,5 @@
1
1
  import { RootState, ThreekitDispatch } from './index';
2
- import { IMetadata, IConfiguration, IProduct } from '../threekit';
2
+ import { IMetadata, IConfiguration, IProduct } from '../types';
3
3
  import { IConnectionConfig } from '../connection';
4
4
  import { IReloadConfig } from './treble';
5
5
  /*****************************************************
@@ -236,7 +236,8 @@ var loadNewProduct = function (config) {
236
236
  }
237
237
  if (shouldCacheProduct)
238
238
  dispatch((0, exports.cacheActiveProduct)({ label: label, thumbnail: thumbnail }));
239
- dispatch((0, exports.setProductId)(undefined));
239
+ if (config)
240
+ dispatch((0, exports.setProductId)(undefined));
240
241
  return [4 /*yield*/, dispatch((0, treble_1.reloadPlayer)(config))];
241
242
  case 1:
242
243
  _a.sent();
@@ -1,5 +1,5 @@
1
1
  import { RootState, ThreekitDispatch } from './index';
2
- import { IProject, IPlayerConfig, IThreekitDisplayAttribute, ISetConfiguration, IConfiguration } from '../threekit';
2
+ import { IProject, IPlayerConfig, IThreekitDisplayAttribute, ISetConfiguration, IConfiguration } from '../types';
3
3
  /*****************************************************
4
4
  * Types and Interfaces
5
5
  ****************************************************/
@@ -350,8 +350,8 @@ var unloadPlayer = function () { return function (dispatch) { return __awaiter(v
350
350
  return __generator(this, function (_a) {
351
351
  switch (_a.label) {
352
352
  case 0:
353
- dispatch((0, exports.setThreekitInitialized)(true));
354
- dispatch((0, exports.setPlayerLoading)(false));
353
+ dispatch((0, exports.setThreekitInitialized)(false));
354
+ dispatch((0, exports.setPlayerLoading)(true));
355
355
  dispatch((0, attributes_1.setAttributes)([]));
356
356
  dispatch((0, product_1.setName)(''));
357
357
  dispatch((0, product_1.setMetadata)({}));
@@ -398,18 +398,21 @@ var reloadPlayer = function (config) {
398
398
  trebleConfig = (0, utils_1.loadTrebleConfig)();
399
399
  playerConfig = Object.assign({}, constants_1.DEFAULT_PLAYER_CONFIG, trebleConfig.player);
400
400
  el = document.getElementById(state.treble.playerElId);
401
- if (state.treble.isThreekitInitialized)
402
- dispatch((0, exports.unloadPlayer)());
403
- return [4 /*yield*/, dispatch((0, exports.initPlayer)({
404
- el: el,
405
- orgId: connectionObj.orgId,
406
- authToken: connectionObj.authToken,
407
- stageId: stageId,
408
- assetId: assetId,
409
- playerConfig: playerConfig,
410
- initialConfiguration: initialConfiguration,
411
- }))];
401
+ if (!state.treble.isThreekitInitialized) return [3 /*break*/, 6];
402
+ return [4 /*yield*/, dispatch((0, exports.unloadPlayer)())];
412
403
  case 5:
404
+ _a.sent();
405
+ _a.label = 6;
406
+ case 6: return [4 /*yield*/, dispatch((0, exports.initPlayer)({
407
+ el: el,
408
+ orgId: connectionObj.orgId,
409
+ authToken: connectionObj.authToken,
410
+ stageId: stageId,
411
+ assetId: assetId,
412
+ playerConfig: playerConfig,
413
+ initialConfiguration: initialConfiguration,
414
+ }))];
415
+ case 7:
413
416
  _a.sent();
414
417
  dispatch((0, price_1.updatePrice)());
415
418
  dispatch((0, product_1.initProduct)());
File without changes
File without changes
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { IThreekitCamera, IConfigurationColor, ICoordinates, IQuaternion, IThreekitDisplayAttribute, ISetConfiguration, IHydratedAttribute } from './threekit';
2
- import { ITrebleConfig, IAttributeTypes } from './threekit';
1
+ import { IThreekitCamera, IConfigurationColor, ICoordinates, IQuaternion, IThreekitDisplayAttribute, ISetConfiguration, IHydratedAttribute } from './types';
2
+ import { ITrebleConfig, IAttributeTypes } from './types';
3
3
  import { RawAttributeValue } from './hooks/useAttribute';
4
4
  import { ITranslationMap } from './api/products';
5
5
  interface ICameraPosition {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threekit-tools/treble",
3
- "version": "0.0.64",
3
+ "version": "0.0.67",
4
4
  "author": "Amaan Saeed",
5
5
  "license": "MIT",
6
6
  "files": [