@crystallize/design-system 1.11.7 → 1.12.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,15 @@
1
1
  # @crystallize/design-system
2
2
 
3
+ ## 1.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a47bba7: The rich text editor is now able to deal with more invalid initial states.
8
+
9
+ ### Patch Changes
10
+
11
+ - a47bba7: Updated to Storybook 7.0.7
12
+
3
13
  ## 1.11.7
4
14
 
5
15
  ### Patch Changes
package/dist/index.js CHANGED
@@ -4390,10 +4390,27 @@ var import_list = require("@lexical/list");
4390
4390
  var import_LexicalHorizontalRuleNode = require("@lexical/react/LexicalHorizontalRuleNode");
4391
4391
  var import_rich_text = require("@lexical/rich-text");
4392
4392
  var import_table = require("@lexical/table");
4393
+
4394
+ // src/rich-text-editor/model/parse-initial-state.ts
4395
+ function parseInitialState({ richText }) {
4396
+ let richTextArray = Array.isArray(richText) ? richText : [richText];
4397
+ richTextArray = richTextArray.map((rootNode) => {
4398
+ if (!rootNode.kind || rootNode.kind === "inline") {
4399
+ return {
4400
+ type: "paragraph",
4401
+ kind: "block",
4402
+ children: [rootNode]
4403
+ };
4404
+ }
4405
+ return rootNode;
4406
+ });
4407
+ return richTextArray;
4408
+ }
4409
+
4410
+ // src/rich-text-editor/model/crystallize-to-lexical.ts
4393
4411
  function composeInitialState({ richText }) {
4394
4412
  return function setLexicalState() {
4395
4413
  const root = (0, import_lexical.$getRoot)();
4396
- const richTextArray = Array.isArray(richText) ? richText : [richText];
4397
4414
  function handleNode({
4398
4415
  crystallizeContentNode,
4399
4416
  lexicalParent
@@ -4535,7 +4552,9 @@ function composeInitialState({ richText }) {
4535
4552
  lexicalParent.append(lexicalNode);
4536
4553
  }
4537
4554
  }
4538
- richTextArray.forEach((crystallizeContentNode) => handleNode({ crystallizeContentNode, lexicalParent: root }));
4555
+ parseInitialState({ richText }).forEach(
4556
+ (crystallizeContentNode) => handleNode({ crystallizeContentNode, lexicalParent: root })
4557
+ );
4539
4558
  };
4540
4559
  }
4541
4560
  function getLexicalTextFormat(node) {
package/dist/index.mjs CHANGED
@@ -4336,10 +4336,27 @@ import { $createListItemNode, $createListNode } from "@lexical/list";
4336
4336
  import { $createHorizontalRuleNode } from "@lexical/react/LexicalHorizontalRuleNode";
4337
4337
  import { $createHeadingNode, $createQuoteNode } from "@lexical/rich-text";
4338
4338
  import { $createTableCellNode, $createTableNode, $createTableRowNode } from "@lexical/table";
4339
+
4340
+ // src/rich-text-editor/model/parse-initial-state.ts
4341
+ function parseInitialState({ richText }) {
4342
+ let richTextArray = Array.isArray(richText) ? richText : [richText];
4343
+ richTextArray = richTextArray.map((rootNode) => {
4344
+ if (!rootNode.kind || rootNode.kind === "inline") {
4345
+ return {
4346
+ type: "paragraph",
4347
+ kind: "block",
4348
+ children: [rootNode]
4349
+ };
4350
+ }
4351
+ return rootNode;
4352
+ });
4353
+ return richTextArray;
4354
+ }
4355
+
4356
+ // src/rich-text-editor/model/crystallize-to-lexical.ts
4339
4357
  function composeInitialState({ richText }) {
4340
4358
  return function setLexicalState() {
4341
4359
  const root = $getRoot();
4342
- const richTextArray = Array.isArray(richText) ? richText : [richText];
4343
4360
  function handleNode({
4344
4361
  crystallizeContentNode,
4345
4362
  lexicalParent
@@ -4481,7 +4498,9 @@ function composeInitialState({ richText }) {
4481
4498
  lexicalParent.append(lexicalNode);
4482
4499
  }
4483
4500
  }
4484
- richTextArray.forEach((crystallizeContentNode) => handleNode({ crystallizeContentNode, lexicalParent: root }));
4501
+ parseInitialState({ richText }).forEach(
4502
+ (crystallizeContentNode) => handleNode({ crystallizeContentNode, lexicalParent: root })
4503
+ );
4485
4504
  };
4486
4505
  }
4487
4506
  function getLexicalTextFormat(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crystallize/design-system",
3
- "version": "1.11.7",
3
+ "version": "1.12.0",
4
4
  "types": "./dist/index.d.ts",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -58,20 +58,20 @@
58
58
  "@faker-js/faker": "7.6.0",
59
59
  "@ianvs/prettier-plugin-sort-imports": "^3.7.1",
60
60
  "@mdx-js/react": "^2.2.1",
61
- "@storybook/addon-actions": "7.0.0-beta.14",
62
- "@storybook/addon-backgrounds": "7.0.0-beta.14",
63
- "@storybook/addon-docs": "7.0.0-beta.14",
64
- "@storybook/addon-essentials": "7.0.0-beta.14",
65
- "@storybook/addon-highlight": "7.0.0-beta.14",
66
- "@storybook/addon-interactions": "7.0.0-beta.14",
67
- "@storybook/addon-links": "7.0.0-beta.14",
68
- "@storybook/addon-measure": "7.0.0-beta.14",
69
- "@storybook/addon-outline": "7.0.0-beta.14",
61
+ "@storybook/addon-actions": "7.0.7",
62
+ "@storybook/addon-backgrounds": "7.0.7",
63
+ "@storybook/addon-docs": "7.0.7",
64
+ "@storybook/addon-essentials": "7.0.7",
65
+ "@storybook/addon-highlight": "7.0.7",
66
+ "@storybook/addon-interactions": "7.0.7",
67
+ "@storybook/addon-links": "7.0.7",
68
+ "@storybook/addon-measure": "7.0.7",
69
+ "@storybook/addon-outline": "7.0.7",
70
70
  "@storybook/addons": "^6.5.15",
71
- "@storybook/react": "7.0.0-beta.14",
72
- "@storybook/react-vite": "7.0.0-beta.14",
71
+ "@storybook/react": "7.0.7",
72
+ "@storybook/react-vite": "7.0.7",
73
73
  "@storybook/testing-library": "^0.0.13",
74
- "@storybook/theming": "7.0.0-beta.14",
74
+ "@storybook/theming": "7.0.7",
75
75
  "@testing-library/jest-dom": "^5.16.4",
76
76
  "@testing-library/react": "^12.0.0",
77
77
  "@testing-library/user-event": "^14.4.3",
@@ -83,14 +83,14 @@
83
83
  "concurrently": "^7.6.0",
84
84
  "hex-rgb": "4.3.0",
85
85
  "postcss": "^8.4.21",
86
- "storybook": "7.0.0-beta.14",
86
+ "storybook": "7.0.7",
87
87
  "storybook-addon-designs": "^6.3.1",
88
88
  "storybook-dark-mode": "^2.0.5",
89
89
  "tailwindcss": "^3.3.0",
90
90
  "tsup": "^6.5.0",
91
91
  "typescript": "^4.9.4",
92
- "vite": "^4.2.1",
93
- "vitest": "^0.30.1",
92
+ "vite": "4.3.4",
93
+ "vitest": "0.30.1",
94
94
  "tsconfig": "0.0.0"
95
95
  },
96
96
  "keywords": [
@@ -116,7 +116,7 @@
116
116
  "build:storybook": "storybook build -s public",
117
117
  "build:tw": "tailwindcss --content ./src/**/*.tsx,!./src/**/*.stories.tsx -c ./tailwind.config.cjs -i src/index.css -o dist/index.css --minify",
118
118
  "build:tsup": "tsup src/index.ts --format esm,cjs --dts",
119
- "build": "pnpm build:tw && pnpm build:tsup && pnpm build:storybook",
119
+ "build": "pnpm build:tw && pnpm build:tsup",
120
120
  "dev:tw": "tailwindcss --content ./src/**/*.tsx,!./src/**/*.stories.tsx -c ./tailwind.config.cjs -i src/index.css -o dist/index.css --watch & tsup src/index.ts --format esm --dts --watch",
121
121
  "dev:tsup": "tsup src/index.ts --format esm --dts --watch",
122
122
  "dev:storybook": "storybook dev -p 6006 --no-open -s public",
@@ -15,13 +15,12 @@ import { $createHeadingNode, $createQuoteNode } from '@lexical/rich-text';
15
15
  import { $createTableCellNode, $createTableNode, $createTableRowNode } from '@lexical/table';
16
16
 
17
17
  import type { CrystallizeRichTextNode, CrystallizeRichText } from '../types/crystallize-rich-text-types';
18
+ import { parseInitialState } from './parse-initial-state';
18
19
 
19
20
  export function composeInitialState({ richText }: { richText: CrystallizeRichText }) {
20
21
  return function setLexicalState() {
21
22
  const root = $getRoot();
22
23
 
23
- const richTextArray = Array.isArray(richText) ? richText : [richText];
24
-
25
24
  function handleNode({
26
25
  crystallizeContentNode,
27
26
  lexicalParent,
@@ -196,7 +195,9 @@ export function composeInitialState({ richText }: { richText: CrystallizeRichTex
196
195
  }
197
196
  }
198
197
 
199
- richTextArray.forEach(crystallizeContentNode => handleNode({ crystallizeContentNode, lexicalParent: root }));
198
+ parseInitialState({ richText }).forEach(crystallizeContentNode =>
199
+ handleNode({ crystallizeContentNode, lexicalParent: root }),
200
+ );
200
201
  };
201
202
  }
202
203
 
@@ -0,0 +1,48 @@
1
+ /* eslint-disable no-console */
2
+
3
+ import type { CrystallizeRichText } from '../rich-text-editor';
4
+ import { parseInitialState } from './parse-initial-state';
5
+
6
+ describe('RichTextEditor parseInitialState', () => {
7
+ it('ensures that the initial state is an array', async () => {
8
+ expect(
9
+ parseInitialState({
10
+ richText: {
11
+ kind: 'block',
12
+ type: 'paragraph',
13
+ textContent: 'hello',
14
+ },
15
+ }),
16
+ ).toEqual([
17
+ {
18
+ kind: 'block',
19
+ type: 'paragraph',
20
+ textContent: 'hello',
21
+ },
22
+ ]);
23
+ });
24
+
25
+ it('ensures that all root nodes are block elements', async () => {
26
+ expect(
27
+ parseInitialState({
28
+ richText: [
29
+ {
30
+ kind: 'inline',
31
+ textContent: 'hello',
32
+ },
33
+ ],
34
+ }),
35
+ ).toEqual([
36
+ {
37
+ kind: 'block',
38
+ type: 'paragraph',
39
+ children: [
40
+ {
41
+ kind: 'inline',
42
+ textContent: 'hello',
43
+ },
44
+ ],
45
+ } as CrystallizeRichText,
46
+ ]);
47
+ });
48
+ });
@@ -0,0 +1,20 @@
1
+ import type { CrystallizeRichText, CrystallizeRichTextNode } from '../types/crystallize-rich-text-types';
2
+
3
+ export function parseInitialState({ richText }: { richText: CrystallizeRichText }): CrystallizeRichTextNode[] {
4
+ let richTextArray = Array.isArray(richText) ? richText : [richText];
5
+
6
+ // Ensure all root items are block elements
7
+ richTextArray = richTextArray.map(rootNode => {
8
+ if (!rootNode.kind || rootNode.kind === 'inline') {
9
+ return {
10
+ type: 'paragraph',
11
+ kind: 'block',
12
+ children: [rootNode],
13
+ };
14
+ }
15
+
16
+ return rootNode;
17
+ });
18
+
19
+ return richTextArray;
20
+ }
@@ -459,3 +459,16 @@ export const CustomTranslation: Story = {
459
459
  },
460
460
  },
461
461
  };
462
+
463
+ export const Bug: Story = {
464
+ args: {
465
+ initialData: [
466
+ {
467
+ kind: 'inline',
468
+ type: null,
469
+ textContent:
470
+ 'Krigsårene frem mot 1814 inneholder noen av de mest dramatiske begivenhetene i både dansk og norsk historie. I denne boken finner du for første gang en samlet fremstilling av krigsårene mellom 1807 og 1814 fra et felles dansk-norsk perspektiv.Dette verket er et sentralt bidrag i markeringen av 200-årsjubileet for grunnloven og den dansk-norske skilsmissen, skrevet av en dansk og en norsk historiker. I boken forteller de om krigsbegivenhetene både til lands og til sjøs, hvordan de ble opplevd blant ulike samfunnslag fra elitene i København, Christiania og Kiel, til husmenn i Østerdalen, bønder på Lolland-Falster og småhandelsfolk i Slesvig-Holstein.1814 var det moderne Norges fødsel. Norge ble selvstendig med en av Europas mest liberale grunnlover, og både selvstendigheten og grunnloven fikk leve videre selv om Norge mot slutten av året ble forent med Sverige i en løs union. Politisk sett gjorde dette Norge til en av Napoleonskrigenes vinnere, men ""mirakelåret"" 1814 ble født av et nederlag.',
471
+ },
472
+ ],
473
+ },
474
+ };