Skip to content

Commit a7eb6ed

Browse files
committed
Add Configuration API
Linting Fix attribute parsing Fix `configure` and `listen` (again) No need for inheritance, move preset getter to editor level Refresh DOMPurify config on each call, extract deepMerge helper Rely on JSON.parse when possible Add vitest Make fallback logic clearer Split presets/global into separate configs, use preset for global api, merge all config constructor args into tree Run tests during local ci and github actions Move javascript tests to into first level test/ folder Rely on editor element preset getter, remove second preset arg from EditorConfiguration Use runtime default preset as source of truth for override attributes Remove unused helper Tweak config export Document config api Rename external toolbar attribute to toolbartarget
1 parent ebadf6b commit a7eb6ed

29 files changed

+1294
-87
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
name: CI
22

3-
on:
4-
pull_request:
5-
push:
6-
branches: [ main ]
3+
on: [push, pull_request]
74

85
jobs:
96
lint:
@@ -55,7 +52,19 @@ jobs:
5552
ruby-version: ruby-3.3.7
5653
bundler-cache: true
5754

58-
- name: Run tests
55+
- name: Set up Node.js
56+
uses: actions/setup-node@v6
57+
with:
58+
node-version: '20'
59+
cache: 'yarn'
60+
61+
- name: Install JavaScript dependencies
62+
run: yarn install --frozen-lockfile
63+
64+
- name: Run JavaScript tests
65+
run: yarn test
66+
67+
- name: Run Rails tests
5968
env:
6069
RAILS_ENV: test
6170
# REDIS_URL: redis://localhost:6379/0

README.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,44 @@ Under the hood, this will insert a `<lexxy-editor>` tag, that will be a first-cl
142142
<lexxy-editor name="post[body]"...>...</lexxy-editor>
143143
```
144144

145+
You can configure editors in two ways: presets and attributes.
146+
147+
```js
148+
import * as Lexxy from "lexxy"
149+
150+
// overriding default options will affect all editors
151+
Lexxy.configure({
152+
default: {
153+
toolbar: false
154+
}
155+
})
156+
<lexxy-editor></lexxy-editor>
157+
158+
// you can also create new presets, which will extend the default preset
159+
Lexxy.configure({
160+
simple: {
161+
attachments: false
162+
}
163+
})
164+
<lexxy-editor preset="simple"></lexxy-editor>
165+
166+
// you can override specific options with attributes on editor elements
167+
<lexxy-editor preset="simple" attachments="true"></lexxy-editor>
168+
```
169+
145170
## Options
146171

147-
The `<lexxy-editor>` element supports these options:
172+
Editors support the following options, configurable using presets and element attributes:
148173

149-
- `placeholder`: Text displayed when the editor is empty.
150-
- `toolbar`: Pass `"false"` to disable the toolbar entirely, or pass an element ID to render the toolbar in an external element. By default, the toolbar is bootstrapped and displayed above the editor.
151-
- `attachments`: Pass `"false"` to disable attachments completely. By default, attachments are supported, including paste and Drag & Drop support.
174+
- `toolbar`: Pass `false` to disable the toolbar entirely. By default, the toolbar is bootstrapped and displayed above the editor. Use the `toolbartarget` element attribute to render in an external element.
175+
- `attachments`: Pass `false` to disable attachments completely. By default, attachments are supported, including paste and Drag & Drop support.
176+
- `multiline`: Pass `false` to force single line editing.
152177

153-
Lexxy uses the `ElementInternals` API to participate in HTML forms as any standard control. This means that you can use standard HTML attributes like `name`, `value`, `required`, `disabled`, etc.
178+
In addition, the `<lexxy-editor>` element supports these attributes:
179+
180+
- `toolbartarget`: Pass an element ID to render the toolbar in an external element. By default, the toolbar is bootstrapped and displayed above the editor.
181+
- `placeholder`: Text displayed when the editor is empty.
182+
- Lexxy uses the `ElementInternals` API to participate in HTML forms as any standard control. This means that you can use standard HTML attributes like `name`, `value`, `required`, `disabled`, etc.
154183

155184
## Prompts
156185

app/assets/javascript/lexxy.js

Lines changed: 168 additions & 43 deletions
Large diffs are not rendered by default.

app/assets/javascript/lexxy.js.br

407 Bytes
Binary file not shown.

app/assets/javascript/lexxy.js.gz

-262 Bytes
Binary file not shown.

app/assets/javascript/lexxy.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
361 Bytes
Binary file not shown.
-289 Bytes
Binary file not shown.

config/ci.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
step "Style: Ruby", "bin/rubocop -f github"
55
step "Style: JavaScript", "yarn lint"
66

7-
step "Tests: prepare", "env RAILS_ENV=test bin/rails db:test:prepare"
8-
step "Tests: run", "env RAILS_ENV=test bin/rails test:all -d"
7+
step "Tests: JavaScript", "yarn test"
8+
step "Tests: Rails (prepare)", "env RAILS_ENV=test bin/rails db:test:prepare"
9+
step "Tests: Rails (run)", "env RAILS_ENV=test bin/rails test:all -d"
910

1011
unless success?
1112
failure "Signoff: CI failed.", "Fix the issues and try again."

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@
1818
"@rollup/plugin-node-resolve": "^16.0.1",
1919
"@rollup/plugin-terser": "^0.4.4",
2020
"eslint": "^9.15.0",
21+
"jsdom": "^27.3.0",
2122
"rollup": "^4.44.1",
2223
"rollup-plugin-copy": "^3.5.0",
23-
"rollup-plugin-gzip": "^4.1.1"
24+
"rollup-plugin-gzip": "^4.1.1",
25+
"vitest": "^4.0.16"
2426
},
2527
"scripts": {
2628
"build": "rollup -c",
2729
"build:npm": "rollup -c rollup.config.npm.mjs",
2830
"watch": "NODE_ENV=development rollup -wc --watch.onEnd=\"rails restart\"",
2931
"lint": "eslint",
32+
"test": "vitest --environment=jsdom",
3033
"prerelease": "yarn build:npm",
3134
"release": "yarn build:npm && yarn publish"
3235
},

0 commit comments

Comments
 (0)