@prismicio/types-internal 0.2.11 → 0.3.1-beta.1

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 (32) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/lib/customtypes/CustomType.d.ts +679 -679
  3. package/lib/customtypes/Section.d.ts +683 -683
  4. package/lib/customtypes/Section.js +2 -1
  5. package/lib/customtypes/widgets/Group.d.ts +1 -1
  6. package/lib/customtypes/widgets/Group.js +2 -1
  7. package/lib/customtypes/widgets/Widget.d.ts +678 -678
  8. package/lib/customtypes/widgets/nestable/RichText.d.ts +18 -1
  9. package/lib/customtypes/widgets/nestable/RichText.js +22 -41
  10. package/lib/customtypes/widgets/slices/CompositeSlice.d.ts +2 -2
  11. package/lib/customtypes/widgets/slices/CompositeSlice.js +3 -2
  12. package/lib/customtypes/widgets/slices/LegacySlice.d.ts +1 -1
  13. package/lib/customtypes/widgets/slices/SharedSlice.d.ts +4 -4
  14. package/lib/customtypes/widgets/slices/SharedSlice.js +3 -2
  15. package/lib/customtypes/widgets/slices/Slices.d.ts +720 -720
  16. package/lib/customtypes/widgets/slices/Slices.js +2 -1
  17. package/lib/documents/widgets/index.d.ts +4 -2
  18. package/lib/documents/widgets/index.js +8 -4
  19. package/lib/documents/widgets/nestable/StructuredTextContent/Block.d.ts +49 -16
  20. package/lib/documents/widgets/nestable/StructuredTextContent/Block.js +8 -9
  21. package/package.json +1 -1
  22. package/src/customtypes/CustomType.ts +1 -1
  23. package/src/customtypes/Section.ts +3 -2
  24. package/src/customtypes/widgets/Group.ts +2 -1
  25. package/src/customtypes/widgets/nestable/RichText.ts +24 -42
  26. package/src/customtypes/widgets/slices/CompositeSlice.ts +3 -2
  27. package/src/customtypes/widgets/slices/SharedSlice.ts +3 -2
  28. package/src/customtypes/widgets/slices/Slices.ts +2 -1
  29. package/src/documents/widgets/index.ts +10 -2
  30. package/src/documents/widgets/nestable/StructuredTextContent/Block.ts +12 -11
  31. package/lib/customtypes/Format.d.ts +0 -4
  32. package/lib/customtypes/Format.js +0 -8
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Slices = exports.DynamicSlices = exports.StaticSlices = exports.slicesReader = exports.DynamicSlicesConfig = exports.StaticSlicesConfig = exports.slicesConfigReader = exports.SlicesLabels = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const widgets_1 = require("../../../documents/widgets");
6
7
  const validators_1 = require("../../../validators");
7
8
  const WidgetTypes_1 = (0, tslib_1.__importDefault)(require("../WidgetTypes"));
8
9
  const CompositeSlice_1 = (0, tslib_1.__importDefault)(require("./CompositeSlice"));
@@ -25,7 +26,7 @@ function slicesConfigReader(codec) {
25
26
  return t.exact(t.partial({
26
27
  label: validators_1.StringOrNull,
27
28
  labels: exports.SlicesLabels,
28
- choices: t.record(t.string, t.union([LegacySlice_1.default, CompositeSlice_1.default, codec])),
29
+ choices: t.record(widgets_1.WidgetKey, t.union([LegacySlice_1.default, CompositeSlice_1.default, codec])),
29
30
  }));
30
31
  }
31
32
  exports.slicesConfigReader = slicesConfigReader;
@@ -1,4 +1,5 @@
1
- import { SlicesContent } from "./slices/SlicesContent";
1
+ import * as t from "io-ts";
2
+ import { SlicesContent } from "./slices";
2
3
  import StaticWidgetContent from "./StaticWidgetContent";
3
4
  export * from "./EmptyContent";
4
5
  export * from "./GroupContent";
@@ -28,7 +29,8 @@ export declare const WidgetTypes: {
28
29
  readonly IntegrationFields: "IntegrationFieldsContent";
29
30
  readonly Separator: "SeparatorContent";
30
31
  };
31
- export declare type WidgetKey = string;
32
+ export declare const WidgetKey: t.Type<string, string, unknown>;
33
+ export declare type WidgetKey = t.TypeOf<typeof WidgetKey>;
32
34
  export declare type WidgetContent = SlicesContent | StaticWidgetContent;
