Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/npmpublish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Node.js Package

on:
release:
types: [created]

jobs:
publish-gpr:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://npm.pkg.github.com/
scope: '@idc-developer'
- run: npm ci
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
# files
node_modules/
example/dist/
dist/

10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ devJS:
@$(NODE_BIN)/watchify -t babelify $(EXAMPLE_SRC)/index.js -o $(EXAMPLE_DIST)/index.js -dv

devCSS:
@$(NODE_BIN)/node-sass $(EXAMPLE_SRC)/index.scss $(EXAMPLE_DIST)/index.css
@$(NODE_BIN)/node-sass $(SRC)/index.scss $(EXAMPLE_DIST)/style.css
@$(NODE_BIN)/node-sass -w $(EXAMPLE_SRC)/index.scss $(EXAMPLE_DIST)/index.css
@$(NODE_BIN)/sass $(EXAMPLE_SRC)/index.scss $(EXAMPLE_DIST)/index.css
@$(NODE_BIN)/sass $(SRC)/index.scss $(EXAMPLE_DIST)/style.css
@$(NODE_BIN)/sass -w $(EXAMPLE_SRC)/index.scss $(EXAMPLE_DIST)/index.css

deployExample:
@$(NODE_BIN)/browserify -t babelify $(EXAMPLE_SRC)/index.js -o $(EXAMPLE_DIST)/index.js -dv
@$(NODE_BIN)/node-sass $(EXAMPLE_SRC)/index.scss $(EXAMPLE_DIST)/index.css
@$(NODE_BIN)/node-sass $(SRC)/index.scss $(EXAMPLE_DIST)/style.css
@$(NODE_BIN)/sass $(EXAMPLE_SRC)/index.scss $(EXAMPLE_DIST)/index.css
@$(NODE_BIN)/sass $(SRC)/index.scss $(EXAMPLE_DIST)/style.css

devServer:
@echo Listening 8888...
Expand Down
2 changes: 1 addition & 1 deletion bin/transferSass.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var sass = require('node-sass')
var sass = require('sass')
var fs = require('fs')
var path = require('path')

Expand Down
11 changes: 11 additions & 0 deletions contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

This doc needs help! Please submit your PR...

## Building a fork locally
Preconditions:
* npm installed and available on path
* unix make is on path (for windows: install cygwin including make, add to path)

## Building
* Clone the git repository
* Install Dependencies: `npm install`
* Run the build: `npm run build`
* If you want to see the examples, start the examples: `npm run start` and open URL http://localhost:8888 in a Browser

## Commit messages

We are using semantic-release to automate the release process, and this depends on a specific format for commit messages. Please run `npm run commit` to use `commitizen` to properly format your commit messages so they can be automatically processed and included in release notes.
Expand Down
13 changes: 13 additions & 0 deletions dist/constant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

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

GLOBAL: {
HIDE: '__react_tooltip_hide_event',
REBUILD: '__react_tooltip_rebuild_event',
SHOW: '__react_tooltip_show_event'
}
};
132 changes: 132 additions & 0 deletions dist/decorators/bodyMode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
'use strict';

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

exports.default = function (target) {
target.prototype.isBodyMode = function () {
return !!this.props.bodyMode;
};

target.prototype.bindBodyListener = function (targetArray) {
var _this = this;

var _state = this.state,
event = _state.event,
eventOff = _state.eventOff,
possibleCustomEvents = _state.possibleCustomEvents,
possibleCustomEventsOff = _state.possibleCustomEventsOff;

var body = getBody();

var customEvents = findCustomEvents(targetArray, 'data-event');
var customEventsOff = findCustomEvents(targetArray, 'data-event-off');

if (event != null) customEvents[event] = true;
if (eventOff != null) customEventsOff[eventOff] = true;
possibleCustomEvents.split(' ').forEach(function (event) {
return customEvents[event] = true;
});
possibleCustomEventsOff.split(' ').forEach(function (event) {
return customEventsOff[event] = true;
});

this.unbindBodyListener(body);

var listeners = this.bodyModeListeners = {};
if (event == null) {
listeners.mouseover = bodyListener.bind(this, this.showTooltip, {});
listeners.mousemove = bodyListener.bind(this, this.updateTooltip, { respectEffect: true });
listeners.mouseout = bodyListener.bind(this, this.hideTooltip, {});
}

for (var _event in customEvents) {
listeners[_event] = bodyListener.bind(this, function (e) {
var targetEventOff = e.currentTarget.getAttribute('data-event-off') || eventOff;
_customEvent.checkStatus.call(_this, targetEventOff, e);
}, { customEvent: true });
}
for (var _event2 in customEventsOff) {
listeners[_event2] = bodyListener.bind(this, this.hideTooltip, { customEvent: true });
}
for (var _event3 in listeners) {
body.addEventListener(_event3, listeners[_event3]);
}
};

target.prototype.unbindBodyListener = function (body) {
body = body || getBody();

var listeners = this.bodyModeListeners;
for (var event in listeners) {
body.removeEventListener(event, listeners[event]);
}
};
};

var _customEvent = require('./customEvent');

var makeProxy = function makeProxy(e) {
var proxy = {};
for (var key in e) {
if (typeof e[key] === 'function') {
proxy[key] = e[key].bind(e);
} else {
proxy[key] = e[key];
}
}
return proxy;
}; /**
* Util method to get effect
*/


