@graview/guest 0.1.37 → 0.1.39
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/README.md +94 -0
- package/client.js +1 -1
- package/dist/channel.d.ts +2 -2
- package/dist/channel.d.ts.map +1 -1
- package/dist/client.generated.js +2 -2
- package/dist/headless/describe.d.ts +5 -0
- package/dist/headless/describe.d.ts.map +1 -1
- package/dist/headless/describe.js +62 -0
- package/dist/headless/describe.js.map +1 -1
- package/dist/headless/index.d.ts +1 -1
- package/dist/headless/index.d.ts.map +1 -1
- package/dist/headless/index.js +11 -3
- package/dist/headless/index.js.map +1 -1
- package/dist/headless/judge.js +2 -2
- package/dist/headless/judge.js.map +1 -1
- package/dist/headless/protocol.d.ts +5 -0
- package/dist/headless/protocol.d.ts.map +1 -1
- package/dist/headless/runtime.generated.d.ts.map +1 -1
- package/dist/headless/runtime.generated.js +1 -1
- package/dist/headless/runtime.generated.js.map +1 -1
- package/dist/host/drop-plan.d.ts +58 -0
- package/dist/host/drop-plan.d.ts.map +1 -0
- package/dist/host/drop-plan.js +164 -0
- package/dist/host/drop-plan.js.map +1 -0
- package/dist/host/drop.d.ts +49 -0
- package/dist/host/drop.d.ts.map +1 -0
- package/dist/host/drop.js +329 -0
- package/dist/host/drop.js.map +1 -0
- package/dist/host/frame.d.ts.map +1 -1
- package/dist/host/frame.js +51 -2
- package/dist/host/frame.js.map +1 -1
- package/dist/host/manifest.d.ts +22 -1
- package/dist/host/manifest.d.ts.map +1 -1
- package/dist/host/manifest.js +29 -0
- package/dist/host/manifest.js.map +1 -1
- package/dist/host/marks.d.ts +20 -0
- package/dist/host/marks.d.ts.map +1 -0
- package/dist/host/marks.js +52 -0
- package/dist/host/marks.js.map +1 -0
- package/dist/host/open-draw.d.ts +2 -0
- package/dist/host/open-draw.d.ts.map +1 -1
- package/dist/host/open-draw.js +1 -0
- package/dist/host/open-draw.js.map +1 -1
- package/dist/host/open-judge.d.ts +12 -1
- package/dist/host/open-judge.d.ts.map +1 -1
- package/dist/host/open-judge.js +18 -11
- package/dist/host/open-judge.js.map +1 -1
- package/dist/host/pictures.d.ts +42 -1
- package/dist/host/pictures.d.ts.map +1 -1
- package/dist/host/pictures.js +79 -15
- package/dist/host/pictures.js.map +1 -1
- package/dist/host/press.d.ts +25 -0
- package/dist/host/press.d.ts.map +1 -1
- package/dist/host/press.js +81 -2
- package/dist/host/press.js.map +1 -1
- package/dist/host/react.d.ts.map +1 -1
- package/dist/host/react.js +2 -1
- package/dist/host/react.js.map +1 -1
- package/dist/host/session.d.ts +20 -0
- package/dist/host/session.d.ts.map +1 -1
- package/dist/host/session.js +31 -14
- package/dist/host/session.js.map +1 -1
- package/dist/host/view-runtime.generated.d.ts.map +1 -1
- package/dist/host/view-runtime.generated.js +1 -1
- package/dist/host/view-runtime.generated.js.map +1 -1
- package/dist/host/view.d.ts +8 -1
- package/dist/host/view.d.ts.map +1 -1
- package/dist/host/view.js +131 -6
- package/dist/host/view.js.map +1 -1
- package/dist/host/views.d.ts +3 -3
- package/dist/host/views.d.ts.map +1 -1
- package/dist/host/worker-react.d.ts +10 -0
- package/dist/host/worker-react.d.ts.map +1 -1
- package/dist/host/worker-react.js +18 -5
- package/dist/host/worker-react.js.map +1 -1
- package/dist/host/writes.d.ts +11 -2
- package/dist/host/writes.d.ts.map +1 -1
- package/dist/host/writes.js +36 -4
- package/dist/host/writes.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/protocol.d.ts +59 -4
- package/dist/protocol.d.ts.map +1 -1
- package/dist/protocol.js +11 -0
- package/dist/protocol.js.map +1 -1
- package/dist/worker/view-global.d.ts +18 -5
- package/dist/worker/view-global.d.ts.map +1 -1
- package/dist/worker/view-global.js +8 -2
- package/dist/worker/view-global.js.map +1 -1
- package/dist/worker/view.d.ts.map +1 -1
- package/dist/worker/view.js +2 -1
- package/dist/worker/view.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.generated.js","sourceRoot":"","sources":["../../src/headless/runtime.generated.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAW,
|
|
1
|
+
{"version":3,"file":"runtime.generated.js","sourceRoot":"","sources":["../../src/headless/runtime.generated.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAW,ks7GAAks7G,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { type AnySchema, type FileKind, type FileValue, type HostFiles, type MutationCall, type Principal, type Store } from "@graview/core";
|
|
2
|
+
import { type WorkerViewManifest } from "./manifest.js";
|
|
3
|
+
/** What a `data-drop` element asks: the kind its files become, the one field it narrows to, and the record they are linked to. */
|
|
4
|
+
export interface DropAsked {
|
|
5
|
+
readonly kind: string;
|
|
6
|
+
/** `data-drop-field`: one of the accepted fields of the kind, rather than any. */
|
|
7
|
+
readonly field?: string;
|
|
8
|
+
/** `data-drop-connect`, as the view wrote it: `<relation>:<record id>`. */
|
|
9
|
+
readonly connect?: string;
|
|
10
|
+
}
|
|
11
|
+
/** A field a file goes in, by its sort. */
|
|
12
|
+
export interface DropField {
|
|
13
|
+
readonly field: string;
|
|
14
|
+
readonly as: FileKind;
|
|
15
|
+
readonly list: boolean;
|
|
16
|
+
}
|
|
17
|
+
export type DropPlan = {
|
|
18
|
+
readonly ok: true;
|
|
19
|
+
readonly kind: string;
|
|
20
|
+
readonly fields: readonly DropField[];
|
|
21
|
+
/** What the picker asks for: the host's kinds of the fields' sorts. */
|
|
22
|
+
readonly accept: string;
|
|
23
|
+
/** The record they are linked to, and by what. */
|
|
24
|
+
readonly connect?: {
|
|
25
|
+
readonly relation: string;
|
|
26
|
+
readonly record: string;
|
|
27
|
+
};
|
|
28
|
+
/** The calls one file's record is made with; the change for several files is these, file after file. */
|
|
29
|
+
readonly calls: (file: {
|
|
30
|
+
readonly field: string;
|
|
31
|
+
readonly value: FileValue;
|
|
32
|
+
readonly at?: string;
|
|
33
|
+
}, at: number) => MutationCall[];
|
|
34
|
+
/** What the change is, said: "Add 4 moments to Saturday". */
|
|
35
|
+
readonly intent: (count: number) => string;
|
|
36
|
+
/** What the host says while files are dragged over it: "Drop to add moments to Saturday." */
|
|
37
|
+
readonly invite: string;
|
|
38
|
+
/** What it says once the change is made: "Added 4 moments to Saturday." */
|
|
39
|
+
readonly added: (count: number) => string;
|
|
40
|
+
} | {
|
|
41
|
+
readonly ok: false;
|
|
42
|
+
readonly says: string;
|
|
43
|
+
};
|
|
44
|
+
/** `<relation>:<record id>`, split at its first colon; undefined where it is not that. */
|
|
45
|
+
export declare function dropConnectOf(said: string | undefined): {
|
|
46
|
+
readonly relation: string;
|
|
47
|
+
readonly record: string;
|
|
48
|
+
} | undefined;
|
|
49
|
+
/** Whether a host's kinds take a type: the type itself, its family (`image/*`), or anything. Any, where it lists none. */
|
|
50
|
+
export declare function takes(kinds: readonly string[], type: string): boolean;
|
|
51
|
+
/** The field of a plan a file of `type` goes in: a picture to an image field, a video to a video field, anything else to a file field — else any file field. */
|
|
52
|
+
export declare function fieldFor(fields: readonly DropField[], type: string): DropField | undefined;
|
|
53
|
+
/** WHAT A DROP ON THIS ELEMENT MAKES, or why it is no drop target. */
|
|
54
|
+
export declare function planDrop<S extends AnySchema>(store: Store<S>, principal: Principal, manifest: WorkerViewManifest, asked: DropAsked, given: {
|
|
55
|
+
readonly shown: ReadonlySet<string>;
|
|
56
|
+
readonly files: HostFiles | undefined;
|
|
57
|
+
}): DropPlan;
|
|
58
|
+
//# sourceMappingURL=drop-plan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop-plan.d.ts","sourceRoot":"","sources":["../../src/host/drop-plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+D,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,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KAAK,MAAM,CAAC;IAC3C,6FAA6F;IAC7F,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,2EAA2E;IAC3E,QAAQ,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3C,GACD;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAElD,0FAA0F;AAC1F,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAI1H;AAED,0HAA0H;AAC1H,wBAAgB,KAAK,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAIrE;AAED,gKAAgK;AAChK,wBAAgB,QAAQ,CAAC,MAAM,EAAE,SAAS,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,CAG1F;AA4CD,sEAAsE;AACtE,wBAAgB,QAAQ,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;IAAE,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAAA;CAAE,GAAG,QAAQ,CAyFpO"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { labelOf, made, nounOf, pluralOf } from "@graview/core";
|
|
2
|
+
import { fileFieldOf } from "./manifest.js";
|
|
3
|
+
import { refArgsOf } from "./marks.js";
|
|
4
|
+
/** `<relation>:<record id>`, split at its first colon; undefined where it is not that. */
|
|
5
|
+
export function dropConnectOf(said) {
|
|
6
|
+
const at = said?.indexOf(":") ?? -1;
|
|
7
|
+
if (!said || at <= 0 || at === said.length - 1)
|
|
8
|
+
return undefined;
|
|
9
|
+
return { relation: said.slice(0, at), record: said.slice(at + 1) };
|
|
10
|
+
}
|
|
11
|
+
/** Whether a host's kinds take a type: the type itself, its family (`image/*`), or anything. Any, where it lists none. */
|
|
12
|
+
export function takes(kinds, type) {
|
|
13
|
+
if (kinds.length === 0)
|
|
14
|
+
return true;
|
|
15
|
+
const family = `${type.split("/")[0]}/*`;
|
|
16
|
+
return kinds.some((kind) => kind === "*" || kind === "*/*" || kind === type || kind === family);
|
|
17
|
+
}
|
|
18
|
+
/** The field of a plan a file of `type` goes in: a picture to an image field, a video to a video field, anything else to a file field — else any file field. */
|
|
19
|
+
export function fieldFor(fields, type) {
|
|
20
|
+
const sort = type.startsWith("image/") ? "image" : type.startsWith("video/") ? "video" : "file";
|
|
21
|
+
return fields.find((one) => one.as === sort) ?? fields.find((one) => one.as === "file");
|
|
22
|
+
}
|
|
23
|
+
/** What the host's kinds take of a field's sort, for the picker: `image/*`, or the host's own image types. */
|
|
24
|
+
function acceptOf(fields, files) {
|
|
25
|
+
const families = new Set(fields.map((one) => (one.as === "image" ? "image/" : one.as === "video" ? "video/" : "")));
|
|
26
|
+
if (families.has("") || files.kinds.length === 0)
|
|
27
|
+
return files.kinds.join(",");
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const family of families) {
|
|
30
|
+
const listed = files.kinds.filter((kind) => kind.startsWith(family));
|
|
31
|
+
out.push(...(listed.length > 0 ? listed : [`${family}*`]));
|
|
32
|
+
}
|
|
33
|
+
return out.join(",");
|
|
34
|
+
}
|
|
35
|
+
const shapeOf = (mutation) => mutation.input?.shape ?? {};
|
|
36
|
+
const required = (mutation, arg) => shapeOf(mutation)[arg]?.safeParse(undefined).success === false;
|
|
37
|
+
/** A plain text argument the act cannot go without: the one a record is named by, filled with the file's name where nothing else says it. */
|
|
38
|
+
function namingArgs(mutation, taken) {
|
|
39
|
+
const refs = new Set(refArgsOf(mutation.input).map((ref) => ref.name));
|
|
40
|
+
return Object.keys(shapeOf(mutation)).filter((arg) => !taken.has(arg) && !refs.has(arg) && required(mutation, arg) && shapeOf(mutation)[arg].safeParse("a name").success && !shapeOf(mutation)[arg].safeParse(1).success);
|
|
41
|
+
}
|
|
42
|
+
const baseName = (name) => name.replace(/\.[a-z0-9]{1,5}$/i, "") || name;
|
|
43
|
+
/*
|
|
44
|
+
* WHEN THE FILE WAS TAKEN (the thirteenth walk): a required time the act
|
|
45
|
+
* cannot go without — a detection's `takenAt`, a moment's day — is the
|
|
46
|
+
* instant the file says it was made (its `at`), else the drop's own, as an
|
|
47
|
+
* instant or as its day, whichever the argument takes.
|
|
48
|
+
*/
|
|
49
|
+
const timeOf = (schema, at) => [at, at.replace(/\.\d{3}Z$/, "Z"), at.slice(0, 10)].find((one) => schema.safeParse(one).success);
|
|
50
|
+
const PROBE = "2026-01-01T00:00:00.000Z";
|
|
51
|
+
/** The arguments a file fills by its time, and those no file can fill: what a drop would leave the act asking for. */
|
|
52
|
+
function unfilled(mutation, given) {
|
|
53
|
+
const shape = shapeOf(mutation);
|
|
54
|
+
const naming = new Set(namingArgs(mutation, given));
|
|
55
|
+
const open = Object.keys(shape).filter((arg) => !given.has(arg) && !naming.has(arg) && required(mutation, arg));
|
|
56
|
+
const timed = open.filter((arg) => timeOf(shape[arg], PROBE) !== undefined);
|
|
57
|
+
return { timed, left: open.filter((arg) => !timed.includes(arg)) };
|
|
58
|
+
}
|
|
59
|
+
/** WHAT A DROP ON THIS ELEMENT MAKES, or why it is no drop target. */
|
|
60
|
+
export function planDrop(store, principal, manifest, asked, given) {
|
|
61
|
+
const no = (says) => ({ ok: false, says });
|
|
62
|
+
const { kind } = asked;
|
|
63
|
+
const accepted = (manifest.accepts ?? []).filter((one) => one.kind === kind && (asked.field === undefined || one.field === asked.field));
|
|
64
|
+
if (accepted.length === 0)
|
|
65
|
+
return no(asked.field === undefined ? `The view's accepts names no field of "${kind}", so nothing dropped there can become one.` : `The view's accepts does not name ${kind}'s "${asked.field}".`);
|
|
66
|
+
const files = given.files;
|
|
67
|
+
if (!files || !(files.maxBytes > 0))
|
|
68
|
+
return no("This host takes no files.");
|
|
69
|
+
const fields = accepted.flatMap((one) => {
|
|
70
|
+
const held = fileFieldOf(store, one.kind, one.field);
|
|
71
|
+
return held ? [{ field: one.field, ...held }] : [];
|
|
72
|
+
});
|
|
73
|
+
/* Only the fields whose sort the host takes. */
|
|
74
|
+
const taken = fields.filter((one) => one.as === "file" || files.kinds.length === 0 || files.kinds.some((kind) => kind === "*" || kind === "*/*" || kind.startsWith(one.as === "image" ? "image/" : "video/")));
|
|
75
|
+
if (taken.length === 0)
|
|
76
|
+
return no(`This host takes none of what ${kind}'s ${fields.map((one) => `"${one.field}"`).join(" or ")} holds.`);
|
|
77
|
+
const connect = asked.connect === undefined ? undefined : dropConnectOf(asked.connect);
|
|
78
|
+
if (asked.connect !== undefined && (!connect || given.shown.has(asked.connect)))
|
|
79
|
+
return no(`data-drop-connect is "<relation>:<record id>", not "${asked.connect}".`);
|
|
80
|
+
if (connect && !given.shown.has(connect.record))
|
|
81
|
+
return no(`data-drop-connect names "${connect.record}", which this view was not shown.`);
|
|
82
|
+
const target = connect ? store.seenBy(principal).graph.getNode(connect.record) : undefined;
|
|
83
|
+
if (connect && !target)
|
|
84
|
+
return no(`data-drop-connect names "${connect.record}", which this seat does not see.`);
|
|
85
|
+
const declared = (owner) => Object.hasOwn((store.schema.tryDefinition(owner)?.edges ?? {}), connect.relation);
|
|
86
|
+
/* The relation leaves the new record (a moment taken on a day), or the record dropped on (a day's moments). */
|
|
87
|
+
const fromNew = connect ? declared(kind) : false;
|
|
88
|
+
if (connect && !fromNew && !declared(target.kind))
|
|
89
|
+
return no(`Neither a "${kind}" nor a "${target.kind}" has the relation "${connect.relation}".`);
|
|
90
|
+
const all = store.allMutations();
|
|
91
|
+
const may = (call) => store.permits(call, principal).ok;
|
|
92
|
+
const takesAll = (mutation) => taken.every((one) => Object.hasOwn(shapeOf(mutation), one.field));
|
|
93
|
+
const makers = all.filter((mutation) => (mutation.creates ?? []).includes(kind) && takesAll(mutation));
|
|
94
|
+
const noun = nounOf(store.schema.tryDefinition(kind), kind);
|
|
95
|
+
const plural = pluralOf(store.schema, kind).toLowerCase();
|
|
96
|
+
const label = target ? labelOf(store.schema.tryDefinition(target.kind), target) : undefined;
|
|
97
|
+
const counted = (count) => `${count === 1 ? `a ${noun}` : `${count} ${plural}`}${label ? ` to ${label}` : ""}`;
|
|
98
|
+
const intent = (count) => `Add ${counted(count)}`;
|
|
99
|
+
const added = (count) => `Added ${counted(count)}.`;
|
|
100
|
+
const invite = `Drop to add ${plural}${label ? ` to ${label}` : ""}.`;
|
|
101
|
+
const fill = (mutation, args, file, at) => {
|
|
102
|
+
const given = new Set(Object.keys(args));
|
|
103
|
+
for (const arg of unfilled(mutation, given).timed)
|
|
104
|
+
args[arg] = timeOf(shapeOf(mutation)[arg], at ?? new Date().toISOString());
|
|
105
|
+
for (const arg of namingArgs(mutation, given))
|
|
106
|
+
args[arg] = baseName(file.name);
|
|
107
|
+
return args;
|
|
108
|
+
};
|
|
109
|
+
/* An act a drop would leave asking for something no file says is no act for a drop: nothing is offered and then refused. */
|
|
110
|
+
const fileArgs = (mutation, ...more) => new Set([...taken.map((one) => one.field), ...more, ...refArgsOf(mutation.input).map((ref) => ref.name)]);
|
|
111
|
+
const asksMore = (mutation, ...more) => unfilled(mutation, fileArgs(mutation, ...more)).left;
|
|
112
|
+
const asking = (mutation, left) => no(`"${mutation.title ?? mutation.name}" asks for ${left.map((arg) => `"${arg}"`).join(" and ")}, which no dropped file says, so nothing dropped here can become a ${noun}.`);
|
|
113
|
+
const value = (one, file) => (one.list ? [file] : file);
|
|
114
|
+
const plan = { ok: true, kind, fields: taken, accept: acceptOf(taken, files), ...(connect ? { connect } : {}), intent, invite, added };
|
|
115
|
+
if (!connect) {
|
|
116
|
+
const maker = makers.find((mutation) => !mutation.subject && may({ name: mutation.name, args: {} }));
|
|
117
|
+
if (!maker)
|
|
118
|
+
return no(`This seat may not make a "${kind}" here.`);
|
|
119
|
+
if (asksMore(maker).length > 0)
|
|
120
|
+
return asking(maker, asksMore(maker));
|
|
121
|
+
return { ...plan, calls: (file) => [{ name: maker.name, args: fill(maker, { [file.field]: value(taken.find((one) => one.field === file.field), file.value) }, file.value, file.at) }] };
|
|
122
|
+
}
|
|
123
|
+
/* One act done to the record dropped on, that makes the kind and links it. */
|
|
124
|
+
const onIt = makers.find((mutation) => mutation.subject && (mutation.subject.kinds === "*" || mutation.subject.kinds.includes(target.kind)) && (mutation.connects ?? []).includes(connect.relation) && may({ name: mutation.name, args: { [mutation.subject.arg]: connect.record } }));
|
|
125
|
+
if (onIt) {
|
|
126
|
+
const arg = onIt.subject.arg;
|
|
127
|
+
if (asksMore(onIt, arg).length > 0)
|
|
128
|
+
return asking(onIt, asksMore(onIt, arg));
|
|
129
|
+
return { ...plan, calls: (file) => [{ name: onIt.name, args: fill(onIt, { [arg]: connect.record, [file.field]: value(taken.find((one) => one.field === file.field), file.value) }, file.value, file.at) }] };
|
|
130
|
+
}
|
|
131
|
+
/* Else one that makes it, and one that links it, naming the record just made. */
|
|
132
|
+
const maker = makers.find((mutation) => !mutation.subject && may({ name: mutation.name, args: {} }));
|
|
133
|
+
if (!maker)
|
|
134
|
+
return no(`This seat may not make a "${kind}" here.`);
|
|
135
|
+
if (asksMore(maker).length > 0)
|
|
136
|
+
return asking(maker, asksMore(maker));
|
|
137
|
+
const linkerKind = fromNew ? kind : target.kind;
|
|
138
|
+
const farKind = fromNew ? target.kind : kind;
|
|
139
|
+
const linker = all.find((mutation) => {
|
|
140
|
+
if (!(mutation.connects ?? []).includes(connect.relation) || !mutation.subject)
|
|
141
|
+
return false;
|
|
142
|
+
const kinds = mutation.subject.kinds;
|
|
143
|
+
if (kinds !== "*" && !kinds.includes(linkerKind))
|
|
144
|
+
return false;
|
|
145
|
+
const to = refArgsOf(mutation.input).find((ref) => ref.name !== mutation.subject.arg && (ref.kinds.includes("*") || ref.kinds.includes(farKind)));
|
|
146
|
+
if (!to)
|
|
147
|
+
return false;
|
|
148
|
+
/* Asked as it will be: from the record dropped on, or to it. */
|
|
149
|
+
return may({ name: mutation.name, args: fromNew ? { [to.name]: connect.record } : { [mutation.subject.arg]: connect.record } });
|
|
150
|
+
});
|
|
151
|
+
if (!linker)
|
|
152
|
+
return no(`This seat may not link a "${kind}" to ${connect.record} by "${connect.relation}".`);
|
|
153
|
+
const subject = linker.subject.arg;
|
|
154
|
+
const to = refArgsOf(linker.input).find((ref) => ref.name !== subject && (ref.kinds.includes("*") || ref.kinds.includes(farKind))).name;
|
|
155
|
+
return {
|
|
156
|
+
...plan,
|
|
157
|
+
calls: (file, at) => [
|
|
158
|
+
{ name: maker.name, args: fill(maker, { [file.field]: value(taken.find((one) => one.field === file.field), file.value) }, file.value, file.at) },
|
|
159
|
+
/* The record the call before it makes: two calls a file, so the maker of file `at` is call `2 × at`. */
|
|
160
|
+
{ name: linker.name, args: fromNew ? { [subject]: made(at * 2), [to]: connect.record } : { [subject]: connect.record, [to]: made(at * 2) } },
|
|
161
|
+
],
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=drop-plan.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop-plan.js","sourceRoot":"","sources":["../../src/host/drop-plan.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAA4I,MAAM,eAAe,CAAC;AAC1M,OAAO,EAAE,WAAW,EAA2B,MAAM,eAAe,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AA8DvC,0FAA0F;AAC1F,MAAM,UAAU,aAAa,CAAC,IAAwB;IACpD,MAAM,EAAE,GAAG,IAAI,EAAE,O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,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,EAAE;SAC7I;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { AnySchema, FileValue, HostFiles, MutationCall, Principal, Store } from "@graview/core";
|
|
2
|
+
import type { GuestDomEvent, GuestRefusal } from "../protocol.js";
|
|
3
|
+
import type { WorkerViewManifest } from "./manifest.js";
|
|
4
|
+
export interface GuestDropsOptions<S extends AnySchema> {
|
|
5
|
+
readonly shadow: ShadowRoot;
|
|
6
|
+
readonly manifest: WorkerViewManifest;
|
|
7
|
+
readonly store: Store<S>;
|
|
8
|
+
readonly principal: Principal;
|
|
9
|
+
/** The page's host's files, read at each drop. */
|
|
10
|
+
readonly files: () => HostFiles | undefined;
|
|
11
|
+
/** The records the view was last shown. */
|
|
12
|
+
readonly shown: () => ReadonlySet<string>;
|
|
13
|
+
/** Whether the view hears `drop` (its `graview.on`): then the drop is told to it, and no record is made for it. */
|
|
14
|
+
readonly hears: () => boolean;
|
|
15
|
+
/** The view's id for an element it drew. */
|
|
16
|
+
readonly idOf: (element: Element) => string | undefined;
|
|
17
|
+
/** Tell the view. */
|
|
18
|
+
readonly send: (message: GuestDomEvent) => void;
|
|
19
|
+
/** Apply the change a drop the view does not hear makes: as the viewer, through the view. */
|
|
20
|
+
readonly change: (calls: readonly MutationCall[], intent: string) => {
|
|
21
|
+
readonly ok: true;
|
|
22
|
+
readonly intent: string;
|
|
23
|
+
} | {
|
|
24
|
+
readonly ok: false;
|
|
25
|
+
readonly reason: GuestRefusal;
|
|
26
|
+
readonly message: string;
|
|
27
|
+
};
|
|
28
|
+
/** A file the host stored and handed the view: one it may hand back in an act's argument. */
|
|
29
|
+
readonly handed: (file: FileValue) => void;
|
|
30
|
+
/** Whether the pointer is coarse (a phone): then a tap on a drop target opens the picker. `(pointer: coarse)` by default. */
|
|
31
|
+
readonly coarse?: () => boolean;
|
|
32
|
+
/** Something about a drop target, said once for the host's problems: why an element marked `data-drop` is not one. */
|
|
33
|
+
readonly onProblem?: (said: string) => void;
|
|
34
|
+
/** A drop began or settled: the region says it has drawn only once nothing is on its way. */
|
|
35
|
+
readonly onBusy?: () => void;
|
|
36
|
+
}
|
|
37
|
+
export interface GuestDrops {
|
|
38
|
+
/** Look again at what the view drew: which elements are drop targets now. Run after each batch it draws. */
|
|
39
|
+
refresh(): void;
|
|
40
|
+
/** An event on what the view drew, before the view hears it: a tap or a key on a drop target opens the picker. True when it was the host's. */
|
|
41
|
+
before(event: Event, at: Element, root: Element): boolean;
|
|
42
|
+
/** Settles once every drop under way has been kept or refused. */
|
|
43
|
+
idle(): Promise<void>;
|
|
44
|
+
/** How many drops are under way. */
|
|
45
|
+
readonly waiting: number;
|
|
46
|
+
dispose(): void;
|
|
47
|
+
}
|
|
48
|
+
export declare function createGuestDrops<S extends AnySchema>(window: Window & typeof globalThis, options: GuestDropsOptions<S>): GuestDrops;
|
|
49
|
+
//# sourceMappingURL=drop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drop.d.ts","sourceRoot":"","sources":["../../src/host/drop.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACrG,OAAO,KAAK,EAAE,aAAa,EAAoB,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEpF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAiCxD,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,SAAS;IACpD,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACtC,QAAQ,CAAC,KAAK,EAAE,KAAK,CA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CAAC;IAChB,+IAA+I;IAC/I,MAAM,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC;IAC1D,kEAAkE;IAClE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,oCAAoC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,OAAO,IAAI,IAAI,CAAC;CACjB;AAiCD,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,UAAU,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,UAAU,CA2RnI"}
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { fieldFor, planDrop, takes } from "./drop-plan.js";
|
|
2
|
+
import { isStoredFile } from "./marks.js";
|
|
3
|
+
const isImage = (file) => file.type.startsWith("image/");
|
|
4
|
+
const isVideo = (file) => file.type.startsWith("video/");
|
|
5
|
+
/** The host's own look for a drop target: over the view's styles, which cannot reach it. */
|
|
6
|
+
const DROP_CSS = `
|
|
7
|
+
[data-graview-drop-over] { outline: 2px dashed var(--graview-accent, Highlight) !important; outline-offset: 2px !important; background-color: color-mix(in srgb, var(--graview-accent, Highlight) 10%, transparent) !important; }
|
|
8
|
+
[data-graview-drop-status], [data-graview-drop-refused] { margin: 4px 0 0; font: 0.8125rem/1.4 var(--graview-font-body, system-ui, sans-serif); color: var(--graview-ink-muted, GrayText); }
|
|
9
|
+
[data-graview-drop-refused] { color: var(--graview-warn, var(--graview-ink, CanvasText)); }
|
|
10
|
+
[data-graview-drop-status]:empty, [data-graview-drop-refused]:empty { display: none; }
|
|
11
|
+
`;
|
|
12
|
+
/** What the person reaches for inside a drop target, which a tap on it leaves to them. */
|
|
13
|
+
const OWN_PRESS = "a, button, input, select, textarea, label, summary, [data-act], [data-lightbox], [data-record], [tabindex]";
|
|
14
|
+
/** A size as a person reads it: "820 bytes", "120 KB", "3.4 MB" (the file editor's words). */
|
|
15
|
+
function sizeWords(bytes) {
|
|
16
|
+
if (bytes < 1000)
|
|
17
|
+
return `${bytes} bytes`;
|
|
18
|
+
if (bytes < 1_000_000)
|
|
19
|
+
return `${Math.round(bytes / 1000)} KB`;
|
|
20
|
+
return `${(bytes / 1_000_000).toFixed(bytes < 10_000_000 ? 1 : 0)} MB`;
|
|
21
|
+
}
|
|
22
|
+
/** A video's type from its name, where the browser said none (a phone's `.MOV` often comes untyped). */
|
|
23
|
+
const ENDINGS = { mov: "video/quicktime", mp4: "video/mp4", m4v: "video/mp4", webm: "video/webm", heic: "image/heic", heif: "image/heif", jpg: "image/jpeg", jpeg: "image/jpeg", png: "image/png" };
|
|
24
|
+
const typeOf = (file) => file.type || ENDINGS[/\.([a-z0-9]{2,4})$/i.exec(file.name)?.[1]?.toLowerCase() ?? ""] || "application/octet-stream";
|
|
25
|
+
/** What a plan's fields hold, said: "a picture or a video". */
|
|
26
|
+
function sortsWords(plan) {
|
|
27
|
+
const said = [...new Set(plan.fields.map((one) => (one.as === "image" ? "a picture" : one.as === "video" ? "a video" : "a file")))];
|
|
28
|
+
return said.length <= 1 ? (said[0] ?? "a file") : `${said.slice(0, -1).join(", ")} or ${said[said.length - 1]}`;
|
|
29
|
+
}
|
|
30
|
+
/** What a target says to assistive technology: what dropping or pressing there does. */
|
|
31
|
+
const describedAs = (plan, coarse) => `${plan.invite.replace(/\.$/, "")}${coarse ? ", or tap to choose them" : ""}.`;
|
|
32
|
+
export function createGuestDrops(window, options) {
|
|
33
|
+
const { shadow } = options;
|
|
34
|
+
const document = shadow.ownerDocument;
|
|
35
|
+
const coarse = options.coarse ?? (() => typeof window.matchMedia === "function" && window.matchMedia("(pointer: coarse)").matches);
|
|
36
|
+
const plans = new WeakMap();
|
|
37
|
+
/* What the host wrote on the view's element: taken away again when it is no target. */
|
|
38
|
+
const described = new WeakSet();
|
|
39
|
+
const told = new Set();
|
|
40
|
+
const pending = new Set();
|
|
41
|
+
const style = document.createElement("style");
|
|
42
|
+
style.setAttribute("data-graview-drop-style", "");
|
|
43
|
+
style.textContent = DROP_CSS;
|
|
44
|
+
const status = document.createElement("p");
|
|
45
|
+
status.setAttribute("data-graview-drop-status", "");
|
|
46
|
+
status.setAttribute("role", "status");
|
|
47
|
+
status.setAttribute("aria-live", "polite");
|
|
48
|
+
const refused = document.createElement("div");
|
|
49
|
+
refused.setAttribute("data-graview-drop-refused", "");
|
|
50
|
+
refused.setAttribute("role", "alert");
|
|
51
|
+
const picker = document.createElement("input");
|
|
52
|
+
picker.type = "file";
|
|
53
|
+
picker.multiple = true;
|
|
54
|
+
picker.hidden = true;
|
|
55
|
+
picker.tabIndex = -1;
|
|
56
|
+
picker.setAttribute("data-graview-drop-picker", "");
|
|
57
|
+
picker.setAttribute("aria-hidden", "true");
|
|
58
|
+
shadow.append(style, status, refused, picker);
|
|
59
|
+
const say = (words) => {
|
|
60
|
+
if (status.textContent !== words)
|
|
61
|
+
status.textContent = words;
|
|
62
|
+
};
|
|
63
|
+
const sayRefused = (lines) => {
|
|
64
|
+
refused.replaceChildren(...lines.map((line) => {
|
|
65
|
+
const one = document.createElement("p");
|
|
66
|
+
one.style.margin = "0";
|
|
67
|
+
one.textContent = line;
|
|
68
|
+
return one;
|
|
69
|
+
}));
|
|
70
|
+
};
|
|
71
|
+
const targets = () => [...shadow.querySelectorAll("[data-drop]")];
|
|
72
|
+
const targetOf = (from) => {
|
|
73
|
+
const at = from;
|
|
74
|
+
const found = at && typeof at.closest === "function" ? at.closest("[data-graview-drop]") : null;
|
|
75
|
+
return found && shadow.contains(found) ? found : undefined;
|
|
76
|
+
};
|
|
77
|
+
const refresh = () => {
|
|
78
|
+
const shown = options.shown();
|
|
79
|
+
const files = options.files();
|
|
80
|
+
let first;
|
|
81
|
+
for (const element of targets()) {
|
|
82
|
+
const kind = element.getAttribute("data-drop") ?? "";
|
|
83
|
+
const plan = planDrop(options.store, options.principal, options.manifest, {
|
|
84
|
+
kind,
|
|
85
|
+
...(element.hasAttribute("data-drop-field") ? { field: element.getAttribute("data-drop-field") } : {}),
|
|
86
|
+
...(element.hasAttribute("data-drop-connect") ? { connect: element.getAttribute("data-drop-connect") } : {}),
|
|
87
|
+
}, { shown, files });
|
|
88
|
+
if (plan.ok) {
|
|
89
|
+
first ??= plan;
|
|
90
|
+
plans.set(element, plan);
|
|
91
|
+
element.setAttribute("data-graview-drop", "");
|
|
92
|
+
if (!element.hasAttribute("aria-description") || described.has(element)) {
|
|
93
|
+
element.setAttribute("aria-description", describedAs(plan, coarse()));
|
|
94
|
+
described.add(element);
|
|
95
|
+
}
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
plans.delete(element);
|
|
99
|
+
element.removeAttribute("data-graview-drop");
|
|
100
|
+
element.removeAttribute("data-graview-drop-over");
|
|
101
|
+
if (described.has(element)) {
|
|
102
|
+
element.removeAttribute("aria-description");
|
|
103
|
+
described.delete(element);
|
|
104
|
+
}
|
|
105
|
+
/* Said once a sentence: a seat that may not make the kind is no problem of the view's, and is not said. */
|
|
106
|
+
if (!/^This seat may not|^This host takes no/.test(plan.says) && !told.has(plan.says)) {
|
|
107
|
+
told.add(plan.says);
|
|
108
|
+
options.onProblem?.(`A drop target the view drew (data-drop="${kind}") is not offered: ${plan.says}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (first)
|
|
112
|
+
picker.accept = first.accept;
|
|
113
|
+
};
|
|
114
|
+
/* ── dragging over ───────────────────────────────────────────────────── */
|
|
115
|
+
const hasFiles = (event) => {
|
|
116
|
+
const types = event.dataTransfer?.types;
|
|
117
|
+
return types !== undefined && Array.from(types).includes("Files");
|
|
118
|
+
};
|
|
119
|
+
let over;
|
|
120
|
+
const light = (element) => {
|
|
121
|
+
if (over === element)
|
|
122
|
+
return;
|
|
123
|
+
over?.removeAttribute("data-graview-drop-over");
|
|
124
|
+
over = element;
|
|
125
|
+
if (element) {
|
|
126
|
+
element.setAttribute("data-graview-drop-over", "");
|
|
127
|
+
say(plans.get(element)?.invite ?? "");
|
|
128
|
+
}
|
|
129
|
+
else if (pending.size === 0)
|
|
130
|
+
say("");
|
|
131
|
+
};
|
|
132
|
+
const onOver = (event) => {
|
|
133
|
+
const element = targetOf(event.composedPath()[0]);
|
|
134
|
+
if (!element || !hasFiles(event))
|
|
135
|
+
return;
|
|
136
|
+
event.preventDefault();
|
|
137
|
+
const transfer = event.dataTransfer;
|
|
138
|
+
if (transfer)
|
|
139
|
+
transfer.dropEffect = "copy";
|
|
140
|
+
light(element);
|
|
141
|
+
};
|
|
142
|
+
const onLeave = (event) => {
|
|
143
|
+
if (!over)
|
|
144
|
+
return;
|
|
145
|
+
const into = event.relatedTarget;
|
|
146
|
+
if (into && over.contains(into))
|
|
147
|
+
return;
|
|
148
|
+
light(undefined);
|
|
149
|
+
};
|
|
150
|
+
const onDrop = (event) => {
|
|
151
|
+
const element = targetOf(event.composedPath()[0]);
|
|
152
|
+
light(undefined);
|
|
153
|
+
if (!element)
|
|
154
|
+
return;
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
event.stopPropagation();
|
|
157
|
+
const files = Array.from((event.dataTransfer?.files ?? []));
|
|
158
|
+
if (files.length > 0)
|
|
159
|
+
take(element, files);
|
|
160
|
+
};
|
|
161
|
+
const onEnd = () => light(undefined);
|
|
162
|
+
shadow.addEventListener("dragenter", onOver);
|
|
163
|
+
shadow.addEventListener("dragover", onOver);
|
|
164
|
+
shadow.addEventListener("dragleave", onLeave);
|
|
165
|
+
shadow.addEventListener("drop", onDrop);
|
|
166
|
+
document.addEventListener("dragend", onEnd);
|
|
167
|
+
document.addEventListener("drop", onEnd);
|
|
168
|
+
/* ── picked ──────────────────────────────────────────────────────────── */
|
|
169
|
+
let picking;
|
|
170
|
+
const pick = (element) => {
|
|
171
|
+
const plan = plans.get(element);
|
|
172
|
+
if (!plan)
|
|
173
|
+
return;
|
|
174
|
+
picking = element;
|
|
175
|
+
picker.accept = plan.accept;
|
|
176
|
+
picker.click();
|
|
177
|
+
};
|
|
178
|
+
picker.addEventListener("change", () => {
|
|
179
|
+
const files = Array.from(picker.files ?? []);
|
|
180
|
+
try {
|
|
181
|
+
picker.value = "";
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
// A picker a test filled by hand: nothing to empty.
|
|
185
|
+
}
|
|
186
|
+
if (picking && files.length > 0)
|
|
187
|
+
take(picking, files);
|
|
188
|
+
});
|
|
189
|
+
/* ── kept ────────────────────────────────────────────────────────────── */
|
|
190
|
+
const take = (element, given) => {
|
|
191
|
+
const plan = plans.get(element);
|
|
192
|
+
const files = options.files();
|
|
193
|
+
if (!plan || !files)
|
|
194
|
+
return;
|
|
195
|
+
const work = keep(element, plan, files, given).finally(() => {
|
|
196
|
+
pending.delete(work);
|
|
197
|
+
options.onBusy?.();
|
|
198
|
+
});
|
|
199
|
+
pending.add(work);
|
|
200
|
+
options.onBusy?.();
|
|
201
|
+
};
|
|
202
|
+
async function keep(element, plan, host, given) {
|
|
203
|
+
sayRefused([]);
|
|
204
|
+
say(`Adding ${given.length === 1 ? `“${given[0].name}”` : `${given.length} files`}…`);
|
|
205
|
+
const problems = [];
|
|
206
|
+
const kept = [];
|
|
207
|
+
for (const file of given) {
|
|
208
|
+
const name = file.name || "file";
|
|
209
|
+
const type = typeOf(file);
|
|
210
|
+
const field = fieldFor(plan.fields, type);
|
|
211
|
+
if (!field) {
|
|
212
|
+
problems.push(`“${name}” isn’t ${sortsWords(plan)}.`);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
if (!takes(host.kinds, type)) {
|
|
216
|
+
problems.push(`“${name}” is ${type}; this host doesn’t take it.`);
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (file.size > host.maxBytes) {
|
|
220
|
+
problems.push(`“${name}” is ${sizeWords(file.size)}; this host takes files up to ${sizeWords(host.maxBytes)}.`);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
let answered;
|
|
224
|
+
try {
|
|
225
|
+
answered = await host.upload(file, name);
|
|
226
|
+
}
|
|
227
|
+
catch (error) {
|
|
228
|
+
problems.push(`“${name}” wasn’t kept: ${error instanceof Error && error.message.trim() ? error.message.trim() : "the host refused it"}`);
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
if (!isStoredFile(answered)) {
|
|
232
|
+
problems.push(`The host’s answer for “${name}” isn’t a file a record can keep.`);
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if ((field.as === "image" && !isImage(answered)) || (field.as === "video" && !isVideo(answered))) {
|
|
236
|
+
problems.push(`The host kept “${name}” as ${answered.type}, not as ${field.as === "image" ? "a picture" : "a video"}.`);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
let value = answered;
|
|
240
|
+
/* A picture's size in pixels, where the host did not say it and this browser can read it. */
|
|
241
|
+
if (isImage(value) && (value.width === undefined || value.height === undefined) && typeof window.createImageBitmap === "function") {
|
|
242
|
+
try {
|
|
243
|
+
const bitmap = await window.createImageBitmap(file);
|
|
244
|
+
value = { ...value, width: bitmap.width, height: bitmap.height };
|
|
245
|
+
bitmap.close();
|
|
246
|
+
}
|
|
247
|
+
catch {
|
|
248
|
+
// Its size is the host's to know, then.
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const at = Number.isFinite(file.lastModified) && file.lastModified > 0 ? new Date(file.lastModified).toISOString() : undefined;
|
|
252
|
+
kept.push({ field: field.field, value, ...(at ? { at } : {}) });
|
|
253
|
+
}
|
|
254
|
+
for (const one of kept)
|
|
255
|
+
options.handed(one.value);
|
|
256
|
+
sayRefused(problems);
|
|
257
|
+
if (options.hears()) {
|
|
258
|
+
const target = options.idOf(element);
|
|
259
|
+
say("");
|
|
260
|
+
if (target === undefined)
|
|
261
|
+
return;
|
|
262
|
+
const files = kept.map(({ field, value, at }) => ({
|
|
263
|
+
href: value.href,
|
|
264
|
+
name: value.name,
|
|
265
|
+
type: value.type,
|
|
266
|
+
bytes: value.bytes,
|
|
267
|
+
...(value.width !== undefined ? { width: value.width } : {}),
|
|
268
|
+
...(value.height !== undefined ? { height: value.height } : {}),
|
|
269
|
+
...(value.poster !== undefined ? { poster: value.poster } : {}),
|
|
270
|
+
...(value.duration !== undefined ? { duration: value.duration } : {}),
|
|
271
|
+
...(at ? { at } : {}),
|
|
272
|
+
field,
|
|
273
|
+
}));
|
|
274
|
+
options.send({ type: "dom-event", target, event: "drop", files, ...(problems.length > 0 ? { refused: problems } : {}) });
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (kept.length === 0)
|
|
278
|
+
return say("");
|
|
279
|
+
/* The default: a record per file, linked, as one change. */
|
|
280
|
+
const calls = kept.flatMap((one, at) => plan.calls(one, at));
|
|
281
|
+
const outcome = options.change(calls, plan.intent(kept.length));
|
|
282
|
+
if (outcome.ok)
|
|
283
|
+
say(plan.added(kept.length));
|
|
284
|
+
else {
|
|
285
|
+
say("");
|
|
286
|
+
sayRefused([...problems, `Nothing was added: ${outcome.message}`]);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
refresh,
|
|
291
|
+
before(event, at, root) {
|
|
292
|
+
const element = targetOf(at);
|
|
293
|
+
if (!element || !root.contains(element) || !plans.has(element))
|
|
294
|
+
return false;
|
|
295
|
+
const key = event.type === "keydown" ? event.key : undefined;
|
|
296
|
+
/* A button, a link or a field inside it is the person's to press, not a tap on the target. */
|
|
297
|
+
const own = event.composedPath()[0]?.closest?.(OWN_PRESS);
|
|
298
|
+
const theirs = own !== null && own !== undefined && own !== element && element.contains(own);
|
|
299
|
+
const tapped = event.type === "click" && coarse() && !theirs;
|
|
300
|
+
const pressed = (key === "Enter" || key === " ") && at === element;
|
|
301
|
+
if (!tapped && !pressed)
|
|
302
|
+
return false;
|
|
303
|
+
event.preventDefault();
|
|
304
|
+
event.stopPropagation();
|
|
305
|
+
pick(element);
|
|
306
|
+
return true;
|
|
307
|
+
},
|
|
308
|
+
idle: async () => {
|
|
309
|
+
while (pending.size > 0)
|
|
310
|
+
await Promise.all([...pending]);
|
|
311
|
+
},
|
|
312
|
+
get waiting() {
|
|
313
|
+
return pending.size;
|
|
314
|
+
},
|
|
315
|
+
dispose() {
|
|
316
|
+
shadow.removeEventListener("dragenter", onOver);
|
|
317
|
+
shadow.removeEventListener("dragover", onOver);
|
|
318
|
+
shadow.removeEventListener("dragleave", onLeave);
|
|
319
|
+
shadow.removeEventListener("drop", onDrop);
|
|
320
|
+
document.removeEventListener("dragend", onEnd);
|
|
321
|
+
document.removeEventListener("drop", onEnd);
|
|
322
|
+
style.remove();
|
|
323
|
+
status.remove();
|
|
324
|
+
refused.remove();
|
|
325
|
+
picker.remove();
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=drop.js.map
|