@portabletext/editor 1.43.0 → 1.44.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/behavior.markdown.cjs +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +445 -623
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/parse-blocks.cjs +151 -0
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -0
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs +2 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-cjs/{selector.is-active-style.cjs → selector.is-selecting-entire-blocks.cjs} +47 -11
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -0
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs +3 -3
- package/lib/_chunks-cjs/util.merge-text-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs +0 -149
- package/lib/_chunks-cjs/util.selection-point-to-block-offset.cjs.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js +1 -1
- package/lib/_chunks-es/editor-provider.js +434 -611
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/parse-blocks.js +152 -0
- package/lib/_chunks-es/parse-blocks.js.map +1 -0
- package/lib/_chunks-es/selector.is-overlapping-selection.js +2 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/_chunks-es/{selector.is-active-style.js → selector.is-selecting-entire-blocks.js} +49 -12
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -0
- package/lib/_chunks-es/util.merge-text-blocks.js +1 -1
- package/lib/_chunks-es/util.selection-point-to-block-offset.js +0 -149
- package/lib/_chunks-es/util.selection-point-to-block-offset.js.map +1 -1
- package/lib/behaviors/index.d.cts +1860 -5464
- package/lib/behaviors/index.d.ts +1860 -5464
- package/lib/index.cjs +4 -4
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +1529 -5062
- package/lib/index.d.ts +1529 -5062
- package/lib/index.js +3 -3
- package/lib/plugins/index.cjs +1 -1
- package/lib/plugins/index.d.cts +1529 -5062
- package/lib/plugins/index.d.ts +1529 -5062
- package/lib/plugins/index.js +1 -1
- package/lib/selectors/index.cjs +12 -11
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +1508 -5064
- package/lib/selectors/index.d.ts +1508 -5064
- package/lib/selectors/index.js +2 -1
- package/lib/utils/index.d.cts +1491 -5057
- package/lib/utils/index.d.ts +1491 -5057
- package/package.json +1 -1
- package/src/behavior-actions/behavior.actions.ts +1 -131
- package/src/behaviors/behavior.default.ts +47 -50
- package/src/behaviors/behavior.internal.insert.ts +118 -0
- package/src/behaviors/behavior.internal.list-item.ts +61 -0
- package/src/behaviors/behavior.internal.select.ts +62 -0
- package/src/behaviors/behavior.internal.style.ts +54 -0
- package/src/behaviors/behavior.perform-event.ts +15 -13
- package/src/behaviors/behavior.types.event.ts +143 -100
- package/src/editor/create-editor.ts +2 -2
- package/src/editor/editor-machine.ts +3 -4
- package/src/editor/plugins/createWithEditableAPI.ts +1 -2
- package/src/editor/sync-machine.ts +1 -1
- package/src/internal-utils/slate-utils.ts +52 -0
- package/src/plugins/plugin.internal.editor-actor-ref.tsx +15 -0
- package/src/plugins/plugin.internal.slate-editor-ref.tsx +15 -0
- package/src/selectors/index.ts +2 -1
- package/src/selectors/selector.get-selected-text-blocks.ts +67 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
- package/src/behavior-actions/behavior.action.data-transfer-set.ts +0 -7
- package/src/behavior-actions/behavior.action.deserialization.failure.ts +0 -9
- package/src/behavior-actions/behavior.action.deserialization.success.ts +0 -16
- package/src/behavior-actions/behavior.action.insert-blocks.ts +0 -140
- package/src/behavior-actions/behavior.action.list-item.ts +0 -100
- package/src/behavior-actions/behavior.action.select.next-block.ts +0 -44
- package/src/behavior-actions/behavior.action.select.previous-block.ts +0 -48
- package/src/behavior-actions/behavior.action.serialization.failure.ts +0 -9
- package/src/behavior-actions/behavior.action.serialization.success.ts +0 -17
- package/src/behavior-actions/behavior.action.style.ts +0 -108
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"selector.is-active-style.cjs","sources":["../../src/selectors/selector.is-selecting-entire-blocks.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-trimmed-selection.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {getSelectionEndBlock, getSelectionStartBlock} from './selectors'\n\n/**\n * @public\n */\nexport const isSelectingEntireBlocks: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n const endPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n\n const startBlock = getSelectionStartBlock(snapshot)\n const endBlock = getSelectionEndBlock(snapshot)\n\n if (!startBlock || !endBlock) {\n return false\n }\n\n const startBlockStartPoint = utils.getBlockStartPoint(startBlock)\n const endBlockEndPoint = utils.getBlockEndPoint(endBlock)\n\n return (\n utils.isEqualSelectionPoints(startBlockStartPoint, startPoint) &&\n utils.isEqualSelectionPoints(endBlockEndPoint, endPoint)\n )\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }> = []\n\n const startPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n const endPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n\n const startBlockKey = isKeySegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeySegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startSpanKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endSpanKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n let startBlockFound = false\n\n for (const block of snapshot.context.value) {\n if (block._key === startBlockKey) {\n startBlockFound = true\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n if (startPoint.offset < child.text.length) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n if (endPoint.offset > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n if (endPoint.offset > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (startBlockFound) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import {isPortableTextTextBlock, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {getFocusSpan, getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n const focusSpan = getFocusSpan(snapshot)\n\n if (selectedSpans.length === 0 || !focusSpan) {\n return []\n }\n\n if (selectedSpans.length === 1 && isSelectionCollapsed(snapshot)) {\n if (snapshot.context.selection.focus.offset === 0) {\n return []\n }\n if (\n snapshot.context.selection.focus.offset === focusSpan.node.text.length\n ) {\n return []\n }\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n selectedSpans.some((span) => span.node.marks?.includes(markDef._key)),\n )\n}\n","import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const guards = createGuards(snapshot.context)\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const guards = createGuards(snapshot.context)\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection, EditorSelectionPoint} from '../types/editor'\nimport {isEmptyTextBlock, isKeyedSegment} from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getTrimmedSelection: EditorSelector<EditorSelection> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return snapshot.context.selection\n }\n\n const startPoint = getSelectionStartPoint(snapshot)\n const endPoint = getSelectionEndPoint(snapshot)\n\n if (!startPoint || !endPoint) {\n return snapshot.context.selection\n }\n\n const startBlockKey = isKeyedSegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : null\n const startChildKey = isKeyedSegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : null\n const endBlockKey = isKeyedSegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : null\n const endChildKey = isKeyedSegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : null\n\n if (!startBlockKey || !endBlockKey) {\n return snapshot.context.selection\n }\n\n let startBlockFound = false\n let adjustedStartPoint: EditorSelectionPoint | undefined\n let trimStartPoint = false\n let adjustedEndPoint: EditorSelectionPoint | undefined\n let trimEndPoint = false\n let previousPotentialEndpoint:\n | {blockKey: string; span: PortableTextSpan}\n | undefined\n\n for (const block of snapshot.context.value) {\n if (block._key === startBlockKey) {\n startBlockFound = true\n\n if (isPortableTextTextBlock(block) && isEmptyTextBlock(block)) {\n continue\n }\n }\n\n if (!startBlockFound) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === endBlockKey && isEmptyTextBlock(block)) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (!isPortableTextSpan(child) || endPoint.offset === 0) {\n adjustedEndPoint = previousPotentialEndpoint\n ? {\n path: [\n {_key: previousPotentialEndpoint.blockKey},\n 'children',\n {_key: previousPotentialEndpoint.span._key},\n ],\n offset: previousPotentialEndpoint.span.text.length,\n }\n : undefined\n\n trimEndPoint = true\n break\n }\n }\n\n if (trimStartPoint) {\n const lonelySpan =\n isPortableTextSpan(child) && block.children.length === 1\n\n if (\n (isPortableTextSpan(child) && child.text.length > 0) ||\n lonelySpan\n ) {\n adjustedStartPoint = {\n path: [{_key: block._key}, 'children', {_key: child._key}],\n offset: 0,\n }\n previousPotentialEndpoint = {blockKey: block._key, span: child}\n trimStartPoint = false\n }\n\n continue\n }\n\n if (child._key === startChildKey) {\n if (!isPortableTextSpan(child)) {\n trimStartPoint = true\n continue\n }\n\n if (startPoint.offset === child.text.length) {\n trimStartPoint = true\n previousPotentialEndpoint =\n child.text.length > 0\n ? {blockKey: block._key, span: child}\n : previousPotentialEndpoint\n continue\n }\n }\n\n previousPotentialEndpoint =\n isPortableTextSpan(child) && child.text.length > 0\n ? {blockKey: block._key, span: child}\n : previousPotentialEndpoint\n }\n\n if (block._key === endBlockKey) {\n break\n }\n }\n\n const trimmedSelection = snapshot.context.selection.backward\n ? {\n anchor: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,\n focus: adjustedStartPoint ?? startPoint,\n backward: true,\n }\n : {\n anchor: adjustedStartPoint ?? startPoint,\n focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,\n }\n\n if (\n isSelectionCollapsed({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: trimmedSelection,\n },\n })\n ) {\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: trimmedSelection,\n },\n })\n\n if (focusTextBlock && !isEmptyTextBlock(focusTextBlock.node)) {\n return null\n }\n }\n\n return trimmedSelection\n}\n","import {isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\nimport {getFocusSpan, getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport function isActiveAnnotation(\n annotation: string,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const focusSpan = getFocusSpan(snapshot)\n\n const selectedSpans = isSelectionExpanded(snapshot)\n ? getSelectedSpans(snapshot)\n : focusSpan\n ? [focusSpan]\n : []\n\n if (selectedSpans.length === 0) {\n return false\n }\n\n if (\n selectedSpans.some(\n (span) => !span.node.marks || span.node.marks?.length === 0,\n )\n ) {\n return false\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectedSpans.every((span) => {\n const spanMarkDefs =\n span.node.marks?.flatMap((mark) => {\n const markDef = selectionMarkDefs.find(\n (markDef) => markDef._key === mark,\n )\n\n return markDef ? [markDef._type] : []\n }) ?? []\n\n return spanMarkDefs.includes(annotation)\n })\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n return snapshot.context.activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n"],"names":["isSelectingEntireBlocks","snapshot","context","selection","startPoint","backward","focus","anchor","endPoint","startBlock","getSelectionStartBlock","endBlock","getSelectionEndBlock","startBlockStartPoint","utils","endBlockEndPoint","isEqualSelectionPoints","getSelectedSpans","selectedSpans","startBlockKey","isKeySegment","path","_key","undefined","endBlockKey","startSpanKey","endSpanKey","startBlockFound","block","value","isPortableTextTextBlock","child","children","isPortableTextSpan","offset","text","length","push","node","getActiveAnnotations","selectedBlocks","getSelectedBlocks","focusSpan","getFocusSpan","isSelectionCollapsed","flatMap","markDefs","filter","markDef","some","span","marks","includes","getActiveListItem","guards","createGuards","selectedTextBlocks","map","isTextBlock","firstTextBlock","at","firstListItem","listItem","every","getActiveStyle","firstStyle","style","getTrimmedSelection","getSelectionStartPoint","getSelectionEndPoint","isKeyedSegment","startChildKey","endChildKey","adjustedStartPoint","trimStartPoint","adjustedEndPoint","trimEndPoint","previousPotentialEndpoint","isEmptyTextBlock","blockKey","lonelySpan","trimmedSelection","focusTextBlock","getFocusTextBlock","isActiveAnnotation","annotation","isSelectionExpanded","selectionMarkDefs","mark","find","_type","isActiveDecorator","decorator","activeDecorators","isActiveListItem","isActiveStyle"],"mappings":";;AAOO,MAAMA,0BAAoDC,CAAa,aAAA;AACxE,MAAA,CAACA,SAASC,QAAQC;AACb,WAAA;AAGT,QAAMC,aAAaH,SAASC,QAAQC,UAAUE,WAC1CJ,SAASC,QAAQC,UAAUG,QAC3BL,SAASC,QAAQC,UAAUI,QACzBC,WAAWP,SAASC,QAAQC,UAAUE,WACxCJ,SAASC,QAAQC,UAAUI,SAC3BN,SAASC,QAAQC,UAAUG,OAEzBG,aAAaC,uDAAuBT,QAAQ,GAC5CU,WAAWC,qDAAqBX,QAAQ;AAE1C,MAAA,CAACQ,cAAc,CAACE;AACX,WAAA;AAGHE,QAAAA,uBAAuBC,iBAAAA,mBAAyBL,UAAU,GAC1DM,mBAAmBD,kCAAuBH,QAAQ;AAGtDG,SAAAA,iBAAAA,uBAA6BD,sBAAsBT,UAAU,KAC7DU,iBAAME,uBAAuBD,kBAAkBP,QAAQ;AAE3D,GCrBaS,mBAKRhB,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGLe,QAAAA,gBAGD,CAAA,GAECd,aAAaH,SAASC,QAAQC,UAAUE,WAC1CJ,SAASC,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-style.js","sources":["../../src/selectors/selector.is-selecting-entire-blocks.ts","../../src/selectors/selector.get-selected-spans.ts","../../src/selectors/selector.get-active-annotations.ts","../../src/selectors/selector.get-active-list-item.ts","../../src/selectors/selector.get-active-style.ts","../../src/selectors/selector.get-trimmed-selection.ts","../../src/selectors/selector.is-active-annotation.ts","../../src/selectors/selector.is-active-decorator.ts","../../src/selectors/selector.is-active-list-item.ts","../../src/selectors/selector.is-active-style.ts"],"sourcesContent":["import type {EditorSelector} from '../editor/editor-selector'\nimport * as utils from '../utils'\nimport {getSelectionEndBlock, getSelectionStartBlock} from './selectors'\n\n/**\n * @public\n */\nexport const isSelectingEntireBlocks: EditorSelector<boolean> = (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const startPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n const endPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n\n const startBlock = getSelectionStartBlock(snapshot)\n const endBlock = getSelectionEndBlock(snapshot)\n\n if (!startBlock || !endBlock) {\n return false\n }\n\n const startBlockStartPoint = utils.getBlockStartPoint(startBlock)\n const endBlockEndPoint = utils.getBlockEndPoint(endBlock)\n\n return (\n utils.isEqualSelectionPoints(startBlockStartPoint, startPoint) &&\n utils.isEqualSelectionPoints(endBlockEndPoint, endPoint)\n )\n}\n","import {\n isKeySegment,\n isPortableTextSpan,\n isPortableTextTextBlock,\n type KeyedSegment,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\n\n/**\n * @public\n */\nexport const getSelectedSpans: EditorSelector<\n Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }>\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedSpans: Array<{\n node: PortableTextSpan\n path: [KeyedSegment, 'children', KeyedSegment]\n }> = []\n\n const startPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.focus\n : snapshot.context.selection.anchor\n const endPoint = snapshot.context.selection.backward\n ? snapshot.context.selection.anchor\n : snapshot.context.selection.focus\n\n const startBlockKey = isKeySegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : undefined\n const endBlockKey = isKeySegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : undefined\n\n if (!startBlockKey || !endBlockKey) {\n return selectedSpans\n }\n\n const startSpanKey = isKeySegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : undefined\n const endSpanKey = isKeySegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : undefined\n\n let startBlockFound = false\n\n for (const block of snapshot.context.value) {\n if (block._key === startBlockKey) {\n startBlockFound = true\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === startBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (startSpanKey && child._key === startSpanKey) {\n if (startPoint.offset < child.text.length) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n if (startSpanKey === endSpanKey) {\n break\n }\n\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n if (endPoint.offset > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n break\n }\n\n if (selectedSpans.length > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n\n if (startBlockKey === endBlockKey) {\n break\n }\n\n continue\n }\n\n if (block._key === endBlockKey) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n if (endSpanKey && child._key === endSpanKey) {\n if (endPoint.offset > 0) {\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n break\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n\n break\n }\n\n if (startBlockFound) {\n for (const child of block.children) {\n if (!isPortableTextSpan(child)) {\n continue\n }\n\n selectedSpans.push({\n node: child,\n path: [{_key: block._key}, 'children', {_key: child._key}],\n })\n }\n }\n }\n\n return selectedSpans\n}\n","import {isPortableTextTextBlock, type PortableTextObject} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {getFocusSpan, getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveAnnotations: EditorSelector<Array<PortableTextObject>> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return []\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const selectedSpans = getSelectedSpans(snapshot)\n const focusSpan = getFocusSpan(snapshot)\n\n if (selectedSpans.length === 0 || !focusSpan) {\n return []\n }\n\n if (selectedSpans.length === 1 && isSelectionCollapsed(snapshot)) {\n if (snapshot.context.selection.focus.offset === 0) {\n return []\n }\n if (\n snapshot.context.selection.focus.offset === focusSpan.node.text.length\n ) {\n return []\n }\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectionMarkDefs.filter((markDef) =>\n selectedSpans.some((span) => span.node.marks?.includes(markDef._key)),\n )\n}\n","import type {PortableTextListBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveListItem: EditorSelector<\n PortableTextListBlock['listItem'] | undefined\n> = (snapshot) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const guards = createGuards(snapshot.context)\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstListItem = firstTextBlock.listItem\n\n if (!firstListItem) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.listItem === firstListItem)) {\n return firstListItem\n }\n\n return undefined\n}\n","import type {PortableTextTextBlock} from '@sanity/types'\nimport {createGuards} from '../behavior-actions/behavior.guards'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport const getActiveStyle: EditorSelector<PortableTextTextBlock['style']> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return undefined\n }\n\n const guards = createGuards(snapshot.context)\n const selectedBlocks = getSelectedBlocks(snapshot).map((block) => block.node)\n const selectedTextBlocks = selectedBlocks.filter(guards.isTextBlock)\n\n const firstTextBlock = selectedTextBlocks.at(0)\n\n if (!firstTextBlock) {\n return undefined\n }\n\n const firstStyle = firstTextBlock.style\n\n if (!firstStyle) {\n return undefined\n }\n\n if (selectedTextBlocks.every((block) => block.style === firstStyle)) {\n return firstStyle\n }\n\n return undefined\n}\n","import {\n isPortableTextSpan,\n isPortableTextTextBlock,\n type PortableTextSpan,\n} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport type {EditorSelection, EditorSelectionPoint} from '../types/editor'\nimport {isEmptyTextBlock, isKeyedSegment} from '../utils'\nimport {getSelectionEndPoint} from './selector.get-selection-end-point'\nimport {getSelectionStartPoint} from './selector.get-selection-start-point'\nimport {isSelectionCollapsed} from './selector.is-selection-collapsed'\nimport {getFocusTextBlock} from './selectors'\n\n/**\n * @public\n */\nexport const getTrimmedSelection: EditorSelector<EditorSelection> = (\n snapshot,\n) => {\n if (!snapshot.context.selection) {\n return snapshot.context.selection\n }\n\n const startPoint = getSelectionStartPoint(snapshot)\n const endPoint = getSelectionEndPoint(snapshot)\n\n if (!startPoint || !endPoint) {\n return snapshot.context.selection\n }\n\n const startBlockKey = isKeyedSegment(startPoint.path[0])\n ? startPoint.path[0]._key\n : null\n const startChildKey = isKeyedSegment(startPoint.path[2])\n ? startPoint.path[2]._key\n : null\n const endBlockKey = isKeyedSegment(endPoint.path[0])\n ? endPoint.path[0]._key\n : null\n const endChildKey = isKeyedSegment(endPoint.path[2])\n ? endPoint.path[2]._key\n : null\n\n if (!startBlockKey || !endBlockKey) {\n return snapshot.context.selection\n }\n\n let startBlockFound = false\n let adjustedStartPoint: EditorSelectionPoint | undefined\n let trimStartPoint = false\n let adjustedEndPoint: EditorSelectionPoint | undefined\n let trimEndPoint = false\n let previousPotentialEndpoint:\n | {blockKey: string; span: PortableTextSpan}\n | undefined\n\n for (const block of snapshot.context.value) {\n if (block._key === startBlockKey) {\n startBlockFound = true\n\n if (isPortableTextTextBlock(block) && isEmptyTextBlock(block)) {\n continue\n }\n }\n\n if (!startBlockFound) {\n continue\n }\n\n if (!isPortableTextTextBlock(block)) {\n continue\n }\n\n if (block._key === endBlockKey && isEmptyTextBlock(block)) {\n break\n }\n\n for (const child of block.children) {\n if (child._key === endChildKey) {\n if (!isPortableTextSpan(child) || endPoint.offset === 0) {\n adjustedEndPoint = previousPotentialEndpoint\n ? {\n path: [\n {_key: previousPotentialEndpoint.blockKey},\n 'children',\n {_key: previousPotentialEndpoint.span._key},\n ],\n offset: previousPotentialEndpoint.span.text.length,\n }\n : undefined\n\n trimEndPoint = true\n break\n }\n }\n\n if (trimStartPoint) {\n const lonelySpan =\n isPortableTextSpan(child) && block.children.length === 1\n\n if (\n (isPortableTextSpan(child) && child.text.length > 0) ||\n lonelySpan\n ) {\n adjustedStartPoint = {\n path: [{_key: block._key}, 'children', {_key: child._key}],\n offset: 0,\n }\n previousPotentialEndpoint = {blockKey: block._key, span: child}\n trimStartPoint = false\n }\n\n continue\n }\n\n if (child._key === startChildKey) {\n if (!isPortableTextSpan(child)) {\n trimStartPoint = true\n continue\n }\n\n if (startPoint.offset === child.text.length) {\n trimStartPoint = true\n previousPotentialEndpoint =\n child.text.length > 0\n ? {blockKey: block._key, span: child}\n : previousPotentialEndpoint\n continue\n }\n }\n\n previousPotentialEndpoint =\n isPortableTextSpan(child) && child.text.length > 0\n ? {blockKey: block._key, span: child}\n : previousPotentialEndpoint\n }\n\n if (block._key === endBlockKey) {\n break\n }\n }\n\n const trimmedSelection = snapshot.context.selection.backward\n ? {\n anchor: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,\n focus: adjustedStartPoint ?? startPoint,\n backward: true,\n }\n : {\n anchor: adjustedStartPoint ?? startPoint,\n focus: trimEndPoint && adjustedEndPoint ? adjustedEndPoint : endPoint,\n }\n\n if (\n isSelectionCollapsed({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: trimmedSelection,\n },\n })\n ) {\n const focusTextBlock = getFocusTextBlock({\n ...snapshot,\n context: {\n ...snapshot.context,\n selection: trimmedSelection,\n },\n })\n\n if (focusTextBlock && !isEmptyTextBlock(focusTextBlock.node)) {\n return null\n }\n }\n\n return trimmedSelection\n}\n","import {isPortableTextTextBlock} from '@sanity/types'\nimport type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\nimport {getFocusSpan, getSelectedBlocks} from './selectors'\n\n/**\n * @public\n */\nexport function isActiveAnnotation(\n annotation: string,\n): EditorSelector<boolean> {\n return (snapshot) => {\n if (!snapshot.context.selection) {\n return false\n }\n\n const selectedBlocks = getSelectedBlocks(snapshot)\n const focusSpan = getFocusSpan(snapshot)\n\n const selectedSpans = isSelectionExpanded(snapshot)\n ? getSelectedSpans(snapshot)\n : focusSpan\n ? [focusSpan]\n : []\n\n if (selectedSpans.length === 0) {\n return false\n }\n\n if (\n selectedSpans.some(\n (span) => !span.node.marks || span.node.marks?.length === 0,\n )\n ) {\n return false\n }\n\n const selectionMarkDefs = selectedBlocks.flatMap((block) =>\n isPortableTextTextBlock(block.node) ? (block.node.markDefs ?? []) : [],\n )\n\n return selectedSpans.every((span) => {\n const spanMarkDefs =\n span.node.marks?.flatMap((mark) => {\n const markDef = selectionMarkDefs.find(\n (markDef) => markDef._key === mark,\n )\n\n return markDef ? [markDef._type] : []\n }) ?? []\n\n return spanMarkDefs.includes(annotation)\n })\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getSelectedSpans} from './selector.get-selected-spans'\nimport {isSelectionExpanded} from './selector.is-selection-expanded'\n\n/**\n * @public\n */\nexport function isActiveDecorator(decorator: string): EditorSelector<boolean> {\n return (snapshot) => {\n if (isSelectionExpanded(snapshot)) {\n const selectedSpans = getSelectedSpans(snapshot)\n\n return (\n selectedSpans.length > 0 &&\n selectedSpans.every((span) => span.node.marks?.includes(decorator))\n )\n }\n\n return snapshot.context.activeDecorators.includes(decorator)\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveListItem} from './selector.get-active-list-item'\n\n/**\n * @public\n */\nexport function isActiveListItem(listItem: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeListItem = getActiveListItem(snapshot)\n\n return activeListItem === listItem\n }\n}\n","import type {EditorSelector} from '../editor/editor-selector'\nimport {getActiveStyle} from './selector.get-active-style'\n\n/**\n * @public\n */\nexport function isActiveStyle(style: string): EditorSelector<boolean> {\n return (snapshot) => {\n const activeStyle = getActiveStyle(snapshot)\n\n return activeStyle === style\n }\n}\n"],"names":["isSelectingEntireBlocks","snapshot","context","selection","startPoint","backward","focus","anchor","endPoint","startBlock","getSelectionStartBlock","endBlock","getSelectionEndBlock","startBlockStartPoint","utils","endBlockEndPoint","getSelectedSpans","selectedSpans","startBlockKey","isKeySegment","path","_key","undefined","endBlockKey","startSpanKey","endSpanKey","startBlockFound","block","value","isPortableTextTextBlock","child","children","isPortableTextSpan","offset","text","length","push","node","getActiveAnnotations","selectedBlocks","getSelectedBlocks","focusSpan","getFocusSpan","isSelectionCollapsed","flatMap","markDefs","filter","markDef","some","span","marks","includes","getActiveListItem","guards","createGuards","selectedTextBlocks","map","isTextBlock","firstTextBlock","at","firstListItem","listItem","every","getActiveStyle","firstStyle","style","getTrimmedSelection","getSelectionStartPoint","getSelectionEndPoint","isKeyedSegment","startChildKey","endChildKey","adjustedStartPoint","trimStartPoint","adjustedEndPoint","trimEndPoint","previousPotentialEndpoint","isEmptyTextBlock","blockKey","lonelySpan","trimmedSelection","focusTextBlock","getFocusTextBlock","isActiveAnnotation","annotation","isSelectionExpanded","selectionMarkDefs","mark","find","_type","isActiveDecorator","decorator","activeDecorators","isActiveListItem","isActiveStyle"],"mappings":";;;AAOO,MAAMA,0BAAoDC,CAAa,aAAA;AACxE,MAAA,CAACA,SAASC,QAAQC;AACb,WAAA;AAGT,QAAMC,aAAaH,SAASC,QAAQC,UAAUE,WAC1CJ,SAASC,QAAQC,UAAUG,QAC3BL,SAASC,QAAQC,UAAUI,QACzBC,WAAWP,SAASC,QAAQC,UAAUE,WACxCJ,SAASC,QAAQC,UAAUI,SAC3BN,SAASC,QAAQC,UAAUG,OAEzBG,aAAaC,uBAAuBT,QAAQ,GAC5CU,WAAWC,qBAAqBX,QAAQ;AAE1C,MAAA,CAACQ,cAAc,CAACE;AACX,WAAA;AAGHE,QAAAA,uBAAuBC,mBAAyBL,UAAU,GAC1DM,mBAAmBD,iBAAuBH,QAAQ;AAGtDG,SAAAA,uBAA6BD,sBAAsBT,UAAU,KAC7DU,uBAA6BC,kBAAkBP,QAAQ;AAE3D,GCrBaQ,mBAKRf,CAAa,aAAA;AACZ,MAAA,CAACA,SAASC,QAAQC;AACpB,WAAO,CAAE;AAGLc,QAAAA,gBAGD,CAAA,GAECb,aAAaH,SAASC,QAAQC,UAAUE,WAC1CJ,SAASC,QAAQC,UAAUG,QAC3BL,SAASC,QAAQC,UAAUI,QACzBC,WAAWP,SAASC,QAAQC,UAAUE,WACxCJ,SAASC,QAAQC,UAAUI,SAC3BN,SAASC,QAAQC,UAAUG,OAEzBY,gBAAgBC,aAAaf,WAAWgB,KAAK,CAAC,CAAC,IACjDhB,WAAWgB,KAAK,CAAC,EAAEC,OACnBC,QACEC,cAAcJ,aAAaX,SAASY,KAAK,CAAC,CAAC,IAC7C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AAOxC,UAAU,CAACA,QAAQ0C,KAAK,IAAI,CAAE;AAAA,IACtC,CAAA,KAAK,CAEYtC,GAAAA,SAASiC,UAAU,CACxC;AAAA,EACH;AACF;AChDO,SAASM,kBAAkBC,WAA4C;AAC5E,SAAQ1F,CAAa,aAAA;AACfoF,QAAAA,oBAAoBpF,QAAQ,GAAG;AAC3BgB,YAAAA,gBAAgBD,iBAAiBf,QAAQ;AAG7CgB,aAAAA,cAAckB,SAAS,KACvBlB,cAAc6C,MAAOb,CAASA,SAAAA,KAAKZ,KAAKa,OAAOC,SAASwC,SAAS,CAAC;AAAA,IAAA;AAItE,WAAO1F,SAASC,QAAQ0F,iBAAiBzC,SAASwC,SAAS;AAAA,EAC7D;AACF;ACdO,SAASE,iBAAiBhC,UAA2C;AAClE5D,SAAAA,CAAAA,aACiBmD,kBAAkBnD,QAAQ,MAEvB4D;AAE9B;ACNO,SAASiC,cAAc7B,OAAwC;AAC5DhE,SAAAA,CAAAA,aACc8D,eAAe9D,QAAQ,MAEpBgE;AAE3B;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
2
|
-
|
|
3
|
-
export const deserializationFailureActionImplementation: BehaviorActionImplementation<
|
|
4
|
-
'deserialization.failure'
|
|
5
|
-
> = ({action}) => {
|
|
6
|
-
console.warn(
|
|
7
|
-
`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`,
|
|
8
|
-
)
|
|
9
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {insertBlocksActionImplementation} from './behavior.action.insert-blocks'
|
|
2
|
-
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
3
|
-
|
|
4
|
-
export const deserializationSuccessActionImplementation: BehaviorActionImplementation<
|
|
5
|
-
'deserialization.success'
|
|
6
|
-
> = ({context, action}) => {
|
|
7
|
-
insertBlocksActionImplementation({
|
|
8
|
-
context,
|
|
9
|
-
action: {
|
|
10
|
-
type: 'insert.blocks',
|
|
11
|
-
blocks: action.data,
|
|
12
|
-
editor: action.editor,
|
|
13
|
-
placement: 'auto',
|
|
14
|
-
},
|
|
15
|
-
})
|
|
16
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import {parseBlocks} from '../internal-utils/parse-blocks'
|
|
2
|
-
import {getFocusBlock} from '../internal-utils/slate-utils'
|
|
3
|
-
import {toSlateValue} from '../internal-utils/values'
|
|
4
|
-
import {insertBreakActionImplementation} from './behavior.action.insert-break'
|
|
5
|
-
import {insertBlock} from './behavior.action.insert.block'
|
|
6
|
-
import {selectNextBlockActionImplementation} from './behavior.action.select.next-block'
|
|
7
|
-
import {selectPreviousBlockActionImplementation} from './behavior.action.select.previous-block'
|
|
8
|
-
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
9
|
-
|
|
10
|
-
export const insertBlocksActionImplementation: BehaviorActionImplementation<
|
|
11
|
-
'insert.blocks'
|
|
12
|
-
> = ({context, action}) => {
|
|
13
|
-
const parsedBlocks = parseBlocks({
|
|
14
|
-
context,
|
|
15
|
-
blocks: action.blocks,
|
|
16
|
-
options: {refreshKeys: false},
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
if (parsedBlocks.length === 0) {
|
|
20
|
-
throw new Error(`Failed to parse blocks ${JSON.stringify(action.blocks)}`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const fragment = toSlateValue(parsedBlocks, {schemaTypes: context.schema})
|
|
24
|
-
|
|
25
|
-
if (fragment.length === 0) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
`Failed to convert blocks to Slate fragment ${JSON.stringify(
|
|
28
|
-
parsedBlocks,
|
|
29
|
-
)}`,
|
|
30
|
-
)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const [focusBlock] = getFocusBlock({editor: action.editor})
|
|
34
|
-
|
|
35
|
-
if (action.placement === 'before') {
|
|
36
|
-
let index = 0
|
|
37
|
-
|
|
38
|
-
for (const block of fragment) {
|
|
39
|
-
insertBlock({
|
|
40
|
-
block,
|
|
41
|
-
placement: index === 0 ? 'before' : 'after',
|
|
42
|
-
select: 'end',
|
|
43
|
-
editor: action.editor,
|
|
44
|
-
schema: context.schema,
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
index++
|
|
48
|
-
}
|
|
49
|
-
} else if (action.placement === 'after') {
|
|
50
|
-
for (const block of fragment) {
|
|
51
|
-
insertBlock({
|
|
52
|
-
block,
|
|
53
|
-
placement: 'after',
|
|
54
|
-
select: 'end',
|
|
55
|
-
editor: action.editor,
|
|
56
|
-
schema: context.schema,
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
} else {
|
|
60
|
-
if (focusBlock && action.editor.isTextBlock(focusBlock)) {
|
|
61
|
-
if (fragment.length === 1) {
|
|
62
|
-
insertBlock({
|
|
63
|
-
block: fragment[0],
|
|
64
|
-
placement: 'auto',
|
|
65
|
-
select: 'end',
|
|
66
|
-
editor: action.editor,
|
|
67
|
-
schema: context.schema,
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
return
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
let index = 0
|
|
74
|
-
|
|
75
|
-
for (const block of fragment) {
|
|
76
|
-
if (index === 0) {
|
|
77
|
-
insertBreakActionImplementation({
|
|
78
|
-
context,
|
|
79
|
-
action: {type: 'insert.break', editor: action.editor},
|
|
80
|
-
})
|
|
81
|
-
selectPreviousBlockActionImplementation({
|
|
82
|
-
context,
|
|
83
|
-
action: {
|
|
84
|
-
type: 'select.previous block',
|
|
85
|
-
editor: action.editor,
|
|
86
|
-
select: 'end',
|
|
87
|
-
},
|
|
88
|
-
})
|
|
89
|
-
insertBlock({
|
|
90
|
-
block,
|
|
91
|
-
placement: 'auto',
|
|
92
|
-
select: 'end',
|
|
93
|
-
editor: action.editor,
|
|
94
|
-
schema: context.schema,
|
|
95
|
-
})
|
|
96
|
-
} else if (index === fragment.length - 1) {
|
|
97
|
-
selectNextBlockActionImplementation({
|
|
98
|
-
context,
|
|
99
|
-
action: {
|
|
100
|
-
type: 'select.next block',
|
|
101
|
-
editor: action.editor,
|
|
102
|
-
select: 'start',
|
|
103
|
-
},
|
|
104
|
-
})
|
|
105
|
-
insertBlock({
|
|
106
|
-
block,
|
|
107
|
-
placement: 'auto',
|
|
108
|
-
select: 'end',
|
|
109
|
-
editor: action.editor,
|
|
110
|
-
schema: context.schema,
|
|
111
|
-
})
|
|
112
|
-
} else {
|
|
113
|
-
insertBlock({
|
|
114
|
-
block,
|
|
115
|
-
placement: 'after',
|
|
116
|
-
select: 'end',
|
|
117
|
-
editor: action.editor,
|
|
118
|
-
schema: context.schema,
|
|
119
|
-
})
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
index++
|
|
123
|
-
}
|
|
124
|
-
} else {
|
|
125
|
-
let index = 0
|
|
126
|
-
|
|
127
|
-
for (const block of fragment) {
|
|
128
|
-
insertBlock({
|
|
129
|
-
block,
|
|
130
|
-
placement: index === 0 ? 'auto' : 'after',
|
|
131
|
-
select: 'end',
|
|
132
|
-
editor: action.editor,
|
|
133
|
-
schema: context.schema,
|
|
134
|
-
})
|
|
135
|
-
|
|
136
|
-
index++
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {Editor, Transforms} from 'slate'
|
|
2
|
-
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
3
|
-
import {createGuards} from './behavior.guards'
|
|
4
|
-
|
|
5
|
-
export const toggleListItemActionImplementation: BehaviorActionImplementation<
|
|
6
|
-
'list item.toggle'
|
|
7
|
-
> = ({context, action}) => {
|
|
8
|
-
const isActive = isListItemActive({
|
|
9
|
-
editor: action.editor,
|
|
10
|
-
listItem: action.listItem,
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
if (isActive) {
|
|
14
|
-
removeListItemActionImplementation({
|
|
15
|
-
context,
|
|
16
|
-
action: {...action, type: 'list item.remove'},
|
|
17
|
-
})
|
|
18
|
-
} else {
|
|
19
|
-
addListItemActionImplementation({
|
|
20
|
-
context,
|
|
21
|
-
action: {...action, type: 'list item.add'},
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const removeListItemActionImplementation: BehaviorActionImplementation<
|
|
27
|
-
'list item.remove'
|
|
28
|
-
> = ({context, action}) => {
|
|
29
|
-
if (!action.editor.selection) {
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const guards = createGuards(context)
|
|
34
|
-
|
|
35
|
-
const selectedBlocks = [
|
|
36
|
-
...Editor.nodes(action.editor, {
|
|
37
|
-
at: action.editor.selection,
|
|
38
|
-
match: (node) => guards.isListBlock(node),
|
|
39
|
-
}),
|
|
40
|
-
]
|
|
41
|
-
|
|
42
|
-
for (const [, at] of selectedBlocks) {
|
|
43
|
-
Transforms.unsetNodes(action.editor, ['listItem', 'level'], {at})
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const addListItemActionImplementation: BehaviorActionImplementation<
|
|
48
|
-
'list item.add'
|
|
49
|
-
> = ({context, action}) => {
|
|
50
|
-
if (!action.editor.selection) {
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const guards = createGuards(context)
|
|
55
|
-
|
|
56
|
-
const selectedBlocks = [
|
|
57
|
-
...Editor.nodes(action.editor, {
|
|
58
|
-
at: action.editor.selection,
|
|
59
|
-
match: (node) => guards.isTextBlock(node),
|
|
60
|
-
}),
|
|
61
|
-
]
|
|
62
|
-
|
|
63
|
-
for (const [, at] of selectedBlocks) {
|
|
64
|
-
Transforms.setNodes(
|
|
65
|
-
action.editor,
|
|
66
|
-
{
|
|
67
|
-
level: 1,
|
|
68
|
-
listItem: action.listItem,
|
|
69
|
-
},
|
|
70
|
-
{at},
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function isListItemActive({
|
|
76
|
-
editor,
|
|
77
|
-
listItem,
|
|
78
|
-
}: {
|
|
79
|
-
editor: Editor
|
|
80
|
-
listItem: string
|
|
81
|
-
}): boolean {
|
|
82
|
-
if (!editor.selection) {
|
|
83
|
-
return false
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const selectedBlocks = [
|
|
87
|
-
...Editor.nodes(editor, {
|
|
88
|
-
at: editor.selection,
|
|
89
|
-
match: (node) => editor.isTextBlock(node),
|
|
90
|
-
}),
|
|
91
|
-
]
|
|
92
|
-
|
|
93
|
-
if (selectedBlocks.length > 0) {
|
|
94
|
-
return selectedBlocks.every(
|
|
95
|
-
([node]) => editor.isListBlock(node) && node.listItem === listItem,
|
|
96
|
-
)
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return false
|
|
100
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import {Editor} from 'slate'
|
|
2
|
-
import {toPortableTextRange} from '../internal-utils/ranges'
|
|
3
|
-
import {selectActionImplementation} from './behavior.action.select'
|
|
4
|
-
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
5
|
-
|
|
6
|
-
export const selectNextBlockActionImplementation: BehaviorActionImplementation<
|
|
7
|
-
'select.next block'
|
|
8
|
-
> = ({context, action}) => {
|
|
9
|
-
if (!action.editor.selection) {
|
|
10
|
-
console.error('Unable to select previous block without a selection')
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const blockPath = action.editor.selection.focus.path.slice(0, 1)
|
|
15
|
-
const nextBlockPath = [blockPath[0] + 1]
|
|
16
|
-
|
|
17
|
-
const position =
|
|
18
|
-
action.select === 'end'
|
|
19
|
-
? Editor.end(action.editor, nextBlockPath)
|
|
20
|
-
: Editor.start(action.editor, nextBlockPath)
|
|
21
|
-
|
|
22
|
-
const newSelection = toPortableTextRange(
|
|
23
|
-
action.editor.children,
|
|
24
|
-
{
|
|
25
|
-
anchor: position,
|
|
26
|
-
focus: position,
|
|
27
|
-
},
|
|
28
|
-
context.schema,
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
if (!newSelection) {
|
|
32
|
-
console.error('Could not find selection for next block')
|
|
33
|
-
return
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
selectActionImplementation({
|
|
37
|
-
context,
|
|
38
|
-
action: {
|
|
39
|
-
type: 'select',
|
|
40
|
-
selection: newSelection,
|
|
41
|
-
editor: action.editor,
|
|
42
|
-
},
|
|
43
|
-
})
|
|
44
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import {Editor, Path} from 'slate'
|
|
2
|
-
import {toPortableTextRange} from '../internal-utils/ranges'
|
|
3
|
-
import {selectActionImplementation} from './behavior.action.select'
|
|
4
|
-
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
5
|
-
|
|
6
|
-
export const selectPreviousBlockActionImplementation: BehaviorActionImplementation<
|
|
7
|
-
'select.previous block'
|
|
8
|
-
> = ({context, action}) => {
|
|
9
|
-
if (!action.editor.selection) {
|
|
10
|
-
console.error('Unable to select previous block without a selection')
|
|
11
|
-
return
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const blockPath = action.editor.selection.focus.path.slice(0, 1)
|
|
15
|
-
|
|
16
|
-
if (!Path.hasPrevious(blockPath)) {
|
|
17
|
-
console.error("There's no previous block to select")
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const position =
|
|
22
|
-
action.select === 'end'
|
|
23
|
-
? Editor.end(action.editor, Path.previous(blockPath))
|
|
24
|
-
: Editor.start(action.editor, Path.previous(blockPath))
|
|
25
|
-
|
|
26
|
-
const newSelection = toPortableTextRange(
|
|
27
|
-
action.editor.children,
|
|
28
|
-
{
|
|
29
|
-
anchor: position,
|
|
30
|
-
focus: position,
|
|
31
|
-
},
|
|
32
|
-
context.schema,
|
|
33
|
-
)
|
|
34
|
-
|
|
35
|
-
if (!newSelection) {
|
|
36
|
-
console.error('Could not find selection for previous block')
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
selectActionImplementation({
|
|
41
|
-
context,
|
|
42
|
-
action: {
|
|
43
|
-
type: 'select',
|
|
44
|
-
selection: newSelection,
|
|
45
|
-
editor: action.editor,
|
|
46
|
-
},
|
|
47
|
-
})
|
|
48
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
2
|
-
|
|
3
|
-
export const serializationFailureActionImplementation: BehaviorActionImplementation<
|
|
4
|
-
'serialization.failure'
|
|
5
|
-
> = ({action}) => {
|
|
6
|
-
console.warn(
|
|
7
|
-
`Serialization of ${action.mimeType} failed with reason "${action.reason}"`,
|
|
8
|
-
)
|
|
9
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {dataTransferSetActionImplementation} from './behavior.action.data-transfer-set'
|
|
2
|
-
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
3
|
-
|
|
4
|
-
export const serializationSuccessActionImplementation: BehaviorActionImplementation<
|
|
5
|
-
'serialization.success'
|
|
6
|
-
> = ({context, action}) => {
|
|
7
|
-
dataTransferSetActionImplementation({
|
|
8
|
-
context,
|
|
9
|
-
action: {
|
|
10
|
-
type: 'data transfer.set',
|
|
11
|
-
data: action.data,
|
|
12
|
-
dataTransfer: action.originEvent.originEvent.dataTransfer,
|
|
13
|
-
mimeType: action.mimeType,
|
|
14
|
-
editor: action.editor,
|
|
15
|
-
},
|
|
16
|
-
})
|
|
17
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import {Editor, Transforms} from 'slate'
|
|
2
|
-
import type {BehaviorActionImplementation} from './behavior.actions'
|
|
3
|
-
import {createGuards} from './behavior.guards'
|
|
4
|
-
|
|
5
|
-
export const toggleStyleActionImplementation: BehaviorActionImplementation<
|
|
6
|
-
'style.toggle'
|
|
7
|
-
> = ({context, action}) => {
|
|
8
|
-
const isActive = isStyleActive({
|
|
9
|
-
editor: action.editor,
|
|
10
|
-
style: action.style,
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
if (isActive) {
|
|
14
|
-
removeStyleActionImplementation({
|
|
15
|
-
context,
|
|
16
|
-
action: {...action, type: 'style.remove'},
|
|
17
|
-
})
|
|
18
|
-
} else {
|
|
19
|
-
addStyleActionImplementation({
|
|
20
|
-
context,
|
|
21
|
-
action: {...action, type: 'style.add'},
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export const removeStyleActionImplementation: BehaviorActionImplementation<
|
|
27
|
-
'style.remove'
|
|
28
|
-
> = ({context, action}) => {
|
|
29
|
-
if (!action.editor.selection) {
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const defaultStyle = context.schema.styles[0].value
|
|
34
|
-
const guards = createGuards(context)
|
|
35
|
-
|
|
36
|
-
const selectedBlocks = [
|
|
37
|
-
...Editor.nodes(action.editor, {
|
|
38
|
-
at: action.editor.selection,
|
|
39
|
-
match: (node) => guards.isTextBlock(node),
|
|
40
|
-
}),
|
|
41
|
-
]
|
|
42
|
-
|
|
43
|
-
for (const [, at] of selectedBlocks) {
|
|
44
|
-
Transforms.setNodes(
|
|
45
|
-
action.editor,
|
|
46
|
-
{
|
|
47
|
-
style: defaultStyle,
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
at,
|
|
51
|
-
},
|
|
52
|
-
)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export const addStyleActionImplementation: BehaviorActionImplementation<
|
|
57
|
-
'style.add'
|
|
58
|
-
> = ({context, action}) => {
|
|
59
|
-
if (!action.editor.selection) {
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const guards = createGuards(context)
|
|
64
|
-
|
|
65
|
-
const selectedBlocks = [
|
|
66
|
-
...Editor.nodes(action.editor, {
|
|
67
|
-
at: action.editor.selection,
|
|
68
|
-
match: (node) => guards.isTextBlock(node),
|
|
69
|
-
}),
|
|
70
|
-
]
|
|
71
|
-
|
|
72
|
-
for (const [, at] of selectedBlocks) {
|
|
73
|
-
Transforms.setNodes(
|
|
74
|
-
action.editor,
|
|
75
|
-
{
|
|
76
|
-
style: action.style,
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
at,
|
|
80
|
-
},
|
|
81
|
-
)
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function isStyleActive({
|
|
86
|
-
editor,
|
|
87
|
-
style,
|
|
88
|
-
}: {
|
|
89
|
-
editor: Editor
|
|
90
|
-
style: string
|
|
91
|
-
}): boolean {
|
|
92
|
-
if (!editor.selection) {
|
|
93
|
-
return false
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const selectedBlocks = [
|
|
97
|
-
...Editor.nodes(editor, {
|
|
98
|
-
at: editor.selection,
|
|
99
|
-
match: (node) => editor.isTextBlock(node),
|
|
100
|
-
}),
|
|
101
|
-
]
|
|
102
|
-
|
|
103
|
-
if (selectedBlocks.length > 0) {
|
|
104
|
-
return selectedBlocks.every(([node]) => node.style === style)
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return false
|
|
108
|
-
}
|