@domternal/core 0.12.1 → 0.13.0

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.cjs CHANGED
@@ -1379,9 +1379,9 @@ var defaultBlockAt = (match) => {
1379
1379
  };
1380
1380
 
1381
1381
  // src/commands/contentCommands.ts
1382
- var setContent = (content, options = {}) => ({ state, tr, dispatch }) => {
1382
+ var setContent = (content, options = {}) => ({ state: state$1, tr, dispatch }) => {
1383
1383
  const { emitUpdate = true, parseOptions } = options;
1384
- const { schema } = state;
1384
+ const { schema } = state$1;
1385
1385
  let doc;
1386
1386
  try {
1387
1387
  doc = createDocument(content, schema, { parseOptions });
@@ -1392,6 +1392,8 @@ var setContent = (content, options = {}) => ({ state, tr, dispatch }) => {
1392
1392
  return true;
1393
1393
  }
1394
1394
  tr.replaceWith(0, tr.doc.content.size, doc.content);
1395
+ const $end = tr.doc.resolve(tr.doc.content.size);
1396
+ tr.setSelection(state.TextSelection.between($end, $end, -1));
1395
1397
  if (!emitUpdate) {
1396
1398
  tr.setMeta("addToHistory", false);
1397
1399
  tr.setMeta("skipUpdate", true);
@@ -4175,6 +4177,23 @@ function copyThemeClass(view, target) {
4175
4177
  });
4176
4178
  }
4177
4179
 
4180
+ // src/utils/announce.ts
4181
+ function announce(view, message) {
4182
+ const editorEl = view.dom.closest(".dm-editor");
4183
+ if (!(editorEl instanceof HTMLElement)) return;
4184
+ let region = editorEl.querySelector(":scope > .dm-live-region");
4185
+ if (!region) {
4186
+ region = document.createElement("div");
4187
+ region.className = "dm-live-region";
4188
+ region.setAttribute("data-dm-editor-ui", "");
4189
+ region.setAttribute("role", "status");
4190
+ region.setAttribute("aria-live", "polite");
4191
+ region.style.cssText = "position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);clip-path:inset(50%);white-space:nowrap;";
4192
+ editorEl.appendChild(region);
4193
+ }
4194
+ region.textContent = region.textContent === message ? `${message}\xA0` : message;
4195
+ }
4196
+
4178
4197
  // src/utils/refocusEditorAfterCommand.ts
4179
4198
  function refocusEditorAfterCommand(view) {
4180
4199
  requestAnimationFrame(() => {
@@ -4193,6 +4212,10 @@ function refocusEditorAfterCommand(view) {
4193
4212
  // src/utils/defaultBubbleContexts.ts
4194
4213
  var NOTION_MODE_CLASS = "dm-notion-mode";
4195
4214
  var NOTION_TEXT_CONTEXT = Object.freeze([
4215
+ // `ai` leads (Notion's "Ask AI"); skipped with its leading separator when
4216
+ // the pro extension is absent, exactly like `mathInline`.
4217
+ "ai",
4218
+ "|",
4196
4219
  "bold",
4197
4220
  "italic",
4198
4221
  "underline",
@@ -8173,6 +8196,18 @@ var Placeholder = Extension.create({
8173
8196
  new state.Plugin({
8174
8197
  key: placeholderPluginKey,
8175
8198
  props: {
8199
+ // Focus and blur repaint the decorations: PM only recomputes
8200
+ // them when a transaction dispatches.
8201
+ handleDOMEvents: {
8202
+ focus: (view) => {
8203
+ view.dispatch(view.state.tr.setMeta(placeholderPluginKey, true));
8204
+ return false;
8205
+ },
8206
+ blur: (view) => {
8207
+ view.dispatch(view.state.tr.setMeta(placeholderPluginKey, false));
8208
+ return false;
8209
+ }
8210
+ },
8176
8211
  decorations: ({ doc, selection }) => {
8177
8212
  const editor = this.editor;
8178
8213
  if (!editor) return view.DecorationSet.empty;
@@ -8188,6 +8223,10 @@ var Placeholder = Extension.create({
8188
8223
  "data-placeholder": getPlaceholderText(node, pos)
8189
8224
  });
8190
8225
  if (showOnlyCurrent) {
8226
+ const view$1 = editor.view;
8227
+ if (!isDocEmpty && view$1?.hasFocus() !== true) {
8228
+ return view.DecorationSet.empty;
8229
+ }
8191
8230
  const { $anchor } = selection;
8192
8231
  if ($anchor.depth === 0) return view.DecorationSet.empty;
8193
8232
  const node = $anchor.parent;
@@ -10621,6 +10660,7 @@ exports.Typography = Typography;
10621
10660
  exports.Underline = Underline;
10622
10661
  exports.UniqueID = UniqueID;
10623
10662
  exports.VERSION = VERSION;
10663
+ exports.announce = announce;
10624
10664
  exports.applyInlineStyles = applyInlineStyles;
10625
10665
  exports.autolinkPlugin = autolinkPlugin;
10626
10666
  exports.autolinkPluginKey = autolinkPluginKey;