@adia-ai/web-components 0.0.2 → 0.0.3

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 (113) hide show
  1. package/a2ui/index.js +23 -17
  2. package/components/accordion/accordion.js +1 -1
  3. package/components/action-list/action-list.js +1 -1
  4. package/components/agent-artifact/agent-artifact.js +1 -1
  5. package/components/agent-feedback-bar/agent-feedback-bar.js +1 -1
  6. package/components/agent-questions/agent-questions.js +1 -1
  7. package/components/agent-reasoning/agent-reasoning.js +1 -1
  8. package/components/agent-suggestions/agent-suggestions.js +1 -1
  9. package/components/agent-trace/agent-trace.js +1 -1
  10. package/components/alert/alert.js +1 -1
  11. package/components/avatar/avatar.js +1 -1
  12. package/components/badge/badge.js +1 -1
  13. package/components/block/block.js +1 -1
  14. package/components/breadcrumb/breadcrumb.js +1 -1
  15. package/components/button/button.js +2 -2
  16. package/components/calendar-picker/calendar-picker.js +2 -2
  17. package/components/canvas/canvas.js +2 -2
  18. package/components/card/card.js +2 -2
  19. package/components/chart/chart.js +1 -1
  20. package/components/chat/chat-input.js +1 -1
  21. package/components/chat/chat.js +2 -2
  22. package/components/check/check.js +2 -2
  23. package/components/code/code.js +1 -1
  24. package/components/col/col.js +1 -1
  25. package/components/color-picker/color-picker.js +1 -1
  26. package/components/command/command.js +1 -1
  27. package/components/description-list/description-list.js +1 -1
  28. package/components/divider/divider.js +1 -1
  29. package/components/drawer/drawer.js +1 -1
  30. package/components/embed/embed.js +1 -1
  31. package/components/empty-state/empty-state.js +1 -1
  32. package/components/grid/grid.js +1 -1
  33. package/components/heatmap/heatmap.js +1 -1
  34. package/components/icon/icon.js +2 -2
  35. package/components/image/image.js +1 -1
  36. package/components/input/input.js +2 -2
  37. package/components/inspector/inspector.js +2 -2
  38. package/components/kbd/kbd.js +1 -1
  39. package/components/list/list.js +1 -1
  40. package/components/menu/menu.js +2 -2
  41. package/components/modal/modal.js +1 -1
  42. package/components/noodles/noodles.js +1 -1
  43. package/components/otp-input/otp-input.js +1 -1
  44. package/components/pagination/pagination.js +1 -1
  45. package/components/pane/pane.js +1 -1
  46. package/components/pipeline-status/pipeline-status.js +1 -1
  47. package/components/popover/popover.js +2 -2
  48. package/components/progress/progress.js +1 -1
  49. package/components/progress-row/progress-row.js +1 -1
  50. package/components/radio/radio.js +2 -2
  51. package/components/range/range.js +1 -1
  52. package/components/rating/rating.js +1 -1
  53. package/components/richtext/richtext.js +2 -2
  54. package/components/row/row.js +2 -2
  55. package/components/search/search.js +1 -1
  56. package/components/segment/segment.js +1 -1
  57. package/components/segmented/segmented.js +1 -1
  58. package/components/select/select.js +2 -2
  59. package/components/skeleton/skeleton.js +1 -1
  60. package/components/slider/slider.js +1 -1
  61. package/components/stack/stack.js +1 -1
  62. package/components/stat/stat.js +1 -1
  63. package/components/stepper/stepper.js +1 -1
  64. package/components/stream/stream.js +1 -1
  65. package/components/swiper/swiper.js +1 -1
  66. package/components/switch/switch.js +2 -2
  67. package/components/table/table.js +1 -1
  68. package/components/tabs/tab.js +1 -1
  69. package/components/tabs/tabs.js +1 -1
  70. package/components/tag/tag.js +1 -1
  71. package/components/text/text.js +1 -1
  72. package/components/textarea/textarea.js +1 -1
  73. package/components/timeline/timeline.js +1 -1
  74. package/components/toast/toast.js +1 -1
  75. package/components/toggle-group/toggle-group.js +1 -1
  76. package/components/toolbar/toolbar.js +2 -2
  77. package/components/tooltip/tooltip.js +2 -2
  78. package/components/tree/tree.js +1 -1
  79. package/components/upload/upload.js +1 -1
  80. package/core/markdown.js +1 -1
  81. package/core/provider.js +2 -2
  82. package/package.json +7 -3
  83. package/patterns/a2ui-root/a2ui-root.a2ui.json +118 -0
  84. package/{a2ui/root.js → patterns/a2ui-root/a2ui-root.js} +9 -4
  85. package/patterns/a2ui-root/a2ui-root.yaml +76 -0
  86. package/patterns/adia-chat/adia-chat.js +3 -3
  87. package/patterns/adia-editor/adia-editor.js +1 -1
  88. package/patterns/app-nav/app-nav.js +1 -1
  89. package/patterns/app-nav-group/app-nav-group.js +2 -2
  90. package/patterns/app-nav-item/app-nav-item.js +1 -1
  91. package/patterns/app-shell/app-shell.js +1 -1
  92. package/patterns/gen-ui/gen-ui.js +1 -1
  93. package/patterns/index.js +1 -0
  94. package/patterns/section-nav/section-nav.js +1 -1
  95. package/patterns/section-nav-group/section-nav-group.js +1 -1
  96. package/patterns/section-nav-item/section-nav-item.js +1 -1
  97. package/traits/define.js +1 -1
  98. package/a2ui/dockables/action.js +0 -152
  99. package/a2ui/dockables/base.js +0 -30
  100. package/a2ui/dockables/controller.js +0 -97
  101. package/a2ui/dockables/data-source.js +0 -103
  102. package/a2ui/dockables/index.js +0 -6
  103. package/a2ui/dockables/lifecycle.js +0 -84
  104. package/a2ui/dockables/provider.js +0 -59
  105. package/a2ui/manifest-runtime.js +0 -226
  106. package/a2ui/registry.js +0 -200
  107. package/a2ui/renderer.js +0 -361
  108. package/a2ui/stream.js +0 -243
  109. package/a2ui/surface-manifest.js +0 -294
  110. package/a2ui/surface.js +0 -222
  111. package/a2ui/wire-factory.js +0 -134
  112. package/a2ui/wiring-engine.js +0 -209
  113. package/a2ui/wiring-registry.js +0 -342
