@portabletext/editor 1.47.0 → 1.47.2
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.core.cjs +7 -7
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/behavior.markdown.cjs.map +1 -1
- package/lib/_chunks-cjs/editor-provider.cjs +379 -326
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-cjs/parse-blocks.cjs +4 -4
- package/lib/_chunks-cjs/parse-blocks.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-overlapping-selection.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +7 -7
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/behavior.markdown.js.map +1 -1
- package/lib/_chunks-es/editor-provider.js +380 -327
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/_chunks-es/parse-blocks.js +4 -4
- package/lib/_chunks-es/parse-blocks.js.map +1 -1
- package/lib/_chunks-es/selector.is-overlapping-selection.js.map +1 -1
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +70 -28
- package/lib/behaviors/index.d.ts +70 -28
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +12 -14
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +61 -3
- package/lib/index.d.ts +61 -3
- package/lib/index.js +12 -14
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +68 -23
- package/lib/plugins/index.d.ts +68 -23
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +69 -27
- package/lib/selectors/index.d.ts +69 -27
- package/lib/utils/index.d.cts +74 -29
- package/lib/utils/index.d.ts +74 -29
- package/package.json +6 -6
- package/src/behavior-actions/behavior.action.insert.block.ts +1 -1
- package/src/behavior-actions/behavior.action.split.block.ts +1 -1
- package/src/behavior-actions/behavior.guards.ts +1 -1
- package/src/behaviors/behavior.core.decorators.ts +4 -4
- package/src/behaviors/behavior.core.insert-break.ts +4 -4
- package/src/behaviors/behavior.decorator-pair.ts +1 -1
- package/src/behaviors/behavior.links.ts +1 -1
- package/src/behaviors/behavior.markdown.ts +1 -1
- package/src/behaviors/behavior.perform-event.ts +1 -1
- package/src/converters/converter.portable-text.deserialize.test.ts +2 -3
- package/src/converters/converter.text-html.deserialize.test.ts +62 -5
- package/src/converters/converter.text-html.serialize.test.ts +9 -5
- package/src/converters/converter.text-html.ts +66 -64
- package/src/converters/converter.text-plain.test.ts +9 -4
- package/src/converters/converter.text-plain.ts +91 -87
- package/src/converters/converters.core.ts +13 -8
- package/src/editor/Editable.tsx +18 -13
- package/src/editor/PortableTextEditor.tsx +5 -5
- package/src/editor/__tests__/PortableTextEditorTester.tsx +4 -3
- package/src/editor/__tests__/insert-block.test.tsx +10 -10
- package/src/editor/__tests__/self-solving.test.tsx +2 -2
- package/src/editor/components/Synchronizer.tsx +1 -1
- package/src/editor/create-editor.ts +51 -18
- package/src/editor/editor-machine.ts +1 -1
- package/src/editor/{define-schema.ts → editor-schema.ts} +114 -5
- package/src/editor/editor-snapshot.ts +1 -1
- package/src/editor/get-active-decorators.ts +2 -2
- package/src/editor/{create-editor-schema.ts → legacy-schema.ts} +3 -3
- package/src/editor/mutation-machine.ts +1 -1
- package/src/editor/plugins/createWithObjectKeys.ts +6 -9
- package/src/editor/plugins/createWithPatches.ts +12 -11
- package/src/editor/plugins/createWithPortableTextBlockStyle.ts +2 -6
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +15 -12
- package/src/editor/plugins/createWithSchemaTypes.ts +24 -16
- package/src/editor/plugins/createWithUndoRedo.ts +3 -4
- package/src/editor/plugins/createWithUtils.ts +12 -10
- package/src/editor/plugins/with-plugins.ts +5 -15
- package/src/editor/range-decorations-machine.ts +1 -1
- package/src/editor/sync-machine.ts +1 -1
- package/src/index.ts +2 -2
- package/src/internal-utils/__tests__/operationToPatches.test.ts +12 -10
- package/src/internal-utils/__tests__/patchToOperations.test.ts +3 -2
- package/src/internal-utils/__tests__/values.test.ts +3 -2
- package/src/internal-utils/applyPatch.ts +7 -9
- package/src/internal-utils/create-test-snapshot.ts +1 -1
- package/src/internal-utils/drag-selection.test.ts +1 -1
- package/src/internal-utils/operationToPatches.ts +4 -6
- package/src/internal-utils/parse-blocks.test.ts +1 -1
- package/src/internal-utils/parse-blocks.ts +8 -7
- package/src/internal-utils/slate-children-to-blocks.ts +1 -1
- package/src/internal-utils/slate-utils.ts +1 -1
- package/src/internal-utils/validateValue.ts +4 -6
- package/src/internal-utils/values.ts +5 -5
- package/src/plugins/plugin.decorator-shortcut.ts +1 -1
- package/src/plugins/plugin.markdown.test.tsx +1 -1
- package/src/plugins/plugin.markdown.tsx +1 -1
- package/src/selectors/selector.get-selection-text.test.ts +1 -1
- package/src/selectors/selector.get-trimmed-selection.test.ts +1 -1
package/lib/behaviors/index.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import type {Patch} from '@portabletext/patches'
|
|
2
|
+
import {KeyedSegment, PortableTextBlock} from '@sanity/types'
|
|
2
3
|
import type {
|
|
3
|
-
ArraySchemaType,
|
|
4
|
-
BlockDecoratorDefinition,
|
|
5
|
-
BlockListDefinition,
|
|
6
|
-
BlockStyleDefinition,
|
|
7
|
-
ObjectSchemaType,
|
|
8
4
|
Path,
|
|
9
5
|
PortableTextChild,
|
|
10
6
|
PortableTextListBlock,
|
|
@@ -12,7 +8,6 @@ import type {
|
|
|
12
8
|
PortableTextSpan,
|
|
13
9
|
PortableTextTextBlock,
|
|
14
10
|
} from '@sanity/types'
|
|
15
|
-
import {KeyedSegment, PortableTextBlock} from '@sanity/types'
|
|
16
11
|
import type {
|
|
17
12
|
FocusEvent as FocusEvent_2,
|
|
18
13
|
KeyboardEvent as KeyboardEvent_2,
|
|
@@ -42,11 +37,7 @@ import {
|
|
|
42
37
|
Values,
|
|
43
38
|
} from 'xstate'
|
|
44
39
|
import {GuardArgs} from 'xstate/guards'
|
|
45
|
-
import {
|
|
46
|
-
BlockOffset,
|
|
47
|
-
EditorSelection,
|
|
48
|
-
PortableTextMemberSchemaTypes as PortableTextMemberSchemaTypes_2,
|
|
49
|
-
} from '..'
|
|
40
|
+
import {BlockOffset, EditorSelection} from '..'
|
|
50
41
|
import {EventPosition} from '../internal-utils/event-position'
|
|
51
42
|
import {MIMEType} from '../internal-utils/mime-type'
|
|
52
43
|
import {PickFromUnion, StrictExtract} from '../type-utils'
|
|
@@ -239,6 +230,14 @@ declare const abstractBehaviorEventTypes: readonly [
|
|
|
239
230
|
'style.toggle',
|
|
240
231
|
]
|
|
241
232
|
|
|
233
|
+
/**
|
|
234
|
+
* @public
|
|
235
|
+
*/
|
|
236
|
+
declare type BaseDefinition = {
|
|
237
|
+
name: string
|
|
238
|
+
title?: string
|
|
239
|
+
}
|
|
240
|
+
|
|
242
241
|
/**
|
|
243
242
|
* @beta
|
|
244
243
|
*/
|
|
@@ -9860,7 +9859,7 @@ declare const editorMachine: StateMachine<
|
|
|
9860
9859
|
converters: Set<Converter>
|
|
9861
9860
|
keyGenerator: () => string
|
|
9862
9861
|
pendingEvents: never[]
|
|
9863
|
-
schema:
|
|
9862
|
+
schema: EditorSchema
|
|
9864
9863
|
selection: null
|
|
9865
9864
|
initialReadOnly: boolean
|
|
9866
9865
|
maxBlocks: number | undefined
|
|
@@ -13340,7 +13339,65 @@ declare const editorMachine: StateMachine<
|
|
|
13340
13339
|
/**
|
|
13341
13340
|
* @public
|
|
13342
13341
|
*/
|
|
13343
|
-
declare type EditorSchema =
|
|
13342
|
+
declare type EditorSchema = {
|
|
13343
|
+
annotations: ReadonlyArray<
|
|
13344
|
+
BaseDefinition & {
|
|
13345
|
+
fields: ReadonlyArray<{
|
|
13346
|
+
name: string
|
|
13347
|
+
type: string
|
|
13348
|
+
}>
|
|
13349
|
+
}
|
|
13350
|
+
>
|
|
13351
|
+
block: {
|
|
13352
|
+
name: string
|
|
13353
|
+
}
|
|
13354
|
+
blockObjects: ReadonlyArray<
|
|
13355
|
+
BaseDefinition & {
|
|
13356
|
+
fields: ReadonlyArray<{
|
|
13357
|
+
name: string
|
|
13358
|
+
type: string
|
|
13359
|
+
}>
|
|
13360
|
+
}
|
|
13361
|
+
>
|
|
13362
|
+
decorators: ReadonlyArray<
|
|
13363
|
+
BaseDefinition & {
|
|
13364
|
+
/**
|
|
13365
|
+
* @deprecated
|
|
13366
|
+
* Use `name` instead
|
|
13367
|
+
*/
|
|
13368
|
+
value: string
|
|
13369
|
+
}
|
|
13370
|
+
>
|
|
13371
|
+
inlineObjects: ReadonlyArray<
|
|
13372
|
+
BaseDefinition & {
|
|
13373
|
+
fields: ReadonlyArray<{
|
|
13374
|
+
name: string
|
|
13375
|
+
type: string
|
|
13376
|
+
}>
|
|
13377
|
+
}
|
|
13378
|
+
>
|
|
13379
|
+
span: {
|
|
13380
|
+
name: string
|
|
13381
|
+
}
|
|
13382
|
+
styles: ReadonlyArray<
|
|
13383
|
+
BaseDefinition & {
|
|
13384
|
+
/**
|
|
13385
|
+
* @deprecated
|
|
13386
|
+
* Use `name` instead
|
|
13387
|
+
*/
|
|
13388
|
+
value: string
|
|
13389
|
+
}
|
|
13390
|
+
>
|
|
13391
|
+
lists: ReadonlyArray<
|
|
13392
|
+
BaseDefinition & {
|
|
13393
|
+
/**
|
|
13394
|
+
* @deprecated
|
|
13395
|
+
* Use `name` instead
|
|
13396
|
+
*/
|
|
13397
|
+
value: string
|
|
13398
|
+
}
|
|
13399
|
+
>
|
|
13400
|
+
}
|
|
13344
13401
|
|
|
13345
13402
|
/** @public */
|
|
13346
13403
|
declare type EditorSelection_2 = {
|
|
@@ -13634,21 +13691,6 @@ declare type PickFromUnion_2<
|
|
|
13634
13691
|
TPickedTags extends TUnion[TTagKey],
|
|
13635
13692
|
> = TUnion extends Record<TTagKey, TPickedTags> ? TUnion : never
|
|
13636
13693
|
|
|
13637
|
-
/** @beta */
|
|
13638
|
-
declare type PortableTextMemberSchemaTypes = {
|
|
13639
|
-
annotations: (ObjectSchemaType & {
|
|
13640
|
-
i18nTitleKey?: string
|
|
13641
|
-
})[]
|
|
13642
|
-
block: ObjectSchemaType
|
|
13643
|
-
blockObjects: ObjectSchemaType[]
|
|
13644
|
-
decorators: BlockDecoratorDefinition[]
|
|
13645
|
-
inlineObjects: ObjectSchemaType[]
|
|
13646
|
-
portableText: ArraySchemaType<PortableTextBlock>
|
|
13647
|
-
span: ObjectSchemaType
|
|
13648
|
-
styles: BlockStyleDefinition[]
|
|
13649
|
-
lists: BlockListDefinition[]
|
|
13650
|
-
}
|
|
13651
|
-
|
|
13652
13694
|
declare interface PortableTextSlateEditor extends ReactEditor {
|
|
13653
13695
|
_key: 'editor'
|
|
13654
13696
|
_type: 'editor'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/behaviors/behavior.code-editor.ts","../../src/behaviors/behavior.emoji-picker.ts","../../src/internal-utils/looks-like-url.ts","../../src/behaviors/behavior.links.ts"],"sourcesContent":["import {isHotkey} from '../internal-utils/is-hotkey'\nimport * as selectors from '../selectors'\nimport {raise} from './behavior.types.action'\nimport {defineBehavior} from './behavior.types.behavior'\n\n/**\n * @beta\n */\nexport type CodeEditorBehaviorsConfig = {\n moveBlockUpShortcut: string\n moveBlockDownShortcut: string\n}\n\n/**\n * @beta\n */\nexport function createCodeEditorBehaviors(config: CodeEditorBehaviorsConfig) {\n return [\n defineBehavior({\n on: 'keyboard.keydown',\n guard: ({snapshot, event}) => {\n const isMoveUpShortcut = isHotkey(\n config.moveBlockUpShortcut,\n event.originEvent,\n )\n const firstBlock = selectors.getFirstBlock(snapshot)\n const selectedBlocks = selectors.getSelectedBlocks(snapshot)\n const blocksAbove =\n firstBlock?.node._key !== selectedBlocks[0]?.node._key\n\n if (!isMoveUpShortcut || !blocksAbove) {\n return false\n }\n\n return {paths: selectedBlocks.map((block) => block.path)}\n },\n actions: [\n (_, {paths}) =>\n paths.map((at) =>\n raise({\n type: 'move.block up',\n at,\n }),\n ),\n ],\n }),\n defineBehavior({\n on: 'keyboard.keydown',\n guard: ({snapshot, event}) => {\n const isMoveDownShortcut = isHotkey(\n config.moveBlockDownShortcut,\n event.originEvent,\n )\n const lastBlock = selectors.getLastBlock(snapshot)\n const selectedBlocks = selectors.getSelectedBlocks(snapshot)\n const blocksBelow =\n lastBlock?.node._key !==\n selectedBlocks[selectedBlocks.length - 1]?.node._key\n\n if (!isMoveDownShortcut || !blocksBelow) {\n return false\n }\n\n return {paths: selectedBlocks.map((block) => block.path).reverse()}\n },\n actions: [\n (_, {paths}) =>\n paths.map((at) =>\n raise({\n type: 'move.block down',\n at,\n }),\n ),\n ],\n }),\n ]\n}\n","import {assertEvent, assign, createActor, setup} from 'xstate'\nimport {isHotkey} from '../internal-utils/is-hotkey'\nimport * as selectors from '../selectors'\nimport {effect, execute, noop} from './behavior.types.action'\nimport {defineBehavior} from './behavior.types.behavior'\n\nconst emojiCharRegEx = /^[a-zA-Z-_0-9]{1}$/\nconst incompleteEmojiRegEx = /:([a-zA-Z-_0-9]+)$/\nconst emojiRegEx = /:([a-zA-Z-_0-9]+):$/\n\n/**\n * @beta\n */\nexport type EmojiPickerBehaviorsConfig<TEmojiMatch> = {\n /**\n * Match emojis by keyword.\n */\n matchEmojis: ({keyword}: {keyword: string}) => Array<TEmojiMatch>\n onMatchesChanged: ({matches}: {matches: Array<TEmojiMatch>}) => void\n onSelectedIndexChanged: ({selectedIndex}: {selectedIndex: number}) => void\n /**\n * Parse an emoji match to a string that will be inserted into the editor.\n */\n parseMatch: ({match}: {match: TEmojiMatch}) => string | undefined\n}\n\n/**\n * @beta\n */\nexport function createEmojiPickerBehaviors<TEmojiMatch>(\n config: EmojiPickerBehaviorsConfig<TEmojiMatch>,\n) {\n const emojiPickerActor = createActor(createEmojiPickerMachine<TEmojiMatch>())\n emojiPickerActor.start()\n emojiPickerActor.subscribe((state) => {\n config.onMatchesChanged({matches: state.context.matches})\n config.onSelectedIndexChanged({selectedIndex: state.context.selectedIndex})\n })\n\n return [\n defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n if (event.text === ':') {\n return false\n }\n\n const isEmojiChar = emojiCharRegEx.test(event.text)\n\n if (!isEmojiChar) {\n return {emojis: []}\n }\n\n const focusBlock = selectors.getFocusTextBlock(snapshot)\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const emojiKeyword = `${textBefore}${event.text}`.match(\n incompleteEmojiRegEx,\n )?.[1]\n\n if (!focusBlock || emojiKeyword === undefined) {\n return {emojis: []}\n }\n\n const emojis = config.matchEmojis({keyword: emojiKeyword})\n\n return {emojis}\n },\n actions: [\n (_, params) => [\n {\n type: 'effect',\n effect: () => {\n emojiPickerActor.send({\n type: 'emojis found',\n matches: params.emojis,\n })\n },\n },\n ],\n ],\n }),\n defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const isColon = event.text === ':'\n\n if (!isColon) {\n return false\n }\n\n const matches = emojiPickerActor.getSnapshot().context.matches\n const selectedIndex =\n emojiPickerActor.getSnapshot().context.selectedIndex\n const emoji = matches[selectedIndex]\n ? config.parseMatch({match: matches[selectedIndex]})\n : undefined\n\n const focusBlock = selectors.getFocusTextBlock(snapshot)\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const emojiKeyword = `${textBefore}:`.match(emojiRegEx)?.[1]\n\n if (!focusBlock || emojiKeyword === undefined) {\n return false\n }\n\n const emojiStringLength = emojiKeyword.length + 2\n\n if (emoji) {\n return {\n focusBlock,\n emoji,\n emojiStringLength,\n textBeforeLength: textBefore.length + 1,\n }\n }\n\n return false\n },\n actions: [\n () => [\n execute({\n type: 'insert.text',\n text: ':',\n }),\n ],\n (_, params) => [\n effect(() => {\n emojiPickerActor.send({type: 'select'})\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: params.focusBlock.path,\n offset: params.textBeforeLength - params.emojiStringLength,\n },\n focus: {\n path: params.focusBlock.path,\n offset: params.textBeforeLength,\n },\n },\n }),\n execute({\n type: 'insert.text',\n text: params.emoji,\n }),\n ],\n ],\n }),\n defineBehavior({\n on: 'keyboard.keydown',\n guard: ({snapshot, event}) => {\n const matches = emojiPickerActor.getSnapshot().context.matches\n\n if (matches.length === 0) {\n return false\n }\n\n const isEscape = isHotkey('Escape', event.originEvent)\n\n if (isEscape) {\n return {action: 'reset' as const}\n }\n\n const isEnter = isHotkey('Enter', event.originEvent)\n const isTab = isHotkey('Tab', event.originEvent)\n\n if (isEnter || isTab) {\n const selectedIndex =\n emojiPickerActor.getSnapshot().context.selectedIndex\n\n const emoji = matches[selectedIndex]\n ? config.parseMatch({match: matches[selectedIndex]})\n : undefined\n\n if (!emoji) {\n return false\n }\n\n const focusBlock = selectors.getFocusTextBlock(snapshot)\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const emojiKeyword = textBefore.match(incompleteEmojiRegEx)?.[1]\n\n if (!focusBlock || emojiKeyword === undefined) {\n return false\n }\n\n const emojiStringLength = emojiKeyword.length + 1\n\n if (emoji) {\n return {\n action: 'select' as const,\n focusBlock,\n emoji,\n emojiStringLength,\n textBeforeLength: textBefore.length,\n }\n }\n\n return false\n }\n\n const isArrowDown = isHotkey('ArrowDown', event.originEvent)\n const isArrowUp = isHotkey('ArrowUp', event.originEvent)\n\n if (isArrowDown && matches.length > 0) {\n return {action: 'navigate down' as const}\n }\n\n if (isArrowUp && matches.length > 0) {\n return {action: 'navigate up' as const}\n }\n\n return false\n },\n actions: [\n (_, params) => {\n if (params.action === 'select') {\n return [\n effect(() => {\n emojiPickerActor.send({type: 'select'})\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: params.focusBlock.path,\n offset: params.textBeforeLength - params.emojiStringLength,\n },\n focus: {\n path: params.focusBlock.path,\n offset: params.textBeforeLength,\n },\n },\n }),\n execute({\n type: 'insert.text',\n text: params.emoji,\n }),\n ]\n }\n\n if (params.action === 'navigate up') {\n return [\n // If we are navigating then we want to hijack the key event and\n // turn it into a noop.\n noop(),\n effect(() => {\n emojiPickerActor.send({type: 'navigate up'})\n }),\n ]\n }\n\n if (params.action === 'navigate down') {\n return [\n // If we are navigating then we want to hijack the key event and\n // turn it into a noop.\n noop(),\n effect(() => {\n emojiPickerActor.send({type: 'navigate down'})\n }),\n ]\n }\n\n return [\n effect(() => {\n emojiPickerActor.send({type: 'reset'})\n }),\n ]\n },\n ],\n }),\n defineBehavior({\n on: 'delete.backward',\n guard: ({snapshot, event}) => {\n if (event.unit !== 'character') {\n return false\n }\n\n const matches = emojiPickerActor.getSnapshot().context.matches\n\n if (matches.length === 0) {\n return false\n }\n\n const focusBlock = selectors.getFocusTextBlock(snapshot)\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const emojiKeyword = textBefore\n .slice(0, textBefore.length - 1)\n .match(incompleteEmojiRegEx)?.[1]\n\n if (!focusBlock || emojiKeyword === undefined) {\n return {emojis: []}\n }\n\n const emojis = config.matchEmojis({keyword: emojiKeyword})\n\n return {emojis}\n },\n actions: [\n (_, params) => [\n {\n type: 'effect',\n effect: () => {\n emojiPickerActor.send({\n type: 'emojis found',\n matches: params.emojis,\n })\n },\n },\n ],\n ],\n }),\n ]\n}\n\nfunction createEmojiPickerMachine<TEmojiSearchResult>() {\n return setup({\n types: {\n context: {} as {\n matches: Array<TEmojiSearchResult>\n selectedIndex: number\n },\n events: {} as\n | {\n type: 'emojis found'\n matches: Array<TEmojiSearchResult>\n }\n | {\n type: 'navigate down' | 'navigate up' | 'select' | 'reset'\n },\n },\n actions: {\n 'assign matches': assign({\n matches: ({event}) => {\n assertEvent(event, 'emojis found')\n return event.matches\n },\n }),\n 'reset matches': assign({\n matches: [],\n }),\n 'reset selected index': assign({\n selectedIndex: 0,\n }),\n 'increment selected index': assign({\n selectedIndex: ({context}) => {\n if (context.selectedIndex === context.matches.length - 1) {\n return 0\n }\n return context.selectedIndex + 1\n },\n }),\n 'decrement selected index': assign({\n selectedIndex: ({context}) => {\n if (context.selectedIndex === 0) {\n return context.matches.length - 1\n }\n return context.selectedIndex - 1\n },\n }),\n },\n guards: {\n 'no matches': ({context}) => context.matches.length === 0,\n },\n }).createMachine({\n id: 'emoji picker',\n context: {\n matches: [],\n selectedIndex: 0,\n },\n initial: 'idle',\n states: {\n 'idle': {\n on: {\n 'emojis found': {\n actions: 'assign matches',\n target: 'showing matches',\n },\n },\n },\n 'showing matches': {\n always: {\n guard: 'no matches',\n target: 'idle',\n },\n exit: ['reset selected index'],\n on: {\n 'emojis found': {\n actions: 'assign matches',\n },\n 'navigate down': {\n actions: 'increment selected index',\n },\n 'navigate up': {\n actions: 'decrement selected index',\n },\n 'reset': {\n target: 'idle',\n actions: ['reset selected index', 'reset matches'],\n },\n 'select': {\n target: 'idle',\n actions: ['reset selected index', 'reset matches'],\n },\n },\n },\n },\n })\n}\n","export function looksLikeUrl(text: string) {\n let looksLikeUrl = false\n try {\n const url = new URL(text)\n\n if (!sensibleProtocols.includes(url.protocol)) {\n return false\n }\n\n looksLikeUrl = true\n } catch {}\n return looksLikeUrl\n}\n\nconst sensibleProtocols = ['http:', 'https:', 'mailto:', 'tel:']\n","import type {EditorSchema} from '../editor/define-schema'\nimport {looksLikeUrl} from '../internal-utils/looks-like-url'\nimport * as selectors from '../selectors'\nimport {execute} from './behavior.types.action'\nimport {defineBehavior} from './behavior.types.behavior'\n\n/**\n * @beta\n */\nexport type LinkBehaviorsConfig = {\n linkAnnotation?: (context: {\n schema: EditorSchema\n url: string\n }) => {name: string; value: {[prop: string]: unknown}} | undefined\n}\n\n/**\n * @beta\n */\nexport function createLinkBehaviors(config: LinkBehaviorsConfig) {\n const pasteLinkOnSelection = defineBehavior({\n on: 'clipboard.paste',\n guard: ({snapshot, event}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const text = event.originEvent.dataTransfer.getData('text/plain')\n const url = looksLikeUrl(text) ? text : undefined\n const annotation =\n url !== undefined\n ? config.linkAnnotation?.({url, schema: snapshot.context.schema})\n : undefined\n\n if (annotation && !selectionCollapsed) {\n return {annotation}\n }\n\n return false\n },\n actions: [\n (_, {annotation}) => [\n execute({\n type: 'annotation.add',\n annotation,\n }),\n ],\n ],\n })\n const pasteLinkAtCaret = defineBehavior({\n on: 'clipboard.paste',\n guard: ({snapshot, event}) => {\n const focusSpan = selectors.getFocusSpan(snapshot)\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n\n if (!focusSpan || !selectionCollapsed) {\n return false\n }\n\n const text = event.originEvent.dataTransfer.getData('text/plain')\n const url = looksLikeUrl(text) ? text : undefined\n const annotation =\n url !== undefined\n ? config.linkAnnotation?.({url, schema: snapshot.context.schema})\n : undefined\n\n if (url && annotation && selectionCollapsed) {\n return {focusSpan, annotation, url}\n }\n\n return false\n },\n actions: [\n (_, {annotation, url}) => [\n execute({\n type: 'insert.span',\n text: url,\n annotations: [annotation],\n }),\n ],\n ],\n })\n\n const linkBehaviors = [pasteLinkOnSelection, pasteLinkAtCaret]\n\n return linkBehaviors\n}\n"],"names":["createCodeEditorBehaviors","config","defineBehavior","on","guard","snapshot","event","isMoveUpShortcut","isHotkey","moveBlockUpShortcut","originEvent","firstBlock","selectors","selectedBlocks","blocksAbove","node","_key","paths","map","block","path","actions","_","at","raise","type","isMoveDownShortcut","moveBlockDownShortcut","lastBlock","blocksBelow","length","reverse","emojiCharRegEx","incompleteEmojiRegEx","emojiRegEx","createEmojiPickerBehaviors","emojiPickerActor","createActor","createEmojiPickerMachine","start","subscribe","state","onMatchesChanged","matches","context","onSelectedIndexChanged","selectedIndex","text","test","emojis","focusBlock","emojiKeyword","match","undefined","matchEmojis","keyword","params","effect","send","getSnapshot","emoji","parseMatch","textBefore","emojiStringLength","textBeforeLength","execute","anchor","offset","focus","action","isEnter","isTab","isArrowDown","isArrowUp","noop","unit","slice","setup","types","events","assign","assertEvent","guards","no matches","createMachine","id","initial","states","target","always","exit","looksLikeUrl","url","URL","sensibleProtocols","includes","protocol","createLinkBehaviors","pasteLinkOnSelection","selectionCollapsed","dataTransfer","getData","annotation","linkAnnotation","schema","pasteLinkAtCaret","focusSpan","annotations"],"mappings":";;;;;;AAgBO,SAASA,0BAA0BC,QAAmC;AAC3E,SAAO,CACLC,eAAe;AAAA,IACbC,IAAI;AAAA,IACJC,OAAOA,CAAC;AAAA,MAACC;AAAAA,MAAUC;AAAAA,IAAAA,MAAW;AACtBC,YAAAA,mBAAmBC,SACvBP,OAAOQ,qBACPH,MAAMI,WACR,GACMC,aAAaC,cAAwBP,QAAQ,GAC7CQ,iBAAiBD,kBAA4BP,QAAQ,GACrDS,cACJH,YAAYI,KAAKC,SAASH,eAAe,CAAC,GAAGE,KAAKC;AAEpD,aAAI,CAACT,oBAAoB,CAACO,cACjB,KAGF;AAAA,QAACG,OAAOJ,eAAeK,IAAKC,CAAAA,UAAUA,MAAMC,IAAI;AAAA,MAAC;AAAA,IAC1D;AAAA,IACAC,SAAS,CACP,CAACC,GAAG;AAAA,MAACL;AAAAA,IACHA,MAAAA,MAAMC,IAAKK,CAAAA,OACTC,MAAM;AAAA,MACJC,MAAM;AAAA,MACNF;AAAAA,IAAAA,CACD,CACH,CAAC;AAAA,EAEN,CAAA,GACDrB,eAAe;AAAA,IACbC,IAAI;AAAA,IACJC,OAAOA,CAAC;AAAA,MAACC;AAAAA,MAAUC;AAAAA,IAAAA,MAAW;AACtBoB,YAAAA,qBAAqBlB,SACzBP,OAAO0B,uBACPrB,MAAMI,WACR,GACMkB,YAAYhB,aAAuBP,QAAQ,GAC3CQ,iBAAiBD,kBAA4BP,QAAQ,GACrDwB,cACJD,WAAWb,KAAKC,SAChBH,eAAeA,eAAeiB,SAAS,CAAC,GAAGf,KAAKC;AAElD,aAAI,CAACU,sBAAsB,CAACG,cACnB,KAGF;AAAA,QAACZ,OAAOJ,eAAeK,IAAKC,WAAUA,MAAMC,IAAI,EAAEW,QAAQ;AAAA,MAAC;AAAA,IACpE;AAAA,IACAV,SAAS,CACP,CAACC,GAAG;AAAA,M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YAAMpD,OAAOzC,MAAMI,YAAY0F,aAAaC,QAAQ,YAAY,GAC1DT,MAAMD,aAAa5C,IAAI,IAAIA,OAAOM,QAClCiD,aACJV,QAAQvC,SACJpD,OAAOsG,iBAAiB;AAAA,QAACX;AAAAA,QAAKY,QAAQnG,SAASuC,QAAQ4D;AAAAA,MAAO,CAAA,IAC9DnD;AAEFuC,aAAAA,OAAOU,cAAcH,qBAChB;AAAA,QAACO;AAAAA,QAAWJ;AAAAA,QAAYV;AAAAA,MAAAA,IAG1B;AAAA,IACT;AAAA,IACAvE,SAAS,CACP,CAACC,GAAG;AAAA,MAACgF;AAAAA,MAAYV;AAAAA,IAAG,MAAM,CACxB3B,QAAQ;AAAA,MACNxC,MAAM;AAAA,MACNsB,MAAM6C;AAAAA,MACNe,aAAa,CAACL,UAAU;AAAA,IAAA,CACzB,CAAC,CACH;AAAA,EAAA,CAEJ;AAEqB,SAAA,CAACJ,sBAAsBO,gBAAgB;AAG/D;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/behaviors/behavior.code-editor.ts","../../src/behaviors/behavior.emoji-picker.ts","../../src/internal-utils/looks-like-url.ts","../../src/behaviors/behavior.links.ts"],"sourcesContent":["import {isHotkey} from '../internal-utils/is-hotkey'\nimport * as selectors from '../selectors'\nimport {raise} from './behavior.types.action'\nimport {defineBehavior} from './behavior.types.behavior'\n\n/**\n * @beta\n */\nexport type CodeEditorBehaviorsConfig = {\n moveBlockUpShortcut: string\n moveBlockDownShortcut: string\n}\n\n/**\n * @beta\n */\nexport function createCodeEditorBehaviors(config: CodeEditorBehaviorsConfig) {\n return [\n defineBehavior({\n on: 'keyboard.keydown',\n guard: ({snapshot, event}) => {\n const isMoveUpShortcut = isHotkey(\n config.moveBlockUpShortcut,\n event.originEvent,\n )\n const firstBlock = selectors.getFirstBlock(snapshot)\n const selectedBlocks = selectors.getSelectedBlocks(snapshot)\n const blocksAbove =\n firstBlock?.node._key !== selectedBlocks[0]?.node._key\n\n if (!isMoveUpShortcut || !blocksAbove) {\n return false\n }\n\n return {paths: selectedBlocks.map((block) => block.path)}\n },\n actions: [\n (_, {paths}) =>\n paths.map((at) =>\n raise({\n type: 'move.block up',\n at,\n }),\n ),\n ],\n }),\n defineBehavior({\n on: 'keyboard.keydown',\n guard: ({snapshot, event}) => {\n const isMoveDownShortcut = isHotkey(\n config.moveBlockDownShortcut,\n event.originEvent,\n )\n const lastBlock = selectors.getLastBlock(snapshot)\n const selectedBlocks = selectors.getSelectedBlocks(snapshot)\n const blocksBelow =\n lastBlock?.node._key !==\n selectedBlocks[selectedBlocks.length - 1]?.node._key\n\n if (!isMoveDownShortcut || !blocksBelow) {\n return false\n }\n\n return {paths: selectedBlocks.map((block) => block.path).reverse()}\n },\n actions: [\n (_, {paths}) =>\n paths.map((at) =>\n raise({\n type: 'move.block down',\n at,\n }),\n ),\n ],\n }),\n ]\n}\n","import {assertEvent, assign, createActor, setup} from 'xstate'\nimport {isHotkey} from '../internal-utils/is-hotkey'\nimport * as selectors from '../selectors'\nimport {effect, execute, noop} from './behavior.types.action'\nimport {defineBehavior} from './behavior.types.behavior'\n\nconst emojiCharRegEx = /^[a-zA-Z-_0-9]{1}$/\nconst incompleteEmojiRegEx = /:([a-zA-Z-_0-9]+)$/\nconst emojiRegEx = /:([a-zA-Z-_0-9]+):$/\n\n/**\n * @beta\n */\nexport type EmojiPickerBehaviorsConfig<TEmojiMatch> = {\n /**\n * Match emojis by keyword.\n */\n matchEmojis: ({keyword}: {keyword: string}) => Array<TEmojiMatch>\n onMatchesChanged: ({matches}: {matches: Array<TEmojiMatch>}) => void\n onSelectedIndexChanged: ({selectedIndex}: {selectedIndex: number}) => void\n /**\n * Parse an emoji match to a string that will be inserted into the editor.\n */\n parseMatch: ({match}: {match: TEmojiMatch}) => string | undefined\n}\n\n/**\n * @beta\n */\nexport function createEmojiPickerBehaviors<TEmojiMatch>(\n config: EmojiPickerBehaviorsConfig<TEmojiMatch>,\n) {\n const emojiPickerActor = createActor(createEmojiPickerMachine<TEmojiMatch>())\n emojiPickerActor.start()\n emojiPickerActor.subscribe((state) => {\n config.onMatchesChanged({matches: state.context.matches})\n config.onSelectedIndexChanged({selectedIndex: state.context.selectedIndex})\n })\n\n return [\n defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n if (event.text === ':') {\n return false\n }\n\n const isEmojiChar = emojiCharRegEx.test(event.text)\n\n if (!isEmojiChar) {\n return {emojis: []}\n }\n\n const focusBlock = selectors.getFocusTextBlock(snapshot)\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const emojiKeyword = `${textBefore}${event.text}`.match(\n incompleteEmojiRegEx,\n )?.[1]\n\n if (!focusBlock || emojiKeyword === undefined) {\n return {emojis: []}\n }\n\n const emojis = config.matchEmojis({keyword: emojiKeyword})\n\n return {emojis}\n },\n actions: [\n (_, params) => [\n {\n type: 'effect',\n effect: () => {\n emojiPickerActor.send({\n type: 'emojis found',\n matches: params.emojis,\n })\n },\n },\n ],\n ],\n }),\n defineBehavior({\n on: 'insert.text',\n guard: ({snapshot, event}) => {\n const isColon = event.text === ':'\n\n if (!isColon) {\n return false\n }\n\n const matches = emojiPickerActor.getSnapshot().context.matches\n const selectedIndex =\n emojiPickerActor.getSnapshot().context.selectedIndex\n const emoji = matches[selectedIndex]\n ? config.parseMatch({match: matches[selectedIndex]})\n : undefined\n\n const focusBlock = selectors.getFocusTextBlock(snapshot)\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const emojiKeyword = `${textBefore}:`.match(emojiRegEx)?.[1]\n\n if (!focusBlock || emojiKeyword === undefined) {\n return false\n }\n\n const emojiStringLength = emojiKeyword.length + 2\n\n if (emoji) {\n return {\n focusBlock,\n emoji,\n emojiStringLength,\n textBeforeLength: textBefore.length + 1,\n }\n }\n\n return false\n },\n actions: [\n () => [\n execute({\n type: 'insert.text',\n text: ':',\n }),\n ],\n (_, params) => [\n effect(() => {\n emojiPickerActor.send({type: 'select'})\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: params.focusBlock.path,\n offset: params.textBeforeLength - params.emojiStringLength,\n },\n focus: {\n path: params.focusBlock.path,\n offset: params.textBeforeLength,\n },\n },\n }),\n execute({\n type: 'insert.text',\n text: params.emoji,\n }),\n ],\n ],\n }),\n defineBehavior({\n on: 'keyboard.keydown',\n guard: ({snapshot, event}) => {\n const matches = emojiPickerActor.getSnapshot().context.matches\n\n if (matches.length === 0) {\n return false\n }\n\n const isEscape = isHotkey('Escape', event.originEvent)\n\n if (isEscape) {\n return {action: 'reset' as const}\n }\n\n const isEnter = isHotkey('Enter', event.originEvent)\n const isTab = isHotkey('Tab', event.originEvent)\n\n if (isEnter || isTab) {\n const selectedIndex =\n emojiPickerActor.getSnapshot().context.selectedIndex\n\n const emoji = matches[selectedIndex]\n ? config.parseMatch({match: matches[selectedIndex]})\n : undefined\n\n if (!emoji) {\n return false\n }\n\n const focusBlock = selectors.getFocusTextBlock(snapshot)\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const emojiKeyword = textBefore.match(incompleteEmojiRegEx)?.[1]\n\n if (!focusBlock || emojiKeyword === undefined) {\n return false\n }\n\n const emojiStringLength = emojiKeyword.length + 1\n\n if (emoji) {\n return {\n action: 'select' as const,\n focusBlock,\n emoji,\n emojiStringLength,\n textBeforeLength: textBefore.length,\n }\n }\n\n return false\n }\n\n const isArrowDown = isHotkey('ArrowDown', event.originEvent)\n const isArrowUp = isHotkey('ArrowUp', event.originEvent)\n\n if (isArrowDown && matches.length > 0) {\n return {action: 'navigate down' as const}\n }\n\n if (isArrowUp && matches.length > 0) {\n return {action: 'navigate up' as const}\n }\n\n return false\n },\n actions: [\n (_, params) => {\n if (params.action === 'select') {\n return [\n effect(() => {\n emojiPickerActor.send({type: 'select'})\n }),\n execute({\n type: 'delete.text',\n at: {\n anchor: {\n path: params.focusBlock.path,\n offset: params.textBeforeLength - params.emojiStringLength,\n },\n focus: {\n path: params.focusBlock.path,\n offset: params.textBeforeLength,\n },\n },\n }),\n execute({\n type: 'insert.text',\n text: params.emoji,\n }),\n ]\n }\n\n if (params.action === 'navigate up') {\n return [\n // If we are navigating then we want to hijack the key event and\n // turn it into a noop.\n noop(),\n effect(() => {\n emojiPickerActor.send({type: 'navigate up'})\n }),\n ]\n }\n\n if (params.action === 'navigate down') {\n return [\n // If we are navigating then we want to hijack the key event and\n // turn it into a noop.\n noop(),\n effect(() => {\n emojiPickerActor.send({type: 'navigate down'})\n }),\n ]\n }\n\n return [\n effect(() => {\n emojiPickerActor.send({type: 'reset'})\n }),\n ]\n },\n ],\n }),\n defineBehavior({\n on: 'delete.backward',\n guard: ({snapshot, event}) => {\n if (event.unit !== 'character') {\n return false\n }\n\n const matches = emojiPickerActor.getSnapshot().context.matches\n\n if (matches.length === 0) {\n return false\n }\n\n const focusBlock = selectors.getFocusTextBlock(snapshot)\n const textBefore = selectors.getBlockTextBefore(snapshot)\n const emojiKeyword = textBefore\n .slice(0, textBefore.length - 1)\n .match(incompleteEmojiRegEx)?.[1]\n\n if (!focusBlock || emojiKeyword === undefined) {\n return {emojis: []}\n }\n\n const emojis = config.matchEmojis({keyword: emojiKeyword})\n\n return {emojis}\n },\n actions: [\n (_, params) => [\n {\n type: 'effect',\n effect: () => {\n emojiPickerActor.send({\n type: 'emojis found',\n matches: params.emojis,\n })\n },\n },\n ],\n ],\n }),\n ]\n}\n\nfunction createEmojiPickerMachine<TEmojiSearchResult>() {\n return setup({\n types: {\n context: {} as {\n matches: Array<TEmojiSearchResult>\n selectedIndex: number\n },\n events: {} as\n | {\n type: 'emojis found'\n matches: Array<TEmojiSearchResult>\n }\n | {\n type: 'navigate down' | 'navigate up' | 'select' | 'reset'\n },\n },\n actions: {\n 'assign matches': assign({\n matches: ({event}) => {\n assertEvent(event, 'emojis found')\n return event.matches\n },\n }),\n 'reset matches': assign({\n matches: [],\n }),\n 'reset selected index': assign({\n selectedIndex: 0,\n }),\n 'increment selected index': assign({\n selectedIndex: ({context}) => {\n if (context.selectedIndex === context.matches.length - 1) {\n return 0\n }\n return context.selectedIndex + 1\n },\n }),\n 'decrement selected index': assign({\n selectedIndex: ({context}) => {\n if (context.selectedIndex === 0) {\n return context.matches.length - 1\n }\n return context.selectedIndex - 1\n },\n }),\n },\n guards: {\n 'no matches': ({context}) => context.matches.length === 0,\n },\n }).createMachine({\n id: 'emoji picker',\n context: {\n matches: [],\n selectedIndex: 0,\n },\n initial: 'idle',\n states: {\n 'idle': {\n on: {\n 'emojis found': {\n actions: 'assign matches',\n target: 'showing matches',\n },\n },\n },\n 'showing matches': {\n always: {\n guard: 'no matches',\n target: 'idle',\n },\n exit: ['reset selected index'],\n on: {\n 'emojis found': {\n actions: 'assign matches',\n },\n 'navigate down': {\n actions: 'increment selected index',\n },\n 'navigate up': {\n actions: 'decrement selected index',\n },\n 'reset': {\n target: 'idle',\n actions: ['reset selected index', 'reset matches'],\n },\n 'select': {\n target: 'idle',\n actions: ['reset selected index', 'reset matches'],\n },\n },\n },\n },\n })\n}\n","export function looksLikeUrl(text: string) {\n let looksLikeUrl = false\n try {\n const url = new URL(text)\n\n if (!sensibleProtocols.includes(url.protocol)) {\n return false\n }\n\n looksLikeUrl = true\n } catch {}\n return looksLikeUrl\n}\n\nconst sensibleProtocols = ['http:', 'https:', 'mailto:', 'tel:']\n","import type {EditorSchema} from '../editor/editor-schema'\nimport {looksLikeUrl} from '../internal-utils/looks-like-url'\nimport * as selectors from '../selectors'\nimport {execute} from './behavior.types.action'\nimport {defineBehavior} from './behavior.types.behavior'\n\n/**\n * @beta\n */\nexport type LinkBehaviorsConfig = {\n linkAnnotation?: (context: {\n schema: EditorSchema\n url: string\n }) => {name: string; value: {[prop: string]: unknown}} | undefined\n}\n\n/**\n * @beta\n */\nexport function createLinkBehaviors(config: LinkBehaviorsConfig) {\n const pasteLinkOnSelection = defineBehavior({\n on: 'clipboard.paste',\n guard: ({snapshot, event}) => {\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n const text = event.originEvent.dataTransfer.getData('text/plain')\n const url = looksLikeUrl(text) ? text : undefined\n const annotation =\n url !== undefined\n ? config.linkAnnotation?.({url, schema: snapshot.context.schema})\n : undefined\n\n if (annotation && !selectionCollapsed) {\n return {annotation}\n }\n\n return false\n },\n actions: [\n (_, {annotation}) => [\n execute({\n type: 'annotation.add',\n annotation,\n }),\n ],\n ],\n })\n const pasteLinkAtCaret = defineBehavior({\n on: 'clipboard.paste',\n guard: ({snapshot, event}) => {\n const focusSpan = selectors.getFocusSpan(snapshot)\n const selectionCollapsed = selectors.isSelectionCollapsed(snapshot)\n\n if (!focusSpan || !selectionCollapsed) {\n return false\n }\n\n const text = event.originEvent.dataTransfer.getData('text/plain')\n const url = looksLikeUrl(text) ? text : undefined\n const annotation =\n url !== undefined\n ? config.linkAnnotation?.({url, schema: snapshot.context.schema})\n : undefined\n\n if (url && annotation && selectionCollapsed) {\n return {focusSpan, annotation, url}\n }\n\n return false\n },\n actions: [\n (_, {annotation, url}) => [\n execute({\n type: 'insert.span',\n text: url,\n annotations: [annotation],\n }),\n ],\n ],\n })\n\n const linkBehaviors = [pasteLinkOnSelection, pasteLinkAtCaret]\n\n return linkBehaviors\n}\n"],"names":["createCodeEditorBehaviors","config","defineBehavior","on","guard","snapshot","event","isMoveUpShortcut","isHotkey","moveBlockUpShortcut","originEvent","firstBlock","selectors","selectedBlocks","blocksAbove","node","_key","paths","map","block","path","actions","_","at","raise","type","isMoveDownShortcut","moveBlockDownShortcut","lastBlock","blocksBelow","length","reverse","emojiCharRegEx","incompleteEmojiRegEx","emojiRegEx","createEmojiPickerBehaviors","emojiPickerActor","createActor","createEmojiPickerMachine","start","subscribe","state","onMatchesChanged","matches","context","onSelectedIndexChanged","selectedIndex","text","test","emojis","focusBlock","emojiKeyword","match","undefined","matchEmojis","keyword","params","effect","send","getSnapshot","emoji","parseMatch","textBefore","emojiStringLength","textBeforeLength","execute","anchor","offset","focus","action","isEnter","isTab","isArrowDown","isArrowUp","noop","unit","slice","setup","types","events","assign","assertEvent","guards","no matches","createMachine","id","initial","states","target","always","exit","looksLikeUrl","url","URL","sensibleProtocols","includes","protocol","createLinkBehaviors","pasteLinkOnSelection","selectionCollapsed","dataTransfer","getData","annotation","linkAnnotation","schema","pasteLinkAtCaret","focusSpan","annotations"],"mappings":";;;;;;AAgBO,SAASA,0BAA0BC,QAAmC;AAC3E,SAAO,CACLC,eAAe;AAAA,IACbC,IAAI;AAAA,IACJC,OAAOA,CAAC;AAAA,MAACC;AAAAA,MAAUC;AAAAA,IAAAA,MAAW;AACtBC,YAAAA,mBAAmBC,SACvBP,OAAOQ,qBACPH,MAAMI,WACR,GACMC,aAAaC,cAAwBP,QAAQ,GAC7CQ,iBAAiBD,kBAA4BP,QAAQ,GACrDS,cACJH,YAAYI,KAAKC,SAASH,eAAe,CAAC,GAAGE,KAAKC;AAEpD,aAAI,CAACT,oBAAoB,CAACO,cACjB,KAGF;AAAA,QAACG,OAAOJ,eAAeK,IAAKC,CAAAA,UAAUA,MAAMC,IAAI;AAAA,MAAC;AAAA,IAC1D;AAAA,IACAC,SAAS,CACP,CAACC,GAAG;AAAA,MAACL;AAAAA,IACHA,MAAAA,MAAMC,IAAKK,CAAAA,OACTC,MAAM;AAAA,MACJC,MAAM;AAAA,MACNF;AAAAA,IAAAA,CACD,CACH,CAAC;AAAA,EAEN,CAAA,GACDrB,eAAe;AAAA,IACbC,IAAI;AAAA,IACJC,OAAOA,CAAC;AAAA,MAACC;AAAAA,MAAUC;AAAAA,IAAAA,MAAW;AACtBoB,YAAAA,qBAAqBlB,SACzBP,OAAO0B,uBACPrB,MAAMI,WACR,GACMkB,YAAYhB,aAAuBP,QAAQ,GAC3CQ,iBAAiBD,kBAA4BP,QAAQ,GACrDwB,cACJD,WAAWb,KAAKC,SAChBH,eAAeA,eAAeiB,SAAS,CAAC,GAAGf,KAAKC;AAElD,aAAI,CAACU,sBAAsB,CAACG,cACnB,KAGF;AAAA,QAACZ,OAAOJ,eAAeK,IAAKC,WAAUA,MAAMC,IAAI,EAAEW,QAAQ;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qBAA+BP,QAAQ;AAE9D,UAAA,CAACqG,aAAa,CAACP;AACV,eAAA;AAGT,YAAMpD,OAAOzC,MAAMI,YAAY0F,aAAaC,QAAQ,YAAY,GAC1DT,MAAMD,aAAa5C,IAAI,IAAIA,OAAOM,QAClCiD,aACJV,QAAQvC,SACJpD,OAAOsG,iBAAiB;AAAA,QAACX;AAAAA,QAAKY,QAAQnG,SAASuC,QAAQ4D;AAAAA,MAAO,CAAA,IAC9DnD;AAEFuC,aAAAA,OAAOU,cAAcH,qBAChB;AAAA,QAACO;AAAAA,QAAWJ;AAAAA,QAAYV;AAAAA,MAAAA,IAG1B;AAAA,IACT;AAAA,IACAvE,SAAS,CACP,CAACC,GAAG;AAAA,MAACgF;AAAAA,MAAYV;AAAAA,IAAG,MAAM,CACxB3B,QAAQ;AAAA,MACNxC,MAAM;AAAA,MACNsB,MAAM6C;AAAAA,MACNe,aAAa,CAACL,UAAU;AAAA,IAAA,CACzB,CAAC,CACH;AAAA,EAAA,CAEJ;AAEqB,SAAA,CAACJ,sBAAsBO,gBAAgB;AAG/D;"}
|
package/lib/index.cjs
CHANGED
|
@@ -1036,18 +1036,18 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1036
1036
|
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
1037
1037
|
const editorActor = React.useContext(editorProvider.EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.matches({
|
|
1038
1038
|
"edit mode": "read only"
|
|
1039
|
-
})),
|
|
1039
|
+
})), slateEditor = slateReact.useSlate(), rangeDecorationsActor = react.useActorRef(rangeDecorationsMachine, {
|
|
1040
1040
|
input: {
|
|
1041
1041
|
rangeDecorations: rangeDecorations ?? [],
|
|
1042
1042
|
readOnly,
|
|
1043
|
-
schema:
|
|
1043
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1044
1044
|
slateEditor,
|
|
1045
1045
|
skipSetup: !editorActor.getSnapshot().matches({
|
|
1046
1046
|
setup: "setting up"
|
|
1047
1047
|
})
|
|
1048
1048
|
}
|
|
1049
1049
|
});
|
|
1050
|
-
react.useSelector(rangeDecorationsActor, (
|
|
1050
|
+
react.useSelector(rangeDecorationsActor, (s_0) => s_0.context.updateCount);
|
|
1051
1051
|
const decorate = React.useMemo(() => createDecorate(rangeDecorationsActor), [rangeDecorationsActor]);
|
|
1052
1052
|
React.useEffect(() => {
|
|
1053
1053
|
rangeDecorationsActor.send({
|
|
@@ -1059,17 +1059,15 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1059
1059
|
type: "range decorations updated",
|
|
1060
1060
|
rangeDecorations: rangeDecorations ?? []
|
|
1061
1061
|
});
|
|
1062
|
-
}, [rangeDecorationsActor, rangeDecorations])
|
|
1063
|
-
const blockTypeName = schemaTypes.block.name;
|
|
1064
|
-
React.useMemo(() => {
|
|
1062
|
+
}, [rangeDecorationsActor, rangeDecorations]), React.useMemo(() => {
|
|
1065
1063
|
if (readOnly)
|
|
1066
1064
|
return debug("Editable is in read only mode"), slateEditor;
|
|
1067
1065
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
1068
1066
|
return debug("Editable is in edit mode"), withHotKeys(slateEditor);
|
|
1069
1067
|
}, [editorActor, hotkeys, portableTextEditor, readOnly, slateEditor]);
|
|
1070
|
-
const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element$1, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [
|
|
1068
|
+
const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element$1, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes: portableTextEditor.schemaTypes, spellCheck }), [portableTextEditor, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = React.useCallback((lProps) => {
|
|
1071
1069
|
if (lProps.leaf._type === "span") {
|
|
1072
|
-
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|
|
1070
|
+
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes: portableTextEditor.schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|
|
1073
1071
|
if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
|
|
1074
1072
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1075
1073
|
/* @__PURE__ */ jsxRuntime.jsx("span", { style: PLACEHOLDER_STYLE, contentEditable: !1, children: renderPlaceholder() }),
|
|
@@ -1081,10 +1079,10 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1081
1079
|
})), rendered;
|
|
1082
1080
|
}
|
|
1083
1081
|
return lProps.children;
|
|
1084
|
-
}, [editorActor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder
|
|
1082
|
+
}, [editorActor, portableTextEditor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder]), restoreSelectionFromProps = React.useCallback(() => {
|
|
1085
1083
|
if (propsSelection) {
|
|
1086
1084
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
1087
|
-
const normalizedSelection = normalizeSelection(propsSelection, editorProvider.fromSlateValue(slateEditor.children,
|
|
1085
|
+
const normalizedSelection = normalizeSelection(propsSelection, editorProvider.fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
|
|
1088
1086
|
if (normalizedSelection !== null) {
|
|
1089
1087
|
debug(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
|
|
1090
1088
|
const slateRange = editorProvider.toSlateRange(normalizedSelection, slateEditor);
|
|
@@ -1094,7 +1092,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1094
1092
|
}), slateEditor.onChange());
|
|
1095
1093
|
}
|
|
1096
1094
|
}
|
|
1097
|
-
}, [
|
|
1095
|
+
}, [editorActor, propsSelection, slateEditor]);
|
|
1098
1096
|
React.useEffect(() => {
|
|
1099
1097
|
const onReady = editorActor.on("ready", () => {
|
|
1100
1098
|
rangeDecorationsActor.send({
|
|
@@ -1167,14 +1165,14 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1167
1165
|
}
|
|
1168
1166
|
}, [onCut, editorActor, slateEditor]), handlePaste = React.useCallback((event_1) => {
|
|
1169
1167
|
const value = editorProvider.PortableTextEditor.getValue(portableTextEditor), path = (slateEditor.selection ? editorProvider.slateRangeToSelection({
|
|
1170
|
-
schema:
|
|
1168
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
1171
1169
|
editor: slateEditor,
|
|
1172
1170
|
range: slateEditor.selection
|
|
1173
1171
|
}) : null)?.focus.path || [], onPasteResult = onPaste?.({
|
|
1174
1172
|
event: event_1,
|
|
1175
1173
|
value,
|
|
1176
1174
|
path,
|
|
1177
|
-
schemaTypes
|
|
1175
|
+
schemaTypes: portableTextEditor.schemaTypes
|
|
1178
1176
|
});
|
|
1179
1177
|
if (onPasteResult || !slateEditor.selection)
|
|
1180
1178
|
event_1.preventDefault(), editorActor.send({
|
|
@@ -1247,7 +1245,7 @@ const debug = editorProvider.debugWithName("component:Editable"), PLACEHOLDER_ST
|
|
|
1247
1245
|
});
|
|
1248
1246
|
}
|
|
1249
1247
|
debug("No result from custom paste handler, pasting normally");
|
|
1250
|
-
}, [editorActor, onPaste, portableTextEditor,
|
|
1248
|
+
}, [editorActor, onPaste, portableTextEditor, slateEditor]), handleOnFocus = React.useCallback((event_2) => {
|
|
1251
1249
|
if (onFocus && onFocus(event_2), !event_2.isDefaultPrevented()) {
|
|
1252
1250
|
const selection_3 = editorProvider.PortableTextEditor.getSelection(portableTextEditor);
|
|
1253
1251
|
selection_3 === null && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()), editorActor.send({
|