@cratis/scene 0.105.6

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 (42) hide show
  1. package/README.md +96 -0
  2. package/dist/AnchorEdges.d.ts +11 -0
  3. package/dist/CategoryAttribute.d.ts +9 -0
  4. package/dist/Component.d.ts +38 -0
  5. package/dist/ComponentLibraryAttribute.d.ts +9 -0
  6. package/dist/ContentControl.d.ts +11 -0
  7. package/dist/Control.d.ts +43 -0
  8. package/dist/ExternalComponent.d.ts +15 -0
  9. package/dist/FrameworkElement.d.ts +41 -0
  10. package/dist/IComponent.d.ts +52 -0
  11. package/dist/IPrototypeComponentDiscovery.d.ts +2 -0
  12. package/dist/IUIElement.d.ts +5 -0
  13. package/dist/ItemsControl.d.ts +16 -0
  14. package/dist/Layout/HorizontalAlignment.d.ts +9 -0
  15. package/dist/Layout/PrototypeLayout.d.ts +9 -0
  16. package/dist/Layout/Thickness.d.ts +21 -0
  17. package/dist/Layout/VerticalAlignment.d.ts +9 -0
  18. package/dist/Layout/Visibility.d.ts +8 -0
  19. package/dist/Panel.d.ts +15 -0
  20. package/dist/Position.d.ts +4 -0
  21. package/dist/PrototypeComponentDiscovery.d.ts +22 -0
  22. package/dist/PrototypeComponentRegistry-FLUzIk5a.js +148 -0
  23. package/dist/PrototypeComponentRegistry.d.ts +28 -0
  24. package/dist/Prototypes/Editor/editorTypes.d.ts +35 -0
  25. package/dist/Prototypes/Rendering/PrototypeThumbnail.d.ts +21 -0
  26. package/dist/Prototypes/Rendering/SceneMessages.d.ts +6 -0
  27. package/dist/Prototypes/Rendering/SceneMessagesContext.d.ts +3 -0
  28. package/dist/Prototypes/Rendering/SceneMessagesProvider.d.ts +7 -0
  29. package/dist/Prototypes/Rendering/TrafficLights.d.ts +9 -0
  30. package/dist/Prototypes/Rendering/defaultSceneMessages.d.ts +2 -0
  31. package/dist/Prototypes/Rendering/index.d.ts +6 -0
  32. package/dist/Prototypes/index.d.ts +2 -0
  33. package/dist/Prototypes/index.js +151 -0
  34. package/dist/ResizeBevhavior.d.ts +1 -0
  35. package/dist/SceneObject.d.ts +14 -0
  36. package/dist/Size.d.ts +4 -0
  37. package/dist/UIElement.d.ts +36 -0
  38. package/dist/WellKnownCategories.d.ts +20 -0
  39. package/dist/index.d.ts +23 -0
  40. package/dist/index.js +261 -0
  41. package/dist/scene.css +2 -0
  42. package/package.json +76 -0
