@dxos/app-framework 0.6.13 → 0.6.14-main.1366248

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 (204) hide show
  1. package/dist/lib/browser/chunk-3E7RY3CE.mjs +72 -0
  2. package/dist/lib/browser/chunk-3E7RY3CE.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-653Y45CL.mjs +41 -0
  4. package/dist/lib/browser/chunk-653Y45CL.mjs.map +7 -0
  5. package/dist/lib/browser/{plugin-MM66VRCO.mjs → chunk-CDLQO5K2.mjs} +66 -20
  6. package/dist/lib/browser/chunk-CDLQO5K2.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-EQTQGGE6.mjs +214 -0
  8. package/dist/lib/browser/chunk-EQTQGGE6.mjs.map +7 -0
  9. package/dist/lib/browser/index.mjs +183 -293
  10. package/dist/lib/browser/index.mjs.map +4 -4
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/plugin-intent-Q5KFPKFA.mjs +22 -0
  13. package/dist/lib/browser/plugin-intent-Q5KFPKFA.mjs.map +7 -0
  14. package/dist/lib/browser/plugin-settings-OM3G2QFY.mjs +11 -0
  15. package/dist/lib/browser/plugin-settings-OM3G2QFY.mjs.map +7 -0
  16. package/dist/lib/browser/plugin-surface-ZQXFAL46.mjs +24 -0
  17. package/dist/lib/browser/plugin-surface-ZQXFAL46.mjs.map +7 -0
  18. package/dist/lib/node/chunk-EF67TRWJ.cjs +236 -0
  19. package/dist/lib/node/chunk-EF67TRWJ.cjs.map +7 -0
  20. package/dist/lib/node/chunk-JZ2JVKRY.cjs +58 -0
  21. package/dist/lib/node/chunk-JZ2JVKRY.cjs.map +7 -0
  22. package/dist/lib/node/{chunk-62W6CMGM.cjs → chunk-QBM42OQ6.cjs} +56 -5
  23. package/dist/lib/node/chunk-QBM42OQ6.cjs.map +7 -0
  24. package/dist/lib/node/{plugin-QV7ESETI.cjs → chunk-VOKMWTKO.cjs} +74 -20
  25. package/dist/lib/node/chunk-VOKMWTKO.cjs.map +7 -0
  26. package/dist/lib/node/index.cjs +195 -310
  27. package/dist/lib/node/index.cjs.map +4 -4
  28. package/dist/lib/node/meta.json +1 -1
  29. package/dist/lib/node/plugin-intent-FMC4SDI3.cjs +43 -0
  30. package/dist/lib/node/plugin-intent-FMC4SDI3.cjs.map +7 -0
  31. package/dist/lib/node/plugin-settings-OZ6IKAE5.cjs +32 -0
  32. package/dist/lib/node/plugin-settings-OZ6IKAE5.cjs.map +7 -0
  33. package/dist/lib/node/{chunk-P5GRB4XF.cjs → plugin-surface-B5NHOBSW.cjs} +19 -22
  34. package/dist/lib/node/plugin-surface-B5NHOBSW.cjs.map +7 -0
  35. package/dist/lib/node-esm/chunk-3FCLBEOX.mjs +215 -0
  36. package/dist/lib/node-esm/chunk-3FCLBEOX.mjs.map +7 -0
  37. package/dist/lib/node-esm/chunk-EYCTSFEJ.mjs +74 -0
  38. package/dist/lib/node-esm/chunk-EYCTSFEJ.mjs.map +7 -0
  39. package/dist/lib/node-esm/chunk-MYNXI5VG.mjs +214 -0
  40. package/dist/lib/node-esm/chunk-MYNXI5VG.mjs.map +7 -0
  41. package/dist/lib/node-esm/chunk-YNU7FTGJ.mjs +43 -0
  42. package/dist/lib/node-esm/chunk-YNU7FTGJ.mjs.map +7 -0
  43. package/dist/lib/node-esm/index.mjs +567 -0
  44. package/dist/lib/node-esm/index.mjs.map +7 -0
  45. package/dist/lib/node-esm/meta.json +1 -0
  46. package/dist/lib/node-esm/plugin-intent-KETLP7UL.mjs +23 -0
  47. package/dist/lib/node-esm/plugin-intent-KETLP7UL.mjs.map +7 -0
  48. package/dist/lib/node-esm/plugin-settings-37UVWF2V.mjs +12 -0
  49. package/dist/lib/node-esm/plugin-settings-37UVWF2V.mjs.map +7 -0
  50. package/dist/lib/node-esm/plugin-surface-QXQRR534.mjs +25 -0
  51. package/dist/lib/node-esm/plugin-surface-QXQRR534.mjs.map +7 -0
  52. package/dist/types/src/App.d.ts +5 -5
  53. package/dist/types/src/App.d.ts.map +1 -1
  54. package/dist/types/src/plugins/common/file.d.ts +1 -1
  55. package/dist/types/src/plugins/common/file.d.ts.map +1 -1
  56. package/dist/types/src/plugins/common/graph.d.ts +1 -1
  57. package/dist/types/src/plugins/common/graph.d.ts.map +1 -1
  58. package/dist/types/src/plugins/common/index.d.ts +0 -1
  59. package/dist/types/src/plugins/common/index.d.ts.map +1 -1
  60. package/dist/types/src/plugins/common/layout.d.ts +6 -6
  61. package/dist/types/src/plugins/common/layout.d.ts.map +1 -1
  62. package/dist/types/src/plugins/common/metadata.d.ts +1 -1
  63. package/dist/types/src/plugins/common/metadata.d.ts.map +1 -1
  64. package/dist/types/src/plugins/common/navigation.d.ts +9 -20
  65. package/dist/types/src/plugins/common/navigation.d.ts.map +1 -1
  66. package/dist/types/src/plugins/common/translations.d.ts +1 -1
  67. package/dist/types/src/plugins/common/translations.d.ts.map +1 -1
  68. package/dist/types/src/plugins/helpers.d.ts +20 -5
  69. package/dist/types/src/plugins/helpers.d.ts.map +1 -1
  70. package/dist/types/src/plugins/index.d.ts +4 -3
  71. package/dist/types/src/plugins/index.d.ts.map +1 -1
  72. package/dist/types/src/plugins/plugin-host/HostPlugin.d.ts +21 -0
  73. package/dist/types/src/plugins/plugin-host/HostPlugin.d.ts.map +1 -0
  74. package/dist/types/src/plugins/plugin-host/PluginContainer.d.ts +14 -0
  75. package/dist/types/src/plugins/plugin-host/PluginContainer.d.ts.map +1 -0
  76. package/dist/types/src/plugins/{PluginHost → plugin-host}/PluginContext.d.ts +4 -4
  77. package/dist/types/src/plugins/plugin-host/PluginContext.d.ts.map +1 -0
  78. package/dist/types/src/plugins/plugin-host/index.d.ts +4 -0
  79. package/dist/types/src/plugins/plugin-host/index.d.ts.map +1 -0
  80. package/dist/types/src/plugins/{PluginHost → plugin-host}/plugin.d.ts +41 -83
  81. package/dist/types/src/plugins/plugin-host/plugin.d.ts.map +1 -0
  82. package/dist/types/src/plugins/plugin-host/plugin.test.d.ts.map +1 -0
  83. package/dist/types/src/plugins/plugin-intent/IntentContext.d.ts.map +1 -0
  84. package/dist/types/src/plugins/{IntentPlugin/plugin.d.ts → plugin-intent/IntentPlugin.d.ts} +3 -4
  85. package/dist/types/src/plugins/plugin-intent/IntentPlugin.d.ts.map +1 -0
  86. package/dist/types/src/plugins/plugin-intent/helpers.d.ts.map +1 -0
  87. package/dist/types/src/plugins/plugin-intent/index.d.ts +6 -0
  88. package/dist/types/src/plugins/plugin-intent/index.d.ts.map +1 -0
  89. package/dist/types/src/plugins/{IntentPlugin → plugin-intent}/intent.d.ts +1 -1
  90. package/dist/types/src/plugins/plugin-intent/intent.d.ts.map +1 -0
  91. package/dist/types/src/plugins/plugin-intent/meta.d.ts.map +1 -0
  92. package/dist/types/src/plugins/{IntentPlugin → plugin-intent}/provides.d.ts +2 -2
  93. package/dist/types/src/plugins/plugin-intent/provides.d.ts.map +1 -0
  94. package/dist/types/src/plugins/plugin-settings/SettingsPlugin.d.ts +4 -0
  95. package/dist/types/src/plugins/plugin-settings/SettingsPlugin.d.ts.map +1 -0
  96. package/dist/types/src/plugins/plugin-settings/index.d.ts +4 -0
  97. package/dist/types/src/plugins/plugin-settings/index.d.ts.map +1 -0
  98. package/dist/types/src/plugins/plugin-settings/meta.d.ts +5 -0
  99. package/dist/types/src/plugins/plugin-settings/meta.d.ts.map +1 -0
  100. package/dist/types/src/plugins/plugin-settings/provides.d.ts +13 -0
  101. package/dist/types/src/plugins/plugin-settings/provides.d.ts.map +1 -0
  102. package/dist/types/src/plugins/plugin-surface/ErrorBoundary.d.ts.map +1 -0
  103. package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/Surface.d.ts +6 -2
  104. package/dist/types/src/plugins/plugin-surface/Surface.d.ts.map +1 -0
  105. package/dist/types/src/plugins/plugin-surface/SurfacePlugin.d.ts +7 -0
  106. package/dist/types/src/plugins/plugin-surface/SurfacePlugin.d.ts.map +1 -0
  107. package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/SurfaceRootContext.d.ts +15 -2
  108. package/dist/types/src/plugins/plugin-surface/SurfaceRootContext.d.ts.map +1 -0
  109. package/dist/types/src/plugins/plugin-surface/helpers.d.ts.map +1 -0
  110. package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/index.d.ts +2 -0
  111. package/dist/types/src/plugins/plugin-surface/index.d.ts.map +1 -0
  112. package/dist/types/src/plugins/plugin-surface/meta.d.ts.map +1 -0
  113. package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/provides.d.ts +1 -1
  114. package/dist/types/src/plugins/plugin-surface/provides.d.ts.map +1 -0
  115. package/package.json +16 -14
  116. package/project.json +3 -8
  117. package/src/App.tsx +18 -16
  118. package/src/plugins/common/file.ts +1 -1
  119. package/src/plugins/common/graph.ts +1 -1
  120. package/src/plugins/common/index.ts +0 -1
  121. package/src/plugins/common/layout.ts +6 -3
  122. package/src/plugins/common/metadata.ts +1 -1
  123. package/src/plugins/common/navigation.ts +10 -15
  124. package/src/plugins/common/translations.ts +2 -8
  125. package/src/plugins/helpers.ts +55 -11
  126. package/src/plugins/index.ts +4 -3
  127. package/src/plugins/plugin-host/HostPlugin.tsx +96 -0
  128. package/src/plugins/plugin-host/PluginContainer.tsx +120 -0
  129. package/src/plugins/{PluginHost → plugin-host}/PluginContext.tsx +9 -14
  130. package/src/plugins/{PluginHost → plugin-host}/index.ts +2 -1
  131. package/src/plugins/{PluginHost → plugin-host}/plugin.test.ts +1 -2
  132. package/src/plugins/{PluginHost → plugin-host}/plugin.ts +50 -52
  133. package/src/plugins/{IntentPlugin/plugin.tsx → plugin-intent/IntentPlugin.tsx} +3 -6
  134. package/src/plugins/{IntentPlugin → plugin-intent}/index.ts +4 -0
  135. package/src/plugins/{IntentPlugin → plugin-intent}/intent.ts +1 -1
  136. package/src/plugins/{IntentPlugin → plugin-intent}/provides.ts +5 -2
  137. package/src/plugins/plugin-settings/SettingsPlugin.tsx +22 -0
  138. package/src/plugins/plugin-settings/index.ts +9 -0
  139. package/src/plugins/plugin-settings/meta.ts +9 -0
  140. package/src/plugins/plugin-settings/provides.ts +29 -0
  141. package/src/plugins/{SurfacePlugin → plugin-surface}/Surface.tsx +74 -40
  142. package/src/plugins/{SurfacePlugin/plugin.tsx → plugin-surface/SurfacePlugin.tsx} +3 -5
  143. package/src/plugins/{SurfacePlugin → plugin-surface}/SurfaceRootContext.tsx +21 -4
  144. package/src/plugins/{SurfacePlugin → plugin-surface}/index.ts +4 -0
  145. package/src/plugins/{SurfacePlugin → plugin-surface}/provides.ts +2 -1
  146. package/tsconfig.json +2 -30
  147. package/vitest.config.ts +9 -0
  148. package/dist/lib/browser/chunk-J45KR4DI.mjs +0 -52
  149. package/dist/lib/browser/chunk-J45KR4DI.mjs.map +0 -7
  150. package/dist/lib/browser/chunk-S5CI6EUQ.mjs +0 -20
  151. package/dist/lib/browser/chunk-S5CI6EUQ.mjs.map +0 -7
  152. package/dist/lib/browser/chunk-YYV26N3W.mjs +0 -26
  153. package/dist/lib/browser/chunk-YYV26N3W.mjs.map +0 -7
  154. package/dist/lib/browser/plugin-K3KCPCTJ.mjs +0 -39
  155. package/dist/lib/browser/plugin-K3KCPCTJ.mjs.map +0 -7
  156. package/dist/lib/browser/plugin-MM66VRCO.mjs.map +0 -7
  157. package/dist/lib/node/chunk-62W6CMGM.cjs.map +0 -7
  158. package/dist/lib/node/chunk-DFST5IG5.cjs +0 -77
  159. package/dist/lib/node/chunk-DFST5IG5.cjs.map +0 -7
  160. package/dist/lib/node/chunk-P5GRB4XF.cjs.map +0 -7
  161. package/dist/lib/node/plugin-QV7ESETI.cjs.map +0 -7
  162. package/dist/lib/node/plugin-RUJ5PEXB.cjs +0 -61
  163. package/dist/lib/node/plugin-RUJ5PEXB.cjs.map +0 -7
  164. package/dist/types/src/plugins/IntentPlugin/IntentContext.d.ts.map +0 -1
  165. package/dist/types/src/plugins/IntentPlugin/helpers.d.ts.map +0 -1
  166. package/dist/types/src/plugins/IntentPlugin/index.d.ts +0 -4
  167. package/dist/types/src/plugins/IntentPlugin/index.d.ts.map +0 -1
  168. package/dist/types/src/plugins/IntentPlugin/intent.d.ts.map +0 -1
  169. package/dist/types/src/plugins/IntentPlugin/meta.d.ts.map +0 -1
  170. package/dist/types/src/plugins/IntentPlugin/plugin.d.ts.map +0 -1
  171. package/dist/types/src/plugins/IntentPlugin/provides.d.ts.map +0 -1
  172. package/dist/types/src/plugins/PluginHost/PluginContext.d.ts.map +0 -1
  173. package/dist/types/src/plugins/PluginHost/PluginHost.d.ts +0 -25
  174. package/dist/types/src/plugins/PluginHost/PluginHost.d.ts.map +0 -1
  175. package/dist/types/src/plugins/PluginHost/index.d.ts +0 -4
  176. package/dist/types/src/plugins/PluginHost/index.d.ts.map +0 -1
  177. package/dist/types/src/plugins/PluginHost/plugin.d.ts.map +0 -1
  178. package/dist/types/src/plugins/PluginHost/plugin.test.d.ts.map +0 -1
  179. package/dist/types/src/plugins/SurfacePlugin/ErrorBoundary.d.ts.map +0 -1
  180. package/dist/types/src/plugins/SurfacePlugin/Surface.d.ts.map +0 -1
  181. package/dist/types/src/plugins/SurfacePlugin/SurfaceRootContext.d.ts.map +0 -1
  182. package/dist/types/src/plugins/SurfacePlugin/helpers.d.ts.map +0 -1
  183. package/dist/types/src/plugins/SurfacePlugin/index.d.ts.map +0 -1
  184. package/dist/types/src/plugins/SurfacePlugin/meta.d.ts.map +0 -1
  185. package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts +0 -8
  186. package/dist/types/src/plugins/SurfacePlugin/plugin.d.ts.map +0 -1
  187. package/dist/types/src/plugins/SurfacePlugin/provides.d.ts.map +0 -1
  188. package/dist/types/src/plugins/common/settings.d.ts +0 -9
  189. package/dist/types/src/plugins/common/settings.d.ts.map +0 -1
  190. package/src/plugins/PluginHost/PluginHost.tsx +0 -198
  191. package/src/plugins/common/settings.ts +0 -22
  192. /package/dist/types/src/plugins/{PluginHost → plugin-host}/plugin.test.d.ts +0 -0
  193. /package/dist/types/src/plugins/{IntentPlugin → plugin-intent}/IntentContext.d.ts +0 -0
  194. /package/dist/types/src/plugins/{IntentPlugin → plugin-intent}/helpers.d.ts +0 -0
  195. /package/dist/types/src/plugins/{IntentPlugin → plugin-intent}/meta.d.ts +0 -0
  196. /package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/ErrorBoundary.d.ts +0 -0
  197. /package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/helpers.d.ts +0 -0
  198. /package/dist/types/src/plugins/{SurfacePlugin → plugin-surface}/meta.d.ts +0 -0
  199. /package/src/plugins/{IntentPlugin → plugin-intent}/IntentContext.tsx +0 -0
  200. /package/src/plugins/{IntentPlugin → plugin-intent}/helpers.ts +0 -0
  201. /package/src/plugins/{IntentPlugin → plugin-intent}/meta.ts +0 -0
  202. /package/src/plugins/{SurfacePlugin → plugin-surface}/ErrorBoundary.tsx +0 -0
  203. /package/src/plugins/{SurfacePlugin → plugin-surface}/helpers.ts +0 -0
  204. /package/src/plugins/{SurfacePlugin → plugin-surface}/meta.ts +0 -0
