@mdxeditor/editor 0.0.1 → 0.0.5-development
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/LICENSE +2 -2
- package/README.md +15 -75
- package/dist/FormatConstants.d.ts +9 -0
- package/dist/FormatConstants.js +10 -0
- package/dist/MDXEditor.d.ts +103 -0
- package/dist/MDXEditor.js +144 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.d.ts +17 -0
- package/dist/directive-editors/AdmonitionDirectiveDescriptor.js +28 -0
- package/dist/directive-editors/GenericDirectiveEditor.d.ts +8 -0
- package/dist/directive-editors/GenericDirectiveEditor.js +32 -0
- package/dist/exportMarkdownFromLexical.d.ts +138 -0
- package/dist/exportMarkdownFromLexical.js +239 -0
- package/dist/gurx/index.d.ts +3 -0
- package/dist/gurx/react.d.ts +152 -0
- package/dist/gurx/react.js +206 -0
- package/dist/gurx/realm.d.ts +148 -0
- package/dist/gurx/realm.js +489 -0
- package/dist/gurx/realmFactory.d.ts +79 -0
- package/dist/gurx/realmFactory.js +32 -0
- package/dist/icons/add_column.svg.js +5 -0
- package/dist/icons/add_photo.svg.js +5 -0
- package/dist/icons/add_row.svg.js +5 -0
- package/dist/icons/admonition.svg.js +5 -0
- package/dist/icons/arrow_drop_down.svg.js +5 -0
- package/dist/icons/check.svg.js +5 -0
- package/dist/icons/check_small.svg.js +5 -0
- package/dist/icons/close.svg.js +5 -0
- package/dist/icons/code.svg.js +5 -0
- package/dist/icons/content_copy.svg.js +5 -0
- package/dist/icons/delete_big.svg.js +5 -0
- package/dist/icons/delete_small.svg.js +5 -0
- package/dist/icons/difference.svg.js +5 -0
- package/dist/icons/edit.svg.js +5 -0
- package/dist/icons/extension.svg.js +7 -0
- package/dist/icons/format_align_center.svg.js +5 -0
- package/dist/icons/format_align_left.svg.js +5 -0
- package/dist/icons/format_align_right.svg.js +5 -0
- package/dist/icons/format_bold.svg.js +5 -0
- package/dist/icons/format_italic.svg.js +5 -0
- package/dist/icons/format_list_bulleted.svg.js +5 -0
- package/dist/icons/format_list_checked.svg.js +5 -0
- package/dist/icons/format_list_numbered.svg.js +5 -0
- package/dist/icons/format_underlined.svg.js +5 -0
- package/dist/icons/frame_source.svg.js +5 -0
- package/dist/icons/frontmatter.svg.js +5 -0
- package/dist/icons/horizontal_rule.svg.js +5 -0
- package/dist/icons/insert_col_left.svg.js +5 -0
- package/dist/icons/insert_col_right.svg.js +5 -0
- package/dist/icons/insert_row_above.svg.js +5 -0
- package/dist/icons/insert_row_below.svg.js +5 -0
- package/dist/icons/link.svg.js +5 -0
- package/dist/icons/link_off.svg.js +5 -0
- package/dist/icons/markdown.svg.js +5 -0
- package/dist/icons/more_horiz.svg.js +5 -0
- package/dist/icons/more_vert.svg.js +5 -0
- package/dist/icons/open_in_new.svg.js +5 -0
- package/dist/icons/redo.svg.js +5 -0
- package/dist/icons/rich_text.svg.js +5 -0
- package/dist/icons/sandpack.svg.js +5 -0
- package/dist/icons/settings.svg.js +5 -0
- package/dist/icons/table.svg.js +5 -0
- package/dist/icons/undo.svg.js +5 -0
- package/dist/importMarkdownToLexical.d.ts +101 -0
- package/dist/importMarkdownToLexical.js +93 -0
- package/dist/index.d.ts +62 -726
- package/dist/index.js +207 -4501
- package/dist/jsx-editors/GenericJsxEditor.d.ts +8 -0
- package/dist/jsx-editors/GenericJsxEditor.js +56 -0
- package/dist/plugins/codeblock/CodeBlockNode.d.ts +100 -0
- package/dist/plugins/codeblock/CodeBlockNode.js +158 -0
- package/dist/plugins/codeblock/CodeBlockVisitor.d.ts +4 -0
- package/dist/plugins/codeblock/CodeBlockVisitor.js +14 -0
- package/dist/plugins/codeblock/MdastCodeVisitor.d.ts +3 -0
- package/dist/plugins/codeblock/MdastCodeVisitor.js +16 -0
- package/dist/plugins/codeblock/index.d.ts +787 -0
- package/dist/plugins/codeblock/index.js +73 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.d.ts +3 -0
- package/dist/plugins/codemirror/CodeMirrorEditor.js +42 -0
- package/dist/plugins/codemirror/index.d.ts +1038 -0
- package/dist/plugins/codemirror/index.js +62 -0
- package/dist/plugins/core/GenericHTMLNode.d.ts +38 -0
- package/dist/plugins/core/GenericHTMLNode.js +117 -0
- package/dist/plugins/core/Icon.d.ts +6 -0
- package/dist/plugins/core/Icon.js +96 -0
- package/dist/plugins/core/LexicalGenericHTMLNodeVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalGenericHTMLNodeVisitor.js +15 -0
- package/dist/plugins/core/LexicalLinebreakVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalLinebreakVisitor.js +10 -0
- package/dist/plugins/core/LexicalParagraphVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalParagraphVisitor.js +10 -0
- package/dist/plugins/core/LexicalRootVisitor.d.ts +4 -0
- package/dist/plugins/core/LexicalRootVisitor.js +10 -0
- package/dist/plugins/core/LexicalTextVisitor.d.ts +5 -0
- package/dist/plugins/core/LexicalTextVisitor.js +102 -0
- package/dist/plugins/core/MdastBreakVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastBreakVisitor.js +10 -0
- package/dist/plugins/core/MdastFormattingVisitor.d.ts +4 -0
- package/dist/plugins/core/MdastFormattingVisitor.js +36 -0
- package/dist/plugins/core/MdastHTMLNode.d.ts +13 -0
- package/dist/plugins/core/MdastHTMLNode.js +122 -0
- package/dist/plugins/core/MdastHTMLVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastHTMLVisitor.js +12 -0
- package/dist/plugins/core/MdastInlineCodeVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastInlineCodeVisitor.js +27 -0
- package/dist/plugins/core/MdastParagraphVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastParagraphVisitor.js +15 -0
- package/dist/plugins/core/MdastRootVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastRootVisitor.js +9 -0
- package/dist/plugins/core/MdastTextVisitor.d.ts +3 -0
- package/dist/plugins/core/MdastTextVisitor.js +10 -0
- package/dist/plugins/core/NestedLexicalEditor.d.ts +92 -0
- package/dist/plugins/core/NestedLexicalEditor.js +185 -0
- package/dist/plugins/core/PropertyPopover.d.ts +23 -0
- package/dist/plugins/core/PropertyPopover.js +39 -0
- package/dist/plugins/core/SharedHistoryPlugin.d.ts +2 -0
- package/dist/plugins/core/SharedHistoryPlugin.js +10 -0
- package/dist/plugins/core/index.d.ts +583 -0
- package/dist/plugins/core/index.js +490 -0
- package/dist/plugins/core/ui/DownshiftAutoComplete.d.ts +15 -0
- package/dist/plugins/core/ui/DownshiftAutoComplete.js +83 -0
- package/dist/plugins/core/ui/PopoverUtils.d.ts +4 -0
- package/dist/plugins/core/ui/PopoverUtils.js +17 -0
- package/dist/plugins/diff-source/DiffSourceWrapper.d.ts +4 -0
- package/dist/plugins/diff-source/DiffSourceWrapper.js +14 -0
- package/dist/plugins/diff-source/DiffViewer.d.ts +2 -0
- package/dist/plugins/diff-source/DiffViewer.js +59 -0
- package/dist/plugins/diff-source/SourceEditor.d.ts +4 -0
- package/dist/plugins/diff-source/SourceEditor.js +53 -0
- package/dist/plugins/diff-source/index.d.ts +725 -0
- package/dist/plugins/diff-source/index.js +56 -0
- package/dist/plugins/directives/DirectiveNode.d.ts +51 -0
- package/dist/plugins/directives/DirectiveNode.js +92 -0
- package/dist/plugins/directives/DirectiveVisitor.d.ts +4 -0
- package/dist/plugins/directives/DirectiveVisitor.js +10 -0
- package/dist/plugins/directives/MdastDirectiveVisitor.d.ts +3 -0
- package/dist/plugins/directives/MdastDirectiveVisitor.js +13 -0
- package/dist/plugins/directives/index.d.ts +773 -0
- package/dist/plugins/directives/index.js +53 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.d.ts +6 -0
- package/dist/plugins/frontmatter/FrontmatterEditor.js +85 -0
- package/dist/plugins/frontmatter/FrontmatterNode.d.ts +35 -0
- package/dist/plugins/frontmatter/FrontmatterNode.js +71 -0
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.d.ts +4 -0
- package/dist/plugins/frontmatter/LexicalFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.d.ts +3 -0
- package/dist/plugins/frontmatter/MdastFrontmatterVisitor.js +10 -0
- package/dist/plugins/frontmatter/index.d.ts +717 -0
- package/dist/plugins/frontmatter/index.js +76 -0
- package/dist/plugins/headings/LexicalHeadingVisitor.d.ts +4 -0
- package/dist/plugins/headings/LexicalHeadingVisitor.js +11 -0
- package/dist/plugins/headings/MdastHeadingVisitor.d.ts +3 -0
- package/dist/plugins/headings/MdastHeadingVisitor.js +10 -0
- package/dist/plugins/headings/index.d.ts +707 -0
- package/dist/plugins/headings/index.js +69 -0
- package/dist/plugins/image/ImageDialog.d.ts +2 -0
- package/dist/plugins/image/ImageDialog.js +70 -0
- package/dist/plugins/image/ImageEditor.d.ts +10 -0
- package/dist/plugins/image/ImageEditor.js +227 -0
- package/dist/plugins/image/ImageNode.d.ts +65 -0
- package/dist/plugins/image/ImageNode.js +152 -0
- package/dist/plugins/image/ImageResizer.d.ts +18 -0
- package/dist/plugins/image/ImageResizer.js +214 -0
- package/dist/plugins/image/LexicalImageVisitor.d.ts +4 -0
- package/dist/plugins/image/LexicalImageVisitor.js +35 -0
- package/dist/plugins/image/MdastImageVisitor.d.ts +6 -0
- package/dist/plugins/image/MdastImageVisitor.js +87 -0
- package/dist/plugins/image/index.d.ts +804 -0
- package/dist/plugins/image/index.js +300 -0
- package/dist/plugins/jsx/LexicalJsxNode.d.ts +54 -0
- package/dist/plugins/jsx/LexicalJsxNode.js +102 -0
- package/dist/plugins/jsx/LexicalJsxVisitor.d.ts +4 -0
- package/dist/plugins/jsx/LexicalJsxVisitor.js +24 -0
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.d.ts +3 -0
- package/dist/plugins/jsx/MdastMdxJsEsmVisitor.js +8 -0
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.d.ts +3 -0
- package/dist/plugins/jsx/MdastMdxJsxElementVisitor.js +12 -0
- package/dist/plugins/jsx/index.d.ts +779 -0
- package/dist/plugins/jsx/index.js +82 -0
- package/dist/plugins/link/AutoLinkPlugin.d.ts +9 -0
- package/dist/plugins/link/AutoLinkPlugin.js +18 -0
- package/dist/plugins/link/LexicalLinkVisitor.d.ts +4 -0
- package/dist/plugins/link/LexicalLinkVisitor.js +10 -0
- package/dist/plugins/link/MdastLinkVisitor.d.ts +3 -0
- package/dist/plugins/link/MdastLinkVisitor.js +14 -0
- package/dist/plugins/link/index.d.ts +101 -0
- package/dist/plugins/link/index.js +33 -0
- package/dist/plugins/link-dialog/LinkDialog.d.ts +16 -0
- package/dist/plugins/link-dialog/LinkDialog.js +148 -0
- package/dist/plugins/link-dialog/index.d.ts +669 -0
- package/dist/plugins/link-dialog/index.js +254 -0
- package/dist/plugins/lists/LexicalListItemVisitor.d.ts +4 -0
- package/dist/plugins/lists/LexicalListItemVisitor.js +23 -0
- package/dist/plugins/lists/LexicalListVisitor.d.ts +4 -0
- package/dist/plugins/lists/LexicalListVisitor.js +13 -0
- package/dist/plugins/lists/MdastListItemVisitor.d.ts +3 -0
- package/dist/plugins/lists/MdastListItemVisitor.js +10 -0
- package/dist/plugins/lists/MdastListVisitor.d.ts +3 -0
- package/dist/plugins/lists/MdastListVisitor.js +20 -0
- package/dist/plugins/lists/index.d.ts +703 -0
- package/dist/plugins/lists/index.js +122 -0
- package/dist/plugins/markdown-shortcut/index.d.ts +80 -0
- package/dist/plugins/markdown-shortcut/index.js +90 -0
- package/dist/plugins/quote/LexicalQuoteVisitor.d.ts +4 -0
- package/dist/plugins/quote/LexicalQuoteVisitor.js +12 -0
- package/dist/plugins/quote/MdastBlockQuoteVisitor.d.ts +3 -0
- package/dist/plugins/quote/MdastBlockQuoteVisitor.js +10 -0
- package/dist/plugins/quote/index.d.ts +480 -0
- package/dist/plugins/quote/index.js +26 -0
- package/dist/plugins/sandpack/SandpackEditor.d.ts +7 -0
- package/dist/plugins/sandpack/SandpackEditor.js +37 -0
- package/dist/plugins/sandpack/index.d.ts +1077 -0
- package/dist/plugins/sandpack/index.js +93 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.d.ts +4 -0
- package/dist/plugins/sandpack/useCodeMirrorRef.js +96 -0
- package/dist/plugins/table/LexicalTableVisitor.d.ts +4 -0
- package/dist/plugins/table/LexicalTableVisitor.js +10 -0
- package/dist/plugins/table/MdastTableVisitor.d.ts +3 -0
- package/dist/plugins/table/MdastTableVisitor.js +10 -0
- package/dist/plugins/table/TableEditor.d.ts +21 -0
- package/dist/plugins/table/TableEditor.js +388 -0
- package/dist/plugins/table/TableNode.d.ts +52 -0
- package/dist/plugins/table/TableNode.js +152 -0
- package/dist/plugins/table/index.d.ts +704 -0
- package/dist/plugins/table/index.js +69 -0
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.d.ts +4 -0
- package/dist/plugins/thematic-break/LexicalThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.d.ts +3 -0
- package/dist/plugins/thematic-break/MdastThematicBreakVisitor.js +10 -0
- package/dist/plugins/thematic-break/index.d.ts +693 -0
- package/dist/plugins/thematic-break/index.js +39 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.d.ts +6 -0
- package/dist/plugins/toolbar/components/BlockTypeSelect.js +54 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.d.ts +5 -0
- package/dist/plugins/toolbar/components/BoldItalicUnderlineToggles.js +33 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.d.ts +6 -0
- package/dist/plugins/toolbar/components/ChangeAdmonitionType.js +30 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.d.ts +7 -0
- package/dist/plugins/toolbar/components/ChangeCodeMirrorLanguage.js +32 -0
- package/dist/plugins/toolbar/components/CodeToggle.d.ts +6 -0
- package/dist/plugins/toolbar/components/CodeToggle.js +19 -0
- package/dist/plugins/toolbar/components/CreateLink.d.ts +6 -0
- package/dist/plugins/toolbar/components/CreateLink.js +20 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.d.ts +18 -0
- package/dist/plugins/toolbar/components/DiffSourceToggleWrapper.js +25 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertAdmonition.js +29 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.d.ts +7 -0
- package/dist/plugins/toolbar/components/InsertCodeBlock.js +20 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertFrontmatter.js +24 -0
- package/dist/plugins/toolbar/components/InsertImage.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertImage.js +14 -0
- package/dist/plugins/toolbar/components/InsertSandpack.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertSandpack.js +13 -0
- package/dist/plugins/toolbar/components/InsertTable.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertTable.js +20 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.d.ts +6 -0
- package/dist/plugins/toolbar/components/InsertThematicBreak.js +11 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.d.ts +7 -0
- package/dist/plugins/toolbar/components/KitchenSinkToolbar.js +58 -0
- package/dist/plugins/toolbar/components/ListsToggle.d.ts +7 -0
- package/dist/plugins/toolbar/components/ListsToggle.js +23 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.d.ts +7 -0
- package/dist/plugins/toolbar/components/ShowSandpackInfo.js +31 -0
- package/dist/plugins/toolbar/components/UndoRedo.d.ts +5 -0
- package/dist/plugins/toolbar/components/UndoRedo.js +58 -0
- package/dist/plugins/toolbar/index.d.ts +564 -0
- package/dist/plugins/toolbar/index.js +40 -0
- package/dist/plugins/toolbar/primitives/DialogButton.d.ts +40 -0
- package/dist/plugins/toolbar/primitives/DialogButton.js +114 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.d.ts +8 -0
- package/dist/plugins/toolbar/primitives/TooltipWrap.js +12 -0
- package/dist/plugins/toolbar/primitives/select.d.ts +50 -0
- package/dist/plugins/toolbar/primitives/select.js +55 -0
- package/dist/plugins/toolbar/primitives/toolbar.d.ts +163 -0
- package/dist/plugins/toolbar/primitives/toolbar.js +115 -0
- package/dist/style.css +1093 -288
- package/dist/styles/globals.css.js +4 -0
- package/dist/styles/lexical-theme.module.css.js +62 -0
- package/dist/styles/lexicalTheme.d.ts +2 -0
- package/dist/styles/lexicalTheme.js +31 -0
- package/dist/styles/ui.module.css.js +311 -0
- package/dist/utils/detectMac.d.ts +3 -0
- package/dist/utils/detectMac.js +13 -0
- package/dist/utils/fp.d.ts +47 -0
- package/dist/utils/fp.js +44 -0
- package/dist/utils/isPartOftheEditorUI.d.ts +1 -0
- package/dist/utils/isPartOftheEditorUI.js +12 -0
- package/dist/utils/lexicalHelpers.d.ts +11 -0
- package/dist/utils/lexicalHelpers.js +80 -0
- package/dist/utils/makeHslTransparent.d.ts +1 -0
- package/dist/utils/makeHslTransparent.js +6 -0
- package/dist/utils/mergeStyleAttributes.d.ts +1 -0
- package/dist/utils/mergeStyleAttributes.js +22 -0
- package/dist/utils/uuid4.d.ts +1 -0
- package/dist/utils/uuid4.js +10 -0
- package/dist/utils/voidEmitter.d.ts +14 -0
- package/dist/utils/voidEmitter.js +15 -0
- package/dist/utils/whitespaceConversion.d.ts +2 -0
- package/dist/utils/whitespaceConversion.js +9 -0
- package/package.json +326 -39
- package/dist/index.cjs +0 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { LongTuple } from './realmFactory';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export type NodeKey = string;
|
|
4
|
+
/** @internal */
|
|
5
|
+
export interface RealmNode<_T = unknown> {
|
|
6
|
+
key: NodeKey;
|
|
7
|
+
toString(): string;
|
|
8
|
+
}
|
|
9
|
+
/** @internal */
|
|
10
|
+
type RN<T = unknown> = RealmNode<T>;
|
|
11
|
+
/** @internal **/
|
|
12
|
+
export type Subscription<T = any> = (value: T) => unknown;
|
|
13
|
+
/** @internal */
|
|
14
|
+
export type UnsubscribeHandle = () => void;
|
|
15
|
+
type ProjectionFunc<T extends unknown[] = unknown[]> = (done: (...values: unknown[]) => void) => (...args: T) => void;
|
|
16
|
+
/** @internal */
|
|
17
|
+
export interface RealmProjection<T extends unknown[] = unknown[]> {
|
|
18
|
+
sources: Set<NodeKey>;
|
|
19
|
+
pulls: Set<NodeKey>;
|
|
20
|
+
sink: NodeKey;
|
|
21
|
+
map: ProjectionFunc<T>;
|
|
22
|
+
}
|
|
23
|
+
/** @internal */
|
|
24
|
+
export interface RealmProjectionSpec<T extends unknown[] = unknown[]> {
|
|
25
|
+
sources: RealmNode[];
|
|
26
|
+
pulls?: RealmNode[];
|
|
27
|
+
sink: RealmNode;
|
|
28
|
+
map: ProjectionFunc<T>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A function which determines if two values are equal.
|
|
32
|
+
* Implement custom comparators when the distinctUntilChanged operator needs to work on non-primitive objects.
|
|
33
|
+
* @returns true if values should be considered equal.
|
|
34
|
+
*/
|
|
35
|
+
export interface Comparator<T = any> {
|
|
36
|
+
(current: T, next: T): boolean;
|
|
37
|
+
}
|
|
38
|
+
type NodesFromValuesRec<T extends unknown[], Acc extends unknown[]> = T extends [infer Head, ...infer Tail] ? NodesFromValuesRec<Tail, [...Acc, Head extends unknown ? RealmNode<Head> : never]> : Acc;
|
|
39
|
+
/** @internal */
|
|
40
|
+
export type NodesFromValues<T extends unknown[]> = T extends unknown[] ? NodesFromValuesRec<T, []> : never;
|
|
41
|
+
/**
|
|
42
|
+
* A comparator function to determine if two values are equal. Used by distinctUntilChanged operator.
|
|
43
|
+
*/
|
|
44
|
+
export declare function defaultComparator<T>(current: T, next: T): boolean;
|
|
45
|
+
declare class SetMap<T> {
|
|
46
|
+
map: Map<string, Set<T>>;
|
|
47
|
+
getOrCreate(key: NodeKey): Set<T>;
|
|
48
|
+
get(key: NodeKey): Set<T> | undefined;
|
|
49
|
+
use(key: NodeKey, cb: (value: Set<T>) => unknown): void;
|
|
50
|
+
delete(key: NodeKey): boolean;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @internal
|
|
54
|
+
*/
|
|
55
|
+
export declare class RefCount {
|
|
56
|
+
map: Map<NodeKey, number>;
|
|
57
|
+
constructor(map?: Map<string, number>);
|
|
58
|
+
clone(): RefCount;
|
|
59
|
+
increment(key: NodeKey): void;
|
|
60
|
+
decrement(key: NodeKey, ifZero: () => void): void;
|
|
61
|
+
}
|
|
62
|
+
/** @internal */
|
|
63
|
+
export type RealmGraph = SetMap<RealmProjection>;
|
|
64
|
+
/** @internal */
|
|
65
|
+
export declare function realm(): {
|
|
66
|
+
combine: {
|
|
67
|
+
<T1>(nodes_0: RN<T1>): RN<T1>;
|
|
68
|
+
<T1_1, T2>(nodes_0: RN<T1_1>, nodes_1: RN<T2>): RN<[T1_1, T2]>;
|
|
69
|
+
<T1_2, T2_1, T3>(nodes_0: RN<T1_2>, nodes_1: RN<T2_1>, nodes_2: RN<T3>): RN<[T1_2, T2_1, T3]>;
|
|
70
|
+
<T1_3, T2_2, T3_1, T4>(nodes_0: RN<T1_3>, nodes_1: RN<T2_2>, nodes_2: RN<T3_1>, nodes_3: RN<T4>): RN<[T1_3, T2_2, T3_1, T4]>;
|
|
71
|
+
<T1_4, T2_3, T3_2, T4_1, T5>(nodes_0: RN<T1_4>, nodes_1: RN<T2_3>, nodes_2: RN<T3_2>, nodes_3: RN<T4_1>, nodes_4: RN<T5>): RN<[T1_4, T2_3, T3_2, T4_1, T5]>;
|
|
72
|
+
<T1_5, T2_4, T3_3, T4_2, T5_1, T6>(nodes_0: RN<T1_5>, nodes_1: RN<T2_4>, nodes_2: RN<T3_3>, nodes_3: RN<T4_2>, nodes_4: RN<T5_1>, nodes_5: RN<T6>): RN<[T1_5, T2_4, T3_3, T4_2, T5_1, T6]>;
|
|
73
|
+
<T1_6, T2_5, T3_4, T4_3, T5_2, T6_1, T7>(nodes_0: RN<T1_6>, nodes_1: RN<T2_5>, nodes_2: RN<T3_4>, nodes_3: RN<T4_3>, nodes_4: RN<T5_2>, nodes_5: RN<T6_1>, nodes_6: RN<T7>): RN<[T1_6, T2_5, T3_4, T4_3, T5_2, T6_1, T7]>;
|
|
74
|
+
<T1_7, T2_6, T3_5, T4_4, T5_3, T6_2, T7_1, T8>(nodes_0: RN<T1_7>, nodes_1: RN<T2_6>, nodes_2: RN<T3_5>, nodes_3: RN<T4_4>, nodes_4: RN<T5_3>, nodes_5: RN<T6_2>, nodes_6: RN<T7_1>, nodes_7: RN<T8>): RN<[T1_7, T2_6, T3_5, T4_4, T5_3, T6_2, T7_1, T8]>;
|
|
75
|
+
<T1_8, T2_7, T3_6, T4_5, T5_4, T6_3, T7_2, T8_1, T9>(nodes_0: RN<T1_8>, nodes_1: RN<T2_7>, nodes_2: RN<T3_6>, nodes_3: RN<T4_5>, nodes_4: RN<T5_4>, nodes_5: RN<T6_3>, nodes_6: RN<T7_2>, nodes_7: RN<T8_1>, nodes_8: RN<T9>): RN<[T1_8, T2_7, T3_6, T4_5, T5_4, T6_3, T7_2, T8_1, T9]>;
|
|
76
|
+
<T1_9, T2_8, T3_7, T4_6, T5_5, T6_4, T7_3, T8_2, T9_1, T10>(nodes_0: RN<T1_9>, nodes_1: RN<T2_8>, nodes_2: RN<T3_7>, nodes_3: RN<T4_6>, nodes_4: RN<T5_5>, nodes_5: RN<T6_4>, nodes_6: RN<T7_3>, nodes_7: RN<T8_2>, nodes_8: RN<T9_1>, nodes_9: RN<T10>): RN<[T1_9, T2_8, T3_7, T4_6, T5_5, T6_4, T7_3, T8_2, T9_1, T10]>;
|
|
77
|
+
<T1_10, T2_9, T3_8, T4_7, T5_6, T6_5, T7_4, T8_3, T9_2, T10_1, T11>(nodes_0: RN<T1_10>, nodes_1: RN<T2_9>, nodes_2: RN<T3_8>, nodes_3: RN<T4_7>, nodes_4: RN<T5_6>, nodes_5: RN<T6_5>, nodes_6: RN<T7_4>, nodes_7: RN<T8_3>, nodes_8: RN<T9_2>, nodes_9: RN<T10_1>, nodes_10: RN<T11>): RN<[T1_10, T2_9, T3_8, T4_7, T5_6, T6_5, T7_4, T8_3, T9_2, T10_1, T11]>;
|
|
78
|
+
<T1_11, T2_10, T3_9, T4_8, T5_7, T6_6, T7_5, T8_4, T9_3, T10_2, T11_1, T12, T13>(nodes_0: RN<T1_11>, nodes_1: RN<T2_10>, nodes_2: RN<T3_9>, nodes_3: RN<T4_8>, nodes_4: RN<T5_7>, nodes_5: RN<T6_6>, nodes_6: RN<T7_5>, nodes_7: RN<T8_4>, nodes_8: RN<T9_3>, nodes_9: RN<T10_2>, nodes_10: RN<T11_1>, nodes_11: RN<T12>, nodes_12: RN<T13>): RN<[T1_11, T2_10, T3_9, T4_8, T5_7, T6_6, T7_5, T8_4, T9_3, T10_2, T11_1, T12, T13]>;
|
|
79
|
+
<T1_12, T2_11, T3_10, T4_9, T5_8, T6_7, T7_6, T8_5, T9_4, T10_3, T11_2, T12_1, T13_1, T14>(nodes_0: RN<T1_12>, nodes_1: RN<T2_11>, nodes_2: RN<T3_10>, nodes_3: RN<T4_9>, nodes_4: RN<T5_8>, nodes_5: RN<T6_7>, nodes_6: RN<T7_6>, nodes_7: RN<T8_5>, nodes_8: RN<T9_4>, nodes_9: RN<T10_3>, nodes_10: RN<T11_2>, nodes_11: RN<T12_1>, nodes_12: RN<T13_1>, nodes_13: RN<T14>): RN<[T1_12, T2_11, T3_10, T4_9, T5_8, T6_7, T7_6, T8_5, T9_4, T10_3, T11_2, T12_1, T13_1, T14]>;
|
|
80
|
+
<T1_13, T2_12, T3_11, T4_10, T5_9, T6_8, T7_7, T8_6, T9_5, T10_4, T11_3, T12_2, T13_2, T14_1, T15>(nodes_0: RN<T1_13>, nodes_1: RN<T2_12>, nodes_2: RN<T3_11>, nodes_3: RN<T4_10>, nodes_4: RN<T5_9>, nodes_5: RN<T6_8>, nodes_6: RN<T7_7>, nodes_7: RN<T8_6>, nodes_8: RN<T9_5>, nodes_9: RN<T10_4>, nodes_10: RN<T11_3>, nodes_11: RN<T12_2>, nodes_12: RN<T13_2>, nodes_13: RN<T14_1>, nodes_14: RN<T15>): RN<[T1_13, T2_12, T3_11, T4_10, T5_9, T6_8, T7_7, T8_6, T9_5, T10_4, T11_3, T12_2, T13_2, T14_1, T15]>;
|
|
81
|
+
<T1_14, T2_13, T3_12, T4_11, T5_10, T6_9, T7_8, T8_7, T9_6, T10_5, T11_4, T12_3, T13_3, T14_2, T15_1, T16>(nodes_0: RN<T1_14>, nodes_1: RN<T2_13>, nodes_2: RN<T3_12>, nodes_3: RN<T4_11>, nodes_4: RN<T5_10>, nodes_5: RN<T6_9>, nodes_6: RN<T7_8>, nodes_7: RN<T8_7>, nodes_8: RN<T9_6>, nodes_9: RN<T10_5>, nodes_10: RN<T11_4>, nodes_11: RN<T12_3>, nodes_12: RN<T13_3>, nodes_13: RN<T14_2>, nodes_14: RN<T15_1>, nodes_15: RN<T16>): RN<[T1_14, T2_13, T3_12, T4_11, T5_10, T6_9, T7_8, T8_7, T9_6, T10_5, T11_4, T12_3, T13_3, T14_2, T15_1, T16]>;
|
|
82
|
+
};
|
|
83
|
+
connect: <T extends unknown[] = unknown[]>({ sources, pulls, map, sink: { key: sink } }: RealmProjectionSpec<T>) => void;
|
|
84
|
+
derive: <T_1>(source: RealmNode<T_1>, initial: T_1) => RealmNode<T_1>;
|
|
85
|
+
getKeyValue: (key: string) => unknown;
|
|
86
|
+
getValue: <T_2>(node: RN<T_2>) => T_2;
|
|
87
|
+
getKeyValues: (keys: string[]) => unknown[];
|
|
88
|
+
label: (newLabels: Record<string, RealmNode<unknown>>) => void;
|
|
89
|
+
labels: Record<string, RealmNode<unknown>>;
|
|
90
|
+
link: <T_3>(source: RealmNode<T_3>, sink: RealmNode<T_3>) => void;
|
|
91
|
+
node: <T_4>(value?: symbol | T_4, distinct?: boolean | Comparator<T_4>) => RealmNode<T_4>;
|
|
92
|
+
o: {
|
|
93
|
+
delayWithMicrotask: <I>() => (source: RealmNode<I>) => RealmNode<I>;
|
|
94
|
+
debounceTime: <I_1>(delay: number) => (source: RealmNode<I_1>) => RealmNode<I_1>;
|
|
95
|
+
filter: <I_2, O_1 = I_2>(predicate: (value: I_2) => boolean) => (source: RealmNode<I_2>) => RealmNode<O_1>;
|
|
96
|
+
map: <I_3, O_2>(mapFunction: (value: I_3) => O_2) => (source: RealmNode<I_3>) => RealmNode<O_2>;
|
|
97
|
+
mapTo: <I_4, O_3>(value: O_3) => (source: RealmNode<I_4>) => RealmNode<O_3>;
|
|
98
|
+
onNext: <I_5, O_4>(bufNode: RN<O_4>) => (source: RealmNode<I_5>) => RealmNode<[I_5, O_4]>;
|
|
99
|
+
scan: <I_6, O_5>(accumulator: (current: O_5, value: I_6) => O_5, seed: O_5) => (source: RealmNode<I_6>) => RealmNode<O_5>;
|
|
100
|
+
throttleTime: <I_7>(delay: number) => (source: RealmNode<I_7>) => RealmNode<I_7>;
|
|
101
|
+
withLatestFrom: {
|
|
102
|
+
<I_8, T1_15>(nodes_0: RN<T1_15>): (source: RN<I_8>) => RN<[I_8, T1_15]>;
|
|
103
|
+
<I_9, T1_16, T2_14>(nodes_0: RN<T1_16>, nodes_1: RN<T2_14>): (source: RN<I_9>) => RN<[I_9, T1_16, T2_14]>;
|
|
104
|
+
<I_10, T1_17, T2_15, T3_13>(nodes_0: RN<T1_17>, nodes_1: RN<T2_15>, nodes_2: RN<T3_13>): (source: RN<I_10>) => RN<[I_10, T1_17, T2_15, T3_13]>;
|
|
105
|
+
<I_11, T1_18, T2_16, T3_14, T4_12>(nodes_0: RN<T1_18>, nodes_1: RN<T2_16>, nodes_2: RN<T3_14>, nodes_3: RN<T4_12>): (source: RN<I_11>) => RN<[I_11, T1_18, T2_16, T3_14, T4_12]>;
|
|
106
|
+
<I_12, T1_19, T2_17, T3_15, T4_13, T5_11>(nodes_0: RN<T1_19>, nodes_1: RN<T2_17>, nodes_2: RN<T3_15>, nodes_3: RN<T4_13>, nodes_4: RN<T5_11>): (source: RN<I_12>) => RN<[I_12, T1_19, T2_17, T3_15, T4_13, T5_11]>;
|
|
107
|
+
<I_13, T1_20, T2_18, T3_16, T4_14, T5_12, T6_10>(nodes_0: RN<T1_20>, nodes_1: RN<T2_18>, nodes_2: RN<T3_16>, nodes_3: RN<T4_14>, nodes_4: RN<T5_12>, nodes_5: RN<T6_10>): (source: RN<I_13>) => RN<[I_13, T1_20, T2_18, T3_16, T4_14, T5_12, T6_10]>;
|
|
108
|
+
<I_14, T1_21, T2_19, T3_17, T4_15, T5_13, T6_11, T7_9>(nodes_0: RN<T1_21>, nodes_1: RN<T2_19>, nodes_2: RN<T3_17>, nodes_3: RN<T4_15>, nodes_4: RN<T5_13>, nodes_5: RN<T6_11>, nodes_6: RN<T7_9>): (source: RN<I_14>) => RN<[I_14, T1_21, T2_19, T3_17, T4_15, T5_13, T6_11, T7_9]>;
|
|
109
|
+
<I_15, T1_22, T2_20, T3_18, T4_16, T5_14, T6_12, T7_10, T8_8>(nodes_0: RN<T1_22>, nodes_1: RN<T2_20>, nodes_2: RN<T3_18>, nodes_3: RN<T4_16>, nodes_4: RN<T5_14>, nodes_5: RN<T6_12>, nodes_6: RN<T7_10>, nodes_7: RN<T8_8>): (source: RN<I_15>) => RN<[I_15, T1_22, T2_20, T3_18, T4_16, T5_14, T6_12, T7_10, T8_8]>;
|
|
110
|
+
};
|
|
111
|
+
once: <I_16>() => (source: RealmNode<I_16>) => RealmNode<I_16>;
|
|
112
|
+
passOnlyAfterNodeHasEmittedBefore: <I_17>(starterNode: RN<unknown>, durationNode: RN<number>) => (source: RealmNode<I_17>) => RealmNode<I_17>;
|
|
113
|
+
};
|
|
114
|
+
pipe: {
|
|
115
|
+
<T_5>(s: RealmNode<T_5>): RealmNode<T_5>;
|
|
116
|
+
<T_6, O1>(s: RealmNode<T_6>, o1: (source: RealmNode<T_6>) => RealmNode<O1>): RealmNode<O1>;
|
|
117
|
+
<T_7, O1_1, O2>(s: RealmNode<T_7>, o_0: (source: RealmNode<T_7>) => RealmNode<O1_1>, o_1: (source: RealmNode<O1_1>) => RealmNode<O2>): RealmNode<O2>;
|
|
118
|
+
<T_8, O1_2, O2_1, O3>(s: RealmNode<T_8>, o_0: (source: RealmNode<T_8>) => RealmNode<O1_2>, o_1: (source: RealmNode<O1_2>) => RealmNode<O2_1>, o_2: (source: RealmNode<O2_1>) => RealmNode<O3>): RealmNode<O3>;
|
|
119
|
+
<T_9, O1_3, O2_2, O3_1, O4>(s: RealmNode<T_9>, o_0: (source: RealmNode<T_9>) => RealmNode<O1_3>, o_1: (source: RealmNode<O1_3>) => RealmNode<O2_2>, o_2: (source: RealmNode<O2_2>) => RealmNode<O3_1>, o_3: (source: RealmNode<O3_1>) => RealmNode<O4>): RealmNode<O4>;
|
|
120
|
+
<T_10, O1_4, O2_3, O3_2, O4_1, O5>(s: RealmNode<T_10>, o_0: (source: RealmNode<T_10>) => RealmNode<O1_4>, o_1: (source: RealmNode<O1_4>) => RealmNode<O2_3>, o_2: (source: RealmNode<O2_3>) => RealmNode<O3_2>, o_3: (source: RealmNode<O3_2>) => RealmNode<O4_1>, o_4: (source: RealmNode<O4_1>) => RealmNode<O5>): RealmNode<O5>;
|
|
121
|
+
<T_11, O1_5, O2_4, O3_3, O4_2, O5_1, O6>(s: RealmNode<T_11>, o_0: (source: RealmNode<T_11>) => RealmNode<O1_5>, o_1: (source: RealmNode<O1_5>) => RealmNode<O2_4>, o_2: (source: RealmNode<O2_4>) => RealmNode<O3_3>, o_3: (source: RealmNode<O3_3>) => RealmNode<O4_2>, o_4: (source: RealmNode<O4_2>) => RealmNode<O5_1>, o_5: (source: RealmNode<O5_1>) => RealmNode<O6>): RealmNode<O6>;
|
|
122
|
+
<T_12, O1_6, O2_5, O3_4, O4_3, O5_2, O6_1, O7>(s: RealmNode<T_12>, o_0: (source: RealmNode<T_12>) => RealmNode<O1_6>, o_1: (source: RealmNode<O1_6>) => RealmNode<O2_5>, o_2: (source: RealmNode<O2_5>) => RealmNode<O3_4>, o_3: (source: RealmNode<O3_4>) => RealmNode<O4_3>, o_4: (source: RealmNode<O4_3>) => RealmNode<O5_2>, o_5: (source: RealmNode<O5_2>) => RealmNode<O6_1>, o_6: (source: RealmNode<O6_1>) => RealmNode<O7>): RealmNode<O7>;
|
|
123
|
+
};
|
|
124
|
+
pub: {
|
|
125
|
+
<T1_23>(args_0: RN<T1_23>, args_1: T1_23): void;
|
|
126
|
+
<T1_24, T2_21>(args_0: RN<T1_24>, args_1: T1_24, args_2: RN<T2_21>, args_3: T2_21): void;
|
|
127
|
+
<T1_25, T2_22, T3_19>(args_0: RN<T1_25>, args_1: T1_25, args_2: RN<T2_22>, args_3: T2_22, args_4: RN<T3_19>, args_5: T3_19): void;
|
|
128
|
+
<T1_26, T2_23, T3_20, T4_17>(args_0: RN<T1_26>, args_1: T1_26, args_2: RN<T2_23>, args_3: T2_23, args_4: RN<T3_20>, args_5: T3_20, args_6: T4_17): void;
|
|
129
|
+
};
|
|
130
|
+
pubIn: (values: Record<NodeKey, unknown>) => void;
|
|
131
|
+
pubKey: (key: string, value: unknown) => void;
|
|
132
|
+
pubKeys: (values: Record<string, unknown>) => void;
|
|
133
|
+
resetSingletonSubs: () => void;
|
|
134
|
+
singletonSub: <T_13>({ key }: RealmNode<T_13>, subscription: Subscription<T_13> | undefined) => UnsubscribeHandle;
|
|
135
|
+
singletonSubKey: <T_14>(key: string, subscription: Subscription<T_14> | undefined) => UnsubscribeHandle;
|
|
136
|
+
spread: <T_15 extends LongTuple<unknown>>(source: RealmNode<T_15>, initialValues: T_15) => NodesFromValues<T_15>;
|
|
137
|
+
sub: {
|
|
138
|
+
<T1_27>(args_0: RN<T1_27>, args_1: Subscription<T1_27>): UnsubscribeHandle;
|
|
139
|
+
<T1_28, T2_24>(args_0: RN<T1_28>, args_1: RN<T2_24>, args_2: Subscription<[T1_28, T2_24]>): UnsubscribeHandle;
|
|
140
|
+
<T1_29, T2_25, T3_21>(args_0: RN<T1_29>, args_1: RN<T2_25>, args_2: RN<T3_21>, args_3: Subscription<[T1_29, T2_25, T3_21]>): UnsubscribeHandle;
|
|
141
|
+
};
|
|
142
|
+
subKey: (key: string, subscription: Subscription<unknown>) => UnsubscribeHandle;
|
|
143
|
+
subKeys: (keys: string[], subscription: Subscription<unknown>) => UnsubscribeHandle;
|
|
144
|
+
};
|
|
145
|
+
/** @internal */
|
|
146
|
+
export interface Realm extends ReturnType<typeof realm> {
|
|
147
|
+
}
|
|
148
|
+
export {};
|
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
import { tap } from "../utils/fp.js";
|
|
8
|
+
import { uuidv4 } from "../utils/uuid4.js";
|
|
9
|
+
function defaultComparator(current, next) {
|
|
10
|
+
return current === next;
|
|
11
|
+
}
|
|
12
|
+
class SetMap {
|
|
13
|
+
constructor() {
|
|
14
|
+
__publicField(this, "map", /* @__PURE__ */ new Map());
|
|
15
|
+
}
|
|
16
|
+
getOrCreate(key) {
|
|
17
|
+
let record = this.map.get(key);
|
|
18
|
+
if (!record) {
|
|
19
|
+
record = /* @__PURE__ */ new Set();
|
|
20
|
+
this.map.set(key, record);
|
|
21
|
+
}
|
|
22
|
+
return record;
|
|
23
|
+
}
|
|
24
|
+
get(key) {
|
|
25
|
+
return this.map.get(key);
|
|
26
|
+
}
|
|
27
|
+
use(key, cb) {
|
|
28
|
+
const set = this.get(key);
|
|
29
|
+
if (set !== void 0) {
|
|
30
|
+
cb(set);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
delete(key) {
|
|
34
|
+
return this.map.delete(key);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
class RefCount {
|
|
38
|
+
constructor(map = /* @__PURE__ */ new Map()) {
|
|
39
|
+
__publicField(this, "map");
|
|
40
|
+
this.map = map;
|
|
41
|
+
}
|
|
42
|
+
clone() {
|
|
43
|
+
return new RefCount(new Map(this.map));
|
|
44
|
+
}
|
|
45
|
+
increment(key) {
|
|
46
|
+
const counter = this.map.get(key) ?? 0;
|
|
47
|
+
this.map.set(key, counter + 1);
|
|
48
|
+
}
|
|
49
|
+
decrement(key, ifZero) {
|
|
50
|
+
let counter = this.map.get(key);
|
|
51
|
+
if (counter !== void 0) {
|
|
52
|
+
counter -= 1;
|
|
53
|
+
this.map.set(key, counter);
|
|
54
|
+
if (counter === 0) {
|
|
55
|
+
ifZero();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const NO_VALUE = Symbol("NO_VALUE");
|
|
61
|
+
function realm() {
|
|
62
|
+
const subscriptions = new SetMap();
|
|
63
|
+
const singletonSubscriptions = /* @__PURE__ */ new Map();
|
|
64
|
+
const graph = new SetMap();
|
|
65
|
+
const state = /* @__PURE__ */ new Map();
|
|
66
|
+
const distinctNodes = /* @__PURE__ */ new Map();
|
|
67
|
+
const labels = {};
|
|
68
|
+
function node(value = NO_VALUE, distinct = false) {
|
|
69
|
+
const key = uuidv4();
|
|
70
|
+
if (value !== NO_VALUE) {
|
|
71
|
+
state.set(key, value);
|
|
72
|
+
}
|
|
73
|
+
if (distinct !== false) {
|
|
74
|
+
distinctNodes.set(key, distinct === true ? defaultComparator : distinct);
|
|
75
|
+
}
|
|
76
|
+
return { key, toString: () => key };
|
|
77
|
+
}
|
|
78
|
+
function subSingle({ key }, subscription) {
|
|
79
|
+
const nodeSubscriptions = subscriptions.getOrCreate(key);
|
|
80
|
+
nodeSubscriptions.add(subscription);
|
|
81
|
+
return () => nodeSubscriptions.delete(subscription);
|
|
82
|
+
}
|
|
83
|
+
function singletonSub({ key }, subscription) {
|
|
84
|
+
if (!subscription) {
|
|
85
|
+
singletonSubscriptions.delete(key);
|
|
86
|
+
} else {
|
|
87
|
+
singletonSubscriptions.set(key, subscription);
|
|
88
|
+
}
|
|
89
|
+
return () => singletonSubscriptions.delete(key);
|
|
90
|
+
}
|
|
91
|
+
function singletonSubKey(key, subscription) {
|
|
92
|
+
return singletonSub(labels[key], subscription);
|
|
93
|
+
}
|
|
94
|
+
function resetSingletonSubs() {
|
|
95
|
+
singletonSubscriptions.clear();
|
|
96
|
+
}
|
|
97
|
+
function subMultiple(sources, cb) {
|
|
98
|
+
const sink = node();
|
|
99
|
+
connect({
|
|
100
|
+
map: (done) => (...args) => {
|
|
101
|
+
done(args);
|
|
102
|
+
},
|
|
103
|
+
sink,
|
|
104
|
+
sources
|
|
105
|
+
});
|
|
106
|
+
return subSingle(sink, cb);
|
|
107
|
+
}
|
|
108
|
+
function sub(...args) {
|
|
109
|
+
const [subscription] = args.slice(-1);
|
|
110
|
+
const nodes = args.slice(0, -1);
|
|
111
|
+
if (nodes.length === 1) {
|
|
112
|
+
return subSingle(nodes[0], subscription);
|
|
113
|
+
} else {
|
|
114
|
+
return subMultiple(nodes, subscription);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
function calculateExecutionMap(keys) {
|
|
118
|
+
const participatingNodeKeys = [];
|
|
119
|
+
const visitedNodes = /* @__PURE__ */ new Set();
|
|
120
|
+
const pendingPulls = new SetMap();
|
|
121
|
+
const refCount = new RefCount();
|
|
122
|
+
const projections = new SetMap();
|
|
123
|
+
function visit(key, insertIndex = 0) {
|
|
124
|
+
refCount.increment(key);
|
|
125
|
+
if (visitedNodes.has(key)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
pendingPulls.use(key, (pulls) => {
|
|
129
|
+
insertIndex = Math.max(...Array.from(pulls).map((key2) => participatingNodeKeys.indexOf(key2))) + 1;
|
|
130
|
+
});
|
|
131
|
+
graph.use(key, (sinkProjections) => {
|
|
132
|
+
sinkProjections.forEach((projection) => {
|
|
133
|
+
if (projection.sources.has(key)) {
|
|
134
|
+
projections.getOrCreate(projection.sink).add(projection);
|
|
135
|
+
visit(projection.sink, insertIndex);
|
|
136
|
+
} else {
|
|
137
|
+
pendingPulls.getOrCreate(projection.sink).add(key);
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
visitedNodes.add(key);
|
|
142
|
+
participatingNodeKeys.splice(insertIndex, 0, key);
|
|
143
|
+
}
|
|
144
|
+
keys.forEach((key) => visit(key));
|
|
145
|
+
return { participatingNodeKeys, pendingPulls, projections, refCount };
|
|
146
|
+
}
|
|
147
|
+
const executionMaps = /* @__PURE__ */ new Map();
|
|
148
|
+
function pubIn(values) {
|
|
149
|
+
var _a;
|
|
150
|
+
const keys = Object.keys(values);
|
|
151
|
+
const executionMapKey = keys.join(",");
|
|
152
|
+
if (!executionMaps.has(executionMapKey)) {
|
|
153
|
+
executionMaps.set(executionMapKey, calculateExecutionMap(keys));
|
|
154
|
+
}
|
|
155
|
+
const map2 = executionMaps.get(executionMapKey);
|
|
156
|
+
const refCount = map2.refCount.clone();
|
|
157
|
+
const participatingNodeKeys = map2.participatingNodeKeys.slice();
|
|
158
|
+
const transientState = new Map(state);
|
|
159
|
+
function nodeWillNotEmit(key) {
|
|
160
|
+
graph.use(key, (projections) => {
|
|
161
|
+
projections.forEach(({ sources, sink }) => {
|
|
162
|
+
if (sources.has(key)) {
|
|
163
|
+
refCount.decrement(sink, () => {
|
|
164
|
+
participatingNodeKeys.splice(participatingNodeKeys.indexOf(sink), 1);
|
|
165
|
+
nodeWillNotEmit(sink);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
let nodeKey;
|
|
172
|
+
while (nodeKey = participatingNodeKeys.shift()) {
|
|
173
|
+
let resolved = false;
|
|
174
|
+
const done = (value) => {
|
|
175
|
+
if (distinctNodes.has(nodeKey) && distinctNodes.get(nodeKey)(state.get(nodeKey), value)) {
|
|
176
|
+
resolved = false;
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
resolved = true;
|
|
180
|
+
transientState.set(nodeKey, value);
|
|
181
|
+
if (state.has(nodeKey)) {
|
|
182
|
+
state.set(nodeKey, value);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
if (Object.prototype.hasOwnProperty.call(values, nodeKey)) {
|
|
186
|
+
done(values[nodeKey]);
|
|
187
|
+
} else {
|
|
188
|
+
map2.projections.use(nodeKey, (nodeProjections) => {
|
|
189
|
+
nodeProjections.forEach((projection) => {
|
|
190
|
+
const args = [...Array.from(projection.sources), ...Array.from(projection.pulls)].map((id) => transientState.get(id));
|
|
191
|
+
projection.map(done)(...args);
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
if (resolved) {
|
|
196
|
+
const value = transientState.get(nodeKey);
|
|
197
|
+
subscriptions.use(nodeKey, (nodeSubscriptions) => {
|
|
198
|
+
nodeSubscriptions.forEach((subscription) => subscription(value));
|
|
199
|
+
});
|
|
200
|
+
(_a = singletonSubscriptions.get(nodeKey)) == null ? void 0 : _a(value);
|
|
201
|
+
} else {
|
|
202
|
+
nodeWillNotEmit(nodeKey);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function nodesToKeySet(nodes) {
|
|
207
|
+
return new Set(nodes.map((s) => s.key));
|
|
208
|
+
}
|
|
209
|
+
function connect({ sources, pulls = [], map: map2, sink: { key: sink } }) {
|
|
210
|
+
const dependency = {
|
|
211
|
+
map: map2,
|
|
212
|
+
pulls: nodesToKeySet(pulls),
|
|
213
|
+
sink,
|
|
214
|
+
sources: nodesToKeySet(sources)
|
|
215
|
+
};
|
|
216
|
+
[...sources, ...pulls].forEach(({ key: sourceKey }) => {
|
|
217
|
+
graph.getOrCreate(sourceKey).add(dependency);
|
|
218
|
+
});
|
|
219
|
+
executionMaps.clear();
|
|
220
|
+
}
|
|
221
|
+
function pub(...args) {
|
|
222
|
+
const map2 = {};
|
|
223
|
+
for (let index = 0; index < args.length; index += 2) {
|
|
224
|
+
const node2 = args[index];
|
|
225
|
+
map2[node2.key] = args[index + 1];
|
|
226
|
+
}
|
|
227
|
+
pubIn(map2);
|
|
228
|
+
}
|
|
229
|
+
function label(newLabels) {
|
|
230
|
+
Object.assign(labels, newLabels);
|
|
231
|
+
}
|
|
232
|
+
function pipe(source, ...operators) {
|
|
233
|
+
for (const operator of operators) {
|
|
234
|
+
source = operator(source);
|
|
235
|
+
}
|
|
236
|
+
return source;
|
|
237
|
+
}
|
|
238
|
+
function spread(source, initialValues) {
|
|
239
|
+
return initialValues.map((initialValue, index) => {
|
|
240
|
+
return tap(node(initialValue, true), (sink) => {
|
|
241
|
+
connect({
|
|
242
|
+
map: (done) => (sourceValue) => {
|
|
243
|
+
done(sourceValue[index]);
|
|
244
|
+
},
|
|
245
|
+
sink,
|
|
246
|
+
sources: [source]
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
function link(source, sink) {
|
|
252
|
+
connect({ map: (done) => (value) => done(value), sink, sources: [source] });
|
|
253
|
+
}
|
|
254
|
+
function derive(source, initial) {
|
|
255
|
+
return tap(node(initial, true), (sink) => {
|
|
256
|
+
connect({ map: (done) => (value) => done(value), sink, sources: [source] });
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
function map(mapFunction) {
|
|
260
|
+
return (source) => {
|
|
261
|
+
const sink = node();
|
|
262
|
+
connect({
|
|
263
|
+
map: (done) => (value) => {
|
|
264
|
+
done(mapFunction(value));
|
|
265
|
+
},
|
|
266
|
+
sink,
|
|
267
|
+
sources: [source]
|
|
268
|
+
});
|
|
269
|
+
return sink;
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
function mapTo(value) {
|
|
273
|
+
return (source) => {
|
|
274
|
+
const sink = node();
|
|
275
|
+
connect({ map: (done) => () => done(value), sink, sources: [source] });
|
|
276
|
+
return sink;
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
function filter(predicate) {
|
|
280
|
+
return (source) => {
|
|
281
|
+
const sink = node();
|
|
282
|
+
connect({ map: (done) => (value) => predicate(value) && done(value), sink, sources: [source] });
|
|
283
|
+
return sink;
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
function once() {
|
|
287
|
+
return (source) => {
|
|
288
|
+
const sink = node();
|
|
289
|
+
let passed = false;
|
|
290
|
+
connect({
|
|
291
|
+
map: (done) => (value) => {
|
|
292
|
+
if (!passed) {
|
|
293
|
+
passed = true;
|
|
294
|
+
done(value);
|
|
295
|
+
}
|
|
296
|
+
},
|
|
297
|
+
sink,
|
|
298
|
+
sources: [source]
|
|
299
|
+
});
|
|
300
|
+
return sink;
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
function scan(accumulator, seed) {
|
|
304
|
+
return (source) => {
|
|
305
|
+
const sink = node();
|
|
306
|
+
connect({ map: (done) => (value) => done(seed = accumulator(seed, value)), sink, sources: [source] });
|
|
307
|
+
return sink;
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function throttleTime(delay) {
|
|
311
|
+
return (source) => {
|
|
312
|
+
const sink = node();
|
|
313
|
+
let currentValue;
|
|
314
|
+
let timeout;
|
|
315
|
+
sub(source, (value) => {
|
|
316
|
+
currentValue = value;
|
|
317
|
+
if (timeout) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
timeout = setTimeout(() => {
|
|
321
|
+
timeout = void 0;
|
|
322
|
+
pub(sink, currentValue);
|
|
323
|
+
}, delay);
|
|
324
|
+
});
|
|
325
|
+
return sink;
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
function delayWithMicrotask() {
|
|
329
|
+
return (source) => {
|
|
330
|
+
const sink = node();
|
|
331
|
+
sub(source, (value) => queueMicrotask(() => pub(sink, value)));
|
|
332
|
+
return sink;
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
function debounceTime(delay) {
|
|
336
|
+
return (source) => {
|
|
337
|
+
const sink = node();
|
|
338
|
+
let currentValue;
|
|
339
|
+
let timeout;
|
|
340
|
+
sub(source, (value) => {
|
|
341
|
+
currentValue = value;
|
|
342
|
+
if (timeout) {
|
|
343
|
+
clearTimeout(timeout);
|
|
344
|
+
}
|
|
345
|
+
timeout = setTimeout(() => {
|
|
346
|
+
pub(sink, currentValue);
|
|
347
|
+
}, delay);
|
|
348
|
+
});
|
|
349
|
+
return sink;
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
function onNext(bufNode) {
|
|
353
|
+
return (source) => {
|
|
354
|
+
const sink = node();
|
|
355
|
+
let pendingValue = NO_VALUE;
|
|
356
|
+
sub(source, (value) => pendingValue = value);
|
|
357
|
+
connect({
|
|
358
|
+
map: (done) => (value) => {
|
|
359
|
+
if (pendingValue !== NO_VALUE) {
|
|
360
|
+
done([pendingValue, value]);
|
|
361
|
+
pendingValue = NO_VALUE;
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
sink,
|
|
365
|
+
sources: [bufNode]
|
|
366
|
+
});
|
|
367
|
+
return sink;
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
function passOnlyAfterNodeHasEmittedBefore(starterNode, durationNode) {
|
|
371
|
+
return (source) => {
|
|
372
|
+
const sink = node();
|
|
373
|
+
let startTime = 0;
|
|
374
|
+
sub(starterNode, () => startTime = Date.now());
|
|
375
|
+
connect({
|
|
376
|
+
map: (done) => (value) => {
|
|
377
|
+
if (Date.now() < startTime + state.get(durationNode.key)) {
|
|
378
|
+
done(value);
|
|
379
|
+
}
|
|
380
|
+
},
|
|
381
|
+
sink,
|
|
382
|
+
sources: [source]
|
|
383
|
+
});
|
|
384
|
+
return sink;
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
function withLatestFrom(...nodes) {
|
|
388
|
+
return (source) => {
|
|
389
|
+
const sink = node();
|
|
390
|
+
connect({
|
|
391
|
+
map: (done) => (...args) => done(args),
|
|
392
|
+
pulls: nodes,
|
|
393
|
+
sink,
|
|
394
|
+
sources: [source]
|
|
395
|
+
});
|
|
396
|
+
return sink;
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function combine(...nodes) {
|
|
400
|
+
const sink = node();
|
|
401
|
+
connect({
|
|
402
|
+
map: (done) => (...args) => done(args),
|
|
403
|
+
sink,
|
|
404
|
+
sources: nodes
|
|
405
|
+
});
|
|
406
|
+
return sink;
|
|
407
|
+
}
|
|
408
|
+
function subKey(key, subscription) {
|
|
409
|
+
return sub(labels[key], subscription);
|
|
410
|
+
}
|
|
411
|
+
function subKeys(keys, subscription) {
|
|
412
|
+
const nodes = keys.map((key) => labels[key]);
|
|
413
|
+
return sub(...nodes.concat(subscription));
|
|
414
|
+
}
|
|
415
|
+
function pubKey(key, value) {
|
|
416
|
+
pubKeys({ [key]: value });
|
|
417
|
+
}
|
|
418
|
+
function pubKeys(values) {
|
|
419
|
+
const valuesWithInternalKeys = Object.entries(values).reduce(
|
|
420
|
+
(acc, [key, value]) => tap(acc, (acc2) => {
|
|
421
|
+
const label2 = labels[key];
|
|
422
|
+
if (!label2) {
|
|
423
|
+
throw new Error(`No label for key ${key}. Do you miss a plugin?`);
|
|
424
|
+
}
|
|
425
|
+
acc2[label2.key] = value;
|
|
426
|
+
return value;
|
|
427
|
+
}),
|
|
428
|
+
{}
|
|
429
|
+
);
|
|
430
|
+
pubIn(valuesWithInternalKeys);
|
|
431
|
+
}
|
|
432
|
+
function getKeyValue(key) {
|
|
433
|
+
return state.get(labels[key].key);
|
|
434
|
+
}
|
|
435
|
+
function getValue(node2) {
|
|
436
|
+
return state.get(node2.key);
|
|
437
|
+
}
|
|
438
|
+
function getKeyValues(keys) {
|
|
439
|
+
return keys.map((key) => {
|
|
440
|
+
const label2 = labels[key];
|
|
441
|
+
if (!label2) {
|
|
442
|
+
throw new Error(`No label for key ${key}. Do you miss a plugin?`);
|
|
443
|
+
}
|
|
444
|
+
return state.get(label2.key);
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
return {
|
|
448
|
+
combine,
|
|
449
|
+
connect,
|
|
450
|
+
derive,
|
|
451
|
+
getKeyValue,
|
|
452
|
+
getValue,
|
|
453
|
+
getKeyValues,
|
|
454
|
+
label,
|
|
455
|
+
labels,
|
|
456
|
+
link,
|
|
457
|
+
node,
|
|
458
|
+
o: {
|
|
459
|
+
delayWithMicrotask,
|
|
460
|
+
debounceTime,
|
|
461
|
+
filter,
|
|
462
|
+
map,
|
|
463
|
+
mapTo,
|
|
464
|
+
onNext,
|
|
465
|
+
scan,
|
|
466
|
+
throttleTime,
|
|
467
|
+
withLatestFrom,
|
|
468
|
+
once,
|
|
469
|
+
passOnlyAfterNodeHasEmittedBefore
|
|
470
|
+
},
|
|
471
|
+
pipe,
|
|
472
|
+
pub,
|
|
473
|
+
pubIn,
|
|
474
|
+
pubKey,
|
|
475
|
+
pubKeys,
|
|
476
|
+
resetSingletonSubs,
|
|
477
|
+
singletonSub,
|
|
478
|
+
singletonSubKey,
|
|
479
|
+
spread,
|
|
480
|
+
sub,
|
|
481
|
+
subKey,
|
|
482
|
+
subKeys
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
export {
|
|
486
|
+
RefCount,
|
|
487
|
+
defaultComparator,
|
|
488
|
+
realm
|
|
489
|
+
};
|