@blocklet/editor 1.6.202 → 1.6.204

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.
@@ -1,7 +1,6 @@
1
1
  import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
2
2
  import { useEffect, useRef, useCallback } from 'react';
3
- import { useMutationObserver } from 'ahooks';
4
- import debounce from 'lodash/debounce';
3
+ import { useMutationObserver, useDebounceFn } from 'ahooks';
5
4
  import { useLocaleContext } from '@arcblock/ux/lib/Locale/context';
6
5
  import Toast from '@arcblock/ux/lib/Toast';
7
6
  const id = 'translate-check-dom';
@@ -46,17 +45,16 @@ export const useTranslationListener = () => {
46
45
  // only not editable
47
46
  if (!editor.isEditable()) {
48
47
  const translated = !!translateRef.current.originalNode;
48
+ const withTranslateFlag = document.querySelector('html.translated-ltr, head.translated-rtl, ya-tr-span, *[_msthash], *[_msttexthash], body[data-immersive-translate-walked]') || translateRef.current.defaultLang !== document.documentElement.lang;
49
49
  // if not translated or need to reload
50
- if ((!translated || reload) &&
51
- (document.querySelector('html.translated-ltr, head.translated-rtl, ya-tr-span, *[_msthash], *[_msttexthash], body[data-immersive-translate-walked]') ||
52
- translateRef.current.defaultLang !== document.documentElement.lang)) {
50
+ if ((!translated || reload) && withTranslateFlag) {
53
51
  const originalNode = editor.getRootElement();
54
52
  if (originalNode) {
55
53
  setTimeout(() => {
56
54
  const clonedNode = originalNode.cloneNode(true);
57
55
  clonedNode.classList.remove('notranslate');
58
56
  clonedNode.addEventListener('click', showTranslationTip);
59
- clonedNode.style.cursor = 'not-allowed';
57
+ // clonedNode.style.cursor = 'not-allowed';
60
58
  originalNode?.replaceWith(clonedNode);
61
59
  translateRef.current.originalNode = originalNode;
62
60
  translateRef.current.clonedNode = clonedNode;
@@ -73,6 +71,7 @@ export const useTranslationListener = () => {
73
71
  }
74
72
  }
75
73
  };
74
+ const { run: debounceAddTranslationDOMListener } = useDebounceFn(addTranslationDOMListener, { wait: 500 });
76
75
  useEffect(() => {
77
76
  if (!document.getElementById(id)) {
78
77
  const defaultTranslationCheckDiv = document.createElement('div');
@@ -86,9 +85,9 @@ export const useTranslationListener = () => {
86
85
  document.body.insertBefore(defaultTranslationCheckDiv.cloneNode(true), document.body.firstChild);
87
86
  }
88
87
  // listen for editor
89
- return editor.registerRootListener(debounce(() => addTranslationDOMListener({ reload: true })));
88
+ return editor.registerRootListener(() => debounceAddTranslationDOMListener({ reload: true }));
90
89
  }, []);
91
- useMutationObserver(debounce(() => addTranslationDOMListener(), 300), document.getElementById(id), {
90
+ useMutationObserver(() => debounceAddTranslationDOMListener(), document.getElementById(id), {
92
91
  attributes: true,
93
92
  childList: true,
94
93
  });
@@ -316,6 +316,12 @@ export default function ComponentPickerMenuPlugin() {
316
316
  return mergeRegister(editor.registerCommand(INSERT_COMPONENT_COMMAND, (payload) => {
317
317
  editor.update(() => {
318
318
  const selection = $getSelection();
319
+ // if no selection, insert text node
320
+ if (!selection) {
321
+ const textNode = $createTextNode(payload);
322
+ $insertNodes([textNode]);
323
+ return true;
324
+ }
319
325
  // @ts-ignore
320
326
  const anchorNode = selection?.anchor?.getNode();
321
327
  const oldText = anchorNode?.getTextContent();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/editor",
3
- "version": "1.6.202",
3
+ "version": "1.6.204",
4
4
  "main": "lib/index.js",
5
5
  "scripts": {
6
6
  "dev": "npm run storybook",
@@ -37,9 +37,9 @@
37
37
  ]
38
38
  },
39
39
  "dependencies": {
40
- "@arcblock/ux": "^2.9.64",
40
+ "@arcblock/ux": "^2.9.65",
41
41
  "@blocklet/embed": "^0.1.11",
42
- "@blocklet/pdf": "1.6.202",
42
+ "@blocklet/pdf": "1.6.204",
43
43
  "@excalidraw/excalidraw": "^0.14.2",
44
44
  "@iconify/iconify": "^3.0.1",
45
45
  "@lexical/clipboard": "0.13.1",
@@ -108,5 +108,5 @@
108
108
  "react": "*",
109
109
  "react-dom": "*"
110
110
  },
111
- "gitHead": "e9c59ba8ff824847f0dcad9b21083f099718b961"
111
+ "gitHead": "9f441ebd16e8ec648858ffe198ba3ff39780ed7e"
112
112
  }