var bodyListener = function bodyListener(callback, options, e) {
var _options$respectEffec = options.respectEffect,
respectEffect = _options$respectEffec === undefined ? false : _options$respectEffec,
_options$customEvent = options.customEvent,
customEvent = _options$customEvent === undefined ? false : _options$customEvent;
var id = this.props.id;

var tip = null;
var forId = void 0;
var target = e.target;
var lastTarget = void 0;
// walk up parent chain until tip is found
// there is no match if parent visible area is matched by mouse position, so some corner cases might not work as expected
while (tip === null && target !== null) {
lastTarget = target;
tip = target.getAttribute('data-tip') || null;
forId = target.getAttribute('data-for') || null;
target = target.parentElement;
}
target = lastTarget || e.target;
if (this.isCustomEvent(target) && !customEvent) {
return;
}

var isTargetBelongsToTooltip = id == null && forId == null || forId === id;

if (tip != null && (!respectEffect || this.getEffect(target) === 'float') && isTargetBelongsToTooltip) {
var proxy = makeProxy(e);
proxy.currentTarget = target;
callback(proxy);
}
};

var findCustomEvents = function findCustomEvents(targetArray, dataAttribute) {
var events = {};
targetArray.forEach(function (target) {
var event = target.getAttribute(dataAttribute);
if (event) event.split(' ').forEach(function (event) {
return events[event] = true;
});
});

return events;
};

var getBody = function getBody() {
return document.getElementsByTagName('body')[0];
};
110 changes: 110 additions & 0 deletions dist/decorators/customEvent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
'use strict';

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

exports.default = function (target) {
target.prototype.isCustomEvent = function (ele) {
var event = this.state.event;

return event || !!ele.getAttribute('data-event');
};

/* Bind listener for custom event */
target.prototype.customBindListener = function (ele) {
var _this = this;

var _state = this.state,
event = _state.event,
eventOff = _state.eventOff;

var dataEvent = ele.getAttribute('data-event') || event;
var dataEventOff = ele.getAttribute('data-event-off') || eventOff;

dataEvent.split(' ').forEach(function (event) {
ele.removeEventListener(event, customListeners.get(ele, event));
var customListener = checkStatus.bind(_this, dataEventOff);
customListeners.set(ele, event, customListener);
ele.addEventListener(event, customListener, false);
});
if (dataEventOff) {
dataEventOff.split(' ').forEach(function (event) {
ele.removeEventListener(event, _this.hideTooltip);
ele.addEventListener(event, _this.hideTooltip, false);
});
}
};

/* Unbind listener for custom event */
target.prototype.customUnbindListener = function (ele) {
var _state2 = this.state,
event = _state2.event,
eventOff = _state2.eventOff;

var dataEvent = event || ele.getAttribute('data-event');
var dataEventOff = eventOff || ele.getAttribute('data-event-off');

ele.removeEventListener(dataEvent, customListeners.get(ele, event));
if (dataEventOff) ele.removeEventListener(dataEventOff, this.hideTooltip);
};
};

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/**
* Custom events to control showing and hiding of tooltip
*
* @attributes
* - `event` {String}
* - `eventOff` {String}
*/

var checkStatus = exports.checkStatus = function checkStatus(dataEventOff, e) {
var show = this.state.show;
var id = this.props.id;

var isCapture = this.isCapture(e.currentTarget);
var currentItem = e.currentTarget.getAttribute('currentItem');

if (!isCapture) e.stopPropagation();
if (show && currentItem === 'true') {
if (!dataEventOff) this.hideTooltip(e);
} else {
e.currentTarget.setAttribute('currentItem', 'true');
setUntargetItems(e.currentTarget, this.getTargetArray(id));
this.showTooltip(e);
}
};

var setUntargetItems = function setUntargetItems(currentTarget, targetArray) {
for (var i = 0; i < targetArray.length; i++) {
if (currentTarget !== targetArray[i]) {
targetArray[i].setAttribute('currentItem', 'false');
} else {
targetArray[i].setAttribute('currentItem', 'true');
}
}
};

var customListeners = {
id: '9b69f92e-d3fe-498b-b1b4-c5e63a51b0cf',
set: function set(target, event, listener) {
if (this.id in target) {
var map = target[this.id];
map[event] = listener;
} else {
// this is workaround for WeakMap, which is not supported in older browsers, such as IE
Object.defineProperty(target, this.id, {
configurable: true,
value: _defineProperty({}, event, listener)
});
}
},
get: function get(target, event) {
var map = target[this.id];
if (map !== undefined) {
return map[event];
}
}
};
12 changes: 12 additions & 0 deletions dist/decorators/getEffect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

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

exports.default = function (target) {
target.prototype.getEffect = function (currentTarget) {
var dataEffect = currentTarget.getAttribute('data-effect');
return dataEffect || this.props.effect || 'float';
};
};
11 changes: 11 additions & 0 deletions dist/decorators/isCapture.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

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

exports.default = function (target) {
target.prototype.isCapture = function (currentTarget) {
return currentTarget && currentTarget.getAttribute('data-iscapture') === 'true' || this.props.isCapture || false;
};
};
Loading