@atlaskit/editor-plugin-block-type 12.1.1 → 12.1.2

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,19 @@
1
1
  # @atlaskit/editor-plugin-block-type
2
2
 
3
+ ## 12.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`8b781b3b3f9ca`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8b781b3b3f9ca) -
8
+ Add setSmallText and setSmallTextWithAnalytics commands, modify setNormalText to remove fontSize
9
+ mark, add FORMAT_SMALL_TEXT analytics enum.
10
+
11
+ Add support to the renderer to render 'small text'.
12
+
13
+ Add 'fontSize' to stage0 default schema.
14
+
15
+ - Updated dependencies
16
+
3
17
  ## 12.1.1
4
18
 
5
19
  ### Patch Changes
@@ -13,11 +13,15 @@ exports.setHeading = setHeading;
13
13
  exports.setHeadingWithAnalytics = void 0;
14
14
  exports.setNormalText = setNormalText;
15
15
  exports.setNormalTextWithAnalytics = setNormalTextWithAnalytics;
16
+ exports.setSmallText = setSmallText;
17
+ exports.setSmallTextWithAnalytics = setSmallTextWithAnalytics;
16
18
  var _analytics = require("@atlaskit/editor-common/analytics");
19
+ var _commands = require("@atlaskit/editor-common/commands");
17
20
  var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
18
21
  var _utils = require("@atlaskit/editor-common/utils");
19
22
  var _transform = require("@atlaskit/editor-prosemirror/transform");
20
23
  var _editorTables = require("@atlaskit/editor-tables");
24
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
21
25
  var _blockTypes = require("../block-types");
22
26
  var _clearFormatting = require("./clear-formatting");
23
27
  var _wrapSelectionIn = require("./wrapSelectionIn");
@@ -33,6 +37,11 @@ function setBlockType(name) {
33
37
  tr: tr
34
38
  });
35
39
  }
40
+ if (name === 'smallText' && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true)) {
41
+ return setSmallText()({
42
+ tr: tr
43
+ });
44
+ }
36
45
  var headingBlockType = _blockTypes.HEADINGS_BY_NAME[name];
37
46
  if (headingBlockType && nodes.heading && headingBlockType.level) {
38
47
  return setHeading(headingBlockType.level)({
@@ -76,6 +85,12 @@ function setHeading(level, fromBlockQuote) {
76
85
  });
77
86
  }
78
87
  });
88
+ var fontSize = schema.marks.fontSize;
89
+ if (fontSize && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true)) {
90
+ (0, _commands.toggleBlockMarkNext)(fontSize, function () {
91
+ return false;
92
+ }, [schema.nodes.heading])(tr);
93
+ }
79
94
  return tr;
80
95
  };
81
96
  }
@@ -88,6 +103,11 @@ function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi, fromBl
88
103
  tr: tr
89
104
  });
90
105
  }
106
+ if (name === 'smallText' && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true)) {
107
+ return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi)({
108
+ tr: tr
109
+ });
110
+ }
91
111
  var headingBlockType = _blockTypes.HEADINGS_BY_NAME[name];
