Skip to content

Instantly share code, notes, and snippets.

View KonnorRogers's full-sized avatar

Konnor Rogers KonnorRogers

View GitHub Profile
@KonnorRogers
KonnorRogers / reactive-components.html
Last active November 28, 2024 20:06
a rough sketch of writing reactive components.
<template component="MyComponent" store="global">
<div
@click="(e) => console.log('Clicked on: ' + this.name)" // event listeners
.name={{ name }} // properties
name="{{ name }}" // attributes
>
Hello {{ name }}
</div>
</template>
@KonnorRogers
KonnorRogers / fetch-mock.js
Last active November 26, 2024 16:36
fetch-mocking
const originalFetch = window.fetch
window.fetch = function (url, options = {}) {
if (url === "http://example.net/locale") {
return new Response(JSON.stringify({
locale: "en-US",
timeZone: "UTC"
}))
} else {
@KonnorRogers
KonnorRogers / sl_button.rb
Created November 2, 2024 19:59
Phlex dump of CLI
class SlButton < Phlex::HTML
register_element :sl_button
def initialize(
caret: false,
circle: false,
disabled: false,
download: nil,
form: nil,
formaction: nil,
@KonnorRogers
KonnorRogers / contenteditable.js
Created October 21, 2024 07:19
Finding if your contenteditable is part of a range across shadow dom.
const selection = document.getSelection()
if (!selection) { return }
let hasNode = false
if (typeof selection.getComposedRanges === "function") {
const staticRange = selection.getComposedRanges(this.contentEditableElement.getRootNode())[0]
if (!staticRange) { return }
@KonnorRogers
KonnorRogers / application_system_test_case.rb
Last active June 15, 2025 19:16
Rails playwright videos and screenshots
# test/application_system_test_case.rb
require "test_helper"
require "playwright"
require "fileutils"
class CapybaraNullDriver < Capybara::Driver::Base
def needs_server?
true
end
end
/**
* @param {InputEvent} e
*/
handleBeforeInput (e) {
// All level 2 input types: <https://w3c.github.io/input-events/#interface-InputEvent-Attributes>
switch (e.inputType) {
// insert typed plain text
case "insertText":
break;
// insert or replace existing text by means of a spell checker, auto-correct, writing suggestions or similar
@KonnorRogers
KonnorRogers / refresh.html
Created September 19, 2024 16:21
Refresh button for Turbo
<button type="button" data-controller="refresh">Refresh</button>
<script type="module">
import { Controller } from "@hotwired/stimulus"
export default class RefreshController extends Controller {
connect () {
this.element.addEventListener("click", this.sendRefresh)
}
@KonnorRogers
KonnorRogers / index.html
Created August 23, 2024 05:11
the joy of SSR
<!-- Case 1 -->
<my-input value="foo">
<template shadowrootmode="open">
<input value="foo">
</template>
</my-input>
<script>
myInput.value = "bar"
customElements.define("my-input", MyInput)
@KonnorRogers
KonnorRogers / cursed.css
Last active August 18, 2024 01:04
Cursed CSS for selected one side of the table
/**
This fancy shenanigans is what allows users to only select 1 side of a diff.
Inspired by this hack: https://stackoverflow.com/posts/73517303/revisions
*/
tr td {
user-select: none;
}
/** I'm not quite sure why its "n+4" instead of "n+3", when <td> 1-3 is the left, and <td> 4-6 is the right */
@KonnorRogers
KonnorRogers / my-element.ts
Last active July 16, 2024 16:17
Catching hydration errors in Lit
class MyElement extends LitElement {
protected update(changedProperties: PropertyValues<this>): void {
try {
super.update(changedProperties)
} catch (e) {
// We should probably check the contents of the message since this could error on a regular update??
// I really dont know. Its hacky, but it works.
const event = new Event("lit-hydration-error", { bubbles: true, composed: true, cancelable: false })
// @ts-expect-error leave me alone TS.
event.error = e