-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(view): refactor block-card logic and api
- Loading branch information
1 parent
1a51bc9
commit 315bfbb
Showing
4 changed files
with
71 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { DOMNode, DOMSelection } from "./dom"; | ||
|
||
export const FAKE_LEFT_BLOCK_CARD_OFFSET = -1; | ||
|
||
export const FAKE_RIGHT_BLOCK_CARD_OFFSET = -2; | ||
|
||
export function hasBlockCardWithNode(node: DOMNode) { | ||
return node && (node.parentElement.hasAttribute('card-target') || (node instanceof HTMLElement && node.hasAttribute('card-target'))); | ||
} | ||
|
||
export function hasBlockCard(selection: DOMSelection) { | ||
return hasBlockCardWithNode(selection?.anchorNode) || hasBlockCardWithNode(selection?.focusNode); | ||
} | ||
|
||
export function getCardTargetAttribute(node: DOMNode) { | ||
return node.parentElement.attributes['card-target'] || (node instanceof HTMLElement && node.attributes['card-target']); | ||
} | ||
|
||
export function isCardLeft(node: DOMNode) { | ||
const cardTarget = getCardTargetAttribute(node); | ||
return cardTarget && cardTarget.nodeValue === 'card-left'; | ||
} | ||
|
||
export function isCardLeftByTargetAttr(targetAttr: any) { | ||
return targetAttr && targetAttr.nodeValue === 'card-left'; | ||
} | ||
|
||
export function isCardRightByTargetAttr(targetAttr: any) { | ||
return targetAttr && targetAttr.nodeValue === 'card-right'; | ||
} | ||
|
||
export function isCardCenterByTargetAttr(targetAttr: any) { | ||
return targetAttr && targetAttr.nodeValue === 'card-center'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters