grist-widget-sdk 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/dist/actions.cjs +96 -0
  3. package/dist/actions.cjs.map +1 -0
  4. package/dist/actions.d.cts +36 -0
  5. package/dist/actions.d.ts +36 -0
  6. package/dist/actions.js +29 -0
  7. package/dist/actions.js.map +1 -0
  8. package/dist/app.cjs +49 -8
  9. package/dist/app.cjs.map +1 -1
  10. package/dist/app.d.cts +3 -2
  11. package/dist/app.d.ts +3 -2
  12. package/dist/app.js +4 -3
  13. package/dist/{chunk-4ZGVKGDF.js → chunk-A4KFKOEQ.js} +2 -58
  14. package/dist/chunk-A4KFKOEQ.js.map +1 -0
  15. package/dist/{chunk-OXA2VITC.js → chunk-CMN4M4S3.js} +6 -4
  16. package/dist/{chunk-OXA2VITC.js.map → chunk-CMN4M4S3.js.map} +1 -1
  17. package/dist/{chunk-MAPAWVQC.js → chunk-DKCRFNAW.js} +104 -17
  18. package/dist/chunk-DKCRFNAW.js.map +1 -0
  19. package/dist/{chunk-LSALXIGM.js → chunk-TUPCTWE5.js} +7 -3
  20. package/dist/chunk-TUPCTWE5.js.map +1 -0
  21. package/dist/chunk-YGQXH2P5.js +81 -0
  22. package/dist/chunk-YGQXH2P5.js.map +1 -0
  23. package/dist/{define-widget-B1FIvI-h.d.cts → define-widget-CYYdqRmB.d.cts} +39 -29
  24. package/dist/{define-widget-B9gEtJP0.d.ts → define-widget-D-NmSglS.d.ts} +39 -29
  25. package/dist/emulator/testing.cjs +49 -8
  26. package/dist/emulator/testing.cjs.map +1 -1
  27. package/dist/emulator/testing.d.cts +1 -0
  28. package/dist/emulator/testing.d.ts +1 -0
  29. package/dist/emulator/testing.js +8 -6
  30. package/dist/emulator/testing.js.map +1 -1
  31. package/dist/emulator.cjs.map +1 -1
  32. package/dist/emulator.js +3 -2
  33. package/dist/index.cjs +128 -23
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +30 -3
  36. package/dist/index.d.ts +30 -3
  37. package/dist/index.js +12 -11
  38. package/dist/{mount-grist-widget-Dtelqao_.d.cts → mount-grist-widget-D0mr__ga.d.cts} +1 -1
  39. package/dist/{mount-grist-widget-CkB-3iG_.d.ts → mount-grist-widget-DVcFl5Ys.d.ts} +1 -1
  40. package/package.json +11 -1
  41. package/dist/chunk-4ZGVKGDF.js.map +0 -1
  42. package/dist/chunk-LSALXIGM.js.map +0 -1
  43. package/dist/chunk-MAPAWVQC.js.map +0 -1
@@ -3,7 +3,10 @@ import {
3
3
  coerceGristDocApiRefRowId,
4
4
  decodeGristValue,
5
5
  encodeGristValue
6
- } from "./chunk-4ZGVKGDF.js";
6
+ } from "./chunk-A4KFKOEQ.js";
7
+ import {
8
+ grist_user_actions_exports
9
+ } from "./chunk-YGQXH2P5.js";
7
10
 
8
11
  // src/sdk/helpers/grist-table-data.ts