@@ -1,152 +0,0 @@
1
- /**
2
- * ActionDock — Binds a AdiaEvent on a component to a handler.
3
- *
4
- * The AdiaEvent is a typed object: { event, target?, debounce?, throttle?, condition? }
5
- * When the DOM event fires, the handler runs with the surface context.
6
- * onSuccess/onError chains run follow-up handlers based on the outcome.
7
- */
8
- import { Dockable } from './base.js';
9
-
10
- /**
11
- * AdiaEvent type → DOM event name.
12
- * AdiaUI components emit semantic events; these map to the actual DOM event to listen on.
13
- */
14
- const NANO_TO_DOM = {
15
- press: 'click',
16
- submit: 'submit',
17
- input: 'input',
18
- change: 'change',
19
- select: 'select',
20
- toggle: 'change',
21
- dismiss: 'close',
22
- navigate: 'click',
23
- mount: 'connectedCallback',
24
- unmount: 'disconnectedCallback',
25
- focus: 'focusin',
26
- blur: 'focusout',
27
- drag: 'dragstart',
28
- drop: 'drop',
29
- };
30
-
31
- export { NANO_TO_DOM };
32
-
33
- export class ActionDock extends Dockable {
34
- kind = 'action';
35
-
36
- /** @type {string} */
37
- id;
38
-
39
- /** @type {{ event: string, target?: string, debounce?: number, throttle?: number, condition?: object }} */
40
- event;
41
-
42
- /** @type {string} handler name */
43
- handler;
44
-
45
- /** @type {object} handler config */
46
- config;
47
-
48
- /** @type {Array|null} follow-up actions on success */
49
- onSuccess;
50
-
51
- /** @type {Array|null} follow-up actions on error */
52
- onError;
53
-
54
- /** @type {Function} (handlerName) => handlerFn */
55
- #resolveHandler;
56
-
57
- /**
58
- * @param {object} decl — { event, handler, config?, onSuccess?, onError? }
59
- * @param {Function} resolveHandler — (name) => async (config, ctx) => result
60
- */
61
- constructor(decl, resolveHandler) {
62
- super();
63
- this.event = decl.event;
64
- this.handler = decl.handler;
65
- this.config = decl.config || {};
66
- this.onSuccess = decl.onSuccess || null;
67
- this.onError = decl.onError || null;
68
- this.#resolveHandler = resolveHandler;
69
-
70
- // Auto-generate id from event + target
71
- this.id = `action:${this.event.event}:${this.event.target || 'root'}:${this.handler}`;
72
- }
73
-
74
- dock(ctx) {
75
- const target = this.event.target
76
- ? ctx.getElement(this.event.target)
77
- : ctx.getRootElement();
78
-
79
- if (!target) {
80
- console.warn(`ActionDock: target "${this.event.target}" not found`);
81
- return;
82
- }
83
-
84
- const domEventName = NANO_TO_DOM[this.event.event] || this.event.event;
85
- const handlerFn = this.#resolveHandler(this.handler);
86
-
87
- if (!handlerFn) {
88
- console.warn(`ActionDock: unknown handler "${this.handler}"`);
89
- return;
90
- }
91
-
92
- let listener = async (domEvent) => {
93
- // Condition guard
94
- if (this.event.condition) {
95
- const val = ctx.getModel(this.event.condition.path);
96
- if ('equals' in this.event.condition && val !== this.event.condition.equals) return;
97
- if ('notEquals' in this.event.condition && val === this.event.condition.notEquals) return;
98
- if ('exists' in this.event.condition && this.event.condition.exists && val == null) return;
99
- }
100
-
101
- try {
102
- const result = await handlerFn(this.config, ctx, domEvent);
103
-
104
- // Run onSuccess chain
105
- if (this.onSuccess) {
106
- for (const follow of this.onSuccess) {
107
- const followFn = this.#resolveHandler(follow.handler);
108
- if (followFn) await followFn(follow.config || {}, ctx, result);
109
- }
110
- }
111
- } catch (err) {
112
- // Run onError chain
113
- if (this.onError) {
114
- for (const follow of this.onError) {
115
- const followFn = this.#resolveHandler(follow.handler);
116
- if (followFn) await followFn(follow.config || {}, ctx, err);
117
- }
118
- } else {
119
- console.error(`ActionDock: handler "${this.handler}" failed`, err);
120
- }
121
- }
122
- };
123
-
124
- // Debounce
125
- if (this.event.debounce > 0) {
126
- const origListener = listener;
127
- let timer;
128
- listener = (...args) => {
129
- clearTimeout(timer);
130
- timer = setTimeout(() => origListener(...args), this.event.debounce);
131
- };
132
- }
133
-
134
- // Throttle
135
- if (this.event.throttle > 0) {
136
- const origListener = listener;
137
- let last = 0;
138
- listener = (...args) => {
139
- const now = Date.now();
140
- if (now - last >= this.event.throttle) {
141
- last = now;
142
- origListener(...args);
143
- }
144
- };
145
- }
146
-
147
- target.addEventListener(domEventName, listener);
148
- return () => target.removeEventListener(domEventName, listener);
149
- }
150
-
151
- undock() {}
152
- }
@@ -1,30 +0,0 @@
1
- /**
2
- * Dockable — Base class for objects that attach to a Surface.
3
- *
4
- * Every dockable has:
5
- * kind — which port type it uses (controller, source, action, provider, lifecycle)
6
- * id — unique identity within the surface
7
- * dock(context) — attach and return cleanup function
8
- * undock() — teardown
9
- */
10
- export class Dockable {
11
- /** @type {'controller'|'source'|'action'|'provider'|'lifecycle'} */
12
- get kind() { throw new Error('Dockable subclass must define kind'); }
13
-
14
- /** @type {string} */
15
- get id() { throw new Error('Dockable subclass must define id'); }
16
-
17
- /**
18
- * Attach to a surface. Receives the surface context.
19
- * Return a cleanup function, or void.
20
- * @param {import('../surface.js').SurfaceContext} ctx
21
- * @returns {(() => void)|void}
22
- */
23
- dock(ctx) { throw new Error('Dockable subclass must implement dock()'); }
24
-
25
- /**
26
- * Detach from the surface. Cleanup fn from dock() is called
27
- * automatically before this.
28
- */
29
- undock() {}
30
- }
@@ -1,97 +0,0 @@
1
- /**
2
- * ControllerDock — Wraps a AdiaUI controller as a dockable.
3
- *
4
- * Instantiates the controller, connects it to its host element,
5
- * and sets up two-way binding between controller state and model paths.
6
- */
7
- import { Dockable } from './base.js';
8
-
9
- export class ControllerDock extends Dockable {
10
- kind = 'controller';
11
-
12
- /** @type {string} */
13
- id;
14
-
15
- /** @type {string} controller type name, e.g., 'FormController' */
16
- type;
17
-
18
- /** @type {string} component id to attach to */
19
- hostId;
20
-
21
- /** @type {object} controller config */
22
- config;
23
-
24
- /** @type {object|null} model path bindings { stateKey: '/model/path' } */
25
- bind;
26
-
27
- /** @type {import('../../controllers/base.js').BaseController|null} */
28
- controller = null;
29
-
30
- /** @type {Function|null} resolve controller class */
31
- #resolveClass;
32
-
33
- /**
34
- * @param {object} decl — { id, type, host, config?, bind? }
35
- * @param {Function} resolveClass — async (type) => ControllerClass
36
- */
37
- constructor(decl, resolveClass) {
38
- super();
39
- this.id = decl.id;
40
- this.type = decl.type;
41
- this.hostId = decl.host;
42
- this.config = decl.config || {};
43
- this.bind = decl.bind || null;
44
- this.#resolveClass = resolveClass;
45
- }
46
-
47
- async dock(ctx) {
48
- const host = ctx.getElement(this.hostId);
49
- if (!host) {
50
- console.warn(`ControllerDock: host element "${this.hostId}" not found`);
51
- return;
52
- }
53
-
54
- const ControllerClass = await this.#resolveClass(this.type);
55
- if (!ControllerClass) {
56
- console.warn(`ControllerDock: unknown controller type "${this.type}"`);
57
- return;
58
- }
59
-
60
- this.controller = new ControllerClass(this.config);
61
- this.controller.connect(host);
62
-
63
- // Two-way bind: controller state ↔ model paths
64
- const unbinders = [];
65
- if (this.bind) {
66
- for (const [stateKey, modelPath] of Object.entries(this.bind)) {
67
- // Controller → model
68
- if (this.controller.subscribe) {
69
- const unsub = this.controller.subscribe(stateKey, (value) => {
70
- ctx.setModel(modelPath, value);
71
- });
72
- if (unsub) unbinders.push(unsub);
73
- }
74
-
75
- // Model → controller (initial sync)
76
- const initial = ctx.getModel(modelPath);
77
- if (initial !== undefined && this.controller.setState) {
78
- this.controller.setState(stateKey, initial);
79
- }
80
- }
81
- }
82
-
83
- host.controller = this.controller;
84
-
85
- return () => {
86
- host.controller = null;
87
- unbinders.forEach(u => u());
88
- };
89
- }
90
-
91
- undock() {
92
- if (this.controller) {
93
- this.controller.disconnect?.();
94
- this.controller = null;
95
- }
96
- }
97
- }
@@ -1,103 +0,0 @@
1
- /**
2
- * DataSourceDock — Fetches data and pushes it into the surface model.
3
- *
4
- * Supports refresh strategies: once, on-focus, interval:{ms}, stream.
5
- * Re-fetch on demand via refetch() (used by refresh-source handler).
6
- */
7
- import { Dockable } from './base.js';
8
-
9
- export class DataSourceDock extends Dockable {
10
- kind = 'source';
11
-
12
- /** @type {string} */
13
- id;
14
-
15
- /** @type {string} URI template, e.g., "resource://users/{userId}" */
16
- uri;
17
-
18
- /** @type {string} model path to write to */
19
- path;
20
-
21
- /** @type {string} refresh strategy */
22
- refresh;
23
-
24
- /** @type {Function} (uri, params) => data */
25
- #resolveData;
26
-
27
- /** @type {import('../surface.js').SurfaceContext|null} */
28
- #ctx = null;
29
-
30
- /**
31
- * @param {object} decl — { id, uri, path, refresh? }
32
- * @param {Function} resolveData — async (uri, params) => data
33
- */
34
- constructor(decl, resolveData) {
35
- super();
36
- this.id = decl.id;
37
- this.uri = decl.uri;
38
- this.path = decl.path;
39
- this.refresh = decl.refresh || 'once';
40
- this.#resolveData = resolveData;
41
- }
42
-
43
- dock(ctx) {
44
- this.#ctx = ctx;
45
-
46
- // Initial fetch
47
- this.#fetch(ctx);
48
-
49
- // Refresh strategy
50
- if (this.refresh === 'on-focus') {
51
- const handler = () => this.#fetch(ctx);
52
- window.addEventListener('focus', handler);
53
- return () => window.removeEventListener('focus', handler);
54
- }
55
-
56
- if (this.refresh.startsWith('interval:')) {
57
- const ms = parseInt(this.refresh.split(':')[1], 10);
58
- if (ms > 0) {
59
- const id = setInterval(() => this.#fetch(ctx), ms);
60
- return () => clearInterval(id);
61
- }
62
- }
63
-
64
- if (this.refresh === 'stream') {
65
- const resolvedUri = this.#resolveUri(ctx);
66
- try {
67
- const source = new EventSource(resolvedUri);
68
- source.onmessage = (e) => {
69
- try { ctx.setModel(this.path, JSON.parse(e.data)); }
70
- catch { /* malformed data */ }
71
- };
72
- return () => source.close();
73
- } catch {
74
- console.warn(`DataSourceDock: stream failed for ${resolvedUri}`);
75
- }
76
- }
77
- }
78
-
79
- undock() {
80
- this.#ctx = null;
81
- }
82
-
83
- /** Re-fetch on demand (called by refresh-source handler). */
84
- refetch() {
85
- if (this.#ctx) this.#fetch(this.#ctx);
86
- }
87
-
88
- async #fetch(ctx) {
89
- const resolvedUri = this.#resolveUri(ctx);
90
- try {
91
- const data = await this.#resolveData(resolvedUri, ctx);
92
- if (data !== undefined) ctx.setModel(this.path, data);
93
- } catch (err) {
94
- console.warn(`DataSourceDock: fetch failed for ${resolvedUri}`, err);
95
- }
96
- }
97
-
98
- #resolveUri(ctx) {
99
- return this.uri.replace(/\{(\w+)\}/g, (_, key) => {
100
- return ctx.getParam(key) ?? ctx.getModel('/' + key) ?? '';
101
- });
102
- }
103
- }
@@ -1,6 +0,0 @@
1
- export { Dockable } from './base.js';
2
- export { ControllerDock } from './controller.js';
3
- export { DataSourceDock } from './data-source.js';
4
- export { ActionDock, NANO_TO_DOM } from './action.js';
5
- export { ProviderDock } from './provider.js';
6
- export { LifecycleDock } from './lifecycle.js';
@@ -1,84 +0,0 @@
1
- /**
2
- * LifecycleDock — Runs actions on mount, unmount, and model changes.
3
- *
4
- * One per surface. Fires onMount actions immediately on dock,
5
- * watches model paths for changes, and runs onUnmount on undock.
6
- */
7
- import { Dockable } from './base.js';
8
-
9
- export class LifecycleDock extends Dockable {
10
- kind = 'lifecycle';
11
- id = 'lifecycle';
12
-
13
- /** @type {Array} actions to run on mount */
14
- onMount;
15
-
16
- /** @type {Array} actions to run on unmount */
17
- onUnmount;
18
-
19
- /** @type {Array} model path watchers */
20
- onModelChange;
21
-
22
- /** @type {Function} (handlerName) => handlerFn */
23
- #resolveHandler;
24
-
25
- /** @type {import('../surface.js').SurfaceContext|null} */
26
- #ctx = null;
27
-
28
- /**
29
- * @param {object} decl — { onMount?, onUnmount?, onModelChange? }
30
- * @param {Function} resolveHandler — (name) => async (config, ctx) => result
31
- */
32
- constructor(decl, resolveHandler) {
33
- super();
34
- this.onMount = decl.onMount || [];
35
- this.onUnmount = decl.onUnmount || [];
36
- this.onModelChange = decl.onModelChange || [];
37
- this.#resolveHandler = resolveHandler;
38
- }
39
-
40
- dock(ctx) {
41
- this.#ctx = ctx;
42
-
43
- // Run onMount actions
44
- for (const action of this.onMount) {
45
- this.#run(action, ctx);
46
- }
47
-
48
- // Set up model watchers
49
- const unwatchers = this.onModelChange.map((watcher) => {
50
- let handler = () => this.#run(watcher, ctx);
51
-
52
- // Debounce if specified
53
- if (watcher.debounce > 0) {
54
- const origHandler = handler;
55
- let timer;
56
- handler = () => {
57
- clearTimeout(timer);
58
- timer = setTimeout(origHandler, watcher.debounce);
59
- };
60
- }
61
-
62
- return ctx.watchModel(watcher.path, handler);
63
- });
64
-
65
- return () => unwatchers.forEach(u => u());
66
- }
67
-
68
- undock() {
69
- if (this.#ctx) {
70
- for (const action of this.onUnmount) {
71
- this.#run(action, this.#ctx);
72
- }
73
- this.#ctx = null;
74
- }
75
- }
76
-
77
- async #run(action, ctx) {
78
- const fn = this.#resolveHandler(action.handler);
79
- if (fn) {
80
- try { await fn(action.config || {}, ctx); }
81
- catch (err) { console.warn(`LifecycleDock: ${action.handler} failed`, err); }
82
- }
83
- }
84
- }
@@ -1,59 +0,0 @@
1
- /**
2
- * ProviderDock — Injects shared context into a component subtree.
3
- *
4
- * Creates an <a2ui-provider> wrapper around the host element.
5
- * Children can consume the context by name.
6
- */
7
- import { Dockable } from './base.js';
8
-
9
- export class ProviderDock extends Dockable {
10
- kind = 'provider';
11
-
12
- /** @type {string} context name, e.g., "auth" */
13
- id;
14
-
15
- /** @type {string|null} component id to wrap (null = root) */
16
- hostId;
17
-
18
- /** @type {*} initial context value */
19
- value;
20
-
21
- /**
22
- * @param {object} decl — { name, host?, value? }
23
- */
24
- constructor(decl) {
25
- super();
26
- this.id = `provider:${decl.name}`;
27
- this.hostId = decl.host || null;
28
- this.value = decl.value ?? null;
29
- }
30
-
31
- dock(ctx) {
32
- const host = this.hostId
33
- ? ctx.getElement(this.hostId)
34
- : ctx.getRootElement();
35
-
36
- if (!host) {
37
- console.warn(`ProviderDock: host "${this.hostId}" not found`);
38
- return;
39
- }
40
-
41
- const provider = document.createElement('a2ui-provider');
42
- provider.setAttribute('name', this.id.replace('provider:', ''));
43
- provider.value = this.value;
44
-
45
- // Wrap: insert provider before host, move host inside
46
- host.parentNode?.insertBefore(provider, host);
47
- provider.appendChild(host);
48
-
49
- return () => {
50
- // Unwrap: move host back out, remove provider
51
- if (provider.parentNode) {
52
- provider.parentNode.insertBefore(host, provider);
53
- provider.remove();
54
- }
55
- };
56
- }
57
-
58
- undock() {}
59
- }