likec4 1.29.1 → 1.31.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/react/index.d.mts CHANGED
@@ -8,9 +8,67 @@ type UnionToIntersection<Union> = (
8
8
  // `Union` into a [distributive conditional
9
9
  // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
10
10
  Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
11
+ type KeysOfUnion<ObjectType> =
12
+ // Hack to fix https://github.com/sindresorhus/type-fest/issues/1008
13
+ keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
14
+ type OptionalKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
15
+ ? (keyof {
16
+ [Key in keyof BaseType as BaseType extends Record<Key, BaseType[Key]> ? never : Key]: never;
17
+ }) & (keyof BaseType) // Intersect with `keyof BaseType` to ensure result of `OptionalKeysOf<BaseType>` is always assignable to `keyof BaseType`
18
+ : never;
19
+ type RequiredKeysOf<BaseType extends object> = BaseType extends unknown // For distributing `BaseType`
20
+ ? Exclude<keyof BaseType, OptionalKeysOf<BaseType>> : never;
21
+ type IsNever<T> = [
22
+ T
23
+ ] extends [
24
+ never
25
+ ] ? true : false;
26
+ type IfNever<T, TypeIfNever = true, TypeIfNotNever = false> = (IsNever<T> extends true ? TypeIfNever : TypeIfNotNever);
27
+ type UnknownArray = readonly unknown[];
28
+ type IsArrayReadonly<T extends UnknownArray> = IfNever<T, false, T extends unknown[] ? false : true>;
29
+ type IfArrayReadonly<T extends UnknownArray, TypeIfArrayReadonly = true, TypeIfNotArrayReadonly = false> = IsArrayReadonly<T> extends infer Result ? Result extends true ? TypeIfArrayReadonly : TypeIfNotArrayReadonly : never;
30
+ type NoInfer$1<T> = T extends infer U ? U : never;
31
+ type IsAny<T> = 0 extends 1 & NoInfer$1<T> ? true : false;
32
+ type IsEqual<A, B> = (<G>() => G extends A & G | G ? 1 : 2) extends (<G>() => G extends B & G | G ? 1 : 2) ? true : false;
11
33
  type Simplify<T> = {
12
34
  [KeyType in keyof T]: T[KeyType];
13
35
  } & {};
36
+ type OmitIndexSignature<ObjectType> = {
37
+ [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? never : KeyType]: ObjectType[KeyType];
38
+ };
39
+ type PickIndexSignature<ObjectType> = {
40
+ [KeyType in keyof ObjectType as {} extends Record<KeyType, unknown> ? KeyType : never]: ObjectType[KeyType];
41
+ };
42
+ type SimpleMerge<Destination, Source> = {
43
+ [Key in keyof Destination as Key extends keyof Source ? never : Key]: Destination[Key];
44
+ } & Source;
45
+ type Merge<Destination, Source> = Simplify<SimpleMerge<PickIndexSignature<Destination>, PickIndexSignature<Source>> & SimpleMerge<OmitIndexSignature<Destination>, OmitIndexSignature<Source>>>;
46
+ type IfAny<T, TypeIfAny = true, TypeIfNotAny = false> = (IsAny<T> extends true ? TypeIfAny : TypeIfNotAny);
47
+ type HomomorphicPick<T, Keys extends KeysOfUnion<T>> = {
48
+ [P in keyof T as Extract<P, Keys>]: T[P];
49
+ };
50
+ type ApplyDefaultOptions<Options extends object, Defaults extends Simplify<Omit<Required<Options>, RequiredKeysOf<Options>> & Partial<Record<RequiredKeysOf<Options>, never>>>, SpecifiedOptions extends Options> = IfAny<SpecifiedOptions, Defaults, IfNever<SpecifiedOptions, Defaults, Simplify<Merge<Defaults, {
51
+ [Key in keyof SpecifiedOptions as Key extends OptionalKeysOf<Options> ? Extract<SpecifiedOptions[Key], undefined> extends never ? Key : never : Key]: SpecifiedOptions[Key];
52
+ }> & Required<Options>> // `& Required<Options>` ensures that `ApplyDefaultOptions<SomeOption, ...>` is always assignable to `Required<SomeOption>`
53
+ >>;
54
+ type Filter<KeyType, ExcludeType> = IsEqual<KeyType, ExcludeType> extends true ? never : (KeyType extends ExcludeType ? never : KeyType);
55
+ type ExceptOptions = {
56
+ /**
57
+ Disallow assigning non-specified properties.
58
+
59
+ Note that any omitted properties in the resulting type will be present in autocomplete as `undefined`.
60
+
61
+ @default false
62
+ */
63
+ requireExactProps?: boolean;
64
+ };
65
+ type DefaultExceptOptions = {
66
+ requireExactProps: false;
67
+ };
68
+ type Except<ObjectType, KeysType extends keyof ObjectType, Options extends ExceptOptions = {}> = _Except<ObjectType, KeysType, ApplyDefaultOptions<ExceptOptions, DefaultExceptOptions, Options>>;
69
+ type _Except<ObjectType, KeysType extends keyof ObjectType, Options extends Required<ExceptOptions>> = {
70
+ [KeyType in keyof ObjectType as Filter<KeyType, KeysType>]: ObjectType[KeyType];
71
+ } & (Options["requireExactProps"] extends true ? Partial<Record<KeysType, never>> : {});
14
72
  type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
15
73
  declare const tag: unique symbol;
16
74
  type TagContainer<Token> = {
@@ -20,6 +78,39 @@ type Tag<Token extends PropertyKey, TagMetadata> = TagContainer<{
20
78
  [K in Token]: TagMetadata;
21
79
  }>;
22
80
  type Tagged<Type, TagName extends PropertyKey, TagMetadata = never> = Type & Tag<TagName, TagMetadata>;
81
+ type SetRequired<BaseType, Keys extends keyof BaseType> = BaseType extends UnknownArray ? SetArrayRequired<BaseType, Keys> extends infer ResultantArray ? IfArrayReadonly<BaseType, Readonly<ResultantArray>, ResultantArray> : never : Simplify<
82
+ // Pick just the keys that are optional from the base type.
83
+ Except<BaseType, Keys> &
84
+ // Pick the keys that should be required from the base type and make them required.
85
+ Required<HomomorphicPick<BaseType, Keys>>>;
86
+ type SetArrayRequired<TArray extends UnknownArray, Keys, Counter extends any[] = [
87
+ ], Accumulator extends UnknownArray = [
88
+ ]> = TArray extends unknown // For distributing `TArray` when it's a union
89
+ ? keyof TArray & `${number}` extends never ? [
90
+ ...Accumulator,
91
+ ...TArray
92
+ ] : TArray extends readonly [
93
+ (infer First)?,
94
+ ...infer Rest
95
+ ] ? "0" extends OptionalKeysOf<TArray> // If the first element of `TArray` is optional
96
+ ? `${Counter["length"]}` extends `${Keys & (string | number)}` // If the current index needs to be required
97
+ ? SetArrayRequired<Rest, Keys, [
98
+ ...Counter,
99
+ any
100
+ ], [
101
+ ...Accumulator,
102
+ First
103
+ ]> : [
104
+ ...Accumulator,
105
+ ...TArray
106
+ ] : SetArrayRequired<Rest, Keys, [
107
+ ...Counter,
108
+ any
109
+ ], [
110
+ ...Accumulator,
111
+ TArray[0]
112
+ ]> : never // Should never happen, since `[(infer F)?, ...infer R]` is a top-type for arrays.
113
+ : never;
23
114
  type TupleToUnion<ArrayType> = ArrayType extends readonly unknown[] ? ArrayType[number] : never;
24
115
  type NonEmptyArray<T> = [
25
116
  T,
@@ -958,7 +1049,7 @@ type NodeDimensionChange = {
958
1049
  type: "dimensions";
959
1050
  dimensions?: Dimensions;
960
1051
  resizing?: boolean;
961
- setAttributes?: boolean;
1052
+ setAttributes?: boolean | "width" | "height";
962
1053
  };
963
1054
  type NodePositionChange = {
964
1055
  id: string;
@@ -2403,6 +2494,146 @@ type ControlsCustomLayoutProps = {
2403
2494
  syncInProgressBadge: ReactNode;
2404
2495
  };
2405
2496
  type ControlsCustomLayout = (props: ControlsCustomLayoutProps) => ReactNode;
2497
+ type NodeProps$2<T extends Record<string, unknown> = {}, NodeType extends string = string> = NodeProps$1<Node$1<Base.NodeData & T, NodeType>>;
2498
+ type ReactFlowNode<Data extends Record<string, unknown>, NodeType extends string> = SetRequired<Node$1<Data, NodeType>, "type" | "initialWidth" | "initialHeight">;
2499
+ type ReactFlowEdge<Data extends Record<string, unknown>, EdgeType extends string> = SetRequired<Edge<Data, EdgeType>, "type" | "data">;
2500
+ declare namespace Base {
2501
+ export type Dimmed = "immediate" | boolean;
2502
+ export type NodeData = {
2503
+ /**
2504
+ * Whether the cursor is hovering over the node
2505
+ */
2506
+ hovered?: boolean;
2507
+ /**
2508
+ * Whether the node is dimmed
2509
+ * 'immediate' means that the node is dimmed without delay
2510
+ */
2511
+ dimmed?: Dimmed;
2512
+ };
2513
+ export type Node = Node$1<NodeData>;
2514
+ export type NodeProps = NodeProps$1<Node$1<Base.NodeData, any>>;
2515
+ export type EdgeData = {
2516
+ /**
2517
+ * Whether the cursor is hovering over the edge
2518
+ */
2519
+ hovered?: boolean;
2520
+ /**
2521
+ * Whether the edge is active (animated and highlighted)
2522
+ */
2523
+ active?: boolean;
2524
+ /**
2525
+ * Whether the edge is dimmed
2526
+ * 'immediate' means that the edge is dimmed without delay
2527
+ */
2528
+ dimmed?: Dimmed;
2529
+ };
2530
+ export type Edge = SetRequired<Edge<EdgeData>, "data">;
2531
+ type WithDimmed = {
2532
+ data: {
2533
+ dimmed?: Dimmed;
2534
+ };
2535
+ };
2536
+ type WithHovered = {
2537
+ data: {
2538
+ hovered?: boolean;
2539
+ };
2540
+ };
2541
+ export function setDimmed<T extends WithDimmed>(value: T, dimmed: "immediate" | boolean): T;
2542
+ export function setDimmed(dimmed: "immediate" | boolean): <T extends WithDimmed>(value: T) => T;
2543
+ export function setHovered<T extends WithHovered>(value: T, hovered: boolean): T;
2544
+ export function setHovered(hovered: boolean): <T extends WithHovered>(value: T) => T;
2545
+ type WithData<D> = {
2546
+ data: D;
2547
+ };
2548
+ export function setData<E extends WithData<any>>(value: E, state: Partial<E["data"]>): E;
2549
+ export function setData<E extends WithData<any>>(state: Partial<E["data"]>): (value: E) => E;
2550
+ export {};
2551
+ }
2552
+ type NonOptional<T extends object> = Simplify<{
2553
+ [P in Exclude<keyof T, OptionalKeysOf<T>>]: T[P];
2554
+ } & {
2555
+ [P in OptionalKeysOf<T>]-?: T[P] | undefined;
2556
+ }>;
2557
+ declare namespace Types {
2558
+ type LeafNodeData = Base.NodeData & NonOptional<Pick<DiagramNode, "id" | "title" | "technology" | "description" | "color" | "shape" | "width" | "level" | "height" | "style" | "position">> & {
2559
+ /**
2560
+ * View this node belongs to
2561
+ */
2562
+ viewId: ViewId;
2563
+ isMultiple?: boolean | undefined;
2564
+ icon: string | null;
2565
+ };
2566
+ /**
2567
+ * Represents element from logical model
2568
+ */
2569
+ type ElementNodeData = LeafNodeData & {
2570
+ modelFqn: Fqn;
2571
+ deploymentFqn?: never;
2572
+ /**
2573
+ * If set - this node has navigation to another view and diagram has handler for this
2574
+ */
2575
+ navigateTo: ViewId | null;
2576
+ };
2577
+ /**
2578
+ * Represents element from deployment model
2579
+ */
2580
+ type DeploymentElementNodeData = LeafNodeData & {
2581
+ navigateTo: ViewId | null;
2582
+ deploymentFqn: Fqn;
2583
+ modelFqn: Fqn | null;
2584
+ };
2585
+ type CompoundNodeData = Base.NodeData & NonOptional<Pick<DiagramNode, "id" | "title" | "color" | "shape" | "style" | "position">> & {
2586
+ /**
2587
+ * View this node belongs to
2588
+ */
2589
+ viewId: ViewId;
2590
+ depth: number;
2591
+ icon?: IconUrl;
2592
+ };
2593
+ type CompoundElementNodeData = CompoundNodeData & {
2594
+ modelFqn: Fqn;
2595
+ deploymentFqn?: never;
2596
+ /**
2597
+ * If set - this node has navigation to another view and diagram has handler for this
2598
+ */
2599
+ navigateTo: ViewId | null;
2600
+ };
2601
+ type CompoundDeploymentNodeData = CompoundNodeData & {
2602
+ deploymentFqn: Fqn;
2603
+ /**
2604
+ * If set - this node refers to a model element
2605
+ */
2606
+ modelFqn: Fqn | null;
2607
+ /**
2608
+ * If set - this node has navigation to another view and diagram has handler for this
2609
+ */
2610
+ navigateTo: ViewId | null;
2611
+ };
2612
+ type ViewGroupNodeData = CompoundNodeData & {
2613
+ isViewGroup: true;
2614
+ };
2615
+ type ElementNode = ReactFlowNode<ElementNodeData, "element">;
2616
+ type DeploymentElementNode = ReactFlowNode<DeploymentElementNodeData, "deployment">;
2617
+ type CompoundElementNode = ReactFlowNode<CompoundElementNodeData, "compound-element">;
2618
+ type CompoundDeploymentNode = ReactFlowNode<CompoundDeploymentNodeData, "compound-deployment">;
2619
+ type ViewGroupNode = ReactFlowNode<ViewGroupNodeData, "view-group">;
2620
+ type Node = ElementNode | DeploymentElementNode | CompoundElementNode | CompoundDeploymentNode | ViewGroupNode;
2621
+ type NodeData = Node["data"];
2622
+ type RelationshipEdgeData = Simplify<Base.EdgeData & NonOptional<Pick<DiagramEdge, "id" | "label" | "labelBBox" | "technology" | "points" | "dir" | "color" | "line" | "head" | "tail" | "navigateTo" | "notes">> & {
2623
+ labelXY: XYPosition | null;
2624
+ controlPoints: XYPosition[] | undefined | null;
2625
+ }>;
2626
+ type RelationshipEdge = ReactFlowEdge<RelationshipEdgeData, "relationship">;
2627
+ type Edge = RelationshipEdge;
2628
+ type EdgeData = RelationshipEdgeData;
2629
+ }
2630
+ interface CustomNodes {
2631
+ element?: undefined | ((props: NodeProps$2<Types.ElementNodeData, "element">) => ReactNode);
2632
+ deployment?: undefined | ((props: NodeProps$2<Types.DeploymentElementNodeData, "deployment">) => ReactNode);
2633
+ compoundElement?: undefined | ((props: NodeProps$2<Types.CompoundElementNodeData, "compound-element">) => ReactNode);
2634
+ compoundDeployment?: undefined | ((props: NodeProps$2<Types.CompoundDeploymentNodeData, "compound-deployment">) => ReactNode);
2635
+ viewGroup?: undefined | ((props: NodeProps$2<Types.ViewGroupNodeData, "view-group">) => ReactNode);
2636
+ }
2406
2637
  type DiagramNodeWithNavigate<ID = ViewId> = Omit<DiagramNode, "navigateTo"> & {
2407
2638
  navigateTo: ID;
2408
2639
  };
@@ -2413,7 +2644,7 @@ type ElementIconRendererProps = {
2413
2644
  icon?: string | null | undefined;
2414
2645
  };
2415
2646
  };
2416
- type ElementIconRenderer = (props: ElementIconRendererProps) => ReactNode;
2647
+ export type ElementIconRenderer = (props: ElementIconRendererProps) => ReactNode;
2417
2648
  type OnNavigateTo<ID = ViewId> = (to: ID, event?: ReactMouseEvent, element?: DiagramNodeWithNavigate<ID>) => void;
2418
2649
  type OnNodeClick = (node: DiagramNode, event: ReactMouseEvent) => void;
2419
2650
  type OnEdgeClick = (edge: DiagramEdge, event: ReactMouseEvent) => void;
@@ -2540,6 +2771,10 @@ interface LikeC4DiagramProperties {
2540
2771
  * Customize layout of the controls on the top left
2541
2772
  */
2542
2773
  renderControls?: ControlsCustomLayout | undefined;
2774
+ /**
2775
+ * Override node renderers
2776
+ */
2777
+ renderNodes?: CustomNodes | undefined;
2543
2778
  /**
2544
2779
  * Dynamic filter, applies both to nodes and edges
2545
2780
  */
@@ -2694,6 +2929,10 @@ export interface LikeC4ViewProps<ViewId = string, Tag = string, Kind = string> {
2694
2929
  mantineTheme?: any;
2695
2930
  /** Function to generate nonce attribute added to all generated `<style />` tags */
2696
2931
  styleNonce?: string | (() => string) | undefined;
2932
+ /**
2933
+ * Override node renderers
2934
+ */
2935
+ renderNodes?: CustomNodes | undefined;
2697
2936
  /**
2698
2937
  * Render custom icon for a node
2699
2938
  * By default, if icon is http:// or https://, it will be rendered as an image
@@ -2819,6 +3058,9 @@ type LikeC4ModelProviderProps = PropsWithChildren<{
2819
3058
  likec4model: any;
2820
3059
  }>;
2821
3060
  export declare const LikeC4ModelProvider: (props: LikeC4ModelProviderProps) => JSX.Element;
3061
+ export declare const ViewNotFound: ({ viewId }: {
3062
+ viewId: string;
3063
+ }) => import("react/jsx-runtime").JSX.Element;
2822
3064
  type AllKeys<T> = T extends any ? keyof T : never;
2823
3065
  type Primitive$1 = boolean | number | string;
2824
3066
  type ReadonlyIfObject<Value> = Value extends undefined ? Value : Value extends (...args: any) => any ? Value : Value extends Primitive$1 ? Value : Value extends object ? Readonly<Value> : Value;
@@ -3036,6 +3278,27 @@ interface Computed {
3036
3278
  ], cb: (...values: StoreValues<OriginStores>) => Task<Value> | Value): ReadableAtom<Value>;
3037
3279
  }
3038
3280
  declare const computed: Computed;
3281
+ interface Batched {
3282
+ <Value, OriginStore extends Store>(stores: OriginStore, cb: (value: StoreValue<OriginStore>) => Task<Value> | Value): ReadableAtom<Value>;
3283
+ /**
3284
+ * Create derived store, which use generates value from another stores.
3285
+ *
3286
+ * ```js
3287
+ * import { batched } from 'nanostores'
3288
+ *
3289
+ * const $sortBy = atom('id')
3290
+ * const $category = atom('')
3291
+ *
3292
+ * export const $link = batched([$sortBy, $category], (sortBy, category) => {
3293
+ * return `/api/entities?sortBy=${sortBy}&category=${category}`
3294
+ * })
3295
+ * ```
3296
+ */
3297
+ <Value, OriginStores extends AnyStore[]>(stores: [
3298
+ ...OriginStores
3299
+ ], cb: (...values: StoreValues<OriginStores>) => Task<Value> | Value): ReadableAtom<Value>;
3300
+ }
3301
+ declare const batched: Batched;
3039
3302
  type StoreKeys<T> = T extends {
3040
3303
  setKey: (k: infer K, v: any) => unknown;
3041
3304
  } ? K : never;
@@ -3056,7 +3319,7 @@ declare function useStore<SomeStore extends Store>(store: SomeStore, options?: U
3056
3319
  export declare const createHooksForModel: ($atom: WritableAtom) => any;
3057
3320
 
3058
3321
  declare namespace nano {
3059
- export { Atom, WritableAtom, atom, computed, map, useStore };
3322
+ export { Atom, WritableAtom, atom, batched, computed, map, useStore };
3060
3323
  }
3061
3324
 
3062
3325
  export {