@crystallize/design-system 1.5.0 → 1.7.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/index.css +85 -142
  3. package/dist/index.d.ts +7 -3
  4. package/dist/index.js +1526 -4411
  5. package/dist/index.mjs +1391 -4294
  6. package/package.json +19 -19
  7. package/src/iconography/document.tsx +19 -0
  8. package/src/iconography/folder.tsx +30 -0
  9. package/src/iconography/index.ts +8 -2
  10. package/src/iconography/product.tsx +42 -0
  11. package/src/rich-text-editor/model/crystallize-to-lexical.ts +1 -1
  12. package/src/rich-text-editor/model/lexical-to-crystallize.ts +2 -2
  13. package/src/rich-text-editor/model/to-text.test.ts +97 -0
  14. package/src/rich-text-editor/model/to-text.ts +47 -0
  15. package/src/rich-text-editor/nodes/BaseNodes.ts +0 -3
  16. package/src/rich-text-editor/plugins/ActionsPlugin/index.tsx +14 -3
  17. package/src/rich-text-editor/plugins/CodeActionMenuPlugin/index.tsx +1 -1
  18. package/src/rich-text-editor/plugins/ComponentPickerPlugin/index.tsx +5 -5
  19. package/src/rich-text-editor/plugins/DraggableBlockPlugin/index.tsx +29 -50
  20. package/src/rich-text-editor/plugins/MaxLengthPlugin/index.tsx +34 -23
  21. package/src/rich-text-editor/plugins/ToolbarPlugin/index.tsx +8 -8
  22. package/src/rich-text-editor/rich-text-editor.css +3 -3
  23. package/src/rich-text-editor/rich-text-editor.stories.tsx +9 -1
  24. package/src/rich-text-editor/rich-text-editor.tsx +30 -24
  25. package/src/rich-text-editor/tests/rich-text-editor-basic-rendering.test.tsx +1 -1
  26. package/src/rich-text-editor/tests/rich-text-editor-model-basics.test.tsx +1 -1
  27. package/src/rich-text-editor/tests/rich-text-editor-model-conversions.test.tsx +1 -1
  28. package/src/rich-text-editor/tests/rich-text-editor-text-formats.test.tsx +1 -1
  29. package/src/rich-text-editor/themes/{PlaygroundEditorTheme.css → CrystallizeRTEditorTheme.css} +81 -85
  30. package/src/rich-text-editor/themes/CrystallizeRTEditorTheme.ts +113 -0
  31. package/dist/draggable-block-menu-KKHDNKJA.svg +0 -1
  32. package/src/rich-text-editor/appSettings.ts +0 -28
  33. package/src/rich-text-editor/context/SettingsContext.tsx +0 -71
  34. package/src/rich-text-editor/context/SharedAutocompleteContext.tsx +0 -60
  35. package/src/rich-text-editor/nodes/AutocompleteNode.tsx +0 -96
  36. package/src/rich-text-editor/plugins/AutocompletePlugin/index.tsx +0 -2536
  37. package/src/rich-text-editor/themes/PlaygroundEditorTheme.ts +0 -113
  38. /package/src/rich-text-editor/{model → types}/crystallize-rich-text-types/code.ts +0 -0
  39. /package/src/rich-text-editor/{model → types}/crystallize-rich-text-types/headings.ts +0 -0
  40. /package/src/rich-text-editor/{model → types}/crystallize-rich-text-types/index.ts +0 -0
  41. /package/src/rich-text-editor/{model → types}/crystallize-rich-text-types/link.ts +0 -0
  42. /package/src/rich-text-editor/{model → types}/crystallize-rich-text-types/table.ts +0 -0
  43. /package/src/rich-text-editor/{types.ts → types/types.ts} +0 -0
