Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
"use strict";

var __rest = this && this.__rest || function (s, e) {
  var t = {};

  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];

  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) t[p[i]] = s[p[i]];
  return t;
};

Object.defineProperty(exports, "__esModule", {
  value: true
});

const chain_able_boost_1 = require("chain-able-boost");

const exotic_1 = require("exotic");

const mobx_1 = require("xmobx/mobx");

const toName = name => {
  switch (name) {
    // case 'size1': return 'Fit'
    // case 'style': return 'Style'
    // case 'color': return 'Color'
    default:
      return chain_able_boost_1.firstToUpperCase(name);
  }
};

exports.toName = toName;
/**
 * used in radio - DOES NOT RESPECT ISDISABLED IF IT ISN'T ENUMERABLE
 */

const convertToOption = option => {
  const {
    name
  } = option,
        remainingProps = __rest(option, ["name"]);

  const label = toName(name);
  return Object.assign({}, remainingProps, {
    value: label,
    label
  });
};

exports.convertToOption = convertToOption;

function defaultOnClickAndOnChangeRadioOption(event, item, state) {
  console.warn('[ProductOptions] defaultOnClickAndOnChangeRadioOption'); // NO_OP
}

exports.defaultOnClickAndOnChangeRadioOption = defaultOnClickAndOnChangeRadioOption; // these are the adapters

const fromItemToValue = item => {
  if (exotic_1.isObj(item) === true) {
    return item.value || item.label;
  } else {
    console.warn('[ProductOptions] RadioGroup - MISSING VALUE FOR ITEM');
    console.dir(item);
    return '@@empty';
  }
};

exports.fromItemToValue = fromItemToValue;

const fromItemToLabel = item => {
  if (exotic_1.isObj(item) === true) {
    // @note - type comes from props, item has the same `label` as `value`
    return item.type || item.label || item.key || item.name;
  } else {
    console.warn('[ProductOptions] RadioGroup - MISSING VALUE FOR ITEM');
    console.dir(item);
    return '@@empty';
  }
};
/**
 * used in square options...
 */


const toOptions = options => {
  const list = options.map(item => {
    return Object.assign({}, item, {
      isSelected: item.isSelected,
      isDisabled: item.isDisabled,
      onClick: item.onClick,
      label: item.name
    });
  });
  return mobx_1.observable(list);
};

exports.toOptions = toOptions; // /**
//  * @todo pooler
//  * @todo put in class
//  */
// class HandlerArguments {
//   @observable event
//   @observable props
//   @observable state
//   @observable ...
//   constructor() {}
//   static init(args) {
//     const instance = new HandlerArguments()
//     Object.assign(instance, args)
//     return instance
//   }
// }
// used in SquareOption and RadioOption
// is not a handler, it's just called on change in a handler

const reusableOnChange = args => {
  const {
    event,
    item,
    props,
    state
  } = args;
  const {
    onClick,
    onChange
  } = props;
  const value = fromItemToValue(Object.assign({}, props, item));
  const label = fromItemToLabel(Object.assign({}, props, item));
  console.debug('[ProductOptions] reusableOnChange');
  console.dir({
    props,
    event,
    item,
    state,
    value,
    label
  }); // @note - this would not work for select dropdown

  if (exotic_1.isFunction(onClick) === true) {
    console.debug('[ProductOptions] onClick');
    onClick(event, {
      label,
      value
    });
  }

  if (exotic_1.isFunction(onChange) === true) {
    console.debug('[ProductOptions] onChange');
    onChange(event, {
      label,
      value
    });
  } // === @note this is old ===
  // onClick()
  // or from state
  // if (isFunction(onClick) === true) {
  //   onClick(value, state)
  // }
  // if (isFunction(onChange) === true) {
  //   onChange(value, state)
  // }

};

exports.reusableOnChange = reusableOnChange;

const convertToOptionFor = type => option => {
  const {
    name
  } = option,
        remainingProps = __rest(option, ["name"]);

  return Object.assign({}, remainingProps, {
    // label = value = name
    label: remainingProps.label || name,
    value: remainingProps.image || name,
    // -.-ß
    // src: ,
    name,
    identifier: name,
    type
  });
};

exports.convertToOptionFor = convertToOptionFor; //# sourceMappingURL=deps.js.map