@domternal/core 0.4.1 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -240,6 +240,12 @@ interface EditorOptions {
240
240
  * @default true
241
241
  */
242
242
  editable?: boolean;
243
+ /**
244
+ * Accessible label for the editor.
245
+ * Sets aria-label on the contenteditable element.
246
+ * @default 'Rich text editor'
247
+ */
248
+ ariaLabel?: string;
243
249
  /**
244
250
  * Autofocus behavior on mount
245
251
  * @default false
@@ -5824,6 +5830,12 @@ interface StarterKitOptions {
5824
5830
  * Set to false to disable the LinkPopover extension, or pass options to configure it.
5825
5831
  */
5826
5832
  linkPopover?: false | Partial<LinkPopoverOptions>;
5833
+ /**
5834
+ * Set to false to disable the SelectionDecoration extension.
5835
+ * When enabled, the editor collapses range selections on blur to prevent
5836
+ * ghost selections from lingering after clicking outside the editor.
5837
+ */
5838
+ selectionDecoration?: false;
5827
5839
  }
5828
5840
  declare const StarterKit: Extension<StarterKitOptions, unknown>;
5829
5841
 
package/dist/index.js CHANGED
@@ -3602,6 +3602,11 @@ var Editor = class extends EventEmitter {
3602
3602
  */
3603
3603
  setEditable(editable) {
3604
3604
  this.options.editable = editable;
3605
+ if (editable) {
3606
+ this.view.dom.removeAttribute("aria-readonly");
3607
+ } else {
3608
+ this.view.dom.setAttribute("aria-readonly", "true");
3609
+ }
3605
3610
  this.view.dispatch(this.state.tr);
3606
3611
  return this;
3607
3612
  }
@@ -3733,6 +3738,12 @@ var Editor = class extends EventEmitter {
3733
3738
  state,
3734
3739
  dispatchTransaction: this.dispatchTransaction.bind(this),
3735
3740
  editable: () => this.options.editable ?? true,
3741
+ attributes: () => ({
3742
+ role: "textbox",
3743
+ "aria-multiline": "true",
3744
+ "aria-label": this.options.ariaLabel ?? "Rich text editor",
3745
+ ...this.options.editable ?? true ? {} : { "aria-readonly": "true" }
3746
+ }),
3736
3747
  ...Object.keys(nodeViews).length > 0 ? { nodeViews } : {},
3737
3748
  // Clipboard transform — apply user-provided transform (e.g. inlineStyles) on copy/cut
3738
3749
  ...this.options.clipboardHTMLTransform ? this.buildClipboardSerializer(this.options.clipboardHTMLTransform, this._extensionManager.schema) : {},
@@ -5415,7 +5426,8 @@ var TaskItem = Node.create({
5415
5426
  "input",
5416
5427
  {
5417
5428
  type: "checkbox",
5418
- checked: node.attrs["checked"] ? "checked" : null
5429
+ checked: node.attrs["checked"] ? "checked" : null,
5430
+ "aria-label": "Task status"
5419
5431
  }
5420
5432
  ]
5421
5433
  ],
@@ -7457,7 +7469,7 @@ var SelectionDecoration = Extension.create(
7457
7469
  handleDOMEvents: {
7458
7470
  blur(view, event) {
7459
7471
  const related = event.relatedTarget;
7460
- if (related instanceof HTMLElement && related.closest("[data-dm-editor-ui]")) {
7472
+ if (related instanceof HTMLElement && (related.closest("[data-dm-editor-ui]") || related.closest(".dm-toolbar") || related.closest(".dm-bubble-menu"))) {
7461
7473
  return false;
7462
7474
  }
7463
7475
  const { from, to } = view.state.selection;
@@ -8152,6 +8164,7 @@ function linkPopoverPlugin({ editor, markType, protocols }) {
8152
8164
  input.type = "url";
8153
8165
  input.placeholder = "Enter URL...";
8154
8166
  input.className = "dm-link-popover-input";
8167
+ input.setAttribute("aria-label", "URL");
8155
8168
  const applyBtn = document.createElement("button");
8156
8169
  applyBtn.type = "button";
8157
8170
  applyBtn.className = "dm-link-popover-btn dm-link-popover-apply";
@@ -8670,6 +8683,10 @@ function createFloatingMenuPlugin(options) {
8670
8683
  shouldShow = defaultShouldShow2,
8671
8684
  offset: offset2 = 0
8672
8685
  } = options;
8686
+ if (!element.getAttribute("role")) {
8687
+ element.setAttribute("role", "toolbar");
8688
+ element.setAttribute("aria-label", "Floating menu");
8689
+ }
8673
8690
  let cleanupFloating = null;
8674
8691
  const updatePosition = (view) => {
8675
8692
  const { selection } = view.state;
@@ -8813,6 +8830,7 @@ var StarterKit = Extension.create({
8813
8830
  maybeAdd(TrailingNode, this.options.trailingNode);
8814
8831
  maybeAdd(ListKeymap, this.options.listKeymap);
8815
8832
  maybeAdd(LinkPopover, this.options.linkPopover);
8833
+ maybeAdd(SelectionDecoration, this.options.selectionDecoration);
8816
8834
  return extensions;
8817
8835
  }
8818
8836
  });