33
35
  export declare const Widget: {
34
36
  fromJson(widgetKey: WidgetKey, widgetValue: unknown, widgetTypes: Map<WidgetKey, string>, widgetPositions: Map<WidgetKey, number>): import("fp-ts/lib/Option").None | import("fp-ts/lib/Option").Some<StaticWidgetContent> | import("fp-ts/lib/Option").Some<SlicesContent>;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Widget = exports.WidgetTypes = exports.StaticWidgetContent = exports.Slices = exports.Nestable = void 0;
3
+ exports.Widget = exports.WidgetKey = exports.WidgetTypes = exports.StaticWidgetContent = exports.Slices = exports.Nestable = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const t = (0, tslib_1.__importStar)(require("io-ts"));
6
+ const function_1 = require("../../validators/function");
5
7
  const EmptyContent_1 = require("./EmptyContent");
6
8
  const GroupContent_1 = require("./GroupContent");
7
9
  const nestable_1 = require("./nestable");
8
- const SlicesContent_1 = require("./slices/SlicesContent");
10
+ const slices_1 = require("./slices");
9
11
  const StaticWidgetContent_1 = (0, tslib_1.__importDefault)(require("./StaticWidgetContent"));
10
12
  const UIDContent_1 = require("./UIDContent");
11
13
  (0, tslib_1.__exportStar)(require("./EmptyContent"), exports);
@@ -21,13 +23,15 @@ exports.WidgetTypes = {
21
23
  Empty: EmptyContent_1.EmptyContentType,
22
24
  UID: UIDContent_1.UIDContentType,
23
25
  Group: GroupContent_1.GroupContentType,
24
- slices: SlicesContent_1.SlicesContentType,
26
+ slices: slices_1.SlicesContentType,
25
27
  };
28
+ const widgetKeyRegex = new RegExp("^[^<>]+$");
29
+ exports.WidgetKey = (0, function_1.refineType)(t.string, "WidgetKey", (s) => widgetKeyRegex.test(s));
26
30
  exports.Widget = {
27
31
  fromJson(widgetKey, widgetValue, widgetTypes, widgetPositions) {
28
32
  const fieldType = widgetTypes.get(widgetKey);
29
33
  if (fieldType === "Slices") {
30
- return SlicesContent_1.SlicesContent.fromJson(widgetKey, widgetValue, widgetTypes, widgetPositions);
34
+ return slices_1.SlicesContent.fromJson(widgetKey, widgetValue, widgetTypes, widgetPositions);
31
35
  }
32
36
  else {
33
37
  return StaticWidgetContent_1.default.fromJson([], widgetKey, widgetValue, widgetTypes, widgetPositions);
@@ -1,10 +1,28 @@
1
1
  import * as t from "io-ts";
2
+ import { RichTextNodeType } from "../../../../customtypes/widgets/nestable";
2
3
  export declare const Meta: t.ExactC<t.IntersectionC<[t.PartialC<{
3
4
  data: t.UnknownC;
4
5
  }>, t.TypeC<{
5
6
  start: t.NumberC;
6
7
  end: t.NumberC;
7
- type: t.StringC;
8
+ type: t.KeyofC<{
9
+ heading1: null;
10
+ heading2: null;
11
+ heading3: null;
12
+ heading4: null;
13
+ heading5: null;
14
+ heading6: null;
15
+ paragraph: null;
16
+ strong: null;
17
+ em: null;
18
+ preformatted: null;
19
+ hyperlink: null;
20
+ image: null;
21
+ embed: null;
22
+ "list-item": null;
23
+ "o-list-item": null;
24
+ rtl: null;
25
+ }>;
8
26
  }>]>>;
9
27
  export declare type Meta = t.TypeOf<typeof Meta>;
10
28
  export declare const Span: t.ExactC<t.IntersectionC<[t.PartialC<{
@@ -12,7 +30,24 @@ export declare const Span: t.ExactC<t.IntersectionC<[t.PartialC<{
12
30
  }>, t.TypeC<{
13
31
  start: t.NumberC;
14
32
  end: t.NumberC;
15
- type: t.StringC;
33
+ type: t.KeyofC<{
34
+ heading1: null;
35
+ heading2: null;
36
+ heading3: null;
37
+ heading4: null;
38
+ heading5: null;
39
+ heading6: null;
40
+ paragraph: null;
41
+ strong: null;
42
+ em: null;
43
+ preformatted: null;
44
+ hyperlink: null;
45
+ image: null;
46
+ embed: null;
47
+ "list-item": null;
48
+ "o-list-item": null;
49
+ rtl: null;
50
+ }>;
16
51
  }>]>>;
17
52
  export declare type Span = Meta;
18
53
  export declare const ValidatedMetas: t.Type<({
@@ -20,17 +55,16 @@ export declare const ValidatedMetas: t.Type<({
20
55
  } & {
21
56
  start: number;
22
57
  end: number;
23
- type: string;
58
+ type: RichTextNodeType;
24
59
  })[], ({
25
60
  data?: unknown;
26
61
  } & {
27
62
  start: number;
28
63
  end: number;
29
- type: string;
64
+ type: RichTextNodeType;
30
65
  })[], unknown>;
31
- export declare const ImageBlockType = "image";
32
66
  export declare const ImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
33
- type: t.LiteralC<"image">;
67
+ type: t.LiteralC<RichTextNodeType.image>;
34
68
  data: t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
35
69
  origin: t.ExactC<t.TypeC<{
36
70
  id: t.StringC;
@@ -124,9 +158,8 @@ export declare const ImageBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
124
158
  }>]>>;
125
159
  export declare type ImageBlock = t.TypeOf<typeof ImageBlock>;
126
160
  export declare function checkImageBlock(block: Block): block is ImageBlock;
127
- export declare const EmbedBlockType = "embed";
128
161
  export declare const EmbedBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
129
- type: t.LiteralC<"embed">;
162
+ type: t.LiteralC<RichTextNodeType.embed>;
130
163
  data: t.Type<import("../EmbedContent").EmbedContentO, unknown, unknown>;
131
164
  }>, t.PartialC<{
132
165
  label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
@@ -135,7 +168,7 @@ export declare const EmbedBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
135
168
  export declare type EmbedBlock = t.TypeOf<typeof EmbedBlock>;
136
169
  export declare function checkEmbedBlock(block: Block): block is EmbedBlock;
137
170
  export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
138
- type: t.Type<string, string, unknown>;
171
+ type: t.Type<RichTextNodeType, RichTextNodeType, unknown>;
139
172
  content: t.IntersectionC<[t.TypeC<{
140
173
  text: t.StringC;
141
174
  }>, t.PartialC<{
@@ -144,13 +177,13 @@ export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
144
177
  } & {
145
178
  start: number;
146
179
  end: number;
147
- type: string;
180
+ type: RichTextNodeType;
148
181
  })[], ({
149
182
  data?: unknown;
150
183
  } & {
151
184
  start: number;
152
185
  end: number;
153
- type: string;
186
+ type: RichTextNodeType;
154
187
  })[], unknown>;
155
188
  }>]>;
156
189
  }>, t.PartialC<{
@@ -159,7 +192,7 @@ export declare const TextBlock: t.ExactC<t.IntersectionC<[t.TypeC<{
159
192
  }>]>>;
160
193
  export declare type TextBlock = t.TypeOf<typeof TextBlock>;
161
194
  export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
162
- type: t.LiteralC<"image">;
195
+ type: t.LiteralC<RichTextNodeType.image>;
163
196
  data: t.IntersectionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
164
197
  origin: t.ExactC<t.TypeC<{
165
198
  id: t.StringC;
@@ -251,13 +284,13 @@ export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
251
284
  label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
252
285
  direction: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
253
286
  }>]>>, t.ExactC<t.IntersectionC<[t.TypeC<{
254
- type: t.LiteralC<"embed">;
287
+ type: t.LiteralC<RichTextNodeType.embed>;
255
288
  data: t.Type<import("../EmbedContent").EmbedContentO, unknown, unknown>;
256
289
  }>, t.PartialC<{
257
290
  label: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
258
291
  direction: t.UnionC<[t.Type<string, string, unknown>, t.NullC, t.UndefinedC]>;
259
292
  }>]>>, t.ExactC<t.IntersectionC<[t.TypeC<{
260
- type: t.Type<string, string, unknown>;
293
+ type: t.Type<RichTextNodeType, RichTextNodeType, unknown>;
261
294
  content: t.IntersectionC<[t.TypeC<{
262
295
  text: t.StringC;
263
296
  }>, t.PartialC<{
@@ -266,13 +299,13 @@ export declare const Block: t.UnionC<[t.ExactC<t.IntersectionC<[t.TypeC<{
266
299
  } & {
267
300
  start: number;
268
301
  end: number;
269
- type: string;
302
+ type: RichTextNodeType;
270
303
  })[], ({
271
304
  data?: unknown;
272
305
  } & {
273
306
  start: number;
274
307
  end: number;
275
- type: string;
308
+ type: RichTextNodeType;
276
309
  })[], unknown>;
277
310
  }>]>;
278
311
  }>, t.PartialC<{
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Block = exports.TextBlock = exports.checkEmbedBlock = exports.EmbedBlock = exports.EmbedBlockType = exports.checkImageBlock = exports.ImageBlock = exports.ImageBlockType = exports.ValidatedMetas = exports.Span = exports.Meta = void 0;
3
+ exports.Block = exports.TextBlock = exports.checkEmbedBlock = exports.EmbedBlock = exports.checkImageBlock = exports.ImageBlock = exports.ValidatedMetas = exports.Span = exports.Meta = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const E = (0, tslib_1.__importStar)(require("fp-ts/lib/Either"));
6
6
  const t = (0, tslib_1.__importStar)(require("io-ts"));
7
+ const nestable_1 = require("../../../../customtypes/widgets/nestable");
7
8
  const validators_1 = require("../../../../validators");
8
9
  const function_1 = require("../../../../validators/function");
9
10
  const EmbedContent_1 = require("../EmbedContent");
@@ -16,7 +17,7 @@ exports.Meta = t.exact(t.intersection([
16
17
  t.type({
17
18
  start: t.number,
18
19
  end: t.number,
19
- type: t.string,
20
+ type: nestable_1.RichTextNodeTypeCodec,
20
21
  }),
21
22
  ]));
22
23
  // export alias for code clarity
@@ -44,10 +45,9 @@ exports.ValidatedMetas = new t.Type("ValidatedMetas", (metas) => Array.isArray(m
44
45
  else
45
46
  return t.failure(metas, c);
46
47
  }, (m) => t.array(exports.Meta).encode(m));
47
- exports.ImageBlockType = "image";
48
48
  exports.ImageBlock = t.exact(t.intersection([
49
49
  t.type({
50
- type: t.literal(exports.ImageBlockType),
50
+ type: t.literal(nestable_1.RichTextNodeType.image),
51
51
  data: t.intersection([
52
52
  ImageContent_1.ImageContentView,
53
53
  t.partial({
@@ -61,13 +61,12 @@ exports.ImageBlock = t.exact(t.intersection([
61
61
  }),
62
62
  ]));
63
63
  function checkImageBlock(block) {
64
- return block.type === exports.ImageBlockType;
64
+ return block.type === nestable_1.RichTextNodeType.image;
65
65
  }
66
66
  exports.checkImageBlock = checkImageBlock;
67
- exports.EmbedBlockType = "embed";
68
67
  exports.EmbedBlock = t.exact(t.intersection([
69
68
  t.type({
70
- type: t.literal(exports.EmbedBlockType),
69
+ type: t.literal(nestable_1.RichTextNodeType.embed),
71
70
  data: EmbedContent_1.EmbedContent,
72
71
  }),
73
72
  t.partial({
@@ -76,12 +75,12 @@ exports.EmbedBlock = t.exact(t.intersection([
76
75
  }),
77
76
  ]));
78
77
  function checkEmbedBlock(block) {
79
- return block.type === exports.EmbedBlockType;
78
+ return block.type === nestable_1.RichTextNodeType.embed;
80
79
  }
81
80
  exports.checkEmbedBlock = checkEmbedBlock;
82
81
  exports.TextBlock = t.exact(t.intersection([
83
82
  t.type({
84
- type: (0, function_1.refineType)(t.string, `string which isn't ${exports.ImageBlockType} ${exports.EmbedBlockType}`, (s) => s !== exports.ImageBlockType && s !== exports.EmbedBlockType),
83
+ type: (0, function_1.refineType)(nestable_1.RichTextNodeTypeCodec, `string which isn't ${nestable_1.RichTextNodeType.image} ${nestable_1.RichTextNodeType.embed}`, (s) => s !== nestable_1.RichTextNodeType.image && s !== nestable_1.RichTextNodeType.embed),
85
84
  content: t.intersection([
86
85
  t.type({
87
86
  text: t.string,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prismicio/types-internal",
3
- "version": "0.2.11",
3
+ "version": "0.3.1-beta.1",
4
4
  "description": "Prismic types for Custom Types and Prismic Data",
5
5
  "keywords": [
6
6
  "typescript",
@@ -38,7 +38,7 @@ function customTypeReader<T extends StaticSection | DynamicSection>(
38
38
  id: t.string,
39
39
  label: StringOrNull,
40
40
  repeatable: withFallback(t.boolean, true),
41
- json: t.record(t.string, codec),
41
+ json: t.record(t.string, codec), //tab name => tab data
42
42
  status: withFallback(t.boolean, true),
43
43
  }),
44
44
  t.partial({
@@ -1,12 +1,13 @@
1
1
  import * as t from "io-ts"
2
2
 
3
- import type { SharedSlice } from "./widgets/slices/SharedSlice"
3
+ import { WidgetKey } from "../documents/widgets"
4
+ import type { SharedSlice } from "./widgets/slices"
4
5
  import { DynamicWidget, StaticWidget, Widgets } from "./widgets/Widget"
5
6
 
6
7
  export function sectionReader<T extends StaticWidget | DynamicWidget>(
7
8
  codec: t.Type<T, unknown>,
8
9
  ) {
9
- return t.record(t.string, codec)
10
+ return t.record(WidgetKey, codec) // WidgetId -> Widget Data
10
11
  }
11
12
 
12
13
  export const StaticSection = sectionReader(StaticWidget)
@@ -1,5 +1,6 @@
1
1
  import * as t from "io-ts"
2
2
 
3
+ import { WidgetKey } from "../../documents/widgets"
3
4
  import { StringOrNull } from "../../validators"
4
5
  import NestableWidget from "./nestable/NestableWidget"
5
6
  import WidgetTypes from "./WidgetTypes"
@@ -8,7 +9,7 @@ const GroupConfig = t.exact(
8
9
  t.partial({
9
10
  label: StringOrNull,
10
11
  repeat: t.boolean,
11
- fields: t.record(t.string, NestableWidget),
12
+ fields: t.record(WidgetKey, NestableWidget),
12
13
  }),
13
14
  )
14
15
  type GroupConfig = t.TypeOf<typeof GroupConfig>
@@ -1,4 +1,4 @@
1
- import { either } from "fp-ts/lib/Either"
1
+ import { either, getOrElseW } from "fp-ts/lib/Either"
2
2
  import * as t from "io-ts"
3
3
 
4
4
  import { StringOrNull } from "../../../validators"
@@ -26,46 +26,24 @@ export enum RichTextNodeType {
26
26
  rtl = "rtl",
27
27
  }
28
28
 
29
- export function parseRichTextNodeType(
30
- str: string,
31
- ): RichTextNodeType | undefined {
32
- switch (str) {
33
- case RichTextNodeType.heading1:
34
- return RichTextNodeType.heading1
35
- case RichTextNodeType.heading2:
36
- return RichTextNodeType.heading2
37
- case RichTextNodeType.heading3:
38
- return RichTextNodeType.heading3
39
- case RichTextNodeType.heading4:
40
- return RichTextNodeType.heading4
41
- case RichTextNodeType.heading5:
42
- return RichTextNodeType.heading5
43
- case RichTextNodeType.heading6:
44
- return RichTextNodeType.heading6
45
- case RichTextNodeType.paragraph:
46
- return RichTextNodeType.paragraph
47
- case RichTextNodeType.strong:
48
- return RichTextNodeType.strong
49
- case RichTextNodeType.em:
50
- return RichTextNodeType.em
51
- case RichTextNodeType.preformatted:
52
- return RichTextNodeType.preformatted
53
- case RichTextNodeType.hyperlink:
54
- return RichTextNodeType.hyperlink
55
- case RichTextNodeType.image:
56
- return RichTextNodeType.image
57
- case RichTextNodeType.embed:
58
- return RichTextNodeType.embed
59
- case RichTextNodeType.list:
60
- return RichTextNodeType.list
61
- case RichTextNodeType.orderedList:
62
- return RichTextNodeType.orderedList
63
- case RichTextNodeType.rtl:
64
- return RichTextNodeType.rtl
65
- default:
66
- return
67
- }
68
- }
29
+ export const RichTextNodeTypeCodec = t.keyof({
30
+ [RichTextNodeType.heading1]: null,
31
+ [RichTextNodeType.heading2]: null,
32
+ [RichTextNodeType.heading3]: null,
33
+ [RichTextNodeType.heading4]: null,
34
+ [RichTextNodeType.heading5]: null,
35
+ [RichTextNodeType.heading6]: null,
36
+ [RichTextNodeType.paragraph]: null,
37
+ [RichTextNodeType.strong]: null,
38
+ [RichTextNodeType.em]: null,
39
+ [RichTextNodeType.preformatted]: null,
40
+ [RichTextNodeType.hyperlink]: null,
41
+ [RichTextNodeType.image]: null,
42
+ [RichTextNodeType.embed]: null,
43
+ [RichTextNodeType.list]: null,
44
+ [RichTextNodeType.orderedList]: null,
45
+ [RichTextNodeType.rtl]: null,
46
+ })
69
47
 
70
48
  const RichTextOptions = new t.Type<string, string, unknown>(
71
49
  "RichTextOptions",
@@ -76,7 +54,11 @@ const RichTextOptions = new t.Type<string, string, unknown>(
76
54
  (s: string | null) => {
77
55
  if (!s) return t.success(DEFAULT_OPTION)
78
56
  const entries = s.split(",").map((e: string) => e.trim())
79
- const filtered = entries.filter((entry) => parseRichTextNodeType(entry))
57
+ const filtered = entries.filter((entry) => {
58
+ return getOrElseW(() => undefined)(
59
+ RichTextNodeTypeCodec.decode(entry),
60
+ )
61
+ })
80
62
  if (!filtered.length) return t.success(DEFAULT_OPTION)
81
63
 
82
64
  return t.success(filtered.join(","))
@@ -1,5 +1,6 @@
1
1
  import * as t from "io-ts"
2
2
 
3
+ import { WidgetKey } from "../../../documents/widgets"
3
4
  import { StringOrNull } from "../../../validators"
4
5
  import NestableWidget from "../nestable/NestableWidget"
5
6
  import SlicesTypes from "./SlicesTypes"
@@ -21,8 +22,8 @@ const CompositeSlice = t.exact(
21
22
  description: t.string,
22
23
  icon: t.string,
23
24
  display: t.string,
24
- "non-repeat": t.record(t.string, NestableWidget),
25
- repeat: t.record(t.string, NestableWidget),
25
+ "non-repeat": t.record(WidgetKey, NestableWidget),
26
+ repeat: t.record(WidgetKey, NestableWidget),
26
27
  config: CompositeSliceConfig,
27
28
  }),
28
29
  ]),
@@ -1,6 +1,7 @@
1
1
  import * as t from "io-ts"
2
2
  import { withFallback } from "io-ts-types/lib/withFallback"
3
3
 
4
+ import { WidgetKey } from "../../../documents/widgets"
4
5
  import NestableWidget from "../nestable/NestableWidget"
5
6
  import SlicesTypes from "./SlicesTypes"
6
7
 
@@ -19,8 +20,8 @@ export const Variation = t.exact(
19
20
  }),
20
21
  t.partial({
21
22
  display: t.string,
22
- primary: t.record(t.string, NestableWidget),
23
- items: t.record(t.string, NestableWidget),
23
+ primary: t.record(WidgetKey, NestableWidget),
24
+ items: t.record(WidgetKey, NestableWidget),
24
25
  }),
25
26
  ]),
26
27
  )
@@ -1,5 +1,6 @@
1
1
  import * as t from "io-ts"
2
2
 
3
+ import { WidgetKey } from "../../../documents/widgets"
3
4
  import { StringOrNull } from "../../../validators"
4
5
  import WidgetTypes from "../WidgetTypes"
5
6
  import CompositeSlice from "./CompositeSlice"
@@ -36,7 +37,7 @@ export function slicesConfigReader<T extends SharedSlice | SharedSliceRef>(
36
37
  label: StringOrNull,
37
38
  labels: SlicesLabels,
38
39
  choices: t.record(
39
- t.string,
40
+ WidgetKey,
40
41
  t.union([LegacySlice, CompositeSlice, codec]),
41
42
  ),
42
43
  }),
@@ -1,7 +1,10 @@
1
+ import * as t from "io-ts"
2
+
3
+ import { refineType } from "../../validators/function"
1
4
  import { EmptyContentType } from "./EmptyContent"
2
5
  import { GroupContentType } from "./GroupContent"
3
6
  import { NestableTypes } from "./nestable"
4
- import { SlicesContent, SlicesContentType } from "./slices/SlicesContent"
7
+ import { SlicesContent, SlicesContentType } from "./slices"
5
8
  import StaticWidgetContent from "./StaticWidgetContent"
6
9
  import { UIDContentType } from "./UIDContent"
7
10
 
@@ -24,7 +27,12 @@ export const WidgetTypes = {
24
27
  slices: SlicesContentType,
25
28
  } as const
26
29
 
27
- export type WidgetKey = string
30
+ const widgetKeyRegex = new RegExp("^[^<>]+$")
31
+ export const WidgetKey = refineType(t.string, "WidgetKey", (s: string) =>
32
+ widgetKeyRegex.test(s),
33
+ )
34
+ export type WidgetKey = t.TypeOf<typeof WidgetKey>
35
+
28
36
  export type WidgetContent = SlicesContent | StaticWidgetContent
29
37
 
30
38
  export const Widget = {
@@ -1,6 +1,10 @@
1
1
  import * as E from "fp-ts/lib/Either"
2
2
  import * as t from "io-ts"
3
3
 
4
+ import {
5
+ RichTextNodeType,
6
+ RichTextNodeTypeCodec,
7
+ } from "../../../../customtypes/widgets/nestable"
4
8
  import { StringOrNull } from "../../../../validators"
5
9
  import { nullable, refineType } from "../../../../validators/function"
6
10
  import { EmbedContent } from "../EmbedContent"
@@ -15,7 +19,7 @@ export const Meta = t.exact(
15
19
  t.type({
16
20
  start: t.number,
17
21
  end: t.number,
18
- type: t.string,
22
+ type: RichTextNodeTypeCodec,
19
23
  }),
20
24
  ]),
21
25
  )
@@ -54,12 +58,10 @@ export const ValidatedMetas = new t.Type<Meta[], Meta[], unknown>(
54
58
  (m) => t.array(Meta).encode(m),
55
59
  )
56
60
 
57
- export const ImageBlockType = "image"
58
-
59
61
  export const ImageBlock = t.exact(
60
62
  t.intersection([
61
63
  t.type({
62
- type: t.literal(ImageBlockType),
64
+ type: t.literal(RichTextNodeType.image),
63
65
  data: t.intersection([
64
66
  ImageContentView,
65
67
  t.partial({
@@ -75,14 +77,13 @@ export const ImageBlock = t.exact(
75
77
  )
76
78
  export type ImageBlock = t.TypeOf<typeof ImageBlock>
77
79
  export function checkImageBlock(block: Block): block is ImageBlock {
78
- return block.type === ImageBlockType
80
+ return block.type === RichTextNodeType.image
79
81
  }
80
82
 
81
- export const EmbedBlockType = "embed"
82
83
  export const EmbedBlock = t.exact(
83
84
  t.intersection([
84
85
  t.type({
85
- type: t.literal(EmbedBlockType),
86
+ type: t.literal(RichTextNodeType.embed),
86
87
  data: EmbedContent,
87
88
  }),
88
89
  t.partial({
@@ -93,16 +94,16 @@ export const EmbedBlock = t.exact(
93
94
  )
94
95
  export type EmbedBlock = t.TypeOf<typeof EmbedBlock>
95
96
  export function checkEmbedBlock(block: Block): block is EmbedBlock {
96
- return block.type === EmbedBlockType
97
+ return block.type === RichTextNodeType.embed
97
98
  }
98
99
 
99
100
  export const TextBlock = t.exact(
100
101
  t.intersection([
101
102
  t.type({
102
103
  type: refineType(
103
- t.string,
104
- `string which isn't ${ImageBlockType} ${EmbedBlockType}`,
105
- (s) => s !== ImageBlockType && s !== EmbedBlockType,
104
+ RichTextNodeTypeCodec,
105
+ `string which isn't ${RichTextNodeType.image} ${RichTextNodeType.embed}`,
106
+ (s) => s !== RichTextNodeType.image && s !== RichTextNodeType.embed,
106
107
  ),
107
108
  content: t.intersection([
108
109
  t.type({
@@ -1,4 +0,0 @@
1
- export declare enum Format {
2
- Static = "static",
3
- Dynamic = "dynamic"
4
- }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Format = void 0;
4
- var Format;
5
- (function (Format) {
6
- Format["Static"] = "static";
7
- Format["Dynamic"] = "dynamic";
8
- })(Format = exports.Format || (exports.Format = {}));