@plasmicpkgs/plasmic-cms 0.0.297 → 0.0.298

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/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { ApiCmsRow as ApiCmsRow_2 } from './schema';
2
- import { ApiCmsTable as ApiCmsTable_2 } from './schema';
1
+ import { _ApiCmsRow } from '@plasmicpkgs/cms';
2
+ import { _ApiCmsTable } from '@plasmicpkgs/cms';
3
3
  import { CanvasComponentProps } from '@plasmicapp/host/registerComponent';
4
+ import { _CmsFieldMeta } from '@plasmicpkgs/cms';
4
5
  import { ComponentMeta } from '@plasmicapp/host/registerComponent';
5
6
  import { GlobalContextMeta } from '@plasmicapp/host/registerGlobalContext';
6
7
  import { default as React_2 } from 'react';
@@ -11,36 +12,12 @@ export declare class API {
11
12
  private config;
12
13
  constructor(config: DatabaseConfig);
13
14
  get(endpoint: string, params?: any): Promise<any>;
14
- fetchTables(): Promise<ApiCmsTable[]>;
15
+ fetchTables(): Promise<_ApiCmsTable[]>;
15
16
  private useDraftForTable;
16
- query(table: string, params?: QueryParams): Promise<ApiCmsRow[]>;
17
+ query(table: string, params?: QueryParams): Promise<_ApiCmsRow[]>;
17
18
  count(table: string, params?: Pick<QueryParams, "where" | "useDraft">): Promise<number>;
18
19
  }
19
20
 
20
- declare interface ApiCmsRow {
21
- identifier: string | null;
22
- data: Record<string, any> | null;
23
- }
24
-
25
- declare interface ApiCmsTable {
26
- identifier: string;
27
- name: string;
28
- schema: CmsTableSchema;
29
- }
30
-
31
- declare interface CmsBaseType {
32
- identifier: string;
33
- name: string;
34
- helperText: string;
35
- required: boolean;
36
- hidden: boolean;
37
- }
38
-
39
- declare interface CmsBoolean extends CmsBaseType {
40
- type: CmsMetaType.BOOLEAN;
41
- defaultValue?: boolean;
42
- }
43
-
44
21
  export declare function CmsCount({ className, table, setControlContextData, ...rest }: CmsCountProps): React_2.JSX.Element | null;
45
22
 
46
23
  export declare const cmsCountFieldMeta: ComponentMeta<CmsCountProps>;
@@ -58,54 +35,6 @@ declare interface CmsCredentialsProviderProps extends DatabaseConfig {
58
35
  children?: React_2.ReactNode;
59
36
  }
60
37
 
61
- declare interface CmsDateTime extends CmsBaseType {
62
- type: CmsMetaType.DATE_TIME;
63
- defaultValue?: string;
64
- }
65
-
66
- declare interface CmsEnum extends CmsBaseType {
67
- type: CmsMetaType.ENUM;
68
- defaultValue?: string;
69
- options: string[];
70
- }
71
-
72
- declare type CmsFieldMeta = CmsText | CmsLongText | CmsNumber | CmsBoolean | CmsImage | CmsFile | CmsDateTime | CmsRef | CmsRichText | CmsEnum;
73
-
74
- declare interface CmsFile extends CmsBaseType {
75
- type: CmsMetaType.FILE;
76
- defaultValue?: string;
77
- }
78
-
79
- declare interface CmsImage extends CmsBaseType {
80
- type: CmsMetaType.IMAGE;
81
- defaultValue?: string;
82
- }
83
-
84
- declare interface CmsLongText extends CmsBaseType, CmsTextLike {
85
- type: CmsMetaType.LONG_TEXT;
86
- }
87
-
88
- declare const enum CmsMetaType {
89
- TEXT = "text",
90
- LONG_TEXT = "long-text",
91
- NUMBER = "number",
92
- IMAGE = "image",
93
- FILE = "file",
94
- DATE_TIME = "date-time",
95
- BOOLEAN = "boolean",
96
- COLOR = "color",
97
- RICH_TEXT = "rich-text",
98
- REF = "ref",
99
- LIST = "list",
100
- OBJECT = "object",
101
- ENUM = "enum"
102
- }
103
-
104
- declare interface CmsNumber extends CmsBaseType {
105
- type: CmsMetaType.NUMBER;
106
- defaultValue?: number;
107
- }
108
-
109
38
  export declare function CmsQueryRepeater({ table, children, setControlContextData, mode, where, useDraft, orderBy, desc, limit, offset, emptyMessage, forceEmptyState, loadingMessage, forceLoadingState, noLayout, noAutoRepeat, className, filterField, filterValue, fields, }: CmsQueryRepeaterProps): React_2.JSX.Element;
