### Start Development Server Source: https://lexxy.dev/docs/development.html Starts both the Rails server and the JavaScript watcher for local development. ```bash bin/dev ``` -------------------------------- ### Install Bundled Gems Source: https://lexxy.dev/docs Execute this command after adding the gem to your Gemfile to install all dependencies. ```bash bundle install ``` -------------------------------- ### Full Lexxy Extension Example Source: https://lexxy.dev/docs/extensions.html A comprehensive example demonstrating a custom Lexxy extension, including configuration, enabled state, allowed elements, lexical extension definition, and toolbar initialization. ```javascript import * as Lexxy from "@37signals/lexxy" Lexxy.configure({ global: { extensions: [ MyLexxyExtension ] }, default: { my_extension: { enableCoolFeature: true } } }) class MyLexxyExtension extends Lexxy.Extension { // optional: defaults to true get enabled() { // depend on an editor config return this.editorElement.supportsRichText // ... or a custom configuration return this.#config.enableCoolFeature } // optional: allow additional elements get allowedElements() { return [ { tag: "iframe", attributes: [ "src", "loading", "allow" ] } ] } get lexicalExtension() { return this.defineExtension({ name: "lexxy/my_lexical_extension", config: this.#config, ///... register(editor, config) { // ... custom Lexical behavior } }) } initializeToolbar(lexxyToolbar) { // ...Toolbar initialization code lexxyToolbar.querySelector("button[name=bold]").insertAdjacentElement(myToolbarElement) } get #config() { return this.editorConfig.get("my_extension") } } ``` -------------------------------- ### Install Project Dependencies Source: https://lexxy.dev/docs/development.html Installs all necessary dependencies including Ruby gems, Node packages, Playwright browsers, and database. ```bash bin/setup ``` -------------------------------- ### Start Development Server on Custom Port Source: https://lexxy.dev/docs/development.html Runs the development server on a specified port, useful for parallel worktrees. ```bash PORT=3100 bin/dev ``` ```bash PORT=3200 bin/dev ``` -------------------------------- ### Run Jekyll Site Locally Source: https://lexxy.dev/docs/development.html Installs dependencies and serves the Jekyll site locally. The site will be available at http://localhost:4000/. ```bash cd home bundle install bundle exec jekyll serve ``` -------------------------------- ### Install Lexxy NPM Package Source: https://lexxy.dev/docs Use yarn to add the Lexxy and Active Storage NPM packages when using JavaScript bundlers. ```bash yarn add @37signals/lexxy yarn add @rails/activestorage # to support attachments ``` -------------------------------- ### Configure Named Presets Source: https://lexxy.dev/docs/configuration.html Define named presets to organize alternative editor setups. This example creates a 'simple' preset that disables rich text editing. ```javascript Lexxy.configure({ simple: { richText: false } }) ``` -------------------------------- ### Basic Editor Element Source: https://lexxy.dev/docs/configuration.html An example of a basic Lexxy editor element with no specific configuration. ```html ``` -------------------------------- ### Restrict Prompt to Document Start Source: https://lexxy.dev/docs/prompts/options-reference.html Configures the prompt to only trigger when it is the very first character of the document. ```html … ``` -------------------------------- ### Stimulus Controller for Syntax Highlighting Source: https://lexxy.dev/docs/css-setup.html Create a Stimulus controller to apply syntax highlighting to Action Text content using Lexxy's highlightCode function. Ensure Lexxy is installed or imported correctly. ```javascript import { highlightCode } from "lexxy" // Or if you installed via a javascript bundler: // import { highlightCode } from "@37signals/lexxy" export default class extends Controller { connect() { highlightCode() } } ``` -------------------------------- ### Configure Headings via Preset Source: https://lexxy.dev/docs/configuration.html Configure the available heading levels in the toolbar dropdown via a preset. This example sets the default headings to h1, h2, and h3. ```javascript // Via preset Lexxy.configure({ default: { headings: ["h1", "h2", "h3"] } }) ``` -------------------------------- ### Configure Default Options Source: https://lexxy.dev/docs/configuration.html Override the default preset to change the behavior of all editors. This example disables the toolbar for all editors. ```javascript Lexxy.configure({ default: { toolbar: false } }) ``` -------------------------------- ### Basic Lexxy Prompt Setup Source: https://lexxy.dev/docs/prompts.html This snippet shows how to add a `` element to a form's rich text area. The `trigger` attribute specifies the character that opens the prompt. ```erb <%= form.rich_text_area :body do %> <% end %> ``` -------------------------------- ### Configure Remote Source for Mentions Source: https://lexxy.dev/docs/prompts/remote-attachments.html Use the `src` attribute to specify the remote endpoint for loading prompt items. This example configures mentions triggered by '@'. ```html ``` -------------------------------- ### Default Prompt Trigger Source: https://lexxy.dev/docs/prompts/options-reference.html The default behavior for the prompt trigger, allowing it to activate at the start of the document or after whitespace/paragraph breaks. ```html … ``` -------------------------------- ### Default Attachment Rendering Partial Source: https://lexxy.dev/docs/prompts/inline-attachments.html Define the partial for rendering the attachment in the view. This example renders the person's name and initials. ```erb <%# app/views/people/_person.html.erb %> <%= person.name %> (<%= person.initials %>) ``` -------------------------------- ### Benchmark Browser Scenarios Source: https://lexxy.dev/docs/development.html Provides options to customize benchmark runs, such as listing available scenarios, running a specific scenario with reduced samples, or setting a shorter time budget. ```bash # List scenarios yarn benchmark:browser --list-scenarios # Run one scenario with smaller sample sizes yarn benchmark:browser --scenario load-very-large-table --warmup 1 --iterations 3 # Use a shorter time budget per sample (default is 5000 ms) yarn benchmark:browser --time-budget 2000 ``` -------------------------------- ### Import Lexxy Source: https://lexxy.dev/docs/configuration.html Import the Lexxy library. This should be done immediately after your import statement. ```javascript import * as Lexxy from "lexxy" ``` -------------------------------- ### Pin Lexxy with Import Maps Source: https://lexxy.dev/docs Configure import maps to include Lexxy and Active Storage for attachments. ```ruby # importmap.rb pin "lexxy", to: "lexxy.js" pin "@rails/activestorage", to: "activestorage.esm.js" # to support attachments ``` -------------------------------- ### Run Browser Benchmark Suite Source: https://lexxy.dev/docs/development.html Executes the full suite of browser benchmarks for the editor's JavaScript side. Results are saved to `tmp/browser-benchmarks.json` by default. ```bash yarn benchmark:browser ``` -------------------------------- ### Import highlightCode Helper from Submodule Source: https://lexxy.dev/docs/css-setup.html If using the npm package and aiming for bundle splitting, import the highlightCode helper directly from the Lexxy helpers submodule. ```javascript import { highlightCode } from "@37signals/lexxy/helpers" ``` -------------------------------- ### Import Lexical Source: https://lexxy.dev/docs/extensions.html Import the Lexical package from the top-level module. ```javascript import { Lexical } from "@37signals/lexxy" ``` -------------------------------- ### Use a Preset Source: https://lexxy.dev/docs/configuration.html Opt into a named preset for an individual editor using the 'preset' attribute. ```html ``` -------------------------------- ### Render Prompt Items Partial Source: https://lexxy.dev/docs/prompts/remote-attachments.html The controller action renders a partial for each item in the collection, formatting them as prompt items for Lexxy. ```erb <%= render partial: "people/prompt_item", collection: @people %> ``` -------------------------------- ### Configure Highlighting Colors Source: https://lexxy.dev/docs/highlighting.html Use this configuration to set custom colors for highlighting buttons and to permit specific colors during paste operations. The `color` and `background-color` arrays within `buttons` define the available toolbar options, while `permit` allows Lexxy to conserve additional colors on paste. ```javascript Lexxy.configure({ default: { highlight: { buttons: { color: [ "red", "rgb(255, 0, 0)", "var(--text-color-1)" ], "background-color": [ "red", "rgba(0, 255, 0, 0.5)", "var(--bg-color-1)" ] }, permit: { color: [ "pink", "blue", "var(--legacy-text-color)" ], "background-color": [ "light-pink", "light-blue", "var(--legacy-bg-color)" ] } } } }) ``` -------------------------------- ### Controller Action for Remote Prompt Items Source: https://lexxy.dev/docs/prompts/remote-attachments.html Define a controller action to fetch and serve all potential prompt items (e.g., people) from the database. Ensure `layout: false` is set for rendering only the partials. ```ruby class PeopleController < ApplicationController def index @people = Person.all render layout: false end end ``` -------------------------------- ### Include Lexxy via CDN Source: https://lexxy.dev/docs Link to Lexxy's CSS and import its JavaScript module directly from a CDN like esm.sh. ```html ``` -------------------------------- ### Import Lexxy in JavaScript Entry Point Source: https://lexxy.dev/docs Import the Lexxy JavaScript file into your application's main JavaScript entry point. ```javascript // app/javascript/application.js import "lexxy" ``` -------------------------------- ### Compare Benchmark Results Source: https://lexxy.dev/docs/development.html Compares two benchmark result files to identify regressions. This is useful for CI checks and understanding performance changes over time. ```bash yarn benchmark:browser:compare tmp/baseline.json tmp/current.json ``` -------------------------------- ### Run JavaScript Unit Tests Source: https://lexxy.dev/docs/development.html Executes the JavaScript unit tests using Vitest. ```bash yarn test ``` -------------------------------- ### Attaching Multiple Editors to a Prompt Item Source: https://lexxy.dev/docs/prompts/multiple-attachments.html Use multiple `