@atlaskit/editor-plugin-local-id 3.3.0 → 4.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  # @atlaskit/editor-plugin-local-id
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`1b290cb1f993b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/1b290cb1f993b) -
8
+ Adds actions to get and replace nodes by their localId
9
+
10
+ ```ts
11
+ // Replace a local id with a ProseMirror node
12
+ api?.localId.actions.replaceNode({ localId: 'example-id', value: node });
13
+
14
+ // Get a prosemirror node based on its local id
15
+ api?.localId.actions.getNode({ localId: 'example-id' });
16
+ ```
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies
21
+
22
+ ## 4.0.0
23
+
24
+ ### Patch Changes
25
+
26
+ - Updated dependencies
27
+
3
28
  ## 3.3.0
4
29
 
5
30
  ### Minor Changes
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findNodeByLocalId = findNodeByLocalId;
7
+ exports.replaceNode = exports.getNode = void 0;
8
+ function findNodeByLocalId(tr, localId) {
9
+ var result;
10
+ tr.doc.descendants(function (node, pos) {
11
+ if (result) {
12
+ return false;
13
+ }
14
+ if (node.attrs.localId === localId) {
15
+ result = {
16
+ node: node,
17
+ pos: pos
18
+ };
19
+ }
20
+ return result === undefined;
21
+ });
22
+ return result;
23
+ }
24
+ var replaceNode = exports.replaceNode = function replaceNode(api) {
25
+ return function (_ref) {
26
+ var _api$core$actions$exe;
27
+ var localId = _ref.localId,
28
+ value = _ref.value;
29
+ var nodeWithPos = getNode(api)({
30
+ localId: localId
31
+ });
32
+ if (!nodeWithPos) {
33
+ return false;
34
+ }
35
+ var pos = nodeWithPos.pos,
36
+ node = nodeWithPos.node;
37
+ return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(function (_ref2) {
38
+ var tr = _ref2.tr;
39
+ return tr.replaceWith(pos, pos + node.nodeSize, value).scrollIntoView();
40
+ })) !== null && _api$core$actions$exe !== void 0 ? _api$core$actions$exe : false;
41
+ };
42
+ };
43
+ var getNode = exports.getNode = function getNode(api) {
44
+ return function (_ref3) {
45
+ var localId = _ref3.localId;
46
+ var result;
47
+ api === null || api === void 0 || api.core.actions.execute(function (_ref4) {
48
+ var tr = _ref4.tr;
49
+ result = findNodeByLocalId(tr, localId);
50
+ return null;
51
+ });
52
+ return result;
53
+ };
54
+ };
@@ -4,10 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.localIdPlugin = void 0;
7
+ var _editorActions = require("./editor-actions");
7
8
  var _main = require("./pm-plugins/main");
8
- var localIdPlugin = exports.localIdPlugin = function localIdPlugin() {
9
+ var localIdPlugin = exports.localIdPlugin = function localIdPlugin(_ref) {
10
+ var api = _ref.api;
9
11
  return {
10
12
  name: 'localId',
13
+ actions: {
14
+ replaceNode: (0, _editorActions.replaceNode)(api),
15
+ getNode: (0, _editorActions.getNode)(api)
16
+ },
11
17
  pmPlugins: function pmPlugins() {
12
18
  return [{
13
19
  name: 'localIdPlugin',
@@ -0,0 +1,47 @@
1
+ export function findNodeByLocalId(tr, localId) {
2
+ let result;
3
+ tr.doc.descendants((node, pos) => {
4
+ if (result) {
5
+ return false;
6
+ }
7
+ if (node.attrs.localId === localId) {
8
+ result = {
9
+ node,
10
+ pos
11
+ };
12
+ }
13
+ return result === undefined;
14
+ });
15
+ return result;
16
+ }
17
+ export const replaceNode = api => ({
18
+ localId,
19
+ value
20
+ }) => {
21
+ var _api$core$actions$exe;
22
+ const nodeWithPos = getNode(api)({
23
+ localId
24
+ });
25
+ if (!nodeWithPos) {
26
+ return false;
27
+ }
28
+ const {
29
+ pos,
30
+ node
31
+ } = nodeWithPos;
32
+ return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(({
33
+ tr
34
+ }) => tr.replaceWith(pos, pos + node.nodeSize, value).scrollIntoView())) !== null && _api$core$actions$exe !== void 0 ? _api$core$actions$exe : false;
35
+ };
36
+ export const getNode = api => ({
37
+ localId
38
+ }) => {
39
+ let result;
40
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(({
41
+ tr
42
+ }) => {
43
+ result = findNodeByLocalId(tr, localId);
44
+ return null;
45
+ });
46
+ return result;
47
+ };
@@ -1,6 +1,13 @@
1
+ import { replaceNode, getNode } from './editor-actions';
1
2
  import { createPlugin } from './pm-plugins/main';
2
- export const localIdPlugin = () => ({
3
+ export const localIdPlugin = ({
4
+ api
5
+ }) => ({
3
6
  name: 'localId',
7
+ actions: {
8
+ replaceNode: replaceNode(api),
9
+ getNode: getNode(api)
10
+ },
4
11
  pmPlugins() {
5
12
  return [{
6
13
  name: 'localIdPlugin',
@@ -0,0 +1,47 @@
1
+ export function findNodeByLocalId(tr, localId) {
2
+ var result;
3
+ tr.doc.descendants(function (node, pos) {
4
+ if (result) {
5
+ return false;
6
+ }
7
+ if (node.attrs.localId === localId) {
8
+ result = {
9
+ node: node,
10
+ pos: pos
11
+ };
12
+ }
13
+ return result === undefined;
14
+ });
15
+ return result;
16
+ }
17
+ export var replaceNode = function replaceNode(api) {
18
+ return function (_ref) {
19
+ var _api$core$actions$exe;
20
+ var localId = _ref.localId,
21
+ value = _ref.value;
22
+ var nodeWithPos = getNode(api)({
23
+ localId: localId
24
+ });
25
+ if (!nodeWithPos) {
26
+ return false;
27
+ }
28
+ var pos = nodeWithPos.pos,
29
+ node = nodeWithPos.node;
30
+ return (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(function (_ref2) {
31
+ var tr = _ref2.tr;
32
+ return tr.replaceWith(pos, pos + node.nodeSize, value).scrollIntoView();
33
+ })) !== null && _api$core$actions$exe !== void 0 ? _api$core$actions$exe : false;
34
+ };
35
+ };
36
+ export var getNode = function getNode(api) {
37
+ return function (_ref3) {
38
+ var localId = _ref3.localId;
39
+ var result;
40
+ api === null || api === void 0 || api.core.actions.execute(function (_ref4) {
41
+ var tr = _ref4.tr;
42
+ result = findNodeByLocalId(tr, localId);
43
+ return null;
44
+ });
45
+ return result;
46
+ };
47
+ };
@@ -1,7 +1,13 @@
1
+ import { replaceNode, getNode } from './editor-actions';
1
2
  import { createPlugin } from './pm-plugins/main';
2
- export var localIdPlugin = function localIdPlugin() {
3
+ export var localIdPlugin = function localIdPlugin(_ref) {
4
+ var api = _ref.api;
3
5
  return {
4
6
  name: 'localId',
7
+ actions: {
8
+ replaceNode: replaceNode(api),
9
+ getNode: getNode(api)
10
+ },
5
11
  pmPlugins: function pmPlugins() {
6
12
  return [{
7
13
  name: 'localIdPlugin',
@@ -0,0 +1,12 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
3
+ import type { Transform } from '@atlaskit/editor-prosemirror/transform';
4
+ import type { NodeWithPos } from '@atlaskit/editor-prosemirror/utils';
5
+ import type { ActionProps, LocalIdPlugin } from '../localIdPluginType';
6
+ type EditorActionProps = ActionProps;
7
+ export declare function findNodeByLocalId(tr: Transform, localId: string): NodeWithPos | undefined;
8
+ export declare const replaceNode: (api: ExtractInjectionAPI<LocalIdPlugin> | undefined) => ({ localId, value }: EditorActionProps & {
9
+ value: Node;
10
+ }) => boolean;
11
+ export declare const getNode: (api: ExtractInjectionAPI<LocalIdPlugin> | undefined) => ({ localId }: EditorActionProps) => NodeWithPos | undefined;
12
+ export {};
@@ -1,2 +1,27 @@
1
1
  import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
- export type LocalIdPlugin = NextEditorPlugin<'localId'>;
2
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
3
+ import type { NodeWithPos } from '@atlaskit/editor-prosemirror/utils';
4
+ export type ActionProps = {
5
+ localId: string;
6
+ };
7
+ export type LocalIdPlugin = NextEditorPlugin<'localId', {
8
+ actions: {
9
+ /**
10
+ * Get the node with its position in the document
11
+ *
12
+ * @param props.localId Local id of the node in question
13
+ * @returns { node: ProsemirrorNode, pos: number } Object containing prosemirror node and position in the document
14
+ */
15
+ getNode: (props: ActionProps) => NodeWithPos | undefined;
16
+ /**
17
+ * Replace the node in the document by its local id
18
+ *
19
+ * @param props.localId Local id of the node in question
20
+ * @param props.value Prosemirror node to replace the node with
21
+ * @returns boolean if the replace was successful
22
+ */
23
+ replaceNode: (props: ActionProps & {
24
+ value: Node;
25
+ }) => boolean;
26
+ };
27
+ }>;
@@ -0,0 +1,12 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
3
+ import type { Transform } from '@atlaskit/editor-prosemirror/transform';
4
+ import type { NodeWithPos } from '@atlaskit/editor-prosemirror/utils';
5
+ import type { ActionProps, LocalIdPlugin } from '../localIdPluginType';
6
+ type EditorActionProps = ActionProps;
7
+ export declare function findNodeByLocalId(tr: Transform, localId: string): NodeWithPos | undefined;
8
+ export declare const replaceNode: (api: ExtractInjectionAPI<LocalIdPlugin> | undefined) => ({ localId, value }: EditorActionProps & {
9
+ value: Node;
10
+ }) => boolean;
11
+ export declare const getNode: (api: ExtractInjectionAPI<LocalIdPlugin> | undefined) => ({ localId }: EditorActionProps) => NodeWithPos | undefined;
12
+ export {};
@@ -1,2 +1,27 @@
1
1
  import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
2
- export type LocalIdPlugin = NextEditorPlugin<'localId'>;
2
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
3
+ import type { NodeWithPos } from '@atlaskit/editor-prosemirror/utils';
4
+ export type ActionProps = {
5
+ localId: string;
6
+ };
7
+ export type LocalIdPlugin = NextEditorPlugin<'localId', {
8
+ actions: {
9
+ /**
10
+ * Get the node with its position in the document
11
+ *
12
+ * @param props.localId Local id of the node in question
13
+ * @returns { node: ProsemirrorNode, pos: number } Object containing prosemirror node and position in the document
14
+ */
15
+ getNode: (props: ActionProps) => NodeWithPos | undefined;
16
+ /**
17
+ * Replace the node in the document by its local id
18
+ *
19
+ * @param props.localId Local id of the node in question
20
+ * @param props.value Prosemirror node to replace the node with
21
+ * @returns boolean if the replace was successful
22
+ */
23
+ replaceNode: (props: ActionProps & {
24
+ value: Node;
25
+ }) => boolean;
26
+ };
27
+ }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-local-id",
3
- "version": "3.3.0",
3
+ "version": "4.1.0",
4
4
  "description": "LocalId plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,7 +35,7 @@
35
35
  "raf-schd": "^4.0.3"
36
36
  },
37
37
  "peerDependencies": {
38
- "@atlaskit/editor-common": "^109.16.0",
38
+ "@atlaskit/editor-common": "^110.4.0",
39
39
  "react": "^18.2.0"
40
40
  },
41
41
  "devDependencies": {