92
112
  if (headingBlockType && nodes.heading && headingBlockType.level) {
93
113
  return setHeadingWithAnalytics(headingBlockType.level, inputMethod, editorAnalyticsApi, fromBlockQuote)({
@@ -97,15 +117,59 @@ function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi, fromBl
97
117
  return null;
98
118
  };
99
119
  }
100
- function setNormalText(fromBlockQuote) {
120
+ function setSmallText() {
101
121
  return function (_ref5) {
102
122
  var tr = _ref5.tr;
103
- var selection = tr.selection,
104
- schema = tr.doc.type.schema;
123
+ var _tr$doc$type$schema = tr.doc.type.schema,
124
+ fontSize = _tr$doc$type$schema.marks.fontSize,
125
+ paragraph = _tr$doc$type$schema.nodes.paragraph;
126
+ if (!fontSize) {
127
+ return null;
128
+ }
129
+ var selection = tr.selection;
105
130
  var ranges = selection instanceof _editorTables.CellSelection ? selection.ranges : [selection];
106
131
  ranges.forEach(function (_ref6) {
107
132
  var $from = _ref6.$from,
108
133
  $to = _ref6.$to;
134
+ tr.setBlockType($from.pos, $to.pos, paragraph);
135
+ });
136
+ (0, _commands.toggleBlockMarkNext)(fontSize, function () {
137
+ return {
138
+ fontSize: 'small'
139
+ };
140
+ }, [paragraph])(tr);
141
+ return tr;
142
+ };
143
+ }
144
+ function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
145
+ return withCurrentHeadingLevel(function (previousHeadingLevel) {
146
+ return function (_ref7) {
147
+ var tr = _ref7.tr;
148
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
149
+ action: _analytics.ACTION.FORMATTED,
150
+ actionSubject: _analytics.ACTION_SUBJECT.TEXT,
151
+ eventType: _analytics.EVENT_TYPE.TRACK,
152
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_SMALL_TEXT,
153
+ attributes: {
154
+ inputMethod: inputMethod,
155
+ previousBlockType: previousHeadingLevel !== undefined ? String(previousHeadingLevel) : undefined
156
+ }
157
+ })(tr);
158
+ return setSmallText()({
159
+ tr: tr
160
+ });
161
+ };
162
+ });
163
+ }
164
+ function setNormalText(fromBlockQuote) {
165
+ return function (_ref8) {
166
+ var tr = _ref8.tr;
167
+ var selection = tr.selection,
168
+ schema = tr.doc.type.schema;
169
+ var ranges = selection instanceof _editorTables.CellSelection ? selection.ranges : [selection];
170
+ ranges.forEach(function (_ref9) {
171
+ var $from = _ref9.$from,
172
+ $to = _ref9.$to;
109
173
  if (fromBlockQuote) {
110
174
  var range = $from.blockRange($to);
111
175
  if (!range) {
@@ -124,12 +188,20 @@ function setNormalText(fromBlockQuote) {
124
188
  tr.setBlockType($from.pos, $to.pos, schema.nodes.paragraph);
125
189
  }
126
190
  });
191
+
192
+ // Remove fontSize mark if present in schema
193
+ var fontSize = schema.marks.fontSize;
194
+ if (fontSize && (0, _expValEquals.expValEquals)('platform_editor_small_font_size', 'isEnabled', true)) {
195
+ (0, _commands.toggleBlockMarkNext)(fontSize, function () {
196
+ return false;
197
+ }, [schema.nodes.paragraph])(tr);
198
+ }
127
199
  return tr;
128
200
  };
129
201
  }
130
202
  function clearFormatting(inputMethod, editorAnalyticsApi) {
131
- return function (_ref7) {
132
- var tr = _ref7.tr;
203
+ return function (_ref0) {
204
+ var tr = _ref0.tr;
133
205
  var formattingCleared = [];
134
206
  var schema = tr.doc.type.schema;
135
207
  _clearFormatting.FORMATTING_MARK_TYPES.forEach(function (mark) {
@@ -186,8 +258,8 @@ function clearFormatting(inputMethod, editorAnalyticsApi) {
186
258
  };
187
259
  }
188
260
  function withCurrentHeadingLevel(fn) {
189
- return function (_ref8) {
190
- var tr = _ref8.tr;
261
+ return function (_ref1) {
262
+ var tr = _ref1.tr;
191
263
  // Find all headings and paragraphs of text
192
264
  var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
193
265
  heading = _tr$doc$type$schema$n.heading,
@@ -224,8 +296,8 @@ function withCurrentHeadingLevel(fn) {
224
296
  }
225
297
  function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote) {
226
298
  return withCurrentHeadingLevel(function (previousHeadingLevel) {
227
- return function (_ref9) {
228
- var tr = _ref9.tr;
299
+ return function (_ref10) {
300
+ var tr = _ref10.tr;
229
301
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
230
302
  action: _analytics.ACTION.FORMATTED,
231
303
  actionSubject: _analytics.ACTION_SUBJECT.TEXT,
@@ -245,8 +317,8 @@ function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQu
245
317
  }
246
318
  var setHeadingWithAnalytics = exports.setHeadingWithAnalytics = function setHeadingWithAnalytics(newHeadingLevel, inputMethod, editorAnalyticsApi, fromBlockQuote) {
247
319
  return withCurrentHeadingLevel(function (previousHeadingLevel) {
248
- return function (_ref0) {
249
- var tr = _ref0.tr;
320
+ return function (_ref11) {
321
+ var tr = _ref11.tr;
250
322
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
251
323
  action: _analytics.ACTION.FORMATTED,
252
324
  actionSubject: _analytics.ACTION_SUBJECT.TEXT,
@@ -294,9 +366,9 @@ var insertBlockQuoteWithAnalytics = exports.insertBlockQuoteWithAnalytics = func
294
366
  })(insertBlockQuote());
295
367
  };
296
368
  function insertBlockQuoteWithAnalyticsCommand(inputMethod, editorAnalyticsApi) {
297
- return withCurrentHeadingLevel(function (previousHeadingLevel) {
298
- return function (_ref1) {
299
- var tr = _ref1.tr;
369
+ return withCurrentHeadingLevel(function () {
370
+ return function (_ref12) {
371
+ var tr = _ref12.tr;
300
372
  var nodes = tr.doc.type.schema.nodes;
301
373
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
302
374
  action: _analytics.ACTION.FORMATTED,
@@ -314,8 +386,8 @@ function insertBlockQuoteWithAnalyticsCommand(inputMethod, editorAnalyticsApi) {
314
386
  });
315
387
  }
316
388
  var cleanUpAtTheStartOfDocument = exports.cleanUpAtTheStartOfDocument = function cleanUpAtTheStartOfDocument(state, dispatch) {
317
- var _ref10 = state.selection,
318
- $cursor = _ref10.$cursor;
389
+ var _ref13 = state.selection,
390
+ $cursor = _ref13.$cursor;
319
391
  if ($cursor && !$cursor.nodeBefore && !$cursor.nodeAfter && $cursor.pos === 1) {
320
392
  var tr = state.tr,
321
393
  schema = state.schema;
@@ -1,6 +1,7 @@
1
1
  ._11c810sd{font:var(--ds-font-heading-large,normal 653 24px/28px "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
2
2
  ._11c812ln{font:var(--ds-font-heading-xlarge,normal 653 28px/2pc "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
3
3
  ._11c812rg{font:var(--_1h4o6ch)}
4
+ ._11c8130a{font:var(--_1b6nbh6)}
4
5
  ._11c81af2{font:var(--ds-font-heading-medium,normal 653 20px/24px "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
5
6
  ._11c81e3o{font:var(--ds-font-heading-small,normal 653 1pc/20px "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
6
7
  ._11c81fq3{font:var(--_1d0ko3v)}
@@ -20,6 +20,7 @@ var _editorToolbar = require("@atlaskit/editor-toolbar");
20
20
  var _compiled = require("@atlaskit/primitives/compiled");
21
21
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
22
22
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
23
+ var smallTextStyle = null;
23
24
  var normalStyle = null;
24
25
  var heading1Style = null;
25
26
  var heading2Style = null;
@@ -73,6 +74,13 @@ var HeadingText = function HeadingText(_ref) {
73
74
  "--_1c98jvx": (0, _runtime.ix)((0, _ugcTokens.editorUGCToken)('editor.font.heading.h6'))
74
75
  }
75
76
  }, children);
77
+ case 'smallText':
78
+ return /*#__PURE__*/React.createElement("div", {
79
+ className: (0, _runtime.ax)(["_11c8130a"]),
80
+ style: {
81
+ "--_1b6nbh6": (0, _runtime.ix)((0, _ugcTokens.editorUGCToken)('editor.font.body.small'))
82
+ }
83
+ }, children);
76
84
  case 'normal':
77
85
  default:
78
86
  return /*#__PURE__*/React.createElement("div", {
@@ -1,8 +1,10 @@
1
1
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
2
+ import { toggleBlockMarkNext } from '@atlaskit/editor-common/commands';
2
3
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
3
4
  import { filterChildrenBetween, wrapSelectionIn } from '@atlaskit/editor-common/utils';
4
5
  import { liftTarget } from '@atlaskit/editor-prosemirror/transform';
5
6
  import { CellSelection } from '@atlaskit/editor-tables';
7
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
6
8
  import { HEADINGS_BY_NAME, NORMAL_TEXT } from '../block-types';
7
9
  import { FORMATTING_NODE_TYPES, FORMATTING_MARK_TYPES, cellSelectionNodesBetween, formatTypes, clearNodeFormattingOnSelection } from './clear-formatting';
8
10
  import { wrapSelectionInBlockType } from './wrapSelectionIn';
@@ -18,6 +20,11 @@ export function setBlockType(name) {
18
20
  tr
19
21
  });
20
22
  }
23
+ if (name === 'smallText' && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
24
+ return setSmallText()({
25
+ tr
26
+ });
27
+ }
21
28
  const headingBlockType = HEADINGS_BY_NAME[name];
22
29
  if (headingBlockType && nodes.heading && headingBlockType.level) {
23
30
  return setHeading(headingBlockType.level)({
@@ -69,6 +76,12 @@ export function setHeading(level, fromBlockQuote) {
69
76
  });
70
77
  }
71
78
  });
79
+ const {
80
+ fontSize
81
+ } = schema.marks;
82
+ if (fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
83
+ toggleBlockMarkNext(fontSize, () => false, [schema.nodes.heading])(tr);
84
+ }
72
85
  return tr;
73
86
  };
74
87
  }
@@ -84,6 +97,11 @@ export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi,
84
97
  tr
85
98
  });
86
99
  }
100
+ if (name === 'smallText' && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
101
+ return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi)({
102
+ tr
103
+ });
104
+ }
87
105
  const headingBlockType = HEADINGS_BY_NAME[name];
88
106
  if (headingBlockType && nodes.heading && headingBlockType.level) {
89
107
  return setHeadingWithAnalytics(headingBlockType.level, inputMethod, editorAnalyticsApi, fromBlockQuote)({
@@ -93,6 +111,56 @@ export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi,
93
111
  return null;
94
112
  };
95
113
  }
114
+ export function setSmallText() {
115
+ return function ({
116
+ tr
117
+ }) {
118
+ const {
119
+ marks: {
120
+ fontSize
121
+ },
122
+ nodes: {
123
+ paragraph
124
+ }
125
+ } = tr.doc.type.schema;
126
+ if (!fontSize) {
127
+ return null;
128
+ }
129
+ const {
130
+ selection
131
+ } = tr;
132
+ const ranges = selection instanceof CellSelection ? selection.ranges : [selection];
133
+ ranges.forEach(({
134
+ $from,
135
+ $to
136
+ }) => {
137
+ tr.setBlockType($from.pos, $to.pos, paragraph);
138
+ });
139
+ toggleBlockMarkNext(fontSize, () => ({
140
+ fontSize: 'small'
141
+ }), [paragraph])(tr);
142
+ return tr;
143
+ };
144
+ }
145
+ export function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
146
+ return withCurrentHeadingLevel(previousHeadingLevel => ({
147
+ tr
148
+ }) => {
149
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
150
+ action: ACTION.FORMATTED,
151
+ actionSubject: ACTION_SUBJECT.TEXT,
152
+ eventType: EVENT_TYPE.TRACK,
153
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_SMALL_TEXT,
154
+ attributes: {
155
+ inputMethod,
156
+ previousBlockType: previousHeadingLevel !== undefined ? String(previousHeadingLevel) : undefined
157
+ }
158
+ })(tr);
159
+ return setSmallText()({
160
+ tr
161
+ });
162
+ });
163
+ }
96
164
  export function setNormalText(fromBlockQuote) {
97
165
  return function ({
98
166
  tr
@@ -128,6 +196,14 @@ export function setNormalText(fromBlockQuote) {
128
196
  tr.setBlockType($from.pos, $to.pos, schema.nodes.paragraph);
129
197
  }
130
198
  });
199
+
200
+ // Remove fontSize mark if present in schema
201
+ const {
202
+ fontSize
203
+ } = schema.marks;
204
+ if (fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
205
+ toggleBlockMarkNext(fontSize, () => false, [schema.nodes.paragraph])(tr);
206
+ }
131
207
  return tr;
132
208
  };
133
209
  }
@@ -294,7 +370,7 @@ export const insertBlockQuoteWithAnalytics = (inputMethod, editorAnalyticsApi) =
294
370
  })(insertBlockQuote());
295
371
  };
296
372
  export function insertBlockQuoteWithAnalyticsCommand(inputMethod, editorAnalyticsApi) {
297
- return withCurrentHeadingLevel(previousHeadingLevel => ({
373
+ return withCurrentHeadingLevel(() => ({
298
374
  tr
299
375
  }) => {
300
376
  const {
@@ -1,6 +1,7 @@
1
1
  ._11c810sd{font:var(--ds-font-heading-large,normal 653 24px/28px "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
2
2
  ._11c812ln{font:var(--ds-font-heading-xlarge,normal 653 28px/2pc "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
3
3
  ._11c812rg{font:var(--_1h4o6ch)}
4
+ ._11c8130a{font:var(--_1b6nbh6)}
4
5
  ._11c81af2{font:var(--ds-font-heading-medium,normal 653 20px/24px "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
5
6
  ._11c81e3o{font:var(--ds-font-heading-small,normal 653 1pc/20px "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
6
7
  ._11c81fq3{font:var(--_1d0ko3v)}
@@ -12,6 +12,7 @@ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared
12
12
  import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
13
13
  import { Box } from '@atlaskit/primitives/compiled';
14
14
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
15
+ const smallTextStyle = null;
15
16
  const normalStyle = null;
16
17
  const heading1Style = null;
17
18
  const heading2Style = null;
@@ -66,6 +67,13 @@ const HeadingText = ({
66
67
  "--_1c98jvx": ix(editorUGCToken('editor.font.heading.h6'))
67
68
  }
68
69
  }, children);
70
+ case 'smallText':
71
+ return /*#__PURE__*/React.createElement("div", {
72
+ className: ax(["_11c8130a"]),
73
+ style: {
74
+ "--_1b6nbh6": ix(editorUGCToken('editor.font.body.small'))
75
+ }
76
+ }, children);
69
77
  case 'normal':
70
78
  default:
71
79
  return /*#__PURE__*/React.createElement("div", {
@@ -2,10 +2,12 @@ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol
2
2
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
3
3
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
4
4
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
5
+ import { toggleBlockMarkNext } from '@atlaskit/editor-common/commands';
5
6
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
6
7
  import { filterChildrenBetween, wrapSelectionIn } from '@atlaskit/editor-common/utils';
7
8
  import { liftTarget } from '@atlaskit/editor-prosemirror/transform';
8
9
  import { CellSelection } from '@atlaskit/editor-tables';
10
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
11
  import { HEADINGS_BY_NAME, NORMAL_TEXT } from '../block-types';
10
12
  import { FORMATTING_NODE_TYPES, FORMATTING_MARK_TYPES, cellSelectionNodesBetween, formatTypes, clearNodeFormattingOnSelection } from './clear-formatting';
11
13
  import { wrapSelectionInBlockType } from './wrapSelectionIn';
@@ -18,6 +20,11 @@ export function setBlockType(name) {
18
20
  tr: tr
19
21
  });
20
22
  }
23
+ if (name === 'smallText' && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
24
+ return setSmallText()({
25
+ tr: tr
26
+ });
27
+ }
21
28
  var headingBlockType = HEADINGS_BY_NAME[name];
22
29
  if (headingBlockType && nodes.heading && headingBlockType.level) {
23
30
  return setHeading(headingBlockType.level)({
@@ -61,6 +68,12 @@ export function setHeading(level, fromBlockQuote) {
61
68
  });
62
69
  }
63
70
  });
71
+ var fontSize = schema.marks.fontSize;
72
+ if (fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
73
+ toggleBlockMarkNext(fontSize, function () {
74
+ return false;
75
+ }, [schema.nodes.heading])(tr);
76
+ }
64
77
  return tr;
65
78
  };
66
79
  }
@@ -73,6 +86,11 @@ export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi,
73
86
  tr: tr
74
87
  });
75
88
  }
89
+ if (name === 'smallText' && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
90
+ return setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi)({
91
+ tr: tr
92
+ });
93
+ }
76
94
  var headingBlockType = HEADINGS_BY_NAME[name];
77
95
  if (headingBlockType && nodes.heading && headingBlockType.level) {
78
96
  return setHeadingWithAnalytics(headingBlockType.level, inputMethod, editorAnalyticsApi, fromBlockQuote)({
@@ -82,15 +100,59 @@ export function setBlockTypeWithAnalytics(name, inputMethod, editorAnalyticsApi,
82
100
  return null;
83
101
  };
84
102
  }
85
- export function setNormalText(fromBlockQuote) {
103
+ export function setSmallText() {
86
104
  return function (_ref5) {
87
105
  var tr = _ref5.tr;
88
- var selection = tr.selection,
89
- schema = tr.doc.type.schema;
106
+ var _tr$doc$type$schema = tr.doc.type.schema,
107
+ fontSize = _tr$doc$type$schema.marks.fontSize,
108
+ paragraph = _tr$doc$type$schema.nodes.paragraph;
109
+ if (!fontSize) {
110
+ return null;
111
+ }
112
+ var selection = tr.selection;
90
113
  var ranges = selection instanceof CellSelection ? selection.ranges : [selection];
91
114
  ranges.forEach(function (_ref6) {
92
115
  var $from = _ref6.$from,
93
116
  $to = _ref6.$to;
117
+ tr.setBlockType($from.pos, $to.pos, paragraph);
118
+ });
119
+ toggleBlockMarkNext(fontSize, function () {
120
+ return {
121
+ fontSize: 'small'
122
+ };
123
+ }, [paragraph])(tr);
124
+ return tr;
125
+ };
126
+ }
127
+ export function setSmallTextWithAnalytics(inputMethod, editorAnalyticsApi) {
128
+ return withCurrentHeadingLevel(function (previousHeadingLevel) {
129
+ return function (_ref7) {
130
+ var tr = _ref7.tr;
131
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
132
+ action: ACTION.FORMATTED,
133
+ actionSubject: ACTION_SUBJECT.TEXT,
134
+ eventType: EVENT_TYPE.TRACK,
135
+ actionSubjectId: ACTION_SUBJECT_ID.FORMAT_SMALL_TEXT,
136
+ attributes: {
137
+ inputMethod: inputMethod,
138
+ previousBlockType: previousHeadingLevel !== undefined ? String(previousHeadingLevel) : undefined
139
+ }
140
+ })(tr);
141
+ return setSmallText()({
142
+ tr: tr
143
+ });
144
+ };
145
+ });
146
+ }
147
+ export function setNormalText(fromBlockQuote) {
148
+ return function (_ref8) {
149
+ var tr = _ref8.tr;
150
+ var selection = tr.selection,
151
+ schema = tr.doc.type.schema;
152
+ var ranges = selection instanceof CellSelection ? selection.ranges : [selection];
153
+ ranges.forEach(function (_ref9) {
154
+ var $from = _ref9.$from,
155
+ $to = _ref9.$to;
94
156
  if (fromBlockQuote) {
95
157
  var range = $from.blockRange($to);
96
158
  if (!range) {
@@ -109,12 +171,20 @@ export function setNormalText(fromBlockQuote) {
109
171
  tr.setBlockType($from.pos, $to.pos, schema.nodes.paragraph);
110
172
  }
111
173
  });
174
+
175
+ // Remove fontSize mark if present in schema
176
+ var fontSize = schema.marks.fontSize;
177
+ if (fontSize && expValEquals('platform_editor_small_font_size', 'isEnabled', true)) {
178
+ toggleBlockMarkNext(fontSize, function () {
179
+ return false;
180
+ }, [schema.nodes.paragraph])(tr);
181
+ }
112
182
  return tr;
113
183
  };
114
184
  }
115
185
  export function clearFormatting(inputMethod, editorAnalyticsApi) {
116
- return function (_ref7) {
117
- var tr = _ref7.tr;
186
+ return function (_ref0) {
187
+ var tr = _ref0.tr;
118
188
  var formattingCleared = [];
119
189
  var schema = tr.doc.type.schema;
120
190
  FORMATTING_MARK_TYPES.forEach(function (mark) {
@@ -171,8 +241,8 @@ export function clearFormatting(inputMethod, editorAnalyticsApi) {
171
241
  };
172
242
  }
173
243
  function withCurrentHeadingLevel(fn) {
174
- return function (_ref8) {
175
- var tr = _ref8.tr;
244
+ return function (_ref1) {
245
+ var tr = _ref1.tr;
176
246
  // Find all headings and paragraphs of text
177
247
  var _tr$doc$type$schema$n = tr.doc.type.schema.nodes,
178
248
  heading = _tr$doc$type$schema$n.heading,
@@ -209,8 +279,8 @@ function withCurrentHeadingLevel(fn) {
209
279
  }
210
280
  export function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, fromBlockQuote) {
211
281
  return withCurrentHeadingLevel(function (previousHeadingLevel) {
212
- return function (_ref9) {
213
- var tr = _ref9.tr;
282
+ return function (_ref10) {
283
+ var tr = _ref10.tr;
214
284
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
215
285
  action: ACTION.FORMATTED,
216
286
  actionSubject: ACTION_SUBJECT.TEXT,
@@ -230,8 +300,8 @@ export function setNormalTextWithAnalytics(inputMethod, editorAnalyticsApi, from
230
300
  }
231
301
  export var setHeadingWithAnalytics = function setHeadingWithAnalytics(newHeadingLevel, inputMethod, editorAnalyticsApi, fromBlockQuote) {
232
302
  return withCurrentHeadingLevel(function (previousHeadingLevel) {
233
- return function (_ref0) {
234
- var tr = _ref0.tr;
303
+ return function (_ref11) {
304
+ var tr = _ref11.tr;
235
305
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
236
306
  action: ACTION.FORMATTED,
237
307
  actionSubject: ACTION_SUBJECT.TEXT,
@@ -279,9 +349,9 @@ export var insertBlockQuoteWithAnalytics = function insertBlockQuoteWithAnalytic
279
349
  })(insertBlockQuote());
280
350
  };
281
351
  export function insertBlockQuoteWithAnalyticsCommand(inputMethod, editorAnalyticsApi) {
282
- return withCurrentHeadingLevel(function (previousHeadingLevel) {
283
- return function (_ref1) {
284
- var tr = _ref1.tr;
352
+ return withCurrentHeadingLevel(function () {
353
+ return function (_ref12) {
354
+ var tr = _ref12.tr;
285
355
  var nodes = tr.doc.type.schema.nodes;
286
356
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
287
357
  action: ACTION.FORMATTED,
@@ -299,8 +369,8 @@ export function insertBlockQuoteWithAnalyticsCommand(inputMethod, editorAnalytic
299
369
  });
300
370
  }
301
371
  export var cleanUpAtTheStartOfDocument = function cleanUpAtTheStartOfDocument(state, dispatch) {
302
- var _ref10 = state.selection,
303
- $cursor = _ref10.$cursor;
372
+ var _ref13 = state.selection,
373
+ $cursor = _ref13.$cursor;
304
374
  if ($cursor && !$cursor.nodeBefore && !$cursor.nodeAfter && $cursor.pos === 1) {
305
375
  var tr = state.tr,
306
376
  schema = state.schema;
@@ -1,6 +1,7 @@
1
1
  ._11c810sd{font:var(--ds-font-heading-large,normal 653 24px/28px "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
2
2
  ._11c812ln{font:var(--ds-font-heading-xlarge,normal 653 28px/2pc "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
3
3
  ._11c812rg{font:var(--_1h4o6ch)}
4
+ ._11c8130a{font:var(--_1b6nbh6)}
4
5
  ._11c81af2{font:var(--ds-font-heading-medium,normal 653 20px/24px "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
5
6
  ._11c81e3o{font:var(--ds-font-heading-small,normal 653 1pc/20px "Atlassian Sans",ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Ubuntu,"Helvetica Neue",sans-serif)}
6
7
  ._11c81fq3{font:var(--_1d0ko3v)}
@@ -12,6 +12,7 @@ import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared
12
12
  import { ToolbarDropdownItem, ToolbarKeyboardShortcutHint } from '@atlaskit/editor-toolbar';
13
13
  import { Box } from '@atlaskit/primitives/compiled';
14
14
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
15
+ var smallTextStyle = null;
15
16
  var normalStyle = null;
16
17
  var heading1Style = null;
17
18
  var heading2Style = null;
@@ -65,6 +66,13 @@ var HeadingText = function HeadingText(_ref) {
65
66
  "--_1c98jvx": ix(editorUGCToken('editor.font.heading.h6'))
66
67
  }
67
68
  }, children);
69
+ case 'smallText':
70
+ return /*#__PURE__*/React.createElement("div", {
71
+ className: ax(["_11c8130a"]),
72
+ style: {
73
+ "--_1b6nbh6": ix(editorUGCToken('editor.font.body.small'))
74
+ }
75
+ }, children);
68
76
  case 'normal':
69
77
  default:
70
78
  return /*#__PURE__*/React.createElement("div", {
@@ -6,6 +6,8 @@ export type ClearFormattingInputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.SHO
6
6
  export declare function setBlockType(name: TextBlockTypes): EditorCommand;
7
7
  export declare function setHeading(level: HeadingLevelsAndNormalText, fromBlockQuote?: boolean): EditorCommand;
8
8
  export declare function setBlockTypeWithAnalytics(name: TextBlockTypes, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
9
+ export declare function setSmallText(): EditorCommand;
10
+ export declare function setSmallTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
9
11
  export declare function setNormalText(fromBlockQuote?: boolean): EditorCommand;
10
12
  export declare function clearFormatting(inputMethod: ClearFormattingInputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
11
13
  export declare function setNormalTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
@@ -6,6 +6,8 @@ export type ClearFormattingInputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.SHO
6
6
  export declare function setBlockType(name: TextBlockTypes): EditorCommand;
7
7
  export declare function setHeading(level: HeadingLevelsAndNormalText, fromBlockQuote?: boolean): EditorCommand;
8
8
  export declare function setBlockTypeWithAnalytics(name: TextBlockTypes, inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
9
+ export declare function setSmallText(): EditorCommand;
10
+ export declare function setSmallTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
9
11
  export declare function setNormalText(fromBlockQuote?: boolean): EditorCommand;
10
12
  export declare function clearFormatting(inputMethod: ClearFormattingInputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
11
13
  export declare function setNormalTextWithAnalytics(inputMethod: InputMethod, editorAnalyticsApi: EditorAnalyticsAPI | undefined, fromBlockQuote?: boolean): EditorCommand;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-type",
3
- "version": "12.1.1",
3
+ "version": "12.1.2",
4
4
  "description": "BlockType plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "atlaskit:src": "src/index.ts",
31
31
  "dependencies": {
32
- "@atlaskit/adf-schema": "^52.3.0",
32
+ "@atlaskit/adf-schema": "^52.4.0",
33
33
  "@atlaskit/css": "^0.19.0",
34
34
  "@atlaskit/editor-plugin-analytics": "^8.0.0",
35
35
  "@atlaskit/editor-plugin-block-menu": "^7.0.0",
@@ -50,14 +50,14 @@
50
50
  "@atlaskit/prosemirror-history": "^0.2.0",
51
51
  "@atlaskit/prosemirror-input-rules": "^3.6.0",
52
52
  "@atlaskit/theme": "^22.0.0",
53
- "@atlaskit/tmp-editor-statsig": "^40.2.0",
53
+ "@atlaskit/tmp-editor-statsig": "^40.3.0",
54
54
  "@atlaskit/tokens": "^11.1.0",
55
55
  "@babel/runtime": "^7.0.0",
56
56
  "@compiled/react": "^0.20.0",
57
57
  "@emotion/react": "^11.7.1"
58
58
  },
59
59
  "peerDependencies": {
60
- "@atlaskit/editor-common": "^112.4.0",
60
+ "@atlaskit/editor-common": "^112.5.0",
61
61
  "react": "^18.2.0",
62
62
  "react-dom": "^18.2.0",
63
63
  "react-intl-next": "npm:react-intl@^5.18.1"