110
39
 
111
40
  export declare const cmsQueryRepeaterMeta: ComponentMeta<CmsQueryRepeaterProps>;
@@ -126,16 +55,6 @@ declare interface CmsQueryRepeaterProps extends QueryParams, CanvasComponentProp
126
55
  mode?: "rows" | "count";
127
56
  }
128
57
 
129
- declare interface CmsRef extends CmsBaseType {
130
- type: CmsMetaType.REF;
131
- defaultValue?: string;
132
- }
133
-
134
- declare interface CmsRichText extends CmsBaseType {
135
- type: CmsMetaType.RICH_TEXT;
136
- defaultValue?: string;
137
- }
138
-
139
58
  export declare function CmsRowField({ className, table, field, dateFormat, setControlContextData, usePlasmicTheme, themeResetClassName, ...rest }: CmsRowFieldProps): React_2.JSX.Element | null;
140
59
 
141
60
  export declare const cmsRowFieldMeta: ComponentMeta<CmsRowFieldProps>;
@@ -184,20 +103,6 @@ declare interface CmsRowLinkProps extends CanvasComponentProps<RowContextData> {
184
103
  suffix?: string;
185
104
  }
186
105
 
187
- declare interface CmsTableSchema {
188
- fields: CmsFieldMeta[];
189
- }
190
-
191
- declare interface CmsText extends CmsBaseType, CmsTextLike {
192
- type: CmsMetaType.TEXT;
193
- }
194
-
195
- declare interface CmsTextLike {
196
- defaultValue?: string;
197
- minChars?: number;
198
- maxChars?: number;
199
- }
200
-
201
106
  export declare interface DatabaseConfig {
202
107
  host: string;
203
108
  databaseId: string;
@@ -206,12 +111,6 @@ export declare interface DatabaseConfig {
206
111
  useDraft?: boolean | string[];
207
112
  }
208
113
 
209
- export declare function fetchContent(cmsId: string, cmsPublicToken: string, tableId: string, params: QueryParams, useDraft: boolean, locale: string): Promise<ApiCmsRow_2[]>;
210
-
211
- export declare function fetchCount(cmsId: string, cmsPublicToken: string, tableId: string, params: QueryParams, useDraft: boolean): Promise<number>;
212
-
213
- export declare function fetchTables(cmsId: string, cmsPublicToken: string): Promise<ApiCmsTable_2[]>;
214
-
215
114
  export declare class HttpError extends Error {
216
115
  status: number;
217
116
  constructor(status: number, message: string);
@@ -234,13 +133,9 @@ export declare function registerAll(loader?: {
234
133
  registerGlobalContext: typeof registerGlobalContext;
235
134
  }): void;
236
135
 
237
- export declare function registerAllCustomFunctions(loader?: {
238
- registerFunction: any;
239
- }): void;
240
-
241
136
  declare interface RowContextData extends TableContextData {
242
- row?: ApiCmsRow;
243
- fieldMeta?: CmsFieldMeta;
137
+ row?: _ApiCmsRow;
138
+ fieldMeta?: _CmsFieldMeta;
244
139
  }
245
140
 
246
141
  declare interface TableContextData extends TablesContextData {
@@ -248,7 +143,7 @@ declare interface TableContextData extends TablesContextData {
248
143
  }
249
144
 
250
145
  declare type TablesContextData = {
251
- tables?: ApiCmsTable[];
146
+ tables?: _ApiCmsTable[];
252
147
  };
253
148
 
254
149
  export { }
package/dist/index.esm.js CHANGED
@@ -57,6 +57,11 @@ import registerGlobalContext from "@plasmicapp/host/registerGlobalContext";
57
57
  // src/components.tsx
58
58
  import { repeatedElement, usePlasmicCanvasContext } from "@plasmicapp/host";
59
59
  import { usePlasmicQueryData } from "@plasmicapp/query";
60
+ import {
61
+ _CmsMetaType as CmsMetaType,
62
+ _mkFieldOptions as mkFieldOptions,
63
+ _mkTableOptions as mkTableOptions
64
+ } from "@plasmicpkgs/cms";
60
65
  import dayjs from "dayjs";
61
66
  import React2 from "react";
62
67
 
@@ -210,7 +215,7 @@ function makeDatabaseCacheKey(config) {
210
215
  if (!config) {
211
216
  return null;
212
217
  }
213
- const _a = config, { databaseToken } = _a, rest = __objRest(_a, ["databaseToken"]);
218
+ const _a = config, { databaseToken: _doNotExposeDatabaseToken } = _a, rest = __objRest(_a, ["databaseToken"]);
214
219
  return JSON.stringify(rest);
215
220
  }
216
221
  function DatabaseProvider({
@@ -365,41 +370,6 @@ function CountProvider({
365
370
  );
366
371
  }
367
372
 
368
- // src/util.ts
369
- function mkTableOptions(tables) {
370
- if (!tables) {
371
- return [];
372
- }
373
- return tables.map((table) => ({
374
- value: table.identifier,
375
- label: table.name
376
- }));
377
- }
378
- function mkFieldOptions(tables, tableIdentifier, types) {
379
- if (!tables) {
380
- return [];
381
- }
382
- const table = tables.find((t) => t.identifier === tableIdentifier);
383
- if (!table) {
384
- return [];
385
- }
386
- let fields = table.schema.fields;
387
- if (types) {
388
- fields = fields.filter((f) => types.includes(f.type));
389
- }
390
- const options = fields.map((f) => ({
391
- value: f.identifier,
392
- label: f.name || f.identifier
393
- }));
394
- if (!options.some((option) => option.value === "_id")) {
395
- options.push({
396
- label: "System-assigned ID",
397
- value: "_id"
398
- });
399
- }
400
- return options;
401
- }
402
-
403
373
  // src/components.tsx
404
374
  var modulePath = "@plasmicpkgs/plasmic-cms";
405
375
  var componentPrefix = "hostless-plasmic-cms";
@@ -556,13 +526,20 @@ var cmsQueryRepeaterMeta = {
556
526
  description: "Field (from model schema) to filter by",
557
527
  options: ({ table }, ctx) => {
558
528
  var _a;
559
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table, [
560
- "number" /* NUMBER */,
561
- "boolean" /* BOOLEAN */,
562
- "text" /* TEXT */,
563
- "long-text" /* LONG_TEXT */,
564
- "ref" /* REF */
565
- ]);
529
+ return mkFieldOptions(
530
+ ctx == null ? void 0 : ctx.tables,
531
+ (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table,
532
+ [
533
+ CmsMetaType.NUMBER,
534
+ CmsMetaType.BOOLEAN,
535
+ CmsMetaType.TEXT,
536
+ CmsMetaType.LONG_TEXT,
537
+ CmsMetaType.REF
538
+ ],
539
+ {
540
+ includeSystemId: true
541
+ }
542
+ );
566
543
  }
567
544
  },
568
545
  filterValue: {
@@ -574,13 +551,20 @@ var cmsQueryRepeaterMeta = {
574
551
  type: "choice",
575
552
  displayName: "Order by",
576
553
  description: "Field to order by.",
577
- options: (_, ctx) => mkFieldOptions(ctx == null ? void 0 : ctx.tables, ctx == null ? void 0 : ctx.table, [
578
- "number" /* NUMBER */,
579
- "boolean" /* BOOLEAN */,
580
- "date-time" /* DATE_TIME */,
581
- "long-text" /* LONG_TEXT */,
582
- "text" /* TEXT */
583
- ]),
554
+ options: (_, ctx) => mkFieldOptions(
555
+ ctx == null ? void 0 : ctx.tables,
556
+ ctx == null ? void 0 : ctx.table,
557
+ [
558
+ CmsMetaType.NUMBER,
559
+ CmsMetaType.BOOLEAN,
560
+ CmsMetaType.DATE_TIME,
561
+ CmsMetaType.LONG_TEXT,
562
+ CmsMetaType.TEXT
563
+ ],
564
+ {
565
+ includeSystemId: true
566
+ }
567
+ ),
584
568
  hidden: (ps) => ps.mode === "count"
585
569
  },
586
570
  desc: {
@@ -612,7 +596,9 @@ var cmsQueryRepeaterMeta = {
612
596
  description: "Fields from the CMS model to include with each row; by default, all fields are included",
613
597
  options: ({ table }, ctx) => {
614
598
  var _a;
615
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table);
599
+ return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table, void 0, {
600
+ includeRefStars: true
601
+ });
616
602
  },
617
603
  hidden: (ps) => ps.mode === "count"
618
604
  },
@@ -781,20 +767,20 @@ var cmsRowFieldMeta = {
781
767
  options: ({ table }, ctx) => {
782
768
  var _a;
783
769
  return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table, [
784
- "number" /* NUMBER */,
785
- "boolean" /* BOOLEAN */,
786
- "text" /* TEXT */,
787
- "long-text" /* LONG_TEXT */,
788
- "date-time" /* DATE_TIME */,
789
- "rich-text" /* RICH_TEXT */,
790
- "image" /* IMAGE */,
791
- "file" /* FILE */,
792
- "enum" /* ENUM */
770
+ CmsMetaType.NUMBER,
771
+ CmsMetaType.BOOLEAN,
772
+ CmsMetaType.TEXT,
773
+ CmsMetaType.LONG_TEXT,
774
+ CmsMetaType.DATE_TIME,
775
+ CmsMetaType.RICH_TEXT,
776
+ CmsMetaType.IMAGE,
777
+ CmsMetaType.FILE,
778
+ CmsMetaType.ENUM
793
779
  ]);
794
780
  },
795
781
  defaultValueHint: (_, ctx) => {
796
782
  var _a, _b;
797
- return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.name) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
783
+ return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.label) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
798
784
  }
799
785
  },
800
786
  dateFormat: {
@@ -815,7 +801,7 @@ var cmsRowFieldMeta = {
815
801
  if (!fieldMeta) {
816
802
  return true;
817
803
  }
818
- return fieldMeta.type !== "date-time" /* DATE_TIME */;
804
+ return fieldMeta.type !== CmsMetaType.DATE_TIME;
819
805
  },
820
806
  options: [
821
807
  {
@@ -914,9 +900,9 @@ function CmsRowField(_a) {
914
900
  tables,
915
901
  field,
916
902
  typeFilters: [
917
- "text" /* TEXT */,
918
- "long-text" /* LONG_TEXT */,
919
- "rich-text" /* RICH_TEXT */
903
+ CmsMetaType.TEXT,
904
+ CmsMetaType.LONG_TEXT,
905
+ CmsMetaType.RICH_TEXT
920
906
  ]
921
907
  }) : void 0;
922
908
  if (tables) {
@@ -937,7 +923,7 @@ function CmsRowField(_a) {
937
923
  if (!data) {
938
924
  return null;
939
925
  }
940
- if (fieldMeta.type === "date-time" /* DATE_TIME */ && dateFormat) {
926
+ if (fieldMeta.type === CmsMetaType.DATE_TIME && dateFormat) {
941
927
  data = dayjs(data).format(dateFormat);
942
928
  }
943
929
  return data ? renderValue(data, fieldMeta.type, __spreadValues({
@@ -986,12 +972,13 @@ function CmsCount(_a) {
986
972
  return /* @__PURE__ */ React2.createElement("div", __spreadValues({ className }, rest), new Intl.NumberFormat().format(res.count));
987
973
  }
988
974
  }
989
- var DEFAULT_TYPE_FILTERS = ["text" /* TEXT */];
975
+ var DEFAULT_TYPE_FILTERS = [CmsMetaType.TEXT];
990
976
  function deriveInferredTableField(opts) {
991
977
  var _a;
992
978
  const { table, tables, field, typeFilters } = opts;
993
- if (!table)
979
+ if (!table) {
994
980
  return void 0;
981
+ }
995
982
  const schema = (_a = tables == null ? void 0 : tables.find((t) => t.identifier === table)) == null ? void 0 : _a.schema;
996
983
  const fieldMeta = field ? schema == null ? void 0 : schema.fields.find((f) => f.identifier === field) : schema == null ? void 0 : schema.fields.find(
997
984
  (f) => (typeFilters != null ? typeFilters : DEFAULT_TYPE_FILTERS).includes(f.type)
@@ -1003,15 +990,16 @@ function assertNever(_) {
1003
990
  }
1004
991
  function renderValue(value, type, props) {
1005
992
  switch (type) {
1006
- case "number" /* NUMBER */:
1007
- case "boolean" /* BOOLEAN */:
1008
- case "text" /* TEXT */:
1009
- case "long-text" /* LONG_TEXT */:
1010
- case "date-time" /* DATE_TIME */:
1011
- case "enum" /* ENUM */:
1012
- case "ref" /* REF */:
993
+ case CmsMetaType.NUMBER:
994
+ case CmsMetaType.BOOLEAN:
995
+ case CmsMetaType.TEXT:
996
+ case CmsMetaType.LONG_TEXT:
997
+ case CmsMetaType.DATE_TIME:
998
+ case CmsMetaType.ENUM:
999
+ case CmsMetaType.REF:
1000
+ case CmsMetaType.COLOR:
1013
1001
  return /* @__PURE__ */ React2.createElement("div", __spreadValues({}, props), value);
1014
- case "rich-text" /* RICH_TEXT */:
1002
+ case CmsMetaType.RICH_TEXT:
1015
1003
  return /* @__PURE__ */ React2.createElement(
1016
1004
  "div",
1017
1005
  __spreadValues({
@@ -1019,7 +1007,7 @@ function renderValue(value, type, props) {
1019
1007
  style: { whiteSpace: "normal" }
1020
1008
  }, props)
1021
1009
  );
1022
- case "image" /* IMAGE */:
1010
+ case CmsMetaType.IMAGE:
1023
1011
  if (value && typeof value === "object" && value.url && value.imageMeta) {
1024
1012
  return /* @__PURE__ */ React2.createElement(
1025
1013
  "img",
@@ -1031,11 +1019,14 @@ function renderValue(value, type, props) {
1031
1019
  );
1032
1020
  }
1033
1021
  return null;
1034
- case "file" /* FILE */:
1022
+ case CmsMetaType.FILE:
1035
1023
  if (value && typeof value === "object" && value.url && value.name) {
1036
1024
  return /* @__PURE__ */ React2.createElement("a", __spreadValues({ href: value.url, target: "_blank" }, props), value.name);
1037
1025
  }
1038
1026
  return null;
1027
+ case CmsMetaType.LIST:
1028
+ case CmsMetaType.OBJECT:
1029
+ return null;
1039
1030
  default:
1040
1031
  assertNever(type);
1041
1032
  }
@@ -1076,7 +1067,7 @@ var cmsRowLinkMeta = {
1076
1067
  },
1077
1068
  defaultValueHint: (_, ctx) => {
1078
1069
  var _a, _b;
1079
- return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.name) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1070
+ return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.label) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1080
1071
  }
1081
1072
  },
1082
1073
  hrefProp: {
@@ -1124,7 +1115,7 @@ function CmsRowLink({
1124
1115
  table: res.table,
1125
1116
  tables,
1126
1117
  field,
1127
- typeFilters: ["file" /* FILE */, "text" /* TEXT */]
1118
+ typeFilters: [CmsMetaType.FILE, CmsMetaType.TEXT]
1128
1119
  });
1129
1120
  if (tables) {
1130
1121
  setControlContextData == null ? void 0 : setControlContextData({
@@ -1144,7 +1135,7 @@ function CmsRowLink({
1144
1135
  const childrenWithProps = React2.Children.map(children, (child) => {
1145
1136
  if (React2.isValidElement(child)) {
1146
1137
  return React2.cloneElement(child, {
1147
- [hrefProp]: fieldMeta.type === "file" /* FILE */ ? value.url : prefix || suffix ? `${prefix || ""}${value}${suffix || ""}` : value
1138
+ [hrefProp]: fieldMeta.type === CmsMetaType.FILE ? value.url : prefix || suffix ? `${prefix || ""}${value}${suffix || ""}` : value
1148
1139
  });
1149
1140
  }
1150
1141
  return child;
@@ -1182,11 +1173,11 @@ var cmsRowImageMeta = {
1182
1173
  description: "Field (from model schema) to use.",
1183
1174
  options: ({ table }, ctx) => {
1184
1175
  var _a;
1185
- return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table, ["image" /* IMAGE */]);
1176
+ return mkFieldOptions(ctx == null ? void 0 : ctx.tables, (_a = ctx == null ? void 0 : ctx.table) != null ? _a : table, [CmsMetaType.IMAGE]);
1186
1177
  },
1187
1178
  defaultValueHint: (_, ctx) => {
1188
1179
  var _a, _b;
1189
- return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.name) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1180
+ return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.label) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1190
1181
  }
1191
1182
  },
1192
1183
  srcProp: {
@@ -1214,7 +1205,7 @@ function CmsRowImage({
1214
1205
  table: res.table,
1215
1206
  tables,
1216
1207
  field,
1217
- typeFilters: ["image" /* IMAGE */]
1208
+ typeFilters: [CmsMetaType.IMAGE]
1218
1209
  });
1219
1210
  if (tables) {
1220
1211
  setControlContextData == null ? void 0 : setControlContextData({
@@ -1276,7 +1267,7 @@ var cmsRowFieldValueMeta = {
1276
1267
  },
1277
1268
  defaultValueHint: (_, ctx) => {
1278
1269
  var _a, _b;
1279
- return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.name) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1270
+ return ((_a = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _a.label) || ((_b = ctx == null ? void 0 : ctx.fieldMeta) == null ? void 0 : _b.identifier);
1280
1271
  }
1281
1272
  },
1282
1273
  valueProp: {
@@ -1311,7 +1302,7 @@ function CmsRowFieldValue(_a) {
1311
1302
  table: res.table,
1312
1303
  tables,
1313
1304
  field,
1314
- typeFilters: ["text" /* TEXT */]
1305
+ typeFilters: [CmsMetaType.TEXT]
1315
1306
  });
1316
1307
  if (tables) {
1317
1308
  setControlContextData == null ? void 0 : setControlContextData({
@@ -1334,152 +1325,6 @@ function CmsRowFieldValue(_a) {
1334
1325
  return /* @__PURE__ */ React2.createElement(React2.Fragment, null, childrenWithProps);
1335
1326
  }
1336
1327
 
1337
- // src/custom-functions.ts
1338
- import registerFunction from "@plasmicapp/host/registerFunction";
1339
- function getCmsHost() {
1340
- var _a;
1341
- return (_a = globalThis["__PLASMIC_CMS_HOST__"]) != null ? _a : DEFAULT_HOST;
1342
- }
1343
- function createTableOptions(_args, ctx) {
1344
- if (!(ctx == null ? void 0 : ctx.tables)) {
1345
- return [];
1346
- }
1347
- return ctx.tables.map((table) => ({
1348
- value: table.identifier,
1349
- label: table.name
1350
- }));
1351
- }
1352
- var sharedTableFnContext = (cmsId, cmsPublicToken, ..._args) => {
1353
- if (!cmsId || !cmsPublicToken) {
1354
- return {
1355
- dataKey: "",
1356
- fetcher: () => __async(void 0, null, function* () {
1357
- return { tables: [] };
1358
- })
1359
- };
1360
- }
1361
- return {
1362
- dataKey: `cms_tables/${JSON.stringify({
1363
- cmsId,
1364
- cmsPublicToken
1365
- })}`,
1366
- fetcher: () => __async(void 0, null, function* () {
1367
- const api = mkApi({
1368
- databaseId: cmsId,
1369
- databaseToken: cmsPublicToken,
1370
- host: getCmsHost()
1371
- });
1372
- const tables = yield api.fetchTables();
1373
- return { tables };
1374
- })
1375
- };
1376
- };
1377
- var cmsIdParam = {
1378
- name: "cmsId",
1379
- type: "string",
1380
- description: "The cms ID"
1381
- };
1382
- var cmsPublicTokenParam = {
1383
- name: "cmsPublicToken",
1384
- type: "string",
1385
- description: "The cms public token"
1386
- };
1387
- var tableIdParam = {
1388
- name: "tableId",
1389
- type: "choice",
1390
- options: createTableOptions
1391
- };
1392
- var paramsParam = {
1393
- name: "params",
1394
- type: "object",
1395
- description: "The parameters to filter the content (e.g., for sorting, limit, offset, advanced queries)"
1396
- };
1397
- var useDraftParam = {
1398
- name: "useDraft",
1399
- type: "boolean",
1400
- description: "Whether to use draft data. Defaults to false."
1401
- };
1402
- var localeParam = {
1403
- name: "locale",
1404
- type: "string",
1405
- description: "The locale to use. Defaults to empty string."
1406
- };
1407
- function fetchTables(cmsId, cmsPublicToken) {
1408
- return __async(this, null, function* () {
1409
- const api = mkApi({
1410
- databaseId: cmsId,
1411
- databaseToken: cmsPublicToken,
1412
- host: getCmsHost()
1413
- });
1414
- return api.fetchTables();
1415
- });
1416
- }
1417
- function fetchContent(cmsId, cmsPublicToken, tableId, params, useDraft, locale) {
1418
- return __async(this, null, function* () {
1419
- const api = mkApi({
1420
- databaseId: cmsId,
1421
- databaseToken: cmsPublicToken,
1422
- host: getCmsHost(),
1423
- useDraft,
1424
- locale
1425
- });
1426
- return api.query(tableId, params);
1427
- });
1428
- }
1429
- function fetchCount(cmsId, cmsPublicToken, tableId, params, useDraft) {
1430
- return __async(this, null, function* () {
1431
- const api = mkApi({
1432
- databaseId: cmsId,
1433
- databaseToken: cmsPublicToken,
1434
- host: getCmsHost(),
1435
- useDraft
1436
- });
1437
- return api.count(tableId, params);
1438
- });
1439
- }
1440
- function registerAllCustomFunctions(loader) {
1441
- function _registerFunction(fn, meta) {
1442
- if (loader) {
1443
- loader.registerFunction(fn, meta);
1444
- } else {
1445
- registerFunction(fn, meta);
1446
- }
1447
- }
1448
- _registerFunction(fetchTables, {
1449
- name: "fetchTables",
1450
- description: "Fetches the tables from the cms",
1451
- importPath: "@plasmicpkgs/plasmic-cms",
1452
- params: [cmsIdParam, cmsPublicTokenParam]
1453
- });
1454
- _registerFunction(fetchContent, {
1455
- name: "fetchContent",
1456
- description: "Fetch content from a cms table",
1457
- importPath: "@plasmicpkgs/plasmic-cms",
1458
- params: [
1459
- cmsIdParam,
1460
- cmsPublicTokenParam,
1461
- tableIdParam,
1462
- paramsParam,
1463
- useDraftParam,
1464
- localeParam
1465
- ],
1466
- fnContext: sharedTableFnContext
1467
- });
1468
- _registerFunction(fetchCount, {
1469
- name: "fetchCount",
1470
- description: "Fetch the count of entries from a cms table",
1471
- importPath: "@plasmicpkgs/plasmic-cms",
1472
- params: [
1473
- cmsIdParam,
1474
- cmsPublicTokenParam,
1475
- tableIdParam,
1476
- paramsParam,
1477
- useDraftParam
1478
- ],
1479
- fnContext: sharedTableFnContext
1480
- });
1481
- }
1482
-
1483
1328
  // src/index.tsx
1484
1329
  function registerAll(loader) {
1485
1330
  const _registerComponent = (Component, defaultMeta) => {
@@ -1521,11 +1366,7 @@ export {
1521
1366
  cmsRowFieldValueMeta,
1522
1367
  cmsRowImageMeta,
1523
1368
  cmsRowLinkMeta,
1524
- fetchContent,
1525
- fetchCount,
1526
- fetchTables,
1527
1369
  mkApi,
1528
- registerAll,
1529
- registerAllCustomFunctions
1370
+ registerAll
1530
1371
  };
1531
1372
  //# sourceMappingURL=index.esm.js.map