package/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # Scene
2
+
3
+ TypeScript models for the Studio's low-code canvas: UIElement hierarchy, ExternalComponent, and the prototype surface component system.
4
+
5
+ ## Serialized prototype previews
6
+
7
+ `PrototypeThumbnail` accepts both live `IComponent` instances and raw `UIElement` data from JSON documents. At render time Scene uses the element's library-qualified `_derivedTypeId` (or `componentName`) to construct a registered component and copy its saved state, recursively hydrating element arrays in all named slots without changing the source document. Without a registered library, it renders a positioned, sized placeholder rather than an empty prototype. Library registration does not trigger a React rerender by itself; rerender the thumbnail after loading bundles to replace placeholders with actual components. Without an open action the thumbnail is a named, non-focusable preview; with one it remains an editor-opening button. The board/document reader does not load bundles or depend on Studio Core.
8
+
9
+ ## Component class — how it works
10
+
11
+ `Component` (in `Component.ts`) is the abstract base class for every prototype surface component (e.g. the 89 PrimeReact wrappers under `Source/PrimeReact/`). It extends `ExternalComponent` so instances are proper `UIElement` subtypes that flow through the command pipeline without any manual wire-format conversion.
12
+
13
+ ### Why extends ExternalComponent?
14
+
15
+ Commands that carry elements use `UIElement[]` as their type on both the C# and TypeScript sides. Before this design, `Component` was a separate class that implemented `IComponent` and had to be converted to a wire-format plain object before assignment (`toWireElement`). That conversion was a callsite smell that hid serialization failures and required every consumer to know about it.
16
+
17
+ Now `Component extends ExternalComponent implements IComponent`. An `InputText` instance IS a `UIElement` — pass it directly:
18
+
19
+ ```ts
20
+ command.elements = updatedElements as unknown as typeof command.elements;
21
+ ```
22
+
23
+ The `as unknown as` cast is still needed because TypeScript sees `UIElement[]` (with `id: Guid`) while the editor's `PrototypeSurfaceElement` type has `id: string`. The runtime values are correct; only the declared types diverge at this boundary.
24
+
25
+ ### How serialization works
26
+
27
+ The Fundamentals `JsonSerializer` walks `Object.getOwnPropertyNames(instance)` and serializes each own property. The design of `Component` ensures only JSON-safe values appear as own properties:
28
+
29
+ | What | Own property? | Why |
30
+ |---|---|---|
31
+ | `id` | Yes — string accessor via `Object.defineProperty` | C# `System.Text.Json` parses a UUID string as `Guid` automatically |
32
+ | `ZIndex`, `anchoring`, `width`, `height`, `name`, `properties`, `slots`, `componentName` | Yes — class fields set in `initialize()` | All are plain values; safely serialized |
33
+ | `_derivedTypeId` | Yes — set explicitly in `initialize()` | Tells Fundamentals to deserialize as `ExternalComponent` on the server |
34
+ | `toolbarIcon` | **No** — prototype getter | React-icons components are regular functions with a `prototype.constructor` self-reference; serializing them causes infinite recursion. Being a prototype getter keeps them out of `Object.getOwnPropertyNames` entirely |
35
+ | `RenderPrototype` | No — abstract prototype method | Same reason; a method on the prototype is never an own property of the instance |
36
+ | `label`, `position`, `size`, `children`, `type` | No — prototype getters | Computed bridges; not serializable data |
37
+
38
+ ### The id bridge
39
+
40
+ `SceneObject` declares `id: Guid` (via `@field(Guid)`). `IComponent` declares `id: string`. The constructor replaces the class-field own property with a plain-string accessor:
41
+
42
+ ```ts
43
+ let _id = '';
44
+ Object.defineProperty(this, 'id', {
45
+ get() { return _id; },
46
+ set(value: string) { _id = String(value ?? ''); },
47
+ enumerable: true,
48
+ configurable: true,
49
+ });
50
+ ```
51
+
52
+ The serializer reads the string UUID; C# parses it as `Guid`. Editor code that compares IDs uses `string` equality throughout.
53
+
54
+ ### The `_derivedTypeId` own property
55
+
56
+ `DerivedType.get(constructor)` uses `Reflect.getOwnMetadata`, which does **not** traverse the prototype chain. The `@derivedType('externalComponent')` decorator is on `ExternalComponent`, so `DerivedType.get(InputText)` returns `undefined`. Without the explicit own property the JSON output would have no `_derivedTypeId` and the C# deserializer would not know to construct an `ExternalComponent`.
57
+
58
+ `initialize()` sets it directly:
59
+
60
+ ```ts
61
+ (this as unknown as Record<string, unknown>)['_derivedTypeId'] = 'externalComponent';
62
+ ```
63
+
64
+ ### The type key
65
+
66
+ After `initialize()`, `componentName` is updated to the full library-qualified key (`'PrimeReact.InputText'`). Before `initialize()` the subclass class field holds the short name (`'InputText'`). The `type` getter always returns the fully qualified key by splitting on `.` and re-joining with `library`:
67
+
68
+ ```ts
69
+ get type(): string {
70
+ const cn = this.componentName ?? '';
71
+ const shortName = cn.split('.').pop() ?? cn;
72
+ return this.library ? `${this.library}.${shortName}` : shortName;
73
+ }
74
+ ```
75
+
76
+ ### Subclass authoring
77
+
78
+ Implement these members:
79
+
80
+ ```ts
81
+ export default class InputText extends Component {
82
+ readonly componentName = 'InputText'; // short name; initialize() stores the full key
83
+ readonly category = 'Form';
84
+ readonly library = 'PrimeReact';
85
+ readonly initialSize = { width: 220, height: 42 };
86
+ readonly resizeBehavior = 'horizontal' as const;
87
+
88
+ // MUST be a getter — not a class field.
89
+ // Class fields are own instance properties and cause infinite recursion in Fundamentals' serializer.
90
+ override get toolbarIcon() { return FaKeyboard; }
91
+
92
+ RenderPrototype({ label }: PrototypeComponentRenderProps): ReactNode { ... }
93
+ }
94
+ ```
95
+
96
+ `toolbarIcon` **must** be an `override get`. A class field (`readonly toolbarIcon = FaKeyboard`) makes `FaKeyboard` an own instance property. Fundamentals' serializer then calls `Object.getOwnPropertyNames(FaKeyboard)` which includes `prototype`, whose `constructor` points back to `FaKeyboard`, causing unbounded recursion and a `RangeError`.
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Represents the edges of a UI element to which it is anchored. Multiple edges can be combined using bitwise operations.
3
+ */
4
+ export declare enum AnchorEdges {
5
+ none = 0,
6
+ top = 1,
7
+ right = 2,
8
+ bottom = 4,
9
+ left = 8
10
+ }
11
+ export declare const allAnchorEdges: number;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Declares the category a type belongs to. Categories group components in the Low Code environment — mirroring how component libraries such as PrimeReact and Cratis Components organise their documentation — so that tools can present palettes and pickers in a familiar structure.
3
+ */
4
+ export declare class CategoryAttribute {
5
+ /**
6
+ * Gets the name of the category.
7
+ */
8
+ name: string;
9
+ }
@@ -0,0 +1,38 @@
1
+ import { ExternalComponent } from './ExternalComponent';
2
+ import type { ComponentState, IComponent, PrototypeComponentRenderProps } from './IComponent';
3
+ import type { ComponentType, ReactNode } from 'react';
4
+ import type { Position } from './Position';
5
+ import type { Size } from './Size';
6
+ /**
7
+ * Abstract base class for all prototype surface components.
8
+ * Extends ExternalComponent so instances are proper UIElement subtypes serializable
9
+ * by Fundamentals without any manual wire-format conversion.
10
+ */
11
+ export declare abstract class Component extends ExternalComponent implements IComponent {
12
+ id: string;
13
+ readonly initialSize: Size;
14
+ readonly resizeBehavior: IComponent['resizeBehavior'];
15
+ readonly acceptsChildren: boolean;
16
+ abstract readonly category: string;
17
+ abstract readonly library: string;
18
+ /**
19
+ * Icon shown in the editor toolbar. Declared as an abstract getter so implementations
20
+ * land on the prototype — NOT as an own instance property. Own function-valued properties
21
+ * cause infinite recursion in the Fundamentals serializer.
22
+ */
23
+ abstract get toolbarIcon(): ComponentType<{
24
+ className?: string;
25
+ }> | undefined;
26
+ constructor();
27
+ get label(): string;
28
+ set label(value: string);
29
+ get position(): Position;
30
+ set position(value: Position);
31
+ get size(): Size;
32
+ set size(value: Size);
33
+ get children(): IComponent[];
34
+ set children(value: IComponent[]);
35
+ get type(): string;
36
+ abstract RenderPrototype(props: PrototypeComponentRenderProps): ReactNode;
37
+ initialize(state: Partial<ComponentState>): this;
38
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Declares the name of the component library assembly. Applied at the assembly level, this attribute identifies which component library (e.g., PrimeReact, Cratis Components) a project represents, enabling tools to discover and display components from known libraries.
3
+ */
4
+ export declare class ComponentLibraryAttribute {
5
+ /**
6
+ * Gets the name of the component library.
7
+ */
8
+ name: string;
9
+ }
@@ -0,0 +1,11 @@
1
+ import { Control } from './Control';
2
+ import { UIElement } from './UIElement';
3
+ /**
4
+ * Represents a {@link Control} that contains a single piece of content. This is the XAML-style base for components that display one child element, such as buttons, cards and framed containers.
5
+ */
6
+ export declare class ContentControl extends Control {
7
+ /**
8
+ * Gets or sets the content of the control.
9
+ */
10
+ content?: UIElement;
11
+ }
@@ -0,0 +1,43 @@
1
+ import { FrameworkElement } from './FrameworkElement';
2
+ import { Thickness } from './Layout/Thickness';
3
+ /**
4
+ * Represents the base class for an interactive control. A {@link Control} adds the appearance surface — colors, padding, border and typography — used by most components.
5
+ */
6
+ export declare class Control extends FrameworkElement {
7
+ /**
8
+ * Gets or sets the background color of the control.
9
+ */
10
+ background?: string;
11
+ /**
12
+ * Gets or sets the foreground (typically text) color of the control.
13
+ */
14
+ foreground?: string;
15
+ /**
16
+ * Gets or sets the border color of the control.
17
+ */
18
+ borderBrush?: string;
19
+ /**
20
+ * Gets or sets the thickness of the control's border.
21
+ */
22
+ borderThickness: Thickness;
23
+ /**
24
+ * Gets or sets the inner padding of the control.
25
+ */
26
+ padding: Thickness;
27
+ /**
28
+ * Gets or sets the font family of any text rendered by the control.
29
+ */
30
+ fontFamily?: string;
31
+ /**
32
+ * Gets or sets the font size of any text rendered by the control.
33
+ */
34
+ fontSize?: number;
35
+ /**
36
+ * Gets or sets the font weight of any text rendered by the control.
37
+ */
38
+ fontWeight?: string;
39
+ /**
40
+ * Gets or sets the tab index of the control, controlling focus order.
41
+ */
42
+ tabIndex: number;
43
+ }
@@ -0,0 +1,15 @@
1
+ import { FrameworkElement } from './FrameworkElement';
2
+ import { UIElement } from './UIElement';
3
+ /**
4
+ * Represents an external component that is not modelled by a dedicated Scene type. This is the primary extension point used by the Low Code environment to represent components sourced from libraries such as PrimeReact or Cratis Components.
5
+ */
6
+ export declare class ExternalComponent extends FrameworkElement {
7
+ /**
8
+ * Gets or sets the {@link ComponentName} identifying the component.
9
+ */
10
+ componentName: string;
11
+ /**
12
+ * Gets the named slots of the component. Each slot is a named projection of child elements — the analogue of named template regions such as PrimeReact's `header`, `footer` or `item` templates.
13
+ */
14
+ slots: Record<string, UIElement[]>;
15
+ }
@@ -0,0 +1,41 @@
1
+ import { HorizontalAlignment } from './Layout/HorizontalAlignment';
2
+ import { Thickness } from './Layout/Thickness';
3
+ import { UIElement } from './UIElement';
4
+ import { VerticalAlignment } from './Layout/VerticalAlignment';
5
+ /**
6
+ * Represents an element that participates in layout. A {@link FrameworkElement} adds sizing, alignment, margin and naming capabilities on top of {@link UIElement}.
7
+ */
8
+ export declare class FrameworkElement extends UIElement {
9
+ /**
10
+ * Gets or sets the design-time name of the element. This is the analogue of XAML's `x:Name` and is used by the Low Code environment to refer to the element.
11
+ */
12
+ name?: string;
13
+ /**
14
+ * Gets or sets the minimum width of the element.
15
+ */
16
+ minWidth: number;
17
+ /**
18
+ * Gets or sets the maximum width of the element.
19
+ */
20
+ maxWidth: number;
21
+ /**
22
+ * Gets or sets the minimum height of the element.
23
+ */
24
+ minHeight: number;
25
+ /**
26
+ * Gets or sets the maximum height of the element.
27
+ */
28
+ maxHeight: number;
29
+ /**
30
+ * Gets or sets the outer margin of the element.
31
+ */
32
+ margin: Thickness;
33
+ /**
34
+ * Gets or sets the horizontal alignment within the layout slot allocated by the parent.
35
+ */
36
+ horizontalAlignment: HorizontalAlignment;
37
+ /**
38
+ * Gets or sets the vertical alignment within the layout slot allocated by the parent.
39
+ */
40
+ verticalAlignment: VerticalAlignment;
41
+ }
@@ -0,0 +1,52 @@
1
+ import type { ComponentType, ReactNode } from 'react';
2
+ import type { AnchorEdges } from './AnchorEdges';
3
+ import type { Position } from './Position';
4
+ import type { ResizeBevhavior } from './ResizeBevhavior';
5
+ import type { Size } from './Size';
6
+ export interface PrototypeComponentRenderProps {
7
+ component: IComponent;
8
+ label: string;
9
+ /** Whether the component is currently being hovered by a dragged item. */
10
+ isDragOver?: boolean;
11
+ }
12
+ export interface ComponentState {
13
+ id: string;
14
+ label: string;
15
+ position: Position;
16
+ size: Size;
17
+ ZIndex: number;
18
+ anchoring: AnchorEdges;
19
+ children?: IComponent[];
20
+ }
21
+ export interface IComponent {
22
+ id: string;
23
+ label: string;
24
+ position: Position;
25
+ size: Size;
26
+ /** Stack order — matches the backend PrototypeElement.ZIndex field name. */
27
+ ZIndex: number;
28
+ /** Anchor edges bitmask — matches the backend PrototypeElement.anchoring field name. */
29
+ anchoring: AnchorEdges;
30
+ /** The component type name within its library (e.g. "Button"). */
31
+ readonly componentName: string;
32
+ readonly type: string;
33
+ readonly category?: string;
34
+ readonly library?: string;
35
+ /** Icon displayed in the editor toolbar for this component type. */
36
+ readonly toolbarIcon?: ComponentType<{
37
+ className?: string;
38
+ }>;
39
+ readonly initialSize?: {
40
+ width: number;
41
+ height: number;
42
+ };
43
+ readonly resizeBehavior?: ResizeBevhavior;
44
+ /** When true, this component acts as a drop target and can receive child components. */
45
+ readonly acceptsChildren?: boolean;
46
+ /** Child components dropped into this component. Positions are relative to this component's top-left. */
47
+ children?: IComponent[];
48
+ RenderPrototype(props: PrototypeComponentRenderProps): ReactNode;
49
+ }
50
+ export interface PrototypeComponentConstructor {
51
+ new (): IComponent;
52
+ }
@@ -0,0 +1,2 @@
1
+ export declare class IPrototypeComponentDiscovery {
2
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Marker interface implemented by {@link UIElement} and used as the DerivedType target for all concrete visual element types so that polymorphic UIElement collections can be serialized and deserialized correctly.
3
+ */
4
+ export declare class IUIElement {
5
+ }
@@ -0,0 +1,16 @@
1
+ import { Control } from './Control';
2
+ import { Panel } from './Panel';
3
+ import { UIElement } from './UIElement';
4
+ /**
5
+ * Represents a {@link Control} that presents a collection of items. This is the XAML-style base for components that display a variable list of children, such as lists, tables, menus and selectors.
6
+ */
7
+ export declare class ItemsControl extends Control {
8
+ /**
9
+ * Gets the collection of items displayed by the control.
10
+ */
11
+ items: UIElement[];
12
+ /**
13
+ * Gets or sets the panel used to lay out {@link Items}. When `null` the control's default items panel is used.
14
+ */
15
+ itemsPanel?: Panel;
16
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Describes how an element is horizontally positioned or stretched within a parent's allocated layout slot.
3
+ */
4
+ export declare enum HorizontalAlignment {
5
+ left = 0,
6
+ center = 1,
7
+ right = 2,
8
+ stretch = 3
9
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Describes how a prototype surface arranges the elements placed on it.
3
+ */
4
+ export declare enum PrototypeLayout {
5
+ absolute = 0,
6
+ flexRow = 1,
7
+ flexColumn = 2,
8
+ grid = 3
9
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Describes the thickness of a frame around a rectangle.
3
+ */
4
+ export declare class Thickness {
5
+ /**
6
+ * The thickness of the left edge.
7
+ */
8
+ left: number;
9
+ /**
10
+ * The thickness of the top edge.
11
+ */
12
+ top: number;
13
+ /**
14
+ * The thickness of the right edge.
15
+ */
16
+ right: number;
17
+ /**
18
+ * The thickness of the bottom edge.
19
+ */
20
+ bottom: number;
21
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Describes how an element is vertically positioned or stretched within a parent's allocated layout slot.
3
+ */
4
+ export declare enum VerticalAlignment {
5
+ top = 0,
6
+ center = 1,
7
+ bottom = 2,
8
+ stretch = 3
9
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Describes the visibility of a {@link UIElement}.
3
+ */
4
+ export declare enum Visibility {
5
+ visible = 0,
6
+ hidden = 1,
7
+ collapsed = 2
8
+ }
@@ -0,0 +1,15 @@
1
+ import { FrameworkElement } from './FrameworkElement';
2
+ import { UIElement } from './UIElement';
3
+ /**
4
+ * Represents the abstract base for components that lay out a collection of {@link UIElement} children. Panels are the primary visual layout primitive in the Scene object model.
5
+ */
6
+ export declare class Panel extends FrameworkElement {
7
+ /**
8
+ * Gets the child elements of the panel.
9
+ */
10
+ children: UIElement[];
11
+ /**
12
+ * Gets or sets the background color of the panel.
13
+ */
14
+ background?: string;
15
+ }
@@ -0,0 +1,4 @@
1
+ export interface Position {
2
+ x: number;
3
+ y: number;
4
+ }
@@ -0,0 +1,22 @@
1
+ export declare class PrototypeComponentDescriptor {
2
+ name: string;
3
+ namespace: string;
4
+ category: string;
5
+ library: string;
6
+ bundlePath: string;
7
+ type: string;
8
+ }
9
+ /**
10
+ * Represents an implementation of {@link IPrototypeComponentDiscovery} that scans loaded assemblies for {@link ComponentLibraryAttribute}-decorated component libraries via reflection.
11
+ */
12
+ export declare class PrototypeComponentDiscovery {
13
+ }
14
+ export declare class PrototypeComponentCategoryDescriptor {
15
+ name: string;
16
+ components: PrototypeComponentDescriptor[];
17
+ }
18
+ export declare class PrototypeComponentLibraryDescriptor {
19
+ name: string;
20
+ bundlePath: string;
21
+ categories: PrototypeComponentCategoryDescriptor[];
22
+ }
@@ -0,0 +1,148 @@
1
+ import { DerivedType as v, Guid as y, field as d } from "@cratis/fundamentals";
2
+ function a(e, o) {
3
+ if (typeof Reflect == "object" && typeof Reflect.metadata == "function") return Reflect.metadata(e, o);
4
+ }
5
+ function p(e, o, t, n) {
6
+ var r = arguments.length, i = r < 3 ? o : n === null ? n = Object.getOwnPropertyDescriptor(o, t) : n, c;
7
+ if (typeof Reflect == "object" && typeof Reflect.decorate == "function") i = Reflect.decorate(e, o, t, n);
8
+ else for (var s = e.length - 1; s >= 0; s--) (c = e[s]) && (i = (r < 3 ? c(i) : r > 3 ? c(o, t, i) : c(o, t)) || i);
9
+ return r > 3 && i && Object.defineProperty(o, t, i), i;
10
+ }
11
+ var O = /* @__PURE__ */ (function(e) {
12
+ return e[e.none = 0] = "none", e[e.top = 1] = "top", e[e.right = 2] = "right", e[e.bottom = 4] = "bottom", e[e.left = 8] = "left", e;
13
+ })({}), T = 15, b = class {
14
+ id;
15
+ properties;
16
+ };
17
+ p([d(y), a("design:type", typeof y > "u" ? Object : y)], b.prototype, "id", void 0);
18
+ p([d(Object), a("design:type", typeof Record > "u" ? Object : Record)], b.prototype, "properties", void 0);
19
+ var j = /* @__PURE__ */ (function(e) {
20
+ return e[e.visible = 0] = "visible", e[e.hidden = 1] = "hidden", e[e.collapsed = 2] = "collapsed", e;
21
+ })({}), u = class extends b {
22
+ visibility;
23
+ isEnabled;
24
+ opacity;
25
+ width;
26
+ height;
27
+ ZIndex;
28
+ anchoring;
29
+ };
30
+ p([d(Number), a("design:type", typeof j > "u" ? Object : j)], u.prototype, "visibility", void 0);
31
+ p([d(Boolean), a("design:type", Boolean)], u.prototype, "isEnabled", void 0);
32
+ p([d(Number), a("design:type", Number)], u.prototype, "opacity", void 0);
33
+ p([d(Number), a("design:type", Number)], u.prototype, "width", void 0);
34
+ p([d(Number), a("design:type", Number)], u.prototype, "height", void 0);
35
+ p([d(Number), a("design:type", Number)], u.prototype, "ZIndex", void 0);
36
+ p([d(Number), a("design:type", typeof O > "u" ? Object : O)], u.prototype, "anchoring", void 0);
37
+ var S = /* @__PURE__ */ (function(e) {
38
+ return e[e.absolute = 0] = "absolute", e[e.flexRow = 1] = "flexRow", e[e.flexColumn = 2] = "flexColumn", e[e.grid = 3] = "grid", e;
39
+ })({}), m = () => (window.__cratisPrototypeComponents ??= {}, window.__cratisPrototypeComponents), N = () => (window.__cratisPrototypeBundleLoads ??= {}, window.__cratisPrototypeBundleLoads), _ = (e) => {
40
+ const o = [e], t = e.split(".").pop();
41
+ return t && t !== e && o.push(t), o;
42
+ }, l = (e, o) => {
43
+ if (typeof window > "u") return;
44
+ const t = m()[e];
45
+ if (t)
46
+ for (const n of _(o)) {
47
+ const r = t[n];
48
+ if (r) return r;
49
+ }
50
+ }, E = (e, o) => {
51
+ m()[e] = o;
52
+ for (const [t, n] of Object.entries(o)) {
53
+ if (!t.includes(".")) continue;
54
+ v.set(n, t);
55
+ let r = Object.getPrototypeOf(n.prototype);
56
+ for (; r && r.constructor && r.constructor !== Object; )
57
+ v.set(n, t, r.constructor), r = Object.getPrototypeOf(r);
58
+ }
59
+ }, x = (e) => {
60
+ if ("RenderPrototype" in e && typeof e.RenderPrototype == "function") return e;
61
+ const o = "_derivedTypeId" in e && typeof e._derivedTypeId == "string" && e._derivedTypeId.includes(".") ? e._derivedTypeId : "componentName" in e && typeof e.componentName == "string" ? e.componentName : "", t = o.indexOf(".");
62
+ if (t < 1) return e;
63
+ const n = l(o.slice(0, t), o.slice(t + 1));
64
+ if (!n) return e;
65
+ const r = Object.fromEntries(Object.entries(e).filter(([i]) => ![
66
+ "type",
67
+ "label",
68
+ "position",
69
+ "size",
70
+ "children"
71
+ ].includes(i)));
72
+ if ("slots" in e && e.slots && typeof e.slots == "object") {
73
+ let i;
74
+ for (const [c, s] of Object.entries(e.slots)) {
75
+ if (!Array.isArray(s)) continue;
76
+ let f;
77
+ for (const [C, w] of s.entries()) {
78
+ const g = x(w);
79
+ g !== w && (f ??= s.slice(), f[C] = g);
80
+ }
81
+ f && (i ??= { ...e.slots }, i[c] = f);
82
+ }
83
+ i && (r.slots = i);
84
+ }
85
+ return Object.assign(new n(), r);
86
+ }, P = (e, o) => {
87
+ const t = l(e, o);
88
+ return t ? new t() : void 0;
89
+ }, z = (e, o, t) => {
90
+ const n = l(e, o);
91
+ if (!n) return;
92
+ const r = new n();
93
+ return typeof r.initialize == "function" ? r.initialize(t) : (Object.assign(r, t), r);
94
+ }, R = async (e) => {
95
+ const o = N();
96
+ if (o[e]) {
97
+ await o[e];
98
+ return;
99
+ }
100
+ o[e] = new Promise((t, n) => {
101
+ const r = document.querySelector(`script[data-prototype-bundle="${e}"]`);
102
+ if (r) {
103
+ r.addEventListener("load", () => t(), { once: !0 }), r.addEventListener("error", () => n(/* @__PURE__ */ new Error(`Failed to load prototype bundle '${e}'.`)), { once: !0 });
104
+ return;
105
+ }
106
+ const i = document.createElement("script");
107
+ i.src = e, i.async = !0, i.dataset.prototypeBundle = e, i.onload = () => t(), i.onerror = () => n(/* @__PURE__ */ new Error(`Failed to load prototype bundle '${e}'.`)), document.head.appendChild(i);
108
+ }), await o[e];
109
+ }, D = async (e) => {
110
+ const o = [...new Set(e.filter(Boolean))];
111
+ await Promise.all(o.map(R)), B();
112
+ }, B = () => {
113
+ const e = m();
114
+ for (const o of Object.values(e)) for (const [t, n] of Object.entries(o))
115
+ t.includes(".") && v.set(n, t, u);
116
+ }, h = (e) => {
117
+ const o = e, t = o.componentName;
118
+ if (!t) return e;
119
+ const n = t.indexOf(".");
120
+ if (n < 0) return e;
121
+ const r = t.substring(0, n), i = t.substring(n + 1), c = l(r, i);
122
+ if (!c) return e;
123
+ const s = new c();
124
+ Object.assign(s, e);
125
+ const f = o.slots;
126
+ return f?.children?.length && (s.slots = {
127
+ ...f,
128
+ children: f.children.map(h)
129
+ }), s;
130
+ }, F = (e) => e.map(h);
131
+ export {
132
+ F as a,
133
+ E as c,
134
+ j as d,
135
+ b as f,
136
+ a as g,
137
+ p as h,
138
+ h as i,
139
+ S as l,
140
+ T as m,
141
+ R as n,
142
+ x as o,
143
+ O as p,
144
+ P as r,
145
+ D as s,
146
+ z as t,
147
+ u
148
+ };
@@ -0,0 +1,28 @@
1
+ import { UIElement } from './UIElement';
2
+ import type { ComponentState, IComponent, PrototypeComponentConstructor } from './IComponent';
3
+ import type { PrototypeSurfaceElement } from './Prototypes/Editor/editorTypes';
4
+ declare global {
5
+ interface Window {
6
+ __cratisPrototypeComponents?: Record<string, Record<string, PrototypeComponentConstructor>>;
7
+ __cratisPrototypeBundleLoads?: Partial<Record<string, Promise<void>>>;
8
+ }
9
+ }
10
+ export declare const registerPrototypeComponentLibrary: (libraryName: string, components: Record<string, PrototypeComponentConstructor>) => void;
11
+ export declare const hydratePrototypeElement: (element: UIElement | IComponent) => UIElement | IComponent;
12
+ export declare const getPrototypeComponent: (libraryName: string, type: string) => IComponent | undefined;
13
+ export declare const createPrototypeComponentInstance: (libraryName: string, type: string, state: Partial<ComponentState>) => IComponent | undefined;
14
+ export declare const ensurePrototypeComponentBundle: (bundlePath: string) => Promise<void>;
15
+ export declare const loadPrototypeComponentLibraries: (bundlePaths: string[]) => Promise<void>;
16
+ /**
17
+ * Reconstruct a server-loaded element as the specific Component subclass it represents.
18
+ * When elements round-trip through the server they arrive as plain data objects, not class
19
+ * instances — so even though the discriminator now carries the real type (e.g. 'PrimeReact.Button'),
20
+ * the canvas still needs the concrete Component subclass re-instantiated to regain full IComponent
21
+ * behavior including RenderPrototype(). The componentName field identifies the class to construct.
22
+ */
23
+ export declare const hydrateElement: (element: PrototypeSurfaceElement) => PrototypeSurfaceElement;
24
+ /**
25
+ * Hydrate all elements in a list, reconstructing each ExternalComponent as the specific
26
+ * Component subclass identified by its componentName.
27
+ */
28
+ export declare const hydrateElements: (elements: PrototypeSurfaceElement[]) => PrototypeSurfaceElement[];