9
12
  function computeRowCount(data) {
@@ -600,6 +603,27 @@ function mapAndCheck(record, columns, mappings, schema) {
600
603
  // src/sdk/use-grist.ts
601
604
  import { createContext, useCallback, useContext, useEffect, useMemo, useSyncExternalStore } from "react";
602
605
 
606
+ // src/sdk/helpers/deprecate.ts
607
+ function isDevelopment() {
608
+ try {
609
+ return process.env.NODE_ENV !== "production";
610
+ } catch {
611
+ return false;
612
+ }
613
+ }
614
+ var warned = /* @__PURE__ */ new Set();
615
+ function warnDeprecated(name, instead) {
616
+ if (warned.has(name) || !isDevelopment()) return;
617
+ warned.add(name);
618
+ console.warn(`[grist-widget-sdk] ${name} is deprecated and goes in 1.0: ${instead}. https://gristwidgets.com/docs/sdk/api/deprecated`);
619
+ }
620
+ function deprecatedFunction(name, instead, fn) {
621
+ return ((...args) => {
622
+ warnDeprecated(name, instead);
623
+ return fn(...args);
624
+ });
625
+ }
626
+
603
627
  // src/sdk/helpers/build-replica-document.ts
604
628
  var FORMULA_PREVIEW_MAX = 500;
605
629
  function readCellStr(table, key, rowIndex) {
@@ -862,15 +886,32 @@ function createGristApi(runtime) {
862
886
  destroy: (ids) => write(() => resolve().destroy(ids))
863
887
  });
864
888
  const tables = /* @__PURE__ */ new Map();
889
+ const selectedColumns = (options) => read(async () => {
890
+ const impl = docApi().fetchSelectedTable ?? grist.fetchSelectedTable;
891
+ if (!impl) throw new Error("fetchSelectedTable is not available in this Grist version");
892
+ return await impl({ keepEncoded: false, ...options });
893
+ });
894
+ const tableColumns = (tableId) => read(async () => await docApi().fetchTable(tableId));
895
+ const fetchRows = (async (a, b) => {
896
+ const tableId = typeof a === "string" ? a : null;
897
+ const { columnar, ...rowOptions } = (typeof a === "object" && a !== null ? a : b) ?? {};
898
+ if (tableId === null) {
899
+ const data = await selectedColumns(rowOptions.columns ? { keepEncoded: true } : void 0);
900
+ return columnar ? data : materializeGristRowsFromColumnar(data, { order: "none", ...rowOptions });
901
+ }
902
+ if (columnar) return tableColumns(tableId);
903
+ return read(() => fetchGristTableRows(docApi(), tableId, rowOptions));
904
+ });
865
905
  return {
866
906
  reload: () => runtime.reload(),
867
- fetchSelectedTable: (options) => read(async () => {
868
- const impl = docApi().fetchSelectedTable ?? grist.fetchSelectedTable;
869
- if (!impl) throw new Error("fetchSelectedTable is not available in this Grist version");
870
- return await impl({ keepEncoded: false, ...options });
871
- }),
872
- fetchTable: (tableId) => read(async () => await docApi().fetchTable(tableId)),
873
- fetchTableRows: (tableId, options) => read(() => fetchGristTableRows(docApi(), tableId, options ?? {})),
907
+ fetchRows,
908
+ fetchSelectedTable: deprecatedFunction("useGrist().fetchSelectedTable()", "use fetchRows({ columnar: true }), or fetchRows() for rows", selectedColumns),
909
+ fetchTable: deprecatedFunction("useGrist().fetchTable()", "use fetchRows(tableId, { columnar: true }), or fetchRows(tableId) for rows", tableColumns),
910
+ fetchTableRows: deprecatedFunction(
911
+ "useGrist().fetchTableRows()",
912
+ "use fetchRows(tableId, options)",
913
+ (tableId, options) => read(() => fetchGristTableRows(docApi(), tableId, options ?? {}))
914
+ ),
874
915
  listTables: (options) => read(async () => {
875
916
  const all = [...await docApi().listTables()];
876
917
  return options?.includeSystem ? all : all.filter((t) => !t.startsWith("_grist") && !t.startsWith("GristHidden_"));
@@ -1392,11 +1433,9 @@ function buildResult(state, mapped, connection, mapBack, resolveMappedColumnId,
1392
1433
  const { runtime, api } = connection;
1393
1434
  const status = deriveStatus(state);
1394
1435
  const columns = runtime.options.columns;
1395
- return {
1436
+ const result = {
1396
1437
  ...api,
1397
1438
  status,
1398
- isAvailable: state.connection === "connecting" ? null : state.connection !== "not-embedded" && state.connection !== "unavailable",
1399
- isReady: status === "ready",
1400
1439
  error: deriveError(state),
1401
1440
  theme: state.theme,
1402
1441
  record: state.record,
@@ -1416,6 +1455,22 @@ function buildResult(state, mapped, connection, mapBack, resolveMappedColumnId,
1416
1455
  actionError: state.actionError,
1417
1456
  widgetOptions: state.widgetOptions
1418
1457
  };
1458
+ const isAvailable = state.connection === "connecting" ? null : state.connection !== "not-embedded" && state.connection !== "unavailable";
1459
+ Object.defineProperties(result, {
1460
+ isAvailable: {
1461
+ get() {
1462
+ warnDeprecated("useGrist().isAvailable", 'read status: "unavailable" outside Grist, "booting" while connecting');
1463
+ return isAvailable;
1464
+ }
1465
+ },
1466
+ isReady: {
1467
+ get() {
1468
+ warnDeprecated("useGrist().isReady", 'use status === "ready"');
1469
+ return status === "ready";
1470
+ }
1471
+ }
1472
+ });
1473
+ return result;
1419
1474
  }
1420
1475
  var EMPTY_MAPPINGS = Object.freeze({});
1421
1476
  function useGristResult(connection) {
@@ -1458,6 +1513,7 @@ function useGristOptional() {
1458
1513
  return fromProvider ? result : null;
1459
1514
  }
1460
1515
  function useGristContext() {
1516
+ warnDeprecated("useGristContext()", "use widget.useGrist() (or useGrist()): mountGristWidget() always renders the provider");
1461
1517
  if (!useContext(GristContext)) {
1462
1518
  throw new Error("useGristContext() must be used inside <GristWidgetProvider> (mountGristWidget renders one).");
1463
1519
  }
@@ -1700,9 +1756,9 @@ function useGristSchema(options) {
1700
1756
  onEditOptions: options?.onEditOptions
1701
1757
  });
1702
1758
  const connection = useGristRuntime();
1703
- const isAvailable = w.isAvailable;
1759
+ const isAvailable = w.status === "booting" ? null : w.status !== "unavailable";
1704
1760
  const readyError = w.status === "error" || w.status === "unavailable" ? w.error : null;
1705
- const docApi = w.isReady && typeof grist !== "undefined" ? grist.docApi ?? null : null;
1761
+ const docApi = w.status === "ready" && typeof grist !== "undefined" ? grist.docApi ?? null : null;
1706
1762
  const [document2, setDocument] = useState3(null);
1707
1763
  const [loading, setLoading] = useState3(false);
1708
1764
  const [error, setError] = useState3(null);
@@ -1818,8 +1874,7 @@ function useGristSchema(options) {
1818
1874
  return a.localeCompare(b);
1819
1875
  });
1820
1876
  }, []);
1821
- return {
1822
- isAvailable,
1877
+ const result = {
1823
1878
  document: document2,
1824
1879
  replicaDocument: document2,
1825
1880
  table,
@@ -1835,6 +1890,13 @@ function useGristSchema(options) {
1835
1890
  error: readyError ?? error,
1836
1891
  reload: load
1837
1892
  };
1893
+ Object.defineProperty(result, "isAvailable", {
1894
+ get() {
1895
+ warnDeprecated("useGristSchema().isAvailable", 'read useGrist().status: "unavailable" outside Grist, "booting" while connecting');
1896
+ return isAvailable;
1897
+ }
1898
+ });
1899
+ return result;
1838
1900
  }
1839
1901
 
1840
1902
  // src/sdk/use-widget-metadata.ts
@@ -1868,6 +1930,22 @@ function setMetaTag(key, value, content) {
1868
1930
  meta.setAttribute("content", content);
1869
1931
  }
1870
1932
 
1933
+ // src/sdk/deprecated-actions.ts
1934
+ var moved = (name) => deprecatedFunction(
1935
+ `${name} from "grist-widget-sdk"`,
1936
+ `import it from "grist-widget-sdk/actions"`,
1937
+ grist_user_actions_exports[name]
1938
+ );
1939
+ var gristAddColumnAction = moved("gristAddColumnAction");
1940
+ var gristAddRecordAction = moved("gristAddRecordAction");
1941
+ var gristAddTableAction = moved("gristAddTableAction");
1942
+ var gristAddVisibleColumnAction = moved("gristAddVisibleColumnAction");
1943
+ var gristModifyColumnAction = moved("gristModifyColumnAction");
1944
+ var gristRemoveColumnAction = moved("gristRemoveColumnAction");
1945
+ var gristRemoveRecordAction = moved("gristRemoveRecordAction");
1946
+ var gristRenameColumnAction = moved("gristRenameColumnAction");
1947
+ var gristUpdateRecordAction = moved("gristUpdateRecordAction");
1948
+
1871
1949
  export {
1872
1950
  tableDataToRows,
1873
1951
  resolveGristFormulaKind,
@@ -1893,6 +1971,15 @@ export {
1893
1971
  GristWidgetProvider,
1894
1972
  GristBoundary,
1895
1973
  useGristSchema,
1896
- useWidgetMetadata
1974
+ useWidgetMetadata,
1975
+ gristAddColumnAction,
1976
+ gristAddRecordAction,
1977
+ gristAddTableAction,
1978
+ gristAddVisibleColumnAction,
1979
+ gristModifyColumnAction,
1980
+ gristRemoveColumnAction,
1981
+ gristRemoveRecordAction,
1982
+ gristRenameColumnAction,
1983
+ gristUpdateRecordAction
1897
1984
  };
1898
- //# sourceMappingURL=chunk-MAPAWVQC.js.map
1985
+ //# sourceMappingURL=chunk-DKCRFNAW.js.map