@sincpro/web-composer 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +198 -2
  3. package/dist/domain/enums.d.ts +65 -0
  4. package/dist/domain/enums.js +56 -0
  5. package/dist/domain/index.d.ts +9 -0
  6. package/dist/domain/index.js +8 -0
  7. package/dist/domain/layout.d.ts +75 -0
  8. package/dist/domain/layout.js +180 -0
  9. package/dist/domain/palette.d.ts +42 -0
  10. package/dist/domain/palette.js +89 -0
  11. package/dist/domain/registry.d.ts +112 -0
  12. package/dist/domain/registry.js +37 -0
  13. package/dist/domain/resource.d.ts +21 -0
  14. package/dist/domain/resource.js +62 -0
  15. package/dist/domain/url.d.ts +3 -0
  16. package/dist/domain/url.js +107 -0
  17. package/dist/domain/workspace.d.ts +138 -0
  18. package/dist/domain/workspace.js +272 -0
  19. package/dist/index.d.ts +20 -0
  20. package/dist/index.js +19 -0
  21. package/dist/shell/Composer.d.ts +24 -0
  22. package/dist/shell/Composer.js +59 -0
  23. package/dist/shell/Palette.d.ts +9 -0
  24. package/dist/shell/Palette.js +123 -0
  25. package/dist/shell/PanelFrame.d.ts +31 -0
  26. package/dist/shell/PanelFrame.js +44 -0
  27. package/dist/shell/PanelHost.d.ts +23 -0
  28. package/dist/shell/PanelHost.js +188 -0
  29. package/dist/shell/RecordLink.d.ts +12 -0
  30. package/dist/shell/RecordLink.js +51 -0
  31. package/dist/shell/ViewHost.d.ts +11 -0
  32. package/dist/shell/ViewHost.js +42 -0
  33. package/dist/shell/copy.d.ts +64 -0
  34. package/dist/shell/copy.js +108 -0
  35. package/dist/state/api.d.ts +32 -0
  36. package/dist/state/api.js +140 -0
  37. package/dist/state/drag.d.ts +31 -0
  38. package/dist/state/drag.js +95 -0
  39. package/dist/state/store.d.ts +45 -0
  40. package/dist/state/store.js +76 -0
  41. package/dist/state/useKeyboard.d.ts +12 -0
  42. package/dist/state/useKeyboard.js +55 -0
  43. package/dist/state/useWorkspace.d.ts +23 -0
  44. package/dist/state/useWorkspace.js +34 -0
  45. package/package.json +82 -4
@@ -0,0 +1,31 @@
1
+ import type { Zone } from "../domain/index.js";
2
+ import { type Dock, DragKind, type ResourceRef } from "../domain/index.js";
3
+ import { type RefObject } from "react";
4
+ export type DragData = {
5
+ kind: typeof DragKind.Panel;
6
+ panelId: string;
7
+ } | {
8
+ kind: typeof DragKind.Ref;
9
+ ref: ResourceRef;
10
+ };
11
+ export type DropData = {
12
+ kind: typeof DragKind.Zone;
13
+ zone: Zone;
14
+ };
15
+ /** Only a DOCKED panel is dragged to another edge. A window moves with the pointer, and a native
16
+ * drag on the same header would swallow that gesture — `enabled` keeps the two apart. */
17
+ export declare function useDraggablePanel(ref: RefObject<HTMLElement | null>, panelId: string, enabled?: boolean): boolean;
18
+ export declare function useDropZone(ref: RefObject<HTMLElement | null>, zone: Dock): boolean;
19
+ /** Makes an element drag a REFERENCE — a row, a chip — that a zone turns into a panel. */
20
+ export declare function useDraggableRef(ref: RefObject<HTMLElement | null>, resource: ResourceRef): boolean;
21
+ /** True while a panel or a reference is being dragged. Drop targets must only steal
22
+ * pointer events then — otherwise they sit on top of “beside” / “floating”
23
+ * and the buttons never fire. */
24
+ export declare function usePanelDragArmed(): boolean;
25
+ export type DropHandlers = {
26
+ onPanelToZone: (panelId: string, zone: Zone) => void;
27
+ onRefToZone: (ref: ResourceRef, zone: Zone) => void;
28
+ };
29
+ /** One monitor for the whole workspace: drop is ONE event with ONE result.
30
+ * Split across targets, an overlapping zone and tab would both apply. */
31
+ export declare function useDropMonitor({ onPanelToZone, onRefToZone }: DropHandlers): void;
@@ -0,0 +1,95 @@
1
+ import { draggable, dropTargetForElements, monitorForElements, } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
2
+ import { DragKind } from "../domain/index.js";
3
+ import { useEffect, useState } from "react";
4
+ const isDrag = (v) => v["kind"] === DragKind.Panel || v["kind"] === DragKind.Ref;
5
+ /** Only a DOCKED panel is dragged to another edge. A window moves with the pointer, and a native
6
+ * drag on the same header would swallow that gesture — `enabled` keeps the two apart. */
7
+ export function useDraggablePanel(ref, panelId, enabled = true) {
8
+ const [dragging, setDragging] = useState(false);
9
+ useEffect(() => {
10
+ const el = ref.current;
11
+ if (el === null || !enabled)
12
+ return;
13
+ return draggable({
14
+ element: el,
15
+ getInitialData: () => ({
16
+ kind: DragKind.Panel,
17
+ panelId,
18
+ }),
19
+ onDragStart: () => setDragging(true),
20
+ onDrop: () => setDragging(false),
21
+ });
22
+ }, [ref, panelId, enabled]);
23
+ return dragging;
24
+ }
25
+ export function useDropZone(ref, zone) {
26
+ const [over, setOver] = useState(false);
27
+ useEffect(() => {
28
+ const el = ref.current;
29
+ if (el === null)
30
+ return;
31
+ return dropTargetForElements({
32
+ element: el,
33
+ getData: () => ({ kind: DragKind.Zone, zone }),
34
+ canDrop: ({ source }) => isDrag(source.data) &&
35
+ (source.data.kind === DragKind.Panel || source.data.kind === DragKind.Ref),
36
+ onDragEnter: () => setOver(true),
37
+ onDragLeave: () => setOver(false),
38
+ onDrop: () => setOver(false),
39
+ });
40
+ }, [ref, zone]);
41
+ return over;
42
+ }
43
+ /** Makes an element drag a REFERENCE — a row, a chip — that a zone turns into a panel. */
44
+ export function useDraggableRef(ref, resource) {
45
+ const [dragging, setDragging] = useState(false);
46
+ useEffect(() => {
47
+ const el = ref.current;
48
+ if (el === null)
49
+ return;
50
+ return draggable({
51
+ element: el,
52
+ getInitialData: () => ({
53
+ kind: DragKind.Ref,
54
+ ref: resource,
55
+ }),
56
+ onDragStart: () => setDragging(true),
57
+ onDrop: () => setDragging(false),
58
+ });
59
+ }, [ref, resource]);
60
+ return dragging;
61
+ }
62
+ /** True while a panel or a reference is being dragged. Drop targets must only steal
63
+ * pointer events then — otherwise they sit on top of “beside” / “floating”
64
+ * and the buttons never fire. */
65
+ export function usePanelDragArmed() {
66
+ const [armed, setArmed] = useState(false);
67
+ useEffect(() => monitorForElements({
68
+ canMonitor: ({ source }) => isDrag(source.data) &&
69
+ (source.data.kind === DragKind.Panel || source.data.kind === DragKind.Ref),
70
+ onDragStart: () => setArmed(true),
71
+ onDrop: () => setArmed(false),
72
+ }), []);
73
+ return armed;
74
+ }
75
+ /** One monitor for the whole workspace: drop is ONE event with ONE result.
76
+ * Split across targets, an overlapping zone and tab would both apply. */
77
+ export function useDropMonitor({ onPanelToZone, onRefToZone }) {
78
+ useEffect(() => monitorForElements({
79
+ canMonitor: ({ source }) => isDrag(source.data),
80
+ onDrop: ({ source, location }) => {
81
+ const target = location.current.dropTargets[0];
82
+ if (target === undefined || !isDrag(source.data))
83
+ return;
84
+ const data = target.data;
85
+ if (source.data.kind === DragKind.Panel && data.kind === DragKind.Zone) {
86
+ onPanelToZone(source.data.panelId, data.zone);
87
+ return;
88
+ }
89
+ if (source.data.kind === DragKind.Ref && data.kind === DragKind.Zone) {
90
+ onRefToZone(source.data.ref, data.zone);
91
+ return;
92
+ }
93
+ },
94
+ }), [onPanelToZone, onRefToZone]);
95
+ }
@@ -0,0 +1,45 @@
1
+ import type { Dock, OpenPanelOptions, ResourceRef, WindowBox, Workspace, Zone } from "../domain/index.js";
2
+ /**
3
+ * The pure reducers already are the state handling; this only binds them to the browser. An
4
+ * external store, not `useState`: with state in the component every action recreated the API
5
+ * views receive, and every panel redrew on any change.
6
+ */
7
+ export type Unsubscribe = () => void;
8
+ export type WorkspaceStore = {
9
+ /** Current state. Read at call time, never captured. */
10
+ get: () => Workspace;
11
+ subscribe: (listener: () => void) => Unsubscribe;
12
+ /** Escape hatch: any reducer, including one of your own. */
13
+ apply: (change: (state: Workspace) => Workspace) => void;
14
+ /** Back to the starting workspace — the `initial` it was created with. */
15
+ reset: () => void;
16
+ push: (view: ResourceRef) => void;
17
+ goTo: (index: number) => void;
18
+ back: () => void;
19
+ openPanel: (view: ResourceRef, options?: Zone | OpenPanelOptions) => void;
20
+ navigatePanel: (id: string, view: ResourceRef) => void;
21
+ movePanel: (id: string, zone: Zone) => void;
22
+ resizeZone: (zone: Dock, size: number) => void;
23
+ resizePanel: (id: string, share: number) => void;
24
+ floatPanel: (id: string, box: WindowBox) => void;
25
+ raisePanel: (id: string) => void;
26
+ collapsePanel: (id: string) => void;
27
+ closePanel: (id: string) => void;
28
+ expandPanel: (id: string) => void;
29
+ maximize: (target: string | null) => void;
30
+ focusPanel: (target: string) => void;
31
+ cycleFocus: (delta: number) => void;
32
+ peek: (view: ResourceRef) => void;
33
+ closePeek: () => void;
34
+ peekToPage: () => void;
35
+ peekToSide: (zone?: Zone) => void;
36
+ };
37
+ export type StoreOptions = {
38
+ initial?: Workspace;
39
+ /** Persist the workspace in the URL hash. Browser history and «share this link» come from
40
+ * here. */
41
+ hash?: boolean;
42
+ /** Called after every change. Hook for telemetry or saving the user's workspace. */
43
+ onChange?: (state: Workspace) => void;
44
+ };
45
+ export declare function createWorkspaceStore({ initial, hash, onChange, }?: StoreOptions): WorkspaceStore;
@@ -0,0 +1,76 @@
1
+ import * as model from "../domain/index.js";
2
+ const inBrowser = () => typeof window !== "undefined";
3
+ function readHash(fallback) {
4
+ if (!inBrowser() || !window.location.hash.startsWith("#/w"))
5
+ return fallback;
6
+ return model.fromHash(window.location.hash);
7
+ }
8
+ export function createWorkspaceStore({ initial = model.EMPTY, hash = false, onChange, } = {}) {
9
+ let state = hash ? readHash(initial) : initial;
10
+ const listeners = new Set();
11
+ const notify = () => {
12
+ for (const l of listeners)
13
+ l();
14
+ onChange?.(state);
15
+ };
16
+ /** Compare the text before writing; otherwise writing the hash fires `hashchange` and the
17
+ * loop never ends. */
18
+ const writeUrl = () => {
19
+ if (!hash || !inBrowser())
20
+ return;
21
+ const text = model.toHash(state);
22
+ if (window.location.hash !== text)
23
+ window.history.replaceState(null, "", text);
24
+ };
25
+ const apply = (change) => {
26
+ const next = change(state);
27
+ if (next === state)
28
+ return;
29
+ state = next;
30
+ writeUrl();
31
+ notify();
32
+ };
33
+ function onHashChange() {
34
+ const fromUrl = readHash(state);
35
+ if (model.toHash(fromUrl) === model.toHash(state))
36
+ return;
37
+ state = fromUrl;
38
+ notify();
39
+ }
40
+ const subscribe = (listener) => {
41
+ listeners.add(listener);
42
+ if (listeners.size === 1 && hash && inBrowser())
43
+ window.addEventListener("hashchange", onHashChange);
44
+ return () => {
45
+ listeners.delete(listener);
46
+ if (listeners.size === 0 && hash && inBrowser())
47
+ window.removeEventListener("hashchange", onHashChange);
48
+ };
49
+ };
50
+ return {
51
+ get: () => state,
52
+ subscribe,
53
+ apply,
54
+ reset: () => apply(() => initial),
55
+ push: (view) => apply((w) => model.push(w, view)),
56
+ goTo: (index) => apply((w) => model.goTo(w, index)),
57
+ back: () => apply(model.back),
58
+ openPanel: (view, options) => apply((w) => model.openPanel(w, view, options)),
59
+ navigatePanel: (id, view) => apply((w) => model.navigatePanel(w, id, view)),
60
+ movePanel: (id, zone) => apply((w) => model.movePanel(w, id, zone)),
61
+ resizeZone: (zone, size) => apply((w) => model.resizeZone(w, zone, size)),
62
+ resizePanel: (id, share) => apply((w) => model.resizePanel(w, id, share)),
63
+ floatPanel: (id, box) => apply((w) => model.floatPanel(w, id, box)),
64
+ raisePanel: (id) => apply((w) => model.raisePanel(w, id)),
65
+ collapsePanel: (id) => apply((w) => model.collapsePanel(w, id)),
66
+ closePanel: (id) => apply((w) => model.closePanel(w, id)),
67
+ expandPanel: (id) => apply((w) => model.expandPanel(w, id)),
68
+ maximize: (target) => apply((w) => model.maximize(w, target)),
69
+ focusPanel: (target) => apply((w) => model.focusPanel(w, target)),
70
+ cycleFocus: (delta) => apply((w) => model.cycleFocus(w, delta)),
71
+ peek: (view) => apply((w) => model.peek(w, view)),
72
+ closePeek: () => apply(model.closePeek),
73
+ peekToPage: () => apply(model.peekToPage),
74
+ peekToSide: (zone) => apply((w) => model.peekToSide(w, zone)),
75
+ };
76
+ }
@@ -0,0 +1,12 @@
1
+ import type { WorkspaceStore } from "./store.js";
2
+ /**
3
+ * Shortcuts talk to the WORKSPACE, not to the browser-focused panel: that focus lives INSIDE the
4
+ * view — almost always in a text field — and the keys belong to it there.
5
+ */
6
+ export type UseKeyboardOptions = {
7
+ workspace: WorkspaceStore;
8
+ enabled?: boolean;
9
+ /** ⌘K. Works while typing too: the palette is where you go FROM a field. */
10
+ onPalette?: () => void;
11
+ };
12
+ export declare function useKeyboard({ workspace, enabled, onPalette }: UseKeyboardOptions): void;
@@ -0,0 +1,55 @@
1
+ import { PAGE } from "../domain/index.js";
2
+ import { useEffect } from "react";
3
+ /** Inside a field only Escape survives. Stealing a key from someone who is typing is worse than
4
+ * having no shortcuts. */
5
+ function isTyping(target) {
6
+ if (!(target instanceof HTMLElement))
7
+ return false;
8
+ return target.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(target.tagName);
9
+ }
10
+ export function useKeyboard({ workspace, enabled = true, onPalette }) {
11
+ useEffect(() => {
12
+ if (!enabled)
13
+ return;
14
+ function onKeyDown(e) {
15
+ const state = workspace.get();
16
+ if (e.key === "Escape") {
17
+ if (state.peek !== null) {
18
+ workspace.closePeek();
19
+ e.preventDefault();
20
+ }
21
+ else if (state.maximized !== null) {
22
+ workspace.maximize(state.maximized);
23
+ e.preventDefault();
24
+ }
25
+ return;
26
+ }
27
+ const mod = e.metaKey || e.ctrlKey;
28
+ if (onPalette !== undefined && mod && e.code === "KeyK") {
29
+ onPalette();
30
+ e.preventDefault();
31
+ return;
32
+ }
33
+ if (isTyping(e.target))
34
+ return;
35
+ if (e.altKey && !mod && e.code === "ArrowLeft") {
36
+ workspace.back();
37
+ e.preventDefault();
38
+ }
39
+ else if (mod && e.altKey && (e.code === "BracketLeft" || e.code === "BracketRight")) {
40
+ workspace.cycleFocus(e.code === "BracketRight" ? 1 : -1);
41
+ e.preventDefault();
42
+ }
43
+ else if (mod && e.shiftKey && e.code === "Enter") {
44
+ workspace.maximize(state.maximized ?? state.focus);
45
+ e.preventDefault();
46
+ }
47
+ else if (mod && e.shiftKey && e.code === "Backspace" && state.focus !== PAGE) {
48
+ workspace.closePanel(state.focus);
49
+ e.preventDefault();
50
+ }
51
+ }
52
+ window.addEventListener("keydown", onKeyDown);
53
+ return () => window.removeEventListener("keydown", onKeyDown);
54
+ }, [enabled, workspace, onPalette]);
55
+ }
@@ -0,0 +1,23 @@
1
+ import type { Workspace, WorkspaceApi } from "../domain/index.js";
2
+ import { type StoreOptions, type WorkspaceStore } from "./store.js";
3
+ /**
4
+ * `useSyncExternalStore` is React, not a state library. What it adds over
5
+ * `useState` is the one thing we needed: subscribe to a slice, so moving one
6
+ * panel does not redraw the other five.
7
+ */
8
+ export declare function useWorkspace(options?: StoreOptions): WorkspaceStore;
9
+ /**
10
+ * Watch a slice of the workspace and redraw only when THAT slice changes.
11
+ * The selector must return something comparable by identity. Reducers are
12
+ * pure and leave untouched data alone, so `tab.panels` stays the same array
13
+ * until someone moves a panel.
14
+ */
15
+ export declare function useWorkspaceSlice<T>(store: WorkspaceStore, select: (state: Workspace) => T): T;
16
+ export declare function useWorkspaceState(store: WorkspaceStore): Workspace;
17
+ /** For a global panel — the chat, the assistant — that follows what the user
18
+ * is working on. Redraws only when the focused resource or its selection change. */
19
+ export declare function useWorkspaceContext(api: WorkspaceApi): {
20
+ focused: import("../domain/index.js").ResourceRef | null;
21
+ selection: readonly import("../domain/index.js").ResourceRef[];
22
+ };
23
+ export type { StoreOptions as UseWorkspaceOptions, WorkspaceStore };
@@ -0,0 +1,34 @@
1
+ import { createWorkspaceStore, } from "./store.js";
2
+ import { useMemo, useRef, useSyncExternalStore } from "react";
3
+ /**
4
+ * `useSyncExternalStore` is React, not a state library. What it adds over
5
+ * `useState` is the one thing we needed: subscribe to a slice, so moving one
6
+ * panel does not redraw the other five.
7
+ */
8
+ export function useWorkspace(options = {}) {
9
+ const saved = useRef(null);
10
+ saved.current ??= createWorkspaceStore(options);
11
+ return saved.current;
12
+ }
13
+ /**
14
+ * Watch a slice of the workspace and redraw only when THAT slice changes.
15
+ * The selector must return something comparable by identity. Reducers are
16
+ * pure and leave untouched data alone, so `tab.panels` stays the same array
17
+ * until someone moves a panel.
18
+ */
19
+ export function useWorkspaceSlice(store, select) {
20
+ const read = useMemo(() => () => select(store.get()), [store, select]);
21
+ return useSyncExternalStore(store.subscribe, read, read);
22
+ }
23
+ export function useWorkspaceState(store) {
24
+ return useSyncExternalStore(store.subscribe, store.get, store.get);
25
+ }
26
+ /** For a global panel — the chat, the assistant — that follows what the user
27
+ * is working on. Redraws only when the focused resource or its selection change. */
28
+ export function useWorkspaceContext(api) {
29
+ const { subscribe, focused, selection } = api.context;
30
+ return {
31
+ focused: useSyncExternalStore(subscribe, focused, focused),
32
+ selection: useSyncExternalStore(subscribe, selection, selection),
33
+ };
34
+ }
package/package.json CHANGED
@@ -1,6 +1,84 @@
1
1
  {
2
2
  "name": "@sincpro/web-composer",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "The Sincpro multitasking workspace for React: tabs, panels, peek, global panels and ⌘K over references.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./domain": {
14
+ "types": "./dist/domain/index.d.ts",
15
+ "default": "./dist/domain/index.js"
16
+ }
17
+ },
18
+ "publishConfig": {
19
+ "access": "public"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "sideEffects": false,
26
+ "prettier": {
27
+ "printWidth": 94
28
+ },
29
+ "peerDependencies": {
30
+ "@sincpro/web-ui": "*",
31
+ "react": ">=19",
32
+ "react-dom": ">=19"
33
+ },
34
+ "devDependencies": {
35
+ "@eslint/js": "^10.0.1",
36
+ "@sincpro/web-ui": "^0.1.0",
37
+ "@storybook/addon-a11y": "10.6.5",
38
+ "@storybook/addon-docs": "10.6.5",
39
+ "@storybook/addon-mcp": "10.6.5",
40
+ "@storybook/react-vite": "10.6.5",
41
+ "@tailwindcss/vite": "4.3.3",
42
+ "@tanstack/react-table": "^9.3.1",
43
+ "@tanstack/react-virtual": "^3.14.24",
44
+ "@types/node": "^26.6.6",
45
+ "@types/react": "^19.3.0",
46
+ "@types/react-dom": "^19.3.0",
47
+ "@vitejs/plugin-react": "6.1.2",
48
+ "eslint": "^10.14.0",
49
+ "eslint-config-prettier": "^10.1.8",
50
+ "eslint-plugin-react-hooks": "^7.1.1",
51
+ "eslint-plugin-simple-import-sort": "^14.0.0",
52
+ "prettier": "^3.9.10",
53
+ "puppeteer-core": "^25.16.0",
54
+ "react": "19.3.1",
55
+ "react-dom": "19.3.1",
56
+ "storybook": "10.6.5",
57
+ "tailwindcss": "4.3.3",
58
+ "tsc-alias": "^1.9.9",
59
+ "tsx": "^4.23.15",
60
+ "typescript": "~6.0.3",
61
+ "typescript-eslint": "^8.72.1",
62
+ "vite": "8.3.5"
63
+ },
64
+ "keywords": [
65
+ "workspace",
66
+ "react",
67
+ "tabs",
68
+ "command-palette",
69
+ "sincpro"
70
+ ],
71
+ "repository": {
72
+ "type": "git",
73
+ "url": "git+https://github.com/Sincpro-SRL/sincpro_web_composer.git"
74
+ },
75
+ "author": "Gutierrez, Andres <andres.gutierrez@sincpro.com.bo>",
76
+ "license": "MIT",
77
+ "engines": {
78
+ "node": ">=26"
79
+ },
80
+ "dependencies": {
81
+ "@atlaskit/pragmatic-drag-and-drop": "^4.0.0",
82
+ "lucide-react": "^1.65.0"
83
+ }
84
+ }