@arc-fusion/pb-editor-wrapper
Advanced tools
Comparing version 1.0.15 to 1.0.16
@@ -10,3 +10,3 @@ "use strict"; | ||
var siblings = []; | ||
var selectedNode = enterNode.nextSibling; | ||
var selectedNode = enterNode === null || enterNode === void 0 ? void 0 : enterNode.nextSibling; | ||
@@ -13,0 +13,0 @@ while (selectedNode && !selectedNode.matches("[data-fusion-component=\"".concat(fingerprint, "\"]"))) { |
"use strict"; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
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); } | ||
@@ -20,6 +20,12 @@ Object.defineProperty(exports, "__esModule", { | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } | ||
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var FeatureWrapper = function FeatureWrapper(_ref) { | ||
@@ -31,2 +37,52 @@ var fingerprint = _ref.fingerprint, | ||
var enterRef = (0, _react.useRef)(); | ||
(0, _react.useEffect)(function () { | ||
var _enterNode$nextSiblin; | ||
if (isChain) return; | ||
var enterNode = _reactDom.default.findDOMNode(enterRef.current); | ||
addMouseEventsToSiblings(enterNode); // observe enterNode with no added siblings | ||
if (enterNode !== null && enterNode !== void 0 && (_enterNode$nextSiblin = enterNode.nextSibling) !== null && _enterNode$nextSiblin !== void 0 && _enterNode$nextSiblin.matches("[data-fusion-component=\"".concat(fingerprint, "\"]"))) { | ||
observeBoundaries(enterNode); | ||
} | ||
return function () { | ||
removeMouseEventsFromSiblings(enterNode); | ||
}; | ||
}); | ||
function observeBoundaries(enterNode) { | ||
var parentNode = enterNode.parentNode; | ||
var config = { | ||
childList: true | ||
}; | ||
var observer = new MutationObserver(callback); | ||
observer.observe(parentNode, config); | ||
function callback(mutationsList) { | ||
var _iterator = _createForOfIteratorHelper(mutationsList), | ||
_step; | ||
try { | ||
for (_iterator.s(); !(_step = _iterator.n()).done;) { | ||
var _mutation$addedNodes; | ||
var mutation = _step.value; | ||
if ((mutation === null || mutation === void 0 ? void 0 : mutation.type) === 'childList' && mutation !== null && mutation !== void 0 && (_mutation$addedNodes = mutation.addedNodes) !== null && _mutation$addedNodes !== void 0 && _mutation$addedNodes.length) { | ||
addMouseEventsToSiblings(enterNode); | ||
} else { | ||
observer.disconnect(); | ||
} | ||
} | ||
} catch (err) { | ||
_iterator.e(err); | ||
} finally { | ||
_iterator.f(); | ||
} | ||
} | ||
} | ||
var previewEvents = { | ||
@@ -61,15 +117,4 @@ generateHover: function generateHover(component) { | ||
(0, _react.useEffect)(function () { | ||
if (isChain) return; | ||
var enterNode = _reactDom.default.findDOMNode(enterRef.current); | ||
function addMouseEventsToSiblings(enterNode) { | ||
var siblingNodes = (0, _getSiblingNodes.getSiblingNodes)(fingerprint, enterNode); | ||
addMouseEvents(siblingNodes); | ||
return function () { | ||
removeMouseEvents(siblingNodes); | ||
}; | ||
}); | ||
function addMouseEvents(siblingNodes) { | ||
siblingNodes.forEach(function (element) { | ||
@@ -81,3 +126,4 @@ element === null || element === void 0 ? void 0 : element.addEventListener('mouseenter', onFeatureHover); | ||
function removeMouseEvents(siblingNodes) { | ||
function removeMouseEventsFromSiblings(enterNode) { | ||
var siblingNodes = (0, _getSiblingNodes.getSiblingNodes)(fingerprint, enterNode); | ||
siblingNodes.forEach(function (element) { | ||
@@ -84,0 +130,0 @@ element === null || element === void 0 ? void 0 : element.removeEventListener('mouseenter', onFeatureHover); |
{ | ||
"name": "@arc-fusion/pb-editor-wrapper", | ||
"description": "PageBuilder Preview Wrapper", | ||
"version": "1.0.15", | ||
"version": "1.0.16", | ||
"module": "dist/index.js", | ||
@@ -16,3 +16,3 @@ "files": [ | ||
"clean": "rimraf dist", | ||
"build": "npm run clean && cross-env NODE_ENV=production babel src/components --out-dir dist --copy-files --ignore __tests__,spec.js,test.js,stories.js,__snapshots__", | ||
"build": "cross-env NODE_ENV=production babel src/components --out-dir dist --copy-files --ignore __tests__,spec.js,test.js,stories.js,__snapshots__", | ||
"build-watch": "watch 'npm run build && npm run local-publish' ./src", | ||
@@ -19,0 +19,0 @@ "local-publish": "yalc publish --private" |
10540
155