@squiz/formatted-text-editor 1.65.0 → 1.66.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,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.66.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a5b0869: Update fte toolbar to max height 100% so that it can be flexible at any width and position placeholder
8
+
9
+ ## 1.65.1
10
+
11
+ ### Patch Changes
12
+
13
+ - 402e8b1: Fixed issue where some Remirror text alignment options (eg. start and end) were not correctly transformed to Squiz formatted text structure.
14
+
3
15
  ## 1.65.0
4
16
 
5
17
  ### Minor Changes
package/lib/index.css CHANGED
@@ -822,6 +822,7 @@
822
822
  outline-width: 0px;
823
823
  }
824
824
  .squiz-fte-scope.squiz-fte-scope__editor .remirror-editor p {
825
+ position: relative;
825
826
  display: block;
826
827
  }
827
828
  .squiz-fte-scope.squiz-fte-scope__editor--bordered {
@@ -909,7 +910,7 @@
909
910
  }
910
911
  .squiz-fte-scope .header-toolbar.show-toolbar {
911
912
  opacity: 1;
912
- max-height: 15vh;
913
+ max-height: 108px;
913
914
  }
914
915
  .squiz-fte-scope__floating-popover {
915
916
  display: flex;
@@ -29,8 +29,18 @@ const resolveNodeTag = (node) => {
29
29
  exports.resolveNodeTag = resolveNodeTag;
30
30
  const resolveFormattingOptions = (node) => {
31
31
  const formattingOptions = {};
32
- if (node.attrs.nodeTextAlignment) {
33
- formattingOptions.alignment = node.attrs.nodeTextAlignment;
32
+ const textAlignment = node.attrs.nodeTextAlignment;
33
+ const textAlignmentMap = {
34
+ none: undefined,
35
+ left: 'left',
36
+ right: 'right',
37
+ center: 'center',
38
+ start: 'left',
39
+ end: 'right',
40
+ justify: 'justify',
41
+ };
42
+ if (textAlignment && textAlignmentMap[textAlignment]) {
43
+ formattingOptions.alignment = textAlignmentMap[textAlignment];
34
44
  }
35
45
  return formattingOptions;
36
46
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/formatted-text-editor",
3
- "version": "1.65.0",
3
+ "version": "1.66.0",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "private": false,
@@ -23,6 +23,7 @@
23
23
  }
24
24
 
25
25
  p {
26
+ position: relative; // ensures that the placeholder text is positioned correctly
26
27
  /* Make sure content aligned with "text-align: justify" is justified */
27
28
  @apply block;
28
29
  }
@@ -32,6 +32,6 @@
32
32
 
33
33
  &.show-toolbar {
34
34
  opacity: 1;
35
- max-height: 15vh;
35
+ max-height: 108px; // this should mean at least 3 icons can git vertically if needed
36
36
  }
37
37
  }
@@ -6,6 +6,7 @@ import { sharedNodeExamples } from '../mocks/squizNodeJson.mock';
6
6
  import { ParagraphExtension, SupExtension } from 'remirror/extensions';
7
7
 
8
8
  type FormattedText = FormattedTextModels.v1.FormattedText;
9
+ type FormattingOptions = FormattedTextModels.v1.FormattingOptions;
9
10
 
10
11
  describe('remirrorNodeToSquizNode', () => {
11
12
  it('should convert a simple Remirror node to a Squiz component JSON object', async () => {
@@ -397,50 +398,60 @@ describe('remirrorNodeToSquizNode', () => {
397
398
  expect(result).toEqual(expected);
398
399
  });
399
400
 
400
- describe('preserve text formatting', () => {
401
- it('should preserve text alignment', async () => {
402
- const content: RemirrorJSON = {
403
- type: 'doc',
404
- content: [
405
- {
406
- type: 'paragraph',
407
- attrs: {
408
- nodeIndent: null,
409
- nodeTextAlignment: 'center',
410
- nodeLineHeight: null,
411
- style: '',
401
+ describe('preserve text formatting - %s', () => {
402
+ it.each([
403
+ ['left', { alignment: 'left' } as FormattingOptions],
404
+ ['right', { alignment: 'right' } as FormattingOptions],
405
+ ['center', { alignment: 'center' } as FormattingOptions],
406
+ ['justify', { alignment: 'justify' } as FormattingOptions],
407
+ ['start', { alignment: 'left' } as FormattingOptions],
408
+ ['end', { alignment: 'right' } as FormattingOptions],
409
+ ['none', undefined],
410
+ [undefined, undefined],
411
+ ])(
412
+ 'should preserve text alignment',
413
+ async (remirrorTextAlignment: string | undefined, expectedFormattingOptions: FormattingOptions | undefined) => {
414
+ const content: RemirrorJSON = {
415
+ type: 'doc',
416
+ content: [
417
+ {
418
+ type: 'paragraph',
419
+ attrs: {
420
+ nodeIndent: null,
421
+ nodeTextAlignment: remirrorTextAlignment,
422
+ nodeLineHeight: null,
423
+ style: '',
424
+ },
425
+ content: [
426
+ {
427
+ type: 'text',
428
+ text: 'Hello world!',
429
+ },
430
+ ],
412
431
  },
413
- content: [
432
+ ],
433
+ };
434
+
435
+ const { editor } = await renderWithEditor(null, { content });
436
+
437
+ const expected: FormattedText = [
438
+ {
439
+ children: [
414
440
  {
415
441
  type: 'text',
416
- text: 'Hello world!',
442
+ value: 'Hello world!',
417
443
  },
418
444
  ],
445
+ formattingOptions: expectedFormattingOptions,
446
+ type: 'tag',
447
+ tag: 'p',
419
448
  },
420
- ],
421
- };
422
-
423
- const { editor } = await renderWithEditor(null, { content });
424
-
425
- const expected: FormattedText = [
426
- {
427
- children: [
428
- {
429
- type: 'text',
430
- value: 'Hello world!',
431
- },
432
- ],
433
- formattingOptions: {
434
- alignment: 'center',
435
- },
436
- type: 'tag',
437
- tag: 'p',
438
- },
439
- ];
449
+ ];
440
450
 
441
- const result = remirrorNodeToSquizNode(editor.doc);
442
- expect(result).toEqual(expected);
443
- });
451
+ const result = remirrorNodeToSquizNode(editor.doc);
452
+ expect(result).toEqual(expected);
453
+ },
454
+ );
444
455
  });
445
456
 
446
457
  it('should handle invalid Remirror node provided', () => {
@@ -14,6 +14,8 @@ type FormattedText = FormattedTextModels.v1.FormattedText;
14
14
  type FormattedNode = FormattedTextModels.v1.FormattedNodes;
15
15
  type FormattedNodeFontProperties = FormattedTextModels.v1.FormattedNodeFontProperties;
16
16
  type FormattedNodeWithChildren = Extract<FormattedNode, { children: FormattedNode[] }>;
17
+ type RemirrorTextAlignment = Exclude<Remirror.Attributes['nodeTextAlignment'], undefined>;
18
+ type FormattedTextAlignment = FormattingOptions['alignment'];
17
19
 
18
20
  export const resolveNodeTag = (node: ProsemirrorNode): string => {
19
21
  if (node.type.name === NodeName.Text) {
@@ -46,9 +48,19 @@ export const resolveNodeTag = (node: ProsemirrorNode): string => {
46
48
 
47
49
  const resolveFormattingOptions = (node: ProsemirrorNode): FormattingOptions => {
48
50
  const formattingOptions: FormattingOptions = {};
51
+ const textAlignment = node.attrs.nodeTextAlignment as RemirrorTextAlignment | undefined;
52
+ const textAlignmentMap: Record<RemirrorTextAlignment, FormattedTextAlignment> = {
53
+ none: undefined,
54
+ left: 'left',
55
+ right: 'right',
56
+ center: 'center',
57
+ start: 'left',
58
+ end: 'right',
59
+ justify: 'justify',
60
+ };
49
61
 
50
- if (node.attrs.nodeTextAlignment) {
51
- formattingOptions.alignment = node.attrs.nodeTextAlignment;
62
+ if (textAlignment && textAlignmentMap[textAlignment]) {
63
+ formattingOptions.alignment = textAlignmentMap[textAlignment];
52
64
  }
53
65
 
54
66
  return formattingOptions;