@capacms/sdk 1.0.0-next.1 → 1.0.0-next.10
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/CHANGELOG.md +450 -0
- package/README.md +1698 -193
- package/bin/capa-codegen.js +192 -5
- package/bin/capa.js +235 -0
- package/bin/graphql-project.js +142 -0
- package/bin/project-env.js +58 -0
- package/dist/client.d.ts +5 -0
- package/dist/client.js +17 -0
- package/dist/codegen.d.ts +55 -0
- package/dist/codegen.js +320 -39
- package/dist/config.d.ts +5 -36
- package/dist/config.js +47 -1
- package/dist/esm/image/index.d.ts +120 -0
- package/dist/esm/image/index.js +250 -0
- package/dist/esm/image/shared-params.generated.d.ts +190 -0
- package/dist/esm/image/shared-params.generated.js +461 -0
- package/dist/esm/nextjs/image-loader.d.ts +60 -0
- package/dist/esm/nextjs/image-loader.js +67 -0
- package/dist/esm/nextjs/overlay.d.ts +30 -0
- package/dist/esm/nextjs/overlay.js +75 -0
- package/dist/esm/overlay/index.d.ts +32 -0
- package/dist/esm/overlay/index.js +576 -0
- package/dist/esm/overlay/protocol.d.ts +187 -0
- package/dist/esm/overlay/protocol.js +240 -0
- package/dist/esm/package.json +4 -0
- package/dist/graphql-codegen.d.ts +117 -0
- package/dist/graphql-codegen.js +705 -0
- package/dist/http.js +1 -1
- package/dist/image/index.d.ts +120 -0
- package/dist/image/index.js +257 -0
- package/dist/image/shared-params.generated.d.ts +190 -0
- package/dist/image/shared-params.generated.js +471 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/next/attrs.d.ts +84 -10
- package/dist/next/attrs.js +119 -2
- package/dist/next/client.d.ts +176 -32
- package/dist/next/client.js +212 -90
- package/dist/next/entry-fields.d.ts +162 -0
- package/dist/next/entry-fields.js +2 -0
- package/dist/next/errors.d.ts +136 -0
- package/dist/next/errors.js +214 -0
- package/dist/next/field-names.d.ts +37 -0
- package/dist/next/field-names.js +145 -0
- package/dist/next/graphql/build.d.ts +27 -0
- package/dist/next/graphql/build.js +98 -0
- package/dist/next/graphql/documents.d.ts +67 -0
- package/dist/next/graphql/documents.js +35 -0
- package/dist/next/graphql/edit-mode.d.ts +16 -0
- package/dist/next/graphql/edit-mode.js +93 -0
- package/dist/next/graphql/filter-values.d.ts +34 -0
- package/dist/next/graphql/filter-values.js +96 -0
- package/dist/next/graphql/introspection.d.ts +89 -0
- package/dist/next/graphql/introspection.js +102 -0
- package/dist/next/graphql/plan.d.ts +115 -0
- package/dist/next/graphql/plan.js +531 -0
- package/dist/next/graphql/request.d.ts +228 -0
- package/dist/next/graphql/request.js +283 -0
- package/dist/next/graphql/rest.d.ts +66 -0
- package/dist/next/graphql/rest.js +502 -0
- package/dist/next/graphql/selection.d.ts +55 -0
- package/dist/next/graphql/selection.js +212 -0
- package/dist/next/graphql/sha256.d.ts +13 -0
- package/dist/next/graphql/sha256.js +86 -0
- package/dist/next/graphql/summary.d.ts +83 -0
- package/dist/next/graphql/summary.js +151 -0
- package/dist/next/graphql/tree-layout.d.ts +36 -0
- package/dist/next/graphql/tree-layout.js +20 -0
- package/dist/next/graphql/tree.d.ts +171 -0
- package/dist/next/graphql/tree.js +249 -0
- package/dist/next/graphql/typed.d.ts +261 -0
- package/dist/next/graphql/typed.js +146 -0
- package/dist/next/index.d.ts +30 -5
- package/dist/next/index.js +32 -1
- package/dist/next/inflate.d.ts +51 -0
- package/dist/next/inflate.js +243 -0
- package/dist/next/key-family.d.ts +31 -0
- package/dist/next/key-family.js +66 -0
- package/dist/next/select-types.d.ts +58 -5
- package/dist/next/system-keys.d.ts +27 -0
- package/dist/next/system-keys.js +42 -0
- package/dist/nextjs/image-loader.d.ts +60 -0
- package/dist/nextjs/image-loader.js +71 -0
- package/dist/nextjs/index.d.ts +484 -5
- package/dist/nextjs/index.js +688 -6
- package/dist/nextjs/overlay.d.ts +30 -0
- package/dist/nextjs/overlay.js +78 -0
- package/dist/overlay/index.d.ts +14 -2
- package/dist/overlay/index.js +282 -43
- package/dist/overlay/protocol.d.ts +98 -2
- package/dist/overlay/protocol.js +151 -4
- package/package.json +63 -15
|
@@ -10,11 +10,30 @@
|
|
|
10
10
|
* highlight { entryId, field: string | null } entryId "" clears
|
|
11
11
|
* outline { on: boolean } outline every tagged element
|
|
12
12
|
* refresh {} re-render the draft
|
|
13
|
+
* patch { entryId, fields: [{ field, value, saved }] }
|
|
14
|
+
* unsaved text, as the editor types it
|
|
13
15
|
*
|
|
14
16
|
* site -> admin (source "capa")
|
|
15
|
-
* ready { path, entries }
|
|
17
|
+
* ready { path, entries, features } after hello, and after every navigation.
|
|
18
|
+
* `features`: what this overlay can do
|
|
19
|
+
* beyond v1 (`SITE_FEATURES`)
|
|
16
20
|
* select { entryId, field } a tagged element was clicked
|
|
17
21
|
* hover { entryId, field } | { entryId: "", field: null }
|
|
22
|
+
* visible { entryId, field } the tagged element at the centre of the
|
|
23
|
+
* viewport changed (throttled, on scroll)
|
|
24
|
+
*
|
|
25
|
+
* `visible` arrived in 1.0.0-next.2 and is OPTIONAL: it is still `v: 1`,
|
|
26
|
+
* because an admin that does not know it drops an unknown type, and an older
|
|
27
|
+
* overlay simply never sends it. Additive messages keep the version; only a
|
|
28
|
+
* change to an existing shape would move it. `patch` and `features` are the
|
|
29
|
+
* same kind of addition: an admin sends `patch` only to an overlay whose
|
|
30
|
+
* `ready` lists "patch", and an older admin never reads `features`.
|
|
31
|
+
*
|
|
32
|
+
* A PATCH IS TEXT ONLY, and only where the page shows the field verbatim. The
|
|
33
|
+
* overlay changes a tagged element's text while it reads exactly `saved` (the
|
|
34
|
+
* value the page was rendered from) or what this page last patched it to, so
|
|
35
|
+
* a field the site formats (a price, a date, Markdown) is left alone until the
|
|
36
|
+
* save re-renders it (`patchedText`).
|
|
18
37
|
*
|
|
19
38
|
* The admin keeps its own copy of these shapes (`apps/admin`, no dependency on
|
|
20
39
|
* this package). If you change one side, change the other.
|
|
@@ -22,6 +41,17 @@
|
|
|
22
41
|
export declare const PROTOCOL_VERSION = 1;
|
|
23
42
|
export declare const ADMIN_SOURCE = "capa-admin";
|
|
24
43
|
export declare const SITE_SOURCE = "capa";
|
|
44
|
+
/** What this overlay can do beyond v1, listed in its `ready`. */
|
|
45
|
+
export declare const SITE_FEATURES: readonly string[];
|
|
46
|
+
/** One field of a `patch`: the text being typed, and the saved value the page was rendered from. */
|
|
47
|
+
export interface PatchField {
|
|
48
|
+
field: string;
|
|
49
|
+
value: string;
|
|
50
|
+
saved: string;
|
|
51
|
+
}
|
|
52
|
+
/** A `patch` past these is refused whole: no form has that many text fields, or that much text in one. */
|
|
53
|
+
export declare const PATCH_MAX_FIELDS = 500;
|
|
54
|
+
export declare const PATCH_MAX_LENGTH = 100000;
|
|
25
55
|
export type AdminMessage = {
|
|
26
56
|
source: typeof ADMIN_SOURCE;
|
|
27
57
|
v: 1;
|
|
@@ -41,6 +71,12 @@ export type AdminMessage = {
|
|
|
41
71
|
source: typeof ADMIN_SOURCE;
|
|
42
72
|
v: 1;
|
|
43
73
|
type: "refresh";
|
|
74
|
+
} | {
|
|
75
|
+
source: typeof ADMIN_SOURCE;
|
|
76
|
+
v: 1;
|
|
77
|
+
type: "patch";
|
|
78
|
+
entryId: string;
|
|
79
|
+
fields: PatchField[];
|
|
44
80
|
};
|
|
45
81
|
export type SiteMessage = {
|
|
46
82
|
source: typeof SITE_SOURCE;
|
|
@@ -48,6 +84,7 @@ export type SiteMessage = {
|
|
|
48
84
|
type: "ready";
|
|
49
85
|
path: string;
|
|
50
86
|
entries: string[];
|
|
87
|
+
features?: string[];
|
|
51
88
|
} | {
|
|
52
89
|
source: typeof SITE_SOURCE;
|
|
53
90
|
v: 1;
|
|
@@ -60,6 +97,12 @@ export type SiteMessage = {
|
|
|
60
97
|
type: "hover";
|
|
61
98
|
entryId: string;
|
|
62
99
|
field: string | null;
|
|
100
|
+
} | {
|
|
101
|
+
source: typeof SITE_SOURCE;
|
|
102
|
+
v: 1;
|
|
103
|
+
type: "visible";
|
|
104
|
+
entryId: string;
|
|
105
|
+
field: string;
|
|
63
106
|
};
|
|
64
107
|
/** The parts of a `MessageEvent` the filter reads, so a test can hand in a literal. */
|
|
65
108
|
export interface MessageLike {
|
|
@@ -86,6 +129,59 @@ export declare function normaliseOrigins(origins: readonly string[]): string[];
|
|
|
86
129
|
* `allowedOrigins` is expected already normalised (`normaliseOrigins`).
|
|
87
130
|
*/
|
|
88
131
|
export declare function acceptMessage(event: MessageLike, allowedOrigins: readonly string[], parent: unknown): AdminMessage | null;
|
|
89
|
-
|
|
132
|
+
/**
|
|
133
|
+
* The text a node should read after a patch, or null to leave it alone.
|
|
134
|
+
*
|
|
135
|
+
* Only while its text (trimmed) is the saved value or what this page last
|
|
136
|
+
* patched it to, so text the site formats is never touched. The whitespace a
|
|
137
|
+
* template put around it stays. Null too when there is nothing to change.
|
|
138
|
+
*/
|
|
139
|
+
export declare function patchedText(current: string, change: {
|
|
140
|
+
value: string;
|
|
141
|
+
saved: string;
|
|
142
|
+
}, lastPatched: string | null, around?: {
|
|
143
|
+
lead: string;
|
|
144
|
+
trail: string;
|
|
145
|
+
}): string | null;
|
|
146
|
+
/**
|
|
147
|
+
* The whitespace around a node's text, which a patch keeps. A node that is
|
|
148
|
+
* only whitespace keeps it in front. The overlay remembers this from the
|
|
149
|
+
* first patch, so text typed away to nothing and back lands where it was.
|
|
150
|
+
*/
|
|
151
|
+
export declare function textAround(current: string): {
|
|
152
|
+
lead: string;
|
|
153
|
+
trail: string;
|
|
154
|
+
};
|
|
155
|
+
export declare function readyMessage(path: string, entries: string[], features?: readonly string[]): SiteMessage;
|
|
90
156
|
export declare function selectMessage(entryId: string, field: string): SiteMessage;
|
|
91
157
|
export declare function hoverMessage(entryId: string, field: string | null): SiteMessage;
|
|
158
|
+
export declare function visibleMessage(entryId: string, field: string): SiteMessage;
|
|
159
|
+
/** The part of a tagged element `pickCentred` reads, so a test can hand in literals. */
|
|
160
|
+
export interface TaggedBox {
|
|
161
|
+
entryId: string;
|
|
162
|
+
field: string;
|
|
163
|
+
/** `getBoundingClientRect()`, viewport coordinates. */
|
|
164
|
+
top: number;
|
|
165
|
+
bottom: number;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The tagged element a reader is looking at: the one that contains the
|
|
169
|
+
* viewport's horizontal centre line, and when several do (a field inside a
|
|
170
|
+
* card that is also tagged) the SMALLEST, because the innermost element is
|
|
171
|
+
* the specific one. When none crosses the line, the nearest one that is at
|
|
172
|
+
* least partly on screen. Null when nothing tagged is on screen at all.
|
|
173
|
+
*
|
|
174
|
+
* `edge` is where the page is scrolled to. A heading near the top of a page
|
|
175
|
+
* can never reach the centre line, because the page cannot scroll above its
|
|
176
|
+
* top; at the top the topmost visible element is the one being read, and at
|
|
177
|
+
* the bottom the bottommost. The same rule a table of contents' scroll spy
|
|
178
|
+
* uses.
|
|
179
|
+
*
|
|
180
|
+
* Pure, so the admin's "follow the page" can be tested without a DOM.
|
|
181
|
+
*/
|
|
182
|
+
export declare function pickCentred(boxes: readonly TaggedBox[], viewportHeight: number, edge?: "top" | "bottom" | null): TaggedBox | null;
|
|
183
|
+
/**
|
|
184
|
+
* Which edge a scroll position is at, for `pickCentred`. A page that does not
|
|
185
|
+
* scroll at all is at neither: nothing moves, and the centre rule stands.
|
|
186
|
+
*/
|
|
187
|
+
export declare function scrollEdge(scrollY: number, viewportHeight: number, scrollHeight: number): "top" | "bottom" | null;
|
package/dist/overlay/protocol.js
CHANGED
|
@@ -11,25 +11,54 @@
|
|
|
11
11
|
* highlight { entryId, field: string | null } entryId "" clears
|
|
12
12
|
* outline { on: boolean } outline every tagged element
|
|
13
13
|
* refresh {} re-render the draft
|
|
14
|
+
* patch { entryId, fields: [{ field, value, saved }] }
|
|
15
|
+
* unsaved text, as the editor types it
|
|
14
16
|
*
|
|
15
17
|
* site -> admin (source "capa")
|
|
16
|
-
* ready { path, entries }
|
|
18
|
+
* ready { path, entries, features } after hello, and after every navigation.
|
|
19
|
+
* `features`: what this overlay can do
|
|
20
|
+
* beyond v1 (`SITE_FEATURES`)
|
|
17
21
|
* select { entryId, field } a tagged element was clicked
|
|
18
22
|
* hover { entryId, field } | { entryId: "", field: null }
|
|
23
|
+
* visible { entryId, field } the tagged element at the centre of the
|
|
24
|
+
* viewport changed (throttled, on scroll)
|
|
25
|
+
*
|
|
26
|
+
* `visible` arrived in 1.0.0-next.2 and is OPTIONAL: it is still `v: 1`,
|
|
27
|
+
* because an admin that does not know it drops an unknown type, and an older
|
|
28
|
+
* overlay simply never sends it. Additive messages keep the version; only a
|
|
29
|
+
* change to an existing shape would move it. `patch` and `features` are the
|
|
30
|
+
* same kind of addition: an admin sends `patch` only to an overlay whose
|
|
31
|
+
* `ready` lists "patch", and an older admin never reads `features`.
|
|
32
|
+
*
|
|
33
|
+
* A PATCH IS TEXT ONLY, and only where the page shows the field verbatim. The
|
|
34
|
+
* overlay changes a tagged element's text while it reads exactly `saved` (the
|
|
35
|
+
* value the page was rendered from) or what this page last patched it to, so
|
|
36
|
+
* a field the site formats (a price, a date, Markdown) is left alone until the
|
|
37
|
+
* save re-renders it (`patchedText`).
|
|
19
38
|
*
|
|
20
39
|
* The admin keeps its own copy of these shapes (`apps/admin`, no dependency on
|
|
21
40
|
* this package). If you change one side, change the other.
|
|
22
41
|
*/
|
|
23
42
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.SITE_SOURCE = exports.ADMIN_SOURCE = exports.PROTOCOL_VERSION = void 0;
|
|
43
|
+
exports.PATCH_MAX_LENGTH = exports.PATCH_MAX_FIELDS = exports.SITE_FEATURES = exports.SITE_SOURCE = exports.ADMIN_SOURCE = exports.PROTOCOL_VERSION = void 0;
|
|
25
44
|
exports.normaliseOrigins = normaliseOrigins;
|
|
26
45
|
exports.acceptMessage = acceptMessage;
|
|
46
|
+
exports.patchedText = patchedText;
|
|
47
|
+
exports.textAround = textAround;
|
|
27
48
|
exports.readyMessage = readyMessage;
|
|
28
49
|
exports.selectMessage = selectMessage;
|
|
29
50
|
exports.hoverMessage = hoverMessage;
|
|
51
|
+
exports.visibleMessage = visibleMessage;
|
|
52
|
+
exports.pickCentred = pickCentred;
|
|
53
|
+
exports.scrollEdge = scrollEdge;
|
|
30
54
|
exports.PROTOCOL_VERSION = 1;
|
|
31
55
|
exports.ADMIN_SOURCE = "capa-admin";
|
|
32
56
|
exports.SITE_SOURCE = "capa";
|
|
57
|
+
/** What this overlay can do beyond v1, listed in its `ready`. */
|
|
58
|
+
exports.SITE_FEATURES = ["patch"];
|
|
59
|
+
/** A `patch` past these is refused whole: no form has that many text fields, or that much text in one. */
|
|
60
|
+
exports.PATCH_MAX_FIELDS = 500;
|
|
61
|
+
exports.PATCH_MAX_LENGTH = 100_000;
|
|
33
62
|
/**
|
|
34
63
|
* `https://admin.example.com/` and `https://admin.example.com` are one origin,
|
|
35
64
|
* and a configured value that is not a URL at all is dropped rather than
|
|
@@ -89,12 +118,62 @@ function acceptMessage(event, allowedOrigins, parent) {
|
|
|
89
118
|
if (m.field !== null && typeof m.field !== "string")
|
|
90
119
|
return null;
|
|
91
120
|
return { source: exports.ADMIN_SOURCE, v: 1, type: "highlight", entryId: m.entryId, field: m.field };
|
|
121
|
+
case "patch": {
|
|
122
|
+
if (typeof m.entryId !== "string" || m.entryId === "")
|
|
123
|
+
return null;
|
|
124
|
+
if (!Array.isArray(m.fields) || m.fields.length > exports.PATCH_MAX_FIELDS)
|
|
125
|
+
return null;
|
|
126
|
+
const fields = [];
|
|
127
|
+
for (const raw of m.fields) {
|
|
128
|
+
if (typeof raw !== "object" || raw === null)
|
|
129
|
+
return null;
|
|
130
|
+
const f = raw;
|
|
131
|
+
if (typeof f.field !== "string" || f.field === "")
|
|
132
|
+
return null;
|
|
133
|
+
if (typeof f.value !== "string" || typeof f.saved !== "string")
|
|
134
|
+
return null;
|
|
135
|
+
if (f.value.length > exports.PATCH_MAX_LENGTH || f.saved.length > exports.PATCH_MAX_LENGTH)
|
|
136
|
+
return null;
|
|
137
|
+
fields.push({ field: f.field, value: f.value, saved: f.saved });
|
|
138
|
+
}
|
|
139
|
+
return { source: exports.ADMIN_SOURCE, v: 1, type: "patch", entryId: m.entryId, fields };
|
|
140
|
+
}
|
|
92
141
|
default:
|
|
93
142
|
return null;
|
|
94
143
|
}
|
|
95
144
|
}
|
|
96
|
-
|
|
97
|
-
|
|
145
|
+
/**
|
|
146
|
+
* The text a node should read after a patch, or null to leave it alone.
|
|
147
|
+
*
|
|
148
|
+
* Only while its text (trimmed) is the saved value or what this page last
|
|
149
|
+
* patched it to, so text the site formats is never touched. The whitespace a
|
|
150
|
+
* template put around it stays. Null too when there is nothing to change.
|
|
151
|
+
*/
|
|
152
|
+
function patchedText(current, change, lastPatched, around = textAround(current)) {
|
|
153
|
+
const text = current.trim();
|
|
154
|
+
const ours = text === change.saved.trim() || (lastPatched !== null && text === lastPatched.trim());
|
|
155
|
+
if (!ours || text === change.value.trim())
|
|
156
|
+
return null;
|
|
157
|
+
return `${around.lead}${change.value}${around.trail}`;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* The whitespace around a node's text, which a patch keeps. A node that is
|
|
161
|
+
* only whitespace keeps it in front. The overlay remembers this from the
|
|
162
|
+
* first patch, so text typed away to nothing and back lands where it was.
|
|
163
|
+
*/
|
|
164
|
+
function textAround(current) {
|
|
165
|
+
const text = current.trim();
|
|
166
|
+
if (text === "")
|
|
167
|
+
return { lead: current, trail: "" };
|
|
168
|
+
return {
|
|
169
|
+
lead: current.slice(0, current.length - current.trimStart().length),
|
|
170
|
+
trail: current.slice(current.trimEnd().length),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function readyMessage(path, entries, features) {
|
|
174
|
+
return features
|
|
175
|
+
? { source: exports.SITE_SOURCE, v: 1, type: "ready", path, entries, features: [...features] }
|
|
176
|
+
: { source: exports.SITE_SOURCE, v: 1, type: "ready", path, entries };
|
|
98
177
|
}
|
|
99
178
|
function selectMessage(entryId, field) {
|
|
100
179
|
return { source: exports.SITE_SOURCE, v: 1, type: "select", entryId, field };
|
|
@@ -104,3 +183,71 @@ function hoverMessage(entryId, field) {
|
|
|
104
183
|
? { source: exports.SITE_SOURCE, v: 1, type: "hover", entryId: "", field: null }
|
|
105
184
|
: { source: exports.SITE_SOURCE, v: 1, type: "hover", entryId, field };
|
|
106
185
|
}
|
|
186
|
+
function visibleMessage(entryId, field) {
|
|
187
|
+
return { source: exports.SITE_SOURCE, v: 1, type: "visible", entryId, field };
|
|
188
|
+
}
|
|
189
|
+
/** Above any element height, so a box that misses the centre line never outranks one that crosses it. */
|
|
190
|
+
const MISS_FLOOR = 1e9;
|
|
191
|
+
/**
|
|
192
|
+
* The tagged element a reader is looking at: the one that contains the
|
|
193
|
+
* viewport's horizontal centre line, and when several do (a field inside a
|
|
194
|
+
* card that is also tagged) the SMALLEST, because the innermost element is
|
|
195
|
+
* the specific one. When none crosses the line, the nearest one that is at
|
|
196
|
+
* least partly on screen. Null when nothing tagged is on screen at all.
|
|
197
|
+
*
|
|
198
|
+
* `edge` is where the page is scrolled to. A heading near the top of a page
|
|
199
|
+
* can never reach the centre line, because the page cannot scroll above its
|
|
200
|
+
* top; at the top the topmost visible element is the one being read, and at
|
|
201
|
+
* the bottom the bottommost. The same rule a table of contents' scroll spy
|
|
202
|
+
* uses.
|
|
203
|
+
*
|
|
204
|
+
* Pure, so the admin's "follow the page" can be tested without a DOM.
|
|
205
|
+
*/
|
|
206
|
+
function pickCentred(boxes, viewportHeight, edge = null) {
|
|
207
|
+
const centre = viewportHeight / 2;
|
|
208
|
+
let best = null;
|
|
209
|
+
let bestScore = Infinity;
|
|
210
|
+
for (const b of boxes) {
|
|
211
|
+
if (!b.entryId || !b.field)
|
|
212
|
+
continue;
|
|
213
|
+
if (b.bottom <= 0 || b.top >= viewportHeight || b.bottom <= b.top)
|
|
214
|
+
continue;
|
|
215
|
+
const height = b.bottom - b.top;
|
|
216
|
+
let score;
|
|
217
|
+
if (edge === "top") {
|
|
218
|
+
// Topmost first; of two that start together, the smaller (inner) one.
|
|
219
|
+
score = b.top * MISS_FLOOR + height;
|
|
220
|
+
}
|
|
221
|
+
else if (edge === "bottom") {
|
|
222
|
+
score = (viewportHeight - b.bottom) * MISS_FLOOR + height;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
// Crossing the line scores by height (smaller wins) and always beats a
|
|
226
|
+
// box that misses it, which scores by its distance from the line on top
|
|
227
|
+
// of a floor no height can reach.
|
|
228
|
+
score =
|
|
229
|
+
b.top <= centre && b.bottom >= centre
|
|
230
|
+
? height
|
|
231
|
+
: MISS_FLOOR + Math.min(Math.abs(b.top - centre), Math.abs(b.bottom - centre));
|
|
232
|
+
}
|
|
233
|
+
if (score < bestScore) {
|
|
234
|
+
best = b;
|
|
235
|
+
bestScore = score;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return best;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Which edge a scroll position is at, for `pickCentred`. A page that does not
|
|
242
|
+
* scroll at all is at neither: nothing moves, and the centre rule stands.
|
|
243
|
+
*/
|
|
244
|
+
function scrollEdge(scrollY, viewportHeight, scrollHeight) {
|
|
245
|
+
const max = scrollHeight - viewportHeight;
|
|
246
|
+
if (max <= 1)
|
|
247
|
+
return null;
|
|
248
|
+
if (scrollY <= 1)
|
|
249
|
+
return "top";
|
|
250
|
+
if (scrollY >= max - 1)
|
|
251
|
+
return "bottom";
|
|
252
|
+
return null;
|
|
253
|
+
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capacms/sdk",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.10",
|
|
4
|
+
"description": "The TypeScript SDK for Capa's content API: REST and GraphQL reads typed from your models, Next.js caching and live preview, and codegen.",
|
|
4
5
|
"license": "UNLICENSED",
|
|
5
|
-
"
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/ZVN-DEV/capa-cms-future.git",
|
|
8
|
-
"directory": "packages/sdk"
|
|
9
|
-
},
|
|
10
|
-
"homepage": "https://github.com/ZVN-DEV/capa-cms-future/tree/main/packages/sdk#readme",
|
|
11
|
-
"bugs": {
|
|
12
|
-
"url": "https://github.com/ZVN-DEV/capa-cms-future/issues"
|
|
13
|
-
},
|
|
6
|
+
"homepage": "https://docs.capacms.com/api",
|
|
14
7
|
"engines": {
|
|
15
8
|
"node": ">=18"
|
|
16
9
|
},
|
|
@@ -18,7 +11,8 @@
|
|
|
18
11
|
"files": [
|
|
19
12
|
"dist",
|
|
20
13
|
"bin",
|
|
21
|
-
"README.md"
|
|
14
|
+
"README.md",
|
|
15
|
+
"CHANGELOG.md"
|
|
22
16
|
],
|
|
23
17
|
"publishConfig": {
|
|
24
18
|
"access": "public",
|
|
@@ -39,11 +33,39 @@
|
|
|
39
33
|
"types": "./dist/nextjs/index.d.ts",
|
|
40
34
|
"default": "./dist/nextjs/index.js"
|
|
41
35
|
},
|
|
36
|
+
"./image": {
|
|
37
|
+
"import": {
|
|
38
|
+
"types": "./dist/esm/image/index.d.ts",
|
|
39
|
+
"default": "./dist/esm/image/index.js"
|
|
40
|
+
},
|
|
41
|
+
"types": "./dist/image/index.d.ts",
|
|
42
|
+
"default": "./dist/image/index.js"
|
|
43
|
+
},
|
|
42
44
|
"./overlay": {
|
|
45
|
+
"import": {
|
|
46
|
+
"types": "./dist/esm/overlay/index.d.ts",
|
|
47
|
+
"default": "./dist/esm/overlay/index.js"
|
|
48
|
+
},
|
|
43
49
|
"types": "./dist/overlay/index.d.ts",
|
|
44
50
|
"default": "./dist/overlay/index.js"
|
|
45
51
|
},
|
|
46
|
-
"./package.json": "./package.json"
|
|
52
|
+
"./package.json": "./package.json",
|
|
53
|
+
"./nextjs/overlay": {
|
|
54
|
+
"import": {
|
|
55
|
+
"types": "./dist/esm/nextjs/overlay.d.ts",
|
|
56
|
+
"default": "./dist/esm/nextjs/overlay.js"
|
|
57
|
+
},
|
|
58
|
+
"types": "./dist/nextjs/overlay.d.ts",
|
|
59
|
+
"default": "./dist/nextjs/overlay.js"
|
|
60
|
+
},
|
|
61
|
+
"./nextjs/image-loader": {
|
|
62
|
+
"import": {
|
|
63
|
+
"types": "./dist/esm/nextjs/image-loader.d.ts",
|
|
64
|
+
"default": "./dist/esm/nextjs/image-loader.js"
|
|
65
|
+
},
|
|
66
|
+
"types": "./dist/nextjs/image-loader.d.ts",
|
|
67
|
+
"default": "./dist/nextjs/image-loader.js"
|
|
68
|
+
}
|
|
47
69
|
},
|
|
48
70
|
"typesVersions": {
|
|
49
71
|
"*": {
|
|
@@ -56,21 +78,47 @@
|
|
|
56
78
|
"overlay": [
|
|
57
79
|
"dist/overlay/index.d.ts"
|
|
58
80
|
],
|
|
81
|
+
"nextjs/overlay": [
|
|
82
|
+
"dist/nextjs/overlay.d.ts"
|
|
83
|
+
],
|
|
84
|
+
"nextjs/image-loader": [
|
|
85
|
+
"dist/nextjs/image-loader.d.ts"
|
|
86
|
+
],
|
|
87
|
+
"image": [
|
|
88
|
+
"dist/image/index.d.ts"
|
|
89
|
+
],
|
|
59
90
|
"*": [
|
|
60
91
|
"dist/index.d.ts"
|
|
61
92
|
]
|
|
62
93
|
}
|
|
63
94
|
},
|
|
64
95
|
"bin": {
|
|
96
|
+
"capa": "bin/capa.js",
|
|
65
97
|
"capa-codegen": "bin/capa-codegen.js"
|
|
66
98
|
},
|
|
99
|
+
"peerDependencies": {
|
|
100
|
+
"graphql": "^16.9.0",
|
|
101
|
+
"react": ">=18"
|
|
102
|
+
},
|
|
103
|
+
"peerDependenciesMeta": {
|
|
104
|
+
"graphql": {
|
|
105
|
+
"optional": true
|
|
106
|
+
},
|
|
107
|
+
"react": {
|
|
108
|
+
"optional": true
|
|
109
|
+
}
|
|
110
|
+
},
|
|
67
111
|
"devDependencies": {
|
|
112
|
+
"graphql": "^16.9.0",
|
|
68
113
|
"typescript": "^5.5.0",
|
|
114
|
+
"@types/react": "19.0.1",
|
|
115
|
+
"next": "15.5.9",
|
|
116
|
+
"react": "19.2.8",
|
|
69
117
|
"@capa/shared": "0.1.0"
|
|
70
118
|
},
|
|
71
119
|
"scripts": {
|
|
72
|
-
"build": "tsc -p tsconfig.json",
|
|
73
|
-
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
74
|
-
"test": "
|
|
120
|
+
"build": "node scripts/shared-image.js && tsc -p tsconfig.json && tsc -p tsconfig.esm.json && node scripts/esm-scope.js",
|
|
121
|
+
"typecheck": "node scripts/shared-image.js && tsc -p tsconfig.json --noEmit && tsc -p tsconfig.esm.json --noEmit",
|
|
122
|
+
"test": "pnpm run build && node --test test/comments.test.js test/codegen.test.js test/client.test.js test/next-client.test.js test/nextjs.test.js test/webhooks.test.js test/attrs.test.js test/overlay.test.js test/overlay-dom.test.js test/nextjs-overlay-refresh.test.js test/nextjs-overlay-bundle.test.js test/inflate.test.js test/field-names.test.js test/next-graphql.test.js test/graphql-codegen.test.js test/graphql-contract.test.js test/readme-snippets.test.js test/nextjs-app.test.js test/nextjs-preview-app.test.js test/package-json.test.js test/changelog.test.js test/published-docs.test.js test/builder-messages.test.js test/image.test.js test/nextjs-image-loader.test.js test/capa-cli-handoff.test.js && tsc -p test/types/tsconfig.consumer.json --noEmit && tsc -p test/types/tsconfig.nonstrict.json --noEmit && tsc -p test/types/tsconfig.next.json --noEmit"
|
|
75
123
|
}
|
|
76
124
|
}
|