Skip to content

Instantly share code, notes, and snippets.

/**
* 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';
@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));
}
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;
const INTERNAL_PROPS = new Set([
'__first',
'__last',
'__size',
'__parent',
'__next',
'__prev',
'__cachedText',
'__key',
]);
"use strict";
import type { LexicalEditor, LexicalNode } from "Lexical";
import type { Binding, Provider } from "LexicalYjs";
import {
createBinding,
syncLexicalUpdateToYjs,
syncYjsChangesToLexical,
} from "LexicalYjs";
createDom() {
return <div>
<div>
<div contenteditable=false>expand/collapse button</div>
<div ref=this.childrenContainer> </div>
</div>
</div>
}
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 = () => {};
var Config = {
'legal-entities/:id': 'entities#show',
'external-contact/current/legal-entities': 'ecEntities#index',
'internal-contact/current/legal-entities': 'icEntities#index',
'outreach-campaigns': 'oc#index',
'outreach-campaigns/new': 'oc#create',
'outreach-campaigns/:id': 'oc#show',
'outreach-campaigns/:id/edit': 'oc#edit',
'outreach-campaigns/:id/legal-entities': 'ocEntities#index'
};
@fantactuka
fantactuka / help.js
Last active December 27, 2015 07:59
$(function () {
var dot,
tooltip;
var help = function (steps) {
dot = dot || $('<div class="dot">').appendTo('body');
tooltip = tooltip || $('<div class="tooltip">').hide().appendTo('body');
steps = steps.slice();
@fantactuka
fantactuka / wadl.html
Created October 11, 2013 18:42
WADL parser
<!doctype html>
<html>
<head>
<title>WADL parser</title>
<link rel="stylesheet" href="application.css"/>
<style type="text/css">
ul#output {
list-style: none outside;
margin: 0 0 20px;