@prismicio/types-internal 2.4.0 → 2.4.1-alpha.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.
- package/lib/customtypes/diff/Variation.d.ts +3 -4
- package/lib/customtypes/diff/Variation.js +40 -2
- package/lib/customtypes/diff/Widgets.d.ts +11 -0
- package/lib/customtypes/diff/Widgets.js +2 -0
- package/package.json +3 -3
- package/src/customtypes/diff/Variation.ts +64 -6
- package/src/customtypes/diff/Widgets.ts +23 -0
- package/lib/content/fields/nestable/RichTextContent/TextBlock.d.ts +0 -727
- package/lib/content/fields/nestable/RichTextContent/TextBlock.js +0 -80
- package/lib/customtypes/widgets/slices/SliceWidget.d.ts +0 -327
- package/lib/customtypes/widgets/slices/SliceWidget.js +0 -8
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type { NestableWidget } from "../widgets/nestable";
|
|
2
|
-
import type { SlicePrimaryWidget } from "../widgets/slices";
|
|
3
1
|
import type { Variation } from "../widgets/slices";
|
|
4
2
|
import { type DiffChange } from "./Changes";
|
|
3
|
+
import type { NestableWidgetDiff, SlicePrimaryWidgetDiff } from "./Widgets";
|
|
5
4
|
export declare type VariationMetadata = Omit<Variation, "primary" | "items">;
|
|
6
5
|
export declare type VariationDiff = DiffChange<Variation, Partial<VariationMetadata> & {
|
|
7
|
-
primary?: Record<string,
|
|
8
|
-
items?: Record<string,
|
|
6
|
+
primary?: Record<string, SlicePrimaryWidgetDiff>;
|
|
7
|
+
items?: Record<string, NestableWidgetDiff>;
|
|
9
8
|
}>;
|
|
10
9
|
export declare const VariationComparator: {
|
|
11
10
|
compare(variationA?: ({
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VariationComparator = void 0;
|
|
4
4
|
const utils_1 = require("../../utils");
|
|
5
|
+
const Group_1 = require("../widgets/Group");
|
|
5
6
|
const Changes_1 = require("./Changes");
|
|
6
7
|
function compareVariationMeta(variationA, variationB) {
|
|
7
8
|
const zippedVariations = utils_1.Objects.zipObjects(variationA, variationB);
|
|
@@ -19,17 +20,54 @@ function compareWidgets(widgetsA, widgetsB) {
|
|
|
19
20
|
if (JSON.stringify(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) === JSON.stringify(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.right))
|
|
20
21
|
return acc;
|
|
21
22
|
const changes = (() => {
|
|
23
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
22
24
|
if (!(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) && !(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.right))
|
|
23
25
|
return;
|
|
24
|
-
if ((widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) && !widgetValue.right)
|
|
26
|
+
if ((widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) && !widgetValue.right) {
|
|
25
27
|
return {
|
|
26
28
|
op: Changes_1.DiffOperation.Removed,
|
|
27
29
|
};
|
|
28
|
-
|
|
30
|
+
}
|
|
31
|
+
if (!(widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.left) && (widgetValue === null || widgetValue === void 0 ? void 0 : widgetValue.right)) {
|
|
32
|
+
if (((_a = widgetValue.right) === null || _a === void 0 ? void 0 : _a.type) === Group_1.GroupFieldType) {
|
|
33
|
+
const group = {
|
|
34
|
+
...widgetValue.right,
|
|
35
|
+
config: {
|
|
36
|
+
...widgetValue.right.config,
|
|
37
|
+
fields: {},
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
// On added groups, this basically marks all fields in the group as added
|
|
41
|
+
group.config.fields =
|
|
42
|
+
compareWidgets(undefined, (_b = widgetValue.right.config) === null || _b === void 0 ? void 0 : _b.fields) || {};
|
|
43
|
+
return {
|
|
44
|
+
op: Changes_1.DiffOperation.Added,
|
|
45
|
+
value: group,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
29
48
|
return {
|
|
30
49
|
op: Changes_1.DiffOperation.Added,
|
|
31
50
|
value: widgetValue.right,
|
|
32
51
|
};
|
|
52
|
+
}
|
|
53
|
+
if (((_c = widgetValue.right) === null || _c === void 0 ? void 0 : _c.type) === Group_1.GroupFieldType) {
|
|
54
|
+
const group = {
|
|
55
|
+
...widgetValue.right,
|
|
56
|
+
config: {
|
|
57
|
+
...widgetValue.right.config,
|
|
58
|
+
fields: {},
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
// On updated groups, this also compares the fields inside the group
|
|
62
|
+
group.config.fields =
|
|
63
|
+
compareWidgets(((_d = widgetValue.left) === null || _d === void 0 ? void 0 : _d.type) === Group_1.GroupFieldType
|
|
64
|
+
? (_f = (_e = widgetValue.left) === null || _e === void 0 ? void 0 : _e.config) === null || _f === void 0 ? void 0 : _f.fields
|
|
65
|
+
: undefined, (_g = widgetValue.right.config) === null || _g === void 0 ? void 0 : _g.fields) || {};
|
|
66
|
+
return {
|
|
67
|
+
op: Changes_1.DiffOperation.Updated,
|
|
68
|
+
value: group,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
33
71
|
return {
|
|
34
72
|
op: Changes_1.DiffOperation.Updated,
|
|
35
73
|
value: widgetValue.right,
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Group } from "../widgets";
|
|
2
|
+
import type { NestableWidget } from "../widgets/nestable";
|
|
3
|
+
import type { DiffChange } from "./Changes";
|
|
4
|
+
export declare type NestableWidgetDiff = DiffChange<NestableWidget, NestableWidget>;
|
|
5
|
+
export declare type GroupWidgetWithFieldsDiff = Omit<Group, "config"> & {
|
|
6
|
+
config: Omit<Group["config"], "fields"> & {
|
|
7
|
+
fields?: Record<string, NestableWidgetDiff>;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export declare type GroupWidgetDiff = DiffChange<GroupWidgetWithFieldsDiff, GroupWidgetWithFieldsDiff>;
|
|
11
|
+
export declare type SlicePrimaryWidgetDiff = NestableWidgetDiff | GroupWidgetDiff;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prismicio/types-internal",
|
|
3
|
-
"version": "2.4.0",
|
|
3
|
+
"version": "2.4.1-alpha.0",
|
|
4
4
|
"description": "Prismic types for Custom Types and Prismic Data",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"prepare": "npm run build",
|
|
26
26
|
"release": "npm run test && standard-version && git push --follow-tags && npm run build && npm publish",
|
|
27
27
|
"release:dry": "standard-version --dry-run",
|
|
28
|
-
"release:alpha": "npm run test && standard-version --prerelease alpha && git push --follow-tags && npm run build && npm publish --tag alpha",
|
|
29
|
-
"release:alpha:dry": "standard-version --prerelease alpha --dry-run",
|
|
28
|
+
"release:alpha": "npm run test && standard-version --prerelease alpha --release-as patch && git push --follow-tags && npm run build && npm publish --tag alpha",
|
|
29
|
+
"release:alpha:dry": "standard-version --prerelease alpha --release-as patch --dry-run",
|
|
30
30
|
"test": "jest --no-cache --silent=false --verbose=false --coverage",
|
|
31
31
|
"test:clear": "jest --clearCache",
|
|
32
32
|
"eslint": "eslint . --cache --cache-location .caches/eslint --cache-strategy content --ext js,ts,tsx --max-warnings 0",
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { Objects } from "../../utils"
|
|
2
|
+
import { GroupFieldType } from "../widgets/Group"
|
|
2
3
|
import type { NestableWidget } from "../widgets/nestable"
|
|
3
4
|
import type { SlicePrimaryWidget } from "../widgets/slices"
|
|
4
5
|
import type { Variation } from "../widgets/slices"
|
|
5
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
type DiffChange,
|
|
8
|
+
DiffOperation
|
|
9
|
+
} from "./Changes"
|
|
10
|
+
import type { GroupWidgetWithFieldsDiff,NestableWidgetDiff, SlicePrimaryWidgetDiff } from "./Widgets"
|
|
6
11
|
|
|
7
12
|
export type VariationMetadata = Omit<Variation, "primary" | "items">
|
|
8
13
|
export type VariationDiff = DiffChange<
|
|
9
14
|
Variation,
|
|
10
15
|
Partial<VariationMetadata> & {
|
|
11
|
-
primary?: Record<string,
|
|
12
|
-
items?: Record<string,
|
|
16
|
+
primary?: Record<string, SlicePrimaryWidgetDiff>
|
|
17
|
+
items?: Record<string, NestableWidgetDiff>
|
|
13
18
|
}
|
|
14
19
|
>
|
|
15
20
|
|
|
@@ -30,7 +35,14 @@ function compareVariationMeta(
|
|
|
30
35
|
function compareWidgets<TWidget extends NestableWidget | SlicePrimaryWidget>(
|
|
31
36
|
widgetsA?: { [key: string]: TWidget },
|
|
32
37
|
widgetsB?: { [key: string]: TWidget },
|
|
33
|
-
):
|
|
38
|
+
):
|
|
39
|
+
| Record<
|
|
40
|
+
string,
|
|
41
|
+
SlicePrimaryWidget extends TWidget
|
|
42
|
+
? SlicePrimaryWidgetDiff
|
|
43
|
+
: NestableWidgetDiff
|
|
44
|
+
>
|
|
45
|
+
| undefined {
|
|
34
46
|
const zippedWidgets = Objects.zipObjects(widgetsA, widgetsB)
|
|
35
47
|
|
|
36
48
|
const diffWidgets = Object.entries(zippedWidgets).reduce(
|
|
@@ -42,15 +54,61 @@ function compareWidgets<TWidget extends NestableWidget | SlicePrimaryWidget>(
|
|
|
42
54
|
|
|
43
55
|
const changes = (() => {
|
|
44
56
|
if (!widgetValue?.left && !widgetValue?.right) return
|
|
45
|
-
|
|
57
|
+
|
|
58
|
+
if (widgetValue?.left && !widgetValue.right) {
|
|
46
59
|
return {
|
|
47
60
|
op: DiffOperation.Removed,
|
|
48
61
|
}
|
|
49
|
-
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!widgetValue?.left && widgetValue?.right) {
|
|
65
|
+
if (widgetValue.right?.type === GroupFieldType) {
|
|
66
|
+
const group: GroupWidgetWithFieldsDiff = {
|
|
67
|
+
...widgetValue.right,
|
|
68
|
+
config: {
|
|
69
|
+
...widgetValue.right.config,
|
|
70
|
+
fields: {},
|
|
71
|
+
},
|
|
72
|
+
}
|
|
73
|
+
// On added groups, this basically marks all fields in the group as added
|
|
74
|
+
group.config.fields =
|
|
75
|
+
compareWidgets(undefined, widgetValue.right.config?.fields) || {}
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
op: DiffOperation.Added,
|
|
79
|
+
value: group,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
50
83
|
return {
|
|
51
84
|
op: DiffOperation.Added,
|
|
52
85
|
value: widgetValue.right,
|
|
53
86
|
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (widgetValue.right?.type === GroupFieldType) {
|
|
90
|
+
const group: GroupWidgetWithFieldsDiff = {
|
|
91
|
+
...widgetValue.right,
|
|
92
|
+
config: {
|
|
93
|
+
...widgetValue.right.config,
|
|
94
|
+
fields: {},
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
// On updated groups, this also compares the fields inside the group
|
|
98
|
+
group.config.fields =
|
|
99
|
+
compareWidgets(
|
|
100
|
+
widgetValue.left?.type === GroupFieldType
|
|
101
|
+
? widgetValue.left?.config?.fields
|
|
102
|
+
: undefined,
|
|
103
|
+
widgetValue.right.config?.fields,
|
|
104
|
+
) || {}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
op: DiffOperation.Updated,
|
|
108
|
+
value: group,
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
54
112
|
return {
|
|
55
113
|
op: DiffOperation.Updated,
|
|
56
114
|
value: widgetValue.right,
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Group } from "../widgets"
|
|
2
|
+
import type { NestableWidget } from "../widgets/nestable"
|
|
3
|
+
import type { DiffChange } from "./Changes"
|
|
4
|
+
|
|
5
|
+
export type NestableWidgetDiff = DiffChange<NestableWidget, NestableWidget>
|
|
6
|
+
|
|
7
|
+
export type GroupWidgetWithFieldsDiff = Omit<Group, "config"> & {
|
|
8
|
+
config: Omit<Group["config"], "fields"> & {
|
|
9
|
+
// This line may need to be updated if we support groups within
|
|
10
|
+
// groups in the future. The diff code is already recursive and
|
|
11
|
+
// should not need updates; inputs are restricted by types, not
|
|
12
|
+
// by code.
|
|
13
|
+
//
|
|
14
|
+
// Ensure tests are updated accordingly.
|
|
15
|
+
fields?: Record<string, NestableWidgetDiff>
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export type GroupWidgetDiff = DiffChange<
|
|
19
|
+
GroupWidgetWithFieldsDiff,
|
|
20
|
+
GroupWidgetWithFieldsDiff
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
export type SlicePrimaryWidgetDiff = NestableWidgetDiff | GroupWidgetDiff
|