@payloadcms/richtext-lexical 3.0.0-alpha.48 → 3.0.0-alpha.49

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.
Files changed (89) hide show
  1. package/dist/cell/index.d.ts.map +1 -1
  2. package/dist/cell/index.js +6 -5
  3. package/dist/cell/index.js.map +1 -1
  4. package/dist/field/Field.d.ts +2 -1
  5. package/dist/field/Field.d.ts.map +1 -1
  6. package/dist/field/Field.js +7 -4
  7. package/dist/field/Field.js.map +1 -1
  8. package/dist/field/features/blocks/component/BlockContent.d.ts +2 -2
  9. package/dist/field/features/blocks/component/BlockContent.d.ts.map +1 -1
  10. package/dist/field/features/blocks/component/BlockContent.js +34 -16
  11. package/dist/field/features/blocks/component/BlockContent.js.map +1 -1
  12. package/dist/field/features/blocks/component/FormSavePlugin.d.ts.map +1 -1
  13. package/dist/field/features/blocks/component/FormSavePlugin.js +2 -1
  14. package/dist/field/features/blocks/component/FormSavePlugin.js.map +1 -1
  15. package/dist/field/features/blocks/component/index.d.ts.map +1 -1
  16. package/dist/field/features/blocks/component/index.js +10 -8
  17. package/dist/field/features/blocks/component/index.js.map +1 -1
  18. package/dist/field/features/blocks/drawer/index.d.ts.map +1 -1
  19. package/dist/field/features/blocks/drawer/index.js +4 -1
  20. package/dist/field/features/blocks/drawer/index.js.map +1 -1
  21. package/dist/field/features/blocks/feature.client.d.ts +1 -1
  22. package/dist/field/features/blocks/feature.client.d.ts.map +1 -1
  23. package/dist/field/features/blocks/feature.client.js.map +1 -1
  24. package/dist/field/features/blocks/feature.server.d.ts.map +1 -1
  25. package/dist/field/features/blocks/feature.server.js +4 -11
  26. package/dist/field/features/blocks/feature.server.js.map +1 -1
  27. package/dist/field/features/createClientComponent.d.ts +1 -2
  28. package/dist/field/features/createClientComponent.d.ts.map +1 -1
  29. package/dist/field/features/createFeaturePropComponent.d.ts.map +1 -1
  30. package/dist/field/features/createFeaturePropComponent.js +3 -2
  31. package/dist/field/features/createFeaturePropComponent.js.map +1 -1
  32. package/dist/field/features/link/drawer/index.d.ts.map +1 -1
  33. package/dist/field/features/link/drawer/index.js +16 -10
  34. package/dist/field/features/link/drawer/index.js.map +1 -1
  35. package/dist/field/features/link/plugins/autoLink/index.js +1 -1
  36. package/dist/field/features/link/plugins/autoLink/index.js.map +1 -1
  37. package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.d.ts.map +1 -1
  38. package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.js +4 -1
  39. package/dist/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.js.map +1 -1
  40. package/dist/field/features/relationship/drawer/index.js +1 -1
  41. package/dist/field/features/relationship/drawer/index.js.map +1 -1
  42. package/dist/field/features/relationship/feature.client.js +1 -1
  43. package/dist/field/features/relationship/feature.client.js.map +1 -1
  44. package/dist/field/features/relationship/nodes/components/RelationshipComponent.d.ts.map +1 -1
  45. package/dist/field/features/relationship/nodes/components/RelationshipComponent.js +5 -1
  46. package/dist/field/features/relationship/nodes/components/RelationshipComponent.js.map +1 -1
  47. package/dist/field/features/relationship/plugins/index.d.ts.map +1 -1
  48. package/dist/field/features/relationship/plugins/index.js +2 -2
  49. package/dist/field/features/relationship/plugins/index.js.map +1 -1
  50. package/dist/field/features/relationship/utils/EnabledRelationshipsCondition.d.ts.map +1 -1
  51. package/dist/field/features/relationship/utils/EnabledRelationshipsCondition.js +2 -1
  52. package/dist/field/features/relationship/utils/EnabledRelationshipsCondition.js.map +1 -1
  53. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.d.ts +2 -2
  54. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.d.ts.map +1 -1
  55. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.js +17 -9
  56. package/dist/field/features/upload/component/ExtraFieldsDrawer/index.js.map +1 -1
  57. package/dist/field/features/upload/component/index.d.ts.map +1 -1
  58. package/dist/field/features/upload/component/index.js +10 -2
  59. package/dist/field/features/upload/component/index.js.map +1 -1
  60. package/dist/field/features/upload/drawer/index.js +1 -1
  61. package/dist/field/features/upload/drawer/index.js.map +1 -1
  62. package/dist/field/features/upload/plugin/index.d.ts.map +1 -1
  63. package/dist/field/features/upload/plugin/index.js +1 -1
  64. package/dist/field/features/upload/plugin/index.js.map +1 -1
  65. package/dist/field/index.d.ts +1 -1
  66. package/dist/field/index.d.ts.map +1 -1
  67. package/dist/field/index.js +5 -5
  68. package/dist/field/index.js.map +1 -1
  69. package/dist/field/lexical/LexicalProvider.d.ts +1 -1
  70. package/dist/field/lexical/LexicalProvider.d.ts.map +1 -1
  71. package/dist/field/lexical/LexicalProvider.js.map +1 -1
  72. package/dist/field/lexical/config/client/EditorConfigProvider.d.ts +1 -1
  73. package/dist/field/lexical/config/client/EditorConfigProvider.d.ts.map +1 -1
  74. package/dist/field/lexical/config/client/EditorConfigProvider.js.map +1 -1
  75. package/dist/field/lexical/plugins/SlashMenu/index.js +1 -1
  76. package/dist/field/lexical/plugins/SlashMenu/index.js.map +1 -1
  77. package/dist/generateComponentMap.d.ts.map +1 -1
  78. package/dist/generateComponentMap.js +5 -3
  79. package/dist/generateComponentMap.js.map +1 -1
  80. package/dist/generateSchemaMap.d.ts.map +1 -1
  81. package/dist/generateSchemaMap.js +2 -1
  82. package/dist/generateSchemaMap.js.map +1 -1
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +15 -19
  85. package/dist/index.js.map +1 -1
  86. package/dist/useLexicalFeature.d.ts.map +1 -1
  87. package/dist/useLexicalFeature.js +3 -3
  88. package/dist/useLexicalFeature.js.map +1 -1
  89. package/package.json +10 -8
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/field/features/blocks/feature.client.tsx"],"sourcesContent":["'use client'\n\nimport type { ReducedBlock } from '@payloadcms/ui/types'\n\nimport { getTranslation } from '@payloadcms/translations'\n\nimport type { FeatureProviderProviderClient } from '../types.js'\n\nimport { SlashMenuOption } from '../../lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js'\nimport { BlockIcon } from '../../lexical/ui/icons/Block/index.js'\nimport { createClientComponent } from '../createClientComponent.js'\nimport { BlockNode } from './nodes/BlocksNode.js'\nimport { INSERT_BLOCK_COMMAND } from './plugin/commands.js'\nimport { BlocksPlugin } from './plugin/index.js'\n\nexport type BlocksFeatureClientProps = {\n reducedBlocks: ReducedBlock[]\n}\n\nconst BlocksFeatureClient: FeatureProviderProviderClient<BlocksFeatureClientProps> = (props) => {\n return {\n clientFeatureProps: props,\n feature: () => ({\n clientFeatureProps: props,\n nodes: [BlockNode],\n plugins: [\n {\n Component: BlocksPlugin,\n position: 'normal',\n },\n ],\n slashMenu: {\n options: [\n {\n displayName: 'Blocks',\n key: 'blocks',\n options: [\n ...props.reducedBlocks.map((block) => {\n return new SlashMenuOption('block-' + block.slug, {\n Icon: BlockIcon,\n displayName: ({ i18n }) => {\n if (!block.labels.singular) {\n return block.slug\n }\n\n return getTranslation(block.labels.singular, i18n)\n },\n keywords: ['block', 'blocks', block.slug],\n onSelect: ({ editor }) => {\n editor.dispatchCommand(INSERT_BLOCK_COMMAND, {\n id: null,\n blockName: '',\n blockType: block.slug,\n })\n },\n })\n }),\n ],\n },\n ],\n },\n }),\n }\n}\n\nexport const BlocksFeatureClientComponent = createClientComponent(BlocksFeatureClient)\n"],"names":["getTranslation","SlashMenuOption","BlockIcon","createClientComponent","BlockNode","INSERT_BLOCK_COMMAND","BlocksPlugin","BlocksFeatureClient","props","clientFeatureProps","feature","nodes","plugins","Component","position","slashMenu","options","displayName","key","reducedBlocks","map","block","slug","Icon","i18n","labels","singular","keywords","onSelect","editor","dispatchCommand","id","blockName","blockType","BlocksFeatureClientComponent"],"mappings":"AAAA;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AAIzD,SAASC,eAAe,QAAQ,sEAAqE;AACrG,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,qBAAqB,QAAQ,8BAA6B;AACnE,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,oBAAoB,QAAQ,uBAAsB;AAC3D,SAASC,YAAY,QAAQ,oBAAmB;AAMhD,MAAMC,sBAA+E,CAACC;IACpF,OAAO;QACLC,oBAAoBD;QACpBE,SAAS,IAAO,CAAA;gBACdD,oBAAoBD;gBACpBG,OAAO;oBAACP;iBAAU;gBAClBQ,SAAS;oBACP;wBACEC,WAAWP;wBACXQ,UAAU;oBACZ;iBACD;gBACDC,WAAW;oBACTC,SAAS;wBACP;4BACEC,aAAa;4BACbC,KAAK;4BACLF,SAAS;mCACJR,MAAMW,aAAa,CAACC,GAAG,CAAC,CAACC;oCAC1B,OAAO,IAAIpB,gBAAgB,WAAWoB,MAAMC,IAAI,EAAE;wCAChDC,MAAMrB;wCACNe,aAAa,CAAC,EAAEO,IAAI,EAAE;4CACpB,IAAI,CAACH,MAAMI,MAAM,CAACC,QAAQ,EAAE;gDAC1B,OAAOL,MAAMC,IAAI;4CACnB;4CAEA,OAAOtB,eAAeqB,MAAMI,MAAM,CAACC,QAAQ,EAAEF;wCAC/C;wCACAG,UAAU;4CAAC;4CAAS;4CAAUN,MAAMC,IAAI;yCAAC;wCACzCM,UAAU,CAAC,EAAEC,MAAM,EAAE;4CACnBA,OAAOC,eAAe,CAACzB,sBAAsB;gDAC3C0B,IAAI;gDACJC,WAAW;gDACXC,WAAWZ,MAAMC,IAAI;4CACvB;wCACF;oCACF;gCACF;6BACD;wBACH;qBACD;gBACH;YACF,CAAA;IACF;AACF;AAEA,OAAO,MAAMY,+BAA+B/B,sBAAsBI,qBAAoB"}
1
+ {"version":3,"sources":["../../../../src/field/features/blocks/feature.client.tsx"],"sourcesContent":["'use client'\n\nimport type { ReducedBlock } from '@payloadcms/ui/utilities/buildComponentMap'\n\nimport { getTranslation } from '@payloadcms/translations'\n\nimport type { FeatureProviderProviderClient } from '../types.js'\n\nimport { SlashMenuOption } from '../../lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js'\nimport { BlockIcon } from '../../lexical/ui/icons/Block/index.js'\nimport { createClientComponent } from '../createClientComponent.js'\nimport { BlockNode } from './nodes/BlocksNode.js'\nimport { INSERT_BLOCK_COMMAND } from './plugin/commands.js'\nimport { BlocksPlugin } from './plugin/index.js'\n\nexport type BlocksFeatureClientProps = {\n reducedBlocks: ReducedBlock[]\n}\n\nconst BlocksFeatureClient: FeatureProviderProviderClient<BlocksFeatureClientProps> = (props) => {\n return {\n clientFeatureProps: props,\n feature: () => ({\n clientFeatureProps: props,\n nodes: [BlockNode],\n plugins: [\n {\n Component: BlocksPlugin,\n position: 'normal',\n },\n ],\n slashMenu: {\n options: [\n {\n displayName: 'Blocks',\n key: 'blocks',\n options: [\n ...props.reducedBlocks.map((block) => {\n return new SlashMenuOption('block-' + block.slug, {\n Icon: BlockIcon,\n displayName: ({ i18n }) => {\n if (!block.labels.singular) {\n return block.slug\n }\n\n return getTranslation(block.labels.singular, i18n)\n },\n keywords: ['block', 'blocks', block.slug],\n onSelect: ({ editor }) => {\n editor.dispatchCommand(INSERT_BLOCK_COMMAND, {\n id: null,\n blockName: '',\n blockType: block.slug,\n })\n },\n })\n }),\n ],\n },\n ],\n },\n }),\n }\n}\n\nexport const BlocksFeatureClientComponent = createClientComponent(BlocksFeatureClient)\n"],"names":["getTranslation","SlashMenuOption","BlockIcon","createClientComponent","BlockNode","INSERT_BLOCK_COMMAND","BlocksPlugin","BlocksFeatureClient","props","clientFeatureProps","feature","nodes","plugins","Component","position","slashMenu","options","displayName","key","reducedBlocks","map","block","slug","Icon","i18n","labels","singular","keywords","onSelect","editor","dispatchCommand","id","blockName","blockType","BlocksFeatureClientComponent"],"mappings":"AAAA;AAIA,SAASA,cAAc,QAAQ,2BAA0B;AAIzD,SAASC,eAAe,QAAQ,sEAAqE;AACrG,SAASC,SAAS,QAAQ,wCAAuC;AACjE,SAASC,qBAAqB,QAAQ,8BAA6B;AACnE,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,oBAAoB,QAAQ,uBAAsB;AAC3D,SAASC,YAAY,QAAQ,oBAAmB;AAMhD,MAAMC,sBAA+E,CAACC;IACpF,OAAO;QACLC,oBAAoBD;QACpBE,SAAS,IAAO,CAAA;gBACdD,oBAAoBD;gBACpBG,OAAO;oBAACP;iBAAU;gBAClBQ,SAAS;oBACP;wBACEC,WAAWP;wBACXQ,UAAU;oBACZ;iBACD;gBACDC,WAAW;oBACTC,SAAS;wBACP;4BACEC,aAAa;4BACbC,KAAK;4BACLF,SAAS;mCACJR,MAAMW,aAAa,CAACC,GAAG,CAAC,CAACC;oCAC1B,OAAO,IAAIpB,gBAAgB,WAAWoB,MAAMC,IAAI,EAAE;wCAChDC,MAAMrB;wCACNe,aAAa,CAAC,EAAEO,IAAI,EAAE;4CACpB,IAAI,CAACH,MAAMI,MAAM,CAACC,QAAQ,EAAE;gDAC1B,OAAOL,MAAMC,IAAI;4CACnB;4CAEA,OAAOtB,eAAeqB,MAAMI,MAAM,CAACC,QAAQ,EAAEF;wCAC/C;wCACAG,UAAU;4CAAC;4CAAS;4CAAUN,MAAMC,IAAI;yCAAC;wCACzCM,UAAU,CAAC,EAAEC,MAAM,EAAE;4CACnBA,OAAOC,eAAe,CAACzB,sBAAsB;gDAC3C0B,IAAI;gDACJC,WAAW;gDACXC,WAAWZ,MAAMC,IAAI;4CACvB;wCACF;oCACF;gCACF;6BACD;wBACH;qBACD;gBACH;YACF,CAAA;IACF;AACF;AAEA,OAAO,MAAMY,+BAA+B/B,sBAAsBI,qBAAoB"}
@@ -1 +1 @@
1
- {"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blocks/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAqB,MAAM,eAAe,CAAA;AAK7D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAQnE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,KAAK,EAAE,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,6BAA6B,CACvD,kBAAkB,EAClB,wBAAwB,CAmHzB,CAAA"}
1
+ {"version":3,"file":"feature.server.d.ts","sourceRoot":"","sources":["../../../../src/field/features/blocks/feature.server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAqB,MAAM,eAAe,CAAA;AAK7D,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAQnE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,KAAK,EAAE,CAAA;CAChB,CAAA;AAED,eAAO,MAAM,aAAa,EAAE,6BAA6B,CACvD,kBAAkB,EAClB,wBAAwB,CAyGzB,CAAA"}
@@ -26,10 +26,10 @@ export const BlocksFeature = (props)=>{
26
26
  for (const block of props.blocks){
27
27
  clientProps.reducedBlocks.push({
28
28
  slug: block.slug,
29
+ fieldMap: [],
29
30
  imageAltText: block.imageAltText,
30
31
  imageURL: block.imageURL,
31
- labels: block.labels,
32
- subfields: []
32
+ labels: block.labels
33
33
  });
34
34
  }
35
35
  return {
@@ -37,17 +37,10 @@ export const BlocksFeature = (props)=>{
37
37
  return {
38
38
  ClientComponent: BlocksFeatureClientComponent,
39
39
  clientFeatureProps: clientProps,
40
- generateSchemaMap: ({ config, props })=>{
41
- const validRelationships = config.collections.map((c)=>c.slug) || [];
40
+ generateSchemaMap: ({ props })=>{
42
41
  const schemaMap = {};
43
42
  for (const block of props.blocks){
44
- const unSanitizedFormSchema = block.fields || [];
45
- const formSchema = sanitizeFields({
46
- config,
47
- fields: unSanitizedFormSchema,
48
- validRelationships
49
- });
50
- schemaMap[block.slug] = formSchema;
43
+ schemaMap[block.slug] = block.fields || [];
51
44
  }
52
45
  return schemaMap;
53
46
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/field/features/blocks/feature.server.ts"],"sourcesContent":["import type { Block, BlockField, Field } from 'payload/types'\n\nimport { baseBlockFields, sanitizeFields } from 'payload/config'\nimport { fieldsToJSONSchema, formatLabels } from 'payload/utilities'\n\nimport type { FeatureProviderProviderServer } from '../types.js'\nimport type { BlocksFeatureClientProps } from './feature.client.js'\n\nimport { cloneDeep } from '../../lexical/utils/cloneDeep.js'\nimport { BlocksFeatureClientComponent } from './feature.client.js'\nimport { BlockNode } from './nodes/BlocksNode.js'\nimport { blockPopulationPromiseHOC } from './populationPromise.js'\nimport { blockValidationHOC } from './validate.js'\n\nexport type BlocksFeatureProps = {\n blocks: Block[]\n}\n\nexport const BlocksFeature: FeatureProviderProviderServer<\n BlocksFeatureProps,\n BlocksFeatureClientProps\n> = (props) => {\n // Sanitization taken from payload/src/fields/config/sanitize.ts\n\n if (props?.blocks?.length) {\n props.blocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n\n return {\n ...blockCopy,\n fields: blockCopy.fields.concat(baseBlockFields),\n labels: !blockCopy.labels ? formatLabels(blockCopy.slug) : blockCopy.labels,\n }\n })\n // unSanitizedBlock.fields are sanitized in the React component and not here.\n // That's because we do not have access to the payload config here.\n }\n\n // Build clientProps\n const clientProps: BlocksFeatureClientProps = {\n reducedBlocks: [],\n }\n for (const block of props.blocks) {\n clientProps.reducedBlocks.push({\n slug: block.slug,\n imageAltText: block.imageAltText,\n imageURL: block.imageURL,\n labels: block.labels,\n subfields: [],\n })\n }\n\n return {\n feature: () => {\n return {\n ClientComponent: BlocksFeatureClientComponent,\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ config, props }) => {\n const validRelationships = config.collections.map((c) => c.slug) || []\n\n const schemaMap: {\n [key: string]: Field[]\n } = {}\n\n for (const block of props.blocks) {\n const unSanitizedFormSchema = block.fields || []\n\n const formSchema = sanitizeFields({\n config,\n fields: unSanitizedFormSchema,\n validRelationships,\n })\n\n schemaMap[block.slug] = formSchema\n }\n\n return schemaMap\n },\n generatedTypes: {\n modifyOutputSchema: ({\n collectionIDFieldTypes,\n config,\n currentSchema,\n field,\n interfaceNameDefinitions,\n }) => {\n if (!props?.blocks?.length) {\n return currentSchema\n }\n\n // sanitize blocks\n const validRelationships = config.collections.map((c) => c.slug) || []\n\n const sanitizedBlocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n return {\n ...blockCopy,\n fields: sanitizeFields({\n config,\n fields: blockCopy.fields,\n validRelationships,\n }),\n }\n })\n\n const blocksField: BlockField = {\n name: field?.name + '_lexical_blocks',\n type: 'blocks',\n blocks: sanitizedBlocks,\n }\n // This is only done so that interfaceNameDefinitions sets those block's interfaceNames.\n // we don't actually use the JSON Schema itself in the generated types yet.\n fieldsToJSONSchema(\n collectionIDFieldTypes,\n [blocksField],\n interfaceNameDefinitions,\n config,\n )\n\n return currentSchema\n },\n },\n nodes: [\n {\n node: BlockNode,\n populationPromises: [blockPopulationPromiseHOC(props)],\n validations: [blockValidationHOC(props)],\n },\n ],\n serverFeatureProps: props,\n }\n },\n key: 'blocks',\n serverFeatureProps: props,\n }\n}\n"],"names":["baseBlockFields","sanitizeFields","fieldsToJSONSchema","formatLabels","cloneDeep","BlocksFeatureClientComponent","BlockNode","blockPopulationPromiseHOC","blockValidationHOC","BlocksFeature","props","blocks","length","map","block","blockCopy","fields","concat","labels","slug","clientProps","reducedBlocks","push","imageAltText","imageURL","subfields","feature","ClientComponent","clientFeatureProps","generateSchemaMap","config","validRelationships","collections","c","schemaMap","unSanitizedFormSchema","formSchema","generatedTypes","modifyOutputSchema","collectionIDFieldTypes","currentSchema","field","interfaceNameDefinitions","sanitizedBlocks","blocksField","name","type","nodes","node","populationPromises","validations","serverFeatureProps","key"],"mappings":"AAEA,SAASA,eAAe,EAAEC,cAAc,QAAQ,iBAAgB;AAChE,SAASC,kBAAkB,EAAEC,YAAY,QAAQ,oBAAmB;AAKpE,SAASC,SAAS,QAAQ,mCAAkC;AAC5D,SAASC,4BAA4B,QAAQ,sBAAqB;AAClE,SAASC,SAAS,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oBAC1B;oBAEA,OAAOF;gBACT;gBACAG,gBAAgB;oBACdC,oBAAoB,CAAC,EACnBC,sBAAsB,EACtBT,MAAM,EACNU,aAAa,EACbC,KAAK,EACLC,wBAAwB,EACzB;wBACC,IAAI,CAAChC,OAAOC,QAAQC,QAAQ;4BAC1B,OAAO4B;wBACT;wBAEA,kBAAkB;wBAClB,MAAMT,qBAAqBD,OAAOE,WAAW,CAACnB,GAAG,CAAC,CAACoB,IAAMA,EAAEd,IAAI,KAAK,EAAE;wBAEtE,MAAMwB,kBAAkBjC,MAAMC,MAAM,CAACE,GAAG,CAAC,CAACC;4BACxC,MAAMC,YAAYX,UAAUU;4BAC5B,OAAO;gCACL,GAAGC,SAAS;gCACZC,QAAQf,eAAe;oCACrB6B;oCACAd,QAAQD,UAAUC,MAAM;oCACxBe;gCACF;4BACF;wBACF;wBAEA,MAAMa,cAA0B;4BAC9BC,MAAMJ,OAAOI,OAAO;4BACpBC,MAAM;4BACNnC,QAAQgC;wBACV;wBACA,wFAAwF;wBACxF,2EAA2E;wBAC3EzC,mBACEqC,wBACA;4BAACK;yBAAY,EACbF,0BACAZ;wBAGF,OAAOU;oBACT;gBACF;gBACAO,OAAO;oBACL;wBACEC,MAAM1C;wBACN2C,oBAAoB;4BAAC1C,0BAA0BG;yBAAO;wBACtDwC,aAAa;4BAAC1C,mBAAmBE;yBAAO;oBAC1C;iBACD;gBACDyC,oBAAoBzC;YACtB;QACF;QACA0C,KAAK;QACLD,oBAAoBzC;IACtB;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../../src/field/features/blocks/feature.server.ts"],"sourcesContent":["import type { Block, BlockField, Field } from 'payload/types'\n\nimport { baseBlockFields, sanitizeFields } from 'payload/config'\nimport { fieldsToJSONSchema, formatLabels } from 'payload/utilities'\n\nimport type { FeatureProviderProviderServer } from '../types.js'\nimport type { BlocksFeatureClientProps } from './feature.client.js'\n\nimport { cloneDeep } from '../../lexical/utils/cloneDeep.js'\nimport { BlocksFeatureClientComponent } from './feature.client.js'\nimport { BlockNode } from './nodes/BlocksNode.js'\nimport { blockPopulationPromiseHOC } from './populationPromise.js'\nimport { blockValidationHOC } from './validate.js'\n\nexport type BlocksFeatureProps = {\n blocks: Block[]\n}\n\nexport const BlocksFeature: FeatureProviderProviderServer<\n BlocksFeatureProps,\n BlocksFeatureClientProps\n> = (props) => {\n // Sanitization taken from payload/src/fields/config/sanitize.ts\n\n if (props?.blocks?.length) {\n props.blocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n\n return {\n ...blockCopy,\n fields: blockCopy.fields.concat(baseBlockFields),\n labels: !blockCopy.labels ? formatLabels(blockCopy.slug) : blockCopy.labels,\n }\n })\n // unSanitizedBlock.fields are sanitized in the React component and not here.\n // That's because we do not have access to the payload config here.\n }\n\n // Build clientProps\n const clientProps: BlocksFeatureClientProps = {\n reducedBlocks: [],\n }\n for (const block of props.blocks) {\n clientProps.reducedBlocks.push({\n slug: block.slug,\n fieldMap: [],\n imageAltText: block.imageAltText,\n imageURL: block.imageURL,\n labels: block.labels,\n })\n }\n\n return {\n feature: () => {\n return {\n ClientComponent: BlocksFeatureClientComponent,\n clientFeatureProps: clientProps,\n generateSchemaMap: ({ props }) => {\n const schemaMap: {\n [key: string]: Field[]\n } = {}\n\n for (const block of props.blocks) {\n schemaMap[block.slug] = block.fields || []\n }\n\n return schemaMap\n },\n generatedTypes: {\n modifyOutputSchema: ({\n collectionIDFieldTypes,\n config,\n currentSchema,\n field,\n interfaceNameDefinitions,\n }) => {\n if (!props?.blocks?.length) {\n return currentSchema\n }\n\n // sanitize blocks\n const validRelationships = config.collections.map((c) => c.slug) || []\n\n const sanitizedBlocks = props.blocks.map((block) => {\n const blockCopy = cloneDeep(block)\n return {\n ...blockCopy,\n fields: sanitizeFields({\n config,\n fields: blockCopy.fields,\n validRelationships,\n }),\n }\n })\n\n const blocksField: BlockField = {\n name: field?.name + '_lexical_blocks',\n type: 'blocks',\n blocks: sanitizedBlocks,\n }\n // This is only done so that interfaceNameDefinitions sets those block's interfaceNames.\n // we don't actually use the JSON Schema itself in the generated types yet.\n fieldsToJSONSchema(\n collectionIDFieldTypes,\n [blocksField],\n interfaceNameDefinitions,\n config,\n )\n\n return currentSchema\n },\n },\n nodes: [\n {\n node: BlockNode,\n populationPromises: [blockPopulationPromiseHOC(props)],\n validations: [blockValidationHOC(props)],\n },\n ],\n serverFeatureProps: props,\n }\n },\n key: 'blocks',\n serverFeatureProps: props,\n }\n}\n"],"names":["baseBlockFields","sanitizeFields","fieldsToJSONSchema","formatLabels","cloneDeep","BlocksFeatureClientComponent","BlockNode","blockPopulationPromiseHOC","blockValidationHOC","BlocksFeature","props","blocks","length","map","block","blockCopy","fields","concat","labels","slug","clientProps","reducedBlocks","push","fieldMap","imageAltText","imageURL","feature","ClientComponent","clientFeatureProps","generateSchemaMap","schemaMap","generatedTypes","modifyOutputSchema","collectionIDFieldTypes","config","currentSchema","field","interfaceNameDefinitions","validRelationships","collections","c","sanitizedBlocks","blocksField","name","type","nodes","node","populationPromises","validations","serverFeatureProps","key"],"mappings":"AAEA,SAASA,eAAe,EAAEC,cAAc,QAAQ,iBAAgB;AAChE,SAASC,kBAAkB,EAAEC,YAAY,QAAQ,oBAAmB;AAKpE,SAASC,SAAS,QAAQ,mCAAkC;AAC5D,SAASC,4BAA4B,QAAQ,sBAAqB;AAClE,SAASC,SAAS,QAAQ,wBAAuB;AACjD,SAASC,yBAAyB,QAAQ,yBAAwB;AAClE,SAASC,kBAAkB,QAAQ,gBAAe;AAMlD,OAAO,MAAMC,gBAGT,CAACC;IACH,gEAAgE;IAEhE,IAAIA,OAAOC,QAAQC,QAAQ;QACzBF,MAAMC,MAAM,GAAGD,MAAMC,MAAM,CAACE,GAAG,CAAC,CAACC;YAC/B,MAAMC,YAAYX,UAAUU;YAE5B,OAAO;gBACL,GAAGC,SAAS;gBACZC,QAAQD,UAAUC,MAAM,CAACC,MAAM,CAACjB;gBAChCkB,QAAQ,CAACH,UAAUG,MAAM,GAAG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ACpBC,MAAM;4BACNjC,QAAQ8B;wBACV;wBACA,wFAAwF;wBACxF,2EAA2E;wBAC3EvC,mBACE+B,wBACA;4BAACS;yBAAY,EACbL,0BACAH;wBAGF,OAAOC;oBACT;gBACF;gBACAU,OAAO;oBACL;wBACEC,MAAMxC;wBACNyC,oBAAoB;4BAACxC,0BAA0BG;yBAAO;wBACtDsC,aAAa;4BAACxC,mBAAmBE;yBAAO;oBAC1C;iBACD;gBACDuC,oBAAoBvC;YACtB;QACF;QACAwC,KAAK;QACLD,oBAAoBvC;IACtB;AACF,EAAC"}
@@ -1,7 +1,6 @@
1
- /// <reference types="react" resolution-mode="require"/>
2
1
  import type { FeatureProviderProviderClient, ServerFeature } from './types.js';
3
2
  /**
4
3
  * Utility function to create a client component for the client feature
5
4
  */
6
- export declare const createClientComponent: <ClientFeatureProps>(clientFeature: FeatureProviderProviderClient<ClientFeatureProps>) => import("react").FC<import("./types.js").ClientComponentProps<ClientFeatureProps>>;
5
+ export declare const createClientComponent: <ClientFeatureProps>(clientFeature: FeatureProviderProviderClient<ClientFeatureProps>) => ServerFeature<unknown, ClientFeatureProps>['ClientComponent'];
7
6
  //# sourceMappingURL=createClientComponent.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"createClientComponent.d.ts","sourceRoot":"","sources":["../../../src/field/features/createClientComponent.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAI9E;;GAEG;AACH,eAAO,MAAM,qBAAqB,6KAOjC,CAAA"}
1
+ {"version":3,"file":"createClientComponent.d.ts","sourceRoot":"","sources":["../../../src/field/features/createClientComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,6BAA6B,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAI9E;;GAEG;AACH,eAAO,MAAM,qBAAqB,sCACjB,8BAA8B,kBAAkB,CAAC,KAC/D,cAAc,OAAO,EAAE,kBAAkB,CAAC,CAAC,iBAAiB,CAK9D,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"createFeaturePropComponent.d.ts","sourceRoot":"","sources":["../../../src/field/features/createFeaturePropComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAa9B,eAAO,MAAM,0BAA0B,4BAEpC,MAAM,EAAE,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAKvD,CAAA"}
1
+ {"version":3,"file":"createFeaturePropComponent.d.ts","sourceRoot":"","sources":["../../../src/field/features/createFeaturePropComponent.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAc9B,eAAO,MAAM,0BAA0B,sBAC/B,CAAC,KACN,MAAM,EAAE,CAAC;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAKvD,CAAA"}
@@ -1,7 +1,8 @@
1
1
  'use client';
2
- import { useAddClientFunction, useFieldPath } from '@payloadcms/ui';
2
+ import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
3
+ import { useAddClientFunction } from '@payloadcms/ui/providers/ClientFunction';
3
4
  const useLexicalFeatureProp = (featureKey, componentKey, prop)=>{
4
- const { schemaPath } = useFieldPath();
5
+ const { schemaPath } = useFieldProps();
5
6
  useAddClientFunction(`lexicalFeature.${schemaPath}.${featureKey}.components.${componentKey}`, prop);
6
7
  };
7
8
  export const createFeaturePropComponent = (prop)=>{
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/field/features/createFeaturePropComponent.tsx"],"sourcesContent":["'use client'\n\nimport type React from 'react'\n\nimport { useAddClientFunction, useFieldPath } from '@payloadcms/ui'\n\nconst useLexicalFeatureProp = <T,>(featureKey: string, componentKey: string, prop: T) => {\n const { schemaPath } = useFieldPath()\n\n useAddClientFunction(\n `lexicalFeature.${schemaPath}.${featureKey}.components.${componentKey}`,\n prop,\n )\n}\n\nexport const createFeaturePropComponent = <T = unknown,>(\n prop: T,\n): React.FC<{ componentKey: string; featureKey: string }> => {\n return (props) => {\n useLexicalFeatureProp(props.featureKey, props.componentKey, prop)\n return null\n }\n}\n"],"names":["useAddClientFunction","useFieldPath","useLexicalFeatureProp","featureKey","componentKey","prop","schemaPath","createFeaturePropComponent","props"],"mappings":"AAAA;AAIA,SAASA,oBAAoB,EAAEC,YAAY,QAAQ,iBAAgB;AAEnE,MAAMC,wBAAwB,CAAKC,YAAoBC,cAAsBC;IAC3E,MAAM,EAAEC,UAAU,EAAE,GAAGL;IAEvBD,qBACE,CAAC,eAAe,EAAEM,WAAW,CAAC,EAAEH,WAAW,YAAY,EAAEC,aAAa,CAAC,EACvEC;AAEJ;AAEA,OAAO,MAAME,6BAA6B,CACxCF;IAEA,OAAO,CAACG;QACNN,sBAAsBM,MAAML,UAAU,EAAEK,MAAMJ,YAAY,EAAEC;QAC5D,OAAO;IACT;AACF,EAAC"}
1
+ {"version":3,"sources":["../../../src/field/features/createFeaturePropComponent.tsx"],"sourcesContent":["'use client'\n\nimport type React from 'react'\n\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { useAddClientFunction } from '@payloadcms/ui/providers/ClientFunction'\n\nconst useLexicalFeatureProp = <T,>(featureKey: string, componentKey: string, prop: T) => {\n const { schemaPath } = useFieldProps()\n\n useAddClientFunction(\n `lexicalFeature.${schemaPath}.${featureKey}.components.${componentKey}`,\n prop,\n )\n}\n\nexport const createFeaturePropComponent = <T = unknown,>(\n prop: T,\n): React.FC<{ componentKey: string; featureKey: string }> => {\n return (props) => {\n useLexicalFeatureProp(props.featureKey, props.componentKey, prop)\n return null\n }\n}\n"],"names":["useFieldProps","useAddClientFunction","useLexicalFeatureProp","featureKey","componentKey","prop","schemaPath","createFeaturePropComponent","props"],"mappings":"AAAA;AAIA,SAASA,aAAa,QAAQ,0CAAyC;AACvE,SAASC,oBAAoB,QAAQ,0CAAyC;AAE9E,MAAMC,wBAAwB,CAAKC,YAAoBC,cAAsBC;IAC3E,MAAM,EAAEC,UAAU,EAAE,GAAGN;IAEvBC,qBACE,CAAC,eAAe,EAAEK,WAAW,CAAC,EAAEH,WAAW,YAAY,EAAEC,aAAa,CAAC,EACvEC;AAEJ;AAEA,OAAO,MAAME,6BAA6B,CACxCF;IAEA,OAAO,CAACG;QACNN,sBAAsBM,MAAML,UAAU,EAAEK,MAAMJ,YAAY,EAAEC;QAC5D,OAAO;IACT;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/link/drawer/index.tsx"],"names":[],"mappings":"AAeA,OAAO,KAA2C,MAAM,OAAO,CAAA;AAI/D,OAAO,cAAc,CAAA;AACrB,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAA;AAIvC,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAyEtC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/field/features/link/drawer/index.tsx"],"names":[],"mappings":"AAYA,OAAO,KAA2C,MAAM,OAAO,CAAA;AAI/D,OAAO,cAAc,CAAA;AACrB,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,YAAY,CAAA;AAIvC,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA4EtC,CAAA"}
@@ -1,5 +1,12 @@
1
- import { Drawer, FieldPathProvider, Form, FormSubmit, RenderFields, getFormState, useConfig, useDocumentInfo, useTranslation } from '@payloadcms/ui';
2
- import { useFieldPath } from '@payloadcms/ui';
1
+ import { Drawer } from '@payloadcms/ui/elements/Drawer';
2
+ import { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider';
3
+ import { Form } from '@payloadcms/ui/forms/Form';
4
+ import { RenderFields } from '@payloadcms/ui/forms/RenderFields';
5
+ import { FormSubmit } from '@payloadcms/ui/forms/Submit';
6
+ import { useConfig } from '@payloadcms/ui/providers/Config';
7
+ import { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo';
8
+ import { useTranslation } from '@payloadcms/ui/providers/Translation';
9
+ import { getFormState } from '@payloadcms/ui/utilities/getFormState';
3
10
  import React, { useCallback, useEffect, useState } from 'react';
4
11
  import { v4 as uuid } from 'uuid';
5
12
  import { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js';
@@ -8,7 +15,7 @@ const baseClass = 'lexical-link-edit-drawer';
8
15
  export const LinkDrawer = ({ drawerSlug, handleModalSubmit, stateData })=>{
9
16
  const { t } = useTranslation();
10
17
  const { id } = useDocumentInfo();
11
- const { schemaPath } = useFieldPath();
18
+ const { schemaPath } = useFieldProps();
12
19
  const config = useConfig();
13
20
  const [initialState, setInitialState] = useState(false);
14
21
  const { field: { richTextComponentMap } } = useEditorConfigContext();
@@ -62,11 +69,7 @@ export const LinkDrawer = ({ drawerSlug, handleModalSubmit, stateData })=>{
62
69
  className: baseClass,
63
70
  slug: drawerSlug,
64
71
  title: t('fields:editLink') ?? ''
65
- }, initialState !== false && /*#__PURE__*/ React.createElement(FieldPathProvider, {
66
- path: "",
67
- schemaPath: ""
68
- }, /*#__PURE__*/ React.createElement(Form, {
69
- // @ts-expect-error // TODO: Fix this type. Is this correct?
72
+ }, initialState !== false && /*#__PURE__*/ React.createElement(Form, {
70
73
  fields: Array.isArray(fieldMap) ? fieldMap : [],
71
74
  initialState: initialState,
72
75
  onChange: [
@@ -76,8 +79,11 @@ export const LinkDrawer = ({ drawerSlug, handleModalSubmit, stateData })=>{
76
79
  uuid: uuid()
77
80
  }, /*#__PURE__*/ React.createElement(RenderFields, {
78
81
  fieldMap: Array.isArray(fieldMap) ? fieldMap : [],
79
- forceRender: true
80
- }), /*#__PURE__*/ React.createElement(FormSubmit, null, t('general:submit')))));
82
+ forceRender: true,
83
+ path: "",
84
+ readOnly: false,
85
+ schemaPath: ""
86
+ }), /*#__PURE__*/ React.createElement(FormSubmit, null, t('general:submit'))));
81
87
  };
82
88
 
83
89
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/field/features/link/drawer/index.tsx"],"sourcesContent":["import type { FormState } from 'payload/types'\n\nimport {\n Drawer,\n FieldPathProvider,\n Form,\n type FormProps,\n FormSubmit,\n RenderFields,\n getFormState,\n useConfig,\n useDocumentInfo,\n useTranslation,\n} from '@payloadcms/ui'\nimport { useFieldPath } from '@payloadcms/ui'\nimport React, { useCallback, useEffect, useState } from 'react'\nimport { v4 as uuid } from 'uuid'\n\nimport { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js'\nimport './index.scss'\nimport { type Props } from './types.js'\n\nconst baseClass = 'lexical-link-edit-drawer'\n\nexport const LinkDrawer: React.FC<Props> = ({ drawerSlug, handleModalSubmit, stateData }) => {\n const { t } = useTranslation()\n const { id } = useDocumentInfo()\n const { schemaPath } = useFieldPath()\n const config = useConfig()\n const [initialState, setInitialState] = useState<FormState | false>(false)\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n const componentMapRenderedFieldsPath = `feature.link.fields.fields`\n const schemaFieldsPath = `${schemaPath}.feature.link.fields`\n\n const fieldMap = richTextComponentMap.get(componentMapRenderedFieldsPath) // Field Schema\n\n useEffect(() => {\n const awaitInitialState = async () => {\n const state = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n data: stateData,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n }) // Form State\n\n setInitialState(state)\n }\n\n if (stateData) {\n void awaitInitialState()\n }\n }, [config.routes.api, config.serverURL, schemaFieldsPath, id, stateData])\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n return await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n formState: prevFormState,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n })\n },\n\n [config.routes.api, config.serverURL, schemaFieldsPath, id],\n )\n\n return (\n <Drawer className={baseClass} slug={drawerSlug} title={t('fields:editLink') ?? ''}>\n {initialState !== false && (\n <FieldPathProvider path=\"\" schemaPath=\"\">\n <Form\n // @ts-expect-error // TODO: Fix this type. Is this correct?\n fields={Array.isArray(fieldMap) ? fieldMap : []}\n initialState={initialState}\n onChange={[onChange]}\n onSubmit={handleModalSubmit}\n uuid={uuid()}\n >\n <RenderFields fieldMap={Array.isArray(fieldMap) ? fieldMap : []} forceRender />\n\n <FormSubmit>{t('general:submit')}</FormSubmit>\n </Form>\n </FieldPathProvider>\n )}\n </Drawer>\n )\n}\n"],"names":["Drawer","FieldPathProvider","Form","FormSubmit","RenderFields","getFormState","useConfig","useDocumentInfo","useTranslation","useFieldPath","React","useCallback","useEffect","useState","v4","uuid","useEditorConfigContext","baseClass","LinkDrawer","drawerSlug","handleModalSubmit","stateData","t","id","schemaPath","config","initialState","setInitialState","field","richTextComponentMap","componentMapRenderedFieldsPath","schemaFieldsPath","fieldMap","get","awaitInitialState","state","apiRoute","routes","api","body","data","operation","serverURL","onChange","formState","prevFormState","className","slug","title","path","fields","Array","isArray","onSubmit","forceRender"],"mappings":"AAEA,SACEA,MAAM,EACNC,iBAAiB,EACjBC,IAAI,EAEJC,UAAU,EACVC,YAAY,EACZC,YAAY,EACZC,SAAS,EACTC,eAAe,EACfC,cAAc,QACT,iBAAgB;AACvB,SAASC,YAAY,QAAQ,iBAAgB;AAC7C,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAC/D,SAASC,MAAMC,IAAI,QAAQ,OAAM;AAEjC,SAASC,sBAAsB,QAAQ,yDAAwD;AAC/F,OAAO,eAAc;AAGrB,MAAMC,YAAY;AAElB,OAAO,MAAMC,aAA8B,CAAC,EAAEC,UAAU,EAAEC,iBAAiB,EAAEC,SAAS,EAAE;IACtF,MAAM,EAAEC,CAAC,EAAE,GAAGd;IACd,MAAM,EAAEe,EAAE,EAAE,GAAGhB;IACf,MA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AQC,MAAMC,OAAO,CAACpB,YAAYA,WAAW,EAAE;QAC/CN,cAAcA;QACdiB,UAAU;YAACA;SAAS;QACpBU,UAAUjC;QACVL,MAAMA;qBAEN,oBAACX;QAAa4B,UAAUmB,MAAMC,OAAO,CAACpB,YAAYA,WAAW,EAAE;QAAEsB,aAAAA;sBAEjE,oBAACnD,kBAAYmB,EAAE;AAM3B,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/field/features/link/drawer/index.tsx"],"sourcesContent":["import type { FormProps } from '@payloadcms/ui/forms/Form'\nimport type { FormState } from 'payload/types'\n\nimport { Drawer } from '@payloadcms/ui/elements/Drawer'\nimport { useFieldProps } from '@payloadcms/ui/forms/FieldPropsProvider'\nimport { Form } from '@payloadcms/ui/forms/Form'\nimport { RenderFields } from '@payloadcms/ui/forms/RenderFields'\nimport { FormSubmit } from '@payloadcms/ui/forms/Submit'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useDocumentInfo } from '@payloadcms/ui/providers/DocumentInfo'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport { getFormState } from '@payloadcms/ui/utilities/getFormState'\nimport React, { useCallback, useEffect, useState } from 'react'\nimport { v4 as uuid } from 'uuid'\n\nimport { useEditorConfigContext } from '../../../lexical/config/client/EditorConfigProvider.js'\nimport './index.scss'\nimport { type Props } from './types.js'\n\nconst baseClass = 'lexical-link-edit-drawer'\n\nexport const LinkDrawer: React.FC<Props> = ({ drawerSlug, handleModalSubmit, stateData }) => {\n const { t } = useTranslation()\n const { id } = useDocumentInfo()\n const { schemaPath } = useFieldProps()\n const config = useConfig()\n const [initialState, setInitialState] = useState<FormState | false>(false)\n const {\n field: { richTextComponentMap },\n } = useEditorConfigContext()\n\n const componentMapRenderedFieldsPath = `feature.link.fields.fields`\n const schemaFieldsPath = `${schemaPath}.feature.link.fields`\n\n const fieldMap = richTextComponentMap.get(componentMapRenderedFieldsPath) // Field Schema\n\n useEffect(() => {\n const awaitInitialState = async () => {\n const state = await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n data: stateData,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n }) // Form State\n\n setInitialState(state)\n }\n\n if (stateData) {\n void awaitInitialState()\n }\n }, [config.routes.api, config.serverURL, schemaFieldsPath, id, stateData])\n\n const onChange: FormProps['onChange'][0] = useCallback(\n async ({ formState: prevFormState }) => {\n return await getFormState({\n apiRoute: config.routes.api,\n body: {\n id,\n formState: prevFormState,\n operation: 'update',\n schemaPath: schemaFieldsPath,\n },\n serverURL: config.serverURL,\n })\n },\n\n [config.routes.api, config.serverURL, schemaFieldsPath, id],\n )\n\n return (\n <Drawer className={baseClass} slug={drawerSlug} title={t('fields:editLink') ?? ''}>\n {initialState !== false && (\n <Form\n fields={Array.isArray(fieldMap) ? fieldMap : []}\n initialState={initialState}\n onChange={[onChange]}\n onSubmit={handleModalSubmit}\n uuid={uuid()}\n >\n <RenderFields\n fieldMap={Array.isArray(fieldMap) ? fieldMap : []}\n forceRender\n path=\"\"\n readOnly={false}\n schemaPath=\"\"\n />\n\n <FormSubmit>{t('general:submit')}</FormSubmit>\n </Form>\n )}\n </Drawer>\n )\n}\n"],"names":["Drawer","useFieldProps","Form","RenderFields","FormSubmit","useConfig","useDocumentInfo","useTranslation","getFormState","React","useCallback","useEffect","useState","v4","uuid","useEditorConfigContext","baseClass","LinkDrawer","drawerSlug","handleModalSubmit","stateData","t","id","schemaPath","config","initialState","setInitialState","field","richTextComponentMap","componentMapRenderedFieldsPath","schemaFieldsPath","fieldMap","get","awaitInitialState","state","apiRoute","routes","api","body","data","operation","serverURL","onChange","formState","prevFormState","className","slug","title","fields","Array","isArray","onSubmit","forceRender","path","readOnly"],"mappings":"AAGA,SAASA,MAAM,QAAQ,iCAAgC;AACvD,SAASC,aAAa,QAAQ,0CAAyC;AACvE,SAASC,IAAI,QAAQ,4BAA2B;AAChD,SAASC,YAAY,QAAQ,oCAAmC;AAChE,SAASC,UAAU,QAAQ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C,YACzC,OAAO,EAAEiC,WAAWC,aAAa,EAAE;QACjC,OAAO,MAAMpC,aAAa;YACxB2B,UAAUX,OAAOY,MAAM,CAACC,GAAG;YAC3BC,MAAM;gBACJhB;gBACAqB,WAAWC;gBACXJ,WAAW;gBACXjB,YAAYO;YACd;YACAW,WAAWjB,OAAOiB,SAAS;QAC7B;IACF,GAEA;QAACjB,OAAOY,MAAM,CAACC,GAAG;QAAEb,OAAOiB,SAAS;QAAEX;QAAkBR;KAAG;IAG7D,qBACE,oBAACtB;QAAO6C,WAAW7B;QAAW8B,MAAM5B;QAAY6B,OAAO1B,EAAE,sBAAsB;OAC5EI,iBAAiB,uBAChB,oBAACvB;QACC8C,QAAQC,MAAMC,OAAO,CAACnB,YAAYA,WAAW,EAAE;QAC/CN,cAAcA;QACdiB,UAAU;YAACA;SAAS;QACpBS,UAAUhC;QACVL,MAAMA;qBAEN,oBAACX;QACC4B,UAAUkB,MAAMC,OAAO,CAACnB,YAAYA,WAAW,EAAE;QACjDqB,aAAAA;QACAC,MAAK;QACLC,UAAU;QACV/B,YAAW;sBAGb,oBAACnB,kBAAYiB,EAAE;AAKzB,EAAC"}
@@ -303,7 +303,7 @@ function useAutoLink(editor, matchers, onChange) {
303
303
  ]);
304
304
  }
305
305
  const URL_REGEX = /((https?:\/\/(www\.)?)|(www\.))[-\w@:%.+~#=]{1,256}\.[a-zA-Z\d()]{1,6}\b([-\w()@:%+.~#?&/=]*)/;
306
- const EMAIL_REGEX = /(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-zA-Z\-\d]+\.)+[a-zA-Z]{2,}))/;
306
+ const EMAIL_REGEX = /(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\])|(([a-z\-\d]+\.)+[a-z]{2,}))/i;
307
307
  const MATCHERS = [
308
308
  createLinkMatcherWithRegExp(URL_REGEX, (text)=>{
309
309
  return text.startsWith('http') ? text : `https://${text}`;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/field/features/link/plugins/autoLink/index.tsx"],"sourcesContent":["'use client'\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\n\nimport lexicalUtilsImport from '@lexical/utils'\nconst { mergeRegister } = lexicalUtilsImport\n\nimport lexicalImport from 'lexical'\nconst {\n $createTextNode,\n $getSelection,\n $isElementNode,\n $isLineBreakNode,\n $isNodeSelection,\n $isRangeSelection,\n $isTextNode,\n TextNode: TextNodeValue,\n} = lexicalImport\n\nimport type { ElementNode, LexicalEditor, LexicalNode } from 'lexical'\n\nimport { type TextNode } from 'lexical'\nimport { useEffect } from 'react'\n\nimport type { LinkFields } from '../../nodes/types.js'\n\nimport { invariant } from '../../../../lexical/utils/invariant.js'\nimport { $createAutoLinkNode, $isAutoLinkNode, AutoLinkNode } from '../../nodes/AutoLinkNode.js'\nimport { $isLinkNode } from '../../nodes/LinkNode.js'\n\ntype ChangeHandler = (url: null | string, prevUrl: null | string) => void\n\ninterface LinkMatcherResult {\n fields?: LinkFields\n index: number\n length: number\n text: string\n url: string\n}\n\nexport type LinkMatcher = (text: string) => LinkMatcherResult | null\n\nexport function createLinkMatcherWithRegExp(\n regExp: RegExp,\n urlTransformer: (text: string) => string = (text) => text,\n) {\n return (text: string) => {\n const match = regExp.exec(text)\n if (match === null) return null\n return {\n index: match.index,\n length: match[0].length,\n text: match[0],\n url: urlTransformer(match[0]),\n }\n }\n}\n\nfunction findFirstMatch(text: string, matchers: LinkMatcher[]): LinkMatcherResult | null {\n for (let i = 0; i < matchers.length; i++) {\n const match = matchers[i](text)\n\n if (match != null) {\n return match\n }\n }\n\n return null\n}\n\nconst PUNCTUATION_OR_SPACE = /[.,;\\s]/\n\nfunction isSeparator(char: string): boolean {\n return PUNCTUATION_OR_SPACE.test(char)\n}\n\nfunction endsWithSeparator(textContent: string): boolean {\n return isSeparator(textContent[textContent.length - 1])\n}\n\nfunction startsWithSeparator(textContent: string): boolean {\n return isSeparator(textContent[0])\n}\n\nfunction isPreviousNodeValid(node: LexicalNode): boolean {\n let previousNode = node.getPreviousSibling()\n if ($isElementNode(previousNode)) {\n previousNode = previousNode.getLastDescendant()\n }\n return (\n previousNode === null ||\n $isLineBreakNode(previousNode) ||\n ($isTextNode(previousNode) && endsWithSeparator(previousNode.getTextContent()))\n )\n}\n\nfunction isNextNodeValid(node: LexicalNode): boolean {\n let nextNode = node.getNextSibling()\n if ($isElementNode(nextNode)) {\n nextNode = nextNode.getFirstDescendant()\n }\n return (\n nextNode === null ||\n $isLineBreakNode(nextNode) ||\n ($isTextNode(nextNode) && startsWithSeparator(nextNode.getTextContent()))\n )\n}\n\nfunction isContentAroundIsValid(\n matchStart: number,\n matchEnd: number,\n text: string,\n nodes: TextNode[],\n): boolean {\n const contentBeforeIsValid =\n matchStart > 0 ? isSeparator(text[matchStart - 1]) : isPreviousNodeValid(nodes[0])\n if (!contentBeforeIsValid) {\n return false\n }\n\n const contentAfterIsValid =\n matchEnd < text.length ? isSeparator(text[matchEnd]) : isNextNodeValid(nodes[nodes.length - 1])\n return contentAfterIsValid\n}\n\nfunction extractMatchingNodes(\n nodes: TextNode[],\n startIndex: number,\n endIndex: number,\n): [\n matchingOffset: number,\n unmodifiedBeforeNodes: TextNode[],\n matchingNodes: TextNode[],\n unmodifiedAfterNodes: TextNode[],\n] {\n const unmodifiedBeforeNodes: TextNode[] = []\n const matchingNodes: TextNode[] = []\n const unmodifiedAfterNodes: TextNode[] = []\n let matchingOffset = 0\n\n let currentOffset = 0\n const currentNodes = [...nodes]\n\n while (currentNodes.length > 0) {\n const currentNode = currentNodes[0]\n const currentNodeText = currentNode.getTextContent()\n const currentNodeLength = currentNodeText.length\n const currentNodeStart = currentOffset\n const currentNodeEnd = currentOffset + currentNodeLength\n\n if (currentNodeEnd <= startIndex) {\n unmodifiedBeforeNodes.push(currentNode)\n matchingOffset += currentNodeLength\n } else if (currentNodeStart >= endIndex) {\n unmodifiedAfterNodes.push(currentNode)\n } else {\n matchingNodes.push(currentNode)\n }\n currentOffset += currentNodeLength\n currentNodes.shift()\n }\n return [matchingOffset, unmodifiedBeforeNodes, matchingNodes, unmodifiedAfterNodes]\n}\n\nfunction createAutoLinkNode(\n nodes: TextNode[],\n startIndex: number,\n endIndex: number,\n match: LinkMatcherResult,\n): TextNode | undefined {\n const fields: LinkFields = {\n linkType: 'custom',\n url: match.url,\n ...match.fields,\n }\n\n const linkNode = $createAutoLinkNode({ fields })\n if (nodes.length === 1) {\n let remainingTextNode = nodes[0]\n let linkTextNode\n if (startIndex === 0) {\n ;[linkTextNode, remainingTextNode] = remainingTextNode.splitText(endIndex)\n } else {\n ;[, linkTextNode, remainingTextNode] = remainingTextNode.splitText(startIndex, endIndex)\n }\n const textNode = $createTextNode(match.text)\n textNode.setFormat(linkTextNode.getFormat())\n textNode.setDetail(linkTextNode.getDetail())\n linkNode.append(textNode)\n linkTextNode.replace(linkNode)\n return remainingTextNode\n } else if (nodes.length > 1) {\n const firstTextNode = nodes[0]\n let offset = firstTextNode.getTextContent().length\n let firstLinkTextNode\n if (startIndex === 0) {\n firstLinkTextNode = firstTextNode\n } else {\n ;[, firstLinkTextNode] = firstTextNode.splitText(startIndex)\n }\n const linkNodes = []\n let remainingTextNode\n for (let i = 1; i < nodes.length; i++) {\n const currentNode = nodes[i]\n const currentNodeText = currentNode.getTextContent()\n const currentNodeLength = currentNodeText.length\n const currentNodeStart = offset\n const currentNodeEnd = offset + currentNodeLength\n if (currentNodeStart < endIndex) {\n if (currentNodeEnd <= endIndex) {\n linkNodes.push(currentNode)\n } else {\n const [linkTextNode, endNode] = currentNode.splitText(endIndex - currentNodeStart)\n linkNodes.push(linkTextNode)\n remainingTextNode = endNode\n }\n }\n offset += currentNodeLength\n }\n const selection = $getSelection()\n const selectedTextNode = selection ? selection.getNodes().find($isTextNode) : undefined\n const textNode = $createTextNode(firstLinkTextNode.getTextContent())\n textNode.setFormat(firstLinkTextNode.getFormat())\n textNode.setDetail(firstLinkTextNode.getDetail())\n linkNode.append(textNode, ...linkNodes)\n // it does not preserve caret position if caret was at the first text node\n // so we need to restore caret position\n if (selectedTextNode && selectedTextNode === firstLinkTextNode) {\n if ($isRangeSelection(selection)) {\n textNode.select(selection.anchor.offset, selection.focus.offset)\n } else if ($isNodeSelection(selection)) {\n textNode.select(0, textNode.getTextContent().length)\n }\n }\n firstLinkTextNode.replace(linkNode)\n return remainingTextNode\n }\n return undefined\n}\n\nfunction handleLinkCreation(\n nodes: TextNode[],\n matchers: LinkMatcher[],\n onChange: ChangeHandler,\n): void {\n let currentNodes = [...nodes]\n const initialText = currentNodes.map((node) => node.getTextContent()).join('')\n let text = initialText\n\n let match\n let invalidMatchEnd = 0\n\n while ((match = findFirstMatch(text, matchers)) != null && match !== null) {\n const matchStart: number = match.index\n const matchLength: number = match.length\n const matchEnd = matchStart + matchLength\n const isValid = isContentAroundIsValid(\n invalidMatchEnd + matchStart,\n invalidMatchEnd + matchEnd,\n initialText,\n currentNodes,\n )\n\n if (isValid) {\n const [matchingOffset, , matchingNodes, unmodifiedAfterNodes] = extractMatchingNodes(\n currentNodes,\n invalidMatchEnd + matchStart,\n invalidMatchEnd + matchEnd,\n )\n\n const actualMatchStart = invalidMatchEnd + matchStart - matchingOffset\n const actualMatchEnd = invalidMatchEnd + matchEnd - matchingOffset\n const remainingTextNode = createAutoLinkNode(\n matchingNodes,\n actualMatchStart,\n actualMatchEnd,\n match,\n )\n currentNodes = remainingTextNode\n ? [remainingTextNode, ...unmodifiedAfterNodes]\n : unmodifiedAfterNodes\n onChange(match.url, null)\n invalidMatchEnd = 0\n } else {\n invalidMatchEnd += matchEnd\n }\n\n text = text.substring(matchEnd)\n }\n}\n\nfunction handleLinkEdit(\n linkNode: AutoLinkNode,\n matchers: LinkMatcher[],\n onChange: ChangeHandler,\n): void {\n // Check children are simple text\n const children = linkNode.getChildren()\n const childrenLength = children.length\n for (let i = 0; i < childrenLength; i++) {\n const child = children[i]\n if (!$isTextNode(child) || !child.isSimpleText()) {\n replaceWithChildren(linkNode)\n onChange(null, linkNode.getFields()?.url ?? null)\n return\n }\n }\n\n // Check text content fully matches\n const text = linkNode.getTextContent()\n const match = findFirstMatch(text, matchers)\n if (match === null || match.text !== text) {\n replaceWithChildren(linkNode)\n onChange(null, linkNode.getFields()?.url ?? null)\n return\n }\n\n // Check neighbors\n if (!isPreviousNodeValid(linkNode) || !isNextNodeValid(linkNode)) {\n replaceWithChildren(linkNode)\n onChange(null, linkNode.getFields()?.url ?? null)\n return\n }\n\n const url = linkNode.getFields()?.url\n if (url !== match?.url) {\n const flds = linkNode.getFields()\n flds.url = match?.url\n linkNode.setFields(flds)\n onChange(match.url, url ?? null)\n }\n}\n\n// Bad neighbors are edits in neighbor nodes that make AutoLinks incompatible.\n// Given the creation preconditions, these can only be simple text nodes.\nfunction handleBadNeighbors(\n textNode: TextNode,\n matchers: LinkMatcher[],\n onChange: ChangeHandler,\n): void {\n const previousSibling = textNode.getPreviousSibling()\n const nextSibling = textNode.getNextSibling()\n const text = textNode.getTextContent()\n\n if ($isAutoLinkNode(previousSibling) && !startsWithSeparator(text)) {\n previousSibling.append(textNode)\n handleLinkEdit(previousSibling, matchers, onChange)\n onChange(null, previousSibling.getFields()?.url ?? null)\n }\n\n if ($isAutoLinkNode(nextSibling) && !endsWithSeparator(text)) {\n replaceWithChildren(nextSibling)\n handleLinkEdit(nextSibling, matchers, onChange)\n onChange(null, nextSibling.getFields()?.url ?? null)\n }\n}\n\nfunction replaceWithChildren(node: ElementNode): LexicalNode[] {\n const children = node.getChildren()\n const childrenLength = children.length\n\n for (let j = childrenLength - 1; j >= 0; j--) {\n node.insertAfter(children[j])\n }\n\n node.remove()\n return children.map((child) => child.getLatest())\n}\n\nfunction getTextNodesToMatch(textNode: TextNode): TextNode[] {\n // check if next siblings are simple text nodes till a node contains a space separator\n const textNodesToMatch = [textNode]\n let nextSibling = textNode.getNextSibling()\n while (nextSibling !== null && $isTextNode(nextSibling) && nextSibling.isSimpleText()) {\n textNodesToMatch.push(nextSibling)\n if (/\\s/.test(nextSibling.getTextContent())) {\n break\n }\n nextSibling = nextSibling.getNextSibling()\n }\n return textNodesToMatch\n}\n\nfunction useAutoLink(\n editor: LexicalEditor,\n matchers: LinkMatcher[],\n onChange?: ChangeHandler,\n): void {\n useEffect(() => {\n if (!editor.hasNodes([AutoLinkNode])) {\n invariant(false, 'LexicalAutoLinkPlugin: AutoLinkNode not registered on editor')\n }\n\n const onChangeWrapped = (url: null | string, prevUrl: null | string): void => {\n if (onChange != null) {\n onChange(url, prevUrl)\n }\n }\n\n return mergeRegister(\n editor.registerNodeTransform(TextNodeValue, (textNode: TextNode) => {\n const parent = textNode.getParentOrThrow()\n const previous = textNode.getPreviousSibling()\n if ($isAutoLinkNode(parent)) {\n handleLinkEdit(parent, matchers, onChangeWrapped)\n } else if (!$isLinkNode(parent)) {\n if (\n textNode.isSimpleText() &&\n (startsWithSeparator(textNode.getTextContent()) || !$isAutoLinkNode(previous))\n ) {\n const textNodesToMatch = getTextNodesToMatch(textNode)\n handleLinkCreation(textNodesToMatch, matchers, onChangeWrapped)\n }\n\n handleBadNeighbors(textNode, matchers, onChangeWrapped)\n }\n }),\n )\n }, [editor, matchers, onChange])\n}\n\nconst URL_REGEX =\n /((https?:\\/\\/(www\\.)?)|(www\\.))[-\\w@:%.+~#=]{1,256}\\.[a-zA-Z\\d()]{1,6}\\b([-\\w()@:%+.~#?&/=]*)/\n\nconst EMAIL_REGEX =\n /(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\])|(([a-zA-Z\\-\\d]+\\.)+[a-zA-Z]{2,}))/\n\nconst MATCHERS = [\n createLinkMatcherWithRegExp(URL_REGEX, (text) => {\n return text.startsWith('http') ? text : `https://${text}`\n }),\n createLinkMatcherWithRegExp(EMAIL_REGEX, (text) => {\n return `mailto:${text}`\n }),\n]\n\nexport function AutoLinkPlugin(): JSX.Element | null {\n const [editor] = useLexicalComposerContext()\n\n useAutoLink(editor, MATCHERS)\n\n return null\n}\n"],"names":["lexicalComposerContextImport","useLexicalComposerContext","lexicalUtilsImport","mergeRegister","lexicalImport","$createTextNode","$getSelection","$isElementNode","$isLineBreakNode","$isNodeSelection","$isRangeSelection","$isTextNode","TextNode","TextNodeValue","useEffect","invariant","$createAutoLinkNode","$isAutoLinkNode","AutoLinkNode","$isLinkNode","createLinkMatcherWithRegExp","regExp","urlTransformer","text","match","exec","index","length","url","findFirstMatch","matchers","i","PUNCTUATION_OR_SPACE","isSeparator","char","test","endsWithSeparator","textContent","startsWithSeparator","isPreviousNodeValid","node","previousNode","getPreviousSibling","getLastDescendant","getTextContent","isNextNodeValid","nextNode","getNextSibling","getFirstDescendant","isContentAroundIsValid","matchStart","matchEnd","nodes","contentBeforeIsValid","contentAfterIsValid","extractMatchingNodes","startIndex","endIndex","unmodifiedBeforeNodes","matchingNodes","unmodifiedAfterNodes","matchingOffset","currentOffset","currentNodes","currentNode","currentNodeText","currentNodeLength","currentNodeStart","currentNodeEnd","push","shift","createAutoLinkNode","fields","linkType","linkNode","remainingTextNode","linkTextNode","splitText","textNode","setFormat","getFormat","setDetail","getDetail","append","replace","firstTextNode","offset","firstLinkTextNode","linkNodes","endNode","selection","selectedTextNode","getNodes","find","undefined","select","anchor","focus","handleLinkCreation","onChange","initialText","map","join","invalidMatchEnd","matchLength","isValid","actualMatchStart","actualMatchEnd","substring","handleLinkEdit","children","getChildren","childrenLength","child","isSimpleText","replaceWithChildren","getFields","flds","setFields","handleBadNeighbors","previousSibling","nextSibling","j","insertAfter","remove","getLatest","getTextNodesToMatch","textNodesToMatch","useAutoLink","editor","hasNodes","onChangeWrapped","prevUrl","registerNodeTransform","parent","getParentOrThrow","previous","URL_REGEX","EMAIL_REGEX","MATCHERS","startsWith","AutoLinkPlugin"],"mappings":"AAAA;AACA,OAAOA,kCAAkC,2CAA0C;AACnF,MAAM,EAAEC,yBAAyB,EAAE,GAAGD;AAEtC,OAAOE,wBAAwB,iBAAgB;AAC/C,MAAM,EAAEC,aAAa,EAAE,GAAGD;AAE1B,OAAOE,mBAAmB,UAAS;AACnC,MAAM,EACJC,eAAe,EACfC,aAAa,EACbC,cAAc,EACdC,gBAAgB,EAChBC,gBAAgB,EAChBC,iBAAiB,EACjBC,WAAW,EACXC,UAAUC,aAAa,EACxB,GAAGT;AAKJ,SAASU,SAAS,QAAQ,QAAO;AAIjC,SAASC,SAAS,QAAQ,yCAAwC;AAClE,SAASC,mBAAmB,EAAEC,eAAe,EAAEC,YAAY,QAAQ,8BAA6B;AAChG,SAASC,WAAW,QAAQ,0BAAyB;AAcrD,OAAO,SAASC,4BACdC,MAAc,EACdC,iBAA2C,CAACC,OAASA,IAAI;IAEzD,OAAO,CAACA;QACN,MAAMC,QAAQH,OAAOI,IAAI,CAACF;QAC1B,IAAIC,UAAU,MAAM,OAAO;QAC3B,OAAO;YACLE,OAAOF,MAAME,KAAK;YAClBC,QAAQH,KAAK,CAAC,EAAE,CAACG,MAAM;YACvBJ,MAAMC,KAAK,CAAC,EAAE;YACdI,KAAKN,eAAeE,KAAK,CAAC,EAAE;QAC9B;IACF;AACF;AAEA,SAASK,eAAeN,IAAY,EAAEO,QAAuB;IAC3D,IAAK,IAAIC,IAAI,GAAGA,IAAID,SAASH,MAAM,EAAEI,IAAK;QACxC,MAAMP,QAAQM,QAAQ,CAACC,EAAE,CAACR;QAE1B,IAAIC,SAAS,MAAM;YACjB,OAAOA;QACT;IACF;IAEA,OAAO;AACT;AAEA,MAAMQ,uBAAuB;AAE7B,SAASC,YAAYC,IAAY;IAC/B,OAAOF,qBAAqBG,IAAI,CAACD;AACnC;AAEA,SAASE,kBAAkB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H,SAAS;gBAC3BzB,eAAeyB,QAAQxG,UAAUqG;YACnC,OAAO,IAAI,CAAChH,YAAYmH,SAAS;gBAC/B,IACExD,SAASoC,YAAY,MACpB5E,CAAAA,oBAAoBwC,SAASlC,cAAc,OAAO,CAAC3B,gBAAgBuH,SAAQ,GAC5E;oBACA,MAAMT,mBAAmBD,oBAAoBhD;oBAC7CoB,mBAAmB6B,kBAAkBjG,UAAUqG;gBACjD;gBAEAZ,mBAAmBzC,UAAUhD,UAAUqG;YACzC;QACF;IAEJ,GAAG;QAACF;QAAQnG;QAAUqE;KAAS;AACjC;AAEA,MAAMsC,YACJ;AAEF,MAAMC,cACJ;AAEF,MAAMC,WAAW;IACfvH,4BAA4BqH,WAAW,CAAClH;QACtC,OAAOA,KAAKqH,UAAU,CAAC,UAAUrH,OAAO,CAAC,QAAQ,EAAEA,KAAK,CAAC;IAC3D;IACAH,4BAA4BsH,aAAa,CAACnH;QACxC,OAAO,CAAC,OAAO,EAAEA,KAAK,CAAC;IACzB;CACD;AAED,OAAO,SAASsH;IACd,MAAM,CAACZ,OAAO,GAAGhI;IAEjB+H,YAAYC,QAAQU;IAEpB,OAAO;AACT"}
1
+ {"version":3,"sources":["../../../../../../src/field/features/link/plugins/autoLink/index.tsx"],"sourcesContent":["'use client'\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\n\nimport lexicalUtilsImport from '@lexical/utils'\nconst { mergeRegister } = lexicalUtilsImport\n\nimport lexicalImport from 'lexical'\nconst {\n $createTextNode,\n $getSelection,\n $isElementNode,\n $isLineBreakNode,\n $isNodeSelection,\n $isRangeSelection,\n $isTextNode,\n TextNode: TextNodeValue,\n} = lexicalImport\n\nimport type { ElementNode, LexicalEditor, LexicalNode } from 'lexical'\n\nimport { type TextNode } from 'lexical'\nimport { useEffect } from 'react'\n\nimport type { LinkFields } from '../../nodes/types.js'\n\nimport { invariant } from '../../../../lexical/utils/invariant.js'\nimport { $createAutoLinkNode, $isAutoLinkNode, AutoLinkNode } from '../../nodes/AutoLinkNode.js'\nimport { $isLinkNode } from '../../nodes/LinkNode.js'\n\ntype ChangeHandler = (url: null | string, prevUrl: null | string) => void\n\ninterface LinkMatcherResult {\n fields?: LinkFields\n index: number\n length: number\n text: string\n url: string\n}\n\nexport type LinkMatcher = (text: string) => LinkMatcherResult | null\n\nexport function createLinkMatcherWithRegExp(\n regExp: RegExp,\n urlTransformer: (text: string) => string = (text) => text,\n) {\n return (text: string) => {\n const match = regExp.exec(text)\n if (match === null) return null\n return {\n index: match.index,\n length: match[0].length,\n text: match[0],\n url: urlTransformer(match[0]),\n }\n }\n}\n\nfunction findFirstMatch(text: string, matchers: LinkMatcher[]): LinkMatcherResult | null {\n for (let i = 0; i < matchers.length; i++) {\n const match = matchers[i](text)\n\n if (match != null) {\n return match\n }\n }\n\n return null\n}\n\nconst PUNCTUATION_OR_SPACE = /[.,;\\s]/\n\nfunction isSeparator(char: string): boolean {\n return PUNCTUATION_OR_SPACE.test(char)\n}\n\nfunction endsWithSeparator(textContent: string): boolean {\n return isSeparator(textContent[textContent.length - 1])\n}\n\nfunction startsWithSeparator(textContent: string): boolean {\n return isSeparator(textContent[0])\n}\n\nfunction isPreviousNodeValid(node: LexicalNode): boolean {\n let previousNode = node.getPreviousSibling()\n if ($isElementNode(previousNode)) {\n previousNode = previousNode.getLastDescendant()\n }\n return (\n previousNode === null ||\n $isLineBreakNode(previousNode) ||\n ($isTextNode(previousNode) && endsWithSeparator(previousNode.getTextContent()))\n )\n}\n\nfunction isNextNodeValid(node: LexicalNode): boolean {\n let nextNode = node.getNextSibling()\n if ($isElementNode(nextNode)) {\n nextNode = nextNode.getFirstDescendant()\n }\n return (\n nextNode === null ||\n $isLineBreakNode(nextNode) ||\n ($isTextNode(nextNode) && startsWithSeparator(nextNode.getTextContent()))\n )\n}\n\nfunction isContentAroundIsValid(\n matchStart: number,\n matchEnd: number,\n text: string,\n nodes: TextNode[],\n): boolean {\n const contentBeforeIsValid =\n matchStart > 0 ? isSeparator(text[matchStart - 1]) : isPreviousNodeValid(nodes[0])\n if (!contentBeforeIsValid) {\n return false\n }\n\n const contentAfterIsValid =\n matchEnd < text.length ? isSeparator(text[matchEnd]) : isNextNodeValid(nodes[nodes.length - 1])\n return contentAfterIsValid\n}\n\nfunction extractMatchingNodes(\n nodes: TextNode[],\n startIndex: number,\n endIndex: number,\n): [\n matchingOffset: number,\n unmodifiedBeforeNodes: TextNode[],\n matchingNodes: TextNode[],\n unmodifiedAfterNodes: TextNode[],\n] {\n const unmodifiedBeforeNodes: TextNode[] = []\n const matchingNodes: TextNode[] = []\n const unmodifiedAfterNodes: TextNode[] = []\n let matchingOffset = 0\n\n let currentOffset = 0\n const currentNodes = [...nodes]\n\n while (currentNodes.length > 0) {\n const currentNode = currentNodes[0]\n const currentNodeText = currentNode.getTextContent()\n const currentNodeLength = currentNodeText.length\n const currentNodeStart = currentOffset\n const currentNodeEnd = currentOffset + currentNodeLength\n\n if (currentNodeEnd <= startIndex) {\n unmodifiedBeforeNodes.push(currentNode)\n matchingOffset += currentNodeLength\n } else if (currentNodeStart >= endIndex) {\n unmodifiedAfterNodes.push(currentNode)\n } else {\n matchingNodes.push(currentNode)\n }\n currentOffset += currentNodeLength\n currentNodes.shift()\n }\n return [matchingOffset, unmodifiedBeforeNodes, matchingNodes, unmodifiedAfterNodes]\n}\n\nfunction createAutoLinkNode(\n nodes: TextNode[],\n startIndex: number,\n endIndex: number,\n match: LinkMatcherResult,\n): TextNode | undefined {\n const fields: LinkFields = {\n linkType: 'custom',\n url: match.url,\n ...match.fields,\n }\n\n const linkNode = $createAutoLinkNode({ fields })\n if (nodes.length === 1) {\n let remainingTextNode = nodes[0]\n let linkTextNode\n if (startIndex === 0) {\n ;[linkTextNode, remainingTextNode] = remainingTextNode.splitText(endIndex)\n } else {\n ;[, linkTextNode, remainingTextNode] = remainingTextNode.splitText(startIndex, endIndex)\n }\n const textNode = $createTextNode(match.text)\n textNode.setFormat(linkTextNode.getFormat())\n textNode.setDetail(linkTextNode.getDetail())\n linkNode.append(textNode)\n linkTextNode.replace(linkNode)\n return remainingTextNode\n } else if (nodes.length > 1) {\n const firstTextNode = nodes[0]\n let offset = firstTextNode.getTextContent().length\n let firstLinkTextNode\n if (startIndex === 0) {\n firstLinkTextNode = firstTextNode\n } else {\n ;[, firstLinkTextNode] = firstTextNode.splitText(startIndex)\n }\n const linkNodes = []\n let remainingTextNode\n for (let i = 1; i < nodes.length; i++) {\n const currentNode = nodes[i]\n const currentNodeText = currentNode.getTextContent()\n const currentNodeLength = currentNodeText.length\n const currentNodeStart = offset\n const currentNodeEnd = offset + currentNodeLength\n if (currentNodeStart < endIndex) {\n if (currentNodeEnd <= endIndex) {\n linkNodes.push(currentNode)\n } else {\n const [linkTextNode, endNode] = currentNode.splitText(endIndex - currentNodeStart)\n linkNodes.push(linkTextNode)\n remainingTextNode = endNode\n }\n }\n offset += currentNodeLength\n }\n const selection = $getSelection()\n const selectedTextNode = selection ? selection.getNodes().find($isTextNode) : undefined\n const textNode = $createTextNode(firstLinkTextNode.getTextContent())\n textNode.setFormat(firstLinkTextNode.getFormat())\n textNode.setDetail(firstLinkTextNode.getDetail())\n linkNode.append(textNode, ...linkNodes)\n // it does not preserve caret position if caret was at the first text node\n // so we need to restore caret position\n if (selectedTextNode && selectedTextNode === firstLinkTextNode) {\n if ($isRangeSelection(selection)) {\n textNode.select(selection.anchor.offset, selection.focus.offset)\n } else if ($isNodeSelection(selection)) {\n textNode.select(0, textNode.getTextContent().length)\n }\n }\n firstLinkTextNode.replace(linkNode)\n return remainingTextNode\n }\n return undefined\n}\n\nfunction handleLinkCreation(\n nodes: TextNode[],\n matchers: LinkMatcher[],\n onChange: ChangeHandler,\n): void {\n let currentNodes = [...nodes]\n const initialText = currentNodes.map((node) => node.getTextContent()).join('')\n let text = initialText\n\n let match\n let invalidMatchEnd = 0\n\n while ((match = findFirstMatch(text, matchers)) != null && match !== null) {\n const matchStart: number = match.index\n const matchLength: number = match.length\n const matchEnd = matchStart + matchLength\n const isValid = isContentAroundIsValid(\n invalidMatchEnd + matchStart,\n invalidMatchEnd + matchEnd,\n initialText,\n currentNodes,\n )\n\n if (isValid) {\n const [matchingOffset, , matchingNodes, unmodifiedAfterNodes] = extractMatchingNodes(\n currentNodes,\n invalidMatchEnd + matchStart,\n invalidMatchEnd + matchEnd,\n )\n\n const actualMatchStart = invalidMatchEnd + matchStart - matchingOffset\n const actualMatchEnd = invalidMatchEnd + matchEnd - matchingOffset\n const remainingTextNode = createAutoLinkNode(\n matchingNodes,\n actualMatchStart,\n actualMatchEnd,\n match,\n )\n currentNodes = remainingTextNode\n ? [remainingTextNode, ...unmodifiedAfterNodes]\n : unmodifiedAfterNodes\n onChange(match.url, null)\n invalidMatchEnd = 0\n } else {\n invalidMatchEnd += matchEnd\n }\n\n text = text.substring(matchEnd)\n }\n}\n\nfunction handleLinkEdit(\n linkNode: AutoLinkNode,\n matchers: LinkMatcher[],\n onChange: ChangeHandler,\n): void {\n // Check children are simple text\n const children = linkNode.getChildren()\n const childrenLength = children.length\n for (let i = 0; i < childrenLength; i++) {\n const child = children[i]\n if (!$isTextNode(child) || !child.isSimpleText()) {\n replaceWithChildren(linkNode)\n onChange(null, linkNode.getFields()?.url ?? null)\n return\n }\n }\n\n // Check text content fully matches\n const text = linkNode.getTextContent()\n const match = findFirstMatch(text, matchers)\n if (match === null || match.text !== text) {\n replaceWithChildren(linkNode)\n onChange(null, linkNode.getFields()?.url ?? null)\n return\n }\n\n // Check neighbors\n if (!isPreviousNodeValid(linkNode) || !isNextNodeValid(linkNode)) {\n replaceWithChildren(linkNode)\n onChange(null, linkNode.getFields()?.url ?? null)\n return\n }\n\n const url = linkNode.getFields()?.url\n if (url !== match?.url) {\n const flds = linkNode.getFields()\n flds.url = match?.url\n linkNode.setFields(flds)\n onChange(match.url, url ?? null)\n }\n}\n\n// Bad neighbors are edits in neighbor nodes that make AutoLinks incompatible.\n// Given the creation preconditions, these can only be simple text nodes.\nfunction handleBadNeighbors(\n textNode: TextNode,\n matchers: LinkMatcher[],\n onChange: ChangeHandler,\n): void {\n const previousSibling = textNode.getPreviousSibling()\n const nextSibling = textNode.getNextSibling()\n const text = textNode.getTextContent()\n\n if ($isAutoLinkNode(previousSibling) && !startsWithSeparator(text)) {\n previousSibling.append(textNode)\n handleLinkEdit(previousSibling, matchers, onChange)\n onChange(null, previousSibling.getFields()?.url ?? null)\n }\n\n if ($isAutoLinkNode(nextSibling) && !endsWithSeparator(text)) {\n replaceWithChildren(nextSibling)\n handleLinkEdit(nextSibling, matchers, onChange)\n onChange(null, nextSibling.getFields()?.url ?? null)\n }\n}\n\nfunction replaceWithChildren(node: ElementNode): LexicalNode[] {\n const children = node.getChildren()\n const childrenLength = children.length\n\n for (let j = childrenLength - 1; j >= 0; j--) {\n node.insertAfter(children[j])\n }\n\n node.remove()\n return children.map((child) => child.getLatest())\n}\n\nfunction getTextNodesToMatch(textNode: TextNode): TextNode[] {\n // check if next siblings are simple text nodes till a node contains a space separator\n const textNodesToMatch = [textNode]\n let nextSibling = textNode.getNextSibling()\n while (nextSibling !== null && $isTextNode(nextSibling) && nextSibling.isSimpleText()) {\n textNodesToMatch.push(nextSibling)\n if (/\\s/.test(nextSibling.getTextContent())) {\n break\n }\n nextSibling = nextSibling.getNextSibling()\n }\n return textNodesToMatch\n}\n\nfunction useAutoLink(\n editor: LexicalEditor,\n matchers: LinkMatcher[],\n onChange?: ChangeHandler,\n): void {\n useEffect(() => {\n if (!editor.hasNodes([AutoLinkNode])) {\n invariant(false, 'LexicalAutoLinkPlugin: AutoLinkNode not registered on editor')\n }\n\n const onChangeWrapped = (url: null | string, prevUrl: null | string): void => {\n if (onChange != null) {\n onChange(url, prevUrl)\n }\n }\n\n return mergeRegister(\n editor.registerNodeTransform(TextNodeValue, (textNode: TextNode) => {\n const parent = textNode.getParentOrThrow()\n const previous = textNode.getPreviousSibling()\n if ($isAutoLinkNode(parent)) {\n handleLinkEdit(parent, matchers, onChangeWrapped)\n } else if (!$isLinkNode(parent)) {\n if (\n textNode.isSimpleText() &&\n (startsWithSeparator(textNode.getTextContent()) || !$isAutoLinkNode(previous))\n ) {\n const textNodesToMatch = getTextNodesToMatch(textNode)\n handleLinkCreation(textNodesToMatch, matchers, onChangeWrapped)\n }\n\n handleBadNeighbors(textNode, matchers, onChangeWrapped)\n }\n }),\n )\n }, [editor, matchers, onChange])\n}\n\nconst URL_REGEX =\n /((https?:\\/\\/(www\\.)?)|(www\\.))[-\\w@:%.+~#=]{1,256}\\.[a-zA-Z\\d()]{1,6}\\b([-\\w()@:%+.~#?&/=]*)/\n\nconst EMAIL_REGEX =\n /(([^<>()[\\]\\\\.,;:\\s@\"]+(\\.[^<>()[\\]\\\\.,;:\\s@\"]+)*)|(\".+\"))@((\\[\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\])|(([a-z\\-\\d]+\\.)+[a-z]{2,}))/i\n\nconst MATCHERS = [\n createLinkMatcherWithRegExp(URL_REGEX, (text) => {\n return text.startsWith('http') ? text : `https://${text}`\n }),\n createLinkMatcherWithRegExp(EMAIL_REGEX, (text) => {\n return `mailto:${text}`\n }),\n]\n\nexport function AutoLinkPlugin(): JSX.Element | null {\n const [editor] = useLexicalComposerContext()\n\n useAutoLink(editor, MATCHERS)\n\n return null\n}\n"],"names":["lexicalComposerContextImport","useLexicalComposerContext","lexicalUtilsImport","mergeRegister","lexicalImport","$createTextNode","$getSelection","$isElementNode","$isLineBreakNode","$isNodeSelection","$isRangeSelection","$isTextNode","TextNode","TextNodeValue","useEffect","invariant","$createAutoLinkNode","$isAutoLinkNode","AutoLinkNode","$isLinkNode","createLinkMatcherWithRegExp","regExp","urlTransformer","text","match","exec","index","length","url","findFirstMatch","matchers","i","PUNCTUATION_OR_SPACE","isSeparator","char","test","endsWithSeparator","textContent","startsWithSeparator","isPreviousNodeValid","node","previousNode","getPreviousSibling","getLastDescendant","getTextContent","isNextNodeValid","nextNode","getNextSibling","getFirstDescendant","isContentAroundIsValid","matchStart","matchEnd","nodes","contentBeforeIsValid","contentAfterIsValid","extractMatchingNodes","startIndex","endIndex","unmodifiedBeforeNodes","matchingNodes","unmodifiedAfterNodes","matchingOffset","currentOffset","currentNodes","currentNode","currentNodeText","currentNodeLength","currentNodeStart","currentNodeEnd","push","shift","createAutoLinkNode","fields","linkType","linkNode","remainingTextNode","linkTextNode","splitText","textNode","setFormat","getFormat","setDetail","getDetail","append","replace","firstTextNode","offset","firstLinkTextNode","linkNodes","endNode","selection","selectedTextNode","getNodes","find","undefined","select","anchor","focus","handleLinkCreation","onChange","initialText","map","join","invalidMatchEnd","matchLength","isValid","actualMatchStart","actualMatchEnd","substring","handleLinkEdit","children","getChildren","childrenLength","child","isSimpleText","replaceWithChildren","getFields","flds","setFields","handleBadNeighbors","previousSibling","nextSibling","j","insertAfter","remove","getLatest","getTextNodesToMatch","textNodesToMatch","useAutoLink","editor","hasNodes","onChangeWrapped","prevUrl","registerNodeTransform","parent","getParentOrThrow","previous","URL_REGEX","EMAIL_REGEX","MATCHERS","startsWith","AutoLinkPlugin"],"mappings":"AAAA;AACA,OAAOA,kCAAkC,2CAA0C;AACnF,MAAM,EAAEC,yBAAyB,EAAE,GAAGD;AAEtC,OAAOE,wBAAwB,iBAAgB;AAC/C,MAAM,EAAEC,aAAa,EAAE,GAAGD;AAE1B,OAAOE,mBAAmB,UAAS;AACnC,MAAM,EACJC,eAAe,EACfC,aAAa,EACbC,cAAc,EACdC,gBAAgB,EAChBC,gBAAgB,EAChBC,iBAAiB,EACjBC,WAAW,EACXC,UAAUC,aAAa,EACxB,GAAGT;AAKJ,SAASU,SAAS,QAAQ,QAAO;AAIjC,SAASC,SAAS,QAAQ,yCAAwC;AAClE,SAASC,mBAAmB,EAAEC,eAAe,EAAEC,YAAY,QAAQ,8BAA6B;AAChG,SAASC,WAAW,QAAQ,0BAAyB;AAcrD,OAAO,SAASC,4BACdC,MAAc,EACdC,iBAA2C,CAACC,O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AAED,OAAO,SAASsH;IACd,MAAM,CAACZ,OAAO,GAAGhI;IAEjB+H,YAAYC,QAAQU;IAEpB,OAAO;AACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.tsx"],"names":[],"mappings":"AAsBA,OAAO,KAAmD,MAAM,OAAO,CAAA;AAcvE,wBAAgB,UAAU,CAAC,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,WAAW,CAAA;CAAE,GAAG,KAAK,CAAC,SAAS,CAoRvF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../src/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAmD,MAAM,OAAO,CAAA;AAcvE,wBAAgB,UAAU,CAAC,EAAE,UAAU,EAAE,EAAE;IAAE,UAAU,EAAE,WAAW,CAAA;CAAE,GAAG,KAAK,CAAC,SAAS,CAoRvF"}
@@ -5,9 +5,12 @@ const { useLexicalComposerContext } = lexicalComposerContextImport;
5
5
  import lexicalUtilsImport from '@lexical/utils';
6
6
  const { $findMatchingParent, mergeRegister } = lexicalUtilsImport;
7
7
  import { getTranslation } from '@payloadcms/translations';
8
- import { formatDrawerSlug, useConfig, useEditDepth, useTranslation } from '@payloadcms/ui';
9
8
  import lexicalImport from 'lexical';
10
9
  const { $getSelection, $isRangeSelection, COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_LOW, KEY_ESCAPE_COMMAND, SELECTION_CHANGE_COMMAND } = lexicalImport;
10
+ import { formatDrawerSlug } from '@payloadcms/ui/elements/Drawer';
11
+ import { useConfig } from '@payloadcms/ui/providers/Config';
12
+ import { useEditDepth } from '@payloadcms/ui/providers/EditDepth';
13
+ import { useTranslation } from '@payloadcms/ui/providers/Translation';
11
14
  import React, { useCallback, useEffect, useRef, useState } from 'react';
12
15
  import { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js';
13
16
  import { getSelectedNode } from '../../../../../lexical/utils/getSelectedNode.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../src/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.tsx"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload/types'\nimport type { Data } from 'payload/types'\n\nimport * as facelessUIImport from '@faceless-ui/modal'\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\n\nimport lexicalUtilsImport from '@lexical/utils'\nconst { $findMatchingParent, mergeRegister } = lexicalUtilsImport\nimport { getTranslation } from '@payloadcms/translations'\nimport { formatDrawerSlug, useConfig, useEditDepth, useTranslation } from '@payloadcms/ui'\nimport lexicalImport from 'lexical'\nconst {\n $getSelection,\n $isRangeSelection,\n COMMAND_PRIORITY_HIGH,\n COMMAND_PRIORITY_LOW,\n KEY_ESCAPE_COMMAND,\n SELECTION_CHANGE_COMMAND,\n} = lexicalImport\n\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\n\nimport type { LinkNode } from '../../../nodes/LinkNode.js'\nimport type { LinkPayload } from '../types.js'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { getSelectedNode } from '../../../../../lexical/utils/getSelectedNode.js'\nimport { setFloatingElemPositionForLinkEditor } from '../../../../../lexical/utils/setFloatingElemPositionForLinkEditor.js'\nimport { LinkDrawer } from '../../../drawer/index.js'\nimport { $isAutoLinkNode } from '../../../nodes/AutoLinkNode.js'\nimport { $createLinkNode } from '../../../nodes/LinkNode.js'\nimport { $isLinkNode, TOGGLE_LINK_COMMAND } from '../../../nodes/LinkNode.js'\nimport { TOGGLE_LINK_WITH_MODAL_COMMAND } from './commands.js'\n\nexport function LinkEditor({ anchorElem }: { anchorElem: HTMLElement }): React.ReactNode {\n const { useModal } = facelessUIImport\n\n const [editor] = useLexicalComposerContext()\n\n const editorRef = useRef<HTMLDivElement | null>(null)\n const [linkUrl, setLinkUrl] = useState('')\n const [linkLabel, setLinkLabel] = useState('')\n\n const { uuid } = useEditorConfigContext()\n\n const config = useConfig()\n\n const { i18n, t } = useTranslation()\n\n const [stateData, setStateData] = useState<LinkPayload>(null)\n\n const { closeModal, toggleModal } = useModal()\n const editDepth = useEditDepth()\n const [isLink, setIsLink] = useState(false)\n const [isAutoLink, setIsAutoLink] = useState(false)\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-rich-text-link-` + uuid,\n depth: editDepth,\n })\n\n const updateLinkEditor = useCallback(() => {\n const selection = $getSelection()\n let selectedNodeDomRect: DOMRect | undefined = null\n\n // Handle the data displayed in the floating link editor & drawer when you click on a link node\n if ($isRangeSelection(selection)) {\n const node = getSelectedNode(selection)\n selectedNodeDomRect = editor.getElementByKey(node.getKey())?.getBoundingClientRect()\n const linkParent: LinkNode = $findMatchingParent(node, $isLinkNode)\n if (linkParent == null) {\n setIsLink(false)\n setIsAutoLink(false)\n setLinkUrl('')\n setLinkLabel('')\n return\n }\n\n // Initial state:\n const data: LinkPayload = {\n fields: {\n doc: undefined,\n linkType: undefined,\n newTab: undefined,\n url: '',\n ...linkParent.getFields(),\n },\n text: linkParent.getTextContent(),\n }\n\n if (linkParent.getFields()?.linkType === 'custom') {\n setLinkUrl(linkParent.getFields()?.url ?? '')\n setLinkLabel('')\n } else {\n // internal link\n setLinkUrl(\n `/admin/collections/${linkParent.getFields()?.doc?.relationTo}/${\n linkParent.getFields()?.doc?.value\n }`,\n )\n\n const relatedField = config.collections.find(\n (coll) => coll.slug === linkParent.getFields()?.doc?.relationTo,\n )\n const label = t('fields:linkedTo', {\n label: getTranslation(relatedField.labels.singular, i18n),\n }).replace(/<[^>]*>?/g, '')\n setLinkLabel(label)\n }\n\n setStateData(data)\n setIsLink(true)\n if ($isAutoLinkNode(linkParent)) {\n setIsAutoLink(true)\n } else {\n setIsAutoLink(false)\n }\n }\n\n const editorElem = editorRef.current\n const nativeSelection = window.getSelection()\n const { activeElement } = document\n\n if (editorElem === null) {\n return\n }\n\n const rootElement = editor.getRootElement()\n\n if (\n selection !== null &&\n nativeSelection !== null &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode)\n ) {\n if (!selectedNodeDomRect) {\n // Get the DOM rect of the selected node using the native selection. This sometimes produces the wrong\n // result, which is why we use lexical's selection preferably.\n selectedNodeDomRect = nativeSelection.getRangeAt(0).getBoundingClientRect()\n }\n\n if (selectedNodeDomRect != null) {\n selectedNodeDomRect.y += 40\n setFloatingElemPositionForLinkEditor(selectedNodeDomRect, editorElem, anchorElem)\n }\n } else if (activeElement == null || activeElement.className !== 'link-input') {\n if (rootElement !== null) {\n setFloatingElemPositionForLinkEditor(null, editorElem, anchorElem)\n }\n setLinkUrl('')\n setLinkLabel('')\n }\n\n return true\n }, [anchorElem, editor, config, t, i18n])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand(\n TOGGLE_LINK_WITH_MODAL_COMMAND,\n (payload: LinkPayload) => {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, payload)\n\n // Now, open the modal\n updateLinkEditor()\n toggleModal(drawerSlug)\n\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor, updateLinkEditor, toggleModal, drawerSlug])\n\n useEffect(() => {\n if (!isLink && editorRef) {\n editorRef.current.style.opacity = '0'\n editorRef.current.style.transform = 'translate(-10000px, -10000px)'\n }\n }, [isLink])\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement\n\n const update = (): void => {\n editor.getEditorState().read(() => {\n void updateLinkEditor()\n })\n }\n\n window.addEventListener('resize', update)\n\n if (scrollerElem != null) {\n scrollerElem.addEventListener('scroll', update)\n }\n\n return () => {\n window.removeEventListener('resize', update)\n\n if (scrollerElem != null) {\n scrollerElem.removeEventListener('scroll', update)\n }\n }\n }, [anchorElem.parentElement, editor, updateLinkEditor])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n void updateLinkEditor()\n })\n }),\n\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n void updateLinkEditor()\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n editor.registerCommand(\n KEY_ESCAPE_COMMAND,\n () => {\n if (isLink) {\n setIsLink(false)\n setIsAutoLink(false)\n return true\n }\n return false\n },\n COMMAND_PRIORITY_HIGH,\n ),\n )\n }, [editor, updateLinkEditor, setIsLink, isLink])\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n void updateLinkEditor()\n })\n }, [editor, updateLinkEditor])\n\n return (\n <React.Fragment>\n <div className=\"link-editor\" ref={editorRef}>\n <div className=\"link-input\">\n <a href={linkUrl} rel=\"noopener noreferrer\" target=\"_blank\">\n {linkLabel != null && linkLabel.length > 0 ? linkLabel : linkUrl}\n </a>\n {editor.isEditable() && (\n <React.Fragment>\n <button\n aria-label=\"Edit link\"\n className=\"link-edit\"\n onClick={() => {\n toggleModal(drawerSlug)\n }}\n onMouseDown={(event) => {\n event.preventDefault()\n }}\n tabIndex={0}\n type=\"button\"\n />\n {!isAutoLink && (\n <button\n aria-label=\"Remove link\"\n className=\"link-trash\"\n onClick={() => {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, null)\n }}\n onMouseDown={(event) => {\n event.preventDefault()\n }}\n tabIndex={0}\n type=\"button\"\n />\n )}\n </React.Fragment>\n )}\n </div>\n </div>\n <LinkDrawer\n drawerSlug={drawerSlug}\n handleModalSubmit={(fields: FormState, data: Data) => {\n closeModal(drawerSlug)\n\n const newLinkPayload: LinkPayload = data as LinkPayload\n\n // See: https://github.com/facebook/lexical/pull/5536. This updates autolink nodes to link nodes whenever a change was made (which is good!).\n editor.update(() => {\n const selection = $getSelection()\n if ($isRangeSelection(selection)) {\n const parent = getSelectedNode(selection).getParent()\n if ($isAutoLinkNode(parent)) {\n const linkNode = $createLinkNode({\n fields: newLinkPayload.fields,\n })\n parent.replace(linkNode, true)\n }\n }\n })\n\n // Needs to happen AFTER a potential auto link => link node conversion, as otherwise, the updated text to display may be lost due to\n // it being applied to the auto link node instead of the link node.\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, newLinkPayload)\n }}\n stateData={stateData}\n />\n </React.Fragment>\n )\n}\n"],"names":["facelessUIImport","lexicalComposerContextImport","useLexicalComposerContext","lexicalUtilsImport","$findMatchingParent","mergeRegister","getTranslation","formatDrawerSlug","useConfig","useEditDepth","useTranslation","lexicalImport","$getSelection","$isRangeSelection","COMMAND_PRIORITY_HIGH","COMMAND_PRIORITY_LOW","KEY_ESCAPE_COMMAND","SELECTION_CHANGE_COMMAND","React","useCallback","useEffect","useRef","useState","useEditorConfigContext","getSelectedNode","setFloatingElemPositionForLinkEditor","LinkDrawer","$isAutoLinkNode","$createLinkNode","$isLinkNode","TOGGLE_LINK_COMMAND","TOGGLE_LINK_WITH_MODAL_COMMAND","LinkEditor","anchorElem","useModal","editor","editorRef","linkUrl","setLinkUrl","linkLabel","setLinkLabel","uuid","config","i18n","t","stateData","setStateData","closeModal","toggleModal","editDepth","isLink","setIsLink","isAutoLink","setIsAutoLink","drawerSlug","slug","depth","updateLinkEditor","selection","selectedNodeDomRect","node","getElementByKey","getKey","getBoundingClientRect","linkParent","data","fields","doc","undefined","linkType","newTab","url","getFields","text","getTextContent","relationTo","value","relatedField","collections","find","coll","label","labels","singular","replace","editorElem","current","nativeSelection","window","getSelection","activeElement","document","rootElement","getRootElement","contains","anchorNode","getRangeAt","y","className","registerCommand","payload","dispatchCommand","style","opacity","transform","scrollerElem","parentElement","update","getEditorState","read","addEventListener","removeEventListener","registerUpdateListener","editorState","Fragment","div","ref","a","href","rel","target","length","isEditable","button","aria-label","onClick","onMouseDown","event","preventDefault","tabIndex","type","handleModalSubmit","newLinkPayload","parent","getParent","linkNode"],"mappings":"AAAA;AAIA,YAAYA,sBAAsB,qBAAoB;AACtD,OAAOC,kCAAkC,2CAA0C;AACnF,MAAM,EAAEC,yBAAyB,EAAE,GAAGD;AAEtC,OAAO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S;QACCC,cAAW;QACX1B,WAAU;QACV2B,SAAS;YACP7E,YAAYM;QACd;QACAwE,aAAa,CAACC;YACZA,MAAMC,cAAc;QACtB;QACAC,UAAU;QACVC,MAAK;QAEN,CAAC9E,4BACA,oBAACuE;QACCC,cAAW;QACX1B,WAAU;QACV2B,SAAS;YACP1F,OAAOkE,eAAe,CAACvE,qBAAqB;QAC9C;QACAgG,aAAa,CAACC;YACZA,MAAMC,cAAc;QACtB;QACAC,UAAU;QACVC,MAAK;yBAOjB,oBAACxG;QACC4B,YAAYA;QACZ6E,mBAAmB,CAACjE,QAAmBD;YACrClB,WAAWO;YAEX,MAAM8E,iBAA8BnE;YAEpC,6IAA6I;YAC7I9B,OAAOwE,MAAM,CAAC;gBACZ,MAAMjD,YAAY9C;gBAClB,IAAIC,kBAAkB6C,YAAY;oBAChC,MAAM2E,SAAS7G,gBAAgBkC,WAAW4E,SAAS;oBACnD,IAAI3G,gBAAgB0G,SAAS;wBAC3B,MAAME,WAAW3G,gBAAgB;4BAC/BsC,QAAQkE,eAAelE,MAAM;wBAC/B;wBACAmE,OAAOjD,OAAO,CAACmD,UAAU;oBAC3B;gBACF;YACF;YAEA,oIAAoI;YACpI,mEAAmE;YACnEpG,OAAOkE,eAAe,CAACvE,qBAAqBsG;QAC9C;QACAvF,WAAWA;;AAInB"}
1
+ {"version":3,"sources":["../../../../../../../src/field/features/link/plugins/floatingLinkEditor/LinkEditor/index.tsx"],"sourcesContent":["'use client'\nimport type { FormState } from 'payload/types'\nimport type { Data } from 'payload/types'\n\nimport * as facelessUIImport from '@faceless-ui/modal'\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\n\nimport lexicalUtilsImport from '@lexical/utils'\nconst { $findMatchingParent, mergeRegister } = lexicalUtilsImport\nimport { getTranslation } from '@payloadcms/translations'\nimport lexicalImport from 'lexical'\nconst {\n $getSelection,\n $isRangeSelection,\n COMMAND_PRIORITY_HIGH,\n COMMAND_PRIORITY_LOW,\n KEY_ESCAPE_COMMAND,\n SELECTION_CHANGE_COMMAND,\n} = lexicalImport\n\nimport { formatDrawerSlug } from '@payloadcms/ui/elements/Drawer'\nimport { useConfig } from '@payloadcms/ui/providers/Config'\nimport { useEditDepth } from '@payloadcms/ui/providers/EditDepth'\nimport { useTranslation } from '@payloadcms/ui/providers/Translation'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\n\nimport type { LinkNode } from '../../../nodes/LinkNode.js'\nimport type { LinkPayload } from '../types.js'\n\nimport { useEditorConfigContext } from '../../../../../lexical/config/client/EditorConfigProvider.js'\nimport { getSelectedNode } from '../../../../../lexical/utils/getSelectedNode.js'\nimport { setFloatingElemPositionForLinkEditor } from '../../../../../lexical/utils/setFloatingElemPositionForLinkEditor.js'\nimport { LinkDrawer } from '../../../drawer/index.js'\nimport { $isAutoLinkNode } from '../../../nodes/AutoLinkNode.js'\nimport { $createLinkNode } from '../../../nodes/LinkNode.js'\nimport { $isLinkNode, TOGGLE_LINK_COMMAND } from '../../../nodes/LinkNode.js'\nimport { TOGGLE_LINK_WITH_MODAL_COMMAND } from './commands.js'\n\nexport function LinkEditor({ anchorElem }: { anchorElem: HTMLElement }): React.ReactNode {\n const { useModal } = facelessUIImport\n\n const [editor] = useLexicalComposerContext()\n\n const editorRef = useRef<HTMLDivElement | null>(null)\n const [linkUrl, setLinkUrl] = useState('')\n const [linkLabel, setLinkLabel] = useState('')\n\n const { uuid } = useEditorConfigContext()\n\n const config = useConfig()\n\n const { i18n, t } = useTranslation()\n\n const [stateData, setStateData] = useState<LinkPayload>(null)\n\n const { closeModal, toggleModal } = useModal()\n const editDepth = useEditDepth()\n const [isLink, setIsLink] = useState(false)\n const [isAutoLink, setIsAutoLink] = useState(false)\n\n const drawerSlug = formatDrawerSlug({\n slug: `lexical-rich-text-link-` + uuid,\n depth: editDepth,\n })\n\n const updateLinkEditor = useCallback(() => {\n const selection = $getSelection()\n let selectedNodeDomRect: DOMRect | undefined = null\n\n // Handle the data displayed in the floating link editor & drawer when you click on a link node\n if ($isRangeSelection(selection)) {\n const node = getSelectedNode(selection)\n selectedNodeDomRect = editor.getElementByKey(node.getKey())?.getBoundingClientRect()\n const linkParent: LinkNode = $findMatchingParent(node, $isLinkNode)\n if (linkParent == null) {\n setIsLink(false)\n setIsAutoLink(false)\n setLinkUrl('')\n setLinkLabel('')\n return\n }\n\n // Initial state:\n const data: LinkPayload = {\n fields: {\n doc: undefined,\n linkType: undefined,\n newTab: undefined,\n url: '',\n ...linkParent.getFields(),\n },\n text: linkParent.getTextContent(),\n }\n\n if (linkParent.getFields()?.linkType === 'custom') {\n setLinkUrl(linkParent.getFields()?.url ?? '')\n setLinkLabel('')\n } else {\n // internal link\n setLinkUrl(\n `/admin/collections/${linkParent.getFields()?.doc?.relationTo}/${\n linkParent.getFields()?.doc?.value\n }`,\n )\n\n const relatedField = config.collections.find(\n (coll) => coll.slug === linkParent.getFields()?.doc?.relationTo,\n )\n const label = t('fields:linkedTo', {\n label: getTranslation(relatedField.labels.singular, i18n),\n }).replace(/<[^>]*>?/g, '')\n setLinkLabel(label)\n }\n\n setStateData(data)\n setIsLink(true)\n if ($isAutoLinkNode(linkParent)) {\n setIsAutoLink(true)\n } else {\n setIsAutoLink(false)\n }\n }\n\n const editorElem = editorRef.current\n const nativeSelection = window.getSelection()\n const { activeElement } = document\n\n if (editorElem === null) {\n return\n }\n\n const rootElement = editor.getRootElement()\n\n if (\n selection !== null &&\n nativeSelection !== null &&\n rootElement !== null &&\n rootElement.contains(nativeSelection.anchorNode)\n ) {\n if (!selectedNodeDomRect) {\n // Get the DOM rect of the selected node using the native selection. This sometimes produces the wrong\n // result, which is why we use lexical's selection preferably.\n selectedNodeDomRect = nativeSelection.getRangeAt(0).getBoundingClientRect()\n }\n\n if (selectedNodeDomRect != null) {\n selectedNodeDomRect.y += 40\n setFloatingElemPositionForLinkEditor(selectedNodeDomRect, editorElem, anchorElem)\n }\n } else if (activeElement == null || activeElement.className !== 'link-input') {\n if (rootElement !== null) {\n setFloatingElemPositionForLinkEditor(null, editorElem, anchorElem)\n }\n setLinkUrl('')\n setLinkLabel('')\n }\n\n return true\n }, [anchorElem, editor, config, t, i18n])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerCommand(\n TOGGLE_LINK_WITH_MODAL_COMMAND,\n (payload: LinkPayload) => {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, payload)\n\n // Now, open the modal\n updateLinkEditor()\n toggleModal(drawerSlug)\n\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n )\n }, [editor, updateLinkEditor, toggleModal, drawerSlug])\n\n useEffect(() => {\n if (!isLink && editorRef) {\n editorRef.current.style.opacity = '0'\n editorRef.current.style.transform = 'translate(-10000px, -10000px)'\n }\n }, [isLink])\n\n useEffect(() => {\n const scrollerElem = anchorElem.parentElement\n\n const update = (): void => {\n editor.getEditorState().read(() => {\n void updateLinkEditor()\n })\n }\n\n window.addEventListener('resize', update)\n\n if (scrollerElem != null) {\n scrollerElem.addEventListener('scroll', update)\n }\n\n return () => {\n window.removeEventListener('resize', update)\n\n if (scrollerElem != null) {\n scrollerElem.removeEventListener('scroll', update)\n }\n }\n }, [anchorElem.parentElement, editor, updateLinkEditor])\n\n useEffect(() => {\n return mergeRegister(\n editor.registerUpdateListener(({ editorState }) => {\n editorState.read(() => {\n void updateLinkEditor()\n })\n }),\n\n editor.registerCommand(\n SELECTION_CHANGE_COMMAND,\n () => {\n void updateLinkEditor()\n return true\n },\n COMMAND_PRIORITY_LOW,\n ),\n editor.registerCommand(\n KEY_ESCAPE_COMMAND,\n () => {\n if (isLink) {\n setIsLink(false)\n setIsAutoLink(false)\n return true\n }\n return false\n },\n COMMAND_PRIORITY_HIGH,\n ),\n )\n }, [editor, updateLinkEditor, setIsLink, isLink])\n\n useEffect(() => {\n editor.getEditorState().read(() => {\n void updateLinkEditor()\n })\n }, [editor, updateLinkEditor])\n\n return (\n <React.Fragment>\n <div className=\"link-editor\" ref={editorRef}>\n <div className=\"link-input\">\n <a href={linkUrl} rel=\"noopener noreferrer\" target=\"_blank\">\n {linkLabel != null && linkLabel.length > 0 ? linkLabel : linkUrl}\n </a>\n {editor.isEditable() && (\n <React.Fragment>\n <button\n aria-label=\"Edit link\"\n className=\"link-edit\"\n onClick={() => {\n toggleModal(drawerSlug)\n }}\n onMouseDown={(event) => {\n event.preventDefault()\n }}\n tabIndex={0}\n type=\"button\"\n />\n {!isAutoLink && (\n <button\n aria-label=\"Remove link\"\n className=\"link-trash\"\n onClick={() => {\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, null)\n }}\n onMouseDown={(event) => {\n event.preventDefault()\n }}\n tabIndex={0}\n type=\"button\"\n />\n )}\n </React.Fragment>\n )}\n </div>\n </div>\n <LinkDrawer\n drawerSlug={drawerSlug}\n handleModalSubmit={(fields: FormState, data: Data) => {\n closeModal(drawerSlug)\n\n const newLinkPayload: LinkPayload = data as LinkPayload\n\n // See: https://github.com/facebook/lexical/pull/5536. This updates autolink nodes to link nodes whenever a change was made (which is good!).\n editor.update(() => {\n const selection = $getSelection()\n if ($isRangeSelection(selection)) {\n const parent = getSelectedNode(selection).getParent()\n if ($isAutoLinkNode(parent)) {\n const linkNode = $createLinkNode({\n fields: newLinkPayload.fields,\n })\n parent.replace(linkNode, true)\n }\n }\n })\n\n // Needs to happen AFTER a potential auto link => link node conversion, as otherwise, the updated text to display may be lost due to\n // it being applied to the auto link node instead of the link node.\n editor.dispatchCommand(TOGGLE_LINK_COMMAND, newLinkPayload)\n }}\n stateData={stateData}\n />\n </React.Fragment>\n )\n}\n"],"names":["facelessUIImport","lexicalComposerContextImport","useLexicalComposerContext","lexicalUtilsImport","$findMatchingParent","mergeRegister","getTranslation","lexicalImport","$getSelection","$isRangeSelection","COMMAND_PRIORITY_HIGH","COMMAND_PRIORITY_LOW","KEY_ESCAPE_COMMAND","SELECTION_CHANGE_COMMAND","formatDrawerSlug","useConfig","useEditDepth","useTranslation","React","useCallback","useEffect","useRef","useState","useEditorConfigContext","getSelectedNode","setFloatingElemPositionForLinkEditor","LinkDrawer","$isAutoLinkNode","$createLinkNode","$isLinkNode","TOGGLE_LINK_COMMAND","TOGGLE_LINK_WITH_MODAL_COMMAND","LinkEditor","anchorElem","useModal","editor","editorRef","linkUrl","setLinkUrl","linkLabel","setLinkLabel","uuid","config","i18n","t","stateData","setStateData","closeModal","toggleModal","editDepth","isLink","setIsLink","isAutoLink","setIsAutoLink","drawerSlug","slug","depth","updateLinkEditor","selection","selectedNodeDomRect","node","getElementByKey","getKey","getBoundingClientRect","linkParent","data","fields","doc","undefined","linkType","newTab","url","getFields","text","getTextContent","relationTo","value","relatedField","collections","find","coll","label","labels","singular","replace","editorElem","current","nativeSelection","window","getSelection","activeElement","document","rootElement","getRootElement","contains","anchorNode","getRangeAt","y","className","registerCommand","payload","dispatchCommand","style","opacity","transform","scrollerElem","parentElement","update","getEditorState","read","addEventListener","removeEventListener","registerUpdateListener","editorState","Fragment","div","ref","a","href","rel","target","length","isEditable","button","aria-label","onClick","onMouseDown","event","preventDefault","tabIndex","type","handleModalSubmit","newLinkPayload","parent","getParent","linkNode"],"mappings":"AAAA;AAIA,YAAYA,sBAAsB,qBAAoB;AACtD,OAAOC,kCAAkC,2CAA0C;AACnF,MAAM,EAAEC,yBAAyB,EAAE,GAAGD;AAEtC,OAAOE,wBAAwB,iBAAgB;AAC/C,MAAM,EAAEC,mBAAmB,EAAEC,aAAa,EAAE,GAAGF;AAC/C,SAASG,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,mBAAmB,UAAS;AACnC,MAAM,EACJC,aAAa,EACbC,iBAAiB,EACjBC,qBAAqB,EACrBC,oBAAoB,EACpBC,kBAAkB,EAClBC,wBAAwB,EACzB,GAAGN;AAEJ,SAASO,gBAAgB,QAAQ,iCAAgC;AACjE,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,YAAY,QAAQ,qCAAoC;AACjE,SAASC,cAAc,QAAQ,uCAAsC;AACrE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YAAYA;QACZ6E,mBAAmB,CAACjE,QAAmBD;YACrClB,WAAWO;YAEX,MAAM8E,iBAA8BnE;YAEpC,6IAA6I;YAC7I9B,OAAOwE,MAAM,CAAC;gBACZ,MAAMjD,YAAYlD;gBAClB,IAAIC,kBAAkBiD,YAAY;oBAChC,MAAM2E,SAAS7G,gBAAgBkC,WAAW4E,SAAS;oBACnD,IAAI3G,gBAAgB0G,SAAS;wBAC3B,MAAME,WAAW3G,gBAAgB;4BAC/BsC,QAAQkE,eAAelE,MAAM;wBAC/B;wBACAmE,OAAOjD,OAAO,CAACmD,UAAU;oBAC3B;gBACF;YACF;YAEA,oIAAoI;YACpI,mEAAmE;YACnEpG,OAAOkE,eAAe,CAACvE,qBAAqBsG;QAC9C;QACAvF,WAAWA;;AAInB"}
@@ -1,9 +1,9 @@
1
1
  'use client';
2
2
  import lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js';
3
3
  const { useLexicalComposerContext } = lexicalComposerContextImport;
4
- import { useListDrawer } from '@payloadcms/ui';
5
4
  import lexicalImport from 'lexical';
6
5
  const { $getNodeByKey, COMMAND_PRIORITY_EDITOR } = lexicalImport;
6
+ import { useListDrawer } from '@payloadcms/ui/elements/ListDrawer';
7
7
  import React, { useCallback, useEffect, useState } from 'react';
8
8
  import { $createRelationshipNode } from '../nodes/RelationshipNode.js';
9
9
  import { INSERT_RELATIONSHIP_COMMAND } from '../plugins/index.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/field/features/relationship/drawer/index.tsx"],"sourcesContent":["'use client'\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\nimport { useListDrawer } from '@payloadcms/ui'\nimport lexicalImport from 'lexical'\nconst { $getNodeByKey, COMMAND_PRIORITY_EDITOR } = lexicalImport\n\nimport type { LexicalEditor } from 'lexical'\n\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport { $createRelationshipNode } from '../nodes/RelationshipNode.js'\nimport { INSERT_RELATIONSHIP_COMMAND } from '../plugins/index.js'\nimport { EnabledRelationshipsCondition } from '../utils/EnabledRelationshipsCondition.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from './commands.js'\n\nconst insertRelationship = ({\n id,\n editor,\n relationTo,\n replaceNodeKey,\n}: {\n editor: LexicalEditor\n id: string\n relationTo: string\n replaceNodeKey: null | string\n}) => {\n if (!replaceNodeKey) {\n editor.dispatchCommand(INSERT_RELATIONSHIP_COMMAND, {\n relationTo,\n value: {\n id,\n },\n })\n } else {\n editor.update(() => {\n const node = $getNodeByKey(replaceNodeKey)\n if (node) {\n node.replace($createRelationshipNode({ relationTo, value: { id } }))\n }\n })\n }\n}\n\ntype Props = {\n enabledCollectionSlugs: null | string[]\n}\n\nconst RelationshipDrawerComponent: React.FC<Props> = ({ enabledCollectionSlugs }) => {\n const [editor] = useLexicalComposerContext()\n const [selectedCollectionSlug, setSelectedCollectionSlug] = useState(\n () => enabledCollectionSlugs[0],\n )\n const [replaceNodeKey, setReplaceNodeKey] = useState<null | string>(null)\n\n const [ListDrawer, ListDrawerToggler, { closeDrawer, isDrawerOpen, openDrawer }] = useListDrawer({\n collectionSlugs: enabledCollectionSlugs,\n selectedCollection: selectedCollectionSlug,\n })\n\n useEffect(() => {\n return editor.registerCommand<{\n replace: { nodeKey: string } | false\n }>(\n INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND,\n (payload) => {\n setReplaceNodeKey(payload?.replace ? payload?.replace.nodeKey : null)\n openDrawer()\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n )\n }, [editor, openDrawer])\n\n const onSelect = useCallback(\n ({ collectionSlug, docID }) => {\n insertRelationship({\n id: docID,\n editor,\n relationTo: collectionSlug,\n replaceNodeKey,\n })\n closeDrawer()\n },\n [editor, closeDrawer, replaceNodeKey],\n )\n\n useEffect(() => {\n // always reset back to first option\n // TODO: this is not working, see the ListDrawer component\n setSelectedCollectionSlug(enabledCollectionSlugs[0])\n }, [isDrawerOpen, enabledCollectionSlugs])\n\n return <ListDrawer onSelect={onSelect} />\n}\n\nexport const RelationshipDrawer = (props: Props): React.ReactNode => {\n return props?.enabledCollectionSlugs?.length > 0 ? ( // If enabledCollectionSlugs it overrides what EnabledRelationshipsCondition is doing\n <RelationshipDrawerComponent {...props} />\n ) : (\n <EnabledRelationshipsCondition {...props}>\n <RelationshipDrawerComponent {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"names":["lexicalComposerContextImport","useLexicalComposerContext","useListDrawer","lexicalImport","$getNodeByKey","COMMAND_PRIORITY_EDITOR","React","useCallback","useEffect","useState","$createRelationshipNode","INSERT_RELATIONSHIP_COMMAND","EnabledRelationshipsCondition","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","insertRelationship","id","editor","relationTo","replaceNodeKey","dispatchCommand","value","update","node","replace","RelationshipDrawerComponent","enabledCollectionSlugs","selectedCollectionSlug","setSelectedCollectionSlug","setReplaceNodeKey","ListDrawer","ListDrawerToggler","closeDrawer","isDrawerOpen","openDrawer","collectionSlugs","selectedCollection","registerCommand","payload","nodeKey","onSelect","collectionSlug","docID","RelationshipDrawer","props","length"],"mappings":"AAAA;AACA,OAAOA,kCAAkC,2CAA0C;AACnF,MAAM,EAAEC,yBAAyB,EAAE,GAAGD;AACtC,SAASE,aAAa,QAAQ,iBAAgB;AAC9C,OAAOC,mBAAmB,UAAS;AACnC,MAAM,EAAEC,aAAa,EAAEC,uBAAuB,EAAE,GAAGF;AAInD,OAAOG,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAE/D,SAASC,uBAAuB,QAAQ,+BAA8B;AACtE,SAASC,2BAA2B,QAAQ,sBAAqB;AACjE,SAASC,6BAA6B,QAAQ,4CAA2C;AACzF,SAASC,uCAAuC,QAAQ,gBAAe;AAEvE,MAAMC,qBAAqB,CAAC,EAC1BC,EAAE,EACFC,MAAM,EACNC,UAAU,EACVC,cAAc,EAMf;IACC,IAAI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6BAAgCmB,uBAEjC,oBAAC/B,+BAAkC+B,qBACjC,oBAACnB,6BAAgCmB;AAGvC,EAAC"}
1
+ {"version":3,"sources":["../../../../../src/field/features/relationship/drawer/index.tsx"],"sourcesContent":["'use client'\nimport lexicalComposerContextImport from '@lexical/react/LexicalComposerContext.js'\nconst { useLexicalComposerContext } = lexicalComposerContextImport\nimport lexicalImport from 'lexical'\nconst { $getNodeByKey, COMMAND_PRIORITY_EDITOR } = lexicalImport\n\nimport type { LexicalEditor } from 'lexical'\n\nimport { useListDrawer } from '@payloadcms/ui/elements/ListDrawer'\nimport React, { useCallback, useEffect, useState } from 'react'\n\nimport { $createRelationshipNode } from '../nodes/RelationshipNode.js'\nimport { INSERT_RELATIONSHIP_COMMAND } from '../plugins/index.js'\nimport { EnabledRelationshipsCondition } from '../utils/EnabledRelationshipsCondition.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from './commands.js'\n\nconst insertRelationship = ({\n id,\n editor,\n relationTo,\n replaceNodeKey,\n}: {\n editor: LexicalEditor\n id: string\n relationTo: string\n replaceNodeKey: null | string\n}) => {\n if (!replaceNodeKey) {\n editor.dispatchCommand(INSERT_RELATIONSHIP_COMMAND, {\n relationTo,\n value: {\n id,\n },\n })\n } else {\n editor.update(() => {\n const node = $getNodeByKey(replaceNodeKey)\n if (node) {\n node.replace($createRelationshipNode({ relationTo, value: { id } }))\n }\n })\n }\n}\n\ntype Props = {\n enabledCollectionSlugs: null | string[]\n}\n\nconst RelationshipDrawerComponent: React.FC<Props> = ({ enabledCollectionSlugs }) => {\n const [editor] = useLexicalComposerContext()\n const [selectedCollectionSlug, setSelectedCollectionSlug] = useState(\n () => enabledCollectionSlugs[0],\n )\n const [replaceNodeKey, setReplaceNodeKey] = useState<null | string>(null)\n\n const [ListDrawer, ListDrawerToggler, { closeDrawer, isDrawerOpen, openDrawer }] = useListDrawer({\n collectionSlugs: enabledCollectionSlugs,\n selectedCollection: selectedCollectionSlug,\n })\n\n useEffect(() => {\n return editor.registerCommand<{\n replace: { nodeKey: string } | false\n }>(\n INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND,\n (payload) => {\n setReplaceNodeKey(payload?.replace ? payload?.replace.nodeKey : null)\n openDrawer()\n return true\n },\n COMMAND_PRIORITY_EDITOR,\n )\n }, [editor, openDrawer])\n\n const onSelect = useCallback(\n ({ collectionSlug, docID }) => {\n insertRelationship({\n id: docID,\n editor,\n relationTo: collectionSlug,\n replaceNodeKey,\n })\n closeDrawer()\n },\n [editor, closeDrawer, replaceNodeKey],\n )\n\n useEffect(() => {\n // always reset back to first option\n // TODO: this is not working, see the ListDrawer component\n setSelectedCollectionSlug(enabledCollectionSlugs[0])\n }, [isDrawerOpen, enabledCollectionSlugs])\n\n return <ListDrawer onSelect={onSelect} />\n}\n\nexport const RelationshipDrawer = (props: Props): React.ReactNode => {\n return props?.enabledCollectionSlugs?.length > 0 ? ( // If enabledCollectionSlugs it overrides what EnabledRelationshipsCondition is doing\n <RelationshipDrawerComponent {...props} />\n ) : (\n <EnabledRelationshipsCondition {...props}>\n <RelationshipDrawerComponent {...props} />\n </EnabledRelationshipsCondition>\n )\n}\n"],"names":["lexicalComposerContextImport","useLexicalComposerContext","lexicalImport","$getNodeByKey","COMMAND_PRIORITY_EDITOR","useListDrawer","React","useCallback","useEffect","useState","$createRelationshipNode","INSERT_RELATIONSHIP_COMMAND","EnabledRelationshipsCondition","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","insertRelationship","id","editor","relationTo","replaceNodeKey","dispatchCommand","value","update","node","replace","RelationshipDrawerComponent","enabledCollectionSlugs","selectedCollectionSlug","setSelectedCollectionSlug","setReplaceNodeKey","ListDrawer","ListDrawerToggler","closeDrawer","isDrawerOpen","openDrawer","collectionSlugs","selectedCollection","registerCommand","payload","nodeKey","onSelect","collectionSlug","docID","RelationshipDrawer","props","length"],"mappings":"AAAA;AACA,OAAOA,kCAAkC,2CAA0C;AACnF,MAAM,EAAEC,yBAAyB,EAAE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KAAW;IAEvB,MAAMM,WAAWhC,YACf,CAAC,EAAEiC,cAAc,EAAEC,KAAK,EAAE;QACxB3B,mBAAmB;YACjBC,IAAI0B;YACJzB;YACAC,YAAYuB;YACZtB;QACF;QACAa;IACF,GACA;QAACf;QAAQe;QAAab;KAAe;IAGvCV,UAAU;QACR,oCAAoC;QACpC,0DAA0D;QAC1DmB,0BAA0BF,sBAAsB,CAAC,EAAE;IACrD,GAAG;QAACO;QAAcP;KAAuB;IAEzC,qBAAO,oBAACI;QAAWU,UAAUA;;AAC/B;AAEA,OAAO,MAAMG,qBAAqB,CAACC;IACjC,OAAOA,OAAOlB,wBAAwBmB,SAAS,kBAC7C,oBAACpB,6BAAgCmB,uBAEjC,oBAAC/B,+BAAkC+B,qBACjC,oBAACnB,6BAAgCmB;AAGvC,EAAC"}
@@ -1,5 +1,5 @@
1
1
  'use client';
2
- import { withMergedProps } from '@payloadcms/ui';
2
+ import { withMergedProps } from '@payloadcms/ui/elements/withMergedProps';
3
3
  import { SlashMenuOption } from '../../lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js';
4
4
  import { RelationshipIcon } from '../../lexical/ui/icons/Relationship/index.js';
5
5
  import { createClientComponent } from '../createClientComponent.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/field/features/relationship/feature.client.tsx"],"sourcesContent":["'use client'\n\nimport { withMergedProps } from '@payloadcms/ui'\n\nimport type { FeatureProviderProviderClient } from '../types.js'\nimport type { RelationshipFeatureProps } from './feature.server.js'\n\nimport { SlashMenuOption } from '../../lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js'\nimport { RelationshipIcon } from '../../lexical/ui/icons/Relationship/index.js'\nimport { createClientComponent } from '../createClientComponent.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from './drawer/commands.js'\nimport { RelationshipNode } from './nodes/RelationshipNode.js'\nimport { RelationshipPlugin } from './plugins/index.js'\n\nconst RelationshipFeatureClient: FeatureProviderProviderClient<RelationshipFeatureProps> = (\n props,\n) => {\n return {\n clientFeatureProps: props,\n feature: () => ({\n clientFeatureProps: props,\n nodes: [RelationshipNode],\n plugins: [\n {\n Component: withMergedProps({\n Component: RelationshipPlugin,\n toMergeIntoProps: props,\n }),\n position: 'normal',\n },\n ],\n slashMenu: {\n options: [\n {\n displayName: 'Basic',\n key: 'basic',\n options: [\n new SlashMenuOption('relationship', {\n Icon: RelationshipIcon,\n displayName: 'Relationship',\n keywords: ['relationship', 'relation', 'rel'],\n onSelect: ({ editor }) => {\n // dispatch INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND\n editor.dispatchCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, {\n replace: false,\n })\n },\n }),\n ],\n },\n ],\n },\n }),\n }\n}\n\nexport const RelationshipFeatureClientComponent = createClientComponent(RelationshipFeatureClient)\n"],"names":["withMergedProps","SlashMenuOption","RelationshipIcon","createClientComponent","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","RelationshipNode","RelationshipPlugin","RelationshipFeatureClient","props","clientFeatureProps","feature","nodes","plugins","Component","toMergeIntoProps","position","slashMenu","options","displayName","key","Icon","keywords","onSelect","editor","dispatchCommand","replace","RelationshipFeatureClientComponent"],"mappings":"AAAA;AAEA,SAASA,eAAe,QAAQ,iBAAgB;AAKhD,SAASC,eAAe,QAAQ,sEAAqE;AACrG,SAASC,gBAAgB,QAAQ,+CAA8C;AAC/E,SAASC,qBAAqB,QAAQ,8BAA6B;AACnE,SAASC,uCAAuC,QAAQ,uBAAsB;AAC9E,SAASC,gBAAgB,QAAQ,8BAA6B;AAC9D,SAASC,kBAAkB,QAAQ,qBAAoB;AAEvD,MAAMC,4BAAqF,CACzFC;IAEA,OAAO;QACLC,oBAAoBD;QACpBE,SAAS,IAAO,CAAA;gBACdD,oBAAoBD;gBACpBG,OAAO;oBAACN;iBAAiB;gBACzBO,SAAS;oBACP;wBACEC,WAAWb,gBAAgB;4BACzBa,WAAWP;4BACXQ,kBAAkBN;wBACpB;wBACAO,UAAU;oBACZ;iBACD;gBACDC,WAAW;oBACTC,SAAS;wBACP;4BACEC,aAAa;4BACbC,KAAK;4BACLF,SAAS;gCACP,IAAIhB,gBAAgB,gBAAgB;oCAClCmB,MAAMlB;oCACNgB,aAAa;oCACbG,UAAU;wCAAC;wCAAgB;wCAAY;qCAAM;oCAC7CC,UAAU,CAAC,EAAEC,MAAM,EAAE;wCACnB,mDAAmD;wCACnDA,OAAOC,eAAe,CAACpB,yCAAyC;4CAC9DqB,SAAS;wCACX;oCACF;gCACF;6BACD;wBACH;qBACD;gBACH;YACF,CAAA;IACF;AACF;AAEA,OAAO,MAAMC,qCAAqCvB,sBAAsBI,2BAA0B"}
1
+ {"version":3,"sources":["../../../../src/field/features/relationship/feature.client.tsx"],"sourcesContent":["'use client'\n\nimport { withMergedProps } from '@payloadcms/ui/elements/withMergedProps'\n\nimport type { FeatureProviderProviderClient } from '../types.js'\nimport type { RelationshipFeatureProps } from './feature.server.js'\n\nimport { SlashMenuOption } from '../../lexical/plugins/SlashMenu/LexicalTypeaheadMenuPlugin/types.js'\nimport { RelationshipIcon } from '../../lexical/ui/icons/Relationship/index.js'\nimport { createClientComponent } from '../createClientComponent.js'\nimport { INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND } from './drawer/commands.js'\nimport { RelationshipNode } from './nodes/RelationshipNode.js'\nimport { RelationshipPlugin } from './plugins/index.js'\n\nconst RelationshipFeatureClient: FeatureProviderProviderClient<RelationshipFeatureProps> = (\n props,\n) => {\n return {\n clientFeatureProps: props,\n feature: () => ({\n clientFeatureProps: props,\n nodes: [RelationshipNode],\n plugins: [\n {\n Component: withMergedProps({\n Component: RelationshipPlugin,\n toMergeIntoProps: props,\n }),\n position: 'normal',\n },\n ],\n slashMenu: {\n options: [\n {\n displayName: 'Basic',\n key: 'basic',\n options: [\n new SlashMenuOption('relationship', {\n Icon: RelationshipIcon,\n displayName: 'Relationship',\n keywords: ['relationship', 'relation', 'rel'],\n onSelect: ({ editor }) => {\n // dispatch INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND\n editor.dispatchCommand(INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND, {\n replace: false,\n })\n },\n }),\n ],\n },\n ],\n },\n }),\n }\n}\n\nexport const RelationshipFeatureClientComponent = createClientComponent(RelationshipFeatureClient)\n"],"names":["withMergedProps","SlashMenuOption","RelationshipIcon","createClientComponent","INSERT_RELATIONSHIP_WITH_DRAWER_COMMAND","RelationshipNode","RelationshipPlugin","RelationshipFeatureClient","props","clientFeatureProps","feature","nodes","plugins","Component","toMergeIntoProps","position","slashMenu","options","displayName","key","Icon","keywords","onSelect","editor","dispatchCommand","replace","RelationshipFeatureClientComponent"],"mappings":"AAAA;AAEA,SAASA,eAAe,QAAQ,0CAAyC;AAKzE,SAASC,eAAe,QAAQ,sEAAqE;AACrG,SAASC,gBAAgB,QAAQ,+CAA8C;AAC/E,SAASC,qBAAqB,QAAQ,8BAA6B;AACnE,SAASC,uCAAuC,QAAQ,uBAAsB;AAC9E,SAASC,gBAAgB,QAAQ,8BAA6B;AAC9D,SAASC,kBAAkB,QAAQ,qBAAoB;AAEvD,MAAMC,4BAAqF,CACzFC;IAEA,OAAO;QACLC,oBAAoBD;QACpBE,SAAS,IAAO,CAAA;gBACdD,oBAAoBD;gBACpBG,OAAO;oBAACN;iBAAiB;gBACzBO,SAAS;oBACP;wBACEC,WAAWb,gBAAgB;4BACzBa,WAAWP;4BACXQ,kBAAkBN;wBACpB;wBACAO,UAAU;oBACZ;iBACD;gBACDC,WAAW;oBACTC,SAAS;wBACP;4BACEC,aAAa;4BACbC,KAAK;4BACLF,SAAS;gCACP,IAAIhB,gBAAgB,gBAAgB;oCAClCmB,MAAMlB;oCACNgB,aAAa;oCACbG,UAAU;wCAAC;wCAAgB;wCAAY;qCAAM;oCAC7CC,UAAU,CAAC,EAAEC,MAAM,EAAE;wCACnB,mDAAmD;wCACnDA,OAAOC,eAAe,CAACpB,yCAAyC;4CAC9DqB,SAAS;wCACX;oCACF;gCACF;6BACD;wBACH;qBACD;gBACH;YACF,CAAA;IACF;AACF;AAEA,OAAO,MAAMC,qCAAqCvB,sBAAsBI,2BAA0B"}
@@ -1 +1 @@
1
- {"version":3,"file":"RelationshipComponent.d.ts","sourceRoot":"","sources":["../../../../../../src/field/features/relationship/nodes/components/RelationshipComponent.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAEhD,OAAO,KAA4C,MAAM,OAAO,CAAA;AAEhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAI9D,OAAO,cAAc,CAAA;AAQrB,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,gBAAgB,CAAA;IACtB,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AA8GD,eAAO,MAAM,qBAAqB,UAAW,KAAK,KAAG,MAAM,SAE1D,CAAA"}
1
+ {"version":3,"file":"RelationshipComponent.d.ts","sourceRoot":"","sources":["../../../../../../src/field/features/relationship/nodes/components/RelationshipComponent.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAOhD,OAAO,KAA4C,MAAM,OAAO,CAAA;AAEhE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAI9D,OAAO,cAAc,CAAA;AAQrB,KAAK,KAAK,GAAG;IACX,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,gBAAgB,CAAA;IACtB,MAAM,CAAC,EAAE,iBAAiB,CAAA;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AA8GD,eAAO,MAAM,qBAAqB,UAAW,KAAK,KAAG,MAAM,SAE1D,CAAA"}