Skip to content

Commit 01dbfed

Browse files
committed
Add Configuration API
Add vitest 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
1 parent 673a8e4 commit 01dbfed

34 files changed

+1387
-100
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,19 @@ jobs:
5555
ruby-version: ruby-3.3.7
5656
bundler-cache: true
5757

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

README.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,56 @@ 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: using `Lexxy.configure` and element 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+
richText: 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" rich-text="true"></lexxy-editor>
168+
169+
// finally, some options can only be configured globally
170+
Lexxy.configure({
171+
global: {
172+
attachmentTagName: "bc-attachment"
173+
}
174+
})
175+
```
176+
145177
## Options
146178

147-
The `<lexxy-editor>` element supports these options:
179+
Editors support the following options, configurable using presets and element attributes:
180+
181+
- `toolbar`: Pass `false` to disable the toolbar entirely, or pass the ID of a `<lexxy-toolbar>` element to use as an external toolbar. By default, the toolbar is bootstrapped and displayed above the editor.
182+
- `attachments`: Pass `false` to disable attachments completely. By default, attachments are supported, including paste and Drag & Drop support.
183+
- `markdown`: Pass `false` to disable Markdown support.
184+
- `multiLine`: Pass `false` to force single line editing.
185+
- `richText`: Pass `false` to disable rich text editing.
186+
187+
In addition, the `<lexxy-editor>` element supports these attributes:
148188

149189
- `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.
190+
- 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.
191+
192+
Finally, the following can only be configured using `Lexxy.configure({ global: ... })`:
152193

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.
194+
- `attachmentTagName`: The tag name used for [Action Text custom attachments](https://guides.rubyonrails.org/action_text_overview.html#signed-globalid). By default, they will be rendered as `action-text-attachment` tags.
154195

155196
## Prompts
156197

app/assets/javascript/lexxy.js

Lines changed: 187 additions & 51 deletions
Large diffs are not rendered by default.

app/assets/javascript/lexxy.js.br

631 Bytes
Binary file not shown.

app/assets/javascript/lexxy.js.gz

-287 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.
506 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": "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)