@threekit-tools/treble 0.0.40 → 0.0.44

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.
@@ -2,7 +2,8 @@ import React from 'react';
2
2
  interface AccordionItemProps extends React.FC {
3
3
  selected: boolean;
4
4
  label: string;
5
- handleClick: () => void;
5
+ handleSelect: () => void;
6
+ onClick: () => void;
6
7
  }
7
8
  interface AccordionProps<T> {
8
9
  children: React.FunctionComponentElement<T>;
@@ -27,9 +27,9 @@ var react_1 = __importStar(require("react"));
27
27
  var accordion_styles_1 = require("./accordion.styles");
28
28
  var CaretDown_1 = __importDefault(require("../../icons/CaretDown"));
29
29
  var AccordionItem = function (props) {
30
- var selected = props.selected, handleClick = props.handleClick, label = props.label, children = props.children;
30
+ var selected = props.selected, handleSelect = props.handleSelect, label = props.label, children = props.children;
31
31
  return (react_1.default.createElement(accordion_styles_1.Wrapper, { selected: selected },
32
- react_1.default.createElement("div", { onClick: handleClick },
32
+ react_1.default.createElement("div", { onClick: handleSelect },
33
33
  react_1.default.createElement("div", null, label),
34
34
  react_1.default.createElement("div", null),
35
35
  react_1.default.createElement("div", null,
@@ -54,7 +54,11 @@ var Accordion = function (props) {
54
54
  return null;
55
55
  return react_1.default.cloneElement(child, {
56
56
  selected: selected === idx,
57
- handleClick: function () { return handleSelect(idx); },
57
+ handleSelect: function () {
58
+ if (child.props.onClick)
59
+ child.props.onClick();
60
+ handleSelect(idx);
61
+ },
58
62
  });
59
63
  });
60
64
  };
@@ -1,8 +1,7 @@
1
1
  import React from 'react';
2
2
  interface TabPaneProps extends React.FC {
3
- selected: boolean;
4
3
  label: string;
5
- handleClick: () => void;
4
+ onClick: () => void;
6
5
  }
7
6
  interface TabsProps<T> {
8
7
  children: React.FunctionComponentElement<T>;
@@ -26,26 +26,25 @@ var TabPane = function (props) { return react_1.default.createElement(react_1.de
26
26
  var Tabs = function (_a) {
27
27
  var children = _a.children;
28
28
  var _b = (0, react_1.useState)(0), selected = _b[0], setSelected = _b[1];
29
- var handleSelect = function (idx) {
30
- return setSelected(idx === selected ? undefined : idx);
31
- };
29
+ var handleSelect = function (idx) { return setSelected(idx); };
32
30
  if (!children)
33
31
  return null;
34
32
  return (react_1.default.createElement(tabs_styles_1.Wrapper, null,
35
33
  react_1.default.createElement(tabs_styles_1.TabsWrapper, null, react_1.default.Children.map(children, function (child, idx) {
36
34
  if (child.type !== TabPane)
37
35
  return null;
38
- return (react_1.default.createElement(tabs_styles_1.Tab, { selected: selected === idx, onClick: function () { return handleSelect(idx); } }, child.props.label));
36
+ return (react_1.default.createElement(tabs_styles_1.Tab, { selected: selected === idx, onClick: function () {
37
+ if (child.props.onClick)
38
+ child.props.onClick();
39
+ handleSelect(idx);
40
+ } }, child.props.label));
39
41
  })),
40
42
  react_1.default.createElement(tabs_styles_1.TabContent, null, react_1.default.Children.map(children, function (child, idx) {
41
43
  if (child.type !== TabPane)
42
44
  return null;
43
45
  if (selected !== idx)
44
46
  return null;
45
- return react_1.default.cloneElement(child, {
46
- selected: selected === idx,
47
- handleClick: function () { return handleSelect(idx); },
48
- });
47
+ return child;
49
48
  }))));
50
49
  };
51
50
  exports.Tabs = Tabs;
@@ -33,8 +33,8 @@ var App = function (props) {
33
33
  var dispatch = (0, store_1.useThreekitDispatch)();
34
34
  (0, react_1.useEffect)(function () {
35
35
  var init = function () {
36
- var playerConfig = props.playerConfig, project = props.project, locale = props.locale, threekitEnv = props.threekitEnv;
37
- dispatch((0, threekit_1.launch)({ playerConfig: playerConfig, project: project, locale: locale, threekitEnv: threekitEnv }));
36
+ var playerConfig = props.playerConfig, project = props.project, locale = props.locale, threekitEnv = props.threekitEnv, eventHandlers = props.eventHandlers;
37
+ dispatch((0, threekit_1.launch)({ playerConfig: playerConfig, project: project, locale: locale, threekitEnv: threekitEnv, eventHandlers: eventHandlers }));
38
38
  };
39
39
  init();
40
40
  return;
@@ -45,6 +45,6 @@ var ThreekitProvider = function (props) {
45
45
  return (react_1.default.createElement(react_redux_1.Provider, { store: store_1.default },
46
46
  react_1.default.createElement(styled_components_1.ThemeProvider, { theme: theme_1.default },
47
47
  react_1.default.createElement(GlobalStyles_styles_1.default, null),
48
- react_1.default.createElement(App, { locale: props.locale, project: props.project, playerConfig: props.playerConfig, threekitEnv: props.threekitEnv }, props.children))));
48
+ react_1.default.createElement(App, { locale: props.locale, project: props.project, playerConfig: props.playerConfig, threekitEnv: props.threekitEnv, eventHandlers: props.eventHandlers }, props.children))));
49
49
  };
50
50
  exports.default = ThreekitProvider;
@@ -1,5 +1,5 @@
1
1
  import { IConfigurationColor, IThreekitDisplayAttribute } from '../../threekit';
2
- export declare type AttributeValue = string | number | IConfigurationColor;
2
+ export declare type AttributeValue = string | number | boolean | IConfigurationColor;
3
3
  declare type UseAttributeError = [undefined, undefined];
4
4
  declare type UseAttributeSuccess = [
5
5
  IThreekitDisplayAttribute,
@@ -16,8 +16,6 @@ var useAttribute = function (attributeName) {
16
16
  var handleChange = function (value) {
17
17
  var _a;
18
18
  var preppedValue = (0, utils_1.selectionToConfiguration)(value, attribute.type);
19
- if (!preppedValue)
20
- return;
21
19
  dispatch((0, threekit_1.setConfiguration)((_a = {},
22
20
  _a[attributeName] = preppedValue,
23
21
  _a)));
@@ -5,11 +5,15 @@ import { ISaveConfigurationConfig, WishlistArray } from '../Treble';
5
5
  /*****************************************************
6
6
  * Types and Interfaces
7
7
  ****************************************************/
8
+ interface EventHandlers {
9
+ postConfigurationChange?: (updatedAttributes: Array<IThreekitDisplayAttribute>, configurationChange: ISetConfiguration, previousConfiguration: Array<IThreekitDisplayAttribute>) => void | Promise<void>;
10
+ }
8
11
  export interface ILaunchConfig {
9
12
  threekitEnv: string;
10
13
  locale: string;
11
14
  project: IProject;
12
15
  playerConfig: IPlayerConfig;
16
+ eventHandlers: EventHandlers;
13
17
  }
14
18
  interface IPriceConfig {
15
19
  id: string;
@@ -84,6 +84,10 @@ var createPlayerLoaderEl = function (elementId) {
84
84
  document.body.appendChild(playerLoader);
85
85
  return playerElement;
86
86
  };
87
+ /*****************************************************
88
+ * Constants and Event Handlers
89
+ ****************************************************/
90
+ var EVENTS = {};
87
91
  var initialState = {
88
92
  // Player HTML element
89
93
  playerElId: undefined,
@@ -357,6 +361,8 @@ var launch = function (launchConfig) {
357
361
  dispatch(setLanguage(launchConfig.locale));
358
362
  dispatch(setTranslations(translations));
359
363
  }
364
+ if (launchConfig === null || launchConfig === void 0 ? void 0 : launchConfig.eventHandlers)
365
+ EVENTS = Object.assign(EVENTS, launchConfig.eventHandlers);
360
366
  if (pricebook.length) {
361
367
  priceConfig = {
362
368
  id: pricebook[0].id,
@@ -384,15 +390,22 @@ var launch = function (launchConfig) {
384
390
  exports.launch = launch;
385
391
  // Configurator
386
392
  var setConfiguration = function (config) { return function (dispatch) { return __awaiter(void 0, void 0, void 0, function () {
387
- var updatedAttributes;
393
+ var previousConfiguration, updatedAttributes;
388
394
  return __generator(this, function (_a) {
389
395
  switch (_a.label) {
390
396
  case 0:
397
+ previousConfiguration = window.threekit.configurator.getDisplayAttributes();
391
398
  dispatch(setPlayerLoading(true));
392
399
  return [4 /*yield*/, window.threekit.configurator.setConfiguration(config)];
393
400
  case 1:
394
401
  _a.sent();
395
402
  updatedAttributes = window.threekit.configurator.getDisplayAttributes();
403
+ if (!EVENTS.postConfigurationChange) return [3 /*break*/, 3];
404
+ return [4 /*yield*/, EVENTS.postConfigurationChange(updatedAttributes, config, previousConfiguration)];
405
+ case 2:
406
+ _a.sent();
407
+ _a.label = 3;
408
+ case 3:
396
409
  dispatch(setAttributes(updatedAttributes));
397
410
  dispatch(setPlayerLoading(false));
398
411
  return [2 /*return*/];
package/dist/utils.d.ts CHANGED
@@ -53,9 +53,9 @@ export declare const metadataValueToObject: (data: string) => Record<string, str
53
53
  */
54
54
  export declare const createThreekitScriptEl: (threekitDomain: string) => Promise<void>;
55
55
  export declare const translateAttribute: (attributes: Array<IThreekitDisplayAttribute>, translations?: ITranslationMap | undefined, language?: string | undefined) => IThreekitDisplayAttribute;
56
- export declare const selectionToConfiguration: (value: string | number | IConfigurationColor, attributeType: string) => string | number | IConfigurationColor | {
57
- assetId: string | number | IConfigurationColor;
58
- } | undefined;
56
+ export declare const selectionToConfiguration: (value: string | number | boolean | IConfigurationColor, attributeType: string) => string | number | boolean | IConfigurationColor | {
57
+ assetId: string | number | boolean | IConfigurationColor;
58
+ };
59
59
  export declare const filterFormAttributes: (attributes: Record<string, IThreekitDisplayAttribute>, attributeComponentProps: IAttributesComponentProps, includeReservedAttributes: boolean) => IThreekitDisplayAttribute[];
60
60
  export declare const isUuid: (str?: string | undefined) => boolean;
61
61
  export declare const loadTrebleConfig: () => Partial<ITrebleConfig>;
package/dist/utils.js CHANGED
@@ -306,8 +306,6 @@ var translateAttribute = function (attributes, translations, language) {
306
306
  };
307
307
  exports.translateAttribute = translateAttribute;
308
308
  var selectionToConfiguration = function (value, attributeType) {
309
- if (!value)
310
- return undefined;
311
309
  switch (attributeType) {
312
310
  case constants_1.ATTRIBUTE_TYPES.number:
313
311
  case constants_1.ATTRIBUTE_TYPES.string:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@threekit-tools/treble",
3
- "version": "0.0.40",
3
+ "version": "0.0.44",
4
4
  "author": "Amaan Saeed",
5
5
  "license": "MIT",
6
6
  "files": [