How to use offsetNode method in stryker-parent

Best JavaScript code snippet using stryker-parent

index.ts

Source:index.ts Github

copy

Full Screen

1/** @module @lexical/offset */2/**3 * Copyright (c) Meta Platforms, Inc. and affiliates.4 *5 * This source code is licensed under the MIT license found in the6 * LICENSE file in the root directory of this source tree.7 *8 */9import type {10 EditorState,11 LexicalEditor,12 NodeKey,13 NodeMap,14 RangeSelection,15 RootNode,16} from 'lexical';17import {18 $createRangeSelection,19 $getNodeByKey,20 $isElementNode,21 $isTextNode,22} from 'lexical';23import invariant from 'shared/invariant';24type OffsetElementNode = {25 child: null | OffsetNode;26 end: number;27 key: NodeKey;28 next: null | OffsetNode;29 parent: null | OffsetElementNode;30 prev: null | OffsetNode;31 start: number;32 type: 'element';33};34type OffsetTextNode = {35 child: null;36 end: number;37 key: NodeKey;38 next: null | OffsetNode;39 parent: null | OffsetElementNode;40 prev: null | OffsetNode;41 start: number;42 type: 'text';43};44type OffsetInlineNode = {45 child: null;46 end: number;47 key: NodeKey;48 next: null | OffsetNode;49 parent: null | OffsetElementNode;50 prev: null | OffsetNode;51 start: number;52 type: 'inline';53};54type OffsetNode = OffsetElementNode | OffsetTextNode | OffsetInlineNode;55type OffsetMap = Map<NodeKey, OffsetNode>;56export class OffsetView {57 _offsetMap: OffsetMap;58 _firstNode: null | OffsetNode;59 _blockOffsetSize: number;60 constructor(61 offsetMap: OffsetMap,62 firstNode: null | OffsetNode,63 blockOffsetSize = 1,64 ) {65 this._offsetMap = offsetMap;66 this._firstNode = firstNode;67 this._blockOffsetSize = blockOffsetSize;68 }69 createSelectionFromOffsets(70 originalStart: number,71 originalEnd: number,72 diffOffsetView?: OffsetView,73 ): null | RangeSelection {74 const firstNode = this._firstNode;75 if (firstNode === null) {76 return null;77 }78 let start = originalStart;79 let end = originalEnd;80 let startOffsetNode = $searchForNodeWithOffset(81 firstNode,82 start,83 this._blockOffsetSize,84 );85 let endOffsetNode = $searchForNodeWithOffset(86 firstNode,87 end,88 this._blockOffsetSize,89 );90 if (diffOffsetView !== undefined) {91 start = $getAdjustedOffsetFromDiff(92 start,93 startOffsetNode,94 diffOffsetView,95 this,96 this._blockOffsetSize,97 );98 startOffsetNode = $searchForNodeWithOffset(99 firstNode,100 start,101 this._blockOffsetSize,102 );103 end = $getAdjustedOffsetFromDiff(104 end,105 endOffsetNode,106 diffOffsetView,107 this,108 this._blockOffsetSize,109 );110 endOffsetNode = $searchForNodeWithOffset(111 firstNode,112 end,113 this._blockOffsetSize,114 );115 }116 if (startOffsetNode === null || endOffsetNode === null) {117 return null;118 }119 let startKey = startOffsetNode.key;120 let endKey = endOffsetNode.key;121 const startNode = $getNodeByKey(startKey);122 const endNode = $getNodeByKey(endKey);123 if (startNode === null || endNode === null) {124 return null;125 }126 let startOffset = 0;127 let endOffset = 0;128 let startType: 'element' | 'text' = 'element';129 let endType: 'element' | 'text' = 'element';130 if (startOffsetNode.type === 'text') {131 startOffset = start - startOffsetNode.start;132 startType = 'text';133 // If we are at the edge of a text node and we134 // don't have a collapsed selection, then let's135 // try and correct the offset node.136 const sibling = startNode.getNextSibling();137 if (138 start !== end &&139 startOffset === startNode.getTextContentSize() &&140 $isTextNode(sibling)141 ) {142 startOffset = 0;143 startKey = sibling.__key;144 }145 } else if (startOffsetNode.type === 'inline') {146 startKey = startNode.getParentOrThrow().getKey();147 startOffset =148 end > startOffsetNode.start149 ? startOffsetNode.end150 : startOffsetNode.start;151 }152 if (endOffsetNode.type === 'text') {153 endOffset = end - endOffsetNode.start;154 endType = 'text';155 } else if (endOffsetNode.type === 'inline') {156 endKey = endNode.getParentOrThrow().getKey();157 endOffset =158 end > endOffsetNode.start ? endOffsetNode.end : endOffsetNode.start;159 }160 const selection = $createRangeSelection();161 if (selection === null) {162 return null;163 }164 selection.anchor.set(startKey, startOffset, startType);165 selection.focus.set(endKey, endOffset, endType);166 return selection;167 }168 getOffsetsFromSelection(selection: RangeSelection): [number, number] {169 const anchor = selection.anchor;170 const focus = selection.focus;171 const offsetMap = this._offsetMap;172 const anchorOffset = anchor.offset;173 const focusOffset = focus.offset;174 let start = -1;175 let end = -1;176 if (anchor.type === 'text') {177 const offsetNode = offsetMap.get(anchor.key);178 if (offsetNode !== undefined) {179 start = offsetNode.start + anchorOffset;180 }181 } else {182 const node = anchor.getNode().getDescendantByIndex(anchorOffset);183 if (node !== null) {184 const offsetNode = offsetMap.get(node.getKey());185 if (offsetNode !== undefined) {186 const isAtEnd = node.getIndexWithinParent() !== anchorOffset;187 start = isAtEnd ? offsetNode.end : offsetNode.start;188 }189 }190 }191 if (focus.type === 'text') {192 const offsetNode = offsetMap.get(focus.key);193 if (offsetNode !== undefined) {194 end = offsetNode.start + focus.offset;195 }196 } else {197 const node = focus.getNode().getDescendantByIndex(focusOffset);198 if (node !== null) {199 const offsetNode = offsetMap.get(node.getKey());200 if (offsetNode !== undefined) {201 const isAtEnd = node.getIndexWithinParent() !== focusOffset;202 end = isAtEnd ? offsetNode.end : offsetNode.start;203 }204 }205 }206 return [start, end];207 }208}209function $getAdjustedOffsetFromDiff(210 offset: number,211 offsetNode: null | OffsetNode,212 prevOffsetView: OffsetView,213 offsetView: OffsetView,214 blockOffsetSize: number,215): number {216 const prevOffsetMap = prevOffsetView._offsetMap;217 const offsetMap = offsetView._offsetMap;218 const visited = new Set();219 let adjustedOffset = offset;220 let currentNode = offsetNode;221 while (currentNode !== null) {222 const key = currentNode.key;223 const prevNode = prevOffsetMap.get(key);224 const diff = currentNode.end - currentNode.start;225 visited.add(key);226 if (prevNode === undefined) {227 adjustedOffset += diff;228 } else {229 const prevDiff = prevNode.end - prevNode.start;230 if (prevDiff !== diff) {231 adjustedOffset += diff - prevDiff;232 }233 }234 const sibling = currentNode.prev;235 if (sibling !== null) {236 currentNode = sibling;237 continue;238 }239 let parent = currentNode.parent;240 while (parent !== null) {241 let parentSibling = parent.prev;242 if (parentSibling !== null) {243 const parentSiblingKey = parentSibling.key;244 const prevParentSibling = prevOffsetMap.get(parentSiblingKey);245 const parentDiff = parentSibling.end - parentSibling.start;246 visited.add(parentSiblingKey);247 if (prevParentSibling === undefined) {248 adjustedOffset += parentDiff;249 } else {250 const prevParentDiff =251 prevParentSibling.end - prevParentSibling.start;252 if (prevParentDiff !== parentDiff) {253 adjustedOffset += parentDiff - prevParentDiff;254 }255 }256 parentSibling = parentSibling.prev;257 }258 parent = parent.parent;259 }260 break;261 }262 // Now traverse through the old offsets nodes and find any nodes we missed263 // above, because they were not in the latest offset node view (they have been264 // deleted).265 const prevFirstNode = prevOffsetView._firstNode;266 if (prevFirstNode !== null) {267 currentNode = $searchForNodeWithOffset(268 prevFirstNode,269 offset,270 blockOffsetSize,271 );272 let alreadyVisitedParentOfCurrentNode = false;273 while (currentNode !== null) {274 if (!visited.has(currentNode.key)) {275 alreadyVisitedParentOfCurrentNode = true;276 break;277 }278 currentNode = currentNode.parent;279 }280 if (!alreadyVisitedParentOfCurrentNode) {281 while (currentNode !== null) {282 const key = currentNode.key;283 if (!visited.has(key)) {284 const node = offsetMap.get(key);285 const prevDiff = currentNode.end - currentNode.start;286 if (node === undefined) {287 adjustedOffset -= prevDiff;288 } else {289 const diff = node.end - node.start;290 if (prevDiff !== diff) {291 adjustedOffset += diff - prevDiff;292 }293 }294 }295 currentNode = currentNode.prev;296 }297 }298 }299 return adjustedOffset;300}301function $searchForNodeWithOffset(302 firstNode: OffsetNode,303 offset: number,304 blockOffsetSize: number,305): OffsetNode | null {306 let currentNode = firstNode;307 while (currentNode !== null) {308 const end =309 currentNode.end +310 (currentNode.type !== 'element' || blockOffsetSize === 0 ? 1 : 0);311 if (offset < end) {312 const child = currentNode.child;313 if (child !== null) {314 currentNode = child;315 continue;316 }317 return currentNode;318 }319 const sibling = currentNode.next;320 if (sibling === null) {321 break;322 }323 currentNode = sibling;324 }325 return null;326}327function $createInternalOffsetNode(328 child: null | OffsetNode,329 type: 'element' | 'text' | 'inline',330 start: number,331 end: number,332 key: NodeKey,333 parent: null | OffsetElementNode,334): {335 child: null | OffsetNode;336 type: 'element' | 'text' | 'inline';337 start: number;338 end: number;339 key: NodeKey;340 parent: null | OffsetElementNode;341 next: null;342 prev: null;343} {344 return {345 child,346 end,347 key,348 next: null,349 parent,350 prev: null,351 start,352 type,353 };354}355function $createOffsetNode(356 state: {357 offset: number;358 prevIsBlock: boolean;359 },360 key: NodeKey,361 parent: null | OffsetElementNode,362 nodeMap: NodeMap,363 offsetMap: OffsetMap,364 blockOffsetSize: number,365): OffsetNode {366 const node = nodeMap.get(key);367 if (node === undefined) {368 invariant(false, 'createOffsetModel: could not find node by key');369 }370 const start = state.offset;371 if ($isElementNode(node)) {372 const childKeys = node.__children;373 const blockIsEmpty = childKeys.length === 0;374 const child = blockIsEmpty375 ? null376 : $createOffsetChild(377 state,378 childKeys,379 null,380 nodeMap,381 offsetMap,382 blockOffsetSize,383 );384 // If the prev node was not a block or the block is empty, we should385 // account for the user being able to selection the block (due to the \n).386 if (!state.prevIsBlock || blockIsEmpty) {387 state.prevIsBlock = true;388 state.offset += blockOffsetSize;389 }390 const offsetNode = $createInternalOffsetNode(391 child,392 'element',393 start,394 start,395 key,396 parent,397 ) as OffsetElementNode;398 if (child !== null) {399 child.parent = offsetNode;400 }401 const end = state.offset;402 offsetNode.end = end;403 offsetMap.set(key, offsetNode);404 return offsetNode;405 }406 state.prevIsBlock = false;407 const isText = $isTextNode(node);408 const length = isText ? node.__text.length : 1;409 const end = (state.offset += length);410 const offsetNode = $createInternalOffsetNode(411 null,412 isText ? 'text' : 'inline',413 start,414 end,415 key,416 parent,417 );418 offsetMap.set(key, offsetNode as OffsetNode);419 return offsetNode as OffsetNode;420}421function $createOffsetChild(422 state: {423 offset: number;424 prevIsBlock: boolean;425 },426 children: Array<NodeKey>,427 parent: null | OffsetElementNode,428 nodeMap: NodeMap,429 offsetMap: OffsetMap,430 blockOffsetSize: number,431): OffsetNode | null {432 let firstNode = null;433 let currentNode = null;434 const childrenLength = children.length;435 for (let i = 0; i < childrenLength; i++) {436 const childKey = children[i];437 const offsetNode = $createOffsetNode(438 state,439 childKey,440 parent,441 nodeMap,442 offsetMap,443 blockOffsetSize,444 );445 if (currentNode === null) {446 firstNode = offsetNode;447 } else {448 offsetNode.prev = currentNode;449 currentNode.next = offsetNode;450 }451 currentNode = offsetNode;452 }453 return firstNode;454}455export function $createOffsetView(456 editor: LexicalEditor,457 blockOffsetSize = 1,458 editorState?: EditorState | null,459): OffsetView {460 const targetEditorState =461 editorState || editor._pendingEditorState || editor._editorState;462 const nodeMap = targetEditorState._nodeMap;463 const root = nodeMap.get('root') as RootNode;464 const offsetMap = new Map();465 const state = {466 offset: 0,467 prevIsBlock: false,468 };469 const node = $createOffsetChild(470 state,471 root.__children,472 null,473 nodeMap,474 offsetMap,475 blockOffsetSize,476 );477 return new OffsetView(offsetMap, node, blockOffsetSize);...

Full Screen

Full Screen

index.js

Source:index.js Github

copy

Full Screen

1/**2 * Copyright (c) Meta Platforms, Inc. and affiliates.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @flow strict8 */9import type {10 EditorState,11 LexicalEditor,12 NodeKey,13 NodeMap,14 RangeSelection15} from 'lexical'16import {17 $createRangeSelection,18 $getNodeByKey,19 $isElementNode,20 $isTextNode21} from 'lexical'22import invariant from 'shared/invariant'23type OffsetElementNode = {24 child: null | OffsetNode,25 end: number,26 key: NodeKey,27 next: null | OffsetNode,28 parent: null | OffsetElementNode,29 prev: null | OffsetNode,30 start: number,31 type: 'element'32}33type OffsetTextNode = {34 child: null,35 end: number,36 key: NodeKey,37 next: null | OffsetNode,38 parent: null | OffsetElementNode,39 prev: null | OffsetNode,40 start: number,41 type: 'text'42}43type OffsetInlineNode = {44 child: null,45 end: number,46 key: NodeKey,47 next: null | OffsetNode,48 parent: null | OffsetElementNode,49 prev: null | OffsetNode,50 start: number,51 type: 'inline'52}53type OffsetNode = OffsetElementNode | OffsetTextNode | OffsetInlineNode54type OffsetMap = Map<NodeKey, OffsetNode>55export class OffsetView {56 _offsetMap: OffsetMap57 _firstNode: null | OffsetNode58 _blockOffsetSize: number59 constructor(60 offsetMap: OffsetMap,61 firstNode: null | OffsetNode,62 blockOffsetSize: number = 163 ): void {64 this._offsetMap = offsetMap65 this._firstNode = firstNode66 this._blockOffsetSize = blockOffsetSize67 }68 createSelectionFromOffsets(69 originalStart: number,70 originalEnd: number,71 diffOffsetView?: OffsetView72 ): null | RangeSelection {73 const firstNode = this._firstNode74 if (firstNode === null) {75 return null76 }77 let start = originalStart78 let end = originalEnd79 let startOffsetNode = $searchForNodeWithOffset(80 firstNode,81 start,82 this._blockOffsetSize83 )84 let endOffsetNode = $searchForNodeWithOffset(85 firstNode,86 end,87 this._blockOffsetSize88 )89 if (diffOffsetView !== undefined) {90 start = $getAdjustedOffsetFromDiff(91 start,92 startOffsetNode,93 diffOffsetView,94 this,95 this._blockOffsetSize96 )97 startOffsetNode = $searchForNodeWithOffset(98 firstNode,99 start,100 this._blockOffsetSize101 )102 end = $getAdjustedOffsetFromDiff(103 end,104 endOffsetNode,105 diffOffsetView,106 this,107 this._blockOffsetSize108 )109 endOffsetNode = $searchForNodeWithOffset(110 firstNode,111 end,112 this._blockOffsetSize113 )114 }115 if (startOffsetNode === null || endOffsetNode === null) {116 return null117 }118 let startKey = startOffsetNode.key119 let endKey = endOffsetNode.key120 const startNode = $getNodeByKey(startKey)121 const endNode = $getNodeByKey(endKey)122 if (startNode === null || endNode === null) {123 return null124 }125 let startOffset = 0126 let endOffset = 0127 let startType = 'element'128 let endType = 'element'129 if (startOffsetNode.type === 'text') {130 startOffset = start - startOffsetNode.start131 startType = 'text'132 // If we are at the edge of a text node and we133 // don't have a collapsed selection, then let's134 // try and correct the offset node.135 const sibling = startNode.getNextSibling()136 if (137 start !== end &&138 startOffset === startNode.getTextContentSize() &&139 $isTextNode(sibling)140 ) {141 startOffset = 0142 startKey = sibling.__key143 }144 } else if (startOffsetNode.type === 'inline') {145 startKey = startNode.getParentOrThrow().getKey()146 startOffset =147 end > startOffsetNode.start148 ? startOffsetNode.end149 : startOffsetNode.start150 }151 if (endOffsetNode.type === 'text') {152 endOffset = end - endOffsetNode.start153 endType = 'text'154 } else if (endOffsetNode.type === 'inline') {155 endKey = endNode.getParentOrThrow().getKey()156 endOffset =157 end > endOffsetNode.start ? endOffsetNode.end : endOffsetNode.start158 }159 const selection = $createRangeSelection()160 if (selection === null) {161 return null162 }163 selection.anchor.set(startKey, startOffset, startType)164 selection.focus.set(endKey, endOffset, endType)165 return selection166 }167 getOffsetsFromSelection(selection: RangeSelection): [number, number] {168 const anchor = selection.anchor169 const focus = selection.focus170 const offsetMap = this._offsetMap171 const anchorOffset = anchor.offset172 const focusOffset = focus.offset173 let start = -1174 let end = -1175 if (anchor.type === 'text') {176 const offsetNode = offsetMap.get(anchor.key)177 if (offsetNode !== undefined) {178 start = offsetNode.start + anchorOffset179 }180 } else {181 const node = anchor.getNode().getDescendantByIndex(anchorOffset)182 const offsetNode = offsetMap.get(node.getKey())183 if (offsetNode !== undefined) {184 const isAtEnd = node.getIndexWithinParent() !== anchorOffset185 start = isAtEnd ? offsetNode.end : offsetNode.start186 }187 }188 if (focus.type === 'text') {189 const offsetNode = offsetMap.get(focus.key)190 if (offsetNode !== undefined) {191 end = offsetNode.start + focus.offset192 }193 } else {194 const node = focus.getNode().getDescendantByIndex(focusOffset)195 const offsetNode = offsetMap.get(node.getKey())196 if (offsetNode !== undefined) {197 const isAtEnd = node.getIndexWithinParent() !== focusOffset198 end = isAtEnd ? offsetNode.end : offsetNode.start199 }200 }201 return [start, end]202 }203}204function $getAdjustedOffsetFromDiff(205 offset: number,206 offsetNode: null | OffsetNode,207 prevOffsetView: OffsetView,208 offsetView: OffsetView,209 blockOffsetSize: number210): number {211 const prevOffsetMap = prevOffsetView._offsetMap212 const offsetMap = offsetView._offsetMap213 const visited = new Set()214 let adjustedOffset = offset215 let currentNode = offsetNode216 while (currentNode !== null) {217 const key = currentNode.key218 const prevNode = prevOffsetMap.get(key)219 const diff = currentNode.end - currentNode.start220 visited.add(key)221 if (prevNode === undefined) {222 adjustedOffset += diff223 } else {224 const prevDiff = prevNode.end - prevNode.start225 if (prevDiff !== diff) {226 adjustedOffset += diff - prevDiff227 }228 }229 const sibling = currentNode.prev230 if (sibling !== null) {231 currentNode = sibling232 continue233 }234 let parent = currentNode.parent235 while (parent !== null) {236 let parentSibling = parent.prev237 if (parentSibling !== null) {238 const parentSiblingKey = parentSibling.key239 const prevParentSibling = prevOffsetMap.get(parentSiblingKey)240 const parentDiff = parentSibling.end - parentSibling.start241 visited.add(parentSiblingKey)242 if (prevParentSibling === undefined) {243 adjustedOffset += parentDiff244 } else {245 const prevParentDiff = prevParentSibling.end - prevParentSibling.start246 if (prevParentDiff !== parentDiff) {247 adjustedOffset += parentDiff - prevParentDiff248 }249 }250 parentSibling = parentSibling.prev251 }252 parent = parent.parent253 }254 break255 }256 // Now traverse through the old offsets nodes and find any nodes we missed257 // above, because they were not in the latest offset node view (they have been258 // deleted).259 const prevFirstNode = prevOffsetView._firstNode260 if (prevFirstNode !== null) {261 currentNode = $searchForNodeWithOffset(262 prevFirstNode,263 offset,264 blockOffsetSize265 )266 let alreadyVisistedParentOfCurrentNode = false267 while (currentNode !== null) {268 if (!visited.has(currentNode.key)) {269 alreadyVisistedParentOfCurrentNode = true270 break271 }272 currentNode = currentNode.parent273 }274 if (!alreadyVisistedParentOfCurrentNode) {275 while (currentNode !== null) {276 const key = currentNode.key277 if (!visited.has(key)) {278 const node = offsetMap.get(key)279 const prevDiff = currentNode.end - currentNode.start280 if (node === undefined) {281 adjustedOffset -= prevDiff282 } else {283 const diff = node.end - node.start284 if (prevDiff !== diff) {285 adjustedOffset += diff - prevDiff286 }287 }288 }289 currentNode = currentNode.prev290 }291 }292 }293 return adjustedOffset294}295function $searchForNodeWithOffset(296 firstNode: OffsetNode,297 offset: number,298 blockOffsetSize: number299): OffsetNode | null {300 let currentNode = firstNode301 while (currentNode !== null) {302 const end =303 currentNode.end +304 (currentNode.type !== 'element' || blockOffsetSize === 0 ? 1 : 0)305 if (offset < end) {306 const child = currentNode.child307 if (child !== null) {308 currentNode = child309 continue310 }311 return currentNode312 }313 const sibling = currentNode.next314 if (sibling === null) {315 break316 }317 currentNode = sibling318 }319 return null320}321function $createInternalOffsetNode<N>(322 child: null | OffsetNode,323 type: 'element' | 'text' | 'inline',324 start: number,325 end: number,326 key: NodeKey,327 parent: null | OffsetElementNode328): N {329 // $FlowFixMe: not sure why Flow doesn't like this?330 return {331 child,332 end,333 key,334 next: null,335 parent,336 prev: null,337 start,338 type339 }340}341function $createOffsetNode(342 state: { offset: number, prevIsBlock: boolean },343 key: NodeKey,344 parent: null | OffsetElementNode,345 nodeMap: NodeMap,346 offsetMap: OffsetMap,347 blockOffsetSize: number348): OffsetNode {349 const node = nodeMap.get(key)350 if (node === undefined) {351 invariant(false, 'createOffsetModel: could not find node by key')352 }353 const start = state.offset354 if ($isElementNode(node)) {355 const childKeys = node.__children356 const blockIsEmpty = childKeys.length === 0357 const child = blockIsEmpty358 ? null359 : $createOffsetChild(360 state,361 childKeys,362 null,363 nodeMap,364 offsetMap,365 blockOffsetSize366 )367 // If the prev node was not a block or the block is empty, we should368 // account for the user being able to selection the block (due to the \n).369 if (!state.prevIsBlock || blockIsEmpty) {370 state.prevIsBlock = true371 state.offset += blockOffsetSize372 }373 const offsetNode = $createInternalOffsetNode<OffsetElementNode>(374 child,375 'element',376 start,377 start,378 key,379 parent380 )381 if (child !== null) {382 child.parent = offsetNode383 }384 const end = state.offset385 offsetNode.end = end386 offsetMap.set(key, offsetNode)387 return offsetNode388 }389 state.prevIsBlock = false390 const isText = $isTextNode(node)391 // $FlowFixMe: isText means __text is available392 const length = isText ? node.__text.length : 1393 const end = (state.offset += length)394 const offsetNode: OffsetTextNode | OffsetInlineNode =395 $createInternalOffsetNode<OffsetTextNode | OffsetInlineNode>(396 null,397 isText ? 'text' : 'inline',398 start,399 end,400 key,401 parent402 )403 offsetMap.set(key, offsetNode)404 return offsetNode405}406function $createOffsetChild(407 state: { offset: number, prevIsBlock: boolean },408 children: Array<NodeKey>,409 parent: null | OffsetElementNode,410 nodeMap: NodeMap,411 offsetMap: OffsetMap,412 blockOffsetSize: number413): OffsetNode | null {414 let firstNode = null415 let currentNode = null416 const childrenLength = children.length417 for (let i = 0; i < childrenLength; i++) {418 const childKey = children[i]419 const offsetNode = $createOffsetNode(420 state,421 childKey,422 parent,423 nodeMap,424 offsetMap,425 blockOffsetSize426 )427 if (currentNode === null) {428 firstNode = offsetNode429 } else {430 offsetNode.prev = currentNode431 currentNode.next = offsetNode432 }433 currentNode = offsetNode434 }435 return firstNode436}437export function $createOffsetView(438 editor: LexicalEditor,439 blockOffsetSize?: number = 1,440 editorState?: EditorState441): OffsetView {442 const targetEditorState =443 editorState || editor._pendingEditorState || editor._editorState444 const nodeMap = targetEditorState._nodeMap445 // $FlowFixMe: root is always in the Map446 const root = ((nodeMap.get('root'): any): RootNode)447 const offsetMap = new Map()448 const state = { offset: 0, prevIsBlock: false }449 const node = $createOffsetChild(450 state,451 root.__children,452 null,453 nodeMap,454 offsetMap,455 blockOffsetSize456 )457 return new OffsetView(offsetMap, node, blockOffsetSize)...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var child = require('stryker-child');3var offset = parent.offsetNode(child);4console.log(offset);5var parent = require('stryker-parent');6var child = require('stryker-child');7var offset = parent.offsetNode(child);8console.log(offset);9var parent = require('stryker-parent');10var child = require('stryker-child');11var offset = parent.offsetNode(child);12console.log(offset);13var parent = require('stryker-parent');14var child = require('stryker-child');15var offset = parent.offsetNode(child);16console.log(offset);17var parent = require('stryker-parent');18var child = require('stryker-child');19var offset = parent.offsetNode(child);20console.log(offset);21var parent = require('stryker-parent');22var child = require('stryker-child');23var offset = parent.offsetNode(child);24console.log(offset);25var parent = require('stryker-parent');26var child = require('stryker-child');27var offset = parent.offsetNode(child);28console.log(offset);29var parent = require('stryker-parent');30var child = require('stryker-child');31var offset = parent.offsetNode(child);32console.log(offset);33var parent = require('stryker-parent');34var child = require('stryker-child');35var offset = parent.offsetNode(child);36console.log(offset);37var parent = require('stryker-parent');38var child = require('stryker-child');39var offset = parent.offsetNode(child);40console.log(offset);41var parent = require('stryker-parent');

Full Screen

Using AI Code Generation

copy

Full Screen

1const parent = require('stryker-parent');2const child = require('./child.js');3const offset = parent.offsetNode(child);4console.log(offset);5const parent = require('stryker-parent');6const child = require('./child.js');7const offset = parent.offsetNode(child);8console.log(offset);

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var offsetNode = parent.offsetNode;3var offset = offsetNode(1);4console.log(offset);5var parent = require('stryker-parent');6var offsetNode = parent.offsetNode;7var offset = offsetNode(2);8console.log(offset);9var parent = require('stryker-parent');10var offsetNode = parent.offsetNode;11var offset = offsetNode(3);12console.log(offset);13var parent = require('stryker-parent');14var offsetNode = parent.offsetNode;15var offset = offsetNode(4);16console.log(offset);17var parent = require('stryker-parent');18var offsetNode = parent.offsetNode;19var offset = offsetNode(5);20console.log(offset);21var parent = require('stryker-parent');22var offsetNode = parent.offsetNode;23var offset = offsetNode(6);24console.log(offset);25var parent = require('stryker-parent');26var offsetNode = parent.offsetNode;27var offset = offsetNode(7);28console.log(offset);29var parent = require('stryker-parent');30var offsetNode = parent.offsetNode;31var offset = offsetNode(8);32console.log(offset);

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = require('stryker-parent');2var p = new parent.Parent();3p.offsetNode(1,2);4console.log(p.x);5console.log(p.y);6var child = require('stryker-child');7var c = new child.Child();8c.offsetNode(1,2);9console.log(c.x);10console.log(c.y);11var parent = require('stryker-parent');12var p = new parent.Parent();13p.offsetNode(1,2);14console.log(p.x);15console.log(p.y);16var child = require('stryker-child');17var c = new child.Child();18c.offsetNode(1,2);19console.log(c.x);20console.log(c.y);

Full Screen

Using AI Code Generation

copy

Full Screen

1var parent = document.querySelector("#parent");2var child = document.querySelector("#child");3var childOffset = offsetNode(child, parent);4console.log(childOffset);5function offsetNode(node, offsetParent) {6 var nodeOffset = {7 };8 var parent = node.offsetParent;9 while (parent && parent !== offsetParent) {10 nodeOffset.top += parent.offsetTop;11 nodeOffset.left += parent.offsetLeft;12 parent = parent.offsetParent;13 }14 return nodeOffset;15}16 #parent {17 width: 300px;18 height: 300px;19 border: 1px solid black;20 position: relative;21 }22 #child {23 width: 100px;24 height: 100px;25 border: 1px solid black;26 position: absolute;27 top: 50px;28 left: 50px;29 }30var parent = document.querySelector("#parent");31var child = document.querySelector("#child");32var childOffset = offsetNode(child, parent);33console.log(childOffset);34function offsetNode(node, offsetParent) {35 var nodeOffset = {36 };

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run stryker-parent automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful