@dxos/app-framework 0.6.11 → 0.6.12-main.5cc132e

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.
@@ -0,0 +1,52 @@
1
+ // packages/sdk/app-framework/src/plugins/IntentPlugin/provides.ts
2
+ var parseIntentPlugin = (plugin) => plugin.provides.intent?.dispatch ? plugin : void 0;
3
+ var parseIntentResolverPlugin = (plugin) => plugin.provides.intent?.resolver ? plugin : void 0;
4
+ var INTENT_ACTION = "dxos.org/plugin/intent";
5
+ var IntentAction;
6
+ (function(IntentAction2) {
7
+ IntentAction2[IntentAction2["SHOW_UNDO"] = `${INTENT_ACTION}/show-undo`] = "SHOW_UNDO";
8
+ })(IntentAction || (IntentAction = {}));
9
+
10
+ // packages/sdk/app-framework/src/plugins/IntentPlugin/IntentContext.tsx
11
+ import { createContext, useContext } from "react";
12
+ import { useEffect } from "react";
13
+ var IntentContext = /* @__PURE__ */ createContext({
14
+ dispatch: async () => ({}),
15
+ undo: async () => ({}),
16
+ history: [],
17
+ registerResolver: () => () => {
18
+ }
19
+ });
20
+ var useIntent = () => useContext(IntentContext);
21
+ var useIntentDispatcher = () => {
22
+ const { dispatch } = useIntent();
23
+ return dispatch;
24
+ };
25
+ var useIntentResolver = (plugin, resolver) => {
26
+ const { registerResolver } = useIntent();
27
+ useEffect(() => {
28
+ return registerResolver(plugin, resolver);
29
+ }, [
30
+ plugin,
31
+ resolver
32
+ ]);
33
+ };
34
+ var IntentProvider = IntentContext.Provider;
35
+
36
+ // packages/sdk/app-framework/src/plugins/IntentPlugin/meta.ts
37
+ var IntentMeta = {
38
+ id: "dxos.org/plugin/intent"
39
+ };
40
+ var meta_default = IntentMeta;
41
+
42
+ export {
43
+ parseIntentPlugin,
44
+ parseIntentResolverPlugin,
45
+ IntentAction,
46
+ useIntent,
47
+ useIntentDispatcher,
48
+ useIntentResolver,
49
+ IntentProvider,
50
+ meta_default
51
+ };
52
+ //# sourceMappingURL=chunk-J45KR4DI.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/plugins/IntentPlugin/provides.ts", "../../../src/plugins/IntentPlugin/IntentContext.tsx", "../../../src/plugins/IntentPlugin/meta.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type IntentContext } from './IntentContext';\nimport { type IntentResolver } from './intent';\nimport { type Plugin } from '../PluginHost';\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_ACTION = 'dxos.org/plugin/intent';\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 { 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 2023 DXOS.org\n//\n\nconst IntentMeta = {\n id: 'dxos.org/plugin/intent',\n};\n\nexport default IntentMeta;\n"],
5
+ "mappings": ";AAkBO,IAAMA,oBAAoB,CAACC,WAC/BA,OAAOC,SAAiBC,QAAQC,WAAYH,SAA0CI;AAElF,IAAMC,4BAA4B,CAACL,WACvCA,OAAOC,SAAiBC,QAAQI,WAAYN,SAA4CI;AAM3F,IAAMG,gBAAgB;;UACVC,eAAAA;AAGT,EAAAA,cAAAA,cAAA,WAAA,IACW,GAAGD,aAAAA,YAAyB,IAAA;GAJ9BC,iBAAAA,eAAAA,CAAAA,EAAAA;;;ACzBZ,SAAuBC,eAAeC,kBAAiC;AACvE,SAASC,iBAAiB;AAkB1B,IAAMC,gBAAwCC,8BAA6B;EACzEC,UAAU,aAAa,CAAC;EACxBC,MAAM,aAAa,CAAC;EACpBC,SAAS,CAAA;EACTC,kBAAkB,MAAM,MAAA;EAAO;AACjC,CAAA;AAMO,IAAMC,YAAY,MAAMC,WAAWP,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,YAAU,MAAA;AACR,WAAOP,iBAAiBK,QAAQC,QAAAA;EAClC,GAAG;IAACD;IAAQC;GAAS;AACvB;AAEO,IAAME,iBAA0Cb,cAAcc;;;AC5CrE,IAAMC,aAAa;EACjBC,IAAI;AACN;AAEA,IAAA,eAAeD;",
6
+ "names": ["parseIntentPlugin", "plugin", "provides", "intent", "dispatch", "undefined", "parseIntentResolverPlugin", "resolver", "INTENT_ACTION", "IntentAction", "createContext", "useContext", "useEffect", "IntentContext", "createContext", "dispatch", "undo", "history", "registerResolver", "useIntent", "useContext", "useIntentDispatcher", "useIntentResolver", "plugin", "resolver", "useEffect", "IntentProvider", "Provider", "IntentMeta", "id"]
7
+ }
@@ -0,0 +1,20 @@
1
+ // packages/sdk/app-framework/src/plugins/helpers.ts
2
+ import { raise } from "@dxos/debug";
3
+ var definePlugin = (plugin) => plugin;
4
+ var findPlugin = (plugins, id) => {
5
+ return plugins.find((plugin) => plugin.meta.id === id || typeof plugin.meta.shortId === "string" && plugin.meta.shortId === id);
6
+ };
7
+ var getPlugin = (plugins, id) => {
8
+ return findPlugin(plugins, id) ?? raise(new Error(`Plugin not found: ${id}`));
9
+ };
10
+ var filterPlugins = (plugins, predicate) => plugins.map((plugin) => predicate(plugin)).filter((plugin) => !!plugin);
11
+ var resolvePlugin = (plugins, predicate) => filterPlugins(plugins, predicate)[0];
12
+
13
+ export {
14
+ definePlugin,
15
+ findPlugin,
16
+ getPlugin,
17
+ filterPlugins,
18
+ resolvePlugin
19
+ };
20
+ //# sourceMappingURL=chunk-S5CI6EUQ.mjs.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 { raise } from '@dxos/debug';\n\nimport { type Plugin } from './PluginHost';\n\n/**\n * Define a plugin\n */\nexport const definePlugin = <TProvides>(plugin: Plugin<TProvides>): Plugin<TProvides> => plugin;\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>(\n plugins: Plugin[],\n predicate: (plugin: Plugin) => Plugin<T> | undefined,\n): Plugin<T>[] => 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>(\n plugins: Plugin[],\n predicate: (plugin: Plugin) => Plugin<T> | undefined,\n): Plugin<T> | undefined => filterPlugins(plugins, predicate)[0];\n"],
5
+ "mappings": ";AAIA,SAASA,aAAa;AAOf,IAAMC,eAAe,CAAYC,WAAiDA;AAKlF,IAAMC,aAAa,CAAIC,SAAmBC,OAAAA;AAC/C,SAAOD,QAAQE,KACb,CAACJ,WAAWA,OAAOK,KAAKF,OAAOA,MAAO,OAAOH,OAAOK,KAAKC,YAAY,YAAYN,OAAOK,KAAKC,YAAYH,EAAAA;AAE7G;AAKO,IAAMI,YAAY,CAAIL,SAAmBC,OAAAA;AAC9C,SAAOF,WAAWC,SAASC,EAAAA,KAAOK,MAAM,IAAIC,MAAM,qBAAqBN,EAAAA,EAAI,CAAA;AAC7E;AAKO,IAAMO,gBAAgB,CAC3BR,SACAS,cACgBT,QAAQU,IAAI,CAACZ,WAAWW,UAAUX,MAAAA,CAAAA,EAASa,OAAO,CAACb,WAAgC,CAAC,CAACA,MAAAA;AAShG,IAAMc,gBAAgB,CAC3BZ,SACAS,cAC0BD,cAAcR,SAASS,SAAAA,EAAW,CAAA;",
6
+ "names": ["raise", "definePlugin", "plugin", "findPlugin", "plugins", "id", "find", "meta", "shortId", "getPlugin", "raise", "Error", "filterPlugins", "predicate", "map", "filter", "resolvePlugin"]
7
+ }
@@ -0,0 +1,26 @@
1
+ // packages/sdk/app-framework/src/plugins/SurfacePlugin/provides.ts
2
+ var parseRootSurfacePlugin = (plugin) => plugin?.provides?.surface?.components ? plugin : void 0;
3
+ var parseSurfacePlugin = (plugin) => plugin?.provides?.surface?.component ? plugin : void 0;
4
+
5
+ // packages/sdk/app-framework/src/plugins/SurfacePlugin/SurfaceRootContext.tsx
6
+ import { createContext, useContext } from "react";
7
+ var SurfaceRootContext = /* @__PURE__ */ createContext({
8
+ components: {}
9
+ });
10
+ var useSurfaceRoot = () => useContext(SurfaceRootContext);
11
+ var SurfaceProvider = SurfaceRootContext.Provider;
12
+
13
+ // packages/sdk/app-framework/src/plugins/SurfacePlugin/meta.ts
14
+ var SurfaceMeta = {
15
+ id: "dxos.org/plugin/surface"
16
+ };
17
+ var meta_default = SurfaceMeta;
18
+
19
+ export {
20
+ parseRootSurfacePlugin,
21
+ parseSurfacePlugin,
22
+ useSurfaceRoot,
23
+ SurfaceProvider,
24
+ meta_default
25
+ };
26
+ //# sourceMappingURL=chunk-YYV26N3W.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/plugins/SurfacePlugin/provides.ts", "../../../src/plugins/SurfacePlugin/SurfaceRootContext.tsx", "../../../src/plugins/SurfacePlugin/meta.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type SurfaceComponent, type SurfaceRootContext } from './SurfaceRootContext';\nimport { type Plugin } from '../PluginHost';\n\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\nimport { createContext, useContext, type Context, type JSX, type Provider, type ForwardedRef } from 'react';\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\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\nconst SurfaceRootContext: Context<SurfaceRootContext> = createContext<SurfaceRootContext>({ components: {} });\n\nexport const useSurfaceRoot = () => useContext(SurfaceRootContext);\n\nexport const SurfaceProvider: Provider<SurfaceRootContext> = SurfaceRootContext.Provider;\n", "//\n// Copyright 2023 DXOS.org\n//\n\nconst SurfaceMeta = {\n id: 'dxos.org/plugin/surface',\n};\n\nexport default SurfaceMeta;\n"],
5
+ "mappings": ";AAoBO,IAAMA,yBAAyB,CAACC,WACpCA,QAAQC,UAAkBC,SAASC,aAAcH,SAA2CI;AAExF,IAAMC,qBAAqB,CAACL,WAChCA,QAAQC,UAAkBC,SAASI,YAAaN,SAAqCI;;;ACpBxF,SAASG,eAAeC,kBAA4E;AAmCpG,IAAMC,qBAAkDC,8BAAkC;EAAEC,YAAY,CAAC;AAAE,CAAA;AAEpG,IAAMC,iBAAiB,MAAMC,WAAWJ,kBAAAA;AAExC,IAAMK,kBAAgDL,mBAAmBM;;;ACvChF,IAAMC,cAAc;EAClBC,IAAI;AACN;AAEA,IAAA,eAAeD;",
6
+ "names": ["parseRootSurfacePlugin", "plugin", "provides", "surface", "components", "undefined", "parseSurfacePlugin", "component", "createContext", "useContext", "SurfaceRootContext", "createContext", "components", "useSurfaceRoot", "useContext", "SurfaceProvider", "Provider", "SurfaceMeta", "id"]
7
+ }