Skip to content

Instantly share code, notes, and snippets.

View zurfyx's full-sized avatar

Gerard Rovira zurfyx

View GitHub Profile
@zurfyx
zurfyx / README.md
Created July 21, 2023 18:57
Lexical Offline (Multi) Selection

The EditorState is always synced with other parties via Collab, and part of the clipboard logic.

There's times when the result should be kept strictly offline. For example:

  1. Search or multi text search (i.e. VSCode find all). Or to show GenAI GPT results.
  2. Other player cursors in Collab (not part of th EditorState)
  3. GenAI GPT Office/Notion-like popover on edit when the prompt refers to a specific part of the edit but the focus has moved to the modal.

This solution leverages Range to follow DOM updates and render on top of the Lexical editor completely independently from the editor. The MutationObserver introduced below is particularly important to make sure that the position is always up-to-date. For example, additional changes in the padding or additional added/removed nodes somewhere on the contenteditable or immediately before our selection host.

The editor dependency is very lightweight, it could easily be decoupled completely.

@zurfyx
zurfyx / server.js
Created November 15, 2016 19:25
Express, Socket.io, Passport & Redis.
import http from 'http';
import express from 'express';
import bodyParser from 'body-parser';
import cookieParser from 'cookie-parser';
import expressValidator from 'express-validator';
import Session from 'express-session';
import morgan from 'morgan';
import mongoose from 'mongoose';
import passport from 'passport';
import { createClient as createRedisClient } from 'redis';
@zurfyx
zurfyx / index.html
Created March 10, 2017 21:28
cache selector (with & w/o jQuery) (http://jsbench.github.io/#3621d3b9b571cc3640fa988b42c5c873) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>cache selector (with & w/o jQuery)</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
type LexicalNodeType2<Type> = $ReadOnly<{
type: Type,
...
}>;
export type SerializedXNode = $ReadOnly<{
// children: Array<SerializedNode>,
direction: 'ltr' | 'rtl' | null,
format: number,
indent: number,
@zurfyx
zurfyx / Invid.sol
Created February 24, 2019 16:20
InVID Rights Management Smart Contract
pragma solidity ^0.4.24;
import "./Ownable.sol";
/**
* @title Contract to register reuse requests on the InVID Rights Management site.
* @dev This contract stores the various request requests and their parties, as well as each of the
* reuse request steps that were taken during the negotiation process.
* The reuse request terms for each of the steps can be found on IPFS.
*/
@zurfyx
zurfyx / react-context-tools.js
Last active January 13, 2019 13:56
React Context Tools (provideBundle, connect, useLocalStorage)
import React, { Fragment, useState } from 'react';
/**
* Plug in many providers with a single component.
* Use:
* const Providers = provideBundle(ThemeProvider, LanguageProvider);
* <Providers>
* <YourComponent></YourComponent>
* </Providers>
*/
@zurfyx
zurfyx / xargs-parallel.sh
Last active August 15, 2018 15:35
Run commands parallelly
#!/bin/bash
# https://stackoverflow.com/a/19618159
# https://stackoverflow.com/a/51861820
#
# Example file contents:
# touch /tmp/a.txt
# touch /tmp/b.txt
if [ "$#" -eq 0 ]; then
echo "$0 <file> [max-procs=0]"
/node_modules
@zurfyx
zurfyx / App.jsx
Created December 31, 2017 20:21
GDAX-like table effect
<div className="table">
<div className="row table-header">
<div>Timestamp</div>
<div>Temperature</div>
<div>Distance</div>
</div>
{this.state.data.map((entry, i) => (
<div key={entry.timestamp} className={
`row
${i === this.state.data.length - 1 ? 'last' : '' }
# Tag last commit as 'latest'.
if [ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" ]; then
git config --global user.email "hi@travis-ci.org"
git config --global user.name "Sr. Travis"
git remote add release "https://${GH_TOKEN}@github.com/zurfyx/travis-android.git"
git push -d release latest
git tag -d latest