@atlaskit/editor-plugin-annotation 25.0.1 → 25.0.3
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/CHANGELOG.md +16 -0
- package/dist/cjs/pm-plugins/resolve-annotatable-target.js +48 -0
- package/dist/es2019/pm-plugins/resolve-annotatable-target.js +44 -0
- package/dist/esm/pm-plugins/resolve-annotatable-target.js +43 -0
- package/dist/types/pm-plugins/resolve-annotatable-target.d.ts +15 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-annotation
|
|
2
2
|
|
|
3
|
+
## 25.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`f6f0e4453badb`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f6f0e4453badb) -
|
|
8
|
+
Add `resolveAnnotatableTargetFromLocalId`, which resolves a `localId` to the node an annotation
|
|
9
|
+
can be applied to — the node itself when it accepts the annotation mark or is a supported block
|
|
10
|
+
node, otherwise its closest accepting ancestor. Internal helper, not yet used by any code path.
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 25.0.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 25.0.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveAnnotatableTargetFromLocalId = void 0;
|
|
7
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
8
|
+
var _utils2 = require("./utils");
|
|
9
|
+
/**
|
|
10
|
+
* Resolves the node to annotate for a `localId`: the node itself when it accepts an annotation
|
|
11
|
+
* (allows the mark, or is a supported block node), otherwise its closest accepting ancestor.
|
|
12
|
+
* Returns undefined when nothing in the ancestor chain accepts one.
|
|
13
|
+
*
|
|
14
|
+
* Kept in sync with the renderer implementation so both sides resolve the same node.
|
|
15
|
+
*/
|
|
16
|
+
var resolveAnnotatableTargetFromLocalId = exports.resolveAnnotatableTargetFromLocalId = function resolveAnnotatableTargetFromLocalId(state, localId, opts) {
|
|
17
|
+
var supportedBlockNodes = opts.supportedBlockNodes;
|
|
18
|
+
var matches = (0, _utils.findNodePosByLocalIds)(state, [localId]);
|
|
19
|
+
if (matches.length === 0) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
var annotationMarkType = state.schema.marks.annotation;
|
|
23
|
+
var nodeAcceptsAnnotation = function nodeAcceptsAnnotation(node) {
|
|
24
|
+
return node.type.allowsMarkType(annotationMarkType) || (0, _utils2.isSupportedBlockNode)(node, supportedBlockNodes);
|
|
25
|
+
};
|
|
26
|
+
var _matches$ = matches[0],
|
|
27
|
+
node = _matches$.node,
|
|
28
|
+
pos = _matches$.pos;
|
|
29
|
+
if (nodeAcceptsAnnotation(node)) {
|
|
30
|
+
return {
|
|
31
|
+
node: node,
|
|
32
|
+
pos: pos
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Ancestors only — never descendants.
|
|
37
|
+
var $pos = state.doc.resolve(pos);
|
|
38
|
+
for (var depth = $pos.depth; depth >= 0; depth--) {
|
|
39
|
+
var ancestor = $pos.node(depth);
|
|
40
|
+
if (nodeAcceptsAnnotation(ancestor)) {
|
|
41
|
+
return {
|
|
42
|
+
node: ancestor,
|
|
43
|
+
pos: depth === 0 ? 0 : $pos.before(depth)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return undefined;
|
|
48
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { findNodePosByLocalIds } from '@atlaskit/editor-common/utils';
|
|
2
|
+
import { isSupportedBlockNode } from './utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the node to annotate for a `localId`: the node itself when it accepts an annotation
|
|
6
|
+
* (allows the mark, or is a supported block node), otherwise its closest accepting ancestor.
|
|
7
|
+
* Returns undefined when nothing in the ancestor chain accepts one.
|
|
8
|
+
*
|
|
9
|
+
* Kept in sync with the renderer implementation so both sides resolve the same node.
|
|
10
|
+
*/
|
|
11
|
+
export const resolveAnnotatableTargetFromLocalId = (state, localId, opts) => {
|
|
12
|
+
const {
|
|
13
|
+
supportedBlockNodes
|
|
14
|
+
} = opts;
|
|
15
|
+
const matches = findNodePosByLocalIds(state, [localId]);
|
|
16
|
+
if (matches.length === 0) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
const annotationMarkType = state.schema.marks.annotation;
|
|
20
|
+
const nodeAcceptsAnnotation = node => node.type.allowsMarkType(annotationMarkType) || isSupportedBlockNode(node, supportedBlockNodes);
|
|
21
|
+
const {
|
|
22
|
+
node,
|
|
23
|
+
pos
|
|
24
|
+
} = matches[0];
|
|
25
|
+
if (nodeAcceptsAnnotation(node)) {
|
|
26
|
+
return {
|
|
27
|
+
node,
|
|
28
|
+
pos
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Ancestors only — never descendants.
|
|
33
|
+
const $pos = state.doc.resolve(pos);
|
|
34
|
+
for (let depth = $pos.depth; depth >= 0; depth--) {
|
|
35
|
+
const ancestor = $pos.node(depth);
|
|
36
|
+
if (nodeAcceptsAnnotation(ancestor)) {
|
|
37
|
+
return {
|
|
38
|
+
node: ancestor,
|
|
39
|
+
pos: depth === 0 ? 0 : $pos.before(depth)
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { findNodePosByLocalIds } from '@atlaskit/editor-common/utils';
|
|
2
|
+
import { isSupportedBlockNode } from './utils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Resolves the node to annotate for a `localId`: the node itself when it accepts an annotation
|
|
6
|
+
* (allows the mark, or is a supported block node), otherwise its closest accepting ancestor.
|
|
7
|
+
* Returns undefined when nothing in the ancestor chain accepts one.
|
|
8
|
+
*
|
|
9
|
+
* Kept in sync with the renderer implementation so both sides resolve the same node.
|
|
10
|
+
*/
|
|
11
|
+
export var resolveAnnotatableTargetFromLocalId = function resolveAnnotatableTargetFromLocalId(state, localId, opts) {
|
|
12
|
+
var supportedBlockNodes = opts.supportedBlockNodes;
|
|
13
|
+
var matches = findNodePosByLocalIds(state, [localId]);
|
|
14
|
+
if (matches.length === 0) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
var annotationMarkType = state.schema.marks.annotation;
|
|
18
|
+
var nodeAcceptsAnnotation = function nodeAcceptsAnnotation(node) {
|
|
19
|
+
return node.type.allowsMarkType(annotationMarkType) || isSupportedBlockNode(node, supportedBlockNodes);
|
|
20
|
+
};
|
|
21
|
+
var _matches$ = matches[0],
|
|
22
|
+
node = _matches$.node,
|
|
23
|
+
pos = _matches$.pos;
|
|
24
|
+
if (nodeAcceptsAnnotation(node)) {
|
|
25
|
+
return {
|
|
26
|
+
node: node,
|
|
27
|
+
pos: pos
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Ancestors only — never descendants.
|
|
32
|
+
var $pos = state.doc.resolve(pos);
|
|
33
|
+
for (var depth = $pos.depth; depth >= 0; depth--) {
|
|
34
|
+
var ancestor = $pos.node(depth);
|
|
35
|
+
if (nodeAcceptsAnnotation(ancestor)) {
|
|
36
|
+
return {
|
|
37
|
+
node: ancestor,
|
|
38
|
+
pos: depth === 0 ? 0 : $pos.before(depth)
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return undefined;
|
|
43
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Node } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the node to annotate for a `localId`: the node itself when it accepts an annotation
|
|
5
|
+
* (allows the mark, or is a supported block node), otherwise its closest accepting ancestor.
|
|
6
|
+
* Returns undefined when nothing in the ancestor chain accepts one.
|
|
7
|
+
*
|
|
8
|
+
* Kept in sync with the renderer implementation so both sides resolve the same node.
|
|
9
|
+
*/
|
|
10
|
+
export declare const resolveAnnotatableTargetFromLocalId: (state: EditorState, localId: string, opts: {
|
|
11
|
+
supportedBlockNodes?: string[];
|
|
12
|
+
}) => {
|
|
13
|
+
node: Node;
|
|
14
|
+
pos: number;
|
|
15
|
+
} | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-annotation",
|
|
3
|
-
"version": "25.0.
|
|
3
|
+
"version": "25.0.3",
|
|
4
4
|
"description": "Annotation plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"@atlaskit/editor-toolbar-model": "^1.2.0",
|
|
32
32
|
"@atlaskit/icon": "^38.0.0",
|
|
33
33
|
"@atlaskit/platform-feature-flags": "^2.2.0",
|
|
34
|
-
"@atlaskit/tmp-editor-statsig": "^
|
|
34
|
+
"@atlaskit/tmp-editor-statsig": "^227.0.0",
|
|
35
35
|
"@babel/runtime": "^7.0.0"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|