UNPKG

@zohodesk/components

Version:

Dot UI is a customizable React component library built to deliver a clean, accessible, and developer-friendly UI experience. It offers a growing set of reusable components designed to align with modern design systems and streamline application development

214 lines (168 loc) • 8.57 kB
"use strict"; function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); } Object.defineProperty(exports, "__esModule", { value: true }); exports.Subscribale = void 0; exports.isBreackPointMatched = isBreackPointMatched; exports.windowResizeObserver = exports.isTouchDevice = void 0; function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get.bind(); } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } var breakPointKeys = { minHeight: true, maxHeight: true, minWidth: true, maxWidth: true }; function isValideBreakPoint(breakPoint) { return Object.keys(breakPoint).every(function (key) { return breakPointKeys[key]; }); } function rangeCheck(minValue, maxValue, screenValue) { if (minValue === undefined) { if (maxValue === undefined) { return undefined; } return maxValue >= screenValue; } if (maxValue === undefined) { return minValue <= screenValue; } return minValue <= screenValue && maxValue >= screenValue; } function isTouchDeviceFunc() { // return window.matchMedia("(pointer: coarse)").matches return 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; } // export const isTouchDevice = // 'ontouchstart' in window && navigator.userAgent.match(/mobi/i) ? true : false; var isTouchDevice = isTouchDeviceFunc(); exports.isTouchDevice = isTouchDevice; function isBreackPointMatched(object, screen) { if (!isValideBreakPoint(object)) { // eslint-disable-next-line no-console console.error('only minHeight,maxHeight,minWidth,maxWidth these keys are allowed, your object', JSON.stringify(object)); // return; } var screenWidth = screen.width, screenHeight = screen.height; var minWidth = object.minWidth, maxWidth = object.maxWidth, minHeight = object.minHeight, maxHeight = object.maxHeight; var isWidth = rangeCheck(minWidth, maxWidth, screenWidth); var isHeight = rangeCheck(minHeight, maxHeight, screenHeight); return { isHeight: isHeight, isWidth: isWidth }; } var Subscribale = /*#__PURE__*/function () { function Subscribale() { _classCallCheck(this, Subscribale); this.subscribers = []; } _createClass(Subscribale, [{ key: "connect", value: function connect() {} }, { key: "disconnect", value: function disconnect() {} }, { key: "subscribe", value: function subscribe(func) { this.subscribers.length && this.connect(); this.subscribers.push(func); } }, { key: "unsubscribe", value: function unsubscribe(func) { this.subscribers = this.subscribers.filter(function (s) { return s !== func; }); this.subscribers.length && this.disconnect(); } }, { key: "dispatch", value: function dispatch() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } this.subscribers.forEach(function (subscriber) { subscriber.apply(void 0, args); }); } }]); return Subscribale; }(); exports.Subscribale = Subscribale; var InitSubscribale = /*#__PURE__*/function (_Subscribale) { _inherits(InitSubscribale, _Subscribale); var _super = _createSuper(InitSubscribale); function InitSubscribale() { _classCallCheck(this, InitSubscribale); return _super.apply(this, arguments); } _createClass(InitSubscribale, [{ key: "connect", value: // must be OverWrite function connect() {} // must be OverWrite }, { key: "disconnect", value: function disconnect() {} }, { key: "subscribe", value: function subscribe(func) { !this.subscribers.length && this.connect(); _get(_getPrototypeOf(InitSubscribale.prototype), "subscribe", this).call(this, func); } }, { key: "unsubscribe", value: function unsubscribe(func) { _get(_getPrototypeOf(InitSubscribale.prototype), "unsubscribe", this).call(this, func); !this.subscribers.length && this.disconnect(); } }]); return InitSubscribale; }(Subscribale); var windowResizeObserver = function () { var subscribaleInstance = new InitSubscribale(); var size = { heigth: window.innerHeight, width: window.innerWidth }; function handleResize() { var newSize = { height: window.innerHeight, width: window.innerWidth }; size = newSize; subscribaleInstance.dispatch(newSize); } function addResizeListener() { window.addEventListener('resize', handleResize); handleResize(); } function removeResizeListener() { window.removeEventListener('resize', handleResize); } subscribaleInstance.connect = addResizeListener; subscribaleInstance.disconnect = removeResizeListener; return { getSize: function getSize() { return size; }, resize: subscribaleInstance, isParentSize: true }; }(); exports.windowResizeObserver = windowResizeObserver;