@payloadcms/richtext-lexical 3.0.0-beta.0 → 3.0.0-beta.10
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/field/features/blocks/feature.server.d.ts +4 -3
- package/dist/field/features/blocks/feature.server.d.ts.map +1 -1
- package/dist/field/features/blocks/feature.server.js +1 -0
- package/dist/field/features/blocks/feature.server.js.map +1 -1
- package/dist/field/features/converters/html/field/index.d.ts +8 -2
- package/dist/field/features/converters/html/field/index.d.ts.map +1 -1
- package/dist/field/features/converters/html/field/index.js +6 -3
- package/dist/field/features/converters/html/field/index.js.map +1 -1
- package/dist/field/features/horizontalrule/component/index.d.ts +10 -0
- package/dist/field/features/horizontalrule/component/index.d.ts.map +1 -0
- package/dist/field/features/horizontalrule/component/index.js +64 -0
- package/dist/field/features/horizontalrule/component/index.js.map +1 -0
- package/dist/field/features/horizontalrule/feature.client.d.ts +3 -0
- package/dist/field/features/horizontalrule/feature.client.d.ts.map +1 -0
- package/dist/field/features/horizontalrule/feature.client.js +53 -0
- package/dist/field/features/horizontalrule/feature.client.js.map +1 -0
- package/dist/field/features/horizontalrule/feature.server.d.ts +3 -0
- package/dist/field/features/horizontalrule/feature.server.d.ts.map +1 -0
- package/dist/field/features/horizontalrule/feature.server.js +36 -0
- package/dist/field/features/horizontalrule/feature.server.js.map +1 -0
- package/dist/field/features/horizontalrule/markdownTransformer.d.ts +3 -0
- package/dist/field/features/horizontalrule/markdownTransformer.d.ts.map +1 -0
- package/dist/field/features/horizontalrule/markdownTransformer.js +23 -0
- package/dist/field/features/horizontalrule/markdownTransformer.js.map +1 -0
- package/dist/field/features/horizontalrule/nodes/HorizontalRuleNode.d.ts +55 -0
- package/dist/field/features/horizontalrule/nodes/HorizontalRuleNode.d.ts.map +1 -0
- package/dist/field/features/horizontalrule/nodes/HorizontalRuleNode.js +89 -0
- package/dist/field/features/horizontalrule/nodes/HorizontalRuleNode.js.map +1 -0
- package/dist/field/features/horizontalrule/plugin/index.d.ts +6 -0
- package/dist/field/features/horizontalrule/plugin/index.d.ts.map +1 -0
- package/dist/field/features/horizontalrule/plugin/index.js +34 -0
- package/dist/field/features/horizontalrule/plugin/index.js.map +1 -0
- package/dist/field/features/horizontalrule/plugin/index.scss +20 -0
- package/dist/field/features/lists/htmlConverter.d.ts.map +1 -1
- package/dist/field/features/lists/htmlConverter.js +12 -4
- package/dist/field/features/lists/htmlConverter.js.map +1 -1
- package/dist/field/features/upload/component/index.d.ts.map +1 -1
- package/dist/field/features/upload/component/index.js +2 -2
- package/dist/field/features/upload/component/index.js.map +1 -1
- package/dist/field/features/upload/validate.d.ts.map +1 -1
- package/dist/field/features/upload/validate.js +4 -6
- package/dist/field/features/upload/validate.js.map +1 -1
- package/dist/field/lexical/config/server/default.d.ts.map +1 -1
- package/dist/field/lexical/config/server/default.js +3 -1
- package/dist/field/lexical/config/server/default.js.map +1 -1
- package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.d.ts.map +1 -1
- package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.js +11 -6
- package/dist/field/lexical/plugins/handles/AddBlockHandlePlugin/index.js.map +1 -1
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.d.ts.map +1 -1
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.js +8 -3
- package/dist/field/lexical/plugins/handles/DraggableBlockPlugin/index.js.map +1 -1
- package/dist/field/lexical/plugins/handles/utils/doesLineHeightAffectElement.d.ts +9 -0
- package/dist/field/lexical/plugins/handles/utils/doesLineHeightAffectElement.d.ts.map +1 -0
- package/dist/field/lexical/plugins/handles/utils/doesLineHeightAffectElement.js +35 -0
- package/dist/field/lexical/plugins/handles/utils/doesLineHeightAffectElement.js.map +1 -0
- package/dist/field/lexical/plugins/handles/utils/setHandlePosition.d.ts +1 -1
- package/dist/field/lexical/plugins/handles/utils/setHandlePosition.d.ts.map +1 -1
- package/dist/field/lexical/plugins/handles/utils/setHandlePosition.js +17 -7
- package/dist/field/lexical/plugins/handles/utils/setHandlePosition.js.map +1 -1
- package/dist/field/lexical/theme/EditorTheme.scss +4 -0
- package/dist/field/lexical/ui/icons/HorizontalRule/index.d.ts +3 -0
- package/dist/field/lexical/ui/icons/HorizontalRule/index.d.ts.map +1 -0
- package/dist/field/lexical/ui/icons/HorizontalRule/index.js +19 -0
- package/dist/field/lexical/ui/icons/HorizontalRule/index.js.map +1 -0
- package/dist/generateComponentMap.d.ts.map +1 -1
- package/dist/generateComponentMap.js +4 -2
- package/dist/generateComponentMap.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/scss/app.scss +2 -3
- package/dist/scss/vars.scss +0 -7
- package/package.json +15 -15
- package/src/index.ts +5 -1
- package/components.d.ts +0 -6
- package/components.js +0 -7
- package/dist/scss/fonts.scss +0 -75
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js';
|
|
3
|
+
const { useLexicalComposerContext } = lexicalComposerContextImport;
|
|
4
|
+
import lexicalUtilsImport from '@lexical/utils';
|
|
5
|
+
const { $insertNodeToNearestRoot } = lexicalUtilsImport;
|
|
6
|
+
import lexicalImport from 'lexical';
|
|
7
|
+
const { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR } = lexicalImport;
|
|
8
|
+
import { useEffect } from 'react';
|
|
9
|
+
import { $createHorizontalRuleNode, INSERT_HORIZONTAL_RULE_COMMAND } from '../nodes/HorizontalRuleNode.js';
|
|
10
|
+
import './index.scss';
|
|
11
|
+
/**
|
|
12
|
+
* Registers the INSERT_HORIZONTAL_RULE_COMMAND lexical command and defines the behavior for when it is called.
|
|
13
|
+
*/ export function HorizontalRulePlugin() {
|
|
14
|
+
const [editor] = useLexicalComposerContext();
|
|
15
|
+
useEffect(()=>{
|
|
16
|
+
return editor.registerCommand(INSERT_HORIZONTAL_RULE_COMMAND, (type)=>{
|
|
17
|
+
const selection = $getSelection();
|
|
18
|
+
if (!$isRangeSelection(selection)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const focusNode = selection.focus.getNode();
|
|
22
|
+
if (focusNode !== null) {
|
|
23
|
+
const horizontalRuleNode = $createHorizontalRuleNode();
|
|
24
|
+
$insertNodeToNearestRoot(horizontalRuleNode);
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
27
|
+
}, COMMAND_PRIORITY_EDITOR);
|
|
28
|
+
}, [
|
|
29
|
+
editor
|
|
30
|
+
]);
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/features/horizontalrule/plugin/index.tsx"],"sourcesContent":["'use client'\n\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\nimport lexicalUtilsImport from '@lexical/utils'\nconst { $insertNodeToNearestRoot } = lexicalUtilsImport\n\nimport lexicalImport from 'lexical'\nconst { $getSelection, $isRangeSelection, COMMAND_PRIORITY_EDITOR } = lexicalImport\nimport { useEffect } from 'react'\n\nimport {\n $createHorizontalRuleNode,\n INSERT_HORIZONTAL_RULE_COMMAND,\n} from '../nodes/HorizontalRuleNode.js'\nimport './index.scss'\n\n/**\n * Registers the INSERT_HORIZONTAL_RULE_COMMAND lexical command and defines the behavior for when it is called.\n */\nexport function HorizontalRulePlugin(): null {\n const [editor] = useLexicalComposerContext()\n\n useEffect(() => {\n return editor.registerCommand(\n INSERT_HORIZONTAL_RULE_COMMAND,\n (type) => {\n const selection = $getSelection()\n\n if (!$isRangeSelection(selection)) {\n return false\n }\n\n const focusNode = selection.focus.getNode()\n\n if (focusNode !== null) {\n const horizontalRuleNode = $createHorizontalRuleNode()\n $insertNodeToNearestRoot(horizontalRuleNode)\n }\n\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n )\n }, [editor])\n\n return null\n}\n"],"names":["lexicalComposerContextImport","useLexicalComposerContext","lexicalUtilsImport","$insertNodeToNearestRoot","lexicalImport","$getSelection","$isRangeSelection","COMMAND_PRIORITY_EDITOR","useEffect","$createHorizontalRuleNode","INSERT_HORIZONTAL_RULE_COMMAND","HorizontalRulePlugin","editor","registerCommand","type","selection","focusNode","focus","getNode","horizontalRuleNode"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAEA,OAAOA,kCAAkC,2CAA0C;AACnF,MAAM,EAAEC,yBAAyB,EAAE,GAAGD;AACtC,OAAOE,wBAAwB,iBAAgB;AAC/C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAErC,OAAOE,mBAAmB,UAAS;AACnC,MAAM,EAAEC,aAAa,EAAEC,iBAAiB,EAAEC,uBAAuB,EAAE,GAAGH;AACtE,SAASI,SAAS,QAAQ,QAAO;AAEjC,SACEC,yBAAyB,EACzBC,8BAA8B,QACzB,iCAAgC;AACvC,OAAO,eAAc;AAErB;;CAEC,GACD,OAAO,SAASC;IACd,MAAM,CAACC,OAAO,GAAGX;IAEjBO,UAAU;QACR,OAAOI,OAAOC,eAAe,CAC3BH,gCACA,CAACI;YACC,MAAMC,YAAYV;YAElB,IAAI,CAACC,kBAAkBS,YAAY;gBACjC,OAAO;YACT;YAEA,MAAMC,YAAYD,UAAUE,KAAK,CAACC,OAAO;YAEzC,IAAIF,cAAc,MAAM;gBACtB,MAAMG,qBAAqBV;gBAC3BN,yBAAyBgB;YAC3B;YAEA,OAAO;QACT,GACAZ;IAEJ,GAAG;QAACK;KAAO;IAEX,OAAO;AACT"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
@import '../../../../scss/styles.scss';
|
|
2
|
+
|
|
3
|
+
hr {
|
|
4
|
+
padding: 2px 2px;
|
|
5
|
+
border: none;
|
|
6
|
+
margin: 1rem 0;
|
|
7
|
+
cursor: pointer;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
hr:after {
|
|
11
|
+
content: '';
|
|
12
|
+
display: block;
|
|
13
|
+
height: 2px;
|
|
14
|
+
background-color: var(--theme-elevation-250);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
hr.selected {
|
|
18
|
+
outline: 2px solid var(--theme-success-500);
|
|
19
|
+
user-select: none;
|
|
20
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"htmlConverter.d.ts","sourceRoot":"","sources":["../../../../src/field/features/lists/htmlConverter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"htmlConverter.d.ts","sourceRoot":"","sources":["../../../../src/field/features/lists/htmlConverter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAM/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAA;AAI1E,eAAO,MAAM,iBAAiB,EAAE,aAAa,CAAC,kBAAkB,CAe/D,CAAA;AAED,eAAO,MAAM,qBAAqB,EAAE,aAAa,CAAC,sBAAsB,CA0CvE,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import lexicalListImport from '@lexical/list';
|
|
2
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
2
3
|
const { ListItemNode, ListNode } = lexicalListImport;
|
|
3
4
|
import { convertLexicalNodesToHTML } from '../converters/html/converter/index.js';
|
|
4
5
|
export const ListHTMLConverter = {
|
|
@@ -12,7 +13,7 @@ export const ListHTMLConverter = {
|
|
|
12
13
|
},
|
|
13
14
|
payload
|
|
14
15
|
});
|
|
15
|
-
return `<${node?.tag} class="
|
|
16
|
+
return `<${node?.tag} class="list-${node?.listType}">${childrenText}</${node?.tag}>`;
|
|
16
17
|
},
|
|
17
18
|
nodeTypes: [
|
|
18
19
|
ListNode.getType()
|
|
@@ -20,6 +21,7 @@ export const ListHTMLConverter = {
|
|
|
20
21
|
};
|
|
21
22
|
export const ListItemHTMLConverter = {
|
|
22
23
|
converter: async ({ converters, node, parent, payload })=>{
|
|
24
|
+
const hasSubLists = node.children.some((child)=>child.type === 'list');
|
|
23
25
|
const childrenText = await convertLexicalNodesToHTML({
|
|
24
26
|
converters,
|
|
25
27
|
lexicalNodes: node.children,
|
|
@@ -30,15 +32,21 @@ export const ListItemHTMLConverter = {
|
|
|
30
32
|
payload
|
|
31
33
|
});
|
|
32
34
|
if ('listType' in parent && parent?.listType === 'check') {
|
|
33
|
-
|
|
35
|
+
const uuid = uuidv4();
|
|
36
|
+
return `<li aria-checked=${node.checked ? 'true' : 'false'} class="${'list-item-checkbox' + (node.checked ? ' list-item-checkbox-checked' : ' list-item-checkbox-unchecked') + (hasSubLists ? ' nestedListItem' : '')}"
|
|
34
37
|
role="checkbox"
|
|
35
38
|
tabIndex=${-1}
|
|
36
39
|
value=${node?.value}
|
|
37
40
|
>
|
|
38
|
-
|
|
41
|
+
${hasSubLists ? childrenText : `
|
|
42
|
+
<input type="checkbox" id="${uuid}"${node.checked ? ' checked' : ''}>
|
|
43
|
+
<label for="${uuid}">${childrenText}</label><br>
|
|
44
|
+
`}
|
|
45
|
+
|
|
46
|
+
|
|
39
47
|
</li>`;
|
|
40
48
|
} else {
|
|
41
|
-
return `<li value=${node?.value}>${childrenText}</li>`;
|
|
49
|
+
return `<li ${hasSubLists ? `class="nestedListItem" ` : ''}value=${node?.value}>${childrenText}</li>`;
|
|
42
50
|
}
|
|
43
51
|
},
|
|
44
52
|
nodeTypes: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/field/features/lists/htmlConverter.ts"],"sourcesContent":["import type { SerializedListItemNode, SerializedListNode } from '@lexical/list'\n\nimport lexicalListImport from '@lexical/list'\nconst { ListItemNode, ListNode } = lexicalListImport\n\nimport type { HTMLConverter } from '../converters/html/converter/types.js'\n\nimport { convertLexicalNodesToHTML } from '../converters/html/converter/index.js'\n\nexport const ListHTMLConverter: HTMLConverter<SerializedListNode> = {\n converter: async ({ converters, node, parent, payload }) => {\n const childrenText = await convertLexicalNodesToHTML({\n converters,\n lexicalNodes: node.children,\n parent: {\n ...node,\n parent,\n },\n payload,\n })\n\n return `<${node?.tag} class=\"
|
|
1
|
+
{"version":3,"sources":["../../../../src/field/features/lists/htmlConverter.ts"],"sourcesContent":["import type { SerializedListItemNode, SerializedListNode } from '@lexical/list'\n\nimport lexicalListImport from '@lexical/list'\nimport { v4 as uuidv4 } from 'uuid'\nconst { ListItemNode, ListNode } = lexicalListImport\n\nimport type { HTMLConverter } from '../converters/html/converter/types.js'\n\nimport { convertLexicalNodesToHTML } from '../converters/html/converter/index.js'\n\nexport const ListHTMLConverter: HTMLConverter<SerializedListNode> = {\n converter: async ({ converters, node, parent, payload }) => {\n const childrenText = await convertLexicalNodesToHTML({\n converters,\n lexicalNodes: node.children,\n parent: {\n ...node,\n parent,\n },\n payload,\n })\n\n return `<${node?.tag} class=\"list-${node?.listType}\">${childrenText}</${node?.tag}>`\n },\n nodeTypes: [ListNode.getType()],\n}\n\nexport const ListItemHTMLConverter: HTMLConverter<SerializedListItemNode> = {\n converter: async ({ converters, node, parent, payload }) => {\n const hasSubLists = node.children.some((child) => child.type === 'list')\n\n const childrenText = await convertLexicalNodesToHTML({\n converters,\n lexicalNodes: node.children,\n parent: {\n ...node,\n parent,\n },\n payload,\n })\n\n if ('listType' in parent && parent?.listType === 'check') {\n const uuid = uuidv4()\n\n return `<li aria-checked=${node.checked ? 'true' : 'false'} class=\"${\n 'list-item-checkbox' +\n (node.checked ? ' list-item-checkbox-checked' : ' list-item-checkbox-unchecked') +\n (hasSubLists ? ' nestedListItem' : '')\n }\"\n role=\"checkbox\"\n tabIndex=${-1}\n value=${node?.value}\n >\n ${\n hasSubLists\n ? childrenText\n : `\n <input type=\"checkbox\" id=\"${uuid}\"${node.checked ? ' checked' : ''}>\n <label for=\"${uuid}\">${childrenText}</label><br>\n `\n }\n\n\n </li>`\n } else {\n return `<li ${hasSubLists ? `class=\"nestedListItem\" ` : ''}value=${node?.value}>${childrenText}</li>`\n }\n },\n nodeTypes: [ListItemNode.getType()],\n}\n"],"names":["lexicalListImport","v4","uuidv4","ListItemNode","ListNode","convertLexicalNodesToHTML","ListHTMLConverter","converter","converters","node","parent","payload","childrenText","lexicalNodes","children","tag","listType","nodeTypes","getType","ListItemHTMLConverter","hasSubLists","some","child","type","uuid","checked","value"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,uBAAuB,gBAAe;AAC7C,SAASC,MAAMC,MAAM,QAAQ,OAAM;AACnC,MAAM,EAAEC,YAAY,EAAEC,QAAQ,EAAE,GAAGJ;AAInC,SAASK,yBAAyB,QAAQ,wCAAuC;AAEjF,OAAO,MAAMC,oBAAuD;IAClEC,WAAW,OAAO,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAE;QACrD,MAAMC,eAAe,MAAMP,0BAA0B;YACnDG;YACAK,cAAcJ,KAAKK,QAAQ;YAC3BJ,QAAQ;gBACN,GAAGD,IAAI;gBACPC;YACF;YACAC;QACF;QAEA,OAAO,CAAC,CAAC,EAAEF,MAAMM,IAAI,aAAa,EAAEN,MAAMO,SAAS,EAAE,EAAEJ,aAAa,EAAE,EAAEH,MAAMM,IAAI,CAAC,CAAC;IACtF;IACAE,WAAW;QAACb,SAASc,OAAO;KAAG;AACjC,EAAC;AAED,OAAO,MAAMC,wBAA+D;IAC1EZ,WAAW,OAAO,EAAEC,UAAU,EAAEC,IAAI,EAAEC,MAAM,EAAEC,OAAO,EAAE;QACrD,MAAMS,cAAcX,KAAKK,QAAQ,CAACO,IAAI,CAAC,CAACC,QAAUA,MAAMC,IAAI,KAAK;QAEjE,MAAMX,eAAe,MAAMP,0BAA0B;YACnDG;YACAK,cAAcJ,KAAKK,QAAQ;YAC3BJ,QAAQ;gBACN,GAAGD,IAAI;gBACPC;YACF;YACAC;QACF;QAEA,IAAI,cAAcD,UAAUA,QAAQM,aAAa,SAAS;YACxD,MAAMQ,OAAOtB;YAEb,OAAO,CAAC,iBAAiB,EAAEO,KAAKgB,OAAO,GAAG,SAAS,QAAQ,QAAQ,EACjE,uBACChB,CAAAA,KAAKgB,OAAO,GAAG,gCAAgC,+BAA8B,IAC7EL,CAAAA,cAAc,oBAAoB,EAAC,EACrC;;mBAEY,EAAE,CAAC,EAAE;gBACR,EAAEX,MAAMiB,MAAM;;MAExB,EACEN,cACIR,eACA,CAAC;mCACsB,EAAEY,KAAK,CAAC,EAAEf,KAAKgB,OAAO,GAAG,aAAa,GAAG;oBACxD,EAAED,KAAK,EAAE,EAAEZ,aAAa;MACtC,CAAC,CACA;;;eAGQ,CAAC;QACZ,OAAO;YACL,OAAO,CAAC,IAAI,EAAEQ,cAAc,CAAC,uBAAuB,CAAC,GAAG,GAAG,MAAM,EAAEX,MAAMiB,MAAM,CAAC,EAAEd,aAAa,KAAK,CAAC;QACvG;IACF;IACAK,WAAW;QAACd,aAAae,OAAO;KAAG;AACrC,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/upload/component/index.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAA4C,MAAM,OAAO,CAAA;AAIhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAMxD,OAAO,cAAc,CAAA;AAQrB,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAEhB,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/upload/component/index.tsx"],"names":[],"mappings":"AAkBA,OAAO,KAA4C,MAAM,OAAO,CAAA;AAIhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAMxD,OAAO,cAAc,CAAA;AAQrB,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,UAAU,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAEhB,CAAA;AAkJD,eAAO,MAAM,eAAe,UAAW,YAAY,KAAG,MAAM,SAM3D,CAAA"}
|
|
@@ -128,11 +128,11 @@ const Component = (props)=>{
|
|
|
128
128
|
className: `${baseClass}__doc-drawer-toggler`
|
|
129
129
|
}, /*#__PURE__*/ React.createElement("strong", null, data?.filename)))), value?.id && /*#__PURE__*/ React.createElement(DocumentDrawer, {
|
|
130
130
|
onSave: updateUpload
|
|
131
|
-
}), /*#__PURE__*/ React.createElement(ExtraFieldsUploadDrawer, {
|
|
131
|
+
}), hasExtraFields ? /*#__PURE__*/ React.createElement(ExtraFieldsUploadDrawer, {
|
|
132
132
|
drawerSlug: drawerSlug,
|
|
133
133
|
relatedCollection: relatedCollection,
|
|
134
134
|
...props
|
|
135
|
-
}));
|
|
135
|
+
}) : null);
|
|
136
136
|
};
|
|
137
137
|
export const UploadComponent = (props)=>{
|
|
138
138
|
return /*#__PURE__*/ React.createElement(EnabledRelationshipsCondition, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/features/upload/component/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientCollectionConfig } from 'payload/types'\n\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\nimport { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection.js'\nimport { getTranslation } from '@payloadcms/translations'\nimport lexicalImport from 'lexical'\nconst { $getNodeByKey } = lexicalImport\n\nimport { Button } from '@payloadcms/ui/elements/Button'\nimport { useDocumentDrawer } from '@payloadcms/ui/elements/DocumentDrawer'\nimport { DrawerToggler } from '@payloadcms/ui/elements/Drawer'\nimport { useDrawerSlug } from '@payloadcms/ui/elements/Drawer'\nimport { File } from '@payloadcms/ui/graphics/File'\nimport usePayloadAPI from '@payloadcms/ui/hooks/usePayloadAPI'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport React, { useCallback, useReducer, useState } from 'react'\n\nimport type { ClientComponentProps } from '../../types.js'\nimport type { UploadFeaturePropsClient } from '../feature.client.js'\nimport type { UploadData } from '../nodes/UploadNode.js'\n\nimport { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js'\nimport { EnabledRelationshipsCondition } from '../../relationship/utils/EnabledRelationshipsCondition.js'\nimport { INSERT_UPLOAD_WITH_DRAWER_COMMAND } from '../drawer/commands.js'\nimport { ExtraFieldsUploadDrawer } from './ExtraFieldsDrawer/index.js'\nimport './index.scss'\n\nconst baseClass = 'lexical-upload'\n\nconst initialParams = {\n depth: 0,\n}\n\nexport type ElementProps = {\n data: UploadData\n nodeKey: string\n //uploadProps: UploadFeatureProps\n}\n\nconst Component: React.FC<ElementProps> = (props) => {\n const {\n data: { fields, relationTo, value },\n nodeKey,\n } = props\n\n const {\n collections,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const [editor] = useLexicalComposerContext()\n const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey)\n const { editorConfig, field } = useEditorConfigContext()\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [relatedCollection, setRelatedCollection] = useState<ClientCollectionConfig>(() =>\n collections.find((coll) => coll.slug === relationTo),\n )\n\n const drawerSlug = useDrawerSlug('upload-drawer')\n\n const [DocumentDrawer, DocumentDrawerToggler, { closeDrawer }] = useDocumentDrawer({\n id: value?.id,\n collectionSlug: relatedCollection.slug,\n })\n\n // Get the referenced document\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value?.id}`,\n { initialParams },\n )\n\n const thumbnailSRC = data?.thumbnailURL || data?.url\n\n const removeUpload = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey).remove()\n })\n }, [editor, nodeKey])\n\n const updateUpload = useCallback(\n (json) => {\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n dispatchCacheBust()\n closeDrawer()\n },\n [setParams, cacheBust, closeDrawer],\n )\n\n const hasExtraFields = (\n editorConfig?.resolvedFeatureMap?.get('upload')\n ?.clientFeatureProps as ClientComponentProps<UploadFeaturePropsClient>\n ).collections?.[relatedCollection.slug]?.hasExtraFields\n\n return (\n <div\n className={[baseClass, isSelected && `${baseClass}--selected`].filter(Boolean).join(' ')}\n contentEditable={false}\n >\n <div className={`${baseClass}__card`}>\n <div className={`${baseClass}__topRow`}>\n {/* TODO: migrate to use @payloadcms/ui/elements/Thumbnail component */}\n <div className={`${baseClass}__thumbnail`}>\n {thumbnailSRC ? <img alt={data?.filename} src={thumbnailSRC} /> : <File />}\n </div>\n <div className={`${baseClass}__topRowRightPanel`}>\n <div className={`${baseClass}__collectionLabel`}>\n {getTranslation(relatedCollection.labels.singular, i18n)}\n </div>\n {editor.isEditable() && (\n <div className={`${baseClass}__actions`}>\n {hasExtraFields ? (\n <DrawerToggler\n className={`${baseClass}__upload-drawer-toggler`}\n disabled={field?.readOnly}\n slug={drawerSlug}\n >\n <Button\n buttonStyle=\"icon-label\"\n el=\"div\"\n icon=\"edit\"\n onClick={(e) => {\n e.preventDefault()\n }}\n round\n tooltip={t('fields:editRelationship')}\n />\n </DrawerToggler>\n ) : null}\n\n <Button\n buttonStyle=\"icon-label\"\n disabled={field?.readOnly}\n el=\"div\"\n icon=\"swap\"\n onClick={() => {\n editor.dispatchCommand(INSERT_UPLOAD_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }}\n round\n tooltip={t('fields:swapUpload')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeUpload()\n }}\n round\n tooltip={t('fields:removeUpload')}\n />\n </div>\n )}\n </div>\n </div>\n <div className={`${baseClass}__bottomRow`}>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <strong>{data?.filename}</strong>\n </DocumentDrawerToggler>\n </div>\n </div>\n {value?.id && <DocumentDrawer onSave={updateUpload} />}\n <ExtraFieldsUploadDrawer\n drawerSlug={drawerSlug}\n relatedCollection={relatedCollection}\n {...props}\n />\n </div>\n )\n}\n\nexport const UploadComponent = (props: ElementProps): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props} uploads>\n <Component {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"names":["lexicalComposerContextImport","useLexicalComposerContext","useLexicalNodeSelection","getTranslation","lexicalImport","$getNodeByKey","Button","useDocumentDrawer","DrawerToggler","useDrawerSlug","File","usePayloadAPI","useConfig","useTranslation","React","useCallback","useReducer","useState","useEditorConfigContext","EnabledRelationshipsCondition","INSERT_UPLOAD_WITH_DRAWER_COMMAND","ExtraFieldsUploadDrawer","baseClass","initialParams","depth","Component","props","data","fields","relationTo","value","nodeKey","collections","routes","api","serverURL","editor","isSelected","setSelected","clearSelection","editorConfig","field","i18n","t","cacheBust","dispatchCacheBust","state","relatedCollection","setRelatedCollection","find","coll","slug","drawerSlug","DocumentDrawer","DocumentDrawerToggler","closeDrawer","id","collectionSlug","setParams","thumbnailSRC","thumbnailURL","url","removeUpload","update","remove","updateUpload","json","hasExtraFields","resolvedFeatureMap","get","clientFeatureProps","div","className","filter","Boolean","join","contentEditable","img","alt","filename","src","labels","singular","isEditable","disabled","readOnly","buttonStyle","el","icon","onClick","e","preventDefault","round","tooltip","dispatchCommand","replace","strong","onSave","UploadComponent","uploads"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAsBkB,WAAW,CAAC,EAAElD,UAAU,oBAAoB,CAAC;qBAClE,oBAAC0E,gBAAQrE,MAAMoD,cAIpBjD,OAAO0B,oBAAM,oBAACH;QAAe4C,QAAQhC;sBACtC,oBAAC5C;QACC+B,YAAYA;QACZL,mBAAmBA;QAClB,GAAGrB,KAAK;;AAIjB;AAEA,OAAO,MAAMwE,kBAAkB,CAACxE;IAC9B,qBACE,oBAACP;QAA+B,GAAGO,KAAK;QAAEyE,SAAAA;qBACxC,oBAAC1E,WAAcC;AAGrB,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/features/upload/component/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientCollectionConfig } from 'payload/types'\n\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\nimport { useLexicalNodeSelection } from '@lexical/react/useLexicalNodeSelection.js'\nimport { getTranslation } from '@payloadcms/translations'\nimport lexicalImport from 'lexical'\nconst { $getNodeByKey } = lexicalImport\n\nimport { Button } from '@payloadcms/ui/elements/Button'\nimport { useDocumentDrawer } from '@payloadcms/ui/elements/DocumentDrawer'\nimport { DrawerToggler } from '@payloadcms/ui/elements/Drawer'\nimport { useDrawerSlug } from '@payloadcms/ui/elements/Drawer'\nimport { File } from '@payloadcms/ui/graphics/File'\nimport usePayloadAPI from '@payloadcms/ui/hooks/usePayloadAPI'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport React, { useCallback, useReducer, useState } from 'react'\n\nimport type { ClientComponentProps } from '../../types.js'\nimport type { UploadFeaturePropsClient } from '../feature.client.js'\nimport type { UploadData } from '../nodes/UploadNode.js'\n\nimport { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js'\nimport { EnabledRelationshipsCondition } from '../../relationship/utils/EnabledRelationshipsCondition.js'\nimport { INSERT_UPLOAD_WITH_DRAWER_COMMAND } from '../drawer/commands.js'\nimport { ExtraFieldsUploadDrawer } from './ExtraFieldsDrawer/index.js'\nimport './index.scss'\n\nconst baseClass = 'lexical-upload'\n\nconst initialParams = {\n depth: 0,\n}\n\nexport type ElementProps = {\n data: UploadData\n nodeKey: string\n //uploadProps: UploadFeatureProps\n}\n\nconst Component: React.FC<ElementProps> = (props) => {\n const {\n data: { fields, relationTo, value },\n nodeKey,\n } = props\n\n const {\n collections,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const [editor] = useLexicalComposerContext()\n const [isSelected, setSelected, clearSelection] = useLexicalNodeSelection(nodeKey)\n const { editorConfig, field } = useEditorConfigContext()\n\n const { i18n, t } = useTranslation()\n const [cacheBust, dispatchCacheBust] = useReducer((state) => state + 1, 0)\n const [relatedCollection, setRelatedCollection] = useState<ClientCollectionConfig>(() =>\n collections.find((coll) => coll.slug === relationTo),\n )\n\n const drawerSlug = useDrawerSlug('upload-drawer')\n\n const [DocumentDrawer, DocumentDrawerToggler, { closeDrawer }] = useDocumentDrawer({\n id: value?.id,\n collectionSlug: relatedCollection.slug,\n })\n\n // Get the referenced document\n const [{ data }, { setParams }] = usePayloadAPI(\n `${serverURL}${api}/${relatedCollection.slug}/${value?.id}`,\n { initialParams },\n )\n\n const thumbnailSRC = data?.thumbnailURL || data?.url\n\n const removeUpload = useCallback(() => {\n editor.update(() => {\n $getNodeByKey(nodeKey).remove()\n })\n }, [editor, nodeKey])\n\n const updateUpload = useCallback(\n (json) => {\n setParams({\n ...initialParams,\n cacheBust, // do this to get the usePayloadAPI to re-fetch the data even though the URL string hasn't changed\n })\n\n dispatchCacheBust()\n closeDrawer()\n },\n [setParams, cacheBust, closeDrawer],\n )\n\n const hasExtraFields = (\n editorConfig?.resolvedFeatureMap?.get('upload')\n ?.clientFeatureProps as ClientComponentProps<UploadFeaturePropsClient>\n ).collections?.[relatedCollection.slug]?.hasExtraFields\n\n return (\n <div\n className={[baseClass, isSelected && `${baseClass}--selected`].filter(Boolean).join(' ')}\n contentEditable={false}\n >\n <div className={`${baseClass}__card`}>\n <div className={`${baseClass}__topRow`}>\n {/* TODO: migrate to use @payloadcms/ui/elements/Thumbnail component */}\n <div className={`${baseClass}__thumbnail`}>\n {thumbnailSRC ? <img alt={data?.filename} src={thumbnailSRC} /> : <File />}\n </div>\n <div className={`${baseClass}__topRowRightPanel`}>\n <div className={`${baseClass}__collectionLabel`}>\n {getTranslation(relatedCollection.labels.singular, i18n)}\n </div>\n {editor.isEditable() && (\n <div className={`${baseClass}__actions`}>\n {hasExtraFields ? (\n <DrawerToggler\n className={`${baseClass}__upload-drawer-toggler`}\n disabled={field?.readOnly}\n slug={drawerSlug}\n >\n <Button\n buttonStyle=\"icon-label\"\n el=\"div\"\n icon=\"edit\"\n onClick={(e) => {\n e.preventDefault()\n }}\n round\n tooltip={t('fields:editRelationship')}\n />\n </DrawerToggler>\n ) : null}\n\n <Button\n buttonStyle=\"icon-label\"\n disabled={field?.readOnly}\n el=\"div\"\n icon=\"swap\"\n onClick={() => {\n editor.dispatchCommand(INSERT_UPLOAD_WITH_DRAWER_COMMAND, {\n replace: { nodeKey },\n })\n }}\n round\n tooltip={t('fields:swapUpload')}\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__removeButton`}\n disabled={field?.readOnly}\n icon=\"x\"\n onClick={(e) => {\n e.preventDefault()\n removeUpload()\n }}\n round\n tooltip={t('fields:removeUpload')}\n />\n </div>\n )}\n </div>\n </div>\n <div className={`${baseClass}__bottomRow`}>\n <DocumentDrawerToggler className={`${baseClass}__doc-drawer-toggler`}>\n <strong>{data?.filename}</strong>\n </DocumentDrawerToggler>\n </div>\n </div>\n {value?.id && <DocumentDrawer onSave={updateUpload} />}\n {hasExtraFields ? (\n <ExtraFieldsUploadDrawer\n drawerSlug={drawerSlug}\n relatedCollection={relatedCollection}\n {...props}\n />\n ) : null}\n </div>\n )\n}\n\nexport const UploadComponent = (props: ElementProps): React.ReactNode => {\n return (\n <EnabledRelationshipsCondition {...props} uploads>\n <Component {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"names":["lexicalComposerContextImport","useLexicalComposerContext","useLexicalNodeSelection","getTranslation","lexicalImport","$getNodeByKey","Button","useDocumentDrawer","DrawerToggler","useDrawerSlug","File","usePayloadAPI","useConfig","useTranslation","React","useCallback","useReducer","useState","useEditorConfigContext","EnabledRelationshipsCondition","INSERT_UPLOAD_WITH_DRAWER_COMMAND","ExtraFieldsUploadDrawer","baseClass","initialParams","depth","Component","props","data","fields","relationTo","value","nodeKey","collections","routes","api","serverURL","editor","isSelected","setSelected","clearSelection","editorConfig","field","i18n","t","cacheBust","dispatchCacheBust","state","relatedCollection","setRelatedCollection","find","coll","slug","drawerSlug","DocumentDrawer","DocumentDrawerToggler","closeDrawer","id","collectionSlug","setParams","thumbnailSRC","thumbnailURL","url","removeUpload","update","remove","updateUpload","json","hasExtraFields","resolvedFeatureMap","get","clientFeatureProps","div","className","filter","Boolean","join","contentEditable","img","alt","filename","src","labels","singular","isEditable","disabled","readOnly","buttonStyle","el","icon","onClick","e","preventDefault","round","tooltip","dispatchCommand","replace","strong","onSave","UploadComponent","uploads"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAGA,OAAOA,kCAAkC,2CAA0C;AACnF,MAAM,EAAEC,yBAAyB,EAAE,GAAGD;AACtC,SAASE,uBAAuB,QAAQ,4CAA2C;AACnF,SAASC,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,mBAAmB,UAAS;AACnC,MAAM,EAAEC,aAAa,EAAE,GAAGD;AAE1B,SAASE,MAAM,QAAQ,iCAAgC;AACvD,SAASC,iBAAiB,QAAQ,yCAAwC;AAC1E,SAASC,aAAa,QAAQ,iCAAgC;AAC9D,SAASC,aAAa,QAAQ,iCAAgC;A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AChB,oBAACZ;QAAIC,WAAW,CAAC,EAAElD,UAAU,SAAS,CAAC;OACpC6C,+BACC,oBAAC3D;QACCgE,WAAW,CAAC,EAAElD,UAAU,uBAAuB,CAAC;QAChD8D,UAAU3C,OAAO4C;QACjBlC,MAAMC;qBAEN,oBAAC9C;QACCgF,aAAY;QACZC,IAAG;QACHC,MAAK;QACLC,SAAS,CAACC;YACRA,EAAEC,cAAc;QAClB;QACAC,OAAAA;QACAC,SAASlD,EAAE;UAGb,oBAEJ,oBAACrC;QACCgF,aAAY;QACZF,UAAU3C,OAAO4C;QACjBE,IAAG;QACHC,MAAK;QACLC,SAAS;YACPrD,OAAO0D,eAAe,CAAC1E,mCAAmC;gBACxD2E,SAAS;oBAAEhE;gBAAQ;YACrB;QACF;QACA6D,OAAAA;QACAC,SAASlD,EAAE;sBAEb,oBAACrC;QACCgF,aAAY;QACZd,WAAW,CAAC,EAAElD,UAAU,cAAc,CAAC;QACvC8D,UAAU3C,OAAO4C;QACjBG,MAAK;QACLC,SAAS,CAACC;YACRA,EAAEC,cAAc;YAChB7B;QACF;QACA8B,OAAAA;QACAC,SAASlD,EAAE;yBAMrB,oBAAC4B;QAAIC,WAAW,CAAC,EAAElD,UAAU,WAAW,CAAC;qBACvC,oBAACgC;QAAsBkB,WAAW,CAAC,EAAElD,UAAU,oBAAoB,CAAC;qBAClE,oBAAC0E,gBAAQrE,MAAMoD,cAIpBjD,OAAO0B,oBAAM,oBAACH;QAAe4C,QAAQhC;QACrCE,+BACC,oBAAC9C;QACC+B,YAAYA;QACZL,mBAAmBA;QAClB,GAAGrB,KAAK;SAET;AAGV;AAEA,OAAO,MAAMwE,kBAAkB,CAACxE;IAC9B,qBACE,oBAACP;QAA+B,GAAGO,KAAK;QAAEyE,SAAAA;qBACxC,oBAAC1E,WAAcC;AAGrB,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/field/features/upload/validate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../../../../src/field/features/upload/validate.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAA;AAIjE,eAAO,MAAM,gBAAgB,QAAO,eAAe,oBAAoB,CAuBtE,CAAA"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getIDType, isValidID } from 'payload/utilities';
|
|
1
|
+
import { isValidID } from 'payload/utilities';
|
|
3
2
|
import { CAN_USE_DOM } from '../../lexical/utils/canUseDOM.js';
|
|
4
3
|
export const uploadValidation = ()=>{
|
|
5
|
-
const uploadValidation = ({ node, validation: { options: { req: { payload
|
|
4
|
+
const uploadValidation = ({ node, validation: { options: { req: { payload, t } } } })=>{
|
|
6
5
|
if (!CAN_USE_DOM) {
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
if (!isValidID(node.value?.id, type)) {
|
|
6
|
+
const idType = payload.collections[node.relationTo].customIDType || payload.db.defaultIDType;
|
|
7
|
+
if (!isValidID(node.value?.id, idType)) {
|
|
10
8
|
return t('validation:validUploadID');
|
|
11
9
|
}
|
|
12
10
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/field/features/upload/validate.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../src/field/features/upload/validate.ts"],"sourcesContent":["import { isValidID } from 'payload/utilities'\n\nimport type { NodeValidation } from '../types.js'\nimport type { SerializedUploadNode } from './nodes/UploadNode.js'\n\nimport { CAN_USE_DOM } from '../../lexical/utils/canUseDOM.js'\n\nexport const uploadValidation = (): NodeValidation<SerializedUploadNode> => {\n const uploadValidation: NodeValidation<SerializedUploadNode> = ({\n node,\n validation: {\n options: {\n req: { payload, t },\n },\n },\n }) => {\n if (!CAN_USE_DOM) {\n const idType = payload.collections[node.relationTo].customIDType || payload.db.defaultIDType\n\n if (!isValidID(node.value?.id, idType)) {\n return t('validation:validUploadID')\n }\n }\n\n // TODO: validate upload collection fields\n\n return true\n }\n\n return uploadValidation\n}\n"],"names":["isValidID","CAN_USE_DOM","uploadValidation","node","validation","options","req","payload","t","idType","collections","relationTo","customIDType","db","defaultIDType","value","id"],"rangeMappings":";;;;;;;;;;;;;;","mappings":"AAAA,SAASA,SAAS,QAAQ,oBAAmB;AAK7C,SAASC,WAAW,QAAQ,mCAAkC;AAE9D,OAAO,MAAMC,mBAAmB;IAC9B,MAAMA,mBAAyD,CAAC,EAC9DC,IAAI,EACJC,YAAY,EACVC,SAAS,EACPC,KAAK,EAAEC,OAAO,EAAEC,CAAC,EAAE,EACpB,EACF,EACF;QACC,IAAI,CAACP,aAAa;YAChB,MAAMQ,SAASF,QAAQG,WAAW,CAACP,KAAKQ,UAAU,CAAC,CAACC,YAAY,IAAIL,QAAQM,EAAE,CAACC,aAAa;YAE5F,IAAI,CAACd,UAAUG,KAAKY,KAAK,EAAEC,IAAIP,SAAS;gBACtC,OAAOD,EAAE;YACX;QACF;QAEA,0CAA0C;QAE1C,OAAO;IACT;IAEA,OAAON;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../../../src/field/lexical/config/server/default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAEnF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../../../src/field/lexical/config/server/default.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAA;AAEnF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAA;AACvE,OAAO,KAAK,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAwBlF,eAAO,MAAM,0BAA0B,EAAE,mBAGxC,CAAA;AAED,eAAO,MAAM,qBAAqB,EAAE,qBAAqB,CAAC,OAAO,EAAE,OAAO,CAAC,EAoB1E,CAAA;AAED,eAAO,MAAM,mBAAmB,EAAE,kBAGjC,CAAA;AAED,eAAO,MAAM,kCAAkC,EAAE,2BACA,CAAA"}
|
|
@@ -8,6 +8,7 @@ import { SubscriptFeature } from '../../../features/format/subscript/feature.ser
|
|
|
8
8
|
import { SuperscriptFeature } from '../../../features/format/superscript/feature.server.js';
|
|
9
9
|
import { UnderlineFeature } from '../../../features/format/underline/feature.server.js';
|
|
10
10
|
import { HeadingFeature } from '../../../features/heading/feature.server.js';
|
|
11
|
+
import { HorizontalRuleFeature } from '../../../features/horizontalrule/feature.server.js';
|
|
11
12
|
import { IndentFeature } from '../../../features/indent/feature.server.js';
|
|
12
13
|
import { LinkFeature } from '../../../features/link/feature.server.js';
|
|
13
14
|
import { CheckListFeature } from '../../../features/lists/checklist/feature.server.js';
|
|
@@ -40,7 +41,8 @@ export const defaultEditorFeatures = [
|
|
|
40
41
|
LinkFeature(),
|
|
41
42
|
RelationshipFeature(),
|
|
42
43
|
BlockQuoteFeature(),
|
|
43
|
-
UploadFeature()
|
|
44
|
+
UploadFeature(),
|
|
45
|
+
HorizontalRuleFeature()
|
|
44
46
|
];
|
|
45
47
|
export const defaultEditorConfig = {
|
|
46
48
|
features: defaultEditorFeatures,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/field/lexical/config/server/default.ts"],"sourcesContent":["import type { EditorConfig as LexicalEditorConfig } from 'lexical/LexicalEditor.js'\n\nimport type { FeatureProviderServer } from '../../../features/types.js'\nimport type { SanitizedServerEditorConfig, ServerEditorConfig } from '../types.js'\n\nimport { AlignFeature } from '../../../features/align/feature.server.js'\nimport { BlockQuoteFeature } from '../../../features/blockquote/feature.server.js'\nimport { BoldFeature } from '../../../features/format/bold/feature.server.js'\nimport { InlineCodeFeature } from '../../../features/format/inlinecode/feature.server.js'\nimport { ItalicFeature } from '../../../features/format/italic/feature.server.js'\nimport { StrikethroughFeature } from '../../../features/format/strikethrough/feature.server.js'\nimport { SubscriptFeature } from '../../../features/format/subscript/feature.server.js'\nimport { SuperscriptFeature } from '../../../features/format/superscript/feature.server.js'\nimport { UnderlineFeature } from '../../../features/format/underline/feature.server.js'\nimport { HeadingFeature } from '../../../features/heading/feature.server.js'\nimport { IndentFeature } from '../../../features/indent/feature.server.js'\nimport { LinkFeature } from '../../../features/link/feature.server.js'\nimport { CheckListFeature } from '../../../features/lists/checklist/feature.server.js'\nimport { OrderedListFeature } from '../../../features/lists/orderedlist/feature.server.js'\nimport { UnorderedListFeature } from '../../../features/lists/unorderedlist/feature.server.js'\nimport { ParagraphFeature } from '../../../features/paragraph/feature.server.js'\nimport { RelationshipFeature } from '../../../features/relationship/feature.server.js'\nimport { UploadFeature } from '../../../features/upload/feature.server.js'\nimport { LexicalEditorTheme } from '../../theme/EditorTheme.js'\nimport { sanitizeServerEditorConfig } from './sanitize.js'\n\nexport const defaultEditorLexicalConfig: LexicalEditorConfig = {\n namespace: 'lexical',\n theme: LexicalEditorTheme,\n}\n\nexport const defaultEditorFeatures: FeatureProviderServer<unknown, unknown>[] = [\n BoldFeature(),\n ItalicFeature(),\n UnderlineFeature(),\n StrikethroughFeature(),\n SubscriptFeature(),\n SuperscriptFeature(),\n InlineCodeFeature(),\n ParagraphFeature(),\n HeadingFeature(),\n AlignFeature(),\n IndentFeature(),\n UnorderedListFeature(),\n OrderedListFeature(),\n CheckListFeature(),\n LinkFeature(),\n RelationshipFeature(),\n BlockQuoteFeature(),\n UploadFeature(),\n]\n\nexport const defaultEditorConfig: ServerEditorConfig = {\n features: defaultEditorFeatures,\n lexical: defaultEditorLexicalConfig,\n}\n\nexport const defaultSanitizedServerEditorConfig: SanitizedServerEditorConfig =\n sanitizeServerEditorConfig(defaultEditorConfig)\n"],"names":["AlignFeature","BlockQuoteFeature","BoldFeature","InlineCodeFeature","ItalicFeature","StrikethroughFeature","SubscriptFeature","SuperscriptFeature","UnderlineFeature","HeadingFeature","IndentFeature","LinkFeature","CheckListFeature","OrderedListFeature","UnorderedListFeature","ParagraphFeature","RelationshipFeature","UploadFeature","LexicalEditorTheme","sanitizeServerEditorConfig","defaultEditorLexicalConfig","namespace","theme","defaultEditorFeatures","defaultEditorConfig","features","lexical","defaultSanitizedServerEditorConfig"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/field/lexical/config/server/default.ts"],"sourcesContent":["import type { EditorConfig as LexicalEditorConfig } from 'lexical/LexicalEditor.js'\n\nimport type { FeatureProviderServer } from '../../../features/types.js'\nimport type { SanitizedServerEditorConfig, ServerEditorConfig } from '../types.js'\n\nimport { AlignFeature } from '../../../features/align/feature.server.js'\nimport { BlockQuoteFeature } from '../../../features/blockquote/feature.server.js'\nimport { BoldFeature } from '../../../features/format/bold/feature.server.js'\nimport { InlineCodeFeature } from '../../../features/format/inlinecode/feature.server.js'\nimport { ItalicFeature } from '../../../features/format/italic/feature.server.js'\nimport { StrikethroughFeature } from '../../../features/format/strikethrough/feature.server.js'\nimport { SubscriptFeature } from '../../../features/format/subscript/feature.server.js'\nimport { SuperscriptFeature } from '../../../features/format/superscript/feature.server.js'\nimport { UnderlineFeature } from '../../../features/format/underline/feature.server.js'\nimport { HeadingFeature } from '../../../features/heading/feature.server.js'\nimport { HorizontalRuleFeature } from '../../../features/horizontalrule/feature.server.js'\nimport { IndentFeature } from '../../../features/indent/feature.server.js'\nimport { LinkFeature } from '../../../features/link/feature.server.js'\nimport { CheckListFeature } from '../../../features/lists/checklist/feature.server.js'\nimport { OrderedListFeature } from '../../../features/lists/orderedlist/feature.server.js'\nimport { UnorderedListFeature } from '../../../features/lists/unorderedlist/feature.server.js'\nimport { ParagraphFeature } from '../../../features/paragraph/feature.server.js'\nimport { RelationshipFeature } from '../../../features/relationship/feature.server.js'\nimport { UploadFeature } from '../../../features/upload/feature.server.js'\nimport { LexicalEditorTheme } from '../../theme/EditorTheme.js'\nimport { sanitizeServerEditorConfig } from './sanitize.js'\n\nexport const defaultEditorLexicalConfig: LexicalEditorConfig = {\n namespace: 'lexical',\n theme: LexicalEditorTheme,\n}\n\nexport const defaultEditorFeatures: FeatureProviderServer<unknown, unknown>[] = [\n BoldFeature(),\n ItalicFeature(),\n UnderlineFeature(),\n StrikethroughFeature(),\n SubscriptFeature(),\n SuperscriptFeature(),\n InlineCodeFeature(),\n ParagraphFeature(),\n HeadingFeature(),\n AlignFeature(),\n IndentFeature(),\n UnorderedListFeature(),\n OrderedListFeature(),\n CheckListFeature(),\n LinkFeature(),\n RelationshipFeature(),\n BlockQuoteFeature(),\n UploadFeature(),\n HorizontalRuleFeature(),\n]\n\nexport const defaultEditorConfig: ServerEditorConfig = {\n features: defaultEditorFeatures,\n lexical: defaultEditorLexicalConfig,\n}\n\nexport const defaultSanitizedServerEditorConfig: SanitizedServerEditorConfig =\n sanitizeServerEditorConfig(defaultEditorConfig)\n"],"names":["AlignFeature","BlockQuoteFeature","BoldFeature","InlineCodeFeature","ItalicFeature","StrikethroughFeature","SubscriptFeature","SuperscriptFeature","UnderlineFeature","HeadingFeature","HorizontalRuleFeature","IndentFeature","LinkFeature","CheckListFeature","OrderedListFeature","UnorderedListFeature","ParagraphFeature","RelationshipFeature","UploadFeature","LexicalEditorTheme","sanitizeServerEditorConfig","defaultEditorLexicalConfig","namespace","theme","defaultEditorFeatures","defaultEditorConfig","features","lexical","defaultSanitizedServerEditorConfig"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,SAASA,YAAY,QAAQ,4CAA2C;AACxE,SAASC,iBAAiB,QAAQ,iDAAgD;AAClF,SAASC,WAAW,QAAQ,kDAAiD;AAC7E,SAASC,iBAAiB,QAAQ,wDAAuD;AACzF,SAASC,aAAa,QAAQ,oDAAmD;AACjF,SAASC,oBAAoB,QAAQ,2DAA0D;AAC/F,SAASC,gBAAgB,QAAQ,uDAAsD;AACvF,SAASC,kBAAkB,QAAQ,yDAAwD;AAC3F,SAASC,gBAAgB,QAAQ,uDAAsD;AACvF,SAASC,cAAc,QAAQ,8CAA6C;AAC5E,SAASC,qBAAqB,QAAQ,qDAAoD;AAC1F,SAASC,aAAa,QAAQ,6CAA4C;AAC1E,SAASC,WAAW,QAAQ,2CAA0C;AACtE,SAASC,gBAAgB,QAAQ,sDAAqD;AACtF,SAASC,kBAAkB,QAAQ,wDAAuD;AAC1F,SAASC,oBAAoB,QAAQ,0DAAyD;AAC9F,SAASC,gBAAgB,QAAQ,gDAA+C;AAChF,SAASC,mBAAmB,QAAQ,mDAAkD;AACtF,SAASC,aAAa,QAAQ,6CAA4C;AAC1E,SAASC,kBAAkB,QAAQ,6BAA4B;AAC/D,SAASC,0BAA0B,QAAQ,gBAAe;AAE1D,OAAO,MAAMC,6BAAkD;IAC7DC,WAAW;IACXC,OAAOJ;AACT,EAAC;AAED,OAAO,MAAMK,wBAAmE;IAC9EtB;IACAE;IACAI;IACAH;IACAC;IACAC;IACAJ;IACAa;IACAP;IACAT;IACAW;IACAI;IACAD;IACAD;IACAD;IACAK;IACAhB;IACAiB;IACAR;CACD,CAAA;AAED,OAAO,MAAMe,sBAA0C;IACrDC,UAAUF;IACVG,SAASN;AACX,EAAC;AAED,OAAO,MAAMO,qCACXR,2BAA2BK,qBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/lexical/plugins/handles/AddBlockHandlePlugin/index.tsx"],"names":[],"mappings":";AAoBA,OAAO,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/lexical/plugins/handles/AddBlockHandlePlugin/index.tsx"],"names":[],"mappings":";AAoBA,OAAO,cAAc,CAAA;AA4SrB,wBAAgB,oBAAoB,CAAC,EACnC,UAA0B,GAC3B,EAAE;IACD,UAAU,CAAC,EAAE,WAAW,CAAA;CACzB,GAAG,GAAG,CAAC,OAAO,CAGd"}
|
|
@@ -122,7 +122,9 @@ function useAddBlockHandle(editor, anchorElem, isEditable) {
|
|
|
122
122
|
const adjustedTop = top + window.scrollY;
|
|
123
123
|
const adjustedBottom = bottom + window.scrollY;
|
|
124
124
|
if (pageY < adjustedTop - verticalBuffer || pageY > adjustedBottom + verticalBuffer || pageX < left - horizontalBuffer || pageX > right + horizontalBuffer) {
|
|
125
|
-
|
|
125
|
+
if (hoveredElement !== null) {
|
|
126
|
+
setHoveredElement(null);
|
|
127
|
+
}
|
|
126
128
|
return;
|
|
127
129
|
}
|
|
128
130
|
// This is used to allow the _emptyBlockElem to be found when the mouse is in the
|
|
@@ -138,10 +140,12 @@ function useAddBlockHandle(editor, anchorElem, isEditable) {
|
|
|
138
140
|
if (!_emptyBlockElem) {
|
|
139
141
|
return;
|
|
140
142
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
if (hoveredElement?.node !== blockNode || hoveredElement?.elem !== _emptyBlockElem) {
|
|
144
|
+
setHoveredElement({
|
|
145
|
+
elem: _emptyBlockElem,
|
|
146
|
+
node: blockNode
|
|
147
|
+
});
|
|
148
|
+
}
|
|
145
149
|
}
|
|
146
150
|
// Since the draggableBlockElem is outside the actual editor, we need to listen to the document
|
|
147
151
|
// to be able to detect when the mouse is outside the editor and respect a buffer around
|
|
@@ -153,7 +157,8 @@ function useAddBlockHandle(editor, anchorElem, isEditable) {
|
|
|
153
157
|
}, [
|
|
154
158
|
scrollerElem,
|
|
155
159
|
anchorElem,
|
|
156
|
-
editor
|
|
160
|
+
editor,
|
|
161
|
+
hoveredElement
|
|
157
162
|
]);
|
|
158
163
|
useEffect(()=>{
|
|
159
164
|
if (menuRef.current && hoveredElement?.node) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/field/lexical/plugins/handles/AddBlockHandlePlugin/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor, LexicalNode, ParagraphNode } from 'lexical'\n\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\nimport lexicalImport from 'lexical'\nconst { $createParagraphNode, $getNodeByKey } = lexicalImport\n\nimport * as React from 'react'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { isHTMLElement } from '../../../utils/guard.js'\nimport { Point } from '../../../utils/point.js'\nimport { Rect } from '../../../utils/rect.js'\nimport { ENABLE_SLASH_MENU_COMMAND } from '../../SlashMenu/LexicalTypeaheadMenuPlugin/index.js'\nimport { getCollapsedMargins } from '../utils/getCollapsedMargins.js'\nimport { getTopLevelNodeKeys } from '../utils/getTopLevelNodeKeys.js'\nimport { isOnHandleElement } from '../utils/isOnHandleElement.js'\nimport { setHandlePosition } from '../utils/setHandlePosition.js'\nimport './index.scss'\n\nconst SPACE = -24\nconst ADD_BLOCK_MENU_CLASSNAME = 'add-block-menu'\n\nconst Downward = 1\nconst Upward = -1\nconst Indeterminate = 0\n\nlet prevIndex = Infinity\n\nfunction getCurrentIndex(keysLength: number): number {\n if (keysLength === 0) {\n return Infinity\n }\n if (prevIndex >= 0 && prevIndex < keysLength) {\n return prevIndex\n }\n\n return Math.floor(keysLength / 2)\n}\n\nfunction getBlockElement(\n anchorElem: HTMLElement,\n editor: LexicalEditor,\n event: MouseEvent,\n useEdgeAsDefault = false,\n horizontalOffset = 0,\n): {\n blockElem: HTMLElement | null\n blockNode: LexicalNode | null\n} {\n const anchorElementRect = anchorElem.getBoundingClientRect()\n const topLevelNodeKeys = getTopLevelNodeKeys(editor)\n\n let blockElem: HTMLElement | null = null\n let blockNode: LexicalNode | null = null\n\n // Return null if matching block element is the first or last node\n editor.getEditorState().read(() => {\n if (useEdgeAsDefault) {\n const [firstNode, lastNode] = [\n editor.getElementByKey(topLevelNodeKeys[0]),\n editor.getElementByKey(topLevelNodeKeys[topLevelNodeKeys.length - 1]),\n ]\n\n const [firstNodeRect, lastNodeRect] = [\n firstNode?.getBoundingClientRect(),\n lastNode?.getBoundingClientRect(),\n ]\n\n if (firstNodeRect && lastNodeRect) {\n if (event.y < firstNodeRect.top) {\n blockElem = firstNode\n } else if (event.y > lastNodeRect.bottom) {\n blockElem = lastNode\n }\n\n if (blockElem) {\n return {\n blockElem: null,\n }\n }\n }\n }\n\n // Find matching block element\n let index = getCurrentIndex(topLevelNodeKeys.length)\n let direction = Indeterminate\n\n while (index >= 0 && index < topLevelNodeKeys.length) {\n const key = topLevelNodeKeys[index]\n const elem = editor.getElementByKey(key)\n if (elem === null) {\n break\n }\n const point = new Point(event.x + horizontalOffset, event.y)\n const domRect = Rect.fromDOM(elem)\n const { marginBottom, marginTop } = getCollapsedMargins(elem)\n\n const rect = domRect.generateNewRect({\n bottom: domRect.bottom + marginBottom,\n left: anchorElementRect.left,\n right: anchorElementRect.right,\n top: domRect.top - marginTop,\n })\n\n const {\n reason: { isOnBottomSide, isOnTopSide },\n result,\n } = rect.contains(point)\n\n if (result) {\n blockElem = elem\n blockNode = $getNodeByKey(key)\n prevIndex = index\n break\n }\n\n if (direction === Indeterminate) {\n if (isOnTopSide) {\n direction = Upward\n } else if (isOnBottomSide) {\n direction = Downward\n } else {\n // stop search block element\n direction = Infinity\n }\n }\n\n index += direction\n }\n })\n\n return {\n blockElem,\n blockNode,\n }\n}\n\nfunction useAddBlockHandle(\n editor: LexicalEditor,\n anchorElem: HTMLElement,\n isEditable: boolean,\n): JSX.Element {\n const scrollerElem = anchorElem.parentElement\n\n const menuRef = useRef<HTMLButtonElement>(null)\n const [hoveredElement, setHoveredElement] = useState<{\n elem: HTMLElement\n node: LexicalNode\n } | null>(null)\n\n useEffect(() => {\n function onDocumentMouseMove(event: MouseEvent) {\n const target = event.target\n if (!isHTMLElement(target)) {\n return\n }\n\n let distanceFromScrollerElem = 0\n // Calculate distance between scrollerElem and target if target is not in scrollerElem\n if (scrollerElem && !scrollerElem.contains(target)) {\n const { bottom, left, right, top } = scrollerElem.getBoundingClientRect()\n const { pageX, pageY } = event\n const horizontalBuffer = 50\n const verticalBuffer = 25\n const adjustedTop = top + window.scrollY\n const adjustedBottom = bottom + window.scrollY\n\n if (\n pageY < adjustedTop - verticalBuffer ||\n pageY > adjustedBottom + verticalBuffer ||\n pageX < left - horizontalBuffer ||\n pageX > right + horizontalBuffer\n ) {\n setHoveredElement(null)\n return\n }\n\n // This is used to allow the _emptyBlockElem to be found when the mouse is in the\n // buffer zone around the scrollerElem.\n if (pageX < left || pageX > right) {\n distanceFromScrollerElem = pageX < left ? pageX - left : pageX - right\n }\n }\n\n if (isOnHandleElement(target, ADD_BLOCK_MENU_CLASSNAME)) {\n return\n }\n const { blockElem: _emptyBlockElem, blockNode } = getBlockElement(\n anchorElem,\n editor,\n event,\n false,\n -distanceFromScrollerElem,\n )\n if (!_emptyBlockElem) {\n return\n }\n setHoveredElement({\n elem: _emptyBlockElem,\n node: blockNode,\n })\n }\n\n // Since the draggableBlockElem is outside the actual editor, we need to listen to the document\n // to be able to detect when the mouse is outside the editor and respect a buffer around\n // the scrollerElem to avoid the draggableBlockElem disappearing too early.\n document?.addEventListener('mousemove', onDocumentMouseMove)\n\n return () => {\n document?.removeEventListener('mousemove', onDocumentMouseMove)\n }\n }, [scrollerElem, anchorElem, editor])\n\n useEffect(() => {\n if (menuRef.current && hoveredElement?.node) {\n editor.getEditorState().read(() => {\n // Check if blockNode is an empty text node\n let isEmptyParagraph = true\n if (\n hoveredElement.node.getType() !== 'paragraph' ||\n hoveredElement.node.getTextContent() !== ''\n ) {\n isEmptyParagraph = false\n }\n\n setHandlePosition(\n hoveredElement?.elem,\n menuRef.current,\n anchorElem,\n isEmptyParagraph ? SPACE : SPACE - 20,\n )\n })\n }\n }, [anchorElem, hoveredElement, editor])\n\n const handleAddClick = useCallback(\n (event) => {\n let hoveredElementToUse = hoveredElement\n if (!hoveredElementToUse?.node) {\n return\n }\n\n // 1. Update hoveredElement.node to a new paragraph node if the hoveredElement.node is not a paragraph node\n editor.update(() => {\n // Check if blockNode is an empty text node\n let isEmptyParagraph = true\n if (\n hoveredElementToUse.node.getType() !== 'paragraph' ||\n hoveredElementToUse.node.getTextContent() !== ''\n ) {\n isEmptyParagraph = false\n }\n\n if (!isEmptyParagraph) {\n const newParagraph = $createParagraphNode()\n hoveredElementToUse.node.insertAfter(newParagraph)\n\n setTimeout(() => {\n hoveredElementToUse = {\n elem: editor.getElementByKey(newParagraph.getKey()),\n node: newParagraph,\n }\n setHoveredElement(hoveredElementToUse)\n }, 0)\n }\n })\n\n // 2. Focus on the new paragraph node\n setTimeout(() => {\n editor.update(() => {\n editor.focus()\n\n if (\n hoveredElementToUse.node &&\n 'select' in hoveredElementToUse.node &&\n typeof hoveredElementToUse.node.select === 'function'\n ) {\n hoveredElementToUse.node.select()\n }\n })\n }, 1)\n\n // Make sure this is called AFTER the focusing has been processed by the browser\n // Otherwise, this won't work\n setTimeout(() => {\n editor.dispatchCommand(ENABLE_SLASH_MENU_COMMAND, {\n node: hoveredElementToUse.node as ParagraphNode,\n })\n }, 2)\n\n event.stopPropagation()\n event.preventDefault()\n },\n [editor, hoveredElement],\n )\n\n return createPortal(\n <React.Fragment>\n <button\n className=\"icon add-block-menu\"\n onClick={(event) => {\n handleAddClick(event)\n }}\n ref={menuRef}\n type=\"button\"\n >\n <div className={isEditable ? 'icon' : ''} />\n </button>\n </React.Fragment>,\n anchorElem,\n )\n}\n\nexport function AddBlockHandlePlugin({\n anchorElem = document.body,\n}: {\n anchorElem?: HTMLElement\n}): JSX.Element {\n const [editor] = useLexicalComposerContext()\n return useAddBlockHandle(editor, anchorElem, editor._editable)\n}\n"],"names":["lexicalComposerContextImport","useLexicalComposerContext","lexicalImport","$createParagraphNode","$getNodeByKey","React","useCallback","useEffect","useRef","useState","createPortal","isHTMLElement","Point","Rect","ENABLE_SLASH_MENU_COMMAND","getCollapsedMargins","getTopLevelNodeKeys","isOnHandleElement","setHandlePosition","SPACE","ADD_BLOCK_MENU_CLASSNAME","Downward","Upward","Indeterminate","prevIndex","Infinity","getCurrentIndex","keysLength","Math","floor","getBlockElement","anchorElem","editor","event","useEdgeAsDefault","horizontalOffset","anchorElementRect","getBoundingClientRect","topLevelNodeKeys","blockElem","blockNode","getEditorState","read","firstNode","lastNode","getElementByKey","length","firstNodeRect","lastNodeRect","y","top","bottom","index","direction","key","elem","point","x","domRect","fromDOM","marginBottom","marginTop","rect","generateNewRect","left","right","reason","isOnBottomSide","isOnTopSide","result","contains","useAddBlockHandle","isEditable","scrollerElem","parentElement","menuRef","hoveredElement","setHoveredElement","onDocumentMouseMove","target","distanceFromScrollerElem","pageX","pageY","horizontalBuffer","verticalBuffer","adjustedTop","window","scrollY","adjustedBottom","_emptyBlockElem","node","document","addEventListener","removeEventListener","current","isEmptyParagraph","getType","getTextContent","handleAddClick","hoveredElementToUse","update","newParagraph","insertAfter","setTimeout","getKey","focus","select","dispatchCommand","stopPropagation","preventDefault","Fragment","button","className","onClick","ref","type","div","AddBlockHandlePlugin","body","_editable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAGA,OAAOA,kCAAkC,2CAA0C;AACnF,MAAM,EAAEC,yBAAyB,EAAE,GAAGD;AACtC,OAAOE,mBAAmB,UAAS;AACnC,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MAAM;wBAChDd,MAAMW;oBACR;oBACAxB,kBAAkBsB;gBACpB,GAAG;YACL;QACF;QAEA,qCAAqC;QACrCI,WAAW;YACTvE,OAAOoE,MAAM,CAAC;gBACZpE,OAAOyE,KAAK;gBAEZ,IACEN,oBAAoBT,IAAI,IACxB,YAAYS,oBAAoBT,IAAI,IACpC,OAAOS,oBAAoBT,IAAI,CAACgB,MAAM,KAAK,YAC3C;oBACAP,oBAAoBT,IAAI,CAACgB,MAAM;gBACjC;YACF;QACF,GAAG;QAEH,gFAAgF;QAChF,6BAA6B;QAC7BH,WAAW;YACTvE,OAAO2E,eAAe,CAAC7F,2BAA2B;gBAChD4E,MAAMS,oBAAoBT,IAAI;YAChC;QACF,GAAG;QAEHzD,MAAM2E,eAAe;QACrB3E,MAAM4E,cAAc;IACtB,GACA;QAAC7E;QAAQ4C;KAAe;IAG1B,qBAAOlE,2BACL,oBAACL,MAAMyG,QAAQ,sBACb,oBAACC;QACCC,WAAU;QACVC,SAAS,CAAChF;YACRiE,eAAejE;QACjB;QACAiF,KAAKvC;QACLwC,MAAK;qBAEL,oBAACC;QAAIJ,WAAWxC,aAAa,SAAS;UAG1CzC;AAEJ;AAEA,OAAO,SAASsF,qBAAqB,EACnCtF,aAAa4D,SAAS2B,IAAI,EAG3B;IACC,MAAM,CAACtF,OAAO,GAAG/B;IACjB,OAAOsE,kBAAkBvC,QAAQD,YAAYC,OAAOuF,SAAS;AAC/D"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/field/lexical/plugins/handles/AddBlockHandlePlugin/index.tsx"],"sourcesContent":["'use client'\nimport type { LexicalEditor, LexicalNode, ParagraphNode } from 'lexical'\n\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\nimport lexicalImport from 'lexical'\nconst { $createParagraphNode, $getNodeByKey } = lexicalImport\n\nimport * as React from 'react'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { isHTMLElement } from '../../../utils/guard.js'\nimport { Point } from '../../../utils/point.js'\nimport { Rect } from '../../../utils/rect.js'\nimport { ENABLE_SLASH_MENU_COMMAND } from '../../SlashMenu/LexicalTypeaheadMenuPlugin/index.js'\nimport { getCollapsedMargins } from '../utils/getCollapsedMargins.js'\nimport { getTopLevelNodeKeys } from '../utils/getTopLevelNodeKeys.js'\nimport { isOnHandleElement } from '../utils/isOnHandleElement.js'\nimport { setHandlePosition } from '../utils/setHandlePosition.js'\nimport './index.scss'\n\nconst SPACE = -24\nconst ADD_BLOCK_MENU_CLASSNAME = 'add-block-menu'\n\nconst Downward = 1\nconst Upward = -1\nconst Indeterminate = 0\n\nlet prevIndex = Infinity\n\nfunction getCurrentIndex(keysLength: number): number {\n if (keysLength === 0) {\n return Infinity\n }\n if (prevIndex >= 0 && prevIndex < keysLength) {\n return prevIndex\n }\n\n return Math.floor(keysLength / 2)\n}\n\nfunction getBlockElement(\n anchorElem: HTMLElement,\n editor: LexicalEditor,\n event: MouseEvent,\n useEdgeAsDefault = false,\n horizontalOffset = 0,\n): {\n blockElem: HTMLElement | null\n blockNode: LexicalNode | null\n} {\n const anchorElementRect = anchorElem.getBoundingClientRect()\n const topLevelNodeKeys = getTopLevelNodeKeys(editor)\n\n let blockElem: HTMLElement | null = null\n let blockNode: LexicalNode | null = null\n\n // Return null if matching block element is the first or last node\n editor.getEditorState().read(() => {\n if (useEdgeAsDefault) {\n const [firstNode, lastNode] = [\n editor.getElementByKey(topLevelNodeKeys[0]),\n editor.getElementByKey(topLevelNodeKeys[topLevelNodeKeys.length - 1]),\n ]\n\n const [firstNodeRect, lastNodeRect] = [\n firstNode?.getBoundingClientRect(),\n lastNode?.getBoundingClientRect(),\n ]\n\n if (firstNodeRect && lastNodeRect) {\n if (event.y < firstNodeRect.top) {\n blockElem = firstNode\n } else if (event.y > lastNodeRect.bottom) {\n blockElem = lastNode\n }\n\n if (blockElem) {\n return {\n blockElem: null,\n }\n }\n }\n }\n\n // Find matching block element\n let index = getCurrentIndex(topLevelNodeKeys.length)\n let direction = Indeterminate\n\n while (index >= 0 && index < topLevelNodeKeys.length) {\n const key = topLevelNodeKeys[index]\n const elem = editor.getElementByKey(key)\n if (elem === null) {\n break\n }\n const point = new Point(event.x + horizontalOffset, event.y)\n const domRect = Rect.fromDOM(elem)\n const { marginBottom, marginTop } = getCollapsedMargins(elem)\n\n const rect = domRect.generateNewRect({\n bottom: domRect.bottom + marginBottom,\n left: anchorElementRect.left,\n right: anchorElementRect.right,\n top: domRect.top - marginTop,\n })\n\n const {\n reason: { isOnBottomSide, isOnTopSide },\n result,\n } = rect.contains(point)\n\n if (result) {\n blockElem = elem\n blockNode = $getNodeByKey(key)\n prevIndex = index\n break\n }\n\n if (direction === Indeterminate) {\n if (isOnTopSide) {\n direction = Upward\n } else if (isOnBottomSide) {\n direction = Downward\n } else {\n // stop search block element\n direction = Infinity\n }\n }\n\n index += direction\n }\n })\n\n return {\n blockElem,\n blockNode,\n }\n}\n\nfunction useAddBlockHandle(\n editor: LexicalEditor,\n anchorElem: HTMLElement,\n isEditable: boolean,\n): JSX.Element {\n const scrollerElem = anchorElem.parentElement\n\n const menuRef = useRef<HTMLButtonElement>(null)\n const [hoveredElement, setHoveredElement] = useState<{\n elem: HTMLElement\n node: LexicalNode\n } | null>(null)\n\n useEffect(() => {\n function onDocumentMouseMove(event: MouseEvent) {\n const target = event.target\n if (!isHTMLElement(target)) {\n return\n }\n\n let distanceFromScrollerElem = 0\n // Calculate distance between scrollerElem and target if target is not in scrollerElem\n if (scrollerElem && !scrollerElem.contains(target)) {\n const { bottom, left, right, top } = scrollerElem.getBoundingClientRect()\n const { pageX, pageY } = event\n const horizontalBuffer = 50\n const verticalBuffer = 25\n const adjustedTop = top + window.scrollY\n const adjustedBottom = bottom + window.scrollY\n\n if (\n pageY < adjustedTop - verticalBuffer ||\n pageY > adjustedBottom + verticalBuffer ||\n pageX < left - horizontalBuffer ||\n pageX > right + horizontalBuffer\n ) {\n if (hoveredElement !== null) {\n setHoveredElement(null)\n }\n return\n }\n\n // This is used to allow the _emptyBlockElem to be found when the mouse is in the\n // buffer zone around the scrollerElem.\n if (pageX < left || pageX > right) {\n distanceFromScrollerElem = pageX < left ? pageX - left : pageX - right\n }\n }\n\n if (isOnHandleElement(target, ADD_BLOCK_MENU_CLASSNAME)) {\n return\n }\n const { blockElem: _emptyBlockElem, blockNode } = getBlockElement(\n anchorElem,\n editor,\n event,\n false,\n -distanceFromScrollerElem,\n )\n if (!_emptyBlockElem) {\n return\n }\n if (hoveredElement?.node !== blockNode || hoveredElement?.elem !== _emptyBlockElem) {\n setHoveredElement({\n elem: _emptyBlockElem,\n node: blockNode,\n })\n }\n }\n\n // Since the draggableBlockElem is outside the actual editor, we need to listen to the document\n // to be able to detect when the mouse is outside the editor and respect a buffer around\n // the scrollerElem to avoid the draggableBlockElem disappearing too early.\n document?.addEventListener('mousemove', onDocumentMouseMove)\n\n return () => {\n document?.removeEventListener('mousemove', onDocumentMouseMove)\n }\n }, [scrollerElem, anchorElem, editor, hoveredElement])\n\n useEffect(() => {\n if (menuRef.current && hoveredElement?.node) {\n editor.getEditorState().read(() => {\n // Check if blockNode is an empty text node\n let isEmptyParagraph = true\n if (\n hoveredElement.node.getType() !== 'paragraph' ||\n hoveredElement.node.getTextContent() !== ''\n ) {\n isEmptyParagraph = false\n }\n\n setHandlePosition(\n hoveredElement?.elem,\n menuRef.current,\n anchorElem,\n isEmptyParagraph ? SPACE : SPACE - 20,\n )\n })\n }\n }, [anchorElem, hoveredElement, editor])\n\n const handleAddClick = useCallback(\n (event) => {\n let hoveredElementToUse = hoveredElement\n if (!hoveredElementToUse?.node) {\n return\n }\n\n // 1. Update hoveredElement.node to a new paragraph node if the hoveredElement.node is not a paragraph node\n editor.update(() => {\n // Check if blockNode is an empty text node\n let isEmptyParagraph = true\n if (\n hoveredElementToUse.node.getType() !== 'paragraph' ||\n hoveredElementToUse.node.getTextContent() !== ''\n ) {\n isEmptyParagraph = false\n }\n\n if (!isEmptyParagraph) {\n const newParagraph = $createParagraphNode()\n hoveredElementToUse.node.insertAfter(newParagraph)\n\n setTimeout(() => {\n hoveredElementToUse = {\n elem: editor.getElementByKey(newParagraph.getKey()),\n node: newParagraph,\n }\n setHoveredElement(hoveredElementToUse)\n }, 0)\n }\n })\n\n // 2. Focus on the new paragraph node\n setTimeout(() => {\n editor.update(() => {\n editor.focus()\n\n if (\n hoveredElementToUse.node &&\n 'select' in hoveredElementToUse.node &&\n typeof hoveredElementToUse.node.select === 'function'\n ) {\n hoveredElementToUse.node.select()\n }\n })\n }, 1)\n\n // Make sure this is called AFTER the focusing has been processed by the browser\n // Otherwise, this won't work\n setTimeout(() => {\n editor.dispatchCommand(ENABLE_SLASH_MENU_COMMAND, {\n node: hoveredElementToUse.node as ParagraphNode,\n })\n }, 2)\n\n event.stopPropagation()\n event.preventDefault()\n },\n [editor, hoveredElement],\n )\n\n return createPortal(\n <React.Fragment>\n <button\n className=\"icon add-block-menu\"\n onClick={(event) => {\n handleAddClick(event)\n }}\n ref={menuRef}\n type=\"button\"\n >\n <div className={isEditable ? 'icon' : ''} />\n </button>\n </React.Fragment>,\n anchorElem,\n )\n}\n\nexport function AddBlockHandlePlugin({\n anchorElem = document.body,\n}: {\n anchorElem?: HTMLElement\n}): JSX.Element {\n const [editor] = useLexicalComposerContext()\n return useAddBlockHandle(editor, anchorElem, editor._editable)\n}\n"],"names":["lexicalComposerContextImport","useLexicalComposerContext","lexicalImport","$createParagraphNode","$getNodeByKey","React","useCallback","useEffect","useRef","useState","createPortal","isHTMLElement","Point","Rect","ENABLE_SLASH_MENU_COMMAND","getCollapsedMargins","getTopLevelNodeKeys","isOnHandleElement","setHandlePosition","SPACE","ADD_BLOCK_MENU_CLASSNAME","Downward","Upward","Indeterminate","prevIndex","Infinity","getCurrentIndex","keysLength","Math","floor","getBlockElement","anchorElem","editor","event","useEdgeAsDefault","horizontalOffset","anchorElementRect","getBoundingClientRect","topLevelNodeKeys","blockElem","blockNode","getEditorState","read","firstNode","lastNode","getElementByKey","length","firstNodeRect","lastNodeRect","y","top","bottom","index","direction","key","elem","point","x","domRect","fromDOM","marginBottom","marginTop","rect","generateNewRect","left","right","reason","isOnBottomSide","isOnTopSide","result","contains","useAddBlockHandle","isEditable","scrollerElem","parentElement","menuRef","hoveredElement","setHoveredElement","onDocumentMouseMove","target","distanceFromScrollerElem","pageX","pageY","horizontalBuffer","verticalBuffer","adjustedTop","window","scrollY","adjustedBottom","_emptyBlockElem","node","document","addEventListener","removeEventListener","current","isEmptyParagraph","getType","getTextContent","handleAddClick","hoveredElementToUse","update","newParagraph","insertAfter","setTimeout","getKey","focus","select","dispatchCommand","stopPropagation","preventDefault","Fragment","button","className","onClick","ref","type","div","AddBlockHandlePlugin","body","_editable"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAGA,OAAOA,kCAAkC,2CAA0C;AACnF,MAAM,EAAEC,yBAAyB,EAAE,GAAGD;AACtC,OAAOE,mBAAmB,UAAS;AACnC,MAAM,EAAEC,oBAAoB,EAAEC,aAAa,EAAE,GAAGF;AAEhD,YAAYG,WAAW,QAAO;AAC9B,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAChE,SAASC,YAAY,QAAQ,YAAW;AAExC,SAASC,aAAa,QAAQ,0BAAyB;AACvD,SAASC,KAAK,QAAQ,0BAAyB;AAC/C,SAASC,IAAI,QAAQ,yBAAwB;AAC7C,SAASC,yBAAyB,QAAQ,sDAAqD;AAC/F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IACpC,OAAOS,oBAAoBT,IAAI,CAACgB,MAAM,KAAK,YAC3C;oBACAP,oBAAoBT,IAAI,CAACgB,MAAM;gBACjC;YACF;QACF,GAAG;QAEH,gFAAgF;QAChF,6BAA6B;QAC7BH,WAAW;YACTvE,OAAO2E,eAAe,CAAC7F,2BAA2B;gBAChD4E,MAAMS,oBAAoBT,IAAI;YAChC;QACF,GAAG;QAEHzD,MAAM2E,eAAe;QACrB3E,MAAM4E,cAAc;IACtB,GACA;QAAC7E;QAAQ4C;KAAe;IAG1B,qBAAOlE,2BACL,oBAACL,MAAMyG,QAAQ,sBACb,oBAACC;QACCC,WAAU;QACVC,SAAS,CAAChF;YACRiE,eAAejE;QACjB;QACAiF,KAAKvC;QACLwC,MAAK;qBAEL,oBAACC;QAAIJ,WAAWxC,aAAa,SAAS;UAG1CzC;AAEJ;AAEA,OAAO,SAASsF,qBAAqB,EACnCtF,aAAa4D,SAAS2B,IAAI,EAG3B;IACC,MAAM,CAACtF,OAAO,GAAG/B;IACjB,OAAOsE,kBAAkBvC,QAAQD,YAAYC,OAAOuF,SAAS;AAC/D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/lexical/plugins/handles/DraggableBlockPlugin/index.tsx"],"names":[],"mappings":";AAqBA,OAAO,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/field/lexical/plugins/handles/DraggableBlockPlugin/index.tsx"],"names":[],"mappings":";AAqBA,OAAO,cAAc,CAAA;AAoXrB,wBAAgB,oBAAoB,CAAC,EACnC,UAA0B,GAC3B,EAAE;IACD,UAAU,CAAC,EAAE,WAAW,CAAA;CACzB,GAAG,GAAG,CAAC,OAAO,CAGd"}
|
|
@@ -106,7 +106,9 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
106
106
|
if (!_draggableBlockElem && !isFoundNodeEmptyParagraph) {
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
|
-
|
|
109
|
+
if (draggableBlockElem !== _draggableBlockElem) {
|
|
110
|
+
setDraggableBlockElem(_draggableBlockElem);
|
|
111
|
+
}
|
|
110
112
|
}
|
|
111
113
|
// Since the draggableBlockElem is outside the actual editor, we need to listen to the document
|
|
112
114
|
// to be able to detect when the mouse is outside the editor and respect a buffer around the
|
|
@@ -119,7 +121,8 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
119
121
|
scrollerElem,
|
|
120
122
|
anchorElem,
|
|
121
123
|
editor,
|
|
122
|
-
calculateDistanceFromScrollerElem
|
|
124
|
+
calculateDistanceFromScrollerElem,
|
|
125
|
+
draggableBlockElem
|
|
123
126
|
]);
|
|
124
127
|
useEffect(()=>{
|
|
125
128
|
if (menuRef.current) {
|
|
@@ -230,7 +233,9 @@ function useDraggableBlockMenu(editor, anchorElem, isEditable) {
|
|
|
230
233
|
targetNode.insertAfter(draggedNode)
|
|
231
234
|
} else {
|
|
232
235
|
targetNode.insertBefore(draggedNode)
|
|
233
|
-
}*/
|
|
236
|
+
}*/ if (draggableBlockElem !== null) {
|
|
237
|
+
setDraggableBlockElem(null);
|
|
238
|
+
}
|
|
234
239
|
});
|
|
235
240
|
return true;
|
|
236
241
|
}
|