@@ -1,60 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- /**
3
- * Copyright (c) Meta Platforms, Inc. and affiliates.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- *
8
- */
9
-
10
- import { createContext, ReactNode, useContext, useEffect, useMemo, useState } from 'react';
11
-
12
- type Suggestion = null | string;
13
- type CallbackFn = (newSuggestion: Suggestion) => void;
14
- type SubscribeFn = (callbackFn: CallbackFn) => () => void;
15
- type PublishFn = (newSuggestion: Suggestion) => void;
16
- type ContextShape = [SubscribeFn, PublishFn];
17
- type HookShape = [suggestion: Suggestion, setSuggestion: PublishFn];
18
-
19
- const Context: React.Context<ContextShape> = createContext([
20
- _cb => () => {
21
- return;
22
- },
23
- (_newSuggestion: Suggestion) => {
24
- return;
25
- },
26
- ]);
27
-
28
- export const SharedAutocompleteContext = ({ children }: { children: ReactNode }): JSX.Element => {
29
- const context: ContextShape = useMemo(() => {
30
- let suggestion: Suggestion | null = null;
31
- const listeners: Set<CallbackFn> = new Set();
32
- return [
33
- (cb: (newSuggestion: Suggestion) => void) => {
34
- cb(suggestion);
35
- listeners.add(cb);
36
- return () => {
37
- listeners.delete(cb);
38
- };
39
- },
40
- (newSuggestion: Suggestion) => {
41
- suggestion = newSuggestion;
42
- for (const listener of listeners) {
43
- listener(newSuggestion);
44
- }
45
- },
46
- ];
47
- }, []);
48
- return <Context.Provider value={context}>{children}</Context.Provider>;
49
- };
50
-
51
- export const useSharedAutocompleteContext = (): HookShape => {
52
- const [subscribe, publish]: ContextShape = useContext(Context);
53
- const [suggestion, setSuggestion] = useState<Suggestion>(null);
54
- useEffect(() => {
55
- return subscribe((newSuggestion: Suggestion) => {
56
- setSuggestion(newSuggestion);
57
- });
58
- }, [subscribe]);
59
- return [suggestion, publish];
60
- };
@@ -1,96 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- */
8
-
9
- import type { Spread } from 'lexical';
10
-
11
- import { DecoratorNode, EditorConfig, NodeKey, SerializedLexicalNode } from 'lexical';
12
- import * as React from 'react';
13
-
14
- import { useSharedAutocompleteContext } from '../context/SharedAutocompleteContext';
15
- import { uuid as UUID } from '../plugins/AutocompletePlugin';
16
-
17
- declare global {
18
- interface Navigator {
19
- userAgentData?: {
20
- mobile: boolean;
21
- };
22
- }
23
- }
24
-
25
- export type SerializedAutocompleteNode = Spread<
26
- {
27
- type: 'autocomplete';
28
- version: 1;
29
- uuid: string;
30
- },
31
- SerializedLexicalNode
32
- >;
33
-
34
- export class AutocompleteNode extends DecoratorNode<JSX.Element | null> {
35
- // TODO add comment
36
- __uuid: string;
37
-
38
- static clone(node: AutocompleteNode): AutocompleteNode {
39
- return new AutocompleteNode(node.__key);
40
- }
41
-
42
- static getType(): 'autocomplete' {
43
- return 'autocomplete';
44
- }
45
-
46
- static importJSON(serializedNode: SerializedAutocompleteNode): AutocompleteNode {
47
- const node = $createAutocompleteNode(serializedNode.uuid);
48
- return node;
49
- }
50
-
51
- exportJSON(): SerializedAutocompleteNode {
52
- return {
53
- ...super.exportJSON(),
54
- type: 'autocomplete',
55
- uuid: this.__uuid,
56
- version: 1,
57
- };
58
- }
59
-
60
- constructor(uuid: string, key?: NodeKey) {
61
- super(key);
62
- this.__uuid = uuid;
63
- }
64
-
65
- updateDOM(prevNode: unknown, dom: HTMLElement, config: EditorConfig): boolean {
66
- return false;
67
- }
68
-
69
- createDOM(config: EditorConfig): HTMLElement {
70
- return document.createElement('span');
71
- }
72
-
73
- decorate(): JSX.Element | null {
74
- if (this.__uuid !== UUID) {
75
- return null;
76
- }
77
- return <AutocompleteComponent />;
78
- }
79
- }
80
-
81
- export function $createAutocompleteNode(uuid: string): AutocompleteNode {
82
- return new AutocompleteNode(uuid);
83
- }
84
-
85
- function AutocompleteComponent(): JSX.Element {
86
- const [suggestion] = useSharedAutocompleteContext();
87
- const userAgentData = window.navigator.userAgentData;
88
- const isMobile =
89
- userAgentData !== undefined ? userAgentData.mobile : window.innerWidth <= 800 && window.innerHeight <= 600;
90
- // TODO Move to theme
91
- return (
92
- <span style={{ color: '#ccc' }} spellCheck="false">
93
- {suggestion} {isMobile ? '(SWIPE \u2B95)' : '(TAB)'}
94
- </span>
95
- );
96
- }