@dxos/plugin-sheet 0.6.10 → 0.6.11-staging.e6894a4
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.
- package/dist/lib/browser/{SheetContainer-ISY6DUVE.mjs → SheetContainer-4XOKHKKZ.mjs} +40 -30
- package/dist/lib/browser/SheetContainer-4XOKHKKZ.mjs.map +7 -0
- package/dist/lib/browser/{chunk-D3PUKBH6.mjs → chunk-FUAGSXA4.mjs} +1 -1
- package/dist/lib/browser/{chunk-D3PUKBH6.mjs.map → chunk-FUAGSXA4.mjs.map} +2 -2
- package/dist/lib/browser/chunk-FWGRE3EG.mjs +175 -0
- package/dist/lib/browser/chunk-FWGRE3EG.mjs.map +7 -0
- package/dist/lib/browser/{chunk-CBRBNG3R.mjs → chunk-P7SSL3EG.mjs} +115 -194
- package/dist/lib/browser/chunk-P7SSL3EG.mjs.map +7 -0
- package/dist/lib/browser/chunk-YPU3R7FA.mjs +8 -0
- package/dist/lib/browser/chunk-YPU3R7FA.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +23 -68
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing.mjs +92 -0
- package/dist/lib/browser/testing.mjs.map +7 -0
- package/dist/lib/browser/types.mjs +1 -1
- package/dist/lib/node/{SheetContainer-ESRTE7A5.cjs → SheetContainer-IQT6TR4Z.cjs} +61 -52
- package/dist/lib/node/SheetContainer-IQT6TR4Z.cjs.map +7 -0
- package/dist/lib/node/chunk-5EPCDAZC.cjs +40 -0
- package/dist/lib/node/chunk-5EPCDAZC.cjs.map +7 -0
- package/dist/lib/node/chunk-727C6YNP.cjs +202 -0
- package/dist/lib/node/chunk-727C6YNP.cjs.map +7 -0
- package/dist/lib/node/{chunk-3R3J7IZR.cjs → chunk-DSYKOI4E.cjs} +4 -4
- package/dist/lib/node/{chunk-3R3J7IZR.cjs.map → chunk-DSYKOI4E.cjs.map} +2 -2
- package/dist/lib/node/{chunk-4EGEA3KL.cjs → chunk-SVAIIXWQ.cjs} +127 -206
- package/dist/lib/node/chunk-SVAIIXWQ.cjs.map +7 -0
- package/dist/lib/node/index.cjs +24 -67
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing.cjs +111 -0
- package/dist/lib/node/testing.cjs.map +7 -0
- package/dist/lib/node/types.cjs +9 -9
- package/dist/lib/node/types.cjs.map +1 -1
- package/dist/types/src/SheetPlugin.d.ts.map +1 -1
- package/dist/types/src/components/CellEditor/extension.d.ts.map +1 -1
- package/dist/types/src/components/ComputeGraph/edge-function.d.ts.map +1 -1
- package/dist/types/src/components/ComputeGraph/graph-context.d.ts.map +1 -1
- package/dist/types/src/components/Sheet/Sheet.stories.d.ts.map +1 -1
- package/dist/types/src/components/SheetContainer.d.ts +1 -1
- package/dist/types/src/components/SheetContainer.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +1 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts +9 -0
- package/dist/types/src/testing.d.ts.map +1 -0
- package/dist/types/src/types.d.ts.map +1 -1
- package/package.json +38 -28
- package/src/SheetPlugin.tsx +18 -4
- package/src/components/CellEditor/extension.ts +16 -10
- package/src/components/ComputeGraph/edge-function.ts +6 -2
- package/src/components/ComputeGraph/graph-context.tsx +10 -1
- package/src/components/Sheet/Sheet.stories.tsx +3 -39
- package/src/components/Sheet/Sheet.tsx +12 -12
- package/src/components/Sheet/formatting.ts +1 -1
- package/src/components/SheetContainer.tsx +2 -1
- package/src/testing.ts +50 -0
- package/src/types.ts +2 -0
- package/dist/lib/browser/SheetContainer-ISY6DUVE.mjs.map +0 -7
- package/dist/lib/browser/chunk-CBRBNG3R.mjs.map +0 -7
- package/dist/lib/node/SheetContainer-ESRTE7A5.cjs.map +0 -7
- package/dist/lib/node/chunk-4EGEA3KL.cjs.map +0 -7
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CustomPlugin,
|
|
3
|
+
CustomPluginTranslations,
|
|
4
|
+
FunctionPluginAsync,
|
|
5
|
+
createComputeGraph
|
|
6
|
+
} from "./chunk-P7SSL3EG.mjs";
|
|
7
|
+
|
|
8
|
+
// packages/plugins/plugin-sheet/src/components/ComputeGraph/edge-function.ts
|
|
9
|
+
import { effect } from "@preact/signals-core";
|
|
10
|
+
import { CellError, ErrorType, FunctionArgumentType } from "hyperformula";
|
|
11
|
+
import { Filter, getMeta } from "@dxos/client/echo";
|
|
12
|
+
import { log } from "@dxos/log";
|
|
13
|
+
import { getUserFunctionUrlInMetadata } from "@dxos/plugin-script/edge";
|
|
14
|
+
import { FunctionType } from "@dxos/plugin-script/types";
|
|
15
|
+
import { nonNullable } from "@dxos/util";
|
|
16
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/components/ComputeGraph/edge-function.ts";
|
|
17
|
+
var EDGE_FUNCTION_TTL = 1e4;
|
|
18
|
+
var EdgeFunctionPlugin = class extends FunctionPluginAsync {
|
|
19
|
+
edge(ast, state) {
|
|
20
|
+
const handler = (subscribe = false) => async (binding, ...args) => {
|
|
21
|
+
const space = this.context.space;
|
|
22
|
+
if (!space) {
|
|
23
|
+
return new CellError(ErrorType.REF, "Missing space");
|
|
24
|
+
}
|
|
25
|
+
const { objects: [fn] } = await space.db.query(Filter.schema(FunctionType, {
|
|
26
|
+
binding
|
|
27
|
+
})).run();
|
|
28
|
+
if (!fn) {
|
|
29
|
+
log.info("Function not found", {
|
|
30
|
+
binding
|
|
31
|
+
}, {
|
|
32
|
+
F: __dxlog_file,
|
|
33
|
+
L: 39,
|
|
34
|
+
S: this,
|
|
35
|
+
C: (f, a) => f(...a)
|
|
36
|
+
});
|
|
37
|
+
return new CellError(ErrorType.REF, "Function not found");
|
|
38
|
+
}
|
|
39
|
+
if (subscribe) {
|
|
40
|
+
const unsubscribe = effect(() => {
|
|
41
|
+
log.info("function changed", {
|
|
42
|
+
fn
|
|
43
|
+
}, {
|
|
44
|
+
F: __dxlog_file,
|
|
45
|
+
L: 45,
|
|
46
|
+
S: this,
|
|
47
|
+
C: (f, a) => f(...a)
|
|
48
|
+
});
|
|
49
|
+
const _ = fn?.version;
|
|
50
|
+
this.runAsyncFunction(ast, state, handler(false), {
|
|
51
|
+
ttl: EDGE_FUNCTION_TTL
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
55
|
+
}
|
|
56
|
+
const path = getUserFunctionUrlInMetadata(getMeta(fn));
|
|
57
|
+
const result = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers: {
|
|
60
|
+
"Content-Type": "application/json"
|
|
61
|
+
},
|
|
62
|
+
body: JSON.stringify({
|
|
63
|
+
args: args.filter(nonNullable)
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
return await result.text();
|
|
67
|
+
};
|
|
68
|
+
return this.runAsyncFunction(ast, state, handler(true), {
|
|
69
|
+
ttl: EDGE_FUNCTION_TTL
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
EdgeFunctionPlugin.implementedFunctions = {
|
|
74
|
+
EDGE: {
|
|
75
|
+
method: "edge",
|
|
76
|
+
parameters: [
|
|
77
|
+
// Binding
|
|
78
|
+
{
|
|
79
|
+
argumentType: FunctionArgumentType.STRING
|
|
80
|
+
},
|
|
81
|
+
// Remote function arguments (currently supporting up to 9).
|
|
82
|
+
{
|
|
83
|
+
argumentType: FunctionArgumentType.ANY,
|
|
84
|
+
optionalArg: true
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
argumentType: FunctionArgumentType.ANY,
|
|
88
|
+
optionalArg: true
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
argumentType: FunctionArgumentType.ANY,
|
|
92
|
+
optionalArg: true
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
argumentType: FunctionArgumentType.ANY,
|
|
96
|
+
optionalArg: true
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
argumentType: FunctionArgumentType.ANY,
|
|
100
|
+
optionalArg: true
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
argumentType: FunctionArgumentType.ANY,
|
|
104
|
+
optionalArg: true
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
argumentType: FunctionArgumentType.ANY,
|
|
108
|
+
optionalArg: true
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
argumentType: FunctionArgumentType.ANY,
|
|
112
|
+
optionalArg: true
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
argumentType: FunctionArgumentType.ANY,
|
|
116
|
+
optionalArg: true
|
|
117
|
+
}
|
|
118
|
+
],
|
|
119
|
+
isVolatile: true
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
var EdgeFunctionPluginTranslations = {
|
|
123
|
+
enGB: {
|
|
124
|
+
EDGE: "EDGE"
|
|
125
|
+
},
|
|
126
|
+
enUS: {
|
|
127
|
+
EDGE: "EDGE"
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
// packages/plugins/plugin-sheet/src/components/ComputeGraph/graph-context.tsx
|
|
132
|
+
import React, { createContext, useContext, useEffect } from "react";
|
|
133
|
+
var ComputeGraphContext = /* @__PURE__ */ createContext({
|
|
134
|
+
graphs: {},
|
|
135
|
+
setGraph: () => {
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
var ComputeGraphContextProvider = ({ children, graphs, setGraph }) => {
|
|
139
|
+
return /* @__PURE__ */ React.createElement(ComputeGraphContext.Provider, {
|
|
140
|
+
value: {
|
|
141
|
+
graphs,
|
|
142
|
+
setGraph
|
|
143
|
+
}
|
|
144
|
+
}, children);
|
|
145
|
+
};
|
|
146
|
+
var useComputeGraph = (space, options) => {
|
|
147
|
+
const { graphs, setGraph } = useContext(ComputeGraphContext);
|
|
148
|
+
const graph = graphs[space.id] ?? createComputeGraph([
|
|
149
|
+
{
|
|
150
|
+
plugin: EdgeFunctionPlugin,
|
|
151
|
+
translations: EdgeFunctionPluginTranslations
|
|
152
|
+
},
|
|
153
|
+
// TODO(wittjosiah): Remove. Needed for current test sheet generated data.
|
|
154
|
+
{
|
|
155
|
+
plugin: CustomPlugin,
|
|
156
|
+
translations: CustomPluginTranslations
|
|
157
|
+
}
|
|
158
|
+
], space, options);
|
|
159
|
+
useEffect(() => {
|
|
160
|
+
if (!graphs[space.id]) {
|
|
161
|
+
setGraph(space.id, graph);
|
|
162
|
+
}
|
|
163
|
+
}, [
|
|
164
|
+
space
|
|
165
|
+
]);
|
|
166
|
+
return graph;
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
export {
|
|
170
|
+
EdgeFunctionPlugin,
|
|
171
|
+
EdgeFunctionPluginTranslations,
|
|
172
|
+
ComputeGraphContextProvider,
|
|
173
|
+
useComputeGraph
|
|
174
|
+
};
|
|
175
|
+
//# sourceMappingURL=chunk-FWGRE3EG.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/components/ComputeGraph/edge-function.ts", "../../../src/components/ComputeGraph/graph-context.tsx"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { effect } from '@preact/signals-core';\nimport { CellError, ErrorType, FunctionArgumentType } from 'hyperformula';\nimport { type InterpreterState } from 'hyperformula/typings/interpreter/InterpreterState';\nimport { type ProcedureAst } from 'hyperformula/typings/parser';\n\nimport { Filter, getMeta } from '@dxos/client/echo';\nimport { log } from '@dxos/log';\nimport { getUserFunctionUrlInMetadata } from '@dxos/plugin-script/edge';\nimport { FunctionType } from '@dxos/plugin-script/types';\nimport { nonNullable } from '@dxos/util';\n\nimport { type AsyncFunction, FunctionPluginAsync } from './async-function';\n\nconst EDGE_FUNCTION_TTL = 10_000;\n\n/**\n * A hyperformula function plugin for calling EDGE functions.\n *\n * https://hyperformula.handsontable.com/guide/custom-functions.html#add-a-simple-custom-function\n */\nexport class EdgeFunctionPlugin extends FunctionPluginAsync {\n edge(ast: ProcedureAst, state: InterpreterState) {\n const handler =\n (subscribe = false): AsyncFunction =>\n async (binding: string, ...args: any) => {\n const space = this.context.space;\n if (!space) {\n return new CellError(ErrorType.REF, 'Missing space');\n }\n\n const {\n objects: [fn],\n } = await space.db.query(Filter.schema(FunctionType, { binding })).run();\n if (!fn) {\n log.info('Function not found', { binding });\n return new CellError(ErrorType.REF, 'Function not found');\n }\n\n if (subscribe) {\n const unsubscribe = effect(() => {\n log.info('function changed', { fn });\n const _ = fn?.version;\n\n // TODO(wittjosiah): `ttl` should be 0 to force a recalculation when a new version is deployed.\n // This needs a ttl to prevent a binding change from causing the function not to be found.\n this.runAsyncFunction(ast, state, handler(false), { ttl: EDGE_FUNCTION_TTL });\n });\n\n this.context.createSubscription(ast.procedureName, unsubscribe);\n }\n\n const path = getUserFunctionUrlInMetadata(getMeta(fn));\n const result = await fetch(`${this.context.remoteFunctionUrl}${path}`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ args: args.filter(nonNullable) }),\n });\n return await result.text();\n };\n\n return this.runAsyncFunction(ast, state, handler(true), { ttl: EDGE_FUNCTION_TTL });\n }\n}\n\nEdgeFunctionPlugin.implementedFunctions = {\n EDGE: {\n method: 'edge',\n parameters: [\n // Binding\n { argumentType: FunctionArgumentType.STRING },\n\n // Remote function arguments (currently supporting up to 9).\n { argumentType: FunctionArgumentType.ANY, optionalArg: true },\n { argumentType: FunctionArgumentType.ANY, optionalArg: true },\n { argumentType: FunctionArgumentType.ANY, optionalArg: true },\n { argumentType: FunctionArgumentType.ANY, optionalArg: true },\n { argumentType: FunctionArgumentType.ANY, optionalArg: true },\n { argumentType: FunctionArgumentType.ANY, optionalArg: true },\n { argumentType: FunctionArgumentType.ANY, optionalArg: true },\n { argumentType: FunctionArgumentType.ANY, optionalArg: true },\n { argumentType: FunctionArgumentType.ANY, optionalArg: true },\n ],\n isVolatile: true,\n },\n};\n\nexport const EdgeFunctionPluginTranslations = {\n enGB: {\n EDGE: 'EDGE',\n },\n enUS: {\n EDGE: 'EDGE',\n },\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { createContext, type PropsWithChildren, useContext, useEffect } from 'react';\n\nimport { type Space } from '@dxos/react-client/echo';\n\nimport { type FunctionContextOptions } from './async-function';\nimport { CustomPlugin, CustomPluginTranslations } from './custom';\nimport { EdgeFunctionPlugin, EdgeFunctionPluginTranslations } from './edge-function';\nimport { createComputeGraph, type ComputeGraph } from './graph';\n\nexport type ComputeGraphContextType = {\n graphs: Record<string, ComputeGraph>;\n setGraph: (key: string, graph: ComputeGraph) => void;\n};\n\nexport const ComputeGraphContext = createContext<ComputeGraphContextType>({ graphs: {}, setGraph: () => {} });\n\nexport const ComputeGraphContextProvider = ({\n children,\n graphs,\n setGraph,\n}: PropsWithChildren<ComputeGraphContextType>) => {\n return <ComputeGraphContext.Provider value={{ graphs, setGraph }}>{children}</ComputeGraphContext.Provider>;\n};\n\nexport const useComputeGraph = (space: Space, options?: Partial<FunctionContextOptions>): ComputeGraph => {\n const { graphs, setGraph } = useContext(ComputeGraphContext);\n const graph =\n graphs[space.id] ??\n createComputeGraph(\n [\n { plugin: EdgeFunctionPlugin, translations: EdgeFunctionPluginTranslations },\n // TODO(wittjosiah): Remove. Needed for current test sheet generated data.\n { plugin: CustomPlugin, translations: CustomPluginTranslations },\n ],\n space,\n options,\n );\n\n useEffect(() => {\n if (!graphs[space.id]) {\n setGraph(space.id, graph);\n }\n }, [space]);\n\n return graph;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAIA,SAASA,cAAc;AACvB,SAASC,WAAWC,WAAWC,4BAA4B;AAI3D,SAASC,QAAQC,eAAe;AAChC,SAASC,WAAW;AACpB,SAASC,oCAAoC;AAC7C,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E;MAAEH,QAAQI;MAAcF,cAAcG;IAAyB;KAEjEX,OACAC,OAAAA;AAGJW,YAAU,MAAA;AACR,QAAI,CAACnB,OAAOO,MAAMI,EAAE,GAAG;AACrBV,eAASM,MAAMI,IAAID,KAAAA;IACrB;EACF,GAAG;IAACH;GAAM;AAEV,SAAOG;AACT;",
|
|
6
|
+
"names": ["effect", "CellError", "ErrorType", "FunctionArgumentType", "Filter", "getMeta", "log", "getUserFunctionUrlInMetadata", "FunctionType", "nonNullable", "EDGE_FUNCTION_TTL", "EdgeFunctionPlugin", "FunctionPluginAsync", "edge", "ast", "state", "handler", "subscribe", "binding", "args", "space", "context", "CellError", "ErrorType", "REF", "objects", "fn", "db", "query", "Filter", "schema", "FunctionType", "run", "log", "info", "unsubscribe", "effect", "_", "version", "runAsyncFunction", "ttl", "createSubscription", "procedureName", "path", "getUserFunctionUrlInMetadata", "getMeta", "result", "fetch", "remoteFunctionUrl", "method", "headers", "body", "JSON", "stringify", "filter", "nonNullable", "text", "implementedFunctions", "EDGE", "parameters", "argumentType", "FunctionArgumentType", "STRING", "ANY", "optionalArg", "isVolatile", "EdgeFunctionPluginTranslations", "enGB", "enUS", "React", "createContext", "useContext", "useEffect", "ComputeGraphContext", "createContext", "graphs", "setGraph", "ComputeGraphContextProvider", "children", "Provider", "value", "useComputeGraph", "space", "options", "useContext", "graph", "id", "createComputeGraph", "plugin", "EdgeFunctionPlugin", "translations", "EdgeFunctionPluginTranslations", "CustomPlugin", "CustomPluginTranslations", "useEffect"]
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ValueTypeEnum
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-FUAGSXA4.mjs";
|
|
4
4
|
|
|
5
5
|
// packages/plugins/plugin-sheet/src/components/ComputeGraph/graph.ts
|
|
6
6
|
import { HyperFormula } from "hyperformula";
|
|
@@ -177,71 +177,6 @@ var ComputeGraph = class {
|
|
|
177
177
|
}
|
|
178
178
|
};
|
|
179
179
|
|
|
180
|
-
// packages/plugins/plugin-sheet/src/model/types.ts
|
|
181
|
-
import { invariant } from "@dxos/invariant";
|
|
182
|
-
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/types.ts";
|
|
183
|
-
var MAX_COLUMNS = 26 * 26;
|
|
184
|
-
var posEquals = (a, b) => {
|
|
185
|
-
return a?.column === b?.column && a?.row === b?.row;
|
|
186
|
-
};
|
|
187
|
-
var columnLetter = (column) => {
|
|
188
|
-
invariant(column < MAX_COLUMNS, `Invalid column: ${column}`, {
|
|
189
|
-
F: __dxlog_file3,
|
|
190
|
-
L: 17,
|
|
191
|
-
S: void 0,
|
|
192
|
-
A: [
|
|
193
|
-
"column < MAX_COLUMNS",
|
|
194
|
-
"`Invalid column: ${column}`"
|
|
195
|
-
]
|
|
196
|
-
});
|
|
197
|
-
return (column >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(column / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + column % 26);
|
|
198
|
-
};
|
|
199
|
-
var addressToA1Notation = ({ column, row }) => {
|
|
200
|
-
return `${columnLetter(column)}${row + 1}`;
|
|
201
|
-
};
|
|
202
|
-
var addressFromA1Notation = (ref) => {
|
|
203
|
-
const match = ref.match(/([A-Z]+)(\d+)/);
|
|
204
|
-
invariant(match, `Invalid notation: ${ref}`, {
|
|
205
|
-
F: __dxlog_file3,
|
|
206
|
-
L: 30,
|
|
207
|
-
S: void 0,
|
|
208
|
-
A: [
|
|
209
|
-
"match",
|
|
210
|
-
"`Invalid notation: ${ref}`"
|
|
211
|
-
]
|
|
212
|
-
});
|
|
213
|
-
return {
|
|
214
|
-
row: parseInt(match[2], 10) - 1,
|
|
215
|
-
column: match[1].split("").reduce((acc, c) => acc * 26 + c.charCodeAt(0) - "A".charCodeAt(0) + 1, 0) - 1
|
|
216
|
-
};
|
|
217
|
-
};
|
|
218
|
-
var rangeToA1Notation = (range) => {
|
|
219
|
-
return [
|
|
220
|
-
range?.from && addressToA1Notation(range?.from),
|
|
221
|
-
range?.to && addressToA1Notation(range?.to)
|
|
222
|
-
].filter(Boolean).join(":");
|
|
223
|
-
};
|
|
224
|
-
var inRange = (range, cell) => {
|
|
225
|
-
if (!range) {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
const { from, to } = range;
|
|
229
|
-
if (from && posEquals(from, cell) || to && posEquals(to, cell)) {
|
|
230
|
-
return true;
|
|
231
|
-
}
|
|
232
|
-
if (!from || !to) {
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
const { column: c1, row: r1 } = from;
|
|
236
|
-
const { column: c2, row: r2 } = to;
|
|
237
|
-
const cMin = Math.min(c1, c2);
|
|
238
|
-
const cMax = Math.max(c1, c2);
|
|
239
|
-
const rMin = Math.min(r1, r2);
|
|
240
|
-
const rMax = Math.max(r1, r2);
|
|
241
|
-
const { column, row } = cell;
|
|
242
|
-
return column >= cMin && column <= cMax && row >= rMin && row <= rMax;
|
|
243
|
-
};
|
|
244
|
-
|
|
245
180
|
// packages/plugins/plugin-sheet/src/model/model.ts
|
|
246
181
|
import { DetailedCellError, ExportedCellChange } from "hyperformula";
|
|
247
182
|
import { Event as Event2 } from "@dxos/async";
|
|
@@ -2624,6 +2559,71 @@ var defaultFunctions = [
|
|
|
2624
2559
|
}
|
|
2625
2560
|
];
|
|
2626
2561
|
|
|
2562
|
+
// packages/plugins/plugin-sheet/src/model/types.ts
|
|
2563
|
+
import { invariant } from "@dxos/invariant";
|
|
2564
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/plugin-sheet/src/model/types.ts";
|
|
2565
|
+
var MAX_COLUMNS = 26 * 26;
|
|
2566
|
+
var posEquals = (a, b) => {
|
|
2567
|
+
return a?.column === b?.column && a?.row === b?.row;
|
|
2568
|
+
};
|
|
2569
|
+
var columnLetter = (column) => {
|
|
2570
|
+
invariant(column < MAX_COLUMNS, `Invalid column: ${column}`, {
|
|
2571
|
+
F: __dxlog_file3,
|
|
2572
|
+
L: 17,
|
|
2573
|
+
S: void 0,
|
|
2574
|
+
A: [
|
|
2575
|
+
"column < MAX_COLUMNS",
|
|
2576
|
+
"`Invalid column: ${column}`"
|
|
2577
|
+
]
|
|
2578
|
+
});
|
|
2579
|
+
return (column >= 26 ? String.fromCharCode("A".charCodeAt(0) + Math.floor(column / 26) - 1) : "") + String.fromCharCode("A".charCodeAt(0) + column % 26);
|
|
2580
|
+
};
|
|
2581
|
+
var addressToA1Notation = ({ column, row }) => {
|
|
2582
|
+
return `${columnLetter(column)}${row + 1}`;
|
|
2583
|
+
};
|
|
2584
|
+
var addressFromA1Notation = (ref) => {
|
|
2585
|
+
const match = ref.match(/([A-Z]+)(\d+)/);
|
|
2586
|
+
invariant(match, `Invalid notation: ${ref}`, {
|
|
2587
|
+
F: __dxlog_file3,
|
|
2588
|
+
L: 30,
|
|
2589
|
+
S: void 0,
|
|
2590
|
+
A: [
|
|
2591
|
+
"match",
|
|
2592
|
+
"`Invalid notation: ${ref}`"
|
|
2593
|
+
]
|
|
2594
|
+
});
|
|
2595
|
+
return {
|
|
2596
|
+
row: parseInt(match[2], 10) - 1,
|
|
2597
|
+
column: match[1].split("").reduce((acc, c) => acc * 26 + c.charCodeAt(0) - "A".charCodeAt(0) + 1, 0) - 1
|
|
2598
|
+
};
|
|
2599
|
+
};
|
|
2600
|
+
var rangeToA1Notation = (range) => {
|
|
2601
|
+
return [
|
|
2602
|
+
range?.from && addressToA1Notation(range?.from),
|
|
2603
|
+
range?.to && addressToA1Notation(range?.to)
|
|
2604
|
+
].filter(Boolean).join(":");
|
|
2605
|
+
};
|
|
2606
|
+
var inRange = (range, cell) => {
|
|
2607
|
+
if (!range) {
|
|
2608
|
+
return false;
|
|
2609
|
+
}
|
|
2610
|
+
const { from, to } = range;
|
|
2611
|
+
if (from && posEquals(from, cell) || to && posEquals(to, cell)) {
|
|
2612
|
+
return true;
|
|
2613
|
+
}
|
|
2614
|
+
if (!from || !to) {
|
|
2615
|
+
return false;
|
|
2616
|
+
}
|
|
2617
|
+
const { column: c1, row: r1 } = from;
|
|
2618
|
+
const { column: c2, row: r2 } = to;
|
|
2619
|
+
const cMin = Math.min(c1, c2);
|
|
2620
|
+
const cMax = Math.max(c1, c2);
|
|
2621
|
+
const rMin = Math.min(r1, r2);
|
|
2622
|
+
const rMax = Math.max(r1, r2);
|
|
2623
|
+
const { column, row } = cell;
|
|
2624
|
+
return column >= cMin && column <= cMax && row >= rMin && row <= rMax;
|
|
2625
|
+
};
|
|
2626
|
+
|
|
2627
2627
|
// packages/plugins/plugin-sheet/src/model/util.ts
|
|
2628
2628
|
import { randomBytes } from "@dxos/crypto";
|
|
2629
2629
|
var ApiError = class extends Error {
|
|
@@ -2765,9 +2765,9 @@ var SheetModel = class {
|
|
|
2765
2765
|
const unsubscribe = this._graph.update.on(() => this.update.emit());
|
|
2766
2766
|
this._ctx.onDispose(unsubscribe);
|
|
2767
2767
|
if (this._space) {
|
|
2768
|
-
const { Filter
|
|
2769
|
-
const { FunctionType
|
|
2770
|
-
const query = this._space?.db.query(
|
|
2768
|
+
const { Filter } = await import("@dxos/client/echo");
|
|
2769
|
+
const { FunctionType } = await import("@dxos/plugin-script/types");
|
|
2770
|
+
const query = this._space?.db.query(Filter.schema(FunctionType));
|
|
2771
2771
|
const unsubscribe2 = query.subscribe(({ objects }) => {
|
|
2772
2772
|
this._functions = objects.filter((fn) => fn.binding);
|
|
2773
2773
|
this.update.emit();
|
|
@@ -3157,146 +3157,71 @@ var SheetModel = class {
|
|
|
3157
3157
|
}
|
|
3158
3158
|
};
|
|
3159
3159
|
|
|
3160
|
-
// packages/plugins/plugin-sheet/src/components/ComputeGraph/
|
|
3161
|
-
import {
|
|
3162
|
-
import {
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
const
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
ttl: 0
|
|
3186
|
-
});
|
|
3187
|
-
});
|
|
3188
|
-
this.context.createSubscription(ast.procedureName, unsubscribe);
|
|
3160
|
+
// packages/plugins/plugin-sheet/src/components/ComputeGraph/custom.ts
|
|
3161
|
+
import { FunctionArgumentType } from "hyperformula";
|
|
3162
|
+
import { getDeep } from "@dxos/util";
|
|
3163
|
+
var parseNumberString = (str) => {
|
|
3164
|
+
return parseFloat(str.replace(/[^\d.]/g, ""));
|
|
3165
|
+
};
|
|
3166
|
+
var CustomPlugin = class extends FunctionPluginAsync {
|
|
3167
|
+
test(ast, state) {
|
|
3168
|
+
const handler = async () => {
|
|
3169
|
+
return Math.random();
|
|
3170
|
+
};
|
|
3171
|
+
return this.runAsyncFunction(ast, state, handler);
|
|
3172
|
+
}
|
|
3173
|
+
crypto(ast, state) {
|
|
3174
|
+
const handler = async (_currency) => {
|
|
3175
|
+
const currency = (_currency || "USD").toUpperCase();
|
|
3176
|
+
const result = await fetch(`https://api.coindesk.com/v1/bpi/currentprice/${currency}.json`);
|
|
3177
|
+
const data = await result.json();
|
|
3178
|
+
const rate = getDeep(data, [
|
|
3179
|
+
"bpi",
|
|
3180
|
+
currency,
|
|
3181
|
+
"rate"
|
|
3182
|
+
]);
|
|
3183
|
+
if (!rate) {
|
|
3184
|
+
return NaN;
|
|
3189
3185
|
}
|
|
3190
|
-
|
|
3191
|
-
const result = await fetch(`${this.context.remoteFunctionUrl}${path}`, {
|
|
3192
|
-
method: "POST",
|
|
3193
|
-
headers: {
|
|
3194
|
-
"Content-Type": "application/json"
|
|
3195
|
-
},
|
|
3196
|
-
body: JSON.stringify({
|
|
3197
|
-
args: args.filter(nonNullable)
|
|
3198
|
-
})
|
|
3199
|
-
});
|
|
3200
|
-
return await result.text();
|
|
3186
|
+
return parseNumberString(rate);
|
|
3201
3187
|
};
|
|
3202
|
-
return this.runAsyncFunction(ast, state, handler
|
|
3203
|
-
ttl:
|
|
3188
|
+
return this.runAsyncFunction(ast, state, handler, {
|
|
3189
|
+
ttl: 1e4
|
|
3204
3190
|
});
|
|
3205
3191
|
}
|
|
3206
3192
|
};
|
|
3207
|
-
|
|
3208
|
-
|
|
3209
|
-
method: "
|
|
3193
|
+
CustomPlugin.implementedFunctions = {
|
|
3194
|
+
TEST: {
|
|
3195
|
+
method: "test",
|
|
3196
|
+
parameters: [],
|
|
3197
|
+
isVolatile: true
|
|
3198
|
+
},
|
|
3199
|
+
CRYPTO: {
|
|
3200
|
+
method: "crypto",
|
|
3210
3201
|
parameters: [
|
|
3211
|
-
// Binding
|
|
3212
|
-
{
|
|
3213
|
-
argumentType: FunctionArgumentType.STRING
|
|
3214
|
-
},
|
|
3215
|
-
// Remote function arguments (currently supporting up to 9).
|
|
3216
|
-
{
|
|
3217
|
-
argumentType: FunctionArgumentType.ANY,
|
|
3218
|
-
optionalArg: true
|
|
3219
|
-
},
|
|
3220
|
-
{
|
|
3221
|
-
argumentType: FunctionArgumentType.ANY,
|
|
3222
|
-
optionalArg: true
|
|
3223
|
-
},
|
|
3224
3202
|
{
|
|
3225
|
-
argumentType: FunctionArgumentType.
|
|
3226
|
-
optionalArg: true
|
|
3227
|
-
},
|
|
3228
|
-
{
|
|
3229
|
-
argumentType: FunctionArgumentType.ANY,
|
|
3230
|
-
optionalArg: true
|
|
3231
|
-
},
|
|
3232
|
-
{
|
|
3233
|
-
argumentType: FunctionArgumentType.ANY,
|
|
3234
|
-
optionalArg: true
|
|
3235
|
-
},
|
|
3236
|
-
{
|
|
3237
|
-
argumentType: FunctionArgumentType.ANY,
|
|
3238
|
-
optionalArg: true
|
|
3239
|
-
},
|
|
3240
|
-
{
|
|
3241
|
-
argumentType: FunctionArgumentType.ANY,
|
|
3242
|
-
optionalArg: true
|
|
3243
|
-
},
|
|
3244
|
-
{
|
|
3245
|
-
argumentType: FunctionArgumentType.ANY,
|
|
3246
|
-
optionalArg: true
|
|
3247
|
-
},
|
|
3248
|
-
{
|
|
3249
|
-
argumentType: FunctionArgumentType.ANY,
|
|
3203
|
+
argumentType: FunctionArgumentType.STRING,
|
|
3250
3204
|
optionalArg: true
|
|
3251
3205
|
}
|
|
3252
3206
|
],
|
|
3253
3207
|
isVolatile: true
|
|
3254
3208
|
}
|
|
3255
3209
|
};
|
|
3256
|
-
var
|
|
3210
|
+
var CustomPluginTranslations = {
|
|
3257
3211
|
enGB: {
|
|
3258
|
-
|
|
3212
|
+
TEST: "TEST",
|
|
3213
|
+
CRYPTO: "CRYPTO"
|
|
3259
3214
|
},
|
|
3260
3215
|
enUS: {
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
};
|
|
3264
|
-
|
|
3265
|
-
// packages/plugins/plugin-sheet/src/components/ComputeGraph/graph-context.tsx
|
|
3266
|
-
import React, { createContext, useContext, useEffect } from "react";
|
|
3267
|
-
var ComputeGraphContext = /* @__PURE__ */ createContext({
|
|
3268
|
-
graphs: {},
|
|
3269
|
-
setGraph: () => {
|
|
3216
|
+
TEST: "TEST",
|
|
3217
|
+
CRYPTO: "CRYPTO"
|
|
3270
3218
|
}
|
|
3271
|
-
});
|
|
3272
|
-
var ComputeGraphContextProvider = ({ children, graphs, setGraph }) => {
|
|
3273
|
-
return /* @__PURE__ */ React.createElement(ComputeGraphContext.Provider, {
|
|
3274
|
-
value: {
|
|
3275
|
-
graphs,
|
|
3276
|
-
setGraph
|
|
3277
|
-
}
|
|
3278
|
-
}, children);
|
|
3279
|
-
};
|
|
3280
|
-
var useComputeGraph = (space, options) => {
|
|
3281
|
-
const { graphs, setGraph } = useContext(ComputeGraphContext);
|
|
3282
|
-
const graph = graphs[space.id] ?? createComputeGraph([
|
|
3283
|
-
{
|
|
3284
|
-
plugin: EdgeFunctionPlugin,
|
|
3285
|
-
translations: EdgeFunctionPluginTranslations
|
|
3286
|
-
}
|
|
3287
|
-
], space, options);
|
|
3288
|
-
useEffect(() => {
|
|
3289
|
-
if (!graphs[space.id]) {
|
|
3290
|
-
setGraph(space.id, graph);
|
|
3291
|
-
}
|
|
3292
|
-
}, [
|
|
3293
|
-
space
|
|
3294
|
-
]);
|
|
3295
|
-
return graph;
|
|
3296
3219
|
};
|
|
3297
3220
|
|
|
3298
3221
|
export {
|
|
3299
3222
|
FunctionPluginAsync,
|
|
3223
|
+
CustomPlugin,
|
|
3224
|
+
CustomPluginTranslations,
|
|
3300
3225
|
createComputeGraph,
|
|
3301
3226
|
defaultFunctions,
|
|
3302
3227
|
posEquals,
|
|
@@ -3305,10 +3230,6 @@ export {
|
|
|
3305
3230
|
addressFromA1Notation,
|
|
3306
3231
|
rangeToA1Notation,
|
|
3307
3232
|
inRange,
|
|
3308
|
-
SheetModel
|
|
3309
|
-
EdgeFunctionPlugin,
|
|
3310
|
-
EdgeFunctionPluginTranslations,
|
|
3311
|
-
ComputeGraphContextProvider,
|
|
3312
|
-
useComputeGraph
|
|
3233
|
+
SheetModel
|
|
3313
3234
|
};
|
|
3314
|
-
//# sourceMappingURL=chunk-
|
|
3235
|
+
//# sourceMappingURL=chunk-P7SSL3EG.mjs.map
|