Skip to content

Instantly share code, notes, and snippets.

"use strict";
import type { LexicalEditor, LexicalNode } from "Lexical";
import type { Binding, Provider } from "LexicalYjs";
import {
createBinding,
syncLexicalUpdateToYjs,
syncYjsChangesToLexical,
} from "LexicalYjs";
@fantactuka
fantactuka / removed-node-listener.ts
Last active September 16, 2023 16:47
Getting node and its DOM element after deletion
useEffect(() => {
const domMap: Map<NodeKey, HTMLElement | null> = new Map();
return editor.registerMutationListener(
MentionNode,
(mutations, {prevEditorState}) => {
for (const [nodeKey, mutation] of mutations) {
if (mutation === 'created' || mutation === 'updated') {
domMap.set(nodeKey, editor.getElementByKey(nodeKey));
}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import type {LexicalEditor, LexicalNode} from 'lexical';
function $walk(
start: LexicalNode | null,
isBackward: boolean = false
): LexicalNode | null {
let node: LexicalNode | null = start;
if ($isElementNode(node) && !node.isEmpty()) {
return isBackward ? node.getLastChild() : node.getFirstChild();
}
let sibling: LexicalNode | null = null;
import {createEditor} from 'Lexical';
import {createBinding, syncYjsChangesToLexical} from 'LexicalYjs';
import {Doc, applyUpdate} from 'yjs';
export default function exportYDoc(
yDocState: Uint8Array,
nodes: Array<Class<LexicalNode>>,
): SerializedEditorState {
const emptyFunction = () => {};
const INTERNAL_PROPS = new Set([
'__first',
'__last',
'__size',
'__parent',
'__next',
'__prev',
'__cachedText',
'__key',
]);
createDom() {
return <div>
<div>
<div contenteditable=false>expand/collapse button</div>
<div ref=this.childrenContainer> </div>
</div>
</div>
}
@fantactuka
fantactuka / gist:1238174
Created September 23, 2011 19:03
Cucumber + Capybara test new window opened
Then /url "([^"]*)" is opened in new window/ do |url|
 browser = page.driver.browser
 current_id = browser.window_handle
 tab_id = page.driver.find_window(url)
 browser.switch_to.window tab_id
 page.driver.browser.close
 browser.switch_to.window current_id
end
@fantactuka
fantactuka / update-chrome-driver.sh
Last active June 2, 2020 13:15
Update Chrome driver for mac os
#!/bin/bash
# bash < <(curl -s https://gist.githubusercontent.com/fantactuka/3228898/raw/f0806a64306426ca72f16734ae7cd16c1f84bd87/update-chrome-driver.sh)
echo "Updating Chrome Driver"
sudo su
if [ -e /usr/bin/chromedriver ]; then
rm /usr/bin/chromedriver
echo "Removing current Chrome Driver from /usr/bin"
@fantactuka
fantactuka / gist:1540550
Created December 30, 2011 16:38
Creates hash code from string, ported from #C
// Borrowed from http://stackoverflow.com/questions/5293174/creating-a-unique-id-from-an-array-of-strings-in-javascript
function getHashCode(str) {
var h1 = (5381 << 16) + 5381, h2 = h1, index = 0;
while (index < str.length) {
h1 = ((h1 << 5) + h1 + (h1 >> 27)) ^ str.charCodeAt(index);
if (index == str.length - 1) {
break;
}
h2 = ((h2 << 5) + h2 + (h2 >> 27)) ^ str.charCodeAt(index + 1);