@atlaskit/editor-plugin-list 10.0.6 → 10.0.8

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,20 @@
1
1
  # @atlaskit/editor-plugin-list
2
2
 
3
+ ## 10.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 10.0.7
10
+
11
+ ### Patch Changes
12
+
13
+ - [`66fc14c10e82b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/66fc14c10e82b) -
14
+ EDITOR-5862: Preserve list attributes (order, localId) during flatten-rebuild indentation
15
+ operations
16
+ - Updated dependencies
17
+
3
18
  ## 10.0.6
4
19
 
5
20
  ### Patch Changes
@@ -70,7 +70,9 @@ function flattenList(_ref) {
70
70
  node: node,
71
71
  pos: pos,
72
72
  depth: depth,
73
- listType: parent.type.name
73
+ listType: parent.type.name,
74
+ parentListAttrs: parent.attrs,
75
+ isSelected: isSelected
74
76
  });
75
77
  if (isSelected) {
76
78
  var index = elements.length - 1;
@@ -124,9 +126,10 @@ function rebuildPMList(elements, schema) {
124
126
  // items[] accumulates the PMNode children (listItem nodes) for that list.
125
127
 
126
128
  var stack = [];
127
- function openList(listType) {
129
+ function openList(listType, listAttrs) {
128
130
  stack.push({
129
131
  listType: listType,
132
+ listAttrs: listAttrs,
130
133
  items: []
131
134
  });
132
135
  }
@@ -141,7 +144,7 @@ function rebuildPMList(elements, schema) {
141
144
  if (!closed) {
142
145
  return 1; // break
143
146
  }
144
- var listNode = schema.nodes[closed.listType].create(null, closed.items);
147
+ var listNode = schema.nodes[closed.listType].create(closed.listAttrs, closed.items);
145
148
 
146
149
  // Attach the closed list to the last listItem on the parent frame
147
150
  var parentFrame = stack[stack.length - 1];
@@ -165,8 +168,8 @@ function rebuildPMList(elements, schema) {
165
168
  }
166
169
  }
167
170
 
168
- // Seed the root list
169
- openList(elements[0].listType);
171
+ // Seed the root list with the first element's parent list attributes
172
+ openList(elements[0].listType, elements[0].parentListAttrs);
170
173
  var _iterator = _createForOfIteratorHelper(elements),
171
174
  _step;
172
175
  try {
@@ -182,8 +185,12 @@ function rebuildPMList(elements, schema) {
182
185
  // Open lists if we need to go deeper.
183
186
  // We do NOT create wrapper listItems here — closeToDepth handles
184
187
  // creating wrappers that contain only the nested list (no empty paragraph).
188
+ // For unselected elements, the list structure already existed so we
189
+ // preserve the parent list's attributes. For selected (moved) elements,
190
+ // this is a new nesting level so we use null (the localId plugin will
191
+ // backfill a fresh UUID).
185
192
  while (stack.length < targetDepth + 1) {
186
- openList(el.listType);
193
+ openList(el.listType, el.isSelected ? null : el.parentListAttrs);
187
194
  }
188
195
 
189
196
  // Build the listItem for this element using its content children
@@ -200,7 +207,7 @@ function rebuildPMList(elements, schema) {
200
207
  }
201
208
  closeToDepth(0);
202
209
  var root = stack[0];
203
- return schema.nodes[root.listType].create(null, root.items);
210
+ return schema.nodes[root.listType].create(root.listAttrs, root.items);
204
211
  }
205
212
  /**
206
213
  * Build a replacement Fragment from a flat array of `ListElement` objects.
@@ -59,7 +59,9 @@ export function flattenList({
59
59
  node,
60
60
  pos,
61
61
  depth,
62
- listType: parent.type.name
62
+ listType: parent.type.name,
63
+ parentListAttrs: parent.attrs,
64
+ isSelected
63
65
  });
64
66
  if (isSelected) {
65
67
  const index = elements.length - 1;
@@ -113,9 +115,10 @@ function rebuildPMList(elements, schema) {
113
115
  // items[] accumulates the PMNode children (listItem nodes) for that list.
114
116
 
115
117
  const stack = [];
116
- function openList(listType) {
118
+ function openList(listType, listAttrs) {
117
119
  stack.push({
118
120
  listType,
121
+ listAttrs,
119
122
  items: []
120
123
  });
121
124
  }
@@ -130,7 +133,7 @@ function rebuildPMList(elements, schema) {
130
133
  if (!closed) {
131
134
  break;
132
135
  }
133
- const listNode = schema.nodes[closed.listType].create(null, closed.items);
136
+ const listNode = schema.nodes[closed.listType].create(closed.listAttrs, closed.items);
134
137
 
135
138
  // Attach the closed list to the last listItem on the parent frame
136
139
  const parentFrame = stack[stack.length - 1];
@@ -149,8 +152,8 @@ function rebuildPMList(elements, schema) {
149
152
  }
150
153
  }
151
154
 
152
- // Seed the root list
153
- openList(elements[0].listType);
155
+ // Seed the root list with the first element's parent list attributes
156
+ openList(elements[0].listType, elements[0].parentListAttrs);
154
157
  for (const el of elements) {
155
158
  const targetDepth = el.depth;
156
159
 
@@ -162,8 +165,12 @@ function rebuildPMList(elements, schema) {
162
165
  // Open lists if we need to go deeper.
163
166
  // We do NOT create wrapper listItems here — closeToDepth handles
164
167
  // creating wrappers that contain only the nested list (no empty paragraph).
168
+ // For unselected elements, the list structure already existed so we
169
+ // preserve the parent list's attributes. For selected (moved) elements,
170
+ // this is a new nesting level so we use null (the localId plugin will
171
+ // backfill a fresh UUID).
165
172
  while (stack.length < targetDepth + 1) {
166
- openList(el.listType);
173
+ openList(el.listType, el.isSelected ? null : el.parentListAttrs);
167
174
  }
168
175
 
169
176
  // Build the listItem for this element using its content children
@@ -175,7 +182,7 @@ function rebuildPMList(elements, schema) {
175
182
  // Close all remaining open lists
176
183
  closeToDepth(0);
177
184
  const root = stack[0];
178
- return schema.nodes[root.listType].create(null, root.items);
185
+ return schema.nodes[root.listType].create(root.listAttrs, root.items);
179
186
  }
180
187
  /**
181
188
  * Build a replacement Fragment from a flat array of `ListElement` objects.
@@ -63,7 +63,9 @@ export function flattenList(_ref) {
63
63
  node: node,
64
64
  pos: pos,
65
65
  depth: depth,
66
- listType: parent.type.name
66
+ listType: parent.type.name,
67
+ parentListAttrs: parent.attrs,
68
+ isSelected: isSelected
67
69
  });
68
70
  if (isSelected) {
69
71
  var index = elements.length - 1;
@@ -117,9 +119,10 @@ function rebuildPMList(elements, schema) {
117
119
  // items[] accumulates the PMNode children (listItem nodes) for that list.
118
120
 
119
121
  var stack = [];
120
- function openList(listType) {
122
+ function openList(listType, listAttrs) {
121
123
  stack.push({
122
124
  listType: listType,
125
+ listAttrs: listAttrs,
123
126
  items: []
124
127
  });
125
128
  }
@@ -134,7 +137,7 @@ function rebuildPMList(elements, schema) {
134
137
  if (!closed) {
135
138
  return 1; // break
136
139
  }
137
- var listNode = schema.nodes[closed.listType].create(null, closed.items);
140
+ var listNode = schema.nodes[closed.listType].create(closed.listAttrs, closed.items);
138
141
 
139
142
  // Attach the closed list to the last listItem on the parent frame
140
143
  var parentFrame = stack[stack.length - 1];
@@ -158,8 +161,8 @@ function rebuildPMList(elements, schema) {
158
161
  }
159
162
  }
160
163
 
161
- // Seed the root list
162
- openList(elements[0].listType);
164
+ // Seed the root list with the first element's parent list attributes
165
+ openList(elements[0].listType, elements[0].parentListAttrs);
163
166
  var _iterator = _createForOfIteratorHelper(elements),
164
167
  _step;
165
168
  try {
@@ -175,8 +178,12 @@ function rebuildPMList(elements, schema) {
175
178
  // Open lists if we need to go deeper.
176
179
  // We do NOT create wrapper listItems here — closeToDepth handles
177
180
  // creating wrappers that contain only the nested list (no empty paragraph).
181
+ // For unselected elements, the list structure already existed so we
182
+ // preserve the parent list's attributes. For selected (moved) elements,
183
+ // this is a new nesting level so we use null (the localId plugin will
184
+ // backfill a fresh UUID).
178
185
  while (stack.length < targetDepth + 1) {
179
- openList(el.listType);
186
+ openList(el.listType, el.isSelected ? null : el.parentListAttrs);
180
187
  }
181
188
 
182
189
  // Build the listItem for this element using its content children
@@ -193,7 +200,7 @@ function rebuildPMList(elements, schema) {
193
200
  }
194
201
  closeToDepth(0);
195
202
  var root = stack[0];
196
- return schema.nodes[root.listType].create(null, root.items);
203
+ return schema.nodes[root.listType].create(root.listAttrs, root.items);
197
204
  }
198
205
  /**
199
206
  * Build a replacement Fragment from a flat array of `ListElement` objects.
@@ -1,4 +1,4 @@
1
- import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
1
+ import type { Attrs, Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
2
2
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
3
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
4
  import { Selection } from '@atlaskit/editor-prosemirror/state';
@@ -8,24 +8,28 @@ import { Selection } from '@atlaskit/editor-prosemirror/state';
8
8
  * only items the user can actually see and select are represented.
9
9
  */
10
10
  export interface ListElement {
11
- node: PMNode;
12
- pos: number;
13
11
  depth: number;
12
+ /** Whether this element was within the user's selection (and had its depth adjusted). */
13
+ isSelected: boolean;
14
14
  listType: 'bulletList' | 'orderedList';
15
+ node: PMNode;
16
+ /** Attributes of the immediate parent list node (bulletList/orderedList). */
17
+ parentListAttrs: Attrs | null;
18
+ pos: number;
15
19
  }
16
20
  export interface FlattenListResult {
17
21
  elements: ListElement[];
18
- startIndex: number;
19
22
  endIndex: number;
20
23
  maxDepth: number;
24
+ startIndex: number;
21
25
  }
22
26
  export interface FlattenListOptions {
27
+ delta: number;
23
28
  doc: PMNode;
24
- rootListStart: number;
25
29
  rootListEnd: number;
30
+ rootListStart: number;
26
31
  selectionFrom: number;
27
32
  selectionTo: number;
28
- delta: number;
29
33
  }
30
34
  /**
31
35
  * Flatten a root list into a flat array of content-bearing `ListElement`
@@ -36,7 +40,6 @@ export interface FlattenListOptions {
36
40
  */
37
41
  export declare function flattenList({ doc, rootListStart, rootListEnd, selectionFrom, selectionTo, delta, }: FlattenListOptions): FlattenListResult | null;
38
42
  export interface BuildResult {
39
- fragment: Fragment;
40
43
  /**
41
44
  * For each element (by index), the offset within the fragment where the
42
45
  * element's content begins. For list elements this is the position just
@@ -47,6 +50,7 @@ export interface BuildResult {
47
50
  * add `rangeStart` to the offset.
48
51
  */
49
52
  contentStartOffsets: number[];
53
+ fragment: Fragment;
50
54
  }
51
55
  /**
52
56
  * Build a replacement Fragment from a flat array of `ListElement` objects.
@@ -58,10 +62,10 @@ export interface BuildResult {
58
62
  */
59
63
  export declare function buildReplacementFragment(elements: ListElement[], schema: Schema): BuildResult;
60
64
  export interface RestoreSelectionOptions {
61
- tr: Transaction;
62
- originalSelection: Selection;
63
65
  from: number;
66
+ originalSelection: Selection;
64
67
  to: number;
68
+ tr: Transaction;
65
69
  }
66
70
  /**
67
71
  * Restore the transaction's selection after a list structural change.
@@ -1,4 +1,4 @@
1
- import type { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
1
+ import type { Attrs, Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
2
2
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
3
3
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
4
  import { Selection } from '@atlaskit/editor-prosemirror/state';
@@ -8,24 +8,28 @@ import { Selection } from '@atlaskit/editor-prosemirror/state';
8
8
  * only items the user can actually see and select are represented.
9
9
  */
10
10
  export interface ListElement {
11
- node: PMNode;
12
- pos: number;
13
11
  depth: number;
12
+ /** Whether this element was within the user's selection (and had its depth adjusted). */
13
+ isSelected: boolean;
14
14
  listType: 'bulletList' | 'orderedList';
15
+ node: PMNode;
16
+ /** Attributes of the immediate parent list node (bulletList/orderedList). */
17
+ parentListAttrs: Attrs | null;
18
+ pos: number;
15
19
  }
16
20
  export interface FlattenListResult {
17
21
  elements: ListElement[];
18
- startIndex: number;
19
22
  endIndex: number;
20
23
  maxDepth: number;
24
+ startIndex: number;
21
25
  }
22
26
  export interface FlattenListOptions {
27
+ delta: number;
23
28
  doc: PMNode;
24
- rootListStart: number;
25
29
  rootListEnd: number;
30
+ rootListStart: number;
26
31
  selectionFrom: number;
27
32
  selectionTo: number;
28
- delta: number;
29
33
  }
30
34
  /**
31
35
  * Flatten a root list into a flat array of content-bearing `ListElement`
@@ -36,7 +40,6 @@ export interface FlattenListOptions {
36
40
  */
37
41
  export declare function flattenList({ doc, rootListStart, rootListEnd, selectionFrom, selectionTo, delta, }: FlattenListOptions): FlattenListResult | null;
38
42
  export interface BuildResult {
39
- fragment: Fragment;
40
43
  /**
41
44
  * For each element (by index), the offset within the fragment where the
42
45
  * element's content begins. For list elements this is the position just
@@ -47,6 +50,7 @@ export interface BuildResult {
47
50
  * add `rangeStart` to the offset.
48
51
  */
49
52
  contentStartOffsets: number[];
53
+ fragment: Fragment;
50
54
  }
51
55
  /**
52
56
  * Build a replacement Fragment from a flat array of `ListElement` objects.
@@ -58,10 +62,10 @@ export interface BuildResult {
58
62
  */
59
63
  export declare function buildReplacementFragment(elements: ListElement[], schema: Schema): BuildResult;
60
64
  export interface RestoreSelectionOptions {
61
- tr: Transaction;
62
- originalSelection: Selection;
63
65
  from: number;
66
+ originalSelection: Selection;
64
67
  to: number;
68
+ tr: Transaction;
65
69
  }
66
70
  /**
67
71
  * Restore the transaction's selection after a list structural change.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-list",
3
- "version": "10.0.6",
3
+ "version": "10.0.8",
4
4
  "description": "List plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -27,7 +27,7 @@
27
27
  "sideEffects": false,
28
28
  "atlaskit:src": "src/index.ts",
29
29
  "dependencies": {
30
- "@atlaskit/adf-schema": "^52.3.0",
30
+ "@atlaskit/adf-schema": "^52.4.0",
31
31
  "@atlaskit/editor-plugin-analytics": "^8.0.0",
32
32
  "@atlaskit/editor-plugin-block-menu": "^7.0.0",
33
33
  "@atlaskit/editor-plugin-feature-flags": "^7.0.0",
@@ -38,11 +38,11 @@
38
38
  "@atlaskit/platform-feature-flags": "^1.1.0",
39
39
  "@atlaskit/prosemirror-history": "^0.2.0",
40
40
  "@atlaskit/prosemirror-input-rules": "^3.6.0",
41
- "@atlaskit/tmp-editor-statsig": "^40.2.0",
41
+ "@atlaskit/tmp-editor-statsig": "^41.0.0",
42
42
  "@babel/runtime": "^7.0.0"
43
43
  },
44
44
  "peerDependencies": {
45
- "@atlaskit/editor-common": "^112.4.0",
45
+ "@atlaskit/editor-common": "^112.6.0",
46
46
  "react": "^18.2.0",
47
47
  "react-intl-next": "npm:react-intl@^5.18.1"
48
48
  },