@@ -0,0 +1,236 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var chunk_EF67TRWJ_exports = {};
30
+ __export(chunk_EF67TRWJ_exports, {
31
+ ErrorBoundary: () => ErrorBoundary,
32
+ Surface: () => Surface,
33
+ SurfaceProvider: () => SurfaceProvider,
34
+ isObject: () => isObject,
35
+ meta_default: () => meta_default,
36
+ parseRootSurfacePlugin: () => parseRootSurfacePlugin,
37
+ parseSurfacePlugin: () => parseSurfacePlugin,
38
+ plugin_surface_default: () => plugin_surface_default,
39
+ useSurface: () => useSurface,
40
+ useSurfaceRoot: () => useSurfaceRoot
41
+ });
42
+ module.exports = __toCommonJS(chunk_EF67TRWJ_exports);
43
+ var import_chunk_QBM42OQ6 = require("./chunk-QBM42OQ6.cjs");
44
+ var import_react = __toESM(require("react"));
45
+ var import_echo_schema = require("@dxos/echo-schema");
46
+ var import_react2 = require("react");
47
+ var import_debug = require("@dxos/debug");
48
+ var import_react3 = __toESM(require("react"));
49
+ var import_react4 = __toESM(require("react"));
50
+ var import_debug2 = require("@dxos/debug");
51
+ var import_log = require("@dxos/log");
52
+ var SurfaceRootContext = /* @__PURE__ */ (0, import_react2.createContext)(void 0);
53
+ var useSurfaceRoot = () => (0, import_react2.useContext)(SurfaceRootContext) ?? (0, import_debug.raise)(new Error("Missing SurfaceRootContext"));
54
+ var SurfaceProvider = SurfaceRootContext.Provider;
55
+ var SurfaceMeta = {
56
+ id: "dxos.org/plugin/surface"
57
+ };
58
+ var meta_default = SurfaceMeta;
59
+ var parseRootSurfacePlugin = (plugin) => plugin?.provides?.surface?.components ? plugin : void 0;
60
+ var parseSurfacePlugin = (plugin) => plugin?.provides?.surface?.component ? plugin : void 0;
61
+ var SurfacePlugin = () => {
62
+ const state = (0, import_echo_schema.create)({
63
+ components: {},
64
+ debugInfo: /* @__PURE__ */ new Map()
65
+ });
66
+ return {
67
+ meta: meta_default,
68
+ ready: async (plugins) => {
69
+ state.components = (0, import_chunk_QBM42OQ6.filterPlugins)(plugins, parseSurfacePlugin).reduce((acc, plugin) => {
70
+ return {
71
+ ...acc,
72
+ [plugin.meta.id]: plugin.provides.surface.component
73
+ };
74
+ }, {});
75
+ },
76
+ provides: {
77
+ surface: state,
78
+ context: ({ children }) => /* @__PURE__ */ import_react.default.createElement(SurfaceProvider, {
79
+ value: state
80
+ }, children)
81
+ }
82
+ };
83
+ };
84
+ var isObject = (data) => !!data && typeof data === "object";
85
+ var ErrorBoundary = class extends import_react3.Component {
86
+ constructor(props) {
87
+ super(props);
88
+ this.state = {
89
+ error: void 0
90
+ };
91
+ }
92
+ static getDerivedStateFromError(error) {
93
+ return {
94
+ error
95
+ };
96
+ }
97
+ componentDidUpdate(prevProps) {
98
+ if (prevProps.data !== this.props.data) {
99
+ this.resetError();
100
+ }
101
+ }
102
+ render() {
103
+ if (this.state.error) {
104
+ return /* @__PURE__ */ import_react3.default.createElement(this.props.fallback, {
105
+ data: this.props.data,
106
+ error: this.state.error,
107
+ reset: this.resetError
108
+ });
109
+ }
110
+ return this.props.children;
111
+ }
112
+ resetError() {
113
+ this.setState({
114
+ error: void 0
115
+ });
116
+ }
117
+ };
118
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/plugin-surface/Surface.tsx";
119
+ var count = 0;
120
+ var Surface = /* @__PURE__ */ (0, import_react4.memo)(/* @__PURE__ */ (0, import_react4.forwardRef)(({ id: _id, role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {
121
+ const props = {
122
+ role,
123
+ name,
124
+ fallback,
125
+ ...rest
126
+ };
127
+ const { debugInfo } = useSurfaceRoot();
128
+ const [id] = (0, import_react4.useState)(() => _id ?? `surface-${++count}`);
129
+ (0, import_react4.useEffect)(() => {
130
+ debugInfo?.set(id, {
131
+ id,
132
+ created: Date.now(),
133
+ name,
134
+ role,
135
+ renderCount: 0
136
+ });
137
+ return () => {
138
+ debugInfo?.delete(id);
139
+ };
140
+ }, [
141
+ id
142
+ ]);
143
+ if (debugInfo?.get(id)) {
144
+ debugInfo.get(id).renderCount++;
145
+ }
146
+ const context = (0, import_react4.useContext)(SurfaceContext);
147
+ const data = props.data ?? (name && context?.surfaces?.[name]?.data || {});
148
+ const resolver = /* @__PURE__ */ import_react4.default.createElement(SurfaceResolver, {
149
+ ...props,
150
+ id,
151
+ ref: forwardedRef
152
+ });
153
+ const suspense = placeholder ? /* @__PURE__ */ import_react4.default.createElement(import_react4.Suspense, {
154
+ fallback: placeholder
155
+ }, resolver) : resolver;
156
+ return fallback ? /* @__PURE__ */ import_react4.default.createElement(ErrorBoundary, {
157
+ data,
158
+ fallback
159
+ }, suspense) : suspense;
160
+ }));
161
+ var SurfaceContext = /* @__PURE__ */ (0, import_react4.createContext)(void 0);
162
+ var useSurface = () => (0, import_react4.useContext)(SurfaceContext) ?? (0, import_debug2.raise)(new Error("Surface context not found"));
163
+ var SurfaceResolver = /* @__PURE__ */ (0, import_react4.forwardRef)((props, forwardedRef) => {
164
+ const { components } = useSurfaceRoot();
165
+ const parent = (0, import_react4.useContext)(SurfaceContext);
166
+ const nodes = resolveNodes(components, props, parent, forwardedRef);
167
+ const currentContext = {
168
+ ...props,
169
+ surfaces: {
170
+ ...props.name && parent?.surfaces?.[props.name]?.surfaces || {},
171
+ ...props.surfaces
172
+ }
173
+ };
174
+ return /* @__PURE__ */ import_react4.default.createElement(SurfaceContext.Provider, {
175
+ value: currentContext
176
+ }, nodes);
177
+ });
178
+ var resolveNodes = (components, props, context, forwardedRef) => {
179
+ const data = {
180
+ ...props.name && context?.surfaces?.[props.name]?.data || {},
181
+ ...props.data
182
+ };
183
+ const candidates = Object.entries(components).map(([key, component]) => {
184
+ const result = component({
185
+ ...props,
186
+ data
187
+ }, forwardedRef);
188
+ if (!result || typeof result !== "object") {
189
+ return void 0;
190
+ }
191
+ if ("node" in result) {
192
+ return [
193
+ key,
194
+ result
195
+ ];
196
+ } else if (/* @__PURE__ */ (0, import_react4.isValidElement)(result)) {
197
+ return [
198
+ key,
199
+ {
200
+ node: result
201
+ }
202
+ ];
203
+ } else {
204
+ import_log.log.warn("invalid result", {
205
+ result
206
+ }, {
207
+ F: __dxlog_file,
208
+ L: 183,
209
+ S: void 0,
210
+ C: (f, a) => f(...a)
211
+ });
212
+ return void 0;
213
+ }
214
+ }).filter((result) => Boolean(result)).sort(([, { disposition: a = "default" }], [, { disposition: b = "default" }]) => {
215
+ return a === b ? 0 : a === "hoist" || b === "fallback" ? -1 : b === "hoist" || a === "fallback" ? 1 : 0;
216
+ });
217
+ const nodes = candidates.map(([key, result]) => /* @__PURE__ */ import_react4.default.createElement(import_react4.Fragment, {
218
+ key
219
+ }, result.node));
220
+ return props.limit ? nodes.slice(0, props.limit) : nodes;
221
+ };
222
+ var plugin_surface_default = SurfacePlugin;
223
+ // Annotate the CommonJS export names for ESM import in node:
224
+ 0 && (module.exports = {
225
+ ErrorBoundary,
226
+ Surface,
227
+ SurfaceProvider,
228
+ isObject,
229
+ meta_default,
230
+ parseRootSurfacePlugin,
231
+ parseSurfacePlugin,
232
+ plugin_surface_default,
233
+ useSurface,
234
+ useSurfaceRoot
235
+ });
236
+ //# sourceMappingURL=chunk-EF67TRWJ.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/plugins/plugin-surface/SurfacePlugin.tsx", "../../../src/plugins/plugin-surface/SurfaceRootContext.tsx", "../../../src/plugins/plugin-surface/meta.ts", "../../../src/plugins/plugin-surface/provides.ts", "../../../src/plugins/plugin-surface/helpers.ts", "../../../src/plugins/plugin-surface/ErrorBoundary.tsx", "../../../src/plugins/plugin-surface/Surface.tsx", "../../../src/plugins/plugin-surface/index.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { create } from '@dxos/echo-schema';\n\nimport { SurfaceProvider, type SurfaceRootContext } from './SurfaceRootContext';\nimport SurfaceMeta from './meta';\nimport { parseSurfacePlugin, type SurfacePluginProvides } from './provides';\nimport { filterPlugins } from '../helpers';\nimport { type PluginDefinition } from '../plugin-host';\n\n/**\n * Provides a registry of surface components.\n */\nexport const SurfacePlugin = (): PluginDefinition<SurfacePluginProvides> => {\n const state = create<SurfaceRootContext>({ components: {}, debugInfo: new Map() });\n\n return {\n meta: SurfaceMeta,\n ready: async (plugins) => {\n state.components = filterPlugins(plugins, parseSurfacePlugin).reduce((acc, plugin) => {\n return { ...acc, [plugin.meta.id]: plugin.provides.surface.component };\n }, {});\n },\n provides: {\n surface: state,\n context: ({ children }) => <SurfaceProvider value={state}>{children}</SurfaceProvider>,\n },\n };\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { createContext, useContext, type JSX, type ForwardedRef } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { type SurfaceProps } from './Surface';\n\n// TODO(wittjosiah): Factor out.\ntype WithRequiredProperty<Type, Key extends keyof Type> = Type & {\n [Property in Key]-?: Type[Property];\n};\n\ntype SurfaceComponentProps = WithRequiredProperty<SurfaceProps, 'data'>;\n\n/**\n * Determines the priority of the surface when multiple components are resolved.\n */\nexport type SurfaceDisposition = 'hoist' | 'fallback';\n\n/**\n * Surface debug info.\n * NOTE: Short-term measure to track perf issues.\n */\nexport type DebugInfo = {\n id: string;\n created: number;\n renderCount: number;\n} & Pick<SurfaceProps, 'role' | 'name'>;\n\nexport type SurfaceResult = {\n node: JSX.Element;\n disposition?: SurfaceDisposition;\n};\n\n/**\n * Function which resolves a Surface.\n *\n * If a null value is returned, the rendering is deferred to other plugins.\n */\nexport type SurfaceComponent = (\n props: SurfaceComponentProps,\n forwardedRef: ForwardedRef<HTMLElement>,\n) => JSX.Element | SurfaceResult | null;\n\nexport type SurfaceRootContext = {\n components: Record<string, SurfaceComponent>;\n\n /**\n * Debug info.\n */\n debugInfo?: Map<string, DebugInfo>;\n};\n\nconst SurfaceRootContext = createContext<SurfaceRootContext | undefined>(undefined);\n\nexport const useSurfaceRoot = () => useContext(SurfaceRootContext) ?? raise(new Error('Missing SurfaceRootContext'));\n\nexport const SurfaceProvider = SurfaceRootContext.Provider;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst SurfaceMeta = {\n id: 'dxos.org/plugin/surface',\n};\n\nexport default SurfaceMeta;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type SurfaceComponent, type SurfaceRootContext } from './SurfaceRootContext';\nimport { type Plugin } from '../plugin-host';\n\n// TODO(burdon): Predicate based providers?\nexport type SurfaceProvides = {\n surface: {\n /**\n * Used by the `Surface` resolver to find a component to render.\n */\n component: SurfaceComponent;\n };\n};\n\nexport type SurfacePluginProvides = {\n surface: SurfaceRootContext;\n};\n\nexport const parseRootSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.components ? (plugin as Plugin<SurfacePluginProvides>) : undefined;\n\nexport const parseSurfacePlugin = (plugin?: Plugin) =>\n (plugin?.provides as any)?.surface?.component ? (plugin as Plugin<SurfaceProvides>) : undefined;\n", "//\n// Copyright 2023 DXOS.org\n//\n\n/**\n * Checks if the given data is an object and not null.\n *\n * Useful inside surface component resolvers as a type guard.\n *\n * @example\n * ```ts\n * const old =\n * data.content &&\n * typeof data.content === 'object' &&\n * 'id' in data.content &&\n * typeof data.content.id === 'string';\n *\n * // becomes\n * const new = isObject(data.content) && typeof data.content.id === 'string';\n * ```\n */\nexport const isObject = (data: unknown): data is { [key: string]: unknown } => !!data && typeof data === 'object';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { Component, type FC, type PropsWithChildren } from 'react';\n\ntype Props = PropsWithChildren<{ data?: any; fallback: FC<{ data?: any; error: Error; reset: () => void }> }>;\ntype State = { error: Error | undefined };\n\n/**\n * Surface error boundary.\n *\n * For basic usage prefer providing a fallback component to `Surface`.\n *\n * For more information on error boundaries, see:\n * https://react.dev/reference/react/Component#catching-rendering-errors-with-an-error-boundary\n */\nexport class ErrorBoundary extends Component<Props, State> {\n constructor(props: Props) {\n super(props);\n this.state = { error: undefined };\n }\n\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n\n override componentDidUpdate(prevProps: Props): void {\n if (prevProps.data !== this.props.data) {\n this.resetError();\n }\n }\n\n override render() {\n if (this.state.error) {\n return <this.props.fallback data={this.props.data} error={this.state.error} reset={this.resetError} />;\n }\n\n return this.props.children;\n }\n\n private resetError() {\n this.setState({ error: undefined });\n }\n}\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport React, {\n Fragment,\n type ForwardedRef,\n type PropsWithChildren,\n type ReactNode,\n Suspense,\n createContext,\n forwardRef,\n isValidElement,\n memo,\n useContext,\n useEffect,\n useState,\n} from 'react';\n\nimport { raise } from '@dxos/debug';\nimport { log } from '@dxos/log';\n\nimport { ErrorBoundary } from './ErrorBoundary';\nimport { type SurfaceComponent, type SurfaceResult, useSurfaceRoot } from './SurfaceRootContext';\n\n/**\n * Direction determines how multiple components are laid out.\n */\nexport type Direction = 'inline' | 'inline-reverse' | 'block' | 'block-reverse';\n\n/**\n * SurfaceProps are the props that are passed to the Surface component.\n */\nexport type SurfaceProps = PropsWithChildren<{\n /**\n * Optional ID for debugging.\n */\n id?: string;\n\n /**\n * Role defines how the data should be rendered.\n */\n role?: string;\n\n /**\n * Names allow nested surfaces to be specified in the parent context, similar to a slot.\n * Defaults to the value of `role` if not specified.\n */\n name?: string;\n\n /**\n * The data to be rendered by the surface.\n */\n data?: Record<string, unknown>;\n\n /**\n * Configure nested surfaces (indexed by the surface's `name`).\n */\n surfaces?: Record<string, Pick<SurfaceProps, 'data' | 'surfaces'>>;\n\n /**\n * If specified, the Surface will be wrapped in an error boundary.\n * The fallback component will be rendered if an error occurs.\n */\n fallback?: ErrorBoundary['props']['fallback'];\n\n /**\n * If specified, the Surface will be wrapped in a suspense boundary.\n * The placeholder component will be rendered while the surface component is loading.\n */\n placeholder?: ReactNode;\n\n /**\n * If more than one component is resolved, the limit determines how many are rendered.\n */\n limit?: number | undefined;\n\n /**\n * If more than one component is resolved, the direction determines how they are laid out.\n * NOTE: This is not yet implemented.\n */\n direction?: Direction;\n\n /**\n * Additional props to pass to the component.\n * These props are not used by Surface itself but may be used by components which resolve the surface.\n */\n [key: string]: unknown;\n}>;\n\nlet count = 0;\n\n/**\n * A surface is a named region of the screen that can be populated by plugins.\n */\nexport const Surface = memo(\n forwardRef<HTMLElement, SurfaceProps>(\n ({ id: _id, role, name = role, fallback, placeholder, ...rest }, forwardedRef) => {\n const props = { role, name, fallback, ...rest };\n const { debugInfo } = useSurfaceRoot();\n\n // Track debug info.\n const [id] = useState<string>(() => _id ?? `surface-${++count}`);\n useEffect(() => {\n debugInfo?.set(id, { id, created: Date.now(), name, role, renderCount: 0 });\n return () => {\n debugInfo?.delete(id);\n };\n }, [id]);\n\n if (debugInfo?.get(id)) {\n debugInfo.get(id)!.renderCount++;\n }\n\n const context = useContext(SurfaceContext);\n const data = props.data ?? ((name && context?.surfaces?.[name]?.data) || {});\n\n const resolver = <SurfaceResolver {...props} id={id} ref={forwardedRef} />;\n const suspense = placeholder ? <Suspense fallback={placeholder}>{resolver}</Suspense> : resolver;\n\n return fallback ? (\n <ErrorBoundary data={data} fallback={fallback}>\n {suspense}\n </ErrorBoundary>\n ) : (\n suspense\n );\n },\n ),\n);\n\nconst SurfaceContext = createContext<SurfaceProps | undefined>(undefined);\n\nexport const useSurface = (): SurfaceProps =>\n useContext(SurfaceContext) ?? raise(new Error('Surface context not found'));\n\n/**\n * Root surface component.\n */\nconst SurfaceResolver = forwardRef<HTMLElement, SurfaceProps>((props, forwardedRef) => {\n const { components } = useSurfaceRoot();\n const parent = useContext(SurfaceContext);\n const nodes = resolveNodes(components, props, parent, forwardedRef);\n const currentContext: SurfaceProps = {\n ...props,\n surfaces: {\n ...((props.name && parent?.surfaces?.[props.name]?.surfaces) || {}),\n ...props.surfaces,\n },\n };\n\n return <SurfaceContext.Provider value={currentContext}>{nodes}</SurfaceContext.Provider>;\n});\n\n/**\n * Resolve surface nodes from across all component.\n */\nconst resolveNodes = (\n components: Record<string, SurfaceComponent>,\n props: SurfaceProps,\n context: SurfaceProps | undefined,\n forwardedRef: ForwardedRef<HTMLElement>,\n): ReactNode[] => {\n const data = {\n ...((props.name && context?.surfaces?.[props.name]?.data) || {}),\n ...props.data,\n };\n\n const candidates = Object.entries(components)\n .map(([key, component]): [string, SurfaceResult] | undefined => {\n // TODO(burdon): Avoid variable return types in plugin contract.\n const result = component({ ...props, data }, forwardedRef);\n if (!result || typeof result !== 'object') {\n return undefined;\n }\n\n // Normalize tuple.\n if ('node' in result) {\n return [key, result];\n } else if (isValidElement(result)) {\n return [key, { node: result }];\n } else {\n log.warn('invalid result', { result });\n return undefined;\n }\n })\n .filter((result): result is [string, SurfaceResult] => Boolean(result))\n .sort(([, { disposition: a = 'default' }], [, { disposition: b = 'default' }]) => {\n return a === b ? 0 : a === 'hoist' || b === 'fallback' ? -1 : b === 'hoist' || a === 'fallback' ? 1 : 0;\n });\n\n // TODO(burdon): Does this prematurely process the node?\n const nodes = candidates.map(([key, result]) => <Fragment key={key}>{result.node}</Fragment>);\n return props.limit ? nodes.slice(0, props.limit) : nodes;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { SurfacePlugin } from './SurfacePlugin';\n\nexport * from './helpers';\nexport * from './provides';\n\nexport * from './ErrorBoundary';\nexport * from './Surface';\nexport * from './SurfaceRootContext';\n\nexport default SurfacePlugin;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAAkB;AAElB,yBAAuB;ACFvB,IAAAA,gBAAuE;AAEvE,mBAAsB;AIFtB,IAAAA,gBAAkE;ACAlE,IAAAA,gBAaO;AAEP,IAAAC,gBA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Q;AACpB,aAAO;QAACD;QAAKC;;IACf,WAAWC,kDAAeD,MAAAA,GAAS;AACjC,aAAO;QAACD;QAAK;UAAEG,MAAMF;QAAO;;IAC9B,OAAO;AACLG,qBAAIC,KAAK,kBAAkB;QAAEJ;MAAO,GAAA;;;;;;AACpC,aAAOnF;IACT;EACF,CAAA,EACCwF,OAAO,CAACL,WAA8CM,QAAQN,MAAAA,CAAAA,EAC9DO,KAAK,CAAC,CAAA,EAAG,EAAEC,aAAaC,IAAI,UAAS,CAAE,GAAG,CAAA,EAAG,EAAED,aAAaE,IAAI,UAAS,CAAE,MAAC;AAC3E,WAAOD,MAAMC,IAAI,IAAID,MAAM,WAAWC,MAAM,aAAa,KAAKA,MAAM,WAAWD,MAAM,aAAa,IAAI;EACxG,CAAA;AAGF,QAAMjB,QAAQG,WAAWG,IAAI,CAAC,CAACC,KAAKC,MAAAA,MAAYtD,8BAAAA,QAAA,cAACiE,wBAAAA;IAASZ;KAAWC,OAAOE,IAAI,CAAA;AAChF,SAAOjD,MAAM2D,QAAQpB,MAAMqB,MAAM,GAAG5D,MAAM2D,KAAK,IAAIpB;AACrD;ACrLA,IAAA,yBAAe3D;",
6
+ "names": ["import_react", "import_debug", "SurfaceRootContext", "createContext", "undefined", "useSurfaceRoot", "useContext", "raise", "Error", "SurfaceProvider", "Provider", "SurfaceMeta", "id", "parseRootSurfacePlugin", "plugin", "provides", "surface", "components", "parseSurfacePlugin", "component", "SurfacePlugin", "state", "create", "debugInfo", "Map", "meta", "ready", "plugins", "filterPlugins", "reduce", "acc", "context", "children", "React", "value", "isObject", "data", "ErrorBoundary", "Component", "constructor", "props", "error", "getDerivedStateFromError", "componentDidUpdate", "prevProps", "resetError", "render", "this", "fallback", "reset", "setState", "count", "Surface", "memo", "forwardRef", "_id", "role", "name", "placeholder", "rest", "forwardedRef", "useState", "useEffect", "set", "created", "Date", "now", "renderCount", "delete", "get", "SurfaceContext", "surfaces", "resolver", "SurfaceResolver", "ref", "suspense", "Suspense", "useSurface", "parent", "nodes", "resolveNodes", "currentContext", "candidates", "Object", "entries", "map", "key", "result", "isValidElement", "node", "log", "warn", "filter", "Boolean", "sort", "disposition", "a", "b", "Fragment", "limit", "slice"]
7
+ }
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var chunk_JZ2JVKRY_exports = {};
20
+ __export(chunk_JZ2JVKRY_exports, {
21
+ SettingsAction: () => SettingsAction,
22
+ meta_default: () => meta_default,
23
+ parseSettingsPlugin: () => parseSettingsPlugin,
24
+ plugin_settings_default: () => plugin_settings_default
25
+ });
26
+ module.exports = __toCommonJS(chunk_JZ2JVKRY_exports);
27
+ var import_local_storage = require("@dxos/local-storage");
28
+ var SettingsMeta = {
29
+ id: "dxos.org/plugin/settings"
30
+ };
31
+ var meta_default = SettingsMeta;
32
+ var SettingsPlugin = () => {
33
+ const settingsStore = new import_local_storage.RootSettingsStore();
34
+ return {
35
+ meta: meta_default,
36
+ provides: {
37
+ settingsStore
38
+ }
39
+ };
40
+ };
41
+ var parseSettingsPlugin = (plugin) => {
42
+ return typeof plugin.provides.settingsStore === "object" ? plugin : void 0;
43
+ };
44
+ var SETTINGS_PLUGIN = "dxos.org/plugin/settings";
45
+ var SETTINGS_ACTION = `${SETTINGS_PLUGIN}/action`;
46
+ var SettingsAction;
47
+ (function(SettingsAction2) {
48
+ SettingsAction2[SettingsAction2["OPEN"] = `${SETTINGS_ACTION}/open`] = "OPEN";
49
+ })(SettingsAction || (SettingsAction = {}));
50
+ var plugin_settings_default = SettingsPlugin;
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ SettingsAction,
54
+ meta_default,
55
+ parseSettingsPlugin,
56
+ plugin_settings_default
57
+ });
58
+ //# sourceMappingURL=chunk-JZ2JVKRY.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/plugins/plugin-settings/SettingsPlugin.tsx", "../../../src/plugins/plugin-settings/meta.ts", "../../../src/plugins/plugin-settings/provides.ts", "../../../src/plugins/plugin-settings/index.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { RootSettingsStore } from '@dxos/local-storage';\n\nimport SettingsMeta from './meta';\nimport { type SettingsPluginProvides } from './provides';\nimport { type PluginDefinition } from '../plugin-host';\n\nexport const SettingsPlugin = (): PluginDefinition<SettingsPluginProvides> => {\n // Global settings singleton.\n // TODO(burdon): Make settings storage extensible so that other plugins can decide the persistence of them.\n const settingsStore = new RootSettingsStore();\n\n return {\n meta: SettingsMeta,\n provides: {\n settingsStore,\n },\n };\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst SettingsMeta = {\n id: 'dxos.org/plugin/settings',\n};\n\nexport default SettingsMeta;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type SettingsStoreFactory, type SettingsValue } from '@dxos/local-storage';\n\nimport { type Plugin } from '../plugin-host';\n\nexport type SettingsProvides<T extends SettingsValue> = {\n settings: T;\n};\n\nexport type SettingsPluginProvides = {\n settingsStore: SettingsStoreFactory;\n};\n\nexport const parseSettingsPlugin = (plugin: Plugin) => {\n return typeof (plugin.provides as any).settingsStore === 'object'\n ? (plugin as Plugin<SettingsPluginProvides>)\n : undefined;\n};\n\nconst SETTINGS_PLUGIN = 'dxos.org/plugin/settings';\n\nconst SETTINGS_ACTION = `${SETTINGS_PLUGIN}/action`;\n\nexport enum SettingsAction {\n OPEN = `${SETTINGS_ACTION}/open`,\n}\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { SettingsPlugin } from './SettingsPlugin';\n\nexport * from './provides';\n\nexport default SettingsPlugin;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,2BAAkC;ACAlC,IAAMA,eAAe;EACnBC,IAAI;AACN;AAEA,IAAA,eAAeD;ADER,IAAME,iBAAiB,MAAA;AAG5B,QAAMC,gBAAgB,IAAIC,uCAAAA;AAE1B,SAAO;IACLC,MAAML;IACNM,UAAU;MACRH;IACF;EACF;AACF;AELO,IAAMI,sBAAsB,CAACC,WAAAA;AAClC,SAAO,OAAQA,OAAOF,SAAiBH,kBAAkB,WACpDK,SACDC;AACN;AAEA,IAAMC,kBAAkB;AAExB,IAAMC,kBAAkB,GAAGD,eAAAA;;UAEfE,iBAAAA;4CACH,GAAGD,eAAAA,OAAsB,IAAA;GADtBC,mBAAAA,iBAAAA,CAAAA,EAAAA;AClBZ,IAAA,0BAAeV;",
6
+ "names": ["SettingsMeta", "id", "SettingsPlugin", "settingsStore", "RootSettingsStore", "meta", "provides", "parseSettingsPlugin", "plugin", "undefined", "SETTINGS_PLUGIN", "SETTINGS_ACTION", "SettingsAction"]
7
+ }
@@ -16,17 +16,19 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_62W6CMGM_exports = {};
20
- __export(chunk_62W6CMGM_exports, {
19
+ var chunk_QBM42OQ6_exports = {};
20
+ __export(chunk_QBM42OQ6_exports, {
21
21
  definePlugin: () => definePlugin,
22
22
  filterPlugins: () => filterPlugins,
23
23
  findPlugin: () => findPlugin,
24
24
  getPlugin: () => getPlugin,
25
25
  resolvePlugin: () => resolvePlugin
26
26
  });
27
- module.exports = __toCommonJS(chunk_62W6CMGM_exports);
27
+ module.exports = __toCommonJS(chunk_QBM42OQ6_exports);
28
+ var import_context = require("@dxos/context");
28
29
  var import_debug = require("@dxos/debug");
29
- var definePlugin = (plugin) => plugin;
30
+ var import_invariant = require("@dxos/invariant");
31
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/helpers.ts";
30
32
  var findPlugin = (plugins, id) => {
31
33
  return plugins.find((plugin) => plugin.meta.id === id || typeof plugin.meta.shortId === "string" && plugin.meta.shortId === id);
32
34
  };
@@ -35,6 +37,55 @@ var getPlugin = (plugins, id) => {
35
37
  };
36
38
  var filterPlugins = (plugins, predicate) => plugins.map((plugin) => predicate(plugin)).filter((plugin) => !!plugin);
37
39
  var resolvePlugin = (plugins, predicate) => filterPlugins(plugins, predicate)[0];
40
+ var PluginContext = class {
41
+ constructor() {
42
+ this.ctx = new import_context.Context(void 0, {
43
+ F: __dxlog_file,
44
+ L: 50
45
+ });
46
+ }
47
+ init(plugins) {
48
+ this._plugins = plugins;
49
+ }
50
+ getPlugin(id) {
51
+ (0, import_invariant.invariant)(this._plugins, void 0, {
52
+ F: __dxlog_file,
53
+ L: 59,
54
+ S: this,
55
+ A: [
56
+ "this._plugins",
57
+ ""
58
+ ]
59
+ });
60
+ return getPlugin(this._plugins, id);
61
+ }
62
+ resolvePlugin(resolver, required = false) {
63
+ (0, import_invariant.invariant)(this._plugins, "context not initialized", {
64
+ F: __dxlog_file,
65
+ L: 65,
66
+ S: this,
67
+ A: [
68
+ "this._plugins",
69
+ "'context not initialized'"
70
+ ]
71
+ });
72
+ const plugin = resolvePlugin(this._plugins, resolver);
73
+ if (required && !plugin) {
74
+ throw new Error("Plugin not found.");
75
+ }
76
+ return plugin;
77
+ }
78
+ onDispose(cb) {
79
+ this.ctx.onDispose(cb);
80
+ }
81
+ dispose() {
82
+ void this.ctx.dispose();
83
+ }
84
+ };
85
+ var definePlugin = (cb) => {
86
+ const context = new PluginContext();
87
+ return () => cb(context);
88
+ };
38
89
  // Annotate the CommonJS export names for ESM import in node:
39
90
  0 && (module.exports = {
40
91
  definePlugin,
@@ -43,4 +94,4 @@ var resolvePlugin = (plugins, predicate) => filterPlugins(plugins, predicate)[0]
43
94
  getPlugin,
44
95
  resolvePlugin
45
96
  });
46
- //# sourceMappingURL=chunk-62W6CMGM.cjs.map
97
+ //# sourceMappingURL=chunk-QBM42OQ6.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/plugins/helpers.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Context, type DisposeCallback } from '@dxos/context';\nimport { raise } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\n\nimport { type Plugin, type PluginDefinition } from './plugin-host';\n\n/**\n * Resolvers allow different instances of plugins to provide a particular capability.\n */\nexport type PluginResolver<T> = (plugin: Plugin) => Plugin<T> | undefined;\n\n/**\n * Find a plugin by ID.\n */\nexport const findPlugin = <T>(plugins: Plugin[], id: string): Plugin<T> | undefined => {\n return plugins.find(\n (plugin) => plugin.meta.id === id || (typeof plugin.meta.shortId === 'string' && plugin.meta.shortId === id),\n ) as Plugin<T>;\n};\n\n/**\n * Find a plugin by ID, or raise an error if not found.\n */\nexport const getPlugin = <T>(plugins: Plugin[], id: string): Plugin<T> => {\n return findPlugin(plugins, id) ?? raise(new Error(`Plugin not found: ${id}`));\n};\n\n/**\n * Filter a list of plugins to only those that match a predicate.\n */\nexport const filterPlugins = <T>(plugins: Plugin[], predicate: PluginResolver<T>): Plugin<T>[] =>\n plugins.map((plugin) => predicate(plugin)).filter((plugin): plugin is Plugin<T> => !!plugin);\n\n/**\n * Resolves a plugin by predicate.\n *\n * @example\n * import { parseIntentPlugin, resolvePlugin } from '@dxos/app-framework';\n * const intentPlugin = resolvePlugin(plugins, parseIntentPlugin);\n */\nexport const resolvePlugin = <T>(plugins: Plugin[], predicate: PluginResolver<T>): Plugin<T> | undefined =>\n filterPlugins(plugins, predicate)[0];\n\nclass PluginContext {\n // TODO(burdon): Use Resource (@dima)?\n public readonly ctx = new Context();\n\n private _plugins?: Plugin[];\n\n init(plugins: Plugin[]) {\n this._plugins = plugins;\n }\n\n getPlugin<T>(id: string): Plugin<T> {\n invariant(this._plugins);\n return getPlugin(this._plugins, id);\n }\n\n resolvePlugin<T>(resolver: PluginResolver<T>): Plugin<T>;\n resolvePlugin<T>(resolver: PluginResolver<T>, required = false): Plugin<T> | undefined {\n invariant(this._plugins, 'context not initialized');\n const plugin = resolvePlugin(this._plugins, resolver);\n if (required && !plugin) {\n // TODO(burdon): Resolver should have a name.\n throw new Error('Plugin not found.');\n }\n\n return plugin;\n }\n\n onDispose(cb: DisposeCallback) {\n this.ctx.onDispose(cb);\n }\n\n dispose() {\n void this.ctx.dispose();\n }\n}\n\n/**\n * Plugin helper with dependency injection and life-cycle support.\n */\nexport const definePlugin = <Provides>(\n cb: (context: PluginContext) => PluginDefinition<Provides>,\n): (() => PluginDefinition<Provides>) => {\n const context = new PluginContext();\n return () => cb(context);\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,qBAA8C;AAC9C,mBAAsB;AACtB,uBAA0B;;AAYnB,IAAMA,aAAa,CAAIC,SAAmBC,OAAAA;AAC/C,SAAOD,QAAQE,KACb,CAACC,WAAWA,OAAOC,KAAKH,OAAOA,MAAO,OAAOE,OAAOC,KAAKC,YAAY,YAAYF,OAAOC,KAAKC,YAAYJ,EAAAA;AAE7G;AAKO,IAAMK,YAAY,CAAIN,SAAmBC,OAAAA;AAC9C,SAAOF,WAAWC,SAASC,EAAAA,SAAOM,oBAAM,IAAIC,MAAM,qBAAqBP,EAAAA,EAAI,CAAA;AAC7E;AAKO,IAAMQ,gBAAgB,CAAIT,SAAmBU,cAClDV,QAAQW,IAAI,CAACR,WAAWO,UAAUP,MAAAA,CAAAA,EAASS,OAAO,CAACT,WAAgC,CAAC,CAACA,MAAAA;AAShF,IAAMU,gBAAgB,CAAIb,SAAmBU,cAClDD,cAAcT,SAASU,SAAAA,EAAW,CAAA;AAEpC,IAAMI,gBAAN,MAAMA;EAAN,cAAA;eAEwB,IAAIC,uBAAAA,QAAAA;;;;;EAI1BC,KAAKhB,SAAmB;AACtB,SAAKiB,WAAWjB;EAClB;EAEAM,UAAaL,IAAuB;AAClCiB,oCAAU,KAAKD,UAAQ,QAAA;;;;;;;;;AACvB,WAAOX,UAAU,KAAKW,UAAUhB,EAAAA;EAClC;EAGAY,cAAiBM,UAA6BC,WAAW,OAA8B;AACrFF,oCAAU,KAAKD,UAAU,2BAAA;;;;;;;;;AACzB,UAAMd,SAASU,cAAc,KAAKI,UAAUE,QAAAA;AAC5C,QAAIC,YAAY,CAACjB,QAAQ;AAEvB,YAAM,IAAIK,MAAM,mBAAA;IAClB;AAEA,WAAOL;EACT;EAEAkB,UAAUC,IAAqB;AAC7B,SAAKC,IAAIF,UAAUC,EAAAA;EACrB;EAEAE,UAAU;AACR,SAAK,KAAKD,IAAIC,QAAO;EACvB;AACF;AAKO,IAAMC,eAAe,CAC1BH,OAAAA;AAEA,QAAMI,UAAU,IAAIZ,cAAAA;AACpB,SAAO,MAAMQ,GAAGI,OAAAA;AAClB;",
6
+ "names": ["findPlugin", "plugins", "id", "find", "plugin", "meta", "shortId", "getPlugin", "raise", "Error", "filterPlugins", "predicate", "map", "filter", "resolvePlugin", "PluginContext", "Context", "init", "_plugins", "invariant", "resolver", "required", "onDispose", "cb", "ctx", "dispose", "definePlugin", "context"]
7
+ }
@@ -26,19 +26,62 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var plugin_QV7ESETI_exports = {};
30
- __export(plugin_QV7ESETI_exports, {
31
- default: () => plugin_default
29
+ var chunk_VOKMWTKO_exports = {};
30
+ __export(chunk_VOKMWTKO_exports, {
31
+ IntentAction: () => IntentAction,
32
+ IntentProvider: () => IntentProvider,
33
+ meta_default: () => meta_default,
34
+ parseIntentPlugin: () => parseIntentPlugin,
35
+ parseIntentResolverPlugin: () => parseIntentResolverPlugin,
36
+ plugin_intent_default: () => plugin_intent_default,
37
+ useIntent: () => useIntent,
38
+ useIntentDispatcher: () => useIntentDispatcher,
39
+ useIntentResolver: () => useIntentResolver
32
40
  });
33
- module.exports = __toCommonJS(plugin_QV7ESETI_exports);
34
- var import_chunk_DFST5IG5 = require("./chunk-DFST5IG5.cjs");
35
- var import_chunk_62W6CMGM = require("./chunk-62W6CMGM.cjs");
41
+ module.exports = __toCommonJS(chunk_VOKMWTKO_exports);
42
+ var import_chunk_QBM42OQ6 = require("./chunk-QBM42OQ6.cjs");
36
43
  var import_react = __toESM(require("react"));
37
44
  var import_echo_schema = require("@dxos/echo-schema");
38
45
  var import_log = require("@dxos/log");
46
+ var import_react2 = require("react");
47
+ var import_react3 = require("react");
39
48
  const import_meta = {};
49
+ var IntentContext = /* @__PURE__ */ (0, import_react2.createContext)({
50
+ dispatch: async () => ({}),
51
+ undo: async () => ({}),
52
+ history: [],
53
+ registerResolver: () => () => {
54
+ }
55
+ });
56
+ var useIntent = () => (0, import_react2.useContext)(IntentContext);
57
+ var useIntentDispatcher = () => {
58
+ const { dispatch } = useIntent();
59
+ return dispatch;
60
+ };
61
+ var useIntentResolver = (plugin, resolver) => {
62
+ const { registerResolver } = useIntent();
63
+ (0, import_react3.useEffect)(() => {
64
+ return registerResolver(plugin, resolver);
65
+ }, [
66
+ plugin,
67
+ resolver
68
+ ]);
69
+ };
70
+ var IntentProvider = IntentContext.Provider;
40
71
  var isUndoable = (chain) => chain.length > 0 && chain.every(({ result }) => result.undoable);
41
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/IntentPlugin/plugin.tsx";
72
+ var IntentMeta = {
73
+ id: "dxos.org/plugin/intent"
74
+ };
75
+ var meta_default = IntentMeta;
76
+ var parseIntentPlugin = (plugin) => plugin.provides.intent?.dispatch ? plugin : void 0;
77
+ var parseIntentResolverPlugin = (plugin) => plugin.provides.intent?.resolver ? plugin : void 0;
78
+ var INTENT_PLUGIN = "dxos.org/plugin/intent";
79
+ var INTENT_ACTION = `${INTENT_PLUGIN}/action`;
80
+ var IntentAction;
81
+ (function(IntentAction2) {
82
+ IntentAction2[IntentAction2["SHOW_UNDO"] = `${INTENT_ACTION}/show-undo`] = "SHOW_UNDO";
83
+ })(IntentAction || (IntentAction = {}));
84
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/app-framework/src/plugins/plugin-intent/IntentPlugin.tsx";
42
85
  var EXECUTION_LIMIT = 1e3;
43
86
  var HISTORY_LIMIT = 100;
44
87
  var IntentPlugin = () => {
@@ -51,7 +94,7 @@ var IntentPlugin = () => {
51
94
  });
52
95
  const dynamicResolvers = /* @__PURE__ */ new Set();
53
96
  return {
54
- meta: import_chunk_DFST5IG5.meta_default,
97
+ meta: meta_default,
55
98
  ready: async (plugins) => {
56
99
  const dispatch = async (intent) => {
57
100
  (0, import_log.log)("dispatch", {
@@ -66,15 +109,14 @@ var IntentPlugin = () => {
66
109
  if (intent.plugin) {
67
110
  for (const entry of dynamicResolvers) {
68
111
  if (entry.plugin === intent.plugin) {
69
- const result2 = await entry.resolver(intent, plugins);
70
- if (result2) {
71
- return result2;
112
+ const result = await entry.resolver(intent, plugins);
113
+ if (result) {
114
+ return result;
72
115
  }
73
116
  }
74
117
  }
75
- const plugin = (0, import_chunk_62W6CMGM.findPlugin)(plugins, intent.plugin);
76
- const result = plugin?.provides.intent.resolver(intent, plugins);
77
- return result;
118
+ const plugin = (0, import_chunk_QBM42OQ6.findPlugin)(plugins, intent.plugin);
119
+ return plugin?.provides.intent.resolver(intent, plugins);
78
120
  }
79
121
  for (const entry of dynamicResolvers) {
80
122
  const result = await entry.resolver(intent, plugins);
@@ -82,7 +124,7 @@ var IntentPlugin = () => {
82
124
  return result;
83
125
  }
84
126
  }
85
- for (const plugin of (0, import_chunk_62W6CMGM.filterPlugins)(plugins, import_chunk_DFST5IG5.parseIntentResolverPlugin)) {
127
+ for (const plugin of (0, import_chunk_QBM42OQ6.filterPlugins)(plugins, parseIntentResolverPlugin)) {
86
128
  const result = await plugin.provides.intent.resolver(intent, plugins);
87
129
  if (result) {
88
130
  return result;
@@ -91,7 +133,7 @@ var IntentPlugin = () => {
91
133
  if (import_meta?.env?.DEV) {
92
134
  import_log.log.warn("No plugin found to handle intent", intent, {
93
135
  F: __dxlog_file,
94
- L: 79,
136
+ L: 78,
95
137
  S: void 0,
96
138
  C: (f, a) => f(...a)
97
139
  });
@@ -134,7 +176,7 @@ var IntentPlugin = () => {
134
176
  }
135
177
  if (isUndoable(executionResults)) {
136
178
  void dispatch({
137
- action: import_chunk_DFST5IG5.IntentAction.SHOW_UNDO,
179
+ action: IntentAction.SHOW_UNDO,
138
180
  data: {
139
181
  results: executionResults
140
182
  }
@@ -174,11 +216,23 @@ var IntentPlugin = () => {
174
216
  },
175
217
  provides: {
176
218
  intent: state,
177
- context: ({ children }) => /* @__PURE__ */ import_react.default.createElement(import_chunk_DFST5IG5.IntentProvider, {
219
+ context: ({ children }) => /* @__PURE__ */ import_react.default.createElement(IntentProvider, {
178
220
  value: state
179
221
  }, children)
180
222
  }
181
223
  };
182
224
  };
183
- var plugin_default = IntentPlugin;
184
- //# sourceMappingURL=plugin-QV7ESETI.cjs.map
225
+ var plugin_intent_default = IntentPlugin;
226
+ // Annotate the CommonJS export names for ESM import in node:
227
+ 0 && (module.exports = {
228
+ IntentAction,
229
+ IntentProvider,
230
+ meta_default,
231
+ parseIntentPlugin,
232
+ parseIntentResolverPlugin,
233
+ plugin_intent_default,
234
+ useIntent,
235
+ useIntentDispatcher,
236
+ useIntentResolver
237
+ });
238
+ //# sourceMappingURL=chunk-VOKMWTKO.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/plugins/plugin-intent/IntentPlugin.tsx", "../../../src/plugins/plugin-intent/IntentContext.tsx", "../../../src/plugins/plugin-intent/helpers.ts", "../../../src/plugins/plugin-intent/meta.ts", "../../../src/plugins/plugin-intent/provides.ts", "../../../src/plugins/plugin-intent/index.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { create } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\n\nimport { type IntentContext, IntentProvider, type IntentExecution } from './IntentContext';\nimport { isUndoable } from './helpers';\nimport type { Intent, IntentResolver } from './intent';\nimport IntentMeta from './meta';\nimport {\n type IntentPluginProvides,\n type IntentResolverProvides,\n parseIntentResolverPlugin,\n IntentAction,\n} from './provides';\nimport { filterPlugins, findPlugin } from '../helpers';\nimport { type PluginDefinition } from '../plugin-host';\n\nconst EXECUTION_LIMIT = 1000;\nconst HISTORY_LIMIT = 100;\n\n/**\n * Allows plugins to register intent handlers and routes sent intents to the appropriate plugin.\n * Inspired by https://developer.android.com/reference/android/content/Intent.\n */\nexport const IntentPlugin = (): PluginDefinition<IntentPluginProvides> => {\n const state = create<IntentContext>({\n dispatch: async () => ({}),\n undo: async () => ({}),\n history: [],\n registerResolver: () => () => {},\n });\n\n const dynamicResolvers = new Set<{ plugin: string; resolver: IntentResolver }>();\n\n return {\n meta: IntentMeta,\n ready: async (plugins) => {\n // Dispatch intent to associated plugin.\n const dispatch = async (intent: Intent) => {\n log('dispatch', { action: intent.action, intent });\n if (intent.plugin) {\n for (const entry of dynamicResolvers) {\n if (entry.plugin === intent.plugin) {\n const result = await entry.resolver(intent, plugins);\n if (result) {\n return result;\n }\n }\n }\n\n const plugin = findPlugin<IntentResolverProvides>(plugins, intent.plugin);\n return plugin?.provides.intent.resolver(intent, plugins);\n }\n\n for (const entry of dynamicResolvers) {\n const result = await entry.resolver(intent, plugins);\n if (result) {\n return result;\n }\n }\n\n // Return resolved value from first plugin that handles the intent.\n for (const plugin of filterPlugins(plugins, parseIntentResolverPlugin)) {\n const result = await plugin.provides.intent.resolver(intent, plugins);\n if (result) {\n return result;\n }\n }\n\n // https://vitejs.dev/guide/env-and-mode#env-variables\n // TODO(wittjosiah): How to handle this more generically?\n if (import.meta?.env?.DEV) {\n log.warn('No plugin found to handle intent', intent);\n }\n };\n\n // Sequentially dispatch array of invents.\n const dispatchChain = async (intentOrArray: Intent | Intent[], depth = 0) => {\n if (depth > EXECUTION_LIMIT) {\n return {\n error: new Error(\n `Intent execution limit exceeded (${EXECUTION_LIMIT} iterations). This is likely due to an infinite loop within intent resolvers.`,\n ),\n };\n }\n\n const executionResults: IntentExecution[] = [];\n const chain = Array.isArray(intentOrArray) ? intentOrArray : [intentOrArray];\n for (const intent of chain) {\n const { result: prevResult } = executionResults.at(-1) ?? {};\n const data = intent.data ? { result: prevResult?.data, ...intent.data } : prevResult?.data;\n const result = await dispatch({ ...intent, data });\n\n if (!result || result?.error) {\n break;\n }\n\n executionResults.push({ intent, result });\n\n // TODO(wittjosiah): How does undo work with returned intents?\n result?.intents?.forEach((intents) => {\n void dispatchChain(intents, depth + 1);\n });\n }\n\n state.history.push(executionResults);\n if (state.history.length > HISTORY_LIMIT) {\n state.history.splice(0, state.history.length - HISTORY_LIMIT);\n }\n\n if (isUndoable(executionResults)) {\n void dispatch({ action: IntentAction.SHOW_UNDO, data: { results: executionResults } });\n }\n\n return executionResults.at(-1)?.result;\n };\n\n const undo = async () => {\n const last = state.history.findLastIndex(isUndoable);\n const chain =\n last !== -1 &&\n state.history[last]?.map(({ intent, result }): Intent => {\n const data = result.undoable?.data ? { ...intent.data, ...result.undoable.data } : intent.data;\n return { ...intent, data, undo: true };\n });\n if (chain) {\n const result = await dispatchChain(chain);\n state.history = state.history.filter((_, index) => index !== last);\n return result;\n }\n };\n\n state.dispatch = dispatchChain;\n state.undo = undo;\n state.registerResolver = (plugin, resolver) => {\n const entry = { plugin, resolver };\n dynamicResolvers.add(entry);\n return () => dynamicResolvers.delete(entry);\n };\n },\n provides: {\n intent: state,\n context: ({ children }) => <IntentProvider value={state}>{children}</IntentProvider>,\n },\n };\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Context, createContext, useContext, type Provider } from 'react';\nimport { useEffect } from 'react';\n\nimport type { UnsubscribeCallback } from '@dxos/async';\n\nimport type { Intent, IntentDispatcher, IntentResolver, IntentResult } from './intent';\n\nexport type IntentExecution = {\n intent: Intent;\n result: IntentResult;\n};\n\nexport type IntentContext = {\n dispatch: IntentDispatcher;\n undo: () => Promise<IntentResult | void>;\n history: IntentExecution[][];\n registerResolver: (pluginId: string, resolver: IntentResolver) => UnsubscribeCallback;\n};\n\nconst IntentContext: Context<IntentContext> = createContext<IntentContext>({\n dispatch: async () => ({}),\n undo: async () => ({}),\n history: [],\n registerResolver: () => () => {},\n});\n\n/**\n * @deprecated Prefer granular hooks.\n */\n// TODO(burdon): Remove. Use useIntentDispatcher.\nexport const useIntent = () => useContext(IntentContext);\n\nexport const useIntentDispatcher = (): IntentDispatcher => {\n const { dispatch } = useIntent();\n return dispatch;\n};\n\nexport const useIntentResolver = (plugin: string, resolver: IntentResolver) => {\n const { registerResolver } = useIntent();\n useEffect(() => {\n return registerResolver(plugin, resolver);\n }, [plugin, resolver]);\n};\n\nexport const IntentProvider: Provider<IntentContext> = IntentContext.Provider;\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type IntentExecution } from './IntentContext';\n\n/**\n * Check if the chain of intents is undoable.\n */\nexport const isUndoable = (chain: IntentExecution[]): boolean =>\n chain.length > 0 && chain.every(({ result }) => result.undoable);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst IntentMeta = {\n id: 'dxos.org/plugin/intent',\n};\n\nexport default IntentMeta;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type IntentContext } from './IntentContext';\nimport { type IntentResolver } from './intent';\nimport { type Plugin } from '../plugin-host';\n\nexport type IntentResolverProvides = {\n intent: {\n resolver: IntentResolver;\n };\n};\n\nexport type IntentPluginProvides = {\n intent: IntentContext;\n};\n\nexport const parseIntentPlugin = (plugin: Plugin) =>\n (plugin.provides as any).intent?.dispatch ? (plugin as Plugin<IntentPluginProvides>) : undefined;\n\nexport const parseIntentResolverPlugin = (plugin: Plugin) =>\n (plugin.provides as any).intent?.resolver ? (plugin as Plugin<IntentResolverProvides>) : undefined;\n\n//\n// Intents\n//\n\nconst INTENT_PLUGIN = 'dxos.org/plugin/intent';\n\nconst INTENT_ACTION = `${INTENT_PLUGIN}/action`;\n\nexport enum IntentAction {\n /**\n * Fired after an intent is dispatched if the intent is undoable.\n */\n SHOW_UNDO = `${INTENT_ACTION}/show-undo`,\n}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { IntentPlugin } from './IntentPlugin';\n\nexport * from './intent';\nexport * from './provides';\n\nexport * from './IntentContext';\n\nexport default IntentPlugin;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAAkB;AAElB,yBAAuB;AACvB,iBAAoB;ACHpB,IAAAA,gBAAuE;AACvE,IAAAA,gBAA0B;;AAkB1B,IAAMC,gBAAwCC,iDAA6B;EACzEC,UAAU,aAAa,CAAC;EACxBC,MAAM,aAAa,CAAC;EACpBC,SAAS,CAAA;EACTC,kBAAkB,MAAM,MAAA;EAAO;AACjC,CAAA;AAMO,IAAMC,YAAY,UAAMC,0BAAWP,aAAAA;AAEnC,IAAMQ,sBAAsB,MAAA;AACjC,QAAM,EAAEN,SAAQ,IAAKI,UAAAA;AACrB,SAAOJ;AACT;AAEO,IAAMO,oBAAoB,CAACC,QAAgBC,aAAAA;AAChD,QAAM,EAAEN,iBAAgB,IAAKC,UAAAA;AAC7BM,+BAAU,MAAA;AACR,WAAOP,iBAAiBK,QAAQC,QAAAA;EAClC,GAAG;IAACD;IAAQC;GAAS;AACvB;AAEO,IAAME,iBAA0Cb,cAAcc;ACvC9D,IAAMC,aAAa,CAAC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olver", "useIntent", "useContext", "useIntentDispatcher", "useIntentResolver", "plugin", "resolver", "useEffect", "IntentProvider", "Provider", "isUndoable", "chain", "length", "every", "result", "undoable", "IntentMeta", "id", "parseIntentPlugin", "provides", "intent", "undefined", "parseIntentResolverPlugin", "INTENT_PLUGIN", "INTENT_ACTION", "IntentAction", "EXECUTION_LIMIT", "HISTORY_LIMIT", "IntentPlugin", "state", "create", "dynamicResolvers", "Set", "meta", "ready", "plugins", "log", "action", "entry", "findPlugin", "filterPlugins", "env", "DEV", "warn", "dispatchChain", "intentOrArray", "depth", "error", "Error", "executionResults", "Array", "isArray", "prevResult", "at", "data", "push", "intents", "forEach", "splice", "SHOW_UNDO", "results", "last", "findLastIndex", "map", "filter", "_", "index", "add", "delete", "context", "children", "React", "value"]
7
+ }