@atlaskit/adf-schema 28.1.12 → 28.1.13
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 +6 -0
- package/package.json +1 -1
- package/src/__tests__/unit/json-schema/v1.ts +0 -55
- package/src/__tests__/unit/schema/create-schema.ts +0 -214
- package/src/__tests__/unit/schema/default-schema.ts +0 -192
- package/src/__tests__/unit/schema/marks/annotation.ts +0 -46
- package/src/__tests__/unit/schema/marks/border.ts +0 -76
- package/src/__tests__/unit/schema/marks/breakout.ts +0 -24
- package/src/__tests__/unit/schema/marks/code.ts +0 -44
- package/src/__tests__/unit/schema/marks/confluence-inline-comment.ts +0 -25
- package/src/__tests__/unit/schema/marks/data-consumer.ts +0 -52
- package/src/__tests__/unit/schema/marks/em.ts +0 -37
- package/src/__tests__/unit/schema/marks/link.ts +0 -188
- package/src/__tests__/unit/schema/marks/strike.ts +0 -37
- package/src/__tests__/unit/schema/marks/strong.ts +0 -43
- package/src/__tests__/unit/schema/marks/subsup.ts +0 -50
- package/src/__tests__/unit/schema/marks/text-color.ts +0 -61
- package/src/__tests__/unit/schema/marks/underline.ts +0 -36
- package/src/__tests__/unit/schema/nodes/_consts.ts +0 -964
- package/src/__tests__/unit/schema/nodes/block-card.ts +0 -184
- package/src/__tests__/unit/schema/nodes/blockquote.ts +0 -44
- package/src/__tests__/unit/schema/nodes/bodied-extension.ts +0 -101
- package/src/__tests__/unit/schema/nodes/code-block.ts +0 -221
- package/src/__tests__/unit/schema/nodes/confluence-unsupported-block.ts +0 -32
- package/src/__tests__/unit/schema/nodes/confluence-unsupported-inline.ts +0 -35
- package/src/__tests__/unit/schema/nodes/date.ts +0 -51
- package/src/__tests__/unit/schema/nodes/decision-item.ts +0 -46
- package/src/__tests__/unit/schema/nodes/decision-list.ts +0 -52
- package/src/__tests__/unit/schema/nodes/embed-card.ts +0 -60
- package/src/__tests__/unit/schema/nodes/emoji.ts +0 -71
- package/src/__tests__/unit/schema/nodes/expand.ts +0 -51
- package/src/__tests__/unit/schema/nodes/extension.ts +0 -101
- package/src/__tests__/unit/schema/nodes/hard-break.ts +0 -24
- package/src/__tests__/unit/schema/nodes/heading.ts +0 -56
- package/src/__tests__/unit/schema/nodes/image.ts +0 -32
- package/src/__tests__/unit/schema/nodes/inline-card.ts +0 -106
- package/src/__tests__/unit/schema/nodes/inline-extension.ts +0 -79
- package/src/__tests__/unit/schema/nodes/layout-column.ts +0 -54
- package/src/__tests__/unit/schema/nodes/layout-section.ts +0 -95
- package/src/__tests__/unit/schema/nodes/list-item.ts +0 -49
- package/src/__tests__/unit/schema/nodes/media-group.ts +0 -67
- package/src/__tests__/unit/schema/nodes/media-single.ts +0 -171
- package/src/__tests__/unit/schema/nodes/media.ts +0 -384
- package/src/__tests__/unit/schema/nodes/mention.ts +0 -115
- package/src/__tests__/unit/schema/nodes/nestedExpand.ts +0 -72
- package/src/__tests__/unit/schema/nodes/ordered-list.ts +0 -49
- package/src/__tests__/unit/schema/nodes/panel.ts +0 -180
- package/src/__tests__/unit/schema/nodes/paragraph.ts +0 -25
- package/src/__tests__/unit/schema/nodes/placeholder.ts +0 -46
- package/src/__tests__/unit/schema/nodes/rule.ts +0 -24
- package/src/__tests__/unit/schema/nodes/status.ts +0 -120
- package/src/__tests__/unit/schema/nodes/tableNodes.ts +0 -555
- package/src/__tests__/unit/schema/nodes/task-item.ts +0 -39
- package/src/__tests__/unit/schema/nodes/task-list.ts +0 -45
- package/src/__tests__/unit/schema/nodes/unknown-block.ts +0 -42
- package/src/__tests__/unit/schema/nodes/unsupported-block.ts +0 -42
- package/src/__tests__/unit/schema/nodes/unsupported-inline.ts +0 -38
- package/src/__tests__/unit/utils/colors.ts +0 -42
- package/src/__tests__/unit/utils/url.ts +0 -209
- package/src/schema/bitbucket-schema.ts +0 -43
- package/src/schema/confluence-schema.ts +0 -76
- package/src/schema/create-schema.ts +0 -337
- package/src/schema/default-schema.ts +0 -180
- package/src/schema/groups.ts +0 -30
- package/src/schema/inline-nodes.ts +0 -9
- package/src/schema/jira-schema.ts +0 -158
- package/src/schema/marks/__tests__/unit/annotation.ts +0 -18
- package/src/schema/marks/alignment.ts +0 -48
- package/src/schema/marks/annotation.ts +0 -107
- package/src/schema/marks/border.ts +0 -74
- package/src/schema/marks/breakout.ts +0 -42
- package/src/schema/marks/code.ts +0 -45
- package/src/schema/marks/confluence-inline-comment.ts +0 -32
- package/src/schema/marks/data-consumer.ts +0 -100
- package/src/schema/marks/em.ts +0 -19
- package/src/schema/marks/fragment.ts +0 -77
- package/src/schema/marks/indentation.ts +0 -47
- package/src/schema/marks/link.ts +0 -139
- package/src/schema/marks/strike.ts +0 -26
- package/src/schema/marks/strong.ts +0 -45
- package/src/schema/marks/subsup.ts +0 -53
- package/src/schema/marks/text-color.ts +0 -172
- package/src/schema/marks/type-ahead-query.ts +0 -22
- package/src/schema/marks/underline.ts +0 -24
- package/src/schema/marks/unsupported-mark.ts +0 -9
- package/src/schema/marks/unsupported-node-attributes.ts +0 -8
- package/src/schema/nodes/block-card.ts +0 -121
- package/src/schema/nodes/blockquote.ts +0 -25
- package/src/schema/nodes/bodied-extension.ts +0 -75
- package/src/schema/nodes/bullet-list.ts +0 -17
- package/src/schema/nodes/caption.ts +0 -51
- package/src/schema/nodes/code-block.ts +0 -176
- package/src/schema/nodes/confluence-jira-issue.ts +0 -43
- package/src/schema/nodes/confluence-unsupported-block.ts +0 -29
- package/src/schema/nodes/confluence-unsupported-inline.ts +0 -30
- package/src/schema/nodes/date.ts +0 -38
- package/src/schema/nodes/decision-item.ts +0 -50
- package/src/schema/nodes/decision-list.ts +0 -56
- package/src/schema/nodes/doc.ts +0 -30
- package/src/schema/nodes/embed-card.ts +0 -62
- package/src/schema/nodes/emoji.ts +0 -89
- package/src/schema/nodes/expand.ts +0 -101
- package/src/schema/nodes/extension.ts +0 -60
- package/src/schema/nodes/hard-break.ts +0 -21
- package/src/schema/nodes/heading.ts +0 -64
- package/src/schema/nodes/image.ts +0 -32
- package/src/schema/nodes/inline-card.ts +0 -70
- package/src/schema/nodes/inline-extension.ts +0 -57
- package/src/schema/nodes/layout-column.ts +0 -68
- package/src/schema/nodes/layout-section.ts +0 -93
- package/src/schema/nodes/list-item.ts +0 -13
- package/src/schema/nodes/media-group.ts +0 -44
- package/src/schema/nodes/media-inline.ts +0 -19
- package/src/schema/nodes/media-single.ts +0 -179
- package/src/schema/nodes/media.ts +0 -253
- package/src/schema/nodes/mention.ts +0 -86
- package/src/schema/nodes/nested-expand.ts +0 -77
- package/src/schema/nodes/ordered-list.ts +0 -62
- package/src/schema/nodes/panel.ts +0 -133
- package/src/schema/nodes/paragraph.ts +0 -79
- package/src/schema/nodes/placeholder.ts +0 -40
- package/src/schema/nodes/rule.ts +0 -17
- package/src/schema/nodes/status.ts +0 -58
- package/src/schema/nodes/tableNodes.ts +0 -478
- package/src/schema/nodes/task-item.ts +0 -51
- package/src/schema/nodes/task-list.ts +0 -61
- package/src/schema/nodes/text.ts +0 -19
- package/src/schema/nodes/types/block-content.ts +0 -51
- package/src/schema/nodes/types/extensions.ts +0 -36
- package/src/schema/nodes/types/inline-content.ts +0 -56
- package/src/schema/nodes/types/list.ts +0 -54
- package/src/schema/nodes/types/mark.ts +0 -16
- package/src/schema/nodes/types/non-nestable-block-content.ts +0 -39
- package/src/schema/nodes/types/rich-media-common.ts +0 -51
- package/src/schema/nodes/unknown-block.ts +0 -13
- package/src/schema/nodes/unsupported-block.ts +0 -28
- package/src/schema/nodes/unsupported-inline.ts +0 -27
- package/src/schema/unsupported.ts +0 -4
- package/src/steps/__tests__/unit/analytics.ts +0 -72
- package/src/steps/__tests__/unit/link-meta-step.ts +0 -64
- package/src/steps/__tests__/unit/override-document-step.ts +0 -174
- package/src/steps/__tests__/unit/set-attrs.ts +0 -71
- package/src/steps/analytics.ts +0 -189
- package/src/steps/link-meta-step.ts +0 -105
- package/src/steps/override-document-step.ts +0 -97
- package/src/steps/set-attrs.tsx +0 -74
- package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-0.json +0 -15
- package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-1.json +0 -15
- package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-2.json +0 -15
- package/src/steps/table/__tests__/__fixtures__/basic/add-column-at-3.json +0 -15
- package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-0.json +0 -9
- package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-1.json +0 -9
- package/src/steps/table/__tests__/__fixtures__/basic/remove-column-at-2.json +0 -9
- package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row-inverted.json +0 -98
- package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row.json +0 -71
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-0.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1-inverted.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-1.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2-inverted.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-2.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/add-column-at-3.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0-inverted.json +0 -63
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-0.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1-inverted.json +0 -64
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-1.json +0 -22
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2-inverted.json +0 -63
- package/src/steps/table/__tests__/__fixtures__/merge-cells/columns/remove-column-at-2.json +0 -21
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-0.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-1.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-2.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3-inverted.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/add-column-at-3.json +0 -19
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0-inverted.json +0 -52
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-0.json +0 -38
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1-inverted.json +0 -52
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-1.json +0 -38
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2-inverted.json +0 -25
- package/src/steps/table/__tests__/__fixtures__/merge-cells/rows/remove-column-at-2.json +0 -11
- package/src/steps/table/__tests__/_utils.ts +0 -102
- package/src/steps/table/__tests__/add-column-merge-columns.ts +0 -509
- package/src/steps/table/__tests__/add-column-merge-rows.ts +0 -466
- package/src/steps/table/__tests__/add-column.ts +0 -638
- package/src/steps/table/add-column.ts +0 -443
- package/src/steps/table/constants.ts +0 -4
- package/src/steps/table/sort-column.ts +0 -57
- package/src/steps/table/types.ts +0 -48
- package/src/steps/table/utils/cell-step.ts +0 -239
- package/src/steps/table/utils/cells-at-column.ts +0 -75
- package/src/steps/table/utils/find-column.ts +0 -90
- package/src/steps/table/utils/get-table-rect-from-doc.ts +0 -37
- package/src/steps/table/utils/side-effects/rows.ts +0 -327
- package/src/steps/table/utils/side-effects/side-effects.ts +0 -90
- package/src/steps/table/utils/side-effects/table.ts +0 -112
- package/src/steps/table/utils/side-effects/types.ts +0 -34
- package/src/steps/table/utils/table-map.ts +0 -28
- package/src/steps/type-ahead.ts +0 -100
- package/src/steps.ts +0 -16
- package/src/utils/colors.ts +0 -171
- package/src/utils/confluence/emoji.ts +0 -99
- package/src/utils/extensions.ts +0 -32
- package/src/utils/parseDOM.ts +0 -2
- package/src/utils/url.ts +0 -173
- package/src/utils/uuid.ts +0 -19
- package/src/version.json +0 -6
package/src/steps/analytics.ts
DELETED
@@ -1,189 +0,0 @@
|
|
1
|
-
import { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
2
|
-
import {
|
3
|
-
Step,
|
4
|
-
StepResult,
|
5
|
-
StepMap,
|
6
|
-
ReplaceStep,
|
7
|
-
Mappable,
|
8
|
-
} from '@atlaskit/editor-prosemirror/transform';
|
9
|
-
import { Slice } from '@atlaskit/editor-prosemirror/model';
|
10
|
-
|
11
|
-
export const analyticsStepType = 'atlaskit-analytics';
|
12
|
-
export const analyticsInvertStepType = 'atlaskit-analytics-invert';
|
13
|
-
|
14
|
-
export interface AnalyticsPayload {
|
15
|
-
action: string;
|
16
|
-
actionSubject: string;
|
17
|
-
actionSubjectId?: string | null;
|
18
|
-
attributes?: Record<string, any>;
|
19
|
-
eventType: string;
|
20
|
-
}
|
21
|
-
|
22
|
-
export interface AnalyticsWithChannel<P extends AnalyticsPayload> {
|
23
|
-
payload: P;
|
24
|
-
channel: string;
|
25
|
-
}
|
26
|
-
|
27
|
-
enum HISTORY_ACTIONS {
|
28
|
-
UNDID = 'undid',
|
29
|
-
REDID = 'redid',
|
30
|
-
}
|
31
|
-
interface UndoAnalyticsEventPayload {
|
32
|
-
action: HISTORY_ACTIONS.UNDID;
|
33
|
-
actionSubject: string;
|
34
|
-
actionSubjectId?: string;
|
35
|
-
attributes?: Record<string, any>;
|
36
|
-
eventType: string;
|
37
|
-
}
|
38
|
-
interface RedoAnalyticsEventPayload {
|
39
|
-
action: HISTORY_ACTIONS.REDID;
|
40
|
-
actionSubject: string;
|
41
|
-
actionSubjectId?: string;
|
42
|
-
attributes?: Record<string, any>;
|
43
|
-
eventType: string;
|
44
|
-
}
|
45
|
-
|
46
|
-
type AnalyticsInvertPayload =
|
47
|
-
| UndoAnalyticsEventPayload
|
48
|
-
| RedoAnalyticsEventPayload;
|
49
|
-
type AnalyticsInvert = AnalyticsWithChannel<AnalyticsInvertPayload>;
|
50
|
-
|
51
|
-
/** Creates undo event from a normal analytics event */
|
52
|
-
function createUndoEvent<P extends AnalyticsPayload>(
|
53
|
-
analyticsEvent: AnalyticsWithChannel<P>,
|
54
|
-
): AnalyticsWithChannel<UndoAnalyticsEventPayload> {
|
55
|
-
return {
|
56
|
-
...analyticsEvent,
|
57
|
-
payload: {
|
58
|
-
action: HISTORY_ACTIONS.UNDID,
|
59
|
-
actionSubject: analyticsEvent.payload.actionSubject,
|
60
|
-
actionSubjectId: analyticsEvent.payload.action,
|
61
|
-
attributes: {
|
62
|
-
...analyticsEvent.payload.attributes,
|
63
|
-
actionSubjectId: analyticsEvent.payload.actionSubjectId,
|
64
|
-
inputMethod: analyticsEvent.payload.attributes?.inputMethod || '',
|
65
|
-
},
|
66
|
-
eventType: 'track',
|
67
|
-
},
|
68
|
-
};
|
69
|
-
}
|
70
|
-
|
71
|
-
/** Toggles event action between undo & redo */
|
72
|
-
const toggleEventAction = (
|
73
|
-
analyticsEvent: AnalyticsWithChannel<
|
74
|
-
UndoAnalyticsEventPayload | RedoAnalyticsEventPayload
|
75
|
-
>,
|
76
|
-
): AnalyticsInvert => ({
|
77
|
-
...analyticsEvent,
|
78
|
-
payload: {
|
79
|
-
...analyticsEvent.payload,
|
80
|
-
action:
|
81
|
-
analyticsEvent.payload.action === HISTORY_ACTIONS.UNDID
|
82
|
-
? HISTORY_ACTIONS.REDID
|
83
|
-
: HISTORY_ACTIONS.UNDID,
|
84
|
-
},
|
85
|
-
});
|
86
|
-
|
87
|
-
function isHistoryAnalyticsEvent(
|
88
|
-
event: AnalyticsWithChannel<AnalyticsPayload>,
|
89
|
-
): event is AnalyticsWithChannel<
|
90
|
-
UndoAnalyticsEventPayload | RedoAnalyticsEventPayload
|
91
|
-
> {
|
92
|
-
return (
|
93
|
-
event.payload.action === HISTORY_ACTIONS.UNDID ||
|
94
|
-
event.payload.action === HISTORY_ACTIONS.REDID
|
95
|
-
);
|
96
|
-
}
|
97
|
-
|
98
|
-
export type AnalyticsInvertStep = AnalyticsStep<AnalyticsInvertPayload>;
|
99
|
-
|
100
|
-
/**
|
101
|
-
* Custom Prosemirror Step to fire our GAS V3 analytics events
|
102
|
-
* Using a Step means that it will work with prosemirror-history and we get
|
103
|
-
* undo/redo events for free
|
104
|
-
*/
|
105
|
-
export class AnalyticsStep<P extends AnalyticsPayload> extends Step {
|
106
|
-
public analyticsEvents: AnalyticsWithChannel<P>[] = [];
|
107
|
-
pos?: number;
|
108
|
-
private actionsToIgnore: string[] = [];
|
109
|
-
|
110
|
-
constructor(
|
111
|
-
analyticsEvents: AnalyticsWithChannel<P>[],
|
112
|
-
actionsToIgnore: string[] = [],
|
113
|
-
pos?: number, // Used to create the map, prevent splitting history.
|
114
|
-
) {
|
115
|
-
super();
|
116
|
-
this.analyticsEvents = analyticsEvents;
|
117
|
-
this.actionsToIgnore = actionsToIgnore;
|
118
|
-
this.pos = pos;
|
119
|
-
}
|
120
|
-
|
121
|
-
/**
|
122
|
-
* Generate new undo/redo analytics event when step is inverted
|
123
|
-
*/
|
124
|
-
invert() {
|
125
|
-
const analyticsEvents: AnalyticsInvert[] = this.analyticsEvents
|
126
|
-
.filter(
|
127
|
-
(analyticsEvent) =>
|
128
|
-
this.actionsToIgnore.indexOf(analyticsEvent.payload.action) === -1,
|
129
|
-
)
|
130
|
-
.map((analyticsEvent) => {
|
131
|
-
if (isHistoryAnalyticsEvent(analyticsEvent)) {
|
132
|
-
return toggleEventAction(analyticsEvent);
|
133
|
-
} else {
|
134
|
-
return createUndoEvent(analyticsEvent);
|
135
|
-
}
|
136
|
-
});
|
137
|
-
|
138
|
-
return new AnalyticsStep(analyticsEvents, []);
|
139
|
-
}
|
140
|
-
|
141
|
-
apply(doc: PMNode) {
|
142
|
-
return StepResult.ok(doc);
|
143
|
-
}
|
144
|
-
|
145
|
-
map(mapping: Mappable) {
|
146
|
-
let newPos = this.pos;
|
147
|
-
if (typeof newPos === 'number') {
|
148
|
-
newPos = mapping.map(newPos);
|
149
|
-
}
|
150
|
-
// Return the same events, this step will never be removed
|
151
|
-
return new AnalyticsStep(
|
152
|
-
this.analyticsEvents,
|
153
|
-
this.actionsToIgnore,
|
154
|
-
newPos,
|
155
|
-
);
|
156
|
-
}
|
157
|
-
|
158
|
-
getMap() {
|
159
|
-
if (typeof this.pos === 'number') {
|
160
|
-
return new StepMap([this.pos, 0, 0]);
|
161
|
-
}
|
162
|
-
return new StepMap([]);
|
163
|
-
}
|
164
|
-
|
165
|
-
merge(other: Step): AnalyticsStep<P> | null {
|
166
|
-
if (other instanceof AnalyticsStep) {
|
167
|
-
const otherAnalyticsEvents = (other as AnalyticsStep<P>)
|
168
|
-
.analyticsEvents as AnalyticsWithChannel<P>[];
|
169
|
-
return new AnalyticsStep([
|
170
|
-
...otherAnalyticsEvents,
|
171
|
-
...this.analyticsEvents,
|
172
|
-
]);
|
173
|
-
}
|
174
|
-
return null;
|
175
|
-
}
|
176
|
-
|
177
|
-
toJSON() {
|
178
|
-
return {
|
179
|
-
stepType: analyticsStepType,
|
180
|
-
};
|
181
|
-
}
|
182
|
-
|
183
|
-
static fromJSON() {
|
184
|
-
return new ReplaceStep(0, 0, Slice.empty);
|
185
|
-
}
|
186
|
-
}
|
187
|
-
|
188
|
-
/** Register this step with Prosemirror */
|
189
|
-
Step.jsonID(analyticsStepType, AnalyticsStep);
|
@@ -1,105 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Node as PMNode,
|
3
|
-
Schema,
|
4
|
-
Slice,
|
5
|
-
} from '@atlaskit/editor-prosemirror/model';
|
6
|
-
import {
|
7
|
-
ReplaceStep,
|
8
|
-
Step,
|
9
|
-
StepMap,
|
10
|
-
StepResult,
|
11
|
-
Mappable,
|
12
|
-
} from '@atlaskit/editor-prosemirror/transform';
|
13
|
-
|
14
|
-
export const stepType = 'editor-linking-meta';
|
15
|
-
export const invertStepType = 'editor-linking-meta-invert';
|
16
|
-
|
17
|
-
export type LinkStepMetadata = {
|
18
|
-
/**
|
19
|
-
* Editor action performed
|
20
|
-
*/
|
21
|
-
action?: string;
|
22
|
-
/**
|
23
|
-
* Editor input method that triggered the transaction
|
24
|
-
*/
|
25
|
-
inputMethod?: string;
|
26
|
-
/**
|
27
|
-
* The applicable card action for this step
|
28
|
-
* if is RESOLVE then the undo/redo steps should be considered "updates" of a link
|
29
|
-
*/
|
30
|
-
cardAction?: 'RESOLVE';
|
31
|
-
/**
|
32
|
-
* Source UI that tiggered this step, if available/applicable
|
33
|
-
*/
|
34
|
-
sourceEvent?: unknown;
|
35
|
-
};
|
36
|
-
|
37
|
-
/**
|
38
|
-
* Custom Prosemirror Step to attach metadata about user interactions with links
|
39
|
-
* Using a Step means that it will work with prosemirror-history and we get utilise when
|
40
|
-
* firing events on history change
|
41
|
-
*/
|
42
|
-
export class LinkMetaStep extends Step {
|
43
|
-
constructor(
|
44
|
-
private pos: number | null,
|
45
|
-
private metadata: LinkStepMetadata,
|
46
|
-
private isInverted: boolean = false,
|
47
|
-
) {
|
48
|
-
super();
|
49
|
-
}
|
50
|
-
|
51
|
-
public getMetadata() {
|
52
|
-
return this.metadata;
|
53
|
-
}
|
54
|
-
|
55
|
-
/**
|
56
|
-
* Generate new undo/redo analytics event when step is inverted
|
57
|
-
*/
|
58
|
-
invert() {
|
59
|
-
/**
|
60
|
-
* Omit sourceEvent in history
|
61
|
-
*/
|
62
|
-
const { sourceEvent, ...metadata } = this.metadata;
|
63
|
-
return new LinkMetaStep(this.pos, metadata, true);
|
64
|
-
}
|
65
|
-
|
66
|
-
// Should make no modifications to the doc
|
67
|
-
apply(doc: PMNode) {
|
68
|
-
return StepResult.ok(doc);
|
69
|
-
}
|
70
|
-
|
71
|
-
map(mapping: Mappable) {
|
72
|
-
let newPos = this.pos;
|
73
|
-
if (typeof newPos === 'number') {
|
74
|
-
newPos = mapping.map(newPos);
|
75
|
-
}
|
76
|
-
// Return the same events, this step will never be removed
|
77
|
-
return new LinkMetaStep(newPos, this.metadata, this.isInverted);
|
78
|
-
}
|
79
|
-
getMap() {
|
80
|
-
return new StepMap([this.pos || 0, 0, 0]);
|
81
|
-
}
|
82
|
-
|
83
|
-
// Return null to avoid merging events
|
84
|
-
merge(): null {
|
85
|
-
return null;
|
86
|
-
}
|
87
|
-
|
88
|
-
toJSON() {
|
89
|
-
// When serialized we should create a noop Replace step
|
90
|
-
return {
|
91
|
-
stepType: 'replace',
|
92
|
-
from: 0,
|
93
|
-
to: 0,
|
94
|
-
};
|
95
|
-
}
|
96
|
-
|
97
|
-
static fromJSON<S extends Schema = any>(_: S, __: { [key: string]: any }) {
|
98
|
-
// This is a "local custom step" once serialized
|
99
|
-
// we need to transform it in a no-operation action
|
100
|
-
return new ReplaceStep(0, 0, Slice.empty);
|
101
|
-
}
|
102
|
-
}
|
103
|
-
|
104
|
-
/** Register this step with Prosemirror */
|
105
|
-
Step.jsonID(stepType, LinkMetaStep);
|
@@ -1,97 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Step,
|
3
|
-
StepResult,
|
4
|
-
StepMap,
|
5
|
-
} from '@atlaskit/editor-prosemirror/transform';
|
6
|
-
import { Node as PMNode, Schema } from '@atlaskit/editor-prosemirror/model';
|
7
|
-
|
8
|
-
type Options = {
|
9
|
-
nextDocument: PMNode;
|
10
|
-
inverted?: boolean;
|
11
|
-
};
|
12
|
-
|
13
|
-
export const overrideDocumentStepType = 'override-document';
|
14
|
-
|
15
|
-
export class OverrideDocumentStep extends Step {
|
16
|
-
public inverted = false;
|
17
|
-
private nextDocument: PMNode;
|
18
|
-
private oldDocumentSize: number = 0;
|
19
|
-
|
20
|
-
constructor(opts: Options) {
|
21
|
-
super();
|
22
|
-
|
23
|
-
const { inverted, nextDocument } = opts;
|
24
|
-
|
25
|
-
if (nextDocument.type.name !== 'doc') {
|
26
|
-
throw new Error(
|
27
|
-
'nextDocument should be the entire prosemirror doc node and not only its content.',
|
28
|
-
);
|
29
|
-
}
|
30
|
-
|
31
|
-
this.nextDocument = nextDocument;
|
32
|
-
this.inverted = Boolean(inverted);
|
33
|
-
}
|
34
|
-
|
35
|
-
apply(doc: PMNode): StepResult {
|
36
|
-
this.oldDocumentSize = doc.content.size;
|
37
|
-
|
38
|
-
return StepResult.ok(this.nextDocument);
|
39
|
-
}
|
40
|
-
|
41
|
-
map(): OverrideDocumentStep {
|
42
|
-
return new OverrideDocumentStep({
|
43
|
-
nextDocument: this.nextDocument,
|
44
|
-
inverted: this.inverted,
|
45
|
-
});
|
46
|
-
}
|
47
|
-
|
48
|
-
getMap(): StepMap {
|
49
|
-
if (!this.nextDocument || !this.oldDocumentSize) {
|
50
|
-
return new StepMap([0, 0, 0]);
|
51
|
-
}
|
52
|
-
|
53
|
-
const oldSize = this.oldDocumentSize;
|
54
|
-
const nextDocumentSize = this.nextDocument.content.size;
|
55
|
-
|
56
|
-
return new StepMap([0, oldSize, nextDocumentSize]);
|
57
|
-
}
|
58
|
-
|
59
|
-
invert(doc: PMNode): OverrideDocumentStep {
|
60
|
-
return new OverrideDocumentStep({
|
61
|
-
nextDocument: doc,
|
62
|
-
inverted: true,
|
63
|
-
});
|
64
|
-
}
|
65
|
-
|
66
|
-
toJSON(): OverrideDocumentStepJSON {
|
67
|
-
return {
|
68
|
-
stepType: overrideDocumentStepType,
|
69
|
-
inverted: this.inverted,
|
70
|
-
nextDocument: this.nextDocument.toJSON(),
|
71
|
-
};
|
72
|
-
}
|
73
|
-
|
74
|
-
static fromJSON(
|
75
|
-
schema: Schema,
|
76
|
-
json: OverrideDocumentStepJSON,
|
77
|
-
): OverrideDocumentStep {
|
78
|
-
if (!json || json.stepType !== overrideDocumentStepType) {
|
79
|
-
throw new RangeError(
|
80
|
-
'Invalid overrideDocument step OverrideDocumentStep.fromJSON',
|
81
|
-
);
|
82
|
-
}
|
83
|
-
|
84
|
-
return new OverrideDocumentStep({
|
85
|
-
inverted: json.inverted,
|
86
|
-
nextDocument: schema.nodeFromJSON(json.nextDocument),
|
87
|
-
});
|
88
|
-
}
|
89
|
-
}
|
90
|
-
|
91
|
-
export type OverrideDocumentStepJSON = {
|
92
|
-
stepType: 'override-document';
|
93
|
-
inverted: boolean;
|
94
|
-
nextDocument: { [key: string]: any };
|
95
|
-
};
|
96
|
-
|
97
|
-
Step.jsonID(overrideDocumentStepType, OverrideDocumentStep);
|
package/src/steps/set-attrs.tsx
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
import {
|
2
|
-
Mappable,
|
3
|
-
Step,
|
4
|
-
StepResult,
|
5
|
-
} from '@atlaskit/editor-prosemirror/transform';
|
6
|
-
import {
|
7
|
-
Node as ProseMirrorNode,
|
8
|
-
Slice,
|
9
|
-
Fragment,
|
10
|
-
Schema,
|
11
|
-
} from '@atlaskit/editor-prosemirror/model';
|
12
|
-
|
13
|
-
/**
|
14
|
-
* For more context on what this is about:
|
15
|
-
* @see https://discuss.prosemirror.net/t/preventing-image-placeholder-replacement-from-being-undone/1394
|
16
|
-
*/
|
17
|
-
export class SetAttrsStep extends Step {
|
18
|
-
pos: number;
|
19
|
-
attrs: object;
|
20
|
-
|
21
|
-
constructor(pos: number, attrs: object) {
|
22
|
-
super();
|
23
|
-
this.pos = pos;
|
24
|
-
this.attrs = attrs;
|
25
|
-
}
|
26
|
-
|
27
|
-
apply(doc: ProseMirrorNode) {
|
28
|
-
let target = doc.nodeAt(this.pos);
|
29
|
-
if (!target) {
|
30
|
-
return StepResult.fail('No node at given position');
|
31
|
-
}
|
32
|
-
|
33
|
-
if (target.isText) {
|
34
|
-
return StepResult.fail(
|
35
|
-
'Target is a text node. Attributes are not allowed.',
|
36
|
-
);
|
37
|
-
}
|
38
|
-
|
39
|
-
const attrs = {
|
40
|
-
...(target.attrs || {}),
|
41
|
-
...(this.attrs || {}),
|
42
|
-
};
|
43
|
-
|
44
|
-
let newNode = target.type.create(attrs, Fragment.empty, target.marks);
|
45
|
-
let slice = new Slice(Fragment.from(newNode), 0, target.isLeaf ? 0 : 1);
|
46
|
-
return StepResult.fromReplace(doc, this.pos, this.pos + 1, slice);
|
47
|
-
}
|
48
|
-
|
49
|
-
invert(doc: ProseMirrorNode) {
|
50
|
-
let target = doc.nodeAt(this.pos);
|
51
|
-
return new SetAttrsStep(this.pos, target ? target.attrs : {});
|
52
|
-
}
|
53
|
-
|
54
|
-
map(mapping: Mappable): SetAttrsStep | null {
|
55
|
-
let result = mapping.mapResult(this.pos, 1);
|
56
|
-
return result.deleted ? null : new SetAttrsStep(result.pos, this.attrs);
|
57
|
-
}
|
58
|
-
|
59
|
-
toJSON() {
|
60
|
-
return { stepType: 'setAttrs', pos: this.pos, attrs: this.attrs };
|
61
|
-
}
|
62
|
-
|
63
|
-
static fromJSON(_schema: Schema, json: { pos?: number; attrs: object }) {
|
64
|
-
if (
|
65
|
-
typeof json.pos !== 'number' ||
|
66
|
-
(json.attrs !== null && typeof json.attrs !== 'object')
|
67
|
-
) {
|
68
|
-
throw new RangeError('Invalid input for SetAttrsStep.fromJSON');
|
69
|
-
}
|
70
|
-
return new SetAttrsStep(json.pos, json.attrs);
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
|
-
Step.jsonID('setAttrs', SetAttrsStep);
|
package/src/steps/table/__tests__/__fixtures__/basic/remove-table/remove-last-row-inverted.json
DELETED
@@ -1,98 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"stepType": "ak-add-column",
|
3
|
-
"tablePos": 2,
|
4
|
-
"cells": [
|
5
|
-
{
|
6
|
-
"from": 2,
|
7
|
-
"to": 6,
|
8
|
-
"newCell": {
|
9
|
-
"type": "tableCell",
|
10
|
-
"attrs": {
|
11
|
-
"colspan": 1,
|
12
|
-
"rowspan": 1,
|
13
|
-
"colwidth": null,
|
14
|
-
"background": "#AAAAAA"
|
15
|
-
},
|
16
|
-
"content": [
|
17
|
-
{
|
18
|
-
"type": "paragraph"
|
19
|
-
}
|
20
|
-
]
|
21
|
-
}
|
22
|
-
}
|
23
|
-
],
|
24
|
-
"isDelete": false,
|
25
|
-
"sideEffects": {
|
26
|
-
"table": {
|
27
|
-
"from": 2,
|
28
|
-
"to": 22,
|
29
|
-
"node": {
|
30
|
-
"type": "table",
|
31
|
-
"attrs": {
|
32
|
-
"isNumberColumnEnabled": false,
|
33
|
-
"layout": "default",
|
34
|
-
"__autoSize": false
|
35
|
-
},
|
36
|
-
"content": [
|
37
|
-
{
|
38
|
-
"type": "tableRow",
|
39
|
-
"content": [
|
40
|
-
{
|
41
|
-
"type": "tableCell",
|
42
|
-
"attrs": {
|
43
|
-
"colspan": 1,
|
44
|
-
"rowspan": 1,
|
45
|
-
"colwidth": null,
|
46
|
-
"background": "#AAAAAA"
|
47
|
-
},
|
48
|
-
"content": [
|
49
|
-
{
|
50
|
-
"type": "paragraph"
|
51
|
-
}
|
52
|
-
]
|
53
|
-
}
|
54
|
-
]
|
55
|
-
},
|
56
|
-
{
|
57
|
-
"type": "tableRow",
|
58
|
-
"content": [
|
59
|
-
{
|
60
|
-
"type": "tableCell",
|
61
|
-
"attrs": {
|
62
|
-
"colspan": 1,
|
63
|
-
"rowspan": 1,
|
64
|
-
"colwidth": null,
|
65
|
-
"background": "#AAAAAA"
|
66
|
-
},
|
67
|
-
"content": [
|
68
|
-
{
|
69
|
-
"type": "paragraph"
|
70
|
-
}
|
71
|
-
]
|
72
|
-
}
|
73
|
-
]
|
74
|
-
},
|
75
|
-
{
|
76
|
-
"type": "tableRow",
|
77
|
-
"content": [
|
78
|
-
{
|
79
|
-
"type": "tableCell",
|
80
|
-
"attrs": {
|
81
|
-
"colspan": 1,
|
82
|
-
"rowspan": 1,
|
83
|
-
"colwidth": null,
|
84
|
-
"background": "#AAAAAA"
|
85
|
-
},
|
86
|
-
"content": [
|
87
|
-
{
|
88
|
-
"type": "paragraph"
|
89
|
-
}
|
90
|
-
]
|
91
|
-
}
|
92
|
-
]
|
93
|
-
}
|
94
|
-
]
|
95
|
-
}
|
96
|
-
}
|
97
|
-
}
|
98
|
-
}
|