@prosekit/core 0.10.0 → 0.12.0-beta.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/dist/{editor-BULC1zqX.d.ts → editor.d.ts} +48 -8
- package/dist/editor.d.ts.map +1 -0
- package/dist/{editor-g-Rqn-ZE.js → editor.js} +19 -60
- package/dist/editor.js.map +1 -0
- package/dist/prosekit-core-test.d.ts +1 -1
- package/dist/prosekit-core-test.js +2 -4
- package/dist/prosekit-core-test.js.map +1 -1
- package/dist/prosekit-core.d.ts +69 -68
- package/dist/prosekit-core.d.ts.map +1 -1
- package/dist/prosekit-core.js +100 -135
- package/dist/prosekit-core.js.map +1 -1
- package/package.json +6 -5
- package/src/commands/add-mark.ts +2 -2
- package/src/commands/expand-mark.ts +1 -1
- package/src/commands/insert-default-block.spec.ts +3 -3
- package/src/commands/insert-default-block.ts +1 -1
- package/src/commands/insert-node.ts +3 -3
- package/src/commands/remove-mark.ts +2 -2
- package/src/commands/remove-node.ts +2 -2
- package/src/commands/select-block.spec.ts +2 -2
- package/src/commands/select-block.ts +1 -1
- package/src/commands/set-block-type.ts +2 -2
- package/src/commands/set-node-attrs-between.spec.ts +2 -2
- package/src/commands/set-node-attrs-between.ts +1 -1
- package/src/commands/set-node-attrs.spec.ts +2 -2
- package/src/commands/set-node-attrs.ts +2 -2
- package/src/commands/toggle-mark.ts +2 -2
- package/src/commands/toggle-node.ts +2 -2
- package/src/commands/toggle-wrap.spec.ts +1 -1
- package/src/commands/toggle-wrap.ts +2 -2
- package/src/commands/unset-block-type.spec.ts +1 -1
- package/src/commands/unset-block-type.ts +1 -1
- package/src/commands/unset-mark.spec.ts +1 -1
- package/src/commands/unset-mark.ts +1 -1
- package/src/commands/wrap.ts +1 -1
- package/src/editor/action.spec.ts +3 -3
- package/src/editor/action.ts +6 -6
- package/src/editor/editor.spec.ts +5 -5
- package/src/editor/editor.ts +13 -13
- package/src/editor/union.spec.ts +7 -7
- package/src/editor/union.ts +4 -4
- package/src/editor/with-priority.ts +3 -3
- package/src/error.ts +8 -1
- package/src/extensions/clipboard-serializer.ts +17 -9
- package/src/extensions/command.ts +19 -19
- package/src/extensions/default-state.spec.ts +3 -3
- package/src/extensions/default-state.ts +5 -5
- package/src/extensions/events/doc-change.ts +2 -2
- package/src/extensions/events/dom-event.spec.ts +3 -3
- package/src/extensions/events/dom-event.ts +7 -7
- package/src/extensions/events/editor-event.ts +6 -6
- package/src/extensions/events/focus.spec.ts +4 -4
- package/src/extensions/events/focus.ts +2 -2
- package/src/extensions/events/plugin-view.ts +4 -4
- package/src/extensions/history.ts +6 -6
- package/src/extensions/keymap-base.spec.ts +5 -5
- package/src/extensions/keymap-base.ts +6 -6
- package/src/extensions/keymap.spec.ts +5 -5
- package/src/extensions/keymap.ts +4 -4
- package/src/extensions/mark-spec.spec.ts +3 -3
- package/src/extensions/mark-spec.ts +8 -8
- package/src/extensions/mark-view-effect.ts +4 -4
- package/src/extensions/mark-view.ts +4 -4
- package/src/extensions/node-spec.spec.ts +5 -5
- package/src/extensions/node-spec.ts +8 -8
- package/src/extensions/node-view-effect.ts +4 -4
- package/src/extensions/node-view.ts +4 -4
- package/src/extensions/plugin.spec.ts +5 -5
- package/src/extensions/plugin.ts +5 -5
- package/src/facets/base-extension.ts +7 -7
- package/src/facets/command.ts +3 -3
- package/src/facets/facet-extension.spec.ts +6 -6
- package/src/facets/facet-extension.ts +12 -8
- package/src/facets/facet-node.spec.ts +3 -3
- package/src/facets/facet-node.ts +24 -14
- package/src/facets/facet.spec.ts +1 -1
- package/src/facets/facet.ts +14 -7
- package/src/facets/root.ts +2 -2
- package/src/facets/schema-spec.ts +2 -2
- package/src/facets/schema.ts +3 -3
- package/src/facets/state.spec.ts +6 -6
- package/src/facets/state.ts +3 -3
- package/src/facets/union-extension.ts +9 -6
- package/src/index.ts +74 -74
- package/src/test/index.ts +1 -1
- package/src/test/test-builder.ts +2 -2
- package/src/test/test-editor.spec.ts +1 -1
- package/src/test/test-editor.ts +6 -6
- package/src/testing/index.ts +10 -10
- package/src/types/extension-mark.ts +1 -1
- package/src/types/extension-node.ts +1 -1
- package/src/types/extension.spec.ts +2 -2
- package/src/types/extension.ts +8 -8
- package/src/types/pick-string-literal.spec.ts +2 -2
- package/src/types/pick-string-literal.ts +1 -1
- package/src/types/pick-sub-type.spec.ts +2 -2
- package/src/types/priority.ts +50 -7
- package/src/types/simplify-deeper.spec.ts +2 -2
- package/src/types/simplify-union.spec.ts +2 -2
- package/src/utils/array-grouping.spec.ts +1 -1
- package/src/utils/assert.ts +1 -1
- package/src/utils/can-use-regex-lookbehind.ts +2 -8
- package/src/utils/clsx.spec.ts +1 -1
- package/src/utils/combine-event-handlers.spec.ts +1 -1
- package/src/utils/editor-content.spec.ts +2 -2
- package/src/utils/editor-content.ts +4 -4
- package/src/utils/find-parent-node-of-type.ts +2 -2
- package/src/utils/find-parent-node.spec.ts +2 -2
- package/src/utils/get-dom-api.ts +1 -1
- package/src/utils/get-mark-type.ts +1 -1
- package/src/utils/get-node-type.ts +1 -1
- package/src/utils/get-node-types.ts +1 -1
- package/src/utils/includes-mark.ts +1 -1
- package/src/utils/is-mark-absent.spec.ts +2 -2
- package/src/utils/is-mark-absent.ts +1 -1
- package/src/utils/is-mark-active.ts +3 -3
- package/src/utils/is-node-active.spec.ts +2 -2
- package/src/utils/is-node-active.ts +3 -3
- package/src/utils/is-subset.spec.ts +1 -1
- package/src/utils/maybe-run.spec.ts +1 -1
- package/src/utils/merge-objects.spec.ts +1 -1
- package/src/utils/merge-objects.ts +1 -1
- package/src/utils/merge-specs.ts +1 -1
- package/src/utils/object-equal.spec.ts +1 -1
- package/src/utils/output-spec.test.ts +1 -1
- package/src/utils/parse.spec.ts +3 -3
- package/src/utils/parse.ts +3 -3
- package/src/utils/remove-undefined-values.spec.ts +1 -1
- package/src/utils/unicode.spec.ts +1 -1
- package/src/utils/with-skip-code-block.ts +1 -1
- package/dist/editor-BULC1zqX.d.ts.map +0 -1
- package/dist/editor-g-Rqn-ZE.js.map +0 -1
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
|
|
2
2
|
import type { DOMEventMap, EditorView } from '@prosekit/pm/view'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import type { PlainExtension } from '../../types/extension'
|
|
7
|
-
import type { Setter } from '../../types/setter'
|
|
8
|
-
import { groupEntries } from '../../utils/array-grouping'
|
|
9
|
-
import { combineEventHandlers } from '../../utils/combine-event-handlers'
|
|
10
|
-
import { pluginFacet, type PluginPayload } from '../plugin'
|
|
4
|
+
import { defineFacetPayload } from '../../facets/facet-extension.ts'
|
|
5
|
+
import { defineFacet, type Facet } from '../../facets/facet.ts'
|
|
6
|
+
import type { PlainExtension } from '../../types/extension.ts'
|
|
7
|
+
import type { Setter } from '../../types/setter.ts'
|
|
8
|
+
import { groupEntries } from '../../utils/array-grouping.ts'
|
|
9
|
+
import { combineEventHandlers } from '../../utils/combine-event-handlers.ts'
|
|
10
|
+
import { pluginFacet, type PluginPayload } from '../plugin.ts'
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* A function to handle the events fired on the editable DOM element. Returns
|
|
@@ -3,12 +3,12 @@ import type { Node, Slice } from '@prosekit/pm/model'
|
|
|
3
3
|
import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
|
|
4
4
|
import type { EditorView } from '@prosekit/pm/view'
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import type { PlainExtension } from '../../types/extension'
|
|
9
|
-
import { groupEntries } from '../../utils/array-grouping'
|
|
10
|
-
import { combineEventHandlers } from '../../utils/combine-event-handlers'
|
|
11
|
-
import { pluginFacet, type PluginPayload } from '../plugin'
|
|
6
|
+
import { defineFacetPayload } from '../../facets/facet-extension.ts'
|
|
7
|
+
import { defineFacet, type Facet } from '../../facets/facet.ts'
|
|
8
|
+
import type { PlainExtension } from '../../types/extension.ts'
|
|
9
|
+
import { groupEntries } from '../../utils/array-grouping.ts'
|
|
10
|
+
import { combineEventHandlers } from '../../utils/combine-event-handlers.ts'
|
|
11
|
+
import { pluginFacet, type PluginPayload } from '../plugin.ts'
|
|
12
12
|
|
|
13
13
|
export type KeyDownHandler = (
|
|
14
14
|
view: EditorView,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { describe, expect, it, vi } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { createEditor } from '../../editor/editor'
|
|
4
|
-
import { union } from '../../editor/union'
|
|
5
|
-
import { defineTestExtension } from '../../testing'
|
|
3
|
+
import { createEditor } from '../../editor/editor.ts'
|
|
4
|
+
import { union } from '../../editor/union.ts'
|
|
5
|
+
import { defineTestExtension } from '../../testing/index.ts'
|
|
6
6
|
|
|
7
|
-
import { defineFocusChangeHandler } from './focus'
|
|
7
|
+
import { defineFocusChangeHandler } from './focus.ts'
|
|
8
8
|
|
|
9
9
|
describe('defineFocusChangeHandler', () => {
|
|
10
10
|
it('should call the handler when the editor is focused or blurred', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { PlainExtension } from '../../types/extension'
|
|
1
|
+
import type { PlainExtension } from '../../types/extension.ts'
|
|
2
2
|
|
|
3
|
-
import { defineDomEventFacetPayload } from './dom-event'
|
|
3
|
+
import { defineDomEventFacetPayload } from './dom-event.ts'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* A function that is called when the editor gains or loses focus.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { PluginKey, ProseMirrorPlugin, type EditorState } from '@prosekit/pm/state'
|
|
2
2
|
import type { EditorView } from '@prosekit/pm/view'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import type { PlainExtension } from '../../types/extension'
|
|
7
|
-
import { pluginFacet, type PluginPayload } from '../plugin'
|
|
4
|
+
import { defineFacetPayload } from '../../facets/facet-extension.ts'
|
|
5
|
+
import { defineFacet } from '../../facets/facet.ts'
|
|
6
|
+
import type { PlainExtension } from '../../types/extension.ts'
|
|
7
|
+
import { pluginFacet, type PluginPayload } from '../plugin.ts'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* A function that is called when the editor view is mounted.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { history, redo, undo } from '@prosekit/pm/history'
|
|
2
2
|
|
|
3
|
-
import { union } from '../editor/union'
|
|
4
|
-
import type { Extension } from '../types/extension'
|
|
5
|
-
import { isApple } from '../utils/env'
|
|
3
|
+
import { union } from '../editor/union.ts'
|
|
4
|
+
import type { Extension } from '../types/extension.ts'
|
|
5
|
+
import { isApple } from '../utils/env.ts'
|
|
6
6
|
|
|
7
|
-
import { defineCommands } from './command'
|
|
8
|
-
import { defineKeymap, type Keymap } from './keymap'
|
|
9
|
-
import { definePlugin } from './plugin'
|
|
7
|
+
import { defineCommands } from './command.ts'
|
|
8
|
+
import { defineKeymap, type Keymap } from './keymap.ts'
|
|
9
|
+
import { definePlugin } from './plugin.ts'
|
|
10
10
|
|
|
11
11
|
const keymap: Keymap = {
|
|
12
12
|
'Mod-z': undo,
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
2
|
import { keyboard } from 'vitest-browser-commands/playwright'
|
|
3
3
|
|
|
4
|
-
import { union } from '../editor/union'
|
|
5
|
-
import type { TestEditor } from '../test'
|
|
6
|
-
import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing'
|
|
7
|
-
import type { SelectionJSON } from '../types/model'
|
|
4
|
+
import { union } from '../editor/union.ts'
|
|
5
|
+
import type { TestEditor } from '../test/index.ts'
|
|
6
|
+
import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing/index.ts'
|
|
7
|
+
import type { SelectionJSON } from '../types/model.ts'
|
|
8
8
|
|
|
9
|
-
import { defineBaseKeymap } from './keymap-base'
|
|
9
|
+
import { defineBaseKeymap } from './keymap-base.ts'
|
|
10
10
|
|
|
11
11
|
describe('Mod-a', () => {
|
|
12
12
|
it('can select the block for the first Mod-a press', async () => {
|
|
@@ -11,12 +11,12 @@ import {
|
|
|
11
11
|
} from '@prosekit/pm/commands'
|
|
12
12
|
import { splitSplittableBlock } from 'prosemirror-splittable'
|
|
13
13
|
|
|
14
|
-
import { selectBlockCommand } from '../commands/select-block'
|
|
15
|
-
import { withPriority } from '../editor/with-priority'
|
|
16
|
-
import type { PlainExtension } from '../types/extension'
|
|
17
|
-
import { Priority } from '../types/priority'
|
|
14
|
+
import { selectBlockCommand } from '../commands/select-block.ts'
|
|
15
|
+
import { withPriority } from '../editor/with-priority.ts'
|
|
16
|
+
import type { PlainExtension } from '../types/extension.ts'
|
|
17
|
+
import type { Priority } from '../types/priority.ts'
|
|
18
18
|
|
|
19
|
-
import { defineKeymap, type Keymap } from './keymap'
|
|
19
|
+
import { defineKeymap, type Keymap } from './keymap.ts'
|
|
20
20
|
|
|
21
21
|
// Replace `splitBlock` with `splitSplittableBlock`
|
|
22
22
|
const customEnter = chainCommands(
|
|
@@ -68,7 +68,7 @@ export interface BaseKeymapOptions {
|
|
|
68
68
|
* @public
|
|
69
69
|
*/
|
|
70
70
|
export function defineBaseKeymap({
|
|
71
|
-
priority = Priority.low,
|
|
71
|
+
priority = (1 satisfies typeof Priority.low),
|
|
72
72
|
preferBlockSelection = true,
|
|
73
73
|
}: BaseKeymapOptions = {}): BaseKeymapExtension {
|
|
74
74
|
const keymap: Keymap = {
|
|
@@ -2,12 +2,12 @@ import type { Command } from '@prosekit/pm/state'
|
|
|
2
2
|
import { describe, expect, it, vi } from 'vitest'
|
|
3
3
|
import { keyboard } from 'vitest-browser-commands/playwright'
|
|
4
4
|
|
|
5
|
-
import { union } from '../editor/union'
|
|
6
|
-
import { withPriority } from '../editor/with-priority'
|
|
7
|
-
import { defineDoc, defineParagraph, defineText, setupTest, setupTestFromExtension } from '../testing'
|
|
8
|
-
import { Priority } from '../types/priority'
|
|
5
|
+
import { union } from '../editor/union.ts'
|
|
6
|
+
import { withPriority } from '../editor/with-priority.ts'
|
|
7
|
+
import { defineDoc, defineParagraph, defineText, setupTest, setupTestFromExtension } from '../testing/index.ts'
|
|
8
|
+
import { Priority } from '../types/priority.ts'
|
|
9
9
|
|
|
10
|
-
import { defineKeymap, type Keymap } from './keymap'
|
|
10
|
+
import { defineKeymap, type Keymap } from './keymap.ts'
|
|
11
11
|
|
|
12
12
|
describe('keymap', () => {
|
|
13
13
|
it('can register and unregister keymap', () => {
|
package/src/extensions/keymap.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { keydownHandler } from '@prosekit/pm/keymap'
|
|
|
2
2
|
import { Plugin, PluginKey, type Command } from '@prosekit/pm/state'
|
|
3
3
|
import type { EditorView } from '@prosekit/pm/view'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import type { PlainExtension } from '../types/extension'
|
|
5
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
6
|
+
import { defineFacet, type Facet } from '../facets/facet.ts'
|
|
7
|
+
import type { PlainExtension } from '../types/extension.ts'
|
|
8
8
|
|
|
9
|
-
import { pluginFacet, type PluginPayload } from './plugin'
|
|
9
|
+
import { pluginFacet, type PluginPayload } from './plugin.ts'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* A set of keybindings. Please read the
|
|
@@ -2,10 +2,10 @@ import type { DOMOutputSpec, TagParseRule } from '@prosekit/pm/model'
|
|
|
2
2
|
import { formatHTML } from 'diffable-html-snapshot'
|
|
3
3
|
import { describe, expect, it } from 'vitest'
|
|
4
4
|
|
|
5
|
-
import { union } from '../editor/union'
|
|
6
|
-
import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing'
|
|
5
|
+
import { union } from '../editor/union.ts'
|
|
6
|
+
import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing/index.ts'
|
|
7
7
|
|
|
8
|
-
import { defineMarkAttr, defineMarkSpec } from './mark-spec'
|
|
8
|
+
import { defineMarkAttr, defineMarkSpec } from './mark-spec.ts'
|
|
9
9
|
|
|
10
10
|
describe('defineMarkSpec', () => {
|
|
11
11
|
it('can merge mark specs', () => {
|
|
@@ -2,14 +2,14 @@ import { isNotNullish, mapGroupBy } from '@ocavue/utils'
|
|
|
2
2
|
import type { AttributeSpec, MarkSpec, SchemaSpec } from '@prosekit/pm/model'
|
|
3
3
|
import OrderedMap from 'orderedmap'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { schemaSpecFacet } from '../facets/schema-spec'
|
|
8
|
-
import type { AnyAttrs, AttrSpec } from '../types/attrs'
|
|
9
|
-
import type { Extension } from '../types/extension'
|
|
10
|
-
import { assert } from '../utils/assert'
|
|
11
|
-
import { mergeSpecs } from '../utils/merge-specs'
|
|
12
|
-
import { wrapOutputSpecAttrs, wrapParseRuleAttrs } from '../utils/output-spec'
|
|
5
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
6
|
+
import { defineFacet } from '../facets/facet.ts'
|
|
7
|
+
import { schemaSpecFacet } from '../facets/schema-spec.ts'
|
|
8
|
+
import type { AnyAttrs, AttrSpec } from '../types/attrs.ts'
|
|
9
|
+
import type { Extension } from '../types/extension.ts'
|
|
10
|
+
import { assert } from '../utils/assert.ts'
|
|
11
|
+
import { mergeSpecs } from '../utils/merge-specs.ts'
|
|
12
|
+
import { wrapOutputSpecAttrs, wrapParseRuleAttrs } from '../utils/output-spec.ts'
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @public
|
|
@@ -2,11 +2,11 @@ import { isNotNullish } from '@ocavue/utils'
|
|
|
2
2
|
import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
|
|
3
3
|
import type { MarkViewConstructor } from '@prosekit/pm/view'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import type { Extension } from '../types/extension'
|
|
5
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
6
|
+
import { defineFacet } from '../facets/facet.ts'
|
|
7
|
+
import type { Extension } from '../types/extension.ts'
|
|
8
8
|
|
|
9
|
-
import { pluginFacet, type PluginPayload } from './plugin'
|
|
9
|
+
import { pluginFacet, type PluginPayload } from './plugin.ts'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @internal
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
|
|
2
2
|
import type { MarkViewConstructor } from '@prosekit/pm/view'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import type { Extension } from '../types/extension'
|
|
4
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
5
|
+
import { defineFacet } from '../facets/facet.ts'
|
|
6
|
+
import type { Extension } from '../types/extension.ts'
|
|
7
7
|
|
|
8
|
-
import { pluginFacet, type PluginPayload } from './plugin'
|
|
8
|
+
import { pluginFacet, type PluginPayload } from './plugin.ts'
|
|
9
9
|
|
|
10
10
|
export interface MarkViewOptions {
|
|
11
11
|
name: string
|
|
@@ -2,12 +2,12 @@ import type { DOMOutputSpec, Schema, TagParseRule } from '@prosekit/pm/model'
|
|
|
2
2
|
import { formatHTML } from 'diffable-html-snapshot'
|
|
3
3
|
import { describe, expect, it } from 'vitest'
|
|
4
4
|
|
|
5
|
-
import { union } from '../editor/union'
|
|
6
|
-
import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing'
|
|
5
|
+
import { union } from '../editor/union.ts'
|
|
6
|
+
import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing/index.ts'
|
|
7
7
|
|
|
8
|
-
import { defineHistory } from './history'
|
|
9
|
-
import { defineBaseKeymap } from './keymap-base'
|
|
10
|
-
import { defineNodeAttr, defineNodeSpec } from './node-spec'
|
|
8
|
+
import { defineHistory } from './history.ts'
|
|
9
|
+
import { defineBaseKeymap } from './keymap-base.ts'
|
|
10
|
+
import { defineNodeAttr, defineNodeSpec } from './node-spec.ts'
|
|
11
11
|
|
|
12
12
|
describe('defineNodeSpec', () => {
|
|
13
13
|
it('can merge node specs', () => {
|
|
@@ -2,14 +2,14 @@ import { isNotNullish, mapGroupBy } from '@ocavue/utils'
|
|
|
2
2
|
import type { AttributeSpec, NodeSpec, SchemaSpec } from '@prosekit/pm/model'
|
|
3
3
|
import OrderedMap from 'orderedmap'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { schemaSpecFacet } from '../facets/schema-spec'
|
|
8
|
-
import type { AnyAttrs, AttrSpec } from '../types/attrs'
|
|
9
|
-
import type { Extension } from '../types/extension'
|
|
10
|
-
import { assert } from '../utils/assert'
|
|
11
|
-
import { mergeSpecs } from '../utils/merge-specs'
|
|
12
|
-
import { wrapOutputSpecAttrs, wrapTagParseRuleAttrs } from '../utils/output-spec'
|
|
5
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
6
|
+
import { defineFacet } from '../facets/facet.ts'
|
|
7
|
+
import { schemaSpecFacet } from '../facets/schema-spec.ts'
|
|
8
|
+
import type { AnyAttrs, AttrSpec } from '../types/attrs.ts'
|
|
9
|
+
import type { Extension } from '../types/extension.ts'
|
|
10
|
+
import { assert } from '../utils/assert.ts'
|
|
11
|
+
import { mergeSpecs } from '../utils/merge-specs.ts'
|
|
12
|
+
import { wrapOutputSpecAttrs, wrapTagParseRuleAttrs } from '../utils/output-spec.ts'
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @public
|
|
@@ -2,11 +2,11 @@ import { isNotNullish } from '@ocavue/utils'
|
|
|
2
2
|
import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
|
|
3
3
|
import type { NodeViewConstructor } from '@prosekit/pm/view'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import type { Extension } from '../types/extension'
|
|
5
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
6
|
+
import { defineFacet } from '../facets/facet.ts'
|
|
7
|
+
import type { Extension } from '../types/extension.ts'
|
|
8
8
|
|
|
9
|
-
import { pluginFacet, type PluginPayload } from './plugin'
|
|
9
|
+
import { pluginFacet, type PluginPayload } from './plugin.ts'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @internal
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { PluginKey, ProseMirrorPlugin } from '@prosekit/pm/state'
|
|
2
2
|
import type { NodeViewConstructor } from '@prosekit/pm/view'
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import type { Extension } from '../types/extension'
|
|
4
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
5
|
+
import { defineFacet } from '../facets/facet.ts'
|
|
6
|
+
import type { Extension } from '../types/extension.ts'
|
|
7
7
|
|
|
8
|
-
import { pluginFacet, type PluginPayload } from './plugin'
|
|
8
|
+
import { pluginFacet, type PluginPayload } from './plugin.ts'
|
|
9
9
|
|
|
10
10
|
export interface NodeViewOptions {
|
|
11
11
|
name: string
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Plugin, PluginKey } from '@prosekit/pm/state'
|
|
2
2
|
import { describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { union } from '../editor/union'
|
|
5
|
-
import { withPriority } from '../editor/with-priority'
|
|
6
|
-
import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing'
|
|
7
|
-
import { Priority } from '../types/priority'
|
|
4
|
+
import { union } from '../editor/union.ts'
|
|
5
|
+
import { withPriority } from '../editor/with-priority.ts'
|
|
6
|
+
import { defineDoc, defineParagraph, defineText, setupTestFromExtension } from '../testing/index.ts'
|
|
7
|
+
import { Priority } from '../types/priority.ts'
|
|
8
8
|
|
|
9
|
-
import { definePlugin } from './plugin'
|
|
9
|
+
import { definePlugin } from './plugin.ts'
|
|
10
10
|
|
|
11
11
|
describe('plugin', () => {
|
|
12
12
|
it('maintains plugin order in state based on priority', () => {
|
package/src/extensions/plugin.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Schema } from '@prosekit/pm/model'
|
|
2
2
|
import { Plugin, type ProseMirrorPlugin } from '@prosekit/pm/state'
|
|
3
3
|
|
|
4
|
-
import { ProseKitError } from '../error'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { stateFacet, type StatePayload } from '../facets/state'
|
|
8
|
-
import type { PlainExtension } from '../types/extension'
|
|
4
|
+
import { ProseKitError } from '../error.ts'
|
|
5
|
+
import { defineFacetPayload } from '../facets/facet-extension.ts'
|
|
6
|
+
import { defineFacet, type Facet } from '../facets/facet.ts'
|
|
7
|
+
import { stateFacet, type StatePayload } from '../facets/state.ts'
|
|
8
|
+
import type { PlainExtension } from '../types/extension.ts'
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Adds a ProseMirror plugin to the editor.
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Schema } from '@prosekit/pm/model'
|
|
2
2
|
|
|
3
|
-
import type { Extension, ExtensionTyping } from '../types/extension'
|
|
4
|
-
import { Priority } from '../types/priority'
|
|
3
|
+
import type { Extension, ExtensionTyping } from '../types/extension.ts'
|
|
4
|
+
import type { Priority } from '../types/priority.ts'
|
|
5
5
|
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import { schemaFacet } from './schema'
|
|
6
|
+
import type { FacetNode } from './facet-node.ts'
|
|
7
|
+
import type { Tuple5 } from './facet-types.ts'
|
|
8
|
+
import type { Facet } from './facet.ts'
|
|
9
|
+
import { schemaFacet } from './schema.ts'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* @internal
|
|
@@ -27,7 +27,7 @@ export abstract class BaseExtension<T extends ExtensionTyping = ExtensionTyping>
|
|
|
27
27
|
* @internal
|
|
28
28
|
*/
|
|
29
29
|
getTree(priority?: Priority): FacetNode {
|
|
30
|
-
const pri = priority ?? this.priority ?? Priority.default
|
|
30
|
+
const pri = priority ?? this.priority ?? (2 satisfies typeof Priority.default)
|
|
31
31
|
return (this.trees[pri] ||= this.createTree(pri))
|
|
32
32
|
}
|
|
33
33
|
|
package/src/facets/command.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { CommandCreators } from '../types/extension-command'
|
|
1
|
+
import type { CommandCreators } from '../types/extension-command.ts'
|
|
2
2
|
|
|
3
|
-
import { defineFacet, type Facet } from './facet'
|
|
4
|
-
import { rootFacet, type RootPayload } from './root'
|
|
3
|
+
import { defineFacet, type Facet } from './facet.ts'
|
|
4
|
+
import { rootFacet, type RootPayload } from './root.ts'
|
|
5
5
|
|
|
6
6
|
type CommandPayload = CommandCreators
|
|
7
7
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { isNotNullish } from '@ocavue/utils'
|
|
2
2
|
import { describe, expect, it, vi } from 'vitest'
|
|
3
3
|
|
|
4
|
-
import { Priority } from '../types/priority'
|
|
4
|
+
import { Priority } from '../types/priority.ts'
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import { UnionExtensionImpl } from './union-extension'
|
|
6
|
+
import { FacetExtensionImpl } from './facet-extension.ts'
|
|
7
|
+
import { subtractFacetNode, unionFacetNode } from './facet-node.ts'
|
|
8
|
+
import type { FacetReducer } from './facet-types.ts'
|
|
9
|
+
import { defineFacet, Facet } from './facet.ts'
|
|
10
|
+
import { UnionExtensionImpl } from './union-extension.ts'
|
|
11
11
|
|
|
12
12
|
describe('facet extension', () => {
|
|
13
13
|
type FooHandler = (foo: string) => void
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import type { Extension } from '../types/extension'
|
|
2
|
-
import type { Priority } from '../types/priority'
|
|
1
|
+
import type { Extension } from '../types/extension.ts'
|
|
2
|
+
import type { Priority } from '../types/priority.ts'
|
|
3
3
|
|
|
4
|
-
import { BaseExtension } from './base-extension'
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import type {
|
|
4
|
+
import { BaseExtension } from './base-extension.ts'
|
|
5
|
+
import { FacetNode } from './facet-node.ts'
|
|
6
|
+
import type { Tuple5 } from './facet-types.ts'
|
|
7
|
+
import type { Facet } from './facet.ts'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
12
|
export class FacetExtensionImpl<Input, Output> extends BaseExtension {
|
|
13
13
|
declare extension: Extension
|
|
14
|
+
readonly facet: Facet<Input, Output>
|
|
15
|
+
readonly payloads: Input[]
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* @internal
|
|
17
19
|
*/
|
|
18
20
|
constructor(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
facet: Facet<Input, Output>,
|
|
22
|
+
payloads: Input[],
|
|
21
23
|
) {
|
|
22
24
|
super()
|
|
25
|
+
this.facet = facet
|
|
26
|
+
this.payloads = payloads
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { expect, test } from 'vitest'
|
|
2
2
|
|
|
3
|
-
import { Priority } from '../types/priority'
|
|
3
|
+
import { Priority } from '../types/priority.ts'
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { FacetNode, subtractFacetNode, unionFacetNode } from './facet-node.ts'
|
|
6
|
+
import { Facet } from './facet.ts'
|
|
7
7
|
|
|
8
8
|
const sum = (input: number[]) => input.reduce((acc, cur) => acc + cur, 0)
|
|
9
9
|
|
package/src/facets/facet-node.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { isNotNullish } from '@ocavue/utils'
|
|
2
2
|
|
|
3
|
-
import { Priority } from '../types/priority'
|
|
4
|
-
import { arraySubtract, uniqPush } from '../utils/array'
|
|
5
|
-
import { assert } from '../utils/assert'
|
|
3
|
+
import type { Priority } from '../types/priority.ts'
|
|
4
|
+
import { arraySubtract, uniqPush } from '../utils/array.ts'
|
|
5
|
+
import { assert } from '../utils/assert.ts'
|
|
6
6
|
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type { RootOutput } from './root'
|
|
7
|
+
import type { FacetReducer, Tuple5 } from './facet-types.ts'
|
|
8
|
+
import type { Facet } from './facet.ts'
|
|
9
|
+
import type { RootOutput } from './root.ts'
|
|
10
10
|
|
|
11
11
|
function zip5<T>(
|
|
12
12
|
a: Tuple5<T>,
|
|
@@ -104,18 +104,28 @@ export function subtractFacetNode<I, O>(
|
|
|
104
104
|
export class FacetNode<I = any, O = any> {
|
|
105
105
|
output: Tuple5<O | null> | null = null
|
|
106
106
|
|
|
107
|
+
readonly facet: Facet<I, O>
|
|
108
|
+
readonly inputs: Tuple5<I[] | null>
|
|
109
|
+
readonly children: Map<number, FacetNode>
|
|
110
|
+
readonly reducers: Tuple5<FacetReducer<I, O> | null>
|
|
111
|
+
|
|
107
112
|
constructor(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
113
|
+
facet: Facet<I, O>,
|
|
114
|
+
inputs: Tuple5<I[] | null> = [null, null, null, null, null],
|
|
115
|
+
children: Map<number, FacetNode> = new Map<number, FacetNode>(),
|
|
116
|
+
reducers: Tuple5<FacetReducer<I, O> | null> = [
|
|
112
117
|
null,
|
|
113
118
|
null,
|
|
114
119
|
null,
|
|
115
120
|
null,
|
|
116
121
|
null,
|
|
117
122
|
],
|
|
118
|
-
) {
|
|
123
|
+
) {
|
|
124
|
+
this.facet = facet
|
|
125
|
+
this.inputs = inputs
|
|
126
|
+
this.children = children
|
|
127
|
+
this.reducers = reducers
|
|
128
|
+
}
|
|
119
129
|
|
|
120
130
|
private calcOutput(): Tuple5<O | null> {
|
|
121
131
|
const inputs: Tuple5<I[] | null> = [null, null, null, null, null]
|
|
@@ -139,9 +149,9 @@ export class FacetNode<I = any, O = any> {
|
|
|
139
149
|
}
|
|
140
150
|
|
|
141
151
|
if (this.facet.singleton) {
|
|
142
|
-
const reducer = (this.reducers[Priority.default] ||= this.facet.reducer)
|
|
152
|
+
const reducer = (this.reducers[2 satisfies typeof Priority.default] ||= this.facet.reducer)
|
|
143
153
|
const input: I[] = inputs.filter(isNotNullish).flat()
|
|
144
|
-
output[Priority.default] = reducer(input)
|
|
154
|
+
output[2 satisfies typeof Priority.default] = reducer(input)
|
|
145
155
|
} else {
|
|
146
156
|
for (let pri = 0; pri < 5; pri++) {
|
|
147
157
|
const input = inputs[pri]
|
|
@@ -164,7 +174,7 @@ export class FacetNode<I = any, O = any> {
|
|
|
164
174
|
|
|
165
175
|
getSingletonOutput(): O | null {
|
|
166
176
|
assert(this.facet.singleton)
|
|
167
|
-
return this.getOutput()[Priority.default]
|
|
177
|
+
return this.getOutput()[2 satisfies typeof Priority.default]
|
|
168
178
|
}
|
|
169
179
|
|
|
170
180
|
getRootOutput(): RootOutput {
|
package/src/facets/facet.spec.ts
CHANGED
package/src/facets/facet.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ProseKitError } from '../error.ts'
|
|
2
2
|
|
|
3
|
-
import type { FacetReducer } from './facet-types'
|
|
3
|
+
import type { FacetReducer } from './facet-types.ts'
|
|
4
4
|
|
|
5
5
|
let facetCount = 0
|
|
6
6
|
|
|
@@ -27,17 +27,24 @@ export class Facet<Input, Output> {
|
|
|
27
27
|
*/
|
|
28
28
|
readonly path: number[]
|
|
29
29
|
|
|
30
|
+
private reduce: () => FacetReducer<Input, Output>
|
|
31
|
+
|
|
30
32
|
/**
|
|
31
33
|
* @internal
|
|
32
34
|
*/
|
|
33
35
|
constructor(
|
|
34
36
|
parent: Facet<Output, any> | null,
|
|
35
37
|
singleton: boolean,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
reducer?: FacetReducer<Input, Output>,
|
|
39
|
+
reduce?: () => FacetReducer<Input, Output>,
|
|
38
40
|
) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
if (reduce && !reducer) {
|
|
42
|
+
this.reduce = reduce
|
|
43
|
+
} else if (reducer && !reduce) {
|
|
44
|
+
this.reduce = () => reducer
|
|
45
|
+
} else {
|
|
46
|
+
throw new ProseKitError('Incorrect reducer')
|
|
47
|
+
}
|
|
41
48
|
|
|
42
49
|
this.parent = parent
|
|
43
50
|
this.singleton = singleton
|
|
@@ -45,7 +52,7 @@ export class Facet<Input, Output> {
|
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
get reducer(): FacetReducer<Input, Output> {
|
|
48
|
-
return
|
|
55
|
+
return this.reduce()
|
|
49
56
|
}
|
|
50
57
|
}
|
|
51
58
|
|