Skip to content

Commit

Permalink
feat: support import from node, #1064
Browse files Browse the repository at this point in the history
  • Loading branch information
Javey committed Feb 11, 2025
1 parent 7734571 commit 5d25963
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 3 additions & 3 deletions hooks/useDocumentClick.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {RefObject, onMounted, onUnmounted} from 'intact';
import {isFunction} from 'intact-shared';
import {isFunction, hasDocumentAvailable} from 'intact-shared';

export interface IgnoreClickEvent extends MouseEvent {
_ignore?: boolean
Expand All @@ -16,15 +16,15 @@ let getNow = Date.now;
// timestamp can either be hi-res (relative to page load) or low-res
// (relative to UNIX epoch), so in order to compare time we have to use the
// same timestamp type when saving the flush timestamp.
if (getNow() > document.createEvent('Event').timeStamp) {
if (hasDocumentAvailable && getNow() > document.createEvent('Event').timeStamp) {
// if the low-res timestamp which is bigger than the event timestamp
// (which is evaluated AFTER) it means the event is using a hi-res timestamp,
// and we need to use the hi-res version for event listeners as well.
getNow = () => performance.now();
}
// #3485: Firefox <= 53 has incorrect Event.timeStamp implementation
// and does not fire microtasks in between event propagation, so safe to exclude.
const ffMatch = navigator.userAgent.match(/firefox\/(\d+)/i);
const ffMatch = hasDocumentAvailable ? navigator.userAgent.match(/firefox\/(\d+)/i) : null;
const skipTimestampCheck = !!(ffMatch && Number(ffMatch[1]) <= 53);

export function useDocumentClick(
Expand Down
3 changes: 2 additions & 1 deletion styles/global.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {injectGlobal, css} from '@emotion/css';
import {theme} from './theme';
import {palette} from '../styles/utils';
import { hasDocumentAvailable } from 'intact-shared';

const slideDirections = {
down: 'center top 0',
Expand All @@ -9,7 +10,7 @@ const slideDirections = {
right: 'left center 0',
};

if (!/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)) {
if (hasDocumentAvailable && !/(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)) {
document.body.classList.add('k-customize-scrollbar');
}

Expand Down

0 comments on commit 5d25963

Please sign in to comment.