@cratis/event-models 0.176.0 → 0.177.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.
@@ -1,6 +1,6 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import type { ScreenEditorStrings } from '../Inspector/ScreenEditorStrings';
3
- import { type PaletteIcons, type PaletteSource } from '../Palette/buildPalette';
3
+ import type { PaletteIcons, PaletteSource } from '../Palette/buildPalette';
4
4
  import type { LayoutLabels } from '../Layouts/toLayoutContainerDescriptors';
5
5
  import type { ScreenEditorEnvironment, ScreenEditorResult, ScreenEditorSubject } from './ScreenEditorHost';
6
6
  import { type WindowSizeMemory } from '../Viewport/windowSizeMemory';
@@ -1,6 +1,6 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import type { ScreenEditorStrings } from '../Inspector/ScreenEditorStrings';
3
- import { type PaletteIcons, type PaletteSource } from '../Palette/buildPalette';
3
+ import type { PaletteIcons, PaletteSource } from '../Palette/buildPalette';
4
4
  import type { LayoutLabels } from '../Layouts/toLayoutContainerDescriptors';
5
5
  import type { ScreenEditorEnvironment, ScreenEditorResult, ScreenEditorSubject } from './ScreenEditorHost';
6
6
  export interface ScreenEditorWorkspaceProps {
@@ -1,4 +1,5 @@
1
1
  import type { ScreenEditorController } from './ScreenEditorController';
2
2
  import type { OpenedSubject } from './openSubject';
3
3
  import type { ScreenEditorEnvironment } from './ScreenEditorHost';
4
- export declare function useScreenEditor(opened: OpenedSubject, authoringTemplate: string | undefined, environment: ScreenEditorEnvironment): ScreenEditorController;
4
+ export type ComponentInsertedListener = (key: string) => void;
5
+ export declare function useScreenEditor(opened: OpenedSubject, authoringTemplate: string | undefined, environment: ScreenEditorEnvironment, onInserted?: ComponentInsertedListener): ScreenEditorController;
@@ -1,5 +1,6 @@
1
1
  import type { IconPickerLabels } from '@cratis/components/IconPicker';
2
2
  import type { IconPropertyFieldStrings } from '../../Icons/IconPropertyFieldStrings';
3
+ import type { ComponentPickerStrings } from '../Palette/ComponentPicker';
3
4
  import type { PropertyEditorStrings } from '../PropertyEditors/Registry/PropertyEditorStrings';
4
5
  import type { StructuredEditorStrings } from '../PropertyEditors/Structured/StructuredEditorStrings';
5
6
  import type { Ownership } from '../Structure/Ownership';
@@ -43,6 +44,8 @@ export interface ScreenEditorStrings {
43
44
  redo: string;
44
45
  palette: string;
45
46
  layoutDrawer: string;
47
+ componentsDrawer: string;
48
+ picker?: ComponentPickerStrings;
46
49
  packageTitles: Record<string, string>;
47
50
  closeDrawer: string;
48
51
  deleteElement: string;
@@ -0,0 +1,21 @@
1
+ import { type PickerEntry } from './componentPickerModel';
2
+ import type { ComponentPickerMemory } from './componentPickerStorage';
3
+ export interface ComponentPickerStrings {
4
+ heading: string;
5
+ filterPlaceholder: string;
6
+ filterLabel: string;
7
+ frequentlyUsed: string;
8
+ groupsHint: string;
9
+ nothingMatches: string;
10
+ viaKeyword: (badge: string, query: string, keyword: string) => string;
11
+ addLabel: (component: string) => string;
12
+ }
13
+ export declare const defaultComponentPickerStrings: ComponentPickerStrings;
14
+ export interface ComponentPickerProps {
15
+ entries: readonly PickerEntry[];
16
+ memory: ComponentPickerMemory;
17
+ strings?: ComponentPickerStrings;
18
+ onAdd: (entry: PickerEntry) => void;
19
+ usageVersion?: number;
20
+ }
21
+ export declare const ComponentPicker: ({ entries, memory, strings, onAdd, usageVersion }: ComponentPickerProps) => import("react").JSX.Element;
@@ -1,7 +1,15 @@
1
- import type { PaletteDrawer } from './buildPalette';
1
+ import type { ReactNode } from 'react';
2
+ import { type ComponentPickerStrings } from './ComponentPicker';
3
+ import type { PickerEntry } from './componentPickerModel';
4
+ import type { ComponentPickerMemory } from './componentPickerStorage';
2
5
  export interface PaletteFoldersProps {
3
- drawers: readonly PaletteDrawer[];
6
+ entries: readonly PickerEntry[];
7
+ memory: ComponentPickerMemory;
8
+ icon: ReactNode;
9
+ title: string;
4
10
  closeLabel: string;
5
- onActivate: (payload: unknown) => void;
11
+ strings?: ComponentPickerStrings;
12
+ usageVersion: number;
13
+ onAdd: (entry: PickerEntry) => void;
6
14
  }
7
- export declare const PaletteFolders: ({ drawers, closeLabel, onActivate }: PaletteFoldersProps) => import("react").JSX.Element;
15
+ export declare const PaletteFolders: ({ entries, memory, icon, title, closeLabel, strings, usageVersion, onAdd }: PaletteFoldersProps) => import("react").JSX.Element;
@@ -1,16 +1,10 @@
1
- import type { ToolbarDrawerItem } from '@cratis/components/Toolbar';
1
+ import type { ComponentDescriptor } from '@cratis/scene.model';
2
2
  import type { ReactNode } from 'react';
3
- import type { LayoutLabels } from '../Layouts/toLayoutContainerDescriptors';
4
3
  import type { LayoutItem } from '../Layouts/LayoutItem';
5
- export interface PaletteDrawer {
6
- id: string;
7
- title: string;
8
- icon: ReactNode;
9
- items: ToolbarDrawerItem[];
10
- }
11
4
  export interface PaletteSource {
12
5
  package: string;
13
6
  components: readonly string[];
7
+ descriptors?: readonly ComponentDescriptor[];
14
8
  }
15
9
  export interface PaletteIcons {
16
10
  layout: (item: LayoutItem) => ReactNode;
@@ -20,4 +14,3 @@ export interface PaletteIcons {
20
14
  package: (packageName: string) => ReactNode;
21
15
  };
22
16
  }
23
- export declare function buildPalette(layoutTitle: string, labels: LayoutLabels, icons: PaletteIcons, sources: readonly PaletteSource[], packageTitles?: Readonly<Record<string, string>>): PaletteDrawer[];
@@ -0,0 +1,54 @@
1
+ import { type ComponentQueryMatch, type ComponentUsage } from '@cratis/scene.engine';
2
+ import { type ComponentDescriptor } from '@cratis/scene.model';
3
+ import type { PalettePayload } from './PaletteEntry';
4
+ export interface PickerEntry {
5
+ key: string;
6
+ label: string;
7
+ badge: string;
8
+ category: string;
9
+ keywords: readonly string[];
10
+ package?: string;
11
+ packageTitle?: string;
12
+ payload: PalettePayload;
13
+ }
14
+ export interface PickerSource {
15
+ package: string;
16
+ components: readonly string[];
17
+ descriptors?: readonly ComponentDescriptor[];
18
+ }
19
+ export interface PickerLayout {
20
+ item: string;
21
+ label: string;
22
+ }
23
+ export declare const uncategorised = "Other";
24
+ export declare const layoutCategory: "Layout";
25
+ export declare function buildPickerEntries(sources: readonly PickerSource[], layouts: readonly PickerLayout[], packageTitles?: Readonly<Record<string, string>>): PickerEntry[];
26
+ export interface PickerRow {
27
+ entry: PickerEntry;
28
+ match: ComponentQueryMatch;
29
+ }
30
+ export interface PickerGroup {
31
+ id: string;
32
+ title: string;
33
+ frequent: boolean;
34
+ count: number;
35
+ expanded: boolean;
36
+ rows: PickerRow[];
37
+ }
38
+ export interface PickerViewInputs {
39
+ entries: readonly PickerEntry[];
40
+ usage: Readonly<Record<string, ComponentUsage>>;
41
+ query: string;
42
+ groups: Readonly<Record<string, boolean>>;
43
+ frequentTitle: string;
44
+ }
45
+ export declare const frequentGroupId = "frequent";
46
+ export declare function buildPickerView({ entries, usage, query, groups, frequentTitle }: PickerViewInputs): PickerGroup[];
47
+ export declare const visibleRows: (view: readonly PickerGroup[]) => {
48
+ group: PickerGroup;
49
+ row: PickerRow;
50
+ }[];
51
+ export declare function highlightParts(text: string, ranges: readonly [number, number][]): {
52
+ text: string;
53
+ marked: boolean;
54
+ }[];
@@ -0,0 +1,15 @@
1
+ import { type ComponentUsage } from '@cratis/scene.engine';
2
+ export declare const componentUsageKey = "cratis.studio.componentUsage.v1";
3
+ export declare const componentGroupsKey = "cratis.studio.componentGroups.v1";
4
+ export interface ComponentPickerStorage {
5
+ getItem(key: string): string | null;
6
+ setItem(key: string, value: string): void;
7
+ }
8
+ export interface ComponentPickerMemory {
9
+ readUsage(): Record<string, ComponentUsage>;
10
+ recordAdded(key: string, now?: number): Record<string, ComponentUsage>;
11
+ readGroups(): Record<string, boolean>;
12
+ writeGroups(groups: Readonly<Record<string, boolean>>): void;
13
+ }
14
+ export declare const browserComponentPickerStorage: () => ComponentPickerStorage | undefined;
15
+ export declare function createComponentPickerMemory(storage?: ComponentPickerStorage | undefined, userId?: string): ComponentPickerMemory;
@@ -0,0 +1,18 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { LayoutLabels } from '../Layouts/toLayoutContainerDescriptors';
3
+ import type { ScreenEditorStrings } from '../Inspector/ScreenEditorStrings';
4
+ import type { PaletteIcons, PaletteSource } from './buildPalette';
5
+ import { type PickerEntry } from './componentPickerModel';
6
+ import { type ComponentPickerMemory } from './componentPickerStorage';
7
+ export interface ComponentPaletteInputs {
8
+ strings: ScreenEditorStrings;
9
+ layoutLabels: LayoutLabels;
10
+ icons: PaletteIcons;
11
+ paletteSources: readonly PaletteSource[];
12
+ onAdd: (entry: PickerEntry) => void;
13
+ memory?: ComponentPickerMemory;
14
+ }
15
+ export declare function useComponentPalette({ strings, layoutLabels, icons, paletteSources, onAdd, memory: given }: ComponentPaletteInputs): {
16
+ palette: ReactNode;
17
+ recordInserted: (key: string) => void;
18
+ };