-
Notifications
You must be signed in to change notification settings - Fork 67
Configuration API #504
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Configuration API #504
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { deepMerge } from "../helpers/hash_helper" | ||
|
|
||
| export default class Configuration { | ||
| #tree = {} | ||
|
|
||
| constructor(...configs) { | ||
| this.merge(...configs) | ||
| } | ||
|
|
||
| merge(...configs) { | ||
| return this.#tree = configs.reduce(deepMerge, this.#tree) | ||
| } | ||
|
|
||
| get(path) { | ||
| const keys = path.split(".") | ||
| return keys.reduce((node, key) => node[key], this.#tree) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import Configuration from "./configuration" | ||
|
|
||
| const global = new Configuration({ | ||
| attachmentTagName: "action-text-attachment" | ||
| }) | ||
|
|
||
| const presets = new Configuration({ | ||
| default: { | ||
| attachments: true, | ||
| markdown: true, | ||
| multiLine: true, | ||
| richText: true, | ||
| toolbar: true, | ||
| } | ||
| }) | ||
|
|
||
| export default { | ||
| global, | ||
| presets, | ||
| configure({ global: newGlobal, ...newPresets }) { | ||
| if (newGlobal) { | ||
| global.merge(newGlobal) | ||
| } | ||
| presets.merge(newPresets) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { nextFrame } from "../helpers/timing_helpers" | |
| import { dispatch } from "../helpers/html_helper" | ||
| import { $getSelection, $isRangeSelection } from "lexical" | ||
| import { $isCodeNode } from "@lexical/code" | ||
| import { $insertDataTransferForRichText } from "@lexical/clipboard" | ||
|
|
||
| export default class Clipboard { | ||
| constructor(editorElement) { | ||
|
|
@@ -70,8 +71,10 @@ export default class Clipboard { | |
| } else if (isUrl(text)) { | ||
| const nodeKey = this.contents.createLink(text) | ||
| this.#dispatchLinkInsertEvent(nodeKey, { url: text }) | ||
| } else { | ||
| } else if (this.editorElement.supportsMarkdown) { | ||
| this.#pasteMarkdown(text) | ||
| } else { | ||
| this.#pasteRichText(clipboardData) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice 👏 |
||
| } | ||
| }) | ||
| } | ||
|
|
@@ -93,6 +96,13 @@ export default class Clipboard { | |
| this.contents.insertHtml(html) | ||
| } | ||
|
|
||
| #pasteRichText(clipboardData) { | ||
| this.editor.update(() => { | ||
| const selection = $getSelection() | ||
| $insertDataTransferForRichText(clipboardData, selection, this.editor) | ||
| }) | ||
| } | ||
|
|
||
| #handlePastedFiles(clipboardData) { | ||
| if (!this.editorElement.supportsAttachments) return | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import Configuration from "../config/configuration" | ||
| import Lexxy from "../config/lexxy" | ||
| import { dasherize } from "../helpers/string_helper" | ||
|
|
||
| export default class EditorConfiguration { | ||
| #editorElement | ||
| #config | ||
|
|
||
| constructor(editorElement) { | ||
| this.#editorElement = editorElement | ||
| this.#config = new Configuration( | ||
| Lexxy.presets.get("default"), | ||
| Lexxy.presets.get(editorElement.preset), | ||
| this.#overrides | ||
| ) | ||
| } | ||
|
|
||
| get(path) { | ||
| return this.#config.get(path) | ||
| } | ||
|
|
||
| get #overrides() { | ||
| const overrides = {} | ||
| for (const option of this.#defaultOptions) { | ||
| const attribute = dasherize(option) | ||
| if (this.#editorElement.hasAttribute(attribute)) { | ||
| overrides[option] = this.#parseAttribute(attribute) | ||
| } | ||
| } | ||
| return overrides | ||
| } | ||
|
|
||
| get #defaultOptions() { | ||
| return Object.keys(Lexxy.presets.get("default")) | ||
| } | ||
|
|
||
| #parseAttribute(attribute) { | ||
| const value = this.#editorElement.getAttribute(attribute) | ||
zachasme marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| try { | ||
| return JSON.parse(value) | ||
| } catch { | ||
| return value | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should include a reference to
Lexxy.globaland the option to configure tag names, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right! ✅
What do you think of the public interface? Right now I only expose
Lexxy.configurewhich re-routes it's input toglobal/presets.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is good 👍